@yu_robotics/remote-cli 1.6.234 → 1.6.235
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.map +1 -1
- package/dist/client/MessageHandler.js +77 -11
- package/dist/client/MessageHandler.js.map +1 -1
- package/dist/executor/AcpExecutor.d.ts +13 -1
- package/dist/executor/AcpExecutor.d.ts.map +1 -1
- package/dist/executor/AcpExecutor.js +18 -2
- package/dist/executor/AcpExecutor.js.map +1 -1
- package/dist/executor/ClaudePersistentExecutor.d.ts +14 -0
- package/dist/executor/ClaudePersistentExecutor.d.ts.map +1 -1
- package/dist/executor/ClaudePersistentExecutor.js +184 -10
- package/dist/executor/ClaudePersistentExecutor.js.map +1 -1
- package/dist/executor/DshExecutor.d.ts +1 -0
- package/dist/executor/DshExecutor.d.ts.map +1 -1
- package/dist/executor/DshExecutor.js +14 -0
- package/dist/executor/DshExecutor.js.map +1 -1
- package/dist/executor/IExecutor.d.ts +5 -0
- package/dist/executor/IExecutor.d.ts.map +1 -1
- package/dist/executor/acp/AcpClient.d.ts +4 -3
- package/dist/executor/acp/AcpClient.d.ts.map +1 -1
- package/dist/executor/acp/AcpClient.js.map +1 -1
- package/dist/executor/dsh/DshAcpClient.d.ts +9 -0
- package/dist/executor/dsh/DshAcpClient.d.ts.map +1 -1
- package/dist/executor/dsh/DshAcpClient.js +72 -2
- package/dist/executor/dsh/DshAcpClient.js.map +1 -1
- package/dist/executor/dsh/DshPrivacy.d.ts +1 -1
- package/dist/executor/dsh/DshPrivacy.d.ts.map +1 -1
- package/dist/executor/dsh/DshPrivacy.js +3 -3
- package/dist/executor/dsh/DshPrivacy.js.map +1 -1
- package/dist/maintenance/release-notes.json +1 -1
- package/dist/managed/tools.d.ts +2 -2
- package/dist/scheduling/ScheduleCapabilities.d.ts +5 -7
- package/dist/scheduling/ScheduleCapabilities.d.ts.map +1 -1
- package/dist/scheduling/ScheduleCapabilities.js +6 -7
- package/dist/scheduling/ScheduleCapabilities.js.map +1 -1
- package/dist/scheduling/ScheduleCommand.js +1 -1
- package/dist/scheduling/ScheduleCommand.js.map +1 -1
- package/dist/scheduling/ScheduleService.d.ts.map +1 -1
- package/dist/scheduling/ScheduleService.js +40 -16
- package/dist/scheduling/ScheduleService.js.map +1 -1
- package/dist/scheduling/ScheduleToolScope.d.ts +1 -0
- package/dist/scheduling/ScheduleToolScope.d.ts.map +1 -1
- package/dist/scheduling/ScheduleToolScope.js +3 -1
- package/dist/scheduling/ScheduleToolScope.js.map +1 -1
- package/dist/scheduling/claude/ClaudeSessionSchedules.d.ts +82 -0
- package/dist/scheduling/claude/ClaudeSessionSchedules.d.ts.map +1 -0
- package/dist/scheduling/claude/ClaudeSessionSchedules.js +457 -0
- package/dist/scheduling/claude/ClaudeSessionSchedules.js.map +1 -0
- package/dist/scheduling/dsh/SessionScheduleBridge.d.ts +35 -0
- package/dist/scheduling/dsh/SessionScheduleBridge.d.ts.map +1 -0
- package/dist/scheduling/dsh/SessionScheduleBridge.js +300 -0
- package/dist/scheduling/dsh/SessionScheduleBridge.js.map +1 -0
- package/dist/scheduling/dsh/SessionScheduleClient.d.ts +15 -0
- package/dist/scheduling/dsh/SessionScheduleClient.d.ts.map +1 -0
- package/dist/scheduling/dsh/SessionScheduleClient.js +182 -0
- package/dist/scheduling/dsh/SessionScheduleClient.js.map +1 -0
- package/dist/scheduling/dsh/SessionScheduleStorage.d.ts +8 -0
- package/dist/scheduling/dsh/SessionScheduleStorage.d.ts.map +1 -0
- package/dist/scheduling/dsh/SessionScheduleStorage.js +34 -0
- package/dist/scheduling/dsh/SessionScheduleStorage.js.map +1 -0
- package/dist/scheduling/dsh/sessionLaunch.d.ts +3 -0
- package/dist/scheduling/dsh/sessionLaunch.d.ts.map +1 -0
- package/dist/scheduling/dsh/sessionLaunch.js +22 -0
- package/dist/scheduling/dsh/sessionLaunch.js.map +1 -0
- package/dist/scheduling/dsh/sessionProtocol.d.ts +4 -0
- package/dist/scheduling/dsh/sessionProtocol.d.ts.map +1 -0
- package/dist/scheduling/dsh/sessionProtocol.js +7 -0
- package/dist/scheduling/dsh/sessionProtocol.js.map +1 -0
- package/dist/scheduling/toolContract.d.ts +1 -1
- package/dist/scheduling/toolContract.js +2 -2
- package/dist/scheduling/toolContract.js.map +1 -1
- package/dist/scheduling/types.d.ts +11 -2
- package/dist/scheduling/types.d.ts.map +1 -1
- package/dist/scheduling/types.js.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,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.ClaudePersistentExecutor = void 0;
|
|
7
|
+
const ClaudeSessionSchedules_1 = require("../scheduling/claude/ClaudeSessionSchedules");
|
|
7
8
|
const tools_1 = require("../managed/tools");
|
|
8
9
|
const ManagedSpawn_1 = require("./ManagedSpawn");
|
|
9
10
|
const OwnershipRuntime_1 = require("../delegation/OwnershipRuntime");
|
|
@@ -271,6 +272,98 @@ class ClaudePersistentExecutor extends events_1.EventEmitter {
|
|
|
271
272
|
}
|
|
272
273
|
return data;
|
|
273
274
|
}
|
|
275
|
+
sessionSchedules;
|
|
276
|
+
scheduleHooksReady = false;
|
|
277
|
+
currentScheduleManagement = false;
|
|
278
|
+
nativeScheduleTimezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
279
|
+
schedules() {
|
|
280
|
+
return this.sessionSchedules ??= new ClaudeSessionSchedules_1.ClaudeSessionSchedules({
|
|
281
|
+
send: frame => {
|
|
282
|
+
if (!this.claudeProcess?.stdin?.writable)
|
|
283
|
+
throw new Error('Native conversation is unavailable.');
|
|
284
|
+
this.claudeProcess.stdin.write(JSON.stringify(frame) + '\n');
|
|
285
|
+
},
|
|
286
|
+
manage: async (prompt, current) => {
|
|
287
|
+
await this.listModels();
|
|
288
|
+
return this.execute(prompt, { nativeScheduleManagement: true, nativeScheduleCurrent: current });
|
|
289
|
+
},
|
|
290
|
+
wake: () => { void this.processQueue(); },
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
async withNativeScheduleOperation(id, current, run, inTurn) {
|
|
294
|
+
if (this.delegationWorker || this.isDestroyed || this.isStopping || this.sandbox.isRestricted())
|
|
295
|
+
throw new Error('Native schedule owner or sandbox is unavailable.');
|
|
296
|
+
if (!inTurn)
|
|
297
|
+
await this.listModels();
|
|
298
|
+
if (!this.scheduleHooksReady)
|
|
299
|
+
throw new Error('Native scheduling hooks are not initialized.');
|
|
300
|
+
return this.schedules().inToolOperation(id, current, run, inTurn);
|
|
301
|
+
}
|
|
302
|
+
nativeScheduleAction(id) { return this.sessionSchedules?.action(id); }
|
|
303
|
+
async createNativeSchedule(input, onEvent, isOwnerCurrent) {
|
|
304
|
+
if (this.delegationWorker || this.isDestroyed || this.isStopping || this.sandbox.isRestricted()
|
|
305
|
+
|| input.cwd !== this.currentWorkingDirectory)
|
|
306
|
+
throw new Error('Native schedule context or sandbox is unavailable.');
|
|
307
|
+
if (!this.scheduleHooksReady)
|
|
308
|
+
throw new Error('Native scheduling hooks are not initialized.');
|
|
309
|
+
const timezone = await this.readNativeScheduleTimezone();
|
|
310
|
+
return this.schedules().create(input, onEvent, isOwnerCurrent, timezone);
|
|
311
|
+
}
|
|
312
|
+
/** Inspect only the effective TZ; never log, retain, or expose settings to a model. */
|
|
313
|
+
readNativeScheduleTimezone() {
|
|
314
|
+
const child = this.claudeProcess;
|
|
315
|
+
if (!child?.stdin?.writable)
|
|
316
|
+
return Promise.reject(new Error('Native conversation is unavailable.'));
|
|
317
|
+
const stdin = child.stdin;
|
|
318
|
+
const requestId = `schedule-timezone-${(0, crypto_1.randomUUID)()}`;
|
|
319
|
+
return new Promise((resolve, reject) => {
|
|
320
|
+
const failure = () => {
|
|
321
|
+
this.pendingControlRequests.delete(requestId);
|
|
322
|
+
clearTimeout(timer);
|
|
323
|
+
reject(new Error('Native session timezone could not be verified. No schedule was created.'));
|
|
324
|
+
};
|
|
325
|
+
const timer = setTimeout(failure, 10_000);
|
|
326
|
+
this.pendingControlRequests.set(requestId, {
|
|
327
|
+
timer, reject: failure,
|
|
328
|
+
resolve: value => {
|
|
329
|
+
clearTimeout(timer);
|
|
330
|
+
this.pendingControlRequests.delete(requestId);
|
|
331
|
+
if (this.claudeProcess !== child || this.isDestroyed || this.isStopping) {
|
|
332
|
+
failure();
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
try {
|
|
336
|
+
const response = value;
|
|
337
|
+
if (!response?.effective || typeof response.effective !== 'object') {
|
|
338
|
+
failure();
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
if (response.effective.disableAllHooks || response.effective.allowManagedHooksOnly) {
|
|
342
|
+
reject(new Error('Native scheduling requires active SDK callback hooks. Native hook policy was not changed.'));
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
const timezone = response.effective.env?.TZ ?? this.nativeScheduleTimezone;
|
|
346
|
+
if (typeof timezone !== 'string' || !timezone || timezone.length > 128) {
|
|
347
|
+
failure();
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
350
|
+
resolve(new Intl.DateTimeFormat('en', { timeZone: timezone }).resolvedOptions().timeZone);
|
|
351
|
+
}
|
|
352
|
+
catch {
|
|
353
|
+
failure();
|
|
354
|
+
}
|
|
355
|
+
},
|
|
356
|
+
});
|
|
357
|
+
try {
|
|
358
|
+
stdin.write(JSON.stringify({ type: 'control_request', request_id: requestId,
|
|
359
|
+
request: { subtype: 'get_settings' } }) + '\n', error => { if (error)
|
|
360
|
+
failure(); });
|
|
361
|
+
}
|
|
362
|
+
catch {
|
|
363
|
+
failure();
|
|
364
|
+
}
|
|
365
|
+
});
|
|
366
|
+
}
|
|
274
367
|
delegation;
|
|
275
368
|
async configureManagedTools(connection) {
|
|
276
369
|
if (this.delegationWorker && connection)
|
|
@@ -293,6 +386,8 @@ class ClaudePersistentExecutor extends events_1.EventEmitter {
|
|
|
293
386
|
* directories that may have their own .claude-session files.
|
|
294
387
|
*/
|
|
295
388
|
isBusy() {
|
|
389
|
+
if (this.sessionSchedules?.busy)
|
|
390
|
+
return true;
|
|
296
391
|
return this.isProcessing || this.isStarting || this.commandQueue.length > 0;
|
|
297
392
|
}
|
|
298
393
|
async setWorkingDirectory(targetPath) {
|
|
@@ -341,6 +436,14 @@ class ClaudePersistentExecutor extends events_1.EventEmitter {
|
|
|
341
436
|
// Build arguments
|
|
342
437
|
// Note: --output-format=stream-json requires --verbose
|
|
343
438
|
const restricted = this.sandbox.isRestricted();
|
|
439
|
+
// Claude restores session-only cron jobs from the resumed transcript, even
|
|
440
|
+
// when the original CronCreate used durable:false. A resumed process that
|
|
441
|
+
// cannot install our ownership hooks must therefore disable native task
|
|
442
|
+
// execution at launch; otherwise a remote-cli job can run unowned after a
|
|
443
|
+
// restart or in a restricted/worker process.
|
|
444
|
+
const managedScheduling = !this.delegationWorker && !restricted
|
|
445
|
+
&& this.delegation?.groups?.includes('scheduling') === true;
|
|
446
|
+
const disableResumedSchedules = !!this.sessionId && !managedScheduling;
|
|
344
447
|
const mcpServers = {};
|
|
345
448
|
const args = [
|
|
346
449
|
'--input-format=stream-json',
|
|
@@ -366,12 +469,14 @@ class ClaudePersistentExecutor extends events_1.EventEmitter {
|
|
|
366
469
|
fileHookCommand = [process.execPath, ClaudePersistentExecutor.FILE_POLICY_SCRIPT, socketPath, this.filePolicyToken]
|
|
367
470
|
.map(quote).join(' ') + ' || exit 2';
|
|
368
471
|
}
|
|
369
|
-
|
|
472
|
+
let settings = this.sandbox.spawnSettings(this.currentWorkingDirectory, fileHookCommand);
|
|
370
473
|
if (settings && this.delegation) {
|
|
371
474
|
const permissions = settings.permissions;
|
|
372
475
|
permissions.allow = [...(permissions.allow ?? []),
|
|
373
476
|
...(0, tools_1.managedTools)(this.delegation).map(tool => `mcp__remote-cli-delegation__${tool.name}`)];
|
|
374
477
|
}
|
|
478
|
+
if (disableResumedSchedules)
|
|
479
|
+
settings = { ...(settings ?? {}), scheduledTasksEnabled: false };
|
|
375
480
|
if (settings)
|
|
376
481
|
args.push('--settings', JSON.stringify(settings));
|
|
377
482
|
mcpServers['remote-cli-approval'] = {
|
|
@@ -384,6 +489,8 @@ class ClaudePersistentExecutor extends events_1.EventEmitter {
|
|
|
384
489
|
}
|
|
385
490
|
else {
|
|
386
491
|
args.push('--dangerously-skip-permissions');
|
|
492
|
+
if (disableResumedSchedules)
|
|
493
|
+
args.push('--settings', JSON.stringify({ scheduledTasksEnabled: false }));
|
|
387
494
|
}
|
|
388
495
|
if (this.delegation) {
|
|
389
496
|
mcpServers['remote-cli-delegation'] = (0, contract_1.delegationMcpConfig)(this.delegation);
|
|
@@ -468,6 +575,9 @@ class ClaudePersistentExecutor extends events_1.EventEmitter {
|
|
|
468
575
|
},
|
|
469
576
|
});
|
|
470
577
|
this.claudeProcess = child;
|
|
578
|
+
this.nativeScheduleTimezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
579
|
+
if (this.delegation?.groups?.includes('scheduling') && !this.delegationWorker && !restricted)
|
|
580
|
+
this.schedules();
|
|
471
581
|
if (this.delegationWorker)
|
|
472
582
|
this.workerGroups.track(child);
|
|
473
583
|
// Buffer for collecting stderr on startup (for error reporting)
|
|
@@ -490,6 +600,10 @@ class ClaudePersistentExecutor extends events_1.EventEmitter {
|
|
|
490
600
|
const forwardStderr = (text) => {
|
|
491
601
|
if (!text)
|
|
492
602
|
return;
|
|
603
|
+
// Stderr has no native turn ID; it cannot be attributed to a foreground
|
|
604
|
+
// request queued behind an autonomous scheduled turn.
|
|
605
|
+
if (this.sessionSchedules?.busy)
|
|
606
|
+
return;
|
|
493
607
|
// Collect stderr during startup for error reporting
|
|
494
608
|
if (isStartupPhase) {
|
|
495
609
|
stderrBuffer.push(text);
|
|
@@ -535,6 +649,11 @@ class ClaudePersistentExecutor extends events_1.EventEmitter {
|
|
|
535
649
|
// Use 'close' event (fires after all I/O streams are closed, i.e. after all stdout
|
|
536
650
|
// data events have been processed) instead of 'exit' for command completion logic.
|
|
537
651
|
child.on('close', (code, signal) => {
|
|
652
|
+
if (this.claudeProcess === child) {
|
|
653
|
+
this.sessionSchedules?.processClosed();
|
|
654
|
+
this.sessionSchedules = undefined;
|
|
655
|
+
this.scheduleHooksReady = false;
|
|
656
|
+
}
|
|
538
657
|
if (this.claudeProcess !== child)
|
|
539
658
|
return;
|
|
540
659
|
flushStderr();
|
|
@@ -624,7 +743,12 @@ class ClaudePersistentExecutor extends events_1.EventEmitter {
|
|
|
624
743
|
child.on('error', (error) => {
|
|
625
744
|
console.error('[ClaudePersistent] Process error:', error);
|
|
626
745
|
this.clearApprovals('Claude process failed');
|
|
627
|
-
|
|
746
|
+
// An error is not exit evidence for a session that owns native jobs.
|
|
747
|
+
// Retain the process until close (or an explicit bounded stop) confirms it.
|
|
748
|
+
if (this.sessionSchedules?.hasJobs)
|
|
749
|
+
this.isStopping = true;
|
|
750
|
+
else
|
|
751
|
+
this.claudeProcess = null;
|
|
628
752
|
this.isStarting = false;
|
|
629
753
|
if (this.currentCommandReject) {
|
|
630
754
|
if (error.message.includes('ENOENT')) {
|
|
@@ -1082,6 +1206,10 @@ class ClaudePersistentExecutor extends events_1.EventEmitter {
|
|
|
1082
1206
|
const parsedMessage = JSON.parse(line);
|
|
1083
1207
|
// Handle native Claude Control response packets (models catalog, etc.).
|
|
1084
1208
|
// These bypass raw stdout logging to prevent any potential account/credential leakage.
|
|
1209
|
+
if (this.sessionSchedules?.accept(parsedMessage))
|
|
1210
|
+
return;
|
|
1211
|
+
if (parsedMessage.type === 'result' && !parsedMessage.parent_tool_use_id)
|
|
1212
|
+
this.sessionSchedules?.foregroundEnded();
|
|
1085
1213
|
if (parsedMessage.type === 'control_response' || parsedMessage.type === 'control_request') {
|
|
1086
1214
|
this.handleControlMessage(parsedMessage);
|
|
1087
1215
|
return;
|
|
@@ -1352,7 +1480,7 @@ class ClaudePersistentExecutor extends events_1.EventEmitter {
|
|
|
1352
1480
|
// which are converted to Feishu Card 2.0 elements by the router.
|
|
1353
1481
|
// Emit hook for tool execution completion (this is the ACTUAL execution result)
|
|
1354
1482
|
// Note: We don't have the original tool name here, but we have the tool_use_id
|
|
1355
|
-
if (this.lifecycleHooks)
|
|
1483
|
+
if (this.lifecycleHooks && !this.currentScheduleManagement)
|
|
1356
1484
|
ClaudeCodeHooks_1.claudeCodeHooks.notifyToolExecuted({
|
|
1357
1485
|
toolName: toolUseId || 'unknown', // Use tool_use_id as identifier
|
|
1358
1486
|
params: {}, // Original params not available in tool_result
|
|
@@ -1450,7 +1578,7 @@ class ClaudePersistentExecutor extends events_1.EventEmitter {
|
|
|
1450
1578
|
console.log('[ClaudePersistent] Requesting interactive input:', prompt);
|
|
1451
1579
|
this.isWaitingForInput = true;
|
|
1452
1580
|
// Emit hook to notify user (fire and forget)
|
|
1453
|
-
if (this.lifecycleHooks)
|
|
1581
|
+
if (this.lifecycleHooks && !this.currentScheduleManagement)
|
|
1454
1582
|
ClaudeCodeHooks_1.claudeCodeHooks.requestUserInput({
|
|
1455
1583
|
prompt,
|
|
1456
1584
|
type: 'text',
|
|
@@ -1500,6 +1628,8 @@ class ClaudePersistentExecutor extends events_1.EventEmitter {
|
|
|
1500
1628
|
content: input,
|
|
1501
1629
|
},
|
|
1502
1630
|
};
|
|
1631
|
+
inputMessage.uuid = (0, crypto_1.randomUUID)();
|
|
1632
|
+
this.sessionSchedules?.foregroundDispatched(inputMessage.uuid);
|
|
1503
1633
|
const inputLine = JSON.stringify(inputMessage);
|
|
1504
1634
|
console.log(`[ClaudePersistent] Sending user input: ${input}`);
|
|
1505
1635
|
this.claudeProcess.stdin?.write(inputLine + '\n');
|
|
@@ -1533,7 +1663,7 @@ class ClaudePersistentExecutor extends events_1.EventEmitter {
|
|
|
1533
1663
|
const output = this.currentOutputBuffer.join('');
|
|
1534
1664
|
console.log(`[ClaudePersistent] Completing command, success=${success}, output length=${output.length}, output preview: ${output.substring(0, 100)}...`);
|
|
1535
1665
|
// Emit task completion hooks
|
|
1536
|
-
if (this.lifecycleHooks && this.currentTaskId) {
|
|
1666
|
+
if (this.lifecycleHooks && !this.currentScheduleManagement && this.currentTaskId) {
|
|
1537
1667
|
const endTime = Date.now();
|
|
1538
1668
|
const duration = endTime - this.currentTaskStartTime;
|
|
1539
1669
|
if (success) {
|
|
@@ -1581,6 +1711,7 @@ class ClaudePersistentExecutor extends events_1.EventEmitter {
|
|
|
1581
1711
|
* Reset current command state
|
|
1582
1712
|
*/
|
|
1583
1713
|
resetCurrentCommand() {
|
|
1714
|
+
this.currentScheduleManagement = false;
|
|
1584
1715
|
this.clearApprovals('Task is no longer active');
|
|
1585
1716
|
this.currentOutputBuffer = [];
|
|
1586
1717
|
this.currentObjectiveDispatched = false;
|
|
@@ -1612,7 +1743,7 @@ class ClaudePersistentExecutor extends events_1.EventEmitter {
|
|
|
1612
1743
|
* Process the command queue
|
|
1613
1744
|
*/
|
|
1614
1745
|
async processQueue() {
|
|
1615
|
-
if (this.isProcessing || this.isStarting || this.commandQueue.length === 0) {
|
|
1746
|
+
if (this.isProcessing || this.isStarting || this.sessionSchedules?.busy || this.commandQueue.length === 0) {
|
|
1616
1747
|
return;
|
|
1617
1748
|
}
|
|
1618
1749
|
// Ensure process is running
|
|
@@ -1639,11 +1770,38 @@ class ClaudePersistentExecutor extends events_1.EventEmitter {
|
|
|
1639
1770
|
}
|
|
1640
1771
|
return;
|
|
1641
1772
|
}
|
|
1773
|
+
if (this.delegation?.groups?.includes('scheduling') && !this.scheduleHooksReady && !this.delegationWorker && !this.sandbox.isRestricted()) {
|
|
1774
|
+
// Initialize callback hooks once per native process before its first model turn.
|
|
1775
|
+
this.isStarting = true;
|
|
1776
|
+
try {
|
|
1777
|
+
await this.listModels();
|
|
1778
|
+
}
|
|
1779
|
+
catch {
|
|
1780
|
+
const failed = this.commandQueue.shift();
|
|
1781
|
+
// A resumed native scheduler can fire before a later command. If hook
|
|
1782
|
+
// registration or policy validation failed, retire that process before
|
|
1783
|
+
// returning an error so no restored job can run without ownership.
|
|
1784
|
+
await this.stopProcess().catch(() => { });
|
|
1785
|
+
failed?.resolve({ success: false, error: 'Native managed-tool initialization failed.' });
|
|
1786
|
+
return;
|
|
1787
|
+
}
|
|
1788
|
+
finally {
|
|
1789
|
+
this.isStarting = false;
|
|
1790
|
+
}
|
|
1791
|
+
}
|
|
1792
|
+
if (this.sessionSchedules?.busy)
|
|
1793
|
+
return;
|
|
1642
1794
|
const command = this.commandQueue.shift();
|
|
1643
1795
|
if (!command) {
|
|
1644
1796
|
return;
|
|
1645
1797
|
}
|
|
1798
|
+
if (command.options.nativeScheduleCurrent && !command.options.nativeScheduleCurrent()) {
|
|
1799
|
+
command.resolve({ success: false, error: 'Native schedule management authorization expired before dispatch.' });
|
|
1800
|
+
void this.processQueue();
|
|
1801
|
+
return;
|
|
1802
|
+
}
|
|
1646
1803
|
this.isProcessing = true;
|
|
1804
|
+
this.currentScheduleManagement = command.options.nativeScheduleManagement === true;
|
|
1647
1805
|
this.currentStreamCallback = command.options.onStream;
|
|
1648
1806
|
this.currentAssistantTextSeen = false;
|
|
1649
1807
|
this.currentDisplayTextCallback = text => {
|
|
@@ -1678,7 +1836,7 @@ class ClaudePersistentExecutor extends events_1.EventEmitter {
|
|
|
1678
1836
|
this.currentTaskId = `task_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`;
|
|
1679
1837
|
this.currentTaskStartTime = Date.now();
|
|
1680
1838
|
// Emit task started hook
|
|
1681
|
-
if (this.lifecycleHooks)
|
|
1839
|
+
if (this.lifecycleHooks && !this.currentScheduleManagement)
|
|
1682
1840
|
ClaudeCodeHooks_1.claudeCodeHooks.notifyTaskStarted({
|
|
1683
1841
|
taskId: this.currentTaskId,
|
|
1684
1842
|
description: command.prompt,
|
|
@@ -1731,6 +1889,8 @@ class ClaudePersistentExecutor extends events_1.EventEmitter {
|
|
|
1731
1889
|
},
|
|
1732
1890
|
...(command.isSlashCommand ? { isSlashCommand: true } : {}),
|
|
1733
1891
|
};
|
|
1892
|
+
inputMessage.uuid = (0, crypto_1.randomUUID)();
|
|
1893
|
+
this.sessionSchedules?.foregroundDispatched(inputMessage.uuid, command.options.nativeScheduleManagement);
|
|
1734
1894
|
const inputLine = JSON.stringify(inputMessage);
|
|
1735
1895
|
console.log(`[ClaudePersistent] Sending command${command.isSlashCommand ? ' (slash)' : ''}: ${command.prompt.substring(0, 100)}...`);
|
|
1736
1896
|
this.currentObjectiveDispatched = true;
|
|
@@ -1785,7 +1945,7 @@ class ClaudePersistentExecutor extends events_1.EventEmitter {
|
|
|
1785
1945
|
console.log('[ClaudePersistent] Aborting current command...');
|
|
1786
1946
|
this.denyAllPendingApprovals('Task aborted by user');
|
|
1787
1947
|
// Emit task aborted hook before stopping
|
|
1788
|
-
if (this.lifecycleHooks && this.currentTaskId) {
|
|
1948
|
+
if (this.lifecycleHooks && !this.currentScheduleManagement && this.currentTaskId) {
|
|
1789
1949
|
ClaudeCodeHooks_1.claudeCodeHooks.notifyTaskAborted({
|
|
1790
1950
|
taskId: this.currentTaskId,
|
|
1791
1951
|
description: '',
|
|
@@ -1917,6 +2077,12 @@ class ClaudePersistentExecutor extends events_1.EventEmitter {
|
|
|
1917
2077
|
if (!child || !child.stdin || child.killed) {
|
|
1918
2078
|
throw new Error('Claude process is not available for control initialization');
|
|
1919
2079
|
}
|
|
2080
|
+
// Install the lifecycle guard even in restricted mode so a native schedule
|
|
2081
|
+
// restored from an earlier unrestricted session cannot run unowned after the
|
|
2082
|
+
// execution policy changes. Creation and management remain rejected below.
|
|
2083
|
+
const scheduleHooks = !this.delegationWorker;
|
|
2084
|
+
if (scheduleHooks)
|
|
2085
|
+
this.schedules();
|
|
1920
2086
|
const stdin = child.stdin;
|
|
1921
2087
|
const requestId = `catalog-${(0, crypto_1.randomUUID)()}`;
|
|
1922
2088
|
const requestPacket = {
|
|
@@ -1924,6 +2090,7 @@ class ClaudePersistentExecutor extends events_1.EventEmitter {
|
|
|
1924
2090
|
request_id: requestId,
|
|
1925
2091
|
request: {
|
|
1926
2092
|
subtype: 'initialize',
|
|
2093
|
+
...(scheduleHooks ? { hooks: ClaudeSessionSchedules_1.SCHEDULE_HOOKS } : {}),
|
|
1927
2094
|
},
|
|
1928
2095
|
};
|
|
1929
2096
|
return new Promise((resolve, reject) => {
|
|
@@ -1938,7 +2105,7 @@ class ClaudePersistentExecutor extends events_1.EventEmitter {
|
|
|
1938
2105
|
reject(new Error('Claude control initialization timed out after 10000ms'));
|
|
1939
2106
|
}, 10_000);
|
|
1940
2107
|
this.pendingControlRequests.set(requestId, {
|
|
1941
|
-
resolve: (response) => {
|
|
2108
|
+
resolve: async (response) => {
|
|
1942
2109
|
cleanup();
|
|
1943
2110
|
if (this.claudeProcess !== child || this.isDestroyed || this.isStopping) {
|
|
1944
2111
|
reject(new Error('Claude catalog process is no longer active'));
|
|
@@ -1947,6 +2114,13 @@ class ClaudePersistentExecutor extends events_1.EventEmitter {
|
|
|
1947
2114
|
try {
|
|
1948
2115
|
const rawResponse = response || {};
|
|
1949
2116
|
const { models, rawEntries } = (0, ClaudeSettings_1.parseClaudeModelsCatalog)(rawResponse.models, this.reportedModel || this.model);
|
|
2117
|
+
if (scheduleHooks && this.sessionId && this.delegation?.groups?.includes('scheduling')) {
|
|
2118
|
+
await this.readNativeScheduleTimezone();
|
|
2119
|
+
}
|
|
2120
|
+
if (scheduleHooks) {
|
|
2121
|
+
this.schedules();
|
|
2122
|
+
this.scheduleHooksReady = true;
|
|
2123
|
+
}
|
|
1950
2124
|
this.cachedRawEntries = rawEntries;
|
|
1951
2125
|
this.cachedModelCatalog = models;
|
|
1952
2126
|
resolve(models);
|
|
@@ -2121,7 +2295,7 @@ class ClaudePersistentExecutor extends events_1.EventEmitter {
|
|
|
2121
2295
|
await this.stopProcess();
|
|
2122
2296
|
// Step 2: Run compact as a one-shot process outside the full context
|
|
2123
2297
|
const compactResult = await new Promise((resolve) => {
|
|
2124
|
-
const child = (0, OwnershipRuntime_1.ownedSpawn)(this.claudeCommand, ['--resume', sessionIdBeforeCompact, '--print', '/compact'], {
|
|
2298
|
+
const child = (0, OwnershipRuntime_1.ownedSpawn)(this.claudeCommand, ['--resume', sessionIdBeforeCompact, '--settings', JSON.stringify({ scheduledTasksEnabled: false }), '--print', '/compact'], {
|
|
2125
2299
|
cwd: this.currentWorkingDirectory,
|
|
2126
2300
|
stdio: ['ignore', 'pipe', 'pipe'],
|
|
2127
2301
|
env: { ...process.env, FORCE_COLOR: '0', CLAUDECODE: '', CLAUDE_CODE: '' },
|