Agent Instructions — agents-md-sync
Instructions for AI coding agents working on this repository. For what the tool itself does, see README.md.
Project
Node/TypeScript CLI that composes an AGENTS.md from markdown partials held in a central Bitbucket template repo, commits and pushes the result to a tool-owned branch on each target Bitbucket Data Center repo, and — when --pr is passed — opens or updates a pull request for that branch. Greenfield — currently only README and this file exist.
Stack
- Language: TypeScript, Node 20+
- Runner:
tsxfor dev,tscfor build - CLI:
commander - Validation:
zod - HTTP:
undici(or built-infetch) - Tests:
vitest
Coding
- TypeScript strict mode. No
anywithout a written reason. - Prefer small, pure functions. Keep I/O (Bitbucket API, fs) at the edges; keep composition logic pure so it can be unit-tested without network.
- No comments that restate the code. Only comment non-obvious why.
- Use Node's built-in
fetchunless a specificundicifeature is needed. - Do NOT introduce a heavy templating engine. Include markers are
<!-- include: NAME.md -->and are resolved by simple string replacement. - Partial resolution is profile-aware:
profiles/<profile>/NAME.mdwins overcommon/NAME.md. Keepcompose.tspure and test both paths. - The default
AGENTS.md.tmplskeleton lives as aDEFAULT_SKELETONconstant insrc/templateLoader.ts. A profile can opt into a bespoke skeleton by droppingAGENTS.md.tmplinto its directory; absent that file, the default is used. - v1 allows exactly ONE profile per target. Multi-profile (polyglot) support is out of scope. Do not add it without a design discussion.
Testing
- Unit tests go in
tests/and mirrorsrc/layout. src/compose.tsMUST be covered by unit tests — it is the only pure-logic module and the heart of the tool.- Network-touching code (
src/bitbucket.ts,src/sync.ts) is tested via mockedfetchor integration tests against a sandbox repo, never against real production Bitbucket repos. - Run tests with
npm test(vitest). Every PR must pass tests locally before opening. - Sample outputs are golden fixtures.
examples/sample-output-<profile>.mdis re-rendered on every build and test run by composing each profile inexamples/template-repo/profiles/againstexamples/template-repo/common/.npm run buildandnpm testboth invoke the render step. If a profile partial changes, the sample file must be updated in the same commit. CI fails if committed samples drift from whatcompose.tsproduces.
Review & Git
- No direct pushes to
master/main. Always work on a feature branch and open a PR. - This repo is NOT a fork. Standard PR targeting applies — but if that ever changes, confirm the PR target with the user before running
gh pr create. - Commits: short imperative subject line, body optional. No Conventional Commits requirement yet.
Build & Run
npm install
npm run build # tsc to dist/
npx tsx src/index.ts --config examples/targets.json --dry-run
Bitbucket API notes
- Target is Bitbucket Data Center (self-hosted). API base:
/rest/api/1.0/. Do NOT use Bitbucket Cloud endpoints (/2.0/). - Auth:
Authorization: Bearer $BITBUCKET_TOKEN. - File write is
PUT /projects/{key}/repos/{slug}/browse/{path}with multipart form fieldscontent,message,branch,sourceCommitId. - When the PR branch already exists, update it — do not create a second branch.
Do not
- Do not push directly to
master/main. - Do not commit secrets, tokens, or
targets.jsonfiles that contain real Bitbucket URLs/credentials. Add a.envandexamples/targets.jsonwith dummy values only. - Do not touch any file in a target repo's
.agents/directory. That directory is 100% repo-owned — the tool reads.agents/<NAME>.mdfiles as per-section addenda when composingAGENTS.md, but only writesAGENTS.mditself. - Do not skip pre-commit hooks (
--no-verify) or Git signing without explicit user approval. - Do not add support for Bitbucket Cloud or GitHub in v1 — it's out of scope.