diff --git a/setup b/setup index a9ab892c8..49a7171b5 100755 --- a/setup +++ b/setup @@ -474,6 +474,14 @@ link_claude_skill_dirs() { # Validate target isn't a symlink before creating the link if [ -L "$target/SKILL.md" ]; then rm "$target/SKILL.md"; fi _link_or_copy "$gstack_dir/$dir_name/SKILL.md" "$target/SKILL.md" + # Link the sections/ subdir for carved skills (v2 plan T9). The prefixed + # Claude skill dir otherwise holds only SKILL.md, so a runtime + # "Read sections/.md" 404s. Route through _link_or_copy so Windows + # gets a fresh copy (and re-copies on every ./setup, refreshing staleness). + if [ -d "$gstack_dir/$dir_name/sections" ]; then + if [ -e "$target/sections" ] || [ -L "$target/sections" ]; then rm -rf "$target/sections"; fi + _link_or_copy "$gstack_dir/$dir_name/sections" "$target/sections" + fi linked+=("$link_name") fi done @@ -1049,6 +1057,20 @@ if [ "$INSTALL_KIRO" -eq 1 ]; then -e "s|~/.codex/skills/gstack|~/.kiro/skills/gstack|g" \ -e "s|~/.claude/skills/gstack|~/.kiro/skills/gstack|g" \ "$skill_dir/SKILL.md" > "$target_dir/SKILL.md" + # Carved skills (v2 plan T9): rewrite + copy each sections/*.md the same way, + # so a runtime "Read sections/.md" resolves under ~/.kiro and doesn't + # leak a ~/.codex or ~/.claude path. Kiro builds from the codex output, so + # these section files only exist for skills that have been carved. + if [ -d "$skill_dir/sections" ]; then + mkdir -p "$target_dir/sections" + for section_file in "$skill_dir/sections"/*; do + [ -f "$section_file" ] || continue + sed -e 's|\$HOME/.codex/skills/gstack|$HOME/.kiro/skills/gstack|g' \ + -e "s|~/.codex/skills/gstack|~/.kiro/skills/gstack|g" \ + -e "s|~/.claude/skills/gstack|~/.kiro/skills/gstack|g" \ + "$section_file" > "$target_dir/sections/$(basename "$section_file")" + done + fi done echo "gstack ready (kiro)." echo " browse: $BROWSE_BIN" diff --git a/test/setup-sections-linking.test.ts b/test/setup-sections-linking.test.ts new file mode 100644 index 000000000..a6aa516ce --- /dev/null +++ b/test/setup-sections-linking.test.ts @@ -0,0 +1,48 @@ +/** + * Static invariant: the two install targets that cherry-pick SKILL.md (Claude + * prefixed dirs + Kiro) must ALSO install the sections/ subdir, or a carved + * skill's runtime "Read sections/.md" 404s. codex/factory/opencode link + * the whole generated dir, so sections ride along for free there. + * + * Matches the repo's static-tripwire style (setup-windows-fallback, + * cdp-session-cleanup). End-to-end "sections resolve in a temp install" runs in + * the group-5/6 functional pass once real ship/sections/ exist. + */ + +import { describe, test, expect } from 'bun:test'; +import * as fs from 'fs'; +import * as path from 'path'; + +const SETUP = fs.readFileSync(path.join(import.meta.dir, '..', 'setup'), 'utf-8'); + +/** Body of a shell function `name() { ... }` up to the closing line `}`. */ +function fnBody(src: string, name: string): string { + const start = src.indexOf(`${name}() {`); + if (start === -1) return ''; + const end = src.indexOf('\n}', start); + return src.slice(start, end === -1 ? undefined : end); +} + +describe('setup links sections/ for cherry-pick install targets', () => { + test('link_claude_skill_dirs links sections/ via _link_or_copy', () => { + const body = fnBody(SETUP, 'link_claude_skill_dirs'); + expect(body).toContain('sections'); + // sections install must route through the windows-safe helper, not raw ln. + expect(body).toMatch(/_link_or_copy\s+"\$gstack_dir\/\$dir_name\/sections"\s+"\$target\/sections"/); + expect(body).toMatch(/if \[ -d "\$gstack_dir\/\$dir_name\/sections" \]/); + }); + + test('kiro per-skill loop rewrites + copies sections/*', () => { + // Kiro builds from the codex output and sed-rewrites paths; sections must get + // the same rewrite so they resolve under ~/.kiro, not ~/.codex or ~/.claude. + expect(SETUP).toMatch(/if \[ -d "\$skill_dir\/sections" \]/); + expect(SETUP).toMatch(/mkdir -p "\$target_dir\/sections"/); + expect(SETUP).toContain('$target_dir/sections/$(basename "$section_file")'); + }); + + test('no raw ln introduced (windows-fallback invariant still holds)', () => { + // Every new line touching sections uses _link_or_copy or sed redirect, never ln. + const sectionLines = SETUP.split('\n').filter(l => l.includes('sections') && /\bln\s+-/.test(l)); + expect(sectionLines).toEqual([]); + }); +});