Skip to content

chore(agents): enforce mechanical invariants in lint and slim AGENTS.md - #1471

Merged
realcodesiman merged 3 commits into
mainfrom
chore/agent-instructions-lint
Nov 2, 2026
Merged

realcodesiman merged 3 commits into
mainfrom
chore/agent-instructions-lint

Conversation

@sung17

@sung17 sung17 commented Oct 12, 2026

Copy link
Copy Markdown
Collaborator

Summary

This PR applies three ideas from mattpocock/skills.

1. Rules a machine can check now live in lint, not in prose. AGENTS.md loads into every agent session, so each line there costs context on every turn.

AGENTS.md (29.6k → 15.9k chars)
├── 23 invariants, one line each, same numbering
└── pointer → docs/agents/invariants.md   (full text, moved verbatim)

pnpm lint
├── check:agent-instructions
├── check:invariants   ← new: scripts/check-invariants.mjs
│   ├── runtime import() in tsdown-built code   (allowlist: packages/events/src/trigger/context.ts)
│   ├── logger.*({ error })  → must be { err: error }
│   ├── Prisma imports
│   └── relations/index.ts: imported but not spread
├── turbo run lint
└── ultracite check
    └── biome.json noRestrictedImports: `db` from @chatbotx.io/database/client
        in apps/** and integrations/** (13 legacy files exempt, tests excluded)
  • The mirrors in .devin/ and .github/copilot-instructions.md are regenerated by pnpm sync:agent-instructions.
  • References to the invariant 23 exempt list now point at docs/agents/invariants.md.
  • invariant-guard runs pnpm check:invariants first. It treats any new allowlist entry as a HIGH finding.
  • The CodeGraph setup notes moved to docs/developer/codegraph.md.

2. New diagnosing-bugs skill (.agents/skills/diagnosing-bugs/). It is a gated loop:

  1. Build a command that goes red on the bug.
  2. Minimise the repro.
  3. Rank falsifiable hypotheses.
  4. Instrument with tagged logs.
  5. Fix with a regression test.
  6. Clean up.

It is adapted to ChatbotX: Vitest per workspace, the public API, and replaying webhook or job payloads. It is registered in the CLAUDE.md routing table.

3. Git guardrail hook (.claude/hooks/block-dangerous-git.mjs, a PreToolUse hook on Bash in .claude/settings.json).

  • Blocks: push --force/-f, reset --hard, clean -f, branch -D, checkout ./restore ., and git add -A/./--all.
  • Allows: --force-with-lease, reset --soft, branch -d, and staging named files.
  • It is written in Node, so it needs no jq.

Evidence

  • check:invariants passes on 6,083 tracked source files. Planting a runtime import("node:fs") in packages/utils and an unspread fooRelations import makes it fail with both errors.
  • The Biome rule fails on a new import { db } in apps/worker/src. It passes for the legacy files and for __tests__, and ultracite's own test overrides still apply.
  • The hook returns exit code 2 on 13 destructive commands and 0 on 13 safe ones.

Merge Danger

Door: two-way. Everything here is guidance, lint, and a local hook. No runtime code changes.

Blast Radius: CI lint and the Claude Code sessions of everyone on the team.

Test plan

🤖 Generated with Claude Code

@github-actions github-actions Bot added the chore Maintenance / housekeeping label Oct 12, 2026
@realcodesiman
realcodesiman force-pushed the chore/agent-instructions-lint branch from 264add1 to 04bb0ec Compare November 2, 2026 03:33
Deathgiver and others added 3 commits November 2, 2026 14:31
- Move the mechanical AGENTS.md invariants into lint: a Biome
  noRestrictedImports rule bans `db` imports in apps/ and integrations/ (13
  legacy files exempt), and scripts/check-invariants.mjs (run by pnpm lint)
  checks dynamic import() in tsdown code, the `{ err }` log key, Prisma
  imports, and the relations/index.ts double edit.
- Condense the invariants in AGENTS.md to one line each. The full text moves
  verbatim to docs/agents/invariants.md, cutting AGENTS.md from 29.6k to
  15.9k characters.
- Add the diagnosing-bugs skill, a gated debugging loop.
- Add a PreToolUse hook that blocks destructive git commands and
  `git add -A`/`.`.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@realcodesiman
realcodesiman force-pushed the chore/agent-instructions-lint branch from ff48b5a to 91c4ffb Compare November 2, 2026 07:33
@realcodesiman
realcodesiman merged commit 3db8dd7 into main Nov 2, 2026
14 checks passed
@realcodesiman
realcodesiman deleted the chore/agent-instructions-lint branch November 2, 2026 08:02
hello-jackytruong referenced this pull request in hello-jackytruong/ChatWorkAI Nov 22, 2026
…md (#1471)

* chore(agents): enforce mechanical invariants in lint and slim AGENTS.md

- Move the mechanical AGENTS.md invariants into lint: a Biome
  noRestrictedImports rule bans `db` imports in apps/ and integrations/ (13
  legacy files exempt), and scripts/check-invariants.mjs (run by pnpm lint)
  checks dynamic import() in tsdown code, the `{ err }` log key, Prisma
  imports, and the relations/index.ts double edit.
- Condense the invariants in AGENTS.md to one line each. The full text moves
  verbatim to docs/agents/invariants.md, cutting AGENTS.md from 29.6k to
  15.9k characters.
- Add the diagnosing-bugs skill, a gated debugging loop.
- Add a PreToolUse hook that blocks destructive git commands and
  `git add -A`/`.`.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

* chore(agents): split shared skills into references

* chore(agents): split specialist skills into references

---------

Co-authored-by: Deathgiver <[email protected]>
Co-authored-by: Real Codesiman <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chore Maintenance / housekeeping

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants