@travisennis/acai 0.0.1
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/.acai/acai.json +9 -0
- package/.acai/prompts/add-openrouter-model.md +13 -0
- package/.acai/prompts/project-status.md +4 -0
- package/.acai/prompts/update-architecture-document.md +9 -0
- package/.acai/rules/learned-rules.md +9 -0
- package/.ai/docs/available-tools.txt +3 -0
- package/.ai/docs/cognitive_complexity_refactoring_progress.md +65 -0
- package/.ai/docs/deleted_tools.md +168 -0
- package/.ai/docs/deleted_tools_88ced9ef.md +56 -0
- package/.ai/docs/image-pasting.md +46 -0
- package/.ai/docs/initialize-app.md +117 -0
- package/.ai/docs/issue-4-plan.md +44 -0
- package/.ai/docs/marked-renderer-debug.md +15 -0
- package/.ai/docs/marked-renderer-refactor-plan.md +64 -0
- package/.ai/docs/memory-use-cases.md +55 -0
- package/.ai/docs/prompt-consistency.md +31 -0
- package/.ai/docs/refactoring-tools.md +98 -0
- package/.ai/docs/system-prompt-update.md +174 -0
- package/.ai/docs/system_prompt.txt +210 -0
- package/.ai/docs/tasks.md +49 -0
- package/.ai/plan.md +131 -0
- package/.ai/prompt.md +1 -0
- package/.ai/scripts/fetch_models.js +27 -0
- package/.ai/scripts/generateSystemPrompt.ts +15 -0
- package/.ai/scripts/list-tools.mjs +4 -0
- package/.ai/scripts/p5_geometric_shapes.js +149 -0
- package/.husky/commit-msg +1 -0
- package/.husky/pre-commit +3 -0
- package/.husky/pre-push +1 -0
- package/.ignore +4 -0
- package/AGENTS.md +25 -0
- package/ARCHITECTURE.md +304 -0
- package/LICENSE +21 -0
- package/README.md +392 -0
- package/TODO.md +2 -0
- package/biome.json +61 -0
- package/commitlint.config.js +3 -0
- package/dist/cli.d.ts +19 -0
- package/dist/cli.js +116 -0
- package/dist/commands/application-log-command.d.ts +2 -0
- package/dist/commands/application-log-command.js +43 -0
- package/dist/commands/clear-command.d.ts +2 -0
- package/dist/commands/clear-command.js +12 -0
- package/dist/commands/compact-command.d.ts +2 -0
- package/dist/commands/compact-command.js +51 -0
- package/dist/commands/copy-command.d.ts +2 -0
- package/dist/commands/copy-command.js +51 -0
- package/dist/commands/edit-command.d.ts +2 -0
- package/dist/commands/edit-command.js +53 -0
- package/dist/commands/edit-prompt-command.d.ts +2 -0
- package/dist/commands/edit-prompt-command.js +25 -0
- package/dist/commands/exit-command.d.ts +2 -0
- package/dist/commands/exit-command.js +14 -0
- package/dist/commands/files-command.d.ts +2 -0
- package/dist/commands/files-command.js +63 -0
- package/dist/commands/generate-rules-command.d.ts +2 -0
- package/dist/commands/generate-rules-command.js +61 -0
- package/dist/commands/help-command.d.ts +2 -0
- package/dist/commands/help-command.js +19 -0
- package/dist/commands/init-command.d.ts +2 -0
- package/dist/commands/init-command.js +40 -0
- package/dist/commands/last-log-command.d.ts +2 -0
- package/dist/commands/last-log-command.js +76 -0
- package/dist/commands/manager.d.ts +22 -0
- package/dist/commands/manager.js +123 -0
- package/dist/commands/model-command.d.ts +2 -0
- package/dist/commands/model-command.js +84 -0
- package/dist/commands/paste-command.d.ts +2 -0
- package/dist/commands/paste-command.js +40 -0
- package/dist/commands/prompt-command.d.ts +2 -0
- package/dist/commands/prompt-command.js +111 -0
- package/dist/commands/reset-command.d.ts +2 -0
- package/dist/commands/reset-command.js +16 -0
- package/dist/commands/rules-command.d.ts +2 -0
- package/dist/commands/rules-command.js +68 -0
- package/dist/commands/save-command.d.ts +2 -0
- package/dist/commands/save-command.js +14 -0
- package/dist/commands/types.d.ts +26 -0
- package/dist/commands/types.js +1 -0
- package/dist/commands/usage-command.d.ts +2 -0
- package/dist/commands/usage-command.js +21 -0
- package/dist/config.d.ts +60 -0
- package/dist/config.js +193 -0
- package/dist/conversation-analyzer.d.ts +10 -0
- package/dist/conversation-analyzer.js +88 -0
- package/dist/dedent.d.ts +3 -0
- package/dist/dedent.js +38 -0
- package/dist/formatting.d.ts +17 -0
- package/dist/formatting.js +103 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +213 -0
- package/dist/logger.d.ts +2 -0
- package/dist/logger.js +24 -0
- package/dist/mentions.d.ts +9 -0
- package/dist/mentions.js +182 -0
- package/dist/messages.d.ts +69 -0
- package/dist/messages.js +261 -0
- package/dist/middleware/audit-message.d.ts +5 -0
- package/dist/middleware/audit-message.js +95 -0
- package/dist/middleware/index.d.ts +2 -0
- package/dist/middleware/index.js +2 -0
- package/dist/middleware/rate-limit.d.ts +4 -0
- package/dist/middleware/rate-limit.js +17 -0
- package/dist/models/ai-config.d.ts +12 -0
- package/dist/models/ai-config.js +87 -0
- package/dist/models/anthropic-provider.d.ts +25 -0
- package/dist/models/anthropic-provider.js +184 -0
- package/dist/models/deepseek-provider.d.ts +20 -0
- package/dist/models/deepseek-provider.js +42 -0
- package/dist/models/google-provider.d.ts +19 -0
- package/dist/models/google-provider.js +56 -0
- package/dist/models/manager.d.ts +15 -0
- package/dist/models/manager.js +48 -0
- package/dist/models/openai-provider.d.ts +22 -0
- package/dist/models/openai-provider.js +70 -0
- package/dist/models/openrouter-provider.d.ts +36 -0
- package/dist/models/openrouter-provider.js +276 -0
- package/dist/models/providers.d.ts +33 -0
- package/dist/models/providers.js +116 -0
- package/dist/models/xai-provider.d.ts +20 -0
- package/dist/models/xai-provider.js +47 -0
- package/dist/parsing.d.ts +2 -0
- package/dist/parsing.js +18 -0
- package/dist/prompts/manager.d.ts +19 -0
- package/dist/prompts/manager.js +71 -0
- package/dist/prompts.d.ts +4 -0
- package/dist/prompts.js +158 -0
- package/dist/repl-prompt.d.ts +14 -0
- package/dist/repl-prompt.js +147 -0
- package/dist/repl.d.ts +27 -0
- package/dist/repl.js +431 -0
- package/dist/source/cli.d.ts +19 -0
- package/dist/source/cli.js +116 -0
- package/dist/source/commands/application-log-command.d.ts +2 -0
- package/dist/source/commands/application-log-command.js +43 -0
- package/dist/source/commands/clear-command.d.ts +2 -0
- package/dist/source/commands/clear-command.js +12 -0
- package/dist/source/commands/compact-command.d.ts +2 -0
- package/dist/source/commands/compact-command.js +51 -0
- package/dist/source/commands/copy-command.d.ts +2 -0
- package/dist/source/commands/copy-command.js +51 -0
- package/dist/source/commands/edit-command.d.ts +2 -0
- package/dist/source/commands/edit-command.js +53 -0
- package/dist/source/commands/edit-prompt-command.d.ts +2 -0
- package/dist/source/commands/edit-prompt-command.js +25 -0
- package/dist/source/commands/exit-command.d.ts +2 -0
- package/dist/source/commands/exit-command.js +14 -0
- package/dist/source/commands/files-command.d.ts +2 -0
- package/dist/source/commands/files-command.js +63 -0
- package/dist/source/commands/generate-rules-command.d.ts +2 -0
- package/dist/source/commands/generate-rules-command.js +61 -0
- package/dist/source/commands/help-command.d.ts +2 -0
- package/dist/source/commands/help-command.js +19 -0
- package/dist/source/commands/init-command.d.ts +2 -0
- package/dist/source/commands/init-command.js +40 -0
- package/dist/source/commands/last-log-command.d.ts +2 -0
- package/dist/source/commands/last-log-command.js +76 -0
- package/dist/source/commands/manager.d.ts +22 -0
- package/dist/source/commands/manager.js +123 -0
- package/dist/source/commands/model-command.d.ts +2 -0
- package/dist/source/commands/model-command.js +84 -0
- package/dist/source/commands/paste-command.d.ts +2 -0
- package/dist/source/commands/paste-command.js +40 -0
- package/dist/source/commands/prompt-command.d.ts +2 -0
- package/dist/source/commands/prompt-command.js +111 -0
- package/dist/source/commands/reset-command.d.ts +2 -0
- package/dist/source/commands/reset-command.js +16 -0
- package/dist/source/commands/rules-command.d.ts +2 -0
- package/dist/source/commands/rules-command.js +68 -0
- package/dist/source/commands/save-command.d.ts +2 -0
- package/dist/source/commands/save-command.js +14 -0
- package/dist/source/commands/types.d.ts +26 -0
- package/dist/source/commands/types.js +1 -0
- package/dist/source/commands/usage-command.d.ts +2 -0
- package/dist/source/commands/usage-command.js +21 -0
- package/dist/source/config.d.ts +60 -0
- package/dist/source/config.js +193 -0
- package/dist/source/conversation-analyzer.d.ts +10 -0
- package/dist/source/conversation-analyzer.js +88 -0
- package/dist/source/dedent.d.ts +3 -0
- package/dist/source/dedent.js +38 -0
- package/dist/source/formatting.d.ts +17 -0
- package/dist/source/formatting.js +103 -0
- package/dist/source/index.d.ts +18 -0
- package/dist/source/index.js +213 -0
- package/dist/source/logger.d.ts +2 -0
- package/dist/source/logger.js +24 -0
- package/dist/source/mentions.d.ts +9 -0
- package/dist/source/mentions.js +182 -0
- package/dist/source/messages.d.ts +69 -0
- package/dist/source/messages.js +261 -0
- package/dist/source/middleware/audit-message.d.ts +5 -0
- package/dist/source/middleware/audit-message.js +95 -0
- package/dist/source/middleware/index.d.ts +2 -0
- package/dist/source/middleware/index.js +2 -0
- package/dist/source/middleware/rate-limit.d.ts +4 -0
- package/dist/source/middleware/rate-limit.js +17 -0
- package/dist/source/models/ai-config.d.ts +12 -0
- package/dist/source/models/ai-config.js +87 -0
- package/dist/source/models/anthropic-provider.d.ts +25 -0
- package/dist/source/models/anthropic-provider.js +184 -0
- package/dist/source/models/deepseek-provider.d.ts +20 -0
- package/dist/source/models/deepseek-provider.js +42 -0
- package/dist/source/models/google-provider.d.ts +19 -0
- package/dist/source/models/google-provider.js +56 -0
- package/dist/source/models/manager.d.ts +15 -0
- package/dist/source/models/manager.js +48 -0
- package/dist/source/models/openai-provider.d.ts +22 -0
- package/dist/source/models/openai-provider.js +70 -0
- package/dist/source/models/openrouter-provider.d.ts +36 -0
- package/dist/source/models/openrouter-provider.js +276 -0
- package/dist/source/models/providers.d.ts +33 -0
- package/dist/source/models/providers.js +116 -0
- package/dist/source/models/xai-provider.d.ts +20 -0
- package/dist/source/models/xai-provider.js +47 -0
- package/dist/source/parsing.d.ts +2 -0
- package/dist/source/parsing.js +18 -0
- package/dist/source/prompts/manager.d.ts +19 -0
- package/dist/source/prompts/manager.js +71 -0
- package/dist/source/prompts.d.ts +4 -0
- package/dist/source/prompts.js +158 -0
- package/dist/source/repl-prompt.d.ts +14 -0
- package/dist/source/repl-prompt.js +147 -0
- package/dist/source/repl.d.ts +27 -0
- package/dist/source/repl.js +431 -0
- package/dist/source/terminal/formatting.d.ts +37 -0
- package/dist/source/terminal/formatting.js +106 -0
- package/dist/source/terminal/index.d.ts +94 -0
- package/dist/source/terminal/index.js +420 -0
- package/dist/source/terminal/markdown-utils.d.ts +2 -0
- package/dist/source/terminal/markdown-utils.js +81 -0
- package/dist/source/terminal/markdown.d.ts +1 -0
- package/dist/source/terminal/markdown.js +111 -0
- package/dist/source/terminal/types.d.ts +71 -0
- package/dist/source/terminal/types.js +1 -0
- package/dist/source/terminal-output.d.ts +8 -0
- package/dist/source/terminal-output.js +213 -0
- package/dist/source/terminal-output.test.d.ts +8 -0
- package/dist/source/terminal-output.test.js +213 -0
- package/dist/source/token-tracker.d.ts +14 -0
- package/dist/source/token-tracker.js +53 -0
- package/dist/source/token-utils.d.ts +7 -0
- package/dist/source/token-utils.js +13 -0
- package/dist/source/tools/agent.d.ts +17 -0
- package/dist/source/tools/agent.js +87 -0
- package/dist/source/tools/bash.d.ts +19 -0
- package/dist/source/tools/bash.js +294 -0
- package/dist/source/tools/code-interpreter.d.ts +12 -0
- package/dist/source/tools/code-interpreter.js +131 -0
- package/dist/source/tools/command-validation.d.ts +8 -0
- package/dist/source/tools/command-validation.js +69 -0
- package/dist/source/tools/delete-file.d.ts +12 -0
- package/dist/source/tools/delete-file.js +56 -0
- package/dist/source/tools/directory-tree.d.ts +12 -0
- package/dist/source/tools/directory-tree.js +38 -0
- package/dist/source/tools/edit-file.d.ts +19 -0
- package/dist/source/tools/edit-file.js +107 -0
- package/dist/source/tools/filesystem-utils.d.ts +22 -0
- package/dist/source/tools/filesystem-utils.js +191 -0
- package/dist/source/tools/git-utils.d.ts +14 -0
- package/dist/source/tools/git-utils.js +64 -0
- package/dist/source/tools/grep.d.ts +17 -0
- package/dist/source/tools/grep.js +138 -0
- package/dist/source/tools/index.d.ts +161 -0
- package/dist/source/tools/index.js +209 -0
- package/dist/source/tools/memory-read.d.ts +13 -0
- package/dist/source/tools/memory-read.js +135 -0
- package/dist/source/tools/memory-write.d.ts +12 -0
- package/dist/source/tools/memory-write.js +83 -0
- package/dist/source/tools/move-file.d.ts +13 -0
- package/dist/source/tools/move-file.js +44 -0
- package/dist/source/tools/read-file.d.ts +17 -0
- package/dist/source/tools/read-file.js +86 -0
- package/dist/source/tools/read-multiple-files.d.ts +14 -0
- package/dist/source/tools/read-multiple-files.js +55 -0
- package/dist/source/tools/save-file.d.ts +17 -0
- package/dist/source/tools/save-file.js +98 -0
- package/dist/source/tools/think.d.ts +11 -0
- package/dist/source/tools/think.js +45 -0
- package/dist/source/tools/types.d.ts +29 -0
- package/dist/source/tools/types.js +14 -0
- package/dist/source/tools/web-fetch.d.ts +47 -0
- package/dist/source/tools/web-fetch.js +246 -0
- package/dist/source/tools/web-search.d.ts +13 -0
- package/dist/source/tools/web-search.js +80 -0
- package/dist/source/utils/process.d.ts +36 -0
- package/dist/source/utils/process.js +75 -0
- package/dist/source/version.d.ts +1 -0
- package/dist/source/version.js +21 -0
- package/dist/terminal/formatting.d.ts +37 -0
- package/dist/terminal/formatting.js +106 -0
- package/dist/terminal/index.d.ts +94 -0
- package/dist/terminal/index.js +420 -0
- package/dist/terminal/markdown-utils.d.ts +2 -0
- package/dist/terminal/markdown-utils.js +81 -0
- package/dist/terminal/markdown.d.ts +1 -0
- package/dist/terminal/markdown.js +111 -0
- package/dist/terminal/types.d.ts +71 -0
- package/dist/terminal/types.js +1 -0
- package/dist/terminal-output.d.ts +8 -0
- package/dist/terminal-output.js +213 -0
- package/dist/token-tracker.d.ts +14 -0
- package/dist/token-tracker.js +53 -0
- package/dist/token-utils.d.ts +7 -0
- package/dist/token-utils.js +13 -0
- package/dist/tools/agent.d.ts +17 -0
- package/dist/tools/agent.js +87 -0
- package/dist/tools/bash.d.ts +19 -0
- package/dist/tools/bash.js +294 -0
- package/dist/tools/code-interpreter.d.ts +12 -0
- package/dist/tools/code-interpreter.js +131 -0
- package/dist/tools/command-validation.d.ts +8 -0
- package/dist/tools/command-validation.js +69 -0
- package/dist/tools/delete-file.d.ts +12 -0
- package/dist/tools/delete-file.js +56 -0
- package/dist/tools/directory-tree.d.ts +12 -0
- package/dist/tools/directory-tree.js +38 -0
- package/dist/tools/edit-file.d.ts +19 -0
- package/dist/tools/edit-file.js +107 -0
- package/dist/tools/filesystem-utils.d.ts +22 -0
- package/dist/tools/filesystem-utils.js +191 -0
- package/dist/tools/git-utils.d.ts +14 -0
- package/dist/tools/git-utils.js +64 -0
- package/dist/tools/grep.d.ts +17 -0
- package/dist/tools/grep.js +138 -0
- package/dist/tools/index.d.ts +161 -0
- package/dist/tools/index.js +209 -0
- package/dist/tools/memory-read.d.ts +13 -0
- package/dist/tools/memory-read.js +135 -0
- package/dist/tools/memory-write.d.ts +12 -0
- package/dist/tools/memory-write.js +83 -0
- package/dist/tools/move-file.d.ts +13 -0
- package/dist/tools/move-file.js +44 -0
- package/dist/tools/read-file.d.ts +17 -0
- package/dist/tools/read-file.js +86 -0
- package/dist/tools/read-multiple-files.d.ts +14 -0
- package/dist/tools/read-multiple-files.js +55 -0
- package/dist/tools/save-file.d.ts +17 -0
- package/dist/tools/save-file.js +98 -0
- package/dist/tools/think.d.ts +11 -0
- package/dist/tools/think.js +45 -0
- package/dist/tools/types.d.ts +29 -0
- package/dist/tools/types.js +14 -0
- package/dist/tools/web-fetch.d.ts +47 -0
- package/dist/tools/web-fetch.js +246 -0
- package/dist/tools/web-search.d.ts +13 -0
- package/dist/tools/web-search.js +80 -0
- package/dist/utils/process.d.ts +36 -0
- package/dist/utils/process.js +75 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +21 -0
- package/knip.json +5 -0
- package/package.json +83 -0
- package/source/cli.ts +172 -0
- package/source/commands/application-log-command.ts +53 -0
- package/source/commands/clear-command.ts +14 -0
- package/source/commands/compact-command.ts +64 -0
- package/source/commands/copy-command.ts +55 -0
- package/source/commands/edit-command.ts +63 -0
- package/source/commands/edit-prompt-command.ts +31 -0
- package/source/commands/exit-command.ts +18 -0
- package/source/commands/files-command.ts +85 -0
- package/source/commands/generate-rules-command.ts +82 -0
- package/source/commands/help-command.ts +27 -0
- package/source/commands/init-command.ts +48 -0
- package/source/commands/last-log-command.ts +88 -0
- package/source/commands/manager.ts +151 -0
- package/source/commands/model-command.ts +123 -0
- package/source/commands/paste-command.ts +62 -0
- package/source/commands/prompt-command.ts +150 -0
- package/source/commands/reset-command.ts +22 -0
- package/source/commands/rules-command.ts +76 -0
- package/source/commands/save-command.ts +20 -0
- package/source/commands/types.ts +28 -0
- package/source/commands/usage-command.ts +26 -0
- package/source/config.ts +223 -0
- package/source/conversation-analyzer.ts +115 -0
- package/source/dedent.ts +53 -0
- package/source/formatting.ts +132 -0
- package/source/index.ts +240 -0
- package/source/logger.ts +29 -0
- package/source/mentions.ts +227 -0
- package/source/messages.ts +360 -0
- package/source/middleware/audit-message.ts +133 -0
- package/source/middleware/index.ts +2 -0
- package/source/middleware/rate-limit.ts +24 -0
- package/source/models/ai-config.ts +109 -0
- package/source/models/anthropic-provider.ts +199 -0
- package/source/models/deepseek-provider.ts +53 -0
- package/source/models/google-provider.ts +68 -0
- package/source/models/manager.ts +84 -0
- package/source/models/openai-provider.ts +81 -0
- package/source/models/openrouter-provider.ts +288 -0
- package/source/models/providers.ts +197 -0
- package/source/models/xai-provider.ts +59 -0
- package/source/parsing.ts +20 -0
- package/source/prompts/manager.ts +90 -0
- package/source/prompts.ts +172 -0
- package/source/repl-prompt.ts +196 -0
- package/source/repl.ts +572 -0
- package/source/terminal/formatting.ts +121 -0
- package/source/terminal/index.ts +518 -0
- package/source/terminal/markdown-utils.ts +89 -0
- package/source/terminal/markdown.ts +155 -0
- package/source/terminal/types.ts +84 -0
- package/source/terminal-output.test.ts +266 -0
- package/source/token-tracker.ts +78 -0
- package/source/token-utils.ts +17 -0
- package/source/tools/agent.ts +107 -0
- package/source/tools/bash.ts +367 -0
- package/source/tools/code-interpreter.ts +172 -0
- package/source/tools/command-validation.ts +81 -0
- package/source/tools/delete-file.ts +71 -0
- package/source/tools/directory-tree.ts +54 -0
- package/source/tools/edit-file.ts +155 -0
- package/source/tools/filesystem-utils.ts +265 -0
- package/source/tools/git-utils.ts +70 -0
- package/source/tools/grep.ts +184 -0
- package/source/tools/index.ts +278 -0
- package/source/tools/memory-read.ts +174 -0
- package/source/tools/memory-write.ts +105 -0
- package/source/tools/move-file.ts +59 -0
- package/source/tools/read-file.ts +129 -0
- package/source/tools/read-multiple-files.ts +80 -0
- package/source/tools/save-file.ts +147 -0
- package/source/tools/think.ts +51 -0
- package/source/tools/types.ts +58 -0
- package/source/tools/web-fetch.ts +327 -0
- package/source/tools/web-search.ts +101 -0
- package/source/utils/process.ts +121 -0
- package/source/version.ts +21 -0
- package/test/commands/copy-command.test.ts +69 -0
- package/test/config.test.ts +200 -0
- package/test/terminal/markdown-utils.test.ts +124 -0
- package/test/tools/bash-tool.test.ts +58 -0
- package/test/tools/code-interpreter.test.ts +91 -0
- package/test/tools/command-validation.test.ts +48 -0
- package/tsconfig.build.json +9 -0
- package/tsconfig.json +30 -0
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
#!/usr/bin/env -S node --no-warnings
|
|
2
|
+
/**
|
|
3
|
+
* Terminal Output Test Module
|
|
4
|
+
*
|
|
5
|
+
* Exercises all methods and features of the Terminal class for testing purposes.
|
|
6
|
+
* Demonstrates various markdown rendering capabilities.
|
|
7
|
+
*/
|
|
8
|
+
import { initTerminal } from "./terminal/index.js";
|
|
9
|
+
// Initialize terminal
|
|
10
|
+
const terminal = initTerminal({
|
|
11
|
+
useColors: true,
|
|
12
|
+
showProgressIndicators: true,
|
|
13
|
+
});
|
|
14
|
+
// Test all terminal methods and features
|
|
15
|
+
function testTerminalOutput() {
|
|
16
|
+
// Clear screen and show welcome
|
|
17
|
+
terminal.clear();
|
|
18
|
+
terminal.displayWelcome();
|
|
19
|
+
// Test basic output methods
|
|
20
|
+
terminal.header("Basic Output Methods");
|
|
21
|
+
terminal.writeln("This is a basic write line");
|
|
22
|
+
terminal.write("This is a basic write without newline");
|
|
23
|
+
terminal.lineBreak();
|
|
24
|
+
terminal.emphasize("This is emphasized text");
|
|
25
|
+
terminal.info("This is an info message");
|
|
26
|
+
terminal.success("This is a success message");
|
|
27
|
+
terminal.warn("This is a warning message");
|
|
28
|
+
terminal.error("This is an error message");
|
|
29
|
+
terminal.lineBreak();
|
|
30
|
+
// Test markdown display
|
|
31
|
+
terminal.header("Markdown Display Features");
|
|
32
|
+
// Headers
|
|
33
|
+
terminal.display("# This is an H1 Header");
|
|
34
|
+
terminal.display("## This is an H2 Header");
|
|
35
|
+
terminal.display("### This is an H3 Header");
|
|
36
|
+
terminal.display("#### This is an H4 Header");
|
|
37
|
+
terminal.display("##### This is an H5 Header");
|
|
38
|
+
terminal.display("###### This is an H6 Header");
|
|
39
|
+
// Text formatting
|
|
40
|
+
terminal.display("**This is bold text**");
|
|
41
|
+
terminal.display("*This is italic text*");
|
|
42
|
+
terminal.display("***This is bold and italic text***");
|
|
43
|
+
terminal.display("This is `inline code` text");
|
|
44
|
+
terminal.display("~~This is strikethrough text~~");
|
|
45
|
+
// Links
|
|
46
|
+
terminal.display("This is a [link](https://example.com)");
|
|
47
|
+
// Images
|
|
48
|
+
terminal.display("This is an ");
|
|
49
|
+
// Blockquotes
|
|
50
|
+
terminal.display("> This is a blockquote");
|
|
51
|
+
terminal.display("> This is a\n> multi-line blockquote");
|
|
52
|
+
// Horizontal rule
|
|
53
|
+
terminal.display("---");
|
|
54
|
+
// Lists
|
|
55
|
+
terminal.display("- This is an unordered list item");
|
|
56
|
+
terminal.display("- This is another unordered list item");
|
|
57
|
+
terminal.display(" - This is a nested list item");
|
|
58
|
+
terminal.display(" - This is a double nested list item");
|
|
59
|
+
terminal.display("1. This is an ordered list item");
|
|
60
|
+
terminal.display("2. This is another ordered list item");
|
|
61
|
+
terminal.display(" 1. This is a nested ordered list item");
|
|
62
|
+
terminal.display(" 2. This is another nested ordered list item");
|
|
63
|
+
// Code blocks
|
|
64
|
+
terminal.display("```javascript\nconst greeting = 'Hello World';\nconsole.log(greeting);\n```");
|
|
65
|
+
terminal.display("```python\ndef hello():\n print('Hello World')\n```");
|
|
66
|
+
terminal.display("```\nThis is a plain code block\n```");
|
|
67
|
+
// Tables
|
|
68
|
+
terminal.display("| Header 1 | Header 2 | Header 3 |\n|----------|----------|----------|\n| Cell 1 | Cell 2 | Cell 3 |\n| Cell 4 | Cell 5 | Cell 6 |");
|
|
69
|
+
// Paragraphs
|
|
70
|
+
terminal.display("This is a paragraph with some **bold** and *italic* text. " +
|
|
71
|
+
"It also contains `inline code` and a [link](https://example.com). " +
|
|
72
|
+
"Here's an  for good measure.");
|
|
73
|
+
terminal.display("This is another paragraph that demonstrates how line breaks work " +
|
|
74
|
+
"in markdown with the terminal display. It should wrap appropriately based " +
|
|
75
|
+
"on the terminal width.");
|
|
76
|
+
// Complex markdown example
|
|
77
|
+
const complexMarkdown = `
|
|
78
|
+
# Complex Markdown Example
|
|
79
|
+
|
|
80
|
+
This is a complex example showing various **markdown** features in *one* document.
|
|
81
|
+
|
|
82
|
+
## Features Demonstrated
|
|
83
|
+
|
|
84
|
+
1. **Headers** of different levels
|
|
85
|
+
2. *Text formatting* options
|
|
86
|
+
3. \`Code elements\` of various types
|
|
87
|
+
4. [External links](https://example.com)
|
|
88
|
+
5. 
|
|
89
|
+
6. Blockquotes
|
|
90
|
+
|
|
91
|
+
> Blockquotes
|
|
92
|
+
|
|
93
|
+
7. Horizontal rules
|
|
94
|
+
8. Lists (ordered and unordered)
|
|
95
|
+
9. Tables
|
|
96
|
+
10. Code blocks
|
|
97
|
+
|
|
98
|
+
## Code Example
|
|
99
|
+
|
|
100
|
+
Here's some JavaScript code:
|
|
101
|
+
|
|
102
|
+
\`\`\`javascript
|
|
103
|
+
function fibonacci(n) {
|
|
104
|
+
if (n <= 1) return n;
|
|
105
|
+
return fibonacci(n - 1) + fibonacci(n - 2);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
console.log(fibonacci(10)); // 55
|
|
109
|
+
\`\`\`
|
|
110
|
+
|
|
111
|
+
## Table Example
|
|
112
|
+
|
|
113
|
+
| Name | Age | City |
|
|
114
|
+
|------|-----|------|
|
|
115
|
+
| John | 30 | New York |
|
|
116
|
+
| Jane | 25 | Boston |
|
|
117
|
+
| Bob | 35 | Chicago |
|
|
118
|
+
|
|
119
|
+
## Blockquote Example
|
|
120
|
+
|
|
121
|
+
> This is a blockquote.
|
|
122
|
+
>
|
|
123
|
+
> It can span multiple lines.
|
|
124
|
+
>
|
|
125
|
+
> > It can also contain nested blockquotes.
|
|
126
|
+
|
|
127
|
+
---
|
|
128
|
+
|
|
129
|
+
## List Examples
|
|
130
|
+
|
|
131
|
+
### Unordered List
|
|
132
|
+
|
|
133
|
+
- Item 1
|
|
134
|
+
- Item 2
|
|
135
|
+
- Nested item 2.1
|
|
136
|
+
- Nested item 2.2
|
|
137
|
+
- Double nested item 2.2.1
|
|
138
|
+
- Item 3
|
|
139
|
+
|
|
140
|
+
### Ordered List
|
|
141
|
+
|
|
142
|
+
1. First item
|
|
143
|
+
2. Second item
|
|
144
|
+
1. Nested item 2.1
|
|
145
|
+
2. Nested item 2.2
|
|
146
|
+
1. Double nested item 2.2.1
|
|
147
|
+
3. Third item
|
|
148
|
+
|
|
149
|
+
## Inline Elements
|
|
150
|
+
|
|
151
|
+
This paragraph contains **bold text**, *italic text*, \`inline code\`,
|
|
152
|
+
~~strikethrough text~~, [a link](https://example.com), and .
|
|
153
|
+
|
|
154
|
+
The end of this complex example.
|
|
155
|
+
`;
|
|
156
|
+
terminal.header("Complex Markdown Example");
|
|
157
|
+
terminal.display(complexMarkdown);
|
|
158
|
+
// Test other terminal features
|
|
159
|
+
terminal.header("Other Terminal Features");
|
|
160
|
+
// Box display
|
|
161
|
+
terminal.box("Info Box", "This is content inside a box with a header");
|
|
162
|
+
terminal.box("Code", `
|
|
163
|
+
\`\`\`javascript
|
|
164
|
+
function fibonacci(n) {
|
|
165
|
+
if (n <= 1) return n;
|
|
166
|
+
return fibonacci(n - 1) + fibonacci(n - 2);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
console.log(fibonacci(10)); // 55
|
|
170
|
+
\`\`\`
|
|
171
|
+
`);
|
|
172
|
+
terminal.box("Markdown Block", `
|
|
173
|
+
This paragraph contains **bold text**, *italic text*, \`inline code\`,
|
|
174
|
+
~~strikethrough text~~, [a link](https://example.com), and .
|
|
175
|
+
`);
|
|
176
|
+
// Horizontal rule
|
|
177
|
+
terminal.hr();
|
|
178
|
+
// Table
|
|
179
|
+
terminal.table([
|
|
180
|
+
["Headers", "Working"],
|
|
181
|
+
["Text Formatting", "Working"],
|
|
182
|
+
["Lists", "Working"],
|
|
183
|
+
["Code Blocks", "Working"],
|
|
184
|
+
["Tables", "Working"],
|
|
185
|
+
["Links", "Working"],
|
|
186
|
+
["Images", "Working"],
|
|
187
|
+
["Blockquotes", "Working"],
|
|
188
|
+
], { header: ["Feature", "Status"] });
|
|
189
|
+
// Progress bar
|
|
190
|
+
terminal.header("Progress Bar Example");
|
|
191
|
+
for (let i = 0; i <= 100; i += 10) {
|
|
192
|
+
terminal.displayProgressBar(i, 100);
|
|
193
|
+
}
|
|
194
|
+
// Spinner (demonstration)
|
|
195
|
+
// terminal.header("Spinner Example");
|
|
196
|
+
// const spinner = terminal.spinner("Loading...");
|
|
197
|
+
// setTimeout(() => {
|
|
198
|
+
// spinner.succeed("Loading complete!");
|
|
199
|
+
// }, 2000);
|
|
200
|
+
// Terminal info
|
|
201
|
+
terminal.header("Terminal Information");
|
|
202
|
+
terminal.writeln(`Terminal size: ${terminal["terminalWidth"]}x${terminal["terminalHeight"]}`);
|
|
203
|
+
terminal.writeln(`Is interactive: ${terminal["isInteractive"]}`);
|
|
204
|
+
// Link example
|
|
205
|
+
terminal.header("Link Example");
|
|
206
|
+
terminal.writeln(`Visit ${terminal.link("Google", "https://google.com")} for search`);
|
|
207
|
+
// Alert
|
|
208
|
+
terminal.alert();
|
|
209
|
+
// Final message
|
|
210
|
+
terminal.success("All terminal features tested successfully!");
|
|
211
|
+
}
|
|
212
|
+
// Run the test
|
|
213
|
+
testTerminalOutput();
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
#!/usr/bin/env -S node --no-warnings
|
|
2
|
+
/**
|
|
3
|
+
* Terminal Output Test Module
|
|
4
|
+
*
|
|
5
|
+
* Exercises all methods and features of the Terminal class for testing purposes.
|
|
6
|
+
* Demonstrates various markdown rendering capabilities.
|
|
7
|
+
*/
|
|
8
|
+
import { initTerminal } from "./terminal/index.js";
|
|
9
|
+
// Initialize terminal
|
|
10
|
+
const terminal = initTerminal({
|
|
11
|
+
useColors: true,
|
|
12
|
+
showProgressIndicators: true,
|
|
13
|
+
});
|
|
14
|
+
// Test all terminal methods and features
|
|
15
|
+
function testTerminalOutput() {
|
|
16
|
+
// Clear screen and show welcome
|
|
17
|
+
terminal.clear();
|
|
18
|
+
terminal.displayWelcome();
|
|
19
|
+
// Test basic output methods
|
|
20
|
+
terminal.header("Basic Output Methods");
|
|
21
|
+
terminal.writeln("This is a basic write line");
|
|
22
|
+
terminal.write("This is a basic write without newline");
|
|
23
|
+
terminal.lineBreak();
|
|
24
|
+
terminal.emphasize("This is emphasized text");
|
|
25
|
+
terminal.info("This is an info message");
|
|
26
|
+
terminal.success("This is a success message");
|
|
27
|
+
terminal.warn("This is a warning message");
|
|
28
|
+
terminal.error("This is an error message");
|
|
29
|
+
terminal.lineBreak();
|
|
30
|
+
// Test markdown display
|
|
31
|
+
terminal.header("Markdown Display Features");
|
|
32
|
+
// Headers
|
|
33
|
+
terminal.display("# This is an H1 Header");
|
|
34
|
+
terminal.display("## This is an H2 Header");
|
|
35
|
+
terminal.display("### This is an H3 Header");
|
|
36
|
+
terminal.display("#### This is an H4 Header");
|
|
37
|
+
terminal.display("##### This is an H5 Header");
|
|
38
|
+
terminal.display("###### This is an H6 Header");
|
|
39
|
+
// Text formatting
|
|
40
|
+
terminal.display("**This is bold text**");
|
|
41
|
+
terminal.display("*This is italic text*");
|
|
42
|
+
terminal.display("***This is bold and italic text***");
|
|
43
|
+
terminal.display("This is `inline code` text");
|
|
44
|
+
terminal.display("~~This is strikethrough text~~");
|
|
45
|
+
// Links
|
|
46
|
+
terminal.display("This is a [link](https://example.com)");
|
|
47
|
+
// Images
|
|
48
|
+
terminal.display("This is an ");
|
|
49
|
+
// Blockquotes
|
|
50
|
+
terminal.display("> This is a blockquote");
|
|
51
|
+
terminal.display("> This is a\n> multi-line blockquote");
|
|
52
|
+
// Horizontal rule
|
|
53
|
+
terminal.display("---");
|
|
54
|
+
// Lists
|
|
55
|
+
terminal.display("- This is an unordered list item");
|
|
56
|
+
terminal.display("- This is another unordered list item");
|
|
57
|
+
terminal.display(" - This is a nested list item");
|
|
58
|
+
terminal.display(" - This is a double nested list item");
|
|
59
|
+
terminal.display("1. This is an ordered list item");
|
|
60
|
+
terminal.display("2. This is another ordered list item");
|
|
61
|
+
terminal.display(" 1. This is a nested ordered list item");
|
|
62
|
+
terminal.display(" 2. This is another nested ordered list item");
|
|
63
|
+
// Code blocks
|
|
64
|
+
terminal.display("```javascript\nconst greeting = 'Hello World';\nconsole.log(greeting);\n```");
|
|
65
|
+
terminal.display("```python\ndef hello():\n print('Hello World')\n```");
|
|
66
|
+
terminal.display("```\nThis is a plain code block\n```");
|
|
67
|
+
// Tables
|
|
68
|
+
terminal.display("| Header 1 | Header 2 | Header 3 |\n|----------|----------|----------|\n| Cell 1 | Cell 2 | Cell 3 |\n| Cell 4 | Cell 5 | Cell 6 |");
|
|
69
|
+
// Paragraphs
|
|
70
|
+
terminal.display("This is a paragraph with some **bold** and *italic* text. " +
|
|
71
|
+
"It also contains `inline code` and a [link](https://example.com). " +
|
|
72
|
+
"Here's an  for good measure.");
|
|
73
|
+
terminal.display("This is another paragraph that demonstrates how line breaks work " +
|
|
74
|
+
"in markdown with the terminal display. It should wrap appropriately based " +
|
|
75
|
+
"on the terminal width.");
|
|
76
|
+
// Complex markdown example
|
|
77
|
+
const complexMarkdown = `
|
|
78
|
+
# Complex Markdown Example
|
|
79
|
+
|
|
80
|
+
This is a complex example showing various **markdown** features in *one* document.
|
|
81
|
+
|
|
82
|
+
## Features Demonstrated
|
|
83
|
+
|
|
84
|
+
1. **Headers** of different levels
|
|
85
|
+
2. *Text formatting* options
|
|
86
|
+
3. \`Code elements\` of various types
|
|
87
|
+
4. [External links](https://example.com)
|
|
88
|
+
5. 
|
|
89
|
+
6. Blockquotes
|
|
90
|
+
|
|
91
|
+
> Blockquotes
|
|
92
|
+
|
|
93
|
+
7. Horizontal rules
|
|
94
|
+
8. Lists (ordered and unordered)
|
|
95
|
+
9. Tables
|
|
96
|
+
10. Code blocks
|
|
97
|
+
|
|
98
|
+
## Code Example
|
|
99
|
+
|
|
100
|
+
Here's some JavaScript code:
|
|
101
|
+
|
|
102
|
+
\`\`\`javascript
|
|
103
|
+
function fibonacci(n) {
|
|
104
|
+
if (n <= 1) return n;
|
|
105
|
+
return fibonacci(n - 1) + fibonacci(n - 2);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
console.log(fibonacci(10)); // 55
|
|
109
|
+
\`\`\`
|
|
110
|
+
|
|
111
|
+
## Table Example
|
|
112
|
+
|
|
113
|
+
| Name | Age | City |
|
|
114
|
+
|------|-----|------|
|
|
115
|
+
| John | 30 | New York |
|
|
116
|
+
| Jane | 25 | Boston |
|
|
117
|
+
| Bob | 35 | Chicago |
|
|
118
|
+
|
|
119
|
+
## Blockquote Example
|
|
120
|
+
|
|
121
|
+
> This is a blockquote.
|
|
122
|
+
>
|
|
123
|
+
> It can span multiple lines.
|
|
124
|
+
>
|
|
125
|
+
> > It can also contain nested blockquotes.
|
|
126
|
+
|
|
127
|
+
---
|
|
128
|
+
|
|
129
|
+
## List Examples
|
|
130
|
+
|
|
131
|
+
### Unordered List
|
|
132
|
+
|
|
133
|
+
- Item 1
|
|
134
|
+
- Item 2
|
|
135
|
+
- Nested item 2.1
|
|
136
|
+
- Nested item 2.2
|
|
137
|
+
- Double nested item 2.2.1
|
|
138
|
+
- Item 3
|
|
139
|
+
|
|
140
|
+
### Ordered List
|
|
141
|
+
|
|
142
|
+
1. First item
|
|
143
|
+
2. Second item
|
|
144
|
+
1. Nested item 2.1
|
|
145
|
+
2. Nested item 2.2
|
|
146
|
+
1. Double nested item 2.2.1
|
|
147
|
+
3. Third item
|
|
148
|
+
|
|
149
|
+
## Inline Elements
|
|
150
|
+
|
|
151
|
+
This paragraph contains **bold text**, *italic text*, \`inline code\`,
|
|
152
|
+
~~strikethrough text~~, [a link](https://example.com), and .
|
|
153
|
+
|
|
154
|
+
The end of this complex example.
|
|
155
|
+
`;
|
|
156
|
+
terminal.header("Complex Markdown Example");
|
|
157
|
+
terminal.display(complexMarkdown);
|
|
158
|
+
// Test other terminal features
|
|
159
|
+
terminal.header("Other Terminal Features");
|
|
160
|
+
// Box display
|
|
161
|
+
terminal.box("Info Box", "This is content inside a box with a header");
|
|
162
|
+
terminal.box("Code", `
|
|
163
|
+
\`\`\`javascript
|
|
164
|
+
function fibonacci(n) {
|
|
165
|
+
if (n <= 1) return n;
|
|
166
|
+
return fibonacci(n - 1) + fibonacci(n - 2);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
console.log(fibonacci(10)); // 55
|
|
170
|
+
\`\`\`
|
|
171
|
+
`);
|
|
172
|
+
terminal.box("Markdown Block", `
|
|
173
|
+
This paragraph contains **bold text**, *italic text*, \`inline code\`,
|
|
174
|
+
~~strikethrough text~~, [a link](https://example.com), and .
|
|
175
|
+
`);
|
|
176
|
+
// Horizontal rule
|
|
177
|
+
terminal.hr();
|
|
178
|
+
// Table
|
|
179
|
+
terminal.table([
|
|
180
|
+
["Headers", "Working"],
|
|
181
|
+
["Text Formatting", "Working"],
|
|
182
|
+
["Lists", "Working"],
|
|
183
|
+
["Code Blocks", "Working"],
|
|
184
|
+
["Tables", "Working"],
|
|
185
|
+
["Links", "Working"],
|
|
186
|
+
["Images", "Working"],
|
|
187
|
+
["Blockquotes", "Working"],
|
|
188
|
+
], { header: ["Feature", "Status"] });
|
|
189
|
+
// Progress bar
|
|
190
|
+
terminal.header("Progress Bar Example");
|
|
191
|
+
for (let i = 0; i <= 100; i += 10) {
|
|
192
|
+
terminal.displayProgressBar(i, 100);
|
|
193
|
+
}
|
|
194
|
+
// Spinner (demonstration)
|
|
195
|
+
// terminal.header("Spinner Example");
|
|
196
|
+
// const spinner = terminal.spinner("Loading...");
|
|
197
|
+
// setTimeout(() => {
|
|
198
|
+
// spinner.succeed("Loading complete!");
|
|
199
|
+
// }, 2000);
|
|
200
|
+
// Terminal info
|
|
201
|
+
terminal.header("Terminal Information");
|
|
202
|
+
terminal.writeln(`Terminal size: ${terminal["terminalWidth"]}x${terminal["terminalHeight"]}`);
|
|
203
|
+
terminal.writeln(`Is interactive: ${terminal["isInteractive"]}`);
|
|
204
|
+
// Link example
|
|
205
|
+
terminal.header("Link Example");
|
|
206
|
+
terminal.writeln(`Visit ${terminal.link("Google", "https://google.com")} for search`);
|
|
207
|
+
// Alert
|
|
208
|
+
terminal.alert();
|
|
209
|
+
// Final message
|
|
210
|
+
terminal.success("All terminal features tested successfully!");
|
|
211
|
+
}
|
|
212
|
+
// Run the test
|
|
213
|
+
testTerminalOutput();
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { EventEmitter } from "node:events";
|
|
2
|
+
import type { LanguageModelUsage } from "ai";
|
|
3
|
+
interface TokenTrackerEvents {
|
|
4
|
+
usage: [LanguageModelUsage];
|
|
5
|
+
}
|
|
6
|
+
export declare class TokenTracker extends EventEmitter<TokenTrackerEvents> {
|
|
7
|
+
private usages;
|
|
8
|
+
trackUsage(tool: string, usage: LanguageModelUsage | undefined): void;
|
|
9
|
+
getTotalUsage(): LanguageModelUsage;
|
|
10
|
+
getUsageByApp(app: string): LanguageModelUsage;
|
|
11
|
+
getUsageBreakdown(): Record<string, number>;
|
|
12
|
+
printSummary(): void;
|
|
13
|
+
}
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { EventEmitter } from "node:events";
|
|
2
|
+
import { isNumber } from "@travisennis/stdlib/typeguards";
|
|
3
|
+
export class TokenTracker extends EventEmitter {
|
|
4
|
+
usages = [];
|
|
5
|
+
trackUsage(tool, usage) {
|
|
6
|
+
if (usage) {
|
|
7
|
+
const u = { tool, usage };
|
|
8
|
+
this.usages.push(u);
|
|
9
|
+
this.emit("usage", usage);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
getTotalUsage() {
|
|
13
|
+
return this.usages.reduce((acc, { usage }) => {
|
|
14
|
+
acc.inputTokens += isNumber(usage.inputTokens) ? usage.inputTokens : 0;
|
|
15
|
+
acc.outputTokens += isNumber(usage.outputTokens)
|
|
16
|
+
? usage.outputTokens
|
|
17
|
+
: 0;
|
|
18
|
+
acc.totalTokens += isNumber(usage.totalTokens) ? usage.totalTokens : 0;
|
|
19
|
+
return acc;
|
|
20
|
+
}, { inputTokens: 0, outputTokens: 0, totalTokens: 0 });
|
|
21
|
+
}
|
|
22
|
+
getUsageByApp(app) {
|
|
23
|
+
return this.usages
|
|
24
|
+
.filter(({ tool }) => tool === app)
|
|
25
|
+
.reduce((acc, { usage }) => {
|
|
26
|
+
acc.inputTokens += isNumber(usage.inputTokens)
|
|
27
|
+
? usage.inputTokens
|
|
28
|
+
: 0;
|
|
29
|
+
acc.outputTokens += isNumber(usage.outputTokens)
|
|
30
|
+
? usage.outputTokens
|
|
31
|
+
: 0;
|
|
32
|
+
acc.totalTokens += isNumber(usage.totalTokens)
|
|
33
|
+
? usage.totalTokens
|
|
34
|
+
: 0;
|
|
35
|
+
return acc;
|
|
36
|
+
}, { inputTokens: 0, outputTokens: 0, totalTokens: 0 });
|
|
37
|
+
}
|
|
38
|
+
getUsageBreakdown() {
|
|
39
|
+
return this.usages.reduce((acc, { tool, usage }) => {
|
|
40
|
+
acc[tool] =
|
|
41
|
+
(acc[tool] || 0) +
|
|
42
|
+
(isNumber(usage.totalTokens) ? usage.totalTokens : 0);
|
|
43
|
+
return acc;
|
|
44
|
+
}, {});
|
|
45
|
+
}
|
|
46
|
+
printSummary() {
|
|
47
|
+
const breakdown = this.getUsageBreakdown();
|
|
48
|
+
console.info("Token Usage Summary:", {
|
|
49
|
+
total: this.getTotalUsage(),
|
|
50
|
+
breakdown,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { encoding_for_model } from "tiktoken";
|
|
2
|
+
export class TokenCounter {
|
|
3
|
+
tiktokenEncoding;
|
|
4
|
+
constructor(model = "chatgpt-4o-latest") {
|
|
5
|
+
this.tiktokenEncoding = encoding_for_model(model);
|
|
6
|
+
}
|
|
7
|
+
count(input) {
|
|
8
|
+
return this.tiktokenEncoding.encode(input).length;
|
|
9
|
+
}
|
|
10
|
+
free() {
|
|
11
|
+
this.tiktokenEncoding.free();
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ModelManager } from "../models/manager.ts";
|
|
2
|
+
import type { TokenTracker } from "../token-tracker.ts";
|
|
3
|
+
import type { TokenCounter } from "../token-utils.ts";
|
|
4
|
+
import type { SendData } from "./types.ts";
|
|
5
|
+
export declare const AgentTool: {
|
|
6
|
+
name: "agent";
|
|
7
|
+
};
|
|
8
|
+
export declare const createAgentTools: (options: {
|
|
9
|
+
modelManager: ModelManager;
|
|
10
|
+
tokenTracker: TokenTracker;
|
|
11
|
+
tokenCounter: TokenCounter;
|
|
12
|
+
sendData?: SendData | undefined;
|
|
13
|
+
}) => {
|
|
14
|
+
agent: import("ai").Tool<{
|
|
15
|
+
prompt: string;
|
|
16
|
+
}, string>;
|
|
17
|
+
};
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { generateText, stepCountIs, tool } from "ai";
|
|
2
|
+
import chalk from "chalk";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { AiConfig } from "../models/ai-config.js";
|
|
5
|
+
import { BashTool } from "./bash.js";
|
|
6
|
+
import { DirectoryTreeTool } from "./directory-tree.js";
|
|
7
|
+
import { GrepTool } from "./grep.js";
|
|
8
|
+
import { initCliTools } from "./index.js";
|
|
9
|
+
import { ReadFileTool } from "./read-file.js";
|
|
10
|
+
import { ReadMultipleFilesTool } from "./read-multiple-files.js";
|
|
11
|
+
export const AgentTool = {
|
|
12
|
+
name: "agent",
|
|
13
|
+
};
|
|
14
|
+
const TOOLS = [
|
|
15
|
+
GrepTool.name,
|
|
16
|
+
BashTool.name,
|
|
17
|
+
ReadFileTool.name,
|
|
18
|
+
ReadMultipleFilesTool.name,
|
|
19
|
+
DirectoryTreeTool.name,
|
|
20
|
+
];
|
|
21
|
+
function getToolDescription() {
|
|
22
|
+
const toolNames = TOOLS.join(", ");
|
|
23
|
+
return `Launch a new agent that has access to the following tools: ${toolNames}. When you are searching for a keyword or file and are not confident that you will find the right match on the first try, use the ${AgentTool.name} tool to perform the search for you. For example:
|
|
24
|
+
|
|
25
|
+
- If you are searching for a keyword like "config" or "logger", the ${AgentTool.name} tool is appropriate
|
|
26
|
+
- If you want to read a specific file path, use the ${ReadFileTool.name} or appropriate command via the ${BashTool.name} tool instead of this tool, to find the match more quickly
|
|
27
|
+
- If you are searching for a specific class definition like "class Foo", use the ${GrepTool.name} tool instead, to find the match more quickly
|
|
28
|
+
|
|
29
|
+
Usage notes:
|
|
30
|
+
1. Launch multiple agents concurrently whenever possible, to maximize performance; to do that, use a single message with multiple tool uses
|
|
31
|
+
2. When the agent is done, it will return a single message back to you. The result returned by the agent is not visible to the user. To show the user the result, you should send a text message back to the user with a concise summary of the result.
|
|
32
|
+
3. Each agent invocation is stateless. You will not be able to send additional messages to the agent, nor will the agent be able to communicate with you outside of its final report. Therefore, your prompt should contain a highly detailed task description for the agent to perform autonomously and you should specify exactly what information the agent should return back to you in its final and only message to you.
|
|
33
|
+
4. The agent's outputs should generally be trusted.`;
|
|
34
|
+
}
|
|
35
|
+
const inputSchema = z.object({
|
|
36
|
+
prompt: z.string().describe("The task for the agent to perform"),
|
|
37
|
+
});
|
|
38
|
+
export const createAgentTools = (options) => {
|
|
39
|
+
const { modelManager, tokenTracker, tokenCounter, sendData } = options;
|
|
40
|
+
return {
|
|
41
|
+
[AgentTool.name]: tool({
|
|
42
|
+
description: getToolDescription(),
|
|
43
|
+
inputSchema: inputSchema,
|
|
44
|
+
execute: async ({ prompt }, { abortSignal, toolCallId }) => {
|
|
45
|
+
sendData?.({
|
|
46
|
+
event: "tool-init",
|
|
47
|
+
id: toolCallId,
|
|
48
|
+
data: `Initializing agent with prompt: ${chalk.cyan(prompt)}`,
|
|
49
|
+
});
|
|
50
|
+
try {
|
|
51
|
+
const modelConfig = modelManager.getModelMetadata("task-agent");
|
|
52
|
+
const aiConfig = new AiConfig({
|
|
53
|
+
modelMetadata: modelConfig,
|
|
54
|
+
prompt: prompt,
|
|
55
|
+
});
|
|
56
|
+
const { text, usage } = await generateText({
|
|
57
|
+
model: modelManager.getModel("task-agent"),
|
|
58
|
+
maxOutputTokens: aiConfig.getMaxTokens(),
|
|
59
|
+
system: "You are a code search assistant that will be given a task that will require you to search a code base to find relevant code and files.",
|
|
60
|
+
prompt: prompt,
|
|
61
|
+
stopWhen: stepCountIs(30),
|
|
62
|
+
providerOptions: aiConfig.getProviderOptions(),
|
|
63
|
+
tools: await initCliTools({ tokenCounter }),
|
|
64
|
+
abortSignal: abortSignal,
|
|
65
|
+
// biome-ignore lint/style/useNamingConvention: third-party code
|
|
66
|
+
experimental_activeTools: [...TOOLS],
|
|
67
|
+
});
|
|
68
|
+
tokenTracker.trackUsage("task-agent", usage);
|
|
69
|
+
sendData?.({
|
|
70
|
+
event: "tool-completion",
|
|
71
|
+
id: toolCallId,
|
|
72
|
+
data: "Finished running the agent tool.",
|
|
73
|
+
});
|
|
74
|
+
return text;
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
sendData?.({
|
|
78
|
+
event: "tool-error",
|
|
79
|
+
id: toolCallId,
|
|
80
|
+
data: "Error running agent tool.",
|
|
81
|
+
});
|
|
82
|
+
return Promise.resolve(error.message);
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
}),
|
|
86
|
+
};
|
|
87
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Terminal } from "../terminal/index.ts";
|
|
2
|
+
import type { TokenCounter } from "../token-utils.ts";
|
|
3
|
+
import type { SendData } from "./types.ts";
|
|
4
|
+
export declare const BashTool: {
|
|
5
|
+
name: "bash";
|
|
6
|
+
};
|
|
7
|
+
export declare const createBashTool: ({ baseDir, sendData, tokenCounter, terminal, autoAcceptAll, }: {
|
|
8
|
+
baseDir: string;
|
|
9
|
+
sendData?: SendData | undefined;
|
|
10
|
+
tokenCounter: TokenCounter;
|
|
11
|
+
terminal?: Terminal;
|
|
12
|
+
autoAcceptAll: boolean;
|
|
13
|
+
}) => {
|
|
14
|
+
bash: import("ai").Tool<{
|
|
15
|
+
command: string;
|
|
16
|
+
cwd: string | null;
|
|
17
|
+
timeout: number | null;
|
|
18
|
+
}, string>;
|
|
19
|
+
};
|