Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions .claude/orchestrator.json

Large diffs are not rendered by default.

17 changes: 12 additions & 5 deletions .claude/skills/orchestrate/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,12 @@ fatal to an unattended worker:
TUI is never sent to twice: it settles and re-reads instead, because a second send into a busy
worker is the ORB-75 corruption.

It also applies the model routing orchestrator.json's notes name: a ticket labelled
`worker:sonnet` swaps `--model opus` for `--model sonnet`; every other ticket uses the
configured args verbatim.
It also resolves model routing from the selected engine's `models` map in
orchestrator.json. No tier label selects `default`; `tier:cheap` and `tier:deep` select
the corresponding engine-specific entries. A tier must change the resolved invocation.
Unknown or conflicting tier labels, missing mappings, and identical tier invocations
fail the launch loudly. The legacy `worker:sonnet` label is rejected with remediation to
use `tier:cheap`; it is never silently translated or ignored.

**Why not `claude -p`.** Headless mode is invisible to Orca: it is not a TUI, so the
worktree card shows no Agents row and clicking the card reveals only a bare shell.
Expand Down Expand Up @@ -227,8 +230,12 @@ sandbox... Input disabled until setup completes" forever in a PTY with no deskto
UAC on, while `orca terminal wait` reports `satisfied: true` throughout. The prerequisite
the harness cannot supply is the account: a paid ChatGPT plan and `codex login`
(`codex login --device-auth` works from a headless session, printing a URL and a one-time
code). Making codex the DEFAULT is still a separate decision (D5) and Thomas's call; this
only makes selecting it work.
code). Its model map defaults to gpt-5.6-terra at medium reasoning, maps `tier:cheap` to
gpt-5.6-luna at low reasoning, and maps `tier:deep` to gpt-5.6-sol at high reasoning.
Terra is the routine default because D2 supplies a complete, validated ticket and the
delivery gates plus D9 bound executor risk; Sol stays available when deeper reasoning is
needed. Model routing does not change the top-level `worker` selection; D5 keeps that as
an explicit configuration decision.

Two consequences of dropping `-p`. The process does NOT exit when the work is done, so
wait with `--for tui-idle`, never `--for exit`. And the permission mode must still come
Expand Down
2 changes: 1 addition & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ While building or fixing, see something broken, stale, or wrong? Fix it immediat

## The workflow (D1-D9)

Linear is the source of truth for product work in this repo and orbit-api; GitHub Issues holds orbit-landing-page, infra chores, and Dependabot (D1). The ticket is the prompt (D2); one ticket = one repo = one reviewable PR, target under 400 lines (D4), and cross-repo work uses an API ticket blocking a UI ticket. The worker engine lives in `.claude/orchestrator.json` (D5); a `visible-effect` ticket needs final screenshots, a critique artifact, and test output before In Review (D7). `RENDER-CORRECTNESS.md` defines the bounded self-critique after capture. Invoke `tools/` scripts through their skills or agents; after `/next`, run `/orchestrate ORB-N --single`.
Linear is the source of truth for product work in this repo and orbit-api; GitHub Issues holds orbit-landing-page, infra chores, and Dependabot (D1). The ticket is the prompt (D2); one ticket = one repo = one reviewable PR, target under 400 lines (D4), and cross-repo work uses an API ticket blocking a UI ticket. The worker engine and its engine-specific model tiers live in `.claude/orchestrator.json` (D5); a `visible-effect` ticket needs final screenshots, a critique artifact, and test output before In Review (D7). `RENDER-CORRECTNESS.md` defines the bounded self-critique after capture. Invoke `tools/` scripts through their skills or agents; after `/next`, run `/orchestrate ORB-N --single`.

- `/feature`
- `/ticket`
Expand Down
1 change: 1 addition & 0 deletions tools/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Read `CONVENTIONS.md` before adding one. Use the `/make-tool` skill to scaffold
| `worker-status.mjs` | The mechanical answer to "is the worker actually done", because tui-idle means stopped, not finished. Derives the verdict from artifacts (commits above the freshly fetched `origin/<base>`, a clean worktree, the branch pushed, a PR open against the target, the issue In Review with the PR attached, an image attached when `visible-effect`, D7) and exits 1 listing exactly what is unmet. | `node tools/worker-status.mjs --worktree <path> --issue ORB-N` (`--base`, `--json`, `--help`) |
| `worker-watch.mjs` | The LIVENESS half of babysitting, alongside `worker-status.mjs`'s delivery verdict: for every Orca worktree in the Orbit repos, the ticket, branch, Linear state, BUSY or IDLE classified by repaint delta across two `terminal list` samples, the last meaningful output lines with TUI repaint noise stripped, and the contract verdict. Reports only; deciding what to send a stalled worker stays the orchestrator's judgement. Backs `/watch`. | `node tools/worker-watch.mjs` (`--repo`, `--lines`, `--no-contract`, `--json`, `--help`) |
| `pr-watch.mjs` | Polls one or more PRs until a state the caller has NOT already acted on and exits naming which transition fired (`gone`, `checks-failed`, `changes-requested`, `review-comment`, `approved`, `ready-to-merge`, `timeout`). A verdict counts only on the CURRENT head, so a stale review does not satisfy it, and `--acted` is the only thing that suppresses one: the terminal condition is "anything I have not handled", never an allowlist of remembered good states. Backs `/orchestrate` section 3. | `node tools/pr-watch.mjs --repo <owner/name> --pr <n> [--acted <n>=<sha>:<verdict>]` (`--once`, `--help`) |
| `lib/orchestrator-config.mjs` | Not a tool, the shared `.claude/orchestrator.json` reader and engine-neutral worker tier resolver. It maps `tier:cheap` and `tier:deep` through the selected engine, rejects legacy, unknown, conflicting, missing or unchanged mappings, and keeps config failures consistent across harness tools. | imported, never invoked |
| `lib/tui-repaint.mjs` | Not a tool, the one shared module: is this TUI mid-turn? Two `lastOutputAt` samples a window apart, since `--for tui-idle` reports satisfied on a working codex and the terminal text keeps stale output. Imported by `launch-worker.mjs`, `nudge-worker.mjs` and `worker-watch.mjs`; exercised through them. | imported, never invoked |
| `orca-web-port.mjs` | Assigns each linked Orca worktree a deterministic web port in the 3100-4099 window, detects a collision before persisting it, reports the assigned port, and starts Next on that port. The root checkout reports the unchanged default 3000. | `node tools/orca-web-port.mjs --setup` on worktree creation; `node tools/orca-web-port.mjs` to report; `npm run web` to start Next |

Expand Down
4 changes: 2 additions & 2 deletions tools/context-budget.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"bytes": 15381,
"bytes": 15416,
"files": {
"CLAUDE.md": 11998,
"CLAUDE.md": 12033,
".claude/rules/core.md": 3383
}
}
14 changes: 9 additions & 5 deletions tools/launch-worker.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { execFileSync, spawnSync } from "node:child_process"
import { appendFileSync, existsSync, readFileSync, statSync } from "node:fs"
import { basename, resolve } from "node:path"

import { readOrchestratorConfig, resolveWorkerInvocation } from "./lib/orchestrator-config.mjs"
import { SETTLE_MS, isRepainting, pause } from "./lib/tui-repaint.mjs"

const USAGE = `usage: launch-worker.mjs --issue ORB-N --prompt-file <path> [options]
Expand Down Expand Up @@ -348,9 +349,9 @@ if (statSync(promptFile).size === 0) fail(2, `prompt file is empty: ${promptFile

let config
try {
config = JSON.parse(readFileSync(new URL("../.claude/orchestrator.json", import.meta.url), "utf8"))
config = readOrchestratorConfig()
} catch (error) {
fail(2, `.claude/orchestrator.json could not be read as JSON: ${error.message}`)
fail(2, error.message)
}
const engineName = config.worker
const engine = config.workers?.[engineName]
Expand Down Expand Up @@ -399,9 +400,12 @@ const worktreeName = `${issue.toLowerCase()}-${slug}`
const branch = `${branchPrefix}/${worktreeName}`
const comment = argOf("--comment") ?? `${issue} launched: worker running`

/** Model routing: a worker:sonnet ticket swaps the configured opus for sonnet, nothing else. */
const wantsSonnet = labels.includes("worker:sonnet")
const engineArgs = engine.args.map((arg, index) => (wantsSonnet && engine.args[index - 1] === "--model" && arg === "opus" ? "sonnet" : arg))
let engineArgs
try {
engineArgs = resolveWorkerInvocation(engineName, engine, labels).args
} catch (error) {
fail(2, error.message)
}
const command = [engine.command, ...engineArgs].join(" ")

/**
Expand Down
91 changes: 91 additions & 0 deletions tools/lib/orchestrator-config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import { readFileSync } from "node:fs"

const isRecord = (value) => value !== null && typeof value === "object" && !Array.isArray(value)

const sameArgs = (first, second) =>
first.length === second.length && first.every((argument, index) => argument === second[index])

const modelEntry = (engineName, models, tier) => {
const entry = models[tier]
if (
!isRecord(entry) ||
typeof entry.model !== "string" ||
entry.model.trim().length === 0 ||
(entry.args !== undefined && (!Array.isArray(entry.args) || entry.args.some((argument) => typeof argument !== "string")))
) {
throw new Error(
`worker engine "${engineName}" has an invalid models.${tier} mapping; expected { model: string, args?: string[] }`,
)
}
return entry
}

const invocationFor = (baseArgs, entry) => [...baseArgs, ...(entry.args ?? []), "--model", entry.model]

export const readOrchestratorConfig = (
configUrl = new URL("../../.claude/orchestrator.json", import.meta.url),
) => {
try {
return JSON.parse(readFileSync(configUrl, "utf8"))
} catch (error) {
throw new Error(`.claude/orchestrator.json could not be read as JSON: ${error.message}`)
}
}

export const resolveWorkerInvocation = (engineName, engine, labels) => {
if (labels.includes("worker:sonnet")) {
throw new Error('worker:sonnet is no longer supported; replace it with "tier:cheap"')
}
if (!isRecord(engine)) {
throw new Error(`worker engine "${engineName}" is missing from .claude/orchestrator.json`)
}
if (
!Array.isArray(engine.args) ||
engine.args.some((argument) => typeof argument !== "string") ||
engine.args.some((argument) => argument === "--model" || argument === "-m" || argument.startsWith("--model="))
) {
throw new Error(`worker engine "${engineName}" must declare args as an array of non-model strings`)
}
if (!isRecord(engine.models) || !Object.hasOwn(engine.models, "default")) {
throw new Error(
`worker engine "${engineName}" has an invalid models.default mapping; expected { model: string, args?: string[] }`,
)
}
for (const requiredTier of ["cheap", "deep"]) {
if (!Object.hasOwn(engine.models, requiredTier)) {
throw new Error(`worker engine "${engineName}" is missing its models.${requiredTier} mapping`)
}
}

const declaredTiers = Object.keys(engine.models).filter((tier) => tier !== "default")
const entries = new Map(
["default", ...declaredTiers].map((tier) => [tier, modelEntry(engineName, engine.models, tier)]),
)
const tierLabels = [...new Set(labels.filter((label) => label.startsWith("tier:")))]
if (tierLabels.length > 1) {
throw new Error(`conflicting worker tier labels: ${tierLabels.join(", ")}`)
}

const tier = tierLabels[0]?.slice("tier:".length) ?? "default"
if (!entries.has(tier)) {
const available = declaredTiers.map((declaredTier) => `tier:${declaredTier}`).join(", ") || "none"
throw new Error(
`worker engine "${engineName}" does not declare tier:${tier}; declared tiers: ${available}`,
)
}

const cheapArgs = entries.has("cheap") ? invocationFor(engine.args, entries.get("cheap")) : null
const deepArgs = entries.has("deep") ? invocationFor(engine.args, entries.get("deep")) : null
if (cheapArgs && deepArgs && sameArgs(cheapArgs, deepArgs)) {
throw new Error(`worker engine "${engineName}" resolves tier:cheap and tier:deep to identical invocations`)
}

const args = invocationFor(engine.args, entries.get(tier))
const defaultArgs = invocationFor(engine.args, entries.get("default"))
if (tier !== "default" && sameArgs(args, defaultArgs)) {
throw new Error(
`worker engine "${engineName}" resolves tier:${tier} to the same invocation as its default model`,
)
}
return { tier, args }
}
18 changes: 8 additions & 10 deletions tools/nudge-worker.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { execFileSync, spawnSync } from "node:child_process"
import { appendFileSync, existsSync, readFileSync } from "node:fs"
import { resolve } from "node:path"

import { readOrchestratorConfig } from "./lib/orchestrator-config.mjs"
import { SETTLE_MS, isRepainting, pause } from "./lib/tui-repaint.mjs"

const USAGE = `usage: nudge-worker.mjs --terminal <handle> (--text "<one line>" | --prompt-file <path> < update.md)
Expand Down Expand Up @@ -75,14 +76,6 @@ const argOf = (flag) => {
return index === -1 ? null : process.argv[index + 1]
}

const readOrchestratorConfig = () => {
try {
return { config: JSON.parse(readFileSync(new URL("../.claude/orchestrator.json", import.meta.url), "utf8")), error: null }
} catch (error) {
return { config: null, error: error.message }
}
}

/** orca prints its `ok: false` payload on STDOUT and leaves stderr empty, so a failed call whose
* reason is only read off stderr reports "Command failed" and nothing else. Read stdout first. */
const orcaFailureReason = (error) => {
Expand Down Expand Up @@ -172,7 +165,12 @@ if (promptFileArg && textArg) fail(2, "--prompt-file and --text are alternatives
if (!Number.isInteger(waitAttemptsAllowed) || waitAttemptsAllowed < 1) fail(2, "--wait-attempts must be a positive integer")
if (textArg && /[\r\n]/.test(textArg)) fail(2, "--text must be a single line; append the long form to the prompt file instead")

const orchestrator = readOrchestratorConfig()
let orchestrator
try {
orchestrator = { config: readOrchestratorConfig(), error: null }
} catch (error) {
orchestrator = { config: null, error: error.message }
}
const engineSource = engineOverridePresent ? "--engine" : ".claude/orchestrator.json worker"
const engineValue = engineOverridePresent ? engineOverride : orchestrator.config?.worker
const normalizedEngine = typeof engineValue === "string" ? engineValue.trim().toLowerCase() : ""
Expand Down Expand Up @@ -236,7 +234,7 @@ let update = ""
if (promptFileArg) {
promptFile = resolve(promptFileArg)
if (!existsSync(promptFile)) fail(2, `prompt file not found: ${promptFile}`)
if (!orchestrator.config) fail(2, `.claude/orchestrator.json could not be read as JSON: ${orchestrator.error}`)
if (!orchestrator.config) fail(2, orchestrator.error)
const repos = orchestrator.config.repos
const normalize = (path) => path.replaceAll("\\", "/").replace(/\/+$/, "").toLowerCase()
for (const [key, path] of Object.entries(repos ?? {})) {
Expand Down
Loading
Loading