@caupulican/pi-adaptative 0.81.32 → 0.81.35
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/CHANGELOG.md +22 -0
- package/dist/bundled-resources/extensions/tmux-agent-manager/README.md +69 -0
- package/dist/bundled-resources/extensions/tmux-agent-manager/index.d.ts +53 -0
- package/dist/bundled-resources/extensions/tmux-agent-manager/index.d.ts.map +1 -0
- package/dist/bundled-resources/extensions/tmux-agent-manager/index.js +1282 -0
- package/dist/bundled-resources/extensions/tmux-agent-manager/index.js.map +1 -0
- package/dist/bundled-resources/extensions/tmux-agent-manager/index.ts +1453 -0
- package/dist/bundled-resources/extensions/tmux-agent-manager/templates/builder-validator.json +14 -0
- package/dist/bundled-resources/extensions/tmux-agent-manager/templates/claude-trio.json +32 -0
- package/dist/bundled-resources/extensions/tmux-agent-manager/templates/full-provider-review.json +15 -0
- package/dist/bundled-resources/extensions/tmux-agent-manager/templates/provider-prompt-smoke.json +14 -0
- package/dist/bundled-resources/prompts/extensionify.md +5 -4
- package/dist/bundled-resources/prompts/skillify.md +5 -5
- package/dist/bundled-resources/skills/pi-harness-learning/SKILL.md +6 -3
- package/dist/config.d.ts +5 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +10 -2
- package/dist/config.js.map +1 -1
- package/dist/core/agent-session.d.ts +7 -0
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +25 -2
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/background-lane-controller.d.ts +12 -3
- package/dist/core/background-lane-controller.d.ts.map +1 -1
- package/dist/core/background-lane-controller.js +67 -26
- package/dist/core/background-lane-controller.js.map +1 -1
- package/dist/core/bash-executor.d.ts.map +1 -1
- package/dist/core/bash-executor.js +7 -3
- package/dist/core/bash-executor.js.map +1 -1
- package/dist/core/context/context-store-retention.d.ts +4 -1
- package/dist/core/context/context-store-retention.d.ts.map +1 -1
- package/dist/core/context/context-store-retention.js +42 -151
- package/dist/core/context/context-store-retention.js.map +1 -1
- package/dist/core/context-pipeline.d.ts.map +1 -1
- package/dist/core/context-pipeline.js +6 -6
- package/dist/core/context-pipeline.js.map +1 -1
- package/dist/core/exec.d.ts.map +1 -1
- package/dist/core/exec.js +25 -39
- package/dist/core/exec.js.map +1 -1
- package/dist/core/extensions/loader.d.ts +9 -2
- package/dist/core/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js +105 -21
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/footer-data-provider.d.ts.map +1 -1
- package/dist/core/footer-data-provider.js +2 -0
- package/dist/core/footer-data-provider.js.map +1 -1
- package/dist/core/goals/goal-state.d.ts +10 -0
- package/dist/core/goals/goal-state.d.ts.map +1 -1
- package/dist/core/goals/goal-state.js +37 -0
- package/dist/core/goals/goal-state.js.map +1 -1
- package/dist/core/goals/goal-tool-core.d.ts +11 -0
- package/dist/core/goals/goal-tool-core.d.ts.map +1 -1
- package/dist/core/goals/goal-tool-core.js +51 -1
- package/dist/core/goals/goal-tool-core.js.map +1 -1
- package/dist/core/improvement-loop.d.ts.map +1 -1
- package/dist/core/improvement-loop.js +26 -5
- package/dist/core/improvement-loop.js.map +1 -1
- package/dist/core/models/fitness-store.d.ts.map +1 -1
- package/dist/core/models/fitness-store.js +1 -1
- package/dist/core/models/fitness-store.js.map +1 -1
- package/dist/core/models/local-runtime.d.ts +6 -4
- package/dist/core/models/local-runtime.d.ts.map +1 -1
- package/dist/core/models/local-runtime.js +108 -36
- package/dist/core/models/local-runtime.js.map +1 -1
- package/dist/core/output-guard.d.ts.map +1 -1
- package/dist/core/output-guard.js +23 -8
- package/dist/core/output-guard.js.map +1 -1
- package/dist/core/package-manager.d.ts.map +1 -1
- package/dist/core/package-manager.js +44 -59
- package/dist/core/package-manager.js.map +1 -1
- package/dist/core/profile-resource-selection.d.ts +16 -0
- package/dist/core/profile-resource-selection.d.ts.map +1 -1
- package/dist/core/profile-resource-selection.js +41 -0
- package/dist/core/profile-resource-selection.js.map +1 -1
- package/dist/core/reflection-controller.d.ts.map +1 -1
- package/dist/core/reflection-controller.js +18 -1
- package/dist/core/reflection-controller.js.map +1 -1
- package/dist/core/reload-blockers.d.ts +1 -0
- package/dist/core/reload-blockers.d.ts.map +1 -1
- package/dist/core/reload-blockers.js +6 -2
- package/dist/core/reload-blockers.js.map +1 -1
- package/dist/core/resource-loader.d.ts +2 -0
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +50 -28
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +1 -1
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/slash-commands.d.ts.map +1 -1
- package/dist/core/slash-commands.js +1 -1
- package/dist/core/slash-commands.js.map +1 -1
- package/dist/core/toolkit/script-runner.d.ts.map +1 -1
- package/dist/core/toolkit/script-runner.js +58 -24
- package/dist/core/toolkit/script-runner.js.map +1 -1
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +13 -26
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/extensionify.d.ts +2 -1
- package/dist/core/tools/extensionify.d.ts.map +1 -1
- package/dist/core/tools/extensionify.js +11 -8
- package/dist/core/tools/extensionify.js.map +1 -1
- package/dist/core/tools/find.d.ts.map +1 -1
- package/dist/core/tools/find.js +54 -48
- package/dist/core/tools/find.js.map +1 -1
- package/dist/core/tools/git-filter.d.ts.map +1 -1
- package/dist/core/tools/git-filter.js +20 -32
- package/dist/core/tools/git-filter.js.map +1 -1
- package/dist/core/tools/goal.d.ts +1 -1
- package/dist/core/tools/goal.d.ts.map +1 -1
- package/dist/core/tools/goal.js +10 -3
- package/dist/core/tools/goal.js.map +1 -1
- package/dist/core/tools/grep.d.ts.map +1 -1
- package/dist/core/tools/grep.js +89 -80
- package/dist/core/tools/grep.js.map +1 -1
- package/dist/core/tools/output-accumulator.d.ts +2 -0
- package/dist/core/tools/output-accumulator.d.ts.map +1 -1
- package/dist/core/tools/output-accumulator.js +7 -4
- package/dist/core/tools/output-accumulator.js.map +1 -1
- package/dist/core/tools/read.d.ts.map +1 -1
- package/dist/core/tools/read.js +4 -3
- package/dist/core/tools/read.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts +2 -0
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +23 -4
- package/dist/main.js.map +1 -1
- package/dist/migrations.d.ts.map +1 -1
- package/dist/migrations.js +18 -4
- package/dist/migrations.js.map +1 -1
- package/dist/modes/interactive/auth-dialogs-controller.d.ts +10 -0
- package/dist/modes/interactive/auth-dialogs-controller.d.ts.map +1 -1
- package/dist/modes/interactive/auth-dialogs-controller.js +94 -27
- package/dist/modes/interactive/auth-dialogs-controller.js.map +1 -1
- package/dist/modes/interactive/auto-learn-controller.d.ts.map +1 -1
- package/dist/modes/interactive/auto-learn-controller.js +2 -1
- package/dist/modes/interactive/auto-learn-controller.js.map +1 -1
- package/dist/modes/interactive/components/bordered-loader.d.ts +1 -0
- package/dist/modes/interactive/components/bordered-loader.d.ts.map +1 -1
- package/dist/modes/interactive/components/bordered-loader.js +8 -0
- package/dist/modes/interactive/components/bordered-loader.js.map +1 -1
- package/dist/modes/interactive/components/extension-editor.d.ts.map +1 -1
- package/dist/modes/interactive/components/extension-editor.js +6 -15
- package/dist/modes/interactive/components/extension-editor.js.map +1 -1
- package/dist/modes/interactive/components/login-dialog.d.ts +3 -1
- package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -1
- package/dist/modes/interactive/components/login-dialog.js +20 -8
- package/dist/modes/interactive/components/login-dialog.js.map +1 -1
- package/dist/modes/interactive/components/profile-resource-editor.d.ts +4 -1
- package/dist/modes/interactive/components/profile-resource-editor.d.ts.map +1 -1
- package/dist/modes/interactive/components/profile-resource-editor.js +22 -39
- package/dist/modes/interactive/components/profile-resource-editor.js.map +1 -1
- package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/session-selector.js +1 -1
- package/dist/modes/interactive/components/session-selector.js.map +1 -1
- package/dist/modes/interactive/config-backup.d.ts +1 -0
- package/dist/modes/interactive/config-backup.d.ts.map +1 -1
- package/dist/modes/interactive/config-backup.js +14 -3
- package/dist/modes/interactive/config-backup.js.map +1 -1
- package/dist/modes/interactive/editor-overlay-host.d.ts +12 -0
- package/dist/modes/interactive/editor-overlay-host.d.ts.map +1 -1
- package/dist/modes/interactive/editor-overlay-host.js +55 -0
- package/dist/modes/interactive/editor-overlay-host.js.map +1 -1
- package/dist/modes/interactive/extension-ui-host.d.ts +2 -1
- package/dist/modes/interactive/extension-ui-host.d.ts.map +1 -1
- package/dist/modes/interactive/extension-ui-host.js +161 -96
- package/dist/modes/interactive/extension-ui-host.js.map +1 -1
- package/dist/modes/interactive/external-editor.d.ts.map +1 -1
- package/dist/modes/interactive/external-editor.js +23 -28
- package/dist/modes/interactive/external-editor.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +14 -8
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/profile-menu-controller.d.ts +5 -1
- package/dist/modes/interactive/profile-menu-controller.d.ts.map +1 -1
- package/dist/modes/interactive/profile-menu-controller.js +118 -24
- package/dist/modes/interactive/profile-menu-controller.js.map +1 -1
- package/dist/modes/interactive/resource-shell-commands.d.ts +1 -0
- package/dist/modes/interactive/resource-shell-commands.d.ts.map +1 -1
- package/dist/modes/interactive/resource-shell-commands.js +5 -1
- package/dist/modes/interactive/resource-shell-commands.js.map +1 -1
- package/dist/modes/interactive/session-flow-commands.d.ts.map +1 -1
- package/dist/modes/interactive/session-flow-commands.js +100 -7
- package/dist/modes/interactive/session-flow-commands.js.map +1 -1
- package/dist/modes/interactive/session-io-commands.d.ts.map +1 -1
- package/dist/modes/interactive/session-io-commands.js +80 -50
- package/dist/modes/interactive/session-io-commands.js.map +1 -1
- package/dist/modes/interactive/startup-checks.d.ts.map +1 -1
- package/dist/modes/interactive/startup-checks.js +14 -17
- package/dist/modes/interactive/startup-checks.js.map +1 -1
- package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-client.js +20 -19
- package/dist/modes/rpc/rpc-client.js.map +1 -1
- package/dist/package-manager-cli.d.ts.map +1 -1
- package/dist/package-manager-cli.js +10 -19
- package/dist/package-manager-cli.js.map +1 -1
- package/dist/utils/child-process.d.ts +13 -7
- package/dist/utils/child-process.d.ts.map +1 -1
- package/dist/utils/child-process.js +56 -3
- package/dist/utils/child-process.js.map +1 -1
- package/dist/utils/clipboard-image.d.ts.map +1 -1
- package/dist/utils/clipboard-image.js +3 -2
- package/dist/utils/clipboard-image.js.map +1 -1
- package/dist/utils/clipboard.d.ts.map +1 -1
- package/dist/utils/clipboard.js +17 -10
- package/dist/utils/clipboard.js.map +1 -1
- package/dist/utils/external-editor-command.d.ts +8 -0
- package/dist/utils/external-editor-command.d.ts.map +1 -0
- package/dist/utils/external-editor-command.js +60 -0
- package/dist/utils/external-editor-command.js.map +1 -0
- package/dist/utils/paths.d.ts.map +1 -1
- package/dist/utils/paths.js +10 -2
- package/dist/utils/paths.js.map +1 -1
- package/dist/utils/tools-manager.d.ts.map +1 -1
- package/dist/utils/tools-manager.js +23 -10
- package/dist/utils/tools-manager.js.map +1 -1
- package/dist/utils/work-directory.d.ts +36 -0
- package/dist/utils/work-directory.d.ts.map +1 -0
- package/dist/utils/work-directory.js +462 -0
- package/dist/utils/work-directory.js.map +1 -0
- package/docs/index.md +2 -0
- package/docs/resources.md +2 -2
- package/docs/rpc.md +1 -1
- package/docs/tmux-agent-manager.md +48 -0
- package/docs/windows.md +100 -7
- package/docs/work-directory.md +41 -0
- package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/npm-shrinkwrap.json +12 -12
- package/package.json +4 -4
|
@@ -12,6 +12,8 @@ export interface EditorOverlayUi {
|
|
|
12
12
|
export interface EditorOverlaySwapOptions {
|
|
13
13
|
/** Component to focus after mounting. Defaults to the mounted component. */
|
|
14
14
|
focus?: Component;
|
|
15
|
+
/** Called exactly once when a later swap or explicit unmount replaces this component. */
|
|
16
|
+
onUnmount?: () => void;
|
|
15
17
|
/**
|
|
16
18
|
* Whether to `setFocus` the target (default) or `restoreFocus` it. The latter
|
|
17
19
|
* prefers the topmost visible overlay and is used when returning to the editor
|
|
@@ -38,11 +40,21 @@ export interface EditorOverlaySwapOptions {
|
|
|
38
40
|
export declare class EditorOverlayHost {
|
|
39
41
|
private readonly container;
|
|
40
42
|
private readonly ui;
|
|
43
|
+
private mountedOnUnmount;
|
|
41
44
|
constructor(container: Container, ui: EditorOverlayUi);
|
|
45
|
+
private notifyMountedUnmount;
|
|
42
46
|
/**
|
|
43
47
|
* Replace whatever the editor container currently holds with `component`,
|
|
44
48
|
* focus a target, and (by default) request a render.
|
|
45
49
|
*/
|
|
46
50
|
swap(component: Component, options?: EditorOverlaySwapOptions): void;
|
|
51
|
+
/** Mount a callback-driven selector and settle it if another overlay supersedes it. */
|
|
52
|
+
showSelector(getRestoreComponent: () => Component, create: (done: () => void) => {
|
|
53
|
+
component: Component;
|
|
54
|
+
focus: Component;
|
|
55
|
+
onSuperseded?: () => void;
|
|
56
|
+
}): void;
|
|
57
|
+
/** Settle and remove the currently mounted component without mounting a replacement. */
|
|
58
|
+
unmount(): void;
|
|
47
59
|
}
|
|
48
60
|
//# sourceMappingURL=editor-overlay-host.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"editor-overlay-host.d.ts","sourceRoot":"","sources":["../../../src/modes/interactive/editor-overlay-host.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAE/D,oEAAoE;AACpE,MAAM,MAAM,sBAAsB,GAAG,KAAK,GAAG,SAAS,CAAC;AAEvD,2EAA2E;AAC3E,MAAM,MAAM,uBAAuB,GAAG,SAAS,GAAG,MAAM,GAAG,MAAM,CAAC;AAElE,6CAA6C;AAC7C,MAAM,WAAW,eAAe;IAC/B,QAAQ,CAAC,SAAS,EAAE,SAAS,GAAG,IAAI,GAAG,IAAI,CAAC;IAC5C,YAAY,CAAC,SAAS,EAAE,SAAS,GAAG,IAAI,GAAG,IAAI,CAAC;IAChD,aAAa,CAAC,KAAK,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;CACrC;AAED,MAAM,WAAW,wBAAwB;IACxC,4EAA4E;IAC5E,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB;;;;OAIG;IACH,SAAS,CAAC,EAAE,sBAAsB,CAAC;IACnC;;;;;OAKG;IACH,MAAM,CAAC,EAAE,uBAAuB,CAAC;CACjC;AAED;;;;;;;;GAQG;AACH,qBAAa,iBAAiB;IAC7B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAY;IACtC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAkB;
|
|
1
|
+
{"version":3,"file":"editor-overlay-host.d.ts","sourceRoot":"","sources":["../../../src/modes/interactive/editor-overlay-host.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAE/D,oEAAoE;AACpE,MAAM,MAAM,sBAAsB,GAAG,KAAK,GAAG,SAAS,CAAC;AAEvD,2EAA2E;AAC3E,MAAM,MAAM,uBAAuB,GAAG,SAAS,GAAG,MAAM,GAAG,MAAM,CAAC;AAElE,6CAA6C;AAC7C,MAAM,WAAW,eAAe;IAC/B,QAAQ,CAAC,SAAS,EAAE,SAAS,GAAG,IAAI,GAAG,IAAI,CAAC;IAC5C,YAAY,CAAC,SAAS,EAAE,SAAS,GAAG,IAAI,GAAG,IAAI,CAAC;IAChD,aAAa,CAAC,KAAK,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;CACrC;AAED,MAAM,WAAW,wBAAwB;IACxC,4EAA4E;IAC5E,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,yFAAyF;IACzF,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;IACvB;;;;OAIG;IACH,SAAS,CAAC,EAAE,sBAAsB,CAAC;IACnC;;;;;OAKG;IACH,MAAM,CAAC,EAAE,uBAAuB,CAAC;CACjC;AAED;;;;;;;;GAQG;AACH,qBAAa,iBAAiB;IAC7B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAY;IACtC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAkB;IACrC,OAAO,CAAC,gBAAgB,CAA2B;IAEnD,YAAY,SAAS,EAAE,SAAS,EAAE,EAAE,EAAE,eAAe,EAGpD;IAED,OAAO,CAAC,oBAAoB;IAc5B;;;OAGG;IACH,IAAI,CAAC,SAAS,EAAE,SAAS,EAAE,OAAO,GAAE,wBAA6B,GAAG,IAAI,CAqBvE;IAED,uFAAuF;IACvF,YAAY,CACX,mBAAmB,EAAE,MAAM,SAAS,EACpC,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,IAAI,KAAK;QAC7B,SAAS,EAAE,SAAS,CAAC;QACrB,KAAK,EAAE,SAAS,CAAC;QACjB,YAAY,CAAC,EAAE,MAAM,IAAI,CAAC;KAC1B,GACC,IAAI,CA4BN;IAED,wFAAwF;IACxF,OAAO,IAAI,IAAI,CAGd;CACD","sourcesContent":["import type { Component, Container } from \"@caupulican/pi-tui\";\n\n/** Focus operation the host performs after mounting a component. */\nexport type EditorOverlayFocusMode = \"set\" | \"restore\";\n\n/** How the host requests a render after swapping the mounted component. */\nexport type EditorOverlayRenderMode = \"default\" | \"sync\" | \"none\";\n\n/** The subset of the TUI the host drives. */\nexport interface EditorOverlayUi {\n\tsetFocus(component: Component | null): void;\n\trestoreFocus(component: Component | null): void;\n\trequestRender(force?: boolean): void;\n}\n\nexport interface EditorOverlaySwapOptions {\n\t/** Component to focus after mounting. Defaults to the mounted component. */\n\tfocus?: Component;\n\t/** Called exactly once when a later swap or explicit unmount replaces this component. */\n\tonUnmount?: () => void;\n\t/**\n\t * Whether to `setFocus` the target (default) or `restoreFocus` it. The latter\n\t * prefers the topmost visible overlay and is used when returning to the editor\n\t * from a selector.\n\t */\n\tfocusMode?: EditorOverlayFocusMode;\n\t/**\n\t * Render request issued after the swap:\n\t * - `\"default\"` (default): `requestRender()`\n\t * - `\"sync\"`: `requestRender(true)` — force an immediate paint\n\t * - `\"none\"`: leave rendering to the caller\n\t */\n\trender?: EditorOverlayRenderMode;\n}\n\n/**\n * Owns the single-slot editor container and performs the recurring\n * \"clear → mount one component → focus a target → request a render\" swap that\n * interactive mode uses to show overlays (selectors, dialogs, loaders) in place\n * of the editor and to restore the editor afterwards.\n *\n * The host is stateless beyond its container/ui references: every swap names the\n * component to mount, so a changing active editor never has to be tracked here.\n */\nexport class EditorOverlayHost {\n\tprivate readonly container: Container;\n\tprivate readonly ui: EditorOverlayUi;\n\tprivate mountedOnUnmount: (() => void) | undefined;\n\n\tconstructor(container: Container, ui: EditorOverlayUi) {\n\t\tthis.container = container;\n\t\tthis.ui = ui;\n\t}\n\n\tprivate notifyMountedUnmount(): void {\n\t\t// Unmount callbacks may synchronously mount another overlay. Drain those nested generations\n\t\t// before the caller installs its replacement so no reentrant component is displaced silently.\n\t\twhile (this.mountedOnUnmount) {\n\t\t\tconst onUnmount = this.mountedOnUnmount;\n\t\t\tthis.mountedOnUnmount = undefined;\n\t\t\ttry {\n\t\t\t\tonUnmount();\n\t\t\t} catch {\n\t\t\t\t// A defective overlay cleanup must not strand the UI on the displaced component.\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Replace whatever the editor container currently holds with `component`,\n\t * focus a target, and (by default) request a render.\n\t */\n\tswap(component: Component, options: EditorOverlaySwapOptions = {}): void {\n\t\tthis.notifyMountedUnmount();\n\t\tthis.container.clear();\n\t\tthis.container.addChild(component);\n\t\tthis.mountedOnUnmount = options.onUnmount;\n\t\tconst target = options.focus ?? component;\n\t\tif (options.focusMode === \"restore\") {\n\t\t\tthis.ui.restoreFocus(target);\n\t\t} else {\n\t\t\tthis.ui.setFocus(target);\n\t\t}\n\t\tswitch (options.render ?? \"default\") {\n\t\t\tcase \"default\":\n\t\t\t\tthis.ui.requestRender();\n\t\t\t\tbreak;\n\t\t\tcase \"sync\":\n\t\t\t\tthis.ui.requestRender(true);\n\t\t\t\tbreak;\n\t\t\tcase \"none\":\n\t\t\t\tbreak;\n\t\t}\n\t}\n\n\t/** Mount a callback-driven selector and settle it if another overlay supersedes it. */\n\tshowSelector(\n\t\tgetRestoreComponent: () => Component,\n\t\tcreate: (done: () => void) => {\n\t\t\tcomponent: Component;\n\t\t\tfocus: Component;\n\t\t\tonSuperseded?: () => void;\n\t\t},\n\t): void {\n\t\tlet settled = false;\n\t\tconst done = () => {\n\t\t\tif (settled) return;\n\t\t\tsettled = true;\n\t\t\tthis.swap(getRestoreComponent(), { focusMode: \"restore\", render: \"none\" });\n\t\t};\n\t\tconst mounted = create(done);\n\t\tthis.swap(mounted.component, {\n\t\t\tfocus: mounted.focus,\n\t\t\tonUnmount: () => {\n\t\t\t\tif (settled) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\t(mounted.component as Component & { dispose?: () => void }).dispose?.();\n\t\t\t\t\t} catch {\n\t\t\t\t\t\t// Disposal is best effort after normal completion.\n\t\t\t\t\t}\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tsettled = true;\n\t\t\t\ttry {\n\t\t\t\t\t(mounted.component as Component & { dispose?: () => void }).dispose?.();\n\t\t\t\t} catch {\n\t\t\t\t\t// Supersession still has to settle when component cleanup fails.\n\t\t\t\t}\n\t\t\t\tmounted.onSuperseded?.();\n\t\t\t},\n\t\t});\n\t}\n\n\t/** Settle and remove the currently mounted component without mounting a replacement. */\n\tunmount(): void {\n\t\tthis.notifyMountedUnmount();\n\t\tthis.container.clear();\n\t}\n}\n"]}
|
|
@@ -10,17 +10,34 @@
|
|
|
10
10
|
export class EditorOverlayHost {
|
|
11
11
|
container;
|
|
12
12
|
ui;
|
|
13
|
+
mountedOnUnmount;
|
|
13
14
|
constructor(container, ui) {
|
|
14
15
|
this.container = container;
|
|
15
16
|
this.ui = ui;
|
|
16
17
|
}
|
|
18
|
+
notifyMountedUnmount() {
|
|
19
|
+
// Unmount callbacks may synchronously mount another overlay. Drain those nested generations
|
|
20
|
+
// before the caller installs its replacement so no reentrant component is displaced silently.
|
|
21
|
+
while (this.mountedOnUnmount) {
|
|
22
|
+
const onUnmount = this.mountedOnUnmount;
|
|
23
|
+
this.mountedOnUnmount = undefined;
|
|
24
|
+
try {
|
|
25
|
+
onUnmount();
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
// A defective overlay cleanup must not strand the UI on the displaced component.
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
17
32
|
/**
|
|
18
33
|
* Replace whatever the editor container currently holds with `component`,
|
|
19
34
|
* focus a target, and (by default) request a render.
|
|
20
35
|
*/
|
|
21
36
|
swap(component, options = {}) {
|
|
37
|
+
this.notifyMountedUnmount();
|
|
22
38
|
this.container.clear();
|
|
23
39
|
this.container.addChild(component);
|
|
40
|
+
this.mountedOnUnmount = options.onUnmount;
|
|
24
41
|
const target = options.focus ?? component;
|
|
25
42
|
if (options.focusMode === "restore") {
|
|
26
43
|
this.ui.restoreFocus(target);
|
|
@@ -39,5 +56,43 @@ export class EditorOverlayHost {
|
|
|
39
56
|
break;
|
|
40
57
|
}
|
|
41
58
|
}
|
|
59
|
+
/** Mount a callback-driven selector and settle it if another overlay supersedes it. */
|
|
60
|
+
showSelector(getRestoreComponent, create) {
|
|
61
|
+
let settled = false;
|
|
62
|
+
const done = () => {
|
|
63
|
+
if (settled)
|
|
64
|
+
return;
|
|
65
|
+
settled = true;
|
|
66
|
+
this.swap(getRestoreComponent(), { focusMode: "restore", render: "none" });
|
|
67
|
+
};
|
|
68
|
+
const mounted = create(done);
|
|
69
|
+
this.swap(mounted.component, {
|
|
70
|
+
focus: mounted.focus,
|
|
71
|
+
onUnmount: () => {
|
|
72
|
+
if (settled) {
|
|
73
|
+
try {
|
|
74
|
+
mounted.component.dispose?.();
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
// Disposal is best effort after normal completion.
|
|
78
|
+
}
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
settled = true;
|
|
82
|
+
try {
|
|
83
|
+
mounted.component.dispose?.();
|
|
84
|
+
}
|
|
85
|
+
catch {
|
|
86
|
+
// Supersession still has to settle when component cleanup fails.
|
|
87
|
+
}
|
|
88
|
+
mounted.onSuperseded?.();
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
/** Settle and remove the currently mounted component without mounting a replacement. */
|
|
93
|
+
unmount() {
|
|
94
|
+
this.notifyMountedUnmount();
|
|
95
|
+
this.container.clear();
|
|
96
|
+
}
|
|
42
97
|
}
|
|
43
98
|
//# sourceMappingURL=editor-overlay-host.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"editor-overlay-host.js","sourceRoot":"","sources":["../../../src/modes/interactive/editor-overlay-host.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"editor-overlay-host.js","sourceRoot":"","sources":["../../../src/modes/interactive/editor-overlay-host.ts"],"names":[],"mappings":"AAmCA;;;;;;;;GAQG;AACH,MAAM,OAAO,iBAAiB;IACZ,SAAS,CAAY;IACrB,EAAE,CAAkB;IAC7B,gBAAgB,CAA2B;IAEnD,YAAY,SAAoB,EAAE,EAAmB,EAAE;QACtD,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC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C,MAIC,EACM;QACP,IAAI,OAAO,GAAG,KAAK,CAAC;QACpB,MAAM,IAAI,GAAG,GAAG,EAAE,CAAC;YAClB,IAAI,OAAO;gBAAE,OAAO;YACpB,OAAO,GAAG,IAAI,CAAC;YACf,IAAI,CAAC,IAAI,CAAC,mBAAmB,EAAE,EAAE,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;QAAA,CAC3E,CAAC;QACF,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;QAC7B,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE;YAC5B,KAAK,EAAE,OAAO,CAAC,KAAK;YACpB,SAAS,EAAE,GAAG,EAAE,CAAC;gBAChB,IAAI,OAAO,EAAE,CAAC;oBACb,IAAI,CAAC;wBACH,OAAO,CAAC,SAAkD,CAAC,OAAO,EAAE,EAAE,CAAC;oBACzE,CAAC;oBAAC,MAAM,CAAC;wBACR,mDAAmD;oBACpD,CAAC;oBACD,OAAO;gBACR,CAAC;gBACD,OAAO,GAAG,IAAI,CAAC;gBACf,IAAI,CAAC;oBACH,OAAO,CAAC,SAAkD,CAAC,OAAO,EAAE,EAAE,CAAC;gBACzE,CAAC;gBAAC,MAAM,CAAC;oBACR,iEAAiE;gBAClE,CAAC;gBACD,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC;YAAA,CACzB;SACD,CAAC,CAAC;IAAA,CACH;IAED,wFAAwF;IACxF,OAAO,GAAS;QACf,IAAI,CAAC,oBAAoB,EAAE,CAAC;QAC5B,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;IAAA,CACvB;CACD","sourcesContent":["import type { Component, Container } from \"@caupulican/pi-tui\";\n\n/** Focus operation the host performs after mounting a component. */\nexport type EditorOverlayFocusMode = \"set\" | \"restore\";\n\n/** How the host requests a render after swapping the mounted component. */\nexport type EditorOverlayRenderMode = \"default\" | \"sync\" | \"none\";\n\n/** The subset of the TUI the host drives. */\nexport interface EditorOverlayUi {\n\tsetFocus(component: Component | null): void;\n\trestoreFocus(component: Component | null): void;\n\trequestRender(force?: boolean): void;\n}\n\nexport interface EditorOverlaySwapOptions {\n\t/** Component to focus after mounting. Defaults to the mounted component. */\n\tfocus?: Component;\n\t/** Called exactly once when a later swap or explicit unmount replaces this component. */\n\tonUnmount?: () => void;\n\t/**\n\t * Whether to `setFocus` the target (default) or `restoreFocus` it. The latter\n\t * prefers the topmost visible overlay and is used when returning to the editor\n\t * from a selector.\n\t */\n\tfocusMode?: EditorOverlayFocusMode;\n\t/**\n\t * Render request issued after the swap:\n\t * - `\"default\"` (default): `requestRender()`\n\t * - `\"sync\"`: `requestRender(true)` — force an immediate paint\n\t * - `\"none\"`: leave rendering to the caller\n\t */\n\trender?: EditorOverlayRenderMode;\n}\n\n/**\n * Owns the single-slot editor container and performs the recurring\n * \"clear → mount one component → focus a target → request a render\" swap that\n * interactive mode uses to show overlays (selectors, dialogs, loaders) in place\n * of the editor and to restore the editor afterwards.\n *\n * The host is stateless beyond its container/ui references: every swap names the\n * component to mount, so a changing active editor never has to be tracked here.\n */\nexport class EditorOverlayHost {\n\tprivate readonly container: Container;\n\tprivate readonly ui: EditorOverlayUi;\n\tprivate mountedOnUnmount: (() => void) | undefined;\n\n\tconstructor(container: Container, ui: EditorOverlayUi) {\n\t\tthis.container = container;\n\t\tthis.ui = ui;\n\t}\n\n\tprivate notifyMountedUnmount(): void {\n\t\t// Unmount callbacks may synchronously mount another overlay. Drain those nested generations\n\t\t// before the caller installs its replacement so no reentrant component is displaced silently.\n\t\twhile (this.mountedOnUnmount) {\n\t\t\tconst onUnmount = this.mountedOnUnmount;\n\t\t\tthis.mountedOnUnmount = undefined;\n\t\t\ttry {\n\t\t\t\tonUnmount();\n\t\t\t} catch {\n\t\t\t\t// A defective overlay cleanup must not strand the UI on the displaced component.\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Replace whatever the editor container currently holds with `component`,\n\t * focus a target, and (by default) request a render.\n\t */\n\tswap(component: Component, options: EditorOverlaySwapOptions = {}): void {\n\t\tthis.notifyMountedUnmount();\n\t\tthis.container.clear();\n\t\tthis.container.addChild(component);\n\t\tthis.mountedOnUnmount = options.onUnmount;\n\t\tconst target = options.focus ?? component;\n\t\tif (options.focusMode === \"restore\") {\n\t\t\tthis.ui.restoreFocus(target);\n\t\t} else {\n\t\t\tthis.ui.setFocus(target);\n\t\t}\n\t\tswitch (options.render ?? \"default\") {\n\t\t\tcase \"default\":\n\t\t\t\tthis.ui.requestRender();\n\t\t\t\tbreak;\n\t\t\tcase \"sync\":\n\t\t\t\tthis.ui.requestRender(true);\n\t\t\t\tbreak;\n\t\t\tcase \"none\":\n\t\t\t\tbreak;\n\t\t}\n\t}\n\n\t/** Mount a callback-driven selector and settle it if another overlay supersedes it. */\n\tshowSelector(\n\t\tgetRestoreComponent: () => Component,\n\t\tcreate: (done: () => void) => {\n\t\t\tcomponent: Component;\n\t\t\tfocus: Component;\n\t\t\tonSuperseded?: () => void;\n\t\t},\n\t): void {\n\t\tlet settled = false;\n\t\tconst done = () => {\n\t\t\tif (settled) return;\n\t\t\tsettled = true;\n\t\t\tthis.swap(getRestoreComponent(), { focusMode: \"restore\", render: \"none\" });\n\t\t};\n\t\tconst mounted = create(done);\n\t\tthis.swap(mounted.component, {\n\t\t\tfocus: mounted.focus,\n\t\t\tonUnmount: () => {\n\t\t\t\tif (settled) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\t(mounted.component as Component & { dispose?: () => void }).dispose?.();\n\t\t\t\t\t} catch {\n\t\t\t\t\t\t// Disposal is best effort after normal completion.\n\t\t\t\t\t}\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tsettled = true;\n\t\t\t\ttry {\n\t\t\t\t\t(mounted.component as Component & { dispose?: () => void }).dispose?.();\n\t\t\t\t} catch {\n\t\t\t\t\t// Supersession still has to settle when component cleanup fails.\n\t\t\t\t}\n\t\t\t\tmounted.onSuperseded?.();\n\t\t\t},\n\t\t});\n\t}\n\n\t/** Settle and remove the currently mounted component without mounting a replacement. */\n\tunmount(): void {\n\t\tthis.notifyMountedUnmount();\n\t\tthis.container.clear();\n\t}\n}\n"]}
|
|
@@ -36,7 +36,6 @@ export interface ExtensionUiHostUi {
|
|
|
36
36
|
readonly footerDataProvider: FooterDataProvider;
|
|
37
37
|
readonly headerContainer: Container;
|
|
38
38
|
readonly chatContainer: Container;
|
|
39
|
-
readonly editorContainer: Container;
|
|
40
39
|
readonly defaultEditor: CustomEditor;
|
|
41
40
|
readonly widgetContainerAbove: Container;
|
|
42
41
|
readonly widgetContainerBelow: Container;
|
|
@@ -72,6 +71,8 @@ export declare class ExtensionUiHost {
|
|
|
72
71
|
private extensionSelector;
|
|
73
72
|
private extensionInput;
|
|
74
73
|
private extensionEditor;
|
|
74
|
+
/** Settles the mounted extension dialog before another dialog can replace its overlay. */
|
|
75
|
+
private activeExtensionDialogCancel;
|
|
75
76
|
private extensionTerminalInputUnsubscribers;
|
|
76
77
|
private extensionWidgetsAbove;
|
|
77
78
|
private extensionWidgetsBelow;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extension-ui-host.d.ts","sourceRoot":"","sources":["../../../src/modes/interactive/extension-ui-host.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EACX,oBAAoB,EACpB,SAAS,EACT,eAAe,EAEf,sBAAsB,EAGtB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,SAAS,EAA4B,KAAK,GAAG,EAAE,MAAM,oBAAoB,CAAC;AACnF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EACX,2BAA2B,EAG3B,eAAe,EACf,kBAAkB,EAClB,wBAAwB,EAExB,MAAM,gCAAgC,CAAC;AACxC,OAAO,KAAK,EAAE,kBAAkB,EAA8B,MAAM,oCAAoC,CAAC;AACzG,OAAO,KAAK,EAAE,kBA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BAAkB,CAAC,aAAa,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAgB7E;CACD","sourcesContent":["/**\n * Extension UI host.\n *\n * Extracted verbatim from interactive-mode.ts (god-file decomposition). Owns the interactive-mode\n * surface of the extension UI API: extension-provided dialogs (selector / confirm / input / multi-line\n * editor / custom component), widget mounting above and below the editor, extension status text, custom\n * footer and header swaps, the custom editor-component swap, keyboard-shortcut wiring, terminal-input\n * listeners, and the `ExtensionUIContext` handed to extensions. It owns exactly the state this cluster\n * mutates (the live dialog components, the widget maps, the terminal-input unsubscribers, the custom\n * footer/header, and the current custom-editor factory) and reaches everything else — the mutable\n * `editor`, the render-core containers, the working-indicator, autocomplete wiring, theme/tools state —\n * through a narrow deps/ui surface rather than the whole InteractiveMode instance. Extensions must see\n * identical behavior, so the render-core operations (working indicator, hidden-thinking label,\n * autocomplete rebuild) stay host-side and are invoked here as delegations.\n */\n\nimport type {\n\tAutocompleteProvider,\n\tComponent,\n\tEditorComponent,\n\tKeyId,\n\tLoaderIndicatorOptions,\n\tOverlayHandle,\n\tOverlayOptions,\n} from \"@caupulican/pi-tui\";\nimport { Container, matchesKey, Spacer, Text, type TUI } from \"@caupulican/pi-tui\";\nimport type { AgentSession } from \"../../core/agent-session.ts\";\nimport type {\n\tAutocompleteProviderFactory,\n\tEditorFactory,\n\tExtensionContext,\n\tExtensionRunner,\n\tExtensionUIContext,\n\tExtensionUIDialogOptions,\n\tExtensionWidgetOptions,\n} from \"../../core/extensions/index.ts\";\nimport type { FooterDataProvider, ReadonlyFooterDataProvider } from \"../../core/footer-data-provider.ts\";\nimport type { KeybindingsManager } from \"../../core/keybindings.ts\";\nimport type { CustomEditor } from \"./components/custom-editor.ts\";\nimport { ExtensionEditorComponent } from \"./components/extension-editor.ts\";\nimport { ExtensionInputComponent } from \"./components/extension-input.ts\";\nimport { ExtensionSelectorComponent } from \"./components/extension-selector.ts\";\nimport type { FooterComponent } from \"./components/footer.ts\";\nimport type { EditorOverlayHost } from \"./editor-overlay-host.ts\";\nimport {\n\tgetAvailableThemesWithPaths,\n\tgetEditorTheme,\n\tgetThemeByName,\n\tsetTheme,\n\tsetThemeInstance,\n\tTheme,\n\ttheme,\n} from \"./theme/theme.ts\";\n\n/** Components that can be expanded/collapsed (custom headers may opt in). */\ninterface Expandable {\n\tsetExpanded(expanded: boolean): void;\n}\n\nfunction isExpandable(obj: unknown): obj is Expandable {\n\treturn typeof obj === \"object\" && obj !== null && \"setExpanded\" in obj && typeof obj.setExpanded === \"function\";\n}\n\n/**\n * The narrow slice of InteractiveMode the extension UI host drives. Stable containers and the TUI are\n * passed directly; mutable render-core state (the active editor, built-in header, loading animation,\n * autocomplete wrappers, tools-expansion) is read/written through accessors so InteractiveMode keeps\n * ownership; and render-core / status operations stay host-side and are exposed here as callbacks.\n */\nexport interface ExtensionUiHostUi {\n\treadonly tui: TUI;\n\treadonly overlayHost: EditorOverlayHost;\n\treadonly keybindings: KeybindingsManager;\n\treadonly footer: FooterComponent;\n\treadonly footerDataProvider: FooterDataProvider;\n\treadonly headerContainer: Container;\n\treadonly chatContainer: Container;\n\treadonly editorContainer: Container;\n\treadonly defaultEditor: CustomEditor;\n\treadonly widgetContainerAbove: Container;\n\treadonly widgetContainerBelow: Container;\n\n\tgetEditor(): EditorComponent;\n\tsetEditor(editor: EditorComponent): void;\n\tgetBuiltInHeader(): Component | undefined;\n\tgetAutocompleteProvider(): AutocompleteProvider | undefined;\n\tgetToolsExpanded(): boolean;\n\tpushAutocompleteProviderWrapper(factory: AutocompleteProviderFactory): void;\n\tresetAutocompleteProviderWrappers(): void;\n\n\tsetupAutocompleteProvider(): void;\n\tsetWorkingVisible(visible: boolean): void;\n\tsetWorkingIndicator(options?: LoaderIndicatorOptions): void;\n\tsetHiddenThinkingLabel(label?: string): void;\n\tsetWorkingMessage(message: string | undefined): void;\n\tresetWorkingIndicators(): void;\n\tsetToolsExpanded(expanded: boolean): void;\n\ttoggleToolsExpanded(): void;\n\tupdateTerminalTitle(): void;\n\tmarkShutdownRequested(): void;\n\tabort(): void;\n\treload(): Promise<void>;\n\tshowStatus(message: string): void;\n\tshowWarning(message: string): void;\n\tshowError(message: string): void;\n}\n\nexport interface ExtensionUiHostDeps {\n\tgetSession(): AgentSession;\n\tui: ExtensionUiHostUi;\n}\n\nexport class ExtensionUiHost {\n\tprivate readonly deps: ExtensionUiHostDeps;\n\n\t// Extension UI state\n\tprivate extensionSelector: ExtensionSelectorComponent | undefined = undefined;\n\tprivate extensionInput: ExtensionInputComponent | undefined = undefined;\n\tprivate extensionEditor: ExtensionEditorComponent | undefined = undefined;\n\tprivate extensionTerminalInputUnsubscribers = new Set<() => void>();\n\n\t// Extension widgets (components rendered above/below the editor)\n\tprivate extensionWidgetsAbove = new Map<string, Component & { dispose?(): void }>();\n\tprivate extensionWidgetsBelow = new Map<string, Component & { dispose?(): void }>();\n\n\t// Custom footer from extension (undefined = use built-in footer)\n\tprivate customFooter: (Component & { dispose?(): void }) | undefined = undefined;\n\n\t// Custom header from extension (undefined = use built-in header)\n\tprivate customHeader: (Component & { dispose?(): void }) | undefined = undefined;\n\n\t// Current custom editor-component factory (undefined = default editor)\n\tprivate editorComponentFactory: EditorFactory | undefined;\n\n\tconstructor(deps: ExtensionUiHostDeps) {\n\t\tthis.deps = deps;\n\t}\n\n\tprivate get session(): AgentSession {\n\t\treturn this.deps.getSession();\n\t}\n\tprivate get ui(): ExtensionUiHostUi {\n\t\treturn this.deps.ui;\n\t}\n\n\t/** The active custom header, if an extension has installed one. */\n\tgetCustomHeader(): (Component & { dispose?(): void }) | undefined {\n\t\treturn this.customHeader;\n\t}\n\n\t/**\n\t * Set up keyboard shortcuts registered by extensions.\n\t */\n\tsetupExtensionShortcuts(extensionRunner: ExtensionRunner): void {\n\t\tconst shortcuts = extensionRunner.getShortcuts(this.ui.keybindings.getEffectiveConfig());\n\t\tif (shortcuts.size === 0) return;\n\n\t\t// Create a context for shortcut handlers\n\t\tconst createContext = (): ExtensionContext => ({\n\t\t\tui: this.createExtensionUIContext(),\n\t\t\thasUI: true,\n\t\t\tmode: \"tui\",\n\t\t\tcwd: this.session.sessionManager.getCwd(),\n\t\t\tsessionManager: this.session.sessionManager,\n\t\t\tmodelRegistry: this.session.modelRegistry,\n\t\t\tmodel: this.session.model,\n\t\t\tisIdle: () => !this.session.isStreaming,\n\t\t\tsignal: this.session.agent.signal,\n\t\t\tabort: () => {\n\t\t\t\tthis.ui.abort();\n\t\t\t},\n\t\t\thasPendingMessages: () => this.session.pendingMessageCount > 0,\n\t\t\tshutdown: () => {\n\t\t\t\tthis.ui.markShutdownRequested();\n\t\t\t},\n\t\t\tgetContextUsage: () => this.session.getContextUsage(),\n\t\t\tcompact: (options) => {\n\t\t\t\tvoid (async () => {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst result = await this.session.compact(options?.customInstructions);\n\t\t\t\t\t\toptions?.onComplete?.(result);\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tconst err = error instanceof Error ? error : new Error(String(error));\n\t\t\t\t\t\toptions?.onError?.(err);\n\t\t\t\t\t}\n\t\t\t\t})();\n\t\t\t},\n\t\t\treload: async () => {\n\t\t\t\tawait this.ui.reload();\n\t\t\t},\n\t\t\tgetSystemPrompt: () => this.session.systemPrompt,\n\t\t});\n\n\t\t// Set up the extension shortcut handler on the default editor\n\t\tthis.ui.defaultEditor.onExtensionShortcut = (data: string) => {\n\t\t\tfor (const [shortcutStr, shortcut] of shortcuts) {\n\t\t\t\t// Cast to KeyId - extension shortcuts use the same format\n\t\t\t\tif (matchesKey(data, shortcutStr as KeyId)) {\n\t\t\t\t\t// Run handler async, don't block input\n\t\t\t\t\tPromise.resolve(shortcut.handler(createContext())).catch((err) => {\n\t\t\t\t\t\tthis.ui.showError(`Shortcut handler error: ${err instanceof Error ? err.message : String(err)}`);\n\t\t\t\t\t});\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn false;\n\t\t};\n\t}\n\n\t/**\n\t * Set extension status text in the footer.\n\t */\n\tprivate setExtensionStatus(key: string, text: string | undefined): void {\n\t\tthis.ui.footerDataProvider.setExtensionStatus(key, text);\n\t\tthis.ui.tui.requestRender();\n\t}\n\n\t// Maximum total widget lines to prevent viewport overflow\n\tprivate static readonly MAX_WIDGET_LINES = 10;\n\n\t/**\n\t * Set an extension widget (string array or custom component).\n\t */\n\tprivate setExtensionWidget(\n\t\tkey: string,\n\t\tcontent: string[] | ((tui: TUI, thm: Theme) => Component & { dispose?(): void }) | undefined,\n\t\toptions?: ExtensionWidgetOptions,\n\t): void {\n\t\tconst placement = options?.placement ?? \"aboveEditor\";\n\t\tconst removeExisting = (map: Map<string, Component & { dispose?(): void }>) => {\n\t\t\tconst existing = map.get(key);\n\t\t\tif (existing?.dispose) existing.dispose();\n\t\t\tmap.delete(key);\n\t\t};\n\n\t\tremoveExisting(this.extensionWidgetsAbove);\n\t\tremoveExisting(this.extensionWidgetsBelow);\n\n\t\tif (content === undefined) {\n\t\t\tthis.renderWidgets();\n\t\t\treturn;\n\t\t}\n\n\t\tlet component: Component & { dispose?(): void };\n\n\t\tif (Array.isArray(content)) {\n\t\t\t// Wrap string array in a Container with Text components\n\t\t\tconst container = new Container();\n\t\t\tfor (const line of content.slice(0, ExtensionUiHost.MAX_WIDGET_LINES)) {\n\t\t\t\tcontainer.addChild(new Text(line, 1, 0));\n\t\t\t}\n\t\t\tif (content.length > ExtensionUiHost.MAX_WIDGET_LINES) {\n\t\t\t\tcontainer.addChild(new Text(theme.fg(\"muted\", \"... (widget truncated)\"), 1, 0));\n\t\t\t}\n\t\t\tcomponent = container;\n\t\t} else {\n\t\t\t// Factory function - create component\n\t\t\tcomponent = content(this.ui.tui, theme);\n\t\t}\n\n\t\tconst targetMap = placement === \"belowEditor\" ? this.extensionWidgetsBelow : this.extensionWidgetsAbove;\n\t\ttargetMap.set(key, component);\n\t\tthis.renderWidgets();\n\t}\n\n\tprivate clearExtensionWidgets(): void {\n\t\tfor (const widget of this.extensionWidgetsAbove.values()) {\n\t\t\twidget.dispose?.();\n\t\t}\n\t\tfor (const widget of this.extensionWidgetsBelow.values()) {\n\t\t\twidget.dispose?.();\n\t\t}\n\t\tthis.extensionWidgetsAbove.clear();\n\t\tthis.extensionWidgetsBelow.clear();\n\t\tthis.renderWidgets();\n\t}\n\n\tresetExtensionUI(): void {\n\t\tif (this.extensionSelector) {\n\t\t\tthis.hideExtensionSelector();\n\t\t}\n\t\tif (this.extensionInput) {\n\t\t\tthis.hideExtensionInput();\n\t\t}\n\t\tif (this.extensionEditor) {\n\t\t\tthis.hideExtensionEditor();\n\t\t}\n\t\tthis.ui.tui.hideOverlay();\n\t\tthis.clearExtensionTerminalInputListeners();\n\t\tthis.setExtensionFooter(undefined);\n\t\tthis.setExtensionHeader(undefined);\n\t\tthis.clearExtensionWidgets();\n\t\tthis.ui.footerDataProvider.clearExtensionStatuses();\n\t\tthis.ui.footer.invalidate();\n\t\tthis.ui.resetAutocompleteProviderWrappers();\n\t\tthis.setCustomEditorComponent(undefined);\n\t\tthis.ui.setupAutocompleteProvider();\n\t\tthis.ui.defaultEditor.onExtensionShortcut = undefined;\n\t\tthis.ui.updateTerminalTitle();\n\t\tthis.ui.resetWorkingIndicators();\n\t}\n\n\t/**\n\t * Render all extension widgets to the widget container.\n\t */\n\trenderWidgets(): void {\n\t\tif (!this.ui.widgetContainerAbove || !this.ui.widgetContainerBelow) return;\n\t\tthis.renderWidgetContainer(this.ui.widgetContainerAbove, this.extensionWidgetsAbove, true, true);\n\t\tthis.renderWidgetContainer(this.ui.widgetContainerBelow, this.extensionWidgetsBelow, false, false);\n\t\tthis.ui.tui.requestRender();\n\t}\n\n\tprivate renderWidgetContainer(\n\t\tcontainer: Container,\n\t\twidgets: Map<string, Component & { dispose?(): void }>,\n\t\tspacerWhenEmpty: boolean,\n\t\tleadingSpacer: boolean,\n\t): void {\n\t\tcontainer.clear();\n\n\t\tif (widgets.size === 0) {\n\t\t\tif (spacerWhenEmpty) {\n\t\t\t\tcontainer.addChild(new Spacer(1));\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tif (leadingSpacer) {\n\t\t\tcontainer.addChild(new Spacer(1));\n\t\t}\n\t\tfor (const component of widgets.values()) {\n\t\t\tcontainer.addChild(component);\n\t\t}\n\t}\n\n\t/**\n\t * Set a custom footer component, or restore the built-in footer.\n\t */\n\tprivate setExtensionFooter(\n\t\tfactory:\n\t\t\t| ((tui: TUI, thm: Theme, footerData: ReadonlyFooterDataProvider) => Component & { dispose?(): void })\n\t\t\t| undefined,\n\t): void {\n\t\t// Dispose existing custom footer\n\t\tif (this.customFooter?.dispose) {\n\t\t\tthis.customFooter.dispose();\n\t\t}\n\n\t\t// Remove current footer from UI\n\t\tif (this.customFooter) {\n\t\t\tthis.ui.tui.removeChild(this.customFooter);\n\t\t} else {\n\t\t\tthis.ui.tui.removeChild(this.ui.footer);\n\t\t}\n\n\t\tif (factory) {\n\t\t\t// Create and add custom footer, passing the data provider\n\t\t\tthis.customFooter = factory(this.ui.tui, theme, this.ui.footerDataProvider);\n\t\t\tthis.ui.tui.addChild(this.customFooter);\n\t\t} else {\n\t\t\t// Restore built-in footer\n\t\t\tthis.customFooter = undefined;\n\t\t\tthis.ui.tui.addChild(this.ui.footer);\n\t\t}\n\n\t\tthis.ui.tui.requestRender();\n\t}\n\n\t/**\n\t * Set a custom header component, or restore the built-in header.\n\t */\n\tprivate setExtensionHeader(factory: ((tui: TUI, thm: Theme) => Component & { dispose?(): void }) | undefined): void {\n\t\t// Header may not be initialized yet if called during early initialization\n\t\tconst builtInHeader = this.ui.getBuiltInHeader();\n\t\tif (!builtInHeader) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Dispose existing custom header\n\t\tif (this.customHeader?.dispose) {\n\t\t\tthis.customHeader.dispose();\n\t\t}\n\n\t\t// Find the index of the current header in the header container\n\t\tconst currentHeader = this.customHeader || builtInHeader;\n\t\tconst index = this.ui.headerContainer.children.indexOf(currentHeader);\n\n\t\tif (factory) {\n\t\t\t// Create and add custom header\n\t\t\tthis.customHeader = factory(this.ui.tui, theme);\n\t\t\tif (isExpandable(this.customHeader)) {\n\t\t\t\tthis.customHeader.setExpanded(this.ui.getToolsExpanded());\n\t\t\t}\n\t\t\tif (index !== -1) {\n\t\t\t\tthis.ui.headerContainer.children[index] = this.customHeader;\n\t\t\t} else {\n\t\t\t\t// If not found (e.g. builtInHeader was never added), add at the top\n\t\t\t\tthis.ui.headerContainer.children.unshift(this.customHeader);\n\t\t\t}\n\t\t} else {\n\t\t\t// Restore built-in header\n\t\t\tthis.customHeader = undefined;\n\t\t\tif (isExpandable(builtInHeader)) {\n\t\t\t\tbuiltInHeader.setExpanded(this.ui.getToolsExpanded());\n\t\t\t}\n\t\t\tif (index !== -1) {\n\t\t\t\tthis.ui.headerContainer.children[index] = builtInHeader;\n\t\t\t}\n\t\t}\n\n\t\tthis.ui.tui.requestRender();\n\t}\n\n\tprivate addExtensionTerminalInputListener(\n\t\thandler: (data: string) => { consume?: boolean; data?: string } | undefined,\n\t): () => void {\n\t\tconst unsubscribe = this.ui.tui.addInputListener(handler);\n\t\tthis.extensionTerminalInputUnsubscribers.add(unsubscribe);\n\t\treturn () => {\n\t\t\tunsubscribe();\n\t\t\tthis.extensionTerminalInputUnsubscribers.delete(unsubscribe);\n\t\t};\n\t}\n\n\tclearExtensionTerminalInputListeners(): void {\n\t\tfor (const unsubscribe of this.extensionTerminalInputUnsubscribers) {\n\t\t\tunsubscribe();\n\t\t}\n\t\tthis.extensionTerminalInputUnsubscribers.clear();\n\t}\n\n\t/**\n\t * Create the ExtensionUIContext for extensions.\n\t */\n\tcreateExtensionUIContext(): ExtensionUIContext {\n\t\treturn {\n\t\t\tselect: (title, options, opts) => this.showExtensionSelector(title, options, opts),\n\t\t\tconfirm: (title, message, opts) => this.showExtensionConfirm(title, message, opts),\n\t\t\tinput: (title, placeholder, opts) => this.showExtensionInput(title, placeholder, opts),\n\t\t\tnotify: (message, type) => this.showExtensionNotify(message, type),\n\t\t\tonTerminalInput: (handler) => this.addExtensionTerminalInputListener(handler),\n\t\t\tsetStatus: (key, text) => this.setExtensionStatus(key, text),\n\t\t\tsetWorkingMessage: (message) => this.ui.setWorkingMessage(message),\n\t\t\tsetWorkingVisible: (visible) => this.ui.setWorkingVisible(visible),\n\t\t\tsetWorkingIndicator: (options) => this.ui.setWorkingIndicator(options),\n\t\t\tsetHiddenThinkingLabel: (label) => this.ui.setHiddenThinkingLabel(label),\n\t\t\tsetWidget: (key, content, options) => this.setExtensionWidget(key, content, options),\n\t\t\tsetFooter: (factory) => this.setExtensionFooter(factory),\n\t\t\tsetHeader: (factory) => this.setExtensionHeader(factory),\n\t\t\tsetTitle: (title) => this.ui.tui.terminal.setTitle(title),\n\t\t\tcustom: (factory, options) => this.showExtensionCustom(factory, options),\n\t\t\tpasteToEditor: (text) => this.ui.getEditor().handleInput(`\\x1b[200~${text}\\x1b[201~`),\n\t\t\tsetEditorText: (text) => this.ui.getEditor().setText(text),\n\t\t\tgetEditorText: () => this.ui.getEditor().getExpandedText?.() ?? this.ui.getEditor().getText(),\n\t\t\teditor: (title, prefill) => this.showExtensionEditor(title, prefill),\n\t\t\taddAutocompleteProvider: (factory) => {\n\t\t\t\tthis.ui.pushAutocompleteProviderWrapper(factory);\n\t\t\t\tthis.ui.setupAutocompleteProvider();\n\t\t\t},\n\t\t\tsetEditorComponent: (factory) => this.setCustomEditorComponent(factory),\n\t\t\tgetEditorComponent: () => this.editorComponentFactory,\n\t\t\tget theme() {\n\t\t\t\treturn theme;\n\t\t\t},\n\t\t\tgetAllThemes: () => getAvailableThemesWithPaths(),\n\t\t\tgetTheme: (name) => getThemeByName(name),\n\t\t\tsetTheme: (themeOrName) => {\n\t\t\t\tif (themeOrName instanceof Theme) {\n\t\t\t\t\tsetThemeInstance(themeOrName);\n\t\t\t\t\tthis.ui.tui.requestRender();\n\t\t\t\t\treturn { success: true };\n\t\t\t\t}\n\t\t\t\tconst result = setTheme(themeOrName, true);\n\t\t\t\tif (result.success) {\n\t\t\t\t\tif (this.session.settingsManager.getTheme() !== themeOrName) {\n\t\t\t\t\t\tthis.session.settingsManager.setTheme(themeOrName);\n\t\t\t\t\t}\n\t\t\t\t\tthis.ui.tui.requestRender();\n\t\t\t\t}\n\t\t\t\treturn result;\n\t\t\t},\n\t\t\tgetToolsExpanded: () => this.ui.getToolsExpanded(),\n\t\t\tsetToolsExpanded: (expanded) => this.ui.setToolsExpanded(expanded),\n\t\t};\n\t}\n\n\t/**\n\t * Show a selector for extensions.\n\t */\n\tshowExtensionSelector(\n\t\ttitle: string,\n\t\toptions: string[],\n\t\topts?: ExtensionUIDialogOptions,\n\t): Promise<string | undefined> {\n\t\treturn new Promise((resolve) => {\n\t\t\tif (opts?.signal?.aborted) {\n\t\t\t\tresolve(undefined);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst onAbort = () => {\n\t\t\t\tthis.hideExtensionSelector();\n\t\t\t\tresolve(undefined);\n\t\t\t};\n\t\t\topts?.signal?.addEventListener(\"abort\", onAbort, { once: true });\n\n\t\t\tthis.extensionSelector = new ExtensionSelectorComponent(\n\t\t\t\ttitle,\n\t\t\t\toptions,\n\t\t\t\t(option) => {\n\t\t\t\t\topts?.signal?.removeEventListener(\"abort\", onAbort);\n\t\t\t\t\tthis.hideExtensionSelector();\n\t\t\t\t\tresolve(option);\n\t\t\t\t},\n\t\t\t\t() => {\n\t\t\t\t\topts?.signal?.removeEventListener(\"abort\", onAbort);\n\t\t\t\t\tthis.hideExtensionSelector();\n\t\t\t\t\tresolve(undefined);\n\t\t\t\t},\n\t\t\t\t{ tui: this.ui.tui, timeout: opts?.timeout, onToggleToolsExpanded: () => this.ui.toggleToolsExpanded() },\n\t\t\t);\n\n\t\t\tthis.ui.overlayHost.swap(this.extensionSelector);\n\t\t});\n\t}\n\n\t/**\n\t * Hide the extension selector.\n\t */\n\tprivate hideExtensionSelector(): void {\n\t\tthis.extensionSelector?.dispose();\n\t\tthis.extensionSelector = undefined;\n\t\tthis.ui.overlayHost.swap(this.ui.getEditor());\n\t}\n\n\t/**\n\t * Show a confirmation dialog for extensions.\n\t */\n\tasync showExtensionConfirm(title: string, message: string, opts?: ExtensionUIDialogOptions): Promise<boolean> {\n\t\tconst result = await this.showExtensionSelector(`${title}\\n${message}`, [\"Yes\", \"No\"], opts);\n\t\treturn result === \"Yes\";\n\t}\n\n\t/**\n\t * Show a text input for extensions.\n\t */\n\tprivate showExtensionInput(\n\t\ttitle: string,\n\t\tplaceholder?: string,\n\t\topts?: ExtensionUIDialogOptions,\n\t): Promise<string | undefined> {\n\t\treturn new Promise((resolve) => {\n\t\t\tif (opts?.signal?.aborted) {\n\t\t\t\tresolve(undefined);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst onAbort = () => {\n\t\t\t\tthis.hideExtensionInput();\n\t\t\t\tresolve(undefined);\n\t\t\t};\n\t\t\topts?.signal?.addEventListener(\"abort\", onAbort, { once: true });\n\n\t\t\tthis.extensionInput = new ExtensionInputComponent(\n\t\t\t\ttitle,\n\t\t\t\tplaceholder,\n\t\t\t\t(value) => {\n\t\t\t\t\topts?.signal?.removeEventListener(\"abort\", onAbort);\n\t\t\t\t\tthis.hideExtensionInput();\n\t\t\t\t\tresolve(value);\n\t\t\t\t},\n\t\t\t\t() => {\n\t\t\t\t\topts?.signal?.removeEventListener(\"abort\", onAbort);\n\t\t\t\t\tthis.hideExtensionInput();\n\t\t\t\t\tresolve(undefined);\n\t\t\t\t},\n\t\t\t\t{ tui: this.ui.tui, timeout: opts?.timeout },\n\t\t\t);\n\n\t\t\tthis.ui.overlayHost.swap(this.extensionInput);\n\t\t});\n\t}\n\n\t/**\n\t * Hide the extension input.\n\t */\n\tprivate hideExtensionInput(): void {\n\t\tthis.extensionInput?.dispose();\n\t\tthis.extensionInput = undefined;\n\t\tthis.ui.overlayHost.swap(this.ui.getEditor());\n\t}\n\n\t/**\n\t * Show a multi-line editor for extensions (with Ctrl+G support).\n\t */\n\tshowExtensionEditor(title: string, prefill?: string): Promise<string | undefined> {\n\t\treturn new Promise((resolve) => {\n\t\t\tthis.extensionEditor = new ExtensionEditorComponent(\n\t\t\t\tthis.ui.tui,\n\t\t\t\tthis.ui.keybindings,\n\t\t\t\ttitle,\n\t\t\t\tprefill,\n\t\t\t\t(value) => {\n\t\t\t\t\tthis.hideExtensionEditor();\n\t\t\t\t\tresolve(value);\n\t\t\t\t},\n\t\t\t\t() => {\n\t\t\t\t\tthis.hideExtensionEditor();\n\t\t\t\t\tresolve(undefined);\n\t\t\t\t},\n\t\t\t);\n\n\t\t\tthis.ui.overlayHost.swap(this.extensionEditor);\n\t\t});\n\t}\n\n\t/**\n\t * Hide the extension editor.\n\t */\n\tprivate hideExtensionEditor(): void {\n\t\tthis.extensionEditor = undefined;\n\t\tthis.ui.overlayHost.swap(this.ui.getEditor());\n\t}\n\n\t/**\n\t * Set a custom editor component from an extension.\n\t * Pass undefined to restore the default editor.\n\t */\n\tprivate setCustomEditorComponent(factory: EditorFactory | undefined): void {\n\t\tthis.editorComponentFactory = factory;\n\n\t\t// Save text from current editor before switching\n\t\tconst currentText = this.ui.getEditor().getText();\n\n\t\tthis.ui.editorContainer.clear();\n\n\t\tif (factory) {\n\t\t\t// Create the custom editor with tui, theme, and keybindings\n\t\t\tconst newEditor = factory(this.ui.tui, getEditorTheme(), this.ui.keybindings);\n\n\t\t\t// Wire up callbacks from the default editor\n\t\t\tnewEditor.onSubmit = this.ui.defaultEditor.onSubmit;\n\t\t\tnewEditor.onChange = this.ui.defaultEditor.onChange;\n\n\t\t\t// Copy text from previous editor\n\t\t\tnewEditor.setText(currentText);\n\n\t\t\t// Copy appearance settings if supported\n\t\t\tif (newEditor.borderColor !== undefined) {\n\t\t\t\tnewEditor.borderColor = this.ui.defaultEditor.borderColor;\n\t\t\t}\n\t\t\tif (newEditor.setPaddingX !== undefined) {\n\t\t\t\tnewEditor.setPaddingX(this.ui.defaultEditor.getPaddingX());\n\t\t\t}\n\n\t\t\t// Set autocomplete if supported\n\t\t\tconst autocompleteProvider = this.ui.getAutocompleteProvider();\n\t\t\tif (newEditor.setAutocompleteProvider && autocompleteProvider) {\n\t\t\t\tnewEditor.setAutocompleteProvider(autocompleteProvider);\n\t\t\t}\n\n\t\t\t// If extending CustomEditor, copy app-level handlers\n\t\t\t// Use duck typing since instanceof fails across jiti module boundaries\n\t\t\tconst customEditor = newEditor as unknown as Record<string, unknown>;\n\t\t\tif (\"actionHandlers\" in customEditor && customEditor.actionHandlers instanceof Map) {\n\t\t\t\tif (!customEditor.onEscape) {\n\t\t\t\t\tcustomEditor.onEscape = () => this.ui.defaultEditor.onEscape?.();\n\t\t\t\t}\n\t\t\t\tif (!customEditor.onCtrlD) {\n\t\t\t\t\tcustomEditor.onCtrlD = () => this.ui.defaultEditor.onCtrlD?.();\n\t\t\t\t}\n\t\t\t\tif (!customEditor.onPasteImage) {\n\t\t\t\t\tcustomEditor.onPasteImage = () => this.ui.defaultEditor.onPasteImage?.();\n\t\t\t\t}\n\t\t\t\tif (!customEditor.onExtensionShortcut) {\n\t\t\t\t\tcustomEditor.onExtensionShortcut = (data: string) => this.ui.defaultEditor.onExtensionShortcut?.(data);\n\t\t\t\t}\n\t\t\t\t// Copy action handlers (clear, suspend, model switching, etc.)\n\t\t\t\tfor (const [action, handler] of this.ui.defaultEditor.actionHandlers) {\n\t\t\t\t\t(customEditor.actionHandlers as Map<string, () => void>).set(action, handler);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tthis.ui.setEditor(newEditor);\n\t\t} else {\n\t\t\t// Restore default editor with text from custom editor\n\t\t\tthis.ui.defaultEditor.setText(currentText);\n\t\t\tthis.ui.setEditor(this.ui.defaultEditor);\n\t\t}\n\n\t\tthis.ui.editorContainer.addChild(this.ui.getEditor() as Component);\n\t\tthis.ui.tui.setFocus(this.ui.getEditor() as Component);\n\t\tthis.ui.tui.requestRender();\n\t}\n\n\t/**\n\t * Show a notification for extensions.\n\t */\n\tprivate showExtensionNotify(message: string, type?: \"info\" | \"warning\" | \"error\"): void {\n\t\tif (type === \"error\") {\n\t\t\tthis.ui.showError(message);\n\t\t} else if (type === \"warning\") {\n\t\t\tthis.ui.showWarning(message);\n\t\t} else {\n\t\t\tthis.ui.showStatus(message);\n\t\t}\n\t}\n\n\t/** Show a custom component with keyboard focus. Overlay mode renders on top of existing content. */\n\tprivate async showExtensionCustom<T>(\n\t\tfactory: (\n\t\t\ttui: TUI,\n\t\t\ttheme: Theme,\n\t\t\tkeybindings: KeybindingsManager,\n\t\t\tdone: (result: T) => void,\n\t\t) => (Component & { dispose?(): void }) | Promise<Component & { dispose?(): void }>,\n\t\toptions?: {\n\t\t\toverlay?: boolean;\n\t\t\toverlayOptions?: OverlayOptions | (() => OverlayOptions);\n\t\t\tonHandle?: (handle: OverlayHandle) => void;\n\t\t},\n\t): Promise<T> {\n\t\tconst savedText = this.ui.getEditor().getText();\n\t\tconst isOverlay = options?.overlay ?? false;\n\n\t\tconst restoreEditor = () => {\n\t\t\tthis.ui.getEditor().setText(savedText);\n\t\t\tthis.ui.overlayHost.swap(this.ui.getEditor(), { focusMode: \"restore\" });\n\t\t};\n\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tlet component: Component & { dispose?(): void };\n\t\t\tlet closed = false;\n\n\t\t\tconst close = (result: T) => {\n\t\t\t\tif (closed) return;\n\t\t\t\tclosed = true;\n\t\t\t\tif (isOverlay) this.ui.tui.hideOverlay();\n\t\t\t\telse restoreEditor();\n\t\t\t\t// Note: both branches above already call requestRender\n\t\t\t\tresolve(result);\n\t\t\t\ttry {\n\t\t\t\t\tcomponent?.dispose?.();\n\t\t\t\t} catch {\n\t\t\t\t\t/* ignore dispose errors */\n\t\t\t\t}\n\t\t\t};\n\n\t\t\tPromise.resolve(factory(this.ui.tui, theme, this.ui.keybindings, close))\n\t\t\t\t.then((c) => {\n\t\t\t\t\tif (closed) return;\n\t\t\t\t\tcomponent = c;\n\t\t\t\t\tif (isOverlay) {\n\t\t\t\t\t\t// Resolve overlay options - can be static or dynamic function\n\t\t\t\t\t\tconst resolveOptions = (): OverlayOptions | undefined => {\n\t\t\t\t\t\t\tif (options?.overlayOptions) {\n\t\t\t\t\t\t\t\tconst opts =\n\t\t\t\t\t\t\t\t\ttypeof options.overlayOptions === \"function\"\n\t\t\t\t\t\t\t\t\t\t? options.overlayOptions()\n\t\t\t\t\t\t\t\t\t\t: options.overlayOptions;\n\t\t\t\t\t\t\t\treturn opts;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t// Fallback: use component's width property if available\n\t\t\t\t\t\t\tconst w = (component as { width?: number }).width;\n\t\t\t\t\t\t\treturn w ? { width: w } : undefined;\n\t\t\t\t\t\t};\n\t\t\t\t\t\tconst handle = this.ui.tui.showOverlay(component, resolveOptions());\n\t\t\t\t\t\t// Expose handle to caller for visibility control\n\t\t\t\t\t\toptions?.onHandle?.(handle);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthis.ui.overlayHost.swap(component);\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t\t\t.catch((err) => {\n\t\t\t\t\tif (closed) return;\n\t\t\t\t\tif (!isOverlay) restoreEditor();\n\t\t\t\t\treject(err);\n\t\t\t\t});\n\t\t});\n\t}\n\n\t/**\n\t * Show an extension error in the UI.\n\t */\n\tshowExtensionError(extensionPath: string, error: string, stack?: string): void {\n\t\tconst errorMsg = `Extension \"${extensionPath}\" error: ${error}`;\n\t\tconst errorText = new Text(theme.fg(\"error\", errorMsg), 1, 0);\n\t\tthis.ui.chatContainer.addChild(errorText);\n\t\tif (stack) {\n\t\t\t// Show stack trace in dim color, indented\n\t\t\tconst stackLines = stack\n\t\t\t\t.split(\"\\n\")\n\t\t\t\t.slice(1) // Skip first line (duplicates error message)\n\t\t\t\t.map((line) => theme.fg(\"dim\", ` ${line.trim()}`))\n\t\t\t\t.join(\"\\n\");\n\t\t\tif (stackLines) {\n\t\t\t\tthis.ui.chatContainer.addChild(new Text(stackLines, 1, 0));\n\t\t\t}\n\t\t}\n\t\tthis.ui.tui.requestRender();\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"extension-ui-host.d.ts","sourceRoot":"","sources":["../../../src/modes/interactive/extension-ui-host.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EACX,oBAAoB,EACpB,SAAS,EACT,eAAe,EAEf,sBAAsB,EAGtB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,SAAS,EAA4B,KAAK,GAAG,EAAE,MAAM,oBAAoB,CAAC;AACnF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EACX,2BAA2B,EAG3B,eAAe,EACf,kBAAkB,EAClB,wBAAwB,EAExB,MAAM,gCAAgC,CAAC;AACxC,OAAO,KAAK,EAAE,kBAAkB,EAA8B,MAAM,oCAAoC,CAAC;AACzG,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAIlE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAoBlE;;;;;GAKG;AACH,MAAM,WAAW,iBAAiB;IACjC,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC;IAClB,QAAQ,CAAC,WAAW,EAAE,iBAAiB,CAAC;IACxC,QAAQ,CAAC,WAAW,EAAE,kBAAkB,CAAC;IACzC,QAAQ,CAAC,MAAM,EAAE,eAAe,CAAC;IACjC,QAAQ,CAAC,kBAAkB,EAAE,kBAAkB,CAAC;IAChD,QAAQ,CAAC,eAAe,EAAE,SAAS,CAAC;IACpC,QAAQ,CAAC,aAAa,EAAE,SAAS,CAAC;IAClC,QAAQ,CAAC,aAAa,EAAE,YAAY,CAAC;IACrC,QAAQ,CAAC,oBAAoB,E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wB,GAC7B,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CA6B7B;IAED;;OAEG;IACH,OAAO,CAAC,qBAAqB;IAQ7B;;OAEG;IACG,oBAAoB,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,wBAAwB,GAAG,OAAO,CAAC,OAAO,CAAC,CAG5G;IAED;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAiC1B;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAQ1B;;OAEG;IACH,mBAAmB,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CA4BhF;IAED;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAM3B;;;OAGG;IACH,OAAO,CAAC,wBAAwB;IA+DhC;;OAEG;IACH,OAAO,CAAC,mBAAmB;YAWb,mBAAmB;IAkGjC;;OAEG;IACH,kBAAkB,CAAC,aAAa,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAgB7E;CACD","sourcesContent":["/**\n * Extension UI host.\n *\n * Extracted verbatim from interactive-mode.ts (god-file decomposition). Owns the interactive-mode\n * surface of the extension UI API: extension-provided dialogs (selector / confirm / input / multi-line\n * editor / custom component), widget mounting above and below the editor, extension status text, custom\n * footer and header swaps, the custom editor-component swap, keyboard-shortcut wiring, terminal-input\n * listeners, and the `ExtensionUIContext` handed to extensions. It owns exactly the state this cluster\n * mutates (the live dialog components, the widget maps, the terminal-input unsubscribers, the custom\n * footer/header, and the current custom-editor factory) and reaches everything else — the mutable\n * `editor`, the render-core containers, the working-indicator, autocomplete wiring, theme/tools state —\n * through a narrow deps/ui surface rather than the whole InteractiveMode instance. Extensions must see\n * identical behavior, so the render-core operations (working indicator, hidden-thinking label,\n * autocomplete rebuild) stay host-side and are invoked here as delegations.\n */\n\nimport type {\n\tAutocompleteProvider,\n\tComponent,\n\tEditorComponent,\n\tKeyId,\n\tLoaderIndicatorOptions,\n\tOverlayHandle,\n\tOverlayOptions,\n} from \"@caupulican/pi-tui\";\nimport { Container, matchesKey, Spacer, Text, type TUI } from \"@caupulican/pi-tui\";\nimport type { AgentSession } from \"../../core/agent-session.ts\";\nimport type {\n\tAutocompleteProviderFactory,\n\tEditorFactory,\n\tExtensionContext,\n\tExtensionRunner,\n\tExtensionUIContext,\n\tExtensionUIDialogOptions,\n\tExtensionWidgetOptions,\n} from \"../../core/extensions/index.ts\";\nimport type { FooterDataProvider, ReadonlyFooterDataProvider } from \"../../core/footer-data-provider.ts\";\nimport type { KeybindingsManager } from \"../../core/keybindings.ts\";\nimport type { CustomEditor } from \"./components/custom-editor.ts\";\nimport { ExtensionEditorComponent } from \"./components/extension-editor.ts\";\nimport { ExtensionInputComponent } from \"./components/extension-input.ts\";\nimport { ExtensionSelectorComponent } from \"./components/extension-selector.ts\";\nimport type { FooterComponent } from \"./components/footer.ts\";\nimport type { EditorOverlayHost } from \"./editor-overlay-host.ts\";\nimport {\n\tgetAvailableThemesWithPaths,\n\tgetEditorTheme,\n\tgetThemeByName,\n\tsetTheme,\n\tsetThemeInstance,\n\tTheme,\n\ttheme,\n} from \"./theme/theme.ts\";\n\n/** Components that can be expanded/collapsed (custom headers may opt in). */\ninterface Expandable {\n\tsetExpanded(expanded: boolean): void;\n}\n\nfunction isExpandable(obj: unknown): obj is Expandable {\n\treturn typeof obj === \"object\" && obj !== null && \"setExpanded\" in obj && typeof obj.setExpanded === \"function\";\n}\n\n/**\n * The narrow slice of InteractiveMode the extension UI host drives. Stable containers and the TUI are\n * passed directly; mutable render-core state (the active editor, built-in header, loading animation,\n * autocomplete wrappers, tools-expansion) is read/written through accessors so InteractiveMode keeps\n * ownership; and render-core / status operations stay host-side and are exposed here as callbacks.\n */\nexport interface ExtensionUiHostUi {\n\treadonly tui: TUI;\n\treadonly overlayHost: EditorOverlayHost;\n\treadonly keybindings: KeybindingsManager;\n\treadonly footer: FooterComponent;\n\treadonly footerDataProvider: FooterDataProvider;\n\treadonly headerContainer: Container;\n\treadonly chatContainer: Container;\n\treadonly defaultEditor: CustomEditor;\n\treadonly widgetContainerAbove: Container;\n\treadonly widgetContainerBelow: Container;\n\n\tgetEditor(): EditorComponent;\n\tsetEditor(editor: EditorComponent): void;\n\tgetBuiltInHeader(): Component | undefined;\n\tgetAutocompleteProvider(): AutocompleteProvider | undefined;\n\tgetToolsExpanded(): boolean;\n\tpushAutocompleteProviderWrapper(factory: AutocompleteProviderFactory): void;\n\tresetAutocompleteProviderWrappers(): void;\n\n\tsetupAutocompleteProvider(): void;\n\tsetWorkingVisible(visible: boolean): void;\n\tsetWorkingIndicator(options?: LoaderIndicatorOptions): void;\n\tsetHiddenThinkingLabel(label?: string): void;\n\tsetWorkingMessage(message: string | undefined): void;\n\tresetWorkingIndicators(): void;\n\tsetToolsExpanded(expanded: boolean): void;\n\ttoggleToolsExpanded(): void;\n\tupdateTerminalTitle(): void;\n\tmarkShutdownRequested(): void;\n\tabort(): void;\n\treload(): Promise<void>;\n\tshowStatus(message: string): void;\n\tshowWarning(message: string): void;\n\tshowError(message: string): void;\n}\n\nexport interface ExtensionUiHostDeps {\n\tgetSession(): AgentSession;\n\tui: ExtensionUiHostUi;\n}\n\nexport class ExtensionUiHost {\n\tprivate readonly deps: ExtensionUiHostDeps;\n\n\t// Extension UI state\n\tprivate extensionSelector: ExtensionSelectorComponent | undefined = undefined;\n\tprivate extensionInput: ExtensionInputComponent | undefined = undefined;\n\tprivate extensionEditor: ExtensionEditorComponent | undefined = undefined;\n\t/** Settles the mounted extension dialog before another dialog can replace its overlay. */\n\tprivate activeExtensionDialogCancel: (() => void) | undefined;\n\tprivate extensionTerminalInputUnsubscribers = new Set<() => void>();\n\n\t// Extension widgets (components rendered above/below the editor)\n\tprivate extensionWidgetsAbove = new Map<string, Component & { dispose?(): void }>();\n\tprivate extensionWidgetsBelow = new Map<string, Component & { dispose?(): void }>();\n\n\t// Custom footer from extension (undefined = use built-in footer)\n\tprivate customFooter: (Component & { dispose?(): void }) | undefined = undefined;\n\n\t// Custom header from extension (undefined = use built-in header)\n\tprivate customHeader: (Component & { dispose?(): void }) | undefined = undefined;\n\n\t// Current custom editor-component factory (undefined = default editor)\n\tprivate editorComponentFactory: EditorFactory | undefined;\n\n\tconstructor(deps: ExtensionUiHostDeps) {\n\t\tthis.deps = deps;\n\t}\n\n\tprivate get session(): AgentSession {\n\t\treturn this.deps.getSession();\n\t}\n\tprivate get ui(): ExtensionUiHostUi {\n\t\treturn this.deps.ui;\n\t}\n\n\t/** The active custom header, if an extension has installed one. */\n\tgetCustomHeader(): (Component & { dispose?(): void }) | undefined {\n\t\treturn this.customHeader;\n\t}\n\n\t/**\n\t * Set up keyboard shortcuts registered by extensions.\n\t */\n\tsetupExtensionShortcuts(extensionRunner: ExtensionRunner): void {\n\t\tconst shortcuts = extensionRunner.getShortcuts(this.ui.keybindings.getEffectiveConfig());\n\t\tif (shortcuts.size === 0) return;\n\n\t\t// Create a context for shortcut handlers\n\t\tconst createContext = (): ExtensionContext => ({\n\t\t\tui: this.createExtensionUIContext(),\n\t\t\thasUI: true,\n\t\t\tmode: \"tui\",\n\t\t\tcwd: this.session.sessionManager.getCwd(),\n\t\t\tsessionManager: this.session.sessionManager,\n\t\t\tmodelRegistry: this.session.modelRegistry,\n\t\t\tmodel: this.session.model,\n\t\t\tisIdle: () => !this.session.isStreaming,\n\t\t\tsignal: this.session.agent.signal,\n\t\t\tabort: () => {\n\t\t\t\tthis.ui.abort();\n\t\t\t},\n\t\t\thasPendingMessages: () => this.session.pendingMessageCount > 0,\n\t\t\tshutdown: () => {\n\t\t\t\tthis.ui.markShutdownRequested();\n\t\t\t},\n\t\t\tgetContextUsage: () => this.session.getContextUsage(),\n\t\t\tcompact: (options) => {\n\t\t\t\tvoid (async () => {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst result = await this.session.compact(options?.customInstructions);\n\t\t\t\t\t\toptions?.onComplete?.(result);\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tconst err = error instanceof Error ? error : new Error(String(error));\n\t\t\t\t\t\toptions?.onError?.(err);\n\t\t\t\t\t}\n\t\t\t\t})();\n\t\t\t},\n\t\t\treload: async () => {\n\t\t\t\tawait this.ui.reload();\n\t\t\t},\n\t\t\tgetSystemPrompt: () => this.session.systemPrompt,\n\t\t});\n\n\t\t// Set up the extension shortcut handler on the default editor\n\t\tthis.ui.defaultEditor.onExtensionShortcut = (data: string) => {\n\t\t\tfor (const [shortcutStr, shortcut] of shortcuts) {\n\t\t\t\t// Cast to KeyId - extension shortcuts use the same format\n\t\t\t\tif (matchesKey(data, shortcutStr as KeyId)) {\n\t\t\t\t\t// Run handler async, don't block input\n\t\t\t\t\tPromise.resolve(shortcut.handler(createContext())).catch((err) => {\n\t\t\t\t\t\tthis.ui.showError(`Shortcut handler error: ${err instanceof Error ? err.message : String(err)}`);\n\t\t\t\t\t});\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn false;\n\t\t};\n\t}\n\n\t/**\n\t * Set extension status text in the footer.\n\t */\n\tprivate setExtensionStatus(key: string, text: string | undefined): void {\n\t\tthis.ui.footerDataProvider.setExtensionStatus(key, text);\n\t\tthis.ui.tui.requestRender();\n\t}\n\n\t// Maximum total widget lines to prevent viewport overflow\n\tprivate static readonly MAX_WIDGET_LINES = 10;\n\n\t/**\n\t * Set an extension widget (string array or custom component).\n\t */\n\tprivate setExtensionWidget(\n\t\tkey: string,\n\t\tcontent: string[] | ((tui: TUI, thm: Theme) => Component & { dispose?(): void }) | undefined,\n\t\toptions?: ExtensionWidgetOptions,\n\t): void {\n\t\tconst placement = options?.placement ?? \"aboveEditor\";\n\t\tconst removeExisting = (map: Map<string, Component & { dispose?(): void }>) => {\n\t\t\tconst existing = map.get(key);\n\t\t\tif (existing?.dispose) existing.dispose();\n\t\t\tmap.delete(key);\n\t\t};\n\n\t\tremoveExisting(this.extensionWidgetsAbove);\n\t\tremoveExisting(this.extensionWidgetsBelow);\n\n\t\tif (content === undefined) {\n\t\t\tthis.renderWidgets();\n\t\t\treturn;\n\t\t}\n\n\t\tlet component: Component & { dispose?(): void };\n\n\t\tif (Array.isArray(content)) {\n\t\t\t// Wrap string array in a Container with Text components\n\t\t\tconst container = new Container();\n\t\t\tfor (const line of content.slice(0, ExtensionUiHost.MAX_WIDGET_LINES)) {\n\t\t\t\tcontainer.addChild(new Text(line, 1, 0));\n\t\t\t}\n\t\t\tif (content.length > ExtensionUiHost.MAX_WIDGET_LINES) {\n\t\t\t\tcontainer.addChild(new Text(theme.fg(\"muted\", \"... (widget truncated)\"), 1, 0));\n\t\t\t}\n\t\t\tcomponent = container;\n\t\t} else {\n\t\t\t// Factory function - create component\n\t\t\tcomponent = content(this.ui.tui, theme);\n\t\t}\n\n\t\tconst targetMap = placement === \"belowEditor\" ? this.extensionWidgetsBelow : this.extensionWidgetsAbove;\n\t\ttargetMap.set(key, component);\n\t\tthis.renderWidgets();\n\t}\n\n\tprivate clearExtensionWidgets(): void {\n\t\tfor (const widget of this.extensionWidgetsAbove.values()) {\n\t\t\twidget.dispose?.();\n\t\t}\n\t\tfor (const widget of this.extensionWidgetsBelow.values()) {\n\t\t\twidget.dispose?.();\n\t\t}\n\t\tthis.extensionWidgetsAbove.clear();\n\t\tthis.extensionWidgetsBelow.clear();\n\t\tthis.renderWidgets();\n\t}\n\n\tresetExtensionUI(): void {\n\t\t// A reset/reload must settle the active dialog before disposing its component.\n\t\tthis.activeExtensionDialogCancel?.();\n\t\tthis.activeExtensionDialogCancel = undefined;\n\t\tif (this.extensionSelector) {\n\t\t\tthis.hideExtensionSelector();\n\t\t}\n\t\tif (this.extensionInput) {\n\t\t\tthis.hideExtensionInput();\n\t\t}\n\t\tif (this.extensionEditor) {\n\t\t\tthis.hideExtensionEditor();\n\t\t}\n\t\tthis.ui.tui.hideOverlay();\n\t\tthis.clearExtensionTerminalInputListeners();\n\t\tthis.setExtensionFooter(undefined);\n\t\tthis.setExtensionHeader(undefined);\n\t\tthis.clearExtensionWidgets();\n\t\tthis.ui.footerDataProvider.clearExtensionStatuses();\n\t\tthis.ui.footer.invalidate();\n\t\tthis.ui.resetAutocompleteProviderWrappers();\n\t\tthis.setCustomEditorComponent(undefined);\n\t\tthis.ui.setupAutocompleteProvider();\n\t\tthis.ui.defaultEditor.onExtensionShortcut = undefined;\n\t\tthis.ui.updateTerminalTitle();\n\t\tthis.ui.resetWorkingIndicators();\n\t}\n\n\t/**\n\t * Render all extension widgets to the widget container.\n\t */\n\trenderWidgets(): void {\n\t\tif (!this.ui.widgetContainerAbove || !this.ui.widgetContainerBelow) return;\n\t\tthis.renderWidgetContainer(this.ui.widgetContainerAbove, this.extensionWidgetsAbove, true, true);\n\t\tthis.renderWidgetContainer(this.ui.widgetContainerBelow, this.extensionWidgetsBelow, false, false);\n\t\tthis.ui.tui.requestRender();\n\t}\n\n\tprivate renderWidgetContainer(\n\t\tcontainer: Container,\n\t\twidgets: Map<string, Component & { dispose?(): void }>,\n\t\tspacerWhenEmpty: boolean,\n\t\tleadingSpacer: boolean,\n\t): void {\n\t\tcontainer.clear();\n\n\t\tif (widgets.size === 0) {\n\t\t\tif (spacerWhenEmpty) {\n\t\t\t\tcontainer.addChild(new Spacer(1));\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tif (leadingSpacer) {\n\t\t\tcontainer.addChild(new Spacer(1));\n\t\t}\n\t\tfor (const component of widgets.values()) {\n\t\t\tcontainer.addChild(component);\n\t\t}\n\t}\n\n\t/**\n\t * Set a custom footer component, or restore the built-in footer.\n\t */\n\tprivate setExtensionFooter(\n\t\tfactory:\n\t\t\t| ((tui: TUI, thm: Theme, footerData: ReadonlyFooterDataProvider) => Component & { dispose?(): void })\n\t\t\t| undefined,\n\t): void {\n\t\t// Dispose existing custom footer\n\t\tif (this.customFooter?.dispose) {\n\t\t\tthis.customFooter.dispose();\n\t\t}\n\n\t\t// Remove current footer from UI\n\t\tif (this.customFooter) {\n\t\t\tthis.ui.tui.removeChild(this.customFooter);\n\t\t} else {\n\t\t\tthis.ui.tui.removeChild(this.ui.footer);\n\t\t}\n\n\t\tif (factory) {\n\t\t\t// Create and add custom footer, passing the data provider\n\t\t\tthis.customFooter = factory(this.ui.tui, theme, this.ui.footerDataProvider);\n\t\t\tthis.ui.tui.addChild(this.customFooter);\n\t\t} else {\n\t\t\t// Restore built-in footer\n\t\t\tthis.customFooter = undefined;\n\t\t\tthis.ui.tui.addChild(this.ui.footer);\n\t\t}\n\n\t\tthis.ui.tui.requestRender();\n\t}\n\n\t/**\n\t * Set a custom header component, or restore the built-in header.\n\t */\n\tprivate setExtensionHeader(factory: ((tui: TUI, thm: Theme) => Component & { dispose?(): void }) | undefined): void {\n\t\t// Header may not be initialized yet if called during early initialization\n\t\tconst builtInHeader = this.ui.getBuiltInHeader();\n\t\tif (!builtInHeader) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Dispose existing custom header\n\t\tif (this.customHeader?.dispose) {\n\t\t\tthis.customHeader.dispose();\n\t\t}\n\n\t\t// Find the index of the current header in the header container\n\t\tconst currentHeader = this.customHeader || builtInHeader;\n\t\tconst index = this.ui.headerContainer.children.indexOf(currentHeader);\n\n\t\tif (factory) {\n\t\t\t// Create and add custom header\n\t\t\tthis.customHeader = factory(this.ui.tui, theme);\n\t\t\tif (isExpandable(this.customHeader)) {\n\t\t\t\tthis.customHeader.setExpanded(this.ui.getToolsExpanded());\n\t\t\t}\n\t\t\tif (index !== -1) {\n\t\t\t\tthis.ui.headerContainer.children[index] = this.customHeader;\n\t\t\t} else {\n\t\t\t\t// If not found (e.g. builtInHeader was never added), add at the top\n\t\t\t\tthis.ui.headerContainer.children.unshift(this.customHeader);\n\t\t\t}\n\t\t} else {\n\t\t\t// Restore built-in header\n\t\t\tthis.customHeader = undefined;\n\t\t\tif (isExpandable(builtInHeader)) {\n\t\t\t\tbuiltInHeader.setExpanded(this.ui.getToolsExpanded());\n\t\t\t}\n\t\t\tif (index !== -1) {\n\t\t\t\tthis.ui.headerContainer.children[index] = builtInHeader;\n\t\t\t}\n\t\t}\n\n\t\tthis.ui.tui.requestRender();\n\t}\n\n\tprivate addExtensionTerminalInputListener(\n\t\thandler: (data: string) => { consume?: boolean; data?: string } | undefined,\n\t): () => void {\n\t\tconst unsubscribe = this.ui.tui.addInputListener(handler);\n\t\tthis.extensionTerminalInputUnsubscribers.add(unsubscribe);\n\t\treturn () => {\n\t\t\tunsubscribe();\n\t\t\tthis.extensionTerminalInputUnsubscribers.delete(unsubscribe);\n\t\t};\n\t}\n\n\tclearExtensionTerminalInputListeners(): void {\n\t\tfor (const unsubscribe of this.extensionTerminalInputUnsubscribers) {\n\t\t\tunsubscribe();\n\t\t}\n\t\tthis.extensionTerminalInputUnsubscribers.clear();\n\t}\n\n\t/**\n\t * Create the ExtensionUIContext for extensions.\n\t */\n\tcreateExtensionUIContext(): ExtensionUIContext {\n\t\treturn {\n\t\t\tselect: (title, options, opts) => this.showExtensionSelector(title, options, opts),\n\t\t\tconfirm: (title, message, opts) => this.showExtensionConfirm(title, message, opts),\n\t\t\tinput: (title, placeholder, opts) => this.showExtensionInput(title, placeholder, opts),\n\t\t\tnotify: (message, type) => this.showExtensionNotify(message, type),\n\t\t\tonTerminalInput: (handler) => this.addExtensionTerminalInputListener(handler),\n\t\t\tsetStatus: (key, text) => this.setExtensionStatus(key, text),\n\t\t\tsetWorkingMessage: (message) => this.ui.setWorkingMessage(message),\n\t\t\tsetWorkingVisible: (visible) => this.ui.setWorkingVisible(visible),\n\t\t\tsetWorkingIndicator: (options) => this.ui.setWorkingIndicator(options),\n\t\t\tsetHiddenThinkingLabel: (label) => this.ui.setHiddenThinkingLabel(label),\n\t\t\tsetWidget: (key, content, options) => this.setExtensionWidget(key, content, options),\n\t\t\tsetFooter: (factory) => this.setExtensionFooter(factory),\n\t\t\tsetHeader: (factory) => this.setExtensionHeader(factory),\n\t\t\tsetTitle: (title) => this.ui.tui.terminal.setTitle(title),\n\t\t\tcustom: (factory, options) => this.showExtensionCustom(factory, options),\n\t\t\tpasteToEditor: (text) => this.ui.getEditor().handleInput(`\\x1b[200~${text}\\x1b[201~`),\n\t\t\tsetEditorText: (text) => this.ui.getEditor().setText(text),\n\t\t\tgetEditorText: () => this.ui.getEditor().getExpandedText?.() ?? this.ui.getEditor().getText(),\n\t\t\teditor: (title, prefill) => this.showExtensionEditor(title, prefill),\n\t\t\taddAutocompleteProvider: (factory) => {\n\t\t\t\tthis.ui.pushAutocompleteProviderWrapper(factory);\n\t\t\t\tthis.ui.setupAutocompleteProvider();\n\t\t\t},\n\t\t\tsetEditorComponent: (factory) => this.setCustomEditorComponent(factory),\n\t\t\tgetEditorComponent: () => this.editorComponentFactory,\n\t\t\tget theme() {\n\t\t\t\treturn theme;\n\t\t\t},\n\t\t\tgetAllThemes: () => getAvailableThemesWithPaths(),\n\t\t\tgetTheme: (name) => getThemeByName(name),\n\t\t\tsetTheme: (themeOrName) => {\n\t\t\t\tif (themeOrName instanceof Theme) {\n\t\t\t\t\tsetThemeInstance(themeOrName);\n\t\t\t\t\tthis.ui.tui.requestRender();\n\t\t\t\t\treturn { success: true };\n\t\t\t\t}\n\t\t\t\tconst result = setTheme(themeOrName, true);\n\t\t\t\tif (result.success) {\n\t\t\t\t\tif (this.session.settingsManager.getTheme() !== themeOrName) {\n\t\t\t\t\t\tthis.session.settingsManager.setTheme(themeOrName);\n\t\t\t\t\t}\n\t\t\t\t\tthis.ui.tui.requestRender();\n\t\t\t\t}\n\t\t\t\treturn result;\n\t\t\t},\n\t\t\tgetToolsExpanded: () => this.ui.getToolsExpanded(),\n\t\t\tsetToolsExpanded: (expanded) => this.ui.setToolsExpanded(expanded),\n\t\t};\n\t}\n\n\t/**\n\t * Show a selector for extensions.\n\t */\n\tshowExtensionSelector(\n\t\ttitle: string,\n\t\toptions: string[],\n\t\topts?: ExtensionUIDialogOptions,\n\t): Promise<string | undefined> {\n\t\tif (opts?.signal?.aborted) return Promise.resolve(undefined);\n\t\t// Replacing an overlay without settling its promise strands the extension handler forever.\n\t\tthis.activeExtensionDialogCancel?.();\n\t\treturn new Promise((resolve) => {\n\t\t\tlet settled = false;\n\t\t\tlet selector: ExtensionSelectorComponent;\n\t\t\tconst finish = (value: string | undefined, restoreEditor = true) => {\n\t\t\t\tif (settled) return;\n\t\t\t\tsettled = true;\n\t\t\t\topts?.signal?.removeEventListener(\"abort\", cancel);\n\t\t\t\tif (this.activeExtensionDialogCancel === cancel) {\n\t\t\t\t\tthis.activeExtensionDialogCancel = undefined;\n\t\t\t\t}\n\t\t\t\tthis.hideExtensionSelector(selector, restoreEditor);\n\t\t\t\tresolve(value);\n\t\t\t};\n\t\t\tconst cancel = () => finish(undefined);\n\n\t\t\tselector = new ExtensionSelectorComponent(title, options, (option) => finish(option), cancel, {\n\t\t\t\ttui: this.ui.tui,\n\t\t\t\ttimeout: opts?.timeout,\n\t\t\t\tonToggleToolsExpanded: () => this.ui.toggleToolsExpanded(),\n\t\t\t});\n\t\t\tthis.extensionSelector = selector;\n\t\t\tthis.activeExtensionDialogCancel = cancel;\n\t\t\tthis.ui.overlayHost.swap(selector, { onUnmount: () => finish(undefined, false) });\n\t\t\topts?.signal?.addEventListener(\"abort\", cancel, { once: true });\n\t\t});\n\t}\n\n\t/**\n\t * Hide the extension selector.\n\t */\n\tprivate hideExtensionSelector(selector = this.extensionSelector, restoreEditor = true): void {\n\t\tif (!selector) return;\n\t\tselector.dispose();\n\t\tif (this.extensionSelector !== selector) return;\n\t\tthis.extensionSelector = undefined;\n\t\tif (restoreEditor) this.ui.overlayHost.swap(this.ui.getEditor());\n\t}\n\n\t/**\n\t * Show a confirmation dialog for extensions.\n\t */\n\tasync showExtensionConfirm(title: string, message: string, opts?: ExtensionUIDialogOptions): Promise<boolean> {\n\t\tconst result = await this.showExtensionSelector(`${title}\\n${message}`, [\"Yes\", \"No\"], opts);\n\t\treturn result === \"Yes\";\n\t}\n\n\t/**\n\t * Show a text input for extensions.\n\t */\n\tprivate showExtensionInput(\n\t\ttitle: string,\n\t\tplaceholder?: string,\n\t\topts?: ExtensionUIDialogOptions,\n\t): Promise<string | undefined> {\n\t\tif (opts?.signal?.aborted) return Promise.resolve(undefined);\n\t\tthis.activeExtensionDialogCancel?.();\n\t\treturn new Promise((resolve) => {\n\t\t\tlet settled = false;\n\t\t\tlet input: ExtensionInputComponent;\n\t\t\tconst finish = (value: string | undefined, restoreEditor = true) => {\n\t\t\t\tif (settled) return;\n\t\t\t\tsettled = true;\n\t\t\t\topts?.signal?.removeEventListener(\"abort\", cancel);\n\t\t\t\tif (this.activeExtensionDialogCancel === cancel) {\n\t\t\t\t\tthis.activeExtensionDialogCancel = undefined;\n\t\t\t\t}\n\t\t\t\tthis.hideExtensionInput(input, restoreEditor);\n\t\t\t\tresolve(value);\n\t\t\t};\n\t\t\tconst cancel = () => finish(undefined);\n\n\t\t\tinput = new ExtensionInputComponent(title, placeholder, (value) => finish(value), cancel, {\n\t\t\t\ttui: this.ui.tui,\n\t\t\t\ttimeout: opts?.timeout,\n\t\t\t});\n\t\t\tthis.extensionInput = input;\n\t\t\tthis.activeExtensionDialogCancel = cancel;\n\t\t\tthis.ui.overlayHost.swap(input, { onUnmount: () => finish(undefined, false) });\n\t\t\topts?.signal?.addEventListener(\"abort\", cancel, { once: true });\n\t\t});\n\t}\n\n\t/**\n\t * Hide the extension input.\n\t */\n\tprivate hideExtensionInput(input = this.extensionInput, restoreEditor = true): void {\n\t\tif (!input) return;\n\t\tinput.dispose();\n\t\tif (this.extensionInput !== input) return;\n\t\tthis.extensionInput = undefined;\n\t\tif (restoreEditor) this.ui.overlayHost.swap(this.ui.getEditor());\n\t}\n\n\t/**\n\t * Show a multi-line editor for extensions (with Ctrl+G support).\n\t */\n\tshowExtensionEditor(title: string, prefill?: string): Promise<string | undefined> {\n\t\tthis.activeExtensionDialogCancel?.();\n\t\treturn new Promise((resolve) => {\n\t\t\tlet settled = false;\n\t\t\tlet editor: ExtensionEditorComponent;\n\t\t\tconst finish = (value: string | undefined, restoreEditor = true) => {\n\t\t\t\tif (settled) return;\n\t\t\t\tsettled = true;\n\t\t\t\tif (this.activeExtensionDialogCancel === cancel) {\n\t\t\t\t\tthis.activeExtensionDialogCancel = undefined;\n\t\t\t\t}\n\t\t\t\tthis.hideExtensionEditor(editor, restoreEditor);\n\t\t\t\tresolve(value);\n\t\t\t};\n\t\t\tconst cancel = () => finish(undefined);\n\n\t\t\teditor = new ExtensionEditorComponent(\n\t\t\t\tthis.ui.tui,\n\t\t\t\tthis.ui.keybindings,\n\t\t\t\ttitle,\n\t\t\t\tprefill,\n\t\t\t\t(value) => finish(value),\n\t\t\t\tcancel,\n\t\t\t);\n\t\t\tthis.extensionEditor = editor;\n\t\t\tthis.activeExtensionDialogCancel = cancel;\n\t\t\tthis.ui.overlayHost.swap(editor, { onUnmount: () => finish(undefined, false) });\n\t\t});\n\t}\n\n\t/**\n\t * Hide the extension editor.\n\t */\n\tprivate hideExtensionEditor(editor = this.extensionEditor, restoreEditor = true): void {\n\t\tif (!editor || this.extensionEditor !== editor) return;\n\t\tthis.extensionEditor = undefined;\n\t\tif (restoreEditor) this.ui.overlayHost.swap(this.ui.getEditor());\n\t}\n\n\t/**\n\t * Set a custom editor component from an extension.\n\t * Pass undefined to restore the default editor.\n\t */\n\tprivate setCustomEditorComponent(factory: EditorFactory | undefined): void {\n\t\tthis.editorComponentFactory = factory;\n\n\t\t// Save text from current editor before switching\n\t\tconst currentText = this.ui.getEditor().getText();\n\n\t\tif (factory) {\n\t\t\t// Create the custom editor with tui, theme, and keybindings\n\t\t\tconst newEditor = factory(this.ui.tui, getEditorTheme(), this.ui.keybindings);\n\n\t\t\t// Wire up callbacks from the default editor\n\t\t\tnewEditor.onSubmit = this.ui.defaultEditor.onSubmit;\n\t\t\tnewEditor.onChange = this.ui.defaultEditor.onChange;\n\n\t\t\t// Copy text from previous editor\n\t\t\tnewEditor.setText(currentText);\n\n\t\t\t// Copy appearance settings if supported\n\t\t\tif (newEditor.borderColor !== undefined) {\n\t\t\t\tnewEditor.borderColor = this.ui.defaultEditor.borderColor;\n\t\t\t}\n\t\t\tif (newEditor.setPaddingX !== undefined) {\n\t\t\t\tnewEditor.setPaddingX(this.ui.defaultEditor.getPaddingX());\n\t\t\t}\n\n\t\t\t// Set autocomplete if supported\n\t\t\tconst autocompleteProvider = this.ui.getAutocompleteProvider();\n\t\t\tif (newEditor.setAutocompleteProvider && autocompleteProvider) {\n\t\t\t\tnewEditor.setAutocompleteProvider(autocompleteProvider);\n\t\t\t}\n\n\t\t\t// If extending CustomEditor, copy app-level handlers\n\t\t\t// Use duck typing since instanceof fails across jiti module boundaries\n\t\t\tconst customEditor = newEditor as unknown as Record<string, unknown>;\n\t\t\tif (\"actionHandlers\" in customEditor && customEditor.actionHandlers instanceof Map) {\n\t\t\t\tif (!customEditor.onEscape) {\n\t\t\t\t\tcustomEditor.onEscape = () => this.ui.defaultEditor.onEscape?.();\n\t\t\t\t}\n\t\t\t\tif (!customEditor.onCtrlD) {\n\t\t\t\t\tcustomEditor.onCtrlD = () => this.ui.defaultEditor.onCtrlD?.();\n\t\t\t\t}\n\t\t\t\tif (!customEditor.onPasteImage) {\n\t\t\t\t\tcustomEditor.onPasteImage = () => this.ui.defaultEditor.onPasteImage?.();\n\t\t\t\t}\n\t\t\t\tif (!customEditor.onExtensionShortcut) {\n\t\t\t\t\tcustomEditor.onExtensionShortcut = (data: string) => this.ui.defaultEditor.onExtensionShortcut?.(data);\n\t\t\t\t}\n\t\t\t\t// Copy action handlers (clear, suspend, model switching, etc.)\n\t\t\t\tfor (const [action, handler] of this.ui.defaultEditor.actionHandlers) {\n\t\t\t\t\t(customEditor.actionHandlers as Map<string, () => void>).set(action, handler);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tthis.ui.setEditor(newEditor);\n\t\t} else {\n\t\t\t// Restore default editor with text from custom editor\n\t\t\tthis.ui.defaultEditor.setText(currentText);\n\t\t\tthis.ui.setEditor(this.ui.defaultEditor);\n\t\t}\n\n\t\tthis.ui.overlayHost.swap(this.ui.getEditor() as Component);\n\t}\n\n\t/**\n\t * Show a notification for extensions.\n\t */\n\tprivate showExtensionNotify(message: string, type?: \"info\" | \"warning\" | \"error\"): void {\n\t\tif (type === \"error\") {\n\t\t\tthis.ui.showError(message);\n\t\t} else if (type === \"warning\") {\n\t\t\tthis.ui.showWarning(message);\n\t\t} else {\n\t\t\tthis.ui.showStatus(message);\n\t\t}\n\t}\n\n\t/** Show a custom component with keyboard focus. Overlay mode renders on top of existing content. */\n\tprivate async showExtensionCustom<T>(\n\t\tfactory: (\n\t\t\ttui: TUI,\n\t\t\ttheme: Theme,\n\t\t\tkeybindings: KeybindingsManager,\n\t\t\tdone: (result: T) => void,\n\t\t) => (Component & { dispose?(): void }) | Promise<Component & { dispose?(): void }>,\n\t\toptions?: {\n\t\t\toverlay?: boolean;\n\t\t\toverlayOptions?: OverlayOptions | (() => OverlayOptions);\n\t\t\tonHandle?: (handle: OverlayHandle) => void;\n\t\t},\n\t): Promise<T> {\n\t\tthis.activeExtensionDialogCancel?.();\n\t\tconst savedText = this.ui.getEditor().getText();\n\t\tconst isOverlay = options?.overlay ?? false;\n\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tlet component: (Component & { dispose?(): void }) | undefined;\n\t\t\tlet overlayHandle: OverlayHandle | undefined;\n\t\t\tlet closed = false;\n\t\t\tlet cancel: () => void;\n\t\t\tconst dispose = (candidate: (Component & { dispose?(): void }) | undefined) => {\n\t\t\t\ttry {\n\t\t\t\t\tcandidate?.dispose?.();\n\t\t\t\t} catch {\n\t\t\t\t\t/* ignore dispose errors */\n\t\t\t\t}\n\t\t\t};\n\t\t\tconst restore = (restoreEditor = true) => {\n\t\t\t\tif (this.activeExtensionDialogCancel !== cancel) return;\n\t\t\t\tthis.activeExtensionDialogCancel = undefined;\n\t\t\t\tif (isOverlay) {\n\t\t\t\t\toverlayHandle?.hide();\n\t\t\t\t} else if (restoreEditor) {\n\t\t\t\t\tthis.ui.getEditor().setText(savedText);\n\t\t\t\t\tthis.ui.overlayHost.swap(this.ui.getEditor(), { focusMode: \"restore\" });\n\t\t\t\t}\n\t\t\t};\n\t\t\tconst close = (result: T) => {\n\t\t\t\tif (closed) return;\n\t\t\t\tclosed = true;\n\t\t\t\tdispose(component);\n\t\t\t\trestore();\n\t\t\t\tresolve(result);\n\t\t\t};\n\t\t\tconst fail = (error: unknown, restoreEditor = true) => {\n\t\t\t\tif (closed) return;\n\t\t\t\tclosed = true;\n\t\t\t\tdispose(component);\n\t\t\t\trestore(restoreEditor);\n\t\t\t\treject(error);\n\t\t\t};\n\t\t\tcancel = () => fail(new Error(\"Extension UI request was superseded or reset\"));\n\t\t\tthis.activeExtensionDialogCancel = cancel;\n\t\t\tlet mountingComponent = false;\n\t\t\tconst onUnmount = () => {\n\t\t\t\tif (!mountingComponent) fail(new Error(\"Extension UI request was superseded or reset\"), false);\n\t\t\t};\n\t\t\tif (!isOverlay) {\n\t\t\t\tthis.ui.overlayHost.swap(this.ui.getEditor(), {\n\t\t\t\t\tfocusMode: \"restore\",\n\t\t\t\t\trender: \"none\",\n\t\t\t\t\tonUnmount,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tPromise.resolve()\n\t\t\t\t.then(() => (closed ? undefined : factory(this.ui.tui, theme, this.ui.keybindings, close)))\n\t\t\t\t.then((createdComponent) => {\n\t\t\t\t\tif (!createdComponent) return;\n\t\t\t\t\tcomponent = createdComponent;\n\t\t\t\t\tif (closed) {\n\t\t\t\t\t\tdispose(component);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tif (isOverlay) {\n\t\t\t\t\t\tconst resolvedOptions =\n\t\t\t\t\t\t\ttypeof options?.overlayOptions === \"function\" ? options.overlayOptions() : options?.overlayOptions;\n\t\t\t\t\t\tconst width = (component as { width?: number }).width;\n\t\t\t\t\t\toverlayHandle = this.ui.tui.showOverlay(\n\t\t\t\t\t\t\tcomponent,\n\t\t\t\t\t\t\tresolvedOptions ?? (width ? { width } : undefined),\n\t\t\t\t\t\t);\n\t\t\t\t\t\toptions?.onHandle?.(overlayHandle);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tmountingComponent = true;\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tthis.ui.overlayHost.swap(component, { onUnmount });\n\t\t\t\t\t\t} finally {\n\t\t\t\t\t\t\tmountingComponent = false;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t\t\t.catch(fail);\n\t\t});\n\t}\n\n\t/**\n\t * Show an extension error in the UI.\n\t */\n\tshowExtensionError(extensionPath: string, error: string, stack?: string): void {\n\t\tconst errorMsg = `Extension \"${extensionPath}\" error: ${error}`;\n\t\tconst errorText = new Text(theme.fg(\"error\", errorMsg), 1, 0);\n\t\tthis.ui.chatContainer.addChild(errorText);\n\t\tif (stack) {\n\t\t\t// Show stack trace in dim color, indented\n\t\t\tconst stackLines = stack\n\t\t\t\t.split(\"\\n\")\n\t\t\t\t.slice(1) // Skip first line (duplicates error message)\n\t\t\t\t.map((line) => theme.fg(\"dim\", ` ${line.trim()}`))\n\t\t\t\t.join(\"\\n\");\n\t\t\tif (stackLines) {\n\t\t\t\tthis.ui.chatContainer.addChild(new Text(stackLines, 1, 0));\n\t\t\t}\n\t\t}\n\t\tthis.ui.tui.requestRender();\n\t}\n}\n"]}
|