maka-agent 0.2.0-dev.24.20260907 → 0.2.0-dev.26.20260909

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 (154) hide show
  1. package/README.md +38 -19
  2. package/README.zh-CN.md +34 -19
  3. package/dist/mcp-capability-provider.js +4 -1
  4. package/dist/pi-transcript-tools.js +6 -0
  5. package/dist/pi-tui-layout.js +56 -10
  6. package/dist/pi-tui-mcp-status.js +2 -2
  7. package/dist/pi-tui-pickers.js +121 -30
  8. package/dist/pi-tui-runner.js +156 -42
  9. package/dist/pi-tui-todo.js +221 -0
  10. package/dist/pi-tui-transcript-viewer.js +134 -7
  11. package/dist/runtime-host-cli-context.js +70 -13
  12. package/dist/runtime-host-handoff-surface.js +51 -26
  13. package/dist/runtime-host-local-handoff.js +11 -1
  14. package/dist/runtime-host-service-manager.js +0 -3
  15. package/dist/runtime-host-session-channel.js +13 -0
  16. package/dist/runtime-host-session-driver.js +42 -1
  17. package/dist/tui-autocomplete-layout.js +3 -1
  18. package/dist/tui-copy-catalog.js +85 -6
  19. package/dist/tui-editor-render.js +36 -0
  20. package/dist/tui-mcp-control.js +41 -6
  21. package/native/runtime-host-windows-task-launcher/prebuilds/win32-x64/maka-runtime-host-task-launcher.exe +0 -0
  22. package/node_modules/@maka/core/dist/agent-run.js +1 -0
  23. package/node_modules/@maka/core/dist/attachments.js +3 -0
  24. package/node_modules/@maka/core/dist/canonical-json.js +27 -0
  25. package/node_modules/@maka/core/dist/capabilities.js +35 -0
  26. package/node_modules/@maka/core/dist/computer-use.js +0 -1
  27. package/node_modules/@maka/core/dist/display-redaction.js +18 -0
  28. package/node_modules/@maka/core/dist/llm-connections.js +13 -0
  29. package/node_modules/@maka/core/dist/model-call-attempt.js +2 -0
  30. package/node_modules/@maka/core/dist/model-metadata.js +4 -0
  31. package/node_modules/@maka/core/dist/redaction.js +35 -0
  32. package/node_modules/@maka/core/dist/run-composition.js +77 -2
  33. package/node_modules/@maka/core/dist/runtime-event.js +3 -0
  34. package/node_modules/@maka/core/dist/session.js +57 -6
  35. package/node_modules/@maka/core/dist/slash-command-catalog.js +1 -0
  36. package/node_modules/@maka/core/dist/tool-result-record-schema.js +2 -1
  37. package/node_modules/@maka/core/dist/workhub-action-result.js +68 -0
  38. package/node_modules/@maka/core/package.json +3 -3
  39. package/node_modules/@maka/eval/dist/experiment-directory.js +4 -13
  40. package/node_modules/@maka/eval/dist/toolchain-verification.js +1 -1
  41. package/node_modules/@maka/mcp/dist/form-elicitation.js +213 -0
  42. package/node_modules/@maka/mcp/dist/index.js +337 -71
  43. package/node_modules/@maka/runtime/dist/agent-run-inspect.js +0 -13
  44. package/node_modules/@maka/runtime/dist/agent-run.js +90 -2
  45. package/node_modules/@maka/runtime/dist/ai-sdk-backend.js +16 -8
  46. package/node_modules/@maka/runtime/dist/ai-sdk-turn.js +57 -50
  47. package/node_modules/@maka/runtime/dist/archive-read-tool.js +2 -2
  48. package/node_modules/@maka/runtime/dist/context-budget-helpers.js +0 -16
  49. package/node_modules/@maka/runtime/dist/conversation-copy.js +153 -11
  50. package/node_modules/@maka/runtime/dist/github-copilot-oauth-enrollment.js +3 -3
  51. package/node_modules/@maka/runtime/dist/goal-continuation.js +5 -1
  52. package/node_modules/@maka/runtime/dist/ledger-tool-result-archive-reader.js +69 -1
  53. package/node_modules/@maka/runtime/dist/mcp-tools.js +7 -2
  54. package/node_modules/@maka/runtime/dist/model-fetcher.js +42 -2
  55. package/node_modules/@maka/runtime/dist/model-history.js +0 -112
  56. package/node_modules/@maka/runtime/dist/plugin-runtime.js +20 -10
  57. package/node_modules/@maka/runtime/dist/plugin-tool-service.js +205 -0
  58. package/node_modules/@maka/runtime/dist/provider-request-telemetry.js +8 -1
  59. package/node_modules/@maka/runtime/dist/request-shape.js +23 -0
  60. package/node_modules/@maka/runtime/dist/runtime-event-backfill.js +1 -1
  61. package/node_modules/@maka/runtime/dist/runtime-event-read-model.js +24 -1
  62. package/node_modules/@maka/runtime/dist/runtime-kernel.js +127 -13
  63. package/node_modules/@maka/runtime/dist/session-manager.js +20 -36
  64. package/node_modules/@maka/runtime/dist/stream-graph-coordinator.js +21 -0
  65. package/node_modules/@maka/runtime/dist/stream-graph-supervisor-tools.js +0 -5
  66. package/node_modules/@maka/runtime/dist/test-connection.js +0 -1
  67. package/node_modules/@maka/runtime/dist/tool-activation-identity.js +41 -0
  68. package/node_modules/@maka/runtime/dist/tool-availability.js +11 -1
  69. package/node_modules/@maka/runtime/dist/tool-result-archive-resource.js +63 -1
  70. package/node_modules/@maka/runtime/dist/tool-result-archive-transition.js +42 -12
  71. package/node_modules/@maka/runtime/dist/tool-result-archive.js +27 -4
  72. package/node_modules/@maka/runtime/package.json +1 -0
  73. package/node_modules/@maka/runtime-host/dist/client/connection.js +30 -5
  74. package/node_modules/@maka/runtime-host/dist/client/host-handoff-copy.js +52 -13
  75. package/node_modules/@maka/runtime-host/dist/client/host-handoff.js +2 -0
  76. package/node_modules/@maka/runtime-host/dist/client/host-retirement.js +4 -2
  77. package/node_modules/@maka/runtime-host/dist/client/peer-client.js +18 -1
  78. package/node_modules/@maka/runtime-host/dist/client/session-subscription.js +19 -0
  79. package/node_modules/@maka/runtime-host/dist/control/endpoint.js +1 -3
  80. package/node_modules/@maka/runtime-host/dist/node-error.js +22 -0
  81. package/node_modules/@maka/runtime-host/dist/operator/managed-deployment.js +1 -3
  82. package/node_modules/@maka/runtime-host/dist/peer-mesh/limits.js +0 -1
  83. package/node_modules/@maka/runtime-host/dist/peer-mesh/model.js +1 -1
  84. package/node_modules/@maka/runtime-host/dist/peer-reachability/publisher.js +1 -3
  85. package/node_modules/@maka/runtime-host/dist/protocol/index.js +9 -1
  86. package/node_modules/@maka/runtime-host/dist/protocol/operations.js +3 -2
  87. package/node_modules/@maka/runtime-host/dist/protocol/plan.js +1 -0
  88. package/node_modules/@maka/runtime-host/dist/protocol/plugin-platform.js +27 -5
  89. package/node_modules/@maka/runtime-host/dist/protocol/project-catalog.js +2 -2
  90. package/node_modules/@maka/runtime-host/dist/protocol/session-continuity.js +1 -0
  91. package/node_modules/@maka/runtime-host/dist/protocol/workhub-coordination.js +86 -157
  92. package/node_modules/@maka/runtime-host/dist/server/access-credential-store.js +4 -0
  93. package/node_modules/@maka/runtime-host/dist/server/agent-graph-coordinator.js +0 -3
  94. package/node_modules/@maka/runtime-host/dist/server/canonical-session-projection.js +2 -1
  95. package/node_modules/@maka/runtime-host/dist/server/connection-session.js +28 -8
  96. package/node_modules/@maka/runtime-host/dist/server/daily-review-coordinator.js +112 -56
  97. package/node_modules/@maka/runtime-host/dist/server/execution-artifacts.js +32 -32
  98. package/node_modules/@maka/runtime-host/dist/server/execution-composition.js +85 -25
  99. package/node_modules/@maka/runtime-host/dist/server/execution-model-composition.js +42 -14
  100. package/node_modules/@maka/runtime-host/dist/server/failure-diagnostic.js +24 -0
  101. package/node_modules/@maka/runtime-host/dist/server/goal-coordinator.js +7 -3
  102. package/node_modules/@maka/runtime-host/dist/server/host-kernel.js +3 -3
  103. package/node_modules/@maka/runtime-host/dist/server/host-session-availability.js +5 -2
  104. package/node_modules/@maka/runtime-host/dist/server/hosted-execution-recovery.js +3 -2
  105. package/node_modules/@maka/runtime-host/dist/server/hosted-execution-tool-profile.js +34 -4
  106. package/node_modules/@maka/runtime-host/dist/server/interactive-run-composer.js +51 -23
  107. package/node_modules/@maka/runtime-host/dist/server/operation-dispatcher.js +2 -7
  108. package/node_modules/@maka/runtime-host/dist/server/plugin-platform-coordinator.js +6 -0
  109. package/node_modules/@maka/runtime-host/dist/server/plugin-platform.js +6 -0
  110. package/node_modules/@maka/runtime-host/dist/server/root-turn-coordinator.js +110 -14
  111. package/node_modules/@maka/runtime-host/dist/server/runtime-resource-coordinator.js +11 -8
  112. package/node_modules/@maka/runtime-host/dist/server/scheduled-task-coordinator.js +31 -21
  113. package/node_modules/@maka/runtime-host/dist/server/serial-outbound-writer.js +1 -1
  114. package/node_modules/@maka/runtime-host/dist/server/session-catalog-coordinator.js +20 -8
  115. package/node_modules/@maka/runtime-host/dist/server/session-retirement-coordinator.js +5 -2
  116. package/node_modules/@maka/runtime-host/dist/server/session-revision-coordinator.js +4 -0
  117. package/node_modules/@maka/runtime-host/dist/server/session-transcript-reader.js +15 -104
  118. package/node_modules/@maka/runtime-host/dist/server/shared-session-transcript.js +3 -0
  119. package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-action-gate.js +59 -82
  120. package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-coordinator.js +132 -139
  121. package/node_modules/@maka/runtime-host/dist/server/workhub-message-attachments.js +46 -0
  122. package/node_modules/@maka/storage/dist/agent-run-store.js +14 -1
  123. package/node_modules/@maka/storage/dist/artifact-store.js +40 -3
  124. package/node_modules/@maka/storage/dist/atomic-file-write.js +74 -0
  125. package/node_modules/@maka/storage/dist/claude-code-session-adapter.js +0 -1
  126. package/node_modules/@maka/storage/dist/codex-session-adapter.js +284 -196
  127. package/node_modules/@maka/storage/dist/credential-store.js +12 -63
  128. package/node_modules/@maka/storage/dist/execution-stores.js +4 -1
  129. package/node_modules/@maka/storage/dist/git-exec.js +61 -0
  130. package/node_modules/@maka/storage/dist/git-worktree-child-executor.js +8 -35
  131. package/node_modules/@maka/storage/dist/goal-authority.js +2 -2
  132. package/node_modules/@maka/storage/dist/interaction-store.js +2 -2
  133. package/node_modules/@maka/storage/dist/mcp-config-store.js +10 -25
  134. package/node_modules/@maka/storage/dist/project-catalog.js +2 -23
  135. package/node_modules/@maka/storage/dist/runtime-event-invariants.js +2 -2
  136. package/node_modules/@maka/storage/dist/runtime-policy/connection-catalog-document.js +8 -3
  137. package/node_modules/@maka/storage/dist/scheduled-task-store.js +249 -283
  138. package/node_modules/@maka/storage/dist/session-bundle-manifest.js +5 -17
  139. package/node_modules/@maka/storage/dist/session-bundle-policy.js +2 -1
  140. package/node_modules/@maka/storage/dist/session-copy-cleanup.js +2 -1
  141. package/node_modules/@maka/storage/dist/session-store.js +14 -2
  142. package/node_modules/@maka/storage/dist/settings-store.js +8 -4
  143. package/node_modules/@maka/storage/dist/sqlite-artifact-metadata.js +11 -0
  144. package/node_modules/@maka/storage/dist/sqlite-runtime-store.js +1 -2
  145. package/node_modules/@maka/storage/dist/sqlite-session-metadata-schema.js +12 -1
  146. package/node_modules/@maka/storage/dist/sqlite-session-metadata-store.js +67 -3
  147. package/node_modules/@maka/storage/dist/stable-storage.js +14 -1
  148. package/node_modules/@maka/storage/dist/storage-id.js +28 -0
  149. package/node_modules/@maka/storage/dist/tool-result-archive-evidence.js +31 -4
  150. package/node_modules/@maka/storage/dist/workspace-identity.js +2 -15
  151. package/node_modules/@maka/storage/dist/workspace-version-authority-internal.js +1 -8
  152. package/package.json +1 -1
  153. package/node_modules/@maka/core/dist/workhub-creation-intent.js +0 -990
  154. package/node_modules/@maka/core/dist/workhub-session-resolver.js +0 -50
@@ -16,12 +16,30 @@
16
16
  * specific language governing permissions and limitations
17
17
  * under the License.
18
18
  */
19
+ import { isWorkHubActionResult } from '@maka/core/workhub-action-result';
20
+ import { decodeMessageContent } from './turn.js';
21
+ import { WORKHUB_COORDINATION_SESSION_ID, isWorkHubCreateDefaults, } from '@maka/core/session';
19
22
  import { requireCount, requireEntityId, requireExactRecord, requireRecord, requireShapedRecord, requireUtf8String, } from './codec.js';
20
23
  import { invalidProtocolFrame } from './errors.js';
21
24
  import { defineOperation } from './operation-spec.js';
22
25
  import { decodeWorkspaceProjection, decodeWorkspaceTarget, } from './workspace.js';
26
+ import { decodeSessionConfigurationUpdateInput, decodeSessionUpdateResult, decodeSessionCatalogItem, SESSION_CATALOG_OPERATION_SPECS, } from './session-catalog.js';
27
+ export function decodeWorkHubCoordinationConfigureModelInput(value) {
28
+ const input = requireExactRecord(value, 'WorkHub model configuration', [
29
+ 'expectedRevision',
30
+ 'modelTarget',
31
+ ]);
32
+ const decoded = decodeSessionConfigurationUpdateInput({
33
+ sessionId: WORKHUB_COORDINATION_SESSION_ID,
34
+ expectedRevision: input.expectedRevision,
35
+ patch: { modelTarget: input.modelTarget },
36
+ });
37
+ return {
38
+ expectedRevision: decoded.expectedRevision,
39
+ modelTarget: decoded.patch.modelTarget,
40
+ };
41
+ }
23
42
  export const WORKHUB_COORDINATION_TEXT_MAX_BYTES = 48 * 1024;
24
- export const WORKHUB_COORDINATION_SUMMARY_MAX_BYTES = 8 * 1024;
25
43
  const COORDINATION_TITLE_MAX_BYTES = 512;
26
44
  const CANDIDATE_SET_ID_MAX_BYTES = 96;
27
45
  export const WORKHUB_COORDINATION_CANDIDATE_MAX_ITEMS = 32;
@@ -54,6 +72,25 @@ const CANDIDATE_ERRORS = [
54
72
  'internal_failure',
55
73
  ];
56
74
  export const WORKHUB_COORDINATION_OPERATION_SPECS = {
75
+ 'workhub.coordination.configureModel': defineOperation({
76
+ mode: 'command',
77
+ availability: 'ready',
78
+ errors: SESSION_CATALOG_OPERATION_SPECS['session.configuration.update'].errors,
79
+ decodeInput: decodeWorkHubCoordinationConfigureModelInput,
80
+ decodeOutput: decodeSessionUpdateResult,
81
+ assertOutputForInput: (input, output) => SESSION_CATALOG_OPERATION_SPECS['session.configuration.update'].assertOutputForInput?.({
82
+ sessionId: WORKHUB_COORDINATION_SESSION_ID,
83
+ expectedRevision: input.expectedRevision,
84
+ patch: { modelTarget: input.modelTarget },
85
+ }, output),
86
+ }),
87
+ 'workhub.coordination.query': defineOperation({
88
+ mode: 'query',
89
+ availability: 'ready',
90
+ errors: RESOLVE_ERRORS,
91
+ decodeInput: decodeWorkHubCoordinationResolveInput,
92
+ decodeOutput: decodeSessionCatalogItem,
93
+ }),
57
94
  'workhub.coordination.resolve': defineOperation({
58
95
  mode: 'command',
59
96
  availability: 'ready',
@@ -68,13 +105,6 @@ export const WORKHUB_COORDINATION_OPERATION_SPECS = {
68
105
  decodeInput: decodeWorkHubCoordinationAnswerInput,
69
106
  decodeOutput: decodeWorkHubCoordinationTurnResult,
70
107
  }),
71
- 'workhub.coordination.record': defineOperation({
72
- mode: 'command',
73
- availability: 'ready',
74
- errors: TURN_ERRORS,
75
- decodeInput: decodeWorkHubCoordinationRecordInput,
76
- decodeOutput: decodeWorkHubCoordinationTurnResult,
77
- }),
78
108
  'workhub.coordination.candidates': defineOperation({
79
109
  mode: 'query',
80
110
  availability: 'ready',
@@ -82,11 +112,11 @@ export const WORKHUB_COORDINATION_OPERATION_SPECS = {
82
112
  decodeInput: decodeWorkHubCoordinationCandidatesInput,
83
113
  decodeOutput: decodeWorkHubCoordinationCandidatesResult,
84
114
  }),
85
- 'workhub.coordination.act': defineOperation({
115
+ 'workhub.coordination.actFromTurn': defineOperation({
86
116
  mode: 'command',
87
117
  availability: 'ready',
88
- errors: TURN_ERRORS,
89
- decodeInput: decodeWorkHubCoordinationActInput,
118
+ errors: [...TURN_ERRORS, 'candidate_set_stale'],
119
+ decodeInput: decodeWorkHubCoordinationActFromTurnInput,
90
120
  decodeOutput: decodeWorkHubCoordinationActResult,
91
121
  }),
92
122
  };
@@ -101,24 +131,18 @@ export function decodeWorkHubCoordinationResolveResult(value) {
101
131
  };
102
132
  }
103
133
  export function decodeWorkHubCoordinationAnswerInput(value) {
104
- const input = requireExactRecord(value, 'WorkHub Coordination answer input', ['turnId', 'text']);
134
+ const input = requireShapedRecord(value, 'WorkHub Coordination answer input', ['turnId', 'text'], ['attachments']);
105
135
  return {
136
+ ...(input.attachments !== undefined
137
+ ? {
138
+ attachments: decodeMessageContent({ text: input.text, attachments: input.attachments })
139
+ .attachments,
140
+ }
141
+ : {}),
106
142
  turnId: requireEntityId(input.turnId, 'WorkHub Coordination Turn id'),
107
143
  text: requireUtf8String(input.text, 'WorkHub Coordination answer text', WORKHUB_COORDINATION_TEXT_MAX_BYTES),
108
144
  };
109
145
  }
110
- export function decodeWorkHubCoordinationRecordInput(value) {
111
- const input = requireExactRecord(value, 'WorkHub Coordination record input', [
112
- 'turnId',
113
- 'userText',
114
- 'assistantText',
115
- ]);
116
- return {
117
- turnId: requireEntityId(input.turnId, 'WorkHub Coordination Turn id'),
118
- userText: requireUtf8String(input.userText, 'WorkHub Coordination user text', WORKHUB_COORDINATION_TEXT_MAX_BYTES),
119
- assistantText: requireUtf8String(input.assistantText, 'WorkHub Coordination assistant text', WORKHUB_COORDINATION_SUMMARY_MAX_BYTES),
120
- };
121
- }
122
146
  export function decodeWorkHubCoordinationTurnResult(value) {
123
147
  const result = requireExactRecord(value, 'WorkHub Coordination Turn result', ['turnId']);
124
148
  return {
@@ -145,35 +169,54 @@ export function decodeWorkHubCoordinationCandidatesResult(value) {
145
169
  candidates: result.candidates.map(decodeWorkHubCoordinationCandidate),
146
170
  };
147
171
  }
148
- export function decodeWorkHubCoordinationActInput(value) {
149
- const input = requireShapedRecord(value, 'WorkHub Coordination action input', ['actionId', 'userText', 'proposal'], ['candidateSetId', 'create', 'confirmation']);
172
+ export function decodeWorkHubCoordinationActFromTurnInput(value) {
173
+ const input = requireShapedRecord(value, 'WorkHub active Turn action input', ['turnId', 'actionId', 'proposal'], ['candidateSetId', 'create', 'newWorkDefaults', 'delegationText']);
174
+ const fields = decodeWorkHubCoordinationActionFields(input);
175
+ return {
176
+ ...fields,
177
+ proposal: fields.proposal,
178
+ turnId: requireEntityId(input.turnId, 'WorkHub Coordination Turn id'),
179
+ };
180
+ }
181
+ function decodeWorkHubCoordinationActionFields(input) {
150
182
  const proposal = decodeWorkHubCoordinationProposal(input.proposal);
183
+ if (input.newWorkDefaults !== undefined &&
184
+ (!isWorkHubCreateDefaults(input.newWorkDefaults) ||
185
+ !(proposal.disposition === 'create_new' ||
186
+ (proposal.disposition === 'replace' && proposal.target.disposition === 'create_new')))) {
187
+ throw invalidProtocolFrame('Invalid WorkHub creation defaults');
188
+ }
189
+ const delegationText = input.delegationText === undefined
190
+ ? undefined
191
+ : requireUtf8String(input.delegationText, 'WorkHub delegation text', WORKHUB_COORDINATION_TEXT_MAX_BYTES);
192
+ if (delegationText !== undefined &&
193
+ (!delegationText.trim() ||
194
+ (proposal.disposition !== 'delegate_existing' &&
195
+ proposal.disposition !== 'create_new' &&
196
+ proposal.disposition !== 'replace'))) {
197
+ throw invalidProtocolFrame('Invalid WorkHub delegation text');
198
+ }
151
199
  const base = {
152
200
  actionId: requireEntityId(input.actionId, 'WorkHub Coordination action id'),
153
- userText: requireUtf8String(input.userText, 'WorkHub Coordination action text', WORKHUB_COORDINATION_TEXT_MAX_BYTES),
154
201
  proposal,
202
+ ...(input.newWorkDefaults !== undefined
203
+ ? { newWorkDefaults: input.newWorkDefaults }
204
+ : {}),
205
+ ...(delegationText === undefined ? {} : { delegationText }),
155
206
  };
156
207
  if (proposal.disposition === 'delegate_existing') {
157
- if (input.create !== undefined ||
158
- input.candidateSetId === undefined ||
159
- input.confirmation !== undefined) {
208
+ if (input.create !== undefined || input.candidateSetId === undefined) {
160
209
  throw invalidProtocolFrame('Invalid WorkHub delegation context');
161
210
  }
162
211
  return { ...base, candidateSetId: candidateSetId(input.candidateSetId) };
163
212
  }
164
213
  if (proposal.disposition === 'create_new') {
165
- if (input.candidateSetId !== undefined ||
166
- input.create === undefined ||
167
- input.confirmation !== undefined) {
214
+ if (input.candidateSetId !== undefined || input.create === undefined) {
168
215
  throw invalidProtocolFrame('Invalid WorkHub creation context');
169
216
  }
170
217
  return { ...base, create: decodeWorkHubCoordinationCreateContext(input.create) };
171
218
  }
172
219
  if (proposal.disposition === 'replace') {
173
- const confirmation = decodeWorkHubCoordinationDestructiveConfirmation(input.confirmation);
174
- if (confirmation.kind !== 'user_correction') {
175
- throw invalidProtocolFrame('Invalid WorkHub replacement confirmation');
176
- }
177
220
  if (proposal.target.disposition === 'delegate_existing') {
178
221
  if (input.candidateSetId === undefined || input.create !== undefined) {
179
222
  throw invalidProtocolFrame('Invalid WorkHub replacement context');
@@ -181,7 +224,6 @@ export function decodeWorkHubCoordinationActInput(value) {
181
224
  return {
182
225
  ...base,
183
226
  candidateSetId: candidateSetId(input.candidateSetId),
184
- confirmation,
185
227
  };
186
228
  }
187
229
  if (input.candidateSetId !== undefined || input.create === undefined) {
@@ -190,112 +232,20 @@ export function decodeWorkHubCoordinationActInput(value) {
190
232
  return {
191
233
  ...base,
192
234
  create: decodeWorkHubCoordinationCreateContext(input.create),
193
- confirmation,
194
235
  };
195
236
  }
196
- if (proposal.disposition === 'stop_work') {
197
- const confirmation = decodeWorkHubCoordinationDestructiveConfirmation(input.confirmation);
198
- if (confirmation.kind !== 'user_stop' ||
199
- input.candidateSetId !== undefined ||
200
- input.create !== undefined) {
201
- throw invalidProtocolFrame('Invalid WorkHub stop context');
202
- }
203
- return { ...base, confirmation };
204
- }
205
- if (input.candidateSetId !== undefined ||
206
- input.create !== undefined ||
207
- input.confirmation !== undefined) {
237
+ if (input.candidateSetId !== undefined || input.create !== undefined) {
208
238
  throw invalidProtocolFrame('Unexpected WorkHub action context');
209
239
  }
210
240
  return base;
211
241
  }
212
242
  export function decodeWorkHubCoordinationActResult(value) {
213
- const result = requireRecord(value, 'WorkHub Coordination action result');
214
- if (result.disposition === 'answer_here' || result.disposition === 'clarify') {
215
- const exact = requireExactRecord(result, 'WorkHub Coordination local action result', [
216
- 'disposition',
217
- 'coordinationTurnId',
218
- ]);
219
- return {
220
- disposition: result.disposition,
221
- coordinationTurnId: requireEntityId(exact.coordinationTurnId, 'WorkHub Coordination Turn id'),
222
- };
223
- }
224
- if (result.disposition === 'delegate_existing' || result.disposition === 'create_new') {
225
- const exact = requireShapedRecord(result, 'WorkHub Coordination execution action result', ['disposition', 'targetSessionId', 'targetTurnId'], ['steered']);
226
- if (exact.steered !== undefined && exact.steered !== true) {
227
- throw invalidProtocolFrame('Invalid WorkHub Coordination steering result');
228
- }
229
- return {
230
- disposition: result.disposition,
231
- targetSessionId: requireEntityId(exact.targetSessionId, 'WorkHub target Session id'),
232
- targetTurnId: requireEntityId(exact.targetTurnId, 'WorkHub target Turn id'),
233
- ...(exact.steered === true ? { steered: true } : {}),
234
- };
235
- }
236
- if (result.disposition === 'replace') {
237
- const exact = requireShapedRecord(result, 'WorkHub Coordination replacement result', ['disposition', 'replacementDisposition', 'targetSessionId', 'targetTurnId'], ['steered']);
238
- if (exact.replacementDisposition !== 'delegate_existing' &&
239
- exact.replacementDisposition !== 'create_new') {
240
- throw invalidProtocolFrame('Invalid WorkHub replacement disposition');
241
- }
242
- if (exact.steered !== undefined && exact.steered !== true) {
243
- throw invalidProtocolFrame('Invalid WorkHub Coordination steering result');
244
- }
245
- return {
246
- disposition: 'replace',
247
- replacementDisposition: exact.replacementDisposition,
248
- targetSessionId: requireEntityId(exact.targetSessionId, 'WorkHub target Session id'),
249
- targetTurnId: requireEntityId(exact.targetTurnId, 'WorkHub target Turn id'),
250
- ...(exact.steered === true ? { steered: true } : {}),
251
- };
252
- }
253
- if (result.disposition === 'stop_work') {
254
- const exact = requireShapedRecord(result, 'WorkHub Coordination stop result', ['disposition', 'outcome', 'targetSessionId'], ['targetTurnId']);
255
- if (exact.outcome !== 'cancelled_pending' &&
256
- exact.outcome !== 'stop_delivered' &&
257
- exact.outcome !== 'already_terminal' &&
258
- exact.outcome !== 'not_owned') {
259
- throw invalidProtocolFrame('Invalid WorkHub stop outcome');
260
- }
261
- if (((exact.outcome === 'stop_delivered' || exact.outcome === 'not_owned') &&
262
- exact.targetTurnId === undefined) ||
263
- (exact.outcome === 'cancelled_pending' && exact.targetTurnId !== undefined)) {
264
- throw invalidProtocolFrame('Invalid WorkHub stop target Turn');
265
- }
266
- return {
267
- disposition: 'stop_work',
268
- outcome: exact.outcome,
269
- targetSessionId: requireEntityId(exact.targetSessionId, 'WorkHub target Session id'),
270
- ...(exact.targetTurnId === undefined
271
- ? {}
272
- : {
273
- targetTurnId: requireEntityId(exact.targetTurnId, 'WorkHub target Turn id'),
274
- }),
275
- };
276
- }
277
- if (result.disposition === 'resume_work') {
278
- const exact = requireShapedRecord(result, 'WorkHub Coordination resume result', ['disposition', 'outcome', 'targetSessionId'], ['targetTurnId']);
279
- if (exact.outcome !== 'resume_started' && exact.outcome !== 'already_running') {
280
- throw invalidProtocolFrame('Invalid WorkHub resume outcome');
281
- }
282
- // Only a started continuation names a Turn: the Host has one to name, and
283
- // the other two outcomes changed nothing that could carry an identity.
284
- if ((exact.outcome === 'resume_started') !== (exact.targetTurnId !== undefined)) {
285
- throw invalidProtocolFrame('Invalid WorkHub resume target Turn');
286
- }
287
- return {
288
- disposition: 'resume_work',
289
- outcome: exact.outcome,
290
- targetSessionId: requireEntityId(exact.targetSessionId, 'WorkHub target Session id'),
291
- ...(exact.targetTurnId === undefined
292
- ? {}
293
- : {
294
- targetTurnId: requireEntityId(exact.targetTurnId, 'WorkHub target Turn id'),
295
- }),
296
- };
243
+ if (!isWorkHubActionResult(value) ||
244
+ value.disposition === 'answer_here' ||
245
+ value.disposition === 'clarify') {
246
+ throw invalidProtocolFrame('Invalid WorkHub Coordination action result');
297
247
  }
298
- throw invalidProtocolFrame('Invalid WorkHub Coordination action disposition');
248
+ return Object.fromEntries(Object.entries(value).filter(([, field]) => field !== undefined));
299
249
  }
300
250
  function decodeWorkHubCoordinationCandidate(value) {
301
251
  const candidate = requireShapedRecord(value, 'WorkHub Coordination candidate', ['candidateRef', 'sessionId', 'sessionName', 'workspace', 'state', 'updatedAt'], ['latestDelegationActionId']);
@@ -315,20 +265,6 @@ function decodeWorkHubCoordinationCandidate(value) {
315
265
  }
316
266
  function decodeWorkHubCoordinationProposal(value) {
317
267
  const proposal = requireRecord(value, 'WorkHub Coordination proposal');
318
- if (proposal.disposition === 'answer_here') {
319
- requireExactRecord(proposal, 'WorkHub answer proposal', ['disposition']);
320
- return { disposition: 'answer_here' };
321
- }
322
- if (proposal.disposition === 'clarify') {
323
- const exact = requireExactRecord(proposal, 'WorkHub clarification proposal', [
324
- 'disposition',
325
- 'assistantText',
326
- ]);
327
- return {
328
- disposition: 'clarify',
329
- assistantText: requireUtf8String(exact.assistantText, 'WorkHub clarification text', WORKHUB_COORDINATION_SUMMARY_MAX_BYTES),
330
- };
331
- }
332
268
  if (proposal.disposition === 'delegate_existing') {
333
269
  const exact = requireExactRecord(proposal, 'WorkHub delegation proposal', [
334
270
  'disposition',
@@ -419,13 +355,6 @@ function decodeWorkHubCoordinationCreateContext(value) {
419
355
  workspace: decodeWorkspaceTarget(context.workspace),
420
356
  };
421
357
  }
422
- function decodeWorkHubCoordinationDestructiveConfirmation(value) {
423
- const confirmation = requireExactRecord(value, 'WorkHub destructive confirmation', ['kind']);
424
- if (confirmation.kind !== 'user_correction' && confirmation.kind !== 'user_stop') {
425
- throw invalidProtocolFrame('Invalid WorkHub destructive confirmation');
426
- }
427
- return { kind: confirmation.kind };
428
- }
429
358
  function candidateSetId(value) {
430
359
  const id = requireUtf8String(value, 'WorkHub candidate set id', CANDIDATE_SET_ID_MAX_BYTES);
431
360
  if (!/^sha256:[a-f0-9]{64}$/u.test(id)) {
@@ -53,6 +53,10 @@ const PERSISTED_GRANT_MIGRATIONS = new Map([
53
53
  // Retired with the second execution-inspection contract; no shipped surface
54
54
  // called execution.inspect.resolve.
55
55
  ['execution.inspect.resolve', { kind: 'release' }],
56
+ // Direct WorkHub actions and record writes were retired. Their grants do not
57
+ // authorize actFromTurn, which requires the active coordination Turn.
58
+ ['workhub.coordination.act', { kind: 'release' }],
59
+ ['workhub.coordination.record', { kind: 'release' }],
56
60
  ]);
57
61
  export const ACCESS_FILE_NAME = 'runtime-host-access.json';
58
62
  export const SESSION_GUEST_OPERATION_GRANTS = Object.freeze([
@@ -117,9 +117,6 @@ export class HostAgentGraphCoordinator {
117
117
  export function projectAgentGraphClientSnapshot(snapshot) {
118
118
  return projectSnapshot(snapshot);
119
119
  }
120
- export function projectAgentGraphOperatorInspection(inspection) {
121
- return projectInspection(inspection);
122
- }
123
120
  function projectSnapshot(snapshot) {
124
121
  const operators = snapshot.operators.slice(0, AGENT_GRAPH_MAX_OPERATORS).map(projectOperator);
125
122
  const visibleOperatorIds = new Set(operators.map((operator) => operator.operatorId));
@@ -16,6 +16,7 @@
16
16
  * specific language governing permissions and limitations
17
17
  * under the License.
18
18
  */
19
+ import { isSessionNotFoundError } from '@maka/storage/execution-stores';
19
20
  import { decodeSessionContinuitySnapshot, SESSION_CONTINUITY_SCHEMA_VERSION, SESSION_CONTINUITY_SNAPSHOT_MAX_BYTES, } from '../protocol/index.js';
20
21
  import { isMissingFile, readCanonicalTurnSnapshot, worstCaseFailedTurnSnapshot, } from './canonical-turn-snapshot.js';
21
22
  import { worstCaseMessageQueueProjection } from './message-queue-capacity.js';
@@ -42,7 +43,7 @@ export class CanonicalSessionProjectionReader {
42
43
  metadataRevision = record.revision;
43
44
  }
44
45
  catch (error) {
45
- if (isMissingFile(error))
46
+ if (isMissingFile(error) || isSessionNotFoundError(error))
46
47
  return null;
47
48
  throw error;
48
49
  }
@@ -17,13 +17,16 @@
17
17
  * under the License.
18
18
  */
19
19
  import { decodeClientFrame, isClientCapabilityClientFrameKind, RUNTIME_HOST_MAX_IN_FLIGHT_DOMAIN_REQUESTS, } from '../protocol/index.js';
20
+ import { runtimeHostLogBuffer } from '../process-diagnostics.js';
20
21
  import { dispatchOperation, operationFailureResponse, } from './operation-dispatcher.js';
21
22
  import { BoundedSerialOutboundWriter } from './serial-outbound-writer.js';
22
23
  import { RuntimeHostTransportError } from '../transport/framed-transport.js';
23
24
  import { authorizeClientCapabilityFrame, authorizeRuntimeHostOperation, hasRuntimeHostOperationGrant, } from './connection-authority.js';
25
+ import { boundedFailureDiagnostic } from './failure-diagnostic.js';
24
26
  export class RuntimeHostConnectionSession {
25
27
  #options;
26
28
  #writer;
29
+ #onDiagnostic;
27
30
  #requests = new Map();
28
31
  #transcriptPageTail = Promise.resolve();
29
32
  #inFlightStatusRequests = 0;
@@ -37,7 +40,9 @@ export class RuntimeHostConnectionSession {
37
40
  #closed = false;
38
41
  constructor(options) {
39
42
  this.#options = options;
40
- this.#writer = new BoundedSerialOutboundWriter(options.transport, () => this.#teardown());
43
+ this.#onDiagnostic =
44
+ options.onDiagnostic ?? ((diagnostic) => runtimeHostLogBuffer.append('error', diagnostic));
45
+ this.#writer = new BoundedSerialOutboundWriter(options.transport, (error) => this.#fail(error));
41
46
  }
42
47
  async run() {
43
48
  this.attachGlobalChanges();
@@ -51,8 +56,8 @@ export class RuntimeHostConnectionSession {
51
56
  await this.#closeAfterDispatchedReplies();
52
57
  }
53
58
  }
54
- catch {
55
- this.#teardown();
59
+ catch (error) {
60
+ this.#fail(error);
56
61
  }
57
62
  finally {
58
63
  this.#teardown();
@@ -94,7 +99,7 @@ export class RuntimeHostConnectionSession {
94
99
  if (isClientCapabilityClientFrameKind(frame.kind)) {
95
100
  const capabilityFrame = frame;
96
101
  if (!authorizeClientCapabilityFrame(this.#options.connection.authority, capabilityFrame)) {
97
- this.#teardown();
102
+ this.#fail(new Error('Runtime Host Client Capability frame is not authorized'));
98
103
  return;
99
104
  }
100
105
  this.#ensureClientCapabilities()?.accept(capabilityFrame);
@@ -104,9 +109,13 @@ export class RuntimeHostConnectionSession {
104
109
  }
105
110
  const usesLivenessReserve = this.#requests.size === RUNTIME_HOST_MAX_IN_FLIGHT_DOMAIN_REQUESTS &&
106
111
  (frame.operation === 'host.status' || this.#inFlightStatusRequests > 0);
107
- if (this.#requests.has(frame.requestId) ||
108
- (this.#requests.size >= RUNTIME_HOST_MAX_IN_FLIGHT_DOMAIN_REQUESTS && !usesLivenessReserve)) {
109
- this.#teardown();
112
+ if (this.#requests.has(frame.requestId)) {
113
+ this.#fail(new Error('Runtime Host Client reused an active request id'));
114
+ return;
115
+ }
116
+ if (this.#requests.size >= RUNTIME_HOST_MAX_IN_FLIGHT_DOMAIN_REQUESTS &&
117
+ !usesLivenessReserve) {
118
+ this.#fail(new Error('Runtime Host Client exceeded the in-flight request limit'));
110
119
  return;
111
120
  }
112
121
  this.#dispatch(frame);
@@ -119,7 +128,7 @@ export class RuntimeHostConnectionSession {
119
128
  ? this.#transcriptPageTail.then(() => this.#handleRequest(frame))
120
129
  : this.#handleRequest(frame);
121
130
  const task = handling
122
- .catch(() => this.#teardown())
131
+ .catch((error) => this.#fail(error))
123
132
  .finally(() => {
124
133
  if (this.#requests.get(frame.requestId) === task) {
125
134
  this.#requests.delete(frame.requestId);
@@ -313,6 +322,17 @@ export class RuntimeHostConnectionSession {
313
322
  this.#hostChanges?.close();
314
323
  this.#hostChanges = undefined;
315
324
  }
325
+ #fail(error) {
326
+ if (this.#closed)
327
+ return;
328
+ try {
329
+ this.#onDiagnostic(`[runtime-host] connection session failed: ${boundedFailureDiagnostic(error)}`);
330
+ }
331
+ catch {
332
+ // Diagnostics cannot keep an invalid connection alive.
333
+ }
334
+ this.#teardown();
335
+ }
316
336
  #teardown() {
317
337
  if (this.#closed)
318
338
  return;