@yu_robotics/remote-cli 1.6.194 → 1.6.196

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 (39) hide show
  1. package/README.md +26 -2
  2. package/dist/client/MessageHandler.d.ts +9 -0
  3. package/dist/client/MessageHandler.d.ts.map +1 -1
  4. package/dist/client/MessageHandler.js +243 -83
  5. package/dist/client/MessageHandler.js.map +1 -1
  6. package/dist/delegation/DelegatedWorkerSessionStore.d.ts +7 -2
  7. package/dist/delegation/DelegatedWorkerSessionStore.d.ts.map +1 -1
  8. package/dist/delegation/DelegatedWorkerSessionStore.js +77 -12
  9. package/dist/delegation/DelegatedWorkerSessionStore.js.map +1 -1
  10. package/dist/delegation/DelegationManager.d.ts +9 -1
  11. package/dist/delegation/DelegationManager.d.ts.map +1 -1
  12. package/dist/delegation/DelegationManager.js +126 -31
  13. package/dist/delegation/DelegationManager.js.map +1 -1
  14. package/dist/delegation/DelegationOwnership.d.ts +8 -0
  15. package/dist/delegation/DelegationOwnership.d.ts.map +1 -1
  16. package/dist/delegation/DelegationOwnership.js +100 -0
  17. package/dist/delegation/DelegationOwnership.js.map +1 -1
  18. package/dist/delegation/OwnershipRuntime.d.ts +3 -0
  19. package/dist/delegation/OwnershipRuntime.d.ts.map +1 -1
  20. package/dist/delegation/OwnershipRuntime.js +36 -7
  21. package/dist/delegation/OwnershipRuntime.js.map +1 -1
  22. package/dist/maintenance/release-notes.json +1 -1
  23. package/dist/settings/SettingsAdmission.d.ts +5 -1
  24. package/dist/settings/SettingsAdmission.d.ts.map +1 -1
  25. package/dist/settings/SettingsAdmission.js +26 -5
  26. package/dist/settings/SettingsAdmission.js.map +1 -1
  27. package/dist/thread/ThreadContextReset.d.ts +5 -0
  28. package/dist/thread/ThreadContextReset.d.ts.map +1 -1
  29. package/dist/thread/ThreadContextReset.js +64 -1
  30. package/dist/thread/ThreadContextReset.js.map +1 -1
  31. package/dist/thread/ThreadExecutorPool.d.ts +2 -0
  32. package/dist/thread/ThreadExecutorPool.d.ts.map +1 -1
  33. package/dist/thread/ThreadExecutorPool.js +9 -10
  34. package/dist/thread/ThreadExecutorPool.js.map +1 -1
  35. package/dist/thread/ThreadManager.d.ts.map +1 -1
  36. package/dist/thread/ThreadManager.js +8 -3
  37. package/dist/thread/ThreadManager.js.map +1 -1
  38. package/dist/thread/types.d.ts +1 -1
  39. package/package.json +1 -1
@@ -22,6 +22,7 @@ const DelegationNotice_1 = require("./DelegationNotice");
22
22
  const WorkingDirectory_1 = require("../utils/WorkingDirectory");
23
23
  const DelegatedWorkspaceManager_1 = require("./DelegatedWorkspaceManager");
24
24
  const DelegationOwnership_1 = require("./DelegationOwnership");
25
+ const OwnershipRuntime_1 = require("./OwnershipRuntime");
25
26
  const ActivityProgress_1 = require("../utils/ActivityProgress");
26
27
  const Activity_1 = require("../executor/Activity");
27
28
  const Version_1 = require("../maintenance/Version");
@@ -29,7 +30,7 @@ exports.DELEGATION_LIMITS = { launches: 12, concurrent: 5, closeoutRounds: 2,
29
30
  idleTimeoutMs: 15 * 60_000, toolIdleTimeoutMs: 45 * 60_000,
30
31
  queueTimeoutMs: 60 * 60_000,
31
32
  resultBytes: 32 * 1024, continuationBytes: 64 * 1024, summaryBytes: 4 * 1024,
32
- storageTimeoutMs: 10_000, toolResponseWaitMs: 20_000, calls: 500 };
33
+ storageTimeoutMs: 10_000, cancelWaitMs: 250, toolResponseWaitMs: 20_000, calls: 500 };
33
34
  /** Bounds and cadence for optional display-only delegated-worker text. */
34
35
  exports.DELEGATION_TEXT_PROGRESS = {
35
36
  flushMs: 2_500,
@@ -137,6 +138,7 @@ class DelegationManager {
137
138
  shutdown;
138
139
  stopping = false;
139
140
  ownershipReleaseStarted = false;
141
+ reportedUnavailableWriterEvidence = false;
140
142
  publicOperations = new Set();
141
143
  maintenance;
142
144
  maintenanceTimer;
@@ -145,6 +147,8 @@ class DelegationManager {
145
147
  workspaces = new Map();
146
148
  pumps = new Set();
147
149
  scopes = new Map();
150
+ detachedScopes = new Map();
151
+ detachedThreads = new Map();
148
152
  timeouts;
149
153
  constructor(guard, factory = executor_1.createExecutor, registry = new BackendRegistry_1.BackendRegistry(), store = new DelegationStore_1.DelegationStore(), timeoutInput = exports.DELEGATION_LIMITS, cleanupMs = 10_000, laneStore = new DelegatedWorkerSessionStore_1.DelegatedWorkerSessionStore(), workspaceManager = new DelegatedWorkspaceManager_1.DelegatedWorkspaceManager()) {
150
154
  this.guard = guard;
@@ -172,9 +176,15 @@ class DelegationManager {
172
176
  if (!this.stopping)
173
177
  return this.ownership.acquire();
174
178
  });
175
- return this.initialization = this.ownership.acquire().catch(error => {
179
+ return this.initialization = (async () => {
180
+ if (!await this.ownership.assertNoForeignWriters())
181
+ await this.laneStore.assertLegacyWritersStopped();
182
+ await this.ownership.acquire();
183
+ })().catch(error => {
176
184
  this.initialization = undefined;
177
- throw error;
185
+ throw new Error('Managed delegation storage could not be verified. Worker launch and storage changes remain disabled; '
186
+ + 'ordinary chat can continue unless an active worker conflicts. Inspect local delegation ownership and inventory before retrying. '
187
+ + 'Existing files and native histories were preserved.', { cause: error });
178
188
  });
179
189
  }
180
190
  assertAcceptingOperations() {
@@ -215,7 +225,7 @@ class DelegationManager {
215
225
  begin(parent) {
216
226
  if (this.stopping)
217
227
  throw new Error('Delegation is shutting down');
218
- this.laneStore.assertContextReady(parent.thread.id);
228
+ this.laneStore.assertContextReady(parent.thread.id, parent.thread.delegationWorkspaceGeneration ?? 0);
219
229
  if (this.scopes.has(parent.thread.id))
220
230
  throw new Error('This thread already owns a delegation turn');
221
231
  // Fail with recovery guidance before realpathSync reports a raw ENOENT.
@@ -236,7 +246,9 @@ class DelegationManager {
236
246
  let sourcePromise;
237
247
  let baseline;
238
248
  let maxChildren = 1;
239
- const workspaceOwner = { id: (0, crypto_1.randomUUID)(), threadId: parent.thread.id, quarantined: false };
249
+ const workspaceOwner = { id: (0, crypto_1.randomUUID)(), threadId: parent.thread.id, quarantined: false, detached: false,
250
+ permitsDirectExecution: () => !integrating && !admissions
251
+ && [...tasks.values()].every(task => task.settled || task.nativeExitConfirmed === true) };
240
252
  const workspaceGeneration = parent.thread.delegationWorkspaceGeneration ?? 0;
241
253
  let execution = 0;
242
254
  let acceptingResults = true;
@@ -276,6 +288,8 @@ class DelegationManager {
276
288
  console.warn('[Delegation] Could not persist task state:', error instanceof Error ? error.message : 'Storage failure');
277
289
  });
278
290
  const notify = (send) => {
291
+ if (closed)
292
+ return;
279
293
  try {
280
294
  send();
281
295
  }
@@ -323,6 +337,8 @@ class DelegationManager {
323
337
  task.executionMetadata = (0, ExecutionMetadata_1.mergeReportedExecutionMetadata)(task.executionMetadata, (0, ExecutionMetadata_1.captureExecutionMetadata)(task.executor, task.record.backend));
324
338
  };
325
339
  const reportProgress = (task, progress) => {
340
+ if (closed)
341
+ return false;
326
342
  try {
327
343
  if (task.record.state === 'running')
328
344
  captureWorkerMetadata(task);
@@ -775,6 +791,8 @@ ${prompt}`));
775
791
  description: `[${backend} delegated task] ${request.description}`, canRemember: false }, task.executor);
776
792
  },
777
793
  onApprovalResolved: (id, status) => {
794
+ if (closed)
795
+ return;
778
796
  parent.onApprovalResolved(id, status);
779
797
  if (acceptingActivity && task.executor === worker && worker.isWaitingInput?.() === false) {
780
798
  task.waitingInputText = undefined;
@@ -852,6 +870,10 @@ ${prompt}`));
852
870
  await deadline(() => confirmGroup.call(task.executor), this.cleanupMs);
853
871
  }
854
872
  nativeExitConfirmed = true;
873
+ task.nativeExitConfirmed = released;
874
+ if (released && task.lane) {
875
+ await this.laneStore.markShutdownConfirmed(task.lane.id, task.lane.contextGeneration ?? 0);
876
+ }
855
877
  if (released && task.lane && task.preserveUnstartedLane) {
856
878
  if (!task.workspacePreparationStarted) {
857
879
  // Only acquisition changed: no checkout or executor was touched.
@@ -1226,6 +1248,8 @@ ${prompt}`));
1226
1248
  calls.set(callId, { signature, result });
1227
1249
  return result;
1228
1250
  };
1251
+ let closing;
1252
+ let cancelledScope = false;
1229
1253
  const scope = {
1230
1254
  invoke,
1231
1255
  isClosed: () => closed,
@@ -1270,6 +1294,9 @@ ${prompt}`));
1270
1294
  checkArtifactCloseout: async () => {
1271
1295
  if (closed)
1272
1296
  throw new Error('Delegation was cancelled');
1297
+ // Ordinary chat has no managed-work obligation and must not open inventory.
1298
+ if (!launches)
1299
+ return [];
1273
1300
  // Unlike result acknowledgement, closeout also waits for native cleanup
1274
1301
  // and artifact collection of tasks whose results were already read.
1275
1302
  await Promise.allSettled([...calls.values()].map(call => call.result));
@@ -1360,29 +1387,50 @@ ${prompt}`));
1360
1387
  return !closed && waiting.length === 1 ? waiting[0].executor : undefined;
1361
1388
  },
1362
1389
  waitingInputCount: () => closed ? 0 : [...activeTasks].filter(task => task.record.state === 'running' && task.executor?.isWaitingInput?.()).length,
1363
- close: async () => {
1390
+ close: (cancelled = false) => {
1391
+ cancelledScope ||= cancelled;
1392
+ if (closing)
1393
+ return closing;
1394
+ // Fence callbacks and tool admission synchronously, before any cleanup await.
1364
1395
  closed = true;
1396
+ workspaceOwner.detached = true;
1365
1397
  this.pumps.delete(pump);
1366
- await Promise.allSettled([...tasks.values()].map(cancel));
1367
- await integrationPending?.catch(() => undefined);
1368
- // Do not wait forever for a discovery-only admission. Its closed check
1369
- // prevents launch; defer reconciliation unless this scope is fully idle.
1370
- if (source && !admissions && !activeTasks.size && [...tasks.values()].every(task => task.settled)
1371
- && !workspaceOwner.quarantined && !parent.isWorkspaceBusy?.(leasePath)
1372
- && ![...this.workspaces].some(([active, owner]) => owner !== workspaceOwner && workspacesOverlap(active, leasePath))) {
1373
- this.workspaces.set(leasePath, workspaceOwner);
1374
- try {
1375
- await reconcileHistory(true);
1376
- }
1377
- catch {
1378
- console.warn('[Delegation] Historical delivery reconciliation deferred; worker files were preserved');
1379
- }
1380
- }
1381
- releaseWorkspaceIfIdle();
1382
- // A version probe may still be pending. Its closed check prevents launch.
1383
1398
  if (this.scopes.get(parent.thread.id) === scope)
1384
1399
  this.scopes.delete(parent.thread.id);
1385
- this.scheduleMaintenance();
1400
+ closing = (async () => {
1401
+ await Promise.allSettled([...tasks.values()].map(cancel));
1402
+ await integrationPending?.catch(() => undefined);
1403
+ // Do not wait forever for a discovery-only admission. Its closed check
1404
+ // prevents launch; defer reconciliation unless this scope is fully idle.
1405
+ if (!cancelledScope && source && !admissions && !activeTasks.size && [...tasks.values()].every(task => task.settled)
1406
+ && !workspaceOwner.quarantined && !parent.isWorkspaceBusy?.(leasePath)
1407
+ && ![...this.workspaces].some(([active, owner]) => owner !== workspaceOwner && workspacesOverlap(active, leasePath))) {
1408
+ this.workspaces.set(leasePath, workspaceOwner);
1409
+ try {
1410
+ await reconcileHistory(true, undefined, () => {
1411
+ if (cancelledScope)
1412
+ throw new Error('Historical reconciliation was cancelled');
1413
+ assertWorkspace();
1414
+ });
1415
+ }
1416
+ catch {
1417
+ console.warn('[Delegation] Historical delivery reconciliation deferred; worker files were preserved');
1418
+ }
1419
+ }
1420
+ releaseWorkspaceIfIdle();
1421
+ // A version probe may still be pending. Its closed check prevents launch.
1422
+ if (launches || this.initialization)
1423
+ this.scheduleMaintenance();
1424
+ })();
1425
+ this.detachedScopes.set(scope, closing);
1426
+ this.detachedThreads.set(scope, parent.thread.id);
1427
+ void closing.then(() => {
1428
+ if (!workspaceOwner.quarantined) {
1429
+ this.detachedScopes.delete(scope);
1430
+ this.detachedThreads.delete(scope);
1431
+ }
1432
+ }, () => undefined);
1433
+ return closing;
1386
1434
  },
1387
1435
  };
1388
1436
  this.pumps.add(pump);
@@ -1392,6 +1440,9 @@ ${prompt}`));
1392
1440
  waitingExecutor(threadId) { return this.scopes.get(threadId)?.waitingExecutor(); }
1393
1441
  hasAmbiguousInput(threadId) { return (this.scopes.get(threadId)?.waitingInputCount() ?? 0) > 1; }
1394
1442
  hasActiveTasks(threadId) { return this.scopes.get(threadId)?.hasTasks() ?? false; }
1443
+ hasWorkspaceLease(threadId) {
1444
+ return [...this.workspaces.values()].some(owner => owner.threadId === threadId);
1445
+ }
1395
1446
  /** Retry previously confirmed cleanup requests without touching uncertain interrupted workers. */
1396
1447
  async reconcilePendingWorkerLanes() {
1397
1448
  this.assertAcceptingOperations();
@@ -1399,7 +1450,7 @@ ${prompt}`));
1399
1450
  return this.maintenance;
1400
1451
  const operation = this.withAdmission(async () => {
1401
1452
  await this.ensureOwnership();
1402
- if (this.scopes.size || this.running || this.workspaces.size)
1453
+ if (this.scopes.size || this.detachedScopes.size || this.running || this.workspaces.size)
1403
1454
  return { removed: 0, failed: 0 };
1404
1455
  await this.workspaceManager.retryReclamation({ limit: 25 });
1405
1456
  return this.removeWorkerLanes(await this.laneStore.cleanupCandidates(), true);
@@ -1417,7 +1468,7 @@ ${prompt}`));
1417
1468
  async invalidateWorkspaceGeneration(threadId, currentGeneration) {
1418
1469
  return this.publicOperation(async () => {
1419
1470
  await this.ensureOwnership();
1420
- if (this.hasActiveTasks(threadId)) {
1471
+ if (this.hasActiveTasks(threadId) || this.hasWorkspaceLease(threadId)) {
1421
1472
  throw new Error('Cannot change working directory while a delegated worker is running. Wait for it to finish or send /abort first.');
1422
1473
  }
1423
1474
  return this.removeWorkerLanes(await this.laneStore.invalidateGeneration(threadId, currentGeneration), true);
@@ -1455,7 +1506,7 @@ ${prompt}`));
1455
1506
  async resetWorkerLanes(threadId, backend) {
1456
1507
  return this.publicOperation(async () => {
1457
1508
  await this.ensureOwnership();
1458
- if (this.hasActiveTasks(threadId)) {
1509
+ if (this.hasActiveTasks(threadId) || this.hasWorkspaceLease(threadId)) {
1459
1510
  throw new Error('Cannot reset delegated worker context while a delegated worker is running. Wait for it to finish or send /abort first.');
1460
1511
  }
1461
1512
  const result = await this.removeWorkerLanes(await this.laneStore.markForReset(threadId, backend));
@@ -1466,7 +1517,7 @@ ${prompt}`));
1466
1517
  async deleteWorkerLanes(threadId) {
1467
1518
  return this.publicOperation(async () => {
1468
1519
  await this.ensureOwnership();
1469
- if (this.hasActiveTasks(threadId)) {
1520
+ if (this.hasActiveTasks(threadId) || this.hasWorkspaceLease(threadId)) {
1470
1521
  throw new Error('Cannot delete delegated worker context while a delegated worker is running.');
1471
1522
  }
1472
1523
  const result = await this.removeWorkerLanes(await this.laneStore.markForReset(threadId));
@@ -1557,10 +1608,53 @@ ${prompt}`));
1557
1608
  if (this.workspaces.size === 0)
1558
1609
  return false;
1559
1610
  const canonical = fs_1.default.realpathSync(cwd);
1560
- return [...this.workspaces].some(([active, owner]) => (owner.quarantined || owner.threadId !== threadId) && workspacesOverlap(active, canonical));
1611
+ return [...this.workspaces].some(([active, owner]) => (owner.quarantined || owner.detached || owner.threadId !== threadId) && workspacesOverlap(active, canonical));
1561
1612
  }
1613
+ /** Chat and native commands honor observed writers without requiring healthy historical inventory. */
1614
+ async assertExecutionSafe(cwd, threadId) {
1615
+ const conflicting = () => {
1616
+ if (!this.workspaces.size)
1617
+ return false;
1618
+ const canonical = fs_1.default.realpathSync(cwd);
1619
+ return [...this.workspaces].some(([active, owner]) => workspacesOverlap(active, canonical)
1620
+ && (owner.quarantined || owner.detached || owner.threadId !== threadId)
1621
+ && !(owner.detached && !owner.quarantined && owner.permitsDirectExecution?.()));
1622
+ };
1623
+ const assertWorkspace = () => {
1624
+ if (conflicting())
1625
+ throw new Error('A managed worker may still write files in this workspace. Use /abort to request cancellation. '
1626
+ + '/clear and /new detach conversation context; conflicting execution must wait for confirmed worker exit.');
1627
+ };
1628
+ assertWorkspace();
1629
+ let evidence;
1630
+ try {
1631
+ evidence = await this.ownership.assertNoKnownForeignWriters();
1632
+ }
1633
+ catch (error) {
1634
+ if (error instanceof OwnershipRuntime_1.ActiveDelegationWriterError) {
1635
+ throw new Error('An active managed-worker owner or recorded native writer was detected. Stop that worker before retrying. '
1636
+ + '/clear and /new reset conversation context but do not stop foreign writers.');
1637
+ }
1638
+ evidence = 'unavailable';
1639
+ }
1640
+ assertWorkspace();
1641
+ if (evidence === 'unavailable' && !this.reportedUnavailableWriterEvidence) {
1642
+ this.reportedUnavailableWriterEvidence = true;
1643
+ console.warn('[Delegation] Historical process evidence is unavailable. Ordinary chat remains enabled; '
1644
+ + 'managed storage operations still require ownership verification. No worker exit was inferred.');
1645
+ }
1646
+ }
1647
+ /** Return promptly while the original scope retains all native and filesystem cleanup. */
1562
1648
  async cancelThread(threadId) {
1563
- return this.publicOperation(async () => { await this.scopes.get(threadId)?.close(); });
1649
+ this.assertAcceptingOperations();
1650
+ const scopes = new Set([...this.detachedThreads].filter(([, owner]) => owner === threadId).map(([scope]) => scope));
1651
+ const active = this.scopes.get(threadId);
1652
+ if (active)
1653
+ scopes.add(active);
1654
+ if (!scopes.size)
1655
+ return;
1656
+ const cleanup = Promise.all([...scopes].map(scope => scope.close(true)));
1657
+ await deadline(() => cleanup, Math.min(exports.DELEGATION_LIMITS.cancelWaitMs, this.cleanupMs)).catch(() => undefined);
1564
1658
  }
1565
1659
  async destroy() {
1566
1660
  if (this.shutdown)
@@ -1569,7 +1663,8 @@ ${prompt}`));
1569
1663
  const shutdown = (async () => {
1570
1664
  clearTimeout(this.maintenanceTimer);
1571
1665
  this.maintenanceTimer = undefined;
1572
- const outcomes = await Promise.allSettled([...this.scopes.values()].map(scope => scope.close()));
1666
+ const active = [...new Set([...this.scopes.values(), ...this.detachedScopes.keys()])].map(scope => scope.close(true));
1667
+ const outcomes = await Promise.allSettled([...active, ...this.detachedScopes.values()]);
1573
1668
  await Promise.allSettled([...this.publicOperations]);
1574
1669
  await this.maintenance;
1575
1670
  await this.admissionGate;