@1agents/acp-service 0.8.1 → 0.8.2

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 (103) hide show
  1. package/README.md +37 -2
  2. package/dist/bin/a2a.js +3 -2
  3. package/dist/src/a2a/executor.d.ts +2 -0
  4. package/dist/src/a2a/executor.js +63 -10
  5. package/dist/src/a2a/gateway.d.ts +407 -14
  6. package/dist/src/a2a/gateway.js +719 -37
  7. package/dist/src/a2a/index.d.ts +8 -1
  8. package/dist/src/a2a/index.js +4 -0
  9. package/dist/src/a2a/notices.d.ts +24 -0
  10. package/dist/src/a2a/notices.js +56 -0
  11. package/dist/src/a2a/preflight.d.ts +52 -0
  12. package/dist/src/a2a/preflight.js +153 -0
  13. package/dist/src/a2a/result-metadata.d.ts +59 -0
  14. package/dist/src/a2a/result-metadata.js +156 -0
  15. package/dist/src/a2a/server.js +30 -0
  16. package/dist/src/a2a/session-delivery.d.ts +69 -0
  17. package/dist/src/a2a/session-delivery.js +260 -0
  18. package/dist/src/a2a/session-hosts.d.ts +34 -0
  19. package/dist/src/a2a/session-hosts.js +211 -0
  20. package/dist/src/a2a/store.js +3 -1
  21. package/dist/src/a2a/types.d.ts +33 -0
  22. package/dist/src/execution/delivery-progress.d.ts +108 -0
  23. package/dist/src/execution/delivery-progress.js +57 -0
  24. package/dist/src/execution/ledger.d.ts +235 -0
  25. package/dist/src/execution/ledger.js +396 -0
  26. package/dist/src/execution/ppt-delivery.d.ts +231 -0
  27. package/dist/src/execution/ppt-delivery.js +625 -0
  28. package/dist/src/execution/targets.d.ts +349 -0
  29. package/dist/src/execution/targets.js +428 -0
  30. package/package.json +11 -12
  31. package/skills/acp-service/SKILL.md +9 -2
  32. package/skills/acp-service/references/a2a.md +72 -4
  33. package/vendor/dsh/a2a-executor.d.ts +2 -1
  34. package/vendor/dsh/a2a-executor.js +28 -1
  35. package/vendor/dsh/a2a.js +1 -0
  36. package/vendor/dsh/client.js +11 -3
  37. package/vendor/runtime/dist/{agent-registry-CMg8LHKY.js → agent-registry-R7A3MSpr.js} +9 -1
  38. package/vendor/runtime/dist/agent-registry-R7A3MSpr.js.map +1 -0
  39. package/vendor/runtime/dist/agent-registry.d.ts +1 -0
  40. package/vendor/runtime/dist/agent-registry.d.ts.map +1 -1
  41. package/vendor/runtime/dist/agent-registry.js +1 -2
  42. package/vendor/runtime/dist/{cli-Bdzplbpj.js → cli-DeOpE2Xz.js} +4 -4
  43. package/vendor/runtime/dist/{cli-Bdzplbpj.js.map → cli-DeOpE2Xz.js.map} +1 -1
  44. package/vendor/runtime/dist/cli.d.ts +2 -1
  45. package/vendor/runtime/dist/cli.js +10 -10
  46. package/vendor/runtime/dist/cli.js.map +1 -1
  47. package/vendor/runtime/dist/{client-BXOiB0ND.d.ts → client-VQsqcIOJ.d.ts} +2 -2
  48. package/vendor/runtime/dist/{client-BXOiB0ND.d.ts.map → client-VQsqcIOJ.d.ts.map} +1 -1
  49. package/vendor/runtime/dist/docs-site/.nojekyll +0 -0
  50. package/vendor/runtime/dist/docs-site/CLI.html +833 -0
  51. package/vendor/runtime/dist/docs-site/VISION.html +415 -0
  52. package/vendor/runtime/dist/docs-site/agents.html +391 -0
  53. package/vendor/runtime/dist/docs-site/compare.html +359 -0
  54. package/vendor/runtime/dist/docs-site/config.html +450 -0
  55. package/vendor/runtime/dist/docs-site/custom-agents.html +408 -0
  56. package/vendor/runtime/dist/docs-site/exit-codes.html +347 -0
  57. package/vendor/runtime/dist/docs-site/favicon.svg +21 -0
  58. package/vendor/runtime/dist/docs-site/flows.html +498 -0
  59. package/vendor/runtime/dist/docs-site/index.html +367 -0
  60. package/vendor/runtime/dist/docs-site/install.html +386 -0
  61. package/vendor/runtime/dist/docs-site/llms.txt +36 -0
  62. package/vendor/runtime/dist/docs-site/output-formats.html +407 -0
  63. package/vendor/runtime/dist/docs-site/permissions.html +422 -0
  64. package/vendor/runtime/dist/docs-site/prompting.html +460 -0
  65. package/vendor/runtime/dist/docs-site/quickstart.html +382 -0
  66. package/vendor/runtime/dist/docs-site/releasing.html +341 -0
  67. package/vendor/runtime/dist/docs-site/runtime-environment.html +329 -0
  68. package/vendor/runtime/dist/docs-site/runtime-process-lifecycle.html +335 -0
  69. package/vendor/runtime/dist/docs-site/safe-errors.html +323 -0
  70. package/vendor/runtime/dist/docs-site/session-control.html +408 -0
  71. package/vendor/runtime/dist/docs-site/session-watch.html +354 -0
  72. package/vendor/runtime/dist/docs-site/sessions.html +488 -0
  73. package/vendor/runtime/dist/docs-site/shared-sessions.html +377 -0
  74. package/vendor/runtime/dist/{flows-BKlAuzM8.js → flows-oaBGn31w.js} +5 -5
  75. package/vendor/runtime/dist/{flows-BKlAuzM8.js.map → flows-oaBGn31w.js.map} +1 -1
  76. package/vendor/runtime/dist/flows.d.ts +2 -2
  77. package/vendor/runtime/dist/flows.d.ts.map +1 -1
  78. package/vendor/runtime/dist/flows.js +1 -2
  79. package/vendor/runtime/dist/{invocation-options-DMy77sEU.js → invocation-options-CUDEE8vW.js} +5 -5
  80. package/vendor/runtime/dist/{invocation-options-DMy77sEU.js.map → invocation-options-CUDEE8vW.js.map} +1 -1
  81. package/vendor/runtime/dist/{ipc-CLv2iL89.js → ipc-BQQpcEdP.js} +98 -20
  82. package/vendor/runtime/dist/ipc-BQQpcEdP.js.map +1 -0
  83. package/vendor/runtime/dist/{output-I-t-v55D.js → output-CFv3jcOQ.js} +86 -22
  84. package/vendor/runtime/dist/output-CFv3jcOQ.js.map +1 -0
  85. package/vendor/runtime/dist/{queue-owner-runtime-RN3uSid0.js → queue-owner-runtime-DvMJiGbP.js} +86 -27
  86. package/vendor/runtime/dist/queue-owner-runtime-DvMJiGbP.js.map +1 -0
  87. package/vendor/runtime/dist/runtime.d.ts +5 -2
  88. package/vendor/runtime/dist/runtime.d.ts.map +1 -1
  89. package/vendor/runtime/dist/runtime.js +77 -29
  90. package/vendor/runtime/dist/runtime.js.map +1 -1
  91. package/vendor/runtime/dist/{session-options-DNnDfiUt.d.ts → session-options-NjpFwf-c.d.ts} +5 -1
  92. package/vendor/runtime/dist/session-options-NjpFwf-c.d.ts.map +1 -0
  93. package/vendor/runtime/dist/{session-watch-CmHbH0jS.js → session-watch-Di-wIdCH.js} +4 -4
  94. package/vendor/runtime/dist/{session-watch-CmHbH0jS.js.map → session-watch-Di-wIdCH.js.map} +1 -1
  95. package/vendor/runtime/dist/{watch-BE-kKa7o.js → watch-CIpoMaWD.js} +2 -2
  96. package/vendor/runtime/dist/{watch-BE-kKa7o.js.map → watch-CIpoMaWD.js.map} +1 -1
  97. package/vendor/runtime/package.json +1 -1
  98. package/vendor/runtime/skills/acpx/SKILL.md +7 -2
  99. package/vendor/runtime/dist/agent-registry-CMg8LHKY.js.map +0 -1
  100. package/vendor/runtime/dist/ipc-CLv2iL89.js.map +0 -1
  101. package/vendor/runtime/dist/output-I-t-v55D.js.map +0 -1
  102. package/vendor/runtime/dist/queue-owner-runtime-RN3uSid0.js.map +0 -1
  103. package/vendor/runtime/dist/session-options-DNnDfiUt.d.ts.map +0 -1
@@ -1,5 +1,5 @@
1
- import { A as findSession, I as pruneSessions, N as listSessions, P as listSessionsForAgent, ct as parsePromptStopReason, j as findSessionByDirectoryWalk, k as findGitRepositoryRoot, nt as extractSessionUpdateNotification, ot as parseJsonRpcErrorMessage, st as parsePermissionNotice, vt as isProcessAlive } from "./ipc-CLv2iL89.js";
2
- import { C as setSessionModeOnOwner, S as setSessionMode, T as setSessionModelOnOwner, _ as cancelSessionPrompt, a as runQueuedTask, at as normalizeQueueOwnerTtlMs, b as setSessionConfigOption, dt as TimeoutError, g as listAgentSessions, h as ensureSession, i as runOnce, it as DEFAULT_QUEUE_OWNER_TTL_MS, m as createSessionWithClient, n as runSessionQueueOwner, o as sendSessionDirect, p as createSession, r as sendSession, t as queueOwnerRuntimeTestInternals, ut as InterruptedError, v as closeSession, w as setSessionModel, x as setSessionConfigOptionOnOwner, y as sessionControlTestInternals } from "./queue-owner-runtime-RN3uSid0.js";
1
+ import { A as findSession, I as pruneSessions, N as listSessions, P as listSessionsForAgent, St as isProcessAlive, ct as parsePermissionNotice, j as findSessionByDirectoryWalk, k as findGitRepositoryRoot, lt as parsePromptStopReason, rt as extractSessionUpdateNotification, st as parseJsonRpcErrorMessage } from "./ipc-BQQpcEdP.js";
2
+ import { C as setSessionModeOnOwner, S as setSessionMode, T as setSessionModelOnOwner, _ as cancelSessionPrompt, a as runQueuedTask, at as normalizeQueueOwnerTtlMs, b as setSessionConfigOption, dt as TimeoutError, g as listAgentSessions, h as ensureSession, i as runOnce, it as DEFAULT_QUEUE_OWNER_TTL_MS, m as createSessionWithClient, n as runSessionQueueOwner, o as sendSessionDirect, p as createSession, r as sendSession, t as queueOwnerRuntimeTestInternals, ut as InterruptedError, v as closeSession, w as setSessionModel, x as setSessionConfigOptionOnOwner, y as sessionControlTestInternals } from "./queue-owner-runtime-DvMJiGbP.js";
3
3
  //#region \0rolldown/runtime.js
4
4
  var __defProp = Object.defineProperty;
5
5
  var __exportAll = (all, no_symbols) => {
@@ -340,8 +340,7 @@ function asRecord(value) {
340
340
  function parseJsonRpcErrorSummary(message) {
341
341
  const fallback = parseJsonRpcErrorMessage(message);
342
342
  if (!fallback) return;
343
- const details = asRecord(asRecord(message.error)?.data)?.details;
344
- return typeof details === "string" && details.trim().length > 0 ? details.trim() : fallback;
343
+ return preferredAcpErrorDetails(asRecord(message.error)?.data) ?? fallback;
345
344
  }
346
345
  function extractJsonRpcMethod(message) {
347
346
  return Object.hasOwn(message, "method") ? message.method?.toString() : void 0;
@@ -441,7 +440,7 @@ function renderAuthRequiredHint(params) {
441
440
  return `hint: run \`acpx config show\` to locate the active config, then add ${formatDisjunction(methodIds.map((methodId) => `\`auth.${methodId}\``))} and retry.`;
442
441
  }
443
442
  function getTextErrorRemediationHints(params) {
444
- const lowerMessage = params.message.toLowerCase();
443
+ const lowerMessage = (preferredAcpErrorDetails(params.acp?.data) ?? params.message).toLowerCase();
445
444
  if (params.detailCode === "AUTH_REQUIRED") return [renderAuthRequiredHint(params)];
446
445
  if (params.code === "TIMEOUT") return ["hint: increase `--timeout <seconds>` for long-running prompts, or check whether the agent/provider is stalled."];
447
446
  if (params.code === "NO_SESSION") return noSessionHints(lowerMessage);
@@ -457,7 +456,7 @@ const TEXT_ERROR_HINT_RULES = [
457
456
  hints: ["hint: rerun with `--verbose` to capture the ACP load failure details.", "hint: if you do not need the old backend session, start a fresh one with `acpx <agent> sessions new` and retry."]
458
457
  },
459
458
  {
460
- matches: (params, lowerMessage) => isRateLimitError(params.message, lowerMessage),
459
+ matches: (_params, lowerMessage) => isRateLimitError(lowerMessage),
461
460
  hints: ["hint: the provider appears rate-limited; retry later, switch model, or check provider quota/billing."]
462
461
  },
463
462
  {
@@ -486,8 +485,12 @@ function isUnsupportedSessionLoadError(lowerMessage) {
486
485
  function isSessionLoadError(lowerMessage) {
487
486
  return lowerMessage.includes("failed to resume acp session") || lowerMessage.includes("session/resume") || lowerMessage.includes("session/load");
488
487
  }
489
- function isRateLimitError(message, lowerMessage) {
490
- return /\b429\b/u.test(message) || ["rate limit", "quota exceeded"].some((text) => lowerMessage.includes(text));
488
+ function isRateLimitError(lowerMessage) {
489
+ return /\b429\b/u.test(lowerMessage) || [
490
+ "rate limit",
491
+ "quota exceeded",
492
+ "usage limit"
493
+ ].some((text) => lowerMessage.includes(text));
491
494
  }
492
495
  function isModelLookupError(lowerMessage) {
493
496
  return [
@@ -545,8 +548,47 @@ function summarizeToolInputJson(rawInput) {
545
548
  const json = safeJson(rawInput, 0);
546
549
  return json ? toInline(json) : void 0;
547
550
  }
551
+ function malformedToolUpdateMessage(update) {
552
+ if (update.locations != null && !validToolLocations(update.locations)) return "Malformed tool call locations";
553
+ return malformedToolContentMessage(update.content);
554
+ }
555
+ function validToolLocations(locations) {
556
+ return Array.isArray(locations) && locations.every(validToolLocation);
557
+ }
558
+ function validToolLocation(location) {
559
+ const record = asRecord(location);
560
+ if (!record) return false;
561
+ if (record.path != null && typeof record.path !== "string") return false;
562
+ return record.line == null || typeof record.line === "number" && Number.isFinite(record.line);
563
+ }
564
+ function malformedToolContentMessage(content) {
565
+ if (content == null) return;
566
+ if (!Array.isArray(content)) return "Malformed tool call content";
567
+ for (const entry of content) {
568
+ const error = malformedToolContentEntry(entry);
569
+ if (error) return error;
570
+ }
571
+ }
572
+ function malformedToolContentEntry(entry) {
573
+ const record = asRecord(entry);
574
+ if (!record) return "Malformed tool call content";
575
+ if (record.type === "diff") return malformedDiffMessage(record);
576
+ if (record.type === "content" && !validToolContentBlock(record.content)) return "Malformed tool call content";
577
+ if (record.type === "terminal" && typeof record.terminalId !== "string") return "Malformed tool call content";
578
+ }
579
+ function malformedDiffMessage(record) {
580
+ if (typeof record.path === "string" && typeof record.newText === "string" && (record.oldText == null || typeof record.oldText === "string")) return;
581
+ return "Malformed tool call diff";
582
+ }
583
+ function validToolContentBlock(content) {
584
+ const block = asRecord(content);
585
+ if (!block || typeof block.type !== "string") return false;
586
+ if (block.type === "text") return typeof block.text === "string";
587
+ if (block.type === "resource") return asRecord(block.resource) !== void 0;
588
+ return true;
589
+ }
548
590
  function formatLocations(locations) {
549
- if (!locations || locations.length === 0) return;
591
+ if (!Array.isArray(locations) || locations.length === 0) return;
550
592
  const unique = /* @__PURE__ */ new Set();
551
593
  for (const location of locations) {
552
594
  const formatted = formatLocation(location);
@@ -560,7 +602,10 @@ function formatLocations(locations) {
560
602
  return `${visible.join(", ")}, +${hidden} more`;
561
603
  }
562
604
  function formatLocation(location) {
563
- const path = location.path?.trim();
605
+ if (!location || typeof location !== "object") return;
606
+ const rawPath = location.path;
607
+ if (typeof rawPath !== "string") return;
608
+ const path = rawPath.trim();
564
609
  if (!path) return;
565
610
  return `${path}${typeof location.line === "number" && Number.isFinite(location.line) ? `:${Math.max(1, Math.trunc(location.line))}` : ""}`;
566
611
  }
@@ -581,13 +626,14 @@ function textFromContentBlock(content) {
581
626
  }
582
627
  }
583
628
  function textFromResourceBlock(content) {
629
+ if (!content.resource || typeof content.resource !== "object") return "[resource]";
584
630
  if ("text" in content.resource && typeof content.resource.text === "string") return content.resource.text;
585
631
  const uri = content.resource.uri;
586
632
  const mimeType = content.resource.mimeType;
587
633
  return `[resource] ${uri}${mimeType ? ` (${mimeType})` : ""}`;
588
634
  }
589
635
  function summarizeToolContent(content) {
590
- if (!content || content.length === 0) return;
636
+ if (!Array.isArray(content) || content.length === 0) return;
591
637
  const fragments = [];
592
638
  for (const entry of content) {
593
639
  const fragment = summarizeToolContentEntry(entry);
@@ -598,13 +644,21 @@ function summarizeToolContent(content) {
598
644
  return unique.join("\n\n");
599
645
  }
600
646
  function summarizeToolContentEntry(entry) {
601
- if (entry.type === "content") {
602
- const text = textFromContentBlock(entry.content);
603
- return text && text.trim() ? text.trimEnd() : void 0;
604
- }
605
- if (entry.type === "diff") return summarizeDiff(entry.path, entry.oldText, entry.newText);
647
+ if (!entry || typeof entry !== "object") return;
648
+ if (entry.type === "content") return summarizeContentEntry(entry);
649
+ if (entry.type === "diff") return summarizeDiffEntry(entry);
606
650
  if (entry.type === "terminal") return `[terminal] ${entry.terminalId}`;
607
651
  }
652
+ function summarizeContentEntry(entry) {
653
+ if (!entry.content || typeof entry.content !== "object") return;
654
+ const text = textFromContentBlock(entry.content);
655
+ return typeof text === "string" && text.trim() ? text.trimEnd() : void 0;
656
+ }
657
+ function summarizeDiffEntry(entry) {
658
+ if (typeof entry.path !== "string" || typeof entry.newText !== "string") return;
659
+ const oldText = typeof entry.oldText === "string" ? entry.oldText : void 0;
660
+ return summarizeDiff(entry.path, oldText, entry.newText);
661
+ }
608
662
  function extractOutputText(value, depth = 0, seen = /* @__PURE__ */ new Set()) {
609
663
  if (value == null) return;
610
664
  const scalar = extractScalarOutputText(value);
@@ -755,7 +809,8 @@ var TextOutputFormatter = class {
755
809
  onError(params) {
756
810
  this.flushThoughtBuffer();
757
811
  this.beginSection();
758
- this.writeLine(this.formatAnsi(`[error] ${params.code}: ${params.message}`, "31"));
812
+ const message = preferredAcpErrorDetails(params.acp?.data) ?? params.message;
813
+ this.writeLine(this.formatAnsi(`[error] ${params.code}: ${message}`, "31"));
759
814
  for (const hint of getTextErrorRemediationHints(params)) this.writeLine(this.dim(hint));
760
815
  }
761
816
  onClientOperation(operation) {
@@ -811,6 +866,15 @@ var TextOutputFormatter = class {
811
866
  for (const line of restLines) this.writeLine(this.dim(` ${line}`));
812
867
  }
813
868
  renderToolUpdate(update) {
869
+ const shapeError = malformedToolUpdateMessage(update);
870
+ if (shapeError) {
871
+ this.onError({
872
+ code: "RUNTIME",
873
+ origin: "acp",
874
+ message: shapeError
875
+ });
876
+ return;
877
+ }
814
878
  const state = this.getOrCreateToolState(update.toolCallId);
815
879
  this.mergeToolState(state, update);
816
880
  const status = asStatus(state.status);
@@ -925,7 +989,7 @@ var QuietOutputFormatter = class {
925
989
  onError(params) {
926
990
  this.flush();
927
991
  const qualifier = params.detailCode ? `${params.code} ${params.detailCode}` : params.code;
928
- const message = preferredAcpErrorDetails(params.acp) ?? params.message;
992
+ const message = preferredAcpErrorDetails(params.acp?.data) ?? params.message;
929
993
  this.stderr.write(`[acpx] error: ${qualifier} ${message.replace(/\r\n?|\n/g, " ")}\n`);
930
994
  }
931
995
  onPermissionEscalation(_event) {}
@@ -991,9 +1055,9 @@ var QuietOutputFormatter = class {
991
1055
  if (typeof cost === "string" && cost.trim()) return `[acpx] cost: ${cost.trim()}`;
992
1056
  }
993
1057
  };
994
- function preferredAcpErrorDetails(acp) {
995
- const details = asRecord(acp?.data)?.details;
996
- return typeof details === "string" && details.trim().length > 0 ? details.trim() : void 0;
1058
+ function preferredAcpErrorDetails(data) {
1059
+ const record = asRecord(data);
1060
+ for (const value of [record?.details, record?.message]) if (typeof value === "string" && value.trim().length > 0) return value.trim();
997
1061
  }
998
1062
  function createOutputFormatter(format, options = {}) {
999
1063
  const stdout = options.stdout ?? process.stdout;
@@ -1009,4 +1073,4 @@ function createOutputFormatter(format, options = {}) {
1009
1073
  //#endregion
1010
1074
  export { MAX_TIMER_DELAY_MS as a, __exportAll as c, JsonMessageSanitizer as i, getTextErrorRemediationHints as n, toTimerMilliseconds as o, output_exports as r, session_exports as s, createOutputFormatter as t };
1011
1075
 
1012
- //# sourceMappingURL=output-I-t-v55D.js.map
1076
+ //# sourceMappingURL=output-CFv3jcOQ.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"output-CFv3jcOQ.js","names":["asRecord"],"sources":["../src/session/session.ts","../src/cli/timer-duration.ts","../src/acp/jsonrpc-error.ts","../src/cli/output/read-suppression.ts","../src/cli/output/json-formatter.ts","../src/cli/output/output.ts"],"sourcesContent":["export * from \"./execution/contracts.js\";\nexport * from \"./execution/session-management.js\";\nexport * from \"./execution/queue-owner-runtime.js\";\nexport * from \"./execution/session-control.js\";\nexport * from \"./execution/runtime.js\";\nexport {\n DEFAULT_HISTORY_LIMIT,\n findGitRepositoryRoot,\n findSession,\n findSessionByDirectoryWalk,\n listSessions,\n listSessionsForAgent,\n pruneSessions,\n} from \"./persistence.js\";\nexport type { PruneOptions, PruneResult } from \"./persistence.js\";\nexport { isProcessAlive } from \"../process-liveness.js\";\n","export const MAX_TIMER_DELAY_MS = 2_147_483_647;\n\nexport function toTimerMilliseconds(seconds: number, allowZero: boolean): number | undefined {\n if (allowZero && seconds === 0) {\n return 0;\n }\n const milliseconds = Math.max(1, Math.round(seconds * 1000));\n return milliseconds <= MAX_TIMER_DELAY_MS ? milliseconds : undefined;\n}\n","import type { OutputErrorAcpPayload, OutputErrorCode, OutputErrorOrigin } from \"../types.js\";\n\nexport const OUTPUT_ERROR_JSONRPC_CODES: Record<OutputErrorCode, number> = {\n NO_SESSION: -32002,\n TIMEOUT: -32070,\n PERMISSION_DENIED: -32071,\n PERMISSION_PROMPT_UNAVAILABLE: -32072,\n EXEC_DISABLED: -32603,\n RUNTIME: -32603,\n USAGE: -32602,\n};\n\ntype JsonRpcErrorObject = {\n code: number;\n message: string;\n data?: unknown;\n};\n\nexport type BuildJsonRpcErrorParams = {\n id?: string | number | null;\n outputCode: OutputErrorCode;\n detailCode?: string;\n origin?: OutputErrorOrigin;\n message: string;\n retryable?: boolean;\n timestamp?: string;\n sessionId?: string;\n acp?: OutputErrorAcpPayload;\n};\n\nfunction hasValidAcpError(\n acp: OutputErrorAcpPayload | undefined,\n): acp is { code: number; message: string; data?: unknown } {\n return Boolean(\n acp &&\n Number.isFinite(acp.code) &&\n typeof acp.message === \"string\" &&\n acp.message.trim().length > 0,\n );\n}\n\nfunction buildFallbackData(params: BuildJsonRpcErrorParams): Record<string, unknown> {\n const data: Record<string, unknown> = {\n acpxCode: params.outputCode,\n detailCode: params.detailCode,\n origin: params.origin,\n retryable: params.retryable,\n timestamp: params.timestamp,\n sessionId: params.sessionId,\n };\n\n for (const [key, value] of Object.entries(data)) {\n if (value === undefined) {\n delete data[key];\n }\n }\n\n return data;\n}\n\nfunction mergeAcpErrorData(acpData: unknown, fallbackData: Record<string, unknown>): unknown {\n if (Object.keys(fallbackData).length === 0) {\n return acpData;\n }\n if (acpData === undefined) {\n return fallbackData;\n }\n if (acpData && typeof acpData === \"object\" && !Array.isArray(acpData)) {\n return {\n ...fallbackData,\n ...acpData,\n };\n }\n return acpData;\n}\n\nfunction buildErrorObject(params: BuildJsonRpcErrorParams): JsonRpcErrorObject {\n const fallbackData = buildFallbackData(params);\n if (hasValidAcpError(params.acp)) {\n const data = mergeAcpErrorData(params.acp.data, fallbackData);\n return {\n code: params.acp.code,\n message: params.acp.message,\n ...(data !== undefined ? { data } : {}),\n };\n }\n\n const data = fallbackData;\n return {\n code: OUTPUT_ERROR_JSONRPC_CODES[params.outputCode] ?? -32603,\n message: params.message,\n ...(Object.keys(data).length > 0 ? { data } : {}),\n };\n}\n\nexport function buildJsonRpcErrorResponse(params: BuildJsonRpcErrorParams): {\n jsonrpc: \"2.0\";\n id: string | number | null;\n error: JsonRpcErrorObject;\n} {\n return {\n jsonrpc: \"2.0\",\n id: params.id ?? null,\n error: buildErrorObject(params),\n };\n}\n","export const SUPPRESSED_READ_OUTPUT = \"[read output suppressed]\";\n\nexport type ReadLikeToolDescriptor = {\n title?: string;\n kind?: string | null;\n};\n\nfunction inferToolKindFromTitle(title: string | undefined): string | undefined {\n const normalized = title?.trim().toLowerCase();\n if (!normalized) {\n return undefined;\n }\n\n const head = normalized.split(/[:\\s]/, 1)[0];\n if (!head) {\n return undefined;\n }\n\n if ([\"read\", \"cat\", \"open\", \"view\"].includes(head)) {\n return \"read\";\n }\n\n return undefined;\n}\n\nexport function isReadLikeTool(tool: ReadLikeToolDescriptor): boolean {\n return (\n tool.kind?.trim().toLowerCase() === \"read\" || inferToolKindFromTitle(tool.title) === \"read\"\n );\n}\n","import { buildJsonRpcErrorResponse } from \"../../acp/jsonrpc-error.js\";\nimport type {\n AcpMessageDirection,\n OutputErrorAcpPayload,\n OutputErrorCode,\n OutputErrorOrigin,\n OutputFormatter,\n OutputFormatterContext,\n} from \"../../types.js\";\nimport { isReadLikeTool, SUPPRESSED_READ_OUTPUT } from \"./read-suppression.js\";\n\ntype WritableLike = {\n write(chunk: string): void;\n};\n\ntype JsonRpcRequestMessage = {\n jsonrpc?: unknown;\n id?: unknown;\n method?: unknown;\n};\n\ntype JsonRpcResponseMessage = {\n jsonrpc?: unknown;\n id?: unknown;\n result?: unknown;\n error?: unknown;\n};\n\nconst DEFAULT_JSON_SESSION_ID = \"unknown\";\n\nfunction asRecord(value: unknown): Record<string, unknown> | undefined {\n if (!value || typeof value !== \"object\" || Array.isArray(value)) {\n return undefined;\n }\n return value as Record<string, unknown>;\n}\n\nfunction jsonRpcIdKey(value: unknown): string | undefined {\n if (typeof value === \"string\") {\n return `s:${value}`;\n }\n if (typeof value === \"number\" && Number.isFinite(value)) {\n return `n:${value}`;\n }\n return undefined;\n}\n\nfunction requestCorrelationKey(\n id: unknown,\n direction: AcpMessageDirection | undefined,\n): string | undefined {\n const idKey = jsonRpcIdKey(id);\n return idKey === undefined ? undefined : `${direction ?? \"unknown\"}:${idKey}`;\n}\n\nfunction reverseDirection(\n direction: AcpMessageDirection | undefined,\n): AcpMessageDirection | undefined {\n if (direction === undefined) {\n return undefined;\n }\n return direction === \"inbound\" ? \"outbound\" : \"inbound\";\n}\n\nfunction sanitizeReadResult(result: unknown): unknown {\n const record = asRecord(result);\n if (!record || typeof record.content !== \"string\") {\n return result;\n }\n return {\n ...record,\n content: SUPPRESSED_READ_OUTPUT,\n };\n}\n\nfunction sanitizeToolContent(content: unknown): unknown {\n if (!Array.isArray(content)) {\n return content;\n }\n\n return [\n {\n type: \"content\",\n content: {\n type: \"text\",\n text: SUPPRESSED_READ_OUTPUT,\n },\n },\n ];\n}\n\nfunction sanitizeToolMessage(message: unknown): unknown {\n const root = asRecord(message);\n const params = asRecord(root?.params);\n const update = asRecord(params?.update);\n if (!root || !params || !update) {\n return message;\n }\n\n return {\n ...root,\n params: {\n ...params,\n update: sanitizeToolUpdate(update),\n },\n };\n}\n\nfunction sanitizeToolUpdate(update: Record<string, unknown>): Record<string, unknown> {\n return {\n ...update,\n rawOutput: sanitizedRawOutput(update),\n content: sanitizedContent(update),\n };\n}\n\nfunction sanitizedRawOutput(update: Record<string, unknown>): unknown {\n if (Object.prototype.hasOwnProperty.call(update, \"rawOutput\") && update.rawOutput !== undefined) {\n return { content: SUPPRESSED_READ_OUTPUT };\n }\n return update.rawOutput;\n}\n\nfunction sanitizedContent(update: Record<string, unknown>): unknown {\n if (Object.prototype.hasOwnProperty.call(update, \"content\") && update.content !== undefined) {\n return sanitizeToolContent(update.content);\n }\n return update.content;\n}\n\nexport class JsonMessageSanitizer {\n private readonly requestMethodById = new Map<string, string>();\n private readonly toolStateById = new Map<string, { title?: string; kind?: string | null }>();\n\n constructor(\n private readonly suppressReads: boolean,\n private readonly partialHistory = false,\n ) {}\n\n sanitize(message: unknown, direction?: AcpMessageDirection): unknown {\n if (!this.suppressReads) {\n return message;\n }\n\n const sanitizedResponse = this.sanitizeReadResponse(message, direction);\n if (sanitizedResponse !== message) {\n return sanitizedResponse;\n }\n\n const sanitizedToolMessage = this.sanitizeReadToolMessage(message);\n if (sanitizedToolMessage !== message) {\n return sanitizedToolMessage;\n }\n\n this.trackRequestMethod(message, direction);\n return message;\n }\n\n private trackRequestMethod(message: unknown, direction: AcpMessageDirection | undefined): void {\n const candidate = message as JsonRpcRequestMessage;\n if (typeof candidate.method !== \"string\") {\n return;\n }\n const idKey = requestCorrelationKey(candidate.id, direction);\n if (!idKey) {\n return;\n }\n this.requestMethodById.set(idKey, candidate.method);\n }\n\n private sanitizeReadResponse(\n message: unknown,\n direction: AcpMessageDirection | undefined,\n ): unknown {\n const candidate = message as JsonRpcResponseMessage;\n const idKey = requestCorrelationKey(candidate.id, reverseDirection(direction));\n if (!idKey) {\n return message;\n }\n\n const hasResult = Object.hasOwn(candidate, \"result\");\n const hasError = Object.hasOwn(candidate, \"error\");\n if (!hasResult && !hasError) {\n return message;\n }\n\n const method = this.requestMethodById.get(idKey);\n this.requestMethodById.delete(idKey);\n if (!hasResult || !this.suppressReadResponse(method)) {\n return message;\n }\n\n const root = asRecord(message);\n if (!root) {\n return message;\n }\n\n return {\n ...root,\n result: sanitizeReadResult(candidate.result),\n };\n }\n\n private suppressReadResponse(method: string | undefined): boolean {\n return method === \"fs/read_text_file\" || (this.partialHistory && method === undefined);\n }\n\n private sanitizeReadToolMessage(message: unknown): unknown {\n const update = this.readToolUpdate(message);\n if (!update) {\n return message;\n }\n\n const toolCallId = typeof update.toolCallId === \"string\" ? update.toolCallId : undefined;\n if (!toolCallId) {\n return message;\n }\n\n const current = this.mergeToolState(toolCallId, update);\n this.toolStateById.set(toolCallId, current);\n\n const unclassified = this.partialHistory && !current.kind && !current.title;\n return isReadLikeTool(current) || unclassified ? sanitizeToolMessage(message) : message;\n }\n\n private readToolUpdate(message: unknown): Record<string, unknown> | undefined {\n const root = asRecord(message);\n if (root?.method !== \"session/update\") {\n return undefined;\n }\n const params = asRecord(root.params);\n const update = asRecord(params?.update);\n if (!params || !update) {\n return undefined;\n }\n\n const sessionUpdate = update.sessionUpdate;\n if (sessionUpdate !== \"tool_call\" && sessionUpdate !== \"tool_call_update\") {\n return undefined;\n }\n return update;\n }\n\n private mergeToolState(\n toolCallId: string,\n update: Record<string, unknown>,\n ): { title?: string; kind?: string | null } {\n const previous = this.toolStateById.get(toolCallId) ?? {};\n return {\n title: typeof update.title === \"string\" ? update.title : previous.title,\n kind: typeof update.kind === \"string\" || update.kind === null ? update.kind : previous.kind,\n };\n }\n}\n\nclass JsonOutputFormatter implements OutputFormatter {\n private readonly stdout: WritableLike;\n private readonly sanitizer: JsonMessageSanitizer;\n private sessionId: string;\n\n constructor(stdout: WritableLike, suppressReads: boolean, context?: OutputFormatterContext) {\n this.stdout = stdout;\n this.sanitizer = new JsonMessageSanitizer(suppressReads);\n this.sessionId = context?.sessionId?.trim() || DEFAULT_JSON_SESSION_ID;\n }\n\n setContext(context: OutputFormatterContext): void {\n this.sessionId = context.sessionId?.trim() || this.sessionId || DEFAULT_JSON_SESSION_ID;\n }\n\n onAcpMessage(message: unknown, direction?: AcpMessageDirection): void {\n this.stdout.write(`${JSON.stringify(this.sanitizer.sanitize(message, direction))}\\n`);\n }\n\n onError(params: {\n code: OutputErrorCode;\n detailCode?: string;\n origin?: OutputErrorOrigin;\n message: string;\n retryable?: boolean;\n acp?: OutputErrorAcpPayload;\n timestamp?: string;\n }): void {\n this.stdout.write(\n `${JSON.stringify(\n buildJsonRpcErrorResponse({\n outputCode: params.code,\n detailCode: params.detailCode,\n origin: params.origin,\n message: params.message,\n retryable: params.retryable,\n timestamp: params.timestamp,\n sessionId: this.sessionId,\n acp: params.acp,\n }),\n )}\\n`,\n );\n }\n\n onPermissionEscalation(): void {\n // JSON mode is raw ACP NDJSON. Escalation details ride on the ACP\n // request_permission response _meta instead of a synthetic acpx event line.\n }\n\n flush(): void {\n // no-op for streaming output\n }\n}\n\nexport function createJsonOutputFormatter(\n stdout: WritableLike,\n suppressReads = false,\n context?: OutputFormatterContext,\n): OutputFormatter {\n return new JsonOutputFormatter(stdout, suppressReads, context);\n}\n","import type {\n AnyMessage,\n ContentBlock,\n SessionNotification,\n ToolCall,\n ToolCallContent,\n ToolCallLocation,\n ToolCallStatus,\n ToolCallUpdate,\n} from \"@agentclientprotocol/sdk\";\nimport {\n extractSessionUpdateNotification,\n parseJsonRpcErrorMessage,\n parsePromptStopReason,\n parsePermissionNotice,\n} from \"../../acp/jsonrpc.js\";\nimport type {\n AcpJsonRpcMessage,\n ClientOperation,\n OutputErrorAcpPayload,\n OutputErrorCode,\n OutputFormatterContext,\n OutputFormat,\n OutputFormatter,\n OutputErrorOrigin,\n PermissionEscalationEvent,\n} from \"../../types.js\";\nimport { createJsonOutputFormatter } from \"./json-formatter.js\";\nimport { isReadLikeTool, SUPPRESSED_READ_OUTPUT } from \"./read-suppression.js\";\n\ntype WritableLike = {\n write(chunk: string): void;\n isTTY?: boolean;\n};\n\ntype RenderableOutputError = {\n code: OutputErrorCode;\n detailCode?: string;\n origin?: OutputErrorOrigin;\n message: string;\n retryable?: boolean;\n acp?: OutputErrorAcpPayload;\n timestamp?: string;\n};\n\ntype OutputFormatterOptions = {\n stdout?: WritableLike;\n stderr?: WritableLike;\n jsonContext?: OutputFormatterContext;\n suppressReads?: boolean;\n};\n\ntype NormalizedToolStatus = ToolCallStatus | \"unknown\";\n\ntype ToolRenderState = {\n id: string;\n title?: string;\n status?: ToolCallStatus | null;\n kind?: string | null;\n locations?: Array<ToolCallLocation> | null;\n rawInput?: unknown;\n rawOutput?: unknown;\n content?: Array<ToolCallContent> | null;\n startedPrinted: boolean;\n finalSignature?: string;\n};\n\ntype ToolDisplay = {\n input?: string;\n files?: string;\n output?: string;\n};\n\nconst MAX_THOUGHT_CHARS = 900;\nconst MAX_INLINE_CHARS = 220;\nconst MAX_OUTPUT_CHARS = 2_000;\nconst MAX_OUTPUT_LINES = 28;\nconst MAX_LOCATION_ITEMS = 5;\nconst OUTPUT_PRIORITY_KEYS = [\n \"stdout\",\n \"stderr\",\n \"output\",\n \"content\",\n \"text\",\n \"message\",\n \"result\",\n \"response\",\n \"value\",\n] as const;\n\nfunction asStatus(status: ToolCallStatus | null | undefined): NormalizedToolStatus {\n return status ?? \"unknown\";\n}\n\nfunction isFinalStatus(status: NormalizedToolStatus): status is \"completed\" | \"failed\" {\n return status === \"completed\" || status === \"failed\";\n}\n\nfunction toStatusLabel(status: NormalizedToolStatus): string {\n return isFinalStatus(status) || status === \"pending\" ? status : \"running\";\n}\n\nfunction asRecord(value: unknown): Record<string, unknown> | undefined {\n if (!value || typeof value !== \"object\" || Array.isArray(value)) {\n return undefined;\n }\n return value as Record<string, unknown>;\n}\n\nfunction parseJsonRpcErrorSummary(message: AcpJsonRpcMessage): string | undefined {\n const fallback = parseJsonRpcErrorMessage(message);\n if (!fallback) {\n return undefined;\n }\n\n const error = asRecord((message as { error?: unknown }).error);\n return preferredAcpErrorDetails(error?.data) ?? fallback;\n}\n\nfunction extractJsonRpcMethod(message: AnyMessage): string | undefined {\n return Object.hasOwn(message, \"method\")\n ? (message as { method?: unknown }).method?.toString()\n : undefined;\n}\n\nfunction collapseWhitespace(value: string): string {\n return value.replace(/\\s+/g, \" \").trim();\n}\n\nfunction normalizeLineEndings(value: string): string {\n return value.replace(/\\r\\n?/g, \"\\n\");\n}\n\nfunction truncate(value: string, maxChars: number): string {\n if (value.length <= maxChars) {\n return value;\n }\n if (maxChars <= 3) {\n return value.slice(0, maxChars);\n }\n return `${value.slice(0, maxChars - 3)}...`;\n}\n\nfunction toInline(value: string, maxChars = MAX_INLINE_CHARS): string {\n return truncate(collapseWhitespace(value), maxChars);\n}\n\nfunction indentBlock(value: string, prefix: string): string {\n return value\n .split(\"\\n\")\n .map((line) => `${prefix}${line}`)\n .join(\"\\n\");\n}\n\nfunction dedupeStrings(values: string[]): string[] {\n return [...new Set(values)];\n}\n\nfunction safeJson(value: unknown, spacing: number): string | undefined {\n const seen = new WeakSet();\n\n try {\n return JSON.stringify(\n value,\n (_key, entry: unknown) => {\n if (typeof entry === \"bigint\") {\n return `${entry}n`;\n }\n if (typeof entry === \"function\") {\n return `[Function ${entry.name || \"anonymous\"}]`;\n }\n if (typeof entry === \"symbol\") {\n return entry.toString();\n }\n if (entry && typeof entry === \"object\") {\n if (seen.has(entry)) {\n return \"[Circular]\";\n }\n seen.add(entry);\n }\n return entry;\n },\n spacing,\n );\n } catch {\n return undefined;\n }\n}\n\nfunction readFirstString(source: Record<string, unknown>, keys: string[]): string | undefined {\n for (const key of keys) {\n const value = source[key];\n if (typeof value === \"string\" && value.trim()) {\n return value.trim();\n }\n }\n return undefined;\n}\n\nfunction readFirstFiniteNumber(\n source: Record<string, unknown>,\n keys: string[],\n): number | undefined {\n for (const key of keys) {\n const value = source[key];\n if (typeof value === \"number\" && Number.isFinite(value)) {\n return value;\n }\n }\n return undefined;\n}\n\nfunction formatMetadataNumber(value: number): string {\n return Number.isInteger(value) ? String(value) : String(Number(value.toFixed(8)));\n}\n\nfunction readFirstStringArray(\n source: Record<string, unknown>,\n keys: string[],\n): string[] | undefined {\n for (const key of keys) {\n const value = source[key];\n if (!Array.isArray(value)) {\n continue;\n }\n const entries = value\n .map((entry) => (typeof entry === \"string\" ? entry.trim() : \"\"))\n .filter((entry) => entry.length > 0);\n if (entries.length > 0) {\n return entries;\n }\n }\n return undefined;\n}\n\nfunction formatDisjunction(values: string[]): string {\n if (values.length <= 1) {\n return values[0] ?? \"\";\n }\n if (values.length === 2) {\n return `${values[0]} or ${values[1]}`;\n }\n return `${values.slice(0, -1).join(\", \")}, or ${values.at(-1)}`;\n}\n\nfunction parseAuthMethodIdsFromMessage(message: string): string[] {\n const methods: string[] = [];\n const methodListMatch = message.match(/auth methods \\[([^\\]]+)\\]/iu);\n if (methodListMatch) {\n methods.push(\n ...methodListMatch[1]\n .split(\",\")\n .map((entry) => entry.trim())\n .filter((entry) => entry.length > 0),\n );\n }\n\n const singleMethodMatch = message.match(/auth method ([\\w.-]+)/iu);\n if (singleMethodMatch) {\n methods.push(singleMethodMatch[1]);\n }\n\n return dedupeStrings(methods);\n}\n\nfunction parseAuthMethodIdsFromAcpData(data: unknown): string[] {\n const record = asRecord(data);\n if (!record) {\n return [];\n }\n\n const methodIds: string[] = [];\n if (typeof record.methodId === \"string\" && record.methodId.trim().length > 0) {\n methodIds.push(record.methodId.trim());\n }\n\n if (Array.isArray(record.methods)) {\n for (const entry of record.methods) {\n const id = parseAuthMethodIdEntry(entry);\n if (id) {\n methodIds.push(id);\n }\n }\n }\n\n return dedupeStrings(methodIds);\n}\n\nfunction parseAuthMethodIdEntry(entry: unknown): string | undefined {\n if (typeof entry === \"string\" && entry.trim().length > 0) {\n return entry.trim();\n }\n\n const id = asRecord(entry)?.id;\n return typeof id === \"string\" && id.trim().length > 0 ? id.trim() : undefined;\n}\n\nfunction renderAuthRequiredHint(params: RenderableOutputError): string {\n const methodIds = dedupeStrings([\n ...parseAuthMethodIdsFromAcpData(params.acp?.data),\n ...parseAuthMethodIdsFromMessage(params.message),\n ]);\n\n if (methodIds.length === 0) {\n return \"hint: run `acpx config show` to locate the active config, then add the required credential under `auth` and retry.\";\n }\n\n const configKeys = methodIds.map((methodId) => `\\`auth.${methodId}\\``);\n return `hint: run \\`acpx config show\\` to locate the active config, then add ${formatDisjunction(configKeys)} and retry.`;\n}\n\nexport function getTextErrorRemediationHints(params: RenderableOutputError): string[] {\n const lowerMessage = (preferredAcpErrorDetails(params.acp?.data) ?? params.message).toLowerCase();\n\n if (params.detailCode === \"AUTH_REQUIRED\") {\n return [renderAuthRequiredHint(params)];\n }\n\n if (params.code === \"TIMEOUT\") {\n return [\n \"hint: increase `--timeout <seconds>` for long-running prompts, or check whether the agent/provider is stalled.\",\n ];\n }\n\n if (params.code === \"NO_SESSION\") {\n return noSessionHints(lowerMessage);\n }\n\n return matchingTextErrorRule(params, lowerMessage)?.hints ?? [];\n}\n\ntype TextErrorHintRule = {\n matches: (params: RenderableOutputError, lowerMessage: string) => boolean;\n hints: string[];\n};\n\nconst TEXT_ERROR_HINT_RULES: TextErrorHintRule[] = [\n {\n matches: (_params, lowerMessage) => isUnsupportedSessionLoadError(lowerMessage),\n hints: [\n \"hint: this adapter cannot resume saved ACP sessions; create a fresh one with `acpx <agent> sessions new` instead of reusing `--resume-session`.\",\n ],\n },\n {\n matches: (_params, lowerMessage) => isSessionLoadError(lowerMessage),\n hints: [\n \"hint: rerun with `--verbose` to capture the ACP load failure details.\",\n \"hint: if you do not need the old backend session, start a fresh one with `acpx <agent> sessions new` and retry.\",\n ],\n },\n {\n matches: (_params, lowerMessage) => isRateLimitError(lowerMessage),\n hints: [\n \"hint: the provider appears rate-limited; retry later, switch model, or check provider quota/billing.\",\n ],\n },\n {\n matches: (_params, lowerMessage) => isModelLookupError(lowerMessage),\n hints: [\n \"hint: check the configured model name for this agent, then retry with `--model <model>` or `sessions set-model <model>`.\",\n ],\n },\n {\n matches: (_params, lowerMessage) => isSessionConfigMethodError(lowerMessage),\n hints: [\n \"hint: rerun with `--verbose` to capture the ACP method/error details before retrying.\",\n ],\n },\n {\n matches: isRuntimeAcpProtocolError,\n hints: [\"hint: rerun with `--verbose` to capture the underlying ACP error details.\"],\n },\n];\n\nfunction matchingTextErrorRule(\n params: RenderableOutputError,\n lowerMessage: string,\n): TextErrorHintRule | undefined {\n return TEXT_ERROR_HINT_RULES.find((rule) => rule.matches(params, lowerMessage));\n}\n\nfunction noSessionHints(lowerMessage: string): string[] {\n if (lowerMessage.includes(\"create one:\")) {\n return [];\n }\n return [\n \"hint: the saved ACP session is missing or stale; start a fresh session with `acpx <agent> sessions new`, then retry.\",\n ];\n}\n\nfunction isUnsupportedSessionLoadError(lowerMessage: string): boolean {\n return (\n lowerMessage.includes(\"does not support session/resume\") ||\n lowerMessage.includes(\"does not support session/load\")\n );\n}\n\nfunction isSessionLoadError(lowerMessage: string): boolean {\n return (\n lowerMessage.includes(\"failed to resume acp session\") ||\n lowerMessage.includes(\"session/resume\") ||\n lowerMessage.includes(\"session/load\")\n );\n}\n\nfunction isRateLimitError(lowerMessage: string): boolean {\n return (\n /\\b429\\b/u.test(lowerMessage) ||\n [\"rate limit\", \"quota exceeded\", \"usage limit\"].some((text) => lowerMessage.includes(text))\n );\n}\n\nfunction isModelLookupError(lowerMessage: string): boolean {\n return [\"model not found\", \"unknown model\", \"invalid model\"].some((text) =>\n lowerMessage.includes(text),\n );\n}\n\nfunction isSessionConfigMethodError(lowerMessage: string): boolean {\n return [\"session/set_mode\", \"session/set_model\", \"session/set_config_option\"].some((text) =>\n lowerMessage.includes(text),\n );\n}\n\nfunction isRuntimeAcpProtocolError(params: RenderableOutputError, lowerMessage: string): boolean {\n return (\n params.origin === \"acp\" &&\n params.code === \"RUNTIME\" &&\n (params.acp?.code === -32602 ||\n params.acp?.code === -32603 ||\n lowerMessage.includes(\"internal error\"))\n );\n}\n\nfunction summarizeToolInput(rawInput: unknown): string | undefined {\n if (rawInput == null) {\n return undefined;\n }\n\n if (isScalarToolInput(rawInput)) {\n return toInline(String(rawInput));\n }\n\n const record = asRecord(rawInput);\n if (record) {\n return summarizeToolInputRecord(record) ?? summarizeToolInputJson(rawInput);\n }\n\n return summarizeToolInputJson(rawInput);\n}\n\nfunction isScalarToolInput(value: unknown): value is string | number | boolean {\n return typeof value === \"string\" || typeof value === \"number\" || typeof value === \"boolean\";\n}\n\nfunction summarizeToolInputRecord(record: Record<string, unknown>): string | undefined {\n const command = readFirstString(record, [\"command\", \"cmd\", \"program\"]);\n const args = readFirstStringArray(record, [\"args\", \"arguments\"]);\n if (command) {\n return toInline([command, ...(args ?? [])].join(\" \"));\n }\n\n const location = readFirstString(record, [\n \"path\",\n \"file\",\n \"filePath\",\n \"filepath\",\n \"target\",\n \"uri\",\n \"url\",\n ]);\n const query = readFirstString(record, [\"query\", \"pattern\", \"text\", \"search\"]);\n return location || query ? toInline(location ?? query ?? \"\") : undefined;\n}\n\nfunction summarizeToolInputJson(rawInput: unknown): string | undefined {\n const json = safeJson(rawInput, 0);\n return json ? toInline(json) : undefined;\n}\n\nfunction malformedToolUpdateMessage(update: {\n locations?: unknown;\n content?: unknown;\n}): string | undefined {\n if (update.locations != null && !validToolLocations(update.locations)) {\n return \"Malformed tool call locations\";\n }\n const contentError = malformedToolContentMessage(update.content);\n return contentError;\n}\n\nfunction validToolLocations(locations: unknown): boolean {\n return Array.isArray(locations) && locations.every(validToolLocation);\n}\n\nfunction validToolLocation(location: unknown): boolean {\n const record = asRecord(location);\n if (!record) {\n return false;\n }\n if (record.path != null && typeof record.path !== \"string\") {\n return false;\n }\n return record.line == null || (typeof record.line === \"number\" && Number.isFinite(record.line));\n}\n\nfunction malformedToolContentMessage(content: unknown): string | undefined {\n if (content == null) {\n return undefined;\n }\n if (!Array.isArray(content)) {\n return \"Malformed tool call content\";\n }\n for (const entry of content) {\n const error = malformedToolContentEntry(entry);\n if (error) {\n return error;\n }\n }\n return undefined;\n}\n\nfunction malformedToolContentEntry(entry: unknown): string | undefined {\n const record = asRecord(entry);\n if (!record) {\n return \"Malformed tool call content\";\n }\n if (record.type === \"diff\") {\n return malformedDiffMessage(record);\n }\n if (record.type === \"content\" && !validToolContentBlock(record.content)) {\n return \"Malformed tool call content\";\n }\n if (record.type === \"terminal\" && typeof record.terminalId !== \"string\") {\n return \"Malformed tool call content\";\n }\n return undefined;\n}\n\nfunction malformedDiffMessage(record: Record<string, unknown>): string | undefined {\n if (\n typeof record.path === \"string\" &&\n typeof record.newText === \"string\" &&\n (record.oldText == null || typeof record.oldText === \"string\")\n ) {\n return undefined;\n }\n return \"Malformed tool call diff\";\n}\n\nfunction validToolContentBlock(content: unknown): boolean {\n const block = asRecord(content);\n if (!block || typeof block.type !== \"string\") {\n return false;\n }\n if (block.type === \"text\") {\n return typeof block.text === \"string\";\n }\n if (block.type === \"resource\") {\n return asRecord(block.resource) !== undefined;\n }\n return true;\n}\n\nfunction formatLocations(\n locations: Array<ToolCallLocation> | null | undefined,\n): string | undefined {\n if (!Array.isArray(locations) || locations.length === 0) {\n return undefined;\n }\n\n const unique = new Set<string>();\n for (const location of locations) {\n const formatted = formatLocation(location);\n if (formatted) {\n unique.add(formatted);\n }\n }\n\n const items = [...unique];\n if (items.length === 0) {\n return undefined;\n }\n\n const visible = items.slice(0, MAX_LOCATION_ITEMS);\n const hidden = items.length - visible.length;\n if (hidden <= 0) {\n return visible.join(\", \");\n }\n\n return `${visible.join(\", \")}, +${hidden} more`;\n}\n\nfunction formatLocation(location: ToolCallLocation): string | undefined {\n if (!location || typeof location !== \"object\") {\n return undefined;\n }\n const rawPath = location.path;\n if (typeof rawPath !== \"string\") {\n return undefined;\n }\n const path = rawPath.trim();\n if (!path) {\n return undefined;\n }\n\n const line =\n typeof location.line === \"number\" && Number.isFinite(location.line)\n ? `:${Math.max(1, Math.trunc(location.line))}`\n : \"\";\n return `${path}${line}`;\n}\n\nfunction summarizeDiff(path: string, oldText: string | null | undefined, newText: string): string {\n const oldLines = oldText ? oldText.split(\"\\n\").length : 0;\n const newLines = newText.split(\"\\n\").length;\n const delta = newLines - oldLines;\n\n if (delta === 0) {\n return `diff ${path} (line count unchanged)`;\n }\n\n const signedDelta = `${delta > 0 ? \"+\" : \"\"}${delta}`;\n return `diff ${path} (${signedDelta} lines)`;\n}\n\nfunction textFromContentBlock(content: ContentBlock): string | undefined {\n switch (content.type) {\n case \"text\":\n return content.text;\n case \"resource_link\":\n return content.title ?? content.name ?? content.uri;\n case \"resource\": {\n return textFromResourceBlock(content);\n }\n case \"image\":\n return `[image] ${content.mimeType}`;\n case \"audio\":\n return `[audio] ${content.mimeType}`;\n default:\n return undefined;\n }\n}\n\nfunction textFromResourceBlock(content: Extract<ContentBlock, { type: \"resource\" }>): string {\n if (!content.resource || typeof content.resource !== \"object\") {\n return \"[resource]\";\n }\n if (\"text\" in content.resource && typeof content.resource.text === \"string\") {\n return content.resource.text;\n }\n const uri = content.resource.uri;\n const mimeType = content.resource.mimeType;\n return `[resource] ${uri}${mimeType ? ` (${mimeType})` : \"\"}`;\n}\n\nfunction summarizeToolContent(\n content: Array<ToolCallContent> | null | undefined,\n): string | undefined {\n if (!Array.isArray(content) || content.length === 0) {\n return undefined;\n }\n\n const fragments: string[] = [];\n\n for (const entry of content) {\n const fragment = summarizeToolContentEntry(entry);\n if (fragment) {\n fragments.push(fragment);\n }\n }\n\n const unique = dedupeStrings(\n fragments.map((fragment) => fragment.trim()).filter((fragment) => fragment.length > 0),\n );\n if (unique.length === 0) {\n return undefined;\n }\n\n return unique.join(\"\\n\\n\");\n}\n\nfunction summarizeToolContentEntry(entry: ToolCallContent): string | undefined {\n if (!entry || typeof entry !== \"object\") {\n return undefined;\n }\n if (entry.type === \"content\") {\n return summarizeContentEntry(entry);\n }\n if (entry.type === \"diff\") {\n return summarizeDiffEntry(entry);\n }\n if (entry.type === \"terminal\") {\n return `[terminal] ${entry.terminalId}`;\n }\n return undefined;\n}\n\nfunction summarizeContentEntry(\n entry: Extract<ToolCallContent, { type: \"content\" }>,\n): string | undefined {\n if (!entry.content || typeof entry.content !== \"object\") {\n return undefined;\n }\n const text = textFromContentBlock(entry.content);\n return typeof text === \"string\" && text.trim() ? text.trimEnd() : undefined;\n}\n\nfunction summarizeDiffEntry(entry: Extract<ToolCallContent, { type: \"diff\" }>): string | undefined {\n if (typeof entry.path !== \"string\" || typeof entry.newText !== \"string\") {\n return undefined;\n }\n const oldText = typeof entry.oldText === \"string\" ? entry.oldText : undefined;\n return summarizeDiff(entry.path, oldText, entry.newText);\n}\n\nfunction extractOutputText(\n value: unknown,\n depth = 0,\n seen = new Set<unknown>(),\n): string | undefined {\n if (value == null) {\n return undefined;\n }\n\n const scalar = extractScalarOutputText(value);\n if (scalar !== null) {\n return scalar;\n }\n\n if (depth >= 4) {\n return undefined;\n }\n\n if (Array.isArray(value)) {\n return extractOutputTextArray(value, depth, seen);\n }\n\n return extractOutputTextRecord(value, depth, seen);\n}\n\nfunction extractOutputTextRecord(\n value: unknown,\n depth: number,\n seen: Set<unknown>,\n): string | undefined {\n const record = asRecord(value);\n if (!record || seen.has(record)) {\n return undefined;\n }\n\n seen.add(record);\n\n return extractPreferredOutputText(record, depth, seen) ?? extractJsonOutputText(record);\n}\n\nfunction extractScalarOutputText(value: unknown): string | undefined | null {\n if (typeof value === \"string\") {\n const trimmed = value.trimEnd();\n return trimmed.length > 0 ? trimmed : undefined;\n }\n\n if (typeof value === \"number\" || typeof value === \"boolean\") {\n return String(value);\n }\n\n return null;\n}\n\nfunction extractOutputTextArray(\n value: unknown[],\n depth: number,\n seen: Set<unknown>,\n): string | undefined {\n const parts = value\n .map((entry) => extractOutputText(entry, depth + 1, seen))\n .filter((entry): entry is string => Boolean(entry));\n return parts.length > 0 ? dedupeStrings(parts).join(\"\\n\") : undefined;\n}\n\nfunction extractPreferredOutputText(\n record: Record<string, unknown>,\n depth: number,\n seen: Set<unknown>,\n): string | undefined {\n const preferred = OUTPUT_PRIORITY_KEYS.flatMap((key) => {\n if (!(key in record)) {\n return [];\n }\n const extracted = extractOutputText(record[key], depth + 1, seen);\n return extracted ? [extracted] : [];\n });\n const uniquePreferred = dedupeStrings(preferred);\n return uniquePreferred.length > 0 ? uniquePreferred.join(\"\\n\") : undefined;\n}\n\nfunction extractJsonOutputText(record: Record<string, unknown>): string | undefined {\n const json = safeJson(record, 2);\n return !json || json === \"{}\" ? undefined : json;\n}\n\nfunction summarizeToolOutput(\n rawOutput: unknown,\n content: Array<ToolCallContent> | null | undefined,\n): string | undefined {\n const outputFromRaw = extractOutputText(rawOutput);\n const outputFromContent = summarizeToolContent(content);\n\n const fragments = dedupeStrings(\n [outputFromRaw, outputFromContent]\n .map((fragment) => fragment?.trim())\n .filter((fragment): fragment is string => Boolean(fragment)),\n );\n\n if (fragments.length === 0) {\n return undefined;\n }\n\n return fragments.join(\"\\n\\n\");\n}\n\nfunction renderToolOutput(state: ToolRenderState, suppressReads: boolean): string | undefined {\n if (suppressReads && isReadLikeTool(state)) {\n return SUPPRESSED_READ_OUTPUT;\n }\n\n return summarizeToolOutput(state.rawOutput, state.content);\n}\n\nfunction limitOutputBlock(value: string): string {\n const normalized = value.replace(/\\r\\n/g, \"\\n\").trim();\n if (!normalized) {\n return \"\";\n }\n\n const lines = normalized.split(\"\\n\");\n const visible = lines.slice(0, MAX_OUTPUT_LINES);\n let result = visible.join(\"\\n\");\n\n if (lines.length > visible.length) {\n const hidden = lines.length - visible.length;\n result += `\\n... (${hidden} more lines)`;\n }\n\n if (result.length > MAX_OUTPUT_CHARS) {\n result = `${result.slice(0, MAX_OUTPUT_CHARS - 3)}...`;\n }\n\n return result;\n}\n\nclass TextOutputFormatter implements OutputFormatter {\n private readonly stdout: WritableLike;\n private readonly useColor: boolean;\n private readonly suppressReads: boolean;\n private readonly toolStates = new Map<string, ToolRenderState>();\n private thoughtBuffer = \"\";\n private wroteAny = false;\n private atLineStart = true;\n\n constructor(stdout: WritableLike, suppressReads: boolean) {\n this.stdout = stdout;\n this.useColor = Boolean(stdout.isTTY);\n this.suppressReads = suppressReads;\n }\n\n setContext(_context: OutputFormatterContext): void {\n // no-op for text mode\n }\n\n onAcpMessage(message: AcpJsonRpcMessage): void {\n const notice = parsePermissionNotice(message);\n if (notice) {\n this.beginSection();\n this.writeLine(`${this.bold(\"[permission]\")} ${notice}`);\n return;\n }\n const notification = extractSessionUpdateNotification(message);\n if (notification) {\n this.renderSessionUpdate(notification);\n return;\n }\n\n const method = extractJsonRpcMethod(message);\n if (method && ![\"session/prompt\", \"session/cancel\", \"session/update\"].includes(method)) {\n this.onClientOperation({\n method: method as ClientOperation[\"method\"],\n status: \"running\",\n summary: method,\n timestamp: new Date().toISOString(),\n });\n return;\n }\n\n const stopReason = parsePromptStopReason(message);\n if (stopReason) {\n this.renderDone(stopReason);\n return;\n }\n\n const errorMessage = parseJsonRpcErrorSummary(message);\n if (errorMessage) {\n this.onError({\n code: \"RUNTIME\",\n origin: \"acp\",\n message: errorMessage,\n });\n }\n }\n\n private renderSessionUpdate(notification: SessionNotification): void {\n const update = notification.update;\n if (update.sessionUpdate !== \"agent_thought_chunk\") {\n this.flushThoughtBuffer();\n }\n this.renderSessionUpdateBody(update);\n }\n\n private renderSessionUpdateBody(update: SessionNotification[\"update\"]): void {\n switch (update.sessionUpdate) {\n case \"agent_message_chunk\": {\n if (update.content.type === \"text\") {\n this.write(update.content.text);\n }\n return;\n }\n case \"agent_thought_chunk\": {\n if (update.content.type === \"text\") {\n this.thoughtBuffer += update.content.text;\n }\n return;\n }\n case \"tool_call\": {\n this.renderToolUpdate(update);\n return;\n }\n case \"tool_call_update\": {\n this.renderToolUpdate(update);\n return;\n }\n case \"plan\": {\n this.renderPlanUpdate(update.entries);\n return;\n }\n default:\n return;\n }\n }\n\n private renderPlanUpdate(\n entries: Extract<SessionNotification[\"update\"], { sessionUpdate: \"plan\" }>[\"entries\"],\n ): void {\n this.beginSection();\n this.writeLine(this.bold(\"[plan]\"));\n for (const entry of entries) {\n this.writeLine(` - [${entry.status}] ${entry.content}`);\n }\n }\n\n private renderDone(stopReason: string): void {\n this.flushThoughtBuffer();\n this.beginSection();\n this.writeLine(this.dim(`[done] ${stopReason}`));\n }\n\n onError(params: RenderableOutputError): void {\n this.flushThoughtBuffer();\n this.beginSection();\n const message = preferredAcpErrorDetails(params.acp?.data) ?? params.message;\n this.writeLine(this.formatAnsi(`[error] ${params.code}: ${message}`, \"31\"));\n for (const hint of getTextErrorRemediationHints(params)) {\n this.writeLine(this.dim(hint));\n }\n }\n\n onClientOperation(operation: ClientOperation): void {\n this.flushThoughtBuffer();\n this.beginSection();\n\n const normalizedStatus: NormalizedToolStatus =\n operation.status === \"completed\"\n ? \"completed\"\n : operation.status === \"failed\"\n ? \"failed\"\n : \"in_progress\";\n const statusText = this.colorStatus(operation.status, normalizedStatus);\n this.writeLine(`${this.bold(\"[client]\")} ${operation.summary} (${statusText})`);\n if (operation.details && operation.details.trim().length > 0) {\n this.writeLine(\" details:\");\n this.writeLine(indentBlock(operation.details, \" \"));\n }\n }\n\n onPermissionEscalation(event: PermissionEscalationEvent): void {\n this.flushThoughtBuffer();\n this.beginSection();\n this.writeLine(`${this.bold(\"[permission]\")} ${event.message}`);\n const details = [\n `sessionId: ${event.sessionId}`,\n `toolCallId: ${event.toolCallId}`,\n event.toolName ? `toolName: ${event.toolName}` : undefined,\n `toolTitle: ${event.toolTitle}`,\n event.toolInput !== undefined\n ? `toolInput: ${summarizeToolInput(event.toolInput) ?? \"(structured input)\"}`\n : undefined,\n event.toolKind ? `toolKind: ${event.toolKind}` : undefined,\n event.matchedRule ? `matchedRule: ${event.matchedRule}` : undefined,\n ].filter((line): line is string => Boolean(line));\n this.writeLine(indentBlock(details.join(\"\\n\"), \" \"));\n }\n\n flush(): void {\n this.flushThoughtBuffer();\n if (!this.atLineStart) {\n this.write(\"\\n\");\n }\n }\n\n private write(chunk: string): void {\n if (!chunk) {\n return;\n }\n this.stdout.write(chunk);\n this.wroteAny = true;\n this.atLineStart = chunk.endsWith(\"\\n\");\n }\n\n private writeLine(line: string): void {\n this.write(`${line}\\n`);\n }\n\n private beginSection(): void {\n if (!this.atLineStart) {\n this.write(\"\\n\");\n }\n if (this.wroteAny) {\n this.write(\"\\n\");\n }\n }\n\n private flushThoughtBuffer(): void {\n const thought = truncate(normalizeLineEndings(this.thoughtBuffer).trim(), MAX_THOUGHT_CHARS);\n this.thoughtBuffer = \"\";\n if (!thought) {\n return;\n }\n\n this.beginSection();\n const [firstLine, ...restLines] = thought.split(\"\\n\");\n this.writeLine(this.dim(`[thinking] ${firstLine}`));\n for (const line of restLines) {\n this.writeLine(this.dim(` ${line}`));\n }\n }\n\n private renderToolUpdate(update: ToolCall | ToolCallUpdate): void {\n const shapeError = malformedToolUpdateMessage(update);\n if (shapeError) {\n this.onError({\n code: \"RUNTIME\",\n origin: \"acp\",\n message: shapeError,\n });\n return;\n }\n const state = this.getOrCreateToolState(update.toolCallId);\n this.mergeToolState(state, update);\n\n const status = asStatus(state.status);\n const final = isFinalStatus(status);\n if (!final && state.startedPrinted) {\n return;\n }\n const display: ToolDisplay = {\n input: summarizeToolInput(state.rawInput),\n files: formatLocations(state.locations),\n output: final ? renderToolOutput(state, this.suppressReads) : undefined,\n };\n if (final) {\n const payload = { title: state.title, status: state.status, kind: state.kind, ...display };\n const signature = safeJson(payload, 0) ?? JSON.stringify(payload);\n if (signature === state.finalSignature) {\n return;\n }\n state.finalSignature = signature;\n } else {\n state.startedPrinted = true;\n }\n this.renderToolState(state, status, display);\n }\n\n private getOrCreateToolState(toolCallId: string): ToolRenderState {\n const existing = this.toolStates.get(toolCallId);\n if (existing) {\n return existing;\n }\n\n const created: ToolRenderState = {\n id: toolCallId,\n startedPrinted: false,\n };\n this.toolStates.set(toolCallId, created);\n return created;\n }\n\n private mergeToolState(state: ToolRenderState, update: ToolCall | ToolCallUpdate): void {\n this.mergeToolTitle(state, update.title);\n this.mergeToolPayloadState(state, update);\n }\n\n private mergeToolTitle(state: ToolRenderState, title: string | null | undefined): void {\n if (typeof title === \"string\" && title.trim().length > 0) {\n state.title = title;\n }\n }\n\n private mergeToolPayloadState(state: ToolRenderState, update: ToolCall | ToolCallUpdate): void {\n if (update.status !== undefined) {\n state.status = update.status;\n }\n if (update.kind !== undefined) {\n state.kind = update.kind;\n }\n if (update.locations !== undefined) {\n state.locations = update.locations;\n }\n if (update.rawInput !== undefined) {\n state.rawInput = update.rawInput;\n }\n if (update.rawOutput !== undefined) {\n state.rawOutput = update.rawOutput;\n }\n if (update.content !== undefined) {\n state.content = update.content;\n }\n }\n\n private renderToolState(\n state: ToolRenderState,\n status: NormalizedToolStatus,\n display: ToolDisplay,\n ): void {\n this.beginSection();\n const title = state.title ?? state.id;\n const statusText = this.colorStatus(toStatusLabel(status), status);\n this.writeLine(`${this.bold(\"[tool]\")} ${title} (${statusText})`);\n if (isFinalStatus(status) && state.kind) {\n this.writeLine(` kind: ${state.kind}`);\n }\n if (display.input) {\n this.writeLine(` input: ${display.input}`);\n }\n if (display.files) {\n this.writeLine(` files: ${display.files}`);\n }\n if (display.output) {\n this.writeLine(\" output:\");\n this.writeLine(indentBlock(limitOutputBlock(display.output), \" \"));\n }\n }\n\n private formatAnsi(text: string, code: string): string {\n if (!this.useColor) {\n return text;\n }\n return `\\u001b[${code}m${text}\\u001b[0m`;\n }\n\n private bold(text: string): string {\n return this.formatAnsi(text, \"1\");\n }\n\n private dim(text: string): string {\n return this.formatAnsi(text, \"2\");\n }\n\n private colorStatus(text: string, status: NormalizedToolStatus): string {\n if (!this.useColor) {\n return text;\n }\n\n switch (status) {\n case \"completed\":\n return this.formatAnsi(text, \"32\");\n case \"failed\":\n return this.formatAnsi(text, \"31\");\n case \"pending\":\n case \"in_progress\":\n case \"unknown\":\n default:\n return this.formatAnsi(text, \"33\");\n }\n }\n}\n\nclass QuietOutputFormatter implements OutputFormatter {\n private readonly stdout: WritableLike;\n private readonly stderr: WritableLike;\n private chunks: string[] = [];\n private finished = false;\n private outputWritten = false;\n private metadataFlushed = false;\n\n constructor(stdout: WritableLike, stderr: WritableLike) {\n this.stdout = stdout;\n this.stderr = stderr;\n }\n\n setContext(_context: OutputFormatterContext): void {\n // no-op for quiet mode\n }\n\n onAcpMessage(message: AcpJsonRpcMessage): void {\n const notice = parsePermissionNotice(message);\n if (notice) {\n this.stderr.write(`[acpx] permission: ${notice.replace(/\\r\\n?|\\n/g, \" \")}\\n`);\n return;\n }\n const update = extractSessionUpdateNotification(message);\n if (\n update?.update.sessionUpdate === \"agent_message_chunk\" &&\n update.update.content.type === \"text\"\n ) {\n if (!this.finished) {\n this.chunks.push(update.update.content.text);\n }\n return;\n }\n\n if (parsePromptStopReason(message)) {\n if (!this.finished) {\n this.finished = true;\n this.flushBufferedOutput(true);\n }\n this.flushMetadata(message);\n }\n }\n\n onError(params: {\n code: OutputErrorCode;\n detailCode?: string;\n origin?: OutputErrorOrigin;\n message: string;\n retryable?: boolean;\n acp?: OutputErrorAcpPayload;\n timestamp?: string;\n }): void {\n this.flush();\n const qualifier = params.detailCode ? `${params.code} ${params.detailCode}` : params.code;\n const message = preferredAcpErrorDetails(params.acp?.data) ?? params.message;\n this.stderr.write(`[acpx] error: ${qualifier} ${message.replace(/\\r\\n?|\\n/g, \" \")}\\n`);\n }\n\n onPermissionEscalation(_event: PermissionEscalationEvent): void {\n // no-op in quiet mode\n }\n\n flush(): void {\n this.flushBufferedOutput();\n }\n\n private flushBufferedOutput(allowEmpty = false): void {\n const text = this.chunks.join(\"\");\n this.chunks = [];\n if (text.length === 0 && (!allowEmpty || this.outputWritten)) {\n return;\n }\n this.outputWritten = true;\n this.stdout.write(text.endsWith(\"\\n\") ? text : `${text}\\n`);\n }\n\n private flushMetadata(message: AcpJsonRpcMessage): void {\n if (this.metadataFlushed) {\n return;\n }\n\n this.metadataFlushed = true;\n const result = asRecord((message as { result?: unknown }).result);\n if (!result) {\n return;\n }\n\n const usageLine = this.formatUsageLine(asRecord(result.usage));\n if (usageLine) {\n this.stderr.write(`${usageLine}\\n`);\n }\n\n const costLine = this.formatCostLine(result.cost);\n if (costLine) {\n this.stderr.write(`${costLine}\\n`);\n }\n }\n\n private formatUsageLine(usage: Record<string, unknown> | undefined): string | undefined {\n if (!usage) {\n return undefined;\n }\n\n const parts: string[] = [];\n const fields: Array<[string, string[]]> = [\n [\"input\", [\"inputTokens\", \"input_tokens\"]],\n [\"output\", [\"outputTokens\", \"output_tokens\"]],\n [\"cache_read\", [\"cachedReadTokens\", \"cacheReadInputTokens\", \"cache_read_input_tokens\"]],\n [\n \"cache_write\",\n [\"cachedWriteTokens\", \"cacheCreationInputTokens\", \"cache_creation_input_tokens\"],\n ],\n [\"total\", [\"totalTokens\", \"total_tokens\"]],\n ];\n\n for (const [label, keys] of fields) {\n const value = readFirstFiniteNumber(usage, keys);\n if (value !== undefined) {\n parts.push(`${label}=${formatMetadataNumber(value)}`);\n }\n }\n\n return parts.length > 0 ? `[acpx] tokens: ${parts.join(\" \")}` : undefined;\n }\n\n private formatCostLine(cost: unknown): string | undefined {\n const scalar = this.formatScalarCostLine(cost);\n if (scalar) {\n return scalar;\n }\n const record = asRecord(cost);\n if (!record) {\n return undefined;\n }\n\n const amount = readFirstFiniteNumber(record, [\"amount\", \"value\", \"total\"]);\n if (amount === undefined) {\n return undefined;\n }\n\n const currency =\n typeof record.currency === \"string\" && record.currency.trim()\n ? ` ${record.currency.trim()}`\n : \"\";\n return `[acpx] cost: ${formatMetadataNumber(amount)}${currency}`;\n }\n\n private formatScalarCostLine(cost: unknown): string | undefined {\n if (typeof cost === \"number\" && Number.isFinite(cost)) {\n return `[acpx] cost: ${formatMetadataNumber(cost)}`;\n }\n\n if (typeof cost === \"string\" && cost.trim()) {\n return `[acpx] cost: ${cost.trim()}`;\n }\n\n return undefined;\n }\n}\n\nfunction preferredAcpErrorDetails(data: unknown): string | undefined {\n const record = asRecord(data);\n for (const value of [record?.details, record?.message]) {\n if (typeof value === \"string\" && value.trim().length > 0) {\n return value.trim();\n }\n }\n return undefined;\n}\n\nexport function createOutputFormatter(\n format: OutputFormat,\n options: OutputFormatterOptions = {},\n): OutputFormatter {\n const stdout = options.stdout ?? process.stdout;\n const stderr = options.stderr ?? process.stderr;\n const suppressReads = options.suppressReads === true;\n\n switch (format) {\n case \"text\":\n return new TextOutputFormatter(stdout, suppressReads);\n case \"json\":\n return createJsonOutputFormatter(stdout, suppressReads, options.jsonContext);\n case \"quiet\":\n return new QuietOutputFormatter(stdout, stderr);\n default: {\n const exhaustive: never = format;\n void exhaustive;\n throw new Error(\"Unsupported output format\");\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACAA,MAAa,qBAAqB;AAElC,SAAgB,oBAAoB,SAAiB,WAAwC;CAC3F,IAAI,aAAa,YAAY,GAC3B,OAAO;CAET,MAAM,eAAe,KAAK,IAAI,GAAG,KAAK,MAAM,UAAU,GAAI,CAAC;CAC3D,OAAO,gBAAA,aAAqC,eAAe,KAAA;AAC7D;;;ACNA,MAAa,6BAA8D;CACzE,YAAY;CACZ,SAAS;CACT,mBAAmB;CACnB,+BAA+B;CAC/B,eAAe;CACf,SAAS;CACT,OAAO;AACT;AAoBA,SAAS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