Repository navigation
Fit the connector's per-request steps inside the compaction cut #890
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+558
−408
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
103c213
Fit the connector's per-request steps inside the compaction cut
jeremy fdd8ec5
Quote acknowledgements in both files, and test the handoff and drift …
jeremy 0a1f159
Assert the quoting rule itself, not its heading
jeremy 9315d7e
Hand off an expanded path, and keep last.json's path before the cut
jeremy 3e6c6c4
Keep the restart after a setup change before the cut, and a path fall…
jeremy 387b3e5
Read the whole skill before a connector change the owner asks for
jeremy 59cba47
Post as the agent from the per-request part, and acknowledge first
jeremy 479f4cd
Give the orchestrator's own replies their commands, and the reread it…
jeremy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| package connector | ||
|
|
||
| import ( | ||
| "os" | ||
| "path/filepath" | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| // perRequestBudget bounds where the orchestrator's per-request steps may end | ||
| // in the skill's body. After a compaction Claude Code re-attaches a skill cut | ||
| // to its first 5,000 tokens (code.claude.com/docs/en/skills, "Skill content | ||
| // lifecycle"); this skill's Markdown runs near 2.9 characters a token, so | ||
| // 14,000 characters stays under the cut with room to spare. A session cut | ||
| // short of the handoff can acknowledge a request and never dispatch it. | ||
| const perRequestBudget = 14000 | ||
|
|
||
| func readConnectSkill(t *testing.T, name string) string { | ||
| t.Helper() | ||
| raw, err := os.ReadFile(filepath.Join("..", "..", "skills", "basecamp-connect", name)) | ||
| require.NoError(t, err) | ||
| return strings.ReplaceAll(string(raw), "\r\n", "\n") | ||
| } | ||
|
|
||
| // skillBody drops the frontmatter, which Claude Code doesn't render into the | ||
| // conversation. | ||
| func skillBody(t *testing.T, skill string) string { | ||
| t.Helper() | ||
| parts := strings.SplitN(skill, "---\n", 3) | ||
| require.Len(t, parts, 3, "the skill opens with frontmatter") | ||
| return parts[2] | ||
| } | ||
|
|
||
| func TestTheConnectSkillKeepsEachRequestsStepsInsideTheCompactionCut(t *testing.T) { | ||
| body := skillBody(t, readConnectSkill(t, "SKILL.md")) | ||
| dispatch := strings.Index(body, "### c. Dispatch one background subagent") | ||
| require.GreaterOrEqual(t, dispatch, 0, "the handoff step is where this test looks for it") | ||
| end := strings.Index(body[dispatch:], "\n## ") | ||
| require.GreaterOrEqual(t, end, 0, "a section follows the handoff") | ||
| end += dispatch | ||
|
|
||
| previous := -1 | ||
| for _, step := range []string{ | ||
| "### 1. Start it, and watch its output", | ||
| "### 2. The request line", | ||
| "## For each request: acknowledge, choose the repo, hand off", | ||
| "### a. Acknowledge, within seconds", | ||
| "### b. Choose the repo", | ||
| "### c. Dispatch one background subagent", | ||
| } { | ||
| at := strings.Index(body, step) | ||
| assert.Greater(t, at, previous, "%q comes after the step before it", step) | ||
| previous = at | ||
| } | ||
| assert.Contains(t, body[:dispatch], "~/.config/basecamp-connect/last.json", | ||
| "choosing the repo names the file of confirmed mappings it reads") | ||
| assert.Contains(t, body[:dispatch], "read `${CLAUDE_SKILL_DIR}/SKILL.md` in full (if that reads literally, the\nbase directory this skill loaded from)", | ||
| "a connector change the owner asks for mid-run reads the setup steps past the cut first, from the base directory where the placeholder isn't expanded") | ||
| assert.Contains(t, body[:dispatch], "goes out as the agent,\nwith `--profile '<profile>'`", | ||
| "the orchestrator's own replies say to post as the agent") | ||
| // The refusal and the holding reply are posted before any subagent starts, | ||
| // so the orchestrator needs the reply commands, which live in subagent.md. | ||
| assert.Contains(t, body[:dispatch], "post as step 5 of `subagent.md` does", | ||
| "the orchestrator's own replies point at the reply commands") | ||
| assert.Contains(t, body[:dispatch], "after a change it restarts", | ||
| "a setup change the owner asks for mid-run says the connector restarts to take it") | ||
| assert.LessOrEqual(t, end, perRequestBudget, | ||
| "the per-request steps end at character %d of the skill's body; keep them within %d, moving setup and reference material after them", | ||
| end, perRequestBudget) | ||
| } | ||
|
|
||
| func TestTheSubagentReadsItsInstructionsFromTheirOwnFile(t *testing.T) { | ||
| skill := readConnectSkill(t, "SKILL.md") | ||
| subagent := readConnectSkill(t, "subagent.md") | ||
|
|
||
| assert.NotContains(t, skill, "## The subagent's instructions", "the subagent's instructions live in subagent.md") | ||
| dispatch := strings.Index(skill, "### c. Dispatch one background subagent") | ||
| require.GreaterOrEqual(t, dispatch, 0) | ||
| handoff := skill[dispatch:] | ||
| handoff = handoff[:strings.Index(handoff, "\n## ")] | ||
| assert.Contains(t, handoff, "`${CLAUDE_SKILL_DIR}/subagent.md`", "the handoff passes the file's path, which Claude Code expands") | ||
| assert.Contains(t, handoff, "read it in full before anything else", "the handoff tells the subagent to read it first") | ||
|
|
||
| // An acknowledgement such as "I'm on it" breaks a single-quoted command | ||
| // unless its quote is escaped, so both files say how. | ||
| acknowledge := skill[strings.Index(skill, "### a. Acknowledge, within seconds"):dispatch] | ||
| assert.Contains(t, acknowledge, "`'\\''`", "the acknowledgement step says how to quote a value") | ||
| assert.Contains(t, subagent, "`'\\''`", "the subagent's instructions say how to quote a value") | ||
|
jeremy marked this conversation as resolved.
|
||
| for _, step := range []string{"**Shell quoting.**", "**1. Acknowledge", "**5. Reply at `reply_to`", "**6. Report back", "**A participant asks, an operator authorizes.**"} { | ||
|
cubic-dev-ai[bot] marked this conversation as resolved.
|
||
| assert.Contains(t, subagent, step) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.