@telpin-sistemas/orqen 0.1.14 → 0.1.15
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/dist/commands/bots.js +65 -0
- package/dist/commands/eval.js +137 -7
- package/dist/commands/workflow.js +172 -17
- package/dist/index.js +11 -1
- package/dist/lib/bots.js +72 -0
- package/dist/lib/config-keys.js +1 -1
- package/dist/lib/config.js +6 -0
- package/dist/lib/connectors-edit.js +28 -2
- package/dist/lib/mcp.js +73 -0
- package/dist/practice/practice.js +6 -0
- package/dist/template/.agents/commands/new_worq.md +2 -0
- package/dist/workflow/board.js +14 -0
- package/dist/workflow/config.js +2 -1
- package/dist/workflow/dry-run-commands.js +2 -0
- package/dist/workflow/dry-run.js +1 -1
- package/dist/workflow/process.js +142 -14
- package/package.json +1 -1
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/** `orqen bots` and `orqen mcp`: the bot profiles of this person and the MCP servers their agents can reach. */
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
|
+
import { ZodError } from "zod";
|
|
4
|
+
import { botsFile, botsFor, readBots, stagesIn, STAGES, toolsIn, writeBots } from "../lib/bots.js";
|
|
5
|
+
import { mcpServers } from "../lib/mcp.js";
|
|
6
|
+
import { mainWorktree, repoRoot } from "../workflow/config.js";
|
|
7
|
+
export const BOTS_HELP = ` bots [--json] Your bot profiles and the stages of this project where each one helps (~/.orqen/bots.json)
|
|
8
|
+
bots set <file|-> Save the whole list (JSON: {"bots": [{name, prompt, projects: {<repo>: [stages]}, connectors}]})
|
|
9
|
+
mcp [--json] MCP servers your agents can reach (.mcp.json, Claude Code, Codex, Gemini); added in each agent`;
|
|
10
|
+
const here = () => mainWorktree(repoRoot());
|
|
11
|
+
function view(bots, repo) {
|
|
12
|
+
return {
|
|
13
|
+
file: botsFile(),
|
|
14
|
+
repo,
|
|
15
|
+
stages: STAGES,
|
|
16
|
+
bots,
|
|
17
|
+
here: {
|
|
18
|
+
tools: toolsIn(bots, repo),
|
|
19
|
+
stages: Object.fromEntries(STAGES.map((s) => [s, botsFor(bots, repo, s).map((b) => b.name)]).filter(([, n]) => n.length)),
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function fail(e) {
|
|
24
|
+
const msg = e instanceof ZodError ? e.issues.map((i) => `${i.path.join(".")}: ${i.message}`).join("; ") : e.message;
|
|
25
|
+
console.error(`✘ ${msg}`);
|
|
26
|
+
process.exitCode = 1;
|
|
27
|
+
}
|
|
28
|
+
export async function botsCommand(args) {
|
|
29
|
+
const json = args.includes("--json");
|
|
30
|
+
const rest = args.filter((a) => a !== "--json");
|
|
31
|
+
const repo = here();
|
|
32
|
+
try {
|
|
33
|
+
if (rest[0] === "set") {
|
|
34
|
+
const src = rest[1] && rest[1] !== "-" ? readFileSync(rest[1], "utf8") : readFileSync(0, "utf8");
|
|
35
|
+
const bots = writeBots(JSON.parse(src));
|
|
36
|
+
return console.log(JSON.stringify(view(bots, repo), null, 2));
|
|
37
|
+
}
|
|
38
|
+
if (rest[0]) {
|
|
39
|
+
console.error(`✘ orqen bots: unknown "${rest[0]}" (bots [--json] | bots set <file|->)`);
|
|
40
|
+
process.exitCode = 1;
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const bots = readBots();
|
|
44
|
+
if (json)
|
|
45
|
+
return console.log(JSON.stringify(view(bots, repo), null, 2));
|
|
46
|
+
if (!bots.length)
|
|
47
|
+
return console.log(`No bots yet. orqen-studio (Settings › Bots) creates them, or: orqen bots set <file>\n${botsFile()}`);
|
|
48
|
+
for (const b of bots) {
|
|
49
|
+
const st = stagesIn(b, repo);
|
|
50
|
+
console.log(`${b.name.padEnd(20)} ${st.length ? st.join(", ") : "(not in this project)"}${b.connectors.length ? ` · mcp: ${b.connectors.join(", ")}` : ""}`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
catch (e) {
|
|
54
|
+
fail(e);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
export async function mcpCommand(args) {
|
|
58
|
+
const list = mcpServers(repoRoot() ? here() : undefined);
|
|
59
|
+
if (args.includes("--json"))
|
|
60
|
+
return console.log(JSON.stringify({ servers: list }, null, 2));
|
|
61
|
+
if (!list.length)
|
|
62
|
+
return console.log("No MCP servers configured (add them in Claude Code, Codex or Gemini).");
|
|
63
|
+
for (const s of list)
|
|
64
|
+
console.log(`${s.name.padEnd(20)} ${s.source.padEnd(8)} ${s.file}`);
|
|
65
|
+
}
|
package/dist/commands/eval.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* (injected into each stage's instructions) and new eval cases.
|
|
4
4
|
*/
|
|
5
5
|
import { execFileSync } from "node:child_process";
|
|
6
|
-
import { appendFileSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
6
|
+
import { appendFileSync, existsSync, mkdirSync, readdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
|
|
7
7
|
import { join } from "node:path";
|
|
8
8
|
import { stringify } from "yaml";
|
|
9
9
|
import { buildConnectors } from "../connectors/index.js";
|
|
@@ -18,7 +18,11 @@ export const EVAL_HELP = ` eval [case|step...] Run the agent on test ticket
|
|
|
18
18
|
--keep Keep the test projects · --json Machine-readable result
|
|
19
19
|
learn What the team marked right/wrong in the desktop app, by step
|
|
20
20
|
--apply Add the new notes to orqen/knowledge/lessons/<STAGE>.md (the agent reads them in that stage)
|
|
21
|
-
--
|
|
21
|
+
--apply <run> Only that note · --discard <run> Drop a note without making it a lesson
|
|
22
|
+
--to-eval <run> Turn a run marked wrong into an eval case (orqen/evals/)
|
|
23
|
+
--json Feedback by step, the pending notes, the lessons of each stage and the eval history
|
|
24
|
+
run record <file|-> Log an agent run of a worq (JSON: run, key, command, state_before, secs, cost…) in orqen/state/app-chat/runs.jsonl
|
|
25
|
+
feedback <run> up|down Mark a run right or wrong · --note <text|-> what was wrong (it becomes a lesson with learn --apply)`;
|
|
22
26
|
function gitRoot() {
|
|
23
27
|
try {
|
|
24
28
|
return execFileSync("git", ["rev-parse", "--show-toplevel"], { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] }).trim();
|
|
@@ -44,6 +48,16 @@ function takeBool(args, name) {
|
|
|
44
48
|
export async function evalCommand(args) {
|
|
45
49
|
const a = [...args];
|
|
46
50
|
const json = takeBool(a, "json"), keep = takeBool(a, "keep"), noLessons = takeBool(a, "no-lessons");
|
|
51
|
+
if (takeBool(a, "history")) {
|
|
52
|
+
const h = evalHistory(gitRoot());
|
|
53
|
+
if (json)
|
|
54
|
+
return console.log(JSON.stringify(h, null, 2));
|
|
55
|
+
if (!h.length)
|
|
56
|
+
return console.log("No eval runs yet: orqen eval");
|
|
57
|
+
for (const r of h.slice(-10))
|
|
58
|
+
console.log(` ${r.ts.slice(0, 16).replace("T", " ")} ${r.passed}/${r.total}${r.lessons ? "" : " (no lessons)"}${r.cost !== undefined ? ` US$ ${Number(r.cost).toFixed(2)}` : ""} ${r.agent}`);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
47
61
|
const agentFlag = takeFlag(a, "agent"), judgeFlag = takeFlag(a, "judge");
|
|
48
62
|
const repo = gitRoot();
|
|
49
63
|
const cfgAgent = existsSync(join(repo, "orqen", "config.yaml")) ? loadConfig().agentCmd : "";
|
|
@@ -94,6 +108,12 @@ const STAGE_OF = {
|
|
|
94
108
|
"/orqen:support": "SUPPORT", "/orqen:analyze": "ANALYSIS", "/orqen:implement": "DEVELOPMENT",
|
|
95
109
|
"/orqen:pr": "DELIVERY", "/orqen:review": "TESTING", "/orqen:approve": "DELIVERY",
|
|
96
110
|
};
|
|
111
|
+
/** The stage a run's lessons belong to: by its command, else by the state it ran in (the desktop app's "Start task" runs are "workflow"). */
|
|
112
|
+
const STATE_STAGE = {
|
|
113
|
+
NEW: "SUPPORT", SUPPORT: "SUPPORT", ANALYSIS: "ANALYSIS", WAITING_CLIENT: "ANALYSIS", DEVELOPMENT: "DEVELOPMENT", EXECUTION: "DEVELOPMENT",
|
|
114
|
+
TESTING: "TESTING", QA_REVIEW: "TESTING", VERIFICATION: "TESTING", CODE_REVIEW: "DELIVERY", DELIVERY: "DELIVERY",
|
|
115
|
+
};
|
|
116
|
+
const stageOfRun = (rec) => STAGE_OF[rec?.command ?? ""] ?? STATE_STAGE[rec?.state_before ?? ""] ?? "GENERAL";
|
|
97
117
|
const STEP_OF = { "/orqen:support": "support", "/orqen:analyze": "analyze" };
|
|
98
118
|
/** The desktop app's run log: runs, verdicts and what the person said was wrong. */
|
|
99
119
|
export function readFeedback(repo) {
|
|
@@ -124,7 +144,11 @@ export function readFeedback(repo) {
|
|
|
124
144
|
}
|
|
125
145
|
export async function learnCommand(args) {
|
|
126
146
|
const a = [...args];
|
|
127
|
-
const
|
|
147
|
+
const applyArg = takeFlag(a, "apply");
|
|
148
|
+
const apply = applyArg !== undefined;
|
|
149
|
+
const only = applyArg || undefined; // --apply <run>: just that note
|
|
150
|
+
const discard = takeFlag(a, "discard");
|
|
151
|
+
const json = takeBool(a, "json");
|
|
128
152
|
const toEval = takeFlag(a, "to-eval");
|
|
129
153
|
const repo = gitRoot();
|
|
130
154
|
const { runs, verdicts } = readFeedback(repo);
|
|
@@ -132,6 +156,16 @@ export async function learnCommand(args) {
|
|
|
132
156
|
return caseFromRun(repo, toEval, runs, verdicts);
|
|
133
157
|
const doneFile = join(repo, "orqen", "state", "app-chat", "learned.json");
|
|
134
158
|
const done = new Set(existsSync(doneFile) ? JSON.parse(readFileSync(doneFile, "utf8")) : []);
|
|
159
|
+
const saveDone = () => { mkdirSync(join(repo, "orqen", "state", "app-chat"), { recursive: true }); writeFileSync(doneFile, JSON.stringify([...done], null, 2)); };
|
|
160
|
+
if (discard) {
|
|
161
|
+
if (!verdicts.has(discard))
|
|
162
|
+
throw new Error(`Run ${discard} has no feedback in orqen/state/app-chat/runs.jsonl`);
|
|
163
|
+
done.add(discard);
|
|
164
|
+
saveDone();
|
|
165
|
+
return console.log(json ? JSON.stringify({ ok: true, discarded: discard }) : `✔ Note of ${discard} dropped: it will not become a lesson.`);
|
|
166
|
+
}
|
|
167
|
+
if (json)
|
|
168
|
+
return console.log(JSON.stringify(learnState(repo, runs, verdicts, done), null, 2));
|
|
135
169
|
const byCommand = new Map();
|
|
136
170
|
const fresh = [];
|
|
137
171
|
for (const v of verdicts.values()) {
|
|
@@ -140,9 +174,11 @@ export async function learnCommand(args) {
|
|
|
140
174
|
const n = byCommand.get(cmd) ?? { up: 0, down: 0 };
|
|
141
175
|
n[v.verdict]++;
|
|
142
176
|
byCommand.set(cmd, n);
|
|
143
|
-
if (rec && v.verdict === "down" && v.note && !done.has(v.run))
|
|
177
|
+
if (rec && v.verdict === "down" && v.note && !done.has(v.run) && (!only || v.run === only))
|
|
144
178
|
fresh.push({ rec, v });
|
|
145
179
|
}
|
|
180
|
+
if (only && !fresh.length)
|
|
181
|
+
throw new Error(`Run ${only} has no pending note (marked wrong, with what was wrong, not applied yet).`);
|
|
146
182
|
if (!byCommand.size) {
|
|
147
183
|
console.log("No feedback yet: mark runs with ✓ / ✗ in the desktop app's chat.");
|
|
148
184
|
return;
|
|
@@ -165,7 +201,7 @@ export async function learnCommand(args) {
|
|
|
165
201
|
mkdirSync(dir, { recursive: true });
|
|
166
202
|
const touched = new Set();
|
|
167
203
|
for (const { rec, v } of fresh) {
|
|
168
|
-
const stage =
|
|
204
|
+
const stage = stageOfRun(rec);
|
|
169
205
|
const file = join(dir, `${stage}.md`);
|
|
170
206
|
if (!existsSync(file))
|
|
171
207
|
writeFileSync(file, `# Lessons for ${stage}\n\nWhat the team corrected in past runs. The agent reads this file in the ${stage} stage: keep it short and concrete; delete what no longer applies.\n\n`);
|
|
@@ -173,8 +209,7 @@ export async function learnCommand(args) {
|
|
|
173
209
|
touched.add(`orqen/knowledge/lessons/${stage}.md`);
|
|
174
210
|
done.add(v.run);
|
|
175
211
|
}
|
|
176
|
-
|
|
177
|
-
writeFileSync(doneFile, JSON.stringify([...done], null, 2));
|
|
212
|
+
saveDone();
|
|
178
213
|
console.log(`\nUpdated: ${[...touched].join(", ")}. Review them and commit: the whole team's agents learn from them.`);
|
|
179
214
|
}
|
|
180
215
|
/** A run marked wrong → orqen/evals/<key>-<step>.yaml with the ticket as it is now, for the person to finish the expectations. */
|
|
@@ -216,3 +251,98 @@ export function lessonsFor(repo, state) {
|
|
|
216
251
|
const capped = text.length > 6000 ? `${text.slice(0, 6000)}\n…` : text;
|
|
217
252
|
return `## Team lessons for this stage (orqen/knowledge/lessons/${state}.md)\nCorrections from past runs. Follow them unless the person says otherwise.\n\n${capped.replace(/^# .*\n+/, "")}`;
|
|
218
253
|
}
|
|
254
|
+
/** Where the desktop app (and `orqen run record`) logs the agent runs of each worq and the person's verdicts. */
|
|
255
|
+
export const runsFile = (repo) => join(repo, "orqen", "state", "app-chat", "runs.jsonl");
|
|
256
|
+
function appendRun(repo, rec) {
|
|
257
|
+
mkdirSync(join(repo, "orqen", "state", "app-chat"), { recursive: true });
|
|
258
|
+
appendFileSync(runsFile(repo), JSON.stringify(rec) + "\n");
|
|
259
|
+
}
|
|
260
|
+
const nowSecs = () => String(Math.floor(Date.now() / 1000));
|
|
261
|
+
const readArg = (v) => v === "-" ? readFileSync(0, "utf8") : existsSync(v) ? readFileSync(v, "utf8") : v;
|
|
262
|
+
/** `orqen run record <file|->`: one agent run of a worq, as any tool that runs agents logs it (the desktop app does). */
|
|
263
|
+
export function runCommand(args) {
|
|
264
|
+
const [sub, src] = args;
|
|
265
|
+
if (sub !== "record" || !src)
|
|
266
|
+
throw new Error("Usage: orqen run record <run.json|-> (JSON: run, key, command, state_before, secs, cost, agent, model…)");
|
|
267
|
+
const rec = JSON.parse(src === "-" ? readFileSync(0, "utf8") : readFileSync(src, "utf8"));
|
|
268
|
+
if (typeof rec.run !== "string" || typeof rec.key !== "string")
|
|
269
|
+
throw new Error("The run needs \"run\" (its id) and \"key\" (the worq).");
|
|
270
|
+
appendRun(gitRoot(), { ...rec, type: "run", ts: rec.ts ?? nowSecs() });
|
|
271
|
+
}
|
|
272
|
+
/** `orqen feedback <run> up|down [--note <text|->]`: the person says whether a run was right; a note says what was wrong. */
|
|
273
|
+
export function feedbackCommand(args) {
|
|
274
|
+
const a = [...args];
|
|
275
|
+
const noteArg = takeFlag(a, "note");
|
|
276
|
+
const [run, verdict] = a;
|
|
277
|
+
if (!run || (verdict !== "up" && verdict !== "down" && verdict !== "note"))
|
|
278
|
+
throw new Error("Usage: orqen feedback <run> up|down [--note <text|->] · orqen feedback <run> note <text|->");
|
|
279
|
+
const repo = gitRoot();
|
|
280
|
+
const key = readFeedback(repo).runs.get(run)?.key;
|
|
281
|
+
const text = verdict === "note" ? readArg(a[2] ?? "") : noteArg !== undefined ? readArg(noteArg) : "";
|
|
282
|
+
if (verdict !== "note")
|
|
283
|
+
appendRun(repo, { type: "feedback", run, ts: nowSecs(), key, verdict });
|
|
284
|
+
if (text.trim())
|
|
285
|
+
appendRun(repo, { type: "feedback-note", run, ts: nowSecs(), key, text: text.trim() });
|
|
286
|
+
}
|
|
287
|
+
/** Time and cost of a worq's agent runs (from the run log), in total and by the stage they ran in. */
|
|
288
|
+
export function runUsage(repo, key) {
|
|
289
|
+
const { runs, verdicts } = readFeedback(repo);
|
|
290
|
+
const total = { runs: 0, secs: 0, cost: 0, up: 0, down: 0 };
|
|
291
|
+
const byState = {};
|
|
292
|
+
for (const r of runs.values()) {
|
|
293
|
+
if (r.key !== key)
|
|
294
|
+
continue;
|
|
295
|
+
const x = r;
|
|
296
|
+
total.runs++;
|
|
297
|
+
total.secs += x.secs ?? 0;
|
|
298
|
+
total.cost += x.cost ?? 0;
|
|
299
|
+
const st = (byState[r.state_before ?? "?"] ??= { runs: 0, secs: 0, cost: 0 });
|
|
300
|
+
st.runs++;
|
|
301
|
+
st.secs += x.secs ?? 0;
|
|
302
|
+
st.cost += x.cost ?? 0;
|
|
303
|
+
const v = verdicts.get(r.run)?.verdict;
|
|
304
|
+
if (v)
|
|
305
|
+
total[v]++;
|
|
306
|
+
}
|
|
307
|
+
return total.runs ? { ...total, secs: Math.round(total.secs), cost: Math.round(total.cost * 100) / 100, by_state: byState } : undefined;
|
|
308
|
+
}
|
|
309
|
+
/** `orqen eval` runs so far (orqen/state/evals/history.jsonl). */
|
|
310
|
+
export function evalHistory(repo) {
|
|
311
|
+
const f = join(repo, "orqen", "state", "evals", "history.jsonl");
|
|
312
|
+
if (!existsSync(f))
|
|
313
|
+
return [];
|
|
314
|
+
return readFileSync(f, "utf8").split(/\r?\n/).filter((l) => l.trim()).flatMap((l) => { try {
|
|
315
|
+
return [JSON.parse(l)];
|
|
316
|
+
}
|
|
317
|
+
catch {
|
|
318
|
+
return [];
|
|
319
|
+
} });
|
|
320
|
+
}
|
|
321
|
+
/** What `orqen learn --json` says: feedback by step, the notes waiting to become lessons, the lessons of each stage and the evals. */
|
|
322
|
+
function learnState(repo, runs, verdicts, done) {
|
|
323
|
+
const byCommand = new Map();
|
|
324
|
+
const byStage = new Map();
|
|
325
|
+
const notes = [];
|
|
326
|
+
for (const v of verdicts.values()) {
|
|
327
|
+
const rec = runs.get(v.run);
|
|
328
|
+
const cmd = rec?.command ?? "chat";
|
|
329
|
+
const c = byCommand.get(cmd) ?? { command: cmd, up: 0, down: 0 };
|
|
330
|
+
c[v.verdict]++;
|
|
331
|
+
byCommand.set(cmd, c);
|
|
332
|
+
const stage = stageOfRun(rec);
|
|
333
|
+
const st = byStage.get(stage) ?? { up: 0, down: 0 };
|
|
334
|
+
st[v.verdict]++;
|
|
335
|
+
byStage.set(stage, st);
|
|
336
|
+
if (rec && v.verdict === "down" && v.note && !done.has(v.run))
|
|
337
|
+
notes.push({ run: v.run, key: rec.key, command: cmd, stage, note: v.note, ts: rec.ts });
|
|
338
|
+
}
|
|
339
|
+
const dir = join(repo, "orqen", "knowledge", "lessons");
|
|
340
|
+
const lessons = existsSync(dir) ? readdirSync(dir).filter((f) => f.endsWith(".md")).map((f) => {
|
|
341
|
+
const text = readFileSync(join(dir, f), "utf8");
|
|
342
|
+
return { stage: f.replace(/\.md$/, ""), count: text.split(/\r?\n/).filter((l) => /^\s*[-*] /.test(l)).length, updated: statSync(join(dir, f)).mtime.toISOString(), file: `orqen/knowledge/lessons/${f}` };
|
|
343
|
+
}) : [];
|
|
344
|
+
return {
|
|
345
|
+
by_command: [...byCommand.values()], by_stage: [...byStage].map(([stage, n]) => ({ stage, ...n })),
|
|
346
|
+
notes, lessons, evals: evalHistory(repo).slice(-20),
|
|
347
|
+
};
|
|
348
|
+
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { ejecutar, partirComando } from "../lib/proc.js";
|
|
3
3
|
import { providerEnv, saveProviders, providerFile } from "../lib/provider-credentials.js";
|
|
4
4
|
import { stageGuideFile } from "../lib/stage-guides.js";
|
|
5
|
-
import { lessonsFor } from "./eval.js";
|
|
5
|
+
import { lessonsFor, runUsage } from "./eval.js";
|
|
6
6
|
import { execFileSync } from "node:child_process";
|
|
7
7
|
import { readFileSync } from "node:fs";
|
|
8
8
|
import { userInfo } from "node:os";
|
|
@@ -15,12 +15,24 @@ import { envWithLegacy } from "../connectors/legacy.js";
|
|
|
15
15
|
import { DRY_RUN_COMMANDS, DryRun } from "../workflow/dry-run.js";
|
|
16
16
|
import { OpenSpecCli } from "../workflow/openspec.js";
|
|
17
17
|
import { Process } from "../workflow/process.js";
|
|
18
|
+
import { whoIs } from "../workflow/board.js";
|
|
18
19
|
import { Store } from "../workflow/store.js";
|
|
19
20
|
import { GitWorkspace } from "../workflow/workspace.js";
|
|
20
|
-
|
|
21
|
+
/** The bot profiles assigned to this stage of this project (none when the person has none, or their file is unreadable). */
|
|
22
|
+
async function stageBots(repoPath, state) {
|
|
23
|
+
try {
|
|
24
|
+
const { botsFor, readBots } = await import("../lib/bots.js");
|
|
25
|
+
const { mainWorktree } = await import("../workflow/config.js");
|
|
26
|
+
return botsFor(readBots(), mainWorktree(repoPath), state);
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return [];
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export const WORKFLOW_COMMANDS = ["list", "qa", "approve", "merged", "cancel", "new_worq", "new-worq", "pending", "support", "analyze", "ask", "conversation", "lane", "take", "complete", "pr", "review", "code-review", "schema", "block", "release", "search", "status", "worqs", "worq", "cycle", "connectors", "doctor", "report", "comments", "comment", "gate", "whoami", "watch"];
|
|
21
33
|
/** What people run: the 9 steps (as /orqen:* commands in their agent) and the CLI commands meant for a person. */
|
|
22
34
|
export const WORKFLOW_HELP = `The 9 steps (run the /orqen:* commands in your agent: it calls the CLI for you):
|
|
23
|
-
1 /orqen:list requests orqen list requests [--json] [--all] Everyone's work list, by role (
|
|
35
|
+
1 /orqen:list requests orqen list requests [--json] [--all] [--mine] Everyone's work list, by role (--mine: only your roles)
|
|
24
36
|
2 /orqen:support <KEY> First-line support: answer the client or escalate to the analyst
|
|
25
37
|
3 /orqen:analyze <KEY> Analysis with the analyst: criteria, lane, spec and the issue
|
|
26
38
|
4 /orqen:list issues orqen list issues [--json] Development queue (free, taken, came back)
|
|
@@ -34,11 +46,16 @@ Request commands for people:
|
|
|
34
46
|
ask <KEY> <question> Ask the requester on their ticket from any stage (/orqen:ask in the agent)
|
|
35
47
|
conversation <KEY> Refresh and show the request comments saved in the worq's conversation.json
|
|
36
48
|
status [KEY] [--json] Where a request is, who acts and what comes next (no KEY: all of them)
|
|
49
|
+
gate <KEY> [--json] The decision a person has to make on it now: what, who, the evidence and the commands that make it
|
|
50
|
+
whoami [--json] Who you are on the team: your name and roles (workflow.people in orqen/config.yaml)
|
|
51
|
+
watch [--json] [--every S] [--since 2h] [--once] Follow the worqs: each move as it happens (--json: one JSON line per event, for tools and CI)
|
|
37
52
|
worqs [--all] [--json] The worqs on this machine: orqen's unit of work, one per request (request + issue + branch + PR + record)
|
|
38
53
|
worq <KEY> [--json] One worq: state, request, issue, branch, PR and the files of its record in orqen/worqs/<KEY>/
|
|
39
54
|
merged <KEY> [--person N] Confirm the hand merge of an approved PR when orqen cannot read it from GitHub
|
|
40
|
-
new_worq "<title>" <brief.json|-> Worq with no request: creates its issue in the connector, skips support and analysis, born in DEVELOPMENT
|
|
55
|
+
new_worq "<title>" <brief.json|-> [--json] Worq with no request: creates its issue in the connector, skips support and analysis, born in DEVELOPMENT
|
|
41
56
|
--issue <KEY> Take an issue that already exists instead of creating one (the title defaults to the issue's)
|
|
57
|
+
<brief.json|-> Alone: the title goes in the brief ("title"), as orqen-studio sends it
|
|
58
|
+
{title, description} Only that: born in ANALYSIS, then /orqen:analyze asks the person what is missing
|
|
42
59
|
cancel <KEY> --reason T Close the request without delivering it: closes the PR unmerged, comments both tickets (CANCELLED)
|
|
43
60
|
release <KEY> Free a request held by an agent that is no longer working on it
|
|
44
61
|
comments <KEY> [--json] Read the request and its conversation with the client
|
|
@@ -71,8 +88,9 @@ Older names (still work, with a notice): pending → list requests · qa → rev
|
|
|
71
88
|
JSON for tools (orqen-studio):
|
|
72
89
|
status [KEY] --json · list requests|issues|prs --json · usage --json · tutorial --step <n> --json
|
|
73
90
|
spec [KEY|change] --json [--dir <worktree>] the spec in the neutral model of src/sdd (any SDD tool)
|
|
74
|
-
connectors get|check <json
|
|
75
|
-
connectors github-choices <json|-> <requests|issues> <repositories|projects|statuses
|
|
91
|
+
connectors get|check <json> [--matches]|set <json>|general-get|general-set [--json] (check --matches: requests the filter would bring, count + first 3)
|
|
92
|
+
connectors github-choices <json|-> <requests|issues> <repositories|projects|statuses>
|
|
93
|
+
<complete|pr|approve|cancel|new_worq> … --dry-run --json {"dry_run","ok","plan":[{kind,text}],"output","errors"}; gate actions that take it say "dry_run": true`;
|
|
76
94
|
/** The person at this machine: Git's user.name for this repository, otherwise the system user. */
|
|
77
95
|
export function quienSoy(repo) {
|
|
78
96
|
try {
|
|
@@ -89,6 +107,9 @@ export function quienSoy(repo) {
|
|
|
89
107
|
}
|
|
90
108
|
}
|
|
91
109
|
export async function runWorkflow(cmd, rest) {
|
|
110
|
+
// --dry-run --json (tools such as orqen-studio): one JSON with the plan and what the command said, nothing else on stdout
|
|
111
|
+
if (rest.includes("--dry-run") && rest.includes("--json"))
|
|
112
|
+
return dryRunJson(cmd, rest);
|
|
92
113
|
let dry;
|
|
93
114
|
try {
|
|
94
115
|
await runCommand(cmd, rest, (d) => { dry = d; });
|
|
@@ -98,7 +119,45 @@ export async function runWorkflow(cmd, rest) {
|
|
|
98
119
|
} // what it would have done, and the temporary copy is deleted
|
|
99
120
|
}
|
|
100
121
|
/** Options the workflow commands take. One that is not here is a typo, and ignoring it can do the wrong thing (`--chnges` approves; `--isue` creates a new issue). */
|
|
101
|
-
const KNOWN_OPTIONS = new Set(["agent", "all", "analyst", "apply", "changes", "comment", "dir", "dry-run", "force", "issue", "json", "loop", "person", "reason", "report", "since", "step", "title", "verdict"]);
|
|
122
|
+
const KNOWN_OPTIONS = new Set(["agent", "all", "analyst", "apply", "changes", "comment", "dir", "dry-run", "every", "force", "issue", "json", "loop", "matches", "mine", "once", "person", "reason", "report", "since", "step", "title", "verdict"]);
|
|
123
|
+
/**
|
|
124
|
+
* `<command> --dry-run --json`: {"dry_run": true, "ok", "plan": [{kind, text}], "output": [lines], "errors": [lines]}.
|
|
125
|
+
* `ok` is false when the command would fail (its checks did not pass): `errors` says why and `plan` is what it got to do.
|
|
126
|
+
*/
|
|
127
|
+
async function dryRunJson(cmd, rest) {
|
|
128
|
+
let dry;
|
|
129
|
+
const output = [], errors = [];
|
|
130
|
+
const { log, error } = console;
|
|
131
|
+
const keep = (to) => (...a) => { for (const l of a.map((x) => typeof x === "string" ? x : JSON.stringify(x)).join(" ").split("\n"))
|
|
132
|
+
if (l.trim())
|
|
133
|
+
to.push(l); };
|
|
134
|
+
console.log = keep(output);
|
|
135
|
+
console.error = keep(errors);
|
|
136
|
+
const before = process.exitCode;
|
|
137
|
+
process.exitCode = 0;
|
|
138
|
+
let plan = [];
|
|
139
|
+
try {
|
|
140
|
+
await runCommand(cmd, rest, (d) => { dry = d; });
|
|
141
|
+
}
|
|
142
|
+
catch (e) {
|
|
143
|
+
errors.push(e.message);
|
|
144
|
+
process.exitCode = 1;
|
|
145
|
+
}
|
|
146
|
+
finally {
|
|
147
|
+
const d = dry;
|
|
148
|
+
if (d) {
|
|
149
|
+
plan = d.report();
|
|
150
|
+
d.finish(() => { });
|
|
151
|
+
}
|
|
152
|
+
console.log = log;
|
|
153
|
+
console.error = error;
|
|
154
|
+
}
|
|
155
|
+
const ok = !process.exitCode && !!dry;
|
|
156
|
+
process.exitCode = before; // the JSON says whether it would work; the call itself worked
|
|
157
|
+
// the line every dry run prints first is for people
|
|
158
|
+
const said = output.filter((l) => !l.startsWith("DRY RUN:"));
|
|
159
|
+
console.log(JSON.stringify({ dry_run: true, command: cmd, ok, plan, output: said, errors }, null, 2));
|
|
160
|
+
}
|
|
102
161
|
async function runCommand(cmd, rest, onDryRun) {
|
|
103
162
|
const unknown = rest.filter((a) => /^--[A-Za-z]/.test(a) && !KNOWN_OPTIONS.has(a.slice(2).split("=")[0]));
|
|
104
163
|
if (unknown.length) {
|
|
@@ -177,6 +236,9 @@ async function runCommand(cmd, rest, onDryRun) {
|
|
|
177
236
|
: "> **Unattended mode: nobody can answer you.** Do not assume. If a doubt changes the outcome, run " +
|
|
178
237
|
`\`orqen block ${key} "<specific question>"\`; a person answers it on the ticket.`,
|
|
179
238
|
"",
|
|
239
|
+
...(ctx.no_client ? [`> **No client: this worq was started by the team.** ${ctx.requester ?? "The person you are working with"} is the requester. ` +
|
|
240
|
+
"Ask them directly here whatever the description leaves open (one question at a time, with your recommendation); " +
|
|
241
|
+
`do not use \`orqen ask\` or wait for answers on the ticket.`, ""] : []),
|
|
180
242
|
guide(s),
|
|
181
243
|
"",
|
|
182
244
|
// the feedback loop: what the team corrected in this stage before (orqen learn --apply)
|
|
@@ -252,7 +314,13 @@ async function runCommand(cmd, rest, onDryRun) {
|
|
|
252
314
|
console.log(` ${b.work.padEnd(12)} ${(b.lane ?? "").padEnd(7)} ${b.pr}\n${"".padEnd(15)}${b.qa ? `QA ${b.qa} · ` : ""}review: ${b.review?.status}${b.review?.detail ? ` (${b.review.detail})` : ""}${ciText(b.checks)}`);
|
|
253
315
|
return;
|
|
254
316
|
}
|
|
255
|
-
const
|
|
317
|
+
const mine = has("mine");
|
|
318
|
+
let board = await flow.board(all);
|
|
319
|
+
// --mine: only what waits for one of the roles of the person at this machine (workflow.people)
|
|
320
|
+
if (mine) {
|
|
321
|
+
const me2 = whoIs(cfg.people, me);
|
|
322
|
+
board = board.filter((b) => me2.roles.includes(b.role));
|
|
323
|
+
}
|
|
256
324
|
if (what === "issues") {
|
|
257
325
|
const q = board.filter((b) => b.state === "DEVELOPMENT");
|
|
258
326
|
if (json)
|
|
@@ -320,20 +388,34 @@ async function runCommand(cmd, rest, onDryRun) {
|
|
|
320
388
|
}
|
|
321
389
|
case "new-worq":
|
|
322
390
|
case "new_worq": {
|
|
391
|
+
let json = false;
|
|
323
392
|
try {
|
|
324
393
|
const issueFlag = flag("issue");
|
|
325
394
|
const existing = issueFlag ? toKey(issueFlag) : undefined;
|
|
395
|
+
json = has("json");
|
|
326
396
|
// with --issue the title is optional (the issue's is used): orqen new_worq --issue GH-12 brief.json
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
397
|
+
// with only the brief, its "title" is the worq's (orqen-studio sends everything on stdin: no quoting of the title on Windows)
|
|
398
|
+
const usage = 'Usage: orqen new_worq "<title>" <brief.json|-> [--person NAME] or orqen new_worq <brief.json|-> or orqen new_worq --issue <KEY> ["<title>"] <brief.json|-> (brief: {"title", "description", "acceptance_criteria": [...], "plan": [...], "estimated_hours"})';
|
|
399
|
+
let [title, src] = rest.length === 1 ? ["", rest[0]] : [rest[0] ?? "", rest[1]];
|
|
400
|
+
if (!src)
|
|
401
|
+
throw new Error(usage);
|
|
330
402
|
const raw = JSON.parse(src === "-" ? readFileSync(0, "utf8") : readFileSync(src, "utf8"));
|
|
403
|
+
if (!title && typeof raw?.title === "string")
|
|
404
|
+
title = raw.title;
|
|
405
|
+
if (!title.trim() && !existing)
|
|
406
|
+
throw new Error(usage);
|
|
331
407
|
const r = await flow.newWorq(title, raw, me || agent, existing);
|
|
408
|
+
// --json: for orqen-studio's "New Worq" (the worq it has to open, or the error to show in the form)
|
|
409
|
+
if (json)
|
|
410
|
+
return console.log(JSON.stringify({ ok: true, ...r, taken: !!existing }));
|
|
332
411
|
console.log(`✔ ${r.key} ${existing ? "taken" : "created"} in ${r.state}: issue ${r.url} (no client request) · worq: ${r.dir}/`);
|
|
333
|
-
console.log(` Next:
|
|
412
|
+
console.log(` Next: ${"next" in r ? r.next : `/orqen:implement ${r.key}`}`);
|
|
334
413
|
}
|
|
335
414
|
catch (e) {
|
|
336
|
-
|
|
415
|
+
if (json)
|
|
416
|
+
console.log(JSON.stringify({ ok: false, error: e.message }));
|
|
417
|
+
else
|
|
418
|
+
console.error(`✘ ${e.message}`);
|
|
337
419
|
process.exitCode = 1;
|
|
338
420
|
}
|
|
339
421
|
return;
|
|
@@ -353,6 +435,77 @@ async function runCommand(cmd, rest, onDryRun) {
|
|
|
353
435
|
}
|
|
354
436
|
return;
|
|
355
437
|
}
|
|
438
|
+
case "gate": {
|
|
439
|
+
const json = has("json");
|
|
440
|
+
try {
|
|
441
|
+
const key = toKey(rest[0]);
|
|
442
|
+
if (!key)
|
|
443
|
+
throw new Error("Usage: orqen gate <KEY> [--json]");
|
|
444
|
+
const g = flow.gate(key);
|
|
445
|
+
const me2 = whoIs(cfg.people, me);
|
|
446
|
+
// whether the person at this machine is the one who decides (by role; the approvers lists, if any, still apply on the tickets)
|
|
447
|
+
const yours = g.waiting && !g.outside && me2.roles.includes(g.role);
|
|
448
|
+
if (json)
|
|
449
|
+
return console.log(JSON.stringify({ ...g, yours, me: me2.name }, null, 2));
|
|
450
|
+
if (!g.waiting)
|
|
451
|
+
return console.log(`${g.key} (${g.state}): nobody has to decide anything now.${g.what ? ` ${g.what}.` : ""}`);
|
|
452
|
+
console.log(`${g.key} (${g.state}) · ${g.role}${g.who ? ` (${g.who.join(", ")})` : ""}${yours ? " · it is yours" : ""}`);
|
|
453
|
+
console.log(` ${g.what}`);
|
|
454
|
+
for (const e of g.evidence)
|
|
455
|
+
console.log(` ${e.ok === true ? "✔" : e.ok === false ? "✘" : "?"} ${e.detail ?? e.label}`);
|
|
456
|
+
for (const a of g.actions)
|
|
457
|
+
console.log(` → ${a.label}: ${a.kind === "cli" ? `orqen ${a.cli.join(" ")}${a.text ? ` (${a.text}, on stdin)` : ""}` : a.agent}`);
|
|
458
|
+
}
|
|
459
|
+
catch (e) {
|
|
460
|
+
if (json)
|
|
461
|
+
console.log(JSON.stringify({ error: e.message }));
|
|
462
|
+
else
|
|
463
|
+
console.error(`✘ ${e.message}`);
|
|
464
|
+
process.exitCode = 1;
|
|
465
|
+
}
|
|
466
|
+
return;
|
|
467
|
+
}
|
|
468
|
+
case "watch": {
|
|
469
|
+
// every few seconds, the new events of the local record (what `orqen cycle`, the agents and the people do here)
|
|
470
|
+
const json = has("json");
|
|
471
|
+
const every = Math.max(1, Number(flag("every") ?? 5));
|
|
472
|
+
const sinceArg = flag("since");
|
|
473
|
+
const once = has("once");
|
|
474
|
+
const me2 = whoIs(cfg.people, me);
|
|
475
|
+
let last = sinceArg ? new Date(/^\d+[mhd]$/.test(sinceArg) ? Date.now() - Number(sinceArg.slice(0, -1)) * { m: 60e3, h: 3600e3, d: 86400e3 }[sinceArg.slice(-1)] : sinceArg).toISOString() : new Date().toISOString();
|
|
476
|
+
const tick = () => {
|
|
477
|
+
const fresh = [];
|
|
478
|
+
for (const item of store.all())
|
|
479
|
+
for (const ev of store.events(item.key))
|
|
480
|
+
if (ev.ts > last)
|
|
481
|
+
fresh.push({ key: item.key, title: item.title, ev });
|
|
482
|
+
fresh.sort((a, b) => a.ev.ts.localeCompare(b.ev.ts));
|
|
483
|
+
for (const { key, title, ev } of fresh) {
|
|
484
|
+
const item = store.get(key);
|
|
485
|
+
const role = item ? flow.boardItem(item).role : undefined;
|
|
486
|
+
const forMe = !!role && ["support", "analyst", "qa", "senior"].includes(role) && me2.roles.includes(role) && ev.to === item?.state;
|
|
487
|
+
if (json)
|
|
488
|
+
console.log(JSON.stringify({ key, title, ...ev, role, for_me: forMe }));
|
|
489
|
+
else
|
|
490
|
+
console.log(`${ev.ts.slice(11, 16)} ${key.padEnd(10)} ${ev.from === ev.to ? ev.to : `${ev.from} → ${ev.to}`} ${ev.detail}${ev.person ? ` (${ev.person})` : ""}${forMe ? " ← yours" : ""}`);
|
|
491
|
+
last = ev.ts;
|
|
492
|
+
}
|
|
493
|
+
};
|
|
494
|
+
tick();
|
|
495
|
+
if (once)
|
|
496
|
+
return;
|
|
497
|
+
if (!json)
|
|
498
|
+
console.error(`Watching the worqs every ${every} s (Ctrl+C to stop)…`);
|
|
499
|
+
await new Promise(() => { setInterval(tick, every * 1000); });
|
|
500
|
+
return;
|
|
501
|
+
}
|
|
502
|
+
case "whoami": {
|
|
503
|
+
const w = whoIs(cfg.people, me);
|
|
504
|
+
if (has("json"))
|
|
505
|
+
return console.log(JSON.stringify(w));
|
|
506
|
+
console.log(`${w.name ?? "(no git user.name)"} · ${w.roles.length ? w.roles.join(", ") : "no roles"}${!w.configured ? " (workflow.people is not set: everyone does everything)" : !w.listed ? " (not listed in workflow.people of orqen/config.yaml)" : ""}`);
|
|
507
|
+
return;
|
|
508
|
+
}
|
|
356
509
|
case "merged": {
|
|
357
510
|
try {
|
|
358
511
|
const key = toKey(rest[0]);
|
|
@@ -503,7 +656,8 @@ async function runCommand(cmd, rest, onDryRun) {
|
|
|
503
656
|
return dispatch();
|
|
504
657
|
}
|
|
505
658
|
try {
|
|
506
|
-
const
|
|
659
|
+
const reasonArg = flag("reason") ?? "";
|
|
660
|
+
const reason = reasonArg === "-" ? readFileSync(0, "utf8") : reasonArg;
|
|
507
661
|
const reportFile = flag("report");
|
|
508
662
|
const key = toKey(rest[0]);
|
|
509
663
|
const decision = rest[1] ?? "";
|
|
@@ -582,7 +736,7 @@ async function runCommand(cmd, rest, onDryRun) {
|
|
|
582
736
|
const files = item.recovered ? [] : worqFiles(join(cfg.factoryDir, item.key));
|
|
583
737
|
const events = store.events(item.key);
|
|
584
738
|
if (json)
|
|
585
|
-
return console.log(JSON.stringify({ ...w, files, events: events.slice(-10) }, null, 2));
|
|
739
|
+
return console.log(JSON.stringify({ ...w, files, events: events.slice(-10), usage: runUsage(cfg.repoPath, item.key) }, null, 2));
|
|
586
740
|
console.log(`Worq ${w.key}${w.title ? ` — ${w.title}` : ""}`);
|
|
587
741
|
console.log(` State: ${w.state}${w.round > 1 ? ` (round ${w.round})` : ""}${w.lane ? ` · lane ${w.lane}` : ""}${w.route && w.route !== "development" ? ` · ${w.route}` : ""}`);
|
|
588
742
|
if (w.next[0])
|
|
@@ -620,7 +774,7 @@ async function runCommand(cmd, rest, onDryRun) {
|
|
|
620
774
|
const k = toKey(rest[0]);
|
|
621
775
|
const item = flow.item(k) ?? await flow.peek(k);
|
|
622
776
|
const b = item ? flow.boardItem(item) : undefined;
|
|
623
|
-
return console.log(JSON.stringify(item ? { ...item, role: b.role, next: b.next, qa_status: b.qa, returned: b.returned, events: store.events(item.key) } : null, null, 2));
|
|
777
|
+
return console.log(JSON.stringify(item ? { ...item, role: b.role, next: b.next, qa_status: b.qa, returned: b.returned, events: store.events(item.key), usage: runUsage(cfg.repoPath, item.key), bots: item ? await stageBots(cfg.repoPath, item.state) : [] } : null, null, 2));
|
|
624
778
|
}
|
|
625
779
|
return console.log(JSON.stringify(store.all().map((r) => ({
|
|
626
780
|
key: r.key, title: r.title ?? r.artifacts?.ANALYSIS?.summary, state: r.state, issue: r.issue, lane: r.lane, route: r.route, round: r.round, branch: r.branch || undefined,
|
|
@@ -704,7 +858,8 @@ async function runCommand(cmd, rest, onDryRun) {
|
|
|
704
858
|
if (rest[0] === "check") {
|
|
705
859
|
const { checkDraft, parseDraft } = await import("../lib/connectors-edit.js");
|
|
706
860
|
const { leerEnv } = await import("../lib/env.js");
|
|
707
|
-
const
|
|
861
|
+
const matches = has("matches");
|
|
862
|
+
const result = await checkDraft(parseDraft(draftInput()), providerEnv(cfg.repoPath), { matches });
|
|
708
863
|
return console.log(JSON.stringify({ connectors: result }, null, 2));
|
|
709
864
|
}
|
|
710
865
|
if (rest[0] === "set") {
|
package/dist/index.js
CHANGED
|
@@ -10,9 +10,10 @@ import { lang, tutorial } from "./commands/tutorial.js";
|
|
|
10
10
|
import { VERSION_CLI } from "./lib/system.js";
|
|
11
11
|
import { mostrarLogo } from "./ui/logo.js";
|
|
12
12
|
import { usageCommand } from "./lib/usage.js";
|
|
13
|
-
import { EVAL_HELP, evalCommand, learnCommand } from "./commands/eval.js";
|
|
13
|
+
import { EVAL_HELP, evalCommand, learnCommand, runCommand, feedbackCommand } from "./commands/eval.js";
|
|
14
14
|
import { SPEC_HELP, specCommand } from "./commands/spec.js";
|
|
15
15
|
import { practice } from "./practice/practice.js";
|
|
16
|
+
import { BOTS_HELP, botsCommand, mcpCommand } from "./commands/bots.js";
|
|
16
17
|
const AYUDA = `
|
|
17
18
|
Usage: orqen <command> [options]
|
|
18
19
|
orqen This help (the desktop app is a separate project: github.com/sistemas-telpin/orqen-studio)
|
|
@@ -43,6 +44,7 @@ Commands:
|
|
|
43
44
|
${SWARM_HELP}
|
|
44
45
|
${EVAL_HELP}
|
|
45
46
|
${SPEC_HELP}
|
|
47
|
+
${BOTS_HELP}
|
|
46
48
|
--version, -v Show version
|
|
47
49
|
--help, -h Show this help · orqen help internal: agent-only commands and JSON for tools
|
|
48
50
|
|
|
@@ -73,10 +75,18 @@ async function main() {
|
|
|
73
75
|
return desktopRelease(crudos[1] ?? "");
|
|
74
76
|
if (crudos[0] === "learn")
|
|
75
77
|
return learnCommand(crudos.slice(1));
|
|
78
|
+
if (crudos[0] === "run")
|
|
79
|
+
return runCommand(crudos.slice(1));
|
|
80
|
+
if (crudos[0] === "feedback")
|
|
81
|
+
return feedbackCommand(crudos.slice(1));
|
|
76
82
|
if (crudos[0] === "spec")
|
|
77
83
|
return specCommand(crudos.slice(1));
|
|
78
84
|
if (crudos[0] === "practice")
|
|
79
85
|
return practice(crudos.slice(1));
|
|
86
|
+
if (crudos[0] === "bots")
|
|
87
|
+
return botsCommand(crudos.slice(1));
|
|
88
|
+
if (crudos[0] === "mcp")
|
|
89
|
+
return mcpCommand(crudos.slice(1));
|
|
80
90
|
// `orqen env test e2e -- <args>`: everything after `--` goes to the test command untouched
|
|
81
91
|
const sep = crudos.indexOf("--");
|
|
82
92
|
const extra = sep >= 0 ? crudos.slice(sep + 1) : [];
|
package/dist/lib/bots.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bot profiles: specialist guidance the Worq agent applies in the stages a project assigns them, with the MCP servers it may
|
|
3
|
+
* use while it does. Personal (each person keeps their own), in ~/.orqen/bots.json; each bot says, per repository, in which
|
|
4
|
+
* stages it is available. `orqen bots` lists them, `orqen bots set -` saves them, and `orqen status KEY --json` gives the
|
|
5
|
+
* agent the ones of the Worq's current stage, so any agent (Studio's or one started in a terminal) gets the same guidance.
|
|
6
|
+
*/
|
|
7
|
+
import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
8
|
+
import { homedir } from "node:os";
|
|
9
|
+
import { dirname, join } from "node:path";
|
|
10
|
+
import { z } from "zod";
|
|
11
|
+
import { claudeTool, samePath } from "./mcp.js";
|
|
12
|
+
export const STAGES = [
|
|
13
|
+
"NEW", "SUPPORT", "ANALYSIS", "WAITING_CLIENT", "DEVELOPMENT", "TESTING", "QA_REVIEW", "CODE_REVIEW", "DELIVERY",
|
|
14
|
+
"ACCEPTANCE", "EXECUTION", "EXECUTION_APPROVAL", "APPLICATION", "VERIFICATION", "BLOCKED",
|
|
15
|
+
];
|
|
16
|
+
export const Bot = z.object({
|
|
17
|
+
name: z.string().trim().min(1),
|
|
18
|
+
prompt: z.string(),
|
|
19
|
+
/** repository path → stages where the bot is available there. */
|
|
20
|
+
projects: z.record(z.string(), z.array(z.enum(STAGES))).default({}),
|
|
21
|
+
/** MCP servers (names, as `orqen mcp` lists them) the bot may use. */
|
|
22
|
+
connectors: z.array(z.string()).default([]),
|
|
23
|
+
/** How Studio draws it; kept as it comes. */
|
|
24
|
+
face: z.unknown().optional(),
|
|
25
|
+
});
|
|
26
|
+
export const Bots = z.array(Bot).superRefine((bots, ctx) => {
|
|
27
|
+
const seen = new Set();
|
|
28
|
+
for (const [i, b] of bots.entries()) {
|
|
29
|
+
const k = b.name.toLowerCase();
|
|
30
|
+
if (seen.has(k))
|
|
31
|
+
ctx.addIssue({ code: "custom", path: [i, "name"], message: `two bots are called "${b.name}"` });
|
|
32
|
+
seen.add(k);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
export const botsFile = () => join(process.env.ORQEN_USER_CONFIG_DIR || join(homedir(), ".orqen"), "bots.json");
|
|
36
|
+
export function readBots(file = botsFile()) {
|
|
37
|
+
if (!existsSync(file))
|
|
38
|
+
return [];
|
|
39
|
+
const raw = JSON.parse(readFileSync(file, "utf8"));
|
|
40
|
+
return Bots.parse(Array.isArray(raw) ? raw : raw.bots ?? []);
|
|
41
|
+
}
|
|
42
|
+
/** Validates and writes (temporary file + rename, so a reader never sees half a file). */
|
|
43
|
+
export function writeBots(input, file = botsFile()) {
|
|
44
|
+
const bots = Bots.parse(Array.isArray(input) ? input : input?.bots);
|
|
45
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
46
|
+
const tmp = `${file}.tmp`;
|
|
47
|
+
writeFileSync(tmp, JSON.stringify({ bots }, null, 2) + "\n");
|
|
48
|
+
renameSync(tmp, file);
|
|
49
|
+
return bots;
|
|
50
|
+
}
|
|
51
|
+
/** Stages of a bot in this repository ([] = not used here). */
|
|
52
|
+
export function stagesIn(bot, repo) {
|
|
53
|
+
return Object.entries(bot.projects).find(([k]) => samePath(k, repo))?.[1] ?? [];
|
|
54
|
+
}
|
|
55
|
+
/** What the agent gets for a Worq in `stage`: the bots assigned to it here, with their guidance and servers. */
|
|
56
|
+
export function botsFor(bots, repo, stage) {
|
|
57
|
+
return bots.filter((b) => stagesIn(b, repo).includes(stage)).map((b) => ({ name: b.name, prompt: b.prompt, connectors: b.connectors }));
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* The tools to allow in one agent run of this repository: the servers of every bot assigned to any stage here. A run can go
|
|
61
|
+
* through several stages (it checks `orqen status` after each one), so they are granted for the run; which bot applies in
|
|
62
|
+
* each stage comes from `orqen status`.
|
|
63
|
+
*/
|
|
64
|
+
export function toolsIn(bots, repo) {
|
|
65
|
+
const out = [];
|
|
66
|
+
for (const b of bots)
|
|
67
|
+
if (stagesIn(b, repo).length)
|
|
68
|
+
for (const c of b.connectors)
|
|
69
|
+
if (!out.includes(claudeTool(c)))
|
|
70
|
+
out.push(claudeTool(c));
|
|
71
|
+
return out;
|
|
72
|
+
}
|
package/dist/lib/config-keys.js
CHANGED
|
@@ -46,7 +46,7 @@ export const CONFIG_KEYS = {
|
|
|
46
46
|
support: "soporte",
|
|
47
47
|
approvers: { as: "aprobadores", keys: { analysis: "analisis", qa: "qa", code: "codigo", client: "cliente", execution: "ejecucion" } },
|
|
48
48
|
code_review: { as: "code_review", keys: { gate: "gate", reviewers: "revisores" } },
|
|
49
|
-
devel_branch: "rama_desarrollo", pr_command: "comando_pr", test_command: "comando_tests",
|
|
49
|
+
devel_branch: "rama_desarrollo", pr_command: "comando_pr", test_command: "comando_tests", people: "personas",
|
|
50
50
|
lock_minutes: "lock_min", interval_seconds: "intervalo_seg",
|
|
51
51
|
},
|
|
52
52
|
},
|
package/dist/lib/config.js
CHANGED
|
@@ -43,6 +43,12 @@ export const Flujo = z.object({
|
|
|
43
43
|
comando_pr: z.string().nullish(),
|
|
44
44
|
/** Full test suite run in TESTING (TEST_COMMAND). */
|
|
45
45
|
comando_tests: z.string().nullish(),
|
|
46
|
+
/**
|
|
47
|
+
* Who does what on this team: the name of each person (their git user.name) → their roles (support, analyst, developer, qa,
|
|
48
|
+
* senior), as a YAML list or "a, b". Studio and `orqen whoami` use it to show each person what waits for them. Absent = everyone
|
|
49
|
+
* does everything (a small team).
|
|
50
|
+
*/
|
|
51
|
+
personas: z.record(z.string(), z.preprocess((v) => typeof v === "string" ? v.split(",").map((s) => s.trim()).filter(Boolean) : v ?? [], z.array(z.enum(["support", "analyst", "developer", "qa", "senior"])))).optional(),
|
|
46
52
|
/** Minutes a taken request stays reserved (ORQEN_LOCK_MIN) and seconds between rounds of `orqen cycle --loop` (ORQEN_INTERVAL_SEC). */
|
|
47
53
|
lock_min: z.number().int().positive().nullish(),
|
|
48
54
|
intervalo_seg: z.number().int().positive().nullish(),
|
|
@@ -44,6 +44,29 @@ export function parseDraft(input) {
|
|
|
44
44
|
const env = Object.fromEntries(Object.entries(raw.env ?? {}).filter(([, v]) => typeof v === "string" && v.trim() !== "").map(([k, v]) => [k, v.trim()]));
|
|
45
45
|
return { conectores: parsed.data, env };
|
|
46
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* The requests the flow would pick up with this connector: the same `pending()` the flow uses (its filter), counted, with the
|
|
49
|
+
* first few titles. Lets a person try a filter before saving it.
|
|
50
|
+
*/
|
|
51
|
+
async function requestMatches(t, n = 3) {
|
|
52
|
+
try {
|
|
53
|
+
const keys = await t.pending();
|
|
54
|
+
const sample = [];
|
|
55
|
+
for (const key of keys.slice(0, n)) {
|
|
56
|
+
try {
|
|
57
|
+
const x = await t.ticket(key);
|
|
58
|
+
sample.push({ key: x.key, title: x.title, ...(x.status ? { status: x.status } : {}) });
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
sample.push({ key, title: "" });
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return { count: keys.length, sample };
|
|
65
|
+
}
|
|
66
|
+
catch (e) {
|
|
67
|
+
return { count: 0, sample: [], error: e.message.split("\n")[0] };
|
|
68
|
+
}
|
|
69
|
+
}
|
|
47
70
|
/** Lists choices using draft credentials, without requiring a repository or saving the draft. */
|
|
48
71
|
export async function githubChoices(draft, current, role, resource) {
|
|
49
72
|
role = role === "external" ? "requests" : role === "internal" ? "issues" : role; // names used by earlier versions of the app
|
|
@@ -67,13 +90,16 @@ export async function githubChoices(draft, current, role, resource) {
|
|
|
67
90
|
}
|
|
68
91
|
}
|
|
69
92
|
/** Checks each connector of the draft against the tool, with the draft secrets over the current ones. Saves nothing. */
|
|
70
|
-
export async function checkDraft(draft, current) {
|
|
93
|
+
export async function checkDraft(draft, current, opts = {}) {
|
|
71
94
|
const env = { ...current, ...draft.env };
|
|
72
95
|
const one = async (role, c) => {
|
|
73
96
|
if (!c)
|
|
74
97
|
return { role, configured: false };
|
|
75
98
|
const t = trackerFor(connectorSettings(c, env));
|
|
76
|
-
|
|
99
|
+
const r = { role, configured: true, kind: t.kind, label: t.label, ...(await t.check()) };
|
|
100
|
+
if (opts.matches && role === "requests" && r.ok)
|
|
101
|
+
r.matches = await requestMatches(t);
|
|
102
|
+
return r;
|
|
77
103
|
};
|
|
78
104
|
return [await one("requests", draft.conectores.requests), await one("issues", draft.conectores.issues)];
|
|
79
105
|
}
|
package/dist/lib/mcp.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The MCP servers the agents of this machine can reach, read from where each agent keeps them: the project's `.mcp.json`
|
|
3
|
+
* and `.gemini/settings.json`, Claude Code's ~/.claude.json (this project's and the global ones), Codex's
|
|
4
|
+
* ~/.codex/config.toml and Gemini's ~/.gemini/settings.json. orqen only reads them: they are added in each agent.
|
|
5
|
+
* `orqen mcp --json` (orqen-studio lists them to pick the ones a bot may use).
|
|
6
|
+
*/
|
|
7
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
8
|
+
import { homedir } from "node:os";
|
|
9
|
+
import { join } from "node:path";
|
|
10
|
+
function json(file) {
|
|
11
|
+
try {
|
|
12
|
+
return existsSync(file) ? JSON.parse(readFileSync(file, "utf8")) : undefined;
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
const servers = (v) => {
|
|
19
|
+
const o = v?.mcpServers;
|
|
20
|
+
return o && typeof o === "object" ? Object.keys(o) : [];
|
|
21
|
+
};
|
|
22
|
+
/** `[mcp_servers.<name>]` tables of a Codex config (not their sub-tables such as `.env`). */
|
|
23
|
+
export function tomlServers(text) {
|
|
24
|
+
const out = [];
|
|
25
|
+
for (const raw of text.split(/\r?\n/)) {
|
|
26
|
+
const m = /^\[mcp_servers\.(.+)\]$/.exec(raw.trim());
|
|
27
|
+
if (!m)
|
|
28
|
+
continue;
|
|
29
|
+
const name = m[1].replace(/^"|"$/g, "");
|
|
30
|
+
if (name && !name.includes("."))
|
|
31
|
+
out.push(name);
|
|
32
|
+
}
|
|
33
|
+
return out;
|
|
34
|
+
}
|
|
35
|
+
/** Repository paths compare without caring for slashes, case (Windows) or a trailing slash. */
|
|
36
|
+
export const samePath = (a, b) => {
|
|
37
|
+
const n = (p) => p.replace(/\\/g, "/").replace(/\/+$/, "").toLowerCase();
|
|
38
|
+
return n(a) === n(b);
|
|
39
|
+
};
|
|
40
|
+
/** Every server found, each name once (the first source wins), in a stable order. */
|
|
41
|
+
export function mcpServers(repo, home = homedir()) {
|
|
42
|
+
const out = [];
|
|
43
|
+
const add = (names, source, file) => {
|
|
44
|
+
for (const name of names)
|
|
45
|
+
if (!out.some((s) => s.name === name))
|
|
46
|
+
out.push({ name, source, file });
|
|
47
|
+
};
|
|
48
|
+
if (repo) {
|
|
49
|
+
add(servers(json(join(repo, ".mcp.json"))), "project", join(repo, ".mcp.json"));
|
|
50
|
+
add(servers(json(join(repo, ".gemini", "settings.json"))), "gemini", join(repo, ".gemini", "settings.json"));
|
|
51
|
+
}
|
|
52
|
+
const claudeFile = join(home, ".claude.json");
|
|
53
|
+
const claude = json(claudeFile);
|
|
54
|
+
if (claude) {
|
|
55
|
+
if (repo) {
|
|
56
|
+
const projects = (claude.projects ?? {});
|
|
57
|
+
const mine = Object.entries(projects).find(([k]) => samePath(k, repo));
|
|
58
|
+
add(servers(mine?.[1]), "claude", claudeFile);
|
|
59
|
+
}
|
|
60
|
+
add(servers(claude), "claude", claudeFile);
|
|
61
|
+
}
|
|
62
|
+
const codex = join(home, ".codex", "config.toml");
|
|
63
|
+
try {
|
|
64
|
+
if (existsSync(codex))
|
|
65
|
+
add(tomlServers(readFileSync(codex, "utf8")), "codex", codex);
|
|
66
|
+
}
|
|
67
|
+
catch { /* unreadable: skipped */ }
|
|
68
|
+
const gemini = join(home, ".gemini", "settings.json");
|
|
69
|
+
add(servers(json(gemini)), "gemini", gemini);
|
|
70
|
+
return out;
|
|
71
|
+
}
|
|
72
|
+
/** The Claude Code tool pattern that allows every tool of a server. */
|
|
73
|
+
export const claudeTool = (name) => `mcp__${name}`;
|
|
@@ -144,6 +144,9 @@ export function clientTurn(key) {
|
|
|
144
144
|
return { key, replied: false, reason: "nothing new from the team" };
|
|
145
145
|
if (ticket.clientSeen === last.id)
|
|
146
146
|
return { key, replied: false, reason: "already read" };
|
|
147
|
+
// it failed on this comment a moment ago (no Claude Code, no session…): wait before spawning the client again
|
|
148
|
+
if (ticket.clientFailed?.id === last.id && Date.now() - Date.parse(ticket.clientFailed.at) < 90_000)
|
|
149
|
+
return { key, replied: false, reason: "failed recently" };
|
|
147
150
|
// one answer at a time per ticket (the app asks every few seconds)
|
|
148
151
|
const lock = join(tmpdir(), `orqen-practice-${ticket.key}.lock`);
|
|
149
152
|
try {
|
|
@@ -166,6 +169,9 @@ export function clientTurn(key) {
|
|
|
166
169
|
const [bin, ...args] = partirComando(cmd);
|
|
167
170
|
const r = ejecutar(bin, args, { cwd: tmpdir(), entrada: prompt, timeoutMs: 180_000 });
|
|
168
171
|
if (r.codigo !== 0 || r.error) {
|
|
172
|
+
const failed = t.read(ticket.key);
|
|
173
|
+
failed.clientFailed = { id: last.id, at: new Date().toISOString() };
|
|
174
|
+
t.write(failed);
|
|
169
175
|
const why = r.error ? r.error.code === "ENOENT" ? `${bin} is not installed or not in the PATH` : r.error.message : (r.stderr || r.stdout).trim().slice(0, 300);
|
|
170
176
|
throw new Error(`${bin}: ${why || `exit code ${r.codigo}`}`);
|
|
171
177
|
}
|
|
@@ -6,6 +6,8 @@ allowed-tools: Bash(orqen:*), AskUserQuestion
|
|
|
6
6
|
|
|
7
7
|
`$ARGUMENTS` is the title of the work, or the key of an issue that already exists (e.g. `GH-12`, `DEV-34`). If it is missing, ask the person for it. This is work the team starts itself: there is no client or request, so support and analysis are skipped. orqen creates the issue in the connector the project uses (the issues connector, or the requests one when there is none), or takes the existing one.
|
|
8
8
|
|
|
9
|
+
**Short path (only a title and a description).** If the person just wants to describe the work in their own words and let the analysis work out the rest, do not build the brief: run `orqen new_worq <brief.json>` with `{ "title": "...", "description": "..." }` (the description as they wrote it, at least 20 characters). The worq is born in ANALYSIS with the person as its analyst and requester; continue with `/orqen:analyze <KEY>`, which asks them what is missing, picks the lane and writes the spec. orqen studio's "Nuevo Worq" does exactly this.
|
|
10
|
+
|
|
9
11
|
If it is an existing issue, read it first (`orqen comments <KEY>` shows its title, description and comments) and start the brief from what it says.
|
|
10
12
|
|
|
11
13
|
Talk with the person briefly, in their language, until you have what `orqen new_worq` needs. Ask only what you cannot infer, one question at a time with your recommendation:
|
package/dist/workflow/board.js
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
/** The roles a person can have on the team (workflow.people in orqen/config.yaml). */
|
|
2
|
+
export const PERSON_ROLES = ["support", "analyst", "developer", "qa", "senior"];
|
|
3
|
+
/**
|
|
4
|
+
* Who a person is on the team: their roles from workflow.people (the name as in git user.name, case and accents ignored).
|
|
5
|
+
* With no people configured everyone does everything (configured: false); a name that is not listed has no roles.
|
|
6
|
+
*/
|
|
7
|
+
export function whoIs(people, name) {
|
|
8
|
+
const norm = (s) => s.normalize("NFD").replace(/[\u0300-\u036f]/g, "").trim().toLowerCase();
|
|
9
|
+
const entries = Object.entries(people ?? {});
|
|
10
|
+
if (!entries.length)
|
|
11
|
+
return { name, roles: [...PERSON_ROLES], configured: false, listed: false };
|
|
12
|
+
const hit = name ? entries.find(([n]) => norm(n) === norm(name)) : undefined;
|
|
13
|
+
return { name: hit?.[0] ?? name, roles: hit ? hit[1].filter((r) => PERSON_ROLES.includes(r)) : [], configured: true, listed: !!hit };
|
|
14
|
+
}
|
|
1
15
|
/** The key a developer works with: the issue when there is one. */
|
|
2
16
|
export const workKey = (item) => item.issue ?? item.key;
|
|
3
17
|
/** The full lane goes through QA (QA_REVIEW, after TESTING) before the senior. */
|
package/dist/workflow/config.js
CHANGED
|
@@ -12,7 +12,7 @@ const env = (k, d = "") => process.env[k] ?? d;
|
|
|
12
12
|
const split = (v) => v.split(",").map((s) => s.trim()).filter(Boolean);
|
|
13
13
|
/** New variable name, falling back to the one used by earlier versions. */
|
|
14
14
|
const envL = (k, legacy, d = "") => envWithLegacy(process.env, k, legacy, d);
|
|
15
|
-
function repoRoot() {
|
|
15
|
+
export function repoRoot() {
|
|
16
16
|
try {
|
|
17
17
|
return execFileSync("git", ["rev-parse", "--show-toplevel"], { cwd: process.cwd(), encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] }).trim();
|
|
18
18
|
}
|
|
@@ -77,6 +77,7 @@ export function loadConfig(over = {}) {
|
|
|
77
77
|
// "jira" is the name used by earlier versions for "ticket"
|
|
78
78
|
codeReviewGate: ["ticket", "jira"].includes(env("CODE_REVIEW_GATE") || f?.code_review.gate || "github") ? "ticket" : "github",
|
|
79
79
|
githubReviewers: list("GITHUB_REVIEWERS", f?.code_review.revisores),
|
|
80
|
+
people: f?.personas ?? {},
|
|
80
81
|
openspecCmd: env("OPENSPEC_CMD") && env("OPENSPEC_CMD") !== "openspec" ? env("OPENSPEC_CMD") : existsSync(localOpenSpec) ? localOpenSpec : "openspec",
|
|
81
82
|
stateDir: envL("ORQEN_STATE_DIR", "REC_STATE_DIR") || (existsSync(localState) || !project ? localState : join(main, "orqen", "state")),
|
|
82
83
|
stagesDir: stages ?? join(TEMPLATES_DIR, "stages"),
|
package/dist/workflow/dry-run.js
CHANGED
|
@@ -12,7 +12,7 @@ import { join, relative } from "node:path";
|
|
|
12
12
|
import { Process } from "./process.js";
|
|
13
13
|
import { Store } from "./store.js";
|
|
14
14
|
import { branchFor } from "./workspace.js";
|
|
15
|
-
export
|
|
15
|
+
export { DRY_RUN_COMMANDS } from "./dry-run-commands.js";
|
|
16
16
|
const oneLine = (s, n = 110) => {
|
|
17
17
|
const first = s.split("\n").map((l) => l.trim()).find(Boolean) ?? "";
|
|
18
18
|
return first.length > n || s.trim().includes("\n") ? `${first.slice(0, n)}…` : first;
|
package/dist/workflow/process.js
CHANGED
|
@@ -20,6 +20,7 @@ import { canLinkNatively, isBotComment, isTransient, LEGACY_STATE_LABELS, STATE_
|
|
|
20
20
|
import { hoursOf } from "./openspec.js";
|
|
21
21
|
import { reviewSql } from "./sql.js";
|
|
22
22
|
import { testCoverage } from "./test-coverage.js";
|
|
23
|
+
import { DRY_RUN_COMMANDS } from "./dry-run-commands.js";
|
|
23
24
|
import { RoutedTracker } from "./routed.js";
|
|
24
25
|
import { newWorkItem } from "./store.js";
|
|
25
26
|
import { needsQa, nextSteps, returned, roleOf, workKey } from "./board.js";
|
|
@@ -296,6 +297,102 @@ export class Process {
|
|
|
296
297
|
}
|
|
297
298
|
return items;
|
|
298
299
|
}
|
|
300
|
+
// ================================================================ gate (`orqen gate`)
|
|
301
|
+
/**
|
|
302
|
+
* The decision a person has to make on a worq right now, with the evidence to make it and the commands that make it: what
|
|
303
|
+
* orqen-studio shows as an approval card, and `orqen gate <KEY>` prints. `waiting: false` when nobody has to decide anything
|
|
304
|
+
* (an agent is working, or it is closed). `outside: true` when the decision is not made here (the client or an approver answers
|
|
305
|
+
* on the ticket). Each action is a CLI command (`cli`: its arguments; `text`: what it needs from the person, sent on stdin
|
|
306
|
+
* where the argument is "-") or a step of the flow for the agent (`agent`: the /orqen:* command).
|
|
307
|
+
*/
|
|
308
|
+
gate(key) {
|
|
309
|
+
const g = this.gateOf(key);
|
|
310
|
+
return { ...g, actions: g.actions.map((a) => a.kind === "cli" && a.cli && DRY_RUN_COMMANDS.includes(a.cli[0]) ? { ...a, dry_run: true } : a) };
|
|
311
|
+
}
|
|
312
|
+
gateOf(key) {
|
|
313
|
+
const item = this.item(key);
|
|
314
|
+
if (!item)
|
|
315
|
+
throw new Error(this.unknownMsg(key));
|
|
316
|
+
const k = item.key, ik = workKey(item);
|
|
317
|
+
const role = roleOf(item, this.cfg);
|
|
318
|
+
const who = (names) => names?.length ? names : undefined;
|
|
319
|
+
const base = { key: k, state: item.state, role, title: item.title };
|
|
320
|
+
const ev = [];
|
|
321
|
+
const testing = item.artifacts.TESTING;
|
|
322
|
+
const tr = item.artifacts.test_result;
|
|
323
|
+
if (tr)
|
|
324
|
+
ev.push({ label: "tests", ok: tr.ok === true, value: tr.ok ? "passing" : "failing", detail: tr.ok ? "the full suite passed" : (tr.output ?? "").split("\n").filter(Boolean).at(-1)?.slice(0, 160) });
|
|
325
|
+
if (testing?.scenarios?.length) {
|
|
326
|
+
const covered = testing.scenarios.filter((x) => x.covered).length;
|
|
327
|
+
ev.push({ label: "criteria", ok: covered === testing.scenarios.length, value: `${covered}/${testing.scenarios.length}`, detail: `${covered}/${testing.scenarios.length} acceptance criteria covered by tests` });
|
|
328
|
+
}
|
|
329
|
+
// tests this worq added that no suite of orqen/environment.yaml runs: TESTING passed without running them
|
|
330
|
+
const uncovered = item.artifacts.test_coverage?.uncovered ?? [];
|
|
331
|
+
if (uncovered.length)
|
|
332
|
+
ev.push({ label: "uncovered_tests", ok: false, value: String(uncovered.length),
|
|
333
|
+
detail: `${uncovered.join(", ")} ${uncovered.length === 1 ? "is" : "are"} not run by any suite in orqen/environment.yaml (tests)` });
|
|
334
|
+
const pr = item.artifacts.devel_pr;
|
|
335
|
+
const prEvidence = () => {
|
|
336
|
+
if (!pr)
|
|
337
|
+
return;
|
|
338
|
+
const h = this.prHealth(pr);
|
|
339
|
+
ev.push({ label: "ci", ok: h.ci === "passing" ? true : h.ci === "unknown" || h.ci === "pending" ? null : false, value: h.ci, detail: `CI ${h.ci}${h.detail ? ` (${h.detail})` : ""}` });
|
|
340
|
+
if (h.conflicts !== undefined)
|
|
341
|
+
ev.push({ label: "conflicts", ok: !h.conflicts, value: h.conflicts ? "yes" : "no", detail: h.conflicts ? `conflicts with ${this.cfg.develBranch}` : `no conflicts with ${this.cfg.develBranch}` });
|
|
342
|
+
};
|
|
343
|
+
const lastReview = item.artifacts.code_reviews?.filter((r) => r.round === item.round).at(-1);
|
|
344
|
+
switch (item.state) {
|
|
345
|
+
case "QA_REVIEW":
|
|
346
|
+
prEvidence();
|
|
347
|
+
return { ...base, waiting: true, who: who(this.cfg.approvers.qa), url: pr,
|
|
348
|
+
what: "QA: check the change on screen (e2e) and approve it, or send it back to development with what to fix",
|
|
349
|
+
evidence: ev, actions: [
|
|
350
|
+
{ id: "approve", kind: "cli", label: "approve", cli: ["review", ik, "approve"] },
|
|
351
|
+
{ id: "changes", kind: "cli", label: "request changes", cli: ["review", ik, "reject", "--reason", "-"], text: "what development must fix (10+ characters)" },
|
|
352
|
+
{ id: "ask", kind: "agent", label: "ask the agent", agent: `/orqen:review ${ik}` },
|
|
353
|
+
] };
|
|
354
|
+
case "CODE_REVIEW":
|
|
355
|
+
if (!pr)
|
|
356
|
+
return { ...base, waiting: false, what: "The PR is not open yet: the agent opens it", evidence: ev, actions: [{ id: "pr", kind: "agent", label: "open the PR", agent: `/orqen:pr ${ik}` }] };
|
|
357
|
+
prEvidence();
|
|
358
|
+
if (lastReview)
|
|
359
|
+
ev.push({ label: "code_review", ok: lastReview.verdict === "approve" ? true : lastReview.verdict === "reject" ? false : null, value: lastReview.verdict, detail: `code review: ${lastReview.verdict} (${lastReview.file})` });
|
|
360
|
+
return { ...base, waiting: true, who: who(this.cfg.approvers.code), url: pr,
|
|
361
|
+
what: `Senior: approve the PR ${pr} or request changes`,
|
|
362
|
+
evidence: ev, actions: [
|
|
363
|
+
{ id: "approve", kind: "cli", label: "approve the PR", cli: ["approve", ik] },
|
|
364
|
+
{ id: "changes", kind: "cli", label: "request changes", cli: ["approve", ik, "--changes", "-"], text: "the changes development has to make (10+ characters)" },
|
|
365
|
+
{ id: "ask", kind: "agent", label: "review it with the agent", agent: `/orqen:approve ${ik}` },
|
|
366
|
+
] };
|
|
367
|
+
case "DELIVERY": {
|
|
368
|
+
const merged = !!item.artifacts.devel_pr_merged;
|
|
369
|
+
if (pr && !merged) {
|
|
370
|
+
prEvidence();
|
|
371
|
+
return { ...base, waiting: true, url: pr, what: `Merge the approved PR ${pr} by hand; orqen detects it${item.origin === "internal" ? " and closes this worq" : ", then the agent delivers to the client"}`,
|
|
372
|
+
evidence: ev, actions: [{ id: "merged", kind: "cli", label: "I merged it", cli: ["merged", ik] }] };
|
|
373
|
+
}
|
|
374
|
+
if (item.origin === "internal")
|
|
375
|
+
return { ...base, waiting: false, what: "Merged: orqen closes it", evidence: ev, actions: [] };
|
|
376
|
+
return { ...base, waiting: true, what: "Deliver: the agent tells the client what changed and how to verify it", evidence: ev,
|
|
377
|
+
actions: [{ id: "deliver", kind: "agent", label: "deliver to the client", agent: `/orqen:approve ${ik}` }] };
|
|
378
|
+
}
|
|
379
|
+
case "WAITING_CLIENT":
|
|
380
|
+
case "ACCEPTANCE":
|
|
381
|
+
case "EXECUTION_APPROVAL":
|
|
382
|
+
case "APPLICATION":
|
|
383
|
+
return { ...base, waiting: true, outside: true, who: who(item.state === "ACCEPTANCE" ? this.cfg.approvers.client : item.state === "WAITING_CLIENT" ? undefined : this.cfg.approvers.execution),
|
|
384
|
+
url: this.requests.url(k),
|
|
385
|
+
what: item.state === "WAITING_CLIENT" ? "Waiting for the client's answers on the request" : item.state === "ACCEPTANCE" ? "Waiting for the client to confirm with /approve on the request" : "Waiting for /approve on the request",
|
|
386
|
+
evidence: ev, actions: [] };
|
|
387
|
+
case "BLOCKED": {
|
|
388
|
+
const why = [...this.store.events(k)].reverse().find((e) => e.to === "BLOCKED")?.detail;
|
|
389
|
+
return { ...base, waiting: true, outside: true, who: who([...(this.cfg.approvers.analysis ?? []), ...this.cfg.approvers.code]), url: this.requests.url(k),
|
|
390
|
+
what: `Blocked${why ? `: ${why}` : ""}. Answer on the request with /approve <what to do>`, reason: why, evidence: ev, actions: [] };
|
|
391
|
+
}
|
|
392
|
+
default:
|
|
393
|
+
return { ...base, waiting: false, what: nextSteps(item, this.cfg)[0]?.what ?? "", evidence: ev, actions: [] };
|
|
394
|
+
}
|
|
395
|
+
}
|
|
299
396
|
// ================================================================ senior's decision
|
|
300
397
|
/**
|
|
301
398
|
* Step 9: the senior approves the PR or requests changes. With CODE_REVIEW_GATE=github the review goes on the PR with their
|
|
@@ -343,13 +440,13 @@ export class Process {
|
|
|
343
440
|
}
|
|
344
441
|
if (action === "approve") {
|
|
345
442
|
await this.commentBoth(item, `Code review: PR approved by ${person}: ${url}${body.trim() ? `\n\n${body.trim()}` : ""}\nMoving to delivery.`);
|
|
346
|
-
await this.move(item, "DELIVERY", `PR approved by ${person}`, agent);
|
|
443
|
+
await this.move(item, "DELIVERY", `PR approved by ${person}`, agent, person);
|
|
347
444
|
}
|
|
348
445
|
else {
|
|
349
446
|
item.feedback.push({ from: person, rejection: body.trim() });
|
|
350
447
|
item.testingAttempts = 0;
|
|
351
448
|
await this.commentBoth(item, `Code review: changes requested by ${person} on ${url}\n\n${body.trim()}\n\nReturning to development.`);
|
|
352
|
-
await this.move(item, "DEVELOPMENT", `changes requested by ${person}`, agent);
|
|
449
|
+
await this.move(item, "DEVELOPMENT", `changes requested by ${person}`, agent, person);
|
|
353
450
|
}
|
|
354
451
|
return { state: item.state, url, onGitHub: false, warning };
|
|
355
452
|
}
|
|
@@ -380,7 +477,7 @@ export class Process {
|
|
|
380
477
|
if (item.state === "NEW") {
|
|
381
478
|
item.supporter = person;
|
|
382
479
|
await this.requests.comment(key, `${person} (support) is handling this request.`);
|
|
383
|
-
await this.move(item, "SUPPORT", "taken by support", agent);
|
|
480
|
+
await this.move(item, "SUPPORT", "taken by support", agent, person);
|
|
384
481
|
}
|
|
385
482
|
item.supporter = person;
|
|
386
483
|
this.store.save(item);
|
|
@@ -399,7 +496,7 @@ export class Process {
|
|
|
399
496
|
const from = item.state;
|
|
400
497
|
item.analyst = analyst;
|
|
401
498
|
await this.requests.comment(key, `${analyst} started analyzing this request.`);
|
|
402
|
-
await this.move(item, "ANALYSIS", from === "SUPPORT" ? "taken by the analyst before support finished" : "registered by analyst", agent);
|
|
499
|
+
await this.move(item, "ANALYSIS", from === "SUPPORT" ? "taken by the analyst before support finished" : "registered by analyst", agent, analyst);
|
|
403
500
|
}
|
|
404
501
|
item.analyst = analyst;
|
|
405
502
|
this.store.save(item);
|
|
@@ -532,6 +629,8 @@ export class Process {
|
|
|
532
629
|
language: detectarIdioma(),
|
|
533
630
|
supporter: item.supporter, analyst: item.analyst, lane: item.lane, worq: `${this.worqRel(key)}/round-${item.round}`, factory: `${this.worqRel(key)}/round-${item.round}`, // factory: old name of worq
|
|
534
631
|
request: ticket, issue: item.issue, comments, environment,
|
|
632
|
+
// a worq started by the team: nobody waits on a ticket, the person who started it is the requester (ask them here)
|
|
633
|
+
...(item.origin === "internal" ? { no_client: true, requester: item.analyst } : {}),
|
|
535
634
|
openspec,
|
|
536
635
|
...(["DEVELOPMENT", "TESTING"].includes(state) ? { tasks: this.tasksOf(item) } : {}),
|
|
537
636
|
...(state === "TESTING" ? { scenarios: this.scenariosOf(item) } : {}),
|
|
@@ -692,10 +791,10 @@ export class Process {
|
|
|
692
791
|
if (decision === "reject") {
|
|
693
792
|
item.feedback.push({ from: by, rejection: reason.trim() });
|
|
694
793
|
item.testingAttempts = 0;
|
|
695
|
-
await this.move(item, GATES.QA_REVIEW.reject, `QA requested changes (${by})`, by);
|
|
794
|
+
await this.move(item, GATES.QA_REVIEW.reject, `QA requested changes (${by})`, by, by);
|
|
696
795
|
}
|
|
697
796
|
else
|
|
698
|
-
await this.move(item, GATES.QA_REVIEW.approve, `QA approved (${by})`, by);
|
|
797
|
+
await this.move(item, GATES.QA_REVIEW.approve, `QA approved (${by})`, by, by);
|
|
699
798
|
return { n, path, next: item.state };
|
|
700
799
|
}
|
|
701
800
|
// ================================================================ complete
|
|
@@ -1013,10 +1112,10 @@ export class Process {
|
|
|
1013
1112
|
item.feedback.push({ from: r.author, rejection: r.body.trim() || `Changes requested on the PR: ${url}` });
|
|
1014
1113
|
item.testingAttempts = 0;
|
|
1015
1114
|
await this.commentBoth(item, `Changes requested on the PR by ${rejected.map((r) => r.author).join(", ")}: ${url}\nReturning to development.`);
|
|
1016
|
-
return this.move(item, GATES.CODE_REVIEW.reject, `changes requested on the PR by ${rejected.map((r) => r.author).join(", ")}
|
|
1115
|
+
return this.move(item, GATES.CODE_REVIEW.reject, `changes requested on the PR by ${rejected.map((r) => r.author).join(", ")}`, undefined, rejected.map((r) => r.author).join(", "));
|
|
1017
1116
|
}
|
|
1018
1117
|
await this.commentBoth(item, `PR approved by ${approved.map((r) => r.author).join(", ")}: ${url}\nMoving to delivery.`);
|
|
1019
|
-
return this.move(item, GATES.CODE_REVIEW.approve, `PR approved by ${approved.map((r) => r.author).join(", ")}
|
|
1118
|
+
return this.move(item, GATES.CODE_REVIEW.approve, `PR approved by ${approved.map((r) => r.author).join(", ")}`, undefined, approved.map((r) => r.author).join(", "));
|
|
1020
1119
|
}
|
|
1021
1120
|
async reviewGate(item) {
|
|
1022
1121
|
const gate = GATES[item.state];
|
|
@@ -1066,7 +1165,7 @@ export class Process {
|
|
|
1066
1165
|
delete item.issue;
|
|
1067
1166
|
} // the new round gets its own issue
|
|
1068
1167
|
}
|
|
1069
|
-
return this.move(item, gate[action === "approve" ? "approve" : "reject"], `/${action} by ${c.authorName} ${reason}`.trim());
|
|
1168
|
+
return this.move(item, gate[action === "approve" ? "approve" : "reject"], `/${action} by ${c.authorName} ${reason}`.trim(), undefined, c.authorName);
|
|
1070
1169
|
}
|
|
1071
1170
|
this.store.save(item);
|
|
1072
1171
|
}
|
|
@@ -1079,7 +1178,7 @@ export class Process {
|
|
|
1079
1178
|
item.questionRounds = 0;
|
|
1080
1179
|
if (m[2].trim())
|
|
1081
1180
|
item.feedback.push({ from: c.authorName, text: m[2].trim() });
|
|
1082
|
-
return this.move(item, item.stateBeforeBlock ?? "ANALYSIS", `unblocked by ${c.authorName}
|
|
1181
|
+
return this.move(item, item.stateBeforeBlock ?? "ANALYSIS", `unblocked by ${c.authorName}`, undefined, c.authorName);
|
|
1083
1182
|
}
|
|
1084
1183
|
item.feedback.push({ from: c.authorName, text: c.body });
|
|
1085
1184
|
}
|
|
@@ -1166,6 +1265,9 @@ export class Process {
|
|
|
1166
1265
|
throw new Error("A title for the worq is required (at least 5 characters).");
|
|
1167
1266
|
const b = (raw ?? {});
|
|
1168
1267
|
const description = typeof b.description === "string" ? b.description.trim() : "";
|
|
1268
|
+
// only a title and a description: the worq is born in ANALYSIS and an agent analyzes it with the person (/orqen:analyze)
|
|
1269
|
+
if (b.acceptance_criteria === undefined && b.plan === undefined && b.estimated_hours === undefined)
|
|
1270
|
+
return this.newWorqToAnalyze(t, description || current?.description?.trim() || "", person, existing);
|
|
1169
1271
|
const analysis = {
|
|
1170
1272
|
summary: typeof b.summary === "string" && b.summary.trim() ? b.summary.trim() : description || t,
|
|
1171
1273
|
type: "change", acceptance_criteria: b.acceptance_criteria, affected_capabilities: [], open_questions: [], risks: Array.isArray(b.risks) ? b.risks : [],
|
|
@@ -1215,6 +1317,31 @@ export class Process {
|
|
|
1215
1317
|
this.fac.write(item, "brief.md", `# ${key} — ${t}\n\n${description}\n`);
|
|
1216
1318
|
return { key, state: this.item(key).state, dir: this.worqRel(key), url: this.requests.url(key) };
|
|
1217
1319
|
}
|
|
1320
|
+
/**
|
|
1321
|
+
* `orqen new_worq` with only a title and a description (the person's own words, as long as they want): the issue is created (or an
|
|
1322
|
+
* existing one taken) and the worq is born in ANALYSIS, with the person as its analyst and requester. Nothing is decided yet: the
|
|
1323
|
+
* analysis agent reads it, asks the person what is missing, picks the lane and writes the spec (/orqen:analyze), as with a request.
|
|
1324
|
+
*/
|
|
1325
|
+
async newWorqToAnalyze(title, description, person, existing) {
|
|
1326
|
+
if (description.length < 20)
|
|
1327
|
+
throw new Error("Describe the work (at least 20 characters): what has to be done and why. The analysis agent asks for what is missing.");
|
|
1328
|
+
let key;
|
|
1329
|
+
if (existing) {
|
|
1330
|
+
key = existing;
|
|
1331
|
+
await this.attemptAsync(() => this.requests.ownSystem.addLabel?.(key, WORQ_LABEL) ?? Promise.resolve());
|
|
1332
|
+
}
|
|
1333
|
+
else {
|
|
1334
|
+
key = await this.requests.create({
|
|
1335
|
+
title, route: "development", labels: [WORQ_LABEL],
|
|
1336
|
+
description: `${description}\n\n*Started by:* ${person}\n\nCreated with orqen (no client request). It is analyzed with ${person}.`,
|
|
1337
|
+
});
|
|
1338
|
+
}
|
|
1339
|
+
const item = { ...newWorkItem(key), origin: "internal", title, analyst: person };
|
|
1340
|
+
this.store.save(item);
|
|
1341
|
+
await this.move(item, "ANALYSIS", `started by ${person} (worq of the team): to analyze`, "internal", person);
|
|
1342
|
+
this.fac.write(item, "brief.md", `# ${key} — ${title}\n\n${description}\n`);
|
|
1343
|
+
return { key, state: item.state, dir: this.worqRel(key), url: this.requests.url(key), next: `/orqen:analyze ${key}` };
|
|
1344
|
+
}
|
|
1218
1345
|
/** A worq started by the team has nobody to deliver to: once its PR is merged it is closed (and so is its issue). */
|
|
1219
1346
|
async closeInternal(item) {
|
|
1220
1347
|
if (item.origin !== "internal" || item.state !== "DELIVERY" || !item.artifacts.devel_pr_merged)
|
|
@@ -1269,7 +1396,7 @@ export class Process {
|
|
|
1269
1396
|
item.artifacts.devel_pr_merged = { at, by, ...(confirmed ? { confirmed_by_hand: true } : {}) };
|
|
1270
1397
|
this.store.save(item);
|
|
1271
1398
|
const what = `PR merged into ${this.cfg.develBranch}${by ? ` by ${by}` : ""}${confirmed ? " (confirmed by hand)" : ""}`;
|
|
1272
|
-
this.store.log(item.key, { ts: new Date().toISOString(), from: item.state, to: item.state, detail: what, agent: "process" });
|
|
1399
|
+
this.store.log(item.key, { ts: new Date().toISOString(), from: item.state, to: item.state, detail: what, agent: "process", ...(by ? { person: by } : {}) });
|
|
1273
1400
|
await this.attemptAsync(() => this.commentBoth(item, `${what}: ${url}`));
|
|
1274
1401
|
}
|
|
1275
1402
|
/** CI and conflicts of a PR. "unknown" (no gh, a PR outside GitHub…) never blocks: it is only shown. */
|
|
@@ -1317,7 +1444,7 @@ export class Process {
|
|
|
1317
1444
|
: pr === "closed" ? `\nThe PR was closed without merging: ${url}`
|
|
1318
1445
|
: pr === "open" ? `\nThe PR could not be closed automatically: close it by hand: ${url}` : "";
|
|
1319
1446
|
await this.commentBoth(item, `Request cancelled by ${person}: ${reason.trim()}${note}`);
|
|
1320
|
-
await this.move(item, "CANCELLED", `cancelled by ${person}: ${reason.trim()}`, agent);
|
|
1447
|
+
await this.move(item, "CANCELLED", `cancelled by ${person}: ${reason.trim()}`, agent, person);
|
|
1321
1448
|
return { state: item.state, pr, url };
|
|
1322
1449
|
}
|
|
1323
1450
|
// ================================================================ utilities
|
|
@@ -1363,7 +1490,8 @@ export class Process {
|
|
|
1363
1490
|
return undefined;
|
|
1364
1491
|
}
|
|
1365
1492
|
}
|
|
1366
|
-
|
|
1493
|
+
/** `person`: who decided or did it (a person's name), when it was a person; the Worq's Activity shows it. */
|
|
1494
|
+
async move(item, to, detail, agent, person) {
|
|
1367
1495
|
const from = item.state;
|
|
1368
1496
|
if (to === "BLOCKED" && from !== "BLOCKED")
|
|
1369
1497
|
item.stateBeforeBlock = from;
|
|
@@ -1377,7 +1505,7 @@ export class Process {
|
|
|
1377
1505
|
item.lastSeenComment = (ours ?? cs.at(-1))?.id ?? "";
|
|
1378
1506
|
}
|
|
1379
1507
|
this.store.save(item);
|
|
1380
|
-
this.store.log(item.key, { ts: new Date().toISOString(), from, to, detail, agent });
|
|
1508
|
+
this.store.log(item.key, { ts: new Date().toISOString(), from, to, detail, agent, ...(person ? { person } : {}) });
|
|
1381
1509
|
this.fac.record(item, from, to, detail, agent);
|
|
1382
1510
|
if (item.branch)
|
|
1383
1511
|
this.attempt(() => this.ws.commit(item.key, `registro ${from} → ${to}`, { path: join(this.cfg.factoryDir, item.key), branch: item.branch }));
|