@memnexus-ai/mx-agent-cli 0.1.280 → 0.1.281

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 (32) hide show
  1. package/dist/__tests__/coordination-401-production-wiring.test.js +119 -1
  2. package/dist/__tests__/coordination-401-production-wiring.test.js.map +1 -1
  3. package/dist/__tests__/coordination-401-recovery.test.js +4 -1
  4. package/dist/__tests__/coordination-401-recovery.test.js.map +1 -1
  5. package/dist/__tests__/coordination-command.test.js +78 -1
  6. package/dist/__tests__/coordination-command.test.js.map +1 -1
  7. package/dist/__tests__/coordination-history.test.js +95 -1
  8. package/dist/__tests__/coordination-history.test.js.map +1 -1
  9. package/dist/__tests__/coordination-provision.test.js +4 -1
  10. package/dist/__tests__/coordination-provision.test.js.map +1 -1
  11. package/dist/__tests__/coordination-render.test.js +196 -0
  12. package/dist/__tests__/coordination-render.test.js.map +1 -1
  13. package/dist/__tests__/session-pause-provisioning.test.d.ts +19 -0
  14. package/dist/__tests__/session-pause-provisioning.test.d.ts.map +1 -0
  15. package/dist/__tests__/session-pause-provisioning.test.js +110 -0
  16. package/dist/__tests__/session-pause-provisioning.test.js.map +1 -0
  17. package/dist/commands/coordination.d.ts +88 -4
  18. package/dist/commands/coordination.d.ts.map +1 -1
  19. package/dist/commands/coordination.js +137 -25
  20. package/dist/commands/coordination.js.map +1 -1
  21. package/dist/commands/session.d.ts.map +1 -1
  22. package/dist/commands/session.js +33 -2
  23. package/dist/commands/session.js.map +1 -1
  24. package/dist/lib/coordination-client.d.ts +13 -2
  25. package/dist/lib/coordination-client.d.ts.map +1 -1
  26. package/dist/lib/coordination-client.js +12 -3
  27. package/dist/lib/coordination-client.js.map +1 -1
  28. package/dist/lib/coordination-render.d.ts +23 -3
  29. package/dist/lib/coordination-render.d.ts.map +1 -1
  30. package/dist/lib/coordination-render.js +80 -8
  31. package/dist/lib/coordination-render.js.map +1 -1
  32. package/package.json +1 -1
@@ -12,6 +12,40 @@
12
12
  import { ServiceHttpError, type CoordinationClient } from '../lib/coordination-client.js';
13
13
  import { type TokenRefreshResult } from '../lib/coordination-token.js';
14
14
  import { type MemoryStore } from '../lib/coordination-memory.js';
15
+ /**
16
+ * Truncate each body to this many chars where a full message is rendered LIVE
17
+ * (`drain`, `watch`). Not applied to `history` — see `runHistory`.
18
+ *
19
+ * These sites once passed no ceiling at all, and a single multi-megabyte body
20
+ * landed whole in the reader's context. 4,000 chars (2026-08-03, 6812efae1) was
21
+ * too tight in the other direction: within two days it cut four launch go/no-go
22
+ * attestations, one of them losing the recommendation the message existed to
23
+ * deliver (#5188).
24
+ *
25
+ * 16,000 is set from the traffic rather than from a token budget: the longest
26
+ * real attestations observed run to about 7,000 characters, so the ceiling sits
27
+ * at roughly twice the largest message anyone has actually sent — a message has
28
+ * to be far outside normal shape before a reader loses anything. It is about 4k
29
+ * tokens, so the worst case for a default 10-message drain is ~40k tokens.
30
+ *
31
+ * IT IS NOT BACKED BY A WRITE CEILING (corrected — security review of #5188). An
32
+ * earlier version of this comment said 16,000 sat "16x below the 256 KiB write
33
+ * ceiling (MAX_BODY_BYTES), which is the bound that stops a log dump". That was
34
+ * wrong in the way that matters: `MAX_BODY_BYTES` is enforced in `runEscalate`, in
35
+ * this process, so it binds only a sender who uses this CLI. Anything speaking
36
+ * HTTP to the service met no size rule at all — `service.enqueue` validated only
37
+ * that the body was a non-empty string, and the sole ceiling was the 1,000,000-byte
38
+ * read cap in `server/http-server.ts`. The server-side 256 KiB check now exists
39
+ * (`MAX_BODY_CHARS` in coordination-service/src/service.ts, SF-4), and it is THAT
40
+ * check, not this constant's neighbour, that stops a log dump.
41
+ *
42
+ * A cut is now marked at BOTH ends of the body by `renderMessageLine` (#5188),
43
+ * senders are warned at send time (`warnOversizeBody`), and the full body is
44
+ * always retrievable — the service archive holds every byte and `history` renders
45
+ * up to `HISTORY_BODY_MAX_CHARS` (100,000), 6x this ceiling and ~14x the largest
46
+ * message ever observed.
47
+ */
48
+ export declare const MESSAGE_BODY_MAX_CHARS = 16000;
15
49
  /**
16
50
  * Stable first line of the loud terminal auth failure. The session-start hook
17
51
  * greps the CLI's stderr for this (coordination-brief.sh) — keep the two in
@@ -33,7 +67,7 @@ export declare class CoordinationAuthError extends ServiceHttpError {
33
67
  constructor(message: string);
34
68
  }
35
69
  /** Test-visible constructor for the 401-recovery wrapper (see AuthRetryingClient). */
36
- export declare function withTokenRefresh(inner: CoordinationClient, rebuild: (token: string) => CoordinationClient, refresh?: (rejectedToken: string) => TokenRefreshResult): CoordinationClient;
70
+ export declare function withTokenRefresh(inner: CoordinationClient, rebuild: (token: string) => CoordinationClient, refresh?: (rejectedToken: string) => TokenRefreshResult, initialToken?: string): CoordinationClient;
37
71
  /**
38
72
  * Build the HTTP client, self-provisioning the coordination token from Key Vault
39
73
  * when none is configured. This ports the coordination-brief hook's KV-fetch into
@@ -48,9 +82,15 @@ export declare function withTokenRefresh(inner: CoordinationClient, rebuild: (to
48
82
  * - infra/no-marker → fail-OPEN, one-line notice.
49
83
  * When a client IS injected (tests), provisioning is skipped entirely.
50
84
  *
51
- * The resolved token is set in-memory (process env for the request) and is NEVER
52
- * written to the global ~/.mx-agent config (the MF-2 cross-worktree-clobber
53
- * defect) and NEVER logged.
85
+ * The resolved token is passed to the client through its ClientConfig ONLY. It is
86
+ * never written to the global ~/.mx-agent config (the MF-2 cross-worktree-clobber
87
+ * defect), never logged, and — since SF-2 of the #5188/#5189 security review —
88
+ * never assigned to `process.env.MX_COORD_SERVICE_TOKEN` either. The env write was
89
+ * harmless while nothing on these paths spawned a child, but `session pause` now
90
+ * calls prepareClient (#5189), and a bearer in the environment is inherited by any
91
+ * subprocess a future change adds. Non-secret interlock state (MX_COORD_EXPECT_TEAM)
92
+ * still goes through env — it is read by the session-start hook in another process,
93
+ * which is the whole point of it.
54
94
  */
55
95
  export declare function prepareClient(deps?: CoordinationDeps): CoordinationClient | null;
56
96
  /**
@@ -250,6 +290,33 @@ export interface HistoryOptions {
250
290
  /** Fetch the full history by following the pagination cursor. */
251
291
  all?: boolean;
252
292
  }
293
+ /**
294
+ * Per-row retrieval ceiling for `history` (security review of #5188).
295
+ *
296
+ * #5188 removed the body ceiling here entirely, and that was too far. Row COUNT is
297
+ * bounded (`--limit`, `HISTORY_MAX_PAGES`) but row SIZE was chosen by the sender,
298
+ * and the same change made broadcasts (`to_team='all'`) reachable from every team's
299
+ * archive query — so one sender could put an arbitrarily large body into every
300
+ * team's retrieval path, permanently (the archive is never trimmed and retention is
301
+ * off by default).
302
+ *
303
+ * 100,000 chars keeps what #5188 was for: the longest real attestation measured is
304
+ * 7,210 chars, so the ceiling is ~14x the largest message anyone has actually sent
305
+ * and every observed body still round-trips byte-for-byte. A cut above it is marked
306
+ * at both ends, and the archive still holds every byte.
307
+ */
308
+ export declare const HISTORY_BODY_MAX_CHARS = 100000;
309
+ /**
310
+ * Whole-render ceiling for `history`. A per-row ceiling does not bound
311
+ * rows x row-size — 200 rows (the service page cap) at 100,000 chars each is 20M
312
+ * characters into a reader's context. This bounds the product. Rows past it are
313
+ * dropped with a renderer-generated count line telling the reader to narrow with
314
+ * `--limit`; nothing is lost, the archive still has it.
315
+ *
316
+ * 2,000,000 chars is ~500k tokens: above any real history page (50 rows of ~7k is
317
+ * ~350k chars) and below the point where one command can fill a context window.
318
+ */
319
+ export declare const HISTORY_RENDER_MAX_CHARS = 2000000;
253
320
  /**
254
321
  * Durable-archive history for THIS team (as sender or recipient). Fetches
255
322
  * GET /archive — team-bound server-side from the token — and renders it through
@@ -259,6 +326,23 @@ export interface HistoryOptions {
259
326
  * follows the `nextBefore` cursor to page the full history (most-recent-first).
260
327
  */
261
328
  export declare function runHistory(opts?: HistoryOptions, deps?: CoordinationDeps): Promise<void>;
329
+ /**
330
+ * Warn the SENDER, at send time, that this body is longer than a live render
331
+ * will show (#5188).
332
+ *
333
+ * Both this CLI (`MAX_BODY_BYTES`, in `runEscalate`) and the service
334
+ * (`MAX_BODY_CHARS`, in `service.enqueue`) REJECT above 256 KiB — a different, much
335
+ * higher, blocking limit against a log dump. This is advisory and
336
+ * never blocks: the message is delivered whole and the archive keeps every byte,
337
+ * but the recipient's `drain`/`watch` shows the first `MESSAGE_BODY_MAX_CHARS`
338
+ * characters. Until now the only party who could tell was the recipient, and only
339
+ * if they spotted the marker. The sender is the party who can act on it — by
340
+ * putting the conclusion first, or by splitting the message.
341
+ *
342
+ * Returns the warning text (or undefined) rather than printing, so it is testable
343
+ * without capturing stderr.
344
+ */
345
+ export declare function oversizeBodyWarning(body: string): string | undefined;
262
346
  export interface StatusDeps {
263
347
  /** Override fetch for the healthz ping (test seam). */
264
348
  fetch?: typeof globalThis.fetch;
@@ -1 +1 @@
1
- {"version":3,"file":"coordination.d.ts","sourceRoot":"","sources":["../../src/commands/coordination.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAKH,OAAO,EAKL,gBAAgB,EAEhB,KAAK,kBAAkB,EAExB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAIL,KAAK,kBAAkB,EACxB,MAAM,8BAA8B,CAAC;AAQtC,OAAO,EAOL,KAAK,WAAW,EACjB,MAAM,+BAA+B,CAAC;AA8HvC;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB,4CAA4C,CAAC;AAE/E;;;;;;;;;GASG;AACH,qBAAa,qBAAsB,SAAQ,gBAAgB;gBAC7C,OAAO,EAAE,MAAM;CAI5B;AA6KD,sFAAsF;AACtF,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,kBAAkB,EACzB,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,kBAAkB,EAC9C,OAAO,CAAC,EAAE,CAAC,aAAa,EAAE,MAAM,KAAK,kBAAkB,GACtD,kBAAkB,CAEpB;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,aAAa,CAAC,IAAI,CAAC,EAAE,gBAAgB,GAAG,kBAAkB,GAAG,IAAI,CAgEhF;AAkCD;;;;GAIG;AACH,MAAM,WAAW,gB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SAAS;IACxB,wDAAwD;IACxD,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;IAChC,2CAA2C;IAC3C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,+EAA+E;IAC/E,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;CACzB;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAK1D;AAiDD;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,QAAQ,CAAC,IAAI,EAAE,YAAY,EAAE,IAAI,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CA8RlF"}
@@ -41,16 +41,39 @@ const BUILTIN_TEAM_DESCRIPTIONS = {
41
41
  /** Truncate each body to this many chars in the brief (token-ceiling control). */
42
42
  const BRIEF_BODY_MAX_CHARS = 500;
43
43
  /**
44
- * Truncate each body to this many chars everywhere a full message is rendered
45
- * (`drain`, `watch`, `history`). The brief's 500-char summary ceiling is too
46
- * tight for reading a real escalation, but these three sites previously passed
47
- * NO ceiling at all: a single multi-megabyte body landed whole in the reader's
48
- * context. 4,000 chars is roughly 1k tokens per message — long enough to carry a
49
- * complete incident report, bounded enough that a runaway body cannot exhaust a
50
- * reader that drains twenty messages at once. Truncation is marked inline by
51
- * `renderMessageLine`, and the full body remains retrievable from the service.
44
+ * Truncate each body to this many chars where a full message is rendered LIVE
45
+ * (`drain`, `watch`). Not applied to `history` — see `runHistory`.
46
+ *
47
+ * These sites once passed no ceiling at all, and a single multi-megabyte body
48
+ * landed whole in the reader's context. 4,000 chars (2026-08-03, 6812efae1) was
49
+ * too tight in the other direction: within two days it cut four launch go/no-go
50
+ * attestations, one of them losing the recommendation the message existed to
51
+ * deliver (#5188).
52
+ *
53
+ * 16,000 is set from the traffic rather than from a token budget: the longest
54
+ * real attestations observed run to about 7,000 characters, so the ceiling sits
55
+ * at roughly twice the largest message anyone has actually sent — a message has
56
+ * to be far outside normal shape before a reader loses anything. It is about 4k
57
+ * tokens, so the worst case for a default 10-message drain is ~40k tokens.
58
+ *
59
+ * IT IS NOT BACKED BY A WRITE CEILING (corrected — security review of #5188). An
60
+ * earlier version of this comment said 16,000 sat "16x below the 256 KiB write
61
+ * ceiling (MAX_BODY_BYTES), which is the bound that stops a log dump". That was
62
+ * wrong in the way that matters: `MAX_BODY_BYTES` is enforced in `runEscalate`, in
63
+ * this process, so it binds only a sender who uses this CLI. Anything speaking
64
+ * HTTP to the service met no size rule at all — `service.enqueue` validated only
65
+ * that the body was a non-empty string, and the sole ceiling was the 1,000,000-byte
66
+ * read cap in `server/http-server.ts`. The server-side 256 KiB check now exists
67
+ * (`MAX_BODY_CHARS` in coordination-service/src/service.ts, SF-4), and it is THAT
68
+ * check, not this constant's neighbour, that stops a log dump.
69
+ *
70
+ * A cut is now marked at BOTH ends of the body by `renderMessageLine` (#5188),
71
+ * senders are warned at send time (`warnOversizeBody`), and the full body is
72
+ * always retrievable — the service archive holds every byte and `history` renders
73
+ * up to `HISTORY_BODY_MAX_CHARS` (100,000), 6x this ceiling and ~14x the largest
74
+ * message ever observed.
52
75
  */
53
- const MESSAGE_BODY_MAX_CHARS = 4000;
76
+ export const MESSAGE_BODY_MAX_CHARS = 16_000;
54
77
  /** Watch backoff cap: 5 minutes (KI-COORDCLI-WATCH-NO-RETRY). */
55
78
  const WATCH_BACKOFF_CAP_MS = 5 * 60 * 1000;
56
79
  /**
@@ -245,10 +268,20 @@ class AuthRetryingClient {
245
268
  * credential problem this client can solve.
246
269
  */
247
270
  refreshes = 0;
248
- constructor(inner, rebuild, refresh) {
271
+ /**
272
+ * The bearer this wrapper's current client is using, so a refresh can name the
273
+ * REJECTED token without reading it back out of `process.env` (SF-2 of the #5188
274
+ * / #5189 security review: the token is a secret and the process environment is
275
+ * inherited by every subprocess). Undefined for an injected client that supplied
276
+ * no token — those fall back to the env read, which is where callers that set
277
+ * MX_COORD_SERVICE_TOKEN themselves still put it.
278
+ */
279
+ currentToken;
280
+ constructor(inner, rebuild, refresh, initialToken) {
249
281
  this.rebuild = rebuild;
250
282
  this.refresh = refresh;
251
283
  this.client = inner;
284
+ this.currentToken = initialToken;
252
285
  }
253
286
  async run(op) {
254
287
  try {
@@ -268,7 +301,7 @@ class AuthRetryingClient {
268
301
  }, false));
269
302
  }
270
303
  this.refreshes++;
271
- const rejected = process.env.MX_COORD_SERVICE_TOKEN ?? '';
304
+ const rejected = this.currentToken ?? process.env.MX_COORD_SERVICE_TOKEN ?? '';
272
305
  let res;
273
306
  try {
274
307
  res = this.refresh(rejected);
@@ -283,8 +316,10 @@ class AuthRetryingClient {
283
316
  this.exhausted = true;
284
317
  throw new CoordinationAuthError(authFailureMessage(res, false));
285
318
  }
286
- // In-memory only (same contract as prepareClient): never the global config.
287
- process.env.MX_COORD_SERVICE_TOKEN = res.token;
319
+ // In-process only, and NOT via process.env (SF-2): the fresh bearer goes to
320
+ // the rebuilt client's config and to this field. It is never written to the
321
+ // global config either.
322
+ this.currentToken = res.token;
288
323
  this.client = this.rebuild(res.token);
289
324
  try {
290
325
  return await op(this.client);
@@ -307,8 +342,8 @@ class AuthRetryingClient {
307
342
  getObligations() { return this.run((c) => c.getObligations()); }
308
343
  }
309
344
  /** Test-visible constructor for the 401-recovery wrapper (see AuthRetryingClient). */
310
- export function withTokenRefresh(inner, rebuild, refresh) {
311
- return new AuthRetryingClient(inner, rebuild, refresh);
345
+ export function withTokenRefresh(inner, rebuild, refresh, initialToken) {
346
+ return new AuthRetryingClient(inner, rebuild, refresh, initialToken);
312
347
  }
313
348
  /**
314
349
  * Build the HTTP client, self-provisioning the coordination token from Key Vault
@@ -324,9 +359,15 @@ export function withTokenRefresh(inner, rebuild, refresh) {
324
359
  * - infra/no-marker → fail-OPEN, one-line notice.
325
360
  * When a client IS injected (tests), provisioning is skipped entirely.
326
361
  *
327
- * The resolved token is set in-memory (process env for the request) and is NEVER
328
- * written to the global ~/.mx-agent config (the MF-2 cross-worktree-clobber
329
- * defect) and NEVER logged.
362
+ * The resolved token is passed to the client through its ClientConfig ONLY. It is
363
+ * never written to the global ~/.mx-agent config (the MF-2 cross-worktree-clobber
364
+ * defect), never logged, and — since SF-2 of the #5188/#5189 security review —
365
+ * never assigned to `process.env.MX_COORD_SERVICE_TOKEN` either. The env write was
366
+ * harmless while nothing on these paths spawned a child, but `session pause` now
367
+ * calls prepareClient (#5189), and a bearer in the environment is inherited by any
368
+ * subprocess a future change adds. Non-secret interlock state (MX_COORD_EXPECT_TEAM)
369
+ * still goes through env — it is read by the session-start hook in another process,
370
+ * which is the whole point of it.
330
371
  */
331
372
  export function prepareClient(deps) {
332
373
  if (deps?.client) {
@@ -348,20 +389,21 @@ export function prepareClient(deps) {
348
389
  let res = { status: 'unprovisioned', detail: 'token resolution failed' };
349
390
  try {
350
391
  res = resolveCoordinationToken();
392
+ let provisioned;
351
393
  if (res.status === 'resolved' && res.token) {
352
- // In-memory only: resolveClientConfig reads MX_COORD_SERVICE_TOKEN in
353
- // preference to the global config, so we never touch the shared config file.
354
- process.env.MX_COORD_SERVICE_TOKEN = res.token;
394
+ // Handed to resolveClientConfig as an override — in-process, never env, never
395
+ // the shared config file (SF-2).
396
+ provisioned = res.token;
355
397
  // SF-B: arm the SF-1 verify-before-confirm interlock on the bare
356
398
  // self-provisioned path, matching the hook (which set MX_COORD_EXPECT_TEAM).
357
- // `??=` so an explicit hook-set value is never overwritten.
399
+ // `??=` so an explicit hook-set value is never overwritten. Not a secret.
358
400
  if (res.slug)
359
401
  process.env.MX_COORD_EXPECT_TEAM ??= res.slug;
360
402
  }
361
- const cfg = resolveClientConfig();
403
+ const cfg = resolveClientConfig({ token: provisioned });
362
404
  // #4970: every provisioned client recovers from a rotated token — invalidate
363
405
  // the per-worktree cache, refetch once, retry; a second 401 is loud.
364
- return withTokenRefresh(new HttpCoordinationClient(cfg), (token) => new HttpCoordinationClient({ ...cfg, token }), deps?.refreshToken ?? refreshCoordinationToken);
406
+ return withTokenRefresh(new HttpCoordinationClient(cfg), (token) => new HttpCoordinationClient({ ...cfg, token }), deps?.refreshToken ?? refreshCoordinationToken, cfg.token);
365
407
  }
366
408
  catch (err) {
367
409
  // No usable token/URL (or a resolve-time throw). Report a non-secret, one-line
@@ -740,6 +782,12 @@ export async function runEscalate(opts, deps) {
740
782
  // #4314: print the target's ownership scope (and the pipeline/extraction guard)
741
783
  // BEFORE sending, on both backends. Advisory only — never blocks the send.
742
784
  printRoutingAdvisory(opts.to, body);
785
+ // #5188: tell the sender when a live render will cut this body. Advisory only,
786
+ // on both backends, and deliberately before the backend split so it fires
787
+ // whether the message goes to the queue or the memory-mode outbox.
788
+ const oversize = oversizeBodyWarning(body);
789
+ if (oversize)
790
+ process.stderr.write(oversize);
743
791
  // Backend routing (PO one-interface design). memory mode requires NO token.
744
792
  if (resolveCoordinationMode() === 'memory') {
745
793
  return runEscalateMemory(opts, body, deps);
@@ -1149,6 +1197,33 @@ export async function runAck(messageId, deps) {
1149
1197
  }
1150
1198
  /** Hard ceiling on `--all` pages so a huge archive cannot loop unbounded. */
1151
1199
  const HISTORY_MAX_PAGES = 500;
1200
+ /**
1201
+ * Per-row retrieval ceiling for `history` (security review of #5188).
1202
+ *
1203
+ * #5188 removed the body ceiling here entirely, and that was too far. Row COUNT is
1204
+ * bounded (`--limit`, `HISTORY_MAX_PAGES`) but row SIZE was chosen by the sender,
1205
+ * and the same change made broadcasts (`to_team='all'`) reachable from every team's
1206
+ * archive query — so one sender could put an arbitrarily large body into every
1207
+ * team's retrieval path, permanently (the archive is never trimmed and retention is
1208
+ * off by default).
1209
+ *
1210
+ * 100,000 chars keeps what #5188 was for: the longest real attestation measured is
1211
+ * 7,210 chars, so the ceiling is ~14x the largest message anyone has actually sent
1212
+ * and every observed body still round-trips byte-for-byte. A cut above it is marked
1213
+ * at both ends, and the archive still holds every byte.
1214
+ */
1215
+ export const HISTORY_BODY_MAX_CHARS = 100_000;
1216
+ /**
1217
+ * Whole-render ceiling for `history`. A per-row ceiling does not bound
1218
+ * rows x row-size — 200 rows (the service page cap) at 100,000 chars each is 20M
1219
+ * characters into a reader's context. This bounds the product. Rows past it are
1220
+ * dropped with a renderer-generated count line telling the reader to narrow with
1221
+ * `--limit`; nothing is lost, the archive still has it.
1222
+ *
1223
+ * 2,000,000 chars is ~500k tokens: above any real history page (50 rows of ~7k is
1224
+ * ~350k chars) and below the point where one command can fill a context window.
1225
+ */
1226
+ export const HISTORY_RENDER_MAX_CHARS = 2_000_000;
1152
1227
  /**
1153
1228
  * Durable-archive history for THIS team (as sender or recipient). Fetches
1154
1229
  * GET /archive — team-bound server-side from the token — and renders it through
@@ -1181,7 +1256,20 @@ export async function runHistory(opts = {}, deps) {
1181
1256
  }
1182
1257
  // Fenced render — identical treatment to the brief/drain (MF-1): every field
1183
1258
  // sanitized, whole block inside one per-render-nonce fence.
1184
- console.log(renderMessages(collected, { fenced: true, maxBodyChars: MESSAGE_BODY_MAX_CHARS }));
1259
+ //
1260
+ // A HIGH body ceiling, not none (security review of #5188). `history` is the
1261
+ // retrieval path — it is what a reader runs precisely because a live render cut
1262
+ // something, so re-applying the LIVE cut here is what made four attestations look
1263
+ // unrecoverable. But "no ceiling" is a different claim than "a ceiling no real
1264
+ // message reaches", and only the second one is safe: --limit and HISTORY_MAX_PAGES
1265
+ // bound the row COUNT, nothing bounded row SIZE, and broadcasts now reach every
1266
+ // team's archive. HISTORY_BODY_MAX_CHARS (100k) clears the largest observed
1267
+ // message by ~14x; HISTORY_RENDER_MAX_CHARS bounds count x size.
1268
+ console.log(renderMessages(collected, {
1269
+ fenced: true,
1270
+ maxBodyChars: HISTORY_BODY_MAX_CHARS,
1271
+ maxTotalChars: HISTORY_RENDER_MAX_CHARS,
1272
+ }));
1185
1273
  }
1186
1274
  // ── status (local diagnostics, no auth required) ─────────────────────
1187
1275
  /**
@@ -1243,6 +1331,30 @@ function printRoutingAdvisory(to, body) {
1243
1331
  if (warning)
1244
1332
  console.error(warning);
1245
1333
  }
1334
+ /**
1335
+ * Warn the SENDER, at send time, that this body is longer than a live render
1336
+ * will show (#5188).
1337
+ *
1338
+ * Both this CLI (`MAX_BODY_BYTES`, in `runEscalate`) and the service
1339
+ * (`MAX_BODY_CHARS`, in `service.enqueue`) REJECT above 256 KiB — a different, much
1340
+ * higher, blocking limit against a log dump. This is advisory and
1341
+ * never blocks: the message is delivered whole and the archive keeps every byte,
1342
+ * but the recipient's `drain`/`watch` shows the first `MESSAGE_BODY_MAX_CHARS`
1343
+ * characters. Until now the only party who could tell was the recipient, and only
1344
+ * if they spotted the marker. The sender is the party who can act on it — by
1345
+ * putting the conclusion first, or by splitting the message.
1346
+ *
1347
+ * Returns the warning text (or undefined) rather than printing, so it is testable
1348
+ * without capturing stderr.
1349
+ */
1350
+ export function oversizeBodyWarning(body) {
1351
+ if (body.length <= MESSAGE_BODY_MAX_CHARS)
1352
+ return undefined;
1353
+ return (`NOTE: this body is ${body.length} chars; a recipient's \`coordination drain\`/\`watch\` renders the ` +
1354
+ `first ${MESSAGE_BODY_MAX_CHARS} and marks the cut. The message is delivered and archived in full — ` +
1355
+ `\`mx-agent coordination history\` renders up to ${HISTORY_BODY_MAX_CHARS} chars of it. Put the conclusion in the first ` +
1356
+ `${MESSAGE_BODY_MAX_CHARS} chars, or split the message (#5188).\n`);
1357
+ }
1246
1358
  /**
1247
1359
  * `mx-agent coordination status` — display local coordination state and
1248
1360
  * service health without requiring authentication. Designed for debugging