@magclaw/cli-core 0.1.25 → 0.1.26
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/package.json +1 -1
- package/src/cli.js +36 -17
package/package.json
CHANGED
package/src/cli.js
CHANGED
|
@@ -3520,14 +3520,15 @@ class MagClawDaemon {
|
|
|
3520
3520
|
const commandId = String(message.commandId || '').trim();
|
|
3521
3521
|
const service = await readServiceState(this.paths.profile, this.env);
|
|
3522
3522
|
const serviceStatus = backgroundServiceStatus(this.paths.profile, this.env);
|
|
3523
|
+
const serviceRunMode = daemonServiceRunMode(service, serviceStatus);
|
|
3523
3524
|
const packageInfo = runtimePackageInfo(this.env, service);
|
|
3524
3525
|
const runMode = {
|
|
3525
|
-
mode:
|
|
3526
|
-
background:
|
|
3527
|
-
active:
|
|
3528
|
-
label: serviceStatus.label || '',
|
|
3529
|
-
serviceName: serviceStatus.serviceName || '',
|
|
3530
|
-
taskName: serviceStatus.taskName || '',
|
|
3526
|
+
mode: serviceRunMode.mode,
|
|
3527
|
+
background: serviceRunMode.background,
|
|
3528
|
+
active: serviceRunMode.active,
|
|
3529
|
+
label: serviceRunMode.background ? serviceStatus.label || '' : '',
|
|
3530
|
+
serviceName: serviceRunMode.background ? serviceStatus.serviceName || '' : '',
|
|
3531
|
+
taskName: serviceRunMode.background ? serviceStatus.taskName || '' : '',
|
|
3531
3532
|
packageName: packageInfo.name,
|
|
3532
3533
|
packageVersion: packageInfo.version,
|
|
3533
3534
|
packageKind: packageInfo.kind,
|
|
@@ -3550,8 +3551,15 @@ class MagClawDaemon {
|
|
|
3550
3551
|
service: runMode,
|
|
3551
3552
|
at: now(),
|
|
3552
3553
|
});
|
|
3553
|
-
const
|
|
3554
|
-
|
|
3554
|
+
const shouldStopBackground = Boolean(runMode.background);
|
|
3555
|
+
const background = shouldStopBackground
|
|
3556
|
+
? stopBackground(this.paths.profile, this.env, { disable: message.disableBackground !== false })
|
|
3557
|
+
: { ok: true, mode: runMode.mode || 'foreground', skipped: true };
|
|
3558
|
+
if (shouldStopBackground) {
|
|
3559
|
+
logInfo('daemon', `Close request stopped background service mode=${background.mode || 'foreground'} ok=${Boolean(background.ok)}.`);
|
|
3560
|
+
} else {
|
|
3561
|
+
logInfo('daemon', 'Foreground close request did not stop background service.');
|
|
3562
|
+
}
|
|
3555
3563
|
this.close();
|
|
3556
3564
|
process.exitCode = 0;
|
|
3557
3565
|
setTimeout(() => process.exit(0), 50).unref?.();
|
|
@@ -3562,6 +3570,7 @@ class MagClawDaemon {
|
|
|
3562
3570
|
const owner = await ensureMachineFingerprint(this.paths.profile, this.env);
|
|
3563
3571
|
const service = await readServiceState(this.paths.profile, this.env);
|
|
3564
3572
|
const serviceStatus = backgroundServiceStatus(this.paths.profile, this.env);
|
|
3573
|
+
const serviceRunMode = daemonServiceRunMode(service, serviceStatus);
|
|
3565
3574
|
const upgrade = await readUpgradeHandoff(this.paths.profile, this.env);
|
|
3566
3575
|
const packageInfo = runtimePackageInfo(this.env, service);
|
|
3567
3576
|
return {
|
|
@@ -3581,12 +3590,12 @@ class MagClawDaemon {
|
|
|
3581
3590
|
packageBin: packageInfo.bin,
|
|
3582
3591
|
cliCoreVersion: CLI_CORE_VERSION,
|
|
3583
3592
|
service: {
|
|
3584
|
-
mode:
|
|
3585
|
-
background:
|
|
3586
|
-
active:
|
|
3587
|
-
label: serviceStatus.label || '',
|
|
3588
|
-
serviceName: serviceStatus.serviceName || '',
|
|
3589
|
-
taskName: serviceStatus.taskName || '',
|
|
3593
|
+
mode: serviceRunMode.mode,
|
|
3594
|
+
background: serviceRunMode.background,
|
|
3595
|
+
active: serviceRunMode.active,
|
|
3596
|
+
label: serviceRunMode.background ? serviceStatus.label || '' : '',
|
|
3597
|
+
serviceName: serviceRunMode.background ? serviceStatus.serviceName || '' : '',
|
|
3598
|
+
taskName: serviceRunMode.background ? serviceStatus.taskName || '' : '',
|
|
3590
3599
|
launcher: service.launcher || '',
|
|
3591
3600
|
packageSpec: service.packageSpec || packageInfo.spec || '',
|
|
3592
3601
|
packageName: service.packageName || packageInfo.name,
|
|
@@ -4102,6 +4111,7 @@ class MagClawDaemon {
|
|
|
4102
4111
|
await this.refreshConfigFromDisk();
|
|
4103
4112
|
const service = await readServiceState(this.paths.profile, this.env);
|
|
4104
4113
|
const serviceStatus = backgroundServiceStatus(this.paths.profile, this.env);
|
|
4114
|
+
const serviceRunMode = daemonServiceRunMode(service, serviceStatus);
|
|
4105
4115
|
const packageInfo = runtimePackageInfo(this.env, service);
|
|
4106
4116
|
const url = toWebSocketUrl(this.config.serverUrl, {
|
|
4107
4117
|
...this.config,
|
|
@@ -4111,9 +4121,9 @@ class MagClawDaemon {
|
|
|
4111
4121
|
packageSpec: packageInfo.spec,
|
|
4112
4122
|
packageBin: packageInfo.bin,
|
|
4113
4123
|
cliCoreVersion: CLI_CORE_VERSION,
|
|
4114
|
-
serviceMode:
|
|
4115
|
-
serviceBackground:
|
|
4116
|
-
serviceActive:
|
|
4124
|
+
serviceMode: serviceRunMode.mode,
|
|
4125
|
+
serviceBackground: serviceRunMode.background,
|
|
4126
|
+
serviceActive: serviceRunMode.active,
|
|
4117
4127
|
});
|
|
4118
4128
|
const requestModule = url.protocol === 'wss:' ? https : http;
|
|
4119
4129
|
const requestUrl = new URL(url.href.replace(/^ws/, 'http'));
|
|
@@ -4536,6 +4546,15 @@ function backgroundServiceStatus(profile, env = process.env) {
|
|
|
4536
4546
|
return { mode: 'foreground', active: false };
|
|
4537
4547
|
}
|
|
4538
4548
|
|
|
4549
|
+
function daemonServiceRunMode(service = {}, serviceStatus = {}) {
|
|
4550
|
+
const background = service.background === true;
|
|
4551
|
+
return {
|
|
4552
|
+
mode: background ? (service.mode || serviceStatus.mode || 'foreground') : 'foreground',
|
|
4553
|
+
background,
|
|
4554
|
+
active: background ? Boolean(serviceStatus.active) : false,
|
|
4555
|
+
};
|
|
4556
|
+
}
|
|
4557
|
+
|
|
4539
4558
|
function launchctlResultIsNotLoaded(result) {
|
|
4540
4559
|
const detail = String(result?.stderr || result?.stdout || '').toLowerCase();
|
|
4541
4560
|
return detail.includes('no such process') || detail.includes('could not find service') || detail.includes('not found');
|