@catamorphic/work-server 0.1.0-alpha.39 → 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.
Files changed (114) hide show
  1. package/NOTICE.txt +7 -0
  2. package/README.md +9 -9
  3. package/dist/admission/routes.d.ts +1 -1
  4. package/dist/admission/routes.d.ts.map +1 -1
  5. package/dist/agent-capabilities.d.ts.map +1 -1
  6. package/dist/agents.d.ts +5 -6
  7. package/dist/agents.d.ts.map +1 -1
  8. package/dist/auth/fastify-auth.d.ts.map +1 -1
  9. package/dist/auth/work-auth-types.d.ts +2 -0
  10. package/dist/auth/work-auth-types.d.ts.map +1 -1
  11. package/dist/auth/work-auth.d.ts.map +1 -1
  12. package/dist/chunk-kcck20aw.js +676 -0
  13. package/dist/chunk-kcck20aw.js.map +11 -0
  14. package/dist/cluster.d.ts +8 -7
  15. package/dist/cluster.d.ts.map +1 -1
  16. package/dist/config.d.ts +5 -15
  17. package/dist/config.d.ts.map +1 -1
  18. package/dist/execution-config.d.ts +22 -0
  19. package/dist/execution-config.d.ts.map +1 -1
  20. package/dist/fake-agent.d.ts +1 -0
  21. package/dist/fake-agent.d.ts.map +1 -1
  22. package/dist/index.d.ts +3 -2
  23. package/dist/index.d.ts.map +1 -1
  24. package/dist/index.js +2730 -2851
  25. package/dist/index.js.map +28 -28
  26. package/dist/machines/contract-kit.d.ts +91 -0
  27. package/dist/machines/contract-kit.d.ts.map +1 -0
  28. package/dist/machines/contract.d.ts +383 -0
  29. package/dist/machines/contract.d.ts.map +1 -0
  30. package/dist/machines/sequencer.d.ts +267 -0
  31. package/dist/machines/sequencer.d.ts.map +1 -0
  32. package/dist/machines/simulation.d.ts +124 -0
  33. package/dist/machines/simulation.d.ts.map +1 -0
  34. package/dist/machines/work-machines.d.ts +61 -0
  35. package/dist/machines/work-machines.d.ts.map +1 -0
  36. package/dist/server.d.ts +15 -11
  37. package/dist/server.d.ts.map +1 -1
  38. package/dist/setup/machines.d.ts +9 -17
  39. package/dist/setup/machines.d.ts.map +1 -1
  40. package/dist/shares/share-routes.d.ts +1 -1
  41. package/dist/shares/share-routes.d.ts.map +1 -1
  42. package/dist/testing.d.ts +8 -0
  43. package/dist/testing.d.ts.map +1 -0
  44. package/dist/testing.js +1013 -0
  45. package/dist/testing.js.map +11 -0
  46. package/dist/workers/disk-care.d.ts +41 -0
  47. package/dist/workers/disk-care.d.ts.map +1 -0
  48. package/dist/workers/harness-sign-ins.d.ts +146 -0
  49. package/dist/workers/harness-sign-ins.d.ts.map +1 -0
  50. package/dist/workers/machine-store.d.ts +196 -0
  51. package/dist/workers/machine-store.d.ts.map +1 -0
  52. package/dist/workers/member-machine-routes.d.ts +5 -3
  53. package/dist/workers/member-machine-routes.d.ts.map +1 -1
  54. package/dist/workers/member-machines.d.ts +47 -28
  55. package/dist/workers/member-machines.d.ts.map +1 -1
  56. package/dist/workers/placement.d.ts +23 -40
  57. package/dist/workers/placement.d.ts.map +1 -1
  58. package/dist/workers/sign-ins.d.ts +44 -17
  59. package/dist/workers/sign-ins.d.ts.map +1 -1
  60. package/dist/workers/worker-protocol.d.ts +5 -2
  61. package/dist/workers/worker-protocol.d.ts.map +1 -1
  62. package/dist/workers/worker-registry.d.ts +174 -223
  63. package/dist/workers/worker-registry.d.ts.map +1 -1
  64. package/dist/workers/worker-routes.d.ts.map +1 -1
  65. package/dist/workers/worker-runtime.d.ts.map +1 -1
  66. package/package.json +31 -21
  67. package/src/admission/routes.ts +5 -2
  68. package/src/agent-capabilities.ts +22 -8
  69. package/src/agents.ts +52 -23
  70. package/src/auth/fastify-auth.ts +149 -17
  71. package/src/auth/work-auth-types.ts +2 -0
  72. package/src/auth/work-auth.ts +27 -0
  73. package/src/cluster.ts +115 -42
  74. package/src/config.ts +15 -41
  75. package/src/execution-config.ts +40 -0
  76. package/src/fake-agent.ts +21 -4
  77. package/src/index.ts +26 -12
  78. package/src/machines/contract-kit.ts +648 -0
  79. package/src/machines/contract.ts +522 -0
  80. package/src/machines/sequencer.ts +1010 -0
  81. package/src/machines/simulation.ts +833 -0
  82. package/src/machines/work-machines.ts +231 -0
  83. package/src/server.ts +235 -150
  84. package/src/setup/machines.ts +128 -121
  85. package/src/shares/share-routes.ts +17 -1
  86. package/src/testing.ts +22 -0
  87. package/src/workers/disk-care.ts +121 -0
  88. package/src/workers/fake-claude-cli.ts +95 -0
  89. package/src/workers/fake-codex-cli.ts +11 -4
  90. package/src/workers/harness-sign-ins.ts +580 -0
  91. package/src/workers/machine-store.ts +1065 -0
  92. package/src/workers/member-machine-routes.ts +92 -20
  93. package/src/workers/member-machines.ts +163 -99
  94. package/src/workers/placement.ts +59 -70
  95. package/src/workers/sign-ins.ts +109 -52
  96. package/src/workers/worker-protocol.ts +5 -2
  97. package/src/workers/worker-registry.ts +894 -754
  98. package/src/workers/worker-routes.ts +4 -1
  99. package/src/workers/worker-runtime.ts +55 -23
  100. package/dist/test-support.d.ts +0 -133
  101. package/dist/test-support.d.ts.map +0 -1
  102. package/dist/workers/codex-sign-ins.d.ts +0 -107
  103. package/dist/workers/codex-sign-ins.d.ts.map +0 -1
  104. package/dist/workers/install-script.d.ts +0 -71
  105. package/dist/workers/install-script.d.ts.map +0 -1
  106. package/dist/workers/machine-classes.d.ts +0 -115
  107. package/dist/workers/machine-classes.d.ts.map +0 -1
  108. package/dist/workers/machine-rules.d.ts +0 -402
  109. package/dist/workers/machine-rules.d.ts.map +0 -1
  110. package/src/test-support.ts +0 -404
  111. package/src/workers/codex-sign-ins.ts +0 -360
  112. package/src/workers/install-script.ts +0 -394
  113. package/src/workers/machine-classes.ts +0 -152
  114. package/src/workers/machine-rules.ts +0 -1954
@@ -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
- /** Labels the Work server sets on every node itself (ADR 0167). */
5
- export const RESERVED_LABELS = ["node", "plane"] as const;
13
+ export { RESERVED_LABELS, servesNobody, servesOneOwner };
6
14
 
7
- export const NodeLabelsSchema = z
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
- * Whose work a worker takes: everyone, or named people and directory groups
24
- * by email, and the owner-less work (project chats and automations) of named
25
- * projects (ADR 0173), or nobody: a pooled machine no rule holds (ADR 0205).
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
- access: WorkerAccessSchema.default({ everyone: true }),
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
- * A worker's placement as the scheduler reads it. A released machine (ADR
59
- * 0205) takes no new work and keeps serving the Allocations it holds.
60
- */
61
- export type ScheduledPlacement = WorkerPlacement & { released: boolean };
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
- export function nodeAccess(access: WorkerAccess): NodeAccess {
64
- if ("everyone" in access) return { everyone: true };
65
- if ("nobody" in access) return { users: [], groups: [], projects: [] };
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
- users: access.people,
68
- groups: access.groups,
69
- projects: access.projects,
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
- * One named person, or one project's own work, and nobody else: no one
75
- * else's work lands here, so process isolation is enough.
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 function servesOneOwner(access: WorkerAccess): boolean {
78
- if ("everyone" in access || "nobody" in access) return false;
79
- const { people, groups, projects } = access;
80
- return groups.length === 0 && people.length + projects.length === 1;
81
- }
59
+ export type ScheduledPlacement = WorkerPlacement & {
60
+ accepting: boolean;
61
+ admissionRevision: string | null;
62
+ };
82
63
 
83
- /** A worker taking no one's work: any isolation is enough. */
84
- export function servesNobody(access: WorkerAccess): boolean {
85
- return "nobody" in access;
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
- /** The directory groups an access list names. */
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
- access: unknown;
85
+ serves: unknown;
97
86
  trusted: boolean;
98
87
  }): WorkerPlacement {
99
- return WorkerPlacementSchema.parse({
100
- labels: row.labels,
101
- access: row.access,
88
+ return {
89
+ labels: NodeLabelsSchema.parse(row.labels),
90
+ for: StoredPrincipals.parse(row.serves ?? null),
102
91
  trusted: row.trusted,
103
- });
92
+ };
104
93
  }
@@ -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, 0213). Each is
18
- * Codex's own home for one member under the machine's data directory, made
19
- * by Codex's own login on this machine. Work never reads, copies or sends
20
- * what is inside: the machine reports only who is signed in, and a sandbox
21
- * of that member's chat mounts their home. Claude Code subscriptions run
22
- * only on the member's own computer, so no machine holds one.
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
- /** The file a signed-in Codex home holds: its file credential store. */
35
- const CODEX_AUTH_FILE = "auth.json";
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 && fs.existsSync(path.join(home, CODEX_AUTH_FILE))
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 Codex sign-in at most (ADR 0213). */
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 Codex sign-in is on this machine, and a machine holds one person's only. Ask an administrator for a machine of your own",
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: one
71
- * machine signed in to several accounts reads to the provider as a shared
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
- * The `codex` to sign in with: the machine's own on `PATH`, else the one
99
- * this package carries (the version Work's Codex harness speaks), run with
100
- * this process's runtime. The image has no `codex` on its `PATH`.
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, "codex"), fs.constants.X_OK);
110
- return { command: "codex", args: [] };
112
+ fs.accessSync(path.join(directory, command), fs.constants.X_OK);
113
+ return true;
111
114
  } catch {
112
- // Not here.
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
- /** Codex's own login, pointed at one home. */
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 codex = codexCommand(input.env);
149
+ const spec = SIGN_IN_SPECS[input.harness];
150
+ const cli = harnessCommand(input.harness, input.env);
130
151
  return {
131
- command: codex.command,
132
- args: [...codex.args, "login", ...(input.args ?? [])],
133
- env: { CODEX_HOME: input.home },
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
- /** Codex keeps its sign-in in the home's own file, so a sandbox sees it. */
138
- const CODEX_FILE_STORE = 'cli_auth_credentials_store = "file"\n';
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
- fs.writeFileSync(path.join(staging, "config.toml"), CODEX_FILE_STORE, {
158
- mode: 0o600,
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 Codex's own login for a member, interactively, in this terminal.
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
- /** Passed to the login (`--device-auth` for a machine without a browser). */
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({ home: staging, args: input.args });
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: { ...process.env, ...login.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 || !fs.existsSync(path.join(staging, CODEX_AUTH_FILE))) {
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 Codex on this machine first.`,
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: 3,
21
- minimum: 3,
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. */