@slock-ai/computer 0.0.7 → 0.0.8
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/index.js +61 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1692,6 +1692,49 @@ async function runStart(opts = {}, deps = {}) {
|
|
|
1692
1692
|
info(`Per-server daemon logs: ~/.slock/computer/servers/<serverId>/daemon.log`);
|
|
1693
1693
|
info(`Check state with \`slock-computer status\`.`);
|
|
1694
1694
|
}
|
|
1695
|
+
async function runStop(deps = {}) {
|
|
1696
|
+
const slockHome = resolveSlockHome();
|
|
1697
|
+
const readPidfile = deps.readPidfile ?? readPidfileAt;
|
|
1698
|
+
const isAlive = deps.isProcessAlive ?? isProcessAlive2;
|
|
1699
|
+
const killer = deps.killSupervisor ?? ((pid2) => {
|
|
1700
|
+
process.kill(pid2, "SIGTERM");
|
|
1701
|
+
});
|
|
1702
|
+
const sleep2 = deps.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
|
|
1703
|
+
const pollIntervalMs = deps.pollIntervalMs ?? 200;
|
|
1704
|
+
const timeoutMs = deps.timeoutMs ?? 5e3;
|
|
1705
|
+
const pidfilePath = supervisorPidPath(slockHome);
|
|
1706
|
+
const pid = await readPidfile(pidfilePath);
|
|
1707
|
+
if (pid === null) {
|
|
1708
|
+
info("Supervisor not running.");
|
|
1709
|
+
return;
|
|
1710
|
+
}
|
|
1711
|
+
if (!isAlive(pid)) {
|
|
1712
|
+
await clearPidfileAt(pidfilePath);
|
|
1713
|
+
info(`Supervisor not running (cleared stale pidfile for pid ${pid}).`);
|
|
1714
|
+
return;
|
|
1715
|
+
}
|
|
1716
|
+
try {
|
|
1717
|
+
killer(pid);
|
|
1718
|
+
} catch (err) {
|
|
1719
|
+
fail(
|
|
1720
|
+
"STOP_SIGNAL_FAILED",
|
|
1721
|
+
`Failed to send SIGTERM to supervisor (pid ${pid}): ${err instanceof Error ? err.message : String(err)}. Check process permissions or run: kill ${pid}`
|
|
1722
|
+
);
|
|
1723
|
+
}
|
|
1724
|
+
const deadline = Date.now() + timeoutMs;
|
|
1725
|
+
while (Date.now() < deadline) {
|
|
1726
|
+
if (!isAlive(pid)) {
|
|
1727
|
+
await clearPidfileAt(pidfilePath);
|
|
1728
|
+
info(`Stopped supervisor (pid ${pid}).`);
|
|
1729
|
+
return;
|
|
1730
|
+
}
|
|
1731
|
+
await sleep2(pollIntervalMs);
|
|
1732
|
+
}
|
|
1733
|
+
fail(
|
|
1734
|
+
"STOP_TIMEOUT",
|
|
1735
|
+
`Supervisor (pid ${pid}) did not exit within ${timeoutMs}ms after SIGTERM. Force-kill with: kill -9 ${pid}`
|
|
1736
|
+
);
|
|
1737
|
+
}
|
|
1695
1738
|
async function runDetach(serverId, serverLabel = serverId) {
|
|
1696
1739
|
assertValidServerId(serverId);
|
|
1697
1740
|
const slockHome = resolveSlockHome();
|
|
@@ -3371,6 +3414,9 @@ async function appendUpgradeLogEntry(slockHome, entry) {
|
|
|
3371
3414
|
}
|
|
3372
3415
|
|
|
3373
3416
|
// src/upgradeCli.ts
|
|
3417
|
+
function isEphemeralNpxContext(binaryDir) {
|
|
3418
|
+
return binaryDir.split(/[\\/]/).includes("_npx");
|
|
3419
|
+
}
|
|
3374
3420
|
async function defaultSpawnFreshSupervisor(slockHome) {
|
|
3375
3421
|
await spawnDetachedSupervisor(slockHome);
|
|
3376
3422
|
}
|
|
@@ -3420,6 +3466,18 @@ async function runUpgradeCli(slockHome, opts, deps = {}) {
|
|
|
3420
3466
|
}
|
|
3421
3467
|
const fromVersion = await (deps.currentVersion ?? defaultCurrentVersion)();
|
|
3422
3468
|
const currentBinaryDir = (deps.currentBinaryDir ?? defaultCurrentBinaryDir)();
|
|
3469
|
+
const isEphemeralFn = deps.isEphemeralNpxContext ?? isEphemeralNpxContext;
|
|
3470
|
+
if (isEphemeralFn(currentBinaryDir)) {
|
|
3471
|
+
fail(
|
|
3472
|
+
"UPGRADE_EPHEMERAL_CONTEXT",
|
|
3473
|
+
`Cannot upgrade from an ephemeral npx context (${currentBinaryDir}).
|
|
3474
|
+
The currently installed Computer service runs from a different install root, which this command cannot reach. To upgrade, manually replace the persistent install:
|
|
3475
|
+
npx -y @slock-ai/computer@latest stop
|
|
3476
|
+
rm -rf ~/.npm/_npx/<persistent-hash>/
|
|
3477
|
+
npx -y @slock-ai/computer@latest start
|
|
3478
|
+
(Find the persistent hash via: ls -d ~/.npm/_npx/*/node_modules/@slock-ai/computer)`
|
|
3479
|
+
);
|
|
3480
|
+
}
|
|
3423
3481
|
if (targetVersion === fromVersion) {
|
|
3424
3482
|
info(`Already at ${fromVersion} (channel ${channel2}). Nothing to do.`);
|
|
3425
3483
|
return;
|
|
@@ -3961,6 +4019,9 @@ program.command("start").argument("[serverSlug]", "optional: verify this server
|
|
|
3961
4019
|
})
|
|
3962
4020
|
);
|
|
3963
4021
|
}));
|
|
4022
|
+
program.command("stop").description("Stop the Computer supervisor (and all managed per-server daemons).").action(withCliExit(async () => {
|
|
4023
|
+
await withMutationLock(() => runStop());
|
|
4024
|
+
}));
|
|
3964
4025
|
program.command("doctor").argument("[serverSlug]", "optional: scope detail (recent crashes) to one server").description("Diagnose login + per-server attachments + per-server preflight (no secrets).").option("--json", "emit the machine-readable report").option("--cleanup", "after diagnosis, run the local residue cleanup pass").option("--fix", "alias for --cleanup (same behavior)").option("--reset-health", "clear <serverSlug>'s crash history so supervisor resumes auto-restart").action(
|
|
3965
4026
|
withCliExit(
|
|
3966
4027
|
async (serverSlug, opts) => {
|
package/package.json
CHANGED