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,72 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { platform } from "node:os";
|
|
3
|
+
import { basename, win32 } from "node:path";
|
|
4
|
+
|
|
5
|
+
const REJECTED_SHELL_BASENAMES = new Set(["fish", "nu", "csh", "tcsh"]);
|
|
6
|
+
const WINDOWS_GIT_BASH_PATH = "C:\\Program Files\\Git\\bin\\bash.exe";
|
|
7
|
+
const WINDOWS_CMD_PATH = "cmd.exe";
|
|
8
|
+
|
|
9
|
+
let cachedShell: string | null = null;
|
|
10
|
+
|
|
11
|
+
function resolveShellBasenames(shellPath: string): Set<string> {
|
|
12
|
+
const primary = basename(shellPath).toLowerCase();
|
|
13
|
+
const windows = win32.basename(shellPath).toLowerCase();
|
|
14
|
+
return primary === windows ? new Set([primary]) : new Set([primary, windows]);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function isRejectedShell(shellPath: string): boolean {
|
|
18
|
+
return [...resolveShellBasenames(shellPath)].some((name) =>
|
|
19
|
+
REJECTED_SHELL_BASENAMES.has(name)
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function getPlatformShellOptions(): string[] {
|
|
24
|
+
if (platform() === "darwin") {
|
|
25
|
+
return ["/bin/zsh", "/bin/bash", "/bin/sh"];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (platform() === "linux") {
|
|
29
|
+
return ["/bin/bash", "/bin/sh"];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return [WINDOWS_GIT_BASH_PATH, WINDOWS_CMD_PATH];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function firstExistingShell(shells: string[]): string | null {
|
|
36
|
+
for (const shell of shells) {
|
|
37
|
+
if (existsSync(shell)) {
|
|
38
|
+
return shell;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function getShell(): string {
|
|
46
|
+
if (cachedShell) {
|
|
47
|
+
return cachedShell;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const envShell = process.env.SHELL?.trim();
|
|
51
|
+
if (envShell && existsSync(envShell) && !isRejectedShell(envShell)) {
|
|
52
|
+
cachedShell = envShell;
|
|
53
|
+
return cachedShell;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const shell = firstExistingShell(getPlatformShellOptions());
|
|
57
|
+
if (shell) {
|
|
58
|
+
cachedShell = shell;
|
|
59
|
+
return shell;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
cachedShell = platform() === "win32" ? WINDOWS_CMD_PATH : "/bin/sh";
|
|
63
|
+
return cachedShell;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function getShellArgs(shell: string): string[] {
|
|
67
|
+
if (resolveShellBasenames(shell).has("cmd.exe")) {
|
|
68
|
+
return ["/c"];
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return ["-c"];
|
|
72
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { maybeExpandSingleLineMerge } from "./merge-expansion";
|
|
2
|
+
|
|
3
|
+
const LEADING_WS_REGEX = /^\s*/;
|
|
4
|
+
|
|
5
|
+
function normalizeTokens(text: string): string {
|
|
6
|
+
return text.replace(/\s+/g, "");
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function stripAllWhitespace(text: string): string {
|
|
10
|
+
return normalizeTokens(text);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// biome-ignore lint/performance/noBarrelFile: intentional re-export for module API surface
|
|
14
|
+
export {
|
|
15
|
+
maybeExpandSingleLineMerge,
|
|
16
|
+
stripMergeOperatorChars,
|
|
17
|
+
stripTrailingContinuationTokens,
|
|
18
|
+
} from "./merge-expansion";
|
|
19
|
+
|
|
20
|
+
function leadingWhitespace(text: string): string {
|
|
21
|
+
if (!text) {
|
|
22
|
+
return "";
|
|
23
|
+
}
|
|
24
|
+
const match = text.match(LEADING_WS_REGEX);
|
|
25
|
+
return match ? match[0] : "";
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: line-wrapping restoration algorithm
|
|
29
|
+
export function restoreOldWrappedLines(
|
|
30
|
+
originalLines: string[],
|
|
31
|
+
replacementLines: string[]
|
|
32
|
+
): string[] {
|
|
33
|
+
if (originalLines.length === 0 || replacementLines.length < 2) {
|
|
34
|
+
return replacementLines;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const canonicalToOriginal = new Map<
|
|
38
|
+
string,
|
|
39
|
+
{ line: string; count: number }
|
|
40
|
+
>();
|
|
41
|
+
for (const line of originalLines) {
|
|
42
|
+
const canonical = stripAllWhitespace(line);
|
|
43
|
+
const existing = canonicalToOriginal.get(canonical);
|
|
44
|
+
if (existing) {
|
|
45
|
+
existing.count += 1;
|
|
46
|
+
} else {
|
|
47
|
+
canonicalToOriginal.set(canonical, { line, count: 1 });
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const candidates: {
|
|
52
|
+
start: number;
|
|
53
|
+
len: number;
|
|
54
|
+
replacement: string;
|
|
55
|
+
canonical: string;
|
|
56
|
+
}[] = [];
|
|
57
|
+
for (let start = 0; start < replacementLines.length; start += 1) {
|
|
58
|
+
for (
|
|
59
|
+
let len = 2;
|
|
60
|
+
len <= 10 && start + len <= replacementLines.length;
|
|
61
|
+
len += 1
|
|
62
|
+
) {
|
|
63
|
+
const span = replacementLines.slice(start, start + len);
|
|
64
|
+
if (span.some((line) => line.trim().length === 0)) {
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
const canonicalSpan = stripAllWhitespace(span.join(""));
|
|
68
|
+
const original = canonicalToOriginal.get(canonicalSpan);
|
|
69
|
+
if (original && original.count === 1 && canonicalSpan.length >= 6) {
|
|
70
|
+
candidates.push({
|
|
71
|
+
start,
|
|
72
|
+
len,
|
|
73
|
+
replacement: original.line,
|
|
74
|
+
canonical: canonicalSpan,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (candidates.length === 0) {
|
|
80
|
+
return replacementLines;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const canonicalCounts = new Map<string, number>();
|
|
84
|
+
for (const candidate of candidates) {
|
|
85
|
+
canonicalCounts.set(
|
|
86
|
+
candidate.canonical,
|
|
87
|
+
(canonicalCounts.get(candidate.canonical) ?? 0) + 1
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const uniqueCandidates = candidates.filter(
|
|
92
|
+
(candidate) => (canonicalCounts.get(candidate.canonical) ?? 0) === 1
|
|
93
|
+
);
|
|
94
|
+
if (uniqueCandidates.length === 0) {
|
|
95
|
+
return replacementLines;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
uniqueCandidates.sort((a, b) => b.start - a.start);
|
|
99
|
+
// Filter overlapping candidates — walk sorted list and skip any whose range overlaps
|
|
100
|
+
const accepted: typeof uniqueCandidates = [];
|
|
101
|
+
let nextAvailable = Number.POSITIVE_INFINITY;
|
|
102
|
+
for (const candidate of uniqueCandidates) {
|
|
103
|
+
const candidateEnd = candidate.start + candidate.len;
|
|
104
|
+
if (candidateEnd <= nextAvailable) {
|
|
105
|
+
accepted.push(candidate);
|
|
106
|
+
nextAvailable = candidate.start;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
const correctedLines = [...replacementLines];
|
|
110
|
+
for (const candidate of accepted) {
|
|
111
|
+
correctedLines.splice(
|
|
112
|
+
candidate.start,
|
|
113
|
+
candidate.len,
|
|
114
|
+
candidate.replacement
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
return correctedLines;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export function restoreIndentForPairedReplacement(
|
|
121
|
+
originalLines: string[],
|
|
122
|
+
replacementLines: string[]
|
|
123
|
+
): string[] {
|
|
124
|
+
if (originalLines.length !== replacementLines.length) {
|
|
125
|
+
return replacementLines;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return replacementLines.map((line, idx) => {
|
|
129
|
+
if (line.length === 0) {
|
|
130
|
+
return line;
|
|
131
|
+
}
|
|
132
|
+
if (leadingWhitespace(line).length > 0) {
|
|
133
|
+
return line;
|
|
134
|
+
}
|
|
135
|
+
const indent = leadingWhitespace(originalLines[idx]);
|
|
136
|
+
if (indent.length === 0) {
|
|
137
|
+
return line;
|
|
138
|
+
}
|
|
139
|
+
// Original line is whitespace-only (no real content) — not meaningful indentation
|
|
140
|
+
if (originalLines[idx].trim().length === 0) {
|
|
141
|
+
return line;
|
|
142
|
+
}
|
|
143
|
+
if (originalLines[idx].trim() === line.trim()) {
|
|
144
|
+
return line;
|
|
145
|
+
}
|
|
146
|
+
return `${indent}${line}`;
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export function autocorrectReplacementLines(
|
|
151
|
+
originalLines: string[],
|
|
152
|
+
replacementLines: string[]
|
|
153
|
+
): string[] {
|
|
154
|
+
let next = replacementLines;
|
|
155
|
+
next = maybeExpandSingleLineMerge(originalLines, next);
|
|
156
|
+
next = restoreOldWrappedLines(originalLines, next);
|
|
157
|
+
next = restoreIndentForPairedReplacement(originalLines, next);
|
|
158
|
+
return next;
|
|
159
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export const NIBBLE_STR = "ZPMQVRWSNKTXJBYH";
|
|
2
|
+
|
|
3
|
+
export const HASHLINE_DICT = Array.from({ length: 256 }, (_, i) => {
|
|
4
|
+
// biome-ignore lint/suspicious/noBitwiseOperators: intentional bit shift for hash nibble extraction
|
|
5
|
+
const high = i >>> 4;
|
|
6
|
+
// biome-ignore lint/suspicious/noBitwiseOperators: intentional bit shift for hash nibble extraction
|
|
7
|
+
const low = i & 0x0f;
|
|
8
|
+
return `${NIBBLE_STR[high]}${NIBBLE_STR[low]}`;
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
export const HASHLINE_REF_PATTERN = /^([0-9]+)#([ZPMQVRWSNKTXJBYH]{2})$/;
|
|
12
|
+
export const HASHLINE_OUTPUT_PATTERN =
|
|
13
|
+
/^([0-9]+)#([ZPMQVRWSNKTXJBYH]{2})\|(.*)$/;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { describe, expect, it } from "bun:test";
|
|
2
|
+
import { generateUnifiedDiff } from "./diff-utils";
|
|
3
|
+
|
|
4
|
+
function createNumberedLines(totalLineCount: number): string {
|
|
5
|
+
return Array.from(
|
|
6
|
+
{ length: totalLineCount },
|
|
7
|
+
(_, index) => `line ${index + 1}`
|
|
8
|
+
).join("\n");
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
describe("generateUnifiedDiff", () => {
|
|
12
|
+
it("creates separate hunks for distant changes", () => {
|
|
13
|
+
const oldContent = createNumberedLines(60);
|
|
14
|
+
const newLines = oldContent.split("\n");
|
|
15
|
+
newLines[4] = "line 5 updated";
|
|
16
|
+
newLines[49] = "line 50 updated";
|
|
17
|
+
const newContent = newLines.join("\n");
|
|
18
|
+
|
|
19
|
+
const diff = generateUnifiedDiff(oldContent, newContent, "sample.txt");
|
|
20
|
+
|
|
21
|
+
const hunkHeaders = diff.match(/^@@/gm) ?? [];
|
|
22
|
+
expect(hunkHeaders.length).toBe(2);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it("creates a single hunk for adjacent changes", () => {
|
|
26
|
+
const oldContent = createNumberedLines(20);
|
|
27
|
+
const newLines = oldContent.split("\n");
|
|
28
|
+
newLines[9] = "line 10 updated";
|
|
29
|
+
newLines[10] = "line 11 updated";
|
|
30
|
+
const newContent = newLines.join("\n");
|
|
31
|
+
|
|
32
|
+
const diff = generateUnifiedDiff(oldContent, newContent, "sample.txt");
|
|
33
|
+
|
|
34
|
+
const hunkHeaders = diff.match(/^@@/gm) ?? [];
|
|
35
|
+
expect(hunkHeaders.length).toBe(1);
|
|
36
|
+
expect(diff).toContain(" line 8");
|
|
37
|
+
expect(diff).toContain(" line 13");
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("returns a diff string for identical content", () => {
|
|
41
|
+
const oldContent = "alpha\nbeta\ngamma";
|
|
42
|
+
const newContent = "alpha\nbeta\ngamma";
|
|
43
|
+
|
|
44
|
+
const diff = generateUnifiedDiff(oldContent, newContent, "sample.txt");
|
|
45
|
+
|
|
46
|
+
expect(typeof diff).toBe("string");
|
|
47
|
+
expect(diff).toContain("--- sample.txt");
|
|
48
|
+
expect(diff).toContain("+++ sample.txt");
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("returns a valid diff when old content is empty", () => {
|
|
52
|
+
const oldContent = "";
|
|
53
|
+
const newContent = "first line\nsecond line";
|
|
54
|
+
|
|
55
|
+
const diff = generateUnifiedDiff(oldContent, newContent, "sample.txt");
|
|
56
|
+
|
|
57
|
+
expect(diff).toContain("--- sample.txt");
|
|
58
|
+
expect(diff).toContain("+++ sample.txt");
|
|
59
|
+
expect(diff).toContain("+first line");
|
|
60
|
+
});
|
|
61
|
+
});
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { createTwoFilesPatch } from "diff";
|
|
2
|
+
import { computeLineHash } from "./hash-computation";
|
|
3
|
+
|
|
4
|
+
export function toHashlineContent(content: string): string {
|
|
5
|
+
if (!content) {
|
|
6
|
+
return content;
|
|
7
|
+
}
|
|
8
|
+
const lines = content.split("\n");
|
|
9
|
+
const lastLine = lines.at(-1);
|
|
10
|
+
const hasTrailingNewline = lastLine === "";
|
|
11
|
+
const contentLines = hasTrailingNewline ? lines.slice(0, -1) : lines;
|
|
12
|
+
const hashlined = contentLines.map((line, i) => {
|
|
13
|
+
const lineNum = i + 1;
|
|
14
|
+
const hash = computeLineHash(lineNum, line);
|
|
15
|
+
return `${lineNum}#${hash}|${line}`;
|
|
16
|
+
});
|
|
17
|
+
return hasTrailingNewline
|
|
18
|
+
? `${hashlined.join("\n")}\n`
|
|
19
|
+
: hashlined.join("\n");
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function generateUnifiedDiff(
|
|
23
|
+
oldContent: string,
|
|
24
|
+
newContent: string,
|
|
25
|
+
filePath: string
|
|
26
|
+
): string {
|
|
27
|
+
return createTwoFilesPatch(filePath, filePath, oldContent, newContent);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function countLineDiffs(
|
|
31
|
+
oldContent: string,
|
|
32
|
+
newContent: string
|
|
33
|
+
): { additions: number; deletions: number } {
|
|
34
|
+
const oldLines = oldContent.split("\n");
|
|
35
|
+
const newLines = newContent.split("\n");
|
|
36
|
+
|
|
37
|
+
const oldSet = new Map<string, number>();
|
|
38
|
+
for (const line of oldLines) {
|
|
39
|
+
oldSet.set(line, (oldSet.get(line) ?? 0) + 1);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const newSet = new Map<string, number>();
|
|
43
|
+
for (const line of newLines) {
|
|
44
|
+
newSet.set(line, (newSet.get(line) ?? 0) + 1);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
let deletions = 0;
|
|
48
|
+
for (const [line, count] of oldSet) {
|
|
49
|
+
const newCount = newSet.get(line) ?? 0;
|
|
50
|
+
if (count > newCount) {
|
|
51
|
+
deletions += count - newCount;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
let additions = 0;
|
|
56
|
+
for (const [line, count] of newSet) {
|
|
57
|
+
const oldCount = oldSet.get(line) ?? 0;
|
|
58
|
+
if (count > oldCount) {
|
|
59
|
+
additions += count - oldCount;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return { additions, deletions };
|
|
64
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { toNewLines } from "./edit-text-normalization";
|
|
2
|
+
import type { HashlineEdit } from "./types";
|
|
3
|
+
|
|
4
|
+
function normalizeEditPayload(payload: string | string[]): string {
|
|
5
|
+
return toNewLines(payload).join("\n");
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
function buildDedupeKey(edit: HashlineEdit): string {
|
|
9
|
+
switch (edit.op) {
|
|
10
|
+
case "replace":
|
|
11
|
+
return `replace|${edit.pos}|${edit.end ?? ""}|${normalizeEditPayload(edit.lines)}`;
|
|
12
|
+
case "append":
|
|
13
|
+
return `append|${edit.pos ?? ""}|${normalizeEditPayload(edit.lines)}`;
|
|
14
|
+
case "prepend":
|
|
15
|
+
return `prepend|${edit.pos ?? ""}|${normalizeEditPayload(edit.lines)}`;
|
|
16
|
+
default:
|
|
17
|
+
return JSON.stringify(edit);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function dedupeEdits(edits: HashlineEdit[]): {
|
|
22
|
+
edits: HashlineEdit[];
|
|
23
|
+
deduplicatedEdits: number;
|
|
24
|
+
} {
|
|
25
|
+
const seen = new Set<string>();
|
|
26
|
+
const deduped: HashlineEdit[] = [];
|
|
27
|
+
let deduplicatedEdits = 0;
|
|
28
|
+
|
|
29
|
+
for (const edit of edits) {
|
|
30
|
+
const key = buildDedupeKey(edit);
|
|
31
|
+
if (seen.has(key)) {
|
|
32
|
+
deduplicatedEdits += 1;
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
seen.add(key);
|
|
36
|
+
deduped.push(edit);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return { edits: deduped, deduplicatedEdits };
|
|
40
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { autocorrectReplacementLines } from "./autocorrect-replacement-lines";
|
|
2
|
+
import {
|
|
3
|
+
restoreLeadingIndent,
|
|
4
|
+
stripInsertAnchorEcho,
|
|
5
|
+
stripInsertBeforeEcho,
|
|
6
|
+
stripRangeBoundaryEcho,
|
|
7
|
+
toNewLines,
|
|
8
|
+
} from "./edit-text-normalization";
|
|
9
|
+
import { parseLineRef, validateLineRef } from "./validation";
|
|
10
|
+
|
|
11
|
+
interface EditApplyOptions {
|
|
12
|
+
skipValidation?: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function shouldValidate(options?: EditApplyOptions): boolean {
|
|
16
|
+
return options?.skipValidation !== true;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function applySetLine(
|
|
20
|
+
lines: string[],
|
|
21
|
+
anchor: string,
|
|
22
|
+
newText: string | string[],
|
|
23
|
+
options?: EditApplyOptions
|
|
24
|
+
): string[] {
|
|
25
|
+
if (shouldValidate(options)) {
|
|
26
|
+
validateLineRef(lines, anchor);
|
|
27
|
+
}
|
|
28
|
+
const { line } = parseLineRef(anchor);
|
|
29
|
+
const result = [...lines];
|
|
30
|
+
const originalLine = lines[line - 1] ?? "";
|
|
31
|
+
const corrected = autocorrectReplacementLines(
|
|
32
|
+
[originalLine],
|
|
33
|
+
toNewLines(newText)
|
|
34
|
+
);
|
|
35
|
+
const replacement = corrected.map((entry, idx) => {
|
|
36
|
+
if (idx !== 0) {
|
|
37
|
+
return entry;
|
|
38
|
+
}
|
|
39
|
+
return restoreLeadingIndent(originalLine, entry);
|
|
40
|
+
});
|
|
41
|
+
result.splice(line - 1, 1, ...replacement);
|
|
42
|
+
return result;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function applyReplaceLines(
|
|
46
|
+
lines: string[],
|
|
47
|
+
startAnchor: string,
|
|
48
|
+
endAnchor: string,
|
|
49
|
+
newText: string | string[],
|
|
50
|
+
options?: EditApplyOptions
|
|
51
|
+
): string[] {
|
|
52
|
+
if (shouldValidate(options)) {
|
|
53
|
+
validateLineRef(lines, startAnchor);
|
|
54
|
+
validateLineRef(lines, endAnchor);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const { line: startLine } = parseLineRef(startAnchor);
|
|
58
|
+
const { line: endLine } = parseLineRef(endAnchor);
|
|
59
|
+
|
|
60
|
+
if (startLine > endLine) {
|
|
61
|
+
throw new Error(
|
|
62
|
+
`Invalid range: start line ${startLine} cannot be greater than end line ${endLine}`
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const result = [...lines];
|
|
67
|
+
const originalRange = lines.slice(startLine - 1, endLine);
|
|
68
|
+
const stripped = stripRangeBoundaryEcho(
|
|
69
|
+
lines,
|
|
70
|
+
startLine,
|
|
71
|
+
endLine,
|
|
72
|
+
toNewLines(newText)
|
|
73
|
+
);
|
|
74
|
+
const corrected = autocorrectReplacementLines(originalRange, stripped);
|
|
75
|
+
const restored = corrected.map((entry, idx) => {
|
|
76
|
+
if (idx !== 0) {
|
|
77
|
+
return entry;
|
|
78
|
+
}
|
|
79
|
+
return restoreLeadingIndent(lines[startLine - 1] ?? "", entry);
|
|
80
|
+
});
|
|
81
|
+
result.splice(startLine - 1, endLine - startLine + 1, ...restored);
|
|
82
|
+
return result;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function applyInsertAfter(
|
|
86
|
+
lines: string[],
|
|
87
|
+
anchor: string,
|
|
88
|
+
text: string | string[],
|
|
89
|
+
options?: EditApplyOptions
|
|
90
|
+
): string[] {
|
|
91
|
+
if (shouldValidate(options)) {
|
|
92
|
+
validateLineRef(lines, anchor);
|
|
93
|
+
}
|
|
94
|
+
const { line } = parseLineRef(anchor);
|
|
95
|
+
const result = [...lines];
|
|
96
|
+
const newLines = stripInsertAnchorEcho(lines[line - 1], toNewLines(text));
|
|
97
|
+
if (newLines.length === 0) {
|
|
98
|
+
throw new Error(`append (anchored) requires non-empty text for ${anchor}`);
|
|
99
|
+
}
|
|
100
|
+
result.splice(line, 0, ...newLines);
|
|
101
|
+
return result;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export function applyInsertBefore(
|
|
105
|
+
lines: string[],
|
|
106
|
+
anchor: string,
|
|
107
|
+
text: string | string[],
|
|
108
|
+
options?: EditApplyOptions
|
|
109
|
+
): string[] {
|
|
110
|
+
if (shouldValidate(options)) {
|
|
111
|
+
validateLineRef(lines, anchor);
|
|
112
|
+
}
|
|
113
|
+
const { line } = parseLineRef(anchor);
|
|
114
|
+
const result = [...lines];
|
|
115
|
+
const newLines = stripInsertBeforeEcho(lines[line - 1], toNewLines(text));
|
|
116
|
+
if (newLines.length === 0) {
|
|
117
|
+
throw new Error(`prepend (anchored) requires non-empty text for ${anchor}`);
|
|
118
|
+
}
|
|
119
|
+
result.splice(line - 1, 0, ...newLines);
|
|
120
|
+
return result;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export function applyAppend(
|
|
124
|
+
lines: string[],
|
|
125
|
+
text: string | string[]
|
|
126
|
+
): string[] {
|
|
127
|
+
const normalized = toNewLines(text);
|
|
128
|
+
if (normalized.length === 0) {
|
|
129
|
+
throw new Error("append requires non-empty text");
|
|
130
|
+
}
|
|
131
|
+
if (lines.length === 1 && lines[0] === "") {
|
|
132
|
+
return [...normalized];
|
|
133
|
+
}
|
|
134
|
+
return [...lines, ...normalized];
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export function applyPrepend(
|
|
138
|
+
lines: string[],
|
|
139
|
+
text: string | string[]
|
|
140
|
+
): string[] {
|
|
141
|
+
const normalized = toNewLines(text);
|
|
142
|
+
if (normalized.length === 0) {
|
|
143
|
+
throw new Error("prepend requires non-empty text");
|
|
144
|
+
}
|
|
145
|
+
if (lines.length === 1 && lines[0] === "") {
|
|
146
|
+
return [...normalized];
|
|
147
|
+
}
|
|
148
|
+
return [...normalized, ...lines];
|
|
149
|
+
}
|