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
@@ -46,18 +46,9 @@ const TRANSCRIPT_TURN_SCAN_LIMIT = 1;
46
46
  * as absent rather than searched for down the Session.
47
47
  */
48
48
  const TRANSCRIPT_LOOKUP_MAX_TURNS = 2;
49
- /** One storage round trip of Coordination rows, sized like one ledger Turn. */
50
- const COORDINATION_TRANSCRIPT_SCAN_LIMIT = 64;
51
- const COORDINATION_TRANSCRIPT_SCAN_MAX_BYTES = DURABLE_TRANSCRIPT_TURN_MAX_BYTES;
52
49
  export function createSessionTranscriptReader(input) {
53
50
  const ledger = createDurableLedgerTranscriptReader(input);
54
- const coordination = createCoordinationTranscriptReader(input.stores);
55
- const isCoordination = (sessionId) => sessionId === WORKHUB_COORDINATION_SESSION_ID;
56
- // Only a ledger-backed Session has a conversion; the Coordination Session's
57
- // rows are the transcript, not something a run left behind.
58
51
  const prepared = async (sessionId) => {
59
- if (isCoordination(sessionId))
60
- return coordination;
61
52
  await input.ensureTranscriptLedger?.(sessionId);
62
53
  return ledger;
63
54
  };
@@ -148,6 +139,12 @@ function createDurableLedgerTranscriptReader(input) {
148
139
  if (projected.diagnostics.some(isHardRuntimeEventReadModelDiagnostic)) {
149
140
  throw new Error('Durable RuntimeEvent transcript projection is incomplete');
150
141
  }
142
+ const admission = turn.invocation.sessionId === WORKHUB_COORDINATION_SESSION_ID
143
+ ? await input.stores.agentRunStore.readRootTurnAdmission(turn.invocation.sessionId, turn.invocation.turnId)
144
+ : undefined;
145
+ const actionId = admission?.execution.kind === 'workhub_coordination'
146
+ ? admission.execution.actionId
147
+ : undefined;
151
148
  const ordinals = new Map(turn.events.map((entry) => [entry.event.id, entry.ordinal]));
152
149
  const emitted = new Map();
153
150
  return projected.messages.map((message, index) => {
@@ -160,7 +157,12 @@ function createDurableLedgerTranscriptReader(input) {
160
157
  throw new Error('RuntimeEvent exceeds its transcript sequence stride');
161
158
  }
162
159
  emitted.set(ordinal, offset + 1);
163
- return { sequence: ordinal * EVENT_SEQUENCE_STRIDE + offset, message };
160
+ return {
161
+ sequence: ordinal * EVENT_SEQUENCE_STRIDE + offset,
162
+ message: message.type === 'user' && actionId
163
+ ? { ...message, coordinationActionId: actionId }
164
+ : message,
165
+ };
164
166
  });
165
167
  };
166
168
  const readTurns = async (sessionId, request) => store.readTranscriptInvocations(sessionId, {
@@ -221,9 +223,11 @@ function createDurableLedgerTranscriptReader(input) {
221
223
  ordinal = older ? low - 1 : high + 1;
222
224
  }
223
225
  };
226
+ const source = { readHighWater: highWater, scan };
224
227
  return {
228
+ source,
225
229
  readHighWater: highWater,
226
- ...pagedTranscriptReads({ readHighWater: highWater, scan }),
230
+ ...pagedTranscriptReads(source),
227
231
  /** One row per Turn, folded from the Turn's own projected messages. */
228
232
  async readTurnContributions(sessionId, throughSequence, position, maxContributions) {
229
233
  const watermark = throughSequence ?? (await highWater(sessionId));
@@ -395,99 +399,6 @@ function pagedTranscriptReads(source) {
395
399
  },
396
400
  };
397
401
  }
398
- /**
399
- * The WorkHub Coordination Session's transcript, read from the rows the WorkHub
400
- * writes.
401
- *
402
- * Every other Session's transcript is what its runs did, so the ledger holds
403
- * all of it. The Coordination Session's is not: a delegation, a stop and a
404
- * routing summary are appended under a Turn id that no root Turn admission ever
405
- * minted, so there is no invocation for the ledger to hang them on and no
406
- * conversion that could lift them. `workhub.coordination.answer` is the one
407
- * path that would admit a real Turn and nothing in the renderer calls it.
408
- *
409
- * Delete this source once the WorkHub admits a Coordination Turn for every
410
- * action, which its own ADR already requires (#3492,
411
- * `docs/architecture/workhub-coordination-session-adr.md`): the Session then
412
- * reads like any other and this reader has nothing left to do.
413
- */
414
- function createCoordinationTranscriptReader(stores) {
415
- const store = stores.sessionStore;
416
- const highWater = (sessionId) => store.readTranscriptHighWaterSnapshot(sessionId);
417
- const scan = async function* (sessionId, request) {
418
- const throughSequence = request.throughSequence === undefined ? await highWater(sessionId) : request.throughSequence;
419
- if (throughSequence === null)
420
- return;
421
- const older = request.direction === 'older';
422
- const position = request.position ?? (older ? throughSequence : 0);
423
- let cursor = older ? Math.min(position, throughSequence) + 1 : position - 1;
424
- for (;;) {
425
- const page = await store.readMessagesAfter(sessionId, {
426
- ...(older ? { beforeSequence: cursor } : { afterSequence: cursor }),
427
- maxMessages: COORDINATION_TRANSCRIPT_SCAN_LIMIT,
428
- maxStoredBytes: COORDINATION_TRANSCRIPT_SCAN_MAX_BYTES,
429
- });
430
- if (page.records.length === 0)
431
- return;
432
- for (const record of page.records) {
433
- if (!older && record.sequence > throughSequence)
434
- return;
435
- yield record;
436
- }
437
- cursor = page.records.at(-1).sequence;
438
- }
439
- };
440
- const source = { readHighWater: highWater, scan };
441
- return {
442
- readHighWater: highWater,
443
- ...pagedTranscriptReads(source),
444
- /** Folded from the rows themselves; these Turns have nothing else. */
445
- async readTurnContributions(sessionId, throughSequence, position, maxContributions) {
446
- const watermark = throughSequence ?? (await highWater(sessionId));
447
- if (watermark === null) {
448
- return { throughSequence: null, contributions: [], nextPosition: null };
449
- }
450
- const byTurn = new Map();
451
- let nextPosition = null;
452
- for await (const { sequence, message } of scan(sessionId, {
453
- direction: 'newer',
454
- throughSequence: watermark,
455
- position,
456
- })) {
457
- const turnId = message.turnId;
458
- if (turnId === undefined)
459
- continue;
460
- if (!byTurn.has(turnId) && byTurn.size === maxContributions) {
461
- nextPosition = sequence;
462
- break;
463
- }
464
- byTurn.set(turnId, foldTurnContribution(byTurn.get(turnId), turnId, sequence, message));
465
- }
466
- return { throughSequence: watermark, contributions: [...byTurn.values()], nextPosition };
467
- },
468
- /** Every prompt, in order: this transcript has no index to sample from. */
469
- async readTurnLandmarks(sessionId, maxLandmarks) {
470
- const throughSequence = await highWater(sessionId);
471
- if (throughSequence === null)
472
- return { throughSequence: null, landmarks: [] };
473
- const landmarks = [];
474
- for await (const { sequence, message } of scan(sessionId, {
475
- direction: 'newer',
476
- throughSequence,
477
- })) {
478
- if (message.type !== 'user' || message.turnId === undefined)
479
- continue;
480
- const label = (message.displayText ?? message.text ?? '').trim();
481
- if (!label)
482
- continue;
483
- landmarks.push({ turnId: message.turnId, sequence, label });
484
- if (landmarks.length === maxLandmarks)
485
- break;
486
- }
487
- return { throughSequence, landmarks };
488
- },
489
- };
490
- }
491
402
  function ordinalOf(sequence) {
492
403
  return Math.floor(sequence / EVENT_SEQUENCE_STRIDE);
493
404
  }
@@ -44,6 +44,9 @@ export function projectSharedSessionTranscriptMessage(message, sessionId) {
44
44
  ? {}
45
45
  : { steeringEventId: message.steeringEventId }),
46
46
  ...(message.origin === undefined ? {} : { origin: message.origin }),
47
+ ...(message.coordinationActionId === undefined
48
+ ? {}
49
+ : { coordinationActionId: message.coordinationActionId }),
47
50
  };
48
51
  }
49
52
  case 'assistant':
@@ -18,7 +18,6 @@
18
18
  */
19
19
  import { createHash } from 'node:crypto';
20
20
  import { WORKHUB_COORDINATION_SESSION_ID, isWorkHubCoordinationSessionTarget, } from '@maka/core/session';
21
- import { readWorkHubRequestIntent, workHubCorrectionTargetsSession, workHubCreationAuthorizesTitle, workHubNamedDelegationActionTargetsSession, } from '@maka/core/workhub-creation-intent';
22
21
  import { WORKHUB_COORDINATION_CANDIDATE_MAX_ITEMS } from '../protocol/index.js';
23
22
  const SIDE_CONVERSATION_LABEL = 'mode:side_conversation';
24
23
  const ACTION_REPLAY_MAX_ITEMS = 256;
@@ -54,10 +53,17 @@ export class WorkHubCoordinationActionGate {
54
53
  async candidates() {
55
54
  return candidateSet(await this.#effects.listSessions());
56
55
  }
57
- act(input, context) {
56
+ act(input, context, admittedTurnId) {
58
57
  if (!input.userText.trim()) {
59
58
  return Promise.reject(new WorkHubActionGateFailure('action_conflict', 'WorkHub action text is empty'));
60
59
  }
60
+ if (input.delegationText !== undefined &&
61
+ (!input.delegationText.trim() ||
62
+ (input.proposal.disposition !== 'delegate_existing' &&
63
+ input.proposal.disposition !== 'create_new' &&
64
+ input.proposal.disposition !== 'replace'))) {
65
+ return Promise.reject(new WorkHubActionGateFailure('action_conflict', 'Invalid WorkHub delegation text'));
66
+ }
61
67
  if (input.proposal.disposition === 'create_new' && !input.proposal.title.trim()) {
62
68
  return Promise.reject(new WorkHubActionGateFailure('action_conflict', 'WorkHub creation title is empty'));
63
69
  }
@@ -70,7 +76,7 @@ export class WorkHubCoordinationActionGate {
70
76
  }
71
77
  return replay.result;
72
78
  }
73
- const result = this.#act(input, fingerprint, context);
79
+ const result = this.#act({ ...input, ...(admittedTurnId ? { coordinationTurnId: admittedTurnId } : {}) }, fingerprint, context);
74
80
  const action = { requestFingerprint, result };
75
81
  this.#actions.set(input.actionId, action);
76
82
  // Successful actions remain a Host-lifetime fast path. Rejections release
@@ -87,12 +93,6 @@ export class WorkHubCoordinationActionGate {
87
93
  }
88
94
  async #act(input, fingerprint, context) {
89
95
  const proposal = input.proposal;
90
- const requestIntent = readWorkHubRequestIntent(input.userText);
91
- if (requestIntent.execution === 'ambiguous' &&
92
- proposal.disposition !== 'answer_here' &&
93
- proposal.disposition !== 'clarify') {
94
- throw new WorkHubActionGateFailure('action_conflict', 'WorkHub cannot write from an ambiguous instruction');
95
- }
96
96
  const durable = await this.#effects.readAssignment(input.actionId);
97
97
  if (durable) {
98
98
  const replayFingerprint = durable.replacesActionId
@@ -106,26 +106,7 @@ export class WorkHubCoordinationActionGate {
106
106
  }
107
107
  return this.#assign(assignmentInputFromRecord(durable), context);
108
108
  }
109
- if (proposal.disposition === 'answer_here') {
110
- const turnId = coordinationTurnId(input.actionId, 'answer');
111
- await this.#claimAction(input.actionId, 'answer_here', fingerprint, turnId);
112
- await this.#effects.answer({ turnId, text: input.userText }, context);
113
- return { disposition: 'answer_here', coordinationTurnId: turnId };
114
- }
115
- if (proposal.disposition === 'clarify') {
116
- const turnId = coordinationTurnId(input.actionId, 'clarify');
117
- await this.#claimAction(input.actionId, 'clarify', fingerprint, turnId);
118
- await this.#effects.clarify({
119
- turnId,
120
- userText: input.userText,
121
- assistantText: proposal.assistantText,
122
- });
123
- return { disposition: 'clarify', coordinationTurnId: turnId };
124
- }
125
109
  if (proposal.disposition === 'stop_work') {
126
- if (input.confirmation?.kind !== 'user_stop' || !requestIntent.stop.imperative) {
127
- throw new WorkHubActionGateFailure('action_conflict', 'WorkHub stop requires an explicit named command in trusted user text');
128
- }
129
110
  const source = await this.#stopSource(input.actionId, proposal.expects.targetSessionId);
130
111
  const stopFingerprint = stopActionFingerprint(input, source);
131
112
  await this.#claimAction(input.actionId, 'stop', stopFingerprint, source.delegationId);
@@ -167,6 +148,7 @@ export class WorkHubCoordinationActionGate {
167
148
  }
168
149
  const requested = await this.#effects.prepareStop({
169
150
  actionId: input.actionId,
151
+ coordinationTurnId: input.coordinationTurnId,
170
152
  actionFingerprint: stopFingerprint,
171
153
  stopsActionId: source.actionId,
172
154
  stopsDelegationId: source.delegationId,
@@ -178,36 +160,33 @@ export class WorkHubCoordinationActionGate {
178
160
  return this.#stop(requested, source);
179
161
  }
180
162
  if (proposal.disposition === 'resume_work') {
181
- if (!requestIntent.resume.imperative) {
182
- throw new WorkHubActionGateFailure('action_conflict', 'WorkHub resume requires an explicit named command in trusted user text');
183
- }
184
- const candidates = await this.candidates();
185
- const target = candidates.candidates.find((candidate) => candidate.sessionId === proposal.expects.targetSessionId);
186
- if (!target)
187
- throw new WorkHubActionGateFailure('candidate_unavailable', 'WorkHub resume target is unavailable');
188
- this.#assertTarget(target);
189
- const source = await this.#soleWorkingDelegation(target.sessionId, 'resume');
190
- if (source.actionId !== proposal.resumesActionId) {
163
+ const source = await this.#effects.readAssignment(proposal.resumesActionId);
164
+ if (!source || source.targetSessionId !== proposal.expects.targetSessionId) {
191
165
  throw new WorkHubActionGateFailure('action_conflict', 'WorkHub resume target delegation changed');
192
166
  }
193
- const currentTargetName = target.sessionName;
194
- if (!currentTargetName ||
195
- !workHubNamedDelegationActionTargetsSession(requestIntent.resume, currentTargetName)) {
196
- throw new WorkHubActionGateFailure('action_conflict', 'WorkHub resume target is not affirmed in trusted user text');
197
- }
198
- return this.#effects.resume({ actionId: input.actionId, source }, context);
167
+ const validateFreshTarget = async () => {
168
+ const candidates = await this.candidates();
169
+ const target = candidates.candidates.find((candidate) => candidate.sessionId === proposal.expects.targetSessionId);
170
+ if (!target)
171
+ throw new WorkHubActionGateFailure('candidate_unavailable', 'WorkHub resume target is unavailable');
172
+ this.#assertTarget(target);
173
+ const current = await this.#soleWorkingDelegation(target.sessionId, 'resume');
174
+ if (current.actionId !== source.actionId) {
175
+ throw new WorkHubActionGateFailure('action_conflict', 'WorkHub resume target delegation changed');
176
+ }
177
+ if (!target.sessionName)
178
+ throw new WorkHubActionGateFailure('action_conflict', 'WorkHub resume target is unavailable');
179
+ };
180
+ return this.#effects.resume({ actionId: input.actionId, source, validateFreshTarget }, context);
199
181
  }
200
182
  if (proposal.disposition === 'create_new') {
201
- if (!input.create || !workHubCreationAuthorizesTitle(requestIntent, proposal.title)) {
202
- throw new WorkHubActionGateFailure('action_conflict', 'WorkHub creation requires an unambiguous instruction and creation context');
183
+ if (!input.create) {
184
+ throw new WorkHubActionGateFailure('action_conflict', 'WorkHub creation context is unavailable');
203
185
  }
204
186
  const sessionId = workHubCreatedSessionId(input.actionId);
205
187
  return this.#assign(delegationAssignment(input, fingerprint, sessionId, proposal.title), context);
206
188
  }
207
189
  if (proposal.disposition === 'replace') {
208
- if (input.confirmation?.kind !== 'user_correction' || !requestIntent.correction.cue) {
209
- throw new WorkHubActionGateFailure('action_conflict', 'WorkHub replacement requires explicit correction in trusted user text');
210
- }
211
190
  const replaced = await this.#effects.readAssignment(proposal.replacesActionId);
212
191
  if (!replaced) {
213
192
  throw new WorkHubActionGateFailure('action_conflict', 'WorkHub can replace only a durable delegation it owns');
@@ -217,9 +196,6 @@ export class WorkHubCoordinationActionGate {
217
196
  }
218
197
  const prepared = await this.#effects.readReplacement(replaced.delegationId);
219
198
  if (prepared) {
220
- if (!isExplicitWorkHubCorrectionText(input.userText, prepared.disposition, prepared.targetSessionName)) {
221
- throw new WorkHubActionGateFailure('action_conflict', 'WorkHub replacement target is not affirmed in trusted user text');
222
- }
223
199
  if (prepared.actionId !== input.actionId ||
224
200
  prepared.actionFingerprint !==
225
201
  replacementActionFingerprint(input, prepared.targetSessionId)) {
@@ -370,21 +346,25 @@ export class WorkHubCoordinationActionGate {
370
346
  }
371
347
  const target = input.proposal.target;
372
348
  if (target.disposition === 'create_new') {
373
- if (!isExplicitWorkHubCorrectionText(input.userText, 'create_new', target.title)) {
374
- throw new WorkHubActionGateFailure('action_conflict', 'WorkHub replacement creation requires explicit non-negated user intent');
375
- }
376
349
  if (!input.create) {
377
350
  throw new WorkHubActionGateFailure('action_conflict', 'WorkHub replacement creation context is unavailable');
378
351
  }
379
352
  const targetSessionId = workHubCreatedSessionId(input.actionId);
380
353
  return {
381
354
  actionId: input.actionId,
355
+ coordinationTurnId: input.coordinationTurnId,
382
356
  actionFingerprint: replacementActionFingerprint(input, targetSessionId),
383
357
  targetSessionId,
384
358
  targetSessionName: target.title,
385
359
  disposition: 'create_new',
386
360
  userText: input.userText,
387
- create: { title: target.title, workspace: input.create.workspace },
361
+ ...(input.attachments ? { attachments: input.attachments } : {}),
362
+ ...(input.delegationText === undefined ? {} : { delegationText: input.delegationText }),
363
+ create: {
364
+ title: target.title,
365
+ workspace: input.create.workspace,
366
+ ...(input.newWorkDefaults ? { defaults: input.newWorkDefaults } : {}),
367
+ },
388
368
  replacesActionId: replaced.actionId,
389
369
  replacesDelegationId: replaced.delegationId,
390
370
  replacedTargetSessionId: replaced.targetSessionId,
@@ -400,19 +380,19 @@ export class WorkHubCoordinationActionGate {
400
380
  throw new WorkHubActionGateFailure('candidate_unavailable', 'WorkHub replacement target is not in the admitted candidate set');
401
381
  }
402
382
  this.#assertTarget(destination);
403
- if (!isExplicitWorkHubCorrectionText(input.userText, 'delegate_existing', destination.sessionName)) {
404
- throw new WorkHubActionGateFailure('action_conflict', 'WorkHub replacement target is not affirmed in trusted user text');
405
- }
406
383
  if (destination.sessionId === replaced.targetSessionId) {
407
384
  throw new WorkHubActionGateFailure('action_conflict', 'WorkHub replacement must choose a different Session');
408
385
  }
409
386
  return {
410
387
  actionId: input.actionId,
388
+ coordinationTurnId: input.coordinationTurnId,
411
389
  actionFingerprint: replacementActionFingerprint(input, destination.sessionId),
412
390
  targetSessionId: destination.sessionId,
413
391
  targetSessionName: destination.sessionName,
414
392
  disposition: 'delegate_existing',
415
393
  userText: input.userText,
394
+ ...(input.attachments ? { attachments: input.attachments } : {}),
395
+ ...(input.delegationText === undefined ? {} : { delegationText: input.delegationText }),
416
396
  replacesActionId: replaced.actionId,
417
397
  replacesDelegationId: replaced.delegationId,
418
398
  replacedTargetSessionId: replaced.targetSessionId,
@@ -599,9 +579,6 @@ function isCandidateSession(session) {
599
579
  function candidateRef(candidateSetId, sessionId) {
600
580
  return `whc_${hash(`${candidateSetId}\0${sessionId}`).slice(0, 48)}`;
601
581
  }
602
- function coordinationTurnId(actionId, kind) {
603
- return `wha_${hash(`${actionId}\0${kind}`).slice(0, 48)}`;
604
- }
605
582
  function delegationAssignment(input, actionFingerprint, targetSessionId, targetSessionName) {
606
583
  const create = input.create;
607
584
  if (input.proposal.disposition !== 'delegate_existing' &&
@@ -610,11 +587,14 @@ function delegationAssignment(input, actionFingerprint, targetSessionId, targetS
610
587
  }
611
588
  const base = {
612
589
  actionId: input.actionId,
590
+ coordinationTurnId: input.coordinationTurnId ?? input.actionId,
613
591
  actionFingerprint,
614
592
  targetSessionId,
615
593
  targetSessionName,
616
594
  disposition: input.proposal.disposition,
617
595
  userText: input.userText,
596
+ ...(input.attachments ? { attachments: input.attachments } : {}),
597
+ ...(input.delegationText === undefined ? {} : { delegationText: input.delegationText }),
618
598
  };
619
599
  if (input.proposal.disposition === 'delegate_existing')
620
600
  return base;
@@ -626,6 +606,7 @@ function delegationAssignment(input, actionFingerprint, targetSessionId, targetS
626
606
  create: {
627
607
  title: input.proposal.title,
628
608
  workspace: create.workspace,
609
+ ...(input.newWorkDefaults ? { defaults: input.newWorkDefaults } : {}),
629
610
  },
630
611
  };
631
612
  }
@@ -657,6 +638,9 @@ function digest(value) {
657
638
  function actionFingerprint(input) {
658
639
  return digest({
659
640
  userText: input.userText,
641
+ ...(input.attachments ? { attachments: input.attachments } : {}),
642
+ ...(input.newWorkDefaults ? { newWorkDefaults: input.newWorkDefaults } : {}),
643
+ ...(input.delegationText === undefined ? {} : { delegationText: input.delegationText }),
660
644
  disposition: input.proposal.disposition,
661
645
  ...(input.proposal.disposition === 'delegate_existing'
662
646
  ? { candidateRef: input.proposal.candidateRef }
@@ -667,9 +651,6 @@ function actionFingerprint(input) {
667
651
  workspace: input.create?.workspace,
668
652
  }
669
653
  : {}),
670
- ...(input.proposal.disposition === 'clarify'
671
- ? { assistantText: input.proposal.assistantText }
672
- : {}),
673
654
  ...(input.proposal.disposition === 'replace'
674
655
  ? {
675
656
  replacesActionId: input.proposal.replacesActionId,
@@ -687,6 +668,9 @@ function replacementActionFingerprint(input, targetSessionId) {
687
668
  }
688
669
  return digest({
689
670
  userText: input.userText,
671
+ ...(input.attachments ? { attachments: input.attachments } : {}),
672
+ ...(input.newWorkDefaults ? { newWorkDefaults: input.newWorkDefaults } : {}),
673
+ ...(input.delegationText === undefined ? {} : { delegationText: input.delegationText }),
690
674
  disposition: input.proposal.disposition,
691
675
  replacesActionId: input.proposal.replacesActionId,
692
676
  target: {
@@ -742,11 +726,16 @@ function stopResultFromRecord(resolution, request) {
742
726
  function assignmentInputFromRecord(assignment) {
743
727
  return {
744
728
  actionId: assignment.actionId,
729
+ coordinationTurnId: assignment.coordinationTurnId,
745
730
  actionFingerprint: assignment.actionFingerprint,
746
731
  targetSessionId: assignment.targetSessionId,
747
732
  targetSessionName: assignment.targetSessionName,
748
733
  disposition: assignment.disposition,
749
734
  userText: assignment.userText,
735
+ ...(assignment.attachments ? { attachments: assignment.attachments } : {}),
736
+ ...(assignment.delegationText === undefined
737
+ ? {}
738
+ : { delegationText: assignment.delegationText }),
750
739
  ...(assignment.create ? { create: assignment.create } : {}),
751
740
  ...(assignment.replacesActionId && assignment.replacesDelegationId
752
741
  ? {
@@ -759,11 +748,16 @@ function assignmentInputFromRecord(assignment) {
759
748
  function assignmentInputFromReplacement(replacement) {
760
749
  return {
761
750
  actionId: replacement.actionId,
751
+ coordinationTurnId: replacement.coordinationTurnId,
762
752
  actionFingerprint: replacement.actionFingerprint,
763
753
  targetSessionId: replacement.targetSessionId,
764
754
  targetSessionName: replacement.targetSessionName,
765
755
  disposition: replacement.disposition,
766
756
  userText: replacement.userText,
757
+ ...(replacement.attachments ? { attachments: replacement.attachments } : {}),
758
+ ...(replacement.delegationText === undefined
759
+ ? {}
760
+ : { delegationText: replacement.delegationText }),
767
761
  ...(replacement.create ? { create: replacement.create } : {}),
768
762
  replacesActionId: replacement.replacesActionId,
769
763
  replacesDelegationId: replacement.replacesDelegationId,
@@ -772,20 +766,3 @@ function assignmentInputFromReplacement(replacement) {
772
766
  function hash(value) {
773
767
  return createHash('sha256').update(value, 'utf8').digest('hex');
774
768
  }
775
- /**
776
- * Destructive replacement needs evidence in the user-originated text itself;
777
- * a strategy-provided replacement proposal and confirmation marker are not
778
- * sufficient authority. Keep this deliberately narrower than route inference.
779
- */
780
- export function isExplicitWorkHubCorrectionText(value, targetDisposition, targetSessionName) {
781
- const intent = readWorkHubRequestIntent(value);
782
- if (targetDisposition === 'create_new') {
783
- return Boolean(intent.correction.cue &&
784
- intent.creation.explicit &&
785
- targetSessionName &&
786
- workHubCreationAuthorizesTitle(intent, targetSessionName));
787
- }
788
- return Boolean(targetSessionName &&
789
- intent.correction.cue &&
790
- workHubCorrectionTargetsSession(intent, targetSessionName));
791
- }