Skip to content

A desktop coding agent with free access to frontier models.

TypeScript

fix(capture): scrub every shape that carries file text by its file's mode

ogsamrat2ba29004c5b3
diff --git a/apps/server/src/__fixtures__/scrub-file-mode.json b/apps/server/src/__fixtures__/scrub-file-mode.json
index 33e32786..4a083e5f 100644
--- a/apps/server/src/__fixtures__/scrub-file-mode.json
+++ b/apps/server/src/__fixtures__/scrub-file-mode.json
@@ -1359,6 +1359,952 @@
]
}
},
+ {
+ "name": "opencode turn.completed: nested apply_patch part, its metadata diffs and the user message's summary.diffs (`file` key) keep code per file; the prompt stays CONFIG",
+ "kind": "trace",
+ "input": {
+ "schema_version": 1,
+ "session_id": "ses_1",
+ "events": [
+ {
+ "at": "2026-10-04T00:00:00.000Z",
+ "type": "engine.request",
+ "data": {
+ "agent": "omnirush-cli",
+ "prompt": "Create src/auth.ts with exactly these two lines:\nexport async function a(token:string){await fetch(u)}\nconst k = \"sk-proj-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\"\nAppend the line API_TOKEN=abcdefgh123 to .env.",
+ "model": null
+ }
+ },
+ {
+ "at": "2026-10-04T00:00:01.000Z",
+ "type": "turn.completed",
+ "data": {
+ "messages": [
+ {
+ "info": {
+ "id": "msg_1",
+ "sessionID": "ses_1",
+ "role": "user",
+ "summary": {
+ "diffs": [
+ {
+ "file": ".env",
+ "patch": "Index: .env\n===================================================================\n--- .env\t\n+++ .env\t\n@@ -1,2 +1,3 @@\n APP_NAME=demo\n DEBUG=1\n+API_TOKEN=abcdefgh123\n",
+ "additions": 1,
+ "deletions": 0,
+ "status": "modified"
+ },
+ {
+ "file": "src/auth.ts",
+ "patch": "Index: src/auth.ts\n===================================================================\n--- src/auth.ts\t\n+++ src/auth.ts\t\n@@ -0,0 +1,2 @@\n+export async function a(token:string){await fetch(u)}\n+const k = \"sk-proj-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\"\n",
+ "additions": 2,
+ "deletions": 0,
+ "status": "added"
+ }
+ ]
+ }
+ },
+ "parts": [
+ {
+ "id": "prt_1",
+ "type": "text",
+ "text": "Create src/auth.ts with exactly these two lines:\nexport async function a(token:string){await fetch(u)}\nconst k = \"sk-proj-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\"\nAppend the line API_TOKEN=abcdefgh123 to .env."
+ }
+ ]
+ },
+ {
+ "info": {
+ "id": "msg_2",
+ "sessionID": "ses_1",
+ "role": "assistant"
+ },
+ "parts": [
+ {
+ "id": "prt_2",
+ "type": "step-start"
+ },
+ {
+ "id": "prt_3",
+ "type": "tool",
+ "callID": "call_1",
+ "tool": "apply_patch",
+ "state": {
+ "status": "completed",
+ "input": {
+ "patchText": "*** Begin Patch\n*** Add File: src/auth.ts\n+export async function a(token:string){await fetch(u)}\n+const k = \"sk-proj-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\"\n*** Update File: .env\n@@\n+API_TOKEN=abcdefgh123\n*** End Patch"
+ },
+ "output": "Success. Updated the following files:\nA src/auth.ts\nM .env",
+ "metadata": {
+ "diff": "Index: /work/proj/src/auth.ts\n===================================================================\n--- /work/proj/src/auth.ts\n+++ /work/proj/src/auth.ts\n@@ -0,0 +1,2 @@\n+export async function a(token:string){await fetch(u)}\n+const k = \"sk-proj-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\"\n\nIndex: /work/proj/.env\n===================================================================\n--- /work/proj/.env\n+++ /work/proj/.env\n@@ -1,2 +1,3 @@\n APP_NAME=demo\n DEBUG=1\n+API_TOKEN=abcdefgh123\n\n",
+ "files": [
+ {
+ "filePath": "/work/proj/src/auth.ts",
+ "relativePath": "src/auth.ts",
+ "type": "add",
+ "patch": "Index: /work/proj/src/auth.ts\n===================================================================\n--- /work/proj/src/auth.ts\n+++ /work/proj/src/auth.ts\n@@ -0,0 +1,2 @@\n+export async function a(token:string){await fetch(u)}\n+const k = \"sk-proj-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\"\n",
+ "additions": 2,
+ "deletions": 0
+ },
+ {
+ "filePath": "/work/proj/.env",
+ "relativePath": ".env",
+ "type": "update",
+ "patch": "Index: /work/proj/.env\n===================================================================\n--- /work/proj/.env\n+++ /work/proj/.env\n@@ -1,2 +1,3 @@\n APP_NAME=demo\n DEBUG=1\n+API_TOKEN=abcdefgh123\n",
+ "additions": 1,
+ "deletions": 0
+ }
+ ],
+ "diagnostics": {},
+ "truncated": false
+ }
+ }
+ },
+ {
+ "id": "prt_4",
+ "type": "patch",
+ "files": [
+ "/work/proj/src/auth.ts",
+ "/work/proj/.env"
+ ]
+ }
+ ]
+ },
+ {
+ "info": {
+ "id": "msg_3",
+ "sessionID": "ses_1",
+ "role": "assistant"
+ },
+ "parts": [
+ {
+ "id": "prt_5",
+ "type": "tool",
+ "callID": "call_2",
+ "tool": "bash",
+ "state": {
+ "status": "completed",
+ "input": {
+ "command": "echo 'export async function a(token:string){await fetch(u)}'; tail -n1 .env"
+ },
+ "output": "export async function a(token:string){await fetch(u)}\nAPI_TOKEN=abcdefgh123\n",
+ "metadata": {
+ "output": "export async function a(token:string){await fetch(u)}\nAPI_TOKEN=abcdefgh123\n"
+ }
+ }
+ }
+ ]
+ }
+ ]
+ }
+ }
+ ]
+ },
+ "expected": {
+ "schema_version": 1,
+ "session_id": "ses_1",
+ "events": [
+ {
+ "at": "2026-10-04T00:00:00.000Z",
+ "type": "engine.request",
+ "data": {
+ "agent": "omnirush-cli",
+ "prompt": "Create src/auth.ts with exactly these two lines:\nexport async function a(token:[REDACTED] fetch(u)}\nconst k = \"[REDACTED]\"\nAppend the line API_TOKEN=[REDACTED] to .env.",
+ "model": null
+ }
+ },
+ {
+ "at": "2026-10-04T00:00:01.000Z",
+ "type": "turn.completed",
+ "data": {
+ "messages": [
+ {
+ "info": {
+ "id": "msg_1",
+ "sessionID": "ses_1",
+ "role": "user",
+ "summary": {
+ "diffs": [
+ {
+ "file": ".env",
+ "patch": "Index: .env\n===================================================================\n--- .env\t\n+++ .env\t\n@@ -1,2 +1,3 @@\n APP_NAME=demo\n DEBUG=1\n+API_TOKEN=[REDACTED]\n",
+ "additions": 1,
+ "deletions": 0,
+ "status": "modified"
+ },
+ {
+ "file": "src/auth.ts",
+ "patch": "Index: src/auth.ts\n===================================================================\n--- src/auth.ts\t\n+++ src/auth.ts\t\n@@ -0,0 +1,2 @@\n+export async function a(token:string){await fetch(u)}\n+const k = \"[REDACTED]\"\n",
+ "additions": 2,
+ "deletions": 0,
+ "status": "added"
+ }
+ ]
+ }
+ },
+ "parts": [
+ {
+ "id": "prt_1",
+ "type": "text",
+ "text": "Create src/auth.ts with exactly these two lines:\nexport async function a(token:[REDACTED] fetch(u)}\nconst k = \"[REDACTED]\"\nAppend the line API_TOKEN=[REDACTED] to .env."
+ }
+ ]
+ },
+ {
+ "info": {
+ "id": "msg_2",
+ "sessionID": "ses_1",
+ "role": "assistant"
+ },
+ "parts": [
+ {
+ "id": "prt_2",
+ "type": "step-start"
+ },
+ {
+ "id": "prt_3",
+ "type": "tool",
+ "callID": "call_1",
+ "tool": "apply_patch",
+ "state": {
+ "status": "completed",
+ "input": {
+ "patchText": "*** Begin Patch\n*** Add File: src/auth.ts\n+export async function a(token:string){await fetch(u)}\n+const k = \"[REDACTED]\"\n*** Update File: .env\n@@\n+API_TOKEN=[REDACTED]\n*** End Patch"
+ },
+ "output": "Success. Updated the following files:\nA src/auth.ts\nM .env",
+ "metadata": {
+ "diff": "Index: /work/proj/src/auth.ts\n===================================================================\n--- /work/proj/src/auth.ts\n+++ /work/proj/src/auth.ts\n@@ -0,0 +1,2 @@\n+export async function a(token:string){await fetch(u)}\n+const k = \"[REDACTED]\"\n\nIndex: /work/proj/.env\n===================================================================\n--- /work/proj/.env\n+++ /work/proj/.env\n@@ -1,2 +1,3 @@\n APP_NAME=demo\n DEBUG=1\n+API_TOKEN=[REDACTED]\n\n",
+ "files": [
+ {
+ "filePath": "/work/proj/src/auth.ts",
+ "relativePath": "src/auth.ts",
+ "type": "add",
+ "patch": "Index: /work/proj/src/auth.ts\n===================================================================\n--- /work/proj/src/auth.ts\n+++ /work/proj/src/auth.ts\n@@ -0,0 +1,2 @@\n+export async function a(token:string){await fetch(u)}\n+const k = \"[REDACTED]\"\n",
+ "additions": 2,
+ "deletions": 0
+ },
+ {
+ "filePath": "/work/proj/.env",
+ "relativePath": ".env",
+ "type": "update",
+ "patch": "Index: /work/proj/.env\n===================================================================\n--- /work/proj/.env\n+++ /work/proj/.env\n@@ -1,2 +1,3 @@\n APP_NAME=demo\n DEBUG=1\n+API_TOKEN=[REDACTED]\n",
+ "additions": 1,
+ "deletions": 0
+ }
+ ],
+ "diagnostics": {},
+ "truncated": false
+ }
+ }
+ },
+ {
+ "id": "prt_4",
+ "type": "patch",
+ "files": [
+ "/work/proj/src/auth.ts",
+ "/work/proj/.env"
+ ]
+ }
+ ]
+ },
+ {
+ "info": {
+ "id": "msg_3",
+ "sessionID": "ses_1",
+ "role": "assistant"
+ },
+ "parts": [
+ {
+ "id": "prt_5",
+ "type": "tool",
+ "callID": "call_2",
+ "tool": "bash",
+ "state": {
+ "status": "completed",
+ "input": {
+ "command": "echo 'export async function a(token:[REDACTED] fetch(u)}'; tail -n1 .env"
+ },
+ "output": "export async function a(token:[REDACTED] fetch(u)}\nAPI_TOKEN=[REDACTED]\n",
+ "metadata": {
+ "output": "export async function a(token:[REDACTED] fetch(u)}\nAPI_TOKEN=[REDACTED]\n"
+ }
+ }
+ }
+ ]
+ }
+ ]
+ }
+ }
+ ]
+ }
+ },
+ {
+ "name": "pi turn.completed: write by `path`, edit with edits[] and a display diff, read of .env, 2.x name/v2 fields; turn.diff hunk",
+ "kind": "trace",
+ "input": {
+ "schema_version": 1,
+ "session_id": "ses_2",
+ "events": [
+ {
+ "at": "2026-10-04T00:00:00.000Z",
+ "type": "engine.request",
+ "data": {
+ "method": "POST",
+ "path": "/session/ses_2/prompt",
+ "body": {
+ "parts": [
+ {
+ "type": "text",
+ "text": "Create src/auth.ts with exactly these two lines:\nexport async function a(token:string){await fetch(u)}\nconst k = \"sk-proj-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\"\nAppend the line API_TOKEN=abcdefgh123 to .env."
+ }
+ ],
+ "agent": "omnirush-cli"
+ }
+ }
+ },
+ {
+ "at": "2026-10-04T00:00:01.000Z",
+ "type": "turn.completed",
+ "data": {
+ "messages": [
+ {
+ "info": {
+ "id": "msg_1",
+ "role": "user",
+ "type": "user",
+ "text": "Create src/auth.ts with exactly these two lines:\nexport async function a(token:string){await fetch(u)}\nconst k = \"sk-proj-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\"\nAppend the line API_TOKEN=abcdefgh123 to .env."
+ },
+ "parts": [
+ {
+ "id": "prt_1",
+ "type": "text",
+ "text": "Create src/auth.ts with exactly these two lines:\nexport async function a(token:string){await fetch(u)}\nconst k = \"sk-proj-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\"\nAppend the line API_TOKEN=abcdefgh123 to .env."
+ }
+ ]
+ },
+ {
+ "info": {
+ "id": "msg_2",
+ "role": "assistant"
+ },
+ "parts": [
+ {
+ "id": "prt_2",
+ "type": "tool",
+ "callID": "call_1|fc_1",
+ "tool": "read",
+ "state": {
+ "status": "completed",
+ "input": {
+ "path": ".env",
+ "offset": 1,
+ "limit": 200
+ },
+ "output": "APP_NAME=demo\nAPI_TOKEN=abcdefgh123\n",
+ "content": [
+ {
+ "type": "text",
+ "text": "APP_NAME=demo\nAPI_TOKEN=abcdefgh123\n"
+ }
+ ]
+ },
+ "name": "read",
+ "executed": false,
+ "v2": {
+ "id": "call_1"
+ }
+ },
+ {
+ "id": "prt_3",
+ "type": "tool",
+ "callID": "call_2|fc_2",
+ "tool": "write",
+ "state": {
+ "status": "completed",
+ "input": {
+ "path": "src/auth.ts",
+ "content": "export async function a(token:string){await fetch(u)}\nconst k = \"sk-proj-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\""
+ },
+ "output": "Successfully wrote to src/auth.ts",
+ "content": [
+ {
+ "type": "text",
+ "text": "Successfully wrote to src/auth.ts"
+ }
+ ]
+ },
+ "name": "write",
+ "executed": false,
+ "v2": {
+ "id": "call_2"
+ }
+ },
+ {
+ "id": "prt_4",
+ "type": "tool",
+ "callID": "call_3|fc_3",
+ "tool": "edit",
+ "state": {
+ "status": "completed",
+ "input": {
+ "path": "src/auth.ts",
+ "edits": [
+ {
+ "oldText": "await fetch(u)",
+ "newText": "await fetch(u, {headers})"
+ }
+ ]
+ },
+ "output": "Successfully replaced 1 block(s) in src/auth.ts.",
+ "metadata": {
+ "diff": "-1 export async function a(token:string){await fetch(u)}\n+1 export async function a(token:string){await fetch(u, {headers})}",
+ "patch": "--- src/auth.ts\n+++ src/auth.ts\n@@ -1,1 +1,1 @@\n-export async function a(token:string){await fetch(u)}\n+export async function a(token:string){await fetch(u, {headers})}\n",
+ "firstChangedLine": 1
+ }
+ },
+ "name": "edit",
+ "executed": false,
+ "v2": {
+ "id": "call_3"
+ }
+ },
+ {
+ "id": "prt_5",
+ "type": "tool",
+ "callID": "call_4|fc_4",
+ "tool": "edit",
+ "state": {
+ "status": "completed",
+ "input": {
+ "path": ".env",
+ "edits": [
+ {
+ "oldText": "DEBUG=1\n",
+ "newText": "DEBUG=1\nAPI_TOKEN=abcdefgh123\n"
+ }
+ ]
+ },
+ "output": "Successfully replaced 1 block(s) in .env.",
+ "metadata": {
+ "diff": " 1 DEBUG=1\n+2 API_TOKEN=abcdefgh123",
+ "patch": "--- .env\n+++ .env\n@@ -1,1 +1,2 @@\n DEBUG=1\n+API_TOKEN=abcdefgh123\n",
+ "firstChangedLine": 2
+ }
+ },
+ "name": "edit",
+ "executed": false,
+ "v2": {
+ "id": "call_4"
+ }
+ },
+ {
+ "id": "prt_6",
+ "type": "patch",
+ "files": [
+ "/work/proj/src/auth.ts",
+ "/work/proj/.env"
+ ]
+ }
+ ]
+ }
+ ]
+ }
+ },
+ {
+ "at": "2026-10-04T00:00:02.000Z",
+ "type": "turn.diff",
+ "data": {
+ "schema_version": 1,
+ "files": [
+ {
+ "path": "src/auth.ts",
+ "status": "added",
+ "before_sha256": null,
+ "after_sha256": "0000000000000000000000000000000000000000000000000000000000000000",
+ "additions": 2,
+ "deletions": 0,
+ "diff": "--- /dev/null\n+++ b/src/auth.ts\n@@ -0,0 +1,2 @@\n+export async function a(token:string){await fetch(u)}\n+const k = \"sk-proj-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\"\n\\ No newline at end of file\n",
+ "truncated": false,
+ "reason": null
+ },
+ {
+ "path": ".env",
+ "status": "modified",
+ "before_sha256": "1111111111111111111111111111111111111111111111111111111111111111",
+ "after_sha256": "2222222222222222222222222222222222222222222222222222222222222222",
+ "additions": 1,
+ "deletions": 0,
+ "diff": "--- a/.env\n+++ b/.env\n@@ -1,1 +1,2 @@\n DEBUG=1\n+API_TOKEN=abcdefgh123\n",
+ "truncated": false,
+ "reason": null
+ }
+ ],
+ "file_count": 2,
+ "omitted_file_count": 0,
+ "truncated": false
+ }
+ }
+ ]
+ },
+ "expected": {
+ "schema_version": 1,
+ "session_id": "ses_2",
+ "events": [
+ {
+ "at": "2026-10-04T00:00:00.000Z",
+ "type": "engine.request",
+ "data": {
+ "method": "POST",
+ "path": "/session/ses_2/prompt",
+ "body": {
+ "parts": [
+ {
+ "type": "text",
+ "text": "Create src/auth.ts with exactly these two lines:\nexport async function a(token:[REDACTED] fetch(u)}\nconst k = \"[REDACTED]\"\nAppend the line API_TOKEN=[REDACTED] to .env."
+ }
+ ],
+ "agent": "omnirush-cli"
+ }
+ }
+ },
+ {
+ "at": "2026-10-04T00:00:01.000Z",
+ "type": "turn.completed",
+ "data": {
+ "messages": [
+ {
+ "info": {
+ "id": "msg_1",
+ "role": "user",
+ "type": "user",
+ "text": "Create src/auth.ts with exactly these two lines:\nexport async function a(token:[REDACTED] fetch(u)}\nconst k = \"[REDACTED]\"\nAppend the line API_TOKEN=[REDACTED] to .env."
+ },
+ "parts": [
+ {
+ "id": "prt_1",
+ "type": "text",
+ "text": "Create src/auth.ts with exactly these two lines:\nexport async function a(token:[REDACTED] fetch(u)}\nconst k = \"[REDACTED]\"\nAppend the line API_TOKEN=[REDACTED] to .env."
+ }
+ ]
+ },
+ {
+ "info": {
+ "id": "msg_2",
+ "role": "assistant"
+ },
+ "parts": [
+ {
+ "id": "prt_2",
+ "type": "tool",
+ "callID": "call_1|fc_1",
+ "tool": "read",
+ "state": {
+ "status": "completed",
+ "input": {
+ "path": ".env",
+ "offset": 1,
+ "limit": 200
+ },
+ "output": "APP_NAME=demo\nAPI_TOKEN=[REDACTED]\n",
+ "content": [
+ {
+ "type": "text",
+ "text": "APP_NAME=demo\nAPI_TOKEN=[REDACTED]\n"
+ }
+ ]
+ },
+ "name": "read",
+ "executed": false,
+ "v2": {
+ "id": "call_1"
+ }
+ },
+ {
+ "id": "prt_3",
+ "type": "tool",
+ "callID": "call_2|fc_2",
+ "tool": "write",
+ "state": {
+ "status": "completed",
+ "input": {
+ "path": "src/auth.ts",
+ "content": "export async function a(token:string){await fetch(u)}\nconst k = \"[REDACTED]\""
+ },
+ "output": "Successfully wrote to src/auth.ts",
+ "content": [
+ {
+ "type": "text",
+ "text": "Successfully wrote to src/auth.ts"
+ }
+ ]
+ },
+ "name": "write",
+ "executed": false,
+ "v2": {
+ "id": "call_2"
+ }
+ },
+ {
+ "id": "prt_4",
+ "type": "tool",
+ "callID": "call_3|fc_3",
+ "tool": "edit",
+ "state": {
+ "status": "completed",
+ "input": {
+ "path": "src/auth.ts",
+ "edits": [
+ {
+ "oldText": "await fetch(u)",
+ "newText": "await fetch(u, {headers})"
+ }
+ ]
+ },
+ "output": "Successfully replaced 1 block(s) in src/auth.ts.",
+ "metadata": {
+ "diff": "-1 export async function a(token:string){await fetch(u)}\n+1 export async function a(token:string){await fetch(u, {headers})}",
+ "patch": "--- src/auth.ts\n+++ src/auth.ts\n@@ -1,1 +1,1 @@\n-export async function a(token:string){await fetch(u)}\n+export async function a(token:string){await fetch(u, {headers})}\n",
+ "firstChangedLine": 1
+ }
+ },
+ "name": "edit",
+ "executed": false,
+ "v2": {
+ "id": "call_3"
+ }
+ },
+ {
+ "id": "prt_5",
+ "type": "tool",
+ "callID": "call_4|fc_4",
+ "tool": "edit",
+ "state": {
+ "status": "completed",
+ "input": {
+ "path": ".env",
+ "edits": [
+ {
+ "oldText": "DEBUG=1\n",
+ "newText": "DEBUG=1\nAPI_TOKEN=[REDACTED]\n"
+ }
+ ]
+ },
+ "output": "Successfully replaced 1 block(s) in .env.",
+ "metadata": {
+ "diff": " 1 DEBUG=1\n+2 API_TOKEN=[REDACTED]",
+ "patch": "--- .env\n+++ .env\n@@ -1,1 +1,2 @@\n DEBUG=1\n+API_TOKEN=[REDACTED]\n",
+ "firstChangedLine": 2
+ }
+ },
+ "name": "edit",
+ "executed": false,
+ "v2": {
+ "id": "call_4"
+ }
+ },
+ {
+ "id": "prt_6",
+ "type": "patch",
+ "files": [
+ "/work/proj/src/auth.ts",
+ "/work/proj/.env"
+ ]
+ }
+ ]
+ }
+ ]
+ }
+ },
+ {
+ "at": "2026-10-04T00:00:02.000Z",
+ "type": "turn.diff",
+ "data": {
+ "schema_version": 1,
+ "files": [
+ {
+ "path": "src/auth.ts",
+ "status": "added",
+ "before_sha256": null,
+ "after_sha256": "0000000000000000000000000000000000000000000000000000000000000000",
+ "additions": 2,
+ "deletions": 0,
+ "diff": "--- /dev/null\n+++ b/src/auth.ts\n@@ -0,0 +1,2 @@\n+export async function a(token:string){await fetch(u)}\n+const k = \"[REDACTED]\"\n\\ No newline at end of file\n",
+ "truncated": false,
+ "reason": null
+ },
+ {
+ "path": ".env",
+ "status": "modified",
+ "before_sha256": "1111111111111111111111111111111111111111111111111111111111111111",
+ "after_sha256": "2222222222222222222222222222222222222222222222222222222222222222",
+ "additions": 1,
+ "deletions": 0,
+ "diff": "--- a/.env\n+++ b/.env\n@@ -1,1 +1,2 @@\n DEBUG=1\n+API_TOKEN=[REDACTED]\n",
+ "truncated": false,
+ "reason": null
+ }
+ ],
+ "file_count": 2,
+ "omitted_file_count": 0,
+ "truncated": false
+ }
+ }
+ ]
+ }
+ },
+ {
+ "name": "session.diff event: each item's before/after/patch takes its own `file`'s mode, a pathless item stays CONFIG",
+ "kind": "trace",
+ "input": {
+ "schema_version": 1,
+ "session_id": "ses_3",
+ "events": [
+ {
+ "at": "2026-10-04T00:00:00.000Z",
+ "type": "session.diff",
+ "data": {
+ "sessionID": "ses_3",
+ "diff": [
+ {
+ "file": "src/auth.ts",
+ "before": "",
+ "after": "export async function a(token:string){await fetch(u)}\nconst k = \"sk-proj-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\"\n",
+ "additions": 2,
+ "deletions": 0,
+ "status": "added"
+ },
+ {
+ "filename": "lib/b.py",
+ "patch": "@@ -0,0 +1 @@\n+async def a(token:str)->Awaitable[None]: pass\n",
+ "additions": 1,
+ "deletions": 0
+ },
+ {
+ "file": ".env",
+ "before": "DEBUG=1\n",
+ "after": "DEBUG=1\nAPI_TOKEN=abcdefgh123\n",
+ "additions": 1,
+ "deletions": 0,
+ "status": "modified"
+ },
+ {
+ "patch": "@@ -0,0 +1 @@\n+export async function a(token:string){await fetch(u)}\n",
+ "additions": 1,
+ "deletions": 0
+ }
+ ]
+ }
+ }
+ ]
+ },
+ "expected": {
+ "schema_version": 1,
+ "session_id": "ses_3",
+ "events": [
+ {
+ "at": "2026-10-04T00:00:00.000Z",
+ "type": "session.diff",
+ "data": {
+ "sessionID": "ses_3",
+ "diff": [
+ {
+ "file": "src/auth.ts",
+ "before": "",
+ "after": "export async function a(token:string){await fetch(u)}\nconst k = \"[REDACTED]\"\n",
+ "additions": 2,
+ "deletions": 0,
+ "status": "added"
+ },
+ {
+ "filename": "lib/b.py",
+ "patch": "@@ -0,0 +1 @@\n+async def a(token:str)->Awaitable[None]: pass\n",
+ "additions": 1,
+ "deletions": 0
+ },
+ {
+ "file": ".env",
+ "before": "DEBUG=1\n",
+ "after": "DEBUG=1\nAPI_TOKEN=[REDACTED]\n",
+ "additions": 1,
+ "deletions": 0,
+ "status": "modified"
+ },
+ {
+ "patch": "@@ -0,0 +1 @@\n+export async function a(token:[REDACTED] fetch(u)}\n",
+ "additions": 1,
+ "deletions": 0
+ }
+ ]
+ }
+ }
+ ]
+ }
+ },
+ {
+ "name": "pi toolCall blocks: write/edit arguments keep code by `path`/`file_path`; bash and read stay CONFIG",
+ "kind": "trace",
+ "input": {
+ "schema_version": 1,
+ "session_id": "ses_4",
+ "events": [
+ {
+ "at": "2026-10-04T00:00:00.000Z",
+ "type": "session.child",
+ "data": {
+ "child_session_id": "ses_5",
+ "parent_session_id": "ses_4",
+ "messages": [
+ {
+ "role": "assistant",
+ "content": [
+ {
+ "type": "toolCall",
+ "id": "call_1",
+ "name": "write",
+ "arguments": {
+ "path": "src/auth.ts",
+ "content": "export async function a(token:string){await fetch(u)}\nconst k = \"sk-proj-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\""
+ }
+ },
+ {
+ "type": "toolCall",
+ "id": "call_2",
+ "name": "edit",
+ "arguments": {
+ "file_path": "src/auth.ts",
+ "old_string": "fetch(u)",
+ "new_string": "fetch(u, {token:string})"
+ }
+ },
+ {
+ "type": "toolCall",
+ "id": "call_3",
+ "name": "edit",
+ "arguments": {
+ "path": ".env",
+ "edits": [
+ {
+ "oldText": "DEBUG=1",
+ "newText": "DEBUG=1\nAPI_TOKEN=abcdefgh123"
+ }
+ ]
+ }
+ },
+ {
+ "type": "toolCall",
+ "id": "call_4",
+ "name": "bash",
+ "arguments": {
+ "command": "echo 'export async function a(token:string){await fetch(u)}'"
+ }
+ },
+ {
+ "type": "toolCall",
+ "id": "call_5",
+ "name": "read",
+ "arguments": {
+ "path": "src/auth.ts"
+ }
+ }
+ ]
+ },
+ {
+ "role": "toolResult",
+ "toolCallId": "call_5",
+ "toolName": "read",
+ "content": [
+ {
+ "type": "text",
+ "text": "export async function a(token:string){await fetch(u)}"
+ }
+ ]
+ }
+ ]
+ }
+ }
+ ]
+ },
+ "expected": {
+ "schema_version": 1,
+ "session_id": "ses_4",
+ "events": [
+ {
+ "at": "2026-10-04T00:00:00.000Z",
+ "type": "session.child",
+ "data": {
+ "child_session_id": "ses_5",
+ "parent_session_id": "ses_4",
+ "messages": [
+ {
+ "role": "assistant",
+ "content": [
+ {
+ "type": "toolCall",
+ "id": "call_1",
+ "name": "write",
+ "arguments": {
+ "path": "src/auth.ts",
+ "content": "export async function a(token:string){await fetch(u)}\nconst k = \"[REDACTED]\""
+ }
+ },
+ {
+ "type": "toolCall",
+ "id": "call_2",
+ "name": "edit",
+ "arguments": {
+ "file_path": "src/auth.ts",
+ "old_string": "fetch(u)",
+ "new_string": "fetch(u, {token:string})"
+ }
+ },
+ {
+ "type": "toolCall",
+ "id": "call_3",
+ "name": "edit",
+ "arguments": {
+ "path": ".env",
+ "edits": [
+ {
+ "oldText": "DEBUG=1",
+ "newText": "DEBUG=1\nAPI_TOKEN=[REDACTED]"
+ }
+ ]
+ }
+ },
+ {
+ "type": "toolCall",
+ "id": "call_4",
+ "name": "bash",
+ "arguments": {
+ "command": "echo 'export async function a(token:[REDACTED] fetch(u)}'"
+ }
+ },
+ {
+ "type": "toolCall",
+ "id": "call_5",
+ "name": "read",
+ "arguments": {
+ "path": "src/auth.ts"
+ }
+ }
+ ]
+ },
+ {
+ "role": "toolResult",
+ "toolCallId": "call_5",
+ "toolName": "read",
+ "content": [
+ {
+ "type": "text",
+ "text": "export async function a(token:[REDACTED] fetch(u)}"
+ }
+ ]
+ }
+ ]
+ }
+ }
+ ]
+ }
+ },
{
"name": "git diff: a .ts section keeps code, a config section is redacted",
"kind": "git_diff",
diff --git a/apps/server/src/session-uploader.ts b/apps/server/src/session-uploader.ts
index 21594c92..420c8b70 100644
--- a/apps/server/src/session-uploader.ts
+++ b/apps/server/src/session-uploader.ts
@@ -1489,15 +1489,17 @@ function redactUploadContentCounted(path: string, text: string): { text: string;
// --- file-aware trace scrub --------------------------------------------------
// The trace is scrubbed in CONFIG mode, except for the strings that carry a
// workspace file's text: the content a file tool writes or replaces, the
-// diffs and patches it reports, a read tool's output and a "turn.diff"
-// event's hunks. Those are scrubbed with the mode the target file's path
-// selects (redactModeForPath), exactly as a snapshot of that file is, so
-// `f(token:string){...}` in a .ts file survives a write tool call the way it
-// survives the file upload. A diff or patch naming several files is scrubbed
-// file by file. Everything else (shell commands and output, chat text, other
-// tools' input and output, a file tool call with no path) stays CONFIG. The
-// backend's _file_aware_* helpers apply the identical rule; a change here
-// must land there too.
+// diffs and patches it reports, a read tool's output, and every file diff
+// entry wherever it sits (an opencode message's `summary.diffs`, a
+// `session.diff` item, a "turn.diff" event's hunks). Those are scrubbed
+// with the mode the target file's path selects (redactModeForPath), exactly
+// as a snapshot of that file is, so `f(token:string){...}` in a .ts file
+// survives a write tool call the way it survives the file upload. A diff or
+// patch naming several files is scrubbed file by file. Everything else
+// (shell commands and output, chat text, other tools' input and output, a
+// file tool call or diff with no path) stays CONFIG. The backend's
+// _file_aware_* helpers apply the identical rule, at collection and in its
+// export-time pass; a change here must land there too.
/** A string the file-aware pass already scrubbed: the JSON walker keeps it as it is. */
class Prescrubbed {
@@ -1517,6 +1519,8 @@ const FILE_TOOL_FRAGMENT_KEYS = ["oldString", "newString", "oldText", "newText",
const FILE_TOOL_PATCH_KEYS = ["patchText", "patch", "input"];
/** A file entry's path in tool metadata (apply_patch `files`, edit `filediff`). */
const FILE_ENTRY_PATH_KEYS = ["filePath", "file", "relativePath", "path"];
+/** A file diff entry's path outside a tool part (summary.diffs[], session.diff, turn.diff files[]). */
+const FILE_DIFF_PATH_KEYS = ["filePath", "file", "path", "file_path", "filename", "relativePath"];
// A diff or patch starts a new file at a git header, a jsdiff `Index:` line
// (opencode's edit and apply_patch metadata) or an apply_patch file marker.
const FILE_SEGMENT_START = /(?:^|(?<=\n))(?=diff --git |Index: |\*\*\* (?:Add|Update|Delete) File: )/;
@@ -1676,31 +1680,30 @@ function fileToolName(part: Record<string, unknown>): string | null {
}
/**
- * The record with the strings that carry file text prescrubbed under their
- * file's mode, or the record itself when it is neither a file tool part
- * (`{type: "tool", tool|name, state}`) nor a "turn.diff" event. The
- * backend's _file_aware_record.
+ * The path of a file diff entry found anywhere in the trace, or null: a
+ * record naming a file (`filePath`, `file`, `path`, `file_path`,
+ * `filename`, `relativePath`) next to a `patch` or `diff` string, or next to
+ * whole-file `before`/`after` texts with `additions`/`deletions` counts.
+ * That is an opencode message's `summary.diffs[]` item and a `session.diff`
+ * event's item (`{file, patch|before|after, additions, deletions, status}`)
+ * and a "turn.diff" event's `files[]` item (`{path, diff}`).
*/
-function fileAwareRecord(record: Record<string, unknown>, tally: { count: number }): Record<string, unknown> {
- if (record.type === "turn.diff" && isRecord(record.data) && Array.isArray(record.data.files)) {
- const files = record.data.files.map((entry) => {
- if (!isRecord(entry)) return entry;
- const copy: Record<string, unknown> = { ...entry };
- prescrub(copy, "diff", (text) => redactDiffByFile(text, fileToolPath(entry.path), tally));
- return copy;
- });
- return { ...record, data: { ...record.data, files } };
- }
- if (record.type !== "tool" || !isRecord(record.state)) return record;
- const name = fileToolName(record);
- if (name === null) return record;
- const state: Record<string, unknown> = { ...record.state };
+function fileDiffEntryPath(record: Record<string, unknown>): string | null {
+ const hasDiff = typeof record.patch === "string" || typeof record.diff === "string";
+ const hasTexts = (typeof record.before === "string" || typeof record.after === "string")
+ && (typeof record.additions === "number" || typeof record.deletions === "number");
+ return hasDiff || hasTexts ? firstFilePath([record], FILE_DIFF_PATH_KEYS) : null;
+}
+
+/** A tool's state (an engine tool part's `state`) with the file text it carries prescrubbed. */
+function fileAwareToolState(source: Record<string, unknown>, name: string, tally: { count: number }): Record<string, unknown> {
+ const state: Record<string, unknown> = { ...source };
const v2 = isRecord(state.v2) ? { ...state.v2 } : null;
const inputs = [state.input, v2?.input].filter(isRecord);
const path = firstFilePath(inputs, FILE_TOOL_PATH_KEYS);
if (FILE_READ_TOOLS.has(name)) {
if (path !== null) fileAwareReadState(state, path, tally);
- return { ...record, state };
+ return state;
}
if (isRecord(state.input)) state.input = fileAwareToolInput(state.input, name, path, tally);
if (isRecord(state.metadata)) state.metadata = fileAwareToolMetadata(state.metadata, path, tally);
@@ -1708,7 +1711,42 @@ function fileAwareRecord(record: Record<string, unknown>, tally: { count: number
if (isRecord(v2.input)) v2.input = fileAwareToolInput(v2.input, name, path, tally);
state.v2 = v2;
}
- return { ...record, state };
+ return state;
+}
+
+/**
+ * The record with the strings that carry file text prescrubbed under their
+ * file's mode, or the record itself when it carries none. The walker calls
+ * it on every object of the trace, at any depth, so a shape is handled
+ * wherever it sits (a "turn.completed" or "turn.messages" event's
+ * `data.messages[].parts[]`, a "session.child" event's messages, an
+ * envelope's events):
+ *
+ * - an engine tool part of a file tool, `{type: "tool", tool|name, state}`
+ * (opencode, pi, 2.x natives under `state.v2`);
+ * - a pi tool call, `{type: "toolCall", name, arguments}`;
+ * - a file diff entry (fileDiffEntryPath): message `summary.diffs[]`,
+ * `session.diff` items, "turn.diff" `files[]`.
+ *
+ * The backend's _file_aware_record.
+ */
+function fileAwareRecord(record: Record<string, unknown>, tally: { count: number }): Record<string, unknown> {
+ if (record.type === "tool" && isRecord(record.state)) {
+ const name = fileToolName(record);
+ return name === null ? record : { ...record, state: fileAwareToolState(record.state, name, tally) };
+ }
+ if (record.type === "toolCall" && isRecord(record.arguments)) {
+ const name = fileToolName(record);
+ if (name === null || FILE_READ_TOOLS.has(name)) return record;
+ const path = firstFilePath([record.arguments], FILE_TOOL_PATH_KEYS);
+ return { ...record, arguments: fileAwareToolInput(record.arguments, name, path, tally) };
+ }
+ const path = fileDiffEntryPath(record);
+ if (path === null) return record;
+ const copy: Record<string, unknown> = { ...record };
+ for (const key of ["patch", "diff"]) prescrub(copy, key, (text) => redactDiffByFile(text, path, tally));
+ for (const key of ["before", "after"]) prescrub(copy, key, (text) => redactFileContent(text, path, tally));
+ return copy;
}
/**