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,222 @@
|
|
|
1
|
+
import * as fs from 'node:fs'
|
|
2
|
+
import * as path from 'node:path'
|
|
3
|
+
// @ts-expect-error - adm-zip has no types
|
|
4
|
+
import AdmZip from 'adm-zip'
|
|
5
|
+
import { fmtErr } from '../errors.js'
|
|
6
|
+
import type { ToolResult } from '../types.js'
|
|
7
|
+
import { CLAWHUB_API_BASE, SKILLS_DIR } from './constants.js'
|
|
8
|
+
import { generateClawHubSkillContent, sanitizeSkillName } from './skill-content.js'
|
|
9
|
+
|
|
10
|
+
/** Fetch skill info from ClawHub API */
|
|
11
|
+
export async function fetchClawHubSkillInfo(
|
|
12
|
+
slug: string,
|
|
13
|
+
): Promise<{ displayName: string; summary: string; latestVersion: string } | null> {
|
|
14
|
+
try {
|
|
15
|
+
const response = await fetch(`${CLAWHUB_API_BASE}/skills/${encodeURIComponent(slug)}`, {
|
|
16
|
+
headers: { Accept: 'application/json' },
|
|
17
|
+
})
|
|
18
|
+
if (!response.ok) return null
|
|
19
|
+
|
|
20
|
+
const data = (await response.json()) as {
|
|
21
|
+
skill?: { displayName?: string; summary?: string }
|
|
22
|
+
latestVersion?: { version?: string }
|
|
23
|
+
}
|
|
24
|
+
return {
|
|
25
|
+
displayName: data.skill?.displayName || slug,
|
|
26
|
+
summary: data.skill?.summary || '',
|
|
27
|
+
latestVersion: data.latestVersion?.version || 'latest',
|
|
28
|
+
}
|
|
29
|
+
} catch {
|
|
30
|
+
return null
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Download a ClawHub skill as a ZIP and extract its content */
|
|
35
|
+
export async function downloadClawHubSkill(
|
|
36
|
+
slug: string,
|
|
37
|
+
version?: string,
|
|
38
|
+
): Promise<{ files: Map<string, string> } | null> {
|
|
39
|
+
try {
|
|
40
|
+
const versionPath = version ? `/${version}` : ''
|
|
41
|
+
const url = `${CLAWHUB_API_BASE}/download?slug=${encodeURIComponent(slug)}${version ? `&version=${encodeURIComponent(version)}` : ''}`
|
|
42
|
+
const response = await fetch(url)
|
|
43
|
+
if (!response.ok) {
|
|
44
|
+
// Try alternative URL patterns
|
|
45
|
+
const altUrl = `${CLAWHUB_API_BASE}/download/${encodeURIComponent(slug)}${versionPath}`
|
|
46
|
+
const altResponse = await fetch(altUrl)
|
|
47
|
+
if (!altResponse.ok) return null
|
|
48
|
+
|
|
49
|
+
const buffer = await altResponse.arrayBuffer()
|
|
50
|
+
return extractZipContent(Buffer.from(buffer))
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const buffer = await response.arrayBuffer()
|
|
54
|
+
return extractZipContent(Buffer.from(buffer))
|
|
55
|
+
} catch {
|
|
56
|
+
return null
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Extract files from a ZIP buffer */
|
|
61
|
+
export function extractZipContent(buffer: Buffer): { files: Map<string, string> } {
|
|
62
|
+
const zip = new AdmZip(buffer)
|
|
63
|
+
const entries = zip.getEntries()
|
|
64
|
+
const files = new Map<string, string>()
|
|
65
|
+
|
|
66
|
+
for (const entry of entries) {
|
|
67
|
+
if (!entry.isDirectory) {
|
|
68
|
+
files.set(entry.entryName, entry.getData().toString('utf-8'))
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return { files }
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Find the SKILL.md entry in the downloaded files (case-insensitive) */
|
|
76
|
+
export function findSkillMdInZip(files: Map<string, string>): string | null {
|
|
77
|
+
for (const [filePath] of files) {
|
|
78
|
+
const normalized = filePath.replace(/\\/g, '/').toLowerCase()
|
|
79
|
+
if (normalized.endsWith('/skill.md')) {
|
|
80
|
+
return files.get(filePath) || null
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
// Fallback: check root-level SKILL.md
|
|
84
|
+
for (const [filePath] of files) {
|
|
85
|
+
const normalized = filePath.replace(/\\/g, '/')
|
|
86
|
+
if (normalized.toLowerCase() === 'skill.md' || normalized.endsWith('/skill.md')) {
|
|
87
|
+
return files.get(filePath) || null
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return null
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** Normalize a ZIP file path, stripping common root directory */
|
|
94
|
+
export function normalizeZipPath(filePath: string, _slug: string): string {
|
|
95
|
+
const normalized = filePath.replace(/\\/g, '/')
|
|
96
|
+
// Strip leading directory that matches the slug or is a common root
|
|
97
|
+
const parts = normalized.split('/')
|
|
98
|
+
if (parts.length > 1) {
|
|
99
|
+
// Remove the first segment if it's a common root
|
|
100
|
+
// ZIPs from ClawHub often have a root folder like "repo-release-notes/"
|
|
101
|
+
return parts.slice(1).join('/')
|
|
102
|
+
}
|
|
103
|
+
return normalized
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** Install a skill from ClawHub */
|
|
107
|
+
export async function installFromClawHub(
|
|
108
|
+
cwd: string,
|
|
109
|
+
slug: string,
|
|
110
|
+
version: string | undefined,
|
|
111
|
+
info: { displayName: string; summary: string; latestVersion: string },
|
|
112
|
+
input: Record<string, unknown>,
|
|
113
|
+
): Promise<ToolResult> {
|
|
114
|
+
const versionToUse = version || info.latestVersion
|
|
115
|
+
|
|
116
|
+
// Download the skill ZIP
|
|
117
|
+
const downloaded = await downloadClawHubSkill(slug, versionToUse)
|
|
118
|
+
if (!downloaded) {
|
|
119
|
+
return {
|
|
120
|
+
success: false,
|
|
121
|
+
output: '',
|
|
122
|
+
error: `Failed to download ClawHub skill "${slug}" (version ${versionToUse}).`,
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const skillsDir = path.resolve(cwd, SKILLS_DIR)
|
|
127
|
+
const skillName = sanitizeSkillName(slug)
|
|
128
|
+
const skillFilePath = path.join(skillsDir, `${skillName}.md`)
|
|
129
|
+
const skillDirPath = path.join(skillsDir, skillName)
|
|
130
|
+
|
|
131
|
+
// Find the SKILL.md in the ZIP
|
|
132
|
+
const skillMdEntry = findSkillMdInZip(downloaded.files)
|
|
133
|
+
|
|
134
|
+
// Also extract supporting files into a subdirectory
|
|
135
|
+
if (skillMdEntry) {
|
|
136
|
+
// Extract all files into skill subdirectory for supporting files
|
|
137
|
+
try {
|
|
138
|
+
fs.mkdirSync(skillDirPath, { recursive: true })
|
|
139
|
+
for (const [filePath, content] of downloaded.files) {
|
|
140
|
+
// Normalize the path: strip common root directory
|
|
141
|
+
const normalizedPath = normalizeZipPath(filePath, slug)
|
|
142
|
+
if (!normalizedPath || normalizedPath === 'SKILL.md') continue // SKILL.md goes to root
|
|
143
|
+
const fullPath = path.join(skillDirPath, normalizedPath)
|
|
144
|
+
fs.mkdirSync(path.dirname(fullPath), { recursive: true })
|
|
145
|
+
fs.writeFileSync(fullPath, content, 'utf-8')
|
|
146
|
+
}
|
|
147
|
+
} catch (err) {
|
|
148
|
+
// Non-critical: supporting files are optional
|
|
149
|
+
console.warn(
|
|
150
|
+
`[install_skill] Warning: could not extract all supporting files: ${fmtErr(err)}`,
|
|
151
|
+
)
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// Generate skill file (using the SKILL.md content from the ZIP)
|
|
155
|
+
const description = (input.description as string) || info.summary || slug
|
|
156
|
+
const skillContent = generateClawHubSkillContent(
|
|
157
|
+
slug,
|
|
158
|
+
info.displayName,
|
|
159
|
+
description,
|
|
160
|
+
skillMdEntry,
|
|
161
|
+
)
|
|
162
|
+
|
|
163
|
+
try {
|
|
164
|
+
fs.mkdirSync(skillsDir, { recursive: true })
|
|
165
|
+
fs.writeFileSync(skillFilePath, skillContent, 'utf-8')
|
|
166
|
+
} catch (err) {
|
|
167
|
+
return {
|
|
168
|
+
success: false,
|
|
169
|
+
output: '',
|
|
170
|
+
error: `Failed to write skill file: ${fmtErr(err)}`,
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
} else {
|
|
174
|
+
// No SKILL.md found in ZIP, generate a wrapper skill
|
|
175
|
+
const description = (input.description as string) || info.summary || slug
|
|
176
|
+
// Collect all extracted content as a markdown reference
|
|
177
|
+
const filesList = Array.from(downloaded.files.keys())
|
|
178
|
+
.map(f => `- ${f}`)
|
|
179
|
+
.join('\n')
|
|
180
|
+
const combinedContent =
|
|
181
|
+
`## Files in this skill\n\n${filesList}\n\n` +
|
|
182
|
+
Array.from(downloaded.files.entries())
|
|
183
|
+
.map(([name, content]) => `### ${name}\n\n\`\`\`\n${content.slice(0, 2000)}\n\`\`\``)
|
|
184
|
+
.join('\n\n')
|
|
185
|
+
|
|
186
|
+
const skillContent = generateClawHubSkillContent(
|
|
187
|
+
slug,
|
|
188
|
+
info.displayName,
|
|
189
|
+
description,
|
|
190
|
+
combinedContent,
|
|
191
|
+
)
|
|
192
|
+
|
|
193
|
+
try {
|
|
194
|
+
fs.mkdirSync(skillsDir, { recursive: true })
|
|
195
|
+
fs.writeFileSync(skillFilePath, skillContent, 'utf-8')
|
|
196
|
+
} catch (err) {
|
|
197
|
+
return {
|
|
198
|
+
success: false,
|
|
199
|
+
output: '',
|
|
200
|
+
error: `Failed to write skill file: ${fmtErr(err)}`,
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
const relPath = path.relative(cwd, skillFilePath).replace(/\\/g, '/')
|
|
206
|
+
const supportRelPath = skillMdEntry ? path.relative(cwd, skillDirPath).replace(/\\/g, '/') : ''
|
|
207
|
+
|
|
208
|
+
let output = `Installed ClawHub skill "${slug}" (v${versionToUse}) and created skill file "${relPath}".`
|
|
209
|
+
if (supportRelPath) {
|
|
210
|
+
output += `\nSupporting files extracted to "${supportRelPath}/".`
|
|
211
|
+
}
|
|
212
|
+
output += `
|
|
213
|
+
|
|
214
|
+
The skill instructions will be loaded automatically on the next turn.
|
|
215
|
+
|
|
216
|
+
To verify: use \`read\` on "${relPath}" to see the skill content.`
|
|
217
|
+
|
|
218
|
+
return {
|
|
219
|
+
success: true,
|
|
220
|
+
output,
|
|
221
|
+
}
|
|
222
|
+
}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import * as fs from 'node:fs'
|
|
2
|
+
import * as path from 'node:path'
|
|
3
|
+
import { fmtErr } from '../errors.js'
|
|
4
|
+
import type { Tool, ToolResult } from '../types.js'
|
|
5
|
+
import { fetchClawHubSkillInfo, installFromClawHub } from './clawhub.js'
|
|
6
|
+
import { SKILLS_DIR } from './constants.js'
|
|
7
|
+
import { fetchNpmPackageInfo, runNpmInstall } from './npm.js'
|
|
8
|
+
import { extractUsageGuide, generateSkillContent, sanitizeSkillName } from './skill-content.js'
|
|
9
|
+
|
|
10
|
+
export function createInstallSkillTool(cwd: string): Tool {
|
|
11
|
+
return {
|
|
12
|
+
definition: {
|
|
13
|
+
name: 'install_skill',
|
|
14
|
+
category: 'Install',
|
|
15
|
+
group: 'Skill',
|
|
16
|
+
description: `Install an npm package or ClawHub skill. This tool:
|
|
17
|
+
1. For npm packages: fetches info from npm registry, runs \`npm install\`, creates a skill file
|
|
18
|
+
2. For ClawHub skills: fetches skill metadata from clawhub.ai, downloads the skill bundle, writes SKILL.md
|
|
19
|
+
|
|
20
|
+
After installation, the skill will be automatically loaded on the next conversation turn (the system prompt includes active skills).
|
|
21
|
+
|
|
22
|
+
Use this when you need to use a third-party npm package or install a skill from ClawHub (clawhub.ai).
|
|
23
|
+
|
|
24
|
+
ClawHub skills: pass the skill slug (e.g. \`repo-release-notes\`) as package_name. The tool auto-detects ClawHub skills.`,
|
|
25
|
+
parameters: {
|
|
26
|
+
package_name: {
|
|
27
|
+
type: 'string',
|
|
28
|
+
description:
|
|
29
|
+
'The npm package name or ClawHub skill slug to install (e.g. "dayjs", "cn-time-parser", "@scope/package", or ClawHub slug like "repo-release-notes")',
|
|
30
|
+
required: true,
|
|
31
|
+
},
|
|
32
|
+
description: {
|
|
33
|
+
type: 'string',
|
|
34
|
+
description:
|
|
35
|
+
'Optional description of what the package/skill does. If not provided, it will be fetched from the npm registry or ClawHub.',
|
|
36
|
+
required: false,
|
|
37
|
+
},
|
|
38
|
+
usage_guide: {
|
|
39
|
+
type: 'string',
|
|
40
|
+
description:
|
|
41
|
+
'Optional custom usage guide for the AI. If not provided, it will be auto-generated from the readme or ClawHub SKILL.md. Provide this if the auto-generated guide is insufficient.',
|
|
42
|
+
required: false,
|
|
43
|
+
},
|
|
44
|
+
clawhub: {
|
|
45
|
+
type: 'boolean',
|
|
46
|
+
description:
|
|
47
|
+
"Force ClawHub mode. If true, treats package_name as a ClawHub skill slug. Auto-detected if the package doesn't exist on npm.",
|
|
48
|
+
required: false,
|
|
49
|
+
},
|
|
50
|
+
version: {
|
|
51
|
+
type: 'string',
|
|
52
|
+
description: 'Optional version for ClawHub skill install (defaults to latest).',
|
|
53
|
+
required: false,
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
async execute(input): Promise<ToolResult> {
|
|
58
|
+
// ── Auto-correction: if input is a string, wrap it ────────────────
|
|
59
|
+
if (typeof input === 'string') {
|
|
60
|
+
input = { package_name: input }
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const packageName = input.package_name as string
|
|
64
|
+
if (!packageName || typeof packageName !== 'string') {
|
|
65
|
+
return {
|
|
66
|
+
success: false,
|
|
67
|
+
output: '',
|
|
68
|
+
error: 'package_name is required (string)',
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const forceClawHub = input.clawhub === true
|
|
73
|
+
const version = input.version as string | undefined
|
|
74
|
+
|
|
75
|
+
// ── Auto-detect: try npm first, fall back to ClawHub ──────────────
|
|
76
|
+
const npmInfo = forceClawHub ? null : await fetchNpmPackageInfo(packageName)
|
|
77
|
+
|
|
78
|
+
// If npm lookup failed and not forced, try ClawHub
|
|
79
|
+
if (!npmInfo && !forceClawHub) {
|
|
80
|
+
const clawhubInfo = await fetchClawHubSkillInfo(packageName)
|
|
81
|
+
if (clawhubInfo) {
|
|
82
|
+
// It's a ClawHub skill — install from ClawHub
|
|
83
|
+
return installFromClawHub(cwd, packageName, version, clawhubInfo, input)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return {
|
|
87
|
+
success: false,
|
|
88
|
+
output: '',
|
|
89
|
+
error: `"${packageName}" was not found on npm registry nor on ClawHub. Check the name and try again.`,
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// If forced ClawHub mode
|
|
94
|
+
if (forceClawHub) {
|
|
95
|
+
const clawhubInfo = await fetchClawHubSkillInfo(packageName)
|
|
96
|
+
if (!clawhubInfo) {
|
|
97
|
+
return {
|
|
98
|
+
success: false,
|
|
99
|
+
output: '',
|
|
100
|
+
error: `"${packageName}" was not found on ClawHub.`,
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return installFromClawHub(cwd, packageName, version, clawhubInfo, input)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// ── npm package install path ──────────────────────────────────────
|
|
107
|
+
const description = (input.description as string) || npmInfo?.description || packageName
|
|
108
|
+
const readme = npmInfo?.readme || ''
|
|
109
|
+
|
|
110
|
+
const installError = await runNpmInstall(cwd, packageName)
|
|
111
|
+
if (installError) {
|
|
112
|
+
return {
|
|
113
|
+
success: false,
|
|
114
|
+
output: '',
|
|
115
|
+
error: `npm install failed: ${installError}`,
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const usageGuide = (input.usage_guide as string) || (readme ? extractUsageGuide(readme) : '')
|
|
120
|
+
|
|
121
|
+
const skillContent = generateSkillContent(packageName, description, usageGuide)
|
|
122
|
+
|
|
123
|
+
const skillsDir = path.resolve(cwd, SKILLS_DIR)
|
|
124
|
+
const skillName = sanitizeSkillName(packageName)
|
|
125
|
+
const skillFilePath = path.join(skillsDir, `${skillName}.md`)
|
|
126
|
+
|
|
127
|
+
try {
|
|
128
|
+
fs.mkdirSync(skillsDir, { recursive: true })
|
|
129
|
+
fs.writeFileSync(skillFilePath, skillContent, 'utf-8')
|
|
130
|
+
} catch (err) {
|
|
131
|
+
return {
|
|
132
|
+
success: false,
|
|
133
|
+
output: '',
|
|
134
|
+
error: `Failed to write skill file: ${fmtErr(err)}`,
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const relPath = path.relative(cwd, skillFilePath).replace(/\\/g, '/')
|
|
139
|
+
|
|
140
|
+
return {
|
|
141
|
+
success: true,
|
|
142
|
+
output: `Installed npm package "${packageName}" and created skill "${relPath}".
|
|
143
|
+
|
|
144
|
+
The package is now a project dependency. The skill file contains usage instructions for the AI and will be loaded automatically on the next turn.
|
|
145
|
+
|
|
146
|
+
To verify: use \`read\` on "${relPath}" to see the skill content.`,
|
|
147
|
+
}
|
|
148
|
+
},
|
|
149
|
+
}
|
|
150
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import * as cp from 'node:child_process'
|
|
2
|
+
import { NPM_REGISTRY_URL } from './constants.js'
|
|
3
|
+
|
|
4
|
+
/** Fetch package info from npm registry */
|
|
5
|
+
export async function fetchNpmPackageInfo(
|
|
6
|
+
packageName: string,
|
|
7
|
+
): Promise<{ description: string; readme: string } | null> {
|
|
8
|
+
try {
|
|
9
|
+
const response = await fetch(`${NPM_REGISTRY_URL}/${encodeURIComponent(packageName)}`, {
|
|
10
|
+
headers: { Accept: 'application/json' },
|
|
11
|
+
})
|
|
12
|
+
if (!response.ok) return null
|
|
13
|
+
|
|
14
|
+
const data = (await response.json()) as {
|
|
15
|
+
description?: string
|
|
16
|
+
readme?: string
|
|
17
|
+
}
|
|
18
|
+
return {
|
|
19
|
+
description: data.description || '',
|
|
20
|
+
readme: data.readme || '',
|
|
21
|
+
}
|
|
22
|
+
} catch {
|
|
23
|
+
return null
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Run npm install in the project directory */
|
|
28
|
+
export async function runNpmInstall(cwd: string, packageName: string): Promise<string | null> {
|
|
29
|
+
return new Promise(resolve => {
|
|
30
|
+
const child = cp.spawn('npm', ['install', packageName], {
|
|
31
|
+
cwd,
|
|
32
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
33
|
+
shell: process.platform === 'win32',
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
let stderr = ''
|
|
37
|
+
child.stderr?.on('data', (data: Buffer) => {
|
|
38
|
+
stderr += data.toString()
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
const timeout = setTimeout(() => {
|
|
42
|
+
child.kill()
|
|
43
|
+
resolve(`Timed out after 60s. ${stderr.slice(0, 500)}`)
|
|
44
|
+
}, 60_000)
|
|
45
|
+
|
|
46
|
+
child.on('close', code => {
|
|
47
|
+
clearTimeout(timeout)
|
|
48
|
+
if (code === 0) {
|
|
49
|
+
resolve(null) // success
|
|
50
|
+
} else {
|
|
51
|
+
resolve(stderr.slice(0, 500) || `npm install exited with code ${code}`)
|
|
52
|
+
}
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
child.on('error', err => {
|
|
56
|
+
clearTimeout(timeout)
|
|
57
|
+
resolve(`Failed to start npm install: ${err.message}`)
|
|
58
|
+
})
|
|
59
|
+
})
|
|
60
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { CLAWHUB_SITE } from './constants.js'
|
|
2
|
+
|
|
3
|
+
/** Sanitize a package name to a valid skill name (lowercase, digits, hyphens) */
|
|
4
|
+
export function sanitizeSkillName(name: string): string {
|
|
5
|
+
return name
|
|
6
|
+
.toLowerCase()
|
|
7
|
+
.replace(/@/g, '')
|
|
8
|
+
.replace(/\//g, '-')
|
|
9
|
+
.replace(/[^a-z0-9-]/g, '')
|
|
10
|
+
.replace(/-+/g, '-')
|
|
11
|
+
.replace(/^-|-$/g, '')
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** Generate a usage guide snippet from the readme */
|
|
15
|
+
export function extractUsageGuide(readme: string): string {
|
|
16
|
+
// Try to extract code examples from the readme
|
|
17
|
+
const codeBlocks: string[] = []
|
|
18
|
+
const blockRegex = /```(?:js|javascript|ts|typescript|bash)\n([\s\S]*?)```/g
|
|
19
|
+
let match: RegExpExecArray | null = blockRegex.exec(readme)
|
|
20
|
+
while (match !== null) {
|
|
21
|
+
const block = match[1].trim()
|
|
22
|
+
if (block.length > 0 && block.length < 1000) {
|
|
23
|
+
codeBlocks.push(block)
|
|
24
|
+
}
|
|
25
|
+
match = blockRegex.exec(readme)
|
|
26
|
+
}
|
|
27
|
+
return codeBlocks.slice(0, 3).join('\n\n')
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Generate the skill markdown content (npm package) */
|
|
31
|
+
export function generateSkillContent(
|
|
32
|
+
packageName: string,
|
|
33
|
+
description: string,
|
|
34
|
+
usageGuide: string,
|
|
35
|
+
): string {
|
|
36
|
+
const installCmd = `npm install ${packageName}`
|
|
37
|
+
|
|
38
|
+
let content = `---
|
|
39
|
+
name: ${sanitizeSkillName(packageName)}
|
|
40
|
+
description: ${description}
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
# ${packageName}
|
|
44
|
+
|
|
45
|
+
${description}
|
|
46
|
+
|
|
47
|
+
## Installation
|
|
48
|
+
|
|
49
|
+
This package is already installed in the project via \`${installCmd}\`.
|
|
50
|
+
|
|
51
|
+
## Usage
|
|
52
|
+
|
|
53
|
+
You can import and use this package in your code:
|
|
54
|
+
|
|
55
|
+
\`\`\`typescript
|
|
56
|
+
import ${packageName.replace(/@/, '').replace(/[/-]/g, '_')} from '${packageName}'
|
|
57
|
+
\`\`\`
|
|
58
|
+
`
|
|
59
|
+
|
|
60
|
+
if (usageGuide) {
|
|
61
|
+
content += `\n## Examples\n\n${usageGuide}\n`
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
content += `
|
|
65
|
+
## Notes
|
|
66
|
+
|
|
67
|
+
- This skill was automatically installed. The package is available as a project dependency.
|
|
68
|
+
- Refer to the package's npm page or repository for full documentation.
|
|
69
|
+
`
|
|
70
|
+
|
|
71
|
+
return content
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** Generate the skill markdown content (ClawHub skill) */
|
|
75
|
+
export function generateClawHubSkillContent(
|
|
76
|
+
slug: string,
|
|
77
|
+
displayName: string,
|
|
78
|
+
summary: string,
|
|
79
|
+
clawhubContent: string,
|
|
80
|
+
): string {
|
|
81
|
+
// If the ZIP contains a SKILL.md, use it directly
|
|
82
|
+
// Otherwise, generate a wrapper skill file
|
|
83
|
+
let content = `---
|
|
84
|
+
name: ${sanitizeSkillName(slug)}
|
|
85
|
+
description: ${summary || displayName}
|
|
86
|
+
clawhub: ${slug}
|
|
87
|
+
---
|
|
88
|
+
|
|
89
|
+
# ${displayName}
|
|
90
|
+
|
|
91
|
+
${summary || `ClawHub skill: ${slug}`}
|
|
92
|
+
|
|
93
|
+
`
|
|
94
|
+
|
|
95
|
+
if (clawhubContent) {
|
|
96
|
+
content += `${clawhubContent}\n`
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
content += `
|
|
100
|
+
## Notes
|
|
101
|
+
|
|
102
|
+
- This skill was installed from [ClawHub](${CLAWHUB_SITE}/${slug}).
|
|
103
|
+
- Source: ${CLAWHUB_SITE}/${slug}
|
|
104
|
+
- The skill instructions are loaded automatically on the next turn.
|
|
105
|
+
`
|
|
106
|
+
|
|
107
|
+
return content
|
|
108
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import * as fs from 'node:fs'
|
|
2
|
+
import * as path from 'node:path'
|
|
3
|
+
import { fmtErr } from '../errors.js'
|
|
4
|
+
import type { Tool, ToolResult } from '../types.js'
|
|
5
|
+
|
|
6
|
+
export function createDeleteMemoryTool(cwd: string): Tool {
|
|
7
|
+
return {
|
|
8
|
+
definition: {
|
|
9
|
+
name: 'delete_memory',
|
|
10
|
+
category: 'Memory',
|
|
11
|
+
group: 'Manage',
|
|
12
|
+
description:
|
|
13
|
+
'Delete a memory entry by id or filename under .lonny/memory (id or file parameter)',
|
|
14
|
+
parameters: {
|
|
15
|
+
id: {
|
|
16
|
+
type: 'string',
|
|
17
|
+
description: 'Memory id (filename without .json) or relative filename',
|
|
18
|
+
required: true,
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
async execute(input): Promise<ToolResult> {
|
|
23
|
+
try {
|
|
24
|
+
const id = (input as any).id || input
|
|
25
|
+
if (typeof id !== 'string' || !id)
|
|
26
|
+
return { success: false, output: '', error: 'id is required (string)' }
|
|
27
|
+
const dir = path.resolve(cwd, '.lonny', 'memory')
|
|
28
|
+
const candidates = [id, `${id}.json`]
|
|
29
|
+
for (const c of candidates) {
|
|
30
|
+
const p = path.join(dir, c)
|
|
31
|
+
try {
|
|
32
|
+
if (fs.existsSync(p)) {
|
|
33
|
+
fs.unlinkSync(p)
|
|
34
|
+
return { success: true, output: `Deleted memory ${c}` }
|
|
35
|
+
}
|
|
36
|
+
} catch (e) {
|
|
37
|
+
return { success: false, output: '', error: fmtErr(e) }
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return { success: false, output: '', error: `Memory not found: ${id}` }
|
|
41
|
+
} catch (err) {
|
|
42
|
+
return { success: false, output: '', error: fmtErr(err) }
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import * as fs from 'node:fs'
|
|
2
|
+
import * as path from 'node:path'
|
|
3
|
+
import { fmtErr } from '../errors.js'
|
|
4
|
+
import type { Tool, ToolResult } from '../types.js'
|
|
5
|
+
|
|
6
|
+
export function createListMemoryTool(cwd: string): Tool {
|
|
7
|
+
return {
|
|
8
|
+
definition: {
|
|
9
|
+
name: 'list_memory',
|
|
10
|
+
category: 'Memory',
|
|
11
|
+
group: 'Query',
|
|
12
|
+
description: 'List memory entries stored under .lonny/memory (optional limit param)',
|
|
13
|
+
parameters: {
|
|
14
|
+
limit: {
|
|
15
|
+
type: 'number',
|
|
16
|
+
description: 'Maximum number of entries to return',
|
|
17
|
+
required: false,
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
async execute(input): Promise<ToolResult> {
|
|
22
|
+
try {
|
|
23
|
+
const limit = typeof (input as any).limit === 'number' ? (input as any).limit : undefined
|
|
24
|
+
const dir = path.resolve(cwd, '.lonny', 'memory')
|
|
25
|
+
if (!fs.existsSync(dir)) return { success: true, output: 'No memories found' }
|
|
26
|
+
const files = fs.readdirSync(dir).filter(f => f.endsWith('.json'))
|
|
27
|
+
const entries: { id: string; createdAt: string; preview: string; tags?: string[] }[] = []
|
|
28
|
+
for (const f of files) {
|
|
29
|
+
try {
|
|
30
|
+
const data = JSON.parse(fs.readFileSync(path.join(dir, f), 'utf-8'))
|
|
31
|
+
entries.push({
|
|
32
|
+
id: data.id || f.replace(/\.json$/, ''),
|
|
33
|
+
createdAt: data.createdAt || '',
|
|
34
|
+
preview: (data.content || '').replace(/\n/g, ' ').slice(0, 200),
|
|
35
|
+
tags: Array.isArray(data.tags) ? data.tags : undefined,
|
|
36
|
+
})
|
|
37
|
+
} catch {
|
|
38
|
+
// ignore corrupted
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
// sort by createdAt desc
|
|
42
|
+
entries.sort((a, b) => (a.createdAt < b.createdAt ? 1 : -1))
|
|
43
|
+
const out = entries.slice(0, limit || entries.length).map(e => {
|
|
44
|
+
const tagStr = e.tags ? ` [tags: ${e.tags.join(',')}]` : ''
|
|
45
|
+
return `${e.id} ${e.createdAt} ${e.preview}${tagStr}`
|
|
46
|
+
})
|
|
47
|
+
return { success: true, output: out.join('\n') }
|
|
48
|
+
} catch (err) {
|
|
49
|
+
return { success: false, output: '', error: fmtErr(err) }
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import * as fs from 'node:fs'
|
|
2
|
+
import * as path from 'node:path'
|
|
3
|
+
import { fmtErr } from '../errors.js'
|
|
4
|
+
import type { Tool, ToolResult } from '../types.js'
|
|
5
|
+
|
|
6
|
+
export function createSaveMemoryTool(cwd: string): Tool {
|
|
7
|
+
return {
|
|
8
|
+
definition: {
|
|
9
|
+
name: 'save_memory',
|
|
10
|
+
category: 'Memory',
|
|
11
|
+
group: 'Write',
|
|
12
|
+
description:
|
|
13
|
+
'Save a memory entry to .lonny/memory as a JSON file (content: string, tags?: string[])',
|
|
14
|
+
parameters: {
|
|
15
|
+
content: { type: 'string', description: 'Memory text', required: true },
|
|
16
|
+
tags: { type: 'array', description: 'Optional tags', required: false },
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
async execute(input): Promise<ToolResult> {
|
|
20
|
+
try {
|
|
21
|
+
const content = (input as any).content || input
|
|
22
|
+
const tags = (input as any).tags
|
|
23
|
+
if (typeof content !== 'string' || !content) {
|
|
24
|
+
return { success: false, output: '', error: 'content is required (string)' }
|
|
25
|
+
}
|
|
26
|
+
const id = String(Date.now()) + '-' + Math.random().toString(36).slice(2, 8)
|
|
27
|
+
const entry = {
|
|
28
|
+
id,
|
|
29
|
+
createdAt: new Date().toISOString(),
|
|
30
|
+
content,
|
|
31
|
+
tags: Array.isArray(tags) ? tags : undefined,
|
|
32
|
+
}
|
|
33
|
+
const dir = path.resolve(cwd, '.lonny', 'memory')
|
|
34
|
+
try {
|
|
35
|
+
fs.mkdirSync(dir, { recursive: true })
|
|
36
|
+
} catch {}
|
|
37
|
+
const file = path.join(dir, `${id}.json`)
|
|
38
|
+
fs.writeFileSync(file, JSON.stringify(entry, null, 2), 'utf-8')
|
|
39
|
+
return { success: true, output: `Saved memory ${id}` }
|
|
40
|
+
} catch (err) {
|
|
41
|
+
return { success: false, output: '', error: fmtErr(err) }
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
}
|
|
45
|
+
}
|