lonny-agent 0.2.4 → 0.2.7
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/.github/workflows/ci.yml +21 -0
- package/AGENTS.md +106 -0
- package/CHANGELOG.md +24 -0
- package/README.md +326 -326
- package/dist/agent/__tests__/session-restore.test.d.ts +2 -0
- package/dist/agent/__tests__/session-restore.test.d.ts.map +1 -0
- package/dist/agent/__tests__/session-restore.test.js +260 -0
- package/dist/agent/__tests__/session-restore.test.js.map +1 -0
- package/dist/agent/commands.d.ts +26 -0
- package/dist/agent/commands.d.ts.map +1 -0
- package/dist/agent/commands.js +253 -0
- package/dist/agent/commands.js.map +1 -0
- package/dist/agent/compaction.js +8 -1
- package/dist/agent/compaction.js.map +1 -1
- package/dist/agent/index.d.ts +2 -1
- package/dist/agent/index.d.ts.map +1 -1
- package/dist/agent/index.js +2 -2
- package/dist/agent/index.js.map +1 -1
- package/dist/agent/llm.d.ts +4 -0
- package/dist/agent/llm.d.ts.map +1 -1
- package/dist/agent/memory.d.ts +12 -0
- package/dist/agent/memory.d.ts.map +1 -0
- package/dist/agent/memory.js +51 -0
- package/dist/agent/memory.js.map +1 -0
- package/dist/agent/prompt-builder.d.ts +6 -1
- package/dist/agent/prompt-builder.d.ts.map +1 -1
- package/dist/agent/prompt-builder.js +100 -33
- package/dist/agent/prompt-builder.js.map +1 -1
- package/dist/agent/providers/google.d.ts.map +1 -1
- package/dist/agent/providers/google.js.map +1 -1
- package/dist/agent/providers/openai.d.ts +1 -0
- package/dist/agent/providers/openai.d.ts.map +1 -1
- package/dist/agent/providers/openai.js +59 -6
- package/dist/agent/providers/openai.js.map +1 -1
- package/dist/agent/session-chat.d.ts +3 -0
- package/dist/agent/session-chat.d.ts.map +1 -0
- package/dist/agent/session-chat.js +384 -0
- package/dist/agent/session-chat.js.map +1 -0
- package/dist/agent/session-display.d.ts +29 -0
- package/dist/agent/session-display.d.ts.map +1 -0
- package/dist/agent/session-display.js +179 -0
- package/dist/agent/session-display.js.map +1 -0
- package/dist/agent/session-persistence.d.ts +55 -0
- package/dist/agent/session-persistence.d.ts.map +1 -0
- package/dist/agent/session-persistence.js +101 -0
- package/dist/agent/session-persistence.js.map +1 -0
- package/dist/agent/session-utils.d.ts +5 -0
- package/dist/agent/session-utils.d.ts.map +1 -0
- package/dist/agent/session-utils.js +51 -0
- package/dist/agent/session-utils.js.map +1 -0
- package/dist/agent/session.d.ts +19 -17
- package/dist/agent/session.d.ts.map +1 -1
- package/dist/agent/session.js +234 -578
- package/dist/agent/session.js.map +1 -1
- package/dist/cli/index.d.ts +4 -0
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +67 -2
- package/dist/cli/index.js.map +1 -1
- package/dist/config/index.d.ts +2 -2
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/index.js +7 -1
- package/dist/config/index.js.map +1 -1
- package/dist/index.js +24 -3
- package/dist/index.js.map +1 -1
- package/dist/tools/__tests__/bash.test.js +169 -2
- package/dist/tools/__tests__/bash.test.js.map +1 -1
- package/dist/tools/__tests__/edit.test.js +1091 -340
- package/dist/tools/__tests__/edit.test.js.map +1 -1
- package/dist/tools/__tests__/fetch.test.js +1 -1
- package/dist/tools/__tests__/fetch.test.js.map +1 -1
- package/dist/tools/__tests__/glob.test.js +1 -1
- package/dist/tools/__tests__/glob.test.js.map +1 -1
- package/dist/tools/__tests__/grep.test.js +33 -1
- package/dist/tools/__tests__/grep.test.js.map +1 -1
- package/dist/tools/__tests__/ls.test.js +1 -1
- package/dist/tools/__tests__/ls.test.js.map +1 -1
- package/dist/tools/__tests__/read.test.js +1 -1
- package/dist/tools/__tests__/read.test.js.map +1 -1
- package/dist/tools/__tests__/registry.test.js +313 -0
- package/dist/tools/__tests__/registry.test.js.map +1 -1
- package/dist/tools/__tests__/sed.test.d.ts +2 -0
- package/dist/tools/__tests__/sed.test.d.ts.map +1 -0
- package/dist/tools/__tests__/sed.test.js +228 -0
- package/dist/tools/__tests__/sed.test.js.map +1 -0
- package/dist/tools/__tests__/write_plan.test.js +1 -1
- package/dist/tools/__tests__/write_plan.test.js.map +1 -1
- package/dist/tools/bash.d.ts.map +1 -1
- package/dist/tools/bash.js +711 -18
- package/dist/tools/bash.js.map +1 -1
- package/dist/tools/codebase/ast/__tests__/ast-edit-demo.d.ts +2 -0
- package/dist/tools/codebase/ast/__tests__/ast-edit-demo.d.ts.map +1 -0
- package/dist/tools/codebase/ast/__tests__/ast-edit-demo.js +7 -0
- package/dist/tools/codebase/ast/__tests__/ast-edit-demo.js.map +1 -0
- package/dist/tools/codebase/ast/__tests__/ast-edit-final.d.ts +6 -0
- package/dist/tools/codebase/ast/__tests__/ast-edit-final.d.ts.map +1 -0
- package/dist/tools/codebase/ast/__tests__/ast-edit-final.js +11 -0
- package/dist/tools/codebase/ast/__tests__/ast-edit-final.js.map +1 -0
- package/dist/tools/codebase/ast/__tests__/ast-edit-test.d.ts +2 -0
- package/dist/tools/codebase/ast/__tests__/ast-edit-test.d.ts.map +1 -0
- package/dist/tools/codebase/ast/__tests__/ast-edit-test.js +9 -0
- package/dist/tools/codebase/ast/__tests__/ast-edit-test.js.map +1 -0
- package/dist/tools/codebase/ast/__tests__/integration.test.d.ts +2 -0
- package/dist/tools/codebase/ast/__tests__/integration.test.d.ts.map +1 -0
- package/dist/tools/codebase/ast/__tests__/integration.test.js +415 -0
- package/dist/tools/codebase/ast/__tests__/integration.test.js.map +1 -0
- package/dist/tools/codebase/ast/__tests__/tree-sitter.test.d.ts +2 -0
- package/dist/tools/codebase/ast/__tests__/tree-sitter.test.d.ts.map +1 -0
- package/dist/tools/codebase/ast/__tests__/tree-sitter.test.js +414 -0
- package/dist/tools/codebase/ast/__tests__/tree-sitter.test.js.map +1 -0
- package/dist/tools/codebase/ast/adapter.d.ts +23 -0
- package/dist/tools/codebase/ast/adapter.d.ts.map +1 -0
- package/dist/tools/codebase/ast/adapter.js +11 -0
- package/dist/tools/codebase/ast/adapter.js.map +1 -0
- package/dist/tools/codebase/ast/tools.d.ts +3 -0
- package/dist/tools/codebase/ast/tools.d.ts.map +1 -0
- package/dist/tools/codebase/ast/tools.js +286 -0
- package/dist/tools/codebase/ast/tools.js.map +1 -0
- package/dist/tools/codebase/ast/tree-sitter-adapter.d.ts +3 -0
- package/dist/tools/codebase/ast/tree-sitter-adapter.d.ts.map +1 -0
- package/dist/tools/codebase/ast/tree-sitter-adapter.js +412 -0
- package/dist/tools/codebase/ast/tree-sitter-adapter.js.map +1 -0
- package/dist/tools/codebase/ast/tree-sitter-converters.d.ts +4 -0
- package/dist/tools/codebase/ast/tree-sitter-converters.d.ts.map +1 -0
- package/dist/tools/codebase/ast/tree-sitter-converters.js +447 -0
- package/dist/tools/codebase/ast/tree-sitter-converters.js.map +1 -0
- package/dist/tools/codebase/ast/types.d.ts +103 -0
- package/dist/tools/codebase/ast/types.d.ts.map +1 -0
- package/dist/tools/codebase/ast/types.js +2 -0
- package/dist/tools/codebase/ast/types.js.map +1 -0
- package/dist/tools/codebase/ast/wasm/tree-sitter-python.wasm +0 -0
- package/dist/tools/codebase/ast/wasm/tree-sitter-tsx.wasm +0 -0
- package/dist/tools/codebase/ast/wasm/tree-sitter-typescript.wasm +0 -0
- package/dist/tools/codebase/ast/wasm/tree-sitter.wasm +0 -0
- package/dist/tools/codebase/ast/wasm/web-tree-sitter.wasm +0 -0
- package/dist/tools/codebase/find.d.ts +3 -0
- package/dist/tools/codebase/find.d.ts.map +1 -0
- package/dist/tools/codebase/find.js +61 -0
- package/dist/tools/codebase/find.js.map +1 -0
- package/dist/tools/codebase/glob.d.ts +3 -0
- package/dist/tools/codebase/glob.d.ts.map +1 -0
- package/dist/tools/codebase/glob.js +37 -0
- package/dist/tools/codebase/glob.js.map +1 -0
- package/dist/tools/codebase/grep.d.ts +3 -0
- package/dist/tools/codebase/grep.d.ts.map +1 -0
- package/dist/tools/codebase/grep.js +169 -0
- package/dist/tools/codebase/grep.js.map +1 -0
- package/dist/tools/codebase/ls.d.ts +3 -0
- package/dist/tools/codebase/ls.d.ts.map +1 -0
- package/dist/tools/codebase/ls.js +39 -0
- package/dist/tools/codebase/ls.js.map +1 -0
- package/dist/tools/codebase/read.d.ts +10 -0
- package/dist/tools/codebase/read.d.ts.map +1 -0
- package/dist/tools/codebase/read.js +81 -0
- package/dist/tools/codebase/read.js.map +1 -0
- package/dist/tools/delete_memory.d.ts +3 -0
- package/dist/tools/delete_memory.d.ts.map +1 -0
- package/dist/tools/delete_memory.js +46 -0
- package/dist/tools/delete_memory.js.map +1 -0
- package/dist/tools/edit/diff-compute.d.ts +4 -0
- package/dist/tools/edit/diff-compute.d.ts.map +1 -0
- package/dist/tools/edit/diff-compute.js +18 -0
- package/dist/tools/edit/diff-compute.js.map +1 -0
- package/dist/tools/edit/diff-render.d.ts +18 -0
- package/dist/tools/edit/diff-render.d.ts.map +1 -0
- package/dist/tools/edit/diff-render.js +128 -0
- package/dist/tools/edit/diff-render.js.map +1 -0
- package/dist/tools/edit/edit.d.ts +4 -0
- package/dist/tools/edit/edit.d.ts.map +1 -0
- package/dist/tools/edit/edit.js +440 -0
- package/dist/tools/edit/edit.js.map +1 -0
- package/dist/tools/edit/matcher.d.ts +24 -0
- package/dist/tools/edit/matcher.d.ts.map +1 -0
- package/dist/tools/edit/matcher.js +66 -0
- package/dist/tools/edit/matcher.js.map +1 -0
- package/dist/tools/edit/parser.d.ts +10 -0
- package/dist/tools/edit/parser.d.ts.map +1 -0
- package/dist/tools/edit/parser.js +120 -0
- package/dist/tools/edit/parser.js.map +1 -0
- package/dist/tools/edit/types.d.ts +16 -0
- package/dist/tools/edit/types.d.ts.map +1 -0
- package/dist/tools/edit/types.js +2 -0
- package/dist/tools/edit/types.js.map +1 -0
- package/dist/tools/edit/write_plan.d.ts +5 -0
- package/dist/tools/edit/write_plan.d.ts.map +1 -0
- package/dist/tools/edit/write_plan.js +98 -0
- package/dist/tools/edit/write_plan.js.map +1 -0
- package/dist/tools/edit.d.ts +50 -9
- package/dist/tools/edit.d.ts.map +1 -1
- package/dist/tools/edit.js +394 -159
- package/dist/tools/edit.js.map +1 -1
- package/dist/tools/execute/bash/constants.d.ts +24 -0
- package/dist/tools/execute/bash/constants.d.ts.map +1 -0
- package/dist/tools/execute/bash/constants.js +88 -0
- package/dist/tools/execute/bash/constants.js.map +1 -0
- package/dist/tools/execute/bash/errors.d.ts +39 -0
- package/dist/tools/execute/bash/errors.d.ts.map +1 -0
- package/dist/tools/execute/bash/errors.js +249 -0
- package/dist/tools/execute/bash/errors.js.map +1 -0
- package/dist/tools/execute/bash/execution.d.ts +18 -0
- package/dist/tools/execute/bash/execution.d.ts.map +1 -0
- package/dist/tools/execute/bash/execution.js +207 -0
- package/dist/tools/execute/bash/execution.js.map +1 -0
- package/dist/tools/execute/bash/index.d.ts +3 -0
- package/dist/tools/execute/bash/index.d.ts.map +1 -0
- package/dist/tools/execute/bash/index.js +117 -0
- package/dist/tools/execute/bash/index.js.map +1 -0
- package/dist/tools/execute/bash/platform.d.ts +6 -0
- package/dist/tools/execute/bash/platform.d.ts.map +1 -0
- package/dist/tools/execute/bash/platform.js +64 -0
- package/dist/tools/execute/bash/platform.js.map +1 -0
- package/dist/tools/execute/bash/security.d.ts +12 -0
- package/dist/tools/execute/bash/security.d.ts.map +1 -0
- package/dist/tools/execute/bash/security.js +26 -0
- package/dist/tools/execute/bash/security.js.map +1 -0
- package/dist/tools/execute/bash/validation.d.ts +16 -0
- package/dist/tools/execute/bash/validation.d.ts.map +1 -0
- package/dist/tools/execute/bash/validation.js +57 -0
- package/dist/tools/execute/bash/validation.js.map +1 -0
- package/dist/tools/execute/bash.d.ts +3 -0
- package/dist/tools/execute/bash.d.ts.map +1 -0
- package/dist/tools/execute/bash.js +728 -0
- package/dist/tools/execute/bash.js.map +1 -0
- package/dist/tools/execute/git.d.ts +3 -0
- package/dist/tools/execute/git.d.ts.map +1 -0
- package/dist/tools/execute/git.js +183 -0
- package/dist/tools/execute/git.js.map +1 -0
- package/dist/tools/execute/task_complete.d.ts +7 -0
- package/dist/tools/execute/task_complete.d.ts.map +1 -0
- package/dist/tools/execute/task_complete.js +38 -0
- package/dist/tools/execute/task_complete.js.map +1 -0
- package/dist/tools/fetch.d.ts.map +1 -1
- package/dist/tools/fetch.js +2 -0
- package/dist/tools/fetch.js.map +1 -1
- package/dist/tools/find.d.ts.map +1 -1
- package/dist/tools/find.js +2 -0
- package/dist/tools/find.js.map +1 -1
- package/dist/tools/git.d.ts.map +1 -1
- package/dist/tools/git.js +2 -0
- package/dist/tools/git.js.map +1 -1
- package/dist/tools/glob.d.ts.map +1 -1
- package/dist/tools/glob.js +2 -0
- package/dist/tools/glob.js.map +1 -1
- package/dist/tools/grep.d.ts.map +1 -1
- package/dist/tools/grep.js +56 -30
- package/dist/tools/grep.js.map +1 -1
- package/dist/tools/install/clawhub.d.ts +26 -0
- package/dist/tools/install/clawhub.d.ts.map +1 -0
- package/dist/tools/install/clawhub.js +182 -0
- package/dist/tools/install/clawhub.js.map +1 -0
- package/dist/tools/install/constants.d.ts +5 -0
- package/dist/tools/install/constants.d.ts.map +1 -0
- package/dist/tools/install/constants.js +5 -0
- package/dist/tools/install/constants.js.map +1 -0
- package/dist/tools/install/install_skill.d.ts +3 -0
- package/dist/tools/install/install_skill.d.ts.map +1 -0
- package/dist/tools/install/install_skill.js +132 -0
- package/dist/tools/install/install_skill.js.map +1 -0
- package/dist/tools/install/npm.d.ts +8 -0
- package/dist/tools/install/npm.d.ts.map +1 -0
- package/dist/tools/install/npm.js +52 -0
- package/dist/tools/install/npm.js.map +1 -0
- package/dist/tools/install/skill-content.d.ts +9 -0
- package/dist/tools/install/skill-content.d.ts.map +1 -0
- package/dist/tools/install/skill-content.js +89 -0
- package/dist/tools/install/skill-content.js.map +1 -0
- package/dist/tools/install_skill.d.ts.map +1 -1
- package/dist/tools/install_skill.js +2 -0
- package/dist/tools/install_skill.js.map +1 -1
- package/dist/tools/list_memory.d.ts +3 -0
- package/dist/tools/list_memory.d.ts.map +1 -0
- package/dist/tools/list_memory.js +55 -0
- package/dist/tools/list_memory.js.map +1 -0
- package/dist/tools/ls.d.ts.map +1 -1
- package/dist/tools/ls.js +2 -0
- package/dist/tools/ls.js.map +1 -1
- package/dist/tools/memory/delete_memory.d.ts +3 -0
- package/dist/tools/memory/delete_memory.d.ts.map +1 -0
- package/dist/tools/memory/delete_memory.js +46 -0
- package/dist/tools/memory/delete_memory.js.map +1 -0
- package/dist/tools/memory/list_memory.d.ts +3 -0
- package/dist/tools/memory/list_memory.d.ts.map +1 -0
- package/dist/tools/memory/list_memory.js +55 -0
- package/dist/tools/memory/list_memory.js.map +1 -0
- package/dist/tools/memory/save_memory.d.ts +3 -0
- package/dist/tools/memory/save_memory.d.ts.map +1 -0
- package/dist/tools/memory/save_memory.js +45 -0
- package/dist/tools/memory/save_memory.js.map +1 -0
- package/dist/tools/read.d.ts.map +1 -1
- package/dist/tools/read.js +2 -0
- package/dist/tools/read.js.map +1 -1
- package/dist/tools/registry.d.ts +7 -8
- package/dist/tools/registry.d.ts.map +1 -1
- package/dist/tools/registry.js +114 -46
- package/dist/tools/registry.js.map +1 -1
- package/dist/tools/save_memory.d.ts +3 -0
- package/dist/tools/save_memory.d.ts.map +1 -0
- package/dist/tools/save_memory.js +45 -0
- package/dist/tools/save_memory.js.map +1 -0
- package/dist/tools/search.d.ts.map +1 -1
- package/dist/tools/search.js +2 -0
- package/dist/tools/search.js.map +1 -1
- package/dist/tools/sed.d.ts +4 -0
- package/dist/tools/sed.d.ts.map +1 -0
- package/dist/tools/sed.js +121 -0
- package/dist/tools/sed.js.map +1 -0
- package/dist/tools/tree.d.ts +12 -0
- package/dist/tools/tree.d.ts.map +1 -0
- package/dist/tools/tree.js +87 -0
- package/dist/tools/tree.js.map +1 -0
- package/dist/tools/types.d.ts +12 -0
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/tools/web/fetch.d.ts +3 -0
- package/dist/tools/web/fetch.d.ts.map +1 -0
- package/dist/tools/web/fetch.js +49 -0
- package/dist/tools/web/fetch.js.map +1 -0
- package/dist/tools/web/search.d.ts +3 -0
- package/dist/tools/web/search.d.ts.map +1 -0
- package/dist/tools/web/search.js +134 -0
- package/dist/tools/web/search.js.map +1 -0
- package/dist/tools/write_plan.d.ts.map +1 -1
- package/dist/tools/write_plan.js +2 -0
- package/dist/tools/write_plan.js.map +1 -1
- package/dist/tui/commands.d.ts +4 -0
- package/dist/tui/commands.d.ts.map +1 -0
- package/dist/tui/commands.js +118 -0
- package/dist/tui/commands.js.map +1 -0
- package/dist/tui/components/colors.d.ts +36 -0
- package/dist/tui/components/colors.d.ts.map +1 -0
- package/dist/tui/components/colors.js +48 -0
- package/dist/tui/components/colors.js.map +1 -0
- package/dist/tui/components/header-bar.d.ts +26 -0
- package/dist/tui/components/header-bar.d.ts.map +1 -0
- package/dist/tui/components/header-bar.js +78 -0
- package/dist/tui/components/header-bar.js.map +1 -0
- package/dist/tui/components/index.d.ts +9 -0
- package/dist/tui/components/index.d.ts.map +1 -0
- package/dist/tui/components/index.js +9 -0
- package/dist/tui/components/index.js.map +1 -0
- package/dist/tui/components/landing-screen.d.ts +12 -0
- package/dist/tui/components/landing-screen.d.ts.map +1 -0
- package/dist/tui/components/landing-screen.js +53 -0
- package/dist/tui/components/landing-screen.js.map +1 -0
- package/dist/tui/components/pixel-logo.d.ts +5 -0
- package/dist/tui/components/pixel-logo.d.ts.map +1 -0
- package/dist/tui/components/pixel-logo.js +27 -0
- package/dist/tui/components/pixel-logo.js.map +1 -0
- package/dist/tui/components/plan-utils.d.ts +11 -0
- package/dist/tui/components/plan-utils.d.ts.map +1 -0
- package/dist/tui/components/plan-utils.js +62 -0
- package/dist/tui/components/plan-utils.js.map +1 -0
- package/dist/tui/components/plans-list.d.ts +18 -0
- package/dist/tui/components/plans-list.d.ts.map +1 -0
- package/dist/tui/components/plans-list.js +46 -0
- package/dist/tui/components/plans-list.js.map +1 -0
- package/dist/tui/components/rich-footer.d.ts +29 -0
- package/dist/tui/components/rich-footer.d.ts.map +1 -0
- package/dist/tui/components/rich-footer.js +124 -0
- package/dist/tui/components/rich-footer.js.map +1 -0
- package/dist/tui/components/todo-panel.d.ts +14 -0
- package/dist/tui/components/todo-panel.d.ts.map +1 -0
- package/dist/tui/components/todo-panel.js +83 -0
- package/dist/tui/components/todo-panel.js.map +1 -0
- package/dist/tui/components.d.ts.map +1 -1
- package/dist/tui/components.js +14 -7
- package/dist/tui/components.js.map +1 -1
- package/dist/tui/index.d.ts +2 -1
- package/dist/tui/index.d.ts.map +1 -1
- package/dist/tui/index.js +99 -505
- package/dist/tui/index.js.map +1 -1
- package/dist/tui/overlays.d.ts +28 -0
- package/dist/tui/overlays.d.ts.map +1 -0
- package/dist/tui/overlays.js +154 -0
- package/dist/tui/overlays.js.map +1 -0
- package/dist/tui/themes.d.ts +5 -0
- package/dist/tui/themes.d.ts.map +1 -0
- package/dist/tui/themes.js +38 -0
- package/dist/tui/themes.js.map +1 -0
- package/dist/web/index.d.ts.map +1 -1
- package/dist/web/index.js +62 -101
- package/dist/web/index.js.map +1 -1
- package/dist/web/public/app.js +5 -855
- package/dist/web/public/confirm.js +70 -0
- package/dist/web/public/index.html +121 -120
- package/dist/web/public/input.js +107 -0
- package/dist/web/public/messages.js +411 -0
- package/dist/web/public/sidebar.js +82 -0
- package/dist/web/public/state.js +72 -0
- package/dist/web/public/style.css +247 -70
- package/dist/web/public/utils.js +37 -0
- package/dist/web/public/websocket.js +267 -0
- package/dist/web/public/ws.js +19 -0
- package/dist/web/session-bridge.d.ts.map +1 -1
- package/dist/web/session-bridge.js +85 -10
- package/dist/web/session-bridge.js.map +1 -1
- package/docs/ast-tools.md +117 -0
- package/package.json +11 -5
- package/scripts/check-line-count.mjs +53 -0
- package/scripts/copy-ast-wasm.mjs +32 -0
- package/scripts/copy-native.mjs +24 -0
- package/scripts/copy-web.mjs +15 -0
- package/src/agent/__tests__/session-restore.test.ts +284 -0
- package/src/agent/commands.ts +274 -0
- package/src/agent/compaction.ts +9 -2
- package/src/agent/index.ts +7 -2
- package/src/agent/llm.ts +4 -0
- package/src/agent/memory.ts +60 -0
- package/src/agent/prompt-builder.ts +111 -33
- package/src/agent/providers/google.ts +0 -1
- package/src/agent/providers/openai.ts +79 -8
- package/src/agent/session-chat.ts +480 -0
- package/src/agent/session-display.ts +195 -0
- package/src/agent/session-persistence.ts +146 -0
- package/src/agent/session-utils.ts +54 -0
- package/src/agent/session.ts +269 -670
- package/src/cli/index.ts +73 -4
- package/src/config/index.ts +14 -7
- package/src/index.ts +30 -3
- package/src/tools/__tests__/bash.test.ts +188 -2
- package/src/tools/__tests__/edit.test.ts +1216 -356
- package/src/tools/__tests__/fetch.test.ts +1 -1
- package/src/tools/__tests__/glob.test.ts +1 -1
- package/src/tools/__tests__/grep.test.ts +36 -1
- package/src/tools/__tests__/ls.test.ts +1 -1
- package/src/tools/__tests__/read.test.ts +1 -1
- package/src/tools/__tests__/registry.test.ts +332 -0
- package/src/tools/__tests__/write_plan.test.ts +1 -1
- package/src/tools/codebase/ast/__tests__/integration.test.ts +452 -0
- package/src/tools/codebase/ast/__tests__/tree-sitter.test.ts +466 -0
- package/src/tools/codebase/ast/adapter.ts +44 -0
- package/src/tools/codebase/ast/tools.ts +322 -0
- package/src/tools/codebase/ast/tree-sitter-adapter.ts +468 -0
- package/src/tools/codebase/ast/tree-sitter-converters.ts +480 -0
- package/src/tools/codebase/ast/types.ts +102 -0
- package/src/tools/codebase/ast/wasm/tree-sitter-python.wasm +0 -0
- package/src/tools/codebase/ast/wasm/tree-sitter-tsx.wasm +0 -0
- package/src/tools/codebase/ast/wasm/tree-sitter-typescript.wasm +0 -0
- package/src/tools/codebase/ast/wasm/tree-sitter.wasm +0 -0
- package/src/tools/codebase/ast/wasm/web-tree-sitter.wasm +0 -0
- package/src/tools/{find.ts → codebase/find.ts} +4 -2
- package/src/tools/{glob.ts → codebase/glob.ts} +4 -2
- package/src/tools/{grep.ts → codebase/grep.ts} +61 -32
- package/src/tools/{ls.ts → codebase/ls.ts} +4 -2
- package/src/tools/{read.ts → codebase/read.ts} +5 -3
- package/src/tools/edit/diff-compute.ts +21 -0
- package/src/tools/edit/diff-render.ts +145 -0
- package/src/tools/edit/edit.ts +468 -0
- package/src/tools/edit/matcher.ts +70 -0
- package/src/tools/edit/parser.ts +131 -0
- package/src/tools/edit/types.ts +19 -0
- package/src/tools/{write_plan.ts → edit/write_plan.ts} +4 -2
- package/src/tools/execute/bash/constants.ts +93 -0
- package/src/tools/execute/bash/errors.ts +304 -0
- package/src/tools/execute/bash/execution.ts +211 -0
- package/src/tools/execute/bash/index.ts +131 -0
- package/src/tools/execute/bash/platform.ts +65 -0
- package/src/tools/execute/bash/security.ts +28 -0
- package/src/tools/execute/bash/validation.ts +78 -0
- package/src/tools/execute/git.ts +209 -0
- package/src/tools/execute/task_complete.ts +40 -0
- package/src/tools/install/clawhub.ts +222 -0
- package/src/tools/install/constants.ts +4 -0
- package/src/tools/install/install_skill.ts +150 -0
- package/src/tools/install/npm.ts +60 -0
- package/src/tools/install/skill-content.ts +108 -0
- package/src/tools/memory/delete_memory.ts +46 -0
- package/src/tools/memory/list_memory.ts +53 -0
- package/src/tools/memory/save_memory.ts +45 -0
- package/src/tools/registry.ts +121 -50
- package/src/tools/tree.ts +103 -0
- package/src/tools/types.ts +13 -0
- package/src/tools/{fetch.ts → web/fetch.ts} +4 -2
- package/src/tools/{search.ts → web/search.ts} +4 -2
- package/src/tui/commands.ts +135 -0
- package/src/tui/components/colors.ts +52 -0
- package/src/tui/components/header-bar.ts +88 -0
- package/src/tui/components/index.ts +8 -0
- package/src/tui/components/landing-screen.ts +67 -0
- package/src/tui/components/pixel-logo.ts +33 -0
- package/src/tui/components/plan-utils.ts +69 -0
- package/src/tui/components/plans-list.ts +55 -0
- package/src/tui/components/rich-footer.ts +146 -0
- package/src/tui/components/todo-panel.ts +95 -0
- package/src/tui/index.ts +110 -561
- package/src/tui/overlays.ts +203 -0
- package/src/tui/themes.ts +41 -0
- package/src/web/index.ts +66 -107
- package/src/web/public/app.js +5 -855
- package/src/web/public/confirm.js +70 -0
- package/src/web/public/index.html +121 -120
- package/src/web/public/input.js +107 -0
- package/src/web/public/messages.js +411 -0
- package/src/web/public/sidebar.js +82 -0
- package/src/web/public/state.js +72 -0
- package/src/web/public/style.css +247 -70
- package/src/web/public/utils.js +37 -0
- package/src/web/public/websocket.js +267 -0
- package/src/web/public/ws.js +19 -0
- package/src/web/session-bridge.ts +90 -12
- package/.claude/settings.local.json +0 -14
- package/.kilo/plans/1780064105789-mighty-pixel.md +0 -171
- package/.kilo/plans/1780293725888-quick-wizard.md +0 -62
- package/.lonny/plan-web-cwd-status.md +0 -38
- package/AGENT.md +0 -99
- package/src/tools/bash.ts +0 -39
- package/src/tools/edit.ts +0 -554
- package/src/tools/exec.ts +0 -348
- package/src/tools/git.ts +0 -76
- package/src/tools/install_skill.ts +0 -539
- package/src/tui/components.ts +0 -635
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { computeDiff } from './diff-compute.js';
|
|
2
|
+
// ── ANSI colors for terminal output ───────────────────────────────────────
|
|
3
|
+
const DIFF_RED = '\x1b[38;2;255;80;80m';
|
|
4
|
+
const DIFF_GREEN = '\x1b[38;2;0;200;100m';
|
|
5
|
+
const DIFF_DIM = '\x1b[38;2;100;100;100m';
|
|
6
|
+
const DIFF_RESET = '\x1b[0m';
|
|
7
|
+
// ── Colors for HTML output ────────────────────────────────────────────────
|
|
8
|
+
const HTML_RED = '#ff5050';
|
|
9
|
+
const HTML_GREEN = '#00c864';
|
|
10
|
+
const HTML_DIM = '#888888';
|
|
11
|
+
/** Terminal renderer — unified-diff format with color */
|
|
12
|
+
export function renderDiffTerminal(lines, startLineNum) {
|
|
13
|
+
if (lines.length === 0)
|
|
14
|
+
return '';
|
|
15
|
+
const output = [];
|
|
16
|
+
let oldLn = startLineNum ?? 1;
|
|
17
|
+
let newLn = startLineNum ?? 1;
|
|
18
|
+
for (const line of lines) {
|
|
19
|
+
if (line.type === 'delete') {
|
|
20
|
+
output.push(` ${DIFF_RED}- ${oldLn} ${line.content}${DIFF_RESET}`);
|
|
21
|
+
oldLn++;
|
|
22
|
+
}
|
|
23
|
+
else if (line.type === 'insert') {
|
|
24
|
+
output.push(` ${DIFF_GREEN}+ ${newLn} ${line.content}${DIFF_RESET}`);
|
|
25
|
+
newLn++;
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
output.push(` ${DIFF_DIM} ${oldLn} ${line.content}${DIFF_RESET}`);
|
|
29
|
+
oldLn++;
|
|
30
|
+
newLn++;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return output.join('\n');
|
|
34
|
+
}
|
|
35
|
+
/** HTML renderer for web output */
|
|
36
|
+
export function renderDiffHtml(lines) {
|
|
37
|
+
if (lines.length === 0)
|
|
38
|
+
return '';
|
|
39
|
+
const output = [];
|
|
40
|
+
for (const line of lines) {
|
|
41
|
+
if (line.type === 'delete') {
|
|
42
|
+
output.push(` <span style="color: ${HTML_RED};">- ${escapeHtml(line.content)}</span>`);
|
|
43
|
+
}
|
|
44
|
+
else if (line.type === 'insert') {
|
|
45
|
+
output.push(` <span style="color: ${HTML_GREEN};">+ ${escapeHtml(line.content)}</span>`);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
output.push(` <span style="color: ${HTML_DIM};"> ${escapeHtml(line.content)}</span>`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return output.join('\n');
|
|
52
|
+
}
|
|
53
|
+
/** Escape HTML special characters */
|
|
54
|
+
export function escapeHtml(str) {
|
|
55
|
+
return str
|
|
56
|
+
.replace(/&/g, '&')
|
|
57
|
+
.replace(/</g, '<')
|
|
58
|
+
.replace(/>/g, '>')
|
|
59
|
+
.replace(/"/g, '"')
|
|
60
|
+
.replace(/'/g, ''');
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Generate diff output using jest-diff.
|
|
64
|
+
* Returns terminal-colored unified-diff format with line numbers.
|
|
65
|
+
*/
|
|
66
|
+
export function generateDiff(oldStr, newStr, startLineNum) {
|
|
67
|
+
const lines = computeDiff(oldStr, newStr);
|
|
68
|
+
return renderDiffTerminal(lines, startLineNum);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Generate diff with surrounding context lines (1 before, 1 after)
|
|
72
|
+
* and line numbers. Context lines are extracted from the full file content.
|
|
73
|
+
*/
|
|
74
|
+
export function generateDiffWithContext(fullContent, oldStr, newStr, matchIndex, matchLength) {
|
|
75
|
+
// Calculate 1-based line number of the first matched line
|
|
76
|
+
const firstLineNum = fullContent.slice(0, matchIndex).split('\n').length;
|
|
77
|
+
const contentLines = fullContent.split('\n');
|
|
78
|
+
// Find 0-based line index where matchIndex falls
|
|
79
|
+
let charPos = 0;
|
|
80
|
+
let matchStartLineIdx = 0;
|
|
81
|
+
for (let i = 0; i < contentLines.length; i++) {
|
|
82
|
+
if (charPos <= matchIndex && matchIndex < charPos + contentLines[i].length + 1) {
|
|
83
|
+
matchStartLineIdx = i;
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
charPos += contentLines[i].length + 1; // +1 for \n
|
|
87
|
+
}
|
|
88
|
+
// How many lines does oldStr span in the original content?
|
|
89
|
+
const oldLines = oldStr === '' ? [] : oldStr.split('\n');
|
|
90
|
+
const oldLineCount = oldLines.length;
|
|
91
|
+
const matchEndLineIdx = matchStartLineIdx + oldLineCount - 1;
|
|
92
|
+
// Context before (1 line) and after (1 line)
|
|
93
|
+
const beforeLineIdx = matchStartLineIdx > 0 ? matchStartLineIdx - 1 : -1;
|
|
94
|
+
const afterLineIdx = matchEndLineIdx < contentLines.length - 1 ? matchEndLineIdx + 1 : -1;
|
|
95
|
+
// Compute diff between oldStr and newStr
|
|
96
|
+
const diffLines = computeDiff(oldStr, newStr);
|
|
97
|
+
const output = [];
|
|
98
|
+
// Context before
|
|
99
|
+
if (beforeLineIdx !== -1) {
|
|
100
|
+
const lineNum = beforeLineIdx + 1;
|
|
101
|
+
output.push(` ${DIFF_DIM} ${lineNum} ${contentLines[beforeLineIdx]}${DIFF_RESET}`);
|
|
102
|
+
}
|
|
103
|
+
// Diff lines with line numbers
|
|
104
|
+
let oldLn = firstLineNum;
|
|
105
|
+
let newLn = firstLineNum;
|
|
106
|
+
for (const line of diffLines) {
|
|
107
|
+
if (line.type === 'delete') {
|
|
108
|
+
output.push(` ${DIFF_RED}- ${oldLn} ${line.content}${DIFF_RESET}`);
|
|
109
|
+
oldLn++;
|
|
110
|
+
}
|
|
111
|
+
else if (line.type === 'insert') {
|
|
112
|
+
output.push(` ${DIFF_GREEN}+ ${newLn} ${line.content}${DIFF_RESET}`);
|
|
113
|
+
newLn++;
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
output.push(` ${DIFF_DIM} ${oldLn} ${line.content}${DIFF_RESET}`);
|
|
117
|
+
oldLn++;
|
|
118
|
+
newLn++;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
// Context after
|
|
122
|
+
if (afterLineIdx !== -1) {
|
|
123
|
+
const lineNum = afterLineIdx + 1;
|
|
124
|
+
output.push(` ${DIFF_DIM} ${lineNum} ${contentLines[afterLineIdx]}${DIFF_RESET}`);
|
|
125
|
+
}
|
|
126
|
+
return output.join('\n');
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=diff-render.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diff-render.js","sourceRoot":"","sources":["../../../src/tools/edit/diff-render.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAG/C,6EAA6E;AAC7E,MAAM,QAAQ,GAAG,sBAAsB,CAAA;AACvC,MAAM,UAAU,GAAG,sBAAsB,CAAA;AACzC,MAAM,QAAQ,GAAG,wBAAwB,CAAA;AACzC,MAAM,UAAU,GAAG,SAAS,CAAA;AAE5B,6EAA6E;AAC7E,MAAM,QAAQ,GAAG,SAAS,CAAA;AAC1B,MAAM,UAAU,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M,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AAC1B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"edit.d.ts","sourceRoot":"","sources":["../../../src/tools/edit/edit.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAE1D,OAAO,KAAK,EAAE,IAAI,EAAc,MAAM,aAAa,CAAA;AAMnD,wBAAgB,cAAc,CAAC,OAAO,EAAE,eAAe,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,CAyc1E"}
|
|
@@ -0,0 +1,440 @@
|
|
|
1
|
+
import * as fs from 'node:fs';
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
import { fmtErr } from '../errors.js';
|
|
4
|
+
import { generateDiff, generateDiffWithContext } from './diff-render.js';
|
|
5
|
+
import { findAllLinesTolerant, normalizeLine } from './matcher.js';
|
|
6
|
+
import { buildDiag, extractEditsFromJSON, parseMarkdownEdit, summarizeRawInput } from './parser.js';
|
|
7
|
+
export function createEditTool(applier, cwd) {
|
|
8
|
+
return {
|
|
9
|
+
definition: {
|
|
10
|
+
name: 'edit',
|
|
11
|
+
category: 'Edit',
|
|
12
|
+
group: 'File',
|
|
13
|
+
description: `Replace exact text in files using markdown code block format.
|
|
14
|
+
IMPORTANT: There is no "write" tool — always use this tool ("edit") to modify files.
|
|
15
|
+
|
|
16
|
+
HOW TO USE:
|
|
17
|
+
1. Read the file first with \`read\`
|
|
18
|
+
2. Copy the EXACT text to replace — include 2-3 lines of context before/after
|
|
19
|
+
3. Use markdown code block format below
|
|
20
|
+
|
|
21
|
+
FORMAT:
|
|
22
|
+
\`\`\`edit
|
|
23
|
+
file: <file_path>
|
|
24
|
+
old: |
|
|
25
|
+
<exact text to find>
|
|
26
|
+
new: |
|
|
27
|
+
<replacement text>
|
|
28
|
+
\`\`\`
|
|
29
|
+
|
|
30
|
+
EXAMPLES:
|
|
31
|
+
Single edit:
|
|
32
|
+
\`\`\`edit
|
|
33
|
+
file: src/config.ts
|
|
34
|
+
old: |
|
|
35
|
+
mode: 'code'
|
|
36
|
+
new: |
|
|
37
|
+
mode: 'plan'
|
|
38
|
+
\`\`\`
|
|
39
|
+
|
|
40
|
+
Create new file:
|
|
41
|
+
\`\`\`edit
|
|
42
|
+
file: src/new.ts
|
|
43
|
+
old: |
|
|
44
|
+
new: |
|
|
45
|
+
const x = 1
|
|
46
|
+
\`\`\`
|
|
47
|
+
|
|
48
|
+
Multiple files (use separate code blocks):
|
|
49
|
+
\`\`\`edit
|
|
50
|
+
file: src/config.ts
|
|
51
|
+
old: |
|
|
52
|
+
mode: 'code'
|
|
53
|
+
new: |
|
|
54
|
+
mode: 'plan'
|
|
55
|
+
\`\`\`
|
|
56
|
+
\`\`\`edit
|
|
57
|
+
file: src/constants.ts
|
|
58
|
+
old: |
|
|
59
|
+
MAX_RETRIES = 3
|
|
60
|
+
new: |
|
|
61
|
+
MAX_RETRIES = 5
|
|
62
|
+
\`\`\`
|
|
63
|
+
|
|
64
|
+
CRITICAL RULES:
|
|
65
|
+
- old and new are separated by "old:" and "new:" labels
|
|
66
|
+
- Use | after label for multi-line content
|
|
67
|
+
- old_string must match EXACTLY (whitespace, indentation, line breaks)
|
|
68
|
+
- Do NOT include the "<lineNumber>: " prefix from read output
|
|
69
|
+
- old_string must be CONTIGUOUS text from the file — you CANNOT skip lines between old_string and new_string boundaries. If you need to edit non-adjacent sections, use separate \`\`\`edit blocks.`,
|
|
70
|
+
parameters: {
|
|
71
|
+
content: {
|
|
72
|
+
type: 'string',
|
|
73
|
+
description: 'Markdown code block with edit instructions. See description for format.',
|
|
74
|
+
required: true,
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
async execute(input) {
|
|
79
|
+
// Debug: keep rawInput for error messages (capture early for all error paths)
|
|
80
|
+
const rawInput = input;
|
|
81
|
+
// ── Parse markdown format ─────────────────────────────────────────
|
|
82
|
+
let edits = [];
|
|
83
|
+
// If input has 'content' field (new markdown format)
|
|
84
|
+
if (typeof input.content === 'string') {
|
|
85
|
+
// Compat: handle double-JSON-wrapped content
|
|
86
|
+
let contentStr = input.content;
|
|
87
|
+
try {
|
|
88
|
+
const parsed = JSON.parse(contentStr);
|
|
89
|
+
if (typeof parsed === 'string') {
|
|
90
|
+
contentStr = parsed;
|
|
91
|
+
}
|
|
92
|
+
else if (parsed && typeof parsed === 'object' && typeof parsed.content === 'string') {
|
|
93
|
+
contentStr = parsed.content;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
// Not JSON — use as-is
|
|
98
|
+
}
|
|
99
|
+
edits = parseMarkdownEdit(contentStr);
|
|
100
|
+
if (edits.length === 0) {
|
|
101
|
+
return {
|
|
102
|
+
success: false,
|
|
103
|
+
output: '',
|
|
104
|
+
error: `Failed to parse edit format. Raw input: ${summarizeRawInput(rawInput)}\nUse: \`\`\`edit\\nfile: path\\nold: |\\ntext\\nnew: |\\ntext\\n\`\`\``,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
// Legacy JSON format (backward compatibility)
|
|
110
|
+
edits = extractEditsFromJSON(input);
|
|
111
|
+
}
|
|
112
|
+
if (edits.length === 0) {
|
|
113
|
+
// Check if input specifically had empty edits array (for better error message)
|
|
114
|
+
const inputEdits = input.edits;
|
|
115
|
+
if ('edits' in input && Array.isArray(inputEdits) && inputEdits.length === 0) {
|
|
116
|
+
return {
|
|
117
|
+
success: false,
|
|
118
|
+
output: '',
|
|
119
|
+
error: `edit FAILED — no edits to apply. The edits array exists but is empty. Raw input: ${summarizeRawInput(rawInput)}`,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
// Check if input has edits key but it's not an array
|
|
123
|
+
if ('edits' in input && !Array.isArray(input.edits)) {
|
|
124
|
+
return {
|
|
125
|
+
success: false,
|
|
126
|
+
output: '',
|
|
127
|
+
error: `edit requires "edits" array. Use markdown format: \`\`\`edit\\nfile: path\\nold: |\\ntext\\nnew: |\\ntext\\n\`\`\`\nRaw input: ${summarizeRawInput(rawInput)}`,
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
return {
|
|
131
|
+
success: false,
|
|
132
|
+
output: '',
|
|
133
|
+
error: `No valid edits found (empty or invalid format). The edit array must contain objects with file_path, old_string, and new_string. Use markdown code block format: \`\`\`edit\\nfile: path\\nold: |\\ntext\\nnew: |\\ntext\\n\`\`\`\nRaw input: ${summarizeRawInput(rawInput)}`,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
// Validate each edit object
|
|
137
|
+
const editErrors = [];
|
|
138
|
+
for (let i = 0; i < edits.length; i++) {
|
|
139
|
+
const e = edits[i];
|
|
140
|
+
const missing = [];
|
|
141
|
+
if (typeof e.file_path !== 'string' || !e.file_path)
|
|
142
|
+
missing.push('file_path');
|
|
143
|
+
if (typeof e.old_string !== 'string')
|
|
144
|
+
missing.push('old_string');
|
|
145
|
+
if (typeof e.new_string !== 'string')
|
|
146
|
+
missing.push('new_string');
|
|
147
|
+
if (e.new_string === '__MISSING_NEW_STRING__') {
|
|
148
|
+
missing.push('new_string (required — LLM must provide a non-empty replacement)');
|
|
149
|
+
}
|
|
150
|
+
if (missing.length > 0) {
|
|
151
|
+
const present = Object.keys(e)
|
|
152
|
+
.filter(k => typeof e[k] === 'string')
|
|
153
|
+
.join(', ');
|
|
154
|
+
editErrors.push(` edit #${i + 1}: missing ${missing.join(', ')}${present ? ` (has: ${present})` : ''}`);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
if (editErrors.length > 0) {
|
|
158
|
+
return {
|
|
159
|
+
success: false,
|
|
160
|
+
output: '',
|
|
161
|
+
error: `edit FAILED — ${editErrors.length} of ${edits.length} edit(s) have missing fields.\n${editErrors.join('\n')}\n\nReceived: ${summarizeRawInput(rawInput)}\n\nEach edit object must be a COMPLETE find-replace pair with BOTH old_string AND new_string.`,
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
// ── Path traversal security check (symlink-aware) ─────────────────
|
|
165
|
+
const resolvedCwd = path.resolve(cwd);
|
|
166
|
+
let realCwd;
|
|
167
|
+
try {
|
|
168
|
+
realCwd = fs.realpathSync(resolvedCwd);
|
|
169
|
+
}
|
|
170
|
+
catch {
|
|
171
|
+
realCwd = resolvedCwd;
|
|
172
|
+
}
|
|
173
|
+
for (let i = 0; i < edits.length; i++) {
|
|
174
|
+
const e = edits[i];
|
|
175
|
+
const resolved = path.resolve(cwd, e.file_path);
|
|
176
|
+
const relative = path.relative(resolvedCwd, resolved);
|
|
177
|
+
if (relative.startsWith('..') || path.isAbsolute(relative)) {
|
|
178
|
+
return {
|
|
179
|
+
success: false,
|
|
180
|
+
output: '',
|
|
181
|
+
error: 'edit FAILED — Path traversal detected: "' +
|
|
182
|
+
e.file_path +
|
|
183
|
+
'" resolves outside the working directory "' +
|
|
184
|
+
resolvedCwd +
|
|
185
|
+
'". All file paths must be within the project directory.',
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
// Symlink-aware check: resolve real path to detect traversal via symlink
|
|
189
|
+
let realPath;
|
|
190
|
+
try {
|
|
191
|
+
realPath = fs.realpathSync(resolved);
|
|
192
|
+
}
|
|
193
|
+
catch {
|
|
194
|
+
// File doesn't exist yet – resolve nearest existing ancestor through symlinks
|
|
195
|
+
let dir = path.dirname(resolved);
|
|
196
|
+
while (!fs.existsSync(dir)) {
|
|
197
|
+
const parent = path.dirname(dir);
|
|
198
|
+
if (parent === dir)
|
|
199
|
+
break; // root
|
|
200
|
+
dir = parent;
|
|
201
|
+
}
|
|
202
|
+
try {
|
|
203
|
+
realPath = path.join(fs.realpathSync(dir), path.relative(dir, resolved));
|
|
204
|
+
}
|
|
205
|
+
catch {
|
|
206
|
+
realPath = resolved;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
const realRelative = path.relative(realCwd, realPath);
|
|
210
|
+
if (realRelative.startsWith('..') || path.isAbsolute(realRelative)) {
|
|
211
|
+
return {
|
|
212
|
+
success: false,
|
|
213
|
+
output: '',
|
|
214
|
+
error: 'edit FAILED — Path traversal detected via symlink: "' +
|
|
215
|
+
e.file_path +
|
|
216
|
+
'" resolves outside "' +
|
|
217
|
+
realCwd +
|
|
218
|
+
'".',
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
const fileGroups = new Map();
|
|
223
|
+
for (const e of edits) {
|
|
224
|
+
const resolved = path.resolve(cwd, e.file_path);
|
|
225
|
+
if (!fileGroups.has(resolved)) {
|
|
226
|
+
let originalContent = null;
|
|
227
|
+
try {
|
|
228
|
+
originalContent = fs.readFileSync(resolved, 'utf-8');
|
|
229
|
+
}
|
|
230
|
+
catch {
|
|
231
|
+
/* file doesn't exist yet */
|
|
232
|
+
}
|
|
233
|
+
fileGroups.set(resolved, { edits: [], originalContent });
|
|
234
|
+
}
|
|
235
|
+
fileGroups.get(resolved).edits.push(e);
|
|
236
|
+
}
|
|
237
|
+
const results = [];
|
|
238
|
+
let anyFailed = false;
|
|
239
|
+
let firstError = '';
|
|
240
|
+
const modifiedFiles = new Map();
|
|
241
|
+
for (const [resolved, group] of fileGroups) {
|
|
242
|
+
const relPath = path.relative(cwd, resolved).replace(/\\/g, '/');
|
|
243
|
+
let content = group.originalContent !== null ? group.originalContent.replace(/\r\n/g, '\n') : null;
|
|
244
|
+
// Check if file was read (for stale-content diagnostics)
|
|
245
|
+
const readWarning = content !== null ? applier.checkModified(resolved) : null;
|
|
246
|
+
for (let i = group.edits.length - 1; i >= 0; i--) {
|
|
247
|
+
const e = group.edits[i];
|
|
248
|
+
// Normalize CRLF → LF in AI-provided strings (critical on Windows)
|
|
249
|
+
e.old_string = e.old_string.replace(/\r\n/g, '\n');
|
|
250
|
+
e.new_string = e.new_string.replace(/\r\n/g, '\n');
|
|
251
|
+
if (e.old_string === '') {
|
|
252
|
+
if (content !== null) {
|
|
253
|
+
// File already exists in-memory (from prior edit in this batch)
|
|
254
|
+
// or on disk — treat as error to prevent silent overwrites.
|
|
255
|
+
results.push(` FAIL ${relPath}: Cannot create — file already exists (duplicate create in batch or file on disk)`);
|
|
256
|
+
if (!anyFailed) {
|
|
257
|
+
anyFailed = true;
|
|
258
|
+
firstError = `Cannot create file "${relPath}": file already exists`;
|
|
259
|
+
}
|
|
260
|
+
break;
|
|
261
|
+
}
|
|
262
|
+
const newLines = e.new_string.split('\n').length;
|
|
263
|
+
content = e.new_string;
|
|
264
|
+
results.push(` Created ${relPath} (${newLines} lines):\n${generateDiff('', e.new_string, 1)}`);
|
|
265
|
+
continue;
|
|
266
|
+
}
|
|
267
|
+
if (content === null) {
|
|
268
|
+
const diag = buildDiag(e);
|
|
269
|
+
const suggestion = ` → Check the file path, or create it first with old_string: "" (empty string).`;
|
|
270
|
+
results.push(` FAIL ${relPath}: File not found
|
|
271
|
+
Edit: ${diag}
|
|
272
|
+
${suggestion}`);
|
|
273
|
+
if (!anyFailed) {
|
|
274
|
+
anyFailed = true;
|
|
275
|
+
firstError = `File not found: ${relPath}`;
|
|
276
|
+
}
|
|
277
|
+
break;
|
|
278
|
+
}
|
|
279
|
+
// ── Tier 1: Exact match ──────────────────────────────────────
|
|
280
|
+
const exactIdx = content.indexOf(e.old_string);
|
|
281
|
+
let matchInfo = null;
|
|
282
|
+
if (exactIdx !== -1) {
|
|
283
|
+
// Exact match found — check for duplicates
|
|
284
|
+
const lastIdx = content.lastIndexOf(e.old_string);
|
|
285
|
+
if (exactIdx !== lastIdx) {
|
|
286
|
+
const diag = buildDiag(e);
|
|
287
|
+
const suggestion = ` → Include more surrounding context lines (2-3 lines before and after) in old_string to make the match unique.`;
|
|
288
|
+
results.push(` FAIL ${relPath}: old_string appears MULTIPLE times
|
|
289
|
+
Edit: ${diag}
|
|
290
|
+
${suggestion}`);
|
|
291
|
+
if (!anyFailed) {
|
|
292
|
+
anyFailed = true;
|
|
293
|
+
firstError = `old_string appears MULTIPLE times in ${relPath}`;
|
|
294
|
+
}
|
|
295
|
+
break;
|
|
296
|
+
}
|
|
297
|
+
matchInfo = { index: exactIdx, length: e.old_string.length, strategy: 'exact' };
|
|
298
|
+
}
|
|
299
|
+
else {
|
|
300
|
+
// ── Tier 2: Whitespace-normalized fallback ─────────────────
|
|
301
|
+
const tolerant = findAllLinesTolerant(content, e.old_string);
|
|
302
|
+
if (tolerant.length === 0) {
|
|
303
|
+
// Not found by any strategy — check if old_string lines are scattered (non-contiguous)
|
|
304
|
+
const contentLines = content.split('\n');
|
|
305
|
+
const oldLines = e.old_string.split('\n').filter(l => l.trim());
|
|
306
|
+
const foundIndices = [];
|
|
307
|
+
for (const ol of oldLines) {
|
|
308
|
+
const normOl = normalizeLine(ol.trim());
|
|
309
|
+
if (!normOl)
|
|
310
|
+
continue;
|
|
311
|
+
const idx = contentLines.findIndex((cl, ci) => !foundIndices.includes(ci) && normalizeLine(cl).includes(normOl));
|
|
312
|
+
if (idx !== -1)
|
|
313
|
+
foundIndices.push(idx);
|
|
314
|
+
}
|
|
315
|
+
let hint = '';
|
|
316
|
+
const isScattered = foundIndices.length >= 2 &&
|
|
317
|
+
foundIndices[foundIndices.length - 1] - foundIndices[0] + 1 > foundIndices.length;
|
|
318
|
+
if (isScattered) {
|
|
319
|
+
hint = `\n ⚠️ ${foundIndices.length} lines of old_string were found in the file, but they are NOT contiguous — you skipped lines between them.
|
|
320
|
+
old_string must be a CONTIGUOUS chunk of the file. Use separate \`\`\`edit blocks for each section (see "Multiple files" example above).
|
|
321
|
+
Matched at lines: ${foundIndices.map(i => i + 1).join(', ')}`;
|
|
322
|
+
}
|
|
323
|
+
else {
|
|
324
|
+
const firstLine = (e.old_string.split('\n')[0] || '').trim();
|
|
325
|
+
if (firstLine) {
|
|
326
|
+
const normFirst = normalizeLine(firstLine);
|
|
327
|
+
const similarIdx = contentLines.findIndex(l => l.length > 0 && normFirst.length > 0 && normalizeLine(l).includes(normFirst));
|
|
328
|
+
if (similarIdx !== -1) {
|
|
329
|
+
const start = Math.max(0, similarIdx - 1);
|
|
330
|
+
const end = Math.min(contentLines.length, similarIdx + 2);
|
|
331
|
+
const snippet = contentLines.slice(start, end).join('\n');
|
|
332
|
+
hint = `\n Near line ${similarIdx + 1}:\n """\n${snippet}\n """`;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
if (!hint && contentLines.length > 0) {
|
|
336
|
+
const lines = contentLines.slice(0, Math.min(contentLines.length, 5));
|
|
337
|
+
hint = `\n File content (first ${lines.length} lines):\n """\n${lines.join('\n')}\n """`;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
const diag = buildDiag(e);
|
|
341
|
+
const readHint = readWarning ? `\n ${readWarning}` : '';
|
|
342
|
+
const suggestion = ` → Read the file again with read({ paths: ["${e.file_path}"] }) to get current content, then retry with exact matching text. Include 2-3 lines of surrounding context for uniqueness.${readHint}`;
|
|
343
|
+
results.push(` FAIL ${relPath}: old_string not found${hint}
|
|
344
|
+
Edit: ${diag}
|
|
345
|
+
${suggestion}`);
|
|
346
|
+
if (!anyFailed) {
|
|
347
|
+
anyFailed = true;
|
|
348
|
+
firstError = `old_string not found in ${relPath}${hint}`;
|
|
349
|
+
}
|
|
350
|
+
break;
|
|
351
|
+
}
|
|
352
|
+
if (tolerant.length > 1) {
|
|
353
|
+
const diag = buildDiag(e);
|
|
354
|
+
const suggestion = ` → Include more surrounding context lines (2-3 lines before and after) in old_string to make the match unique.`;
|
|
355
|
+
results.push(` FAIL ${relPath}: old_string appears MULTIPLE times (whitespace-normalized)\n Edit: ${diag}\n${suggestion}`);
|
|
356
|
+
if (!anyFailed) {
|
|
357
|
+
anyFailed = true;
|
|
358
|
+
firstError = `old_string appears MULTIPLE times in ${relPath} (whitespace-normalized)`;
|
|
359
|
+
}
|
|
360
|
+
break;
|
|
361
|
+
}
|
|
362
|
+
matchInfo = {
|
|
363
|
+
index: tolerant[0].index,
|
|
364
|
+
length: tolerant[0].length,
|
|
365
|
+
strategy: 'tolerant',
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
// For tolerant matching, use the actual file text at the match position
|
|
369
|
+
// so the diff reflects what was really in the file (with original whitespace).
|
|
370
|
+
const matchedOld = matchInfo.strategy === 'tolerant'
|
|
371
|
+
? content.slice(matchInfo.index, matchInfo.index + matchInfo.length)
|
|
372
|
+
: e.old_string;
|
|
373
|
+
const diff = generateDiffWithContext(content, matchedOld, e.new_string, matchInfo.index, matchInfo.length);
|
|
374
|
+
results.push(` Edited ${relPath}:\n${diff}`);
|
|
375
|
+
content =
|
|
376
|
+
content.slice(0, matchInfo.index) +
|
|
377
|
+
e.new_string +
|
|
378
|
+
content.slice(matchInfo.index + matchInfo.length);
|
|
379
|
+
}
|
|
380
|
+
if (anyFailed)
|
|
381
|
+
break;
|
|
382
|
+
modifiedFiles.set(resolved, content);
|
|
383
|
+
}
|
|
384
|
+
if (anyFailed) {
|
|
385
|
+
for (const [filePath, group] of fileGroups) {
|
|
386
|
+
const originalContent = group.originalContent;
|
|
387
|
+
if (originalContent === null) {
|
|
388
|
+
try {
|
|
389
|
+
fs.unlinkSync(filePath);
|
|
390
|
+
}
|
|
391
|
+
catch {
|
|
392
|
+
/* ok */
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
else {
|
|
396
|
+
try {
|
|
397
|
+
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
398
|
+
fs.writeFileSync(filePath, originalContent, 'utf-8');
|
|
399
|
+
}
|
|
400
|
+
catch {
|
|
401
|
+
/* ok */
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
applier.markRead(filePath);
|
|
405
|
+
}
|
|
406
|
+
// Only show FAIL lines in the error (successful edits were rolled back)
|
|
407
|
+
const failLines = results.filter(r => r.startsWith(' FAIL ')).join('\n');
|
|
408
|
+
return {
|
|
409
|
+
success: false,
|
|
410
|
+
output: '',
|
|
411
|
+
error: `Edit FAILED — all changes rolled back.\n${failLines}\n\n${firstError}`,
|
|
412
|
+
};
|
|
413
|
+
}
|
|
414
|
+
for (const [resolved, content] of modifiedFiles) {
|
|
415
|
+
try {
|
|
416
|
+
if (content === null) {
|
|
417
|
+
fs.unlinkSync(resolved);
|
|
418
|
+
}
|
|
419
|
+
else {
|
|
420
|
+
fs.mkdirSync(path.dirname(resolved), { recursive: true });
|
|
421
|
+
fs.writeFileSync(resolved, content, 'utf-8');
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
catch (err) {
|
|
425
|
+
return {
|
|
426
|
+
success: false,
|
|
427
|
+
output: '',
|
|
428
|
+
error: `Failed to write ${path.relative(cwd, resolved).replace(/\\/g, '/')}: ${fmtErr(err)}. Input: ${summarizeRawInput(rawInput)}`,
|
|
429
|
+
};
|
|
430
|
+
}
|
|
431
|
+
applier.markRead(resolved);
|
|
432
|
+
}
|
|
433
|
+
return {
|
|
434
|
+
success: true,
|
|
435
|
+
output: results.join('\n').replace(/^ {2}/gm, ''),
|
|
436
|
+
};
|
|
437
|
+
},
|
|
438
|
+
};
|
|
439
|
+
}
|
|
440
|
+
//# sourceMappingURL=edit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"edit.js","sourceRoot":"","sources":["../../../src/tools/edit/edit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAA;AAC7B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AAEjC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAErC,OAAO,EAAE,YAAY,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAA;AACxE,OAAO,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAClE,OAAO,EAAE,SAAS,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAGnG,MAAM,UAAU,cAAc,CAAC,OAAwB,EAAE,GAAW;IAClE,OAAO;QACL,UAAU,EAAE;YACV,IAAI,EAAE,MAAM;YACZ,Q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QAAQ,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAA;wBACzD,EAAE,CAAC,aAAa,CAAC,QAAQ,EAAE,OAAO,EAAE,OAAO,CAAC,CAAA;oBAC9C,CAAC;gBACH,CAAC;gBAAC,OAAO,GAAG,EAAE,CAAC;oBACb,OAAO;wBACL,OAAO,EAAE,KAAK;wBACd,MAAM,EAAE,EAAE;wBACV,KAAK,EAAE,mBAAmB,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,KAAK,MAAM,CAAC,GAAG,CAAC,YAAY,iBAAiB,CAAC,QAAQ,CAAC,EAAE;qBACpI,CAAA;gBACH,CAAC;gBACD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAA;YAC5B,CAAC;YAED,OAAO;gBACL,OAAO,EAAE,IAAI;gBACb,MAAM,EAAE,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC;aAClD,CAAA;QACH,CAAC;KACF,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { MatchPos } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Normalize a line for whitespace-tolerant comparison:
|
|
4
|
+
* 1. Trim leading/trailing whitespace
|
|
5
|
+
* 2. Collapse runs of 2+ spaces/tabs into a single space
|
|
6
|
+
*
|
|
7
|
+
* This handles whitespace differences ANYWHERE on the line:
|
|
8
|
+
* - Leading/trailing spaces → `trim()` removes them
|
|
9
|
+
* - Extra internal spaces → `"foo bar"` → `"foo bar"`
|
|
10
|
+
* - Blank lines with spaces → `" "` → `""`
|
|
11
|
+
*/
|
|
12
|
+
/** Export for testing */
|
|
13
|
+
export declare function normalizeLine(s: string): string;
|
|
14
|
+
/**
|
|
15
|
+
* Sliding-window line search that ignores whitespace differences
|
|
16
|
+
* (leading, trailing, and internal runs).
|
|
17
|
+
*
|
|
18
|
+
* Returns all match positions in the ORIGINAL (unnormalized) content,
|
|
19
|
+
* so the caller can do content.slice(match.index, match.index + match.length)
|
|
20
|
+
* to extract the actual matched text (with its original whitespace).
|
|
21
|
+
*/
|
|
22
|
+
/** Export for testing */
|
|
23
|
+
export declare function findAllLinesTolerant(content: string, oldString: string): MatchPos[];
|
|
24
|
+
//# sourceMappingURL=matcher.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"matcher.d.ts","sourceRoot":"","sources":["../../../src/tools/edit/matcher.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAE1C;;;;;;;;;GASG;AACH,yBAAyB;AACzB,wBAAgB,aAAa,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAE/C;AAED;;;;;;;GAOG;AACH,yBAAyB;AACzB,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,QAAQ,EAAE,CA2CnF"}
|