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,154 @@
|
|
|
1
|
+
import { describe, expect, it } from "bun:test";
|
|
2
|
+
import {
|
|
3
|
+
applyHashlineEdits,
|
|
4
|
+
applyHashlineEditsWithReport,
|
|
5
|
+
computeLineHash,
|
|
6
|
+
HashlineMismatchError,
|
|
7
|
+
} from ".";
|
|
8
|
+
|
|
9
|
+
const OVERLAPPING_REGEX = /[Oo]verlapping/;
|
|
10
|
+
|
|
11
|
+
describe("hashline - edit operations", () => {
|
|
12
|
+
it("replaces anchored line", () => {
|
|
13
|
+
const content = "alpha\nbravo\ncharlie";
|
|
14
|
+
const bravoHash = computeLineHash(2, "bravo");
|
|
15
|
+
const result = applyHashlineEdits(content, [
|
|
16
|
+
{ op: "replace", pos: `2#${bravoHash}`, lines: ["BRAVO"] },
|
|
17
|
+
]);
|
|
18
|
+
expect(result).toBe("alpha\nBRAVO\ncharlie");
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("inserts with append and prepend", () => {
|
|
22
|
+
const content = "a\nb";
|
|
23
|
+
const bHash = computeLineHash(2, "b");
|
|
24
|
+
const result = applyHashlineEdits(content, [
|
|
25
|
+
{ op: "prepend", pos: `2#${bHash}`, lines: ["before-b"] },
|
|
26
|
+
{ op: "append", pos: `2#${bHash}`, lines: ["after-b"] },
|
|
27
|
+
]);
|
|
28
|
+
expect(result).toBe("a\nbefore-b\nb\nafter-b");
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("appends at EOF", () => {
|
|
32
|
+
const content = "a\nb";
|
|
33
|
+
const result = applyHashlineEdits(content, [
|
|
34
|
+
{ op: "append", lines: ["c"] },
|
|
35
|
+
]);
|
|
36
|
+
expect(result).toBe("a\nb\nc");
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("preserves append order for same anchor", () => {
|
|
40
|
+
const content = "a\nb";
|
|
41
|
+
const bHash = computeLineHash(2, "b");
|
|
42
|
+
const result = applyHashlineEdits(content, [
|
|
43
|
+
{ op: "append", pos: `2#${bHash}`, lines: ["first"] },
|
|
44
|
+
{ op: "append", pos: `2#${bHash}`, lines: ["second"] },
|
|
45
|
+
]);
|
|
46
|
+
expect(result).toBe("a\nb\nsecond\nfirst");
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("dedupes semantically identical edits", () => {
|
|
50
|
+
const content = "a\nb";
|
|
51
|
+
const bHash = computeLineHash(2, "b");
|
|
52
|
+
const report = applyHashlineEditsWithReport(content, [
|
|
53
|
+
{ op: "append", pos: `2#${bHash}`, lines: ["dup"] },
|
|
54
|
+
{ op: "append", pos: `2#${bHash}`, lines: ["dup"] },
|
|
55
|
+
]);
|
|
56
|
+
expect(report.content).toBe("a\nb\ndup");
|
|
57
|
+
expect(report.deduplicatedEdits).toBe(1);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("preserves prepend order for same anchor", () => {
|
|
61
|
+
const content = "a\nb";
|
|
62
|
+
const bHash = computeLineHash(2, "b");
|
|
63
|
+
const result = applyHashlineEdits(content, [
|
|
64
|
+
{ op: "prepend", pos: `2#${bHash}`, lines: ["first"] },
|
|
65
|
+
{ op: "prepend", pos: `2#${bHash}`, lines: ["second"] },
|
|
66
|
+
]);
|
|
67
|
+
expect(result).toBe("a\nsecond\nfirst\nb");
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("throws mismatch error for stale anchors", () => {
|
|
71
|
+
const content = "one\ntwo\nthree";
|
|
72
|
+
const staleHash = computeLineHash(2, "TWO");
|
|
73
|
+
expect(() =>
|
|
74
|
+
applyHashlineEdits(content, [
|
|
75
|
+
{ op: "replace", pos: `2#${staleHash}`, lines: ["two-updated"] },
|
|
76
|
+
])
|
|
77
|
+
).toThrow(HashlineMismatchError);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it("collects remaps for stale anchors", () => {
|
|
81
|
+
const content = "one\ntwo\nthree";
|
|
82
|
+
const staleHash = computeLineHash(2, "TWO");
|
|
83
|
+
try {
|
|
84
|
+
applyHashlineEdits(content, [
|
|
85
|
+
{ op: "replace", pos: `2#${staleHash}`, lines: ["two-updated"] },
|
|
86
|
+
]);
|
|
87
|
+
throw new Error("Expected HashlineMismatchError to be thrown");
|
|
88
|
+
} catch (error) {
|
|
89
|
+
expect(error).toBeInstanceOf(HashlineMismatchError);
|
|
90
|
+
const mismatchError = error as HashlineMismatchError;
|
|
91
|
+
const expectedKey = `2#${staleHash}`;
|
|
92
|
+
const actualValue = mismatchError.remaps.get(expectedKey);
|
|
93
|
+
expect(actualValue).toBe(`2#${computeLineHash(2, "two")}`);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it("formats mismatch context lines with pipe delimiter", () => {
|
|
98
|
+
const content = "one\ntwo\nthree";
|
|
99
|
+
const staleHash = computeLineHash(2, "TWO");
|
|
100
|
+
try {
|
|
101
|
+
applyHashlineEdits(content, [
|
|
102
|
+
{ op: "replace", pos: `2#${staleHash}`, lines: ["two-updated"] },
|
|
103
|
+
]);
|
|
104
|
+
throw new Error("Expected HashlineMismatchError to be thrown");
|
|
105
|
+
} catch (error) {
|
|
106
|
+
expect(error).toBeInstanceOf(HashlineMismatchError);
|
|
107
|
+
const message = (error as Error).message;
|
|
108
|
+
expect(message).toContain(`>>> 2#${computeLineHash(2, "two")}|two`);
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it("silently deletes lines via replace with empty content", () => {
|
|
113
|
+
const content = "hello\nworld";
|
|
114
|
+
const helloHash = computeLineHash(1, "hello");
|
|
115
|
+
const result = applyHashlineEdits(content, [
|
|
116
|
+
{ op: "replace", pos: `1#${helloHash}`, lines: [] },
|
|
117
|
+
]);
|
|
118
|
+
expect(result).toBe("world");
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it("reports noop edits", () => {
|
|
122
|
+
const content = "hello\nworld";
|
|
123
|
+
const helloHash = computeLineHash(1, "hello");
|
|
124
|
+
const report = applyHashlineEditsWithReport(content, [
|
|
125
|
+
{ op: "replace", pos: `1#${helloHash}`, lines: ["hello"] },
|
|
126
|
+
]);
|
|
127
|
+
expect(report.noopEdits).toBe(1);
|
|
128
|
+
expect(report.content).toBe(content);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it("detects overlapping range edits", () => {
|
|
132
|
+
const content = "a\nb\nc\nd\ne";
|
|
133
|
+
const aH = computeLineHash(1, "a");
|
|
134
|
+
const cH = computeLineHash(3, "c");
|
|
135
|
+
const bH = computeLineHash(2, "b");
|
|
136
|
+
const dH = computeLineHash(4, "d");
|
|
137
|
+
expect(() =>
|
|
138
|
+
applyHashlineEdits(content, [
|
|
139
|
+
{
|
|
140
|
+
op: "replace",
|
|
141
|
+
pos: `1#${aH}`,
|
|
142
|
+
end: `3#${cH}`,
|
|
143
|
+
lines: ["x", "y", "z"],
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
op: "replace",
|
|
147
|
+
pos: `2#${bH}`,
|
|
148
|
+
end: `4#${dH}`,
|
|
149
|
+
lines: ["x", "y", "z"],
|
|
150
|
+
},
|
|
151
|
+
])
|
|
152
|
+
).toThrow(OVERLAPPING_REGEX);
|
|
153
|
+
});
|
|
154
|
+
});
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { dedupeEdits } from "./edit-deduplication";
|
|
2
|
+
import {
|
|
3
|
+
applyAppend,
|
|
4
|
+
applyInsertAfter,
|
|
5
|
+
applyInsertBefore,
|
|
6
|
+
applyPrepend,
|
|
7
|
+
applyReplaceLines,
|
|
8
|
+
applySetLine,
|
|
9
|
+
} from "./edit-operation-primitives";
|
|
10
|
+
import {
|
|
11
|
+
collectLineRefs,
|
|
12
|
+
detectOverlappingRanges,
|
|
13
|
+
getEditLineNumber,
|
|
14
|
+
} from "./edit-ordering";
|
|
15
|
+
import type { HashlineEdit } from "./types";
|
|
16
|
+
import { validateLineRefs } from "./validation";
|
|
17
|
+
|
|
18
|
+
/** Compare two string arrays element-by-element. O(n) with early exit. */
|
|
19
|
+
function arraysEqual(a: string[], b: string[]): boolean {
|
|
20
|
+
if (a.length !== b.length) return false;
|
|
21
|
+
for (let i = 0; i < a.length; i++) {
|
|
22
|
+
if (a[i] !== b[i]) return false;
|
|
23
|
+
}
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface HashlineApplyReport {
|
|
28
|
+
content: string;
|
|
29
|
+
deduplicatedEdits: number;
|
|
30
|
+
noopEdits: number;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: core edit application logic
|
|
34
|
+
export function applyHashlineEditsWithReport(
|
|
35
|
+
content: string,
|
|
36
|
+
edits: HashlineEdit[]
|
|
37
|
+
): HashlineApplyReport {
|
|
38
|
+
if (edits.length === 0) {
|
|
39
|
+
return {
|
|
40
|
+
content,
|
|
41
|
+
noopEdits: 0,
|
|
42
|
+
deduplicatedEdits: 0,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const dedupeResult = dedupeEdits(edits);
|
|
47
|
+
const EDIT_PRECEDENCE: Record<string, number> = {
|
|
48
|
+
replace: 0,
|
|
49
|
+
append: 1,
|
|
50
|
+
prepend: 2,
|
|
51
|
+
};
|
|
52
|
+
const sortedEdits = [...dedupeResult.edits].sort((a, b) => {
|
|
53
|
+
const lineA = getEditLineNumber(a);
|
|
54
|
+
const lineB = getEditLineNumber(b);
|
|
55
|
+
if (lineB !== lineA) {
|
|
56
|
+
return lineB - lineA;
|
|
57
|
+
}
|
|
58
|
+
return (EDIT_PRECEDENCE[a.op] ?? 3) - (EDIT_PRECEDENCE[b.op] ?? 3);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
let noopEdits = 0;
|
|
62
|
+
|
|
63
|
+
let lines = content.length === 0 ? [] : content.split("\n");
|
|
64
|
+
|
|
65
|
+
const refs = collectLineRefs(sortedEdits);
|
|
66
|
+
validateLineRefs(lines, refs);
|
|
67
|
+
|
|
68
|
+
const overlapError = detectOverlappingRanges(dedupeResult.edits);
|
|
69
|
+
if (overlapError) {
|
|
70
|
+
throw new Error(overlapError);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
for (const edit of sortedEdits) {
|
|
74
|
+
switch (edit.op) {
|
|
75
|
+
case "replace": {
|
|
76
|
+
const next = edit.end
|
|
77
|
+
? applyReplaceLines(lines, edit.pos, edit.end, edit.lines, {
|
|
78
|
+
skipValidation: true,
|
|
79
|
+
})
|
|
80
|
+
: applySetLine(lines, edit.pos, edit.lines, { skipValidation: true });
|
|
81
|
+
if (arraysEqual(next, lines)) {
|
|
82
|
+
noopEdits += 1;
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
lines = next;
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
case "append": {
|
|
89
|
+
const next = edit.pos
|
|
90
|
+
? applyInsertAfter(lines, edit.pos, edit.lines, {
|
|
91
|
+
skipValidation: true,
|
|
92
|
+
})
|
|
93
|
+
: applyAppend(lines, edit.lines);
|
|
94
|
+
if (arraysEqual(next, lines)) {
|
|
95
|
+
noopEdits += 1;
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
lines = next;
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
case "prepend": {
|
|
102
|
+
const next = edit.pos
|
|
103
|
+
? applyInsertBefore(lines, edit.pos, edit.lines, {
|
|
104
|
+
skipValidation: true,
|
|
105
|
+
})
|
|
106
|
+
: applyPrepend(lines, edit.lines);
|
|
107
|
+
if (arraysEqual(next, lines)) {
|
|
108
|
+
noopEdits += 1;
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
lines = next;
|
|
112
|
+
break;
|
|
113
|
+
}
|
|
114
|
+
default: {
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return {
|
|
121
|
+
content: lines.join("\n"),
|
|
122
|
+
noopEdits,
|
|
123
|
+
deduplicatedEdits: dedupeResult.deduplicatedEdits,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export function applyHashlineEdits(
|
|
128
|
+
content: string,
|
|
129
|
+
edits: HashlineEdit[]
|
|
130
|
+
): string {
|
|
131
|
+
return applyHashlineEditsWithReport(content, edits).content;
|
|
132
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { HashlineEdit } from "./types";
|
|
2
|
+
import { parseLineRef } from "./validation";
|
|
3
|
+
|
|
4
|
+
export function getEditLineNumber(edit: HashlineEdit): number {
|
|
5
|
+
switch (edit.op) {
|
|
6
|
+
case "replace":
|
|
7
|
+
return parseLineRef(edit.end ?? edit.pos).line;
|
|
8
|
+
case "append":
|
|
9
|
+
return edit.pos ? parseLineRef(edit.pos).line : Number.POSITIVE_INFINITY;
|
|
10
|
+
case "prepend":
|
|
11
|
+
return edit.pos ? parseLineRef(edit.pos).line : Number.NEGATIVE_INFINITY;
|
|
12
|
+
default:
|
|
13
|
+
return Number.POSITIVE_INFINITY;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function collectLineRefs(edits: HashlineEdit[]): string[] {
|
|
18
|
+
return edits.flatMap((edit) => {
|
|
19
|
+
switch (edit.op) {
|
|
20
|
+
case "replace":
|
|
21
|
+
return edit.end ? [edit.pos, edit.end] : [edit.pos];
|
|
22
|
+
case "append":
|
|
23
|
+
case "prepend":
|
|
24
|
+
return edit.pos ? [edit.pos] : [];
|
|
25
|
+
default:
|
|
26
|
+
return [];
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function detectOverlappingRanges(edits: HashlineEdit[]): string | null {
|
|
32
|
+
const ranges: { start: number; end: number; idx: number }[] = [];
|
|
33
|
+
for (let i = 0; i < edits.length; i++) {
|
|
34
|
+
const edit = edits[i];
|
|
35
|
+
if (edit.op !== "replace" || !edit.end) {
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
const start = parseLineRef(edit.pos).line;
|
|
39
|
+
const end = parseLineRef(edit.end).line;
|
|
40
|
+
ranges.push({ start, end, idx: i });
|
|
41
|
+
}
|
|
42
|
+
if (ranges.length < 2) {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
ranges.sort((a, b) => a.start - b.start || a.end - b.end);
|
|
47
|
+
for (let i = 1; i < ranges.length; i++) {
|
|
48
|
+
const prev = ranges[i - 1];
|
|
49
|
+
const curr = ranges[i];
|
|
50
|
+
if (curr.start <= prev.end) {
|
|
51
|
+
return (
|
|
52
|
+
"Overlapping range edits detected: " +
|
|
53
|
+
`edit ${prev.idx + 1} (lines ${prev.start}-${prev.end}) overlaps with ` +
|
|
54
|
+
`edit ${curr.idx + 1} (lines ${curr.start}-${curr.end}). ` +
|
|
55
|
+
"Use pos-only replace for single-line edits."
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
const HASHLINE_PREFIX_RE =
|
|
2
|
+
/^\s*(?:>>>|>>)?\s*\d+\s*#\s*[ZPMQVRWSNKTXJBYH]{2}\|/;
|
|
3
|
+
const DIFF_PLUS_RE = /^[+](?![+])/;
|
|
4
|
+
const LEADING_WHITESPACE_REGEX = /^\s*/;
|
|
5
|
+
|
|
6
|
+
function equalsIgnoringWhitespace(a: string, b: string): boolean {
|
|
7
|
+
if (a === b) {
|
|
8
|
+
return true;
|
|
9
|
+
}
|
|
10
|
+
return a.replace(/\s+/g, "") === b.replace(/\s+/g, "");
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function leadingWhitespace(text: string): string {
|
|
14
|
+
if (!text) {
|
|
15
|
+
return "";
|
|
16
|
+
}
|
|
17
|
+
const match = text.match(LEADING_WHITESPACE_REGEX);
|
|
18
|
+
return match ? match[0] : "";
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function stripLinePrefixes(lines: string[]): string[] {
|
|
22
|
+
let hashPrefixCount = 0;
|
|
23
|
+
let diffPlusCount = 0;
|
|
24
|
+
let nonEmpty = 0;
|
|
25
|
+
|
|
26
|
+
for (const line of lines) {
|
|
27
|
+
if (line.length === 0) {
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
nonEmpty += 1;
|
|
31
|
+
if (HASHLINE_PREFIX_RE.test(line)) {
|
|
32
|
+
hashPrefixCount += 1;
|
|
33
|
+
}
|
|
34
|
+
if (DIFF_PLUS_RE.test(line)) {
|
|
35
|
+
diffPlusCount += 1;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (nonEmpty === 0) {
|
|
40
|
+
return lines;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const stripHash = hashPrefixCount > 0 && hashPrefixCount >= nonEmpty * 0.5;
|
|
44
|
+
const stripPlus =
|
|
45
|
+
!stripHash && diffPlusCount > 0 && diffPlusCount >= nonEmpty * 0.5;
|
|
46
|
+
|
|
47
|
+
if (!(stripHash || stripPlus)) {
|
|
48
|
+
return lines;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return lines.map((line) => {
|
|
52
|
+
if (stripHash) {
|
|
53
|
+
return line.replace(HASHLINE_PREFIX_RE, "");
|
|
54
|
+
}
|
|
55
|
+
if (stripPlus) {
|
|
56
|
+
return line.replace(DIFF_PLUS_RE, "");
|
|
57
|
+
}
|
|
58
|
+
return line;
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function toNewLines(input: string | string[]): string[] {
|
|
63
|
+
if (Array.isArray(input)) {
|
|
64
|
+
return stripLinePrefixes(input);
|
|
65
|
+
}
|
|
66
|
+
return stripLinePrefixes(input.split("\n"));
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function restoreLeadingIndent(
|
|
70
|
+
templateLine: string,
|
|
71
|
+
line: string
|
|
72
|
+
): string {
|
|
73
|
+
if (line.length === 0) {
|
|
74
|
+
return line;
|
|
75
|
+
}
|
|
76
|
+
const templateIndent = leadingWhitespace(templateLine);
|
|
77
|
+
if (templateIndent.length === 0) {
|
|
78
|
+
return line;
|
|
79
|
+
}
|
|
80
|
+
if (leadingWhitespace(line).length > 0) {
|
|
81
|
+
return line;
|
|
82
|
+
}
|
|
83
|
+
if (templateLine.trim() === line.trim()) {
|
|
84
|
+
return line;
|
|
85
|
+
}
|
|
86
|
+
return `${templateIndent}${line}`;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export function stripInsertAnchorEcho(
|
|
90
|
+
anchorLine: string,
|
|
91
|
+
newLines: string[]
|
|
92
|
+
): string[] {
|
|
93
|
+
if (newLines.length === 0) {
|
|
94
|
+
return newLines;
|
|
95
|
+
}
|
|
96
|
+
if (equalsIgnoringWhitespace(newLines[0], anchorLine)) {
|
|
97
|
+
return newLines.slice(1);
|
|
98
|
+
}
|
|
99
|
+
return newLines;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export function stripInsertBeforeEcho(
|
|
103
|
+
anchorLine: string,
|
|
104
|
+
newLines: string[]
|
|
105
|
+
): string[] {
|
|
106
|
+
if (newLines.length <= 1) {
|
|
107
|
+
return newLines;
|
|
108
|
+
}
|
|
109
|
+
const lastLine = newLines.at(-1);
|
|
110
|
+
if (
|
|
111
|
+
lastLine !== undefined &&
|
|
112
|
+
equalsIgnoringWhitespace(lastLine, anchorLine)
|
|
113
|
+
) {
|
|
114
|
+
return newLines.slice(0, -1);
|
|
115
|
+
}
|
|
116
|
+
return newLines;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export function stripInsertBoundaryEcho(
|
|
120
|
+
afterLine: string,
|
|
121
|
+
beforeLine: string,
|
|
122
|
+
newLines: string[]
|
|
123
|
+
): string[] {
|
|
124
|
+
let out = newLines;
|
|
125
|
+
if (out.length > 0 && equalsIgnoringWhitespace(out[0], afterLine)) {
|
|
126
|
+
out = out.slice(1);
|
|
127
|
+
}
|
|
128
|
+
const lastLine = out.at(-1);
|
|
129
|
+
if (
|
|
130
|
+
out.length > 0 &&
|
|
131
|
+
lastLine !== undefined &&
|
|
132
|
+
equalsIgnoringWhitespace(lastLine, beforeLine)
|
|
133
|
+
) {
|
|
134
|
+
out = out.slice(0, -1);
|
|
135
|
+
}
|
|
136
|
+
return out;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export function stripRangeBoundaryEcho(
|
|
140
|
+
lines: string[],
|
|
141
|
+
startLine: number,
|
|
142
|
+
endLine: number,
|
|
143
|
+
newLines: string[]
|
|
144
|
+
): string[] {
|
|
145
|
+
const replacedCount = endLine - startLine + 1;
|
|
146
|
+
if (newLines.length <= 1 || newLines.length <= replacedCount) {
|
|
147
|
+
return newLines;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
let out = newLines;
|
|
151
|
+
const beforeIdx = startLine - 2;
|
|
152
|
+
if (beforeIdx >= 0 && equalsIgnoringWhitespace(out[0], lines[beforeIdx])) {
|
|
153
|
+
out = out.slice(1);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const afterIdx = endLine;
|
|
157
|
+
const lastLine = out.at(-1);
|
|
158
|
+
if (
|
|
159
|
+
afterIdx < lines.length &&
|
|
160
|
+
out.length > 0 &&
|
|
161
|
+
lastLine !== undefined &&
|
|
162
|
+
equalsIgnoringWhitespace(lastLine, lines[afterIdx])
|
|
163
|
+
) {
|
|
164
|
+
out = out.slice(0, -1);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
return out;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export function parseHashlineText(
|
|
171
|
+
input: string[] | string | null | undefined
|
|
172
|
+
): string[] {
|
|
173
|
+
if (input === null || input === undefined) {
|
|
174
|
+
return [];
|
|
175
|
+
}
|
|
176
|
+
if (Array.isArray(input)) {
|
|
177
|
+
return stripLinePrefixes(input);
|
|
178
|
+
}
|
|
179
|
+
return toNewLines(input);
|
|
180
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
export interface FileTextEnvelope {
|
|
2
|
+
content: string;
|
|
3
|
+
hadBom: boolean;
|
|
4
|
+
lineEnding: "\n" | "\r\n";
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
function detectLineEnding(content: string): "\n" | "\r\n" {
|
|
8
|
+
const crlfIndex = content.indexOf("\r\n");
|
|
9
|
+
const lfIndex = content.indexOf("\n");
|
|
10
|
+
if (lfIndex === -1) {
|
|
11
|
+
return "\n";
|
|
12
|
+
}
|
|
13
|
+
if (crlfIndex === -1) {
|
|
14
|
+
return "\n";
|
|
15
|
+
}
|
|
16
|
+
return crlfIndex < lfIndex ? "\r\n" : "\n";
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function stripBom(content: string): { content: string; hadBom: boolean } {
|
|
20
|
+
if (!content.startsWith("\uFEFF")) {
|
|
21
|
+
return { content, hadBom: false };
|
|
22
|
+
}
|
|
23
|
+
return { content: content.slice(1), hadBom: true };
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function normalizeToLf(content: string): string {
|
|
27
|
+
return content.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function restoreLineEndings(
|
|
31
|
+
content: string,
|
|
32
|
+
lineEnding: "\n" | "\r\n"
|
|
33
|
+
): string {
|
|
34
|
+
if (lineEnding === "\n") {
|
|
35
|
+
return content;
|
|
36
|
+
}
|
|
37
|
+
return content.replace(/\n/g, "\r\n");
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function canonicalizeFileText(content: string): FileTextEnvelope {
|
|
41
|
+
const stripped = stripBom(content);
|
|
42
|
+
return {
|
|
43
|
+
content: normalizeToLf(stripped.content),
|
|
44
|
+
hadBom: stripped.hadBom,
|
|
45
|
+
lineEnding: detectLineEnding(stripped.content),
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function restoreFileText(
|
|
50
|
+
content: string,
|
|
51
|
+
envelope: FileTextEnvelope
|
|
52
|
+
): string {
|
|
53
|
+
const withLineEnding = restoreLineEndings(content, envelope.lineEnding);
|
|
54
|
+
if (!envelope.hadBom) {
|
|
55
|
+
return withLineEnding;
|
|
56
|
+
}
|
|
57
|
+
return `\uFEFF${withLineEnding}`;
|
|
58
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { describe, expect, it } from "bun:test";
|
|
2
|
+
import {
|
|
3
|
+
computeFileHash,
|
|
4
|
+
computeLineHash,
|
|
5
|
+
streamHashLinesFromLines,
|
|
6
|
+
streamHashLinesFromUtf8,
|
|
7
|
+
} from ".";
|
|
8
|
+
|
|
9
|
+
const HASH_PATTERN = /^[ZPMQVRWSNKTXJBYH]{2}$/;
|
|
10
|
+
|
|
11
|
+
describe("hashline - hash computation", () => {
|
|
12
|
+
it("computes 2-char line hashes", () => {
|
|
13
|
+
const hash = computeLineHash(1, "hello");
|
|
14
|
+
expect(hash).toMatch(HASH_PATTERN);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it("uses line number for symbol-only lines", () => {
|
|
18
|
+
const a = computeLineHash(1, "***");
|
|
19
|
+
const b = computeLineHash(2, "***");
|
|
20
|
+
expect(a).not.toBe(b);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it("does not use line number for alphanumeric lines", () => {
|
|
24
|
+
const a = computeLineHash(1, "hello");
|
|
25
|
+
const b = computeLineHash(2, "hello");
|
|
26
|
+
expect(a).toBe(b);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("computes deterministic file hash", () => {
|
|
30
|
+
const a = computeFileHash("a\nb\n");
|
|
31
|
+
const b = computeFileHash("a\nb\n");
|
|
32
|
+
const c = computeFileHash("a\nB\n");
|
|
33
|
+
|
|
34
|
+
expect(a).toBe(b);
|
|
35
|
+
expect(a).not.toBe(c);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("streams hashline numbering from lines", async () => {
|
|
39
|
+
const chunks: string[] = [];
|
|
40
|
+
for await (const chunk of streamHashLinesFromLines(["a", "b", "c"], {
|
|
41
|
+
maxChunkLines: 2,
|
|
42
|
+
})) {
|
|
43
|
+
chunks.push(chunk);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const output = chunks.join("\n");
|
|
47
|
+
expect(output).toBe(
|
|
48
|
+
[
|
|
49
|
+
`1#${computeLineHash(1, "a")}|a`,
|
|
50
|
+
`2#${computeLineHash(2, "b")}|b`,
|
|
51
|
+
`3#${computeLineHash(3, "c")}|c`,
|
|
52
|
+
].join("\n")
|
|
53
|
+
);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it("streams hashline numbering from UTF-8 bytes", async () => {
|
|
57
|
+
const stream = new ReadableStream<Uint8Array>({
|
|
58
|
+
start(controller) {
|
|
59
|
+
controller.enqueue(new TextEncoder().encode("a\nb\n"));
|
|
60
|
+
controller.enqueue(new TextEncoder().encode("c\n"));
|
|
61
|
+
controller.close();
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
const chunks: string[] = [];
|
|
66
|
+
for await (const chunk of streamHashLinesFromUtf8(stream, {
|
|
67
|
+
maxChunkLines: 2,
|
|
68
|
+
})) {
|
|
69
|
+
chunks.push(chunk);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const output = chunks.join("\n");
|
|
73
|
+
expect(output).toBe(
|
|
74
|
+
[
|
|
75
|
+
`1#${computeLineHash(1, "a")}|a`,
|
|
76
|
+
`2#${computeLineHash(2, "b")}|b`,
|
|
77
|
+
`3#${computeLineHash(3, "c")}|c`,
|
|
78
|
+
`4#${computeLineHash(4, "")}|`,
|
|
79
|
+
].join("\n")
|
|
80
|
+
);
|
|
81
|
+
});
|
|
82
|
+
});
|