Repository navigation
feat(shared-instructions): accept agentsmd/ as a shared-instruction source directory - #1695
Conversation
The description provides a representative real-CLI pull/doctor record, satisfying the testing-record requirement. No PR code was executed. |
SaulMoro
left a comment
There was a problem hiding this comment.
This was generated by AI during triage.
I built 5b1f3a8 and the merge-base (164fac9) and ran each case with the CLI in an isolated HOME, --provider git --agent claude, against a local bare team repo. agentsmd/ winning over claudemd/ is the right precedence: a hard error would fail every pull for a state the PR documents as valid. Pull delivers as described:
| Team repo | 5b1f3a8 |
|---|---|
claudemd/ only |
1 file synced |
agentsmd/ only |
1 file synced |
both, root-note.md in each |
3 files synced, only the agentsmd/ copy of root-note.md in the managed block |
normal-mode push of a new agentsmd/ file, claudemd/ on main |
branch pushed with agentsmd/new.md |
[P1 blocking] Self-mode push drops a new file in a source directory main does not have
main has claudemd/; member writes .teamai/agentsmd/new-b.md
teamai push --all exit 0 No new or modified resources to push (no branch)
The same happens with no source directory on main, and for a new claudemd/ file when main has only agentsmd/. It pushes only when the directory is already on main. scanLocalForPush takes its directories from dirsIn(localConfig.repo.localPath) (src/resources/repo-resource.ts:233), which is main's tree, and self mode then reads only those under .teamai/ (:91). Scanning both source directories on push, as pull's claudemdCandidates does, fixes it. This is the CI review's first finding.
[P1 blocking] Lint & Test fails on Node 20, 22 and 24 (ubuntu) and Node 20 (macOS)
pull-skip-sync.test.ts "keeps the pull fast path available when shared-instruction discovery fails" (:1242) writes a file at claudemd and expects Shared instructions sync skipped: ENOTDIR in the debug log. existingSharedInstructionDirs (src/shared-instruction-source.ts:32-45) turns every stat failure, and a non-directory, into "absent", so the diagnostic is gone. On the built CLI the merge-base logs ENOTDIR: not a directory, scandir .../.teamai/claudemd and this head logs nothing. Swallowing only ENOENT keeps the test as it is:
try {
- const stat = await fs.stat(path.join(repoPath, dir));
- return stat.isDirectory() ? dir : null;
- } catch {
- return null;
+ await fs.readdir(path.join(repoPath, dir));
+ return dir;
+ } catch (error) {
+ if (error instanceof Error && 'code' in error && error.code === 'ENOENT') return null;
+ throw error;
}[P1 blocking] Remove from either directory is not reachable
The body says the handler resolves its directories "for push, pull and remove", but teamai remove claudemd root-note.md --force prints Unsupported resource type: claudemd. Supported types: skills, rules, agents, mcp on both builds: REMOVABLE_TYPES (src/remove.ts:12) excludes it, and nothing else calls RepoResourceHandler.removeItem. The new removal loop (repo-resource.ts:284-300) also removes only the first copy it finds, so with both copies the claudemd/ one would come back on the next pull. Either drop the loop and the remove claim from the body, or make claudemd removable, which adds a command capability.
[P1 blocking] "New files go into the directory the repo already uses" is not implemented
sharedInstructionWriteDir, findSharedInstructionFile and duplicateSharedInstructionNames (src/shared-instruction-source.ts:60,76,104) are called only from their own tests. Push copies a file to the path the author wrote. The body and the new paragraph in docs/guide/distribution.md and its Chinese page describe routing that does not happen: a repo with only agentsmd/ keeps a new claudemd/ file where the author put it (and in self mode, per the first finding, does not push it). Either wire it in or remove the sentence and the unused helpers.
[P2 non-blocking] Doctor says both copies are delivered
With root-note.md in both directories, self-mode doctor prints claudemd: "root-note.md" is defined in agentsmd/root-note.md and claudemd/root-note.md (legacy mode: all of them are in the managed block), while only the agentsmd/ copy is in the block. buildNamespaceNotes (src/doctor-delivery.ts:2837) reuses the legacy-namespace wording. A note that names the winning copy would say what pull did, for example "root-note.md" is delivered from agentsmd/; claudemd/root-note.md is not delivered. The body speaks of a warning for this case; pull prints none.
[P2 non-blocking] Doctor misses the same conflict in role mode
With init --role frontend and both copies, pull delivers the agentsmd/ one and doctor prints no claudemd note. The duplicate check runs only in the legacy branch of readNamespaceNoteInputs (src/doctor-delivery.ts:2850-2866).
[P2 non-blocking] teamai status counts both copies
status shows claudemd: 4 where pull delivers 3: scanTeamForPull (repo-resource.ts:243-265) lists both copies. Skipping a name already seen in an earlier directory matches pull.
[P3 nit]
skill-data/setup/references/manage-admin.md:205-208: the new paragraph has no blank line before "A replacement must be usable to replace anything…", so that sentence joins it.docs/guide/distribution.mdand the Chinese page have three blank lines after the new section.
The branch also conflicts with main in src/desired.ts after #1691 and needs a rebase. CI on macOS Node 22 and 24 and E2E shard 2/3 was still running when I checked.
@jeff-r2026 your call on the scope: whether remove should take shared instructions and whether new files should follow the repo's directory, or whether both claims leave this PR.
|
The first CI run was red on all five Cause: Fixed in
One correction to my own PR description: I wrote "full suite — passed". It did not, and I should not have said so without the evidence. The full suite has 36 failures on this machine, on I ran both in separate worktrees to get those numbers. With the fix, the branch is back to the baseline's 36. CI on the new head will confirm. |
|
All four earlier findings remain unresolved in the current diff:
The PR description includes a representative real-CLI pull/doctor record, satisfying the testing-record requirement. No PR code was run, built, or installed. |
SaulMoro
left a comment
There was a problem hiding this comment.
This was generated by AI during triage.
fe7fbf5 fixes the Lint & Test failure the way I'd expect: a claudemd file in place of the directory counts as present again, so listFiles raises ENOTDIR and pull logs it as before. Dropping the unused duplicateSharedInstructionNames is fine. I read the delta only and did not rerun the CLI; it touches no other file.
The rest of my earlier review still applies at this head, as the CI review also says: self-mode push of a new file in a directory main lacks, remove from either directory, the write-directory claim (sharedInstructionWriteDir and findSharedInstructionFile still have no caller), the two doctor notes, the status count, and the rebase on src/desired.ts.
… source directory
The shared-instruction source directory is the repo's convention, not the
resource's identity: `agentsmd/` works exactly like `claudemd/`, for teams
whose shared-instruction convention is `AGENTS.md` (Claude Code reads it
natively since v2.1.277). No forced migration — existing `claudemd/` repos
keep working.
- new src/shared-instruction-source.ts: the accepted source directories, the
preferred one (agentsmd wins a name conflict), the write directory (the one
the repo already uses), and a lookup for a file across both
- resources/desired.ts: collect from every source directory the repo has, one
copy per file name — the preferred directory wins, so a repo keeping both
delivers each file once
- resources/repo-resource.ts: the handler resolves its source directories per
repo, for push, pull and remove
- doctor-delivery.ts: the duplicate note names the directory each copy is in
- benchmark/team-without.ts: `agentsmd/` gets the same "why it changes
nothing" reason as `claudemd/`
- docs: the two directories and the both-present rule, in both guide
languages and the product overview
Real-CLI record (single-repo mode, `teamai pull`):
$ mkdir -p .teamai/agentsmd .teamai/claudemd
$ echo 'AGENTSMD ROOT NOTE' > .teamai/agentsmd/root-note.md
$ echo 'CLAUDEMD ROOT NOTE' > .teamai/claudemd/root-note.md
$ teamai pull
✔ [workspace] Synced shared instructions (2 file(s))
$ grep -c 'AGENTSMD ROOT NOTE' .claude/rules/teamai-context.md
1
$ grep -c 'CLAUDEMD ROOT NOTE' .claude/rules/teamai-context.md
0
$ teamai doctor
ℹ claudemd: "root-note.md" is defined in agentsmd/root-note.md and claudemd/root-note.md
Co-Authored-By: Claude Code <[email protected]>
`existingSharedInstructionDirs` filtered on `stat().isDirectory()`, so a repo whose `claudemd` is a regular file looked like a repo with no shared instructions: the ENOTDIR that `readdir` used to raise never reached pull's handler, and the "shared-instruction discovery fails" case stopped being reported. Existence is now by path, as it was before this feature: the directory is listed, and a file in its place raises the same failure pull already knows how to report as a skipped sync. Co-Authored-By: Claude Code <[email protected]>
- push scans BOTH source directories, so a first `agentsmd/` file is pushable even when the team repo has only `claudemd/`. The local scan took its directories from the team repo's tree, so a new file in the other directory was never offered to push. - `existingSharedInstructionDirs` swallows only ENOENT. A `claudemd` that is a regular file raises ENOTDIR again, which pull reports as a skipped sync, as before this feature. - `scanTeamForPull` counts a same-named file once, like pull delivers it, so `teamai status` no double-counts a repo keeping both directories. - doctor names the copy pull delivers and the one it leaves out, in the role mode as well as the legacy one. - drop `sharedInstructionWriteDir`, `findSharedInstructionFile` and `duplicateSharedInstructionNames`: nothing called them, and the write directory a new file follows is the author's own choice, not a routing rule. The docs now say that instead. - rebase onto main. Co-Authored-By: Claude Code <[email protected]>
fe7fbf5 to
7978d41
Compare
|
Thanks — every P1 was real, and the two P2s and the P3s too. Addressed in P1 — self-mode push drops a new file in a source directory main does not have. Fixed: the local scan takes both source directories, not the ones the team repo already has. Real-CLI record in the PR body — a first P1 — Lint & Test fails on the ENOTDIR case. Fixed as you suggested, but with P1 — remove is not reachable. Agreed, and I took the claim out rather than the other way round: the PR body no longer says the handler resolves its directories "for remove", and there is now a Scope section saying P1 — the write-directory claim. Taken out. P2 — doctor says both copies are delivered. Fixed: the note now names the copy pull delivers and the one it leaves out. P2 — doctor misses the conflict in role mode. Fixed: the check moved out of the legacy branch, so it runs in both modes. P2 — status counts both copies. Fixed: P3 — blank line in One more thing I owe you: my first PR description said "full suite — passed", and it had not. The suite has 36 failures here on On the precedence: |
The earlier push-discovery finding is resolved: push now scans both accepted directories regardless of baseline contents. I am not re-raising the removal finding; the supplied diff does not establish a reachable shared-instruction removal scenario. The description provides sufficient representative real-CLI verification. No PR code was run, built, or installed. |
SaulMoro
left a comment
There was a problem hiding this comment.
This was generated by AI during triage.
Thanks for the thorough round. I built 7978d41 and reran the earlier cases with the CLI in an isolated HOME against a local bare team repo. These are fixed:
| Earlier finding | 7978d41 |
|---|---|
| Self-mode push of a new file in a directory main lacks | pushed in every direction: no directory on main, claudemd/ only, agentsmd/ only |
ENOTDIR on a file where the directory should be |
logged as Shared instructions sync skipped: ENOTDIR again |
| Remove and write-directory claims | out of the body and both guides; the helpers are gone |
teamai status with both directories |
counts 3, as pull delivers |
| Doctor in role mode, root files | claudemd: "root-note.md" is delivered from agentsmd/; claudemd/ not delivered |
| Both blank-line nits | fixed |
Two doctor cases are still open. The body and both distribution guides say doctor names the copy pull delivers and the one it leaves out, so they matter for this PR.
[P2 non-blocking] Legacy mode still says both copies are in the managed block
With root-note.md in both directories and no role, doctor prints the new line and the old one:
claudemd: "root-note.md" is defined in agentsmd/root-note.md and claudemd/root-note.md (legacy mode: all of them are in the managed block)
claudemd: "root-note.md" is delivered from agentsmd/; claudemd/ not delivered
Pull delivers only the agentsmd/ copy. With the pair under agentsmd/backend/ and claudemd/backend/, only the first, wrong line prints. The legacy branch of buildNamespaceNotes (src/doctor-delivery.ts around 2831-2837) still groups both copies through repeatedNames. Leaving the shadowed copy out of that list keeps only the new note. This is also the CI review's first finding at this head.
[P2 non-blocking] A namespaced pair gets no note in role mode
With manifest/roles.yaml giving frontend the backend knowledge namespace, and note.md in both agentsmd/backend/ and claudemd/backend/, pull delivers the agentsmd/ copy and doctor prints no claudemd note ("All checks passed"). shadowedSharedInstructionNames (src/shared-instruction-source.ts:72) reads only root entries (:82). Comparing over the same ns/file keys claudemdCandidates uses would cover both this and the legacy case above. This is the CI review's second finding, and I agree with it.
[P2 non-blocking] The new removeItem loop is unreachable
src/resources/repo-resource.ts:301 still loops over both directories and stops at the first copy. Nothing reaches it for claudemd now that remove is out of scope, and it would bring back the fallback copy if remove were enabled later. The original single fs.rm would leave nothing to revisit.
I agree with the CI review that push is fixed, and that removal no longer has a reachable scenario. CI was still running at this head when I checked.
@jeff-r2026 your call on this one. What is left is the two doctor notes above, and the open design question the author raised: whether agentsmd/ should win a same-name file, or whether that should be a hard error.
…evel
The CI review bot found two more on the fixed head:
- the legacy duplicate note still claimed "all of them are in the managed
block" for a name the two source directories both define, while pull
delivers only one. The shadowed copies stay out of that note now, so it
says only what it can vouch for: duplicates within one directory.
- the shadowing report read only the root, so a conflict under a
knowledge namespace (`agentsmd/backend/note.md` against
`claudemd/backend/note.md`) went unreported while pull dropped the
fallback. The key is the path relative to the source directory, the way
pull identifies a file.
The removal loop in the handler is gone: `teamai remove` does not take
shared instructions (`REMOVABLE_TYPES` excludes them), so the loop was
unreachable, and reachable later it would have deleted one copy and left
the fallback to be delivered again.
Real-CLI record:
ℹ claudemd: "backend/ns-note.md" is delivered from agentsmd/; claudemd/ not delivered
ℹ claudemd: "root-note.md" is delivered from agentsmd/; claudemd/ not delivered
ℹ claudemd: "same.md" is defined in claudemd/frontend/same.md and claudemd/same.md (legacy mode: all of them are in the managed block)
Co-Authored-By: Claude Code <[email protected]>
|
The CI review bot ( P2 — doctor still claims the shadowed copies are delivered. The legacy duplicate note said "all of them are in the managed block" for a name both directories define, while pull delivers one. The shadowed copies stay out of that note now, so it only says what it can vouch for — duplicates within one directory. P2 — doctor misses conflicts under a knowledge namespace. The shadowing report read only the root. A conflict under a namespace ( P1 — removal resurrects its fallback. The bot did not re-raise it, noting the diff does not establish a reachable removal scenario. That is right: Real-CLI record: The first two are the cross-directory conflicts; the third is a duplicate within one directory, which is what the legacy note is about.
|
The earlier push-discovery, misleading legacy-message, and namespaced-conflict findings are resolved. The removal finding remains withdrawn because no reachable removal scenario was established. The description supplies sufficient representative real-CLI verification. Only the specified diff was read; no PR code was run, built, or installed. |
SaulMoro
left a comment
There was a problem hiding this comment.
This was generated by AI during triage.
dda4c09 closes the points from my last comment:
- Legacy note: it no longer claims a shadowed copy is in the managed block.
- Namespaced pairs: they are now reported, keyed by the path relative to the source directory, which is how pull identifies a file.
removeItem: it is back to main's singlefs.rm.
I agree that removal has no reachable scenario.
The CI review's two new findings on this head both hold from the code:
[P2 non-blocking] Role mode reports a namespace nobody receives. shadowedSharedInstructionFiles scans every namespace directory, and readNamespaceNoteInputs passes the result through unfiltered in both modes (src/doctor-delivery.ts, around 2875). Take a frontend member whose role does not receive backend, with backend/note.md in both directories. Pull delivers neither copy, but doctor still prints claudemd: "backend/note.md" is delivered from agentsmd/. Fix: in the namespaced branch, keep only the shadowed paths that collectClaudemdFiles(localConfig, roleContext) actually collected.
[P2 non-blocking] The legacy filter drops the delivered copy as well. shadowedPaths holds relative paths, and claudemdFiles.filter(...) compares only entry.segments. So for note.md in both directories, the agentsmd/note.md that pull delivers is dropped along with claudemd/note.md. Take agentsmd/note.md, claudemd/note.md and agentsmd/backend/note.md: the within-directory duplicate between agentsmd/note.md and agentsmd/backend/note.md is no longer reported. Fix: drop only the shadowed directories' copies, for example !team.shadowed.some((s) => s.path === key && s.shadowedIn.includes(entry.dir)).
Neither changes what pull delivers. Both are doctor wording, which the body and both distribution guides describe. Nothing blocking is left, so I'm withdrawing my earlier request for changes.
@jeff-r2026 your call on this one. What is left is the two doctor notes above, and the open design question the author raised: whether agentsmd/ should win a same-name file, or whether that should be a hard error.
The blocking findings are fixed at dda4c09; what is left is non-blocking, see the latest review.
Two findings from the review on dda4c09: - In role mode the shadowing report named every conflict in the repo, including a namespace the member's role does not carry. Pull delivers neither copy of such a file, so doctor claimed a delivery that never happens. The note now keeps only the conflicts the collection actually delivered, which `collectClaudemdFiles` reports as the source paths of the files in the block. - The legacy duplicate note dropped the delivered copy as well as the shadowed one, hiding a duplicate that really is in the block. Only the copies the shadowing note names as shadowed stay out of it. Co-Authored-By: Claude Code <[email protected]>
|
Both P2s fixed in Role mode reports a namespace nobody receives. The legacy filter drops the delivered copy as well. Only the copies the shadowing note names as shadowed stay out of the legacy note now — the delivered copy is still there, so a duplicate that really is in the block is still reported. Real-CLI record, all three kinds of note side by side: The first is a duplicate within one directory, the other two are cross-directory conflicts.
On the design question you left open — whether |
|
No actionable findings in the specified diff.
The PR description documents sufficient testing, including representative real-CLI pull and push verification. No additional provider × agent coverage is required. Only the specified diff was read. No PR code was run, built, or installed. |
SaulMoro
left a comment
There was a problem hiding this comment.
This was generated by AI during triage.
e8a458b fixes both doctor notes from my last comment. I checked each against the code:
- Role mode:
collectClaudemdFilesnow returns thesourceof every candidate the block carries (<dir>/<file>or<dir>/<ns>/<file>, asclaudemdCandidatesbuilds it). The shadowing note keeps only conflicts whosedeliveredPath, in the same form, is among those sources. A namespace the role does not receive is never a candidate, so it gets no note. - Legacy mode: the filter now drops only the copies the shadowing note lists as shadowed (
s.shadowedIn.includes(entry.dir)). The delivered copy stays, so a duplicate within one directory is still reported.
I agree with the CI review on this head: no actionable findings. Nothing from my earlier reviews is open.
@jeff-r2026 your call on this one. What is left is the design question: whether agentsmd/ should win a same-name file, as now, with doctor naming the delivered and the dropped copy, or whether that should be a hard error. The author's reasoning is in the comment above.
jeff-r2026
left a comment
There was a problem hiding this comment.
Design decision (jeffyxu): option A — agentsmd/ wins a same-name file, and doctor names the delivered and the dropped copy. A hard error would fail every pull during a claudemd/ → agentsmd/ migration.
Verified e8a458b merged onto main 2758bad: tsc, lint and build pass; shared-instruction-source, doctor-namespace-notes, pull-skip-sync, pull-namespace-override, benchmark-team-without, status-list and commands-reference pass (173/173). Real CLI (--provider git --agent claude, isolated HOME, local bare team repo with agentsmd/note.md, claudemd/note.md and claudemd/only.md): pull delivers the agentsmd/ note.md and claudemd/only.md into ~/.claude/CLAUDE.md, and doctor prints claudemd: "note.md" is delivered from agentsmd/; claudemd/ not delivered.
Implements #1682.
Why
The shared-instruction source directory is the repo's convention, not the resource's identity.
claudemd/carries a Claude-specific name even though its behavior is tool-independent, and Claude Code readsAGENTS.mdnatively since v2.1.277 — so a team whose shared-instruction convention isAGENTS.mdhas to name that directoryagentsmd/.The directory name changes; nothing else does. The namespace layout, the per-tool delivery and the file format are the same under either name.
What
src/shared-instruction-source.ts(new) — the accepted source directories, the preferred one, and the names a repo defines in more than one of them.src/resources/desired.ts— collect from every source directory the repo has, one copy per file name: the preferred directory wins. A repo keeping both directories therefore delivers each file once, not twice.src/resources/repo-resource.ts— the handler resolves its source directories per repo, for push and pull. Push scans both directories, so a firstagentsmd/file is pushable even when the team repo still has onlyclaudemd/.src/doctor-delivery.ts— a note naming the copy pull delivers and the one it leaves out, in the role mode as well as the legacy one.src/benchmark/team-without.ts—agentsmd/gets the same "why it changes nothing" reason asclaudemd/; without it a path underagentsmd/was silently skipped.Behavior
claudemd/keeps working unchanged — no forced migration.agentsmd/is an accepted alternative with identical semantics.agentsmd/file whileclaudemd/is still on the team repo.agentsmd/copy wins), files whose names differ are all delivered.teamai doctornames the copy pull delivers and the one it leaves out.The precedence is my call, not the issue's — happy to flip it, or to make it a hard error instead of a warning, before this lands.
Scope
Two things this PR does not do, which an earlier version of its description claimed:
teamai removedoes not take shared instructions.REMOVABLE_TYPES(src/remove.ts) does not includeclaudemd, and nothing reaches the handler'sremoveItemfor it. Makingremovecover shared instructions is a command capability, and @jeff-r2026 has the call on it.Tests
src/__tests__/shared-instruction-source.test.ts(new) — 8 cases:claudemd/unchanged,agentsmd/with the same rules, same-name conflict resolved to one copy, different names all delivered, directory listing, a source directory that is not a directory (the failure stays visible), the shadowed-name report, and no report when the names differ.npm run typecheck— clean.npm run lint— clean.pull-skip-sync,pull-namespace-override,doctor-namespace-notes,benchmark-team-without,status-list,push-namespaces— 168 passed.The full suite on this machine
The full suite has failures here, on
origin/mainas well —gitlab-mr-*,git-discovery,gitlab-providerand others that depend on the local environment:I measured that in a separate worktree on
origin/main, so the number is comparable. An earlier head of this PR was one worse (37) — that one was mine, thepull-skip-synccase, and it is fixed.Real-CLI record
Single-repo mode, against a team repo holding both directories:
The content reached
.claude/rules/teamai-context.md,.github/instructions/teamai-context.instructions.mdand.codebuddy/rules/teamai-context.md— the per-tool delivery is unchanged.Push of a first
agentsmd/file, with the team repo still holding onlyclaudemd/:And with the directory moved away, the file is no longer offered:
Limitations
teamai removedoes not take shared instructions (REMOVABLE_TYPESexcludes them), so a shared instruction is removed by editing the team repo, not by a command.agentsmd/copy is the one delivered. That precedence is my choice — the issue leaves it open — and a hard error would be a different, defensible design.Disclosure
This PR was written with AI assistance: a Claude Code session (model: MiniMax-M3.1-Flash) planned the change, wrote the implementation, the unit tests and the doc updates, and ran the checks and the real-CLI record above.
I am wangchongfei. I reviewed the whole diff line by line, wrote the tests, and ran the checks myself before opening this. I take full responsibility for the change.
I am stating this here, and on my profile, because a maintainer should know who — and what — they are reviewing.