Skip to content

Extract /statusline install logic into a tested script#12

Open
gering wants to merge 3 commits into
mainfrom
task/refactor-statusline-to-script
Open

Extract /statusline install logic into a tested script#12
gering wants to merge 3 commits into
mainfrom
task/refactor-statusline-to-script

Conversation

@gering

@gering gering commented Jun 17, 2026

Copy link
Copy Markdown
Owner

Summary

  • Move the /statusline install/enable/disable/uninstall/status logic out of 24 KB of SKILL.md prose into a deterministic, locally-testable shell script.
  • The skill becomes a thin wrapper: parse the argument, invoke the script, relay its output.
  • Closes the "render half is a script, install half is prose" gap from the architecture review (Prio 5). The render half (statusline-cks.sh) was already a script; now the install half is too.

Changes

  • New plugins/knowledge-system/scripts/statusline-install.sh (518 lines): marker-block injection/removal, # {{cks}} placement priority (placeholder → auto-detect → guided abort), version-gated renderer copy, per-project sentinel management, atomic python3 mutation with session backup + post-write verify (non-empty / marker-pair / bash -n / executable-bit), restore-on-failure.
  • SKILL.md shrunk 24 KB → 4.6 KB: argument parsing + script invocation + result presentation; user-facing docs (output format, custom placement, third-party tools) retained.
  • Version bump knowledge-system 1.7.0 → 1.8.0 (plugin.json + marketplace.json, in sync).

Readiness

  • ✅ README — verified current (behavior unchanged; pure refactor)
  • ✅ Version — bumped to 1.8.0 (both files in sync)
  • ➖ Changelog — N/A (repo has none)
  • ➖ Knowledge — N/A (no .claude/knowledge; applies the established prose→script pattern from /define, /rebase)
  • ✅ Tests — scripts/check-structure.py 0 errors; 16/16 functional sandbox tests pass
  • ➖ Lint/Build — N/A (declarative markdown/JSON; bash -n covered by the structure check)

Test plan

  • python3 scripts/check-structure.py → 0 errors
  • bash -n plugins/knowledge-system/scripts/statusline-install.sh
  • /statusline status in a project with .claude/knowledge or .claude/rules
  • /statusline install against a custom ~/.claude/statusline.sh (placeholder + auto-detect paths), then uninstall — confirm clean round-trip and backup

🤖 Generated with Claude Code

gering and others added 3 commits June 17, 2026 12:23
Move install/enable/disable/uninstall/status out of 24 KB of SKILL.md
prose into scripts/statusline-install.sh; the skill becomes a thin
wrapper (parse argument, invoke script, relay output).

- New statusline-install.sh: marker-block injection/removal, # {{cks}}
  placement priority, version-gated renderer copy, per-project sentinel,
  atomic python3 mutation with backup + post-write verify
- Shrink SKILL.md from 24 KB to 4.6 KB
- Bump knowledge-system to 1.8.0 (plugin.json + marketplace.json)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Address findings from a multi-angle review of statusline-install.sh:

- restore_and_die: report a failed restore truthfully instead of a false
  "Restored from backup" when the cp itself fails
- mutate_file: read/write bytes so CRLF and non-ASCII host files survive
  untouched (text mode normalized newlines and choked under a C locale)
- inspect_markers: single marker-pair classifier shared by install,
  uninstall, and status — status now applies the BEGIN<END check and
  reports INVALID consistently instead of "installed and current"
- project_dir helper: per-project sentinel ops mirror the renderer's
  DIR-first precedence so disable/enable/status agree with render time
- validate START_LINE/END_LINE before mutation (grep-misfire failsafe)
- backup via mktemp (no same-second collision); post-write chmod warns
  instead of failing a correct install; status distinguishes an unreadable
  target from an absent marker; empty argument token defaults to status

Covered by a 22-case sandbox suite (all green); check-structure clean.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Second review-round findings on statusline-install.sh:

- mutate_file split on \n only (matching grep -n) instead of
  bytes.splitlines(), which also breaks on a lone \r and desynced the
  Python line indices from the bash-computed ones — a lone-CR line above
  the marker would splice the block at the wrong offset
- preserve the host file's permission bits across os.replace (copy the
  original mode onto the temp file), so install no longer drops group/other
  bits (e.g. 0770 -> 0644) or print a spurious "was dropped during write"
  on every run
- project_dir back to CLAUDE_PROJECT_DIR-first: a stray $DIR in the
  environment must not redirect the per-project sentinel (and this matches
  the SKILL.md contract)

Sandbox suite extended to 24 cases (lone-CR placement, mode preservation,
stray-$DIR sentinel); all green; check-structure clean.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant