@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,93 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { FallbackChainProvider } from "../src/providers/fallback-chain.js";
|
|
3
|
+
import type { MemoryProvider } from "../src/types.js";
|
|
4
|
+
|
|
5
|
+
function makeProvider(
|
|
6
|
+
name: string,
|
|
7
|
+
impl?: Partial<MemoryProvider>,
|
|
8
|
+
): MemoryProvider {
|
|
9
|
+
return {
|
|
10
|
+
name,
|
|
11
|
+
compress: impl?.compress ?? (async () => `compressed by ${name}`),
|
|
12
|
+
summarize: impl?.summarize ?? (async () => `summarized by ${name}`),
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
describe("FallbackChainProvider", () => {
|
|
17
|
+
it("returns result from first provider when it succeeds", async () => {
|
|
18
|
+
const chain = new FallbackChainProvider([
|
|
19
|
+
makeProvider("primary"),
|
|
20
|
+
makeProvider("secondary"),
|
|
21
|
+
]);
|
|
22
|
+
const result = await chain.compress("sys", "user");
|
|
23
|
+
expect(result).toBe("compressed by primary");
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("falls back to second provider when first fails", async () => {
|
|
27
|
+
const failing: MemoryProvider = {
|
|
28
|
+
name: "failing",
|
|
29
|
+
compress: async () => {
|
|
30
|
+
throw new Error("primary down");
|
|
31
|
+
},
|
|
32
|
+
summarize: async () => {
|
|
33
|
+
throw new Error("primary down");
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
const chain = new FallbackChainProvider([
|
|
37
|
+
failing,
|
|
38
|
+
makeProvider("backup"),
|
|
39
|
+
]);
|
|
40
|
+
const result = await chain.compress("sys", "user");
|
|
41
|
+
expect(result).toBe("compressed by backup");
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("throws the last error when all providers fail", async () => {
|
|
45
|
+
const failing1: MemoryProvider = {
|
|
46
|
+
name: "fail1",
|
|
47
|
+
compress: async () => {
|
|
48
|
+
throw new Error("fail1 error");
|
|
49
|
+
},
|
|
50
|
+
summarize: async () => {
|
|
51
|
+
throw new Error("fail1 error");
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
const failing2: MemoryProvider = {
|
|
55
|
+
name: "fail2",
|
|
56
|
+
compress: async () => {
|
|
57
|
+
throw new Error("fail2 error");
|
|
58
|
+
},
|
|
59
|
+
summarize: async () => {
|
|
60
|
+
throw new Error("fail2 error");
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
const chain = new FallbackChainProvider([failing1, failing2]);
|
|
64
|
+
await expect(chain.compress("sys", "user")).rejects.toThrow("fail2 error");
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("formats the name correctly", () => {
|
|
68
|
+
const chain = new FallbackChainProvider([
|
|
69
|
+
makeProvider("anthropic"),
|
|
70
|
+
makeProvider("gemini"),
|
|
71
|
+
makeProvider("openrouter"),
|
|
72
|
+
]);
|
|
73
|
+
expect(chain.name).toBe("fallback(anthropic -> gemini -> openrouter)");
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it("summarize also uses fallback chain", async () => {
|
|
77
|
+
const failing: MemoryProvider = {
|
|
78
|
+
name: "failing",
|
|
79
|
+
compress: async () => {
|
|
80
|
+
throw new Error("down");
|
|
81
|
+
},
|
|
82
|
+
summarize: async () => {
|
|
83
|
+
throw new Error("down");
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
const chain = new FallbackChainProvider([
|
|
87
|
+
failing,
|
|
88
|
+
makeProvider("backup"),
|
|
89
|
+
]);
|
|
90
|
+
const result = await chain.summarize("sys", "user");
|
|
91
|
+
expect(result).toBe("summarized by backup");
|
|
92
|
+
});
|
|
93
|
+
});
|
|
@@ -0,0 +1,485 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach, vi } from "vitest";
|
|
2
|
+
|
|
3
|
+
vi.mock("iii-sdk", () => ({
|
|
4
|
+
getContext: () => ({
|
|
5
|
+
logger: { info: vi.fn(), error: vi.fn(), warn: vi.fn() },
|
|
6
|
+
}),
|
|
7
|
+
}));
|
|
8
|
+
|
|
9
|
+
import { registerFrontierFunction } from "../src/functions/frontier.js";
|
|
10
|
+
import { registerActionsFunction } from "../src/functions/actions.js";
|
|
11
|
+
import type { Action, ActionEdge, Checkpoint, Lease } from "../src/types.js";
|
|
12
|
+
import type { FrontierItem } from "../src/functions/frontier.js";
|
|
13
|
+
|
|
14
|
+
function mockKV() {
|
|
15
|
+
const store = new Map<string, Map<string, unknown>>();
|
|
16
|
+
return {
|
|
17
|
+
get: async <T>(scope: string, key: string): Promise<T | null> => {
|
|
18
|
+
return (store.get(scope)?.get(key) as T) ?? null;
|
|
19
|
+
},
|
|
20
|
+
set: async <T>(scope: string, key: string, data: T): Promise<T> => {
|
|
21
|
+
if (!store.has(scope)) store.set(scope, new Map());
|
|
22
|
+
store.get(scope)!.set(key, data);
|
|
23
|
+
return data;
|
|
24
|
+
},
|
|
25
|
+
delete: async (scope: string, key: string): Promise<void> => {
|
|
26
|
+
store.get(scope)?.delete(key);
|
|
27
|
+
},
|
|
28
|
+
list: async <T>(scope: string): Promise<T[]> => {
|
|
29
|
+
const entries = store.get(scope);
|
|
30
|
+
return entries ? (Array.from(entries.values()) as T[]) : [];
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function mockSdk() {
|
|
36
|
+
const functions = new Map<string, Function>();
|
|
37
|
+
return {
|
|
38
|
+
registerFunction: (opts: { id: string }, handler: Function) => {
|
|
39
|
+
functions.set(opts.id, handler);
|
|
40
|
+
},
|
|
41
|
+
registerTrigger: () => {},
|
|
42
|
+
trigger: async (id: string, data: unknown) => {
|
|
43
|
+
const fn = functions.get(id);
|
|
44
|
+
if (!fn) throw new Error(`No function: ${id}`);
|
|
45
|
+
return fn(data);
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function makeAction(overrides: Partial<Action>): Action {
|
|
51
|
+
const now = new Date().toISOString();
|
|
52
|
+
return {
|
|
53
|
+
id: overrides.id || `act_${Math.random().toString(36).slice(2, 10)}`,
|
|
54
|
+
title: overrides.title || "Test action",
|
|
55
|
+
description: overrides.description || "",
|
|
56
|
+
status: overrides.status || "pending",
|
|
57
|
+
priority: overrides.priority || 5,
|
|
58
|
+
createdAt: overrides.createdAt || now,
|
|
59
|
+
updatedAt: overrides.updatedAt || now,
|
|
60
|
+
createdBy: overrides.createdBy || "agent-1",
|
|
61
|
+
assignedTo: overrides.assignedTo,
|
|
62
|
+
project: overrides.project,
|
|
63
|
+
tags: overrides.tags || [],
|
|
64
|
+
sourceObservationIds: overrides.sourceObservationIds || [],
|
|
65
|
+
sourceMemoryIds: overrides.sourceMemoryIds || [],
|
|
66
|
+
result: overrides.result,
|
|
67
|
+
parentId: overrides.parentId,
|
|
68
|
+
metadata: overrides.metadata,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
describe("Frontier Functions", () => {
|
|
73
|
+
let sdk: ReturnType<typeof mockSdk>;
|
|
74
|
+
let kv: ReturnType<typeof mockKV>;
|
|
75
|
+
|
|
76
|
+
beforeEach(() => {
|
|
77
|
+
sdk = mockSdk();
|
|
78
|
+
kv = mockKV();
|
|
79
|
+
registerActionsFunction(sdk as never, kv as never);
|
|
80
|
+
registerFrontierFunction(sdk as never, kv as never);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
describe("mem::frontier", () => {
|
|
84
|
+
it("returns empty frontier when no actions exist", async () => {
|
|
85
|
+
const result = (await sdk.trigger("mem::frontier", {})) as {
|
|
86
|
+
success: boolean;
|
|
87
|
+
frontier: FrontierItem[];
|
|
88
|
+
totalActions: number;
|
|
89
|
+
totalUnblocked: number;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
expect(result.success).toBe(true);
|
|
93
|
+
expect(result.frontier).toEqual([]);
|
|
94
|
+
expect(result.totalActions).toBe(0);
|
|
95
|
+
expect(result.totalUnblocked).toBe(0);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it("returns pending actions sorted by score", async () => {
|
|
99
|
+
const lowPriority = makeAction({
|
|
100
|
+
id: "act_low",
|
|
101
|
+
title: "Low priority",
|
|
102
|
+
priority: 2,
|
|
103
|
+
});
|
|
104
|
+
const highPriority = makeAction({
|
|
105
|
+
id: "act_high",
|
|
106
|
+
title: "High priority",
|
|
107
|
+
priority: 9,
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
await kv.set("mem:actions", lowPriority.id, lowPriority);
|
|
111
|
+
await kv.set("mem:actions", highPriority.id, highPriority);
|
|
112
|
+
|
|
113
|
+
const result = (await sdk.trigger("mem::frontier", {})) as {
|
|
114
|
+
success: boolean;
|
|
115
|
+
frontier: FrontierItem[];
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
expect(result.success).toBe(true);
|
|
119
|
+
expect(result.frontier.length).toBe(2);
|
|
120
|
+
expect(result.frontier[0].action.id).toBe("act_high");
|
|
121
|
+
expect(result.frontier[1].action.id).toBe("act_low");
|
|
122
|
+
expect(result.frontier[0].score).toBeGreaterThan(
|
|
123
|
+
result.frontier[1].score,
|
|
124
|
+
);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it("excludes done and cancelled actions", async () => {
|
|
128
|
+
const pending = makeAction({
|
|
129
|
+
id: "act_pending",
|
|
130
|
+
title: "Pending",
|
|
131
|
+
status: "pending",
|
|
132
|
+
});
|
|
133
|
+
const done = makeAction({
|
|
134
|
+
id: "act_done",
|
|
135
|
+
title: "Done",
|
|
136
|
+
status: "done",
|
|
137
|
+
});
|
|
138
|
+
const cancelled = makeAction({
|
|
139
|
+
id: "act_cancelled",
|
|
140
|
+
title: "Cancelled",
|
|
141
|
+
status: "cancelled",
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
await kv.set("mem:actions", pending.id, pending);
|
|
145
|
+
await kv.set("mem:actions", done.id, done);
|
|
146
|
+
await kv.set("mem:actions", cancelled.id, cancelled);
|
|
147
|
+
|
|
148
|
+
const result = (await sdk.trigger("mem::frontier", {})) as {
|
|
149
|
+
success: boolean;
|
|
150
|
+
frontier: FrontierItem[];
|
|
151
|
+
totalActions: number;
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
expect(result.success).toBe(true);
|
|
155
|
+
expect(result.frontier.length).toBe(1);
|
|
156
|
+
expect(result.frontier[0].action.id).toBe("act_pending");
|
|
157
|
+
expect(result.totalActions).toBe(3);
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it("excludes blocked actions with unsatisfied requires edge", async () => {
|
|
161
|
+
const dependency = makeAction({
|
|
162
|
+
id: "act_dep",
|
|
163
|
+
title: "Dependency",
|
|
164
|
+
status: "pending",
|
|
165
|
+
});
|
|
166
|
+
const blocked = makeAction({
|
|
167
|
+
id: "act_blocked",
|
|
168
|
+
title: "Blocked",
|
|
169
|
+
status: "blocked",
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
await kv.set("mem:actions", dependency.id, dependency);
|
|
173
|
+
await kv.set("mem:actions", blocked.id, blocked);
|
|
174
|
+
|
|
175
|
+
const edge: ActionEdge = {
|
|
176
|
+
id: "ae_1",
|
|
177
|
+
type: "requires",
|
|
178
|
+
sourceActionId: blocked.id,
|
|
179
|
+
targetActionId: dependency.id,
|
|
180
|
+
createdAt: new Date().toISOString(),
|
|
181
|
+
};
|
|
182
|
+
await kv.set("mem:action-edges", edge.id, edge);
|
|
183
|
+
|
|
184
|
+
const result = (await sdk.trigger("mem::frontier", {})) as {
|
|
185
|
+
success: boolean;
|
|
186
|
+
frontier: FrontierItem[];
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
expect(result.success).toBe(true);
|
|
190
|
+
const ids = result.frontier.map((f) => f.action.id);
|
|
191
|
+
expect(ids).toContain("act_dep");
|
|
192
|
+
expect(ids).not.toContain("act_blocked");
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
it("respects project filter", async () => {
|
|
196
|
+
const alphaAction = makeAction({
|
|
197
|
+
id: "act_alpha",
|
|
198
|
+
title: "Alpha task",
|
|
199
|
+
project: "alpha",
|
|
200
|
+
});
|
|
201
|
+
const betaAction = makeAction({
|
|
202
|
+
id: "act_beta",
|
|
203
|
+
title: "Beta task",
|
|
204
|
+
project: "beta",
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
await kv.set("mem:actions", alphaAction.id, alphaAction);
|
|
208
|
+
await kv.set("mem:actions", betaAction.id, betaAction);
|
|
209
|
+
|
|
210
|
+
const result = (await sdk.trigger("mem::frontier", {
|
|
211
|
+
project: "alpha",
|
|
212
|
+
})) as { success: boolean; frontier: FrontierItem[] };
|
|
213
|
+
|
|
214
|
+
expect(result.success).toBe(true);
|
|
215
|
+
expect(result.frontier.length).toBe(1);
|
|
216
|
+
expect(result.frontier[0].action.project).toBe("alpha");
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
it("higher priority scores higher", async () => {
|
|
220
|
+
const low = makeAction({
|
|
221
|
+
id: "act_low",
|
|
222
|
+
title: "Low",
|
|
223
|
+
priority: 1,
|
|
224
|
+
createdAt: new Date().toISOString(),
|
|
225
|
+
});
|
|
226
|
+
const high = makeAction({
|
|
227
|
+
id: "act_high",
|
|
228
|
+
title: "High",
|
|
229
|
+
priority: 10,
|
|
230
|
+
createdAt: new Date().toISOString(),
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
await kv.set("mem:actions", low.id, low);
|
|
234
|
+
await kv.set("mem:actions", high.id, high);
|
|
235
|
+
|
|
236
|
+
const result = (await sdk.trigger("mem::frontier", {})) as {
|
|
237
|
+
success: boolean;
|
|
238
|
+
frontier: FrontierItem[];
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
expect(result.frontier[0].action.id).toBe("act_high");
|
|
242
|
+
expect(result.frontier[0].score).toBeGreaterThan(
|
|
243
|
+
result.frontier[1].score,
|
|
244
|
+
);
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
it("excludes actions gated by pending checkpoint", async () => {
|
|
248
|
+
const gatedAction = makeAction({
|
|
249
|
+
id: "act_gated",
|
|
250
|
+
title: "Gated action",
|
|
251
|
+
status: "pending",
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
const checkpoint: Checkpoint = {
|
|
255
|
+
id: "ckpt_1",
|
|
256
|
+
name: "CI check",
|
|
257
|
+
description: "Waiting for CI",
|
|
258
|
+
status: "pending",
|
|
259
|
+
type: "ci",
|
|
260
|
+
createdAt: new Date().toISOString(),
|
|
261
|
+
linkedActionIds: ["act_gated"],
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
await kv.set("mem:actions", gatedAction.id, gatedAction);
|
|
265
|
+
await kv.set("mem:checkpoints", checkpoint.id, checkpoint);
|
|
266
|
+
|
|
267
|
+
const gateEdge: ActionEdge = {
|
|
268
|
+
id: "ae_gate",
|
|
269
|
+
type: "gated_by",
|
|
270
|
+
sourceActionId: gatedAction.id,
|
|
271
|
+
targetActionId: checkpoint.id,
|
|
272
|
+
createdAt: new Date().toISOString(),
|
|
273
|
+
};
|
|
274
|
+
await kv.set("mem:action-edges", gateEdge.id, gateEdge);
|
|
275
|
+
|
|
276
|
+
const result = (await sdk.trigger("mem::frontier", {})) as {
|
|
277
|
+
success: boolean;
|
|
278
|
+
frontier: FrontierItem[];
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
expect(result.frontier.length).toBe(0);
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
it("excludes actions conflicting with active actions", async () => {
|
|
285
|
+
const activeAction = makeAction({
|
|
286
|
+
id: "act_active",
|
|
287
|
+
title: "Active task",
|
|
288
|
+
status: "active",
|
|
289
|
+
});
|
|
290
|
+
const conflictAction = makeAction({
|
|
291
|
+
id: "act_conflict",
|
|
292
|
+
title: "Conflicting task",
|
|
293
|
+
status: "pending",
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
await kv.set("mem:actions", activeAction.id, activeAction);
|
|
297
|
+
await kv.set("mem:actions", conflictAction.id, conflictAction);
|
|
298
|
+
|
|
299
|
+
const conflictEdge: ActionEdge = {
|
|
300
|
+
id: "ae_conflict",
|
|
301
|
+
type: "conflicts_with",
|
|
302
|
+
sourceActionId: conflictAction.id,
|
|
303
|
+
targetActionId: activeAction.id,
|
|
304
|
+
createdAt: new Date().toISOString(),
|
|
305
|
+
};
|
|
306
|
+
await kv.set("mem:action-edges", conflictEdge.id, conflictEdge);
|
|
307
|
+
|
|
308
|
+
const result = (await sdk.trigger("mem::frontier", {})) as {
|
|
309
|
+
success: boolean;
|
|
310
|
+
frontier: FrontierItem[];
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
const ids = result.frontier.map((f) => f.action.id);
|
|
314
|
+
expect(ids).toContain("act_active");
|
|
315
|
+
expect(ids).not.toContain("act_conflict");
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
it("active actions get score bonus", async () => {
|
|
319
|
+
const pendingAction = makeAction({
|
|
320
|
+
id: "act_pending",
|
|
321
|
+
title: "Pending",
|
|
322
|
+
status: "pending",
|
|
323
|
+
priority: 5,
|
|
324
|
+
createdAt: new Date().toISOString(),
|
|
325
|
+
});
|
|
326
|
+
const activeAction = makeAction({
|
|
327
|
+
id: "act_active",
|
|
328
|
+
title: "Active",
|
|
329
|
+
status: "active",
|
|
330
|
+
priority: 5,
|
|
331
|
+
createdAt: new Date().toISOString(),
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
await kv.set("mem:actions", pendingAction.id, pendingAction);
|
|
335
|
+
await kv.set("mem:actions", activeAction.id, activeAction);
|
|
336
|
+
|
|
337
|
+
const result = (await sdk.trigger("mem::frontier", {})) as {
|
|
338
|
+
success: boolean;
|
|
339
|
+
frontier: FrontierItem[];
|
|
340
|
+
};
|
|
341
|
+
|
|
342
|
+
const activeItem = result.frontier.find(
|
|
343
|
+
(f) => f.action.id === "act_active",
|
|
344
|
+
)!;
|
|
345
|
+
const pendingItem = result.frontier.find(
|
|
346
|
+
(f) => f.action.id === "act_pending",
|
|
347
|
+
)!;
|
|
348
|
+
|
|
349
|
+
expect(activeItem.score).toBeGreaterThan(pendingItem.score);
|
|
350
|
+
});
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
describe("mem::next", () => {
|
|
354
|
+
it("returns top suggestion when actions exist", async () => {
|
|
355
|
+
const action = makeAction({
|
|
356
|
+
id: "act_1",
|
|
357
|
+
title: "Top task",
|
|
358
|
+
priority: 8,
|
|
359
|
+
tags: ["urgent"],
|
|
360
|
+
});
|
|
361
|
+
await kv.set("mem:actions", action.id, action);
|
|
362
|
+
|
|
363
|
+
const result = (await sdk.trigger("mem::next", {})) as {
|
|
364
|
+
success: boolean;
|
|
365
|
+
suggestion: {
|
|
366
|
+
actionId: string;
|
|
367
|
+
title: string;
|
|
368
|
+
description: string;
|
|
369
|
+
priority: number;
|
|
370
|
+
score: number;
|
|
371
|
+
tags: string[];
|
|
372
|
+
} | null;
|
|
373
|
+
message: string;
|
|
374
|
+
totalActions: number;
|
|
375
|
+
};
|
|
376
|
+
|
|
377
|
+
expect(result.success).toBe(true);
|
|
378
|
+
expect(result.suggestion).not.toBeNull();
|
|
379
|
+
expect(result.suggestion!.actionId).toBe("act_1");
|
|
380
|
+
expect(result.suggestion!.title).toBe("Top task");
|
|
381
|
+
expect(result.suggestion!.priority).toBe(8);
|
|
382
|
+
expect(result.suggestion!.tags).toEqual(["urgent"]);
|
|
383
|
+
expect(result.message).toContain("Top task");
|
|
384
|
+
expect(result.totalActions).toBe(1);
|
|
385
|
+
});
|
|
386
|
+
|
|
387
|
+
it("returns null suggestion when no actions exist", async () => {
|
|
388
|
+
const result = (await sdk.trigger("mem::next", {})) as {
|
|
389
|
+
success: boolean;
|
|
390
|
+
suggestion: null;
|
|
391
|
+
message: string;
|
|
392
|
+
totalActions: number;
|
|
393
|
+
};
|
|
394
|
+
|
|
395
|
+
expect(result.success).toBe(true);
|
|
396
|
+
expect(result.suggestion).toBeNull();
|
|
397
|
+
expect(result.message).toContain("No actionable work");
|
|
398
|
+
expect(result.totalActions).toBe(0);
|
|
399
|
+
});
|
|
400
|
+
|
|
401
|
+
it("returns null when all actions are done", async () => {
|
|
402
|
+
const doneAction = makeAction({
|
|
403
|
+
id: "act_done",
|
|
404
|
+
title: "Completed",
|
|
405
|
+
status: "done",
|
|
406
|
+
});
|
|
407
|
+
await kv.set("mem:actions", doneAction.id, doneAction);
|
|
408
|
+
|
|
409
|
+
const result = (await sdk.trigger("mem::next", {})) as {
|
|
410
|
+
success: boolean;
|
|
411
|
+
suggestion: null;
|
|
412
|
+
message: string;
|
|
413
|
+
totalActions: number;
|
|
414
|
+
};
|
|
415
|
+
|
|
416
|
+
expect(result.success).toBe(true);
|
|
417
|
+
expect(result.suggestion).toBeNull();
|
|
418
|
+
expect(result.totalActions).toBe(1);
|
|
419
|
+
});
|
|
420
|
+
|
|
421
|
+
it("propagates failure when frontier fails", async () => {
|
|
422
|
+
const originalFunctions = new Map<string, Function>();
|
|
423
|
+
|
|
424
|
+
const failSdk = {
|
|
425
|
+
registerFunction: (opts: { id: string }, handler: Function) => {
|
|
426
|
+
originalFunctions.set(opts.id, handler);
|
|
427
|
+
},
|
|
428
|
+
registerTrigger: () => {},
|
|
429
|
+
trigger: async (id: string, data: unknown) => {
|
|
430
|
+
if (id === "mem::frontier") {
|
|
431
|
+
return { success: false, error: "internal failure" };
|
|
432
|
+
}
|
|
433
|
+
const fn = originalFunctions.get(id);
|
|
434
|
+
if (!fn) throw new Error(`No function: ${id}`);
|
|
435
|
+
return fn(data);
|
|
436
|
+
},
|
|
437
|
+
};
|
|
438
|
+
|
|
439
|
+
const failKv = mockKV();
|
|
440
|
+
registerFrontierFunction(failSdk as never, failKv as never);
|
|
441
|
+
|
|
442
|
+
const nextFn = originalFunctions.get("mem::next")!;
|
|
443
|
+
const result = (await nextFn({})) as {
|
|
444
|
+
success: boolean;
|
|
445
|
+
suggestion: null;
|
|
446
|
+
message: string;
|
|
447
|
+
totalActions: number;
|
|
448
|
+
};
|
|
449
|
+
|
|
450
|
+
expect(result.success).toBe(false);
|
|
451
|
+
expect(result.suggestion).toBeNull();
|
|
452
|
+
expect(result.message).toContain("Failed to compute frontier");
|
|
453
|
+
expect(result.totalActions).toBe(0);
|
|
454
|
+
});
|
|
455
|
+
|
|
456
|
+
it("respects project filter", async () => {
|
|
457
|
+
const alphaAction = makeAction({
|
|
458
|
+
id: "act_alpha",
|
|
459
|
+
title: "Alpha task",
|
|
460
|
+
project: "alpha",
|
|
461
|
+
priority: 5,
|
|
462
|
+
});
|
|
463
|
+
const betaAction = makeAction({
|
|
464
|
+
id: "act_beta",
|
|
465
|
+
title: "Beta task",
|
|
466
|
+
project: "beta",
|
|
467
|
+
priority: 10,
|
|
468
|
+
});
|
|
469
|
+
|
|
470
|
+
await kv.set("mem:actions", alphaAction.id, alphaAction);
|
|
471
|
+
await kv.set("mem:actions", betaAction.id, betaAction);
|
|
472
|
+
|
|
473
|
+
const result = (await sdk.trigger("mem::next", {
|
|
474
|
+
project: "alpha",
|
|
475
|
+
})) as {
|
|
476
|
+
success: boolean;
|
|
477
|
+
suggestion: { actionId: string; title: string } | null;
|
|
478
|
+
};
|
|
479
|
+
|
|
480
|
+
expect(result.success).toBe(true);
|
|
481
|
+
expect(result.suggestion).not.toBeNull();
|
|
482
|
+
expect(result.suggestion!.actionId).toBe("act_alpha");
|
|
483
|
+
});
|
|
484
|
+
});
|
|
485
|
+
});
|