@oyasmi/pipiclaw 0.9.5 → 0.9.6-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (345) hide show
  1. package/README.en.md +300 -142
  2. package/README.md +295 -140
  3. package/dist/agent/builtin-commands.d.ts +1 -1
  4. package/dist/agent/builtin-commands.js +1 -1
  5. package/dist/agent/channel-runner.d.ts +4 -3
  6. package/dist/agent/channel-runner.js +17 -28
  7. package/dist/agent/maintenance-context.js +2 -2
  8. package/dist/agent/prompt/builder.d.ts +1 -1
  9. package/dist/agent/prompt/builder.js +1 -1
  10. package/dist/agent/prompt/extension.d.ts +1 -1
  11. package/dist/agent/prompt/extension.js +1 -1
  12. package/dist/agent/prompt/manifest.d.ts +6 -1
  13. package/dist/agent/prompt/manifest.js +12 -5
  14. package/dist/agent/prompt/resources.d.ts +0 -3
  15. package/dist/agent/prompt/resources.js +0 -6
  16. package/dist/agent/prompt/sections.d.ts +2 -2
  17. package/dist/agent/prompt/sections.js +36 -26
  18. package/dist/agent/prompt/types.d.ts +3 -2
  19. package/dist/agent/runner-factory.js +1 -1
  20. package/dist/agent/session/command-extension.js +3 -1
  21. package/dist/agent/session/compaction-summary.js +3 -6
  22. package/dist/agent/session/compaction.d.ts +2 -0
  23. package/dist/agent/session/compaction.js +22 -14
  24. package/dist/agent/session/event-guards.d.ts +2 -1
  25. package/dist/agent/session/event-guards.js +6 -0
  26. package/dist/agent/session/model-selection.d.ts +2 -1
  27. package/dist/agent/session/model-selection.js +5 -5
  28. package/dist/agent/session/session-events.js +31 -4
  29. package/dist/agent/session/session-host.d.ts +5 -3
  30. package/dist/agent/session/session-host.js +20 -16
  31. package/dist/agent/status-render.js +3 -0
  32. package/dist/agent/stop-watchdog.js +5 -1
  33. package/dist/agent/turn/task-digest.d.ts +2 -5
  34. package/dist/agent/turn/task-digest.js +25 -45
  35. package/dist/agent/turn/turn-context.js +4 -6
  36. package/dist/agent/turn/turn-error.d.ts +1 -1
  37. package/dist/agent/turn/turn-error.js +9 -0
  38. package/dist/agent/turn/turn-pipeline.d.ts +10 -5
  39. package/dist/agent/turn/turn-pipeline.js +36 -7
  40. package/dist/agent/turn/turn-prompt.d.ts +2 -0
  41. package/dist/agent/turn/turn-prompt.js +2 -1
  42. package/dist/agent/turn/turn-recovery.js +4 -1
  43. package/dist/agent/turn/turn-state.d.ts +2 -0
  44. package/dist/agent/turn/turn-state.js +2 -1
  45. package/dist/agent/types.d.ts +23 -3
  46. package/dist/agent/types.js +2 -0
  47. package/dist/app/auth-command.d.ts +25 -0
  48. package/dist/app/auth-command.js +200 -67
  49. package/dist/app/home.d.ts +7 -8
  50. package/dist/app/home.js +143 -56
  51. package/dist/channel/attachments.d.ts +4 -0
  52. package/dist/channel/attachments.js +4 -0
  53. package/dist/channel/channel-context.d.ts +6 -0
  54. package/dist/channel/config.d.ts +3 -0
  55. package/dist/channel/config.js +11 -5
  56. package/dist/channel/store.d.ts +1 -1
  57. package/dist/commands/catalog.js +42 -10
  58. package/dist/commands/router.js +5 -1
  59. package/dist/desk/commands.d.ts +44 -5
  60. package/dist/desk/commands.js +162 -28
  61. package/dist/desk/paths.d.ts +6 -0
  62. package/dist/desk/paths.js +21 -1
  63. package/dist/desk/registry.d.ts +17 -2
  64. package/dist/desk/registry.js +122 -12
  65. package/dist/desk/types.d.ts +83 -1
  66. package/dist/dingtalk/bot.d.ts +1 -1
  67. package/dist/dingtalk/bot.js +4 -3
  68. package/dist/dingtalk/config.js +10 -10
  69. package/dist/dingtalk/delivery.js +15 -8
  70. package/dist/dingtalk/inbound-media.d.ts +36 -14
  71. package/dist/dingtalk/inbound-media.js +71 -12
  72. package/dist/dingtalk/inbound.d.ts +9 -2
  73. package/dist/dingtalk/inbound.js +17 -2
  74. package/dist/dingtalk/media.d.ts +4 -10
  75. package/dist/dingtalk/media.js +58 -32
  76. package/dist/events/commands.d.ts +2 -0
  77. package/dist/events/commands.js +13 -8
  78. package/dist/events/history.d.ts +9 -0
  79. package/dist/events/history.js +66 -0
  80. package/dist/events/parse.js +7 -3
  81. package/dist/events/types.d.ts +3 -0
  82. package/dist/events/watcher.d.ts +4 -8
  83. package/dist/events/watcher.js +53 -58
  84. package/dist/jobs/kill.d.ts +23 -0
  85. package/dist/jobs/kill.js +65 -0
  86. package/dist/jobs/manager.d.ts +19 -18
  87. package/dist/jobs/manager.js +36 -103
  88. package/dist/main.js +15 -3
  89. package/dist/memory/boundary-work.d.ts +2 -1
  90. package/dist/memory/boundary-work.js +1 -1
  91. package/dist/memory/lifecycle.d.ts +2 -1
  92. package/dist/memory/lifecycle.js +2 -2
  93. package/dist/memory/reflect-job.d.ts +2 -1
  94. package/dist/memory/reflect-job.js +1 -1
  95. package/dist/memory/reflect.d.ts +2 -1
  96. package/dist/memory/reflect.js +25 -4
  97. package/dist/memory/scheduler.d.ts +2 -1
  98. package/dist/memory/scheduler.js +1 -1
  99. package/dist/memory/session-corpus.d.ts +1 -1
  100. package/dist/memory/session-corpus.js +76 -1
  101. package/dist/memory/session-search.d.ts +2 -1
  102. package/dist/memory/session-search.js +14 -12
  103. package/dist/memory/sidecar-worker.d.ts +2 -1
  104. package/dist/memory/sidecar-worker.js +2 -4
  105. package/dist/memory/store.d.ts +2 -0
  106. package/dist/memory/store.js +19 -9
  107. package/dist/models/credential-work.d.ts +7 -0
  108. package/dist/models/credential-work.js +36 -0
  109. package/dist/models/login-ui.js +4 -4
  110. package/dist/models/provider-login.js +7 -6
  111. package/dist/models/requests.d.ts +8 -0
  112. package/dist/models/requests.js +69 -0
  113. package/dist/models/runtime.d.ts +3 -1
  114. package/dist/models/runtime.js +9 -2
  115. package/dist/playbooks/agent-delegation.md +20 -45
  116. package/dist/playbooks/background-jobs.md +1 -1
  117. package/dist/playbooks/catalog.js +1 -1
  118. package/dist/playbooks/delegation-inline.md +25 -0
  119. package/dist/playbooks/delegation-recovery.md +28 -0
  120. package/dist/playbooks/event-scheduling.md +18 -37
  121. package/dist/playbooks/event-sensors.md +26 -0
  122. package/dist/playbooks/event-task-template.md +22 -0
  123. package/dist/playbooks/learning-and-skills.md +26 -0
  124. package/dist/playbooks/memory-operations.md +36 -0
  125. package/dist/playbooks/outbound-media.md +2 -2
  126. package/dist/playbooks/runtime-files.md +29 -0
  127. package/dist/playbooks/runtime-operations.md +25 -0
  128. package/dist/playbooks/runtime-orientation.md +18 -53
  129. package/dist/playbooks/task-lead.md +22 -68
  130. package/dist/playbooks/task-manage.md +38 -0
  131. package/dist/playbooks/task-recovery.md +24 -0
  132. package/dist/playbooks/task-verify.md +22 -0
  133. package/dist/runtime/bootstrap.d.ts +10 -0
  134. package/dist/runtime/bootstrap.js +93 -29
  135. package/dist/runtime/daemon-lock.js +3 -3
  136. package/dist/runtime/desk-runtime.d.ts +40 -7
  137. package/dist/runtime/desk-runtime.js +330 -44
  138. package/dist/runtime/durable-dispatch.d.ts +14 -2
  139. package/dist/runtime/durable-dispatch.js +207 -65
  140. package/dist/runtime/ingress-busy.js +17 -8
  141. package/dist/runtime/ingress-commands.js +24 -4
  142. package/dist/runtime/ingress-deps.d.ts +4 -1
  143. package/dist/runtime/ingress.js +6 -1
  144. package/dist/runtime/request-execution.js +7 -6
  145. package/dist/runtime/shutdown.d.ts +4 -1
  146. package/dist/runtime/shutdown.js +88 -35
  147. package/dist/runtime/task-close.d.ts +1 -1
  148. package/dist/runtime/task-close.js +6 -3
  149. package/dist/runtime/task-control.d.ts +2 -3
  150. package/dist/runtime/task-control.js +38 -11
  151. package/dist/runtime/task-input.js +1 -1
  152. package/dist/runtime/task-lane-types.d.ts +12 -2
  153. package/dist/runtime/task-lane-types.js +9 -0
  154. package/dist/runtime/task-lane.d.ts +2 -0
  155. package/dist/runtime/task-lane.js +38 -20
  156. package/dist/runtime/task-step.d.ts +3 -3
  157. package/dist/runtime/task-step.js +34 -16
  158. package/dist/runtime/transports.js +6 -5
  159. package/dist/runtime/turn-run.js +103 -66
  160. package/dist/security/command-guard.d.ts +1 -1
  161. package/dist/security/command-guard.js +259 -314
  162. package/dist/security/path-guard.js +48 -7
  163. package/dist/security/shell-parse.d.ts +10 -0
  164. package/dist/security/shell-parse.js +224 -0
  165. package/dist/security/types.d.ts +2 -0
  166. package/dist/subagents/commands.d.ts +1 -1
  167. package/dist/subagents/commands.js +14 -5
  168. package/dist/subagents/completion-wake.js +6 -0
  169. package/dist/subagents/detached-discovery.d.ts +1 -1
  170. package/dist/subagents/discovery.d.ts +18 -199
  171. package/dist/subagents/discovery.js +35 -289
  172. package/dist/subagents/dispatch.d.ts +1 -2
  173. package/dist/subagents/dispatch.js +50 -29
  174. package/dist/subagents/external/antigravity-cli.d.ts +2 -0
  175. package/dist/subagents/external/antigravity-cli.js +517 -0
  176. package/dist/subagents/external/claude-code.js +8 -17
  177. package/dist/subagents/external/codex-cli.js +8 -18
  178. package/dist/subagents/external/cursor-cli.js +34 -31
  179. package/dist/subagents/external/dispatch.d.ts +21 -7
  180. package/dist/subagents/external/dispatch.js +146 -12
  181. package/dist/subagents/external/exec.js +3 -0
  182. package/dist/subagents/external/harness.d.ts +57 -33
  183. package/dist/subagents/external/harness.js +69 -40
  184. package/dist/subagents/external/reconciliation.js +1 -0
  185. package/dist/subagents/external/registry.js +4 -1
  186. package/dist/subagents/external/role-warnings.d.ts +4 -13
  187. package/dist/subagents/external/role-warnings.js +4 -28
  188. package/dist/subagents/external/run.d.ts +1 -2
  189. package/dist/subagents/external/run.js +16 -26
  190. package/dist/subagents/external/settlement.d.ts +2 -0
  191. package/dist/subagents/external/settlement.js +13 -3
  192. package/dist/subagents/format.d.ts +1 -1
  193. package/dist/subagents/format.js +1 -1
  194. package/dist/subagents/internal/outcome.d.ts +1 -2
  195. package/dist/subagents/internal/outcome.js +19 -12
  196. package/dist/subagents/internal/provider-retry.d.ts +1 -2
  197. package/dist/subagents/internal/provider-retry.js +2 -4
  198. package/dist/subagents/internal/run.d.ts +2 -3
  199. package/dist/subagents/internal/run.js +27 -4
  200. package/dist/subagents/internal/state.d.ts +2 -5
  201. package/dist/subagents/internal/state.js +1 -2
  202. package/dist/subagents/internal/worker.d.ts +1 -2
  203. package/dist/subagents/internal/worker.js +20 -10
  204. package/dist/subagents/resolve.d.ts +56 -0
  205. package/dist/subagents/resolve.js +202 -0
  206. package/dist/subagents/result.d.ts +6 -4
  207. package/dist/subagents/result.js +39 -6
  208. package/dist/subagents/run-record.d.ts +54 -2
  209. package/dist/subagents/run-record.js +7 -0
  210. package/dist/subagents/runs.d.ts +6 -31
  211. package/dist/subagents/runs.js +26 -31
  212. package/dist/subagents/task-envelope.d.ts +1 -2
  213. package/dist/subagents/task-envelope.js +13 -4
  214. package/dist/subagents/task-settlement.js +1 -0
  215. package/dist/subagents/types.d.ts +105 -6
  216. package/dist/subagents/types.js +16 -1
  217. package/dist/subagents/workspace-lease.d.ts +41 -24
  218. package/dist/subagents/workspace-lease.js +159 -24
  219. package/dist/subagents/worktree.d.ts +52 -0
  220. package/dist/subagents/worktree.js +363 -0
  221. package/dist/tasks/archive.js +4 -0
  222. package/dist/tasks/brief.d.ts +5 -1
  223. package/dist/tasks/brief.js +19 -5
  224. package/dist/tasks/commands.d.ts +6 -1
  225. package/dist/tasks/commands.js +32 -7
  226. package/dist/tasks/control.d.ts +11 -0
  227. package/dist/tasks/delivery.d.ts +2 -0
  228. package/dist/tasks/delivery.js +141 -21
  229. package/dist/tasks/loop-log.d.ts +12 -0
  230. package/dist/tasks/loop-log.js +10 -1
  231. package/dist/tasks/receipts.d.ts +7 -3
  232. package/dist/tasks/receipts.js +34 -5
  233. package/dist/tools/bash.d.ts +3 -0
  234. package/dist/tools/bash.js +29 -15
  235. package/dist/tools/contract/presentation.js +7 -5
  236. package/dist/tools/edit-diff.d.ts +11 -0
  237. package/dist/tools/edit-diff.js +148 -0
  238. package/dist/tools/edit-match.d.ts +18 -0
  239. package/dist/tools/edit-match.js +242 -0
  240. package/dist/tools/edit.d.ts +10 -2
  241. package/dist/tools/edit.js +91 -361
  242. package/dist/tools/event-manage.d.ts +2 -1
  243. package/dist/tools/event-manage.js +46 -39
  244. package/dist/tools/file-observations.d.ts +9 -0
  245. package/dist/tools/file-observations.js +50 -0
  246. package/dist/tools/glob-match.d.ts +3 -1
  247. package/dist/tools/glob-match.js +40 -17
  248. package/dist/tools/glob.d.ts +1 -0
  249. package/dist/tools/glob.js +39 -19
  250. package/dist/tools/grep-command.d.ts +13 -0
  251. package/dist/tools/grep-command.js +77 -0
  252. package/dist/tools/grep.js +96 -201
  253. package/dist/tools/index.d.ts +6 -2
  254. package/dist/tools/index.js +9 -4
  255. package/dist/tools/job.js +12 -11
  256. package/dist/tools/read.d.ts +2 -0
  257. package/dist/tools/read.js +10 -2
  258. package/dist/tools/registry.d.ts +16 -11
  259. package/dist/tools/registry.js +32 -12
  260. package/dist/tools/send-media.js +9 -5
  261. package/dist/tools/session-search.d.ts +2 -1
  262. package/dist/tools/session-search.js +15 -5
  263. package/dist/tools/skill.js +13 -12
  264. package/dist/tools/subagent-manage.d.ts +1 -1
  265. package/dist/tools/subagent-manage.js +25 -152
  266. package/dist/tools/subagent.d.ts +24 -2
  267. package/dist/tools/subagent.js +24 -18
  268. package/dist/tools/task-manage/control-tools.js +1 -1
  269. package/dist/tools/task-manage/factory.d.ts +2 -2
  270. package/dist/tools/task-manage/factory.js +40 -4
  271. package/dist/tools/task-manage/lifecycle.d.ts +3 -3
  272. package/dist/tools/task-manage/lifecycle.js +56 -13
  273. package/dist/tools/task-manage/schema.d.ts +4 -1
  274. package/dist/tools/task-manage/schema.js +4 -1
  275. package/dist/tools/task-manage/shared.d.ts +1 -1
  276. package/dist/tools/task-manage/types.d.ts +5 -1
  277. package/dist/tools/write-content.d.ts +7 -1
  278. package/dist/tools/write-content.js +18 -6
  279. package/dist/tools/write.d.ts +3 -0
  280. package/dist/tools/write.js +6 -2
  281. package/dist/tui/cli.d.ts +6 -6
  282. package/dist/tui/cli.js +120 -28
  283. package/dist/tui/client.d.ts +7 -0
  284. package/dist/tui/client.js +67 -16
  285. package/dist/tui/frontend.d.ts +2 -0
  286. package/dist/tui/pitui-frontend.d.ts +4 -0
  287. package/dist/tui/pitui-frontend.js +27 -0
  288. package/dist/tui/render.d.ts +1 -0
  289. package/dist/tui/render.js +5 -0
  290. package/dist/tui/session.js +6 -0
  291. package/dist/usage/ledger.d.ts +1 -1
  292. package/dist/usage/render.js +1 -1
  293. package/dist/web/client.d.ts +1 -0
  294. package/dist/web/client.js +11 -0
  295. package/dist/web/fetch.js +6 -3
  296. package/dist/webapi/auth.d.ts +0 -3
  297. package/dist/webapi/auth.js +3 -7
  298. package/dist/webapi/config.js +17 -14
  299. package/dist/webapi/key-command.js +41 -41
  300. package/dist/webapi/response-state.d.ts +7 -1
  301. package/dist/webapi/response-state.js +166 -3
  302. package/dist/webapi/routes/websocket.js +24 -1
  303. package/dist/webapi/server.d.ts +3 -1
  304. package/dist/webapi/server.js +32 -1
  305. package/dist/webapi/service.js +8 -0
  306. package/dist/webapi/transport.d.ts +2 -0
  307. package/dist/webapi/transport.js +11 -1
  308. package/examples/sub-agents/README.md +43 -75
  309. package/examples/sub-agents/agy-main.md +21 -0
  310. package/examples/sub-agents/claude-high.md +21 -0
  311. package/examples/sub-agents/claude-main.md +21 -0
  312. package/examples/sub-agents/codex-flash.md +21 -0
  313. package/examples/sub-agents/codex-high.md +21 -0
  314. package/examples/sub-agents/codex-main.md +21 -0
  315. package/examples/sub-agents/codex-review.md +20 -0
  316. package/examples/sub-agents/cursor-high.md +20 -0
  317. package/examples/sub-agents/cursor-main.md +20 -0
  318. package/examples/sub-agents/glm-flash.md +21 -0
  319. package/examples/sub-agents/glm-high.md +21 -0
  320. package/examples/sub-agents/pi-scout.md +20 -0
  321. package/package.json +11 -12
  322. package/dist/agent/session/request-tools.d.ts +0 -3
  323. package/dist/agent/session/request-tools.js +0 -20
  324. package/dist/models/api-keys.d.ts +0 -11
  325. package/dist/models/api-keys.js +0 -22
  326. package/dist/playbooks/memory-and-learning.md +0 -55
  327. package/examples/sub-agents/agents/claude-high.md +0 -23
  328. package/examples/sub-agents/agents/claude-main.md +0 -23
  329. package/examples/sub-agents/agents/codex-flash.md +0 -23
  330. package/examples/sub-agents/agents/codex-high.md +0 -23
  331. package/examples/sub-agents/agents/codex-main.md +0 -23
  332. package/examples/sub-agents/agents/codex-review.md +0 -23
  333. package/examples/sub-agents/agents/cursor-high.md +0 -22
  334. package/examples/sub-agents/agents/cursor-main.md +0 -22
  335. package/examples/sub-agents/agents/glm-flash.md +0 -23
  336. package/examples/sub-agents/agents/glm-high.md +0 -23
  337. package/examples/sub-agents/agents/scout.md +0 -30
  338. package/examples/sub-agents/roles/builder-hard.md +0 -34
  339. package/examples/sub-agents/roles/builder.md +0 -34
  340. package/examples/sub-agents/roles/explorer.md +0 -39
  341. package/examples/sub-agents/roles/git-committer.md +0 -43
  342. package/examples/sub-agents/roles/planner.md +0 -33
  343. package/examples/sub-agents/roles/reviewer.md +0 -33
  344. package/examples/sub-agents/roles/verifier.md +0 -35
  345. package/examples/sub-agents/roles/worker.md +0 -34
@@ -0,0 +1,517 @@
1
+ import { splitShellWords } from "../../shared/shell-words.js";
2
+ import { isPlainObject } from "../../shared/type-guards.js";
3
+ import { detectExistingFlags, expandPlaceholders, formatDroppedPlaceholderWarnings, outputFormatConflicts, parseJsonObjectLines, } from "./harness.js";
4
+ /**
5
+ * `antigravity-cli` harness (spec 068). One prompt, one short-lived `agy` process.
6
+ *
7
+ * Unlike `claude` and `agent`, `agy`'s `-p` / `--print` / `--prompt` flags take a string argument
8
+ * (`flag.StringVar`) and block piped stdin, so this adapter never passes `-p`. Piped stdin with
9
+ * `--output-format stream-json` enters headless print mode automatically.
10
+ *
11
+ * Event shapes and token semantics were verified against `agy 1.5.9`:
12
+ * - `output_tokens` already includes `thinking_tokens`; `total_tokens = input_tokens + output_tokens`.
13
+ * - `--conversation <id>` follow-ups report cumulative conversation totals in `result.usage` while
14
+ * `step_update.usage` reports only the current invocation's steps (no historical step replay).
15
+ * - Invalid `--conversation <id>` on a model prompt logs a stderr warning and silently allocates a
16
+ * new UUID, so `expectedResumeSessionId` is verified in `parseOutcome` (D8).
17
+ */
18
+ const THINKING_LEVEL_TO_ANTIGRAVITY_EFFORT = {
19
+ off: "low",
20
+ minimal: "low",
21
+ low: "low",
22
+ medium: "medium",
23
+ high: "high",
24
+ xhigh: "xhigh",
25
+ max: "max",
26
+ };
27
+ const PROGRESS_LABEL_MAX_CHARS = 80;
28
+ const MAX_DENIED_ACTION_PREVIEW_ITEMS = 5;
29
+ const MAX_DENIED_ACTION_ITEM_CHARS = 80;
30
+ const TOOL_SUBJECT_FIELDS = [
31
+ "CommandLine",
32
+ "command",
33
+ "Path",
34
+ "TargetFile",
35
+ "SearchPath",
36
+ "Directory",
37
+ "file_path",
38
+ "target_file",
39
+ "path",
40
+ "Query",
41
+ "Pattern",
42
+ "query",
43
+ "pattern",
44
+ "Url",
45
+ "url",
46
+ "Role",
47
+ "Description",
48
+ "toolSummary",
49
+ ];
50
+ function toAntigravityEffort(level) {
51
+ return THINKING_LEVEL_TO_ANTIGRAVITY_EFFORT[level] ?? level;
52
+ }
53
+ function hasPrintToken(token) {
54
+ return (token === "-p" ||
55
+ token === "--print" ||
56
+ token === "--prompt" ||
57
+ token.startsWith("--print=") ||
58
+ token.startsWith("--prompt="));
59
+ }
60
+ function hasInteractiveToken(token) {
61
+ return token === "-i" || token === "--prompt-interactive" || token.startsWith("--prompt-interactive=");
62
+ }
63
+ function hasConversationToken(token) {
64
+ return (token === "-c" ||
65
+ token === "--continue" ||
66
+ token === "--conversation" ||
67
+ token.startsWith("--continue=") ||
68
+ token.startsWith("--conversation="));
69
+ }
70
+ function resolveEffectiveMode(tokens) {
71
+ let mode;
72
+ for (let i = 0; i < tokens.length; i += 1) {
73
+ const token = tokens[i];
74
+ if (token === "--mode") {
75
+ const next = tokens[i + 1];
76
+ if (next !== undefined) {
77
+ mode = next;
78
+ i += 1;
79
+ }
80
+ }
81
+ else if (token.startsWith("--mode=")) {
82
+ mode = token.slice("--mode=".length);
83
+ }
84
+ }
85
+ return mode;
86
+ }
87
+ function collapseWhitespace(text) {
88
+ return text.replace(/\s+/g, " ").trim();
89
+ }
90
+ function isNonNegativeFiniteNumber(value) {
91
+ return typeof value === "number" && Number.isFinite(value) && value >= 0;
92
+ }
93
+ function parseUsageSnapshot(raw) {
94
+ if (!isPlainObject(raw))
95
+ return undefined;
96
+ if (!isNonNegativeFiniteNumber(raw.input_tokens))
97
+ return undefined;
98
+ if (!isNonNegativeFiniteNumber(raw.output_tokens))
99
+ return undefined;
100
+ if (raw.cache_read_tokens !== undefined && !isNonNegativeFiniteNumber(raw.cache_read_tokens)) {
101
+ return undefined;
102
+ }
103
+ if (raw.thinking_tokens !== undefined && !isNonNegativeFiniteNumber(raw.thinking_tokens)) {
104
+ return undefined;
105
+ }
106
+ if (raw.total_tokens !== undefined && !isNonNegativeFiniteNumber(raw.total_tokens)) {
107
+ return undefined;
108
+ }
109
+ const input = raw.input_tokens;
110
+ const output = raw.output_tokens;
111
+ const cacheRead = raw.cache_read_tokens ?? 0;
112
+ const total = raw.total_tokens ?? input + output;
113
+ return {
114
+ input,
115
+ output,
116
+ cacheRead,
117
+ cacheWrite: 0,
118
+ total,
119
+ };
120
+ }
121
+ function isNonZeroUsage(snapshot) {
122
+ return snapshot.input > 0 || snapshot.output > 0 || snapshot.cacheRead > 0 || snapshot.total > 0;
123
+ }
124
+ function sumUsageSnapshots(snapshots) {
125
+ let input = 0;
126
+ let output = 0;
127
+ let cacheRead = 0;
128
+ let total = 0;
129
+ for (const item of snapshots) {
130
+ input += item.input;
131
+ output += item.output;
132
+ cacheRead += item.cacheRead;
133
+ total += item.total;
134
+ }
135
+ return {
136
+ input,
137
+ output,
138
+ cacheRead,
139
+ cacheWrite: 0,
140
+ total,
141
+ };
142
+ }
143
+ function joinStepsWithBoundaries(steps) {
144
+ if (steps.length === 0)
145
+ return "";
146
+ let acc = steps[0];
147
+ for (let i = 1; i < steps.length; i += 1) {
148
+ const next = steps[i];
149
+ if (!acc.endsWith("\n") && !next.startsWith("\n")) {
150
+ acc += "\n";
151
+ }
152
+ acc += next;
153
+ }
154
+ return acc;
155
+ }
156
+ function extractDeniedActions(value) {
157
+ if (!Array.isArray(value))
158
+ return [];
159
+ const items = [];
160
+ for (const entry of value) {
161
+ if (typeof entry === "string" && entry.trim().length > 0) {
162
+ items.push(collapseWhitespace(entry).slice(0, MAX_DENIED_ACTION_ITEM_CHARS));
163
+ }
164
+ }
165
+ return items;
166
+ }
167
+ function formatDeniedActionsPreview(actions) {
168
+ const shown = actions.slice(0, MAX_DENIED_ACTION_PREVIEW_ITEMS).join(", ");
169
+ const remaining = actions.length - MAX_DENIED_ACTION_PREVIEW_ITEMS;
170
+ return remaining > 0 ? `${shown}; +${remaining} more in events.jsonl` : shown;
171
+ }
172
+ function formatCompletedDeniedNotice(actions) {
173
+ const preview = formatDeniedActionsPreview(actions);
174
+ return `[antigravity-cli permission notice] Denied actions during headless run: ${preview}. Inspect this run's events.jsonl / stderr.log, verify any skipped work, or re-run with a role that grants the required permissions.`;
175
+ }
176
+ function parametersObject(value) {
177
+ if (isPlainObject(value))
178
+ return value;
179
+ if (typeof value !== "string")
180
+ return undefined;
181
+ try {
182
+ const parsed = JSON.parse(value);
183
+ return isPlainObject(parsed) ? parsed : undefined;
184
+ }
185
+ catch {
186
+ return undefined;
187
+ }
188
+ }
189
+ function subjectFromToolParameters(params) {
190
+ for (const field of TOOL_SUBJECT_FIELDS) {
191
+ const value = params[field];
192
+ if (typeof value !== "string")
193
+ continue;
194
+ const raw = field === "CommandLine" || field === "command" ? (value.split(/\r?\n/)[0] ?? "") : value;
195
+ const collapsed = collapseWhitespace(raw);
196
+ if (collapsed)
197
+ return collapsed;
198
+ }
199
+ return undefined;
200
+ }
201
+ function formatProgressLabel(verb, subject) {
202
+ const text = collapseWhitespace(subject ? `${verb} ${subject}` : verb);
203
+ if (!text)
204
+ return undefined;
205
+ return text.slice(0, PROGRESS_LABEL_MAX_CHARS);
206
+ }
207
+ export const antigravityCliHarness = {
208
+ id: "antigravity-cli",
209
+ parserVersion: 1,
210
+ resumable: true,
211
+ requiresProtocolTerminal: true,
212
+ supportsImplicitVerifyThinking: true,
213
+ verifiesResumeSession: true,
214
+ roleWarnings(input) {
215
+ const tokens = splitShellWords(input.command);
216
+ const warnings = [];
217
+ if (tokens.some(hasPrintToken)) {
218
+ warnings.push(`${input.entryName}: -p, --print, and --prompt consume a string argument and block piped stdin in agy; omit them so headless delegation reads from stdin`);
219
+ }
220
+ if (tokens.some(hasInteractiveToken)) {
221
+ warnings.push(`${input.entryName}: -i and --prompt-interactive require a TTY and will fail or hang in a detached background delegation`);
222
+ }
223
+ if (tokens.some(hasConversationToken)) {
224
+ warnings.push(`${input.entryName}: -c, --continue, and --conversation pin or share session context across runs and conflict with follow_up --conversation <id>; session resumption is managed by Pipiclaw`);
225
+ }
226
+ const effectiveMode = resolveEffectiveMode(tokens);
227
+ const hasSkipPermissions = tokens.some((token) => token === "--dangerously-skip-permissions" || token.startsWith("--dangerously-skip-permissions="));
228
+ const hasWriteMode = effectiveMode === "accept-edits" || effectiveMode === "auto";
229
+ const hasAgentOrSettings = tokens.some((token) => token === "--agent" ||
230
+ token.startsWith("--agent=") ||
231
+ token === "--settings" ||
232
+ token.startsWith("--settings="));
233
+ const hasSandbox = tokens.some((token) => token === "--sandbox" || token.startsWith("--sandbox="));
234
+ if (input.mutates === "write" && effectiveMode === "plan") {
235
+ warnings.push(`${input.entryName}: --mode plan adds planning instructions and may divert implementation work; it does not enforce read-only execution and headless plan review may auto-approve`);
236
+ }
237
+ if (input.mutates === "write" && !hasSkipPermissions && !hasWriteMode && !hasAgentOrSettings) {
238
+ warnings.push(`${input.entryName}: command declares no explicit permission source (--dangerously-skip-permissions, --mode accept-edits/auto, --agent, or --settings); actions requiring review under default request-review mode are denied in headless runs unless allowed by host permission rules`);
239
+ }
240
+ if (input.mutates === "read" && (hasSkipPermissions || hasWriteMode)) {
241
+ warnings.push(`${input.entryName}: command includes --dangerously-skip-permissions or --mode accept-edits/auto, so the CLI can modify files and the workspace write lock will not stop it`);
242
+ }
243
+ else if (input.mutates === "read" && (effectiveMode === "plan" || hasSandbox)) {
244
+ warnings.push(`${input.entryName}: --mode plan and --sandbox alone do not guarantee read-only execution in agy; verify CLI permission rules and host boundaries or declare mutates: write`);
245
+ }
246
+ return warnings;
247
+ },
248
+ buildInvocation(input) {
249
+ if (input.argv.length === 0) {
250
+ throw new Error("antigravity-cli: command produced no argv tokens");
251
+ }
252
+ const [executable, ...rest] = input.argv;
253
+ const existing = detectExistingFlags(rest, { shortModelFlag: false, thinkingAlias: false });
254
+ const effort = input.thinkingLevel ? toAntigravityEffort(input.thinkingLevel) : undefined;
255
+ const { argv: expandedRest, used, dropped, } = expandPlaceholders(rest, {
256
+ $MODEL: input.model,
257
+ $EFFORT: effort,
258
+ $PROMPT_FILE: input.promptFile,
259
+ $SYSTEM_PROMPT_FILE: input.systemPromptFile,
260
+ });
261
+ const warnings = formatDroppedPlaceholderWarnings(dropped);
262
+ if (outputFormatConflicts(expandedRest)) {
263
+ warnings.push("Appended --output-format stream-json; the command already set a different output format, and settlement parses stream-json.");
264
+ }
265
+ if (expandedRest.some((token) => hasPrintToken(token) || hasInteractiveToken(token))) {
266
+ warnings.push("Command includes -p/--print/--prompt or -i/--prompt-interactive; in agy these flags consume a following argument, block piped stdin, or require an interactive terminal.");
267
+ }
268
+ if (expandedRest.some(hasConversationToken)) {
269
+ warnings.push("Command includes -c/--continue/--conversation; pinning or resuming a session in the role command can share state across runs and conflict with runtime follow_up resumption.");
270
+ }
271
+ const args = [...expandedRest, "--output-format", "stream-json"];
272
+ if (input.model && !existing.model && !used.has("$MODEL")) {
273
+ args.push("--model", input.model);
274
+ }
275
+ if (effort && !existing.effort && !used.has("$EFFORT")) {
276
+ args.push("--effort", effort);
277
+ }
278
+ if (input.resumeSessionId) {
279
+ args.push("--conversation", input.resumeSessionId);
280
+ }
281
+ return {
282
+ executable,
283
+ args,
284
+ resumable: true,
285
+ warnings: warnings.length > 0 ? warnings : undefined,
286
+ };
287
+ },
288
+ parseOutcome(input) {
289
+ let sessionId;
290
+ let terminalSeen = false;
291
+ let protocolStatus = "absent";
292
+ let errorMessage;
293
+ const expectedResumeId = input.expectedResumeSessionId?.trim() || undefined;
294
+ let matchedExpectedSession = false;
295
+ let mismatchedSessionId;
296
+ const stepTexts = new Map();
297
+ const stepUsages = new Map();
298
+ const userInputStepIndices = new Set();
299
+ let resultResponse;
300
+ let resultStructuredOutput;
301
+ let resultDeniedActions = [];
302
+ let resultUsage;
303
+ const recordParentConversationId = (value) => {
304
+ if (typeof value !== "string")
305
+ return;
306
+ const trimmed = value.trim();
307
+ if (!trimmed)
308
+ return;
309
+ sessionId = trimmed;
310
+ if (expectedResumeId) {
311
+ if (trimmed === expectedResumeId) {
312
+ matchedExpectedSession = true;
313
+ }
314
+ else {
315
+ mismatchedSessionId ??= trimmed;
316
+ }
317
+ }
318
+ };
319
+ const events = parseJsonObjectLines(input.eventsText);
320
+ const parsedAnyObject = events.length > 0;
321
+ for (const event of events) {
322
+ recordParentConversationId(event.conversation_id);
323
+ if (event.event === "step_update" && isPlainObject(event.step_update)) {
324
+ const step = event.step_update;
325
+ recordParentConversationId(step.conversation_id);
326
+ const stepIndex = typeof step.step_index === "number" && Number.isInteger(step.step_index) && step.step_index >= 0
327
+ ? step.step_index
328
+ : undefined;
329
+ if (stepIndex !== undefined) {
330
+ if (step.step_type === "user_input") {
331
+ userInputStepIndices.add(stepIndex);
332
+ }
333
+ if (step.step_type === "agent_response" &&
334
+ typeof step.text_delta === "string" &&
335
+ step.text_delta.length > 0) {
336
+ const prev = stepTexts.get(stepIndex) ?? "";
337
+ stepTexts.set(stepIndex, prev + step.text_delta);
338
+ }
339
+ const stepUsage = parseUsageSnapshot(step.usage);
340
+ if (stepUsage !== undefined) {
341
+ const existing = stepUsages.get(stepIndex);
342
+ if (!existing || isNonZeroUsage(stepUsage)) {
343
+ stepUsages.set(stepIndex, stepUsage);
344
+ }
345
+ }
346
+ }
347
+ }
348
+ if (event.event === "result" && isPlainObject(event.result)) {
349
+ const res = event.result;
350
+ terminalSeen = true;
351
+ recordParentConversationId(res.conversation_id);
352
+ const status = typeof res.status === "string" ? res.status.trim() : "";
353
+ const finishedReason = typeof res.finished_reason === "string" ? res.finished_reason.trim() : "";
354
+ const isSuccess = status === "SUCCESS" && !finishedReason;
355
+ protocolStatus = isSuccess ? "completed" : "failed";
356
+ resultResponse = typeof res.response === "string" ? res.response : undefined;
357
+ resultStructuredOutput = res.structured_output;
358
+ resultDeniedActions = extractDeniedActions(res.denied_actions);
359
+ resultUsage = parseUsageSnapshot(res.usage);
360
+ if (!isSuccess) {
361
+ const rawError = typeof res.error === "string" ? res.error.trim() : "";
362
+ let primaryError;
363
+ if (rawError) {
364
+ primaryError = rawError;
365
+ }
366
+ else if (finishedReason) {
367
+ primaryError = `antigravity-cli stopped: ${finishedReason}`;
368
+ }
369
+ else if (status) {
370
+ primaryError = `antigravity-cli reported status ${status}`;
371
+ }
372
+ else {
373
+ primaryError = "antigravity-cli reported an error";
374
+ }
375
+ if (resultDeniedActions.length > 0) {
376
+ primaryError = `${primaryError} (denied actions: ${formatDeniedActionsPreview(resultDeniedActions)})`;
377
+ }
378
+ errorMessage = primaryError;
379
+ }
380
+ else {
381
+ errorMessage = undefined;
382
+ }
383
+ }
384
+ }
385
+ if (!parsedAnyObject && input.eventsText.trim()) {
386
+ protocolStatus = "unparsable";
387
+ }
388
+ const orderedStepTexts = [...stepTexts.entries()]
389
+ .sort(([a], [b]) => a - b)
390
+ .map(([, text]) => text)
391
+ .filter((text) => text.length > 0);
392
+ const joinedStepsText = joinStepsWithBoundaries(orderedStepTexts);
393
+ let finalText;
394
+ if (!terminalSeen) {
395
+ finalText = joinedStepsText;
396
+ }
397
+ else if (typeof resultResponse === "string" && resultResponse.trim().length > 0) {
398
+ if (orderedStepTexts.length > 1 && orderedStepTexts.join("") === resultResponse) {
399
+ finalText = joinedStepsText;
400
+ }
401
+ else {
402
+ finalText = resultResponse;
403
+ }
404
+ }
405
+ else if (joinedStepsText.trim().length > 0) {
406
+ finalText = joinedStepsText;
407
+ }
408
+ else if (resultStructuredOutput !== undefined) {
409
+ finalText = JSON.stringify(resultStructuredOutput) ?? "";
410
+ }
411
+ else {
412
+ finalText = "";
413
+ }
414
+ if (terminalSeen && protocolStatus === "completed" && resultDeniedActions.length > 0) {
415
+ const notice = formatCompletedDeniedNotice(resultDeniedActions);
416
+ finalText = finalText ? `${notice}\n\n${finalText}` : notice;
417
+ }
418
+ // D8: verify resumed conversation identity against parent-session events.
419
+ if (expectedResumeId) {
420
+ if (mismatchedSessionId !== undefined) {
421
+ protocolStatus = "failed";
422
+ sessionId = undefined;
423
+ errorMessage = `antigravity-cli session mismatch: expected conversation "${expectedResumeId}" but CLI reported "${mismatchedSessionId}". Inspect events.jsonl/stderr.log and start a new delegation with full context.`;
424
+ }
425
+ else if (!matchedExpectedSession) {
426
+ sessionId = undefined;
427
+ if (parsedAnyObject || terminalSeen) {
428
+ protocolStatus = "failed";
429
+ const missingReason = `antigravity-cli session verification failed: expected conversation "${expectedResumeId}" was not confirmed in stream events. Inspect events.jsonl/stderr.log and start a new delegation with full context.`;
430
+ errorMessage = errorMessage ? `${errorMessage}; ${missingReason}` : missingReason;
431
+ }
432
+ }
433
+ }
434
+ const stderr = input.stderrTail?.trim();
435
+ if (!terminalSeen && !errorMessage && stderr) {
436
+ errorMessage = stderr;
437
+ }
438
+ // D5: resolve single-run token usage.
439
+ const summedSteps = stepUsages.size > 0 ? sumUsageSnapshots(stepUsages.values()) : undefined;
440
+ const hasNonZeroSteps = summedSteps !== undefined && isNonZeroUsage(summedSteps);
441
+ let chosenUsage;
442
+ if (expectedResumeId) {
443
+ // On `--conversation`, `result.usage` is cumulative across turns; only non-replayed step usage belongs to this run.
444
+ if (hasNonZeroSteps && userInputStepIndices.size <= 1) {
445
+ chosenUsage = summedSteps;
446
+ }
447
+ }
448
+ else if (resultUsage !== undefined && isNonZeroUsage(resultUsage)) {
449
+ chosenUsage = resultUsage;
450
+ }
451
+ else if (hasNonZeroSteps) {
452
+ chosenUsage = summedSteps;
453
+ }
454
+ const usage = chosenUsage
455
+ ? {
456
+ input: chosenUsage.input,
457
+ output: chosenUsage.output,
458
+ cacheRead: chosenUsage.cacheRead,
459
+ cacheWrite: chosenUsage.cacheWrite,
460
+ total: chosenUsage.total,
461
+ }
462
+ : undefined;
463
+ return {
464
+ finalText,
465
+ terminalSeen,
466
+ protocolStatus,
467
+ exitCode: input.exitCode,
468
+ sessionId,
469
+ usage,
470
+ usageKnown: chosenUsage !== undefined,
471
+ costKnown: false,
472
+ stderrTail: input.stderrTail,
473
+ errorMessage,
474
+ };
475
+ },
476
+ toProgressLabel(line) {
477
+ let event;
478
+ try {
479
+ event = JSON.parse(line.trim());
480
+ }
481
+ catch {
482
+ return undefined;
483
+ }
484
+ if (!isPlainObject(event) || event.event !== "step_update" || !isPlainObject(event.step_update)) {
485
+ return undefined;
486
+ }
487
+ const step = event.step_update;
488
+ if (step.state !== "ACTIVE")
489
+ return undefined;
490
+ if (isPlainObject(step.subagent_info) &&
491
+ Array.isArray(step.subagent_info.subagents) &&
492
+ step.subagent_info.subagents.length > 0) {
493
+ const first = step.subagent_info.subagents[0];
494
+ const subagentName = isPlainObject(first)
495
+ ? typeof first.role === "string" && first.role.trim()
496
+ ? first.role.trim()
497
+ : typeof first.type_name === "string" && first.type_name.trim()
498
+ ? first.type_name.trim()
499
+ : undefined
500
+ : undefined;
501
+ return formatProgressLabel("subagent", subagentName);
502
+ }
503
+ const toolInfo = isPlainObject(step.tool_info) ? step.tool_info : undefined;
504
+ const toolName = typeof toolInfo?.name === "string" && toolInfo.name.trim()
505
+ ? toolInfo.name.trim()
506
+ : typeof step.tool_name === "string" && step.tool_name.trim()
507
+ ? step.tool_name.trim()
508
+ : undefined;
509
+ if (step.step_type !== "tool" && !toolName)
510
+ return undefined;
511
+ if (!toolName)
512
+ return undefined;
513
+ const params = parametersObject(toolInfo?.parameters);
514
+ const subject = params ? subjectFromToolParameters(params) : undefined;
515
+ return formatProgressLabel(toolName, subject);
516
+ },
517
+ };
@@ -1,6 +1,6 @@
1
1
  import { randomUUID } from "node:crypto";
2
2
  import { isRecord } from "../../shared/type-guards.js";
3
- import { detectExistingFlags, expandPlaceholders, formatDroppedPlaceholderWarnings, } from "./harness.js";
3
+ import { detectExistingFlags, expandPlaceholders, formatDroppedPlaceholderWarnings, parseJsonObjectLines, } from "./harness.js";
4
4
  /**
5
5
  * `claude-code` harness (spec 040, D3/D4). Same one-prompt-one-process model as codex-cli; the
6
6
  * differences are argv shape and stdout schema.
@@ -36,6 +36,10 @@ export const claudeCodeHarness = {
36
36
  // `result` event never arrives (timeout/cancel kill the process before claude-code emits one) —
37
37
  // `op=show` can use this to distinguish "adapter is stale" from "the agent itself crashed".
38
38
  parserVersion: 2,
39
+ resumable: true,
40
+ requiresProtocolTerminal: true,
41
+ supportsImplicitVerifyThinking: true,
42
+ acceptsSystemPromptFlag: true,
39
43
  buildInvocation(input) {
40
44
  if (input.argv.length === 0) {
41
45
  throw new Error("claude-code: command produced no argv tokens");
@@ -87,28 +91,15 @@ export const claudeCodeHarness = {
87
91
  let usageKnown = false;
88
92
  let costKnown = false;
89
93
  let costTotal;
90
- let parsedAnyLine = false;
91
94
  // Fallback only: a run killed by timeout/cancel never gets a `result` event, so without this
92
95
  // a fully productive 90-minute run reports empty text and zero usage (D-review §1.2). Neither
93
96
  // of these ever sets `terminalSeen`/`protocolStatus` — only a real `result` event may do that;
94
97
  // streamed text is not proof the run finished.
95
98
  let lastAssistantText = "";
96
99
  let streamedUsage;
97
- for (const line of input.eventsText.split("\n")) {
98
- const trimmed = line.trim();
99
- if (!trimmed)
100
- continue;
101
- let event;
102
- try {
103
- event = JSON.parse(trimmed);
104
- }
105
- catch {
106
- continue; // Tolerate a torn or non-JSON line.
107
- }
108
- if (typeof event !== "object" || event === null)
109
- continue;
110
- parsedAnyLine = true;
111
- const record = event;
100
+ const records = parseJsonObjectLines(input.eventsText);
101
+ const parsedAnyLine = records.length > 0;
102
+ for (const record of records) {
112
103
  const sid = record.session_id;
113
104
  if (typeof sid === "string")
114
105
  sessionId = sid;
@@ -1,5 +1,5 @@
1
1
  import { isRecord } from "../../shared/type-guards.js";
2
- import { detectExistingFlags, expandPlaceholders, formatDroppedPlaceholderWarnings, } from "./harness.js";
2
+ import { detectExistingFlags, expandPlaceholders, formatDroppedPlaceholderWarnings, parseJsonObjectLines, } from "./harness.js";
3
3
  /**
4
4
  * `codex-cli` harness (spec 040, D3/D4). One prompt, one short-lived process, NDJSON on stdout
5
5
  * (`--json -`). Chosen as the first structured harness because its process model already matches
@@ -30,12 +30,15 @@ function toCodexEffort(level) {
30
30
  export const codexCliHarness = {
31
31
  id: "codex-cli",
32
32
  parserVersion: 1,
33
+ resumable: true,
34
+ requiresProtocolTerminal: true,
35
+ supportsImplicitVerifyThinking: true,
33
36
  buildInvocation(input) {
34
37
  if (input.argv.length === 0) {
35
38
  throw new Error("codex-cli: command produced no argv tokens");
36
39
  }
37
40
  const [executable, ...rest] = input.argv;
38
- const existing = detectExistingFlags(rest);
41
+ const existing = detectExistingFlags(rest, { codexConfigFlag: true });
39
42
  const effort = toCodexEffort(input.thinkingLevel);
40
43
  const { argv: expandedRest, used, dropped, } = expandPlaceholders(rest, {
41
44
  $MODEL: input.model,
@@ -70,22 +73,9 @@ export const codexCliHarness = {
70
73
  let errorMessage;
71
74
  let usage;
72
75
  let usageKnown = false;
73
- let parsedAnyLine = false;
74
- for (const line of input.eventsText.split("\n")) {
75
- const trimmed = line.trim();
76
- if (!trimmed)
77
- continue;
78
- let event;
79
- try {
80
- event = JSON.parse(trimmed);
81
- }
82
- catch {
83
- continue; // Tolerate a torn or non-JSON line; judged by what *did* parse.
84
- }
85
- if (typeof event !== "object" || event === null)
86
- continue;
87
- parsedAnyLine = true;
88
- const record = event;
76
+ const records = parseJsonObjectLines(input.eventsText);
77
+ const parsedAnyLine = records.length > 0;
78
+ for (const record of records) {
89
79
  const threadId = record.thread_id ?? record.thread?.id;
90
80
  if (typeof threadId === "string")
91
81
  sessionId = threadId;