Skip to content

Turbocharge Claude Code, Cursor, Codex, Gemini & every coding agent: faster, cheaper, with contextual understanding specific to your codebase.

fix(init): explicit empty agent list selects nothing; validate ids before writing

Shrish Dwivedia7c3b6067c7e
diff --git a/src/cli.ts b/src/cli.ts
index 3cd3ea8f..0fb2e231 100644
--- a/src/cli.ts
+++ b/src/cli.ts
@@ -202,6 +202,16 @@ program
}
const repo = resolve(dir);
const explicit = Array.isArray(opts.agents) ? opts.agents : undefined;
+
+ if (explicit) {
+ const validIds = [...hostIds(), "claude"];
+ const unknown = explicit.filter((id) => !validIds.includes(id));
+ if (unknown.length) {
+ console.error(`✗ unknown agent id(s): ${unknown.join(", ")} — valid: ${validIds.join(", ")}`);
+ process.exit(1);
+ }
+ }
+
const wantClaude = !explicit || explicit.includes("claude");
if (wantClaude) {
@@ -223,10 +233,7 @@ program
for (const w of r.written) console.error(`✓ ${w.id}: ${w.path} (${w.action})`);
if (!explicit && !opts.allAgents && r.written.length === 0)
console.error("· no other agents detected (see --list-agents / --all-agents)");
- if (r.unknown.length) {
- console.error(`✗ unknown agent id(s): ${r.unknown.join(", ")} — valid: ${[...hostIds(), "claude"].join(", ")}`);
- process.exit(1);
- }
+ // r.unknown is always empty here — ids are validated above, before any writes.
}
console.error("\nDone. Claude Code gets live hooks + statusline; other agents read their instruction files.");
console.error("For LLM summaries: set OPENROUTER_API_KEY and run `graft build --deep`.");
diff --git a/src/hosts/init.ts b/src/hosts/init.ts
index 02d67ca6..fd950a72 100644
--- a/src/hosts/init.ts
+++ b/src/hosts/init.ts
@@ -39,7 +39,7 @@ export function runHostsInit(
let selected: HostTarget[];
let unknown: string[] = [];
- if (opts.agents?.length) {
+ if (opts.agents !== undefined) {
const byId = new Map(HOSTS.map((h) => [h.id, h]));
selected = opts.agents.flatMap((id) => byId.get(id) ?? []);
unknown = opts.agents.filter((id) => !byId.has(id));
diff --git a/test/hosts-init.test.ts b/test/hosts-init.test.ts
index 401bcc04..25586616 100644
--- a/test/hosts-init.test.ts
+++ b/test/hosts-init.test.ts
@@ -64,3 +64,36 @@ test('CLI: unknown agent id exits non-zero', () => {
}),
);
});
+
+test('explicit empty agents list writes nothing, even when home has agent dirs (no fallback to detection)', () => {
+ const home = fresh(); const repo = fresh();
+ mkdirSync(join(home, '.cursor'));
+ const r = runHostsInit(repo, { home, agents: [] });
+ assert.deepEqual(r.written, []);
+ assert.ok(!existsSync(join(repo, '.cursor')));
+});
+
+test('CLI: --agents claude with --no-build writes .claude/ but no other-agent files', () => {
+ const repo = fresh();
+ execFileSync(process.execPath, ['--import', 'tsx', 'src/cli.ts', 'init', repo, '--no-build', '--agents', 'claude'], {
+ encoding: 'utf8',
+ });
+ assert.ok(existsSync(join(repo, '.claude')));
+ assert.ok(!existsSync(join(repo, 'AGENTS.md')));
+ assert.ok(!existsSync(join(repo, 'GEMINI.md')));
+ assert.ok(!existsSync(join(repo, '.cursor')));
+});
+
+test('CLI: --agents claude gemini nope exits non-zero and leaves repo untouched (validation before writes)', () => {
+ const repo = fresh();
+ assert.throws(() =>
+ execFileSync(
+ process.execPath,
+ ['--import', 'tsx', 'src/cli.ts', 'init', repo, '--no-build', '--agents', 'claude', 'gemini', 'nope'],
+ { encoding: 'utf8', stdio: 'pipe' },
+ ),
+ );
+ assert.ok(!existsSync(join(repo, '.claude')));
+ assert.ok(!existsSync(join(repo, 'GEMINI.md')));
+ assert.ok(!existsSync(join(repo, 'AGENTS.md')));
+});