@agentmemory/agentmemory 0.9.30 → 0.9.32
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/.env.example +57 -48
- package/AGENTS.md +8 -8
- package/README.md +256 -819
- package/dist/.env.example +57 -48
- package/dist/cli.d.mts.map +1 -1
- package/dist/cli.mjs +2257 -1027
- package/dist/cli.mjs.map +1 -1
- package/dist/compression-recovery-CZh63Jmz.mjs +5997 -0
- package/dist/compression-recovery-CZh63Jmz.mjs.map +1 -0
- package/dist/{connect-B4_ca6BD.mjs → connect-BX3njQ3Y.mjs} +897 -276
- package/dist/connect-BX3njQ3Y.mjs.map +1 -0
- package/dist/hooks/_capture.d.mts +5 -1
- package/dist/hooks/_capture.d.mts.map +1 -1
- package/dist/hooks/_capture.mjs +141 -26
- package/dist/hooks/_capture.mjs.map +1 -1
- package/dist/hooks/notification.mjs +20 -6
- package/dist/hooks/notification.mjs.map +1 -1
- package/dist/hooks/post-commit.mjs +83 -10
- package/dist/hooks/post-commit.mjs.map +1 -1
- package/dist/hooks/post-tool-failure.mjs +19 -6
- package/dist/hooks/post-tool-failure.mjs.map +1 -1
- package/dist/hooks/post-tool-use.mjs +19 -6
- package/dist/hooks/post-tool-use.mjs.map +1 -1
- package/dist/hooks/pre-compact.mjs +104 -22
- package/dist/hooks/pre-compact.mjs.map +1 -1
- package/dist/hooks/pre-tool-use.mjs +83 -10
- package/dist/hooks/pre-tool-use.mjs.map +1 -1
- package/dist/hooks/prompt-submit.mjs +12 -4
- package/dist/hooks/prompt-submit.mjs.map +1 -1
- package/dist/hooks/session-end.mjs +59 -17
- package/dist/hooks/session-end.mjs.map +1 -1
- package/dist/hooks/session-start.mjs +95 -15
- package/dist/hooks/session-start.mjs.map +1 -1
- package/dist/hooks/stop.mjs +75 -72
- package/dist/hooks/stop.mjs.map +1 -1
- package/dist/hooks/subagent-start.mjs +13 -5
- package/dist/hooks/subagent-start.mjs.map +1 -1
- package/dist/hooks/subagent-stop.mjs +32 -10
- package/dist/hooks/subagent-stop.mjs.map +1 -1
- package/dist/hooks/task-completed.mjs +21 -6
- package/dist/hooks/task-completed.mjs.map +1 -1
- package/dist/{image-refs-T_urbwHM.mjs → image-refs-Cyta4Lf9.mjs} +2 -2
- package/dist/{image-refs-T_urbwHM.mjs.map → image-refs-Cyta4Lf9.mjs.map} +1 -1
- package/dist/index.mjs +16390 -11530
- package/dist/index.mjs.map +1 -1
- package/dist/integrations/dsh.d.mts +55 -0
- package/dist/integrations/dsh.d.mts.map +1 -0
- package/dist/integrations/dsh.mjs +1172 -0
- package/dist/integrations/dsh.mjs.map +1 -0
- package/dist/{keyed-mutex-DchXsyfP.mjs → keyed-mutex-DCUh7PG-.mjs} +58 -9
- package/dist/keyed-mutex-DCUh7PG-.mjs.map +1 -0
- package/dist/{secret-store-BnY3A50C.mjs → secret-store-iYXRcrO8.mjs} +717 -474
- package/dist/secret-store-iYXRcrO8.mjs.map +1 -0
- package/dist/session-arguments-zxsbbd8y.mjs +113 -0
- package/dist/session-arguments-zxsbbd8y.mjs.map +1 -0
- package/dist/{src-Jsq9LCeH.mjs → src-C23nMpda.mjs} +5263 -4667
- package/dist/src-C23nMpda.mjs.map +1 -0
- package/dist/{standalone-DKCdrf1d.mjs → standalone-BYo5USDb.mjs} +379 -63
- package/dist/standalone-BYo5USDb.mjs.map +1 -0
- package/dist/standalone.d.mts +1 -1
- package/dist/standalone.d.mts.map +1 -1
- package/dist/standalone.mjs +864 -81
- package/dist/standalone.mjs.map +1 -1
- package/dist/viewer/index.html +337 -168
- package/integrations/hermes/README.md +94 -0
- package/integrations/hermes/__init__.py +670 -0
- package/integrations/hermes/plugin.yaml +27 -0
- package/integrations/omp/LICENSE +190 -0
- package/integrations/omp/README.md +76 -0
- package/integrations/omp/capture.ts +1 -0
- package/integrations/omp/dist/index.mjs +1477 -0
- package/integrations/omp/index.ts +488 -0
- package/integrations/omp/package.json +13 -0
- package/integrations/omp/security.ts +67 -0
- package/integrations/omp/skills/agentmemory-agents/REFERENCE.md +32 -0
- package/integrations/omp/skills/agentmemory-agents/SKILL.md +48 -0
- package/integrations/omp/skills/agentmemory-agents/TROUBLESHOOTING.md +70 -0
- package/integrations/omp/skills/agentmemory-architecture/SKILL.md +37 -0
- package/integrations/omp/skills/agentmemory-architecture/TROUBLESHOOTING.md +70 -0
- package/integrations/omp/skills/agentmemory-config/REFERENCE.md +91 -0
- package/integrations/omp/skills/agentmemory-config/SKILL.md +98 -0
- package/integrations/omp/skills/agentmemory-config/TROUBLESHOOTING.md +70 -0
- package/integrations/omp/skills/agentmemory-hooks/REFERENCE.md +20 -0
- package/integrations/omp/skills/agentmemory-hooks/SKILL.md +60 -0
- package/integrations/omp/skills/agentmemory-hooks/TROUBLESHOOTING.md +70 -0
- package/integrations/omp/skills/agentmemory-mcp-tools/REFERENCE.md +66 -0
- package/integrations/omp/skills/agentmemory-mcp-tools/SKILL.md +52 -0
- package/integrations/omp/skills/agentmemory-mcp-tools/TROUBLESHOOTING.md +70 -0
- package/integrations/omp/skills/agentmemory-rest-api/REFERENCE.md +159 -0
- package/integrations/omp/skills/agentmemory-rest-api/SKILL.md +49 -0
- package/integrations/omp/skills/agentmemory-rest-api/TROUBLESHOOTING.md +70 -0
- package/integrations/omp/skills/commit-context/EXAMPLES.md +71 -0
- package/integrations/omp/skills/commit-context/SKILL.md +64 -0
- package/integrations/omp/skills/commit-context/TROUBLESHOOTING.md +70 -0
- package/integrations/omp/skills/commit-history/EXAMPLES.md +71 -0
- package/integrations/omp/skills/commit-history/SKILL.md +62 -0
- package/integrations/omp/skills/commit-history/TROUBLESHOOTING.md +70 -0
- package/integrations/omp/skills/forget/EXAMPLES.md +40 -0
- package/integrations/omp/skills/forget/SKILL.md +73 -0
- package/integrations/omp/skills/forget/TROUBLESHOOTING.md +70 -0
- package/integrations/omp/skills/handoff/EXAMPLES.md +57 -0
- package/integrations/omp/skills/handoff/SKILL.md +75 -0
- package/integrations/omp/skills/handoff/TROUBLESHOOTING.md +70 -0
- package/integrations/omp/skills/lesson/SKILL.md +64 -0
- package/integrations/omp/skills/lesson/TROUBLESHOOTING.md +70 -0
- package/integrations/omp/skills/memory-discipline/SKILL.md +65 -0
- package/integrations/omp/skills/memory-discipline/TROUBLESHOOTING.md +70 -0
- package/integrations/omp/skills/recall/EXAMPLES.md +74 -0
- package/integrations/omp/skills/recall/SKILL.md +74 -0
- package/integrations/omp/skills/recall/TROUBLESHOOTING.md +70 -0
- package/integrations/omp/skills/recap/EXAMPLES.md +62 -0
- package/integrations/omp/skills/recap/SKILL.md +68 -0
- package/integrations/omp/skills/recap/TROUBLESHOOTING.md +70 -0
- package/integrations/omp/skills/remember/EXAMPLES.md +67 -0
- package/integrations/omp/skills/remember/SKILL.md +66 -0
- package/integrations/omp/skills/remember/TROUBLESHOOTING.md +70 -0
- package/integrations/omp/skills/session-history/EXAMPLES.md +59 -0
- package/integrations/omp/skills/session-history/SKILL.md +67 -0
- package/integrations/omp/skills/session-history/TROUBLESHOOTING.md +70 -0
- package/integrations/omp/skills/write-agentmemory-skill/SKILL.md +41 -0
- package/integrations/omp/skills/write-agentmemory-skill/TROUBLESHOOTING.md +70 -0
- package/integrations/openclaw/LICENSE +190 -0
- package/integrations/openclaw/README.md +98 -0
- package/integrations/openclaw/openclaw.plugin.json +71 -0
- package/integrations/openclaw/package.json +38 -0
- package/integrations/openclaw/plugin.mjs +425 -0
- package/integrations/openclaw/plugin.yaml +26 -0
- package/integrations/openclaw/skills/agentmemory-agents/REFERENCE.md +32 -0
- package/integrations/openclaw/skills/agentmemory-agents/SKILL.md +48 -0
- package/integrations/openclaw/skills/agentmemory-agents/TROUBLESHOOTING.md +70 -0
- package/integrations/openclaw/skills/agentmemory-architecture/SKILL.md +37 -0
- package/integrations/openclaw/skills/agentmemory-architecture/TROUBLESHOOTING.md +70 -0
- package/integrations/openclaw/skills/agentmemory-config/REFERENCE.md +91 -0
- package/integrations/openclaw/skills/agentmemory-config/SKILL.md +98 -0
- package/integrations/openclaw/skills/agentmemory-config/TROUBLESHOOTING.md +70 -0
- package/integrations/openclaw/skills/agentmemory-hooks/REFERENCE.md +20 -0
- package/integrations/openclaw/skills/agentmemory-hooks/SKILL.md +60 -0
- package/integrations/openclaw/skills/agentmemory-hooks/TROUBLESHOOTING.md +70 -0
- package/integrations/openclaw/skills/agentmemory-mcp-tools/REFERENCE.md +66 -0
- package/integrations/openclaw/skills/agentmemory-mcp-tools/SKILL.md +52 -0
- package/integrations/openclaw/skills/agentmemory-mcp-tools/TROUBLESHOOTING.md +70 -0
- package/integrations/openclaw/skills/agentmemory-rest-api/REFERENCE.md +159 -0
- package/integrations/openclaw/skills/agentmemory-rest-api/SKILL.md +49 -0
- package/integrations/openclaw/skills/agentmemory-rest-api/TROUBLESHOOTING.md +70 -0
- package/integrations/openclaw/skills/commit-context/EXAMPLES.md +71 -0
- package/integrations/openclaw/skills/commit-context/SKILL.md +64 -0
- package/integrations/openclaw/skills/commit-context/TROUBLESHOOTING.md +70 -0
- package/integrations/openclaw/skills/commit-history/EXAMPLES.md +71 -0
- package/integrations/openclaw/skills/commit-history/SKILL.md +62 -0
- package/integrations/openclaw/skills/commit-history/TROUBLESHOOTING.md +70 -0
- package/integrations/openclaw/skills/forget/EXAMPLES.md +40 -0
- package/integrations/openclaw/skills/forget/SKILL.md +73 -0
- package/integrations/openclaw/skills/forget/TROUBLESHOOTING.md +70 -0
- package/integrations/openclaw/skills/handoff/EXAMPLES.md +57 -0
- package/integrations/openclaw/skills/handoff/SKILL.md +75 -0
- package/integrations/openclaw/skills/handoff/TROUBLESHOOTING.md +70 -0
- package/integrations/openclaw/skills/lesson/SKILL.md +64 -0
- package/integrations/openclaw/skills/lesson/TROUBLESHOOTING.md +70 -0
- package/integrations/openclaw/skills/memory-discipline/SKILL.md +65 -0
- package/integrations/openclaw/skills/memory-discipline/TROUBLESHOOTING.md +70 -0
- package/integrations/openclaw/skills/recall/EXAMPLES.md +74 -0
- package/integrations/openclaw/skills/recall/SKILL.md +74 -0
- package/integrations/openclaw/skills/recall/TROUBLESHOOTING.md +70 -0
- package/integrations/openclaw/skills/recap/EXAMPLES.md +62 -0
- package/integrations/openclaw/skills/recap/SKILL.md +68 -0
- package/integrations/openclaw/skills/recap/TROUBLESHOOTING.md +70 -0
- package/integrations/openclaw/skills/remember/EXAMPLES.md +67 -0
- package/integrations/openclaw/skills/remember/SKILL.md +66 -0
- package/integrations/openclaw/skills/remember/TROUBLESHOOTING.md +70 -0
- package/integrations/openclaw/skills/session-history/EXAMPLES.md +59 -0
- package/integrations/openclaw/skills/session-history/SKILL.md +67 -0
- package/integrations/openclaw/skills/session-history/TROUBLESHOOTING.md +70 -0
- package/integrations/openclaw/skills/write-agentmemory-skill/SKILL.md +41 -0
- package/integrations/openclaw/skills/write-agentmemory-skill/TROUBLESHOOTING.md +70 -0
- package/integrations/pi/LICENSE +190 -0
- package/integrations/pi/README.md +46 -51
- package/integrations/pi/dist/index.mjs +1460 -0
- package/integrations/pi/index.ts +192 -175
- package/integrations/pi/package.json +17 -7
- package/integrations/pi/security.ts +6 -26
- package/integrations/pi/skills/agentmemory-agents/REFERENCE.md +32 -0
- package/integrations/pi/skills/agentmemory-agents/SKILL.md +48 -0
- package/integrations/pi/skills/agentmemory-agents/TROUBLESHOOTING.md +70 -0
- package/integrations/pi/skills/agentmemory-architecture/SKILL.md +37 -0
- package/integrations/pi/skills/agentmemory-architecture/TROUBLESHOOTING.md +70 -0
- package/integrations/pi/skills/agentmemory-config/REFERENCE.md +91 -0
- package/integrations/pi/skills/agentmemory-config/SKILL.md +98 -0
- package/integrations/pi/skills/agentmemory-config/TROUBLESHOOTING.md +70 -0
- package/integrations/pi/skills/agentmemory-hooks/REFERENCE.md +20 -0
- package/integrations/pi/skills/agentmemory-hooks/SKILL.md +60 -0
- package/integrations/pi/skills/agentmemory-hooks/TROUBLESHOOTING.md +70 -0
- package/integrations/pi/skills/agentmemory-mcp-tools/REFERENCE.md +66 -0
- package/integrations/pi/skills/agentmemory-mcp-tools/SKILL.md +52 -0
- package/integrations/pi/skills/agentmemory-mcp-tools/TROUBLESHOOTING.md +70 -0
- package/integrations/pi/skills/agentmemory-rest-api/REFERENCE.md +159 -0
- package/integrations/pi/skills/agentmemory-rest-api/SKILL.md +49 -0
- package/integrations/pi/skills/agentmemory-rest-api/TROUBLESHOOTING.md +70 -0
- package/integrations/pi/skills/commit-context/EXAMPLES.md +71 -0
- package/integrations/pi/skills/commit-context/SKILL.md +64 -0
- package/integrations/pi/skills/commit-context/TROUBLESHOOTING.md +70 -0
- package/integrations/pi/skills/commit-history/EXAMPLES.md +71 -0
- package/integrations/pi/skills/commit-history/SKILL.md +62 -0
- package/integrations/pi/skills/commit-history/TROUBLESHOOTING.md +70 -0
- package/integrations/pi/skills/forget/EXAMPLES.md +40 -0
- package/integrations/pi/skills/forget/SKILL.md +73 -0
- package/integrations/pi/skills/forget/TROUBLESHOOTING.md +70 -0
- package/integrations/pi/skills/handoff/EXAMPLES.md +57 -0
- package/integrations/pi/skills/handoff/SKILL.md +75 -0
- package/integrations/pi/skills/handoff/TROUBLESHOOTING.md +70 -0
- package/integrations/pi/skills/lesson/SKILL.md +64 -0
- package/integrations/pi/skills/lesson/TROUBLESHOOTING.md +70 -0
- package/integrations/pi/skills/memory-discipline/SKILL.md +65 -0
- package/integrations/pi/skills/memory-discipline/TROUBLESHOOTING.md +70 -0
- package/integrations/pi/skills/recall/EXAMPLES.md +74 -0
- package/integrations/pi/skills/recall/SKILL.md +74 -0
- package/integrations/pi/skills/recall/TROUBLESHOOTING.md +70 -0
- package/integrations/pi/skills/recap/EXAMPLES.md +62 -0
- package/integrations/pi/skills/recap/SKILL.md +68 -0
- package/integrations/pi/skills/recap/TROUBLESHOOTING.md +70 -0
- package/integrations/pi/skills/remember/EXAMPLES.md +67 -0
- package/integrations/pi/skills/remember/SKILL.md +66 -0
- package/integrations/pi/skills/remember/TROUBLESHOOTING.md +70 -0
- package/integrations/pi/skills/session-history/EXAMPLES.md +59 -0
- package/integrations/pi/skills/session-history/SKILL.md +67 -0
- package/integrations/pi/skills/session-history/TROUBLESHOOTING.md +70 -0
- package/integrations/pi/skills/write-agentmemory-skill/SKILL.md +41 -0
- package/integrations/pi/skills/write-agentmemory-skill/TROUBLESHOOTING.md +70 -0
- package/package.json +33 -11
- package/plugin/.claude-plugin/plugin.json +16 -3
- package/plugin/.codex-plugin/plugin.json +4 -3
- package/plugin/.devin-plugin/plugin.json +6 -5
- package/plugin/.mcp.json +5 -1
- package/plugin/README.md +71 -0
- package/plugin/cursor/hooks.json +23 -8
- package/plugin/hooks/hooks.json +24 -12
- package/plugin/hooks.json +67 -0
- package/plugin/opencode/README.md +1 -1
- package/plugin/opencode/agentmemory-capture.ts +25 -11
- package/plugin/opencode/plugin.json +1 -1
- package/plugin/plugin.json +1 -1
- package/plugin/scripts/_capture.d.mts +5 -1
- package/plugin/scripts/_capture.d.mts.map +1 -1
- package/plugin/scripts/_capture.mjs +141 -26
- package/plugin/scripts/_capture.mjs.map +1 -1
- package/plugin/scripts/cursor/run-detached.mjs +786 -0
- package/plugin/scripts/cursor/run-detached.mjs.map +1 -0
- package/plugin/scripts/cursor/run-hook.d.mts +1 -0
- package/plugin/scripts/cursor/run-hook.mjs +704 -0
- package/plugin/scripts/cursor/run-hook.mjs.map +1 -0
- package/plugin/scripts/notification.mjs +20 -6
- package/plugin/scripts/notification.mjs.map +1 -1
- package/plugin/scripts/plugin-bridge.mjs +61 -11
- package/plugin/scripts/post-tool-failure.mjs +19 -6
- package/plugin/scripts/post-tool-failure.mjs.map +1 -1
- package/plugin/scripts/post-tool-use.mjs +19 -6
- package/plugin/scripts/post-tool-use.mjs.map +1 -1
- package/plugin/scripts/pre-compact.mjs +104 -22
- package/plugin/scripts/pre-compact.mjs.map +1 -1
- package/plugin/scripts/pre-tool-use.mjs +83 -10
- package/plugin/scripts/pre-tool-use.mjs.map +1 -1
- package/plugin/scripts/prompt-submit.mjs +12 -4
- package/plugin/scripts/prompt-submit.mjs.map +1 -1
- package/plugin/scripts/session-end.mjs +59 -17
- package/plugin/scripts/session-end.mjs.map +1 -1
- package/plugin/scripts/session-start.mjs +95 -15
- package/plugin/scripts/session-start.mjs.map +1 -1
- package/plugin/scripts/stop.mjs +75 -72
- package/plugin/scripts/stop.mjs.map +1 -1
- package/plugin/scripts/subagent-start.mjs +13 -5
- package/plugin/scripts/subagent-start.mjs.map +1 -1
- package/plugin/scripts/subagent-stop.mjs +32 -10
- package/plugin/scripts/subagent-stop.mjs.map +1 -1
- package/plugin/scripts/task-completed.mjs +21 -6
- package/plugin/scripts/task-completed.mjs.map +1 -1
- package/plugin/skills/_shared/TROUBLESHOOTING.md +21 -7
- package/plugin/skills/agentmemory-agents/REFERENCE.md +8 -7
- package/plugin/skills/agentmemory-agents/SKILL.md +19 -5
- package/plugin/skills/agentmemory-agents/TROUBLESHOOTING.md +70 -0
- package/plugin/skills/agentmemory-architecture/SKILL.md +8 -4
- package/plugin/skills/agentmemory-architecture/TROUBLESHOOTING.md +70 -0
- package/plugin/skills/agentmemory-config/REFERENCE.md +13 -15
- package/plugin/skills/agentmemory-config/SKILL.md +34 -10
- package/plugin/skills/agentmemory-config/TROUBLESHOOTING.md +70 -0
- package/plugin/skills/agentmemory-hooks/SKILL.md +31 -10
- package/plugin/skills/agentmemory-hooks/TROUBLESHOOTING.md +70 -0
- package/plugin/skills/agentmemory-mcp-tools/REFERENCE.md +5 -5
- package/plugin/skills/agentmemory-mcp-tools/SKILL.md +16 -3
- package/plugin/skills/agentmemory-mcp-tools/TROUBLESHOOTING.md +70 -0
- package/plugin/skills/agentmemory-rest-api/REFERENCE.md +10 -1
- package/plugin/skills/agentmemory-rest-api/SKILL.md +12 -6
- package/plugin/skills/agentmemory-rest-api/TROUBLESHOOTING.md +70 -0
- package/plugin/skills/commit-context/SKILL.md +1 -1
- package/plugin/skills/commit-context/TROUBLESHOOTING.md +70 -0
- package/plugin/skills/commit-history/SKILL.md +1 -1
- package/plugin/skills/commit-history/TROUBLESHOOTING.md +70 -0
- package/plugin/skills/forget/EXAMPLES.md +19 -54
- package/plugin/skills/forget/SKILL.md +16 -12
- package/plugin/skills/forget/TROUBLESHOOTING.md +70 -0
- package/plugin/skills/handoff/EXAMPLES.md +5 -4
- package/plugin/skills/handoff/SKILL.md +10 -5
- package/plugin/skills/handoff/TROUBLESHOOTING.md +70 -0
- package/plugin/skills/lesson/SKILL.md +1 -1
- package/plugin/skills/lesson/TROUBLESHOOTING.md +70 -0
- package/plugin/skills/memory-discipline/SKILL.md +1 -1
- package/plugin/skills/memory-discipline/TROUBLESHOOTING.md +70 -0
- package/plugin/skills/recall/SKILL.md +18 -7
- package/plugin/skills/recall/TROUBLESHOOTING.md +70 -0
- package/plugin/skills/recap/EXAMPLES.md +5 -3
- package/plugin/skills/recap/SKILL.md +11 -6
- package/plugin/skills/recap/TROUBLESHOOTING.md +70 -0
- package/plugin/skills/remember/EXAMPLES.md +3 -3
- package/plugin/skills/remember/SKILL.md +1 -1
- package/plugin/skills/remember/TROUBLESHOOTING.md +70 -0
- package/plugin/skills/session-history/EXAMPLES.md +2 -2
- package/plugin/skills/session-history/SKILL.md +10 -4
- package/plugin/skills/session-history/TROUBLESHOOTING.md +70 -0
- package/plugin/skills/write-agentmemory-skill/SKILL.md +2 -1
- package/plugin/skills/write-agentmemory-skill/TROUBLESHOOTING.md +70 -0
- package/dist/connect-B4_ca6BD.mjs.map +0 -1
- package/dist/docker-compose.yml +0 -73
- package/dist/iii-config.docker.yaml +0 -53
- package/dist/iii-config.yaml +0 -63
- package/dist/keyed-mutex-DchXsyfP.mjs.map +0 -1
- package/dist/secret-store-BnY3A50C.mjs.map +0 -1
- package/dist/src-Jsq9LCeH.mjs.map +0 -1
- package/dist/standalone-DKCdrf1d.mjs.map +0 -1
- package/dist/status-IRz7ta8-.mjs +0 -2344
- package/dist/status-IRz7ta8-.mjs.map +0 -1
- package/docker-compose.yml +0 -73
- package/iii-config.docker.yaml +0 -53
- package/iii-config.yaml +0 -63
- package/plugin/scripts/post-commit.mjs +0 -184
- package/plugin/scripts/post-commit.mjs.map +0 -1
- /package/plugin/scripts/{post-commit.d.mts → cursor/run-detached.d.mts} +0 -0
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { s as generateId } from "./keyed-mutex-DCUh7PG-.mjs";
|
|
2
|
+
import { $ as getStandalonePersistPath, C as getAllTools, E as VERSION, H as getAgentId, P as redactCredentialUrls, at as isAgentScopeIsolated, c as memoryToObservation, f as isSearchLayer, g as queryAudit, i as resolveClientSecret, o as buildRecallResponse } from "./secret-store-iYXRcrO8.mjs";
|
|
3
|
+
import { a as pageAfterCursor, c as sortByKeyDesc, n as parseSearchExpansionIds, t as parseSessionArguments } from "./session-arguments-zxsbbd8y.mjs";
|
|
4
|
+
import { chmodSync, closeSync, existsSync, fchmodSync, mkdirSync, openSync, readFileSync, renameSync, rmSync, statSync, writeFileSync, writeSync } from "node:fs";
|
|
5
|
+
import { dirname, join } from "node:path";
|
|
6
|
+
import { homedir, tmpdir } from "node:os";
|
|
5
7
|
//#region src/mcp/in-memory-kv.ts
|
|
6
8
|
var InMemoryKV = class {
|
|
7
9
|
store = /* @__PURE__ */ new Map();
|
|
@@ -32,20 +34,35 @@ var InMemoryKV = class {
|
|
|
32
34
|
return entries ? Array.from(entries.values()) : [];
|
|
33
35
|
}
|
|
34
36
|
persist() {
|
|
35
|
-
if (!this.persistPath) return;
|
|
37
|
+
if (!this.persistPath) return false;
|
|
36
38
|
try {
|
|
37
39
|
const dir = dirname(this.persistPath);
|
|
38
40
|
if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
|
|
39
41
|
const data = {};
|
|
40
42
|
for (const [scope, entries] of this.store) data[scope] = Object.fromEntries(entries);
|
|
41
|
-
|
|
43
|
+
const tmpPath = `${this.persistPath}.${process.pid}.tmp`;
|
|
44
|
+
try {
|
|
45
|
+
writeFileSync(tmpPath, JSON.stringify(data), {
|
|
46
|
+
encoding: "utf-8",
|
|
47
|
+
mode: 384
|
|
48
|
+
});
|
|
49
|
+
renameSync(tmpPath, this.persistPath);
|
|
50
|
+
} catch (err) {
|
|
51
|
+
try {
|
|
52
|
+
rmSync(tmpPath, { force: true });
|
|
53
|
+
} catch {}
|
|
54
|
+
throw err;
|
|
55
|
+
}
|
|
56
|
+
return true;
|
|
42
57
|
} catch (err) {
|
|
43
58
|
process.stderr.write(`[@agentmemory/mcp] Persist failed: ${err instanceof Error ? err.message : String(err)}\n`);
|
|
59
|
+
return false;
|
|
44
60
|
}
|
|
45
61
|
}
|
|
46
62
|
};
|
|
47
63
|
//#endregion
|
|
48
64
|
//#region src/mcp/transport.ts
|
|
65
|
+
let activeStdioTransports = 0;
|
|
49
66
|
var JsonRpcError = class extends Error {
|
|
50
67
|
constructor(code, message) {
|
|
51
68
|
super(message);
|
|
@@ -198,6 +215,7 @@ function createMessageParser(onMessage, writeErr = (msg) => process.stderr.write
|
|
|
198
215
|
function createStdioTransport(handler) {
|
|
199
216
|
let parser = null;
|
|
200
217
|
let queue = Promise.resolve();
|
|
218
|
+
let active = false;
|
|
201
219
|
const writeResponse = (response) => {
|
|
202
220
|
const formatted = formatResponse(response, parser?.isFramed() ?? false);
|
|
203
221
|
if (typeof formatted === "string") {
|
|
@@ -209,6 +227,10 @@ function createStdioTransport(handler) {
|
|
|
209
227
|
const onData = (chunk) => parser?.push(chunk);
|
|
210
228
|
return {
|
|
211
229
|
start() {
|
|
230
|
+
if (active) return;
|
|
231
|
+
active = true;
|
|
232
|
+
activeStdioTransports += 1;
|
|
233
|
+
process.env["AGENTMEMORY_MCP_STDIO__"] = "1";
|
|
212
234
|
parser = createMessageParser((message) => {
|
|
213
235
|
queue = queue.then(() => processLine(message, handler, writeResponse));
|
|
214
236
|
queue.catch((err) => {
|
|
@@ -219,10 +241,161 @@ function createStdioTransport(handler) {
|
|
|
219
241
|
},
|
|
220
242
|
stop() {
|
|
221
243
|
process.stdin.off("data", onData);
|
|
244
|
+
if (active) {
|
|
245
|
+
active = false;
|
|
246
|
+
activeStdioTransports -= 1;
|
|
247
|
+
if (activeStdioTransports === 0) delete process.env["AGENTMEMORY_MCP_STDIO__"];
|
|
248
|
+
}
|
|
222
249
|
parser = null;
|
|
223
250
|
}
|
|
224
251
|
};
|
|
225
252
|
}
|
|
253
|
+
const MAX_CRASH_LINE_BYTES = 64 * 1024;
|
|
254
|
+
function writeStderr(text) {
|
|
255
|
+
process.stderr.write(text);
|
|
256
|
+
}
|
|
257
|
+
function stderrWriteMayBlock(platform = process.platform, isTTY = process.stderr.isTTY) {
|
|
258
|
+
return platform === "win32" && !isTTY;
|
|
259
|
+
}
|
|
260
|
+
function mcpCrashLogPath(env = process.env) {
|
|
261
|
+
return join(env["AGENTMEMORY_DATA_DIR"] || join(homedir(), ".agentmemory"), "mcp-crash.log");
|
|
262
|
+
}
|
|
263
|
+
function formatFatal(kind, reason, now = /* @__PURE__ */ new Date()) {
|
|
264
|
+
const detail = reason instanceof Error ? reason.stack || reason.message : String(reason);
|
|
265
|
+
return redactCredentialUrls(`[${now.toISOString()}] pid=${process.pid} ${kind}: ${detail}\n`);
|
|
266
|
+
}
|
|
267
|
+
function safeFormat(kind, reason) {
|
|
268
|
+
try {
|
|
269
|
+
return formatFatal(kind, reason);
|
|
270
|
+
} catch {
|
|
271
|
+
return `[${(/* @__PURE__ */ new Date()).toISOString()}] pid=${process.pid} ${kind}: (the error could not be formatted)\n`;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
function describe(err) {
|
|
275
|
+
return err instanceof Error ? err.message : String(err);
|
|
276
|
+
}
|
|
277
|
+
function rotateCrashLog(logPath, notices) {
|
|
278
|
+
const rotated = `${logPath}.1`;
|
|
279
|
+
try {
|
|
280
|
+
renameSync(logPath, rotated);
|
|
281
|
+
} catch (err) {
|
|
282
|
+
if (err.code === "ENOENT") return;
|
|
283
|
+
throw err;
|
|
284
|
+
}
|
|
285
|
+
try {
|
|
286
|
+
chmodSync(rotated, 384);
|
|
287
|
+
} catch (err) {
|
|
288
|
+
notices.push(`[@agentmemory/mcp] rotated crash log ${rotated} could not be made owner-only: ${describe(err)}\n`);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
function boundCrashLine(line, maxBytes = MAX_CRASH_LINE_BYTES) {
|
|
292
|
+
const bytes = Buffer.from(line, "utf8");
|
|
293
|
+
if (bytes.length <= maxBytes) return line;
|
|
294
|
+
const marker = " ...(truncated)\n";
|
|
295
|
+
const markerBytes = Buffer.byteLength(marker);
|
|
296
|
+
if (maxBytes <= markerBytes) return bytes.subarray(0, Math.max(0, maxBytes)).toString("utf8").replace(/�+$/, "");
|
|
297
|
+
return `${bytes.subarray(0, maxBytes - markerBytes).toString("utf8").replace(/�+$/, "")}${marker}`;
|
|
298
|
+
}
|
|
299
|
+
function writeAll(fd, data, write = writeSync) {
|
|
300
|
+
let offset = 0;
|
|
301
|
+
while (offset < data.length) {
|
|
302
|
+
const n = write(fd, data, offset, data.length - offset);
|
|
303
|
+
if (!(n > 0)) throw new Error(`crash log write stopped after ${offset} of ${data.length} bytes`);
|
|
304
|
+
offset += n;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
function writeCrashLog(line, logPath = mcpCrashLogPath()) {
|
|
308
|
+
const notices = [];
|
|
309
|
+
const bounded = boundCrashLine(line);
|
|
310
|
+
let fd;
|
|
311
|
+
try {
|
|
312
|
+
mkdirSync(dirname(logPath), {
|
|
313
|
+
recursive: true,
|
|
314
|
+
mode: 448
|
|
315
|
+
});
|
|
316
|
+
if (existsSync(logPath) && statSync(logPath).size + Buffer.byteLength(bounded) > 1048576) rotateCrashLog(logPath, notices);
|
|
317
|
+
fd = openSync(logPath, "a", 384);
|
|
318
|
+
try {
|
|
319
|
+
fchmodSync(fd, 384);
|
|
320
|
+
} catch (err) {
|
|
321
|
+
notices.push(`[@agentmemory/mcp] crash log ${logPath} could not be made owner-only, so it was not written: ${describe(err)}\n`);
|
|
322
|
+
return {
|
|
323
|
+
written: false,
|
|
324
|
+
notices
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
writeAll(fd, Buffer.from(bounded, "utf8"));
|
|
328
|
+
notices.push(`[@agentmemory/mcp] crash log: ${logPath}\n`);
|
|
329
|
+
return {
|
|
330
|
+
written: true,
|
|
331
|
+
notices
|
|
332
|
+
};
|
|
333
|
+
} catch (err) {
|
|
334
|
+
notices.push(`[@agentmemory/mcp] crash log not written to ${logPath}: ${describe(err)}\n`);
|
|
335
|
+
return {
|
|
336
|
+
written: false,
|
|
337
|
+
notices
|
|
338
|
+
};
|
|
339
|
+
} finally {
|
|
340
|
+
if (fd !== void 0) try {
|
|
341
|
+
closeSync(fd);
|
|
342
|
+
} catch {}
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
function fallbackCrashLogPath() {
|
|
346
|
+
return join(tmpdir(), "agentmemory-mcp-crash.log");
|
|
347
|
+
}
|
|
348
|
+
function handleFatal(kind, reason, hooks) {
|
|
349
|
+
const line = safeFormat(kind, reason);
|
|
350
|
+
const stderrMayBlock = hooks.stderrMayBlock ?? stderrWriteMayBlock();
|
|
351
|
+
let result = {
|
|
352
|
+
written: false,
|
|
353
|
+
notices: []
|
|
354
|
+
};
|
|
355
|
+
try {
|
|
356
|
+
result = writeCrashLog(line, hooks.logPath ?? mcpCrashLogPath());
|
|
357
|
+
} catch {}
|
|
358
|
+
const notices = result.notices;
|
|
359
|
+
if (!result.written && stderrMayBlock) try {
|
|
360
|
+
writeCrashLog(line + notices.join(""), hooks.fallbackLogPath ?? fallbackCrashLogPath());
|
|
361
|
+
} catch {}
|
|
362
|
+
try {
|
|
363
|
+
hooks.persist();
|
|
364
|
+
} catch {}
|
|
365
|
+
if (!stderrMayBlock) {
|
|
366
|
+
const write = hooks.write ?? writeStderr;
|
|
367
|
+
for (const text of [`[@agentmemory/mcp] fatal ${line}`, ...notices]) try {
|
|
368
|
+
write(text);
|
|
369
|
+
} catch {}
|
|
370
|
+
}
|
|
371
|
+
(hooks.exit ?? ((code) => process.exit(code)))(1);
|
|
372
|
+
}
|
|
373
|
+
function installCrashHandlers(hooks) {
|
|
374
|
+
process.on("uncaughtException", (err) => handleFatal("uncaughtException", err, hooks));
|
|
375
|
+
process.on("unhandledRejection", (reason) => handleFatal("unhandledRejection", reason, hooks));
|
|
376
|
+
}
|
|
377
|
+
//#endregion
|
|
378
|
+
//#region src/hooks/_endpoint.ts
|
|
379
|
+
const OPTION_PREFIX = "CLAUDE_PLUGIN_OPTION_";
|
|
380
|
+
function filled(value) {
|
|
381
|
+
const trimmed = value?.trim();
|
|
382
|
+
if (!trimmed || trimmed.startsWith("${") && trimmed.endsWith("}")) return void 0;
|
|
383
|
+
return value;
|
|
384
|
+
}
|
|
385
|
+
function hookSetting(name, env = process.env) {
|
|
386
|
+
const optionKey = `${OPTION_PREFIX}${name}`;
|
|
387
|
+
const option = filled(env[optionKey])?.trim();
|
|
388
|
+
if (option) return option;
|
|
389
|
+
if (name === "AGENTMEMORY_SECRET" && optionKey in env) return void 0;
|
|
390
|
+
return filled(env[name]);
|
|
391
|
+
}
|
|
392
|
+
function resolveSettingSecret(url, env = process.env) {
|
|
393
|
+
const secretEnv = { ...env };
|
|
394
|
+
const explicit = hookSetting("AGENTMEMORY_SECRET", env);
|
|
395
|
+
if (explicit === void 0) delete secretEnv["AGENTMEMORY_SECRET"];
|
|
396
|
+
else secretEnv["AGENTMEMORY_SECRET"] = explicit;
|
|
397
|
+
return resolveClientSecret(url, secretEnv);
|
|
398
|
+
}
|
|
226
399
|
//#endregion
|
|
227
400
|
//#region src/mcp/rest-proxy.ts
|
|
228
401
|
const DEFAULT_URL = "http://localhost:3111";
|
|
@@ -235,7 +408,7 @@ function probeTimeoutMs() {
|
|
|
235
408
|
const n = Number(raw);
|
|
236
409
|
return Number.isFinite(n) && n > 0 ? Math.floor(n) : DEFAULT_HEALTH_PROBE_TIMEOUT_MS;
|
|
237
410
|
}
|
|
238
|
-
function
|
|
411
|
+
function isProxyRequired() {
|
|
239
412
|
const raw = process.env["AGENTMEMORY_FORCE_PROXY"];
|
|
240
413
|
return raw === "1" || raw === "true";
|
|
241
414
|
}
|
|
@@ -250,26 +423,32 @@ var ProxyCallError = class extends Error {
|
|
|
250
423
|
}
|
|
251
424
|
};
|
|
252
425
|
let cached = null;
|
|
426
|
+
let cachedUrl = null;
|
|
253
427
|
let cachedAt = 0;
|
|
254
428
|
let probeInFlight = null;
|
|
255
429
|
function resolveEnvOrEmpty(name) {
|
|
256
|
-
|
|
257
|
-
if (!raw) return "";
|
|
258
|
-
if (raw.startsWith("${") && raw.endsWith("}")) return "";
|
|
259
|
-
return raw;
|
|
430
|
+
return hookSetting(name) ?? "";
|
|
260
431
|
}
|
|
261
432
|
function baseUrl() {
|
|
262
|
-
|
|
433
|
+
const value = resolveEnvOrEmpty("AGENTMEMORY_URL") || DEFAULT_URL;
|
|
434
|
+
try {
|
|
435
|
+
const parsed = new URL(value);
|
|
436
|
+
if (!["http:", "https:"].includes(parsed.protocol) || !parsed.hostname || parsed.username || parsed.password || /[?#\s]/.test(value)) throw new Error();
|
|
437
|
+
return value.replace(/\/+$/, "");
|
|
438
|
+
} catch {
|
|
439
|
+
throw new Error("AGENTMEMORY_URL must be an HTTP(S) URL without credentials, query, or fragment");
|
|
440
|
+
}
|
|
263
441
|
}
|
|
264
|
-
function authHeader() {
|
|
265
|
-
const secret =
|
|
442
|
+
function authHeader(url) {
|
|
443
|
+
const secret = resolveSettingSecret(url);
|
|
266
444
|
return secret ? { authorization: `Bearer ${secret}` } : {};
|
|
267
445
|
}
|
|
268
446
|
const defaultLivezProbe = async (url, timeoutMs, headers) => {
|
|
269
447
|
const res = await fetch(`${url}/agentmemory/livez`, {
|
|
270
448
|
method: "GET",
|
|
271
449
|
headers,
|
|
272
|
-
signal: AbortSignal.timeout(timeoutMs)
|
|
450
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
451
|
+
redirect: "error"
|
|
273
452
|
});
|
|
274
453
|
return {
|
|
275
454
|
ok: res.ok,
|
|
@@ -281,7 +460,7 @@ let livezProbe = defaultLivezProbe;
|
|
|
281
460
|
async function probe(url) {
|
|
282
461
|
const timeout = probeTimeoutMs();
|
|
283
462
|
try {
|
|
284
|
-
const res = await livezProbe(url, timeout, authHeader());
|
|
463
|
+
const res = await livezProbe(url, timeout, authHeader(url));
|
|
285
464
|
if (!res.ok) process.stderr.write(`[@agentmemory/mcp] livez probe ${url}/agentmemory/livez -> ${res.status ?? "?"} ${res.statusText ?? ""}; falling back to local InMemoryKV (set AGENTMEMORY_FORCE_PROXY=1 to skip the probe)\n`);
|
|
286
465
|
return res.ok;
|
|
287
466
|
} catch (err) {
|
|
@@ -291,33 +470,38 @@ async function probe(url) {
|
|
|
291
470
|
}
|
|
292
471
|
function invalidateHandle() {
|
|
293
472
|
cached = null;
|
|
473
|
+
cachedUrl = null;
|
|
294
474
|
cachedAt = 0;
|
|
295
475
|
}
|
|
296
476
|
async function resolveHandle() {
|
|
297
477
|
const now = Date.now();
|
|
478
|
+
const url = baseUrl();
|
|
479
|
+
if (cached && (cachedUrl !== url || cached.mode === "local" && isProxyRequired())) invalidateHandle();
|
|
298
480
|
if (cached) if (cached.mode === "local" && now - cachedAt >= LOCAL_MODE_TTL_MS) {
|
|
299
481
|
cached = null;
|
|
300
482
|
cachedAt = 0;
|
|
301
483
|
} else return cached;
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
const
|
|
305
|
-
probeInFlight = (async () => {
|
|
484
|
+
const skipProbe = isProxyRequired();
|
|
485
|
+
if (probeInFlight?.url === url && probeInFlight.forceProxy === skipProbe) return probeInFlight.promise;
|
|
486
|
+
const pending = (async () => {
|
|
306
487
|
const up = skipProbe ? true : await probe(url);
|
|
488
|
+
if (baseUrl() !== url || isProxyRequired() !== skipProbe) return resolveHandle();
|
|
307
489
|
if (skipProbe) process.stderr.write(`[@agentmemory/mcp] AGENTMEMORY_FORCE_PROXY set; skipping livez probe and trusting ${url}\n`);
|
|
308
490
|
if (up) {
|
|
309
491
|
const handle = {
|
|
310
492
|
mode: "proxy",
|
|
311
493
|
baseUrl: url,
|
|
312
494
|
call: async (path, init) => {
|
|
495
|
+
if (baseUrl() !== url) throw new Error("AgentMemory endpoint changed; resolve a new proxy handle before retrying.");
|
|
313
496
|
const res = await fetch(`${url}${path}`, {
|
|
314
497
|
...init,
|
|
315
498
|
headers: {
|
|
316
499
|
"content-type": "application/json",
|
|
317
|
-
...authHeader(),
|
|
500
|
+
...authHeader(url),
|
|
318
501
|
...init?.headers
|
|
319
502
|
},
|
|
320
|
-
signal: AbortSignal.timeout(CALL_TIMEOUT_MS)
|
|
503
|
+
signal: AbortSignal.timeout(CALL_TIMEOUT_MS),
|
|
504
|
+
redirect: "error"
|
|
321
505
|
});
|
|
322
506
|
if (!res.ok) {
|
|
323
507
|
const errText = await res.text().catch(() => "");
|
|
@@ -334,18 +518,25 @@ async function resolveHandle() {
|
|
|
334
518
|
}
|
|
335
519
|
};
|
|
336
520
|
cached = handle;
|
|
521
|
+
cachedUrl = url;
|
|
337
522
|
cachedAt = Date.now();
|
|
338
523
|
return handle;
|
|
339
524
|
}
|
|
340
525
|
const local = { mode: "local" };
|
|
341
526
|
cached = local;
|
|
527
|
+
cachedUrl = url;
|
|
342
528
|
cachedAt = Date.now();
|
|
343
529
|
return local;
|
|
344
530
|
})();
|
|
531
|
+
probeInFlight = {
|
|
532
|
+
url,
|
|
533
|
+
forceProxy: skipProbe,
|
|
534
|
+
promise: pending
|
|
535
|
+
};
|
|
345
536
|
try {
|
|
346
|
-
return await
|
|
537
|
+
return await pending;
|
|
347
538
|
} finally {
|
|
348
|
-
probeInFlight = null;
|
|
539
|
+
if (probeInFlight?.promise === pending) probeInFlight = null;
|
|
349
540
|
}
|
|
350
541
|
}
|
|
351
542
|
//#endregion
|
|
@@ -405,6 +596,9 @@ function textResponse(payload, pretty = false) {
|
|
|
405
596
|
text: JSON.stringify(payload, null, pretty ? 2 : 0)
|
|
406
597
|
}] };
|
|
407
598
|
}
|
|
599
|
+
function isAuthenticationError(error) {
|
|
600
|
+
return error instanceof ProxyCallError && (error.status === 401 || error.status === 403);
|
|
601
|
+
}
|
|
408
602
|
function validate(toolName, args) {
|
|
409
603
|
if (!IMPLEMENTED_TOOLS.has(toolName)) throw new Error(`Unknown tool: ${toolName}`);
|
|
410
604
|
const v = { tool: toolName };
|
|
@@ -422,22 +616,41 @@ function validate(toolName, args) {
|
|
|
422
616
|
}
|
|
423
617
|
case "memory_recall":
|
|
424
618
|
case "memory_smart_search": {
|
|
619
|
+
if (args.targetLayer !== void 0 && !isSearchLayer(args.targetLayer)) throw new Error("targetLayer must be one of: all, memory, observation");
|
|
620
|
+
v.targetLayer = args.targetLayer ?? "all";
|
|
621
|
+
for (const field of [
|
|
622
|
+
"project",
|
|
623
|
+
"cwd",
|
|
624
|
+
"agentId",
|
|
625
|
+
"sessionId",
|
|
626
|
+
"source"
|
|
627
|
+
]) {
|
|
628
|
+
if (args[field] !== void 0 && typeof args[field] !== "string") throw new Error(`${field} must be a string`);
|
|
629
|
+
if (typeof args[field] === "string" && args[field].trim()) v[field] = args[field].trim();
|
|
630
|
+
}
|
|
631
|
+
if (toolName === "memory_smart_search") {
|
|
632
|
+
v.expandIds = parseSearchExpansionIds(args.expandIds);
|
|
633
|
+
if (typeof args.includeLessons === "boolean") v.includeLessons = args.includeLessons;
|
|
634
|
+
}
|
|
425
635
|
const query = args["query"];
|
|
426
|
-
if (typeof query !== "string" || !query.trim())
|
|
427
|
-
|
|
636
|
+
if (typeof query !== "string" || !query.trim()) {
|
|
637
|
+
if (!v.expandIds?.length) throw new Error("query is required unless expandIds is provided");
|
|
638
|
+
} else v.query = query.trim();
|
|
428
639
|
v.limit = parseLimit(args["limit"]);
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
640
|
+
if (toolName === "memory_recall") {
|
|
641
|
+
const format = typeof args.format === "string" ? args.format.trim().toLowerCase() : args.format ?? "full";
|
|
642
|
+
if (format !== "full" && format !== "compact" && format !== "narrative") throw new Error("format must be one of: full, compact, narrative");
|
|
643
|
+
v.format = format;
|
|
644
|
+
if (args.token_budget !== void 0) {
|
|
645
|
+
const budget = typeof args.token_budget === "string" ? Number(args.token_budget) : args.token_budget;
|
|
646
|
+
if (typeof budget !== "number" || !Number.isInteger(budget) || budget < 1) throw new Error("token_budget must be a positive integer");
|
|
647
|
+
v.tokenBudget = budget;
|
|
648
|
+
}
|
|
436
649
|
}
|
|
437
650
|
return v;
|
|
438
651
|
}
|
|
439
652
|
case "memory_sessions":
|
|
440
|
-
v.
|
|
653
|
+
v.sessionQuery = parseSessionArguments(args);
|
|
441
654
|
return v;
|
|
442
655
|
case "memory_governance_delete": {
|
|
443
656
|
const ids = normalizeList(args["memoryIds"]);
|
|
@@ -446,7 +659,22 @@ function validate(toolName, args) {
|
|
|
446
659
|
v.reason = args["reason"] || "plugin skill request";
|
|
447
660
|
return v;
|
|
448
661
|
}
|
|
449
|
-
case "memory_export":
|
|
662
|
+
case "memory_export": {
|
|
663
|
+
const query = new URLSearchParams();
|
|
664
|
+
for (const key of [
|
|
665
|
+
"maxSessions",
|
|
666
|
+
"offset",
|
|
667
|
+
"collectionLimit",
|
|
668
|
+
"collectionOffset"
|
|
669
|
+
]) {
|
|
670
|
+
const n = Number(args[key]);
|
|
671
|
+
const min = key === "maxSessions" || key === "collectionLimit" ? 1 : 0;
|
|
672
|
+
if (args[key] !== void 0 && Number.isInteger(n) && n >= min) query.set(key, String(n));
|
|
673
|
+
}
|
|
674
|
+
if (typeof args["collections"] === "string") query.set("collections", args["collections"]);
|
|
675
|
+
v.exportQuery = query.toString();
|
|
676
|
+
return v;
|
|
677
|
+
}
|
|
450
678
|
case "memory_audit":
|
|
451
679
|
v.limit = parseLimit(args["limit"], 50);
|
|
452
680
|
return v;
|
|
@@ -470,7 +698,11 @@ async function handleProxy(v, handle) {
|
|
|
470
698
|
const body = {
|
|
471
699
|
query: v.query,
|
|
472
700
|
limit: v.limit,
|
|
473
|
-
format: v.format ?? "full"
|
|
701
|
+
format: v.format ?? "full",
|
|
702
|
+
targetLayer: v.targetLayer,
|
|
703
|
+
project: v.project,
|
|
704
|
+
cwd: v.cwd,
|
|
705
|
+
agentId: v.agentId
|
|
474
706
|
};
|
|
475
707
|
if (v.tokenBudget != null) body["token_budget"] = v.tokenBudget;
|
|
476
708
|
return textResponse(await handle.call("/agentmemory/search", {
|
|
@@ -481,16 +713,21 @@ async function handleProxy(v, handle) {
|
|
|
481
713
|
case "memory_smart_search": {
|
|
482
714
|
const body = {
|
|
483
715
|
query: v.query,
|
|
484
|
-
limit: v.limit
|
|
716
|
+
limit: v.limit,
|
|
717
|
+
targetLayer: v.targetLayer,
|
|
718
|
+
project: v.project,
|
|
719
|
+
agentId: v.agentId,
|
|
720
|
+
expandIds: v.expandIds,
|
|
721
|
+
sessionId: v.sessionId,
|
|
722
|
+
source: v.source,
|
|
723
|
+
includeLessons: v.includeLessons
|
|
485
724
|
};
|
|
486
|
-
if (v.format != null) body["format"] = v.format;
|
|
487
|
-
if (v.tokenBudget != null) body["token_budget"] = v.tokenBudget;
|
|
488
725
|
return textResponse(await handle.call("/agentmemory/smart-search", {
|
|
489
726
|
method: "POST",
|
|
490
727
|
body: JSON.stringify(body)
|
|
491
728
|
}), true);
|
|
492
729
|
}
|
|
493
|
-
case "memory_sessions": return textResponse(await handle.call(`/agentmemory/sessions
|
|
730
|
+
case "memory_sessions": return textResponse(await handle.call(`/agentmemory/sessions?${new URLSearchParams(v.sessionQuery)}`, { method: "GET" }), true);
|
|
494
731
|
case "memory_governance_delete": return textResponse(await handle.call("/agentmemory/governance/memories", {
|
|
495
732
|
method: "DELETE",
|
|
496
733
|
body: JSON.stringify({
|
|
@@ -499,15 +736,22 @@ async function handleProxy(v, handle) {
|
|
|
499
736
|
})
|
|
500
737
|
}));
|
|
501
738
|
case "memory_export": try {
|
|
502
|
-
return textResponse(await handle.call(
|
|
739
|
+
return textResponse(await handle.call(`/agentmemory/export${v.exportQuery ? `?${v.exportQuery}` : ""}`, { method: "GET" }), true);
|
|
503
740
|
} catch (err) {
|
|
504
|
-
if (err instanceof ProxyCallError && err.body != null && typeof err.body === "object" && err.body.oversized === true) return textResponse(err.body, true);
|
|
741
|
+
if (err instanceof ProxyCallError && err.status === 413 && err.body != null && typeof err.body === "object" && err.body.oversized === true) return textResponse(err.body, true);
|
|
505
742
|
throw err;
|
|
506
743
|
}
|
|
507
744
|
case "memory_audit": return textResponse(await handle.call(`/agentmemory/audit?limit=${v.limit}`, { method: "GET" }), true);
|
|
508
745
|
default: throw new Error(`Unknown tool: ${v.tool}`);
|
|
509
746
|
}
|
|
510
747
|
}
|
|
748
|
+
function localFallbackNotice(persisted) {
|
|
749
|
+
const store = persisted ? "the local fallback file, which the server does not read" : "this process's in-memory fallback store, which is lost when the process exits";
|
|
750
|
+
return {
|
|
751
|
+
storage: "local",
|
|
752
|
+
warning: `agentmemory server at ${displayAgentmemoryUrl()} did not confirm this call, so it ran against ${store}.`
|
|
753
|
+
};
|
|
754
|
+
}
|
|
511
755
|
async function handleLocal(v, kvInstance) {
|
|
512
756
|
switch (v.tool) {
|
|
513
757
|
case "memory_save": {
|
|
@@ -525,34 +769,98 @@ async function handleLocal(v, kvInstance) {
|
|
|
525
769
|
strength: 7,
|
|
526
770
|
version: 1,
|
|
527
771
|
isLatest: true,
|
|
528
|
-
sessionIds: []
|
|
772
|
+
sessionIds: [],
|
|
773
|
+
...v.project !== void 0 && { project: v.project },
|
|
774
|
+
...(v.agentId ?? getAgentId()) !== void 0 && { agentId: v.agentId ?? getAgentId() }
|
|
775
|
+
});
|
|
776
|
+
return textResponse({
|
|
777
|
+
saved: id,
|
|
778
|
+
...localFallbackNotice(kvInstance.persist())
|
|
529
779
|
});
|
|
530
|
-
kvInstance.persist();
|
|
531
|
-
return textResponse({ saved: id });
|
|
532
780
|
}
|
|
533
781
|
case "memory_recall":
|
|
534
782
|
case "memory_smart_search": {
|
|
783
|
+
const isolated = isAgentScopeIsolated();
|
|
784
|
+
const agentId = v.agentId === "*" ? void 0 : v.agentId ?? (isolated ? getAgentId() : void 0);
|
|
785
|
+
if (isolated && v.agentId !== "*" && !agentId) throw new Error("AGENTMEMORY_AGENT_SCOPE=isolated requires an agentId; pass '*' to read across agents");
|
|
535
786
|
const query = (v.query || "").toLowerCase();
|
|
536
787
|
const limit = v.limit ?? DEFAULT_LIMIT;
|
|
788
|
+
const all = v.targetLayer === "observation" ? [] : await kvInstance.list("mem:memories");
|
|
789
|
+
const sessions = v.project || v.cwd ? await kvInstance.list("mem:sessions") : [];
|
|
790
|
+
const sessionsById = new Map(sessions.map((session) => [session.id, session]));
|
|
791
|
+
const scoped = all.filter((memory) => {
|
|
792
|
+
if (memory.isLatest === false || agentId && memory.agentId !== agentId) return false;
|
|
793
|
+
const linkedSessions = (memory.sessionIds ?? []).map((id) => sessionsById.get(id));
|
|
794
|
+
if (v.project && (memory.project ? memory.project !== v.project : !linkedSessions.some((session) => session?.project === v.project))) return false;
|
|
795
|
+
if (v.cwd && !linkedSessions.some((session) => session?.cwd === v.cwd)) return false;
|
|
796
|
+
return true;
|
|
797
|
+
});
|
|
798
|
+
if (v.tool === "memory_smart_search" && v.expandIds?.length) {
|
|
799
|
+
const ids = v.expandIds.map((entry) => typeof entry === "string" ? entry : entry.obsId);
|
|
800
|
+
const byId = new Map(scoped.map((memory) => [memory.id, memory]));
|
|
801
|
+
const eligible = ids.filter((id) => byId.has(id));
|
|
802
|
+
return textResponse({
|
|
803
|
+
mode: "expanded",
|
|
804
|
+
results: eligible.slice(0, 20).map((id) => {
|
|
805
|
+
const observation = memoryToObservation(byId.get(id));
|
|
806
|
+
return {
|
|
807
|
+
obsId: id,
|
|
808
|
+
sessionId: observation.sessionId,
|
|
809
|
+
observation,
|
|
810
|
+
layer: "memory"
|
|
811
|
+
};
|
|
812
|
+
}),
|
|
813
|
+
truncated: eligible.length > 20
|
|
814
|
+
}, true);
|
|
815
|
+
}
|
|
816
|
+
const results = scoped.filter((memory) => {
|
|
817
|
+
const text = [
|
|
818
|
+
memory.title,
|
|
819
|
+
memory.content,
|
|
820
|
+
...memory.files ?? [],
|
|
821
|
+
...memory.concepts ?? [],
|
|
822
|
+
...memory.sessionIds ?? [],
|
|
823
|
+
memory.id
|
|
824
|
+
].join(" ").toLowerCase();
|
|
825
|
+
return query.split(/\s+/).every((word) => text.includes(word));
|
|
826
|
+
}).slice(0, limit);
|
|
827
|
+
if (v.tool === "memory_recall") return textResponse(buildRecallResponse(results.map((memory) => {
|
|
828
|
+
const observation = memoryToObservation(memory);
|
|
829
|
+
return {
|
|
830
|
+
sessionId: observation.sessionId,
|
|
831
|
+
observation,
|
|
832
|
+
score: 1,
|
|
833
|
+
layer: "memory"
|
|
834
|
+
};
|
|
835
|
+
}), v.format ?? "full", v.tokenBudget), true);
|
|
537
836
|
return textResponse({
|
|
538
837
|
mode: "compact",
|
|
539
|
-
results:
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
].join(" ").toLowerCase();
|
|
548
|
-
return query.split(/\s+/).every((word) => text.includes(word));
|
|
549
|
-
}).slice(0, limit)
|
|
838
|
+
results: results.map((memory) => ({
|
|
839
|
+
...memory,
|
|
840
|
+
type: "decision",
|
|
841
|
+
memoryType: memory.type,
|
|
842
|
+
obsId: memory.id,
|
|
843
|
+
sessionId: memory.sessionIds?.[0] ?? "memory",
|
|
844
|
+
layer: "memory"
|
|
845
|
+
}))
|
|
550
846
|
}, true);
|
|
551
847
|
}
|
|
552
848
|
case "memory_sessions": {
|
|
553
|
-
const
|
|
554
|
-
const
|
|
555
|
-
|
|
849
|
+
const query = v.sessionQuery;
|
|
850
|
+
const agentId = query.agentId === "*" ? void 0 : query.agentId ?? (isAgentScopeIsolated() ? getAgentId() : void 0);
|
|
851
|
+
const sessions = (await kvInstance.list("mem:sessions")).filter((session) => session && typeof session.id === "string" && session.id.length > 0).filter((session) => !query.project || session.project === query.project).filter((session) => !agentId || session.agentId === agentId);
|
|
852
|
+
const key = (session) => session.startedAt || "";
|
|
853
|
+
const { page, nextCursor } = pageAfterCursor(sortByKeyDesc(sessions, key, (session) => session.id), key, (session) => session.id, query.cursor, Number(query.limit));
|
|
854
|
+
return textResponse({
|
|
855
|
+
sessions: await Promise.all(page.map(async (session) => {
|
|
856
|
+
const summary = await kvInstance.get("mem:summaries", session.id);
|
|
857
|
+
return summary ? {
|
|
858
|
+
...session,
|
|
859
|
+
summary
|
|
860
|
+
} : session;
|
|
861
|
+
})),
|
|
862
|
+
nextCursor
|
|
863
|
+
}, true);
|
|
556
864
|
}
|
|
557
865
|
case "memory_governance_delete": {
|
|
558
866
|
let deleted = 0;
|
|
@@ -560,11 +868,12 @@ async function handleLocal(v, kvInstance) {
|
|
|
560
868
|
await kvInstance.delete("mem:memories", id);
|
|
561
869
|
deleted++;
|
|
562
870
|
}
|
|
563
|
-
kvInstance.persist();
|
|
871
|
+
const persisted = kvInstance.persist();
|
|
564
872
|
return textResponse({
|
|
565
873
|
deleted,
|
|
566
874
|
requested: (v.memoryIds || []).length,
|
|
567
|
-
reason: v.reason
|
|
875
|
+
reason: v.reason,
|
|
876
|
+
...localFallbackNotice(persisted)
|
|
568
877
|
});
|
|
569
878
|
}
|
|
570
879
|
case "memory_export": return textResponse({
|
|
@@ -604,6 +913,10 @@ async function handleToolCall(toolName, args, kvInstance = kv) {
|
|
|
604
913
|
if (handle.mode === "proxy") try {
|
|
605
914
|
return await handleProxy(validated, handle);
|
|
606
915
|
} catch (err) {
|
|
916
|
+
if (toolName === "memory_sessions" || isAuthenticationError(err) || isProxyRequired()) {
|
|
917
|
+
invalidateHandle();
|
|
918
|
+
throw err;
|
|
919
|
+
}
|
|
607
920
|
process.stderr.write(`[@agentmemory/mcp] proxy call failed for ${toolName}: ${err instanceof Error ? err.message : String(err)}; invalidating handle and falling back to local KV\n`);
|
|
608
921
|
invalidateHandle();
|
|
609
922
|
}
|
|
@@ -624,10 +937,12 @@ async function handleToolsList() {
|
|
|
624
937
|
if (debug) process.stderr.write(`[@agentmemory/mcp] tools/list: returning ${remote.tools.length} tools from server\n`);
|
|
625
938
|
return { tools: remote.tools };
|
|
626
939
|
}
|
|
940
|
+
if (isProxyRequired()) throw new Error("AgentMemory returned an invalid tool inventory");
|
|
627
941
|
process.stderr.write(`[@agentmemory/mcp] tools/list: server returned unexpected shape (no .tools array); falling back to local IMPLEMENTED_TOOLS list. Set AGENTMEMORY_DEBUG=1 to inspect response.\n`);
|
|
628
942
|
} catch (err) {
|
|
629
|
-
process.stderr.write(`[@agentmemory/mcp] tools/list proxy failed: ${err instanceof Error ? err.message : String(err)}; falling back to local list\n`);
|
|
630
943
|
invalidateHandle();
|
|
944
|
+
if (isAuthenticationError(err) || isProxyRequired()) throw err;
|
|
945
|
+
process.stderr.write(`[@agentmemory/mcp] tools/list proxy failed: ${err instanceof Error ? err.message : String(err)}; falling back to local list\n`);
|
|
631
946
|
}
|
|
632
947
|
const fallback = getAllTools().filter((t) => IMPLEMENTED_TOOLS.has(t.name));
|
|
633
948
|
if (debug) process.stderr.write(`[@agentmemory/mcp] tools/list: returning ${fallback.length} local fallback tools (${fallback.map((t) => t.name).join(",")})\n`);
|
|
@@ -666,6 +981,7 @@ const transport = createStdioTransport(async (method, params) => {
|
|
|
666
981
|
default: throw new Error(`Unknown method: ${method}`);
|
|
667
982
|
}
|
|
668
983
|
});
|
|
984
|
+
installCrashHandlers({ persist: () => kv.persist() });
|
|
669
985
|
process.stderr.write(`[@agentmemory/mcp] Standalone MCP server v${SERVER_INFO.version} starting...\n`);
|
|
670
986
|
transport.start();
|
|
671
987
|
process.on("SIGINT", () => {
|
|
@@ -679,4 +995,4 @@ process.on("SIGTERM", () => {
|
|
|
679
995
|
//#endregion
|
|
680
996
|
export {};
|
|
681
997
|
|
|
682
|
-
//# sourceMappingURL=standalone-
|
|
998
|
+
//# sourceMappingURL=standalone-BYo5USDb.mjs.map
|