The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu
Go agent-ai-cliagent-harnessesagent-securitybrowser-extensionciclaude-codecloudcodexcursordetection-engineeringjevknowledge-basememorymobile-device-managementobservabilitysecuritysecurity-information-and-event-managementsecurity-toolstelemetrytraces
Write a prompt captured by both the hook and the export once
Claude9ef7bd7957b9
diff --git a/pkg/asymptoteobserve/share.go b/pkg/asymptoteobserve/share.goindex e2b54fd9..630320b4 100644--- a/pkg/asymptoteobserve/share.go+++ b/pkg/asymptoteobserve/share.go@@ -429,6 +429,7 @@ func BuildShareMessagesWithOptions(events []Event, opts ShareOptions) []ShareMescalls: map[string]*ShareToolCallContent{},results: map[string]*ShareToolResultContent{},callMessage: map[string]*ShareMessageV1{},+ prompts: map[string]*ShareMessageV1{},}for _, item := range orderShareEvents(events) {b.add(item)@@ -519,6 +520,9 @@ type shareBuilder struct {// pending holds call ids of invocations that named no runtime call id, newest last, waiting for// a completion to pair with by tool name.pending []string+ // prompts holds user messages by harness, session and prompt.id, so one prompt captured by two+ // paths (a hook and the OTLP export) is written once.+ prompts map[string]*ShareMessageV1}type shareEventClass int@@ -620,10 +624,24 @@ func (b *shareBuilder) add(item shareEvent) {switch class {case sharePrompt:text := sharePromptText(event)+ key := sharePromptKey(event)+ if existing := b.prompts[key]; key != "" && existing != nil {+ // The same prompt from a second capture path: fill in the text if the first copy+ // had none, and write nothing new.+ if existing.Text == sharePromptNotRetained && text != "" {+ text = b.scrub.text(text)+ existing.Text = text+ existing.Parts = []SharePartV1{{Type: SharePartText, Order: 1, Content: ShareTextContent{Text: text}}}+ }+ return+ }if text == "" {- text = "(prompt text not retained)"+ text = sharePromptNotRetained}b.appendText(item, ShareRoleUser, SharePartText, text)+ if key != "" {+ b.prompts[key] = b.messages[len(b.messages)-1]+ }case shareAgentText:text := shareAssistantText(event, GenAIPartTypeText)if text == "" {@@ -648,6 +666,21 @@ func (b *shareBuilder) add(item shareEvent) {}}+const sharePromptNotRetained = "(prompt text not retained)"++// sharePromptKey names one user prompt across capture paths: prompt.id is the runtime's own id for+// the turn, which a hook and the OTLP export both carry.+func sharePromptKey(event Event) string {+ if event.Prompt == nil || strings.TrimSpace(event.Prompt.ID) == "" {+ return ""+ }+ session := ""+ if event.Session != nil {+ session = event.Session.ID+ }+ return NormalizeHarnessName(event.Harness.Name) + "\x00" + session + "\x00" + strings.TrimSpace(event.Prompt.ID)+}+func (b *shareBuilder) newMessage(item shareEvent, id, role, text string, parts ...SharePartV1) *ShareMessageV1 {for i := range parts {parts[i].Order = i + 1diff --git a/pkg/asymptoteobserve/share_test.go b/pkg/asymptoteobserve/share_test.goindex 0cb796d3..0acd83a9 100644--- a/pkg/asymptoteobserve/share_test.go+++ b/pkg/asymptoteobserve/share_test.go@@ -557,3 +557,25 @@ func TestBuildShareMessagesTreatsAPostToolInvokedEventAsTheResult(t *testing.T)t.Fatalf("result = %+v", result)}}++func TestBuildShareMessagesWritesAPromptCapturedTwiceOnce(t *testing.T) {+ // Claude Code logs each prompt from the UserPromptSubmit hook and from the OTLP export, with+ // different event ids and the same prompt.id. The export copy may carry no text.+ otlp := shareEventAt("2026-10-01T10:00:00Z", "claude_code", CollectionMethodOTLP, "prompt.submitted", "prompt")+ otlp.Event.ID = "p-otlp"+ otlp.Prompt = &PromptInfo{ID: "prompt-1"}+ hook := shareEventAt("2026-10-01T10:00:00.5Z", "claude_code", CollectionMethodHook, "prompt.submitted", "prompt")+ hook.Event.ID = "p-hook"+ hook.Prompt = &PromptInfo{ID: "prompt-1", Text: "fix the test"}+ next := shareEventAt("2026-10-01T10:01:00Z", "claude_code", CollectionMethodHook, "prompt.submitted", "prompt")+ next.Event.ID = "p-next"+ next.Prompt = &PromptInfo{ID: "prompt-2", Text: "fix the test"}++ messages := BuildShareMessagesWithOptions([]Event{otlp, hook, next}, shareTestOpts)+ if len(messages) != 2 {+ t.Fatalf("messages = %d, want 2: %+v", len(messages), messages)+ }+ if messages[0].Text != "fix the test" || messages[0].ID != "p-otlp" {+ t.Fatalf("first prompt = %+v", messages[0])+ }+}