@yu_robotics/remote-cli 1.6.244 → 1.6.251

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 (155) hide show
  1. package/dist/client/MessageHandler.d.ts +6 -2
  2. package/dist/client/MessageHandler.d.ts.map +1 -1
  3. package/dist/client/MessageHandler.js +144 -48
  4. package/dist/client/MessageHandler.js.map +1 -1
  5. package/dist/client/WebSocketClient.d.ts +3 -0
  6. package/dist/client/WebSocketClient.d.ts.map +1 -1
  7. package/dist/client/WebSocketClient.js +3 -1
  8. package/dist/client/WebSocketClient.js.map +1 -1
  9. package/dist/commands/start.d.ts +5 -0
  10. package/dist/commands/start.d.ts.map +1 -1
  11. package/dist/commands/start.js +37 -0
  12. package/dist/commands/start.js.map +1 -1
  13. package/dist/executor/AgyExecutor.d.ts +39 -2
  14. package/dist/executor/AgyExecutor.d.ts.map +1 -1
  15. package/dist/executor/AgyExecutor.js +383 -38
  16. package/dist/executor/AgyExecutor.js.map +1 -1
  17. package/dist/executor/ClaudePersistentExecutor.d.ts.map +1 -1
  18. package/dist/executor/ClaudePersistentExecutor.js +29 -16
  19. package/dist/executor/ClaudePersistentExecutor.js.map +1 -1
  20. package/dist/executor/DshExecutor.d.ts +1 -0
  21. package/dist/executor/DshExecutor.d.ts.map +1 -1
  22. package/dist/executor/IExecutor.d.ts +1 -1
  23. package/dist/executor/IExecutor.d.ts.map +1 -1
  24. package/dist/executor/acp/AcpClient.d.ts +5 -0
  25. package/dist/executor/acp/AcpClient.d.ts.map +1 -1
  26. package/dist/executor/acp/AcpClient.js +19 -1
  27. package/dist/executor/acp/AcpClient.js.map +1 -1
  28. package/dist/executor/agy/AgyAcpRuntime.d.ts +82 -0
  29. package/dist/executor/agy/AgyAcpRuntime.d.ts.map +1 -0
  30. package/dist/executor/agy/AgyAcpRuntime.js +390 -0
  31. package/dist/executor/agy/AgyAcpRuntime.js.map +1 -0
  32. package/dist/executor/index.d.ts.map +1 -1
  33. package/dist/executor/index.js +2 -1
  34. package/dist/executor/index.js.map +1 -1
  35. package/dist/files/FileInbox.d.ts +1 -0
  36. package/dist/files/FileInbox.d.ts.map +1 -1
  37. package/dist/files/FileInbox.js +49 -4
  38. package/dist/files/FileInbox.js.map +1 -1
  39. package/dist/index.js +2 -0
  40. package/dist/index.js.map +1 -1
  41. package/dist/maintenance/release-notes.json +1 -1
  42. package/dist/managed/tools.d.ts +2 -2
  43. package/dist/scheduling/ScheduleCapabilities.d.ts +4 -4
  44. package/dist/scheduling/ScheduleCapabilities.d.ts.map +1 -1
  45. package/dist/scheduling/ScheduleCapabilities.js +6 -6
  46. package/dist/scheduling/ScheduleCapabilities.js.map +1 -1
  47. package/dist/scheduling/ScheduleCleanup.js +1 -1
  48. package/dist/scheduling/ScheduleCleanup.js.map +1 -1
  49. package/dist/scheduling/ScheduleCommand.d.ts +1 -0
  50. package/dist/scheduling/ScheduleCommand.d.ts.map +1 -1
  51. package/dist/scheduling/ScheduleCommand.js +9 -3
  52. package/dist/scheduling/ScheduleCommand.js.map +1 -1
  53. package/dist/scheduling/ScheduleService.d.ts +27 -1
  54. package/dist/scheduling/ScheduleService.d.ts.map +1 -1
  55. package/dist/scheduling/ScheduleService.js +235 -51
  56. package/dist/scheduling/ScheduleService.js.map +1 -1
  57. package/dist/scheduling/ScheduleToolScope.d.ts.map +1 -1
  58. package/dist/scheduling/ScheduleToolScope.js +12 -2
  59. package/dist/scheduling/ScheduleToolScope.js.map +1 -1
  60. package/dist/scheduling/agy/AgyCheckpoint.d.ts +35 -0
  61. package/dist/scheduling/agy/AgyCheckpoint.d.ts.map +1 -0
  62. package/dist/scheduling/agy/AgyCheckpoint.js +160 -0
  63. package/dist/scheduling/agy/AgyCheckpoint.js.map +1 -0
  64. package/dist/scheduling/agy/AgyHookRelay.d.ts +33 -0
  65. package/dist/scheduling/agy/AgyHookRelay.d.ts.map +1 -0
  66. package/dist/scheduling/agy/AgyHookRelay.js +274 -0
  67. package/dist/scheduling/agy/AgyHookRelay.js.map +1 -0
  68. package/dist/scheduling/agy/AgyScheduleHost.d.ts +42 -0
  69. package/dist/scheduling/agy/AgyScheduleHost.d.ts.map +1 -0
  70. package/dist/scheduling/agy/AgyScheduleHost.js +121 -0
  71. package/dist/scheduling/agy/AgyScheduleHost.js.map +1 -0
  72. package/dist/scheduling/agy/AgySessionSchedules.d.ts +109 -0
  73. package/dist/scheduling/agy/AgySessionSchedules.d.ts.map +1 -0
  74. package/dist/scheduling/agy/AgySessionSchedules.js +476 -0
  75. package/dist/scheduling/agy/AgySessionSchedules.js.map +1 -0
  76. package/dist/scheduling/agy/hookClient.d.ts +4 -0
  77. package/dist/scheduling/agy/hookClient.d.ts.map +1 -0
  78. package/dist/scheduling/agy/hookClient.js +62 -0
  79. package/dist/scheduling/agy/hookClient.js.map +1 -0
  80. package/dist/scheduling/agy/transcript.d.ts +36 -0
  81. package/dist/scheduling/agy/transcript.d.ts.map +1 -0
  82. package/dist/scheduling/agy/transcript.js +108 -0
  83. package/dist/scheduling/agy/transcript.js.map +1 -0
  84. package/dist/scheduling/claude/ClaudeSessionSchedules.d.ts +7 -0
  85. package/dist/scheduling/claude/ClaudeSessionSchedules.d.ts.map +1 -1
  86. package/dist/scheduling/claude/ClaudeSessionSchedules.js +157 -59
  87. package/dist/scheduling/claude/ClaudeSessionSchedules.js.map +1 -1
  88. package/dist/scheduling/toolContract.d.ts +1 -1
  89. package/dist/scheduling/toolContract.js +1 -1
  90. package/dist/scheduling/toolContract.js.map +1 -1
  91. package/dist/scheduling/types.d.ts +10 -2
  92. package/dist/scheduling/types.d.ts.map +1 -1
  93. package/dist/scheduling/types.js.map +1 -1
  94. package/dist/service/SessionHostSupervisor.d.ts +63 -0
  95. package/dist/service/SessionHostSupervisor.d.ts.map +1 -0
  96. package/dist/service/SessionHostSupervisor.js +323 -0
  97. package/dist/service/SessionHostSupervisor.js.map +1 -0
  98. package/dist/sessionHost/HostClient.d.ts +49 -0
  99. package/dist/sessionHost/HostClient.d.ts.map +1 -0
  100. package/dist/sessionHost/HostClient.js +101 -0
  101. package/dist/sessionHost/HostClient.js.map +1 -0
  102. package/dist/sessionHost/HostProtocol.d.ts +65 -0
  103. package/dist/sessionHost/HostProtocol.d.ts.map +1 -0
  104. package/dist/sessionHost/HostProtocol.js +78 -0
  105. package/dist/sessionHost/HostProtocol.js.map +1 -0
  106. package/dist/sessionHost/HostServer.d.ts +52 -0
  107. package/dist/sessionHost/HostServer.d.ts.map +1 -0
  108. package/dist/sessionHost/HostServer.js +413 -0
  109. package/dist/sessionHost/HostServer.js.map +1 -0
  110. package/dist/sessionHost/HostStore.d.ts +43 -0
  111. package/dist/sessionHost/HostStore.d.ts.map +1 -0
  112. package/dist/sessionHost/HostStore.js +206 -0
  113. package/dist/sessionHost/HostStore.js.map +1 -0
  114. package/dist/sessionHost/RetainedFrontend.d.ts +63 -0
  115. package/dist/sessionHost/RetainedFrontend.d.ts.map +1 -0
  116. package/dist/sessionHost/RetainedFrontend.js +244 -0
  117. package/dist/sessionHost/RetainedFrontend.js.map +1 -0
  118. package/dist/sessionHost/RetainedHostLauncher.d.ts +25 -0
  119. package/dist/sessionHost/RetainedHostLauncher.d.ts.map +1 -0
  120. package/dist/sessionHost/RetainedHostLauncher.js +132 -0
  121. package/dist/sessionHost/RetainedHostLauncher.js.map +1 -0
  122. package/dist/sessionHost/RetainedRuntime.d.ts +62 -0
  123. package/dist/sessionHost/RetainedRuntime.d.ts.map +1 -0
  124. package/dist/sessionHost/RetainedRuntime.js +478 -0
  125. package/dist/sessionHost/RetainedRuntime.js.map +1 -0
  126. package/dist/sessionHost/RuntimeJournal.d.ts +47 -0
  127. package/dist/sessionHost/RuntimeJournal.d.ts.map +1 -0
  128. package/dist/sessionHost/RuntimeJournal.js +103 -0
  129. package/dist/sessionHost/RuntimeJournal.js.map +1 -0
  130. package/dist/sessionHost/entry.d.ts +13 -0
  131. package/dist/sessionHost/entry.d.ts.map +1 -0
  132. package/dist/sessionHost/entry.js +107 -0
  133. package/dist/sessionHost/entry.js.map +1 -0
  134. package/dist/thread/ThreadManager.d.ts.map +1 -1
  135. package/dist/thread/ThreadManager.js +33 -0
  136. package/dist/thread/ThreadManager.js.map +1 -1
  137. package/dist/types/ScheduleCards.d.ts +1 -1
  138. package/dist/types/ScheduleCards.d.ts.map +1 -1
  139. package/dist/update/AutomaticUpdater.d.ts +2 -1
  140. package/dist/update/AutomaticUpdater.d.ts.map +1 -1
  141. package/dist/update/AutomaticUpdater.js +26 -12
  142. package/dist/update/AutomaticUpdater.js.map +1 -1
  143. package/dist/update/PinnedHostBundle.d.ts +49 -0
  144. package/dist/update/PinnedHostBundle.d.ts.map +1 -0
  145. package/dist/update/PinnedHostBundle.js +309 -0
  146. package/dist/update/PinnedHostBundle.js.map +1 -0
  147. package/native/prebuilds/darwin-arm64/managed_native.node +0 -0
  148. package/native/prebuilds/darwin-arm64/manifest.json +1 -1
  149. package/native/prebuilds/darwin-x64/managed_native.node +0 -0
  150. package/native/prebuilds/darwin-x64/manifest.json +1 -1
  151. package/native/prebuilds/win32-arm64/managed_native.node +0 -0
  152. package/native/prebuilds/win32-arm64/manifest.json +1 -1
  153. package/native/prebuilds/win32-x64/managed_native.node +0 -0
  154. package/native/prebuilds/win32-x64/manifest.json +1 -1
  155. package/package.json +1 -1
@@ -34,6 +34,8 @@ var __importStar = (this && this.__importStar) || (function () {
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.AgyExecutor = exports.parseAgyModels = void 0;
37
+ const AgyCheckpoint_1 = require("../scheduling/agy/AgyCheckpoint");
38
+ const AgyAcpRuntime_1 = require("./agy/AgyAcpRuntime");
37
39
  const ManagedSpawn_1 = require("./ManagedSpawn");
38
40
  const child_process_1 = require("child_process");
39
41
  const ManagedProcessGroups_1 = require("./ManagedProcessGroups");
@@ -112,7 +114,9 @@ const ABORTED_STATUSES = new Set(['INTERRUPTED', 'CANCELED']);
112
114
  * IExecutor implementation for the Antigravity CLI (`agy`) — Google's
113
115
  * agentic CLI from the Antigravity suite.
114
116
  *
115
- * agy speaks a Claude-Code-style stream-json protocol: one persistent
117
+ * Fresh production conversations use AgyAcpRuntime for shared native scheduling.
118
+ * Saved conversations and managed workers retain the compatible transport below.
119
+ * The legacy path speaks a Claude-Code-style stream-json protocol: one persistent
116
120
  * process per conversation, NDJSON prompts in on stdin
117
121
  * ({"event":"user","message":{"content":"..."}}), NDJSON events out on
118
122
  * stdout (init / step_update / result). Conversations survive process
@@ -166,7 +170,12 @@ class AgyExecutor {
166
170
  managedProcesses = new WeakSet();
167
171
  workerGroups = new ManagedProcessGroups_1.ManagedProcessGroups();
168
172
  delegationConfigured = false;
173
+ configuringTools = false;
169
174
  pendingExits = new Set();
175
+ /** A timeout is not exit evidence. Only an explicit joined retirement clears it. */
176
+ shutdownUncertain = false;
177
+ /** Invalidates prompts waiting for a predecessor when abort/reset retires their context. */
178
+ contextRevision = 0;
170
179
  /** Handoff summary from compactWhenFull, wrapped into the next prompt (consumed once). */
171
180
  pendingContextSeed = null;
172
181
  activityTracker = new Activity_1.ActivityTracker();
@@ -180,8 +189,165 @@ class AgyExecutor {
180
189
  preexistingNativeIds = new Set();
181
190
  observedNativeIds = new Set();
182
191
  resettingNativeContext = false;
192
+ acp;
193
+ acpEligible = false;
194
+ acpLeaseUnconfirmed = false;
195
+ nativeAcp;
196
+ resumePermit;
197
+ restoringCheckpoint;
198
+ cleanCheckpoint() {
199
+ try {
200
+ const value = this.checkpoint().read();
201
+ return value?.state === 'clean' ? value : undefined;
202
+ }
203
+ catch {
204
+ return;
205
+ } // Incompatible proof never grants admission or breaks legacy chat.
206
+ }
207
+ resumeCleanChat() {
208
+ if (this.acp || this.resumePermit || this.proc || this.acpLeaseUnconfirmed || this.scheduleOwner?.retired === false || !this.conversationId)
209
+ return;
210
+ const proof = this.cleanCheckpoint();
211
+ if (proof?.sessionId === this.conversationId && Object.keys(proof.jobs).length === 0) {
212
+ this.resumePermit = this.checkpoint().consume(this.conversationId);
213
+ if (this.scheduleOwner) {
214
+ fs.rmSync(this.sessionFilePath + '.native-schedules', { force: true });
215
+ this.scheduleOwner = undefined;
216
+ }
217
+ }
218
+ }
219
+ recoveryIdentity() { return JSON.stringify({ sessionId: this.conversationId, configuration: this.checkpoint().configuration }); }
220
+ checkpoint() {
221
+ return new AgyCheckpoint_1.AgyCheckpoint(this.sessionFilePath + '.checkpoint', (0, AgyCheckpoint_1.definitionDigest)([this.threadId, this.currentWorkingDirectory, this.agyCommand, this.model ?? null, this.effort ?? null, this.autoApprove]));
222
+ }
223
+ get nativeScheduleRecovery() {
224
+ if (!this.nativeAcp || !this.threadId || this.delegationWorker)
225
+ return;
226
+ return {
227
+ provider: 'agy-before-first-wake-v1', strategy: 'reconstruct', orderlyOnly: true,
228
+ describe: () => this.recoveryIdentity(),
229
+ finishRestart: async () => {
230
+ if (!this.acp?.checkpointClean)
231
+ throw new Error('AGY exact deadline-bounded handoff is not clean.');
232
+ await this.acp.close();
233
+ this.acp = undefined;
234
+ this.restoringCheckpoint = undefined;
235
+ },
236
+ reconcile: async (record, context, emit) => {
237
+ const checkpoint = this.checkpoint();
238
+ if (record.rule.kind === 'once' && Date.parse(record.rule.at) <= Date.now())
239
+ throw new Error('Expired AGY one-shot will not be reconstructed.');
240
+ if (record.recovery?.handoff !== 'clean' || record.recovery.identity !== this.recoveryIdentity()
241
+ || !context.isCurrent() || context.signal.aborted || record.cancelRequested)
242
+ throw new Error('AGY clean recovery ownership changed.');
243
+ const input = { id: record.id, backend: record.backend, threadId: record.threadId, cwd: record.cwd,
244
+ prompt: record.prompt, rule: record.rule, ...record.execution, recovery: record.recovery };
245
+ const proof = this.restoringCheckpoint ?? checkpoint.read();
246
+ if (!proof || proof.jobs[record.id] !== (0, AgyCheckpoint_1.scheduleDigest)(input))
247
+ throw new Error('AGY definition has no exact handoff proof.');
248
+ if (!this.restoringCheckpoint) {
249
+ if (this.acp || this.proc || this.acpLeaseUnconfirmed || this.scheduleOwner?.retired === false)
250
+ throw new Error('AGY predecessor retirement is not confirmed.');
251
+ this.resumePermit = checkpoint.consume(this.conversationId);
252
+ this.restoringCheckpoint = proof;
253
+ this.acp = undefined;
254
+ }
255
+ // Consume per-job proof before mutation. A partial restore is not a retry permit.
256
+ delete this.restoringCheckpoint.jobs[record.id];
257
+ return this.createNativeSchedule(input, emit, () => context.isOwnerCurrent?.() ?? context.isCurrent(), context.canAdmitOccurrence);
258
+ },
259
+ };
260
+ }
261
+ scheduleOwner;
262
+ writeNativeState(file, data) {
263
+ const temporary = file + '.tmp';
264
+ const fd = fs.openSync(temporary, 'w', 0o600);
265
+ try {
266
+ fs.writeFileSync(fd, JSON.stringify(data));
267
+ fs.fsyncSync(fd);
268
+ }
269
+ finally {
270
+ fs.closeSync(fd);
271
+ }
272
+ fs.renameSync(temporary, file);
273
+ }
274
+ assertNoRetainedSchedules() {
275
+ if (this.acp?.hasJobs || this.scheduleOwner?.sessionId === this.conversationId) {
276
+ throw new Error('AGY native notifications may remain queued. Reconfiguration/recovery of this conversation is unavailable; keep its schedule evidence and use a new thread.');
277
+ }
278
+ }
279
+ assertScheduleResettable() {
280
+ if (fs.existsSync(this.sessionFilePath + '.checkpoint.lock'))
281
+ throw new Error('AGY checkpoint transition is unconfirmed; retained state cannot be discarded.');
282
+ if (this.acpLeaseUnconfirmed && !this.acp)
283
+ throw new Error('Previous AGY ACP host retirement is unconfirmed; retained session and hook evidence cannot be discarded.');
284
+ if (this.scheduleOwner?.sessionId === this.conversationId && !this.scheduleOwner.retired) {
285
+ throw new Error('AGY native notifications have unresolved ownership; confirm exact host retirement before explicitly discarding this context.');
286
+ }
287
+ }
288
+ async stopForContextReset() {
289
+ if (this.acp)
290
+ await this.acp.close();
291
+ else
292
+ await this.abort();
293
+ }
294
+ acpRuntime() {
295
+ if (this.acp)
296
+ return this.acp;
297
+ this.resumeCleanChat();
298
+ if (((!this.acpEligible || this.conversationId) && !this.resumePermit) || !this.agyHome || !this.threadId || this.proc || this.isDestroyed) {
299
+ throw new Error('AGY scheduling requires a fresh ACP conversation. This saved/legacy conversation remains on its compatible transport; use a new AGY thread.');
300
+ }
301
+ const env = this.buildEnv();
302
+ // Both native HOME conventions must point to this thread on every platform.
303
+ env.HOME = this.agyHome;
304
+ env.USERPROFILE = this.agyHome;
305
+ this.acp = new AgyAcpRuntime_1.AgyAcpRuntime({ command: this.agyCommand, home: this.agyHome,
306
+ cwd: this.currentWorkingDirectory, threadId: this.threadId, model: this.model, effort: this.effort,
307
+ autoApprove: this.autoApprove, env, checkpoint: this.checkpoint(), resume: this.resumePermit, mcpServers: (0, contract_1.delegationSessionServers)(this.delegationConnection), mapTool: mapAgyTool,
308
+ saveSession: id => {
309
+ // Unlike legacy best-effort persistence, native scheduling cannot proceed
310
+ // without an original-session pointer on disk.
311
+ this.writeNativeState(this.sessionFilePath, { id, transport: 'acp', retired: false, savedAt: new Date().toISOString() });
312
+ this.conversationId = id;
313
+ this.acpLeaseUnconfirmed = true;
314
+ },
315
+ retireSession: id => {
316
+ this.writeNativeState(this.sessionFilePath, { id, transport: 'acp', retired: true, savedAt: new Date().toISOString() });
317
+ this.acpLeaseUnconfirmed = false;
318
+ },
319
+ retainScheduleOwner: (sessionId, hostId, retired) => {
320
+ const owner = { sessionId, hostId, retired };
321
+ const file = this.sessionFilePath + '.native-schedules';
322
+ this.writeNativeState(file, owner);
323
+ this.scheduleOwner = owner;
324
+ },
325
+ });
326
+ this.resumePermit = undefined;
327
+ return this.acp;
328
+ }
329
+ async withNativeScheduleOperation(id, current, run, inTurn) {
330
+ if (this.configuringTools || this.resettingNativeContext || this.shutdownUncertain)
331
+ throw new Error('AGY context transition is pending.');
332
+ return this.acpRuntime().withOperation(id, current, run, inTurn);
333
+ }
334
+ nativeScheduleAction(id) { return this.acp?.action(id); }
335
+ async createNativeSchedule(input, emit, current = () => true, admit = () => true) {
336
+ if (input.cwd !== this.currentWorkingDirectory || input.threadId !== this.threadId || input.model !== this.model || input.effort !== this.effort) {
337
+ throw new Error('AGY schedule configuration does not match the original session.');
338
+ }
339
+ const runtime = this.acpRuntime();
340
+ await runtime.start();
341
+ if (input.recovery)
342
+ input = { ...input, recovery: { ...input.recovery, identity: this.recoveryIdentity() } };
343
+ return runtime.create(input, emit, () => !this.isDestroyed && current() && admit());
344
+ }
345
+ preservesProcessOnAbort() { return !!this.acp; }
346
+ hasPendingCancellation() { return !!this.acp?.hasJobs && !!this.acp.blocked; }
347
+ hasPendingScheduleMutation() { return this.acp?.pendingMutation ?? false; }
183
348
  constructor(directoryGuard, options = {}) {
184
349
  this.directoryGuard = directoryGuard;
350
+ this.nativeAcp = options.nativeAcp === true && !options.delegationWorker && options.autoApprove !== false;
185
351
  this.model = options.model;
186
352
  this.effort = options.effort;
187
353
  this.autoApprove = options.autoApprove ?? true;
@@ -213,6 +379,21 @@ class AgyExecutor {
213
379
  this.sessionFilePath = path.join(this.currentWorkingDirectory, '.agy-session');
214
380
  }
215
381
  this.loadConversationId();
382
+ this.acpEligible = this.nativeAcp && !!this.threadId && !this.conversationId;
383
+ try {
384
+ if (!fs.existsSync(this.sessionFilePath + '.native-schedules'))
385
+ return;
386
+ const owner = JSON.parse(fs.readFileSync(this.sessionFilePath + '.native-schedules', 'utf8'));
387
+ if (typeof owner.sessionId !== 'string' || typeof owner.hostId !== 'string' || typeof owner.retired !== 'boolean')
388
+ throw new Error('Invalid AGY schedule owner.');
389
+ if (!this.conversationId)
390
+ throw new Error('Missing original AGY schedule conversation pointer.');
391
+ this.scheduleOwner = owner;
392
+ }
393
+ catch (error) {
394
+ if (error.code !== 'ENOENT')
395
+ throw new Error('AGY schedule ownership journal is unreadable; admission is blocked.');
396
+ }
216
397
  }
217
398
  // ─── Per-thread HOME isolation ────────────────────────────────────────────
218
399
  /**
@@ -303,23 +484,38 @@ class AgyExecutor {
303
484
  await this.configureDelegation(connection);
304
485
  }
305
486
  async configureDelegation(connection) {
487
+ if (this.configuringTools)
488
+ throw new Error('AGY managed-tool configuration is already in progress');
306
489
  if (this.delegationConfigured && (0, contract_1.sameConnection)(this.delegationConnection, connection))
307
490
  return;
308
- if (this.isProcessing)
309
- throw new Error('Cannot change delegation during an active turn');
491
+ if (this.isProcessing || this.resettingNativeContext)
492
+ throw new Error('Cannot change delegation during an active turn or context reset');
310
493
  if (!this.agyHome) {
311
494
  if (connection)
312
495
  throw new Error('AGY delegation requires a thread-scoped HOME');
313
496
  return;
314
497
  }
315
- this.killProcess();
316
- await this.waitForExit();
317
- if (this.isDestroyed)
318
- throw new Error('Executor has been destroyed');
319
- this.ensureThreadHome();
320
- await (0, AgyDelegationConfig_1.configureAgyDelegation)(this.agyCommand, this.agyHome, !!connection);
321
- this.delegationConnection = connection;
322
- this.delegationConfigured = true;
498
+ if (!this.cleanCheckpoint())
499
+ this.assertNoRetainedSchedules();
500
+ this.configuringTools = true;
501
+ try {
502
+ if (this.acp) {
503
+ await this.acp.close();
504
+ this.acp = undefined;
505
+ this.acpEligible = false;
506
+ }
507
+ this.killProcess();
508
+ await this.waitForExit();
509
+ if (this.isDestroyed)
510
+ throw new Error('Executor has been destroyed');
511
+ this.ensureThreadHome();
512
+ await (0, AgyDelegationConfig_1.configureAgyDelegation)(this.agyCommand, this.agyHome, !!connection);
513
+ this.delegationConnection = connection;
514
+ this.delegationConfigured = true;
515
+ }
516
+ finally {
517
+ this.configuringTools = false;
518
+ }
323
519
  }
324
520
  async getAccountUsage() {
325
521
  let env;
@@ -359,7 +555,11 @@ class AgyExecutor {
359
555
  });
360
556
  }
361
557
  isBusy() {
362
- return this.isProcessing || this.activeCommand !== null || this.commandQueue.length > 0;
558
+ return !!this.acp?.busy || this.isProcessing || this.activeCommand !== null || this.commandQueue.length > 0
559
+ || this.resettingNativeContext || this.configuringTools || this.shutdownUncertain || !this.proc && this.pendingExits.size > 0;
560
+ }
561
+ hasUncertainShutdown() {
562
+ return this.shutdownUncertain;
363
563
  }
364
564
  async setWorkingDirectory(targetPath) {
365
565
  const resolved = this.directoryGuard.resolveWorkingDirectory(targetPath, this.currentWorkingDirectory);
@@ -371,34 +571,86 @@ class AgyExecutor {
371
571
  this.currentWorkingDirectory = resolved;
372
572
  }
373
573
  async resetContext() {
374
- this.killProcess();
375
- // /clear means a real fresh start — drop any carried-over compact seed
376
- this.pendingContextSeed = null;
574
+ if (this.resettingNativeContext || this.configuringTools)
575
+ throw new Error('AGY context reset or managed-tool configuration is already in progress');
576
+ this.assertScheduleResettable();
377
577
  this.resettingNativeContext = true;
578
+ this.contextRevision++;
378
579
  try {
580
+ if (this.acp) {
581
+ await this.acp.close();
582
+ this.acp = undefined;
583
+ }
584
+ this.killProcess();
585
+ await this.waitForExit();
379
586
  // Keep the old pointer until admitted observations finish. The caller must await reset.
380
587
  if (this.nativeObserver)
381
588
  await this.nativeReceiptOperations;
589
+ this.shutdownUncertain = false;
590
+ // /clear means a real fresh start. Do not erase resume evidence before exit.
591
+ this.pendingContextSeed = null;
382
592
  this.clearConversationId();
593
+ this.acpLeaseUnconfirmed = false;
594
+ this.resumePermit = undefined;
595
+ this.restoringCheckpoint = undefined;
596
+ fs.rmSync(this.sessionFilePath + '.checkpoint', { force: true });
597
+ if (this.scheduleOwner?.retired) {
598
+ fs.rmSync(this.sessionFilePath + '.native-schedules', { force: true });
599
+ this.scheduleOwner = undefined;
600
+ }
601
+ this.acpEligible = this.nativeAcp && !!this.threadId;
383
602
  }
384
603
  finally {
385
604
  this.resettingNativeContext = false;
386
605
  }
387
606
  }
388
607
  async abort() {
389
- if (!this.proc || !this.activeCommand)
608
+ if (this.acp) {
609
+ const runtime = this.acp;
610
+ const cancelled = await runtime.abort();
611
+ // No managed native definitions/notifications have ever been admitted:
612
+ // ordinary abort may retire the host and resume the SAME saved conversation
613
+ // on its compatible transport. Scheduled sessions remain visibly fenced.
614
+ if (!runtime.hasJobs && (cancelled || runtime.blocked)) {
615
+ await runtime.close();
616
+ this.acp = undefined;
617
+ this.acpEligible = false;
618
+ }
619
+ return cancelled;
620
+ }
621
+ const retiring = this.pendingExits.size > 0 && !this.proc;
622
+ if (!this.activeCommand && !this.isProcessing && !retiring && !this.shutdownUncertain)
390
623
  return false;
391
624
  // agy's stream-json protocol has no cancel request (control_request is
392
625
  // explicitly unsupported), so abort = kill the process. The conversation
393
626
  // id survives, so the next command resumes context.
394
627
  console.log('[AgyExecutor] Aborting: killing agy process');
628
+ this.contextRevision++;
395
629
  this.killProcess('Aborted by user');
630
+ await this.waitForExit();
631
+ this.shutdownUncertain = false;
396
632
  return true;
397
633
  }
634
+ abortStatusMessage() {
635
+ if (this.acp?.continuationSucceeded)
636
+ return 'AGY foreground cancelled; eligible future schedules resumed automatically in the same conversation after deadline-bounded predecessor retirement.';
637
+ if (this.acp?.hasJobs && this.acp.blocked)
638
+ return 'AGY foreground cancelled; native timers may still queue reminders. Dispatch is blocked. Original schedule ownership and recovery evidence are retained; use /schedule list. Uncertain work will not be replayed.';
639
+ if (this.acp?.hasJobs)
640
+ return 'No foreground command was cancelled. Native schedules remain on their current host.';
641
+ return 'AGY stream-json abort stops its host. Conversation context can resume after confirmed exit; native session-only timers are not restored.';
642
+ }
398
643
  async destroy() {
399
- if (this.isDestroyed)
644
+ if (this.isDestroyed) {
645
+ if (this.acp)
646
+ await this.acp.close();
647
+ await this.waitForExit();
400
648
  return;
649
+ }
401
650
  this.isDestroyed = true;
651
+ this.contextRevision++;
652
+ if (this.acp)
653
+ await this.acp.close();
402
654
  // Reject everything still queued — nothing may respawn after destroy
403
655
  const queued = this.commandQueue.splice(0);
404
656
  for (const command of queued) {
@@ -412,6 +664,7 @@ class AgyExecutor {
412
664
  catch { /* already closed */ }
413
665
  }
414
666
  this.killProcess('Executor destroyed');
667
+ await this.waitForExit();
415
668
  if (this.nativeObserver)
416
669
  await this.nativeReceiptOperations;
417
670
  if (this.agyHome && this.delegationConnection) {
@@ -437,6 +690,10 @@ class AgyExecutor {
437
690
  timer = setTimeout(() => reject(new Error('AGY process exit could not be confirmed')), this.killEscalationMs + 5_000);
438
691
  })]);
439
692
  }
693
+ catch (error) {
694
+ this.shutdownUncertain = true;
695
+ throw error;
696
+ }
440
697
  finally {
441
698
  if (timer)
442
699
  clearTimeout(timer);
@@ -450,7 +707,7 @@ class AgyExecutor {
450
707
  await this.workerGroups.waitForExit();
451
708
  }
452
709
  isProcessRunning() {
453
- return this.proc !== null;
710
+ return !!this.acp?.running || this.proc !== null;
454
711
  }
455
712
  getSessionId() {
456
713
  return this.conversationId;
@@ -467,6 +724,14 @@ class AgyExecutor {
467
724
  * passes it back via the factory on restarts.
468
725
  */
469
726
  async setModel(model, _onStream) {
727
+ this.assertNoRetainedSchedules();
728
+ if (this.acp) {
729
+ if (this.acp.busy)
730
+ throw new Error('AGY is busy.');
731
+ await this.acp.close();
732
+ this.acp = undefined;
733
+ this.acpEligible = false;
734
+ }
470
735
  this.model = model;
471
736
  if (this.proc && !this.activeCommand) {
472
737
  console.log(`[AgyExecutor] Model set to ${model} — recycling idle process (conversation preserved)`);
@@ -492,6 +757,14 @@ class AgyExecutor {
492
757
  error: `Unsupported AGY reasoning effort: ${effort}. Supported values: auto, ${SUPPORTED_EFFORTS.join(', ')}.`,
493
758
  };
494
759
  }
760
+ this.assertNoRetainedSchedules();
761
+ if (this.acp) {
762
+ if (this.acp.busy)
763
+ throw new Error('AGY is busy.');
764
+ await this.acp.close();
765
+ this.acp = undefined;
766
+ this.acpEligible = false;
767
+ }
495
768
  this.effort = normalized === 'auto' ? undefined : normalized;
496
769
  if (this.proc && !this.activeCommand) {
497
770
  console.log(`[AgyExecutor] Reasoning effort set to ${normalized} — recycling idle process (conversation preserved)`);
@@ -511,7 +784,15 @@ class AgyExecutor {
511
784
  : `Reasoning effort set to ${normalized}. Takes effect on the next command.`,
512
785
  };
513
786
  }
514
- clearModel() {
787
+ async clearModel() {
788
+ this.assertNoRetainedSchedules();
789
+ if (this.acp) {
790
+ if (this.acp.busy)
791
+ throw new Error('AGY is busy.');
792
+ await this.acp.close();
793
+ this.acp = undefined;
794
+ this.acpEligible = false;
795
+ }
515
796
  this.model = undefined;
516
797
  if (this.proc && !this.activeCommand) {
517
798
  this.killProcess();
@@ -563,6 +844,7 @@ class AgyExecutor {
563
844
  * a plain reset and say so honestly.
564
845
  */
565
846
  async compactWhenFull(onStream) {
847
+ this.assertNoRetainedSchedules();
566
848
  if (!this.proc && !this.conversationId) {
567
849
  return { success: true, output: 'No active conversation to compact.' };
568
850
  }
@@ -596,11 +878,15 @@ class AgyExecutor {
596
878
  * HOMEs) is left untouched.
597
879
  */
598
880
  async deleteThreadData(_threadId) {
881
+ this.assertScheduleResettable();
599
882
  await this.destroy();
600
883
  // Managed lanes retain brain deliverables and recovery evidence. Parent reset owns history cleanup.
601
884
  if (this.delegationWorker)
602
885
  return;
603
886
  this.clearConversationId();
887
+ fs.rmSync(this.sessionFilePath + '.checkpoint', { force: true });
888
+ if (this.scheduleOwner?.retired)
889
+ fs.rmSync(this.sessionFilePath + '.native-schedules', { force: true });
604
890
  if (this.agyHome) {
605
891
  fs.rmSync(this.agyHome, { recursive: true, force: true });
606
892
  }
@@ -625,24 +911,65 @@ class AgyExecutor {
625
911
  void this.processQueue();
626
912
  }
627
913
  }
628
- executeQueued(prompt, options) {
629
- return new Promise((resolve) => {
630
- if (options.attachments?.length && !this.attachmentWarningShown) {
631
- this.attachmentWarningShown = true;
632
- console.warn('[AgyExecutor] agy stream-json input supports text only — attachments were dropped');
633
- }
634
- let proc;
914
+ async executeQueued(prompt, options) {
915
+ if (options.attachments?.length && !this.attachmentWarningShown) {
916
+ this.attachmentWarningShown = true;
917
+ console.warn('[AgyExecutor] AGY input supports text only — attachments were dropped');
918
+ }
919
+ this.resumeCleanChat();
920
+ if (!this.acp && this.acpLeaseUnconfirmed)
921
+ throw new Error('Previous AGY ACP host or hook restoration is unconfirmed. No saved conversation was resumed; retain its state for explicit recovery.');
922
+ if (!this.acp && this.scheduleOwner?.sessionId === this.conversationId) {
923
+ throw new Error('AGY native schedules from this saved conversation require unresolved queue recovery. No prompt was sent. Use /schedule list; automatic reconstruction is unavailable.');
924
+ }
925
+ if (this.acp || this.acpEligible || this.resumePermit) {
926
+ const runtime = this.acpRuntime();
927
+ // Do not silently abandon a newly allocated ACP conversation on error.
635
928
  try {
636
- proc = this.ensureProcess();
637
- prompt = options.resolvePrompt?.(this.conversationId) ?? prompt;
929
+ await runtime.start();
638
930
  }
639
931
  catch (error) {
640
- resolve({
641
- success: false,
642
- error: error instanceof Error ? error.message : String(error),
643
- });
644
- return;
932
+ if (runtime.safeFallback && !this.conversationId) {
933
+ this.acp = undefined;
934
+ this.acpEligible = false;
935
+ console.warn('[AgyExecutor] Native ACP initialization unavailable; using compatible transport without scheduling.');
936
+ return this.executeQueued(prompt, options);
937
+ }
938
+ throw error;
939
+ }
940
+ if (this.pendingContextSeed) {
941
+ const seed = this.pendingContextSeed;
942
+ this.pendingContextSeed = null;
943
+ const resolve = options.resolvePrompt;
944
+ options = { ...options, resolvePrompt: id => (0, compactHandoff_1.seedPromptWithHandoff)(resolve?.(id) ?? prompt, seed) };
645
945
  }
946
+ try {
947
+ return await runtime.execute(prompt, { ...options, inactivityTimeout: options.inactivityTimeout ?? this.inactivityTimeoutMs });
948
+ }
949
+ finally {
950
+ if (!runtime.hasJobs && runtime.blocked) {
951
+ await runtime.close();
952
+ this.acp = undefined;
953
+ this.acpEligible = false;
954
+ }
955
+ }
956
+ }
957
+ const revision = this.contextRevision;
958
+ let proc;
959
+ try {
960
+ this.assertExecutionContext(revision);
961
+ if (!this.proc && this.pendingExits.size)
962
+ await this.waitForExit();
963
+ proc = this.ensureProcess(revision);
964
+ prompt = options.resolvePrompt?.(this.conversationId) ?? prompt;
965
+ }
966
+ catch (error) {
967
+ return {
968
+ success: false,
969
+ error: error instanceof Error ? error.message : String(error),
970
+ };
971
+ }
972
+ return new Promise((resolve) => {
646
973
  const active = { options, resolve, inactivityTimeoutMs: options.inactivityTimeout };
647
974
  this.activityTracker.setCallback(options.onActivity);
648
975
  this.activityTracker.reset();
@@ -740,15 +1067,31 @@ class AgyExecutor {
740
1067
  }
741
1068
  }
742
1069
  // ─── Process lifecycle ────────────────────────────────────────────────────
743
- ensureProcess() {
1070
+ assertExecutionContext(revision) {
744
1071
  if (this.isDestroyed) {
745
1072
  throw new Error('Executor has been destroyed');
746
1073
  }
747
- if (this.resettingNativeContext)
748
- throw new Error('AGY context reset is still draining native receipts');
1074
+ if (revision !== this.contextRevision || this.resettingNativeContext)
1075
+ throw new Error('AGY execution context retired before prompt dispatch');
1076
+ if (this.configuringTools)
1077
+ throw new Error('AGY managed-tool configuration is still in progress');
1078
+ if (this.shutdownUncertain)
1079
+ throw new Error('AGY process exit is unconfirmed. Retry /abort before sending more work.');
1080
+ }
1081
+ ensureProcess(revision) {
1082
+ this.assertExecutionContext(revision);
749
1083
  (0, WorkingDirectory_1.assertWorkingDirectoryExists)(this.currentWorkingDirectory);
750
1084
  if (this.proc)
751
1085
  return this.proc;
1086
+ // Signalling, leader exit and transport close are different boundaries. The
1087
+ // predecessor must close before a successor opens the same native database.
1088
+ // This is a host/transport fence, not proof that escaped descendants retired.
1089
+ if (this.pendingExits.size)
1090
+ throw new Error('AGY predecessor transport has not closed');
1091
+ // Compatible transport can admit unobserved native work. Revoke any older
1092
+ // clean ACP proof before spawning it, even when configuration later reverts.
1093
+ if (this.sessionFilePath && fs.existsSync(this.sessionFilePath + '.checkpoint'))
1094
+ fs.rmSync(this.sessionFilePath + '.checkpoint', { force: true });
752
1095
  const env = this.buildEnv();
753
1096
  if (this.nativeObserver && this.agyHome) {
754
1097
  const scope = path.join(this.agyHome, '.gemini', 'antigravity-cli');
@@ -806,11 +1149,10 @@ class AgyExecutor {
806
1149
  if (proc !== this.proc)
807
1150
  return;
808
1151
  console.error('[AgyExecutor] Process error:', error);
809
- this.proc = null;
810
1152
  const friendly = error.message.includes('ENOENT')
811
1153
  ? 'AGY CLI (agy) is not installed or not found on PATH. Install it from https://antigravity.google/cli, or use /backend to switch to another backend.'
812
1154
  : `agy process error: ${error.message}`;
813
- this.completeActiveCommand({ success: false, error: friendly });
1155
+ this.killProcess(friendly);
814
1156
  });
815
1157
  proc.on('exit', (code, signal) => {
816
1158
  if (proc !== this.proc)
@@ -1007,11 +1349,14 @@ class AgyExecutor {
1007
1349
  const session = JSON.parse(data);
1008
1350
  if (session.id) {
1009
1351
  this.conversationId = session.id;
1352
+ this.acpLeaseUnconfirmed = session.transport === 'acp' && session.retired !== true;
1010
1353
  console.log(`[AgyExecutor] Loaded conversation ID: ${this.conversationId}`);
1011
1354
  }
1012
1355
  }
1013
1356
  }
1014
1357
  catch (error) {
1358
+ if (this.nativeAcp)
1359
+ throw new Error('Saved AGY conversation pointer is unreadable; no new conversation was allocated.');
1015
1360
  console.error('[AgyExecutor] Failed to load conversation ID:', error);
1016
1361
  this.conversationId = null;
1017
1362
  }