@commonlyai/cli 0.1.407 → 0.1.408
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/commands/daemon.js +49 -20
package/package.json
CHANGED
package/src/commands/daemon.js
CHANGED
|
@@ -280,11 +280,23 @@ export const getDaemonMachineStatus = async ({ client, record }) => {
|
|
|
280
280
|
return machine;
|
|
281
281
|
};
|
|
282
282
|
|
|
283
|
-
|
|
283
|
+
// Keys on body.message, never error.message: a server that explains a revoke
|
|
284
|
+
// (F641) puts its text in body.error, which api.js prefers for error.message.
|
|
285
|
+
export const isRevokedDaemonKey = (error) => error?.status === 401 && [
|
|
284
286
|
'Daemon token revoked or unknown',
|
|
285
287
|
'Machine access revoked',
|
|
286
288
|
].includes(error?.body?.message);
|
|
287
289
|
|
|
290
|
+
// F641: what the server says the person should do about a revoked key, as one
|
|
291
|
+
// printable line, or '' when it says nothing. Control characters are dropped
|
|
292
|
+
// so a response can never drive the terminal.
|
|
293
|
+
const REVOKED_REASON_MAX = 500;
|
|
294
|
+
export const revokedDaemonReasonText = (error) => {
|
|
295
|
+
if (!isRevokedDaemonKey(error) || typeof error?.body?.error !== 'string') return '';
|
|
296
|
+
// eslint-disable-next-line no-control-regex
|
|
297
|
+
return error.body.error.replace(/[\u0000-\u001f\u007f-\u009f]/g, '').trim().slice(0, REVOKED_REASON_MAX);
|
|
298
|
+
};
|
|
299
|
+
|
|
288
300
|
const isMissingDaemonMachine = (error) => error?.status === 404
|
|
289
301
|
&& error?.body?.message === 'Machine not found';
|
|
290
302
|
|
|
@@ -299,8 +311,30 @@ const storedDaemonState = async (client, record) => {
|
|
|
299
311
|
}
|
|
300
312
|
};
|
|
301
313
|
|
|
314
|
+
// The daemon's stop when the server refuses its key for good: save the stop
|
|
315
|
+
// marker, say why, end supervision and exit 77. A server reason (F641) prints
|
|
316
|
+
// first; the stop line stays as it was, for anyone reading logs for it.
|
|
317
|
+
export const createTerminalAuthStop = ({
|
|
318
|
+
record, stampLog, stopSupervision, saveStop = saveDaemonStop, platform = process.platform,
|
|
319
|
+
}) => (error) => {
|
|
320
|
+
let saved = false;
|
|
321
|
+
try {
|
|
322
|
+
saveStop(record, 77);
|
|
323
|
+
saved = true;
|
|
324
|
+
} catch (saveError) {
|
|
325
|
+
stampLog(`could not save revoked-machine stop marker: ${saveError.message}`);
|
|
326
|
+
}
|
|
327
|
+
const reason = revokedDaemonReasonText(error);
|
|
328
|
+
if (reason) stampLog(reason);
|
|
329
|
+
stampLog(`machine key revoked; stopping supervised agents. Run: ${CLI} daemon register`);
|
|
330
|
+
stopSupervision();
|
|
331
|
+
// Without the marker launchd would restart forever. A successful
|
|
332
|
+
// exit parks it on macOS; systemd honors 77 directly.
|
|
333
|
+
process.exitCode = saved || platform !== 'darwin' ? 77 : 0;
|
|
334
|
+
};
|
|
335
|
+
|
|
302
336
|
export const daemonStatusErrorMessage = (error) => (isRevokedDaemonKey(error)
|
|
303
|
-
? `This computer's old key was revoked. Run: ${CLI} daemon register`
|
|
337
|
+
? [revokedDaemonReasonText(error), `This computer's old key was revoked. Run: ${CLI} daemon register`].filter(Boolean).join('\n')
|
|
304
338
|
: isMissingDaemonMachine(error)
|
|
305
339
|
? `This computer is no longer registered. Run: ${CLI} daemon register`
|
|
306
340
|
: `Daemon status failed: ${error.message}`);
|
|
@@ -790,24 +824,19 @@ Examples:
|
|
|
790
824
|
let terminalEnded = false;
|
|
791
825
|
const terminalAuth = (error) => isRevokedDaemonKey(error)
|
|
792
826
|
|| isMissingDaemonMachine(error);
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
releaseLock();
|
|
807
|
-
// Without the marker launchd would restart forever. A successful
|
|
808
|
-
// exit parks it on macOS; systemd honors 77 directly.
|
|
809
|
-
process.exitCode = saved || process.platform !== 'darwin' ? 77 : 0;
|
|
810
|
-
};
|
|
827
|
+
// F637's order holds: marker, log lines, then timers, supervisor and the
|
|
828
|
+
// one-daemon lock, then the exit code (createTerminalAuthStop).
|
|
829
|
+
const onTerminalAuthError = createTerminalAuthStop({
|
|
830
|
+
record,
|
|
831
|
+
stampLog,
|
|
832
|
+
stopSupervision: () => {
|
|
833
|
+
terminalEnded = true;
|
|
834
|
+
clearInterval(pollTimer);
|
|
835
|
+
clearInterval(heartbeatTimer);
|
|
836
|
+
supervisor.stop();
|
|
837
|
+
releaseLock();
|
|
838
|
+
},
|
|
839
|
+
});
|
|
811
840
|
const runtimeInventory = createInventoryCache((harnesses) => collectRuntimeInventory(getAdapter, undefined, harnesses, { loginState }));
|
|
812
841
|
supervisor = createDaemonSupervisor({
|
|
813
842
|
record,
|