diff --git a/scripts/build.ps1 b/scripts/build.ps1 index 40793a6..88dfdf3 100644 --- a/scripts/build.ps1 +++ b/scripts/build.ps1 @@ -90,10 +90,11 @@ foreach ($agentDir in $sourceAgentDirs) { $agentNames += $name } -# Codex keeps the original rule-loading text unchanged: every rule ships as a plain -# file and AGENTS.md tells Codex to load the matching one by path. +# Codex: general.md is embedded directly into AGENTS.md, the same way Claude embeds +# it into CLAUDE.md, instead of only being referenced by path — guaranteed present +# either way, and safe even if a subagent's AGENTS.md inheritance is not guaranteed. $codexRuleLoading = @' -Always load and apply `rules/general.md` before starting any task. +General rules are embedded below. When programming, always load and apply `rules/security.md`. This includes implementing, modifying, debugging, reviewing, testing, and configuring software, scripts, hooks, infrastructure, and integrations. @@ -157,9 +158,12 @@ foreach ($platform in @('windows','linux')) { $claudeRuleLoading = "Always apply ``rules/general.md`` before starting any task, embedded below.`r`n`r`nDetect the languages, frameworks, tools, and change areas from the repository and the requested work. Invoke every matching rule skill before editing. Invoke all matching rule skills when multiple technologies apply.`r`n`r`nInvoke rule skills when their subject applies:`r`n`r`n" + ($claudeRuleSkillLines -join "`r`n") $sharedTemplate = Get-Content (Join-Path $shared 'global-instructions.md') -Raw - Set-Content (Join-Path $output "codex-$platform/AGENTS.md") ($sharedTemplate.Replace('__RULE_LOADING__', $codexRuleLoading)) -Encoding UTF8 - $generalContent = Get-Content (Join-Path $shared 'rules/general.md') -Raw + + $agentsContent = $sharedTemplate.Replace('__RULE_LOADING__', $codexRuleLoading) + $agentsContent = $agentsContent.TrimEnd() + "`r`n`r`n---`r`n`r`n$generalContent" + Set-Content (Join-Path $output "codex-$platform/AGENTS.md") $agentsContent -Encoding UTF8 + $claudeContent = $sharedTemplate.Replace('__RULE_LOADING__', $claudeRuleLoading) $claudeContent = $claudeContent.TrimEnd() + "`r`n`r`n---`r`n`r`n$generalContent" Set-Content (Join-Path $output "claude-$platform/CLAUDE.md") $claudeContent -Encoding UTF8 diff --git a/scripts/build.sh b/scripts/build.sh index 8b3c710..ee0fe90 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -80,10 +80,11 @@ for agent_dir in "${agent_dirs[@]}"; do agent_seen[$name]=1 done -# Codex keeps the original rule-loading text unchanged: every rule ships as a plain -# file and AGENTS.md tells Codex to load the matching one by path. +# Codex: general.md is embedded directly into AGENTS.md, the same way Claude embeds +# it into CLAUDE.md, instead of only being referenced by path — guaranteed present +# either way, and safe even if a subagent's AGENTS.md inheritance is not guaranteed. read -r -d '' codex_rule_loading <<'BLOCK' || true -Always load and apply `rules/general.md` before starting any task. +General rules are embedded below. When programming, always load and apply `rules/security.md`. This includes implementing, modifying, debugging, reviewing, testing, and configuring software, scripts, hooks, infrastructure, and integrations. @@ -152,10 +153,11 @@ Invoke rule skills when their subject applies: ${claude_rule_loading_list%$'\n'}" shared_template=$(<"$shared/global-instructions.md") -agents_content=${shared_template//__RULE_LOADING__/$codex_rule_loading} -printf '%s\n' "$agents_content" > "$output/codex-$platform/AGENTS.md" - general_content=$(<"$shared/rules/general.md") + +agents_content=${shared_template//__RULE_LOADING__/$codex_rule_loading} +printf '%s\n\n---\n\n%s\n' "${agents_content%$'\n'}" "$general_content" > "$output/codex-$platform/AGENTS.md" + claude_content=${shared_template//__RULE_LOADING__/$claude_rule_loading} printf '%s\n\n---\n\n%s\n' "${claude_content%$'\n'}" "$general_content" > "$output/claude-$platform/CLAUDE.md"