From a4fab2b33952fc01a25a50efc0a1485728ea1998 Mon Sep 17 00:00:00 2001 From: r Date: Mon, 9 Nov 2026 15:14:28 -0500 Subject: [PATCH] fix(codex): shared instructions use the codex CLI-invocation convention (#2638) The Codex integration audit forbids `@claude-flow/cli@latest` anywhere in codex src. The shared-instructions module now takes the CLI prefix as a parameter: codex defaults to its generators' convention (`npx @claude-flow/cli`, unversioned, as AGENTS.md already uses), and the CLI passes its own `@latest` form, so the single-host CLAUDE.md is byte-identical (snapshots unchanged). finalizeDualInstructions checks AGENTS.md for the codex form. Both copies of the module stay byte-identical. Co-Authored-By: RuFlo --- .../init-dual-single-source-2638.test.ts | 12 +++- .../cli/src/init/claudemd-generator.ts | 30 +++++++--- .../cli/src/init/dual-instructions.ts | 4 +- .../cli/src/init/shared-instructions.ts | 55 +++++++++++-------- .../src/generators/shared-instructions.ts | 55 +++++++++++-------- 5 files changed, 96 insertions(+), 60 deletions(-) diff --git a/v3/@claude-flow/cli/__tests__/init-dual-single-source-2638.test.ts b/v3/@claude-flow/cli/__tests__/init-dual-single-source-2638.test.ts index b63ce9c859..720e047441 100644 --- a/v3/@claude-flow/cli/__tests__/init-dual-single-source-2638.test.ts +++ b/v3/@claude-flow/cli/__tests__/init-dual-single-source-2638.test.ts @@ -21,7 +21,7 @@ vi.mock('@claude-flow/codex', () => ({ })); import { initCommand } from '../src/commands/init.js'; -import { generateClaudeMd, generateDualClaudeMd, sharedSectionsForImport } from '../src/init/claudemd-generator.js'; +import { AGENTS_MD_CLI, generateClaudeMd, generateDualClaudeMd, sharedSectionsForImport } from '../src/init/claudemd-generator.js'; import { finalizeDualInstructions, writeDualClaudeMd } from '../src/init/dual-instructions.js'; import { executeInit } from '../src/init/executor.js'; import { DEFAULT_INIT_OPTIONS, MINIMAL_INIT_OPTIONS, type ClaudeMdTemplate, type InitOptions, type InitResult } from '../src/init/types.js'; @@ -59,6 +59,10 @@ describe('shared sections have one source (#2638)', () => { describe('generateDualClaudeMd (#2638)', () => { const agents = generateDualAgentsMd({ projectName: 'demo' }); + it('the dual AGENTS.md carries the shared sections in the form finalize checks for', () => { + for (const section of sharedSectionsForImport(AGENTS_MD_CLI)) expect(agents).toContain(section); + }); + for (const template of TEMPLATES) { it(`${template}: imports AGENTS.md, repeats no shared section, loses no line`, () => { const dual = generateDualClaudeMd(DEFAULT_INIT_OPTIONS, template); @@ -66,11 +70,13 @@ describe('generateDualClaudeMd (#2638)', () => { for (const section of sharedSectionsForImport()) expect(dual).not.toContain(section); expect(h2(dual).filter((h) => h2(agents).includes(h))).toEqual([]); - // Lossless: every line of the single-host file is in CLAUDE.md or AGENTS.md. + // Lossless: every line of the single-host file is in CLAUDE.md or AGENTS.md + // (AGENTS.md invokes the CLI in the codex generators' form). const single = generateClaudeMd(DEFAULT_INIT_OPTIONS, template); + const asAgents = (l: string) => l.split('npx @claude-flow/cli@latest').join(AGENTS_MD_CLI); const missing = single.split('\n') .filter((l) => l.trim() && !/^#{1,3} /.test(l)) - .filter((l) => !dual.includes(l) && !agents.includes(l)); + .filter((l) => !dual.includes(l) && !agents.includes(asAgents(l))); expect(missing).toEqual([]); }); } diff --git a/v3/@claude-flow/cli/src/init/claudemd-generator.ts b/v3/@claude-flow/cli/src/init/claudemd-generator.ts index d1190a2a7f..d8510f311f 100644 --- a/v3/@claude-flow/cli/src/init/claudemd-generator.ts +++ b/v3/@claude-flow/cli/src/init/claudemd-generator.ts @@ -11,7 +11,8 @@ import { AGENTS_MD_IMPORT, CLAUDE_RULE_INSERT_AT, SHARED_RULE_LINES, - SWARM_ROUTING_BODY, + DEFAULT_CLI, + swarmRoutingBody, sharedAgentTypes, sharedBuildAndTest, sharedCliQuickRef, @@ -24,6 +25,9 @@ import { // mirror of the codex module that writes them into AGENTS.md). Everything // left in this file is Claude-specific, or a template extra. +/** How this file's sections invoke the CLI (single-host CLAUDE.md form). */ +const CLI = 'npx @claude-flow/cli@latest'; + /** Claude-only: the Claude Code Bash tool suggests this trailer; Codex has its own commit rule. */ const CO_AUTHORED_BY_RULE = '- NEVER add a `Co-Authored-By` trailer to user commits unless this project\'s `.claude/settings.json` has `attribution.commit` set (#2078). The Claude Code Bash tool may suggest one in its default commit-message template — ignore it. `Co-Authored-By` is semantic authorship attribution under git/GitHub convention; the tool is the facilitator, not a co-author.'; @@ -144,12 +148,12 @@ const THREE_TIER_ROUTING = `### 3-Tier Model Routing | 3 | Sonnet/Opus | Architecture, security, complex reasoning |`; function swarmConfig(options: InitOptions): string { - return `## Swarm & Routing\n\n${swarmRuntimeConfig(options)}\n\n${SWARM_ROUTING_BODY}\n\n${THREE_TIER_ROUTING}`; + return `## Swarm & Routing\n\n${swarmRuntimeConfig(options)}\n\n${swarmRoutingBody(CLI)}\n\n${THREE_TIER_ROUTING}`; } -const memoryAndLearning = sharedMemoryAndLearning; +const memoryAndLearning = () => sharedMemoryAndLearning(CLI); const agentTypes = sharedAgentTypes; -const cliQuickRef = sharedCliQuickRef; +const cliQuickRef = () => sharedCliQuickRef(CLI); const buildAndTest = sharedBuildAndTest; function setupAndBoundary(): string { @@ -350,18 +354,26 @@ export function generateMinimalClaudeMd(options: InitOptions): string { return generateClaudeMd(options, 'minimal'); } -/** The sections a CLAUDE.md that imports AGENTS.md must not repeat. */ -export function sharedSectionsForImport(): string[] { +/** + * The shared sections, with the CLI invoked as `cli`. With the default (this + * file's form) they are what a CLAUDE.md importing AGENTS.md must not repeat; + * with `AGENTS_MD_CLI` they are exactly what the codex generator writes into + * AGENTS.md. + */ +export function sharedSectionsForImport(cli: string = CLI): string[] { return [ `## Rules\n\n${SHARED_RULE_LINES.join('\n')}`, - `## Swarm & Routing\n\n${SWARM_ROUTING_BODY}`, - sharedMemoryAndLearning(), + `## Swarm & Routing\n\n${swarmRoutingBody(cli)}`, + sharedMemoryAndLearning(cli), sharedAgentTypes(), sharedBuildAndTest(), - sharedCliQuickRef(), + sharedCliQuickRef(cli), ]; } +/** How the codex generator writes the CLI invocation into AGENTS.md. */ +export const AGENTS_MD_CLI = DEFAULT_CLI; + /** * #2638 dual mode: CLAUDE.md imports AGENTS.md (which carries the shared * sections) and keeps only what is Claude-specific, plus any template extras diff --git a/v3/@claude-flow/cli/src/init/dual-instructions.ts b/v3/@claude-flow/cli/src/init/dual-instructions.ts index cc337c13f0..e9a103a4d3 100644 --- a/v3/@claude-flow/cli/src/init/dual-instructions.ts +++ b/v3/@claude-flow/cli/src/init/dual-instructions.ts @@ -16,7 +16,7 @@ import * as fs from 'fs'; import * as path from 'path'; import type { InitOptions, InitResult } from './types.js'; -import { generateClaudeMd, generateDualClaudeMd, sharedSectionsForImport } from './claudemd-generator.js'; +import { AGENTS_MD_CLI, generateClaudeMd, generateDualClaudeMd, sharedSectionsForImport } from './claudemd-generator.js'; import { importsAgentsMd } from './shared-instructions.js'; export const DUAL_MIGRATION_HINT = @@ -87,7 +87,7 @@ export function finalizeDualInstructions(targetDir: string, claudeResult: InitRe agentsMd = fs.readFileSync(path.join(targetDir, 'AGENTS.md'), 'utf-8'); } catch { /* missing AGENTS.md: handled below */ } - const missing = sharedSectionsForImport().filter((section) => !agentsMd.includes(section)); + const missing = sharedSectionsForImport(AGENTS_MD_CLI).filter((section) => !agentsMd.includes(section)); if (missing.length === 0) { return { action: 'import', message: 'CLAUDE.md imports AGENTS.md (shared sections live once, in AGENTS.md)' }; } diff --git a/v3/@claude-flow/cli/src/init/shared-instructions.ts b/v3/@claude-flow/cli/src/init/shared-instructions.ts index 30ef53b08a..7d6369a8b7 100644 --- a/v3/@claude-flow/cli/src/init/shared-instructions.ts +++ b/v3/@claude-flow/cli/src/init/shared-instructions.ts @@ -17,6 +17,13 @@ * Pure: no imports, no I/O. */ +/** + * How the sections invoke the Ruflo CLI. The default is the codex generators' + * convention (unversioned, as in AGENTS.md); the CLI passes its own pinned-tag + * form so its single-host CLAUDE.md is unchanged. + */ +export const DEFAULT_CLI = 'npx @claude-flow/cli'; + /** Rules both hosts follow. The Claude-only commit-trailer rule is kept by the CLI. */ export const SHARED_RULE_LINES: readonly string[] = [ '- Do what has been asked; nothing more, nothing less', @@ -37,8 +44,9 @@ export function sharedRules(): string { } /** Swarm body shared by both hosts: init command, routing table, when to swarm. */ -export const SWARM_ROUTING_BODY = `\`\`\`bash -npx @claude-flow/cli@latest swarm init --topology hierarchical --max-agents 8 --strategy specialized +export function swarmRoutingBody(cli: string = DEFAULT_CLI): string { + return `\`\`\`bash +${cli} swarm init --topology hierarchical --max-agents 8 --strategy specialized \`\`\` ### Agent Routing @@ -54,24 +62,25 @@ npx @claude-flow/cli@latest swarm init --topology hierarchical --max-agents 8 -- ### When to Swarm - **YES**: 3+ files, new features, cross-module refactoring, API changes, security, performance - **NO**: single file edits, 1-2 line fixes, docs updates, config changes, questions`; - -export function sharedSwarmRouting(): string { - return `## Swarm & Routing\n\n${SWARM_ROUTING_BODY}`; } -export function sharedMemoryAndLearning(): string { +export function sharedSwarmRouting(cli: string = DEFAULT_CLI): string { + return `## Swarm & Routing\n\n${swarmRoutingBody(cli)}`; +} + +export function sharedMemoryAndLearning(cli: string = DEFAULT_CLI): string { return `## Memory & Learning ### Before Any Task \`\`\`bash -npx @claude-flow/cli@latest memory search --query "[task keywords]" --namespace patterns -npx @claude-flow/cli@latest hooks route --task "[task description]" +${cli} memory search --query "[task keywords]" --namespace patterns +${cli} hooks route --task "[task description]" \`\`\` ### After Success \`\`\`bash -npx @claude-flow/cli@latest memory store --namespace patterns --key "[name]" --value "[what worked]" -npx @claude-flow/cli@latest hooks post-task --task-id "[id]" --success true --store-results true +${cli} memory store --namespace patterns --key "[name]" --value "[what worked]" +${cli} hooks post-task --task-id "[id]" --success true --store-results true \`\`\` ### MCP Tools (use \`ToolSearch("keyword")\` to discover) @@ -97,7 +106,7 @@ npx @claude-flow/cli@latest hooks post-task --task-id "[id]" --success true --st | \`document\` | After API changes | \`\`\`bash -npx @claude-flow/cli@latest hooks worker dispatch --trigger audit +${cli} hooks worker dispatch --trigger audit \`\`\``; } @@ -125,17 +134,17 @@ npm run build && npm test \`\`\``; } -export function sharedCliQuickRef(): string { +export function sharedCliQuickRef(cli: string = DEFAULT_CLI): string { return `## CLI Quick Reference \`\`\`bash -npx @claude-flow/cli@latest init --wizard # Setup -npx @claude-flow/cli@latest swarm init --v3-mode # Start swarm -npx @claude-flow/cli@latest memory search --query "" # Vector search -npx @claude-flow/cli@latest hooks route --task "" # Route to agent -npx @claude-flow/cli@latest doctor --fix # Diagnostics -npx @claude-flow/cli@latest security scan # Security scan -npx @claude-flow/cli@latest performance benchmark # Benchmarks +${cli} init --wizard # Setup +${cli} swarm init --v3-mode # Start swarm +${cli} memory search --query "" # Vector search +${cli} hooks route --task "" # Route to agent +${cli} doctor --fix # Diagnostics +${cli} security scan # Security scan +${cli} performance benchmark # Benchmarks \`\`\` 26 commands, 140+ subcommands. Use \`--help\` on any command for details.`; @@ -145,14 +154,14 @@ npx @claude-flow/cli@latest performance benchmark # Benchmarks * Every shared section, in order. AGENTS.md (dual mode) writes all of them; * a CLAUDE.md that imports AGENTS.md must not repeat any of them. */ -export function generateSharedInstructions(): string[] { +export function generateSharedInstructions(cli: string = DEFAULT_CLI): string[] { return [ sharedRules(), - sharedSwarmRouting(), - sharedMemoryAndLearning(), + sharedSwarmRouting(cli), + sharedMemoryAndLearning(cli), sharedAgentTypes(), sharedBuildAndTest(), - sharedCliQuickRef(), + sharedCliQuickRef(cli), ]; } diff --git a/v3/@claude-flow/codex/src/generators/shared-instructions.ts b/v3/@claude-flow/codex/src/generators/shared-instructions.ts index 30ef53b08a..7d6369a8b7 100644 --- a/v3/@claude-flow/codex/src/generators/shared-instructions.ts +++ b/v3/@claude-flow/codex/src/generators/shared-instructions.ts @@ -17,6 +17,13 @@ * Pure: no imports, no I/O. */ +/** + * How the sections invoke the Ruflo CLI. The default is the codex generators' + * convention (unversioned, as in AGENTS.md); the CLI passes its own pinned-tag + * form so its single-host CLAUDE.md is unchanged. + */ +export const DEFAULT_CLI = 'npx @claude-flow/cli'; + /** Rules both hosts follow. The Claude-only commit-trailer rule is kept by the CLI. */ export const SHARED_RULE_LINES: readonly string[] = [ '- Do what has been asked; nothing more, nothing less', @@ -37,8 +44,9 @@ export function sharedRules(): string { } /** Swarm body shared by both hosts: init command, routing table, when to swarm. */ -export const SWARM_ROUTING_BODY = `\`\`\`bash -npx @claude-flow/cli@latest swarm init --topology hierarchical --max-agents 8 --strategy specialized +export function swarmRoutingBody(cli: string = DEFAULT_CLI): string { + return `\`\`\`bash +${cli} swarm init --topology hierarchical --max-agents 8 --strategy specialized \`\`\` ### Agent Routing @@ -54,24 +62,25 @@ npx @claude-flow/cli@latest swarm init --topology hierarchical --max-agents 8 -- ### When to Swarm - **YES**: 3+ files, new features, cross-module refactoring, API changes, security, performance - **NO**: single file edits, 1-2 line fixes, docs updates, config changes, questions`; - -export function sharedSwarmRouting(): string { - return `## Swarm & Routing\n\n${SWARM_ROUTING_BODY}`; } -export function sharedMemoryAndLearning(): string { +export function sharedSwarmRouting(cli: string = DEFAULT_CLI): string { + return `## Swarm & Routing\n\n${swarmRoutingBody(cli)}`; +} + +export function sharedMemoryAndLearning(cli: string = DEFAULT_CLI): string { return `## Memory & Learning ### Before Any Task \`\`\`bash -npx @claude-flow/cli@latest memory search --query "[task keywords]" --namespace patterns -npx @claude-flow/cli@latest hooks route --task "[task description]" +${cli} memory search --query "[task keywords]" --namespace patterns +${cli} hooks route --task "[task description]" \`\`\` ### After Success \`\`\`bash -npx @claude-flow/cli@latest memory store --namespace patterns --key "[name]" --value "[what worked]" -npx @claude-flow/cli@latest hooks post-task --task-id "[id]" --success true --store-results true +${cli} memory store --namespace patterns --key "[name]" --value "[what worked]" +${cli} hooks post-task --task-id "[id]" --success true --store-results true \`\`\` ### MCP Tools (use \`ToolSearch("keyword")\` to discover) @@ -97,7 +106,7 @@ npx @claude-flow/cli@latest hooks post-task --task-id "[id]" --success true --st | \`document\` | After API changes | \`\`\`bash -npx @claude-flow/cli@latest hooks worker dispatch --trigger audit +${cli} hooks worker dispatch --trigger audit \`\`\``; } @@ -125,17 +134,17 @@ npm run build && npm test \`\`\``; } -export function sharedCliQuickRef(): string { +export function sharedCliQuickRef(cli: string = DEFAULT_CLI): string { return `## CLI Quick Reference \`\`\`bash -npx @claude-flow/cli@latest init --wizard # Setup -npx @claude-flow/cli@latest swarm init --v3-mode # Start swarm -npx @claude-flow/cli@latest memory search --query "" # Vector search -npx @claude-flow/cli@latest hooks route --task "" # Route to agent -npx @claude-flow/cli@latest doctor --fix # Diagnostics -npx @claude-flow/cli@latest security scan # Security scan -npx @claude-flow/cli@latest performance benchmark # Benchmarks +${cli} init --wizard # Setup +${cli} swarm init --v3-mode # Start swarm +${cli} memory search --query "" # Vector search +${cli} hooks route --task "" # Route to agent +${cli} doctor --fix # Diagnostics +${cli} security scan # Security scan +${cli} performance benchmark # Benchmarks \`\`\` 26 commands, 140+ subcommands. Use \`--help\` on any command for details.`; @@ -145,14 +154,14 @@ npx @claude-flow/cli@latest performance benchmark # Benchmarks * Every shared section, in order. AGENTS.md (dual mode) writes all of them; * a CLAUDE.md that imports AGENTS.md must not repeat any of them. */ -export function generateSharedInstructions(): string[] { +export function generateSharedInstructions(cli: string = DEFAULT_CLI): string[] { return [ sharedRules(), - sharedSwarmRouting(), - sharedMemoryAndLearning(), + sharedSwarmRouting(cli), + sharedMemoryAndLearning(cli), sharedAgentTypes(), sharedBuildAndTest(), - sharedCliQuickRef(), + sharedCliQuickRef(cli), ]; }