gsd-pi 2.34.0-dev.ed0bfbf → 2.35.0-dev.55dcc60

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 (255) hide show
  1. package/dist/resources/extensions/gsd/changelog.js +162 -0
  2. package/dist/resources/extensions/gsd/commands-bootstrap.js +1 -0
  3. package/dist/resources/extensions/gsd/commands-inspect.js +10 -3
  4. package/dist/resources/extensions/gsd/commands-prefs-wizard.js +5 -1
  5. package/dist/resources/extensions/gsd/commands.js +8 -1
  6. package/dist/resources/extensions/gsd/docs/preferences-reference.md +10 -0
  7. package/dist/resources/extensions/gsd/doctor-checks.js +113 -5
  8. package/dist/resources/extensions/gsd/doctor-proactive.js +22 -0
  9. package/dist/resources/extensions/gsd/doctor.js +36 -0
  10. package/dist/resources/extensions/gsd/guided-flow.js +4 -2
  11. package/dist/resources/extensions/gsd/preferences-validation.js +38 -0
  12. package/dist/resources/extensions/gsd/preferences.js +2 -0
  13. package/dist/resources/skills/create-gsd-extension/references/events-reference.md +4 -4
  14. package/package.json +1 -1
  15. package/packages/pi-agent-core/dist/agent-loop.d.ts +14 -0
  16. package/packages/pi-agent-core/dist/agent-loop.d.ts.map +1 -1
  17. package/packages/pi-agent-core/dist/agent-loop.js +24 -27
  18. package/packages/pi-agent-core/dist/agent-loop.js.map +1 -1
  19. package/packages/pi-agent-core/dist/agent.d.ts +1 -0
  20. package/packages/pi-agent-core/dist/agent.d.ts.map +1 -1
  21. package/packages/pi-agent-core/dist/agent.js +11 -22
  22. package/packages/pi-agent-core/dist/agent.js.map +1 -1
  23. package/packages/pi-agent-core/dist/proxy.d.ts.map +1 -1
  24. package/packages/pi-agent-core/dist/proxy.js +2 -8
  25. package/packages/pi-agent-core/dist/proxy.js.map +1 -1
  26. package/packages/pi-agent-core/src/agent-loop.ts +30 -27
  27. package/packages/pi-agent-core/src/agent.ts +12 -23
  28. package/packages/pi-agent-core/src/proxy.ts +2 -8
  29. package/packages/pi-ai/dist/providers/azure-openai-responses.d.ts.map +1 -1
  30. package/packages/pi-ai/dist/providers/azure-openai-responses.js +5 -41
  31. package/packages/pi-ai/dist/providers/azure-openai-responses.js.map +1 -1
  32. package/packages/pi-ai/dist/providers/openai-completions.d.ts.map +1 -1
  33. package/packages/pi-ai/dist/providers/openai-completions.js +10 -73
  34. package/packages/pi-ai/dist/providers/openai-completions.js.map +1 -1
  35. package/packages/pi-ai/dist/providers/openai-responses.d.ts.map +1 -1
  36. package/packages/pi-ai/dist/providers/openai-responses.js +8 -79
  37. package/packages/pi-ai/dist/providers/openai-responses.js.map +1 -1
  38. package/packages/pi-ai/dist/providers/openai-shared.d.ts +65 -0
  39. package/packages/pi-ai/dist/providers/openai-shared.d.ts.map +1 -0
  40. package/packages/pi-ai/dist/providers/openai-shared.js +146 -0
  41. package/packages/pi-ai/dist/providers/openai-shared.js.map +1 -0
  42. package/packages/pi-ai/dist/utils/oauth/google-antigravity.d.ts.map +1 -1
  43. package/packages/pi-ai/dist/utils/oauth/google-antigravity.js +7 -135
  44. package/packages/pi-ai/dist/utils/oauth/google-antigravity.js.map +1 -1
  45. package/packages/pi-ai/dist/utils/oauth/google-gemini-cli.d.ts.map +1 -1
  46. package/packages/pi-ai/dist/utils/oauth/google-gemini-cli.js +7 -135
  47. package/packages/pi-ai/dist/utils/oauth/google-gemini-cli.js.map +1 -1
  48. package/packages/pi-ai/dist/utils/oauth/google-oauth-utils.d.ts +46 -0
  49. package/packages/pi-ai/dist/utils/oauth/google-oauth-utils.d.ts.map +1 -0
  50. package/packages/pi-ai/dist/utils/oauth/google-oauth-utils.js +160 -0
  51. package/packages/pi-ai/dist/utils/oauth/google-oauth-utils.js.map +1 -0
  52. package/packages/pi-ai/src/providers/azure-openai-responses.ts +11 -45
  53. package/packages/pi-ai/src/providers/openai-completions.ts +16 -86
  54. package/packages/pi-ai/src/providers/openai-responses.ts +15 -95
  55. package/packages/pi-ai/src/providers/openai-shared.ts +193 -0
  56. package/packages/pi-ai/src/utils/oauth/google-antigravity.ts +14 -162
  57. package/packages/pi-ai/src/utils/oauth/google-gemini-cli.ts +13 -161
  58. package/packages/pi-ai/src/utils/oauth/google-oauth-utils.ts +201 -0
  59. package/packages/pi-coding-agent/dist/core/agent-session.d.ts +16 -63
  60. package/packages/pi-coding-agent/dist/core/agent-session.d.ts.map +1 -1
  61. package/packages/pi-coding-agent/dist/core/agent-session.js +104 -641
  62. package/packages/pi-coding-agent/dist/core/agent-session.js.map +1 -1
  63. package/packages/pi-coding-agent/dist/core/auth-storage.d.ts +0 -1
  64. package/packages/pi-coding-agent/dist/core/auth-storage.d.ts.map +1 -1
  65. package/packages/pi-coding-agent/dist/core/auth-storage.js +4 -35
  66. package/packages/pi-coding-agent/dist/core/auth-storage.js.map +1 -1
  67. package/packages/pi-coding-agent/dist/core/compaction/branch-summarization.d.ts.map +1 -1
  68. package/packages/pi-coding-agent/dist/core/compaction/branch-summarization.js +5 -43
  69. package/packages/pi-coding-agent/dist/core/compaction/branch-summarization.js.map +1 -1
  70. package/packages/pi-coding-agent/dist/core/compaction/compaction.d.ts.map +1 -1
  71. package/packages/pi-coding-agent/dist/core/compaction/compaction.js +11 -69
  72. package/packages/pi-coding-agent/dist/core/compaction/compaction.js.map +1 -1
  73. package/packages/pi-coding-agent/dist/core/compaction/utils.d.ts +40 -0
  74. package/packages/pi-coding-agent/dist/core/compaction/utils.d.ts.map +1 -1
  75. package/packages/pi-coding-agent/dist/core/compaction/utils.js +78 -0
  76. package/packages/pi-coding-agent/dist/core/compaction/utils.js.map +1 -1
  77. package/packages/pi-coding-agent/dist/core/compaction-orchestrator.d.ts +77 -0
  78. package/packages/pi-coding-agent/dist/core/compaction-orchestrator.d.ts.map +1 -0
  79. package/packages/pi-coding-agent/dist/core/compaction-orchestrator.js +331 -0
  80. package/packages/pi-coding-agent/dist/core/compaction-orchestrator.js.map +1 -0
  81. package/packages/pi-coding-agent/dist/core/extensions/index.d.ts +2 -2
  82. package/packages/pi-coding-agent/dist/core/extensions/index.d.ts.map +1 -1
  83. package/packages/pi-coding-agent/dist/core/extensions/index.js +1 -1
  84. package/packages/pi-coding-agent/dist/core/extensions/index.js.map +1 -1
  85. package/packages/pi-coding-agent/dist/core/extensions/runner.d.ts +15 -0
  86. package/packages/pi-coding-agent/dist/core/extensions/runner.d.ts.map +1 -1
  87. package/packages/pi-coding-agent/dist/core/extensions/runner.js +129 -243
  88. package/packages/pi-coding-agent/dist/core/extensions/runner.js.map +1 -1
  89. package/packages/pi-coding-agent/dist/core/extensions/types.d.ts +49 -42
  90. package/packages/pi-coding-agent/dist/core/extensions/types.d.ts.map +1 -1
  91. package/packages/pi-coding-agent/dist/core/extensions/types.js +2 -21
  92. package/packages/pi-coding-agent/dist/core/extensions/types.js.map +1 -1
  93. package/packages/pi-coding-agent/dist/core/lock-utils.d.ts +39 -0
  94. package/packages/pi-coding-agent/dist/core/lock-utils.d.ts.map +1 -0
  95. package/packages/pi-coding-agent/dist/core/lock-utils.js +89 -0
  96. package/packages/pi-coding-agent/dist/core/lock-utils.js.map +1 -0
  97. package/packages/pi-coding-agent/dist/core/lsp/config.d.ts +2 -0
  98. package/packages/pi-coding-agent/dist/core/lsp/config.d.ts.map +1 -1
  99. package/packages/pi-coding-agent/dist/core/lsp/config.js +4 -1
  100. package/packages/pi-coding-agent/dist/core/lsp/config.js.map +1 -1
  101. package/packages/pi-coding-agent/dist/core/lsp/index.d.ts.map +1 -1
  102. package/packages/pi-coding-agent/dist/core/lsp/index.js +52 -107
  103. package/packages/pi-coding-agent/dist/core/lsp/index.js.map +1 -1
  104. package/packages/pi-coding-agent/dist/core/lsp/lspmux.d.ts.map +1 -1
  105. package/packages/pi-coding-agent/dist/core/lsp/lspmux.js +2 -21
  106. package/packages/pi-coding-agent/dist/core/lsp/lspmux.js.map +1 -1
  107. package/packages/pi-coding-agent/dist/core/lsp/types.d.ts +0 -1
  108. package/packages/pi-coding-agent/dist/core/lsp/types.d.ts.map +1 -1
  109. package/packages/pi-coding-agent/dist/core/lsp/types.js +0 -28
  110. package/packages/pi-coding-agent/dist/core/lsp/types.js.map +1 -1
  111. package/packages/pi-coding-agent/dist/core/package-manager.d.ts.map +1 -1
  112. package/packages/pi-coding-agent/dist/core/package-manager.js +2 -4
  113. package/packages/pi-coding-agent/dist/core/package-manager.js.map +1 -1
  114. package/packages/pi-coding-agent/dist/core/resource-loader.d.ts +2 -4
  115. package/packages/pi-coding-agent/dist/core/resource-loader.d.ts.map +1 -1
  116. package/packages/pi-coding-agent/dist/core/resource-loader.js +33 -58
  117. package/packages/pi-coding-agent/dist/core/resource-loader.js.map +1 -1
  118. package/packages/pi-coding-agent/dist/core/retry-handler.d.ts +87 -0
  119. package/packages/pi-coding-agent/dist/core/retry-handler.d.ts.map +1 -0
  120. package/packages/pi-coding-agent/dist/core/retry-handler.js +295 -0
  121. package/packages/pi-coding-agent/dist/core/retry-handler.js.map +1 -0
  122. package/packages/pi-coding-agent/dist/core/session-manager.d.ts +0 -1
  123. package/packages/pi-coding-agent/dist/core/session-manager.d.ts.map +1 -1
  124. package/packages/pi-coding-agent/dist/core/session-manager.js +3 -28
  125. package/packages/pi-coding-agent/dist/core/session-manager.js.map +1 -1
  126. package/packages/pi-coding-agent/dist/core/settings-manager.d.ts +8 -0
  127. package/packages/pi-coding-agent/dist/core/settings-manager.d.ts.map +1 -1
  128. package/packages/pi-coding-agent/dist/core/settings-manager.js +76 -166
  129. package/packages/pi-coding-agent/dist/core/settings-manager.js.map +1 -1
  130. package/packages/pi-coding-agent/dist/core/skills.d.ts.map +1 -1
  131. package/packages/pi-coding-agent/dist/core/skills.js +1 -3
  132. package/packages/pi-coding-agent/dist/core/skills.js.map +1 -1
  133. package/packages/pi-coding-agent/dist/index.d.ts +1 -1
  134. package/packages/pi-coding-agent/dist/index.d.ts.map +1 -1
  135. package/packages/pi-coding-agent/dist/index.js +1 -1
  136. package/packages/pi-coding-agent/dist/index.js.map +1 -1
  137. package/packages/pi-coding-agent/dist/modes/interactive/components/session-selector.d.ts +1 -1
  138. package/packages/pi-coding-agent/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
  139. package/packages/pi-coding-agent/dist/modes/interactive/components/session-selector.js +9 -26
  140. package/packages/pi-coding-agent/dist/modes/interactive/components/session-selector.js.map +1 -1
  141. package/packages/pi-coding-agent/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  142. package/packages/pi-coding-agent/dist/modes/interactive/components/tool-execution.js +1 -13
  143. package/packages/pi-coding-agent/dist/modes/interactive/components/tool-execution.js.map +1 -1
  144. package/packages/pi-coding-agent/dist/modes/interactive/components/tree-render-utils.d.ts +44 -0
  145. package/packages/pi-coding-agent/dist/modes/interactive/components/tree-render-utils.d.ts.map +1 -0
  146. package/packages/pi-coding-agent/dist/modes/interactive/components/tree-render-utils.js +61 -0
  147. package/packages/pi-coding-agent/dist/modes/interactive/components/tree-render-utils.js.map +1 -0
  148. package/packages/pi-coding-agent/dist/modes/interactive/components/tree-selector.d.ts.map +1 -1
  149. package/packages/pi-coding-agent/dist/modes/interactive/components/tree-selector.js +6 -9
  150. package/packages/pi-coding-agent/dist/modes/interactive/components/tree-selector.js.map +1 -1
  151. package/packages/pi-coding-agent/dist/modes/interactive/theme/theme.d.ts +65 -0
  152. package/packages/pi-coding-agent/dist/modes/interactive/theme/theme.d.ts.map +1 -1
  153. package/packages/pi-coding-agent/dist/modes/interactive/theme/theme.js +6 -16
  154. package/packages/pi-coding-agent/dist/modes/interactive/theme/theme.js.map +1 -1
  155. package/packages/pi-coding-agent/dist/modes/interactive/theme/themes.d.ts +12 -0
  156. package/packages/pi-coding-agent/dist/modes/interactive/theme/themes.d.ts.map +1 -0
  157. package/packages/pi-coding-agent/dist/modes/interactive/theme/themes.js +175 -0
  158. package/packages/pi-coding-agent/dist/modes/interactive/theme/themes.js.map +1 -0
  159. package/packages/pi-coding-agent/dist/modes/interactive/utils/shorten-path.d.ts +6 -0
  160. package/packages/pi-coding-agent/dist/modes/interactive/utils/shorten-path.d.ts.map +1 -0
  161. package/packages/pi-coding-agent/dist/modes/interactive/utils/shorten-path.js +15 -0
  162. package/packages/pi-coding-agent/dist/modes/interactive/utils/shorten-path.js.map +1 -0
  163. package/packages/pi-coding-agent/dist/modes/print-mode.d.ts.map +1 -1
  164. package/packages/pi-coding-agent/dist/modes/print-mode.js +2 -30
  165. package/packages/pi-coding-agent/dist/modes/print-mode.js.map +1 -1
  166. package/packages/pi-coding-agent/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  167. package/packages/pi-coding-agent/dist/modes/rpc/rpc-mode.js +2 -28
  168. package/packages/pi-coding-agent/dist/modes/rpc/rpc-mode.js.map +1 -1
  169. package/packages/pi-coding-agent/dist/modes/shared/command-context-actions.d.ts +19 -0
  170. package/packages/pi-coding-agent/dist/modes/shared/command-context-actions.d.ts.map +1 -0
  171. package/packages/pi-coding-agent/dist/modes/shared/command-context-actions.js +45 -0
  172. package/packages/pi-coding-agent/dist/modes/shared/command-context-actions.js.map +1 -0
  173. package/packages/pi-coding-agent/dist/utils/error.d.ts +5 -0
  174. package/packages/pi-coding-agent/dist/utils/error.d.ts.map +1 -0
  175. package/packages/pi-coding-agent/dist/utils/error.js +7 -0
  176. package/packages/pi-coding-agent/dist/utils/error.js.map +1 -0
  177. package/packages/pi-coding-agent/package.json +1 -1
  178. package/packages/pi-coding-agent/src/core/agent-session.ts +117 -745
  179. package/packages/pi-coding-agent/src/core/auth-storage.ts +4 -38
  180. package/packages/pi-coding-agent/src/core/compaction/branch-summarization.ts +7 -53
  181. package/packages/pi-coding-agent/src/core/compaction/compaction.ts +14 -74
  182. package/packages/pi-coding-agent/src/core/compaction/utils.ts +100 -0
  183. package/packages/pi-coding-agent/src/core/compaction-orchestrator.ts +424 -0
  184. package/packages/pi-coding-agent/src/core/extensions/index.ts +1 -21
  185. package/packages/pi-coding-agent/src/core/extensions/runner.ts +119 -243
  186. package/packages/pi-coding-agent/src/core/extensions/types.ts +50 -69
  187. package/packages/pi-coding-agent/src/core/lock-utils.ts +113 -0
  188. package/packages/pi-coding-agent/src/core/lsp/config.ts +4 -1
  189. package/packages/pi-coding-agent/src/core/lsp/index.ts +83 -152
  190. package/packages/pi-coding-agent/src/core/lsp/lspmux.ts +2 -22
  191. package/packages/pi-coding-agent/src/core/lsp/types.ts +0 -29
  192. package/packages/pi-coding-agent/src/core/package-manager.ts +1 -4
  193. package/packages/pi-coding-agent/src/core/resource-loader.ts +43 -67
  194. package/packages/pi-coding-agent/src/core/retry-handler.ts +359 -0
  195. package/packages/pi-coding-agent/src/core/session-manager.ts +3 -30
  196. package/packages/pi-coding-agent/src/core/settings-manager.ts +85 -164
  197. package/packages/pi-coding-agent/src/core/skills.ts +1 -4
  198. package/packages/pi-coding-agent/src/index.ts +1 -7
  199. package/packages/pi-coding-agent/src/modes/interactive/components/session-selector.ts +17 -29
  200. package/packages/pi-coding-agent/src/modes/interactive/components/tool-execution.ts +1 -13
  201. package/packages/pi-coding-agent/src/modes/interactive/components/tree-render-utils.ts +81 -0
  202. package/packages/pi-coding-agent/src/modes/interactive/components/tree-selector.ts +14 -19
  203. package/packages/pi-coding-agent/src/modes/interactive/theme/theme.ts +7 -18
  204. package/packages/pi-coding-agent/src/modes/interactive/theme/themes.ts +196 -0
  205. package/packages/pi-coding-agent/src/modes/interactive/utils/shorten-path.ts +14 -0
  206. package/packages/pi-coding-agent/src/modes/print-mode.ts +2 -30
  207. package/packages/pi-coding-agent/src/modes/rpc/rpc-mode.ts +2 -28
  208. package/packages/pi-coding-agent/src/modes/shared/command-context-actions.ts +53 -0
  209. package/packages/pi-coding-agent/src/utils/error.ts +6 -0
  210. package/packages/pi-tui/dist/components/markdown.d.ts +5 -0
  211. package/packages/pi-tui/dist/components/markdown.d.ts.map +1 -1
  212. package/packages/pi-tui/dist/components/markdown.js +25 -31
  213. package/packages/pi-tui/dist/components/markdown.js.map +1 -1
  214. package/packages/pi-tui/dist/keys.d.ts +0 -4
  215. package/packages/pi-tui/dist/keys.d.ts.map +1 -1
  216. package/packages/pi-tui/dist/keys.js +94 -162
  217. package/packages/pi-tui/dist/keys.js.map +1 -1
  218. package/packages/pi-tui/src/components/markdown.ts +25 -29
  219. package/packages/pi-tui/src/keys.ts +94 -173
  220. package/pkg/dist/modes/interactive/theme/theme.d.ts +65 -0
  221. package/pkg/dist/modes/interactive/theme/theme.d.ts.map +1 -1
  222. package/pkg/dist/modes/interactive/theme/theme.js +6 -16
  223. package/pkg/dist/modes/interactive/theme/theme.js.map +1 -1
  224. package/pkg/dist/modes/interactive/theme/themes.d.ts +12 -0
  225. package/pkg/dist/modes/interactive/theme/themes.d.ts.map +1 -0
  226. package/pkg/dist/modes/interactive/theme/themes.js +175 -0
  227. package/pkg/dist/modes/interactive/theme/themes.js.map +1 -0
  228. package/pkg/package.json +1 -1
  229. package/src/resources/extensions/gsd/changelog.ts +213 -0
  230. package/src/resources/extensions/gsd/commands-bootstrap.ts +1 -0
  231. package/src/resources/extensions/gsd/commands-inspect.ts +10 -3
  232. package/src/resources/extensions/gsd/commands-prefs-wizard.ts +5 -1
  233. package/src/resources/extensions/gsd/commands.ts +9 -1
  234. package/src/resources/extensions/gsd/docs/preferences-reference.md +10 -0
  235. package/src/resources/extensions/gsd/doctor-checks.ts +107 -5
  236. package/src/resources/extensions/gsd/doctor-proactive.ts +24 -0
  237. package/src/resources/extensions/gsd/doctor-types.ts +9 -1
  238. package/src/resources/extensions/gsd/doctor.ts +35 -0
  239. package/src/resources/extensions/gsd/guided-flow.ts +4 -2
  240. package/src/resources/extensions/gsd/preferences-validation.ts +38 -0
  241. package/src/resources/extensions/gsd/preferences.ts +2 -0
  242. package/src/resources/extensions/gsd/tests/commands-inspect-open-db.test.ts +46 -0
  243. package/src/resources/extensions/gsd/tests/doctor-git.test.ts +98 -2
  244. package/src/resources/extensions/gsd/tests/doctor-runtime.test.ts +59 -3
  245. package/src/resources/extensions/gsd/tests/preferences.test.ts +28 -0
  246. package/src/resources/skills/create-gsd-extension/references/events-reference.md +4 -4
  247. package/packages/pi-coding-agent/dist/modes/interactive/theme/dark.json +0 -85
  248. package/packages/pi-coding-agent/dist/modes/interactive/theme/light.json +0 -84
  249. package/packages/pi-coding-agent/dist/modes/interactive/theme/theme-schema.json +0 -335
  250. package/packages/pi-coding-agent/src/modes/interactive/theme/dark.json +0 -85
  251. package/packages/pi-coding-agent/src/modes/interactive/theme/light.json +0 -84
  252. package/packages/pi-coding-agent/src/modes/interactive/theme/theme-schema.json +0 -335
  253. package/pkg/dist/modes/interactive/theme/dark.json +0 -85
  254. package/pkg/dist/modes/interactive/theme/light.json +0 -84
  255. package/pkg/dist/modes/interactive/theme/theme-schema.json +0 -335
@@ -363,245 +363,152 @@ export class ExtensionRunner {
363
363
  event.type === "session_before_compact" ||
364
364
  event.type === "session_before_tree");
365
365
  }
366
- async emit(event) {
366
+ /**
367
+ * Shared handler invocation loop.
368
+ *
369
+ * Iterates every handler registered for `eventType` across all extensions,
370
+ * calling each inside a try/catch that emits an ExtensionError on failure.
371
+ *
372
+ * `getEvent` builds the event object for each handler call — callers that
373
+ * mutate state between calls (e.g. context, before_provider_request) supply
374
+ * a function; callers with a fixed event can pass a constant.
375
+ *
376
+ * `processResult` receives each handler's return value and the owning
377
+ * extension's path. It returns `{ done: true }` to short-circuit
378
+ * or `{ done: false }` to keep iterating.
379
+ */
380
+ async invokeHandlers(eventType, getEvent, processResult) {
367
381
  const ctx = this.createContext();
368
- let result;
369
382
  for (const ext of this.extensions) {
370
- const handlers = ext.handlers.get(event.type);
383
+ const handlers = ext.handlers.get(eventType);
371
384
  if (!handlers || handlers.length === 0)
372
385
  continue;
373
386
  for (const handler of handlers) {
374
387
  try {
388
+ const event = getEvent();
375
389
  const handlerResult = await handler(event, ctx);
376
- if (this.isSessionBeforeEvent(event) && handlerResult) {
377
- result = handlerResult;
378
- if (result.cancel) {
379
- return result;
380
- }
381
- }
390
+ const action = processResult(handlerResult, ext.path);
391
+ if (action.done)
392
+ return;
382
393
  }
383
394
  catch (err) {
384
395
  const message = err instanceof Error ? err.message : String(err);
385
396
  const stack = err instanceof Error ? err.stack : undefined;
386
397
  this.emitError({
387
398
  extensionPath: ext.path,
388
- event: event.type,
399
+ event: eventType,
389
400
  error: message,
390
401
  stack,
391
402
  });
392
403
  }
393
404
  }
394
405
  }
406
+ }
407
+ async emit(event) {
408
+ let result;
409
+ const isSessionBefore = this.isSessionBeforeEvent(event);
410
+ await this.invokeHandlers(event.type, () => event, (handlerResult) => {
411
+ if (isSessionBefore && handlerResult) {
412
+ result = handlerResult;
413
+ if (result.cancel)
414
+ return { done: true };
415
+ }
416
+ return { done: false };
417
+ });
395
418
  return result;
396
419
  }
397
420
  async emitToolResult(event) {
398
- const ctx = this.createContext();
399
421
  const currentEvent = { ...event };
400
422
  let modified = false;
401
- for (const ext of this.extensions) {
402
- const handlers = ext.handlers.get("tool_result");
403
- if (!handlers || handlers.length === 0)
404
- continue;
405
- for (const handler of handlers) {
406
- try {
407
- const handlerResult = (await handler(currentEvent, ctx));
408
- if (!handlerResult)
409
- continue;
410
- if (handlerResult.content !== undefined) {
411
- currentEvent.content = handlerResult.content;
412
- modified = true;
413
- }
414
- if (handlerResult.details !== undefined) {
415
- currentEvent.details = handlerResult.details;
416
- modified = true;
417
- }
418
- if (handlerResult.isError !== undefined) {
419
- currentEvent.isError = handlerResult.isError;
420
- modified = true;
421
- }
422
- }
423
- catch (err) {
424
- const message = err instanceof Error ? err.message : String(err);
425
- const stack = err instanceof Error ? err.stack : undefined;
426
- this.emitError({
427
- extensionPath: ext.path,
428
- event: "tool_result",
429
- error: message,
430
- stack,
431
- });
432
- }
423
+ await this.invokeHandlers("tool_result", () => currentEvent, (handlerResult) => {
424
+ const r = handlerResult;
425
+ if (!r)
426
+ return { done: false };
427
+ if (r.content !== undefined) {
428
+ currentEvent.content = r.content;
429
+ modified = true;
433
430
  }
434
- }
435
- if (!modified) {
431
+ if (r.details !== undefined) {
432
+ currentEvent.details = r.details;
433
+ modified = true;
434
+ }
435
+ if (r.isError !== undefined) {
436
+ currentEvent.isError = r.isError;
437
+ modified = true;
438
+ }
439
+ return { done: false };
440
+ });
441
+ if (!modified)
436
442
  return undefined;
437
- }
438
- return {
439
- content: currentEvent.content,
440
- details: currentEvent.details,
441
- isError: currentEvent.isError,
442
- };
443
+ return { content: currentEvent.content, details: currentEvent.details, isError: currentEvent.isError };
443
444
  }
444
445
  async emitToolCall(event) {
445
- const ctx = this.createContext();
446
446
  let result;
447
- for (const ext of this.extensions) {
448
- const handlers = ext.handlers.get("tool_call");
449
- if (!handlers || handlers.length === 0)
450
- continue;
451
- for (const handler of handlers) {
452
- try {
453
- const handlerResult = await handler(event, ctx);
454
- if (handlerResult) {
455
- result = handlerResult;
456
- if (result.block) {
457
- return result;
458
- }
459
- }
460
- }
461
- catch (err) {
462
- const message = err instanceof Error ? err.message : String(err);
463
- const stack = err instanceof Error ? err.stack : undefined;
464
- this.emitError({
465
- extensionPath: ext.path,
466
- event: "tool_call",
467
- error: message,
468
- stack,
469
- });
470
- }
447
+ await this.invokeHandlers("tool_call", () => event, (handlerResult) => {
448
+ if (handlerResult) {
449
+ result = handlerResult;
450
+ if (result.block)
451
+ return { done: true };
471
452
  }
472
- }
453
+ return { done: false };
454
+ });
473
455
  return result;
474
456
  }
475
457
  async emitUserBash(event) {
476
- const ctx = this.createContext();
477
- for (const ext of this.extensions) {
478
- const handlers = ext.handlers.get("user_bash");
479
- if (!handlers || handlers.length === 0)
480
- continue;
481
- for (const handler of handlers) {
482
- try {
483
- const handlerResult = await handler(event, ctx);
484
- if (handlerResult) {
485
- return handlerResult;
486
- }
487
- }
488
- catch (err) {
489
- const message = err instanceof Error ? err.message : String(err);
490
- const stack = err instanceof Error ? err.stack : undefined;
491
- this.emitError({
492
- extensionPath: ext.path,
493
- event: "user_bash",
494
- error: message,
495
- stack,
496
- });
497
- }
458
+ let result;
459
+ await this.invokeHandlers("user_bash", () => event, (handlerResult) => {
460
+ if (handlerResult) {
461
+ result = handlerResult;
462
+ return { done: true };
498
463
  }
499
- }
500
- return undefined;
464
+ return { done: false };
465
+ });
466
+ return result;
501
467
  }
502
468
  async emitContext(messages) {
503
- const ctx = this.createContext();
504
469
  let currentMessages = structuredClone(messages);
505
- for (const ext of this.extensions) {
506
- const handlers = ext.handlers.get("context");
507
- if (!handlers || handlers.length === 0)
508
- continue;
509
- for (const handler of handlers) {
510
- try {
511
- const event = { type: "context", messages: currentMessages };
512
- const handlerResult = await handler(event, ctx);
513
- if (handlerResult && handlerResult.messages) {
514
- currentMessages = handlerResult.messages;
515
- }
516
- }
517
- catch (err) {
518
- const message = err instanceof Error ? err.message : String(err);
519
- const stack = err instanceof Error ? err.stack : undefined;
520
- this.emitError({
521
- extensionPath: ext.path,
522
- event: "context",
523
- error: message,
524
- stack,
525
- });
526
- }
470
+ await this.invokeHandlers("context", () => ({ type: "context", messages: currentMessages }), (handlerResult) => {
471
+ if (handlerResult && handlerResult.messages) {
472
+ currentMessages = handlerResult.messages;
527
473
  }
528
- }
474
+ return { done: false };
475
+ });
529
476
  return currentMessages;
530
477
  }
531
478
  async emitBeforeProviderRequest(payload, model) {
532
- const ctx = this.createContext();
533
479
  let currentPayload = payload;
534
- for (const ext of this.extensions) {
535
- const handlers = ext.handlers.get("before_provider_request");
536
- if (!handlers || handlers.length === 0)
537
- continue;
538
- for (const handler of handlers) {
539
- try {
540
- const event = {
541
- type: "before_provider_request",
542
- payload: currentPayload,
543
- model,
544
- };
545
- const handlerResult = await handler(event, ctx);
546
- if (handlerResult !== undefined) {
547
- currentPayload = handlerResult;
548
- }
549
- }
550
- catch (err) {
551
- const message = err instanceof Error ? err.message : String(err);
552
- const stack = err instanceof Error ? err.stack : undefined;
553
- this.emitError({
554
- extensionPath: ext.path,
555
- event: "before_provider_request",
556
- error: message,
557
- stack,
558
- });
559
- }
560
- }
561
- }
480
+ await this.invokeHandlers("before_provider_request", () => ({
481
+ type: "before_provider_request",
482
+ payload: currentPayload,
483
+ model,
484
+ }), (handlerResult) => {
485
+ if (handlerResult !== undefined)
486
+ currentPayload = handlerResult;
487
+ return { done: false };
488
+ });
562
489
  return currentPayload;
563
490
  }
564
491
  async emitBeforeAgentStart(prompt, images, systemPrompt) {
565
- const ctx = this.createContext();
566
492
  const messages = [];
567
493
  let currentSystemPrompt = systemPrompt;
568
494
  let systemPromptModified = false;
569
- for (const ext of this.extensions) {
570
- const handlers = ext.handlers.get("before_agent_start");
571
- if (!handlers || handlers.length === 0)
572
- continue;
573
- for (const handler of handlers) {
574
- try {
575
- const event = {
576
- type: "before_agent_start",
577
- prompt,
578
- images,
579
- systemPrompt: currentSystemPrompt,
580
- };
581
- const handlerResult = await handler(event, ctx);
582
- if (handlerResult) {
583
- const result = handlerResult;
584
- if (result.message) {
585
- messages.push(result.message);
586
- }
587
- if (result.systemPrompt !== undefined) {
588
- currentSystemPrompt = result.systemPrompt;
589
- systemPromptModified = true;
590
- }
591
- }
592
- }
593
- catch (err) {
594
- const message = err instanceof Error ? err.message : String(err);
595
- const stack = err instanceof Error ? err.stack : undefined;
596
- this.emitError({
597
- extensionPath: ext.path,
598
- event: "before_agent_start",
599
- error: message,
600
- stack,
601
- });
495
+ await this.invokeHandlers("before_agent_start", () => ({
496
+ type: "before_agent_start",
497
+ prompt,
498
+ images,
499
+ systemPrompt: currentSystemPrompt,
500
+ }), (handlerResult) => {
501
+ if (handlerResult) {
502
+ const r = handlerResult;
503
+ if (r.message)
504
+ messages.push(r.message);
505
+ if (r.systemPrompt !== undefined) {
506
+ currentSystemPrompt = r.systemPrompt;
507
+ systemPromptModified = true;
602
508
  }
603
509
  }
604
- }
510
+ return { done: false };
511
+ });
605
512
  if (messages.length > 0 || systemPromptModified) {
606
513
  return {
607
514
  messages: messages.length > 0 ? messages : undefined,
@@ -611,70 +518,49 @@ export class ExtensionRunner {
611
518
  return undefined;
612
519
  }
613
520
  async emitResourcesDiscover(cwd, reason) {
614
- const ctx = this.createContext();
615
521
  const skillPaths = [];
616
522
  const promptPaths = [];
617
523
  const themePaths = [];
618
- for (const ext of this.extensions) {
619
- const handlers = ext.handlers.get("resources_discover");
620
- if (!handlers || handlers.length === 0)
621
- continue;
622
- for (const handler of handlers) {
623
- try {
624
- const event = { type: "resources_discover", cwd, reason };
625
- const handlerResult = await handler(event, ctx);
626
- const result = handlerResult;
627
- if (result?.skillPaths?.length) {
628
- skillPaths.push(...result.skillPaths.map((path) => ({ path, extensionPath: ext.path })));
629
- }
630
- if (result?.promptPaths?.length) {
631
- promptPaths.push(...result.promptPaths.map((path) => ({ path, extensionPath: ext.path })));
632
- }
633
- if (result?.themePaths?.length) {
634
- themePaths.push(...result.themePaths.map((path) => ({ path, extensionPath: ext.path })));
635
- }
636
- }
637
- catch (err) {
638
- const message = err instanceof Error ? err.message : String(err);
639
- const stack = err instanceof Error ? err.stack : undefined;
640
- this.emitError({
641
- extensionPath: ext.path,
642
- event: "resources_discover",
643
- error: message,
644
- stack,
645
- });
646
- }
647
- }
648
- }
524
+ await this.invokeHandlers("resources_discover", () => ({
525
+ type: "resources_discover",
526
+ cwd,
527
+ reason,
528
+ }), (handlerResult, extensionPath) => {
529
+ const r = handlerResult;
530
+ if (r?.skillPaths?.length)
531
+ skillPaths.push(...r.skillPaths.map((path) => ({ path, extensionPath })));
532
+ if (r?.promptPaths?.length)
533
+ promptPaths.push(...r.promptPaths.map((path) => ({ path, extensionPath })));
534
+ if (r?.themePaths?.length)
535
+ themePaths.push(...r.themePaths.map((path) => ({ path, extensionPath })));
536
+ return { done: false };
537
+ });
649
538
  return { skillPaths, promptPaths, themePaths };
650
539
  }
651
540
  /** Emit input event. Transforms chain, "handled" short-circuits. */
652
541
  async emitInput(text, images, source) {
653
- const ctx = this.createContext();
654
542
  let currentText = text;
655
543
  let currentImages = images;
656
- for (const ext of this.extensions) {
657
- for (const handler of ext.handlers.get("input") ?? []) {
658
- try {
659
- const event = { type: "input", text: currentText, images: currentImages, source };
660
- const result = (await handler(event, ctx));
661
- if (result?.action === "handled")
662
- return result;
663
- if (result?.action === "transform") {
664
- currentText = result.text;
665
- currentImages = result.images ?? currentImages;
666
- }
667
- }
668
- catch (err) {
669
- this.emitError({
670
- extensionPath: ext.path,
671
- event: "input",
672
- error: err instanceof Error ? err.message : String(err),
673
- stack: err instanceof Error ? err.stack : undefined,
674
- });
675
- }
544
+ let handled;
545
+ await this.invokeHandlers("input", () => ({
546
+ type: "input",
547
+ text: currentText,
548
+ images: currentImages,
549
+ source,
550
+ }), (handlerResult) => {
551
+ const r = handlerResult;
552
+ if (r?.action === "handled") {
553
+ handled = r;
554
+ return { done: true };
676
555
  }
677
- }
556
+ if (r?.action === "transform") {
557
+ currentText = r.text;
558
+ currentImages = r.images ?? currentImages;
559
+ }
560
+ return { done: false };
561
+ });
562
+ if (handled)
563
+ return handled;
678
564
  return currentText !== text || currentImages !== images
679
565
  ? { action: "transform", text: currentText, images: currentImages }
680
566
  : { action: "continue" };