Skip to content

docs: grep-first rule for shared code + advisory duplication count - #3061

Merged
kodiakhq[bot] merged 1 commit into
mainfrom
tomagent-code-reuse
Sep 2, 2026
Merged

docs: grep-first rule for shared code + advisory duplication count#3061
kodiakhq[bot] merged 1 commit into
mainfrom
tomagent-code-reuse

Conversation

@teeohhem

@teeohhem teeohhem commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Summary

Trying to cut down on duplicated code. Two parts:

Grep-first rule (agent_docs/code_style.md) — before adding a type, schema, helper, or component, grep for the operation it performs, not the name you'd give it. common-utils has no root barrel, so there's no index to read; the doc adds a map of the nine modules holding ~90% of cross-package imports.

A check (scripts/ci/ratchet.mjs) — the ratchet now counts @source packages/... markers on files ported wholesale into packages/cli. 37 today. Advisory only: it warns, never fails. Gating it would just teach people to drop the marker, since deleting the comment removes the record of a copy, not the copy.

No existing duplicates are removed here.

How to test on Vercel preview

N/A — non-UI change.

References

  • Linear Issue: n/a
  • Related PRs: n/a

Adds a REQUIRED "Before you add a type, schema, or helper" section to
agent_docs/code_style.md: grep for the operation rather than the name you
were about to give it, plus a map of the nine common-utils modules that
carry ~90% of cross-package imports. common-utils has no root barrel, so
grep is the only index.

The escape-hatch ratchet now counts `@source packages/...` port markers,
and agent_docs documents the marker for the first time. The count is
advisory rather than gated: unlike `as any`, deleting an `@source` line
removes the record of a copy, not the copy, so failing on an increase
would only discourage annotating ports.
@changeset-bot

changeset-bot Bot commented Sep 2, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: de70f5b

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vercel

vercel Bot commented Sep 2, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

2 Skipped Deployments
Project Deployment Actions Updated
hyperdx-oss Ignored Ignored Sep 2, 2026 5:59pm UTC
hyperdx-storybook Ignored Ignored Sep 2, 2026 5:59pm UTC

Request Review

@github-actions github-actions Bot added the review/tier-2 Low risk — AI review + quick human skim label Sep 2, 2026
@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

🔵 Tier 2 — Low Risk

Small, isolated change with no API route or data model modifications.

Why this tier:

  • Standard feature/fix — introduces new logic or modifies core functionality

Review process: AI review + quick human skim (target: 5–15 min). Reviewer validates AI assessment and checks for domain-specific concerns.
SLA: Resolve within 4 business hours.

Stats
  • Production files changed: 2
  • Production lines changed: 47 (+ 20 in test files, excluded from tier calculation)
  • Branch: tomagent-code-reuse
  • Author: teeohhem

To override this classification, remove the review/tier-2 label and apply a different review/tier-* label. Manual overrides are preserved on subsequent pushes.

@greptile-apps

greptile-apps Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR documents a grep-first policy for shared types, schemas, helpers, and components, and adds advisory tracking for whole-file @source copy markers.

  • Expands repository and CLI guidance for discovering and documenting shared implementations.
  • Adds @source counting without making increases fatal.
  • Updates the ratchet baseline and covers advisory-only and mixed advisory/gated increases.

Confidence Score: 5/5

The PR appears safe to merge with no actionable defects identified.

Advisory counting is isolated from existing fatal ratchet checks, generated and baseline count shapes remain aligned, and the documentation marker examples are excluded from source-file counting.

Important Files Changed

Filename Overview
scripts/ci/ratchet.mjs Adds @source as an advisory-only ratchet pattern while preserving fatal behavior for existing gated patterns.
scripts/ci/tests/ratchet.test.mjs Adds focused coverage showing advisory increases remain nonfatal and cannot mask gated increases.
scripts/ci/ratchet-baseline.json Adds aligned @source baseline entries for every tracked workspace package.
agent_docs/code_style.md Introduces the required grep-first shared-code guidance and documents whole-file source markers.
packages/cli/AGENTS.md Documents source tags for CLI files ported from the web frontend.

Reviews (1): Last reviewed commit: "docs: grep-first rule for shared code, p..." | Re-trigger Greptile

Comment thread packages/cli/AGENTS.md
Comment thread scripts/ci/__tests__/ratchet.test.mjs
@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

PR Review

3 finding(s): 🔴 0 critical · 🟠 1 major · 🔵 2 minor

2 posted as inline comment(s) on the changed lines. 1 listed below.

Findings outside the changed lines

  • 🟠 scripts/ci/ratchet.mjs:161Deleting an @source tag is reported as an "improvement" — the exact behaviour the advisory design exists to prevent → The now < max branch at scripts/ci/ratchet.mjs:157-163 is shared by gated and advisory patterns, so removing an @source line prints ! cli/@source: 36 < baseline 37 — run \yarn ratchet:update` to lock the improvement in and exits 0. The doc comment 20 lines above (ADVISORY, lines 27-37) says the opposite: "deleting an @sourceline removes the record of a copy, not the copy", and that gating would "teach people to stop annotating their ports". As written, un-annotating a port is not just ungated but actively congratulated, while annotating one (see the next finding) trips the above-baseline warning. Branch onADVISORY.has(name)in thenow < maxcase too and word it for what it means — e.g.! cli/@source: 36 < baseline 37 — if you moved a port into common-utils run `yarn ratchet:update`; if you only deleted the tag, put it back`.

Severity is the reviewer's own estimate and is used for ordering, not filtering.

@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Deep Review

Scope is a docs + CI-script change: prose adds a "grep-first before adding shared code" rule, and scripts/ci/ratchet.mjs gains an advisory @source duplication counter that is reported but never fails CI. The only executable change is ratchet.mjs and its test; the advisory branch ordering, the now-unused improved return, the messages.length log condition, the @source regex, and the .ts/.tsx-only EXTS filter were all verified correct against the tree, and every doc line-anchor and cross-reference in the new code_style.md section resolves to what it claims. Baseline @source: 37 for cli matches an actual marker count of 37; other packages are 0.

🟡 P2 — recommended

  • scripts/ci/__tests__/ratchet.test.mjs:44 — The feature's core detector, the regex /@source packages\//g, is never tested against matching content; the fixture only asserts @source: 0, so a broken prefix or a regex that matches nothing would leave every test green while silently counting no ports.
    • Fix: Add a fixture file containing an @source packages/... comment and assert the counted value is nonzero, plus a negative case where bare @source without packages/ is not matched.
🔵 P3 nitpicks (3)
  • scripts/ci/__tests__/ratchet.test.mjs:115 — No test asserts an advisory pattern exactly at baseline (now === max) stays silent, so a regression making advisory reporting fire at-baseline would go uncaught.
    • Fix: Add @source at baseline to the at baseline passes quietly fixture and assert empty messages.
  • scripts/ci/__tests__/ratchet.test.mjs:124 — An advisory pattern below baseline should still fall through to the improvement nudge, but no test exercises @source below baseline, so a future short-circuit of the advisory branch could drop the nudge undetected.
    • Fix: Add a below-baseline @source case asserting the run yarn ratchet:update nudge with improved === true.
  • scripts/ci/ratchet.mjs:129compare() still computes and returns improved, but main() no longer reads it after switching to messages.length; harmless but mildly confusing dead wiring in the caller.
    • Fix: Leave improved in the return contract (a test asserts it) but add a brief comment noting main() intentionally no longer branches on it.

Reviewers (3): correctness, testing, maintainability.

Testing gaps: The advisory comparison logic (warn-not-fail, and an advisory rise not masking a gated rise) is well covered with value assertions; the untested surface is the regex actually matching @source packages/ inside file content and the at/below-baseline advisory paths.

@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

E2E Test Results

All tests passed • 335 passed • 1 skipped • 1412s

Status Count
✅ Passed 335
❌ Failed 0
⚠️ Flaky 0
⏭️ Skipped 1

Tests ran across 4 shards in parallel.

View full report →

@kodiakhq
kodiakhq Bot merged commit dd5fe4f into main Sep 2, 2026
33 checks passed
@kodiakhq
kodiakhq Bot deleted the tomagent-code-reuse branch September 2, 2026 19:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automerge review/tier-2 Low risk — AI review + quick human skim

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants