Fit the connector's per-request steps inside the compaction cut

Merged
JE
2mo ago
+558-408

Summary

basecamp-connect now leads with the steps each request needs, and the subagent's instructions move to skills/basecamp-connect/subagent.md. The subagent reads that file itself.

Why

  • After a compaction Claude Code re-attaches each invoked skill cut to its first 5,000 tokens (skills, "Skill content lifecycle").
  • On main the skill is ~13,300 tokens, and the cut falls before the handoff. A compacted orchestrator could acknowledge a request and then never dispatch it.
  • Follow-up to #887, as Jeremy asked. That PR makes a hook re-read the skill after compaction; this one makes the skill survive the cut without it.

Change

  • New order:
    1. Intro
    2. Running the connector (start and watch, then the request line)
    3. For each request (a. acknowledge, b. choose the repo, c. dispatch)
    4. Then rules, invocation, first-time setup, stopping and checking
  • Rules, invocation and setup matter at start, when the whole file is in context.
  • subagent.md is the former "The subagent's instructions" section. It inlines the boost loop it used to reach "as above".
  • The handoff passes the file's path and tells the subagent to read it in full first. The orchestrator no longer pastes ~4.3k tokens into every dispatch.
  • Two cross-references now point at subagent.md.
  • scripts/check-skill-drift.sh stripped everything before a second ---, so a file without frontmatter was skipped whole. It now strips frontmatter only when the file opens with one. make check-skill-drift checks subagent.md too.
  • internal/release/manifests_test.go requires subagent.md to ship.

Verification

  • Token counts from API usage (haiku, prompt with the text minus a baseline):
    • per-request part of the rendered body: 4,474 tokens
    • whole skill: 9,353 (main: 13,294)
    • subagent.md: 4,276
  • internal/connector/skill_layout_test.go:
    • The per-request steps end within 14,000 characters of the body, about 4,800 tokens at this file's ~2.9 chars/token, and come in order.
    • The subagent's steps live in subagent.md.
    • Both tests fail on main's skill.
  • make check-skill-drift passes: subagent.md has 12 commands and 23 flags validated, and appending a bogus command turns it red. make test-skill-drift, test-sync-skills, and go test ./internal/connector/ ./internal/release/ pass.
  • golangci-lint on this machine trips on a sibling worktree's file (../basecamp-cli-worktrees/security-ci-main/...), not on this diff.

Alternatives

  • Trimming prose to fit: the subagent text alone is ~4.3k tokens, so the order had to change anyway.
  • Keeping the subagent text in SKILL.md after the cut: the orchestrator would still paste it into every handoff and would need it after compaction. A file the subagent reads removes both costs.

Summary by cubic

Fits the basecamp-connect per-request steps within the 5,000-token cut Claude Code re-attaches after compaction. The skill ran ~13,300 tokens, so the cut fell before the handoff and a compacted orchestrator could acknowledge a request but never dispatch it.

  • Opens with start/watching, the request line, and acknowledge, choose-repo, dispatch; repo choice names ~/.config/basecamp-connect/last.json and its mapping shape. The post-as-the-agent rule joined the per-request part, which still posts a holding reply and a refusal itself and points at step 5 of subagent.md for the reply commands; the restart after a setup change stays before the cut. A connector change an owner asks for mid-run reads SKILL.md in full first, after the acknowledgement, since setup, stopping and checking sit past the cut, using the base directory as fallback if the placeholder reads literally. Rules, invocation, and first-time setup follow, and the skill drops to ~9,353 tokens.
  • Moves the subagent's instructions to subagent.md; the handoff passes ${CLAUDE_SKILL_DIR}/subagent.md, which Claude Code expands (with the skill's base directory as fallback if it reads literally), and tells the subagent to read it in full, so the orchestrator no longer pastes ~4.3k tokens into every handoff. The quoting rule joined the per-request window, since it sat past the cut while the boost still interpolated the acknowledgement, which would break on values like "I'm on it". The person lookup in subagent.md uses the handed-off account, which a Person id needs.
  • Adds a layout test holding the per-request steps within 14,000 characters (they end at 13,900, about 4,765 tokens), asserting they come in order, reading the handoff section alone to check it passes subagent.md and the read-it-first instruction, and asserting the '\'' escape in the acknowledgement and in subagent.md; it fails on main.
  • Fixes scripts/check-skill-drift.sh, which skipped frontmatter-less files whole; it now strips frontmatter only when present, checks subagent.md too, and two new drift-test fixtures cover frontmatter-less files.