@travisennis/acai 0.0.9 → 0.0.11
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 +51 -760
- package/bin/acai +52 -0
- package/dist/agent/index.d.ts +12 -2
- package/dist/agent/index.d.ts.map +1 -1
- package/dist/agent/index.js +380 -199
- package/dist/agent/sub-agent.d.ts +23 -0
- package/dist/agent/sub-agent.d.ts.map +1 -0
- package/dist/agent/sub-agent.js +109 -0
- package/dist/cli/index.d.ts +26 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/{cli.js → cli/index.js} +84 -77
- package/dist/{stdin.d.ts → cli/stdin.d.ts} +2 -1
- package/dist/cli/stdin.d.ts.map +1 -0
- package/dist/{stdin.js → cli/stdin.js} +11 -0
- package/dist/commands/copy/index.js +2 -2
- package/dist/commands/copy/utils.d.ts.map +1 -1
- package/dist/commands/copy/utils.js +15 -13
- package/dist/commands/generate-rules/index.d.ts +1 -1
- package/dist/commands/generate-rules/index.d.ts.map +1 -1
- package/dist/commands/generate-rules/index.js +16 -101
- package/dist/commands/generate-rules/service.d.ts +22 -0
- package/dist/commands/generate-rules/service.d.ts.map +1 -0
- package/dist/commands/generate-rules/service.js +103 -0
- package/dist/commands/handoff/index.js +2 -2
- package/dist/commands/health/index.js +1 -1
- package/dist/commands/health/utils.d.ts +3 -2
- package/dist/commands/health/utils.d.ts.map +1 -1
- package/dist/commands/health/utils.js +6 -0
- package/dist/commands/history/index.d.ts +1 -1
- package/dist/commands/history/index.d.ts.map +1 -1
- package/dist/commands/history/index.js +17 -18
- package/dist/commands/history/types.d.ts +38 -0
- package/dist/commands/history/types.d.ts.map +1 -1
- package/dist/commands/history/utils.d.ts.map +1 -1
- package/dist/commands/history/utils.js +63 -58
- package/dist/commands/init/index.d.ts.map +1 -1
- package/dist/commands/init/index.js +3 -8
- package/dist/commands/init-project/index.d.ts.map +1 -1
- package/dist/commands/init-project/index.js +3 -3
- package/dist/commands/init-project/utils.d.ts +2 -1
- package/dist/commands/init-project/utils.d.ts.map +1 -1
- package/dist/commands/init-project/utils.js +10 -2
- package/dist/commands/list-tools/index.d.ts.map +1 -1
- package/dist/commands/list-tools/index.js +7 -31
- package/dist/commands/manager.d.ts +2 -2
- package/dist/commands/manager.d.ts.map +1 -1
- package/dist/commands/manager.js +55 -33
- package/dist/commands/model/index.d.ts.map +1 -1
- package/dist/commands/model/index.js +20 -151
- package/dist/commands/model/model-panel.d.ts +4 -0
- package/dist/commands/model/model-panel.d.ts.map +1 -0
- package/dist/commands/model/model-panel.js +144 -0
- package/dist/commands/paste/index.d.ts.map +1 -1
- package/dist/commands/paste/index.js +59 -62
- package/dist/commands/paste/utils.d.ts.map +1 -1
- package/dist/commands/paste/utils.js +88 -58
- package/dist/commands/pickup/index.d.ts.map +1 -1
- package/dist/commands/pickup/index.js +6 -3
- package/dist/commands/pickup/utils.js +3 -3
- package/dist/commands/resources/index.d.ts.map +1 -1
- package/dist/commands/resources/index.js +33 -50
- package/dist/commands/review/index.d.ts.map +1 -1
- package/dist/commands/review/index.js +3 -117
- package/dist/commands/review/review-panel.d.ts +3 -0
- package/dist/commands/review/review-panel.d.ts.map +1 -0
- package/dist/commands/review/review-panel.js +186 -0
- package/dist/commands/review/utils.d.ts +15 -1
- package/dist/commands/review/utils.d.ts.map +1 -1
- package/dist/commands/review/utils.js +127 -68
- package/dist/commands/session/index.d.ts +1 -1
- package/dist/commands/session/index.d.ts.map +1 -1
- package/dist/commands/session/index.js +124 -135
- package/dist/commands/shell/index.d.ts.map +1 -1
- package/dist/commands/shell/index.js +16 -1
- package/dist/commands/types.d.ts +2 -2
- package/dist/commands/types.d.ts.map +1 -1
- package/dist/{config.d.ts → config/index.d.ts} +20 -9
- package/dist/config/index.d.ts.map +1 -0
- package/dist/{config.js → config/index.js} +43 -42
- package/dist/execution/index.d.ts.map +1 -1
- package/dist/execution/index.js +75 -55
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +148 -141
- package/dist/middleware/cache.d.ts.map +1 -1
- package/dist/middleware/cache.js +18 -36
- package/dist/models/ai-config.d.ts +1 -0
- package/dist/models/ai-config.d.ts.map +1 -1
- package/dist/models/ai-config.js +4 -3
- package/dist/models/anthropic-provider.d.ts +2 -5
- package/dist/models/anthropic-provider.d.ts.map +1 -1
- package/dist/models/anthropic-provider.js +3 -70
- package/dist/models/deepseek-provider.d.ts +1 -0
- package/dist/models/deepseek-provider.d.ts.map +1 -1
- package/dist/models/google-provider.d.ts +2 -3
- package/dist/models/google-provider.d.ts.map +1 -1
- package/dist/models/google-provider.js +0 -26
- package/dist/models/groq-provider.d.ts +1 -0
- package/dist/models/groq-provider.d.ts.map +1 -1
- package/dist/models/manager.d.ts +13 -2
- package/dist/models/manager.d.ts.map +1 -1
- package/dist/models/manager.js +20 -8
- package/dist/models/openai-provider.d.ts +2 -5
- package/dist/models/openai-provider.d.ts.map +1 -1
- package/dist/models/openai-provider.js +0 -52
- package/dist/models/opencode-go-provider.d.ts +25 -0
- package/dist/models/opencode-go-provider.d.ts.map +1 -0
- package/dist/models/opencode-go-provider.js +78 -0
- package/dist/models/opencode-zen-provider.d.ts +7 -3
- package/dist/models/opencode-zen-provider.d.ts.map +1 -1
- package/dist/models/opencode-zen-provider.js +49 -10
- package/dist/models/openrouter-provider.d.ts +27 -31
- package/dist/models/openrouter-provider.d.ts.map +1 -1
- package/dist/models/openrouter-provider.js +121 -180
- package/dist/models/providers.d.ts +3 -3
- package/dist/models/providers.d.ts.map +1 -1
- package/dist/models/providers.js +6 -0
- package/dist/models/xai-provider.d.ts +4 -3
- package/dist/models/xai-provider.d.ts.map +1 -1
- package/dist/models/xai-provider.js +18 -18
- package/dist/modes/manager.d.ts +24 -0
- package/dist/modes/manager.d.ts.map +1 -0
- package/dist/modes/manager.js +77 -0
- package/dist/modes/prompts.d.ts +2 -0
- package/dist/modes/prompts.d.ts.map +1 -0
- package/dist/modes/prompts.js +142 -0
- package/dist/prompts/mentions.d.ts +11 -0
- package/dist/prompts/mentions.d.ts.map +1 -0
- package/dist/{mentions.js → prompts/mentions.js} +55 -85
- package/dist/{prompts.d.ts → prompts/system-prompt.d.ts} +7 -2
- package/dist/prompts/system-prompt.d.ts.map +1 -0
- package/dist/{prompts.js → prompts/system-prompt.js} +31 -16
- package/dist/repl/index.d.ts +174 -0
- package/dist/repl/index.d.ts.map +1 -0
- package/dist/{repl-new.js → repl/index.js} +397 -76
- package/dist/repl/project-status.d.ts +1 -0
- package/dist/repl/project-status.d.ts.map +1 -1
- package/dist/repl/project-status.js +4 -1
- package/dist/sessions/manager.d.ts +92 -0
- package/dist/sessions/manager.d.ts.map +1 -1
- package/dist/sessions/manager.js +262 -9
- package/dist/sessions/summary.d.ts +4 -0
- package/dist/sessions/summary.d.ts.map +1 -0
- package/dist/sessions/summary.js +30 -0
- package/dist/skills/index.d.ts +29 -0
- package/dist/skills/index.d.ts.map +1 -0
- package/dist/skills/index.js +294 -0
- package/dist/subagents/index.d.ts +16 -0
- package/dist/subagents/index.d.ts.map +1 -0
- package/dist/subagents/index.js +231 -0
- package/dist/terminal/control.d.ts +1 -1
- package/dist/terminal/control.d.ts.map +1 -1
- package/dist/terminal/control.js +3 -3
- package/dist/terminal/east-asian-width.d.ts.map +1 -1
- package/dist/terminal/east-asian-width.js +404 -351
- package/dist/terminal/keys.d.ts +17 -0
- package/dist/terminal/keys.d.ts.map +1 -1
- package/dist/terminal/keys.js +37 -0
- package/dist/terminal/select-prompt.d.ts.map +1 -1
- package/dist/terminal/select-prompt.js +24 -12
- package/dist/terminal/string-width.d.ts.map +1 -1
- package/dist/terminal/string-width.js +25 -27
- package/dist/terminal/style.d.ts.map +1 -1
- package/dist/terminal/style.js +4 -7
- package/dist/terminal/supports-color.d.ts.map +1 -1
- package/dist/terminal/supports-color.js +41 -27
- package/dist/terminal/table/cell.d.ts +12 -0
- package/dist/terminal/table/cell.d.ts.map +1 -1
- package/dist/terminal/table/cell.js +40 -25
- package/dist/terminal/table/layout-manager.d.ts.map +1 -1
- package/dist/terminal/table/layout-manager.js +100 -68
- package/dist/terminal/table/utils.d.ts +1 -1
- package/dist/terminal/table/utils.d.ts.map +1 -1
- package/dist/terminal/table/utils.js +17 -10
- package/dist/terminal/wrap-ansi.d.ts.map +1 -1
- package/dist/terminal/wrap-ansi.js +174 -105
- package/dist/tokens/tracker.d.ts +1 -0
- package/dist/tokens/tracker.d.ts.map +1 -1
- package/dist/tokens/tracker.js +3 -0
- package/dist/tools/agent.d.ts +27 -0
- package/dist/tools/agent.d.ts.map +1 -0
- package/dist/tools/agent.js +81 -0
- package/dist/tools/apply-patch.d.ts +62 -0
- package/dist/tools/apply-patch.d.ts.map +1 -0
- package/dist/tools/apply-patch.js +377 -0
- package/dist/tools/bash.d.ts +4 -3
- package/dist/tools/bash.d.ts.map +1 -1
- package/dist/tools/bash.js +349 -141
- package/dist/tools/directory-tree.d.ts +3 -3
- package/dist/tools/directory-tree.d.ts.map +1 -1
- package/dist/tools/directory-tree.js +8 -5
- package/dist/tools/dynamic-tool-loader.d.ts +3 -6
- package/dist/tools/dynamic-tool-loader.d.ts.map +1 -1
- package/dist/tools/dynamic-tool-loader.js +20 -4
- package/dist/tools/edit-file.d.ts +7 -7
- package/dist/tools/edit-file.d.ts.map +1 -1
- package/dist/tools/edit-file.js +292 -85
- package/dist/tools/glob.d.ts +6 -6
- package/dist/tools/glob.d.ts.map +1 -1
- package/dist/tools/glob.js +110 -63
- package/dist/tools/grep.d.ts +15 -12
- package/dist/tools/grep.d.ts.map +1 -1
- package/dist/tools/grep.js +315 -193
- package/dist/tools/index.d.ts +114 -9
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +39 -24
- package/dist/tools/ls.d.ts +2 -2
- package/dist/tools/ls.d.ts.map +1 -1
- package/dist/tools/ls.js +7 -5
- package/dist/tools/read-file.d.ts +4 -6
- package/dist/tools/read-file.d.ts.map +1 -1
- package/dist/tools/read-file.js +84 -39
- package/dist/tools/save-file.d.ts +3 -3
- package/dist/tools/save-file.d.ts.map +1 -1
- package/dist/tools/save-file.js +36 -31
- package/dist/tools/skill.d.ts +23 -0
- package/dist/tools/skill.d.ts.map +1 -0
- package/dist/tools/skill.js +65 -0
- package/dist/tools/think.d.ts.map +1 -1
- package/dist/tools/think.js +2 -9
- package/dist/tools/utils.d.ts +2 -0
- package/dist/tools/utils.d.ts.map +1 -1
- package/dist/tools/utils.js +12 -0
- package/dist/tools/web-fetch.d.ts +50 -0
- package/dist/tools/web-fetch.d.ts.map +1 -0
- package/dist/tools/web-fetch.js +446 -0
- package/dist/tools/web-search.d.ts +44 -0
- package/dist/tools/web-search.d.ts.map +1 -0
- package/dist/tools/web-search.js +226 -0
- package/dist/tui/autocomplete/attachment-provider.d.ts +3 -6
- package/dist/tui/autocomplete/attachment-provider.d.ts.map +1 -1
- package/dist/tui/autocomplete/attachment-provider.js +25 -78
- package/dist/tui/autocomplete/base-provider.d.ts +1 -0
- package/dist/tui/autocomplete/base-provider.d.ts.map +1 -1
- package/dist/tui/autocomplete/combined-provider.d.ts +1 -4
- package/dist/tui/autocomplete/combined-provider.d.ts.map +1 -1
- package/dist/tui/autocomplete/combined-provider.js +3 -17
- package/dist/tui/autocomplete/command-provider.d.ts +1 -0
- package/dist/tui/autocomplete/command-provider.d.ts.map +1 -1
- package/dist/tui/autocomplete/command-provider.js +3 -0
- package/dist/tui/autocomplete/file-search-provider.d.ts +2 -1
- package/dist/tui/autocomplete/file-search-provider.d.ts.map +1 -1
- package/dist/tui/autocomplete/file-search-provider.js +37 -17
- package/dist/tui/autocomplete/skill-provider.d.ts +17 -0
- package/dist/tui/autocomplete/skill-provider.d.ts.map +1 -0
- package/dist/tui/autocomplete/skill-provider.js +49 -0
- package/dist/tui/autocomplete/utils.d.ts +2 -1
- package/dist/tui/autocomplete/utils.d.ts.map +1 -1
- package/dist/tui/autocomplete/utils.js +25 -23
- package/dist/tui/autocomplete.d.ts +2 -2
- package/dist/tui/autocomplete.d.ts.map +1 -1
- package/dist/tui/autocomplete.js +3 -5
- package/dist/tui/components/assistant-message.d.ts.map +1 -1
- package/dist/tui/components/assistant-message.js +0 -4
- package/dist/tui/components/editor.d.ts +18 -3
- package/dist/tui/components/editor.d.ts.map +1 -1
- package/dist/tui/components/editor.js +211 -237
- package/dist/tui/components/footer.d.ts +6 -4
- package/dist/tui/components/footer.d.ts.map +1 -1
- package/dist/tui/components/footer.js +49 -25
- package/dist/tui/components/markdown.d.ts +10 -7
- package/dist/tui/components/markdown.d.ts.map +1 -1
- package/dist/tui/components/markdown.js +57 -39
- package/dist/tui/components/modal.d.ts.map +1 -1
- package/dist/tui/components/modal.js +35 -33
- package/dist/tui/components/notification.d.ts +13 -2
- package/dist/tui/components/notification.d.ts.map +1 -1
- package/dist/tui/components/notification.js +36 -2
- package/dist/tui/components/progress-bar.js +1 -1
- package/dist/tui/components/select-list.d.ts +1 -0
- package/dist/tui/components/select-list.d.ts.map +1 -1
- package/dist/tui/components/select-list.js +14 -11
- package/dist/tui/components/text.d.ts +16 -0
- package/dist/tui/components/text.d.ts.map +1 -1
- package/dist/tui/components/text.js +72 -57
- package/dist/tui/components/thinking-block.d.ts +9 -0
- package/dist/tui/components/thinking-block.d.ts.map +1 -1
- package/dist/tui/components/thinking-block.js +43 -11
- package/dist/tui/components/tool-execution.d.ts +5 -1
- package/dist/tui/components/tool-execution.d.ts.map +1 -1
- package/dist/tui/components/tool-execution.js +19 -10
- package/dist/tui/components/user-message.d.ts.map +1 -1
- package/dist/tui/components/user-message.js +0 -3
- package/dist/tui/components/welcome.d.ts +2 -1
- package/dist/tui/components/welcome.d.ts.map +1 -1
- package/dist/tui/components/welcome.js +2 -2
- package/dist/tui/editor-launcher.d.ts +3 -2
- package/dist/tui/editor-launcher.d.ts.map +1 -1
- package/dist/tui/index.d.ts +0 -1
- package/dist/tui/index.d.ts.map +1 -1
- package/dist/tui/terminal.d.ts.map +1 -1
- package/dist/tui/terminal.js +10 -2
- package/dist/tui/tui.d.ts +43 -0
- package/dist/tui/tui.d.ts.map +1 -1
- package/dist/tui/tui.js +166 -41
- package/dist/tui/utils.d.ts +1 -5
- package/dist/tui/utils.d.ts.map +1 -1
- package/dist/tui/utils.js +271 -44
- package/dist/utils/bash/parse.d.ts +19 -0
- package/dist/utils/bash/parse.d.ts.map +1 -0
- package/dist/utils/bash/parse.js +223 -0
- package/dist/utils/bash/quote.d.ts +6 -0
- package/dist/utils/bash/quote.d.ts.map +1 -0
- package/dist/utils/bash/quote.js +23 -0
- package/dist/utils/bash.d.ts.map +1 -1
- package/dist/utils/bash.js +211 -126
- package/dist/utils/command-protection.d.ts +28 -0
- package/dist/utils/command-protection.d.ts.map +1 -0
- package/dist/utils/command-protection.js +324 -0
- package/dist/utils/dedent.d.ts.map +1 -0
- package/dist/utils/env-expand.d.ts +2 -0
- package/dist/utils/env-expand.d.ts.map +1 -0
- package/dist/utils/env-expand.js +8 -0
- package/dist/utils/filesystem/path-display.d.ts +11 -0
- package/dist/utils/filesystem/path-display.d.ts.map +1 -0
- package/dist/utils/filesystem/path-display.js +32 -0
- package/dist/utils/filesystem/security.d.ts +2 -2
- package/dist/utils/filesystem/security.d.ts.map +1 -1
- package/dist/utils/filesystem/security.js +28 -30
- package/dist/utils/formatting.d.ts.map +1 -0
- package/dist/{formatting.js → utils/formatting.js} +1 -1
- package/dist/utils/git.d.ts +4 -0
- package/dist/utils/git.d.ts.map +1 -1
- package/dist/utils/git.js +30 -0
- package/dist/utils/glob.d.ts +1 -1
- package/dist/utils/glob.d.ts.map +1 -1
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/{logger.js → utils/logger.js} +1 -1
- package/dist/utils/parsing.d.ts.map +1 -0
- package/dist/utils/process.d.ts.map +1 -1
- package/dist/utils/process.js +90 -37
- package/dist/utils/templates.d.ts +2 -0
- package/dist/utils/templates.d.ts.map +1 -0
- package/dist/utils/templates.js +24 -0
- package/dist/utils/version.d.ts.map +1 -0
- package/dist/{version.js → utils/version.js} +1 -1
- package/package.json +35 -26
- package/dist/cli.d.ts +0 -23
- package/dist/cli.d.ts.map +0 -1
- package/dist/commands/add-directory/types.d.ts +0 -6
- package/dist/commands/add-directory/types.d.ts.map +0 -1
- package/dist/commands/add-directory/types.js +0 -1
- package/dist/commands/copy/types.d.ts +0 -3
- package/dist/commands/copy/types.d.ts.map +0 -1
- package/dist/commands/copy/types.js +0 -1
- package/dist/commands/exit/index.d.ts +0 -10
- package/dist/commands/exit/index.d.ts.map +0 -1
- package/dist/commands/exit/index.js +0 -21
- package/dist/commands/exit/types.d.ts +0 -8
- package/dist/commands/exit/types.d.ts.map +0 -1
- package/dist/commands/exit/types.js +0 -1
- package/dist/commands/exit/utils.d.ts +0 -2
- package/dist/commands/exit/utils.d.ts.map +0 -1
- package/dist/commands/exit/utils.js +0 -13
- package/dist/commands/prompt/index.d.ts +0 -5
- package/dist/commands/prompt/index.d.ts.map +0 -1
- package/dist/commands/prompt/index.js +0 -122
- package/dist/commands/prompt/types.d.ts +0 -15
- package/dist/commands/prompt/types.d.ts.map +0 -1
- package/dist/commands/prompt/types.js +0 -1
- package/dist/commands/prompt/utils.d.ts +0 -12
- package/dist/commands/prompt/utils.d.ts.map +0 -1
- package/dist/commands/prompt/utils.js +0 -107
- package/dist/commands/reset/index.d.ts +0 -3
- package/dist/commands/reset/index.d.ts.map +0 -1
- package/dist/commands/reset/index.js +0 -25
- package/dist/commands/reset/types.d.ts +0 -1
- package/dist/commands/reset/types.d.ts.map +0 -1
- package/dist/commands/reset/types.js +0 -3
- package/dist/commands/review/types.d.ts +0 -12
- package/dist/commands/review/types.d.ts.map +0 -1
- package/dist/commands/review/types.js +0 -1
- package/dist/commands/save/index.d.ts +0 -3
- package/dist/commands/save/index.d.ts.map +0 -1
- package/dist/commands/save/index.js +0 -19
- package/dist/config.d.ts.map +0 -1
- package/dist/dedent.d.ts.map +0 -1
- package/dist/formatting.d.ts.map +0 -1
- package/dist/logger.d.ts.map +0 -1
- package/dist/mentions.d.ts +0 -14
- package/dist/mentions.d.ts.map +0 -1
- package/dist/parsing.d.ts.map +0 -1
- package/dist/prompts.d.ts.map +0 -1
- package/dist/repl-new.d.ts +0 -65
- package/dist/repl-new.d.ts.map +0 -1
- package/dist/skills.d.ts +0 -16
- package/dist/skills.d.ts.map +0 -1
- package/dist/skills.js +0 -233
- package/dist/stdin.d.ts.map +0 -1
- package/dist/tui/autocomplete/path-provider.d.ts +0 -21
- package/dist/tui/autocomplete/path-provider.d.ts.map +0 -1
- package/dist/tui/autocomplete/path-provider.js +0 -164
- package/dist/utils/iterables.d.ts +0 -2
- package/dist/utils/iterables.d.ts.map +0 -1
- package/dist/utils/iterables.js +0 -6
- package/dist/version.d.ts.map +0 -1
- /package/dist/{dedent.d.ts → utils/dedent.d.ts} +0 -0
- /package/dist/{dedent.js → utils/dedent.js} +0 -0
- /package/dist/{formatting.d.ts → utils/formatting.d.ts} +0 -0
- /package/dist/{logger.d.ts → utils/logger.d.ts} +0 -0
- /package/dist/{parsing.d.ts → utils/parsing.d.ts} +0 -0
- /package/dist/{parsing.js → utils/parsing.js} +0 -0
- /package/dist/{version.d.ts → utils/version.d.ts} +0 -0
package/dist/execution/index.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* in a controlled environment with proper error handling.
|
|
6
6
|
*/
|
|
7
7
|
import { exec, spawn } from "node:child_process";
|
|
8
|
-
import { logger } from "../logger.js";
|
|
8
|
+
import { logger } from "../utils/logger.js";
|
|
9
9
|
/**
|
|
10
10
|
* List of dangerous commands that shouldn't be executed
|
|
11
11
|
*/
|
|
@@ -44,6 +44,37 @@ function ttySizeEnv() {
|
|
|
44
44
|
}
|
|
45
45
|
return env;
|
|
46
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* Factory function for creating abort handlers.
|
|
49
|
+
* Defined at module level to avoid capturing closure scope,
|
|
50
|
+
* preventing memory leaks when AbortSignal is long-lived.
|
|
51
|
+
*/
|
|
52
|
+
function createAbortHandler(childProc, cmd, start, settleFn, shouldThrow) {
|
|
53
|
+
return function abortHandler() {
|
|
54
|
+
childProc.kill("SIGTERM");
|
|
55
|
+
const error = new Error("Command execution aborted");
|
|
56
|
+
const duration = Date.now() - start;
|
|
57
|
+
settleFn({
|
|
58
|
+
output: "",
|
|
59
|
+
exitCode: 1,
|
|
60
|
+
error,
|
|
61
|
+
command: cmd,
|
|
62
|
+
duration,
|
|
63
|
+
}, shouldThrow, error);
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Factory function for creating background process abort handlers.
|
|
68
|
+
* Defined at module level to avoid capturing closure scope.
|
|
69
|
+
* Note: Process cleanup from backgroundProcesses map is handled by the exit handler.
|
|
70
|
+
*/
|
|
71
|
+
function createBackgroundAbortHandler(childProc, getRunningState) {
|
|
72
|
+
return function abortHandler() {
|
|
73
|
+
if (getRunningState()) {
|
|
74
|
+
childProc.kill("SIGTERM");
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
}
|
|
47
78
|
export class ExecutionEnvironment {
|
|
48
79
|
config;
|
|
49
80
|
backgroundProcesses = new Map();
|
|
@@ -148,62 +179,58 @@ export class ExecutionEnvironment {
|
|
|
148
179
|
resolve(result);
|
|
149
180
|
}
|
|
150
181
|
};
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
182
|
+
// Extract callback handlers to reduce cognitive complexity
|
|
183
|
+
const handleExecError = (error, output, duration) => {
|
|
184
|
+
const exitCode = error.code ?? 1;
|
|
185
|
+
logger.error({
|
|
186
|
+
error: error.message,
|
|
187
|
+
exitCode,
|
|
188
|
+
duration,
|
|
189
|
+
}, `Command execution failed: ${command}`);
|
|
190
|
+
settle({
|
|
191
|
+
output: preserveOutputOnError ? output : "",
|
|
192
|
+
exitCode,
|
|
193
|
+
error,
|
|
194
|
+
command,
|
|
195
|
+
duration,
|
|
196
|
+
}, throwOnError, error);
|
|
197
|
+
};
|
|
198
|
+
const handleExecSuccess = (output, duration) => {
|
|
199
|
+
logger.debug({
|
|
200
|
+
duration,
|
|
201
|
+
outputLength: output.length,
|
|
202
|
+
}, `Command executed successfully: ${command}`);
|
|
203
|
+
settle({
|
|
204
|
+
output,
|
|
205
|
+
exitCode: 0,
|
|
206
|
+
command,
|
|
207
|
+
duration,
|
|
208
|
+
}, false);
|
|
209
|
+
};
|
|
210
|
+
const handleExecCallback = (error, stdout, stderr) => {
|
|
160
211
|
const duration = Date.now() - startTime;
|
|
161
|
-
// Combine stdout and stderr if requested
|
|
162
212
|
const output = captureStderr
|
|
163
213
|
? `${stdout}${stderr ? stderr : ""}`
|
|
164
214
|
: stdout;
|
|
165
215
|
if (error) {
|
|
166
|
-
|
|
167
|
-
logger.error({
|
|
168
|
-
error: error.message,
|
|
169
|
-
exitCode,
|
|
170
|
-
duration,
|
|
171
|
-
}, `Command execution failed: ${command}`);
|
|
172
|
-
settle({
|
|
173
|
-
output: preserveOutputOnError ? output : "",
|
|
174
|
-
exitCode,
|
|
175
|
-
error,
|
|
176
|
-
command,
|
|
177
|
-
duration,
|
|
178
|
-
}, throwOnError, error);
|
|
216
|
+
handleExecError(error, output, duration);
|
|
179
217
|
}
|
|
180
218
|
else {
|
|
181
|
-
|
|
182
|
-
duration,
|
|
183
|
-
outputLength: output.length,
|
|
184
|
-
}, `Command executed successfully: ${command}`);
|
|
185
|
-
settle({
|
|
186
|
-
output,
|
|
187
|
-
exitCode: 0,
|
|
188
|
-
command,
|
|
189
|
-
duration,
|
|
190
|
-
}, false);
|
|
219
|
+
handleExecSuccess(output, duration);
|
|
191
220
|
}
|
|
192
|
-
}
|
|
221
|
+
};
|
|
222
|
+
const childProcess = exec(command, {
|
|
223
|
+
cwd,
|
|
224
|
+
env,
|
|
225
|
+
timeout,
|
|
226
|
+
maxBuffer,
|
|
227
|
+
shell,
|
|
228
|
+
windowsHide: true,
|
|
229
|
+
encoding: "utf8",
|
|
230
|
+
}, handleExecCallback);
|
|
193
231
|
// Handle abort signal
|
|
194
232
|
if (options.abortSignal) {
|
|
195
|
-
abortHandler = (
|
|
196
|
-
logger.warn({ command, pid: childProcess.pid }, "Command execution aborted");
|
|
197
|
-
childProcess.kill("SIGTERM");
|
|
198
|
-
const error = new Error("Command execution aborted");
|
|
199
|
-
settle({
|
|
200
|
-
output: "",
|
|
201
|
-
exitCode: 1,
|
|
202
|
-
error,
|
|
203
|
-
command,
|
|
204
|
-
duration: Date.now() - startTime,
|
|
205
|
-
}, throwOnError, error);
|
|
206
|
-
};
|
|
233
|
+
abortHandler = createAbortHandler(childProcess, command, startTime, settle, throwOnError);
|
|
207
234
|
options.abortSignal.addEventListener("abort", abortHandler, {
|
|
208
235
|
once: true,
|
|
209
236
|
});
|
|
@@ -314,14 +341,7 @@ export class ExecutionEnvironment {
|
|
|
314
341
|
// Handle abort signal for background process
|
|
315
342
|
let abortHandler;
|
|
316
343
|
if (options.abortSignal) {
|
|
317
|
-
abortHandler = () =>
|
|
318
|
-
logger.warn({ command, pid }, "Background command execution aborted");
|
|
319
|
-
if (isRunning) {
|
|
320
|
-
childProcess.kill("SIGTERM");
|
|
321
|
-
isRunning = false;
|
|
322
|
-
this.backgroundProcesses.delete(pid);
|
|
323
|
-
}
|
|
324
|
-
};
|
|
344
|
+
abortHandler = createBackgroundAbortHandler(childProcess, () => isRunning);
|
|
325
345
|
options.abortSignal.addEventListener("abort", abortHandler, {
|
|
326
346
|
once: true,
|
|
327
347
|
});
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../source/index.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../source/index.ts"],"names":[],"mappings":";AA6BA,MAAM,WAAW,gBAAgB;IAC/B,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,EAAE,CAAC;CACvB;AAGD,wBAAgB,sBAAsB,CACpC,UAAU,GAAE,MAAM,EAAO,GACxB,gBAAgB,CAsBlB;AAoDD,QAAA,MAAM,KAAK;;;;;;;;;;CAAyB,CAAC;AAMrC;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAE9C;AAED,MAAM,MAAM,KAAK,GAAG,OAAO,KAAK,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -6,32 +6,36 @@ import { parseArgs } from "node:util";
|
|
|
6
6
|
import { asyncTry, isFailure, syncTry } from "@travisennis/stdlib/try";
|
|
7
7
|
import { isDefined } from "@travisennis/stdlib/typeguards";
|
|
8
8
|
import { Agent } from "./agent/index.js";
|
|
9
|
-
import { Cli } from "./cli.js";
|
|
9
|
+
import { Cli } from "./cli/index.js";
|
|
10
|
+
import { readStdinWithLimits } from "./cli/stdin.js";
|
|
10
11
|
import { CommandManager } from "./commands/manager.js";
|
|
11
|
-
import { config
|
|
12
|
-
import { logger } from "./logger.js";
|
|
13
|
-
import { PromptError, processPrompt } from "./mentions.js";
|
|
12
|
+
import { config } from "./config/index.js";
|
|
14
13
|
import { ModelManager } from "./models/manager.js";
|
|
15
14
|
import { isSupportedModel } from "./models/providers.js";
|
|
16
15
|
import { PromptManager } from "./prompts/manager.js";
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
16
|
+
import { processPrompt } from "./prompts/mentions.js";
|
|
17
|
+
import { systemPrompt } from "./prompts/system-prompt.js";
|
|
18
|
+
import { Repl } from "./repl/index.js";
|
|
19
19
|
import { SessionManager } from "./sessions/manager.js";
|
|
20
|
-
import {
|
|
20
|
+
import { writeExitSummary } from "./sessions/summary.js";
|
|
21
21
|
import { setTerminalTitle } from "./terminal/control.js";
|
|
22
22
|
import { select } from "./terminal/select-prompt.js";
|
|
23
23
|
import { TokenCounter } from "./tokens/counter.js";
|
|
24
24
|
import { TokenTracker } from "./tokens/tracker.js";
|
|
25
25
|
import { initTools } from "./tools/index.js";
|
|
26
|
-
import {
|
|
26
|
+
import { logger } from "./utils/logger.js";
|
|
27
|
+
import { getPackageVersion } from "./utils/version.js";
|
|
27
28
|
// Create workspace context from CLI arguments
|
|
28
29
|
export function createWorkspaceContext(addDirArgs = []) {
|
|
29
30
|
const primaryDir = process.cwd();
|
|
30
31
|
mkdirSync("/tmp/acai", { recursive: true });
|
|
31
32
|
const allowedDirs = [
|
|
32
33
|
primaryDir,
|
|
34
|
+
"/tmp",
|
|
33
35
|
"/tmp/acai",
|
|
36
|
+
"/var/folders",
|
|
34
37
|
path.join(os.homedir(), ".acai"),
|
|
38
|
+
path.join(os.homedir(), ".agents"),
|
|
35
39
|
...addDirArgs,
|
|
36
40
|
];
|
|
37
41
|
// Remove duplicates while preserving order
|
|
@@ -52,7 +56,7 @@ Options
|
|
|
52
56
|
--resume Resume a specific session by ID, or most recent if no ID given
|
|
53
57
|
--add-dir Add additional working directory (can be used multiple times)
|
|
54
58
|
--no-skills Disable skills discovery and loading
|
|
55
|
-
|
|
59
|
+
--no-session Don't save session to disk
|
|
56
60
|
|
|
57
61
|
--help, -h Show help
|
|
58
62
|
--version, -v Show version
|
|
@@ -73,6 +77,7 @@ const parsed = syncTry(() => parseArgs({
|
|
|
73
77
|
resume: { type: "boolean", default: false },
|
|
74
78
|
"add-dir": { type: "string", multiple: true },
|
|
75
79
|
"no-skills": { type: "boolean", default: false },
|
|
80
|
+
"no-session": { type: "boolean", default: false },
|
|
76
81
|
help: { type: "boolean", short: "h" },
|
|
77
82
|
version: { type: "boolean", short: "v" },
|
|
78
83
|
},
|
|
@@ -96,46 +101,34 @@ export function handleError(error) {
|
|
|
96
101
|
logger.error({ error: error }, error.message);
|
|
97
102
|
}
|
|
98
103
|
// Configuration constants
|
|
99
|
-
const DEFAULT_HISTORY_LIMIT =
|
|
100
|
-
const CONTINUE_HISTORY_LIMIT = 1;
|
|
104
|
+
const DEFAULT_HISTORY_LIMIT = 20; // the amount of sessions to retrieve from session history
|
|
101
105
|
// Helper functions for main()
|
|
102
106
|
async function initializeAppState(appConfig, initialPromptInput, stdinContent, hasContinueOrResume, resumeSessionId) {
|
|
103
107
|
const appDir = config.app;
|
|
104
108
|
// Parallelize independent async operations
|
|
105
|
-
const [
|
|
106
|
-
appDir.ensurePath("
|
|
109
|
+
const [sessionsDir, modelManager] = await Promise.all([
|
|
110
|
+
appDir.ensurePath("sessions"),
|
|
107
111
|
initializeModelManager(appDir),
|
|
108
112
|
]);
|
|
109
113
|
// Initialize synchronous components
|
|
110
114
|
const tokenTracker = new TokenTracker();
|
|
111
115
|
const tokenCounter = new TokenCounter();
|
|
112
116
|
// Initialize dependent components
|
|
113
|
-
const sessionManager = await initializeSessionManager(
|
|
117
|
+
const sessionManager = await initializeSessionManager(sessionsDir, modelManager, tokenTracker);
|
|
114
118
|
// Handle conversation history loading
|
|
115
|
-
await handleConversationHistory(sessionManager,
|
|
119
|
+
await handleConversationHistory(sessionManager, sessionsDir, hasContinueOrResume, resumeSessionId);
|
|
116
120
|
// Setup prompt manager
|
|
117
121
|
const promptManager = new PromptManager(tokenCounter);
|
|
118
122
|
if (!hasContinueOrResume && isDefined(initialPromptInput)) {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
promptManager.addContext(context);
|
|
127
|
-
}
|
|
128
|
-
promptManager.set(processedPrompt.message);
|
|
129
|
-
}
|
|
130
|
-
catch (error) {
|
|
131
|
-
if (error instanceof PromptError) {
|
|
132
|
-
logger.error(`Prompt mention error: ${error.message}`);
|
|
133
|
-
promptManager.set(initialPromptInput);
|
|
134
|
-
}
|
|
135
|
-
else {
|
|
136
|
-
throw new Error("Failed to process prompt.", { cause: error });
|
|
137
|
-
}
|
|
123
|
+
const modelConfig = modelManager.getModelMetadata("repl");
|
|
124
|
+
const processedPrompt = await processPrompt(initialPromptInput, {
|
|
125
|
+
baseDir: process.cwd(),
|
|
126
|
+
model: modelConfig,
|
|
127
|
+
});
|
|
128
|
+
for (const context of processedPrompt.context) {
|
|
129
|
+
promptManager.addContext(context);
|
|
138
130
|
}
|
|
131
|
+
promptManager.set(processedPrompt.message);
|
|
139
132
|
}
|
|
140
133
|
if (stdinContent && stdinContent.trim().length > 0) {
|
|
141
134
|
if (isDefined(initialPromptInput)) {
|
|
@@ -228,41 +221,42 @@ async function determineInitialPrompt() {
|
|
|
228
221
|
async function initializeModelManager(appDir) {
|
|
229
222
|
const chosenModel = isSupportedModel(flags.model)
|
|
230
223
|
? flags.model
|
|
231
|
-
: "opencode:
|
|
224
|
+
: "opencode-go:kimi-k2-5";
|
|
225
|
+
const projectConfig = await config.getConfig();
|
|
226
|
+
const devtoolsEnabled = projectConfig.devtools?.enabled ?? false;
|
|
232
227
|
const modelManager = new ModelManager({
|
|
233
228
|
stateDir: await appDir.ensurePath("audit"),
|
|
229
|
+
devtoolsEnabled,
|
|
234
230
|
});
|
|
235
231
|
modelManager.setModel("repl", chosenModel);
|
|
236
232
|
modelManager.setModel("cli", chosenModel);
|
|
237
233
|
modelManager.setModel("title-conversation", chosenModel);
|
|
238
234
|
modelManager.setModel("conversation-summarizer", chosenModel);
|
|
239
|
-
modelManager.setModel("tool-repair",
|
|
235
|
+
modelManager.setModel("tool-repair", "openai:gpt-5.1-codex-mini");
|
|
240
236
|
modelManager.setModel("conversation-analyzer", chosenModel);
|
|
241
237
|
modelManager.setModel("init-project", chosenModel);
|
|
242
|
-
modelManager.setModel("task-agent", chosenModel);
|
|
243
238
|
modelManager.setModel("handoff-agent", chosenModel);
|
|
244
|
-
modelManager.setModel("edit-fix", chosenModel);
|
|
245
239
|
return modelManager;
|
|
246
240
|
}
|
|
247
|
-
async function initializeSessionManager(
|
|
248
|
-
const
|
|
249
|
-
stateDir:
|
|
241
|
+
async function initializeSessionManager(sessionsDir, modelManager, tokenTracker) {
|
|
242
|
+
const sessionManager = new SessionManager({
|
|
243
|
+
stateDir: sessionsDir,
|
|
250
244
|
modelManager,
|
|
251
245
|
tokenTracker,
|
|
252
246
|
});
|
|
253
|
-
|
|
247
|
+
sessionManager.on("update-title", (title) => setTerminalTitle(title));
|
|
254
248
|
// Listen for model changes and update session manager when repl model changes
|
|
255
249
|
modelManager.on("set-model", (app, _model) => {
|
|
256
250
|
if (app === "repl") {
|
|
257
251
|
const modelId = modelManager.getModel("repl").modelId;
|
|
258
|
-
|
|
252
|
+
sessionManager.setModelId(modelId);
|
|
259
253
|
}
|
|
260
254
|
});
|
|
261
|
-
return
|
|
255
|
+
return sessionManager;
|
|
262
256
|
}
|
|
263
|
-
async function handleConversationHistory(
|
|
257
|
+
async function handleConversationHistory(sessionManager, sessionsDir, _hasContinueOrResume, resumeSessionId) {
|
|
264
258
|
if (flags.continue === true) {
|
|
265
|
-
const histories = await SessionManager.load(
|
|
259
|
+
const histories = await SessionManager.load(sessionsDir, DEFAULT_HISTORY_LIMIT);
|
|
266
260
|
if (histories.length > 0) {
|
|
267
261
|
try {
|
|
268
262
|
const choice = await select({
|
|
@@ -275,7 +269,7 @@ async function handleConversationHistory(messageHistory, messageHistoryDir, _has
|
|
|
275
269
|
});
|
|
276
270
|
const selectedHistory = histories.at(choice);
|
|
277
271
|
if (selectedHistory) {
|
|
278
|
-
|
|
272
|
+
sessionManager.restore(selectedHistory);
|
|
279
273
|
logger.info(`Resuming conversation: ${selectedHistory.title}`);
|
|
280
274
|
setTerminalTitle(selectedHistory.title || `acai: ${process.cwd()}`);
|
|
281
275
|
}
|
|
@@ -300,10 +294,10 @@ async function handleConversationHistory(messageHistory, messageHistoryDir, _has
|
|
|
300
294
|
}
|
|
301
295
|
else if (flags.resume === true) {
|
|
302
296
|
if (resumeSessionId) {
|
|
303
|
-
const histories = await SessionManager.load(
|
|
297
|
+
const histories = await SessionManager.load(sessionsDir, DEFAULT_HISTORY_LIMIT);
|
|
304
298
|
const targetHistory = histories.find((h) => h.sessionId === resumeSessionId);
|
|
305
299
|
if (targetHistory) {
|
|
306
|
-
|
|
300
|
+
sessionManager.restore(targetHistory);
|
|
307
301
|
logger.info(`Resuming conversation: ${targetHistory.title}`);
|
|
308
302
|
setTerminalTitle(targetHistory.title || `acai: ${process.cwd()}`);
|
|
309
303
|
}
|
|
@@ -313,10 +307,10 @@ async function handleConversationHistory(messageHistory, messageHistoryDir, _has
|
|
|
313
307
|
}
|
|
314
308
|
}
|
|
315
309
|
else {
|
|
316
|
-
const histories = await SessionManager.load(
|
|
310
|
+
const histories = await SessionManager.load(sessionsDir, 1); // read the most recent session
|
|
317
311
|
const latestHistory = histories.at(0);
|
|
318
312
|
if (latestHistory) {
|
|
319
|
-
|
|
313
|
+
sessionManager.restore(latestHistory);
|
|
320
314
|
console.info(`Resuming conversation: ${latestHistory.title}`);
|
|
321
315
|
setTerminalTitle(latestHistory.title || `acai: ${process.cwd()}`);
|
|
322
316
|
}
|
|
@@ -326,133 +320,134 @@ async function handleConversationHistory(messageHistory, messageHistoryDir, _has
|
|
|
326
320
|
}
|
|
327
321
|
}
|
|
328
322
|
}
|
|
329
|
-
async function runCliMode(state) {
|
|
330
|
-
const skillsEnabled = !flags["no-skills"] && (await config.getSkillsEnabled());
|
|
323
|
+
async function runCliMode(state, noSession) {
|
|
331
324
|
const cliProcess = new Cli({
|
|
332
325
|
promptManager: state.promptManager,
|
|
333
|
-
|
|
326
|
+
sessionManager: state.sessionManager,
|
|
334
327
|
modelManager: state.modelManager,
|
|
335
328
|
tokenTracker: state.tokenTracker,
|
|
336
329
|
tokenCounter: state.tokenCounter,
|
|
337
330
|
workspace,
|
|
338
|
-
|
|
331
|
+
noSession,
|
|
339
332
|
});
|
|
340
333
|
(await asyncTry(cliProcess.run())).recover(handleError);
|
|
341
334
|
}
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
const tools = await initTools({
|
|
345
|
-
workspace,
|
|
346
|
-
});
|
|
347
|
-
const agent = new Agent({
|
|
348
|
-
sessionManager: state.sessionManager,
|
|
349
|
-
modelManager: state.modelManager,
|
|
350
|
-
tokenTracker: state.tokenTracker,
|
|
351
|
-
});
|
|
352
|
-
// When stdin was piped, use /dev/tty for interactive input instead of process.stdin
|
|
353
|
-
const repl = new NewRepl({
|
|
354
|
-
agent,
|
|
355
|
-
promptManager: state.promptManager,
|
|
356
|
-
config: state.appConfig,
|
|
357
|
-
messageHistory: state.sessionManager,
|
|
358
|
-
modelManager: state.modelManager,
|
|
359
|
-
tokenTracker: state.tokenTracker,
|
|
360
|
-
commands: state.commands,
|
|
361
|
-
tokenCounter: state.tokenCounter,
|
|
362
|
-
promptHistory: state.promptHistory,
|
|
363
|
-
workspace,
|
|
364
|
-
tools,
|
|
365
|
-
terminalOptions: { useTty: stdinWasPiped },
|
|
366
|
-
});
|
|
367
|
-
await repl.init();
|
|
368
|
-
// Reconstruct session display if there are existing messages
|
|
369
|
-
if (!state.sessionManager.isEmpty()) {
|
|
370
|
-
await repl.rerender();
|
|
371
|
-
}
|
|
372
|
-
state.sessionManager.on("clear-history", () => {
|
|
335
|
+
function setupReplEventHandlers(repl, agent, sessionManager, noSession) {
|
|
336
|
+
sessionManager.on("clear-history", async () => {
|
|
373
337
|
logger.info("Resetting agent state.");
|
|
374
338
|
agent.resetState();
|
|
339
|
+
agent.setConfig(await config.getConfig());
|
|
375
340
|
void repl.rerender();
|
|
376
341
|
});
|
|
377
|
-
// Set interrupt callback
|
|
378
342
|
repl.setInterruptCallback(async () => {
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
343
|
+
if (!noSession) {
|
|
344
|
+
try {
|
|
345
|
+
await sessionManager.save();
|
|
346
|
+
}
|
|
347
|
+
catch (error) {
|
|
348
|
+
logger.warn({ error }, "Failed to save message history on interrupt");
|
|
349
|
+
}
|
|
385
350
|
}
|
|
386
351
|
agent.abort();
|
|
387
352
|
});
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
353
|
+
repl.setExitCallback(async (_sessionId) => {
|
|
354
|
+
if (!sessionManager.isEmpty()) {
|
|
355
|
+
await repl.triggerRuleGeneration();
|
|
356
|
+
writeExitSummary(sessionManager, noSession);
|
|
392
357
|
}
|
|
393
358
|
});
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
tools,
|
|
414
|
-
activeTools,
|
|
415
|
-
abortSignal: agent.abortSignal,
|
|
416
|
-
});
|
|
417
|
-
for await (const result of results) {
|
|
418
|
-
await repl.handle(result, agent.state);
|
|
419
|
-
}
|
|
420
|
-
await state.sessionManager.save();
|
|
359
|
+
}
|
|
360
|
+
async function handleStdinPrompt(state, agent, repl, tools, activeTools, systemPromptResult, noSession) {
|
|
361
|
+
if (!state.promptManager.isPending()) {
|
|
362
|
+
return false;
|
|
363
|
+
}
|
|
364
|
+
try {
|
|
365
|
+
const promptText = state.promptManager.get();
|
|
366
|
+
const userMessage = state.promptManager.getUserMessage();
|
|
367
|
+
state.sessionManager.appendUserMessage(userMessage);
|
|
368
|
+
const results = agent.run({
|
|
369
|
+
systemPrompt: systemPromptResult.prompt,
|
|
370
|
+
input: promptText,
|
|
371
|
+
tools,
|
|
372
|
+
activeTools,
|
|
373
|
+
abortSignal: agent.abortSignal,
|
|
374
|
+
maxIterations: state.appConfig.loop.maxIterations,
|
|
375
|
+
});
|
|
376
|
+
for await (const result of results) {
|
|
377
|
+
await repl.handle(result, agent.state);
|
|
421
378
|
}
|
|
422
|
-
|
|
423
|
-
|
|
379
|
+
if (!noSession) {
|
|
380
|
+
await state.sessionManager.save();
|
|
424
381
|
}
|
|
382
|
+
return true;
|
|
425
383
|
}
|
|
426
|
-
|
|
384
|
+
catch {
|
|
385
|
+
return false;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
async function runInteractiveLoop(repl, agent, tools, activeTools, systemPromptResult, noSession, sessionManager, maxIterations) {
|
|
427
389
|
while (true) {
|
|
428
390
|
const userInput = await repl.getUserInput();
|
|
429
|
-
const projectConfig = await config.getConfig();
|
|
430
|
-
const activeTools = projectConfig.tools.activeTools;
|
|
431
|
-
const skillsEnabled = !flags["no-skills"] && (projectConfig.skills?.enabled ?? true);
|
|
432
391
|
try {
|
|
433
|
-
const systemPromptResult = await systemPrompt({
|
|
434
|
-
activeTools,
|
|
435
|
-
allowedDirs: workspace.allowedDirs,
|
|
436
|
-
skillsEnabled,
|
|
437
|
-
});
|
|
438
392
|
const results = agent.run({
|
|
439
393
|
systemPrompt: systemPromptResult.prompt,
|
|
440
394
|
input: userInput,
|
|
441
395
|
tools,
|
|
442
396
|
activeTools,
|
|
443
397
|
abortSignal: agent.abortSignal,
|
|
398
|
+
maxIterations,
|
|
444
399
|
});
|
|
445
400
|
for await (const result of results) {
|
|
446
401
|
await repl.handle(result, agent.state);
|
|
447
402
|
}
|
|
448
|
-
|
|
403
|
+
if (!noSession) {
|
|
404
|
+
await sessionManager.save();
|
|
405
|
+
}
|
|
449
406
|
}
|
|
450
|
-
catch
|
|
451
|
-
//
|
|
452
|
-
// repl.showError((error as Error).message || "Unknown error occurred");
|
|
407
|
+
catch {
|
|
408
|
+
// Error displayed in the TUI
|
|
453
409
|
}
|
|
454
410
|
}
|
|
455
411
|
}
|
|
412
|
+
async function runReplMode(state, stdinWasPiped, noSession) {
|
|
413
|
+
const tools = await initTools({ workspace });
|
|
414
|
+
const agent = new Agent({
|
|
415
|
+
config: state.appConfig,
|
|
416
|
+
sessionManager: state.sessionManager,
|
|
417
|
+
modelManager: state.modelManager,
|
|
418
|
+
tokenTracker: state.tokenTracker,
|
|
419
|
+
});
|
|
420
|
+
const repl = new Repl({
|
|
421
|
+
agent,
|
|
422
|
+
promptManager: state.promptManager,
|
|
423
|
+
configManager: config,
|
|
424
|
+
sessionManager: state.sessionManager,
|
|
425
|
+
modelManager: state.modelManager,
|
|
426
|
+
tokenTracker: state.tokenTracker,
|
|
427
|
+
commands: state.commands,
|
|
428
|
+
tokenCounter: state.tokenCounter,
|
|
429
|
+
promptHistory: state.promptHistory,
|
|
430
|
+
workspace,
|
|
431
|
+
tools,
|
|
432
|
+
terminalOptions: { useTty: stdinWasPiped },
|
|
433
|
+
noSession,
|
|
434
|
+
});
|
|
435
|
+
await repl.init();
|
|
436
|
+
if (!state.sessionManager.isEmpty()) {
|
|
437
|
+
await repl.rerender();
|
|
438
|
+
}
|
|
439
|
+
setupReplEventHandlers(repl, agent, state.sessionManager, noSession);
|
|
440
|
+
const activeTools = state.appConfig.tools.activeTools;
|
|
441
|
+
const skillsEnabled = !flags["no-skills"] && (state.appConfig.skills?.enabled ?? true);
|
|
442
|
+
const systemPromptResult = await systemPrompt({
|
|
443
|
+
activeTools,
|
|
444
|
+
allowedDirs: workspace.allowedDirs,
|
|
445
|
+
logsPath: state.appConfig.logs?.path,
|
|
446
|
+
skillsEnabled,
|
|
447
|
+
});
|
|
448
|
+
await handleStdinPrompt(state, agent, repl, tools, activeTools, systemPromptResult, noSession);
|
|
449
|
+
await runInteractiveLoop(repl, agent, tools, activeTools, systemPromptResult, noSession, state.sessionManager, state.appConfig.loop.maxIterations);
|
|
450
|
+
}
|
|
456
451
|
async function main() {
|
|
457
452
|
try {
|
|
458
453
|
const appConfig = await config.ensureDefaultConfig("acai");
|
|
@@ -467,14 +462,26 @@ async function main() {
|
|
|
467
462
|
const { initialPromptInput, stdinContent, hasContinueOrResume, resumeSessionId, } = await determineInitialPrompt();
|
|
468
463
|
// Initialize application state
|
|
469
464
|
const state = await initializeAppState(appConfig, initialPromptInput, stdinContent, hasContinueOrResume, resumeSessionId);
|
|
465
|
+
// Add logs directory to allowed directories if configured
|
|
466
|
+
const logsPath = (await config.getConfig()).logs?.path;
|
|
467
|
+
if (logsPath) {
|
|
468
|
+
// Expand ~ to home directory before resolving
|
|
469
|
+
const expandedLogsPath = logsPath.startsWith("~/") || logsPath === "~"
|
|
470
|
+
? path.join(os.homedir(), logsPath.slice(1))
|
|
471
|
+
: logsPath;
|
|
472
|
+
const logsDir = path.dirname(path.resolve(expandedLogsPath));
|
|
473
|
+
if (!workspace.allowedDirs.includes(logsDir)) {
|
|
474
|
+
workspace.allowedDirs.push(logsDir);
|
|
475
|
+
}
|
|
476
|
+
}
|
|
470
477
|
// Set terminal title after all validation is complete
|
|
471
478
|
setTerminalTitle(`acai: ${workspace.primaryDir}`);
|
|
472
479
|
// Handle CLI mode if initial prompt provided
|
|
473
480
|
if (isDefined(initialPromptInput)) {
|
|
474
|
-
return await runCliMode(state);
|
|
481
|
+
return await runCliMode(state, flags["no-session"] === true);
|
|
475
482
|
}
|
|
476
483
|
// Setup REPL mode
|
|
477
|
-
return await runReplMode(state, stdinContent !== null);
|
|
484
|
+
return await runReplMode(state, stdinContent !== null, flags["no-session"] === true);
|
|
478
485
|
}
|
|
479
486
|
catch (error) {
|
|
480
487
|
handleError(error);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../../source/middleware/cache.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,yBAAyB,EAE1B,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../../source/middleware/cache.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,yBAAyB,EAE1B,MAAM,kBAAkB,CAAC;AAyE1B,eAAO,MAAM,eAAe,EAAE,yBA+E7B,CAAC"}
|