Files
multica/server/pkg/agent/testdata/cursor-agent-2026.07.20-stream-json.jsonl
Bohan Jiang a92bd5387e MUL-5231 fix(agent): parse Cursor top-level thinking and tool_call events (#5846)
Cursor stream-json emits reasoning and tool calls as top-level `thinking` /
`tool_call` events; the parser only looked for them inside assistant messages,
so transcripts showed a single step. Match the top-level events, taking the
tool name from the nested `<name>ToolCall` key and normalizing the packed
call_id. Subtypes are matched explicitly — only `started` opens a tool, only
`completed` closes it, only `delta` carries reasoning — so an unknown/missing
subtype is ignored rather than synthesizing a fake result (which would decrement
the daemon in-flight tool count early and misfire the watchdog) or polluting
reasoning. Covered by a recorded-stream fixture test, an unknown-subtype
regression test, and an opt-in real-CLI smoke test.
2026-07-24 01:52:15 +08:00

24 lines
8.4 KiB
JSON

{"type":"system","subtype":"init","apiKeySource":"login","cwd":"/private/tmp/curcap","session_id":"ebb521c2-404d-4a4e-8c2f-1f8bdb141043","model":"Auto","permissionMode":"default"}
{"type":"user","message":{"role":"user","content":[{"type":"text","text":"Read notes.txt, then run \"wc -l notes.txt\" in the shell, then write the number of lines into count.txt. Keep it short."}]},"session_id":"ebb521c2-404d-4a4e-8c2f-1f8bdb141043"}
{"type":"thinking","subtype":"delta","text":"Reading notes.txt.","session_id":"ebb521c2-404d-4a4e-8c2f-1f8bdb141043","timestamp_ms":1784819288883}
{"type":"thinking","subtype":"delta","text":"\n\nRunning wc -l on notes.txt.","session_id":"ebb521c2-404d-4a4e-8c2f-1f8bdb141043","timestamp_ms":1784819289514}
{"type":"thinking","subtype":"delta","text":" Writing the line count","session_id":"ebb521c2-404d-4a4e-8c2f-1f8bdb141043","timestamp_ms":1784819289514}
{"type":"thinking","subtype":"delta","text":" to count.txt.","session_id":"ebb521c2-404d-4a4e-8c2f-1f8bdb141043","timestamp_ms":1784819289514}
{"type":"thinking","subtype":"completed","session_id":"ebb521c2-404d-4a4e-8c2f-1f8bdb141043","timestamp_ms":1784819289515}
{"type":"assistant","message":{"role":"assistant","content":[{"type":"text","text":"I'll read `notes.txt`, run `wc -l`, then write the line count to `count.txt`."}]},"session_id":"ebb521c2-404d-4a4e-8c2f-1f8bdb141043","model_call_id":"59ff63a6-195e-463f-89ce-f26a820987bf-0-c94p","timestamp_ms":1784819289520}
{"type":"tool_call","subtype":"started","call_id":"call-bb11656a-e59e-4356-9866-5b206aedb390-0\nfc_35bc3e26-1dfc-9c07-b668-4c50a744b8f9_0","tool_call":{"readToolCall":{"args":{"path":"/tmp/curcap/notes.txt"}},"hookAdditionalContexts":[],"toolCallId":"call-bb11656a-e59e-4356-9866-5b206aedb390-0\nfc_35bc3e26-1dfc-9c07-b668-4c50a744b8f9_0","startedAtMs":"1784819289745"},"model_call_id":"59ff63a6-195e-463f-89ce-f26a820987bf-0-c94p","session_id":"ebb521c2-404d-4a4e-8c2f-1f8bdb141043","timestamp_ms":1784819289520}
{"type":"tool_call","subtype":"started","call_id":"call-bb11656a-e59e-4356-9866-5b206aedb390-1\nfc_35bc3e26-1dfc-9c07-b668-4c50a744b8f9_1","tool_call":{"shellToolCall":{"args":{"command":"wc -l notes.txt","workingDirectory":"","timeout":30000,"toolCallId":"call-bb11656a-e59e-4356-9866-5b206aedb390-1\nfc_35bc3e26-1dfc-9c07-b668-4c50a744b8f9_1","simpleCommands":["wc"],"hasInputRedirect":false,"hasOutputRedirect":false,"parsingResult":{"parsingFailed":false,"executableCommands":[{"name":"wc","args":[{"type":"word","value":"-l"},{"type":"word","value":"notes.txt"}],"fullText":"wc -l notes.txt"}],"hasRedirects":false,"hasCommandSubstitution":false,"redirects":[]},"fileOutputThresholdBytes":"40000","isBackground":false,"skipApproval":false,"timeoutBehavior":"TIMEOUT_BEHAVIOR_BACKGROUND","hardTimeout":86400000,"description":"Count lines in notes.txt","closeStdin":true,"conversationId":"ebb521c2-404d-4a4e-8c2f-1f8bdb141043"},"description":"Count lines in notes.txt"},"hookAdditionalContexts":[],"toolCallId":"call-bb11656a-e59e-4356-9866-5b206aedb390-1\nfc_35bc3e26-1dfc-9c07-b668-4c50a744b8f9_1","startedAtMs":"1784819289750"},"model_call_id":"59ff63a6-195e-463f-89ce-f26a820987bf-0-c94p","session_id":"ebb521c2-404d-4a4e-8c2f-1f8bdb141043","timestamp_ms":1784819289526}
{"type":"tool_call","subtype":"completed","call_id":"call-bb11656a-e59e-4356-9866-5b206aedb390-0\nfc_35bc3e26-1dfc-9c07-b668-4c50a744b8f9_0","tool_call":{"readToolCall":{"args":{"path":"/tmp/curcap/notes.txt"},"result":{"success":{"content":"alpha\nbeta\ngamma\n","isEmpty":false,"exceededLimit":false,"totalLines":4,"fileSize":17,"path":"/tmp/curcap/notes.txt","readRange":{"startLine":1,"endLine":4},"relatedCursorRulePaths":[],"relatedCursorRules":[]}}},"hookAdditionalContexts":[],"toolCallId":"call-bb11656a-e59e-4356-9866-5b206aedb390-0\nfc_35bc3e26-1dfc-9c07-b668-4c50a744b8f9_0","startedAtMs":"1784819289745","completedAtMs":"1784819289937"},"model_call_id":"59ff63a6-195e-463f-89ce-f26a820987bf-0-c94p","session_id":"ebb521c2-404d-4a4e-8c2f-1f8bdb141043","timestamp_ms":1784819289719}
{"type":"tool_call","subtype":"completed","call_id":"call-bb11656a-e59e-4356-9866-5b206aedb390-1\nfc_35bc3e26-1dfc-9c07-b668-4c50a744b8f9_1","tool_call":{"shellToolCall":{"args":{"command":"wc -l notes.txt","workingDirectory":"","timeout":30000,"toolCallId":"call-bb11656a-e59e-4356-9866-5b206aedb390-1\nfc_35bc3e26-1dfc-9c07-b668-4c50a744b8f9_1","simpleCommands":["wc"],"hasInputRedirect":false,"hasOutputRedirect":false,"parsingResult":{"parsingFailed":false,"executableCommands":[{"name":"wc","args":[{"type":"word","value":"-l"},{"type":"word","value":"notes.txt"}],"fullText":"wc -l notes.txt"}],"hasRedirects":false,"hasCommandSubstitution":false,"redirects":[]},"fileOutputThresholdBytes":"40000","isBackground":false,"skipApproval":false,"timeoutBehavior":"TIMEOUT_BEHAVIOR_BACKGROUND","hardTimeout":86400000,"description":"Count lines in notes.txt","closeStdin":true,"conversationId":"ebb521c2-404d-4a4e-8c2f-1f8bdb141043"},"result":{"success":{"command":"wc -l notes.txt","workingDirectory":"","exitCode":0,"signal":"","stdout":" 3 notes.txt\n","stderr":"","executionTime":1479,"interleavedOutput":" 3 notes.txt\n","localExecutionTimeMs":280},"isBackground":false},"description":"Count lines in notes.txt"},"hookAdditionalContexts":[],"toolCallId":"call-bb11656a-e59e-4356-9866-5b206aedb390-1\nfc_35bc3e26-1dfc-9c07-b668-4c50a744b8f9_1","startedAtMs":"1784819289750","completedAtMs":"1784819291229"},"model_call_id":"59ff63a6-195e-463f-89ce-f26a820987bf-0-c94p","session_id":"ebb521c2-404d-4a4e-8c2f-1f8bdb141043","timestamp_ms":1784819291011}
{"type":"thinking","subtype":"delta","text":"notes.txt contains 3","session_id":"ebb521c2-404d-4a4e-8c2f-1f8bdb141043","timestamp_ms":1784819292716}
{"type":"thinking","subtype":"delta","text":" lines. I will write","session_id":"ebb521c2-404d-4a4e-8c2f-1f8bdb141043","timestamp_ms":1784819292716}
{"type":"thinking","subtype":"delta","text":" 3 into count.txt.","session_id":"ebb521c2-404d-4a4e-8c2f-1f8bdb141043","timestamp_ms":1784819292716}
{"type":"thinking","subtype":"completed","session_id":"ebb521c2-404d-4a4e-8c2f-1f8bdb141043","timestamp_ms":1784819292716}
{"type":"tool_call","subtype":"started","call_id":"call-c52c0cd6-81ad-4a87-94c5-f5b0119f3ed4-2\nfc_27b4c3fb-9abc-92ae-967f-147ee264096e_0","tool_call":{"editToolCall":{"args":{"path":"/tmp/curcap/count.txt","streamContent":"3\n"}},"hookAdditionalContexts":[],"toolCallId":"call-c52c0cd6-81ad-4a87-94c5-f5b0119f3ed4-2\nfc_27b4c3fb-9abc-92ae-967f-147ee264096e_0","startedAtMs":"1784819292927"},"model_call_id":"59ff63a6-195e-463f-89ce-f26a820987bf-1-g9hb","session_id":"ebb521c2-404d-4a4e-8c2f-1f8bdb141043","timestamp_ms":1784819292717}
{"type":"tool_call","subtype":"completed","call_id":"call-c52c0cd6-81ad-4a87-94c5-f5b0119f3ed4-2\nfc_27b4c3fb-9abc-92ae-967f-147ee264096e_0","tool_call":{"editToolCall":{"args":{"path":"/tmp/curcap/count.txt","streamContent":"3\n"},"result":{"success":{"path":"/tmp/curcap/count.txt","linesAdded":1,"linesRemoved":1,"diffString":"--- /dev/null\n+++ b//tmp/curcap/count.txt\n@@ -1 +1 @@\n-\n+3","afterFullFileContent":"3\n","message":"Wrote contents to /tmp/curcap/count.txt"}}},"hookAdditionalContexts":[],"toolCallId":"call-c52c0cd6-81ad-4a87-94c5-f5b0119f3ed4-2\nfc_27b4c3fb-9abc-92ae-967f-147ee264096e_0","startedAtMs":"1784819292927","completedAtMs":"1784819293314"},"model_call_id":"59ff63a6-195e-463f-89ce-f26a820987bf-1-g9hb","session_id":"ebb521c2-404d-4a4e-8c2f-1f8bdb141043","timestamp_ms":1784819293094}
{"type":"thinking","subtype":"delta","text":"Finished. The line count","session_id":"ebb521c2-404d-4a4e-8c2f-1f8bdb141043","timestamp_ms":1784819294133}
{"type":"thinking","subtype":"delta","text":" was written to count.txt.","session_id":"ebb521c2-404d-4a4e-8c2f-1f8bdb141043","timestamp_ms":1784819294133}
{"type":"thinking","subtype":"completed","session_id":"ebb521c2-404d-4a4e-8c2f-1f8bdb141043","timestamp_ms":1784819294133}
{"type":"assistant","message":{"role":"assistant","content":[{"type":"text","text":"`notes.txt` has 3 lines (`alpha`, `beta`, `gamma`). Wrote `3` to `count.txt`."}]},"session_id":"ebb521c2-404d-4a4e-8c2f-1f8bdb141043"}
{"type":"result","subtype":"success","duration_ms":9679,"duration_api_ms":9679,"is_error":false,"result":"I'll read `notes.txt`, run `wc -l`, then write the line count to `count.txt`.`notes.txt` has 3 lines (`alpha`, `beta`, `gamma`). Wrote `3` to `count.txt`.","session_id":"ebb521c2-404d-4a4e-8c2f-1f8bdb141043","request_id":"59ff63a6-195e-463f-89ce-f26a820987bf","usage":{"inputTokens":8830,"outputTokens":185,"cacheReadTokens":44800,"cacheWriteTokens":0}}