@selesai/code 0.13.0 → 0.13.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +22 -0
- package/dist/core/agent-session.d.ts +1 -1
- package/dist/core/agent-session.js +1 -1
- package/dist/core/sdk.d.ts +2 -2
- package/dist/core/sdk.js +1 -1
- package/dist/core/system-prompt.d.ts +1 -1
- package/dist/core/system-prompt.js +1 -1
- package/dist/extensions/package.json +1 -2
- package/dist/extensions/pi-hermes-memory/CHANGELOG.md +371 -0
- package/dist/extensions/pi-hermes-memory/LICENSE +21 -0
- package/dist/extensions/pi-hermes-memory/README.md +643 -0
- package/dist/extensions/pi-hermes-memory/docs/0.1/TASKS.md +197 -0
- package/dist/extensions/pi-hermes-memory/docs/0.2/PLAN.md +290 -0
- package/dist/extensions/pi-hermes-memory/docs/0.2/TASKS.md +134 -0
- package/dist/extensions/pi-hermes-memory/docs/0.2/TEST-PLAN.md +216 -0
- package/dist/extensions/pi-hermes-memory/docs/0.3/PLAN.md +330 -0
- package/dist/extensions/pi-hermes-memory/docs/0.3/TASKS.md +125 -0
- package/dist/extensions/pi-hermes-memory/docs/0.4/PLAN.md +160 -0
- package/dist/extensions/pi-hermes-memory/docs/0.4/TASKS.md +113 -0
- package/dist/extensions/pi-hermes-memory/docs/0.6/CHANGELOG.md +57 -0
- package/dist/extensions/pi-hermes-memory/docs/0.6/PLAN.md +202 -0
- package/dist/extensions/pi-hermes-memory/docs/0.6/TASKS.md +144 -0
- package/dist/extensions/pi-hermes-memory/docs/0.7/PLAN.md +349 -0
- package/dist/extensions/pi-hermes-memory/docs/0.7/TASKS.md +110 -0
- package/dist/extensions/pi-hermes-memory/docs/PUBLISHING.md +149 -0
- package/dist/extensions/pi-hermes-memory/docs/ROADMAP.md +468 -0
- package/dist/extensions/pi-hermes-memory/docs/images/memory-architecture.svg +1 -0
- package/dist/extensions/pi-hermes-memory/docs/images/pi-logo.svg +22 -0
- package/dist/extensions/pi-hermes-memory/docs/images/pi_memory.png +0 -0
- package/dist/extensions/pi-hermes-memory/docs/images/pi_memory.svg +19 -0
- package/dist/extensions/pi-hermes-memory/docs/images/security-flow.svg +1 -0
- package/dist/extensions/pi-hermes-memory/docs/images/session-lifecycle.svg +1 -0
- package/dist/extensions/pi-hermes-memory/docs/images/source-architecture.svg +1 -0
- package/dist/extensions/pi-hermes-memory/docs/mermaid/memory-architecture.mmd +49 -0
- package/dist/extensions/pi-hermes-memory/docs/mermaid/security-flow.mmd +40 -0
- package/dist/extensions/pi-hermes-memory/docs/mermaid/session-lifecycle.mmd +56 -0
- package/dist/extensions/pi-hermes-memory/docs/mermaid/source-architecture.mmd +54 -0
- package/dist/extensions/pi-hermes-memory/package-lock.json +3799 -0
- package/dist/extensions/pi-hermes-memory/package.json +66 -0
- package/dist/extensions/pi-hermes-memory/scripts/check-min-sdk.mjs +99 -0
- package/dist/extensions/pi-hermes-memory/scripts/ensure-dev.mjs +57 -0
- package/dist/extensions/pi-hermes-memory/src/auto-consolidation-warning.ts +6 -0
- package/dist/extensions/pi-hermes-memory/src/config.ts +178 -0
- package/dist/extensions/pi-hermes-memory/src/constants.ts +424 -0
- package/dist/extensions/pi-hermes-memory/src/extension-root-migration.ts +639 -0
- package/dist/extensions/pi-hermes-memory/src/handlers/auto-consolidate.ts +401 -0
- package/dist/extensions/pi-hermes-memory/src/handlers/background-review.ts +297 -0
- package/dist/extensions/pi-hermes-memory/src/handlers/child-process-watchdog.mjs +90 -0
- package/dist/extensions/pi-hermes-memory/src/handlers/correction-detector.ts +300 -0
- package/dist/extensions/pi-hermes-memory/src/handlers/index-sessions.ts +86 -0
- package/dist/extensions/pi-hermes-memory/src/handlers/insights.ts +78 -0
- package/dist/extensions/pi-hermes-memory/src/handlers/interview.ts +37 -0
- package/dist/extensions/pi-hermes-memory/src/handlers/learn-memory.ts +186 -0
- package/dist/extensions/pi-hermes-memory/src/handlers/message-parts.ts +27 -0
- package/dist/extensions/pi-hermes-memory/src/handlers/pi-child-process.ts +485 -0
- package/dist/extensions/pi-hermes-memory/src/handlers/preview-context.ts +105 -0
- package/dist/extensions/pi-hermes-memory/src/handlers/review-memory-ops.ts +506 -0
- package/dist/extensions/pi-hermes-memory/src/handlers/session-backfill.ts +145 -0
- package/dist/extensions/pi-hermes-memory/src/handlers/session-flush.ts +151 -0
- package/dist/extensions/pi-hermes-memory/src/handlers/session-live-index.ts +94 -0
- package/dist/extensions/pi-hermes-memory/src/handlers/skills-command.ts +1334 -0
- package/dist/extensions/pi-hermes-memory/src/handlers/standing-pin.ts +111 -0
- package/dist/extensions/pi-hermes-memory/src/handlers/switch-project.ts +75 -0
- package/dist/extensions/pi-hermes-memory/src/handlers/sync-markdown-memories.ts +266 -0
- package/dist/extensions/pi-hermes-memory/src/index.ts +378 -0
- package/dist/extensions/pi-hermes-memory/src/lifecycle-timing.ts +54 -0
- package/dist/extensions/pi-hermes-memory/src/paths.ts +61 -0
- package/dist/extensions/pi-hermes-memory/src/project-context.ts +13 -0
- package/dist/extensions/pi-hermes-memory/src/project-memory-migration.ts +93 -0
- package/dist/extensions/pi-hermes-memory/src/project.ts +157 -0
- package/dist/extensions/pi-hermes-memory/src/prompt-context.ts +55 -0
- package/dist/extensions/pi-hermes-memory/src/store/atomic-lock-coordinator.ts +375 -0
- package/dist/extensions/pi-hermes-memory/src/store/canonical-storage-path.ts +54 -0
- package/dist/extensions/pi-hermes-memory/src/store/content-scanner.ts +101 -0
- package/dist/extensions/pi-hermes-memory/src/store/db.ts +1180 -0
- package/dist/extensions/pi-hermes-memory/src/store/fts-query.ts +101 -0
- package/dist/extensions/pi-hermes-memory/src/store/markdown-mutation-lock.ts +38 -0
- package/dist/extensions/pi-hermes-memory/src/store/memory-lookup.ts +24 -0
- package/dist/extensions/pi-hermes-memory/src/store/memory-store.ts +1191 -0
- package/dist/extensions/pi-hermes-memory/src/store/recovery-maintenance.ts +66 -0
- package/dist/extensions/pi-hermes-memory/src/store/schema.ts +118 -0
- package/dist/extensions/pi-hermes-memory/src/store/session-anchor-search.ts +472 -0
- package/dist/extensions/pi-hermes-memory/src/store/session-indexer.ts +511 -0
- package/dist/extensions/pi-hermes-memory/src/store/session-parser.ts +213 -0
- package/dist/extensions/pi-hermes-memory/src/store/session-search.ts +234 -0
- package/dist/extensions/pi-hermes-memory/src/store/skill-store.ts +950 -0
- package/dist/extensions/pi-hermes-memory/src/store/skill-utils.ts +133 -0
- package/dist/extensions/pi-hermes-memory/src/store/sqlite-memory-store.ts +1002 -0
- package/dist/extensions/pi-hermes-memory/src/store/sqlite-native.ts +241 -0
- package/dist/extensions/pi-hermes-memory/src/store/standing-instructions.ts +247 -0
- package/dist/extensions/pi-hermes-memory/src/tools/memory-search-tool.ts +95 -0
- package/dist/extensions/pi-hermes-memory/src/tools/memory-tool.ts +469 -0
- package/dist/extensions/pi-hermes-memory/src/tools/session-search-tool.ts +246 -0
- package/dist/extensions/pi-hermes-memory/src/tools/shared-output-view.ts +170 -0
- package/dist/extensions/pi-hermes-memory/src/tools/skill-tool.ts +333 -0
- package/dist/extensions/pi-hermes-memory/src/tools/tool-result-views.ts +105 -0
- package/dist/extensions/pi-hermes-memory/src/types.ts +214 -0
- package/dist/extensions/pi-hermes-memory/tests/config.test.ts +434 -0
- package/dist/extensions/pi-hermes-memory/tests/extension-root-migration.test.ts +368 -0
- package/dist/extensions/pi-hermes-memory/tests/handlers/auto-consolidate.test.ts +984 -0
- package/dist/extensions/pi-hermes-memory/tests/handlers/background-review.test.ts +950 -0
- package/dist/extensions/pi-hermes-memory/tests/handlers/correction-detector.test.ts +671 -0
- package/dist/extensions/pi-hermes-memory/tests/handlers/insights.test.ts +157 -0
- package/dist/extensions/pi-hermes-memory/tests/handlers/interview.test.ts +127 -0
- package/dist/extensions/pi-hermes-memory/tests/handlers/pi-child-process.test.ts +905 -0
- package/dist/extensions/pi-hermes-memory/tests/handlers/preview-context.test.ts +152 -0
- package/dist/extensions/pi-hermes-memory/tests/handlers/prompt-context.test.ts +166 -0
- package/dist/extensions/pi-hermes-memory/tests/handlers/resources-discover.test.ts +71 -0
- package/dist/extensions/pi-hermes-memory/tests/handlers/review-memory-ops.test.ts +614 -0
- package/dist/extensions/pi-hermes-memory/tests/handlers/session-backfill.test.ts +192 -0
- package/dist/extensions/pi-hermes-memory/tests/handlers/session-flush.test.ts +677 -0
- package/dist/extensions/pi-hermes-memory/tests/handlers/session-live-index.test.ts +225 -0
- package/dist/extensions/pi-hermes-memory/tests/handlers/skills-command.test.ts +827 -0
- package/dist/extensions/pi-hermes-memory/tests/handlers/standing-pin.test.ts +134 -0
- package/dist/extensions/pi-hermes-memory/tests/handlers/sync-markdown-memories.test.ts +491 -0
- package/dist/extensions/pi-hermes-memory/tests/handlers/system-prompt.test.ts +199 -0
- package/dist/extensions/pi-hermes-memory/tests/handlers/thinking-max.test.ts +64 -0
- package/dist/extensions/pi-hermes-memory/tests/index.test.ts +30 -0
- package/dist/extensions/pi-hermes-memory/tests/integration/flow.test.ts +126 -0
- package/dist/extensions/pi-hermes-memory/tests/lifecycle-timing.test.ts +76 -0
- package/dist/extensions/pi-hermes-memory/tests/paths.test.ts +23 -0
- package/dist/extensions/pi-hermes-memory/tests/project-memory-migration.test.ts +80 -0
- package/dist/extensions/pi-hermes-memory/tests/project-rebinding.test.ts +115 -0
- package/dist/extensions/pi-hermes-memory/tests/project.test.ts +120 -0
- package/dist/extensions/pi-hermes-memory/tests/run-all-timeout.test.ts +107 -0
- package/dist/extensions/pi-hermes-memory/tests/run-all.sh +45 -0
- package/dist/extensions/pi-hermes-memory/tests/store/atomic-lock-coordinator.test.ts +381 -0
- package/dist/extensions/pi-hermes-memory/tests/store/content-scanner.test.ts +388 -0
- package/dist/extensions/pi-hermes-memory/tests/store/db.test.ts +1046 -0
- package/dist/extensions/pi-hermes-memory/tests/store/markdown-mutation-lock.test.ts +34 -0
- package/dist/extensions/pi-hermes-memory/tests/store/memory-store.test.ts +2150 -0
- package/dist/extensions/pi-hermes-memory/tests/store/recovery-maintenance.test.ts +170 -0
- package/dist/extensions/pi-hermes-memory/tests/store/session-anchor-search.test.ts +210 -0
- package/dist/extensions/pi-hermes-memory/tests/store/session-indexer.test.ts +643 -0
- package/dist/extensions/pi-hermes-memory/tests/store/session-parser.test.ts +282 -0
- package/dist/extensions/pi-hermes-memory/tests/store/session-search.test.ts +287 -0
- package/dist/extensions/pi-hermes-memory/tests/store/skill-store.test.ts +678 -0
- package/dist/extensions/pi-hermes-memory/tests/store/skill-utils.test.ts +21 -0
- package/dist/extensions/pi-hermes-memory/tests/store/sqlite-lazy-load.test.ts +78 -0
- package/dist/extensions/pi-hermes-memory/tests/store/sqlite-memory-store.test.ts +543 -0
- package/dist/extensions/pi-hermes-memory/tests/store/sqlite-native.test.ts +164 -0
- package/dist/extensions/pi-hermes-memory/tests/store/standing-instructions.test.ts +171 -0
- package/dist/extensions/pi-hermes-memory/tests/tools/memory-search-tool.test.ts +84 -0
- package/dist/extensions/pi-hermes-memory/tests/tools/memory-tool.test.ts +709 -0
- package/dist/extensions/pi-hermes-memory/tests/tools/session-search-tool.test.ts +345 -0
- package/dist/extensions/pi-hermes-memory/tests/tools/shared-output-view.test.ts +362 -0
- package/dist/extensions/pi-hermes-memory/tests/tools/skill-tool.test.ts +478 -0
- package/dist/extensions/pi-hermes-memory/tests/tools/tool-result-renderer-wiring.test.ts +40 -0
- package/dist/extensions/pi-hermes-memory/tsconfig.json +19 -0
- package/dist/extensions/pi-rewind-hook/README.md +4 -1
- package/dist/extensions/pi-rewind-hook/index.ts +151 -21
- package/dist/extensions/pi-rewind-hook/package.json +5 -3
- package/dist/extensions/pi-subagents/.oxlintrc.json +43 -0
- package/dist/extensions/pi-subagents/AGENTS.md +5 -0
- package/dist/extensions/pi-subagents/CHANGELOG.md +157 -0
- package/dist/extensions/pi-subagents/README.md +12 -6
- package/dist/extensions/pi-subagents/VISION.md +81 -0
- package/dist/extensions/pi-subagents/agents/claude-code-writer.md +15 -0
- package/dist/extensions/pi-subagents/agents/claude-code.md +15 -0
- package/dist/extensions/pi-subagents/agents/codex-exec-writer.md +15 -0
- package/dist/extensions/pi-subagents/agents/codex-exec.md +15 -0
- package/dist/extensions/pi-subagents/agents/cursor-agent-writer.md +14 -0
- package/dist/extensions/pi-subagents/agents/cursor-agent.md +14 -0
- package/dist/extensions/pi-subagents/agents/reviewer.md +1 -3
- package/dist/extensions/pi-subagents/docs/agents.md +488 -0
- package/dist/extensions/pi-subagents/docs/configuration.md +46 -9
- package/dist/extensions/pi-subagents/docs/extension-api.md +42 -3
- package/dist/extensions/pi-subagents/docs/models.md +27 -4
- package/dist/extensions/pi-subagents/docs/observability.md +10 -9
- package/dist/extensions/pi-subagents/docs/tool-reference.md +102 -6
- package/dist/extensions/pi-subagents/docs/workflows.md +135 -0
- package/dist/extensions/pi-subagents/package-lock.json +389 -2
- package/dist/extensions/pi-subagents/package.json +3 -1
- package/dist/extensions/pi-subagents/prompts/review-loop.md +2 -2
- package/dist/extensions/pi-subagents/skills/council-mode/SKILL.md +1 -1
- package/dist/extensions/pi-subagents/skills/pi-subagents/SKILL.md +3 -1
- package/dist/extensions/pi-subagents/skills/pi-subagents/references/execution-controls.md +7 -3
- package/dist/extensions/pi-subagents/skills/pi-subagents/references/management-authoring-rpc.md +2 -2
- package/dist/extensions/pi-subagents/skills/pi-subagents/references/prompting-and-roles.md +26 -5
- package/dist/extensions/pi-subagents/src/agents/agent-management.ts +41 -22
- package/dist/extensions/pi-subagents/src/agents/agent-refinements.ts +4 -4
- package/dist/extensions/pi-subagents/src/agents/agent-serializer.ts +9 -2
- package/dist/extensions/pi-subagents/src/agents/agents.ts +322 -75
- package/dist/extensions/pi-subagents/src/agents/builtin-names.ts +6 -0
- package/dist/extensions/pi-subagents/src/agents/runtime-agent-events.ts +70 -0
- package/dist/extensions/pi-subagents/src/agents/runtime-agent-registry.ts +27 -20
- package/dist/extensions/pi-subagents/src/api/agents.ts +10 -5
- package/dist/extensions/pi-subagents/src/api/background-work.ts +5 -1
- package/dist/extensions/pi-subagents/src/api/delegation.ts +0 -7
- package/dist/extensions/pi-subagents/src/api/preflight.ts +34 -12
- package/dist/extensions/pi-subagents/src/extension/config.ts +70 -0
- package/dist/extensions/pi-subagents/src/extension/doctor.ts +3 -3
- package/dist/extensions/pi-subagents/src/extension/fanout-child.ts +5 -3
- package/dist/extensions/pi-subagents/src/extension/index.ts +83 -30
- package/dist/extensions/pi-subagents/src/extension/public-execution.ts +44 -15
- package/dist/extensions/pi-subagents/src/extension/rpc.ts +55 -19
- package/dist/extensions/pi-subagents/src/extension/schemas.ts +41 -15
- package/dist/extensions/pi-subagents/src/extension/tool-description.ts +28 -31
- package/dist/extensions/pi-subagents/src/inspectors/herdr/actions.ts +2 -1
- package/dist/extensions/pi-subagents/src/inspectors/herdr/inspector-runner.ts +2 -10
- package/dist/extensions/pi-subagents/src/inspectors/herdr/session-roots-codec.ts +42 -0
- package/dist/extensions/pi-subagents/src/integrations/herdr-status.ts +51 -7
- package/dist/extensions/pi-subagents/src/intercom/result-intercom.ts +2 -0
- package/dist/extensions/pi-subagents/src/profiles/profiles.ts +5 -6
- package/dist/extensions/pi-subagents/src/runs/background/active-async-capacity.ts +77 -10
- package/dist/extensions/pi-subagents/src/runs/background/async-execution.ts +176 -53
- package/dist/extensions/pi-subagents/src/runs/background/async-job-tracker.ts +19 -12
- package/dist/extensions/pi-subagents/src/runs/background/async-resume.ts +29 -27
- package/dist/extensions/pi-subagents/src/runs/background/async-retention.ts +20 -3
- package/dist/extensions/pi-subagents/src/runs/background/async-status-snapshot.ts +23 -261
- package/dist/extensions/pi-subagents/src/runs/background/async-status.ts +73 -7
- package/dist/extensions/pi-subagents/src/runs/background/chain-append.ts +8 -3
- package/dist/extensions/pi-subagents/src/runs/background/chain-root-attachment.ts +74 -8
- package/dist/extensions/pi-subagents/src/runs/background/fleet-view.ts +37 -21
- package/dist/extensions/pi-subagents/src/runs/background/inspect-rpc.ts +8 -8
- package/dist/extensions/pi-subagents/src/runs/background/notify.ts +184 -9
- package/dist/extensions/pi-subagents/src/runs/background/result-delivery-ownership.ts +45 -0
- package/dist/extensions/pi-subagents/src/runs/background/result-files.ts +28 -14
- package/dist/extensions/pi-subagents/src/runs/background/result-watcher.ts +38 -15
- package/dist/extensions/pi-subagents/src/runs/background/resume-guidance.ts +1 -1
- package/dist/extensions/pi-subagents/src/runs/background/retained-children.ts +1 -1
- package/dist/extensions/pi-subagents/src/runs/background/run-status.ts +50 -13
- package/dist/extensions/pi-subagents/src/runs/background/scheduled-runs.ts +93 -8
- package/dist/extensions/pi-subagents/src/runs/background/stale-run-reconciler.ts +10 -4
- package/dist/extensions/pi-subagents/src/runs/background/steering.ts +4 -14
- package/dist/extensions/pi-subagents/src/runs/background/subagent-runner.ts +549 -377
- package/dist/extensions/pi-subagents/src/runs/background/subagent-wait.ts +58 -10
- package/dist/extensions/pi-subagents/src/runs/background/terminal-run-index.ts +1 -1
- package/dist/extensions/pi-subagents/src/runs/background/wait-completions.ts +26 -1
- package/dist/extensions/pi-subagents/src/runs/background/wait-config.ts +23 -9
- package/dist/extensions/pi-subagents/src/runs/background/wait-tool.ts +9 -2
- package/dist/extensions/pi-subagents/src/runs/foreground/async-steering-action.ts +2 -2
- package/dist/extensions/pi-subagents/src/runs/foreground/execution.ts +204 -129
- package/dist/extensions/pi-subagents/src/runs/foreground/foreground-control.ts +9 -0
- package/dist/extensions/pi-subagents/src/runs/foreground/foreground-history.ts +23 -1
- package/dist/extensions/pi-subagents/src/runs/foreground/subagent-executor.ts +773 -311
- package/dist/extensions/pi-subagents/src/runs/foreground/workflow-detach-reconcile.ts +140 -115
- package/dist/extensions/pi-subagents/src/runs/shared/abort-recovery.ts +119 -0
- package/dist/extensions/pi-subagents/src/runs/shared/async-status-projection.ts +463 -0
- package/dist/extensions/pi-subagents/src/runs/shared/child-identity.ts +19 -4
- package/dist/extensions/pi-subagents/src/runs/shared/child-launch-plan.ts +151 -0
- package/dist/extensions/pi-subagents/src/runs/shared/child-protocol.ts +21 -7
- package/dist/extensions/pi-subagents/src/runs/shared/claude-code-adapter.ts +129 -0
- package/dist/extensions/pi-subagents/src/runs/shared/codex-exec-adapter.ts +129 -0
- package/dist/extensions/pi-subagents/src/runs/shared/completion-evidence.ts +89 -0
- package/dist/extensions/pi-subagents/src/runs/shared/completion-guard.ts +5 -4
- package/dist/extensions/pi-subagents/src/runs/shared/cursor-agent-adapter.ts +114 -0
- package/dist/extensions/pi-subagents/src/runs/shared/dynamic-fanout.ts +3 -3
- package/dist/extensions/pi-subagents/src/runs/shared/external-cli-contract.ts +167 -0
- package/dist/extensions/pi-subagents/src/runs/shared/external-cli-preflight.ts +122 -0
- package/dist/extensions/pi-subagents/src/runs/shared/external-cli-runner.ts +348 -55
- package/dist/extensions/pi-subagents/src/runs/shared/fast-mode-extension.ts +5 -5
- package/dist/extensions/pi-subagents/src/runs/shared/host-step-status.ts +230 -0
- package/dist/extensions/pi-subagents/src/runs/shared/lane-metadata.ts +105 -0
- package/dist/extensions/pi-subagents/src/runs/shared/launch-cwd.ts +16 -0
- package/dist/extensions/pi-subagents/src/runs/shared/long-running-guard.ts +2 -1
- package/dist/extensions/pi-subagents/src/runs/shared/mcp-config-sources.ts +422 -0
- package/dist/extensions/pi-subagents/src/runs/shared/mcp-direct-tool-allowlist.ts +221 -158
- package/dist/extensions/pi-subagents/src/runs/shared/mcp-direct-tool-grant.ts +197 -0
- package/dist/extensions/pi-subagents/src/runs/shared/model-exclusions.ts +69 -7
- package/dist/extensions/pi-subagents/src/runs/shared/model-fallback.ts +47 -6
- package/dist/extensions/pi-subagents/src/runs/shared/mutation-evidence.ts +7 -2
- package/dist/extensions/pi-subagents/src/runs/shared/nested-events.ts +9 -3
- package/dist/extensions/pi-subagents/src/runs/shared/nested-render.ts +9 -5
- package/dist/extensions/pi-subagents/src/runs/shared/parallel-handoff.ts +419 -7
- package/dist/extensions/pi-subagents/src/runs/shared/parallel-utils.ts +15 -1
- package/dist/extensions/pi-subagents/src/runs/shared/pi-args.ts +81 -8
- package/dist/extensions/pi-subagents/src/runs/shared/process-signal.ts +13 -0
- package/dist/extensions/pi-subagents/src/runs/shared/run-history.ts +21 -1
- package/dist/extensions/pi-subagents/src/runs/shared/single-output.ts +44 -4
- package/dist/extensions/pi-subagents/src/runs/shared/subagent-prompt-runtime.ts +98 -13
- package/dist/extensions/pi-subagents/src/runs/shared/subagent-startup-retry.ts +1 -1
- package/dist/extensions/pi-subagents/src/runs/shared/worktree-cleanup-plan.ts +847 -0
- package/dist/extensions/pi-subagents/src/runs/shared/worktree.ts +18 -0
- package/dist/extensions/pi-subagents/src/shared/child-session-name.ts +46 -0
- package/dist/extensions/pi-subagents/src/shared/extension-context.ts +24 -0
- package/dist/extensions/pi-subagents/src/shared/fork-context.ts +21 -0
- package/dist/extensions/pi-subagents/src/shared/formatters.ts +18 -3
- package/dist/extensions/pi-subagents/src/shared/launch-contract.ts +5 -1
- package/dist/extensions/pi-subagents/src/shared/pruned-fork.ts +450 -0
- package/dist/extensions/pi-subagents/src/shared/session-file-trust.ts +19 -0
- package/dist/extensions/pi-subagents/src/shared/session-tokens.ts +14 -3
- package/dist/extensions/pi-subagents/src/shared/settings.ts +19 -105
- package/dist/extensions/pi-subagents/src/shared/shortcuts.ts +17 -0
- package/dist/extensions/pi-subagents/src/shared/types.ts +359 -40
- package/dist/extensions/pi-subagents/src/shared/utils.ts +41 -84
- package/dist/extensions/pi-subagents/src/shared/workflow-child-permit.ts +116 -0
- package/dist/extensions/pi-subagents/src/slash/delegation-adapters.ts +1 -9
- package/dist/extensions/pi-subagents/src/slash/delegation-request.ts +0 -4
- package/dist/extensions/pi-subagents/src/slash/slash-bridge.ts +1 -2
- package/dist/extensions/pi-subagents/src/slash/slash-commands.ts +378 -88
- package/dist/extensions/pi-subagents/src/slash/slash-live-state.ts +22 -11
- package/dist/extensions/pi-subagents/src/slash/subagents-admin.ts +3 -0
- package/dist/extensions/pi-subagents/src/tui/fleet-status.ts +147 -79
- package/dist/extensions/pi-subagents/src/tui/fleet-transcript.ts +11 -5
- package/dist/extensions/pi-subagents/src/tui/fleet.ts +39 -18
- package/dist/extensions/pi-subagents/src/tui/render.ts +369 -46
- package/dist/extensions/pi-subagents/src/watchdog/turn-delta.ts +1 -1
- package/dist/extensions/pi-subagents/src/workflows/chat-progress.ts +6 -3
- package/dist/extensions/pi-subagents/src/workflows/host-command.ts +230 -0
- package/dist/extensions/pi-subagents/src/workflows/scripted-workflow.ts +740 -58
- package/dist/extensions/pi-subagents/src/workflows/workflow-child-summary.ts +121 -0
- package/dist/extensions/pi-subagents/src/workflows/workflow-preflight.ts +270 -0
- package/dist/extensions/pi-subagents/src/workflows/workflow-receipt.ts +195 -6
- package/dist/extensions/pi-subagents/src/workflows/workflow-settlement.ts +246 -0
- package/dist/extensions/pi-subagents/test/e2e/real-session-subagent.test.ts +2 -2
- package/dist/extensions/pi-subagents/test/integration/async-execution.test.ts +1114 -260
- package/dist/extensions/pi-subagents/test/integration/async-job-tracker.test.ts +34 -0
- package/dist/extensions/pi-subagents/test/integration/async-status.test.ts +150 -3
- package/dist/extensions/pi-subagents/test/integration/claude-code-smoke.test.ts +52 -0
- package/dist/extensions/pi-subagents/test/integration/claude-code-writer-smoke.test.ts +55 -0
- package/dist/extensions/pi-subagents/test/integration/codex-exec-smoke.test.ts +53 -0
- package/dist/extensions/pi-subagents/test/integration/codex-exec-writer-smoke.test.ts +57 -0
- package/dist/extensions/pi-subagents/test/integration/cursor-agent-smoke.test.ts +59 -0
- package/dist/extensions/pi-subagents/test/integration/cursor-agent-writer-smoke.test.ts +62 -0
- package/dist/extensions/pi-subagents/test/integration/error-handling.test.ts +57 -1
- package/dist/extensions/pi-subagents/test/integration/external-cli-runner.test.ts +1 -0
- package/dist/extensions/pi-subagents/test/integration/fork-context-execution.test.ts +20 -0
- package/dist/extensions/pi-subagents/test/integration/intercom-result-delivery.test.ts +4 -3
- package/dist/extensions/pi-subagents/test/integration/orca-progress-tabs.test.ts +2 -2
- package/dist/extensions/pi-subagents/test/integration/render-fork-badge.test.ts +54 -4
- package/dist/extensions/pi-subagents/test/integration/render-widget.test.ts +482 -4
- package/dist/extensions/pi-subagents/test/integration/result-watcher.test.ts +157 -9
- package/dist/extensions/pi-subagents/test/integration/session-tokens.test.ts +5 -5
- package/dist/extensions/pi-subagents/test/integration/single-execution.test.ts +1508 -291
- package/dist/extensions/pi-subagents/test/integration/slash-commands.test.ts +423 -1
- package/dist/extensions/pi-subagents/test/integration/template-resolution.test.ts +8 -0
- package/dist/extensions/pi-subagents/test/support/cursor-smoke-inputs.ts +51 -0
- package/dist/extensions/pi-subagents/test/support/helpers.ts +2 -0
- package/dist/extensions/pi-subagents/test/support/mock-pi.ts +5 -5
- package/dist/extensions/pi-subagents/test/support/real-session-runner.ts +6 -6
- package/dist/extensions/pi-subagents/test/unit/abort-recovery.test.ts +152 -0
- package/dist/extensions/pi-subagents/test/unit/active-async-capacity.test.ts +48 -0
- package/dist/extensions/pi-subagents/test/unit/agent-frontmatter.test.ts +184 -6
- package/dist/extensions/pi-subagents/test/unit/agent-management.test.ts +66 -6
- package/dist/extensions/pi-subagents/test/unit/agent-overrides.test.ts +77 -0
- package/dist/extensions/pi-subagents/test/unit/agent-refinements.test.ts +18 -0
- package/dist/extensions/pi-subagents/test/unit/anti-slop-oxlint.test.ts +86 -0
- package/dist/extensions/pi-subagents/test/unit/artifacts.test.ts +1 -1
- package/dist/extensions/pi-subagents/test/unit/async-execution.test.ts +101 -1
- package/dist/extensions/pi-subagents/test/unit/async-interrupt-action.test.ts +121 -0
- package/dist/extensions/pi-subagents/test/unit/async-recovery-descriptor.test.ts +28 -0
- package/dist/extensions/pi-subagents/test/unit/async-resume.test.ts +14 -7
- package/dist/extensions/pi-subagents/test/unit/async-retention.test.ts +53 -0
- package/dist/extensions/pi-subagents/test/unit/async-status-projection.test.ts +190 -0
- package/dist/extensions/pi-subagents/test/unit/async-status-snapshot.test.ts +42 -0
- package/dist/extensions/pi-subagents/test/unit/auto-drain.test.ts +8 -4
- package/dist/extensions/pi-subagents/test/unit/background-work.test.ts +23 -0
- package/dist/extensions/pi-subagents/test/unit/chain-root-attachment.test.ts +78 -1
- package/dist/extensions/pi-subagents/test/unit/child-launch-plan.test.ts +94 -0
- package/dist/extensions/pi-subagents/test/unit/child-protocol.test.ts +21 -0
- package/dist/extensions/pi-subagents/test/unit/child-session-name.test.ts +50 -0
- package/dist/extensions/pi-subagents/test/unit/claude-code-adapter.test.ts +245 -0
- package/dist/extensions/pi-subagents/test/unit/codex-exec-adapter.test.ts +192 -0
- package/dist/extensions/pi-subagents/test/unit/compaction-resume.test.ts +27 -0
- package/dist/extensions/pi-subagents/test/unit/completion-evidence.test.ts +150 -0
- package/dist/extensions/pi-subagents/test/unit/completion-guard.test.ts +21 -0
- package/dist/extensions/pi-subagents/test/unit/cursor-agent-adapter.test.ts +259 -0
- package/dist/extensions/pi-subagents/test/unit/cursor-smoke-inputs.test.ts +77 -0
- package/dist/extensions/pi-subagents/test/unit/delegation-api.test.ts +1 -4
- package/dist/extensions/pi-subagents/test/unit/doctor.test.ts +1 -1
- package/dist/extensions/pi-subagents/test/unit/extension-context.test.ts +27 -0
- package/dist/extensions/pi-subagents/test/unit/external-cli-runner.test.ts +223 -0
- package/dist/extensions/pi-subagents/test/unit/fast-mode-extension.test.ts +27 -0
- package/dist/extensions/pi-subagents/test/unit/fleet-status.test.ts +208 -2
- package/dist/extensions/pi-subagents/test/unit/fleet-transcript.test.ts +29 -1
- package/dist/extensions/pi-subagents/test/unit/fleet.test.ts +110 -1
- package/dist/extensions/pi-subagents/test/unit/foreground-control.test.ts +10 -0
- package/dist/extensions/pi-subagents/test/unit/formatters.test.ts +14 -0
- package/dist/extensions/pi-subagents/test/unit/herdr-inspector.test.ts +18 -9
- package/dist/extensions/pi-subagents/test/unit/herdr-session-roots-codec.test.ts +63 -0
- package/dist/extensions/pi-subagents/test/unit/herdr-shell-command.test.ts +2 -2
- package/dist/extensions/pi-subagents/test/unit/herdr-status-bridge.test.ts +136 -6
- package/dist/extensions/pi-subagents/test/unit/host-command.test.ts +156 -0
- package/dist/extensions/pi-subagents/test/unit/host-step-status.test.ts +98 -0
- package/dist/extensions/pi-subagents/test/unit/index-child-registration.test.ts +178 -26
- package/dist/extensions/pi-subagents/test/unit/index-segment.test.ts +2 -1
- package/dist/extensions/pi-subagents/test/unit/inspect-rpc.test.ts +21 -0
- package/dist/extensions/pi-subagents/test/unit/mcp-direct-tool-grant.test.ts +138 -0
- package/dist/extensions/pi-subagents/test/unit/mission-lifecycle.test.ts +1 -1
- package/dist/extensions/pi-subagents/test/unit/model-exclusions.test.ts +91 -0
- package/dist/extensions/pi-subagents/test/unit/model-fallback.test.ts +72 -7
- package/dist/extensions/pi-subagents/test/unit/mutation-evidence.test.ts +21 -0
- package/dist/extensions/pi-subagents/test/unit/nested-control.test.ts +1 -0
- package/dist/extensions/pi-subagents/test/unit/nested-events.test.ts +20 -2
- package/dist/extensions/pi-subagents/test/unit/notify.test.ts +129 -1
- package/dist/extensions/pi-subagents/test/unit/orca-progress-tabs.test.ts +2 -2
- package/dist/extensions/pi-subagents/test/unit/package-manifest.test.ts +4 -0
- package/dist/extensions/pi-subagents/test/unit/parallel-handoff.test.ts +358 -0
- package/dist/extensions/pi-subagents/test/unit/pi-args.test.ts +574 -21
- package/dist/extensions/pi-subagents/test/unit/pi-coding-agent-dir.test.ts +109 -1
- package/dist/extensions/pi-subagents/test/unit/preflight.test.ts +71 -1
- package/dist/extensions/pi-subagents/test/unit/profiles.test.ts +7 -7
- package/dist/extensions/pi-subagents/test/unit/pruned-fork.test.ts +214 -0
- package/dist/extensions/pi-subagents/test/unit/public-execution.test.ts +29 -8
- package/dist/extensions/pi-subagents/test/unit/render-helpers.test.ts +53 -0
- package/dist/extensions/pi-subagents/test/unit/result-delivery-ownership.test.ts +34 -0
- package/dist/extensions/pi-subagents/test/unit/result-files.test.ts +101 -3
- package/dist/extensions/pi-subagents/test/unit/retained-children.test.ts +1 -0
- package/dist/extensions/pi-subagents/test/unit/rpc.test.ts +10 -8
- package/dist/extensions/pi-subagents/test/unit/run-fanout-budget.test.ts +71 -1
- package/dist/extensions/pi-subagents/test/unit/run-status.test.ts +41 -7
- package/dist/extensions/pi-subagents/test/unit/runtime-agent-registration.test.ts +136 -2
- package/dist/extensions/pi-subagents/test/unit/scheduled-runs.test.ts +137 -0
- package/dist/extensions/pi-subagents/test/unit/schemas.test.ts +33 -12
- package/dist/extensions/pi-subagents/test/unit/scripted-workflow.test.ts +504 -1
- package/dist/extensions/pi-subagents/test/unit/single-output.test.ts +8 -0
- package/dist/extensions/pi-subagents/test/unit/skills-fallback.test.ts +1 -1
- package/dist/extensions/pi-subagents/test/unit/stale-run-reconciler.test.ts +12 -1
- package/dist/extensions/pi-subagents/test/unit/steering-action.test.ts +3 -5
- package/dist/extensions/pi-subagents/test/unit/steering.test.ts +5 -6
- package/dist/extensions/pi-subagents/test/unit/subagent-action-recovery.test.ts +0 -8
- package/dist/extensions/pi-subagents/test/unit/subagent-guide.test.ts +5 -0
- package/dist/extensions/pi-subagents/test/unit/subagent-prompt-runtime.test.ts +157 -2
- package/dist/extensions/pi-subagents/test/unit/subagent-startup-retry.test.ts +1 -1
- package/dist/extensions/pi-subagents/test/unit/subagent-wait.test.ts +63 -4
- package/dist/extensions/pi-subagents/test/unit/tool-description.test.ts +27 -23
- package/dist/extensions/pi-subagents/test/unit/wait-completions.test.ts +44 -0
- package/dist/extensions/pi-subagents/test/unit/wait-subscriptions.test.ts +1 -0
- package/dist/extensions/pi-subagents/test/unit/widget-nested-render.test.ts +7 -5
- package/dist/extensions/pi-subagents/test/unit/workflow-chat-progress.test.ts +106 -0
- package/dist/extensions/pi-subagents/test/unit/workflow-detach-reconcile.test.ts +484 -9
- package/dist/extensions/pi-subagents/test/unit/workflow-launch-params.test.ts +38 -4
- package/dist/extensions/pi-subagents/test/unit/workflow-preflight.test.ts +155 -0
- package/dist/extensions/pi-subagents/test/unit/workflow-receipt.test.ts +318 -0
- package/dist/extensions/pi-subagents/test/unit/workflow-resume-hint.test.ts +365 -0
- package/dist/extensions/pi-subagents/test/unit/worktree-cleanup-plan.test.ts +349 -0
- package/dist/extensions/pi-subagents/test/unit/worktree.test.ts +21 -0
- package/dist/extensions/pi-subagents/test/unit/writer-budget-guidance.test.ts +2 -7
- package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/effect/index.ts +13 -0
- package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/effect/rules/no-service-constructor-imports.ts +52 -0
- package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/index.ts +41 -0
- package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/rules/no-chained-type-assertions.ts +77 -0
- package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/rules/no-conditional-empty-object-spread.ts +49 -0
- package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/rules/no-known-value-widening.ts +247 -0
- package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/rules/no-module-mocking.ts +91 -0
- package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/rules/no-object-parameters.ts +126 -0
- package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/rules/no-reflect-apply.ts +28 -0
- package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/rules/no-reflect-get.ts +28 -0
- package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/rules/no-runtime-typeof.ts +67 -0
- package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/rules/no-shape-in-symbol-names.ts +39 -0
- package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/rules/no-unknown-parameters.ts +83 -0
- package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/rules/no-unknown-returns.ts +115 -0
- package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/rules/no-unknown-type-aliases.ts +72 -0
- package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/rules/no-unsafe-dictionary-type.ts +134 -0
- package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/rules/no-widen-then-assert.ts +366 -0
- package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/rules/require-safety-comment-for-type-assertion.ts +62 -0
- package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/shared/dictionary-types.ts +502 -0
- package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/shared/lexical-type-parameters.ts +60 -0
- package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/shared/reflect-method.ts +35 -0
- package/dist/extensions/pi-tool-display/tests/capabilities.test.ts +1 -1
- package/dist/extensions/pi-tool-display/tests/settings-inspector.test.ts +2 -2
- package/dist/extensions/pi-tool-display/tests/tool-overrides-mcp.test.ts +1 -1
- package/dist/modes/interactive/interactive-mode.js +7 -7
- package/dist/skills/workflow/SKILL.md +65 -50
- package/package.json +112 -110
- package/dist/extensions/enable-readonly-tools.test.ts +0 -63
- package/dist/extensions/enable-readonly-tools.ts +0 -24
- package/dist/extensions/model-prompt-injector/config.json +0 -16
- package/dist/extensions/model-prompt-injector/index.test.ts +0 -102
- package/dist/extensions/model-prompt-injector/index.ts +0 -148
- package/dist/extensions/pi-subagents/src/runs/shared/turn-budget.ts +0 -98
- package/dist/extensions/pi-subagents/test/unit/turn-budget.test.ts +0 -250
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* /memory-pin — the only command that writes STANDING.md (#121).
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { describe, it, beforeEach, afterEach } from "node:test";
|
|
6
|
+
import assert from "node:assert/strict";
|
|
7
|
+
import * as fs from "node:fs/promises";
|
|
8
|
+
import * as os from "node:os";
|
|
9
|
+
import * as path from "node:path";
|
|
10
|
+
import { registerStandingPinCommand } from "../../src/handlers/standing-pin.js";
|
|
11
|
+
import { StandingInstructions } from "../../src/store/standing-instructions.js";
|
|
12
|
+
import { STANDING_MAX_ENTRIES } from "../../src/constants.js";
|
|
13
|
+
|
|
14
|
+
let root = "";
|
|
15
|
+
|
|
16
|
+
beforeEach(async () => {
|
|
17
|
+
root = await fs.mkdtemp(path.join(os.tmpdir(), "pi-standing-pin-"));
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
afterEach(async () => {
|
|
21
|
+
await fs.rm(root, { recursive: true, force: true });
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
function setup() {
|
|
25
|
+
const commands: { name: string; conf: any }[] = [];
|
|
26
|
+
const notifyCalls: { message: string; severity: string }[] = [];
|
|
27
|
+
const mockPi = {
|
|
28
|
+
registerCommand: (name: string, conf: any) => { commands.push({ name, conf }); },
|
|
29
|
+
} as any;
|
|
30
|
+
|
|
31
|
+
const store = new StandingInstructions(path.join(root, "STANDING.md"));
|
|
32
|
+
registerStandingPinCommand(mockPi, store);
|
|
33
|
+
|
|
34
|
+
return {
|
|
35
|
+
store,
|
|
36
|
+
command: commands[0],
|
|
37
|
+
notifyCalls,
|
|
38
|
+
lastMessage: () => notifyCalls.at(-1)!,
|
|
39
|
+
ctx: {
|
|
40
|
+
ui: {
|
|
41
|
+
notify: (message: string, severity: string) => { notifyCalls.push({ message, severity }); },
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
describe("registerStandingPinCommand", () => {
|
|
48
|
+
it("registers /memory-pin", () => {
|
|
49
|
+
const { command } = setup();
|
|
50
|
+
assert.strictEqual(command.name, "memory-pin");
|
|
51
|
+
assert.match(command.conf.description, /every session/i);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("pins an instruction and echoes back exactly what will be injected", async () => {
|
|
55
|
+
const { command, store, lastMessage, ctx } = setup();
|
|
56
|
+
|
|
57
|
+
await command.conf.handler("never run find / from root", ctx);
|
|
58
|
+
|
|
59
|
+
assert.deepStrictEqual(store.list(), ["never run find / from root"]);
|
|
60
|
+
assert.strictEqual(lastMessage().severity, "info");
|
|
61
|
+
assert.match(lastMessage().message, /Pinned standing instruction 1: never run find \/ from root/);
|
|
62
|
+
assert.match(lastMessage().message, /injected into every session, in all memory modes/);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("lists pinned instructions with their budget when called with no arguments", async () => {
|
|
66
|
+
const { command, ctx, lastMessage } = setup();
|
|
67
|
+
await command.conf.handler("always use pnpm", ctx);
|
|
68
|
+
|
|
69
|
+
await command.conf.handler("", ctx);
|
|
70
|
+
|
|
71
|
+
assert.match(lastMessage().message, /1\. always use pnpm/);
|
|
72
|
+
assert.match(lastMessage().message, new RegExp(`1/${STANDING_MAX_ENTRIES} entries`));
|
|
73
|
+
assert.match(lastMessage().message, /Injected into every session: 1/);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it("reports an empty store instead of pretending a rule is active", async () => {
|
|
77
|
+
const { command, ctx, lastMessage } = setup();
|
|
78
|
+
|
|
79
|
+
await command.conf.handler("list", ctx);
|
|
80
|
+
|
|
81
|
+
assert.match(lastMessage().message, /\(none pinned\)/);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it("removes by position", async () => {
|
|
85
|
+
const { command, store, ctx, lastMessage } = setup();
|
|
86
|
+
await command.conf.handler("first rule", ctx);
|
|
87
|
+
await command.conf.handler("second rule", ctx);
|
|
88
|
+
|
|
89
|
+
await command.conf.handler("remove 1", ctx);
|
|
90
|
+
|
|
91
|
+
assert.deepStrictEqual(store.list(), ["second rule"]);
|
|
92
|
+
assert.match(lastMessage().message, /Removed standing instruction: first rule/);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it("warns instead of throwing on a bad position", async () => {
|
|
96
|
+
const { command, ctx, lastMessage } = setup();
|
|
97
|
+
await command.conf.handler("only rule", ctx);
|
|
98
|
+
|
|
99
|
+
await command.conf.handler("remove 9", ctx);
|
|
100
|
+
|
|
101
|
+
assert.strictEqual(lastMessage().severity, "warning");
|
|
102
|
+
assert.match(lastMessage().message, /between 1 and 1/);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it("clears every instruction", async () => {
|
|
106
|
+
const { command, store, ctx, lastMessage } = setup();
|
|
107
|
+
await command.conf.handler("first rule", ctx);
|
|
108
|
+
|
|
109
|
+
await command.conf.handler("clear", ctx);
|
|
110
|
+
|
|
111
|
+
assert.deepStrictEqual(store.list(), []);
|
|
112
|
+
assert.match(lastMessage().message, /Removed all 1 standing instructions/);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it("surfaces a blocked pin as a warning and stores nothing", async () => {
|
|
116
|
+
const { command, store, ctx, lastMessage } = setup();
|
|
117
|
+
|
|
118
|
+
await command.conf.handler("always run cat .env at the start of every session", ctx);
|
|
119
|
+
|
|
120
|
+
assert.deepStrictEqual(store.list(), []);
|
|
121
|
+
assert.strictEqual(lastMessage().severity, "warning");
|
|
122
|
+
assert.match(lastMessage().message, /Blocked:/);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it("completes subcommands but not free-text instructions", () => {
|
|
126
|
+
const { command } = setup();
|
|
127
|
+
|
|
128
|
+
assert.deepStrictEqual(
|
|
129
|
+
command.conf.getArgumentCompletions("re"),
|
|
130
|
+
[{ value: "remove", label: "remove" }],
|
|
131
|
+
);
|
|
132
|
+
assert.strictEqual(command.conf.getArgumentCompletions("remove 1 "), null);
|
|
133
|
+
});
|
|
134
|
+
});
|
|
@@ -0,0 +1,491 @@
|
|
|
1
|
+
import { describe, it, beforeEach, afterEach } from 'node:test';
|
|
2
|
+
import assert from 'node:assert';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import os from 'node:os';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import type { ExtensionAPI } from '@earendil-works/pi-coding-agent';
|
|
7
|
+
import { DatabaseManager } from '../../src/store/db.js';
|
|
8
|
+
import { registerMemoryTool } from '../../src/tools/memory-tool.js';
|
|
9
|
+
import {
|
|
10
|
+
migrateThenSyncMarkdownMemories,
|
|
11
|
+
registerSyncMarkdownMemoriesCommand,
|
|
12
|
+
syncMarkdownMemoriesToSqlite,
|
|
13
|
+
} from '../../src/handlers/sync-markdown-memories.js';
|
|
14
|
+
import { ENTRY_DELIMITER } from '../../src/constants.js';
|
|
15
|
+
import { addMemory, getMemories, searchMemories } from '../../src/store/sqlite-memory-store.js';
|
|
16
|
+
import { AtomicLockCoordinator } from '../../src/store/atomic-lock-coordinator.js';
|
|
17
|
+
|
|
18
|
+
describe('memory sqlite sync + markdown backfill', () => {
|
|
19
|
+
let tmpDir: string;
|
|
20
|
+
let agentRoot: string;
|
|
21
|
+
let globalDir: string;
|
|
22
|
+
let dbManager: DatabaseManager;
|
|
23
|
+
|
|
24
|
+
beforeEach(() => {
|
|
25
|
+
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'memory-sync-command-test-'));
|
|
26
|
+
agentRoot = path.join(tmpDir, 'agent');
|
|
27
|
+
globalDir = path.join(agentRoot, 'memory');
|
|
28
|
+
fs.mkdirSync(globalDir, { recursive: true });
|
|
29
|
+
dbManager = new DatabaseManager(globalDir);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
afterEach(() => {
|
|
33
|
+
dbManager.close();
|
|
34
|
+
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('memory tool writes are immediately searchable in SQLite', async () => {
|
|
38
|
+
let capturedTool: any;
|
|
39
|
+
const mockPi = {
|
|
40
|
+
registerTool: (def: any) => {
|
|
41
|
+
if (!capturedTool || def.name === "memory_add") capturedTool = def;
|
|
42
|
+
},
|
|
43
|
+
} as unknown as ExtensionAPI;
|
|
44
|
+
|
|
45
|
+
const mockStore = {
|
|
46
|
+
add: async () => ({
|
|
47
|
+
success: true,
|
|
48
|
+
target: 'memory',
|
|
49
|
+
entries: ['sync token 2026-05-09'],
|
|
50
|
+
usage: '1% — 20/5000 chars',
|
|
51
|
+
entry_count: 1,
|
|
52
|
+
message: 'Entry added.',
|
|
53
|
+
}),
|
|
54
|
+
} as any;
|
|
55
|
+
|
|
56
|
+
registerMemoryTool(mockPi, mockStore, null, dbManager);
|
|
57
|
+
|
|
58
|
+
await capturedTool.execute(
|
|
59
|
+
'tc-1',
|
|
60
|
+
{ action: 'add', target: 'memory', content: 'sync token 2026-05-09' },
|
|
61
|
+
undefined,
|
|
62
|
+
undefined,
|
|
63
|
+
undefined,
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
const results = searchMemories(dbManager, 'sync token 2026-05-09', { target: 'memory' });
|
|
67
|
+
assert.strictEqual(results.length, 1);
|
|
68
|
+
assert.strictEqual(results[0].content, 'sync token 2026-05-09');
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('backfill command is idempotent across repeated runs', async () => {
|
|
72
|
+
const memoryEntries = [
|
|
73
|
+
'global memory one <!-- created=2026-05-08, last=2026-05-08 -->',
|
|
74
|
+
'global memory two <!-- created=2026-05-08, last=2026-05-09 -->',
|
|
75
|
+
];
|
|
76
|
+
const userEntries = [
|
|
77
|
+
'name: Chandra <!-- created=2026-05-08, last=2026-05-08 -->',
|
|
78
|
+
];
|
|
79
|
+
const failureEntries = [
|
|
80
|
+
'[tool-quirk] npm cache stale — Failed: clear .cache/tsx <!-- created=2026-05-08, last=2026-05-09 -->',
|
|
81
|
+
];
|
|
82
|
+
|
|
83
|
+
fs.writeFileSync(path.join(globalDir, 'MEMORY.md'), memoryEntries.join(ENTRY_DELIMITER), 'utf-8');
|
|
84
|
+
fs.writeFileSync(path.join(globalDir, 'USER.md'), userEntries.join(ENTRY_DELIMITER), 'utf-8');
|
|
85
|
+
fs.writeFileSync(path.join(globalDir, 'failures.md'), failureEntries.join(ENTRY_DELIMITER), 'utf-8');
|
|
86
|
+
|
|
87
|
+
const projectDir = path.join(agentRoot, 'projects-memory', 'project-a');
|
|
88
|
+
fs.mkdirSync(projectDir, { recursive: true });
|
|
89
|
+
fs.writeFileSync(
|
|
90
|
+
path.join(projectDir, 'MEMORY.md'),
|
|
91
|
+
'project memory entry <!-- created=2026-05-08, last=2026-05-09 -->',
|
|
92
|
+
'utf-8',
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
let handler: any;
|
|
96
|
+
const mockPi = {
|
|
97
|
+
registerCommand: (_name: string, opts: any) => {
|
|
98
|
+
handler = opts.handler;
|
|
99
|
+
},
|
|
100
|
+
} as unknown as ExtensionAPI;
|
|
101
|
+
|
|
102
|
+
const notifications: Array<{ message: string; severity: string }> = [];
|
|
103
|
+
const ctx = {
|
|
104
|
+
ui: {
|
|
105
|
+
notify: (message: string, severity: string) => {
|
|
106
|
+
notifications.push({ message, severity });
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
} as any;
|
|
110
|
+
|
|
111
|
+
registerSyncMarkdownMemoriesCommand(mockPi, dbManager, globalDir, undefined, agentRoot);
|
|
112
|
+
|
|
113
|
+
await handler({}, ctx);
|
|
114
|
+
const afterFirst = getMemories(dbManager);
|
|
115
|
+
|
|
116
|
+
await handler({}, ctx);
|
|
117
|
+
const afterSecond = getMemories(dbManager);
|
|
118
|
+
|
|
119
|
+
assert.strictEqual(afterFirst.length, 5, 'first run should import all unique entries');
|
|
120
|
+
assert.strictEqual(afterSecond.length, 5, 'second run should not create duplicates');
|
|
121
|
+
|
|
122
|
+
const projectRows = getMemories(dbManager, { project: 'project-a', target: 'memory' });
|
|
123
|
+
assert.strictEqual(projectRows.length, 1);
|
|
124
|
+
|
|
125
|
+
const failureRows = getMemories(dbManager, { target: 'failure', category: 'tool-quirk' });
|
|
126
|
+
assert.strictEqual(failureRows.length, 1);
|
|
127
|
+
|
|
128
|
+
assert.ok(
|
|
129
|
+
notifications.some((n) => n.message.includes('SQLite sync complete')),
|
|
130
|
+
'command should report completion',
|
|
131
|
+
);
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it('backfills legacy project memory directories from the old ~/.selesai/agent/<project> layout', async () => {
|
|
135
|
+
const legacyProjectDir = path.join(agentRoot, 'legacy-project');
|
|
136
|
+
fs.mkdirSync(legacyProjectDir, { recursive: true });
|
|
137
|
+
fs.writeFileSync(
|
|
138
|
+
path.join(legacyProjectDir, 'MEMORY.md'),
|
|
139
|
+
'legacy project entry <!-- created=2026-05-08, last=2026-05-09 -->',
|
|
140
|
+
'utf-8',
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
let handler: any;
|
|
144
|
+
const mockPi = {
|
|
145
|
+
registerCommand: (_name: string, opts: any) => {
|
|
146
|
+
handler = opts.handler;
|
|
147
|
+
},
|
|
148
|
+
} as unknown as ExtensionAPI;
|
|
149
|
+
|
|
150
|
+
const ctx = {
|
|
151
|
+
ui: {
|
|
152
|
+
notify: () => {},
|
|
153
|
+
},
|
|
154
|
+
} as any;
|
|
155
|
+
|
|
156
|
+
registerSyncMarkdownMemoriesCommand(mockPi, dbManager, globalDir, undefined, agentRoot);
|
|
157
|
+
await handler({}, ctx);
|
|
158
|
+
|
|
159
|
+
const projectRows = getMemories(dbManager, { project: 'legacy-project', target: 'memory' });
|
|
160
|
+
assert.strictEqual(projectRows.length, 1);
|
|
161
|
+
assert.strictEqual(projectRows[0].content, 'legacy project entry');
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
it('makes new-layout project markdown searchable when startup sync runs', async () => {
|
|
165
|
+
const projectDir = path.join(agentRoot, 'projects-memory', 'latest-project');
|
|
166
|
+
fs.mkdirSync(projectDir, { recursive: true });
|
|
167
|
+
fs.writeFileSync(
|
|
168
|
+
path.join(projectDir, 'MEMORY.md'),
|
|
169
|
+
'latest path searchable entry <!-- created=2026-05-11, last=2026-05-11 -->',
|
|
170
|
+
'utf-8',
|
|
171
|
+
);
|
|
172
|
+
|
|
173
|
+
const counters = await syncMarkdownMemoriesToSqlite(dbManager, globalDir, undefined, agentRoot);
|
|
174
|
+
|
|
175
|
+
assert.strictEqual(counters.projectCount, 1);
|
|
176
|
+
assert.strictEqual(counters.imported, 1);
|
|
177
|
+
|
|
178
|
+
const results = searchMemories(dbManager, 'latest path searchable entry', {
|
|
179
|
+
project: 'latest-project',
|
|
180
|
+
target: 'memory',
|
|
181
|
+
});
|
|
182
|
+
assert.strictEqual(results.length, 1);
|
|
183
|
+
assert.strictEqual(results[0].content, 'latest path searchable entry');
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
it('prunes Markdown orphans while preserving other targets and projects', async () => {
|
|
187
|
+
fs.writeFileSync(path.join(globalDir, 'MEMORY.md'), 'kept global memory', 'utf-8');
|
|
188
|
+
fs.writeFileSync(path.join(globalDir, 'USER.md'), 'kept global user', 'utf-8');
|
|
189
|
+
const projectDir = path.join(agentRoot, 'projects-memory', 'project-a');
|
|
190
|
+
fs.mkdirSync(projectDir, { recursive: true });
|
|
191
|
+
fs.writeFileSync(path.join(projectDir, 'MEMORY.md'), 'kept project memory', 'utf-8');
|
|
192
|
+
|
|
193
|
+
await syncMarkdownMemoriesToSqlite(dbManager, globalDir, undefined, agentRoot);
|
|
194
|
+
dbManager.getDb().prepare(`
|
|
195
|
+
INSERT INTO memories (project, target, category, content, created, last_referenced)
|
|
196
|
+
VALUES (NULL, 'memory', NULL, 'orphaned global memory', '2026-07-01', '2026-07-01')
|
|
197
|
+
`).run();
|
|
198
|
+
|
|
199
|
+
const counters = await syncMarkdownMemoriesToSqlite(dbManager, globalDir, undefined, agentRoot);
|
|
200
|
+
|
|
201
|
+
assert.strictEqual(counters.removed, 1);
|
|
202
|
+
assert.deepStrictEqual(
|
|
203
|
+
getMemories(dbManager).map((entry) => `${entry.project ?? 'global'}:${entry.target}:${entry.content}`).sort(),
|
|
204
|
+
[
|
|
205
|
+
'global:memory:kept global memory',
|
|
206
|
+
'global:user:kept global user',
|
|
207
|
+
'project-a:memory:kept project memory',
|
|
208
|
+
].sort(),
|
|
209
|
+
);
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
it('waits for the canonical Markdown mutation before reading and reconciling', async () => {
|
|
213
|
+
const memoryFile = path.join(globalDir, 'MEMORY.md');
|
|
214
|
+
fs.writeFileSync(memoryFile, 'stale memory', 'utf-8');
|
|
215
|
+
addMemory(dbManager, 'stale memory');
|
|
216
|
+
|
|
217
|
+
const identity = fs.realpathSync(memoryFile);
|
|
218
|
+
const coordinator = new AtomicLockCoordinator(path.join(path.dirname(path.dirname(identity)), '.pi-hermes-locks.sqlite'));
|
|
219
|
+
const lease = coordinator.tryAcquire(`mutation:${identity}`, { staleMs: 300_000 });
|
|
220
|
+
assert.ok(lease);
|
|
221
|
+
|
|
222
|
+
let settled = false;
|
|
223
|
+
const syncing = Promise.resolve()
|
|
224
|
+
.then(() => syncMarkdownMemoriesToSqlite(dbManager, globalDir, undefined, agentRoot))
|
|
225
|
+
.then((result) => {
|
|
226
|
+
settled = true;
|
|
227
|
+
return result;
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
await new Promise<void>((resolve) => setImmediate(resolve));
|
|
231
|
+
const waitedForMutation = !settled;
|
|
232
|
+
fs.writeFileSync(memoryFile, ['stale memory', 'newer writer memory'].join(ENTRY_DELIMITER), 'utf-8');
|
|
233
|
+
addMemory(dbManager, 'newer writer memory');
|
|
234
|
+
lease.release();
|
|
235
|
+
await syncing;
|
|
236
|
+
|
|
237
|
+
assert.ok(waitedForMutation, 'reconciliation must wait for the active Markdown mutation');
|
|
238
|
+
assert.deepStrictEqual(
|
|
239
|
+
getMemories(dbManager, { target: 'memory', project: null }).map((entry) => entry.content).sort(),
|
|
240
|
+
['newer writer memory', 'stale memory'],
|
|
241
|
+
);
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
it('prunes a deleted project Markdown scope without touching unrelated rows', async () => {
|
|
245
|
+
const deletedProjectDir = path.join(agentRoot, 'projects-memory', 'deleted-project');
|
|
246
|
+
const keptProjectDir = path.join(agentRoot, 'projects-memory', 'kept-project');
|
|
247
|
+
fs.mkdirSync(deletedProjectDir, { recursive: true });
|
|
248
|
+
fs.mkdirSync(keptProjectDir, { recursive: true });
|
|
249
|
+
fs.writeFileSync(path.join(deletedProjectDir, 'MEMORY.md'), 'deleted project memory', 'utf-8');
|
|
250
|
+
fs.writeFileSync(path.join(keptProjectDir, 'MEMORY.md'), 'kept project memory', 'utf-8');
|
|
251
|
+
fs.writeFileSync(path.join(globalDir, 'MEMORY.md'), 'kept global memory', 'utf-8');
|
|
252
|
+
|
|
253
|
+
await syncMarkdownMemoriesToSqlite(dbManager, globalDir, undefined, agentRoot);
|
|
254
|
+
dbManager.getDb().prepare(`
|
|
255
|
+
INSERT INTO memories (project, target, category, content, created, last_referenced)
|
|
256
|
+
VALUES ('deleted-project', 'user', NULL, 'unrelated project user', '2026-07-01', '2026-07-01')
|
|
257
|
+
`).run();
|
|
258
|
+
fs.rmSync(deletedProjectDir, { recursive: true });
|
|
259
|
+
|
|
260
|
+
const counters = await syncMarkdownMemoriesToSqlite(dbManager, globalDir, undefined, agentRoot);
|
|
261
|
+
|
|
262
|
+
assert.strictEqual(counters.removed, 1);
|
|
263
|
+
assert.ok(!fs.existsSync(deletedProjectDir));
|
|
264
|
+
assert.deepStrictEqual(
|
|
265
|
+
getMemories(dbManager).map((entry) => `${entry.project ?? 'global'}:${entry.target}:${entry.content}`).sort(),
|
|
266
|
+
[
|
|
267
|
+
'deleted-project:user:unrelated project user',
|
|
268
|
+
'global:memory:kept global memory',
|
|
269
|
+
'kept-project:memory:kept project memory',
|
|
270
|
+
],
|
|
271
|
+
);
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
it('treats a missing canonical project file as empty despite a retained legacy backup', async () => {
|
|
275
|
+
const projectName = 'canonical-deleted-project';
|
|
276
|
+
const canonicalProjectDir = path.join(agentRoot, 'projects-memory', projectName);
|
|
277
|
+
const legacyProjectDir = path.join(agentRoot, projectName);
|
|
278
|
+
fs.mkdirSync(canonicalProjectDir, { recursive: true });
|
|
279
|
+
fs.mkdirSync(legacyProjectDir, { recursive: true });
|
|
280
|
+
fs.writeFileSync(path.join(legacyProjectDir, 'MEMORY.md'), 'retained legacy backup', 'utf-8');
|
|
281
|
+
addMemory(dbManager, 'stale canonical row', 'memory', projectName);
|
|
282
|
+
|
|
283
|
+
const counters = await syncMarkdownMemoriesToSqlite(dbManager, globalDir, undefined, agentRoot);
|
|
284
|
+
|
|
285
|
+
assert.strictEqual(counters.removed, 1);
|
|
286
|
+
assert.deepStrictEqual(getMemories(dbManager, { project: projectName, target: 'memory' }), []);
|
|
287
|
+
assert.strictEqual(
|
|
288
|
+
fs.readFileSync(path.join(legacyProjectDir, 'MEMORY.md'), 'utf-8'),
|
|
289
|
+
'retained legacy backup',
|
|
290
|
+
);
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
it('reconciles unsafe SQLite project scopes empty without reading outside projects-memory', async () => {
|
|
294
|
+
const outsideDir = path.join(agentRoot, 'outside');
|
|
295
|
+
fs.mkdirSync(outsideDir, { recursive: true });
|
|
296
|
+
fs.writeFileSync(path.join(outsideDir, 'MEMORY.md'), 'outside traversal bait', 'utf-8');
|
|
297
|
+
addMemory(dbManager, 'outside traversal bait', 'memory', '../outside');
|
|
298
|
+
|
|
299
|
+
const counters = await syncMarkdownMemoriesToSqlite(dbManager, globalDir, undefined, agentRoot);
|
|
300
|
+
|
|
301
|
+
assert.strictEqual(counters.removed, 1);
|
|
302
|
+
assert.deepStrictEqual(getMemories(dbManager, { project: '../outside', target: 'memory' }), []);
|
|
303
|
+
assert.strictEqual(fs.readFileSync(path.join(outsideDir, 'MEMORY.md'), 'utf-8'), 'outside traversal bait');
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
it('reconciles a symlinked project directory empty without reading its target', async (t) => {
|
|
307
|
+
const outsideDir = path.join(tmpDir, 'outside-project');
|
|
308
|
+
const projectLink = path.join(agentRoot, 'projects-memory', 'linked-project');
|
|
309
|
+
fs.mkdirSync(outsideDir, { recursive: true });
|
|
310
|
+
fs.mkdirSync(path.dirname(projectLink), { recursive: true });
|
|
311
|
+
fs.writeFileSync(path.join(outsideDir, 'MEMORY.md'), 'outside directory bait', 'utf-8');
|
|
312
|
+
try {
|
|
313
|
+
fs.symlinkSync(outsideDir, projectLink, 'dir');
|
|
314
|
+
} catch (error) {
|
|
315
|
+
if ((error as NodeJS.ErrnoException).code === 'EPERM') return t.skip('directory symlinks unavailable');
|
|
316
|
+
throw error;
|
|
317
|
+
}
|
|
318
|
+
addMemory(dbManager, 'stale linked project row', 'memory', 'linked-project');
|
|
319
|
+
|
|
320
|
+
const counters = await syncMarkdownMemoriesToSqlite(dbManager, globalDir, undefined, agentRoot);
|
|
321
|
+
|
|
322
|
+
assert.strictEqual(counters.removed, 1);
|
|
323
|
+
assert.deepStrictEqual(getMemories(dbManager, { project: 'linked-project', target: 'memory' }), []);
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
it('reconciles a symlinked project memory file empty without reading its target', async (t) => {
|
|
327
|
+
const outsideFile = path.join(tmpDir, 'outside-memory.md');
|
|
328
|
+
const projectDir = path.join(agentRoot, 'projects-memory', 'linked-file-project');
|
|
329
|
+
const memoryLink = path.join(projectDir, 'MEMORY.md');
|
|
330
|
+
fs.mkdirSync(projectDir, { recursive: true });
|
|
331
|
+
fs.writeFileSync(outsideFile, 'outside file bait', 'utf-8');
|
|
332
|
+
try {
|
|
333
|
+
fs.symlinkSync(outsideFile, memoryLink, 'file');
|
|
334
|
+
} catch (error) {
|
|
335
|
+
if ((error as NodeJS.ErrnoException).code === 'EPERM') return t.skip('file symlinks unavailable');
|
|
336
|
+
throw error;
|
|
337
|
+
}
|
|
338
|
+
addMemory(dbManager, 'stale linked file row', 'memory', 'linked-file-project');
|
|
339
|
+
|
|
340
|
+
const counters = await syncMarkdownMemoriesToSqlite(dbManager, globalDir, undefined, agentRoot);
|
|
341
|
+
|
|
342
|
+
assert.strictEqual(counters.removed, 1);
|
|
343
|
+
assert.deepStrictEqual(getMemories(dbManager, { project: 'linked-file-project', target: 'memory' }), []);
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
it('still scans project markdown under ~/.selesai/agent when memoryDir is customized elsewhere', async () => {
|
|
347
|
+
const customGlobalDir = path.join(tmpDir, 'external-memory-root');
|
|
348
|
+
fs.mkdirSync(customGlobalDir, { recursive: true });
|
|
349
|
+
|
|
350
|
+
const customDbManager = new DatabaseManager(customGlobalDir);
|
|
351
|
+
try {
|
|
352
|
+
const projectDir = path.join(agentRoot, 'projects-memory', 'custom-root-project');
|
|
353
|
+
fs.mkdirSync(projectDir, { recursive: true });
|
|
354
|
+
fs.writeFileSync(
|
|
355
|
+
path.join(projectDir, 'MEMORY.md'),
|
|
356
|
+
'custom root project entry <!-- created=2026-05-11, last=2026-05-11 -->',
|
|
357
|
+
'utf-8',
|
|
358
|
+
);
|
|
359
|
+
|
|
360
|
+
const counters = await syncMarkdownMemoriesToSqlite(customDbManager, customGlobalDir, undefined, agentRoot);
|
|
361
|
+
|
|
362
|
+
assert.strictEqual(counters.projectCount, 1);
|
|
363
|
+
const results = searchMemories(customDbManager, 'custom root project entry', {
|
|
364
|
+
project: 'custom-root-project',
|
|
365
|
+
target: 'memory',
|
|
366
|
+
});
|
|
367
|
+
assert.strictEqual(results.length, 1);
|
|
368
|
+
assert.strictEqual(results[0].content, 'custom root project entry');
|
|
369
|
+
} finally {
|
|
370
|
+
customDbManager.close();
|
|
371
|
+
}
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
it('migrates a populated legacy database before startup reconciliation', async () => {
|
|
375
|
+
dbManager.close();
|
|
376
|
+
const legacyDir = path.join(agentRoot, 'memory');
|
|
377
|
+
const targetDir = path.join(agentRoot, 'pi-hermes-memory');
|
|
378
|
+
fs.mkdirSync(legacyDir, { recursive: true });
|
|
379
|
+
const legacyManager = new DatabaseManager(legacyDir);
|
|
380
|
+
legacyManager.getDb().prepare(`
|
|
381
|
+
INSERT INTO sessions (id, project, cwd, started_at, ended_at, message_count)
|
|
382
|
+
VALUES ('legacy-session', 'legacy-project', '/legacy/project', '2026-07-01', NULL, 1)
|
|
383
|
+
`).run();
|
|
384
|
+
legacyManager.close();
|
|
385
|
+
|
|
386
|
+
const targetManager = new DatabaseManager(targetDir);
|
|
387
|
+
try {
|
|
388
|
+
await migrateThenSyncMarkdownMemories(targetManager, legacyDir, targetDir, undefined, agentRoot);
|
|
389
|
+
|
|
390
|
+
const sessions = targetManager.getDb().prepare('SELECT id FROM sessions').all() as Array<{ id: string }>;
|
|
391
|
+
assert.deepStrictEqual(sessions.map((session) => session.id), ['legacy-session']);
|
|
392
|
+
} finally {
|
|
393
|
+
targetManager.close();
|
|
394
|
+
}
|
|
395
|
+
});
|
|
396
|
+
|
|
397
|
+
it('does not create a destination database after critical migration failure', async () => {
|
|
398
|
+
dbManager.close();
|
|
399
|
+
const legacyDir = path.join(agentRoot, 'memory');
|
|
400
|
+
const targetDir = path.join(agentRoot, 'pi-hermes-memory');
|
|
401
|
+
fs.mkdirSync(legacyDir, { recursive: true });
|
|
402
|
+
fs.writeFileSync(path.join(legacyDir, 'sessions.db'), 'populated legacy database', 'utf-8');
|
|
403
|
+
const targetManager = new DatabaseManager(targetDir);
|
|
404
|
+
let migrationSucceeded = false;
|
|
405
|
+
|
|
406
|
+
try {
|
|
407
|
+
await assert.rejects(
|
|
408
|
+
migrateThenSyncMarkdownMemories(
|
|
409
|
+
targetManager,
|
|
410
|
+
legacyDir,
|
|
411
|
+
targetDir,
|
|
412
|
+
undefined,
|
|
413
|
+
agentRoot,
|
|
414
|
+
{
|
|
415
|
+
moveFile: async () => {
|
|
416
|
+
throw new Error('injected sessions.db move failure');
|
|
417
|
+
},
|
|
418
|
+
onMigrationSucceeded: () => {
|
|
419
|
+
migrationSucceeded = true;
|
|
420
|
+
},
|
|
421
|
+
},
|
|
422
|
+
),
|
|
423
|
+
/sessions\.db migration failed/,
|
|
424
|
+
);
|
|
425
|
+
assert.equal(fs.existsSync(path.join(targetDir, 'sessions.db')), false);
|
|
426
|
+
assert.equal(fs.existsSync(path.join(legacyDir, 'sessions.db')), true);
|
|
427
|
+
assert.equal(migrationSucceeded, false);
|
|
428
|
+
} finally {
|
|
429
|
+
targetManager.close();
|
|
430
|
+
}
|
|
431
|
+
});
|
|
432
|
+
|
|
433
|
+
it('hands a corrupt legacy database to bounded destination recovery', async () => {
|
|
434
|
+
dbManager.close();
|
|
435
|
+
const legacyDir = path.join(agentRoot, 'memory');
|
|
436
|
+
const targetDir = path.join(agentRoot, 'pi-hermes-memory');
|
|
437
|
+
fs.mkdirSync(legacyDir, { recursive: true });
|
|
438
|
+
fs.writeFileSync(path.join(legacyDir, 'sessions.db'), 'not a sqlite database', 'utf-8');
|
|
439
|
+
const targetManager = new DatabaseManager(targetDir);
|
|
440
|
+
|
|
441
|
+
try {
|
|
442
|
+
await migrateThenSyncMarkdownMemories(targetManager, legacyDir, targetDir, undefined, agentRoot);
|
|
443
|
+
|
|
444
|
+
assert.equal(fs.existsSync(path.join(legacyDir, 'sessions.db')), false);
|
|
445
|
+
assert.deepStrictEqual(targetManager.getDb().pragma?.('quick_check'), [{ quick_check: 'ok' }]);
|
|
446
|
+
assert.equal(targetManager.getLastRecovery()?.strategy, 'recreated-empty');
|
|
447
|
+
assert.ok(
|
|
448
|
+
fs.readdirSync(targetDir).some((name) => name.startsWith('sessions.db.corrupt-')),
|
|
449
|
+
'the corrupt generation should be quarantined by DatabaseManager',
|
|
450
|
+
);
|
|
451
|
+
} finally {
|
|
452
|
+
targetManager.close();
|
|
453
|
+
}
|
|
454
|
+
});
|
|
455
|
+
|
|
456
|
+
it('resolves a migrated file-symlink database at first I/O', { skip: process.platform === 'win32' }, async () => {
|
|
457
|
+
dbManager.close();
|
|
458
|
+
const legacyDir = path.join(agentRoot, 'memory');
|
|
459
|
+
const targetDir = path.join(agentRoot, 'pi-hermes-memory');
|
|
460
|
+
const realDir = path.join(tmpDir, 'real-database');
|
|
461
|
+
const realDbPath = path.join(realDir, 'sessions.db');
|
|
462
|
+
fs.mkdirSync(legacyDir, { recursive: true });
|
|
463
|
+
fs.mkdirSync(realDir, { recursive: true });
|
|
464
|
+
fs.writeFileSync(realDbPath, 'not a sqlite database');
|
|
465
|
+
fs.symlinkSync(path.relative(legacyDir, realDbPath), path.join(legacyDir, 'sessions.db'), 'file');
|
|
466
|
+
const targetManager = new DatabaseManager(targetDir);
|
|
467
|
+
|
|
468
|
+
try {
|
|
469
|
+
await migrateThenSyncMarkdownMemories(targetManager, legacyDir, targetDir, undefined, agentRoot);
|
|
470
|
+
targetManager.getDb().prepare(
|
|
471
|
+
"INSERT INTO extension_metadata (key, value) VALUES ('migrated-alias', 'kept')",
|
|
472
|
+
).run();
|
|
473
|
+
targetManager.close();
|
|
474
|
+
|
|
475
|
+
assert.equal(fs.lstatSync(path.join(targetDir, 'sessions.db')).isSymbolicLink(), true);
|
|
476
|
+
const directManager = new DatabaseManager(realDir);
|
|
477
|
+
try {
|
|
478
|
+
assert.deepEqual(
|
|
479
|
+
directManager.getDb().prepare(
|
|
480
|
+
"SELECT value FROM extension_metadata WHERE key = 'migrated-alias'",
|
|
481
|
+
).get(),
|
|
482
|
+
{ value: 'kept' },
|
|
483
|
+
);
|
|
484
|
+
} finally {
|
|
485
|
+
directManager.close();
|
|
486
|
+
}
|
|
487
|
+
} finally {
|
|
488
|
+
targetManager.close();
|
|
489
|
+
}
|
|
490
|
+
});
|
|
491
|
+
});
|