@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,551 @@
|
|
|
1
|
+
//#region src/state/schema.ts
|
|
2
|
+
const KV = {
|
|
3
|
+
sessions: "mem:sessions",
|
|
4
|
+
observations: (sessionId) => `mem:obs:${sessionId}`,
|
|
5
|
+
memories: "mem:memories",
|
|
6
|
+
summaries: "mem:summaries",
|
|
7
|
+
config: "mem:config",
|
|
8
|
+
metrics: "mem:metrics",
|
|
9
|
+
health: "mem:health",
|
|
10
|
+
embeddings: (obsId) => `mem:emb:${obsId}`,
|
|
11
|
+
bm25Index: "mem:index:bm25",
|
|
12
|
+
relations: "mem:relations",
|
|
13
|
+
profiles: "mem:profiles",
|
|
14
|
+
claudeBridge: "mem:claude-bridge",
|
|
15
|
+
graphNodes: "mem:graph:nodes",
|
|
16
|
+
graphEdges: "mem:graph:edges",
|
|
17
|
+
semantic: "mem:semantic",
|
|
18
|
+
procedural: "mem:procedural",
|
|
19
|
+
teamShared: (teamId) => `mem:team:${teamId}:shared`,
|
|
20
|
+
teamUsers: (teamId, userId) => `mem:team:${teamId}:users:${userId}`,
|
|
21
|
+
teamProfile: (teamId) => `mem:team:${teamId}:profile`,
|
|
22
|
+
audit: "mem:audit",
|
|
23
|
+
actions: "mem:actions",
|
|
24
|
+
actionEdges: "mem:action-edges",
|
|
25
|
+
leases: "mem:leases",
|
|
26
|
+
routines: "mem:routines",
|
|
27
|
+
routineRuns: "mem:routine-runs",
|
|
28
|
+
signals: "mem:signals",
|
|
29
|
+
checkpoints: "mem:checkpoints",
|
|
30
|
+
mesh: "mem:mesh",
|
|
31
|
+
sketches: "mem:sketches",
|
|
32
|
+
facets: "mem:facets",
|
|
33
|
+
sentinels: "mem:sentinels",
|
|
34
|
+
crystals: "mem:crystals"
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
//#endregion
|
|
38
|
+
//#region src/state/keyed-mutex.ts
|
|
39
|
+
const locks = /* @__PURE__ */ new Map();
|
|
40
|
+
function withKeyedLock(key, fn) {
|
|
41
|
+
const next = (locks.get(key) ?? Promise.resolve()).then(fn, fn);
|
|
42
|
+
const cleanup = next.then(() => {}, () => {});
|
|
43
|
+
locks.set(key, cleanup);
|
|
44
|
+
cleanup.then(() => {
|
|
45
|
+
if (locks.get(key) === cleanup) locks.delete(key);
|
|
46
|
+
});
|
|
47
|
+
return next;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
//#endregion
|
|
51
|
+
//#region src/functions/diagnostics.ts
|
|
52
|
+
const ALL_CATEGORIES = [
|
|
53
|
+
"actions",
|
|
54
|
+
"leases",
|
|
55
|
+
"sentinels",
|
|
56
|
+
"sketches",
|
|
57
|
+
"signals",
|
|
58
|
+
"sessions",
|
|
59
|
+
"memories",
|
|
60
|
+
"mesh"
|
|
61
|
+
];
|
|
62
|
+
const TWENTY_FOUR_HOURS_MS = 1440 * 60 * 1e3;
|
|
63
|
+
const ONE_HOUR_MS = 3600 * 1e3;
|
|
64
|
+
function registerDiagnosticsFunction(sdk, kv) {
|
|
65
|
+
sdk.registerFunction({ id: "mem::diagnose" }, async (data) => {
|
|
66
|
+
const categories = data.categories && data.categories.length > 0 ? data.categories.filter((c) => ALL_CATEGORIES.includes(c)) : ALL_CATEGORIES;
|
|
67
|
+
const checks = [];
|
|
68
|
+
const now = Date.now();
|
|
69
|
+
if (categories.includes("actions")) {
|
|
70
|
+
const actions = await kv.list(KV.actions);
|
|
71
|
+
const allEdges = await kv.list(KV.actionEdges);
|
|
72
|
+
const leases = await kv.list(KV.leases);
|
|
73
|
+
const actionMap = new Map(actions.map((a) => [a.id, a]));
|
|
74
|
+
for (const action of actions) {
|
|
75
|
+
if (action.status === "active") {
|
|
76
|
+
if (!leases.some((l) => l.actionId === action.id && l.status === "active" && new Date(l.expiresAt).getTime() > now)) checks.push({
|
|
77
|
+
name: `active-no-lease:${action.id}`,
|
|
78
|
+
category: "actions",
|
|
79
|
+
status: "warn",
|
|
80
|
+
message: `Action "${action.title}" is active but has no active lease`,
|
|
81
|
+
fixable: false
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
if (action.status === "blocked") {
|
|
85
|
+
const deps = allEdges.filter((e) => e.sourceActionId === action.id && e.type === "requires");
|
|
86
|
+
if (deps.length > 0) {
|
|
87
|
+
if (deps.every((d) => {
|
|
88
|
+
const target = actionMap.get(d.targetActionId);
|
|
89
|
+
return target && target.status === "done";
|
|
90
|
+
})) checks.push({
|
|
91
|
+
name: `blocked-deps-done:${action.id}`,
|
|
92
|
+
category: "actions",
|
|
93
|
+
status: "fail",
|
|
94
|
+
message: `Action "${action.title}" is blocked but all dependencies are done`,
|
|
95
|
+
fixable: true
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (action.status === "pending") {
|
|
100
|
+
const deps = allEdges.filter((e) => e.sourceActionId === action.id && e.type === "requires");
|
|
101
|
+
if (deps.length > 0) {
|
|
102
|
+
if (deps.some((d) => {
|
|
103
|
+
const target = actionMap.get(d.targetActionId);
|
|
104
|
+
return !target || target.status !== "done";
|
|
105
|
+
})) checks.push({
|
|
106
|
+
name: `pending-unsatisfied-deps:${action.id}`,
|
|
107
|
+
category: "actions",
|
|
108
|
+
status: "fail",
|
|
109
|
+
message: `Action "${action.title}" is pending but has unsatisfied dependencies`,
|
|
110
|
+
fixable: true
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
if (!checks.some((c) => c.category === "actions" && c.status !== "pass")) checks.push({
|
|
116
|
+
name: "actions-ok",
|
|
117
|
+
category: "actions",
|
|
118
|
+
status: "pass",
|
|
119
|
+
message: `All ${actions.length} actions are consistent`,
|
|
120
|
+
fixable: false
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
if (categories.includes("leases")) {
|
|
124
|
+
const leases = await kv.list(KV.leases);
|
|
125
|
+
const actions = await kv.list(KV.actions);
|
|
126
|
+
const actionIds = new Set(actions.map((a) => a.id));
|
|
127
|
+
let leaseIssues = 0;
|
|
128
|
+
for (const lease of leases) {
|
|
129
|
+
if (lease.status === "active" && new Date(lease.expiresAt).getTime() <= now) {
|
|
130
|
+
checks.push({
|
|
131
|
+
name: `expired-lease:${lease.id}`,
|
|
132
|
+
category: "leases",
|
|
133
|
+
status: "fail",
|
|
134
|
+
message: `Lease ${lease.id} for action ${lease.actionId} expired at ${lease.expiresAt}`,
|
|
135
|
+
fixable: true
|
|
136
|
+
});
|
|
137
|
+
leaseIssues++;
|
|
138
|
+
}
|
|
139
|
+
if (!actionIds.has(lease.actionId)) {
|
|
140
|
+
checks.push({
|
|
141
|
+
name: `orphaned-lease:${lease.id}`,
|
|
142
|
+
category: "leases",
|
|
143
|
+
status: "fail",
|
|
144
|
+
message: `Lease ${lease.id} references non-existent action ${lease.actionId}`,
|
|
145
|
+
fixable: true
|
|
146
|
+
});
|
|
147
|
+
leaseIssues++;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
if (leaseIssues === 0) checks.push({
|
|
151
|
+
name: "leases-ok",
|
|
152
|
+
category: "leases",
|
|
153
|
+
status: "pass",
|
|
154
|
+
message: `All ${leases.length} leases are healthy`,
|
|
155
|
+
fixable: false
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
if (categories.includes("sentinels")) {
|
|
159
|
+
const sentinels = await kv.list(KV.sentinels);
|
|
160
|
+
const actions = await kv.list(KV.actions);
|
|
161
|
+
const actionIds = new Set(actions.map((a) => a.id));
|
|
162
|
+
let sentinelIssues = 0;
|
|
163
|
+
for (const sentinel of sentinels) {
|
|
164
|
+
if (sentinel.status === "watching" && sentinel.expiresAt && new Date(sentinel.expiresAt).getTime() <= now) {
|
|
165
|
+
checks.push({
|
|
166
|
+
name: `expired-sentinel:${sentinel.id}`,
|
|
167
|
+
category: "sentinels",
|
|
168
|
+
status: "fail",
|
|
169
|
+
message: `Sentinel "${sentinel.name}" expired at ${sentinel.expiresAt}`,
|
|
170
|
+
fixable: true
|
|
171
|
+
});
|
|
172
|
+
sentinelIssues++;
|
|
173
|
+
}
|
|
174
|
+
for (const actionId of sentinel.linkedActionIds) if (!actionIds.has(actionId)) {
|
|
175
|
+
checks.push({
|
|
176
|
+
name: `sentinel-missing-action:${sentinel.id}:${actionId}`,
|
|
177
|
+
category: "sentinels",
|
|
178
|
+
status: "warn",
|
|
179
|
+
message: `Sentinel "${sentinel.name}" references non-existent action ${actionId}`,
|
|
180
|
+
fixable: false
|
|
181
|
+
});
|
|
182
|
+
sentinelIssues++;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
if (sentinelIssues === 0) checks.push({
|
|
186
|
+
name: "sentinels-ok",
|
|
187
|
+
category: "sentinels",
|
|
188
|
+
status: "pass",
|
|
189
|
+
message: `All ${sentinels.length} sentinels are healthy`,
|
|
190
|
+
fixable: false
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
if (categories.includes("sketches")) {
|
|
194
|
+
const sketches = await kv.list(KV.sketches);
|
|
195
|
+
let sketchIssues = 0;
|
|
196
|
+
for (const sketch of sketches) if (sketch.status === "active" && new Date(sketch.expiresAt).getTime() <= now) {
|
|
197
|
+
checks.push({
|
|
198
|
+
name: `expired-sketch:${sketch.id}`,
|
|
199
|
+
category: "sketches",
|
|
200
|
+
status: "fail",
|
|
201
|
+
message: `Sketch "${sketch.title}" expired at ${sketch.expiresAt}`,
|
|
202
|
+
fixable: true
|
|
203
|
+
});
|
|
204
|
+
sketchIssues++;
|
|
205
|
+
}
|
|
206
|
+
if (sketchIssues === 0) checks.push({
|
|
207
|
+
name: "sketches-ok",
|
|
208
|
+
category: "sketches",
|
|
209
|
+
status: "pass",
|
|
210
|
+
message: `All ${sketches.length} sketches are healthy`,
|
|
211
|
+
fixable: false
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
if (categories.includes("signals")) {
|
|
215
|
+
const signals = await kv.list(KV.signals);
|
|
216
|
+
let signalIssues = 0;
|
|
217
|
+
for (const signal of signals) if (signal.expiresAt && new Date(signal.expiresAt).getTime() <= now) {
|
|
218
|
+
checks.push({
|
|
219
|
+
name: `expired-signal:${signal.id}`,
|
|
220
|
+
category: "signals",
|
|
221
|
+
status: "fail",
|
|
222
|
+
message: `Signal from "${signal.from}" expired at ${signal.expiresAt}`,
|
|
223
|
+
fixable: true
|
|
224
|
+
});
|
|
225
|
+
signalIssues++;
|
|
226
|
+
}
|
|
227
|
+
if (signalIssues === 0) checks.push({
|
|
228
|
+
name: "signals-ok",
|
|
229
|
+
category: "signals",
|
|
230
|
+
status: "pass",
|
|
231
|
+
message: `All ${signals.length} signals are healthy`,
|
|
232
|
+
fixable: false
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
if (categories.includes("sessions")) {
|
|
236
|
+
const sessions = await kv.list(KV.sessions);
|
|
237
|
+
let sessionIssues = 0;
|
|
238
|
+
for (const session of sessions) if (session.status === "active" && now - new Date(session.startedAt).getTime() > TWENTY_FOUR_HOURS_MS) {
|
|
239
|
+
checks.push({
|
|
240
|
+
name: `abandoned-session:${session.id}`,
|
|
241
|
+
category: "sessions",
|
|
242
|
+
status: "warn",
|
|
243
|
+
message: `Session ${session.id} has been active for over 24 hours`,
|
|
244
|
+
fixable: false
|
|
245
|
+
});
|
|
246
|
+
sessionIssues++;
|
|
247
|
+
}
|
|
248
|
+
if (sessionIssues === 0) checks.push({
|
|
249
|
+
name: "sessions-ok",
|
|
250
|
+
category: "sessions",
|
|
251
|
+
status: "pass",
|
|
252
|
+
message: `All ${sessions.length} sessions are healthy`,
|
|
253
|
+
fixable: false
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
if (categories.includes("memories")) {
|
|
257
|
+
const memories = await kv.list(KV.memories);
|
|
258
|
+
const memoryIds = new Set(memories.map((m) => m.id));
|
|
259
|
+
const supersededBy = /* @__PURE__ */ new Map();
|
|
260
|
+
let memoryIssues = 0;
|
|
261
|
+
for (const memory of memories) if (memory.supersedes && memory.supersedes.length > 0) for (const sid of memory.supersedes) {
|
|
262
|
+
if (!memoryIds.has(sid)) {
|
|
263
|
+
checks.push({
|
|
264
|
+
name: `memory-missing-supersedes:${memory.id}:${sid}`,
|
|
265
|
+
category: "memories",
|
|
266
|
+
status: "warn",
|
|
267
|
+
message: `Memory "${memory.title}" supersedes non-existent memory ${sid}`,
|
|
268
|
+
fixable: false
|
|
269
|
+
});
|
|
270
|
+
memoryIssues++;
|
|
271
|
+
}
|
|
272
|
+
supersededBy.set(sid, memory.id);
|
|
273
|
+
}
|
|
274
|
+
for (const memory of memories) if (memory.isLatest && supersededBy.has(memory.id)) {
|
|
275
|
+
checks.push({
|
|
276
|
+
name: `memory-stale-latest:${memory.id}`,
|
|
277
|
+
category: "memories",
|
|
278
|
+
status: "fail",
|
|
279
|
+
message: `Memory "${memory.title}" has isLatest=true but is superseded by ${supersededBy.get(memory.id)}`,
|
|
280
|
+
fixable: true
|
|
281
|
+
});
|
|
282
|
+
memoryIssues++;
|
|
283
|
+
}
|
|
284
|
+
if (memoryIssues === 0) checks.push({
|
|
285
|
+
name: "memories-ok",
|
|
286
|
+
category: "memories",
|
|
287
|
+
status: "pass",
|
|
288
|
+
message: `All ${memories.length} memories are consistent`,
|
|
289
|
+
fixable: false
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
if (categories.includes("mesh")) {
|
|
293
|
+
const peers = await kv.list(KV.mesh);
|
|
294
|
+
let meshIssues = 0;
|
|
295
|
+
for (const peer of peers) {
|
|
296
|
+
if (peer.lastSyncAt && now - new Date(peer.lastSyncAt).getTime() > ONE_HOUR_MS) {
|
|
297
|
+
checks.push({
|
|
298
|
+
name: `stale-peer:${peer.id}`,
|
|
299
|
+
category: "mesh",
|
|
300
|
+
status: "warn",
|
|
301
|
+
message: `Peer "${peer.name}" last synced over 1 hour ago`,
|
|
302
|
+
fixable: false
|
|
303
|
+
});
|
|
304
|
+
meshIssues++;
|
|
305
|
+
}
|
|
306
|
+
if (peer.status === "error") {
|
|
307
|
+
checks.push({
|
|
308
|
+
name: `error-peer:${peer.id}`,
|
|
309
|
+
category: "mesh",
|
|
310
|
+
status: "warn",
|
|
311
|
+
message: `Peer "${peer.name}" is in error state`,
|
|
312
|
+
fixable: false
|
|
313
|
+
});
|
|
314
|
+
meshIssues++;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
if (meshIssues === 0) checks.push({
|
|
318
|
+
name: "mesh-ok",
|
|
319
|
+
category: "mesh",
|
|
320
|
+
status: "pass",
|
|
321
|
+
message: `All ${peers.length} mesh peers are healthy`,
|
|
322
|
+
fixable: false
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
return {
|
|
326
|
+
success: true,
|
|
327
|
+
checks,
|
|
328
|
+
summary: {
|
|
329
|
+
pass: checks.filter((c) => c.status === "pass").length,
|
|
330
|
+
warn: checks.filter((c) => c.status === "warn").length,
|
|
331
|
+
fail: checks.filter((c) => c.status === "fail").length,
|
|
332
|
+
fixable: checks.filter((c) => c.fixable).length
|
|
333
|
+
}
|
|
334
|
+
};
|
|
335
|
+
});
|
|
336
|
+
sdk.registerFunction({ id: "mem::heal" }, async (data) => {
|
|
337
|
+
const dryRun = data.dryRun ?? false;
|
|
338
|
+
const categories = data.categories && data.categories.length > 0 ? data.categories.filter((c) => ALL_CATEGORIES.includes(c)) : ALL_CATEGORIES;
|
|
339
|
+
let fixed = 0;
|
|
340
|
+
let skipped = 0;
|
|
341
|
+
const details = [];
|
|
342
|
+
const now = Date.now();
|
|
343
|
+
if (categories.includes("actions")) {
|
|
344
|
+
const actions = await kv.list(KV.actions);
|
|
345
|
+
const allEdges = await kv.list(KV.actionEdges);
|
|
346
|
+
const actionMap = new Map(actions.map((a) => [a.id, a]));
|
|
347
|
+
for (const action of actions) {
|
|
348
|
+
if (action.status === "blocked") {
|
|
349
|
+
const deps = allEdges.filter((e) => e.sourceActionId === action.id && e.type === "requires");
|
|
350
|
+
if (deps.length > 0) {
|
|
351
|
+
if (deps.every((d) => {
|
|
352
|
+
const target = actionMap.get(d.targetActionId);
|
|
353
|
+
return target && target.status === "done";
|
|
354
|
+
})) {
|
|
355
|
+
if (dryRun) {
|
|
356
|
+
details.push(`[dry-run] Would unblock action "${action.title}" (${action.id})`);
|
|
357
|
+
fixed++;
|
|
358
|
+
continue;
|
|
359
|
+
}
|
|
360
|
+
if (await withKeyedLock(`mem:action:${action.id}`, async () => {
|
|
361
|
+
const fresh = await kv.get(KV.actions, action.id);
|
|
362
|
+
if (!fresh || fresh.status !== "blocked") return false;
|
|
363
|
+
const freshDeps = (await kv.list(KV.actionEdges)).filter((e) => e.sourceActionId === fresh.id && e.type === "requires");
|
|
364
|
+
const freshActions = await kv.list(KV.actions);
|
|
365
|
+
const freshMap = new Map(freshActions.map((a) => [a.id, a]));
|
|
366
|
+
if (!freshDeps.every((d) => {
|
|
367
|
+
const target = freshMap.get(d.targetActionId);
|
|
368
|
+
return target && target.status === "done";
|
|
369
|
+
})) return false;
|
|
370
|
+
fresh.status = "pending";
|
|
371
|
+
fresh.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
372
|
+
await kv.set(KV.actions, fresh.id, fresh);
|
|
373
|
+
return true;
|
|
374
|
+
})) {
|
|
375
|
+
details.push(`Unblocked action "${action.title}" (${action.id})`);
|
|
376
|
+
fixed++;
|
|
377
|
+
} else skipped++;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
if (action.status === "pending") {
|
|
382
|
+
const deps = allEdges.filter((e) => e.sourceActionId === action.id && e.type === "requires");
|
|
383
|
+
if (deps.length > 0) {
|
|
384
|
+
if (deps.some((d) => {
|
|
385
|
+
const target = actionMap.get(d.targetActionId);
|
|
386
|
+
return !target || target.status !== "done";
|
|
387
|
+
})) {
|
|
388
|
+
if (dryRun) {
|
|
389
|
+
details.push(`[dry-run] Would block action "${action.title}" (${action.id})`);
|
|
390
|
+
fixed++;
|
|
391
|
+
continue;
|
|
392
|
+
}
|
|
393
|
+
if (await withKeyedLock(`mem:action:${action.id}`, async () => {
|
|
394
|
+
const fresh = await kv.get(KV.actions, action.id);
|
|
395
|
+
if (!fresh || fresh.status !== "pending") return false;
|
|
396
|
+
const freshDeps = (await kv.list(KV.actionEdges)).filter((e) => e.sourceActionId === fresh.id && e.type === "requires");
|
|
397
|
+
const freshActions = await kv.list(KV.actions);
|
|
398
|
+
const freshMap = new Map(freshActions.map((a) => [a.id, a]));
|
|
399
|
+
if (!freshDeps.some((d) => {
|
|
400
|
+
const target = freshMap.get(d.targetActionId);
|
|
401
|
+
return !target || target.status !== "done";
|
|
402
|
+
})) return false;
|
|
403
|
+
fresh.status = "blocked";
|
|
404
|
+
fresh.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
405
|
+
await kv.set(KV.actions, fresh.id, fresh);
|
|
406
|
+
return true;
|
|
407
|
+
})) {
|
|
408
|
+
details.push(`Blocked action "${action.title}" (${action.id})`);
|
|
409
|
+
fixed++;
|
|
410
|
+
} else skipped++;
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
if (categories.includes("leases")) {
|
|
417
|
+
const leases = await kv.list(KV.leases);
|
|
418
|
+
const actions = await kv.list(KV.actions);
|
|
419
|
+
const actionIds = new Set(actions.map((a) => a.id));
|
|
420
|
+
for (const lease of leases) {
|
|
421
|
+
if (lease.status === "active" && new Date(lease.expiresAt).getTime() <= now) {
|
|
422
|
+
if (dryRun) {
|
|
423
|
+
details.push(`[dry-run] Would expire lease ${lease.id} for action ${lease.actionId}`);
|
|
424
|
+
fixed++;
|
|
425
|
+
continue;
|
|
426
|
+
}
|
|
427
|
+
if (await withKeyedLock(`mem:action:${lease.actionId}`, async () => {
|
|
428
|
+
const fresh = await kv.get(KV.leases, lease.id);
|
|
429
|
+
if (!fresh || fresh.status !== "active" || new Date(fresh.expiresAt).getTime() > Date.now()) return false;
|
|
430
|
+
fresh.status = "expired";
|
|
431
|
+
await kv.set(KV.leases, fresh.id, fresh);
|
|
432
|
+
const action = await kv.get(KV.actions, fresh.actionId);
|
|
433
|
+
if (action && action.status === "active" && action.assignedTo === fresh.agentId) {
|
|
434
|
+
action.status = "pending";
|
|
435
|
+
action.assignedTo = void 0;
|
|
436
|
+
action.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
437
|
+
await kv.set(KV.actions, action.id, action);
|
|
438
|
+
}
|
|
439
|
+
return true;
|
|
440
|
+
})) {
|
|
441
|
+
details.push(`Expired lease ${lease.id} for action ${lease.actionId}`);
|
|
442
|
+
fixed++;
|
|
443
|
+
} else skipped++;
|
|
444
|
+
continue;
|
|
445
|
+
}
|
|
446
|
+
if (!actionIds.has(lease.actionId)) {
|
|
447
|
+
if (dryRun) {
|
|
448
|
+
details.push(`[dry-run] Would delete orphaned lease ${lease.id}`);
|
|
449
|
+
fixed++;
|
|
450
|
+
continue;
|
|
451
|
+
}
|
|
452
|
+
await kv.delete(KV.leases, lease.id);
|
|
453
|
+
details.push(`Deleted orphaned lease ${lease.id}`);
|
|
454
|
+
fixed++;
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
if (categories.includes("sentinels")) {
|
|
459
|
+
const sentinels = await kv.list(KV.sentinels);
|
|
460
|
+
for (const sentinel of sentinels) if (sentinel.status === "watching" && sentinel.expiresAt && new Date(sentinel.expiresAt).getTime() <= now) {
|
|
461
|
+
if (dryRun) {
|
|
462
|
+
details.push(`[dry-run] Would expire sentinel "${sentinel.name}" (${sentinel.id})`);
|
|
463
|
+
fixed++;
|
|
464
|
+
continue;
|
|
465
|
+
}
|
|
466
|
+
if (await withKeyedLock(`mem:sentinel:${sentinel.id}`, async () => {
|
|
467
|
+
const fresh = await kv.get(KV.sentinels, sentinel.id);
|
|
468
|
+
if (!fresh || fresh.status !== "watching") return false;
|
|
469
|
+
if (!fresh.expiresAt || new Date(fresh.expiresAt).getTime() > Date.now()) return false;
|
|
470
|
+
fresh.status = "expired";
|
|
471
|
+
await kv.set(KV.sentinels, fresh.id, fresh);
|
|
472
|
+
return true;
|
|
473
|
+
})) {
|
|
474
|
+
details.push(`Expired sentinel "${sentinel.name}" (${sentinel.id})`);
|
|
475
|
+
fixed++;
|
|
476
|
+
} else skipped++;
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
if (categories.includes("sketches")) {
|
|
480
|
+
const sketches = await kv.list(KV.sketches);
|
|
481
|
+
for (const sketch of sketches) if (sketch.status === "active" && new Date(sketch.expiresAt).getTime() <= now) {
|
|
482
|
+
if (dryRun) {
|
|
483
|
+
details.push(`[dry-run] Would discard expired sketch "${sketch.title}" (${sketch.id})`);
|
|
484
|
+
fixed++;
|
|
485
|
+
continue;
|
|
486
|
+
}
|
|
487
|
+
if (await withKeyedLock(`mem:sketch:${sketch.id}`, async () => {
|
|
488
|
+
const fresh = await kv.get(KV.sketches, sketch.id);
|
|
489
|
+
if (!fresh || fresh.status !== "active" || new Date(fresh.expiresAt).getTime() > Date.now()) return false;
|
|
490
|
+
const allEdges = await kv.list(KV.actionEdges);
|
|
491
|
+
const actionIdSet = new Set(fresh.actionIds);
|
|
492
|
+
for (const edge of allEdges) if (actionIdSet.has(edge.sourceActionId) || actionIdSet.has(edge.targetActionId)) await kv.delete(KV.actionEdges, edge.id);
|
|
493
|
+
for (const actionId of fresh.actionIds) await kv.delete(KV.actions, actionId);
|
|
494
|
+
fresh.status = "discarded";
|
|
495
|
+
fresh.discardedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
496
|
+
await kv.set(KV.sketches, fresh.id, fresh);
|
|
497
|
+
return true;
|
|
498
|
+
})) {
|
|
499
|
+
details.push(`Discarded expired sketch "${sketch.title}" (${sketch.id})`);
|
|
500
|
+
fixed++;
|
|
501
|
+
} else skipped++;
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
if (categories.includes("signals")) {
|
|
505
|
+
const signals = await kv.list(KV.signals);
|
|
506
|
+
for (const signal of signals) if (signal.expiresAt && new Date(signal.expiresAt).getTime() <= now) {
|
|
507
|
+
if (dryRun) {
|
|
508
|
+
details.push(`[dry-run] Would delete expired signal ${signal.id}`);
|
|
509
|
+
fixed++;
|
|
510
|
+
continue;
|
|
511
|
+
}
|
|
512
|
+
await kv.delete(KV.signals, signal.id);
|
|
513
|
+
details.push(`Deleted expired signal ${signal.id}`);
|
|
514
|
+
fixed++;
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
if (categories.includes("memories")) {
|
|
518
|
+
const memories = await kv.list(KV.memories);
|
|
519
|
+
const supersededBy = /* @__PURE__ */ new Map();
|
|
520
|
+
for (const memory of memories) if (memory.supersedes && memory.supersedes.length > 0) for (const sid of memory.supersedes) supersededBy.set(sid, memory.id);
|
|
521
|
+
for (const memory of memories) if (memory.isLatest && supersededBy.has(memory.id)) {
|
|
522
|
+
if (dryRun) {
|
|
523
|
+
details.push(`[dry-run] Would set isLatest=false on memory "${memory.title}" (${memory.id})`);
|
|
524
|
+
fixed++;
|
|
525
|
+
continue;
|
|
526
|
+
}
|
|
527
|
+
if (await withKeyedLock(`mem:memory:${memory.id}`, async () => {
|
|
528
|
+
const fresh = await kv.get(KV.memories, memory.id);
|
|
529
|
+
if (!fresh || !fresh.isLatest) return false;
|
|
530
|
+
fresh.isLatest = false;
|
|
531
|
+
fresh.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
532
|
+
await kv.set(KV.memories, fresh.id, fresh);
|
|
533
|
+
return true;
|
|
534
|
+
})) {
|
|
535
|
+
details.push(`Set isLatest=false on memory "${memory.title}" (${memory.id})`);
|
|
536
|
+
fixed++;
|
|
537
|
+
} else skipped++;
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
return {
|
|
541
|
+
success: true,
|
|
542
|
+
fixed,
|
|
543
|
+
skipped,
|
|
544
|
+
details
|
|
545
|
+
};
|
|
546
|
+
});
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
//#endregion
|
|
550
|
+
export { registerDiagnosticsFunction };
|
|
551
|
+
//# sourceMappingURL=diagnostics.mjs.map
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
//#region src/hooks/notification.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
|
+
if (data.notification_type !== "permission_prompt") return;
|
|
20
|
+
const sessionId = data.session_id || "unknown";
|
|
21
|
+
try {
|
|
22
|
+
await fetch(`${REST_URL}/agentmemory/observe`, {
|
|
23
|
+
method: "POST",
|
|
24
|
+
headers: authHeaders(),
|
|
25
|
+
body: JSON.stringify({
|
|
26
|
+
hookType: "notification",
|
|
27
|
+
sessionId,
|
|
28
|
+
project: data.cwd || process.cwd(),
|
|
29
|
+
cwd: data.cwd || process.cwd(),
|
|
30
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
31
|
+
data: {
|
|
32
|
+
notification_type: data.notification_type,
|
|
33
|
+
title: data.title,
|
|
34
|
+
message: data.message
|
|
35
|
+
}
|
|
36
|
+
}),
|
|
37
|
+
signal: AbortSignal.timeout(2e3)
|
|
38
|
+
});
|
|
39
|
+
} catch {}
|
|
40
|
+
}
|
|
41
|
+
main();
|
|
42
|
+
|
|
43
|
+
//#endregion
|
|
44
|
+
export { };
|
|
45
|
+
//# sourceMappingURL=notification.mjs.map
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
//#region src/hooks/post-tool-failure.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
|
+
if (data.is_interrupt) return;
|
|
20
|
+
const sessionId = data.session_id || "unknown";
|
|
21
|
+
try {
|
|
22
|
+
await fetch(`${REST_URL}/agentmemory/observe`, {
|
|
23
|
+
method: "POST",
|
|
24
|
+
headers: authHeaders(),
|
|
25
|
+
body: JSON.stringify({
|
|
26
|
+
hookType: "post_tool_failure",
|
|
27
|
+
sessionId,
|
|
28
|
+
project: data.cwd || process.cwd(),
|
|
29
|
+
cwd: data.cwd || process.cwd(),
|
|
30
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
31
|
+
data: {
|
|
32
|
+
tool_name: data.tool_name,
|
|
33
|
+
tool_input: typeof data.tool_input === "string" ? data.tool_input.slice(0, 4e3) : JSON.stringify(data.tool_input ?? "").slice(0, 4e3),
|
|
34
|
+
error: typeof data.error === "string" ? data.error.slice(0, 4e3) : JSON.stringify(data.error ?? "").slice(0, 4e3)
|
|
35
|
+
}
|
|
36
|
+
}),
|
|
37
|
+
signal: AbortSignal.timeout(3e3)
|
|
38
|
+
});
|
|
39
|
+
} catch {}
|
|
40
|
+
}
|
|
41
|
+
main();
|
|
42
|
+
|
|
43
|
+
//#endregion
|
|
44
|
+
export { };
|
|
45
|
+
//# sourceMappingURL=post-tool-failure.mjs.map
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
//#region src/hooks/post-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 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: "post_tool_use",
|
|
26
|
+
sessionId,
|
|
27
|
+
project: data.cwd || process.cwd(),
|
|
28
|
+
cwd: data.cwd || process.cwd(),
|
|
29
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
30
|
+
data: {
|
|
31
|
+
tool_name: data.tool_name,
|
|
32
|
+
tool_input: data.tool_input,
|
|
33
|
+
tool_output: truncate(data.tool_output, 8e3)
|
|
34
|
+
}
|
|
35
|
+
}),
|
|
36
|
+
signal: AbortSignal.timeout(3e3)
|
|
37
|
+
});
|
|
38
|
+
} catch {}
|
|
39
|
+
}
|
|
40
|
+
function truncate(value, max) {
|
|
41
|
+
if (typeof value === "string" && value.length > max) return value.slice(0, max) + "\n[...truncated]";
|
|
42
|
+
if (typeof value === "object" && value !== null) {
|
|
43
|
+
const str = JSON.stringify(value);
|
|
44
|
+
if (str.length > max) return str.slice(0, max) + "...[truncated]";
|
|
45
|
+
return value;
|
|
46
|
+
}
|
|
47
|
+
return value;
|
|
48
|
+
}
|
|
49
|
+
main();
|
|
50
|
+
|
|
51
|
+
//#endregion
|
|
52
|
+
export { };
|
|
53
|
+
//# sourceMappingURL=post-tool-use.mjs.map
|