Skip to content

Commit b8d0b7b

Browse files
kosakoclaude
andcommitted
Prune non-canonical instruction marker files even when asset exists (#48 review)
Codex PR review (should): instruction prune が tool 単位 all-or-nothing で、instruction asset があると instructions/* スキャンを丸ごとスキップしていた。canonical な INSTRUCTION_FILENAMES だけを保持し、それ以外の marker 付きファイルは asset 有無に かかわらず削除するようにした。回帰 self-test を追加。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 62b864f commit b8d0b7b

2 files changed

Lines changed: 30 additions & 3 deletions

File tree

scripts/lib/build.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,12 @@ def prune
171171
end
172172
end
173173

174-
# instruction: その tool 向け instruction asset が無ければ generated を削除する。
175-
next if instruction_expected[tool]
176-
174+
# instruction: 期待する canonical ファイル (INSTRUCTION_FILENAMES) 以外の
175+
# marker 付きファイルを削除する。instruction asset が無ければ canonical も対象。
176+
keep = instruction_expected[tool] ? ArtifactTargets::INSTRUCTION_FILENAMES[tool] : nil
177177
Dir.glob(File.join(@root, "generated", tool, "instructions", "*")).sort.each do |file|
178178
next unless File.file?(file)
179+
next if keep && File.basename(file) == keep
179180

180181
if InstructionMarker.parse(File.read(file))
181182
FileUtils.rm_f(file)

scripts/tests/build-test.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,32 @@ grep -q "pruned: generated/codex/instructions/AGENTS.md" "$tmp/out-iprune" || fa
245245
[ ! -e "$tmp/instr/generated/codex/instructions/AGENTS.md" ] || fail "orphan instruction should be removed"
246246
[ ! -e "$tmp/instr/generated/claude-code/instructions/CLAUDE.md" ] || fail "orphan claude instruction should be removed"
247247

248+
# --- case 4e: instruction asset があっても canonical 以外の marker ファイルは prune ---
249+
mkdir -p "$tmp/instr3/shared/instructions"
250+
cat > "$tmp/instr3/shared/instructions/personal-ops.md" <<'EOF'
251+
# ops
252+
EOF
253+
cat > "$tmp/instr3/shared/instructions/personal-ops.asset.yml" <<'EOF'
254+
schema_version: 1
255+
name: personal-ops
256+
kind: instruction
257+
visibility: public
258+
targets:
259+
- codex
260+
risk:
261+
prompt_injection: low
262+
privacy: low
263+
source:
264+
path: shared/instructions/personal-ops.md
265+
format: markdown
266+
EOF
267+
"$build" --root "$tmp/instr3" --quiet > /dev/null
268+
printf '<!-- agent-tools:managed v=1 repo=agent-tools name=personal-old target=codex artifact_kind=instruction source=shared/x.md build_id=sha256:old -->\nstale\n' \
269+
> "$tmp/instr3/generated/codex/instructions/STRAY.md"
270+
"$build" --root "$tmp/instr3" --prune > "$tmp/out-stray" 2>&1 || fail "prune should pass: $(cat "$tmp/out-stray")"
271+
[ -f "$tmp/instr3/generated/codex/instructions/AGENTS.md" ] || fail "canonical instruction must survive prune"
272+
[ ! -e "$tmp/instr3/generated/codex/instructions/STRAY.md" ] || fail "non-canonical marker file should be pruned"
273+
248274
# --- case 5: repository 本体が build できる ---
249275
repo_root=$(CDPATH= cd -- "$script_dir/../.." && pwd)
250276
"$build" --root "$repo_root" --quiet > "$tmp/out-repo" 2>&1 \

0 commit comments

Comments
 (0)