@yu_robotics/remote-cli 1.6.231 → 1.6.234
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.
- package/dist/client/MessageHandler.d.ts +23 -0
- package/dist/client/MessageHandler.d.ts.map +1 -1
- package/dist/client/MessageHandler.js +422 -8
- package/dist/client/MessageHandler.js.map +1 -1
- package/dist/client/WebSocketClient.d.ts +4 -1
- package/dist/client/WebSocketClient.d.ts.map +1 -1
- package/dist/client/WebSocketClient.js +39 -3
- package/dist/client/WebSocketClient.js.map +1 -1
- package/dist/delegation/DelegationBridge.d.ts +2 -13
- package/dist/delegation/DelegationBridge.d.ts.map +1 -1
- package/dist/delegation/DelegationBridge.js +3 -126
- package/dist/delegation/DelegationBridge.js.map +1 -1
- package/dist/delegation/contract.d.ts +3 -4
- package/dist/delegation/contract.d.ts.map +1 -1
- package/dist/delegation/contract.js +3 -2
- package/dist/delegation/contract.js.map +1 -1
- package/dist/delegation/mcpServer.js +3 -2
- package/dist/delegation/mcpServer.js.map +1 -1
- package/dist/delegation/piExtension.d.ts +3 -3
- package/dist/delegation/piExtension.d.ts.map +1 -1
- package/dist/delegation/piExtension.js +4 -4
- package/dist/delegation/piExtension.js.map +1 -1
- package/dist/executor/AcpExecutor.d.ts +1 -0
- package/dist/executor/AcpExecutor.d.ts.map +1 -1
- package/dist/executor/AcpExecutor.js +10 -4
- package/dist/executor/AcpExecutor.js.map +1 -1
- package/dist/executor/AgyExecutor.d.ts +1 -0
- package/dist/executor/AgyExecutor.d.ts.map +1 -1
- package/dist/executor/AgyExecutor.js +5 -0
- package/dist/executor/AgyExecutor.js.map +1 -1
- package/dist/executor/ClaudePersistentExecutor.d.ts +1 -0
- package/dist/executor/ClaudePersistentExecutor.d.ts.map +1 -1
- package/dist/executor/ClaudePersistentExecutor.js +7 -1
- package/dist/executor/ClaudePersistentExecutor.js.map +1 -1
- package/dist/executor/CodexAppServerExecutor.d.ts +1 -0
- package/dist/executor/CodexAppServerExecutor.d.ts.map +1 -1
- package/dist/executor/CodexAppServerExecutor.js +15 -8
- package/dist/executor/CodexAppServerExecutor.js.map +1 -1
- package/dist/executor/IExecutor.d.ts +2 -0
- package/dist/executor/IExecutor.d.ts.map +1 -1
- package/dist/executor/PiExecutor.d.ts +1 -0
- package/dist/executor/PiExecutor.d.ts.map +1 -1
- package/dist/executor/PiExecutor.js +5 -0
- package/dist/executor/PiExecutor.js.map +1 -1
- package/dist/executor/pi/PiClient.d.ts.map +1 -1
- package/dist/executor/pi/PiClient.js +1 -0
- package/dist/executor/pi/PiClient.js.map +1 -1
- package/dist/maintenance/release-notes.json +1 -1
- package/dist/managed/ManagedToolBridge.d.ts +14 -0
- package/dist/managed/ManagedToolBridge.d.ts.map +1 -0
- package/dist/managed/ManagedToolBridge.js +132 -0
- package/dist/managed/ManagedToolBridge.js.map +1 -0
- package/dist/managed/contract.d.ts +9 -0
- package/dist/managed/contract.d.ts.map +1 -0
- package/dist/managed/contract.js +7 -0
- package/dist/managed/contract.js.map +1 -0
- package/dist/managed/tools.d.ts +230 -0
- package/dist/managed/tools.d.ts.map +1 -0
- package/dist/managed/tools.js +23 -0
- package/dist/managed/tools.js.map +1 -0
- package/dist/scheduling/ClaudeNativeScheduleProvider.d.ts +19 -0
- package/dist/scheduling/ClaudeNativeScheduleProvider.d.ts.map +1 -0
- package/dist/scheduling/ClaudeNativeScheduleProvider.js +570 -0
- package/dist/scheduling/ClaudeNativeScheduleProvider.js.map +1 -0
- package/dist/scheduling/DshNativeScheduleProvider.d.ts +19 -0
- package/dist/scheduling/DshNativeScheduleProvider.d.ts.map +1 -0
- package/dist/scheduling/DshNativeScheduleProvider.js +470 -0
- package/dist/scheduling/DshNativeScheduleProvider.js.map +1 -0
- package/dist/scheduling/ScheduleCapabilities.d.ts +53 -0
- package/dist/scheduling/ScheduleCapabilities.d.ts.map +1 -0
- package/dist/scheduling/ScheduleCapabilities.js +65 -0
- package/dist/scheduling/ScheduleCapabilities.js.map +1 -0
- package/dist/scheduling/ScheduleCardService.d.ts +26 -0
- package/dist/scheduling/ScheduleCardService.d.ts.map +1 -0
- package/dist/scheduling/ScheduleCardService.js +109 -0
- package/dist/scheduling/ScheduleCardService.js.map +1 -0
- package/dist/scheduling/ScheduleCommand.d.ts +27 -0
- package/dist/scheduling/ScheduleCommand.d.ts.map +1 -0
- package/dist/scheduling/ScheduleCommand.js +173 -0
- package/dist/scheduling/ScheduleCommand.js.map +1 -0
- package/dist/scheduling/ScheduleDeliveryClient.d.ts +17 -0
- package/dist/scheduling/ScheduleDeliveryClient.d.ts.map +1 -0
- package/dist/scheduling/ScheduleDeliveryClient.js +109 -0
- package/dist/scheduling/ScheduleDeliveryClient.js.map +1 -0
- package/dist/scheduling/ScheduleService.d.ts +75 -0
- package/dist/scheduling/ScheduleService.d.ts.map +1 -0
- package/dist/scheduling/ScheduleService.js +749 -0
- package/dist/scheduling/ScheduleService.js.map +1 -0
- package/dist/scheduling/ScheduleToolScope.d.ts +55 -0
- package/dist/scheduling/ScheduleToolScope.d.ts.map +1 -0
- package/dist/scheduling/ScheduleToolScope.js +182 -0
- package/dist/scheduling/ScheduleToolScope.js.map +1 -0
- package/dist/scheduling/claude/rules.d.ts +8 -0
- package/dist/scheduling/claude/rules.d.ts.map +1 -0
- package/dist/scheduling/claude/rules.js +46 -0
- package/dist/scheduling/claude/rules.js.map +1 -0
- package/dist/scheduling/dsh/HostBridge.d.ts +96 -0
- package/dist/scheduling/dsh/HostBridge.d.ts.map +1 -0
- package/dist/scheduling/dsh/HostBridge.js +364 -0
- package/dist/scheduling/dsh/HostBridge.js.map +1 -0
- package/dist/scheduling/dsh/ScopePlugin.d.ts +9 -0
- package/dist/scheduling/dsh/ScopePlugin.d.ts.map +1 -0
- package/dist/scheduling/dsh/ScopePlugin.js +13 -0
- package/dist/scheduling/dsh/ScopePlugin.js.map +1 -0
- package/dist/scheduling/dsh/launch.d.ts +13 -0
- package/dist/scheduling/dsh/launch.d.ts.map +1 -0
- package/dist/scheduling/dsh/launch.js +58 -0
- package/dist/scheduling/dsh/launch.js.map +1 -0
- package/dist/scheduling/dsh/protocol.d.ts +28 -0
- package/dist/scheduling/dsh/protocol.d.ts.map +1 -0
- package/dist/scheduling/dsh/protocol.js +142 -0
- package/dist/scheduling/dsh/protocol.js.map +1 -0
- package/dist/scheduling/toolContract.d.ts +48 -0
- package/dist/scheduling/toolContract.d.ts.map +1 -0
- package/dist/scheduling/toolContract.js +24 -0
- package/dist/scheduling/toolContract.js.map +1 -0
- package/dist/scheduling/types.d.ts +79 -0
- package/dist/scheduling/types.d.ts.map +1 -0
- package/dist/scheduling/types.js +13 -0
- package/dist/scheduling/types.js.map +1 -0
- package/dist/types/ScheduleCards.d.ts +56 -0
- package/dist/types/ScheduleCards.d.ts.map +1 -0
- package/dist/types/ScheduleCards.js +3 -0
- package/dist/types/ScheduleCards.js.map +1 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/index.d.ts.map +1 -1
- package/native/prebuilds/darwin-arm64/managed_native.node +0 -0
- package/native/prebuilds/darwin-arm64/manifest.json +1 -1
- package/native/prebuilds/darwin-x64/managed_native.node +0 -0
- package/native/prebuilds/darwin-x64/manifest.json +1 -1
- package/native/prebuilds/win32-arm64/managed_native.node +0 -0
- package/native/prebuilds/win32-arm64/manifest.json +1 -1
- package/native/prebuilds/win32-x64/managed_native.node +0 -0
- package/native/prebuilds/win32-x64/manifest.json +1 -1
- package/package.json +1 -1
|
@@ -4,6 +4,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.MessageHandler = void 0;
|
|
7
|
+
const ScheduleToolScope_1 = require("../scheduling/ScheduleToolScope");
|
|
8
|
+
const toolContract_1 = require("../scheduling/toolContract");
|
|
9
|
+
const ScheduleCardService_1 = require("../scheduling/ScheduleCardService");
|
|
7
10
|
const PendingOutputFiles_1 = require("../output/PendingOutputFiles");
|
|
8
11
|
const OutputFiles_1 = require("../output/OutputFiles");
|
|
9
12
|
const OutputSnapshots_1 = require("../output/OutputSnapshots");
|
|
@@ -51,6 +54,13 @@ const SessionResumeService_1 = require("../session/SessionResumeService");
|
|
|
51
54
|
const adapters_1 = require("../session/adapters");
|
|
52
55
|
const PiSessionCatalog_1 = require("../session/adapters/PiSessionCatalog");
|
|
53
56
|
const SessionControl_1 = require("../session/SessionControl");
|
|
57
|
+
const ScheduleService_1 = require("../scheduling/ScheduleService");
|
|
58
|
+
const ClaudeNativeScheduleProvider_1 = require("../scheduling/ClaudeNativeScheduleProvider");
|
|
59
|
+
const DshNativeScheduleProvider_1 = require("../scheduling/DshNativeScheduleProvider");
|
|
60
|
+
const ScheduleDeliveryClient_1 = require("../scheduling/ScheduleDeliveryClient");
|
|
61
|
+
const ScheduleCommand_1 = require("../scheduling/ScheduleCommand");
|
|
62
|
+
const ScheduleCapabilities_1 = require("../scheduling/ScheduleCapabilities");
|
|
63
|
+
const ClaudeSandbox_1 = require("../executor/claude/ClaudeSandbox");
|
|
54
64
|
const EFFORT_BACKENDS = new Set(['claude', 'codex', 'agy', 'opencode', 'kimi', 'zcode', 'pi', 'dsh']);
|
|
55
65
|
const SLASH_SESSION_BACKENDS = new Set(['opencode', 'kimi', 'zcode', 'pi']);
|
|
56
66
|
const NATIVE_SKILLS_BACKENDS = new Set(['claude', 'agy', 'opencode', 'kimi', 'zcode', 'pi']);
|
|
@@ -206,14 +216,57 @@ class MessageHandler {
|
|
|
206
216
|
pendingOutputSupported = false;
|
|
207
217
|
pendingOutputFiles = new PendingOutputFiles_1.PendingOutputFiles();
|
|
208
218
|
imageConnectionEpoch = 0;
|
|
219
|
+
scheduleResultsSupported = false;
|
|
220
|
+
scheduleCardsSupported = false;
|
|
221
|
+
scheduleToolCardsSupported = false;
|
|
222
|
+
scheduleToolOperations = new ScheduleToolScope_1.ScheduleToolOperations();
|
|
223
|
+
scheduleCardReceipts = new Map();
|
|
224
|
+
scheduleCards;
|
|
225
|
+
schedules;
|
|
226
|
+
scheduleInitialization;
|
|
227
|
+
scheduleDelivery;
|
|
228
|
+
scheduleOwners = new Map();
|
|
229
|
+
scheduleManagement = new Set();
|
|
209
230
|
constructor(wsClient, threadPool, threadManager, directoryGuard, config) {
|
|
210
231
|
this.wsClient = wsClient;
|
|
211
232
|
this.threadPool = threadPool;
|
|
212
233
|
this.threadManager = threadManager;
|
|
213
234
|
this.directoryGuard = directoryGuard;
|
|
214
235
|
this.config = config;
|
|
236
|
+
this.scheduleCards = new ScheduleCardService_1.ScheduleCardService({
|
|
237
|
+
current: owner => {
|
|
238
|
+
try {
|
|
239
|
+
return !this.isDestroyed && this.scheduleGeneration(owner.threadId) === owner.generation;
|
|
240
|
+
}
|
|
241
|
+
catch {
|
|
242
|
+
return false;
|
|
243
|
+
}
|
|
244
|
+
},
|
|
245
|
+
threadName: id => this.threadManager.getThread(id)?.name ?? id,
|
|
246
|
+
records: owner => this.schedules.list(owner),
|
|
247
|
+
canCancel: (owner, id) => this.schedules.canCancel(owner, id),
|
|
248
|
+
refresh: owner => this.schedules.refresh(owner),
|
|
249
|
+
cancel: (owner, id) => this.schedules.cancel(owner, id),
|
|
250
|
+
exclusive: async (owner, body) => {
|
|
251
|
+
if (!this.schedules || this.isDestroyed || this.automaticUpdateInProgress
|
|
252
|
+
|| this.scheduleManagement.has(owner.threadId))
|
|
253
|
+
throw new Error('Schedule controls are busy.');
|
|
254
|
+
this.scheduleManagement.add(owner.threadId);
|
|
255
|
+
try {
|
|
256
|
+
return await body();
|
|
257
|
+
}
|
|
258
|
+
finally {
|
|
259
|
+
this.scheduleManagement.delete(owner.threadId);
|
|
260
|
+
}
|
|
261
|
+
},
|
|
262
|
+
});
|
|
215
263
|
this.wsClient.onClose?.(() => {
|
|
216
264
|
this.imageConnectionEpoch++;
|
|
265
|
+
this.scheduleResultsSupported = false;
|
|
266
|
+
this.scheduleCardsSupported = false;
|
|
267
|
+
this.scheduleToolCardsSupported = false;
|
|
268
|
+
this.clearScheduleCardReceipts();
|
|
269
|
+
this.scheduleCards.invalidate();
|
|
217
270
|
this.routerVersion = undefined;
|
|
218
271
|
this.fileInbox?.disconnect();
|
|
219
272
|
this.outputFiles?.disconnect();
|
|
@@ -316,6 +369,26 @@ class MessageHandler {
|
|
|
316
369
|
case 'command':
|
|
317
370
|
await this.handleCommandMessage(message, this.fileInbox?.mark());
|
|
318
371
|
return;
|
|
372
|
+
case 'schedule_tool_card_ack': {
|
|
373
|
+
if (!this.scheduleToolCardsSupported || typeof message.messageId !== 'string')
|
|
374
|
+
return;
|
|
375
|
+
const pending = this.scheduleCardReceipts.get(message.messageId);
|
|
376
|
+
if (pending && typeof message.success === 'boolean') {
|
|
377
|
+
clearTimeout(pending.timer);
|
|
378
|
+
this.scheduleCardReceipts.delete(message.messageId);
|
|
379
|
+
pending.resolve(message.success ? 'Management card delivered.' : 'Management card unavailable. Use /schedule list; do not recreate the task.');
|
|
380
|
+
}
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
case 'schedule_action': {
|
|
384
|
+
if (!this.scheduleCardsSupported || !this.schedules)
|
|
385
|
+
return;
|
|
386
|
+
const epoch = this.imageConnectionEpoch;
|
|
387
|
+
const result = await this.scheduleCards.action(message);
|
|
388
|
+
if (!this.isDestroyed && this.scheduleCardsSupported && epoch === this.imageConnectionEpoch)
|
|
389
|
+
this.wsClient.send(result);
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
319
392
|
case 'settings_action':
|
|
320
393
|
if (this.settingsCardsSupported) {
|
|
321
394
|
const request = message;
|
|
@@ -359,6 +432,16 @@ class MessageHandler {
|
|
|
359
432
|
this.attachmentHintsSupported = data.capabilities?.outputAttachmentHintsV1 === true;
|
|
360
433
|
this.pendingOutputSupported = data.capabilities?.pendingOutputFilesV1 === true;
|
|
361
434
|
this.routerVersion = typeof data.routerVersion === 'string' ? data.routerVersion : undefined;
|
|
435
|
+
this.scheduleResultsSupported = data.capabilities?.scheduleResultsV1 === true;
|
|
436
|
+
this.scheduleCardsSupported = this.scheduleResultsSupported && data.capabilities?.scheduleCardsV1 === true;
|
|
437
|
+
this.scheduleToolCardsSupported = this.scheduleCardsSupported && data.capabilities?.scheduleToolCardsV1 === true;
|
|
438
|
+
if (this.scheduleResultsSupported) {
|
|
439
|
+
void this.recoverSchedules().catch(() => {
|
|
440
|
+
if (this.isDestroyed || !this.scheduleResultsSupported)
|
|
441
|
+
return;
|
|
442
|
+
console.warn('[Schedules] Local schedule recovery is unavailable. Use /schedule list for details.');
|
|
443
|
+
});
|
|
444
|
+
}
|
|
362
445
|
if (data.capabilities?.outputFilesV1 === true) {
|
|
363
446
|
try {
|
|
364
447
|
if (!this.outputFiles) {
|
|
@@ -442,6 +525,7 @@ class MessageHandler {
|
|
|
442
525
|
|| this.pendingReplaces.size > 0
|
|
443
526
|
|| this.activeThreadOperations.size > 0
|
|
444
527
|
|| this.abortOperations.size > 0
|
|
528
|
+
|| this.scheduleManagement.size > 0 || this.schedules?.hasActiveSchedules()
|
|
445
529
|
|| this.threadManager.listThreads().some(thread => this.settingsAdmission.isBlocked(thread.id))) {
|
|
446
530
|
return false;
|
|
447
531
|
}
|
|
@@ -579,6 +663,10 @@ class MessageHandler {
|
|
|
579
663
|
return;
|
|
580
664
|
}
|
|
581
665
|
const settingsCommand = content?.trim() ?? '';
|
|
666
|
+
if (/^\/schedule(?:\s|$)/.test(settingsCommand)) {
|
|
667
|
+
await this.handleScheduleCommand(message, resolvedThreadId);
|
|
668
|
+
return;
|
|
669
|
+
}
|
|
582
670
|
if (settingsCommand === '/clear' || settingsCommand === '/new') {
|
|
583
671
|
await this.clearThreadConversation(messageId, resolvedThreadId);
|
|
584
672
|
return;
|
|
@@ -1051,6 +1139,7 @@ class MessageHandler {
|
|
|
1051
1139
|
void bridge.close().catch(() => undefined);
|
|
1052
1140
|
}
|
|
1053
1141
|
async clearThreadConversation(messageId, threadId) {
|
|
1142
|
+
await this.assertSchedulesIdle(threadId);
|
|
1054
1143
|
this.conversationRevisions.set(threadId, (this.conversationRevisions.get(threadId) ?? 0) + 1);
|
|
1055
1144
|
this.settingsService.invalidate(threadId);
|
|
1056
1145
|
this.directoryBrowser.invalidate(threadId);
|
|
@@ -1190,6 +1279,8 @@ class MessageHandler {
|
|
|
1190
1279
|
}
|
|
1191
1280
|
}
|
|
1192
1281
|
if (trimmed === '/sandbox' || trimmed.startsWith('/sandbox ')) {
|
|
1282
|
+
if (trimmed !== '/sandbox')
|
|
1283
|
+
await this.assertSchedulesIdle(threadId);
|
|
1193
1284
|
if (!('getSandboxStatus' in executor) || !('configureSandbox' in executor)) {
|
|
1194
1285
|
this.sendResponse(messageId, threadId, { success: false, error: '/sandbox is currently supported by the Codex and Claude Code backends.' });
|
|
1195
1286
|
return true;
|
|
@@ -1305,6 +1396,7 @@ Use /compact to reduce conversation context or /clear to start a fresh context.`
|
|
|
1305
1396
|
- /effort [auto|level] - Open effort settings, or set a native supported level with a text argument
|
|
1306
1397
|
- /goal [objective|pause|resume|clear] - Manage a native Codex goal; optional --budget <tokens> on start or resume
|
|
1307
1398
|
- /sandbox [on|off|read-only|default|allow <directory>|remove <directory>|network on|off] - Configure this thread's sandbox (Codex, Claude Code)
|
|
1399
|
+
- /schedule [capabilities|list|cancel <id>|after|at|cron] - Manage native scheduled tasks; /schedule shows examples
|
|
1308
1400
|
- /delegation [on|off|reset [backend]] - Delegate tasks between installed agent backends; reset saved worker context when needed
|
|
1309
1401
|
- /backend - Open backend settings (Current thread by default; Confirm applies)
|
|
1310
1402
|
- /backend <index> - Switch all threads and clear per-thread backend overrides
|
|
@@ -1835,6 +1927,7 @@ You can also use natural language commands to control Claude Code CLI.`,
|
|
|
1835
1927
|
return;
|
|
1836
1928
|
}
|
|
1837
1929
|
try {
|
|
1930
|
+
await this.assertSchedulesIdle(target.id);
|
|
1838
1931
|
await this.delegation.cancelThread(target.id);
|
|
1839
1932
|
await this.delegationBridges.get(target.id)?.close();
|
|
1840
1933
|
this.delegationBridges.delete(target.id);
|
|
@@ -2316,6 +2409,8 @@ You can also use natural language commands to control Claude Code CLI.`,
|
|
|
2316
2409
|
throw new Error('Conversation request was cancelled'); };
|
|
2317
2410
|
this.sendStreamContext(messageId, threadId, executor);
|
|
2318
2411
|
let delegationScope;
|
|
2412
|
+
let scheduleScope;
|
|
2413
|
+
let clearScheduleModelOverride;
|
|
2319
2414
|
let delegationBridge;
|
|
2320
2415
|
let executionMetadata;
|
|
2321
2416
|
let requestFinished = false;
|
|
@@ -2382,6 +2477,12 @@ You can also use natural language commands to control Claude Code CLI.`,
|
|
|
2382
2477
|
}
|
|
2383
2478
|
const responseError = fromQueue && !success
|
|
2384
2479
|
? this.pauseQueueAfterFailure(threadId, error || 'Queued command failed') : error;
|
|
2480
|
+
const scheduleFailures = scheduleScope?.unreportedFailures() ?? [];
|
|
2481
|
+
if (scheduleFailures.length) {
|
|
2482
|
+
const details = scheduleFailures.slice(0, 5).map(result => `${result.requestId}: ${result.error ?? 'Operation failed.'}${result.scheduleId ? `\nTask reference: ${result.scheduleId}` : ''}`).join('\n\n');
|
|
2483
|
+
const fence = '`'.repeat(Math.max(3, ...Array.from(details.matchAll(/`+/g), match => match[0].length + 1)));
|
|
2484
|
+
this.sendStreamChunk(messageId, threadId, `\nScheduled operation failed after its pending receipt:\n${fence}text\n${details}\n${fence}\nUse /schedule list to inspect the final task state before retrying.\n`);
|
|
2485
|
+
}
|
|
2385
2486
|
this.sendResponse(messageId, threadId, { success, error: responseError, threads: this.threadPool.getSummaries(), executionMetadata, attachmentHints: outputAttachmentHints });
|
|
2386
2487
|
if (fromQueue)
|
|
2387
2488
|
console.log(`[MessageHandler] Finished queued message ${messageId} in thread ${threadId}: success=${success}, remaining=${this.threadQueues.get(threadId)?.length ?? 0}, paused=${this.pausedQueues.has(threadId)}`);
|
|
@@ -2403,6 +2504,11 @@ You can also use natural language commands to control Claude Code CLI.`,
|
|
|
2403
2504
|
}
|
|
2404
2505
|
await this.delegation.assertExecutionSafe(executor.getCurrentWorkingDirectory(), threadId);
|
|
2405
2506
|
assertCurrent();
|
|
2507
|
+
if ((goalRequest || !openId) && executor.configureManagedTools && this.delegationBridges.has(threadId)) {
|
|
2508
|
+
await executor.configureManagedTools(undefined);
|
|
2509
|
+
assertCurrent();
|
|
2510
|
+
this.detachDelegationBridge(threadId);
|
|
2511
|
+
}
|
|
2406
2512
|
if (thread && (0, DelegationSettings_1.isDelegationEnabled)(thread) && executor.configureDelegation) {
|
|
2407
2513
|
const backend = this.threadPool.getBackendKey(threadId);
|
|
2408
2514
|
if (!thread.delegationBackends?.includes(backend)) {
|
|
@@ -2450,18 +2556,69 @@ You can also use natural language commands to control Claude Code CLI.`,
|
|
|
2450
2556
|
}), });
|
|
2451
2557
|
delegationBridge = this.delegationBridges.get(threadId) ?? new DelegationBridge_1.DelegationBridge();
|
|
2452
2558
|
this.delegationBridges.set(threadId, delegationBridge);
|
|
2453
|
-
const connection = await delegationBridge.start();
|
|
2559
|
+
const connection = await delegationBridge.start(executor.configureManagedTools && openId && !goalRequest ? ['delegation', 'scheduling'] : undefined);
|
|
2454
2560
|
assertCurrent();
|
|
2455
|
-
await executor.configureDelegation(connection);
|
|
2561
|
+
await (executor.configureManagedTools ?? executor.configureDelegation).call(executor, connection);
|
|
2456
2562
|
assertCurrent();
|
|
2457
2563
|
if (delegationScope.isClosed() || this.isDestroyed || this.abortOperations.has(threadId)) {
|
|
2458
2564
|
throw new Error('Delegation was cancelled before the coordinator started');
|
|
2459
2565
|
}
|
|
2460
2566
|
content = `${contract_1.DELEGATION_INSTRUCTIONS}\n\nUser request:\n${content}`;
|
|
2461
2567
|
}
|
|
2462
|
-
else if (
|
|
2568
|
+
else if ((!executor.configureManagedTools || goalRequest || !openId)
|
|
2569
|
+
&& thread?.delegationBackends?.includes(this.threadPool.getBackendKey(threadId)) && executor.configureDelegation) {
|
|
2463
2570
|
await executor.configureDelegation(undefined);
|
|
2464
2571
|
}
|
|
2572
|
+
if (thread && openId && !goalRequest && executor.configureManagedTools) {
|
|
2573
|
+
const owner = { threadId, openId, generation: this.scheduleGeneration(threadId) };
|
|
2574
|
+
const epoch = this.imageConnectionEpoch;
|
|
2575
|
+
const backend = this.threadPool.getBackendKey(threadId);
|
|
2576
|
+
const config = structuredClone(this.executorConfiguration());
|
|
2577
|
+
let settings = JSON.stringify({ config, models: thread.models, model: thread.model, efforts: thread.efforts });
|
|
2578
|
+
const context = { backend, config, cwd: thread.workingDirectory,
|
|
2579
|
+
model: thread.models?.[backend] ?? (backend === 'claude' ? thread.model || undefined : config[backend]?.model),
|
|
2580
|
+
effort: thread.efforts?.[backend],
|
|
2581
|
+
current: () => {
|
|
2582
|
+
try {
|
|
2583
|
+
const latest = this.threadManager.getThread(threadId);
|
|
2584
|
+
return isCurrent() && !this.abortOperations.has(threadId) && !this.automaticUpdateInProgress && this.wsClient.isConnected()
|
|
2585
|
+
&& epoch === this.imageConnectionEpoch && this.scheduleGeneration(threadId) === owner.generation
|
|
2586
|
+
&& this.threadPool.getBackendKey(threadId) === backend && !!latest
|
|
2587
|
+
&& JSON.stringify({ config: this.executorConfiguration(), models: latest.models, model: latest.model, efforts: latest.efforts }) === settings;
|
|
2588
|
+
}
|
|
2589
|
+
catch {
|
|
2590
|
+
return false;
|
|
2591
|
+
}
|
|
2592
|
+
} };
|
|
2593
|
+
clearScheduleModelOverride = () => {
|
|
2594
|
+
// Match only the authorized recovery mutation. Other concurrent policy
|
|
2595
|
+
// or model changes still fail the captured-context comparison.
|
|
2596
|
+
const captured = JSON.parse(settings);
|
|
2597
|
+
if (captured.models)
|
|
2598
|
+
delete captured.models.codex;
|
|
2599
|
+
settings = JSON.stringify(captured);
|
|
2600
|
+
context.model = config.codex?.model;
|
|
2601
|
+
};
|
|
2602
|
+
if (!delegationBridge) {
|
|
2603
|
+
delegationBridge = this.delegationBridges.get(threadId) ?? new DelegationBridge_1.DelegationBridge();
|
|
2604
|
+
this.delegationBridges.set(threadId, delegationBridge);
|
|
2605
|
+
const connection = await delegationBridge.start(['scheduling']);
|
|
2606
|
+
assertCurrent();
|
|
2607
|
+
await executor.configureManagedTools(connection);
|
|
2608
|
+
assertCurrent();
|
|
2609
|
+
}
|
|
2610
|
+
scheduleScope = this.scheduleToolOperations.scope({ owner, messageId, backend, current: context.current,
|
|
2611
|
+
run: (command, id) => this.runScheduleOperation(owner, command, id, context),
|
|
2612
|
+
present: async (records, operationId) => {
|
|
2613
|
+
if (!context.current() || !this.scheduleToolCardsSupported)
|
|
2614
|
+
return 'Management card unavailable. Use /schedule list; do not recreate the task.';
|
|
2615
|
+
const menu = this.scheduleCards.open(owner, records);
|
|
2616
|
+
return this.deliverScheduleToolCard({ type: 'schedule_tool_card', messageId: `schedule-card-${operationId}`,
|
|
2617
|
+
parentMessageId: messageId, openId, threadId, menu, timestamp: Date.now() });
|
|
2618
|
+
},
|
|
2619
|
+
});
|
|
2620
|
+
content = `${(0, toolContract_1.scheduleGuidance)()}\n\nUser request:\n${content}`;
|
|
2621
|
+
}
|
|
2465
2622
|
// Retain the callback so native completion tracking consumes late items
|
|
2466
2623
|
// and deduplicates them without adding background output to another turn.
|
|
2467
2624
|
const onTaskNotification = (_notification) => { };
|
|
@@ -2584,11 +2741,13 @@ You can also use natural language commands to control Claude Code CLI.`,
|
|
|
2584
2741
|
showState('Working');
|
|
2585
2742
|
scope?.beginExecution(continuationResults.map(task => task.taskId));
|
|
2586
2743
|
const launchRevision = scope?.getLaunchRevision();
|
|
2587
|
-
if (scope)
|
|
2588
|
-
delegationBridge?.activate((
|
|
2589
|
-
if (!active)
|
|
2744
|
+
if (scope || scheduleScope)
|
|
2745
|
+
delegationBridge?.activate((name, args, callId) => {
|
|
2746
|
+
if (!active || !isCurrent())
|
|
2590
2747
|
return Promise.reject(new Error('The coordinator execution has ended'));
|
|
2591
|
-
|
|
2748
|
+
if (name.startsWith('remote_cli_schedule_') && scheduleScope)
|
|
2749
|
+
return scheduleScope.invoke(name, args);
|
|
2750
|
+
return scope ? scope.invoke(name, args, callId) : Promise.reject(new Error('Delegation is disabled for this turn.'));
|
|
2592
2751
|
});
|
|
2593
2752
|
const canPublish = () => isCurrent() && active && (!scope || (!scope.isClosed() && !scope.hasPendingResults()));
|
|
2594
2753
|
const guardedOptions = {
|
|
@@ -2714,7 +2873,8 @@ You can also use natural language commands to control Claude Code CLI.`,
|
|
|
2714
2873
|
if (!finished)
|
|
2715
2874
|
scope?.finishExecution(false);
|
|
2716
2875
|
// Goal activation mutates durable native state; never replay it as a model retry.
|
|
2717
|
-
|
|
2876
|
+
await scheduleScope?.drain();
|
|
2877
|
+
mayRetry = !goalRequest && !scheduleScope?.hasSideEffects && (!scope || scope.getLaunchRevision() === launchRevision);
|
|
2718
2878
|
}
|
|
2719
2879
|
};
|
|
2720
2880
|
finishPreparation();
|
|
@@ -2732,6 +2892,7 @@ You can also use natural language commands to control Claude Code CLI.`,
|
|
|
2732
2892
|
return this.clearInvalidCodexModel(threadId, executor, result.error);
|
|
2733
2893
|
})) {
|
|
2734
2894
|
assertCoordinatorActive();
|
|
2895
|
+
clearScheduleModelOverride?.();
|
|
2735
2896
|
this.sendStreamChunk(messageId, threadId, '⚠️ The saved Codex model is unavailable for this account. Cleared it and retrying with the backend default...\n');
|
|
2736
2897
|
// Retain the ordinary path's existing image-flush timing on model retry.
|
|
2737
2898
|
result = await executeOnce(prompt, options, !!delegationScope);
|
|
@@ -2806,6 +2967,8 @@ You can also use natural language commands to control Claude Code CLI.`,
|
|
|
2806
2967
|
}
|
|
2807
2968
|
finally {
|
|
2808
2969
|
finishPreparation();
|
|
2970
|
+
await scheduleScope?.close();
|
|
2971
|
+
delegationBridge?.activate(undefined);
|
|
2809
2972
|
if (delegationBridge && this.delegationBridges.get(threadId) !== delegationBridge) {
|
|
2810
2973
|
void delegationBridge.close().catch(() => undefined);
|
|
2811
2974
|
}
|
|
@@ -3112,6 +3275,7 @@ You can also use natural language commands to control Claude Code CLI.`,
|
|
|
3112
3275
|
threads: result.threads,
|
|
3113
3276
|
queueConfirmation: result.queueConfirmation,
|
|
3114
3277
|
...(result.executionMetadata ? { executionMetadata: result.executionMetadata } : {}),
|
|
3278
|
+
...(this.scheduleCardsSupported && result.scheduleMenu ? { scheduleMenu: result.scheduleMenu } : {}),
|
|
3115
3279
|
...(this.attachmentHintsSupported && result.attachmentHints ? { attachmentHints: result.attachmentHints } : {}),
|
|
3116
3280
|
...(this.settingsCardsSupported && result.settingsMenu
|
|
3117
3281
|
&& (result.settingsMenu.kind !== 'delegation' || this.delegationCardsSupported)
|
|
@@ -3129,8 +3293,254 @@ You can also use natural language commands to control Claude Code CLI.`,
|
|
|
3129
3293
|
executorConfiguration() {
|
|
3130
3294
|
return this.config.get('executor') ?? { type: 'auto' };
|
|
3131
3295
|
}
|
|
3296
|
+
scheduleGeneration(threadId) {
|
|
3297
|
+
const thread = this.threadManager.getThread(threadId);
|
|
3298
|
+
if (!thread)
|
|
3299
|
+
throw new Error('This thread no longer exists.');
|
|
3300
|
+
this.threadManager.contextResets.assertReady(threadId);
|
|
3301
|
+
return (0, crypto_1.createHash)('sha256').update(JSON.stringify({
|
|
3302
|
+
server: this.config.get('serverUrl'), device: this.config.get('deviceId'),
|
|
3303
|
+
thread: threadId, cwd: thread.workingDirectory,
|
|
3304
|
+
generation: this.threadManager.contextResets.generation(threadId, thread.delegationWorkspaceGeneration ?? 0),
|
|
3305
|
+
})).digest('hex');
|
|
3306
|
+
}
|
|
3307
|
+
scheduleDirectory() {
|
|
3308
|
+
const directory = this.config.getConfigDir?.();
|
|
3309
|
+
if (typeof directory !== 'string' || !directory)
|
|
3310
|
+
return undefined;
|
|
3311
|
+
const namespace = (0, crypto_1.createHash)('sha256').update(JSON.stringify({
|
|
3312
|
+
server: this.config.get('serverUrl'), device: this.config.get('deviceId'),
|
|
3313
|
+
})).digest('hex');
|
|
3314
|
+
return path_1.default.join(directory, 'schedules', namespace);
|
|
3315
|
+
}
|
|
3316
|
+
/** Binding recovery only reads existing storage; explicit command/tool use initializes it. */
|
|
3317
|
+
async recoverSchedules() {
|
|
3318
|
+
if (this.isDestroyed || !this.scheduleResultsSupported)
|
|
3319
|
+
return;
|
|
3320
|
+
if (!this.scheduleInitialization) {
|
|
3321
|
+
const directory = this.scheduleDirectory();
|
|
3322
|
+
if (!directory)
|
|
3323
|
+
return;
|
|
3324
|
+
try {
|
|
3325
|
+
await fs_1.default.promises.lstat(path_1.default.join(directory, ScheduleService_1.SCHEDULE_CATALOG_FILE));
|
|
3326
|
+
}
|
|
3327
|
+
catch (error) {
|
|
3328
|
+
if (['ENOENT', 'ENOTDIR'].includes(error.code ?? ''))
|
|
3329
|
+
return;
|
|
3330
|
+
throw error;
|
|
3331
|
+
}
|
|
3332
|
+
}
|
|
3333
|
+
// A disconnect or shutdown can happen while storage is being checked. Never
|
|
3334
|
+
// create a late service/subscription after shutdown has collected its work.
|
|
3335
|
+
if (this.isDestroyed || !this.scheduleResultsSupported)
|
|
3336
|
+
return;
|
|
3337
|
+
const service = await this.initializeSchedules();
|
|
3338
|
+
if (!this.isDestroyed && this.scheduleResultsSupported)
|
|
3339
|
+
await service.retryDeliveries();
|
|
3340
|
+
}
|
|
3341
|
+
initializeSchedules() {
|
|
3342
|
+
if (this.scheduleInitialization)
|
|
3343
|
+
return this.scheduleInitialization;
|
|
3344
|
+
this.scheduleInitialization = (async () => {
|
|
3345
|
+
if (this.isDestroyed)
|
|
3346
|
+
throw new Error('The client is shutting down.');
|
|
3347
|
+
const directory = this.scheduleDirectory();
|
|
3348
|
+
if (!directory)
|
|
3349
|
+
throw new Error('Local schedule storage is unavailable.');
|
|
3350
|
+
const providers = { claude: new ClaudeNativeScheduleProvider_1.ClaudeNativeScheduleProvider(), dsh: new DshNativeScheduleProvider_1.DshNativeScheduleProvider() };
|
|
3351
|
+
const service = new ScheduleService_1.ScheduleService({
|
|
3352
|
+
directory,
|
|
3353
|
+
provider: { create: (input, onEvent) => {
|
|
3354
|
+
const backend = input.backend === undefined ? 'claude' : input.backend;
|
|
3355
|
+
(0, ScheduleCapabilities_1.assertNativeScheduleBackend)(backend);
|
|
3356
|
+
return providers[backend].create(input, onEvent);
|
|
3357
|
+
} },
|
|
3358
|
+
isOwnerCurrent: owner => {
|
|
3359
|
+
// Shutdown blocks delivery separately; it does not invalidate persisted ownership.
|
|
3360
|
+
try {
|
|
3361
|
+
return this.scheduleGeneration(owner.threadId) === owner.generation;
|
|
3362
|
+
}
|
|
3363
|
+
catch {
|
|
3364
|
+
return false;
|
|
3365
|
+
}
|
|
3366
|
+
},
|
|
3367
|
+
deliver: async (delivery) => {
|
|
3368
|
+
if (!this.scheduleResultsSupported || this.isDestroyed)
|
|
3369
|
+
throw new Error('Scheduled result delivery is unavailable.');
|
|
3370
|
+
const thread = this.threadManager.getThread(delivery.schedule.threadId);
|
|
3371
|
+
if (!thread)
|
|
3372
|
+
throw new Error('The original thread no longer exists.');
|
|
3373
|
+
await this.scheduleDelivery.deliver(delivery, thread.name);
|
|
3374
|
+
},
|
|
3375
|
+
});
|
|
3376
|
+
await service.initialize();
|
|
3377
|
+
if (!this.isDestroyed)
|
|
3378
|
+
this.scheduleDelivery = new ScheduleDeliveryClient_1.ScheduleDeliveryClient(this.wsClient);
|
|
3379
|
+
this.schedules = service;
|
|
3380
|
+
return service;
|
|
3381
|
+
})();
|
|
3382
|
+
return this.scheduleInitialization;
|
|
3383
|
+
}
|
|
3384
|
+
async activeSchedules(threadId) {
|
|
3385
|
+
const owner = this.scheduleOwners.get(threadId);
|
|
3386
|
+
if (!owner || !this.schedules)
|
|
3387
|
+
return [];
|
|
3388
|
+
const records = await this.schedules.list(owner);
|
|
3389
|
+
const active = records.filter(record => ['creating', 'active', 'running'].includes(record.state));
|
|
3390
|
+
if (!active.length && !this.scheduleManagement.has(threadId))
|
|
3391
|
+
this.scheduleOwners.delete(threadId);
|
|
3392
|
+
return active;
|
|
3393
|
+
}
|
|
3394
|
+
async assertSchedulesIdle(threadId) {
|
|
3395
|
+
if (this.scheduleManagement.has(threadId) || this.schedules?.hasActiveSchedules(threadId)) {
|
|
3396
|
+
throw new Error('Cancel this thread\'s schedules with /schedule cancel <id> before resetting context, changing directory, or deleting the thread.');
|
|
3397
|
+
}
|
|
3398
|
+
}
|
|
3399
|
+
clearScheduleCardReceipts() {
|
|
3400
|
+
for (const pending of this.scheduleCardReceipts.values()) {
|
|
3401
|
+
clearTimeout(pending.timer);
|
|
3402
|
+
pending.resolve('Management card delivery is unknown. Use /schedule list; do not recreate the task.');
|
|
3403
|
+
}
|
|
3404
|
+
this.scheduleCardReceipts.clear();
|
|
3405
|
+
}
|
|
3406
|
+
deliverScheduleToolCard(message) {
|
|
3407
|
+
if (this.scheduleCardReceipts.size >= 5)
|
|
3408
|
+
return Promise.resolve('Management card limit reached. Use /schedule list.');
|
|
3409
|
+
return new Promise(resolve => {
|
|
3410
|
+
const timer = setTimeout(() => {
|
|
3411
|
+
this.scheduleCardReceipts.delete(message.messageId);
|
|
3412
|
+
resolve('Management card delivery is unknown. Use /schedule list; do not recreate the task.');
|
|
3413
|
+
}, 8000);
|
|
3414
|
+
this.scheduleCardReceipts.set(message.messageId, { resolve, timer });
|
|
3415
|
+
try {
|
|
3416
|
+
if (this.wsClient.send(message))
|
|
3417
|
+
return;
|
|
3418
|
+
}
|
|
3419
|
+
catch { /* The native operation already succeeded. */ }
|
|
3420
|
+
clearTimeout(timer);
|
|
3421
|
+
this.scheduleCardReceipts.delete(message.messageId);
|
|
3422
|
+
resolve('Management card unavailable. Use /schedule list; do not recreate the task.');
|
|
3423
|
+
});
|
|
3424
|
+
}
|
|
3425
|
+
/** Shared admission for slash commands and scoped model tools. Native providers alone own timing. */
|
|
3426
|
+
async runScheduleOperation(owner, command, id = (0, uuid_1.v4)(), context) {
|
|
3427
|
+
const current = () => {
|
|
3428
|
+
try {
|
|
3429
|
+
return !this.isDestroyed && this.scheduleGeneration(owner.threadId) === owner.generation && (!context || context.current());
|
|
3430
|
+
}
|
|
3431
|
+
catch {
|
|
3432
|
+
return false;
|
|
3433
|
+
}
|
|
3434
|
+
};
|
|
3435
|
+
const check = () => { if (!current() || this.automaticUpdateInProgress)
|
|
3436
|
+
throw new Error('Scheduling context changed or client is shutting down/updating.'); };
|
|
3437
|
+
check();
|
|
3438
|
+
if (this.scheduleManagement.has(owner.threadId))
|
|
3439
|
+
throw new Error('A schedule operation is already in progress for this thread.');
|
|
3440
|
+
this.scheduleManagement.add(owner.threadId);
|
|
3441
|
+
try {
|
|
3442
|
+
const backend = context?.backend ?? this.threadPool.getBackendKey(owner.threadId);
|
|
3443
|
+
const config = context?.config ?? this.executorConfiguration();
|
|
3444
|
+
if (command.kind === 'create') {
|
|
3445
|
+
(0, ScheduleCapabilities_1.assertNativeScheduleBackend)(backend);
|
|
3446
|
+
if (!this.scheduleResultsSupported || !this.wsClient.isConnected())
|
|
3447
|
+
throw new Error('Schedule creation requires a connected Router with scheduleResultsV1 support.');
|
|
3448
|
+
if (backend === 'claude' && new ClaudeSandbox_1.ClaudeSandbox(this.directoryGuard, config.claude?.sandbox, owner.threadId).isRestricted()) {
|
|
3449
|
+
throw new Error('This native scheduling adapter does not support restricted Claude sandboxes. No schedule was created and sandbox settings were not changed.');
|
|
3450
|
+
}
|
|
3451
|
+
}
|
|
3452
|
+
const service = await this.initializeSchedules();
|
|
3453
|
+
check();
|
|
3454
|
+
if (command.kind === 'list') {
|
|
3455
|
+
await service.refresh(owner);
|
|
3456
|
+
check();
|
|
3457
|
+
void service.retryDeliveries().catch(() => { });
|
|
3458
|
+
return service.list(owner);
|
|
3459
|
+
}
|
|
3460
|
+
if (command.kind === 'cancel')
|
|
3461
|
+
return [await service.cancel(owner, command.id)];
|
|
3462
|
+
(0, ScheduleCapabilities_1.assertNativeScheduleBackend)(backend);
|
|
3463
|
+
// A durable record fences retries after lost in-memory receipts or a process restart.
|
|
3464
|
+
if ((await service.list(owner)).some(record => record.id === id))
|
|
3465
|
+
throw new Error(`Schedule ${id} already has a durable record. Use /schedule list; it was not recreated.`);
|
|
3466
|
+
check();
|
|
3467
|
+
const thread = this.threadManager.getThread(owner.threadId);
|
|
3468
|
+
const cwd = this.directoryGuard.resolveWorkingDirectory(context?.cwd ?? thread.workingDirectory);
|
|
3469
|
+
(0, WorkingDirectory_1.assertWorkingDirectoryExists)(cwd);
|
|
3470
|
+
const existingOwner = this.scheduleOwners.get(owner.threadId);
|
|
3471
|
+
if (existingOwner && existingOwner.openId !== owner.openId && (await this.activeSchedules(owner.threadId)).length)
|
|
3472
|
+
throw new Error('This thread has schedules belonging to a different owner.');
|
|
3473
|
+
check();
|
|
3474
|
+
this.scheduleOwners.set(owner.threadId, owner);
|
|
3475
|
+
const record = await service.create(owner, { id, backend, cwd, rule: command.rule, prompt: command.prompt,
|
|
3476
|
+
command: config[backend]?.command,
|
|
3477
|
+
model: context ? context.model : thread.models?.[backend] ?? (backend === 'claude' ? thread.model || undefined : config.dsh?.model),
|
|
3478
|
+
effort: context ? context.effort : thread.efforts?.[backend] });
|
|
3479
|
+
if (!current()) {
|
|
3480
|
+
await service.cancel(owner, record.id);
|
|
3481
|
+
throw new Error('Scheduling context retired during creation; the native task was cancelled.');
|
|
3482
|
+
}
|
|
3483
|
+
return [record];
|
|
3484
|
+
}
|
|
3485
|
+
finally {
|
|
3486
|
+
this.scheduleManagement.delete(owner.threadId);
|
|
3487
|
+
await this.activeSchedules(owner.threadId).catch(() => undefined);
|
|
3488
|
+
}
|
|
3489
|
+
}
|
|
3490
|
+
async handleScheduleCommand(message, threadId) {
|
|
3491
|
+
const respond = (result) => this.sendResponse(message.messageId, threadId, result, true);
|
|
3492
|
+
const menuFor = (owner, records) => {
|
|
3493
|
+
if (!this.scheduleCardsSupported)
|
|
3494
|
+
return undefined;
|
|
3495
|
+
try {
|
|
3496
|
+
return this.scheduleCards.open(owner, records);
|
|
3497
|
+
}
|
|
3498
|
+
catch {
|
|
3499
|
+
return undefined;
|
|
3500
|
+
} // A presentation failure must not turn successful native work into a failed command.
|
|
3501
|
+
};
|
|
3502
|
+
try {
|
|
3503
|
+
const command = (0, ScheduleCommand_1.parseScheduleCommand)(message.content ?? '');
|
|
3504
|
+
if (!command || command.kind === 'help') {
|
|
3505
|
+
respond({ success: true, output: ScheduleCommand_1.SCHEDULE_USAGE });
|
|
3506
|
+
return;
|
|
3507
|
+
}
|
|
3508
|
+
if (command.kind === 'invalid') {
|
|
3509
|
+
respond({ success: false, error: command.message });
|
|
3510
|
+
return;
|
|
3511
|
+
}
|
|
3512
|
+
if (command.kind === 'capabilities') {
|
|
3513
|
+
respond({ success: true, output: ScheduleCapabilities_1.SCHEDULE_CAPABILITIES });
|
|
3514
|
+
return;
|
|
3515
|
+
}
|
|
3516
|
+
if (!message.openId)
|
|
3517
|
+
throw new Error('Scheduled tasks require an authenticated thread owner.');
|
|
3518
|
+
if (message.attachments?.length || message.fileIds?.length || message.workingDirectory) {
|
|
3519
|
+
throw new Error('Use /cd first and include a self-contained text prompt. Schedule commands do not accept attachments or directory overrides.');
|
|
3520
|
+
}
|
|
3521
|
+
const owner = { threadId, openId: message.openId, generation: this.scheduleGeneration(threadId) };
|
|
3522
|
+
const records = await this.runScheduleOperation(owner, command.kind === 'list' ? { kind: 'list' } : command);
|
|
3523
|
+
const record = records[0];
|
|
3524
|
+
let output;
|
|
3525
|
+
if (command.kind === 'list')
|
|
3526
|
+
output = records.length ? records.map(item => `${item.id} — ${item.state}\n${item.rule.kind === 'once' ? item.rule.at : `${item.rule.expression} (${item.rule.timezone})`}\n${item.prompt.slice(0, 240)}${item.error ? `\n${item.error}` : ''}`).join('\n\n') : 'No schedules in this thread. Use /schedule for examples.';
|
|
3527
|
+
else if (command.kind === 'cancel')
|
|
3528
|
+
output = `Schedule ${record.id}: ${record.state}.`;
|
|
3529
|
+
else {
|
|
3530
|
+
const lifecycle = record.backend === 'claude'
|
|
3531
|
+
? 'Schedules are lost when the native process exits; recurring tasks expire after seven days.'
|
|
3532
|
+
: 'Native job storage is isolated and is never automatically reopened after process exit.';
|
|
3533
|
+
output = `Schedule ${record.id}: ${record.state}.\n${record.rule.kind === 'once' ? record.rule.at : `${record.rule.expression} (${record.rule.timezone})`}\n\nRuns in its own ${ScheduleCapabilities_1.NATIVE_SCHEDULE_CAPABILITIES[record.backend].label} session and returns results to this thread. Keep the CLI running; native timing is approximate. ${lifecycle}\nUse /schedule list or /schedule cancel ${record.id}.`;
|
|
3534
|
+
}
|
|
3535
|
+
respond({ success: true, scheduleMenu: menuFor(owner, records), output });
|
|
3536
|
+
}
|
|
3537
|
+
catch (error) {
|
|
3538
|
+
respond({ success: false, error: error instanceof Error ? error.message : 'Schedule operation failed.' });
|
|
3539
|
+
}
|
|
3540
|
+
}
|
|
3132
3541
|
/** Shared card/text Apply path. Callers hold exclusive settings admission. */
|
|
3133
3542
|
async changeWorkingDirectory(threadId, targetDir) {
|
|
3543
|
+
await this.assertSchedulesIdle(threadId);
|
|
3134
3544
|
if (this.isDestroyed || this.automaticUpdateInProgress || this.abortOperations.has(threadId)
|
|
3135
3545
|
|| this.threadPool.isThreadBusy(threadId) || this.coordinatorPreparations.has(threadId) || this.hasThreadQueueState(threadId)) {
|
|
3136
3546
|
throw new Error('Cannot change working directory while the thread has active or queued work. Retry when it is idle.');
|
|
@@ -3445,7 +3855,10 @@ You can also use natural language commands to control Claude Code CLI.`,
|
|
|
3445
3855
|
async destroy() {
|
|
3446
3856
|
this.directoryBrowser.destroy();
|
|
3447
3857
|
this.settingsService.destroy();
|
|
3858
|
+
this.scheduleCards.destroy();
|
|
3859
|
+
this.clearScheduleCardReceipts();
|
|
3448
3860
|
this.isDestroyed = true;
|
|
3861
|
+
this.scheduleDelivery?.destroy();
|
|
3449
3862
|
this.pendingOutputFiles.clear();
|
|
3450
3863
|
for (const threadId of this.activeThreadOperations.keys()) {
|
|
3451
3864
|
this.settingsAdmission.cancelRecoverable(threadId);
|
|
@@ -3459,6 +3872,7 @@ You can also use natural language commands to control Claude Code CLI.`,
|
|
|
3459
3872
|
this.notificationAdapter.unregister();
|
|
3460
3873
|
try {
|
|
3461
3874
|
const results = await Promise.allSettled([
|
|
3875
|
+
this.scheduleInitialization?.then(service => service.destroy(), () => undefined),
|
|
3462
3876
|
this.delegation.destroy(),
|
|
3463
3877
|
...[...this.delegationBridges.values()].map(bridge => bridge.close()),
|
|
3464
3878
|
this.threadPool.destroyAll({ deleteData: false, shutdown: true }),
|