gsd-pi 2.34.0-dev.7d38042 → 2.34.0-dev.e6d9bed
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.
- package/dist/resources/extensions/gsd/commands-prefs-wizard.js +5 -1
- package/dist/resources/extensions/gsd/docs/preferences-reference.md +10 -0
- package/dist/resources/extensions/gsd/doctor-checks.js +113 -5
- package/dist/resources/extensions/gsd/doctor-proactive.js +22 -0
- package/dist/resources/extensions/gsd/doctor.js +36 -0
- package/dist/resources/extensions/gsd/guided-flow.js +4 -2
- package/dist/resources/extensions/gsd/preferences-validation.js +38 -0
- package/dist/resources/extensions/gsd/preferences.js +2 -0
- package/dist/resources/skills/create-gsd-extension/references/events-reference.md +4 -4
- package/package.json +1 -1
- package/packages/pi-agent-core/dist/agent-loop.d.ts +14 -0
- package/packages/pi-agent-core/dist/agent-loop.d.ts.map +1 -1
- package/packages/pi-agent-core/dist/agent-loop.js +24 -27
- package/packages/pi-agent-core/dist/agent-loop.js.map +1 -1
- package/packages/pi-agent-core/dist/agent.d.ts +1 -0
- package/packages/pi-agent-core/dist/agent.d.ts.map +1 -1
- package/packages/pi-agent-core/dist/agent.js +11 -22
- package/packages/pi-agent-core/dist/agent.js.map +1 -1
- package/packages/pi-agent-core/dist/proxy.d.ts.map +1 -1
- package/packages/pi-agent-core/dist/proxy.js +2 -8
- package/packages/pi-agent-core/dist/proxy.js.map +1 -1
- package/packages/pi-agent-core/src/agent-loop.ts +30 -27
- package/packages/pi-agent-core/src/agent.ts +12 -23
- package/packages/pi-agent-core/src/proxy.ts +2 -8
- package/packages/pi-ai/dist/providers/azure-openai-responses.d.ts.map +1 -1
- package/packages/pi-ai/dist/providers/azure-openai-responses.js +5 -41
- package/packages/pi-ai/dist/providers/azure-openai-responses.js.map +1 -1
- package/packages/pi-ai/dist/providers/openai-completions.d.ts.map +1 -1
- package/packages/pi-ai/dist/providers/openai-completions.js +10 -73
- package/packages/pi-ai/dist/providers/openai-completions.js.map +1 -1
- package/packages/pi-ai/dist/providers/openai-responses.d.ts.map +1 -1
- package/packages/pi-ai/dist/providers/openai-responses.js +8 -79
- package/packages/pi-ai/dist/providers/openai-responses.js.map +1 -1
- package/packages/pi-ai/dist/providers/openai-shared.d.ts +65 -0
- package/packages/pi-ai/dist/providers/openai-shared.d.ts.map +1 -0
- package/packages/pi-ai/dist/providers/openai-shared.js +146 -0
- package/packages/pi-ai/dist/providers/openai-shared.js.map +1 -0
- package/packages/pi-ai/dist/utils/oauth/google-antigravity.d.ts.map +1 -1
- package/packages/pi-ai/dist/utils/oauth/google-antigravity.js +7 -135
- package/packages/pi-ai/dist/utils/oauth/google-antigravity.js.map +1 -1
- package/packages/pi-ai/dist/utils/oauth/google-gemini-cli.d.ts.map +1 -1
- package/packages/pi-ai/dist/utils/oauth/google-gemini-cli.js +7 -135
- package/packages/pi-ai/dist/utils/oauth/google-gemini-cli.js.map +1 -1
- package/packages/pi-ai/dist/utils/oauth/google-oauth-utils.d.ts +46 -0
- package/packages/pi-ai/dist/utils/oauth/google-oauth-utils.d.ts.map +1 -0
- package/packages/pi-ai/dist/utils/oauth/google-oauth-utils.js +160 -0
- package/packages/pi-ai/dist/utils/oauth/google-oauth-utils.js.map +1 -0
- package/packages/pi-ai/src/providers/azure-openai-responses.ts +11 -45
- package/packages/pi-ai/src/providers/openai-completions.ts +16 -86
- package/packages/pi-ai/src/providers/openai-responses.ts +15 -95
- package/packages/pi-ai/src/providers/openai-shared.ts +193 -0
- package/packages/pi-ai/src/utils/oauth/google-antigravity.ts +14 -162
- package/packages/pi-ai/src/utils/oauth/google-gemini-cli.ts +13 -161
- package/packages/pi-ai/src/utils/oauth/google-oauth-utils.ts +201 -0
- package/packages/pi-coding-agent/dist/core/agent-session.d.ts +16 -63
- package/packages/pi-coding-agent/dist/core/agent-session.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/agent-session.js +104 -641
- package/packages/pi-coding-agent/dist/core/agent-session.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/auth-storage.d.ts +0 -1
- package/packages/pi-coding-agent/dist/core/auth-storage.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/auth-storage.js +4 -35
- package/packages/pi-coding-agent/dist/core/auth-storage.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/compaction/branch-summarization.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/compaction/branch-summarization.js +5 -43
- package/packages/pi-coding-agent/dist/core/compaction/branch-summarization.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/compaction/compaction.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/compaction/compaction.js +11 -69
- package/packages/pi-coding-agent/dist/core/compaction/compaction.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/compaction/utils.d.ts +40 -0
- package/packages/pi-coding-agent/dist/core/compaction/utils.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/compaction/utils.js +78 -0
- package/packages/pi-coding-agent/dist/core/compaction/utils.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/compaction-orchestrator.d.ts +77 -0
- package/packages/pi-coding-agent/dist/core/compaction-orchestrator.d.ts.map +1 -0
- package/packages/pi-coding-agent/dist/core/compaction-orchestrator.js +331 -0
- package/packages/pi-coding-agent/dist/core/compaction-orchestrator.js.map +1 -0
- package/packages/pi-coding-agent/dist/core/extensions/index.d.ts +2 -2
- package/packages/pi-coding-agent/dist/core/extensions/index.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/extensions/index.js +1 -1
- package/packages/pi-coding-agent/dist/core/extensions/index.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/extensions/runner.d.ts +15 -0
- package/packages/pi-coding-agent/dist/core/extensions/runner.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/extensions/runner.js +129 -243
- package/packages/pi-coding-agent/dist/core/extensions/runner.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/extensions/types.d.ts +49 -42
- package/packages/pi-coding-agent/dist/core/extensions/types.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/extensions/types.js +2 -21
- package/packages/pi-coding-agent/dist/core/extensions/types.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/lock-utils.d.ts +39 -0
- package/packages/pi-coding-agent/dist/core/lock-utils.d.ts.map +1 -0
- package/packages/pi-coding-agent/dist/core/lock-utils.js +89 -0
- package/packages/pi-coding-agent/dist/core/lock-utils.js.map +1 -0
- package/packages/pi-coding-agent/dist/core/lsp/config.d.ts +2 -0
- package/packages/pi-coding-agent/dist/core/lsp/config.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/lsp/config.js +4 -1
- package/packages/pi-coding-agent/dist/core/lsp/config.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/lsp/index.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/lsp/index.js +52 -107
- package/packages/pi-coding-agent/dist/core/lsp/index.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/lsp/lspmux.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/lsp/lspmux.js +2 -21
- package/packages/pi-coding-agent/dist/core/lsp/lspmux.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/lsp/types.d.ts +0 -1
- package/packages/pi-coding-agent/dist/core/lsp/types.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/lsp/types.js +0 -28
- package/packages/pi-coding-agent/dist/core/lsp/types.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/package-manager.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/package-manager.js +2 -4
- package/packages/pi-coding-agent/dist/core/package-manager.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/resource-loader.d.ts +2 -4
- package/packages/pi-coding-agent/dist/core/resource-loader.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/resource-loader.js +33 -58
- package/packages/pi-coding-agent/dist/core/resource-loader.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/retry-handler.d.ts +87 -0
- package/packages/pi-coding-agent/dist/core/retry-handler.d.ts.map +1 -0
- package/packages/pi-coding-agent/dist/core/retry-handler.js +295 -0
- package/packages/pi-coding-agent/dist/core/retry-handler.js.map +1 -0
- package/packages/pi-coding-agent/dist/core/session-manager.d.ts +0 -1
- package/packages/pi-coding-agent/dist/core/session-manager.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/session-manager.js +3 -28
- package/packages/pi-coding-agent/dist/core/session-manager.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/skills.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/skills.js +1 -3
- package/packages/pi-coding-agent/dist/core/skills.js.map +1 -1
- package/packages/pi-coding-agent/dist/index.d.ts +1 -1
- package/packages/pi-coding-agent/dist/index.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/index.js +1 -1
- package/packages/pi-coding-agent/dist/index.js.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/session-selector.d.ts +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/session-selector.js +9 -26
- package/packages/pi-coding-agent/dist/modes/interactive/components/session-selector.js.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/tool-execution.js +1 -13
- package/packages/pi-coding-agent/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/tree-render-utils.d.ts +44 -0
- package/packages/pi-coding-agent/dist/modes/interactive/components/tree-render-utils.d.ts.map +1 -0
- package/packages/pi-coding-agent/dist/modes/interactive/components/tree-render-utils.js +61 -0
- package/packages/pi-coding-agent/dist/modes/interactive/components/tree-render-utils.js.map +1 -0
- package/packages/pi-coding-agent/dist/modes/interactive/components/tree-selector.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/tree-selector.js +6 -9
- package/packages/pi-coding-agent/dist/modes/interactive/components/tree-selector.js.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/utils/shorten-path.d.ts +6 -0
- package/packages/pi-coding-agent/dist/modes/interactive/utils/shorten-path.d.ts.map +1 -0
- package/packages/pi-coding-agent/dist/modes/interactive/utils/shorten-path.js +15 -0
- package/packages/pi-coding-agent/dist/modes/interactive/utils/shorten-path.js.map +1 -0
- package/packages/pi-coding-agent/dist/modes/print-mode.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/modes/print-mode.js +2 -30
- package/packages/pi-coding-agent/dist/modes/print-mode.js.map +1 -1
- package/packages/pi-coding-agent/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/modes/rpc/rpc-mode.js +2 -28
- package/packages/pi-coding-agent/dist/modes/rpc/rpc-mode.js.map +1 -1
- package/packages/pi-coding-agent/dist/modes/shared/command-context-actions.d.ts +19 -0
- package/packages/pi-coding-agent/dist/modes/shared/command-context-actions.d.ts.map +1 -0
- package/packages/pi-coding-agent/dist/modes/shared/command-context-actions.js +45 -0
- package/packages/pi-coding-agent/dist/modes/shared/command-context-actions.js.map +1 -0
- package/packages/pi-coding-agent/dist/utils/error.d.ts +5 -0
- package/packages/pi-coding-agent/dist/utils/error.d.ts.map +1 -0
- package/packages/pi-coding-agent/dist/utils/error.js +7 -0
- package/packages/pi-coding-agent/dist/utils/error.js.map +1 -0
- package/packages/pi-coding-agent/src/core/agent-session.ts +117 -745
- package/packages/pi-coding-agent/src/core/auth-storage.ts +4 -38
- package/packages/pi-coding-agent/src/core/compaction/branch-summarization.ts +7 -53
- package/packages/pi-coding-agent/src/core/compaction/compaction.ts +14 -74
- package/packages/pi-coding-agent/src/core/compaction/utils.ts +100 -0
- package/packages/pi-coding-agent/src/core/compaction-orchestrator.ts +424 -0
- package/packages/pi-coding-agent/src/core/extensions/index.ts +1 -21
- package/packages/pi-coding-agent/src/core/extensions/runner.ts +119 -243
- package/packages/pi-coding-agent/src/core/extensions/types.ts +50 -69
- package/packages/pi-coding-agent/src/core/lock-utils.ts +113 -0
- package/packages/pi-coding-agent/src/core/lsp/config.ts +4 -1
- package/packages/pi-coding-agent/src/core/lsp/index.ts +83 -152
- package/packages/pi-coding-agent/src/core/lsp/lspmux.ts +2 -22
- package/packages/pi-coding-agent/src/core/lsp/types.ts +0 -29
- package/packages/pi-coding-agent/src/core/package-manager.ts +1 -4
- package/packages/pi-coding-agent/src/core/resource-loader.ts +43 -67
- package/packages/pi-coding-agent/src/core/retry-handler.ts +359 -0
- package/packages/pi-coding-agent/src/core/session-manager.ts +3 -30
- package/packages/pi-coding-agent/src/core/skills.ts +1 -4
- package/packages/pi-coding-agent/src/index.ts +1 -7
- package/packages/pi-coding-agent/src/modes/interactive/components/session-selector.ts +17 -29
- package/packages/pi-coding-agent/src/modes/interactive/components/tool-execution.ts +1 -13
- package/packages/pi-coding-agent/src/modes/interactive/components/tree-render-utils.ts +81 -0
- package/packages/pi-coding-agent/src/modes/interactive/components/tree-selector.ts +14 -19
- package/packages/pi-coding-agent/src/modes/interactive/utils/shorten-path.ts +14 -0
- package/packages/pi-coding-agent/src/modes/print-mode.ts +2 -30
- package/packages/pi-coding-agent/src/modes/rpc/rpc-mode.ts +2 -28
- package/packages/pi-coding-agent/src/modes/shared/command-context-actions.ts +53 -0
- package/packages/pi-coding-agent/src/utils/error.ts +6 -0
- package/packages/pi-tui/dist/components/markdown.d.ts +5 -0
- package/packages/pi-tui/dist/components/markdown.d.ts.map +1 -1
- package/packages/pi-tui/dist/components/markdown.js +25 -31
- package/packages/pi-tui/dist/components/markdown.js.map +1 -1
- package/packages/pi-tui/dist/keys.d.ts +0 -4
- package/packages/pi-tui/dist/keys.d.ts.map +1 -1
- package/packages/pi-tui/dist/keys.js +94 -162
- package/packages/pi-tui/dist/keys.js.map +1 -1
- package/packages/pi-tui/src/components/markdown.ts +25 -29
- package/packages/pi-tui/src/keys.ts +94 -173
- package/src/resources/extensions/gsd/commands-prefs-wizard.ts +5 -1
- package/src/resources/extensions/gsd/docs/preferences-reference.md +10 -0
- package/src/resources/extensions/gsd/doctor-checks.ts +107 -5
- package/src/resources/extensions/gsd/doctor-proactive.ts +24 -0
- package/src/resources/extensions/gsd/doctor-types.ts +9 -1
- package/src/resources/extensions/gsd/doctor.ts +35 -0
- package/src/resources/extensions/gsd/guided-flow.ts +4 -2
- package/src/resources/extensions/gsd/preferences-validation.ts +38 -0
- package/src/resources/extensions/gsd/preferences.ts +2 -0
- package/src/resources/extensions/gsd/tests/doctor-git.test.ts +98 -2
- package/src/resources/extensions/gsd/tests/doctor-runtime.test.ts +59 -3
- package/src/resources/extensions/gsd/tests/preferences.test.ts +28 -0
- package/src/resources/skills/create-gsd-extension/references/events-reference.md +4 -4
|
@@ -363,245 +363,152 @@ export class ExtensionRunner {
|
|
|
363
363
|
event.type === "session_before_compact" ||
|
|
364
364
|
event.type === "session_before_tree");
|
|
365
365
|
}
|
|
366
|
-
|
|
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(
|
|
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
|
-
|
|
377
|
-
|
|
378
|
-
|
|
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:
|
|
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
|
-
|
|
402
|
-
const
|
|
403
|
-
if (!
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
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
|
-
|
|
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
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
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
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
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
|
-
|
|
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
|
-
|
|
506
|
-
|
|
507
|
-
|
|
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
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
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
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
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
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
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
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
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" };
|