maka-agent 0.2.0-dev.64.20260929 → 0.2.0-dev.68.20261003

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 (109) hide show
  1. package/LICENSE +1 -1
  2. package/THIRD_PARTY_NOTICES.txt +3 -3
  3. package/dist/pi-tui-runner.js +26 -29
  4. package/dist/tui-copy-catalog.js +9 -9
  5. package/native/runtime-host-peer/prebuilds/darwin-arm64/maka_runtime_host_peer.node +0 -0
  6. package/native/runtime-host-peer/prebuilds/linux-arm64/maka_runtime_host_peer.node +0 -0
  7. package/native/runtime-host-peer/prebuilds/linux-x64/maka_runtime_host_peer.node +0 -0
  8. package/native/runtime-host-peer/prebuilds/win32-x64/maka_runtime_host_peer.node +0 -0
  9. package/native/runtime-host-windows-task-launcher/prebuilds/win32-x64/maka-runtime-host-task-launcher.exe +0 -0
  10. package/node_modules/@maka/acp-executor-plugin/dist/acp-catalog.js +132 -0
  11. package/node_modules/@maka/acp-executor-plugin/dist/index.js +251 -113
  12. package/node_modules/@maka/acp-executor-plugin/dist/plugin.mjs +431 -108
  13. package/node_modules/@maka/core/dist/executor-catalog.js +25 -3
  14. package/node_modules/@maka/core/dist/settings.js +2 -2
  15. package/node_modules/@maka/core/dist/tool-ledger-scanner.js +53 -150
  16. package/node_modules/@maka/runtime/dist/admission-limiter.js +3 -2
  17. package/node_modules/@maka/runtime/dist/ai-sdk-compaction.js +8 -1
  18. package/node_modules/@maka/runtime/dist/conversation-copy.js +6 -0
  19. package/node_modules/@maka/runtime/dist/plugin-data-services.js +7 -0
  20. package/node_modules/@maka/runtime/dist/plugin-executor-service.js +19 -3
  21. package/node_modules/@maka/runtime/dist/runtime-event-read-model.js +17 -0
  22. package/node_modules/@maka/runtime/dist/session-manager.js +26 -40
  23. package/node_modules/@maka/runtime/dist/stream-graph-coordinator.js +79 -13
  24. package/node_modules/@maka/runtime/dist/stream-graph-projection.js +64 -0
  25. package/node_modules/@maka/runtime/dist/stream-graph-read-model.js +138 -20
  26. package/node_modules/@maka/runtime/dist/tool-availability.js +10 -3
  27. package/node_modules/@maka/runtime/package.json +1 -0
  28. package/node_modules/@maka/runtime-host/dist/antigravity-program.js +49 -0
  29. package/node_modules/@maka/runtime-host/dist/candidate-entry.js +15 -0
  30. package/node_modules/@maka/runtime-host/dist/candidate-startup-failure.js +5 -0
  31. package/node_modules/@maka/runtime-host/dist/client/session-catalog-summary.js +1 -0
  32. package/node_modules/@maka/runtime-host/dist/client/startup-error.js +5 -0
  33. package/node_modules/@maka/runtime-host/dist/protocol/agent-graph.js +46 -1
  34. package/node_modules/@maka/runtime-host/dist/protocol/index.js +16 -1
  35. package/node_modules/@maka/runtime-host/dist/protocol/operations.js +5 -1
  36. package/node_modules/@maka/runtime-host/dist/protocol/plugin-platform.js +8 -2
  37. package/node_modules/@maka/runtime-host/dist/protocol/session-catalog.js +12 -0
  38. package/node_modules/@maka/runtime-host/dist/protocol/session-retirement.js +46 -10
  39. package/node_modules/@maka/runtime-host/dist/protocol/storage-usage.js +155 -0
  40. package/node_modules/@maka/runtime-host/dist/server/acp/antigravity.js +5 -19
  41. package/node_modules/@maka/runtime-host/dist/server/agent-graph-coordinator.js +23 -0
  42. package/node_modules/@maka/runtime-host/dist/server/canonical-turn-snapshot.js +5 -0
  43. package/node_modules/@maka/runtime-host/dist/server/execution-composition.js +41 -9
  44. package/node_modules/@maka/runtime-host/dist/server/external-agent-setup-coordinator.js +3 -0
  45. package/node_modules/@maka/runtime-host/dist/server/hosted-execution-tool-profile.js +2 -0
  46. package/node_modules/@maka/runtime-host/dist/server/plugin-data-runtime.js +6 -0
  47. package/node_modules/@maka/runtime-host/dist/server/plugin-scratch-directory.js +55 -0
  48. package/node_modules/@maka/runtime-host/dist/server/session-catalog-coordinator.js +46 -6
  49. package/node_modules/@maka/runtime-host/dist/server/session-retirement-coordinator.js +112 -36
  50. package/node_modules/@maka/runtime-host/dist/server/session-revision-coordinator.js +27 -1
  51. package/node_modules/@maka/runtime-host/dist/server/storage-usage-coordinator.js +67 -0
  52. package/node_modules/@maka/runtime-host/dist/server/workhub-inspection-tool.js +208 -0
  53. package/node_modules/@maka/runtime-host/package.json +1 -0
  54. package/node_modules/@maka/storage/dist/git-worktree-child-executor.js +3 -1
  55. package/node_modules/@maka/storage/dist/operational-state-store.js +0 -13
  56. package/node_modules/@maka/storage/dist/session-store.js +9 -6
  57. package/node_modules/@maka/storage/dist/sqlite-file-set.js +22 -0
  58. package/node_modules/@maka/storage/dist/sqlite-long-term-memory-store.js +1 -3
  59. package/node_modules/@maka/storage/dist/sqlite-runtime-store.js +10 -260
  60. package/node_modules/@maka/storage/dist/sqlite-session-catalog-query.js +1 -0
  61. package/node_modules/@maka/storage/dist/sqlite-session-metadata-schema.js +18 -6
  62. package/node_modules/@maka/storage/dist/sqlite-session-metadata-store.js +28 -6
  63. package/node_modules/@maka/storage/dist/storage-footprint.js +239 -0
  64. package/node_modules/@maka/storage/dist/storage-writer-composition.js +10 -1
  65. package/node_modules/axios/CHANGELOG.md +62 -0
  66. package/node_modules/axios/README.md +297 -5
  67. package/node_modules/axios/dist/axios.js +728 -170
  68. package/node_modules/axios/dist/axios.min.js +3 -3
  69. package/node_modules/axios/dist/browser/axios.cjs +871 -188
  70. package/node_modules/axios/dist/esm/axios.js +871 -188
  71. package/node_modules/axios/dist/esm/axios.min.js +2 -2
  72. package/node_modules/axios/dist/node/axios.cjs +1037 -225
  73. package/node_modules/axios/lib/adapters/fetch.js +64 -11
  74. package/node_modules/axios/lib/adapters/http.js +140 -67
  75. package/node_modules/axios/lib/adapters/xhr.js +52 -3
  76. package/node_modules/axios/lib/core/Axios.js +43 -20
  77. package/node_modules/axios/lib/core/AxiosError.js +33 -2
  78. package/node_modules/axios/lib/core/AxiosHeaders.js +124 -1
  79. package/node_modules/axios/lib/core/InterceptorManager.js +107 -8
  80. package/node_modules/axios/lib/core/buildFullPath.js +41 -15
  81. package/node_modules/axios/lib/core/dispatchRequest.js +8 -2
  82. package/node_modules/axios/lib/core/mergeConfig.js +19 -4
  83. package/node_modules/axios/lib/core/methodList.js +17 -0
  84. package/node_modules/axios/lib/core/setFormDataHeaders.js +27 -0
  85. package/node_modules/axios/lib/defaults/index.js +2 -1
  86. package/node_modules/axios/lib/env/data.js +1 -1
  87. package/node_modules/axios/lib/helpers/Http2Sessions.js +2 -0
  88. package/node_modules/axios/lib/helpers/HttpStatusCode.js +12 -1
  89. package/node_modules/axios/lib/helpers/combineURLs.js +11 -3
  90. package/node_modules/axios/lib/helpers/composeSignals.js +12 -1
  91. package/node_modules/axios/lib/helpers/estimateDataURLDecodedBytes.js +115 -54
  92. package/node_modules/axios/lib/helpers/formDataToJSON.js +11 -5
  93. package/node_modules/axios/lib/helpers/fromDataURI.js +5 -4
  94. package/node_modules/axios/lib/helpers/normalizeURLForProtocolCheck.js +24 -0
  95. package/node_modules/axios/lib/helpers/parseHeaders.js +5 -3
  96. package/node_modules/axios/lib/helpers/progressEventReducer.js +4 -4
  97. package/node_modules/axios/lib/helpers/resolveConfig.js +5 -17
  98. package/node_modules/axios/lib/helpers/shouldBypassProxy.js +300 -5
  99. package/node_modules/axios/lib/helpers/throttle.js +3 -2
  100. package/node_modules/axios/lib/helpers/toFormData.js +17 -23
  101. package/node_modules/axios/lib/platform/node/classes/Buffer.js +11 -0
  102. package/node_modules/axios/lib/utils.js +151 -18
  103. package/node_modules/axios/package.json +21 -19
  104. package/node_modules/brace-expansion/dist/commonjs/index.js +69 -25
  105. package/node_modules/brace-expansion/dist/esm/index.js +68 -24
  106. package/node_modules/brace-expansion/package.json +2 -1
  107. package/node_modules/fast-uri/index.js +10 -6
  108. package/node_modules/fast-uri/package.json +1 -1
  109. package/package.json +1 -1
@@ -23,12 +23,17 @@ export function isExecutorConfiguration(value) {
23
23
  if (!value || typeof value !== 'object' || Array.isArray(value))
24
24
  return false;
25
25
  const record = value;
26
- return (Object.keys(record).every((key) => key === 'model') &&
26
+ return (Object.keys(record).every((key) => key === 'model' || key === 'mode') &&
27
27
  (record.model === undefined ||
28
28
  (typeof record.model === 'string' &&
29
29
  record.model.length > 0 &&
30
30
  record.model.length <= 1024 &&
31
- !/[\0\r\n]/u.test(record.model))));
31
+ !/[\0\r\n]/u.test(record.model))) &&
32
+ (record.mode === undefined ||
33
+ (typeof record.mode === 'string' &&
34
+ record.mode.length > 0 &&
35
+ record.mode.length <= 1024 &&
36
+ !/[\0\r\n]/u.test(record.mode))));
32
37
  }
33
38
  export function normalizeCatalogEntry(value, id) {
34
39
  if (!value ||
@@ -54,8 +59,18 @@ export function normalizeCatalogEntry(value, id) {
54
59
  (model.providerType === undefined || CATALOG_PROVIDER_TYPES.includes(model.providerType))) ||
55
60
  new Set(value.models.map((model) => model.id)).size !== value.models.length ||
56
61
  !isExecutorConfiguration({ model: value.currentModel }) ||
62
+ (value.modes !== undefined &&
63
+ (!Array.isArray(value.modes) ||
64
+ value.modes.length > 64 ||
65
+ !value.modes.every((mode) => mode &&
66
+ typeof mode.id === 'string' &&
67
+ isExecutorConfiguration({ mode: mode.id }) &&
68
+ isCatalogText(mode.name)) ||
69
+ new Set(value.modes.map((mode) => mode.id)).size !== value.modes.length)) ||
70
+ !isExecutorConfiguration({ mode: value.currentMode }) ||
57
71
  typeof value.supportsAttachments !== 'boolean' ||
58
- typeof value.supportsModelChange !== 'boolean')
72
+ typeof value.supportsModelChange !== 'boolean' ||
73
+ (value.supportsModeChange !== undefined && typeof value.supportsModeChange !== 'boolean'))
59
74
  throw new TypeError('Executor catalog is invalid');
60
75
  const usedModels = new Set();
61
76
  const groupIds = new Set();
@@ -106,8 +121,15 @@ export function normalizeCatalogEntry(value, id) {
106
121
  }
107
122
  : {}),
108
123
  ...(value.currentModel !== undefined ? { currentModel: value.currentModel } : {}),
124
+ ...(value.modes !== undefined
125
+ ? { modes: Object.freeze(value.modes.map(({ id, name }) => Object.freeze({ id, name }))) }
126
+ : {}),
127
+ ...(value.currentMode !== undefined ? { currentMode: value.currentMode } : {}),
109
128
  supportsAttachments: value.supportsAttachments,
110
129
  supportsModelChange: value.supportsModelChange,
130
+ ...(value.supportsModeChange !== undefined
131
+ ? { supportsModeChange: value.supportsModeChange }
132
+ : {}),
111
133
  });
112
134
  }
113
135
  function isCatalogText(value) {
@@ -340,7 +340,7 @@ export function createDefaultSettings() {
340
340
  activeTab: 'requests',
341
341
  },
342
342
  appearance: {
343
- workbarTogglePosition: 'edge',
343
+ workbarTogglePosition: 'titlebar',
344
344
  theme: 'auto',
345
345
  palette: 'default',
346
346
  appIcon: DEFAULT_APP_ICON,
@@ -517,7 +517,7 @@ export function normalizeSettings(input) {
517
517
  // position; UI density is no longer a product setting.
518
518
  appearance: {
519
519
  ...appearanceWithoutLegacyFields,
520
- workbarTogglePosition: base.appearance.workbarTogglePosition === 'titlebar' ? 'titlebar' : 'edge',
520
+ workbarTogglePosition: base.appearance.workbarTogglePosition === 'edge' ? 'edge' : 'titlebar',
521
521
  palette: isThemePalette(base.appearance.palette) ? base.appearance.palette : 'default',
522
522
  // Same fail-closed rule as `palette` above, for the same reason: an
523
523
  // unknown id would otherwise reach the main process and resolve to a
@@ -132,37 +132,46 @@ export function validateGenericToolLedgerAppend(event) {
132
132
  */
133
133
  export function validateToolLedgerTransition(input) {
134
134
  const reducer = new ToolLedgerReducer(input.existingEvents);
135
- const validation = validateIncrementalToolLedgerTransition({
136
- reducer,
137
- candidateEvents: input.candidateEvents,
138
- expectedTransition: input.expectedTransition,
139
- });
140
- if (validation.ok) {
141
- reducer.commit(validation.checkpoint);
142
- return { ok: true };
135
+ const existing = reducer.scan();
136
+ if (existing.hasCorruption) {
137
+ return { source: 'existing', ...issueValidation(existing.issues[0]) };
138
+ }
139
+ const candidates = [];
140
+ for (const candidate of input.candidateEvents) {
141
+ const prior = reducer.event(candidate.id);
142
+ if (!prior) {
143
+ candidates.push(candidate);
144
+ continue;
145
+ }
146
+ if (!nodeUtil.isDeepStrictEqual(prior, candidate)) {
147
+ return {
148
+ ok: false,
149
+ source: 'candidate',
150
+ code: 'duplicate_event_id',
151
+ eventId: candidate.id,
152
+ };
153
+ }
143
154
  }
144
- const { source: _source, ...failure } = validation;
145
- return failure;
155
+ const shape = validateTransitionShape(candidates, input.expectedTransition);
156
+ if (!shape.ok)
157
+ return { source: 'candidate', ...shape };
158
+ reducer.append(candidates);
159
+ const issue = reducer.scan().issues[0];
160
+ return issue ? { source: 'candidate', ...issueValidation(issue) } : { ok: true };
146
161
  }
147
162
  /**
148
- * Stateful interpretation of an immutable RuntimeEvent prefix.
149
- *
150
- * Candidate appends mutate the reducer behind a checkpoint. The caller either
151
- * commits that checkpoint after durable transaction commit or rolls it back.
152
- * Rollback records only the fields touched by the candidate batch, so a small
153
- * append does not clone maps proportional to the full checked prefix.
163
+ * Invocation-scoped interpretation shared by scans and prospective validation.
164
+ * Each caller owns a fresh reducer; no state survives a validation call.
154
165
  */
155
- export class ToolLedgerReducer {
166
+ class ToolLedgerReducer {
156
167
  operations = [];
157
168
  issues = [];
158
169
  eventsById = new Map();
159
170
  byToolCall = new Map();
160
171
  byOperation = new Map();
161
172
  invocationSpines = new Map();
162
- undoLog = [];
163
- recordUndo = false;
164
- constructor(events = []) {
165
- this.consume(events, false);
173
+ constructor(events) {
174
+ this.append(events);
166
175
  }
167
176
  scan() {
168
177
  const dependencyIssues = this.toolDependencyIssues();
@@ -195,45 +204,16 @@ export class ToolLedgerReducer {
195
204
  event(eventId) {
196
205
  return this.eventsById.get(eventId);
197
206
  }
198
- checkpoint() {
199
- return this.undoLog.length;
200
- }
201
207
  append(events) {
202
- this.consume(events, true);
203
- }
204
- rollback(checkpoint) {
205
- this.assertCheckpoint(checkpoint);
206
- for (let index = this.undoLog.length - 1; index >= checkpoint; index -= 1) {
207
- this.undoLog[index]();
208
- }
209
- this.undoLog.length = checkpoint;
210
- }
211
- commit(checkpoint) {
212
- this.assertCheckpoint(checkpoint);
213
- this.undoLog.length = checkpoint;
214
- }
215
- assertCheckpoint(checkpoint) {
216
- if (!Number.isSafeInteger(checkpoint) || checkpoint < 0 || checkpoint > this.undoLog.length) {
217
- throw new RangeError('Invalid tool ledger reducer checkpoint');
218
- }
219
- }
220
- consume(events, recordUndo) {
221
- const previous = this.recordUndo;
222
- this.recordUndo = recordUndo;
223
- try {
224
- for (const event of events)
225
- this.consumeEvent(event);
226
- }
227
- finally {
228
- this.recordUndo = previous;
229
- }
208
+ for (const event of events)
209
+ this.consumeEvent(event);
230
210
  }
231
211
  consumeEvent(event) {
232
212
  if (this.eventsById.has(event.id)) {
233
213
  this.addIssue(undefined, { code: 'duplicate_event_id', eventId: event.id });
234
214
  return;
235
215
  }
236
- this.setMap(this.eventsById, event.id, event);
216
+ this.eventsById.set(event.id, event);
237
217
  const spine = JSON.stringify([event.sessionId, event.runId, event.turnId]);
238
218
  const existingSpine = this.invocationSpines.get(event.invocationId);
239
219
  if (existingSpine !== undefined && existingSpine !== spine) {
@@ -243,7 +223,7 @@ export class ToolLedgerReducer {
243
223
  });
244
224
  }
245
225
  else {
246
- this.setMap(this.invocationSpines, event.invocationId, spine);
226
+ this.invocationSpines.set(event.invocationId, spine);
247
227
  }
248
228
  const lane = validateToolLedgerEventLane(event);
249
229
  if (!lane.ok) {
@@ -260,7 +240,7 @@ export class ToolLedgerReducer {
260
240
  const existing = this.byToolCall.get(toolCallKey);
261
241
  if (existing) {
262
242
  if (!existing.callEvent) {
263
- this.setOperationField(existing, 'callEvent', event);
243
+ existing.callEvent = event;
264
244
  if (existing.toolName !== content.name) {
265
245
  this.addIssue(existing, {
266
246
  code: 'identity_conflict',
@@ -287,8 +267,8 @@ export class ToolLedgerReducer {
287
267
  decisionEvents: [],
288
268
  issues: [],
289
269
  };
290
- this.setMap(this.byToolCall, toolCallKey, operation);
291
- this.push(this.operations, operation);
270
+ this.byToolCall.set(toolCallKey, operation);
271
+ this.operations.push(operation);
292
272
  return;
293
273
  }
294
274
  if (lane.lane === 'tool_dispatch') {
@@ -307,8 +287,8 @@ export class ToolLedgerReducer {
307
287
  decisionEvents: [],
308
288
  issues: [],
309
289
  };
310
- this.setMap(this.byToolCall, toolCallKey, operation);
311
- this.push(this.operations, operation);
290
+ this.byToolCall.set(toolCallKey, operation);
291
+ this.operations.push(operation);
312
292
  this.addIssue(operation, {
313
293
  code: 'event_order_conflict',
314
294
  eventId: event.id,
@@ -333,14 +313,14 @@ export class ToolLedgerReducer {
333
313
  operationId: dispatch.operationId,
334
314
  toolCallId: dispatch.providerToolCallId,
335
315
  };
336
- this.push(this.issues, issue);
337
- this.push(existingOperation.issues, issue);
338
- this.push(operation.issues, issue);
316
+ this.issues.push(issue);
317
+ existingOperation.issues.push(issue);
318
+ operation.issues.push(issue);
339
319
  return;
340
320
  }
341
- this.setOperationField(operation, 'operationId', dispatch.operationId);
342
- this.setOperationField(operation, 'dispatchEvent', event);
343
- this.setMap(this.byOperation, dispatch.operationId, operation);
321
+ operation.operationId = dispatch.operationId;
322
+ operation.dispatchEvent = event;
323
+ this.byOperation.set(dispatch.operationId, operation);
344
324
  if (operation.toolName !== dispatch.toolName ||
345
325
  event.refs?.operationId !== dispatch.operationId ||
346
326
  event.refs?.toolCallId !== dispatch.providerToolCallId ||
@@ -406,8 +386,8 @@ export class ToolLedgerReducer {
406
386
  decisionEvents: [],
407
387
  issues: [],
408
388
  };
409
- this.push(this.operations, orphan);
410
- this.setMap(this.byToolCall, toolCallKey, orphan);
389
+ this.operations.push(orphan);
390
+ this.byToolCall.set(toolCallKey, orphan);
411
391
  this.addIssue(orphan, {
412
392
  code: 'orphan_response',
413
393
  eventId: event.id,
@@ -424,7 +404,7 @@ export class ToolLedgerReducer {
424
404
  });
425
405
  return;
426
406
  }
427
- this.setOperationField(operation, 'responseEvent', event);
407
+ operation.responseEvent = event;
428
408
  if (operation.toolName !== content.name ||
429
409
  !sameExecutionIdentity(operation.callEvent, event) ||
430
410
  (operation.operationId !== undefined &&
@@ -454,48 +434,15 @@ export class ToolLedgerReducer {
454
434
  return;
455
435
  }
456
436
  if (lane.lane === 'reconcile_result')
457
- this.push(operation.reconcileEvents, event);
437
+ operation.reconcileEvents.push(event);
458
438
  else
459
- this.push(operation.decisionEvents, event);
439
+ operation.decisionEvents.push(event);
460
440
  }
461
441
  }
462
442
  addIssue(operation, issue) {
463
- this.push(this.issues, issue);
443
+ this.issues.push(issue);
464
444
  if (operation)
465
- this.push(operation.issues, issue);
466
- }
467
- push(values, value) {
468
- const length = values.length;
469
- this.undo(() => {
470
- values.length = length;
471
- });
472
- values.push(value);
473
- }
474
- setMap(values, key, value) {
475
- const had = values.has(key);
476
- const previous = values.get(key);
477
- this.undo(() => {
478
- if (had)
479
- values.set(key, previous);
480
- else
481
- values.delete(key);
482
- });
483
- values.set(key, value);
484
- }
485
- setOperationField(operation, key, value) {
486
- const had = Object.hasOwn(operation, key);
487
- const previous = operation[key];
488
- this.undo(() => {
489
- if (had)
490
- operation[key] = previous;
491
- else
492
- delete operation[key];
493
- });
494
- operation[key] = value;
495
- }
496
- undo(operation) {
497
- if (this.recordUndo)
498
- this.undoLog.push(operation);
445
+ operation.issues.push(issue);
499
446
  }
500
447
  toolDependencyIssues() {
501
448
  const result = [];
@@ -579,53 +526,9 @@ export class ToolLedgerReducer {
579
526
  return result;
580
527
  }
581
528
  }
582
- /**
583
- * Applies one prospective writer batch to a checked prefix. A successful call
584
- * leaves the candidate delta applied until the caller commits or rolls back the
585
- * returned checkpoint. A rejected candidate restores the reducer immediately.
586
- */
587
- export function validateIncrementalToolLedgerTransition(input) {
588
- const existing = input.reducer.scan();
589
- if (existing.hasCorruption) {
590
- return { source: 'existing', ...issueValidation(existing.issues[0]) };
591
- }
592
- const candidates = [];
593
- for (const candidate of input.candidateEvents) {
594
- const prior = input.reducer.event(candidate.id);
595
- if (!prior) {
596
- candidates.push(candidate);
597
- continue;
598
- }
599
- if (!nodeUtil.isDeepStrictEqual(prior, candidate)) {
600
- return {
601
- ok: false,
602
- source: 'candidate',
603
- code: 'duplicate_event_id',
604
- eventId: candidate.id,
605
- };
606
- }
607
- }
608
- const shape = validateTransitionShape(candidates, input.expectedTransition);
609
- if (!shape.ok)
610
- return { source: 'candidate', ...shape };
611
- const checkpoint = input.reducer.checkpoint();
612
- try {
613
- input.reducer.append(candidates);
614
- }
615
- catch (error) {
616
- input.reducer.rollback(checkpoint);
617
- throw error;
618
- }
619
- const issue = input.reducer.scan().issues[0];
620
- if (issue) {
621
- input.reducer.rollback(checkpoint);
622
- return { source: 'candidate', ...issueValidation(issue) };
623
- }
624
- return { ok: true, checkpoint, appendedEvents: candidates.length };
625
- }
626
529
  /**
627
530
  * Scans immutable RuntimeEvents once, in physical ledger order. Resolver,
628
- * projection rebuild and incremental writers all use the same reducer rules.
531
+ * projection rebuild and prospective writers all use the same reducer rules.
629
532
  */
630
533
  export function scanToolLedger(events) {
631
534
  return new ToolLedgerReducer(events).scan();
@@ -19,12 +19,13 @@
19
19
  /**
20
20
  * Abort-aware FIFO permits, bounded by capacity.
21
21
  *
22
- * Two boundaries use it, at different lifetimes. Child-agent runs take one
22
+ * Boundaries use it at different lifetimes. Child-agent runs take one
23
23
  * instance per turn: tool-call admission and child-run capacity are separate
24
24
  * boundaries, since one admitted tool may eventually spawn multiple children,
25
25
  * so the limiter belongs at the narrow spawn capability where every caller
26
26
  * shares the same real-run budget. Code Mode cells take one per backend, which
27
- * has to outlive a turn — see `executeCodeModeCell`.
27
+ * has to outlive a turn — see `executeCodeModeCell`. ACP catalog probes share
28
+ * one per runtime Entry and hold permits through process cleanup.
28
29
  *
29
30
  * A caller that must turn work away rather than queue it reads `waitingCount`
30
31
  * before calling `acquire`. Nothing awaits between that read and the enqueue
@@ -132,7 +132,14 @@ export class AiSdkCompaction {
132
132
  if (previousCheckpoint) {
133
133
  const match = matchHistoryCompactCheckpointPrefix(previousCheckpoint, runtimeContext);
134
134
  if (!match.reason && match.successorRuntimeEvents.length === 0) {
135
- {
135
+ // Raw identity is not enough: a projection transition committed
136
+ // after the fold rewrites the covered span's effective view without
137
+ // touching the raw ledger, so reuse requires the pinned effective
138
+ // digest to still match — the same gate the pre-send path applies
139
+ // (#5929). On drift, fall through to the planner, whose roll-forward
140
+ // currency check discards the stale checkpoint and re-summarizes.
141
+ const effectiveCovered = await this.foldEffectiveModelHistory(match.coveredRuntimeEvents);
142
+ if (this.checkpointEffectiveCoverageMatches(previousCheckpoint, effectiveCovered)) {
136
143
  const projectedEvents = projectHistoryCompactCheckpointReplay(previousCheckpoint, match.coveredRuntimeEvents, []);
137
144
  return {
138
145
  outcome: { kind: 'unchanged', reason: 'already_compacted' },
@@ -529,6 +529,12 @@ export async function cloneConversationRuntimeLedger(input) {
529
529
  await input.runStore.appendEvent(input.referenceMap.targetSessionId, runId, clonedEvent);
530
530
  }
531
531
  if (plan.terminal.kind === 'fact' && terminalEvent) {
532
+ // The preflight rejects handoff lineage before a plan reaches cloning,
533
+ // so a handed-off run never gets here; the guard keeps the outcome type
534
+ // honest at the boundary.
535
+ if (plan.terminal.fact.runStatus === 'handed_off') {
536
+ throw new Error(`Copied AgentRun ${plan.run.runId} carries unresolved handoff lineage`);
537
+ }
532
538
  await commitTerminalRunWithRuntimeFact({
533
539
  runtimeEventStore: input.runtimeEventStore,
534
540
  newId: input.newId,
@@ -131,6 +131,13 @@ export class PluginStorageService extends PluginNamespacedDataService {
131
131
  const result = await this.mutateValues([{ key, value, ...options }]);
132
132
  return result[key];
133
133
  }
134
+ /** The callback must drain any process using the directory before settling. */
135
+ withScratchDirectory(key, signal, use) {
136
+ const runtime = this.runtime();
137
+ if (!runtime.withScratchDirectory)
138
+ throw new Error('Plugin scratch directories are unavailable');
139
+ return runtime.withScratchDirectory(this.namespace(), validKey(key), signal, use);
140
+ }
134
141
  async delete(key, options = {}) {
135
142
  const result = await this.mutateValues([{ key, ...options }]);
136
143
  return result[key];
@@ -66,6 +66,9 @@ export class PluginExecutorService extends Service {
66
66
  ? { configureConversation: provider.configureConversation.bind(provider) }
67
67
  : {}),
68
68
  ...(provider.discover ? { discover: provider.discover.bind(provider) } : {}),
69
+ ...(provider.invalidateCatalog
70
+ ? { invalidateCatalog: provider.invalidateCatalog.bind(provider) }
71
+ : {}),
69
72
  ...(provider.inspectConversation
70
73
  ? { inspectConversation: provider.inspectConversation.bind(provider) }
71
74
  : {}),
@@ -152,7 +155,11 @@ export class PluginExecutorService extends Service {
152
155
  cwd: input.cwd,
153
156
  ...(input.configuration ? { configuration: input.configuration } : {}),
154
157
  })
155
- : await entry.provider.discover?.({ cwd: input.cwd, signal: combined });
158
+ : await entry.provider.discover?.({
159
+ cwd: input.cwd,
160
+ signal: combined,
161
+ ...(input.refresh ? { refresh: true } : {}),
162
+ });
156
163
  combined.throwIfAborted();
157
164
  if (!result)
158
165
  return fallback;
@@ -163,6 +170,12 @@ export class PluginExecutorService extends Service {
163
170
  }
164
171
  })));
165
172
  }
173
+ invalidateCatalog() {
174
+ for (const entry of this.registry.entries('profile')) {
175
+ if (!entry.retired)
176
+ entry.provider.invalidateCatalog?.();
177
+ }
178
+ }
166
179
  async configureConversation(sessionId, executorId, input) {
167
180
  const entry = this.entry(sessionId, executorId);
168
181
  const configure = entry.provider.configureConversation;
@@ -171,8 +184,11 @@ export class PluginExecutorService extends Service {
171
184
  throw new Error('Executor configuration is unavailable or busy');
172
185
  if (!isExecutorConfiguration(input.configuration))
173
186
  throw new TypeError('Invalid executor configuration');
174
- await this.withActiveOperation(entry, { conversationKey: input.conversationKey }, async (signal) => {
175
- await configure(input, AbortSignal.any([signal, AbortSignal.timeout(30_000)]));
187
+ return await this.withActiveOperation(entry, { conversationKey: input.conversationKey }, async (signal) => {
188
+ const confirmed = await configure(input, AbortSignal.any([signal, AbortSignal.timeout(30_000)]));
189
+ if (confirmed !== undefined && !isExecutorConfiguration(confirmed))
190
+ throw new TypeError('Invalid confirmed executor configuration');
191
+ return confirmed;
176
192
  });
177
193
  }
178
194
  /** Task retirement releases retained provider resources; backend refresh must not. */
@@ -567,6 +567,23 @@ export function classifyRuntimeEventTerminalFact(invocation, events) {
567
567
  return { diagnostics };
568
568
  }
569
569
  const terminalEvent = terminalSignals[0];
570
+ // A handoff pause seals the run without ending the turn: the successor run
571
+ // owns the turn's terminal state. The pause carries no terminal status by
572
+ // design — completed/failed/aborted would each be a lie about a run that was
573
+ // none of them — so it classifies as its own status. The event is immutable
574
+ // once written, so ledgers written before this classification carry exactly
575
+ // this shape.
576
+ if (terminalEvent.actions?.handoffPause) {
577
+ const fact = {
578
+ runId: invocation.runId,
579
+ turnId: invocation.turnId,
580
+ runStatus: 'handed_off',
581
+ turnStatus: 'handed_off',
582
+ terminalEvent,
583
+ diagnostics,
584
+ };
585
+ return { fact, diagnostics };
586
+ }
570
587
  if (!isTerminalRuntimeEventStatus(terminalEvent.status)) {
571
588
  diagnostics.push(readModelDiagnostic('incomplete_event', 'terminal RuntimeEvent requires a terminal status for recovery', terminalEvent));
572
589
  return { diagnostics };