maka-agent 0.2.0-dev.30.20260912 → 0.2.0-dev.32.20260914

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 (245) hide show
  1. package/THIRD_PARTY_NOTICES.txt +392 -0
  2. package/dist/acp/maka-acp-agent.js +8 -2
  3. package/dist/acp/prompt-content.js +225 -0
  4. package/dist/acp/session-event-mapper.js +103 -0
  5. package/dist/acp/session-registry.js +654 -17
  6. package/dist/acp/stdio-server.js +10 -1
  7. package/dist/cli-core.js +1 -1
  8. package/dist/pi-transcript-tools.js +3 -2
  9. package/dist/pi-transcript.js +15 -6
  10. package/dist/runtime-host-session-channel.js +63 -9
  11. package/native/runtime-host-windows-task-launcher/prebuilds/win32-x64/maka-runtime-host-task-launcher.exe +0 -0
  12. package/node_modules/@maka/core/dist/agent-graph-schedule.js +15 -4
  13. package/node_modules/@maka/core/dist/artifacts.js +6 -0
  14. package/node_modules/@maka/core/dist/attachments.js +7 -2
  15. package/node_modules/@maka/core/dist/durable-tool-result-projection.js +3 -1
  16. package/node_modules/@maka/core/dist/events.js +21 -0
  17. package/node_modules/@maka/core/dist/executor-id.js +22 -0
  18. package/node_modules/@maka/core/dist/external-session.js +18 -0
  19. package/node_modules/@maka/core/dist/goal.js +44 -2
  20. package/node_modules/@maka/core/dist/model-call-usage-projection.js +0 -13
  21. package/node_modules/@maka/core/dist/permission.js +0 -1
  22. package/node_modules/@maka/core/dist/runtime-boundary.js +73 -29
  23. package/node_modules/@maka/core/dist/runtime-event.js +25 -6
  24. package/node_modules/@maka/core/dist/runtime-handoff.js +10 -2
  25. package/node_modules/@maka/core/dist/runtime-logical-execution.js +39 -14
  26. package/node_modules/@maka/core/dist/session-send-projection.js +6 -3
  27. package/node_modules/@maka/core/dist/session.js +8 -2
  28. package/node_modules/@maka/core/dist/shell-run-result.js +1 -0
  29. package/node_modules/@maka/core/dist/shell-run.js +4 -0
  30. package/node_modules/@maka/core/dist/tool-result-archive-evidence.js +3 -1
  31. package/node_modules/@maka/core/dist/tool-result-record-schema.js +2 -1
  32. package/node_modules/@maka/core/dist/unified-diff.js +33 -26
  33. package/node_modules/@maka/core/dist/work-board.js +94 -1
  34. package/node_modules/@maka/core/package.json +1 -0
  35. package/node_modules/@maka/eval/dist/fleet-simulation.js +270 -0
  36. package/node_modules/@maka/eval/dist/fleet-store.js +243 -0
  37. package/node_modules/@maka/eval/dist/fleet-worker.js +125 -0
  38. package/node_modules/@maka/eval/dist/fleet.js +329 -0
  39. package/node_modules/@maka/eval/dist/index.js +3 -0
  40. package/node_modules/@maka/runtime/dist/agent-run.js +2 -17
  41. package/node_modules/@maka/runtime/dist/ai-sdk-compaction.js +55 -180
  42. package/node_modules/@maka/runtime/dist/ai-sdk-message-projection.js +43 -26
  43. package/node_modules/@maka/runtime/dist/ai-sdk-turn.js +271 -382
  44. package/node_modules/@maka/runtime/dist/background-task-health-tool.js +104 -0
  45. package/node_modules/@maka/runtime/dist/bash-model-output.js +7 -1
  46. package/node_modules/@maka/runtime/dist/bash-tail-buffer.js +13 -52
  47. package/node_modules/@maka/runtime/dist/builtin-tools.js +59 -111
  48. package/node_modules/@maka/runtime/dist/child-fd-input.js +3 -2
  49. package/node_modules/@maka/runtime/dist/context-budget-policy.js +1 -11
  50. package/node_modules/@maka/runtime/dist/context-budget.js +12 -1
  51. package/node_modules/@maka/runtime/dist/conversation-copy.js +104 -9
  52. package/node_modules/@maka/runtime/dist/filesystem-executor.js +10 -6
  53. package/node_modules/@maka/runtime/dist/filesystem-worker/client.js +77 -19
  54. package/node_modules/@maka/runtime/dist/filesystem-worker/launch-spec.js +66 -55
  55. package/node_modules/@maka/runtime/dist/filesystem-worker/operations.js +34 -97
  56. package/node_modules/@maka/runtime/dist/filesystem-worker/protocol.js +25 -10
  57. package/node_modules/@maka/runtime/dist/filesystem-worker/worker-entry.js +2 -0
  58. package/node_modules/@maka/runtime/dist/glob-search.js +74 -0
  59. package/node_modules/@maka/runtime/dist/goal-continuation.js +78 -8
  60. package/node_modules/@maka/runtime/dist/goal-state.js +7 -0
  61. package/node_modules/@maka/runtime/dist/grep-search.js +155 -0
  62. package/node_modules/@maka/runtime/dist/history-compaction.js +3 -1
  63. package/node_modules/@maka/runtime/dist/ledger-tool-result-archive-reader.js +84 -94
  64. package/node_modules/@maka/runtime/dist/local-web-fetch.js +1 -1
  65. package/node_modules/@maka/runtime/dist/model-adapter.js +62 -53
  66. package/node_modules/@maka/runtime/dist/model-history.js +26 -8
  67. package/node_modules/@maka/runtime/dist/pipe-tail-collector.js +6 -9
  68. package/node_modules/@maka/runtime/dist/plugin-executor-backend.js +311 -0
  69. package/node_modules/@maka/runtime/dist/plugin-executor-service.js +344 -0
  70. package/node_modules/@maka/runtime/dist/provider-error-classification.js +7 -1
  71. package/node_modules/@maka/runtime/dist/provider-request-telemetry.js +35 -8
  72. package/node_modules/@maka/runtime/dist/read-page.js +231 -0
  73. package/node_modules/@maka/runtime/dist/request-projection.js +2 -15
  74. package/node_modules/@maka/runtime/dist/ripgrep-executable.js +62 -0
  75. package/node_modules/@maka/runtime/dist/ripgrep-guidance.js +81 -0
  76. package/node_modules/@maka/runtime/dist/runtime-event-backfill.js +7 -1
  77. package/node_modules/@maka/runtime/dist/runtime-event-read-model.js +188 -20
  78. package/node_modules/@maka/runtime/dist/runtime-invocation-route.js +49 -0
  79. package/node_modules/@maka/runtime/dist/runtime-kernel.js +72 -150
  80. package/node_modules/@maka/runtime/dist/runtime-read-model.js +2 -3
  81. package/node_modules/@maka/runtime/dist/sandbox/linux-profile-path.js +7 -1
  82. package/node_modules/@maka/runtime/dist/sandbox/linux-sandbox.js +20 -5
  83. package/node_modules/@maka/runtime/dist/session-event-runtime-mapper.js +3 -0
  84. package/node_modules/@maka/runtime/dist/session-manager.js +106 -64
  85. package/node_modules/@maka/runtime/dist/session-recap.js +9 -5
  86. package/node_modules/@maka/runtime/dist/shell-exec.js +7 -25
  87. package/node_modules/@maka/runtime/dist/shell-run-manager.js +10 -4
  88. package/node_modules/@maka/runtime/dist/shell-run-tool-result.js +2 -1
  89. package/node_modules/@maka/runtime/dist/shell-tools.js +6 -12
  90. package/node_modules/@maka/runtime/dist/stream-graph-schedule-reconcile.js +1 -0
  91. package/node_modules/@maka/runtime/dist/stream-graph-supervisor-tools.js +26 -4
  92. package/node_modules/@maka/runtime/dist/subagent-tools.js +7 -0
  93. package/node_modules/@maka/runtime/dist/tool-availability.js +0 -1
  94. package/node_modules/@maka/runtime/dist/tool-output.js +1 -1
  95. package/node_modules/@maka/runtime/dist/tool-result-archive-capability.js +24 -36
  96. package/node_modules/@maka/runtime/dist/tool-result-archive-resource.js +32 -527
  97. package/node_modules/@maka/runtime/dist/tool-result-archive-transition.js +17 -119
  98. package/node_modules/@maka/runtime/dist/tool-result-archive.js +7 -25
  99. package/node_modules/@maka/runtime/dist/tool-runtime.js +52 -471
  100. package/node_modules/@maka/runtime/dist/workers/filesystem-worker.js +6933 -3681
  101. package/node_modules/@maka/runtime/dist/workspace-executor.js +20 -24
  102. package/node_modules/@maka/runtime/package.json +5 -0
  103. package/node_modules/@maka/runtime-host/dist/adapter/session-projector.js +7 -2
  104. package/node_modules/@maka/runtime-host/dist/client/host-handoff-copy.js +185 -191
  105. package/node_modules/@maka/runtime-host/dist/client/reconnecting-connection.js +3 -0
  106. package/node_modules/@maka/runtime-host/dist/client/session-catalog-summary.js +1 -0
  107. package/node_modules/@maka/runtime-host/dist/protocol/external-session.js +24 -3
  108. package/node_modules/@maka/runtime-host/dist/protocol/index.js +8 -1
  109. package/node_modules/@maka/runtime-host/dist/protocol/message.js +2 -2
  110. package/node_modules/@maka/runtime-host/dist/protocol/operations.js +1 -0
  111. package/node_modules/@maka/runtime-host/dist/protocol/plugin-platform.js +42 -5
  112. package/node_modules/@maka/runtime-host/dist/protocol/session-catalog.js +31 -3
  113. package/node_modules/@maka/runtime-host/dist/protocol/session-continuity.js +8 -2
  114. package/node_modules/@maka/runtime-host/dist/protocol/turn.js +10 -2
  115. package/node_modules/@maka/runtime-host/dist/protocol/workhub-coordination.js +38 -0
  116. package/node_modules/@maka/runtime-host/dist/server/child-agent-composition.js +1 -0
  117. package/node_modules/@maka/runtime-host/dist/server/execution-artifacts.js +3 -30
  118. package/node_modules/@maka/runtime-host/dist/server/execution-composition.js +56 -8
  119. package/node_modules/@maka/runtime-host/dist/server/external-session-coordinator.js +14 -1
  120. package/node_modules/@maka/runtime-host/dist/server/goal-coordinator.js +81 -7
  121. package/node_modules/@maka/runtime-host/dist/server/host-session-availability.js +10 -2
  122. package/node_modules/@maka/runtime-host/dist/server/hosted-execution-tool-profile.js +13 -13
  123. package/node_modules/@maka/runtime-host/dist/server/interaction-coordinator.js +65 -0
  124. package/node_modules/@maka/runtime-host/dist/server/plugin-platform-coordinator.js +6 -0
  125. package/node_modules/@maka/runtime-host/dist/server/plugin-platform.js +6 -0
  126. package/node_modules/@maka/runtime-host/dist/server/root-turn-coordinator.js +1 -0
  127. package/node_modules/@maka/runtime-host/dist/server/session-catalog-coordinator.js +56 -16
  128. package/node_modules/@maka/runtime-host/dist/server/session-continuity-coordinator.js +9 -5
  129. package/node_modules/@maka/runtime-host/dist/server/session-revision-coordinator.js +4 -0
  130. package/node_modules/@maka/runtime-host/dist/server/session-transcript-reader.js +88 -72
  131. package/node_modules/@maka/runtime-host/dist/server/web-fetch-tool.js +37 -1
  132. package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-action-gate.js +21 -4
  133. package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-coordinator.js +145 -1
  134. package/node_modules/@maka/storage/dist/agent-run-store.js +5 -2
  135. package/node_modules/@maka/storage/dist/claude-code-session-adapter.js +450 -234
  136. package/node_modules/@maka/storage/dist/claude-code-transcript-lineage.js +106 -77
  137. package/node_modules/@maka/storage/dist/execution-stores.js +2 -1
  138. package/node_modules/@maka/storage/dist/legacy-run-header.js +2 -2
  139. package/node_modules/@maka/storage/dist/model-call-usage-sql.js +1 -1
  140. package/node_modules/@maka/storage/dist/runtime-transcript-query.js +27 -14
  141. package/node_modules/@maka/storage/dist/session-store.js +12 -2
  142. package/node_modules/@maka/storage/dist/sqlite-long-term-memory-store.js +86 -12
  143. package/node_modules/@maka/storage/dist/sqlite-runtime-store.js +69 -3
  144. package/node_modules/@maka/storage/dist/work-board-store.js +40 -1
  145. package/node_modules/balanced-match/LICENSE.md +23 -0
  146. package/node_modules/balanced-match/README.md +57 -0
  147. package/node_modules/balanced-match/dist/commonjs/index.js +59 -0
  148. package/node_modules/balanced-match/dist/commonjs/package.json +3 -0
  149. package/node_modules/balanced-match/dist/esm/index.js +54 -0
  150. package/node_modules/balanced-match/dist/esm/package.json +3 -0
  151. package/node_modules/balanced-match/package.json +68 -0
  152. package/node_modules/brace-expansion/LICENSE +23 -0
  153. package/node_modules/brace-expansion/README.md +105 -0
  154. package/node_modules/brace-expansion/dist/commonjs/index.js +289 -0
  155. package/node_modules/brace-expansion/dist/commonjs/package.json +3 -0
  156. package/node_modules/brace-expansion/dist/esm/index.js +285 -0
  157. package/node_modules/brace-expansion/dist/esm/package.json +3 -0
  158. package/node_modules/brace-expansion/package.json +64 -0
  159. package/node_modules/glob/LICENSE.md +63 -0
  160. package/node_modules/glob/README.md +1203 -0
  161. package/node_modules/glob/dist/commonjs/glob.js +248 -0
  162. package/node_modules/glob/dist/commonjs/has-magic.js +27 -0
  163. package/node_modules/glob/dist/commonjs/ignore.js +119 -0
  164. package/node_modules/glob/dist/commonjs/index.js +68 -0
  165. package/node_modules/glob/dist/commonjs/index.min.js +4 -0
  166. package/node_modules/glob/dist/commonjs/package.json +3 -0
  167. package/node_modules/glob/dist/commonjs/pattern.js +223 -0
  168. package/node_modules/glob/dist/commonjs/processor.js +301 -0
  169. package/node_modules/glob/dist/commonjs/walker.js +387 -0
  170. package/node_modules/glob/dist/esm/glob.js +244 -0
  171. package/node_modules/glob/dist/esm/has-magic.js +23 -0
  172. package/node_modules/glob/dist/esm/ignore.js +115 -0
  173. package/node_modules/glob/dist/esm/index.js +55 -0
  174. package/node_modules/glob/dist/esm/index.min.js +4 -0
  175. package/node_modules/glob/dist/esm/package.json +3 -0
  176. package/node_modules/glob/dist/esm/pattern.js +219 -0
  177. package/node_modules/glob/dist/esm/processor.js +294 -0
  178. package/node_modules/glob/dist/esm/walker.js +381 -0
  179. package/node_modules/glob/package.json +98 -0
  180. package/node_modules/minimatch/LICENSE.md +55 -0
  181. package/node_modules/minimatch/README.md +528 -0
  182. package/node_modules/minimatch/dist/commonjs/assert-valid-pattern.js +14 -0
  183. package/node_modules/minimatch/dist/commonjs/ast.js +845 -0
  184. package/node_modules/minimatch/dist/commonjs/brace-expressions.js +150 -0
  185. package/node_modules/minimatch/dist/commonjs/escape.js +30 -0
  186. package/node_modules/minimatch/dist/commonjs/index.js +1127 -0
  187. package/node_modules/minimatch/dist/commonjs/package.json +3 -0
  188. package/node_modules/minimatch/dist/commonjs/unescape.js +38 -0
  189. package/node_modules/minimatch/dist/esm/assert-valid-pattern.js +10 -0
  190. package/node_modules/minimatch/dist/esm/ast.js +841 -0
  191. package/node_modules/minimatch/dist/esm/brace-expressions.js +146 -0
  192. package/node_modules/minimatch/dist/esm/escape.js +26 -0
  193. package/node_modules/minimatch/dist/esm/index.js +1114 -0
  194. package/node_modules/minimatch/dist/esm/package.json +3 -0
  195. package/node_modules/minimatch/dist/esm/unescape.js +34 -0
  196. package/node_modules/minimatch/package.json +73 -0
  197. package/node_modules/minipass/LICENSE.md +55 -0
  198. package/node_modules/minipass/README.md +825 -0
  199. package/node_modules/minipass/dist/commonjs/index.js +1038 -0
  200. package/node_modules/minipass/dist/commonjs/package.json +3 -0
  201. package/node_modules/minipass/dist/esm/index.js +1020 -0
  202. package/node_modules/minipass/dist/esm/package.json +3 -0
  203. package/node_modules/minipass/package.json +77 -0
  204. package/node_modules/path-scurry/LICENSE.md +55 -0
  205. package/node_modules/path-scurry/README.md +636 -0
  206. package/node_modules/path-scurry/dist/commonjs/index.js +2018 -0
  207. package/node_modules/path-scurry/dist/commonjs/package.json +3 -0
  208. package/node_modules/path-scurry/dist/esm/index.js +1983 -0
  209. package/node_modules/path-scurry/dist/esm/package.json +3 -0
  210. package/node_modules/path-scurry/node_modules/lru-cache/LICENSE.md +55 -0
  211. package/node_modules/path-scurry/node_modules/lru-cache/README.md +469 -0
  212. package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/browser/diagnostics-channel.js +7 -0
  213. package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/browser/index.js +1726 -0
  214. package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/browser/index.min.js +2 -0
  215. package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/browser/perf.js +10 -0
  216. package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/diagnostics-channel-cjs.d.cts.map +1 -0
  217. package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/diagnostics-channel.js +7 -0
  218. package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/index.js +1726 -0
  219. package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/index.min.js +2 -0
  220. package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/node/diagnostics-channel.js +9 -0
  221. package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/node/index.js +1726 -0
  222. package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/node/index.min.js +2 -0
  223. package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/node/perf.js +10 -0
  224. package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/package.json +3 -0
  225. package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/perf.js +10 -0
  226. package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/browser/diagnostics-channel.js +4 -0
  227. package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/browser/index.js +1722 -0
  228. package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/browser/index.min.js +2 -0
  229. package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/browser/perf.js +7 -0
  230. package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/diagnostics-channel-esm.d.mts.map +1 -0
  231. package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/diagnostics-channel.js +19 -0
  232. package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/index.js +1722 -0
  233. package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/index.min.js +2 -0
  234. package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/node/diagnostics-channel.js +6 -0
  235. package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/node/index.js +1722 -0
  236. package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/node/index.min.js +2 -0
  237. package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/node/perf.js +7 -0
  238. package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/package.json +3 -0
  239. package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/perf.js +7 -0
  240. package/node_modules/path-scurry/node_modules/lru-cache/package.json +154 -0
  241. package/node_modules/path-scurry/package.json +72 -0
  242. package/package.json +1 -1
  243. package/node_modules/@maka/runtime/dist/active-tool-result-prune.js +0 -248
  244. package/node_modules/@maka/runtime/dist/active-tool-result-working-set.js +0 -218
  245. package/node_modules/@maka/runtime/dist/archive-read-tool.js +0 -115
@@ -23,108 +23,98 @@ import { decodeLedgerTransition, reduceEffectiveModelProjections, } from './mode
23
23
  import { isArchivedToolResultPlaceholder, } from './tool-result-archive.js';
24
24
  import { serializeToolResultProjectionV1 } from './tool-result-archive-encoding.js';
25
25
  import { TOOL_RESULT_ARCHIVE_EVIDENCE_MAX_BYTES, TOOL_RESULT_ARCHIVE_EVIDENCE_MAX_TRANSITIONS, } from '@maka/core/tool-result-archive-evidence';
26
- /**
27
- * Read-only v1 reconstruction. It never calls a live tool projector, reads an
28
- * Artifact, changes history, or authorizes access from a hash alone.
29
- * The evidence port is trusted to return the complete bounded target history.
30
- */
31
- export function createLedgerToolResultArchiveReader(evidence) {
32
- return async (input) => {
33
- const request = { ...input };
34
- if (!isArchivedToolResultPlaceholder(request) ||
35
- !/^[a-f0-9]{64}$/.test(request.bodySha256) ||
36
- !Number.isSafeInteger(request.originalBytes) ||
37
- request.originalBytes < 1) {
38
- return { ok: false, reason: 'corrupt' };
26
+ async function readLedgerArchive(evidence, request) {
27
+ const identity = 'bodySha256' in request ? request : undefined;
28
+ if (identity &&
29
+ (!/^[a-f0-9]{64}$/.test(identity.bodySha256) ||
30
+ !Number.isSafeInteger(identity.originalBytes) ||
31
+ identity.originalBytes < 1))
32
+ return { ok: false, reason: 'corrupt' };
33
+ if (!Number.isSafeInteger(request.maxBytes) ||
34
+ (identity && request.maxBytes < identity.originalBytes))
35
+ return { ok: false, reason: 'too_large' };
36
+ try {
37
+ const loaded = await evidence.read({
38
+ sessionId: request.sessionId,
39
+ runtimeEventId: request.runtimeEventId,
40
+ });
41
+ if (!loaded.ok)
42
+ return {
43
+ ok: false,
44
+ reason: loaded.reason === 'unavailable' ? 'read_failed' : loaded.reason,
45
+ };
46
+ const { event } = loaded;
47
+ const content = event.content;
48
+ if (event.sessionId !== request.sessionId)
49
+ return { ok: false, reason: 'session_mismatch' };
50
+ if (event.id !== request.runtimeEventId ||
51
+ content?.kind !== 'function_response' ||
52
+ (identity && (content.id !== identity.toolCallId || content.name !== identity.toolName)) ||
53
+ content.providerExecuted ||
54
+ !content.modelProjection)
55
+ return { ok: false, reason: 'source_mismatch' };
56
+ let source = decodeDurableToolResultProjection(content.modelProjection);
57
+ const byId = new Map();
58
+ for (const record of loaded.transitions) {
59
+ const transition = decodeLedgerTransition(record, request.sessionId);
60
+ if (!transition ||
61
+ record.sessionId !== request.sessionId ||
62
+ transition.target.runtimeEventId !== event.id)
63
+ return { ok: false, reason: 'corrupt' };
64
+ const previous = byId.get(transition.transitionId);
65
+ if (previous &&
66
+ JSON.stringify({ ...previous, createdAt: 0 }) !==
67
+ JSON.stringify({ ...transition, createdAt: 0 })) {
68
+ return { ok: false, reason: 'corrupt' };
69
+ }
70
+ byId.set(transition.transitionId, transition);
39
71
  }
40
- const maxBytes = request.maxBytes ?? request.originalBytes;
41
- if (!Number.isSafeInteger(maxBytes) || maxBytes < request.originalBytes)
42
- return { ok: false, reason: 'too_large' };
43
- try {
44
- const loaded = await evidence.read({
45
- sessionId: request.sessionId,
46
- runtimeEventId: request.runtimeEventId,
47
- });
48
- if (!loaded.ok)
49
- return {
50
- ok: false,
51
- reason: loaded.reason === 'unavailable' ? 'read_failed' : loaded.reason,
52
- };
53
- const { event } = loaded;
54
- const content = event.content;
55
- if (event.sessionId !== request.sessionId)
56
- return { ok: false, reason: 'session_mismatch' };
57
- if (event.id !== request.runtimeEventId ||
58
- content?.kind !== 'function_response' ||
59
- content.id !== request.toolCallId ||
60
- content.name !== request.toolName ||
61
- content.providerExecuted ||
62
- !content.modelProjection)
63
- return { ok: false, reason: 'source_mismatch' };
64
- let source = decodeDurableToolResultProjection(content.modelProjection);
65
- const byId = new Map();
66
- for (const record of loaded.transitions) {
67
- const transition = decodeLedgerTransition(record, request.sessionId);
68
- if (!transition ||
69
- record.sessionId !== request.sessionId ||
70
- transition.target.runtimeEventId !== event.id)
72
+ const reduction = reduceEffectiveModelProjections([event], [...byId.values()]);
73
+ for (const transition of reduction.applied) {
74
+ const replacement = transition.replacement;
75
+ const placeholder = replacement.kind === 'json' ? replacement.value : undefined;
76
+ if (isArchivedToolResultPlaceholder(placeholder) &&
77
+ ((!identity && transition === reduction.applied.at(-1)) ||
78
+ (placeholder.rewriteVersion === 2 &&
79
+ identity &&
80
+ placeholder.sourceProjectionDigest === identity.sourceProjectionDigest &&
81
+ placeholder.previousTransitionId === identity.previousTransitionId))) {
82
+ if (placeholder.runtimeEventId !== event.id ||
83
+ placeholder.toolCallId !== content.id ||
84
+ placeholder.toolName !== content.name ||
85
+ (identity &&
86
+ (placeholder.bodySha256 !== identity.bodySha256 ||
87
+ placeholder.originalBytes !== identity.originalBytes)))
88
+ return { ok: false, reason: 'source_mismatch' };
89
+ if (placeholder.rewriteVersion === 2 &&
90
+ (placeholder.sourceProjectionDigest !== transition.sourceProjectionDigest ||
91
+ placeholder.previousTransitionId !== transition.previousTransitionId))
71
92
  return { ok: false, reason: 'corrupt' };
72
- const previous = byId.get(transition.transitionId);
73
- if (previous &&
74
- JSON.stringify({ ...previous, createdAt: 0 }) !==
75
- JSON.stringify({ ...transition, createdAt: 0 })) {
93
+ const serializedResult = serializeToolResultProjectionV1(source);
94
+ if (placeholder.originalBytes > request.maxBytes)
95
+ return { ok: false, reason: 'too_large' };
96
+ if (Buffer.byteLength(serializedResult, 'utf8') !== placeholder.originalBytes)
97
+ return { ok: false, reason: 'size_mismatch' };
98
+ if (createHash('sha256').update(serializedResult).digest('hex') !== placeholder.bodySha256)
76
99
  return { ok: false, reason: 'corrupt' };
77
- }
78
- byId.set(transition.transitionId, transition);
79
- }
80
- const reduction = reduceEffectiveModelProjections([event], [...byId.values()]);
81
- for (const transition of reduction.applied) {
82
- const replacement = transition.replacement;
83
- const placeholder = replacement.kind === 'json' ? replacement.value : undefined;
84
- if (isArchivedToolResultPlaceholder(placeholder) &&
85
- ((placeholder.rewriteVersion === 1 &&
86
- request.rewriteVersion === 1 &&
87
- placeholder.artifactId === request.artifactId) ||
88
- (placeholder.rewriteVersion === 2 &&
89
- request.rewriteVersion === 2 &&
90
- placeholder.sourceProjectionDigest === request.sourceProjectionDigest &&
91
- placeholder.previousTransitionId === request.previousTransitionId))) {
92
- if (placeholder.runtimeEventId !== request.runtimeEventId ||
93
- placeholder.toolCallId !== request.toolCallId ||
94
- placeholder.toolName !== request.toolName ||
95
- placeholder.bodySha256 !== request.bodySha256 ||
96
- placeholder.originalBytes !== request.originalBytes ||
97
- placeholder.rewriteVersion !== request.rewriteVersion)
98
- return { ok: false, reason: 'source_mismatch' };
99
- if (placeholder.rewriteVersion === 2 &&
100
- (placeholder.sourceProjectionDigest !== transition.sourceProjectionDigest ||
101
- placeholder.previousTransitionId !== transition.previousTransitionId))
102
- return { ok: false, reason: 'corrupt' };
103
- const serializedResult = serializeToolResultProjectionV1(source);
104
- if (Buffer.byteLength(serializedResult, 'utf8') !== request.originalBytes)
105
- return { ok: false, reason: 'size_mismatch' };
106
- if (createHash('sha256').update(serializedResult).digest('hex') !== request.bodySha256)
107
- return { ok: false, reason: 'corrupt' };
108
- return { ok: true, serializedResult };
109
- }
110
- source = transition.replacement;
100
+ return { ok: true, serializedResult };
111
101
  }
112
- return { ok: false, reason: 'not_found' };
102
+ source = transition.replacement;
113
103
  }
114
- catch {
115
- return { ok: false, reason: 'corrupt' };
104
+ if (!identity && reduction.rejected.length === 0) {
105
+ const serializedResult = serializeToolResultProjectionV1(source);
106
+ if (Buffer.byteLength(serializedResult, 'utf8') > request.maxBytes)
107
+ return { ok: false, reason: 'too_large' };
108
+ return { ok: true, serializedResult };
116
109
  }
117
- };
110
+ return { ok: false, reason: 'not_found' };
111
+ }
112
+ catch {
113
+ return { ok: false, reason: 'corrupt' };
114
+ }
118
115
  }
119
116
  export function createLedgerArchiveResourceReader(evidence) {
120
- const reader = createLedgerToolResultArchiveReader(evidence);
121
- return (input) => reader({
122
- ...input,
123
- kind: 'maka.archived_tool_result',
124
- rewriteVersion: 2,
125
- originalEstimatedTokens: 1,
126
- reason: 'stale_tool_result_pruned_before_compact',
127
- });
117
+ return (input) => readLedgerArchive(evidence, input);
128
118
  }
129
119
  /** Verify reconstructibility before committing a replacement; does not write any payload. */
130
120
  export function createLedgerArchivePreparer(evidence) {
@@ -119,7 +119,7 @@ export function createLocalWebFetchExecutor(input) {
119
119
  function responseLimitError() {
120
120
  return new Error('WebFetch response exceeds the 5 MB response limit.');
121
121
  }
122
- function assertAllowedTarget(url) {
122
+ export function assertAllowedTarget(url) {
123
123
  if (url.protocol !== 'http:' && url.protocol !== 'https:') {
124
124
  throw new Error('WebFetch URL must use HTTP or HTTPS.');
125
125
  }
@@ -101,17 +101,22 @@ export class ModelAdapter {
101
101
  });
102
102
  const { streamText, wrapLanguageModel } = ai;
103
103
  const maxOutputTokens = selectedModelMaxOutputTokens(this.input.connection, this.input.modelId, this.input.providerOptions, this.runtime);
104
+ let settleAccounting;
105
+ const terminalModel = withProviderFinishBoundary(input.model, wrapLanguageModel);
104
106
  const trackedModel = input.providerRequestTracker
105
107
  ? withProviderStreamTracking({
106
- model: input.model,
108
+ model: terminalModel,
107
109
  wrapLanguageModel,
108
110
  tracker: input.providerRequestTracker,
109
111
  abortSignal: input.abortSignal,
112
+ onAttempt: (settle) => {
113
+ settleAccounting = settle;
114
+ },
110
115
  ...(input.historyCompactBoundary
111
116
  ? { historyCompactBoundary: input.historyCompactBoundary }
112
117
  : {}),
113
118
  })
114
- : input.model;
119
+ : terminalModel;
115
120
  const usesOpenAiResponsesAdapter = hasOpenAiResponsesAdapter(this.runtime);
116
121
  const providerToolName = (name) => usesOpenAiResponsesAdapter && name === TOOL_SEARCH_NAME ? TOOL_SEARCH_PROVIDER_NAME : name;
117
122
  const runtimeToolName = (name) => usesOpenAiResponsesAdapter && name === TOOL_SEARCH_PROVIDER_NAME ? TOOL_SEARCH_NAME : name;
@@ -158,10 +163,6 @@ export class ModelAdapter {
158
163
  providerOptions,
159
164
  ...(responsesLane ? { headers: { [OPENAI_RESPONSES_LANE_HEADER]: responsesLane } } : {}),
160
165
  maxRetries: 0,
161
- // Preserve the final request's Maka-owned message projection without
162
- // retaining the provider request body. ProviderRequestTracker owns body
163
- // capture; duplicating it here can retain large base64 image payloads.
164
- include: { requestMessages: true },
165
166
  // With no continuation predicate, streamText performs one provider step.
166
167
  // Continuation belongs to the Runtime above this adapter.
167
168
  abortSignal: input.abortSignal,
@@ -176,6 +177,9 @@ export class ModelAdapter {
176
177
  requestMessages: fullMessages,
177
178
  abortSignal: input.abortSignal,
178
179
  runtimeToolName,
180
+ settleAccounting: async (outcome) => {
181
+ await settleAccounting?.(outcome);
182
+ },
179
183
  });
180
184
  }
181
185
  /**
@@ -194,7 +198,6 @@ export class ModelAdapter {
194
198
  const outcome = new Promise((resolve) => {
195
199
  settleOutcome = resolve;
196
200
  });
197
- const request = { messages: continuation.requestMessages };
198
201
  const events = {
199
202
  async *[Symbol.asyncIterator]() {
200
203
  let failure;
@@ -210,6 +213,10 @@ export class ModelAdapter {
210
213
  chunk.type === 'step-finish') {
211
214
  streamedRawFinishReason =
212
215
  rawFinishReasonString(chunk.rawFinishReason) ?? streamedRawFinishReason;
216
+ streamedFinishReason = chunkFinishReason(chunk) ?? streamedFinishReason;
217
+ if (chunk.type === 'finish')
218
+ sawFinish = true;
219
+ continue;
213
220
  }
214
221
  if (isUnfinalizedPlaintextSummaryReasoningEnd(chunk, resolvedRuntime)) {
215
222
  // The SDK emits this trailer from flush() when no
@@ -223,11 +230,6 @@ export class ModelAdapter {
223
230
  for (const event of translateChunk(chunk, openAiChatReasoningTransportState, resolvedRuntime, continuation.runtimeToolName)) {
224
231
  if (event.kind === 'error')
225
232
  failure = event.failure;
226
- if (event.kind === 'finish')
227
- sawFinish = true;
228
- if (event.kind === 'finish' || event.kind === 'step-finish') {
229
- streamedFinishReason = event.finishReason ?? streamedFinishReason;
230
- }
231
233
  yield event;
232
234
  }
233
235
  }
@@ -239,6 +241,9 @@ export class ModelAdapter {
239
241
  }
240
242
  }
241
243
  finally {
244
+ if (continuation.abortSignal.aborted) {
245
+ failure = normalizeProviderFailure(continuation.abortSignal.reason);
246
+ }
242
247
  const [sdkUsage, sdkFinishReason] = await Promise.all([
243
248
  sdk.usage.catch(() => undefined),
244
249
  sdk.finishReason.catch(() => undefined),
@@ -263,7 +268,6 @@ export class ModelAdapter {
263
268
  finishReason,
264
269
  rawFinishReason,
265
270
  usage,
266
- request,
267
271
  });
268
272
  let deferredFailure;
269
273
  if (sawUnfinalizedPlaintextSummary && settled.kind === 'completed') {
@@ -276,7 +280,6 @@ export class ModelAdapter {
276
280
  finishReason,
277
281
  rawFinishReason,
278
282
  usage,
279
- request,
280
283
  });
281
284
  }
282
285
  try {
@@ -301,7 +304,12 @@ export class ModelAdapter {
301
304
  }
302
305
  }
303
306
  finally {
304
- settleOutcome(settled);
307
+ try {
308
+ await continuation.settleAccounting(settled);
309
+ }
310
+ finally {
311
+ settleOutcome(settled);
312
+ }
305
313
  }
306
314
  if (deferredFailure) {
307
315
  // Consumers may stop iterating at the first error. The outcome and
@@ -378,33 +386,32 @@ export class ModelAdapter {
378
386
  }
379
387
  }
380
388
  export function settleModelStepOutcome(evidence) {
381
- const { aborted, failure, sawFinish, finishReason, rawFinishReason, usage, request } = evidence;
389
+ const { aborted, failure, sawFinish, finishReason, rawFinishReason, usage } = evidence;
382
390
  if (aborted || failure?.kind === 'abort') {
383
- return failedStepOutcome('aborted', failure ??
384
- normalizeProviderFailure(Object.assign(new Error('aborted'), { name: 'AbortError' })), request, usage);
391
+ return failedStepOutcome(failure ??
392
+ normalizeProviderFailure(Object.assign(new Error('aborted'), { name: 'AbortError' })), usage);
385
393
  }
386
394
  if (failure) {
387
- return failedStepOutcome('failed', failure, request, usage);
395
+ return failedStepOutcome(failure, usage);
388
396
  }
389
397
  if (!sawFinish || finishReason === 'other' || finishReason === 'unknown') {
390
- return failedStepOutcome('truncated', modelStepFailure('stream_truncated', `Provider stream ended without finishing (${finishReason})`), request, usage);
398
+ return failedStepOutcome(modelStepFailure('stream_truncated', `Provider stream ended without finishing (${finishReason})`), usage);
391
399
  }
392
400
  if (finishReason === 'content-filter' || finishReason === 'error') {
393
401
  const terminalFailure = finishReason === 'error'
394
402
  ? providerFinishFailure(rawFinishReason)
395
403
  : modelStepFailure('unknown', 'Provider stopped the stream on a content filter');
396
- return failedStepOutcome('failed', terminalFailure, request, usage);
404
+ return failedStepOutcome(terminalFailure, usage);
397
405
  }
398
406
  return {
399
407
  kind: 'completed',
400
408
  finishReason,
401
409
  ...(usage ? { usage } : {}),
402
- request,
403
410
  continuation: 'none',
404
411
  };
405
412
  }
406
413
  function modelStepFailure(kind, message) {
407
- return { type: 'model_failure', kind, message, retryable: false };
414
+ return { type: 'model_failure', kind, message, retryable: kind === 'stream_truncated' };
408
415
  }
409
416
  function providerFinishFailure(rawFinishReason) {
410
417
  if (rawFinishReason && rawFinishReason !== 'error') {
@@ -424,12 +431,11 @@ function providerFinishFailure(rawFinishReason) {
424
431
  }
425
432
  return modelStepFailure('provider_unavailable', 'Provider stopped the stream with an error');
426
433
  }
427
- function failedStepOutcome(kind, failure, request, usage) {
434
+ function failedStepOutcome(failure, usage) {
428
435
  return {
429
- kind,
436
+ kind: 'failed',
430
437
  failure,
431
438
  ...(usage ? { usage } : {}),
432
- request,
433
439
  continuation: 'none',
434
440
  };
435
441
  }
@@ -486,6 +492,35 @@ function requireResponsesReplayProfile(runtime) {
486
492
  }
487
493
  return runtime.responsesReplayProfile;
488
494
  }
495
+ /**
496
+ * A provider `finish` part is the LanguageModel stream's terminal semantic
497
+ * boundary. Expose EOF at that boundary so the SDK can flush its public
498
+ * finish/usage promises even when the transport keeps the connection open.
499
+ */
500
+ function withProviderFinishBoundary(model, wrapLanguageModel) {
501
+ return wrapLanguageModel({
502
+ model,
503
+ middleware: {
504
+ wrapStream: async ({ doStream, }) => {
505
+ const result = await doStream();
506
+ return {
507
+ ...result,
508
+ stream: result.stream.pipeThrough(new TransformStream({
509
+ transform(part, controller) {
510
+ controller.enqueue(part);
511
+ if (part !== null &&
512
+ typeof part === 'object' &&
513
+ !Array.isArray(part) &&
514
+ part.type === 'finish') {
515
+ controller.terminate();
516
+ }
517
+ },
518
+ })),
519
+ };
520
+ },
521
+ },
522
+ });
523
+ }
489
524
  /**
490
525
  * The finish reason to forward, preferring what the provider actually said.
491
526
  *
@@ -750,33 +785,7 @@ function translateChunk(chunk, openAiChatReasoningTransportState, runtime, runti
750
785
  case 'tool-input-start':
751
786
  case 'tool-input-delta':
752
787
  case 'tool-input-end':
753
- return chunk.providerExecuted === true ? [{ kind: 'provider-tool-input' }] : [];
754
- // Step boundaries (`start-step` / `finish-step`) and the terminal `finish`
755
- // carry no text/thinking to stream. The backend owns step accounting: it
756
- // counts and flushes one AssistantMessage per step and rotates the
757
- // messageId at each `finish-step`. `step-finish` is legacy replay fixture
758
- // compatibility — handled as a step boundary, not a text carrier.
759
- case 'finish-step':
760
- case 'step-finish': {
761
- const finishReason = chunkFinishReason(chunk);
762
- const rawFinishReason = rawFinishReasonString(chunk.rawFinishReason);
763
- // The same value the turn's outcome is decided from, so the record and
764
- // the outcome cannot name different reasons for the same stream.
765
- const usage = normalizeAiSdkUsage(chunk.usage, {
766
- rawFinishReason: rawFinishReason ?? finishReason,
767
- });
768
- return [
769
- {
770
- kind: 'step-finish',
771
- ...(usage ? { usage } : {}),
772
- ...(finishReason ? { finishReason } : {}),
773
- },
774
- ];
775
- }
776
- case 'finish': {
777
- const finishReason = chunkFinishReason(chunk);
778
- return [{ kind: 'finish', ...(finishReason ? { finishReason } : {}) }];
779
- }
788
+ return [{ kind: 'tool-input', providerExecuted: chunk.providerExecuted === true }];
780
789
  case 'start-step':
781
790
  case 'tool-result':
782
791
  case 'tool-error': {
@@ -134,8 +134,30 @@ export function estimateEffectiveToolResultChars(content, sessionId) {
134
134
  export function estimateRuntimeEventChars(event) {
135
135
  let total = 0;
136
136
  const content = event.content;
137
- if (content?.kind === 'text' || content?.kind === 'thinking')
137
+ if (content?.kind === 'text' || content?.kind === 'thinking') {
138
138
  total += content.text.length;
139
+ // Structured carriers are part of the event's weight: a quote- or
140
+ // attachment-only user message must not estimate to zero, or the
141
+ // history-compact gate drops a model-visible event (#4804).
142
+ if (content.kind === 'text') {
143
+ for (const quote of content.quotes ?? []) {
144
+ total += quote.text.length + (quote.label?.length ?? 0);
145
+ }
146
+ for (const attachment of content.attachments ?? []) {
147
+ // Weight the block the projection actually emits, not the display
148
+ // fields: name+mimeType is ~25 chars while the formatted attachment
149
+ // block with its Read guidance runs to hundreds (#4815 review).
150
+ total += formatAttachmentRefs([attachment]).length;
151
+ }
152
+ // Directory references project as one fixed envelope per message; count
153
+ // what it actually emits, or a directory-only message estimates to zero
154
+ // and the history-compact gate drops a model-visible event from the
155
+ // replay successors (#4815 review).
156
+ if (content.directoryReferences?.length) {
157
+ total += formatDirectoryReferences(content.directoryReferences).length;
158
+ }
159
+ }
160
+ }
139
161
  else if (content?.kind === 'function_call')
140
162
  total += content.name.length + stableJsonLength(content.args);
141
163
  else if (content?.kind === 'function_response')
@@ -584,15 +606,11 @@ export function buildRuntimeEventModelReplayPlan(events, options = {}) {
584
606
  providerOptions: steeringProviderOptions(item.steering.eventId),
585
607
  }
586
608
  : { role: item.role, content: item.content });
587
- const semanticKinds = [...new Set(items.map((item) => item.kind))];
588
609
  return {
589
610
  items,
590
611
  textMessages,
591
- semanticKinds,
592
612
  diagnostics,
593
- hasProviderNativeSemantics: semanticKinds.includes('thinking') ||
594
- semanticKinds.includes('tool_call') ||
595
- semanticKinds.includes('tool_result'),
613
+ hasProviderNativeSemantics: items.some((item) => item.kind !== 'text'),
596
614
  };
597
615
  }
598
616
  function modelTextRole(role) {
@@ -724,7 +742,7 @@ function formatAttachmentRefs(attachments) {
724
742
  .map((attachment) => {
725
743
  const resourceRef = formatAttachmentResourceRef(attachment.ref);
726
744
  const readArgument = resourceRef
727
- ? { ref: resourceRef }
745
+ ? { path: resourceRef }
728
746
  : attachment.ref.kind === 'workspace_file'
729
747
  ? { path: attachment.ref.relativePath }
730
748
  : attachment.ref.kind === 'external_file'
@@ -737,7 +755,7 @@ function formatAttachmentRefs(attachments) {
737
755
  ...(attachment.kind === 'image'
738
756
  ? [`Markdown image source: ${JSON.stringify(resourceRef)}`]
739
757
  : []),
740
- 'This is a Session resource, not a workspace file. Use the ref above; never use the display name as a path.',
758
+ 'This is a Session resource, not a workspace file. Use the path above; never use the display name as a path.',
741
759
  ].join('\n')
742
760
  : `Read argument: ${JSON.stringify(readArgument)}`
743
761
  : 'The attachment content is unavailable to Read.';
@@ -16,9 +16,8 @@
16
16
  * specific language governing permissions and limitations
17
17
  * under the License.
18
18
  */
19
- import { redactSecrets } from '@maka/core/redaction';
20
19
  import { BashTailBuffer } from './bash-tail-buffer.js';
21
- import { BASH_MAX_RETAINED_CHARS, shellTailValueWithUnsafeDropMarker } from './shell-exec.js';
20
+ import { BASH_MAX_RETAINED_CHARS } from './shell-exec.js';
22
21
  export class PipeTailCollector {
23
22
  stdout;
24
23
  stderr;
@@ -47,18 +46,16 @@ export class PipeTailCollector {
47
46
  return this.generation;
48
47
  }
49
48
  snapshot() {
50
- const stdoutRaw = shellTailValueWithUnsafeDropMarker(this.stdout);
51
- const stderrRaw = shellTailValueWithUnsafeDropMarker(this.stderr);
52
- const stdout = redactSecrets(stdoutRaw);
53
- const stderr = redactSecrets(stderrRaw);
49
+ const stdout = this.stdout.value();
50
+ const stderr = this.stderr.value();
54
51
  return {
55
52
  mode: 'pipes',
56
53
  stdout,
57
54
  stderr,
58
55
  ...(this.latestStream ? { latestStream: this.latestStream } : {}),
59
- stdoutTruncated: this.stdoutChars > stdoutRaw.length || this.stdout.hasDroppedUnsafe(),
60
- stderrTruncated: this.stderrChars > stderrRaw.length || this.stderr.hasDroppedUnsafe(),
61
- redacted: stdout !== stdoutRaw || stderr !== stderrRaw,
56
+ stdoutTruncated: this.stdoutChars > stdout.length,
57
+ stderrTruncated: this.stderrChars > stderr.length,
58
+ redacted: false,
62
59
  };
63
60
  }
64
61
  currentGeneration() {