Skip to content

Commit 4db0cf8

Browse files
authored
feat(trace): record the skills that an agent used in a session (#3551)
1 parent 179493c commit 4db0cf8

30 files changed

Lines changed: 3668 additions & 174 deletions

‎app/cli/internal/trace/claude/hooks.go‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ var commandTools = []string{"Bash"}
5858
// kind fired.
5959
var hookToolMatcher = strings.Join(append(append([]string{}, fileWritingTools...), commandTools...), "|")
6060

61+
// postHookToolMatcher also covers the Skill tool. The skill is loaded only
62+
// after the call, so the post hook is the first one that can copy its folder.
63+
var postHookToolMatcher = hookToolMatcher + "|" + skillTool
64+
6165
type hookEvent struct {
6266
event string
6367
command string
@@ -68,7 +72,7 @@ var hookEvents = []hookEvent{
6872
{eventSessionStart, "chainloop trace hook claude session-start", ""},
6973
{eventUserPromptSubmit, "chainloop trace hook claude user-prompt-submit", ""},
7074
{eventPreToolUse, "chainloop trace hook claude pre-tool-use", hookToolMatcher},
71-
{eventPostToolUse, "chainloop trace hook claude post-tool-use", hookToolMatcher},
75+
{eventPostToolUse, "chainloop trace hook claude post-tool-use", postHookToolMatcher},
7276
{eventPostToolUseFailure, "chainloop trace hook claude post-tool-use", hookToolMatcher},
7377
{eventSessionEnd, "chainloop trace hook claude session-end", ""},
7478
}

‎app/cli/internal/trace/claude/hooks_test.go‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,13 @@ func TestInstallHooks(t *testing.T) {
6464
preEntry := preEntries[0].(map[string]any)
6565
assert.Equal(t, "Edit|Write|MultiEdit|Bash", preEntry["matcher"])
6666

67-
// PostToolUse should have matcher
67+
// PostToolUse also matches Skill, to copy the folder of a loaded skill
6868
postEntries := hooks["PostToolUse"].([]any)
6969
postEntry := postEntries[0].(map[string]any)
70-
assert.Equal(t, "Edit|Write|MultiEdit|Bash", postEntry["matcher"])
70+
assert.Equal(t, "Edit|Write|MultiEdit|Bash|Skill", postEntry["matcher"])
7171

72-
// PostToolUseFailure should have the same matcher
72+
// PostToolUseFailure keeps the edit matcher: a failed Skill call loads
73+
// no skill
7374
failureEntries := hooks["PostToolUseFailure"].([]any)
7475
failureEntry := failureEntries[0].(map[string]any)
7576
assert.Equal(t, "Edit|Write|MultiEdit|Bash", failureEntry["matcher"])

0 commit comments

Comments
 (0)