@staix/agent-mem 0.37.0 → 0.38.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.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-mem",
3
- "version": "0.37.0",
3
+ "version": "0.38.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.38.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.38.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",
@@ -1,5 +1,7 @@
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 { capacityText, type CapacityReport } from "./memory/capacity.ts";
3
5
  import { createMemoryMcp } from "./mcp-memory.ts";
4
6
  import { safeProfileLockMessage } from "./memory/profile-lock-diagnostic.ts";
5
7
  import { memoryHome } from "./memory/home.ts";
@@ -24,6 +26,43 @@ const accepts = (command: string, allowed: readonly string[]) => new AgentUsageE
24
26
 
25
27
  type ReadCall = { tool: keyof ReturnType<typeof createMemoryMcp>["tools"]; args: Record<string, unknown> };
26
28
 
29
+ const object = (value: unknown): Record<string, unknown> | undefined => value && typeof value === "object" && !Array.isArray(value) ? value as Record<string, unknown> : undefined;
30
+ const text = (value: unknown): string => typeof value === "string" ? value : "";
31
+
32
+ /** Convert only values already returned by the screened MCP handler. */
33
+ function screenedRow(value: unknown): HumanMemoryRow {
34
+ const entry = object(value) ?? {}, run = object(entry.run), capture = object(entry.capture), view = object(entry.view) ?? entry;
35
+ const evidence = entry.evidence === false ? ["not evidence"] : entry.evidence === true ? ["evidence"] : [];
36
+ const score = typeof entry.score === "number" ? [`score ${entry.score}`] : [];
37
+ if (run) {
38
+ if (typeof run.first !== "string" || typeof run.to !== "string" || typeof run.count !== "number") throw new Error(UNAVAILABLE);
39
+ 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] };
40
+ }
41
+ if (capture) {
42
+ if (typeof capture.id !== "number" || typeof capture.at !== "string" || typeof capture.event !== "string" || typeof capture.excerpt !== "string") throw new Error(UNAVAILABLE);
43
+ 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] };
44
+ }
45
+ if (typeof view.id !== "string" || typeof view.kind !== "string" || typeof view.at !== "string" || typeof view.text !== "string") throw new Error(UNAVAILABLE);
46
+ const id = text(view.id), title = text(view.title), body = text(view.text);
47
+ const stale = view.stale === true ? `(stale${view.staleReason === "missing_in_checkout" ? ": missing" : view.staleReason === "mtime_newer_than_note" ? ": newer" : ""})` : "";
48
+ const folded = typeof entry.folded === "number" && entry.folded > 0 ? `+${entry.folded} same task` : "";
49
+ 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] };
50
+ }
51
+
52
+ function screenedDetail(value: unknown, columns: number, style: Style, now?: number): string {
53
+ const outer = object(value), view = object(outer?.view) ?? outer;
54
+ 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 }) });
55
+ if (!outer) return "No entry.";
56
+ const row = screenedRow(value), capture = object(outer.capture), record = capture ?? view ?? {};
57
+ const fields: [string, string][] = [];
58
+ if (typeof outer.evidence === "boolean") fields.push(["Evidence", outer.evidence ? "yes" : "no"]);
59
+ if (capture && typeof capture.at === "string") fields.push(["Recorded at", capture.at]);
60
+ if (capture?.subagent === true) fields.push(["Subagent", "yes"]);
61
+ 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]);
62
+ if (Array.isArray(record.paths)) fields.push(["Paths", record.paths.filter((item): item is string => typeof item === "string").join(", ")]);
63
+ return memoryRecordText(row, { columns, style, ...(now === undefined ? {} : { now }) }, fields);
64
+ }
65
+
27
66
  function values(argv: readonly string[], name: string): string[] {
28
67
  const out: string[] = [];
29
68
  for (let i = 0; i < argv.length; i++) {
@@ -98,7 +137,7 @@ function route(parsed: ParsedCommand, argv: readonly string[]): ReadCall | undef
98
137
  export async function agentCliRead(
99
138
  parsed: ParsedCommand,
100
139
  argv: readonly string[],
101
- context: { cwd?: string; env?: Readonly<Record<string, string | undefined>> },
140
+ context: { cwd?: string; env?: Readonly<Record<string, string | undefined>>; columns?: number; style?: Style; now?: () => number },
102
141
  ): Promise<string | undefined> {
103
142
  const call = route(parsed, argv);
104
143
  if (!call) return undefined;
@@ -110,8 +149,19 @@ export async function agentCliRead(
110
149
  const value = await memory.tools[call.tool](call.args);
111
150
  const output = JSON.stringify(value);
112
151
  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}`;
152
+ if (parsed.options["--json"] !== true && parsed.path[0] === "capacity" && value && typeof value === "object") {
153
+ const shown = capacityText(value as CapacityReport, { columns: context.columns ?? 80, style: context.style ?? PLAIN });
154
+ if (Buffer.byteLength(shown) > RESULT_BYTES) throw new Error(UNAVAILABLE);
155
+ return shown;
156
+ }
157
+ if (parsed.options["--json"] !== true && ["list", "search", "show"].includes(parsed.path[0] ?? "")) {
158
+ const columns = context.columns ?? 80, style = context.style ?? PLAIN, now = context.now?.();
159
+ const rows = parsed.path[0] === "list" ? value : object(value)?.hits;
160
+ if (parsed.path[0] !== "show" && !Array.isArray(rows)) throw new Error(UNAVAILABLE);
161
+ const render = { columns, style, ...(now === undefined ? {} : { now }) };
162
+ 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 }] : []; }) : [];
163
+ const engine = object(value)?.engine;
164
+ 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
165
  if (Buffer.byteLength(shown) > RESULT_BYTES) throw new Error(UNAVAILABLE);
116
166
  return shown;
117
167
  }