@agentmemory/agentmemory 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +14 -0
- package/.github/workflows/ci.yml +22 -0
- package/.github/workflows/publish.yml +28 -0
- package/AGENTS.md +113 -0
- package/LICENSE +190 -0
- package/README.md +828 -0
- package/assets/banner.png +0 -0
- package/assets/demo.gif +0 -0
- package/assets/demo.mp4 +0 -0
- package/benchmark/QUALITY.md +73 -0
- package/benchmark/REAL-EMBEDDINGS.md +67 -0
- package/benchmark/SCALE.md +110 -0
- package/benchmark/dataset.ts +293 -0
- package/benchmark/quality-eval.ts +643 -0
- package/benchmark/real-embeddings-eval.ts +405 -0
- package/benchmark/scale-eval.ts +398 -0
- package/dist/cli.d.mts +1 -0
- package/dist/cli.mjs +137 -0
- package/dist/cli.mjs.map +1 -0
- package/dist/docker-compose.yml +14 -0
- package/dist/hooks/notification.d.mts +1 -0
- package/dist/hooks/notification.mjs +45 -0
- package/dist/hooks/notification.mjs.map +1 -0
- package/dist/hooks/post-tool-failure.d.mts +1 -0
- package/dist/hooks/post-tool-failure.mjs +45 -0
- package/dist/hooks/post-tool-failure.mjs.map +1 -0
- package/dist/hooks/post-tool-use.d.mts +1 -0
- package/dist/hooks/post-tool-use.mjs +53 -0
- package/dist/hooks/post-tool-use.mjs.map +1 -0
- package/dist/hooks/pre-compact.d.mts +1 -0
- package/dist/hooks/pre-compact.mjs +50 -0
- package/dist/hooks/pre-compact.mjs.map +1 -0
- package/dist/hooks/pre-tool-use.d.mts +1 -0
- package/dist/hooks/pre-tool-use.mjs +69 -0
- package/dist/hooks/pre-tool-use.mjs.map +1 -0
- package/dist/hooks/prompt-submit.d.mts +1 -0
- package/dist/hooks/prompt-submit.mjs +40 -0
- package/dist/hooks/prompt-submit.mjs.map +1 -0
- package/dist/hooks/session-end.d.mts +1 -0
- package/dist/hooks/session-end.mjs +61 -0
- package/dist/hooks/session-end.mjs.map +1 -0
- package/dist/hooks/session-start.d.mts +1 -0
- package/dist/hooks/session-start.mjs +42 -0
- package/dist/hooks/session-start.mjs.map +1 -0
- package/dist/hooks/stop.d.mts +1 -0
- package/dist/hooks/stop.mjs +33 -0
- package/dist/hooks/stop.mjs.map +1 -0
- package/dist/hooks/subagent-start.d.mts +1 -0
- package/dist/hooks/subagent-start.mjs +43 -0
- package/dist/hooks/subagent-start.mjs.map +1 -0
- package/dist/hooks/subagent-stop.d.mts +1 -0
- package/dist/hooks/subagent-stop.mjs +45 -0
- package/dist/hooks/subagent-stop.mjs.map +1 -0
- package/dist/hooks/task-completed.d.mts +1 -0
- package/dist/hooks/task-completed.mjs +46 -0
- package/dist/hooks/task-completed.mjs.map +1 -0
- package/dist/iii-config.yaml +51 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.mjs +13776 -0
- package/dist/index.mjs.map +1 -0
- package/dist/src-QxitMPfJ.mjs +13775 -0
- package/dist/src-QxitMPfJ.mjs.map +1 -0
- package/dist/standalone.d.mts +1 -0
- package/dist/standalone.mjs +1155 -0
- package/dist/standalone.mjs.map +1 -0
- package/dist/transformers-BX_tgxdO.mjs +38684 -0
- package/dist/transformers-BX_tgxdO.mjs.map +1 -0
- package/dist/transformers-KMm1i9no.mjs +38683 -0
- package/dist/transformers-KMm1i9no.mjs.map +1 -0
- package/docker-compose.yml +14 -0
- package/iii-config.yaml +51 -0
- package/package.json +59 -0
- package/plugin/.claude-plugin/plugin.json +10 -0
- package/plugin/hooks/hooks.json +77 -0
- package/plugin/scripts/diagnostics.mjs +551 -0
- package/plugin/scripts/notification.mjs +45 -0
- package/plugin/scripts/post-tool-failure.mjs +45 -0
- package/plugin/scripts/post-tool-use.mjs +53 -0
- package/plugin/scripts/pre-compact.mjs +50 -0
- package/plugin/scripts/pre-tool-use.mjs +69 -0
- package/plugin/scripts/prompt-submit.mjs +40 -0
- package/plugin/scripts/session-end.mjs +61 -0
- package/plugin/scripts/session-start.mjs +42 -0
- package/plugin/scripts/stop.mjs +33 -0
- package/plugin/scripts/subagent-start.mjs +43 -0
- package/plugin/scripts/subagent-stop.mjs +45 -0
- package/plugin/scripts/task-completed.mjs +46 -0
- package/plugin/skills/forget/SKILL.md +32 -0
- package/plugin/skills/recall/SKILL.md +18 -0
- package/plugin/skills/remember/SKILL.md +25 -0
- package/plugin/skills/session-history/SKILL.md +17 -0
- package/src/auth.ts +12 -0
- package/src/cli.ts +159 -0
- package/src/config.ts +221 -0
- package/src/eval/metrics-store.ts +65 -0
- package/src/eval/quality.ts +51 -0
- package/src/eval/schemas.ts +124 -0
- package/src/eval/self-correct.ts +28 -0
- package/src/eval/validator.ts +31 -0
- package/src/functions/actions.ts +288 -0
- package/src/functions/audit.ts +61 -0
- package/src/functions/auto-forget.ts +169 -0
- package/src/functions/branch-aware.ts +169 -0
- package/src/functions/cascade.ts +80 -0
- package/src/functions/checkpoints.ts +209 -0
- package/src/functions/claude-bridge.ts +161 -0
- package/src/functions/compress.ts +194 -0
- package/src/functions/consolidate.ts +212 -0
- package/src/functions/consolidation-pipeline.ts +258 -0
- package/src/functions/context.ts +169 -0
- package/src/functions/crystallize.ts +293 -0
- package/src/functions/dedup.ts +57 -0
- package/src/functions/diagnostics.ts +785 -0
- package/src/functions/enrich.ts +132 -0
- package/src/functions/evict.ts +163 -0
- package/src/functions/export-import.ts +508 -0
- package/src/functions/facets.ts +248 -0
- package/src/functions/file-index.ts +106 -0
- package/src/functions/flow-compress.ts +214 -0
- package/src/functions/frontier.ts +196 -0
- package/src/functions/governance.ts +131 -0
- package/src/functions/graph-retrieval.ts +277 -0
- package/src/functions/graph.ts +275 -0
- package/src/functions/leases.ts +216 -0
- package/src/functions/lessons.ts +253 -0
- package/src/functions/mesh.ts +434 -0
- package/src/functions/migrate.ts +165 -0
- package/src/functions/observe.ts +144 -0
- package/src/functions/obsidian-export.ts +310 -0
- package/src/functions/patterns.ts +138 -0
- package/src/functions/privacy.ts +39 -0
- package/src/functions/profile.ts +155 -0
- package/src/functions/query-expansion.ts +186 -0
- package/src/functions/relations.ts +237 -0
- package/src/functions/remember.ts +162 -0
- package/src/functions/retention.ts +235 -0
- package/src/functions/routines.ts +289 -0
- package/src/functions/search.ts +80 -0
- package/src/functions/sentinels.ts +417 -0
- package/src/functions/signals.ts +186 -0
- package/src/functions/sketches.ts +274 -0
- package/src/functions/sliding-window.ts +257 -0
- package/src/functions/smart-search.ts +115 -0
- package/src/functions/snapshot.ts +219 -0
- package/src/functions/summarize.ts +155 -0
- package/src/functions/team.ts +147 -0
- package/src/functions/temporal-graph.ts +476 -0
- package/src/functions/timeline.ts +138 -0
- package/src/functions/verify.ts +117 -0
- package/src/health/monitor.ts +110 -0
- package/src/health/thresholds.ts +73 -0
- package/src/hooks/notification.ts +52 -0
- package/src/hooks/post-tool-failure.ts +58 -0
- package/src/hooks/post-tool-use.ts +62 -0
- package/src/hooks/pre-compact.ts +60 -0
- package/src/hooks/pre-tool-use.ts +72 -0
- package/src/hooks/prompt-submit.ts +46 -0
- package/src/hooks/session-end.ts +71 -0
- package/src/hooks/session-start.ts +48 -0
- package/src/hooks/stop.ts +39 -0
- package/src/hooks/subagent-start.ts +49 -0
- package/src/hooks/subagent-stop.ts +54 -0
- package/src/hooks/task-completed.ts +54 -0
- package/src/index.ts +342 -0
- package/src/mcp/in-memory-kv.ts +61 -0
- package/src/mcp/server.ts +1455 -0
- package/src/mcp/standalone.ts +177 -0
- package/src/mcp/tools-registry.ts +769 -0
- package/src/mcp/transport.ts +91 -0
- package/src/prompts/compression.ts +67 -0
- package/src/prompts/consolidation.ts +48 -0
- package/src/prompts/graph-extraction.ts +35 -0
- package/src/prompts/summary.ts +38 -0
- package/src/prompts/xml.ts +26 -0
- package/src/providers/agent-sdk.ts +34 -0
- package/src/providers/anthropic.ts +35 -0
- package/src/providers/circuit-breaker.ts +82 -0
- package/src/providers/embedding/cohere.ts +46 -0
- package/src/providers/embedding/gemini.ts +54 -0
- package/src/providers/embedding/index.ts +39 -0
- package/src/providers/embedding/local.ts +52 -0
- package/src/providers/embedding/openai.ts +45 -0
- package/src/providers/embedding/openrouter.ts +51 -0
- package/src/providers/embedding/voyage.ts +46 -0
- package/src/providers/fallback-chain.ts +31 -0
- package/src/providers/index.ts +84 -0
- package/src/providers/openrouter.ts +71 -0
- package/src/providers/resilient.ts +37 -0
- package/src/state/hybrid-search.ts +295 -0
- package/src/state/index-persistence.ts +63 -0
- package/src/state/keyed-mutex.ts +18 -0
- package/src/state/kv.ts +33 -0
- package/src/state/schema.ts +71 -0
- package/src/state/search-index.ts +245 -0
- package/src/state/stemmer.ts +104 -0
- package/src/state/synonyms.ts +63 -0
- package/src/state/vector-index.ts +130 -0
- package/src/telemetry/setup.ts +116 -0
- package/src/triggers/api.ts +1904 -0
- package/src/triggers/events.ts +71 -0
- package/src/types.ts +769 -0
- package/src/version.ts +1 -0
- package/src/viewer/index.html +2497 -0
- package/src/viewer/server.ts +207 -0
- package/src/xenova.d.ts +3 -0
- package/test/actions.test.ts +490 -0
- package/test/audit.test.ts +108 -0
- package/test/auto-forget.test.ts +188 -0
- package/test/cascade.test.ts +277 -0
- package/test/checkpoints.test.ts +493 -0
- package/test/circuit-breaker.test.ts +107 -0
- package/test/claude-bridge.test.ts +178 -0
- package/test/confidence.test.ts +247 -0
- package/test/consistency.test.ts +61 -0
- package/test/consolidation-pipeline.test.ts +251 -0
- package/test/crystallize.test.ts +521 -0
- package/test/diagnostics.test.ts +638 -0
- package/test/embedding-provider.test.ts +49 -0
- package/test/enrich.test.ts +209 -0
- package/test/eval.test.ts +300 -0
- package/test/export-import.test.ts +251 -0
- package/test/facets.test.ts +448 -0
- package/test/fallback-chain.test.ts +93 -0
- package/test/frontier.test.ts +485 -0
- package/test/governance.test.ts +147 -0
- package/test/graph-retrieval.test.ts +186 -0
- package/test/graph.test.ts +160 -0
- package/test/helpers/mocks.ts +40 -0
- package/test/hybrid-search.test.ts +145 -0
- package/test/index-persistence.test.ts +124 -0
- package/test/integration.test.ts +265 -0
- package/test/leases.test.ts +399 -0
- package/test/mcp-prompts.test.ts +218 -0
- package/test/mcp-resources.test.ts +286 -0
- package/test/mcp-standalone.test.ts +113 -0
- package/test/mesh.test.ts +700 -0
- package/test/privacy.test.ts +87 -0
- package/test/profile.test.ts +161 -0
- package/test/query-expansion.test.ts +154 -0
- package/test/relations.test.ts +198 -0
- package/test/retention.test.ts +245 -0
- package/test/routines.test.ts +497 -0
- package/test/schema-fingerprint.test.ts +81 -0
- package/test/schema.test.ts +42 -0
- package/test/search-index.test.ts +128 -0
- package/test/sentinels.test.ts +626 -0
- package/test/signals.test.ts +410 -0
- package/test/sketches.test.ts +549 -0
- package/test/sliding-window.test.ts +199 -0
- package/test/smart-search.test.ts +169 -0
- package/test/snapshot.test.ts +165 -0
- package/test/team.test.ts +156 -0
- package/test/temporal-graph.test.ts +378 -0
- package/test/timeline.test.ts +148 -0
- package/test/vector-index.test.ts +79 -0
- package/test/verify.test.ts +209 -0
- package/test/xml.test.ts +65 -0
- package/tsconfig.json +22 -0
- package/tsdown.config.ts +62 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
//#region src/hooks/pre-compact.ts
|
|
3
|
+
const REST_URL = process.env["AGENTMEMORY_URL"] || "http://localhost:3111";
|
|
4
|
+
const SECRET = process.env["AGENTMEMORY_SECRET"] || "";
|
|
5
|
+
function authHeaders() {
|
|
6
|
+
const h = { "Content-Type": "application/json" };
|
|
7
|
+
if (SECRET) h["Authorization"] = `Bearer ${SECRET}`;
|
|
8
|
+
return h;
|
|
9
|
+
}
|
|
10
|
+
async function main() {
|
|
11
|
+
let input = "";
|
|
12
|
+
for await (const chunk of process.stdin) input += chunk;
|
|
13
|
+
let data;
|
|
14
|
+
try {
|
|
15
|
+
data = JSON.parse(input);
|
|
16
|
+
} catch {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const sessionId = data.session_id || "unknown";
|
|
20
|
+
const project = data.cwd || process.cwd();
|
|
21
|
+
if (process.env["CLAUDE_MEMORY_BRIDGE"] === "true") try {
|
|
22
|
+
await fetch(`${REST_URL}/agentmemory/claude-bridge/sync`, {
|
|
23
|
+
method: "POST",
|
|
24
|
+
headers: authHeaders(),
|
|
25
|
+
body: JSON.stringify({}),
|
|
26
|
+
signal: AbortSignal.timeout(5e3)
|
|
27
|
+
});
|
|
28
|
+
} catch {}
|
|
29
|
+
try {
|
|
30
|
+
const res = await fetch(`${REST_URL}/agentmemory/context`, {
|
|
31
|
+
method: "POST",
|
|
32
|
+
headers: authHeaders(),
|
|
33
|
+
body: JSON.stringify({
|
|
34
|
+
sessionId,
|
|
35
|
+
project,
|
|
36
|
+
budget: 1500
|
|
37
|
+
}),
|
|
38
|
+
signal: AbortSignal.timeout(5e3)
|
|
39
|
+
});
|
|
40
|
+
if (res.ok) {
|
|
41
|
+
const result = await res.json();
|
|
42
|
+
if (result.context) process.stdout.write(result.context);
|
|
43
|
+
}
|
|
44
|
+
} catch {}
|
|
45
|
+
}
|
|
46
|
+
main();
|
|
47
|
+
|
|
48
|
+
//#endregion
|
|
49
|
+
export { };
|
|
50
|
+
//# sourceMappingURL=pre-compact.mjs.map
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
//#region src/hooks/pre-tool-use.ts
|
|
3
|
+
const REST_URL = process.env["AGENTMEMORY_URL"] || "http://localhost:3111";
|
|
4
|
+
const SECRET = process.env["AGENTMEMORY_SECRET"] || "";
|
|
5
|
+
function authHeaders() {
|
|
6
|
+
const h = { "Content-Type": "application/json" };
|
|
7
|
+
if (SECRET) h["Authorization"] = `Bearer ${SECRET}`;
|
|
8
|
+
return h;
|
|
9
|
+
}
|
|
10
|
+
async function main() {
|
|
11
|
+
let input = "";
|
|
12
|
+
for await (const chunk of process.stdin) input += chunk;
|
|
13
|
+
let data;
|
|
14
|
+
try {
|
|
15
|
+
data = JSON.parse(input);
|
|
16
|
+
} catch {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const toolName = data.tool_name;
|
|
20
|
+
if (!toolName) return;
|
|
21
|
+
if (![
|
|
22
|
+
"Edit",
|
|
23
|
+
"Write",
|
|
24
|
+
"Read",
|
|
25
|
+
"Glob",
|
|
26
|
+
"Grep"
|
|
27
|
+
].includes(toolName)) return;
|
|
28
|
+
const toolInput = data.tool_input || {};
|
|
29
|
+
const files = [];
|
|
30
|
+
const fileKeys = toolName === "Grep" ? ["path", "file"] : [
|
|
31
|
+
"file_path",
|
|
32
|
+
"path",
|
|
33
|
+
"file",
|
|
34
|
+
"pattern"
|
|
35
|
+
];
|
|
36
|
+
for (const key of fileKeys) {
|
|
37
|
+
const val = toolInput[key];
|
|
38
|
+
if (typeof val === "string" && val.length > 0) files.push(val);
|
|
39
|
+
}
|
|
40
|
+
if (files.length === 0) return;
|
|
41
|
+
const terms = [];
|
|
42
|
+
if (toolName === "Grep" || toolName === "Glob") {
|
|
43
|
+
const pattern = toolInput["pattern"];
|
|
44
|
+
if (typeof pattern === "string" && pattern.length > 0) terms.push(pattern);
|
|
45
|
+
}
|
|
46
|
+
const sessionId = data.session_id || "unknown";
|
|
47
|
+
try {
|
|
48
|
+
const res = await fetch(`${REST_URL}/agentmemory/enrich`, {
|
|
49
|
+
method: "POST",
|
|
50
|
+
headers: authHeaders(),
|
|
51
|
+
body: JSON.stringify({
|
|
52
|
+
sessionId,
|
|
53
|
+
files,
|
|
54
|
+
terms,
|
|
55
|
+
toolName
|
|
56
|
+
}),
|
|
57
|
+
signal: AbortSignal.timeout(2e3)
|
|
58
|
+
});
|
|
59
|
+
if (res.ok) {
|
|
60
|
+
const result = await res.json();
|
|
61
|
+
if (result.context) process.stdout.write(result.context);
|
|
62
|
+
}
|
|
63
|
+
} catch {}
|
|
64
|
+
}
|
|
65
|
+
main();
|
|
66
|
+
|
|
67
|
+
//#endregion
|
|
68
|
+
export { };
|
|
69
|
+
//# sourceMappingURL=pre-tool-use.mjs.map
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
//#region src/hooks/prompt-submit.ts
|
|
3
|
+
const REST_URL = process.env["AGENTMEMORY_URL"] || "http://localhost:3111";
|
|
4
|
+
const SECRET = process.env["AGENTMEMORY_SECRET"] || "";
|
|
5
|
+
function authHeaders() {
|
|
6
|
+
const h = { "Content-Type": "application/json" };
|
|
7
|
+
if (SECRET) h["Authorization"] = `Bearer ${SECRET}`;
|
|
8
|
+
return h;
|
|
9
|
+
}
|
|
10
|
+
async function main() {
|
|
11
|
+
let input = "";
|
|
12
|
+
for await (const chunk of process.stdin) input += chunk;
|
|
13
|
+
let data;
|
|
14
|
+
try {
|
|
15
|
+
data = JSON.parse(input);
|
|
16
|
+
} catch {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const sessionId = data.session_id || "unknown";
|
|
20
|
+
try {
|
|
21
|
+
await fetch(`${REST_URL}/agentmemory/observe`, {
|
|
22
|
+
method: "POST",
|
|
23
|
+
headers: authHeaders(),
|
|
24
|
+
body: JSON.stringify({
|
|
25
|
+
hookType: "prompt_submit",
|
|
26
|
+
sessionId,
|
|
27
|
+
project: data.cwd || process.cwd(),
|
|
28
|
+
cwd: data.cwd || process.cwd(),
|
|
29
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
30
|
+
data: { prompt: data.prompt }
|
|
31
|
+
}),
|
|
32
|
+
signal: AbortSignal.timeout(3e3)
|
|
33
|
+
});
|
|
34
|
+
} catch {}
|
|
35
|
+
}
|
|
36
|
+
main();
|
|
37
|
+
|
|
38
|
+
//#endregion
|
|
39
|
+
export { };
|
|
40
|
+
//# sourceMappingURL=prompt-submit.mjs.map
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
//#region src/hooks/session-end.ts
|
|
3
|
+
const REST_URL = process.env["AGENTMEMORY_URL"] || "http://localhost:3111";
|
|
4
|
+
const SECRET = process.env["AGENTMEMORY_SECRET"] || "";
|
|
5
|
+
function authHeaders() {
|
|
6
|
+
const h = { "Content-Type": "application/json" };
|
|
7
|
+
if (SECRET) h["Authorization"] = `Bearer ${SECRET}`;
|
|
8
|
+
return h;
|
|
9
|
+
}
|
|
10
|
+
async function main() {
|
|
11
|
+
let input = "";
|
|
12
|
+
for await (const chunk of process.stdin) input += chunk;
|
|
13
|
+
let data;
|
|
14
|
+
try {
|
|
15
|
+
data = JSON.parse(input);
|
|
16
|
+
} catch {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const sessionId = data.session_id || "unknown";
|
|
20
|
+
try {
|
|
21
|
+
await fetch(`${REST_URL}/agentmemory/session/end`, {
|
|
22
|
+
method: "POST",
|
|
23
|
+
headers: authHeaders(),
|
|
24
|
+
body: JSON.stringify({ sessionId }),
|
|
25
|
+
signal: AbortSignal.timeout(5e3)
|
|
26
|
+
});
|
|
27
|
+
} catch {}
|
|
28
|
+
if (process.env["CONSOLIDATION_ENABLED"] === "true") {
|
|
29
|
+
try {
|
|
30
|
+
await fetch(`${REST_URL}/agentmemory/crystals/auto`, {
|
|
31
|
+
method: "POST",
|
|
32
|
+
headers: authHeaders(),
|
|
33
|
+
body: JSON.stringify({ olderThanDays: 0 }),
|
|
34
|
+
signal: AbortSignal.timeout(15e3)
|
|
35
|
+
});
|
|
36
|
+
} catch {}
|
|
37
|
+
try {
|
|
38
|
+
await fetch(`${REST_URL}/agentmemory/consolidate-pipeline`, {
|
|
39
|
+
method: "POST",
|
|
40
|
+
headers: authHeaders(),
|
|
41
|
+
body: JSON.stringify({
|
|
42
|
+
tier: "all",
|
|
43
|
+
force: true
|
|
44
|
+
}),
|
|
45
|
+
signal: AbortSignal.timeout(3e4)
|
|
46
|
+
});
|
|
47
|
+
} catch {}
|
|
48
|
+
}
|
|
49
|
+
if (process.env["CLAUDE_MEMORY_BRIDGE"] === "true") try {
|
|
50
|
+
await fetch(`${REST_URL}/agentmemory/claude-bridge/sync`, {
|
|
51
|
+
method: "POST",
|
|
52
|
+
headers: authHeaders(),
|
|
53
|
+
signal: AbortSignal.timeout(5e3)
|
|
54
|
+
});
|
|
55
|
+
} catch {}
|
|
56
|
+
}
|
|
57
|
+
main();
|
|
58
|
+
|
|
59
|
+
//#endregion
|
|
60
|
+
export { };
|
|
61
|
+
//# sourceMappingURL=session-end.mjs.map
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
//#region src/hooks/session-start.ts
|
|
3
|
+
const REST_URL = process.env["AGENTMEMORY_URL"] || "http://localhost:3111";
|
|
4
|
+
const SECRET = process.env["AGENTMEMORY_SECRET"] || "";
|
|
5
|
+
function authHeaders() {
|
|
6
|
+
const h = { "Content-Type": "application/json" };
|
|
7
|
+
if (SECRET) h["Authorization"] = `Bearer ${SECRET}`;
|
|
8
|
+
return h;
|
|
9
|
+
}
|
|
10
|
+
async function main() {
|
|
11
|
+
let input = "";
|
|
12
|
+
for await (const chunk of process.stdin) input += chunk;
|
|
13
|
+
let data;
|
|
14
|
+
try {
|
|
15
|
+
data = JSON.parse(input);
|
|
16
|
+
} catch {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const sessionId = data.session_id || `ses_${Date.now().toString(36)}`;
|
|
20
|
+
const project = data.cwd || process.cwd();
|
|
21
|
+
try {
|
|
22
|
+
const res = await fetch(`${REST_URL}/agentmemory/session/start`, {
|
|
23
|
+
method: "POST",
|
|
24
|
+
headers: authHeaders(),
|
|
25
|
+
body: JSON.stringify({
|
|
26
|
+
sessionId,
|
|
27
|
+
project,
|
|
28
|
+
cwd: project
|
|
29
|
+
}),
|
|
30
|
+
signal: AbortSignal.timeout(5e3)
|
|
31
|
+
});
|
|
32
|
+
if (res.ok) {
|
|
33
|
+
const result = await res.json();
|
|
34
|
+
if (result.context) process.stdout.write(result.context);
|
|
35
|
+
}
|
|
36
|
+
} catch {}
|
|
37
|
+
}
|
|
38
|
+
main();
|
|
39
|
+
|
|
40
|
+
//#endregion
|
|
41
|
+
export { };
|
|
42
|
+
//# sourceMappingURL=session-start.mjs.map
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
//#region src/hooks/stop.ts
|
|
3
|
+
const REST_URL = process.env["AGENTMEMORY_URL"] || "http://localhost:3111";
|
|
4
|
+
const SECRET = process.env["AGENTMEMORY_SECRET"] || "";
|
|
5
|
+
function authHeaders() {
|
|
6
|
+
const h = { "Content-Type": "application/json" };
|
|
7
|
+
if (SECRET) h["Authorization"] = `Bearer ${SECRET}`;
|
|
8
|
+
return h;
|
|
9
|
+
}
|
|
10
|
+
async function main() {
|
|
11
|
+
let input = "";
|
|
12
|
+
for await (const chunk of process.stdin) input += chunk;
|
|
13
|
+
let data;
|
|
14
|
+
try {
|
|
15
|
+
data = JSON.parse(input);
|
|
16
|
+
} catch {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const sessionId = data.session_id || "unknown";
|
|
20
|
+
try {
|
|
21
|
+
await fetch(`${REST_URL}/agentmemory/summarize`, {
|
|
22
|
+
method: "POST",
|
|
23
|
+
headers: authHeaders(),
|
|
24
|
+
body: JSON.stringify({ sessionId }),
|
|
25
|
+
signal: AbortSignal.timeout(3e4)
|
|
26
|
+
});
|
|
27
|
+
} catch {}
|
|
28
|
+
}
|
|
29
|
+
main();
|
|
30
|
+
|
|
31
|
+
//#endregion
|
|
32
|
+
export { };
|
|
33
|
+
//# sourceMappingURL=stop.mjs.map
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
//#region src/hooks/subagent-start.ts
|
|
3
|
+
const REST_URL = process.env["AGENTMEMORY_URL"] || "http://localhost:3111";
|
|
4
|
+
const SECRET = process.env["AGENTMEMORY_SECRET"] || "";
|
|
5
|
+
function authHeaders() {
|
|
6
|
+
const h = { "Content-Type": "application/json" };
|
|
7
|
+
if (SECRET) h["Authorization"] = `Bearer ${SECRET}`;
|
|
8
|
+
return h;
|
|
9
|
+
}
|
|
10
|
+
async function main() {
|
|
11
|
+
let input = "";
|
|
12
|
+
for await (const chunk of process.stdin) input += chunk;
|
|
13
|
+
let data;
|
|
14
|
+
try {
|
|
15
|
+
data = JSON.parse(input);
|
|
16
|
+
} catch {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const sessionId = data.session_id || "unknown";
|
|
20
|
+
try {
|
|
21
|
+
await fetch(`${REST_URL}/agentmemory/observe`, {
|
|
22
|
+
method: "POST",
|
|
23
|
+
headers: authHeaders(),
|
|
24
|
+
body: JSON.stringify({
|
|
25
|
+
hookType: "subagent_start",
|
|
26
|
+
sessionId,
|
|
27
|
+
project: data.cwd || process.cwd(),
|
|
28
|
+
cwd: data.cwd || process.cwd(),
|
|
29
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
30
|
+
data: {
|
|
31
|
+
agent_id: data.agent_id,
|
|
32
|
+
agent_type: data.agent_type
|
|
33
|
+
}
|
|
34
|
+
}),
|
|
35
|
+
signal: AbortSignal.timeout(2e3)
|
|
36
|
+
});
|
|
37
|
+
} catch {}
|
|
38
|
+
}
|
|
39
|
+
main();
|
|
40
|
+
|
|
41
|
+
//#endregion
|
|
42
|
+
export { };
|
|
43
|
+
//# sourceMappingURL=subagent-start.mjs.map
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
//#region src/hooks/subagent-stop.ts
|
|
3
|
+
const REST_URL = process.env["AGENTMEMORY_URL"] || "http://localhost:3111";
|
|
4
|
+
const SECRET = process.env["AGENTMEMORY_SECRET"] || "";
|
|
5
|
+
function authHeaders() {
|
|
6
|
+
const h = { "Content-Type": "application/json" };
|
|
7
|
+
if (SECRET) h["Authorization"] = `Bearer ${SECRET}`;
|
|
8
|
+
return h;
|
|
9
|
+
}
|
|
10
|
+
async function main() {
|
|
11
|
+
let input = "";
|
|
12
|
+
for await (const chunk of process.stdin) input += chunk;
|
|
13
|
+
let data;
|
|
14
|
+
try {
|
|
15
|
+
data = JSON.parse(input);
|
|
16
|
+
} catch {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const sessionId = data.session_id || "unknown";
|
|
20
|
+
const lastMsg = typeof data.last_assistant_message === "string" ? data.last_assistant_message.slice(0, 4e3) : "";
|
|
21
|
+
try {
|
|
22
|
+
await fetch(`${REST_URL}/agentmemory/observe`, {
|
|
23
|
+
method: "POST",
|
|
24
|
+
headers: authHeaders(),
|
|
25
|
+
body: JSON.stringify({
|
|
26
|
+
hookType: "subagent_stop",
|
|
27
|
+
sessionId,
|
|
28
|
+
project: data.cwd || process.cwd(),
|
|
29
|
+
cwd: data.cwd || process.cwd(),
|
|
30
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
31
|
+
data: {
|
|
32
|
+
agent_id: data.agent_id,
|
|
33
|
+
agent_type: data.agent_type,
|
|
34
|
+
last_message: lastMsg
|
|
35
|
+
}
|
|
36
|
+
}),
|
|
37
|
+
signal: AbortSignal.timeout(2e3)
|
|
38
|
+
});
|
|
39
|
+
} catch {}
|
|
40
|
+
}
|
|
41
|
+
main();
|
|
42
|
+
|
|
43
|
+
//#endregion
|
|
44
|
+
export { };
|
|
45
|
+
//# sourceMappingURL=subagent-stop.mjs.map
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
//#region src/hooks/task-completed.ts
|
|
3
|
+
const REST_URL = process.env["AGENTMEMORY_URL"] || "http://localhost:3111";
|
|
4
|
+
const SECRET = process.env["AGENTMEMORY_SECRET"] || "";
|
|
5
|
+
function authHeaders() {
|
|
6
|
+
const h = { "Content-Type": "application/json" };
|
|
7
|
+
if (SECRET) h["Authorization"] = `Bearer ${SECRET}`;
|
|
8
|
+
return h;
|
|
9
|
+
}
|
|
10
|
+
async function main() {
|
|
11
|
+
let input = "";
|
|
12
|
+
for await (const chunk of process.stdin) input += chunk;
|
|
13
|
+
let data;
|
|
14
|
+
try {
|
|
15
|
+
data = JSON.parse(input);
|
|
16
|
+
} catch {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const sessionId = data.session_id || "unknown";
|
|
20
|
+
try {
|
|
21
|
+
await fetch(`${REST_URL}/agentmemory/observe`, {
|
|
22
|
+
method: "POST",
|
|
23
|
+
headers: authHeaders(),
|
|
24
|
+
body: JSON.stringify({
|
|
25
|
+
hookType: "task_completed",
|
|
26
|
+
sessionId,
|
|
27
|
+
project: data.cwd || process.cwd(),
|
|
28
|
+
cwd: data.cwd || process.cwd(),
|
|
29
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
30
|
+
data: {
|
|
31
|
+
task_id: data.task_id,
|
|
32
|
+
task_subject: data.task_subject,
|
|
33
|
+
task_description: typeof data.task_description === "string" ? data.task_description.slice(0, 2e3) : "",
|
|
34
|
+
teammate_name: data.teammate_name,
|
|
35
|
+
team_name: data.team_name
|
|
36
|
+
}
|
|
37
|
+
}),
|
|
38
|
+
signal: AbortSignal.timeout(2e3)
|
|
39
|
+
});
|
|
40
|
+
} catch {}
|
|
41
|
+
}
|
|
42
|
+
main();
|
|
43
|
+
|
|
44
|
+
//#endregion
|
|
45
|
+
export { };
|
|
46
|
+
//# sourceMappingURL=task-completed.mjs.map
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: forget
|
|
3
|
+
description: Delete specific observations or sessions from agentmemory. Use when user says "forget this", "delete memory", or wants to remove specific data for privacy.
|
|
4
|
+
argument-hint: "[what to forget - session ID, file path, or search term]"
|
|
5
|
+
user-invocable: true
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
The user wants to remove data from agentmemory: $ARGUMENTS
|
|
9
|
+
|
|
10
|
+
**IMPORTANT**: This is a destructive operation. Always confirm with the user before deleting.
|
|
11
|
+
|
|
12
|
+
Steps:
|
|
13
|
+
1. First, search for matching observations:
|
|
14
|
+
```bash
|
|
15
|
+
curl -s -H "Content-Type: application/json" \
|
|
16
|
+
-H "Authorization: Bearer ${AGENTMEMORY_SECRET:-}" \
|
|
17
|
+
-X POST "http://${AGENTMEMORY_URL:-localhost:3111}/agentmemory/search" \
|
|
18
|
+
-d '{"query": "<SEARCH_TERM>", "limit": 20}'
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
2. Show the user what was found and ask for confirmation
|
|
22
|
+
3. If confirmed, delete via:
|
|
23
|
+
```bash
|
|
24
|
+
curl -s -H "Content-Type: application/json" \
|
|
25
|
+
-H "Authorization: Bearer ${AGENTMEMORY_SECRET:-}" \
|
|
26
|
+
-X POST "http://${AGENTMEMORY_URL:-localhost:3111}/agentmemory/forget" \
|
|
27
|
+
-d '{"sessionId": "<ID>"}' # or {"observationIds": ["id1", "id2"]}
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
4. Confirm deletion to the user
|
|
31
|
+
|
|
32
|
+
Never delete without explicit user confirmation.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: recall
|
|
3
|
+
description: Search agentmemory for past observations, sessions, and learnings about a topic. Use when the user says "recall", "remember", "what did we do", or needs context from past sessions.
|
|
4
|
+
argument-hint: "[search query]"
|
|
5
|
+
user-invocable: true
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
Search agentmemory for observations matching: $ARGUMENTS
|
|
9
|
+
|
|
10
|
+
!`QUERY=$(echo "$ARGUMENTS" | sed 's/\\/\\\\/g; s/"/\\"/g') && curl -s -H "Content-Type: application/json" -H "Authorization: Bearer ${AGENTMEMORY_SECRET:-}" -X POST http://${AGENTMEMORY_URL:-localhost:3111}/agentmemory/search -d "{\"query\": \"${QUERY}\", \"limit\": 10}" 2>/dev/null || echo '{"results":[]}'`
|
|
11
|
+
|
|
12
|
+
Present the search results to the user in a readable format:
|
|
13
|
+
- Group by session
|
|
14
|
+
- Show observation type, title, and narrative
|
|
15
|
+
- Highlight the most important observations (importance >= 7)
|
|
16
|
+
- If no results found, suggest alternative search terms
|
|
17
|
+
|
|
18
|
+
Do NOT make up or hallucinate results. Only present what was returned from the search.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: remember
|
|
3
|
+
description: Explicitly save an insight, decision, or learning to agentmemory's long-term storage. Use when the user says "remember this", "save this", or wants to preserve knowledge for future sessions.
|
|
4
|
+
argument-hint: "[what to remember]"
|
|
5
|
+
user-invocable: true
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
The user wants to save this to long-term memory: $ARGUMENTS
|
|
9
|
+
|
|
10
|
+
To save this, make a POST request using the Bash tool:
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
curl -s -H "Content-Type: application/json" \
|
|
14
|
+
-H "Authorization: Bearer ${AGENTMEMORY_SECRET:-}" \
|
|
15
|
+
-X POST "http://${AGENTMEMORY_URL:-localhost:3111}/agentmemory/remember" \
|
|
16
|
+
-d '{"content": "<ESCAPED_CONTENT>", "concepts": [<CONCEPTS>], "files": [<FILES>]}'
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Steps:
|
|
20
|
+
1. Analyze what the user wants to remember
|
|
21
|
+
2. Extract key concepts (2-5 searchable terms)
|
|
22
|
+
3. Extract relevant file paths if any
|
|
23
|
+
4. Make the API call with the properly escaped content
|
|
24
|
+
5. Confirm to the user that the memory was saved
|
|
25
|
+
6. Show what concepts were tagged for future recall
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: session-history
|
|
3
|
+
description: Show what happened in recent past sessions on this project. Use when user asks "what did we do last time", "session history", "past sessions", or wants an overview of previous work.
|
|
4
|
+
user-invocable: true
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
Fetch recent session history from agentmemory:
|
|
8
|
+
|
|
9
|
+
!`curl -s -H "Authorization: Bearer ${AGENTMEMORY_SECRET:-}" "http://${AGENTMEMORY_URL:-localhost:3111}/agentmemory/sessions" 2>/dev/null || echo '{"sessions":[]}'`
|
|
10
|
+
|
|
11
|
+
Present the sessions in reverse chronological order:
|
|
12
|
+
- Show session ID (first 8 chars), project, start time, status
|
|
13
|
+
- For each session with observations, show the key highlights
|
|
14
|
+
- Note total observation count per session
|
|
15
|
+
- If summaries exist, show the session title and key decisions
|
|
16
|
+
|
|
17
|
+
Format as a clean timeline. Do NOT make up sessions -- only show what was returned.
|
package/src/auth.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { timingSafeEqual, createHmac, randomBytes } from "node:crypto";
|
|
2
|
+
|
|
3
|
+
const hmacKey = randomBytes(32);
|
|
4
|
+
|
|
5
|
+
export function timingSafeCompare(a: string, b: string): boolean {
|
|
6
|
+
const hmacA = createHmac("sha256", hmacKey).update(a).digest();
|
|
7
|
+
const hmacB = createHmac("sha256", hmacKey).update(b).digest();
|
|
8
|
+
return timingSafeEqual(hmacA, hmacB);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const VIEWER_CSP =
|
|
12
|
+
"default-src 'none'; script-src 'unsafe-inline'; style-src 'unsafe-inline'; connect-src 'self' ws://localhost:* wss://localhost:*; img-src 'self'; font-src 'self'";
|