mixdog 0.7.1
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/.claude-plugin/marketplace.json +31 -0
- package/.claude-plugin/plugin.json +20 -0
- package/.gitattributes +34 -0
- package/.mcp.json +14 -0
- package/ARCHITECTURE.md +77 -0
- package/CHANGELOG.md +7 -0
- package/CONTRIBUTING.md +45 -0
- package/DATA-FLOW.md +79 -0
- package/LICENSE +21 -0
- package/README.md +389 -0
- package/SECURITY.md +138 -0
- package/UNINSTALL.md +112 -0
- package/agents/maintenance.md +5 -0
- package/agents/memory-classification.md +30 -0
- package/agents/scheduler-task.md +18 -0
- package/agents/webhook-handler.md +27 -0
- package/agents/worker.md +24 -0
- package/bin/bridge +133 -0
- package/bin/statusline-launcher.mjs +78 -0
- package/bin/statusline-lib.mjs +550 -0
- package/bin/statusline.mjs +607 -0
- package/bun.lock +802 -0
- package/commands/config.md +16 -0
- package/commands/doctor.md +13 -0
- package/commands/setup.md +17 -0
- package/defaults/cycle3-review-prompt.md +90 -0
- package/defaults/hidden-roles.json +65 -0
- package/defaults/memory-chunk-prompt.md +63 -0
- package/defaults/memory-promote-prompt.md +135 -0
- package/defaults/mixdog-config.template.json +27 -0
- package/defaults/user-workflow.json +8 -0
- package/defaults/user-workflow.md +12 -0
- package/hooks/hooks.json +73 -0
- package/hooks/lib/active-instance.cjs +77 -0
- package/hooks/lib/permission-evaluator.cjs +411 -0
- package/hooks/lib/permission-route.cjs +63 -0
- package/hooks/lib/permission-rules.cjs +170 -0
- package/hooks/lib/settings-loader.cjs +116 -0
- package/hooks/post-tool-use.cjs +84 -0
- package/hooks/pre-mcp-sandbox.cjs +158 -0
- package/hooks/pre-tool-subagent.cjs +253 -0
- package/hooks/session-start.cjs +1372 -0
- package/hooks/turn-timer.cjs +82 -0
- package/lib/claude-md-writer.cjs +386 -0
- package/lib/config-cjs.cjs +61 -0
- package/lib/hook-pipe-path.cjs +10 -0
- package/lib/keychain-cjs.cjs +263 -0
- package/lib/plugin-paths.cjs +61 -0
- package/lib/rules-builder.cjs +241 -0
- package/lib/text-utils.cjs +61 -0
- package/native/README.md +117 -0
- package/native/prebuilt/linux-aarch64/mixdog-shim +0 -0
- package/native/prebuilt/linux-x86_64/mixdog-shim +0 -0
- package/native/prebuilt/macos-aarch64/mixdog-shim +0 -0
- package/native/prebuilt/macos-x86_64/mixdog-shim +0 -0
- package/native/prebuilt/windows-x86_64/mixdog-shim.exe +0 -0
- package/package.json +107 -0
- package/prompts/code-review.txt +16 -0
- package/prompts/security-audit.txt +17 -0
- package/rules/bridge/00-common.md +39 -0
- package/rules/bridge/20-skip-protocol.md +18 -0
- package/rules/bridge/30-explorer.md +33 -0
- package/rules/bridge/40-cycle1-agent.md +52 -0
- package/rules/bridge/41-cycle2-agent.md +62 -0
- package/rules/bridge/42-cycle3-agent.md +44 -0
- package/rules/lead/00-tool-lead.md +61 -0
- package/rules/lead/01-general.md +23 -0
- package/rules/lead/02-channels.md +49 -0
- package/rules/lead/03-team.md +27 -0
- package/rules/lead/04-workflow.md +20 -0
- package/rules/shared/00-language.md +14 -0
- package/rules/shared/01-tool.md +138 -0
- package/scripts/bootstrap.mjs +184 -0
- package/scripts/bridge-unify-smoke.mjs +308 -0
- package/scripts/build-runtime-linux.sh +348 -0
- package/scripts/build-runtime-macos.sh +217 -0
- package/scripts/build-runtime-windows.ps1 +242 -0
- package/scripts/builtin-utils-smoke.mjs +392 -0
- package/scripts/check-json.mjs +45 -0
- package/scripts/check-syntax-changed.mjs +102 -0
- package/scripts/check-syntax.mjs +58 -0
- package/scripts/code-graph-batch.test.mjs +33 -0
- package/scripts/config-preserve-smoke.mjs +180 -0
- package/scripts/doctor.mjs +484 -0
- package/scripts/edit-normalize-fuzz.mjs +130 -0
- package/scripts/edit-normalize-smoke.mjs +401 -0
- package/scripts/edit-operation-smoke.mjs +369 -0
- package/scripts/edit2-smoke.mjs +63 -0
- package/scripts/fuzzy-e2e.mjs +28 -0
- package/scripts/fuzzy-smoke.mjs +26 -0
- package/scripts/generate-runtime-manifest.mjs +166 -0
- package/scripts/guard-smoke.mjs +66 -0
- package/scripts/hidden-role-schema-smoke.mjs +162 -0
- package/scripts/hook-routing-smoke.mjs +29 -0
- package/scripts/inject-input.ps1 +204 -0
- package/scripts/io-complex-smoke.mjs +667 -0
- package/scripts/io-explore-bench.mjs +424 -0
- package/scripts/io-guardrails-smoke.mjs +205 -0
- package/scripts/io-mini-bench-baseline.json +11 -0
- package/scripts/io-mini-bench.mjs +216 -0
- package/scripts/io-route-harness.mjs +933 -0
- package/scripts/io-telemetry-report.mjs +691 -0
- package/scripts/mutation-bench.mjs +564 -0
- package/scripts/mutation-io-smoke.mjs +1081 -0
- package/scripts/native-patch-bridge-smoke.mjs +288 -0
- package/scripts/native-patch-smoke.mjs +304 -0
- package/scripts/patch-interior-context-smoke.mjs +49 -0
- package/scripts/patch-newline-utf8-smoke.mjs +157 -0
- package/scripts/perf-hook-smoke.mjs +71 -0
- package/scripts/permission-eval-smoke.mjs +426 -0
- package/scripts/prep-patch.mjs +53 -0
- package/scripts/prep-shim.mjs +96 -0
- package/scripts/provider-cache-smoke.mjs +687 -0
- package/scripts/report-runtime-health.mjs +132 -0
- package/scripts/run-mcp.mjs +1547 -0
- package/scripts/salvage-v4a-shatter.test.mjs +58 -0
- package/scripts/scoped-cache-io-smoke.mjs +103 -0
- package/scripts/shell-policy-round3-smoke.mjs +46 -0
- package/scripts/smoke-runtime-negative.ps1 +100 -0
- package/scripts/smoke-runtime-negative.sh +95 -0
- package/scripts/stall-policy-smoke.mjs +50 -0
- package/scripts/start-memory-worker.mjs +23 -0
- package/scripts/statusline-launcher-smoke.mjs +82 -0
- package/scripts/stress-atomic-write.mjs +1028 -0
- package/scripts/test-config-rmw-restore.mjs +122 -0
- package/scripts/test-fault-inject.mjs +164 -0
- package/scripts/test-large-file.mjs +174 -0
- package/scripts/tool-edge-smoke.mjs +209 -0
- package/scripts/uninstall.mjs +201 -0
- package/scripts/webhook-selfheal-smoke.mjs +29 -0
- package/scripts/write-overwrite-guard-smoke.mjs +56 -0
- package/server-main.mjs +3055 -0
- package/server.mjs +468 -0
- package/setup/config-merge.mjs +254 -0
- package/setup/install.mjs +120 -0
- package/setup/launch-core.mjs +507 -0
- package/setup/launch.mjs +101 -0
- package/setup/setup-server.mjs +3206 -0
- package/setup/setup.html +3693 -0
- package/skills/retro-skill-proposer/SKILL.md +92 -0
- package/skills/schedule-add/SKILL.md +77 -0
- package/skills/setup/SKILL.md +346 -0
- package/skills/webhook-add/SKILL.md +81 -0
- package/src/agent/bridge-stall-watchdog.mjs +337 -0
- package/src/agent/index.mjs +2138 -0
- package/src/agent/orchestrator/activity-bus.mjs +38 -0
- package/src/agent/orchestrator/ai-wrapped-dispatch.mjs +1010 -0
- package/src/agent/orchestrator/bridge-retry.mjs +220 -0
- package/src/agent/orchestrator/bridge-trace.mjs +583 -0
- package/src/agent/orchestrator/cache-mtime.mjs +58 -0
- package/src/agent/orchestrator/config.mjs +358 -0
- package/src/agent/orchestrator/context/collect.mjs +651 -0
- package/src/agent/orchestrator/dispatch-persist.mjs +549 -0
- package/src/agent/orchestrator/drain-registry.mjs +50 -0
- package/src/agent/orchestrator/explore-validator.mjs +8 -0
- package/src/agent/orchestrator/internal-roles.mjs +118 -0
- package/src/agent/orchestrator/internal-tools.mjs +88 -0
- package/src/agent/orchestrator/jobs.mjs +116 -0
- package/src/agent/orchestrator/mcp/client.mjs +364 -0
- package/src/agent/orchestrator/providers/anthropic-betas.mjs +21 -0
- package/src/agent/orchestrator/providers/anthropic-oauth.mjs +1745 -0
- package/src/agent/orchestrator/providers/anthropic.mjs +437 -0
- package/src/agent/orchestrator/providers/gemini.mjs +1175 -0
- package/src/agent/orchestrator/providers/grok-oauth.mjs +782 -0
- package/src/agent/orchestrator/providers/model-catalog.mjs +241 -0
- package/src/agent/orchestrator/providers/openai-compat.mjs +1467 -0
- package/src/agent/orchestrator/providers/openai-oauth-ws.mjs +1890 -0
- package/src/agent/orchestrator/providers/openai-oauth.mjs +1307 -0
- package/src/agent/orchestrator/providers/openai-ws.mjs +104 -0
- package/src/agent/orchestrator/providers/registry.mjs +192 -0
- package/src/agent/orchestrator/providers/retry-classifier.mjs +325 -0
- package/src/agent/orchestrator/session/abort-lookup.mjs +13 -0
- package/src/agent/orchestrator/session/cache/post-edit-marks.mjs +42 -0
- package/src/agent/orchestrator/session/cache/prefetch-cache.mjs +142 -0
- package/src/agent/orchestrator/session/cache/read-cache.mjs +319 -0
- package/src/agent/orchestrator/session/cache/scoped-cache-outcome.mjs +11 -0
- package/src/agent/orchestrator/session/cache/scoped-cache.mjs +361 -0
- package/src/agent/orchestrator/session/cache/util.mjs +49 -0
- package/src/agent/orchestrator/session/loop.mjs +1478 -0
- package/src/agent/orchestrator/session/manager.mjs +1975 -0
- package/src/agent/orchestrator/session/read-dedup.mjs +6 -0
- package/src/agent/orchestrator/session/result-classification.mjs +65 -0
- package/src/agent/orchestrator/session/save-session-worker.mjs +18 -0
- package/src/agent/orchestrator/session/store.mjs +624 -0
- package/src/agent/orchestrator/session/stream-watchdog.mjs +130 -0
- package/src/agent/orchestrator/session/tool-result-offload.mjs +166 -0
- package/src/agent/orchestrator/session/trim.mjs +491 -0
- package/src/agent/orchestrator/smart-bridge/CACHE-SHARD.md +115 -0
- package/src/agent/orchestrator/smart-bridge/bridge-llm.mjs +327 -0
- package/src/agent/orchestrator/smart-bridge/cache-obs.mjs +150 -0
- package/src/agent/orchestrator/smart-bridge/cache-strategy.mjs +228 -0
- package/src/agent/orchestrator/smart-bridge/index.mjs +215 -0
- package/src/agent/orchestrator/smart-bridge/profiles.mjs +37 -0
- package/src/agent/orchestrator/smart-bridge/registry.mjs +348 -0
- package/src/agent/orchestrator/smart-bridge/session-builder.mjs +116 -0
- package/src/agent/orchestrator/stall-policy.mjs +195 -0
- package/src/agent/orchestrator/tool-loop-guard.mjs +75 -0
- package/src/agent/orchestrator/tools/bash-policy-scan.mjs +77 -0
- package/src/agent/orchestrator/tools/bash-session.mjs +721 -0
- package/src/agent/orchestrator/tools/builtin/advisory-lock.mjs +171 -0
- package/src/agent/orchestrator/tools/builtin/arg-guard.mjs +455 -0
- package/src/agent/orchestrator/tools/builtin/atomic-write.mjs +236 -0
- package/src/agent/orchestrator/tools/builtin/bash-tool.mjs +480 -0
- package/src/agent/orchestrator/tools/builtin/binary-file.mjs +76 -0
- package/src/agent/orchestrator/tools/builtin/builtin-tools.mjs +256 -0
- package/src/agent/orchestrator/tools/builtin/cache-layers.mjs +386 -0
- package/src/agent/orchestrator/tools/builtin/cwd-utils.mjs +37 -0
- package/src/agent/orchestrator/tools/builtin/device-paths.mjs +154 -0
- package/src/agent/orchestrator/tools/builtin/diagnostics-tool.mjs +292 -0
- package/src/agent/orchestrator/tools/builtin/diff-utils.mjs +109 -0
- package/src/agent/orchestrator/tools/builtin/edit-base-guard.mjs +58 -0
- package/src/agent/orchestrator/tools/builtin/edit-byte-plan.mjs +240 -0
- package/src/agent/orchestrator/tools/builtin/edit-byte-utils.mjs +113 -0
- package/src/agent/orchestrator/tools/builtin/edit-commit.mjs +74 -0
- package/src/agent/orchestrator/tools/builtin/edit-context-utils.mjs +242 -0
- package/src/agent/orchestrator/tools/builtin/edit-diagnostics.mjs +211 -0
- package/src/agent/orchestrator/tools/builtin/edit-engine.mjs +1364 -0
- package/src/agent/orchestrator/tools/builtin/edit-failure-context.mjs +126 -0
- package/src/agent/orchestrator/tools/builtin/edit-hint.mjs +141 -0
- package/src/agent/orchestrator/tools/builtin/edit-match-utils.mjs +194 -0
- package/src/agent/orchestrator/tools/builtin/edit-partial-write.mjs +60 -0
- package/src/agent/orchestrator/tools/builtin/edit-stale-refresh.mjs +168 -0
- package/src/agent/orchestrator/tools/builtin/edit-tool.mjs +173 -0
- package/src/agent/orchestrator/tools/builtin/edit-utf8-guard.mjs +48 -0
- package/src/agent/orchestrator/tools/builtin/fs-reachability.mjs +48 -0
- package/src/agent/orchestrator/tools/builtin/fuzzy-match.mjs +99 -0
- package/src/agent/orchestrator/tools/builtin/glob-walk.mjs +170 -0
- package/src/agent/orchestrator/tools/builtin/grep-formatting.mjs +113 -0
- package/src/agent/orchestrator/tools/builtin/hash-utils.mjs +6 -0
- package/src/agent/orchestrator/tools/builtin/list-formatting.mjs +7 -0
- package/src/agent/orchestrator/tools/builtin/list-tool.mjs +593 -0
- package/src/agent/orchestrator/tools/builtin/native-edit-runner.mjs +89 -0
- package/src/agent/orchestrator/tools/builtin/notebook-edit-tool.mjs +300 -0
- package/src/agent/orchestrator/tools/builtin/open-config-tool.mjs +26 -0
- package/src/agent/orchestrator/tools/builtin/path-diagnostics.mjs +152 -0
- package/src/agent/orchestrator/tools/builtin/path-locks.mjs +35 -0
- package/src/agent/orchestrator/tools/builtin/path-utils.mjs +201 -0
- package/src/agent/orchestrator/tools/builtin/read-args.mjs +103 -0
- package/src/agent/orchestrator/tools/builtin/read-batch.mjs +172 -0
- package/src/agent/orchestrator/tools/builtin/read-constants.mjs +40 -0
- package/src/agent/orchestrator/tools/builtin/read-formatting.mjs +118 -0
- package/src/agent/orchestrator/tools/builtin/read-image-resize.mjs +189 -0
- package/src/agent/orchestrator/tools/builtin/read-image.mjs +88 -0
- package/src/agent/orchestrator/tools/builtin/read-lines.mjs +12 -0
- package/src/agent/orchestrator/tools/builtin/read-mode-tool.mjs +455 -0
- package/src/agent/orchestrator/tools/builtin/read-open.mjs +190 -0
- package/src/agent/orchestrator/tools/builtin/read-range-index.mjs +271 -0
- package/src/agent/orchestrator/tools/builtin/read-ranges.mjs +26 -0
- package/src/agent/orchestrator/tools/builtin/read-single-tool.mjs +728 -0
- package/src/agent/orchestrator/tools/builtin/read-snapshot-runtime.mjs +173 -0
- package/src/agent/orchestrator/tools/builtin/read-special-files.mjs +268 -0
- package/src/agent/orchestrator/tools/builtin/read-streaming.mjs +602 -0
- package/src/agent/orchestrator/tools/builtin/read-tool.mjs +530 -0
- package/src/agent/orchestrator/tools/builtin/read-windows.mjs +107 -0
- package/src/agent/orchestrator/tools/builtin/rename-tool.mjs +196 -0
- package/src/agent/orchestrator/tools/builtin/rg-runner.mjs +422 -0
- package/src/agent/orchestrator/tools/builtin/search-builders.mjs +158 -0
- package/src/agent/orchestrator/tools/builtin/search-tool.mjs +869 -0
- package/src/agent/orchestrator/tools/builtin/shell-analysis.mjs +653 -0
- package/src/agent/orchestrator/tools/builtin/shell-jobs.mjs +936 -0
- package/src/agent/orchestrator/tools/builtin/shell-output.mjs +36 -0
- package/src/agent/orchestrator/tools/builtin/shell-runtime.mjs +214 -0
- package/src/agent/orchestrator/tools/builtin/snapshot-helpers.mjs +143 -0
- package/src/agent/orchestrator/tools/builtin/snapshot-store.mjs +206 -0
- package/src/agent/orchestrator/tools/builtin/snapshot-validation.mjs +98 -0
- package/src/agent/orchestrator/tools/builtin/text-stats.mjs +69 -0
- package/src/agent/orchestrator/tools/builtin/windows-roots.mjs +23 -0
- package/src/agent/orchestrator/tools/builtin/write-tool.mjs +401 -0
- package/src/agent/orchestrator/tools/builtin.mjs +500 -0
- package/src/agent/orchestrator/tools/code-graph-prewarm-worker.mjs +39 -0
- package/src/agent/orchestrator/tools/code-graph-tool-defs.mjs +24 -0
- package/src/agent/orchestrator/tools/code-graph.mjs +4095 -0
- package/src/agent/orchestrator/tools/cwd-tool.mjs +298 -0
- package/src/agent/orchestrator/tools/destructive-warning.mjs +323 -0
- package/src/agent/orchestrator/tools/edit-normalize.mjs +603 -0
- package/src/agent/orchestrator/tools/env-scrub.mjs +100 -0
- package/src/agent/orchestrator/tools/graph-binary-fetcher.mjs +144 -0
- package/src/agent/orchestrator/tools/graph-manifest.json +26 -0
- package/src/agent/orchestrator/tools/host-input.mjs +204 -0
- package/src/agent/orchestrator/tools/mutation-content-cache.mjs +67 -0
- package/src/agent/orchestrator/tools/mutation-planner.mjs +75 -0
- package/src/agent/orchestrator/tools/next-call-utils.mjs +48 -0
- package/src/agent/orchestrator/tools/patch-binary-fetcher.mjs +133 -0
- package/src/agent/orchestrator/tools/patch-manifest.json +26 -0
- package/src/agent/orchestrator/tools/patch-tool-defs.mjs +20 -0
- package/src/agent/orchestrator/tools/patch.mjs +2754 -0
- package/src/agent/orchestrator/tools/progress-message.mjs +118 -0
- package/src/agent/orchestrator/tools/result-compression.mjs +279 -0
- package/src/agent/orchestrator/tools/shell-command.mjs +865 -0
- package/src/agent/orchestrator/tools/shell-exec-policy.mjs +89 -0
- package/src/agent/orchestrator/tools/shell-policy-danger-target.mjs +27 -0
- package/src/agent/orchestrator/tools/shell-policy-imports.mjs +7 -0
- package/src/agent/orchestrator/tools/shell-policy.mjs +345 -0
- package/src/agent/orchestrator/tools/shell-snapshot.mjs +313 -0
- package/src/agent/orchestrator/workflow-store.mjs +93 -0
- package/src/agent/tool-defs.mjs +103 -0
- package/src/channels/backends/discord.mjs +784 -0
- package/src/channels/data/voice-runtime-manifest.json +138 -0
- package/src/channels/index.mjs +3229 -0
- package/src/channels/lib/cli-worker-host.mjs +12 -0
- package/src/channels/lib/config-lock.mjs +13 -0
- package/src/channels/lib/config.mjs +292 -0
- package/src/channels/lib/drop-trace.mjs +71 -0
- package/src/channels/lib/event-pipeline.mjs +81 -0
- package/src/channels/lib/event-queue.mjs +345 -0
- package/src/channels/lib/executor.mjs +168 -0
- package/src/channels/lib/format.mjs +188 -0
- package/src/channels/lib/holidays.mjs +138 -0
- package/src/channels/lib/hook-pipe-server.mjs +802 -0
- package/src/channels/lib/interaction-workflows.mjs +184 -0
- package/src/channels/lib/memory-client.mjs +149 -0
- package/src/channels/lib/output-forwarder.mjs +765 -0
- package/src/channels/lib/runtime-paths.mjs +479 -0
- package/src/channels/lib/scheduler.mjs +723 -0
- package/src/channels/lib/session-control.mjs +36 -0
- package/src/channels/lib/session-discovery.mjs +103 -0
- package/src/channels/lib/settings.mjs +11 -0
- package/src/channels/lib/state-file.mjs +68 -0
- package/src/channels/lib/status-snapshot.mjs +219 -0
- package/src/channels/lib/tool-format.mjs +140 -0
- package/src/channels/lib/transcript-discovery.mjs +195 -0
- package/src/channels/lib/voice-runtime-fetcher.mjs +734 -0
- package/src/channels/lib/webhook.mjs +1179 -0
- package/src/channels/lib/whisper-server.mjs +477 -0
- package/src/channels/tool-defs.mjs +170 -0
- package/src/daemon/host.mjs +118 -0
- package/src/daemon/mcp-transport.mjs +47 -0
- package/src/daemon/session.mjs +100 -0
- package/src/daemon/thin-client.mjs +71 -0
- package/src/daemon/transport.mjs +163 -0
- package/src/memory/data/runtime-manifest.json +40 -0
- package/src/memory/index.mjs +3305 -0
- package/src/memory/lib/agent-ipc.mjs +93 -0
- package/src/memory/lib/bridge-trace-queries.mjs +120 -0
- package/src/memory/lib/core-memory-store.mjs +330 -0
- package/src/memory/lib/embedding-provider.mjs +269 -0
- package/src/memory/lib/embedding-worker.mjs +323 -0
- package/src/memory/lib/llm-worker-host.mjs +17 -0
- package/src/memory/lib/memory-cycle.mjs +11 -0
- package/src/memory/lib/memory-cycle1.mjs +641 -0
- package/src/memory/lib/memory-cycle2.mjs +1284 -0
- package/src/memory/lib/memory-cycle3.mjs +540 -0
- package/src/memory/lib/memory-embed.mjs +299 -0
- package/src/memory/lib/memory-extraction.mjs +5 -0
- package/src/memory/lib/memory-maintenance-store.mjs +32 -0
- package/src/memory/lib/memory-ops-policy.mjs +190 -0
- package/src/memory/lib/memory-recall-id-patch.mjs +15 -0
- package/src/memory/lib/memory-recall-read-query.mjs +7 -0
- package/src/memory/lib/memory-recall-scope-filter.mjs +63 -0
- package/src/memory/lib/memory-recall-store.mjs +621 -0
- package/src/memory/lib/memory-retrievers.mjs +112 -0
- package/src/memory/lib/memory-score.mjs +71 -0
- package/src/memory/lib/memory-text-utils.mjs +58 -0
- package/src/memory/lib/memory.mjs +412 -0
- package/src/memory/lib/model-profile.mjs +85 -0
- package/src/memory/lib/pg/adapter.mjs +308 -0
- package/src/memory/lib/pg/process.mjs +360 -0
- package/src/memory/lib/pg/supervisor.mjs +396 -0
- package/src/memory/lib/project-id-resolver.mjs +86 -0
- package/src/memory/lib/runtime-fetcher.mjs +442 -0
- package/src/memory/lib/trace-store.mjs +728 -0
- package/src/memory/tool-defs.mjs +79 -0
- package/src/search/index.mjs +1173 -0
- package/src/search/lib/backends/anthropic-oauth.mjs +98 -0
- package/src/search/lib/backends/exa.mjs +50 -0
- package/src/search/lib/backends/firecrawl.mjs +61 -0
- package/src/search/lib/backends/gemini-api.mjs +83 -0
- package/src/search/lib/backends/grok-oauth.mjs +86 -0
- package/src/search/lib/backends/index.mjs +150 -0
- package/src/search/lib/backends/openai-api.mjs +144 -0
- package/src/search/lib/backends/openai-oauth.mjs +98 -0
- package/src/search/lib/backends/openai-web-search.mjs +76 -0
- package/src/search/lib/backends/tavily.mjs +55 -0
- package/src/search/lib/backends/xai-api.mjs +113 -0
- package/src/search/lib/cache.mjs +131 -0
- package/src/search/lib/config.mjs +192 -0
- package/src/search/lib/formatter.mjs +115 -0
- package/src/search/lib/provider-usage.mjs +67 -0
- package/src/search/lib/providers.mjs +47 -0
- package/src/search/lib/search-intent.mjs +109 -0
- package/src/search/lib/setup-handler.mjs +261 -0
- package/src/search/lib/state.mjs +201 -0
- package/src/search/lib/web-tools.mjs +1207 -0
- package/src/search/tool-defs.mjs +83 -0
- package/src/setup/defender-exclusion.mjs +183 -0
- package/src/shared/abort-controller.mjs +15 -0
- package/src/shared/atomic-file.mjs +420 -0
- package/src/shared/config.mjs +350 -0
- package/src/shared/daemon-recycle.mjs +108 -0
- package/src/shared/disable-claude-builtins.mjs +88 -0
- package/src/shared/err-text.mjs +12 -0
- package/src/shared/llm/cost.mjs +66 -0
- package/src/shared/llm/http-agent.mjs +123 -0
- package/src/shared/llm/index.mjs +41 -0
- package/src/shared/llm/pid-cleanup.mjs +27 -0
- package/src/shared/llm/usage-log.mjs +47 -0
- package/src/shared/plugin-paths.mjs +58 -0
- package/src/shared/schedules-store.mjs +70 -0
- package/src/shared/seed.mjs +119 -0
- package/src/shared/user-cwd.mjs +213 -0
- package/src/shared/user-data-guard.mjs +238 -0
- package/src/status/aggregator.mjs +584 -0
- package/src/status/server.mjs +413 -0
- package/tools.json +1653 -0
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
// notebook_edit — structural Jupyter notebook (.ipynb) cell editor.
|
|
2
|
+
//
|
|
3
|
+
// Mixdog can READ rendered notebooks (extractIpynbText) but had no
|
|
4
|
+
// structural editor: a generic text `edit` against the raw .ipynb JSON is
|
|
5
|
+
// fragile (source is line-split arrays, outputs/execution_count are
|
|
6
|
+
// machine state). This tool parses the notebook JSON, resolves a cell by
|
|
7
|
+
// its real `cell.id` or a numeric `cell-N` index, then replaces / inserts /
|
|
8
|
+
// deletes a cell and writes the JSON back — preserving the on-disk BOM
|
|
9
|
+
// encoding and line endings, and gated behind the same read-before-write
|
|
10
|
+
// snapshot guard as edit/write. Mirrors Claude Code's NotebookEditTool.
|
|
11
|
+
import { readFileSync, statSync } from 'fs';
|
|
12
|
+
import { extname } from 'path';
|
|
13
|
+
import { markCodeGraphDirtyPaths } from '../code-graph.mjs';
|
|
14
|
+
import {
|
|
15
|
+
normalizeInputPath,
|
|
16
|
+
normalizeOutputPath,
|
|
17
|
+
resolveAgainstCwd,
|
|
18
|
+
} from './path-utils.mjs';
|
|
19
|
+
import { normalizeErrorMessage } from './path-diagnostics.mjs';
|
|
20
|
+
import { withPathLock } from './path-locks.mjs';
|
|
21
|
+
import { withAdvisoryLocks } from './advisory-lock.mjs';
|
|
22
|
+
import { hashText } from './hash-utils.mjs';
|
|
23
|
+
import {
|
|
24
|
+
getReadSnapshot,
|
|
25
|
+
isSnapshotStale,
|
|
26
|
+
readContentIfSnapshotHashMatches,
|
|
27
|
+
recordReadSnapshot,
|
|
28
|
+
} from './read-snapshot-runtime.mjs';
|
|
29
|
+
import {
|
|
30
|
+
invalidateBuiltinResultCache,
|
|
31
|
+
seedRawContentCacheAfterWrite,
|
|
32
|
+
} from './cache-layers.mjs';
|
|
33
|
+
import { atomicWrite } from './atomic-write.mjs';
|
|
34
|
+
import { detectExistingEncoding, toWriteBuffer } from './write-tool.mjs';
|
|
35
|
+
import {
|
|
36
|
+
hasUnsafeWin32Component,
|
|
37
|
+
isWindowsDevicePath,
|
|
38
|
+
} from './device-paths.mjs';
|
|
39
|
+
|
|
40
|
+
// Jupyter serialises notebooks with a single-space indent.
|
|
41
|
+
const IPYNB_INDENT = 1;
|
|
42
|
+
|
|
43
|
+
// Parse a "cell-N" synthetic id (the addressing scheme the read renderer
|
|
44
|
+
// exposes for notebooks without real cell ids) into its 0-based index.
|
|
45
|
+
// Returns undefined for anything that is not exactly that shape.
|
|
46
|
+
function parseCellId(cellId) {
|
|
47
|
+
if (typeof cellId !== 'string') return undefined;
|
|
48
|
+
const m = cellId.match(/^cell-(\d+)$/);
|
|
49
|
+
if (!m) return undefined;
|
|
50
|
+
const n = Number.parseInt(m[1], 10);
|
|
51
|
+
return Number.isFinite(n) ? n : undefined;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Decode the raw notebook bytes honouring the leading BOM (same invariant
|
|
55
|
+
// the write path re-applies), and report the dominant line ending so the
|
|
56
|
+
// re-serialised JSON round-trips the file's CRLF/LF convention.
|
|
57
|
+
function readNotebookSource(fullPath) {
|
|
58
|
+
const raw = readFileSync(fullPath);
|
|
59
|
+
let text;
|
|
60
|
+
if (raw.length >= 2 && raw[0] === 0xff && raw[1] === 0xfe) {
|
|
61
|
+
text = raw.subarray(2).toString('utf16le');
|
|
62
|
+
} else if (raw.length >= 3 && raw[0] === 0xef && raw[1] === 0xbb && raw[2] === 0xbf) {
|
|
63
|
+
text = raw.subarray(3).toString('utf-8');
|
|
64
|
+
} else {
|
|
65
|
+
text = raw.toString('utf-8');
|
|
66
|
+
}
|
|
67
|
+
const crlf = (text.match(/\r\n/g) || []).length;
|
|
68
|
+
const lf = (text.match(/\n/g) || []).length;
|
|
69
|
+
const lineEnding = crlf > 0 && crlf >= lf - crlf ? '\r\n' : '\n';
|
|
70
|
+
return { text, lineEnding };
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export async function executeNotebookEditTool(args, workDir, readStateScope, options = {}) {
|
|
74
|
+
if (typeof args.file_path === 'string' && !args.notebook_path) args.notebook_path = args.file_path;
|
|
75
|
+
if (typeof args.path === 'string' && !args.notebook_path) args.notebook_path = args.path;
|
|
76
|
+
|
|
77
|
+
let notebookPath = args.notebook_path;
|
|
78
|
+
if (typeof notebookPath === 'string') notebookPath = normalizeInputPath(notebookPath);
|
|
79
|
+
if (!notebookPath) return 'Error: notebook_path is required';
|
|
80
|
+
|
|
81
|
+
const newSource = args.new_source;
|
|
82
|
+
const cellId = args.cell_id;
|
|
83
|
+
let cellType = args.cell_type;
|
|
84
|
+
const editMode = args.edit_mode === undefined || args.edit_mode === null ? 'replace' : args.edit_mode;
|
|
85
|
+
|
|
86
|
+
if (editMode !== 'replace' && editMode !== 'insert' && editMode !== 'delete') {
|
|
87
|
+
return `Error: edit_mode must be replace, insert, or delete (got ${JSON.stringify(args.edit_mode)})`;
|
|
88
|
+
}
|
|
89
|
+
if (cellType !== undefined && cellType !== 'code' && cellType !== 'markdown') {
|
|
90
|
+
return `Error: cell_type must be code or markdown (got ${JSON.stringify(cellType)})`;
|
|
91
|
+
}
|
|
92
|
+
if (editMode !== 'delete' && typeof newSource !== 'string') {
|
|
93
|
+
return `Error: new_source must be a string for edit_mode=${editMode}`;
|
|
94
|
+
}
|
|
95
|
+
if (editMode === 'insert' && !cellType) {
|
|
96
|
+
return 'Error: cell_type is required when using edit_mode=insert';
|
|
97
|
+
}
|
|
98
|
+
if (editMode !== 'insert' && !cellId) {
|
|
99
|
+
return 'Error: cell_id must be specified when not inserting a new cell';
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// R12: Win32 component / device-name guard before path resolution so a
|
|
103
|
+
// relative path can't be coerced into a device alias or NTFS ADS suffix.
|
|
104
|
+
if (typeof isWindowsDevicePath === 'function' && isWindowsDevicePath(notebookPath)) {
|
|
105
|
+
return `Error: cannot edit Windows device path (reserved name or raw-device namespace): ${normalizeOutputPath(notebookPath)}`;
|
|
106
|
+
}
|
|
107
|
+
if (typeof hasUnsafeWin32Component === 'function' && hasUnsafeWin32Component(notebookPath)) {
|
|
108
|
+
return `Error: cannot edit Windows path with trailing dot/space or NTFS ADS suffix (bypasses device guard): ${normalizeOutputPath(notebookPath)}`;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const fullPath = resolveAgainstCwd(notebookPath, workDir);
|
|
112
|
+
// R1: short-circuit UNC/SMB paths before any fs probe to prevent NTLM
|
|
113
|
+
// credential leakage via implicit network auth.
|
|
114
|
+
if (fullPath.startsWith('\\\\') || fullPath.startsWith('//')) {
|
|
115
|
+
return `Error: UNC/SMB paths are not supported (R1: NTLM-leak prevention): ${notebookPath}`;
|
|
116
|
+
}
|
|
117
|
+
if (typeof isWindowsDevicePath === 'function' && isWindowsDevicePath(fullPath)) {
|
|
118
|
+
return `Error: cannot edit Windows device path (reserved name or raw-device namespace): ${normalizeOutputPath(notebookPath)}`;
|
|
119
|
+
}
|
|
120
|
+
if (typeof hasUnsafeWin32Component === 'function' && hasUnsafeWin32Component(fullPath)) {
|
|
121
|
+
return `Error: cannot edit Windows path with trailing dot/space or NTFS ADS suffix (bypasses device guard): ${normalizeOutputPath(notebookPath)}`;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (extname(fullPath).toLowerCase() !== '.ipynb') {
|
|
125
|
+
return `Error: file must be a Jupyter notebook (.ipynb). For other file types use edit/write: ${normalizeOutputPath(notebookPath)}`;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return withPathLock(fullPath, () =>
|
|
129
|
+
withAdvisoryLocks([fullPath], async () => {
|
|
130
|
+
let existing;
|
|
131
|
+
try {
|
|
132
|
+
existing = statSync(fullPath);
|
|
133
|
+
} catch (err) {
|
|
134
|
+
if (err && err.code === 'ENOENT') {
|
|
135
|
+
return `Error: notebook file does not exist: ${normalizeOutputPath(notebookPath)}`;
|
|
136
|
+
}
|
|
137
|
+
return `Error: stat failed before edit: ${normalizeErrorMessage(err instanceof Error ? err.message : String(err))}: ${notebookPath}`;
|
|
138
|
+
}
|
|
139
|
+
if (!existing.isFile()) {
|
|
140
|
+
return `Error: notebook path is not a regular file: ${normalizeOutputPath(notebookPath)}`;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// Read-before-write guard (parity with edit/write): the notebook
|
|
144
|
+
// must have been read this session, and not changed since, or a
|
|
145
|
+
// structural edit could clobber an unseen / externally-modified file.
|
|
146
|
+
const snapshot = getReadSnapshot(fullPath, readStateScope);
|
|
147
|
+
if (!snapshot) {
|
|
148
|
+
return `Error [code 6]: notebook has not been read yet — read it first before editing: ${normalizeOutputPath(notebookPath)}`;
|
|
149
|
+
}
|
|
150
|
+
if (isSnapshotStale(existing, snapshot, fullPath)) {
|
|
151
|
+
const hashOk = readContentIfSnapshotHashMatches(fullPath, snapshot, null, existing);
|
|
152
|
+
if (hashOk === null) {
|
|
153
|
+
return `Error [code 7]: notebook modified since read — read it again before editing: ${normalizeOutputPath(notebookPath)}`;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
let originalText;
|
|
158
|
+
let lineEnding;
|
|
159
|
+
try {
|
|
160
|
+
({ text: originalText, lineEnding } = readNotebookSource(fullPath));
|
|
161
|
+
} catch (err) {
|
|
162
|
+
return `Error: failed to read notebook: ${normalizeErrorMessage(err instanceof Error ? err.message : String(err))}: ${notebookPath}`;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
let notebook;
|
|
166
|
+
try {
|
|
167
|
+
notebook = JSON.parse(originalText);
|
|
168
|
+
} catch {
|
|
169
|
+
return `Error: notebook is not valid JSON: ${normalizeOutputPath(notebookPath)}`;
|
|
170
|
+
}
|
|
171
|
+
if (!notebook || !Array.isArray(notebook.cells)) {
|
|
172
|
+
return `Error: notebook JSON has no "cells" array: ${normalizeOutputPath(notebookPath)}`;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// Resolve target cell index: real cell.id first, then cell-N index.
|
|
176
|
+
let cellIndex;
|
|
177
|
+
if (!cellId) {
|
|
178
|
+
cellIndex = 0; // insert-at-start default
|
|
179
|
+
} else {
|
|
180
|
+
cellIndex = notebook.cells.findIndex((cell) => cell && cell.id === cellId);
|
|
181
|
+
if (cellIndex === -1) {
|
|
182
|
+
const parsed = parseCellId(cellId);
|
|
183
|
+
if (parsed !== undefined) {
|
|
184
|
+
// Mode-aware bound (matches NotebookEditTool semantics):
|
|
185
|
+
// insert may address the append slot (index ===
|
|
186
|
+
// cells.length) to add a cell at the very end;
|
|
187
|
+
// replace/delete require an EXISTING cell
|
|
188
|
+
// [0 .. cells.length-1], so a past-end index errors.
|
|
189
|
+
const maxIndex = editMode === 'insert'
|
|
190
|
+
? notebook.cells.length
|
|
191
|
+
: notebook.cells.length - 1;
|
|
192
|
+
if (parsed < 0 || parsed > maxIndex) {
|
|
193
|
+
return `Error: cell with index ${parsed} does not exist in notebook (${notebook.cells.length} cells)`;
|
|
194
|
+
}
|
|
195
|
+
cellIndex = parsed;
|
|
196
|
+
} else {
|
|
197
|
+
return `Error: cell with ID "${cellId}" not found in notebook`;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
// Insert lands AFTER the referenced cell. When the index is the
|
|
201
|
+
// append slot (=== cells.length) there is no referenced cell to
|
|
202
|
+
// sit after, so leave it as-is to append at the very end.
|
|
203
|
+
if (editMode === 'insert' && cellIndex < notebook.cells.length) {
|
|
204
|
+
cellIndex += 1;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// Insert at the append slot (index === cells.length) adds a cell at
|
|
209
|
+
// the very end — this is the reachable "add a cell at the end" path.
|
|
210
|
+
// replace/delete past-end already errored at the bound check above.
|
|
211
|
+
let effectiveMode = editMode;
|
|
212
|
+
|
|
213
|
+
// Only mint a real cell id when the notebook format supports it
|
|
214
|
+
// (nbformat 4.5+ / >4), matching how Jupyter assigns cell ids.
|
|
215
|
+
const supportsCellId =
|
|
216
|
+
notebook.nbformat > 4 ||
|
|
217
|
+
(notebook.nbformat === 4 && (notebook.nbformat_minor ?? 0) >= 5);
|
|
218
|
+
let resultCellId;
|
|
219
|
+
if (supportsCellId) {
|
|
220
|
+
resultCellId = effectiveMode === 'insert'
|
|
221
|
+
? Math.random().toString(36).substring(2, 15)
|
|
222
|
+
: cellId;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
if (effectiveMode === 'delete') {
|
|
226
|
+
notebook.cells.splice(cellIndex, 1);
|
|
227
|
+
} else if (effectiveMode === 'insert') {
|
|
228
|
+
const newCell = cellType === 'markdown'
|
|
229
|
+
? { cell_type: 'markdown', metadata: {}, source: newSource }
|
|
230
|
+
: { cell_type: 'code', metadata: {}, execution_count: null, outputs: [], source: newSource };
|
|
231
|
+
if (supportsCellId) newCell.id = resultCellId;
|
|
232
|
+
notebook.cells.splice(cellIndex, 0, newCell);
|
|
233
|
+
} else {
|
|
234
|
+
const targetCell = notebook.cells[cellIndex];
|
|
235
|
+
if (!targetCell) {
|
|
236
|
+
return `Error: cell at index ${cellIndex} does not exist in notebook`;
|
|
237
|
+
}
|
|
238
|
+
targetCell.source = newSource;
|
|
239
|
+
// A MODIFIED code cell's prior run state is invalid: reset
|
|
240
|
+
// execution_count and clear THIS cell's outputs only; every
|
|
241
|
+
// other cell's structure/outputs is left untouched.
|
|
242
|
+
if (targetCell.cell_type === 'code') {
|
|
243
|
+
targetCell.execution_count = null;
|
|
244
|
+
targetCell.outputs = [];
|
|
245
|
+
}
|
|
246
|
+
if (cellType && cellType !== targetCell.cell_type) {
|
|
247
|
+
targetCell.cell_type = cellType;
|
|
248
|
+
// Switching to code requires the code-cell machine fields;
|
|
249
|
+
// switching to markdown drops them.
|
|
250
|
+
if (cellType === 'code') {
|
|
251
|
+
if (targetCell.execution_count === undefined) targetCell.execution_count = null;
|
|
252
|
+
if (!Array.isArray(targetCell.outputs)) targetCell.outputs = [];
|
|
253
|
+
} else {
|
|
254
|
+
delete targetCell.execution_count;
|
|
255
|
+
delete targetCell.outputs;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
let updatedText = JSON.stringify(notebook, null, IPYNB_INDENT);
|
|
261
|
+
// Preserve the file's line-ending convention. JSON.stringify only
|
|
262
|
+
// emits \n; re-apply CRLF when the original used it.
|
|
263
|
+
if (lineEnding === '\r\n') updatedText = updatedText.replace(/\n/g, '\r\n');
|
|
264
|
+
|
|
265
|
+
// Re-encode honouring the on-disk BOM (utf16le / utf8+BOM / utf8).
|
|
266
|
+
const writeContent = toWriteBuffer(updatedText, detectExistingEncoding(fullPath));
|
|
267
|
+
|
|
268
|
+
try {
|
|
269
|
+
await atomicWrite(fullPath, writeContent, { sessionId: options?.sessionId });
|
|
270
|
+
} catch (err) {
|
|
271
|
+
return `Error: ${normalizeErrorMessage(err instanceof Error ? err.message : String(err))}`;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
let writtenStat = null;
|
|
275
|
+
try { writtenStat = statSync(fullPath); } catch {}
|
|
276
|
+
// Refresh the read snapshot post-write (matches edit/write) so a
|
|
277
|
+
// follow-up read/edit in the same instant isn't blocked or stale.
|
|
278
|
+
recordReadSnapshot(fullPath, writtenStat || undefined, readStateScope, {
|
|
279
|
+
source: 'write',
|
|
280
|
+
contentHash: hashText(writeContent),
|
|
281
|
+
replaceExisting: true,
|
|
282
|
+
});
|
|
283
|
+
invalidateBuiltinResultCache([fullPath]);
|
|
284
|
+
seedRawContentCacheAfterWrite(fullPath, writeContent, writtenStat);
|
|
285
|
+
markCodeGraphDirtyPaths([fullPath]);
|
|
286
|
+
|
|
287
|
+
const cellLabel = resultCellId || (cellId ?? `cell-${cellIndex}`);
|
|
288
|
+
switch (effectiveMode) {
|
|
289
|
+
case 'insert':
|
|
290
|
+
return `Inserted ${cellType || 'code'} cell ${cellLabel} in ${normalizeOutputPath(notebookPath)}`;
|
|
291
|
+
case 'delete':
|
|
292
|
+
return `Deleted cell ${cellId} in ${normalizeOutputPath(notebookPath)}`;
|
|
293
|
+
default:
|
|
294
|
+
return `Updated cell ${cellLabel} in ${normalizeOutputPath(notebookPath)}`;
|
|
295
|
+
}
|
|
296
|
+
})
|
|
297
|
+
);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
export default executeNotebookEditTool;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// open_config builtin tool.
|
|
2
|
+
//
|
|
3
|
+
// Lives in the always-on `builtin` module (not the gated `agent` module) so
|
|
4
|
+
// the config UI stays reachable even when modules.agent.enabled === false —
|
|
5
|
+
// otherwise a user who disabled the agent module would lose every way to open
|
|
6
|
+
// the settings UI (the old `bun launch.mjs` slash shell-out is gone).
|
|
7
|
+
//
|
|
8
|
+
// Launches the config UI through the resident MCP server. Because this server
|
|
9
|
+
// is a long-lived background process, its spawn of setup-server
|
|
10
|
+
// (windowsHide:true inside launch-core) creates NO console window — unlike the
|
|
11
|
+
// old `!bun launch.mjs` slash-command shell-out, which flashed a conhost. The
|
|
12
|
+
// launch-core import is lazy so its child_process/http deps stay off the hot
|
|
13
|
+
// builtin path until the tool is actually called.
|
|
14
|
+
|
|
15
|
+
export async function executeOpenConfigTool() {
|
|
16
|
+
const { launchConfigUi, LaunchError } = await import(
|
|
17
|
+
new URL('../../../../../setup/launch-core.mjs', import.meta.url).href
|
|
18
|
+
);
|
|
19
|
+
try {
|
|
20
|
+
const url = await launchConfigUi();
|
|
21
|
+
return `Config UI opened at ${url}`;
|
|
22
|
+
} catch (err) {
|
|
23
|
+
if (err instanceof LaunchError) return `Error: ${err.message.trim()}`;
|
|
24
|
+
throw err;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { readdirSync } from 'fs';
|
|
2
|
+
import { basename, dirname, extname, isAbsolute, join, relative } from 'path';
|
|
3
|
+
import { homedir } from 'os';
|
|
4
|
+
|
|
5
|
+
// Suggest a sibling file the caller may have meant when the requested
|
|
6
|
+
// path is missing: same stem with a different extension, or a same-name
|
|
7
|
+
// sibling differing only in case. Pure best-effort; any fs error returns
|
|
8
|
+
// null so the caller falls back to the bare "not found" message.
|
|
9
|
+
export function findSimilarFile(fullPath) {
|
|
10
|
+
try {
|
|
11
|
+
const dir = dirname(fullPath);
|
|
12
|
+
const base = basename(fullPath);
|
|
13
|
+
const stem = basename(fullPath, extname(fullPath));
|
|
14
|
+
const entries = readdirSync(dir);
|
|
15
|
+
const sameStem = entries.find((e) => e !== base && basename(e, extname(e)) === stem);
|
|
16
|
+
if (sameStem) return join(dir, sameStem);
|
|
17
|
+
const caseMatch = entries.find((e) => e !== base && e.toLowerCase() === base.toLowerCase());
|
|
18
|
+
if (caseMatch) return join(dir, caseMatch);
|
|
19
|
+
return null;
|
|
20
|
+
} catch { return null; }
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Sibling listing for ENOENT diagnostics. Pure information extension —
|
|
24
|
+
// callers always receive the directory's existing entries (capped) inline
|
|
25
|
+
// in the error hint, removing the recovery cost of a follow-up list/glob
|
|
26
|
+
// call. Measurement showed ENOENT recovery consistently runs read→glob/
|
|
27
|
+
// list→read (4-call); siblings inline collapses that to read→read.
|
|
28
|
+
export function listSiblings(dir, limit = 12) {
|
|
29
|
+
try {
|
|
30
|
+
return readdirSync(dir).filter((n) => !n.startsWith('.')).slice(0, limit);
|
|
31
|
+
} catch { return []; }
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Locate a missing file's basename ELSEWHERE under the search root. The most
|
|
35
|
+
// common ENOENT cause is a right-name / wrong-directory path (e.g. asking for
|
|
36
|
+
// `webhook.mjs` when the file lives at `src/channels/lib/webhook.mjs`).
|
|
37
|
+
// findSimilarFile only inspects the same directory, so a wrong-directory miss
|
|
38
|
+
// gets no hint and the caller reconstructs the real path with a grep/glob
|
|
39
|
+
// storm. This walks the root (BFS — shallow hits first), skipping noise dirs
|
|
40
|
+
// and hard-capped on directories scanned, and returns up to `limit` real
|
|
41
|
+
// locations so the error can name them directly. Pure best-effort; any error
|
|
42
|
+
// returns [].
|
|
43
|
+
const BASENAME_SCAN_SKIP_DIRS = new Set([
|
|
44
|
+
'node_modules', '.git', '.hg', '.svn', 'dist', 'build', 'out',
|
|
45
|
+
'coverage', '.next', '.nuxt', '.turbo', '.cache', 'vendor',
|
|
46
|
+
'target', '.venv', 'venv', '__pycache__', '.idea', '.vscode',
|
|
47
|
+
]);
|
|
48
|
+
export function findFileByBasename(searchRoot, fullPath, { limit = 3, maxDirs = 6000 } = {}) {
|
|
49
|
+
try {
|
|
50
|
+
if (typeof searchRoot !== 'string' || !searchRoot) return [];
|
|
51
|
+
const target = basename(fullPath).toLowerCase();
|
|
52
|
+
if (!target) return [];
|
|
53
|
+
const matches = [];
|
|
54
|
+
const queue = [searchRoot];
|
|
55
|
+
let scanned = 0;
|
|
56
|
+
while (queue.length && matches.length < limit && scanned < maxDirs) {
|
|
57
|
+
const dir = queue.shift();
|
|
58
|
+
scanned++;
|
|
59
|
+
let entries;
|
|
60
|
+
try { entries = readdirSync(dir, { withFileTypes: true }); }
|
|
61
|
+
catch { continue; }
|
|
62
|
+
for (const ent of entries) {
|
|
63
|
+
const name = ent.name;
|
|
64
|
+
if (ent.isDirectory()) {
|
|
65
|
+
if (name.startsWith('.') || BASENAME_SCAN_SKIP_DIRS.has(name)) continue;
|
|
66
|
+
queue.push(join(dir, name));
|
|
67
|
+
} else if (ent.isFile() && name.toLowerCase() === target) {
|
|
68
|
+
const hit = join(dir, name);
|
|
69
|
+
if (hit !== fullPath) {
|
|
70
|
+
// Return search-root-relative so the hint stays leak-safe
|
|
71
|
+
// (no home / cache absolute) and is directly read-usable.
|
|
72
|
+
matches.push(relative(searchRoot, hit));
|
|
73
|
+
if (matches.length >= limit) break;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return matches;
|
|
79
|
+
} catch { return []; }
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Node's native fs errors embed the failing path wrapped in single quotes
|
|
83
|
+
// using OS-native separators ('C:\\Users\\foo\\bar.mjs' on Windows). Without
|
|
84
|
+
// this pass, read error bodies surface backslash paths that
|
|
85
|
+
// break the forward-slash convention the rest of the tool output keeps.
|
|
86
|
+
// Accepts an optional workDir to produce cwd-relative paths. This pass also
|
|
87
|
+
// closes the R14 tool-result info-leak boundary: home dir / plugin root /
|
|
88
|
+
// plugin data / runtime dir absolutes are rewritten into stable tokens so
|
|
89
|
+
// model-facing error bodies never carry environment-specific filesystem
|
|
90
|
+
// segments. Full detail is retained in local logs upstream of this call.
|
|
91
|
+
//
|
|
92
|
+
// Replacement priority for any absolute path encountered:
|
|
93
|
+
// 1. cwd-relative (workDir set and path is inside workDir)
|
|
94
|
+
// 2. <runtime>/... (CLAUDE_PLUGIN_RUNTIME prefix)
|
|
95
|
+
// 3. <plugin-data>/... (CLAUDE_PLUGIN_DATA prefix)
|
|
96
|
+
// 4. <plugin-root>/... (CLAUDE_PLUGIN_ROOT prefix)
|
|
97
|
+
// 5. ~/... (OS home directory prefix)
|
|
98
|
+
// 6. forward-slash normalised absolute (Windows backslash → slash, no leak)
|
|
99
|
+
//
|
|
100
|
+
// Two surface forms are scrubbed:
|
|
101
|
+
// * quoted drive-letter / POSIX absolute paths inside the message body
|
|
102
|
+
// * bare `file:///C:/...` or `file:///abs/...` stack-frame URIs (no quotes)
|
|
103
|
+
// More-specific prefixes are checked first so plugin-data wins over the
|
|
104
|
+
// containing home directory.
|
|
105
|
+
export function normalizeErrorMessage(msg, workDir) {
|
|
106
|
+
if (typeof msg !== 'string') return msg;
|
|
107
|
+
const home = homedir().replace(/\\/g, '/');
|
|
108
|
+
const pluginRoot = (process.env.CLAUDE_PLUGIN_ROOT || '').replace(/\\/g, '/');
|
|
109
|
+
const pluginData = (process.env.CLAUDE_PLUGIN_DATA || '').replace(/\\/g, '/');
|
|
110
|
+
const runtimeDir = (process.env.CLAUDE_PLUGIN_RUNTIME || '').replace(/\\/g, '/');
|
|
111
|
+
const cwd = typeof workDir === 'string' && workDir ? workDir.replace(/\\/g, '/') : '';
|
|
112
|
+
|
|
113
|
+
const redact = (raw) => {
|
|
114
|
+
const fwd = raw.replace(/\\/g, '/');
|
|
115
|
+
if (cwd) {
|
|
116
|
+
try {
|
|
117
|
+
const rel = relative(cwd, fwd);
|
|
118
|
+
if (rel && !rel.startsWith('..') && !isAbsolute(rel)) {
|
|
119
|
+
return rel.replace(/\\/g, '/');
|
|
120
|
+
}
|
|
121
|
+
} catch { /* fall through */ }
|
|
122
|
+
}
|
|
123
|
+
if (runtimeDir && (fwd === runtimeDir || fwd.startsWith(runtimeDir + '/'))) {
|
|
124
|
+
return `<runtime>${fwd.slice(runtimeDir.length)}`;
|
|
125
|
+
}
|
|
126
|
+
if (pluginData && (fwd === pluginData || fwd.startsWith(pluginData + '/'))) {
|
|
127
|
+
return `<plugin-data>${fwd.slice(pluginData.length)}`;
|
|
128
|
+
}
|
|
129
|
+
if (pluginRoot && (fwd === pluginRoot || fwd.startsWith(pluginRoot + '/'))) {
|
|
130
|
+
return `<plugin-root>${fwd.slice(pluginRoot.length)}`;
|
|
131
|
+
}
|
|
132
|
+
if (home && (fwd === home || fwd.startsWith(home + '/'))) {
|
|
133
|
+
return `~${fwd.slice(home.length)}`;
|
|
134
|
+
}
|
|
135
|
+
return fwd;
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
// 1. Strip bare `file:///...` stack-frame URIs first so the inner path
|
|
139
|
+
// survives the quoted-path pass that follows (URIs aren't quoted).
|
|
140
|
+
let out = msg.replace(
|
|
141
|
+
/file:\/\/\/([A-Za-z]:\/[^\s'"<>)\]]+|\/[^\s'"<>)\]]+)/g,
|
|
142
|
+
(_m, p) => redact(p),
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
// 2. Redact quoted drive-letter (Windows) and POSIX absolute paths.
|
|
146
|
+
out = out.replace(
|
|
147
|
+
/(['"])([A-Za-z]:[\\\/][^'"]+|\/[^'"]+)\1/g,
|
|
148
|
+
(_m, q, p) => `${q}${redact(p)}${q}`,
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
return out;
|
|
152
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// Per-path mutex for concurrent Edit/Write operations. Maps absPath → Promise
|
|
2
|
+
// chain so that overlapping calls for the same file are serialised in-process.
|
|
3
|
+
const editLocks = new Map();
|
|
4
|
+
|
|
5
|
+
export function pathLockKey(absPath) {
|
|
6
|
+
const text = String(absPath || '');
|
|
7
|
+
return process.platform === 'win32' ? text.toLowerCase() : text;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function withPathLock(absPath, fn) {
|
|
11
|
+
const lockKey = pathLockKey(absPath);
|
|
12
|
+
const prev = editLocks.get(lockKey) ?? Promise.resolve();
|
|
13
|
+
const next = prev.then(fn, fn); // pass through errors so chain never stalls
|
|
14
|
+
editLocks.set(lockKey, next.then(
|
|
15
|
+
() => { if (editLocks.get(lockKey) === next) editLocks.delete(lockKey); },
|
|
16
|
+
() => { if (editLocks.get(lockKey) === next) editLocks.delete(lockKey); },
|
|
17
|
+
));
|
|
18
|
+
return next;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function withBuiltinPathLocks(paths, fn) {
|
|
22
|
+
const keyed = new Map();
|
|
23
|
+
for (const p of Array.isArray(paths) ? paths : [paths]) {
|
|
24
|
+
if (!p) continue;
|
|
25
|
+
keyed.set(pathLockKey(p), String(p));
|
|
26
|
+
}
|
|
27
|
+
const sorted = [...keyed.entries()]
|
|
28
|
+
.sort((a, b) => a[0].localeCompare(b[0]))
|
|
29
|
+
.map((entry) => entry[1]);
|
|
30
|
+
const run = (idx) => {
|
|
31
|
+
if (idx >= sorted.length) return fn();
|
|
32
|
+
return withPathLock(sorted[idx], () => run(idx + 1));
|
|
33
|
+
};
|
|
34
|
+
return run(0);
|
|
35
|
+
}
|