maka-agent 0.2.0-dev.23.20260906 → 0.2.0-dev.25.20260908

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 (215) hide show
  1. package/README.md +38 -19
  2. package/README.zh-CN.md +34 -19
  3. package/dist/acp/maka-acp-agent.js +2 -1
  4. package/dist/acp/session-configuration.js +143 -0
  5. package/dist/acp/session-registry.js +90 -4
  6. package/dist/cli-core.js +2 -0
  7. package/dist/pi-transcript-tools.js +6 -0
  8. package/dist/pi-transcript.js +5 -12
  9. package/dist/pi-tui-layout.js +56 -10
  10. package/dist/pi-tui-pickers.js +102 -1
  11. package/dist/pi-tui-runner.js +230 -46
  12. package/dist/pi-tui-todo.js +221 -0
  13. package/dist/pi-tui-transcript-viewer.js +134 -7
  14. package/dist/runtime-host-cli-context.js +224 -78
  15. package/dist/runtime-host-cli-installation.js +8 -2
  16. package/dist/runtime-host-cli.js +31 -1
  17. package/dist/runtime-host-handoff-surface.js +106 -0
  18. package/dist/runtime-host-installed-update-bootstrap.js +13 -0
  19. package/dist/runtime-host-installed-update-coordinator.js +33 -0
  20. package/dist/runtime-host-lifecycle-transaction.js +9 -1
  21. package/dist/runtime-host-local-handoff.js +48 -5
  22. package/dist/runtime-host-local-managed-activation.js +84 -0
  23. package/dist/runtime-host-local-source-retirement.js +18 -2
  24. package/dist/runtime-host-managed-lifecycle-manager.js +1 -0
  25. package/dist/runtime-host-operator-retirement.js +50 -0
  26. package/dist/runtime-host-service-manager.js +3 -3
  27. package/dist/runtime-host-session-channel.js +13 -0
  28. package/dist/runtime-host-session-driver.js +46 -26
  29. package/dist/runtime-host-session-update.js +62 -0
  30. package/dist/runtime-host-tui-command.js +38 -73
  31. package/dist/runtime-host-tui-context.js +1 -0
  32. package/dist/runtime-host-tui-owner.js +226 -0
  33. package/dist/tui-copy-catalog.js +219 -6
  34. package/dist/tui-host-owner-copy.js +24 -0
  35. package/native/runtime-host-windows-task-launcher/prebuilds/win32-x64/maka-runtime-host-task-launcher.exe +0 -0
  36. package/node_modules/@maka/core/dist/agent-run.js +1 -0
  37. package/node_modules/@maka/core/dist/attachments.js +3 -0
  38. package/node_modules/@maka/core/dist/canonical-json.js +27 -0
  39. package/node_modules/@maka/core/dist/canonical-runtime-event.js +3 -1
  40. package/node_modules/@maka/core/dist/capabilities.js +35 -0
  41. package/node_modules/@maka/core/dist/computer-use.js +0 -1
  42. package/node_modules/@maka/core/dist/display-redaction.js +18 -0
  43. package/node_modules/@maka/core/dist/llm-connections.js +13 -0
  44. package/node_modules/@maka/core/dist/model-call-attempt.js +2 -0
  45. package/node_modules/@maka/core/dist/model-failure.js +40 -0
  46. package/node_modules/@maka/core/dist/model-metadata.generated.js +4 -4
  47. package/node_modules/@maka/core/dist/model-metadata.js +7 -3
  48. package/node_modules/@maka/core/dist/model-web-search.js +5 -4
  49. package/node_modules/@maka/core/dist/provider-registry.js +45 -4
  50. package/node_modules/@maka/core/dist/record-schema.js +9 -2
  51. package/node_modules/@maka/core/dist/redaction.js +35 -0
  52. package/node_modules/@maka/core/dist/run-composition.js +77 -2
  53. package/node_modules/@maka/core/dist/runtime-boundary.js +31 -11
  54. package/node_modules/@maka/core/dist/runtime-event.js +37 -6
  55. package/node_modules/@maka/core/dist/runtime-handoff.js +98 -0
  56. package/node_modules/@maka/core/dist/runtime-invocation.js +1 -1
  57. package/node_modules/@maka/core/dist/runtime-logical-execution.js +112 -0
  58. package/node_modules/@maka/core/dist/session.js +84 -56
  59. package/node_modules/@maka/core/dist/slash-command-catalog.js +3 -0
  60. package/node_modules/@maka/core/dist/tool-result-archive-evidence.js +20 -0
  61. package/node_modules/@maka/core/dist/tool-result-record-schema.js +2 -1
  62. package/node_modules/@maka/core/dist/usage-record-schema.js +26 -35
  63. package/node_modules/@maka/core/package.json +5 -0
  64. package/node_modules/@maka/eval/dist/experiment-directory.js +4 -13
  65. package/node_modules/@maka/mcp/dist/index.js +131 -1
  66. package/node_modules/@maka/runtime/dist/agent-run-inspect.js +0 -13
  67. package/node_modules/@maka/runtime/dist/agent-run.js +351 -105
  68. package/node_modules/@maka/runtime/dist/ai-sdk-backend.js +29 -13
  69. package/node_modules/@maka/runtime/dist/ai-sdk-compaction.js +109 -34
  70. package/node_modules/@maka/runtime/dist/ai-sdk-turn.js +184 -183
  71. package/node_modules/@maka/runtime/dist/archive-read-tool.js +2 -2
  72. package/node_modules/@maka/runtime/dist/context-budget-helpers.js +0 -16
  73. package/node_modules/@maka/runtime/dist/context-budget.js +14 -9
  74. package/node_modules/@maka/runtime/dist/conversation-copy.js +158 -15
  75. package/node_modules/@maka/runtime/dist/github-copilot-oauth-enrollment.js +3 -3
  76. package/node_modules/@maka/runtime/dist/goal-continuation.js +36 -4
  77. package/node_modules/@maka/runtime/dist/history-compact-checkpoint.js +18 -9
  78. package/node_modules/@maka/runtime/dist/history-compact-summarizer.js +30 -22
  79. package/node_modules/@maka/runtime/dist/history-compaction.js +29 -4
  80. package/node_modules/@maka/runtime/dist/ledger-tool-result-archive-reader.js +174 -0
  81. package/node_modules/@maka/runtime/dist/mcp-tools.js +7 -2
  82. package/node_modules/@maka/runtime/dist/message-authority.js +9 -0
  83. package/node_modules/@maka/runtime/dist/model-adapter.js +19 -98
  84. package/node_modules/@maka/runtime/dist/model-factory.js +19 -81
  85. package/node_modules/@maka/runtime/dist/model-fetcher.js +49 -2
  86. package/node_modules/@maka/runtime/dist/model-history.js +0 -112
  87. package/node_modules/@maka/runtime/dist/model-runtime.js +85 -111
  88. package/node_modules/@maka/runtime/dist/native-web-search-tool.js +2 -1
  89. package/node_modules/@maka/runtime/dist/openai-codex-history-compactor.js +2 -2
  90. package/node_modules/@maka/runtime/dist/opencode-session-header.js +4 -2
  91. package/node_modules/@maka/runtime/dist/plugin-runtime.js +20 -10
  92. package/node_modules/@maka/runtime/dist/plugin-tool-service.js +205 -0
  93. package/node_modules/@maka/runtime/dist/provider-error-classification.js +84 -123
  94. package/node_modules/@maka/runtime/dist/provider-request-telemetry.js +76 -109
  95. package/node_modules/@maka/runtime/dist/request-shape.js +23 -0
  96. package/node_modules/@maka/runtime/dist/run-handoff-gate.js +97 -0
  97. package/node_modules/@maka/runtime/dist/runtime-event-backfill.js +83 -55
  98. package/node_modules/@maka/runtime/dist/runtime-event-read-model.js +121 -159
  99. package/node_modules/@maka/runtime/dist/runtime-kernel.js +157 -112
  100. package/node_modules/@maka/runtime/dist/runtime-ledger-repair.js +160 -79
  101. package/node_modules/@maka/runtime/dist/runtime-read-model.js +30 -89
  102. package/node_modules/@maka/runtime/dist/runtime-resume.js +80 -4
  103. package/node_modules/@maka/runtime/dist/session-event-runtime-mapper.js +5 -0
  104. package/node_modules/@maka/runtime/dist/session-manager.js +171 -288
  105. package/node_modules/@maka/runtime/dist/session-projection-helpers.js +0 -27
  106. package/node_modules/@maka/runtime/dist/stream-graph-coordinator.js +21 -0
  107. package/node_modules/@maka/runtime/dist/stream-graph-supervisor-tools.js +0 -5
  108. package/node_modules/@maka/runtime/dist/subscription-model-fetch.js +3 -4
  109. package/node_modules/@maka/runtime/dist/test-connection.js +16 -17
  110. package/node_modules/@maka/runtime/dist/tool-activation-identity.js +41 -0
  111. package/node_modules/@maka/runtime/dist/tool-availability.js +11 -1
  112. package/node_modules/@maka/runtime/dist/tool-result-archive-encoding.js +38 -0
  113. package/node_modules/@maka/runtime/dist/tool-result-archive-resource.js +63 -1
  114. package/node_modules/@maka/runtime/dist/tool-result-archive-transition.js +42 -12
  115. package/node_modules/@maka/runtime/dist/tool-result-archive.js +27 -4
  116. package/node_modules/@maka/runtime/dist/tool-runtime.js +3 -61
  117. package/node_modules/@maka/runtime/package.json +2 -0
  118. package/node_modules/@maka/runtime-host/dist/adapter/session-projector.js +35 -0
  119. package/node_modules/@maka/runtime-host/dist/client/connect-or-spawn.js +9 -1
  120. package/node_modules/@maka/runtime-host/dist/client/connection.js +3 -0
  121. package/node_modules/@maka/runtime-host/dist/client/host-handoff-copy.js +179 -0
  122. package/node_modules/@maka/runtime-host/dist/client/host-handoff.js +275 -0
  123. package/node_modules/@maka/runtime-host/dist/client/host-retirement.js +26 -5
  124. package/node_modules/@maka/runtime-host/dist/client/index.js +2 -0
  125. package/node_modules/@maka/runtime-host/dist/client/launcher.js +3 -0
  126. package/node_modules/@maka/runtime-host/dist/client/remote-compatibility-error.js +2 -0
  127. package/node_modules/@maka/runtime-host/dist/client/session-subscription.js +46 -5
  128. package/node_modules/@maka/runtime-host/dist/control/endpoint.js +1 -3
  129. package/node_modules/@maka/runtime-host/dist/node-error.js +22 -0
  130. package/node_modules/@maka/runtime-host/dist/operator/index.js +2 -1
  131. package/node_modules/@maka/runtime-host/dist/operator/managed-deployment.js +1 -3
  132. package/node_modules/@maka/runtime-host/dist/operator/retirement-cancellation.js +20 -0
  133. package/node_modules/@maka/runtime-host/dist/peer-mesh/limits.js +0 -1
  134. package/node_modules/@maka/runtime-host/dist/peer-mesh/model.js +1 -1
  135. package/node_modules/@maka/runtime-host/dist/peer-reachability/publisher.js +1 -3
  136. package/node_modules/@maka/runtime-host/dist/protocol/host-status.js +21 -12
  137. package/node_modules/@maka/runtime-host/dist/protocol/index.js +29 -1
  138. package/node_modules/@maka/runtime-host/dist/protocol/operations.js +1 -0
  139. package/node_modules/@maka/runtime-host/dist/protocol/plan.js +1 -0
  140. package/node_modules/@maka/runtime-host/dist/protocol/plugin-platform.js +27 -5
  141. package/node_modules/@maka/runtime-host/dist/protocol/project-catalog.js +2 -2
  142. package/node_modules/@maka/runtime-host/dist/protocol/session-continuity.js +40 -20
  143. package/node_modules/@maka/runtime-host/dist/protocol/session-transcript.js +0 -5
  144. package/node_modules/@maka/runtime-host/dist/protocol/session-turns.js +29 -58
  145. package/node_modules/@maka/runtime-host/dist/protocol/turn.js +11 -1
  146. package/node_modules/@maka/runtime-host/dist/protocol/workhub-coordination.js +31 -2
  147. package/node_modules/@maka/runtime-host/dist/server/access-credential-store.js +1 -0
  148. package/node_modules/@maka/runtime-host/dist/server/agent-graph-coordinator.js +0 -3
  149. package/node_modules/@maka/runtime-host/dist/server/canonical-turn-snapshot.js +19 -4
  150. package/node_modules/@maka/runtime-host/dist/server/connection-session.js +7 -6
  151. package/node_modules/@maka/runtime-host/dist/server/execution-artifacts.js +32 -32
  152. package/node_modules/@maka/runtime-host/dist/server/execution-composition.js +144 -33
  153. package/node_modules/@maka/runtime-host/dist/server/execution-model-authority.js +5 -5
  154. package/node_modules/@maka/runtime-host/dist/server/execution-model-composition.js +45 -16
  155. package/node_modules/@maka/runtime-host/dist/server/goal-coordinator.js +40 -1
  156. package/node_modules/@maka/runtime-host/dist/server/host-kernel.js +96 -17
  157. package/node_modules/@maka/runtime-host/dist/server/host-residency-registry.js +13 -7
  158. package/node_modules/@maka/runtime-host/dist/server/hosted-execution-admission-registry.js +3 -1
  159. package/node_modules/@maka/runtime-host/dist/server/hosted-execution-recovery.js +124 -62
  160. package/node_modules/@maka/runtime-host/dist/server/interactive-run-composer.js +47 -22
  161. package/node_modules/@maka/runtime-host/dist/server/message-coordinator.js +76 -6
  162. package/node_modules/@maka/runtime-host/dist/server/plugin-platform-coordinator.js +6 -0
  163. package/node_modules/@maka/runtime-host/dist/server/plugin-platform.js +6 -0
  164. package/node_modules/@maka/runtime-host/dist/server/root-turn-coordinator.js +325 -73
  165. package/node_modules/@maka/runtime-host/dist/server/scheduled-task-coordinator.js +37 -2
  166. package/node_modules/@maka/runtime-host/dist/server/serial-outbound-writer.js +45 -3
  167. package/node_modules/@maka/runtime-host/dist/server/session-catalog-coordinator.js +50 -7
  168. package/node_modules/@maka/runtime-host/dist/server/session-continuity-coordinator.js +87 -25
  169. package/node_modules/@maka/runtime-host/dist/server/session-retirement-coordinator.js +5 -2
  170. package/node_modules/@maka/runtime-host/dist/server/session-revision-coordinator.js +12 -55
  171. package/node_modules/@maka/runtime-host/dist/server/session-sidecar-purge.js +1 -16
  172. package/node_modules/@maka/runtime-host/dist/server/session-transcript-pager.js +0 -1
  173. package/node_modules/@maka/runtime-host/dist/server/session-transcript-reader.js +460 -70
  174. package/node_modules/@maka/runtime-host/dist/server/shared-session-transcript.js +1 -1
  175. package/node_modules/@maka/runtime-host/dist/server/storage-maintenance.js +109 -0
  176. package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-action-gate.js +20 -2
  177. package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-coordinator.js +13 -4
  178. package/node_modules/@maka/runtime-host/dist/server/workhub-message-attachments.js +46 -0
  179. package/node_modules/@maka/storage/dist/artifact-store.js +21 -10
  180. package/node_modules/@maka/storage/dist/artifact-stores.js +1 -1
  181. package/node_modules/@maka/storage/dist/claude-code-session-adapter.js +0 -5
  182. package/node_modules/@maka/storage/dist/codex-session-adapter.js +284 -198
  183. package/node_modules/@maka/storage/dist/context-offload-snapshot.js +325 -0
  184. package/node_modules/@maka/storage/dist/execution-stores.js +9 -7
  185. package/node_modules/@maka/storage/dist/file-session-repository.js +1012 -0
  186. package/node_modules/@maka/storage/dist/git-exec.js +61 -0
  187. package/node_modules/@maka/storage/dist/git-worktree-child-executor.js +8 -35
  188. package/node_modules/@maka/storage/dist/goal-authority.js +2 -2
  189. package/node_modules/@maka/storage/dist/interaction-store.js +2 -2
  190. package/node_modules/@maka/storage/dist/opencode-session-adapter.js +0 -4
  191. package/node_modules/@maka/storage/dist/operational-state-backup.js +9 -5
  192. package/node_modules/@maka/storage/dist/project-catalog.js +2 -23
  193. package/node_modules/@maka/storage/dist/runtime-event-invariants.js +2 -2
  194. package/node_modules/@maka/storage/dist/runtime-event-persistence.js +1 -0
  195. package/node_modules/@maka/storage/dist/runtime-policy/connection-catalog-document.js +8 -3
  196. package/node_modules/@maka/storage/dist/runtime-transcript-query.js +308 -0
  197. package/node_modules/@maka/storage/dist/scheduled-task-store.js +249 -283
  198. package/node_modules/@maka/storage/dist/session-bundle-manifest.js +5 -17
  199. package/node_modules/@maka/storage/dist/session-bundle-policy.js +26 -5
  200. package/node_modules/@maka/storage/dist/session-copy-cleanup.js +2 -1
  201. package/node_modules/@maka/storage/dist/session-message-projection.js +15 -0
  202. package/node_modules/@maka/storage/dist/session-repository.js +767 -0
  203. package/node_modules/@maka/storage/dist/session-store.js +25 -99
  204. package/node_modules/@maka/storage/dist/sqlite-artifact-metadata.js +10 -3
  205. package/node_modules/@maka/storage/dist/sqlite-context-offload-store.js +24 -8
  206. package/node_modules/@maka/storage/dist/sqlite-core-execution-schema.js +7 -1
  207. package/node_modules/@maka/storage/dist/sqlite-runtime-schema.js +44 -1
  208. package/node_modules/@maka/storage/dist/sqlite-runtime-store.js +130 -27
  209. package/node_modules/@maka/storage/dist/sqlite-session-metadata-store.js +109 -892
  210. package/node_modules/@maka/storage/dist/storage-id.js +28 -0
  211. package/node_modules/@maka/storage/dist/tool-result-archive-evidence.js +138 -0
  212. package/node_modules/@maka/storage/dist/workspace-identity.js +2 -15
  213. package/node_modules/@maka/storage/dist/workspace-version-authority-internal.js +1 -8
  214. package/node_modules/@maka/storage/package.json +2 -0
  215. package/package.json +1 -1
@@ -0,0 +1,109 @@
1
+ /*
2
+ * Licensed to the Apache Software Foundation (ASF) under one
3
+ * or more contributor license agreements. See the NOTICE file
4
+ * distributed with this work for additional information
5
+ * regarding copyright ownership. The ASF licenses this file
6
+ * to you under the Apache License, Version 2.0 (the
7
+ * "License"); you may not use this file except in compliance
8
+ * with the License. You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing,
13
+ * software distributed under the License is distributed on an
14
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ * KIND, either express or implied. See the License for the
16
+ * specific language governing permissions and limitations
17
+ * under the License.
18
+ */
19
+ const ACTIVE_DELAY_MS = 100;
20
+ const IDLE_DELAY_MS = 60_000;
21
+ const MAX_BATCH_ITEMS = 64;
22
+ const MAX_BATCH_BYTES = 16 * 1024 * 1024;
23
+ /** Physical cleanup is optional work, admitted only after the Host publishes Ready. */
24
+ export class HostStorageMaintenance {
25
+ #lanes;
26
+ #onError;
27
+ #started = false;
28
+ #draining = false;
29
+ constructor(input) {
30
+ this.#onError = input.onError;
31
+ let after;
32
+ this.#lanes = [
33
+ {
34
+ name: 'artifact upgrade cleanup',
35
+ failures: 0,
36
+ run: async () => {
37
+ const result = await input.artifacts.reclaimUpgradeResidue({
38
+ after,
39
+ maxPaths: MAX_BATCH_ITEMS,
40
+ });
41
+ after = result.nextAfter ?? undefined;
42
+ if (result.failedPaths > 0) {
43
+ this.#report('artifact upgrade cleanup', new Error(`${result.failedPaths} paths remain pending`));
44
+ }
45
+ return result.nextAfter !== null;
46
+ },
47
+ },
48
+ ];
49
+ const context = input.contextOffload;
50
+ if (context)
51
+ this.#lanes.push({
52
+ name: 'context garbage collection',
53
+ failures: 0,
54
+ run: async () => (await context.collectGarbage({
55
+ olderThan: Date.now(),
56
+ maxBlobs: MAX_BATCH_ITEMS,
57
+ maxBytes: MAX_BATCH_BYTES,
58
+ })).hasMore,
59
+ });
60
+ }
61
+ start() {
62
+ if (this.#started || this.#draining)
63
+ return;
64
+ this.#started = true;
65
+ for (const lane of this.#lanes)
66
+ this.#schedule(lane, ACTIVE_DELAY_MS);
67
+ }
68
+ beginDrain() {
69
+ this.#draining = true;
70
+ for (const lane of this.#lanes)
71
+ clearTimeout(lane.timer);
72
+ }
73
+ async close() {
74
+ this.beginDrain();
75
+ await Promise.all(this.#lanes.map((lane) => lane.pending));
76
+ }
77
+ #schedule(lane, delay) {
78
+ if (this.#draining)
79
+ return;
80
+ lane.timer = setTimeout(() => {
81
+ lane.pending = this.#run(lane);
82
+ }, delay);
83
+ lane.timer.unref();
84
+ }
85
+ async #run(lane) {
86
+ if (this.#draining)
87
+ return;
88
+ let delay;
89
+ try {
90
+ const more = await lane.run();
91
+ lane.failures = 0;
92
+ delay = more ? ACTIVE_DELAY_MS : IDLE_DELAY_MS;
93
+ }
94
+ catch (error) {
95
+ lane.failures = Math.min(lane.failures + 1, 7);
96
+ delay = Math.min(IDLE_DELAY_MS, 1000 * 2 ** (lane.failures - 1));
97
+ this.#report(lane.name, error);
98
+ }
99
+ this.#schedule(lane, delay);
100
+ }
101
+ #report(name, error) {
102
+ try {
103
+ this.#onError(name, error);
104
+ }
105
+ catch {
106
+ // Diagnostics must not terminate a maintenance lane or poison Host readiness.
107
+ }
108
+ }
109
+ }
@@ -109,7 +109,11 @@ export class WorkHubCoordinationActionGate {
109
109
  if (proposal.disposition === 'answer_here') {
110
110
  const turnId = coordinationTurnId(input.actionId, 'answer');
111
111
  await this.#claimAction(input.actionId, 'answer_here', fingerprint, turnId);
112
- await this.#effects.answer({ turnId, text: input.userText }, context);
112
+ await this.#effects.answer({
113
+ turnId,
114
+ text: input.userText,
115
+ ...(input.attachments ? { attachments: input.attachments } : {}),
116
+ }, context);
113
117
  return { disposition: 'answer_here', coordinationTurnId: turnId };
114
118
  }
115
119
  if (proposal.disposition === 'clarify') {
@@ -384,7 +388,12 @@ export class WorkHubCoordinationActionGate {
384
388
  targetSessionName: target.title,
385
389
  disposition: 'create_new',
386
390
  userText: input.userText,
387
- create: { title: target.title, workspace: input.create.workspace },
391
+ ...(input.attachments ? { attachments: input.attachments } : {}),
392
+ create: {
393
+ title: target.title,
394
+ workspace: input.create.workspace,
395
+ ...(input.newWorkDefaults ? { defaults: input.newWorkDefaults } : {}),
396
+ },
388
397
  replacesActionId: replaced.actionId,
389
398
  replacesDelegationId: replaced.delegationId,
390
399
  replacedTargetSessionId: replaced.targetSessionId,
@@ -413,6 +422,7 @@ export class WorkHubCoordinationActionGate {
413
422
  targetSessionName: destination.sessionName,
414
423
  disposition: 'delegate_existing',
415
424
  userText: input.userText,
425
+ ...(input.attachments ? { attachments: input.attachments } : {}),
416
426
  replacesActionId: replaced.actionId,
417
427
  replacesDelegationId: replaced.delegationId,
418
428
  replacedTargetSessionId: replaced.targetSessionId,
@@ -615,6 +625,7 @@ function delegationAssignment(input, actionFingerprint, targetSessionId, targetS
615
625
  targetSessionName,
616
626
  disposition: input.proposal.disposition,
617
627
  userText: input.userText,
628
+ ...(input.attachments ? { attachments: input.attachments } : {}),
618
629
  };
619
630
  if (input.proposal.disposition === 'delegate_existing')
620
631
  return base;
@@ -626,6 +637,7 @@ function delegationAssignment(input, actionFingerprint, targetSessionId, targetS
626
637
  create: {
627
638
  title: input.proposal.title,
628
639
  workspace: create.workspace,
640
+ ...(input.newWorkDefaults ? { defaults: input.newWorkDefaults } : {}),
629
641
  },
630
642
  };
631
643
  }
@@ -657,6 +669,8 @@ function digest(value) {
657
669
  function actionFingerprint(input) {
658
670
  return digest({
659
671
  userText: input.userText,
672
+ ...(input.attachments ? { attachments: input.attachments } : {}),
673
+ ...(input.newWorkDefaults ? { newWorkDefaults: input.newWorkDefaults } : {}),
660
674
  disposition: input.proposal.disposition,
661
675
  ...(input.proposal.disposition === 'delegate_existing'
662
676
  ? { candidateRef: input.proposal.candidateRef }
@@ -687,6 +701,8 @@ function replacementActionFingerprint(input, targetSessionId) {
687
701
  }
688
702
  return digest({
689
703
  userText: input.userText,
704
+ ...(input.attachments ? { attachments: input.attachments } : {}),
705
+ ...(input.newWorkDefaults ? { newWorkDefaults: input.newWorkDefaults } : {}),
690
706
  disposition: input.proposal.disposition,
691
707
  replacesActionId: input.proposal.replacesActionId,
692
708
  target: {
@@ -747,6 +763,7 @@ function assignmentInputFromRecord(assignment) {
747
763
  targetSessionName: assignment.targetSessionName,
748
764
  disposition: assignment.disposition,
749
765
  userText: assignment.userText,
766
+ ...(assignment.attachments ? { attachments: assignment.attachments } : {}),
750
767
  ...(assignment.create ? { create: assignment.create } : {}),
751
768
  ...(assignment.replacesActionId && assignment.replacesDelegationId
752
769
  ? {
@@ -764,6 +781,7 @@ function assignmentInputFromReplacement(replacement) {
764
781
  targetSessionName: replacement.targetSessionName,
765
782
  disposition: replacement.disposition,
766
783
  userText: replacement.userText,
784
+ ...(replacement.attachments ? { attachments: replacement.attachments } : {}),
767
785
  ...(replacement.create ? { create: replacement.create } : {}),
768
786
  replacesActionId: replacement.replacesActionId,
769
787
  replacesDelegationId: replacement.replacesDelegationId,
@@ -88,7 +88,7 @@ export class HostWorkHubCoordinationCoordinator {
88
88
  readStopRequest: (delegationId) => this.#stores.readWorkHubStopRequest(delegationId),
89
89
  readStopResolution: (delegationId) => this.#stores.readWorkHubStopResolution(delegationId),
90
90
  answer: async (input, context) => {
91
- const outcome = await this.#answer({ turnId: input.turnId, text: input.text }, context);
91
+ const outcome = await this.#answer(input, context);
92
92
  if (!outcome.ok) {
93
93
  throw new WorkHubActionEffectFailure(outcome.error.code, outcome.error.message);
94
94
  }
@@ -136,6 +136,7 @@ export class HostWorkHubCoordinationCoordinator {
136
136
  targetSessionName: input.targetSessionName,
137
137
  disposition: input.disposition,
138
138
  userText: input.userText,
139
+ ...(input.attachments ? { attachments: input.attachments } : {}),
139
140
  replacesActionId: input.replacesActionId,
140
141
  replacesDelegationId: input.replacesDelegationId,
141
142
  replacedTargetSessionId: input.replacedTargetSessionId,
@@ -443,7 +444,10 @@ export class HostWorkHubCoordinationCoordinator {
443
444
  turnId: input.turnId,
444
445
  execution: {
445
446
  kind: 'workhub_coordination',
446
- inputDigest: digest({ text: input.text }),
447
+ inputDigest: digest({
448
+ text: input.text,
449
+ ...(input.attachments ? { attachments: input.attachments } : {}),
450
+ }),
447
451
  },
448
452
  archivedMessage: 'WorkHub Coordination Session is unavailable',
449
453
  // A recorded summary owns its Turn identity durably but is admitted
@@ -462,7 +466,13 @@ export class HostWorkHubCoordinationCoordinator {
462
466
  }
463
467
  return recorded.length > 0
464
468
  ? { kind: 'rejected', outcome: turnIdentityConflict() }
465
- : { kind: 'ready', content: normalizeMessageContent({ text: input.text }) };
469
+ : {
470
+ kind: 'ready',
471
+ content: normalizeMessageContent({
472
+ text: input.text,
473
+ ...(input.attachments ? { attachments: input.attachments } : {}),
474
+ }),
475
+ };
466
476
  },
467
477
  }, context);
468
478
  return outcome.ok ? { ok: true, result: { turnId: input.turnId } } : outcome;
@@ -619,7 +629,6 @@ function coordinationSummaryMessages(input) {
619
629
  turnId: input.turnId,
620
630
  ts: ts + 2,
621
631
  status: 'completed',
622
- partialOutputRetained: false,
623
632
  },
624
633
  ];
625
634
  }
@@ -0,0 +1,46 @@
1
+ /*
2
+ * Licensed to the Apache Software Foundation (ASF) under one
3
+ * or more contributor license agreements. See the NOTICE file
4
+ * distributed with this work for additional information
5
+ * regarding copyright ownership. The ASF licenses this file
6
+ * to you under the Apache License, Version 2.0 (the
7
+ * "License"); you may not use this file except in compliance
8
+ * with the License. You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing,
13
+ * software distributed under the License is distributed on an
14
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ * KIND, either express or implied. See the License for the
16
+ * specific language governing permissions and limitations
17
+ * under the License.
18
+ */
19
+ import { WORKHUB_COORDINATION_SESSION_ID } from '@maka/core/session';
20
+ import { WorkHubActionEffectFailure } from './workhub-coordination-action-gate.js';
21
+ /** Preserve canonical ownership when a Coordination message is delegated. */
22
+ export async function copyWorkHubAttachmentsToTarget(store, artifacts, targetSessionId, attachments) {
23
+ const invalid = await artifacts.validateTurnAttachments(WORKHUB_COORDINATION_SESSION_ID, attachments);
24
+ if (invalid)
25
+ throw new WorkHubActionEffectFailure('operation_conflict', invalid);
26
+ const ids = attachments.map((attachment) => {
27
+ if (attachment.ref.kind !== 'session_file')
28
+ throw new Error('Invalid WorkHub attachment');
29
+ return attachment.ref.relativePath;
30
+ });
31
+ const copied = await store.copyConversationArtifacts({
32
+ sourceSessionId: WORKHUB_COORDINATION_SESSION_ID,
33
+ targetSessionId,
34
+ turnIds: [],
35
+ includeArtifactIds: ids,
36
+ });
37
+ return attachments.map((attachment, index) => {
38
+ const relativePath = copied.artifactIds.get(ids[index]);
39
+ if (!relativePath)
40
+ throw new WorkHubActionEffectFailure('operation_conflict', 'WorkHub attachment was not copied');
41
+ return {
42
+ ...attachment,
43
+ ref: { kind: 'session_file', sessionId: targetSessionId, relativePath },
44
+ };
45
+ });
46
+ }
@@ -240,18 +240,22 @@ class SqliteArtifactStore {
240
240
  * once its file is gone, and a file that will not go keeps only its own note
241
241
  * rather than holding up the ones behind it.
242
242
  */
243
- async reclaimUpgradeResidue() {
244
- await this.enqueueMutation(async () => {
245
- await this.prepareMutationUnlocked();
246
- const recorded = this.metadataRepository.readUpgradeOrphanPaths();
247
- if (recorded.length === 0)
248
- return;
249
- const claimed = new Set(this.records.map((record) => record.relativePath));
243
+ async reclaimUpgradeResidue(input) {
244
+ if (!Number.isSafeInteger(input.maxPaths) || input.maxPaths < 1 || input.maxPaths > 1024) {
245
+ throw new TypeError('Artifact cleanup path limit must be between 1 and 1024');
246
+ }
247
+ const after = input.after ?? '';
248
+ const maxPaths = input.maxPaths;
249
+ return this.enqueueMutation(async () => {
250
+ const recorded = this.metadataRepository.readUpgradeOrphanPaths(after, maxPaths + 1);
251
+ const selected = recorded.slice(0, maxPaths);
250
252
  const directories = new Set();
251
253
  const discharged = [];
254
+ let failedPaths = 0;
252
255
  try {
253
- for (const relativePath of recorded) {
254
- if (claimed.has(relativePath) || !isSafeRelativeArtifactPath(relativePath)) {
256
+ for (const relativePath of selected) {
257
+ if (this.metadataRepository.hasRelativePath(relativePath) ||
258
+ !isSafeRelativeArtifactPath(relativePath)) {
255
259
  discharged.push(relativePath);
256
260
  continue;
257
261
  }
@@ -261,8 +265,10 @@ class SqliteArtifactStore {
261
265
  directories.add(dirname(target));
262
266
  }
263
267
  catch (error) {
264
- if (!isNotFound(error))
268
+ if (!isNotFound(error)) {
269
+ failedPaths += 1;
265
270
  continue;
271
+ }
266
272
  }
267
273
  discharged.push(relativePath);
268
274
  }
@@ -273,6 +279,11 @@ class SqliteArtifactStore {
273
279
  }
274
280
  if (discharged.length > 0)
275
281
  this.metadataRepository.forgetUpgradeOrphanPaths(discharged);
282
+ return {
283
+ nextAfter: recorded.length > selected.length ? selected.at(-1) : null,
284
+ processedPaths: selected.length,
285
+ failedPaths,
286
+ };
276
287
  });
277
288
  }
278
289
  async replayExistingArtifactUnlocked(existing, input, canonical) {
@@ -103,7 +103,7 @@ function createWriterFacade(lease, authority) {
103
103
  return run(() => store.copyConversationArtifacts(acceptedInput));
104
104
  },
105
105
  purgeSessionArtifacts: (sessionId) => run(() => store.purgeSessionArtifacts(sessionId)),
106
- reclaimUpgradeResidue: () => run(() => store.reclaimUpgradeResidue()),
106
+ reclaimUpgradeResidue: (input) => run(() => store.reclaimUpgradeResidue(input)),
107
107
  deleteUserArtifactInSession: (sessionId, artifactId) => run(() => store.deleteUserArtifactInSession(sessionId, artifactId)),
108
108
  close: () => {
109
109
  if (writerByLease.get(lease) === facade)
@@ -306,7 +306,6 @@ function timestampMs(record) {
306
306
  }
307
307
  return undefined;
308
308
  }
309
- export default ClaudeCodeSessionAdapter;
310
309
  /* ------------------------------------------------------------------ *
311
310
  * Transcript -> StoredMessage[]
312
311
  * ------------------------------------------------------------------ */
@@ -393,7 +392,6 @@ export function convertTranscript(sessionId, rawRecords) {
393
392
  status: 'aborted',
394
393
  abortedAt: turn.lastTs,
395
394
  abortSource: 'claude-code.interrupt',
396
- partialOutputRetained: true,
397
395
  });
398
396
  }
399
397
  else if (turn.failed) {
@@ -404,7 +402,6 @@ export function convertTranscript(sessionId, rawRecords) {
404
402
  ts: turn.lastTs,
405
403
  status: 'failed',
406
404
  errorClass: 'claude_code_api_error',
407
- partialOutputRetained: true,
408
405
  });
409
406
  }
410
407
  else if (turn.terminalStop) {
@@ -414,7 +411,6 @@ export function convertTranscript(sessionId, rawRecords) {
414
411
  turnId: turn.turnId,
415
412
  ts: turn.lastTs,
416
413
  status: 'completed',
417
- partialOutputRetained: true,
418
414
  });
419
415
  }
420
416
  else {
@@ -426,7 +422,6 @@ export function convertTranscript(sessionId, rawRecords) {
426
422
  status: 'aborted',
427
423
  abortedAt: turn.lastTs,
428
424
  abortSource: EXTERNAL_SNAPSHOT_ABORT_SOURCE,
429
- partialOutputRetained: true,
430
425
  });
431
426
  }
432
427
  turn = undefined;