orca-flow 0.0.0-stage → 1.3.0
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/CHANGELOG.md +42 -0
- package/LICENSE +21 -0
- package/README.md +86 -2
- package/ROADMAP.md +83 -0
- package/bin/oflow.mjs +80 -0
- package/package.json +52 -4
- package/references/checklists/migrations.md +8 -0
- package/references/checklists/performance.md +8 -0
- package/references/checklists/security.md +9 -0
- package/references/checklists/ui-a11y.md +8 -0
- package/site/app.js +271 -0
- package/site/cinema.js +125 -0
- package/site/data.js +243 -0
- package/site/favicon.svg +14 -0
- package/site/i18n.js +86 -0
- package/site/index.html +306 -0
- package/site/motion.js +200 -0
- package/site/playbook.js +221 -0
- package/site/styles.css +244 -0
- package/skills/architecture/SKILL.md +17 -0
- package/skills/build-ticket/SKILL.md +29 -0
- package/skills/debug/SKILL.md +17 -0
- package/skills/grill-spec/SKILL.md +26 -0
- package/skills/lead-effort/SKILL.md +26 -0
- package/skills/proto-spike/SKILL.md +17 -0
- package/skills/resume/SKILL.md +26 -0
- package/skills/retro-guardrail/SKILL.md +19 -0
- package/skills/setup-project/SKILL.md +26 -0
- package/skills/slice-tickets/SKILL.md +31 -0
- package/skills/verify-app/SKILL.md +22 -0
- package/src/agents.mjs +278 -0
- package/src/checkpoint.mjs +160 -0
- package/src/config.mjs +140 -0
- package/src/doctor.mjs +190 -0
- package/src/gate.mjs +205 -0
- package/src/git.mjs +149 -0
- package/src/hook.mjs +168 -0
- package/src/init.mjs +149 -0
- package/src/install.mjs +192 -0
- package/src/lock.mjs +80 -0
- package/src/pr.mjs +120 -0
- package/src/review.mjs +254 -0
- package/src/seal.mjs +200 -0
- package/src/site-server.mjs +57 -0
- package/src/stats.mjs +257 -0
- package/src/status.mjs +234 -0
- package/src/tracker-github.mjs +196 -0
- package/src/wave.mjs +193 -0
- package/src/worker.mjs +297 -0
package/src/wave.mjs
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { globToRegExp, matchesAnyGlob } from "./git.mjs";
|
|
2
|
+
|
|
3
|
+
const WILDCARD_RE = /[*?]/;
|
|
4
|
+
|
|
5
|
+
function normalizeTouchPattern(raw) {
|
|
6
|
+
let clean = String(raw ?? "").trim().replace(/^[`"'()]+|[`"'()]+$/g, "");
|
|
7
|
+
clean = clean.replace(/\\/g, "/").replace(/\/+/g, "/").replace(/^\.\//, "").replace(/^\/+/, "");
|
|
8
|
+
if (!clean || /^(none|-|n\/a)$/i.test(clean)) return null;
|
|
9
|
+
if (clean.endsWith("/")) clean += "**";
|
|
10
|
+
return clean;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Parse comma- or whitespace-separated file/glob patterns from a ticket's Touches: field.
|
|
15
|
+
*/
|
|
16
|
+
export function parseTouches(raw) {
|
|
17
|
+
if (!raw || /^(none|-|n\/a)$/i.test(String(raw).trim())) return [];
|
|
18
|
+
const out = [];
|
|
19
|
+
for (const part of String(raw).split(/[,\s]+/)) {
|
|
20
|
+
const norm = normalizeTouchPattern(part);
|
|
21
|
+
if (norm && !out.includes(norm)) out.push(norm);
|
|
22
|
+
}
|
|
23
|
+
return out;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function segmentsCanOverlap(segA, segB) {
|
|
27
|
+
const wildA = WILDCARD_RE.test(segA);
|
|
28
|
+
const wildB = WILDCARD_RE.test(segB);
|
|
29
|
+
if (!wildA && !wildB) return segA === segB;
|
|
30
|
+
if (!wildA && wildB) return globToRegExp(segB).test(segA);
|
|
31
|
+
if (wildA && !wildB) return globToRegExp(segA).test(segB);
|
|
32
|
+
|
|
33
|
+
const firstA = segA.search(WILDCARD_RE);
|
|
34
|
+
const firstB = segB.search(WILDCARD_RE);
|
|
35
|
+
const lastA = Math.max(segA.lastIndexOf("*"), segA.lastIndexOf("?"));
|
|
36
|
+
const lastB = Math.max(segB.lastIndexOf("*"), segB.lastIndexOf("?"));
|
|
37
|
+
|
|
38
|
+
const prefixA = segA.slice(0, firstA);
|
|
39
|
+
const prefixB = segB.slice(0, firstB);
|
|
40
|
+
const suffixA = segA.slice(lastA + 1);
|
|
41
|
+
const suffixB = segB.slice(lastB + 1);
|
|
42
|
+
|
|
43
|
+
return (prefixA.startsWith(prefixB) || prefixB.startsWith(prefixA)) &&
|
|
44
|
+
(suffixA.endsWith(suffixB) || suffixB.endsWith(suffixA));
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function globSegmentsOverlap(segsA, segsB) {
|
|
48
|
+
const memo = new Map();
|
|
49
|
+
function match(i, j) {
|
|
50
|
+
if (i === segsA.length && j === segsB.length) return true;
|
|
51
|
+
const key = `${i}:${j}`;
|
|
52
|
+
if (memo.has(key)) return memo.get(key);
|
|
53
|
+
let res = false;
|
|
54
|
+
if (segsA[i] === "**") {
|
|
55
|
+
res = match(i + 1, j) || (j < segsB.length && match(i, j + 1));
|
|
56
|
+
} else if (segsB[j] === "**") {
|
|
57
|
+
res = match(i, j + 1) || (i < segsA.length && match(i + 1, j));
|
|
58
|
+
} else if (i < segsA.length && j < segsB.length && segmentsCanOverlap(segsA[i], segsB[j])) {
|
|
59
|
+
res = match(i + 1, j + 1);
|
|
60
|
+
}
|
|
61
|
+
memo.set(key, res);
|
|
62
|
+
return res;
|
|
63
|
+
}
|
|
64
|
+
return match(0, 0);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Determine whether two normalized path/glob patterns can match any common file path.
|
|
69
|
+
*/
|
|
70
|
+
export function patternsOverlap(patA, patB, trackedFiles = []) {
|
|
71
|
+
const a = normalizeTouchPattern(patA);
|
|
72
|
+
const b = normalizeTouchPattern(patB);
|
|
73
|
+
if (!a || !b) return false;
|
|
74
|
+
if (a === b || matchesAnyGlob(a, [b]) || matchesAnyGlob(b, [a])) return true;
|
|
75
|
+
if (globSegmentsOverlap(a.split("/"), b.split("/"))) return true;
|
|
76
|
+
if (trackedFiles.length > 0) {
|
|
77
|
+
return trackedFiles.some((f) => matchesAnyGlob(f, [a]) && matchesAnyGlob(f, [b]));
|
|
78
|
+
}
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Return the first overlapping pair across two Touches arrays, or null when disjoint.
|
|
84
|
+
*/
|
|
85
|
+
export function findScopeOverlap(touchesA = [], touchesB = [], trackedFiles = []) {
|
|
86
|
+
if (!touchesA.length || !touchesB.length) return null;
|
|
87
|
+
for (const patternA of touchesA) {
|
|
88
|
+
for (const patternB of touchesB) {
|
|
89
|
+
if (patternsOverlap(patternA, patternB, trackedFiles)) {
|
|
90
|
+
return { patternA, patternB };
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Select a non-overlapping batch of ready tickets up to maxSlots with collision-free VERIFY_PORTs.
|
|
99
|
+
*/
|
|
100
|
+
export function checkWaveConflicts(candidates, activeTickets = [], { maxSlots = 3, trackedFiles = [] } = {}) {
|
|
101
|
+
const occupied = activeTickets.map((t) => ({
|
|
102
|
+
file: t.file,
|
|
103
|
+
id: t.id,
|
|
104
|
+
touches: t.touches ?? [],
|
|
105
|
+
}));
|
|
106
|
+
const usedPorts = new Set(
|
|
107
|
+
activeTickets.map((t) => 8800 + ((t.portOffset ?? (Number.parseInt(t.id, 10) || 1)) % 100)),
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
function allocatePort(preferred) {
|
|
111
|
+
let port = preferred;
|
|
112
|
+
while (usedPorts.has(port) && port < 8999) port++;
|
|
113
|
+
usedPorts.add(port);
|
|
114
|
+
return port;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const selected = [];
|
|
118
|
+
const deferred = [];
|
|
119
|
+
|
|
120
|
+
for (const cand of candidates) {
|
|
121
|
+
let conflict = null;
|
|
122
|
+
for (const occ of occupied) {
|
|
123
|
+
const hit = findScopeOverlap(cand.touches ?? [], occ.touches, trackedFiles);
|
|
124
|
+
if (hit) {
|
|
125
|
+
conflict = { occ, hit };
|
|
126
|
+
break;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (conflict) {
|
|
131
|
+
deferred.push({
|
|
132
|
+
ticket: cand,
|
|
133
|
+
reason: "touches-conflict",
|
|
134
|
+
conflictWith: conflict.occ.file,
|
|
135
|
+
overlap: `${conflict.hit.patternA} <-> ${conflict.hit.patternB}`,
|
|
136
|
+
});
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if (selected.length >= maxSlots) {
|
|
141
|
+
deferred.push({
|
|
142
|
+
ticket: cand,
|
|
143
|
+
reason: "concurrency-cap",
|
|
144
|
+
conflictWith: null,
|
|
145
|
+
overlap: null,
|
|
146
|
+
});
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const preferredPort = 8800 + ((cand.portOffset ?? (Number.parseInt(cand.id, 10) || 1)) % 100);
|
|
151
|
+
const verifyPort = allocatePort(preferredPort);
|
|
152
|
+
selected.push({ ticket: cand, verifyPort });
|
|
153
|
+
occupied.push({ file: cand.file, id: cand.id, touches: cand.touches ?? [] });
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
return { maxSlots, selected, deferred };
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Format a planned wave into JSON or human-readable terminal summary.
|
|
161
|
+
*/
|
|
162
|
+
export function formatWaveReport(wave, { json = false } = {}) {
|
|
163
|
+
if (json) {
|
|
164
|
+
return JSON.stringify({
|
|
165
|
+
slots: wave.slots,
|
|
166
|
+
selected: wave.plans.map((p) => ({
|
|
167
|
+
file: p.ticket.file,
|
|
168
|
+
name: p.name,
|
|
169
|
+
agent: p.ticket.agent,
|
|
170
|
+
verifyPort: p.verifyPort,
|
|
171
|
+
touches: p.ticket.touches,
|
|
172
|
+
args: p.args,
|
|
173
|
+
})),
|
|
174
|
+
deferred: wave.deferred.map((d) => ({
|
|
175
|
+
file: d.ticket.file,
|
|
176
|
+
reason: d.reason,
|
|
177
|
+
conflictWith: d.conflictWith,
|
|
178
|
+
overlap: d.overlap,
|
|
179
|
+
})),
|
|
180
|
+
}, null, 2);
|
|
181
|
+
}
|
|
182
|
+
const lines = [`wave selected=${wave.plans.length} deferred=${wave.deferred.length} slots=${wave.slots}`];
|
|
183
|
+
for (const p of wave.plans) {
|
|
184
|
+
const scope = p.ticket.touches.length ? ` touches=${p.ticket.touches.join(",")}` : "";
|
|
185
|
+
lines.push(` dispatch ${p.name} agent=${p.ticket.agent} port=${p.verifyPort}${scope}`);
|
|
186
|
+
lines.push(` orca ${p.args.join(" ")}`);
|
|
187
|
+
}
|
|
188
|
+
for (const d of wave.deferred) {
|
|
189
|
+
const detail = d.conflictWith ? ` with=${d.conflictWith} (${d.overlap})` : "";
|
|
190
|
+
lines.push(` defer ${d.ticket.file} reason=${d.reason}${detail}`);
|
|
191
|
+
}
|
|
192
|
+
return lines.join("\n");
|
|
193
|
+
}
|
package/src/worker.mjs
ADDED
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
import { execFileSync } from "node:child_process";
|
|
2
|
+
import { existsSync, readdirSync, readFileSync } from "node:fs";
|
|
3
|
+
import { basename, dirname, join, resolve } from "node:path";
|
|
4
|
+
import { parseArgs } from "node:util";
|
|
5
|
+
import { normalizeAgent } from "./agents.mjs";
|
|
6
|
+
import { KIT_ROOT, loadConfig } from "./config.mjs";
|
|
7
|
+
import { scanEfforts } from "./status.mjs";
|
|
8
|
+
import { materializeGithubIssue, parseGithubIssueRef } from "./tracker-github.mjs";
|
|
9
|
+
import { checkWaveConflicts, findScopeOverlap, formatWaveReport, parseTouches } from "./wave.mjs";
|
|
10
|
+
|
|
11
|
+
const CLAUDE_MODELS = {
|
|
12
|
+
sonnet: "claude-sonnet-5-5",
|
|
13
|
+
opus: "claude-opus-5-5",
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
function extractField(text, name) {
|
|
17
|
+
const m = text.match(new RegExp(`^(?:\\*\\*)?${name}:(?:\\*\\*)?(.*)$`, "m"));
|
|
18
|
+
return m ? m[1].trim() : null;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function parseTicket(ticketPath, config, { agentOverride } = {}) {
|
|
22
|
+
const text = readFileSync(ticketPath, "utf8");
|
|
23
|
+
const rawAgent = agentOverride || extractField(text, "Agent");
|
|
24
|
+
const allowed = config.agents.allowedWorkers;
|
|
25
|
+
if (!rawAgent) {
|
|
26
|
+
throw new Error(`${ticketPath}: "Agent:" must be ${allowed.join(", ")}, got "missing"`);
|
|
27
|
+
}
|
|
28
|
+
const agent = rawAgent.trim().toLowerCase() === "auto"
|
|
29
|
+
? config.agents.defaultLead
|
|
30
|
+
: normalizeAgent(rawAgent);
|
|
31
|
+
if (!allowed.includes(agent)) {
|
|
32
|
+
throw new Error(
|
|
33
|
+
`${ticketPath}: Agent "${agent}" is not enabled in .orca-flow.json allowedWorkers (${allowed.join(", ")}). ` +
|
|
34
|
+
`Pass --agent ${allowed[0]} or run "oflow agents set ...".`,
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
let rawModel = extractField(text, "Model") || (agent === "claude" ? "sonnet" : "default");
|
|
39
|
+
if (agentOverride) {
|
|
40
|
+
if (agent === "claude" && rawModel === "default") rawModel = "sonnet";
|
|
41
|
+
else if (agent !== "claude" && (CLAUDE_MODELS[rawModel] || rawModel.startsWith("claude-"))) rawModel = "default";
|
|
42
|
+
}
|
|
43
|
+
if (agent === "claude" && !CLAUDE_MODELS[rawModel] && !rawModel.startsWith("claude-")) {
|
|
44
|
+
throw new Error(`${ticketPath}: invalid Claude model "${rawModel}". Use sonnet or opus.`);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const blockers = parseBlockersList(extractField(text, "Blocked by"));
|
|
48
|
+
const touches = parseTouches(extractField(text, "Touches"));
|
|
49
|
+
return { agent, model: rawModel, blockers, touches, text };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function parseBlockersList(raw) {
|
|
53
|
+
const blockers = [];
|
|
54
|
+
if (raw && !/^(none|-|n\/a)$/i.test(raw)) {
|
|
55
|
+
for (const token of raw.split(/[\s,]+/)) {
|
|
56
|
+
const clean = token.replace(/^#/, "").trim();
|
|
57
|
+
if (clean) blockers.push(clean);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return blockers;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function findBlockerFile(files, id) {
|
|
64
|
+
const padded = id.padStart(2, "0");
|
|
65
|
+
return files.find((f) => f.startsWith(`${padded}-`) || f.startsWith(`${id}-`) || f === id);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function detectBlockerCycle(dir, startFile, files, trail = []) {
|
|
69
|
+
const nextTrail = [...trail, startFile];
|
|
70
|
+
const raw = extractField(readFileSync(join(dir, startFile), "utf8"), "Blocked by");
|
|
71
|
+
for (const dep of parseBlockersList(raw)) {
|
|
72
|
+
const depFile = findBlockerFile(files, dep);
|
|
73
|
+
if (!depFile) continue;
|
|
74
|
+
const hit = nextTrail.indexOf(depFile);
|
|
75
|
+
if (hit !== -1) return [...nextTrail.slice(hit), depFile];
|
|
76
|
+
const nested = detectBlockerCycle(dir, depFile, files, nextTrail);
|
|
77
|
+
if (nested) return nested;
|
|
78
|
+
}
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function checkBlockers(ticketPath, blockers) {
|
|
83
|
+
if (!blockers.length) return;
|
|
84
|
+
const dir = dirname(ticketPath);
|
|
85
|
+
const files = existsSync(dir) ? readdirSync(dir) : [];
|
|
86
|
+
const rootFile = basename(ticketPath);
|
|
87
|
+
const cycle = detectBlockerCycle(dir, rootFile, files);
|
|
88
|
+
if (cycle) {
|
|
89
|
+
throw new Error(`Circular Blocked-by dependency detected: ${cycle.join(" -> ")}`);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const unresolved = [];
|
|
93
|
+
for (const id of blockers) {
|
|
94
|
+
const match = findBlockerFile(files, id);
|
|
95
|
+
if (!match) {
|
|
96
|
+
unresolved.push(`${id} (ticket file not found in ${dir})`);
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
const status = extractField(readFileSync(join(dir, match), "utf8"), "Status") || "open";
|
|
100
|
+
if (!/^(done|merged|resolved)\b/i.test(status)) {
|
|
101
|
+
unresolved.push(`${match} (status=${status})`);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (unresolved.length) {
|
|
106
|
+
throw new Error(`Ticket is blocked by unresolved dependencies: ${unresolved.join(", ")}`);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export function deriveWorkerIdentity(ticketPath) {
|
|
111
|
+
const norm = ticketPath.replace(/\\/g, "/");
|
|
112
|
+
const m = norm.match(/(?:^|\/)(\.scratch\/([^/_][^/]*)\/issues\/(\d+)-[^/]+\.md)$/);
|
|
113
|
+
if (m) {
|
|
114
|
+
return { relTicket: m[1], name: `${m[2]}-${m[3]}`, portOffset: Number.parseInt(m[3], 10) || 1 };
|
|
115
|
+
}
|
|
116
|
+
const ghMatch = norm.match(/(?:^|\/)issue-(\d+)\.md$/);
|
|
117
|
+
if (ghMatch) {
|
|
118
|
+
const num = Number.parseInt(ghMatch[1], 10) || 1;
|
|
119
|
+
return { relTicket: norm, name: `issue-${num}`, portOffset: (num % 100) || 1 };
|
|
120
|
+
}
|
|
121
|
+
const slug = basename(norm, ".md").replace(/[^a-zA-Z0-9-]+/g, "-").toLowerCase();
|
|
122
|
+
return { relTicket: norm, name: slug, portOffset: 1 };
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export function buildWorkerPlan(ticketInput, { type = "feat", cwd = process.cwd(), agent, verifyPort: explicitPort, force = false, ghRunner } = {}) {
|
|
126
|
+
if (!["feat", "fix", "chore", "docs"].includes(type)) {
|
|
127
|
+
throw new Error(`--type must be feat, fix, chore, or docs; got "${type}"`);
|
|
128
|
+
}
|
|
129
|
+
const ghNum = parseGithubIssueRef(ticketInput);
|
|
130
|
+
const materialized = ghNum !== null ? materializeGithubIssue(ghNum, { cwd, force, ghRunner }) : null;
|
|
131
|
+
const ticketPath = materialized ? materialized.ticketPath : ticketInput;
|
|
132
|
+
const absTicket = resolve(cwd, ticketPath);
|
|
133
|
+
if (!existsSync(absTicket)) throw new Error(`Ticket not found: ${absTicket}`);
|
|
134
|
+
|
|
135
|
+
const { root, config } = loadConfig(cwd);
|
|
136
|
+
const ticket = parseTicket(absTicket, config, { agentOverride: agent });
|
|
137
|
+
checkBlockers(absTicket, ticket.blockers);
|
|
138
|
+
|
|
139
|
+
const identity = deriveWorkerIdentity(ticketPath);
|
|
140
|
+
const relTicket = materialized ? `GitHub issue #${ghNum} (${materialized.ticketPath})` : identity.relTicket;
|
|
141
|
+
const { name, portOffset } = identity;
|
|
142
|
+
if (!force && ticket.touches.length > 0) {
|
|
143
|
+
const active = scanEfforts(root, config.tracker)
|
|
144
|
+
.flatMap((e) => e.tickets)
|
|
145
|
+
.filter((t) => t.state === "active" && resolve(root, t.file) !== absTicket && t.touches.length > 0);
|
|
146
|
+
for (const occ of active) {
|
|
147
|
+
const hit = findScopeOverlap(ticket.touches, occ.touches);
|
|
148
|
+
if (hit) {
|
|
149
|
+
throw new Error(
|
|
150
|
+
`Ticket ${relTicket} Touches scope overlaps active ticket ${occ.file} (${hit.patternA} <-> ${hit.patternB}). ` +
|
|
151
|
+
`Wait for it to finish or pass --force.`,
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const skillRef = join(KIT_ROOT, "skills", "build-ticket", "SKILL.md");
|
|
158
|
+
const verifyPort = explicitPort ?? (8800 + (portOffset % 100));
|
|
159
|
+
const modelFlags = ticket.agent === "claude"
|
|
160
|
+
? ["--model", CLAUDE_MODELS[ticket.model] || ticket.model, "--effort", "high"]
|
|
161
|
+
: [];
|
|
162
|
+
|
|
163
|
+
const args = [
|
|
164
|
+
"orchestration", "worker-start",
|
|
165
|
+
"--repo", config.orcaRepo,
|
|
166
|
+
"--worktree", config.agents.worktreeMode,
|
|
167
|
+
"--name", name,
|
|
168
|
+
"--base-branch", config.baseBranch,
|
|
169
|
+
"--setup", "run",
|
|
170
|
+
"--agent", ticket.agent,
|
|
171
|
+
...modelFlags,
|
|
172
|
+
"--spec-file", "-",
|
|
173
|
+
"--json",
|
|
174
|
+
];
|
|
175
|
+
|
|
176
|
+
const reviewKind = config.agents.allowedWorkers.length >= 2
|
|
177
|
+
? "cross-vendor"
|
|
178
|
+
: "independent fresh-context";
|
|
179
|
+
const brief = [
|
|
180
|
+
`Read ~/.agents/skills/build-ticket/SKILL.md (fallback: ${skillRef}) and follow it for ${relTicket}.`,
|
|
181
|
+
`Rename branch to ${type}/${name}. Use ${config.verifyIsolation.portEnv}=${verifyPort} when running verify.`,
|
|
182
|
+
`Do not spawn nested orchestrators. Run oflow gate, ${reviewKind} oflow review run --author ${ticket.agent}, open PR with oflow pr, then report worker_done and stop.`,
|
|
183
|
+
].join(" ");
|
|
184
|
+
|
|
185
|
+
return { config, ticket, name, verifyPort, args, brief };
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Plan a conflict-free wave of ready tickets across one or all efforts.
|
|
190
|
+
*/
|
|
191
|
+
export function planReadyWave({ cwd = process.cwd(), effort, max, type = "feat", agent, activeCount = 0 } = {}) {
|
|
192
|
+
const { root, config } = loadConfig(cwd);
|
|
193
|
+
let efforts = scanEfforts(root, config.tracker);
|
|
194
|
+
if (effort) {
|
|
195
|
+
efforts = efforts.filter((e) => e.effort === effort);
|
|
196
|
+
if (!efforts.length) {
|
|
197
|
+
throw new Error(`Effort "${effort}" not found under ${config.tracker.dir || ".scratch"}.`);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
const cycles = efforts.flatMap((e) => e.cycles);
|
|
201
|
+
if (cycles.length) {
|
|
202
|
+
throw new Error(`Cannot dispatch wave: circular dependency detected (${cycles.join(", ")}).`);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
const activeTickets = [];
|
|
206
|
+
const readyTickets = [];
|
|
207
|
+
for (const e of efforts) {
|
|
208
|
+
for (const t of e.tickets) {
|
|
209
|
+
const withPort = { ...t, portOffset: deriveWorkerIdentity(t.file).portOffset };
|
|
210
|
+
if (t.state === "active") activeTickets.push(withPort);
|
|
211
|
+
else if (t.state === "ready") readyTickets.push(withPort);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const cap = max !== undefined ? max : Math.max(0, config.agents.maxConcurrentWorkers - activeCount);
|
|
216
|
+
const wave = checkWaveConflicts(readyTickets, activeTickets, { maxSlots: cap });
|
|
217
|
+
const plans = wave.selected.map((item) => ({
|
|
218
|
+
...buildWorkerPlan(item.ticket.file, { type, cwd: root, agent, verifyPort: item.verifyPort, force: true }),
|
|
219
|
+
ticket: { ...item.ticket, ...parseTicket(resolve(root, item.ticket.file), config, { agentOverride: agent }) },
|
|
220
|
+
}));
|
|
221
|
+
|
|
222
|
+
return { root, config, slots: cap, plans, deferred: wave.deferred };
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
function getActiveWorkerCount() {
|
|
226
|
+
try {
|
|
227
|
+
const raw = execFileSync("orca", ["orchestration", "worker-list", "--json"], { encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] });
|
|
228
|
+
const parsed = JSON.parse(raw);
|
|
229
|
+
const list = parsed?.result?.workers ?? [];
|
|
230
|
+
return list.filter((w) => w.liveness === "live" || !w.settled).length;
|
|
231
|
+
} catch {
|
|
232
|
+
return 0;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
export async function runWorker(argv, { cwd = process.cwd(), ghRunner } = {}) {
|
|
237
|
+
const { values, positionals } = parseArgs({
|
|
238
|
+
args: argv,
|
|
239
|
+
allowPositionals: true,
|
|
240
|
+
options: {
|
|
241
|
+
ready: { type: "boolean", default: false },
|
|
242
|
+
effort: { type: "string" },
|
|
243
|
+
max: { type: "string" },
|
|
244
|
+
agent: { type: "string" },
|
|
245
|
+
type: { type: "string", default: "feat" },
|
|
246
|
+
force: { type: "boolean", default: false },
|
|
247
|
+
"dry-run": { type: "boolean", default: false },
|
|
248
|
+
json: { type: "boolean", default: false },
|
|
249
|
+
},
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
if (values.ready) {
|
|
253
|
+
if (positionals.length) throw new Error("Cannot combine a ticket path with --ready.");
|
|
254
|
+
let max;
|
|
255
|
+
if (values.max !== undefined) {
|
|
256
|
+
max = Number.parseInt(values.max, 10);
|
|
257
|
+
if (!Number.isInteger(max) || max < 0) {
|
|
258
|
+
throw new Error(`--max must be a non-negative integer; got "${values.max}".`);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
const activeCount = values["dry-run"] ? 0 : getActiveWorkerCount();
|
|
262
|
+
const wave = planReadyWave({ cwd, effort: values.effort, max, type: values.type, agent: values.agent, activeCount });
|
|
263
|
+
if (values.json || values["dry-run"]) {
|
|
264
|
+
console.log(formatWaveReport(wave, { json: values.json }));
|
|
265
|
+
return 0;
|
|
266
|
+
}
|
|
267
|
+
if (!wave.plans.length) {
|
|
268
|
+
console.log("No conflict-free ready tickets to dispatch.");
|
|
269
|
+
return 0;
|
|
270
|
+
}
|
|
271
|
+
execFileSync("git", ["fetch", "-q"], { cwd: wave.root, stdio: "inherit" });
|
|
272
|
+
for (const plan of wave.plans) {
|
|
273
|
+
execFileSync("orca", plan.args, { cwd: wave.root, input: plan.brief, stdio: ["pipe", "inherit", "inherit"] });
|
|
274
|
+
}
|
|
275
|
+
return 0;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
const [ticketPath, ...extra] = positionals;
|
|
279
|
+
if (!ticketPath || extra.length) {
|
|
280
|
+
throw new Error("Usage: oflow worker (<ticket-path>|#<n>|gh:<n>|--ready) [--effort <e>] [--max <n>] [--agent claude|codex|agy] [--type feat|fix|chore|docs] [--force] [--dry-run]");
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
const plan = buildWorkerPlan(ticketPath, { cwd, type: values.type, agent: values.agent, force: values.force, ghRunner });
|
|
284
|
+
if (values["dry-run"]) {
|
|
285
|
+
console.log(`orca ${plan.args.join(" ")}\n\n${plan.brief}`);
|
|
286
|
+
return 0;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
const activeCount = getActiveWorkerCount();
|
|
290
|
+
const maxWorkers = plan.config.agents.maxConcurrentWorkers;
|
|
291
|
+
if (activeCount >= maxWorkers) {
|
|
292
|
+
throw new Error(`Active Orca workers (${activeCount}) reached limit maxConcurrentWorkers=${maxWorkers}. Wait before starting more.`);
|
|
293
|
+
}
|
|
294
|
+
execFileSync("git", ["fetch", "-q"], { cwd, stdio: "inherit" });
|
|
295
|
+
execFileSync("orca", plan.args, { cwd, input: plan.brief, stdio: ["pipe", "inherit", "inherit"] });
|
|
296
|
+
return 0;
|
|
297
|
+
}
|