Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/__tests__/pull-skip-sync.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,7 @@ describe('enabledAgents whitelist on pull inject, skip-sync, and cleanup (#510)'
);
await fse.ensureDir(path.join(repoPath, 'claudemd', 'common'));
await fse.writeFile(path.join(repoPath, 'claudemd', 'common', 'note.md'), 'Shared team instructions.\n');
await fse.writeFile(path.join(repoPath, 'claudemd', 'shared.md'), 'Root-level shared instructions.\n');

vi.stubEnv('HOME', homeDir);
vi.mocked(detectProjectConfig).mockResolvedValue(null);
Expand Down Expand Up @@ -743,6 +744,7 @@ describe('enabledAgents whitelist on pull inject, skip-sync, and cleanup (#510)'
const claudeMd = await fse.readFile(path.join(homeDir, '.claude', 'CLAUDE.md'), 'utf8');
expect(claudeMd).toContain(TEAMAI_CULTURE_START);
expect(claudeMd).toContain(TEAMAI_CLAUDEMD_START);
expect(claudeMd).toContain('Root-level shared instructions.');
expect(claudeMd).toContain(TEAMAI_RECALL_RULES_START);

const codebuddyMd = await fse.readFile(path.join(homeDir, '.codebuddy', 'CODEBUDDY.md'), 'utf8');
Expand Down
14 changes: 11 additions & 3 deletions src/pull.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1520,8 +1520,8 @@ export function compileRecallRulesBlock(): string {
/**
* Collect claudemd .md files filtered by the user's active knowledge namespaces.
*
* Walks claudemd/<namespace>/*.md for each active namespace.
* Falls back to collecting ALL namespace dirs when no role context is available.
* Always collects root-level claudemd/*.md files, then walks claudemd/<namespace>/*.md
* for each active namespace. Root-level instructions are shared with every member.
*/
async function collectClaudemdFiles(
repoPath: string,
Expand All @@ -1530,6 +1530,15 @@ async function collectClaudemdFiles(
const claudemdDir = path.join(repoPath, 'claudemd');
if (!await pathExists(claudemdDir)) return [];

const contents: string[] = [];
const rootFiles = (await listFiles(claudemdDir))
.filter((f) => f.endsWith('.md'))
.sort();
for (const file of rootFiles) {
const content = await readFileSafe(path.join(claudemdDir, file));
if (content) contents.push(content);
}

// Determine which namespace dirs to scan
let namespaceDirs: string[];
if (roleContext) {
Expand All @@ -1539,7 +1548,6 @@ async function collectClaudemdFiles(
namespaceDirs = await listDirs(claudemdDir);
}

const contents: string[] = [];
for (const ns of namespaceDirs) {
const nsDir = path.join(claudemdDir, ns);
if (!await pathExists(nsDir)) continue;
Expand Down
Loading