maka-agent 0.2.0-dev.11.20260831 → 0.2.0-dev.14.20260902

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 (226) hide show
  1. package/LICENSE +2 -2
  2. package/RUNTIME_HOST_PEER_DEPENDENCIES.rust.tsv +70 -0
  3. package/RUNTIME_HOST_PEER_THIRD_PARTY_NOTICES.txt +1839 -140
  4. package/THIRD_PARTY_NOTICES.txt +2 -2
  5. package/dist/acp/maka-acp-agent.js +6 -3
  6. package/dist/acp/session-registry.js +307 -0
  7. package/dist/acp/stdio-server.js +20 -1
  8. package/dist/cli-core.js +40 -3
  9. package/dist/mcp-capability-provider.js +1 -1
  10. package/dist/onboarding-catalog.js +3 -5
  11. package/dist/pi-transcript.js +21 -17
  12. package/dist/pi-tui-layout.js +4 -2
  13. package/dist/pi-tui-mcp-status.js +44 -130
  14. package/dist/pi-tui-pickers.js +11 -5
  15. package/dist/pi-tui-runner.js +133 -102
  16. package/dist/runtime-host-access-command.js +37 -4
  17. package/dist/runtime-host-capability-provider-command.js +16 -2
  18. package/dist/runtime-host-cli-context.js +73 -3
  19. package/dist/runtime-host-cli.js +187 -10
  20. package/dist/runtime-host-lifecycle-transaction.js +5 -2
  21. package/dist/runtime-host-managed-lifecycle-manager.js +1 -0
  22. package/dist/runtime-host-onboarding.js +12 -16
  23. package/dist/runtime-host-peer-management-command.js +16 -4
  24. package/dist/runtime-host-plugin-command.js +101 -0
  25. package/dist/runtime-host-run-command.js +8 -2
  26. package/dist/runtime-host-service-management-command.js +2 -1
  27. package/dist/runtime-host-setup-command.js +1 -0
  28. package/dist/runtime-host-task-readiness.js +2 -3
  29. package/dist/runtime-host-tui-command.js +1 -1
  30. package/dist/runtime-host-tui-context.js +18 -5
  31. package/dist/runtime-host-update-command.js +71 -35
  32. package/dist/runtime-host-update-discovery.js +1 -0
  33. package/dist/tui-clipboard.js +86 -0
  34. package/dist/tui-copy-catalog.js +248 -0
  35. package/dist/tui-copy-command.js +103 -0
  36. package/native/runtime-host-peer/prebuilds/darwin-arm64/maka_runtime_host_peer.node +0 -0
  37. package/native/runtime-host-peer/prebuilds/linux-arm64/maka_runtime_host_peer.node +0 -0
  38. package/native/runtime-host-peer/prebuilds/linux-x64/maka_runtime_host_peer.node +0 -0
  39. package/native/runtime-host-peer/prebuilds/win32-x64/maka_runtime_host_peer.node +0 -0
  40. package/node_modules/@maka/core/dist/attachments.js +92 -1
  41. package/node_modules/@maka/core/dist/bounded-response.js +71 -0
  42. package/node_modules/@maka/core/dist/chat-model-choice.js +8 -33
  43. package/node_modules/@maka/core/dist/client-capability-grant.js +149 -0
  44. package/node_modules/@maka/core/dist/connection-error-copy.js +17 -34
  45. package/node_modules/@maka/core/dist/connection-readiness.js +3 -31
  46. package/node_modules/@maka/core/dist/deep-research.js +1 -20
  47. package/node_modules/@maka/core/dist/events.js +22 -14
  48. package/node_modules/@maka/core/dist/foreign-session.js +2 -2
  49. package/node_modules/@maka/core/dist/interaction.js +49 -2
  50. package/node_modules/@maka/core/dist/llm-connections.js +74 -82
  51. package/node_modules/@maka/core/dist/maka-wordmark.js +23 -0
  52. package/node_modules/@maka/core/dist/model-catalog.js +242 -315
  53. package/node_modules/@maka/core/dist/model-facts.js +13 -19
  54. package/node_modules/@maka/core/dist/model-metadata.generated.js +1907 -1872
  55. package/node_modules/@maka/core/dist/model-metadata.js +184 -199
  56. package/node_modules/@maka/core/dist/model-thinking.js +1 -1
  57. package/node_modules/@maka/core/dist/models-dev-projection.js +302 -0
  58. package/node_modules/@maka/core/dist/models-dev-refresh.js +55 -0
  59. package/node_modules/@maka/core/dist/onboarding.js +2 -1
  60. package/node_modules/@maka/core/dist/provider-auth.js +47 -291
  61. package/node_modules/@maka/core/dist/provider-registry.js +68 -357
  62. package/node_modules/@maka/core/dist/runtime-event.js +5 -0
  63. package/node_modules/@maka/core/dist/runtime-policy/connection-catalog-codec.js +83 -18
  64. package/node_modules/@maka/core/dist/runtime-policy/credential-vault-codec.js +9 -1
  65. package/node_modules/@maka/core/dist/runtime-policy/model-catalog-entry-codec.js +84 -0
  66. package/node_modules/@maka/core/dist/runtime-policy/policy-codec.js +75 -0
  67. package/node_modules/@maka/core/dist/runtime-policy.js +5 -2
  68. package/node_modules/@maka/core/dist/session-send-projection.js +2 -1
  69. package/node_modules/@maka/core/dist/session-start-mode.js +42 -0
  70. package/node_modules/@maka/core/dist/session.js +120 -5
  71. package/node_modules/@maka/core/dist/settings.js +10 -2
  72. package/node_modules/@maka/core/dist/slash-command-catalog.js +1 -0
  73. package/node_modules/@maka/core/dist/task-submission-readiness.js +2 -1
  74. package/node_modules/@maka/core/dist/usage-record-schema.js +11 -1
  75. package/node_modules/@maka/core/dist/workhub-creation-intent.js +896 -0
  76. package/node_modules/@maka/core/package.json +8 -2
  77. package/node_modules/@maka/mcp/dist/index.js +1 -0
  78. package/node_modules/@maka/runtime/dist/agent-run.js +7 -0
  79. package/node_modules/@maka/runtime/dist/ai-sdk-backend.js +55 -82
  80. package/node_modules/@maka/runtime/dist/ai-sdk-compaction.js +178 -140
  81. package/node_modules/@maka/runtime/dist/archive-read-tool.js +26 -5
  82. package/node_modules/@maka/runtime/dist/builtin-tools.js +27 -2
  83. package/node_modules/@maka/runtime/dist/context-budget-policy.js +0 -12
  84. package/node_modules/@maka/runtime/dist/conversation-copy.js +66 -43
  85. package/node_modules/@maka/runtime/dist/durable-tool-result-projection.js +31 -0
  86. package/node_modules/@maka/runtime/dist/history-compact-error.js +10 -2
  87. package/node_modules/@maka/runtime/dist/history-compact-input-fit.js +7 -1
  88. package/node_modules/@maka/runtime/dist/history-compaction.js +13 -22
  89. package/node_modules/@maka/runtime/dist/image-file.js +5 -20
  90. package/node_modules/@maka/runtime/dist/local-web-fetch.js +2 -43
  91. package/node_modules/@maka/runtime/dist/mcp-tools.js +28 -0
  92. package/node_modules/@maka/runtime/dist/model-fetcher.js +15 -8
  93. package/node_modules/@maka/runtime/dist/model-history.js +59 -17
  94. package/node_modules/@maka/runtime/dist/model-runtime.js +2 -2
  95. package/node_modules/@maka/runtime/dist/plugin-composition-loader.js +173 -20
  96. package/node_modules/@maka/runtime/dist/plugin-runtime.js +219 -0
  97. package/node_modules/@maka/runtime/dist/provider-image-overflow-recovery.js +12 -31
  98. package/node_modules/@maka/runtime/dist/quiescent-session-snapshot.js +78 -0
  99. package/node_modules/@maka/runtime/dist/runtime-event-backfill.js +6 -0
  100. package/node_modules/@maka/runtime/dist/runtime-event-read-model.js +14 -2
  101. package/node_modules/@maka/runtime/dist/session-event-runtime-mapper.js +11 -10
  102. package/node_modules/@maka/runtime/dist/shell-tools.js +77 -1
  103. package/node_modules/@maka/runtime/dist/telemetry/model-pricing.generated.js +93 -83
  104. package/node_modules/@maka/runtime/dist/test-connection.js +6 -6
  105. package/node_modules/@maka/runtime/dist/tool-availability.js +74 -5
  106. package/node_modules/@maka/runtime/dist/tool-result-archive-resource.js +333 -52
  107. package/node_modules/@maka/runtime/dist/tool-result-archive-transition.js +34 -3
  108. package/node_modules/@maka/runtime/dist/tool-runtime.js +62 -6
  109. package/node_modules/@maka/runtime/dist/workers/filesystem-worker.js +39 -16
  110. package/node_modules/@maka/runtime/package.json +1 -0
  111. package/node_modules/@maka/runtime-host/dist/adapter/session-projector.js +10 -3
  112. package/node_modules/@maka/runtime-host/dist/client/catalog-reader.js +59 -18
  113. package/node_modules/@maka/runtime-host/dist/client/client-capability-channel.js +3 -2
  114. package/node_modules/@maka/runtime-host/dist/client/connection.js +72 -31
  115. package/node_modules/@maka/runtime-host/dist/client/host-profile.js +49 -4
  116. package/node_modules/@maka/runtime-host/dist/client/index.js +3 -2
  117. package/node_modules/@maka/runtime-host/dist/client/oauth-presentation.js +1 -1
  118. package/node_modules/@maka/runtime-host/dist/client/owner-connection-code.js +32 -1
  119. package/node_modules/@maka/runtime-host/dist/client/peer-client.js +26 -4
  120. package/node_modules/@maka/runtime-host/dist/client/reconnecting-connection.js +8 -0
  121. package/node_modules/@maka/runtime-host/dist/operator/access-management-frame.js +10 -1
  122. package/node_modules/@maka/runtime-host/dist/operator/index.js +2 -1
  123. package/node_modules/@maka/runtime-host/dist/operator/managed-deployment.js +2 -0
  124. package/node_modules/@maka/runtime-host/dist/operator/peer-management-frame.js +2 -0
  125. package/node_modules/@maka/runtime-host/dist/operator/service-management-frame.js +2 -0
  126. package/node_modules/@maka/runtime-host/dist/peer-mesh/node.js +56 -12
  127. package/node_modules/@maka/runtime-host/dist/peer-mesh/owner.js +4 -0
  128. package/node_modules/@maka/runtime-host/dist/protocol/client-capability.js +22 -1
  129. package/node_modules/@maka/runtime-host/dist/protocol/configuration.js +55 -9
  130. package/node_modules/@maka/{storage/dist/task-ledger-store-internal.js → runtime-host/dist/protocol/connection-catalog-change.js} +7 -13
  131. package/node_modules/@maka/runtime-host/dist/protocol/host-status.js +37 -0
  132. package/node_modules/@maka/runtime-host/dist/protocol/index.js +49 -1
  133. package/node_modules/@maka/runtime-host/dist/protocol/network-proxy.js +1 -7
  134. package/node_modules/@maka/runtime-host/dist/protocol/operations.js +5 -1
  135. package/node_modules/@maka/runtime-host/dist/protocol/plugin-platform.js +512 -0
  136. package/node_modules/@maka/runtime-host/dist/protocol/runtime-policy.js +72 -61
  137. package/node_modules/@maka/runtime-host/dist/protocol/session-catalog.js +1 -1
  138. package/node_modules/@maka/runtime-host/dist/protocol/session-collaboration.js +4 -2
  139. package/node_modules/@maka/runtime-host/dist/protocol/turn.js +5 -12
  140. package/node_modules/@maka/runtime-host/dist/protocol/workhub-coordination.js +92 -4
  141. package/node_modules/@maka/runtime-host/dist/server/access-authority.js +17 -14
  142. package/node_modules/@maka/runtime-host/dist/server/access-credential-metadata.js +4 -2
  143. package/node_modules/@maka/runtime-host/dist/server/access-credential-store.js +119 -47
  144. package/node_modules/@maka/runtime-host/dist/server/agent-graph-execution-coordinator.js +1 -2
  145. package/node_modules/@maka/runtime-host/dist/server/bootstrap-runtime-policy.js +10 -4
  146. package/node_modules/@maka/runtime-host/dist/server/canonical-turn-snapshot.js +0 -9
  147. package/node_modules/@maka/runtime-host/dist/server/client-capability-coordinator.js +192 -18
  148. package/node_modules/@maka/runtime-host/dist/server/client-capability-invocation-broker.js +122 -48
  149. package/node_modules/@maka/runtime-host/dist/server/client-capability-provider-id.js +31 -0
  150. package/node_modules/@maka/runtime-host/dist/server/configuration-coordinator.js +20 -1
  151. package/node_modules/@maka/runtime-host/dist/server/connection-effect-coordinator.js +5 -5
  152. package/node_modules/@maka/runtime-host/dist/server/connection-session.js +1 -0
  153. package/node_modules/@maka/runtime-host/dist/server/execution-composition.js +163 -28
  154. package/node_modules/@maka/runtime-host/dist/server/execution-model-authority.js +2 -2
  155. package/node_modules/@maka/runtime-host/dist/server/execution-service.js +4 -1
  156. package/node_modules/@maka/runtime-host/dist/server/extension-bundle.js +249 -0
  157. package/node_modules/@maka/runtime-host/dist/server/extension-package-manifest.js +262 -0
  158. package/node_modules/@maka/runtime-host/dist/server/host-change-feed.js +11 -0
  159. package/node_modules/@maka/runtime-host/dist/server/host-kernel.js +15 -0
  160. package/node_modules/@maka/runtime-host/dist/server/index.js +5 -0
  161. package/node_modules/@maka/runtime-host/dist/server/interaction-coordinator.js +181 -13
  162. package/node_modules/@maka/runtime-host/dist/server/interaction-projection.js +6 -0
  163. package/node_modules/@maka/runtime-host/dist/server/listener-set.js +8 -4
  164. package/node_modules/@maka/runtime-host/dist/server/message-coordinator.js +88 -22
  165. package/node_modules/@maka/runtime-host/dist/server/model-metadata-refresh.js +96 -0
  166. package/node_modules/@maka/runtime-host/dist/server/network-proxy-coordinator.js +0 -1
  167. package/node_modules/@maka/runtime-host/dist/server/operation-dispatcher.js +43 -118
  168. package/node_modules/@maka/runtime-host/dist/server/peer-listener.js +3 -0
  169. package/node_modules/@maka/runtime-host/dist/server/plugin-composition-patch.js +58 -0
  170. package/node_modules/@maka/runtime-host/dist/server/plugin-composition-store.js +141 -0
  171. package/node_modules/@maka/runtime-host/dist/server/plugin-package-loader.js +130 -0
  172. package/node_modules/@maka/runtime-host/dist/server/plugin-package-store.js +528 -0
  173. package/node_modules/@maka/runtime-host/dist/server/plugin-platform-coordinator.js +249 -0
  174. package/node_modules/@maka/runtime-host/dist/server/plugin-platform.js +1130 -0
  175. package/node_modules/@maka/runtime-host/dist/server/root-admission-owner.js +4 -0
  176. package/node_modules/@maka/runtime-host/dist/server/root-turn-coordinator.js +24 -5
  177. package/node_modules/@maka/runtime-host/dist/server/runtime-policy-coordinator.js +57 -5
  178. package/node_modules/@maka/runtime-host/dist/server/session-catalog-coordinator.js +2 -1
  179. package/node_modules/@maka/runtime-host/dist/server/session-retirement-coordinator.js +3 -3
  180. package/node_modules/@maka/runtime-host/dist/server/session-revision-coordinator.js +35 -3
  181. package/node_modules/@maka/runtime-host/dist/server/session-sidecar-purge.js +16 -0
  182. package/node_modules/@maka/runtime-host/dist/server/session-transcript-pager.js +10 -2
  183. package/node_modules/@maka/runtime-host/dist/server/web-fetch-tool.js +1 -1
  184. package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-action-gate.js +276 -3
  185. package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-coordinator.js +101 -1
  186. package/node_modules/@maka/runtime-host/dist/transport/peer-native.js +1 -0
  187. package/node_modules/@maka/runtime-host/dist/webrtc-stun-policy.js +114 -0
  188. package/node_modules/@maka/runtime-host/package.json +2 -0
  189. package/node_modules/@maka/storage/dist/agent-run-store.js +4 -0
  190. package/node_modules/@maka/storage/dist/artifact-store.js +7 -23
  191. package/node_modules/@maka/storage/dist/conversation-operational-state.js +3 -0
  192. package/node_modules/@maka/storage/dist/execution-stores.js +3 -0
  193. package/node_modules/@maka/storage/dist/interaction-store-public.js +1 -1
  194. package/node_modules/@maka/storage/dist/interaction-store.js +173 -0
  195. package/node_modules/@maka/storage/dist/production-session-snapshot.js +761 -0
  196. package/node_modules/@maka/storage/dist/quiescent-session-snapshot.js +1 -1
  197. package/node_modules/@maka/storage/dist/runtime-policy/connection-catalog-document.js +19 -22
  198. package/node_modules/@maka/storage/dist/runtime-policy/coordinator.js +205 -42
  199. package/node_modules/@maka/storage/dist/runtime-policy/onboarding-transaction.js +2 -2
  200. package/node_modules/@maka/storage/dist/runtime-policy-stores.js +5 -2
  201. package/node_modules/@maka/storage/dist/session-message-projection.js +1 -1
  202. package/node_modules/@maka/storage/dist/session-store.js +32 -6
  203. package/node_modules/@maka/storage/dist/session-todo-store.js +6 -68
  204. package/node_modules/@maka/storage/dist/settings-store.js +16 -25
  205. package/node_modules/@maka/storage/dist/sqlite-core-execution-schema.js +19 -0
  206. package/node_modules/@maka/storage/dist/sqlite-session-metadata-schema.js +10 -1
  207. package/node_modules/@maka/storage/dist/sqlite-session-metadata-store.js +73 -3
  208. package/node_modules/@maka/storage/dist/sqlite-workflow-schema.js +2 -10
  209. package/node_modules/@maka/storage/package.json +2 -0
  210. package/node_modules/fast-uri/index.js +215 -47
  211. package/node_modules/fast-uri/lib/schemes.js +9 -4
  212. package/node_modules/fast-uri/lib/utils.js +396 -92
  213. package/node_modules/fast-uri/package.json +1 -1
  214. package/node_modules/qs/.github/THREAT_MODEL.md +3 -3
  215. package/node_modules/qs/CHANGELOG.md +15 -0
  216. package/node_modules/qs/README.md +19 -1
  217. package/node_modules/qs/dist/qs.js +21 -21
  218. package/node_modules/qs/eslint.config.mjs +1 -1
  219. package/node_modules/qs/lib/parse.js +3 -4
  220. package/node_modules/qs/lib/stringify.js +23 -8
  221. package/node_modules/qs/lib/utils.js +10 -3
  222. package/node_modules/qs/package.json +4 -4
  223. package/package.json +1 -1
  224. package/node_modules/@maka/core/dist/task-ledger.js +0 -669
  225. package/node_modules/@maka/storage/dist/task-ledger-authority.js +0 -121
  226. package/node_modules/@maka/storage/dist/task-ledger-store.js +0 -663
@@ -0,0 +1,101 @@
1
+ /*
2
+ * Licensed to the Apache Software Foundation (ASF) under one
3
+ * or more contributor license agreements. See the NOTICE file
4
+ * distributed with this work for additional information
5
+ * regarding copyright ownership. The ASF licenses this file
6
+ * to you under the Apache License, Version 2.0 (the
7
+ * "License"); you may not use this file except in compliance
8
+ * with the License. You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing,
13
+ * software distributed under the License is distributed on an
14
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ * KIND, either express or implied. See the License for the
16
+ * specific language governing permissions and limitations
17
+ * under the License.
18
+ */
19
+ import { connectExistingRuntimeHost } from '@maka/runtime-host/client';
20
+ import { RUNTIME_HOST_PROTOCOL_VERSION } from '@maka/runtime-host/protocol';
21
+ import { readFile } from 'node:fs/promises';
22
+ import { resolve } from 'node:path';
23
+ const PROTOCOL = {
24
+ min: RUNTIME_HOST_PROTOCOL_VERSION,
25
+ max: RUNTIME_HOST_PROTOCOL_VERSION,
26
+ };
27
+ export async function runRuntimeHostPluginCli(command, overrides = {}) {
28
+ const deps = { ...defaultDeps(), ...overrides };
29
+ const connection = await deps.connect(command.rootPath);
30
+ try {
31
+ const result = await execute(connection, command, deps.readText);
32
+ deps.write(`${JSON.stringify(result, null, 2)}\n`);
33
+ return 0;
34
+ }
35
+ finally {
36
+ await connection.close();
37
+ }
38
+ }
39
+ async function execute(connection, command, readText) {
40
+ const paging = {
41
+ ...(command.cursor === undefined ? {} : { cursor: command.cursor }),
42
+ ...(command.limit === undefined ? {} : { limit: command.limit }),
43
+ };
44
+ switch (command.action) {
45
+ case 'status':
46
+ return await connection.request('plugin.platform.query', { view: 'status' });
47
+ case 'list':
48
+ return await connection.request('plugin.platform.query', { view: 'packages', ...paging });
49
+ case 'inspect':
50
+ return await connection.request('plugin.platform.query', {
51
+ view: 'entries',
52
+ ...paging,
53
+ ...(command.rootId ? { rootId: command.rootId } : {}),
54
+ });
55
+ case 'failures':
56
+ return await connection.request('plugin.platform.query', { view: 'failures', ...paging });
57
+ case 'install':
58
+ return await connection.request('plugin.package.install', {
59
+ sourcePath: resolve(requireSubject(command)),
60
+ });
61
+ case 'uninstall':
62
+ return await connection.request('plugin.package.uninstall', {
63
+ extensionId: requireSubject(command),
64
+ });
65
+ case 'reload':
66
+ return await connection.request('plugin.package.reload', {
67
+ extensionId: requireSubject(command),
68
+ });
69
+ case 'export':
70
+ return await connection.request('plugin.package.export', {
71
+ extensionId: requireSubject(command),
72
+ targetPath: resolve(command.targetPath ?? missing('Plugin export target path')),
73
+ });
74
+ case 'apply': {
75
+ const decoded = JSON.parse(await readText(resolve(requireSubject(command))));
76
+ return await connection.request('plugin.composition.apply', decoded);
77
+ }
78
+ case 'reconcile':
79
+ return await connection.request('plugin.platform.reconcile', {});
80
+ }
81
+ }
82
+ function requireSubject(command) {
83
+ return command.subject ?? missing(`Plugin ${command.action} target`);
84
+ }
85
+ function missing(label) {
86
+ throw new Error(`${label} is missing`);
87
+ }
88
+ function defaultDeps() {
89
+ return {
90
+ connect: connectLocalOwner,
91
+ readText: (path) => readFile(path, 'utf8'),
92
+ write: (value) => process.stdout.write(value),
93
+ };
94
+ }
95
+ async function connectLocalOwner(rootPath) {
96
+ const result = await connectExistingRuntimeHost({ rootPath, protocol: PROTOCOL });
97
+ if (result.kind !== 'connected') {
98
+ throw new Error(`Runtime Host service is not available (${result.kind})`);
99
+ }
100
+ return result.connection;
101
+ }
@@ -314,7 +314,11 @@ class RuntimeHostRunRuntime {
314
314
  await this.#observer?.(active.outcome.outcome('fail'));
315
315
  }
316
316
  async #stopTurn(turn) {
317
- await this.#connection.request('turn.stop', turn);
317
+ await this.#connection.request('turn.stop', {
318
+ sessionId: turn.sessionId,
319
+ turnId: turn.turnId,
320
+ runId: turn.runId,
321
+ });
318
322
  }
319
323
  async #stopGraph(sessionId) {
320
324
  try {
@@ -432,6 +436,7 @@ class TurnOutcomeClassifier {
432
436
  if (observation.outcome === 'sandbox_failure') {
433
437
  this.#unresolvedSandboxFailures.set(observation.toolUseId, {
434
438
  failedStepId: call?.stepId,
439
+ failedToolName: call?.toolName,
435
440
  });
436
441
  return;
437
442
  }
@@ -443,7 +448,8 @@ class TurnOutcomeClassifier {
443
448
  unresolved.length === 1 &&
444
449
  call?.stepId !== undefined &&
445
450
  unresolved[0]?.failedStepId !== undefined &&
446
- call.stepId !== unresolved[0].failedStepId) {
451
+ call.stepId !== unresolved[0].failedStepId &&
452
+ call.toolName === unresolved[0].failedToolName) {
447
453
  this.#unresolvedSandboxFailures.clear();
448
454
  this.#sandboxBoundaryRecovered = true;
449
455
  }
@@ -18,7 +18,7 @@
18
18
  */
19
19
  import { truncateUtf8 } from '@maka/core/diagnostic-log';
20
20
  import { release } from 'node:os';
21
- import { assertRuntimeHostManagedDeploymentAuthorityDurablyAbsent, encodeRuntimeHostServiceManagementFrame, RUNTIME_HOST_OPERATOR_ACCESS_MANAGEMENT_CAPABILITY, RUNTIME_HOST_OPERATOR_CAPABILITY_REQUEST_ENV, RUNTIME_HOST_OPERATOR_PEER_MANAGEMENT_CAPABILITY, RUNTIME_HOST_OPERATOR_PEER_RELAY_DISCOVERY_CAPABILITY, RUNTIME_HOST_OPERATOR_PROJECT_DIRECTORY_CONFIGURATION_REQUEST_ENV, RUNTIME_HOST_OPERATOR_PROCESS_LIFETIME_LOCK_CAPABILITY, RUNTIME_HOST_SERVICE_ERROR_CODE_MAX_BYTES, RUNTIME_HOST_SERVICE_ERROR_MESSAGE_MAX_BYTES, } from '@maka/runtime-host/operator';
21
+ import { assertRuntimeHostManagedDeploymentAuthorityDurablyAbsent, encodeRuntimeHostServiceManagementFrame, RUNTIME_HOST_OPERATOR_ACCESS_MANAGEMENT_CAPABILITY, RUNTIME_HOST_OPERATOR_CAPABILITY_REQUEST_ENV, RUNTIME_HOST_OPERATOR_PEER_MANAGEMENT_CAPABILITY, RUNTIME_HOST_OPERATOR_PEER_RELAY_DISCOVERY_CAPABILITY, RUNTIME_HOST_OPERATOR_PEER_WEBRTC_STUN_CAPABILITY, RUNTIME_HOST_OPERATOR_PROJECT_DIRECTORY_CONFIGURATION_REQUEST_ENV, RUNTIME_HOST_OPERATOR_PROCESS_LIFETIME_LOCK_CAPABILITY, RUNTIME_HOST_SERVICE_ERROR_CODE_MAX_BYTES, RUNTIME_HOST_SERVICE_ERROR_MESSAGE_MAX_BYTES, } from '@maka/runtime-host/operator';
22
22
  import { resolveExistingStorageRoot, tryAcquireStateRootOwner } from '@maka/storage/root-authority';
23
23
  import { cleanupRuntimeHostManagedDeployment, effectiveRuntimeHostProjectDirectoryRoots, manageRuntimeHostService, resolveRuntimeHostManagedServiceConfigPath, resolveRuntimeHostManagedServiceId, runtimeHostManagedServiceConfigFingerprint, RuntimeHostServiceManagerError, withRuntimeHostManagedServiceDeploymentLock, withRuntimeHostManagedServiceLifecycleLock, } from './runtime-host-service-manager.js';
24
24
  import { createLaunchAgentRuntimeHostService } from './runtime-host-launch-agent-service.js';
@@ -277,6 +277,7 @@ function requestedOperatorCapabilities() {
277
277
  if (requested === RUNTIME_HOST_OPERATOR_ACCESS_MANAGEMENT_CAPABILITY ||
278
278
  requested === RUNTIME_HOST_OPERATOR_PEER_MANAGEMENT_CAPABILITY ||
279
279
  requested === RUNTIME_HOST_OPERATOR_PEER_RELAY_DISCOVERY_CAPABILITY ||
280
+ requested === RUNTIME_HOST_OPERATOR_PEER_WEBRTC_STUN_CAPABILITY ||
280
281
  requested === RUNTIME_HOST_OPERATOR_PROCESS_LIFETIME_LOCK_CAPABILITY) {
281
282
  capabilities.push(requested);
282
283
  }
@@ -383,6 +383,7 @@ async function prepareSupervisedDirectPeer(options, deps, cliPath, deploymentRoo
383
383
  ...(options.directPeer?.coordinationRelays ?? current?.coordinationRelays ?? []),
384
384
  ],
385
385
  automaticRelayDiscovery: current?.automaticRelayDiscovery ?? true,
386
+ webRtcStunPolicy: current?.webRtcStunPolicy ?? { kind: 'default' },
386
387
  };
387
388
  }
388
389
  function sameDesiredManagedDeployment(current, desired) {
@@ -18,7 +18,7 @@
18
18
  */
19
19
  import { stat } from 'node:fs/promises';
20
20
  import { deriveTaskSubmissionReadiness, } from '@maka/core/task-submission-readiness';
21
- import { PROVIDER_DEFAULTS } from '@maka/core/llm-connections';
21
+ import { PROVIDER_REGISTRY } from '@maka/core/llm-connections';
22
22
  import { providerAuthRequiresSecret } from '@maka/core/llm-connections';
23
23
  export async function readRuntimeHostCliTaskReadiness(input, now = Date.now) {
24
24
  const checkedAt = now();
@@ -70,7 +70,6 @@ function catalogEntryAsLlmConnection(entry, catalog) {
70
70
  enabledModelIds: [...entry.enabledModelIds],
71
71
  models: [...entry.models],
72
72
  ...(entry.modelSource ? { modelSource: entry.modelSource } : {}),
73
- ...(entry.modelsFetchedAt ? { modelsFetchedAt: entry.modelsFetchedAt } : {}),
74
73
  ...(entry.lastTest
75
74
  ? { lastTestStatus: entry.lastTest.status, lastTestAt: entry.lastTest.checkedAt }
76
75
  : {}),
@@ -81,7 +80,7 @@ function catalogEntryAsLlmConnection(entry, catalog) {
81
80
  async function readHasSecret(connection, entry) {
82
81
  if (!providerAuthRequiresSecret(entry.providerType))
83
82
  return false;
84
- const authKind = PROVIDER_DEFAULTS[entry.providerType].authKind;
83
+ const authKind = PROVIDER_REGISTRY[entry.providerType].authKind;
85
84
  const kind = authKind === 'oauth_token' ? 'oauth_token' : 'api_key';
86
85
  try {
87
86
  const result = await connection.request('credential.vault.query', {
@@ -67,10 +67,10 @@ export async function runRuntimeHostTui(input) {
67
67
  choice.connectionSlug === context.connectionSlug)
68
68
  .map((choice) => choice.model),
69
69
  modelChoices: context.modelChoices,
70
+ subscribeModelCatalogChanges: context.subscribeModelCatalogChanges,
70
71
  connectionSlug: context.connectionSlug,
71
72
  connectionId: context.connectionId,
72
73
  connectionIdentities: context.connectionIdentities,
73
- providerType: context.providerType,
74
74
  modelContextWindow: context.modelContextWindow,
75
75
  permissionMode: context.prospectivePermissionMode,
76
76
  turnActivity: context.turnActivity,
@@ -22,7 +22,7 @@ import { createGenesisExecutionBoundary, executionBoundaryDisplayMode, } from '@
22
22
  import { findProjectByIdentity } from '@maka/core/project';
23
23
  import { SessionActivityRegistry } from '@maka/runtime/goal-turn-lifecycle';
24
24
  import { acquireProcessLifetimeOwner, } from '@maka/storage/process-lifetime-owner';
25
- import { readRuntimeHostAgentGraphEpochs, readRuntimeHostInvocableSkills, readRuntimeHostProjects, isRuntimeHostReconnectingConnection, } from '@maka/runtime-host/client';
25
+ import { readRuntimeHostAgentGraphEpochs, readRuntimeHostConnectionCatalog, readRuntimeHostInvocableSkills, readRuntimeHostProjects, isRuntimeHostReconnectingConnection, } from '@maka/runtime-host/client';
26
26
  import { runtimeHostProfileUsesHostWorkspace } from '@maka/runtime-host/profile-kind';
27
27
  import { connectRuntimeHostCli, readHostChatDefaultPermissionMode, resolveRuntimeHostCliTarget, } from './runtime-host-cli-context.js';
28
28
  import { createRuntimeHostMakaSessionDriver, } from './runtime-host-session-driver.js';
@@ -94,7 +94,13 @@ export async function createRuntimeHostTuiContext(input) {
94
94
  }),
95
95
  });
96
96
  }
97
- const modelContextWindow = selectedTarget.connection?.models.find((model) => model.id === selectedTarget.model)?.contextWindow;
97
+ // From the Host-resolved choice, not the connection's stored rows: a
98
+ // fallback or provider-default model exists only in the resolved catalog,
99
+ // so reading `models` left the very first status line and its diagnostics
100
+ // without a denominator until some later transition happened to refresh
101
+ // it. Every later read of this value already comes from `modelChoices`.
102
+ const modelContextWindow = modelChoices.find((choice) => choice.connectionSlug === selectedTarget.connectionSlug &&
103
+ choice.model === selectedTarget.model)?.contextWindow;
98
104
  return {
99
105
  connection,
100
106
  driver,
@@ -105,12 +111,19 @@ export async function createRuntimeHostTuiContext(input) {
105
111
  : { connectionId: selectedTarget.connectionId }),
106
112
  connectionIdentities: projectRuntimeHostConnectionIdentities(catalog),
107
113
  connectionName: selectedTarget.connection?.name ?? selectedTarget.connectionSlug,
108
- ...(selectedTarget.connection
109
- ? { providerType: selectedTarget.connection.providerType }
110
- : {}),
111
114
  model: selectedTarget.model,
112
115
  ...(modelContextWindow === undefined ? {} : { modelContextWindow }),
113
116
  modelChoices,
117
+ subscribeModelCatalogChanges: (listener) => connection.subscribeConnectionCatalogChanges(() => {
118
+ void readRuntimeHostConnectionCatalog(connection)
119
+ .then((refreshed) => listener({
120
+ modelChoices: projectRuntimeHostModelChoices(refreshed),
121
+ connectionIdentities: projectRuntimeHostConnectionIdentities(refreshed),
122
+ }))
123
+ // A catalog that will not read leaves the choices the TUI already
124
+ // has. The Host announces again the next time it changes.
125
+ .catch(() => undefined);
126
+ }),
114
127
  prospectivePermissionMode,
115
128
  turnActivity: createHostOwnedTurnActivity(),
116
129
  listSkills: (cwd) => listStablePresentedSkills(connection, driver.getSessionId(), workspace ??
@@ -30,6 +30,13 @@ import { canDiscardRuntimeHostLifecycleDesiredArtifacts, replaceRuntimeHostLifec
30
30
  import { manageRuntimeHostManagedLifecycle } from './runtime-host-managed-lifecycle-manager.js';
31
31
  const OPERATOR_TIMEOUT_MS = 2 * 60_000;
32
32
  const OPERATOR_OUTPUT_MAX_BYTES = 256 * 1024;
33
+ function runtimeHostPackageUpdateOperation(input) {
34
+ if (input.currentVersion !== input.targetVersion ||
35
+ input.currentIntegrity !== input.targetIntegrity) {
36
+ return 'update';
37
+ }
38
+ return input.replaceExpectedHost ? 'replace_current' : 'already_current';
39
+ }
33
40
  class RuntimeHostUpdateSelectionError extends Error {
34
41
  code;
35
42
  constructor(code, message) {
@@ -55,6 +62,19 @@ export async function runManagedRuntimeHostUpdateCli(options, overrides = {}, fr
55
62
  createBackend: createPlatformRuntimeHostServiceBackend,
56
63
  verifyReady: verifyRuntimeHostManagedServiceReady,
57
64
  runOperator: runManagedRuntimeHostOperator,
65
+ canonical: {
66
+ createLifecycleDeps: (rootId) => ({
67
+ convergeOperator: (currentConfig, desiredConfig) => convergeRuntimeHostManagedOperator(currentConfig, desiredConfig),
68
+ verifyOperator: verifyRuntimeHostManagedOperator,
69
+ resolveProvider: (requested) => resolveRuntimeHostLifecycleProvider(rootId, requested),
70
+ }),
71
+ assertOperatorDeployment: assertRuntimeHostManagedOperatorDeployment,
72
+ recoverDeployment: resolveRecoverableRuntimeHostManagedDeployment,
73
+ verifyProjection: verifyRuntimeHostLifecycleProjection,
74
+ assertOperatorConfig: assertRuntimeHostManagedOperatorConfig,
75
+ manageLifecycle: manageRuntimeHostManagedLifecycle,
76
+ replaceLifecycle: replaceRuntimeHostLifecycle,
77
+ },
58
78
  writeOutput: (value) => process.stdout.write(value),
59
79
  writeError: (value) => process.stderr.write(value),
60
80
  ...overrides,
@@ -359,27 +379,24 @@ async function runCanonicalRuntimeHostUpdate(options, deps, emit) {
359
379
  let staged;
360
380
  try {
361
381
  return await deps.withDeploymentLock(resolveRuntimeHostManagedControlRoot(options.managedRootId), async () => {
362
- await assertRuntimeHostManagedOperatorDeployment(options.managedRootId, options.operatorDeploymentId, process.argv[1] ?? '');
382
+ await deps.canonical.assertOperatorDeployment(options.managedRootId, options.operatorDeploymentId, process.argv[1] ?? '');
363
383
  const rejection = await deps.revalidateSelection();
364
384
  if (rejection) {
365
385
  throw new RuntimeHostUpdateSelectionError(rejection.code, rejection.message);
366
386
  }
367
- const lifecycleDeps = {
368
- convergeOperator: (currentConfig, desiredConfig) => convergeRuntimeHostManagedOperator(currentConfig, desiredConfig),
369
- verifyOperator: verifyRuntimeHostManagedOperator,
370
- resolveProvider: (requested) => resolveRuntimeHostLifecycleProvider(options.managedRootId, requested),
371
- };
372
- const recovered = await resolveRecoverableRuntimeHostManagedDeployment(options.managedRootId, lifecycleDeps, {
387
+ const lifecycleDeps = deps.canonical.createLifecycleDeps(options.managedRootId);
388
+ const recovered = await deps.canonical.recoverDeployment(options.managedRootId, lifecycleDeps, {
373
389
  expectedTarget: options.expectedTarget,
374
390
  ...(options.expectedHost ? { expectedOwner: options.expectedHost } : {}),
391
+ allowInterruptActiveTasks: options.allowInterruptActiveTasks ?? false,
375
392
  });
376
393
  if (recovered.kind === 'absent') {
377
394
  throw new RuntimeHostServiceManagerError('not_installed', 'The managed Runtime Host deployment is not installed');
378
395
  }
379
396
  const current = recovered.config;
380
- await verifyRuntimeHostLifecycleProjection(current, lifecycleDeps);
381
- assertRuntimeHostManagedOperatorConfig(current, options.operatorDeploymentId, process.argv[1] ?? '');
382
- const currentStatus = await manageRuntimeHostManagedLifecycle(options.managedRootId, {
397
+ await deps.canonical.verifyProjection(current, lifecycleDeps);
398
+ deps.canonical.assertOperatorConfig(current, options.operatorDeploymentId, process.argv[1] ?? '');
399
+ const currentStatus = await deps.canonical.manageLifecycle(options.managedRootId, {
383
400
  action: 'status',
384
401
  clientDataRoot: options.clientDataRoot,
385
402
  defaultRootPath: options.defaultRootPath,
@@ -405,8 +422,14 @@ async function runCanonicalRuntimeHostUpdate(options, deps, emit) {
405
422
  if (!selectedDeploymentStillCurrent && !targetDeploymentIsCurrent) {
406
423
  throw new RuntimeHostServiceManagerError('target_mismatch', 'The managed Runtime Host changed after its update candidate was selected');
407
424
  }
408
- if (options.version === current.launch.package.version &&
409
- targetIntegrity === current.launch.package.integrity) {
425
+ const updateOperation = runtimeHostPackageUpdateOperation({
426
+ currentVersion: current.launch.package.version,
427
+ currentIntegrity: current.launch.package.integrity,
428
+ targetVersion: options.version,
429
+ targetIntegrity,
430
+ replaceExpectedHost: options.expectedHost !== undefined,
431
+ });
432
+ if (updateOperation === 'already_current') {
410
433
  await deps.prunePackages(current);
411
434
  emit({
412
435
  schemaVersion: 1,
@@ -419,15 +442,17 @@ async function runCanonicalRuntimeHostUpdate(options, deps, emit) {
419
442
  return 0;
420
443
  }
421
444
  emit(progress('checking', current.launch.package.version, options.version));
422
- emit(progress('staging', current.launch.package.version, options.version));
423
- staged = await deps.prepareDeployment({
424
- serviceId: options.managedRootId,
425
- clientDataRoot: options.clientDataRoot,
426
- sourcePackageRoot: options.sourcePackageRoot,
427
- version: options.version,
428
- packageIntegrity: targetIntegrity,
429
- deploymentRoot: current.deploymentRoot,
430
- });
445
+ if (updateOperation === 'update') {
446
+ emit(progress('staging', current.launch.package.version, options.version));
447
+ staged = await deps.prepareDeployment({
448
+ serviceId: options.managedRootId,
449
+ clientDataRoot: options.clientDataRoot,
450
+ sourcePackageRoot: options.sourcePackageRoot,
451
+ version: options.version,
452
+ packageIntegrity: targetIntegrity,
453
+ deploymentRoot: current.deploymentRoot,
454
+ });
455
+ }
431
456
  const desired = {
432
457
  ...current,
433
458
  configRevision: current.configRevision + 1,
@@ -442,7 +467,7 @@ async function runCanonicalRuntimeHostUpdate(options, deps, emit) {
442
467
  };
443
468
  emit(progress('retiring', current.launch.package.version, options.version));
444
469
  emit(progress('replacing', current.launch.package.version, options.version));
445
- const replacement = await replaceRuntimeHostLifecycle({
470
+ const replacement = await deps.canonical.replaceLifecycle({
446
471
  operation: 'update',
447
472
  current,
448
473
  desired,
@@ -458,8 +483,10 @@ async function runCanonicalRuntimeHostUpdate(options, deps, emit) {
458
483
  deps: lifecycleDeps,
459
484
  });
460
485
  if (replacement.kind === 'active_tasks') {
461
- await staged.rollback();
462
- staged = undefined;
486
+ if (staged) {
487
+ await staged.rollback();
488
+ staged = undefined;
489
+ }
463
490
  emit({
464
491
  schemaVersion: 1,
465
492
  kind: 'result',
@@ -476,7 +503,7 @@ async function runCanonicalRuntimeHostUpdate(options, deps, emit) {
476
503
  }
477
504
  staged = undefined;
478
505
  await deps.prunePackages(desired);
479
- const updated = await manageRuntimeHostManagedLifecycle(options.managedRootId, {
506
+ const updated = await deps.canonical.manageLifecycle(options.managedRootId, {
480
507
  action: 'status',
481
508
  clientDataRoot: options.clientDataRoot,
482
509
  defaultRootPath: options.defaultRootPath,
@@ -490,11 +517,13 @@ async function runCanonicalRuntimeHostUpdate(options, deps, emit) {
490
517
  action: 'update',
491
518
  service: runtimeHostServiceSummary(updated),
492
519
  ...operatorCapabilities(),
493
- update: {
494
- kind: 'updated',
495
- previousVersion: current.launch.package.version,
496
- targetVersion: options.version,
497
- },
520
+ update: updateOperation === 'replace_current'
521
+ ? { kind: 'repaired', version: options.version }
522
+ : {
523
+ kind: 'updated',
524
+ previousVersion: current.launch.package.version,
525
+ targetVersion: options.version,
526
+ },
498
527
  });
499
528
  return 0;
500
529
  });
@@ -509,7 +538,9 @@ async function runCanonicalRuntimeHostUpdate(options, deps, emit) {
509
538
  ? error.code
510
539
  : error instanceof RuntimeHostLifecycleTransactionError && error.code === 'owner_changed'
511
540
  ? 'target_mismatch'
512
- : 'update_incomplete';
541
+ : error instanceof RuntimeHostLifecycleTransactionError && error.code === 'active_tasks'
542
+ ? 'active_tasks'
543
+ : 'update_incomplete';
513
544
  emit({
514
545
  schemaVersion: 1,
515
546
  kind: 'error',
@@ -543,6 +574,7 @@ export async function runManagedRuntimeHostSelectedUpdateCli(options, overrides
543
574
  ...(options.operatorDeploymentId
544
575
  ? { operatorDeploymentId: options.operatorDeploymentId }
545
576
  : {}),
577
+ ...(options.allowInterruptActiveTasks ? { allowInterruptActiveTasks: true } : {}),
546
578
  });
547
579
  return await runManagedRuntimeHostResolvedUpdateCli(options, selection, deps, emit);
548
580
  }
@@ -551,7 +583,9 @@ export async function runManagedRuntimeHostSelectedUpdateCli(options, overrides
551
583
  error instanceof RuntimeHostServiceManagerError ||
552
584
  error instanceof RuntimeHostUpdatePackageError
553
585
  ? error.code
554
- : 'update_resolution_failed';
586
+ : error instanceof RuntimeHostLifecycleTransactionError && error.code === 'active_tasks'
587
+ ? 'active_tasks'
588
+ : 'update_resolution_failed';
555
589
  const message = error instanceof Error ? error.message : String(error);
556
590
  emit({
557
591
  schemaVersion: 1,
@@ -576,8 +610,10 @@ export async function runManagedRuntimeHostResolvedUpdateCli(options, selection,
576
610
  };
577
611
  try {
578
612
  if (selection.outcome.kind === 'manual_action' &&
579
- !(options.expectedHost &&
580
- options.allowInterruptActiveTasks &&
613
+ !((options.expectedHost ||
614
+ (options.allowManualUpdate &&
615
+ options.managedRootId &&
616
+ options.expectedTarget.deploymentId)) &&
581
617
  selection.outcome.reason !== 'target_not_newer')) {
582
618
  frameSink({
583
619
  schemaVersion: 1,
@@ -591,7 +627,7 @@ export async function runManagedRuntimeHostResolvedUpdateCli(options, selection,
591
627
  return 1;
592
628
  }
593
629
  const apply = async (packageRoot) => {
594
- const { selector: _selector, ...updateOptions } = options;
630
+ const { selector: _selector, allowManualUpdate: _allowManualUpdate, ...updateOptions } = options;
595
631
  return await deps.update({
596
632
  ...updateOptions,
597
633
  sourcePackageRoot: packageRoot,
@@ -59,6 +59,7 @@ async function resolveManagedRuntimeHostUpdate(options, verifyDeployment) {
59
59
  nodePath: process.execPath,
60
60
  cliPath: process.argv[1] ?? '',
61
61
  ...(options.expectedTarget ? { expectedTarget: options.expectedTarget } : {}),
62
+ ...(options.allowInterruptActiveTasks ? { allowInterruptActiveTasks: true } : {}),
62
63
  };
63
64
  const backend = options.managedRootId
64
65
  ? undefined
@@ -0,0 +1,86 @@
1
+ /*
2
+ * Licensed to the Apache Software Foundation (ASF) under one
3
+ * or more contributor license agreements. See the NOTICE file
4
+ * distributed with this work for additional information
5
+ * regarding copyright ownership. The ASF licenses this file
6
+ * to you under the Apache License, Version 2.0 (the
7
+ * "License"); you may not use this file except in compliance
8
+ * with the License. You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing,
13
+ * software distributed under the License is distributed on an
14
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ * KIND, either express or implied. See the License for the
16
+ * specific language governing permissions and limitations
17
+ * under the License.
18
+ */
19
+ /**
20
+ * OSC 52 clipboard writes for the terminal TUI.
21
+ *
22
+ * OSC 52 asks the *terminal emulator* to set the system clipboard, so it works
23
+ * across SSH (the sequence rides the same stream as the rendered UI) and needs
24
+ * no `pbcopy`/`xclip`/`wl-copy` binary. The trade-off is that the write is
25
+ * fire-and-forget: the protocol has no acknowledgement, so we cannot tell
26
+ * whether the terminal honoured it, ignored it (e.g. macOS Terminal.app), or
27
+ * silently dropped it.
28
+ *
29
+ * Payload size is the sharp edge. Past a terminal's OSC-string buffer the
30
+ * sequence is not parsed to completion, so the clipboard is never set to the
31
+ * intended text: kitty logs `OSC sequence too long, truncating` and drops the
32
+ * write, st (pre-0.8.3) returns once its buffer fills. Nothing is echoed to the
33
+ * screen, so the failure is silent. Those buffers vary widely (kitty ~8 KB,
34
+ * Tabby ~1 KB, xterm ~1 MB) and are undetectable from here. We do two things
35
+ * about it: refuse above {@link MAX_CLIPBOARD_TEXT_BYTES}, sized so the emitted
36
+ * sequence clears the ~8 KB buffer of mainstream terminals like kitty and an
37
+ * oversized `/copy all` fails on a readable error rather than a silent drop;
38
+ * and — because a terminal with a smaller buffer (e.g. Tabby) can still drop a
39
+ * below-limit write — word the confirmation as best-effort rather than a promise
40
+ * of success (see `tui-copy-catalog.ts`).
41
+ *
42
+ * Under tmux the bare sequence is still the right primitive to emit, but note
43
+ * it does not land on a default tmux: `set-clipboard` has defaulted to
44
+ * `external` since tmux 2.6, which *ignores* an application's attempt to set a
45
+ * tmux buffer, so forwarding needs `set-clipboard on`. Forwarding also requires
46
+ * an `Ms` capability in the outer terminfo, which nested tmux and the inner side
47
+ * of GNU screen lack (screen itself only recognises OSC 52 wrapped in DCS).
48
+ * Wrapping in tmux's DCS passthrough is deliberately avoided anyway: it needs
49
+ * `allow-passthrough on` (off by default in modern tmux) and bypasses tmux's own
50
+ * clipboard handling, so it would drop the copy on a default configuration too.
51
+ */
52
+ /**
53
+ * Upper bound on the source text of a single OSC 52 write, in UTF-8 bytes. Its
54
+ * base64 encoding (~4/3) plus the 8-byte `ESC ] 52 ; c ; … BEL` framing has to
55
+ * fit a terminal's OSC-string buffer: at 4 KiB the sequence is ~5.5 KB, under
56
+ * the ~8 KB buffer terminals like kitty use (kitty drops a ~6.1 KB reply, whose
57
+ * sequence just tops 8 KB), so an emitted copy lands there. Larger content is
58
+ * refused rather than emitted and silently truncated; the residual variance
59
+ * below this (e.g. Tabby ~1 KB) is what keeps the confirmation best-effort.
60
+ */
61
+ export const MAX_CLIPBOARD_TEXT_BYTES = 4096;
62
+ /** OSC 52 targets the system clipboard selection (`c`). */
63
+ const CLIPBOARD_SELECTION = 'c';
64
+ /**
65
+ * Build the OSC 52 escape sequence that sets the system clipboard to `text`:
66
+ * `ESC ] 52 ; c ; <base64> BEL`. The BEL (`\x07`) terminator is accepted more
67
+ * widely than the ST (`ESC \`) form.
68
+ */
69
+ export function osc52ClipboardSequence(text) {
70
+ const base64 = Buffer.from(text, 'utf8').toString('base64');
71
+ return `\x1b]52;${CLIPBOARD_SELECTION};${base64}\x07`;
72
+ }
73
+ /**
74
+ * Copy `text` to the system clipboard via OSC 52, refusing an oversized payload
75
+ * rather than emitting a sequence a terminal would silently truncate. On
76
+ * success the write is fire-and-forget — see the file header for why there is
77
+ * no delivery result.
78
+ */
79
+ export function copyToClipboard(terminal, text) {
80
+ const bytes = Buffer.byteLength(text, 'utf8');
81
+ if (bytes > MAX_CLIPBOARD_TEXT_BYTES) {
82
+ return { ok: false, reason: 'too_large', bytes, limit: MAX_CLIPBOARD_TEXT_BYTES };
83
+ }
84
+ terminal.write(osc52ClipboardSequence(text));
85
+ return { ok: true, bytes };
86
+ }