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,101 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { writeFile } from "node:fs/promises";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
|
|
6
|
+
const ANSI_ESCAPE_PREFIX = `${String.fromCharCode(27)}${String.fromCharCode(155)}`;
|
|
7
|
+
const ANSI_ESCAPE_PATTERN = new RegExp(
|
|
8
|
+
`[${ANSI_ESCAPE_PREFIX}][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]`,
|
|
9
|
+
"g"
|
|
10
|
+
);
|
|
11
|
+
const MULTIPLE_NEWLINE_PATTERN = /\n{3,}/g;
|
|
12
|
+
|
|
13
|
+
export interface TruncationResult {
|
|
14
|
+
fullOutputPath?: string;
|
|
15
|
+
originalBytes: number;
|
|
16
|
+
originalLines: number;
|
|
17
|
+
text: string;
|
|
18
|
+
truncated: boolean;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function stripAnsi(text: string): string {
|
|
22
|
+
return text.replace(ANSI_ESCAPE_PATTERN, "");
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function sanitizeOutput(text: string): string {
|
|
26
|
+
return stripAnsi(text)
|
|
27
|
+
.replace(/\r/g, "")
|
|
28
|
+
.replace(MULTIPLE_NEWLINE_PATTERN, "\n\n");
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async function persistFullOutput(text: string): Promise<string> {
|
|
32
|
+
for (let attempt = 0; attempt < 3; attempt += 1) {
|
|
33
|
+
const tempPath = join(tmpdir(), `cea-output-${randomUUID()}.txt`);
|
|
34
|
+
try {
|
|
35
|
+
await writeFile(tempPath, text, { encoding: "utf-8", flag: "wx" });
|
|
36
|
+
return tempPath;
|
|
37
|
+
} catch (error) {
|
|
38
|
+
if (
|
|
39
|
+
typeof error === "object" &&
|
|
40
|
+
error !== null &&
|
|
41
|
+
"code" in error &&
|
|
42
|
+
(error as NodeJS.ErrnoException).code === "EEXIST"
|
|
43
|
+
) {
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
throw error;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
throw new Error("Failed to persist truncated output.");
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export async function truncateOutput(
|
|
54
|
+
text: string,
|
|
55
|
+
options: { maxLines?: number; maxBytes?: number } = {}
|
|
56
|
+
): Promise<TruncationResult> {
|
|
57
|
+
const maxLines = options.maxLines ?? 2000;
|
|
58
|
+
const maxBytes = options.maxBytes ?? 51_200;
|
|
59
|
+
|
|
60
|
+
const originalLines = text.split("\n").length;
|
|
61
|
+
const originalBytes = Buffer.byteLength(text);
|
|
62
|
+
|
|
63
|
+
if (originalLines <= maxLines && originalBytes <= maxBytes) {
|
|
64
|
+
return {
|
|
65
|
+
text,
|
|
66
|
+
truncated: false,
|
|
67
|
+
originalLines,
|
|
68
|
+
originalBytes,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const firstLineLimit = Math.max(1, Math.floor(maxLines * 0.2));
|
|
73
|
+
const lastLineLimit = Math.max(0, maxLines - 1 - firstLineLimit);
|
|
74
|
+
|
|
75
|
+
const lines = text.split("\n");
|
|
76
|
+
const firstLines = lines.slice(0, firstLineLimit);
|
|
77
|
+
const lastStart = Math.max(firstLines.length, lines.length - lastLineLimit);
|
|
78
|
+
const lastLines = lines.slice(lastStart);
|
|
79
|
+
const omittedLineCount = Math.max(
|
|
80
|
+
0,
|
|
81
|
+
lines.length - (firstLines.length + lastLines.length)
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
const tempPath = await persistFullOutput(text);
|
|
85
|
+
|
|
86
|
+
const truncatedText = [
|
|
87
|
+
...firstLines,
|
|
88
|
+
`[...] ${omittedLineCount} lines omitted. Full output saved to ${tempPath}. Use read_file to view specific sections.`,
|
|
89
|
+
...lastLines,
|
|
90
|
+
]
|
|
91
|
+
.filter((line) => line.length > 0)
|
|
92
|
+
.join("\n");
|
|
93
|
+
|
|
94
|
+
return {
|
|
95
|
+
text: truncatedText,
|
|
96
|
+
truncated: true,
|
|
97
|
+
fullOutputPath: tempPath,
|
|
98
|
+
originalLines,
|
|
99
|
+
originalBytes,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { afterAll, beforeAll, describe, expect, it } from "bun:test";
|
|
2
|
+
import { spawn } from "node:child_process";
|
|
3
|
+
import { existsSync, mkdtempSync, realpathSync, rmSync } from "node:fs";
|
|
4
|
+
import { tmpdir } from "node:os";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
import { executeCommand, killProcessTree } from "./process-manager";
|
|
7
|
+
import { getShell, getShellArgs } from "./shell-detection";
|
|
8
|
+
|
|
9
|
+
const FIVE_SECONDS_MS = 5000;
|
|
10
|
+
const SIGKILL_GRACE_MS = 1000;
|
|
11
|
+
const ABORT_DELAY_MS = 50;
|
|
12
|
+
const SHORT_TIMEOUT_MS = 100;
|
|
13
|
+
|
|
14
|
+
function hasErrnoCode(error: unknown, code: string): boolean {
|
|
15
|
+
return (
|
|
16
|
+
typeof error === "object" &&
|
|
17
|
+
error !== null &&
|
|
18
|
+
"code" in error &&
|
|
19
|
+
(error as { code?: string }).code === code
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function isProcessAlive(pid: number): boolean {
|
|
24
|
+
try {
|
|
25
|
+
process.kill(pid, 0);
|
|
26
|
+
return true;
|
|
27
|
+
} catch (error) {
|
|
28
|
+
return hasErrnoCode(error, "EPERM");
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function sleep(ms: number): Promise<void> {
|
|
33
|
+
return new Promise((resolve) => {
|
|
34
|
+
setTimeout(resolve, ms);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
describe("process-manager", () => {
|
|
39
|
+
let tempDir: string;
|
|
40
|
+
|
|
41
|
+
beforeAll(() => {
|
|
42
|
+
tempDir = mkdtempSync(join(tmpdir(), "process-manager-test-"));
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
afterAll(() => {
|
|
46
|
+
if (existsSync(tempDir)) {
|
|
47
|
+
rmSync(tempDir, { recursive: true, force: true });
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("returns exact command result for echo hello", async () => {
|
|
52
|
+
const result = await executeCommand("echo hello");
|
|
53
|
+
|
|
54
|
+
expect(result).toEqual({
|
|
55
|
+
exitCode: 0,
|
|
56
|
+
output: "hello\n",
|
|
57
|
+
cancelled: false,
|
|
58
|
+
timedOut: false,
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it("returns non-zero exit code for failing command", async () => {
|
|
63
|
+
const result = await executeCommand("exit 1");
|
|
64
|
+
|
|
65
|
+
expect(result.exitCode).toBe(1);
|
|
66
|
+
expect(result.cancelled).toBe(false);
|
|
67
|
+
expect(result.timedOut).toBe(false);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("executes commands in provided workdir", async () => {
|
|
71
|
+
const result = await executeCommand("pwd", { workdir: tempDir });
|
|
72
|
+
const actualWorkdir = realpathSync(result.output.trim());
|
|
73
|
+
const expectedWorkdir = realpathSync(tempDir);
|
|
74
|
+
|
|
75
|
+
expect(result.exitCode).toBe(0);
|
|
76
|
+
expect(actualWorkdir).toBe(expectedWorkdir);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it("uses stdin ignore by default", async () => {
|
|
80
|
+
const startedAt = Date.now();
|
|
81
|
+
const result = await executeCommand("cat", { timeoutMs: FIVE_SECONDS_MS });
|
|
82
|
+
const elapsed = Date.now() - startedAt;
|
|
83
|
+
|
|
84
|
+
expect(result.exitCode).toBe(0);
|
|
85
|
+
expect(result.timedOut).toBe(false);
|
|
86
|
+
expect(elapsed).toBeLessThan(FIVE_SECONDS_MS);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it("streams combined chunks through onChunk callback", async () => {
|
|
90
|
+
const streamedChunks: string[] = [];
|
|
91
|
+
|
|
92
|
+
const result = await executeCommand(
|
|
93
|
+
"printf 'stdout-chunk'; printf 'stderr-chunk' >&2",
|
|
94
|
+
{
|
|
95
|
+
onChunk: (chunk) => {
|
|
96
|
+
streamedChunks.push(chunk);
|
|
97
|
+
},
|
|
98
|
+
}
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
const streamedOutput = streamedChunks.join("");
|
|
102
|
+
|
|
103
|
+
expect(result.exitCode).toBe(0);
|
|
104
|
+
expect(result.output).toContain("stdout-chunk");
|
|
105
|
+
expect(result.output).toContain("stderr-chunk");
|
|
106
|
+
expect(streamedChunks.length).toBeGreaterThan(0);
|
|
107
|
+
expect(streamedOutput).toContain("stdout-chunk");
|
|
108
|
+
expect(streamedOutput).toContain("stderr-chunk");
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it("sets timedOut=true and kills process within 5 seconds", async () => {
|
|
112
|
+
const startedAt = Date.now();
|
|
113
|
+
const result = await executeCommand("trap '' TERM; sleep 30", {
|
|
114
|
+
timeoutMs: SHORT_TIMEOUT_MS,
|
|
115
|
+
});
|
|
116
|
+
const elapsed = Date.now() - startedAt;
|
|
117
|
+
|
|
118
|
+
expect(result.timedOut).toBe(true);
|
|
119
|
+
expect(result.cancelled).toBe(false);
|
|
120
|
+
expect(result.exitCode).toBe(124);
|
|
121
|
+
expect(elapsed).toBeLessThan(FIVE_SECONDS_MS);
|
|
122
|
+
}, 10_000);
|
|
123
|
+
|
|
124
|
+
it("supports AbortSignal cancellation", async () => {
|
|
125
|
+
const controller = new AbortController();
|
|
126
|
+
const startedAt = Date.now();
|
|
127
|
+
const command = executeCommand("sleep 30", { signal: controller.signal });
|
|
128
|
+
|
|
129
|
+
setTimeout(() => {
|
|
130
|
+
controller.abort();
|
|
131
|
+
}, ABORT_DELAY_MS);
|
|
132
|
+
|
|
133
|
+
const result = await command;
|
|
134
|
+
const elapsed = Date.now() - startedAt;
|
|
135
|
+
|
|
136
|
+
expect(result.cancelled).toBe(true);
|
|
137
|
+
expect(result.timedOut).toBe(false);
|
|
138
|
+
expect(result.exitCode).toBe(130);
|
|
139
|
+
expect(elapsed).toBeLessThan(FIVE_SECONDS_MS);
|
|
140
|
+
}, 10_000);
|
|
141
|
+
|
|
142
|
+
it("killProcessTree terminates detached process groups", async () => {
|
|
143
|
+
const shell = getShell();
|
|
144
|
+
const shellArgs = getShellArgs(shell);
|
|
145
|
+
const child = spawn(shell, [...shellArgs, "trap '' TERM; sleep 30"], {
|
|
146
|
+
detached: true,
|
|
147
|
+
stdio: ["ignore", "ignore", "ignore"],
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
const pid = child.pid;
|
|
151
|
+
expect(pid).toBeDefined();
|
|
152
|
+
|
|
153
|
+
if (!pid) {
|
|
154
|
+
throw new Error("Expected detached child pid to be defined");
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
try {
|
|
158
|
+
await sleep(ABORT_DELAY_MS);
|
|
159
|
+
killProcessTree(pid);
|
|
160
|
+
await sleep(SIGKILL_GRACE_MS);
|
|
161
|
+
|
|
162
|
+
expect(isProcessAlive(pid)).toBe(false);
|
|
163
|
+
} finally {
|
|
164
|
+
killProcessTree(pid);
|
|
165
|
+
}
|
|
166
|
+
}, 10_000);
|
|
167
|
+
|
|
168
|
+
it("does not use spawnSync", async () => {
|
|
169
|
+
const source = await Bun.file(
|
|
170
|
+
new URL("./process-manager.ts", import.meta.url)
|
|
171
|
+
).text();
|
|
172
|
+
|
|
173
|
+
expect(source.includes("spawnSync")).toBe(false);
|
|
174
|
+
});
|
|
175
|
+
});
|
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { getFullWrappedCommand as wrapCommand } from "./noninteractive-wrapper";
|
|
3
|
+
import { sanitizeOutput, truncateOutput } from "./output-handler";
|
|
4
|
+
import { getShell, getShellArgs } from "./shell-detection";
|
|
5
|
+
|
|
6
|
+
const DEFAULT_TIMEOUT_MS = 120_000;
|
|
7
|
+
const SIGKILL_DELAY_MS = 200;
|
|
8
|
+
const SPAWN_ERROR_EXIT_CODE = 1;
|
|
9
|
+
const CANCELLED_EXIT_CODE = 130;
|
|
10
|
+
const TIMEOUT_EXIT_CODE = 124;
|
|
11
|
+
const MAX_IN_MEMORY_OUTPUT_BYTES = 2 * 1024 * 1024;
|
|
12
|
+
const TRIMMED_BUFFER_TARGET_BYTES = 512 * 1024;
|
|
13
|
+
const activeProcesses = new Set<number>();
|
|
14
|
+
|
|
15
|
+
export interface ExecuteOptions {
|
|
16
|
+
onChunk?: (chunk: string) => void;
|
|
17
|
+
signal?: AbortSignal;
|
|
18
|
+
stdin?: "ignore" | "pipe";
|
|
19
|
+
timeoutMs?: number;
|
|
20
|
+
workdir?: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface ExecuteResult {
|
|
24
|
+
cancelled: boolean;
|
|
25
|
+
exitCode: number;
|
|
26
|
+
output: string;
|
|
27
|
+
timedOut: boolean;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function hasErrnoCode(error: unknown, code: string): boolean {
|
|
31
|
+
return (
|
|
32
|
+
typeof error === "object" &&
|
|
33
|
+
error !== null &&
|
|
34
|
+
"code" in error &&
|
|
35
|
+
(error as { code?: string }).code === code
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function isProcessGroupAlive(pid: number): boolean {
|
|
40
|
+
if (pid <= 1) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
try {
|
|
44
|
+
process.kill(-pid, 0);
|
|
45
|
+
return true;
|
|
46
|
+
} catch (error) {
|
|
47
|
+
return hasErrnoCode(error, "EPERM");
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function safeKillProcessGroup(pid: number, signal: NodeJS.Signals): void {
|
|
52
|
+
if (pid <= 1) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
try {
|
|
56
|
+
process.kill(-pid, signal);
|
|
57
|
+
} catch (error) {
|
|
58
|
+
if (hasErrnoCode(error, "ESRCH") || hasErrnoCode(error, "EPERM")) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
throw error;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function resolveExitCode(
|
|
66
|
+
code: number | null,
|
|
67
|
+
timedOut: boolean,
|
|
68
|
+
cancelled: boolean,
|
|
69
|
+
spawnFailed: boolean
|
|
70
|
+
): number {
|
|
71
|
+
if (typeof code === "number") {
|
|
72
|
+
return code;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (timedOut) {
|
|
76
|
+
return TIMEOUT_EXIT_CODE;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (cancelled) {
|
|
80
|
+
return CANCELLED_EXIT_CODE;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (spawnFailed) {
|
|
84
|
+
return SPAWN_ERROR_EXIT_CODE;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return SPAWN_ERROR_EXIT_CODE;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function trimToLastBytes(
|
|
91
|
+
text: string,
|
|
92
|
+
maxBytes: number
|
|
93
|
+
): { droppedBytes: number; text: string } {
|
|
94
|
+
const bytes = Buffer.from(text, "utf-8");
|
|
95
|
+
if (bytes.length <= maxBytes) {
|
|
96
|
+
return { text, droppedBytes: 0 };
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const start = bytes.length - maxBytes;
|
|
100
|
+
|
|
101
|
+
return {
|
|
102
|
+
text: bytes.subarray(start).toString("utf-8"),
|
|
103
|
+
droppedBytes: start,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export function killProcessTree(pid: number, force = false): void {
|
|
108
|
+
if (pid <= 1) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
safeKillProcessGroup(pid, "SIGTERM");
|
|
113
|
+
|
|
114
|
+
if (force) {
|
|
115
|
+
safeKillProcessGroup(pid, "SIGKILL");
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const handle = setTimeout(() => {
|
|
120
|
+
if (!isProcessGroupAlive(pid)) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
safeKillProcessGroup(pid, "SIGKILL");
|
|
124
|
+
}, SIGKILL_DELAY_MS);
|
|
125
|
+
if (typeof handle === "object" && "unref" in handle) {
|
|
126
|
+
handle.unref();
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export async function executeCommand(
|
|
131
|
+
command: string,
|
|
132
|
+
options: ExecuteOptions = {}
|
|
133
|
+
): Promise<ExecuteResult> {
|
|
134
|
+
const {
|
|
135
|
+
workdir,
|
|
136
|
+
timeoutMs = DEFAULT_TIMEOUT_MS,
|
|
137
|
+
signal,
|
|
138
|
+
onChunk,
|
|
139
|
+
stdin = "ignore",
|
|
140
|
+
} = options;
|
|
141
|
+
|
|
142
|
+
if (signal?.aborted) {
|
|
143
|
+
return {
|
|
144
|
+
exitCode: CANCELLED_EXIT_CODE,
|
|
145
|
+
output: "",
|
|
146
|
+
cancelled: true,
|
|
147
|
+
timedOut: false,
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const shell = getShell();
|
|
152
|
+
const shellArgs = getShellArgs(shell);
|
|
153
|
+
const wrappedCommand = wrapCommand(command);
|
|
154
|
+
|
|
155
|
+
return await new Promise<ExecuteResult>((resolve) => {
|
|
156
|
+
const child = spawn(shell, [...shellArgs, wrappedCommand], {
|
|
157
|
+
detached: true,
|
|
158
|
+
stdio: [stdin, "pipe", "pipe"],
|
|
159
|
+
cwd: workdir,
|
|
160
|
+
env: {
|
|
161
|
+
...process.env,
|
|
162
|
+
TERM: "dumb",
|
|
163
|
+
},
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
child.unref();
|
|
167
|
+
|
|
168
|
+
if (child.pid) {
|
|
169
|
+
activeProcesses.add(child.pid);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const stdoutDecoder = new TextDecoder();
|
|
173
|
+
const stderrDecoder = new TextDecoder();
|
|
174
|
+
let bufferedOutput = "";
|
|
175
|
+
let droppedBytes = 0;
|
|
176
|
+
|
|
177
|
+
let timedOut = false;
|
|
178
|
+
let cancelled = false;
|
|
179
|
+
let spawnFailed = false;
|
|
180
|
+
let settled = false;
|
|
181
|
+
|
|
182
|
+
const timeoutHandle = setTimeout(() => {
|
|
183
|
+
timedOut = true;
|
|
184
|
+
if (child.pid) {
|
|
185
|
+
killProcessTree(child.pid);
|
|
186
|
+
}
|
|
187
|
+
}, timeoutMs);
|
|
188
|
+
|
|
189
|
+
const abortHandler = () => {
|
|
190
|
+
cancelled = true;
|
|
191
|
+
if (child.pid) {
|
|
192
|
+
killProcessTree(child.pid);
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
if (signal) {
|
|
197
|
+
signal.addEventListener("abort", abortHandler, { once: true });
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const appendChunk = (chunk: Buffer, decoder: TextDecoder): void => {
|
|
201
|
+
const decoded = decoder.decode(chunk, { stream: true });
|
|
202
|
+
bufferedOutput += decoded;
|
|
203
|
+
if (
|
|
204
|
+
Buffer.byteLength(bufferedOutput, "utf-8") > MAX_IN_MEMORY_OUTPUT_BYTES
|
|
205
|
+
) {
|
|
206
|
+
const trimmed = trimToLastBytes(
|
|
207
|
+
bufferedOutput,
|
|
208
|
+
TRIMMED_BUFFER_TARGET_BYTES
|
|
209
|
+
);
|
|
210
|
+
bufferedOutput = trimmed.text;
|
|
211
|
+
droppedBytes += trimmed.droppedBytes;
|
|
212
|
+
}
|
|
213
|
+
onChunk?.(decoded);
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
const flushDecoder = (decoder: TextDecoder): void => {
|
|
217
|
+
const remaining = decoder.decode();
|
|
218
|
+
if (!remaining) {
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
bufferedOutput += remaining;
|
|
222
|
+
if (
|
|
223
|
+
Buffer.byteLength(bufferedOutput, "utf-8") > MAX_IN_MEMORY_OUTPUT_BYTES
|
|
224
|
+
) {
|
|
225
|
+
const trimmed = trimToLastBytes(
|
|
226
|
+
bufferedOutput,
|
|
227
|
+
TRIMMED_BUFFER_TARGET_BYTES
|
|
228
|
+
);
|
|
229
|
+
bufferedOutput = trimmed.text;
|
|
230
|
+
droppedBytes += trimmed.droppedBytes;
|
|
231
|
+
}
|
|
232
|
+
onChunk?.(remaining);
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
const finish = (code: number | null): void => {
|
|
236
|
+
if (settled) {
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
settled = true;
|
|
240
|
+
|
|
241
|
+
if (child.pid) {
|
|
242
|
+
activeProcesses.delete(child.pid);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
clearTimeout(timeoutHandle);
|
|
246
|
+
if (signal) {
|
|
247
|
+
signal.removeEventListener("abort", abortHandler);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
flushDecoder(stdoutDecoder);
|
|
251
|
+
flushDecoder(stderrDecoder);
|
|
252
|
+
|
|
253
|
+
const sanitizedOutput = sanitizeOutput(bufferedOutput);
|
|
254
|
+
const withDroppedPrefix =
|
|
255
|
+
droppedBytes > 0
|
|
256
|
+
? `[... ${droppedBytes} bytes omitted before completion due to output volume ...]\n${sanitizedOutput}`
|
|
257
|
+
: sanitizedOutput;
|
|
258
|
+
truncateOutput(withDroppedPrefix)
|
|
259
|
+
.then((truncatedOutput) => {
|
|
260
|
+
resolve({
|
|
261
|
+
exitCode: resolveExitCode(code, timedOut, cancelled, spawnFailed),
|
|
262
|
+
output: truncatedOutput.text,
|
|
263
|
+
cancelled,
|
|
264
|
+
timedOut,
|
|
265
|
+
});
|
|
266
|
+
})
|
|
267
|
+
.catch((error) => {
|
|
268
|
+
const errorMessage =
|
|
269
|
+
error instanceof Error
|
|
270
|
+
? error.message
|
|
271
|
+
: "Failed to truncate output.";
|
|
272
|
+
resolve({
|
|
273
|
+
exitCode: resolveExitCode(code, timedOut, cancelled, spawnFailed),
|
|
274
|
+
output: `${withDroppedPrefix}\n${errorMessage}`,
|
|
275
|
+
cancelled,
|
|
276
|
+
timedOut,
|
|
277
|
+
});
|
|
278
|
+
});
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
child.stdout?.on("data", (chunk: Buffer) => {
|
|
282
|
+
appendChunk(chunk, stdoutDecoder);
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
child.stderr?.on("data", (chunk: Buffer) => {
|
|
286
|
+
appendChunk(chunk, stderrDecoder);
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
child.on("close", (code) => {
|
|
290
|
+
finish(code);
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
child.on("error", (error) => {
|
|
294
|
+
spawnFailed = true;
|
|
295
|
+
bufferedOutput += `${(error as Error).message}\n`;
|
|
296
|
+
finish(null);
|
|
297
|
+
});
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
export function cleanup(force = false): void {
|
|
302
|
+
for (const pid of activeProcesses) {
|
|
303
|
+
try {
|
|
304
|
+
killProcessTree(pid, force);
|
|
305
|
+
} catch {
|
|
306
|
+
// Best-effort cleanup: continue killing remaining processes
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
activeProcesses.clear();
|
|
310
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { spawnSync } from "node:child_process";
|
|
3
|
+
import { existsSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
4
|
+
import { platform, tmpdir } from "node:os";
|
|
5
|
+
import { dirname, join } from "node:path";
|
|
6
|
+
import { getShell, getShellArgs } from "./shell-detection";
|
|
7
|
+
|
|
8
|
+
const SHELL_DETECTION_SCRIPT =
|
|
9
|
+
"import { getShell } from './shell-detection'; console.log(getShell());";
|
|
10
|
+
const SHELL_DETECTION_CWD = join(
|
|
11
|
+
process.cwd(),
|
|
12
|
+
"packages",
|
|
13
|
+
"cea",
|
|
14
|
+
"src",
|
|
15
|
+
"tools",
|
|
16
|
+
"utils",
|
|
17
|
+
"execute"
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
function runShellDetectionWithEnv(shellPath: string): string {
|
|
21
|
+
const env = { ...process.env, SHELL: shellPath };
|
|
22
|
+
const result = spawnSync(process.execPath, ["-e", SHELL_DETECTION_SCRIPT], {
|
|
23
|
+
cwd: SHELL_DETECTION_CWD,
|
|
24
|
+
env,
|
|
25
|
+
encoding: "utf8",
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
if (result.status !== 0 || !result.stdout) {
|
|
29
|
+
throw new Error("Failed to evaluate getShell in child process");
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return result.stdout.trim();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function createFakeShell(shellName: string): string {
|
|
36
|
+
const tempDir = mkdtempSync(join(tmpdir(), "shell-detection-"));
|
|
37
|
+
const shellPath = join(tempDir, shellName);
|
|
38
|
+
writeFileSync(shellPath, "#!/bin/sh\n");
|
|
39
|
+
return shellPath;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function removeFakeShell(shellPath: string): void {
|
|
43
|
+
rmSync(shellPath, { force: true });
|
|
44
|
+
rmSync(dirname(shellPath), { recursive: true, force: true });
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function getFallbackCandidates(): string[] {
|
|
48
|
+
if (platform() === "darwin") {
|
|
49
|
+
return ["/bin/zsh", "/bin/bash", "/bin/sh"];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (platform() === "linux") {
|
|
53
|
+
return ["/bin/bash", "/bin/sh"];
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return ["C:\\Program Files\\Git\\bin\\bash.exe", "cmd.exe"];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
describe("shell detection", () => {
|
|
60
|
+
test("returns a valid shell path", () => {
|
|
61
|
+
const shell = getShell();
|
|
62
|
+
|
|
63
|
+
expect(typeof shell).toBe("string");
|
|
64
|
+
expect(shell.length).toBeGreaterThan(0);
|
|
65
|
+
expect(existsSync(shell)).toBe(true);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test("returns cached shell path on repeated calls", () => {
|
|
69
|
+
const first = getShell();
|
|
70
|
+
const second = getShell();
|
|
71
|
+
|
|
72
|
+
expect(first).toBe(second);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
test("uses explicit SHELL path when valid", () => {
|
|
76
|
+
const fakeShell = createFakeShell("zsh-shell");
|
|
77
|
+
try {
|
|
78
|
+
const shell = runShellDetectionWithEnv(fakeShell);
|
|
79
|
+
expect(shell).toBe(fakeShell);
|
|
80
|
+
} finally {
|
|
81
|
+
removeFakeShell(fakeShell);
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
test("falls back when SHELL is rejected", () => {
|
|
86
|
+
const fakeRejectedShell = createFakeShell("fish");
|
|
87
|
+
try {
|
|
88
|
+
const shell = runShellDetectionWithEnv(fakeRejectedShell);
|
|
89
|
+
const candidates = getFallbackCandidates();
|
|
90
|
+
const availableFallback = candidates.find((candidate) =>
|
|
91
|
+
existsSync(candidate)
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
if (availableFallback) {
|
|
95
|
+
expect(shell).toBe(availableFallback);
|
|
96
|
+
}
|
|
97
|
+
expect(shell).not.toBe(fakeRejectedShell);
|
|
98
|
+
expect(existsSync(shell)).toBe(true);
|
|
99
|
+
} finally {
|
|
100
|
+
removeFakeShell(fakeRejectedShell);
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
test("returns args for unix shell format", () => {
|
|
105
|
+
expect(getShellArgs("/bin/bash")).toEqual(["-c"]);
|
|
106
|
+
expect(getShellArgs("/usr/bin/sh")).toEqual(["-c"]);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
test("returns args for cmd.exe", () => {
|
|
110
|
+
expect(getShellArgs("C:\\Windows\\System32\\cmd.exe")).toEqual(["/c"]);
|
|
111
|
+
});
|
|
112
|
+
});
|