refactor(claude-md): split shared base into module fragments, inject name at runtime
Move every agent-specific instruction out of the shared container/CLAUDE.md
so the base is genuinely universal. Persona/identity now comes from the
system-prompt addendum (buildSystemPromptAddendum now takes assistantName
and prepends "# You are {name}"). Per-module instructions live alongside
each MCP tool source:
container/agent-runner/src/mcp-tools/core.instructions.md
container/agent-runner/src/mcp-tools/scheduling.instructions.md
container/agent-runner/src/mcp-tools/self-mod.instructions.md
composeGroupClaudeMd() scans that directory and emits `module-<name>.md`
fragments as symlinks to /app/src/mcp-tools/<name>.instructions.md (valid
via the existing RO source mount). Skill fragments renamed to
`skill-<name>.md` for naming consistency with `module-*` and `mcp-*`.
Mount tightening so composer-managed files can't be clobbered by agent
writes: nested RO mounts for /workspace/agent/CLAUDE.md and
/workspace/agent/.claude-fragments/. CLAUDE.local.md (per-group memory)
stays RW as the only writable CLAUDE.md-family file.
.gitignore: ignore CLAUDE.local.md, .claude-shared.md, .claude-fragments/
everywhere, and simplify groups/ rules to ignore the whole tree (per-
installation state, not tracked).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -26,6 +26,11 @@ import type { AgentGroup } from './types.js';
|
||||
// dance instead of existsSync), valid inside the container via RO mounts.
|
||||
const SHARED_CLAUDE_MD_CONTAINER_PATH = '/app/CLAUDE.md';
|
||||
const SHARED_SKILLS_CONTAINER_BASE = '/app/skills';
|
||||
const SHARED_MCP_TOOLS_CONTAINER_BASE = '/app/src/mcp-tools';
|
||||
|
||||
// Host-side source paths used to discover fragment sources at compose time.
|
||||
// Resolved at call time (process.cwd() = project root) so tests can swap cwd.
|
||||
const MCP_TOOLS_HOST_SUBPATH = path.join('container', 'agent-runner', 'src', 'mcp-tools');
|
||||
|
||||
const COMPOSED_HEADER = '<!-- Composed at spawn — do not edit. Edit CLAUDE.local.md for per-group content. -->';
|
||||
|
||||
@@ -59,7 +64,7 @@ export function composeGroupClaudeMd(group: AgentGroup): void {
|
||||
for (const skillName of fs.readdirSync(skillsHostDir)) {
|
||||
const hostFragment = path.join(skillsHostDir, skillName, 'instructions.md');
|
||||
if (fs.existsSync(hostFragment)) {
|
||||
desired.set(`${skillName}.md`, {
|
||||
desired.set(`skill-${skillName}.md`, {
|
||||
type: 'symlink',
|
||||
content: `${SHARED_SKILLS_CONTAINER_BASE}/${skillName}/instructions.md`,
|
||||
});
|
||||
@@ -67,7 +72,25 @@ export function composeGroupClaudeMd(group: AgentGroup): void {
|
||||
}
|
||||
}
|
||||
|
||||
// MCP server fragments — inline instructions from container.json.
|
||||
// Built-in module fragments — every MCP tool source file that ships a
|
||||
// sibling `<name>.instructions.md`. These describe how the agent should
|
||||
// use that module's MCP tools (schedule_task, install_packages, etc.).
|
||||
// Always included — these are built-in, not toggleable.
|
||||
const mcpToolsHostDir = path.join(process.cwd(), MCP_TOOLS_HOST_SUBPATH);
|
||||
if (fs.existsSync(mcpToolsHostDir)) {
|
||||
for (const entry of fs.readdirSync(mcpToolsHostDir)) {
|
||||
const match = entry.match(/^(.+)\.instructions\.md$/);
|
||||
if (!match) continue;
|
||||
const moduleName = match[1];
|
||||
desired.set(`module-${moduleName}.md`, {
|
||||
type: 'symlink',
|
||||
content: `${SHARED_MCP_TOOLS_CONTAINER_BASE}/${entry}`,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// MCP server fragments — inline instructions from container.json for
|
||||
// user-added external MCP servers.
|
||||
for (const [name, mcp] of Object.entries(config.mcpServers)) {
|
||||
if (mcp.instructions) {
|
||||
desired.set(`mcp-${name}.md`, {
|
||||
|
||||
@@ -5,13 +5,7 @@ import { readEnvFile } from './env.js';
|
||||
import { isValidTimezone } from './timezone.js';
|
||||
|
||||
// Read config values from .env (falls back to process.env).
|
||||
const envConfig = readEnvFile([
|
||||
'ASSISTANT_NAME',
|
||||
'ASSISTANT_HAS_OWN_NUMBER',
|
||||
'ONECLI_URL',
|
||||
'ONECLI_API_KEY',
|
||||
'TZ',
|
||||
]);
|
||||
const envConfig = readEnvFile(['ASSISTANT_NAME', 'ASSISTANT_HAS_OWN_NUMBER', 'ONECLI_URL', 'ONECLI_API_KEY', 'TZ']);
|
||||
|
||||
export const ASSISTANT_NAME = process.env.ASSISTANT_NAME || envConfig.ASSISTANT_NAME || 'Andy';
|
||||
export const ASSISTANT_HAS_OWN_NUMBER =
|
||||
|
||||
@@ -215,7 +215,7 @@ function buildMounts(
|
||||
// Session folder at /workspace (contains inbound.db, outbound.db, outbox/, .claude/)
|
||||
mounts.push({ hostPath: sessDir, containerPath: '/workspace', readonly: false });
|
||||
|
||||
// Agent group folder at /workspace/agent (RW for working files + CLAUDE.md)
|
||||
// Agent group folder at /workspace/agent (RW for working files + CLAUDE.local.md)
|
||||
mounts.push({ hostPath: groupDir, containerPath: '/workspace/agent', readonly: false });
|
||||
|
||||
// container.json — nested RO mount on top of RW group dir so the agent
|
||||
@@ -225,6 +225,22 @@ function buildMounts(
|
||||
mounts.push({ hostPath: containerJsonPath, containerPath: '/workspace/agent/container.json', readonly: true });
|
||||
}
|
||||
|
||||
// Composer-managed CLAUDE.md artifacts — nested RO mounts. These are
|
||||
// regenerated from the shared base + fragments on every spawn; any
|
||||
// agent-side writes would be clobbered, so enforce read-only. Only
|
||||
// CLAUDE.local.md (per-group memory) remains RW via the group-dir mount.
|
||||
// `.claude-shared.md` is a symlink whose target (`/app/CLAUDE.md`) is
|
||||
// already RO-mounted, so writes through it fail regardless — no need for
|
||||
// a nested mount there.
|
||||
const composedClaudeMd = path.join(groupDir, 'CLAUDE.md');
|
||||
if (fs.existsSync(composedClaudeMd)) {
|
||||
mounts.push({ hostPath: composedClaudeMd, containerPath: '/workspace/agent/CLAUDE.md', readonly: true });
|
||||
}
|
||||
const fragmentsDir = path.join(groupDir, '.claude-fragments');
|
||||
if (fs.existsSync(fragmentsDir)) {
|
||||
mounts.push({ hostPath: fragmentsDir, containerPath: '/workspace/agent/.claude-fragments', readonly: true });
|
||||
}
|
||||
|
||||
// Global memory directory — always read-only.
|
||||
const globalDir = path.join(GROUPS_DIR, 'global');
|
||||
if (fs.existsSync(globalDir)) {
|
||||
|
||||
Reference in New Issue
Block a user