@catamorphic/work-server 0.1.0-alpha.38 → 0.1.0-alpha.41
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/NOTICE.txt +7 -0
- package/README.md +9 -9
- package/dist/admission/routes.d.ts +1 -1
- package/dist/admission/routes.d.ts.map +1 -1
- package/dist/agent-capabilities.d.ts.map +1 -1
- package/dist/agents.d.ts +5 -6
- package/dist/agents.d.ts.map +1 -1
- package/dist/auth/fastify-auth.d.ts.map +1 -1
- package/dist/auth/work-auth-types.d.ts +2 -0
- package/dist/auth/work-auth-types.d.ts.map +1 -1
- package/dist/auth/work-auth.d.ts.map +1 -1
- package/dist/chunk-kcck20aw.js +676 -0
- package/dist/chunk-kcck20aw.js.map +11 -0
- package/dist/cluster.d.ts +8 -7
- package/dist/cluster.d.ts.map +1 -1
- package/dist/config.d.ts +5 -15
- package/dist/config.d.ts.map +1 -1
- package/dist/execution-config.d.ts +22 -0
- package/dist/execution-config.d.ts.map +1 -1
- package/dist/fake-agent.d.ts +1 -0
- package/dist/fake-agent.d.ts.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2730 -2851
- package/dist/index.js.map +28 -28
- package/dist/machines/contract-kit.d.ts +91 -0
- package/dist/machines/contract-kit.d.ts.map +1 -0
- package/dist/machines/contract.d.ts +383 -0
- package/dist/machines/contract.d.ts.map +1 -0
- package/dist/machines/sequencer.d.ts +267 -0
- package/dist/machines/sequencer.d.ts.map +1 -0
- package/dist/machines/simulation.d.ts +124 -0
- package/dist/machines/simulation.d.ts.map +1 -0
- package/dist/machines/work-machines.d.ts +61 -0
- package/dist/machines/work-machines.d.ts.map +1 -0
- package/dist/server.d.ts +15 -11
- package/dist/server.d.ts.map +1 -1
- package/dist/setup/machines.d.ts +9 -17
- package/dist/setup/machines.d.ts.map +1 -1
- package/dist/shares/share-routes.d.ts +1 -1
- package/dist/shares/share-routes.d.ts.map +1 -1
- package/dist/testing.d.ts +8 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +1013 -0
- package/dist/testing.js.map +11 -0
- package/dist/workers/disk-care.d.ts +41 -0
- package/dist/workers/disk-care.d.ts.map +1 -0
- package/dist/workers/harness-sign-ins.d.ts +146 -0
- package/dist/workers/harness-sign-ins.d.ts.map +1 -0
- package/dist/workers/machine-store.d.ts +196 -0
- package/dist/workers/machine-store.d.ts.map +1 -0
- package/dist/workers/member-machine-routes.d.ts +5 -3
- package/dist/workers/member-machine-routes.d.ts.map +1 -1
- package/dist/workers/member-machines.d.ts +47 -28
- package/dist/workers/member-machines.d.ts.map +1 -1
- package/dist/workers/placement.d.ts +23 -40
- package/dist/workers/placement.d.ts.map +1 -1
- package/dist/workers/sign-ins.d.ts +44 -17
- package/dist/workers/sign-ins.d.ts.map +1 -1
- package/dist/workers/worker-protocol.d.ts +5 -2
- package/dist/workers/worker-protocol.d.ts.map +1 -1
- package/dist/workers/worker-registry.d.ts +174 -223
- package/dist/workers/worker-registry.d.ts.map +1 -1
- package/dist/workers/worker-routes.d.ts.map +1 -1
- package/dist/workers/worker-runtime.d.ts.map +1 -1
- package/package.json +44 -34
- package/src/admission/routes.ts +5 -2
- package/src/agent-capabilities.ts +22 -8
- package/src/agents.ts +52 -23
- package/src/auth/fastify-auth.ts +149 -17
- package/src/auth/work-auth-types.ts +2 -0
- package/src/auth/work-auth.ts +27 -0
- package/src/cluster.ts +115 -42
- package/src/config.ts +15 -41
- package/src/execution-config.ts +40 -0
- package/src/fake-agent.ts +21 -4
- package/src/index.ts +26 -12
- package/src/machines/contract-kit.ts +648 -0
- package/src/machines/contract.ts +522 -0
- package/src/machines/sequencer.ts +1010 -0
- package/src/machines/simulation.ts +833 -0
- package/src/machines/work-machines.ts +231 -0
- package/src/server.ts +235 -150
- package/src/setup/machines.ts +128 -121
- package/src/shares/share-routes.ts +17 -1
- package/src/testing.ts +22 -0
- package/src/workers/disk-care.ts +121 -0
- package/src/workers/fake-claude-cli.ts +95 -0
- package/src/workers/fake-codex-cli.ts +11 -4
- package/src/workers/harness-sign-ins.ts +580 -0
- package/src/workers/machine-store.ts +1065 -0
- package/src/workers/member-machine-routes.ts +92 -20
- package/src/workers/member-machines.ts +163 -99
- package/src/workers/placement.ts +59 -70
- package/src/workers/sign-ins.ts +109 -52
- package/src/workers/worker-protocol.ts +5 -2
- package/src/workers/worker-registry.ts +894 -754
- package/src/workers/worker-routes.ts +4 -1
- package/src/workers/worker-runtime.ts +55 -23
- package/dist/test-support.d.ts +0 -133
- package/dist/test-support.d.ts.map +0 -1
- package/dist/workers/codex-sign-ins.d.ts +0 -107
- package/dist/workers/codex-sign-ins.d.ts.map +0 -1
- package/dist/workers/install-script.d.ts +0 -71
- package/dist/workers/install-script.d.ts.map +0 -1
- package/dist/workers/machine-classes.d.ts +0 -115
- package/dist/workers/machine-classes.d.ts.map +0 -1
- package/dist/workers/machine-rules.d.ts +0 -402
- package/dist/workers/machine-rules.d.ts.map +0 -1
- package/src/test-support.ts +0 -404
- package/src/workers/codex-sign-ins.ts +0 -360
- package/src/workers/install-script.ts +0 -394
- package/src/workers/machine-classes.ts +0 -152
- package/src/workers/machine-rules.ts +0 -1954
package/src/workers/placement.ts
CHANGED
|
@@ -1,104 +1,93 @@
|
|
|
1
1
|
import type { NodeAccess } from "@catamorphic/sandbox";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
+
import {
|
|
4
|
+
MachineLabelsSchema,
|
|
5
|
+
type MachinePrincipal,
|
|
6
|
+
MachinePrincipalSchema,
|
|
7
|
+
normalizePrincipals,
|
|
8
|
+
RESERVED_LABELS,
|
|
9
|
+
servesNobody,
|
|
10
|
+
servesOneOwner,
|
|
11
|
+
} from "../machines/contract.js";
|
|
3
12
|
|
|
4
|
-
|
|
5
|
-
export const RESERVED_LABELS = ["node", "plane"] as const;
|
|
13
|
+
export { RESERVED_LABELS, servesNobody, servesOneOwner };
|
|
6
14
|
|
|
7
|
-
export const NodeLabelsSchema =
|
|
8
|
-
.record(
|
|
9
|
-
z
|
|
10
|
-
.string()
|
|
11
|
-
.regex(
|
|
12
|
-
/^[a-z0-9][a-z0-9._-]{0,62}$/,
|
|
13
|
-
"Label names are lowercase letters, digits, dots, dashes",
|
|
14
|
-
),
|
|
15
|
-
z.string().min(1).max(128),
|
|
16
|
-
)
|
|
17
|
-
.refine(
|
|
18
|
-
(labels) => RESERVED_LABELS.every((key) => !(key in labels)),
|
|
19
|
-
`The server sets ${RESERVED_LABELS.join(" and ")} itself`,
|
|
20
|
-
);
|
|
15
|
+
export const NodeLabelsSchema = MachineLabelsSchema;
|
|
21
16
|
|
|
22
17
|
/**
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* Control-plane state; a worker never declares it.
|
|
18
|
+
* A machine's placement (ADRs 0167, 0349): the labels an Environment's
|
|
19
|
+
* `pool` selects on, whom it is for (users, projects' own work, single
|
|
20
|
+
* chat keys, or anyone when absent), and whether those it serves trust
|
|
21
|
+
* each other. Control-plane state; a worker never declares it.
|
|
27
22
|
*/
|
|
28
|
-
export const WorkerAccessSchema = z.union([
|
|
29
|
-
z.strictObject({ everyone: z.literal(true) }),
|
|
30
|
-
z.strictObject({ nobody: z.literal(true) }),
|
|
31
|
-
z
|
|
32
|
-
.strictObject({
|
|
33
|
-
people: z.array(z.email().toLowerCase()).max(500).default([]),
|
|
34
|
-
groups: z.array(z.email().toLowerCase()).max(100).default([]),
|
|
35
|
-
projects: z.array(z.uuid()).max(100).default([]),
|
|
36
|
-
})
|
|
37
|
-
.refine(
|
|
38
|
-
(access) =>
|
|
39
|
-
access.people.length + access.groups.length + access.projects.length >
|
|
40
|
-
0,
|
|
41
|
-
"Name at least one person, group or project, or use { everyone: true }",
|
|
42
|
-
),
|
|
43
|
-
]);
|
|
44
|
-
export type WorkerAccess = z.output<typeof WorkerAccessSchema>;
|
|
45
|
-
|
|
46
23
|
export const WorkerPlacementSchema = z.strictObject({
|
|
47
24
|
labels: NodeLabelsSchema.default({}),
|
|
48
|
-
|
|
25
|
+
/** Who may place work here; left out, anyone. An empty list: nobody. */
|
|
26
|
+
for: z.array(MachinePrincipalSchema).max(500).optional(),
|
|
49
27
|
/**
|
|
50
28
|
* The people this worker serves trust each other: process isolation is
|
|
51
29
|
* acceptable although it serves more than one person.
|
|
52
30
|
*/
|
|
53
31
|
trusted: z.boolean().default(false),
|
|
54
32
|
});
|
|
55
|
-
export type WorkerPlacement = z.output<typeof WorkerPlacementSchema>;
|
|
56
33
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
34
|
+
export interface WorkerPlacement {
|
|
35
|
+
labels: Readonly<Record<string, string>>;
|
|
36
|
+
/** Null: anyone whose role and Environment allow it. */
|
|
37
|
+
for: readonly MachinePrincipal[] | null;
|
|
38
|
+
trusted: boolean;
|
|
39
|
+
}
|
|
62
40
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
41
|
+
/** A parsed placement, with "anyone" as null and principals in order. */
|
|
42
|
+
export function workerPlacement(
|
|
43
|
+
input: z.input<typeof WorkerPlacementSchema>,
|
|
44
|
+
): WorkerPlacement {
|
|
45
|
+
const parsed = WorkerPlacementSchema.parse(input);
|
|
66
46
|
return {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
47
|
+
labels: parsed.labels,
|
|
48
|
+
for: parsed.for === undefined ? null : normalizePrincipals(parsed.for),
|
|
49
|
+
trusted: parsed.trusted,
|
|
70
50
|
};
|
|
71
51
|
}
|
|
72
52
|
|
|
73
53
|
/**
|
|
74
|
-
*
|
|
75
|
-
*
|
|
54
|
+
* A worker's placement as the scheduler reads it. A machine that is not
|
|
55
|
+
* `accepting` (the plan dropped it, it is stopping, stopped, resuming or
|
|
56
|
+
* being reset, ADRs 0349, 0350) takes no new work and keeps serving the
|
|
57
|
+
* Allocations it holds.
|
|
76
58
|
*/
|
|
77
|
-
export
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
59
|
+
export type ScheduledPlacement = WorkerPlacement & {
|
|
60
|
+
accepting: boolean;
|
|
61
|
+
admissionRevision: string | null;
|
|
62
|
+
};
|
|
82
63
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
64
|
+
export function nodeAccess(
|
|
65
|
+
principals: readonly MachinePrincipal[] | null,
|
|
66
|
+
): NodeAccess {
|
|
67
|
+
if (principals === null) return { everyone: true };
|
|
68
|
+
const users: string[] = [];
|
|
69
|
+
const projects: string[] = [];
|
|
70
|
+
const keys: { project: string; key: string }[] = [];
|
|
71
|
+
for (const principal of principals) {
|
|
72
|
+
if ("user" in principal) users.push(principal.user);
|
|
73
|
+
else if ("key" in principal)
|
|
74
|
+
keys.push({ project: principal.project, key: principal.key });
|
|
75
|
+
else projects.push(principal.project);
|
|
76
|
+
}
|
|
77
|
+
return { users, projects, keys };
|
|
86
78
|
}
|
|
87
79
|
|
|
88
|
-
|
|
89
|
-
export function accessGroupsOf(access: WorkerAccess): readonly string[] {
|
|
90
|
-
return "groups" in access ? access.groups : [];
|
|
91
|
-
}
|
|
80
|
+
const StoredPrincipals = z.array(MachinePrincipalSchema).nullable();
|
|
92
81
|
|
|
93
82
|
/** Stored placement, validated on the way out of the database. */
|
|
94
83
|
export function storedPlacement(row: {
|
|
95
84
|
labels: unknown;
|
|
96
|
-
|
|
85
|
+
serves: unknown;
|
|
97
86
|
trusted: boolean;
|
|
98
87
|
}): WorkerPlacement {
|
|
99
|
-
return
|
|
100
|
-
labels: row.labels,
|
|
101
|
-
|
|
88
|
+
return {
|
|
89
|
+
labels: NodeLabelsSchema.parse(row.labels),
|
|
90
|
+
for: StoredPrincipals.parse(row.serves ?? null),
|
|
102
91
|
trusted: row.trusted,
|
|
103
|
-
}
|
|
92
|
+
};
|
|
104
93
|
}
|
package/src/workers/sign-ins.ts
CHANGED
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
MACHINE_CAPABILITIES,
|
|
8
8
|
machineSignInHome,
|
|
9
9
|
SIGN_IN_HARNESSES,
|
|
10
|
+
SIGN_IN_SPECS,
|
|
10
11
|
type SignInHarness,
|
|
11
12
|
signInCapability,
|
|
12
13
|
signInMemberDirectory,
|
|
@@ -14,12 +15,13 @@ import {
|
|
|
14
15
|
} from "@catamorphic/sandbox";
|
|
15
16
|
|
|
16
17
|
/**
|
|
17
|
-
* Members' own Codex sign-ins on this machine (ADRs 0199,
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
18
|
+
* Members' own Claude Code and Codex sign-ins on this machine (ADRs 0199,
|
|
19
|
+
* 0213, 0342). Each is the harness's own home for one member under the
|
|
20
|
+
* machine's data directory, made by the harness's own unmodified login on
|
|
21
|
+
* this machine. Work never reads, copies or sends what is inside: the
|
|
22
|
+
* machine reports only who is signed in, and a sandbox of that member's
|
|
23
|
+
* chat mounts their home. What differs between harnesses is in
|
|
24
|
+
* `SIGN_IN_SPECS`.
|
|
23
25
|
*/
|
|
24
26
|
export function signInRoot(dataDir: string): string {
|
|
25
27
|
return path.join(dataDir, "sign-ins");
|
|
@@ -31,8 +33,15 @@ export interface MachineSignIn {
|
|
|
31
33
|
home: string;
|
|
32
34
|
}
|
|
33
35
|
|
|
34
|
-
/**
|
|
35
|
-
|
|
36
|
+
/** Whether a home holds the file its harness's completed login leaves. */
|
|
37
|
+
export function signedIn(input: {
|
|
38
|
+
harness: SignInHarness;
|
|
39
|
+
home: string;
|
|
40
|
+
}): boolean {
|
|
41
|
+
return fs.existsSync(
|
|
42
|
+
path.join(input.home, SIGN_IN_SPECS[input.harness].completionFile),
|
|
43
|
+
);
|
|
44
|
+
}
|
|
36
45
|
|
|
37
46
|
/** The sign-in homes on this machine that hold a completed login. */
|
|
38
47
|
export function listMachineSignIns(root: string): MachineSignIn[] {
|
|
@@ -49,27 +58,28 @@ export function listMachineSignIns(root: string): MachineSignIn[] {
|
|
|
49
58
|
? signInMemberOf(entry.name)
|
|
50
59
|
: undefined;
|
|
51
60
|
const home = path.join(directory, entry.name);
|
|
52
|
-
return member &&
|
|
61
|
+
return member && signedIn({ harness, home })
|
|
53
62
|
? [{ harness, member, home }]
|
|
54
63
|
: [];
|
|
55
64
|
});
|
|
56
65
|
});
|
|
57
66
|
}
|
|
58
67
|
|
|
59
|
-
/** A machine holds one person's
|
|
68
|
+
/** A machine holds one person's sign-ins at most (ADRs 0213, 0342). */
|
|
60
69
|
export class MachineHeldError extends Error {
|
|
61
70
|
constructor() {
|
|
62
71
|
super(
|
|
63
|
-
"Another person's
|
|
72
|
+
"Another person's sign-in is on this machine, and a machine holds one person's only. Ask an administrator for a machine of your own",
|
|
64
73
|
);
|
|
65
74
|
this.name = "MachineHeldError";
|
|
66
75
|
}
|
|
67
76
|
}
|
|
68
77
|
|
|
69
78
|
/**
|
|
70
|
-
* Refuse a member's login on a machine that holds someone else's
|
|
71
|
-
* machine signed in to several accounts reads to
|
|
72
|
-
* or resold account.
|
|
79
|
+
* Refuse a member's login on a machine that holds someone else's, of any
|
|
80
|
+
* harness: one machine signed in to several people's accounts reads to a
|
|
81
|
+
* provider as a shared or resold account. One person may hold a sign-in of
|
|
82
|
+
* each harness there.
|
|
73
83
|
*/
|
|
74
84
|
export function assertMachineFree(input: { root: string; member: string }) {
|
|
75
85
|
if (
|
|
@@ -94,48 +104,72 @@ export function signInCapabilities(root: string): string[] {
|
|
|
94
104
|
];
|
|
95
105
|
}
|
|
96
106
|
|
|
97
|
-
/**
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
*/
|
|
102
|
-
export function codexCommand(env: NodeJS.ProcessEnv = process.env): {
|
|
103
|
-
command: string;
|
|
104
|
-
args: string[];
|
|
105
|
-
} {
|
|
106
|
-
for (const directory of (env.PATH ?? "").split(path.delimiter)) {
|
|
107
|
-
if (!directory) continue;
|
|
107
|
+
/** Whether an executable of this name is on a search path. */
|
|
108
|
+
function onPath(command: string, env: NodeJS.ProcessEnv): boolean {
|
|
109
|
+
return (env.PATH ?? "").split(path.delimiter).some((directory) => {
|
|
110
|
+
if (!directory) return false;
|
|
108
111
|
try {
|
|
109
|
-
fs.accessSync(path.join(directory,
|
|
110
|
-
return
|
|
112
|
+
fs.accessSync(path.join(directory, command), fs.constants.X_OK);
|
|
113
|
+
return true;
|
|
111
114
|
} catch {
|
|
112
|
-
|
|
115
|
+
return false;
|
|
113
116
|
}
|
|
114
|
-
}
|
|
115
|
-
return {
|
|
116
|
-
command: process.execPath,
|
|
117
|
-
args: [
|
|
118
|
-
createRequire(import.meta.url).resolve("@openai/codex/bin/codex.js"),
|
|
119
|
-
],
|
|
120
|
-
};
|
|
117
|
+
});
|
|
121
118
|
}
|
|
122
119
|
|
|
123
|
-
/**
|
|
120
|
+
/**
|
|
121
|
+
* The CLI to sign in with: the machine's own on `PATH`. For Codex, else
|
|
122
|
+
* the one this package carries (the version Work's Codex harness speaks),
|
|
123
|
+
* run with this process's runtime: the image has no `codex` on its `PATH`.
|
|
124
|
+
* Claude Code is always the machine's own unmodified `claude`.
|
|
125
|
+
*/
|
|
126
|
+
export function harnessCommand(
|
|
127
|
+
harness: SignInHarness,
|
|
128
|
+
env: NodeJS.ProcessEnv = process.env,
|
|
129
|
+
): { command: string; args: string[] } {
|
|
130
|
+
const { command } = SIGN_IN_SPECS[harness];
|
|
131
|
+
if (harness === "codex" && !onPath(command, env))
|
|
132
|
+
return {
|
|
133
|
+
command: process.execPath,
|
|
134
|
+
args: [
|
|
135
|
+
createRequire(import.meta.url).resolve("@openai/codex/bin/codex.js"),
|
|
136
|
+
],
|
|
137
|
+
};
|
|
138
|
+
return { command, args: [] };
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** The harness's own login, pointed at one home. */
|
|
124
142
|
export function signInCommand(input: {
|
|
143
|
+
harness: SignInHarness;
|
|
125
144
|
home: string;
|
|
145
|
+
/** Instead of the harness's default login arguments. */
|
|
126
146
|
args?: readonly string[];
|
|
127
147
|
env?: NodeJS.ProcessEnv;
|
|
128
148
|
}): { command: string; args: string[]; env: Record<string, string> } {
|
|
129
|
-
const
|
|
149
|
+
const spec = SIGN_IN_SPECS[input.harness];
|
|
150
|
+
const cli = harnessCommand(input.harness, input.env);
|
|
130
151
|
return {
|
|
131
|
-
command:
|
|
132
|
-
args: [...
|
|
133
|
-
env: {
|
|
152
|
+
command: cli.command,
|
|
153
|
+
args: [...cli.args, ...spec.login, ...(input.args ?? spec.defaultArgs)],
|
|
154
|
+
env: { [spec.homeVariable]: input.home },
|
|
134
155
|
};
|
|
135
156
|
}
|
|
136
157
|
|
|
137
|
-
/**
|
|
138
|
-
|
|
158
|
+
/**
|
|
159
|
+
* The environment a login runs in: this process's, pointed at the login's
|
|
160
|
+
* home, without any variable that would hand the CLI another credential
|
|
161
|
+
* (an organization's key on a single server is not the member's sign-in).
|
|
162
|
+
*/
|
|
163
|
+
export function signInEnvironment(input: {
|
|
164
|
+
harness: SignInHarness;
|
|
165
|
+
base: NodeJS.ProcessEnv;
|
|
166
|
+
login: Record<string, string>;
|
|
167
|
+
}): NodeJS.ProcessEnv {
|
|
168
|
+
const env: NodeJS.ProcessEnv = { ...input.base };
|
|
169
|
+
for (const name of SIGN_IN_SPECS[input.harness].otherCredentials ?? [])
|
|
170
|
+
delete env[name];
|
|
171
|
+
return { ...env, ...input.login };
|
|
172
|
+
}
|
|
139
173
|
|
|
140
174
|
/**
|
|
141
175
|
* A login runs in a home of its own beside the member's, so a pending or
|
|
@@ -154,9 +188,10 @@ export function stageSignIn(input: {
|
|
|
154
188
|
`${input.harness}-${signInMemberDirectory(input.member)}-${randomUUID()}`,
|
|
155
189
|
);
|
|
156
190
|
fs.mkdirSync(staging, { recursive: true, mode: 0o700 });
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
191
|
+
for (const [name, content] of Object.entries(
|
|
192
|
+
SIGN_IN_SPECS[input.harness].homeFiles ?? {},
|
|
193
|
+
))
|
|
194
|
+
fs.writeFileSync(path.join(staging, name), content, { mode: 0o600 });
|
|
160
195
|
return staging;
|
|
161
196
|
}
|
|
162
197
|
|
|
@@ -174,6 +209,18 @@ export function placeSignIn(input: {
|
|
|
174
209
|
return home;
|
|
175
210
|
}
|
|
176
211
|
|
|
212
|
+
/**
|
|
213
|
+
* Why a login that exited cleanly left no sign-in in its home, for a
|
|
214
|
+
* person to read. On macOS Claude Code keeps its sign-in in the Keychain,
|
|
215
|
+
* keyed to the home it ran in, which no sandbox mounts.
|
|
216
|
+
*/
|
|
217
|
+
export function noSignInLeft(harness: SignInHarness): string {
|
|
218
|
+
const { name } = SIGN_IN_SPECS[harness];
|
|
219
|
+
return harness === "claude-code" && process.platform === "darwin"
|
|
220
|
+
? `${name} kept this sign-in in the macOS Keychain instead of its home, so a sandbox cannot use it. Sign in on a Linux machine`
|
|
221
|
+
: `${name} did not complete the sign-in`;
|
|
222
|
+
}
|
|
223
|
+
|
|
177
224
|
type Spawn = (
|
|
178
225
|
command: string,
|
|
179
226
|
args: string[],
|
|
@@ -181,7 +228,7 @@ type Spawn = (
|
|
|
181
228
|
) => Pick<SpawnSyncReturns<Buffer>, "status" | "error">;
|
|
182
229
|
|
|
183
230
|
/**
|
|
184
|
-
* Run
|
|
231
|
+
* Run a harness's own login for a member, interactively, in this terminal.
|
|
185
232
|
* Only a login that completes becomes the member's home, and only on a
|
|
186
233
|
* machine that holds no one else's ({@link assertMachineFree}).
|
|
187
234
|
*/
|
|
@@ -189,31 +236,41 @@ export function signInOnMachine(input: {
|
|
|
189
236
|
dataDir: string;
|
|
190
237
|
harness: SignInHarness;
|
|
191
238
|
member: string;
|
|
192
|
-
/**
|
|
239
|
+
/** Instead of the harness's default login arguments. */
|
|
193
240
|
args?: readonly string[];
|
|
194
241
|
spawn?: Spawn;
|
|
195
|
-
}): { home: string; exitCode: number } {
|
|
242
|
+
}): { home: string; exitCode: number; reason?: string } {
|
|
196
243
|
const root = signInRoot(input.dataDir);
|
|
197
244
|
assertMachineFree({ root, member: input.member });
|
|
198
245
|
const staging = stageSignIn({ ...input, root });
|
|
199
|
-
const login = signInCommand({
|
|
246
|
+
const login = signInCommand({
|
|
247
|
+
harness: input.harness,
|
|
248
|
+
home: staging,
|
|
249
|
+
args: input.args,
|
|
250
|
+
});
|
|
200
251
|
const spawn: Spawn =
|
|
201
252
|
input.spawn ??
|
|
202
253
|
((command, args, options) => spawnSync(command, args, options));
|
|
203
254
|
const result = spawn(login.command, login.args, {
|
|
204
|
-
env: {
|
|
255
|
+
env: signInEnvironment({
|
|
256
|
+
harness: input.harness,
|
|
257
|
+
base: process.env,
|
|
258
|
+
login: login.env,
|
|
259
|
+
}),
|
|
205
260
|
stdio: "inherit",
|
|
206
261
|
});
|
|
207
262
|
const exitCode = result.error ? 127 : (result.status ?? 1);
|
|
208
|
-
if (exitCode !== 0 || !
|
|
263
|
+
if (exitCode !== 0 || !signedIn({ harness: input.harness, home: staging })) {
|
|
209
264
|
fs.rmSync(staging, { recursive: true, force: true });
|
|
210
265
|
if (result.error)
|
|
211
266
|
throw new Error(
|
|
212
|
-
`Could not run ${login.command}: ${result.error.message}. Install
|
|
267
|
+
`Could not run ${login.command}: ${result.error.message}. Install ${SIGN_IN_SPECS[input.harness].name} on this machine first.`,
|
|
213
268
|
);
|
|
214
269
|
return {
|
|
215
270
|
home: machineSignInHome({ ...input, root }),
|
|
216
271
|
exitCode: exitCode || 1,
|
|
272
|
+
// The login said it finished, and left nothing to sign in with.
|
|
273
|
+
...(exitCode === 0 ? { reason: noSignInLeft(input.harness) } : {}),
|
|
217
274
|
};
|
|
218
275
|
}
|
|
219
276
|
return { home: placeSignIn({ ...input, root, staging }), exitCode: 0 };
|
|
@@ -15,10 +15,13 @@ export const WORKER_PROTOCOL_HEADER = "work-protocol";
|
|
|
15
15
|
* protocol 1 could open none of them.
|
|
16
16
|
* 3: the `egress.widen` and `egress.narrow` operations open a setup's
|
|
17
17
|
* network in a running sandbox and close it again (ADR 0257).
|
|
18
|
+
* 4: `machine.harnessSignIn` replaces `machine.codexSignIn`, names its
|
|
19
|
+
* harness and hands a login the code it waits for (ADR 0342); a worker of
|
|
20
|
+
* protocol 3 could parse none of it.
|
|
18
21
|
*/
|
|
19
22
|
export const WORKER_PROTOCOL = {
|
|
20
|
-
server:
|
|
21
|
-
minimum:
|
|
23
|
+
server: 4,
|
|
24
|
+
minimum: 4,
|
|
22
25
|
} as const;
|
|
23
26
|
|
|
24
27
|
/** What a control plane answers a worker it cannot drive, with status 426. */
|