comisai 1.0.24 → 1.0.26

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 (192) hide show
  1. package/node_modules/@comis/agent/dist/bootstrap/sections/tool-descriptions.js +130 -10
  2. package/node_modules/@comis/agent/dist/bootstrap/sections/tooling-sections.d.ts +1 -1
  3. package/node_modules/@comis/agent/dist/bootstrap/sections/tooling-sections.js +9 -2
  4. package/node_modules/@comis/agent/dist/bridge/bridge-metrics.d.ts +8 -0
  5. package/node_modules/@comis/agent/dist/bridge/bridge-metrics.js +2 -0
  6. package/node_modules/@comis/agent/dist/bridge/pi-event-bridge.d.ts +29 -0
  7. package/node_modules/@comis/agent/dist/bridge/pi-event-bridge.js +242 -2
  8. package/node_modules/@comis/agent/dist/bridge/thinking-block-hash-invariant.d.ts +210 -0
  9. package/node_modules/@comis/agent/dist/bridge/thinking-block-hash-invariant.js +566 -0
  10. package/node_modules/@comis/agent/dist/context-engine/context-engine.js +8 -6
  11. package/node_modules/@comis/agent/dist/context-engine/signature-replay-scrubber.d.ts +51 -30
  12. package/node_modules/@comis/agent/dist/context-engine/signature-replay-scrubber.js +109 -36
  13. package/node_modules/@comis/agent/dist/executor/executor-context-engine-setup.js +5 -1
  14. package/node_modules/@comis/agent/dist/executor/executor-post-execution.js +22 -20
  15. package/node_modules/@comis/agent/dist/executor/executor-prompt-runner.d.ts +2 -0
  16. package/node_modules/@comis/agent/dist/executor/executor-prompt-runner.js +111 -15
  17. package/node_modules/@comis/agent/dist/executor/executor-response-filter.d.ts +20 -17
  18. package/node_modules/@comis/agent/dist/executor/executor-response-filter.js +132 -52
  19. package/node_modules/@comis/agent/dist/executor/executor-tool-assembly.js +16 -3
  20. package/node_modules/@comis/agent/dist/executor/model-retry.d.ts +14 -0
  21. package/node_modules/@comis/agent/dist/executor/model-retry.js +72 -1
  22. package/node_modules/@comis/agent/dist/executor/pi-executor.d.ts +3 -0
  23. package/node_modules/@comis/agent/dist/executor/pi-executor.js +68 -9
  24. package/node_modules/@comis/agent/dist/executor/post-batch-continuation.d.ts +82 -0
  25. package/node_modules/@comis/agent/dist/executor/post-batch-continuation.js +200 -0
  26. package/node_modules/@comis/agent/dist/executor/stream-wrappers/request-body-injector.js +1 -9
  27. package/node_modules/@comis/agent/dist/executor/tool-deferral.d.ts +37 -2
  28. package/node_modules/@comis/agent/dist/executor/tool-deferral.js +45 -3
  29. package/node_modules/@comis/agent/dist/executor/tool-parallelism.js +0 -1
  30. package/node_modules/@comis/agent/dist/executor/types.d.ts +11 -2
  31. package/node_modules/@comis/agent/dist/index.d.ts +3 -1
  32. package/node_modules/@comis/agent/dist/index.js +2 -0
  33. package/node_modules/@comis/agent/dist/model/last-known-model.d.ts +36 -0
  34. package/node_modules/@comis/agent/dist/model/last-known-model.js +49 -0
  35. package/node_modules/@comis/agent/dist/model/model-registry-adapter.d.ts +16 -4
  36. package/node_modules/@comis/agent/dist/model/model-registry-adapter.js +65 -21
  37. package/node_modules/@comis/agent/dist/planner/types.d.ts +0 -2
  38. package/node_modules/@comis/agent/dist/session/comis-session-manager.d.ts +10 -0
  39. package/node_modules/@comis/agent/dist/session/comis-session-manager.js +5 -0
  40. package/node_modules/@comis/agent/dist/spawn/pi-mono-adapters.js +7 -0
  41. package/node_modules/@comis/agent/package.json +1 -1
  42. package/node_modules/@comis/channels/package.json +1 -1
  43. package/node_modules/@comis/cli/dist/client/rpc-client.js +6 -1
  44. package/node_modules/@comis/cli/dist/commands/doctor.js +5 -3
  45. package/node_modules/@comis/cli/dist/commands/health.js +5 -2
  46. package/node_modules/@comis/cli/dist/wizard/json-output.js +7 -3
  47. package/node_modules/@comis/cli/dist/wizard/steps/11-daemon-start.js +130 -0
  48. package/node_modules/@comis/cli/package.json +1 -1
  49. package/node_modules/@comis/core/dist/bootstrap.js +5 -0
  50. package/node_modules/@comis/core/dist/config/env-layer.d.ts +31 -0
  51. package/node_modules/@comis/core/dist/config/env-layer.js +41 -0
  52. package/node_modules/@comis/core/dist/config/immutable-keys.d.ts +2 -2
  53. package/node_modules/@comis/core/dist/config/immutable-keys.js +8 -3
  54. package/node_modules/@comis/core/dist/config/layered.d.ts +9 -0
  55. package/node_modules/@comis/core/dist/config/layered.js +11 -0
  56. package/node_modules/@comis/core/dist/config/managed-sections.d.ts +43 -4
  57. package/node_modules/@comis/core/dist/config/managed-sections.js +100 -6
  58. package/node_modules/@comis/core/dist/config/schema-agent.d.ts +39 -0
  59. package/node_modules/@comis/core/dist/config/schema-agent.js +14 -0
  60. package/node_modules/@comis/core/dist/config/schema.d.ts +4 -0
  61. package/node_modules/@comis/core/dist/config/schema.js +14 -0
  62. package/node_modules/@comis/core/dist/domain/execution-graph.d.ts +1 -1
  63. package/node_modules/@comis/core/dist/event-bus/events-agent.d.ts +17 -2
  64. package/node_modules/@comis/core/dist/exports/config.d.ts +2 -2
  65. package/node_modules/@comis/core/dist/exports/config.js +1 -1
  66. package/node_modules/@comis/core/package.json +1 -1
  67. package/node_modules/@comis/daemon/dist/daemon.d.ts +22 -0
  68. package/node_modules/@comis/daemon/dist/daemon.js +45 -0
  69. package/node_modules/@comis/daemon/dist/rpc/agent-handlers.d.ts +5 -2
  70. package/node_modules/@comis/daemon/dist/rpc/agent-handlers.js +80 -1
  71. package/node_modules/@comis/daemon/dist/rpc/agent-inline-workspace.d.ts +67 -0
  72. package/node_modules/@comis/daemon/dist/rpc/agent-inline-workspace.js +139 -0
  73. package/node_modules/@comis/daemon/dist/rpc/model-handlers.d.ts +3 -0
  74. package/node_modules/@comis/daemon/dist/rpc/model-handlers.js +29 -5
  75. package/node_modules/@comis/daemon/dist/rpc/probe-provider-auth.d.ts +30 -0
  76. package/node_modules/@comis/daemon/dist/rpc/probe-provider-auth.js +59 -0
  77. package/node_modules/@comis/daemon/dist/rpc/provider-handlers.d.ts +37 -0
  78. package/node_modules/@comis/daemon/dist/rpc/provider-handlers.js +330 -0
  79. package/node_modules/@comis/daemon/dist/rpc/rpc-dispatch.js +18 -1
  80. package/node_modules/@comis/daemon/dist/setup-docker-restart-warn.d.ts +4 -0
  81. package/node_modules/@comis/daemon/dist/setup-docker-restart-warn.js +30 -0
  82. package/node_modules/@comis/daemon/dist/wiring/setup-agents.d.ts +3 -1
  83. package/node_modules/@comis/daemon/dist/wiring/setup-agents.js +28 -2
  84. package/node_modules/@comis/daemon/dist/wiring/setup-cross-session.js +1 -0
  85. package/node_modules/@comis/daemon/dist/wiring/setup-tools.js +7 -4
  86. package/node_modules/@comis/daemon/package.json +1 -1
  87. package/node_modules/@comis/gateway/package.json +1 -1
  88. package/node_modules/@comis/infra/dist/index.d.ts +1 -0
  89. package/node_modules/@comis/infra/dist/index.js +2 -0
  90. package/node_modules/@comis/infra/dist/runtime/is-docker.d.ts +1 -0
  91. package/node_modules/@comis/infra/dist/runtime/is-docker.js +25 -0
  92. package/node_modules/@comis/infra/package.json +1 -1
  93. package/node_modules/@comis/memory/package.json +1 -1
  94. package/node_modules/@comis/scheduler/package.json +1 -1
  95. package/node_modules/@comis/shared/package.json +1 -1
  96. package/node_modules/@comis/skills/dist/bridge/tool-metadata-registry.js +1 -3
  97. package/node_modules/@comis/skills/dist/builtin/platform/admin-manage-factory.js +24 -1
  98. package/node_modules/@comis/skills/dist/builtin/platform/agents-manage-tool.d.ts +53 -7
  99. package/node_modules/@comis/skills/dist/builtin/platform/agents-manage-tool.js +218 -24
  100. package/node_modules/@comis/skills/dist/builtin/platform/gateway-tool.d.ts +4 -1
  101. package/node_modules/@comis/skills/dist/builtin/platform/gateway-tool.js +16 -1
  102. package/node_modules/@comis/skills/dist/builtin/platform/index.d.ts +1 -1
  103. package/node_modules/@comis/skills/dist/builtin/platform/index.js +1 -1
  104. package/node_modules/@comis/skills/dist/builtin/platform/providers-manage-tool.d.ts +56 -0
  105. package/node_modules/@comis/skills/dist/builtin/platform/providers-manage-tool.js +203 -0
  106. package/node_modules/@comis/skills/dist/index.d.ts +1 -1
  107. package/node_modules/@comis/skills/dist/index.js +2 -2
  108. package/node_modules/@comis/skills/dist/policy/tool-policy.js +0 -1
  109. package/node_modules/@comis/skills/package.json +1 -1
  110. package/node_modules/@comis/web/dist/assets/{agent-detail-BG9MGWWj.js → agent-detail-DqL6Artv.js} +270 -270
  111. package/node_modules/@comis/web/dist/assets/agent-editor-CNM_h94Y.js +2173 -0
  112. package/node_modules/@comis/web/dist/assets/{agent-list-LHCJ4rw2.js → agent-list-Dbh-xD_F.js} +170 -170
  113. package/node_modules/@comis/web/dist/assets/{approvals-q9VH_IKr.js → approvals-C-K6hN2U.js} +13 -13
  114. package/node_modules/@comis/web/dist/assets/billing-view-C1DmtyzK.js +375 -0
  115. package/node_modules/@comis/web/dist/assets/{channel-detail-CaInesJM.js → channel-detail-CtCH22N1.js} +265 -265
  116. package/node_modules/@comis/web/dist/assets/channel-list-C7xXn-60.js +323 -0
  117. package/node_modules/@comis/web/dist/assets/{chat-console-CNmzl0JW.js → chat-console-C51pjFwk.js} +243 -246
  118. package/node_modules/@comis/web/dist/assets/{config-editor-DX4ITw6y.js → config-editor-BLArYRB7.js} +477 -477
  119. package/node_modules/@comis/web/dist/assets/{context-dag-browser-BwiaF5tf.js → context-dag-browser-fuyMinNI.js} +105 -105
  120. package/node_modules/@comis/web/dist/assets/{context-engine-BZ5Am6hA.js → context-engine-Bngf2bH0.js} +136 -136
  121. package/node_modules/@comis/web/dist/assets/decorate-BvWYovGE.js +38 -0
  122. package/node_modules/@comis/web/dist/assets/{delivery-view-OfBZof-m.js → delivery-view-C80hucxX.js} +134 -134
  123. package/node_modules/@comis/web/dist/assets/{diagnostics-view-YFwCxgr2.js → diagnostics-view-Cl4VbHZ6.js} +82 -82
  124. package/node_modules/@comis/web/dist/assets/directive-BOYXJ-K-.js +1 -0
  125. package/node_modules/@comis/web/dist/assets/{extract-variables-BM5qyK-s.js → extract-variables-B7-Doo7l.js} +39 -39
  126. package/node_modules/@comis/web/dist/assets/{ic-array-editor-B7m6x7-S.js → ic-array-editor-BLoEyeLS.js} +29 -29
  127. package/node_modules/@comis/web/dist/assets/{ic-breadcrumb-CUMpp3BL.js → ic-breadcrumb-DqN6G3gc.js} +16 -16
  128. package/node_modules/@comis/web/dist/assets/{ic-budget-segment-bar-BtJ6x5mN.js → ic-budget-segment-bar-zLsMzjDO.js} +20 -20
  129. package/node_modules/@comis/web/dist/assets/ic-chat-message-ByFUoMm6.js +352 -0
  130. package/node_modules/@comis/web/dist/assets/{ic-confirm-dialog-CCDbB04e.js → ic-confirm-dialog-DGlPbV1T.js} +26 -26
  131. package/node_modules/@comis/web/dist/assets/{ic-connection-dot-CnT1b8xr.js → ic-connection-dot-C4nDHgY2.js} +13 -13
  132. package/node_modules/@comis/web/dist/assets/ic-data-table-CKIvr-ag.js +277 -0
  133. package/node_modules/@comis/web/dist/assets/ic-delivery-row-B3YwjjuM.js +67 -0
  134. package/node_modules/@comis/web/dist/assets/{ic-detail-panel-BF83r-if.js → ic-detail-panel-DiCe4hLr.js} +27 -27
  135. package/node_modules/@comis/web/dist/assets/{ic-empty-state-60l2ePhd.js → ic-empty-state-CM3Wbj2f.js} +19 -19
  136. package/node_modules/@comis/web/dist/assets/ic-graph-canvas-ByRjij68.js +359 -0
  137. package/node_modules/@comis/web/dist/assets/ic-icon-BGNCCPpZ.js +33 -0
  138. package/node_modules/@comis/web/dist/assets/{ic-layer-waterfall-COvEYMg5.js → ic-layer-waterfall-WkaFyu-l.js} +18 -18
  139. package/node_modules/@comis/web/dist/assets/ic-relative-time-B3UAnTqg.js +12 -0
  140. package/node_modules/@comis/web/dist/assets/{ic-search-input-CSOxY9g7.js → ic-search-input-B02AGw1i.js} +22 -22
  141. package/node_modules/@comis/web/dist/assets/{ic-select-Ce-Raudx.js → ic-select-BqfZISjw.js} +29 -29
  142. package/node_modules/@comis/web/dist/assets/ic-tabs-yBjkWKJH.js +95 -0
  143. package/node_modules/@comis/web/dist/assets/ic-tag-CvMVQFRR.js +33 -0
  144. package/node_modules/@comis/web/dist/assets/{ic-time-range-picker-CypCT68y.js → ic-time-range-picker-DXbYeBmY.js} +31 -31
  145. package/node_modules/@comis/web/dist/assets/{ic-tool-call-7MaXSsCW.js → ic-tool-call-Bh5kq-yY.js} +51 -51
  146. package/node_modules/@comis/web/dist/assets/index-BBkuC-EU.js +2792 -0
  147. package/node_modules/@comis/web/dist/assets/index-CVEaS9aY.css +2 -0
  148. package/node_modules/@comis/web/dist/assets/{mcp-management-BNZPnpDn.js → mcp-management-DB-phOo7.js} +209 -209
  149. package/node_modules/@comis/web/dist/assets/{media-config-BBvTYxOX.js → media-config-CRqZ1ZUH.js} +154 -154
  150. package/node_modules/@comis/web/dist/assets/{media-test-BkK3RCRK.js → media-test-C9vE20Oy.js} +259 -259
  151. package/node_modules/@comis/web/dist/assets/{memory-inspector-1hDGCGat.js → memory-inspector-CeqfnxMZ.js} +450 -450
  152. package/node_modules/@comis/web/dist/assets/{message-center-CXefwsUu.js → message-center-Daup7Mof.js} +290 -290
  153. package/node_modules/@comis/web/dist/assets/{models-C1qcU_j3.js → models-DLYnEU8E.js} +371 -371
  154. package/node_modules/@comis/web/dist/assets/observability-types-D0tkwElU.js +1 -0
  155. package/node_modules/@comis/web/dist/assets/{observe-view-C0VBhX4C.js → observe-view-BTSt_PO5.js} +399 -399
  156. package/node_modules/@comis/web/dist/assets/pipeline-builder-DknfzyLt.js +1495 -0
  157. package/node_modules/@comis/web/dist/assets/{pipeline-history-DkfOQ6SW.js → pipeline-history-JnHZdeU_.js} +124 -124
  158. package/node_modules/@comis/web/dist/assets/{pipeline-history-detail-hyHgD0ai.js → pipeline-history-detail-Dg4knsEb.js} +65 -65
  159. package/node_modules/@comis/web/dist/assets/{pipeline-list-BPW8hV-q.js → pipeline-list-AEnibjsp.js} +227 -227
  160. package/node_modules/@comis/web/dist/assets/{pipeline-monitor-Bip16T7e.js → pipeline-monitor-DG7RbIOO.js} +298 -298
  161. package/node_modules/@comis/web/dist/assets/{scheduler-BGgwKd06.js → scheduler-uL1fYKAT.js} +486 -486
  162. package/node_modules/@comis/web/dist/assets/{security-D15st4xx.js → security-C3DywRLH.js} +389 -389
  163. package/node_modules/@comis/web/dist/assets/{session-detail-SGEYNJ0M.js → session-detail-BtqCNWXV.js} +294 -294
  164. package/node_modules/@comis/web/dist/assets/session-key-parser-Dkqcj2Ss.js +1 -0
  165. package/node_modules/@comis/web/dist/assets/session-list-CJXWa2XT.js +231 -0
  166. package/node_modules/@comis/web/dist/assets/{setup-wizard-nT0tz9QP.js → setup-wizard-ywn7oJvu.js} +486 -494
  167. package/node_modules/@comis/web/dist/assets/{skills-D8yVfSUy.js → skills-DX0KYnWD.js} +329 -329
  168. package/node_modules/@comis/web/dist/assets/{subagents-HHXMeHYo.js → subagents-B8p5YJEB.js} +74 -74
  169. package/node_modules/@comis/web/dist/assets/{workspace-manager-BQlr10iH.js → workspace-manager-CgzNIrw1.js} +236 -236
  170. package/node_modules/@comis/web/dist/index.html +3 -2
  171. package/node_modules/@comis/web/package.json +1 -1
  172. package/package.json +15 -15
  173. package/node_modules/@comis/skills/dist/builtin/platform/agents-list-tool.d.ts +0 -19
  174. package/node_modules/@comis/skills/dist/builtin/platform/agents-list-tool.js +0 -39
  175. package/node_modules/@comis/web/dist/assets/agent-editor-C26Q_xCs.js +0 -2173
  176. package/node_modules/@comis/web/dist/assets/billing-view-CtYvBqTE.js +0 -375
  177. package/node_modules/@comis/web/dist/assets/channel-list-B8dj3O9a.js +0 -323
  178. package/node_modules/@comis/web/dist/assets/directive-DoeGSK_T.js +0 -1
  179. package/node_modules/@comis/web/dist/assets/ic-chat-message-CFyDJd0z.js +0 -352
  180. package/node_modules/@comis/web/dist/assets/ic-data-table-CKUNTxHw.js +0 -277
  181. package/node_modules/@comis/web/dist/assets/ic-delivery-row-GP5Fkygs.js +0 -67
  182. package/node_modules/@comis/web/dist/assets/ic-graph-canvas-C8FuSMe1.js +0 -359
  183. package/node_modules/@comis/web/dist/assets/ic-icon-xeGTVhVG.js +0 -33
  184. package/node_modules/@comis/web/dist/assets/ic-relative-time-3FqpjeAI.js +0 -12
  185. package/node_modules/@comis/web/dist/assets/ic-tabs-B7QtM_v8.js +0 -95
  186. package/node_modules/@comis/web/dist/assets/ic-tag-CPPUnDLF.js +0 -33
  187. package/node_modules/@comis/web/dist/assets/index-CEcM1R_C.js +0 -2830
  188. package/node_modules/@comis/web/dist/assets/index-CIJFuItj.css +0 -1
  189. package/node_modules/@comis/web/dist/assets/observability-types-D7jUtSde.js +0 -1
  190. package/node_modules/@comis/web/dist/assets/pipeline-builder-DcUUIrm0.js +0 -1496
  191. package/node_modules/@comis/web/dist/assets/session-key-parser-DPORMVyU.js +0 -1
  192. package/node_modules/@comis/web/dist/assets/session-list-6ybUTxbY.js +0 -231
@@ -0,0 +1,210 @@
1
+ /**
2
+ * Thinking-block hash invariant -- diagnostic instrumentation only.
3
+ *
4
+ * Observed problem: Anthropic 400 `messages.N.content.M: thinking/redacted_thinking
5
+ * blocks cannot be modified` errors keep firing in production even after the
6
+ * surrogate-guard, drift-scrubber, and signed-replay-detector layers shipped
7
+ * (260425-rvm), and even after the immutable-section redirect (260425-t40).
8
+ * Trace `c7b91328-9dc5-4618-9ae8-ca207b4b93df` on 2026-04-28 hit a 400 ~2.2s
9
+ * after `turn_end` -- meaning *some other layer* mutates a signed thinking
10
+ * block between the assistant turn and the next replay. We don't know which.
11
+ *
12
+ * This module is the diagnostic. At each `turn_end` with signed thinking
13
+ * blocks, the bridge captures a SHA-256 hash of every thinking block. Before
14
+ * the next assistant-message resend, the bridge recomputes the hashes and
15
+ * asserts they match the captured snapshots. On mismatch, ONE structured
16
+ * ERROR log fires per mutated index with enough context to pinpoint the
17
+ * offending layer (responseId, blockIndex, old/new hash, first-32-chars of
18
+ * old/new text, signature length before/after).
19
+ *
20
+ * Behavior contract (enforced by tests + source-shape grep):
21
+ * - NEVER throws. Every code path returns normally; logger errors are
22
+ * swallowed because we don't want the diagnostic itself to abort agent flow.
23
+ * - NEVER mutates inputs. Pure read; only output is the structured log.
24
+ * - NEVER alters request flow. The mismatch is observable signal only --
25
+ * Anthropic's 400 still surfaces through the existing error path
26
+ * (signed-replay-detector -> executor-prompt-runner). Bug A behavior fix
27
+ * is a separate quick task gated on what this diagnostic reveals.
28
+ *
29
+ * Logging surface follows CLAUDE.md canonical Pino fields:
30
+ * - object-first signature: `error({...fields}, "msg")`
31
+ * - `module: "agent.bridge.hash-invariant"`
32
+ * - `errorKind: "internal"` (classification per AGENTS.md §2.1)
33
+ * - `hint`: actionable next step for the on-call diagnoser
34
+ * - `responseId`, `blockIndex`, `oldHash`, `newHash`,
35
+ * `oldText.firstChars`, `newText.firstChars`, `oldSigLen`, `newSigLen`
36
+ *
37
+ * Privacy / threat note: `oldText.firstChars` and `newText.firstChars` are
38
+ * 32-char prefixes of `block.thinking`. Anthropic redacts thinking text
39
+ * upstream when it would leak credentials, and Comis layers (surrogate guard,
40
+ * drift scrubber) further sanitize before any persistence. The hash itself is
41
+ * one-way and non-credential-bearing. Pino's redaction config is a safety net.
42
+ *
43
+ * @module
44
+ */
45
+ /** A captured snapshot of one thinking block's hash + diagnostic prefix. */
46
+ export interface ThinkingBlockHash {
47
+ /** Position within the thinking-only stream (skips text/tool/redacted blocks). */
48
+ blockIndex: number;
49
+ /** SHA-256 hex digest of `(type | thinking | thinkingSignature | redacted)`. */
50
+ hash: string;
51
+ /** First 32 chars of `thinking` -- diagnostic on mismatch only. */
52
+ textFirstChars: string;
53
+ /** Length of `thinkingSignature` -- diagnostic, never the value. */
54
+ sigLen: number;
55
+ }
56
+ /** Logger surface required by `assertThinkingBlocksUnchanged`. */
57
+ export interface AssertDeps {
58
+ logger: {
59
+ error: (obj: Record<string, unknown>, msg: string) => void;
60
+ };
61
+ }
62
+ /** Result shape returned by `assertThinkingBlocksUnchanged`. Counters surface
63
+ * what the helper observed on this call so callers can emit telemetry without
64
+ * re-walking the inputs. Fields are computed even when the helper is a no-op
65
+ * (empty prior). */
66
+ export interface AssertResult {
67
+ /** Number of `prior` entries we walked (equals `prior.length` when prior is
68
+ * an array; 0 when prior was empty/non-array). */
69
+ candidatesChecked: number;
70
+ /** Number of structured ERROR logs emitted on this call (1 per missing
71
+ * index + 1 per hash-mismatch index). */
72
+ mismatchesLogged: number;
73
+ /** True iff at least one prior `blockIndex` had a corresponding entry in
74
+ * `current`, regardless of whether the hashes matched. False when current
75
+ * was empty/non-array OR every prior index was missing. */
76
+ anyResponseIdMatched: boolean;
77
+ }
78
+ /**
79
+ * Compute SHA-256 hashes for every `type:"thinking"` block in `content`.
80
+ *
81
+ * Mirrors signature-surrogate-guard's exclusion rule: skips non-thinking
82
+ * blocks AND skips blocks where `redacted === true` (no readable text). The
83
+ * resulting `blockIndex` field counts position WITHIN the thinking-only
84
+ * stream, so callers can compare positionally even when the surrounding mix
85
+ * of text/tool blocks varies between turns.
86
+ *
87
+ * Pure: never mutates input, never throws. Returns an empty array when
88
+ * `content` is empty or contains no thinking blocks.
89
+ */
90
+ export declare function computeThinkingBlockHashes(content: ReadonlyArray<Record<string, unknown>> | undefined | null): ThinkingBlockHash[];
91
+ /**
92
+ * Compare prior captured hashes against the current shape of `content`.
93
+ *
94
+ * Logs ONE structured ERROR per mismatched index. When `prior` is empty,
95
+ * this is a no-op (no hashes were captured for this responseId, so there's
96
+ * nothing to verify). When `current` has fewer thinking blocks than `prior`,
97
+ * each missing index is reported with `newHash:null`, `newText.firstChars:""`,
98
+ * `newSigLen:0`.
99
+ *
100
+ * Never throws. Never mutates `prior` or `current`.
101
+ */
102
+ export declare function assertThinkingBlocksUnchanged(prior: ReadonlyArray<ThinkingBlockHash>, current: ReadonlyArray<Record<string, unknown>> | undefined | null, responseId: string | undefined, deps: AssertDeps): AssertResult;
103
+ /** Logger surface required by `restoreCanonicalThinkingBlocks`. Both methods
104
+ * optional; the helper is a silent no-op when omitted. */
105
+ export interface RestoreDeps {
106
+ logger?: {
107
+ info: (obj: Record<string, unknown>, msg: string) => void;
108
+ warn: (obj: Record<string, unknown>, msg: string) => void;
109
+ };
110
+ }
111
+ /** Result shape returned by `restoreCanonicalThinkingBlocks`. */
112
+ export interface RestoreResult {
113
+ /** SAME reference as input when no swap happened, otherwise a new top-level array. */
114
+ messages: unknown[];
115
+ /** Total number of thinking blocks replaced across all messages. */
116
+ restoredCount: number;
117
+ /** Distinct responseIds that had at least one swap, in walk order. */
118
+ affectedResponseIds: string[];
119
+ }
120
+ /**
121
+ * Replace mutated thinking blocks with their canonical snapshot, in-memory only.
122
+ *
123
+ * Pure: never mutates input arrays or block objects. Idempotent: when canonical
124
+ * matches in-memory exactly, returns `{ messages: <same ref>, restoredCount: 0,
125
+ * affectedResponseIds: [] }`. On at least one swap, returns a NEW top-level
126
+ * array AND a NEW content array on each affected message.
127
+ *
128
+ * Replaces ONLY blocks where BOTH `current[i].type === "thinking"` AND
129
+ * `canonical[i].type === "thinking"` AND `current[i].redacted !== true` AND
130
+ * `canonical[i].redacted !== true`. Text blocks, tool_use, tool_result,
131
+ * redacted_thinking, and any block where positional types disagree are passed
132
+ * through unchanged.
133
+ *
134
+ * Skips messages where `role !== "assistant"`, where `responseId` is not a
135
+ * string, or where the canonical store has no entry for that responseId.
136
+ *
137
+ * Never throws. On any unexpected error during the walk (e.g. malformed
138
+ * canonical entry whose getter throws), the entire result is `{ messages:
139
+ * <input ref>, restoredCount: 0, affectedResponseIds: [] }` and ONE WARN log
140
+ * fires with `module: RESTORE_MODULE_FIELD, errorKind: "internal"`.
141
+ */
142
+ export declare function restoreCanonicalThinkingBlocks(messages: ReadonlyArray<unknown> | undefined | null, canonicalStore: ReadonlyMap<string, ReadonlyArray<unknown>>, deps?: RestoreDeps): RestoreResult;
143
+ export declare const WIRE_DIFF_HINT_FILE_MISSING: string;
144
+ export declare const WIRE_DIFF_HINT_NOT_FOUND: string;
145
+ export declare const WIRE_DIFF_HINT_INTERNAL: string;
146
+ /** A single divergent block found by `diffThinkingBlocksAgainstPersisted`. */
147
+ export interface PersistedDiffEntry {
148
+ /** Position within the thinking-only stream (matches computeThinkingBlockHashes blockIndex). */
149
+ blockIndex: number;
150
+ /** SHA-256 hash of the persisted (canonical) block. */
151
+ persistedHash: string;
152
+ /** SHA-256 hash of the in-memory block, or null when the block is missing entirely. */
153
+ inMemoryHash: string | null;
154
+ /** First 32 chars of persisted thinking text. */
155
+ persistedText: {
156
+ firstChars: string;
157
+ };
158
+ /** First 32 chars of in-memory thinking text; empty string when block missing. */
159
+ inMemoryText: {
160
+ firstChars: string;
161
+ };
162
+ /** Length of the persisted thinkingSignature. */
163
+ persistedSigLen: number;
164
+ /** Length of the in-memory thinkingSignature; 0 when block missing. */
165
+ inMemorySigLen: number;
166
+ }
167
+ /** Logger + readFile dependency injection for `diffThinkingBlocksAgainstPersisted`.
168
+ *
169
+ * Both fields optional. When `readFile` is omitted, the module-level
170
+ * `node:fs/promises` readFile is used. When `logger` is omitted, the helper
171
+ * silently skips all log calls (used by tests + by silent-failure paths). */
172
+ export interface DiffDeps {
173
+ logger?: {
174
+ warn: (obj: Record<string, unknown>, msg: string) => void;
175
+ error?: (obj: Record<string, unknown>, msg: string) => void;
176
+ };
177
+ /** Inject for test isolation. Returns the JSONL file contents as a UTF-8 string. */
178
+ readFile?: (path: string, encoding: "utf-8") => Promise<string>;
179
+ }
180
+ /**
181
+ * Diff in-memory thinking blocks against the persisted JSONL canonical.
182
+ *
183
+ * Reads the persisted JSONL session file, locates the FIRST assistant message
184
+ * matching `responseId`, and compares its content (canonical, written from
185
+ * Anthropic's stream at receipt time) against `inMemoryContent` using the
186
+ * existing `computeThinkingBlockHashes` primitive.
187
+ *
188
+ * Returns an array of `PersistedDiffEntry` -- one per divergent thinking
189
+ * block. When everything matches positionally, returns `[]`. When in-memory
190
+ * has fewer thinking blocks than persisted, each missing index produces an
191
+ * entry with `inMemoryHash: null`, empty `inMemoryText.firstChars`, and
192
+ * `inMemorySigLen: 0`.
193
+ *
194
+ * Behavior contract:
195
+ * - NEVER throws. Read errors, parse errors, or responseId-not-found degrade
196
+ * to ONE WARN log + `[]`.
197
+ * - When TWO assistant messages share the same responseId in the JSONL,
198
+ * uses the FIRST match (matches the bridge's "trust the first persisted
199
+ * state" semantic).
200
+ * - Malformed lines (invalid JSON) are skipped silently; scanning continues.
201
+ *
202
+ * @param inMemoryContent - The in-memory content array of the assistant
203
+ * message (the same shape pi-ai is about to serialize).
204
+ * @param responseId - The responseId of the assistant message to look up.
205
+ * @param jsonlPath - Resolved absolute path to the JSONL session file. Path
206
+ * composition is the caller's responsibility (this helper does no
207
+ * safePath / sessionKey routing).
208
+ * @param deps - Optional logger + readFile injection.
209
+ */
210
+ export declare function diffThinkingBlocksAgainstPersisted(inMemoryContent: ReadonlyArray<Record<string, unknown>> | undefined | null, responseId: string, jsonlPath: string, deps?: DiffDeps): Promise<PersistedDiffEntry[]>;