@travisennis/acai 0.0.4 → 0.0.6
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/README.md +229 -8
- package/dist/agent/index.d.ts +119 -0
- package/dist/agent/index.d.ts.map +1 -0
- package/dist/agent/index.js +406 -0
- package/dist/agent/manual-loop.d.ts +41 -0
- package/dist/agent/manual-loop.d.ts.map +1 -0
- package/dist/agent/manual-loop.js +278 -0
- package/dist/api/exa/index.d.ts +177 -0
- package/dist/api/exa/index.d.ts.map +1 -0
- package/dist/api/exa/index.js +439 -0
- package/dist/cli.d.ts +5 -2
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +27 -33
- package/dist/commands/add-directory-command.d.ts +3 -0
- package/dist/commands/add-directory-command.d.ts.map +1 -0
- package/dist/commands/add-directory-command.js +85 -0
- package/dist/commands/application-log-command.d.ts +1 -0
- package/dist/commands/application-log-command.d.ts.map +1 -0
- package/dist/commands/application-log-command.js +39 -3
- package/dist/commands/clear-command.d.ts +1 -0
- package/dist/commands/clear-command.d.ts.map +1 -0
- package/dist/commands/clear-command.js +10 -3
- package/dist/commands/compact-command.d.ts +1 -0
- package/dist/commands/compact-command.d.ts.map +1 -0
- package/dist/commands/compact-command.js +16 -3
- package/dist/commands/context-command.d.ts +3 -0
- package/dist/commands/context-command.d.ts.map +1 -0
- package/dist/commands/context-command.js +183 -0
- package/dist/commands/copy-command.d.ts +1 -0
- package/dist/commands/copy-command.d.ts.map +1 -0
- package/dist/commands/copy-command.js +31 -2
- package/dist/commands/edit-command.d.ts +1 -0
- package/dist/commands/edit-command.d.ts.map +1 -0
- package/dist/commands/edit-command.js +40 -5
- package/dist/commands/edit-prompt-command.d.ts +2 -1
- package/dist/commands/edit-prompt-command.d.ts.map +1 -0
- package/dist/commands/edit-prompt-command.js +43 -7
- package/dist/commands/exit-command.d.ts +13 -2
- package/dist/commands/exit-command.d.ts.map +1 -0
- package/dist/commands/exit-command.js +34 -2
- package/dist/commands/files-command.d.ts +1 -0
- package/dist/commands/files-command.d.ts.map +1 -0
- package/dist/commands/files-command.js +66 -8
- package/dist/commands/generate-rules-command.d.ts +1 -0
- package/dist/commands/generate-rules-command.d.ts.map +1 -0
- package/dist/commands/generate-rules-command.js +315 -4
- package/dist/commands/handoff-command.d.ts +3 -0
- package/dist/commands/handoff-command.d.ts.map +1 -0
- package/dist/commands/handoff-command.js +202 -0
- package/dist/commands/health-command.d.ts +3 -1
- package/dist/commands/health-command.d.ts.map +1 -0
- package/dist/commands/health-command.js +160 -6
- package/dist/commands/help-command.d.ts +1 -0
- package/dist/commands/help-command.d.ts.map +1 -0
- package/dist/commands/help-command.js +30 -3
- package/dist/commands/history-command.d.ts +3 -0
- package/dist/commands/history-command.d.ts.map +1 -0
- package/dist/commands/history-command.js +534 -0
- package/dist/commands/init-command.d.ts +2 -1
- package/dist/commands/init-command.d.ts.map +1 -0
- package/dist/commands/init-command.js +56 -20
- package/dist/commands/last-log-command.d.ts +1 -0
- package/dist/commands/last-log-command.d.ts.map +1 -0
- package/dist/commands/last-log-command.js +39 -17
- package/dist/commands/list-directories-command.d.ts +3 -0
- package/dist/commands/list-directories-command.d.ts.map +1 -0
- package/dist/commands/list-directories-command.js +48 -0
- package/dist/commands/list-tools-command.d.ts +3 -0
- package/dist/commands/list-tools-command.d.ts.map +1 -0
- package/dist/commands/list-tools-command.js +124 -0
- package/dist/commands/manager.d.ts +20 -3
- package/dist/commands/manager.d.ts.map +1 -0
- package/dist/commands/manager.js +123 -26
- package/dist/commands/model-command.d.ts +23 -0
- package/dist/commands/model-command.d.ts.map +1 -0
- package/dist/commands/model-command.js +261 -5
- package/dist/commands/paste-command.d.ts +1 -0
- package/dist/commands/paste-command.d.ts.map +1 -0
- package/dist/commands/paste-command.js +98 -5
- package/dist/commands/pickup-command.d.ts +3 -0
- package/dist/commands/pickup-command.d.ts.map +1 -0
- package/dist/commands/pickup-command.js +161 -0
- package/dist/commands/prompt-command.d.ts +2 -1
- package/dist/commands/prompt-command.d.ts.map +1 -0
- package/dist/commands/prompt-command.js +178 -9
- package/dist/commands/remove-directory-command.d.ts +3 -0
- package/dist/commands/remove-directory-command.d.ts.map +1 -0
- package/dist/commands/remove-directory-command.js +87 -0
- package/dist/commands/reset-command.d.ts +2 -1
- package/dist/commands/reset-command.d.ts.map +1 -0
- package/dist/commands/reset-command.js +14 -3
- package/dist/commands/rules-command.d.ts +1 -0
- package/dist/commands/rules-command.d.ts.map +1 -0
- package/dist/commands/rules-command.js +70 -3
- package/dist/commands/save-command.d.ts +1 -0
- package/dist/commands/save-command.d.ts.map +1 -0
- package/dist/commands/save-command.js +13 -1
- package/dist/commands/shell-command.d.ts +3 -0
- package/dist/commands/shell-command.d.ts.map +1 -0
- package/dist/commands/shell-command.js +128 -0
- package/dist/commands/types.d.ts +16 -8
- package/dist/commands/types.d.ts.map +1 -0
- package/dist/commands/usage-command.d.ts +1 -0
- package/dist/commands/usage-command.d.ts.map +1 -0
- package/dist/commands/usage-command.js +24 -3
- package/dist/config.d.ts +21 -34
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +55 -15
- package/dist/dedent.d.ts +1 -0
- package/dist/dedent.d.ts.map +1 -0
- package/dist/execution/index.d.ts +112 -0
- package/dist/execution/index.d.ts.map +1 -0
- package/dist/execution/index.js +432 -0
- package/dist/formatting.d.ts +107 -10
- package/dist/formatting.d.ts.map +1 -0
- package/dist/formatting.js +150 -62
- package/dist/index.d.ts +8 -2
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +150 -38
- package/dist/logger.d.ts +1 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +47 -18
- package/dist/mentions.d.ts +6 -1
- package/dist/mentions.d.ts.map +1 -0
- package/dist/mentions.js +58 -11
- package/dist/messages.d.ts +16 -20
- package/dist/messages.d.ts.map +1 -0
- package/dist/messages.js +89 -72
- package/dist/middleware/audit-message.d.ts +1 -0
- package/dist/middleware/audit-message.d.ts.map +1 -0
- package/dist/middleware/cache.d.ts +3 -0
- package/dist/middleware/cache.d.ts.map +1 -0
- package/dist/middleware/cache.js +53 -0
- package/dist/middleware/index.d.ts +2 -0
- package/dist/middleware/index.d.ts.map +1 -0
- package/dist/middleware/index.js +1 -0
- package/dist/middleware/rate-limit.d.ts +1 -0
- package/dist/middleware/rate-limit.d.ts.map +1 -0
- package/dist/models/ai-config.d.ts +5 -2
- package/dist/models/ai-config.d.ts.map +1 -0
- package/dist/models/ai-config.js +12 -2
- package/dist/models/anthropic-provider.d.ts +1 -0
- package/dist/models/anthropic-provider.d.ts.map +1 -0
- package/dist/models/anthropic-provider.js +3 -60
- package/dist/models/deepseek-provider.d.ts +1 -0
- package/dist/models/deepseek-provider.d.ts.map +1 -0
- package/dist/models/google-provider.d.ts +1 -0
- package/dist/models/google-provider.d.ts.map +1 -0
- package/dist/models/groq-provider.d.ts +20 -0
- package/dist/models/groq-provider.d.ts.map +1 -0
- package/dist/models/groq-provider.js +31 -0
- package/dist/models/manager.d.ts +3 -1
- package/dist/models/manager.d.ts.map +1 -0
- package/dist/models/manager.js +26 -2
- package/dist/models/openai-provider.d.ts +2 -1
- package/dist/models/openai-provider.d.ts.map +1 -0
- package/dist/models/openrouter-provider.d.ts +25 -23
- package/dist/models/openrouter-provider.d.ts.map +1 -0
- package/dist/models/openrouter-provider.js +181 -122
- package/dist/models/providers.d.ts +4 -5
- package/dist/models/providers.d.ts.map +1 -0
- package/dist/models/providers.js +7 -3
- package/dist/models/xai-provider.d.ts +1 -0
- package/dist/models/xai-provider.d.ts.map +1 -0
- package/dist/parsing.d.ts +2 -1
- package/dist/parsing.d.ts.map +1 -0
- package/dist/prompts/manager.d.ts +14 -2
- package/dist/prompts/manager.d.ts.map +1 -0
- package/dist/prompts.d.ts +2 -0
- package/dist/prompts.d.ts.map +1 -0
- package/dist/prompts.js +65 -12
- package/dist/repl/display-tool-messages.d.ts +4 -0
- package/dist/repl/display-tool-messages.d.ts.map +1 -0
- package/dist/repl/display-tool-messages.js +58 -0
- package/dist/repl/display-tool-use.d.ts +14 -0
- package/dist/repl/display-tool-use.d.ts.map +1 -0
- package/dist/repl/display-tool-use.js +63 -0
- package/dist/repl/get-prompt-header.d.ts +8 -0
- package/dist/repl/get-prompt-header.d.ts.map +1 -0
- package/dist/repl/get-prompt-header.js +9 -0
- package/dist/repl/project-status-line.d.ts +2 -0
- package/dist/repl/project-status-line.d.ts.map +1 -0
- package/dist/repl/project-status-line.js +31 -0
- package/dist/repl/prompt.d.ts +21 -0
- package/dist/repl/prompt.d.ts.map +1 -0
- package/dist/{repl-prompt.js → repl/prompt.js} +119 -22
- package/dist/repl/tool-call-repair.d.ts +4 -0
- package/dist/repl/tool-call-repair.d.ts.map +1 -0
- package/dist/repl/tool-call-repair.js +54 -0
- package/dist/repl-new.d.ts +53 -0
- package/dist/repl-new.d.ts.map +1 -0
- package/dist/repl-new.js +374 -0
- package/dist/repl.d.ts +9 -7
- package/dist/repl.d.ts.map +1 -0
- package/dist/repl.js +142 -378
- package/dist/terminal/ansi-styles.d.ts +77 -0
- package/dist/terminal/ansi-styles.d.ts.map +1 -0
- package/dist/terminal/ansi-styles.js +215 -0
- package/dist/terminal/checkbox-prompt.d.ts +36 -0
- package/dist/terminal/checkbox-prompt.d.ts.map +1 -0
- package/dist/terminal/checkbox-prompt.js +368 -0
- package/dist/terminal/default-theme.d.ts +6 -0
- package/dist/terminal/default-theme.d.ts.map +1 -0
- package/dist/terminal/default-theme.js +182 -0
- package/dist/terminal/east-asian-width.d.ts +8 -0
- package/dist/terminal/east-asian-width.d.ts.map +1 -0
- package/dist/terminal/east-asian-width.js +409 -0
- package/dist/terminal/editor-prompt.d.ts +10 -0
- package/dist/terminal/editor-prompt.d.ts.map +1 -0
- package/dist/terminal/editor-prompt.js +61 -0
- package/dist/terminal/errors.d.ts +19 -0
- package/dist/terminal/errors.d.ts.map +1 -0
- package/dist/terminal/errors.js +37 -0
- package/dist/terminal/formatting.d.ts +1 -11
- package/dist/terminal/formatting.d.ts.map +1 -0
- package/dist/terminal/formatting.js +4 -20
- package/dist/terminal/highlight/index.d.ts +53 -0
- package/dist/terminal/highlight/index.d.ts.map +1 -0
- package/dist/terminal/highlight/index.js +90 -0
- package/dist/terminal/highlight/theme.d.ts +233 -0
- package/dist/terminal/highlight/theme.d.ts.map +1 -0
- package/dist/terminal/highlight/theme.js +83 -0
- package/dist/terminal/index.d.ts +23 -9
- package/dist/terminal/index.d.ts.map +1 -0
- package/dist/terminal/index.js +136 -126
- package/dist/terminal/input-prompt.d.ts +17 -0
- package/dist/terminal/input-prompt.d.ts.map +1 -0
- package/dist/terminal/input-prompt.js +181 -0
- package/dist/terminal/markdown-utils.d.ts +1 -0
- package/dist/terminal/markdown-utils.d.ts.map +1 -0
- package/dist/terminal/markdown.d.ts +1 -0
- package/dist/terminal/markdown.d.ts.map +1 -0
- package/dist/terminal/markdown.js +20 -12
- package/dist/terminal/search-prompt.d.ts +20 -0
- package/dist/terminal/search-prompt.d.ts.map +1 -0
- package/dist/terminal/search-prompt.js +280 -0
- package/dist/terminal/select-prompt.d.ts +26 -0
- package/dist/terminal/select-prompt.d.ts.map +1 -0
- package/dist/terminal/select-prompt.js +306 -0
- package/dist/terminal/string-width.d.ts +7 -0
- package/dist/terminal/string-width.d.ts.map +1 -0
- package/dist/terminal/string-width.js +61 -0
- package/dist/terminal/strip-ansi.d.ts +2 -0
- package/dist/terminal/strip-ansi.d.ts.map +1 -0
- package/dist/terminal/strip-ansi.js +20 -0
- package/dist/terminal/style.d.ts +191 -0
- package/dist/terminal/style.d.ts.map +1 -0
- package/dist/terminal/style.js +259 -0
- package/dist/terminal/supports-color.d.ts +1 -0
- package/dist/terminal/supports-color.d.ts.map +1 -0
- package/dist/terminal/supports-hyperlinks.d.ts +1 -3
- package/dist/terminal/supports-hyperlinks.d.ts.map +1 -0
- package/dist/terminal/supports-hyperlinks.js +1 -1
- package/dist/terminal/types.d.ts +1 -37
- package/dist/terminal/types.d.ts.map +1 -0
- package/dist/terminal/wrap-ansi.d.ts +8 -0
- package/dist/terminal/wrap-ansi.d.ts.map +1 -0
- package/dist/terminal/wrap-ansi.js +190 -0
- package/dist/{token-utils.d.ts → tokens/counter.d.ts} +1 -0
- package/dist/tokens/counter.d.ts.map +1 -0
- package/dist/{token-utils.js → tokens/counter.js} +1 -1
- package/dist/tokens/threshold.d.ts +35 -0
- package/dist/tokens/threshold.d.ts.map +1 -0
- package/dist/tokens/threshold.js +85 -0
- package/dist/{token-tracker.d.ts → tokens/tracker.d.ts} +1 -0
- package/dist/tokens/tracker.d.ts.map +1 -0
- package/dist/tools/advanced-edit-file.d.ts +69 -0
- package/dist/tools/advanced-edit-file.d.ts.map +1 -0
- package/dist/tools/advanced-edit-file.js +281 -0
- package/dist/tools/agent.d.ts +19 -7
- package/dist/tools/agent.d.ts.map +1 -0
- package/dist/tools/agent.js +70 -54
- package/dist/tools/bash-utils.d.ts +7 -0
- package/dist/tools/bash-utils.d.ts.map +1 -0
- package/dist/tools/bash-utils.js +220 -0
- package/dist/tools/bash.d.ts +25 -14
- package/dist/tools/bash.d.ts.map +1 -0
- package/dist/tools/bash.js +87 -251
- package/dist/tools/code-interpreter.d.ts +22 -10
- package/dist/tools/code-interpreter.d.ts.map +1 -0
- package/dist/tools/code-interpreter.js +146 -210
- package/dist/tools/delete-file.d.ts +18 -9
- package/dist/tools/delete-file.d.ts.map +1 -0
- package/dist/tools/delete-file.js +55 -85
- package/dist/tools/directory-tree.d.ts +26 -6
- package/dist/tools/directory-tree.d.ts.map +1 -0
- package/dist/tools/directory-tree.js +109 -28
- package/dist/tools/dynamic-tool-loader.d.ts +22 -0
- package/dist/tools/dynamic-tool-loader.d.ts.map +1 -0
- package/dist/tools/dynamic-tool-loader.js +272 -0
- package/dist/tools/dynamic-tool-parser.d.ts +21 -0
- package/dist/tools/dynamic-tool-parser.d.ts.map +1 -0
- package/dist/tools/dynamic-tool-parser.js +22 -0
- package/dist/tools/edit-file.d.ts +41 -13
- package/dist/tools/edit-file.d.ts.map +1 -0
- package/dist/tools/edit-file.js +173 -96
- package/dist/tools/filesystem-utils.d.ts +7 -21
- package/dist/tools/filesystem-utils.d.ts.map +1 -0
- package/dist/tools/filesystem-utils.js +111 -149
- package/dist/tools/git-utils.d.ts +1 -0
- package/dist/tools/git-utils.d.ts.map +1 -0
- package/dist/tools/glob.d.ts +36 -0
- package/dist/tools/glob.d.ts.map +1 -0
- package/dist/tools/glob.js +143 -0
- package/dist/tools/grep.d.ts +76 -13
- package/dist/tools/grep.d.ts.map +1 -0
- package/dist/tools/grep.js +420 -135
- package/dist/tools/index.d.ts +207 -133
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +245 -127
- package/dist/tools/llm-edit-fixer.d.ts +25 -0
- package/dist/tools/llm-edit-fixer.d.ts.map +1 -0
- package/dist/tools/llm-edit-fixer.js +150 -0
- package/dist/tools/move-file.d.ts +20 -7
- package/dist/tools/move-file.d.ts.map +1 -0
- package/dist/tools/move-file.js +43 -29
- package/dist/tools/read-file.d.ts +49 -10
- package/dist/tools/read-file.d.ts.map +1 -0
- package/dist/tools/read-file.js +79 -67
- package/dist/tools/read-multiple-files.d.ts +19 -7
- package/dist/tools/read-multiple-files.d.ts.map +1 -0
- package/dist/tools/read-multiple-files.js +117 -33
- package/dist/tools/save-file.d.ts +46 -11
- package/dist/tools/save-file.d.ts.map +1 -0
- package/dist/tools/save-file.js +63 -78
- package/dist/tools/think.d.ts +16 -7
- package/dist/tools/think.d.ts.map +1 -0
- package/dist/tools/think.js +34 -22
- package/dist/tools/types.d.ts +18 -11
- package/dist/tools/types.d.ts.map +1 -0
- package/dist/tools/types.js +9 -0
- package/dist/tools/utils.d.ts +14 -0
- package/dist/tools/utils.d.ts.map +1 -0
- package/dist/tools/utils.js +16 -0
- package/dist/tools/web-fetch.d.ts +15 -6
- package/dist/tools/web-fetch.d.ts.map +1 -0
- package/dist/tools/web-fetch.js +40 -39
- package/dist/tools/web-search.d.ts +17 -7
- package/dist/tools/web-search.d.ts.map +1 -0
- package/dist/tools/web-search.js +86 -33
- package/dist/tui/autocomplete.d.ts +44 -0
- package/dist/tui/autocomplete.d.ts.map +1 -0
- package/dist/tui/autocomplete.js +466 -0
- package/dist/tui/components/assistant-message.d.ts +18 -0
- package/dist/tui/components/assistant-message.d.ts.map +1 -0
- package/dist/tui/components/assistant-message.js +29 -0
- package/dist/tui/components/editor.d.ts +51 -0
- package/dist/tui/components/editor.d.ts.map +1 -0
- package/dist/tui/components/editor.js +758 -0
- package/dist/tui/components/footer.d.ts +24 -0
- package/dist/tui/components/footer.d.ts.map +1 -0
- package/dist/tui/components/footer.js +197 -0
- package/dist/tui/components/input.d.ts +14 -0
- package/dist/tui/components/input.d.ts.map +1 -0
- package/dist/tui/components/input.js +122 -0
- package/dist/tui/components/loader.d.ts +19 -0
- package/dist/tui/components/loader.d.ts.map +1 -0
- package/dist/tui/components/loader.js +45 -0
- package/dist/tui/components/markdown.d.ts +103 -0
- package/dist/tui/components/markdown.d.ts.map +1 -0
- package/dist/tui/components/markdown.js +533 -0
- package/dist/tui/components/modal.d.ts +40 -0
- package/dist/tui/components/modal.d.ts.map +1 -0
- package/dist/tui/components/modal.js +292 -0
- package/dist/tui/components/prompt-status.d.ts +16 -0
- package/dist/tui/components/prompt-status.d.ts.map +1 -0
- package/dist/tui/components/prompt-status.js +21 -0
- package/dist/tui/components/select-list.d.ts +22 -0
- package/dist/tui/components/select-list.d.ts.map +1 -0
- package/dist/tui/components/select-list.js +143 -0
- package/dist/tui/components/spacer.d.ts +16 -0
- package/dist/tui/components/spacer.d.ts.map +1 -0
- package/dist/tui/components/spacer.js +27 -0
- package/dist/tui/components/text.d.ts +26 -0
- package/dist/tui/components/text.d.ts.map +1 -0
- package/dist/tui/components/text.js +143 -0
- package/dist/tui/components/thinking-block.d.ts +14 -0
- package/dist/tui/components/thinking-block.d.ts.map +1 -0
- package/dist/tui/components/thinking-block.js +30 -0
- package/dist/tui/components/tool-execution.d.ts +17 -0
- package/dist/tui/components/tool-execution.d.ts.map +1 -0
- package/dist/tui/components/tool-execution.js +153 -0
- package/dist/tui/components/user-message.d.ts +9 -0
- package/dist/tui/components/user-message.d.ts.map +1 -0
- package/dist/tui/components/user-message.js +21 -0
- package/dist/tui/components/welcome.d.ts +6 -0
- package/dist/tui/components/welcome.d.ts.map +1 -0
- package/dist/tui/components/welcome.js +30 -0
- package/dist/tui/index.d.ts +14 -0
- package/dist/tui/index.d.ts.map +1 -0
- package/dist/tui/index.js +18 -0
- package/dist/tui/terminal.d.ts +37 -0
- package/dist/tui/terminal.d.ts.map +1 -0
- package/dist/tui/terminal.js +104 -0
- package/dist/tui/tui.d.ts +67 -0
- package/dist/tui/tui.d.ts.map +1 -0
- package/dist/tui/tui.js +184 -0
- package/dist/tui/utils.d.ts +19 -0
- package/dist/tui/utils.d.ts.map +1 -0
- package/dist/tui/utils.js +31 -0
- package/dist/utils/filesystem.d.ts +23 -0
- package/dist/utils/filesystem.d.ts.map +1 -0
- package/dist/utils/filesystem.js +140 -0
- package/dist/utils/filetype-detection.d.ts +3 -0
- package/dist/utils/filetype-detection.d.ts.map +1 -0
- package/dist/utils/filetype-detection.js +112 -0
- package/dist/utils/generators.d.ts +3 -0
- package/dist/utils/generators.d.ts.map +1 -0
- package/dist/utils/generators.js +25 -0
- package/dist/utils/glob.d.ts +52 -0
- package/dist/utils/glob.d.ts.map +1 -0
- package/dist/utils/glob.js +376 -0
- package/dist/utils/ignore.d.ts +104 -0
- package/dist/utils/ignore.d.ts.map +1 -0
- package/dist/utils/ignore.js +649 -0
- package/dist/utils/iterables.d.ts +2 -0
- package/dist/utils/iterables.d.ts.map +1 -0
- package/dist/utils/iterables.js +6 -0
- package/dist/utils/process.d.ts +3 -2
- package/dist/utils/process.d.ts.map +1 -0
- package/dist/utils/process.js +17 -2
- package/dist/utils/zod-utils.d.ts +4 -0
- package/dist/utils/zod-utils.d.ts.map +1 -0
- package/dist/utils/zod-utils.js +7 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.d.ts.map +1 -0
- package/package.json +34 -32
- package/dist/conversation-analyzer.d.ts +0 -10
- package/dist/conversation-analyzer.js +0 -88
- package/dist/repl-prompt.d.ts +0 -14
- package/dist/tools/command-validation.d.ts +0 -11
- package/dist/tools/command-validation.js +0 -45
- /package/dist/{token-tracker.js → tokens/tracker.js} +0 -0
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
// Converted from ansi-styles/index.js to modern TypeScript
|
|
2
|
+
// Original source: chalk-main/source/vendor/ansi-styles/index.js
|
|
3
|
+
import { objectEntries } from "@travisennis/stdlib/object";
|
|
4
|
+
const ANSI_BACKGROUND_OFFSET = 10;
|
|
5
|
+
const wrapAnsi16 = (offset = 0) => (code) => `\u001B[${code + offset}m`;
|
|
6
|
+
const wrapAnsi256 = (offset = 0) => (code) => `\u001B[${38 + offset};5;${code}m`;
|
|
7
|
+
const wrapAnsi16m = (offset = 0) => (red, green, blue) => `\u001B[${38 + offset};2;${red};${green};${blue}m`;
|
|
8
|
+
const styles = {
|
|
9
|
+
modifier: {
|
|
10
|
+
reset: [0, 0],
|
|
11
|
+
// 21 isn't widely supported and 22 does the same thing
|
|
12
|
+
bold: [1, 22],
|
|
13
|
+
dim: [2, 22],
|
|
14
|
+
italic: [3, 23],
|
|
15
|
+
underline: [4, 24],
|
|
16
|
+
overline: [53, 55],
|
|
17
|
+
inverse: [7, 27],
|
|
18
|
+
hidden: [8, 28],
|
|
19
|
+
strikethrough: [9, 29],
|
|
20
|
+
},
|
|
21
|
+
color: {
|
|
22
|
+
black: [30, 39],
|
|
23
|
+
red: [31, 39],
|
|
24
|
+
green: [32, 39],
|
|
25
|
+
yellow: [33, 39],
|
|
26
|
+
blue: [34, 39],
|
|
27
|
+
magenta: [35, 39],
|
|
28
|
+
cyan: [36, 39],
|
|
29
|
+
white: [37, 39],
|
|
30
|
+
// Bright color
|
|
31
|
+
blackBright: [90, 39],
|
|
32
|
+
gray: [90, 39], // Alias of `blackBright`
|
|
33
|
+
grey: [90, 39], // Alias of `blackBright`
|
|
34
|
+
redBright: [91, 39],
|
|
35
|
+
greenBright: [92, 39],
|
|
36
|
+
yellowBright: [93, 39],
|
|
37
|
+
blueBright: [94, 39],
|
|
38
|
+
magentaBright: [95, 39],
|
|
39
|
+
cyanBright: [96, 39],
|
|
40
|
+
whiteBright: [97, 39],
|
|
41
|
+
},
|
|
42
|
+
bgColor: {
|
|
43
|
+
bgBlack: [40, 49],
|
|
44
|
+
bgRed: [41, 49],
|
|
45
|
+
bgGreen: [42, 49],
|
|
46
|
+
bgYellow: [43, 49],
|
|
47
|
+
bgBlue: [44, 49],
|
|
48
|
+
bgMagenta: [45, 49],
|
|
49
|
+
bgCyan: [46, 49],
|
|
50
|
+
bgWhite: [47, 49],
|
|
51
|
+
// Bright color
|
|
52
|
+
bgBlackBright: [100, 49],
|
|
53
|
+
bgGray: [100, 49], // Alias of `bgBlackBright`
|
|
54
|
+
bgGrey: [100, 49], // Alias of `bgBlackBright`
|
|
55
|
+
bgRedBright: [101, 49],
|
|
56
|
+
bgGreenBright: [102, 49],
|
|
57
|
+
bgYellowBright: [103, 49],
|
|
58
|
+
bgBlueBright: [104, 49],
|
|
59
|
+
bgMagentaBright: [105, 49],
|
|
60
|
+
bgCyanBright: [106, 49],
|
|
61
|
+
bgWhiteBright: [107, 49],
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Assembles the styles object with open/close ANSI sequences.
|
|
66
|
+
* @returns The fully assembled styles object.
|
|
67
|
+
*/
|
|
68
|
+
function assembleStyles() {
|
|
69
|
+
const codes = new Map();
|
|
70
|
+
for (const [groupName, group] of objectEntries(styles)) {
|
|
71
|
+
for (const [styleName, styleCodes] of objectEntries(group)) {
|
|
72
|
+
const style = {
|
|
73
|
+
open: `\u001B[${styleCodes[0]}m`,
|
|
74
|
+
close: `\u001B[${styleCodes[1]}m`,
|
|
75
|
+
};
|
|
76
|
+
// biome-ignore lint/suspicious/noExplicitAny: Dynamic property assignment needed for chalk compatibility
|
|
77
|
+
styles[styleName] = style;
|
|
78
|
+
// biome-ignore lint/suspicious/noExplicitAny: Dynamic property assignment needed for chalk compatibility
|
|
79
|
+
group[styleName] = style;
|
|
80
|
+
codes.set(styleCodes[0], styleCodes[1]);
|
|
81
|
+
}
|
|
82
|
+
Object.defineProperty(styles, groupName, {
|
|
83
|
+
value: group,
|
|
84
|
+
enumerable: false,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
Object.defineProperty(styles, "codes", {
|
|
88
|
+
value: codes,
|
|
89
|
+
enumerable: false,
|
|
90
|
+
});
|
|
91
|
+
// biome-ignore lint/suspicious/noExplicitAny: Dynamic property assignment needed for chalk compatibility
|
|
92
|
+
styles.color.close = "\u001B[39m";
|
|
93
|
+
// biome-ignore lint/suspicious/noExplicitAny: Dynamic property assignment needed for chalk compatibility
|
|
94
|
+
styles.bgColor.close = "\u001B[49m";
|
|
95
|
+
// biome-ignore lint/suspicious/noExplicitAny: Dynamic property assignment needed for chalk compatibility
|
|
96
|
+
styles.color.ansi = wrapAnsi16();
|
|
97
|
+
// biome-ignore lint/suspicious/noExplicitAny: Dynamic property assignment needed for chalk compatibility
|
|
98
|
+
styles.color.ansi256 = wrapAnsi256();
|
|
99
|
+
// biome-ignore lint/suspicious/noExplicitAny: Dynamic property assignment needed for chalk compatibility
|
|
100
|
+
styles.color.ansi16m = wrapAnsi16m();
|
|
101
|
+
// biome-ignore lint/suspicious/noExplicitAny: Dynamic property assignment needed for chalk compatibility
|
|
102
|
+
styles.bgColor.ansi = wrapAnsi16(ANSI_BACKGROUND_OFFSET);
|
|
103
|
+
// biome-ignore lint/suspicious/noExplicitAny: Dynamic property assignment needed for chalk compatibility
|
|
104
|
+
styles.bgColor.ansi256 = wrapAnsi256(ANSI_BACKGROUND_OFFSET);
|
|
105
|
+
// biome-ignore lint/suspicious/noExplicitAny: Dynamic property assignment needed for chalk compatibility
|
|
106
|
+
styles.bgColor.ansi16m = wrapAnsi16m(ANSI_BACKGROUND_OFFSET);
|
|
107
|
+
// Color conversion functions (from original source)
|
|
108
|
+
Object.defineProperties(styles, {
|
|
109
|
+
rgbToAnsi256: {
|
|
110
|
+
value(red, green, blue) {
|
|
111
|
+
// We use the extended greyscale palette here, with the exception of
|
|
112
|
+
// black and white. normal palette only has 4 greyscale shades.
|
|
113
|
+
if (red === green && green === blue) {
|
|
114
|
+
if (red < 8) {
|
|
115
|
+
return 16;
|
|
116
|
+
}
|
|
117
|
+
if (red > 248) {
|
|
118
|
+
return 231;
|
|
119
|
+
}
|
|
120
|
+
return Math.round(((red - 8) / 247) * 24) + 232;
|
|
121
|
+
}
|
|
122
|
+
return (16 +
|
|
123
|
+
36 * Math.round((red / 255) * 5) +
|
|
124
|
+
6 * Math.round((green / 255) * 5) +
|
|
125
|
+
Math.round((blue / 255) * 5));
|
|
126
|
+
},
|
|
127
|
+
enumerable: false,
|
|
128
|
+
},
|
|
129
|
+
hexToRgb: {
|
|
130
|
+
value(hex) {
|
|
131
|
+
const matches = /[a-f\d]{6}|[a-f\d]{3}/i.exec(hex);
|
|
132
|
+
if (!matches) {
|
|
133
|
+
return [0, 0, 0];
|
|
134
|
+
}
|
|
135
|
+
let [colorString] = matches;
|
|
136
|
+
if (colorString.length === 3) {
|
|
137
|
+
colorString = [...colorString]
|
|
138
|
+
.map((character) => character + character)
|
|
139
|
+
.join("");
|
|
140
|
+
}
|
|
141
|
+
const integer = Number.parseInt(colorString, 16);
|
|
142
|
+
return [
|
|
143
|
+
/* eslint-disable no-bitwise */
|
|
144
|
+
(integer >> 16) & 0xff,
|
|
145
|
+
(integer >> 8) & 0xff,
|
|
146
|
+
integer & 0xff,
|
|
147
|
+
/* eslint-enable no-bitwise */
|
|
148
|
+
];
|
|
149
|
+
},
|
|
150
|
+
enumerable: false,
|
|
151
|
+
},
|
|
152
|
+
hexToAnsi256: {
|
|
153
|
+
value: (hex) =>
|
|
154
|
+
// biome-ignore lint/suspicious/noExplicitAny: Dynamic method access needed for chalk compatibility
|
|
155
|
+
styles.rgbToAnsi256(...styles.hexToRgb(hex)),
|
|
156
|
+
enumerable: false,
|
|
157
|
+
},
|
|
158
|
+
ansi256ToAnsi: {
|
|
159
|
+
value(codeParam) {
|
|
160
|
+
const code = codeParam;
|
|
161
|
+
if (code < 8) {
|
|
162
|
+
return 30 + code;
|
|
163
|
+
}
|
|
164
|
+
if (code < 16) {
|
|
165
|
+
return 90 + (code - 8);
|
|
166
|
+
}
|
|
167
|
+
let red;
|
|
168
|
+
let green;
|
|
169
|
+
let blue;
|
|
170
|
+
if (code >= 232) {
|
|
171
|
+
red = ((code - 232) * 10 + 8) / 255;
|
|
172
|
+
green = red;
|
|
173
|
+
blue = red;
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
const adjustedCode = code - 16;
|
|
177
|
+
const remainder = adjustedCode % 36;
|
|
178
|
+
red = Math.floor(adjustedCode / 36) / 5;
|
|
179
|
+
green = Math.floor(remainder / 6) / 5;
|
|
180
|
+
blue = (remainder % 6) / 5;
|
|
181
|
+
}
|
|
182
|
+
const value = Math.max(red, green, blue) * 2;
|
|
183
|
+
if (value === 0) {
|
|
184
|
+
return 30;
|
|
185
|
+
}
|
|
186
|
+
// eslint-disable-next-line no-bitwise
|
|
187
|
+
let result = 30 +
|
|
188
|
+
((Math.round(blue) << 2) |
|
|
189
|
+
(Math.round(green) << 1) |
|
|
190
|
+
Math.round(red));
|
|
191
|
+
if (value === 2) {
|
|
192
|
+
result += 60;
|
|
193
|
+
}
|
|
194
|
+
return result;
|
|
195
|
+
},
|
|
196
|
+
enumerable: false,
|
|
197
|
+
},
|
|
198
|
+
rgbToAnsi: {
|
|
199
|
+
value: (red, green, blue) =>
|
|
200
|
+
// biome-ignore lint/suspicious/noExplicitAny: Dynamic method access needed for chalk compatibility
|
|
201
|
+
styles.ansi256ToAnsi(
|
|
202
|
+
// biome-ignore lint/suspicious/noExplicitAny: Dynamic method access needed for chalk compatibility
|
|
203
|
+
styles.rgbToAnsi256(red, green, blue)),
|
|
204
|
+
enumerable: false,
|
|
205
|
+
},
|
|
206
|
+
hexToAnsi: {
|
|
207
|
+
value: (hex) =>
|
|
208
|
+
// biome-ignore lint/suspicious/noExplicitAny: Dynamic method access needed for chalk compatibility
|
|
209
|
+
styles.ansi256ToAnsi(styles.hexToAnsi256(hex)),
|
|
210
|
+
enumerable: false,
|
|
211
|
+
},
|
|
212
|
+
});
|
|
213
|
+
return styles;
|
|
214
|
+
}
|
|
215
|
+
export const ansiStyles = assembleStyles();
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Standalone checkbox prompt (inquirer-like)
|
|
4
|
+
* - TypeScript version
|
|
5
|
+
*/
|
|
6
|
+
interface TerminalIo {
|
|
7
|
+
stdin: NodeJS.ReadStream;
|
|
8
|
+
stdout: NodeJS.WriteStream;
|
|
9
|
+
}
|
|
10
|
+
interface ChoiceObject<T = unknown> {
|
|
11
|
+
name: string;
|
|
12
|
+
value: T;
|
|
13
|
+
disabled?: boolean;
|
|
14
|
+
checked?: boolean;
|
|
15
|
+
}
|
|
16
|
+
export type Choice<T = unknown> = string | ChoiceObject<T>;
|
|
17
|
+
export interface CheckboxOptions<T = unknown> {
|
|
18
|
+
message?: string;
|
|
19
|
+
choices: Choice<T>[];
|
|
20
|
+
initial?: number;
|
|
21
|
+
pageSize?: number;
|
|
22
|
+
loop?: boolean;
|
|
23
|
+
required?: boolean;
|
|
24
|
+
signal?: AbortSignal;
|
|
25
|
+
terminal?: TerminalIo;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Interactive checkbox prompt for selecting multiple options
|
|
29
|
+
* @param options Configuration options for the checkbox prompt
|
|
30
|
+
* @returns Promise resolving to array of selected values
|
|
31
|
+
* @throws {PromptCancelError} When user cancels with Ctrl+C
|
|
32
|
+
* @throws {PromptAbortError} When signal is aborted
|
|
33
|
+
*/
|
|
34
|
+
export declare function checkbox<T = unknown>({ message, choices, initial, pageSize, required, signal, terminal, }: CheckboxOptions<T>): Promise<T[]>;
|
|
35
|
+
export {};
|
|
36
|
+
//# sourceMappingURL=checkbox-prompt.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkbox-prompt.d.ts","sourceRoot":"","sources":["../../source/terminal/checkbox-prompt.ts"],"names":[],"mappings":";AACA;;;GAGG;AAoCH,UAAU,UAAU;IAClB,KAAK,EAAE,MAAM,CAAC,UAAU,CAAC;IACzB,MAAM,EAAE,MAAM,CAAC,WAAW,CAAC;CAC5B;AAED,UAAU,YAAY,CAAC,CAAC,GAAG,OAAO;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,CAAC,CAAC;IACT,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AACD,MAAM,MAAM,MAAM,CAAC,CAAC,GAAG,OAAO,IAAI,MAAM,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC;AAS3D,MAAM,WAAW,eAAe,CAAC,CAAC,GAAG,OAAO;IAC1C,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,QAAQ,CAAC,EAAE,UAAU,CAAC;CACvB;AA4GD;;;;;;GAMG;AACH,wBAAsB,QAAQ,CAAC,CAAC,GAAG,OAAO,EAAE,EAC1C,OAAkB,EAClB,OAAO,EACP,OAAW,EACX,QAAY,EACZ,QAAgB,EAChB,MAAM,EACN,QAA2D,GAC5D,EAAE,eAAe,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC,CAiQnC"}
|
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Standalone checkbox prompt (inquirer-like)
|
|
4
|
+
* - TypeScript version
|
|
5
|
+
*/
|
|
6
|
+
import { isAbortError, isCancelError, PromptAbortError, PromptCancelError, } from "./errors.js";
|
|
7
|
+
const Keys = {
|
|
8
|
+
up: "\x1b[A",
|
|
9
|
+
down: "\x1b[B",
|
|
10
|
+
home: "\x1b[H",
|
|
11
|
+
homeAlt: "\x1b[1~",
|
|
12
|
+
end: "\x1b[F",
|
|
13
|
+
endAlt: "\x1b[4~",
|
|
14
|
+
ctrlC: "\u0003",
|
|
15
|
+
enter: "\r",
|
|
16
|
+
newline: "\n",
|
|
17
|
+
backspace: "\x7f",
|
|
18
|
+
backspaceAlt: "\b",
|
|
19
|
+
};
|
|
20
|
+
const ANSI = {
|
|
21
|
+
hideCursor: "\x1b[?25l",
|
|
22
|
+
showCursor: "\x1b[?25h",
|
|
23
|
+
clearLine: "\x1b[2K",
|
|
24
|
+
carriageReturn: "\r",
|
|
25
|
+
moveToStart: "\x1b[0G",
|
|
26
|
+
clearFromCursor: "\x1b[0J",
|
|
27
|
+
moveUp: "\x1b[1A",
|
|
28
|
+
cyan: "\x1b[36m",
|
|
29
|
+
dim: "\x1b[2m",
|
|
30
|
+
reset: "\x1b[0m",
|
|
31
|
+
};
|
|
32
|
+
function normalizeChoice(choice) {
|
|
33
|
+
if (typeof choice === "string") {
|
|
34
|
+
return {
|
|
35
|
+
name: choice,
|
|
36
|
+
value: choice,
|
|
37
|
+
disabled: false,
|
|
38
|
+
checked: false,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
const { name, value, disabled = false, checked = false } = choice;
|
|
42
|
+
return { name, value, disabled, checked };
|
|
43
|
+
}
|
|
44
|
+
function updatePageStart(pointerIndex, pageSize, totalItems) {
|
|
45
|
+
const currentPage = Math.floor(pointerIndex / pageSize);
|
|
46
|
+
const pageStart = currentPage * pageSize;
|
|
47
|
+
return Math.max(0, Math.min(pageStart, Math.max(0, totalItems - pageSize)));
|
|
48
|
+
}
|
|
49
|
+
function findNextEnabledIndex(choices, startIndex, direction) {
|
|
50
|
+
const len = choices.length;
|
|
51
|
+
let index = startIndex;
|
|
52
|
+
for (let i = 0; i < len; i++) {
|
|
53
|
+
index = (index + direction + len) % len;
|
|
54
|
+
if (!choices[index].disabled) {
|
|
55
|
+
return index;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return startIndex;
|
|
59
|
+
}
|
|
60
|
+
function findFirstEnabledIndex(choices) {
|
|
61
|
+
for (let i = 0; i < choices.length; i++) {
|
|
62
|
+
if (!choices[i].disabled) {
|
|
63
|
+
return i;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return 0;
|
|
67
|
+
}
|
|
68
|
+
function findLastEnabledIndex(choices) {
|
|
69
|
+
for (let i = choices.length - 1; i >= 0; i--) {
|
|
70
|
+
if (!choices[i].disabled) {
|
|
71
|
+
return i;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return choices.length - 1;
|
|
75
|
+
}
|
|
76
|
+
function render(choices, pointerIndex, pageStart, pageSize, prompt, typed, requiredError = false) {
|
|
77
|
+
const visible = choices.slice(pageStart, pageStart + pageSize);
|
|
78
|
+
const lines = [];
|
|
79
|
+
lines.push(`${prompt}${typed ? ` (search: ${typed})` : ""}`);
|
|
80
|
+
if (requiredError) {
|
|
81
|
+
lines.push(`${ANSI.dim}At least one option must be selected${ANSI.reset}`);
|
|
82
|
+
}
|
|
83
|
+
for (let i = 0; i < visible.length; i++) {
|
|
84
|
+
const actualIndex = pageStart + i;
|
|
85
|
+
const ch = visible[i];
|
|
86
|
+
const prefix = actualIndex === pointerIndex ? "›" : " ";
|
|
87
|
+
const checkbox = ch.checked ? "[x]" : "[ ]";
|
|
88
|
+
if (ch.disabled) {
|
|
89
|
+
lines.push(` ${prefix} ${checkbox} ${ch.name} (disabled)`);
|
|
90
|
+
}
|
|
91
|
+
else if (actualIndex === pointerIndex) {
|
|
92
|
+
lines.push(`${ANSI.cyan} ${prefix} ${checkbox} ${ch.name}${ANSI.reset}`);
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
lines.push(` ${prefix} ${checkbox} ${ch.name}`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if (choices.length > pageSize) {
|
|
99
|
+
const pageCount = Math.ceil(choices.length / pageSize);
|
|
100
|
+
const currentPage = Math.ceil(pageStart / pageSize) + 1;
|
|
101
|
+
lines.push(`${ANSI.dim}Page ${currentPage}/${pageCount}${ANSI.reset}`);
|
|
102
|
+
}
|
|
103
|
+
// Add keyboard shortcuts help
|
|
104
|
+
lines.push("");
|
|
105
|
+
lines.push(`${ANSI.dim}Controls: ↑↓ move, space toggle, a select all, i invert, enter confirm, ctrl+c cancel${ANSI.reset}`);
|
|
106
|
+
return lines.join("\n");
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Interactive checkbox prompt for selecting multiple options
|
|
110
|
+
* @param options Configuration options for the checkbox prompt
|
|
111
|
+
* @returns Promise resolving to array of selected values
|
|
112
|
+
* @throws {PromptCancelError} When user cancels with Ctrl+C
|
|
113
|
+
* @throws {PromptAbortError} When signal is aborted
|
|
114
|
+
*/
|
|
115
|
+
export async function checkbox({ message = "Select", choices, initial = 0, pageSize = 7, required = false, signal, terminal = { stdin: process.stdin, stdout: process.stdout }, }) {
|
|
116
|
+
if (!Array.isArray(choices) || choices.length === 0) {
|
|
117
|
+
throw new Error("choices must be a non-empty array");
|
|
118
|
+
}
|
|
119
|
+
const normalized = choices.map(normalizeChoice);
|
|
120
|
+
const hasEnabledChoice = normalized.some((ch) => !ch.disabled);
|
|
121
|
+
if (!hasEnabledChoice) {
|
|
122
|
+
throw new Error("At least one choice must be enabled");
|
|
123
|
+
}
|
|
124
|
+
let pointer = Math.max(0, Math.min(Math.floor(initial ?? 0), normalized.length - 1));
|
|
125
|
+
if (normalized[pointer].disabled) {
|
|
126
|
+
pointer = findNextEnabledIndex(normalized, pointer, 1);
|
|
127
|
+
}
|
|
128
|
+
let pageStart = updatePageStart(pointer, pageSize, normalized.length);
|
|
129
|
+
const { stdin, stdout } = terminal;
|
|
130
|
+
if (!stdin.isTTY) {
|
|
131
|
+
throw new Error("TTY required");
|
|
132
|
+
}
|
|
133
|
+
stdin.setRawMode(true);
|
|
134
|
+
stdin.resume();
|
|
135
|
+
stdin.setEncoding("utf8");
|
|
136
|
+
let searchBuffer = "";
|
|
137
|
+
let searchTimer = null;
|
|
138
|
+
let requiredError = false;
|
|
139
|
+
const resetSearchBuffer = () => {
|
|
140
|
+
if (searchTimer)
|
|
141
|
+
clearTimeout(searchTimer);
|
|
142
|
+
searchTimer = setTimeout(() => {
|
|
143
|
+
searchBuffer = "";
|
|
144
|
+
}, 800);
|
|
145
|
+
};
|
|
146
|
+
let previousOutputLines = 0;
|
|
147
|
+
function clearPreviousOutput(lineCount) {
|
|
148
|
+
for (let i = 0; i < lineCount; i++) {
|
|
149
|
+
stdout.write(`${ANSI.moveUp}${ANSI.clearLine}`);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
function renderToScreen() {
|
|
153
|
+
// Clear current line and move to start
|
|
154
|
+
stdout.write(ANSI.clearLine);
|
|
155
|
+
stdout.write(ANSI.moveToStart);
|
|
156
|
+
// Clear from cursor to end of screen to remove any existing output below
|
|
157
|
+
stdout.write(ANSI.clearFromCursor);
|
|
158
|
+
// Clear previous output by moving up and clearing lines
|
|
159
|
+
clearPreviousOutput(previousOutputLines);
|
|
160
|
+
const out = render(normalized, pointer, pageStart, pageSize, message, searchBuffer, requiredError);
|
|
161
|
+
// Count lines in current output
|
|
162
|
+
previousOutputLines = out.split("\n").length;
|
|
163
|
+
stdout.write(`${out}\n`);
|
|
164
|
+
}
|
|
165
|
+
function move(delta) {
|
|
166
|
+
pointer = findNextEnabledIndex(normalized, pointer, delta);
|
|
167
|
+
pageStart = updatePageStart(pointer, pageSize, normalized.length);
|
|
168
|
+
renderToScreen();
|
|
169
|
+
}
|
|
170
|
+
function jumpToIndexStartingWith(prefix) {
|
|
171
|
+
const start = (pointer + 1) % normalized.length;
|
|
172
|
+
const lowerPref = prefix.toLowerCase();
|
|
173
|
+
for (let i = 0; i < normalized.length; i++) {
|
|
174
|
+
const idx = (start + i) % normalized.length;
|
|
175
|
+
if (normalized[idx].disabled)
|
|
176
|
+
continue;
|
|
177
|
+
if (normalized[idx].name.toLowerCase().startsWith(lowerPref)) {
|
|
178
|
+
pointer = idx;
|
|
179
|
+
pageStart = updatePageStart(pointer, pageSize, normalized.length);
|
|
180
|
+
renderToScreen();
|
|
181
|
+
return true;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return false;
|
|
185
|
+
}
|
|
186
|
+
function toggleCurrent() {
|
|
187
|
+
if (!normalized[pointer].disabled) {
|
|
188
|
+
normalized[pointer].checked = !normalized[pointer].checked;
|
|
189
|
+
renderToScreen();
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
function toggleAll() {
|
|
193
|
+
const allChecked = normalized.every((ch) => ch.disabled || ch.checked);
|
|
194
|
+
normalized.forEach((ch) => {
|
|
195
|
+
if (!ch.disabled) {
|
|
196
|
+
ch.checked = !allChecked;
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
renderToScreen();
|
|
200
|
+
}
|
|
201
|
+
function invertSelection() {
|
|
202
|
+
normalized.forEach((ch) => {
|
|
203
|
+
if (!ch.disabled) {
|
|
204
|
+
ch.checked = !ch.checked;
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
renderToScreen();
|
|
208
|
+
}
|
|
209
|
+
return new Promise((resolve, reject) => {
|
|
210
|
+
let resolved = false;
|
|
211
|
+
let cleanupCalled = false;
|
|
212
|
+
function cleanup() {
|
|
213
|
+
if (cleanupCalled)
|
|
214
|
+
return;
|
|
215
|
+
cleanupCalled = true;
|
|
216
|
+
stdin.setRawMode(false);
|
|
217
|
+
stdin.pause();
|
|
218
|
+
stdin.removeListener("data", onData);
|
|
219
|
+
if (searchTimer)
|
|
220
|
+
clearTimeout(searchTimer);
|
|
221
|
+
if (signal && abortHandler) {
|
|
222
|
+
signal.removeEventListener("abort", abortHandler);
|
|
223
|
+
}
|
|
224
|
+
stdout.write(ANSI.showCursor);
|
|
225
|
+
}
|
|
226
|
+
const abortHandler = signal
|
|
227
|
+
? () => {
|
|
228
|
+
cleanup();
|
|
229
|
+
reject(new PromptAbortError());
|
|
230
|
+
}
|
|
231
|
+
: null;
|
|
232
|
+
if (signal && abortHandler) {
|
|
233
|
+
signal.addEventListener("abort", abortHandler);
|
|
234
|
+
}
|
|
235
|
+
function onData(key) {
|
|
236
|
+
if (key === Keys.ctrlC) {
|
|
237
|
+
cleanup();
|
|
238
|
+
stdout.write("\n");
|
|
239
|
+
reject(new PromptCancelError());
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
if (key === Keys.enter || key === Keys.newline) {
|
|
243
|
+
const selected = normalized.filter((ch) => ch.checked && !ch.disabled);
|
|
244
|
+
if (required && selected.length === 0) {
|
|
245
|
+
// Show error but don't exit
|
|
246
|
+
requiredError = true;
|
|
247
|
+
renderToScreen();
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
requiredError = false;
|
|
251
|
+
resolved = true;
|
|
252
|
+
cleanup();
|
|
253
|
+
stdout.write("\n");
|
|
254
|
+
resolve(selected.map((ch) => ch.value));
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
if (key === Keys.up) {
|
|
258
|
+
move(-1);
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
if (key === Keys.down) {
|
|
262
|
+
move(1);
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
if (key === Keys.home || key === Keys.homeAlt) {
|
|
266
|
+
pointer = findFirstEnabledIndex(normalized);
|
|
267
|
+
pageStart = updatePageStart(pointer, pageSize, normalized.length);
|
|
268
|
+
renderToScreen();
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
271
|
+
if (key === Keys.end || key === Keys.endAlt) {
|
|
272
|
+
pointer = findLastEnabledIndex(normalized);
|
|
273
|
+
pageStart = updatePageStart(pointer, pageSize, normalized.length);
|
|
274
|
+
renderToScreen();
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
if (key === Keys.backspace || key === Keys.backspaceAlt) {
|
|
278
|
+
if (searchBuffer.length > 0) {
|
|
279
|
+
searchBuffer = searchBuffer.slice(0, -1);
|
|
280
|
+
if (searchBuffer.length === 0)
|
|
281
|
+
resetSearchBuffer();
|
|
282
|
+
renderToScreen();
|
|
283
|
+
}
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
if (key === " ") {
|
|
287
|
+
toggleCurrent();
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
if (key === "a") {
|
|
291
|
+
toggleAll();
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
if (key === "i") {
|
|
295
|
+
invertSelection();
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
if (key && key >= " " && key <= "~") {
|
|
299
|
+
searchBuffer += key;
|
|
300
|
+
resetSearchBuffer();
|
|
301
|
+
const found = jumpToIndexStartingWith(searchBuffer);
|
|
302
|
+
if (!found) {
|
|
303
|
+
searchBuffer = key;
|
|
304
|
+
resetSearchBuffer();
|
|
305
|
+
jumpToIndexStartingWith(searchBuffer);
|
|
306
|
+
}
|
|
307
|
+
renderToScreen();
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
try {
|
|
312
|
+
stdout.write(ANSI.hideCursor);
|
|
313
|
+
// Reset previous output lines counter to ensure clean start
|
|
314
|
+
previousOutputLines = 0;
|
|
315
|
+
renderToScreen();
|
|
316
|
+
stdin.on("data", onData);
|
|
317
|
+
const exitHandler = () => {
|
|
318
|
+
if (!resolved) {
|
|
319
|
+
cleanup();
|
|
320
|
+
stdout.write("\n");
|
|
321
|
+
}
|
|
322
|
+
};
|
|
323
|
+
process.on("exit", exitHandler);
|
|
324
|
+
}
|
|
325
|
+
catch (error) {
|
|
326
|
+
cleanup();
|
|
327
|
+
throw error;
|
|
328
|
+
}
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
// Quick test when run directly
|
|
332
|
+
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
333
|
+
(async () => {
|
|
334
|
+
try {
|
|
335
|
+
const res = await checkbox({
|
|
336
|
+
message: "Pick fruits",
|
|
337
|
+
choices: [
|
|
338
|
+
"Apple",
|
|
339
|
+
"Banana",
|
|
340
|
+
{ name: "Date", value: "date", checked: true },
|
|
341
|
+
"Elderberry",
|
|
342
|
+
{ name: "Fig", value: "fig", disabled: true },
|
|
343
|
+
"Grapes",
|
|
344
|
+
"Honeydew",
|
|
345
|
+
"Orange",
|
|
346
|
+
],
|
|
347
|
+
pageSize: 3,
|
|
348
|
+
initial: 0,
|
|
349
|
+
});
|
|
350
|
+
console.info("You picked:", res);
|
|
351
|
+
process.exit(0);
|
|
352
|
+
}
|
|
353
|
+
catch (err) {
|
|
354
|
+
if (isCancelError(err)) {
|
|
355
|
+
console.error("Cancelled");
|
|
356
|
+
process.exit(2);
|
|
357
|
+
}
|
|
358
|
+
else if (isAbortError(err)) {
|
|
359
|
+
console.error("Aborted");
|
|
360
|
+
process.exit(3);
|
|
361
|
+
}
|
|
362
|
+
else {
|
|
363
|
+
console.error(err);
|
|
364
|
+
process.exit(1);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
})();
|
|
368
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"default-theme.d.ts","sourceRoot":"","sources":["../../source/terminal/default-theme.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AASlD;;GAEG;AACH,eAAO,MAAM,aAAa,EAAE,KAqN3B,CAAC"}
|