@chankov/agent-fleet 0.0.2 → 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.
Files changed (47) hide show
  1. package/.claude/commands/doctor-agent-fleet.md +1 -1
  2. package/.claude/commands/setup-agent-fleet.md +4 -4
  3. package/.opencode/commands/af-doctor-agent-fleet.md +2 -0
  4. package/.opencode/commands/af-setup-agent-fleet.md +1 -1
  5. package/.pi/agents/peers.yaml +4 -0
  6. package/.pi/agents/teams.yaml +2 -2
  7. package/.pi/harnesses/agent-hub/README.md +57 -4
  8. package/.pi/harnesses/agent-hub/index.ts +236 -80
  9. package/.pi/harnesses/agent-hub/research-retention.js +34 -0
  10. package/.pi/harnesses/ask-user-remote/README.md +2 -0
  11. package/.pi/harnesses/coms/README.md +11 -0
  12. package/.pi/prompts/doctor-agent-fleet.md +1 -1
  13. package/.pi/prompts/setup-agent-fleet.md +4 -4
  14. package/README.md +102 -540
  15. package/agents/architect.md +1 -1
  16. package/agents/planner.md +1 -1
  17. package/agents/security-auditor.md +1 -1
  18. package/bin/snapshot-version.js +17 -1
  19. package/codex/CONDUCTOR.md +148 -0
  20. package/docs/ARCHITECTURE.md +165 -0
  21. package/docs/agent-fleet-setup.md +1 -0
  22. package/docs/claude-code-coms-bridge.md +10 -0
  23. package/docs/codex-remote-conductor.md +170 -0
  24. package/docs/coms-hermes-bridge.md +121 -0
  25. package/docs/getting-started.md +14 -0
  26. package/docs/npm-install.md +2 -0
  27. package/docs/pi-setup.md +2 -0
  28. package/hermes/README.md +48 -0
  29. package/hermes/skills/hub-conductor/SKILL.md +84 -0
  30. package/hermes/skills/hub-liaison/SKILL.md +84 -0
  31. package/justfile +100 -13
  32. package/package.json +10 -3
  33. package/scripts/codex-conductor.ts +41 -0
  34. package/scripts/codex-remote-control.ts +167 -0
  35. package/scripts/coms-cli.ts +311 -199
  36. package/scripts/coms-hermes-bridge.ts +2 -2
  37. package/scripts/lib/codex-conductor.ts +88 -0
  38. package/scripts/lib/codex-remote-control.ts +480 -0
  39. package/scripts/lib/coms-envelope.ts +51 -6
  40. package/scripts/lib/herdr-layout.ts +18 -3
  41. package/scripts/lib/hermes-bridge-core.ts +4 -4
  42. package/scripts/lib/team-project.ts +85 -1
  43. package/scripts/team-up.ts +77 -18
  44. package/skills/guided-workspace-setup/SKILL.md +123 -97
  45. package/skills/guided-workspace-setup/companion-manifest.json +33 -0
  46. package/skills/peer-coms/SKILL.md +9 -0
  47. package/systemd/user/agent-fleet-codex-remote-control.service.in +23 -0
@@ -19,6 +19,35 @@ export const COMS_DIR = process.env.PI_COMS_DIR || path.join(os.homedir(), ".pi"
19
19
  export const MAX_HOPS = Number(process.env.PI_COMS_MAX_HOPS) || 5;
20
20
  export const DEFAULT_TIMEOUT_MS = Number(process.env.PI_COMS_TIMEOUT_MS) || 1_800_000;
21
21
  const LINE_CAP_BYTES = 64 * 1024;
22
+ // Pi peers refresh heartbeat_at every 30 seconds. A fresh heartbeat is the
23
+ // portable liveness signal for callers inside a sandbox/PID namespace, where
24
+ // process.kill(pid, 0) can incorrectly report a live host peer as ESRCH.
25
+ const REGISTRY_HEARTBEAT_FRESH_MS = 90_000;
26
+
27
+ // Registry paths are shared by every coms participant. Keep their components
28
+ // conservative so callers cannot escape the project/name directory structure.
29
+ export const COMS_PROJECT_SAFE = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
30
+ export const COMS_NAME_SAFE = /^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$/;
31
+
32
+ export function validateComsProject(project: string): string {
33
+ if (
34
+ project.length === 0 ||
35
+ project === "." ||
36
+ project.includes("..") ||
37
+ project.includes("/") ||
38
+ project.includes("\\") ||
39
+ !COMS_PROJECT_SAFE.test(project)
40
+ ) {
41
+ throw new Error(`Invalid project name: ${JSON.stringify(project)}`);
42
+ }
43
+ return project;
44
+ }
45
+
46
+ export function validateComsName(name: string): string {
47
+ if (!COMS_NAME_SAFE.test(name)) throw new Error(`Invalid coms name: ${JSON.stringify(name)}`);
48
+ if (name === "projects") throw new Error(`Invalid reserved coms name: ${JSON.stringify(name)}`);
49
+ return name;
50
+ }
22
51
 
23
52
  // ━━ Envelope shapes (mirror coms/index.ts) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
24
53
 
@@ -221,11 +250,11 @@ export function isCancelEnvelope(obj: unknown): obj is CancelEnvelope {
221
250
  // ━━ Registry I/O (mirrors coms/index.ts semantics) ━━━━━━━━━━━━━━━━━━━━━━━━
222
251
 
223
252
  export function projectAgentsDir(project: string): string {
224
- return path.join(COMS_DIR, "projects", project, "agents");
253
+ return path.join(COMS_DIR, "projects", validateComsProject(project), "agents");
225
254
  }
226
255
 
227
256
  export function registryFilePath(project: string, name: string): string {
228
- return path.join(projectAgentsDir(project), `${name}.json`);
257
+ return path.join(projectAgentsDir(project), `${validateComsName(name)}.json`);
229
258
  }
230
259
 
231
260
  export function ensureComsDirs(project: string): void {
@@ -241,6 +270,7 @@ export function ensureComsDirs(project: string): void {
241
270
  }
242
271
 
243
272
  export function writeRegistryAtomic(entry: RegistryEntry, project: string): string {
273
+ validateComsName(entry.name);
244
274
  const file = registryFilePath(project, entry.name);
245
275
  const tmp = `${file}.tmp-${process.pid}-${Date.now()}`;
246
276
  fs.writeFileSync(tmp, JSON.stringify(entry, null, 2));
@@ -261,8 +291,9 @@ export function readAllRegistryEntries(project: string): RegistryEntry[] {
261
291
  let files: string[];
262
292
  try {
263
293
  files = fs.readdirSync(dir).filter((f) => f.endsWith(".json"));
264
- } catch {
265
- return [];
294
+ } catch (error) {
295
+ if ((error as NodeJS.ErrnoException).code === "ENOENT") return [];
296
+ throw new Error(`Unable to read coms registry ${dir}: ${(error as NodeJS.ErrnoException).code ?? "unknown error"}`);
266
297
  }
267
298
  const out: RegistryEntry[] = [];
268
299
  for (const f of files) {
@@ -276,11 +307,24 @@ export function readAllRegistryEntries(project: string): RegistryEntry[] {
276
307
  return out;
277
308
  }
278
309
 
279
- // Same liveness rule as the coms harness: ESRCH removes the entry, EPERM
280
- // counts as live.
310
+ export function registryHeartbeatIsFresh(entry: RegistryEntry, now = Date.now()): boolean {
311
+ if (!entry.heartbeat_at) return false;
312
+ const heartbeat = Date.parse(entry.heartbeat_at);
313
+ if (!Number.isFinite(heartbeat)) return false;
314
+ const age = now - heartbeat;
315
+ return age >= -5_000 && age <= REGISTRY_HEARTBEAT_FRESH_MS;
316
+ }
317
+
318
+ // A fresh heartbeat wins before the PID probe because Codex remote commands
319
+ // can execute in a distinct PID namespace. For entries without a fresh
320
+ // heartbeat, preserve the harness rule: ESRCH removes; EPERM counts as live.
281
321
  export function pruneDeadEntries(project: string): RegistryEntry[] {
282
322
  const live: RegistryEntry[] = [];
283
323
  for (const entry of readAllRegistryEntries(project)) {
324
+ if (registryHeartbeatIsFresh(entry)) {
325
+ live.push(entry);
326
+ continue;
327
+ }
284
328
  try {
285
329
  process.kill(entry.pid, 0);
286
330
  live.push(entry);
@@ -296,6 +340,7 @@ export function pruneDeadEntries(project: string): RegistryEntry[] {
296
340
  }
297
341
 
298
342
  export function resolveUniqueName(project: string, desiredName: string): string {
343
+ validateComsName(desiredName);
299
344
  const liveNames = new Set(pruneDeadEntries(project).map((e) => e.name));
300
345
  if (!liveNames.has(desiredName)) return desiredName;
301
346
  let n = 2;
@@ -186,7 +186,7 @@ export interface TeamLayoutOptions {
186
186
  // existing argv shapes; non-default projects are appended to hidden recipe
187
187
  // positional args after model/session.
188
188
  project?: string;
189
- hub?: { command: string[]; label: string; ratio?: number };
189
+ hub?: { command: string[]; label: string; ratio?: number; cwd?: string; env?: Record<string, string> };
190
190
  }
191
191
 
192
192
  function paneNode(
@@ -234,7 +234,16 @@ function bsp(nodes: LayoutNode[], depth: number): LayoutNode {
234
234
  export function buildTeamLayout(opts: TeamLayoutOptions): LayoutNode {
235
235
  const { team, peers, repoRoot, envForPeer, resumeForPeer, delayForPeer, hub, project = DEFAULT_PROJECT } = opts;
236
236
  validateProject(project);
237
- if (peers.length === 0) throw new Error(`Team "${team}" has no peers.`);
237
+ if (peers.length === 0) {
238
+ if (!hub) throw new Error(`Team "${team}" has no peers.`);
239
+ return {
240
+ type: "pane",
241
+ command: hub.command,
242
+ cwd: hub.cwd ?? repoRoot,
243
+ label: hub.label,
244
+ ...(hub.env && Object.keys(hub.env).length > 0 ? { env: hub.env } : {}),
245
+ };
246
+ }
238
247
  const panes = peers.map((p) => paneNode(p, team, repoRoot, envForPeer, resumeForPeer, project, delayForPeer));
239
248
  const grid = bsp(panes, hub ? 1 : 0);
240
249
  if (!hub) return grid;
@@ -242,7 +251,13 @@ export function buildTeamLayout(opts: TeamLayoutOptions): LayoutNode {
242
251
  type: "split",
243
252
  direction: "right",
244
253
  ratio: hub.ratio ?? 0.4,
245
- first: { type: "pane", command: hub.command, cwd: repoRoot, label: hub.label },
254
+ first: {
255
+ type: "pane",
256
+ command: hub.command,
257
+ cwd: hub.cwd ?? repoRoot,
258
+ label: hub.label,
259
+ ...(hub.env && Object.keys(hub.env).length > 0 ? { env: hub.env } : {}),
260
+ },
246
261
  second: grid,
247
262
  };
248
263
  }
@@ -117,9 +117,9 @@ export function formatTelegramQuestion(input: HermesBridgeQuestion, limit = TELE
117
117
  if (!isValidQid(input.qid)) throw new Error("qid must be a 26-character Crockford ULID");
118
118
  const options = input.options ?? [];
119
119
  const header = `❓ [${HUB_Q_PREFIX}:${input.qid}] ${input.question}`;
120
- const optionsBlock = options.length > 0 ? `\n\nОпции:\n${formatOptions(options)}` : "";
121
- const instruction = `\n\n↩ Отговори с reply на това съобщение, или напиши: ${HUB_Q_PREFIX}:${input.qid}: <отговор>`;
122
- const contextPrefix = input.context ? "\n\nКонтекст: " : "";
120
+ const optionsBlock = options.length > 0 ? `\n\nOptions:\n${formatOptions(options)}` : "";
121
+ const instruction = `\n\n↩ Reply to this message, or type: ${HUB_Q_PREFIX}:${input.qid}: <answer>`;
122
+ const contextPrefix = input.context ? "\n\nContext: " : "";
123
123
  const fixedLength = header.length + contextPrefix.length + optionsBlock.length + instruction.length;
124
124
  const contextBudget = Math.max(0, limit - fixedLength);
125
125
  const context = input.context ? truncateUtf16(input.context, contextBudget) : "";
@@ -199,7 +199,7 @@ export function timeoutErrorMessage(timeoutMs: number): string {
199
199
  }
200
200
 
201
201
  export function timeoutTelegramNote(qid: string, timeoutMs: number): string {
202
- return `⌛ [${HUB_Q_PREFIX}:${qid}] Въпросът изтече след ${timeoutMs}ms.`;
202
+ return `⌛ [${HUB_Q_PREFIX}:${qid}] The question timed out after ${timeoutMs}ms.`;
203
203
  }
204
204
 
205
205
  export function timeoutOutcome(qid: string, timeoutMs = timeoutMsFromEnv()): {
@@ -4,6 +4,7 @@
4
4
  // already isolates peers by --project; this file only keeps team workspace
5
5
  // labels, snapshot files, and generated launch argv in sync with that scope.
6
6
 
7
+ import * as os from "node:os";
7
8
  import * as path from "node:path";
8
9
 
9
10
  export const DEFAULT_PROJECT = "default";
@@ -13,6 +14,32 @@ export const DEFAULT_PROJECT = "default";
13
14
  // like "acme.prod", but ".." is not allowed anywhere.
14
15
  export const PROJECT_SAFE = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
15
16
  export const TEAM_SAFE = /^[A-Za-z0-9_-]+$/;
17
+ export const CODEX_CONTRACT_IDENTITY = "agent-fleet-codex-conductor-pilot-v1";
18
+ export const DEFAULT_CODEX_TIMEOUT_MS = 300_000;
19
+
20
+ export type ConductorBackend = "hermes" | "codex";
21
+ export type WorkspaceMode = "peers" | "hub" | "conductor-hermes" | "conductor-codex";
22
+
23
+ export interface ConductorSpec {
24
+ backend: ConductorBackend;
25
+ workspaceMode: Extract<WorkspaceMode, `conductor-${string}`>;
26
+ paneLabel: string;
27
+ command: string[];
28
+ cwd: string;
29
+ env: Record<string, string>;
30
+ ratio: number;
31
+ displayText: string;
32
+ expectedServiceScope: "none" | "agent-fleet-codex-remote-control.service";
33
+ conductorName: string;
34
+ team: string;
35
+ }
36
+
37
+ function validateAbsoluteRepoRoot(repoRoot: string): string {
38
+ if (!path.isAbsolute(repoRoot) || path.resolve(repoRoot) !== repoRoot || repoRoot.includes("..")) {
39
+ throw new Error(`Invalid absolute repository root: ${JSON.stringify(repoRoot)}`);
40
+ }
41
+ return repoRoot;
42
+ }
16
43
 
17
44
  export function validateProject(project: string): string {
18
45
  if (
@@ -71,7 +98,7 @@ export function parseProjectFlag(argv: string[]): string {
71
98
  // on a shared `pi-hub-<team>`. Pass `tag` from worktreeTag(REPO_ROOT); it
72
99
  // defaults to "repo" only for callers that have no checkout in hand.
73
100
  export function teamWorkspaceLabel(
74
- kind: "peers" | "hub" | "conductor",
101
+ kind: WorkspaceMode,
75
102
  team: string,
76
103
  project = DEFAULT_PROJECT,
77
104
  tag = "repo",
@@ -91,6 +118,63 @@ export function conductorCommand(): string[] {
91
118
  return ["hermes", "-p", "dev"];
92
119
  }
93
120
 
121
+ export function conductorSpec(
122
+ backend: ConductorBackend,
123
+ input: { repoRoot: string; runtimeDir?: string; team: string; project?: string; nodeBin?: string },
124
+ ): ConductorSpec {
125
+ const repoRoot = validateAbsoluteRepoRoot(input.repoRoot);
126
+ const team = validateTeamName(input.team);
127
+ const project = validateProject(input.project ?? DEFAULT_PROJECT);
128
+ const conductorName = `${backend}-${team}-conductor`;
129
+ if (backend === "hermes") {
130
+ return {
131
+ backend,
132
+ workspaceMode: "conductor-hermes",
133
+ paneLabel: "conductor-hermes",
134
+ command: conductorCommand(),
135
+ cwd: repoRoot,
136
+ env: {},
137
+ ratio: 0.35,
138
+ displayText: "Hermes conductor; no herdr control",
139
+ expectedServiceScope: "none",
140
+ conductorName,
141
+ team,
142
+ };
143
+ }
144
+ const runtimeDir = input.runtimeDir ?? path.join(os.homedir(), ".local", "state", "agent-fleet", "codex-conductor");
145
+ if (!path.isAbsolute(runtimeDir) || path.resolve(runtimeDir) !== runtimeDir) {
146
+ throw new Error(`Codex conductor requires an absolute runtime directory: ${JSON.stringify(runtimeDir)}`);
147
+ }
148
+ const relativeRuntime = path.relative(repoRoot, runtimeDir);
149
+ if (relativeRuntime === "" || (!relativeRuntime.startsWith("..") && !path.isAbsolute(relativeRuntime))) {
150
+ throw new Error("Codex conductor requires a runtime directory outside repoRoot");
151
+ }
152
+ const workspaceDir = path.join(runtimeDir, "workspace");
153
+ const nodeBin = input.nodeBin ?? process.execPath;
154
+ if (!path.isAbsolute(nodeBin)) throw new Error(`Codex conductor requires an absolute Node binary path: ${JSON.stringify(nodeBin)}`);
155
+ return {
156
+ backend,
157
+ workspaceMode: "conductor-codex",
158
+ paneLabel: "conductor-codex-control",
159
+ command: [nodeBin, "--experimental-strip-types", path.join(repoRoot, "scripts", "codex-remote-control.ts"), "control-pane"],
160
+ cwd: workspaceDir,
161
+ env: {
162
+ AGENT_FLEET_REPO_ROOT: repoRoot,
163
+ COMS_CLI_PROJECT: project,
164
+ COMS_CLI_NAME: conductorName,
165
+ COMS_CLI_TIMEOUT_MS: String(DEFAULT_CODEX_TIMEOUT_MS),
166
+ AGENT_FLEET_CODEX_CONTRACT_PATH: path.join(workspaceDir, "AGENTS.md"),
167
+ AGENT_FLEET_CODEX_CONTRACT_IDENTITY: CODEX_CONTRACT_IDENTITY,
168
+ AGENT_FLEET_CONDUCTOR_BACKEND: "codex",
169
+ },
170
+ ratio: 0.35,
171
+ displayText: "Codex control pane; requested systemd state only",
172
+ expectedServiceScope: "agent-fleet-codex-remote-control.service",
173
+ conductorName,
174
+ team,
175
+ };
176
+ }
177
+
94
178
  export function teamSnapshotPath(snapshotDir: string, team: string, project = DEFAULT_PROJECT): string {
95
179
  validateTeamName(team);
96
180
  validateProject(project);
@@ -35,10 +35,20 @@ import {
35
35
  type Peer,
36
36
  } from "./lib/herdr-layout.ts";
37
37
  import { planSpawnDelays } from "./lib/spawn-stagger.ts";
38
- import { DEFAULT_PROJECT, conductorCommand, hubCommand, parseProjectFlag, teamWorkspaceLabel, validateTeamName, worktreeTag } from "./lib/team-project.ts";
38
+ import {
39
+ DEFAULT_PROJECT,
40
+ conductorSpec,
41
+ hubCommand,
42
+ parseProjectFlag,
43
+ teamWorkspaceLabel,
44
+ validateTeamName,
45
+ worktreeTag,
46
+ type ConductorBackend,
47
+ type ConductorSpec,
48
+ } from "./lib/team-project.ts";
39
49
 
40
50
  const SCRIPT_DIR = path.dirname(fileURLToPath(import.meta.url));
41
- const REPO_ROOT = path.resolve(SCRIPT_DIR, "..");
51
+ const REPO_ROOT = fs.realpathSync(path.resolve(SCRIPT_DIR, ".."));
42
52
  // Scopes the workspace label to this checkout so the same team from another
43
53
  // repo/worktree gets its own workspace instead of colliding (see worktreeTag).
44
54
  const WORKTREE_TAG = worktreeTag(REPO_ROOT);
@@ -47,7 +57,6 @@ const DEFAULT_PEERS_YAML = path.join(REPO_ROOT, ".pi", "agents", "peers.yaml");
47
57
  // The guarded hub or Hermes conductor occupies this share of the workspace in
48
58
  // --hub/--conductor mode; the team tiles in the rest.
49
59
  const HUB_RATIO = 0.4;
50
- const CONDUCTOR_RATIO = 0.35;
51
60
 
52
61
  function flagValue(argv: string[], flag: string): string | null {
53
62
  const i = argv.indexOf(flag);
@@ -62,6 +71,16 @@ function die(msg: string): never {
62
71
  process.exit(1);
63
72
  }
64
73
 
74
+ function parseConductorBackend(argv: string[]): ConductorBackend | null {
75
+ const indexes = argv.flatMap((value, index) => value === "--conductor" ? [index] : []);
76
+ if (indexes.length > 1) throw new Error("--conductor may only be provided once");
77
+ if (indexes.length === 0) return null;
78
+ const value = argv[indexes[0] + 1];
79
+ if (!value || value.startsWith("--")) return "hermes"; // legacy bare --conductor
80
+ if (value === "hermes" || value === "codex") return value;
81
+ throw new Error(`Unknown conductor backend: ${JSON.stringify(value)} (expected hermes or codex)`);
82
+ }
83
+
65
84
  function loadTeam(team: string, peersYaml: string): Peer[] {
66
85
  if (!fs.existsSync(peersYaml)) die(`peers.yaml not found at ${peersYaml}`);
67
86
  const teams = parsePeersYaml(fs.readFileSync(peersYaml, "utf-8"));
@@ -70,7 +89,6 @@ function loadTeam(team: string, peersYaml: string): Peer[] {
70
89
  const names = Object.keys(teams).join(", ") || "(none)";
71
90
  die(`Unknown team "${team}". Available teams: ${names}`);
72
91
  }
73
- if (peers.length === 0) die(`Team "${team}" has no peers.`);
74
92
  return peers;
75
93
  }
76
94
 
@@ -128,20 +146,38 @@ function makeDelayLoader(peers: Peer[], mode: "peers" | "hub" | "conductor"): (p
128
146
  return delayForPeer;
129
147
  }
130
148
 
149
+ async function validateCodexLaunchOrDie(spec: ConductorSpec, project: string): Promise<void> {
150
+ try {
151
+ const { assertConductorContext, lifecyclePaths, loadOwnedConfig, preflight, requestedState } = await import("./lib/codex-remote-control.ts");
152
+ const config = loadOwnedConfig(lifecyclePaths().configPath);
153
+ assertConductorContext(config, {
154
+ repoRoot: REPO_ROOT,
155
+ project,
156
+ team: spec.team,
157
+ name: spec.conductorName,
158
+ timeoutMs: Number(spec.env.COMS_CLI_TIMEOUT_MS),
159
+ contractPath: String(spec.env.AGENT_FLEET_CODEX_CONTRACT_PATH),
160
+ contractIdentity: String(spec.env.AGENT_FLEET_CODEX_CONTRACT_IDENTITY),
161
+ });
162
+ preflight(config);
163
+ const state = requestedState();
164
+ if (state.active !== "active" || state.sub !== "exited") {
165
+ throw new Error(`Codex user service is not in requested active (exited) state: ${state.active} (${state.sub})`);
166
+ }
167
+ } catch (err) {
168
+ die(`Codex launch refused before Herdr: ${err instanceof Error ? err.message : String(err)}`);
169
+ }
170
+ }
171
+
131
172
  function buildLayoutOrDie(
132
173
  team: string,
133
174
  peers: Peer[],
134
175
  envForPeer: (p: Peer) => Record<string, string> | undefined,
135
- mode: "peers" | "hub" | "conductor",
136
176
  project: string,
177
+ rootPane?: { command: string[]; label: string; ratio: number; cwd?: string; env?: Record<string, string> },
137
178
  delayForPeer?: (p: Peer) => number | undefined,
138
179
  ): LayoutNode {
139
180
  try {
140
- const rootPane = mode === "hub"
141
- ? { command: hubCommand(project), label: "hub", ratio: HUB_RATIO }
142
- : mode === "conductor"
143
- ? { command: conductorCommand(), label: "conductor", ratio: CONDUCTOR_RATIO }
144
- : undefined;
145
181
  return buildTeamLayout({
146
182
  team,
147
183
  peers,
@@ -171,7 +207,12 @@ async function main(): Promise<void> {
171
207
  }
172
208
  const dryRun = argv.includes("--dry-run");
173
209
  const hub = argv.includes("--hub");
174
- const conductor = argv.includes("--conductor");
210
+ let conductor: ConductorBackend | null;
211
+ try {
212
+ conductor = parseConductorBackend(argv);
213
+ } catch (err) {
214
+ die(err instanceof Error ? err.message : String(err));
215
+ }
175
216
  if (hub && conductor) die("--hub and --conductor are mutually exclusive");
176
217
  const mode: "peers" | "hub" | "conductor" = hub ? "hub" : conductor ? "conductor" : "peers";
177
218
 
@@ -186,19 +227,35 @@ async function main(): Promise<void> {
186
227
  die(err instanceof Error ? err.message : String(err));
187
228
  }
188
229
  const peers = loadTeam(team, peersYaml);
230
+ if (peers.length === 0 && mode === "peers") {
231
+ die(`Team "${team}" has no peers. Empty teams require --hub or --conductor.`);
232
+ }
233
+ let spec: ConductorSpec | undefined;
189
234
  let label: string;
190
235
  try {
191
- label = teamWorkspaceLabel(mode, team, project, WORKTREE_TAG);
236
+ spec = conductor ? conductorSpec(conductor, {
237
+ repoRoot: REPO_ROOT,
238
+ runtimeDir: path.join(os.homedir(), ".local", "state", "agent-fleet", "codex-conductor"),
239
+ team,
240
+ project,
241
+ nodeBin: process.execPath,
242
+ }) : undefined;
243
+ label = teamWorkspaceLabel(spec?.workspaceMode ?? (hub ? "hub" : "peers"), team, project, WORKTREE_TAG);
192
244
  } catch (err) {
193
245
  die(err instanceof Error ? err.message : String(err));
194
246
  }
247
+ const rootPane = hub
248
+ ? { command: hubCommand(project), label: "hub", ratio: HUB_RATIO }
249
+ : spec
250
+ ? { command: spec.command, label: spec.paneLabel, ratio: spec.ratio, cwd: spec.cwd, env: spec.env }
251
+ : undefined;
195
252
 
196
253
  if (dryRun) {
197
254
  // No herdr calls and no env_file reads on this path — must work with no
198
255
  // herdr installed, and secrets never reach the output.
199
- const layout = buildLayoutOrDie(team, peers, makeEnvLoader(peers, true), mode, project);
256
+ const layout = buildLayoutOrDie(team, peers, makeEnvLoader(peers, true), project, rootPane);
200
257
  const projectNote = project === DEFAULT_PROJECT ? "" : `, project "${project}"`;
201
- const extra = mode === "hub" ? " + hub" : mode === "conductor" ? " + conductor" : "";
258
+ const extra = mode === "hub" ? " + hub" : spec ? ` + ${spec.backend === "codex" ? "Codex conductor" : "Hermes conductor"}` : "";
202
259
  console.log(
203
260
  `# team-up (dry run) — team "${team}"${projectNote}, ${peers.length} peer(s)${extra}, herdr workspace "${label}"`,
204
261
  );
@@ -211,7 +268,8 @@ async function main(): Promise<void> {
211
268
  return;
212
269
  }
213
270
 
214
- const layout = buildLayoutOrDie(team, peers, makeEnvLoader(peers, false), mode, project, makeDelayLoader(peers, mode));
271
+ if (spec?.backend === "codex") await validateCodexLaunchOrDie(spec, project);
272
+ const layout = buildLayoutOrDie(team, peers, makeEnvLoader(peers, false), project, rootPane, makeDelayLoader(peers, mode));
215
273
 
216
274
  // Import lazily so --dry-run never touches the client (or the socket).
217
275
  const { herdr, requireHerdr, HerdrUnavailableError } = await import(
@@ -223,7 +281,7 @@ async function main(): Promise<void> {
223
281
  } catch (err) {
224
282
  if (err instanceof HerdrUnavailableError) {
225
283
  console.error(err.message);
226
- const dryRecipe = mode === "hub" ? "hub-team-dry" : mode === "conductor" ? "conductor-dry" : "team-up-dry";
284
+ const dryRecipe = mode === "hub" ? "hub-team-dry" : spec?.backend === "codex" ? "conductor-codex-dry" : mode === "conductor" ? "conductor-dry" : "team-up-dry";
227
285
  console.error(`(dry run still works: just ${dryRecipe} ${team}${project === DEFAULT_PROJECT ? "" : ` --project ${project}`})`);
228
286
  process.exit(1);
229
287
  }
@@ -253,12 +311,13 @@ async function main(): Promise<void> {
253
311
  }
254
312
  }
255
313
 
256
- const launchedPrefix = mode === "hub" ? "hub + " : mode === "conductor" ? "conductor + " : "";
314
+ const launchedPrefix = mode === "hub" ? "hub + " : spec ? `${spec.backend} conductor + ` : "";
257
315
  console.log(
258
316
  `Launched ${launchedPrefix}${peers.length} peer(s) for team "${team}" in herdr workspace "${label}" (${wsId}):`,
259
317
  );
260
318
  if (mode === "hub") console.log(` • hub (${hubCommand(project).join(" ")} — guarded dispatcher)`);
261
- if (mode === "conductor") console.log(` • conductor (${conductorCommand().join(" ")} — Hermes conductor; no herdr control)`);
319
+ if (spec) console.log(` • ${spec.paneLabel} (${spec.command.join(" ")} — ${spec.displayText})`);
320
+ if (spec?.backend === "codex") console.log(" • Closing this workspace does not stop the enabled Codex user service; stop it explicitly.");
262
321
  for (const p of peers) console.log(` • ${p.name}`);
263
322
  console.log(`Focus: herdr workspace focus ${wsId}`);
264
323
  console.log(`Close: herdr workspace close ${wsId}`);