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
@@ -17,7 +17,6 @@
17
17
  * under the License.
18
18
  */
19
19
  import { resolve } from 'node:path';
20
- import { isTaskLedgerEvent, projectTaskLedgerEvents, } from '@maka/core/task-ledger';
21
20
  import { normalizeSessionTodoItems, } from '@maka/core/session-todo';
22
21
  import { acquireOperationalStateDatabase, } from './operational-state-store.js';
23
22
  import { assertSafeSessionId } from './session-store.js';
@@ -46,9 +45,9 @@ class SqliteSessionTodoStoreImpl {
46
45
  const existing = readStoredDocument(this.#lease.database, sessionId);
47
46
  if (existing)
48
47
  return snapshotFromDocument(existing);
49
- const bootstrapped = bootstrapLegacyTasks(this.#lease.database, sessionId);
50
- insertDocument(this.#lease.database, sessionId, bootstrapped);
51
- return snapshotFromDocument(bootstrapped);
48
+ const initial = emptyDocument();
49
+ insertDocument(this.#lease.database, sessionId, initial);
50
+ return snapshotFromDocument(initial);
52
51
  });
53
52
  });
54
53
  return snapshot;
@@ -76,10 +75,9 @@ class SqliteSessionTodoStoreImpl {
76
75
  let snapshot;
77
76
  await this.#write(async () => {
78
77
  snapshot = this.#lease.transaction('write', () => {
79
- const source = input.copyCurrent
80
- ? (readStoredDocument(this.#lease.database, input.sourceSessionId) ??
81
- bootstrapAndInsert(this.#lease.database, input.sourceSessionId))
82
- : emptyDocument();
78
+ const source = (input.copyCurrent
79
+ ? readStoredDocument(this.#lease.database, input.sourceSessionId)
80
+ : undefined) ?? emptyDocument();
83
81
  const existing = readStoredDocument(this.#lease.database, input.targetSessionId);
84
82
  if (existing) {
85
83
  if (!sameDocument(existing, source)) {
@@ -100,9 +98,6 @@ class SqliteSessionTodoStoreImpl {
100
98
  this.#lease.database
101
99
  .prepare('DELETE FROM workflow_session_todo_documents WHERE session_id = ?')
102
100
  .run(sessionId);
103
- this.#lease.database
104
- .prepare('DELETE FROM workflow_task_ledger_events WHERE session_id = ?')
105
- .run(sessionId);
106
101
  });
107
102
  });
108
103
  }
@@ -112,11 +107,6 @@ class SqliteSessionTodoStoreImpl {
112
107
  return chainWrite(this.writeQueues, 'session-todo', operation);
113
108
  }
114
109
  }
115
- function bootstrapAndInsert(database, sessionId) {
116
- const document = bootstrapLegacyTasks(database, sessionId);
117
- insertDocument(database, sessionId, document);
118
- return document;
119
- }
120
110
  function emptyDocument() {
121
111
  return { schemaVersion: SESSION_TODO_DOCUMENT_SCHEMA_VERSION, items: [] };
122
112
  }
@@ -157,58 +147,6 @@ function readStoredDocument(database, sessionId) {
157
147
  items: normalized.value.items,
158
148
  };
159
149
  }
160
- function bootstrapLegacyTasks(database, sessionId) {
161
- const rows = database
162
- .prepare(`
163
- SELECT record_json
164
- FROM workflow_task_ledger_events
165
- WHERE session_id = ?
166
- ORDER BY sequence
167
- `)
168
- .all(sessionId);
169
- const events = rows.map((row, index) => {
170
- if (typeof row.record_json !== 'string') {
171
- throw new Error(`Invalid legacy Task event at sequence ${index}`);
172
- }
173
- let parsed;
174
- try {
175
- parsed = JSON.parse(row.record_json);
176
- }
177
- catch {
178
- throw new Error(`Invalid legacy Task event JSON at sequence ${index}`);
179
- }
180
- if (!isTaskLedgerEvent(parsed) || parsed.sessionId !== sessionId) {
181
- throw new Error(`Invalid legacy Task event at sequence ${index}`);
182
- }
183
- return parsed;
184
- });
185
- const projected = projectTaskLedgerEvents(events);
186
- if (projected.diagnostics.length > 0) {
187
- throw new Error(`Legacy Task ledger is not projectable: ${projected.diagnostics.join('; ')}`);
188
- }
189
- const items = projected.tasks.flatMap((task) => {
190
- switch (task.status) {
191
- case 'pending':
192
- case 'in_progress':
193
- return [{ content: task.subject, status: task.status }];
194
- case 'blocked':
195
- // SessionTodo deliberately has no workflow-specific blocked state or
196
- // reason field. Keep the unfinished subject visible for replanning.
197
- return [{ content: task.subject, status: 'pending' }];
198
- case 'completed':
199
- case 'failed':
200
- case 'cancelled':
201
- return [];
202
- }
203
- });
204
- const normalized = normalizeSessionTodoItems(items);
205
- if (!normalized.ok)
206
- throw new Error(`Legacy Task bootstrap failed: ${normalized.message}`);
207
- return {
208
- schemaVersion: SESSION_TODO_DOCUMENT_SCHEMA_VERSION,
209
- items: normalized.value.items,
210
- };
211
- }
212
150
  function insertDocument(database, sessionId, document) {
213
151
  database
214
152
  .prepare(`
@@ -24,11 +24,9 @@ export function createSettingsStore(workspaceRoot) {
24
24
  return new FileSettingsStore(workspaceRoot);
25
25
  }
26
26
  class FileSettingsStore {
27
- workspaceRoot;
28
27
  settingsPath;
29
28
  queue = Promise.resolve();
30
29
  constructor(workspaceRoot) {
31
- this.workspaceRoot = workspaceRoot;
32
30
  this.settingsPath = join(workspaceRoot, 'settings.json');
33
31
  }
34
32
  async get() {
@@ -43,7 +41,12 @@ class FileSettingsStore {
43
41
  async readOrCreate() {
44
42
  try {
45
43
  const text = await readFile(this.settingsPath, 'utf8');
46
- return normalizeSettings(JSON.parse(text));
44
+ const persisted = JSON.parse(text);
45
+ const settings = normalizeSettings(persisted);
46
+ if (hasLegacyProxyCredentialFields(persisted)) {
47
+ await this.write(settings);
48
+ }
49
+ return settings;
47
50
  }
48
51
  catch (error) {
49
52
  if (error.code !== 'ENOENT')
@@ -129,28 +132,6 @@ class FileSettingsStore {
129
132
  throw new Error('Failed to clear onboarding milestone');
130
133
  return result;
131
134
  }
132
- async testNetworkProxy() {
133
- const started = Date.now();
134
- const settings = await this.get();
135
- const proxy = settings.network.proxy;
136
- if (!proxy.enabled) {
137
- return { ok: true, message: '代理未启用,当前会直接连接。', latencyMs: Date.now() - started };
138
- }
139
- if (!proxy.host.trim())
140
- return { ok: false, message: '代理服务器地址不能为空' };
141
- if (!Number.isInteger(proxy.port) || proxy.port <= 0 || proxy.port > 65535) {
142
- return { ok: false, message: '代理端口必须在 1-65535 之间' };
143
- }
144
- if (proxy.authEnabled && (!proxy.username.trim() || !proxy.password)) {
145
- return { ok: false, message: '启用代理认证后需要用户名和密码' };
146
- }
147
- return {
148
- ok: true,
149
- message: `代理配置有效:${proxy.protocol}://${proxy.host}:${proxy.port}`,
150
- latencyMs: Date.now() - started,
151
- details: { bypassList: proxy.bypassList, autoBypassDomains: proxy.autoBypassDomains },
152
- };
153
- }
154
135
  async write(settings) {
155
136
  await mkdir(dirname(this.settingsPath), { recursive: true });
156
137
  const tempPath = `${this.settingsPath}.${process.pid}.${Date.now()}.tmp`;
@@ -163,3 +144,13 @@ class FileSettingsStore {
163
144
  return next;
164
145
  }
165
146
  }
147
+ function hasLegacyProxyCredentialFields(value) {
148
+ if (!isRecord(value) || !isRecord(value.network) || !isRecord(value.network.proxy)) {
149
+ return false;
150
+ }
151
+ const proxy = value.network.proxy;
152
+ return ['password', 'passwordConfigured', 'credential'].some((key) => Object.prototype.hasOwnProperty.call(proxy, key));
153
+ }
154
+ function isRecord(value) {
155
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
156
+ }
@@ -108,6 +108,25 @@ export function migrateSqliteCoreExecutionDatabase(db) {
108
108
  ON DELETE CASCADE
109
109
  );
110
110
 
111
+ CREATE TABLE IF NOT EXISTS core_client_capability_session_grants (
112
+ session_id TEXT NOT NULL,
113
+ provider_id TEXT NOT NULL,
114
+ contract_id TEXT NOT NULL,
115
+ server_id TEXT NOT NULL,
116
+ tool_name TEXT NOT NULL,
117
+ capability TEXT NOT NULL,
118
+ scope_kind TEXT NOT NULL,
119
+ scope_value TEXT NOT NULL,
120
+ granted_at INTEGER NOT NULL,
121
+ record_json TEXT NOT NULL,
122
+ PRIMARY KEY (
123
+ session_id, provider_id, contract_id, capability, scope_kind, scope_value
124
+ )
125
+ );
126
+
127
+ CREATE INDEX IF NOT EXISTS core_client_capability_session_grants_session
128
+ ON core_client_capability_session_grants(session_id, granted_at);
129
+
111
130
  CREATE TABLE IF NOT EXISTS core_shell_runs (
112
131
  session_id TEXT NOT NULL,
113
132
  shell_run_id TEXT NOT NULL,
@@ -16,7 +16,7 @@
16
16
  * specific language governing permissions and limitations
17
17
  * under the License.
18
18
  */
19
- export const SQLITE_SESSION_METADATA_SCHEMA_VERSION = 35;
19
+ export const SQLITE_SESSION_METADATA_SCHEMA_VERSION = 36;
20
20
  export const SQLITE_SESSION_MESSAGE_CHUNK_BYTES = 64 * 1024;
21
21
  export const SQLITE_SESSION_MESSAGE_CHUNK_MARKER = '{"$maka":"session-message-chunks-v1"}';
22
22
  export const SQLITE_AGENT_GRAPH_CONTROL_TABLES = [
@@ -1228,6 +1228,15 @@ const MIGRATIONS = new Map([
1228
1228
  DEFAULT '{"loaded":[],"failed":[],"receipts":[]}';
1229
1229
  `,
1230
1230
  ],
1231
+ [
1232
+ 36,
1233
+ `
1234
+ -- WorkHub replacement intent and atomic supersession records require the
1235
+ -- schema-v2 canonical message decoder. Prevent older builds from opening
1236
+ -- a profile after either record has been committed.
1237
+ SELECT 1;
1238
+ `,
1239
+ ],
1231
1240
  ]);
1232
1241
  if (MIGRATIONS.size !== SQLITE_SESSION_METADATA_SCHEMA_VERSION) {
1233
1242
  throw new Error('SQLite session metadata migrations contain a duplicate or missing version');
@@ -1153,6 +1153,12 @@ export class SqliteSessionMetadataStore {
1153
1153
  async assignWorkHubMessage(request) {
1154
1154
  const assignmentJson = JSON.stringify(request.assignment);
1155
1155
  const assignment = decodeCanonicalMessage(JSON.parse(assignmentJson));
1156
+ const supersessionJson = request.supersession
1157
+ ? JSON.stringify(request.supersession)
1158
+ : undefined;
1159
+ const supersession = supersessionJson
1160
+ ? decodeCanonicalMessage(JSON.parse(supersessionJson))
1161
+ : undefined;
1156
1162
  const admission = normalizePendingMessageAdmission(request.admission);
1157
1163
  const suffix = createHash('sha256')
1158
1164
  .update(request.assignment.actionId)
@@ -1173,6 +1179,26 @@ export class SqliteSessionMetadataStore {
1173
1179
  admission.disposition !== 'steering') {
1174
1180
  throw new SessionMetadataConflictError('Invalid WorkHub assignment identity');
1175
1181
  }
1182
+ if ((assignment.replacesActionId === undefined) !==
1183
+ (assignment.replacesDelegationId === undefined) ||
1184
+ (assignment.replacesDelegationId === undefined) !== (supersession === undefined) ||
1185
+ (supersession !== undefined &&
1186
+ (supersession.type !== 'workhub_coordination' ||
1187
+ supersession.kind !== 'delegation_superseded' ||
1188
+ supersession.actionId !== assignment.actionId ||
1189
+ supersession.actionFingerprint !== assignment.actionFingerprint ||
1190
+ supersession.coordinationTurnId !== assignment.coordinationTurnId ||
1191
+ supersession.turnId !== assignment.coordinationTurnId ||
1192
+ supersession.supersededActionId !== assignment.replacesActionId ||
1193
+ supersession.supersededDelegationId !== assignment.replacesDelegationId ||
1194
+ supersession.replacementDelegationId !== assignment.delegationId ||
1195
+ supersession.id !==
1196
+ `whx_${createHash('sha256')
1197
+ .update(supersession.supersededDelegationId)
1198
+ .digest('hex')
1199
+ .slice(0, 48)}`))) {
1200
+ throw new SessionMetadataConflictError('Invalid WorkHub supersession identity');
1201
+ }
1176
1202
  const create = request.create
1177
1203
  ? {
1178
1204
  header: normalizeSessionHeader(request.create.header),
@@ -1209,6 +1235,30 @@ export class SqliteSessionMetadataStore {
1209
1235
  assignment: existingAssignment,
1210
1236
  };
1211
1237
  }
1238
+ if (supersession && assignment.replacesActionId && assignment.replacesDelegationId) {
1239
+ const replacedSuffix = createHash('sha256')
1240
+ .update(assignment.replacesActionId)
1241
+ .digest('hex')
1242
+ .slice(0, 48);
1243
+ const replaced = this.readMessageByIdSync(WORKHUB_COORDINATION_SESSION_ID, `wha_${replacedSuffix}`);
1244
+ if (replaced?.type !== 'workhub_coordination' ||
1245
+ replaced.kind !== 'delegation_assigned' ||
1246
+ replaced.delegationId !== assignment.replacesDelegationId) {
1247
+ throw new SessionMetadataConflictError('WorkHub supersession source is unavailable');
1248
+ }
1249
+ const abortSuffix = createHash('sha256')
1250
+ .update(assignment.replacesDelegationId)
1251
+ .digest('hex')
1252
+ .slice(0, 48);
1253
+ const existingAbort = this.readMessageByIdSync(WORKHUB_COORDINATION_SESSION_ID, `whb_${abortSuffix}`);
1254
+ if (existingAbort) {
1255
+ throw new SessionMetadataConflictError('WorkHub delegation replacement is aborted');
1256
+ }
1257
+ const existingSupersession = this.readMessageByIdSync(WORKHUB_COORDINATION_SESSION_ID, supersession.id);
1258
+ if (existingSupersession) {
1259
+ throw new SessionMetadataConflictError('WorkHub delegation is already superseded');
1260
+ }
1261
+ }
1212
1262
  let targetCreated = false;
1213
1263
  if (create) {
1214
1264
  const probe = this.probeStableSessionCreateSync(create.header.id, create.requestFingerprint);
@@ -1234,8 +1284,19 @@ export class SqliteSessionMetadataStore {
1234
1284
  if (target.header.status === 'waiting_for_user') {
1235
1285
  throw new SessionMetadataConflictError('WorkHub target Session is waiting for user input');
1236
1286
  }
1287
+ let committedAssignment = assignment;
1288
+ let committedAssignmentJson = assignmentJson;
1237
1289
  if (target.header.name !== assignment.targetSessionName) {
1238
- throw new SessionMetadataConflictError('WorkHub target display identity changed');
1290
+ if (assignment.disposition !== 'delegate_existing' ||
1291
+ assignment.replacesDelegationId === undefined) {
1292
+ throw new SessionMetadataConflictError('WorkHub target display identity changed');
1293
+ }
1294
+ // A durable replacement owns the target Session id before retiring the
1295
+ // source. Canonicalize its display-only name at the same transaction
1296
+ // boundary that validates the target so a concurrent rename cannot
1297
+ // strand the already-retired delegation.
1298
+ committedAssignment = { ...assignment, targetSessionName: target.header.name };
1299
+ committedAssignmentJson = JSON.stringify(committedAssignment);
1239
1300
  }
1240
1301
  if (this.readMessageAdmissionSync(admission.sessionId, admission.messageId)) {
1241
1302
  throw new SessionMetadataConflictError('WorkHub target Message identity belongs to another admission');
@@ -1249,9 +1310,14 @@ export class SqliteSessionMetadataStore {
1249
1310
  sequenceRow.last_sequence < -1) {
1250
1311
  throw new SessionMetadataConflictError('Invalid WorkHub transcript sequence');
1251
1312
  }
1252
- this.insertSessionMessagesSync(WORKHUB_COORDINATION_SESSION_ID, sequenceRow.last_sequence + 1, [{ message: assignment, json: assignmentJson }]);
1313
+ this.insertSessionMessagesSync(WORKHUB_COORDINATION_SESSION_ID, sequenceRow.last_sequence + 1, [
1314
+ { message: committedAssignment, json: committedAssignmentJson },
1315
+ ...(supersession && supersessionJson
1316
+ ? [{ message: supersession, json: supersessionJson }]
1317
+ : []),
1318
+ ]);
1253
1319
  this.updateCatalogProjectionSync(WORKHUB_COORDINATION_SESSION_ID, request.projection, false);
1254
- return { kind: 'assigned', targetCreated, assignment };
1320
+ return { kind: 'assigned', targetCreated, assignment: committedAssignment };
1255
1321
  });
1256
1322
  }
1257
1323
  async readMessageAdmission(sessionId, messageId) {
@@ -4881,6 +4947,8 @@ function sameWorkHubAssignmentRequest(existing, requested) {
4881
4947
  disposition: existing.disposition,
4882
4948
  userText: existing.userText,
4883
4949
  create: existing.create,
4950
+ replacesActionId: existing.replacesActionId,
4951
+ replacesDelegationId: existing.replacesDelegationId,
4884
4952
  }, {
4885
4953
  actionId: requested.actionId,
4886
4954
  actionFingerprint: requested.actionFingerprint,
@@ -4889,6 +4957,8 @@ function sameWorkHubAssignmentRequest(existing, requested) {
4889
4957
  disposition: requested.disposition,
4890
4958
  userText: requested.userText,
4891
4959
  create: requested.create,
4960
+ replacesActionId: requested.replacesActionId,
4961
+ replacesDelegationId: requested.replacesDelegationId,
4892
4962
  });
4893
4963
  }
4894
4964
  function foldTurnContribution(current, turnId, sequence, message) {
@@ -16,7 +16,7 @@
16
16
  * specific language governing permissions and limitations
17
17
  * under the License.
18
18
  */
19
- export const SQLITE_WORKFLOW_SCHEMA_VERSION = 11;
19
+ export const SQLITE_WORKFLOW_SCHEMA_VERSION = 12;
20
20
  const RELEASED_WORKFLOW_PROJECTION_TABLES = [
21
21
  {
22
22
  name: 'workflow_task_ledger_projections',
@@ -39,15 +39,7 @@ export function migrateSqliteWorkflowDatabase(db) {
39
39
  db.exec(`
40
40
  DROP INDEX IF EXISTS workflow_plan_reminders_order;
41
41
  DROP TABLE IF EXISTS workflow_plan_reminders;
42
-
43
- CREATE TABLE IF NOT EXISTS workflow_task_ledger_events (
44
- session_id TEXT NOT NULL,
45
- sequence INTEGER NOT NULL CHECK (sequence >= 0),
46
- event_id TEXT NOT NULL,
47
- record_json TEXT NOT NULL,
48
- PRIMARY KEY (session_id, sequence),
49
- UNIQUE (session_id, event_id)
50
- );
42
+ DROP TABLE IF EXISTS workflow_task_ledger_events;
51
43
 
52
44
  CREATE TABLE IF NOT EXISTS workflow_session_todo_documents (
53
45
  session_id TEXT PRIMARY KEY,
@@ -40,6 +40,8 @@
40
40
  "./runtime-event-persistence": "./dist/runtime-event-persistence.js",
41
41
  "./runtime-policy-stores": "./dist/runtime-policy-stores.js",
42
42
  "./scheduled-task-store": "./dist/scheduled-task-store.js",
43
+ "./quiescent-session-snapshot": "./dist/quiescent-session-snapshot.js",
44
+ "./production-session-snapshot": "./dist/production-session-snapshot.js",
43
45
  "./session-bundle-policy": "./dist/session-bundle-policy.js",
44
46
  "./session-copy-cleanup": "./dist/session-copy-cleanup.js",
45
47
  "./session-todo-authority": "./dist/session-todo-authority.js",