Skip to content

The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu

Treat a tool.invoked event that carries a result as the completion

Claudea6bdd4a0ea73
diff --git a/pkg/asymptoteobserve/share.go b/pkg/asymptoteobserve/share.go
index bba9f6a5..e2b54fd9 100644
--- a/pkg/asymptoteobserve/share.go
+++ b/pkg/asymptoteobserve/share.go
@@ -573,7 +573,10 @@ func isShareInvocation(event Event) bool {
switch strings.ToLower(strings.TrimSpace(event.Event.Action)) {
case "tool.invoked", "tool.started", "tool.call", "tool.execute.before", "tool.execution_start",
"command.invoked", "command.execute.before", "mcp.tool_call":
- return true
+ // The hook adapter also labels a post-tool event tool.invoked for tools it has no more
+ // specific action for (WebFetch, Task, Grep, ...). That event carries the finished call's
+ // result, and is a completion.
+ return !hasShareCompletionEvidence(event)
}
return false
}
@@ -585,13 +588,20 @@ func isShareCompletion(event Event) bool {
case "tool.completed", "tool.failed", "tool.execute.after", "tool.execution_complete", "tool.result":
return true
}
- if event.GenAI != nil && event.GenAI.Tool != nil && event.GenAI.Tool.Call != nil && event.GenAI.Tool.Call.Result != nil {
+ if event.File != nil && event.File.Diff != "" {
return true
}
- if event.Command != nil && (event.Command.Output != "" || event.Command.ExitCode != nil || event.Command.DurationMS > 0) {
+ return hasShareCompletionEvidence(event)
+}
+
+// hasShareCompletionEvidence reports an event that carries what only a finished call has: a
+// result, command output or exit code, or an error. A diff is not evidence on its own, because an
+// edit's invocation can carry the patch it is about to apply.
+func hasShareCompletionEvidence(event Event) bool {
+ if event.GenAI != nil && event.GenAI.Tool != nil && event.GenAI.Tool.Call != nil && event.GenAI.Tool.Call.Result != nil {
return true
}
- if event.File != nil && event.File.Diff != "" {
+ if event.Command != nil && (event.Command.Output != "" || event.Command.ExitCode != nil || event.Command.DurationMS > 0) {
return true
}
return event.Error != nil && event.Error.Type != ""
diff --git a/pkg/asymptoteobserve/share_test.go b/pkg/asymptoteobserve/share_test.go
index c8cba549..0cb796d3 100644
--- a/pkg/asymptoteobserve/share_test.go
+++ b/pkg/asymptoteobserve/share_test.go
@@ -2,6 +2,7 @@ package asymptoteobserve
import (
"encoding/json"
+ "fmt"
"strings"
"testing"
)
@@ -530,3 +531,29 @@ func TestShareMetadataUsesExplicitHomeWithoutLookup(t *testing.T) {
t.Fatalf("title = %q", meta.Title)
}
}
+
+func TestBuildShareMessagesTreatsAPostToolInvokedEventAsTheResult(t *testing.T) {
+ // The hook adapter labels a PostToolUse for tools without a more specific action (WebFetch,
+ // Grep, Task, ...) tool.invoked, carrying the result. With a PreToolUse tool.invoked for the
+ // same call (Kimi Code, Muse Code) it must still produce a result.
+ pre := shareEventAt("2026-10-01T10:00:00Z", "kimi_code", CollectionMethodHook, "tool.invoked", "tool")
+ pre.Event.ID = "k-pre"
+ pre = withCall(pre, "call_1", "WebFetch", map[string]interface{}{"url": "https://example.com"}, nil)
+ post := shareEventAt("2026-10-01T10:00:01Z", "kimi_code", CollectionMethodHook, "tool.invoked", "tool")
+ post.Event.ID = "k-post"
+ post = withCall(post, "call_1", "WebFetch", nil, "page body")
+ // Alone (Claude: PreToolUse becomes an approval), the post event still yields a call and result.
+ lone := shareEventAt("2026-10-01T10:00:02Z", "claude_code", CollectionMethodHook, "tool.invoked", "tool")
+ lone.Event.ID = "c-post"
+ lone = withCall(lone, "toolu_9", "Grep", map[string]interface{}{"pattern": "x"}, "3 matches")
+
+ messages := BuildShareMessagesWithOptions([]Event{pre, post, lone}, shareTestOpts)
+ want := "assistant/tool_call,assistant/tool_result,assistant/tool_call,assistant/tool_result"
+ if got := partsOf(t, messages); strings.Join(got, ",") != want {
+ t.Fatalf("parts = %v", got)
+ }
+ result := messages[1].Parts[0].Content.(*ShareToolResultContent)
+ if result.CallID != "call_1" || !strings.Contains(fmt.Sprint(result.Output), "page body") {
+ t.Fatalf("result = %+v", result)
+ }
+}