@staix/agent-mem 0.36.0 → 0.37.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.36.0",
3
+ "version": "0.37.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.36.0. Requires Bun 1.4.2 or later; no runtime dependencies.
6
+ Version: 0.37.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.36.0",
3
+ "version": "0.37.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",
@@ -11,6 +11,9 @@
11
11
  "engines": {
12
12
  "bun": ">=1.4.2"
13
13
  },
14
+ "dependencies": {
15
+ "@staix/cli-output": "0.1.3"
16
+ },
14
17
  "devDependencies": {
15
18
  "@staix/agent-console": "0.1.3",
16
19
  "@types/bun": "^1.3.0",
package/src/cli.ts CHANGED
@@ -69,7 +69,8 @@ import { buildNote, FAIL_TEMPLATE, hasFailLabel, noteAdd, parseFailTemplate, typ
69
69
  import { runEditor } from "./memory/editor.ts";
70
70
  import { doctorReport, doctorText } from "./memory/doctor.ts";
71
71
  import { statusText, type StatusView } from "./memory/status-text.ts";
72
- import { asciiMarkers, markerCell, paint, resolveColor, streamEnv, style, wrapReport, facts, label, PLAIN, type Style } from "./memory/style.ts";
72
+ import { asciiMarkers, errorLine, errorSpans, EXIT, markerCell, paint, resolveColor, streamEnv } from "@staix/cli-output";
73
+ import { style, wrapReport, facts, label, PLAIN, type Style } from "./memory/style.ts";
73
74
  import { endLikeSignal, nextSyncAt, readSyncState, recordSyncAttempt, remoteConfigured, syncDue, stopSignal, syncOutcome, usableState, SYNC_IF_DUE_DEADLINE_MS, type StopCause } from "./memory/sync-cadence.ts";
74
75
 
75
76
  const VERSION = (JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8")) as { version: string }).version;
@@ -1536,7 +1537,7 @@ async function placementProgress(home: string, mode: string, context: CliContext
1536
1537
  return new SyncProgress({ sink: snapshot => { for (const index of live) try { parts[index]!(snapshot); } catch { live.delete(index); } } });
1537
1538
  }
1538
1539
  function outputStyle(context: CliContext, options: Record<string, string | boolean>): Style {
1539
- const color = resolveColor(typeof options["--color"] === "string" ? options["--color"] : undefined, streamEnv((context.stdoutTTY ?? process.stdout.isTTY) === true, context.env ?? process.env));
1540
+ const color = resolveColor(typeof options["--color"] === "string" ? options["--color"] : undefined, streamEnv((context.stdoutTTY ?? process.stdout.isTTY) === true, context.env ?? process.env), "amem");
1540
1541
  if (color instanceof Error) throw color;
1541
1542
  return style(options["--json"] !== true && color, asciiMarkers(context.env ?? process.env, options["--ascii"] === true));
1542
1543
  }
@@ -1573,7 +1574,7 @@ export function ingestText(kind: IngestKind, result: IngestReceipt, s: Style = P
1573
1574
 
1574
1575
  export function formatCliError(error: unknown, usage = false): string {
1575
1576
  if (error instanceof DecayApplyError || error instanceof CliPartialApplyError) return error.render();
1576
- const message = `amem: ${(error as Error).message}`;
1577
+ const message = errorLine("amem", String((error as Error).message), "", { tty: false })[0]!;
1577
1578
  return usage || (error as { exitCode?: number }).exitCode === 2 ? `${message}\nUsage: amem <command> [options]\nRun 'amem --help' for details.` : message;
1578
1579
  }
1579
1580
 
@@ -1589,11 +1590,13 @@ export async function main(argv = process.argv.slice(2)): Promise<void> {
1589
1590
  if (process.stderr.isTTY) {
1590
1591
  let options: Record<string, string | boolean> = {};
1591
1592
  try { options = parseCommand(argv).options; } catch { /* Invalid options still report their usage error. */ }
1592
- const color = resolveColor(typeof options["--color"] === "string" ? options["--color"] : undefined, streamEnv(true, process.env));
1593
+ const color = resolveColor(typeof options["--color"] === "string" ? options["--color"] : undefined, streamEnv(true, process.env), "amem");
1593
1594
  const ascii = asciiMarkers(process.env, options["--ascii"] === true);
1594
- prefix = `${paint("error", markerCell("fail", ascii), !argv.includes("--json") && color === true)} `;
1595
+ // ponytail: amem keeps the two-cell marker column; upgrade when errorSpans exposes that padding.
1596
+ const marker = errorSpans("amem", "", "", { tty: true, ascii })[0]![0]!;
1597
+ prefix = `${paint([{ ...marker, text: markerCell("fail", ascii) }], !argv.includes("--json") && color === true)} `;
1595
1598
  }
1596
- const code = (error as { exitCode?: number }).exitCode ?? ((error as Error).message.startsWith("usage:") ? 2 : 1);
1599
+ const code = (error as { exitCode?: number }).exitCode ?? ((error as Error).message.startsWith("usage:") ? EXIT.usage : EXIT.fail);
1597
1600
  console.error(prefix + formatCliError(error, code === 2)); process.exitCode = code;
1598
1601
  }
1599
1602
  if (personStop !== undefined) endLikeSignal(personStop); // after the report, with amem's own handlers already removed
@@ -19,7 +19,8 @@ import { readSelector } from "./generation.ts";
19
19
  import { processLiveness, withGitTimeout } from "./platform.ts";
20
20
  import { endLikeSignal, STOP_SIGNALS } from "./sync-cadence.ts";
21
21
  import { boundRepoRoot } from "./repo-scope.ts";
22
- import { facts, label, paint, section, markerCell, PLAIN, singleLine, type Style } from "./style.ts";
22
+ import { markerCell, paint } from "@staix/cli-output";
23
+ import { facts, label, section, PLAIN, singleLine, type Style } from "./style.ts";
23
24
  import { aliasedKeys, shardDir } from "./shard.ts";
24
25
  import type { MemoryStore, View } from "./store.ts";
25
26
  import { nextSyncAt, readSyncState, remoteConfigured, syncDue, usableState } from "./sync-cadence.ts";
@@ -693,8 +694,8 @@ export function doctorText(report: DoctorReport, s: Style = PLAIN): string {
693
694
  if (item.hint) actions.push(`${name}: ${item.hint}`);
694
695
  if (name === "capture" && item.clis) for (const [cli, row] of Object.entries(item.clis as Record<string, { hint?: string }>)) if (row.hint) actions.push(`capture ${cli}: ${row.hint}`);
695
696
  }
696
- const lines = [`${paint("header", " amem Doctor", s.color)}: ${report.status === "ok" ? s.ok(report.status) : report.status === "attention" ? s.attention(report.status) : s.error(report.status)}${summary ? ` (${summary})` : ` (all ${entries.length} checks ok)`}`,
697
- ...(actions.length ? ["", section(s, "Attention"), ...actions.map(action => ` ${paint("accent", markerCell("next", s.ascii), s.color)} ${action}`)] : []),
697
+ const lines = [`${paint([{ role: "header", text: " amem Doctor" }], s.color)}: ${report.status === "ok" ? s.ok(report.status) : report.status === "attention" ? s.attention(report.status) : s.error(report.status)}${summary ? ` (${summary})` : ` (all ${entries.length} checks ok)`}`,
698
+ ...(actions.length ? ["", section(s, "Attention"), ...actions.map(action => ` ${paint([{ role: "accent", text: markerCell("next", s.ascii) }], s.color)} ${action}`)] : []),
698
699
  "", section(s, "Checks"), ` home: ${report.home.path} ${s.dim(`(${report.home.source})`)}`, ` project: ${report.project}`];
699
700
  const order: Record<SectionStatus, number> = { attention: 0, unavailable: 1, skipped: 2, ok: 3 };
700
701
  entries.sort((a, b) => order[a[1].status] - order[b[1].status]);
@@ -706,10 +707,10 @@ export function doctorText(report: DoctorReport, s: Style = PLAIN): string {
706
707
  }
707
708
  lines.push("", actions.length ? "Next actions: see Attention" : "Next actions: none");
708
709
  const counts = [
709
- ...(count("attention") ? [`${paint("warning", markerCell("warn", s.ascii), s.color)} ${count("attention")} warnings`] : []),
710
- ...(count("unavailable") ? [`${paint("hint", markerCell("unknown", s.ascii), s.color)} ${count("unavailable")} unknown`] : []),
711
- ...(count("skipped") ? [`${paint("hint", markerCell("absent", s.ascii), s.color)} ${count("skipped")} skipped`] : []),
712
- ...(count("ok") ? [`${paint("success", markerCell("ok", s.ascii), s.color)} ${count("ok")} ok`] : []),
710
+ ...(count("attention") ? [`${paint([{ role: "warning", text: markerCell("warn", s.ascii) }], s.color)} ${count("attention")} warnings`] : []),
711
+ ...(count("unavailable") ? [`${paint([{ role: "hint", text: markerCell("unknown", s.ascii) }], s.color)} ${count("unavailable")} unknown`] : []),
712
+ ...(count("skipped") ? [`${paint([{ role: "hint", text: markerCell("absent", s.ascii) }], s.color)} ${count("skipped")} skipped`] : []),
713
+ ...(count("ok") ? [`${paint([{ role: "success", text: markerCell("ok", s.ascii) }], s.color)} ${count("ok")} ok`] : []),
713
714
  ];
714
715
  if (counts.length) lines.push(counts.join(" "));
715
716
  return lines.join("\n");
@@ -1,4 +1,5 @@
1
- import { facts, label, markerCell, paint, section, PLAIN, type Style } from "./style.ts";
1
+ import { markerCell, paint } from "@staix/cli-output";
2
+ import { facts, label, section, PLAIN, type Style } from "./style.ts";
2
3
 
3
4
  /** The `amem status` object as the CLI builds it; `amem status --json` prints it unchanged. */
4
5
  export interface StatusView {
@@ -32,8 +33,8 @@ export function statusText(status: StatusView, s: Style = PLAIN): string {
32
33
  const { machine, repo, denyPaths, piiPatterns, ...limits } = status.config;
33
34
  const pendingCounts = facts(Object.fromEntries(Object.entries(status.pending).filter(([key]) => !key.endsWith("Ids"))));
34
35
  const lines = [
35
- `${paint("header", " amem Status", s.color)}: ${overall === "ok" ? s.ok(overall) : overall === "attention" ? s.attention(overall) : s.error(overall)}`,
36
- ...(warnings.length || actions.length ? ["", section(s, "Attention"), ...warnings.map(warning => ` ${s.attention(markerCell("warn", s.ascii))} ${warning}`), ...actions.map(action => ` ${paint("accent", markerCell("next", s.ascii), s.color)} ${action}`)] : []),
36
+ `${paint([{ role: "header", text: " amem Status" }], s.color)}: ${overall === "ok" ? s.ok(overall) : overall === "attention" ? s.attention(overall) : s.error(overall)}`,
37
+ ...(warnings.length || actions.length ? ["", section(s, "Attention"), ...warnings.map(warning => ` ${s.attention(markerCell("warn", s.ascii))} ${warning}`), ...actions.map(action => ` ${paint([{ role: "accent", text: markerCell("next", s.ascii) }], s.color)} ${action}`)] : []),
37
38
  "", section(s, "Memory"),
38
39
  ` home: ${status.home.path} ${s.dim(`(${status.home.source})`)}`,
39
40
  `${label(s, "ok")} policy: machine ${machine ?? "none (defaults)"}, repo ${repo ?? "none"}; ${denyPaths} deny paths, ${piiPatterns} PII patterns${facts(limits) ? `; ${facts(limits)}` : ""}`,
@@ -1,8 +1,10 @@
1
1
  /**
2
- * A tiny, dependency-free text style for person-facing CLI output (#125).
2
+ * Application-specific text helpers for person-facing CLI output (#125).
3
3
  * Color is decoration only: every caller also prints a textual label, so plain output carries the same facts.
4
4
  * JSON output never passes through this module.
5
5
  */
6
+ import { MARKERS, SECTION_MARKER, SGR_RESET, cellWidth, markerCell, paint, type MarkerName } from "@staix/cli-output";
7
+
6
8
  export interface Style {
7
9
  readonly color: boolean;
8
10
  readonly ascii: boolean;
@@ -13,57 +15,15 @@ export interface Style {
13
15
  bold(text: string): string;
14
16
  }
15
17
 
16
- /** Portable CLI output standard v1 vocabulary. */
17
- export type Role = "header" | "section" | "key" | "value" | "success" | "warning" | "error" | "hint" | "accent";
18
- const ESC = String.fromCharCode(27);
19
- export const SGR_RESET = `${ESC}[0m`;
20
- export const ROLE_SGR: Readonly<Record<Role, string>> = Object.freeze({
21
- header: `${ESC}[1;34m`, section: `${ESC}[1;35m`, key: `${ESC}[34m`, value: "",
22
- success: `${ESC}[1;32m`, warning: `${ESC}[1;33m`, error: `${ESC}[1;31m`,
23
- hint: `${ESC}[90m`, accent: `${ESC}[36m`,
24
- });
25
- export const MARKER_NAMES = ["ok", "fail", "warn", "absent", "unknown", "pending", "active", "next"] as const;
26
- export type MarkerName = (typeof MARKER_NAMES)[number];
27
- export const MARKERS: Readonly<Record<MarkerName, { glyph: string; ascii: string; role: Role }>> = Object.freeze({
28
- ok: { glyph: "✓", ascii: "ok", role: "success" }, fail: { glyph: "✗", ascii: "x", role: "error" },
29
- warn: { glyph: "⚠", ascii: "!", role: "warning" }, absent: { glyph: "-", ascii: "-", role: "hint" },
30
- unknown: { glyph: "?", ascii: "?", role: "hint" }, pending: { glyph: "~", ascii: "~", role: "hint" },
31
- active: { glyph: "*", ascii: "*", role: "success" }, next: { glyph: "→", ascii: "->", role: "accent" },
32
- });
33
- export const SECTION_MARKER = { glyph: "▸", ascii: ">" } as const;
34
- export const MARKER_COLUMN = 2;
35
- export const cellWidth = (text: string): number => Bun.stringWidth(text, { ambiguousIsNarrow: true });
36
- export function markerCell(name: MarkerName, ascii: boolean): string {
37
- const text = ascii ? MARKERS[name].ascii : MARKERS[name].glyph;
38
- return text + " ".repeat(Math.max(0, MARKER_COLUMN - cellWidth(text)));
39
- }
40
- export interface ColorEnv { isTTY: boolean; TERM?: string; NO_COLOR?: string; FORCE_COLOR?: string; CLICOLOR?: string; CLICOLOR_FORCE?: string }
41
- export function streamEnv(isTTY: boolean, env: Readonly<Record<string, string | undefined>> = process.env): ColorEnv {
42
- return { isTTY, TERM: env.TERM, NO_COLOR: env.NO_COLOR, FORCE_COLOR: env.FORCE_COLOR, CLICOLOR: env.CLICOLOR, CLICOLOR_FORCE: env.CLICOLOR_FORCE };
43
- }
44
- export function resolveColor(flag: string | undefined, env: ColorEnv): boolean | Error {
45
- if (flag === "always") return true;
46
- if (flag === "never") return false;
47
- if (flag !== undefined && flag !== "auto") return new Error("usage: amem <command> [--color=auto|always|never]");
48
- if (env.NO_COLOR) return false;
49
- if ((env.FORCE_COLOR && env.FORCE_COLOR !== "0") || (env.CLICOLOR_FORCE && env.CLICOLOR_FORCE !== "0")) return true;
50
- if (env.FORCE_COLOR === "0" || env.CLICOLOR === "0") return false;
51
- return env.isTTY && env.TERM !== "dumb";
52
- }
53
- export function asciiMarkers(env: Readonly<Record<string, string | undefined>> = process.env, flag = false): boolean {
54
- return flag || !/utf-?8/i.test(env.LC_ALL || env.LC_CTYPE || env.LANG || "");
55
- }
56
- export function paint(role: Role, text: string, color: boolean): string {
57
- return color && ROLE_SGR[role] ? `${ROLE_SGR[role]}${text}${SGR_RESET}` : text;
58
- }
59
18
  export function section(s: Style, name: string): string {
60
- return paint("section", `${s.ascii ? SECTION_MARKER.ascii : SECTION_MARKER.glyph} ${name}`, s.color);
19
+ return paint([{ role: "section", text: `${s.ascii ? SECTION_MARKER.ascii : SECTION_MARKER.glyph} ${name}` }], s.color);
61
20
  }
62
21
 
63
22
  /** Wrap report prose at a stream's requested width; a pipe without COLUMNS remains unwrapped. */
23
+ // ponytail: this renderer receives already-painted strings; migrate producers to structured spans under #590.
64
24
  export function wrapReport(text: string, width: number | undefined): string {
65
25
  if (!Number.isSafeInteger(width) || width === undefined || width < 20) return text;
66
- const ansi = new RegExp(`${ESC}\\[[0-9;]*m`, "g");
26
+ const ansi = new RegExp(`${SGR_RESET[0]}\\[[0-9;]*m`, "g");
67
27
  const measure = (value: string) => cellWidth(value.replace(ansi, ""));
68
28
  return text.split("\n").flatMap(line => {
69
29
  if (measure(line) <= width) return [line];
@@ -78,7 +38,7 @@ export function wrapReport(text: string, width: number | undefined): string {
78
38
  if (measure(row + spacing + word) <= width) { row += spacing + word; spacing = ""; continue; }
79
39
  row += spacing; spacing = "";
80
40
  // Long unbroken values are continued without truncation; --json retains their exact bytes.
81
- for (const part of word.match(new RegExp(`${ESC}\\[[0-9;]*m|.`, "gu")) ?? []) {
41
+ for (const part of word.match(new RegExp(`${SGR_RESET[0]}\\[[0-9;]*m|.`, "gu")) ?? []) {
82
42
  if (measure(row + part) > width) { result.push(row); row = continuation; }
83
43
  row += part;
84
44
  }
@@ -88,14 +48,9 @@ export function wrapReport(text: string, width: number | undefined): string {
88
48
  }).join("\n");
89
49
  }
90
50
 
91
- /** Default color decision for one stream, following the shared precedence table. */
92
- export function colorEnabled(env: Readonly<Record<string, string | undefined>>, isTTY: boolean | undefined): boolean {
93
- return resolveColor("auto", streamEnv(isTTY === true, env)) === true;
94
- }
95
-
96
51
  export function style(color: boolean, ascii = true): Style {
97
- return { color, ascii, ok: text => paint("success", text, color), attention: text => paint("warning", text, color),
98
- error: text => paint("error", text, color), dim: text => paint("hint", text, color), bold: text => paint("value", text, color) };
52
+ return { color, ascii, ok: text => paint([{ role: "success", text }], color), attention: text => paint([{ role: "warning", text }], color),
53
+ error: text => paint([{ role: "error", text }], color), dim: text => paint([{ role: "hint", text }], color), bold: text => paint([{ role: "value", text }], color) };
99
54
  }
100
55
  export const PLAIN: Style = style(false);
101
56
 
@@ -107,7 +62,7 @@ export function label(s: Style, state: "ok" | "attention" | "skipped" | "unavail
107
62
  const word = { ok: "OK", attention: "ATTENTION", skipped: "SKIPPED", unavailable: "UNAVAILABLE", error: "ERROR" }[state].padEnd(11);
108
63
  const marker: MarkerName = state === "ok" ? "ok" : state === "attention" ? "warn" : state === "skipped" ? "absent" : state === "unavailable" ? "unknown" : "fail";
109
64
  const text = `${markerCell(marker, s.ascii)} ${word}`;
110
- return ` ${paint(MARKERS[marker].role, text, s.color)}`;
65
+ return ` ${paint([{ role: MARKERS[marker].role, text }], s.color)}`;
111
66
  }
112
67
 
113
68
  /** "key value" pairs, leaving out zero, empty and null values; returns "" when nothing material is left. */