@magclaw/cli-core 0.1.27 → 0.1.28
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 +30 -6
package/package.json
CHANGED
package/src/cli.js
CHANGED
|
@@ -12,7 +12,7 @@ import { renderListProfiles, shouldUseColor } from './list-renderer.js';
|
|
|
12
12
|
export const DEFAULT_PROFILE = 'default';
|
|
13
13
|
export const DEFAULT_SERVER_URL = 'http://127.0.0.1:6543';
|
|
14
14
|
const DEFAULT_DAEMON_HEARTBEAT_MS = 25_000;
|
|
15
|
-
const DEFAULT_DAEMON_INBOUND_WATCHDOG_MS =
|
|
15
|
+
const DEFAULT_DAEMON_INBOUND_WATCHDOG_MS = 15_000;
|
|
16
16
|
const DEFAULT_DAEMON_RECONNECT_MIN_MS = 1_000;
|
|
17
17
|
const DEFAULT_DAEMON_RECONNECT_MAX_MS = 30_000;
|
|
18
18
|
const DEFAULT_MAX_CONCURRENT_AGENT_STARTS = 5;
|
|
@@ -3613,7 +3613,7 @@ class MagClawDaemon {
|
|
|
3613
3613
|
} else {
|
|
3614
3614
|
logInfo('daemon', 'Foreground close request did not stop background service.');
|
|
3615
3615
|
}
|
|
3616
|
-
this.close();
|
|
3616
|
+
this.close({ notify: false, reason: 'cloud_close' });
|
|
3617
3617
|
process.exitCode = 0;
|
|
3618
3618
|
setTimeout(() => process.exit(0), 50).unref?.();
|
|
3619
3619
|
}
|
|
@@ -3856,7 +3856,7 @@ class MagClawDaemon {
|
|
|
3856
3856
|
break;
|
|
3857
3857
|
case 'token:revoked':
|
|
3858
3858
|
logError('daemon', 'Machine token was revoked by the server.');
|
|
3859
|
-
this.close();
|
|
3859
|
+
this.close({ notify: false, reason: 'token_revoked' });
|
|
3860
3860
|
process.exitCode = 2;
|
|
3861
3861
|
break;
|
|
3862
3862
|
default:
|
|
@@ -4134,8 +4134,29 @@ class MagClawDaemon {
|
|
|
4134
4134
|
});
|
|
4135
4135
|
}
|
|
4136
4136
|
|
|
4137
|
-
|
|
4137
|
+
sendStoppingNotice(reason = 'local_stop') {
|
|
4138
|
+
const packageInfo = runtimePackageInfo(this.env);
|
|
4139
|
+
const sent = this.send({
|
|
4140
|
+
type: 'daemon:stopping',
|
|
4141
|
+
time: now(),
|
|
4142
|
+
reason,
|
|
4143
|
+
computerId: this.config.computerId || null,
|
|
4144
|
+
daemonVersion: packageInfo.version || DAEMON_VERSION,
|
|
4145
|
+
packageName: packageInfo.name,
|
|
4146
|
+
packageVersion: packageInfo.version,
|
|
4147
|
+
packageKind: packageInfo.kind,
|
|
4148
|
+
packageSpec: packageInfo.spec,
|
|
4149
|
+
packageBin: packageInfo.bin,
|
|
4150
|
+
runningAgents: [...this.sessions.keys()],
|
|
4151
|
+
});
|
|
4152
|
+
if (sent) logInfo('daemon', `Sent stopping notice (${reason}).`);
|
|
4153
|
+
return sent;
|
|
4154
|
+
}
|
|
4155
|
+
|
|
4156
|
+
close(options = {}) {
|
|
4138
4157
|
if (this.closed) return;
|
|
4158
|
+
const notify = options.notify !== false;
|
|
4159
|
+
if (notify) this.sendStoppingNotice(options.reason || 'local_stop');
|
|
4139
4160
|
this.closed = true;
|
|
4140
4161
|
for (const session of this.sessions.values()) session.stop();
|
|
4141
4162
|
this.sessions.clear();
|
|
@@ -4155,7 +4176,10 @@ class MagClawDaemon {
|
|
|
4155
4176
|
this.request.destroy(new Error('MagClaw daemon is shutting down.'));
|
|
4156
4177
|
this.request = null;
|
|
4157
4178
|
}
|
|
4158
|
-
if (this.socket && !this.socket.destroyed)
|
|
4179
|
+
if (this.socket && !this.socket.destroyed) {
|
|
4180
|
+
if (notify) this.socket.end();
|
|
4181
|
+
else this.socket.destroy();
|
|
4182
|
+
}
|
|
4159
4183
|
this.socket = null;
|
|
4160
4184
|
}
|
|
4161
4185
|
|
|
@@ -5386,7 +5410,7 @@ async function runForegroundDaemon(config, env = process.env) {
|
|
|
5386
5410
|
let forceExitTimer = null;
|
|
5387
5411
|
const shutdown = (signal) => {
|
|
5388
5412
|
process.exitCode = signal === 'SIGINT' ? 130 : 143;
|
|
5389
|
-
daemon.close();
|
|
5413
|
+
daemon.close({ reason: signal === 'SIGINT' ? 'sigint' : 'sigterm' });
|
|
5390
5414
|
forceExitTimer ||= setTimeout(() => process.exit(process.exitCode || 1), 5000);
|
|
5391
5415
|
forceExitTimer.unref?.();
|
|
5392
5416
|
};
|