@staix/agent-mem 0.37.0 → 0.39.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.
Files changed (49) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/README.md +1 -1
  3. package/package.json +1 -1
  4. package/src/brief-curated.ts +8 -4
  5. package/src/cli-agent-reads.ts +55 -4
  6. package/src/cli.ts +222 -93
  7. package/src/commands-table.ts +332 -171
  8. package/src/index.ts +5 -0
  9. package/src/memory/capacity-text.ts +100 -0
  10. package/src/memory/capacity.ts +1 -57
  11. package/src/memory/commands.ts +45 -9
  12. package/src/memory/curated-cache-state.ts +22 -3
  13. package/src/memory/doctor-text.ts +144 -0
  14. package/src/memory/doctor.ts +9 -86
  15. package/src/memory/eval-audit-text.ts +62 -0
  16. package/src/memory/eval-audit.ts +1 -34
  17. package/src/memory/eval-text.ts +32 -0
  18. package/src/memory/eval.ts +1 -14
  19. package/src/memory/formats.ts +2 -0
  20. package/src/memory/gc-text.ts +22 -0
  21. package/src/memory/gc.ts +0 -6
  22. package/src/memory/generation-index.ts +1 -1
  23. package/src/memory/index-file.ts +1 -1
  24. package/src/memory/metrics.ts +18 -10
  25. package/src/memory/migrate-text.ts +32 -0
  26. package/src/memory/migrate.ts +0 -29
  27. package/src/memory/prune-text.ts +29 -0
  28. package/src/memory/prune.ts +0 -26
  29. package/src/memory/report-text.ts +233 -0
  30. package/src/memory/shard-migration-text.ts +40 -0
  31. package/src/memory/shard-migration.ts +0 -37
  32. package/src/memory/status-text.ts +72 -29
  33. package/src/memory/store.ts +112 -17
  34. package/src/memory/style.ts +98 -1
  35. package/src/memory/sync-placement-bound.ts +2 -2
  36. package/src/memory/sync-placement-checkpoint-person.ts +1 -1
  37. package/src/memory/sync-placement-noop-cache.ts +93 -0
  38. package/src/memory/sync-placement-refusal-category.ts +18 -0
  39. package/src/memory/sync-placement-transport.ts +43 -7
  40. package/src/memory/sync-progress-text.ts +7 -0
  41. package/src/memory/sync-progress.ts +21 -7
  42. package/src/memory/sync-screen.ts +13 -0
  43. package/src/memory/work-lists.ts +6 -4
  44. package/src/setup-drift.ts +1 -1
  45. package/src/setup-writer-roots.ts +136 -0
  46. package/src/setup.ts +122 -159
  47. package/src/sync-placement-writer-context.ts +8 -3
  48. package/src/ui/plugin.ts +4 -2
  49. package/src/work-brief-preparation.ts +28 -0
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-mem",
3
- "version": "0.37.0",
3
+ "version": "0.39.0",
4
4
  "description": "Bounded project memory tools and seven deterministic capture hooks, without a resident worker.",
5
5
  "mcpServers": {
6
6
  "agent-mem": {
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  Curated memory with append-only JSONL logs, a derived SQLite index, short- and long-term tiers, a typed graph, goals with leases, and git sync between machines. Extracted from [agent-hub](https://github.com/STAIxBWLB/agent-hub), with compatible storage and entry IDs.
4
4
 
5
5
  <!-- facts:version -->
6
- Version: 0.37.0. Requires Bun 1.4.2 or later; runtime dependencies: @staix/cli-output.
6
+ Version: 0.39.0. Requires Bun 1.4.2 or later; runtime dependencies: @staix/cli-output.
7
7
  <!-- /facts:version -->
8
8
 
9
9
  ## Quick start
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@staix/agent-mem",
3
- "version": "0.37.0",
3
+ "version": "0.39.0",
4
4
  "description": "Curated, shared memory for coding agents: append-only logs, a derived index, tiers and a typed graph.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -6,6 +6,8 @@ import { BRIEF_CACHE_BYTES, writeBriefCache, type BriefCacheRow } from "./brief-
6
6
  import { PREFERENCE_SLOT } from "./memory/preference-brief.ts";
7
7
  import { taskGroupKey } from "./memory/task-group.ts";
8
8
 
9
+ // The longest serialized Date.parse result (or null) fits this reservation.
10
+ const EXPIRY_RESERVATION = -8_640_000_000_000_000;
9
11
  const PAGE_ROWS = 32, MAX_PAGES = 4, SECTION_RECORDS = 4, RECORD_BYTES = 768, MAX_AGE = 24 * 60 * 60 * 1000;
10
12
 
11
13
  /** Canonical curated display shared by the library brief and snapshot writer. */
@@ -54,8 +56,9 @@ export function buildPreferenceBriefCache(store: Pick<MemoryStore, "readPreferen
54
56
  options: { base: string; project: string; directory: string; binding: string; cwd?: string; now?: () => number; policy?: StandalonePolicyOptions }): void {
55
57
  if (options.policy?.host) throw new Error("prebuilt preference brief requires synchronous standalone policy; remove host policy or use the async session brief");
56
58
  const now = (options.now ?? Date.now)(), policy = createStandalonePolicy(configuredPolicyOptions(options.base, options.cwd, options.policy));
59
+ const builtThrough = Math.max(1, now);
57
60
  const rows: BriefCacheRow[] = [], expires: number[] = [];
58
- let partial = false, bytes = Buffer.byteLength(JSON.stringify({ schema: "agent-mem.brief-cache/v1", project: options.project, section: "preferences", builtThrough: 1, partial: false, rows: [], preferences: { builtAt: now, binding: options.binding, expiresAt: null } })) + 1;
61
+ let partial = false, bytes = Buffer.byteLength(JSON.stringify({ schema: "agent-mem.brief-cache/v1", project: options.project, section: "preferences", builtThrough, partial: false, rows: [], preferences: { builtAt: now, binding: options.binding, expiresAt: EXPIRY_RESERVATION } })) + 1;
59
62
  store.withDeferredPromotions(() => {
60
63
  // Newest first with no paging: the slot must not hide an old preference behind newer notes of other kinds.
61
64
  const page = store.readPreferences(options.project, PREFERENCE_SLOT);
@@ -76,7 +79,7 @@ export function buildPreferenceBriefCache(store: Pick<MemoryStore, "readPreferen
76
79
  });
77
80
  const expiresAt = expires.length ? Math.min(...expires) : null;
78
81
  writeBriefCache({ directory: options.directory, project: options.project, section: "preferences" }, {
79
- schema: "agent-mem.brief-cache/v1", project: options.project, section: "preferences", builtThrough: Math.max(1, now), partial, rows,
82
+ schema: "agent-mem.brief-cache/v1", project: options.project, section: "preferences", builtThrough, partial, rows,
80
83
  preferences: { builtAt: now, binding: options.binding, expiresAt },
81
84
  });
82
85
  }
@@ -85,10 +88,11 @@ export function buildCuratedBriefCache(store: Pick<MemoryStore, "readPage" | "wi
85
88
  options: { base: string; project: string; directory: string; binding: string; cwd?: string; now?: () => number; policy?: StandalonePolicyOptions }): void {
86
89
  if (options.policy?.host) throw new Error("prebuilt curated brief requires synchronous standalone policy; remove host policy or use the async session brief");
87
90
  const now = (options.now ?? Date.now)(), policy = createStandalonePolicy(configuredPolicyOptions(options.base, options.cwd, options.policy));
91
+ const builtThrough = Math.max(1, now);
88
92
  const rows: BriefCacheRow[] = [], expires: number[] = [];
89
93
  let partial = false, after: { position: number; id: string } | undefined, complete = false;
90
94
  const tasks = new Set<string>(); // #423: one row per task, the first in page order; later same-task rows take no slot
91
- let bytes = Buffer.byteLength(JSON.stringify({ schema: "agent-mem.brief-cache/v1", project: options.project, section: "curated", builtThrough: 1, partial: false, rows: [], curated: { builtAt: now, binding: options.binding, expiresAt: null } })) + 1;
95
+ let bytes = Buffer.byteLength(JSON.stringify({ schema: "agent-mem.brief-cache/v1", project: options.project, section: "curated", builtThrough, partial: false, rows: [], curated: { builtAt: now, binding: options.binding, expiresAt: EXPIRY_RESERVATION } })) + 1;
92
96
  store.withDeferredPromotions(() => {
93
97
  for (let pageNo = 0; pageNo < MAX_PAGES; pageNo++) {
94
98
  const page = store.readPage({ project: options.project, limit: PAGE_ROWS, after });
@@ -117,7 +121,7 @@ export function buildCuratedBriefCache(store: Pick<MemoryStore, "readPage" | "wi
117
121
  });
118
122
  const expiresAt = expires.length ? Math.min(...expires) : null;
119
123
  writeBriefCache({ directory: options.directory, project: options.project, section: "curated" }, {
120
- schema: "agent-mem.brief-cache/v1", project: options.project, section: "curated", builtThrough: Math.max(1, now), partial, rows,
124
+ schema: "agent-mem.brief-cache/v1", project: options.project, section: "curated", builtThrough, partial, rows,
121
125
  curated: { builtAt: now, binding: options.binding, expiresAt },
122
126
  });
123
127
  }
@@ -1,5 +1,8 @@
1
1
  import { noteDisplayActor } from "./memory/cli-attribution.ts";
2
- import { singleLine } from "./memory/style.ts";
2
+ import { memoryDetailText, memoryRecordText, memoryScoresText, memoryTableText, PLAIN, type HumanMemoryRow, type Style } from "./memory/style.ts";
3
+ import type { View } from "./memory/store.ts";
4
+ import { type CapacityReport } from "./memory/capacity.ts";
5
+ import { capacityText } from "./memory/capacity-text.ts";
3
6
  import { createMemoryMcp } from "./mcp-memory.ts";
4
7
  import { safeProfileLockMessage } from "./memory/profile-lock-diagnostic.ts";
5
8
  import { memoryHome } from "./memory/home.ts";
@@ -24,6 +27,43 @@ const accepts = (command: string, allowed: readonly string[]) => new AgentUsageE
24
27
 
25
28
  type ReadCall = { tool: keyof ReturnType<typeof createMemoryMcp>["tools"]; args: Record<string, unknown> };
26
29
 
30
+ const object = (value: unknown): Record<string, unknown> | undefined => value && typeof value === "object" && !Array.isArray(value) ? value as Record<string, unknown> : undefined;
31
+ const text = (value: unknown): string => typeof value === "string" ? value : "";
32
+
33
+ /** Convert only values already returned by the screened MCP handler. */
34
+ function screenedRow(value: unknown): HumanMemoryRow {
35
+ const entry = object(value) ?? {}, run = object(entry.run), capture = object(entry.capture), view = object(entry.view) ?? entry;
36
+ const evidence = entry.evidence === false ? ["not evidence"] : entry.evidence === true ? ["evidence"] : [];
37
+ const score = typeof entry.score === "number" ? [`score ${entry.score}`] : [];
38
+ if (run) {
39
+ if (typeof run.first !== "string" || typeof run.to !== "string" || typeof run.count !== "number") throw new Error(UNAVAILABLE);
40
+ return { id: run.first, kind: "tool run", at: run.to, text: `${run.count} tool events`, ...(typeof run.agent === "string" ? { peer: run.agent } : {}), flags: [...evidence, ...score] };
41
+ }
42
+ if (capture) {
43
+ if (typeof capture.id !== "number" || typeof capture.at !== "string" || typeof capture.event !== "string" || typeof capture.excerpt !== "string") throw new Error(UNAVAILABLE);
44
+ return { id: `capture:${capture.id}`, kind: "capture", at: capture.at, text: `${capture.event}: ${capture.excerpt}`, ...(typeof capture.agent === "string" ? { peer: capture.agent } : {}), flags: [...evidence, ...(capture.subagent === true ? ["subagent"] : []), ...score] };
45
+ }
46
+ if (typeof view.id !== "string" || typeof view.kind !== "string" || typeof view.at !== "string" || typeof view.text !== "string") throw new Error(UNAVAILABLE);
47
+ const id = text(view.id), title = text(view.title), body = text(view.text);
48
+ const stale = view.stale === true ? `(stale${view.staleReason === "missing_in_checkout" ? ": missing" : view.staleReason === "mtime_newer_than_note" ? ": newer" : ""})` : "";
49
+ const folded = typeof entry.folded === "number" && entry.folded > 0 ? `+${entry.folded} same task` : "";
50
+ return { id: entry.source === "repo" ? `repo:${id}` : id, kind: text(view.kind) || "entry", at: text(view.at), text: `${title ? `${title}: ` : ""}${body}`, ...(typeof view.tier === "string" ? { tier: view.tier } : {}), ...(typeof view.peer === "string" ? { peer: view.peer } : {}), ...(typeof view.scope === "string" ? { scope: view.scope } : {}), flags: [...evidence, ...(stale ? [stale] : []), ...(folded ? [folded] : []), ...score] };
51
+ }
52
+
53
+ function screenedDetail(value: unknown, columns: number, style: Style, now?: number): string {
54
+ const outer = object(value), view = object(outer?.view) ?? outer;
55
+ if (view && ["id", "text", "peer", "kind", "tier", "at", "scope", "project", "machine"].every(key => typeof view[key] === "string") && Array.isArray(view.about)) return memoryDetailText(view as unknown as View, { columns, style, actor: noteDisplayActor(view.peer as string), ...(now === undefined ? {} : { now }) });
56
+ if (!outer) return "No entry.";
57
+ const row = screenedRow(value), capture = object(outer.capture), record = capture ?? view ?? {};
58
+ const fields: [string, string][] = [];
59
+ if (typeof outer.evidence === "boolean") fields.push(["Evidence", outer.evidence ? "yes" : "no"]);
60
+ if (capture && typeof capture.at === "string") fields.push(["Recorded at", capture.at]);
61
+ if (capture?.subagent === true) fields.push(["Subagent", "yes"]);
62
+ for (const [label, key] of [["Agent", "agent"], ["Session", "session"], ["Scope", "scope"]] as const) if (typeof record[key] === "string") fields.push([label, record[key] as string]);
63
+ if (Array.isArray(record.paths)) fields.push(["Paths", record.paths.filter((item): item is string => typeof item === "string").join(", ")]);
64
+ return memoryRecordText(row, { columns, style, ...(now === undefined ? {} : { now }) }, fields);
65
+ }
66
+
27
67
  function values(argv: readonly string[], name: string): string[] {
28
68
  const out: string[] = [];
29
69
  for (let i = 0; i < argv.length; i++) {
@@ -98,7 +138,7 @@ function route(parsed: ParsedCommand, argv: readonly string[]): ReadCall | undef
98
138
  export async function agentCliRead(
99
139
  parsed: ParsedCommand,
100
140
  argv: readonly string[],
101
- context: { cwd?: string; env?: Readonly<Record<string, string | undefined>> },
141
+ context: { cwd?: string; env?: Readonly<Record<string, string | undefined>>; columns?: number; style?: Style; now?: () => number },
102
142
  ): Promise<string | undefined> {
103
143
  const call = route(parsed, argv);
104
144
  if (!call) return undefined;
@@ -110,8 +150,19 @@ export async function agentCliRead(
110
150
  const value = await memory.tools[call.tool](call.args);
111
151
  const output = JSON.stringify(value);
112
152
  if (output === undefined || Buffer.byteLength(output) > RESULT_BYTES) throw new Error(UNAVAILABLE);
113
- if (parsed.path[0] === "show" && parsed.options["--json"] !== true && value && typeof value === "object" && "peer" in value && typeof value.peer === "string") {
114
- const shown = `actor: ${noteDisplayActor(value.peer)}, peer: ${singleLine(value.peer)}\n${output}`;
153
+ if (parsed.options["--json"] !== true && parsed.path[0] === "capacity" && value && typeof value === "object") {
154
+ const shown = capacityText(value as CapacityReport, { columns: context.columns ?? 80, style: context.style ?? PLAIN });
155
+ if (Buffer.byteLength(shown) > RESULT_BYTES) throw new Error(UNAVAILABLE);
156
+ return shown;
157
+ }
158
+ if (parsed.options["--json"] !== true && ["list", "search", "show"].includes(parsed.path[0] ?? "")) {
159
+ const columns = context.columns ?? 80, style = context.style ?? PLAIN, now = context.now?.();
160
+ const rows = parsed.path[0] === "list" ? value : object(value)?.hits;
161
+ if (parsed.path[0] !== "show" && !Array.isArray(rows)) throw new Error(UNAVAILABLE);
162
+ const render = { columns, style, ...(now === undefined ? {} : { now }) };
163
+ const scores = parsed.path[0] === "search" && parsed.options["--explain"] === true && Array.isArray(rows) ? rows.flatMap(item => { const details = object(object(item)?.scoreDetails); return details ? [{ id: screenedRow(item).id, details }] : []; }) : [];
164
+ const engine = object(value)?.engine;
165
+ const shown = parsed.path[0] === "show" ? screenedDetail(value, columns, style, now) : [memoryTableText(Array.isArray(rows) ? rows.map(screenedRow) : [], parsed.path[0] === "search" ? "Search" : "Memory", render, typeof engine === "string" ? `Engine: ${engine}` : undefined), memoryScoresText(scores, render)].filter(Boolean).join("\n\n");
115
166
  if (Buffer.byteLength(shown) > RESULT_BYTES) throw new Error(UNAVAILABLE);
116
167
  return shown;
117
168
  }