Claude Code answers a Skill call with "Launching skill: <name>" and sends the skill's SKILL.md after the results, as a text block headed "Base directory for this skill: …". Sinced84f58fd2(#5403) that text counts as the agent's own (desktopNote), so it is no longer said to the run as the user's, which was right, but nothing handed it to the run either: on the Claude subscription route a model that launched a skill saw "Launching skill: pdf" and never what the skill says. Every skill launched through magpie's Claude subscription lost its body. withSkillBodies appends each such body to its Skill call's result (two skills at once each get their own), else to the result it follows, else to the last; saidWithResults still leaves it out of the user's words. Found with a real Claude Code 2.1.316 in a sandbox HOME against the live gateway: a proxy between them showed the body in the request, and the model answered as if it had none. Run (mote, at this tree): - go test -tags nogui ./internal/gateway -run 'SkillBod|Desktop|TaskNotice|SaidWith|MidTurn|Notice' -count=1: ok. - TestSkillBodyRealClaudeCode parses the request Claude Code sent (testdata/claude-code-skill-launch.json: its own bytes, trimmed to the launch turn, paths shortened) and checks what the run is handed. - Broken by hand (withSkillBodies returning results as they came): TestSkillBodyReachesTheSkillResult and TestSkillBodiesTwoSkills red. - go test -tags nogui ./internal/gateway -count=1 -timeout 45m: ok (1220.8s), at origin/main6b0b7a96e. Rebased on8f74442e4, whose gateway change is browser.go: -run 'SkillBod|Browser|ClaudeSub|TaskNotice' ok. Not tried: a real run through a gateway built from this tree (the Claude subscription's sign-in would be refreshed by a sandbox copy). docs/subsystems/claude-subscription-bridge.md says what withSkillBodies does, beside withTaskNotices.
104 lines
3.7 KiB
Go
104 lines
3.7 KiB
Go
package gateway
|
|
|
|
import (
|
|
"os"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// Claude Code answers a Skill call with "Launching skill: pdf" and sends
|
|
// the skill's SKILL.md after the results, as a text block headed "Base
|
|
// directory for this skill: …". The run's model is handed it in the
|
|
// Skill call's result, and the user is not said to have sent it.
|
|
func TestSkillBodyReachesTheSkillResult(t *testing.T) {
|
|
body := "Base directory for this skill: /home/u/.claude/skills/pdf\n\n# PDF\n\nUse pdftotext."
|
|
msgs := []Message{
|
|
{Role: "user", Parts: []Part{{Kind: Text, Text: "read a.pdf"}}},
|
|
{Role: "assistant", Parts: []Part{
|
|
{Kind: ToolCall, CallID: "c1", Name: "Read"},
|
|
{Kind: ToolCall, CallID: "c2", Name: "Skill"},
|
|
}},
|
|
{Role: "user", Parts: []Part{
|
|
{Kind: ToolResult, CallID: "c1", Text: "a.pdf is binary"},
|
|
{Kind: ToolResult, CallID: "c2", Text: "Launching skill: pdf"},
|
|
{Kind: Text, Text: body},
|
|
}},
|
|
}
|
|
results := msgs[2].Parts[:2]
|
|
got := withSkillBodies(results, msgs)
|
|
if !strings.Contains(got[1].Text, "Use pdftotext.") || !strings.HasPrefix(got[1].Text, "Launching skill: pdf") {
|
|
t.Fatalf("the Skill result doesn't carry the skill's body: %q", got[1].Text)
|
|
}
|
|
if strings.Contains(got[0].Text, "pdftotext") {
|
|
t.Fatalf("the body went to the Read result: %q", got[0].Text)
|
|
}
|
|
if results[1].Text != "Launching skill: pdf" {
|
|
t.Fatal("the request's own result was changed in place")
|
|
}
|
|
if said := saidWithResults(msgs); said != "" {
|
|
t.Fatalf("the skill's body went to the run as the user's: %q", said)
|
|
}
|
|
|
|
// in a reminder, and with no Skill call to match: the last result
|
|
msgs[1].Parts[1].Name = "Other"
|
|
msgs[2].Parts[2].Text = "<system-reminder>\n" + body + "\n</system-reminder>"
|
|
got = withSkillBodies(results, msgs)
|
|
if !strings.HasSuffix(got[1].Text, "Use pdftotext.") {
|
|
t.Fatalf("no Skill call: %q", got[1].Text)
|
|
}
|
|
|
|
// nothing after the results: the same results
|
|
msgs[2].Parts = msgs[2].Parts[:2]
|
|
if got := withSkillBodies(results, msgs); &got[0] != &results[0] {
|
|
t.Fatal("no body, yet the results were copied")
|
|
}
|
|
}
|
|
|
|
// Two skills launched at once each get their own body.
|
|
func TestSkillBodiesTwoSkills(t *testing.T) {
|
|
msgs := []Message{
|
|
{Role: "assistant", Parts: []Part{
|
|
{Kind: ToolCall, CallID: "a", Name: "Skill"},
|
|
{Kind: ToolCall, CallID: "b", Name: "Skill"},
|
|
}},
|
|
{Role: "user", Parts: []Part{
|
|
{Kind: ToolResult, CallID: "a", Text: "Launching skill: pdf"},
|
|
{Kind: ToolResult, CallID: "b", Text: "Launching skill: xlsx"},
|
|
{Kind: Text, Text: "Base directory for this skill: /s/pdf\n\nPDF body"},
|
|
{Kind: Text, Text: "Base directory for this skill: /s/xlsx\n\nXLSX body"},
|
|
}},
|
|
}
|
|
got := withSkillBodies(msgs[1].Parts[:2], msgs)
|
|
if !strings.HasSuffix(got[0].Text, "PDF body") || !strings.HasSuffix(got[1].Text, "XLSX body") {
|
|
t.Fatalf("%q / %q", got[0].Text, got[1].Text)
|
|
}
|
|
}
|
|
|
|
// The request Claude Code 2.1.316 sent after a Skill call, as it came
|
|
// (paths shortened): the body reaches the run with the Skill result.
|
|
func TestSkillBodyRealClaudeCode(t *testing.T) {
|
|
b, err := os.ReadFile("testdata/claude-code-skill-launch.json")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
r, err := parseAnthropic(b)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
last := r.Messages[len(r.Messages)-1]
|
|
var results []Part
|
|
for _, p := range last.Parts {
|
|
if p.Kind == ToolResult {
|
|
results = append(results, p)
|
|
}
|
|
}
|
|
got := withTaskNotices(withSkillBodies(results, r.Messages), r.Messages)
|
|
if len(got) != 1 || !strings.HasPrefix(got[0].Text, "Launching skill: magpie-skills\n\nBase directory for this skill: ") ||
|
|
!strings.Contains(got[0].Text, "/Users/u/.claude/skills/magpie-skills/.skills/greet-user/SKILL.md") {
|
|
t.Fatalf("the run is handed: %+v", got)
|
|
}
|
|
if said := saidWithResults(r.Messages); said != "" {
|
|
t.Fatalf("said as the user's: %q", said)
|
|
}
|
|
}
|