@slock-ai/computer 0.0.1 → 0.0.3
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 +20 -17
- package/package.json +13 -13
package/dist/index.js
CHANGED
|
@@ -306,13 +306,22 @@ function fail(code, message, exitCode = 1) {
|
|
|
306
306
|
throw new CliExit(exitCode);
|
|
307
307
|
}
|
|
308
308
|
|
|
309
|
+
// src/serverUrl.ts
|
|
310
|
+
var DEFAULT_SLOCK_SERVER_URL = "https://api.slock.ai";
|
|
311
|
+
function resolveServerUrl(...candidates) {
|
|
312
|
+
for (const candidate of candidates) {
|
|
313
|
+
const value = candidate?.trim();
|
|
314
|
+
if (value) return value;
|
|
315
|
+
}
|
|
316
|
+
return DEFAULT_SLOCK_SERVER_URL;
|
|
317
|
+
}
|
|
318
|
+
|
|
309
319
|
// src/login.ts
|
|
310
320
|
function sleep(ms) {
|
|
311
321
|
return new Promise((r) => setTimeout(r, ms));
|
|
312
322
|
}
|
|
313
323
|
async function runLogin(opts) {
|
|
314
|
-
const baseUrl = (opts.serverUrl
|
|
315
|
-
if (!baseUrl) fail("MISSING_SERVER_URL", "Set SLOCK_SERVER_URL or pass --server-url <url>.");
|
|
324
|
+
const baseUrl = resolveServerUrl(opts.serverUrl, process.env.SLOCK_SERVER_URL);
|
|
316
325
|
const client = new DeviceAuthClient(baseUrl);
|
|
317
326
|
let grant;
|
|
318
327
|
try {
|
|
@@ -482,10 +491,7 @@ async function runAttach(opts) {
|
|
|
482
491
|
`User session at ${sessionFile} is invalid. Re-run \`slock-computer login\`.`
|
|
483
492
|
);
|
|
484
493
|
}
|
|
485
|
-
const baseUrl = (opts.serverUrl
|
|
486
|
-
if (!baseUrl) {
|
|
487
|
-
fail("MISSING_SERVER_URL", "Set SLOCK_SERVER_URL or pass --server-url <url>.");
|
|
488
|
-
}
|
|
494
|
+
const baseUrl = resolveServerUrl(opts.serverUrl, session.serverUrl, process.env.SLOCK_SERVER_URL);
|
|
489
495
|
const client = new ComputerAttachClient(baseUrl, session.accessToken);
|
|
490
496
|
const slugForServer = normalizeServerSlug(opts.serverSlug);
|
|
491
497
|
if (!slugForServer) {
|
|
@@ -700,10 +706,7 @@ async function runAdoptLegacy(inputs) {
|
|
|
700
706
|
`User session at ${sessionFile} is invalid. Re-run \`slock-computer login\`.`
|
|
701
707
|
);
|
|
702
708
|
}
|
|
703
|
-
const baseUrl = (inputs.serverUrl
|
|
704
|
-
if (!baseUrl) {
|
|
705
|
-
fail("MISSING_SERVER_URL", "Set SLOCK_SERVER_URL or pass --server-url <url>.");
|
|
706
|
-
}
|
|
709
|
+
const baseUrl = resolveServerUrl(inputs.serverUrl, session.serverUrl, process.env.SLOCK_SERVER_URL);
|
|
707
710
|
const slugForServer = normalizeServerSlug(inputs.serverSlug);
|
|
708
711
|
if (!slugForServer) {
|
|
709
712
|
fail("ADOPT_NOT_AUTHORIZED", "Server slug must not be empty.");
|
|
@@ -1663,7 +1666,7 @@ async function runSetup(opts, deps = {}) {
|
|
|
1663
1666
|
if (!opts.adoptLegacy && liveLegacy) {
|
|
1664
1667
|
fail(
|
|
1665
1668
|
"LEGACY_DAEMON_RUNNING",
|
|
1666
|
-
|
|
1669
|
+
`A legacy daemon appears to be running in ${slockHome}, so Computer setup stopped before creating a second attachment. To proceed: try the Computer beta in an isolated home with \`SLOCK_HOME=$HOME/.slock-computer-beta slock-computer setup ${label}\`; or stop the legacy daemon with \`pkill -f slock-daemon && rm -f ~/.slock/daemon.pid\`; or migrate the existing daemon with \`--adopt-legacy --legacy-api-key <key>\`.`
|
|
1667
1670
|
);
|
|
1668
1671
|
}
|
|
1669
1672
|
if (opts.adoptLegacy && hasLegacyKey) {
|
|
@@ -1678,7 +1681,7 @@ async function runSetup(opts, deps = {}) {
|
|
|
1678
1681
|
} else if (opts.adoptLegacy && liveLegacy) {
|
|
1679
1682
|
fail(
|
|
1680
1683
|
"LEGACY_DAEMON_RUNNING",
|
|
1681
|
-
|
|
1684
|
+
`A legacy daemon is running in ${slockHome}, but no legacy key was provided. To proceed: provide --legacy-api-key-file/--legacy-api-key/--legacy-api-key-stdin to adopt it; or stop the legacy daemon with \`pkill -f slock-daemon && rm -f ~/.slock/daemon.pid\`; or use an isolated home with \`SLOCK_HOME=$HOME/.slock-computer-beta slock-computer setup ${label}\` for a clean beta trial.`
|
|
1682
1685
|
);
|
|
1683
1686
|
} else {
|
|
1684
1687
|
if (opts.adoptLegacy) {
|
|
@@ -3634,16 +3637,16 @@ function withCliExit(fn) {
|
|
|
3634
3637
|
};
|
|
3635
3638
|
}
|
|
3636
3639
|
var program = new Command();
|
|
3637
|
-
program.name("slock-computer").description("Slock Computer \u2014 local-machine control plane (login + N per-server attachments).").version("0.0.
|
|
3638
|
-
program.command("login").description("Log in via device-code (one user identity per Computer / SLOCK_HOME).").option("--server-url <url>",
|
|
3640
|
+
program.name("slock-computer").description("Slock Computer \u2014 local-machine control plane (login + N per-server attachments).").version("0.0.3");
|
|
3641
|
+
program.command("login").description("Log in via device-code (one user identity per Computer / SLOCK_HOME).").option("--server-url <url>", `Slock API base URL; defaults to SLOCK_SERVER_URL or ${DEFAULT_SLOCK_SERVER_URL}`).action(withCliExit(async (opts) => {
|
|
3639
3642
|
await runLogin({ serverUrl: opts.serverUrl });
|
|
3640
3643
|
}));
|
|
3641
|
-
program.command("attach").argument("<serverSlug>", "target Slock server slug (canonical form `/myserver`; bare `myserver` accepted)").description("Attach this Computer to one Slock server (add-not-replace; multi-server OK).").option("--server-url <url>",
|
|
3644
|
+
program.command("attach").argument("<serverSlug>", "target Slock server slug (canonical form `/myserver`; bare `myserver` accepted)").description("Attach this Computer to one Slock server (add-not-replace; multi-server OK).").option("--server-url <url>", `Slock API base URL; defaults to the saved user session, SLOCK_SERVER_URL, or ${DEFAULT_SLOCK_SERVER_URL}`).option("--name <name>", "Computer display name; defaults to a sanitized hostname").option("--no-run", "only authorize + write local state; do not start the supervisor").option("--foreground", "run the supervisor in this terminal instead of the background").action(withCliExit(async (serverSlug, opts) => {
|
|
3642
3645
|
await withMutationLock(
|
|
3643
3646
|
() => runAttach({ serverSlug, serverUrl: opts.serverUrl, name: opts.name, run: opts.run, foreground: opts.foreground })
|
|
3644
3647
|
);
|
|
3645
3648
|
}));
|
|
3646
|
-
program.command("setup").argument("<serverSlug>", "target Slock server slug (canonical form `/myserver`; bare `myserver` accepted)").description("Set up this Computer for one server: login if needed, attach/adopt if needed, then start.").option("--server-url <url>",
|
|
3649
|
+
program.command("setup").argument("<serverSlug>", "target Slock server slug (canonical form `/myserver`; bare `myserver` accepted)").description("Set up this Computer for one server: login if needed, attach/adopt if needed, then start.").option("--server-url <url>", `Slock API base URL; defaults to the saved user session, SLOCK_SERVER_URL, or ${DEFAULT_SLOCK_SERVER_URL}`).option("--name <name>", "Computer display name for a new attachment/adoption; defaults to a sanitized hostname").option("--adopt-legacy", "attempt one-time migration from a legacy daemon before fresh attach fallback").option("--legacy-api-key <key>", "legacy key for --adopt-legacy (migration-only; prefer file/stdin)").option("--legacy-api-key-file <path>", "path to a file containing the legacy key for --adopt-legacy").option("--legacy-api-key-stdin", "read the legacy key from stdin for --adopt-legacy").option("--no-start", "stop after login + attach/adopt; do not start the supervisor").option("--foreground", "run the supervisor in this terminal instead of the background").option("-y, --yes", "allow non-interactive setup after confirming the planned actions").action(
|
|
3647
3650
|
withCliExit(async (serverSlug, opts) => {
|
|
3648
3651
|
await withMutationLock(
|
|
3649
3652
|
() => runSetup({
|
|
@@ -3663,7 +3666,7 @@ program.command("setup").argument("<serverSlug>", "target Slock server slug (can
|
|
|
3663
3666
|
);
|
|
3664
3667
|
program.command("adopt-legacy").argument("<serverSlug>", "target Slock server slug (the legacy machine's server)").description(
|
|
3665
3668
|
"One-time migration: trade a legacy sk_machine_* / sk_daemon_* key for a fresh Computer attachment (sk_computer_*)."
|
|
3666
|
-
).option("--server-url <url>",
|
|
3669
|
+
).option("--server-url <url>", `Slock API base URL; defaults to the saved user session, SLOCK_SERVER_URL, or ${DEFAULT_SLOCK_SERVER_URL}`).option("--name <name>", "name to record on the new Computer attachment (default: existing machine name)").option("--legacy-api-key <key>", "raw legacy key on argv (insecure on shared shells; prefer --legacy-api-key-file or stdin)").option("--legacy-api-key-file <path>", "path to a 0600 file containing the legacy key (one line)").option("--legacy-api-key-stdin", "read the legacy key from stdin").action(
|
|
3667
3670
|
withCliExit(async (serverSlug, opts) => {
|
|
3668
3671
|
await withMutationLock(
|
|
3669
3672
|
() => runAdoptLegacy({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@slock-ai/computer",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "Slock Computer — standalone human/local-machine control-plane CLI (login + attach). Distinct from the agent-facing @slock-ai/cli.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -17,20 +17,11 @@
|
|
|
17
17
|
"publishConfig": {
|
|
18
18
|
"access": "public"
|
|
19
19
|
},
|
|
20
|
-
"scripts": {
|
|
21
|
-
"computer": "tsx src/index.ts",
|
|
22
|
-
"start": "tsx src/index.ts",
|
|
23
|
-
"build:deps": "pnpm --filter @slock-ai/daemon build",
|
|
24
|
-
"build": "pnpm run build:deps && tsup",
|
|
25
|
-
"test": "node --import tsx --test --test-force-exit 'src/**/*.test.ts'",
|
|
26
|
-
"typecheck": "tsc --noEmit",
|
|
27
|
-
"lint:boundaries": "node scripts/check-boundaries.mjs"
|
|
28
|
-
},
|
|
29
20
|
"dependencies": {
|
|
30
|
-
"@slock-ai/daemon": "workspace:*",
|
|
31
21
|
"commander": "^12.1.0",
|
|
32
22
|
"proper-lockfile": "^4.1.2",
|
|
33
|
-
"undici": "^7.24.7"
|
|
23
|
+
"undici": "^7.24.7",
|
|
24
|
+
"@slock-ai/daemon": "0.52.2"
|
|
34
25
|
},
|
|
35
26
|
"devDependencies": {
|
|
36
27
|
"@types/node": "^25.5.0",
|
|
@@ -38,5 +29,14 @@
|
|
|
38
29
|
"tsup": "^8.5.1",
|
|
39
30
|
"tsx": "^4.21.0",
|
|
40
31
|
"typescript": "^5.9.3"
|
|
32
|
+
},
|
|
33
|
+
"scripts": {
|
|
34
|
+
"computer": "tsx src/index.ts",
|
|
35
|
+
"start": "tsx src/index.ts",
|
|
36
|
+
"build:deps": "pnpm --filter @slock-ai/daemon build",
|
|
37
|
+
"build": "pnpm run build:deps && tsup",
|
|
38
|
+
"test": "node --import tsx --test --test-force-exit 'src/**/*.test.ts'",
|
|
39
|
+
"typecheck": "tsc --noEmit",
|
|
40
|
+
"lint:boundaries": "node scripts/check-boundaries.mjs"
|
|
41
41
|
}
|
|
42
|
-
}
|
|
42
|
+
}
|