@chankov/agent-fleet 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.
Files changed (65) 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/model-profiles.yaml +12 -12
  6. package/.pi/agents/peers.yaml +26 -22
  7. package/.pi/agents/teams.yaml +2 -2
  8. package/.pi/harnesses/agent-hub/README.md +57 -4
  9. package/.pi/harnesses/agent-hub/index.ts +236 -80
  10. package/.pi/harnesses/agent-hub/research-retention.js +34 -0
  11. package/.pi/harnesses/ask-user-remote/README.md +8 -0
  12. package/.pi/harnesses/ask-user-remote/index.ts +41 -1
  13. package/.pi/harnesses/coms/README.md +11 -0
  14. package/.pi/prompts/doctor-agent-fleet.md +1 -1
  15. package/.pi/prompts/setup-agent-fleet.md +4 -4
  16. package/README.md +133 -354
  17. package/agents/architect.md +4 -2
  18. package/agents/bowser.md +2 -1
  19. package/agents/builder.md +3 -2
  20. package/agents/code-reviewer.md +7 -7
  21. package/agents/deep-researcher.md +3 -3
  22. package/agents/documenter.md +3 -1
  23. package/agents/orchestrator.md +5 -3
  24. package/agents/plan-reviewer.md +5 -5
  25. package/agents/planner.md +7 -7
  26. package/agents/releaser.md +3 -1
  27. package/agents/researcher.md +3 -3
  28. package/agents/security-auditor.md +7 -7
  29. package/agents/test-engineer.md +5 -5
  30. package/agents/web-debugger.md +3 -3
  31. package/agents/web-performance-auditor.md +3 -3
  32. package/bin/snapshot-version.js +17 -1
  33. package/codex/CONDUCTOR.md +148 -0
  34. package/docs/ARCHITECTURE.md +165 -0
  35. package/docs/agent-fleet-setup.md +1 -0
  36. package/docs/claude-code-coms-bridge.md +10 -0
  37. package/docs/codex-remote-conductor.md +170 -0
  38. package/docs/coms-hermes-bridge.md +121 -0
  39. package/docs/getting-started.md +14 -0
  40. package/docs/npm-install.md +2 -0
  41. package/docs/pi-extensions.md +16 -0
  42. package/docs/pi-setup.md +2 -0
  43. package/hermes/README.md +48 -0
  44. package/hermes/skills/hub-conductor/SKILL.md +84 -0
  45. package/hermes/skills/hub-liaison/SKILL.md +84 -0
  46. package/justfile +132 -15
  47. package/package.json +10 -3
  48. package/scripts/codex-conductor.ts +41 -0
  49. package/scripts/codex-remote-control.ts +167 -0
  50. package/scripts/coms-cli.ts +311 -199
  51. package/scripts/coms-hermes-bridge.ts +8 -4
  52. package/scripts/lib/codex-conductor.ts +88 -0
  53. package/scripts/lib/codex-remote-control.ts +480 -0
  54. package/scripts/lib/coms-envelope.ts +51 -6
  55. package/scripts/lib/herdr-layout.ts +35 -7
  56. package/scripts/lib/hermes-bridge-core.ts +4 -4
  57. package/scripts/lib/spawn-stagger.ts +101 -0
  58. package/scripts/lib/team-project.ts +112 -3
  59. package/scripts/lib/team-snapshot.ts +3 -2
  60. package/scripts/team-snapshot.ts +23 -6
  61. package/scripts/team-up.ts +106 -18
  62. package/skills/guided-workspace-setup/SKILL.md +123 -97
  63. package/skills/guided-workspace-setup/companion-manifest.json +33 -0
  64. package/skills/peer-coms/SKILL.md +9 -0
  65. package/systemd/user/agent-fleet-codex-remote-control.service.in +23 -0
@@ -22,6 +22,7 @@
22
22
  // - Never clobber an existing workspace of the same label; refuse and explain.
23
23
 
24
24
  import * as fs from "node:fs";
25
+ import * as os from "node:os";
25
26
  import * as path from "node:path";
26
27
  import { fileURLToPath } from "node:url";
27
28
 
@@ -33,16 +34,29 @@ import {
33
34
  type LayoutNode,
34
35
  type Peer,
35
36
  } from "./lib/herdr-layout.ts";
36
- import { DEFAULT_PROJECT, conductorCommand, hubCommand, parseProjectFlag, teamWorkspaceLabel, validateTeamName } from "./lib/team-project.ts";
37
+ import { planSpawnDelays } from "./lib/spawn-stagger.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";
37
49
 
38
50
  const SCRIPT_DIR = path.dirname(fileURLToPath(import.meta.url));
39
- const REPO_ROOT = path.resolve(SCRIPT_DIR, "..");
51
+ const REPO_ROOT = fs.realpathSync(path.resolve(SCRIPT_DIR, ".."));
52
+ // Scopes the workspace label to this checkout so the same team from another
53
+ // repo/worktree gets its own workspace instead of colliding (see worktreeTag).
54
+ const WORKTREE_TAG = worktreeTag(REPO_ROOT);
40
55
  const DEFAULT_PEERS_YAML = path.join(REPO_ROOT, ".pi", "agents", "peers.yaml");
41
56
 
42
57
  // The guarded hub or Hermes conductor occupies this share of the workspace in
43
58
  // --hub/--conductor mode; the team tiles in the rest.
44
59
  const HUB_RATIO = 0.4;
45
- const CONDUCTOR_RATIO = 0.35;
46
60
 
47
61
  function flagValue(argv: string[], flag: string): string | null {
48
62
  const i = argv.indexOf(flag);
@@ -57,6 +71,16 @@ function die(msg: string): never {
57
71
  process.exit(1);
58
72
  }
59
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
+
60
84
  function loadTeam(team: string, peersYaml: string): Peer[] {
61
85
  if (!fs.existsSync(peersYaml)) die(`peers.yaml not found at ${peersYaml}`);
62
86
  const teams = parsePeersYaml(fs.readFileSync(peersYaml, "utf-8"));
@@ -65,7 +89,6 @@ function loadTeam(team: string, peersYaml: string): Peer[] {
65
89
  const names = Object.keys(teams).join(", ") || "(none)";
66
90
  die(`Unknown team "${team}". Available teams: ${names}`);
67
91
  }
68
- if (peers.length === 0) die(`Team "${team}" has no peers.`);
69
92
  return peers;
70
93
  }
71
94
 
@@ -101,25 +124,67 @@ function makeEnvLoader(
101
124
  };
102
125
  }
103
126
 
127
+ // Pre-warm/stagger (see scripts/lib/spawn-stagger.ts): when auth.json holds a
128
+ // stale OAuth token, simultaneous pi boots race on its file lock and the
129
+ // losers come up with every provider "unconfigured". One pi pane (the hub
130
+ // when present, else the first pi peer) starts immediately and refreshes the
131
+ // token; the others get a small AGENT_FLEET_SPAWN_DELAY via pane env. The
132
+ // auth file is only read for `type`/`expires` — values never leave this
133
+ // process. Dry-run never reaches this (no live-state reads on that path).
134
+ function makeDelayLoader(peers: Peer[], mode: "peers" | "hub" | "conductor"): (peer: Peer) => number | undefined {
135
+ let raw: string | undefined;
136
+ try {
137
+ raw = fs.readFileSync(path.join(os.homedir(), ".pi", "agent", "auth.json"), "utf-8");
138
+ } catch {
139
+ raw = undefined;
140
+ }
141
+ // The conductor root is Hermes, not pi — the first pi peer warms instead.
142
+ const { needed, delayForPeer } = planSpawnDelays(peers, mode === "hub", raw);
143
+ if (needed) {
144
+ console.log("Stale pi OAuth token detected — staggering pane starts so one pane can refresh it first.");
145
+ }
146
+ return delayForPeer;
147
+ }
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
+
104
172
  function buildLayoutOrDie(
105
173
  team: string,
106
174
  peers: Peer[],
107
175
  envForPeer: (p: Peer) => Record<string, string> | undefined,
108
- mode: "peers" | "hub" | "conductor",
109
176
  project: string,
177
+ rootPane?: { command: string[]; label: string; ratio: number; cwd?: string; env?: Record<string, string> },
178
+ delayForPeer?: (p: Peer) => number | undefined,
110
179
  ): LayoutNode {
111
180
  try {
112
- const rootPane = mode === "hub"
113
- ? { command: hubCommand(project), label: "hub", ratio: HUB_RATIO }
114
- : mode === "conductor"
115
- ? { command: conductorCommand(), label: "conductor", ratio: CONDUCTOR_RATIO }
116
- : undefined;
117
181
  return buildTeamLayout({
118
182
  team,
119
183
  peers,
120
184
  repoRoot: REPO_ROOT,
121
185
  envForPeer,
122
186
  project,
187
+ ...(delayForPeer ? { delayForPeer } : {}),
123
188
  ...(rootPane ? { hub: rootPane } : {}),
124
189
  });
125
190
  } catch (err) {
@@ -142,7 +207,12 @@ async function main(): Promise<void> {
142
207
  }
143
208
  const dryRun = argv.includes("--dry-run");
144
209
  const hub = argv.includes("--hub");
145
- 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
+ }
146
216
  if (hub && conductor) die("--hub and --conductor are mutually exclusive");
147
217
  const mode: "peers" | "hub" | "conductor" = hub ? "hub" : conductor ? "conductor" : "peers";
148
218
 
@@ -157,19 +227,35 @@ async function main(): Promise<void> {
157
227
  die(err instanceof Error ? err.message : String(err));
158
228
  }
159
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;
160
234
  let label: string;
161
235
  try {
162
- label = teamWorkspaceLabel(mode, team, project);
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);
163
244
  } catch (err) {
164
245
  die(err instanceof Error ? err.message : String(err));
165
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;
166
252
 
167
253
  if (dryRun) {
168
254
  // No herdr calls and no env_file reads on this path — must work with no
169
255
  // herdr installed, and secrets never reach the output.
170
- const layout = buildLayoutOrDie(team, peers, makeEnvLoader(peers, true), mode, project);
256
+ const layout = buildLayoutOrDie(team, peers, makeEnvLoader(peers, true), project, rootPane);
171
257
  const projectNote = project === DEFAULT_PROJECT ? "" : `, project "${project}"`;
172
- const extra = mode === "hub" ? " + hub" : mode === "conductor" ? " + conductor" : "";
258
+ const extra = mode === "hub" ? " + hub" : spec ? ` + ${spec.backend === "codex" ? "Codex conductor" : "Hermes conductor"}` : "";
173
259
  console.log(
174
260
  `# team-up (dry run) — team "${team}"${projectNote}, ${peers.length} peer(s)${extra}, herdr workspace "${label}"`,
175
261
  );
@@ -182,7 +268,8 @@ async function main(): Promise<void> {
182
268
  return;
183
269
  }
184
270
 
185
- const layout = buildLayoutOrDie(team, peers, makeEnvLoader(peers, false), mode, project);
271
+ if (spec?.backend === "codex") await validateCodexLaunchOrDie(spec, project);
272
+ const layout = buildLayoutOrDie(team, peers, makeEnvLoader(peers, false), project, rootPane, makeDelayLoader(peers, mode));
186
273
 
187
274
  // Import lazily so --dry-run never touches the client (or the socket).
188
275
  const { herdr, requireHerdr, HerdrUnavailableError } = await import(
@@ -194,7 +281,7 @@ async function main(): Promise<void> {
194
281
  } catch (err) {
195
282
  if (err instanceof HerdrUnavailableError) {
196
283
  console.error(err.message);
197
- 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";
198
285
  console.error(`(dry run still works: just ${dryRecipe} ${team}${project === DEFAULT_PROJECT ? "" : ` --project ${project}`})`);
199
286
  process.exit(1);
200
287
  }
@@ -224,12 +311,13 @@ async function main(): Promise<void> {
224
311
  }
225
312
  }
226
313
 
227
- const launchedPrefix = mode === "hub" ? "hub + " : mode === "conductor" ? "conductor + " : "";
314
+ const launchedPrefix = mode === "hub" ? "hub + " : spec ? `${spec.backend} conductor + ` : "";
228
315
  console.log(
229
316
  `Launched ${launchedPrefix}${peers.length} peer(s) for team "${team}" in herdr workspace "${label}" (${wsId}):`,
230
317
  );
231
318
  if (mode === "hub") console.log(` • hub (${hubCommand(project).join(" ")} — guarded dispatcher)`);
232
- 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.");
233
321
  for (const p of peers) console.log(` • ${p.name}`);
234
322
  console.log(`Focus: herdr workspace focus ${wsId}`);
235
323
  console.log(`Close: herdr workspace close ${wsId}`);