Skip to content

docs: add AGENTS.md — architecture, invariants and conventions - #66

Merged
c-1k merged 2 commits into
masterfrom
ship/agents-md
Jul 28, 2026
Merged

docs: add AGENTS.md — architecture, invariants and conventions#66
c-1k merged 2 commits into
masterfrom
ship/agents-md

Conversation

@c-1k

@c-1k c-1k commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds AGENTS.md at the repo root — architecture, invariants, and conventions for anyone (or anything) writing code here.

The repo had no instructions file of any kind. The CLAUDE.md that once served this purpose was gitignored and never committed, and its working copy was lost, so it is unrecoverable. The practical effect is that a fresh clone, an outside contributor, and every automated review tool saw none of the project's rules — they lived only in tooling outside the repository.

That has a measurable cost. On #63 an automated reviewer filed the :: wallet-id charset restriction as a P1 bug. It isn't one: excluding : from the parent charset is what makes parent::costCenter derivation collision-free, and widening it would have broken allocation rather than fixed it. The reviewer had no way to know, and no way to be told — scoped reviews can't take a custom prompt. A repo-root AGENTS.md is the channel that fixes this class of false positive permanently.

Contents

  • What usertrust is, the repo layout, and the 10-step flow of a governed call
  • The invariants — money, audit, policy/safety, client detection — each stated as a rule plus the concrete failure it prevents
  • The packages/verify zero-dependency parity contract: the mirrored-file table, the exact strip() file-diff rule, and why divergence is CVE-class
  • Conventions: TypeScript strictness, ESM .js extensions, Biome, Vitest globals: false, test layout, source headers, comment style
  • Real build/typecheck/lint/test commands, including why npx tsc -b --noEmit fails (TS6310)
  • Commit conventions and the DCO requirement
  • A "What NOT to flag in code review" table — the deliberate designs that look like defects
  • Known drift and hazards — verified oddities worth knowing before touching the surrounding code

How it was built and checked

Every claim was verified against the code, not carried over from memory. Six readers harvested in parallel from the code, the CI/config, git history, and merged PR bodies, tagging each fact verified or asserted.

Three adversarial passes then reviewed the draft and found real defects, all fixed here:

  • Fact-check — ran every documented command and re-derived every count. Caught 10 errors, including a false "every file carries SPDX" (5 don't), a wrong mirrored-file line count, and a resolveRates claim that was untrue on the headless path.
  • Invariant coverage — tested the file against real incidents from git history. Caught 5 gaps, the worst being an exists-exception list that omitted createFundedBudgetWallet and would have licensed a double-funding regression, and a :: guard stated as two of its three clauses — the omitted clause is the one that stops a:::b from resolving to two different owners.
  • Public-repo hygiene — zero internal-tooling leaks, zero secrets, zero absolute paths. Confirmed AGENTS.md is trackable and that the local CLAUDE.md remains gitignored and absent from the index.

Test plan

Documentation only — no code changes, so lint, typecheck, test and tb-integration are unaffected. The value is in the claims being true:

  • Every command in the file was executed during verification: npm run typecheck, npm run lint, npm test, the coverage invocation with all four CI thresholds, and the single-file vitest example
  • npx tsc -b --noEmit was confirmed to fail with TS6310 exactly as documented
  • The strip() parity rule was checked byte-for-byte against the test that enforces it, and all three mirrored file pairs were diffed
  • Counts re-derived from the tree: 39 Biome warnings, 7 control-character sanitizers, 3 policy call sites, 113/118 SPDX headers

c-1k and others added 2 commits July 27, 2026 21:52
This repo had no instructions file of any kind. CLAUDE.md was gitignored and
never committed, and the working copy was lost, so the only machine-readable
rules about how to work here lived in tooling outside the repo. A fresh clone, an
outside contributor, and every automated review tool saw none of it.

That has a concrete cost. An automated reviewer recently filed the `::` wallet-id
charset restriction as a bug, because nothing in the repo said the restriction is
what makes cost-center derivation collision-free. Review tools cannot be handed
this context out of band — a repo-root AGENTS.md is the channel.

Contents: the architecture and the flow of a governed call; the invariants,
each stated as a rule plus the concrete failure it prevents; the packages/verify
zero-dependency parity contract with the mirrored-file list and the exact
file-diff rule; conventions; real build and test commands; commit and DCO rules;
a "what NOT to flag in review" table; and the known drift.

Everything in it was verified against the code rather than carried over from
memory. Three adversarial passes checked it afterwards: a fact-check that ran
every documented command, an invariant-coverage pass that tested it against real
incidents from git history, and a hygiene pass confirming no internal tooling
leaked into a public file.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Cam <cam@camwhiteus.com>
Four executable entry points begin with `#!/usr/bin/env node`, so the header sits
on lines 2-3 rather than line 1. "New files open with" was not literally true for
them, and a reader checking only the first line concludes the header is missing —
which is exactly what the Codex gate did on this PR, reporting four false
positives.

The count itself was right and is unchanged: 113 of 118 files carry the header,
the five that do not are all of `packages/acs-adapter/src/`. Also records that no
file carries one of the two lines without the other.

Raised by the Codex gate on #66 (P3).

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Cam <cam@camwhiteus.com>
@c-1k

c-1k commented Jul 28, 2026

Copy link
Copy Markdown
Contributor Author

Codex Gate — review and triage

Two passes were run, because a scoped codex review only sees the diff and half of this work is a gitignored file that never appears there.

Pass 1 — codex review --base master (AGENTS.md)

One finding:

[P3] Correct the already-stale list of headerless source filesAGENTS.md:560-561
"the tree already has additional headerless source files outside packages/acs-adapter/src/ (for example packages/core/src/cli/main.ts, packages/server/src/cli/main.ts, packages/ui/src/server/main.ts, and packages/verify/src/cli.ts)"

Verdict: finding dismissed, underlying imprecision fixed (cb21c4a).

All four named files do carry the header. Each is an executable entry point beginning with #!/usr/bin/env node, so SPDX sits on line 2 and Copyright on line 3. Counted over all 118 .ts/.tsx files under packages/*/src by checking the first three lines: exactly 5 lack it, and they are precisely the acs-adapter sources already named. All 113 others carry both lines; none carries one without the other.

But the confusion was earned — the file said new files "open with" the header, which is not literally true for those four. It now states the shebang convention explicitly and says to check the first three lines. A wrong finding surfaced a real documentation defect.

Deliberated via codex exec. Codex re-ran the count itself and conceded:

The strongest case against my original finding is that it was wrong on the facts. […] Those were false positives from checking only line 1. […] exactly these 5 lack the SPDX line […] The maintainer's clarification to say "check the first three lines" fixes the real documentation ambiguity.

Pass 2 — codex exec on CLAUDE.md

CLAUDE.md is gitignored and absent from the index, so it reaches no diff and codex review cannot see it. It was reviewed by piping its contents through codex exec instead.

Finding Verdict
The Biome nested-root failure also surfaces sibling worktree config errors Valid — fixed
"Run it from inside the worktree" is not universally safe Valid — fixed
"gh pr checks will never show one" is too absolute to verify from the repo Valid — fixed
AGENTS.md is not on master yet Correct today, self-resolving on merge
Coverage-threshold block duplicates AGENTS.md Already scoped to the reproduce-CI command only
Draft-PR gate duplicates AGENTS.md Codex conceded the procedure belongs here

The two Biome findings were the useful ones and reproduce exactly: ship/mobile-optimization and ship/site-perf both exit 1 on their own biome.json, on the deprecated recommended field — they predate the Biome 2 migration. CLAUDE.md now says the workaround holds for a worktree branched off current master, and that failing on its own config is a signal the branch needs rebasing.

(Those two stale worktrees and their remote branches are unrelated leftovers, flagged separately for cleanup.)

@c-1k
c-1k marked this pull request as ready for review July 28, 2026 02:00
@c-1k
c-1k merged commit 0dae0e7 into master Jul 28, 2026
9 checks passed
@c-1k
c-1k deleted the ship/agents-md branch July 28, 2026 02:02

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cb21c4aef4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread AGENTS.md
Comment on lines +315 to +316
**Hard rules fail closed; soft rules stay lenient.** An indeterminate condition (missing or
mistyped guarded field) is treated as *satisfied* for a hard rule, so the guard still fires.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Restrict the fail-closed guarantee to numeric comparisons

This guarantee does not apply to every condition: only gt/gte/lt/lte return "indeterminate" for missing or mistyped fields. Operators such as exists, contains, and regex return false, causing even a hard deny rule not to match. An agent relying on this statement could create a supposedly fail-closed string or existence guard that actually fails open, so the text must either limit the guarantee to numeric operators or require the evaluator to implement it consistently.

Useful? React with 👍 / 👎.

Comment thread AGENTS.md
Comment on lines +345 to +348
There is a second, blunter layer with a governance consequence of its own: `MAX_REGEX_INPUT = 4096`
truncates the resolved value *before* matching, so a `matches` rule can never see past a field's
first 4096 characters. That is a control that fails **open** on long input — never write a `matches`
rule that has to catch something an attacker can push past that boundary.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Use the actual regex policy operator

FieldOperator and evaluateFieldCondition recognize regex, not matches, and loadPolicies casts parsed JSON/YAML without validating operator names. A policy author following this wording can therefore write operator: "matches"; it reaches the evaluator's default false branch and silently disables the rule, including a hard deny intended as a security control.

Useful? React with 👍 / 👎.

Comment thread AGENTS.md
Comment on lines +90 to +91
8. **Audit first.** The `llm_call` event is appended to the hash chain **before** the budget commit
and before the ledger POST, so a `failClosed` deployment never settles an unaudited spend.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Document the streaming audit-order exception

For streaming calls, finalizeStreamSettle commits budgetSpent and calls engine.postPendingSpend before appending the llm_call event; if that append fails under failClosed, only the receipt rejects after the spend has settled. Thus the unconditional claim that audit always precedes POST and prevents unaudited settlement is false for governed streams and should explicitly distinguish the non-streaming and post-delivery streaming paths.

AGENTS.md reference: AGENTS.md:L124-L130

Useful? React with 👍 / 👎.

Comment thread AGENTS.md
Comment on lines +401 to +403
`--`-prefix match. The resolved wallet is echoed in both output modes, and **every echoed value goes
through `forDisplay` first** — an echoed flag value is argv, the caller may be an agent, and
picocolors adds SGR codes without sanitizing anything it wraps.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Cover requireValue before claiming every echo is sanitized

When a space-separated value starts with -, requireValue embeds the raw value directly in its error (write ${flag}=${raw}...) without calling forDisplay. For example, a --parent value beginning with - followed by an ESC sequence reaches the terminal unchanged, so this statement currently hides a terminal-repaint path; sanitize that interpolation or qualify the claimed coverage.

AGENTS.md reference: AGENTS.md:L370-L374

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant