@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,174 +0,0 @@
1
- // FILE: src/plugins/v2-runtime/setup.ts
2
- // VERSION: 1.1.0
3
- // START_MODULE_CONTRACT
4
- // PURPOSE: Dispatch the v2 setup(ctx) entry for the package root across the vvoc server plugins through a shared adapter carrying per-location config resolution and config watching.
5
- // SCOPE: Central v2 registration seam: the adapter context (plugin context, location resolver, config watch helper), the ordered plugin setup registry, full-v2-context feature detection, per-plugin error isolation, and aggregated reverse-order cleanup disposal.
6
- // DEPENDS: [@opencode/plugin, src/plugins/v2-runtime/location-config.ts, src/plugins/v2-runtime/config-watcher.ts]
7
- // LINKS: [M-PLUGIN-V2-RUNTIME, V-M-PLUGIN-V2-RUNTIME]
8
- // ROLE: RUNTIME
9
- // MAP_MODE: EXPORTS
10
- // END_MODULE_CONTRACT
11
- //
12
- // START_MODULE_MAP
13
- // setupV2Plugins - Run the v2 registrations for every vvoc server plugin against one full OpenCode v2 plugin context and return one aggregated cleanup; no-ops under the v1 v2-bridge host where the v1 runtime already calls server().
14
- // V2_PLUGIN_SETUPS - Ordered registry of per-plugin v2 setup functions extended by later migration tasks.
15
- // V2AdapterContext - Plugin context plus the location resolver and multiplexed config watcher shared by all vvoc plugins.
16
- // createV2Adapter - Build the shared adapter context with the location resolver and multiplexed config watcher.
17
- // isFullV2Context - Feature-detect whether a setup context carries the full OpenCode v2 domain set.
18
- // END_MODULE_MAP
19
- //
20
- // START_CHANGE_SUMMARY
21
- // LAST_CHANGE: [C-OPENCODE-V2-MIGRATION T-002 - Plugin setups now receive the shared adapter context with per-location config resolution and config watching.]
22
- // END_CHANGE_SUMMARY
23
- import { createLocationResolver } from "./location-config.js";
24
- import { watchProjectVvocConfig } from "./config-watcher.js";
25
- import { setupAnalyticsV2 } from "../analytics/v2.js";
26
- import { setupSystemContextInjectionV2 } from "../system-context-injection/v2.js";
27
- import { setupModelRolesV2 } from "../model-roles/v2.js";
28
- import { setupToolHistoryCompactionV2 } from "../tool-history-compaction/v2.js";
29
- import { setupSpecGuardV2 } from "../spec-guard/v2.js";
30
- import { setupSecretsRedactionV2 } from "../secrets-redaction/v2.js";
31
- import { setupPeakHoursV2 } from "../peak-hours/v2.js";
32
- import { setupWebToolsV2 } from "../web-tools/v2.js";
33
- import { setupHashlineEditV2 } from "../hashline-edit/v2.js";
34
- import { setupGuardianV2 } from "../guardian/v2.js";
35
- import { setupWorkflowV2 } from "../workflow/v2.js";
36
- // END_BLOCK_V2_ADAPTER_CONTEXT
37
- // START_BLOCK_V2_PLUGIN_SETUPS
38
- /**
39
- * Per-plugin v2 setup functions in the canonical v1 plugin order. Migration
40
- * tasks append entries as each plugin gains its v2 registration.
41
- */
42
- export const V2_PLUGIN_SETUPS = [
43
- { name: "analytics", setup: (adapter) => setupAnalyticsV2(adapter) },
44
- { name: "system-context-injection", setup: (adapter) => setupSystemContextInjectionV2(adapter) },
45
- { name: "model-roles", setup: (adapter) => setupModelRolesV2(adapter) },
46
- { name: "tool-history-compaction", setup: (adapter) => setupToolHistoryCompactionV2(adapter) },
47
- { name: "spec-guard", setup: (adapter) => setupSpecGuardV2(adapter) },
48
- { name: "secrets-redaction", setup: (adapter) => setupSecretsRedactionV2(adapter) },
49
- { name: "peak-hours", setup: (adapter) => setupPeakHoursV2(adapter) },
50
- { name: "web-tools", setup: (adapter) => setupWebToolsV2(adapter) },
51
- { name: "hashline-edit", setup: (adapter) => setupHashlineEditV2(adapter) },
52
- { name: "guardian", setup: (adapter) => setupGuardianV2(adapter) },
53
- { name: "workflow", setup: (adapter) => setupWorkflowV2(adapter) },
54
- ];
55
- // END_BLOCK_V2_PLUGIN_SETUPS
56
- // START_BLOCK_IS_FULL_V2_CONTEXT
57
- /**
58
- * OpenCode v1 (>= 1.18.29) also invokes setup() on dual entrypoints through
59
- * its reduced v2 bridge host, whose context only carries the agent, aisdk,
60
- * catalog, command, integration, plugin, reference, and skill domains. The
61
- * full OpenCode v2 context additionally carries app, location, event, model,
62
- * provider, session, storage, tool, and the remaining runtime domains. Probe
63
- * verified against OpenCode 1.18.32: the v1 bridge lacks tool, session, event,
64
- * storage, app, and location, so their presence distinguishes the runtimes.
65
- */
66
- export function isFullV2Context(context) {
67
- const probe = context;
68
- return ("tool" in probe &&
69
- "session" in probe &&
70
- "event" in probe &&
71
- "storage" in probe &&
72
- "app" in probe &&
73
- "location" in probe);
74
- }
75
- // END_BLOCK_IS_FULL_V2_CONTEXT
76
- // START_BLOCK_CREATE_ADAPTER
77
- /**
78
- * Build the shared adapter for one plugin context: a per-location config
79
- * resolver and a config watcher multiplexer that keeps one filesystem watch
80
- * per directory regardless of how many plugins subscribe to that directory.
81
- */
82
- export function createV2Adapter(context) {
83
- const resolver = createLocationResolver();
84
- const subscriptions = new Map();
85
- const activeWatches = new Map();
86
- async function ensureWatched(directory) {
87
- if (activeWatches.has(directory))
88
- return;
89
- const listeners = subscriptions.get(directory);
90
- if (!listeners || listeners.size === 0)
91
- return;
92
- const stopWatch = await watchProjectVvocConfig(directory, () => {
93
- resolver.invalidate(directory);
94
- for (const listener of listeners.values()) {
95
- try {
96
- listener();
97
- }
98
- catch (error) {
99
- console.warn(`[vvoc][v2-runtime] config listener failed for ${directory}: ${String(error)}`);
100
- }
101
- }
102
- });
103
- activeWatches.set(directory, stopWatch);
104
- }
105
- return {
106
- ctx: context,
107
- resolver,
108
- async watchConfig(directory, onChange) {
109
- const key = Symbol("vvoc-config-listener");
110
- let listeners = subscriptions.get(directory);
111
- if (!listeners) {
112
- listeners = new Map();
113
- subscriptions.set(directory, listeners);
114
- }
115
- listeners.set(key, onChange);
116
- await ensureWatched(directory);
117
- let stopped = false;
118
- return () => {
119
- if (stopped)
120
- return;
121
- stopped = true;
122
- const current = subscriptions.get(directory);
123
- if (!current)
124
- return;
125
- current.delete(key);
126
- if (current.size === 0) {
127
- subscriptions.delete(directory);
128
- const stopWatch = activeWatches.get(directory);
129
- if (stopWatch) {
130
- activeWatches.delete(directory);
131
- stopWatch();
132
- }
133
- }
134
- };
135
- },
136
- };
137
- }
138
- // END_BLOCK_CREATE_ADAPTER
139
- // START_BLOCK_SETUP_V2_PLUGINS
140
- /**
141
- * Run every registered v2 plugin setup against the adapter, isolating failures
142
- * per plugin, and return one cleanup that disposes the successful cleanups in
143
- * reverse registration order.
144
- *
145
- * Under the v1 v2-bridge host this returns without registering anything: the
146
- * same entrypoint's server() member already provides the v1 behavior, so the
147
- * package never registers twice inside one OpenCode v1 process.
148
- */
149
- export async function setupV2Plugins(context) {
150
- if (!isFullV2Context(context))
151
- return undefined;
152
- const adapter = createV2Adapter(context);
153
- const cleanups = [];
154
- for (const entry of V2_PLUGIN_SETUPS) {
155
- try {
156
- const cleanup = await entry.setup(adapter);
157
- if (typeof cleanup === "function") {
158
- cleanups.push(cleanup);
159
- }
160
- }
161
- catch (error) {
162
- console.error(`[vvoc][v2-runtime] plugin ${entry.name} failed to load: ${String(error)}`);
163
- }
164
- }
165
- if (cleanups.length === 0)
166
- return undefined;
167
- return async () => {
168
- for (const cleanup of cleanups.reverse()) {
169
- await cleanup();
170
- }
171
- };
172
- }
173
- // END_BLOCK_SETUP_V2_PLUGINS
174
- //# sourceMappingURL=setup.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"setup.js","sourceRoot":"","sources":["../../../src/plugins/v2-runtime/setup.ts"],"names":[],"mappings":"AAAA,wCAAwC;AACxC,iBAAiB;AACjB,wBAAwB;AACxB,wLAAwL;AACxL,wQAAwQ;AACxQ,qHAAqH;AACrH,wDAAwD;AACxD,kBAAkB;AAClB,sBAAsB;AACtB,sBAAsB;AACtB,EAAE;AACF,mBAAmB;AACnB,0OAA0O;AAC1O,4GAA4G;AAC5G,4HAA4H;AAC5H,kHAAkH;AAClH,sGAAsG;AACtG,iBAAiB;AACjB,EAAE;AACF,uBAAuB;AACvB,iKAAiK;AACjK,qBAAqB;AAGrB,OAAO,EAAE,sBAAsB,EAAyB,MAAM,sBAAsB,CAAC;AACrF,OAAO,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,KAAK,CAAC,EAAE,CAAC,CAAC;QAC5F,CAAC;IACH,CAAC;IACD,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,SAAS,CAAC;IAC5C,OAAO,KAAK,IAAI,EAAE;QAChB,KAAK,MAAM,OAAO,IAAI,QAAQ,CAAC,OAAO,EAAE,EAAE,CAAC;YACzC,MAAM,OAAO,EAAE,CAAC;QAClB,CAAC;IACH,CAAC,CAAC;AACJ,CAAC;AACD,6BAA6B"}
@@ -1,11 +0,0 @@
1
- import type { Plugin as V2Plugin } from "@opencode/plugin";
2
- import type { V2AdapterContext } from "../v2-runtime/setup.js";
3
- /**
4
- * Register the web tools on the v2 runtime.
5
- *
6
- * A later valid tool registration overrides the same effective name, so
7
- * registering web_search and web_fetch replaces the OpenCode built-ins while
8
- * the plugin is enabled and disposing the registration restores them, which
9
- * replaces the v1 config-hook builtin suppression.
10
- */
11
- export declare function setupWebToolsV2(adapter: V2AdapterContext): Promise<V2Plugin.Cleanup | void>;
@@ -1,99 +0,0 @@
1
- // FILE: src/plugins/web-tools/v2.ts
2
- // VERSION: 1.0.0
3
- // START_MODULE_CONTRACT
4
- // PURPOSE: Register the canonical web_search and web_fetch tools on the OpenCode v2 runtime, overriding the built-ins while the plugin is enabled.
5
- // SCOPE: v2 setup only: publish both owned tools with their strict JSON Schema inputs through the tool transform, adapt the shared executors to the v2 executor contract with cooperative cancellation through the context signal, resolve credentials per plugin-load location, and leave unowned tool ids untouched.
6
- // DEPENDS: [@opencode/plugin, src/lib/agent-tool-contract.ts, src/lib/config-layers.ts, src/plugins/web-tools/config.ts, src/plugins/web-tools/fetch-service.ts, src/plugins/web-tools/schemas.ts, src/plugins/web-tools/search-service.ts, src/plugins/v2-runtime/setup.ts]
7
- // LINKS: [M-PLUGIN-WEB-TOOLS, V-M-PLUGIN-WEB-TOOLS, M-PLUGIN-V2-RUNTIME]
8
- // ROLE: RUNTIME
9
- // MAP_MODE: EXPORTS
10
- // END_MODULE_CONTRACT
11
- //
12
- // START_MODULE_MAP
13
- // setupWebToolsV2 - Register both web tools for one OpenCode v2 plugin context.
14
- // END_MODULE_MAP
15
- //
16
- // START_CHANGE_SUMMARY
17
- // LAST_CHANGE: [C-OPENCODE-V2-MIGRATION T-004 - Ported web tools onto the v2 tool transform with built-in override semantics.]
18
- // END_CHANGE_SUMMARY
19
- import { loadVvocConfigForRead } from "../../lib/config-layers.js";
20
- import { isVvocPluginEnabled } from "../../lib/plugin-toggle-config.js";
21
- import { resolveWebRuntimeConfig } from "./config.js";
22
- import { createWebFetchTool } from "./fetch-service.js";
23
- import { createWebSearchTool } from "./search-service.js";
24
- import { webToolContracts } from "./schemas.js";
25
- // START_BLOCK_ADAPT_V1_EXECUTOR
26
- /**
27
- * Adapt one v1 tool executor invocation to the v2 Tool.Result shape.
28
- *
29
- * The v1 executors validate their own arguments, ask for permission through
30
- * the v1 ask() surface (v2 gates these tools through session permission rules
31
- * instead), and return { title, output, metadata }; the adapter forwards the
32
- * cancellation signal and maps the output to the v2 content string.
33
- */
34
- function adaptV1Executor(execute) {
35
- return async (input, context) => {
36
- const result = (await execute(input, {
37
- ask: async () => { },
38
- abort: context.signal,
39
- }));
40
- if (typeof result === "string") {
41
- return { content: result };
42
- }
43
- return {
44
- ...(result?.title ? { title: result.title } : {}),
45
- content: result?.output ?? "",
46
- ...(result?.metadata ? { metadata: result.metadata } : {}),
47
- };
48
- };
49
- }
50
- // END_BLOCK_ADAPT_V1_EXECUTOR
51
- // START_BLOCK_SETUP_WEB_TOOLS_V2
52
- /**
53
- * Register the web tools on the v2 runtime.
54
- *
55
- * A later valid tool registration overrides the same effective name, so
56
- * registering web_search and web_fetch replaces the OpenCode built-ins while
57
- * the plugin is enabled and disposing the registration restores them, which
58
- * replaces the v1 config-hook builtin suppression.
59
- */
60
- export async function setupWebToolsV2(adapter) {
61
- const directory = adapter.ctx.location.directory;
62
- const read = await loadVvocConfigForRead({
63
- cwd: directory,
64
- scope: "effective",
65
- allowDefault: true,
66
- });
67
- if (!isVvocPluginEnabled(read.config, "web-tools"))
68
- return undefined;
69
- const resolved = resolveWebRuntimeConfig({
70
- config: read.config,
71
- source: read.source,
72
- warnings: read.warnings,
73
- });
74
- const searchContract = webToolContracts.find((contract) => contract.toolId === "web_search");
75
- const fetchContract = webToolContracts.find((contract) => contract.toolId === "web_fetch");
76
- if (!searchContract || !fetchContract) {
77
- console.error("[vvoc][web-tools] owned tool contracts missing; v2 registration skipped");
78
- return undefined;
79
- }
80
- const searchTool = createWebSearchTool(resolved.search);
81
- const fetchTool = createWebFetchTool(resolved.fetch);
82
- const registration = await adapter.ctx.tool.transform((editor) => {
83
- editor.add({
84
- name: "web_search",
85
- description: "Search the web with the configured provider and return ranked results.",
86
- input: searchContract.inputJsonSchema,
87
- execute: adaptV1Executor(searchTool.execute),
88
- });
89
- editor.add({
90
- name: "web_fetch",
91
- description: "Fetch one URL and return its content as markdown.",
92
- input: fetchContract.inputJsonSchema,
93
- execute: adaptV1Executor(fetchTool.execute),
94
- });
95
- });
96
- return () => registration.dispose();
97
- }
98
- // END_BLOCK_SETUP_WEB_TOOLS_V2
99
- //# sourceMappingURL=v2.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"v2.js","sourceRoot":"","sources":["../../../src/plugins/web-tools/v2.ts"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,iBAAiB;AACjB,wBAAwB;AACxB,qJAAqJ;AACrJ,yTAAyT;AACzT,+QAA+Q;AAC/Q,2EAA2E;AAC3E,kBAAkB;AAClB,sBAAsB;AACtB,sBAAsB;AACtB,EAAE;AACF,mBAAmB;AACnB,kFAAkF;AAClF,iBAAiB;AACjB,EAAE;AACF,uBAAuB;AACvB,iIAAiI;AACjI,qBAAqB;AAIrB,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AACxE,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;A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AgB,CAAU;SAC9D,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,OAAO,EAAE,CAAC;AACtC,CAAC;AACD,+BAA+B"}
@@ -1,76 +0,0 @@
1
- import type { Plugin as V2Plugin } from "@opencode/plugin";
2
- import type { V2AdapterContext } from "../v2-runtime/setup.js";
3
- /**
4
- * A v1-shaped client built on v2 domains. Session lookups map onto
5
- * ctx.session, logging degrades to console, and the repair continuation
6
- * prompt is unsupported under the v2 prompt shape and throws so the
7
- * bounded continuation path fails closed exactly like a failed continuation.
8
- */
9
- export declare function createWorkflowClientShim(adapter: V2AdapterContext): {
10
- app: {
11
- log: () => Promise<void>;
12
- };
13
- session: {
14
- get: (input: {
15
- path: {
16
- id: string;
17
- };
18
- }) => Promise<{
19
- data: import("@opencode/client").SessionInfo;
20
- }>;
21
- message: (input: {
22
- path: {
23
- id: string;
24
- messageID: string;
25
- };
26
- }) => Promise<{
27
- data: {
28
- id?: string;
29
- };
30
- error?: undefined;
31
- } | {
32
- data: undefined;
33
- error: {
34
- name: string;
35
- };
36
- }>;
37
- prompt: (_input: unknown) => Promise<never>;
38
- };
39
- };
40
- /**
41
- * Map v2 subagent launch arguments onto the v1 task shape the launch
42
- * validation consumes: agent becomes subagent_type, the v2 resume sessionID
43
- * becomes task_id, and background passes through. The v1 reader fields stay
44
- * authoritative so every eligibility rule applies unchanged.
45
- */
46
- export declare function adaptSubagentLaunchArgs(input: unknown): unknown;
47
- /**
48
- * Translate one v2 server event into the v1 event shape the shared workflow
49
- * event handler consumes, or undefined when the event carries no workflow
50
- * meaning.
51
- *
52
- * Mappings (verified against the v2 event schemas):
53
- * - session.inbox.enqueued with a user item becomes message.updated with a
54
- * user message info, driving child-prompt freshness observation.
55
- * - session.tool.failed and session.tool.progress become message.part.updated
56
- * task-tool part states, driving live delegated binding taints and the
57
- * confirmed host-terminal-error failed-attempt path; the binding lookup
58
- * inside the handler stays fail-closed for unmatched identities.
59
- * - session.deleted maps directly, driving store and persistence cleanup.
60
- */
61
- export declare function mapV2EventToV1Shape(event: unknown): {
62
- type: string;
63
- properties: Record<string, unknown>;
64
- } | undefined;
65
- /**
66
- * Bridge the workflow surface onto the v2 runtime.
67
- *
68
- * The v1 factory runs once with the shimmed client; its returned hook object
69
- * is routed onto v2 domains: tools publish with their strict JSON Schema
70
- * inputs, before and after guards run as v2 tool hooks with the launcher
71
- * renamed from task to subagent, and the profile guidance appends through
72
- * the session context hook. Protocol parsing stays fail-closed: envelope
73
- * shapes the shared parser does not recognize reject the attempt, never
74
- * accept it.
75
- */
76
- export declare function setupWorkflowV2(adapter: V2AdapterContext): Promise<V2Plugin.Cleanup | void>;
@@ -1,283 +0,0 @@
1
- // FILE: src/plugins/workflow/v2.ts
2
- // VERSION: 1.0.0
3
- // START_MODULE_CONTRACT
4
- // PURPOSE: Run the complete workflow enforcement surface on the OpenCode v2 runtime by bridging the v1 plugin factory's hooks and tools onto v2 domains.
5
- // SCOPE: v2 setup only: instantiate the v1 factory once with a shimmed client, register its five tools with their strict JSON Schema inputs through the tool transform, route execute.before and execute.after through v2 tool hooks with subagent-launch argument adaptation (v2 names the launcher subagent with agent and sessionID fields), append the profile guidance through the session context hook, and keep every fail-closed guarantee of the shared protocol unchanged.
6
- // DEPENDS: [@opencode/plugin, src/lib/config-layers.ts, src/plugins/workflow/index.ts, src/plugins/v2-runtime/setup.ts]
7
- // LINKS: [M-PLUGIN-WORKFLOW, V-M-PLUGIN-WORKFLOW, M-WORKFLOW-PROTOCOL, M-PLUGIN-V2-RUNTIME]
8
- // ROLE: RUNTIME
9
- // MAP_MODE: EXPORTS
10
- // END_MODULE_CONTRACT
11
- //
12
- // START_MODULE_MAP
13
- // setupWorkflowV2 - Bridge the full workflow surface onto one OpenCode v2 plugin context.
14
- // createWorkflowClientShim - v1-shaped client over v2 domains for the workflow authorization and repair surfaces.
15
- // adaptSubagentLaunchArgs - Map v2 subagent tool arguments onto the v1 task launch shape.
16
- // mapV2EventToV1Shape - Translate v2 server events into the v1 event shapes the shared handler consumes.
17
- // END_MODULE_MAP
18
- //
19
- // START_CHANGE_SUMMARY
20
- // LAST_CHANGE: [C-OPENCODE-V2-MIGRATION T-005 - Bridged the workflow enforcement surface onto v2 tool, session, and event domains.]
21
- // END_CHANGE_SUMMARY
22
- import { WorkflowPlugin } from "./index.js";
23
- // START_BLOCK_CREATE_WORKFLOW_CLIENT_SHIM
24
- /**
25
- * A v1-shaped client built on v2 domains. Session lookups map onto
26
- * ctx.session, logging degrades to console, and the repair continuation
27
- * prompt is unsupported under the v2 prompt shape and throws so the
28
- * bounded continuation path fails closed exactly like a failed continuation.
29
- */
30
- export function createWorkflowClientShim(adapter) {
31
- return {
32
- app: {
33
- log: async () => { },
34
- },
35
- session: {
36
- get: async (input) => {
37
- const data = await adapter.ctx.session.get({ sessionID: input.path.id });
38
- return { data };
39
- },
40
- message: async (input) => {
41
- try {
42
- const messages = await adapter.ctx.session.context({ sessionID: input.path.id });
43
- const hit = messages.find((message) => message.id === input.path.messageID);
44
- return hit ? { data: hit } : { data: undefined, error: { name: "NotFound" } };
45
- }
46
- catch {
47
- return { data: undefined, error: { name: "NotFound" } };
48
- }
49
- },
50
- prompt: async (_input) => {
51
- throw new Error("workflow continuation prompt is not available on the v2 runtime");
52
- },
53
- },
54
- };
55
- }
56
- // END_BLOCK_CREATE_WORKFLOW_CLIENT_SHIM
57
- // START_BLOCK_ADAPT_SUBAGENT_LAUNCH_ARGS
58
- /**
59
- * Map v2 subagent launch arguments onto the v1 task shape the launch
60
- * validation consumes: agent becomes subagent_type, the v2 resume sessionID
61
- * becomes task_id, and background passes through. The v1 reader fields stay
62
- * authoritative so every eligibility rule applies unchanged.
63
- */
64
- export function adaptSubagentLaunchArgs(input) {
65
- if (!input || typeof input !== "object")
66
- return input;
67
- const record = input;
68
- return {
69
- ...record,
70
- ...(typeof record.agent === "string" ? { subagent_type: record.agent } : {}),
71
- ...(typeof record.sessionID === "string" ? { task_id: record.sessionID } : {}),
72
- };
73
- }
74
- // END_BLOCK_ADAPT_SUBAGENT_LAUNCH_ARGS
75
- // START_BLOCK_MAP_V2_EVENT_TO_V1_SHAPES
76
- /**
77
- * Translate one v2 server event into the v1 event shape the shared workflow
78
- * event handler consumes, or undefined when the event carries no workflow
79
- * meaning.
80
- *
81
- * Mappings (verified against the v2 event schemas):
82
- * - session.inbox.enqueued with a user item becomes message.updated with a
83
- * user message info, driving child-prompt freshness observation.
84
- * - session.tool.failed and session.tool.progress become message.part.updated
85
- * task-tool part states, driving live delegated binding taints and the
86
- * confirmed host-terminal-error failed-attempt path; the binding lookup
87
- * inside the handler stays fail-closed for unmatched identities.
88
- * - session.deleted maps directly, driving store and persistence cleanup.
89
- */
90
- export function mapV2EventToV1Shape(event) {
91
- const typed = event;
92
- const data = typed?.data ?? {};
93
- switch (typed?.type) {
94
- case "session.inbox.enqueued": {
95
- const item = data.item;
96
- if (item?.type === "user" &&
97
- typeof item.sessionID === "string" &&
98
- typeof item.id === "string") {
99
- return {
100
- type: "message.updated",
101
- properties: { info: { role: "user", sessionID: item.sessionID, id: item.id } },
102
- };
103
- }
104
- return undefined;
105
- }
106
- case "session.tool.failed":
107
- case "session.tool.progress": {
108
- const sessionID = typeof data.sessionID === "string" ? data.sessionID : undefined;
109
- const callID = typeof data.id === "string" ? data.id : undefined;
110
- if (!sessionID || !callID)
111
- return undefined;
112
- const isError = typed.type === "session.tool.failed";
113
- const metadata = data.metadata && typeof data.metadata === "object"
114
- ? data.metadata
115
- : undefined;
116
- const rawError = data.error;
117
- const errorText = typeof rawError === "string"
118
- ? rawError
119
- : rawError && typeof rawError.message === "string"
120
- ? rawError.message
121
- : undefined;
122
- return {
123
- type: "message.part.updated",
124
- properties: {
125
- part: {
126
- type: "tool",
127
- tool: "task",
128
- sessionID,
129
- callID,
130
- state: {
131
- status: isError ? "error" : "running",
132
- ...(errorText !== undefined ? { error: errorText } : {}),
133
- ...(metadata ? { metadata } : {}),
134
- },
135
- },
136
- },
137
- };
138
- }
139
- case "session.deleted": {
140
- if (typeof data.sessionID !== "string")
141
- return undefined;
142
- return { type: "session.deleted", properties: { sessionID: data.sessionID } };
143
- }
144
- default:
145
- return undefined;
146
- }
147
- }
148
- // END_BLOCK_MAP_V2_EVENT_TO_V1_SHAPES
149
- // START_BLOCK_SETUP_WORKFLOW_V2
150
- /**
151
- * Bridge the workflow surface onto the v2 runtime.
152
- *
153
- * The v1 factory runs once with the shimmed client; its returned hook object
154
- * is routed onto v2 domains: tools publish with their strict JSON Schema
155
- * inputs, before and after guards run as v2 tool hooks with the launcher
156
- * renamed from task to subagent, and the profile guidance appends through
157
- * the session context hook. Protocol parsing stays fail-closed: envelope
158
- * shapes the shared parser does not recognize reject the attempt, never
159
- * accept it.
160
- */
161
- export async function setupWorkflowV2(adapter) {
162
- const directory = adapter.ctx.location.directory;
163
- const hooks = (await WorkflowPlugin({
164
- client: createWorkflowClientShim(adapter),
165
- project: { id: directory, directory },
166
- directory,
167
- worktree: directory,
168
- experimental_workspace: { register: () => { } },
169
- serverUrl: new URL("http://127.0.0.1:1"),
170
- $: {},
171
- }));
172
- if (!hooks)
173
- return undefined;
174
- const cleanups = [];
175
- // Tools: publish each v1 tool entry with its contract JSON Schema input.
176
- const toolEntries = (hooks.tool ?? {});
177
- const { workflowToolContracts } = await import("./input-validation.js");
178
- const toolRegistration = await adapter.ctx.tool.transform((editor) => {
179
- for (const [name, entry] of Object.entries(toolEntries)) {
180
- const contract = workflowToolContracts.find((item) => item.toolId === name);
181
- editor.add({
182
- name,
183
- description: entry.description,
184
- input: (contract?.inputJsonSchema ?? { type: "object" }),
185
- execute: (async (input, context) => {
186
- const result = await entry.execute(input, {
187
- sessionID: context.sessionID,
188
- agent: context.agent,
189
- abort: context.signal,
190
- });
191
- return { content: typeof result === "string" ? result : JSON.stringify(result) };
192
- }),
193
- });
194
- }
195
- });
196
- cleanups.push(() => toolRegistration.dispose());
197
- // Owned validation plus task-launch tracking on execute.before.
198
- const beforeHook = await adapter.ctx.tool.hook("execute.before", (event) => {
199
- const tool = String(event.tool) === "subagent" ? "task" : String(event.tool);
200
- const args = String(event.tool) === "subagent" ? adaptSubagentLaunchArgs(event.input) : event.input;
201
- const before = hooks["tool.execute.before"];
202
- if (!before)
203
- return;
204
- return before({ tool, sessionID: event.sessionID, callID: event.id, agent: event.agent }, { args });
205
- });
206
- cleanups.push(() => beforeHook.dispose());
207
- // Delegated result tracking on execute.after.
208
- const afterHook = await adapter.ctx.tool.hook("execute.after", (event) => {
209
- if (event.status !== "completed")
210
- return;
211
- const tool = String(event.tool) === "subagent" ? "task" : String(event.tool);
212
- const args = String(event.tool) === "subagent" ? adaptSubagentLaunchArgs(event.input) : event.input;
213
- const result = event.result;
214
- const output = typeof result.content === "string"
215
- ? result.content
216
- : Array.isArray(result.content)
217
- ? result.content.map((part) => part.text ?? "").join("\n")
218
- : "";
219
- const after = hooks["tool.execute.after"];
220
- if (!after)
221
- return;
222
- return after({ tool, sessionID: event.sessionID, callID: event.id, agent: event.agent, args }, { output, metadata: {} });
223
- });
224
- cleanups.push(() => afterHook.dispose());
225
- // Profile guidance through the session context hook.
226
- const chatMessage = hooks["chat.message"];
227
- if (chatMessage) {
228
- const contextHook = await adapter.ctx.session.hook("context", (event) => {
229
- const message = {
230
- agent: event.agent,
231
- system: event.system
232
- .filter((part) => part.type === "text")
233
- .map((part) => part.text)
234
- .join("\n\n"),
235
- };
236
- const before = message.system;
237
- const result = chatMessage({}, { message });
238
- if (result instanceof Promise) {
239
- return result.then(() => {
240
- if (typeof message.system === "string" && message.system !== before) {
241
- event.system.length = 0;
242
- event.system.push({ type: "text", text: message.system });
243
- }
244
- });
245
- }
246
- return undefined;
247
- });
248
- cleanups.push(() => contextHook.dispose());
249
- }
250
- // Event bridge: route the v2 server events the shared handler consumes.
251
- const eventHandler = hooks.event;
252
- if (eventHandler) {
253
- const controller = new AbortController();
254
- void (async () => {
255
- try {
256
- for await (const evt of adapter.ctx.event.subscribe({ signal: controller.signal })) {
257
- const located = evt;
258
- if (located.location?.directory && located.location.directory !== directory)
259
- continue;
260
- const shaped = mapV2EventToV1Shape(evt);
261
- if (!shaped)
262
- continue;
263
- try {
264
- await eventHandler({ event: shaped });
265
- }
266
- catch (error) {
267
- console.warn(`[vvoc][workflow] bridged event failed: ${String(error)}`);
268
- }
269
- }
270
- }
271
- catch {
272
- // Stream failures never break the host.
273
- }
274
- })();
275
- cleanups.push(async () => controller.abort());
276
- }
277
- return async () => {
278
- for (const dispose of cleanups.reverse())
279
- await dispose();
280
- };
281
- }
282
- // END_BLOCK_SETUP_WORKFLOW_V2
283
- //# sourceMappingURL=v2.js.map