@felan-ai/felan 0.28.4 → 0.31.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOTICE +20 -0
- package/README.md +127 -40
- package/dist/acp/daemon-session.d.ts +34 -0
- package/dist/acp/daemon-session.d.ts.map +1 -0
- package/dist/acp/daemon-session.js +142 -0
- package/dist/acp/daemon-session.js.map +1 -0
- package/dist/acp/login.d.ts +4 -2
- package/dist/acp/login.d.ts.map +1 -1
- package/dist/acp/login.js +155 -251
- package/dist/acp/login.js.map +1 -1
- package/dist/acp/protocol-interactions.d.ts +25 -0
- package/dist/acp/protocol-interactions.d.ts.map +1 -0
- package/dist/acp/protocol-interactions.js +297 -0
- package/dist/acp/protocol-interactions.js.map +1 -0
- package/dist/acp/protocol-updates.d.ts +20 -0
- package/dist/acp/protocol-updates.d.ts.map +1 -0
- package/dist/acp/protocol-updates.js +114 -0
- package/dist/acp/protocol-updates.js.map +1 -0
- package/dist/acp/session-registry.d.ts +4 -9
- package/dist/acp/session-registry.d.ts.map +1 -1
- package/dist/acp/session-registry.js +178 -386
- package/dist/acp/session-registry.js.map +1 -1
- package/dist/cli-config.d.ts +7 -0
- package/dist/cli-config.d.ts.map +1 -0
- package/dist/cli-config.js +18 -0
- package/dist/cli-config.js.map +1 -0
- package/dist/cli-main.d.ts +12 -7
- package/dist/cli-main.d.ts.map +1 -1
- package/dist/cli-main.js +106 -105
- package/dist/cli-main.js.map +1 -1
- package/dist/client/agent-host.d.ts +52 -0
- package/dist/client/agent-host.d.ts.map +1 -0
- package/dist/client/agent-host.js +413 -0
- package/dist/client/agent-host.js.map +1 -0
- package/dist/client/agents-presenter.d.ts +12 -0
- package/dist/client/agents-presenter.d.ts.map +1 -0
- package/dist/client/agents-presenter.js +66 -0
- package/dist/client/agents-presenter.js.map +1 -0
- package/dist/client/client.d.ts +181 -0
- package/dist/client/client.d.ts.map +1 -0
- package/dist/client/client.js +806 -0
- package/dist/client/client.js.map +1 -0
- package/dist/client/daemon-blocked.d.ts +12 -0
- package/dist/client/daemon-blocked.d.ts.map +1 -0
- package/dist/client/daemon-blocked.js +27 -0
- package/dist/client/daemon-blocked.js.map +1 -0
- package/dist/client/daemon-stop.d.ts +5 -0
- package/dist/client/daemon-stop.d.ts.map +1 -0
- package/dist/client/daemon-stop.js +36 -0
- package/dist/client/daemon-stop.js.map +1 -0
- package/dist/client/diagnostics.d.ts +55 -0
- package/dist/client/diagnostics.d.ts.map +1 -0
- package/dist/client/diagnostics.js +47 -0
- package/dist/client/diagnostics.js.map +1 -0
- package/dist/client/hint-renderers.d.ts +16 -0
- package/dist/client/hint-renderers.d.ts.map +1 -0
- package/dist/client/hint-renderers.js +28 -0
- package/dist/client/hint-renderers.js.map +1 -0
- package/dist/client/index.d.ts +5 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +5 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/message-display.d.ts +21 -0
- package/dist/client/message-display.d.ts.map +1 -0
- package/dist/client/message-display.js +115 -0
- package/dist/client/message-display.js.map +1 -0
- package/dist/client/powerline-presenter.d.ts +13 -0
- package/dist/client/powerline-presenter.d.ts.map +1 -0
- package/dist/client/powerline-presenter.js +67 -0
- package/dist/client/powerline-presenter.js.map +1 -0
- package/dist/client/presenters.d.ts +43 -0
- package/dist/client/presenters.d.ts.map +1 -0
- package/dist/client/presenters.js +118 -0
- package/dist/client/presenters.js.map +1 -0
- package/dist/client/reducer.d.ts +37 -0
- package/dist/client/reducer.d.ts.map +1 -0
- package/dist/client/reducer.js +173 -0
- package/dist/client/reducer.js.map +1 -0
- package/dist/client/session-title.d.ts +6 -0
- package/dist/client/session-title.d.ts.map +1 -0
- package/dist/client/session-title.js +13 -0
- package/dist/client/session-title.js.map +1 -0
- package/dist/client/transport.d.ts +14 -0
- package/dist/client/transport.d.ts.map +1 -0
- package/dist/client/transport.js +46 -0
- package/dist/client/transport.js.map +1 -0
- package/dist/client/ui.d.ts +25 -0
- package/dist/client/ui.d.ts.map +1 -0
- package/dist/client/ui.js +123 -0
- package/dist/client/ui.js.map +1 -0
- package/dist/client-application.d.ts +37 -0
- package/dist/client-application.d.ts.map +1 -0
- package/dist/client-application.js +126 -0
- package/dist/client-application.js.map +1 -0
- package/dist/compaction-presentation.d.ts +6 -4
- package/dist/compaction-presentation.d.ts.map +1 -1
- package/dist/compaction-presentation.js +11 -37
- package/dist/compaction-presentation.js.map +1 -1
- package/dist/daemon-command.d.ts +10 -0
- package/dist/daemon-command.d.ts.map +1 -0
- package/dist/daemon-command.js +163 -0
- package/dist/daemon-command.js.map +1 -0
- package/dist/daemon-entrypoint.d.ts +5 -0
- package/dist/daemon-entrypoint.d.ts.map +1 -0
- package/dist/daemon-entrypoint.js +17 -0
- package/dist/daemon-entrypoint.js.map +1 -0
- package/dist/daemon-host.d.ts +2 -0
- package/dist/daemon-host.d.ts.map +1 -0
- package/dist/daemon-host.js +18 -0
- package/dist/daemon-host.js.map +1 -0
- package/dist/dependency-onboarding.js +3 -3
- package/dist/dependency-onboarding.js.map +1 -1
- package/dist/execution-completion.d.ts +3 -0
- package/dist/execution-completion.d.ts.map +1 -0
- package/dist/execution-completion.js +2 -0
- package/dist/execution-completion.js.map +1 -0
- package/dist/headless.d.ts +39 -0
- package/dist/headless.d.ts.map +1 -0
- package/dist/headless.js +315 -0
- package/dist/headless.js.map +1 -0
- package/dist/host.json +55 -0
- package/dist/index.d.ts +9 -19
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -10
- package/dist/index.js.map +1 -1
- package/dist/memory/{history-view.d.ts → history-renderer.d.ts} +13 -6
- package/dist/memory/history-renderer.d.ts.map +1 -0
- package/dist/memory/{history-view.js → history-renderer.js} +34 -30
- package/dist/memory/history-renderer.js.map +1 -0
- package/dist/memory/history.d.ts +1 -31
- package/dist/memory/history.d.ts.map +1 -1
- package/dist/memory/history.js +1 -306
- package/dist/memory/history.js.map +1 -1
- package/dist/memory/ui.d.ts +5 -0
- package/dist/memory/ui.d.ts.map +1 -0
- package/dist/memory/ui.js +2 -0
- package/dist/memory/ui.js.map +1 -0
- package/dist/process-restart.d.ts +4 -6
- package/dist/process-restart.d.ts.map +1 -1
- package/dist/process-restart.js +17 -96
- package/dist/process-restart.js.map +1 -1
- package/dist/{browser → providers/browser}/authorization-host.d.ts +2 -1
- package/dist/providers/browser/authorization-host.d.ts.map +1 -0
- package/dist/{browser → providers/browser}/authorization-host.js +9 -22
- package/dist/providers/browser/authorization-host.js.map +1 -0
- package/dist/providers/browser/chrome-devtools.d.ts.map +1 -0
- package/dist/providers/browser/chrome-devtools.js.map +1 -0
- package/dist/providers/browser/connection-lease.d.ts.map +1 -0
- package/dist/providers/browser/connection-lease.js.map +1 -0
- package/dist/providers/browser-authorization.d.ts +6 -0
- package/dist/providers/browser-authorization.d.ts.map +1 -0
- package/dist/providers/browser-authorization.js +30 -0
- package/dist/providers/browser-authorization.js.map +1 -0
- package/dist/providers/classifier.d.ts.map +1 -0
- package/dist/providers/classifier.js.map +1 -0
- package/dist/providers/codemode.d.ts.map +1 -0
- package/dist/providers/codemode.js.map +1 -0
- package/dist/providers/configuration.d.ts +23 -0
- package/dist/providers/configuration.d.ts.map +1 -0
- package/dist/providers/configuration.js +154 -0
- package/dist/providers/configuration.js.map +1 -0
- package/dist/providers/credential-storage.d.ts +10 -0
- package/dist/providers/credential-storage.d.ts.map +1 -0
- package/dist/providers/credential-storage.js +57 -0
- package/dist/providers/credential-storage.js.map +1 -0
- package/dist/providers/dependencies.d.ts +3 -0
- package/dist/providers/dependencies.d.ts.map +1 -0
- package/dist/providers/dependencies.js +31 -0
- package/dist/providers/dependencies.js.map +1 -0
- package/dist/providers/execution-binding.d.ts +7 -0
- package/dist/providers/execution-binding.d.ts.map +1 -0
- package/dist/providers/execution-binding.js +180 -0
- package/dist/providers/execution-binding.js.map +1 -0
- package/dist/providers/execution-services.d.ts +24 -0
- package/dist/providers/execution-services.d.ts.map +1 -0
- package/dist/providers/execution-services.js +91 -0
- package/dist/providers/execution-services.js.map +1 -0
- package/dist/providers/extension-catalog.d.ts +30 -0
- package/dist/providers/extension-catalog.d.ts.map +1 -0
- package/dist/providers/extension-catalog.js +39 -0
- package/dist/providers/extension-catalog.js.map +1 -0
- package/dist/providers/extension-services.d.ts +14 -0
- package/dist/providers/extension-services.d.ts.map +1 -0
- package/dist/providers/extension-services.js +2 -0
- package/dist/providers/extension-services.js.map +1 -0
- package/dist/providers/extensions.d.ts +7 -0
- package/dist/providers/extensions.d.ts.map +1 -0
- package/dist/providers/extensions.js +32 -0
- package/dist/providers/extensions.js.map +1 -0
- package/dist/providers/felan-platform.d.ts +6 -0
- package/dist/providers/felan-platform.d.ts.map +1 -0
- package/dist/providers/felan-platform.js +11 -0
- package/dist/providers/felan-platform.js.map +1 -0
- package/dist/providers/global-settings.d.ts +46 -0
- package/dist/providers/global-settings.d.ts.map +1 -0
- package/dist/providers/global-settings.js +187 -0
- package/dist/providers/global-settings.js.map +1 -0
- package/dist/providers/llama/extension.d.ts +10 -0
- package/dist/providers/llama/extension.d.ts.map +1 -0
- package/dist/providers/llama/extension.js +34 -0
- package/dist/providers/llama/extension.js.map +1 -0
- package/dist/providers/llama/management.d.ts +5 -0
- package/dist/providers/llama/management.d.ts.map +1 -0
- package/dist/providers/llama/management.js +176 -0
- package/dist/providers/llama/management.js.map +1 -0
- package/dist/providers/llama/presentation.d.ts +32 -0
- package/dist/providers/llama/presentation.d.ts.map +1 -0
- package/dist/providers/llama/presentation.js +141 -0
- package/dist/providers/llama/presentation.js.map +1 -0
- package/dist/providers/llama/sdk.d.ts +71 -0
- package/dist/providers/llama/sdk.d.ts.map +1 -0
- package/dist/providers/llama/sdk.js +25 -0
- package/dist/providers/llama/sdk.js.map +1 -0
- package/dist/providers/local-model-runtime.d.ts +4 -0
- package/dist/providers/local-model-runtime.d.ts.map +1 -0
- package/dist/providers/local-model-runtime.js +11 -0
- package/dist/providers/local-model-runtime.js.map +1 -0
- package/dist/providers/local-resources.d.ts +6 -0
- package/dist/providers/local-resources.d.ts.map +1 -0
- package/dist/providers/local-resources.js +13 -0
- package/dist/providers/local-resources.js.map +1 -0
- package/dist/providers/mcp/callback-server.d.ts +3 -0
- package/dist/providers/mcp/callback-server.d.ts.map +1 -0
- package/dist/{mcp → providers/mcp}/callback-server.js +5 -1
- package/dist/providers/mcp/callback-server.js.map +1 -0
- package/dist/providers/mcp-callback.d.ts +6 -0
- package/dist/providers/mcp-callback.d.ts.map +1 -0
- package/dist/providers/mcp-callback.js +67 -0
- package/dist/providers/mcp-callback.js.map +1 -0
- package/dist/providers/model-defaults.d.ts.map +1 -0
- package/dist/providers/model-defaults.js.map +1 -0
- package/dist/providers/models-subscription.d.ts +14 -0
- package/dist/providers/models-subscription.d.ts.map +1 -0
- package/dist/{powerline.js → providers/models-subscription.js} +28 -83
- package/dist/providers/models-subscription.js.map +1 -0
- package/dist/providers/models.d.ts +18 -0
- package/dist/providers/models.d.ts.map +1 -0
- package/dist/providers/models.js +371 -0
- package/dist/providers/models.js.map +1 -0
- package/dist/providers/pi-lock.d.ts.map +1 -0
- package/dist/{pi-lock.js → providers/pi-lock.js} +1 -1
- package/dist/providers/pi-lock.js.map +1 -0
- package/dist/providers/platform.d.ts +3 -0
- package/dist/providers/platform.d.ts.map +1 -0
- package/dist/providers/platform.js +14 -0
- package/dist/providers/platform.js.map +1 -0
- package/dist/providers/process-adapter.d.ts +3 -0
- package/dist/providers/process-adapter.d.ts.map +1 -0
- package/dist/providers/process-adapter.js +46 -0
- package/dist/providers/process-adapter.js.map +1 -0
- package/dist/providers/process-bootstrap.d.ts +17 -0
- package/dist/providers/process-bootstrap.d.ts.map +1 -0
- package/dist/providers/process-bootstrap.js +87 -0
- package/dist/providers/process-bootstrap.js.map +1 -0
- package/dist/providers/project-trust.d.ts +8 -0
- package/dist/providers/project-trust.d.ts.map +1 -0
- package/dist/providers/project-trust.js +112 -0
- package/dist/providers/project-trust.js.map +1 -0
- package/dist/providers/runtime-dependencies.d.ts +6 -0
- package/dist/providers/runtime-dependencies.d.ts.map +1 -0
- package/dist/providers/runtime-dependencies.js +31 -0
- package/dist/providers/runtime-dependencies.js.map +1 -0
- package/dist/providers/runtime.d.ts +6 -0
- package/dist/providers/runtime.d.ts.map +1 -0
- package/dist/providers/runtime.js +15 -0
- package/dist/providers/runtime.js.map +1 -0
- package/dist/{savings.d.ts → providers/savings.d.ts} +7 -0
- package/dist/providers/savings.d.ts.map +1 -0
- package/dist/{savings.js → providers/savings.js} +46 -1
- package/dist/providers/savings.js.map +1 -0
- package/dist/providers/secrets.d.ts +15 -0
- package/dist/providers/secrets.d.ts.map +1 -0
- package/dist/providers/secrets.js +233 -0
- package/dist/providers/secrets.js.map +1 -0
- package/dist/providers/session-runtime.d.ts +16 -0
- package/dist/providers/session-runtime.d.ts.map +1 -0
- package/dist/providers/session-runtime.js +193 -0
- package/dist/providers/session-runtime.js.map +1 -0
- package/dist/providers/sessions.d.ts +6 -0
- package/dist/providers/sessions.d.ts.map +1 -0
- package/dist/providers/sessions.js +97 -0
- package/dist/providers/sessions.js.map +1 -0
- package/dist/providers/settings-store.d.ts +4 -0
- package/dist/providers/settings-store.d.ts.map +1 -0
- package/dist/providers/settings-store.js +70 -0
- package/dist/providers/settings-store.js.map +1 -0
- package/dist/{settings.d.ts → providers/settings.d.ts} +7 -24
- package/dist/providers/settings.d.ts.map +1 -0
- package/dist/providers/settings.js +170 -0
- package/dist/providers/settings.js.map +1 -0
- package/dist/providers/setup/auth-driver.d.ts +16 -0
- package/dist/providers/setup/auth-driver.d.ts.map +1 -0
- package/dist/providers/setup/auth-driver.js +92 -0
- package/dist/providers/setup/auth-driver.js.map +1 -0
- package/dist/providers/setup/auth-wire.d.ts +51 -0
- package/dist/providers/setup/auth-wire.d.ts.map +1 -0
- package/dist/providers/setup/auth-wire.js +17 -0
- package/dist/providers/setup/auth-wire.js.map +1 -0
- package/dist/providers/setup/auth-worker.d.ts +14 -0
- package/dist/providers/setup/auth-worker.d.ts.map +1 -0
- package/dist/providers/setup/auth-worker.js +187 -0
- package/dist/providers/setup/auth-worker.js.map +1 -0
- package/dist/providers/setup/manager.d.ts +45 -0
- package/dist/providers/setup/manager.d.ts.map +1 -0
- package/dist/providers/setup/manager.js +283 -0
- package/dist/providers/setup/manager.js.map +1 -0
- package/dist/providers/setup/parent-guard.d.ts +3 -0
- package/dist/providers/setup/parent-guard.d.ts.map +1 -0
- package/dist/providers/setup/parent-guard.js +14 -0
- package/dist/providers/setup/parent-guard.js.map +1 -0
- package/dist/providers/setup-open.d.ts +9 -0
- package/dist/providers/setup-open.d.ts.map +1 -0
- package/dist/providers/setup-open.js +32 -0
- package/dist/providers/setup-open.js.map +1 -0
- package/dist/providers/system-prompt.d.ts.map +1 -0
- package/dist/providers/system-prompt.js.map +1 -0
- package/dist/providers/tool-policy.d.ts +2 -0
- package/dist/providers/tool-policy.d.ts.map +1 -0
- package/dist/providers/tool-policy.js +14 -0
- package/dist/providers/tool-policy.js.map +1 -0
- package/dist/providers/ui/extension-ui.d.ts +7 -0
- package/dist/providers/ui/extension-ui.d.ts.map +1 -0
- package/dist/providers/ui/extension-ui.js +42 -0
- package/dist/providers/ui/extension-ui.js.map +1 -0
- package/dist/providers/ui/port.d.ts +24 -0
- package/dist/providers/ui/port.d.ts.map +1 -0
- package/dist/providers/ui/port.js +2 -0
- package/dist/providers/ui/port.js.map +1 -0
- package/dist/savings-command.d.ts +1 -1
- package/dist/savings-command.d.ts.map +1 -1
- package/dist/savings-command.js +1 -1
- package/dist/savings-command.js.map +1 -1
- package/dist/session-picker.d.ts +13 -12
- package/dist/session-picker.d.ts.map +1 -1
- package/dist/session-picker.js +13 -23
- package/dist/session-picker.js.map +1 -1
- package/dist/subagents/agent-navigator.d.ts +24 -11
- package/dist/subagents/agent-navigator.d.ts.map +1 -1
- package/dist/subagents/agent-navigator.js +154 -86
- package/dist/subagents/agent-navigator.js.map +1 -1
- package/dist/subagents/agent-transcript.d.ts +8 -2
- package/dist/subagents/agent-transcript.d.ts.map +1 -1
- package/dist/subagents/agent-transcript.js +312 -29
- package/dist/subagents/agent-transcript.js.map +1 -1
- package/dist/subagents/completion-presentation.d.ts +13 -0
- package/dist/subagents/completion-presentation.d.ts.map +1 -1
- package/dist/subagents/completion-presentation.js +15 -42
- package/dist/subagents/completion-presentation.js.map +1 -1
- package/dist/subagents/transcript-components.d.ts +107 -0
- package/dist/subagents/transcript-components.d.ts.map +1 -0
- package/dist/subagents/transcript-components.js +306 -0
- package/dist/subagents/transcript-components.js.map +1 -0
- package/dist/subagents/types.d.ts +77 -0
- package/dist/subagents/types.d.ts.map +1 -0
- package/dist/subagents/types.js +2 -0
- package/dist/subagents/types.js.map +1 -0
- package/dist/themes/felan-dark.json +1 -1
- package/dist/tool-activity/mode.d.ts +5 -0
- package/dist/tool-activity/mode.d.ts.map +1 -0
- package/dist/tool-activity/mode.js +17 -0
- package/dist/tool-activity/mode.js.map +1 -0
- package/dist/tool-activity/presentation.d.ts.map +1 -1
- package/dist/tool-activity/presentation.js +104 -28
- package/dist/tool-activity/presentation.js.map +1 -1
- package/dist/tool-activity/state.d.ts +9 -2
- package/dist/tool-activity/state.d.ts.map +1 -1
- package/dist/tool-activity/state.js +43 -3
- package/dist/tool-activity/state.js.map +1 -1
- package/dist/tui/ask-user-preferences.d.ts +9 -0
- package/dist/tui/ask-user-preferences.d.ts.map +1 -0
- package/dist/tui/ask-user-preferences.js +16 -0
- package/dist/tui/ask-user-preferences.js.map +1 -0
- package/dist/tui/command-help.d.ts +13 -0
- package/dist/tui/command-help.d.ts.map +1 -0
- package/dist/tui/command-help.js +57 -0
- package/dist/tui/command-help.js.map +1 -0
- package/dist/tui/commands.d.ts +22 -0
- package/dist/tui/commands.d.ts.map +1 -0
- package/dist/tui/commands.js +408 -0
- package/dist/tui/commands.js.map +1 -0
- package/dist/tui/completion-text.d.ts +9 -0
- package/dist/tui/completion-text.d.ts.map +1 -0
- package/dist/tui/completion-text.js +33 -0
- package/dist/tui/completion-text.js.map +1 -0
- package/dist/tui/controller.d.ts +110 -0
- package/dist/tui/controller.d.ts.map +1 -0
- package/dist/tui/controller.js +579 -0
- package/dist/tui/controller.js.map +1 -0
- package/dist/tui/dialogs.d.ts +57 -0
- package/dist/tui/dialogs.d.ts.map +1 -0
- package/dist/tui/dialogs.js +242 -0
- package/dist/tui/dialogs.js.map +1 -0
- package/dist/tui/generic-ui.d.ts +4 -0
- package/dist/tui/generic-ui.d.ts.map +1 -0
- package/dist/tui/generic-ui.js +132 -0
- package/dist/tui/generic-ui.js.map +1 -0
- package/dist/tui/herdr.d.ts +56 -0
- package/dist/tui/herdr.d.ts.map +1 -0
- package/dist/tui/herdr.js +219 -0
- package/dist/tui/herdr.js.map +1 -0
- package/dist/tui/interactions.d.ts +36 -0
- package/dist/tui/interactions.d.ts.map +1 -0
- package/dist/tui/interactions.js +253 -0
- package/dist/tui/interactions.js.map +1 -0
- package/dist/tui/keybindings.d.ts +15 -0
- package/dist/tui/keybindings.d.ts.map +1 -0
- package/dist/tui/keybindings.js +101 -0
- package/dist/tui/keybindings.js.map +1 -0
- package/dist/tui/markdown.d.ts +4 -0
- package/dist/tui/markdown.d.ts.map +1 -0
- package/dist/tui/markdown.js +6 -0
- package/dist/tui/markdown.js.map +1 -0
- package/dist/tui/preferences-schema.d.ts +121 -0
- package/dist/tui/preferences-schema.d.ts.map +1 -0
- package/dist/tui/preferences-schema.js +42 -0
- package/dist/tui/preferences-schema.js.map +1 -0
- package/dist/tui/preferences-store.d.ts +22 -0
- package/dist/tui/preferences-store.d.ts.map +1 -0
- package/dist/tui/preferences-store.js +240 -0
- package/dist/tui/preferences-store.js.map +1 -0
- package/dist/tui/preferences.d.ts +42 -0
- package/dist/tui/preferences.d.ts.map +1 -0
- package/dist/tui/preferences.js +246 -0
- package/dist/tui/preferences.js.map +1 -0
- package/dist/tui/presentation-preferences.d.ts +11 -0
- package/dist/tui/presentation-preferences.d.ts.map +1 -0
- package/dist/tui/presentation-preferences.js +29 -0
- package/dist/tui/presentation-preferences.js.map +1 -0
- package/dist/tui/presentation-ui.d.ts +7 -0
- package/dist/tui/presentation-ui.d.ts.map +1 -0
- package/dist/tui/presentation-ui.js +17 -0
- package/dist/tui/presentation-ui.js.map +1 -0
- package/dist/tui/presenters.d.ts +18 -0
- package/dist/tui/presenters.d.ts.map +1 -0
- package/dist/tui/presenters.js +118 -0
- package/dist/tui/presenters.js.map +1 -0
- package/dist/tui/remote.d.ts +7 -0
- package/dist/tui/remote.d.ts.map +1 -0
- package/dist/tui/remote.js +139 -0
- package/dist/tui/remote.js.map +1 -0
- package/dist/tui/renderers/ask-user/single-select-layout.d.ts +20 -0
- package/dist/tui/renderers/ask-user/single-select-layout.d.ts.map +1 -0
- package/dist/tui/renderers/ask-user/single-select-layout.js +111 -0
- package/dist/tui/renderers/ask-user/single-select-layout.js.map +1 -0
- package/dist/tui/renderers/ask-user.d.ts +21 -0
- package/dist/tui/renderers/ask-user.d.ts.map +1 -0
- package/dist/tui/renderers/ask-user.js +1348 -0
- package/dist/tui/renderers/ask-user.js.map +1 -0
- package/dist/tui/renderers/codebase-memory.d.ts +3 -0
- package/dist/tui/renderers/codebase-memory.d.ts.map +1 -0
- package/dist/tui/renderers/codebase-memory.js +38 -0
- package/dist/tui/renderers/codebase-memory.js.map +1 -0
- package/dist/tui/renderers/codex.d.ts +5 -0
- package/dist/tui/renderers/codex.d.ts.map +1 -0
- package/dist/tui/renderers/codex.js +9 -0
- package/dist/tui/renderers/codex.js.map +1 -0
- package/dist/tui/renderers/context-view.d.ts +3 -0
- package/dist/tui/renderers/context-view.d.ts.map +1 -0
- package/dist/tui/renderers/context-view.js +69 -0
- package/dist/tui/renderers/context-view.js.map +1 -0
- package/dist/{fusion → tui/renderers/fusion}/model-picker.d.ts +2 -1
- package/dist/tui/renderers/fusion/model-picker.d.ts.map +1 -0
- package/dist/{fusion → tui/renderers/fusion}/model-picker.js +1 -0
- package/dist/tui/renderers/fusion/model-picker.js.map +1 -0
- package/dist/tui/renderers/fusion.d.ts +7 -0
- package/dist/tui/renderers/fusion.d.ts.map +1 -0
- package/dist/tui/renderers/fusion.js +266 -0
- package/dist/tui/renderers/fusion.js.map +1 -0
- package/dist/tui/renderers/insights/charts.d.ts +14 -0
- package/dist/tui/renderers/insights/charts.d.ts.map +1 -0
- package/dist/tui/renderers/insights/charts.js +77 -0
- package/dist/tui/renderers/insights/charts.js.map +1 -0
- package/dist/tui/renderers/insights/panel.d.ts +55 -0
- package/dist/tui/renderers/insights/panel.d.ts.map +1 -0
- package/dist/tui/renderers/insights/panel.js +310 -0
- package/dist/tui/renderers/insights/panel.js.map +1 -0
- package/dist/tui/renderers/insights.d.ts +4 -0
- package/dist/tui/renderers/insights.d.ts.map +1 -0
- package/dist/tui/renderers/insights.js +51 -0
- package/dist/tui/renderers/insights.js.map +1 -0
- package/dist/tui/renderers/memory.d.ts +5 -0
- package/dist/tui/renderers/memory.d.ts.map +1 -0
- package/dist/tui/renderers/memory.js +99 -0
- package/dist/tui/renderers/memory.js.map +1 -0
- package/dist/tui/renderers/navigation.d.ts +7 -0
- package/dist/tui/renderers/navigation.d.ts.map +1 -0
- package/dist/tui/renderers/navigation.js +14 -0
- package/dist/tui/renderers/navigation.js.map +1 -0
- package/dist/tui/renderers/powerline/colors.d.ts +18 -0
- package/dist/tui/renderers/powerline/colors.d.ts.map +1 -0
- package/dist/tui/renderers/powerline/colors.js +42 -0
- package/dist/tui/renderers/powerline/colors.js.map +1 -0
- package/dist/tui/renderers/powerline/config.d.ts +44 -0
- package/dist/tui/renderers/powerline/config.d.ts.map +1 -0
- package/dist/tui/renderers/powerline/config.js +123 -0
- package/dist/tui/renderers/powerline/config.js.map +1 -0
- package/dist/tui/renderers/powerline/footer-renderer.d.ts +7 -0
- package/dist/tui/renderers/powerline/footer-renderer.d.ts.map +1 -0
- package/dist/tui/renderers/powerline/footer-renderer.js +74 -0
- package/dist/tui/renderers/powerline/footer-renderer.js.map +1 -0
- package/dist/tui/renderers/powerline/projected-footer.d.ts +24 -0
- package/dist/tui/renderers/powerline/projected-footer.d.ts.map +1 -0
- package/dist/tui/renderers/powerline/projected-footer.js +33 -0
- package/dist/tui/renderers/powerline/projected-footer.js.map +1 -0
- package/dist/tui/renderers/powerline/segments.d.ts +18 -0
- package/dist/tui/renderers/powerline/segments.d.ts.map +1 -0
- package/dist/tui/renderers/powerline/segments.js +331 -0
- package/dist/tui/renderers/powerline/segments.js.map +1 -0
- package/dist/tui/renderers/powerline/symbols.d.ts +27 -0
- package/dist/tui/renderers/powerline/symbols.d.ts.map +1 -0
- package/dist/tui/renderers/powerline/symbols.js +17 -0
- package/dist/tui/renderers/powerline/symbols.js.map +1 -0
- package/dist/tui/renderers/powerline.d.ts +4 -0
- package/dist/tui/renderers/powerline.d.ts.map +1 -0
- package/dist/tui/renderers/powerline.js +4 -0
- package/dist/tui/renderers/powerline.js.map +1 -0
- package/dist/tui/renderers/prewalk/plan-review.d.ts +28 -0
- package/dist/tui/renderers/prewalk/plan-review.d.ts.map +1 -0
- package/dist/tui/renderers/prewalk/plan-review.js +414 -0
- package/dist/tui/renderers/prewalk/plan-review.js.map +1 -0
- package/dist/tui/renderers/prewalk.d.ts +5 -0
- package/dist/tui/renderers/prewalk.d.ts.map +1 -0
- package/dist/tui/renderers/prewalk.js +43 -0
- package/dist/tui/renderers/prewalk.js.map +1 -0
- package/dist/tui/renderers/processes/background-bash-view.d.ts +45 -0
- package/dist/tui/renderers/processes/background-bash-view.d.ts.map +1 -0
- package/dist/tui/renderers/processes/background-bash-view.js +405 -0
- package/dist/tui/renderers/processes/background-bash-view.js.map +1 -0
- package/dist/tui/renderers/processes/completion-message.d.ts +26 -0
- package/dist/tui/renderers/processes/completion-message.d.ts.map +1 -0
- package/dist/tui/renderers/processes/completion-message.js +97 -0
- package/dist/tui/renderers/processes/completion-message.js.map +1 -0
- package/dist/tui/renderers/processes/process-view.d.ts +40 -0
- package/dist/tui/renderers/processes/process-view.d.ts.map +1 -0
- package/dist/tui/renderers/processes/process-view.js +250 -0
- package/dist/tui/renderers/processes/process-view.js.map +1 -0
- package/dist/tui/renderers/processes.d.ts +12 -0
- package/dist/tui/renderers/processes.d.ts.map +1 -0
- package/dist/tui/renderers/processes.js +80 -0
- package/dist/tui/renderers/processes.js.map +1 -0
- package/dist/tui/renderers/prompt-history/picker.d.ts +64 -0
- package/dist/tui/renderers/prompt-history/picker.d.ts.map +1 -0
- package/dist/tui/renderers/prompt-history/picker.js +430 -0
- package/dist/tui/renderers/prompt-history/picker.js.map +1 -0
- package/dist/tui/renderers/prompt-history.d.ts +16 -0
- package/dist/tui/renderers/prompt-history.d.ts.map +1 -0
- package/dist/tui/renderers/prompt-history.js +113 -0
- package/dist/tui/renderers/prompt-history.js.map +1 -0
- package/dist/tui/renderers/tasks/tasks-overlay.d.ts +37 -0
- package/dist/tui/renderers/tasks/tasks-overlay.d.ts.map +1 -0
- package/dist/tui/renderers/tasks/tasks-overlay.js +461 -0
- package/dist/tui/renderers/tasks/tasks-overlay.js.map +1 -0
- package/dist/tui/renderers/tasks.d.ts +18 -0
- package/dist/tui/renderers/tasks.d.ts.map +1 -0
- package/dist/tui/renderers/tasks.js +97 -0
- package/dist/tui/renderers/tasks.js.map +1 -0
- package/dist/tui/run.d.ts +22 -0
- package/dist/tui/run.d.ts.map +1 -0
- package/dist/tui/run.js +249 -0
- package/dist/tui/run.js.map +1 -0
- package/dist/tui/screen.d.ts +73 -0
- package/dist/tui/screen.d.ts.map +1 -0
- package/dist/tui/screen.js +371 -0
- package/dist/tui/screen.js.map +1 -0
- package/dist/tui/session-navigator.d.ts +53 -0
- package/dist/tui/session-navigator.d.ts.map +1 -0
- package/dist/tui/session-navigator.js +256 -0
- package/dist/tui/session-navigator.js.map +1 -0
- package/dist/tui/settings-menu.d.ts +31 -0
- package/dist/tui/settings-menu.d.ts.map +1 -0
- package/dist/tui/settings-menu.js +78 -0
- package/dist/tui/settings-menu.js.map +1 -0
- package/dist/tui/setup-ui.d.ts +14 -0
- package/dist/tui/setup-ui.d.ts.map +1 -0
- package/dist/tui/setup-ui.js +122 -0
- package/dist/tui/setup-ui.js.map +1 -0
- package/dist/tui/setup.d.ts +29 -0
- package/dist/tui/setup.d.ts.map +1 -0
- package/dist/tui/setup.js +414 -0
- package/dist/tui/setup.js.map +1 -0
- package/dist/tui/shell-execution.d.ts +20 -0
- package/dist/tui/shell-execution.d.ts.map +1 -0
- package/dist/tui/shell-execution.js +64 -0
- package/dist/tui/shell-execution.js.map +1 -0
- package/dist/tui/startup-header.d.ts +4 -0
- package/dist/tui/startup-header.d.ts.map +1 -0
- package/dist/tui/startup-header.js +19 -0
- package/dist/tui/startup-header.js.map +1 -0
- package/dist/tui/streaming-markdown.d.ts +21 -0
- package/dist/tui/streaming-markdown.d.ts.map +1 -0
- package/dist/tui/streaming-markdown.js +118 -0
- package/dist/tui/streaming-markdown.js.map +1 -0
- package/dist/tui/theme-config.d.ts +26 -0
- package/dist/tui/theme-config.d.ts.map +1 -0
- package/dist/tui/theme-config.js +87 -0
- package/dist/tui/theme-config.js.map +1 -0
- package/dist/tui/theme-picker.d.ts +23 -0
- package/dist/tui/theme-picker.d.ts.map +1 -0
- package/dist/tui/theme-picker.js +91 -0
- package/dist/tui/theme-picker.js.map +1 -0
- package/dist/tui/theme.d.ts +15 -0
- package/dist/tui/theme.d.ts.map +1 -0
- package/dist/tui/theme.js +216 -0
- package/dist/tui/theme.js.map +1 -0
- package/dist/tui/tool-inspector.d.ts +24 -0
- package/dist/tui/tool-inspector.d.ts.map +1 -0
- package/dist/tui/tool-inspector.js +81 -0
- package/dist/tui/tool-inspector.js.map +1 -0
- package/dist/tui/tool-presentation.d.ts +3 -0
- package/dist/tui/tool-presentation.d.ts.map +1 -0
- package/dist/tui/tool-presentation.js +22 -0
- package/dist/tui/tool-presentation.js.map +1 -0
- package/dist/tui/transcript.d.ts +6 -0
- package/dist/tui/transcript.d.ts.map +1 -0
- package/dist/tui/transcript.js +78 -0
- package/dist/tui/transcript.js.map +1 -0
- package/dist/tui/tree-navigator.d.ts +71 -0
- package/dist/tui/tree-navigator.d.ts.map +1 -0
- package/dist/tui/tree-navigator.js +522 -0
- package/dist/tui/tree-navigator.js.map +1 -0
- package/npm-shrinkwrap.json +598 -116
- package/package.json +79 -30
- package/dist/acp/interactions.d.ts +0 -22
- package/dist/acp/interactions.d.ts.map +0 -1
- package/dist/acp/interactions.js +0 -353
- package/dist/acp/interactions.js.map +0 -1
- package/dist/application.d.ts +0 -23
- package/dist/application.d.ts.map +0 -1
- package/dist/application.js +0 -267
- package/dist/application.js.map +0 -1
- package/dist/browser/authorization-host.d.ts.map +0 -1
- package/dist/browser/authorization-host.js.map +0 -1
- package/dist/browser/chrome-devtools.d.ts.map +0 -1
- package/dist/browser/chrome-devtools.js.map +0 -1
- package/dist/browser/connection-lease.d.ts.map +0 -1
- package/dist/browser/connection-lease.js.map +0 -1
- package/dist/classifier-settings.d.ts +0 -10
- package/dist/classifier-settings.d.ts.map +0 -1
- package/dist/classifier-settings.js +0 -98
- package/dist/classifier-settings.js.map +0 -1
- package/dist/classifier.d.ts.map +0 -1
- package/dist/classifier.js.map +0 -1
- package/dist/codemode.d.ts.map +0 -1
- package/dist/codemode.js.map +0 -1
- package/dist/codex.d.ts +0 -3
- package/dist/codex.d.ts.map +0 -1
- package/dist/codex.js +0 -8
- package/dist/codex.js.map +0 -1
- package/dist/command-autocomplete.d.ts +0 -3
- package/dist/command-autocomplete.d.ts.map +0 -1
- package/dist/command-autocomplete.js +0 -10
- package/dist/command-autocomplete.js.map +0 -1
- package/dist/cwd-command.d.ts +0 -13
- package/dist/cwd-command.d.ts.map +0 -1
- package/dist/cwd-command.js +0 -176
- package/dist/cwd-command.js.map +0 -1
- package/dist/dependencies.d.ts +0 -37
- package/dist/dependencies.d.ts.map +0 -1
- package/dist/dependencies.js +0 -372
- package/dist/dependencies.js.map +0 -1
- package/dist/extension-settings.d.ts +0 -12
- package/dist/extension-settings.d.ts.map +0 -1
- package/dist/extension-settings.js +0 -241
- package/dist/extension-settings.js.map +0 -1
- package/dist/extensions.d.ts +0 -62
- package/dist/extensions.d.ts.map +0 -1
- package/dist/extensions.js +0 -265
- package/dist/extensions.js.map +0 -1
- package/dist/fusion/host.d.ts +0 -3
- package/dist/fusion/host.d.ts.map +0 -1
- package/dist/fusion/host.js +0 -333
- package/dist/fusion/host.js.map +0 -1
- package/dist/fusion/model-picker.d.ts.map +0 -1
- package/dist/fusion/model-picker.js.map +0 -1
- package/dist/herdr.d.ts +0 -29
- package/dist/herdr.d.ts.map +0 -1
- package/dist/herdr.js +0 -247
- package/dist/herdr.js.map +0 -1
- package/dist/insights.d.ts +0 -5
- package/dist/insights.d.ts.map +0 -1
- package/dist/insights.js +0 -140
- package/dist/insights.js.map +0 -1
- package/dist/lock.d.ts +0 -27
- package/dist/lock.d.ts.map +0 -1
- package/dist/lock.js +0 -432
- package/dist/lock.js.map +0 -1
- package/dist/logger.d.ts +0 -7
- package/dist/logger.d.ts.map +0 -1
- package/dist/logger.js +0 -48
- package/dist/logger.js.map +0 -1
- package/dist/mcp/callback-server.d.ts +0 -11
- package/dist/mcp/callback-server.d.ts.map +0 -1
- package/dist/mcp/callback-server.js.map +0 -1
- package/dist/mcp/config.d.ts +0 -20
- package/dist/mcp/config.d.ts.map +0 -1
- package/dist/mcp/config.js +0 -352
- package/dist/mcp/config.js.map +0 -1
- package/dist/mcp/index.d.ts +0 -3
- package/dist/mcp/index.d.ts.map +0 -1
- package/dist/mcp/index.js +0 -25
- package/dist/mcp/index.js.map +0 -1
- package/dist/mcp/oauth-host.d.ts +0 -42
- package/dist/mcp/oauth-host.d.ts.map +0 -1
- package/dist/mcp/oauth-host.js +0 -524
- package/dist/mcp/oauth-host.js.map +0 -1
- package/dist/mcp/oauth-store.d.ts +0 -27
- package/dist/mcp/oauth-store.d.ts.map +0 -1
- package/dist/mcp/oauth-store.js +0 -138
- package/dist/mcp/oauth-store.js.map +0 -1
- package/dist/memory/control.d.ts +0 -8
- package/dist/memory/control.d.ts.map +0 -1
- package/dist/memory/control.js +0 -167
- package/dist/memory/control.js.map +0 -1
- package/dist/memory/coordinator.d.ts +0 -53
- package/dist/memory/coordinator.d.ts.map +0 -1
- package/dist/memory/coordinator.js +0 -807
- package/dist/memory/coordinator.js.map +0 -1
- package/dist/memory/dreamer.d.ts +0 -50
- package/dist/memory/dreamer.d.ts.map +0 -1
- package/dist/memory/dreamer.js +0 -527
- package/dist/memory/dreamer.js.map +0 -1
- package/dist/memory/history-view.d.ts.map +0 -1
- package/dist/memory/history-view.js.map +0 -1
- package/dist/memory/lease.d.ts +0 -13
- package/dist/memory/lease.d.ts.map +0 -1
- package/dist/memory/lease.js +0 -188
- package/dist/memory/lease.js.map +0 -1
- package/dist/memory/project.d.ts +0 -7
- package/dist/memory/project.d.ts.map +0 -1
- package/dist/memory/project.js +0 -41
- package/dist/memory/project.js.map +0 -1
- package/dist/memory/run-retention.d.ts +0 -12
- package/dist/memory/run-retention.d.ts.map +0 -1
- package/dist/memory/run-retention.js +0 -294
- package/dist/memory/run-retention.js.map +0 -1
- package/dist/memory/run.d.ts +0 -79
- package/dist/memory/run.d.ts.map +0 -1
- package/dist/memory/run.js +0 -417
- package/dist/memory/run.js.map +0 -1
- package/dist/memory/store.d.ts +0 -116
- package/dist/memory/store.d.ts.map +0 -1
- package/dist/memory/store.js +0 -751
- package/dist/memory/store.js.map +0 -1
- package/dist/model-defaults.d.ts.map +0 -1
- package/dist/model-defaults.js.map +0 -1
- package/dist/model-selector.d.ts +0 -5
- package/dist/model-selector.d.ts.map +0 -1
- package/dist/model-selector.js +0 -87
- package/dist/model-selector.js.map +0 -1
- package/dist/output-style-instructions.d.ts +0 -6
- package/dist/output-style-instructions.d.ts.map +0 -1
- package/dist/output-style-instructions.js +0 -53
- package/dist/output-style-instructions.js.map +0 -1
- package/dist/overlay-images.d.ts +0 -9
- package/dist/overlay-images.d.ts.map +0 -1
- package/dist/overlay-images.js +0 -99
- package/dist/overlay-images.js.map +0 -1
- package/dist/pi-extensions.d.ts +0 -28
- package/dist/pi-extensions.d.ts.map +0 -1
- package/dist/pi-extensions.js +0 -141
- package/dist/pi-extensions.js.map +0 -1
- package/dist/pi-llama.d.ts +0 -2
- package/dist/pi-llama.d.ts.map +0 -1
- package/dist/pi-llama.js +0 -15
- package/dist/pi-llama.js.map +0 -1
- package/dist/pi-lock.d.ts.map +0 -1
- package/dist/pi-lock.js.map +0 -1
- package/dist/powerline.d.ts +0 -12
- package/dist/powerline.d.ts.map +0 -1
- package/dist/powerline.js.map +0 -1
- package/dist/project-trust-prompt.d.ts +0 -30
- package/dist/project-trust-prompt.d.ts.map +0 -1
- package/dist/project-trust-prompt.js +0 -122
- package/dist/project-trust-prompt.js.map +0 -1
- package/dist/project-trust.d.ts +0 -8
- package/dist/project-trust.d.ts.map +0 -1
- package/dist/project-trust.js +0 -36
- package/dist/project-trust.js.map +0 -1
- package/dist/prompt-history.d.ts +0 -11
- package/dist/prompt-history.d.ts.map +0 -1
- package/dist/prompt-history.js +0 -96
- package/dist/prompt-history.js.map +0 -1
- package/dist/restart-command.d.ts +0 -9
- package/dist/restart-command.d.ts.map +0 -1
- package/dist/restart-command.js +0 -94
- package/dist/restart-command.js.map +0 -1
- package/dist/resume.d.ts +0 -5
- package/dist/resume.d.ts.map +0 -1
- package/dist/resume.js +0 -46
- package/dist/resume.js.map +0 -1
- package/dist/runtime-factory.d.ts +0 -12
- package/dist/runtime-factory.d.ts.map +0 -1
- package/dist/runtime-factory.js +0 -12
- package/dist/runtime-factory.js.map +0 -1
- package/dist/runtime.d.ts +0 -59
- package/dist/runtime.d.ts.map +0 -1
- package/dist/runtime.js +0 -534
- package/dist/runtime.js.map +0 -1
- package/dist/savings.d.ts.map +0 -1
- package/dist/savings.js.map +0 -1
- package/dist/settings.d.ts.map +0 -1
- package/dist/settings.js +0 -359
- package/dist/settings.js.map +0 -1
- package/dist/startup-header.d.ts +0 -9
- package/dist/startup-header.d.ts.map +0 -1
- package/dist/startup-header.js +0 -151
- package/dist/startup-header.js.map +0 -1
- package/dist/subagents/catalog.d.ts +0 -8
- package/dist/subagents/catalog.d.ts.map +0 -1
- package/dist/subagents/catalog.js +0 -136
- package/dist/subagents/catalog.js.map +0 -1
- package/dist/subagents/host.d.ts +0 -133
- package/dist/subagents/host.d.ts.map +0 -1
- package/dist/subagents/host.js +0 -1420
- package/dist/subagents/host.js.map +0 -1
- package/dist/subagents/store.d.ts +0 -25
- package/dist/subagents/store.d.ts.map +0 -1
- package/dist/subagents/store.js +0 -35
- package/dist/subagents/store.js.map +0 -1
- package/dist/system-prompt.d.ts.map +0 -1
- package/dist/system-prompt.js.map +0 -1
- package/dist/tui-compatibility.d.ts +0 -4
- package/dist/tui-compatibility.d.ts.map +0 -1
- package/dist/tui-compatibility.js +0 -244
- package/dist/tui-compatibility.js.map +0 -1
- package/dist/update-notification.d.ts +0 -3
- package/dist/update-notification.d.ts.map +0 -1
- package/dist/update-notification.js +0 -50
- package/dist/update-notification.js.map +0 -1
- /package/dist/{browser → providers/browser}/chrome-devtools.d.ts +0 -0
- /package/dist/{browser → providers/browser}/chrome-devtools.js +0 -0
- /package/dist/{browser → providers/browser}/connection-lease.d.ts +0 -0
- /package/dist/{browser → providers/browser}/connection-lease.js +0 -0
- /package/dist/{classifier.d.ts → providers/classifier.d.ts} +0 -0
- /package/dist/{classifier.js → providers/classifier.js} +0 -0
- /package/dist/{codemode.d.ts → providers/codemode.d.ts} +0 -0
- /package/dist/{codemode.js → providers/codemode.js} +0 -0
- /package/dist/{model-defaults.d.ts → providers/model-defaults.d.ts} +0 -0
- /package/dist/{model-defaults.js → providers/model-defaults.js} +0 -0
- /package/dist/{pi-lock.d.ts → providers/pi-lock.d.ts} +0 -0
- /package/dist/{system-prompt.d.ts → providers/system-prompt.d.ts} +0 -0
- /package/dist/{system-prompt.js → providers/system-prompt.js} +0 -0
|
@@ -0,0 +1,1348 @@
|
|
|
1
|
+
import { decodeUiMarkdown } from '../../client/ui.js';
|
|
2
|
+
import { createRequire } from 'node:module';
|
|
3
|
+
import { Container, decodeKittyPrintable, Editor, fuzzyFilter, Key, matchesKey, Spacer, Text, truncateToWidth, wrapTextWithAnsi, } from '@earendil-works/pi-tui';
|
|
4
|
+
import { normalizeAskUserOption } from '@felan-ai/ext-ask-user/data';
|
|
5
|
+
import { renderSingleSelectRows } from './ask-user/single-select-layout.js';
|
|
6
|
+
import { DEFAULT_ASK_USER_CONFIG, normalizeAskUserShortcut } from '../ask-user-preferences.js';
|
|
7
|
+
export { ASK_USER_FORM_HINT } from '@felan-ai/ext-ask-user/data';
|
|
8
|
+
const VERSION = createRequire(import.meta.url)('../../../package.json').version;
|
|
9
|
+
const BOX_LEFT = '│ ';
|
|
10
|
+
const BOX_RIGHT = ' │';
|
|
11
|
+
const BOX_OVERHEAD = BOX_LEFT.length + BOX_RIGHT.length;
|
|
12
|
+
const OVERLAY_MAX_HEIGHT_RATIO = 0.85;
|
|
13
|
+
const OVERLAY_MIN_RENDER_LINES = 8;
|
|
14
|
+
const OVERLAY_WIDTH = '92%';
|
|
15
|
+
const OVERLAY_MAX_HEIGHT = '85%';
|
|
16
|
+
const OVERLAY_MIN_WIDTH = 40;
|
|
17
|
+
const SPLIT_PANE_MIN_WIDTH = 84;
|
|
18
|
+
const SPLIT_LEFT_MIN_WIDTH = 32;
|
|
19
|
+
const SPLIT_RIGHT_MIN_WIDTH = 28;
|
|
20
|
+
const SPLIT_SEPARATOR = ' │ ';
|
|
21
|
+
const COMMENT_LABEL = 'Add extra context after selection';
|
|
22
|
+
const DEFAULT_OVERLAY_TOGGLE = 'alt+o';
|
|
23
|
+
const DEFAULT_COMMENT_TOGGLE = 'ctrl+g';
|
|
24
|
+
const CONTEXT_TOGGLE_KEY = Key.ctrl('e');
|
|
25
|
+
const INLINE_CONTEXT_MAX_ROWS = 3;
|
|
26
|
+
const FREEFORM_SENTINEL = 'Type custom response...';
|
|
27
|
+
const DISABLED_SHORTCUT = {
|
|
28
|
+
disabled: true,
|
|
29
|
+
spec: null,
|
|
30
|
+
matches: (_data) => false,
|
|
31
|
+
};
|
|
32
|
+
export function createTuiAskUserPresenter(config = {}) {
|
|
33
|
+
const defaults = { ...DEFAULT_ASK_USER_CONFIG, ...config };
|
|
34
|
+
return { present: (request, context) => presentAskUser(request, {
|
|
35
|
+
...context, mode: 'tui', hasUI: true, reportProgress: context.reportProgress ?? (() => { }),
|
|
36
|
+
}, defaults) };
|
|
37
|
+
}
|
|
38
|
+
export async function presentAskUserForm(form, context, config = {}) {
|
|
39
|
+
const ids = [...new Set(form.input.fields.map(field => field.id.replace(/\.(mode|selection|text|comment)$/u, '')))];
|
|
40
|
+
const sections = form.markdown?.split(/^## Question \d+: /mu).slice(1) ?? [];
|
|
41
|
+
const questions = ids.map((id, index) => {
|
|
42
|
+
const selection = form.input.fields.find(field => field.id === `${id}.selection`);
|
|
43
|
+
const section = sections[index] ?? '';
|
|
44
|
+
const newline = section.indexOf('\n');
|
|
45
|
+
const header = newline < 0 ? `Q${index + 1}` : section.slice(0, newline);
|
|
46
|
+
const body = section.slice(newline + 1).trim();
|
|
47
|
+
const choicesAt = body.indexOf('\n\n- ');
|
|
48
|
+
const skipAt = body.lastIndexOf('\n\nChoose an answer type.');
|
|
49
|
+
const content = choicesAt >= 0 ? body.slice(0, choicesAt) : skipAt >= 0 ? body.slice(0, skipAt) : body;
|
|
50
|
+
const [question, ...context] = content.split('\n\n');
|
|
51
|
+
const choices = choicesAt < 0 ? [] : body.slice(choicesAt + 4, body.lastIndexOf('\n\nSelect ')).split('\n- ').map(formLiteral);
|
|
52
|
+
const options = selection?.kind === 'enum' || selection?.kind === 'multi_select' ? selection.options : [];
|
|
53
|
+
const numbered = new Set(options.map(option => option.label)).size !== options.length;
|
|
54
|
+
return {
|
|
55
|
+
id, header: formLiteral(header), question: formLiteral(question || form.title),
|
|
56
|
+
...(context.length ? { context: formLiteral(context.join('\n\n')) } : {}),
|
|
57
|
+
options: options.map((option, index) => {
|
|
58
|
+
const title = option.label.replace(/[\u0000-\u001f\u007f-\u009f]/gu, '');
|
|
59
|
+
const choice = choices[index];
|
|
60
|
+
const description = choice?.startsWith(`${option.label}: `) ? choice.slice(option.label.length + 2) : undefined;
|
|
61
|
+
return { title: numbered ? `${index + 1}. ${title}` : title, ...(description === undefined ? {} : { description }) };
|
|
62
|
+
}),
|
|
63
|
+
allowMultiple: selection?.kind === 'multi_select',
|
|
64
|
+
allowFreeform: form.input.fields.some(field => field.id === `${id}.text` && field.kind === 'string'),
|
|
65
|
+
allowComment: form.input.fields.some(field => field.id === `${id}.comment` && field.kind === 'string'),
|
|
66
|
+
};
|
|
67
|
+
});
|
|
68
|
+
const result = await createTuiAskUserPresenter(config).present({ questions }, context);
|
|
69
|
+
if (context.signal.aborted)
|
|
70
|
+
return undefined;
|
|
71
|
+
const action = form.actions.find(action => action.id === (result.status === 'answered' ? 'submit' : 'cancel'));
|
|
72
|
+
if (!action)
|
|
73
|
+
throw new Error('Ask-user form is missing its response action.');
|
|
74
|
+
const values = {};
|
|
75
|
+
if (result.status === 'answered')
|
|
76
|
+
for (const question of questions) {
|
|
77
|
+
const response = result.answers.find(answer => answer.questionId === question.id)?.response;
|
|
78
|
+
const mode = response?.kind ?? 'skip';
|
|
79
|
+
if (form.input.fields.some(field => field.id === `${question.id}.mode`))
|
|
80
|
+
values[`${question.id}.mode`] = mode;
|
|
81
|
+
if (response?.kind === 'freeform')
|
|
82
|
+
values[`${question.id}.text`] = response.text;
|
|
83
|
+
if (response?.kind === 'selection') {
|
|
84
|
+
const field = form.input.fields.find(field => field.id === `${question.id}.selection`);
|
|
85
|
+
if (field?.kind !== 'enum' && field?.kind !== 'multi_select')
|
|
86
|
+
throw new Error('Ask-user selection field is missing.');
|
|
87
|
+
const selected = response.selections.map(title => {
|
|
88
|
+
const option = field.options[question.options.findIndex(option => option.title === title)];
|
|
89
|
+
if (!option)
|
|
90
|
+
throw new Error('Ask-user returned an undeclared selection.');
|
|
91
|
+
return option.id;
|
|
92
|
+
});
|
|
93
|
+
values[field.id] = field.kind === 'multi_select' ? selected : selected[0];
|
|
94
|
+
if (response.comment !== undefined)
|
|
95
|
+
values[`${question.id}.comment`] = response.comment;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return { kind: 'form', actionId: action.id, outcome: action.outcome, values };
|
|
99
|
+
}
|
|
100
|
+
function formLiteral(value) {
|
|
101
|
+
return decodeUiMarkdown(value, { plainText: true }).replace(/[\u0000-\u0008\u000b-\u001f\u007f-\u009f]/gu, '');
|
|
102
|
+
}
|
|
103
|
+
async function presentAskUser(request, execution, config) {
|
|
104
|
+
if (execution.signal.aborted)
|
|
105
|
+
return { status: 'cancelled', reason: 'abort' };
|
|
106
|
+
const ctx = execution;
|
|
107
|
+
if (!ctx.hasUI || (ctx.mode !== 'tui' && ctx.mode !== 'rpc')) {
|
|
108
|
+
return {
|
|
109
|
+
status: 'cancelled',
|
|
110
|
+
reason: 'unavailable',
|
|
111
|
+
message: `ask_user requires TUI or RPC dialog mode; current mode is ${ctx.mode}`,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
const displayMode = request.displayMode ?? config.displayMode;
|
|
115
|
+
const singleSelectLayout = request.singleSelectLayout ?? config.singleSelectLayout;
|
|
116
|
+
const shortcuts = {
|
|
117
|
+
overlayToggle: resolveShortcut(request.overlayToggleKey, config.overlayToggleKey, DEFAULT_OVERLAY_TOGGLE),
|
|
118
|
+
commentToggle: resolveShortcut(request.commentToggleKey, config.commentToggleKey, DEFAULT_COMMENT_TOGGLE),
|
|
119
|
+
};
|
|
120
|
+
let timedOut = false;
|
|
121
|
+
let aborted = false;
|
|
122
|
+
if (ctx.mode === 'rpc') {
|
|
123
|
+
const dialogResult = await askQuestionsViaDialogs(ctx.ui, request.questions, request.timeout, execution.signal);
|
|
124
|
+
if (dialogResult.cancelled)
|
|
125
|
+
return { status: 'cancelled', reason: dialogResult.cancelled };
|
|
126
|
+
return dialogResult.answers.some((answer) => answer.response !== null)
|
|
127
|
+
? { status: 'answered', answers: dialogResult.answers }
|
|
128
|
+
: { status: 'cancelled', reason: 'user' };
|
|
129
|
+
}
|
|
130
|
+
let overlayHandle;
|
|
131
|
+
let removeOverlayListener;
|
|
132
|
+
let removeAbortListener;
|
|
133
|
+
let timeoutHandle;
|
|
134
|
+
let announcedHidden = false;
|
|
135
|
+
try {
|
|
136
|
+
const overlayToggle = shortcuts.overlayToggle;
|
|
137
|
+
if (displayMode === 'overlay' && !overlayToggle.disabled && typeof ctx.ui.onTerminalInput === 'function') {
|
|
138
|
+
removeOverlayListener = ctx.ui.onTerminalInput((data) => {
|
|
139
|
+
if (!overlayHandle || !overlayToggle.matches(data))
|
|
140
|
+
return undefined;
|
|
141
|
+
const hidden = !overlayHandle.isHidden();
|
|
142
|
+
overlayHandle.setHidden(hidden);
|
|
143
|
+
if (hidden && !announcedHidden) {
|
|
144
|
+
announcedHidden = true;
|
|
145
|
+
ctx.ui.notify?.(`ask_user hidden — press ${overlayToggle.spec} to reopen`, 'info');
|
|
146
|
+
}
|
|
147
|
+
return { consume: true };
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
const result = await ctx.ui.custom((tui, theme, keybindings, done) => {
|
|
151
|
+
let settled = false;
|
|
152
|
+
const finish = (value) => {
|
|
153
|
+
if (settled)
|
|
154
|
+
return;
|
|
155
|
+
settled = true;
|
|
156
|
+
done(value);
|
|
157
|
+
};
|
|
158
|
+
const onAbort = () => {
|
|
159
|
+
aborted = true;
|
|
160
|
+
finish(null);
|
|
161
|
+
};
|
|
162
|
+
execution.signal.addEventListener('abort', onAbort, { once: true });
|
|
163
|
+
removeAbortListener = () => execution.signal.removeEventListener('abort', onAbort);
|
|
164
|
+
if (request.timeout !== undefined) {
|
|
165
|
+
timeoutHandle = setTimeout(() => {
|
|
166
|
+
timedOut = true;
|
|
167
|
+
finish(null);
|
|
168
|
+
}, request.timeout);
|
|
169
|
+
}
|
|
170
|
+
if (request.questions.length === 1) {
|
|
171
|
+
const question = request.questions[0];
|
|
172
|
+
return new AskPrompt(question, displayMode, singleSelectLayout, tui, theme, keybindings, shortcuts, (response) => finish(response === null ? null : [{ questionId: question.id, response }]));
|
|
173
|
+
}
|
|
174
|
+
return new AskWizard(request.questions, displayMode, singleSelectLayout, tui, theme, keybindings, shortcuts, execution.reportProgress, finish);
|
|
175
|
+
}, customUIOptions(displayMode, (handle) => {
|
|
176
|
+
overlayHandle = handle;
|
|
177
|
+
}));
|
|
178
|
+
if (result === undefined) {
|
|
179
|
+
const dialogResult = await askQuestionsViaDialogs(ctx.ui, request.questions, request.timeout, execution.signal);
|
|
180
|
+
if (dialogResult.cancelled)
|
|
181
|
+
return { status: 'cancelled', reason: dialogResult.cancelled };
|
|
182
|
+
return dialogResult.answers.some((answer) => answer.response !== null)
|
|
183
|
+
? { status: 'answered', answers: dialogResult.answers }
|
|
184
|
+
: { status: 'cancelled', reason: 'user' };
|
|
185
|
+
}
|
|
186
|
+
if (result === null) {
|
|
187
|
+
return {
|
|
188
|
+
status: 'cancelled',
|
|
189
|
+
reason: timedOut ? 'timeout' : aborted || execution.signal.aborted ? 'abort' : 'user',
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
return { status: 'answered', answers: result };
|
|
193
|
+
}
|
|
194
|
+
finally {
|
|
195
|
+
if (timeoutHandle !== undefined)
|
|
196
|
+
clearTimeout(timeoutHandle);
|
|
197
|
+
removeAbortListener?.();
|
|
198
|
+
removeOverlayListener?.();
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
function resolveShortcut(parameter, configuredDefault, fallback) {
|
|
202
|
+
for (const value of [parameter, configuredDefault, fallback]) {
|
|
203
|
+
if (value === undefined)
|
|
204
|
+
continue;
|
|
205
|
+
if (value === null)
|
|
206
|
+
return DISABLED_SHORTCUT;
|
|
207
|
+
const normalized = normalizeAskUserShortcut(value);
|
|
208
|
+
if (normalized === undefined)
|
|
209
|
+
continue;
|
|
210
|
+
if (normalized === null)
|
|
211
|
+
return DISABLED_SHORTCUT;
|
|
212
|
+
return { disabled: false, spec: normalized, matches: (data) => matchesKey(data, normalized) };
|
|
213
|
+
}
|
|
214
|
+
return DISABLED_SHORTCUT;
|
|
215
|
+
}
|
|
216
|
+
function customUIOptions(displayMode, onHandle) {
|
|
217
|
+
if (displayMode === 'inline')
|
|
218
|
+
return undefined;
|
|
219
|
+
return {
|
|
220
|
+
overlay: true,
|
|
221
|
+
overlayOptions: {
|
|
222
|
+
anchor: 'center',
|
|
223
|
+
width: OVERLAY_WIDTH,
|
|
224
|
+
minWidth: OVERLAY_MIN_WIDTH,
|
|
225
|
+
maxHeight: OVERLAY_MAX_HEIGHT,
|
|
226
|
+
margin: 1,
|
|
227
|
+
},
|
|
228
|
+
onHandle,
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
function overlayMaxRenderLines(terminalRows) {
|
|
232
|
+
const rows = Number.isFinite(terminalRows) ? Math.max(1, Math.floor(terminalRows)) : 24;
|
|
233
|
+
const availableRows = Math.max(1, rows - 2);
|
|
234
|
+
const ratioRows = Math.max(1, Math.floor(rows * OVERLAY_MAX_HEIGHT_RATIO));
|
|
235
|
+
const minimumRows = Math.min(OVERLAY_MIN_RENDER_LINES, availableRows);
|
|
236
|
+
return Math.min(availableRows, Math.max(minimumRows, ratioRows));
|
|
237
|
+
}
|
|
238
|
+
class BorderTop {
|
|
239
|
+
color;
|
|
240
|
+
title;
|
|
241
|
+
titleColor;
|
|
242
|
+
constructor(color, title, titleColor) {
|
|
243
|
+
this.color = color;
|
|
244
|
+
this.title = title;
|
|
245
|
+
this.titleColor = titleColor;
|
|
246
|
+
}
|
|
247
|
+
invalidate() { }
|
|
248
|
+
render(width) {
|
|
249
|
+
const inner = Math.max(0, width - 2);
|
|
250
|
+
if (inner < this.title.length + 4)
|
|
251
|
+
return [this.color(`╭${'─'.repeat(inner)}╮`)];
|
|
252
|
+
const label = ` ${this.title} `;
|
|
253
|
+
return [
|
|
254
|
+
this.color('╭─')
|
|
255
|
+
+ this.titleColor(label)
|
|
256
|
+
+ this.color(`${'─'.repeat(Math.max(0, inner - label.length - 1))}╮`),
|
|
257
|
+
];
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
class BorderBottom {
|
|
261
|
+
color;
|
|
262
|
+
label;
|
|
263
|
+
labelColor;
|
|
264
|
+
constructor(color, label, labelColor) {
|
|
265
|
+
this.color = color;
|
|
266
|
+
this.label = label;
|
|
267
|
+
this.labelColor = labelColor;
|
|
268
|
+
}
|
|
269
|
+
invalidate() { }
|
|
270
|
+
render(width) {
|
|
271
|
+
const inner = Math.max(0, width - 2);
|
|
272
|
+
if (inner < this.label.length + 4)
|
|
273
|
+
return [this.color(`╰${'─'.repeat(inner)}╯`)];
|
|
274
|
+
const tag = ` ${this.label} `;
|
|
275
|
+
return [
|
|
276
|
+
this.color(`╰${'─'.repeat(Math.max(0, inner - tag.length - 1))}`)
|
|
277
|
+
+ this.labelColor(tag)
|
|
278
|
+
+ this.color('─╯'),
|
|
279
|
+
];
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
function createEditorTheme(theme) {
|
|
283
|
+
return {
|
|
284
|
+
borderColor: (text) => theme.fg('accent', text),
|
|
285
|
+
selectList: {
|
|
286
|
+
selectedPrefix: (text) => theme.fg('accent', text),
|
|
287
|
+
selectedText: (text) => theme.fg('accent', text),
|
|
288
|
+
description: (text) => theme.fg('muted', text),
|
|
289
|
+
scrollInfo: (text) => theme.fg('dim', text),
|
|
290
|
+
noMatch: (text) => theme.fg('warning', text),
|
|
291
|
+
},
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
function keyHint(theme, keybindings, binding, description) {
|
|
295
|
+
return `${theme.fg('dim', keybindings.getKeys(binding).join('/'))}${theme.fg('muted', ` ${description}`)}`;
|
|
296
|
+
}
|
|
297
|
+
function literalHint(theme, key, description) {
|
|
298
|
+
return `${theme.fg('dim', key)}${theme.fg('muted', ` ${description}`)}`;
|
|
299
|
+
}
|
|
300
|
+
function matchesUp(data, keybindings) {
|
|
301
|
+
return keybindings.matches(data, 'tui.select.up')
|
|
302
|
+
|| matchesKey(data, Key.shift('tab'))
|
|
303
|
+
|| matchesKey(data, Key.ctrl('k'));
|
|
304
|
+
}
|
|
305
|
+
function matchesDown(data, keybindings) {
|
|
306
|
+
return keybindings.matches(data, 'tui.select.down')
|
|
307
|
+
|| matchesKey(data, Key.tab)
|
|
308
|
+
|| matchesKey(data, Key.ctrl('j'));
|
|
309
|
+
}
|
|
310
|
+
function matchesSubmit(data, keybindings) {
|
|
311
|
+
return keybindings.matches(data, 'tui.select.confirm')
|
|
312
|
+
|| keybindings.matches(data, 'tui.input.submit')
|
|
313
|
+
|| matchesKey(data, Key.enter)
|
|
314
|
+
|| matchesKey(data, Key.return);
|
|
315
|
+
}
|
|
316
|
+
class MultiSelectList {
|
|
317
|
+
options;
|
|
318
|
+
allowFreeform;
|
|
319
|
+
allowComment;
|
|
320
|
+
theme;
|
|
321
|
+
keybindings;
|
|
322
|
+
commentToggle;
|
|
323
|
+
selectedIndex = 0;
|
|
324
|
+
checked = new Set();
|
|
325
|
+
commentEnabled = false;
|
|
326
|
+
maxVisibleRows = 10;
|
|
327
|
+
cachedWidth;
|
|
328
|
+
cachedLines;
|
|
329
|
+
onCancel;
|
|
330
|
+
onSubmit;
|
|
331
|
+
onEnterFreeform;
|
|
332
|
+
constructor(options, allowFreeform, allowComment, theme, keybindings, commentToggle) {
|
|
333
|
+
this.options = options;
|
|
334
|
+
this.allowFreeform = allowFreeform;
|
|
335
|
+
this.allowComment = allowComment;
|
|
336
|
+
this.theme = theme;
|
|
337
|
+
this.keybindings = keybindings;
|
|
338
|
+
this.commentToggle = commentToggle;
|
|
339
|
+
}
|
|
340
|
+
setMaxVisibleRows(rows) {
|
|
341
|
+
const normalized = Math.max(1, Math.floor(rows));
|
|
342
|
+
if (normalized !== this.maxVisibleRows) {
|
|
343
|
+
this.maxVisibleRows = normalized;
|
|
344
|
+
this.invalidate();
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
invalidate() {
|
|
348
|
+
this.cachedWidth = undefined;
|
|
349
|
+
this.cachedLines = undefined;
|
|
350
|
+
}
|
|
351
|
+
handleInput(data) {
|
|
352
|
+
if (this.keybindings.matches(data, 'tui.select.cancel'))
|
|
353
|
+
return this.onCancel?.();
|
|
354
|
+
const count = this.itemCount();
|
|
355
|
+
if (count === 0)
|
|
356
|
+
return this.onCancel?.();
|
|
357
|
+
if (this.allowComment && !this.commentToggle.disabled && this.commentToggle.matches(data)) {
|
|
358
|
+
this.toggleComment();
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
361
|
+
if (matchesUp(data, this.keybindings)) {
|
|
362
|
+
this.selectedIndex = this.selectedIndex === 0 ? count - 1 : this.selectedIndex - 1;
|
|
363
|
+
this.invalidate();
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
if (matchesDown(data, this.keybindings)) {
|
|
367
|
+
this.selectedIndex = this.selectedIndex === count - 1 ? 0 : this.selectedIndex + 1;
|
|
368
|
+
this.invalidate();
|
|
369
|
+
return;
|
|
370
|
+
}
|
|
371
|
+
const number = data.match(/^[1-9]$/);
|
|
372
|
+
if (number) {
|
|
373
|
+
const index = Number(number[0]) - 1;
|
|
374
|
+
if (index < this.options.length) {
|
|
375
|
+
this.toggle(index);
|
|
376
|
+
this.selectedIndex = index;
|
|
377
|
+
this.invalidate();
|
|
378
|
+
}
|
|
379
|
+
return;
|
|
380
|
+
}
|
|
381
|
+
if (matchesKey(data, Key.space)) {
|
|
382
|
+
if (this.isCommentRow(this.selectedIndex))
|
|
383
|
+
return this.toggleComment();
|
|
384
|
+
if (this.isFreeformRow(this.selectedIndex))
|
|
385
|
+
return this.onEnterFreeform?.();
|
|
386
|
+
this.toggle(this.selectedIndex);
|
|
387
|
+
this.invalidate();
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
390
|
+
if (!matchesSubmit(data, this.keybindings))
|
|
391
|
+
return;
|
|
392
|
+
if (this.isCommentRow(this.selectedIndex))
|
|
393
|
+
return this.toggleComment();
|
|
394
|
+
if (this.isFreeformRow(this.selectedIndex))
|
|
395
|
+
return this.onEnterFreeform?.();
|
|
396
|
+
const selections = [...this.checked]
|
|
397
|
+
.sort((left, right) => left - right)
|
|
398
|
+
.map((index) => this.options[index]?.title)
|
|
399
|
+
.filter((title) => title !== undefined);
|
|
400
|
+
const fallback = this.options[this.selectedIndex]?.title;
|
|
401
|
+
const result = selections.length > 0 ? selections : fallback ? [fallback] : [];
|
|
402
|
+
if (result.length > 0)
|
|
403
|
+
this.onSubmit?.(result, this.commentEnabled);
|
|
404
|
+
else
|
|
405
|
+
this.onCancel?.();
|
|
406
|
+
}
|
|
407
|
+
render(width) {
|
|
408
|
+
if (this.cachedLines && this.cachedWidth === width)
|
|
409
|
+
return this.cachedLines;
|
|
410
|
+
const count = this.itemCount();
|
|
411
|
+
if (count === 0)
|
|
412
|
+
return [this.theme.fg('warning', 'No options')];
|
|
413
|
+
const blocks = [];
|
|
414
|
+
for (let index = 0; index < count; index += 1) {
|
|
415
|
+
const active = index === this.selectedIndex;
|
|
416
|
+
const pointer = active ? this.theme.fg('accent', '→') : ' ';
|
|
417
|
+
const block = [];
|
|
418
|
+
if (this.isCommentRow(index)) {
|
|
419
|
+
const check = this.commentEnabled ? this.theme.fg('success', '[✓]') : this.theme.fg('dim', '[ ]');
|
|
420
|
+
block.push(truncateToWidth(`${pointer} ${check} ${this.theme.fg(active ? 'accent' : 'text', COMMENT_LABEL)}`, width, ''));
|
|
421
|
+
blocks.push(block);
|
|
422
|
+
continue;
|
|
423
|
+
}
|
|
424
|
+
if (this.isFreeformRow(index)) {
|
|
425
|
+
block.push(truncateToWidth(`${pointer} ${this.theme.fg(active ? 'accent' : 'text', 'Type something.')} ${this.theme.fg('muted', '— Enter a custom response')}`, width, ''));
|
|
426
|
+
blocks.push(block);
|
|
427
|
+
continue;
|
|
428
|
+
}
|
|
429
|
+
const option = this.options[index];
|
|
430
|
+
const check = this.checked.has(index) ? this.theme.fg('success', '[✓]') : this.theme.fg('dim', '[ ]');
|
|
431
|
+
block.push(truncateToWidth(`${pointer} ${this.theme.fg('dim', `${index + 1}.`)} ${check} ${this.theme.fg(active ? 'accent' : 'text', this.theme.bold(option.title))}`, width, ''));
|
|
432
|
+
if (option.description) {
|
|
433
|
+
for (const line of wrapTextWithAnsi(option.description, Math.max(10, width - 6))) {
|
|
434
|
+
block.push(truncateToWidth(` ${this.theme.fg('muted', line)}`, width, ''));
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
blocks.push(block);
|
|
438
|
+
}
|
|
439
|
+
const totalRows = blocks.reduce((sum, block) => sum + block.length, 0);
|
|
440
|
+
let lines;
|
|
441
|
+
if (totalRows <= this.maxVisibleRows) {
|
|
442
|
+
lines = blocks.flat();
|
|
443
|
+
}
|
|
444
|
+
else {
|
|
445
|
+
const availableRows = this.maxVisibleRows > 1 ? this.maxVisibleRows - 1 : 1;
|
|
446
|
+
const selectedBlock = blocks[this.selectedIndex] ?? blocks[0] ?? [];
|
|
447
|
+
if (selectedBlock.length >= availableRows) {
|
|
448
|
+
lines = selectedBlock.slice(0, availableRows);
|
|
449
|
+
}
|
|
450
|
+
else {
|
|
451
|
+
let start = this.selectedIndex;
|
|
452
|
+
let end = this.selectedIndex + 1;
|
|
453
|
+
let usedRows = selectedBlock.length;
|
|
454
|
+
while (true) {
|
|
455
|
+
const next = blocks[end];
|
|
456
|
+
if (next && usedRows + next.length <= availableRows) {
|
|
457
|
+
usedRows += next.length;
|
|
458
|
+
end += 1;
|
|
459
|
+
continue;
|
|
460
|
+
}
|
|
461
|
+
const previous = blocks[start - 1];
|
|
462
|
+
if (previous && usedRows + previous.length <= availableRows) {
|
|
463
|
+
start -= 1;
|
|
464
|
+
usedRows += previous.length;
|
|
465
|
+
continue;
|
|
466
|
+
}
|
|
467
|
+
break;
|
|
468
|
+
}
|
|
469
|
+
lines = blocks.slice(start, end).flat();
|
|
470
|
+
}
|
|
471
|
+
if (this.maxVisibleRows > 1) {
|
|
472
|
+
lines.push(this.theme.fg('dim', truncateToWidth(` (${this.selectedIndex + 1}/${count})`, width, '')));
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
this.cachedWidth = width;
|
|
476
|
+
this.cachedLines = lines;
|
|
477
|
+
return lines;
|
|
478
|
+
}
|
|
479
|
+
itemCount() {
|
|
480
|
+
return this.options.length + (this.allowComment ? 1 : 0) + (this.allowFreeform ? 1 : 0);
|
|
481
|
+
}
|
|
482
|
+
isCommentRow(index) {
|
|
483
|
+
return this.allowComment && index === this.options.length;
|
|
484
|
+
}
|
|
485
|
+
isFreeformRow(index) {
|
|
486
|
+
return this.allowFreeform && index === this.options.length + (this.allowComment ? 1 : 0);
|
|
487
|
+
}
|
|
488
|
+
toggle(index) {
|
|
489
|
+
if (index < 0 || index >= this.options.length)
|
|
490
|
+
return;
|
|
491
|
+
if (this.checked.has(index))
|
|
492
|
+
this.checked.delete(index);
|
|
493
|
+
else
|
|
494
|
+
this.checked.add(index);
|
|
495
|
+
}
|
|
496
|
+
toggleComment() {
|
|
497
|
+
if (!this.allowComment)
|
|
498
|
+
return;
|
|
499
|
+
this.commentEnabled = !this.commentEnabled;
|
|
500
|
+
this.invalidate();
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
class SearchableSingleSelect {
|
|
504
|
+
options;
|
|
505
|
+
allowFreeform;
|
|
506
|
+
allowComment;
|
|
507
|
+
theme;
|
|
508
|
+
singleSelectLayout;
|
|
509
|
+
keybindings;
|
|
510
|
+
commentToggle;
|
|
511
|
+
selectedIndex = 0;
|
|
512
|
+
searchQuery = '';
|
|
513
|
+
commentEnabled = false;
|
|
514
|
+
maxVisibleRows = 12;
|
|
515
|
+
cachedWidth;
|
|
516
|
+
cachedLines;
|
|
517
|
+
onCancel;
|
|
518
|
+
onSubmit;
|
|
519
|
+
onEnterFreeform;
|
|
520
|
+
constructor(options, allowFreeform, allowComment, theme, singleSelectLayout, keybindings, commentToggle) {
|
|
521
|
+
this.options = options;
|
|
522
|
+
this.allowFreeform = allowFreeform;
|
|
523
|
+
this.allowComment = allowComment;
|
|
524
|
+
this.theme = theme;
|
|
525
|
+
this.singleSelectLayout = singleSelectLayout;
|
|
526
|
+
this.keybindings = keybindings;
|
|
527
|
+
this.commentToggle = commentToggle;
|
|
528
|
+
}
|
|
529
|
+
setMaxVisibleRows(rows) {
|
|
530
|
+
const normalized = Math.max(1, Math.floor(rows));
|
|
531
|
+
if (normalized !== this.maxVisibleRows) {
|
|
532
|
+
this.maxVisibleRows = normalized;
|
|
533
|
+
this.invalidate();
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
invalidate() {
|
|
537
|
+
this.cachedWidth = undefined;
|
|
538
|
+
this.cachedLines = undefined;
|
|
539
|
+
}
|
|
540
|
+
handleInput(data) {
|
|
541
|
+
if (this.searchQuery && matchesKey(data, Key.escape)) {
|
|
542
|
+
this.setSearch('');
|
|
543
|
+
return;
|
|
544
|
+
}
|
|
545
|
+
if (this.keybindings.matches(data, 'tui.select.cancel'))
|
|
546
|
+
return this.onCancel?.();
|
|
547
|
+
if (this.allowComment && !this.commentToggle.disabled && this.commentToggle.matches(data)) {
|
|
548
|
+
this.toggleComment();
|
|
549
|
+
return;
|
|
550
|
+
}
|
|
551
|
+
const filtered = this.filtered();
|
|
552
|
+
const count = this.itemCount(filtered);
|
|
553
|
+
if (matchesUp(data, this.keybindings) && count > 0) {
|
|
554
|
+
this.selectedIndex = this.selectedIndex === 0 ? count - 1 : this.selectedIndex - 1;
|
|
555
|
+
this.invalidate();
|
|
556
|
+
return;
|
|
557
|
+
}
|
|
558
|
+
if (matchesDown(data, this.keybindings) && count > 0) {
|
|
559
|
+
this.selectedIndex = this.selectedIndex === count - 1 ? 0 : this.selectedIndex + 1;
|
|
560
|
+
this.invalidate();
|
|
561
|
+
return;
|
|
562
|
+
}
|
|
563
|
+
const number = data.match(/^[1-9]$/);
|
|
564
|
+
if (number && Number(number[0]) <= filtered.length) {
|
|
565
|
+
this.selectedIndex = Number(number[0]) - 1;
|
|
566
|
+
this.invalidate();
|
|
567
|
+
return;
|
|
568
|
+
}
|
|
569
|
+
if (matchesKey(data, Key.space) && this.isCommentRow(this.selectedIndex, filtered)) {
|
|
570
|
+
this.toggleComment();
|
|
571
|
+
return;
|
|
572
|
+
}
|
|
573
|
+
if (matchesSubmit(data, this.keybindings) && count > 0) {
|
|
574
|
+
if (this.isCommentRow(this.selectedIndex, filtered))
|
|
575
|
+
return this.toggleComment();
|
|
576
|
+
if (this.isFreeformRow(this.selectedIndex, filtered))
|
|
577
|
+
return this.onEnterFreeform?.();
|
|
578
|
+
const selected = filtered[this.selectedIndex]?.title;
|
|
579
|
+
if (selected)
|
|
580
|
+
this.onSubmit?.(selected, this.commentEnabled);
|
|
581
|
+
else
|
|
582
|
+
this.onCancel?.();
|
|
583
|
+
return;
|
|
584
|
+
}
|
|
585
|
+
if (this.keybindings.matches(data, 'tui.editor.deleteCharBackward') || matchesKey(data, Key.backspace)) {
|
|
586
|
+
const characters = [...this.searchQuery];
|
|
587
|
+
characters.pop();
|
|
588
|
+
this.setSearch(characters.join(''));
|
|
589
|
+
return;
|
|
590
|
+
}
|
|
591
|
+
const printable = printableInput(data);
|
|
592
|
+
if (printable)
|
|
593
|
+
this.setSearch(this.searchQuery + printable);
|
|
594
|
+
}
|
|
595
|
+
render(width) {
|
|
596
|
+
if (this.cachedLines && this.cachedWidth === width)
|
|
597
|
+
return this.cachedLines;
|
|
598
|
+
const filtered = this.filtered();
|
|
599
|
+
const count = this.itemCount(filtered);
|
|
600
|
+
this.selectedIndex = count > 0 ? Math.min(this.selectedIndex, count - 1) : 0;
|
|
601
|
+
const split = this.singleSelectLayout === 'list' ? null : splitPaneWidths(width);
|
|
602
|
+
const lines = split
|
|
603
|
+
? this.renderSplit(split.left, split.right, filtered)
|
|
604
|
+
: this.renderList(width, filtered, false);
|
|
605
|
+
this.cachedWidth = width;
|
|
606
|
+
this.cachedLines = lines;
|
|
607
|
+
return lines;
|
|
608
|
+
}
|
|
609
|
+
renderList(width, filtered, hideDescriptions) {
|
|
610
|
+
const query = this.searchQuery ? this.theme.fg('text', this.searchQuery) : this.theme.fg('dim', 'type to filter');
|
|
611
|
+
const header = [truncateToWidth(`${this.theme.fg('accent', 'Filter:')} ${query}`, width, '')];
|
|
612
|
+
if (this.searchQuery && filtered.length === 0)
|
|
613
|
+
header.push(this.theme.fg('warning', 'No matching options'));
|
|
614
|
+
const rows = renderSingleSelectRows({
|
|
615
|
+
options: filtered,
|
|
616
|
+
selectedIndex: this.selectedIndex,
|
|
617
|
+
width,
|
|
618
|
+
allowFreeform: this.allowFreeform,
|
|
619
|
+
allowComment: this.allowComment,
|
|
620
|
+
commentEnabled: this.commentEnabled,
|
|
621
|
+
maxRows: Math.max(1, this.maxVisibleRows - header.length),
|
|
622
|
+
hideDescriptions,
|
|
623
|
+
});
|
|
624
|
+
const renderedRows = rows.map((row) => this.styleLine(row.line, width, row.selected));
|
|
625
|
+
if (this.maxVisibleRows === 1)
|
|
626
|
+
return renderedRows.length > 0 ? [renderedRows[0]] : header.slice(-1);
|
|
627
|
+
return [...header, ...renderedRows].slice(0, this.maxVisibleRows);
|
|
628
|
+
}
|
|
629
|
+
renderSplit(leftWidth, rightWidth, filtered) {
|
|
630
|
+
const left = this.renderList(leftWidth, filtered, true);
|
|
631
|
+
const right = this.preview(rightWidth, filtered);
|
|
632
|
+
const rows = Math.min(this.maxVisibleRows, Math.max(left.length, right.length));
|
|
633
|
+
return Array.from({ length: rows }, (_, index) => (`${truncateToWidth(left[index] ?? '', leftWidth, '', true)}${this.theme.fg('dim', SPLIT_SEPARATOR)}${truncateToWidth(right[index] ?? '', rightWidth, '')}`));
|
|
634
|
+
}
|
|
635
|
+
preview(width, filtered) {
|
|
636
|
+
let title;
|
|
637
|
+
let description;
|
|
638
|
+
if (this.isCommentRow(this.selectedIndex, filtered)) {
|
|
639
|
+
title = 'Additional context';
|
|
640
|
+
description = `Currently ${this.commentEnabled ? 'enabled' : 'disabled'}. Add an explanation after selecting.`;
|
|
641
|
+
}
|
|
642
|
+
else if (this.isFreeformRow(this.selectedIndex, filtered)) {
|
|
643
|
+
title = 'Custom response';
|
|
644
|
+
description = 'Open the editor to write an answer when none of the listed options fit.';
|
|
645
|
+
}
|
|
646
|
+
else {
|
|
647
|
+
const selected = filtered[this.selectedIndex];
|
|
648
|
+
title = selected?.title ?? 'No option selected';
|
|
649
|
+
description = selected?.description ?? 'No additional details provided for this option.';
|
|
650
|
+
}
|
|
651
|
+
const lines = [this.theme.fg('accent', this.theme.bold(title)), ''];
|
|
652
|
+
lines.push(...wrapTextWithAnsi(description, Math.max(10, width)).map((line) => this.theme.fg('muted', line)));
|
|
653
|
+
return lines.slice(0, this.maxVisibleRows);
|
|
654
|
+
}
|
|
655
|
+
styleLine(line, width, selected) {
|
|
656
|
+
if (selected)
|
|
657
|
+
return truncateToWidth(this.theme.fg('accent', this.theme.bold(line)), width, '');
|
|
658
|
+
if (line.startsWith(' '))
|
|
659
|
+
return truncateToWidth(this.theme.fg('muted', line), width, '');
|
|
660
|
+
if (line.trim().startsWith('('))
|
|
661
|
+
return truncateToWidth(this.theme.fg('dim', line), width, '');
|
|
662
|
+
return truncateToWidth(this.theme.fg('text', line), width, '');
|
|
663
|
+
}
|
|
664
|
+
filtered() {
|
|
665
|
+
return fuzzyFilter([...this.options], this.searchQuery, (option) => `${option.title} ${option.description ?? ''}`);
|
|
666
|
+
}
|
|
667
|
+
itemCount(filtered) {
|
|
668
|
+
return filtered.length + (this.allowComment ? 1 : 0) + (this.allowFreeform ? 1 : 0);
|
|
669
|
+
}
|
|
670
|
+
isCommentRow(index, filtered) {
|
|
671
|
+
return this.allowComment && index === filtered.length;
|
|
672
|
+
}
|
|
673
|
+
isFreeformRow(index, filtered) {
|
|
674
|
+
return this.allowFreeform && index === filtered.length + (this.allowComment ? 1 : 0);
|
|
675
|
+
}
|
|
676
|
+
setSearch(value) {
|
|
677
|
+
this.searchQuery = value;
|
|
678
|
+
this.selectedIndex = 0;
|
|
679
|
+
this.invalidate();
|
|
680
|
+
}
|
|
681
|
+
toggleComment() {
|
|
682
|
+
this.commentEnabled = !this.commentEnabled;
|
|
683
|
+
this.invalidate();
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
function printableInput(data) {
|
|
687
|
+
const kitty = decodeKittyPrintable(data);
|
|
688
|
+
if (kitty !== undefined)
|
|
689
|
+
return kitty;
|
|
690
|
+
const characters = [...data];
|
|
691
|
+
if (characters.length !== 1)
|
|
692
|
+
return null;
|
|
693
|
+
const character = characters[0];
|
|
694
|
+
const code = character.charCodeAt(0);
|
|
695
|
+
return code < 32 || code === 0x7f || (code >= 0x80 && code <= 0x9f) ? null : character;
|
|
696
|
+
}
|
|
697
|
+
function splitPaneWidths(width) {
|
|
698
|
+
if (width < SPLIT_PANE_MIN_WIDTH)
|
|
699
|
+
return null;
|
|
700
|
+
const available = width - SPLIT_SEPARATOR.length;
|
|
701
|
+
if (available < SPLIT_LEFT_MIN_WIDTH + SPLIT_RIGHT_MIN_WIDTH)
|
|
702
|
+
return null;
|
|
703
|
+
const left = Math.max(SPLIT_LEFT_MIN_WIDTH, Math.min(Math.floor(available * 0.42), available - SPLIT_RIGHT_MIN_WIDTH));
|
|
704
|
+
const right = available - left;
|
|
705
|
+
return right < SPLIT_RIGHT_MIN_WIDTH ? null : { left, right };
|
|
706
|
+
}
|
|
707
|
+
class AskPrompt extends Container {
|
|
708
|
+
question;
|
|
709
|
+
displayMode;
|
|
710
|
+
singleSelectLayout;
|
|
711
|
+
tui;
|
|
712
|
+
theme;
|
|
713
|
+
keybindings;
|
|
714
|
+
shortcuts;
|
|
715
|
+
onDone;
|
|
716
|
+
mode = 'select';
|
|
717
|
+
pendingSelections = [];
|
|
718
|
+
freeformDraft = '';
|
|
719
|
+
commentDraft = '';
|
|
720
|
+
modeContainer = new Container();
|
|
721
|
+
titleText = new Text('', 1, 0);
|
|
722
|
+
helpText = new Text('', 1, 0);
|
|
723
|
+
contextText;
|
|
724
|
+
contextIsCollapsible = false;
|
|
725
|
+
contextExpanded = false;
|
|
726
|
+
singleSelect;
|
|
727
|
+
multiSelect;
|
|
728
|
+
editor;
|
|
729
|
+
_focused = false;
|
|
730
|
+
get focused() {
|
|
731
|
+
return this._focused;
|
|
732
|
+
}
|
|
733
|
+
set focused(value) {
|
|
734
|
+
this._focused = value;
|
|
735
|
+
if (this.editor && this.mode !== 'select')
|
|
736
|
+
this.editor.focused = value;
|
|
737
|
+
}
|
|
738
|
+
constructor(question, displayMode, singleSelectLayout, tui, theme, keybindings, shortcuts, onDone) {
|
|
739
|
+
super();
|
|
740
|
+
this.question = question;
|
|
741
|
+
this.displayMode = displayMode;
|
|
742
|
+
this.singleSelectLayout = singleSelectLayout;
|
|
743
|
+
this.tui = tui;
|
|
744
|
+
this.theme = theme;
|
|
745
|
+
this.keybindings = keybindings;
|
|
746
|
+
this.shortcuts = shortcuts;
|
|
747
|
+
this.onDone = onDone;
|
|
748
|
+
this.addChild(new BorderTop((text) => theme.fg('accent', text), 'ask_user', (text) => theme.fg('dim', theme.bold(text))));
|
|
749
|
+
this.addChild(new Spacer(1));
|
|
750
|
+
this.addChild(this.titleText);
|
|
751
|
+
this.addChild(new Spacer(1));
|
|
752
|
+
this.addChild(new Text(theme.fg('text', theme.bold(question.question)), 1, 0));
|
|
753
|
+
if (question.context) {
|
|
754
|
+
this.addChild(new Spacer(1));
|
|
755
|
+
this.contextText = new Text('', 1, 0);
|
|
756
|
+
this.addChild(this.contextText);
|
|
757
|
+
}
|
|
758
|
+
this.addChild(new Spacer(1));
|
|
759
|
+
this.addChild(this.modeContainer);
|
|
760
|
+
this.addChild(new Spacer(1));
|
|
761
|
+
this.addChild(this.helpText);
|
|
762
|
+
this.addChild(new Spacer(1));
|
|
763
|
+
this.addChild(new BorderBottom((text) => theme.fg('accent', text), `v${VERSION}`, (text) => theme.fg('dim', text)));
|
|
764
|
+
this.showSelect();
|
|
765
|
+
}
|
|
766
|
+
invalidate() {
|
|
767
|
+
super.invalidate();
|
|
768
|
+
this.updateText();
|
|
769
|
+
}
|
|
770
|
+
render(width) {
|
|
771
|
+
const innerWidth = Math.max(1, width - (this.displayMode === 'overlay' ? BOX_OVERHEAD : 0));
|
|
772
|
+
const maxHeight = this.displayMode === 'overlay'
|
|
773
|
+
? overlayMaxRenderLines(this.tui.terminal.rows)
|
|
774
|
+
: undefined;
|
|
775
|
+
this.updateContext(innerWidth, maxHeight);
|
|
776
|
+
if (this.mode === 'select') {
|
|
777
|
+
const questionRows = wrapTextWithAnsi(this.question.question, Math.max(10, innerWidth - 2)).length;
|
|
778
|
+
const contextRows = this.contextText?.render(innerWidth).length ?? 0;
|
|
779
|
+
const staticLines = 10 + questionRows + (contextRows > 0 ? contextRows + 1 : 0);
|
|
780
|
+
const visibleRows = maxHeight === undefined
|
|
781
|
+
? (this.question.allowMultiple ? 10 : 12)
|
|
782
|
+
: Math.max(1, maxHeight - staticLines);
|
|
783
|
+
if (this.question.allowMultiple)
|
|
784
|
+
this.ensureMulti().setMaxVisibleRows(visibleRows);
|
|
785
|
+
else
|
|
786
|
+
this.ensureSingle().setMaxVisibleRows(visibleRows);
|
|
787
|
+
}
|
|
788
|
+
const lines = super.render(innerWidth);
|
|
789
|
+
if (maxHeight !== undefined && lines.length > maxHeight) {
|
|
790
|
+
if (maxHeight <= 1)
|
|
791
|
+
return [this.renderTopBorder(width)];
|
|
792
|
+
if (maxHeight === 2)
|
|
793
|
+
return [this.renderTopBorder(width), this.renderBottomBorder(width)];
|
|
794
|
+
const bodyCapacity = maxHeight - 2;
|
|
795
|
+
const renderedModeLines = this.modeContainer.render(innerWidth);
|
|
796
|
+
let prioritizedModeLines = renderedModeLines;
|
|
797
|
+
if (this.mode !== 'select' && renderedModeLines.length > 1) {
|
|
798
|
+
prioritizedModeLines = renderedModeLines.slice(0, -1);
|
|
799
|
+
}
|
|
800
|
+
else if (!this.question.allowMultiple && renderedModeLines.length > 1) {
|
|
801
|
+
prioritizedModeLines = renderedModeLines.slice(1);
|
|
802
|
+
}
|
|
803
|
+
const modeLines = prioritizedModeLines.slice(-bodyCapacity);
|
|
804
|
+
const promptBudget = Math.max(0, bodyCapacity - modeLines.length);
|
|
805
|
+
const promptLines = [
|
|
806
|
+
...new Text(this.theme.fg('text', this.theme.bold(this.question.question)), 1, 0).render(innerWidth),
|
|
807
|
+
...(this.contextText?.render(innerWidth) ?? []),
|
|
808
|
+
].slice(0, promptBudget);
|
|
809
|
+
return this.frameBody([...promptLines, ...modeLines], width, innerWidth);
|
|
810
|
+
}
|
|
811
|
+
return lines.map((line, index) => {
|
|
812
|
+
if (index === 0)
|
|
813
|
+
return this.renderTopBorder(width);
|
|
814
|
+
if (index === lines.length - 1)
|
|
815
|
+
return this.renderBottomBorder(width);
|
|
816
|
+
return this.displayMode === 'overlay'
|
|
817
|
+
? this.boxLine(line, innerWidth)
|
|
818
|
+
: truncateToWidth(line, width, '', true);
|
|
819
|
+
});
|
|
820
|
+
}
|
|
821
|
+
handleInput(data) {
|
|
822
|
+
if (this.contextIsCollapsible && matchesKey(data, CONTEXT_TOGGLE_KEY)) {
|
|
823
|
+
this.contextExpanded = !this.contextExpanded;
|
|
824
|
+
this.invalidate();
|
|
825
|
+
this.tui.requestRender();
|
|
826
|
+
return;
|
|
827
|
+
}
|
|
828
|
+
if (this.mode !== 'select') {
|
|
829
|
+
if (matchesKey(data, Key.escape)) {
|
|
830
|
+
this.showSelect();
|
|
831
|
+
return;
|
|
832
|
+
}
|
|
833
|
+
if (this.keybindings.matches(data, 'tui.select.cancel')) {
|
|
834
|
+
this.onDone(null);
|
|
835
|
+
return;
|
|
836
|
+
}
|
|
837
|
+
this.ensureEditor().handleInput(data);
|
|
838
|
+
this.tui.requestRender();
|
|
839
|
+
return;
|
|
840
|
+
}
|
|
841
|
+
if (this.question.allowMultiple)
|
|
842
|
+
this.ensureMulti().handleInput(data);
|
|
843
|
+
else
|
|
844
|
+
this.ensureSingle().handleInput(data);
|
|
845
|
+
this.tui.requestRender();
|
|
846
|
+
}
|
|
847
|
+
isTextInputMode() {
|
|
848
|
+
return this.mode !== 'select';
|
|
849
|
+
}
|
|
850
|
+
ensureSingle() {
|
|
851
|
+
if (this.singleSelect)
|
|
852
|
+
return this.singleSelect;
|
|
853
|
+
const list = new SearchableSingleSelect(this.question.options, this.question.allowFreeform, this.question.allowComment, this.theme, this.singleSelectLayout, this.keybindings, this.shortcuts.commentToggle);
|
|
854
|
+
list.onCancel = () => this.onDone(null);
|
|
855
|
+
list.onEnterFreeform = () => this.showFreeform();
|
|
856
|
+
list.onSubmit = (selection, comment) => this.handleSelection([selection], comment);
|
|
857
|
+
this.singleSelect = list;
|
|
858
|
+
return list;
|
|
859
|
+
}
|
|
860
|
+
ensureMulti() {
|
|
861
|
+
if (this.multiSelect)
|
|
862
|
+
return this.multiSelect;
|
|
863
|
+
const list = new MultiSelectList(this.question.options, this.question.allowFreeform, this.question.allowComment, this.theme, this.keybindings, this.shortcuts.commentToggle);
|
|
864
|
+
list.onCancel = () => this.onDone(null);
|
|
865
|
+
list.onEnterFreeform = () => this.showFreeform();
|
|
866
|
+
list.onSubmit = (selections, comment) => this.handleSelection(selections, comment);
|
|
867
|
+
this.multiSelect = list;
|
|
868
|
+
return list;
|
|
869
|
+
}
|
|
870
|
+
ensureEditor() {
|
|
871
|
+
if (this.editor)
|
|
872
|
+
return this.editor;
|
|
873
|
+
const editor = new Editor(this.tui, createEditorTheme(this.theme));
|
|
874
|
+
editor.disableSubmit = false;
|
|
875
|
+
editor.onSubmit = (text) => {
|
|
876
|
+
if (this.mode === 'freeform')
|
|
877
|
+
this.onDone(freeformResponse(text));
|
|
878
|
+
else
|
|
879
|
+
this.onDone(selectionResponse(this.pendingSelections, text));
|
|
880
|
+
};
|
|
881
|
+
editor.focused = this._focused;
|
|
882
|
+
this.editor = editor;
|
|
883
|
+
return editor;
|
|
884
|
+
}
|
|
885
|
+
handleSelection(selections, wantsComment) {
|
|
886
|
+
if (this.question.allowComment && wantsComment) {
|
|
887
|
+
this.pendingSelections = selections;
|
|
888
|
+
this.commentDraft = '';
|
|
889
|
+
this.showComment();
|
|
890
|
+
return;
|
|
891
|
+
}
|
|
892
|
+
this.onDone(selectionResponse(selections));
|
|
893
|
+
}
|
|
894
|
+
showSelect() {
|
|
895
|
+
this.saveDraft();
|
|
896
|
+
this.mode = 'select';
|
|
897
|
+
this.pendingSelections = [];
|
|
898
|
+
this.modeContainer.clear();
|
|
899
|
+
this.modeContainer.addChild(this.question.allowMultiple ? this.ensureMulti() : this.ensureSingle());
|
|
900
|
+
this.updateText();
|
|
901
|
+
this.invalidate();
|
|
902
|
+
this.tui.requestRender();
|
|
903
|
+
}
|
|
904
|
+
showFreeform() {
|
|
905
|
+
this.saveDraft();
|
|
906
|
+
this.mode = 'freeform';
|
|
907
|
+
this.modeContainer.clear();
|
|
908
|
+
this.setEditorText(this.freeformDraft);
|
|
909
|
+
this.modeContainer.addChild(new Text(this.theme.fg('accent', this.theme.bold('Custom response')), 1, 0));
|
|
910
|
+
this.modeContainer.addChild(new Spacer(1));
|
|
911
|
+
this.modeContainer.addChild(this.ensureEditor());
|
|
912
|
+
this.updateText();
|
|
913
|
+
this.invalidate();
|
|
914
|
+
this.tui.requestRender();
|
|
915
|
+
}
|
|
916
|
+
showComment() {
|
|
917
|
+
this.saveDraft();
|
|
918
|
+
this.mode = 'comment';
|
|
919
|
+
this.modeContainer.clear();
|
|
920
|
+
this.setEditorText(this.commentDraft);
|
|
921
|
+
this.modeContainer.addChild(new Text(this.theme.fg('accent', this.theme.bold('Selected:')), 1, 0));
|
|
922
|
+
this.modeContainer.addChild(new Text(this.pendingSelections.join(', '), 1, 0));
|
|
923
|
+
this.modeContainer.addChild(new Spacer(1));
|
|
924
|
+
this.modeContainer.addChild(this.ensureEditor());
|
|
925
|
+
this.updateText();
|
|
926
|
+
this.invalidate();
|
|
927
|
+
this.tui.requestRender();
|
|
928
|
+
}
|
|
929
|
+
saveDraft() {
|
|
930
|
+
if (!this.editor || this.mode === 'select')
|
|
931
|
+
return;
|
|
932
|
+
const text = this.editor.getText();
|
|
933
|
+
if (this.mode === 'freeform')
|
|
934
|
+
this.freeformDraft = text;
|
|
935
|
+
else
|
|
936
|
+
this.commentDraft = text;
|
|
937
|
+
}
|
|
938
|
+
setEditorText(text) {
|
|
939
|
+
this.ensureEditor().setText(text);
|
|
940
|
+
}
|
|
941
|
+
updateText() {
|
|
942
|
+
this.titleText.setText(this.theme.fg('accent', this.theme.bold(this.mode === 'comment' ? 'Optional comment' : 'Question')));
|
|
943
|
+
const overlay = this.displayMode === 'overlay' && !this.shortcuts.overlayToggle.disabled
|
|
944
|
+
? literalHint(this.theme, this.shortcuts.overlayToggle.spec, 'hide')
|
|
945
|
+
: undefined;
|
|
946
|
+
const context = this.contextIsCollapsible
|
|
947
|
+
? literalHint(this.theme, CONTEXT_TOGGLE_KEY, this.contextExpanded ? 'collapse context' : 'expand context')
|
|
948
|
+
: undefined;
|
|
949
|
+
if (this.mode !== 'select') {
|
|
950
|
+
this.helpText.setText(this.theme.fg('dim', [
|
|
951
|
+
keyHint(this.theme, this.keybindings, 'tui.input.submit', this.mode === 'comment' ? 'submit/skip' : 'submit'),
|
|
952
|
+
literalHint(this.theme, 'esc', 'back'),
|
|
953
|
+
context,
|
|
954
|
+
overlay,
|
|
955
|
+
].filter(Boolean).join(' • ')));
|
|
956
|
+
return;
|
|
957
|
+
}
|
|
958
|
+
const comment = this.question.allowComment && !this.shortcuts.commentToggle.disabled
|
|
959
|
+
? literalHint(this.theme, this.shortcuts.commentToggle.spec, 'toggle context')
|
|
960
|
+
: undefined;
|
|
961
|
+
this.helpText.setText(this.theme.fg('dim', [
|
|
962
|
+
this.question.allowMultiple ? literalHint(this.theme, 'space', 'toggle') : literalHint(this.theme, 'type', 'filter'),
|
|
963
|
+
literalHint(this.theme, '↑↓', 'navigate'),
|
|
964
|
+
comment,
|
|
965
|
+
context,
|
|
966
|
+
overlay,
|
|
967
|
+
keyHint(this.theme, this.keybindings, 'tui.select.confirm', this.question.allowMultiple ? 'submit' : 'select'),
|
|
968
|
+
keyHint(this.theme, this.keybindings, 'tui.select.cancel', 'cancel'),
|
|
969
|
+
].filter(Boolean).join(' • ')));
|
|
970
|
+
}
|
|
971
|
+
updateContext(width, maxHeight) {
|
|
972
|
+
if (!this.contextText || !this.question.context)
|
|
973
|
+
return;
|
|
974
|
+
const contentWidth = Math.max(10, width - 2);
|
|
975
|
+
const contextRows = wrapTextWithAnsi(this.question.context, contentWidth).length;
|
|
976
|
+
const questionRows = wrapTextWithAnsi(this.question.question, contentWidth).length;
|
|
977
|
+
const wouldCrowdChoices = maxHeight !== undefined && 11 + questionRows + contextRows + 1 > maxHeight;
|
|
978
|
+
const collapsible = contextRows > INLINE_CONTEXT_MAX_ROWS || wouldCrowdChoices;
|
|
979
|
+
if (this.contextIsCollapsible !== collapsible) {
|
|
980
|
+
this.contextIsCollapsible = collapsible;
|
|
981
|
+
if (!collapsible)
|
|
982
|
+
this.contextExpanded = false;
|
|
983
|
+
this.updateText();
|
|
984
|
+
}
|
|
985
|
+
if (this.contextIsCollapsible && !this.contextExpanded) {
|
|
986
|
+
this.contextText.setText(this.theme.fg('dim', `Context (${contextRows} lines) — ${CONTEXT_TOGGLE_KEY} expand`));
|
|
987
|
+
return;
|
|
988
|
+
}
|
|
989
|
+
this.contextText.setText(`${this.theme.fg('accent', this.theme.bold('Context:'))}\n${this.theme.fg('dim', this.question.context)}`);
|
|
990
|
+
}
|
|
991
|
+
frameBody(body, width, innerWidth) {
|
|
992
|
+
if (this.displayMode === 'inline') {
|
|
993
|
+
return [this.renderTopBorder(width), ...body.map((line) => truncateToWidth(line, width, '', true)), this.renderBottomBorder(width)];
|
|
994
|
+
}
|
|
995
|
+
return [
|
|
996
|
+
this.renderTopBorder(width),
|
|
997
|
+
...body.map((line) => this.boxLine(line, innerWidth)),
|
|
998
|
+
this.renderBottomBorder(width),
|
|
999
|
+
];
|
|
1000
|
+
}
|
|
1001
|
+
boxLine(line, innerWidth) {
|
|
1002
|
+
const border = (text) => this.theme.fg('accent', text);
|
|
1003
|
+
return `${border(BOX_LEFT)}${truncateToWidth(line, innerWidth, '', true)}${border(BOX_RIGHT)}`;
|
|
1004
|
+
}
|
|
1005
|
+
renderTopBorder(width) {
|
|
1006
|
+
if (this.displayMode === 'inline')
|
|
1007
|
+
return this.theme.fg('accent', '─'.repeat(Math.max(1, width)));
|
|
1008
|
+
return new BorderTop((text) => this.theme.fg('accent', text), 'ask_user', (text) => this.theme.fg('dim', this.theme.bold(text))).render(width)[0];
|
|
1009
|
+
}
|
|
1010
|
+
renderBottomBorder(width) {
|
|
1011
|
+
if (this.displayMode === 'inline')
|
|
1012
|
+
return this.theme.fg('accent', '─'.repeat(Math.max(1, width)));
|
|
1013
|
+
return new BorderBottom((text) => this.theme.fg('accent', text), `v${VERSION}`, (text) => this.theme.fg('dim', text)).render(width)[0];
|
|
1014
|
+
}
|
|
1015
|
+
}
|
|
1016
|
+
class AskWizard {
|
|
1017
|
+
questions;
|
|
1018
|
+
displayMode;
|
|
1019
|
+
singleSelectLayout;
|
|
1020
|
+
tui;
|
|
1021
|
+
theme;
|
|
1022
|
+
keybindings;
|
|
1023
|
+
shortcuts;
|
|
1024
|
+
reportProgress;
|
|
1025
|
+
onDone;
|
|
1026
|
+
index = 0;
|
|
1027
|
+
responses = new Map();
|
|
1028
|
+
prompt;
|
|
1029
|
+
_focused = false;
|
|
1030
|
+
get focused() {
|
|
1031
|
+
return this._focused;
|
|
1032
|
+
}
|
|
1033
|
+
set focused(value) {
|
|
1034
|
+
this._focused = value;
|
|
1035
|
+
if (this.prompt)
|
|
1036
|
+
this.prompt.focused = value;
|
|
1037
|
+
}
|
|
1038
|
+
constructor(questions, displayMode, singleSelectLayout, tui, theme, keybindings, shortcuts, reportProgress, onDone) {
|
|
1039
|
+
this.questions = questions;
|
|
1040
|
+
this.displayMode = displayMode;
|
|
1041
|
+
this.singleSelectLayout = singleSelectLayout;
|
|
1042
|
+
this.tui = tui;
|
|
1043
|
+
this.theme = theme;
|
|
1044
|
+
this.keybindings = keybindings;
|
|
1045
|
+
this.shortcuts = shortcuts;
|
|
1046
|
+
this.reportProgress = reportProgress;
|
|
1047
|
+
this.onDone = onDone;
|
|
1048
|
+
}
|
|
1049
|
+
invalidate() {
|
|
1050
|
+
this.prompt?.invalidate();
|
|
1051
|
+
}
|
|
1052
|
+
handleInput(data) {
|
|
1053
|
+
if (this.index === this.questions.length) {
|
|
1054
|
+
if (this.navigate(data))
|
|
1055
|
+
return;
|
|
1056
|
+
if (matchesSubmit(data, this.keybindings)) {
|
|
1057
|
+
const answers = this.answers();
|
|
1058
|
+
this.onDone(answers.some((answer) => answer.response !== null) ? answers : null);
|
|
1059
|
+
}
|
|
1060
|
+
else if (this.keybindings.matches(data, 'tui.select.cancel')) {
|
|
1061
|
+
this.onDone(null);
|
|
1062
|
+
}
|
|
1063
|
+
return;
|
|
1064
|
+
}
|
|
1065
|
+
const prompt = this.ensurePrompt();
|
|
1066
|
+
if (!prompt.isTextInputMode() && this.navigate(data))
|
|
1067
|
+
return;
|
|
1068
|
+
prompt.handleInput(data);
|
|
1069
|
+
}
|
|
1070
|
+
render(width) {
|
|
1071
|
+
const body = this.index === this.questions.length ? this.renderReview(width) : this.ensurePrompt().render(width);
|
|
1072
|
+
if (body.length < 2)
|
|
1073
|
+
return body;
|
|
1074
|
+
const border = (text) => this.theme.fg('accent', text);
|
|
1075
|
+
const inner = Math.max(1, width - (this.displayMode === 'overlay' ? BOX_OVERHEAD : 0));
|
|
1076
|
+
const navigation = this.displayMode === 'overlay'
|
|
1077
|
+
? `${border(BOX_LEFT)}${truncateToWidth(this.navigation(), inner, '', true)}${border(BOX_RIGHT)}`
|
|
1078
|
+
: truncateToWidth(this.navigation(), width, '', true);
|
|
1079
|
+
const spacer = this.displayMode === 'overlay'
|
|
1080
|
+
? `${border(BOX_LEFT)}${truncateToWidth('', inner, '', true)}${border(BOX_RIGHT)}`
|
|
1081
|
+
: ' '.repeat(width);
|
|
1082
|
+
const decorated = [body[0], navigation, spacer, ...body.slice(1)];
|
|
1083
|
+
if (this.displayMode !== 'overlay')
|
|
1084
|
+
return decorated;
|
|
1085
|
+
const maxHeight = overlayMaxRenderLines(this.tui.terminal.rows);
|
|
1086
|
+
if (decorated.length <= maxHeight)
|
|
1087
|
+
return decorated;
|
|
1088
|
+
if (maxHeight <= 1)
|
|
1089
|
+
return [body[0]];
|
|
1090
|
+
if (maxHeight === 2)
|
|
1091
|
+
return [body[0], body.at(-1)];
|
|
1092
|
+
const contentCapacity = maxHeight - 2;
|
|
1093
|
+
const promptContent = body.slice(1, -1);
|
|
1094
|
+
const content = contentCapacity === 1
|
|
1095
|
+
? promptContent.slice(-1)
|
|
1096
|
+
: [navigation, ...promptContent.slice(-(contentCapacity - 1))];
|
|
1097
|
+
return [body[0], ...content, body.at(-1)];
|
|
1098
|
+
}
|
|
1099
|
+
ensurePrompt() {
|
|
1100
|
+
if (this.prompt)
|
|
1101
|
+
return this.prompt;
|
|
1102
|
+
const question = this.questions[this.index];
|
|
1103
|
+
this.prompt = new AskPrompt(question, this.displayMode, this.singleSelectLayout, this.tui, this.theme, this.keybindings, this.shortcuts, (response) => {
|
|
1104
|
+
if (response === null) {
|
|
1105
|
+
this.onDone(null);
|
|
1106
|
+
return;
|
|
1107
|
+
}
|
|
1108
|
+
this.responses.set(question.id, response);
|
|
1109
|
+
const answers = this.answers();
|
|
1110
|
+
this.reportProgress(answers);
|
|
1111
|
+
this.index = this.index < this.questions.length - 1 ? this.index + 1 : this.questions.length;
|
|
1112
|
+
this.prompt = undefined;
|
|
1113
|
+
this.invalidate();
|
|
1114
|
+
this.tui.requestRender();
|
|
1115
|
+
});
|
|
1116
|
+
this.prompt.focused = this._focused;
|
|
1117
|
+
return this.prompt;
|
|
1118
|
+
}
|
|
1119
|
+
navigate(data) {
|
|
1120
|
+
if (matchesKey(data, Key.tab) || matchesKey(data, Key.right)) {
|
|
1121
|
+
this.goTo((this.index + 1) % (this.questions.length + 1));
|
|
1122
|
+
return true;
|
|
1123
|
+
}
|
|
1124
|
+
if (matchesKey(data, Key.shift('tab')) || matchesKey(data, Key.left)) {
|
|
1125
|
+
this.goTo((this.index - 1 + this.questions.length + 1) % (this.questions.length + 1));
|
|
1126
|
+
return true;
|
|
1127
|
+
}
|
|
1128
|
+
return false;
|
|
1129
|
+
}
|
|
1130
|
+
goTo(index) {
|
|
1131
|
+
this.index = index;
|
|
1132
|
+
this.prompt = undefined;
|
|
1133
|
+
this.invalidate();
|
|
1134
|
+
this.tui.requestRender();
|
|
1135
|
+
}
|
|
1136
|
+
answers() {
|
|
1137
|
+
return this.questions.map((question) => ({
|
|
1138
|
+
questionId: question.id,
|
|
1139
|
+
response: this.responses.get(question.id) ?? null,
|
|
1140
|
+
}));
|
|
1141
|
+
}
|
|
1142
|
+
navigation() {
|
|
1143
|
+
const parts = [this.theme.fg('dim', '←')];
|
|
1144
|
+
for (let index = 0; index < this.questions.length; index += 1) {
|
|
1145
|
+
const question = this.questions[index];
|
|
1146
|
+
const answered = this.responses.has(question.id);
|
|
1147
|
+
const label = `${answered ? '✓' : '□'} ${question.header}`;
|
|
1148
|
+
parts.push(index === this.index
|
|
1149
|
+
? this.theme.fg('accent', `[${label}]`)
|
|
1150
|
+
: this.theme.fg(answered ? 'success' : 'muted', label));
|
|
1151
|
+
}
|
|
1152
|
+
const submit = `${this.responses.size > 0 ? '✓' : '□'} Submit`;
|
|
1153
|
+
parts.push(this.index === this.questions.length
|
|
1154
|
+
? this.theme.fg('accent', `[${submit}]`)
|
|
1155
|
+
: this.theme.fg(this.responses.size > 0 ? 'success' : 'muted', submit));
|
|
1156
|
+
parts.push(this.theme.fg('dim', '→'));
|
|
1157
|
+
return parts.join(' ');
|
|
1158
|
+
}
|
|
1159
|
+
renderReview(width) {
|
|
1160
|
+
const border = (text) => this.theme.fg('accent', text);
|
|
1161
|
+
const inner = Math.max(1, width - (this.displayMode === 'overlay' ? BOX_OVERHEAD : 0));
|
|
1162
|
+
const body = [this.theme.fg('accent', this.theme.bold('Review answers')), ''];
|
|
1163
|
+
for (const question of this.questions) {
|
|
1164
|
+
body.push(`${this.theme.fg('muted', `${question.header}:`)} ${this.theme.fg('text', question.question)}`);
|
|
1165
|
+
body.push(` ${this.responses.has(question.id) ? formatResponse(this.responses.get(question.id)) : this.theme.fg('muted', 'Skipped')}`);
|
|
1166
|
+
}
|
|
1167
|
+
body.push('', this.theme.fg('dim', 'Enter submit • unanswered questions are skipped • Tab/←→ navigate • Esc cancel'));
|
|
1168
|
+
const bodyLines = body.map((line) => this.displayMode === 'overlay'
|
|
1169
|
+
? this.boxLine(line, inner)
|
|
1170
|
+
: truncateToWidth(line, width, '', true));
|
|
1171
|
+
return [
|
|
1172
|
+
this.displayMode === 'overlay'
|
|
1173
|
+
? new BorderTop(border, 'ask_user', (text) => this.theme.fg('dim', this.theme.bold(text))).render(width)[0]
|
|
1174
|
+
: border('─'.repeat(Math.max(1, width))),
|
|
1175
|
+
...bodyLines,
|
|
1176
|
+
this.displayMode === 'overlay'
|
|
1177
|
+
? new BorderBottom(border, `v${VERSION}`, (text) => this.theme.fg('dim', text)).render(width)[0]
|
|
1178
|
+
: border('─'.repeat(Math.max(1, width))),
|
|
1179
|
+
];
|
|
1180
|
+
}
|
|
1181
|
+
boxLine(line, innerWidth) {
|
|
1182
|
+
const border = (text) => this.theme.fg('accent', text);
|
|
1183
|
+
return `${border(BOX_LEFT)}${truncateToWidth(line, innerWidth, '', true)}${border(BOX_RIGHT)}`;
|
|
1184
|
+
}
|
|
1185
|
+
}
|
|
1186
|
+
async function askQuestionsViaDialogs(ui, questions, timeout, signal) {
|
|
1187
|
+
const answers = [];
|
|
1188
|
+
const deadline = timeout === undefined ? undefined : Date.now() + timeout;
|
|
1189
|
+
for (const question of questions) {
|
|
1190
|
+
if (signal?.aborted)
|
|
1191
|
+
return { answers, cancelled: 'abort' };
|
|
1192
|
+
const remaining = deadline === undefined ? undefined : deadline - Date.now();
|
|
1193
|
+
if (remaining !== undefined && remaining <= 0)
|
|
1194
|
+
return { answers, cancelled: 'timeout' };
|
|
1195
|
+
const response = await raceDialogAbort(askViaDialogs(ui, question, remaining), signal);
|
|
1196
|
+
if (response.aborted)
|
|
1197
|
+
return { answers, cancelled: 'abort' };
|
|
1198
|
+
if (response.value === null && deadline !== undefined && Date.now() >= deadline) {
|
|
1199
|
+
return { answers, cancelled: 'timeout' };
|
|
1200
|
+
}
|
|
1201
|
+
answers.push({
|
|
1202
|
+
questionId: question.id,
|
|
1203
|
+
response: response.value,
|
|
1204
|
+
});
|
|
1205
|
+
}
|
|
1206
|
+
return { answers };
|
|
1207
|
+
}
|
|
1208
|
+
async function raceDialogAbort(operation, signal) {
|
|
1209
|
+
if (!signal)
|
|
1210
|
+
return { aborted: false, value: await operation };
|
|
1211
|
+
if (signal.aborted)
|
|
1212
|
+
return { aborted: true };
|
|
1213
|
+
// Pi dialogs have no abort option, so stop this host flow even if the RPC
|
|
1214
|
+
// client dismisses its outstanding prompt later.
|
|
1215
|
+
let removeListener = () => { };
|
|
1216
|
+
const aborted = new Promise((resolve) => {
|
|
1217
|
+
const onAbort = () => resolve({ aborted: true });
|
|
1218
|
+
signal.addEventListener('abort', onAbort, { once: true });
|
|
1219
|
+
removeListener = () => signal.removeEventListener('abort', onAbort);
|
|
1220
|
+
});
|
|
1221
|
+
try {
|
|
1222
|
+
return await Promise.race([
|
|
1223
|
+
operation.then((value) => ({ aborted: false, value })),
|
|
1224
|
+
aborted,
|
|
1225
|
+
]);
|
|
1226
|
+
}
|
|
1227
|
+
finally {
|
|
1228
|
+
removeListener();
|
|
1229
|
+
}
|
|
1230
|
+
}
|
|
1231
|
+
async function askViaDialogs(ui, question, timeout) {
|
|
1232
|
+
const dialogOptions = timeout === undefined ? undefined : { timeout };
|
|
1233
|
+
const prompt = question.context
|
|
1234
|
+
? `${question.question}\n\nContext:\n${question.context}`
|
|
1235
|
+
: question.question;
|
|
1236
|
+
if (question.options.length === 0) {
|
|
1237
|
+
const answer = await ui.input(prompt, 'Type your answer...', dialogOptions);
|
|
1238
|
+
return answer === undefined ? null : freeformResponse(answer);
|
|
1239
|
+
}
|
|
1240
|
+
if (question.allowMultiple) {
|
|
1241
|
+
const options = formatOptions(question.options);
|
|
1242
|
+
const raw = await ui.input(`${prompt}\n\nOptions (select one or more):\n${options}`, 'Type option titles separated by commas...', dialogOptions);
|
|
1243
|
+
if (raw === undefined)
|
|
1244
|
+
return null;
|
|
1245
|
+
const selections = raw.split(',').map((selection) => selection.trim()).filter(Boolean);
|
|
1246
|
+
if (selections.length === 0)
|
|
1247
|
+
return null;
|
|
1248
|
+
if (!question.allowComment)
|
|
1249
|
+
return selectionResponse(selections);
|
|
1250
|
+
const comment = await ui.input(`${prompt}\n\nSelected:\n${selections.map((selection) => `- ${selection}`).join('\n')}`, 'Optional comment (press Enter to skip)...', dialogOptions);
|
|
1251
|
+
return selectionResponse(selections, comment);
|
|
1252
|
+
}
|
|
1253
|
+
const options = question.options.map((option) => option.title);
|
|
1254
|
+
if (question.allowFreeform)
|
|
1255
|
+
options.push(FREEFORM_SENTINEL);
|
|
1256
|
+
const selected = await ui.select(prompt, options, dialogOptions);
|
|
1257
|
+
if (selected === undefined)
|
|
1258
|
+
return null;
|
|
1259
|
+
if (selected === FREEFORM_SENTINEL) {
|
|
1260
|
+
const answer = await ui.input(prompt, 'Type your answer...', dialogOptions);
|
|
1261
|
+
return answer === undefined ? null : freeformResponse(answer);
|
|
1262
|
+
}
|
|
1263
|
+
if (!question.allowComment)
|
|
1264
|
+
return selectionResponse([selected]);
|
|
1265
|
+
const comment = await ui.input(`${prompt}\n\nSelected option:\n- ${selected}`, 'Optional comment (press Enter to skip)...', dialogOptions);
|
|
1266
|
+
return selectionResponse([selected], comment);
|
|
1267
|
+
}
|
|
1268
|
+
function selectionResponse(selections, comment) {
|
|
1269
|
+
const normalizedSelections = selections.map((selection) => selection.trim()).filter(Boolean);
|
|
1270
|
+
if (normalizedSelections.length === 0)
|
|
1271
|
+
return null;
|
|
1272
|
+
const normalizedComment = comment?.trim();
|
|
1273
|
+
return {
|
|
1274
|
+
kind: 'selection',
|
|
1275
|
+
selections: normalizedSelections,
|
|
1276
|
+
...(normalizedComment ? { comment: normalizedComment } : {}),
|
|
1277
|
+
};
|
|
1278
|
+
}
|
|
1279
|
+
function freeformResponse(text) {
|
|
1280
|
+
const normalized = text.trim();
|
|
1281
|
+
return normalized ? { kind: 'freeform', text: normalized } : null;
|
|
1282
|
+
}
|
|
1283
|
+
function formatOptions(options) {
|
|
1284
|
+
return options.map((option, index) => (`${index + 1}. ${option.title}${option.description ? ` — ${option.description}` : ''}`)).join('\n');
|
|
1285
|
+
}
|
|
1286
|
+
function formatResponse(response) {
|
|
1287
|
+
if (response.kind === 'freeform')
|
|
1288
|
+
return response.text;
|
|
1289
|
+
const selections = response.selections.join(', ');
|
|
1290
|
+
return response.comment ? `${selections} — ${response.comment}` : selections;
|
|
1291
|
+
}
|
|
1292
|
+
export const askUserToolPresentation = {
|
|
1293
|
+
renderCall(args, theme) {
|
|
1294
|
+
const values = args;
|
|
1295
|
+
if (Array.isArray(values.questions) && values.questions.length > 0) {
|
|
1296
|
+
const labels = values.questions.map((question, index) => (question.header || question.question || `Q${index + 1}`));
|
|
1297
|
+
return new Text(`${theme.fg('toolTitle', theme.bold('ask_user '))}${theme.fg('muted', `${values.questions.length} questions`)}\n${theme.fg('dim', ` ${truncateToWidth(labels.join(', '), 80)}`)}`, 0, 0);
|
|
1298
|
+
}
|
|
1299
|
+
const options = Array.isArray(values.options) ? values.options : [];
|
|
1300
|
+
const labels = options.map((option) => normalizeAskUserOption(option)?.title ?? '<invalid>');
|
|
1301
|
+
const optionLine = labels.length > 0
|
|
1302
|
+
? `\n${theme.fg('dim', ` ${labels.length} option(s): ${labels.join(', ')}`)}`
|
|
1303
|
+
: '';
|
|
1304
|
+
const modes = `${values.allowMultiple ? ' [multi-select]' : ''}${values.allowComment ? ' [optional comment]' : ''}`;
|
|
1305
|
+
return new Text(`${theme.fg('toolTitle', theme.bold('ask_user '))}${theme.fg('muted', String(values.question ?? ''))}${optionLine}${theme.fg('dim', modes)}`, 0, 0);
|
|
1306
|
+
},
|
|
1307
|
+
renderResult(result, options, theme) {
|
|
1308
|
+
const details = result.details;
|
|
1309
|
+
if (details && 'error' in details)
|
|
1310
|
+
return new Text(theme.fg('error', `✗ ${details.error}`), 0, 0);
|
|
1311
|
+
if (options.isPartial) {
|
|
1312
|
+
const waiting = result.content
|
|
1313
|
+
.filter((part) => part.type === 'text')
|
|
1314
|
+
.map((part) => part.text)
|
|
1315
|
+
.join('\n') || 'Waiting for user input...';
|
|
1316
|
+
return new Text(theme.fg('muted', waiting), 0, 0);
|
|
1317
|
+
}
|
|
1318
|
+
if (!details)
|
|
1319
|
+
return new Text(theme.fg('warning', 'No result'), 0, 0);
|
|
1320
|
+
if (details.status === 'cancelled')
|
|
1321
|
+
return new Text(theme.fg('warning', details.message ?? 'Cancelled'), 0, 0);
|
|
1322
|
+
if (details.status === 'deferred') {
|
|
1323
|
+
const interaction = details.interactionId ? ` (interaction: ${details.interactionId})` : '';
|
|
1324
|
+
return new Text(theme.fg('muted', `${details.message ?? 'Question sent'}${interaction}`), 0, 0);
|
|
1325
|
+
}
|
|
1326
|
+
if (details.status === 'pending')
|
|
1327
|
+
return new Text(theme.fg('muted', 'Waiting for user input...'), 0, 0);
|
|
1328
|
+
if (details.kind === 'single') {
|
|
1329
|
+
if (!details.response)
|
|
1330
|
+
return new Text(theme.fg('warning', 'Skipped'), 0, 0);
|
|
1331
|
+
let text = `${theme.fg('success', '✓ ')}${theme.fg('accent', formatResponse(details.response))}`;
|
|
1332
|
+
if (options.expanded) {
|
|
1333
|
+
text += `\n${theme.fg('dim', `Q: ${details.question.question}`)}`;
|
|
1334
|
+
if (details.question.context)
|
|
1335
|
+
text += `\n${theme.fg('dim', details.question.context)}`;
|
|
1336
|
+
}
|
|
1337
|
+
return new Text(text, 0, 0);
|
|
1338
|
+
}
|
|
1339
|
+
const lines = details.questions.map((question) => {
|
|
1340
|
+
const response = details.responses[question.id];
|
|
1341
|
+
return response
|
|
1342
|
+
? `${theme.fg('success', '✓ ')}${theme.fg('accent', question.header)}: ${formatResponse(response)}`
|
|
1343
|
+
: `${theme.fg('muted', '○ ')}${theme.fg('muted', question.header)}: skipped`;
|
|
1344
|
+
});
|
|
1345
|
+
return new Text(lines.join('\n'), 0, 0);
|
|
1346
|
+
},
|
|
1347
|
+
};
|
|
1348
|
+
//# sourceMappingURL=ask-user.js.map
|