plugsuits 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli.js +3 -0
- package/dist/agent-reasoning-default.test.d.ts +2 -0
- package/dist/agent-reasoning-default.test.d.ts.map +1 -0
- package/dist/agent-reasoning-default.test.js +38 -0
- package/dist/agent-reasoning-default.test.js.map +1 -0
- package/dist/agent.d.ts +61 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +308 -0
- package/dist/agent.js.map +1 -0
- package/dist/agent.test.d.ts +2 -0
- package/dist/agent.test.d.ts.map +1 -0
- package/dist/agent.test.js +38 -0
- package/dist/agent.test.js.map +1 -0
- package/dist/cli-args.d.ts +15 -0
- package/dist/cli-args.d.ts.map +1 -0
- package/dist/cli-args.js +63 -0
- package/dist/cli-args.js.map +1 -0
- package/dist/cli-args.test.d.ts +2 -0
- package/dist/cli-args.test.d.ts.map +1 -0
- package/dist/cli-args.test.js +105 -0
- package/dist/cli-args.test.js.map +1 -0
- package/dist/commands/aliases-and-tool-fallback.test.d.ts +2 -0
- package/dist/commands/aliases-and-tool-fallback.test.d.ts.map +1 -0
- package/dist/commands/aliases-and-tool-fallback.test.js +132 -0
- package/dist/commands/aliases-and-tool-fallback.test.js.map +1 -0
- package/dist/commands/clear.d.ts +3 -0
- package/dist/commands/clear.d.ts.map +1 -0
- package/dist/commands/clear.js +12 -0
- package/dist/commands/clear.js.map +1 -0
- package/dist/commands/factories/create-toggle-command.d.ts +13 -0
- package/dist/commands/factories/create-toggle-command.d.ts.map +1 -0
- package/dist/commands/factories/create-toggle-command.js +38 -0
- package/dist/commands/factories/create-toggle-command.js.map +1 -0
- package/dist/commands/help.d.ts +3 -0
- package/dist/commands/help.d.ts.map +1 -0
- package/dist/commands/help.js +23 -0
- package/dist/commands/help.js.map +1 -0
- package/dist/commands/index.d.ts +18 -0
- package/dist/commands/index.d.ts.map +1 -0
- package/dist/commands/index.js +82 -0
- package/dist/commands/index.js.map +1 -0
- package/dist/commands/model.d.ts +15 -0
- package/dist/commands/model.d.ts.map +1 -0
- package/dist/commands/model.js +100 -0
- package/dist/commands/model.js.map +1 -0
- package/dist/commands/reasoning-mode.d.ts +3 -0
- package/dist/commands/reasoning-mode.d.ts.map +1 -0
- package/dist/commands/reasoning-mode.js +47 -0
- package/dist/commands/reasoning-mode.js.map +1 -0
- package/dist/commands/render.d.ts +19 -0
- package/dist/commands/render.d.ts.map +1 -0
- package/dist/commands/render.js +140 -0
- package/dist/commands/render.js.map +1 -0
- package/dist/commands/render.test.d.ts +2 -0
- package/dist/commands/render.test.d.ts.map +1 -0
- package/dist/commands/render.test.js +36 -0
- package/dist/commands/render.test.js.map +1 -0
- package/dist/commands/tool-fallback.d.ts +3 -0
- package/dist/commands/tool-fallback.d.ts.map +1 -0
- package/dist/commands/tool-fallback.js +38 -0
- package/dist/commands/tool-fallback.js.map +1 -0
- package/dist/commands/translate.d.ts +3 -0
- package/dist/commands/translate.d.ts.map +1 -0
- package/dist/commands/translate.js +12 -0
- package/dist/commands/translate.js.map +1 -0
- package/dist/commands/translate.test.d.ts +2 -0
- package/dist/commands/translate.test.d.ts.map +1 -0
- package/dist/commands/translate.test.js +49 -0
- package/dist/commands/translate.test.js.map +1 -0
- package/dist/commands/types.d.ts +17 -0
- package/dist/commands/types.d.ts.map +1 -0
- package/dist/commands/types.js +2 -0
- package/dist/commands/types.js.map +1 -0
- package/dist/context/environment-context.d.ts +2 -0
- package/dist/context/environment-context.d.ts.map +1 -0
- package/dist/context/environment-context.js +11 -0
- package/dist/context/environment-context.js.map +1 -0
- package/dist/context/paths.d.ts +3 -0
- package/dist/context/paths.d.ts.map +1 -0
- package/dist/context/paths.js +3 -0
- package/dist/context/paths.js.map +1 -0
- package/dist/context/session.d.ts +4 -0
- package/dist/context/session.d.ts.map +1 -0
- package/dist/context/session.js +16 -0
- package/dist/context/session.js.map +1 -0
- package/dist/context/skill-command-prefix.d.ts +4 -0
- package/dist/context/skill-command-prefix.d.ts.map +1 -0
- package/dist/context/skill-command-prefix.js +15 -0
- package/dist/context/skill-command-prefix.js.map +1 -0
- package/dist/context/skills-integration.test.d.ts +2 -0
- package/dist/context/skills-integration.test.d.ts.map +1 -0
- package/dist/context/skills-integration.test.js +87 -0
- package/dist/context/skills-integration.test.js.map +1 -0
- package/dist/context/skills.d.ts +18 -0
- package/dist/context/skills.d.ts.map +1 -0
- package/dist/context/skills.js +431 -0
- package/dist/context/skills.js.map +1 -0
- package/dist/context/skills.test.d.ts +2 -0
- package/dist/context/skills.test.d.ts.map +1 -0
- package/dist/context/skills.test.js +20 -0
- package/dist/context/skills.test.js.map +1 -0
- package/dist/context/system-prompt.d.ts +2 -0
- package/dist/context/system-prompt.d.ts.map +1 -0
- package/dist/context/system-prompt.js +100 -0
- package/dist/context/system-prompt.js.map +1 -0
- package/dist/context/translation-integration.test.d.ts +2 -0
- package/dist/context/translation-integration.test.d.ts.map +1 -0
- package/dist/context/translation-integration.test.js +138 -0
- package/dist/context/translation-integration.test.js.map +1 -0
- package/dist/context/translation.d.ts +21 -0
- package/dist/context/translation.d.ts.map +1 -0
- package/dist/context/translation.js +82 -0
- package/dist/context/translation.js.map +1 -0
- package/dist/context/translation.test.d.ts +2 -0
- package/dist/context/translation.test.d.ts.map +1 -0
- package/dist/context/translation.test.js +129 -0
- package/dist/context/translation.test.js.map +1 -0
- package/dist/entrypoints/cli-input-rendering.test.d.ts +2 -0
- package/dist/entrypoints/cli-input-rendering.test.d.ts.map +1 -0
- package/dist/entrypoints/cli-input-rendering.test.js +192 -0
- package/dist/entrypoints/cli-input-rendering.test.js.map +1 -0
- package/dist/entrypoints/cli.d.ts +3 -0
- package/dist/entrypoints/cli.d.ts.map +1 -0
- package/dist/entrypoints/cli.js +1268 -0
- package/dist/entrypoints/cli.js.map +1 -0
- package/dist/entrypoints/headless-agent-config.d.ts +21 -0
- package/dist/entrypoints/headless-agent-config.d.ts.map +1 -0
- package/dist/entrypoints/headless-agent-config.js +15 -0
- package/dist/entrypoints/headless-agent-config.js.map +1 -0
- package/dist/entrypoints/headless-agent-config.test.d.ts +2 -0
- package/dist/entrypoints/headless-agent-config.test.d.ts.map +1 -0
- package/dist/entrypoints/headless-agent-config.test.js +63 -0
- package/dist/entrypoints/headless-agent-config.test.js.map +1 -0
- package/dist/entrypoints/headless.d.ts +3 -0
- package/dist/entrypoints/headless.d.ts.map +1 -0
- package/dist/entrypoints/headless.js +396 -0
- package/dist/entrypoints/headless.js.map +1 -0
- package/dist/env.d.ts +8 -0
- package/dist/env.d.ts.map +1 -0
- package/dist/env.js +14 -0
- package/dist/env.js.map +1 -0
- package/dist/friendli-models.d.ts +21 -0
- package/dist/friendli-models.d.ts.map +1 -0
- package/dist/friendli-models.js +57 -0
- package/dist/friendli-models.js.map +1 -0
- package/dist/friendli-reasoning.d.ts +10 -0
- package/dist/friendli-reasoning.d.ts.map +1 -0
- package/dist/friendli-reasoning.js +181 -0
- package/dist/friendli-reasoning.js.map +1 -0
- package/dist/friendli-reasoning.test.d.ts +2 -0
- package/dist/friendli-reasoning.test.d.ts.map +1 -0
- package/dist/friendli-reasoning.test.js +77 -0
- package/dist/friendli-reasoning.test.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/interaction/colors.d.ts +22 -0
- package/dist/interaction/colors.d.ts.map +1 -0
- package/dist/interaction/colors.js +24 -0
- package/dist/interaction/colors.js.map +1 -0
- package/dist/interaction/pi-tui-stream-renderer.d.ts +19 -0
- package/dist/interaction/pi-tui-stream-renderer.d.ts.map +1 -0
- package/dist/interaction/pi-tui-stream-renderer.js +1509 -0
- package/dist/interaction/pi-tui-stream-renderer.js.map +1 -0
- package/dist/interaction/pi-tui-stream-renderer.test.d.ts +2 -0
- package/dist/interaction/pi-tui-stream-renderer.test.d.ts.map +1 -0
- package/dist/interaction/pi-tui-stream-renderer.test.js +1314 -0
- package/dist/interaction/pi-tui-stream-renderer.test.js.map +1 -0
- package/dist/interaction/spinner.d.ts +13 -0
- package/dist/interaction/spinner.d.ts.map +1 -0
- package/dist/interaction/spinner.js +51 -0
- package/dist/interaction/spinner.js.map +1 -0
- package/dist/middleware/index.d.ts +7 -0
- package/dist/middleware/index.d.ts.map +1 -0
- package/dist/middleware/index.js +15 -0
- package/dist/middleware/index.js.map +1 -0
- package/dist/middleware/todo-continuation.d.ts +11 -0
- package/dist/middleware/todo-continuation.d.ts.map +1 -0
- package/dist/middleware/todo-continuation.js +103 -0
- package/dist/middleware/todo-continuation.js.map +1 -0
- package/dist/middleware/trim-leading-newlines.d.ts +3 -0
- package/dist/middleware/trim-leading-newlines.d.ts.map +1 -0
- package/dist/middleware/trim-leading-newlines.js +49 -0
- package/dist/middleware/trim-leading-newlines.js.map +1 -0
- package/dist/reasoning-mode.d.ts +5 -0
- package/dist/reasoning-mode.d.ts.map +1 -0
- package/dist/reasoning-mode.js +30 -0
- package/dist/reasoning-mode.js.map +1 -0
- package/dist/reasoning-mode.test.d.ts +2 -0
- package/dist/reasoning-mode.test.d.ts.map +1 -0
- package/dist/reasoning-mode.test.js +22 -0
- package/dist/reasoning-mode.test.js.map +1 -0
- package/dist/tool-fallback-mode.d.ts +6 -0
- package/dist/tool-fallback-mode.d.ts.map +1 -0
- package/dist/tool-fallback-mode.js +25 -0
- package/dist/tool-fallback-mode.js.map +1 -0
- package/dist/tools/execute/shell-execute.d.ts +17 -0
- package/dist/tools/execute/shell-execute.d.ts.map +1 -0
- package/dist/tools/execute/shell-execute.js +55 -0
- package/dist/tools/execute/shell-execute.js.map +1 -0
- package/dist/tools/execute/shell-execute.test.d.ts +2 -0
- package/dist/tools/execute/shell-execute.test.d.ts.map +1 -0
- package/dist/tools/execute/shell-execute.test.js +86 -0
- package/dist/tools/execute/shell-execute.test.js.map +1 -0
- package/dist/tools/execute/shell-interact.d.ts +10 -0
- package/dist/tools/execute/shell-interact.d.ts.map +1 -0
- package/dist/tools/execute/shell-interact.js +122 -0
- package/dist/tools/execute/shell-interact.js.map +1 -0
- package/dist/tools/execute/shell-interact.test.d.ts +2 -0
- package/dist/tools/execute/shell-interact.test.d.ts.map +1 -0
- package/dist/tools/execute/shell-interact.test.js +175 -0
- package/dist/tools/execute/shell-interact.test.js.map +1 -0
- package/dist/tools/explore/glob.d.ts +15 -0
- package/dist/tools/explore/glob.d.ts.map +1 -0
- package/dist/tools/explore/glob.js +107 -0
- package/dist/tools/explore/glob.js.map +1 -0
- package/dist/tools/explore/glob.test.d.ts +2 -0
- package/dist/tools/explore/glob.test.d.ts.map +1 -0
- package/dist/tools/explore/glob.test.js +183 -0
- package/dist/tools/explore/glob.test.js.map +1 -0
- package/dist/tools/explore/grep.d.ts +27 -0
- package/dist/tools/explore/grep.d.ts.map +1 -0
- package/dist/tools/explore/grep.js +203 -0
- package/dist/tools/explore/grep.js.map +1 -0
- package/dist/tools/explore/grep.test.d.ts +2 -0
- package/dist/tools/explore/grep.test.d.ts.map +1 -0
- package/dist/tools/explore/grep.test.js +132 -0
- package/dist/tools/explore/grep.test.js.map +1 -0
- package/dist/tools/explore/read-file.d.ts +23 -0
- package/dist/tools/explore/read-file.d.ts.map +1 -0
- package/dist/tools/explore/read-file.js +84 -0
- package/dist/tools/explore/read-file.js.map +1 -0
- package/dist/tools/explore/read-file.test.d.ts +2 -0
- package/dist/tools/explore/read-file.test.d.ts.map +1 -0
- package/dist/tools/explore/read-file.test.js +278 -0
- package/dist/tools/explore/read-file.test.js.map +1 -0
- package/dist/tools/index.d.ts +71 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +26 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/modify/delete-file.d.ts +19 -0
- package/dist/tools/modify/delete-file.d.ts.map +1 -0
- package/dist/tools/modify/delete-file.js +71 -0
- package/dist/tools/modify/delete-file.js.map +1 -0
- package/dist/tools/modify/delete-file.test.d.ts +2 -0
- package/dist/tools/modify/delete-file.test.d.ts.map +1 -0
- package/dist/tools/modify/delete-file.test.js +136 -0
- package/dist/tools/modify/delete-file.test.js.map +1 -0
- package/dist/tools/modify/edit-file-diagnostics.d.ts +17 -0
- package/dist/tools/modify/edit-file-diagnostics.d.ts.map +1 -0
- package/dist/tools/modify/edit-file-diagnostics.js +157 -0
- package/dist/tools/modify/edit-file-diagnostics.js.map +1 -0
- package/dist/tools/modify/edit-file-repair.d.ts +13 -0
- package/dist/tools/modify/edit-file-repair.d.ts.map +1 -0
- package/dist/tools/modify/edit-file-repair.js +135 -0
- package/dist/tools/modify/edit-file-repair.js.map +1 -0
- package/dist/tools/modify/edit-file-stress.test.d.ts +2 -0
- package/dist/tools/modify/edit-file-stress.test.d.ts.map +1 -0
- package/dist/tools/modify/edit-file-stress.test.js +163 -0
- package/dist/tools/modify/edit-file-stress.test.js.map +1 -0
- package/dist/tools/modify/edit-file-validation.d.ts +9 -0
- package/dist/tools/modify/edit-file-validation.d.ts.map +1 -0
- package/dist/tools/modify/edit-file-validation.js +86 -0
- package/dist/tools/modify/edit-file-validation.js.map +1 -0
- package/dist/tools/modify/edit-file-whitespace.test.d.ts +2 -0
- package/dist/tools/modify/edit-file-whitespace.test.d.ts.map +1 -0
- package/dist/tools/modify/edit-file-whitespace.test.js +90 -0
- package/dist/tools/modify/edit-file-whitespace.test.js.map +1 -0
- package/dist/tools/modify/edit-file.d.ts +33 -0
- package/dist/tools/modify/edit-file.d.ts.map +1 -0
- package/dist/tools/modify/edit-file.js +177 -0
- package/dist/tools/modify/edit-file.js.map +1 -0
- package/dist/tools/modify/edit-file.test.d.ts +2 -0
- package/dist/tools/modify/edit-file.test.d.ts.map +1 -0
- package/dist/tools/modify/edit-file.test.js +948 -0
- package/dist/tools/modify/edit-file.test.js.map +1 -0
- package/dist/tools/modify/write-file.d.ts +17 -0
- package/dist/tools/modify/write-file.d.ts.map +1 -0
- package/dist/tools/modify/write-file.js +39 -0
- package/dist/tools/modify/write-file.js.map +1 -0
- package/dist/tools/modify/write-file.test.d.ts +2 -0
- package/dist/tools/modify/write-file.test.d.ts.map +1 -0
- package/dist/tools/modify/write-file.test.js +168 -0
- package/dist/tools/modify/write-file.test.js.map +1 -0
- package/dist/tools/planning/load-skill.d.ts +13 -0
- package/dist/tools/planning/load-skill.d.ts.map +1 -0
- package/dist/tools/planning/load-skill.js +101 -0
- package/dist/tools/planning/load-skill.js.map +1 -0
- package/dist/tools/planning/load-skill.test.d.ts +2 -0
- package/dist/tools/planning/load-skill.test.d.ts.map +1 -0
- package/dist/tools/planning/load-skill.test.js +37 -0
- package/dist/tools/planning/load-skill.test.js.map +1 -0
- package/dist/tools/planning/todo-write.d.ts +49 -0
- package/dist/tools/planning/todo-write.d.ts.map +1 -0
- package/dist/tools/planning/todo-write.js +118 -0
- package/dist/tools/planning/todo-write.js.map +1 -0
- package/dist/tools/planning/todo-write.test.d.ts +2 -0
- package/dist/tools/planning/todo-write.test.d.ts.map +1 -0
- package/dist/tools/planning/todo-write.test.js +82 -0
- package/dist/tools/planning/todo-write.test.js.map +1 -0
- package/dist/tools/utils/execute/format-utils.d.ts +4 -0
- package/dist/tools/utils/execute/format-utils.d.ts.map +1 -0
- package/dist/tools/utils/execute/format-utils.js +31 -0
- package/dist/tools/utils/execute/format-utils.js.map +1 -0
- package/dist/tools/utils/execute/format-utils.test.d.ts +2 -0
- package/dist/tools/utils/execute/format-utils.test.d.ts.map +1 -0
- package/dist/tools/utils/execute/format-utils.test.js +40 -0
- package/dist/tools/utils/execute/format-utils.test.js.map +1 -0
- package/dist/tools/utils/execute/noninteractive-wrapper.d.ts +12 -0
- package/dist/tools/utils/execute/noninteractive-wrapper.d.ts.map +1 -0
- package/dist/tools/utils/execute/noninteractive-wrapper.js +269 -0
- package/dist/tools/utils/execute/noninteractive-wrapper.js.map +1 -0
- package/dist/tools/utils/execute/noninteractive-wrapper.test.d.ts +2 -0
- package/dist/tools/utils/execute/noninteractive-wrapper.test.d.ts.map +1 -0
- package/dist/tools/utils/execute/noninteractive-wrapper.test.js +233 -0
- package/dist/tools/utils/execute/noninteractive-wrapper.test.js.map +1 -0
- package/dist/tools/utils/execute/output-handler.d.ts +14 -0
- package/dist/tools/utils/execute/output-handler.d.ts.map +1 -0
- package/dist/tools/utils/execute/output-handler.js +71 -0
- package/dist/tools/utils/execute/output-handler.js.map +1 -0
- package/dist/tools/utils/execute/output-handler.test.d.ts +2 -0
- package/dist/tools/utils/execute/output-handler.test.d.ts.map +1 -0
- package/dist/tools/utils/execute/output-handler.test.js +58 -0
- package/dist/tools/utils/execute/output-handler.test.js.map +1 -0
- package/dist/tools/utils/execute/process-manager.d.ts +17 -0
- package/dist/tools/utils/execute/process-manager.d.ts.map +1 -0
- package/dist/tools/utils/execute/process-manager.js +229 -0
- package/dist/tools/utils/execute/process-manager.js.map +1 -0
- package/dist/tools/utils/execute/process-manager.test.d.ts +2 -0
- package/dist/tools/utils/execute/process-manager.test.d.ts.map +1 -0
- package/dist/tools/utils/execute/process-manager.test.js +139 -0
- package/dist/tools/utils/execute/process-manager.test.js.map +1 -0
- package/dist/tools/utils/execute/shell-detection.d.ts +3 -0
- package/dist/tools/utils/execute/shell-detection.d.ts.map +1 -0
- package/dist/tools/utils/execute/shell-detection.js +56 -0
- package/dist/tools/utils/execute/shell-detection.js.map +1 -0
- package/dist/tools/utils/execute/shell-detection.test.d.ts +2 -0
- package/dist/tools/utils/execute/shell-detection.test.d.ts.map +1 -0
- package/dist/tools/utils/execute/shell-detection.test.js +86 -0
- package/dist/tools/utils/execute/shell-detection.test.js.map +1 -0
- package/dist/tools/utils/hashline/autocorrect-replacement-lines.d.ts +5 -0
- package/dist/tools/utils/hashline/autocorrect-replacement-lines.d.ts.map +1 -0
- package/dist/tools/utils/hashline/autocorrect-replacement-lines.js +113 -0
- package/dist/tools/utils/hashline/autocorrect-replacement-lines.js.map +1 -0
- package/dist/tools/utils/hashline/constants.d.ts +5 -0
- package/dist/tools/utils/hashline/constants.d.ts.map +1 -0
- package/dist/tools/utils/hashline/constants.js +11 -0
- package/dist/tools/utils/hashline/constants.js.map +1 -0
- package/dist/tools/utils/hashline/diff-utils.d.ts +7 -0
- package/dist/tools/utils/hashline/diff-utils.d.ts.map +1 -0
- package/dist/tools/utils/hashline/diff-utils.js +50 -0
- package/dist/tools/utils/hashline/diff-utils.js.map +1 -0
- package/dist/tools/utils/hashline/diff-utils.test.d.ts +2 -0
- package/dist/tools/utils/hashline/diff-utils.test.d.ts.map +1 -0
- package/dist/tools/utils/hashline/diff-utils.test.js +46 -0
- package/dist/tools/utils/hashline/diff-utils.test.js.map +1 -0
- package/dist/tools/utils/hashline/edit-deduplication.d.ts +6 -0
- package/dist/tools/utils/hashline/edit-deduplication.d.ts.map +1 -0
- package/dist/tools/utils/hashline/edit-deduplication.js +32 -0
- package/dist/tools/utils/hashline/edit-deduplication.js.map +1 -0
- package/dist/tools/utils/hashline/edit-operation-primitives.d.ts +11 -0
- package/dist/tools/utils/hashline/edit-operation-primitives.d.ts.map +1 -0
- package/dist/tools/utils/hashline/edit-operation-primitives.js +93 -0
- package/dist/tools/utils/hashline/edit-operation-primitives.js.map +1 -0
- package/dist/tools/utils/hashline/edit-operations.d.ts +9 -0
- package/dist/tools/utils/hashline/edit-operations.d.ts.map +1 -0
- package/dist/tools/utils/hashline/edit-operations.js +101 -0
- package/dist/tools/utils/hashline/edit-operations.js.map +1 -0
- package/dist/tools/utils/hashline/edit-operations.test.d.ts +2 -0
- package/dist/tools/utils/hashline/edit-operations.test.d.ts.map +1 -0
- package/dist/tools/utils/hashline/edit-operations.test.js +135 -0
- package/dist/tools/utils/hashline/edit-operations.test.js.map +1 -0
- package/dist/tools/utils/hashline/edit-ordering.d.ts +5 -0
- package/dist/tools/utils/hashline/edit-ordering.d.ts.map +1 -0
- package/dist/tools/utils/hashline/edit-ordering.js +54 -0
- package/dist/tools/utils/hashline/edit-ordering.js.map +1 -0
- package/dist/tools/utils/hashline/edit-text-normalization.d.ts +9 -0
- package/dist/tools/utils/hashline/edit-text-normalization.d.ts.map +1 -0
- package/dist/tools/utils/hashline/edit-text-normalization.js +135 -0
- package/dist/tools/utils/hashline/edit-text-normalization.js.map +1 -0
- package/dist/tools/utils/hashline/file-text-canonicalization.d.ts +8 -0
- package/dist/tools/utils/hashline/file-text-canonicalization.d.ts.map +1 -0
- package/dist/tools/utils/hashline/file-text-canonicalization.js +42 -0
- package/dist/tools/utils/hashline/file-text-canonicalization.js.map +1 -0
- package/dist/tools/utils/hashline/hash-computation.d.ts +14 -0
- package/dist/tools/utils/hashline/hash-computation.d.ts.map +1 -0
- package/dist/tools/utils/hashline/hash-computation.js +158 -0
- package/dist/tools/utils/hashline/hash-computation.js.map +1 -0
- package/dist/tools/utils/hashline/hash-computation.test.d.ts +2 -0
- package/dist/tools/utils/hashline/hash-computation.test.d.ts.map +1 -0
- package/dist/tools/utils/hashline/hash-computation.test.js +63 -0
- package/dist/tools/utils/hashline/hash-computation.test.js.map +1 -0
- package/dist/tools/utils/hashline/hashline-chunk-formatter.d.ts +11 -0
- package/dist/tools/utils/hashline/hashline-chunk-formatter.d.ts.map +1 -0
- package/dist/tools/utils/hashline/hashline-chunk-formatter.js +41 -0
- package/dist/tools/utils/hashline/hashline-chunk-formatter.js.map +1 -0
- package/dist/tools/utils/hashline/hashline-edit-diff.d.ts +2 -0
- package/dist/tools/utils/hashline/hashline-edit-diff.d.ts.map +1 -0
- package/dist/tools/utils/hashline/hashline-edit-diff.js +27 -0
- package/dist/tools/utils/hashline/hashline-edit-diff.js.map +1 -0
- package/dist/tools/utils/hashline/index.d.ts +14 -0
- package/dist/tools/utils/hashline/index.d.ts.map +1 -0
- package/dist/tools/utils/hashline/index.js +11 -0
- package/dist/tools/utils/hashline/index.js.map +1 -0
- package/dist/tools/utils/hashline/merge-expansion.d.ts +4 -0
- package/dist/tools/utils/hashline/merge-expansion.d.ts.map +1 -0
- package/dist/tools/utils/hashline/merge-expansion.js +105 -0
- package/dist/tools/utils/hashline/merge-expansion.js.map +1 -0
- package/dist/tools/utils/hashline/normalize-edits.d.ts +11 -0
- package/dist/tools/utils/hashline/normalize-edits.d.ts.map +1 -0
- package/dist/tools/utils/hashline/normalize-edits.js +81 -0
- package/dist/tools/utils/hashline/normalize-edits.js.map +1 -0
- package/dist/tools/utils/hashline/types.d.ts +18 -0
- package/dist/tools/utils/hashline/types.d.ts.map +1 -0
- package/dist/tools/utils/hashline/types.js +2 -0
- package/dist/tools/utils/hashline/types.js.map +1 -0
- package/dist/tools/utils/hashline/validation.d.ts +19 -0
- package/dist/tools/utils/hashline/validation.d.ts.map +1 -0
- package/dist/tools/utils/hashline/validation.js +161 -0
- package/dist/tools/utils/hashline/validation.js.map +1 -0
- package/dist/tools/utils/hashline/validation.test.d.ts +2 -0
- package/dist/tools/utils/hashline/validation.test.d.ts.map +1 -0
- package/dist/tools/utils/hashline/validation.test.js +86 -0
- package/dist/tools/utils/hashline/validation.test.js.map +1 -0
- package/dist/tools/utils/safety-utils.d.ts +66 -0
- package/dist/tools/utils/safety-utils.d.ts.map +1 -0
- package/dist/tools/utils/safety-utils.js +681 -0
- package/dist/tools/utils/safety-utils.js.map +1 -0
- package/dist/utils/tools-manager.d.ts +16 -0
- package/dist/utils/tools-manager.d.ts.map +1 -0
- package/dist/utils/tools-manager.js +257 -0
- package/dist/utils/tools-manager.js.map +1 -0
- package/package.json +49 -0
- package/src/AGENTS.md +52 -0
- package/src/agent-reasoning-default.test.ts +48 -0
- package/src/agent.test.ts +49 -0
- package/src/agent.ts +455 -0
- package/src/cli-args.test.ts +152 -0
- package/src/cli-args.ts +90 -0
- package/src/commands/aliases-and-tool-fallback.test.ts +172 -0
- package/src/commands/clear.ts +14 -0
- package/src/commands/factories/create-toggle-command.ts +68 -0
- package/src/commands/help.ts +30 -0
- package/src/commands/index.ts +125 -0
- package/src/commands/model.ts +146 -0
- package/src/commands/reasoning-mode.ts +55 -0
- package/src/commands/render.test.ts +47 -0
- package/src/commands/render.ts +205 -0
- package/src/commands/tool-fallback.ts +47 -0
- package/src/commands/translate.test.ts +62 -0
- package/src/commands/translate.ts +14 -0
- package/src/commands/types.ts +18 -0
- package/src/context/environment-context.ts +11 -0
- package/src/context/paths.ts +2 -0
- package/src/context/session.ts +18 -0
- package/src/context/skill-command-prefix.ts +18 -0
- package/src/context/skills-integration.test.ts +113 -0
- package/src/context/skills.test.ts +25 -0
- package/src/context/skills.ts +566 -0
- package/src/context/system-prompt.ts +100 -0
- package/src/context/translation-integration.test.ts +194 -0
- package/src/context/translation.test.ts +186 -0
- package/src/context/translation.ts +122 -0
- package/src/entrypoints/AGENTS.md +33 -0
- package/src/entrypoints/cli-input-rendering.test.ts +236 -0
- package/src/entrypoints/cli.ts +1845 -0
- package/src/entrypoints/headless-agent-config.test.ts +82 -0
- package/src/entrypoints/headless-agent-config.ts +42 -0
- package/src/entrypoints/headless.ts +622 -0
- package/src/env.ts +14 -0
- package/src/friendli-models.ts +81 -0
- package/src/friendli-reasoning.test.ts +147 -0
- package/src/friendli-reasoning.ts +280 -0
- package/src/index.ts +3 -0
- package/src/interaction/colors.ts +24 -0
- package/src/interaction/pi-tui-stream-renderer.test.ts +1471 -0
- package/src/interaction/pi-tui-stream-renderer.ts +2150 -0
- package/src/interaction/spinner.ts +61 -0
- package/src/middleware/index.ts +32 -0
- package/src/middleware/todo-continuation.ts +128 -0
- package/src/middleware/trim-leading-newlines.ts +66 -0
- package/src/reasoning-mode.test.ts +24 -0
- package/src/reasoning-mode.ts +40 -0
- package/src/skills/example/SKILL.md +44 -0
- package/src/skills/example/references/api.md +37 -0
- package/src/skills/example/scripts/setup.sh +13 -0
- package/src/skills/git-workflow.md +405 -0
- package/src/tool-fallback-mode.ts +34 -0
- package/src/tools/AGENTS.md +44 -0
- package/src/tools/execute/shell-execute.test.ts +114 -0
- package/src/tools/execute/shell-execute.ts +74 -0
- package/src/tools/execute/shell-execute.txt +27 -0
- package/src/tools/execute/shell-interact.test.ts +236 -0
- package/src/tools/execute/shell-interact.ts +151 -0
- package/src/tools/execute/shell-interact.txt +15 -0
- package/src/tools/explore/glob-files.txt +8 -0
- package/src/tools/explore/glob.test.ts +217 -0
- package/src/tools/explore/glob.ts +137 -0
- package/src/tools/explore/grep-files.txt +12 -0
- package/src/tools/explore/grep.test.ts +183 -0
- package/src/tools/explore/grep.ts +266 -0
- package/src/tools/explore/read-file.test.ts +355 -0
- package/src/tools/explore/read-file.ts +102 -0
- package/src/tools/explore/read-file.txt +24 -0
- package/src/tools/index.ts +29 -0
- package/src/tools/modify/AGENTS.md +38 -0
- package/src/tools/modify/delete-file.test.ts +200 -0
- package/src/tools/modify/delete-file.ts +95 -0
- package/src/tools/modify/delete-file.txt +9 -0
- package/src/tools/modify/edit-file-diagnostics.ts +210 -0
- package/src/tools/modify/edit-file-repair.ts +183 -0
- package/src/tools/modify/edit-file-stress.test.ts +200 -0
- package/src/tools/modify/edit-file-validation.ts +134 -0
- package/src/tools/modify/edit-file-whitespace.test.ts +117 -0
- package/src/tools/modify/edit-file.test.ts +1231 -0
- package/src/tools/modify/edit-file.ts +252 -0
- package/src/tools/modify/edit-file.txt +73 -0
- package/src/tools/modify/write-file.test.ts +240 -0
- package/src/tools/modify/write-file.ts +56 -0
- package/src/tools/modify/write-file.txt +9 -0
- package/src/tools/planning/load-skill.test.ts +48 -0
- package/src/tools/planning/load-skill.ts +136 -0
- package/src/tools/planning/load-skill.txt +6 -0
- package/src/tools/planning/todo-write.test.ts +91 -0
- package/src/tools/planning/todo-write.ts +141 -0
- package/src/tools/planning/todo-write.txt +7 -0
- package/src/tools/utils/execute/format-utils.test.ts +53 -0
- package/src/tools/utils/execute/format-utils.ts +37 -0
- package/src/tools/utils/execute/noninteractive-wrapper.test.ts +306 -0
- package/src/tools/utils/execute/noninteractive-wrapper.ts +314 -0
- package/src/tools/utils/execute/output-handler.test.ts +72 -0
- package/src/tools/utils/execute/output-handler.ts +101 -0
- package/src/tools/utils/execute/process-manager.test.ts +175 -0
- package/src/tools/utils/execute/process-manager.ts +310 -0
- package/src/tools/utils/execute/shell-detection.test.ts +112 -0
- package/src/tools/utils/execute/shell-detection.ts +72 -0
- package/src/tools/utils/hashline/autocorrect-replacement-lines.ts +159 -0
- package/src/tools/utils/hashline/constants.ts +13 -0
- package/src/tools/utils/hashline/diff-utils.test.ts +61 -0
- package/src/tools/utils/hashline/diff-utils.ts +64 -0
- package/src/tools/utils/hashline/edit-deduplication.ts +40 -0
- package/src/tools/utils/hashline/edit-operation-primitives.ts +149 -0
- package/src/tools/utils/hashline/edit-operations.test.ts +154 -0
- package/src/tools/utils/hashline/edit-operations.ts +132 -0
- package/src/tools/utils/hashline/edit-ordering.ts +60 -0
- package/src/tools/utils/hashline/edit-text-normalization.ts +180 -0
- package/src/tools/utils/hashline/file-text-canonicalization.ts +58 -0
- package/src/tools/utils/hashline/hash-computation.test.ts +82 -0
- package/src/tools/utils/hashline/hash-computation.ts +199 -0
- package/src/tools/utils/hashline/hashline-chunk-formatter.ts +61 -0
- package/src/tools/utils/hashline/hashline-edit-diff.ts +35 -0
- package/src/tools/utils/hashline/index.ts +55 -0
- package/src/tools/utils/hashline/merge-expansion.ts +120 -0
- package/src/tools/utils/hashline/normalize-edits.ts +127 -0
- package/src/tools/utils/hashline/types.ts +20 -0
- package/src/tools/utils/hashline/validation.test.ts +109 -0
- package/src/tools/utils/hashline/validation.ts +212 -0
- package/src/tools/utils/safety-utils.ts +938 -0
- package/src/utils/tools-manager.ts +353 -0
|
@@ -0,0 +1,1845 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
|
|
3
|
+
import { stripVTControlCharacters } from "node:util";
|
|
4
|
+
import {
|
|
5
|
+
MANUAL_TOOL_LOOP_MAX_STEPS,
|
|
6
|
+
MessageHistory,
|
|
7
|
+
shouldContinueManualToolLoop,
|
|
8
|
+
} from "@ai-sdk-tool/harness";
|
|
9
|
+
import {
|
|
10
|
+
type AutocompleteItem,
|
|
11
|
+
type AutocompleteProvider,
|
|
12
|
+
CombinedAutocompleteProvider,
|
|
13
|
+
Container,
|
|
14
|
+
Editor,
|
|
15
|
+
type EditorTheme,
|
|
16
|
+
Input,
|
|
17
|
+
isKeyRelease,
|
|
18
|
+
isKeyRepeat,
|
|
19
|
+
Key,
|
|
20
|
+
Loader,
|
|
21
|
+
Markdown,
|
|
22
|
+
type MarkdownTheme,
|
|
23
|
+
matchesKey,
|
|
24
|
+
ProcessTerminal,
|
|
25
|
+
SelectList,
|
|
26
|
+
type SlashCommand,
|
|
27
|
+
Spacer,
|
|
28
|
+
Text,
|
|
29
|
+
TUI,
|
|
30
|
+
} from "@mariozechner/pi-tui";
|
|
31
|
+
import type { ProviderType } from "../agent";
|
|
32
|
+
import { agentManager } from "../agent";
|
|
33
|
+
import {
|
|
34
|
+
parseProviderArg,
|
|
35
|
+
parseReasoningCliOption,
|
|
36
|
+
parseToolFallbackCliOption,
|
|
37
|
+
parseTranslateCliOption,
|
|
38
|
+
} from "../cli-args";
|
|
39
|
+
import {
|
|
40
|
+
executeCommand,
|
|
41
|
+
getCommands,
|
|
42
|
+
isCommand,
|
|
43
|
+
isSkillCommandResult,
|
|
44
|
+
parseCommand,
|
|
45
|
+
registerCommand,
|
|
46
|
+
resolveRegisteredCommandName,
|
|
47
|
+
} from "../commands";
|
|
48
|
+
import { createClearCommand } from "../commands/clear";
|
|
49
|
+
import {
|
|
50
|
+
applyModelSelection,
|
|
51
|
+
createModelCommand,
|
|
52
|
+
findModelBySelection,
|
|
53
|
+
getAvailableModels,
|
|
54
|
+
type ModelInfo,
|
|
55
|
+
} from "../commands/model";
|
|
56
|
+
import { createReasoningModeCommand } from "../commands/reasoning-mode";
|
|
57
|
+
import { createRenderCommand } from "../commands/render";
|
|
58
|
+
import { createToolFallbackCommand } from "../commands/tool-fallback";
|
|
59
|
+
import { createTranslateCommand } from "../commands/translate";
|
|
60
|
+
import { getSessionId, initializeSession } from "../context/session";
|
|
61
|
+
import { toPromptsCommandName } from "../context/skill-command-prefix";
|
|
62
|
+
import type { SkillInfo } from "../context/skills";
|
|
63
|
+
import { loadAllSkills } from "../context/skills";
|
|
64
|
+
import { isNonEnglish, translateToEnglish } from "../context/translation";
|
|
65
|
+
import { env } from "../env";
|
|
66
|
+
import { renderFullStreamWithPiTui } from "../interaction/pi-tui-stream-renderer";
|
|
67
|
+
import { setSpinnerOutputEnabled } from "../interaction/spinner";
|
|
68
|
+
import {
|
|
69
|
+
buildTodoContinuationUserMessage,
|
|
70
|
+
getIncompleteTodos,
|
|
71
|
+
} from "../middleware/todo-continuation";
|
|
72
|
+
import {
|
|
73
|
+
DEFAULT_REASONING_MODE,
|
|
74
|
+
parseReasoningMode,
|
|
75
|
+
type ReasoningMode,
|
|
76
|
+
} from "../reasoning-mode";
|
|
77
|
+
import {
|
|
78
|
+
DEFAULT_TOOL_FALLBACK_MODE,
|
|
79
|
+
parseToolFallbackMode,
|
|
80
|
+
TOOL_FALLBACK_MODES,
|
|
81
|
+
type ToolFallbackMode,
|
|
82
|
+
} from "../tool-fallback-mode";
|
|
83
|
+
import { cleanup } from "../tools/utils/execute/process-manager";
|
|
84
|
+
import { initializeTools } from "../utils/tools-manager";
|
|
85
|
+
|
|
86
|
+
const ANSI_RESET = "\x1b[0m";
|
|
87
|
+
const ANSI_BLACK = "\x1b[30m";
|
|
88
|
+
const ANSI_BOLD = "\x1b[1m";
|
|
89
|
+
const ANSI_DIM = "\x1b[2m";
|
|
90
|
+
const ANSI_ITALIC = "\x1b[3m";
|
|
91
|
+
const ANSI_UNDERLINE = "\x1b[4m";
|
|
92
|
+
const ANSI_BG_GRAY = "\x1b[100m";
|
|
93
|
+
const ANSI_BG_SOFT_LIGHT = "\x1b[48;5;249m";
|
|
94
|
+
const ANSI_GREEN = "\x1b[92m";
|
|
95
|
+
const ANSI_YELLOW = "\x1b[93m";
|
|
96
|
+
const ANSI_MAGENTA = "\x1b[95m";
|
|
97
|
+
const ANSI_CYAN = "\x1b[36m";
|
|
98
|
+
const ANSI_BRIGHT_CYAN = "\x1b[96m";
|
|
99
|
+
const ANSI_GRAY = "\x1b[90m";
|
|
100
|
+
const CTRL_C_ETX = "\u0003";
|
|
101
|
+
const CTRL_C_EXIT_WINDOW_MS = 500;
|
|
102
|
+
|
|
103
|
+
const messageHistory = new MessageHistory();
|
|
104
|
+
let cachedSkills: SkillInfo[] = [];
|
|
105
|
+
let shouldExit = false;
|
|
106
|
+
let activeStreamController: AbortController | null = null;
|
|
107
|
+
let streamInterruptRequested = false;
|
|
108
|
+
let activeUiForSignals: { requestExit: () => void } | null = null;
|
|
109
|
+
let requestedProcessExitCode: number | null = null;
|
|
110
|
+
let signalShutdownRequested = false;
|
|
111
|
+
|
|
112
|
+
const cancelActiveStream = (): boolean => {
|
|
113
|
+
if (!activeStreamController || activeStreamController.signal.aborted) {
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
streamInterruptRequested = true;
|
|
118
|
+
activeStreamController.abort("User requested stream interruption");
|
|
119
|
+
return true;
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
const clearActiveStreamController = (
|
|
123
|
+
streamController: AbortController
|
|
124
|
+
): void => {
|
|
125
|
+
if (activeStreamController === streamController) {
|
|
126
|
+
activeStreamController = null;
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
const style = (prefix: string, text: string): string => {
|
|
131
|
+
return `${prefix}${text}${ANSI_RESET}`;
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
const sanitizeCodeFence = (text: string): string => {
|
|
135
|
+
return text.replaceAll("```", "` ` `");
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
const stripAnsi = (value: string): string => {
|
|
139
|
+
if (typeof stripVTControlCharacters === "function") {
|
|
140
|
+
return stripVTControlCharacters(value);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
let output = "";
|
|
144
|
+
let index = 0;
|
|
145
|
+
|
|
146
|
+
while (index < value.length) {
|
|
147
|
+
const char = value[index];
|
|
148
|
+
if (char === "\u001b") {
|
|
149
|
+
index += 1;
|
|
150
|
+
if (index < value.length && value[index] === "[") {
|
|
151
|
+
index += 1;
|
|
152
|
+
while (index < value.length) {
|
|
153
|
+
const code = value.charCodeAt(index);
|
|
154
|
+
index += 1;
|
|
155
|
+
if (code >= 0x40 && code <= 0x7e) {
|
|
156
|
+
break;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
output += char;
|
|
164
|
+
index += 1;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
return output;
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
const createMarkdownTheme = (): MarkdownTheme => {
|
|
171
|
+
return {
|
|
172
|
+
heading: (text) => style(`${ANSI_BOLD}${ANSI_BRIGHT_CYAN}`, text),
|
|
173
|
+
link: (text) => style(`${ANSI_UNDERLINE}${ANSI_CYAN}`, text),
|
|
174
|
+
linkUrl: (text) => style(ANSI_GRAY, text),
|
|
175
|
+
code: (text) => style(ANSI_YELLOW, text),
|
|
176
|
+
codeBlock: (text) => style(ANSI_GREEN, text),
|
|
177
|
+
codeBlockBorder: (text) => style(ANSI_GRAY, text),
|
|
178
|
+
quote: (text) => style(`${ANSI_ITALIC}${ANSI_GRAY}`, text),
|
|
179
|
+
quoteBorder: (text) => style(ANSI_GRAY, text),
|
|
180
|
+
hr: (text) => style(ANSI_GRAY, text),
|
|
181
|
+
listBullet: (text) => style(ANSI_MAGENTA, text),
|
|
182
|
+
bold: (text) => style(ANSI_BOLD, text),
|
|
183
|
+
italic: (text) => style(ANSI_ITALIC, text),
|
|
184
|
+
strikethrough: (text) => style(ANSI_DIM, text),
|
|
185
|
+
underline: (text) => style(ANSI_UNDERLINE, text),
|
|
186
|
+
codeBlockIndent: " ",
|
|
187
|
+
};
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
const createEditorTheme = (): EditorTheme => {
|
|
191
|
+
return {
|
|
192
|
+
borderColor: (text: string) => style(ANSI_GRAY, text),
|
|
193
|
+
selectList: {
|
|
194
|
+
selectedPrefix: (text: string) => style(`${ANSI_BOLD}${ANSI_CYAN}`, text),
|
|
195
|
+
selectedText: (text: string) => style(ANSI_CYAN, text),
|
|
196
|
+
description: (text: string) => style(ANSI_GRAY, text),
|
|
197
|
+
scrollInfo: (text: string) => style(ANSI_DIM, text),
|
|
198
|
+
noMatch: (text: string) => style(ANSI_DIM, text),
|
|
199
|
+
},
|
|
200
|
+
};
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
const addUserMessage = (
|
|
204
|
+
chatContainer: Container,
|
|
205
|
+
markdownTheme: MarkdownTheme,
|
|
206
|
+
message: string
|
|
207
|
+
): void => {
|
|
208
|
+
chatContainer.addChild(new Spacer(1));
|
|
209
|
+
|
|
210
|
+
chatContainer.addChild(
|
|
211
|
+
new Markdown(message, 1, 1, markdownTheme, {
|
|
212
|
+
bgColor: (text: string) =>
|
|
213
|
+
style(`${ANSI_BG_SOFT_LIGHT}${ANSI_BLACK}`, text),
|
|
214
|
+
})
|
|
215
|
+
);
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
const addTranslatedMessage = (
|
|
219
|
+
chatContainer: Container,
|
|
220
|
+
markdownTheme: MarkdownTheme,
|
|
221
|
+
message: string
|
|
222
|
+
): void => {
|
|
223
|
+
chatContainer.addChild(new Spacer(1));
|
|
224
|
+
chatContainer.addChild(
|
|
225
|
+
new Markdown(message, 1, 1, markdownTheme, {
|
|
226
|
+
bgColor: (text: string) => style(ANSI_BG_GRAY, text),
|
|
227
|
+
})
|
|
228
|
+
);
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
const addSystemMessage = (chatContainer: Container, message: string): void => {
|
|
232
|
+
const cleaned = stripAnsi(message).trimEnd();
|
|
233
|
+
|
|
234
|
+
if (cleaned.length === 0) {
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
chatContainer.addChild(new Spacer(1));
|
|
239
|
+
chatContainer.addChild(
|
|
240
|
+
new Text(style(ANSI_GRAY, sanitizeCodeFence(cleaned)), 1, 0)
|
|
241
|
+
);
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
const addNewSessionMessage = (chatContainer: Container): void => {
|
|
245
|
+
chatContainer.addChild(new Spacer(1));
|
|
246
|
+
chatContainer.addChild(
|
|
247
|
+
new Text(style(ANSI_BRIGHT_CYAN, "✓ New session started"), 1, 1)
|
|
248
|
+
);
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
const SKILL_LABEL_MAX_WIDTH = 24;
|
|
252
|
+
const MODEL_LABEL_MAX_WIDTH = 26;
|
|
253
|
+
const MODEL_NAME_MAX_WIDTH = 28;
|
|
254
|
+
|
|
255
|
+
type SlashAutocompleteEntry = SlashCommand | AutocompleteItem;
|
|
256
|
+
|
|
257
|
+
const truncateAutocompleteLabel = (value: string, maxWidth: number): string => {
|
|
258
|
+
if (value.length <= maxWidth) {
|
|
259
|
+
return value;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
if (maxWidth <= 1) {
|
|
263
|
+
return "…";
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
return `${value.slice(0, maxWidth - 1)}…`;
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
const toAutocompleteEntryValue = (entry: SlashAutocompleteEntry): string => {
|
|
270
|
+
return "name" in entry ? entry.name : entry.value;
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
const buildModelSelectorDescription = (
|
|
274
|
+
modelName: string | undefined,
|
|
275
|
+
providerLabel: string
|
|
276
|
+
): string => {
|
|
277
|
+
if (!modelName) {
|
|
278
|
+
return providerLabel;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
const truncatedName = truncateAutocompleteLabel(
|
|
282
|
+
modelName,
|
|
283
|
+
MODEL_NAME_MAX_WIDTH
|
|
284
|
+
);
|
|
285
|
+
return `${truncatedName} - ${providerLabel}`;
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
const buildModelSelectorLabel = (
|
|
289
|
+
modelId: string,
|
|
290
|
+
isCurrent: boolean
|
|
291
|
+
): string => {
|
|
292
|
+
const currentMarker = isCurrent ? "* " : " ";
|
|
293
|
+
const truncatedModelId = truncateAutocompleteLabel(
|
|
294
|
+
modelId,
|
|
295
|
+
MODEL_LABEL_MAX_WIDTH
|
|
296
|
+
);
|
|
297
|
+
return `${currentMarker}${truncatedModelId}`;
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
const buildCurrentIndicatorLabel = (
|
|
301
|
+
label: string,
|
|
302
|
+
isCurrent: boolean
|
|
303
|
+
): string => {
|
|
304
|
+
const currentMarker = isCurrent ? "* " : " ";
|
|
305
|
+
return `${currentMarker}${label}`;
|
|
306
|
+
};
|
|
307
|
+
|
|
308
|
+
const createAutocompleteCommands = (
|
|
309
|
+
skills: SkillInfo[]
|
|
310
|
+
): SlashAutocompleteEntry[] => {
|
|
311
|
+
const createCommandSuggestion = (
|
|
312
|
+
command: {
|
|
313
|
+
argumentSuggestions?: string[];
|
|
314
|
+
description: string;
|
|
315
|
+
name: string;
|
|
316
|
+
},
|
|
317
|
+
name: string,
|
|
318
|
+
description: string
|
|
319
|
+
): SlashCommand => {
|
|
320
|
+
const suggestions = command.argumentSuggestions;
|
|
321
|
+
|
|
322
|
+
return {
|
|
323
|
+
name,
|
|
324
|
+
description,
|
|
325
|
+
getArgumentCompletions:
|
|
326
|
+
suggestions && suggestions.length > 0
|
|
327
|
+
? (argumentPrefix: string) => {
|
|
328
|
+
const matches = suggestions.filter((suggestion) =>
|
|
329
|
+
suggestion
|
|
330
|
+
.toLowerCase()
|
|
331
|
+
.startsWith(argumentPrefix.toLowerCase())
|
|
332
|
+
);
|
|
333
|
+
|
|
334
|
+
if (matches.length === 0) {
|
|
335
|
+
return null;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
return matches.map((match) => ({
|
|
339
|
+
value: match,
|
|
340
|
+
label: match,
|
|
341
|
+
}));
|
|
342
|
+
}
|
|
343
|
+
: undefined,
|
|
344
|
+
} satisfies SlashCommand;
|
|
345
|
+
};
|
|
346
|
+
|
|
347
|
+
const commandSuggestions = Array.from(getCommands().values()).map(
|
|
348
|
+
(command) => {
|
|
349
|
+
const aliases =
|
|
350
|
+
"aliases" in command && Array.isArray(command.aliases)
|
|
351
|
+
? command.aliases
|
|
352
|
+
: [];
|
|
353
|
+
const aliasSuffix =
|
|
354
|
+
aliases.length > 0 ? ` (aliases: ${aliases.join(", ")})` : "";
|
|
355
|
+
|
|
356
|
+
return createCommandSuggestion(
|
|
357
|
+
command,
|
|
358
|
+
command.name,
|
|
359
|
+
`${command.description}${aliasSuffix}`
|
|
360
|
+
);
|
|
361
|
+
}
|
|
362
|
+
);
|
|
363
|
+
|
|
364
|
+
const skillSuggestions: AutocompleteItem[] = skills.map((skill) => {
|
|
365
|
+
const commandName = toPromptsCommandName(skill.id);
|
|
366
|
+
return {
|
|
367
|
+
value: commandName,
|
|
368
|
+
label: truncateAutocompleteLabel(commandName, SKILL_LABEL_MAX_WIDTH),
|
|
369
|
+
description: skill.description,
|
|
370
|
+
};
|
|
371
|
+
});
|
|
372
|
+
|
|
373
|
+
const suggestions: SlashAutocompleteEntry[] = [
|
|
374
|
+
...commandSuggestions,
|
|
375
|
+
...skillSuggestions,
|
|
376
|
+
];
|
|
377
|
+
const seenNames = new Set<string>();
|
|
378
|
+
const uniqueSuggestions: SlashAutocompleteEntry[] = [];
|
|
379
|
+
|
|
380
|
+
for (const suggestion of suggestions) {
|
|
381
|
+
const normalizedName = toAutocompleteEntryValue(suggestion).toLowerCase();
|
|
382
|
+
if (seenNames.has(normalizedName)) {
|
|
383
|
+
continue;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
seenNames.add(normalizedName);
|
|
387
|
+
uniqueSuggestions.push(suggestion);
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
return uniqueSuggestions;
|
|
391
|
+
};
|
|
392
|
+
|
|
393
|
+
const toAutocompleteItem = (suggestion: SlashCommand): AutocompleteItem => ({
|
|
394
|
+
value: suggestion.name,
|
|
395
|
+
label: suggestion.name,
|
|
396
|
+
...(suggestion.description ? { description: suggestion.description } : {}),
|
|
397
|
+
});
|
|
398
|
+
|
|
399
|
+
const buildCommandSuggestionsByName = (
|
|
400
|
+
slashCommands: SlashAutocompleteEntry[]
|
|
401
|
+
): Map<string, SlashCommand> => {
|
|
402
|
+
const commandSuggestionsByName = new Map<string, SlashCommand>();
|
|
403
|
+
|
|
404
|
+
for (const suggestion of slashCommands) {
|
|
405
|
+
if (!("name" in suggestion)) {
|
|
406
|
+
continue;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
commandSuggestionsByName.set(suggestion.name.toLowerCase(), suggestion);
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
return commandSuggestionsByName;
|
|
413
|
+
};
|
|
414
|
+
|
|
415
|
+
const buildAliasToCanonicalNameMap = (): Map<string, string> => {
|
|
416
|
+
const aliasToCanonicalName = new Map<string, string>();
|
|
417
|
+
|
|
418
|
+
for (const command of getCommands().values()) {
|
|
419
|
+
const canonicalName = command.name.toLowerCase();
|
|
420
|
+
|
|
421
|
+
for (const alias of command.aliases ?? []) {
|
|
422
|
+
const normalizedAlias = alias.toLowerCase();
|
|
423
|
+
if (normalizedAlias === canonicalName) {
|
|
424
|
+
continue;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
aliasToCanonicalName.set(normalizedAlias, canonicalName);
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
return aliasToCanonicalName;
|
|
432
|
+
};
|
|
433
|
+
|
|
434
|
+
const getAliasArgumentSuggestions = (
|
|
435
|
+
textBeforeCursor: string,
|
|
436
|
+
commandSuggestionsByName: Map<string, SlashCommand>
|
|
437
|
+
): { items: AutocompleteItem[]; prefix: string } | null => {
|
|
438
|
+
const spaceIndex = textBeforeCursor.indexOf(" ");
|
|
439
|
+
if (spaceIndex < 0) {
|
|
440
|
+
return null;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
const commandName = textBeforeCursor.slice(1, spaceIndex).toLowerCase();
|
|
444
|
+
const resolvedName = resolveRegisteredCommandName(commandName);
|
|
445
|
+
if (resolvedName === commandName) {
|
|
446
|
+
return null;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
const command = commandSuggestionsByName.get(resolvedName);
|
|
450
|
+
if (!command?.getArgumentCompletions) {
|
|
451
|
+
return null;
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
const argumentPrefix = textBeforeCursor.slice(spaceIndex + 1);
|
|
455
|
+
const items = command.getArgumentCompletions(argumentPrefix);
|
|
456
|
+
if (!items || items.length === 0) {
|
|
457
|
+
return null;
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
return {
|
|
461
|
+
items,
|
|
462
|
+
prefix: argumentPrefix,
|
|
463
|
+
};
|
|
464
|
+
};
|
|
465
|
+
|
|
466
|
+
const getAliasMatches = (
|
|
467
|
+
query: string,
|
|
468
|
+
aliasToCanonicalName: Map<string, string>,
|
|
469
|
+
commandSuggestionsByName: Map<string, SlashCommand>
|
|
470
|
+
): AutocompleteItem[] => {
|
|
471
|
+
const aliasMatches: AutocompleteItem[] = [];
|
|
472
|
+
const seenCanonicalNames = new Set<string>();
|
|
473
|
+
|
|
474
|
+
for (const [alias, canonicalName] of aliasToCanonicalName) {
|
|
475
|
+
if (!alias.startsWith(query) || seenCanonicalNames.has(canonicalName)) {
|
|
476
|
+
continue;
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
const suggestion = commandSuggestionsByName.get(canonicalName);
|
|
480
|
+
if (!suggestion) {
|
|
481
|
+
continue;
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
seenCanonicalNames.add(canonicalName);
|
|
485
|
+
aliasMatches.push(toAutocompleteItem(suggestion));
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
return aliasMatches;
|
|
489
|
+
};
|
|
490
|
+
|
|
491
|
+
const mergeAutocompleteItems = (
|
|
492
|
+
prioritizedItems: AutocompleteItem[],
|
|
493
|
+
fallbackItems: AutocompleteItem[] = []
|
|
494
|
+
): AutocompleteItem[] => {
|
|
495
|
+
const mergedItems: AutocompleteItem[] = [];
|
|
496
|
+
const seenValues = new Set<string>();
|
|
497
|
+
|
|
498
|
+
for (const item of [...prioritizedItems, ...fallbackItems]) {
|
|
499
|
+
const normalizedValue = item.value.toLowerCase();
|
|
500
|
+
if (seenValues.has(normalizedValue)) {
|
|
501
|
+
continue;
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
seenValues.add(normalizedValue);
|
|
505
|
+
mergedItems.push(item);
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
return mergedItems;
|
|
509
|
+
};
|
|
510
|
+
|
|
511
|
+
const createAliasAwareAutocompleteProvider = (
|
|
512
|
+
skills: SkillInfo[]
|
|
513
|
+
): AutocompleteProvider => {
|
|
514
|
+
const slashCommands = createAutocompleteCommands(skills);
|
|
515
|
+
const fallbackProvider = new CombinedAutocompleteProvider(
|
|
516
|
+
slashCommands,
|
|
517
|
+
process.cwd()
|
|
518
|
+
);
|
|
519
|
+
const commandSuggestionsByName = buildCommandSuggestionsByName(slashCommands);
|
|
520
|
+
const aliasToCanonicalName = buildAliasToCanonicalNameMap();
|
|
521
|
+
|
|
522
|
+
return {
|
|
523
|
+
getSuggestions: (lines, cursorLine, cursorCol) => {
|
|
524
|
+
const currentLine = lines[cursorLine] ?? "";
|
|
525
|
+
const textBeforeCursor = currentLine.slice(0, cursorCol);
|
|
526
|
+
|
|
527
|
+
if (!textBeforeCursor.startsWith("/")) {
|
|
528
|
+
return fallbackProvider.getSuggestions(lines, cursorLine, cursorCol);
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
const aliasArgumentSuggestions = getAliasArgumentSuggestions(
|
|
532
|
+
textBeforeCursor,
|
|
533
|
+
commandSuggestionsByName
|
|
534
|
+
);
|
|
535
|
+
if (aliasArgumentSuggestions) {
|
|
536
|
+
return aliasArgumentSuggestions;
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
const defaultSuggestions = fallbackProvider.getSuggestions(
|
|
540
|
+
lines,
|
|
541
|
+
cursorLine,
|
|
542
|
+
cursorCol
|
|
543
|
+
);
|
|
544
|
+
|
|
545
|
+
if (textBeforeCursor.includes(" ")) {
|
|
546
|
+
return defaultSuggestions;
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
const query = textBeforeCursor.slice(1).toLowerCase();
|
|
550
|
+
if (query.length === 0) {
|
|
551
|
+
return defaultSuggestions;
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
const aliasMatches = getAliasMatches(
|
|
555
|
+
query,
|
|
556
|
+
aliasToCanonicalName,
|
|
557
|
+
commandSuggestionsByName
|
|
558
|
+
);
|
|
559
|
+
|
|
560
|
+
if (aliasMatches.length === 0) {
|
|
561
|
+
return defaultSuggestions;
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
return {
|
|
565
|
+
items: mergeAutocompleteItems(aliasMatches, defaultSuggestions?.items),
|
|
566
|
+
prefix: textBeforeCursor,
|
|
567
|
+
};
|
|
568
|
+
},
|
|
569
|
+
applyCompletion: (lines, cursorLine, cursorCol, item, prefix) =>
|
|
570
|
+
fallbackProvider.applyCompletion(
|
|
571
|
+
lines,
|
|
572
|
+
cursorLine,
|
|
573
|
+
cursorCol,
|
|
574
|
+
item,
|
|
575
|
+
prefix
|
|
576
|
+
),
|
|
577
|
+
};
|
|
578
|
+
};
|
|
579
|
+
|
|
580
|
+
interface CliUi {
|
|
581
|
+
chatContainer: Container;
|
|
582
|
+
clearStatus: () => void;
|
|
583
|
+
dispose: () => Promise<void>;
|
|
584
|
+
editor: Editor;
|
|
585
|
+
markdownTheme: MarkdownTheme;
|
|
586
|
+
requestExit: () => void;
|
|
587
|
+
showLoader: (message: string) => void;
|
|
588
|
+
showModelSelector: (
|
|
589
|
+
models: ModelInfo[],
|
|
590
|
+
currentModelId: string,
|
|
591
|
+
currentProvider: ProviderType,
|
|
592
|
+
initialFilter?: string
|
|
593
|
+
) => Promise<ModelInfo | null>;
|
|
594
|
+
showReasoningModeSelector: (
|
|
595
|
+
currentMode: ReasoningMode
|
|
596
|
+
) => Promise<ReasoningMode | null>;
|
|
597
|
+
showToolFallbackSelector: (
|
|
598
|
+
currentMode: ToolFallbackMode
|
|
599
|
+
) => Promise<ToolFallbackMode | null>;
|
|
600
|
+
showTranslateModeSelector: (
|
|
601
|
+
currentEnabled: boolean
|
|
602
|
+
) => Promise<boolean | null>;
|
|
603
|
+
tui: TUI;
|
|
604
|
+
updateHeader: () => void;
|
|
605
|
+
waitForInput: () => Promise<string | null>;
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
const createCliUi = (skills: SkillInfo[]): CliUi => {
|
|
609
|
+
const markdownTheme = createMarkdownTheme();
|
|
610
|
+
const terminal = new ProcessTerminal();
|
|
611
|
+
const tui = new TUI(terminal);
|
|
612
|
+
tui.setClearOnShrink(true);
|
|
613
|
+
const headerContainer = new Container();
|
|
614
|
+
const chatContainer = new Container();
|
|
615
|
+
const statusContainer = new Container();
|
|
616
|
+
const editorContainer = new Container();
|
|
617
|
+
|
|
618
|
+
const title = new Text("", 1, 0);
|
|
619
|
+
const help = new Text(
|
|
620
|
+
style(
|
|
621
|
+
ANSI_DIM,
|
|
622
|
+
"Enter to submit, Shift+Enter for newline, /help for commands, Ctrl+C clears input, Ctrl+C again exits"
|
|
623
|
+
),
|
|
624
|
+
1,
|
|
625
|
+
0
|
|
626
|
+
);
|
|
627
|
+
|
|
628
|
+
const updateHeader = (): void => {
|
|
629
|
+
const sessionId = getSessionId();
|
|
630
|
+
const provider = agentManager.getProvider();
|
|
631
|
+
const model = agentManager.getModelId();
|
|
632
|
+
title.setText(
|
|
633
|
+
`${style(`${ANSI_BOLD}${ANSI_BRIGHT_CYAN}`, "Code Editing Agent")} ${style(
|
|
634
|
+
ANSI_DIM,
|
|
635
|
+
`${provider}/${model}`
|
|
636
|
+
)}\n${style(ANSI_DIM, `Session: ${sessionId}`)}`
|
|
637
|
+
);
|
|
638
|
+
tui.requestRender();
|
|
639
|
+
};
|
|
640
|
+
|
|
641
|
+
headerContainer.addChild(new Spacer(1));
|
|
642
|
+
headerContainer.addChild(title);
|
|
643
|
+
headerContainer.addChild(help);
|
|
644
|
+
headerContainer.addChild(new Spacer(1));
|
|
645
|
+
|
|
646
|
+
const editorTheme = createEditorTheme();
|
|
647
|
+
const editor = new Editor(tui, editorTheme, {
|
|
648
|
+
paddingX: 1,
|
|
649
|
+
autocompleteMaxVisible: 8,
|
|
650
|
+
});
|
|
651
|
+
editor.setAutocompleteProvider(createAliasAwareAutocompleteProvider(skills));
|
|
652
|
+
|
|
653
|
+
editorContainer.addChild(editor);
|
|
654
|
+
|
|
655
|
+
tui.addChild(headerContainer);
|
|
656
|
+
tui.addChild(chatContainer);
|
|
657
|
+
tui.addChild(statusContainer);
|
|
658
|
+
tui.addChild(editorContainer);
|
|
659
|
+
tui.setFocus(editor);
|
|
660
|
+
|
|
661
|
+
let loader: Loader | null = null;
|
|
662
|
+
let inputResolver: ((value: string | null) => void) | null = null;
|
|
663
|
+
let pendingExitConfirmation = false;
|
|
664
|
+
let lastCtrlCPressAt = 0;
|
|
665
|
+
let activeModalCancel: (() => void) | null = null;
|
|
666
|
+
|
|
667
|
+
const clearStatus = (): void => {
|
|
668
|
+
if (loader) {
|
|
669
|
+
loader.stop();
|
|
670
|
+
statusContainer.removeChild(loader);
|
|
671
|
+
loader = null;
|
|
672
|
+
}
|
|
673
|
+
statusContainer.clear();
|
|
674
|
+
tui.requestRender();
|
|
675
|
+
};
|
|
676
|
+
|
|
677
|
+
const showLoader = (message: string): void => {
|
|
678
|
+
clearStatus();
|
|
679
|
+
loader = new Loader(
|
|
680
|
+
tui,
|
|
681
|
+
(text: string) => style(ANSI_CYAN, text),
|
|
682
|
+
(text: string) => style(ANSI_DIM, text),
|
|
683
|
+
message
|
|
684
|
+
);
|
|
685
|
+
statusContainer.addChild(loader);
|
|
686
|
+
loader.start();
|
|
687
|
+
tui.requestRender();
|
|
688
|
+
};
|
|
689
|
+
|
|
690
|
+
const clearPromptInput = (): void => {
|
|
691
|
+
editor.setText("");
|
|
692
|
+
tui.setFocus(editor);
|
|
693
|
+
tui.requestRender();
|
|
694
|
+
};
|
|
695
|
+
|
|
696
|
+
const clearPendingExitConfirmation = (): void => {
|
|
697
|
+
pendingExitConfirmation = false;
|
|
698
|
+
};
|
|
699
|
+
|
|
700
|
+
const setActiveModalCancel = (cancel: (() => void) | null): void => {
|
|
701
|
+
activeModalCancel = cancel;
|
|
702
|
+
};
|
|
703
|
+
|
|
704
|
+
const dismissActiveModal = (): void => {
|
|
705
|
+
if (!activeModalCancel) {
|
|
706
|
+
return;
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
const cancel = activeModalCancel;
|
|
710
|
+
activeModalCancel = null;
|
|
711
|
+
cancel();
|
|
712
|
+
};
|
|
713
|
+
|
|
714
|
+
const shouldClearPendingExitConfirmation = (data: string): boolean => {
|
|
715
|
+
if (!pendingExitConfirmation) {
|
|
716
|
+
return false;
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
if (isCtrlCInput(data)) {
|
|
720
|
+
return false;
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
if (isKeyRelease(data) || isKeyRepeat(data)) {
|
|
724
|
+
return false;
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
return true;
|
|
728
|
+
};
|
|
729
|
+
|
|
730
|
+
const isCtrlCInput = (data: string): boolean => {
|
|
731
|
+
return data === CTRL_C_ETX || matchesKey(data, Key.ctrl("c"));
|
|
732
|
+
};
|
|
733
|
+
|
|
734
|
+
const handleCtrlCPress = (): void => {
|
|
735
|
+
const now = Date.now();
|
|
736
|
+
|
|
737
|
+
// Double press within window: request graceful shutdown immediately.
|
|
738
|
+
if (now - lastCtrlCPressAt < CTRL_C_EXIT_WINDOW_MS) {
|
|
739
|
+
lastCtrlCPressAt = 0;
|
|
740
|
+
dismissActiveModal();
|
|
741
|
+
requestExit();
|
|
742
|
+
return;
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
lastCtrlCPressAt = now;
|
|
746
|
+
// First press: try to cancel active stream
|
|
747
|
+
const canceled = cancelActiveStream();
|
|
748
|
+
if (canceled) {
|
|
749
|
+
pendingExitConfirmation = true;
|
|
750
|
+
clearStatus();
|
|
751
|
+
return;
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
// First press, no active stream: clear prompt
|
|
755
|
+
pendingExitConfirmation = true;
|
|
756
|
+
dismissActiveModal();
|
|
757
|
+
clearPromptInput();
|
|
758
|
+
};
|
|
759
|
+
|
|
760
|
+
const showReasoningModeSelector = async (
|
|
761
|
+
currentMode: ReasoningMode
|
|
762
|
+
): Promise<ReasoningMode | null> => {
|
|
763
|
+
clearStatus();
|
|
764
|
+
|
|
765
|
+
const selectableModes = agentManager.getSelectableReasoningModes();
|
|
766
|
+
const descriptions: Record<ReasoningMode, string> = {
|
|
767
|
+
off: "Disable reasoning mode",
|
|
768
|
+
on: "Enable reasoning if supported",
|
|
769
|
+
interleaved: "Enable interleaved reasoning field mode",
|
|
770
|
+
preserved: "Enable preserved interleaved reasoning mode",
|
|
771
|
+
};
|
|
772
|
+
|
|
773
|
+
const selectorContainer = new Container();
|
|
774
|
+
selectorContainer.addChild(
|
|
775
|
+
new Text(style(ANSI_DIM, "Select reasoning execution"), 1, 0)
|
|
776
|
+
);
|
|
777
|
+
selectorContainer.addChild(new Spacer(1));
|
|
778
|
+
|
|
779
|
+
const selectList = new SelectList(
|
|
780
|
+
selectableModes.map((mode) => ({
|
|
781
|
+
value: mode,
|
|
782
|
+
label: buildCurrentIndicatorLabel(mode, currentMode === mode),
|
|
783
|
+
description: descriptions[mode],
|
|
784
|
+
})),
|
|
785
|
+
2,
|
|
786
|
+
editorTheme.selectList
|
|
787
|
+
);
|
|
788
|
+
|
|
789
|
+
const selectedIndex = selectableModes.indexOf(currentMode);
|
|
790
|
+
selectList.setSelectedIndex(selectedIndex >= 0 ? selectedIndex : 0);
|
|
791
|
+
|
|
792
|
+
selectorContainer.addChild(selectList);
|
|
793
|
+
statusContainer.addChild(selectorContainer);
|
|
794
|
+
tui.requestRender();
|
|
795
|
+
|
|
796
|
+
return await new Promise((resolve) => {
|
|
797
|
+
let removeSelectorInputListener: () => void = () => undefined;
|
|
798
|
+
let done = false;
|
|
799
|
+
|
|
800
|
+
const cleanup = (): void => {
|
|
801
|
+
removeSelectorInputListener();
|
|
802
|
+
statusContainer.removeChild(selectorContainer);
|
|
803
|
+
tui.requestRender();
|
|
804
|
+
};
|
|
805
|
+
|
|
806
|
+
const finish = (value: ReasoningMode | null): void => {
|
|
807
|
+
if (done) {
|
|
808
|
+
return;
|
|
809
|
+
}
|
|
810
|
+
done = true;
|
|
811
|
+
setActiveModalCancel(null);
|
|
812
|
+
cleanup();
|
|
813
|
+
resolve(value);
|
|
814
|
+
};
|
|
815
|
+
|
|
816
|
+
setActiveModalCancel(() => {
|
|
817
|
+
finish(null);
|
|
818
|
+
});
|
|
819
|
+
|
|
820
|
+
selectList.onSelect = (item) => {
|
|
821
|
+
const selectedMode = parseReasoningMode(item.value);
|
|
822
|
+
finish(selectedMode ?? DEFAULT_REASONING_MODE);
|
|
823
|
+
};
|
|
824
|
+
selectList.onCancel = () => {
|
|
825
|
+
finish(null);
|
|
826
|
+
};
|
|
827
|
+
|
|
828
|
+
removeSelectorInputListener = tui.addInputListener((data) => {
|
|
829
|
+
if (isCtrlCInput(data)) {
|
|
830
|
+
handleCtrlCPress();
|
|
831
|
+
finish(null);
|
|
832
|
+
return { consume: true };
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
if (shouldClearPendingExitConfirmation(data)) {
|
|
836
|
+
clearPendingExitConfirmation();
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
selectList.handleInput(data);
|
|
840
|
+
tui.requestRender();
|
|
841
|
+
return { consume: true };
|
|
842
|
+
});
|
|
843
|
+
});
|
|
844
|
+
};
|
|
845
|
+
|
|
846
|
+
const showToolFallbackSelector = async (
|
|
847
|
+
currentMode: ToolFallbackMode
|
|
848
|
+
): Promise<ToolFallbackMode | null> => {
|
|
849
|
+
clearStatus();
|
|
850
|
+
|
|
851
|
+
const selectorContainer = new Container();
|
|
852
|
+
selectorContainer.addChild(
|
|
853
|
+
new Text(style(ANSI_DIM, "Select tool fallback mode"), 1, 0)
|
|
854
|
+
);
|
|
855
|
+
selectorContainer.addChild(new Spacer(1));
|
|
856
|
+
|
|
857
|
+
const selectList = new SelectList(
|
|
858
|
+
[
|
|
859
|
+
{
|
|
860
|
+
value: "disable",
|
|
861
|
+
label: buildCurrentIndicatorLabel(
|
|
862
|
+
"disable",
|
|
863
|
+
currentMode === "disable"
|
|
864
|
+
),
|
|
865
|
+
description: "Use native tool support only",
|
|
866
|
+
},
|
|
867
|
+
{
|
|
868
|
+
value: "morphxml",
|
|
869
|
+
label: buildCurrentIndicatorLabel(
|
|
870
|
+
"morphxml",
|
|
871
|
+
currentMode === "morphxml"
|
|
872
|
+
),
|
|
873
|
+
description: "XML tags per tool (MorphXML protocol)",
|
|
874
|
+
},
|
|
875
|
+
{
|
|
876
|
+
value: "hermes",
|
|
877
|
+
label: buildCurrentIndicatorLabel("hermes", currentMode === "hermes"),
|
|
878
|
+
description: "Hermes JSON-in-XML tool_call format",
|
|
879
|
+
},
|
|
880
|
+
{
|
|
881
|
+
value: "qwen3coder",
|
|
882
|
+
label: buildCurrentIndicatorLabel(
|
|
883
|
+
"qwen3coder",
|
|
884
|
+
currentMode === "qwen3coder"
|
|
885
|
+
),
|
|
886
|
+
description: "Qwen3Coder function-tag tool_call format",
|
|
887
|
+
},
|
|
888
|
+
],
|
|
889
|
+
4,
|
|
890
|
+
editorTheme.selectList
|
|
891
|
+
);
|
|
892
|
+
const currentModeIndex = TOOL_FALLBACK_MODES.indexOf(currentMode);
|
|
893
|
+
if (currentModeIndex >= 0) {
|
|
894
|
+
selectList.setSelectedIndex(currentModeIndex);
|
|
895
|
+
}
|
|
896
|
+
|
|
897
|
+
selectorContainer.addChild(selectList);
|
|
898
|
+
statusContainer.addChild(selectorContainer);
|
|
899
|
+
tui.requestRender();
|
|
900
|
+
|
|
901
|
+
return await new Promise((resolve) => {
|
|
902
|
+
let removeSelectorInputListener: () => void = () => undefined;
|
|
903
|
+
let done = false;
|
|
904
|
+
|
|
905
|
+
const cleanup = (): void => {
|
|
906
|
+
removeSelectorInputListener();
|
|
907
|
+
statusContainer.removeChild(selectorContainer);
|
|
908
|
+
tui.requestRender();
|
|
909
|
+
};
|
|
910
|
+
|
|
911
|
+
const finish = (value: ToolFallbackMode | null): void => {
|
|
912
|
+
if (done) {
|
|
913
|
+
return;
|
|
914
|
+
}
|
|
915
|
+
done = true;
|
|
916
|
+
setActiveModalCancel(null);
|
|
917
|
+
cleanup();
|
|
918
|
+
resolve(value);
|
|
919
|
+
};
|
|
920
|
+
|
|
921
|
+
setActiveModalCancel(() => {
|
|
922
|
+
finish(null);
|
|
923
|
+
});
|
|
924
|
+
|
|
925
|
+
selectList.onSelect = (item) => {
|
|
926
|
+
const parsedMode = parseToolFallbackMode(item.value);
|
|
927
|
+
finish(parsedMode);
|
|
928
|
+
};
|
|
929
|
+
selectList.onCancel = () => {
|
|
930
|
+
finish(null);
|
|
931
|
+
};
|
|
932
|
+
|
|
933
|
+
removeSelectorInputListener = tui.addInputListener((data) => {
|
|
934
|
+
if (isCtrlCInput(data)) {
|
|
935
|
+
handleCtrlCPress();
|
|
936
|
+
finish(null);
|
|
937
|
+
return { consume: true };
|
|
938
|
+
}
|
|
939
|
+
|
|
940
|
+
if (shouldClearPendingExitConfirmation(data)) {
|
|
941
|
+
clearPendingExitConfirmation();
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
selectList.handleInput(data);
|
|
945
|
+
tui.requestRender();
|
|
946
|
+
return { consume: true };
|
|
947
|
+
});
|
|
948
|
+
});
|
|
949
|
+
};
|
|
950
|
+
|
|
951
|
+
const showTranslateModeSelector = async (
|
|
952
|
+
currentEnabled: boolean
|
|
953
|
+
): Promise<boolean | null> => {
|
|
954
|
+
clearStatus();
|
|
955
|
+
|
|
956
|
+
const selectorContainer = new Container();
|
|
957
|
+
selectorContainer.addChild(
|
|
958
|
+
new Text(style(ANSI_DIM, "Select translation mode"), 1, 0)
|
|
959
|
+
);
|
|
960
|
+
selectorContainer.addChild(new Spacer(1));
|
|
961
|
+
|
|
962
|
+
const selectList = new SelectList(
|
|
963
|
+
[
|
|
964
|
+
{
|
|
965
|
+
value: "on",
|
|
966
|
+
label: buildCurrentIndicatorLabel("on", currentEnabled),
|
|
967
|
+
description: "Auto-translate non-English prompts",
|
|
968
|
+
},
|
|
969
|
+
{
|
|
970
|
+
value: "off",
|
|
971
|
+
label: buildCurrentIndicatorLabel("off", !currentEnabled),
|
|
972
|
+
description: "Use prompts as entered",
|
|
973
|
+
},
|
|
974
|
+
],
|
|
975
|
+
2,
|
|
976
|
+
editorTheme.selectList
|
|
977
|
+
);
|
|
978
|
+
selectList.setSelectedIndex(currentEnabled ? 0 : 1);
|
|
979
|
+
|
|
980
|
+
selectorContainer.addChild(selectList);
|
|
981
|
+
statusContainer.addChild(selectorContainer);
|
|
982
|
+
tui.requestRender();
|
|
983
|
+
|
|
984
|
+
return await new Promise((resolve) => {
|
|
985
|
+
let removeSelectorInputListener: () => void = () => undefined;
|
|
986
|
+
let done = false;
|
|
987
|
+
|
|
988
|
+
const cleanup = (): void => {
|
|
989
|
+
removeSelectorInputListener();
|
|
990
|
+
statusContainer.removeChild(selectorContainer);
|
|
991
|
+
tui.requestRender();
|
|
992
|
+
};
|
|
993
|
+
|
|
994
|
+
const finish = (value: boolean | null): void => {
|
|
995
|
+
if (done) {
|
|
996
|
+
return;
|
|
997
|
+
}
|
|
998
|
+
done = true;
|
|
999
|
+
setActiveModalCancel(null);
|
|
1000
|
+
cleanup();
|
|
1001
|
+
resolve(value);
|
|
1002
|
+
};
|
|
1003
|
+
|
|
1004
|
+
setActiveModalCancel(() => {
|
|
1005
|
+
finish(null);
|
|
1006
|
+
});
|
|
1007
|
+
|
|
1008
|
+
selectList.onSelect = (item) => {
|
|
1009
|
+
finish(item.value === "on");
|
|
1010
|
+
};
|
|
1011
|
+
selectList.onCancel = () => {
|
|
1012
|
+
finish(null);
|
|
1013
|
+
};
|
|
1014
|
+
|
|
1015
|
+
removeSelectorInputListener = tui.addInputListener((data) => {
|
|
1016
|
+
if (isCtrlCInput(data)) {
|
|
1017
|
+
handleCtrlCPress();
|
|
1018
|
+
finish(null);
|
|
1019
|
+
return { consume: true };
|
|
1020
|
+
}
|
|
1021
|
+
|
|
1022
|
+
if (shouldClearPendingExitConfirmation(data)) {
|
|
1023
|
+
clearPendingExitConfirmation();
|
|
1024
|
+
}
|
|
1025
|
+
|
|
1026
|
+
selectList.handleInput(data);
|
|
1027
|
+
tui.requestRender();
|
|
1028
|
+
return { consume: true };
|
|
1029
|
+
});
|
|
1030
|
+
});
|
|
1031
|
+
};
|
|
1032
|
+
|
|
1033
|
+
const showModelSelector = async (
|
|
1034
|
+
models: ModelInfo[],
|
|
1035
|
+
currentModelId: string,
|
|
1036
|
+
currentProvider: ProviderType,
|
|
1037
|
+
initialFilter = ""
|
|
1038
|
+
): Promise<ModelInfo | null> => {
|
|
1039
|
+
clearStatus();
|
|
1040
|
+
|
|
1041
|
+
const selectorContainer = new Container();
|
|
1042
|
+
|
|
1043
|
+
const searchInput = new Input();
|
|
1044
|
+
searchInput.focused = true;
|
|
1045
|
+
searchInput.setValue(initialFilter);
|
|
1046
|
+
selectorContainer.addChild(searchInput);
|
|
1047
|
+
selectorContainer.addChild(new Spacer(1));
|
|
1048
|
+
|
|
1049
|
+
const modelMap = new Map<string, ModelInfo>();
|
|
1050
|
+
const items = models.map((model) => {
|
|
1051
|
+
const key = `${model.provider}:${model.id}`;
|
|
1052
|
+
modelMap.set(key, model);
|
|
1053
|
+
const providerLabel =
|
|
1054
|
+
model.provider === "anthropic" ? "Anthropic" : "FriendliAI";
|
|
1055
|
+
const isCurrent =
|
|
1056
|
+
model.id === currentModelId && model.provider === currentProvider;
|
|
1057
|
+
|
|
1058
|
+
return {
|
|
1059
|
+
value: key,
|
|
1060
|
+
label: buildModelSelectorLabel(model.id, isCurrent),
|
|
1061
|
+
description: buildModelSelectorDescription(model.name, providerLabel),
|
|
1062
|
+
};
|
|
1063
|
+
});
|
|
1064
|
+
|
|
1065
|
+
const selectList = new SelectList(items, 10, editorTheme.selectList);
|
|
1066
|
+
const currentIndex = items.findIndex(
|
|
1067
|
+
(item) => item.value === `${currentProvider}:${currentModelId}`
|
|
1068
|
+
);
|
|
1069
|
+
if (currentIndex >= 0) {
|
|
1070
|
+
selectList.setSelectedIndex(currentIndex);
|
|
1071
|
+
}
|
|
1072
|
+
|
|
1073
|
+
if (initialFilter.length > 0) {
|
|
1074
|
+
selectList.setFilter(initialFilter);
|
|
1075
|
+
}
|
|
1076
|
+
|
|
1077
|
+
selectorContainer.addChild(selectList);
|
|
1078
|
+
selectorContainer.addChild(new Spacer(1));
|
|
1079
|
+
selectorContainer.addChild(
|
|
1080
|
+
new Text(
|
|
1081
|
+
style(ANSI_DIM, "Type to filter, Enter to select, Esc to cancel"),
|
|
1082
|
+
1,
|
|
1083
|
+
0
|
|
1084
|
+
)
|
|
1085
|
+
);
|
|
1086
|
+
statusContainer.addChild(selectorContainer);
|
|
1087
|
+
tui.requestRender();
|
|
1088
|
+
|
|
1089
|
+
return await new Promise((resolve) => {
|
|
1090
|
+
let removeSelectorInputListener: () => void = () => undefined;
|
|
1091
|
+
let done = false;
|
|
1092
|
+
|
|
1093
|
+
const cleanup = (): void => {
|
|
1094
|
+
removeSelectorInputListener();
|
|
1095
|
+
statusContainer.removeChild(selectorContainer);
|
|
1096
|
+
searchInput.focused = false;
|
|
1097
|
+
tui.requestRender();
|
|
1098
|
+
};
|
|
1099
|
+
|
|
1100
|
+
const finish = (value: ModelInfo | null): void => {
|
|
1101
|
+
if (done) {
|
|
1102
|
+
return;
|
|
1103
|
+
}
|
|
1104
|
+
done = true;
|
|
1105
|
+
setActiveModalCancel(null);
|
|
1106
|
+
cleanup();
|
|
1107
|
+
resolve(value);
|
|
1108
|
+
};
|
|
1109
|
+
|
|
1110
|
+
setActiveModalCancel(() => {
|
|
1111
|
+
finish(null);
|
|
1112
|
+
});
|
|
1113
|
+
|
|
1114
|
+
const selectCurrent = (): void => {
|
|
1115
|
+
const selectedItem = selectList.getSelectedItem();
|
|
1116
|
+
if (!selectedItem) {
|
|
1117
|
+
return;
|
|
1118
|
+
}
|
|
1119
|
+
finish(modelMap.get(selectedItem.value) ?? null);
|
|
1120
|
+
};
|
|
1121
|
+
|
|
1122
|
+
selectList.onSelect = (item) => {
|
|
1123
|
+
finish(modelMap.get(item.value) ?? null);
|
|
1124
|
+
};
|
|
1125
|
+
selectList.onCancel = () => {
|
|
1126
|
+
finish(null);
|
|
1127
|
+
};
|
|
1128
|
+
searchInput.onSubmit = () => {
|
|
1129
|
+
selectCurrent();
|
|
1130
|
+
};
|
|
1131
|
+
searchInput.onEscape = () => {
|
|
1132
|
+
finish(null);
|
|
1133
|
+
};
|
|
1134
|
+
|
|
1135
|
+
removeSelectorInputListener = tui.addInputListener((data) => {
|
|
1136
|
+
if (isCtrlCInput(data)) {
|
|
1137
|
+
handleCtrlCPress();
|
|
1138
|
+
finish(null);
|
|
1139
|
+
return { consume: true };
|
|
1140
|
+
}
|
|
1141
|
+
|
|
1142
|
+
if (shouldClearPendingExitConfirmation(data)) {
|
|
1143
|
+
clearPendingExitConfirmation();
|
|
1144
|
+
}
|
|
1145
|
+
|
|
1146
|
+
if (
|
|
1147
|
+
matchesKey(data, Key.up) ||
|
|
1148
|
+
matchesKey(data, Key.down) ||
|
|
1149
|
+
matchesKey(data, Key.enter) ||
|
|
1150
|
+
matchesKey(data, Key.escape)
|
|
1151
|
+
) {
|
|
1152
|
+
selectList.handleInput(data);
|
|
1153
|
+
tui.requestRender();
|
|
1154
|
+
return { consume: true };
|
|
1155
|
+
}
|
|
1156
|
+
|
|
1157
|
+
searchInput.handleInput(data);
|
|
1158
|
+
selectList.setFilter(searchInput.getValue());
|
|
1159
|
+
tui.requestRender();
|
|
1160
|
+
return { consume: true };
|
|
1161
|
+
});
|
|
1162
|
+
});
|
|
1163
|
+
};
|
|
1164
|
+
|
|
1165
|
+
const requestExit = (): void => {
|
|
1166
|
+
pendingExitConfirmation = false;
|
|
1167
|
+
shouldExit = true;
|
|
1168
|
+
lastCtrlCPressAt = 0;
|
|
1169
|
+
cancelActiveStream();
|
|
1170
|
+
clearStatus();
|
|
1171
|
+
dismissActiveModal();
|
|
1172
|
+
if (inputResolver) {
|
|
1173
|
+
const resolve = inputResolver;
|
|
1174
|
+
inputResolver = null;
|
|
1175
|
+
resolve(null);
|
|
1176
|
+
}
|
|
1177
|
+
};
|
|
1178
|
+
|
|
1179
|
+
const onSigInt = () => {
|
|
1180
|
+
handleCtrlCPress();
|
|
1181
|
+
};
|
|
1182
|
+
|
|
1183
|
+
const onTerminalResize = () => {
|
|
1184
|
+
tui.requestRender(true);
|
|
1185
|
+
};
|
|
1186
|
+
|
|
1187
|
+
const removeInputListener = tui.addInputListener((data) => {
|
|
1188
|
+
if (isCtrlCInput(data)) {
|
|
1189
|
+
handleCtrlCPress();
|
|
1190
|
+
return { consume: true };
|
|
1191
|
+
}
|
|
1192
|
+
|
|
1193
|
+
if (shouldClearPendingExitConfirmation(data)) {
|
|
1194
|
+
clearPendingExitConfirmation();
|
|
1195
|
+
}
|
|
1196
|
+
|
|
1197
|
+
return undefined;
|
|
1198
|
+
});
|
|
1199
|
+
|
|
1200
|
+
process.on("SIGINT", onSigInt);
|
|
1201
|
+
process.stdout.on("resize", onTerminalResize);
|
|
1202
|
+
|
|
1203
|
+
editor.onSubmit = (text: string) => {
|
|
1204
|
+
if (!inputResolver) {
|
|
1205
|
+
return;
|
|
1206
|
+
}
|
|
1207
|
+
|
|
1208
|
+
pendingExitConfirmation = false;
|
|
1209
|
+
lastCtrlCPressAt = 0;
|
|
1210
|
+
const resolve = inputResolver;
|
|
1211
|
+
inputResolver = null;
|
|
1212
|
+
resolve(text);
|
|
1213
|
+
};
|
|
1214
|
+
|
|
1215
|
+
const waitForInput = (): Promise<string | null> => {
|
|
1216
|
+
return new Promise((resolve) => {
|
|
1217
|
+
inputResolver = resolve;
|
|
1218
|
+
tui.setFocus(editor);
|
|
1219
|
+
tui.requestRender();
|
|
1220
|
+
});
|
|
1221
|
+
};
|
|
1222
|
+
|
|
1223
|
+
const dispose = async (): Promise<void> => {
|
|
1224
|
+
clearStatus();
|
|
1225
|
+
|
|
1226
|
+
if (inputResolver) {
|
|
1227
|
+
const resolve = inputResolver;
|
|
1228
|
+
inputResolver = null;
|
|
1229
|
+
resolve(null);
|
|
1230
|
+
}
|
|
1231
|
+
|
|
1232
|
+
// Release module-level refs to allow GC after UI teardown
|
|
1233
|
+
activeStreamController = null;
|
|
1234
|
+
streamInterruptRequested = false;
|
|
1235
|
+
dismissActiveModal();
|
|
1236
|
+
|
|
1237
|
+
removeInputListener();
|
|
1238
|
+
process.off("SIGINT", onSigInt);
|
|
1239
|
+
process.stdout.off("resize", onTerminalResize);
|
|
1240
|
+
|
|
1241
|
+
try {
|
|
1242
|
+
await terminal.drainInput();
|
|
1243
|
+
} finally {
|
|
1244
|
+
tui.stop();
|
|
1245
|
+
}
|
|
1246
|
+
};
|
|
1247
|
+
|
|
1248
|
+
updateHeader();
|
|
1249
|
+
tui.start();
|
|
1250
|
+
|
|
1251
|
+
return {
|
|
1252
|
+
tui,
|
|
1253
|
+
editor,
|
|
1254
|
+
chatContainer,
|
|
1255
|
+
markdownTheme,
|
|
1256
|
+
updateHeader,
|
|
1257
|
+
waitForInput,
|
|
1258
|
+
requestExit,
|
|
1259
|
+
showLoader,
|
|
1260
|
+
showModelSelector,
|
|
1261
|
+
showToolFallbackSelector,
|
|
1262
|
+
showReasoningModeSelector,
|
|
1263
|
+
showTranslateModeSelector,
|
|
1264
|
+
clearStatus,
|
|
1265
|
+
dispose,
|
|
1266
|
+
};
|
|
1267
|
+
};
|
|
1268
|
+
|
|
1269
|
+
registerCommand(
|
|
1270
|
+
createRenderCommand(async () => ({
|
|
1271
|
+
model: agentManager.getModelId(),
|
|
1272
|
+
modelType: agentManager.getModelType(),
|
|
1273
|
+
instructions: await agentManager.getInstructions(),
|
|
1274
|
+
tools: agentManager.getTools(),
|
|
1275
|
+
messages: messageHistory.toModelMessages(),
|
|
1276
|
+
reasoningMode: agentManager.getReasoningMode(),
|
|
1277
|
+
toolFallbackMode: agentManager.getToolFallbackMode(),
|
|
1278
|
+
}))
|
|
1279
|
+
);
|
|
1280
|
+
registerCommand(createModelCommand());
|
|
1281
|
+
registerCommand(createClearCommand());
|
|
1282
|
+
registerCommand(createReasoningModeCommand());
|
|
1283
|
+
registerCommand(createToolFallbackCommand());
|
|
1284
|
+
registerCommand(createTranslateCommand());
|
|
1285
|
+
|
|
1286
|
+
const parseCliArgs = (): {
|
|
1287
|
+
reasoningMode: ReasoningMode | null;
|
|
1288
|
+
toolFallbackMode: ToolFallbackMode;
|
|
1289
|
+
model: string | null;
|
|
1290
|
+
provider: ProviderType | null;
|
|
1291
|
+
translateUserPrompts: boolean;
|
|
1292
|
+
} => {
|
|
1293
|
+
const args = process.argv.slice(2);
|
|
1294
|
+
let reasoningMode: ReasoningMode | null = null;
|
|
1295
|
+
let toolFallbackMode: ToolFallbackMode = DEFAULT_TOOL_FALLBACK_MODE;
|
|
1296
|
+
let model: string | null = null;
|
|
1297
|
+
let provider: ProviderType | null = null;
|
|
1298
|
+
let translateUserPrompts = true;
|
|
1299
|
+
|
|
1300
|
+
for (let i = 0; i < args.length; i += 1) {
|
|
1301
|
+
const arg = args[i];
|
|
1302
|
+
|
|
1303
|
+
const reasoningOption = parseReasoningCliOption(args, i);
|
|
1304
|
+
if (reasoningOption) {
|
|
1305
|
+
reasoningMode = reasoningOption.mode;
|
|
1306
|
+
i += reasoningOption.consumedArgs;
|
|
1307
|
+
continue;
|
|
1308
|
+
}
|
|
1309
|
+
|
|
1310
|
+
const toolFallbackOption = parseToolFallbackCliOption(args, i);
|
|
1311
|
+
if (toolFallbackOption) {
|
|
1312
|
+
toolFallbackMode = toolFallbackOption.mode;
|
|
1313
|
+
i += toolFallbackOption.consumedArgs;
|
|
1314
|
+
continue;
|
|
1315
|
+
}
|
|
1316
|
+
|
|
1317
|
+
if (arg === "--model" && i + 1 < args.length) {
|
|
1318
|
+
model = args[i + 1];
|
|
1319
|
+
i += 1;
|
|
1320
|
+
continue;
|
|
1321
|
+
}
|
|
1322
|
+
|
|
1323
|
+
if (arg === "--provider" && i + 1 < args.length) {
|
|
1324
|
+
provider = parseProviderArg(args[i + 1]) ?? provider;
|
|
1325
|
+
i += 1;
|
|
1326
|
+
continue;
|
|
1327
|
+
}
|
|
1328
|
+
|
|
1329
|
+
const translateOption = parseTranslateCliOption(arg);
|
|
1330
|
+
if (translateOption !== null) {
|
|
1331
|
+
translateUserPrompts = translateOption;
|
|
1332
|
+
}
|
|
1333
|
+
}
|
|
1334
|
+
|
|
1335
|
+
return {
|
|
1336
|
+
reasoningMode,
|
|
1337
|
+
toolFallbackMode,
|
|
1338
|
+
model,
|
|
1339
|
+
provider,
|
|
1340
|
+
translateUserPrompts,
|
|
1341
|
+
};
|
|
1342
|
+
};
|
|
1343
|
+
|
|
1344
|
+
const setupAgent = (): void => {
|
|
1345
|
+
const {
|
|
1346
|
+
reasoningMode,
|
|
1347
|
+
toolFallbackMode,
|
|
1348
|
+
model,
|
|
1349
|
+
provider,
|
|
1350
|
+
translateUserPrompts,
|
|
1351
|
+
} = parseCliArgs();
|
|
1352
|
+
if (provider) {
|
|
1353
|
+
agentManager.setProvider(provider);
|
|
1354
|
+
}
|
|
1355
|
+
if (model) {
|
|
1356
|
+
agentManager.setModelId(model);
|
|
1357
|
+
}
|
|
1358
|
+
|
|
1359
|
+
if (reasoningMode !== null) {
|
|
1360
|
+
agentManager.setReasoningMode(reasoningMode);
|
|
1361
|
+
}
|
|
1362
|
+
|
|
1363
|
+
agentManager.setToolFallbackMode(toolFallbackMode);
|
|
1364
|
+
agentManager.setTranslationEnabled(translateUserPrompts);
|
|
1365
|
+
};
|
|
1366
|
+
|
|
1367
|
+
type AgentResponseStatus = "completed" | "interrupted";
|
|
1368
|
+
|
|
1369
|
+
const processAgentResponse = async (
|
|
1370
|
+
ui: CliUi
|
|
1371
|
+
): Promise<AgentResponseStatus> => {
|
|
1372
|
+
let manualToolLoopCount = 0;
|
|
1373
|
+
|
|
1374
|
+
while (true) {
|
|
1375
|
+
ui.showLoader("Working...");
|
|
1376
|
+
const streamAbortController = new AbortController();
|
|
1377
|
+
activeStreamController = streamAbortController;
|
|
1378
|
+
streamInterruptRequested = false;
|
|
1379
|
+
|
|
1380
|
+
try {
|
|
1381
|
+
const stream = await agentManager.stream(
|
|
1382
|
+
messageHistory.toModelMessages(),
|
|
1383
|
+
{ abortSignal: streamAbortController.signal }
|
|
1384
|
+
);
|
|
1385
|
+
|
|
1386
|
+
let hasClearedStreamingLoader = false;
|
|
1387
|
+
const clearStreamingLoader = (): void => {
|
|
1388
|
+
if (hasClearedStreamingLoader) {
|
|
1389
|
+
return;
|
|
1390
|
+
}
|
|
1391
|
+
hasClearedStreamingLoader = true;
|
|
1392
|
+
ui.clearStatus();
|
|
1393
|
+
};
|
|
1394
|
+
|
|
1395
|
+
await renderFullStreamWithPiTui(stream.fullStream, {
|
|
1396
|
+
ui: ui.tui,
|
|
1397
|
+
chatContainer: ui.chatContainer,
|
|
1398
|
+
markdownTheme: ui.markdownTheme,
|
|
1399
|
+
onFirstVisiblePart: clearStreamingLoader,
|
|
1400
|
+
showReasoning: true,
|
|
1401
|
+
showSteps: false,
|
|
1402
|
+
showToolResults: true,
|
|
1403
|
+
showFiles: false,
|
|
1404
|
+
showSources: false,
|
|
1405
|
+
showFinishReason: env.DEBUG_SHOW_FINISH_REASON,
|
|
1406
|
+
});
|
|
1407
|
+
|
|
1408
|
+
clearStreamingLoader();
|
|
1409
|
+
|
|
1410
|
+
const [response, finishReason] = await Promise.all([
|
|
1411
|
+
stream.response,
|
|
1412
|
+
stream.finishReason,
|
|
1413
|
+
]);
|
|
1414
|
+
|
|
1415
|
+
if (streamInterruptRequested || streamAbortController.signal.aborted) {
|
|
1416
|
+
addSystemMessage(
|
|
1417
|
+
ui.chatContainer,
|
|
1418
|
+
"[agent] Stream interrupted by user. Waiting for input."
|
|
1419
|
+
);
|
|
1420
|
+
ui.tui.requestRender();
|
|
1421
|
+
return "interrupted";
|
|
1422
|
+
}
|
|
1423
|
+
|
|
1424
|
+
messageHistory.addModelMessages(response.messages);
|
|
1425
|
+
|
|
1426
|
+
if (!shouldContinueManualToolLoop(finishReason)) {
|
|
1427
|
+
return "completed";
|
|
1428
|
+
}
|
|
1429
|
+
|
|
1430
|
+
manualToolLoopCount += 1;
|
|
1431
|
+
if (manualToolLoopCount >= MANUAL_TOOL_LOOP_MAX_STEPS) {
|
|
1432
|
+
addSystemMessage(
|
|
1433
|
+
ui.chatContainer,
|
|
1434
|
+
`[agent] Manual tool loop safety cap reached (${MANUAL_TOOL_LOOP_MAX_STEPS}); waiting for input.`
|
|
1435
|
+
);
|
|
1436
|
+
ui.tui.requestRender();
|
|
1437
|
+
return "completed";
|
|
1438
|
+
}
|
|
1439
|
+
} catch (error) {
|
|
1440
|
+
if (streamInterruptRequested || streamAbortController.signal.aborted) {
|
|
1441
|
+
addSystemMessage(
|
|
1442
|
+
ui.chatContainer,
|
|
1443
|
+
"[agent] Stream interrupted by user. Waiting for input."
|
|
1444
|
+
);
|
|
1445
|
+
ui.tui.requestRender();
|
|
1446
|
+
return "interrupted";
|
|
1447
|
+
}
|
|
1448
|
+
|
|
1449
|
+
throw error;
|
|
1450
|
+
} finally {
|
|
1451
|
+
clearActiveStreamController(streamAbortController);
|
|
1452
|
+
streamInterruptRequested = false;
|
|
1453
|
+
ui.clearStatus();
|
|
1454
|
+
}
|
|
1455
|
+
}
|
|
1456
|
+
};
|
|
1457
|
+
|
|
1458
|
+
const handleAgentResponse = async (ui: CliUi): Promise<void> => {
|
|
1459
|
+
while (true) {
|
|
1460
|
+
const result = await processAgentResponse(ui);
|
|
1461
|
+
if (result === "interrupted") {
|
|
1462
|
+
return;
|
|
1463
|
+
}
|
|
1464
|
+
|
|
1465
|
+
const incompleteTodos = await getIncompleteTodos();
|
|
1466
|
+
if (incompleteTodos.length === 0) {
|
|
1467
|
+
return;
|
|
1468
|
+
}
|
|
1469
|
+
|
|
1470
|
+
const reminder = buildTodoContinuationUserMessage(incompleteTodos);
|
|
1471
|
+
messageHistory.addUserMessage(reminder);
|
|
1472
|
+
}
|
|
1473
|
+
};
|
|
1474
|
+
|
|
1475
|
+
const renderCommandMessage = (ui: CliUi, message: string): void => {
|
|
1476
|
+
addSystemMessage(ui.chatContainer, message);
|
|
1477
|
+
ui.updateHeader();
|
|
1478
|
+
ui.tui.requestRender();
|
|
1479
|
+
};
|
|
1480
|
+
|
|
1481
|
+
const handleModelCommand = async (
|
|
1482
|
+
ui: CliUi,
|
|
1483
|
+
commandInput: string,
|
|
1484
|
+
parsed: ReturnType<typeof parseCommand>
|
|
1485
|
+
): Promise<boolean | null> => {
|
|
1486
|
+
if (parsed?.name !== "model") {
|
|
1487
|
+
return null;
|
|
1488
|
+
}
|
|
1489
|
+
|
|
1490
|
+
const models = getAvailableModels();
|
|
1491
|
+
if (models.length === 0) {
|
|
1492
|
+
const result = await executeCommand(commandInput);
|
|
1493
|
+
if (result?.message) {
|
|
1494
|
+
renderCommandMessage(ui, result.message);
|
|
1495
|
+
return true;
|
|
1496
|
+
}
|
|
1497
|
+
return false;
|
|
1498
|
+
}
|
|
1499
|
+
|
|
1500
|
+
const searchTerm = parsed.args[0]?.trim() ?? "";
|
|
1501
|
+
const exactMatch =
|
|
1502
|
+
searchTerm.length > 0
|
|
1503
|
+
? findModelBySelection(searchTerm, models)
|
|
1504
|
+
: undefined;
|
|
1505
|
+
|
|
1506
|
+
if (parsed.args.length > 0 && exactMatch) {
|
|
1507
|
+
return null;
|
|
1508
|
+
}
|
|
1509
|
+
|
|
1510
|
+
const selectedModel = await ui.showModelSelector(
|
|
1511
|
+
models,
|
|
1512
|
+
agentManager.getModelId(),
|
|
1513
|
+
agentManager.getProvider(),
|
|
1514
|
+
searchTerm
|
|
1515
|
+
);
|
|
1516
|
+
if (!selectedModel) {
|
|
1517
|
+
return true;
|
|
1518
|
+
}
|
|
1519
|
+
|
|
1520
|
+
const selectionResult = applyModelSelection(selectedModel);
|
|
1521
|
+
if (selectionResult.message) {
|
|
1522
|
+
renderCommandMessage(ui, selectionResult.message);
|
|
1523
|
+
return true;
|
|
1524
|
+
}
|
|
1525
|
+
|
|
1526
|
+
ui.updateHeader();
|
|
1527
|
+
ui.tui.requestRender();
|
|
1528
|
+
return true;
|
|
1529
|
+
};
|
|
1530
|
+
|
|
1531
|
+
const resolveToolFallbackCommandInput = async (
|
|
1532
|
+
ui: CliUi,
|
|
1533
|
+
commandInput: string,
|
|
1534
|
+
parsed: ReturnType<typeof parseCommand>
|
|
1535
|
+
): Promise<string | null> => {
|
|
1536
|
+
if (parsed?.name !== "tool-fallback" || parsed.args.length > 0) {
|
|
1537
|
+
return commandInput;
|
|
1538
|
+
}
|
|
1539
|
+
|
|
1540
|
+
const selected = await ui.showToolFallbackSelector(
|
|
1541
|
+
agentManager.getToolFallbackMode()
|
|
1542
|
+
);
|
|
1543
|
+
if (!selected) {
|
|
1544
|
+
return null;
|
|
1545
|
+
}
|
|
1546
|
+
|
|
1547
|
+
return `/tool-fallback ${selected}`;
|
|
1548
|
+
};
|
|
1549
|
+
|
|
1550
|
+
const resolveReasoningModeCommandInput = async (
|
|
1551
|
+
ui: CliUi,
|
|
1552
|
+
commandInput: string,
|
|
1553
|
+
parsed: ReturnType<typeof parseCommand>
|
|
1554
|
+
): Promise<string | null> => {
|
|
1555
|
+
if (
|
|
1556
|
+
!parsed ||
|
|
1557
|
+
(parsed.name !== "think" && parsed.name !== "reasoning-mode") ||
|
|
1558
|
+
parsed.args.length > 0
|
|
1559
|
+
) {
|
|
1560
|
+
return commandInput;
|
|
1561
|
+
}
|
|
1562
|
+
|
|
1563
|
+
const selected = await ui.showReasoningModeSelector(
|
|
1564
|
+
agentManager.getReasoningMode()
|
|
1565
|
+
);
|
|
1566
|
+
if (!selected) {
|
|
1567
|
+
return null;
|
|
1568
|
+
}
|
|
1569
|
+
|
|
1570
|
+
return `/reasoning-mode ${selected}`;
|
|
1571
|
+
};
|
|
1572
|
+
|
|
1573
|
+
const resolveTranslateCommandInput = async (
|
|
1574
|
+
ui: CliUi,
|
|
1575
|
+
commandInput: string,
|
|
1576
|
+
parsed: ReturnType<typeof parseCommand>
|
|
1577
|
+
): Promise<string | null> => {
|
|
1578
|
+
if (parsed?.name !== "translate" || parsed.args.length > 0) {
|
|
1579
|
+
return commandInput;
|
|
1580
|
+
}
|
|
1581
|
+
|
|
1582
|
+
const selected = await ui.showTranslateModeSelector(
|
|
1583
|
+
agentManager.isTranslationEnabled()
|
|
1584
|
+
);
|
|
1585
|
+
if (selected === null) {
|
|
1586
|
+
return null;
|
|
1587
|
+
}
|
|
1588
|
+
|
|
1589
|
+
return `/translate ${selected ? "on" : "off"}`;
|
|
1590
|
+
};
|
|
1591
|
+
|
|
1592
|
+
const handleCommand = async (ui: CliUi, input: string): Promise<boolean> => {
|
|
1593
|
+
let commandInput = input;
|
|
1594
|
+
const initialParsed = parseCommand(commandInput);
|
|
1595
|
+
|
|
1596
|
+
const modelHandled = await handleModelCommand(
|
|
1597
|
+
ui,
|
|
1598
|
+
commandInput,
|
|
1599
|
+
initialParsed
|
|
1600
|
+
);
|
|
1601
|
+
if (modelHandled !== null) {
|
|
1602
|
+
return modelHandled;
|
|
1603
|
+
}
|
|
1604
|
+
|
|
1605
|
+
const toolFallbackCommandInput = await resolveToolFallbackCommandInput(
|
|
1606
|
+
ui,
|
|
1607
|
+
commandInput,
|
|
1608
|
+
initialParsed
|
|
1609
|
+
);
|
|
1610
|
+
if (!toolFallbackCommandInput) {
|
|
1611
|
+
return true;
|
|
1612
|
+
}
|
|
1613
|
+
commandInput = toolFallbackCommandInput;
|
|
1614
|
+
|
|
1615
|
+
const reasoningModeCommandInput = await resolveReasoningModeCommandInput(
|
|
1616
|
+
ui,
|
|
1617
|
+
commandInput,
|
|
1618
|
+
initialParsed
|
|
1619
|
+
);
|
|
1620
|
+
if (!reasoningModeCommandInput) {
|
|
1621
|
+
return true;
|
|
1622
|
+
}
|
|
1623
|
+
commandInput = reasoningModeCommandInput;
|
|
1624
|
+
|
|
1625
|
+
const translateCommandInput = await resolveTranslateCommandInput(
|
|
1626
|
+
ui,
|
|
1627
|
+
commandInput,
|
|
1628
|
+
initialParsed
|
|
1629
|
+
);
|
|
1630
|
+
if (!translateCommandInput) {
|
|
1631
|
+
return true;
|
|
1632
|
+
}
|
|
1633
|
+
commandInput = translateCommandInput;
|
|
1634
|
+
|
|
1635
|
+
const parsed = parseCommand(commandInput);
|
|
1636
|
+
const resolvedCommandName = parsed
|
|
1637
|
+
? resolveRegisteredCommandName(parsed.name)
|
|
1638
|
+
: null;
|
|
1639
|
+
const isNativeCommand =
|
|
1640
|
+
resolvedCommandName === "clear" ||
|
|
1641
|
+
resolvedCommandName === "reasoning-mode" ||
|
|
1642
|
+
resolvedCommandName === "tool-fallback" ||
|
|
1643
|
+
resolvedCommandName === "translate";
|
|
1644
|
+
|
|
1645
|
+
if (!isNativeCommand) {
|
|
1646
|
+
ui.showLoader("Working...");
|
|
1647
|
+
}
|
|
1648
|
+
|
|
1649
|
+
const result = await executeCommand(commandInput);
|
|
1650
|
+
|
|
1651
|
+
if (!isNativeCommand) {
|
|
1652
|
+
ui.clearStatus();
|
|
1653
|
+
}
|
|
1654
|
+
|
|
1655
|
+
if (result?.action === "new-session") {
|
|
1656
|
+
ui.clearStatus();
|
|
1657
|
+
initializeSession();
|
|
1658
|
+
messageHistory.clear();
|
|
1659
|
+
ui.chatContainer.clear();
|
|
1660
|
+
addNewSessionMessage(ui.chatContainer);
|
|
1661
|
+
ui.updateHeader();
|
|
1662
|
+
ui.tui.requestRender();
|
|
1663
|
+
return true;
|
|
1664
|
+
}
|
|
1665
|
+
|
|
1666
|
+
if (isSkillCommandResult(result)) {
|
|
1667
|
+
const skillMessage = `<command-name>/${result.skillId}</command-name>\n\n${result.skillContent}`;
|
|
1668
|
+
messageHistory.addUserMessage(skillMessage);
|
|
1669
|
+
await handleAgentResponse(ui);
|
|
1670
|
+
return true;
|
|
1671
|
+
}
|
|
1672
|
+
|
|
1673
|
+
if (result?.message) {
|
|
1674
|
+
renderCommandMessage(ui, result.message);
|
|
1675
|
+
return true;
|
|
1676
|
+
}
|
|
1677
|
+
|
|
1678
|
+
return false;
|
|
1679
|
+
};
|
|
1680
|
+
|
|
1681
|
+
const processInput = async (ui: CliUi, input: string): Promise<boolean> => {
|
|
1682
|
+
const trimmed = input.trim();
|
|
1683
|
+
|
|
1684
|
+
if (shouldExit || trimmed.length === 0 || trimmed.toLowerCase() === "exit") {
|
|
1685
|
+
return false;
|
|
1686
|
+
}
|
|
1687
|
+
|
|
1688
|
+
ui.editor.disableSubmit = true;
|
|
1689
|
+
try {
|
|
1690
|
+
if (isCommand(trimmed)) {
|
|
1691
|
+
addUserMessage(ui.chatContainer, ui.markdownTheme, trimmed);
|
|
1692
|
+
ui.tui.requestRender();
|
|
1693
|
+
return await handleCommand(ui, trimmed);
|
|
1694
|
+
}
|
|
1695
|
+
|
|
1696
|
+
let contentForModel = trimmed;
|
|
1697
|
+
let originalContent: string | undefined;
|
|
1698
|
+
let translationError: string | undefined;
|
|
1699
|
+
|
|
1700
|
+
if (agentManager.isTranslationEnabled()) {
|
|
1701
|
+
const shouldShowTranslationLoader = isNonEnglish(trimmed);
|
|
1702
|
+
if (shouldShowTranslationLoader) {
|
|
1703
|
+
addUserMessage(ui.chatContainer, ui.markdownTheme, trimmed);
|
|
1704
|
+
ui.tui.requestRender();
|
|
1705
|
+
}
|
|
1706
|
+
|
|
1707
|
+
if (shouldShowTranslationLoader) {
|
|
1708
|
+
ui.showLoader("Translating...");
|
|
1709
|
+
}
|
|
1710
|
+
|
|
1711
|
+
try {
|
|
1712
|
+
const translationResult = await translateToEnglish(
|
|
1713
|
+
trimmed,
|
|
1714
|
+
agentManager
|
|
1715
|
+
);
|
|
1716
|
+
contentForModel = translationResult.text;
|
|
1717
|
+
originalContent = translationResult.originalText;
|
|
1718
|
+
translationError = translationResult.error;
|
|
1719
|
+
} finally {
|
|
1720
|
+
if (shouldShowTranslationLoader) {
|
|
1721
|
+
ui.clearStatus();
|
|
1722
|
+
}
|
|
1723
|
+
}
|
|
1724
|
+
}
|
|
1725
|
+
|
|
1726
|
+
if (!(isNonEnglish(trimmed) && agentManager.isTranslationEnabled())) {
|
|
1727
|
+
addUserMessage(ui.chatContainer, ui.markdownTheme, contentForModel);
|
|
1728
|
+
} else if (originalContent) {
|
|
1729
|
+
addTranslatedMessage(ui.chatContainer, ui.markdownTheme, contentForModel);
|
|
1730
|
+
}
|
|
1731
|
+
|
|
1732
|
+
if (translationError) {
|
|
1733
|
+
addSystemMessage(
|
|
1734
|
+
ui.chatContainer,
|
|
1735
|
+
`[translation] Failed to translate input: ${translationError}. Using original text.`
|
|
1736
|
+
);
|
|
1737
|
+
}
|
|
1738
|
+
messageHistory.addUserMessage(contentForModel, originalContent);
|
|
1739
|
+
ui.tui.requestRender();
|
|
1740
|
+
await handleAgentResponse(ui);
|
|
1741
|
+
return true;
|
|
1742
|
+
} catch (error) {
|
|
1743
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
1744
|
+
addSystemMessage(ui.chatContainer, `Error: ${errorMessage}`);
|
|
1745
|
+
ui.tui.requestRender();
|
|
1746
|
+
return true;
|
|
1747
|
+
} finally {
|
|
1748
|
+
ui.editor.disableSubmit = false;
|
|
1749
|
+
ui.editor.setText("");
|
|
1750
|
+
ui.tui.setFocus(ui.editor);
|
|
1751
|
+
ui.tui.requestRender();
|
|
1752
|
+
}
|
|
1753
|
+
};
|
|
1754
|
+
|
|
1755
|
+
const run = async (): Promise<void> => {
|
|
1756
|
+
await initializeTools();
|
|
1757
|
+
cachedSkills = await loadAllSkills();
|
|
1758
|
+
setSpinnerOutputEnabled(false);
|
|
1759
|
+
|
|
1760
|
+
initializeSession();
|
|
1761
|
+
setupAgent();
|
|
1762
|
+
|
|
1763
|
+
const ui = createCliUi(cachedSkills);
|
|
1764
|
+
activeUiForSignals = ui;
|
|
1765
|
+
|
|
1766
|
+
try {
|
|
1767
|
+
while (!shouldExit) {
|
|
1768
|
+
const input = await ui.waitForInput();
|
|
1769
|
+
if (input === null) {
|
|
1770
|
+
break;
|
|
1771
|
+
}
|
|
1772
|
+
|
|
1773
|
+
const shouldContinue = await processInput(ui, input);
|
|
1774
|
+
if (!shouldContinue) {
|
|
1775
|
+
break;
|
|
1776
|
+
}
|
|
1777
|
+
}
|
|
1778
|
+
} finally {
|
|
1779
|
+
activeUiForSignals = null;
|
|
1780
|
+
await ui.dispose();
|
|
1781
|
+
cleanupExecutionResources();
|
|
1782
|
+
setSpinnerOutputEnabled(true);
|
|
1783
|
+
}
|
|
1784
|
+
|
|
1785
|
+
if (requestedProcessExitCode !== null) {
|
|
1786
|
+
process.exit(requestedProcessExitCode);
|
|
1787
|
+
}
|
|
1788
|
+
};
|
|
1789
|
+
|
|
1790
|
+
const cleanupExecutionResources = (): void => {
|
|
1791
|
+
cleanup();
|
|
1792
|
+
};
|
|
1793
|
+
|
|
1794
|
+
const exitWithCleanup = (code: number): never => {
|
|
1795
|
+
cleanup(true);
|
|
1796
|
+
process.exit(code);
|
|
1797
|
+
};
|
|
1798
|
+
|
|
1799
|
+
const requestSignalShutdown = (code: number): void => {
|
|
1800
|
+
if (signalShutdownRequested) {
|
|
1801
|
+
return;
|
|
1802
|
+
}
|
|
1803
|
+
signalShutdownRequested = true;
|
|
1804
|
+
|
|
1805
|
+
requestedProcessExitCode = code;
|
|
1806
|
+
shouldExit = true;
|
|
1807
|
+
|
|
1808
|
+
if (activeUiForSignals) {
|
|
1809
|
+
activeUiForSignals.requestExit();
|
|
1810
|
+
return;
|
|
1811
|
+
}
|
|
1812
|
+
|
|
1813
|
+
exitWithCleanup(code);
|
|
1814
|
+
};
|
|
1815
|
+
|
|
1816
|
+
process.once("exit", () => {
|
|
1817
|
+
cleanupExecutionResources();
|
|
1818
|
+
});
|
|
1819
|
+
|
|
1820
|
+
process.once("SIGTERM", () => {
|
|
1821
|
+
requestSignalShutdown(143);
|
|
1822
|
+
});
|
|
1823
|
+
|
|
1824
|
+
process.once("SIGHUP", () => {
|
|
1825
|
+
requestSignalShutdown(129);
|
|
1826
|
+
});
|
|
1827
|
+
|
|
1828
|
+
process.once("SIGQUIT", () => {
|
|
1829
|
+
requestSignalShutdown(131);
|
|
1830
|
+
});
|
|
1831
|
+
|
|
1832
|
+
process.once("uncaughtException", (error: unknown) => {
|
|
1833
|
+
console.error("Fatal error:", error);
|
|
1834
|
+
exitWithCleanup(1);
|
|
1835
|
+
});
|
|
1836
|
+
|
|
1837
|
+
process.once("unhandledRejection", (reason: unknown) => {
|
|
1838
|
+
console.error("Unhandled rejection:", reason);
|
|
1839
|
+
exitWithCleanup(1);
|
|
1840
|
+
});
|
|
1841
|
+
|
|
1842
|
+
run().catch((error: unknown) => {
|
|
1843
|
+
console.error("Fatal error:", error);
|
|
1844
|
+
exitWithCleanup(1);
|
|
1845
|
+
});
|