Skip to content

fix(preamble): echo SESSIONS count so CLAUDE.md rules can read it (#1651 Defect A)#1747

Open
0xDevNinja wants to merge 1 commit into
garrytan:mainfrom
0xDevNinja:fix/1651-sessions-echo
Open

fix(preamble): echo SESSIONS count so CLAUDE.md rules can read it (#1651 Defect A)#1747
0xDevNinja wants to merge 1 commit into
garrytan:mainfrom
0xDevNinja:fix/1651-sessions-echo

Conversation

@0xDevNinja
Copy link
Copy Markdown
Contributor

Summary

  • The preamble at scripts/resolvers/preamble/generate-preamble-bash.ts:23 computes _SESSIONS=$(find ~/.gstack/sessions -mmin -120 -type f | wc -l | tr -d ' ') but never echoes it. Every other preamble state value (BRANCH, PROACTIVE, SKILL_PREFIX, REPO_MODE, TELEMETRY, EXPLAIN_LEVEL, QUESTION_TUNING, LEARNINGS, ARTIFACTS_SYNC, ...) is echoed for the calling agent to read; SESSIONS is the lone hole.
  • Any CLAUDE.md rule that points at "the preamble's session count" has no value to read and silently ships non-functional, as the reporter caught on a post-ship audit.
  • Add echo "SESSIONS: $_SESSIONS" next to the existing BRANCH/PROACTIVE/SKILL_PREFIX block in the preamble, plus an invariant test in test/gen-skill-docs.test.ts that fails if any SKILL.md containing the _SESSIONS=$(find computation no longer echoes the value.

Closes #1651 Defect A only.

Out of scope (Defect B)

The reporter's Defect B — marker mtime falling outside the 2h window for long-running sessions that don't invoke a gstack skill in that span — needs hook-infra work (PreToolUse refresh on every tool call) and is a separate change with broader surface area. Leaving it for a follow-up so this PR stays small and safe to land.

Diff shape

  • 1 resolver edit: +1 echo line
  • 1 test addition: +30 lines (invariant pinning the echo across all generated SKILL.md files)
  • 47 regenerated SKILL.md files (no manual edits; produced by bun run gen:skill-docs)

Tests

bun test test/skill-validation.test.ts test/gen-skill-docs.test.ts
# 712 pass, 7 fail (existing 711 + 1 new invariant)

The 7 failures are the pre-existing --dry-run freshness check cases on non-Claude hosts that reproduce on upstream/main with this branch's changes stashed — unrelated.

Verification

$ grep -n "SESSIONS:" ship/SKILL.md context-save/SKILL.md
ship/SKILL.md:47:echo "SESSIONS: $_SESSIONS"
context-save/SKILL.md:46:echo "SESSIONS: $_SESSIONS"

A user-side rule like

If preamble emits SESSIONS: 2 (or higher), force a worktree switch before any edit.

now has a value to read instead of having to inline the find itself.

- _SESSIONS=$(find ~/.gstack/sessions -mmin -120) was computed but never
  echoed; CLAUDE.md rules pointing at "the preamble's session count"
  had no value to read
- Add `echo "SESSIONS: $_SESSIONS"` next to BRANCH/PROACTIVE/etc.
- Add invariant test that every SKILL.md including the preamble echoes
  the value (locks Defect A from garrytan#1651)

Closes garrytan#1651 Defect A. Defect B (marker mtime refresh via PreToolUse
hook) needs hook-infra work — leaving for a follow-up.
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.

Two defects in _SESSIONS concurrent-session detection — value never echoed + marker TTL doesn't reflect 'currently active'

1 participant