Repository navigation
Description
Human request (Vain, 2026-11-16). Companion to #4282, whose UI guardrails (#4294 static, #4295 runtime/visual) this spec reuses and does not duplicate.
Problem
The codebase is the context every agent reads. A small slip that merges (a floating promise, a 12k-line file growing by 300 lines, a rule that only lives in prose) is copied by the next agent and compounds. Today:
- Lint is thin.
.oxlintrc.jsononly hasignorePatterns: oxlint runs its defaultcorrectnessset, with notypescript/react/import/unicorn/jsx-a11yplugins and no type-aware rules. Our own rules live in 14scripts/check-*.mjsscripts that run only inpnpm lint, never in the editor. - Pre-commit only formats.
.lintstagedrc.jsonrunsoxfmt; nothing lints until CI. Agents (the main authors) get no feedback at edit time:.claude/settings.jsonhas no hooks. - Structural health is unmeasured. 2,264 TS/TSX source files; the largest are
client/locale.ts12.0k lines,runtime/bot-runtime.ts11.4k,bridge/methods.ts10.6k,client/bridge.ts7.4k. 47 mobile test files are excluded fromtsc. No dead-code, cycle, duplication or boundary checks. - CI checks but does not review.
verify.ymlruns static/tests/perf-budget/e2e. Nobody reviews a PR against the linked issue or the repo's standards before a Human does. - The feature map cannot be targeted.
verify-deepseekbot/features/(pstack's feature map, 80 features) says how to drive and prove each feature, but no feature names its source paths or its glossary terms, so neither an agent nor CI can tell which features a diff or a bug report touches. - Tests are example-based only. No property-based, model-based or fuzz testing (
fast-checkis not a dependency). Perf has good guards (perf-budgetjob, render-commit benches, timeline/GenUI budgets) but no continuous trend. - AGENTS.md is 188 lines / ~40 KB, loaded into every agent, plus 7.3k lines in
docs/agents/and mobile docs, plus 343 ADRs (2.4 MB) whose current rules are spread across amendments. Many rules are checkable and some already are, but the prose does not say which.
Principle: push each rule to the lowest layer that can enforce it
| Layer | Where it bites | Feedback time |
|---|---|---|
| L1 Codebase health | The goal and its metric: a pnpm health report of ratcheted numbers that only improve |
— |
| L2 Lint | Agent edit hook → editor (oxc extension) → pre-commit → pnpm lint |
seconds |
| L3 CI | PR checks that need the diff/PR body, plus an AI review job | minutes |
| L4 Trustworthy agent work | Feature map ↔ source ↔ glossary: an agent locates the feature a diff or bug touches, proves it with the verification tooling, and reports in glossary terms | minutes, before PR |
| L5 Probabilistic + perf testing | Property/model-based/fuzz tests, UI monkey runs, perf benches, nightly health trend | per PR + nightly |
| L6 Prose | Only what no check can express (process, judgement, rationale), loaded on demand | — |
Every check follows the #4282 pattern: shrink-only baseline for existing code, an error message that names the source rule and prints the fix, and pnpm lint:fix applies mechanical fixes. A rule moved down a layer is deleted from prose, leaving at most a one-line pointer.
Guardrail registry. scripts/guardrails.json lists every rule: id, source doc anchor, layer, check, baseline file. pnpm lint verifies that every registered check exists, every baseline only shrank, and every doc line marked Enforced by points at a registered check, so docs and checks cannot drift apart. pnpm health reads the same registry.
L1 — Codebase health metrics (ratcheted)
| Metric | Tool | Rule |
|---|---|---|
| Lint findings per file × rule | oxlint JSON + scripts/lint-ratchet.mjs |
baseline only shrinks |
| File length | ratchet script | new files ≤ 800 lines; baselined files may not grow |
| Function size / cyclomatic complexity | oxlint max-lines-per-function, complexity |
same ratchet |
| Import cycles, layer boundaries (Host ↔ Client, package public entries, mobile ↛ Host internals, ADR ownership boundaries) | oxlint import/no-cycle + a boundaries config (dependency-cruiser if oxlint cannot express it) |
zero new |
| Dead exports, unused files and deps | knip | baseline only shrinks |
| Copy-paste duplication | jscpd | baseline only shrinks |
Files excluded from tsc |
tsconfig.json exclude list |
list only shrinks |
| Always-loaded agent prose | bytes of AGENTS.md, CLAUDE.md, apps/mobile/AGENTS.md |
only shrinks |
L2 — Lint (edit time, before CI)
- Expand oxlint. Enable
typescript,react,react-hooks,import,unicorn,jsx-a11y,promiseplugins and thesuspiciouscategory; add type-aware rules throughoxlint-tsgolint(stable since July 2026):no-floating-promises,no-misused-promises,switch-exhaustiveness-check,no-unnecessary-condition,await-thenable,restrict-template-expressions. Existing findings go into the ratchet baseline. - One linter in the editor. Port the AST-shaped
check-*.mjsrules (source policy: no comments / nouseEffect/ whole-store subscriptions; host casts; tool effects) and Design guardrails G1: turn the written UI/UX rules into lint with autofix #4294's rules into an oxlint JS plugin (scripts/oxlint-plugin-tobs/) so they show in the editor with a location and quick fix. Repo-shaped checks (ledger, ADR numbers, feature map, CI plan) stay scripts. - Agent edit hook.
.claude/settings.jsonPostToolUseon Edit/Write runs oxlint + oxfmt on the touched file and returns findings to the agent; the same for Codex hooks.PreToolUserefuses edits in the main checkout (worktree discipline). - Pre-commit. lint-staged runs
oxlint --type-awareon staged files and the fast scripts that accept paths;gitleaks protect --stagedfor secrets; refuse commits onmainin the main worktree. Pre-push:pnpm typecheck+ci-affected --runfor the pushed diff. - Prose rules that become L2 rules: see the mapping table below.
L3 — CI evaluates and reviews
- Health delta summary. A
healthjob posts one sticky PR comment: each L1 metric base → head, what improved, which baseline entry blocks. A worse metric already fails lint; the comment is for review. - PR body lint.
scripts/check-pr-body.mjs:Closes #Nas plain text, the merge-risk bullet, the CI-plan line,visual-prsections, issue-claim reference, glossary terms (L4). (UI evidence is Design guardrails G2: visual regression, accessibility and layout-contract checks in CI #4295 rule 6.) - AI review. A
reviewjob runs Claude Code (GitHub Action) with the repo'scode-reviewskill: Standards axis (repo rules + guardrail registry) and Spec axis (linked issue), posting inline findings. Advisory first; a finding class becomes blocking only after it proves precise, and a recurring finding should become an L2 rule instead (the review output is the backlog for new lint rules). - Required checks.
static,health,pr-body, tests andperf-budgetbecome required onmain.
L4 — Trustworthy agent work: feature map ↔ source ↔ glossary
Vain's framing: maintain the feature map and the verification tooling so that, on a bug or a change, an agent can locate the specific feature, prove the behaviour the way a user would, and describe pages and features in the terms GLOSSARY.md defines. pstack is already vendored (56 skills from cursor/plugins in .agents/skills/, locked in skills-lock.json); verify-deepseekbot/features/ is its feature map.
- Feature → source. Each
features/*.mdgets aSourceslist (globs).check-feature-map.mjsfails when a glob matches nothing and reports source dirs no feature claims (the unmapped inventory ratchets down). - Feature → glossary. Each feature names its
Terms: theGLOSSARY.mdentries for the pages, components and concepts it covers (GLOSSARY.mdalready has a parseable**Term / 中文**:+_Avoid_:shape, 302 entries). The check fails when a named term is not in the glossary. - Glossary lint.
scripts/check-glossary-terms.mjsflags_Avoid_terms (e.g. 「弹窗」, "drawer", "Tob" for the product) in feature files, skill docs and, in CI, PR bodies and issue bodies the PR links, printing the preferred term. Off-glossary nouns in feature files fail; in PR text they warn. Baseline for existing docs. - Diff / bug → feature.
node scripts/feature-impact.mjs --base origin/main(or--paths, or--terms "<bug text>") prints the touched features, their journeys, glossary terms and whether they need a model. CI posts it; the PR's Verification bullet names a run (or a reason) for each touched feature. An agent triaging a bug starts from the same command. - Upkeep. A scheduled
maintain-verification-skillpass (pstack's upkeep loop) keeps map, sources and terms honest, one PR of proven corrections at a time; a glossary term added without a feature, or a feature whose terms left the glossary, shows up in its report.
L5 — Probabilistic, UI-fuzz and performance testing
| Need | Library / approach | First targets |
|---|---|---|
| Property-based tests | fast-check + @fast-check/vitest (test.prop, seed + path printed on failure, shrinking) |
pure logic: ci-plan rules, migration ledger, Markdown stream reveal, mention resolution, timeline cursors, call-grid tiling, usage totals (the ADR conversions below) |
| Model-based (stateful) tests | fc.commands + fc.asyncModelRun against a simple model |
client store reducers, channels/sqlite-store, Outbox idempotency, ready-set harvest, approval lifecycle |
| UI fuzz (props/content) | fast-check arbitraries (long CJK, emoji, RTL, empty, 10k-char, many rows) rendered in vitest browser mode / the #4295 gallery; invariants: no throw, no horizontal overflow, no clipped text, focus still reachable | ds/ primitives, message rows, settings rows |
| UI fuzz (interaction) | Playwright monkey run on a verify-app Host with fast-check-generated action sequences (click/type/scroll/resize/theme switch); invariants: no console error, no uncaught rejection, no long task > 200 ms, no layout jump; replayable by seed |
Bot mode main screens, nightly |
| Mobile fuzz | Maestro flows with randomized input on Simulator (shared-device queue) | later |
| Perf benches | existing render-commit benches + vitest bench, tracked by CodSpeed (simulation mode, <1% variance on shared runners, blocks regressions on PRs), or a self-hosted baseline if a SaaS is not wanted |
store writes, timeline render, Markdown parse, bridge RPC encode |
| Render hotspots | react-scan in dev builds + render-count assertions (extend client-store-*-render-bench) |
sidebar, timeline |
| Bundle / heap | size budget on packages/client output; existing heap observation |
client bundle |
| Continuous monitoring | nightly health workflow: full fuzz seeds, perf trend, L1 metrics → published trend page; a regression opens an issue |
— |
All of this follows docs/agents/ax-performance.md (profile before fixing, A/B on frozen fixtures, budgets only tighten).
Prose → lowest layer (first pass over AGENTS.md)
| Rule (source) | Today | Target | Check |
|---|---|---|---|
Scripts are .mjs, no .ps1/.cmd/.bat (Conventions) |
L2 check-no-shell-scripts |
keep, prose → pointer | — |
Spawn with shell:false + windowsHide:true (Conventions) |
prose | L2 | oxlint plugin rule on spawn/execFile/fork options |
| Never commit secrets (Conventions, ADR-0006) | prose | L2 + L3 | gitleaks pre-commit + CI |
| Migration ids (Conventions) | L2 check-schema-migrations |
keep | — |
| Generated docs never edited; diagram SVGs committed; slides output not committed | prose | L3 | CI regenerates (sync-docs, diagrams, slides:build) and fails on diff |
| OG font subset after Chinese copy change | prose | L3 | test that every OG title glyph is in the subset |
Vendored skills unedited (skills-lock.json) |
prose | L2 | hash check against the lock file |
agent/skills/ mirrors .agents/skills/ |
prose | L2 | mirror check |
Structured developer logs, no ad-hoc console (Developer diagnostics) |
prose | L2 | oxlint no-console in Host packages, baselined |
/api interceptor owned by api-gateway (dsh-dev) |
prose | L2 | plugin rule: no connection.rpc.intercept('/api') |
| CLI parity | L2 check-cli-parity |
keep | — |
| Perf assessment for new features/dependencies; budgets only tighten | prose + perf-budget |
L3 | PR-body check requires the perf line when deps or hot paths change; budget files may only tighten without a perf:approved label |
| Worktree discipline | prose | L2 | edit hook + pre-commit refuse the main checkout / main |
Issue claim, Closes #N plain text, merge-risk bullet, CI-plan line, visual-pr |
prose + template | L3 | check-pr-body |
| Release ledger fragments | L2 changelog:check |
keep | — |
| CI plan rules | L2 ci-plan --check |
keep | — |
| Feature map updated when the app moves | prose + structure check | L4 | Sources globs + impact report |
| Name the component by platform term; product nouns from the glossary | prose | L4 + L3 | check-glossary-terms (_Avoid_ lists) + AI review |
| Store subscriptions select fields | L2 check-source-policy |
keep (move into the oxlint plugin) | — |
| DSH/Cordis vocabulary | prose | L3 | AI review |
| UI design / copy / motion / tokens | prose | — | owned by #4294 / #4295 |
| Tracer-bullet delivery, IM browser QA, VPS, device QA, QA evidence, SEO, DSH upgrade, resource cleanup | prose | L6 | stays prose, but moves out of always-loaded AGENTS.md into on-demand skills/docs behind a one-line router |
| 343 ADRs | prose | L2/L3/L5 + L6 | see the ADR cleanup comment: 23 delete, 46 convert, ~250 consolidated into 18 topic decision docs, 24 stale proposals resolved |
docs/agents/*.md get the same pass, file by file, as each tracer bullet touches them.
Out of scope
UI rules already in #4294/#4295. Rewriting large files: the ratchet stops growth; splitting them is separate refactor work that the health report will prioritise.
Delivery: tracer bullets (sub-issues, in order)
- TB1 One rule through every layer (Guardrails TB1: one type-aware lint rule through agent hook, editor, pre-commit and CI with a shrink-only baseline #4297). Ratchet runner +
guardrails.json+ one type-aware rule (no-floating-promises) wired through the agent edit hook, editor config, lint-staged,pnpm lintand CI, with a baseline and a fix message. Proves the pipeline. - TB2 Health report + structural ratchets.
pnpm health: file length, complexity, cycles, tsc-exclude list, agent-prose bytes; CI sticky delta comment. - TB3 Expand oxlint + first prose conversions. Plugins/categories; oxlint JS plugin with the spawn,
no-consoleand/apiintercept rules; gitleaks; worktree hooks; delete the converted prose fromAGENTS.md. - TB4 PR body lint + AI review job.
check-pr-body; advisory Claude Code review using thecode-reviewskill. - TB5 Feature map ↔ source ↔ glossary.
SourcesandTermsfor the 80 features,check-glossary-terms,feature-impact.mjs(diff, paths or bug text), CI impact comment. - TB6 Property & model-based tests. fast-check foundation; first targets are the ADR invariants marked L5; seed reproduction in the failure message.
- TB7 UI fuzz + perf trend. Seeded Playwright monkey run on
verify-app; nightlyhealthworkflow with perf benches tracked. - TB8 Slim AGENTS.md. Move L6 runbooks into skills/docs behind a router; the prose-bytes ratchet locks it.
- TB9 ADR cleanup. One PR per topic: delete, convert (with its check), consolidate the rest into
docs/decisions/<topic>.mdwithEnforced bylinks. Per-ADR dispositions are in the comment below, pending Vain's review.
Activity
DoodleBears commentedon Nov 16, 2026
ADR cleanup proposal (TB9, scope added by Vain 2026-11-16) — pending Vain's review, nothing deleted yet
Vain's rule: an ADR stays as prose (L6) only when its decision cannot be pushed into L1–L5, and outdated ADRs are deleted. Git history keeps every deleted ADR, so deleting one is reversible.
Inventory. There are 343 ADRs (2.4 MB): 213 Accepted, about 38 Proposed, and the rest with free-text statuses. Decisions are often patched in place ("Amended by", "Partly superseded by"), so the current rule for one area is spread across many files. Memory has 18 files, IM providers 45 and calls 21. An agent that reads one ADR can miss the amendment that overrides it, which is the slippage this spec targets.
What can move down a layer. An ADR holds a what (an invariant) and a why (alternatives and trade-offs). The what usually fits an import/ownership boundary, a type, or a property, model-based or snapshot test. The why cannot be checked, but it is short once the amendment history is stripped.
Proposal
docs/decisions/<topic>.md). Each holds one current-state section per decision with a 2–5 line why and anEnforced byline, and no amendment history. The numbered files go away.check-adr-numbersbecomes the registry check onEnforced bylinks.docs/architecture/keeps owning how it works; topic docs own why.Method and limits. These dispositions come from each ADR's title, status, supersession notes and the opening of its decision. Each topic PR re-reads its ADRs in full before deleting anything, so a disposition can still change.
sync-docspublishes ADRs at/dev/adr, so the site moves to the topic docs in the same PRs. Delivery is one small PR per topic, largest first (IM providers, Messaging, Sessions), and each PR lands its checks with it.Per-ADR dispositions
Only deletions, conversions and stale proposals are listed per ADR. Every other ADR is listed by number under "Merge the why".
Memory (18)
Bot identity & lifecycle (19)
PersonaBotIdSessions, Orchestrator & Assignments (27)
Messaging & Channels (29)
Inbox & attention (13)
Persistence, backup & usage (19)
check-schema-migrations(exists)External IM providers (45)
Computer (13)
Browser (10)
Workspaces & files (7)
Approvals, secrets & private input (20)
Desktop / Web UI (29)
packages/clientnever imports Host modulesMobile app (29)
motion.tsspringsCalls & voice (21)
Connect, remote Hosts & Team mode (18)
Release, CLI, telemetry & diagnostics (20)
engines.dshmatches the verified floorMarketplace (3) — Merge the why: 0131, 0240, 0267
GenUI (3)
Generated by Claude Code
DoodleBears commentedon Nov 16, 2026
What else to adopt from pstack (poteto)
pstack is already vendored: 56 skills from
cursor/pluginsin.agents/skills/, its guide in.agents/docs/guide/, and thepoteto-agentandcomment-sickoagents. The 1–5 + 6 ladder in this spec is poteto's/correctladder (skills/correct/SKILL.md, guide 09 "Fix the environment with /correct"): architecture → types → a lint/CI check whose error names the fix → a test → docs last. pstack also has a principle-encode-lessons-in-structure skill: "If the fix is structural, only use the structural fix. The instruction is the symptom." This spec already uses several of these ideas; the rest are adopted below.Conventions from
/correctfolded into the specswitch-exhaustiveness-check), andunknownat boundaries (typescript-best-practices). Design guardrails G1: turn the written UI/UX rules into lint with autofix #4294 rules 4 and 11 already work this way.guardrails.jsonentry gets a fixture taken from a real commit, revert or review comment where the mistake happened. The check must fail on that fixture in a test. "A check you've never seen fail proves nothing."AGENTS.mdfromguardrails.json. When an agent is corrected for a rule that is already in the table but has no enforcement, that is a repeat and gets fixed structurally in the same change. A rule is dropped once its mistake can no longer happen.pnpmscript, and CI only calls the scripts.Skills and workflows to wire in
/correctwith no argument/create-formal-verification-skill+maintain-…/statechart/maintain-verification-skill/blast-radiusfeature-impact.mjs./interrogateci:full/ high merge-risk class).code-reviewstays the default./benchmark-checklist/no-comments/comment-sickocheck-source-policy); nothing to add./reflect//retro/correct. This is the intake for new guardrails.unslopped prose. Its checks merge intocheck-pr-body(TB4).Tracer-bullet changes
/correct(read-only) over recent history and attach its mistake classes to this issue. That ranks the L2/L3 backlog by real frequency instead of guesses.guardrails.json.Generated by Claude Code
DoodleBears commentedon Nov 16, 2026
Delivery update (Vain, 2026-11-16)
/create-formal-verification-skill,/statechart), adopted at Vain's request. It is split out of TB6. Targets in order: Outbox retry idempotency (ADR-0039), ready-set harvest (0077), live notify only after commit (0054), Connect enrollment issue/cancel (0339). Each model must fail on a deliberately broken variant before it counts. The statechart for each one is generated from the TLA+ and embedded in its topic decision doc, so the picture and the checked model cannot drift./correctpass over recent history to rank the L2/L3 backlog by how often each mistake actually happened.Generated by Claude Code
docs(decisions): consolidate the 18 Memory ADRs into one topic decisi…
DoodleBears commentedon Nov 16, 2026
Merge policy (from the maintainer, 2026-11-16, revised)
The guardrail layers are what make merging trustworthy. When CI and the repo rules pass, an internal PR merges. This includes UI/UX changes: fix forward with a follow-up PR instead of holding the merge.
needs-humanwhen its author is external or its diff touches one-way-door paths, such as schema migrations, release workflows, auth and secrets, or protocol contracts. Reuse the ci-plan area rules so the path list lives in one place.Generated by Claude Code
DoodleBears commentedon Nov 16, 2026
Provenance labels: harness and model (from the maintainer, 2026-11-16)
Every issue and PR an agent implements carries the harness and model that wrote it. These labels are provenance for the multi-model evaluation and for review triage.
harness:<name>: the agent runner, lowercase. For exampleharness:claude-code,harness:codex,harness:cursor,harness:opencode.model:<id>: the model id without effort or date suffixes, lowercase. For examplemodel:claude-opus-5-5,model:deepseek-v4-pro,model:kimi-k3.1-pro. Use the served model the runner reports, not the configured alias.agent:active, these labels are never removed when the work ends.verifyand cancels the run in progress.Applied so far: #4296, #4297, #4299 and #4300 carry
harness:claude-codeandmodel:claude-opus-5-5.TB12 (planned):
Agent-Task:orCo-Authored-By:from an agent) but has noharness:ormodel:label.Generated by Claude Code
124 remaining items
DoodleBears commentedon Nov 19, 2026
Agent work claim
codex/local/01a1f288-d03a-7481-b2c1-e044f7934e09(a Codex task)codex/4296-tb9-mobile-uidocs(decisions): publish the mobile UI topic
DoodleBears commentedon Nov 19, 2026
Agent work outcome
codex/local/01a1f288-d03a-7481-b2c1-e044f7934e09ae69121d925336e07d72e5e9eaaf7c1c4d6855daengine-host.tsfinding, and the other verification jobs passed or were skipped by the workflow.docs(decisions): fold Bot identity and lifecycle ADRs
DoodleBears commentedon Nov 19, 2026
Agent work outcome
codex/local/01a1f1af-08a4-7d81-85da-7a38ff18d6422fe64c5ed08533913737ef744745b795267609b2. Local lint and 49 focused tests passed. The temporary invalid Bot ID variant failed the new test. Sixteen numbered files were retired, and the three existing Tob anchors remain in Tob.fa68e13275cbb17b172dd7ce8bbce61058190496. Local lint and 141 focused tests passed. The boundary guard rejected a temporary import of Host code from Client source. Twenty-five numbered files were retired, including ADR-0348 and ADR-0351. Six existing anchors remain in Onboarding.docs(decisions): fold the Mobile app ADRs into one topic doc with a p…
docs(decisions): fold the Team mode ADRs into one topic doc with a Ho…
docs(decisions): fold the Bot identity and lifecycle ADRs into one to…
docs(decisions): fold the Mobile app UI ADRs into one topic doc with …
docs(decisions): fold the Desktop and Web UI ADRs into one topic doc (#…
DoodleBears commentedon Nov 19, 2026
Agent work claim
codex/local/01a1f310-4527-7a23-9535-1f3e6fd6265d(Codex task)codex/4296-tb9-tail,codex/4296-tb8-slim-agentsDoodleBears commentedon Nov 19, 2026
Agent work outcome
codex/local/01a1f310-4527-7a23-9535-1f3e6fd6265da0281ca8351a4b03863106659d711559661e36db. Four ADRs folded, 206 focused tests and head-local lint passed, and the temporary canary that ignored degraded capabilities failed its regression test. ADRs 0353–0356 stay with Fall back from a Subscription Engine to the next Routing Group target when its quota runs out #4574.625440e3f84afd4751f571a522bef1fba0addc76. Prose dropped from 37,729 to 20,525 bytes. All 76 focused tests passed. The cap refused one extra byte and the generated table check refused a changed row.docs(decisions): fold the last ADRs into topic docs (TB9) (#4664)
docs(agents): slim AGENTS.md behind a router (TB8) (#4665)