@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,56 +0,0 @@
1
- // FILE: src/plugins/tool-history-compaction/v2.ts
2
- // VERSION: 1.0.0
3
- // START_MODULE_CONTRACT
4
- // PURPOSE: Register tool-history compaction on the OpenCode v2 session context hook with per-session location resolution.
5
- // SCOPE: v2 setup only: gate on the per-location plugin toggle, rewrite only the in-memory message copy the model is about to receive through the shared pure compactMessages transform, and stay fail-soft on handler errors.
6
- // DEPENDS: [@opencode/plugin, src/lib/config-layers.ts, src/plugins/tool-history-compaction/config.ts, src/plugins/tool-history-compaction/transform.ts, src/plugins/v2-runtime/setup.ts]
7
- // LINKS: [M-PLUGIN-TOOL-HISTORY-COMPACTION, V-M-PLUGIN-TOOL-HISTORY-COMPACTION, M-PLUGIN-V2-RUNTIME]
8
- // ROLE: RUNTIME
9
- // MAP_MODE: EXPORTS
10
- // END_MODULE_CONTRACT
11
- //
12
- // START_MODULE_MAP
13
- // setupToolHistoryCompactionV2 - Register the compaction context hook 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 tool-history compaction onto the v2 session context hook.]
18
- // END_CHANGE_SUMMARY
19
- import { parseToolHistoryCompactionEntry } from "./config.js";
20
- import { compactMessages } from "./transform.js";
21
- // START_BLOCK_SETUP_TOOL_HISTORY_COMPACTION_V2
22
- /**
23
- * Register the compaction hook on the v2 runtime.
24
- *
25
- * The v1 experimental.chat.messages.transform becomes the v2 session context
26
- * hook, which owns the mutable message copy for the outgoing model request.
27
- * Enablement resolves per session location so one shared server can host
28
- * projects with different compaction settings.
29
- */
30
- export async function setupToolHistoryCompactionV2(adapter) {
31
- const registration = await adapter.ctx.session.hook("context", async (event) => {
32
- try {
33
- const snapshot = await adapter.resolver.forSession(event.sessionID, (input) => adapter.ctx.session.get(input));
34
- if (!snapshot)
35
- return;
36
- const entry = parseToolHistoryCompactionEntry(snapshot.config.plugins?.["tool-history-compaction"]);
37
- if (!entry.enabled)
38
- return;
39
- const messages = event.messages;
40
- const adapted = messages.map((message) => ({
41
- info: message,
42
- parts: (message.parts ?? []),
43
- }));
44
- compactMessages(adapted, entry.config);
45
- for (const [index, message] of messages.entries()) {
46
- message.parts = adapted[index]?.parts;
47
- }
48
- }
49
- catch (error) {
50
- console.warn(`[vvoc][tool-history-compaction] context hook failed: ${String(error)}`);
51
- }
52
- });
53
- return () => registration.dispose();
54
- }
55
- // END_BLOCK_SETUP_TOOL_HISTORY_COMPACTION_V2
56
- //# sourceMappingURL=v2.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"v2.js","sourceRoot":"","sources":["../../../src/plugins/tool-history-compaction/v2.ts"],"names":[],"mappings":"AAAA,kDAAkD;AAClD,iBAAiB;AACjB,wBAAwB;AACxB,4HAA4H;AAC5H,iOAAiO;AACjO,4LAA4L;AAC5L,uGAAuG;AACvG,kBAAkB;AAClB,sBAAsB;AACtB,sBAAsB;AACtB,EAAE;AACF,mBAAmB;AACnB,4GAA4G;AAC5G,iBAAiB;AACjB,EAAE;AACF,uBAAuB;AACvB,oHAAoH;AACpH,qBAAqB;AAIrB,OAAO,EAAE,+BAA+B,EAAE,MAAM,aAAa,CAAC;AAC9D,OAAO,EAAE,eAAe,EAAyB,MAAM,gBAAgB,CAAC;AAExE,+CAA+C;AAC/C;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,4BAA4B,CAChD,OAAyB;IAEzB,MAAM,YAAY,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE;QAC7E,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAC,KAAK,CAAC,SAAmB,EAAE,CAAC,KAAK,EAAE,EAAE,CACtF,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAC/B,CAAC;YACF,IAAI,CAAC,QAAQ;gBAAE,OAAO;YACtB,MAAM,KAAK,GAAG,+BAA+B,CAC1C,QAAQ,CAAC,MAAM,CAAC,OAA+C,EAAE,CAChE,yBAAyB,CAC1B,CACF,CAAC;YACF,IAAI,CAAC,KAAK,CAAC,OAAO;gBAAE,OAAO;YAE3B,MAAM,QAAQ,GAAG,KAAK,CAAC,QAErB,CAAC;YACH,MAAM,OAAO,GAAuB,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;gBAC7D,IAAI,EAAE,OAAO;gBACb,KAAK,EAAE,CAAC,OAAO,CAAC,KAAK,IAAI,EAAE,CAA8B;aAC1D,CAAC,CAAC,CAAC;YACJ,eAAe,CAAC,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;YACvC,KAAK,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,IAAI,QAAQ,CAAC,OAAO,EAAE,EAAE,CAAC;gBAClD,OAAO,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,EAAE,KAAwC,CAAC;YAC3E,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,IAAI,CAAC,wDAAwD,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QACxF,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,OAAO,EAAE,CAAC;AACtC,CAAC;AACD,6CAA6C"}
@@ -1,26 +0,0 @@
1
- export interface WatcherRegistrationOptions {
2
- /** Injectable nearest-project config-path resolver for deterministic tests. */
3
- resolveProjectConfigPath?: (directory: string) => Promise<string | undefined>;
4
- /** Debounce window in milliseconds; defaults to 200. */
5
- debounceMs?: number;
6
- /** Injectable logger for non-fatal watcher diagnostics. */
7
- warn?: (message: string) => void;
8
- /** Injectable filesystem watch factory for deterministic tests. */
9
- createWatch?: (filePath: string, onEvent: () => void, onError: (error: unknown) => void) => {
10
- close: () => void;
11
- };
12
- }
13
- /**
14
- * Watch the project vvoc config effective for one directory.
15
- *
16
- * Resolves the nearest project config root the same way the layer engine
17
- * does, watches the config file's directory so atomic replace writes are
18
- * observed, debounces bursts, and invokes every callback with the resolved
19
- * config path. Callback errors are isolated per callback; watcher errors
20
- * degrade to a logged warning and stop notification for that directory.
21
- *
22
- * Returns a stop function that is safe to call multiple times. The function
23
- * itself never throws: a directory without a project config resolves to a
24
- * no-op watcher with the provided warn hook informed.
25
- */
26
- export declare function watchProjectVvocConfig(directory: string, onChange: (configPath: string) => void, options?: WatcherRegistrationOptions): Promise<() => void>;
@@ -1,111 +0,0 @@
1
- // FILE: src/plugins/v2-runtime/config-watcher.ts
2
- // VERSION: 1.0.0
3
- // START_MODULE_CONTRACT
4
- // PURPOSE: Watch a project's effective vvoc config file for changes and notify registered reload callbacks without restarting the OpenCode v2 server.
5
- // SCOPE: Watcher registration per directory with debounced change notification, callback error isolation, multiplexed subscriptions over one filesystem watch, and a returned stop function; never throws to the caller.
6
- // DEPENDS: [node:fs/promises, node:fs, src/lib/config-layers.ts]
7
- // LINKS: [M-PLUGIN-V2-RUNTIME, V-M-PLUGIN-V2-RUNTIME, M-CONFIG-LAYERS]
8
- // ROLE: RUNTIME
9
- // MAP_MODE: EXPORTS
10
- // END_MODULE_CONTRACT
11
- //
12
- // START_MODULE_MAP
13
- // WatcherRegistrationOptions - Injectable project-path resolution, debounce window, and logger for deterministic tests.
14
- // watchProjectVvocConfig - Watch one directory's project vvoc config and invoke callbacks on debounced changes until stopped.
15
- // END_MODULE_MAP
16
- //
17
- // START_CHANGE_SUMMARY
18
- // LAST_CHANGE: [C-OPENCODE-V2-MIGRATION T-002 - Created the debounced config watcher powering restart-free preset switching.]
19
- // END_CHANGE_SUMMARY
20
- import { watch } from "node:fs";
21
- import { basename, dirname } from "node:path";
22
- import { access } from "node:fs/promises";
23
- import { findNearestProjectConfigRoot } from "../../lib/config-layers.js";
24
- import { getProjectVvocConfigPath } from "../../lib/vvoc-paths.js";
25
- // END_BLOCK_WATCHER_OPTIONS
26
- // START_BLOCK_WATCH_PROJECT_VVOC_CONFIG
27
- /**
28
- * Watch the project vvoc config effective for one directory.
29
- *
30
- * Resolves the nearest project config root the same way the layer engine
31
- * does, watches the config file's directory so atomic replace writes are
32
- * observed, debounces bursts, and invokes every callback with the resolved
33
- * config path. Callback errors are isolated per callback; watcher errors
34
- * degrade to a logged warning and stop notification for that directory.
35
- *
36
- * Returns a stop function that is safe to call multiple times. The function
37
- * itself never throws: a directory without a project config resolves to a
38
- * no-op watcher with the provided warn hook informed.
39
- */
40
- export async function watchProjectVvocConfig(directory, onChange, options = {}) {
41
- const debounceMs = options.debounceMs ?? 200;
42
- const warn = options.warn ?? ((message) => console.warn(message));
43
- const resolveProjectConfigPath = options.resolveProjectConfigPath ??
44
- (async (dir) => {
45
- const root = await findNearestProjectConfigRoot(dir);
46
- if (root?.vvocConfigPath)
47
- return root.vvocConfigPath;
48
- // Watch the canonical project path even when absent so a later file
49
- // creation is observed.
50
- const canonical = getProjectVvocConfigPath(dir);
51
- try {
52
- await access(canonical);
53
- return canonical;
54
- }
55
- catch {
56
- return undefined;
57
- }
58
- });
59
- const createWatch = options.createWatch ??
60
- ((filePath, onEvent, onError) => {
61
- const watcher = watch(dirname(filePath), { persistent: false }, (_event, filename) => {
62
- if (!filename || filename === basename(filePath)) {
63
- onEvent();
64
- }
65
- });
66
- watcher.on("error", onError);
67
- return watcher;
68
- });
69
- const configPath = await resolveProjectConfigPath(directory);
70
- if (!configPath) {
71
- warn(`[vvoc][v2-runtime] no project vvoc config found for ${directory}; config watching disabled`);
72
- return () => { };
73
- }
74
- let stopped = false;
75
- let timer;
76
- const watcher = createWatch(configPath, () => {
77
- if (stopped)
78
- return;
79
- if (timer)
80
- clearTimeout(timer);
81
- timer = setTimeout(() => {
82
- timer = undefined;
83
- if (stopped)
84
- return;
85
- try {
86
- onChange(configPath);
87
- }
88
- catch (error) {
89
- warn(`[vvoc][v2-runtime] config change callback failed for ${configPath}: ${String(error)}`);
90
- }
91
- }, debounceMs);
92
- }, (error) => {
93
- warn(`[vvoc][v2-runtime] config watcher error for ${configPath}: ${String(error)}`);
94
- });
95
- return () => {
96
- if (stopped)
97
- return;
98
- stopped = true;
99
- if (timer)
100
- clearTimeout(timer);
101
- timer = undefined;
102
- try {
103
- watcher.close();
104
- }
105
- catch {
106
- // Closing a dead watcher is not an error.
107
- }
108
- };
109
- }
110
- // END_BLOCK_WATCH_PROJECT_VVOC_CONFIG
111
- //# sourceMappingURL=config-watcher.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"config-watcher.js","sourceRoot":"","sources":["../../../src/plugins/v2-runtime/config-watcher.ts"],"names":[],"mappings":"AAAA,iDAAiD;AACjD,iBAAiB;AACjB,wBAAwB;AACxB,wJAAwJ;AACxJ,2NAA2N;AAC3N,mEAAmE;AACnE,yEAAyE;AACzE,kBAAkB;AAClB,sBAAsB;AACtB,sBAAsB;AACtB,EAAE;AACF,mBAAmB;AACnB,0HAA0H;AAC1H,gIAAgI;AAChI,iBAAiB;AACjB,EAAE;AACF,uBAAuB;AACvB,gIAAgI;AAChI,qBAAqB;AAErB,OAAO,EAAE,KAAK,EAAkB,MAAM,SAAS,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,4BAA4B,EAAE,MAAM,4BAA4B,CAAC;AAC1E,OAAO,EAAE,wBAAwB,EAAE,MAAM,yBAAyB,CAAC;AAsBnE,4BAA4B;AAE5B,wCAAwC;AACxC;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC1C,SAAiB,EACjB,QAAsC,EACtC,UAAsC,EAAE;IAExC,MAAM,UAAU,GAAG,OAAO,CAAC,UA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AC;QAChB,IAAI,CACF,uDAAuD,SAAS,4BAA4B,CAC7F,CAAC;QACF,OAAO,GAAG,EAAE,GAAE,CAAC,CAAC;IAClB,CAAC;IAED,IAAI,OAAO,GAAG,KAAK,CAAC;IACpB,IAAI,KAAgD,CAAC;IACrD,MAAM,OAAO,GAAG,WAAW,CACzB,UAAU,EACV,GAAG,EAAE;QACH,IAAI,OAAO;YAAE,OAAO;QACpB,IAAI,KAAK;YAAE,YAAY,CAAC,KAAK,CAAC,CAAC;QAC/B,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE;YACtB,KAAK,GAAG,SAAS,CAAC;YAClB,IAAI,OAAO;gBAAE,OAAO;YACpB,IAAI,CAAC;gBACH,QAAQ,CAAC,UAAU,CAAC,CAAC;YACvB,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,IAAI,CACF,wDAAwD,UAAU,KAAK,MAAM,CAAC,KAAK,CAAC,EAAE,CACvF,CAAC;YACJ,CAAC;QACH,CAAC,EAAE,UAAU,CAAC,CAAC;IACjB,CAAC,EACD,CAAC,KAAK,EAAE,EAAE;QACR,IAAI,CAAC,+CAA+C,UAAU,KAAK,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IACtF,CAAC,CACF,CAAC;IAEF,OAAO,GAAG,EAAE;QACV,IAAI,OAAO;YAAE,OAAO;QACpB,OAAO,GAAG,IAAI,CAAC;QACf,IAAI,KAAK;YAAE,YAAY,CAAC,KAAK,CAAC,CAAC;QAC/B,KAAK,GAAG,SAAS,CAAC;QAClB,IAAI,CAAC;YACH,OAAO,CAAC,KAAK,EAAE,CAAC;QAClB,CAAC;QAAC,MAAM,CAAC;YACP,0CAA0C;QAC5C,CAAC;IACH,CAAC,CAAC;AACJ,CAAC;AACD,sCAAsC"}
@@ -1,50 +0,0 @@
1
- import { Plugin as V2Plugin } from "@opencode/plugin";
2
- import type { Hooks, Plugin as V1Plugin, PluginInput, PluginOptions } from "@opencode-ai/plugin";
3
- /**
4
- * The v2 setup signature, including an optional cleanup return.
5
- */
6
- export type V2Setup = (context: V2Plugin.Context) => Promise<V2Plugin.Cleanup | void> | V2Plugin.Cleanup | void;
7
- /**
8
- * A dual-runtime plugin entrypoint: the v2 Plugin shape (id + setup) plus the
9
- * v1 object-entrypoint server() member. OpenCode v1 (>= 1.18.29) detects the
10
- * default export through its id/server members and calls only server(); OpenCode
11
- * v2 reads id and setup() and ignores server(). Neither runtime loads the other
12
- * path, so a package exposing exactly this default export registers once.
13
- */
14
- export type DualPlugin = V2Plugin.Plugin & {
15
- server: V1Plugin;
16
- };
17
- /**
18
- * Build the dual entrypoint for one plugin.
19
- *
20
- * The v1 factory keeps its original single-argument or two-argument signature
21
- * and is wrapped verbatim as the server() member. The v2 setup receives the v2
22
- * plugin context and may return nothing yet; later migration tasks attach the
23
- * domain registrations.
24
- */
25
- export declare function defineDualPlugin(definition: {
26
- id: string;
27
- v1: V1Plugin;
28
- v2: V2Setup;
29
- }): DualPlugin;
30
- /**
31
- * Merge multiple v1 hook objects into one hook object.
32
- *
33
- * The v1 runtime triggers each hook key across plugin entries sequentially in
34
- * registration order, and calls dispose() on every entry in registration order
35
- * at shutdown. Producing one merged object that chains every key sequentially
36
- * and forwards dispose in registration order reproduces that behavior exactly
37
- * while presenting the aggregator as a single plugin entry.
38
- *
39
- * Children that returned undefined or an object without the requested key are
40
- * skipped for that key. An empty list produces an object with no hook members.
41
- */
42
- export declare function mergeV1Hooks(entries: Array<Hooks | undefined>): Hooks;
43
- /**
44
- * Run v1 plugin factories sequentially and merge their hook objects.
45
- *
46
- * A factory that throws is logged and skipped so one failing plugin cannot take
47
- * the remaining plugins offline, matching how the v1 runtime isolates plugin
48
- * load failures across separate package entries.
49
- */
50
- export declare function aggregateV1Plugins(factories: Array<V1Plugin>, input: PluginInput, options?: PluginOptions, onError?: (error: unknown, index: number) => void): Promise<Hooks>;
@@ -1,114 +0,0 @@
1
- // FILE: src/plugins/v2-runtime/index.ts
2
- // VERSION: 1.0.0
3
- // START_MODULE_CONTRACT
4
- // PURPOSE: Provide the dual-runtime plugin foundation that lets one package entrypoint serve OpenCode v1 (server() object entrypoints, >= 1.18.29) and OpenCode v2 (Plugin.define setup, >= 2.0.18) without double registration.
5
- // SCOPE: Dual entrypoint construction with stable plugin ids, sequential v1 plugin aggregation with per-plugin error isolation, hook-object merging that preserves v1 trigger and dispose ordering, and the typed seams later tasks use to attach v2 domain registrations.
6
- // DEPENDS: [@opencode/plugin, @opencode-ai/plugin]
7
- // LINKS: [M-PLUGIN-V2-RUNTIME, V-M-PLUGIN-V2-RUNTIME, M-PLUGIN-GUARDIAN, M-PLUGIN-WORKFLOW]
8
- // ROLE: RUNTIME
9
- // MAP_MODE: EXPORTS
10
- // END_MODULE_CONTRACT
11
- //
12
- // START_MODULE_MAP
13
- // defineDualPlugin - Build a dual entrypoint whose default export serves v2 via setup(ctx) and v1 via server(input, options).
14
- // mergeV1Hooks - Merge v1 hook objects into one object that runs each hook key sequentially in registration order and disposes in the same order.
15
- // aggregateV1Plugins - Run v1 plugin factories sequentially with per-factory error isolation and merge their hook objects.
16
- // DualPlugin - Type of the dual entrypoint: v2 Plugin shape plus the v1 server() member.
17
- // V2Setup - Signature of a v2 setup function receiving the v2 plugin Context.
18
- // END_MODULE_MAP
19
- //
20
- // START_CHANGE_SUMMARY
21
- // LAST_CHANGE: [C-OPENCODE-V2-MIGRATION - Created the dual-runtime foundation so every package entrypoint loads under both OpenCode runtimes.]
22
- // END_CHANGE_SUMMARY
23
- import { Plugin as V2Plugin } from "@opencode/plugin";
24
- // END_BLOCK_DUAL_PLUGIN_TYPE
25
- // START_BLOCK_DEFINE_DUAL_PLUGIN
26
- /**
27
- * Build the dual entrypoint for one plugin.
28
- *
29
- * The v1 factory keeps its original single-argument or two-argument signature
30
- * and is wrapped verbatim as the server() member. The v2 setup receives the v2
31
- * plugin context and may return nothing yet; later migration tasks attach the
32
- * domain registrations.
33
- */
34
- export function defineDualPlugin(definition) {
35
- return {
36
- ...V2Plugin.define({
37
- id: definition.id,
38
- setup: definition.v2,
39
- }),
40
- server: definition.v1,
41
- };
42
- }
43
- // END_BLOCK_DEFINE_DUAL_PLUGIN
44
- // START_BLOCK_MERGE_V1_HOOKS
45
- /**
46
- * Merge multiple v1 hook objects into one hook object.
47
- *
48
- * The v1 runtime triggers each hook key across plugin entries sequentially in
49
- * registration order, and calls dispose() on every entry in registration order
50
- * at shutdown. Producing one merged object that chains every key sequentially
51
- * and forwards dispose in registration order reproduces that behavior exactly
52
- * while presenting the aggregator as a single plugin entry.
53
- *
54
- * Children that returned undefined or an object without the requested key are
55
- * skipped for that key. An empty list produces an object with no hook members.
56
- */
57
- export function mergeV1Hooks(entries) {
58
- const present = entries.filter((entry) => Boolean(entry));
59
- const keys = new Set();
60
- for (const entry of present) {
61
- for (const key of Object.keys(entry)) {
62
- keys.add(key);
63
- }
64
- }
65
- const merged = {};
66
- for (const key of keys) {
67
- if (key === "dispose")
68
- continue;
69
- const handlers = present
70
- .map((entry) => entry[key])
71
- .filter((handler) => typeof handler === "function");
72
- if (handlers.length === 0)
73
- continue;
74
- merged[key] = async (input, output) => {
75
- for (const handler of handlers) {
76
- await handler(input, output);
77
- }
78
- };
79
- }
80
- const disposers = present
81
- .map((entry) => entry.dispose)
82
- .filter((disposer) => typeof disposer === "function");
83
- if (disposers.length > 0) {
84
- merged.dispose = async () => {
85
- for (const disposer of disposers) {
86
- await disposer();
87
- }
88
- };
89
- }
90
- return merged;
91
- }
92
- // END_BLOCK_MERGE_V1_HOOKS
93
- // START_BLOCK_AGGREGATE_V1_PLUGINS
94
- /**
95
- * Run v1 plugin factories sequentially and merge their hook objects.
96
- *
97
- * A factory that throws is logged and skipped so one failing plugin cannot take
98
- * the remaining plugins offline, matching how the v1 runtime isolates plugin
99
- * load failures across separate package entries.
100
- */
101
- export async function aggregateV1Plugins(factories, input, options, onError) {
102
- const results = [];
103
- for (const [index, factory] of factories.entries()) {
104
- try {
105
- results.push(await factory(input, options));
106
- }
107
- catch (error) {
108
- onError?.(error, index);
109
- }
110
- }
111
- return mergeV1Hooks(results);
112
- }
113
- // END_BLOCK_AGGREGATE_V1_PLUGINS
114
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/plugins/v2-runtime/index.ts"],"names":[],"mappings":"AAAA,wCAAwC;AACxC,iBAAiB;AACjB,wBAAwB;AACxB,mOAAmO;AACnO,6QAA6Q;AAC7Q,qDAAqD;AACrD,8FAA8F;AAC9F,kBAAkB;AAClB,sBAAsB;AACtB,sBAAsB;AACtB,EAAE;AACF,mBAAmB;AACnB,gIAAgI;AAChI,oJAAoJ;AACpJ,6HAA6H;AAC7H,2FAA2F;AAC3F,gFAAgF;AAChF,iBAAiB;AACjB,EAAE;AACF,uBAAuB;AACvB,iJAAiJ;AACjJ,qBAAqB;AAErB,OAAO,EAAE,MAAM,IAAI,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAqBtD,6BAA6B;AAE7B,iCAAiC;AACjC;;;;;;;GAOG;AACH,MAAM,UAAU,gBAAgB,CAAC,UAIhC;IACC,OAAO;QACL,GAAG,QAAQ,CAAC,MAAM,CAAC;YACjB,EAAE,EAAE,UAAU,CAAC,EAAE;YACjB,KAAK,EAAE,UAAU,CAAC,EAAE;SACrB,CAAC;QACF,MAAM,EAAE,UAAU,CAAC,EAAE;KACtB,CAAC;AACJ,CAAC;AACD,+BAA+B;AAE/B,6BAA6B;AAC7B;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,YAAY,CAAC,OAAiC;IAC5D,MAAM,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,KAAK,EAAkB,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;IAC1E,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IAC/B,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;QAC5B,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI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AU,kBAAkB,CACtC,SAA0B,EAC1B,KAAkB,EAClB,OAAuB,EACvB,OAAiD;IAEjD,MAAM,OAAO,GAA6B,EAAE,CAAC;IAC7C,KAAK,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,IAAI,SAAS,CAAC,OAAO,EAAE,EAAE,CAAC;QACnD,IAAI,CAAC;YACH,OAAO,CAAC,IAAI,CAAC,MAAM,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC;QAC9C,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;QAC1B,CAAC;IACH,CAAC;IACD,OAAO,YAAY,CAAC,OAAO,CAAC,CAAC;AAC/B,CAAC;AACD,iCAAiC"}
@@ -1,51 +0,0 @@
1
- import type { ConfigSource } from "../../lib/config-layers.js";
2
- import type { VvocConfig } from "../../lib/vvoc-config.js";
3
- /**
4
- * Effective vvoc config resolved for one session location directory.
5
- */
6
- export interface LocationConfigSnapshot {
7
- readonly directory: string;
8
- readonly config: VvocConfig;
9
- readonly source: ConfigSource;
10
- readonly warnings: readonly string[];
11
- readonly loadedAt: number;
12
- }
13
- export interface LocationResolverOptions {
14
- /**
15
- * Injectable effective-config loader for one directory. Defaults to the
16
- * layer engine with effective scope and default fallback, mirroring the v1
17
- * startup snapshot semantics for that directory.
18
- */
19
- loadForDirectory?: (directory: string) => Promise<Omit<LocationConfigSnapshot, "directory" | "loadedAt">>;
20
- /** TTL in milliseconds for cached entries; defaults to 2000. */
21
- ttlMs?: number;
22
- /** Injectable logger receiving resolution failure warnings. */
23
- warn?: (message: string) => void;
24
- /** Injectable clock in milliseconds for deterministic tests. */
25
- now?: () => number;
26
- }
27
- export interface LocationResolver {
28
- /** Resolve the effective config for one directory, or undefined when it cannot be loaded (fail closed). */
29
- forDirectory(directory: string): Promise<LocationConfigSnapshot | undefined>;
30
- /** Resolve the effective config for a session through its persisted location directory. */
31
- forSession(sessionID: string, sessionGet: (input: {
32
- sessionID: string;
33
- }) => Promise<{
34
- location?: {
35
- directory?: string;
36
- };
37
- } | undefined>): Promise<LocationConfigSnapshot | undefined>;
38
- /** Drop the cached entry for one directory so the next read reloads from disk. */
39
- invalidate(directory: string): void;
40
- /** Number of directories currently cached; exposed for tests and diagnostics. */
41
- readonly cachedDirectories: readonly string[];
42
- }
43
- /**
44
- * Build the per-location resolver.
45
- *
46
- * A directory whose config fails to load resolves to undefined after a logged
47
- * warning, and that failure is cached for the TTL so a broken project does not
48
- * hammer the filesystem from every hook invocation. Plugins treat undefined as
49
- * disabled for that location, preserving the v1 fail-closed posture.
50
- */
51
- export declare function createLocationResolver(options?: LocationResolverOptions): LocationResolver;
@@ -1,91 +0,0 @@
1
- // FILE: src/plugins/v2-runtime/location-config.ts
2
- // VERSION: 1.0.0
3
- // START_MODULE_CONTRACT
4
- // PURPOSE: Resolve the effective vvoc configuration per session location for the OpenCode v2 runtime, replacing the v1 startup-snapshot model.
5
- // SCOPE: Per-directory effective config resolution through the existing layer engine with TTL caching, session-to-directory mapping through the v2 session API, watcher-driven invalidation, and fail-closed behavior for unresolvable locations.
6
- // DEPENDS: [src/lib/config-layers.ts]
7
- // LINKS: [M-PLUGIN-V2-RUNTIME, V-M-PLUGIN-V2-RUNTIME, M-CONFIG-LAYERS]
8
- // ROLE: RUNTIME
9
- // MAP_MODE: EXPORTS
10
- // END_MODULE_CONTRACT
11
- //
12
- // START_MODULE_MAP
13
- // LocationConfigSnapshot - Effective config resolved for one directory plus source metadata and load time.
14
- // LocationResolver - Resolver interface with forDirectory, forSession, invalidate, and cachedDirectories.
15
- // LocationResolverOptions - Injectable loader, logger, TTL, and clock for deterministic tests.
16
- // createLocationResolver - Build a per-directory caching resolver with session mapping and invalidation.
17
- // END_MODULE_MAP
18
- //
19
- // START_CHANGE_SUMMARY
20
- // LAST_CHANGE: [C-OPENCODE-V2-MIGRATION T-002 - Created the per-location config resolver for the v2 runtime.]
21
- // END_CHANGE_SUMMARY
22
- import { loadVvocConfigForRead } from "../../lib/config-layers.js";
23
- /**
24
- * Build the per-location resolver.
25
- *
26
- * A directory whose config fails to load resolves to undefined after a logged
27
- * warning, and that failure is cached for the TTL so a broken project does not
28
- * hammer the filesystem from every hook invocation. Plugins treat undefined as
29
- * disabled for that location, preserving the v1 fail-closed posture.
30
- */
31
- export function createLocationResolver(options = {}) {
32
- const ttlMs = options.ttlMs ?? 2000;
33
- const warn = options.warn ?? ((message) => console.warn(message));
34
- const now = options.now ?? Date.now;
35
- const load = options.loadForDirectory ??
36
- (async (directory) => {
37
- const read = await loadVvocConfigForRead({
38
- cwd: directory,
39
- scope: "effective",
40
- allowDefault: true,
41
- });
42
- return { config: read.config, source: read.source, warnings: read.warnings };
43
- });
44
- const cache = new Map();
45
- async function resolve(directory) {
46
- const key = directory;
47
- const cached = cache.get(key);
48
- if (cached && cached.expiresAt > now()) {
49
- return cached.value;
50
- }
51
- let value;
52
- try {
53
- value = { directory, ...(await load(directory)), loadedAt: now() };
54
- }
55
- catch (error) {
56
- warn(`[vvoc][v2-runtime] config resolution failed for ${directory}: ${String(error)}; plugins stay disabled for this location`);
57
- value = undefined;
58
- }
59
- cache.set(key, { value, expiresAt: now() + ttlMs });
60
- return value;
61
- }
62
- return {
63
- async forDirectory(directory) {
64
- return resolve(directory);
65
- },
66
- async forSession(sessionID, sessionGet) {
67
- let directory;
68
- try {
69
- const session = await sessionGet({ sessionID });
70
- directory = session?.location?.directory;
71
- }
72
- catch (error) {
73
- warn(`[vvoc][v2-runtime] session lookup failed for ${sessionID}: ${String(error)}; plugins stay disabled for this session`);
74
- return undefined;
75
- }
76
- if (!directory) {
77
- warn(`[vvoc][v2-runtime] session ${sessionID} has no location directory; plugins stay disabled for this session`);
78
- return undefined;
79
- }
80
- return resolve(directory);
81
- },
82
- invalidate(directory) {
83
- cache.delete(directory);
84
- },
85
- get cachedDirectories() {
86
- return [...cache.keys()];
87
- },
88
- };
89
- }
90
- // END_BLOCK_CREATE_LOCATION_RESOLVER
91
- //# sourceMappingURL=location-config.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"location-config.js","sourceRoot":"","sources":["../../../src/plugins/v2-runtime/location-config.ts"],"names":[],"mappings":"AAAA,kDAAkD;AAClD,iBAAiB;AACjB,wBAAwB;AACxB,iJAAiJ;AACjJ,oPAAoP;AACpP,wCAAwC;AACxC,yEAAyE;AACzE,kBAAkB;AAClB,sBAAsB;AACtB,sBAAsB;AACtB,EAAE;AACF,mBAAmB;AACnB,6GAA6G;AAC7G,4GAA4G;AAC5G,iGAAiG;AACjG,2GAA2G;AAC3G,iBAAiB;AACjB,EAAE;AACF,uBAAuB;AACvB,gHAAgH;AAChH,qBAAqB;AAErB,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AA6DnE;;;;;;;GAOG;AACH,MAAM,UAAU,sBAAsB,CAAC,UAAmC,EAAE;IAC1E,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,IAAI,CAAC;IACpC,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,CAAC,CAAC,OAAe,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;IAC1E,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC;IACpC,MAAM,IAAI,GACR,OAAO,CAAC,gBAAgB;QACxB,CAAC,KAAK,EAAE,SAAiB,EAAE,EAAE;YAC3B,MAAM,IAAI,GAAG,MAAM,qBAAqB,CAAC;gBACvC,GAAG,EAAE,SAAS;gBACd,KAAK,EAAE,WAAW;gBAClB,YAAY,EAAE,IAAI;aACnB,CAAC,CAAC;YACH,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC;QAC/E,CAAC,CAAC,CAAC;IAEL,MAAM,KAAK,GAAG,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S,CAAC;YACnB,CAAC;YACD,IAAI,CAAC,SAAS,EAAE,CAAC;gBACf,IAAI,CACF,8BAA8B,SAAS,oEAAoE,CAC5G,CAAC;gBACF,OAAO,SAAS,CAAC;YACnB,CAAC;YACD,OAAO,OAAO,CAAC,SAAS,CAAC,CAAC;QAC5B,CAAC;QACD,UAAU,CAAC,SAAS;YAClB,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QAC1B,CAAC;QACD,IAAI,iBAAiB;YACnB,OAAO,CAAC,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;QAC3B,CAAC;KACF,CAAC;AACJ,CAAC;AACD,qCAAqC"}
@@ -1,48 +0,0 @@
1
- import type { Plugin as V2Plugin } from "@opencode/plugin";
2
- import { type LocationResolver } from "./location-config.js";
3
- /**
4
- * The context handed to every vvoc plugin v2 setup: the OpenCode v2 plugin
5
- * context plus the shared location resolver and a multiplexed config watcher.
6
- */
7
- export interface V2AdapterContext {
8
- readonly ctx: V2Plugin.Context;
9
- readonly resolver: LocationResolver;
10
- /** Watch the project vvoc config effective for one directory; the returned stop function never throws. */
11
- watchConfig(directory: string, onChange: () => void): Promise<() => void>;
12
- }
13
- type V2PluginSetup = (adapter: V2AdapterContext) => Promise<V2Plugin.Cleanup | void> | V2Plugin.Cleanup | void;
14
- /**
15
- * Per-plugin v2 setup functions in the canonical v1 plugin order. Migration
16
- * tasks append entries as each plugin gains its v2 registration.
17
- */
18
- export declare const V2_PLUGIN_SETUPS: Array<{
19
- name: string;
20
- setup: V2PluginSetup;
21
- }>;
22
- /**
23
- * OpenCode v1 (>= 1.18.29) also invokes setup() on dual entrypoints through
24
- * its reduced v2 bridge host, whose context only carries the agent, aisdk,
25
- * catalog, command, integration, plugin, reference, and skill domains. The
26
- * full OpenCode v2 context additionally carries app, location, event, model,
27
- * provider, session, storage, tool, and the remaining runtime domains. Probe
28
- * verified against OpenCode 1.18.32: the v1 bridge lacks tool, session, event,
29
- * storage, app, and location, so their presence distinguishes the runtimes.
30
- */
31
- export declare function isFullV2Context(context: V2Plugin.Context): boolean;
32
- /**
33
- * Build the shared adapter for one plugin context: a per-location config
34
- * resolver and a config watcher multiplexer that keeps one filesystem watch
35
- * per directory regardless of how many plugins subscribe to that directory.
36
- */
37
- export declare function createV2Adapter(context: V2Plugin.Context): V2AdapterContext;
38
- /**
39
- * Run every registered v2 plugin setup against the adapter, isolating failures
40
- * per plugin, and return one cleanup that disposes the successful cleanups in
41
- * reverse registration order.
42
- *
43
- * Under the v1 v2-bridge host this returns without registering anything: the
44
- * same entrypoint's server() member already provides the v1 behavior, so the
45
- * package never registers twice inside one OpenCode v1 process.
46
- */
47
- export declare function setupV2Plugins(context: V2Plugin.Context): Promise<V2Plugin.Cleanup | void>;
48
- export {};