@memnexus-ai/mx-agent-cli 0.1.237 → 0.1.239

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 (36) hide show
  1. package/dist/__tests__/coordination-memory.test.js +116 -2
  2. package/dist/__tests__/coordination-memory.test.js.map +1 -1
  3. package/dist/__tests__/digest-fail-closed.test.d.ts +16 -0
  4. package/dist/__tests__/digest-fail-closed.test.d.ts.map +1 -0
  5. package/dist/__tests__/digest-fail-closed.test.js +248 -0
  6. package/dist/__tests__/digest-fail-closed.test.js.map +1 -0
  7. package/dist/__tests__/memory-archive-prep.test.js +289 -4
  8. package/dist/__tests__/memory-archive-prep.test.js.map +1 -1
  9. package/dist/__tests__/pager-fail-closed.test.d.ts +19 -0
  10. package/dist/__tests__/pager-fail-closed.test.d.ts.map +1 -0
  11. package/dist/__tests__/pager-fail-closed.test.js +229 -0
  12. package/dist/__tests__/pager-fail-closed.test.js.map +1 -0
  13. package/dist/agent-config/hooks/memory-checkpoint-reminder.sh +106 -3
  14. package/dist/commands/coordination.d.ts.map +1 -1
  15. package/dist/commands/coordination.js +17 -6
  16. package/dist/commands/coordination.js.map +1 -1
  17. package/dist/commands/digest.d.ts.map +1 -1
  18. package/dist/commands/digest.js +50 -51
  19. package/dist/commands/digest.js.map +1 -1
  20. package/dist/commands/memory.d.ts +21 -4
  21. package/dist/commands/memory.d.ts.map +1 -1
  22. package/dist/commands/memory.js +45 -10
  23. package/dist/commands/memory.js.map +1 -1
  24. package/dist/commands/pager.d.ts +17 -0
  25. package/dist/commands/pager.d.ts.map +1 -1
  26. package/dist/commands/pager.js +51 -57
  27. package/dist/commands/pager.js.map +1 -1
  28. package/dist/lib/coordination-memory.d.ts +33 -5
  29. package/dist/lib/coordination-memory.d.ts.map +1 -1
  30. package/dist/lib/coordination-memory.js +43 -51
  31. package/dist/lib/coordination-memory.js.map +1 -1
  32. package/dist/lib/memory.d.ts +73 -11
  33. package/dist/lib/memory.d.ts.map +1 -1
  34. package/dist/lib/memory.js +179 -22
  35. package/dist/lib/memory.js.map +1 -1
  36. package/package.json +1 -1
@@ -20,6 +20,7 @@
20
20
  *
21
21
  * NO coordination service token is required on this path.
22
22
  */
23
+ import { type NamedMemoryReadStatus } from './memory.js';
23
24
  import type { Priority } from './coordination-client.js';
24
25
  /** Fallback product slug when neither env nor project config supplies one. */
25
26
  export declare const DEFAULT_PRODUCT_SLUG = "memnexus";
@@ -56,15 +57,23 @@ export declare function outboxName(slug: string, team: string): string;
56
57
  /** `<slug>-cross-team-escalations` — the shared, platform-composed doc. */
57
58
  export declare function sharedDocName(slug: string): string;
58
59
  export interface NamedMemoryRecord {
59
- exists: boolean;
60
+ /**
61
+ * `present` — read, content below. `absent` — POSITIVE evidence the memory is
62
+ * not there. `unknown` — the read failed; the caller must NOT create, because
63
+ * `mx memories create --name` upserts and would replace a live outbox with a
64
+ * single entry. See lib/memory.ts `classifyNamedMemoryRead` (FL-1).
65
+ */
66
+ status: NamedMemoryReadStatus;
60
67
  content: string | null;
68
+ /** Operator-facing failure detail; set when status === 'unknown'. */
69
+ reason?: string;
61
70
  }
62
71
  /**
63
72
  * Minimal named-memory access the memory backend needs. Injected in tests so the
64
73
  * fetch-edit-verify logic can be exercised without hitting the real `mx` CLI.
65
74
  */
66
75
  export interface MemoryStore {
67
- /** Fetch a named memory. `exists:false` when it is not found. */
76
+ /** Fetch a named memory. Three-state — see `NamedMemoryRecord`. */
68
77
  get(name: string): NamedMemoryRecord;
69
78
  /** Create a new named memory (used when the outbox does not yet exist). */
70
79
  create(name: string, content: string, codeContext: Record<string, string>): void;
@@ -80,6 +89,13 @@ export interface OutboxEscalateInput {
80
89
  body: string;
81
90
  productSlug: string;
82
91
  }
92
+ /**
93
+ * Thrown when the outbox could not be READ, so no write was attempted. Distinct
94
+ * from a write that ran and failed: the caller maps this to the could-not-run
95
+ * exit status (FL-14), because nothing about the send was actually tried.
96
+ */
97
+ export declare class UnreadableOutboxError extends Error {
98
+ }
83
99
  export interface OutboxEscalateResult {
84
100
  name: string;
85
101
  /** Whether the outbox was created (true) or an existing one updated (false). */
@@ -103,13 +119,23 @@ export declare function buildEntryBlock(input: OutboxEscalateInput, now?: Date):
103
119
  * 4. VERIFY: re-fetch and confirm the new block is present AND the prior content
104
120
  * is intact (no clobber). Returns verified=false if either check fails so the
105
121
  * caller can surface a hard error rather than silently losing the message.
122
+ *
123
+ * A step-1 read that FAILS (status `unknown`) throws instead of falling through
124
+ * to create. Creating on an unreadable outbox is a silent data-loss bug, not a
125
+ * conservative default: `mx memories create --name` upserts, so it would replace
126
+ * the whole outbox with this one entry — and the step-4 byte-verify cannot catch
127
+ * it, because `priorContent` is empty on that path and `priorIntact` is then
128
+ * vacuously true. One transient 500 was enough to erase the history.
106
129
  */
107
130
  export declare function escalateToOutbox(input: OutboxEscalateInput, store?: MemoryStore, now?: Date): OutboxEscalateResult;
108
131
  /**
109
132
  * Read the shared escalations doc and render entries addressed to `team`
110
- * (or broadcast to `all`) inside the provenance fence. Returns null when the
111
- * doc is absent/empty, and an empty-array marker via `entries.length === 0`
112
- * when nothing is addressed to this team.
133
+ * (or broadcast to `all`) inside the provenance fence. `present:false` means the
134
+ * doc is absent/empty; `entries.length === 0` means nothing is addressed to this
135
+ * team. `unreadable:true` means the doc could not be READ — a distinct third
136
+ * outcome, because "no coordination pending" and "I could not check whether any
137
+ * coordination is pending" are opposite facts for a session that is about to
138
+ * start work (FL-1).
113
139
  *
114
140
  * The doc is agent-authored and UNTRUSTED: every rendered line is sanitized and
115
141
  * the whole block sits inside one per-render-nonce fence, identical to the queue
@@ -119,6 +145,8 @@ export declare function escalateToOutbox(input: OutboxEscalateInput, store?: Mem
119
145
  export declare function readEscalationsForTeam(team: string, productSlug: string, store?: MemoryStore): {
120
146
  present: boolean;
121
147
  entries: string[];
148
+ unreadable: boolean;
149
+ reason?: string;
122
150
  };
123
151
  /** Render matched shared-doc blocks as a fenced, sanitized string. */
124
152
  export declare function renderEscalationBlocks(blocks: string[]): string;
@@ -1 +1 @@
1
- {"version":3,"file":"coordination-memory.d.ts","sourceRoot":"","sources":["../../src/lib/coordination-memory.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AASH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAEzD,8EAA8E;AAC9E,eAAO,MAAM,oBAAoB,aAAa,CAAC;AAC/C,8DAA8D;AAC9D,eAAO,MAAM,oBAAoB,oBAAoB,CAAC;AAGtD,4EAA4E;AAC5E,eAAO,MAAM,eAAe,sBAAsB,CAAC;AAanD;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,CAW/D;AAYD;;;;;;;;;;;;GAYG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAuB3D;AAED,2EAA2E;AAC3E,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAE7D;AAED,2EAA2E;AAC3E,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAElD;AAID,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CACxB;AAED;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC1B,iEAAiE;IACjE,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,iBAAiB,CAAC;IACrC,2EAA2E;IAC3E,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CAAC;IACjF,gEAAgE;IAChE,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAA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AC;IACX,QAAQ,EAAE,QAAQ,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;;;GAIG;AACH,qBAAa,qBAAsB,SAAQ,KAAK;CAAG;AAEnD,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,gFAAgF;IAChF,OAAO,EAAE,OAAO,CAAC;IACjB,8FAA8F;IAC9F,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,mBAAmB,EAAE,GAAG,GAAE,IAAiB,GAAG,MAAM,CAa1F;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,mBAAmB,EAC1B,KAAK,GAAE,WAAgC,EACvC,GAAG,GAAE,IAAiB,GACrB,oBAAoB,CAgCtB;AAWD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,MAAM,EACnB,KAAK,GAAE,WAAgC,GACtC;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,MAAM,EAAE,CAAC;IAAC,UAAU,EAAE,OAAO,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,CAgC/E;AAED,sEAAsE;AACtE,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,CAS/D"}
@@ -27,6 +27,7 @@ import { loadProjectConfig, resolveProjectConfig } from './project-config.js';
27
27
  import { findProjectRoot } from './worktree.js';
28
28
  import { getConfigValue } from './config.js';
29
29
  import { fenceBlock, sanitizeField } from './coordination-render.js';
30
+ import { readNamedMemoryJson } from './memory.js';
30
31
  /** Fallback product slug when neither env nor project config supplies one. */
31
32
  export const DEFAULT_PRODUCT_SLUG = 'memnexus';
32
33
  /** Env override for the product slug (highest precedence). */
@@ -129,37 +130,6 @@ export function outboxName(slug, team) {
129
130
  export function sharedDocName(slug) {
130
131
  return `${slug}-cross-team-escalations`;
131
132
  }
132
- /** Locate the leading JSON object in `mx memories get` output. */
133
- function findJsonEnd(str) {
134
- let depth = 0;
135
- let inString = false;
136
- let escape = false;
137
- for (let i = 0; i < str.length; i++) {
138
- const ch = str[i];
139
- if (escape) {
140
- escape = false;
141
- continue;
142
- }
143
- if (ch === '\\' && inString) {
144
- escape = true;
145
- continue;
146
- }
147
- if (ch === '"') {
148
- inString = !inString;
149
- continue;
150
- }
151
- if (inString)
152
- continue;
153
- if (ch === '{')
154
- depth++;
155
- else if (ch === '}') {
156
- depth--;
157
- if (depth === 0)
158
- return i + 1;
159
- }
160
- }
161
- return 0;
162
- }
163
133
  function mx(args) {
164
134
  const res = execFileSync('mx', args, {
165
135
  encoding: 'utf-8',
@@ -172,18 +142,12 @@ function mx(args) {
172
142
  /** Default store backed by the real `mx memories` CLI. */
173
143
  export const defaultMemoryStore = {
174
144
  get(name) {
175
- try {
176
- const { stdout } = mx(['memories', 'get', '--name', name, '--format', 'json']);
177
- const end = findJsonEnd(stdout);
178
- const jsonStr = end > 0 ? stdout.slice(0, end) : stdout;
179
- const parsed = JSON.parse(jsonStr);
180
- const content = typeof parsed.content === 'string' ? parsed.content : null;
181
- return { exists: content !== null, content };
182
- }
183
- catch {
184
- // Not found or any read failure → treat as absent so the caller creates it.
185
- return { exists: false, content: null };
186
- }
145
+ // Delegates to the shared three-state reader so a read failure is reported
146
+ // as `unknown` and never collapsed onto "absent". The previous shape here
147
+ // caught EVERY error to `exists:false`, which sent escalateToOutbox down the
148
+ // create path and replaced a live outbox with the single new entry.
149
+ const read = readNamedMemoryJson(name);
150
+ return { status: read.status, content: read.status === 'present' ? read.content : null, reason: read.reason };
187
151
  },
188
152
  create(name, content, codeContext) {
189
153
  mx([
@@ -203,6 +167,13 @@ export const defaultMemoryStore = {
203
167
  ]);
204
168
  },
205
169
  };
170
+ /**
171
+ * Thrown when the outbox could not be READ, so no write was attempted. Distinct
172
+ * from a write that ran and failed: the caller maps this to the could-not-run
173
+ * exit status (FL-14), because nothing about the send was actually tried.
174
+ */
175
+ export class UnreadableOutboxError extends Error {
176
+ }
206
177
  /**
207
178
  * Build one convention entry block. Priority is upcased to the P0–P3 convention.
208
179
  * Every untrusted field (team names, body) is sanitized so a crafted `--body`
@@ -232,16 +203,28 @@ export function buildEntryBlock(input, now = new Date()) {
232
203
  * 4. VERIFY: re-fetch and confirm the new block is present AND the prior content
233
204
  * is intact (no clobber). Returns verified=false if either check fails so the
234
205
  * caller can surface a hard error rather than silently losing the message.
206
+ *
207
+ * A step-1 read that FAILS (status `unknown`) throws instead of falling through
208
+ * to create. Creating on an unreadable outbox is a silent data-loss bug, not a
209
+ * conservative default: `mx memories create --name` upserts, so it would replace
210
+ * the whole outbox with this one entry — and the step-4 byte-verify cannot catch
211
+ * it, because `priorContent` is empty on that path and `priorIntact` is then
212
+ * vacuously true. One transient 500 was enough to erase the history.
235
213
  */
236
214
  export function escalateToOutbox(input, store = defaultMemoryStore, now = new Date()) {
237
215
  const name = outboxName(input.productSlug, input.fromTeam);
238
216
  const block = buildEntryBlock(input, now);
239
217
  const codeContext = { product: input.productSlug, team: input.fromTeam, service: 'coordination' };
240
218
  const before = store.get(name);
241
- const priorContent = before.exists && before.content ? before.content : '';
219
+ if (before.status === 'unknown') {
220
+ throw new UnreadableOutboxError(`could not read the current outbox "${name}" (${before.reason || 'reason unavailable'}). ` +
221
+ `Refusing to write: a create on an unread outbox would REPLACE every prior entry. ` +
222
+ `Nothing was sent — retry once MemNexus responds.`);
223
+ }
224
+ const priorContent = before.status === 'present' && before.content ? before.content : '';
242
225
  const newContent = priorContent ? `${block}\n\n${priorContent}` : block;
243
226
  let created = false;
244
- if (before.exists) {
227
+ if (before.status === 'present') {
245
228
  store.update(name, newContent, codeContext);
246
229
  }
247
230
  else {
@@ -249,6 +232,8 @@ export function escalateToOutbox(input, store = defaultMemoryStore, now = new Da
249
232
  created = true;
250
233
  }
251
234
  // Byte-verify: the block must be present and no prior entry may have vanished.
235
+ // An `unknown` re-read is NOT a pass — content is null, so blockPresent is
236
+ // false and the caller reports the write as unverified (fail loud).
252
237
  const after = store.get(name);
253
238
  const afterContent = after.content ?? '';
254
239
  const blockPresent = afterContent.includes(block);
@@ -264,9 +249,12 @@ function targetOfHeader(line) {
264
249
  }
265
250
  /**
266
251
  * Read the shared escalations doc and render entries addressed to `team`
267
- * (or broadcast to `all`) inside the provenance fence. Returns null when the
268
- * doc is absent/empty, and an empty-array marker via `entries.length === 0`
269
- * when nothing is addressed to this team.
252
+ * (or broadcast to `all`) inside the provenance fence. `present:false` means the
253
+ * doc is absent/empty; `entries.length === 0` means nothing is addressed to this
254
+ * team. `unreadable:true` means the doc could not be READ — a distinct third
255
+ * outcome, because "no coordination pending" and "I could not check whether any
256
+ * coordination is pending" are opposite facts for a session that is about to
257
+ * start work (FL-1).
270
258
  *
271
259
  * The doc is agent-authored and UNTRUSTED: every rendered line is sanitized and
272
260
  * the whole block sits inside one per-render-nonce fence, identical to the queue
@@ -275,8 +263,12 @@ function targetOfHeader(line) {
275
263
  */
276
264
  export function readEscalationsForTeam(team, productSlug, store = defaultMemoryStore) {
277
265
  const doc = store.get(sharedDocName(productSlug));
278
- if (!doc.exists || !doc.content)
279
- return { present: false, entries: [] };
266
+ if (doc.status === 'unknown') {
267
+ return { present: false, entries: [], unreadable: true, reason: doc.reason };
268
+ }
269
+ if (doc.status === 'absent' || !doc.content) {
270
+ return { present: false, entries: [], unreadable: false };
271
+ }
280
272
  // Split into blocks on a LINE-ANCHORED separator; keep only those addressed to
281
273
  // this team (or broadcast). An inline `======...` inside a body is NOT a
282
274
  // separator (it is not on its own line), so it cannot spawn a spurious block.
@@ -301,7 +293,7 @@ export function readEscalationsForTeam(team, productSlug, store = defaultMemoryS
301
293
  if (t === wanted || t === 'all')
302
294
  matched.push(block);
303
295
  }
304
- return { present: true, entries: matched };
296
+ return { present: true, entries: matched, unreadable: false };
305
297
  }
306
298
  /** Render matched shared-doc blocks as a fenced, sanitized string. */
307
299
  export function renderEscalationBlocks(blocks) {
@@ -1 +1 @@
1
- {"version":3,"file":"coordination-memory.js","sourceRoot":"","sources":["../../src/lib/coordination-memory.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC9E,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAGrE,8EAA8E;AAC9E,MAAM,CAAC,MAAM,oBAAoB,GAAG,UAAU,CAAC;AAC/C,8DAA8D;AAC9D,MAAM,CAAC,MAAM,oBAAoB,GAAG,iBAAiB,CAAC;AACtD,6EAA6E;AAC7E,MAAM,WAAW,GAAG,uBAAuB,CAAC;AAC5C,4EAA4E;AAC5E,MAAM,CAAC,MAAM,eAAe,GAAG,mBAAmB,CAAC;AACnD,yDAAyD;AACzD,MAAM,SAAS,GAAG,wCAAwC,CAAC;AAC3D;;;;;;;GAOG;AACH,MAAM,oBAAoB,GAAG,mBAAmB,CAAC;AAEjD;;;;;;;;GAQG;AACH,MAAM,UAAU,kBAAkB,CAAC,WAAoB;IACrD,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,EAAE,IAAI,EAAE,CAAC;IACtD,IAAI,GAAG;QAAE,OAAO,GAAG,CAAC;IACpB,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,WAAW,IAAI,eAAe,EAAE,CAAC;QAC9C,MA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,CAAC,CAAC;AAC3B,CAAC"}
@@ -120,18 +120,80 @@ export declare function getNamedMemory(name: string): {
120
120
  output: string;
121
121
  };
122
122
  /**
123
- * Fetch a named memory's structured JSON and return whether it exists plus its
124
- * content. `mx memories get` exits 0 even for a missing memory (it prints a
125
- * "Not Found" banner instead of JSON), so `ok`/exit-code alone cannot tell
126
- * existence — we detect it by parsing the JSON body. Tolerant of status/spinner
127
- * lines printed before the JSON: we parse from the first `{`.
123
+ * Outcome of one named-memory read. THREE states, never two (fail-loud FL-1):
124
+ * a read that could not be performed must never render as "the memory is not
125
+ * there", because every caller of this module treats absence as a licence to
126
+ * CREATE — and `mx memories create --name` UPSERTS silently.
128
127
  *
129
- * Used by `archive-prep` for the collision check — `mx memories create --name`
130
- * UPSERTS silently, so we must positively confirm an archive name is free before
131
- * suggesting it.
128
+ * - `present` — the memory was read and its JSON body is in `body`/`content`.
129
+ * - `absent` — POSITIVE evidence the name is free.
130
+ * - `unknown` — the read failed. `reason` names the exit status. Callers must
131
+ * fail closed: do not create, do not report an empty result.
132
132
  */
133
- export declare function getNamedMemoryJson(name: string): {
134
- exists: boolean;
133
+ export type NamedMemoryReadStatus = 'present' | 'absent' | 'unknown';
134
+ export interface NamedMemoryRead {
135
+ status: NamedMemoryReadStatus;
136
+ /** The memory's `content` field; '' unless status === 'present'. */
135
137
  content: string;
136
- };
138
+ /** The parsed top-level JSON object; undefined unless status === 'present'. */
139
+ body?: Record<string, unknown>;
140
+ /** Operator-facing explanation. Set whenever status === 'unknown'. */
141
+ reason?: string;
142
+ /** Child exit status; null when the process could not be spawned or was killed. */
143
+ exitCode: number | null;
144
+ }
145
+ /**
146
+ * Parse the leading top-level JSON object out of `stdout`, tolerating any
147
+ * preamble before the first `{` and any trailing text after the object closes.
148
+ * Returns null when no complete object can be parsed.
149
+ */
150
+ export declare function parseLeadingJsonObject(stdout: string): Record<string, unknown> | null;
151
+ /**
152
+ * Classify one `mx memories get ... --format json` invocation. Pure, so the
153
+ * fault paths are unit-testable without spawning anything (FL-16).
154
+ *
155
+ * `absent` requires POSITIVE evidence, and exactly ONE shape qualifies: the exit
156
+ * status is mx's not-found code AND mx's own anchored not-found banner is on
157
+ * stderr. BOTH conditions are required — either alone is forgeable or ambiguous.
158
+ *
159
+ * Everything else is `unknown`: any other non-zero status, a killed/timed-out
160
+ * child, a spawn failure, a body that will not parse, and exit 0 with no JSON
161
+ * body. That last one is not an inferred absence — no live mx path produces it
162
+ * (a genuine miss exits 1), so if we ever see it, something we do not model has
163
+ * happened and guessing "the memory is not there" is exactly the inference this
164
+ * function exists to refuse.
165
+ *
166
+ * Matching the marker on STDERR only is deliberate (CWE-20): memory content is
167
+ * attacker-influenced and is echoed on stdout, so a memory whose body contained
168
+ * the words "not found" must not be able to make its own read look like a miss.
169
+ */
170
+ export declare function classifyNamedMemoryRead(res: {
171
+ status: number | null;
172
+ stdout: string;
173
+ stderr: string;
174
+ spawnFailed: boolean;
175
+ errorMessage?: string;
176
+ }): NamedMemoryRead;
177
+ /**
178
+ * Redact credential-shaped substrings from text that is about to be surfaced.
179
+ *
180
+ * Failure reasons built here travel a long way: onto the operator's terminal,
181
+ * into escalation bodies, into memory content, into CI logs. mx relays server
182
+ * message bodies verbatim, and a misconfigured or echoing endpoint can put an
183
+ * Authorization header or a connection string into one. Redacting at the single
184
+ * point where the reason string is built means every consumer inherits it.
185
+ *
186
+ * Order matters: the labelled-secret pattern runs after the bare-token patterns
187
+ * so a labelled Bearer token is not partially consumed first.
188
+ */
189
+ export declare function redactSecrets(text: string): string;
190
+ /**
191
+ * Read a named memory's structured JSON, three-state (see `NamedMemoryRead`).
192
+ *
193
+ * `--format json` is passed EXPLICITLY and must stay: without it the CLI falls
194
+ * back to `config.getFormat()`, whose shipped default is `table`. Every caller
195
+ * here parses JSON, so an unset local config would otherwise turn every read
196
+ * into a silent miss on any host but our own.
197
+ */
198
+ export declare function readNamedMemoryJson(name: string): NamedMemoryRead;
137
199
  //# sourceMappingURL=memory.d.ts.map
@@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CACvB,GAAG,eAAe,CA0ClB;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CASlD;AAeD;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,CAcjE"}
@@ -228,33 +228,190 @@ export function getNamedMemory(name) {
228
228
  return { ok, output: output.trim() };
229
229
  }
230
230
  /**
231
- * Fetch a named memory's structured JSON and return whether it exists plus its
232
- * content. `mx memories get` exits 0 even for a missing memory (it prints a
233
- * "Not Found" banner instead of JSON), so `ok`/exit-code alone cannot tell
234
- * existence — we detect it by parsing the JSON body. Tolerant of status/spinner
235
- * lines printed before the JSON: we parse from the first `{`.
231
+ * Parse the leading top-level JSON object out of `stdout`, tolerating any
232
+ * preamble before the first `{` and any trailing text after the object closes.
233
+ * Returns null when no complete object can be parsed.
234
+ */
235
+ export function parseLeadingJsonObject(stdout) {
236
+ const start = stdout.indexOf('{');
237
+ if (start === -1)
238
+ return null;
239
+ let depth = 0;
240
+ let inString = false;
241
+ let escape = false;
242
+ let end = -1;
243
+ for (let i = start; i < stdout.length; i++) {
244
+ const ch = stdout[i];
245
+ if (escape) {
246
+ escape = false;
247
+ continue;
248
+ }
249
+ if (ch === '\\' && inString) {
250
+ escape = true;
251
+ continue;
252
+ }
253
+ if (ch === '"') {
254
+ inString = !inString;
255
+ continue;
256
+ }
257
+ if (inString)
258
+ continue;
259
+ if (ch === '{')
260
+ depth++;
261
+ else if (ch === '}') {
262
+ depth--;
263
+ if (depth === 0) {
264
+ end = i + 1;
265
+ break;
266
+ }
267
+ }
268
+ }
269
+ if (end === -1)
270
+ return null;
271
+ try {
272
+ const obj = JSON.parse(stdout.slice(start, end));
273
+ return obj && typeof obj === 'object' && !Array.isArray(obj)
274
+ ? obj
275
+ : null;
276
+ }
277
+ catch {
278
+ return null;
279
+ }
280
+ }
281
+ /**
282
+ * The exit status mx uses for a 404. Verified against mx 1.7.220: 1 = not found,
283
+ * 2 = 422 validation, 3 = 401/403 auth, 4 = network, 5 = 429/5xx/other API error.
284
+ * Note 1 is ALSO the generic unhandled-error code, so the status alone is not
285
+ * sufficient — it is one of two required conditions below.
286
+ */
287
+ const MX_EXIT_NOT_FOUND = 1;
288
+ /**
289
+ * mx's OWN not-found banner line, anchored to the start of a line.
290
+ *
291
+ * Anchoring is a security control, not tidiness. mx relays server-supplied
292
+ * message bodies to stderr verbatim, so an unanchored /not found/ would let a
293
+ * 502 carrying "upstream service not found" — or any API response body an
294
+ * attacker can influence — classify as `absent`, which re-opens the outbox
295
+ * clobber this whole change exists to close. The real banner is
296
+ * `❌ Not Found: Resource does not exist`, so we allow only leading
297
+ * non-word characters (the emoji, ANSI colour bytes, whitespace) before it.
298
+ * `\b404\b` is deliberately absent: it never appears in mx's own banner and
299
+ * matched only relayed prose.
300
+ */
301
+ const NOT_FOUND_STDERR_RE = /^[^\w]*not found\b/im;
302
+ /**
303
+ * Classify one `mx memories get ... --format json` invocation. Pure, so the
304
+ * fault paths are unit-testable without spawning anything (FL-16).
305
+ *
306
+ * `absent` requires POSITIVE evidence, and exactly ONE shape qualifies: the exit
307
+ * status is mx's not-found code AND mx's own anchored not-found banner is on
308
+ * stderr. BOTH conditions are required — either alone is forgeable or ambiguous.
309
+ *
310
+ * Everything else is `unknown`: any other non-zero status, a killed/timed-out
311
+ * child, a spawn failure, a body that will not parse, and exit 0 with no JSON
312
+ * body. That last one is not an inferred absence — no live mx path produces it
313
+ * (a genuine miss exits 1), so if we ever see it, something we do not model has
314
+ * happened and guessing "the memory is not there" is exactly the inference this
315
+ * function exists to refuse.
236
316
  *
237
- * Used by `archive-prep` for the collision check — `mx memories create --name`
238
- * UPSERTS silently, so we must positively confirm an archive name is free before
239
- * suggesting it.
317
+ * Matching the marker on STDERR only is deliberate (CWE-20): memory content is
318
+ * attacker-influenced and is echoed on stdout, so a memory whose body contained
319
+ * the words "not found" must not be able to make its own read look like a miss.
240
320
  */
241
- export function getNamedMemoryJson(name) {
321
+ export function classifyNamedMemoryRead(res) {
322
+ if (res.spawnFailed) {
323
+ return {
324
+ status: 'unknown',
325
+ content: '',
326
+ exitCode: res.status,
327
+ reason: `mx could not be run${res.errorMessage ? `: ${redactSecrets(res.errorMessage).slice(0, 160)}` : ''}`,
328
+ };
329
+ }
330
+ if (res.status === 0) {
331
+ const body = parseLeadingJsonObject(res.stdout);
332
+ if (!body) {
333
+ // Success status with no success body: unmodelled, so unknown — never a
334
+ // guess that the memory is missing.
335
+ return {
336
+ status: 'unknown',
337
+ content: '',
338
+ exitCode: 0,
339
+ reason: 'mx exited 0 but printed no JSON body',
340
+ };
341
+ }
342
+ const content = typeof body.content === 'string' ? body.content : '';
343
+ return { status: 'present', content, body, exitCode: 0 };
344
+ }
345
+ // BOTH conditions required — see NOT_FOUND_STDERR_RE for why the status check
346
+ // alone is insufficient and why the banner match alone is forgeable.
347
+ if (res.status === MX_EXIT_NOT_FOUND && NOT_FOUND_STDERR_RE.test(res.stderr)) {
348
+ return { status: 'absent', content: '', exitCode: res.status };
349
+ }
350
+ const detail = firstMeaningfulLine(res.stderr);
351
+ return {
352
+ status: 'unknown',
353
+ content: '',
354
+ exitCode: res.status,
355
+ reason: res.status === null
356
+ ? `mx was killed or timed out${detail ? ` (${detail})` : ''}`
357
+ : `mx exited ${res.status}${detail ? ` (${detail})` : ''}`,
358
+ };
359
+ }
360
+ /**
361
+ * Redact credential-shaped substrings from text that is about to be surfaced.
362
+ *
363
+ * Failure reasons built here travel a long way: onto the operator's terminal,
364
+ * into escalation bodies, into memory content, into CI logs. mx relays server
365
+ * message bodies verbatim, and a misconfigured or echoing endpoint can put an
366
+ * Authorization header or a connection string into one. Redacting at the single
367
+ * point where the reason string is built means every consumer inherits it.
368
+ *
369
+ * Order matters: the labelled-secret pattern runs after the bare-token patterns
370
+ * so a labelled Bearer token is not partially consumed first.
371
+ */
372
+ export function redactSecrets(text) {
373
+ return text
374
+ .replace(/Bearer\s+\S+/gi, 'Bearer [REDACTED]')
375
+ // URL userinfo: scheme://user:password@host
376
+ .replace(/\/\/[^/@\s]+:[^/@\s]+@/g, '//[REDACTED]@')
377
+ // Common API-key prefixes: mx_/mx-, sk_/sk-, ghp_, xoxb-/xoxp-/xoxa-
378
+ .replace(/\b(mx|sk|ghp|xox[bap])[-_][A-Za-z0-9_-]{8,}/g, '$1_[REDACTED]')
379
+ // Labelled secrets: api_key=…, token: …, password=…, authorization: …
380
+ .replace(/\b(api[-_]?key|token|password|authorization)\s*[:=]\s*\S+/gi, '$1=[REDACTED]');
381
+ }
382
+ /**
383
+ * First non-empty, non-spinner line of stderr — for one-line failure reasons.
384
+ * Redaction happens BEFORE truncation, so a secret cannot survive by sitting
385
+ * past the 160-character cut and then being re-exposed if the cap ever changes.
386
+ */
387
+ function firstMeaningfulLine(stderr) {
388
+ const line = stderr
389
+ .split('\n')
390
+ .map((l) => l.replace(/^[-\\|/\s✔✖❌⚠]+/, '').trim())
391
+ .find((l) => l.length > 0);
392
+ return line ? redactSecrets(line).slice(0, 160) : '';
393
+ }
394
+ /**
395
+ * Read a named memory's structured JSON, three-state (see `NamedMemoryRead`).
396
+ *
397
+ * `--format json` is passed EXPLICITLY and must stay: without it the CLI falls
398
+ * back to `config.getFormat()`, whose shipped default is `table`. Every caller
399
+ * here parses JSON, so an unset local config would otherwise turn every read
400
+ * into a silent miss on any host but our own.
401
+ */
402
+ export function readNamedMemoryJson(name) {
242
403
  const result = spawnSync('mx', ['memories', 'get', '--name', name, '--format', 'json'], {
243
404
  stdio: 'pipe',
244
405
  encoding: 'utf-8',
406
+ timeout: 15000,
407
+ maxBuffer: 1024 * 1024,
408
+ });
409
+ return classifyNamedMemoryRead({
410
+ status: result.status,
411
+ stdout: result.stdout || '',
412
+ stderr: result.stderr || '',
413
+ spawnFailed: Boolean(result.error),
414
+ errorMessage: result.error?.message,
245
415
  });
246
- const stdout = result.stdout || '';
247
- const brace = stdout.indexOf('{');
248
- if (brace === -1)
249
- return { exists: false, content: '' };
250
- try {
251
- const obj = JSON.parse(stdout.slice(brace));
252
- const exists = Boolean(obj && (obj.id || obj.content !== undefined));
253
- const content = typeof obj.content === 'string' ? obj.content : '';
254
- return { exists, content };
255
- }
256
- catch {
257
- return { exists: false, content: '' };
258
- }
259
416
  }
260
417
  //# sourceMappingURL=memory.js.map