feat(protocol): wire contract, canonical reducer and golden fixtures

- v1 envelope across browser/daemon/plugin
- SessionState model + reducer rules (pi events + pi2:* derived events)
- fixtures for basic turn, queue/todo/attention and abort/exit
- 9 conformance tests pinning the reducer
This commit is contained in:
yuez committed 2026-10-21 10:58:46 +08:00
commit 9d817f35b7
19 files changed
+2922

No files matched your search

+24
View File
@@ -0,0 +1,24 @@
{"type":"pi2:session","ts":1000,"session":{"status":"idle","cwd":"/repo","model":{"provider":"anthropic","id":"claude-sonnet-4-5"},"thinking":"medium","contextUsage":{"tokens":1200,"window":200000,"percent":0.6}}}
{"type":"agent_start","ts":1010}
{"type":"turn_start","ts":1011}
{"type":"message_start","ts":1012,"message":{"role":"user","content":"List the files","timestamp":1012}}
{"type":"message_end","ts":1013,"message":{"role":"user","content":"List the files","timestamp":1012}}
{"type":"message_start","ts":1014,"message":{"role":"assistant","content":[],"timestamp":1014}}
{"type":"message_update","ts":1015,"assistantMessageEvent":{"type":"thinking_start","contentIndex":0}}
{"type":"message_update","ts":1016,"assistantMessageEvent":{"type":"thinking_delta","contentIndex":0,"delta":"I should "}}
{"type":"message_update","ts":1017,"assistantMessageEvent":{"type":"thinking_delta","contentIndex":0,"delta":"list files."}}
{"type":"message_update","ts":1018,"assistantMessageEvent":{"type":"thinking_end","contentIndex":0,"content":"I should list files."}}
{"type":"message_update","ts":1019,"assistantMessageEvent":{"type":"text_start","contentIndex":1}}
{"type":"message_update","ts":1020,"assistantMessageEvent":{"type":"text_delta","contentIndex":1,"delta":"Let me "}}
{"type":"message_update","ts":1021,"assistantMessageEvent":{"type":"toolcall_start","contentIndex":2,"id":"call_1","toolName":"bash"}}
{"type":"message_update","ts":1022,"assistantMessageEvent":{"type":"toolcall_delta","contentIndex":2,"delta":"{\"command\":"}}
{"type":"message_update","ts":1023,"assistantMessageEvent":{"type":"toolcall_delta","contentIndex":2,"delta":"\"ls\"}"}}
{"type":"message_update","ts":1024,"assistantMessageEvent":{"type":"toolcall_end","contentIndex":2,"toolCall":{"type":"toolCall","id":"call_1","name":"bash","arguments":{"command":"ls"}}}}
{"type":"message_update","ts":1025,"assistantMessageEvent":{"type":"text_delta","contentIndex":1,"delta":"list them."}}
{"type":"message_end","ts":1030,"message":{"role":"assistant","content":[{"type":"thinking","thinking":"I should list files."},{"type":"text","text":"Let me list them."},{"type":"toolCall","id":"call_1","name":"bash","arguments":{"command":"ls"}}],"usage":{"input":100,"output":20,"cacheRead":0,"cacheWrite":0,"totalTokens":120,"cost":{"input":0.001,"output":0.002,"cacheRead":0,"cacheWrite":0,"total":0.003}},"timestamp":1030}}
{"type":"tool_execution_start","ts":1031,"toolCallId":"call_1","toolName":"bash","args":{"command":"ls"}}
{"type":"tool_execution_update","ts":1034,"toolCallId":"call_1","toolName":"bash","args":{"command":"ls"},"partialResult":{"content":[{"type":"text","text":"a.txt"}],"details":{}}}
{"type":"tool_execution_end","ts":1040,"toolCallId":"call_1","toolName":"bash","result":{"content":[{"type":"text","text":"a.txt\nb.txt"}],"details":{}},"isError":false,"durationMs":9}
{"type":"turn_end","ts":1041,"message":{"role":"assistant","content":[],"timestamp":1041},"toolResults":[]}
{"type":"agent_end","ts":1042,"messages":[],"willRetry":false}
{"type":"agent_settled","ts":1050,"aborted":false}
+79
View File
@@ -0,0 +1,79 @@
{
"sessionId": "basic-turn",
"workspaceId": "ws-fixture",
"cwd": "/repo",
"name": null,
"status": "idle",
"flags": {
"attention": false,
"done": true,
"error": false
},
"model": {
"provider": "anthropic",
"id": "claude-sonnet-4-5"
},
"thinking": "medium",
"usage": {
"input": 100,
"output": 20,
"cacheRead": 0,
"cacheWrite": 0,
"cost": 0.003
},
"contextUsage": {
"tokens": 1200,
"window": 200000,
"percent": 0.6
},
"queue": [],
"todos": [],
"tasks": [],
"batches": [],
"subagents": [],
"attention": [],
"entries": [
{
"id": "m1",
"role": "user",
"ts": 1012,
"blocks": [
{
"type": "text",
"text": "List the files"
}
],
"done": true
},
{
"id": "m2",
"role": "assistant",
"ts": 1014,
"blocks": [
{
"type": "thinking",
"text": "I should list files."
},
{
"type": "text",
"text": "Let me list them."
},
{
"type": "tool",
"toolCallId": "call_1",
"name": "bash",
"state": "done",
"args": {
"command": "ls"
},
"output": {
"text": "a.txt\nb.txt",
"details": {}
},
"durationMs": 9
}
],
"done": true
}
]
}
@@ -0,0 +1,11 @@
{"type":"pi2:session","ts":3000,"session":{"status":"idle","cwd":"/repo","model":{"provider":"anthropic","id":"claude-sonnet-4-5"},"thinking":"off"}}
{"type":"agent_start","ts":3001}
{"type":"message_start","ts":3002,"message":{"role":"assistant","content":[],"timestamp":3002}}
{"type":"message_update","ts":3003,"assistantMessageEvent":{"type":"text_start","contentIndex":0}}
{"type":"message_update","ts":3004,"assistantMessageEvent":{"type":"text_delta","contentIndex":0,"delta":"partial answer"}}
{"type":"message_update","ts":3005,"assistantMessageEvent":{"type":"error","reason":"aborted","error":"Aborted by user"}}
{"type":"pi2:error","ts":3006,"message":"Aborted by user"}
{"type":"agent_settled","ts":3007,"aborted":true}
{"type":"compaction_start","ts":3010,"reason":"manual"}
{"type":"compaction_end","ts":3020,"reason":"manual","success":true}
{"type":"pi2:process_exit","ts":3030,"code":0,"signal":null}
@@ -0,0 +1,53 @@
{
"sessionId": "error-abort-compaction",
"workspaceId": "ws-fixture",
"cwd": "/repo",
"name": null,
"status": "exited",
"flags": {
"attention": false,
"done": false,
"error": true
},
"model": {
"provider": "anthropic",
"id": "claude-sonnet-4-5"
},
"thinking": "off",
"usage": {
"input": 0,
"output": 0,
"cacheRead": 0,
"cacheWrite": 0,
"cost": 0
},
"contextUsage": null,
"queue": [],
"todos": [],
"tasks": [],
"batches": [],
"subagents": [],
"attention": [],
"entries": [
{
"id": "m1",
"role": "assistant",
"ts": 3002,
"blocks": [
{
"type": "text",
"text": "partial answer"
},
{
"type": "error",
"text": "Aborted by user"
},
{
"type": "error",
"text": "Aborted by user"
}
],
"done": false
}
]
}
@@ -0,0 +1,10 @@
{"type":"pi2:session","ts":2000,"session":{"status":"busy","cwd":"/repo","model":{"provider":"anthropic","id":"claude-sonnet-4-5"},"thinking":"high","contextUsage":{"tokens":1234,"window":200000,"percent":0.6}}}
{"type":"session_info_changed","ts":2001,"name":"Refactor auth"}
{"type":"queue_update","ts":2002,"steering":["use pnpm"],"followUp":["then run the tests"]}
{"type":"pi2:todo","ts":2003,"todos":[{"content":"read auth.ts","status":"completed","activeForm":"reading auth.ts"},{"content":"refactor","status":"in_progress","activeForm":"refactoring"},{"content":"test","status":"pending"}],"completed":1,"total":3}
{"type":"pi2:batch","ts":2004,"batchId":"b1","status":"running","items":[{"ref":"0","name":"audit","status":"ok"},{"ref":"1","name":"refactor","status":"running"}],"summary":{"total":2,"done":1,"ok":1,"failed":0,"cancelled":0,"running":1}}
{"type":"pi2:task","ts":2005,"task":{"id":"t1","command":"pnpm test","status":"running","startTime":2005}}
{"type":"pi2:subagents","ts":2006,"subagents":[{"id":"s2","name":"audit","status":"completed","model":"claude-sonnet-4-5"},{"id":"s3","name":"refactor","status":"active","model":"deepseek-v4.1"}],"parentId":"s1"}
{"type":"pi2:attention_request","ts":2007,"requestId":"att1","method":"select","title":"Apply diff?","message":"3 files changed","options":[{"id":"accept","label":"Accept"},{"id":"reject","label":"Reject"}],"timeoutSec":120}
{"type":"pi2:attention_resolved","ts":2008,"requestId":"att1","by":{"clientId":"c1","kind":"web"},"response":{"id":"accept"}}
{"type":"agent_settled","ts":2010,"aborted":false}
+107
View File
@@ -0,0 +1,107 @@
{
"sessionId": "queue-todo-attention",
"workspaceId": "ws-fixture",
"cwd": "/repo",
"name": "Refactor auth",
"status": "idle",
"flags": {
"attention": false,
"done": true,
"error": false
},
"model": {
"provider": "anthropic",
"id": "claude-sonnet-4-5"
},
"thinking": "high",
"usage": {
"input": 0,
"output": 0,
"cacheRead": 0,
"cacheWrite": 0,
"cost": 0
},
"contextUsage": {
"tokens": 1234,
"window": 200000,
"percent": 0.6
},
"queue": [
{
"id": "q:steer:0",
"text": "use pnpm",
"steer": true
},
{
"id": "q:follow:0",
"text": "then run the tests",
"steer": false
}
],
"todos": [
{
"content": "read auth.ts",
"status": "completed",
"activeForm": "reading auth.ts"
},
{
"content": "refactor",
"status": "in_progress",
"activeForm": "refactoring"
},
{
"content": "test",
"status": "pending"
}
],
"tasks": [
{
"id": "t1",
"command": "pnpm test",
"status": "running",
"startTime": 2005
}
],
"batches": [
{
"batchId": "b1",
"status": "running",
"items": [
{
"ref": "0",
"name": "audit",
"status": "ok"
},
{
"ref": "1",
"name": "refactor",
"status": "running"
}
],
"summary": {
"total": 2,
"done": 1,
"ok": 1,
"failed": 0,
"cancelled": 0,
"running": 1
}
}
],
"subagents": [
{
"id": "s2",
"name": "audit",
"status": "completed",
"model": "claude-sonnet-4-5"
},
{
"id": "s3",
"name": "refactor",
"status": "active",
"model": "deepseek-v4.1"
}
],
"attention": [],
"entries": []
}