@osovv/vv-opencode 2.0.1 → 2.1.0

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 (296) hide show
  1. package/CHANGELOG.md +42 -0
  2. package/README.md +87 -86
  3. package/dist/commands/completion.js +0 -1
  4. package/dist/commands/completion.js.map +1 -1
  5. package/dist/commands/doctor.js +6 -9
  6. package/dist/commands/doctor.js.map +1 -1
  7. package/dist/commands/init.d.ts +2 -1
  8. package/dist/commands/init.js +7 -12
  9. package/dist/commands/init.js.map +1 -1
  10. package/dist/commands/install.d.ts +4 -0
  11. package/dist/commands/install.js +40 -37
  12. package/dist/commands/install.js.map +1 -1
  13. package/dist/commands/launch.d.ts +2 -1
  14. package/dist/commands/launch.js +18 -14
  15. package/dist/commands/launch.js.map +1 -1
  16. package/dist/commands/patch-provider.d.ts +225 -307
  17. package/dist/commands/patch-provider.js +92 -296
  18. package/dist/commands/patch-provider.js.map +1 -1
  19. package/dist/commands/status.js +7 -10
  20. package/dist/commands/status.js.map +1 -1
  21. package/dist/commands/sync.d.ts +4 -0
  22. package/dist/commands/sync.js +38 -35
  23. package/dist/commands/sync.js.map +1 -1
  24. package/dist/index.d.ts +25 -5
  25. package/dist/index.js +73 -34
  26. package/dist/index.js.map +1 -1
  27. package/dist/lib/agent-tool-catalog.d.ts +1 -1
  28. package/dist/lib/agent-tool-catalog.js +3 -6
  29. package/dist/lib/agent-tool-catalog.js.map +1 -1
  30. package/dist/lib/agent-tool-contract.d.ts +22 -13
  31. package/dist/lib/agent-tool-contract.js +20 -20
  32. package/dist/lib/agent-tool-contract.js.map +1 -1
  33. package/dist/lib/analytics/types.d.ts +7 -1
  34. package/dist/lib/analytics/types.js +2 -2
  35. package/dist/lib/analytics/types.js.map +1 -1
  36. package/dist/lib/config-layers.d.ts +28 -6
  37. package/dist/lib/config-layers.js +268 -73
  38. package/dist/lib/config-layers.js.map +1 -1
  39. package/dist/lib/managed-agents.d.ts +24 -2
  40. package/dist/lib/managed-agents.js +45 -15
  41. package/dist/lib/managed-agents.js.map +1 -1
  42. package/dist/lib/model-roles.d.ts +5 -0
  43. package/dist/lib/model-roles.js +22 -1
  44. package/dist/lib/model-roles.js.map +1 -1
  45. package/dist/lib/opencode/agent-registrations.d.ts +4 -4
  46. package/dist/lib/opencode/agent-registrations.js +386 -197
  47. package/dist/lib/opencode/agent-registrations.js.map +1 -1
  48. package/dist/lib/opencode/inspection.d.ts +13 -13
  49. package/dist/lib/opencode/inspection.js +69 -106
  50. package/dist/lib/opencode/inspection.js.map +1 -1
  51. package/dist/lib/opencode/model-overrides.d.ts +2 -2
  52. package/dist/lib/opencode/model-overrides.js +192 -47
  53. package/dist/lib/opencode/model-overrides.js.map +1 -1
  54. package/dist/lib/opencode/paths.d.ts +6 -2
  55. package/dist/lib/opencode/paths.js +12 -11
  56. package/dist/lib/opencode/paths.js.map +1 -1
  57. package/dist/lib/opencode/plugin-registration.d.ts +10 -11
  58. package/dist/lib/opencode/plugin-registration.js +76 -138
  59. package/dist/lib/opencode/plugin-registration.js.map +1 -1
  60. package/dist/lib/opencode/shared-utils.d.ts +47 -3
  61. package/dist/lib/opencode/shared-utils.js +346 -15
  62. package/dist/lib/opencode/shared-utils.js.map +1 -1
  63. package/dist/lib/opencode.d.ts +5 -6
  64. package/dist/lib/opencode.js +10 -10
  65. package/dist/lib/opencode.js.map +1 -1
  66. package/dist/lib/vvoc-config.js +4 -4
  67. package/dist/lib/vvoc-config.js.map +1 -1
  68. package/dist/lib/vvoc-paths.d.ts +7 -0
  69. package/dist/lib/vvoc-paths.js +15 -1
  70. package/dist/lib/vvoc-paths.js.map +1 -1
  71. package/dist/lib/vvoc-preset-registry.d.ts +38 -50
  72. package/dist/lib/vvoc-preset-registry.js +38 -48
  73. package/dist/lib/vvoc-preset-registry.js.map +1 -1
  74. package/dist/plugins/analytics/index.d.ts +20 -14
  75. package/dist/plugins/analytics/index.js +281 -133
  76. package/dist/plugins/analytics/index.js.map +1 -1
  77. package/dist/plugins/guardian/index.d.ts +63 -42
  78. package/dist/plugins/guardian/index.js +217 -759
  79. package/dist/plugins/guardian/index.js.map +1 -1
  80. package/dist/plugins/hashline-edit/index.d.ts +145 -31
  81. package/dist/plugins/hashline-edit/index.js +679 -244
  82. package/dist/plugins/hashline-edit/index.js.map +1 -1
  83. package/dist/plugins/hashline-edit/schemas.d.ts +1 -1
  84. package/dist/plugins/hashline-edit/schemas.js +3 -3
  85. package/dist/plugins/hashline-edit/schemas.js.map +1 -1
  86. package/dist/plugins/model-roles/index.d.ts +18 -4
  87. package/dist/plugins/model-roles/index.js +44 -181
  88. package/dist/plugins/model-roles/index.js.map +1 -1
  89. package/dist/plugins/peak-hours/index.d.ts +23 -23
  90. package/dist/plugins/peak-hours/index.js +211 -180
  91. package/dist/plugins/peak-hours/index.js.map +1 -1
  92. package/dist/plugins/secrets-redaction/deep.js +35 -51
  93. package/dist/plugins/secrets-redaction/deep.js.map +1 -1
  94. package/dist/plugins/secrets-redaction/index.d.ts +96 -8
  95. package/dist/plugins/secrets-redaction/index.js +290 -102
  96. package/dist/plugins/secrets-redaction/index.js.map +1 -1
  97. package/dist/plugins/secrets-redaction/session.d.ts +9 -0
  98. package/dist/plugins/secrets-redaction/session.js +21 -4
  99. package/dist/plugins/secrets-redaction/session.js.map +1 -1
  100. package/dist/plugins/secrets-redaction/stream.d.ts +92 -0
  101. package/dist/plugins/secrets-redaction/stream.js +772 -0
  102. package/dist/plugins/secrets-redaction/stream.js.map +1 -0
  103. package/dist/plugins/spec-guard/index.d.ts +49 -18
  104. package/dist/plugins/spec-guard/index.js +231 -129
  105. package/dist/plugins/spec-guard/index.js.map +1 -1
  106. package/dist/plugins/system-context-injection/index.d.ts +10 -4
  107. package/dist/plugins/system-context-injection/index.js +271 -78
  108. package/dist/plugins/system-context-injection/index.js.map +1 -1
  109. package/dist/plugins/tool-history-compaction/index.d.ts +26 -4
  110. package/dist/plugins/tool-history-compaction/index.js +170 -32
  111. package/dist/plugins/tool-history-compaction/index.js.map +1 -1
  112. package/dist/plugins/tool-history-compaction/transform.d.ts +47 -16
  113. package/dist/plugins/tool-history-compaction/transform.js +173 -55
  114. package/dist/plugins/tool-history-compaction/transform.js.map +1 -1
  115. package/dist/plugins/web-tools/fetch-service.d.ts +51 -13
  116. package/dist/plugins/web-tools/fetch-service.js +106 -75
  117. package/dist/plugins/web-tools/fetch-service.js.map +1 -1
  118. package/dist/plugins/web-tools/index.d.ts +58 -16
  119. package/dist/plugins/web-tools/index.js +202 -91
  120. package/dist/plugins/web-tools/index.js.map +1 -1
  121. package/dist/plugins/web-tools/media-loader.d.ts +3 -3
  122. package/dist/plugins/web-tools/media-loader.js +3 -3
  123. package/dist/plugins/web-tools/media-loader.js.map +1 -1
  124. package/dist/plugins/web-tools/providers/native-fetch.d.ts +2 -2
  125. package/dist/plugins/web-tools/providers/native-fetch.js +1 -1
  126. package/dist/plugins/web-tools/providers/native-fetch.js.map +1 -1
  127. package/dist/plugins/web-tools/providers/spider.d.ts +2 -2
  128. package/dist/plugins/web-tools/providers/spider.js +1 -1
  129. package/dist/plugins/web-tools/providers/spider.js.map +1 -1
  130. package/dist/plugins/web-tools/providers/zai.d.ts +2 -2
  131. package/dist/plugins/web-tools/providers/zai.js +1 -1
  132. package/dist/plugins/web-tools/providers/zai.js.map +1 -1
  133. package/dist/plugins/web-tools/schemas.d.ts +1 -1
  134. package/dist/plugins/web-tools/schemas.js +3 -3
  135. package/dist/plugins/web-tools/schemas.js.map +1 -1
  136. package/dist/plugins/web-tools/search-service.d.ts +81 -12
  137. package/dist/plugins/web-tools/search-service.js +104 -57
  138. package/dist/plugins/web-tools/search-service.js.map +1 -1
  139. package/dist/plugins/workflow/authorization.d.ts +44 -10
  140. package/dist/plugins/workflow/authorization.js +113 -73
  141. package/dist/plugins/workflow/authorization.js.map +1 -1
  142. package/dist/plugins/workflow/cancellation.d.ts +86 -0
  143. package/dist/plugins/workflow/cancellation.js +202 -0
  144. package/dist/plugins/workflow/cancellation.js.map +1 -0
  145. package/dist/plugins/workflow/checkpoints.d.ts +7 -1
  146. package/dist/plugins/workflow/checkpoints.js +141 -21
  147. package/dist/plugins/workflow/checkpoints.js.map +1 -1
  148. package/dist/plugins/workflow/delegated.d.ts +14 -0
  149. package/dist/plugins/workflow/delegated.js +6 -5
  150. package/dist/plugins/workflow/delegated.js.map +1 -1
  151. package/dist/plugins/workflow/host.d.ts +81 -0
  152. package/dist/plugins/workflow/host.js +189 -0
  153. package/dist/plugins/workflow/host.js.map +1 -0
  154. package/dist/plugins/workflow/index.d.ts +69 -4
  155. package/dist/plugins/workflow/index.js +1391 -1026
  156. package/dist/plugins/workflow/index.js.map +1 -1
  157. package/dist/plugins/workflow/recovery.d.ts +3 -5
  158. package/dist/plugins/workflow/recovery.js +18 -33
  159. package/dist/plugins/workflow/recovery.js.map +1 -1
  160. package/dist/plugins/workflow/repair.d.ts +31 -5
  161. package/dist/plugins/workflow/repair.js +116 -48
  162. package/dist/plugins/workflow/repair.js.map +1 -1
  163. package/dist/plugins/workflow/results.d.ts +31 -31
  164. package/dist/plugins/workflow/results.js +4 -4
  165. package/dist/plugins/workflow/results.js.map +1 -1
  166. package/dist/plugins/workflow/schemas.d.ts +3 -3
  167. package/dist/plugins/workflow/schemas.js +5 -5
  168. package/dist/plugins/workflow/schemas.js.map +1 -1
  169. package/dist/plugins/workflow/system-instruction.md +4 -0
  170. package/dist/plugins/workflow/tooling.d.ts +6 -0
  171. package/dist/plugins/workflow/tooling.js +3 -1
  172. package/dist/plugins/workflow/tooling.js.map +1 -1
  173. package/dist/runtime/auxiliary.d.ts +13 -0
  174. package/dist/runtime/auxiliary.js +108 -0
  175. package/dist/runtime/auxiliary.js.map +1 -0
  176. package/dist/runtime/client.d.ts +88 -0
  177. package/dist/runtime/client.js +174 -0
  178. package/dist/runtime/client.js.map +1 -0
  179. package/dist/runtime/context-inspection-contract.d.ts +397 -0
  180. package/dist/runtime/context-inspection-contract.js +622 -0
  181. package/dist/runtime/context-inspection-contract.js.map +1 -0
  182. package/dist/runtime/context-inspection.d.ts +52 -0
  183. package/dist/runtime/context-inspection.js +324 -0
  184. package/dist/runtime/context-inspection.js.map +1 -0
  185. package/dist/runtime/context.d.ts +192 -0
  186. package/dist/runtime/context.js +1246 -0
  187. package/dist/runtime/context.js.map +1 -0
  188. package/dist/runtime/coordination.d.ts +40 -0
  189. package/dist/runtime/coordination.js +87 -0
  190. package/dist/runtime/coordination.js.map +1 -0
  191. package/dist/runtime/model-registry.d.ts +34 -0
  192. package/dist/runtime/model-registry.js +227 -0
  193. package/dist/runtime/model-registry.js.map +1 -0
  194. package/dist/runtime/permissions.d.ts +20 -0
  195. package/dist/runtime/permissions.js +250 -0
  196. package/dist/runtime/permissions.js.map +1 -0
  197. package/dist/runtime/snapshot-config.d.ts +80 -0
  198. package/dist/runtime/snapshot-config.js +268 -0
  199. package/dist/runtime/snapshot-config.js.map +1 -0
  200. package/dist/runtime/snapshot-store.d.ts +25 -0
  201. package/dist/runtime/snapshot-store.js +519 -0
  202. package/dist/runtime/snapshot-store.js.map +1 -0
  203. package/dist/runtime/snapshots.d.ts +59 -0
  204. package/dist/runtime/snapshots.js +721 -0
  205. package/dist/runtime/snapshots.js.map +1 -0
  206. package/dist/runtime/types.d.ts +713 -0
  207. package/dist/runtime/types.js +190 -0
  208. package/dist/runtime/types.js.map +1 -0
  209. package/dist/tui/analytics/indicator.d.ts +25 -26
  210. package/dist/tui/analytics/indicator.js +66 -74
  211. package/dist/tui/analytics/indicator.js.map +1 -1
  212. package/dist/tui/branding/footer.d.ts +7 -12
  213. package/dist/tui/branding/footer.js +16 -24
  214. package/dist/tui/branding/footer.js.map +1 -1
  215. package/dist/tui/context/analyze.d.ts +20 -9
  216. package/dist/tui/context/analyze.js +295 -257
  217. package/dist/tui/context/analyze.js.map +1 -1
  218. package/dist/tui/context/collect.d.ts +29 -3
  219. package/dist/tui/context/collect.js +450 -66
  220. package/dist/tui/context/collect.js.map +1 -1
  221. package/dist/tui/context/plugin.d.ts +21 -7
  222. package/dist/tui/context/plugin.js +65 -70
  223. package/dist/tui/context/plugin.js.map +1 -1
  224. package/dist/tui/context/types.d.ts +174 -43
  225. package/dist/tui/context/types.js +25 -19
  226. package/dist/tui/context/types.js.map +1 -1
  227. package/dist/tui/context/view.d.ts +33 -7
  228. package/dist/tui/context/view.js +136 -81
  229. package/dist/tui/context/view.js.map +1 -1
  230. package/dist/tui/peak-hours/banner.d.ts +13 -11
  231. package/dist/tui/peak-hours/banner.js +48 -80
  232. package/dist/tui/peak-hours/banner.js.map +1 -1
  233. package/dist/tui/policy.d.ts +69 -0
  234. package/dist/tui/policy.js +169 -0
  235. package/dist/tui/policy.js.map +1 -0
  236. package/dist/tui.d.ts +3 -8
  237. package/dist/tui.js +72 -68
  238. package/dist/tui.js.map +1 -1
  239. package/package.json +19 -15
  240. package/schemas/vvoc/v3.json +1 -1
  241. package/server.js +3 -5
  242. package/templates/agents/enhancer.md +10 -5
  243. package/templates/agents/guardian.md +10 -4
  244. package/templates/agents/investigator.md +4 -2
  245. package/templates/agents/vv-code-reviewer.md +4 -2
  246. package/templates/agents/vv-spec-reviewer.md +4 -2
  247. package/templates/skills/vv-execute/references/tool-contracts.md +1 -1
  248. package/tui.js +3 -5
  249. package/dist/plugins/analytics/v2.d.ts +0 -21
  250. package/dist/plugins/analytics/v2.js +0 -133
  251. package/dist/plugins/analytics/v2.js.map +0 -1
  252. package/dist/plugins/guardian/v2.d.ts +0 -13
  253. package/dist/plugins/guardian/v2.js +0 -204
  254. package/dist/plugins/guardian/v2.js.map +0 -1
  255. package/dist/plugins/hashline-edit/v2.d.ts +0 -12
  256. package/dist/plugins/hashline-edit/v2.js +0 -145
  257. package/dist/plugins/hashline-edit/v2.js.map +0 -1
  258. package/dist/plugins/model-roles/v2.d.ts +0 -24
  259. package/dist/plugins/model-roles/v2.js +0 -274
  260. package/dist/plugins/model-roles/v2.js.map +0 -1
  261. package/dist/plugins/peak-hours/v2.d.ts +0 -12
  262. package/dist/plugins/peak-hours/v2.js +0 -99
  263. package/dist/plugins/peak-hours/v2.js.map +0 -1
  264. package/dist/plugins/secrets-redaction/v2.d.ts +0 -19
  265. package/dist/plugins/secrets-redaction/v2.js +0 -138
  266. package/dist/plugins/secrets-redaction/v2.js.map +0 -1
  267. package/dist/plugins/spec-guard/v2.d.ts +0 -12
  268. package/dist/plugins/spec-guard/v2.js +0 -139
  269. package/dist/plugins/spec-guard/v2.js.map +0 -1
  270. package/dist/plugins/system-context-injection/agent-contexts.d.ts +0 -5
  271. package/dist/plugins/system-context-injection/agent-contexts.js +0 -164
  272. package/dist/plugins/system-context-injection/agent-contexts.js.map +0 -1
  273. package/dist/plugins/system-context-injection/v2.d.ts +0 -13
  274. package/dist/plugins/system-context-injection/v2.js +0 -60
  275. package/dist/plugins/system-context-injection/v2.js.map +0 -1
  276. package/dist/plugins/tool-history-compaction/v2.d.ts +0 -11
  277. package/dist/plugins/tool-history-compaction/v2.js +0 -56
  278. package/dist/plugins/tool-history-compaction/v2.js.map +0 -1
  279. package/dist/plugins/v2-runtime/config-watcher.d.ts +0 -26
  280. package/dist/plugins/v2-runtime/config-watcher.js +0 -111
  281. package/dist/plugins/v2-runtime/config-watcher.js.map +0 -1
  282. package/dist/plugins/v2-runtime/index.d.ts +0 -50
  283. package/dist/plugins/v2-runtime/index.js +0 -114
  284. package/dist/plugins/v2-runtime/index.js.map +0 -1
  285. package/dist/plugins/v2-runtime/location-config.d.ts +0 -51
  286. package/dist/plugins/v2-runtime/location-config.js +0 -91
  287. package/dist/plugins/v2-runtime/location-config.js.map +0 -1
  288. package/dist/plugins/v2-runtime/setup.d.ts +0 -48
  289. package/dist/plugins/v2-runtime/setup.js +0 -174
  290. package/dist/plugins/v2-runtime/setup.js.map +0 -1
  291. package/dist/plugins/web-tools/v2.d.ts +0 -11
  292. package/dist/plugins/web-tools/v2.js +0 -99
  293. package/dist/plugins/web-tools/v2.js.map +0 -1
  294. package/dist/plugins/workflow/v2.d.ts +0 -76
  295. package/dist/plugins/workflow/v2.js +0 -283
  296. package/dist/plugins/workflow/v2.js.map +0 -1
@@ -1,9 +1,9 @@
1
1
  // FILE: src/plugins/workflow/authorization.ts
2
- // VERSION: 1.0.0
2
+ // VERSION: 2.0.0
3
3
  // START_MODULE_CONTRACT
4
- // PURPOSE: Workflow tool access guards and SDK-backed read-only authorization message lookups over an explicit plugin context.
5
- // SCOPE: Agent gating for workflow tools, primary root-controller mutation authorization (agent, trusted workspace, invalid-hydration, and root-session identity through the pinned SDK session.get), and the recovery and advance-authority message lookups through the pinned SDK session.message retaining only identity, timing, and eligibility metadata. No tool definitions, stores, or persistence here.
6
- // DEPENDS: [@opencode-ai/plugin (Plugin type), src/plugins/workflow/delegated.ts (LookupRecoveryUserMessage type), src/plugins/workflow/authority.ts (AuthorityMessageSnapshot type)]
4
+ // PURPOSE: Workflow tool access guards and native-session-backed read-only authorization message lookups over an explicit plugin context.
5
+ // SCOPE: Agent gating for workflow tools, primary root-controller mutation authorization (agent, trusted workspace, invalid-hydration, and root/fork identity through the native session.get), and the recovery and advance-authority message lookups through the native session.context retaining only identity, timing, and eligibility metadata. No tool definitions, stores, or persistence here.
6
+ // DEPENDS: [src/plugins/workflow/delegated.ts (LookupRecoveryUserMessage type), src/plugins/workflow/authority.ts (AuthorityMessageSnapshot type)]
7
7
  // LINKS: [M-PLUGIN-WORKFLOW, M-WORKFLOW-DELEGATED, M-WORKFLOW-AUTHORITY]
8
8
  // ROLE: RUNTIME
9
9
  // MAP_MODE: EXPORTS
@@ -11,16 +11,19 @@
11
11
  //
12
12
  // START_MODULE_MAP
13
13
  // WORKFLOW_CONTROLLER_AGENT - Canonical agent name allowed to use workflow tools and control mutations.
14
- // WorkflowAuthorizationContext - Explicit plugin context (client, directory, worktree, trusted root, invalid-hydration sessions) consumed by the factory.
14
+ // NativeWorkflowSessionInfo - Structural native session info used for root/fork/workspace identity.
15
+ // NativeWorkflowSession - Narrow native session surface (get + context) used for identity.
16
+ // NativeAuthorizationClient - Narrow full-client surface (session.get + exact session.message.get) used for identity and message lookups.
17
+ // WorkflowAuthorizationContext - Explicit plugin context (native client, trusted directory/root, invalid-hydration sessions) consumed by the factory.
15
18
  // WorkflowAuthorization - Authorization guards and lookups bound to one plugin instance.
16
19
  // canUseWorkflowTools - True when the calling agent is the workflow controller.
17
20
  // assertWorkflowToolAccess - Throws WORKFLOW_TOOL_DENIED for non-controller agents.
18
21
  // shouldInjectForAgent - True when workflow guidance should be injected for the agent.
19
- // createWorkflowAuthorization - Binds the primary-controller mutation guard and the SDK-backed message lookups to an explicit context.
22
+ // createWorkflowAuthorization - Binds the primary-controller mutation guard and the native message lookups to an explicit context.
20
23
  // END_MODULE_MAP
21
24
  //
22
25
  // START_CHANGE_SUMMARY
23
- // LAST_CHANGE: [C-AGENT-TOOL-CONTRACTS T-003 - Diagnostics carry a stable category: non-controller agent, child session, and workspace mismatch remain CONTROL_DENIED/authorization, a failing SDK root/session lookup is HOST_CONTEXT_UNAVAILABLE/host_context, and invalid persisted state is PERSISTENCE_FAILED/persistence. Message text is unchanged where meaningful. SDK-backed message lookups are unchanged.]
26
+ // LAST_CHANGE: [C-OPENCODE-V2-NATIVE T-004 attempt 3 - Authorization message lookups now use the authenticated full client's exact session.message.get by id (surviving context compaction) instead of the projected session.context list; root identity still rejects child and fork sessions and verifies host location.]
24
27
  // END_CHANGE_SUMMARY
25
28
  import { WorkflowDiagnosticError } from "./results.js";
26
29
  export const WORKFLOW_CONTROLLER_AGENT = "vv-controller";
@@ -40,106 +43,143 @@ export function assertWorkflowToolAccess(agentName, toolName) {
40
43
  export function shouldInjectForAgent(agentName) {
41
44
  return canUseWorkflowTools(agentName);
42
45
  }
46
+ function isRecord(value) {
47
+ return typeof value === "object" && value !== null && !Array.isArray(value);
48
+ }
49
+ function readMessageId(message) {
50
+ if (!isRecord(message))
51
+ return undefined;
52
+ return typeof message.id === "string" ? message.id : undefined;
53
+ }
54
+ function readMessageType(message) {
55
+ if (!isRecord(message))
56
+ return undefined;
57
+ return typeof message.type === "string" ? message.type : undefined;
58
+ }
59
+ function readMessageCreated(message) {
60
+ if (!isRecord(message) || !isRecord(message.time))
61
+ return undefined;
62
+ const created = message.time.created;
63
+ return typeof created === "number" && Number.isFinite(created) ? created : undefined;
64
+ }
65
+ function readTextParts(message) {
66
+ if (!isRecord(message))
67
+ return [];
68
+ const type = message.type;
69
+ if (type === "user" || type === "synthetic" || type === "system") {
70
+ return typeof message.text === "string" ? [message.text] : [];
71
+ }
72
+ if (type === "assistant") {
73
+ const content = message.content;
74
+ if (!Array.isArray(content))
75
+ return [];
76
+ return content
77
+ .filter((part) => {
78
+ return isRecord(part) && part.type === "text" && typeof part.text === "string";
79
+ })
80
+ .map((part) => part.text);
81
+ }
82
+ return [];
83
+ }
84
+ /**
85
+ * Read one exact native message by id through the authenticated full client.
86
+ * Returns undefined only when the message genuinely does not exist; a transport
87
+ * or authentication failure propagates so the domain reports a lookup failure
88
+ * instead of conflating it with a missing message.
89
+ */
90
+ async function readNativeMessageById(client, sessionId, messageId) {
91
+ const message = await client.session.message.get({ sessionID: sessionId, messageID: messageId });
92
+ return message ?? undefined;
93
+ }
43
94
  export function createWorkflowAuthorization(context) {
44
- const { client, directory, worktree, trustedWorkspaceRoot, invalidHydrationSessions } = context;
95
+ const { getClient, directory, trustedWorkspaceRoot, invalidHydrationSessions } = context;
96
+ /** Normalized trusted workspace comparison (native reports absolute paths). */
97
+ function isTrustedWorkspacePath(candidate) {
98
+ if (typeof candidate !== "string" || candidate === "")
99
+ return false;
100
+ return candidate === directory || candidate === trustedWorkspaceRoot;
101
+ }
45
102
  // New control mutations require the primary vv-controller session: the calling
46
- // agent must be vv-controller, the session must be a root session (no
47
- // parentID), and the ToolContext workspace must match the plugin's trusted
48
- // directory/worktree. None of this identity comes from tool arguments.
49
- async function assertPrimaryControllerMutation(agent, sessionId, contextWorkspace, toolName) {
103
+ // agent must be vv-controller, the host session must be a root session with no
104
+ // parent and no fork lineage, and the host-reported location must match the
105
+ // plugin's trusted workspace. None of this identity comes from tool arguments.
106
+ async function assertPrimaryControllerMutation(agent, sessionId, toolName) {
50
107
  if (!canUseWorkflowTools(agent)) {
51
108
  throw controlDenied(`CONTROL_DENIED: ${toolName} is only available to ${WORKFLOW_CONTROLLER_AGENT} sessions. Current agent: ${agent?.trim() || "unknown-agent"}.`);
52
109
  }
53
- if (contextWorkspace.worktree !== undefined &&
54
- contextWorkspace.worktree !== worktree &&
55
- contextWorkspace.worktree !== trustedWorkspaceRoot) {
56
- throw controlDenied(`CONTROL_DENIED: ${toolName} workspace ${contextWorkspace.worktree} does not match the trusted plugin workspace.`);
57
- }
58
- if (contextWorkspace.worktree === undefined &&
59
- contextWorkspace.directory !== undefined &&
60
- contextWorkspace.directory !== directory) {
61
- throw controlDenied(`CONTROL_DENIED: ${toolName} directory ${contextWorkspace.directory} does not match the trusted plugin directory.`);
62
- }
63
110
  if (invalidHydrationSessions.has(sessionId)) {
64
111
  // Invalid persisted state is a persistence/host condition, not a caller
65
112
  // authorization failure; keep the failure closed and the text explicit.
66
113
  throw new WorkflowDiagnosticError("PERSISTENCE_FAILED", "persistence", `PERSISTENCE_FAILED: persisted workflow state for session ${sessionId} is invalid; resolve or remove it before new control mutations.`);
67
114
  }
68
- let parentID;
115
+ let info;
69
116
  try {
70
- const response = await client.session.get({ path: { id: sessionId } });
71
- if (!response.data) {
72
- throw new Error("missing session payload");
73
- }
74
- parentID = response.data.parentID;
117
+ const client = await getClient();
118
+ info = await client.session.get({ sessionID: sessionId });
75
119
  }
76
120
  catch (error) {
77
- // A missing or failing SDK root/session lookup is unavailable trusted host
121
+ // A missing or failing native session lookup is unavailable trusted host
78
122
  // context, not a denial of authorization.
79
123
  throw new WorkflowDiagnosticError("HOST_CONTEXT_UNAVAILABLE", "host_context", `HOST_CONTEXT_UNAVAILABLE: ${toolName} requires root-session identity for ${sessionId}, which could not be verified: ${error.message}`);
80
124
  }
125
+ const parentID = info.parentID;
81
126
  if (parentID !== undefined && parentID !== null && parentID !== "") {
82
- throw controlDenied(`CONTROL_DENIED: ${toolName} may only run in the root session; session ${sessionId} is a child of ${parentID}.`);
127
+ throw controlDenied(`CONTROL_DENIED: ${toolName} may only run in the root session; session ${sessionId} is a child of ${String(parentID)}.`);
128
+ }
129
+ const forkedFrom = info.fork?.sessionID;
130
+ if (forkedFrom !== undefined && forkedFrom !== null && forkedFrom !== "") {
131
+ throw controlDenied(`CONTROL_DENIED: ${toolName} may only run in the root session; session ${sessionId} is a fork of ${String(forkedFrom)}.`);
132
+ }
133
+ const hostDirectory = info.location?.directory;
134
+ if (hostDirectory !== undefined && !isTrustedWorkspacePath(hostDirectory)) {
135
+ throw controlDenied(`CONTROL_DENIED: ${toolName} workspace ${String(hostDirectory)} does not match the trusted plugin workspace.`);
83
136
  }
84
137
  }
85
- // Read-only SDK message lookup for user-authorized recovery. Only identity
138
+ // Read-only native message lookup for user-authorized recovery. Only identity
86
139
  // and timing metadata (role, sessionID, id, time.created) are retained;
87
140
  // message bodies never enter validation, persistence, or logs. Transport
88
141
  // failures throw so the domain reports AUTHORIZATION_LOOKUP_FAILED instead
89
142
  // of conflating an unreachable lookup with a nonexistent message.
90
143
  const lookupRecoveryUserMessage = async (sessionId, messageId) => {
91
- const response = await client.session.message({
92
- path: { id: sessionId, messageID: messageId },
93
- query: { directory },
94
- });
95
- if (response.error || !response.data) {
96
- const errorName = response.error?.name;
97
- if (errorName && errorName !== "NotFound") {
98
- throw new Error(`session message lookup failed: ${errorName}`);
99
- }
144
+ const message = await readNativeMessageById(await getClient(), sessionId, messageId);
145
+ if (message === undefined) {
146
+ return undefined;
147
+ }
148
+ const type = readMessageType(message);
149
+ const id = readMessageId(message);
150
+ // Only the exact requested id participates; a mismatched payload id is a
151
+ // lookup defect, never silently accepted as the requested message.
152
+ if (type !== "user" || (id !== undefined && id !== messageId)) {
100
153
  return undefined;
101
154
  }
102
- const info = response.data.info;
103
155
  return {
104
- role: info.role,
105
- sessionID: info.sessionID,
106
- id: info.id,
107
- timeCreatedMs: typeof info.time?.created === "number" && Number.isFinite(info.time.created)
108
- ? info.time.created
109
- : undefined,
156
+ role: "user",
157
+ sessionID: sessionId,
158
+ id: messageId,
159
+ timeCreatedMs: readMessageCreated(message),
110
160
  };
111
161
  };
112
- // Advance-authority provenance uses the same pinned SDK message response.
113
- // Only verified identity/timing/eligibility metadata leaves this lookup; raw
114
- // user text is never persisted or logged.
162
+ // Advance-authority provenance uses the same exact native message lookup. Only
163
+ // verified identity/timing/eligibility metadata leaves this lookup; raw user
164
+ // text is never persisted or logged.
115
165
  const lookupAuthorityMessage = async (input) => {
116
- const response = await client.session.message({
117
- path: { id: input.sessionId, messageID: input.messageId },
118
- query: { directory },
119
- });
120
- if (response.error || !response.data) {
121
- const errorName = response.error?.name;
122
- if (errorName && errorName !== "NotFound") {
123
- throw new Error(`authority message lookup failed: ${errorName}`);
124
- }
166
+ const message = await readNativeMessageById(await getClient(), input.sessionId, input.messageId);
167
+ if (message === undefined) {
168
+ return undefined;
169
+ }
170
+ const type = readMessageType(message);
171
+ const id = readMessageId(message);
172
+ if (id !== undefined && id !== input.messageId) {
125
173
  return undefined;
126
174
  }
127
- const info = response.data.info;
128
- const parts = Array.isArray(response.data.parts) ? response.data.parts : [];
129
- const textParts = parts
130
- .map((part) => part)
131
- .filter((part) => part.type === "text" && typeof part.text === "string")
132
- .map((part) => part.text);
133
175
  return {
134
- messageId: info.id ?? input.messageId,
135
- sessionId: info.sessionID ?? input.sessionId,
136
- role: info.role === "user" ? "user" : "assistant",
137
- createdMs: typeof info.time?.created === "number" && Number.isFinite(info.time.created)
138
- ? info.time.created
139
- : 0,
140
- ignored: info.ignored === true,
176
+ messageId: input.messageId,
177
+ sessionId: input.sessionId,
178
+ role: type === "user" ? "user" : "assistant",
179
+ createdMs: readMessageCreated(message) ?? 0,
180
+ ignored: isRecord(message) && message.ignored === true,
141
181
  syntheticOnly: false,
142
- textParts,
182
+ textParts: readTextParts(message),
143
183
  };
144
184
  };
145
185
  return { assertPrimaryControllerMutation, lookupRecoveryUserMessage, lookupAuthorityMessage };
@@ -1 +1 @@
1
- {"version":3,"file":"authorization.js","sourceRoot":"","sources":["../../../src/plugins/workflow/authorization.ts"],"names":[],"mappings":"AAAA,8CAA8C;AAC9C,iBAAiB;AACjB,wBAAwB;AACxB,iIAAiI;AACjI,mZAAmZ;AACnZ,wLAAwL;AACxL,2EAA2E;AAC3E,kBAAkB;AAClB,sBAAsB;AACtB,sBAAsB;AACtB,EAAE;AACF,mBAAmB;AACnB,0GAA0G;AAC1G,4JAA4J;AAC5J,2FAA2F;AAC3F,kFAAkF;AAClF,sFAAsF;AACtF,yFAAyF;AACzF,yIAAyI;AACzI,iBAAiB;AACjB,EAAE;AACF,uBAAuB;AACvB,yZAAyZ;AACzZ,qBAAqB;AAKrB,OAAO,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAEvD,MAAM,CAAC,MAAM,yBAAyB,GAAG,eAAe,CAAC;AAEzD,SAAS,aAAa,CAAC,OAAe;IACpC,OAAO,IAAI,uBAAuB,CAAC,gBAAgB,EAAE,eAAe,EAAE,OAAO,CAAC,CAAC;AACjF,CAAC;AA4BD,MAAM,UAAU,mBAAmB,CAAC,SAA6B;IAC/D,OAAO,SAAS,KAAK,yBAAyB,CAAC;AACjD,CAAC;AAED,MAAM,UAAU,wBAAwB,CAAC,SAA6B,EAAE,QAAgB;IACtF,IAAI,mBAAmB,CAAC,SAAS,CAAC,EAAE,CAAC;QACnC,OAAO;IACT,CAAC;IAED,MAAM,aAAa,GAAG,SAAS,EAAE,IAAI,EAAE,IAAI,eAAe,CAAC;IAC3D,MAAM,IAAI,uBAAuB,CAC/B,sBAAsB,EACtB,eAAe,EACf,yBAAyB,QAAQ,yBAAyB,yBAAyB,6BAA6B,aAAa,GAAG,CACjI,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,SAA6B;IAChE,OAAO,mBAAmB,CAAC,SAAS,CAAC,CAAC;AACxC,CAAC;AAED,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,SAAS,CAChB,CAAC;QACF,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;YAC1B,OAAO,SAAS,CAAC;QACnB,CAAC;QACD,MAAM,IAAI,GAAG,eAAe,CAAC,OAAO,CAAC,CAAC;QACtC,MAAM,EAAE,GAAG,aAAa,CAAC,OAAO,CAAC,CAAC;QAClC,IAAI,EAAE,KAAK,SAAS,IAAI,EAAE,KAAK,KAAK,CAAC,SAAS,EAAE,CAAC;YAC/C,OAAO,SAAS,CAAC;QACnB,CAAC;QACD,OAAO;YACL,SAAS,EAAE,KAAK,CAAC,SAAS;YAC1B,SAAS,EAAE,KAAK,CAAC,SAAS;YAC1B,IAAI,EAAE,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,WAAW;YAC5C,SAAS,EAAE,kBAAkB,CAAC,OAAO,CAAC,IAAI,CAAC;YAC3C,OAAO,EAAE,QAAQ,CAAC,OAAO,CAAC,IAAI,OAAO,CAAC,OAAO,KAAK,IAAI;YACtD,aAAa,EAAE,KAAK;YACpB,SAAS,EAAE,aAAa,CAAC,OAAO,CAAC;SAClC,CAAC;IACJ,CAAC,CAAC;IAEF,OAAO,EAAE,+BAA+B,EAAE,yBAAyB,EAAE,sBAAsB,EAAE,CAAC;AAChG,CAAC"}
@@ -0,0 +1,86 @@
1
+ /** Native `SessionError.Error` shape (packages/schema/src/session-error.ts). */
2
+ export interface NativeStructuredError {
3
+ readonly type: string;
4
+ readonly message: string;
5
+ readonly status?: number;
6
+ }
7
+ /** Decoded native `session.tool.success` / `session.tool.failed` terminal event. */
8
+ export interface NativeToolTerminalEvent {
9
+ readonly sessionID: string;
10
+ readonly callID: string;
11
+ readonly status: "success" | "failed";
12
+ /** Present only on failed. */
13
+ readonly error?: NativeStructuredError;
14
+ readonly metadata?: Readonly<Record<string, unknown>>;
15
+ }
16
+ /** Decoded native `session.synthetic` event. */
17
+ export interface NativeSyntheticEvent {
18
+ readonly sessionID: string;
19
+ readonly text: string;
20
+ readonly description?: string;
21
+ readonly metadata?: Readonly<Record<string, unknown>>;
22
+ }
23
+ /** Decoded native `session.execution.failed` / `session.execution.interrupted` event. */
24
+ export interface NativeExecutionTerminalEvent {
25
+ readonly sessionID: string;
26
+ readonly status: "failed" | "interrupted";
27
+ readonly error?: NativeStructuredError;
28
+ readonly reason?: "user" | "shutdown" | "superseded" | "inactivity";
29
+ }
30
+ /** Native mapping of a foreground subagent tool-call termination. */
31
+ export type SubagentToolFailureKind = "cancelled" | "failed" | "interrupted";
32
+ /** Parsed subagent tool-call termination naming the child session it belongs to. */
33
+ export interface SubagentToolFailure {
34
+ readonly kind: SubagentToolFailureKind;
35
+ readonly childSessionId: string;
36
+ readonly detail?: string;
37
+ }
38
+ /**
39
+ * Parse only the exact pinned subagent termination messages, covering both
40
+ * native interrupt shapes (live root interrupt and stale post-death settle). A
41
+ * generic provider or transport error, an unrelated tool interrupt, or an
42
+ * interrupt without a subagent child session id is not a cancellation and
43
+ * returns undefined.
44
+ */
45
+ export declare function parseSubagentToolFailure(message: string): SubagentToolFailure | undefined;
46
+ /** True only for a terminal native `{type:"aborted"}` structured error. */
47
+ export declare function isAbortedStructuredError(error: NativeStructuredError | undefined): error is NativeStructuredError;
48
+ /** Decode a native session.tool.success/session.tool.failed envelope, or undefined for any other event. */
49
+ export declare function decodeToolTerminalEvent(event: unknown): NativeToolTerminalEvent | undefined;
50
+ /** Decode a native session.synthetic envelope, or undefined for any other event. */
51
+ export declare function decodeSyntheticEvent(event: unknown): NativeSyntheticEvent | undefined;
52
+ /** Decode a native session.execution.failed/session.execution.interrupted envelope. */
53
+ export declare function decodeExecutionTerminalEvent(event: unknown): NativeExecutionTerminalEvent | undefined;
54
+ /**
55
+ * Strict evidence bundle for one candidate cancellation recovery. Every field is
56
+ * required and independently verified; the caller must supply evidence observed
57
+ * from authoritative native sources only.
58
+ */
59
+ export interface CancellationEvidence {
60
+ /** Session that owned the subagent tool call (the workflow/controller session). */
61
+ readonly parentSessionId: string;
62
+ /** Stable native tool call identity of the terminated subagent call. */
63
+ readonly callID: string;
64
+ /** Child session the termination names; must match every other child reference. */
65
+ readonly childSessionId: string;
66
+ /** Parent tool-call termination; only cancelled/interrupted qualify, never a generic failure. */
67
+ readonly parentToolFailure: SubagentToolFailure;
68
+ /** Child's structured terminal abort; only `{type:"aborted"}` qualifies. */
69
+ readonly childTerminalError: NativeStructuredError;
70
+ /** True when the child still has an active execution/inbox; quiescence requires false. */
71
+ readonly childActive: boolean;
72
+ }
73
+ /** Cancellation evidence evaluation outcome. */
74
+ export type CancellationEvidenceDecision = {
75
+ readonly ok: true;
76
+ } | {
77
+ readonly ok: false;
78
+ readonly reason: string;
79
+ };
80
+ /**
81
+ * Approve cancellation settlement only when the parent tool-call termination is an
82
+ * authoritative cancellation/interruption naming the child, the child reports a
83
+ * terminal structured abort, and the child is quiescent. A plain provider failure,
84
+ * a different/wrong child, an unspecified call, or an active child all refuse.
85
+ */
86
+ export declare function evaluateCancellationEvidence(evidence: CancellationEvidence): CancellationEvidenceDecision;
@@ -0,0 +1,202 @@
1
+ // FILE: src/plugins/workflow/cancellation.ts
2
+ // VERSION: 1.0.0
3
+ // START_MODULE_CONTRACT
4
+ // PURPOSE: Decode native OpenCode 2.0.18 terminal tool/execution/synthetic events and decide, under a strict evidence rule, whether a workflow attempt was authoritatively cancelled.
5
+ // SCOPE: Pure native event decoding and cancellation-evidence evaluation only. No session/client access, no state mutation, no persistence, no budgets. The approved evidence rule requires an authoritative parent subagent tool-call termination, the actual child's terminal abort, and child quiescence; every other shape refuses.
6
+ // DEPENDS: []
7
+ // LINKS: [M-PLUGIN-WORKFLOW, M-WORKFLOW-DELEGATED, M-WORKFLOW-EXECUTION, V-M-PLUGIN-WORKFLOW]
8
+ // ROLE: RUNTIME
9
+ // MAP_MODE: EXPORTS
10
+ // END_MODULE_CONTRACT
11
+ //
12
+ // START_MODULE_MAP
13
+ // NativeStructuredError - Native SessionError.Error shape ({type, message, status?}).
14
+ // NativeToolTerminalEvent - Decoded session.tool.success/session.tool.failed terminal event.
15
+ // NativeSyntheticEvent - Decoded session.synthetic event delivered to a parent session.
16
+ // NativeExecutionTerminalEvent - Decoded session.execution.failed/interrupted terminal event.
17
+ // SubagentToolFailureKind - Native mapping of a foreground subagent tool-call termination.
18
+ // SubagentToolFailure - Parsed subagent tool-call termination with the child session it names.
19
+ // parseSubagentToolFailure - Parse the exact pinned subagent failure/cancel/interrupt messages (both native interrupt shapes).
20
+ // isAbortedStructuredError - True only for a terminal native `{type:"aborted"}` error.
21
+ // decodeToolTerminalEvent - Decode a native session.tool.success/session.tool.failed envelope.
22
+ // decodeSyntheticEvent - Decode a native session.synthetic envelope.
23
+ // decodeExecutionTerminalEvent - Decode a native session.execution.failed/interrupted envelope.
24
+ // CancellationEvidence - Strict evidence bundle for one candidate cancellation recovery.
25
+ // CancellationEvidenceDecision - Approved or refused cancellation settlement outcome.
26
+ // evaluateCancellationEvidence - Approve cancellation settlement only with complete, matching, quiescent evidence.
27
+ // END_MODULE_MAP
28
+ //
29
+ // START_CHANGE_SUMMARY
30
+ // LAST_CHANGE: [C-OPENCODE-V2-NATIVE wi-20 - parseSubagentToolFailure now recognizes BOTH pinned 2.0.18 interrupt shapes: the live in-process root-interrupt `Tool execution interrupted (sessionID: <id>)` (step.ts TOOLS_INTERRUPTED composed by publish-llm-event.ts failTool) in addition to the stale post-process-death `Tool execution interrupted: subagent (sessionID: <id>)` (llm.ts settleStaleToolCalls). A root interrupt now yields kind 'interrupted' with the child session id, so explicit recovery can settle the attempt; a bare interrupt without a child session id, a generic provider/transport error, or unrelated text still returns undefined. T-004 originally added the authoritative native cancellation mapping and strict recovery evidence rule, replacing the V1 Task cancelled / MessageAbortedError assumption with verified 2.0.18 shapes.]
31
+ // END_CHANGE_SUMMARY
32
+ // Exact pinned messages from the 2.0.18 source:
33
+ // - packages/core/src/tool/plugin/subagent.ts: `Subagent cancelled (sessionID: <id>)`
34
+ // and `Subagent failed (sessionID: <id>): <detail>`.
35
+ // - LIVE in-process root interrupt (parent session interrupted while the subagent
36
+ // tool part is unsettled — the common TUI Esc / API interrupt case):
37
+ // packages/core/src/session/runner/step.ts:61 `TOOLS_INTERRUPTED`
38
+ // (`{ type: "aborted", message: "Tool execution interrupted" }`) composed by
39
+ // packages/core/src/session/runner/publish-llm-event.ts:342-358 (`failTool`
40
+ // subagent special case) into `Tool execution interrupted (sessionID: <id>)`.
41
+ // - STALE post-process-death settle: packages/core/src/session/runner/llm.ts:348
42
+ // (`settleStaleToolCalls`) `Tool execution interrupted: subagent (sessionID: <id>)`.
43
+ // Both interrupt shapes carry a subagent child session id; a bare
44
+ // `Tool execution interrupted` (no child session id) is not evidence here.
45
+ const SUBAGENT_CANCELLED_RE = /^Subagent cancelled \(sessionID: ([^)\s]+)\)$/;
46
+ const SUBAGENT_FAILED_RE = /^Subagent failed \(sessionID: ([^)\s]+)\)(?:: ([\s\S]*))?$/;
47
+ const SUBAGENT_INTERRUPTED_LIVE_RE = /^Tool execution interrupted \(sessionID: ([^)\s]+)\)$/;
48
+ const SUBAGENT_INTERRUPTED_STALE_RE = /^Tool execution interrupted: subagent \(sessionID: ([^)\s]+)\)$/;
49
+ /**
50
+ * Parse only the exact pinned subagent termination messages, covering both
51
+ * native interrupt shapes (live root interrupt and stale post-death settle). A
52
+ * generic provider or transport error, an unrelated tool interrupt, or an
53
+ * interrupt without a subagent child session id is not a cancellation and
54
+ * returns undefined.
55
+ */
56
+ export function parseSubagentToolFailure(message) {
57
+ const cancelled = SUBAGENT_CANCELLED_RE.exec(message);
58
+ if (cancelled) {
59
+ return { kind: "cancelled", childSessionId: cancelled[1] };
60
+ }
61
+ const failed = SUBAGENT_FAILED_RE.exec(message);
62
+ if (failed) {
63
+ const detail = failed[2];
64
+ return {
65
+ kind: "failed",
66
+ childSessionId: failed[1],
67
+ ...(detail === undefined || detail === "" ? {} : { detail }),
68
+ };
69
+ }
70
+ const liveInterrupted = SUBAGENT_INTERRUPTED_LIVE_RE.exec(message);
71
+ if (liveInterrupted) {
72
+ return { kind: "interrupted", childSessionId: liveInterrupted[1] };
73
+ }
74
+ const staleInterrupted = SUBAGENT_INTERRUPTED_STALE_RE.exec(message);
75
+ if (staleInterrupted) {
76
+ return { kind: "interrupted", childSessionId: staleInterrupted[1] };
77
+ }
78
+ return undefined;
79
+ }
80
+ /** True only for a terminal native `{type:"aborted"}` structured error. */
81
+ export function isAbortedStructuredError(error) {
82
+ return error !== undefined && error.type === "aborted";
83
+ }
84
+ function isRecord(value) {
85
+ return typeof value === "object" && value !== null && !Array.isArray(value);
86
+ }
87
+ function decodeStructuredError(value) {
88
+ if (!isRecord(value))
89
+ return undefined;
90
+ const type = value.type;
91
+ const message = value.message;
92
+ if (typeof type !== "string" || typeof message !== "string")
93
+ return undefined;
94
+ const status = value.status;
95
+ return {
96
+ type,
97
+ message,
98
+ ...(typeof status === "number" && Number.isFinite(status) ? { status } : {}),
99
+ };
100
+ }
101
+ function readEnvelope(event) {
102
+ if (!isRecord(event))
103
+ return undefined;
104
+ const type = event.type;
105
+ const data = event.data;
106
+ if (typeof type !== "string" || !isRecord(data))
107
+ return undefined;
108
+ return { type, data };
109
+ }
110
+ /** Decode a native session.tool.success/session.tool.failed envelope, or undefined for any other event. */
111
+ export function decodeToolTerminalEvent(event) {
112
+ const envelope = readEnvelope(event);
113
+ if (!envelope)
114
+ return undefined;
115
+ const { type, data } = envelope;
116
+ if (type !== "session.tool.success" && type !== "session.tool.failed")
117
+ return undefined;
118
+ const sessionID = data.sessionID;
119
+ const callID = data.id;
120
+ if (typeof sessionID !== "string" || typeof callID !== "string")
121
+ return undefined;
122
+ const metadata = isRecord(data.metadata) ? data.metadata : undefined;
123
+ if (type === "session.tool.success") {
124
+ return { sessionID, callID, status: "success", ...(metadata ? { metadata } : {}) };
125
+ }
126
+ const error = decodeStructuredError(data.error);
127
+ if (error === undefined)
128
+ return undefined;
129
+ return { sessionID, callID, status: "failed", error, ...(metadata ? { metadata } : {}) };
130
+ }
131
+ /** Decode a native session.synthetic envelope, or undefined for any other event. */
132
+ export function decodeSyntheticEvent(event) {
133
+ const envelope = readEnvelope(event);
134
+ if (!envelope || envelope.type !== "session.synthetic")
135
+ return undefined;
136
+ const { data } = envelope;
137
+ const sessionID = data.sessionID;
138
+ const text = data.text;
139
+ if (typeof sessionID !== "string" || typeof text !== "string")
140
+ return undefined;
141
+ const description = typeof data.description === "string" ? data.description : undefined;
142
+ const metadata = isRecord(data.metadata) ? data.metadata : undefined;
143
+ return {
144
+ sessionID,
145
+ text,
146
+ ...(description === undefined ? {} : { description }),
147
+ ...(metadata === undefined ? {} : { metadata }),
148
+ };
149
+ }
150
+ /** Decode a native session.execution.failed/session.execution.interrupted envelope. */
151
+ export function decodeExecutionTerminalEvent(event) {
152
+ const envelope = readEnvelope(event);
153
+ if (!envelope)
154
+ return undefined;
155
+ const { type, data } = envelope;
156
+ if (type === "session.execution.failed") {
157
+ const error = decodeStructuredError(data.error);
158
+ if (error === undefined)
159
+ return undefined;
160
+ const sessionID = data.sessionID;
161
+ if (typeof sessionID !== "string")
162
+ return undefined;
163
+ return { sessionID, status: "failed", error };
164
+ }
165
+ if (type === "session.execution.interrupted") {
166
+ const sessionID = data.sessionID;
167
+ const reason = data.reason;
168
+ if (typeof sessionID !== "string")
169
+ return undefined;
170
+ if (reason !== "user" &&
171
+ reason !== "shutdown" &&
172
+ reason !== "superseded" &&
173
+ reason !== "inactivity") {
174
+ return undefined;
175
+ }
176
+ return { sessionID, status: "interrupted", reason };
177
+ }
178
+ return undefined;
179
+ }
180
+ /**
181
+ * Approve cancellation settlement only when the parent tool-call termination is an
182
+ * authoritative cancellation/interruption naming the child, the child reports a
183
+ * terminal structured abort, and the child is quiescent. A plain provider failure,
184
+ * a different/wrong child, an unspecified call, or an active child all refuse.
185
+ */
186
+ export function evaluateCancellationEvidence(evidence) {
187
+ const { parentToolFailure } = evidence;
188
+ if (parentToolFailure.kind === "failed") {
189
+ return { ok: false, reason: "PARENT_TOOL_FAILURE_NOT_CANCELLATION" };
190
+ }
191
+ if (parentToolFailure.childSessionId !== evidence.childSessionId) {
192
+ return { ok: false, reason: "PARENT_CHILD_SESSION_MISMATCH" };
193
+ }
194
+ if (!isAbortedStructuredError(evidence.childTerminalError)) {
195
+ return { ok: false, reason: "CHILD_TERMINAL_NOT_ABORTED" };
196
+ }
197
+ if (evidence.childActive) {
198
+ return { ok: false, reason: "CHILD_STILL_ACTIVE" };
199
+ }
200
+ return { ok: true };
201
+ }
202
+ //# sourceMappingURL=cancellation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cancellation.js","sourceRoot":"","sources":["../../../src/plugins/workflow/cancellation.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAC7C,iBAAiB;AACjB,wBAAwB;AACxB,wLAAwL;AACxL,0UAA0U;AAC1U,gBAAgB;AAChB,gGAAgG;AAChG,kBAAkB;AAClB,sBAAsB;AACtB,sBAAsB;AACtB,EAAE;AACF,mBAAmB;AACnB,wFAAwF;AACxF,+FAA+F;AAC/F,0FAA0F;AAC1F,gGAAgG;AAChG,6FAA6F;AAC7F,iGAAiG;AACjG,iIAAiI;AACjI,yFAAyF;AACzF,iGAAiG;AACjG,uEAAuE;AACvE,kGAAkG;AAClG,2FAA2F;AAC3F,wFAAwF;AACxF,qHAAqH;AACrH,iBAAiB;AACjB,EAAE;AACF,uBAAuB;AACvB,k1BAAk1B;AACl1B,qBAAqB;AA6CrB,gDAAgD;AAChD,sFAAsF;AACtF,uDAAuD;AACvD,kFAAkF;AAClF,uEAAuE;AACvE,oEAAoE;AACpE,+EAA+E;AAC/E,8EAA8E;AAC9E,gFAAgF;AAChF,iFAAiF;AACjF,uFAAuF;AACvF,kEAAkE;AAClE,2EAA2E;AAC3E,MAAM,qBAAqB,GAAG,+CAA+C,CAAC;AAC9E,MAAM,kBAAkB,GAAG,4DAA4D,CAAC;AACxF,MAAM,4BAA4B,GAAG,uDAAuD,CAAC;AAC7F,MAAM,6BAA6B,GACjC,iEAAiE,CAAC;A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E,EAAE,EAAE,IAAI,EAAE,CAAC;AACtB,CAAC"}
@@ -197,7 +197,7 @@ export type AuthorizeReworkResult = {
197
197
  grantedAttempts: number;
198
198
  } | {
199
199
  ok: false;
200
- errorCode: "RUN_NOT_FOUND" | "SESSION_MISMATCH" | "CHECKPOINT_NOT_FOUND" | "RUN_SEALED" | "CHECKPOINT_NOT_FAILED" | "HARD_STOP_CHECKPOINT" | "TASK_NOT_COVERED" | "WORK_ITEM_NOT_BOUND" | "REWORK_REJECTED";
200
+ errorCode: "RUN_NOT_FOUND" | "SESSION_MISMATCH" | "CHECKPOINT_NOT_FOUND" | "RUN_SEALED" | "CHECKPOINT_NOT_FAILED" | "HARD_STOP_CHECKPOINT" | "TASK_NOT_COVERED" | "WORK_ITEM_NOT_BOUND" | "NOT_ACCEPTED" | "STALE_ATTEMPT" | "REWORK_REJECTED";
201
201
  message: string;
202
202
  };
203
203
  export interface AuthorizeReworkInput {
@@ -206,6 +206,12 @@ export interface AuthorizeReworkInput {
206
206
  checkpointId: string;
207
207
  workItemId: string;
208
208
  reason: string;
209
+ /**
210
+ * Public attempt identity the caller believes is the accepted result to
211
+ * reopen. When provided it must match the item's current accepted attempt so
212
+ * a stale attempt number can never silently target a newer accepted result.
213
+ */
214
+ attempt?: number;
209
215
  }
210
216
  export declare function authorizeReworkFromFailedCheckpoint(store: WorkItemStore, input: AuthorizeReworkInput): AuthorizeReworkResult;
211
217
  export declare function authorizeReworkFromFailedCheckpointInStore(data: WorkItemStoreData, input: AuthorizeReworkInput): AuthorizeReworkResult;