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,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Repro: malformed mixdog-config.json + writeSection('search', …) must not
|
|
3
|
+
* wipe channels/memory/agent; restores from backup or throws.
|
|
4
|
+
*/
|
|
5
|
+
import assert from 'node:assert/strict';
|
|
6
|
+
import {
|
|
7
|
+
mkdtempSync,
|
|
8
|
+
mkdirSync,
|
|
9
|
+
writeFileSync,
|
|
10
|
+
readFileSync,
|
|
11
|
+
rmSync,
|
|
12
|
+
} from 'fs';
|
|
13
|
+
import { tmpdir } from 'os';
|
|
14
|
+
import { join, dirname } from 'path';
|
|
15
|
+
import { fileURLToPath } from 'url';
|
|
16
|
+
|
|
17
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
18
|
+
|
|
19
|
+
async function loadConfigModule(dataDir, backupRoot) {
|
|
20
|
+
process.env.CLAUDE_PLUGIN_DATA = dataDir;
|
|
21
|
+
process.env.MIXDOG_USER_DATA_BACKUP_ROOT = backupRoot;
|
|
22
|
+
process.env.MIXDOG_SKIP_USER_DATA_BACKUP = '1';
|
|
23
|
+
const url = new URL(`../src/shared/config.mjs?run=${Date.now()}`, import.meta.url).href;
|
|
24
|
+
return import(url);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function writeConfig(dataDir, obj) {
|
|
28
|
+
writeFileSync(
|
|
29
|
+
join(dataDir, 'mixdog-config.json'),
|
|
30
|
+
JSON.stringify(obj, null, 2) + '\n',
|
|
31
|
+
'utf8',
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async function main() {
|
|
36
|
+
const dataDir = mkdtempSync(join(tmpdir(), 'mixdog-config-rmw-'));
|
|
37
|
+
const backupRoot = mkdtempSync(join(tmpdir(), 'mixdog-config-backup-'));
|
|
38
|
+
|
|
39
|
+
const prior = {
|
|
40
|
+
channels: { guild: '111' },
|
|
41
|
+
memory: { enabled: true },
|
|
42
|
+
agent: { presets: { default: { model: 'x' } } },
|
|
43
|
+
};
|
|
44
|
+
writeConfig(dataDir, prior);
|
|
45
|
+
|
|
46
|
+
process.env.CLAUDE_PLUGIN_DATA = dataDir;
|
|
47
|
+
process.env.MIXDOG_USER_DATA_BACKUP_ROOT = backupRoot;
|
|
48
|
+
const guardUrl = new URL(`../src/shared/user-data-guard.mjs?t=${Date.now()}`, import.meta.url).href;
|
|
49
|
+
const { backupUserData, markUserDataInitialized } = await import(guardUrl);
|
|
50
|
+
const snap = backupUserData(dataDir, 'test-fixture');
|
|
51
|
+
assert.ok(snap.dir, 'backup fixture should copy mixdog-config.json');
|
|
52
|
+
|
|
53
|
+
writeFileSync(join(dataDir, 'mixdog-config.json'), '{ not valid json\n', 'utf8');
|
|
54
|
+
|
|
55
|
+
const { writeSection } = await loadConfigModule(dataDir, backupRoot);
|
|
56
|
+
writeSection('search', { provider: 'brave' });
|
|
57
|
+
|
|
58
|
+
const onDisk = JSON.parse(readFileSync(join(dataDir, 'mixdog-config.json'), 'utf8'));
|
|
59
|
+
assert.deepEqual(onDisk.channels, prior.channels);
|
|
60
|
+
assert.deepEqual(onDisk.memory, prior.memory);
|
|
61
|
+
assert.deepEqual(onDisk.agent, prior.agent);
|
|
62
|
+
assert.deepEqual(onDisk.search, { provider: 'brave' });
|
|
63
|
+
|
|
64
|
+
const freshDir = mkdtempSync(join(tmpdir(), 'mixdog-config-fresh-'));
|
|
65
|
+
const { writeSection: writeFresh } = await loadConfigModule(freshDir, backupRoot);
|
|
66
|
+
writeFresh('search', { only: true });
|
|
67
|
+
const freshDisk = JSON.parse(readFileSync(join(freshDir, 'mixdog-config.json'), 'utf8'));
|
|
68
|
+
assert.deepEqual(freshDisk, { search: { only: true } });
|
|
69
|
+
|
|
70
|
+
const noBackupDir = mkdtempSync(join(tmpdir(), 'mixdog-config-noback-'));
|
|
71
|
+
markUserDataInitialized(noBackupDir);
|
|
72
|
+
writeFileSync(join(noBackupDir, 'mixdog-config.json'), '[]', 'utf8');
|
|
73
|
+
const { writeSection: writeNoBackup } = await loadConfigModule(
|
|
74
|
+
noBackupDir,
|
|
75
|
+
mkdtempSync(join(tmpdir(), 'empty-backup-')),
|
|
76
|
+
);
|
|
77
|
+
let threw = false;
|
|
78
|
+
try {
|
|
79
|
+
writeNoBackup('search', { x: 1 });
|
|
80
|
+
} catch (err) {
|
|
81
|
+
threw = true;
|
|
82
|
+
assert.match(String(err.message), /refusing section write/);
|
|
83
|
+
}
|
|
84
|
+
assert.equal(threw, true, 'malformed config with init marker and no backup must throw');
|
|
85
|
+
|
|
86
|
+
const pickRoot = mkdtempSync(join(tmpdir(), 'mixdog-config-pick-'));
|
|
87
|
+
const fullCfg = {
|
|
88
|
+
channels: { guild: '222' },
|
|
89
|
+
memory: { enabled: false },
|
|
90
|
+
agent: { presets: {} },
|
|
91
|
+
};
|
|
92
|
+
const oldDir = join(pickRoot, '2026-06-03T19-00-00-000Z-old-full');
|
|
93
|
+
const newDir = join(pickRoot, '2026-06-03T21-00-00-000Z-new-degenerate');
|
|
94
|
+
mkdirSync(oldDir, { recursive: true });
|
|
95
|
+
mkdirSync(newDir, { recursive: true });
|
|
96
|
+
writeFileSync(join(oldDir, 'mixdog-config.json'), JSON.stringify(fullCfg) + '\n', 'utf8');
|
|
97
|
+
writeFileSync(
|
|
98
|
+
join(newDir, 'mixdog-config.json'),
|
|
99
|
+
JSON.stringify({ search: { provider: 'tavily' } }) + '\n',
|
|
100
|
+
'utf8',
|
|
101
|
+
);
|
|
102
|
+
process.env.MIXDOG_USER_DATA_BACKUP_ROOT = pickRoot;
|
|
103
|
+
const pickUrl = new URL(`../src/shared/user-data-guard.mjs?pick=${Date.now()}`, import.meta.url).href;
|
|
104
|
+
const { loadLatestMixdogConfigFromBackup } = await import(pickUrl);
|
|
105
|
+
const picked = loadLatestMixdogConfigFromBackup(null);
|
|
106
|
+
assert.deepEqual(picked?.channels, fullCfg.channels);
|
|
107
|
+
assert.deepEqual(picked?.agent, fullCfg.agent);
|
|
108
|
+
assert.equal(picked?.search, undefined, 'must not restore newest search-only snapshot');
|
|
109
|
+
rmSync(pickRoot, { recursive: true, force: true });
|
|
110
|
+
|
|
111
|
+
rmSync(dataDir, { recursive: true, force: true });
|
|
112
|
+
rmSync(backupRoot, { recursive: true, force: true });
|
|
113
|
+
rmSync(freshDir, { recursive: true, force: true });
|
|
114
|
+
rmSync(noBackupDir, { recursive: true, force: true });
|
|
115
|
+
|
|
116
|
+
console.log('test-config-rmw-restore: ok');
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
main().catch((err) => {
|
|
120
|
+
console.error(err);
|
|
121
|
+
process.exit(1);
|
|
122
|
+
});
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
// Fault-injection test: a victim acquires the advisory lock then is SIGKILL'd
|
|
2
|
+
// (release never runs). Followers must detect the orphan via isPidAlive=false,
|
|
3
|
+
// cleanup the lockfile, and succeed.
|
|
4
|
+
import { spawn } from 'child_process';
|
|
5
|
+
import {
|
|
6
|
+
mkdtempSync, writeFileSync, readFileSync, existsSync, statSync,
|
|
7
|
+
readdirSync, rmSync,
|
|
8
|
+
} from 'fs';
|
|
9
|
+
import { tmpdir } from 'os';
|
|
10
|
+
import { join, dirname, basename } from 'path';
|
|
11
|
+
import { fileURLToPath } from 'url';
|
|
12
|
+
import { performance } from 'perf_hooks';
|
|
13
|
+
|
|
14
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
15
|
+
const __dirname = dirname(__filename);
|
|
16
|
+
const repoRoot = dirname(__dirname);
|
|
17
|
+
|
|
18
|
+
const atomicModUrl = 'file://' + join(repoRoot, 'src/agent/orchestrator/tools/builtin/atomic-write.mjs').replace(/\\/g, '/');
|
|
19
|
+
const lockModUrl = 'file://' + join(repoRoot, 'src/agent/orchestrator/tools/builtin/advisory-lock.mjs').replace(/\\/g, '/');
|
|
20
|
+
|
|
21
|
+
function snapshot(p) {
|
|
22
|
+
try {
|
|
23
|
+
const s = statSync(p);
|
|
24
|
+
return { exists: true, size: s.size, mtimeMs: s.mtimeMs, ino: s.ino };
|
|
25
|
+
} catch { return { exists: false }; }
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// --- Victim mode ---
|
|
29
|
+
if (process.argv[2] === '--victim') {
|
|
30
|
+
const target = process.argv[3];
|
|
31
|
+
const { acquireAdvisoryLock } = await import(lockModUrl);
|
|
32
|
+
const handle = await acquireAdvisoryLock(target, { timeoutMs: 5000 });
|
|
33
|
+
process.stdout.write(JSON.stringify({
|
|
34
|
+
event: 'acquired', pid: process.pid, lockFile: handle.lockFile,
|
|
35
|
+
}) + '\n');
|
|
36
|
+
// Block forever — parent will SIGKILL
|
|
37
|
+
await new Promise(() => { /* never resolves */ });
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// --- Follower mode ---
|
|
41
|
+
if (process.argv[2] === '--follower') {
|
|
42
|
+
const target = process.argv[3];
|
|
43
|
+
const content = process.argv[4];
|
|
44
|
+
const { atomicWrite } = await import(atomicModUrl);
|
|
45
|
+
const { acquireAdvisoryLock } = await import(lockModUrl);
|
|
46
|
+
const t0 = performance.now();
|
|
47
|
+
try {
|
|
48
|
+
const acquireT0 = Date.now();
|
|
49
|
+
const handle = await acquireAdvisoryLock(target, { timeoutMs: 15000 });
|
|
50
|
+
const acquireT1 = Date.now();
|
|
51
|
+
try {
|
|
52
|
+
await atomicWrite(target, content, { expectedTargetSnapshot: snapshot(target) });
|
|
53
|
+
} finally { handle.release(); }
|
|
54
|
+
const dt = +(performance.now() - t0).toFixed(2);
|
|
55
|
+
process.stdout.write(JSON.stringify({
|
|
56
|
+
ok: true, pid: process.pid, dt, acquireMs: acquireT1 - acquireT0,
|
|
57
|
+
}) + '\n');
|
|
58
|
+
process.exit(0);
|
|
59
|
+
} catch (err) {
|
|
60
|
+
process.stdout.write(JSON.stringify({
|
|
61
|
+
ok: false, code: err.code, msg: String(err.message).slice(0, 150), pid: process.pid,
|
|
62
|
+
}) + '\n');
|
|
63
|
+
process.exit(1);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// --- Driver ---
|
|
68
|
+
const dir = mkdtempSync(join(tmpdir(), 'fault-inject-'));
|
|
69
|
+
const target = join(dir, 'target.txt');
|
|
70
|
+
writeFileSync(target, 'INITIAL\n');
|
|
71
|
+
const lockFile = join(dir, '.target.txt.mixdog-lock');
|
|
72
|
+
|
|
73
|
+
console.log('=== Fault injection: victim SIGKILL + 5 followers ===');
|
|
74
|
+
console.log('dir=' + dir);
|
|
75
|
+
|
|
76
|
+
// 1. Spawn victim, wait for acquire signal
|
|
77
|
+
const victim = spawn(process.execPath, [__filename, '--victim', target], {
|
|
78
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
79
|
+
});
|
|
80
|
+
let victimOut = '';
|
|
81
|
+
victim.stdout.on('data', d => { victimOut += d; });
|
|
82
|
+
// Pre-attach the close listener BEFORE kill — otherwise SIGKILL fires the
|
|
83
|
+
// close event before the listener is attached and the driver hangs forever.
|
|
84
|
+
const victimClosed = new Promise(r => victim.on('close', code => r(code)));
|
|
85
|
+
|
|
86
|
+
const deadline = Date.now() + 5000;
|
|
87
|
+
while (!/acquired/.test(victimOut) && Date.now() < deadline) {
|
|
88
|
+
await new Promise(r => setTimeout(r, 10));
|
|
89
|
+
}
|
|
90
|
+
if (!/acquired/.test(victimOut)) {
|
|
91
|
+
console.error('FAIL: victim did not acquire within 5s');
|
|
92
|
+
victim.kill('SIGKILL');
|
|
93
|
+
rmSync(dir, { recursive: true, force: true });
|
|
94
|
+
process.exit(1);
|
|
95
|
+
}
|
|
96
|
+
const victimInfo = JSON.parse(victimOut.trim().split('\n').pop());
|
|
97
|
+
console.log('victim acquired: pid=' + victimInfo.pid + ' lockfile=' + basename(victimInfo.lockFile));
|
|
98
|
+
|
|
99
|
+
// 2. SIGKILL victim — release() never runs
|
|
100
|
+
const killT0 = Date.now();
|
|
101
|
+
victim.kill('SIGKILL');
|
|
102
|
+
await victimClosed;
|
|
103
|
+
const killT1 = Date.now();
|
|
104
|
+
console.log('SIGKILL sent + victim closed in ' + (killT1 - killT0) + 'ms');
|
|
105
|
+
|
|
106
|
+
// 3. Verify lockfile remains (orphan)
|
|
107
|
+
if (!existsSync(lockFile)) {
|
|
108
|
+
console.error('FAIL: lockfile vanished after SIGKILL — release ran? unexpected.');
|
|
109
|
+
rmSync(dir, { recursive: true, force: true });
|
|
110
|
+
process.exit(1);
|
|
111
|
+
}
|
|
112
|
+
console.log('orphan lockfile remains: ' + readFileSync(lockFile, 'utf8'));
|
|
113
|
+
|
|
114
|
+
// 4. Spawn 5 followers in parallel
|
|
115
|
+
const N = 5;
|
|
116
|
+
const followerStart = Date.now();
|
|
117
|
+
const followerProcs = [];
|
|
118
|
+
for (let i = 0; i < N; i += 1) {
|
|
119
|
+
const f = spawn(process.execPath, [__filename, '--follower', target, 'FOLLOWER-' + i + '\n'], {
|
|
120
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
121
|
+
});
|
|
122
|
+
let out = '';
|
|
123
|
+
f.stdout.on('data', d => { out += d; });
|
|
124
|
+
followerProcs.push(new Promise(res => f.on('close', code => {
|
|
125
|
+
try {
|
|
126
|
+
res({ code, ...JSON.parse(out.trim().split('\n').pop()) });
|
|
127
|
+
} catch {
|
|
128
|
+
res({ code, ok: false, raw: out.slice(-100) });
|
|
129
|
+
}
|
|
130
|
+
})));
|
|
131
|
+
}
|
|
132
|
+
const results = await Promise.all(followerProcs);
|
|
133
|
+
const followerWallMs = Date.now() - followerStart;
|
|
134
|
+
|
|
135
|
+
// 5. Verify final state
|
|
136
|
+
const okCount = results.filter(r => r.ok).length;
|
|
137
|
+
const finalContent = readFileSync(target, 'utf8');
|
|
138
|
+
const isValid = /^FOLLOWER-\d+\n?$/.test(finalContent);
|
|
139
|
+
const leftovers = readdirSync(dir).filter(n =>
|
|
140
|
+
n.endsWith('.mixdog-lock') || n.includes('.mixdog-tmp-')
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
console.log('');
|
|
144
|
+
console.log('Follower results (' + followerWallMs + 'ms total):');
|
|
145
|
+
results.forEach((r, i) => {
|
|
146
|
+
console.log(' #' + i + ' pid=' + r.pid + ' ok=' + r.ok
|
|
147
|
+
+ (r.acquireMs !== undefined ? ' acquireMs=' + r.acquireMs : '')
|
|
148
|
+
+ (r.code ? ' code=' + r.code : '')
|
|
149
|
+
+ (r.dt ? ' dt=' + r.dt + 'ms' : ''));
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
console.log('');
|
|
153
|
+
console.log('Final state:');
|
|
154
|
+
console.log(' okCount: ' + okCount + '/' + N);
|
|
155
|
+
console.log(' final content: ' + JSON.stringify(finalContent));
|
|
156
|
+
console.log(' isValid: ' + isValid);
|
|
157
|
+
console.log(' leftovers: ' + (leftovers.length === 0 ? 'CLEAN' : leftovers.join(', ')));
|
|
158
|
+
|
|
159
|
+
const pass = okCount === N && isValid && leftovers.length === 0;
|
|
160
|
+
console.log('');
|
|
161
|
+
console.log(pass ? '=== PASS ===' : '=== FAIL ===');
|
|
162
|
+
|
|
163
|
+
rmSync(dir, { recursive: true, force: true });
|
|
164
|
+
process.exit(pass ? 0 : 1);
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
// Large-file streaming test: 100MB target, 4 concurrent writers replacing
|
|
2
|
+
// with ~100MB payloads of different sizes, 4 concurrent readers verifying
|
|
3
|
+
// sentinels + expected-size set. Forces atomic-write streaming path
|
|
4
|
+
// (>1MB threshold) + Windows EBUSY backoff during reader hold.
|
|
5
|
+
import { spawn } from 'child_process';
|
|
6
|
+
import {
|
|
7
|
+
mkdtempSync, writeFileSync, readFileSync, statSync, readdirSync, rmSync,
|
|
8
|
+
} from 'fs';
|
|
9
|
+
import { tmpdir } from 'os';
|
|
10
|
+
import { join, dirname } from 'path';
|
|
11
|
+
import { fileURLToPath } from 'url';
|
|
12
|
+
import { performance } from 'perf_hooks';
|
|
13
|
+
|
|
14
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
15
|
+
const __dirname = dirname(__filename);
|
|
16
|
+
const repoRoot = dirname(__dirname);
|
|
17
|
+
const atomicModUrl = 'file://' + join(repoRoot, 'src/agent/orchestrator/tools/builtin/atomic-write.mjs').replace(/\\/g, '/');
|
|
18
|
+
const lockModUrl = 'file://' + join(repoRoot, 'src/agent/orchestrator/tools/builtin/advisory-lock.mjs').replace(/\\/g, '/');
|
|
19
|
+
|
|
20
|
+
function snapshot(p) {
|
|
21
|
+
try {
|
|
22
|
+
const s = statSync(p);
|
|
23
|
+
return { exists: true, size: s.size, mtimeMs: s.mtimeMs, ino: s.ino };
|
|
24
|
+
} catch { return { exists: false }; }
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// --- Writer mode ---
|
|
28
|
+
if (process.argv[2] === '--writer') {
|
|
29
|
+
const target = process.argv[3];
|
|
30
|
+
const payloadFile = process.argv[4];
|
|
31
|
+
const { atomicWrite } = await import(atomicModUrl);
|
|
32
|
+
const { acquireAdvisoryLock } = await import(lockModUrl);
|
|
33
|
+
const t0 = performance.now();
|
|
34
|
+
const handle = await acquireAdvisoryLock(target, { timeoutMs: 60000 });
|
|
35
|
+
try {
|
|
36
|
+
const payload = readFileSync(payloadFile);
|
|
37
|
+
await atomicWrite(target, payload, { expectedTargetSnapshot: snapshot(target) });
|
|
38
|
+
} finally { handle.release(); }
|
|
39
|
+
const dt = +(performance.now() - t0).toFixed(2);
|
|
40
|
+
process.stdout.write(JSON.stringify({ ok: true, mode: 'writer', dt, pid: process.pid }) + '\n');
|
|
41
|
+
process.exit(0);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// --- Reader mode ---
|
|
45
|
+
if (process.argv[2] === '--reader') {
|
|
46
|
+
const target = process.argv[3];
|
|
47
|
+
const expectedSizes = process.argv[4].split(',').map(Number);
|
|
48
|
+
const N = 30;
|
|
49
|
+
const sizes = new Set();
|
|
50
|
+
let reads = 0;
|
|
51
|
+
for (let i = 0; i < N; i += 1) {
|
|
52
|
+
try {
|
|
53
|
+
const buf = readFileSync(target);
|
|
54
|
+
sizes.add(buf.length);
|
|
55
|
+
if (buf.length === 0 || !expectedSizes.includes(buf.length)) {
|
|
56
|
+
process.stdout.write(JSON.stringify({
|
|
57
|
+
ok: false, torn: true, reason: 'unexpected-size', len: buf.length, pid: process.pid,
|
|
58
|
+
}) + '\n');
|
|
59
|
+
process.exit(2);
|
|
60
|
+
}
|
|
61
|
+
const tail = buf.subarray(buf.length - 4).toString();
|
|
62
|
+
if (tail !== '|END') {
|
|
63
|
+
process.stdout.write(JSON.stringify({
|
|
64
|
+
ok: false, torn: true, reason: 'tail', len: buf.length, tail, pid: process.pid,
|
|
65
|
+
}) + '\n');
|
|
66
|
+
process.exit(2);
|
|
67
|
+
}
|
|
68
|
+
} catch (err) {
|
|
69
|
+
if (err.code !== 'ENOENT') throw err;
|
|
70
|
+
}
|
|
71
|
+
reads += 1;
|
|
72
|
+
await new Promise(r => setTimeout(r, 10));
|
|
73
|
+
}
|
|
74
|
+
process.stdout.write(JSON.stringify({
|
|
75
|
+
ok: true, mode: 'reader', reads, distinctSizes: sizes.size, pid: process.pid,
|
|
76
|
+
}) + '\n');
|
|
77
|
+
process.exit(0);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// --- Driver ---
|
|
81
|
+
const dir = mkdtempSync(join(tmpdir(), 'large-file-'));
|
|
82
|
+
const target = join(dir, 'big.dat');
|
|
83
|
+
console.log('=== C. Large-file streaming edit (~100MB) ===');
|
|
84
|
+
console.log('dir=' + dir);
|
|
85
|
+
|
|
86
|
+
const SIZE_BYTES = 100 * 1024 * 1024;
|
|
87
|
+
const t0 = Date.now();
|
|
88
|
+
const initBuf = Buffer.alloc(SIZE_BYTES);
|
|
89
|
+
initBuf.fill('a');
|
|
90
|
+
initBuf.write('INIT-', 0);
|
|
91
|
+
initBuf.write('|END', SIZE_BYTES - 4);
|
|
92
|
+
writeFileSync(target, initBuf);
|
|
93
|
+
const initSize = statSync(target).size;
|
|
94
|
+
console.log('initial: ' + (initSize / 1024 / 1024).toFixed(1) + 'MB in ' + (Date.now() - t0) + 'ms');
|
|
95
|
+
|
|
96
|
+
const payloads = [];
|
|
97
|
+
for (let i = 0; i < 4; i += 1) {
|
|
98
|
+
const sz = SIZE_BYTES + (i - 1) * 1024; // 99.999MB .. 100.003MB
|
|
99
|
+
const buf = Buffer.alloc(sz);
|
|
100
|
+
buf.fill('b');
|
|
101
|
+
buf.write('PAY' + i + '-', 0);
|
|
102
|
+
buf.write('|END', sz - 4);
|
|
103
|
+
const p = join(dir, 'payload-' + i + '.bin');
|
|
104
|
+
writeFileSync(p, buf);
|
|
105
|
+
payloads.push({ path: p, size: sz });
|
|
106
|
+
}
|
|
107
|
+
console.log('payloads: ' + payloads.map(p => p.size).join(', '));
|
|
108
|
+
|
|
109
|
+
const expectedSizes = [initSize, ...payloads.map(p => p.size)].join(',');
|
|
110
|
+
|
|
111
|
+
// 4 readers spawned first, then 4 writers
|
|
112
|
+
const readerProcs = [];
|
|
113
|
+
for (let i = 0; i < 4; i += 1) {
|
|
114
|
+
const f = spawn(process.execPath, [__filename, '--reader', target, expectedSizes], {
|
|
115
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
116
|
+
});
|
|
117
|
+
let out = '';
|
|
118
|
+
f.stdout.on('data', d => { out += d; });
|
|
119
|
+
readerProcs.push(new Promise(res => f.on('close', code => {
|
|
120
|
+
try { res({ code, ...JSON.parse(out.trim().split('\n').pop()) }); }
|
|
121
|
+
catch { res({ code, ok: false, raw: out.slice(-100) }); }
|
|
122
|
+
})));
|
|
123
|
+
}
|
|
124
|
+
await new Promise(r => setTimeout(r, 100));
|
|
125
|
+
|
|
126
|
+
const writerProcs = [];
|
|
127
|
+
for (let i = 0; i < 4; i += 1) {
|
|
128
|
+
const f = spawn(process.execPath, [__filename, '--writer', target, payloads[i].path], {
|
|
129
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
130
|
+
});
|
|
131
|
+
let out = '';
|
|
132
|
+
f.stdout.on('data', d => { out += d; });
|
|
133
|
+
writerProcs.push(new Promise(res => f.on('close', code => {
|
|
134
|
+
try { res({ code, ...JSON.parse(out.trim().split('\n').pop()) }); }
|
|
135
|
+
catch { res({ code, ok: false, raw: out.slice(-100) }); }
|
|
136
|
+
})));
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const writeStart = Date.now();
|
|
140
|
+
const [writers, readers] = await Promise.all([
|
|
141
|
+
Promise.all(writerProcs),
|
|
142
|
+
Promise.all(readerProcs),
|
|
143
|
+
]);
|
|
144
|
+
const wallMs = Date.now() - writeStart;
|
|
145
|
+
|
|
146
|
+
const writersOk = writers.filter(r => r.ok).length;
|
|
147
|
+
const readersOk = readers.filter(r => r.ok).length;
|
|
148
|
+
const tornFound = readers.some(r => r.torn === true);
|
|
149
|
+
const leftovers = readdirSync(dir).filter(n =>
|
|
150
|
+
n.endsWith('.mixdog-lock') || n.includes('.mixdog-tmp-')
|
|
151
|
+
);
|
|
152
|
+
const finalSize = statSync(target).size;
|
|
153
|
+
const finalIsPayload = payloads.some(p => p.size === finalSize);
|
|
154
|
+
|
|
155
|
+
console.log('');
|
|
156
|
+
console.log('Writers (' + wallMs + 'ms):');
|
|
157
|
+
writers.forEach((r, i) => console.log(' #' + i + ' ok=' + r.ok + ' dt=' + (r.dt || '?') + 'ms'));
|
|
158
|
+
console.log('Readers:');
|
|
159
|
+
readers.forEach((r, i) => console.log(' #' + i + ' ok=' + r.ok + ' reads=' + (r.reads || 0) + ' distinctSizes=' + (r.distinctSizes || 0)));
|
|
160
|
+
console.log('');
|
|
161
|
+
console.log('Final:');
|
|
162
|
+
console.log(' finalSize: ' + (finalSize / 1024 / 1024).toFixed(2) + 'MB');
|
|
163
|
+
console.log(' finalIsPayload: ' + finalIsPayload);
|
|
164
|
+
console.log(' writersOk: ' + writersOk + '/4');
|
|
165
|
+
console.log(' readersOk: ' + readersOk + '/4');
|
|
166
|
+
console.log(' torn: ' + (tornFound ? 'YES' : 'no'));
|
|
167
|
+
console.log(' leftovers: ' + (leftovers.length === 0 ? 'CLEAN' : leftovers.join(', ')));
|
|
168
|
+
|
|
169
|
+
const pass = writersOk === 4 && readersOk === 4 && !tornFound && finalIsPayload && leftovers.length === 0;
|
|
170
|
+
console.log('');
|
|
171
|
+
console.log(pass ? '=== PASS ===' : '=== FAIL ===');
|
|
172
|
+
|
|
173
|
+
rmSync(dir, { recursive: true, force: true });
|
|
174
|
+
process.exit(pass ? 0 : 1);
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
// tool-edge-smoke.mjs — regression suite locking in builtin-tool edge cases
|
|
2
|
+
// proven by live testing. Self-contained: builds throwaway fixtures under a
|
|
3
|
+
// temp dir, drives the real tool impls imported straight from ../src, prints
|
|
4
|
+
// PASS/FAIL per case, and exits 1 if any case fails.
|
|
5
|
+
//
|
|
6
|
+
// Run: bun scripts/tool-edge-smoke.mjs (or: node scripts/tool-edge-smoke.mjs)
|
|
7
|
+
//
|
|
8
|
+
// Cases (all anchored to behaviour observed live):
|
|
9
|
+
// 1 grep anchored glob src/**/*.mjs matches under absolute proper-case,
|
|
10
|
+
// absolute lowercase, and relative path (true-cased rg cwd fix)
|
|
11
|
+
// 2 grep array pattern -> `# per-pattern:` summary exposes a zero-hit member
|
|
12
|
+
// 3 `-i` hint appears on a true zero-match cased pattern, absent when offset>0
|
|
13
|
+
// 4 resolveSymbolReadSpan: const-arrow decl gets an exact end; fn decl unchanged
|
|
14
|
+
// 5 list find: invalid modified_after errors; `24h` works
|
|
15
|
+
// 6 grep pattern caps: 21-array -> error, 6 multiline -> error
|
|
16
|
+
// 7 glob magic path `dir/*` + pattern matches files directly in dir
|
|
17
|
+
// 8 diagnostics node --check fallback flags a syntax-error fixture
|
|
18
|
+
// 9 list tree output >50KB hits the char-cap truncation marker
|
|
19
|
+
// 10 read a 1x1 PNG -> image content block, not an error
|
|
20
|
+
|
|
21
|
+
import { tmpdir } from 'os';
|
|
22
|
+
import { join, dirname, sep } from 'path';
|
|
23
|
+
import { fileURLToPath } from 'url';
|
|
24
|
+
import { mkdirSync, writeFileSync, rmSync } from 'fs';
|
|
25
|
+
|
|
26
|
+
const ROOT = join(dirname(fileURLToPath(import.meta.url)), '..');
|
|
27
|
+
const IS_WIN = process.platform === 'win32';
|
|
28
|
+
|
|
29
|
+
// Tool impls imported directly from ../src.
|
|
30
|
+
const { executeGrepTool, executeGlobTool } =
|
|
31
|
+
await import('../src/agent/orchestrator/tools/builtin/search-tool.mjs');
|
|
32
|
+
const { executeListTool } =
|
|
33
|
+
await import('../src/agent/orchestrator/tools/builtin/list-tool.mjs');
|
|
34
|
+
const { executeDiagnosticsTool } =
|
|
35
|
+
await import('../src/agent/orchestrator/tools/builtin/diagnostics-tool.mjs');
|
|
36
|
+
const { resolveSymbolReadSpan } =
|
|
37
|
+
await import('../src/agent/orchestrator/tools/code-graph.mjs');
|
|
38
|
+
// read has a thick helper-injection signature; drive it through the builtin
|
|
39
|
+
// dispatcher so the real image fast-path runs exactly as in production.
|
|
40
|
+
const { executeBuiltinTool } =
|
|
41
|
+
await import('../src/agent/orchestrator/tools/builtin.mjs');
|
|
42
|
+
|
|
43
|
+
// grep wants an executeChildBuiltinTool arg; none of our grep cases hit the
|
|
44
|
+
// glob-only fallback (a pattern is always present), so a noop suffices.
|
|
45
|
+
const noopChild = async () => '';
|
|
46
|
+
|
|
47
|
+
// ---- fixtures ----------------------------------------------------------
|
|
48
|
+
const FIX = join(tmpdir(), `mixdog-tool-edge-smoke-${process.pid}`);
|
|
49
|
+
function mk(rel, content) {
|
|
50
|
+
const p = join(FIX, rel);
|
|
51
|
+
mkdirSync(dirname(p), { recursive: true });
|
|
52
|
+
writeFileSync(p, content);
|
|
53
|
+
return p;
|
|
54
|
+
}
|
|
55
|
+
mkdirSync(FIX, { recursive: true });
|
|
56
|
+
|
|
57
|
+
// ---- harness -----------------------------------------------------------
|
|
58
|
+
let passed = 0;
|
|
59
|
+
let failed = 0;
|
|
60
|
+
function assert(cond, msg) { if (!cond) throw new Error(msg || 'assertion failed'); }
|
|
61
|
+
async function check(name, fn) {
|
|
62
|
+
try { await fn(); passed++; console.log(` PASS ${name}`); }
|
|
63
|
+
catch (e) { failed++; console.log(` FAIL ${name}\n ${e?.message || e}`); }
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
try {
|
|
67
|
+
// ---- 1: anchored glob across path-casing forms ----------------------
|
|
68
|
+
await check('grep anchored glob src/**/*.mjs matches (proper / lower / relative)', async () => {
|
|
69
|
+
const glob = 'src/**/*.mjs';
|
|
70
|
+
const pattern = 'export';
|
|
71
|
+
const run = (searchPath, workDir) =>
|
|
72
|
+
executeGrepTool({ pattern, path: searchPath, glob, head_limit: 5 }, workDir, noopChild, null, {});
|
|
73
|
+
|
|
74
|
+
const proper = await run(ROOT, IS_WIN ? ROOT.toLowerCase() : ROOT);
|
|
75
|
+
assert(typeof proper === 'string' && /\.mjs/.test(proper) && !/no matches/i.test(proper),
|
|
76
|
+
`proper-case absolute produced no matches: ${proper.slice(0, 120)}`);
|
|
77
|
+
|
|
78
|
+
if (IS_WIN) {
|
|
79
|
+
const lower = await run(ROOT.toLowerCase(), ROOT);
|
|
80
|
+
assert(/\.mjs/.test(lower) && !/no matches/i.test(lower),
|
|
81
|
+
`lowercase absolute produced no matches: ${lower.slice(0, 120)}`);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const rel = await run('.', ROOT);
|
|
85
|
+
assert(/\.mjs/.test(rel) && !/no matches/i.test(rel),
|
|
86
|
+
`relative path produced no matches: ${rel.slice(0, 120)}`);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
// ---- 2: per-pattern summary exposes a zero-hit member ---------------
|
|
90
|
+
await check('grep array pattern -> # per-pattern: shows a zero-hit member', async () => {
|
|
91
|
+
const out = await executeGrepTool(
|
|
92
|
+
{ pattern: ['export', 'zzz_no_such_token_qwxyz'], path: ROOT, glob: 'src/**/*.mjs', head_limit: 3 },
|
|
93
|
+
ROOT, noopChild, null, {});
|
|
94
|
+
assert(/# per-pattern:/.test(out), `missing per-pattern summary: ${out.slice(-200)}`);
|
|
95
|
+
assert(/zzz_no_such_token_qwxyz.*?=0 files/.test(out), `zero-hit member not shown as 0 files: ${out.slice(-200)}`);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
// ---- 3: -i hint only on a true zero-match cased search --------------
|
|
99
|
+
await check('grep -i hint present at offset 0, absent at offset>0', async () => {
|
|
100
|
+
mk('hint/file.txt', 'HelloWorld lives here\n');
|
|
101
|
+
const dir = join(FIX, 'hint');
|
|
102
|
+
const hit = await executeGrepTool({ pattern: 'helloworld', path: dir }, FIX, noopChild, null, {});
|
|
103
|
+
assert(/case-insensitive would match — try -i/.test(hit), `expected -i hint: ${hit}`);
|
|
104
|
+
const skipped = await executeGrepTool({ pattern: 'helloworld', path: dir, offset: 1 }, FIX, noopChild, null, {});
|
|
105
|
+
assert(!/case-insensitive would match/.test(skipped), `hint must be suppressed at offset>0: ${skipped}`);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
// ---- 4: span end inference for a const-arrow decl -------------------
|
|
109
|
+
await check('resolveSymbolReadSpan: const-arrow exact end, fn decl unchanged', async () => {
|
|
110
|
+
const cgDir = join(FIX, 'cg');
|
|
111
|
+
mk('cg/sample.mjs', [
|
|
112
|
+
'export const myArrow = (a, b) => {', // 1
|
|
113
|
+
' const x = a + b;', // 2
|
|
114
|
+
' const y = x * 2;', // 3
|
|
115
|
+
' const z = y - 1;', // 4
|
|
116
|
+
' return z;', // 5
|
|
117
|
+
'};', // 6
|
|
118
|
+
'function plainFn(n) {', // 7
|
|
119
|
+
' return n + 1;', // 8
|
|
120
|
+
'}', // 9
|
|
121
|
+
'',
|
|
122
|
+
].join('\n'));
|
|
123
|
+
|
|
124
|
+
const arrow = await resolveSymbolReadSpan(cgDir, { symbol: 'myArrow', path: 'sample.mjs' });
|
|
125
|
+
assert(!arrow.error, `myArrow lookup errored: ${arrow.error}`);
|
|
126
|
+
assert(arrow.startLine === 1 && arrow.endLine === 6 && arrow.approximate === false,
|
|
127
|
+
`const-arrow span wrong: ${JSON.stringify(arrow)}`);
|
|
128
|
+
|
|
129
|
+
const fn = await resolveSymbolReadSpan(cgDir, { symbol: 'plainFn', path: 'sample.mjs' });
|
|
130
|
+
assert(!fn.error, `plainFn lookup errored: ${fn.error}`);
|
|
131
|
+
assert(fn.startLine === 7 && fn.endLine === 9,
|
|
132
|
+
`function decl span changed: ${JSON.stringify(fn)}`);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
// ---- 5: list find time-window validation ----------------------------
|
|
136
|
+
await check('list find: invalid modified_after errors, 24h works', async () => {
|
|
137
|
+
mk('find/recent.txt', 'x\n');
|
|
138
|
+
const dir = join(FIX, 'find');
|
|
139
|
+
const bad = await executeListTool({ mode: 'find', path: dir, modified_after: 'not-a-date' }, FIX, {});
|
|
140
|
+
assert(/Error: invalid modified_after/.test(bad), `expected invalid-date error: ${bad}`);
|
|
141
|
+
const ok = await executeListTool({ mode: 'find', path: dir, modified_after: '24h' }, FIX, {});
|
|
142
|
+
assert(!/^Error/.test(ok) && /recent\.txt/.test(ok), `24h window should list the fresh fixture: ${ok}`);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
// ---- 6: grep pattern-count caps -------------------------------------
|
|
146
|
+
await check('grep caps: 21-array errors, 6 multiline errors', async () => {
|
|
147
|
+
const twentyOne = Array.from({ length: 21 }, (_, i) => `p${i}`);
|
|
148
|
+
const arr = await executeGrepTool({ pattern: twentyOne, path: FIX }, FIX, noopChild, null, {});
|
|
149
|
+
assert(/Error: pattern array exceeds the 20-pattern cap/.test(arr), `expected array cap error: ${arr}`);
|
|
150
|
+
const six = Array.from({ length: 6 }, (_, i) => `m${i}`);
|
|
151
|
+
const ml = await executeGrepTool({ pattern: six, path: FIX, multiline: true }, FIX, noopChild, null, {});
|
|
152
|
+
assert(/Error: multiline:true with more than 5 patterns/.test(ml), `expected multiline cap error: ${ml}`);
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
// ---- 7: glob magic path `dir/*` + pattern ---------------------------
|
|
156
|
+
await check('glob magic path dir/* + pattern matches files directly in dir', async () => {
|
|
157
|
+
mk('gdir/a.txt', '1');
|
|
158
|
+
mk('gdir/b.txt', '2');
|
|
159
|
+
mk('gdir/c.log', '3');
|
|
160
|
+
const out = await executeGlobTool({ path: 'gdir/*', pattern: '*.txt' }, FIX, {});
|
|
161
|
+
assert(/a\.txt/.test(out) && /b\.txt/.test(out), `direct-in-dir files missing: ${out}`);
|
|
162
|
+
assert(!/c\.log/.test(out), `pattern should exclude non-matching file: ${out}`);
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
// ---- 8: diagnostics node --check fallback ---------------------------
|
|
166
|
+
await check('diagnostics node --check fallback flags a syntax-error fixture', async () => {
|
|
167
|
+
const broken = mk('diag/broken.mjs', 'const x = (;\n');
|
|
168
|
+
const out = await executeDiagnosticsTool({ path: broken }, FIX, {});
|
|
169
|
+
let parsed;
|
|
170
|
+
try { parsed = JSON.parse(out); } catch { throw new Error(`non-JSON envelope: ${out}`); }
|
|
171
|
+
assert(/node --check/.test(String(parsed.checker || '')), `expected node --check fallback: ${parsed.checker}`);
|
|
172
|
+
assert(parsed.count >= 1 && parsed.findings.some((f) => f.severity === 'error'),
|
|
173
|
+
`syntax error not flagged: ${out}`);
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
// ---- 9: tree char-cap truncation marker -----------------------------
|
|
177
|
+
await check('list tree output >50KB hits the char-cap truncation marker', async () => {
|
|
178
|
+
// Wide+padded tree so the rendered output exceeds TREE_OUTPUT_CHAR_CAP
|
|
179
|
+
// (50KB). head_limit:0 disables the row page-cap so the char-cap is what
|
|
180
|
+
// actually trips. Long names keep the file count modest.
|
|
181
|
+
const pad = 'x'.repeat(40);
|
|
182
|
+
for (let d = 0; d < 40; d++) {
|
|
183
|
+
for (let f = 0; f < 40; f++) {
|
|
184
|
+
mk(`bigtree/dir_${pad}_${d}/file_${pad}_${f}.txt`, '.');
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
const out = await executeListTool({ mode: 'tree', path: join(FIX, 'bigtree'), depth: 3, head_limit: 0 }, FIX, {});
|
|
188
|
+
assert(/output truncated at 49 KB/.test(out), `expected char-cap truncation marker: ...${out.slice(-160)}`);
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
// ---- 10: read a 1x1 PNG returns image content -----------------------
|
|
192
|
+
await check('read 1x1 PNG -> image content block, not an error', async () => {
|
|
193
|
+
const pngB64 =
|
|
194
|
+
'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==';
|
|
195
|
+
const png = join(FIX, 'img', 'pixel.png');
|
|
196
|
+
mkdirSync(dirname(png), { recursive: true });
|
|
197
|
+
writeFileSync(png, Buffer.from(pngB64, 'base64'));
|
|
198
|
+
const res = await executeBuiltinTool('read', { path: png }, FIX, {});
|
|
199
|
+
assert(res && typeof res === 'object' && !Array.isArray(res), `expected a content-block object, got: ${typeof res}`);
|
|
200
|
+
assert(res.isError !== true, `read flagged an error: ${JSON.stringify(res).slice(0, 200)}`);
|
|
201
|
+
assert(Array.isArray(res.content) && res.content.some((c) => c && c.type === 'image'),
|
|
202
|
+
`no image content block returned: ${JSON.stringify(res).slice(0, 200)}`);
|
|
203
|
+
});
|
|
204
|
+
} finally {
|
|
205
|
+
try { rmSync(FIX, { recursive: true, force: true }); } catch { /* best-effort cleanup */ }
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
console.log(`\n${passed} passed, ${failed} failed`);
|
|
209
|
+
process.exit(failed > 0 ? 1 : 0);
|