@astrosheep/keiyaku 4.6.7 → 4.6.9

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 (336) hide show
  1. package/README.md +46 -16
  2. package/build/plugins/claude/.claude-plugin/plugin.json +1 -1
  3. package/build/plugins/claude/skills/keiyaku/SKILL.md +5 -6
  4. package/build/plugins/claude/skills/keiyaku-akuma/SKILL.md +1 -1
  5. package/build/plugins/claude/skills/keiyaku-akuma/references/automation.md +8 -8
  6. package/build/plugins/claude/skills/keiyaku-babysit/SKILL.md +1 -1
  7. package/build/plugins/claude/skills/keiyaku-bind/SKILL.md +9 -9
  8. package/build/plugins/claude/skills/keiyaku-debt/SKILL.md +91 -0
  9. package/build/plugins/claude/skills/keiyaku-workflow/SKILL.md +2 -2
  10. package/build/plugins/codex/.codex-plugin/plugin.json +1 -1
  11. package/build/plugins/codex/skills/keiyaku/SKILL.md +5 -6
  12. package/build/plugins/codex/skills/keiyaku-akuma/SKILL.md +1 -1
  13. package/build/plugins/codex/skills/keiyaku-akuma/references/automation.md +8 -8
  14. package/build/plugins/codex/skills/keiyaku-babysit/SKILL.md +1 -1
  15. package/build/plugins/codex/skills/keiyaku-bind/SKILL.md +9 -9
  16. package/build/plugins/codex/skills/keiyaku-debt/SKILL.md +91 -0
  17. package/build/plugins/codex/skills/keiyaku-workflow/SKILL.md +2 -2
  18. package/build/plugins/opencode/index.js +1 -1
  19. package/build/plugins/opencode/skills/keiyaku/SKILL.md +5 -6
  20. package/build/plugins/opencode/skills/keiyaku-akuma/SKILL.md +1 -1
  21. package/build/plugins/opencode/skills/keiyaku-akuma/references/automation.md +8 -8
  22. package/build/plugins/opencode/skills/keiyaku-babysit/SKILL.md +1 -1
  23. package/build/plugins/opencode/skills/keiyaku-bind/SKILL.md +9 -9
  24. package/build/plugins/opencode/skills/keiyaku-debt/SKILL.md +91 -0
  25. package/build/plugins/opencode/skills/keiyaku-workflow/SKILL.md +2 -2
  26. package/build/plugins/pi/keiyaku.ts +0 -5
  27. package/build/skills/keiyaku/SKILL.md +5 -6
  28. package/build/skills/keiyaku-akuma/SKILL.md +1 -1
  29. package/build/skills/keiyaku-akuma/references/automation.md +8 -8
  30. package/build/skills/keiyaku-babysit/SKILL.md +1 -1
  31. package/build/skills/keiyaku-bind/SKILL.md +9 -9
  32. package/build/skills/keiyaku-debt/SKILL.md +91 -0
  33. package/build/skills/keiyaku-workflow/SKILL.md +2 -2
  34. package/build/src/akuma/akuma-call.d.ts +2 -0
  35. package/build/src/akuma/akuma-call.js +8 -2
  36. package/build/src/akuma/akuma-instance.d.ts +14 -1
  37. package/build/src/akuma/akuma-instance.js +37 -7
  38. package/build/src/akuma/akuma-observe.d.ts +33 -8
  39. package/build/src/akuma/akuma-observe.js +89 -63
  40. package/build/src/akuma/akuma-owner.d.ts +14 -2
  41. package/build/src/akuma/akuma-owner.js +49 -35
  42. package/build/src/akuma/akuma-selection-execution.js +9 -1
  43. package/build/src/akuma/akuma-stream.d.ts +22 -0
  44. package/build/src/akuma/akuma-stream.js +116 -0
  45. package/build/src/akuma/akuma-wait.d.ts +1 -40
  46. package/build/src/akuma/akuma-wait.js +23 -84
  47. package/build/src/akuma/akuma.d.ts +52 -16
  48. package/build/src/akuma/akuma.js +10 -10
  49. package/build/src/akuma/allowed.d.ts +7 -12
  50. package/build/src/akuma/allowed.js +13 -4
  51. package/build/src/akuma/archetype.d.ts +7 -15
  52. package/build/src/akuma/archetype.js +36 -35
  53. package/build/src/akuma/body-supervisor.d.ts +5 -5
  54. package/build/src/akuma/body-supervisor.js +22 -20
  55. package/build/src/akuma/body.d.ts +5 -3
  56. package/build/src/akuma/body.js +57 -8
  57. package/build/src/akuma/call-request.d.ts +30 -32
  58. package/build/src/akuma/call-request.js +10 -3
  59. package/build/src/akuma/caller.d.ts +39 -0
  60. package/build/src/akuma/caller.js +36 -0
  61. package/build/src/akuma/dispatch-association.d.ts +0 -1
  62. package/build/src/akuma/dispatch-association.js +0 -3
  63. package/build/src/akuma/heart/activity-schema.d.ts +12 -0
  64. package/build/src/akuma/heart/activity-schema.js +6 -0
  65. package/build/src/akuma/heart/facts.d.ts +16 -12
  66. package/build/src/akuma/heart/facts.js +8 -0
  67. package/build/src/akuma/heart/index.d.ts +61 -9
  68. package/build/src/akuma/heart/index.js +89 -24
  69. package/build/src/akuma/heart/rows.d.ts +3 -3
  70. package/build/src/akuma/heart/rows.js +5 -3
  71. package/build/src/akuma/heart/soul.d.ts +10 -1
  72. package/build/src/akuma/heart/soul.js +34 -24
  73. package/build/src/akuma/heart/storage.d.ts +20 -0
  74. package/build/src/akuma/heart/storage.js +62 -3
  75. package/build/src/akuma/heart/timeline.d.ts +7 -0
  76. package/build/src/akuma/heart/timeline.js +10 -0
  77. package/build/src/akuma/identity.d.ts +0 -1
  78. package/build/src/akuma/identity.js +2 -5
  79. package/build/src/akuma/index.d.ts +6 -2
  80. package/build/src/akuma/index.js +1 -0
  81. package/build/src/akuma/nuke.js +6 -28
  82. package/build/src/akuma/projection.d.ts +25 -11
  83. package/build/src/akuma/projection.js +24 -7
  84. package/build/src/akuma/provider-recipe.d.ts +18 -6
  85. package/build/src/akuma/provider-recipe.js +24 -1
  86. package/build/src/akuma/provider.d.ts +31 -10
  87. package/build/src/akuma/provider.js +105 -14
  88. package/build/src/akuma/providers/acp/events.js +29 -19
  89. package/build/src/akuma/providers/acp/index.js +2 -3
  90. package/build/src/akuma/providers/claude/events.js +110 -69
  91. package/build/src/akuma/providers/claude/index.d.ts +2 -2
  92. package/build/src/akuma/providers/claude/index.js +4 -8
  93. package/build/src/akuma/providers/codex-app-server/events.js +17 -2
  94. package/build/src/akuma/providers/codex-app-server/index.js +17 -11
  95. package/build/src/akuma/providers/decode.d.ts +33 -0
  96. package/build/src/akuma/providers/decode.js +65 -0
  97. package/build/src/akuma/providers/execution-environment.d.ts +2 -1
  98. package/build/src/akuma/providers/execution-environment.js +3 -0
  99. package/build/src/akuma/providers/grok-build/index.js +16 -48
  100. package/build/src/akuma/providers/index.js +2 -0
  101. package/build/src/akuma/providers/lifecycle.d.ts +9 -0
  102. package/build/src/akuma/providers/lifecycle.js +10 -0
  103. package/build/src/akuma/providers/opencode-sdk/event-stream.d.ts +3 -3
  104. package/build/src/akuma/providers/opencode-sdk/event-stream.js +2 -25
  105. package/build/src/akuma/providers/opencode-sdk/events.d.ts +7 -43
  106. package/build/src/akuma/providers/opencode-sdk/events.js +146 -296
  107. package/build/src/akuma/providers/opencode-sdk/index.js +270 -431
  108. package/build/src/akuma/providers/opencode-sdk/native-http.d.ts +9 -0
  109. package/build/src/akuma/providers/opencode-sdk/native-http.js +69 -0
  110. package/build/src/akuma/providers/opencode-sdk/session.d.ts +42 -36
  111. package/build/src/akuma/providers/opencode-sdk/session.js +75 -84
  112. package/build/src/akuma/providers/paseo/events.d.ts +33 -0
  113. package/build/src/akuma/providers/paseo/events.js +204 -0
  114. package/build/src/akuma/providers/paseo/index.d.ts +9 -0
  115. package/build/src/akuma/providers/paseo/index.js +357 -0
  116. package/build/src/akuma/providers/pi/events.d.ts +2 -0
  117. package/build/src/akuma/providers/pi/events.js +36 -38
  118. package/build/src/akuma/providers/pi/index.js +21 -35
  119. package/build/src/akuma/publication.d.ts +2 -0
  120. package/build/src/akuma/publication.js +5 -0
  121. package/build/src/akuma/request-lifecycle.d.ts +4 -2
  122. package/build/src/akuma/request-lifecycle.js +27 -12
  123. package/build/src/akuma/request-rendezvous.js +38 -55
  124. package/build/src/akuma/request-serve.d.ts +1 -1
  125. package/build/src/akuma/request-serve.js +77 -113
  126. package/build/src/akuma/requests.d.ts +3 -1
  127. package/build/src/akuma/requests.js +32 -0
  128. package/build/src/akuma/selection-observation.d.ts +129 -53
  129. package/build/src/akuma/selection-observation.js +3 -9
  130. package/build/src/akuma/turn-drive.d.ts +3 -0
  131. package/build/src/akuma/turn-drive.js +28 -10
  132. package/build/src/akuma-body.js +12 -22
  133. package/build/src/cli/akuma-caller.d.ts +3 -0
  134. package/build/src/cli/akuma-caller.js +31 -0
  135. package/build/src/cli/commands/akuma-grammar.js +10 -16
  136. package/build/src/cli/commands/akuma.js +25 -55
  137. package/build/src/cli/commands/contract-grammar.d.ts +9 -7
  138. package/build/src/cli/commands/contract-grammar.js +40 -47
  139. package/build/src/cli/commands/contract-help.d.ts +17 -7
  140. package/build/src/cli/commands/contract-help.js +50 -11
  141. package/build/src/cli/commands/contract.js +34 -63
  142. package/build/src/cli/commands/debt-grammar.d.ts +19 -0
  143. package/build/src/cli/commands/debt-grammar.js +323 -0
  144. package/build/src/cli/commands/debt-query.d.ts +5 -0
  145. package/build/src/cli/commands/{task-query.js → debt-query.js} +9 -9
  146. package/build/src/cli/commands/{task.d.ts → debt.d.ts} +2 -2
  147. package/build/src/cli/commands/{task.js → debt.js} +87 -164
  148. package/build/src/cli/coordinates.d.ts +1 -1
  149. package/build/src/cli/coordinates.js +1 -1
  150. package/build/src/cli/parse.d.ts +5 -5
  151. package/build/src/cli/parse.js +17 -16
  152. package/build/src/cli/render/akuma-activity.d.ts +11 -83
  153. package/build/src/cli/render/akuma-activity.js +20 -382
  154. package/build/src/cli/render/catalog.d.ts +4 -7
  155. package/build/src/cli/render/catalog.js +5 -5
  156. package/build/src/cli/render/contract-history.js +3 -6
  157. package/build/src/cli/render/contract.js +17 -52
  158. package/build/src/cli/render/debt.d.ts +28 -0
  159. package/build/src/cli/render/{task.js → debt.js} +55 -133
  160. package/build/src/cli/render/kanshi.js +28 -28
  161. package/build/src/cli/render/marks.d.ts +5 -5
  162. package/build/src/cli/render/marks.js +4 -10
  163. package/build/src/cli/render/nuke.js +1 -1
  164. package/build/src/cli/render/receipt.js +3 -10
  165. package/build/src/cli/runtime.d.ts +1 -1
  166. package/build/src/cli/runtime.js +14 -20
  167. package/build/src/cli/scan.d.ts +1 -1
  168. package/build/src/cli/selectors.d.ts +3 -6
  169. package/build/src/cli/selectors.js +22 -53
  170. package/build/src/cli/usage.d.ts +1 -1
  171. package/build/src/cli/usage.js +4 -4
  172. package/build/src/contract-worktree.js +3 -3
  173. package/build/src/debt/board.d.ts +160 -0
  174. package/build/src/{task → debt}/board.js +89 -89
  175. package/build/src/debt/catalog.d.ts +11 -0
  176. package/build/src/debt/catalog.js +59 -0
  177. package/build/src/{task → debt}/context.d.ts +1 -1
  178. package/build/src/{task → debt}/context.js +1 -1
  179. package/build/src/{task → debt}/created-observation.d.ts +6 -10
  180. package/build/src/{task → debt}/created-observation.js +7 -7
  181. package/build/src/debt/document.d.ts +37 -0
  182. package/build/src/{task → debt}/document.js +37 -37
  183. package/build/src/debt/identity.d.ts +21 -0
  184. package/build/src/{task → debt}/identity.js +35 -35
  185. package/build/src/debt/index.d.ts +111 -0
  186. package/build/src/debt/index.js +203 -0
  187. package/build/src/{task → debt}/input.d.ts +8 -8
  188. package/build/src/{task → debt}/input.js +21 -21
  189. package/build/src/debt/lifecycle-operations.d.ts +6 -0
  190. package/build/src/{task → debt}/lifecycle-operations.js +27 -31
  191. package/build/src/debt/mutation-result.d.ts +981 -0
  192. package/build/src/debt/mutation-result.js +109 -0
  193. package/build/src/debt/mutation.d.ts +424 -0
  194. package/build/src/debt/mutation.js +223 -0
  195. package/build/src/debt/operation-types.d.ts +71 -0
  196. package/build/src/debt/operations.d.ts +28 -0
  197. package/build/src/{task → debt}/operations.js +59 -60
  198. package/build/src/debt/query.d.ts +76 -0
  199. package/build/src/{task → debt}/query.js +55 -55
  200. package/build/src/{task → debt}/store.d.ts +13 -13
  201. package/build/src/{task → debt}/store.js +58 -49
  202. package/build/src/debt/view.d.ts +4 -0
  203. package/build/src/debt/view.js +7 -0
  204. package/build/src/dispatch/index.d.ts +3 -3
  205. package/build/src/dispatch/index.js +1 -2
  206. package/build/src/git/observe.d.ts +6 -2
  207. package/build/src/git/observe.js +6 -2
  208. package/build/src/identity/coordinates.d.ts +1 -1
  209. package/build/src/index.d.ts +17 -17
  210. package/build/src/index.js +11 -11
  211. package/build/src/kanshi/index.d.ts +2 -2
  212. package/build/src/kanshi/read.js +54 -39
  213. package/build/src/kanshi/report.d.ts +7 -7
  214. package/build/src/kanshi/select.js +4 -4
  215. package/build/src/library/address.js +2 -4
  216. package/build/src/library/akuma-creation.d.ts +5 -1
  217. package/build/src/library/akuma-creation.js +27 -47
  218. package/build/src/library/akumas.d.ts +7 -7
  219. package/build/src/library/akumas.js +13 -9
  220. package/build/src/library/bind.d.ts +17 -17
  221. package/build/src/library/bind.js +16 -12
  222. package/build/src/library/contract-address.d.ts +9 -0
  223. package/build/src/library/contract-address.js +71 -0
  224. package/build/src/library/contract-composition.d.ts +4 -7
  225. package/build/src/library/contract-composition.js +6 -18
  226. package/build/src/library/contract-creation.d.ts +3 -5
  227. package/build/src/library/contract-creation.js +24 -22
  228. package/build/src/library/contract-execution.js +21 -26
  229. package/build/src/library/contract-outcomes.d.ts +2 -14
  230. package/build/src/library/contract-outcomes.js +2 -13
  231. package/build/src/library/contract-types.d.ts +38 -4
  232. package/build/src/library/delivery.d.ts +0 -2
  233. package/build/src/library/delivery.js +2 -5
  234. package/build/src/library/input.d.ts +2 -2
  235. package/build/src/library/input.js +5 -5
  236. package/build/src/library/invocation.js +2 -2
  237. package/build/src/library/keiyaku.d.ts +0 -5
  238. package/build/src/library/keiyaku.js +6 -12
  239. package/build/src/library/nuke.js +3 -3
  240. package/build/src/library/outcome.d.ts +626 -625
  241. package/build/src/library/outcome.js +13 -3
  242. package/build/src/library/reconcile.js +8 -16
  243. package/build/src/library/refusal.d.ts +2 -2
  244. package/build/src/library/repo.d.ts +3 -2
  245. package/build/src/library/repo.js +10 -5
  246. package/build/src/library/selection.d.ts +5 -8
  247. package/build/src/library/selection.js +22 -73
  248. package/build/src/plugin/akuma-signals.d.ts +2 -0
  249. package/build/src/plugin/akuma-signals.js +4 -0
  250. package/build/src/plugin/public.d.ts +32 -2
  251. package/build/src/plugin/runtime.js +5 -3
  252. package/build/src/protocol/amend.js +3 -2
  253. package/build/src/protocol/attempt.js +3 -8
  254. package/build/src/protocol/bind.d.ts +2 -2
  255. package/build/src/protocol/bind.js +1 -1
  256. package/build/src/protocol/deliver.js +3 -3
  257. package/build/src/protocol/operations.d.ts +1 -3
  258. package/build/src/protocol/operations.js +0 -8
  259. package/build/src/protocol/outcome.d.ts +1 -2
  260. package/build/src/protocol/outcome.js +1 -13
  261. package/build/src/protocol/placement.js +3 -10
  262. package/build/src/protocol/read/status.js +31 -70
  263. package/build/src/protocol/reintegrate.js +3 -10
  264. package/build/src/protocol/review.js +3 -3
  265. package/build/src/protocol/run.d.ts +5 -1
  266. package/build/src/protocol/run.js +3 -3
  267. package/build/src/runtime/proc/windows-launch.exe +0 -0
  268. package/build/src/settlement/fence.d.ts +3 -3
  269. package/build/src/settlement/fence.js +4 -4
  270. package/build/src/settlement/holder.d.ts +16 -16
  271. package/build/src/settlement/holder.js +69 -63
  272. package/build/src/settlement/settle.d.ts +5 -5
  273. package/build/src/settlement/settle.js +53 -53
  274. package/package.json +19 -9
  275. package/plugins/paseo/plugin/index.server.ts +17 -0
  276. package/plugins/paseo/plugin/paseo-plugin.json +4 -0
  277. package/plugins/paseo/plugin/server/attach.ts +52 -0
  278. package/plugins/paseo/plugin/server/keiyaku.ts +44 -0
  279. package/plugins/paseo/plugin/server/message.ts +60 -0
  280. package/plugins/paseo/plugin/server/mirror.ts +193 -0
  281. package/plugins/paseo/plugin/server/model.ts +14 -0
  282. package/plugins/paseo/plugin/server/provider.ts +276 -0
  283. package/plugins/paseo/plugin/server/sdk-worker.ts +237 -0
  284. package/plugins/paseo/plugin/server/sdk.ts +289 -0
  285. package/plugins/paseo/plugin/server/stop.ts +26 -0
  286. package/plugins/paseo/plugin/server/transport.ts +35 -0
  287. package/plugins/paseo/plugin/shared/attach-rpc.ts +10 -0
  288. package/plugins/paseo/plugin/shared/refresh-rpc.ts +6 -0
  289. package/plugins/paseo/plugin/tsconfig.json +6 -0
  290. package/plugins/pi/keiyaku.ts +57 -0
  291. package/skills/keiyaku/SKILL.md +43 -0
  292. package/skills/keiyaku-akuma/SKILL.md +130 -0
  293. package/skills/keiyaku-akuma/references/automation.md +269 -0
  294. package/skills/keiyaku-babysit/SKILL.md +65 -0
  295. package/skills/keiyaku-bind/SKILL.md +216 -0
  296. package/skills/keiyaku-bind/agents/openai.yaml +4 -0
  297. package/skills/keiyaku-debt/SKILL.md +91 -0
  298. package/skills/keiyaku-workflow/SKILL.md +129 -0
  299. package/build/plugins/claude/skills/keiyaku-task/SKILL.md +0 -104
  300. package/build/plugins/codex/skills/keiyaku-task/SKILL.md +0 -104
  301. package/build/plugins/opencode/skills/keiyaku-task/SKILL.md +0 -104
  302. package/build/skills/keiyaku-task/SKILL.md +0 -104
  303. package/build/src/cli/commands/amend.d.ts +0 -12
  304. package/build/src/cli/commands/amend.js +0 -10
  305. package/build/src/cli/commands/bind.d.ts +0 -11
  306. package/build/src/cli/commands/bind.js +0 -23
  307. package/build/src/cli/commands/task-grammar.d.ts +0 -19
  308. package/build/src/cli/commands/task-grammar.js +0 -384
  309. package/build/src/cli/commands/task-query.d.ts +0 -5
  310. package/build/src/cli/render/task.d.ts +0 -41
  311. package/build/src/dispatch/association.d.ts +0 -1
  312. package/build/src/dispatch/association.js +0 -1
  313. package/build/src/task/board.d.ts +0 -168
  314. package/build/src/task/catalog.d.ts +0 -11
  315. package/build/src/task/catalog.js +0 -59
  316. package/build/src/task/compose-language.d.ts +0 -57
  317. package/build/src/task/compose-language.js +0 -364
  318. package/build/src/task/compose-parser.d.ts +0 -32
  319. package/build/src/task/compose-parser.js +0 -180
  320. package/build/src/task/compose.d.ts +0 -16
  321. package/build/src/task/compose.js +0 -189
  322. package/build/src/task/document.d.ts +0 -39
  323. package/build/src/task/identity.d.ts +0 -21
  324. package/build/src/task/index.d.ts +0 -138
  325. package/build/src/task/index.js +0 -269
  326. package/build/src/task/lifecycle-operations.d.ts +0 -6
  327. package/build/src/task/mutation-result.d.ts +0 -1726
  328. package/build/src/task/mutation-result.js +0 -198
  329. package/build/src/task/mutation.d.ts +0 -590
  330. package/build/src/task/mutation.js +0 -262
  331. package/build/src/task/operation-types.d.ts +0 -71
  332. package/build/src/task/operations.d.ts +0 -28
  333. package/build/src/task/query.d.ts +0 -76
  334. package/build/src/task/view.d.ts +0 -4
  335. package/build/src/task/view.js +0 -7
  336. /package/build/src/{task → debt}/operation-types.js +0 -0
@@ -1,322 +1,172 @@
1
- import { noteEvent, otherToolCall } from "../../provider.js";
2
- export const OPENCODE_EVENT_DISPOSITIONS = {
3
- "server.instance.disposed": "dropped",
4
- "installation.updated": "dropped",
5
- "installation.update-available": "dropped",
6
- "lsp.client.diagnostics": "dropped",
7
- "lsp.updated": "dropped",
8
- "message.updated": "mapped",
9
- "message.removed": "dropped",
10
- "message.part.updated": "mapped",
11
- "message.part.removed": "dropped",
12
- "permission.updated": "dropped",
13
- "permission.replied": "dropped",
14
- "session.status": "dropped",
15
- "session.idle": "dropped",
16
- "session.compacted": "note",
17
- "file.edited": "dropped",
18
- "todo.updated": "mapped",
19
- "command.executed": "dropped",
20
- "session.created": "dropped",
21
- "session.updated": "dropped",
22
- "session.deleted": "dropped",
23
- "session.diff": "dropped",
24
- "session.error": "mapped",
25
- "file.watcher.updated": "dropped",
26
- "vcs.branch.updated": "dropped",
27
- "tui.prompt.append": "dropped",
28
- "tui.command.execute": "dropped",
29
- "tui.toast.show": "dropped",
30
- "pty.created": "dropped",
31
- "pty.updated": "dropped",
32
- "pty.exited": "dropped",
33
- "pty.deleted": "dropped",
34
- "server.connected": "dropped",
35
- };
36
- // OpenCode may emit these server-side metadata events before the generated
37
- // SDK union catches up. They are all non-narrative and therefore remain drop
38
- // dispositions; genuinely new execution events still use the unknown arm.
39
- const RUNTIME_DROPPED_EVENT_KINDS = new Set([
40
- "plugin.added",
41
- "catalog.updated",
42
- "reference.updated",
43
- "integration.updated",
44
- "server.heartbeat",
45
- "message.part.delta",
46
- ]);
47
- function object(value) {
48
- return value !== null && typeof value === "object" && !Array.isArray(value)
49
- ? value
50
- : undefined;
51
- }
52
- function text(value) {
53
- return typeof value === "string" && value.length > 0 ? value : undefined;
54
- }
55
- function diagnostic(value) {
1
+ import { modelEvent, noteEvent, otherToolCall, } from "../../provider.js";
2
+ import { nonnegativeCount, object, positiveLine, stringValue, text } from "../decode.js";
3
+ export function diagnostic(value) {
56
4
  const data = object(value);
57
- const nested = object(data?.data);
58
- return text(nested?.message) ?? text(data?.message) ?? "OpenCode session failed";
5
+ return text(data?.message) ?? text(object(data?.data)?.message) ?? "OpenCode execution failed";
59
6
  }
60
- function positiveLine(value) {
61
- return typeof value === "number" && Number.isSafeInteger(value) && value >= 1 ? value : undefined;
62
- }
63
- function nonnegativeCount(value) {
64
- return typeof value === "number" && Number.isSafeInteger(value) && value >= 0 ? value : undefined;
7
+ function callFor(name, input) {
8
+ const value = object(input);
9
+ if (name === "shell")
10
+ return { kind: "run", command: text(value?.command) ?? name };
11
+ if (name === "read") {
12
+ const path = text(value?.filePath) ?? text(value?.path);
13
+ if (path !== undefined)
14
+ return {
15
+ kind: "read",
16
+ path,
17
+ ...(positiveLine(value?.offset) === undefined ? {} : { offset: positiveLine(value?.offset) }),
18
+ ...(positiveLine(value?.limit) === undefined ? {} : { limit: positiveLine(value?.limit) }),
19
+ };
20
+ }
21
+ if (name === "grep" || name === "glob") {
22
+ const query = text(value?.pattern);
23
+ const path = text(value?.path);
24
+ if (query !== undefined)
25
+ return {
26
+ kind: "search",
27
+ scope: name === "glob" ? "files" : "content",
28
+ query,
29
+ ...(path === undefined ? {} : { path }),
30
+ };
31
+ }
32
+ if (name === "edit") {
33
+ const path = text(value?.path);
34
+ if (path !== undefined)
35
+ return { kind: "fileChange", changes: [{ op: "update", path }] };
36
+ }
37
+ return otherToolCall(name, input);
65
38
  }
66
- function diffstat(value) {
67
- if (value === undefined)
39
+ function observedChanges(metadata) {
40
+ const files = object(metadata)?.files;
41
+ if (!Array.isArray(files))
68
42
  return undefined;
69
- const added = nonnegativeCount(value.additions);
70
- const removed = nonnegativeCount(value.deletions);
71
- return added === undefined || removed === undefined ? undefined : { added, removed };
72
- }
73
- function fileChange(changes) {
43
+ const changes = files.flatMap((item) => {
44
+ const file = object(item);
45
+ const path = text(file?.file);
46
+ const status = file?.status;
47
+ if (path === undefined || (status !== "added" && status !== "deleted" && status !== "modified"))
48
+ return [];
49
+ const added = nonnegativeCount(file?.additions);
50
+ const removed = nonnegativeCount(file?.deletions);
51
+ const patch = stringValue(file?.patch);
52
+ return [
53
+ {
54
+ op: status === "added" ? "add" : status === "deleted" ? "delete" : "update",
55
+ path,
56
+ ...(added === undefined || removed === undefined ? {} : { diffstat: { added, removed } }),
57
+ ...(patch === undefined ? {} : { patch }),
58
+ },
59
+ ];
60
+ });
74
61
  return changes.length === 0 ? undefined : { kind: "fileChange", changes };
75
62
  }
76
- function change(op, path, stats) {
77
- return stats === undefined ? { op, path } : { op, path, diffstat: stats };
78
- }
79
- function editCall(input, metadata) {
80
- const path = text(input?.filePath);
81
- if (path === undefined)
82
- return undefined;
83
- return fileChange([change("update", path, diffstat(object(metadata?.filediff)))]);
84
- }
85
- function writeCall(input, metadata) {
86
- const path = text(metadata?.filepath) ?? text(input?.filePath);
87
- const op = metadata?.exists === false ? "add" : metadata?.exists === true ? "update" : undefined;
88
- return path === undefined || op === undefined ? undefined : fileChange([change(op, path, undefined)]);
89
- }
90
- function applyPatchFile(value) {
91
- const file = object(value);
92
- if (file === undefined)
93
- return undefined;
94
- const type = file.type;
95
- const op = type === "add"
96
- ? "add"
97
- : type === "delete"
98
- ? "delete"
99
- : type === "update" || type === "modify" || type === "move"
100
- ? "update"
101
- : undefined;
102
- const path = type === "move" ? text(file.movePath) : text(file.filePath);
103
- return op === undefined || path === undefined ? undefined : change(op, path, diffstat(file));
104
- }
105
- function applyPatchCall(metadata) {
106
- if (!Array.isArray(metadata?.files))
107
- return undefined;
108
- return fileChange(metadata.files.flatMap((value) => {
109
- const next = applyPatchFile(value);
110
- return next === undefined ? [] : [next];
111
- }));
112
- }
113
- function strongerCall(previous, next) {
114
- if (next === undefined)
115
- return previous;
116
- if (previous?.kind === "fileChange" && next.kind !== "fileChange")
117
- return previous;
118
- // The correlated start's admitted preview is authority: a later update never
119
- // overwrites it, empty or conflicting, while a start without one adopts supplied evidence.
120
- if (next.kind === "other" && previous?.kind === "other" && previous.input !== undefined)
121
- return { ...next, input: previous.input };
122
- return next;
123
- }
124
- function runCall(name, value) {
125
- return name === "bash" || name === "shell" ? { kind: "run", command: text(value?.command) ?? name } : undefined;
126
- }
127
- function readCall(name, value) {
128
- if (name !== "read")
129
- return undefined;
130
- const path = text(value?.filePath) ?? text(value?.path);
131
- if (path === undefined)
63
+ function output(content) {
64
+ if (!Array.isArray(content))
132
65
  return undefined;
133
- const offset = positiveLine(value?.offset);
134
- const limit = positiveLine(value?.limit);
135
- return {
136
- kind: "read",
137
- path,
138
- ...(offset === undefined ? {} : { offset }),
139
- ...(limit === undefined ? {} : { limit }),
140
- };
141
- }
142
- function searchCall(name, value) {
143
- if (name !== "grep" && name !== "glob" && name !== "search")
144
- return undefined;
145
- const query = text(value?.pattern) ?? text(value?.query);
146
- if (query === undefined)
147
- return undefined;
148
- const path = text(value?.path) ?? text(value?.filePath);
149
- const glob = text(value?.glob);
150
- const scope = name === "glob" ? "files" : "content";
151
- return {
152
- kind: "search",
153
- query,
154
- scope,
155
- ...(path === undefined ? {} : { path }),
156
- ...(scope === "content" && glob !== undefined ? { glob } : {}),
157
- };
158
- }
159
- function callFor(name, input, metadata) {
160
- const value = object(input);
161
- const meta = object(metadata);
162
- const lower = name.toLowerCase();
163
- if (lower === "bash" || lower === "shell")
164
- return runCall(lower, value);
165
- if (lower === "read")
166
- return readCall(lower, value);
167
- if (lower === "grep" || lower === "glob" || lower === "search")
168
- return searchCall(lower, value);
169
- if (lower === "edit")
170
- return editCall(value, meta) ?? otherToolCall(name, input);
171
- if (lower === "write")
172
- return writeCall(value, meta) ?? otherToolCall(name, input);
173
- if (lower === "apply_patch")
174
- return applyPatchCall(meta) ?? otherToolCall(name, input);
175
- return otherToolCall(name, input);
176
- }
177
- function belongs(part, state) {
178
- return state.sessionId === undefined || part.sessionID === state.sessionId;
179
- }
180
- function mapTextPart(part, events, state, thought) {
181
- const id = text(part.id);
182
- const time = object(part.time);
183
- const content = text(part.text);
184
- const seen = thought ? state.reasoningParts : state.assistantParts;
185
- if (!belongs(part, state) || id === undefined || content === undefined || time?.end === undefined || seen.has(id))
186
- return;
187
- seen.add(id);
188
- if (thought)
189
- events.emit({ type: "thought", text: content });
190
- else
191
- events.emit({ type: "assistant", text: content });
192
- }
193
- function resultFor(state, failed) {
194
- const exit = object(state.metadata)?.exit;
195
- const exitCode = typeof exit === "number" && Number.isInteger(exit) ? exit : undefined;
196
- if (failed) {
197
- return {
198
- status: "error",
199
- message: text(state.error) ?? "OpenCode tool failed",
200
- ...(exitCode === undefined ? {} : { exitCode }),
201
- };
202
- }
203
- return {
204
- status: exitCode !== undefined && exitCode !== 0 ? "error" : "ok",
205
- ...(exitCode === undefined ? {} : { exitCode }),
206
- };
66
+ const parts = content.flatMap((part) => {
67
+ const value = object(part);
68
+ const text = value?.type === "text" ? stringValue(value.text) : undefined;
69
+ return text === undefined ? [] : [text];
70
+ });
71
+ return parts.length === 0 ? undefined : parts.join("\n\n");
207
72
  }
208
- function mapToolPart(part, events, state) {
209
- if (!belongs(part, state))
73
+ const DROPPED = new Set([
74
+ "server.connected",
75
+ "server.heartbeat",
76
+ "session.created",
77
+ "session.forked",
78
+ "session.deleted",
79
+ "session.inbox.enqueued",
80
+ "session.inbox.delivered",
81
+ "session.inbox.cancelled",
82
+ "session.inbox.delivery.changed",
83
+ "session.execution.started",
84
+ "session.execution.succeeded",
85
+ "session.execution.failed",
86
+ "session.execution.interrupted",
87
+ "session.model.selected",
88
+ "session.agent.selected",
89
+ "session.instructions.updated",
90
+ "session.permissions",
91
+ "session.step.streamed",
92
+ "session.step.ended",
93
+ "session.usage.updated",
94
+ "session.usage.recorded",
95
+ "session.text.started",
96
+ "session.text.delta",
97
+ "session.reasoning.started",
98
+ "session.reasoning.delta",
99
+ "session.tool.input.delta",
100
+ "session.tool.input.ended",
101
+ "session.tool.progress",
102
+ "session.retry.scheduled",
103
+ ]);
104
+ /** Only complete native values enter narration. The caller enforces submission/step correlation. */
105
+ export function mapEvent(value, events, state) {
106
+ const event = object(value);
107
+ if (event === undefined || typeof event.type !== "string")
210
108
  return;
211
- const id = text(part.callID);
212
- const name = text(part.tool);
213
- const toolState = object(part.state);
214
- if (id === undefined || name === undefined || toolState === undefined)
109
+ const data = object(event.data) ?? {};
110
+ if (state.sessionId !== undefined && data.sessionID !== state.sessionId)
215
111
  return;
216
- const next = callFor(name, toolState.input, toolState.metadata);
217
- if ((toolState.status === "pending" || toolState.status === "running") &&
218
- !state.tools.has(id) &&
219
- !state.completedTools.has(id)) {
220
- if (next === undefined)
221
- return;
222
- const observed = { name, call: next };
223
- state.tools.set(id, observed);
224
- events.emit({ type: "tool", phase: "started", id, ...observed });
112
+ const type = event.type;
113
+ if (type === "session.step.started") {
114
+ const model = object(data.model);
115
+ const provider = text(model?.providerID);
116
+ const id = text(model?.id);
117
+ if (provider !== undefined && id !== undefined)
118
+ events.emit(modelEvent(`${provider}/${id}`));
225
119
  return;
226
120
  }
227
- if ((toolState.status !== "completed" && toolState.status !== "error") || state.completedTools.has(id))
228
- return;
229
- const started = state.tools.get(id);
230
- const call = strongerCall(started?.call, next);
231
- if (call === undefined)
121
+ if (type === "session.text.ended" || type === "session.reasoning.ended") {
122
+ if (typeof data.text === "string")
123
+ events.emit({ type: type === "session.text.ended" ? "assistant" : "thought", text: data.text });
232
124
  return;
233
- const observed = { name: started?.name ?? name, call };
234
- if (!state.tools.has(id)) {
235
- state.tools.set(id, observed);
236
- events.emit({ type: "tool", phase: "started", id, ...observed });
237
125
  }
238
- else {
239
- state.tools.set(id, observed);
240
- }
241
- state.completedTools.add(id);
242
- events.emit({
243
- type: "tool",
244
- phase: "completed",
245
- id,
246
- ...observed,
247
- result: resultFor(toolState, toolState.status === "error"),
248
- });
249
- }
250
- function mapPart(part, events, state) {
251
- if (part.type === "text")
252
- return mapTextPart(part, events, state, false);
253
- if (part.type === "reasoning")
254
- return mapTextPart(part, events, state, true);
255
- if (part.type === "tool")
256
- mapToolPart(part, events, state);
257
- }
258
- function mapSessionError(properties, events, state) {
259
- if (state.sessionId !== undefined && properties.sessionID !== state.sessionId)
260
- return;
261
- state.failure = diagnostic(properties.error);
262
- events.emit(noteEvent(state.failure));
263
- }
264
- function mapTodo(properties, events, state) {
265
- if (properties.sessionID !== state.sessionId || !Array.isArray(properties.todos))
266
- return;
267
- const summary = properties.todos
268
- .flatMap((value) => {
269
- const todo = object(value);
270
- const content = text(todo?.content);
271
- return content === undefined ? [] : [`${text(todo?.status) ?? "todo"}: ${content}`];
272
- })
273
- .join("; ");
274
- if (summary.length > 0)
275
- events.emit(noteEvent(summary));
276
- }
277
- function ignoredEvent(type) {
278
- return (typeof type === "string" &&
279
- (OPENCODE_EVENT_DISPOSITIONS[type] === "dropped" || RUNTIME_DROPPED_EVENT_KINDS.has(type)));
280
- }
281
- export function mapEvent(value, events, state) {
282
- const event = object(value);
283
- if (event === undefined)
284
- return;
285
- const properties = object(event.properties) ?? {};
286
- if (event.type === "message.part.updated") {
287
- const part = object(properties.part);
288
- if (part !== undefined)
289
- mapPart(part, events, state);
126
+ if (type === "session.tool.input.started") {
127
+ if (typeof data.id === "string" && typeof data.name === "string")
128
+ state.tools.set(data.id, { name: data.name });
290
129
  return;
291
130
  }
292
- if (event.type === "message.updated") {
293
- const info = object(properties.info);
294
- if (info !== undefined &&
295
- info.sessionID === state.sessionId &&
296
- info.role === "assistant" &&
297
- info.error !== undefined) {
298
- state.failure = diagnostic(info.error);
131
+ if (type === "session.tool.called" || type === "session.tool.success" || type === "session.tool.failed") {
132
+ const id = text(data.id);
133
+ const started = id === undefined ? undefined : state.tools.get(id);
134
+ if (id === undefined || started === undefined || state.completed.has(id))
135
+ return;
136
+ if (started.call === undefined) {
137
+ started.call = callFor(started.name, data.input);
138
+ events.emit({ type: "tool", phase: "started", id, name: started.name, call: started.call });
139
+ }
140
+ if (type === "session.tool.called")
141
+ return;
142
+ if (started.name === "edit" || started.name === "patch" || started.name === "write") {
143
+ started.call = observedChanges(data.metadata) ?? started.call;
299
144
  }
145
+ const observed = output(data.content);
146
+ const nativeExit = object(data.metadata)?.exit;
147
+ const exit = typeof nativeExit === "number" && Number.isInteger(nativeExit) ? nativeExit : undefined;
148
+ const result = {
149
+ status: type === "session.tool.failed" || (exit !== undefined && exit !== 0) ? "error" : "ok",
150
+ ...(type === "session.tool.failed" ? { message: diagnostic(data.error) } : {}),
151
+ ...(observed === undefined ? {} : { output: observed }),
152
+ ...(exit === undefined ? {} : { exitCode: exit }),
153
+ };
154
+ state.completed.add(id);
155
+ events.emit({ type: "tool", phase: "completed", id, name: started.name, call: started.call, result });
300
156
  return;
301
157
  }
302
- if (event.type === "session.error")
303
- return mapSessionError(properties, events, state);
304
- if (event.type === "session.compacted") {
158
+ if (type === "session.compaction.ended") {
305
159
  events.emit(noteEvent("Context compacted"));
306
160
  return;
307
161
  }
308
- if (event.type === "todo.updated")
309
- return mapTodo(properties, events, state);
310
- if (ignoredEvent(event.type))
162
+ if (type === "session.compaction.failed") {
163
+ events.emit(noteEvent(diagnostic(data.error)));
164
+ return;
165
+ }
166
+ if (type === "session.compaction.started" || type === "session.compaction.delta" || DROPPED.has(type))
311
167
  return;
312
- events.emit({ type: "unknown", kind: typeof event.type === "string" ? event.type : "unknown" });
168
+ events.emit({ type: "unknown", kind: type });
313
169
  }
314
170
  export function createEventState(sessionId) {
315
- return {
316
- ...(sessionId === undefined ? {} : { sessionId }),
317
- assistantParts: new Set(),
318
- reasoningParts: new Set(),
319
- tools: new Map(),
320
- completedTools: new Set(),
321
- };
171
+ return { ...(sessionId === undefined ? {} : { sessionId }), tools: new Map(), completed: new Set() };
322
172
  }