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

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 (110) hide show
  1. package/dist/cli-core.js +21 -0
  2. package/dist/mcp-capability-provider.js +4 -1
  3. package/dist/pi-tui-mcp-status.js +2 -2
  4. package/dist/pi-tui-pickers.js +19 -29
  5. package/dist/runtime-host-cli.js +43 -3
  6. package/dist/runtime-host-handoff-surface.js +10 -8
  7. package/dist/runtime-host-lifecycle-transaction.js +28 -3
  8. package/dist/runtime-host-local-source-retirement.js +1 -1
  9. package/dist/runtime-host-setup-command.js +29 -6
  10. package/dist/runtime-host-update-command.js +49 -5
  11. package/dist/session-export-command.js +72 -0
  12. package/dist/tui-autocomplete-layout.js +3 -1
  13. package/dist/tui-copy-catalog.js +6 -3
  14. package/dist/tui-editor-render.js +36 -0
  15. package/dist/tui-mcp-control.js +41 -6
  16. package/native/runtime-host-windows-task-launcher/prebuilds/win32-x64/maka-runtime-host-task-launcher.exe +0 -0
  17. package/node_modules/@maka/core/dist/runtime-event.js +3 -0
  18. package/node_modules/@maka/core/dist/session.js +29 -4
  19. package/node_modules/@maka/core/dist/usage-stats/types.js +2 -0
  20. package/node_modules/@maka/core/dist/workhub-action-result.js +68 -0
  21. package/node_modules/@maka/core/dist/workhub-routing.js +126 -0
  22. package/node_modules/@maka/core/package.json +3 -3
  23. package/node_modules/@maka/eval/dist/toolchain-verification.js +1 -1
  24. package/node_modules/@maka/mcp/dist/form-elicitation.js +213 -0
  25. package/node_modules/@maka/mcp/dist/index.js +337 -71
  26. package/node_modules/@maka/runtime/dist/agent-run.js +10 -1
  27. package/node_modules/@maka/runtime/dist/ai-sdk-turn.js +7 -3
  28. package/node_modules/@maka/runtime/dist/builtin-tools.js +21 -2
  29. package/node_modules/@maka/runtime/dist/goal-continuation.js +5 -1
  30. package/node_modules/@maka/runtime/dist/plugin-agent-service.js +131 -0
  31. package/node_modules/@maka/runtime/dist/plugin-approval-service.js +33 -0
  32. package/node_modules/@maka/runtime/dist/plugin-attachment-service.js +53 -0
  33. package/node_modules/@maka/runtime/dist/plugin-command-service.js +100 -0
  34. package/node_modules/@maka/runtime/dist/plugin-data-services.js +332 -0
  35. package/node_modules/@maka/runtime/dist/plugin-fs-service.js +62 -0
  36. package/node_modules/@maka/runtime/dist/plugin-goal-service.js +61 -0
  37. package/node_modules/@maka/runtime/dist/plugin-invocation-signal.js +24 -0
  38. package/node_modules/@maka/runtime/dist/plugin-llm-service.js +85 -0
  39. package/node_modules/@maka/runtime/dist/plugin-lsp-service.js +94 -0
  40. package/node_modules/@maka/runtime/dist/plugin-scope-registry.js +91 -0
  41. package/node_modules/@maka/runtime/dist/plugin-session-query-service.js +71 -0
  42. package/node_modules/@maka/runtime/dist/plugin-shell-env-service.js +87 -0
  43. package/node_modules/@maka/runtime/dist/plugin-shell-service.js +74 -0
  44. package/node_modules/@maka/runtime/dist/plugin-skill-service.js +93 -0
  45. package/node_modules/@maka/runtime/dist/plugin-system-prompt-service.js +346 -0
  46. package/node_modules/@maka/runtime/dist/plugin-tool-service.js +18 -52
  47. package/node_modules/@maka/runtime/dist/plugin-user-question-service.js +43 -0
  48. package/node_modules/@maka/runtime/dist/plugin-web-service.js +69 -0
  49. package/node_modules/@maka/runtime/dist/runtime-event-read-model.js +20 -1
  50. package/node_modules/@maka/runtime/dist/runtime-kernel.js +120 -13
  51. package/node_modules/@maka/runtime/dist/session-export.js +177 -0
  52. package/node_modules/@maka/runtime/dist/session-manager.js +20 -36
  53. package/node_modules/@maka/runtime/package.json +18 -0
  54. package/node_modules/@maka/runtime-host/dist/client/connection.js +30 -5
  55. package/node_modules/@maka/runtime-host/dist/client/host-handoff-copy.js +83 -18
  56. package/node_modules/@maka/runtime-host/dist/client/host-handoff.js +46 -12
  57. package/node_modules/@maka/runtime-host/dist/client/host-retirement.js +4 -2
  58. package/node_modules/@maka/runtime-host/dist/client/peer-client.js +18 -1
  59. package/node_modules/@maka/runtime-host/dist/operator/setup-frame.js +31 -21
  60. package/node_modules/@maka/runtime-host/dist/protocol/index.js +13 -1
  61. package/node_modules/@maka/runtime-host/dist/protocol/operations.js +3 -2
  62. package/node_modules/@maka/runtime-host/dist/protocol/plugin-platform.js +30 -5
  63. package/node_modules/@maka/runtime-host/dist/protocol/session-continuity.js +1 -0
  64. package/node_modules/@maka/runtime-host/dist/protocol/workhub-coordination.js +90 -188
  65. package/node_modules/@maka/runtime-host/dist/server/access-credential-store.js +4 -0
  66. package/node_modules/@maka/runtime-host/dist/server/canonical-session-projection.js +2 -1
  67. package/node_modules/@maka/runtime-host/dist/server/client-capability-coordinator.js +62 -4
  68. package/node_modules/@maka/runtime-host/dist/server/connection-session.js +28 -8
  69. package/node_modules/@maka/runtime-host/dist/server/daily-review-coordinator.js +112 -56
  70. package/node_modules/@maka/runtime-host/dist/server/execution-composition.js +497 -27
  71. package/node_modules/@maka/runtime-host/dist/server/execution-model-authority.js +74 -0
  72. package/node_modules/@maka/runtime-host/dist/server/failure-diagnostic.js +24 -0
  73. package/node_modules/@maka/runtime-host/dist/server/goal-coordinator.js +7 -3
  74. package/node_modules/@maka/runtime-host/dist/server/host-kernel.js +3 -3
  75. package/node_modules/@maka/runtime-host/dist/server/host-session-availability.js +5 -2
  76. package/node_modules/@maka/runtime-host/dist/server/hosted-execution-recovery.js +4 -3
  77. package/node_modules/@maka/runtime-host/dist/server/hosted-execution-tool-profile.js +64 -4
  78. package/node_modules/@maka/runtime-host/dist/server/interactive-run-composer.js +83 -17
  79. package/node_modules/@maka/runtime-host/dist/server/message-coordinator.js +25 -4
  80. package/node_modules/@maka/runtime-host/dist/server/operation-dispatcher.js +2 -7
  81. package/node_modules/@maka/runtime-host/dist/server/plugin-data-runtime.js +234 -0
  82. package/node_modules/@maka/runtime-host/dist/server/plugin-platform-coordinator.js +6 -0
  83. package/node_modules/@maka/runtime-host/dist/server/plugin-platform.js +12 -0
  84. package/node_modules/@maka/runtime-host/dist/server/root-turn-coordinator.js +289 -96
  85. package/node_modules/@maka/runtime-host/dist/server/runtime-resource-coordinator.js +11 -8
  86. package/node_modules/@maka/runtime-host/dist/server/scheduled-task-coordinator.js +31 -21
  87. package/node_modules/@maka/runtime-host/dist/server/serial-outbound-writer.js +1 -1
  88. package/node_modules/@maka/runtime-host/dist/server/session-catalog-coordinator.js +20 -8
  89. package/node_modules/@maka/runtime-host/dist/server/session-transcript-reader.js +15 -104
  90. package/node_modules/@maka/runtime-host/dist/server/shared-session-transcript.js +3 -0
  91. package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-action-gate.js +85 -117
  92. package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-coordinator.js +201 -136
  93. package/node_modules/@maka/storage/dist/agent-run-store.js +60 -3
  94. package/node_modules/@maka/storage/dist/artifact-store.js +40 -3
  95. package/node_modules/@maka/storage/dist/atomic-file-write.js +74 -0
  96. package/node_modules/@maka/storage/dist/context-offload-snapshot.js +13 -6
  97. package/node_modules/@maka/storage/dist/credential-store.js +12 -63
  98. package/node_modules/@maka/storage/dist/execution-stores.js +5 -2
  99. package/node_modules/@maka/storage/dist/mcp-config-store.js +10 -25
  100. package/node_modules/@maka/storage/dist/session-bundle-policy.js +333 -30
  101. package/node_modules/@maka/storage/dist/session-store.js +16 -4
  102. package/node_modules/@maka/storage/dist/settings-store.js +8 -4
  103. package/node_modules/@maka/storage/dist/sqlite-artifact-metadata.js +11 -0
  104. package/node_modules/@maka/storage/dist/sqlite-session-metadata-schema.js +12 -1
  105. package/node_modules/@maka/storage/dist/sqlite-session-metadata-store.js +79 -8
  106. package/node_modules/@maka/storage/dist/stable-storage.js +14 -1
  107. package/node_modules/@maka/storage/package.json +2 -0
  108. package/package.json +1 -1
  109. package/node_modules/@maka/core/dist/workhub-creation-intent.js +0 -990
  110. package/node_modules/@maka/core/dist/workhub-session-resolver.js +0 -50
@@ -22,6 +22,7 @@ export function formatHostHandoff(view, locale) {
22
22
  const tw = locale === 'zh-TW';
23
23
  const titles = tw
24
24
  ? {
25
+ replacement_required: '需要切換 WSL 背景服務',
25
26
  busy: '背景服務仍在使用中',
26
27
  activity_unknown: '需要確認是否停止背景服務',
27
28
  operator_required: '背景服務需要手動更新',
@@ -30,6 +31,7 @@ export function formatHostHandoff(view, locale) {
30
31
  }
31
32
  : zh
32
33
  ? {
34
+ replacement_required: '需要切换 WSL 后台服务',
33
35
  busy: '后台服务仍在使用中',
34
36
  activity_unknown: '需要确认是否停止后台服务',
35
37
  operator_required: '后台服务需要手动更新',
@@ -37,6 +39,7 @@ export function formatHostHandoff(view, locale) {
37
39
  retry_required: '暂时无法完成交接',
38
40
  }
39
41
  : {
42
+ replacement_required: 'Switch the WSL background service',
40
43
  busy: 'Your background service is still in use',
41
44
  activity_unknown: 'Confirm before stopping the service',
42
45
  operator_required: 'The background service needs a manual update',
@@ -45,6 +48,7 @@ export function formatHostHandoff(view, locale) {
45
48
  };
46
49
  const descriptions = tw
47
50
  ? {
51
+ replacement_required: '目前尚未更新。選擇繼續後,將透過已安裝的管理程式安全停止舊服務並啟動選定版本;有進行中的工作時會另行確認。',
48
52
  busy: '其他連線或正在執行的工作阻止了自動交接。停止並繼續可能中斷這些工作。',
49
53
  activity_unknown: '背景服務與目前用戶端不相容,且無法確認有哪些工作仍在執行。停止並繼續會重新啟動服務,可能中斷其他視窗或裝置上的工作。',
50
54
  operator_required: `目前無法從這裡更新背景服務。請透過 ${view.target.name} 上管理此服務的應用程式或命令更新,再重試。`,
@@ -53,6 +57,7 @@ export function formatHostHandoff(view, locale) {
53
57
  }
54
58
  : zh
55
59
  ? {
60
+ replacement_required: '当前尚未更新。选择继续后,将通过已安装的管理程序安全停止旧服务并启动选定版本;有活动工作时会另行确认。',
56
61
  busy: '其它连接或正在执行的工作阻止了自动交接。停止并继续可能中断这些工作。',
57
62
  activity_unknown: '后台服务与当前客户端不兼容,且无法确认有哪些工作仍在运行。停止并继续会重新启动服务,可能中断其他窗口或设备上的工作。',
58
63
  operator_required: `目前无法从这里更新后台服务。请通过 ${view.target.name} 上管理此服务的应用或命令更新,然后重试。`,
@@ -60,6 +65,7 @@ export function formatHostHandoff(view, locale) {
60
65
  retry_required: '服务状态发生了变化,或交接尚未完成。可以安全重试,不会默认中断工作。',
61
66
  }
62
67
  : {
68
+ replacement_required: 'No update is running. Continue to retire the old service through its installed operator and start the selected version. Interrupting active work requires a separate confirmation.',
63
69
  busy: 'Other connections or work in progress prevent an automatic handoff. Stopping the service may interrupt that work.',
64
70
  activity_unknown: 'The background service is incompatible with this client, and its active work is unknown. Stop and continue restarts it and may interrupt work in other windows or devices.',
65
71
  operator_required: `This client cannot update the background service here. Use its managing app or operator command on ${view.target.name}, then retry.`,
@@ -89,7 +95,43 @@ export function formatHostHandoff(view, locale) {
89
95
  };
90
96
  descriptions.operator_required = guidance[view.recoveryBlocker];
91
97
  }
98
+ if (view.manualRecheck && view.reason === 'busy') {
99
+ descriptions.busy = zh
100
+ ? tw
101
+ ? '舊服務拒絕安全停止;這可能是其他連線或背景工作所致。關閉其他用戶端後可再次嘗試安全停止,或明確選擇中斷工作並繼續。'
102
+ : '旧服务拒绝安全停止;这可能是其他连接或后台工作所致。关闭其他客户端后可再次尝试安全停止,或明确选择中断工作并继续。'
103
+ : 'The old service refused safe retirement. Other connections or background work may be keeping it in use. Close other clients and try stopping safely again, or explicitly interrupt work and continue.';
104
+ }
105
+ if (view.manualRecheck && view.reason === 'operator_required') {
106
+ titles.operator_required = zh
107
+ ? tw
108
+ ? '無法連線到背景服務'
109
+ : '无法连接后台服务'
110
+ : 'Cannot connect to the background service';
111
+ descriptions.operator_required = zh
112
+ ? tw
113
+ ? '目前版本無法連線,且尚未執行更新。請查看診斷或更新用戶端,完成後重新檢查。'
114
+ : '当前版本无法连接,且尚未执行更新。请查看诊断或更新客户端,完成后重新检查。'
115
+ : 'These builds cannot connect and no update is running. Check the diagnostic or update the client, then recheck.';
116
+ }
117
+ const packageChange = view.packageChange
118
+ ? `${view.target.name}: ${view.packageChange.current} → ${view.packageChange.target}`
119
+ : '';
92
120
  const activity = view.activity;
121
+ const background = activity?.drainResidencies;
122
+ const backgroundFacts = !activity
123
+ ? ''
124
+ : background !== undefined
125
+ ? tw
126
+ ? `${background} 個背景工作`
127
+ : zh
128
+ ? `${background} 个后台工作`
129
+ : `${background} background activities`
130
+ : tw
131
+ ? '背景工作數量未知'
132
+ : zh
133
+ ? '后台工作数量未知'
134
+ : 'Background activity count unknown';
93
135
  const facts = activity
94
136
  ? tw
95
137
  ? `${activity.connections} 個連線 · ${activity.activeOperations} 個進行中的操作`
@@ -97,17 +139,23 @@ export function formatHostHandoff(view, locale) {
97
139
  ? `${activity.connections} 个连接 · ${activity.activeOperations} 个进行中的操作`
98
140
  : `${activity.connections} connections · ${activity.activeOperations} operations in progress`
99
141
  : '';
100
- const waiting = view.mayExitNaturally
101
- ? tw
102
- ? 'Maka 會持續檢查,並在可以安全繼續時自動繼續。'
103
- : zh
104
- ? 'Maka 会持续检查,并在可以安全继续时自动继续。'
105
- : 'Maka keeps checking and continues automatically when it is safe.'
106
- : tw
107
- ? 'Maka 會持續檢查。若狀態沒有改變,等待或重試不會解決此問題。'
108
- : zh
109
- ? 'Maka 会持续检查。若状态没有变化,等待或重试不会解决此问题。'
110
- : 'Maka keeps checking. Waiting or retrying will not resolve this unless the service state changes.';
142
+ const waiting = view.manualRecheck
143
+ ? zh
144
+ ? tw
145
+ ? '重新檢查只會重試連線,不會更新服務。'
146
+ : '重新检查只会重试连接,不会更新服务。'
147
+ : 'Recheck retries the connection without updating the service.'
148
+ : view.mayExitNaturally
149
+ ? tw
150
+ ? 'Maka 會持續檢查,並在可以安全繼續時自動繼續。'
151
+ : zh
152
+ ? 'Maka 会持续检查,并在可以安全继续时自动继续。'
153
+ : 'Maka keeps checking and continues automatically when it is safe.'
154
+ : tw
155
+ ? 'Maka 會持續檢查。若狀態沒有改變,等待或重試不會解決此問題。'
156
+ : zh
157
+ ? 'Maka 会持续检查。若状态没有变化,等待或重试不会解决此问题。'
158
+ : 'Maka keeps checking. Waiting or retrying will not resolve this unless the service state changes.';
111
159
  const repairNotice = view.operation === 'repair'
112
160
  ? tw
113
161
  ? '修復將使用目前應用程式配套的版本,可能替換現有服務版本。'
@@ -118,19 +166,34 @@ export function formatHostHandoff(view, locale) {
118
166
  const labels = tw
119
167
  ? {
120
168
  cancel: '取消',
121
- retry: '安全重試',
122
- interrupt: view.operation === 'repair' ? '中斷並修復' : '停止並繼續',
169
+ retry: view.manualRecheck ? '重新檢查' : '安全重試',
170
+ replace: '停止舊服務並繼續',
171
+ interrupt: view.manualRecheck
172
+ ? '中斷工作並繼續'
173
+ : view.operation === 'repair'
174
+ ? '中斷並修復'
175
+ : '停止並繼續',
123
176
  }
124
177
  : zh
125
178
  ? {
126
179
  cancel: '取消',
127
- retry: '安全重试',
128
- interrupt: view.operation === 'repair' ? '中断并修复' : '停止并继续',
180
+ retry: view.manualRecheck ? '重新检查' : '安全重试',
181
+ replace: '停止旧服务并继续',
182
+ interrupt: view.manualRecheck
183
+ ? '中断工作并继续'
184
+ : view.operation === 'repair'
185
+ ? '中断并修复'
186
+ : '停止并继续',
129
187
  }
130
188
  : {
131
189
  cancel: 'Cancel',
132
- retry: 'Retry safely',
133
- interrupt: view.operation === 'repair' ? 'Interrupt and repair' : 'Stop and continue',
190
+ retry: view.manualRecheck ? 'Recheck' : 'Retry safely',
191
+ replace: 'Stop old service and continue',
192
+ interrupt: view.manualRecheck
193
+ ? 'Interrupt work and continue'
194
+ : view.operation === 'repair'
195
+ ? 'Interrupt and repair'
196
+ : 'Stop and continue',
134
197
  };
135
198
  const phases = tw
136
199
  ? {
@@ -173,7 +236,9 @@ export function formatHostHandoff(view, locale) {
173
236
  : zh
174
237
  ? '正在完成交接或安全收尾,请稍候。'
175
238
  : 'Finishing the handoff or its safe recovery. Please wait.'
176
- : [facts, waiting, repairNotice, view.operatorStep].filter(Boolean).join('\n'),
239
+ : [packageChange, facts, backgroundFacts, waiting, repairNotice, view.operatorStep]
240
+ .filter(Boolean)
241
+ .join('\n'),
177
242
  actions: view.actions.map((action) => ({ action, label: labels[action] })),
178
243
  };
179
244
  }
@@ -55,6 +55,8 @@ export async function runHostHandoff(input) {
55
55
  // (or a broken successor) into an automatic replacement storm.
56
56
  const attempted = new Set();
57
57
  let automaticAttempts = 0;
58
+ let refusedWork;
59
+ let replacementCompleted = false;
58
60
  let recovery;
59
61
  const publish = (next) => {
60
62
  view = next;
@@ -102,7 +104,10 @@ export async function runHostHandoff(input) {
102
104
  target: view.target,
103
105
  reason: 'unavailable',
104
106
  mayExitNaturally: false,
105
- diagnostic: boundedDiagnostic(error),
107
+ ...(view.manualRecheck ? { manualRecheck: true } : {}),
108
+ diagnostic: replacementCompleted
109
+ ? `Host replacement completed, but reconnection failed: ${boundedDiagnostic(error)}`
110
+ : boundedDiagnostic(error),
106
111
  },
107
112
  };
108
113
  }
@@ -124,11 +129,13 @@ export async function runHostHandoff(input) {
124
129
  const blocker = observed.blocker;
125
130
  if (recovery?.identity !== blocker.identity)
126
131
  recovery = undefined;
132
+ if (refusedWork !== blocker.identity)
133
+ refusedWork = undefined;
127
134
  const nextSignature = blockerSignature(blocker);
128
135
  if (signature !== nextSignature) {
129
136
  signature = nextSignature;
130
137
  choice = undefined;
131
- publish(projectBlocker(blocker, randomUUID(), recovery?.diagnostic));
138
+ publish(projectBlocker(blocker, randomUUID(), recovery?.diagnostic, refusedWork === blocker.identity));
132
139
  }
133
140
  const current = view;
134
141
  const selected = choice;
@@ -142,12 +149,19 @@ export async function runHostHandoff(input) {
142
149
  const automatic = !recovery &&
143
150
  automaticAttempts < 3 &&
144
151
  !attempted.has(nextSignature) &&
152
+ !blocker.replacement?.requiresExplicitSelection &&
145
153
  blocker.replacement?.canReplaceIdle &&
146
154
  blocker.activity &&
147
155
  (isHostActivityIdle(blocker.activity) || cooperative);
148
156
  const interrupt = selected?.revision === current.revision && selected.action === 'interrupt';
157
+ const replace = selected?.revision === current.revision && selected.action === 'replace';
149
158
  const retry = selected?.revision === current.revision && selected.action === 'retry';
150
- if ((automatic || interrupt || (retry && blocker.replacement?.canReplaceIdle)) &&
159
+ if ((automatic ||
160
+ interrupt ||
161
+ replace ||
162
+ (retry &&
163
+ !blocker.replacement?.requiresExplicitSelection &&
164
+ blocker.replacement?.canReplaceIdle)) &&
151
165
  blocker.replacement) {
152
166
  if (automatic) {
153
167
  attempted.add(nextSignature);
@@ -179,6 +193,8 @@ export async function runHostHandoff(input) {
179
193
  finally {
180
194
  attemptAbort = undefined;
181
195
  }
196
+ replacementCompleted = result.kind === 'completed';
197
+ refusedWork = result.kind === 'active_work' ? blocker.identity : undefined;
182
198
  recovery =
183
199
  result.kind === 'recovery_required'
184
200
  ? { identity: blocker.identity, diagnostic: result.diagnostic.slice(0, 8_192) }
@@ -195,7 +211,7 @@ export async function runHostHandoff(input) {
195
211
  signature = undefined;
196
212
  continue;
197
213
  }
198
- const attention = projectBlocker(blocker, current.revision, recovery?.diagnostic);
214
+ const attention = projectBlocker(blocker, current.revision, recovery?.diagnostic, refusedWork === blocker.identity);
199
215
  if (!input.openSurface)
200
216
  throw new HostHandoffRequiredError(attention);
201
217
  surface ??= input.openSurface(submit);
@@ -211,7 +227,7 @@ export async function runHostHandoff(input) {
211
227
  resolve();
212
228
  };
213
229
  const abort = () => finish(input.signal?.reason);
214
- const timer = setTimeout(finish, interval);
230
+ const timer = blocker.manualRecheck ? undefined : setTimeout(finish, interval);
215
231
  wake = () => finish();
216
232
  input.signal?.addEventListener('abort', abort, { once: true });
217
233
  if (input.signal?.aborted)
@@ -225,7 +241,7 @@ export async function runHostHandoff(input) {
225
241
  surface?.close();
226
242
  }
227
243
  }
228
- function projectBlocker(blocker, revision, recovery) {
244
+ function projectBlocker(blocker, revision, recovery, activeWorkRefused = false) {
229
245
  const replacement = blocker.replacement;
230
246
  return {
231
247
  revision,
@@ -237,15 +253,30 @@ function projectBlocker(blocker, revision, recovery) {
237
253
  ? 'repair_required'
238
254
  : !replacement
239
255
  ? 'operator_required'
240
- : !blocker.activity
241
- ? 'activity_unknown'
242
- : isHostActivityIdle(blocker.activity)
243
- ? 'retry_required'
244
- : 'busy',
256
+ : replacement.requiresExplicitSelection
257
+ ? activeWorkRefused
258
+ ? 'busy'
259
+ : 'replacement_required'
260
+ : !blocker.activity
261
+ ? 'activity_unknown'
262
+ : isHostActivityIdle(blocker.activity)
263
+ ? 'retry_required'
264
+ : 'busy',
245
265
  ...(blocker.activity ? { activity: blocker.activity } : {}),
246
266
  mayExitNaturally: blocker.mayExitNaturally,
267
+ ...(blocker.manualRecheck ? { manualRecheck: true } : {}),
268
+ ...(blocker.packageChange ? { packageChange: blocker.packageChange } : {}),
247
269
  ...(replacement ? { operation: replacement.kind } : {}),
248
- actions: replacement?.canInterrupt ? ['cancel', 'retry', 'interrupt'] : ['cancel', 'retry'],
270
+ actions: replacement?.requiresExplicitSelection
271
+ ? [
272
+ 'cancel',
273
+ 'retry',
274
+ 'replace',
275
+ ...(activeWorkRefused && replacement.canInterrupt ? ['interrupt'] : []),
276
+ ]
277
+ : replacement?.canInterrupt
278
+ ? ['cancel', 'retry', 'interrupt']
279
+ : ['cancel', 'retry'],
249
280
  defaultAction: 'cancel',
250
281
  ...(blocker.recoveryBlocker ? { recoveryBlocker: blocker.recoveryBlocker } : {}),
251
282
  ...(blocker.operatorStep ? { operatorStep: blocker.operatorStep } : {}),
@@ -265,6 +296,9 @@ function blockerSignature(blocker) {
265
296
  blocker.replacement?.kind,
266
297
  blocker.replacement?.canReplaceIdle,
267
298
  blocker.replacement?.canInterrupt,
299
+ blocker.replacement?.requiresExplicitSelection,
300
+ blocker.manualRecheck,
301
+ blocker.packageChange,
268
302
  blocker.operatorStep,
269
303
  blocker.recoveryBlocker,
270
304
  blocker.diagnostic,
@@ -23,7 +23,7 @@
23
23
  * transport detail here so lifecycle owners can model the operation as
24
24
  * retirement instead of spreading update-specific authority.
25
25
  */
26
- export async function prepareConnectedRuntimeHostRetirement(connection, mode, timeoutMs, signal) {
26
+ export async function prepareConnectedRuntimeHostRetirement(connection, mode, timeoutMs, signal, options) {
27
27
  signal?.throwIfAborted();
28
28
  // Retirement uses a dedicated lifecycle connection. Closing it cancels the
29
29
  // Host's reversible preparation; a committed retirement remains committed.
@@ -35,7 +35,9 @@ export async function prepareConnectedRuntimeHostRetirement(connection, mode, ti
35
35
  return await connection.request('host.upgrade.prepare', {
36
36
  expectedHostEpoch: connection.hostEpoch,
37
37
  allowInterruptActiveTasks: mode === 'interrupt_active_work',
38
- ...(mode === 'refuse_active_work' && connection.cooperativeHandoff
38
+ ...(mode === 'refuse_active_work' &&
39
+ connection.cooperativeHandoff &&
40
+ options?.allowCooperativeHandoff !== false
39
41
  ? { allowCooperativeHandoff: true }
40
42
  : {}),
41
43
  }, timeoutMs);
@@ -149,6 +149,23 @@ class RuntimeHostPeerClientImpl {
149
149
  };
150
150
  }
151
151
  subscribeRoutes(peerId, listener) {
152
+ const snapshot = () => this.#connectionResolution({ peerId, routeHints: [], directDeadlineMs: 0 }, 'application', false);
153
+ let previous = snapshot();
154
+ let connected = this.isConnected(peerId);
155
+ return this.#subscribeRouteResolution(peerId, () => {
156
+ const next = snapshot();
157
+ const nextConnected = this.isConnected(peerId);
158
+ const available = next.state === 'available' &&
159
+ (!sameCandidates(previous, next) || (nextConnected && !connected));
160
+ previous = next;
161
+ connected = nextConnected;
162
+ // A dial's own recovery sweep toggles recovering/exhausted. Waking its
163
+ // reconnect owner for those transitions would bypass every backoff.
164
+ if (available)
165
+ listener();
166
+ });
167
+ }
168
+ #subscribeRouteResolution(peerId, listener) {
152
169
  const listeners = this.#routeListeners.get(peerId) ?? new Set();
153
170
  const first = listeners.size === 0;
154
171
  listeners.add(listener);
@@ -362,7 +379,7 @@ class RuntimeHostPeerClientImpl {
362
379
  updateTail = updateTail.then(() => updatePeerConnect(endpoint, requestId, candidates, () => settled), () => updatePeerConnect(endpoint, requestId, candidates, () => settled));
363
380
  void updateTail.catch(() => undefined);
364
381
  };
365
- const unsubscribe = kind === 'application' ? this.subscribeRoutes(input.peerId, update) : undefined;
382
+ const unsubscribe = kind === 'application' ? this.#subscribeRouteResolution(input.peerId, update) : undefined;
366
383
  let connection;
367
384
  try {
368
385
  connection = endpoint[kind === 'application' ? 'connect' : 'connectMeshControl']({
@@ -41,6 +41,29 @@ const frameBase = {
41
41
  schemaVersion: z.literal(1),
42
42
  sequence: z.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER),
43
43
  };
44
+ const environmentBindingFields = {
45
+ version: boundedString(128),
46
+ serviceId: z.string().regex(/^[a-f0-9]{64}$/u),
47
+ deploymentId: z.string().uuid(),
48
+ operator: z.unknown().transform((value, context) => {
49
+ try {
50
+ const command = decodeRuntimeHostOperatorCommand(value);
51
+ if (command.kind !== 'node') {
52
+ throw new Error('Runtime Host setup operator must be a Node command');
53
+ }
54
+ return command;
55
+ }
56
+ catch (error) {
57
+ context.addIssue({
58
+ code: 'custom',
59
+ message: error instanceof Error ? error.message : 'Runtime Host operator is invalid',
60
+ });
61
+ return z.NEVER;
62
+ }
63
+ }),
64
+ rootPath: boundedString(4 * 1024).refine((value) => !/[\u0000-\u001f\u007f]/u.test(value)),
65
+ rootId: z.string().regex(/^[a-f0-9]{64}$/u),
66
+ };
44
67
  const SETUP_FRAME_SCHEMA = z.discriminatedUnion('kind', [
45
68
  z
46
69
  .object({
@@ -53,27 +76,7 @@ const SETUP_FRAME_SCHEMA = z.discriminatedUnion('kind', [
53
76
  .object({
54
77
  ...frameBase,
55
78
  kind: z.literal('complete'),
56
- version: boundedString(128),
57
- serviceId: z.string().regex(/^[a-f0-9]{64}$/u),
58
- deploymentId: z.string().uuid(),
59
- operator: z.unknown().transform((value, context) => {
60
- try {
61
- const command = decodeRuntimeHostOperatorCommand(value);
62
- if (command.kind !== 'node') {
63
- throw new Error('Runtime Host setup operator must be a Node command');
64
- }
65
- return command;
66
- }
67
- catch (error) {
68
- context.addIssue({
69
- code: 'custom',
70
- message: error instanceof Error ? error.message : 'Runtime Host operator is invalid',
71
- });
72
- return z.NEVER;
73
- }
74
- }),
75
- rootPath: boundedString(4 * 1024).refine((value) => !/[\u0000-\u001f\u007f]/u.test(value)),
76
- rootId: z.string().regex(/^[a-f0-9]{64}$/u),
79
+ ...environmentBindingFields,
77
80
  endpoint: boundedString(SETUP_FIELD_MAX_BYTES).refine((value) => parseRuntimeHostSetupEndpoint(value) !== undefined),
78
81
  credentialId: boundedString(SETUP_FIELD_MAX_BYTES),
79
82
  credential: boundedString(SETUP_CREDENTIAL_MAX_BYTES),
@@ -87,6 +90,13 @@ const SETUP_FRAME_SCHEMA = z.discriminatedUnion('kind', [
87
90
  .optional(),
88
91
  })
89
92
  .strict(),
93
+ z
94
+ .object({
95
+ ...frameBase,
96
+ kind: z.literal('existing_environment'),
97
+ ...environmentBindingFields,
98
+ })
99
+ .strict(),
90
100
  z
91
101
  .object({
92
102
  ...frameBase,
@@ -62,7 +62,19 @@ export const RUNTIME_HOST_REGISTRATION_SCHEMA_VERSION = 1;
62
62
  export const RUNTIME_HOST_PROTOCOL_VERSION = 0;
63
63
  // Increment when the same protocol version no longer guarantees safe Client-Host
64
64
  // interoperability. Mismatches are rejected before domain commands are admitted.
65
- export const RUNTIME_HOST_COMPATIBILITY_EPOCH = 133;
65
+ export const RUNTIME_HOST_COMPATIBILITY_EPOCH = 141;
66
+ // 141: WorkHub root admissions bind model Intent/Recall decisions before actions.
67
+ // 140: Plugin Platform queries expose scoped Command contribution projections.
68
+ // Epoch-139 peers reject the added query view and result shape.
69
+ // 139: WorkHub recovery preserves the Host-authenticated Desktop capability binding.
70
+ // 138: Removes the unused steering display anchor from canonical MessageContent.
71
+ // 137: Reserved by the former display anchor contract.
72
+ // 136: WorkHub transient proposals distinguish routing dispositions from linked
73
+ // operations. Older peers expect replace/stop_work/resume_work dispositions.
74
+ // 135: WorkHub model Turns replace direct action proposals with active-Turn task tools.
75
+ // 134: Coordination actions own real Runtime Turns. Removes the synthetic record
76
+ // operation, projects typed action receipts and admitted action identities, and
77
+ // distinguishes stale candidate refusals and resumable transcript preparation.
66
78
  // 133: WorkHub actions carry attachments and new-Work model/permission defaults.
67
79
  // Epoch-132 peers reject these additional fields on strict action shapes.
68
80
  // 132: new Tool Result archives use versioned ledger references, not Artifact payloads.
@@ -218,9 +218,10 @@ export const REMOTE_OWNER_OPERATION_GRANTS = Object.freeze([
218
218
  'usage.query',
219
219
  'web-search.execute',
220
220
  'workhub.coordination.answer',
221
- 'workhub.coordination.act',
221
+ 'workhub.coordination.actFromTurn',
222
222
  'workhub.coordination.candidates',
223
- 'workhub.coordination.record',
223
+ 'workhub.coordination.configureModel',
224
+ 'workhub.coordination.query',
224
225
  'workhub.coordination.resolve',
225
226
  ]);
226
227
  const REMOTE_OWNER_OPERATION_GRANT_SET = new Set(REMOTE_OWNER_OPERATION_GRANTS);
@@ -108,7 +108,7 @@ export const PLUGIN_PLATFORM_OPERATION_SPECS = {
108
108
  };
109
109
  function decodePluginPlatformQueryInput(value) {
110
110
  const input = requireShapedRecord(value, 'Plugin Platform query input', ['view'], ['rootId', 'cursor', 'limit']);
111
- if (!['status', 'packages', 'entries', 'tools', 'failures'].includes(input.view)) {
111
+ if (!['status', 'packages', 'entries', 'tools', 'commands', 'failures'].includes(input.view)) {
112
112
  throw invalidProtocolFrame('Invalid Plugin Platform query view');
113
113
  }
114
114
  const view = input.view;
@@ -125,8 +125,8 @@ function decodePluginPlatformQueryInput(value) {
125
125
  (input.rootId !== undefined || cursor !== undefined || limit !== undefined)) {
126
126
  throw invalidProtocolFrame('Plugin Platform status query does not accept paging');
127
127
  }
128
- if (input.rootId !== undefined && view !== 'entries' && view !== 'tools') {
129
- throw invalidProtocolFrame('Plugin root identity is only valid for Entry and Tool queries');
128
+ if (input.rootId !== undefined && view !== 'entries' && view !== 'tools' && view !== 'commands') {
129
+ throw invalidProtocolFrame('Plugin root identity is only valid for Entry, Tool, and Command queries');
130
130
  }
131
131
  let rootId;
132
132
  if (input.rootId !== undefined) {
@@ -190,7 +190,7 @@ function decodePluginPlatformQueryResult(value) {
190
190
  ]);
191
191
  if (!Array.isArray(output.items) ||
192
192
  output.items.length > 64 ||
193
- !['packages', 'entries', 'tools', 'failures'].includes(view)) {
193
+ !['packages', 'entries', 'tools', 'commands', 'failures'].includes(view)) {
194
194
  throw invalidProtocolFrame('Invalid Plugin Platform page');
195
195
  }
196
196
  const nextCursor = output.nextCursor === null
@@ -203,11 +203,36 @@ function decodePluginPlatformQueryResult(value) {
203
203
  ? { view, items: decodeInspections(output.items), nextCursor }
204
204
  : view === 'tools'
205
205
  ? { view, items: output.items.map(decodeToolInspection), nextCursor }
206
- : { view: 'failures', items: output.items.map(decodePlatformFailure), nextCursor };
206
+ : view === 'commands'
207
+ ? { view, items: output.items.map(decodeCommandInspection), nextCursor }
208
+ : { view: 'failures', items: output.items.map(decodePlatformFailure), nextCursor };
207
209
  }
208
210
  requireEncodedByteLimit(decoded, 'Plugin Platform query result', PLUGIN_PLATFORM_QUERY_RESULT_MAX_BYTES);
209
211
  return decoded;
210
212
  }
213
+ function decodeCommandInspection(value) {
214
+ const item = requireExactRecord(value, 'Plugin Command inspection', [
215
+ 'entryId',
216
+ 'scopeId',
217
+ 'extensionId',
218
+ 'generation',
219
+ 'name',
220
+ 'description',
221
+ 'aliases',
222
+ ]);
223
+ if (!Array.isArray(item.aliases) || item.aliases.length > 64) {
224
+ throw invalidProtocolFrame('Invalid Plugin Command aliases');
225
+ }
226
+ return {
227
+ entryId: requireId(item.entryId, 'Plugin Entry identity'),
228
+ scopeId: requireString(item.scopeId, 'Plugin scope identity', 256),
229
+ extensionId: requireId(item.extensionId, 'Plugin package identity'),
230
+ generation: requireCount(item.generation, 'Plugin generation'),
231
+ name: requireString(item.name, 'Plugin Command name', 128),
232
+ description: requireString(item.description, 'Plugin Command description', 4096),
233
+ aliases: item.aliases.map((alias) => requireString(alias, 'Plugin Command alias', 128)),
234
+ };
235
+ }
211
236
  function decodePlatformFailure(value) {
212
237
  const failure = requireShapedRecord(value, 'Plugin Platform failure', ['diagnostic'], ['entryId', 'extensionId']);
213
238
  if (failure.entryId === undefined && failure.extensionId === undefined) {
@@ -56,6 +56,7 @@ export const SESSION_DOMAINS = [
56
56
  ];
57
57
  export const SESSION_RUNTIME_RESOURCE_CHANGES_MAX = 64;
58
58
  const SUBSCRIPTION_OPEN_ERRORS = [
59
+ 'transcript_preparing',
59
60
  'host_not_ready',
60
61
  'host_draining',
61
62
  'operation_unavailable',