goatcode-sh 0.0.1 → 0.1.2
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 +85 -0
- package/.github/workflows/release.yml +107 -0
- package/.opencode/plugins/goatcode.js +1 -0
- package/AGENTS.md +59 -0
- package/CONTRIBUTING.md +110 -0
- package/LICENSE +21 -0
- package/README.md +106 -12
- package/bun.lock +2081 -0
- package/bunfig.toml +3 -0
- package/dist/agents/advisor/config.d.ts +4 -0
- package/dist/agents/advisor/index.d.ts +2 -0
- package/dist/agents/advisor/plugin.d.ts +1 -0
- package/dist/agents/advisor/prompt-meta.d.ts +2 -0
- package/dist/agents/advisor/prompt.d.ts +1 -0
- package/dist/agents/agent-builder.d.ts +10 -0
- package/dist/agents/agent-registry.d.ts +8 -0
- package/dist/agents/builtin-agents.d.ts +2 -0
- package/dist/agents/deep-worker/config.d.ts +4 -0
- package/dist/agents/deep-worker/index.d.ts +2 -0
- package/dist/agents/deep-worker/plugin.d.ts +1 -0
- package/dist/agents/deep-worker/prompt-meta.d.ts +2 -0
- package/dist/agents/deep-worker/prompt.d.ts +1 -0
- package/dist/agents/explorer/config.d.ts +4 -0
- package/dist/agents/explorer/index.d.ts +2 -0
- package/dist/agents/explorer/plugin.d.ts +1 -0
- package/dist/agents/explorer/prompt-meta.d.ts +2 -0
- package/dist/agents/explorer/prompt.d.ts +1 -0
- package/dist/agents/fallback-chains.d.ts +2 -0
- package/dist/agents/index.d.ts +14 -0
- package/dist/agents/orchestrator/config.d.ts +4 -0
- package/dist/agents/orchestrator/index.d.ts +2 -0
- package/dist/agents/orchestrator/plugin.d.ts +1 -0
- package/dist/agents/orchestrator/prompt-meta.d.ts +2 -0
- package/dist/agents/orchestrator/prompt.d.ts +1 -0
- package/dist/agents/planner/config.d.ts +4 -0
- package/dist/agents/planner/index.d.ts +2 -0
- package/dist/agents/planner/plugin.d.ts +1 -0
- package/dist/agents/planner/prompt-meta.d.ts +2 -0
- package/dist/agents/planner/prompt.d.ts +1 -0
- package/dist/agents/prompt-meta.d.ts +11 -0
- package/dist/agents/prompt-registry.d.ts +4 -0
- package/dist/agents/researcher/config.d.ts +4 -0
- package/dist/agents/researcher/index.d.ts +2 -0
- package/dist/agents/researcher/plugin.d.ts +1 -0
- package/dist/agents/researcher/prompt-meta.d.ts +2 -0
- package/dist/agents/researcher/prompt.d.ts +1 -0
- package/dist/agents/tool-restrictions.d.ts +7 -0
- package/dist/agents/worker/config.d.ts +4 -0
- package/dist/agents/worker/index.d.ts +2 -0
- package/dist/agents/worker/plugin.d.ts +1 -0
- package/dist/agents/worker/prompt-meta.d.ts +2 -0
- package/dist/agents/worker/prompt.d.ts +1 -0
- package/dist/bootstrap.d.ts +3 -0
- package/dist/cli/cli.d.ts +3 -0
- package/dist/cli/commands/install.d.ts +12 -0
- package/dist/cli/commands/update.d.ts +1 -0
- package/dist/cli/config-generator.d.ts +26 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/config/defaults.d.ts +3 -0
- package/dist/config/define-config.d.ts +27 -0
- package/dist/config/index.d.ts +6 -0
- package/dist/config/loader.d.ts +3 -0
- package/dist/config/paths.d.ts +4 -0
- package/dist/config/schema.d.ts +273 -0
- package/dist/config/validator.d.ts +9 -0
- package/dist/features/auto-update/index.d.ts +3 -0
- package/dist/features/auto-update/plugin.d.ts +2 -0
- package/dist/features/auto-update/update-checker.d.ts +7 -0
- package/dist/features/background-agent/concurrency.d.ts +10 -0
- package/dist/features/background-agent/index.d.ts +6 -0
- package/dist/features/background-agent/manager.d.ts +18 -0
- package/dist/features/background-agent/poller.d.ts +17 -0
- package/dist/features/background-agent/singleton.d.ts +7 -0
- package/dist/features/background-agent/spawner.d.ts +6 -0
- package/dist/features/background-agent/types.d.ts +18 -0
- package/dist/features/builtin-features.d.ts +2 -0
- package/dist/features/categories/category-config.d.ts +9 -0
- package/dist/features/categories/category-resolver.d.ts +6 -0
- package/dist/features/categories/index.d.ts +3 -0
- package/dist/features/categories/prompt-appends.d.ts +10 -0
- package/dist/features/loops/file-store.d.ts +22 -0
- package/dist/features/loops/handler.d.ts +9 -0
- package/dist/features/loops/index.d.ts +5 -0
- package/dist/features/loops/memory-store.d.ts +11 -0
- package/dist/features/loops/plugin.d.ts +34 -0
- package/dist/features/loops/shared/event-utils.d.ts +7 -0
- package/dist/features/loops/state.d.ts +22 -0
- package/dist/features/prompt-builder/agent-table-builder.d.ts +6 -0
- package/dist/features/prompt-builder/category-section-builder.d.ts +2 -0
- package/dist/features/prompt-builder/dynamic-prompt-builder.d.ts +9 -0
- package/dist/features/prompt-builder/index.d.ts +7 -0
- package/dist/features/prompt-builder/skill-section-builder.d.ts +5 -0
- package/dist/features/session-state/index.d.ts +5 -0
- package/dist/features/session-state/session-cursor.d.ts +13 -0
- package/dist/features/session-state/session-store.d.ts +12 -0
- package/dist/features/session-state/session-tools-store.d.ts +4 -0
- package/dist/features/skills/builtin/git-master.d.ts +2 -0
- package/dist/features/skills/index.d.ts +10 -0
- package/dist/features/skills/skill-loader.d.ts +22 -0
- package/dist/features/skills/skill-merger.d.ts +2 -0
- package/dist/features/slash-commands/command-registry.d.ts +3 -0
- package/dist/features/slash-commands/commands/cancel-loop.d.ts +2 -0
- package/dist/features/slash-commands/commands/handoff.d.ts +2 -0
- package/dist/features/slash-commands/commands/init-deep.d.ts +2 -0
- package/dist/features/slash-commands/commands/loop.d.ts +2 -0
- package/dist/features/slash-commands/commands/start-work.d.ts +2 -0
- package/dist/features/slash-commands/commands/stop-continuation.d.ts +2 -0
- package/dist/features/slash-commands/index.d.ts +2 -0
- package/dist/features/slash-commands/types.d.ts +5 -0
- package/dist/hooks/anthropic-effort/handler.d.ts +5 -0
- package/dist/hooks/anthropic-effort/index.d.ts +3 -0
- package/dist/hooks/anthropic-effort/plugin.d.ts +1 -0
- package/dist/hooks/builtin-hooks.d.ts +2 -0
- package/dist/hooks/comment-checker/handler.d.ts +5 -0
- package/dist/hooks/comment-checker/index.d.ts +2 -0
- package/dist/hooks/comment-checker/plugin.d.ts +1 -0
- package/dist/hooks/compaction-context/handler.d.ts +2 -0
- package/dist/hooks/compaction-context/index.d.ts +2 -0
- package/dist/hooks/compaction-context/plugin.d.ts +1 -0
- package/dist/hooks/compaction-todo-preserver/handler.d.ts +4 -0
- package/dist/hooks/compaction-todo-preserver/index.d.ts +2 -0
- package/dist/hooks/compaction-todo-preserver/plugin.d.ts +1 -0
- package/dist/hooks/context-injector/handlers/agents.d.ts +1 -0
- package/dist/hooks/context-injector/handlers/readme.d.ts +1 -0
- package/dist/hooks/context-injector/handlers/rules.d.ts +1 -0
- package/dist/hooks/context-injector/index.d.ts +4 -0
- package/dist/hooks/context-injector/plugin.d.ts +1 -0
- package/dist/hooks/context-window-limit/handler.d.ts +6 -0
- package/dist/hooks/context-window-limit/index.d.ts +2 -0
- package/dist/hooks/context-window-limit/plugin.d.ts +1 -0
- package/dist/hooks/delegate-retry/handler.d.ts +16 -0
- package/dist/hooks/delegate-retry/index.d.ts +3 -0
- package/dist/hooks/delegate-retry/plugin.d.ts +1 -0
- package/dist/hooks/edit-error/handler.d.ts +6 -0
- package/dist/hooks/edit-error/index.d.ts +2 -0
- package/dist/hooks/edit-error/plugin.d.ts +1 -0
- package/dist/hooks/empty-response-detector/handler.d.ts +5 -0
- package/dist/hooks/empty-response-detector/index.d.ts +2 -0
- package/dist/hooks/empty-response-detector/plugin.d.ts +1 -0
- package/dist/hooks/error-diagnostics/handler.d.ts +6 -0
- package/dist/hooks/error-diagnostics/patterns.d.ts +3 -0
- package/dist/hooks/error-diagnostics/plugin.d.ts +1 -0
- package/dist/hooks/error-diagnostics/types.d.ts +14 -0
- package/dist/hooks/foreground-fallback/handler.d.ts +22 -0
- package/dist/hooks/foreground-fallback/index.d.ts +2 -0
- package/dist/hooks/foreground-fallback/plugin.d.ts +1 -0
- package/dist/hooks/hashline-diff-enhancer/handler.d.ts +28 -0
- package/dist/hooks/hashline-diff-enhancer/index.d.ts +2 -0
- package/dist/hooks/hashline-diff-enhancer/plugin.d.ts +1 -0
- package/dist/hooks/hashline-read-enhancer/handler.d.ts +4 -0
- package/dist/hooks/hashline-read-enhancer/index.d.ts +2 -0
- package/dist/hooks/hashline-read-enhancer/plugin.d.ts +1 -0
- package/dist/hooks/hook-composer.d.ts +4 -0
- package/dist/hooks/hook-ordering.d.ts +9 -0
- package/dist/hooks/hook-types.d.ts +3 -0
- package/dist/hooks/index.d.ts +6 -0
- package/dist/hooks/json-error/handler.d.ts +6 -0
- package/dist/hooks/json-error/index.d.ts +2 -0
- package/dist/hooks/json-error/plugin.d.ts +1 -0
- package/dist/hooks/keyword-detector/handler.d.ts +8 -0
- package/dist/hooks/keyword-detector/index.d.ts +3 -0
- package/dist/hooks/keyword-detector/plugin.d.ts +1 -0
- package/dist/hooks/model-fallback/handler.d.ts +21 -0
- package/dist/hooks/model-fallback/index.d.ts +2 -0
- package/dist/hooks/model-fallback/plugin.d.ts +1 -0
- package/dist/hooks/phase-reminder/handler.d.ts +5 -0
- package/dist/hooks/phase-reminder/index.d.ts +2 -0
- package/dist/hooks/phase-reminder/plugin.d.ts +1 -0
- package/dist/hooks/post-read-nudge/handler.d.ts +5 -0
- package/dist/hooks/post-read-nudge/index.d.ts +2 -0
- package/dist/hooks/post-read-nudge/plugin.d.ts +1 -0
- package/dist/hooks/preemptive-compaction/handler.d.ts +31 -0
- package/dist/hooks/preemptive-compaction/index.d.ts +2 -0
- package/dist/hooks/preemptive-compaction/plugin.d.ts +1 -0
- package/dist/hooks/runtime-fallback/handler.d.ts +21 -0
- package/dist/hooks/runtime-fallback/index.d.ts +2 -0
- package/dist/hooks/runtime-fallback/plugin.d.ts +1 -0
- package/dist/hooks/safe-hook-wrapper.d.ts +2 -0
- package/dist/hooks/session-recovery/handler.d.ts +6 -0
- package/dist/hooks/session-recovery/index.d.ts +2 -0
- package/dist/hooks/session-recovery/plugin.d.ts +1 -0
- package/dist/hooks/skill-discovery/plugin.d.ts +1 -0
- package/dist/hooks/stop-guard/handler.d.ts +4 -0
- package/dist/hooks/stop-guard/index.d.ts +2 -0
- package/dist/hooks/stop-guard/plugin.d.ts +1 -0
- package/dist/hooks/task-resume-info/handler.d.ts +4 -0
- package/dist/hooks/task-resume-info/index.d.ts +2 -0
- package/dist/hooks/task-resume-info/plugin.d.ts +1 -0
- package/dist/hooks/think-mode/handler.d.ts +4 -0
- package/dist/hooks/think-mode/index.d.ts +2 -0
- package/dist/hooks/think-mode/plugin.d.ts +1 -0
- package/dist/hooks/thinking-block-validator/handler.d.ts +4 -0
- package/dist/hooks/thinking-block-validator/index.d.ts +2 -0
- package/dist/hooks/thinking-block-validator/plugin.d.ts +1 -0
- package/dist/hooks/todo-enforcer/handler.d.ts +4 -0
- package/dist/hooks/todo-enforcer/index.d.ts +2 -0
- package/dist/hooks/todo-enforcer/plugin.d.ts +1 -0
- package/dist/hooks/todowrite-disabler/handler.d.ts +6 -0
- package/dist/hooks/todowrite-disabler/index.d.ts +2 -0
- package/dist/hooks/todowrite-disabler/plugin.d.ts +1 -0
- package/dist/hooks/tool-output-truncator/handler.d.ts +4 -0
- package/dist/hooks/tool-output-truncator/index.d.ts +2 -0
- package/dist/hooks/tool-output-truncator/plugin.d.ts +1 -0
- package/dist/hooks/write-file-guard/handler.d.ts +7 -0
- package/dist/hooks/write-file-guard/index.d.ts +2 -0
- package/dist/hooks/write-file-guard/plugin.d.ts +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +8547 -0
- package/dist/plugin/compositor.d.ts +9 -0
- package/dist/plugin/index.d.ts +1 -0
- package/dist/plugin-api/define-plugin.d.ts +33 -0
- package/dist/plugin-api/index.d.ts +3 -0
- package/dist/plugin-api/types.d.ts +10 -0
- package/dist/registry/agent-aggregator.d.ts +3 -0
- package/dist/registry/contribution-aggregator.d.ts +10 -0
- package/dist/registry/dependency-resolver.d.ts +3 -0
- package/dist/registry/hook-aggregator.d.ts +2 -0
- package/dist/registry/index.d.ts +6 -0
- package/dist/registry/plugin-registry.d.ts +16 -0
- package/dist/registry/tool-aggregator.d.ts +3 -0
- package/dist/registry/types.d.ts +9 -0
- package/dist/runtime/index.d.ts +7 -0
- package/dist/shared/data-path.d.ts +4 -0
- package/dist/shared/deep-merge.d.ts +13 -0
- package/dist/shared/fallback-chain.d.ts +1 -0
- package/dist/shared/index.d.ts +19 -0
- package/dist/shared/logger.d.ts +4 -0
- package/dist/shared/model-availability.d.ts +1 -0
- package/dist/shared/model-normalization.d.ts +6 -0
- package/dist/shared/model-prefix-map.d.ts +11 -0
- package/dist/shared/model-resolution-pipeline.d.ts +14 -0
- package/dist/shared/models-dev.d.ts +29 -0
- package/dist/shared/provider-discovery.d.ts +28 -0
- package/dist/shared/provider-registry.d.ts +16 -0
- package/dist/shared/safe-create-hook.d.ts +3 -0
- package/dist/shared/snake-case.d.ts +1 -0
- package/dist/shared/truncate-description.d.ts +1 -0
- package/dist/test-utils/index.d.ts +6 -0
- package/dist/test-utils/mock-agent-config.d.ts +5 -0
- package/dist/test-utils/mock-hook-inputs.d.ts +20 -0
- package/dist/test-utils/mock-hook-outputs.d.ts +20 -0
- package/dist/test-utils/mock-plugin-context.d.ts +6 -0
- package/dist/test-utils/mock-sdk-client.d.ts +41 -0
- package/dist/test-utils/mock-tool-context.d.ts +6 -0
- package/dist/tools/ast-grep/index.d.ts +4 -0
- package/dist/tools/ast-grep/replace/handler.d.ts +7 -0
- package/dist/tools/ast-grep/replace/plugin.d.ts +1 -0
- package/dist/tools/ast-grep/replace/types.d.ts +37 -0
- package/dist/tools/ast-grep/search/handler.d.ts +14 -0
- package/dist/tools/ast-grep/search/plugin.d.ts +1 -0
- package/dist/tools/ast-grep/search/types.d.ts +37 -0
- package/dist/tools/background-task/cancel/handler.d.ts +4 -0
- package/dist/tools/background-task/cancel/plugin.d.ts +2 -0
- package/dist/tools/background-task/cancel/types.d.ts +4 -0
- package/dist/tools/background-task/index.d.ts +2 -0
- package/dist/tools/background-task/output/handler.d.ts +3 -0
- package/dist/tools/background-task/output/plugin.d.ts +2 -0
- package/dist/tools/background-task/output/types.d.ts +11 -0
- package/dist/tools/bridge.d.ts +7 -0
- package/dist/tools/builtin-tools.d.ts +2 -0
- package/dist/tools/delegate-task/category-resolver.d.ts +4 -0
- package/dist/tools/delegate-task/constants.d.ts +3 -0
- package/dist/tools/delegate-task/executor.d.ts +10 -0
- package/dist/tools/delegate-task/handler.d.ts +3 -0
- package/dist/tools/delegate-task/index.d.ts +7 -0
- package/dist/tools/delegate-task/plugin.d.ts +2 -0
- package/dist/tools/delegate-task/types.d.ts +17 -0
- package/dist/tools/glob/handler.d.ts +7 -0
- package/dist/tools/glob/index.d.ts +2 -0
- package/dist/tools/glob/plugin.d.ts +1 -0
- package/dist/tools/glob/types.d.ts +7 -0
- package/dist/tools/grep/handler.d.ts +13 -0
- package/dist/tools/grep/index.d.ts +2 -0
- package/dist/tools/grep/plugin.d.ts +1 -0
- package/dist/tools/grep/types.d.ts +15 -0
- package/dist/tools/hashline-edit/constants.d.ts +4 -0
- package/dist/tools/hashline-edit/edit-operations.d.ts +4 -0
- package/dist/tools/hashline-edit/handler.d.ts +5 -0
- package/dist/tools/hashline-edit/hash-computation.d.ts +2 -0
- package/dist/tools/hashline-edit/index.d.ts +5 -0
- package/dist/tools/hashline-edit/plugin.d.ts +3 -0
- package/dist/tools/hashline-edit/types.d.ts +21 -0
- package/dist/tools/index.d.ts +4 -0
- package/dist/tools/look-at/handler.d.ts +6 -0
- package/dist/tools/look-at/index.d.ts +3 -0
- package/dist/tools/look-at/plugin.d.ts +1 -0
- package/dist/tools/look-at/types.d.ts +9 -0
- package/dist/tools/lsp/client.d.ts +7 -0
- package/dist/tools/lsp/diagnostics/handler.d.ts +2 -0
- package/dist/tools/lsp/diagnostics/plugin.d.ts +1 -0
- package/dist/tools/lsp/diagnostics/types.d.ts +13 -0
- package/dist/tools/lsp/find-references/handler.d.ts +2 -0
- package/dist/tools/lsp/find-references/plugin.d.ts +1 -0
- package/dist/tools/lsp/find-references/types.d.ts +8 -0
- package/dist/tools/lsp/goto-definition/handler.d.ts +2 -0
- package/dist/tools/lsp/goto-definition/plugin.d.ts +1 -0
- package/dist/tools/lsp/goto-definition/types.d.ts +7 -0
- package/dist/tools/lsp/index.d.ts +6 -0
- package/dist/tools/lsp/prepare-rename/handler.d.ts +2 -0
- package/dist/tools/lsp/prepare-rename/plugin.d.ts +1 -0
- package/dist/tools/lsp/prepare-rename/types.d.ts +7 -0
- package/dist/tools/lsp/rename/handler.d.ts +2 -0
- package/dist/tools/lsp/rename/plugin.d.ts +1 -0
- package/dist/tools/lsp/rename/types.d.ts +8 -0
- package/dist/tools/lsp/symbols/handler.d.ts +2 -0
- package/dist/tools/lsp/symbols/plugin.d.ts +1 -0
- package/dist/tools/lsp/symbols/types.d.ts +11 -0
- package/dist/tools/session-manager/client-context.d.ts +3 -0
- package/dist/tools/session-manager/index.d.ts +5 -0
- package/dist/tools/session-manager/info/handler.d.ts +3 -0
- package/dist/tools/session-manager/info/plugin.d.ts +1 -0
- package/dist/tools/session-manager/info/types.d.ts +3 -0
- package/dist/tools/session-manager/list/handler.d.ts +3 -0
- package/dist/tools/session-manager/list/plugin.d.ts +1 -0
- package/dist/tools/session-manager/list/types.d.ts +6 -0
- package/dist/tools/session-manager/read/handler.d.ts +3 -0
- package/dist/tools/session-manager/read/plugin.d.ts +1 -0
- package/dist/tools/session-manager/read/types.d.ts +6 -0
- package/dist/tools/session-manager/search/handler.d.ts +3 -0
- package/dist/tools/session-manager/search/plugin.d.ts +1 -0
- package/dist/tools/session-manager/search/types.d.ts +6 -0
- package/dist/tools/session-manager/session-formatter.d.ts +29 -0
- package/dist/tools/session-manager/types.d.ts +36 -0
- package/dist/tools/shared/constants.d.ts +3 -0
- package/dist/tools/skill/handler.d.ts +4 -0
- package/dist/tools/skill/index.d.ts +3 -0
- package/dist/tools/skill/plugin.d.ts +1 -0
- package/dist/tools/skill/types.d.ts +12 -0
- package/dist/tools/skill-mcp/handler.d.ts +5 -0
- package/dist/tools/skill-mcp/index.d.ts +3 -0
- package/dist/tools/skill-mcp/plugin.d.ts +1 -0
- package/dist/tools/skill-mcp/types.d.ts +13 -0
- package/dist/tools/task/create/handler.d.ts +2 -0
- package/dist/tools/task/create/plugin.d.ts +1 -0
- package/dist/tools/task/format-task.d.ts +2 -0
- package/dist/tools/task/get/handler.d.ts +2 -0
- package/dist/tools/task/get/plugin.d.ts +1 -0
- package/dist/tools/task/index.d.ts +4 -0
- package/dist/tools/task/list/handler.d.ts +2 -0
- package/dist/tools/task/list/plugin.d.ts +1 -0
- package/dist/tools/task/storage.d.ts +7 -0
- package/dist/tools/task/types.d.ts +84 -0
- package/dist/tools/task/update/handler.d.ts +2 -0
- package/dist/tools/task/update/plugin.d.ts +1 -0
- package/dist/tools/tool-builder.d.ts +7 -0
- package/dist/tools/tool-registry-adapter.d.ts +3 -0
- package/dist/types/agent.d.ts +40 -0
- package/dist/types/category.d.ts +22 -0
- package/dist/types/config.d.ts +23 -0
- package/dist/types/hook.d.ts +18 -0
- package/dist/types/index.d.ts +12 -0
- package/dist/types/plugin.d.ts +41 -0
- package/dist/types/tool.d.ts +7 -0
- package/eval/README.md +160 -0
- package/eval/ablation-config.yaml +43 -0
- package/eval/assertions/ablation-scorer.ts +81 -0
- package/eval/assertions/hook-impact.ts +152 -0
- package/eval/assertions/task-completion.ts +65 -0
- package/eval/assertions/tool-accuracy.ts +56 -0
- package/eval/promptfooconfig.yaml +42 -0
- package/eval/providers/opencode-baseline.ts +63 -0
- package/eval/providers/opencode-client.ts +112 -0
- package/eval/providers/opencode-provider.ts +66 -0
- package/eval/spike/config.yaml +13 -0
- package/eval/spike/provider.ts +15 -0
- package/npm-reserve/README.md +19 -0
- package/npm-reserve/package.json +24 -0
- package/opencode.json +6 -0
- package/package.json +47 -8
- package/src/agents/advisor/config.ts +6 -0
- package/src/agents/advisor/index.ts +2 -0
- package/src/agents/advisor/plugin.test.ts +48 -0
- package/src/agents/advisor/plugin.ts +17 -0
- package/src/agents/advisor/prompt-meta.ts +14 -0
- package/src/agents/advisor/prompt.ts +93 -0
- package/src/agents/agent-builder.test.ts +66 -0
- package/src/agents/agent-builder.ts +97 -0
- package/src/agents/agent-plugins.test.ts +98 -0
- package/src/agents/agent-registry.ts +25 -0
- package/src/agents/builtin-agents.ts +18 -0
- package/src/agents/deep-worker/config.ts +6 -0
- package/src/agents/deep-worker/index.ts +2 -0
- package/src/agents/deep-worker/plugin.test.ts +31 -0
- package/src/agents/deep-worker/plugin.ts +16 -0
- package/src/agents/deep-worker/prompt-meta.ts +14 -0
- package/src/agents/deep-worker/prompt.ts +121 -0
- package/src/agents/disabled/analyst/config.ts +6 -0
- package/src/agents/disabled/analyst/index.ts +2 -0
- package/src/agents/disabled/analyst/plugin.ts +16 -0
- package/src/agents/disabled/analyst/prompt.ts +1 -0
- package/src/agents/disabled/executor/config.ts +9 -0
- package/src/agents/disabled/executor/index.ts +2 -0
- package/src/agents/disabled/executor/plugin.ts +16 -0
- package/src/agents/disabled/executor/prompt.ts +1 -0
- package/src/agents/disabled/inspector/config.ts +6 -0
- package/src/agents/disabled/inspector/index.ts +2 -0
- package/src/agents/disabled/inspector/plugin.ts +18 -0
- package/src/agents/disabled/inspector/prompt.ts +1 -0
- package/src/agents/disabled/reviewer/config.ts +6 -0
- package/src/agents/disabled/reviewer/index.ts +2 -0
- package/src/agents/disabled/reviewer/plugin.ts +18 -0
- package/src/agents/disabled/reviewer/prompt.ts +1 -0
- package/src/agents/explorer/config.ts +6 -0
- package/src/agents/explorer/index.ts +2 -0
- package/src/agents/explorer/plugin.test.ts +36 -0
- package/src/agents/explorer/plugin.ts +15 -0
- package/src/agents/explorer/prompt-meta.ts +14 -0
- package/src/agents/explorer/prompt.ts +96 -0
- package/src/agents/fallback-chains.ts +13 -0
- package/src/agents/index.ts +18 -0
- package/src/agents/model-resolution.test.ts +79 -0
- package/src/agents/orchestrator/config.ts +10 -0
- package/src/agents/orchestrator/index.ts +2 -0
- package/src/agents/orchestrator/plugin.test.ts +31 -0
- package/src/agents/orchestrator/plugin.ts +16 -0
- package/src/agents/orchestrator/prompt-meta.ts +14 -0
- package/src/agents/orchestrator/prompt.ts +143 -0
- package/src/agents/planner/config.ts +6 -0
- package/src/agents/planner/index.ts +2 -0
- package/src/agents/planner/plugin.test.ts +31 -0
- package/src/agents/planner/plugin.ts +16 -0
- package/src/agents/planner/prompt-meta.ts +14 -0
- package/src/agents/planner/prompt.ts +138 -0
- package/src/agents/prompt-meta.ts +12 -0
- package/src/agents/prompt-registry.test.ts +98 -0
- package/src/agents/prompt-registry.ts +22 -0
- package/src/agents/researcher/config.ts +6 -0
- package/src/agents/researcher/index.ts +2 -0
- package/src/agents/researcher/plugin.test.ts +31 -0
- package/src/agents/researcher/plugin.ts +16 -0
- package/src/agents/researcher/prompt-meta.ts +14 -0
- package/src/agents/researcher/prompt.ts +116 -0
- package/src/agents/tool-restrictions.ts +87 -0
- package/src/agents/worker/config.ts +6 -0
- package/src/agents/worker/index.ts +2 -0
- package/src/agents/worker/plugin.test.ts +31 -0
- package/src/agents/worker/plugin.ts +15 -0
- package/src/agents/worker/prompt-meta.ts +14 -0
- package/src/agents/worker/prompt.ts +83 -0
- package/src/bootstrap.integration.test.ts +168 -0
- package/src/bootstrap.ts +171 -0
- package/src/cli/cli.ts +42 -0
- package/src/cli/commands/install.test.ts +40 -0
- package/src/cli/commands/install.ts +125 -0
- package/src/cli/commands/update.test.ts +84 -0
- package/src/cli/commands/update.ts +45 -0
- package/src/cli/config-generator.test.ts +178 -0
- package/src/cli/config-generator.ts +119 -0
- package/src/cli/index.test.ts +34 -0
- package/src/cli/index.ts +4 -0
- package/src/config/defaults.ts +24 -0
- package/src/config/define-config.ts +38 -0
- package/src/config/index.ts +6 -0
- package/src/config/loader.test.ts +218 -0
- package/src/config/loader.ts +89 -0
- package/src/config/paths.ts +30 -0
- package/src/config/schema.test.ts +69 -0
- package/src/config/schema.ts +57 -0
- package/src/config/validator.ts +24 -0
- package/src/features/auto-update/auto-update.test.ts +105 -0
- package/src/features/auto-update/index.ts +4 -0
- package/src/features/auto-update/plugin.ts +45 -0
- package/src/features/auto-update/update-checker.ts +66 -0
- package/src/features/background-agent/concurrency.test.ts +65 -0
- package/src/features/background-agent/concurrency.ts +44 -0
- package/src/features/background-agent/index.ts +12 -0
- package/src/features/background-agent/manager.ts +214 -0
- package/src/features/background-agent/poller.test.ts +33 -0
- package/src/features/background-agent/poller.ts +75 -0
- package/src/features/background-agent/singleton.ts +26 -0
- package/src/features/background-agent/spawner.ts +51 -0
- package/src/features/background-agent/types.ts +20 -0
- package/src/features/builtin-features.ts +5 -0
- package/src/features/categories/categories.test.ts +68 -0
- package/src/features/categories/category-config.ts +70 -0
- package/src/features/categories/category-resolver.ts +36 -0
- package/src/features/categories/index.ts +8 -0
- package/src/features/categories/prompt-appends.ts +38 -0
- package/src/features/loops/file-store.ts +151 -0
- package/src/features/loops/handler.ts +89 -0
- package/src/features/loops/index.ts +28 -0
- package/src/features/loops/loops.test.ts +175 -0
- package/src/features/loops/memory-store.ts +53 -0
- package/src/features/loops/plugin.ts +107 -0
- package/src/features/loops/shared/event-utils.ts +50 -0
- package/src/features/loops/state.ts +44 -0
- package/src/features/prompt-builder/agent-table-builder.ts +23 -0
- package/src/features/prompt-builder/category-section-builder.ts +21 -0
- package/src/features/prompt-builder/dynamic-prompt-builder.ts +42 -0
- package/src/features/prompt-builder/index.ts +7 -0
- package/src/features/prompt-builder/prompt-builder.test.ts +244 -0
- package/src/features/prompt-builder/skill-section-builder.ts +25 -0
- package/src/features/session-state/index.ts +17 -0
- package/src/features/session-state/session-cursor.test.ts +137 -0
- package/src/features/session-state/session-cursor.ts +80 -0
- package/src/features/session-state/session-store.test.ts +82 -0
- package/src/features/session-state/session-store.ts +37 -0
- package/src/features/session-state/session-tools-store.ts +18 -0
- package/src/features/skills/builtin/git-master.ts +109 -0
- package/src/features/skills/index.ts +97 -0
- package/src/features/skills/skill-loader.ts +133 -0
- package/src/features/skills/skill-merger.ts +15 -0
- package/src/features/skills/skills.test.ts +120 -0
- package/src/features/slash-commands/command-registry.ts +36 -0
- package/src/features/slash-commands/commands/cancel-loop.ts +17 -0
- package/src/features/slash-commands/commands/handoff.ts +59 -0
- package/src/features/slash-commands/commands/init-deep.ts +40 -0
- package/src/features/slash-commands/commands/loop.ts +39 -0
- package/src/features/slash-commands/commands/start-work.ts +39 -0
- package/src/features/slash-commands/commands/stop-continuation.ts +21 -0
- package/src/features/slash-commands/index.ts +2 -0
- package/src/features/slash-commands/slash-commands.test.ts +68 -0
- package/src/features/slash-commands/types.ts +5 -0
- package/src/hooks/anthropic-effort/handler.test.ts +156 -0
- package/src/hooks/anthropic-effort/handler.ts +64 -0
- package/src/hooks/anthropic-effort/index.ts +3 -0
- package/src/hooks/anthropic-effort/plugin.ts +17 -0
- package/src/hooks/builtin-hooks.ts +64 -0
- package/src/hooks/comment-checker/handler.test.ts +65 -0
- package/src/hooks/comment-checker/handler.ts +60 -0
- package/src/hooks/comment-checker/index.ts +2 -0
- package/src/hooks/comment-checker/plugin.ts +15 -0
- package/src/hooks/compaction-context/handler.test.ts +160 -0
- package/src/hooks/compaction-context/handler.ts +179 -0
- package/src/hooks/compaction-context/index.ts +5 -0
- package/src/hooks/compaction-context/plugin.ts +40 -0
- package/src/hooks/compaction-todo-preserver/handler.test.ts +155 -0
- package/src/hooks/compaction-todo-preserver/handler.ts +129 -0
- package/src/hooks/compaction-todo-preserver/index.ts +2 -0
- package/src/hooks/compaction-todo-preserver/plugin.ts +18 -0
- package/src/hooks/context-injection.test.ts +124 -0
- package/src/hooks/context-injector/handlers/agents.test.ts +90 -0
- package/src/hooks/context-injector/handlers/agents.ts +81 -0
- package/src/hooks/context-injector/handlers/readme.ts +55 -0
- package/src/hooks/context-injector/handlers/rules.ts +62 -0
- package/src/hooks/context-injector/index.ts +4 -0
- package/src/hooks/context-injector/plugin.ts +56 -0
- package/src/hooks/context-window-limit/handler.test.ts +103 -0
- package/src/hooks/context-window-limit/handler.ts +128 -0
- package/src/hooks/context-window-limit/index.ts +6 -0
- package/src/hooks/context-window-limit/plugin.ts +15 -0
- package/src/hooks/continuation.test.ts +103 -0
- package/src/hooks/delegate-retry/handler.test.ts +212 -0
- package/src/hooks/delegate-retry/handler.ts +137 -0
- package/src/hooks/delegate-retry/index.ts +8 -0
- package/src/hooks/delegate-retry/plugin.ts +15 -0
- package/src/hooks/edit-error/handler.test.ts +82 -0
- package/src/hooks/edit-error/handler.ts +50 -0
- package/src/hooks/edit-error/index.ts +6 -0
- package/src/hooks/edit-error/plugin.ts +15 -0
- package/src/hooks/empty-response-detector/handler.test.ts +133 -0
- package/src/hooks/empty-response-detector/handler.ts +62 -0
- package/src/hooks/empty-response-detector/index.ts +2 -0
- package/src/hooks/empty-response-detector/plugin.ts +18 -0
- package/src/hooks/error-diagnostics/error-diagnostics.test.ts +116 -0
- package/src/hooks/error-diagnostics/handler.test.ts +147 -0
- package/src/hooks/error-diagnostics/handler.ts +135 -0
- package/src/hooks/error-diagnostics/patterns.ts +93 -0
- package/src/hooks/error-diagnostics/plugin.ts +11 -0
- package/src/hooks/error-diagnostics/types.ts +26 -0
- package/src/hooks/error-recovery.test.ts +85 -0
- package/src/hooks/foreground-fallback/handler.test.ts +229 -0
- package/src/hooks/foreground-fallback/handler.ts +294 -0
- package/src/hooks/foreground-fallback/index.ts +2 -0
- package/src/hooks/foreground-fallback/plugin.ts +18 -0
- package/src/hooks/hashline-diff-enhancer/handler.test.ts +166 -0
- package/src/hooks/hashline-diff-enhancer/handler.ts +186 -0
- package/src/hooks/hashline-diff-enhancer/index.ts +6 -0
- package/src/hooks/hashline-diff-enhancer/plugin.ts +24 -0
- package/src/hooks/hashline-read-enhancer/handler.test.ts +121 -0
- package/src/hooks/hashline-read-enhancer/handler.ts +165 -0
- package/src/hooks/hashline-read-enhancer/index.ts +2 -0
- package/src/hooks/hashline-read-enhancer/plugin.ts +18 -0
- package/src/hooks/hook-composer.test.ts +52 -0
- package/src/hooks/hook-composer.ts +17 -0
- package/src/hooks/hook-composition.integration.test.ts +274 -0
- package/src/hooks/hook-ordering.ts +41 -0
- package/src/hooks/hook-types.ts +22 -0
- package/src/hooks/index.ts +6 -0
- package/src/hooks/json-error/handler.test.ts +95 -0
- package/src/hooks/json-error/handler.ts +82 -0
- package/src/hooks/json-error/index.ts +6 -0
- package/src/hooks/json-error/plugin.ts +15 -0
- package/src/hooks/keyword-detector/handler.test.ts +113 -0
- package/src/hooks/keyword-detector/handler.ts +73 -0
- package/src/hooks/keyword-detector/index.ts +8 -0
- package/src/hooks/keyword-detector/plugin.ts +24 -0
- package/src/hooks/model-fallback/handler.test.ts +163 -0
- package/src/hooks/model-fallback/handler.ts +178 -0
- package/src/hooks/model-fallback/index.ts +2 -0
- package/src/hooks/model-fallback/plugin.ts +11 -0
- package/src/hooks/model-management.test.ts +121 -0
- package/src/hooks/phase-reminder/handler.test.ts +105 -0
- package/src/hooks/phase-reminder/handler.ts +54 -0
- package/src/hooks/phase-reminder/index.ts +2 -0
- package/src/hooks/phase-reminder/plugin.ts +18 -0
- package/src/hooks/post-read-nudge/handler.test.ts +106 -0
- package/src/hooks/post-read-nudge/handler.ts +28 -0
- package/src/hooks/post-read-nudge/index.ts +2 -0
- package/src/hooks/post-read-nudge/plugin.ts +18 -0
- package/src/hooks/preemptive-compaction/handler.test.ts +130 -0
- package/src/hooks/preemptive-compaction/handler.ts +84 -0
- package/src/hooks/preemptive-compaction/index.ts +2 -0
- package/src/hooks/preemptive-compaction/plugin.ts +15 -0
- package/src/hooks/productivity.test.ts +332 -0
- package/src/hooks/quality.test.ts +330 -0
- package/src/hooks/runtime-fallback/handler.test.ts +142 -0
- package/src/hooks/runtime-fallback/handler.ts +171 -0
- package/src/hooks/runtime-fallback/index.ts +2 -0
- package/src/hooks/runtime-fallback/plugin.ts +13 -0
- package/src/hooks/safe-hook-wrapper.test.ts +35 -0
- package/src/hooks/safe-hook-wrapper.ts +12 -0
- package/src/hooks/session-recovery/handler.test.ts +88 -0
- package/src/hooks/session-recovery/handler.ts +87 -0
- package/src/hooks/session-recovery/index.ts +6 -0
- package/src/hooks/session-recovery/plugin.ts +15 -0
- package/src/hooks/skill-discovery/plugin.ts +45 -0
- package/src/hooks/stop-guard/handler.test.ts +147 -0
- package/src/hooks/stop-guard/handler.ts +127 -0
- package/src/hooks/stop-guard/index.ts +2 -0
- package/src/hooks/stop-guard/plugin.ts +15 -0
- package/src/hooks/task-hooks.test.ts +324 -0
- package/src/hooks/task-resume-info/handler.test.ts +180 -0
- package/src/hooks/task-resume-info/handler.ts +61 -0
- package/src/hooks/task-resume-info/index.ts +2 -0
- package/src/hooks/task-resume-info/plugin.ts +15 -0
- package/src/hooks/think-mode/handler.test.ts +139 -0
- package/src/hooks/think-mode/handler.ts +50 -0
- package/src/hooks/think-mode/index.ts +2 -0
- package/src/hooks/think-mode/plugin.ts +15 -0
- package/src/hooks/thinking-block-validator/handler.test.ts +79 -0
- package/src/hooks/thinking-block-validator/handler.ts +93 -0
- package/src/hooks/thinking-block-validator/index.ts +2 -0
- package/src/hooks/thinking-block-validator/plugin.ts +18 -0
- package/src/hooks/todo-enforcer/handler.test.ts +153 -0
- package/src/hooks/todo-enforcer/handler.ts +100 -0
- package/src/hooks/todo-enforcer/index.ts +2 -0
- package/src/hooks/todo-enforcer/plugin.ts +15 -0
- package/src/hooks/todowrite-disabler/handler.test.ts +119 -0
- package/src/hooks/todowrite-disabler/handler.ts +50 -0
- package/src/hooks/todowrite-disabler/index.ts +6 -0
- package/src/hooks/todowrite-disabler/plugin.ts +46 -0
- package/src/hooks/tool-output-truncator/handler.test.ts +113 -0
- package/src/hooks/tool-output-truncator/handler.ts +83 -0
- package/src/hooks/tool-output-truncator/index.ts +2 -0
- package/src/hooks/tool-output-truncator/plugin.ts +18 -0
- package/src/hooks/tool-output.test.ts +238 -0
- package/src/hooks/workflow-reminders.test.ts +187 -0
- package/src/hooks/write-file-guard/handler.test.ts +107 -0
- package/src/hooks/write-file-guard/handler.ts +166 -0
- package/src/hooks/write-file-guard/index.ts +2 -0
- package/src/hooks/write-file-guard/plugin.ts +23 -0
- package/src/index.ts +8 -0
- package/src/plugin/compositor.ts +99 -0
- package/src/plugin/index.ts +1 -0
- package/src/plugin-api/define-plugin.test.ts +66 -0
- package/src/plugin-api/define-plugin.ts +36 -0
- package/src/plugin-api/index.ts +26 -0
- package/src/plugin-api/types.ts +28 -0
- package/src/registry/agent-aggregator.ts +13 -0
- package/src/registry/contribution-aggregator.test.ts +62 -0
- package/src/registry/contribution-aggregator.ts +114 -0
- package/src/registry/contribution-conflicts.integration.test.ts +186 -0
- package/src/registry/dependency-resolver.test.ts +35 -0
- package/src/registry/dependency-resolver.ts +64 -0
- package/src/registry/hook-aggregator.test.ts +78 -0
- package/src/registry/hook-aggregator.ts +63 -0
- package/src/registry/index.ts +6 -0
- package/src/registry/plugin-lifecycle.integration.test.ts +94 -0
- package/src/registry/plugin-overrides.integration.test.ts +140 -0
- package/src/registry/plugin-registry.test.ts +56 -0
- package/src/registry/plugin-registry.ts +82 -0
- package/src/registry/tool-aggregator.ts +13 -0
- package/src/registry/types.ts +11 -0
- package/src/runtime/index.ts +43 -0
- package/src/shared/data-path.ts +18 -0
- package/src/shared/deep-merge.test.ts +36 -0
- package/src/shared/deep-merge.ts +61 -0
- package/src/shared/fallback-chain.ts +8 -0
- package/src/shared/index.ts +59 -0
- package/src/shared/logger.ts +54 -0
- package/src/shared/model-availability.ts +18 -0
- package/src/shared/model-normalization.test.ts +75 -0
- package/src/shared/model-normalization.ts +28 -0
- package/src/shared/model-prefix-map.test.ts +75 -0
- package/src/shared/model-prefix-map.ts +58 -0
- package/src/shared/model-resolution-pipeline.test.ts +111 -0
- package/src/shared/model-resolution-pipeline.ts +55 -0
- package/src/shared/models-dev.test.ts +277 -0
- package/src/shared/models-dev.ts +176 -0
- package/src/shared/provider-discovery.test.ts +97 -0
- package/src/shared/provider-discovery.ts +73 -0
- package/src/shared/provider-registry.test.ts +212 -0
- package/src/shared/provider-registry.ts +157 -0
- package/src/shared/safe-create-hook.ts +15 -0
- package/src/shared/snake-case.ts +7 -0
- package/src/shared/truncate-description.ts +6 -0
- package/src/test-utils/index.ts +6 -0
- package/src/test-utils/mock-agent-config.ts +13 -0
- package/src/test-utils/mock-hook-inputs.ts +148 -0
- package/src/test-utils/mock-hook-outputs.ts +153 -0
- package/src/test-utils/mock-plugin-context.test.ts +32 -0
- package/src/test-utils/mock-plugin-context.ts +21 -0
- package/src/test-utils/mock-sdk-client.ts +52 -0
- package/src/test-utils/mock-tool-context.ts +24 -0
- package/src/tools/ast-grep/index.ts +4 -0
- package/src/tools/ast-grep/replace/handler.test.ts +93 -0
- package/src/tools/ast-grep/replace/handler.ts +89 -0
- package/src/tools/ast-grep/replace/plugin.ts +10 -0
- package/src/tools/ast-grep/replace/types.ts +14 -0
- package/src/tools/ast-grep/search/handler.test.ts +94 -0
- package/src/tools/ast-grep/search/handler.ts +93 -0
- package/src/tools/ast-grep/search/plugin.ts +10 -0
- package/src/tools/ast-grep/search/types.ts +42 -0
- package/src/tools/background-task/background-task.test.ts +185 -0
- package/src/tools/background-task/cancel/handler.test.ts +141 -0
- package/src/tools/background-task/cancel/handler.ts +52 -0
- package/src/tools/background-task/cancel/plugin.ts +30 -0
- package/src/tools/background-task/cancel/types.ts +4 -0
- package/src/tools/background-task/index.ts +2 -0
- package/src/tools/background-task/output/handler.test.ts +142 -0
- package/src/tools/background-task/output/handler.ts +93 -0
- package/src/tools/background-task/output/plugin.ts +60 -0
- package/src/tools/background-task/output/types.ts +11 -0
- package/src/tools/bridge.test.ts +55 -0
- package/src/tools/bridge.ts +13 -0
- package/src/tools/builtin-tools.ts +54 -0
- package/src/tools/code-search.test.ts +203 -0
- package/src/tools/delegate-task/category-resolver.ts +18 -0
- package/src/tools/delegate-task/constants.ts +43 -0
- package/src/tools/delegate-task/delegate-task.test.ts +245 -0
- package/src/tools/delegate-task/executor.ts +157 -0
- package/src/tools/delegate-task/handler.ts +74 -0
- package/src/tools/delegate-task/index.ts +7 -0
- package/src/tools/delegate-task/plugin.ts +21 -0
- package/src/tools/delegate-task/types.ts +19 -0
- package/src/tools/glob/handler.test.ts +80 -0
- package/src/tools/glob/handler.ts +74 -0
- package/src/tools/glob/index.ts +2 -0
- package/src/tools/glob/plugin.ts +10 -0
- package/src/tools/glob/types.ts +14 -0
- package/src/tools/grep/handler.test.ts +79 -0
- package/src/tools/grep/handler.ts +104 -0
- package/src/tools/grep/index.ts +2 -0
- package/src/tools/grep/plugin.ts +10 -0
- package/src/tools/grep/types.ts +28 -0
- package/src/tools/hashline-edit/constants.ts +10 -0
- package/src/tools/hashline-edit/edit-operations.ts +115 -0
- package/src/tools/hashline-edit/handler.test.ts +105 -0
- package/src/tools/hashline-edit/handler.ts +33 -0
- package/src/tools/hashline-edit/hash-computation.ts +20 -0
- package/src/tools/hashline-edit/hashline-edit.test.ts +62 -0
- package/src/tools/hashline-edit/index.ts +5 -0
- package/src/tools/hashline-edit/plugin.ts +28 -0
- package/src/tools/hashline-edit/types.ts +42 -0
- package/src/tools/index.ts +4 -0
- package/src/tools/look-at/handler.test.ts +189 -0
- package/src/tools/look-at/handler.ts +232 -0
- package/src/tools/look-at/index.ts +3 -0
- package/src/tools/look-at/look-at.test.ts +200 -0
- package/src/tools/look-at/plugin.ts +10 -0
- package/src/tools/look-at/types.ts +17 -0
- package/src/tools/lsp/client.ts +145 -0
- package/src/tools/lsp/diagnostics/handler.test.ts +94 -0
- package/src/tools/lsp/diagnostics/handler.ts +39 -0
- package/src/tools/lsp/diagnostics/plugin.ts +10 -0
- package/src/tools/lsp/diagnostics/types.ts +15 -0
- package/src/tools/lsp/find-references/handler.test.ts +79 -0
- package/src/tools/lsp/find-references/handler.ts +38 -0
- package/src/tools/lsp/find-references/plugin.ts +10 -0
- package/src/tools/lsp/find-references/types.ts +10 -0
- package/src/tools/lsp/goto-definition/handler.test.ts +80 -0
- package/src/tools/lsp/goto-definition/handler.ts +38 -0
- package/src/tools/lsp/goto-definition/plugin.ts +10 -0
- package/src/tools/lsp/goto-definition/types.ts +9 -0
- package/src/tools/lsp/index.ts +6 -0
- package/src/tools/lsp/lsp-tools.test.ts +150 -0
- package/src/tools/lsp/prepare-rename/handler.test.ts +81 -0
- package/src/tools/lsp/prepare-rename/handler.ts +34 -0
- package/src/tools/lsp/prepare-rename/plugin.ts +10 -0
- package/src/tools/lsp/prepare-rename/types.ts +9 -0
- package/src/tools/lsp/rename/handler.test.ts +87 -0
- package/src/tools/lsp/rename/handler.ts +34 -0
- package/src/tools/lsp/rename/plugin.ts +10 -0
- package/src/tools/lsp/rename/types.ts +10 -0
- package/src/tools/lsp/symbols/handler.test.ts +108 -0
- package/src/tools/lsp/symbols/handler.ts +43 -0
- package/src/tools/lsp/symbols/plugin.ts +10 -0
- package/src/tools/lsp/symbols/types.ts +13 -0
- package/src/tools/session-manager/client-context.ts +16 -0
- package/src/tools/session-manager/index.ts +5 -0
- package/src/tools/session-manager/info/handler.test.ts +100 -0
- package/src/tools/session-manager/info/handler.ts +27 -0
- package/src/tools/session-manager/info/plugin.ts +40 -0
- package/src/tools/session-manager/info/types.ts +3 -0
- package/src/tools/session-manager/list/handler.test.ts +122 -0
- package/src/tools/session-manager/list/handler.ts +56 -0
- package/src/tools/session-manager/list/plugin.ts +52 -0
- package/src/tools/session-manager/list/types.ts +6 -0
- package/src/tools/session-manager/read/handler.test.ts +114 -0
- package/src/tools/session-manager/read/handler.ts +36 -0
- package/src/tools/session-manager/read/plugin.ts +57 -0
- package/src/tools/session-manager/read/types.ts +6 -0
- package/src/tools/session-manager/search/handler.test.ts +115 -0
- package/src/tools/session-manager/search/handler.ts +72 -0
- package/src/tools/session-manager/search/plugin.ts +57 -0
- package/src/tools/session-manager/search/types.ts +6 -0
- package/src/tools/session-manager/session-formatter.ts +315 -0
- package/src/tools/session-manager/session-manager.test.ts +254 -0
- package/src/tools/session-manager/types.ts +41 -0
- package/src/tools/shared/constants.ts +3 -0
- package/src/tools/skill/handler.test.ts +57 -0
- package/src/tools/skill/handler.ts +27 -0
- package/src/tools/skill/index.ts +3 -0
- package/src/tools/skill/plugin.ts +41 -0
- package/src/tools/skill/types.ts +14 -0
- package/src/tools/skill-mcp/handler.test.ts +68 -0
- package/src/tools/skill-mcp/handler.ts +84 -0
- package/src/tools/skill-mcp/index.ts +3 -0
- package/src/tools/skill-mcp/plugin.ts +37 -0
- package/src/tools/skill-mcp/types.ts +15 -0
- package/src/tools/skill-tools.test.ts +172 -0
- package/src/tools/task/create/handler.test.ts +64 -0
- package/src/tools/task/create/handler.ts +43 -0
- package/src/tools/task/create/plugin.ts +10 -0
- package/src/tools/task/format-task.test.ts +37 -0
- package/src/tools/task/format-task.ts +19 -0
- package/src/tools/task/get/handler.test.ts +76 -0
- package/src/tools/task/get/handler.ts +35 -0
- package/src/tools/task/get/plugin.ts +10 -0
- package/src/tools/task/index.ts +4 -0
- package/src/tools/task/list/handler.test.ts +70 -0
- package/src/tools/task/list/handler.ts +48 -0
- package/src/tools/task/list/plugin.ts +10 -0
- package/src/tools/task/storage.ts +14 -0
- package/src/tools/task/task.test.ts +165 -0
- package/src/tools/task/types.ts +51 -0
- package/src/tools/task/update/handler.test.ts +86 -0
- package/src/tools/task/update/handler.ts +54 -0
- package/src/tools/task/update/plugin.ts +10 -0
- package/src/tools/tool-builder.test.ts +32 -0
- package/src/tools/tool-builder.ts +24 -0
- package/src/tools/tool-registry-adapter.test.ts +51 -0
- package/src/tools/tool-registry-adapter.ts +19 -0
- package/src/types/agent.ts +53 -0
- package/src/types/category.ts +32 -0
- package/src/types/config.ts +26 -0
- package/src/types/hook.ts +44 -0
- package/src/types/index.ts +12 -0
- package/src/types/plugin.ts +47 -0
- package/src/types/tool.ts +10 -0
- package/test-setup.ts +8 -0
- package/tsconfig.json +20 -0
- /package/{index.js → npm-reserve/index.js} +0 -0
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { describe, it, expect } from "bun:test";
|
|
2
|
+
import * as fs from "node:fs";
|
|
3
|
+
import * as os from "node:os";
|
|
4
|
+
import * as path from "node:path";
|
|
5
|
+
import {
|
|
6
|
+
createHashlineDiffEnhancerBeforeHandler,
|
|
7
|
+
createHashlineDiffEnhancerAfterHandler,
|
|
8
|
+
createHashlineDiffEnhancerHandlers,
|
|
9
|
+
} from "./handler";
|
|
10
|
+
|
|
11
|
+
const HASHLINE_PATTERN = /^[0-9]+#[ZPMQVRWSNKTXJBYH]{2}\|/;
|
|
12
|
+
|
|
13
|
+
describe("createHashlineDiffEnhancerHandlers", () => {
|
|
14
|
+
describe("#given a Write tool that modifies an existing file", () => {
|
|
15
|
+
describe("#when before and after handlers both run", () => {
|
|
16
|
+
it("#then metadata contains diff, hashlined content, and filediff", async () => {
|
|
17
|
+
const beforeHandler = createHashlineDiffEnhancerBeforeHandler();
|
|
18
|
+
const afterHandler = createHashlineDiffEnhancerAfterHandler();
|
|
19
|
+
|
|
20
|
+
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "hashline-diff-"));
|
|
21
|
+
const filePath = path.join(tempDir, "test.ts");
|
|
22
|
+
fs.writeFileSync(filePath, "const a = 1\nconst b = 2\n");
|
|
23
|
+
|
|
24
|
+
const sessionID = "s1";
|
|
25
|
+
const callID = "c1";
|
|
26
|
+
const beforeInput = { tool: "write", sessionID, callID };
|
|
27
|
+
const beforeOutput = { args: { filePath } };
|
|
28
|
+
|
|
29
|
+
await beforeHandler(beforeInput, beforeOutput);
|
|
30
|
+
|
|
31
|
+
fs.writeFileSync(filePath, "const a = 1\nconst b = 2\nconst c = 3\n");
|
|
32
|
+
|
|
33
|
+
const afterInput = { tool: "write", sessionID, callID, args: {} };
|
|
34
|
+
const afterOutput = {
|
|
35
|
+
title: "write",
|
|
36
|
+
output: "File written successfully.",
|
|
37
|
+
metadata: {} as Record<string, unknown>,
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
await afterHandler(afterInput, afterOutput);
|
|
41
|
+
|
|
42
|
+
expect(afterOutput.metadata.diff).toBeDefined();
|
|
43
|
+
expect(typeof afterOutput.metadata.diff).toBe("string");
|
|
44
|
+
expect(afterOutput.metadata.hashlined).toBeDefined();
|
|
45
|
+
const hashlined = afterOutput.metadata.hashlined as string;
|
|
46
|
+
expect(hashlined).toMatch(HASHLINE_PATTERN);
|
|
47
|
+
expect(afterOutput.metadata.filediff).toBeDefined();
|
|
48
|
+
expect(afterOutput.title).toBe(filePath);
|
|
49
|
+
|
|
50
|
+
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
describe("#given a non-Write tool", () => {
|
|
56
|
+
describe("#when the before handler processes the input", () => {
|
|
57
|
+
it("#then does not capture any state and after handler is a no-op", async () => {
|
|
58
|
+
const beforeHandler = createHashlineDiffEnhancerBeforeHandler();
|
|
59
|
+
const input = { tool: "read", sessionID: "s1", callID: "c2" };
|
|
60
|
+
const output = { args: { filePath: "/some/file.ts" } };
|
|
61
|
+
|
|
62
|
+
await beforeHandler(input, output);
|
|
63
|
+
|
|
64
|
+
const afterHandler = createHashlineDiffEnhancerAfterHandler();
|
|
65
|
+
const afterInput = { tool: "read", sessionID: "s1", callID: "c2", args: {} };
|
|
66
|
+
const afterOutput = {
|
|
67
|
+
title: "read",
|
|
68
|
+
output: "file content",
|
|
69
|
+
metadata: {} as Record<string, unknown>,
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
await afterHandler(afterInput, afterOutput);
|
|
73
|
+
|
|
74
|
+
expect(afterOutput.metadata.diff).toBeUndefined();
|
|
75
|
+
expect(afterOutput.metadata.hashlined).toBeUndefined();
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
describe("#given after handler called without prior before capture", () => {
|
|
81
|
+
describe("#when a different callID is used", () => {
|
|
82
|
+
it("#then after handler produces no diff metadata", async () => {
|
|
83
|
+
const afterHandler = createHashlineDiffEnhancerAfterHandler();
|
|
84
|
+
const afterInput = { tool: "write", sessionID: "s1", callID: "c-no-before", args: {} };
|
|
85
|
+
const afterOutput = {
|
|
86
|
+
title: "write",
|
|
87
|
+
output: "File written successfully.",
|
|
88
|
+
metadata: {} as Record<string, unknown>,
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
await afterHandler(afterInput, afterOutput);
|
|
92
|
+
|
|
93
|
+
expect(afterOutput.metadata.diff).toBeUndefined();
|
|
94
|
+
expect(afterOutput.metadata.hashlined).toBeUndefined();
|
|
95
|
+
expect(afterOutput.title).toBe("write");
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
describe("#given a Write tool targeting a new file", () => {
|
|
101
|
+
describe("#when before captures empty content and after reads the written file", () => {
|
|
102
|
+
it("#then diff reflects all lines as additions", async () => {
|
|
103
|
+
const { before, after } = createHashlineDiffEnhancerHandlers();
|
|
104
|
+
|
|
105
|
+
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "hashline-diff-new-"));
|
|
106
|
+
const filePath = path.join(tempDir, "new-file.ts");
|
|
107
|
+
|
|
108
|
+
const sessionID = "s2";
|
|
109
|
+
const callID = "c3";
|
|
110
|
+
const beforeInput = { tool: "write", sessionID, callID };
|
|
111
|
+
const beforeOutput = { args: { filePath } };
|
|
112
|
+
|
|
113
|
+
await before(beforeInput, beforeOutput);
|
|
114
|
+
|
|
115
|
+
fs.writeFileSync(filePath, "line one\nline two\nline three\n");
|
|
116
|
+
|
|
117
|
+
const afterInput = { tool: "write", sessionID, callID, args: {} };
|
|
118
|
+
const afterOutput = {
|
|
119
|
+
title: "write",
|
|
120
|
+
output: "File written successfully.",
|
|
121
|
+
metadata: {} as Record<string, unknown>,
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
await after(afterInput, afterOutput);
|
|
125
|
+
|
|
126
|
+
expect(afterOutput.metadata.diff).toBeDefined();
|
|
127
|
+
const diff = afterOutput.metadata.diff as string;
|
|
128
|
+
expect(diff).toContain("+3 additions");
|
|
129
|
+
expect(diff).toContain("-0 deletions");
|
|
130
|
+
expect(afterOutput.metadata.hashlined).toBeDefined();
|
|
131
|
+
expect(afterOutput.title).toBe(filePath);
|
|
132
|
+
|
|
133
|
+
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
describe("#given missing sessionID or callID", () => {
|
|
139
|
+
describe("#when the before handler receives incomplete input", () => {
|
|
140
|
+
it("#then does not capture state", async () => {
|
|
141
|
+
const beforeHandler = createHashlineDiffEnhancerBeforeHandler();
|
|
142
|
+
const afterHandler = createHashlineDiffEnhancerAfterHandler();
|
|
143
|
+
|
|
144
|
+
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "hashline-diff-noid-"));
|
|
145
|
+
const filePath = path.join(tempDir, "test.ts");
|
|
146
|
+
fs.writeFileSync(filePath, "content\n");
|
|
147
|
+
|
|
148
|
+
const beforeInput = { tool: "write", sessionID: "", callID: "" };
|
|
149
|
+
const beforeOutput = { args: { filePath } };
|
|
150
|
+
await beforeHandler(beforeInput, beforeOutput);
|
|
151
|
+
|
|
152
|
+
const afterInput = { tool: "write", sessionID: "", callID: "", args: {} };
|
|
153
|
+
const afterOutput = {
|
|
154
|
+
title: "write",
|
|
155
|
+
output: "File written successfully.",
|
|
156
|
+
metadata: {} as Record<string, unknown>,
|
|
157
|
+
};
|
|
158
|
+
await afterHandler(afterInput, afterOutput);
|
|
159
|
+
|
|
160
|
+
expect(afterOutput.metadata.diff).toBeUndefined();
|
|
161
|
+
|
|
162
|
+
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
});
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import type { PluginHookContributions } from "../../types/hook";
|
|
2
|
+
import { log } from "../../shared/logger";
|
|
3
|
+
import { computeLineHash } from "../../tools/hashline-edit/hash-computation";
|
|
4
|
+
|
|
5
|
+
const STALE_TIMEOUT_MS = 5 * 60 * 1000;
|
|
6
|
+
|
|
7
|
+
type BeforeInput = { tool: string; sessionID: string; callID: string };
|
|
8
|
+
type BeforeOutput = { args: Record<string, unknown> };
|
|
9
|
+
type AfterInput = { tool: string; sessionID: string; callID: string };
|
|
10
|
+
type AfterOutput = { title: string; output: string; metadata: Record<string, unknown> };
|
|
11
|
+
|
|
12
|
+
type PreToolUseHook = NonNullable<PluginHookContributions["tool.execute.before"]>;
|
|
13
|
+
type PostToolUseHook = NonNullable<PluginHookContributions["tool.execute.after"]>;
|
|
14
|
+
|
|
15
|
+
interface PendingCapture {
|
|
16
|
+
content: string;
|
|
17
|
+
filePath: string;
|
|
18
|
+
storedAt: number;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const pendingCaptures = new Map<string, PendingCapture>();
|
|
22
|
+
|
|
23
|
+
function makeKey(sessionID: string, callID: string): string {
|
|
24
|
+
return `${sessionID}:${callID}`;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function cleanupStaleEntries(): void {
|
|
28
|
+
const now = Date.now();
|
|
29
|
+
for (const [key, entry] of pendingCaptures) {
|
|
30
|
+
if (now - entry.storedAt > STALE_TIMEOUT_MS) {
|
|
31
|
+
pendingCaptures.delete(key);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function isWriteTool(toolName: string): boolean {
|
|
37
|
+
return toolName.toLowerCase() === "write";
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
41
|
+
return typeof value === "object" && value !== null;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function extractFilePath(args: Record<string, unknown>): string | undefined {
|
|
45
|
+
const path = args.path ?? args.filePath ?? args.file_path;
|
|
46
|
+
return typeof path === "string" ? path : undefined;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async function captureOldContent(filePath: string): Promise<string> {
|
|
50
|
+
try {
|
|
51
|
+
const file = Bun.file(filePath);
|
|
52
|
+
if (await file.exists()) {
|
|
53
|
+
return await file.text();
|
|
54
|
+
}
|
|
55
|
+
} catch {
|
|
56
|
+
log("[hashline-diff-enhancer] failed to read old content", { filePath });
|
|
57
|
+
}
|
|
58
|
+
return "";
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function toHashlineContent(content: string): string {
|
|
62
|
+
if (!content) return content;
|
|
63
|
+
const lines = content.split("\n");
|
|
64
|
+
const lastLine = lines[lines.length - 1];
|
|
65
|
+
const hasTrailingNewline = lastLine === "";
|
|
66
|
+
const contentLines = hasTrailingNewline ? lines.slice(0, -1) : lines;
|
|
67
|
+
const hashlined = contentLines.map((line, i) => {
|
|
68
|
+
const lineNum = i + 1;
|
|
69
|
+
const hash = computeLineHash(lineNum, line);
|
|
70
|
+
return `${lineNum}#${hash}|${line}`;
|
|
71
|
+
});
|
|
72
|
+
return hasTrailingNewline ? hashlined.join("\n") + "\n" : hashlined.join("\n");
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function buildSimpleDiff(oldContent: string, newContent: string, filePath: string): string {
|
|
76
|
+
const oldLines = oldContent.split("\n");
|
|
77
|
+
const newLines = newContent.split("\n");
|
|
78
|
+
|
|
79
|
+
const oldSet = new Map<string, number>();
|
|
80
|
+
for (const line of oldLines) {
|
|
81
|
+
oldSet.set(line, (oldSet.get(line) ?? 0) + 1);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const newSet = new Map<string, number>();
|
|
85
|
+
for (const line of newLines) {
|
|
86
|
+
newSet.set(line, (newSet.get(line) ?? 0) + 1);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
let deletions = 0;
|
|
90
|
+
for (const [line, count] of oldSet) {
|
|
91
|
+
const newCount = newSet.get(line) ?? 0;
|
|
92
|
+
if (count > newCount) deletions += count - newCount;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
let additions = 0;
|
|
96
|
+
for (const [line, count] of newSet) {
|
|
97
|
+
const oldCount = oldSet.get(line) ?? 0;
|
|
98
|
+
if (count > oldCount) additions += count - oldCount;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return `--- ${filePath}\n+++ ${filePath}\n@@ -${oldLines.length} lines +${newLines.length} lines @@\n+${additions} additions, -${deletions} deletions`;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export function createHashlineDiffEnhancerBeforeHandler(): PreToolUseHook {
|
|
105
|
+
return async (input: unknown, output: unknown) => {
|
|
106
|
+
if (!isRecord(input) || !isRecord(output)) return;
|
|
107
|
+
|
|
108
|
+
const tool = input.tool;
|
|
109
|
+
if (typeof tool !== "string" || !isWriteTool(tool)) return;
|
|
110
|
+
|
|
111
|
+
const args = output.args;
|
|
112
|
+
if (!isRecord(args)) return;
|
|
113
|
+
|
|
114
|
+
const filePath = extractFilePath(args);
|
|
115
|
+
if (!filePath) return;
|
|
116
|
+
|
|
117
|
+
const sessionID = typeof input.sessionID === "string" ? input.sessionID : "";
|
|
118
|
+
const callID = typeof input.callID === "string" ? input.callID : "";
|
|
119
|
+
if (!sessionID || !callID) return;
|
|
120
|
+
|
|
121
|
+
cleanupStaleEntries();
|
|
122
|
+
const oldContent = await captureOldContent(filePath);
|
|
123
|
+
pendingCaptures.set(makeKey(sessionID, callID), {
|
|
124
|
+
content: oldContent,
|
|
125
|
+
filePath,
|
|
126
|
+
storedAt: Date.now(),
|
|
127
|
+
});
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export function createHashlineDiffEnhancerAfterHandler(): PostToolUseHook {
|
|
132
|
+
return async (input: unknown, output: unknown) => {
|
|
133
|
+
if (!isRecord(input) || !isRecord(output)) return;
|
|
134
|
+
|
|
135
|
+
const tool = input.tool;
|
|
136
|
+
if (typeof tool !== "string" || !isWriteTool(tool)) return;
|
|
137
|
+
|
|
138
|
+
const sessionID = typeof input.sessionID === "string" ? input.sessionID : "";
|
|
139
|
+
const callID = typeof input.callID === "string" ? input.callID : "";
|
|
140
|
+
if (!sessionID || !callID) return;
|
|
141
|
+
|
|
142
|
+
const key = makeKey(sessionID, callID);
|
|
143
|
+
const captured = pendingCaptures.get(key);
|
|
144
|
+
if (!captured) return;
|
|
145
|
+
pendingCaptures.delete(key);
|
|
146
|
+
|
|
147
|
+
const { content: oldContent, filePath } = captured;
|
|
148
|
+
|
|
149
|
+
let newContent: string;
|
|
150
|
+
try {
|
|
151
|
+
newContent = await Bun.file(filePath).text();
|
|
152
|
+
} catch {
|
|
153
|
+
log("[hashline-diff-enhancer] failed to read new content", { filePath });
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const metadata = output.metadata;
|
|
158
|
+
if (!isRecord(metadata)) return;
|
|
159
|
+
|
|
160
|
+
const diff = buildSimpleDiff(oldContent, newContent, filePath);
|
|
161
|
+
const hashlinedNew = toHashlineContent(newContent);
|
|
162
|
+
|
|
163
|
+
metadata.filediff = {
|
|
164
|
+
file: filePath,
|
|
165
|
+
path: filePath,
|
|
166
|
+
before: oldContent,
|
|
167
|
+
after: newContent,
|
|
168
|
+
};
|
|
169
|
+
metadata.diff = diff;
|
|
170
|
+
metadata.hashlined = hashlinedNew;
|
|
171
|
+
|
|
172
|
+
output.title = filePath as string;
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export function createHashlineDiffEnhancerHandlers(): {
|
|
177
|
+
before: PreToolUseHook;
|
|
178
|
+
after: PostToolUseHook;
|
|
179
|
+
} {
|
|
180
|
+
return {
|
|
181
|
+
before: createHashlineDiffEnhancerBeforeHandler(),
|
|
182
|
+
after: createHashlineDiffEnhancerAfterHandler(),
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export type { BeforeInput, BeforeOutput, AfterInput, AfterOutput };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { definePlugin } from "../../plugin-api/define-plugin";
|
|
2
|
+
import { safeCreateHook } from "../../shared/safe-create-hook";
|
|
3
|
+
import {
|
|
4
|
+
createHashlineDiffEnhancerBeforeHandler,
|
|
5
|
+
createHashlineDiffEnhancerAfterHandler,
|
|
6
|
+
} from "./handler";
|
|
7
|
+
|
|
8
|
+
const toolExecuteBeforeHook = safeCreateHook(
|
|
9
|
+
"hashline-diff-enhancer-before",
|
|
10
|
+
createHashlineDiffEnhancerBeforeHandler,
|
|
11
|
+
);
|
|
12
|
+
const toolExecuteAfterHook = safeCreateHook(
|
|
13
|
+
"hashline-diff-enhancer-after",
|
|
14
|
+
createHashlineDiffEnhancerAfterHandler,
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
export const hashlineDiffEnhancerPlugin = definePlugin({
|
|
18
|
+
name: "hashline-diff-enhancer",
|
|
19
|
+
version: "0.1.0",
|
|
20
|
+
hooks: {
|
|
21
|
+
...(toolExecuteBeforeHook ? { "tool.execute.before": toolExecuteBeforeHook } : {}),
|
|
22
|
+
...(toolExecuteAfterHook ? { "tool.execute.after": toolExecuteAfterHook } : {}),
|
|
23
|
+
},
|
|
24
|
+
});
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { describe, it, expect } from "bun:test";
|
|
2
|
+
import * as fs from "node:fs";
|
|
3
|
+
import * as os from "node:os";
|
|
4
|
+
import * as path from "node:path";
|
|
5
|
+
import { createHashlineReadEnhancerHandler } from "./handler";
|
|
6
|
+
|
|
7
|
+
const HASHLINE_PATTERN = /^[0-9]+#[ZPMQVRWSNKTXJBYH]{2}\|/;
|
|
8
|
+
|
|
9
|
+
describe("createHashlineReadEnhancerHandler", () => {
|
|
10
|
+
describe("#given a Read tool output with content tags", () => {
|
|
11
|
+
describe("#when the handler processes the output", () => {
|
|
12
|
+
it("#then prepends LINE#HASH| to each file line inside content tags", async () => {
|
|
13
|
+
const handler = createHashlineReadEnhancerHandler();
|
|
14
|
+
const input = { tool: "read", sessionID: "s1", callID: "c1", args: {} };
|
|
15
|
+
const output = {
|
|
16
|
+
title: "demo.ts",
|
|
17
|
+
output: [
|
|
18
|
+
"<path>/tmp/demo.ts</path>",
|
|
19
|
+
"<type>file</type>",
|
|
20
|
+
"<content>",
|
|
21
|
+
"1: const x = 1",
|
|
22
|
+
"2: const y = 2",
|
|
23
|
+
"</content>",
|
|
24
|
+
].join("\n"),
|
|
25
|
+
metadata: {},
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
await handler(input, output);
|
|
29
|
+
|
|
30
|
+
const lines = output.output.split("\n");
|
|
31
|
+
expect(lines[3]).toMatch(HASHLINE_PATTERN);
|
|
32
|
+
expect(lines[3]).toContain("const x = 1");
|
|
33
|
+
expect(lines[4]).toMatch(HASHLINE_PATTERN);
|
|
34
|
+
expect(lines[4]).toContain("const y = 2");
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
describe("#given a Read tool output without content tags", () => {
|
|
40
|
+
describe("#when the handler processes plain numbered lines", () => {
|
|
41
|
+
it("#then hashifies each numbered line directly", async () => {
|
|
42
|
+
const handler = createHashlineReadEnhancerHandler();
|
|
43
|
+
const input = { tool: "read", sessionID: "s1", callID: "c1", args: {} };
|
|
44
|
+
const output = {
|
|
45
|
+
title: "README.md",
|
|
46
|
+
output: ["1: # Title", "2: Some content", "3: More content"].join("\n"),
|
|
47
|
+
metadata: {},
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
await handler(input, output);
|
|
51
|
+
|
|
52
|
+
const lines = output.output.split("\n");
|
|
53
|
+
expect(lines[0]).toMatch(HASHLINE_PATTERN);
|
|
54
|
+
expect(lines[0]).toContain("# Title");
|
|
55
|
+
expect(lines[1]).toMatch(HASHLINE_PATTERN);
|
|
56
|
+
expect(lines[2]).toMatch(HASHLINE_PATTERN);
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
describe("#given a non-Read tool", () => {
|
|
62
|
+
describe("#when the handler processes the output", () => {
|
|
63
|
+
it("#then leaves the output unchanged", async () => {
|
|
64
|
+
const handler = createHashlineReadEnhancerHandler();
|
|
65
|
+
const input = { tool: "bash", sessionID: "s1", callID: "c1", args: {} };
|
|
66
|
+
const original = "1: some output";
|
|
67
|
+
const output = {
|
|
68
|
+
title: "bash",
|
|
69
|
+
output: original,
|
|
70
|
+
metadata: {},
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
await handler(input, output);
|
|
74
|
+
|
|
75
|
+
expect(output.output).toBe(original);
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
describe("#given a Read tool with empty output", () => {
|
|
81
|
+
describe("#when the handler processes the output", () => {
|
|
82
|
+
it("#then returns the empty output unchanged", async () => {
|
|
83
|
+
const handler = createHashlineReadEnhancerHandler();
|
|
84
|
+
const input = { tool: "read", sessionID: "s1", callID: "c1", args: {} };
|
|
85
|
+
const output = {
|
|
86
|
+
title: "empty.ts",
|
|
87
|
+
output: "",
|
|
88
|
+
metadata: {},
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
await handler(input, output);
|
|
92
|
+
|
|
93
|
+
expect(output.output).toBe("");
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
describe("#given a Write tool with a valid file path", () => {
|
|
99
|
+
describe("#when the handler processes the output", () => {
|
|
100
|
+
it("#then replaces output with a line count summary", async () => {
|
|
101
|
+
const handler = createHashlineReadEnhancerHandler();
|
|
102
|
+
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "hashline-read-write-"));
|
|
103
|
+
const filePath = path.join(tempDir, "demo.ts");
|
|
104
|
+
fs.writeFileSync(filePath, "const x = 1\nconst y = 2");
|
|
105
|
+
const input = { tool: "write", sessionID: "s1", callID: "c1", args: {} };
|
|
106
|
+
const output = {
|
|
107
|
+
title: "write",
|
|
108
|
+
output: "Wrote file successfully.",
|
|
109
|
+
metadata: { filepath: filePath },
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
await handler(input, output);
|
|
113
|
+
|
|
114
|
+
expect(output.output).toContain("File written successfully.");
|
|
115
|
+
expect(output.output).toContain("2 lines written.");
|
|
116
|
+
|
|
117
|
+
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
});
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import type { PluginHookContributions } from "../../types/hook";
|
|
2
|
+
import { computeLineHash } from "../../tools/hashline-edit/hash-computation";
|
|
3
|
+
|
|
4
|
+
const WRITE_SUCCESS_MARKER = "File written successfully.";
|
|
5
|
+
const COLON_READ_LINE_PATTERN = /^\s*(\d+): ?(.*)$/;
|
|
6
|
+
const PIPE_READ_LINE_PATTERN = /^\s*(\d+)\| ?(.*)$/;
|
|
7
|
+
const CONTENT_OPEN_TAG = "<content>";
|
|
8
|
+
const CONTENT_CLOSE_TAG = "</content>";
|
|
9
|
+
const FILE_OPEN_TAG = "<file>";
|
|
10
|
+
const FILE_CLOSE_TAG = "</file>";
|
|
11
|
+
const OPENCODE_LINE_TRUNCATION_SUFFIX = "... (line truncated to 2000 chars)";
|
|
12
|
+
|
|
13
|
+
type PostToolUseHook = NonNullable<PluginHookContributions["tool.execute.after"]>;
|
|
14
|
+
|
|
15
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
16
|
+
return typeof value === "object" && value !== null;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function isReadTool(toolName: string): boolean {
|
|
20
|
+
return toolName.toLowerCase() === "read";
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function isWriteTool(toolName: string): boolean {
|
|
24
|
+
return toolName.toLowerCase() === "write";
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function isTextFile(output: string): boolean {
|
|
28
|
+
const firstLine = output.split("\n")[0] ?? "";
|
|
29
|
+
return COLON_READ_LINE_PATTERN.test(firstLine) || PIPE_READ_LINE_PATTERN.test(firstLine);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function parseReadLine(line: string): { lineNumber: number; content: string } | null {
|
|
33
|
+
const colonMatch = COLON_READ_LINE_PATTERN.exec(line);
|
|
34
|
+
if (colonMatch) {
|
|
35
|
+
return {
|
|
36
|
+
lineNumber: Number.parseInt(colonMatch[1], 10),
|
|
37
|
+
content: colonMatch[2] ?? "",
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const pipeMatch = PIPE_READ_LINE_PATTERN.exec(line);
|
|
42
|
+
if (pipeMatch) {
|
|
43
|
+
return {
|
|
44
|
+
lineNumber: Number.parseInt(pipeMatch[1], 10),
|
|
45
|
+
content: pipeMatch[2] ?? "",
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function transformLine(line: string): string {
|
|
53
|
+
const parsed = parseReadLine(line);
|
|
54
|
+
if (!parsed) return line;
|
|
55
|
+
if (parsed.content.endsWith(OPENCODE_LINE_TRUNCATION_SUFFIX)) return line;
|
|
56
|
+
const hash = computeLineHash(parsed.lineNumber, parsed.content);
|
|
57
|
+
return `${parsed.lineNumber}#${hash}|${parsed.content}`;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function transformOutput(output: string): string {
|
|
61
|
+
if (!output) return output;
|
|
62
|
+
|
|
63
|
+
const lines = output.split("\n");
|
|
64
|
+
const contentStart = lines.findIndex(
|
|
65
|
+
(line) => line === CONTENT_OPEN_TAG || line.startsWith(CONTENT_OPEN_TAG),
|
|
66
|
+
);
|
|
67
|
+
const contentEnd = lines.indexOf(CONTENT_CLOSE_TAG);
|
|
68
|
+
const fileStart = lines.findIndex(
|
|
69
|
+
(line) => line === FILE_OPEN_TAG || line.startsWith(FILE_OPEN_TAG),
|
|
70
|
+
);
|
|
71
|
+
const fileEnd = lines.indexOf(FILE_CLOSE_TAG);
|
|
72
|
+
|
|
73
|
+
const blockStart = contentStart !== -1 ? contentStart : fileStart;
|
|
74
|
+
const blockEnd = contentStart !== -1 ? contentEnd : fileEnd;
|
|
75
|
+
const openTag = contentStart !== -1 ? CONTENT_OPEN_TAG : FILE_OPEN_TAG;
|
|
76
|
+
|
|
77
|
+
if (blockStart !== -1 && blockEnd !== -1 && blockEnd > blockStart) {
|
|
78
|
+
const openLine = lines[blockStart] ?? "";
|
|
79
|
+
const inlineFirst =
|
|
80
|
+
openLine.startsWith(openTag) && openLine !== openTag ? openLine.slice(openTag.length) : null;
|
|
81
|
+
const fileLines =
|
|
82
|
+
inlineFirst !== null
|
|
83
|
+
? [inlineFirst, ...lines.slice(blockStart + 1, blockEnd)]
|
|
84
|
+
: lines.slice(blockStart + 1, blockEnd);
|
|
85
|
+
if (!isTextFile(fileLines[0] ?? "")) return output;
|
|
86
|
+
|
|
87
|
+
const result: string[] = [];
|
|
88
|
+
for (const line of fileLines) {
|
|
89
|
+
if (!parseReadLine(line)) {
|
|
90
|
+
result.push(...fileLines.slice(result.length));
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
result.push(transformLine(line));
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const prefixLines =
|
|
97
|
+
inlineFirst !== null
|
|
98
|
+
? [...lines.slice(0, blockStart), openTag]
|
|
99
|
+
: lines.slice(0, blockStart + 1);
|
|
100
|
+
|
|
101
|
+
return [...prefixLines, ...result, ...lines.slice(blockEnd)].join("\n");
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (!isTextFile(lines[0] ?? "")) return output;
|
|
105
|
+
|
|
106
|
+
const result: string[] = [];
|
|
107
|
+
for (const line of lines) {
|
|
108
|
+
if (!parseReadLine(line)) {
|
|
109
|
+
result.push(...lines.slice(result.length));
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
112
|
+
result.push(transformLine(line));
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return result.join("\n");
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function extractFilePath(metadata: unknown): string | undefined {
|
|
119
|
+
if (!isRecord(metadata)) return undefined;
|
|
120
|
+
const candidates = [metadata.filepath, metadata.filePath, metadata.path, metadata.file];
|
|
121
|
+
for (const candidate of candidates) {
|
|
122
|
+
if (typeof candidate === "string" && candidate.length > 0) return candidate;
|
|
123
|
+
}
|
|
124
|
+
return undefined;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
async function appendWriteHashlineOutput(output: Record<string, unknown>): Promise<void> {
|
|
128
|
+
const outputStr = output.output;
|
|
129
|
+
if (typeof outputStr !== "string") return;
|
|
130
|
+
if (outputStr.startsWith(WRITE_SUCCESS_MARKER)) return;
|
|
131
|
+
|
|
132
|
+
const outputLower = outputStr.toLowerCase();
|
|
133
|
+
if (outputLower.startsWith("error") || outputLower.includes("failed")) return;
|
|
134
|
+
|
|
135
|
+
const filePath = extractFilePath(output.metadata);
|
|
136
|
+
if (!filePath) return;
|
|
137
|
+
|
|
138
|
+
const file = Bun.file(filePath);
|
|
139
|
+
if (!(await file.exists())) return;
|
|
140
|
+
|
|
141
|
+
const content = await file.text();
|
|
142
|
+
const lines = content.split("\n");
|
|
143
|
+
const lineCount =
|
|
144
|
+
content === "" ? 0 : lines[lines.length - 1] === "" ? lines.length - 1 : lines.length;
|
|
145
|
+
output.output = `${WRITE_SUCCESS_MARKER} ${lineCount} lines written.`;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export function createHashlineReadEnhancerHandler(): PostToolUseHook {
|
|
149
|
+
return async (input: unknown, output: unknown) => {
|
|
150
|
+
if (!isRecord(input) || !isRecord(output)) return;
|
|
151
|
+
|
|
152
|
+
const tool = input.tool;
|
|
153
|
+
if (typeof tool !== "string") return;
|
|
154
|
+
|
|
155
|
+
if (isWriteTool(tool) && typeof output.output === "string") {
|
|
156
|
+
await appendWriteHashlineOutput(output);
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if (!isReadTool(tool)) return;
|
|
161
|
+
if (typeof output.output !== "string") return;
|
|
162
|
+
|
|
163
|
+
output.output = transformOutput(output.output);
|
|
164
|
+
};
|
|
165
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { definePlugin } from "../../plugin-api/define-plugin";
|
|
2
|
+
import { safeCreateHook } from "../../shared/safe-create-hook";
|
|
3
|
+
import { createHashlineReadEnhancerHandler } from "./handler";
|
|
4
|
+
|
|
5
|
+
const toolExecuteAfterHook = safeCreateHook(
|
|
6
|
+
"hashline-read-enhancer",
|
|
7
|
+
createHashlineReadEnhancerHandler,
|
|
8
|
+
);
|
|
9
|
+
|
|
10
|
+
export const hashlineReadEnhancerPlugin = definePlugin({
|
|
11
|
+
name: "hashline-read-enhancer",
|
|
12
|
+
version: "0.1.0",
|
|
13
|
+
hooks: toolExecuteAfterHook
|
|
14
|
+
? {
|
|
15
|
+
"tool.execute.after": toolExecuteAfterHook,
|
|
16
|
+
}
|
|
17
|
+
: {},
|
|
18
|
+
});
|