@slock-ai/computer 0.0.3 → 0.0.4
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 +77 -6
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -121,15 +121,18 @@ var ComputerAttachClient = class {
|
|
|
121
121
|
resumed: body.resumed === true
|
|
122
122
|
};
|
|
123
123
|
}
|
|
124
|
-
const code = body && typeof body.code === "string" ? body.code :
|
|
125
|
-
if (res.status === 401
|
|
126
|
-
return { status: "legacy_key_invalid" };
|
|
124
|
+
const code = body && typeof body.code === "string" ? body.code : void 0;
|
|
125
|
+
if (res.status === 401) {
|
|
126
|
+
if (code === "legacy_key_invalid") return { status: "legacy_key_invalid" };
|
|
127
|
+
if (code === "auth_required") return { status: "auth_required" };
|
|
128
|
+
return { status: "unexpected_response", httpStatus: res.status, ...code ? { code } : {} };
|
|
127
129
|
}
|
|
128
130
|
if (res.status === 409 && code === "legacy_machine_key_migrated") {
|
|
129
131
|
return { status: "legacy_machine_key_migrated" };
|
|
130
132
|
}
|
|
131
133
|
if (res.status === 403) return { status: "not_authorized" };
|
|
132
134
|
if (res.status === 404) return { status: "disabled" };
|
|
135
|
+
if (!code) return { status: "unexpected_response", httpStatus: res.status };
|
|
133
136
|
return { status: "error", code };
|
|
134
137
|
}
|
|
135
138
|
/**
|
|
@@ -688,6 +691,43 @@ async function stopLegacyDaemonByOwnerFile(ownerFile) {
|
|
|
688
691
|
}
|
|
689
692
|
return { attempted: true, pid, outcome: "timed_out" };
|
|
690
693
|
}
|
|
694
|
+
async function readLegacyOwnerEvidence(ownerFile) {
|
|
695
|
+
let raw;
|
|
696
|
+
try {
|
|
697
|
+
raw = await readFile3(ownerFile, "utf8");
|
|
698
|
+
} catch {
|
|
699
|
+
return { ownerFile, reason: "owner_file_absent" };
|
|
700
|
+
}
|
|
701
|
+
let owner;
|
|
702
|
+
try {
|
|
703
|
+
owner = JSON.parse(raw);
|
|
704
|
+
} catch {
|
|
705
|
+
return { ownerFile, reason: "owner_json_unparseable" };
|
|
706
|
+
}
|
|
707
|
+
const pid = typeof owner.pid === "number" ? owner.pid : void 0;
|
|
708
|
+
return {
|
|
709
|
+
ownerFile,
|
|
710
|
+
pid,
|
|
711
|
+
alive: typeof pid === "number" ? isProcessAlive(pid) : void 0,
|
|
712
|
+
startedAt: typeof owner.startedAt === "string" ? owner.startedAt : void 0,
|
|
713
|
+
serverUrl: typeof owner.serverUrl === "string" ? owner.serverUrl : void 0,
|
|
714
|
+
reason: typeof pid === "number" ? void 0 : "owner_json_missing_pid"
|
|
715
|
+
};
|
|
716
|
+
}
|
|
717
|
+
function formatLegacyOwnerEvidence(slockHome, evidence) {
|
|
718
|
+
const fields = [
|
|
719
|
+
`SLOCK_HOME=${slockHome}`,
|
|
720
|
+
`owner=${evidence.ownerFile}`
|
|
721
|
+
];
|
|
722
|
+
if (typeof evidence.pid === "number") {
|
|
723
|
+
fields.push(`pid=${evidence.pid}`);
|
|
724
|
+
if (typeof evidence.alive === "boolean") fields.push(`alive=${evidence.alive}`);
|
|
725
|
+
}
|
|
726
|
+
if (evidence.startedAt) fields.push(`startedAt=${evidence.startedAt}`);
|
|
727
|
+
if (evidence.serverUrl) fields.push(`serverUrl=${evidence.serverUrl}`);
|
|
728
|
+
if (evidence.reason) fields.push(`ownerStatus=${evidence.reason}`);
|
|
729
|
+
return fields.join(" ");
|
|
730
|
+
}
|
|
691
731
|
async function runAdoptLegacy(inputs) {
|
|
692
732
|
const slockHome = resolveSlockHome();
|
|
693
733
|
const sessionFile = userSessionPath(slockHome);
|
|
@@ -718,6 +758,7 @@ async function runAdoptLegacy(inputs) {
|
|
|
718
758
|
const client = new ComputerAttachClient(baseUrl, session.accessToken);
|
|
719
759
|
const adoptStartedAt = /* @__PURE__ */ new Date();
|
|
720
760
|
const legacyOwnerFile = legacyLockOwnerPath(slockHome, legacy.rawKey);
|
|
761
|
+
const ownerEvidence = await readLegacyOwnerEvidence(legacyOwnerFile);
|
|
721
762
|
const result = await client.adoptLegacy(legacy.rawKey, inputs.name);
|
|
722
763
|
legacy.rawKey = void 0;
|
|
723
764
|
if (result.status === "disabled") {
|
|
@@ -743,7 +784,7 @@ async function runAdoptLegacy(inputs) {
|
|
|
743
784
|
});
|
|
744
785
|
fail(
|
|
745
786
|
"LEGACY_KEY_INVALID",
|
|
746
|
-
|
|
787
|
+
`Server rejected the legacy api key (unknown / wrong server / malformed). Local legacy owner evidence for this key: ${formatLegacyOwnerEvidence(slockHome, ownerEvidence)}. Verify the key came from this SLOCK_HOME and server, or use a fresh isolated SLOCK_HOME for a clean Computer setup.`
|
|
747
788
|
);
|
|
748
789
|
}
|
|
749
790
|
if (result.status === "legacy_machine_key_migrated") {
|
|
@@ -756,7 +797,20 @@ async function runAdoptLegacy(inputs) {
|
|
|
756
797
|
});
|
|
757
798
|
fail(
|
|
758
799
|
"LEGACY_MACHINE_KEY_MIGRATED",
|
|
759
|
-
|
|
800
|
+
`This machine has already been adopted; the legacy key is no longer accepted. Local legacy owner evidence for this key: ${formatLegacyOwnerEvidence(slockHome, ownerEvidence)}. Use \`slock-computer attach\` to add another Computer attachment, or use a fresh isolated SLOCK_HOME for a clean setup.`
|
|
801
|
+
);
|
|
802
|
+
}
|
|
803
|
+
if (result.status === "auth_required") {
|
|
804
|
+
await appendAdoptionLog(slockHome, {
|
|
805
|
+
mode: legacy.mode,
|
|
806
|
+
redactedPrefix: legacy.redactedPrefix,
|
|
807
|
+
startedAt: adoptStartedAt,
|
|
808
|
+
outcome: "failed",
|
|
809
|
+
failureReason: "auth_required"
|
|
810
|
+
});
|
|
811
|
+
fail(
|
|
812
|
+
"ADOPT_AUTH_REQUIRED",
|
|
813
|
+
`Your Computer user session was rejected by the server before legacy adoption. Local legacy owner evidence for this key: ${formatLegacyOwnerEvidence(slockHome, ownerEvidence)}. Re-run \`slock-computer login\` for this server (use the same \`--server-url\` if not on production), then retry the adopt command. No local Computer state was written.`
|
|
760
814
|
);
|
|
761
815
|
}
|
|
762
816
|
if (result.status === "not_authorized") {
|
|
@@ -772,6 +826,20 @@ async function runAdoptLegacy(inputs) {
|
|
|
772
826
|
"Not authorized to adopt this machine on this server. Check that you are a current member."
|
|
773
827
|
);
|
|
774
828
|
}
|
|
829
|
+
if (result.status === "unexpected_response") {
|
|
830
|
+
await appendAdoptionLog(slockHome, {
|
|
831
|
+
mode: legacy.mode,
|
|
832
|
+
redactedPrefix: legacy.redactedPrefix,
|
|
833
|
+
startedAt: adoptStartedAt,
|
|
834
|
+
outcome: "failed",
|
|
835
|
+
failureReason: result.code ? `unexpected_response_${result.code}` : "unexpected_response_missing_code"
|
|
836
|
+
});
|
|
837
|
+
const responseDetail = result.code ? `status ${result.httpStatus}, code ${result.code}` : `status ${result.httpStatus}, missing error code`;
|
|
838
|
+
fail(
|
|
839
|
+
"ADOPT_UNEXPECTED_RESPONSE",
|
|
840
|
+
`Server returned an unexpected legacy adoption response (${responseDetail}). Local legacy owner evidence for this key: ${formatLegacyOwnerEvidence(slockHome, ownerEvidence)}. Please report this with the command, server URL, and SLOCK_HOME; no local Computer state was written.`
|
|
841
|
+
);
|
|
842
|
+
}
|
|
775
843
|
if (result.status === "error") {
|
|
776
844
|
await appendAdoptionLog(slockHome, {
|
|
777
845
|
mode: legacy.mode,
|
|
@@ -780,7 +848,10 @@ async function runAdoptLegacy(inputs) {
|
|
|
780
848
|
outcome: "failed",
|
|
781
849
|
failureReason: result.code
|
|
782
850
|
});
|
|
783
|
-
fail(
|
|
851
|
+
fail(
|
|
852
|
+
"ADOPT_FAILED",
|
|
853
|
+
`Adoption failed at server exchange (${result.code}). Local legacy owner evidence for this key: ${formatLegacyOwnerEvidence(slockHome, ownerEvidence)}. Confirm the user session is valid, the legacy key belongs to this server/SLOCK_HOME, and the server URL is correct. No local Computer state was written.`
|
|
854
|
+
);
|
|
784
855
|
}
|
|
785
856
|
info(result.resumed ? "Adopted (resumed prior attachment); running preflight\u2026" : "Adopted; running preflight\u2026");
|
|
786
857
|
const pre = await client.preflight(result.apiKey);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@slock-ai/computer",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
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": {
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"commander": "^12.1.0",
|
|
22
22
|
"proper-lockfile": "^4.1.2",
|
|
23
23
|
"undici": "^7.24.7",
|
|
24
|
-
"@slock-ai/daemon": "0.
|
|
24
|
+
"@slock-ai/daemon": "0.53.0"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@types/node": "^25.5.0",
|