@telpin-sistemas/orqen 0.1.10 → 0.1.12
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/doctor.js +123 -0
- package/dist/commands/init.js +1 -1
- package/dist/commands/update.js +17 -6
- package/dist/commands/workflow.js +49 -11
- package/dist/connectors/asana.js +3 -2
- package/dist/connectors/github.js +73 -2
- package/dist/connectors/jira.js +4 -0
- package/dist/connectors/local.js +10 -0
- package/dist/connectors/markup.js +40 -0
- package/dist/connectors/types.js +2 -0
- package/dist/lib/kit.js +19 -1
- package/dist/lib/processes.js +11 -4
- package/dist/template/.agents/commands/new_worq.md +17 -6
- package/dist/template/AGENTS.md +1 -1
- package/dist/workflow/process.js +68 -12
- package/dist/workflow/report.js +103 -0
- package/dist/workflow/routed.js +28 -4
- package/package.json +1 -1
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `orqen doctor`: everything the flow needs on this machine and in this repository, checked at once, each problem with what to do.
|
|
3
|
+
* The same things otherwise show up one at a time, in the middle of a stage (gh missing at `orqen pr`, a base branch that is not on
|
|
4
|
+
* origin, a connector without credentials…).
|
|
5
|
+
*/
|
|
6
|
+
import { spawnSync } from "node:child_process";
|
|
7
|
+
import { existsSync, readdirSync } from "node:fs";
|
|
8
|
+
import { join } from "node:path";
|
|
9
|
+
import { existeConfig, leerConfig } from "../lib/config.js";
|
|
10
|
+
import { leerManifest } from "../lib/kit.js";
|
|
11
|
+
import { VERSION_CLI } from "../lib/system.js";
|
|
12
|
+
import { ghFailure } from "../workflow/workspace.js";
|
|
13
|
+
export const systemRunner = (cmd, args, o = {}) => {
|
|
14
|
+
const r = spawnSync(cmd, args, { cwd: o.cwd, shell: o.shell, encoding: "utf8", windowsHide: true, timeout: 30_000 });
|
|
15
|
+
return { code: r.status, stdout: r.stdout ?? "", stderr: r.stderr ?? "", error: r.error };
|
|
16
|
+
};
|
|
17
|
+
export async function diagnose(cfg, connectors, run = systemRunner) {
|
|
18
|
+
const repo = cfg.repoPath;
|
|
19
|
+
const out = [];
|
|
20
|
+
const add = (name, status, detail, fix) => out.push({ name, status, detail, ...(fix ? { fix } : {}) });
|
|
21
|
+
// --- repository
|
|
22
|
+
const origin = run("git", ["remote", "get-url", "origin"], { cwd: repo });
|
|
23
|
+
if (origin.error?.code === "ENOENT")
|
|
24
|
+
add("git", "fail", "git is not installed or is not in the PATH", "Install git and open a new terminal");
|
|
25
|
+
else if (origin.code !== 0)
|
|
26
|
+
add("git", "fail", "the repository has no origin remote: branches and PRs cannot be pushed", "git remote add origin <url>");
|
|
27
|
+
else
|
|
28
|
+
add("git", "ok", `origin: ${origin.stdout.trim()}`);
|
|
29
|
+
// --- orqen in the project
|
|
30
|
+
const installed = existeConfig(repo);
|
|
31
|
+
if (!installed)
|
|
32
|
+
add("orqen", "fail", "orqen is not installed in this repository (no orqen/config.yaml)", "orqen init");
|
|
33
|
+
else {
|
|
34
|
+
const kit = leerManifest(repo).kit;
|
|
35
|
+
if (kit === VERSION_CLI)
|
|
36
|
+
add("kit", "ok", `kit ${kit}, same as the CLI`);
|
|
37
|
+
else
|
|
38
|
+
add("kit", "warn", `the kit is ${kit} and the CLI ${VERSION_CLI}: the /orqen:* commands may not match the CLI`, "orqen update --no-cli");
|
|
39
|
+
}
|
|
40
|
+
// --- GitHub CLI: orqen pr, the senior's review, CI and merge detection
|
|
41
|
+
const gh = run("gh", ["auth", "status"], { cwd: repo });
|
|
42
|
+
if (gh.error || gh.code !== 0) {
|
|
43
|
+
const why = ghFailure(gh.error ?? Object.assign(new Error(gh.stderr || "gh failed"), { stderr: gh.stderr }));
|
|
44
|
+
add("gh", "fail", why, gh.error?.code === "ENOENT" ? "Install it from https://cli.github.com and open a new terminal" : "gh auth login");
|
|
45
|
+
}
|
|
46
|
+
else
|
|
47
|
+
add("gh", "ok", (gh.stdout + gh.stderr).split("\n").map((l) => l.trim()).find((l) => /logged in/i.test(l)) ?? "logged in");
|
|
48
|
+
// --- the branch PRs go to
|
|
49
|
+
if (origin.code === 0) {
|
|
50
|
+
const base = run("git", ["ls-remote", "--exit-code", "--heads", "origin", cfg.develBranch], { cwd: repo });
|
|
51
|
+
if (base.code === 0)
|
|
52
|
+
add("base branch", "ok", `${cfg.develBranch} exists on origin`);
|
|
53
|
+
else if (base.code === 2)
|
|
54
|
+
add("base branch", "fail", `the branch PRs go to (${cfg.develBranch}) does not exist on origin: orqen pr will refuse to open them`, `git push origin <branch>:${cfg.develBranch}, or set workflow.devel_branch in orqen/config.yaml`);
|
|
55
|
+
else
|
|
56
|
+
add("base branch", "warn", `could not check whether ${cfg.develBranch} exists on origin (${(base.stderr || "no answer").trim().split("\n")[0]})`);
|
|
57
|
+
}
|
|
58
|
+
// --- connectors
|
|
59
|
+
for (const role of ["requests", "issues"]) {
|
|
60
|
+
const t = connectors[role];
|
|
61
|
+
const name = role === "requests" ? "requests connector" : "issues connector";
|
|
62
|
+
if (!t) {
|
|
63
|
+
if (role === "requests")
|
|
64
|
+
add(name, "fail", "not configured: orqen has nowhere to read the requests from", "orqen connectors setup");
|
|
65
|
+
else
|
|
66
|
+
add(name, "ok", "not configured: development issues go to the requests connector");
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
let r;
|
|
70
|
+
try {
|
|
71
|
+
r = await t.check();
|
|
72
|
+
}
|
|
73
|
+
catch (e) {
|
|
74
|
+
r = { ok: false, detail: e.message.split("\n")[0] };
|
|
75
|
+
}
|
|
76
|
+
add(name, r.ok ? "ok" : "fail", `${t.label}: ${r.detail}`, r.ok ? undefined : "orqen connectors setup");
|
|
77
|
+
}
|
|
78
|
+
// --- CI: without it, the senior approves without knowing whether the tests pass on the PR
|
|
79
|
+
const wf = join(repo, ".github", "workflows");
|
|
80
|
+
const workflows = existsSync(wf) ? readdirSync(wf).filter((f) => /\.ya?ml$/i.test(f)) : [];
|
|
81
|
+
if (workflows.length)
|
|
82
|
+
add("CI", "ok", `${workflows.length} GitHub Actions workflow(s)`);
|
|
83
|
+
else
|
|
84
|
+
add("CI", "warn", "no GitHub Actions workflows: /orqen:approve cannot check that the tests pass on the PR", "Add a workflow in .github/workflows that runs the tests (if CI runs elsewhere, ignore this)");
|
|
85
|
+
// --- tests the testing stage runs
|
|
86
|
+
if (installed) {
|
|
87
|
+
let tests;
|
|
88
|
+
try {
|
|
89
|
+
tests = leerConfig(repo).entornos.tests;
|
|
90
|
+
}
|
|
91
|
+
catch (e) {
|
|
92
|
+
add("config", "fail", e.message.replace(/\n/g, " "), "Fix orqen/config.yaml and orqen/environment.yaml as the message says");
|
|
93
|
+
}
|
|
94
|
+
const inFile = { unitarios: "unit", integracion: "integration" }; // as written in orqen/environment.yaml
|
|
95
|
+
const set = Object.entries(tests ?? {}).filter(([, v]) => v).map(([k]) => inFile[k] ?? k);
|
|
96
|
+
if (set.length)
|
|
97
|
+
add("tests", "ok", `configured: ${set.join(", ")}`);
|
|
98
|
+
else if (tests)
|
|
99
|
+
add("tests", "warn", "no tests in orqen/environment.yaml: the testing stage has nothing to run", "Set tests.unit in orqen/environment.yaml");
|
|
100
|
+
}
|
|
101
|
+
// --- the agent that runs the stages unattended (orqen cycle, orqen eval)
|
|
102
|
+
const agent = cfg.agentCmd.trim().split(/\s+/)[0];
|
|
103
|
+
if (agent) {
|
|
104
|
+
const a = run(agent, ["--version"], { cwd: repo, shell: process.platform === "win32" });
|
|
105
|
+
if (a.error?.code === "ENOENT" || a.code === 127 || (process.platform === "win32" && a.code === 1 && /not recognized/i.test(a.stderr)))
|
|
106
|
+
add("agent", "warn", `${agent} (agent.command) is not in the PATH: orqen cycle and orqen eval cannot run it`, `Install ${agent} or change agent.command in orqen/config.yaml`);
|
|
107
|
+
else
|
|
108
|
+
add("agent", "ok", `${agent} ${a.stdout.trim().split("\n")[0]}`.trim());
|
|
109
|
+
}
|
|
110
|
+
return out;
|
|
111
|
+
}
|
|
112
|
+
const ICON = { ok: "✔", warn: "⚠", fail: "✘" };
|
|
113
|
+
export function printChecks(checks) {
|
|
114
|
+
const w = Math.max(...checks.map((c) => c.name.length));
|
|
115
|
+
for (const c of checks) {
|
|
116
|
+
console.log(`${ICON[c.status]} ${c.name.padEnd(w)} ${c.detail}`);
|
|
117
|
+
if (c.fix && c.status !== "ok")
|
|
118
|
+
console.log(` ${" ".repeat(w)} → ${c.fix}`);
|
|
119
|
+
}
|
|
120
|
+
const fails = checks.filter((c) => c.status === "fail").length, warns = checks.filter((c) => c.status === "warn").length;
|
|
121
|
+
console.log(fails ? `\n${fails} problem(s) to fix before using the flow${warns ? `, ${warns} warning(s)` : ""}.`
|
|
122
|
+
: warns ? `\nReady, with ${warns} warning(s).` : "\nEverything is ready.");
|
|
123
|
+
}
|
package/dist/commands/init.js
CHANGED
|
@@ -357,7 +357,7 @@ async function prepararOpenSpec(repo, agentes, herramientasPedidas, yes) {
|
|
|
357
357
|
return { instalacion, version: versionFinal, herramientas };
|
|
358
358
|
}
|
|
359
359
|
function resumenPlan(plan, config) {
|
|
360
|
-
const icono = { crear: pc.green("+"), actualizar: pc.yellow("~"), igual: gris("="), conflicto: pc.red("!") };
|
|
360
|
+
const icono = { crear: pc.green("+"), actualizar: pc.yellow("~"), igual: gris("="), conflicto: pc.red("!"), borrar: pc.red("-"), obsoleto: pc.yellow("?") };
|
|
361
361
|
const filas = [
|
|
362
362
|
`${pc.green("+")} ${ARCHIVO_CONFIG} ${gris("(the flow: project, connectors, workflow)")}`,
|
|
363
363
|
`${pc.green("+")} ${ARCHIVO_ENTORNO} ${gris("(stack, how each part starts, tests)")}`,
|
package/dist/commands/update.js
CHANGED
|
@@ -22,7 +22,7 @@ function paqueteGlobal(gestor, paquete) {
|
|
|
22
22
|
throw new Error(r.stderr.trim() || r.error?.message || `Could not locate global packages for ${gestor}.`);
|
|
23
23
|
return join(r.stdout.trim(), paquete);
|
|
24
24
|
}
|
|
25
|
-
async function actualizarPaquete(gestor, paquete, actual, yes, objetivo) {
|
|
25
|
+
async function actualizarPaquete(gestor, paquete, actual, yes, objetivo, desktop = false) {
|
|
26
26
|
const ultima = objetivo ?? ultimaVersionPaquete(gestor, paquete);
|
|
27
27
|
if (!ultima)
|
|
28
28
|
return { status: "unavailable", version: actual };
|
|
@@ -30,7 +30,15 @@ async function actualizarPaquete(gestor, paquete, actual, yes, objetivo) {
|
|
|
30
30
|
return { status: "current", version: actual };
|
|
31
31
|
if (!await confirmar(`Update ${paquete} from ${actual} to ${ultima}?`, true, yes))
|
|
32
32
|
return { status: "skipped", version: actual };
|
|
33
|
-
const
|
|
33
|
+
const args = [gestor === "pnpm" ? "add" : "install", "-g", `${paquete}@${ultima}`];
|
|
34
|
+
if (desktop) {
|
|
35
|
+
const binario = `@telpin-sistemas/orqen-desktop-${process.platform}-${process.arch}@${ultima}`;
|
|
36
|
+
const descarga = await ejecutarAsync(gestor, ["cache", "add", binario, "--prefer-online", "--fetch-retries=0"], { timeoutMs: 60_000 });
|
|
37
|
+
if (descarga.codigo !== 0)
|
|
38
|
+
throw new Error("The platform build is still unavailable on npm. Your current installation is intact. Try again in a few minutes.");
|
|
39
|
+
args.push("--include=optional", binario);
|
|
40
|
+
}
|
|
41
|
+
const r = await ejecutarAsync(gestor, args, { timeoutMs: 10 * 60_000 });
|
|
34
42
|
if (r.codigo !== 0)
|
|
35
43
|
throw new Error(`Update failed for ${paquete}: ${(r.stderr || r.stdout || r.error?.message || `exit code ${r.codigo}`).trim().slice(-1500)}`);
|
|
36
44
|
return { status: "installed", version: ultima };
|
|
@@ -100,7 +108,7 @@ export async function update(o) {
|
|
|
100
108
|
throw new Error("--target requires --desktop and a valid version.");
|
|
101
109
|
if (o.desktop) {
|
|
102
110
|
const { paquete, version: actual } = instalacionDesktop();
|
|
103
|
-
const result = await actualizarPaquete("npm", paquete, actual, !!o.yes || !interactivo(), o.target);
|
|
111
|
+
const result = await actualizarPaquete("npm", paquete, actual, !!o.yes || !interactivo(), o.target, true);
|
|
104
112
|
if (result.status === "unavailable")
|
|
105
113
|
throw new Error("Could not check npm for orqen Desktop updates.");
|
|
106
114
|
if (o.json)
|
|
@@ -207,15 +215,18 @@ export async function update(o) {
|
|
|
207
215
|
if (!cambios.length)
|
|
208
216
|
p.log.success(`The kit is up to date (v${VERSION_CLI})`);
|
|
209
217
|
else {
|
|
210
|
-
const icono = { crear: pc.green("+"), actualizar: pc.yellow("~"), conflicto: pc.red("!") };
|
|
211
|
-
|
|
218
|
+
const icono = { crear: pc.green("+"), actualizar: pc.yellow("~"), conflicto: pc.red("!"), borrar: pc.red("-"), obsoleto: pc.yellow("?") };
|
|
219
|
+
const nota = { conflicto: pc.red(" (local edits require review)"), borrar: pc.dim(" (no longer in the kit)"), obsoleto: pc.yellow(" (no longer in the kit, but edited: kept)") };
|
|
220
|
+
p.note(cambios.map((c) => `${icono[c.accion]} ${c.ruta}${nota[c.accion] ?? ""}`).join("\n"), `Kit ${manifest.kit} → ${VERSION_CLI}`);
|
|
212
221
|
if (await confirmar("Apply the kit updates?", true, yes)) {
|
|
213
222
|
const res = await aplicar(repo, plan, (c) => resolverConflicto(c, yes));
|
|
214
223
|
actualizarVersiones(repo, { kit: VERSION_CLI, cli: VERSION_CLI });
|
|
215
224
|
const n = (a) => res.filter((r) => r.accion === a).length;
|
|
216
|
-
p.log.success(`Kit v${VERSION_CLI}: ${n("crear")} created, ${n("actualizar")} updated, ${n("mantenido")} kept, ${n("guardado-al-lado")} to merge manually`);
|
|
225
|
+
p.log.success(`Kit v${VERSION_CLI}: ${n("crear")} created, ${n("actualizar")} updated, ${n("borrar")} deleted, ${n("mantenido")} kept, ${n("guardado-al-lado")} to merge manually`);
|
|
217
226
|
for (const r of res.filter((r) => r.accion === "guardado-al-lado"))
|
|
218
227
|
p.log.warn(`${r.ruta} → see ${r.detalle}`);
|
|
228
|
+
for (const r of res.filter((r) => r.accion === "obsoleto"))
|
|
229
|
+
p.log.warn(`${r.ruta} is no longer part of the kit and has local edits: it was kept, delete it when you no longer need it`);
|
|
219
230
|
}
|
|
220
231
|
}
|
|
221
232
|
}
|
|
@@ -16,7 +16,7 @@ import { OpenSpecCli } from "../workflow/openspec.js";
|
|
|
16
16
|
import { Process } from "../workflow/process.js";
|
|
17
17
|
import { Store } from "../workflow/store.js";
|
|
18
18
|
import { GitWorkspace } from "../workflow/workspace.js";
|
|
19
|
-
export const WORKFLOW_COMMANDS = ["list", "qa", "approve", "merged", "cancel", "new_worq", "pending", "support", "analyze", "ask", "conversation", "lane", "take", "complete", "pr", "review", "code-review", "schema", "block", "release", "search", "status", "worqs", "worq", "cycle", "connectors", "comments", "comment"];
|
|
19
|
+
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"];
|
|
20
20
|
/** What people run: the 9 steps (as /orqen:* commands in their agent) and the CLI commands meant for a person. */
|
|
21
21
|
export const WORKFLOW_HELP = `The 9 steps (run the /orqen:* commands in your agent: it calls the CLI for you):
|
|
22
22
|
1 /orqen:list requests orqen list requests [--json] [--all] Everyone's work list, by role (takes nothing)
|
|
@@ -37,11 +37,14 @@ Request commands for people:
|
|
|
37
37
|
worq <KEY> [--json] One worq: state, request, issue, branch, PR and the files of its record in orqen/worqs/<KEY>/
|
|
38
38
|
merged <KEY> [--person N] Confirm the hand merge of an approved PR when orqen cannot read it from GitHub
|
|
39
39
|
new_worq "<title>" <brief.json|-> Worq with no request: creates its issue in the connector, skips support and analysis, born in DEVELOPMENT
|
|
40
|
+
--issue <KEY> Take an issue that already exists instead of creating one (the title defaults to the issue's)
|
|
40
41
|
cancel <KEY> --reason T Close the request without delivering it: closes the PR unmerged, comments both tickets (CANCELLED)
|
|
41
42
|
release <KEY> Free a request held by an agent that is no longer working on it
|
|
42
43
|
comments <KEY> [--json] Read the request and its conversation with the client
|
|
43
44
|
comment <KEY> <file|-> Reply to the client on the request (--person NAME)
|
|
44
45
|
connectors [setup] Show and check the connectors (requests and issues), or set them up
|
|
46
|
+
doctor [--json] Check everything the flow needs at once (git, gh, base branch, connectors, CI, tests, agent), with what to do
|
|
47
|
+
report [--since YYYY-MM-DD|<n>d] [--json] How the work flowed: time to close by lane, where it waits, returns to development, estimate
|
|
45
48
|
cycle [--loop] Unattended mode (cron/CI/server): agent stages only, never support or analysis
|
|
46
49
|
|
|
47
50
|
Agent-only commands (the /orqen:* commands run them) and JSON for tools: orqen help internal`;
|
|
@@ -234,7 +237,7 @@ export async function runWorkflow(cmd, rest) {
|
|
|
234
237
|
continue;
|
|
235
238
|
console.log(`${titles[role]}:`);
|
|
236
239
|
for (const b of xs)
|
|
237
|
-
console.log(` ${b.work.padEnd(12)} ${b.state.padEnd(15)} ${(b.next[0]?.command ?? "").padEnd(28)} ${b.takenBy ? `(taken by ${b.takenBy} since ${b.since?.slice(0, 16).replace("T", " ")})` : ""}${b.recovered ?
|
|
240
|
+
console.log(` ${b.work.padEnd(12)} ${b.state.padEnd(15)} ${(b.next[0]?.command ?? "").padEnd(28)} ${b.takenBy ? `(taken by ${b.takenBy} since ${b.since?.slice(0, 16).replace("T", " ")})` : ""}${b.recovered ? ` ← state read from the ticket; this machine has no record${b.next[0]?.command ? "" : " and its branch is not on origin yet (it appears when whoever started it pushes)"}` : ""}`);
|
|
238
241
|
}
|
|
239
242
|
return;
|
|
240
243
|
}
|
|
@@ -278,15 +281,18 @@ export async function runWorkflow(cmd, rest) {
|
|
|
278
281
|
}
|
|
279
282
|
return;
|
|
280
283
|
}
|
|
284
|
+
case "new-worq":
|
|
281
285
|
case "new_worq": {
|
|
282
286
|
try {
|
|
283
|
-
const
|
|
284
|
-
const
|
|
285
|
-
|
|
286
|
-
|
|
287
|
+
const issueFlag = flag("issue");
|
|
288
|
+
const existing = issueFlag ? toKey(issueFlag) : undefined;
|
|
289
|
+
// with --issue the title is optional (the issue's is used): orqen new_worq --issue GH-12 brief.json
|
|
290
|
+
const [title, src] = existing && rest.length === 1 ? ["", rest[0]] : [rest[0] ?? "", rest[1]];
|
|
291
|
+
if ((!title && !existing) || !src)
|
|
292
|
+
throw new Error('Usage: orqen new_worq "<title>" <brief.json|-> [--person NAME] or orqen new_worq --issue <KEY> ["<title>"] <brief.json|-> (brief: {"description", "acceptance_criteria": [...], "plan": [...], "estimated_hours"})');
|
|
287
293
|
const raw = JSON.parse(src === "-" ? readFileSync(0, "utf8") : readFileSync(src, "utf8"));
|
|
288
|
-
const r = await flow.newWorq(title, raw, me || agent);
|
|
289
|
-
console.log(`✔ ${r.key} created in ${r.state}: issue ${r.url} (no client request) · worq: ${r.dir}/`);
|
|
294
|
+
const r = await flow.newWorq(title, raw, me || agent, existing);
|
|
295
|
+
console.log(`✔ ${r.key} ${existing ? "taken" : "created"} in ${r.state}: issue ${r.url} (no client request) · worq: ${r.dir}/`);
|
|
290
296
|
console.log(` Next: /orqen:implement ${r.key}`);
|
|
291
297
|
}
|
|
292
298
|
catch (e) {
|
|
@@ -543,7 +549,7 @@ export async function runWorkflow(cmd, rest) {
|
|
|
543
549
|
console.log(`Worq ${w.key}${w.title ? ` — ${w.title}` : ""}`);
|
|
544
550
|
console.log(` State: ${w.state}${w.round > 1 ? ` (round ${w.round})` : ""}${w.lane ? ` · lane ${w.lane}` : ""}${w.route && w.route !== "development" ? ` · ${w.route}` : ""}`);
|
|
545
551
|
if (w.next[0])
|
|
546
|
-
console.log(` Next: ${w.next[0].command} (${w.role}: ${w.next[0].what})`);
|
|
552
|
+
console.log(` Next: ${w.next[0].command ? `${w.next[0].command} (${w.role}: ${w.next[0].what})` : `${w.role}: ${w.next[0].what}`}`);
|
|
547
553
|
console.log(` Request: ${w.key} ${w.request_url}`);
|
|
548
554
|
if (w.issue)
|
|
549
555
|
console.log(` Issue: ${w.issue}${w.issue_url ? ` ${w.issue_url}` : ""}`);
|
|
@@ -554,7 +560,7 @@ export async function runWorkflow(cmd, rest) {
|
|
|
554
560
|
if (w.supporter || w.analyst)
|
|
555
561
|
console.log(` People: ${[w.supporter && `support ${w.supporter}`, w.analyst && `analyst ${w.analyst}`].filter(Boolean).join(" · ")}`);
|
|
556
562
|
if (item.recovered)
|
|
557
|
-
console.log(
|
|
563
|
+
console.log(` ${flow.recoveredHint(key).text}`);
|
|
558
564
|
else {
|
|
559
565
|
console.log(` Folder: ${w.dir}/`);
|
|
560
566
|
for (const f of files)
|
|
@@ -590,7 +596,7 @@ export async function runWorkflow(cmd, rest) {
|
|
|
590
596
|
const item = flow.item(key) ?? await flow.peek(key);
|
|
591
597
|
console.log(item ? JSON.stringify({ ...item, artifacts: Object.keys(item.artifacts) }, null, 2) : "unknown");
|
|
592
598
|
if (item?.recovered)
|
|
593
|
-
console.log(
|
|
599
|
+
console.log(flow.recoveredHint(key).text);
|
|
594
600
|
for (const ev of store.events(key))
|
|
595
601
|
console.log(` ${ev.ts} ${ev.from} → ${ev.to} ${ev.detail}`);
|
|
596
602
|
}
|
|
@@ -599,6 +605,38 @@ export async function runWorkflow(cmd, rest) {
|
|
|
599
605
|
console.log(`${r.key.padEnd(12)} ${r.state.padEnd(15)} ${(r.issue ?? "").padEnd(12)} ${r.change ?? ""}`);
|
|
600
606
|
return;
|
|
601
607
|
}
|
|
608
|
+
case "report": {
|
|
609
|
+
const { buildReport, printReport } = await import("../workflow/report.js");
|
|
610
|
+
const json = has("json");
|
|
611
|
+
const since = flag("since");
|
|
612
|
+
let from;
|
|
613
|
+
if (since) {
|
|
614
|
+
const days = /^(\d+)d$/i.exec(since);
|
|
615
|
+
from = days ? new Date(Date.now() - Number(days[1]) * 86_400_000) : new Date(since);
|
|
616
|
+
if (Number.isNaN(from.getTime())) {
|
|
617
|
+
console.error("✘ --since takes a date (2026-11-01) or a number of days (30d)");
|
|
618
|
+
process.exitCode = 1;
|
|
619
|
+
return;
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
const r = buildReport(store.all().map((item) => ({ item, events: store.events(item.key) })), { from });
|
|
623
|
+
if (json)
|
|
624
|
+
console.log(JSON.stringify(r, null, 2));
|
|
625
|
+
else
|
|
626
|
+
printReport(r);
|
|
627
|
+
return;
|
|
628
|
+
}
|
|
629
|
+
case "doctor": {
|
|
630
|
+
const { diagnose, printChecks } = await import("./doctor.js");
|
|
631
|
+
const checks = await diagnose(cfg, connectors);
|
|
632
|
+
if (has("json"))
|
|
633
|
+
console.log(JSON.stringify({ checks }, null, 2));
|
|
634
|
+
else
|
|
635
|
+
printChecks(checks);
|
|
636
|
+
if (checks.some((c) => c.status === "fail"))
|
|
637
|
+
process.exitCode = 1;
|
|
638
|
+
return;
|
|
639
|
+
}
|
|
602
640
|
case "connectors": {
|
|
603
641
|
// JSON for tools such as orqen-studio: {"conectores": {...}, "env": {"JIRA_TOKEN": "..."}} on stdin or in a file
|
|
604
642
|
const draftInput = () => JSON.parse(!rest[1] || rest[1] === "-" ? readFileSync(0, "utf8") : readFileSync(rest[1], "utf8"));
|
package/dist/connectors/asana.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* of the project; "completed" marks it done. Asana tags need ids, so the state is not mirrored as a tag.
|
|
5
5
|
*/
|
|
6
6
|
import { idOf, keyOf } from "./config.js";
|
|
7
|
+
import { toPlain } from "./markup.js";
|
|
7
8
|
import { BOT_MARK, checkFailure } from "./types.js";
|
|
8
9
|
const API = "https://app.asana.com/api/1.0";
|
|
9
10
|
export class AsanaTracker {
|
|
@@ -68,7 +69,7 @@ export class AsanaTracker {
|
|
|
68
69
|
}));
|
|
69
70
|
}
|
|
70
71
|
async comment(key, text) {
|
|
71
|
-
await this.req("POST", `/tasks/${this.gid(key)}/stories`, { text: `${BOT_MARK} ${text}` });
|
|
72
|
+
await this.req("POST", `/tasks/${this.gid(key)}/stories`, { text: `${BOT_MARK} ${toPlain(text)}` });
|
|
72
73
|
}
|
|
73
74
|
async setStateLabel() { }
|
|
74
75
|
async transition(key, name) {
|
|
@@ -84,7 +85,7 @@ export class AsanaTracker {
|
|
|
84
85
|
return true;
|
|
85
86
|
}
|
|
86
87
|
async create(t) {
|
|
87
|
-
const r = await this.req("POST", "/tasks", { name: t.title.slice(0, 250), notes: t.description, projects: [this.needProject()] });
|
|
88
|
+
const r = await this.req("POST", "/tasks", { name: t.title.slice(0, 250), notes: toPlain(t.description), projects: [this.needProject()] });
|
|
88
89
|
return keyOf(this.s.prefix, r.gid);
|
|
89
90
|
}
|
|
90
91
|
url(key) { return `https://app.asana.com/0/${this.s.project || 0}/${this.gid(key)}`; }
|
|
@@ -8,6 +8,48 @@ import { idOf, keyOf } from "./config.js";
|
|
|
8
8
|
import { toMarkdown } from "./markup.js";
|
|
9
9
|
import { BOT_MARK, LEGACY_STATE_LABELS, STATE_LABEL, checkFailure } from "./types.js";
|
|
10
10
|
const API = "https://api.github.com";
|
|
11
|
+
/**
|
|
12
|
+
* A search filter as parameters of the list of issues, or undefined when the list cannot express it. Without is:open/closed
|
|
13
|
+
* the search returns both, and so does the list (state=all). `label:a,b` means "a or b" in search but "a and b" in the list,
|
|
14
|
+
* so it is searched.
|
|
15
|
+
*/
|
|
16
|
+
export function listFilter(query) {
|
|
17
|
+
const f = { state: "all", labels: [] };
|
|
18
|
+
for (const token of query.match(/(?:[^\s"]+|"[^"]*")+/g) ?? []) {
|
|
19
|
+
const m = token.match(/^([a-z]+):(.+)$/i);
|
|
20
|
+
if (!m)
|
|
21
|
+
return undefined;
|
|
22
|
+
const v = m[2].replace(/"/g, "");
|
|
23
|
+
if (!v || v.includes(","))
|
|
24
|
+
return undefined;
|
|
25
|
+
switch (m[1].toLowerCase()) {
|
|
26
|
+
case "is":
|
|
27
|
+
case "state":
|
|
28
|
+
if (v === "issue")
|
|
29
|
+
break;
|
|
30
|
+
if (v === "open" || v === "closed") {
|
|
31
|
+
f.state = v;
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
34
|
+
return undefined;
|
|
35
|
+
case "label":
|
|
36
|
+
f.labels.push(v);
|
|
37
|
+
break;
|
|
38
|
+
case "assignee":
|
|
39
|
+
if (f.assignee)
|
|
40
|
+
return undefined;
|
|
41
|
+
f.assignee = v;
|
|
42
|
+
break;
|
|
43
|
+
case "author":
|
|
44
|
+
if (f.creator)
|
|
45
|
+
return undefined;
|
|
46
|
+
f.creator = v;
|
|
47
|
+
break;
|
|
48
|
+
default: return undefined;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return f;
|
|
52
|
+
}
|
|
11
53
|
export class GithubTracker {
|
|
12
54
|
s;
|
|
13
55
|
api;
|
|
@@ -86,7 +128,7 @@ export class GithubTracker {
|
|
|
86
128
|
if (!this.s.project) {
|
|
87
129
|
if (this.s.status)
|
|
88
130
|
throw new Error("Select a GitHub Project before choosing a pending status");
|
|
89
|
-
return this.
|
|
131
|
+
return this.find(this.s.query);
|
|
90
132
|
}
|
|
91
133
|
// The project's issues (in one status, or in any status when none is chosen), narrowed by the search qualifiers if there are any.
|
|
92
134
|
const project = await this.project();
|
|
@@ -111,7 +153,7 @@ export class GithubTracker {
|
|
|
111
153
|
} while (cursor);
|
|
112
154
|
// Preserve explicitly configured issue qualifiers as an additional filter.
|
|
113
155
|
if (!oldColumn && this.s.query.trim() && this.s.query.trim() !== "is:open") {
|
|
114
|
-
const matching = new Set(await this.
|
|
156
|
+
const matching = new Set(await this.find(this.s.query));
|
|
115
157
|
return [...new Set(keys)].filter((key) => matching.has(key));
|
|
116
158
|
}
|
|
117
159
|
return [...new Set(keys)];
|
|
@@ -129,6 +171,35 @@ export class GithubTracker {
|
|
|
129
171
|
const r = await this.req("GET", `/search/issues?per_page=100&q=${encodeURIComponent(q)}`);
|
|
130
172
|
return (r.items ?? []).map((i) => keyOf(this.s.prefix, i.number));
|
|
131
173
|
}
|
|
174
|
+
/**
|
|
175
|
+
* The issues a filter selects. When the filter only has qualifiers the list of issues understands (is:open|closed, state:,
|
|
176
|
+
* label:, assignee:, author:) the list is read instead of the search: the search allows 30 requests per minute (the list,
|
|
177
|
+
* 5000 per hour, which matters for an unattended `orqen cycle`) and returns a single page of 100 (the list is paginated).
|
|
178
|
+
* Anything else (free text, OR, negations) is searched. Neither shows an issue created a few seconds ago: GitHub takes a
|
|
179
|
+
* moment to list it either way, so it shows up on the next run.
|
|
180
|
+
*/
|
|
181
|
+
async find(query) {
|
|
182
|
+
const f = listFilter(query);
|
|
183
|
+
if (!f)
|
|
184
|
+
return this.search(query);
|
|
185
|
+
const keys = [];
|
|
186
|
+
for (let page = 1; page <= 10; page++) {
|
|
187
|
+
const p = new URLSearchParams({ state: f.state, per_page: "100", page: String(page) });
|
|
188
|
+
if (f.labels.length)
|
|
189
|
+
p.set("labels", f.labels.join(","));
|
|
190
|
+
if (f.assignee)
|
|
191
|
+
p.set("assignee", f.assignee);
|
|
192
|
+
if (f.creator)
|
|
193
|
+
p.set("creator", f.creator);
|
|
194
|
+
const rows = await this.req("GET", `/repos/{repo}/issues?${p}`);
|
|
195
|
+
keys.push(...rows.filter((i) => !i.pull_request).map((i) => keyOf(this.s.prefix, i.number))); // the list also has PRs
|
|
196
|
+
if (rows.length < 100)
|
|
197
|
+
break;
|
|
198
|
+
}
|
|
199
|
+
return keys;
|
|
200
|
+
}
|
|
201
|
+
labelled(label) { return this.find(`is:open label:"${label}"`); }
|
|
202
|
+
async addLabel(key, label) { await this.req("POST", `/repos/{repo}/issues/${this.n(key)}/labels`, { labels: [label] }); }
|
|
132
203
|
async ticket(key) {
|
|
133
204
|
const i = await this.req("GET", `/repos/{repo}/issues/${this.n(key)}`);
|
|
134
205
|
return {
|
package/dist/connectors/jira.js
CHANGED
|
@@ -52,6 +52,7 @@ export class JiraTracker {
|
|
|
52
52
|
return t ? JSON.parse(t) : {};
|
|
53
53
|
}
|
|
54
54
|
pending() { return this.search(this.s.query); }
|
|
55
|
+
labelled(label) { return this.search(`${this.s.project ? `project = "${this.s.project}" AND ` : ""}labels = "${label}" AND statusCategory != Done`); }
|
|
55
56
|
async search(jql) {
|
|
56
57
|
const path = this.s.deployment === "cloud" ? "/rest/api/3/search/jql" : "/rest/api/2/search";
|
|
57
58
|
const r = await this.req("GET", path, undefined, { jql, fields: "key", maxResults: 100 });
|
|
@@ -85,6 +86,9 @@ export class JiraTracker {
|
|
|
85
86
|
async comment(key, text) {
|
|
86
87
|
await this.req("POST", `/rest/api/2/issue/${this.native(key)}/comment`, { body: `${BOT_MARK} ${text}` });
|
|
87
88
|
}
|
|
89
|
+
async addLabel(key, label) {
|
|
90
|
+
await this.req("PUT", `/rest/api/2/issue/${this.native(key)}`, { update: { labels: [{ add: label }] } });
|
|
91
|
+
}
|
|
88
92
|
async setStateLabel(key, state) {
|
|
89
93
|
const { labels } = await this.ticket(key);
|
|
90
94
|
const next = labels.filter((l) => ![STATE_LABEL, ...LEGACY_STATE_LABELS].some((p) => l.startsWith(p))).concat(`${STATE_LABEL}${state.toLowerCase()}`);
|
package/dist/connectors/local.js
CHANGED
|
@@ -58,6 +58,16 @@ export class LocalTracker {
|
|
|
58
58
|
}
|
|
59
59
|
});
|
|
60
60
|
}
|
|
61
|
+
async addLabel(key, label) {
|
|
62
|
+
const t = this.read(key);
|
|
63
|
+
if (!t.labels.includes(label)) {
|
|
64
|
+
t.labels.push(label);
|
|
65
|
+
this.write(t);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
async labelled(label) {
|
|
69
|
+
return (await this.pending()).filter((k) => this.read(k).labels.includes(label));
|
|
70
|
+
}
|
|
61
71
|
async search(query) {
|
|
62
72
|
const q = query.toLowerCase().trim();
|
|
63
73
|
return this.keys().filter((k) => {
|
|
@@ -44,6 +44,46 @@ export function toMarkdown(text) {
|
|
|
44
44
|
out.push("```"); // an unclosed block must not swallow what follows
|
|
45
45
|
return out.join("\n");
|
|
46
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* Plain text for tools that show comments as typed (Asana's `text`): the Jira markup goes away without losing structure.
|
|
49
|
+
* `*bold*` → bold, `* item` → `• item`, `# item` → `1. item`, `h2. Title` → Title, `{{x}}` → x, `[text|url]` → text (url),
|
|
50
|
+
* `{code}` blocks keep their lines, indented. Text with no markup is returned as it is.
|
|
51
|
+
*/
|
|
52
|
+
export function toPlain(text) {
|
|
53
|
+
const out = [];
|
|
54
|
+
let fence = false, numbered = 0;
|
|
55
|
+
for (const raw of text.replace(/\r\n/g, "\n").split("\n")) {
|
|
56
|
+
if (/^\s*\{(?:code|noformat)(?::[\w+-]+)?\}\s*$/.test(raw)) {
|
|
57
|
+
fence = !fence;
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
if (fence) {
|
|
61
|
+
out.push(` ${raw}`);
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
const n = raw.match(/^#\s+(.*)$/);
|
|
65
|
+
if (n) {
|
|
66
|
+
numbered++;
|
|
67
|
+
out.push(`${numbered}. ${plainInline(n[1])}`);
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
numbered = 0;
|
|
71
|
+
const h = raw.match(/^h[1-6]\.\s+(.*)$/);
|
|
72
|
+
if (h) {
|
|
73
|
+
out.push(plainInline(h[1]));
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
const b = raw.match(/^\*\s+(.*)$/);
|
|
77
|
+
out.push(b ? `• ${plainInline(b[1])}` : plainInline(raw));
|
|
78
|
+
}
|
|
79
|
+
return out.join("\n");
|
|
80
|
+
}
|
|
81
|
+
function plainInline(line) {
|
|
82
|
+
return line
|
|
83
|
+
.replace(/(?<![*\w])\*(?=\S)([^*\n]+?)(?<=\S)\*(?![*\w])/g, "$1")
|
|
84
|
+
.replace(/\{\{([^}\n]+)\}\}/g, "$1")
|
|
85
|
+
.replace(/\[([^\]|\n]+)\|(https?:\/\/[^\]\s]+)\]/g, "$1 ($2)");
|
|
86
|
+
}
|
|
47
87
|
function inline(line) {
|
|
48
88
|
return line
|
|
49
89
|
// *bold* → **bold** (not when it is already **bold**, nor a * inside a word)
|
package/dist/connectors/types.js
CHANGED
|
@@ -15,6 +15,8 @@ export const isBotComment = (body) => [BOT_MARK, ...LEGACY_BOT_MARKS].some((m) =
|
|
|
15
15
|
/** Prefix of the label that mirrors the orqen state on the ticket (e.g. orqen-state-development). */
|
|
16
16
|
export const STATE_LABEL = "orqen-state-";
|
|
17
17
|
export const LEGACY_STATE_LABELS = ["rec-state-"];
|
|
18
|
+
/** Label of the issue of a worq started by the team (`orqen new_worq`): any machine finds it and knows it has no client request. */
|
|
19
|
+
export const WORQ_LABEL = "orqen-worq";
|
|
18
20
|
/** Readable detail of a failed check: Node's fetch only says "fetch failed" and leaves the reason in `cause`. */
|
|
19
21
|
export function checkFailure(e, host) {
|
|
20
22
|
const err = e;
|
package/dist/lib/kit.js
CHANGED
|
@@ -7,11 +7,12 @@
|
|
|
7
7
|
* - Skip files already up to date.
|
|
8
8
|
* - Replace files that match the saved hash.
|
|
9
9
|
* - Ask the user how to handle local edits.
|
|
10
|
+
* - Delete the kit files that the kit no longer ships (a command that was renamed or removed), unless the team edited them.
|
|
10
11
|
* Manage only the marked AGENTS.md block.
|
|
11
12
|
* Merge additions into OpenSpec config, CLAUDE.md, .gitignore, and marketplace.json.
|
|
12
13
|
*/
|
|
13
14
|
import { createHash } from "node:crypto";
|
|
14
|
-
import { existsSync, mkdirSync, readdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
|
|
15
|
+
import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
15
16
|
import { dirname, join, relative } from "node:path";
|
|
16
17
|
import { VERSION_CLI } from "./system.js";
|
|
17
18
|
import { TEMPLATES_DIR } from "./template-assets.js";
|
|
@@ -143,6 +144,8 @@ export function claudeSettings(actual, mk) {
|
|
|
143
144
|
j.enabledPlugins = { ...(j.enabledPlugins ?? {}), [`orqen@${mk}`]: true };
|
|
144
145
|
return JSON.stringify(j, null, 2) + "\n";
|
|
145
146
|
}
|
|
147
|
+
/** Folders whose files belong to the kit: what it stops shipping there can be deleted. */
|
|
148
|
+
const KIT_OWNED = /^orqen\/(plugin|stages)\//;
|
|
146
149
|
export function planificar(repo, vars, o = {}) {
|
|
147
150
|
const manifest = leerManifest(repo);
|
|
148
151
|
const cambios = [];
|
|
@@ -161,6 +164,14 @@ export function planificar(repo, vars, o = {}) {
|
|
|
161
164
|
accion = "conflicto";
|
|
162
165
|
cambios.push({ ruta, modo: "archivo", accion, nuevo, actual, hashNuevo: h });
|
|
163
166
|
}
|
|
167
|
+
// Files of an earlier kit that this one no longer ships, only inside the folders the kit owns.
|
|
168
|
+
for (const ruta of Object.keys(manifest.archivos)) {
|
|
169
|
+
if (ruta in archivos || !KIT_OWNED.test(ruta))
|
|
170
|
+
continue;
|
|
171
|
+
const actual = leer(join(repo, ruta));
|
|
172
|
+
const editado = actual !== undefined && manifest.archivos[ruta] !== hash(actual);
|
|
173
|
+
cambios.push({ ruta, modo: "archivo", accion: editado ? "obsoleto" : "borrar", nuevo: "", actual });
|
|
174
|
+
}
|
|
164
175
|
// Managed AGENTS.md block
|
|
165
176
|
{
|
|
166
177
|
const ruta = "AGENTS.md", clave = "AGENTS.md#orqen";
|
|
@@ -211,6 +222,13 @@ export async function aplicar(repo, cambios, resolver) {
|
|
|
211
222
|
out.push({ ruta: c.ruta, accion: "igual" });
|
|
212
223
|
continue;
|
|
213
224
|
}
|
|
225
|
+
if (c.accion === "borrar" || c.accion === "obsoleto") {
|
|
226
|
+
if (c.accion === "borrar")
|
|
227
|
+
rmSync(join(repo, c.ruta), { force: true });
|
|
228
|
+
delete manifest.archivos[clave];
|
|
229
|
+
out.push({ ruta: c.ruta, accion: c.accion });
|
|
230
|
+
continue;
|
|
231
|
+
}
|
|
214
232
|
if (c.accion === "conflicto") {
|
|
215
233
|
const d = await resolver(c);
|
|
216
234
|
if (d === "mantener") {
|
package/dist/lib/processes.js
CHANGED
|
@@ -56,14 +56,21 @@ function leerPuertos(repo) {
|
|
|
56
56
|
return {};
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
|
-
/** Can this port be listened on
|
|
60
|
-
|
|
59
|
+
/** Can this port be listened on on that host? An IPv6 host on a machine without IPv6 does not count against it. */
|
|
60
|
+
function sePuedeEscuchar(puerto, host) {
|
|
61
61
|
return new Promise((ok) => {
|
|
62
62
|
const s = createServer();
|
|
63
|
-
s.once("error", () => ok(
|
|
64
|
-
s.listen({ port: puerto, host
|
|
63
|
+
s.once("error", (e) => ok(host === "::" && ["EAFNOSUPPORT", "EADDRNOTAVAIL"].includes(e.code ?? "")));
|
|
64
|
+
s.listen({ port: puerto, host, exclusive: true }, () => s.close(() => ok(true)));
|
|
65
65
|
});
|
|
66
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* Can this port be listened on now? Checks IPv4 and IPv6 and that nothing answers on it: on Windows a server listening
|
|
69
|
+
* on `::` (Node's default) does not stop a bind on 127.0.0.1, so binding only there would hand the same port to two worktrees.
|
|
70
|
+
*/
|
|
71
|
+
export async function puertoLibre(puerto) {
|
|
72
|
+
return await sePuedeEscuchar(puerto, "127.0.0.1") && await sePuedeEscuchar(puerto, "::") && !(await puertoAbierto(puerto, 300));
|
|
73
|
+
}
|
|
67
74
|
/** The ports in use by this worktree: the assigned one of each dynamic process, the fixed one of the rest. */
|
|
68
75
|
export function puertosActuales(repo, procesos, variables = {}) {
|
|
69
76
|
const guardados = leerPuertos(repo);
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
---
|
|
2
|
-
description: Start a worq the team itself needs (no client request, no support or analysis): creates its issue in the connector and takes it to development
|
|
3
|
-
argument-hint: <title>
|
|
2
|
+
description: Start a worq the team itself needs (no client request, no support or analysis): creates its issue in the connector, or takes an existing one, and takes it to development
|
|
3
|
+
argument-hint: <title> | <ISSUE-KEY>
|
|
4
4
|
allowed-tools: Bash(orqen:*), AskUserQuestion
|
|
5
5
|
---
|
|
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
|
+
|
|
9
|
+
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.
|
|
8
10
|
|
|
9
11
|
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:
|
|
10
12
|
- **description**: what to do and why, in a few sentences.
|
|
@@ -12,10 +14,19 @@ Talk with the person briefly, in their language, until you have what `orqen new_
|
|
|
12
14
|
- **plan**: the steps, each ending with its estimate in hours, e.g. `Unify the entry point (2h)`.
|
|
13
15
|
- **estimated_hours**: the total.
|
|
14
16
|
|
|
15
|
-
|
|
17
|
+
Recognise the kind of work and propose its usual criteria, so the person confirms or adjusts instead of writing them from scratch:
|
|
18
|
+
- **Refactor**: the behaviour does not change (the existing tests pass without editing them); what was duplicated or tangled has one place; no public API changes unless agreed.
|
|
19
|
+
- **Technical debt / cleanup**: the dead code, warning or workaround named in the description is gone; the build and the tests stay green.
|
|
20
|
+
- **Dependency upgrade**: the new version is in the manifest and the lock file; the tests pass; the breaking changes of the changelog that affect the project are handled (name them).
|
|
21
|
+
- **Bug the team found**: a test that reproduces the bug fails before the fix and passes after it; nearby behaviour stays the same.
|
|
22
|
+
- **Tooling / CI / scripts**: the new command or job runs from a clean checkout; the README or the docs say how to use it.
|
|
23
|
+
- **Performance**: the operation is measured before and after with the same data, and the target is a number.
|
|
24
|
+
|
|
25
|
+
Show the person the brief and get their explicit OK, because the issue is created (or labelled and commented) in the tracker right away. Then write it as JSON in a temporary file outside the repository and run, from the repository root:
|
|
16
26
|
|
|
17
|
-
`orqen new_worq "<title>" <brief.json>`
|
|
27
|
+
- new issue: `orqen new_worq "<title>" <brief.json>`
|
|
28
|
+
- existing issue: `orqen new_worq --issue <KEY> <brief.json>` (the title is the issue's; pass `"<title>"` before the file to use another)
|
|
18
29
|
|
|
19
|
-
The brief is `{ "description": "...", "acceptance_criteria": ["..."], "plan": ["... (2h)"], "estimated_hours": 4 }`. orqen validates it
|
|
30
|
+
The brief is `{ "description": "...", "acceptance_criteria": ["..."], "plan": ["... (2h)"], "estimated_hours": 4 }`. orqen validates it and starts the worq with the issue's key (`<KEY>`), in DEVELOPMENT, direct lane. If it reports the brief is invalid, nothing was created: fix what it names and run it again. If it says the issue was created but the worq could not start, fix that and run the `--issue` command it prints, so no second issue is created.
|
|
20
31
|
|
|
21
32
|
Then continue with `/orqen:implement <KEY>`. The rest of the flow is the usual one (testing, `/orqen:pr`, senior `/orqen:approve`) without QA. There is no delivery or client acceptance: when a person merges the PR by hand, orqen detects it and closes the worq and its issue.
|
package/dist/template/AGENTS.md
CHANGED
|
@@ -30,7 +30,7 @@ The 9 steps, one command each (the person runs it; you follow it):
|
|
|
30
30
|
|
|
31
31
|
### Working with the person
|
|
32
32
|
|
|
33
|
-
Development the team starts itself (no client, no request) skips support and analysis: `/orqen:new_worq <title>` (or `orqen new_worq "<title>" <brief.json>`) creates the issue in the connector in use and a worq with its key in DEVELOPMENT, direct lane, with the brief as its analysis. It follows implement → testing → PR → senior review, without QA, and closes by itself when a person merges the PR (there is no delivery or client acceptance). Its issue is created in the issues connector (or the requests one when there is none) and closed with the worq.
|
|
33
|
+
Development the team starts itself (no client, no request) skips support and analysis: `/orqen:new_worq <title>` (or `orqen new_worq "<title>" <brief.json>`) creates the issue in the connector in use (or takes an existing one with `--issue <KEY>`) and a worq with its key in DEVELOPMENT, direct lane, with the brief as its analysis. It follows implement → testing → PR → senior review, without QA, and closes by itself when a person merges the PR (there is no delivery or client acceptance). Its issue is created in the issues connector (or the requests one when there is none) and closed with the worq.
|
|
34
34
|
|
|
35
35
|
In any stage, use `/orqen:ask <KEY> <question>` to ask the requester directly on the original request. The requester can reply with an ordinary comment. To read the replies and refresh `orqen/worqs/<KEY>/conversation.json`, run `orqen conversation <KEY>`. Both commands accept the request key or its linked issue key and preserve the current stage.
|
|
36
36
|
|
package/dist/workflow/process.js
CHANGED
|
@@ -16,7 +16,7 @@ import { detectarIdioma } from "../lib/lang.js";
|
|
|
16
16
|
import { SCHEMAS } from "./schemas.js";
|
|
17
17
|
import { LANES, State, GATES, isAgentState, isFinal, isGate, nextStateAfterStage, } from "./states.js";
|
|
18
18
|
import { Factory } from "./factory.js";
|
|
19
|
-
import { canLinkNatively, isBotComment, LEGACY_STATE_LABELS, STATE_LABEL } from "../connectors/index.js";
|
|
19
|
+
import { canLinkNatively, isBotComment, LEGACY_STATE_LABELS, STATE_LABEL, WORQ_LABEL } from "../connectors/index.js";
|
|
20
20
|
import { hoursOf } from "./openspec.js";
|
|
21
21
|
import { reviewSql } from "./sql.js";
|
|
22
22
|
import { RoutedTracker } from "./routed.js";
|
|
@@ -100,7 +100,10 @@ export class Process {
|
|
|
100
100
|
const state = label ? label.slice(prefix.length).toUpperCase() : "";
|
|
101
101
|
if (!(state in State) || state === "NEW")
|
|
102
102
|
return newWorkItem(key);
|
|
103
|
-
const item = {
|
|
103
|
+
const item = {
|
|
104
|
+
...newWorkItem(key), state: state, title: ticket.title, recovered: "label",
|
|
105
|
+
...(ticket.labels.includes(WORQ_LABEL) || this.requests.isTeamWorq(key) ? { origin: "internal" } : {}),
|
|
106
|
+
};
|
|
104
107
|
this.fromLabels.set(key, item);
|
|
105
108
|
return item;
|
|
106
109
|
}
|
|
@@ -122,6 +125,33 @@ export class Process {
|
|
|
122
125
|
const rel = relative(this.cfg.repoPath, join(this.cfg.factoryDir, key)).replaceAll("\\", "/");
|
|
123
126
|
return rel.startsWith("..") || /^[a-zA-Z]:/.test(rel) ? `orqen/worqs/${key}` : rel;
|
|
124
127
|
}
|
|
128
|
+
branchOnOrigin = new Map();
|
|
129
|
+
/**
|
|
130
|
+
* A worq this machine knows only from its ticket's label: fetch its branch to recover it, or, when the branch is not on
|
|
131
|
+
* origin yet (whoever started it has not pushed), say so instead of suggesting a fetch that fails. Asked once per branch.
|
|
132
|
+
*/
|
|
133
|
+
recoveredHint(key) {
|
|
134
|
+
const branch = branchFor(key);
|
|
135
|
+
if (!this.branchOnOrigin.has(branch)) {
|
|
136
|
+
let on;
|
|
137
|
+
try {
|
|
138
|
+
on = this.ws.remoteBranchExists?.(branch);
|
|
139
|
+
}
|
|
140
|
+
catch {
|
|
141
|
+
on = undefined;
|
|
142
|
+
}
|
|
143
|
+
this.branchOnOrigin.set(branch, on);
|
|
144
|
+
}
|
|
145
|
+
if (this.branchOnOrigin.get(branch) === false)
|
|
146
|
+
return {
|
|
147
|
+
command: "", what: `Its branch ${branch} is not on origin yet: it appears once whoever started it pushes it (orqen pr)`,
|
|
148
|
+
text: `The state is read from the ticket's label: this machine has no record, and its branch ${branch} is not on origin yet. It appears once whoever started it pushes it (orqen pr); then git fetch origin ${branch} recovers the worq.`,
|
|
149
|
+
};
|
|
150
|
+
return {
|
|
151
|
+
command: `git fetch origin ${branch}`, what: "The state comes from the ticket only: fetch the request branch so orqen recovers its full record, then continue",
|
|
152
|
+
text: `The state is read from the ticket's label: this machine has no record. Fetch its branch to recover the worq (git fetch origin ${branch}).`,
|
|
153
|
+
};
|
|
154
|
+
}
|
|
125
155
|
fetchHint(key) {
|
|
126
156
|
return `If someone worked on it elsewhere, fetch its branch (git fetch origin ${branchFor(key)}) so orqen can recover its worq from ${this.worqRel(key)}/state.json.`;
|
|
127
157
|
}
|
|
@@ -210,7 +240,7 @@ export class Process {
|
|
|
210
240
|
qa: needsQa(item) && item.state === "QA_REVIEW" ? "pending" : needsQa(item) && item.state === "CODE_REVIEW" ? "approved" : undefined,
|
|
211
241
|
recovered: item.recovered,
|
|
212
242
|
next: item.recovered
|
|
213
|
-
? [{ step: 0, role: roleOf(item, this.cfg), command
|
|
243
|
+
? (({ command, what }) => [{ step: 0, role: roleOf(item, this.cfg), command, what }])(this.recoveredHint(item.key))
|
|
214
244
|
: nextSteps(item, this.cfg),
|
|
215
245
|
updated: this.store.events(item.key).at(-1)?.ts,
|
|
216
246
|
merge: item.state === "DELIVERY" && item.artifacts.devel_pr ? (item.artifacts.devel_pr_merged ? "merged" : "pending") : undefined,
|
|
@@ -1006,9 +1036,24 @@ export class Process {
|
|
|
1006
1036
|
* use (issues, or requests when there is none) and skips support and analysis: the brief (description, acceptance criteria and plan)
|
|
1007
1037
|
* takes the place of the analysis and the worq, keyed by that issue, is born in DEVELOPMENT, direct lane (implement → testing → PR →
|
|
1008
1038
|
* senior). It closes when its PR is merged.
|
|
1039
|
+
* With `existing` (`--issue <KEY>`) it takes an issue that is already there (created by a person, or left by an attempt that failed)
|
|
1040
|
+
* instead of creating one: the title defaults to the issue's.
|
|
1009
1041
|
*/
|
|
1010
|
-
async newWorq(title, raw, person) {
|
|
1011
|
-
const
|
|
1042
|
+
async newWorq(title, raw, person, existing) {
|
|
1043
|
+
const own = this.requests.ownSystem;
|
|
1044
|
+
let current;
|
|
1045
|
+
if (existing) {
|
|
1046
|
+
const was = this.item(existing);
|
|
1047
|
+
if (was)
|
|
1048
|
+
throw new Error(`${existing} is already a worq (${was.state}): see it with orqen status ${existing}`);
|
|
1049
|
+
try {
|
|
1050
|
+
current = await own.ticket(existing);
|
|
1051
|
+
}
|
|
1052
|
+
catch (e) {
|
|
1053
|
+
throw new Error(`${existing} could not be read in ${own.label}: ${e.message.split("\n")[0]}`);
|
|
1054
|
+
}
|
|
1055
|
+
}
|
|
1056
|
+
const t = title.trim() || current?.title?.trim() || "";
|
|
1012
1057
|
if (t.length < 5)
|
|
1013
1058
|
throw new Error("A title for the worq is required (at least 5 characters).");
|
|
1014
1059
|
const b = (raw ?? {});
|
|
@@ -1016,7 +1061,9 @@ export class Process {
|
|
|
1016
1061
|
const analysis = {
|
|
1017
1062
|
summary: typeof b.summary === "string" && b.summary.trim() ? b.summary.trim() : description || t,
|
|
1018
1063
|
type: "change", acceptance_criteria: b.acceptance_criteria, affected_capabilities: [], open_questions: [], risks: Array.isArray(b.risks) ? b.risks : [],
|
|
1019
|
-
ready: true, analyst_ok: true, route: "development", lane: "direct", lane_rationale:
|
|
1064
|
+
ready: true, analyst_ok: true, route: "development", lane: "direct", lane_rationale: existing
|
|
1065
|
+
? `Taken by orqen as a worq of the team (no client request), started by ${person}: direct lane.`
|
|
1066
|
+
: "Started by the team: no client request, direct lane.",
|
|
1020
1067
|
plan: b.plan, estimated_hours: b.estimated_hours,
|
|
1021
1068
|
};
|
|
1022
1069
|
// validated before creating anything: an invalid brief must not leave an issue behind
|
|
@@ -1024,18 +1071,27 @@ export class Process {
|
|
|
1024
1071
|
if (!parsed.success)
|
|
1025
1072
|
throw new Error(`The brief is not valid:\n${parsed.error.issues.map((i) => ` ${i.path.join(".") || "(root)"}: ${i.message}`).join("\n")}`);
|
|
1026
1073
|
const s = parsed.data;
|
|
1027
|
-
const
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1074
|
+
const brief = `*Acceptance criteria:*\n${bullets(s.acceptance_criteria)}\n\n*Plan:*\n${bullets(s.plan ?? [])}\n\n*Estimate:* ${s.estimated_hours ?? "?"} h\n*Started by:* ${person}`;
|
|
1075
|
+
let key;
|
|
1076
|
+
if (existing) {
|
|
1077
|
+
key = existing;
|
|
1078
|
+
// the label lets any machine find it; without addLabel (Asana) only the machines that know it do
|
|
1079
|
+
await this.attemptAsync(() => own.addLabel?.(key, WORQ_LABEL) ?? Promise.resolve());
|
|
1080
|
+
}
|
|
1081
|
+
else {
|
|
1082
|
+
key = await this.requests.create({
|
|
1083
|
+
title: t, route: "development", labels: [WORQ_LABEL, "lane-direct"],
|
|
1084
|
+
description: `${description || t}\n\n${brief}\n\nCreated with orqen (no client request).`,
|
|
1085
|
+
});
|
|
1086
|
+
}
|
|
1032
1087
|
const item = { ...newWorkItem(key), state: "ANALYSIS", origin: "internal", title: t, analyst: person, lock: { agent: "internal", since: new Date().toISOString() } };
|
|
1033
1088
|
this.store.save(item);
|
|
1034
1089
|
const r = await this.complete(key, analysis, "internal");
|
|
1035
1090
|
if (!r.ok) {
|
|
1036
1091
|
this.store.remove(key);
|
|
1037
1092
|
rmSync(this.fac.dirOf(key), { recursive: true, force: true });
|
|
1038
|
-
throw new Error(`The issue ${key} was created, but the worq could not start:\n${r.errors.map((e) => " " + e).join("\n")}`
|
|
1093
|
+
throw new Error(`The issue ${key} ${existing ? "is there" : "was created"}, but the worq could not start:\n${r.errors.map((e) => " " + e).join("\n")}\n` +
|
|
1094
|
+
`Fix it and take that issue with: orqen new_worq --issue ${key} <brief.json>`);
|
|
1039
1095
|
}
|
|
1040
1096
|
if (description)
|
|
1041
1097
|
this.fac.write(item, "brief.md", `# ${key} — ${t}\n\n${description}\n`);
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { isFinal } from "./states.js";
|
|
2
|
+
const HOUR = 3_600_000;
|
|
3
|
+
/** States after development where the work can be sent back to it. */
|
|
4
|
+
const REVIEW_STATES = ["TESTING", "QA_REVIEW", "CODE_REVIEW", "DELIVERY", "ACCEPTANCE"];
|
|
5
|
+
const round = (n) => Math.round(n * 10) / 10;
|
|
6
|
+
export const median = (xs) => {
|
|
7
|
+
if (!xs.length)
|
|
8
|
+
return 0;
|
|
9
|
+
const s = [...xs].sort((a, b) => a - b), m = Math.floor(s.length / 2);
|
|
10
|
+
return s.length % 2 ? s[m] : (s[m - 1] + s[m]) / 2;
|
|
11
|
+
};
|
|
12
|
+
export function worqReport(item, events, now = new Date()) {
|
|
13
|
+
if (!events.length)
|
|
14
|
+
return undefined;
|
|
15
|
+
const hoursIn = {};
|
|
16
|
+
let returns = 0;
|
|
17
|
+
for (let i = 0; i < events.length; i++) {
|
|
18
|
+
const e = events[i];
|
|
19
|
+
if (e.to === "DEVELOPMENT" && REVIEW_STATES.includes(e.from))
|
|
20
|
+
returns++;
|
|
21
|
+
if (isFinal(e.to))
|
|
22
|
+
continue;
|
|
23
|
+
const end = i + 1 < events.length ? Date.parse(events[i + 1].ts) : now.getTime();
|
|
24
|
+
hoursIn[e.to] = (hoursIn[e.to] ?? 0) + Math.max(0, end - Date.parse(e.ts)) / HOUR;
|
|
25
|
+
}
|
|
26
|
+
const entered = [...events].reverse().find((e) => e.from !== e.to) ?? events[0];
|
|
27
|
+
const finalEvent = events.find((e) => isFinal(e.to));
|
|
28
|
+
const started = events[0].ts;
|
|
29
|
+
const endMs = finalEvent ? Date.parse(finalEvent.ts) : now.getTime();
|
|
30
|
+
return {
|
|
31
|
+
key: item.key, title: item.title, state: item.state, lane: item.route === "operational" ? "operational" : item.lane,
|
|
32
|
+
internal: item.origin === "internal" || undefined, started, finished: finalEvent?.ts,
|
|
33
|
+
leadHours: round((endMs - Date.parse(started)) / HOUR),
|
|
34
|
+
hoursIn: Object.fromEntries(Object.entries(hoursIn).map(([k, v]) => [k, round(v)])),
|
|
35
|
+
returns, estimatedHours: typeof item.artifacts.estimated_hours === "number" ? item.artifacts.estimated_hours : undefined,
|
|
36
|
+
...(finalEvent ? {} : { inStateHours: round((now.getTime() - Date.parse(entered.ts)) / HOUR) }),
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/** The report of the worqs that had activity since `from` (all of them without it). */
|
|
40
|
+
export function buildReport(items, o = {}) {
|
|
41
|
+
const now = o.now ?? new Date();
|
|
42
|
+
const worqs = items
|
|
43
|
+
.filter(({ events }) => !o.from || events.some((e) => Date.parse(e.ts) >= o.from.getTime()))
|
|
44
|
+
.map(({ item, events }) => worqReport(item, events, now))
|
|
45
|
+
.filter((w) => !!w)
|
|
46
|
+
.sort((a, b) => a.started.localeCompare(b.started));
|
|
47
|
+
const byState = new Map();
|
|
48
|
+
for (const w of worqs)
|
|
49
|
+
for (const [s, h] of Object.entries(w.hoursIn)) {
|
|
50
|
+
if (s === "NEW")
|
|
51
|
+
continue;
|
|
52
|
+
byState.set(s, [...(byState.get(s) ?? []), h]);
|
|
53
|
+
}
|
|
54
|
+
const states = [...byState].map(([state, hs]) => ({ state, worqs: hs.length, medianHours: round(median(hs)), totalHours: round(hs.reduce((a, b) => a + b, 0)) }))
|
|
55
|
+
.sort((a, b) => b.medianHours - a.medianHours);
|
|
56
|
+
const closed = worqs.filter((w) => w.state === "CLOSED");
|
|
57
|
+
const lanes = new Map();
|
|
58
|
+
for (const w of closed)
|
|
59
|
+
lanes.set(w.lane ?? "—", [...(lanes.get(w.lane ?? "—") ?? []), w.leadHours]);
|
|
60
|
+
const leadByLane = [...lanes].map(([lane, hs]) => ({ lane, closed: hs.length, medianHours: round(median(hs)) }));
|
|
61
|
+
const est = closed.filter((w) => w.estimatedHours !== undefined && w.hoursIn.DEVELOPMENT !== undefined);
|
|
62
|
+
return {
|
|
63
|
+
from: o.from?.toISOString(), until: now.toISOString(), worqs,
|
|
64
|
+
totals: {
|
|
65
|
+
worqs: worqs.length, closed: closed.length, cancelled: worqs.filter((w) => w.state === "CANCELLED").length,
|
|
66
|
+
open: worqs.filter((w) => !isFinal(w.state)).length, blocked: worqs.filter((w) => w.state === "BLOCKED").length,
|
|
67
|
+
returns: worqs.reduce((a, w) => a + w.returns, 0), internal: worqs.filter((w) => w.internal).length,
|
|
68
|
+
},
|
|
69
|
+
states, leadByLane,
|
|
70
|
+
...(est.length ? { estimate: {
|
|
71
|
+
worqs: est.length, estimatedHours: round(est.reduce((a, w) => a + w.estimatedHours, 0)),
|
|
72
|
+
developmentHours: round(est.reduce((a, w) => a + w.hoursIn.DEVELOPMENT, 0)),
|
|
73
|
+
} } : {}),
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
const fmt = (h) => (h < 1 ? `${Math.round(h * 60)} min` : h < 48 ? `${round(h)} h` : `${round(h / 24)} d`);
|
|
77
|
+
export function printReport(r) {
|
|
78
|
+
const t = r.totals;
|
|
79
|
+
console.log(`Worqs${r.from ? ` with activity since ${r.from.slice(0, 10)}` : ""}: ${t.worqs} · closed ${t.closed} · open ${t.open}` +
|
|
80
|
+
`${t.blocked ? ` (blocked ${t.blocked})` : ""} · cancelled ${t.cancelled}${t.internal ? ` · of the team (new_worq) ${t.internal}` : ""}`);
|
|
81
|
+
if (!t.worqs)
|
|
82
|
+
return;
|
|
83
|
+
if (r.leadByLane.length) {
|
|
84
|
+
console.log("\nTime from start to close (median, closed ones):");
|
|
85
|
+
for (const l of r.leadByLane)
|
|
86
|
+
console.log(` ${l.lane.padEnd(12)} ${fmt(l.medianHours).padStart(8)} (${l.closed})`);
|
|
87
|
+
}
|
|
88
|
+
if (r.states.length) {
|
|
89
|
+
console.log("\nWhere the work spends its time (median per worq, slowest first):");
|
|
90
|
+
for (const s of r.states.slice(0, 8))
|
|
91
|
+
console.log(` ${s.state.padEnd(18)} ${fmt(s.medianHours).padStart(8)} (${s.worqs} worq${s.worqs === 1 ? "" : "s"})`);
|
|
92
|
+
}
|
|
93
|
+
const back = r.worqs.filter((w) => w.returns);
|
|
94
|
+
console.log(`\nBack to development: ${t.returns} time(s)${back.length ? ` in ${back.length} worq(s): ${back.sort((a, b) => b.returns - a.returns).slice(0, 5).map((w) => `${w.key} ×${w.returns}`).join(", ")}` : ""}`);
|
|
95
|
+
if (r.estimate)
|
|
96
|
+
console.log(`Estimate vs time in development (${r.estimate.worqs} closed): ${fmt(r.estimate.estimatedHours)} estimated · ${fmt(r.estimate.developmentHours)} in DEVELOPMENT (wall clock, waiting included)`);
|
|
97
|
+
const stuck = r.worqs.filter((w) => !isFinal(w.state)).map((w) => ({ w, h: w.inStateHours ?? 0 })).sort((a, b) => b.h - a.h).slice(0, 5);
|
|
98
|
+
if (stuck.length) {
|
|
99
|
+
console.log("\nOpen the longest in their current state:");
|
|
100
|
+
for (const { w, h } of stuck)
|
|
101
|
+
console.log(` ${w.key.padEnd(10)} ${w.state.padEnd(16)} ${fmt(h).padStart(8)} ${w.title ?? ""}`.trimEnd());
|
|
102
|
+
}
|
|
103
|
+
}
|
package/dist/workflow/routed.js
CHANGED
|
@@ -1,20 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The requests system as the process sees it. Real requests go to the requests connector; a worq started by the team (`orqen new_worq`)
|
|
3
|
+
* has no client request: its ticket is the issue that orqen created in the connector in use (issues, or requests when there is none),
|
|
4
|
+
* labelled WORQ_LABEL so that a machine with no record of it finds it too.
|
|
5
|
+
*/
|
|
6
|
+
import { WORQ_LABEL } from "../connectors/types.js";
|
|
1
7
|
export class RoutedTracker {
|
|
2
8
|
real;
|
|
3
9
|
own;
|
|
4
10
|
isOwn;
|
|
5
11
|
ownKeys;
|
|
6
|
-
/**
|
|
12
|
+
/** Keys found by their label in the connector (this machine may have no record of them). */
|
|
13
|
+
found = new Set();
|
|
14
|
+
/** `isOwn(key)`: this machine knows the worq is the team's own; `ownKeys()`: the open ones it knows (so they are reviewed too). */
|
|
7
15
|
constructor(real, own, isOwn, ownKeys) {
|
|
8
16
|
this.real = real;
|
|
9
17
|
this.own = own;
|
|
10
18
|
this.isOwn = isOwn;
|
|
11
19
|
this.ownKeys = ownKeys;
|
|
12
20
|
}
|
|
13
|
-
to = (key) => (this.isOwn(key) ? this.own : this.real);
|
|
21
|
+
to = (key) => (this.isOwn(key) || this.found.has(key) ? this.own : this.real);
|
|
14
22
|
get kind() { return this.real.kind; }
|
|
15
23
|
get label() { return this.real.label; }
|
|
16
|
-
/**
|
|
17
|
-
|
|
24
|
+
/** Where the team's own worqs live (the issues connector, or the requests one when there is none). */
|
|
25
|
+
get ownSystem() { return this.own; }
|
|
26
|
+
/** Whether the key is a worq of the team (known here or found by its label). */
|
|
27
|
+
isTeamWorq(key) { return this.isOwn(key) || this.found.has(key); }
|
|
28
|
+
/** The team's own worqs are always reviewed too (their PR is read, their merge detected), also those started on another machine. */
|
|
29
|
+
async pending() {
|
|
30
|
+
const keys = [...await this.real.pending(), ...this.ownKeys()];
|
|
31
|
+
if (this.own.labelled) {
|
|
32
|
+
try {
|
|
33
|
+
for (const k of await this.own.labelled(WORQ_LABEL)) {
|
|
34
|
+
this.found.add(k);
|
|
35
|
+
keys.push(k);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
catch { /* the connector could not be searched: the worqs this machine knows are still there */ }
|
|
39
|
+
}
|
|
40
|
+
return [...new Set(keys)];
|
|
41
|
+
}
|
|
18
42
|
search(query) { return this.real.search(query); }
|
|
19
43
|
ticket(key) { return this.to(key).ticket(key); }
|
|
20
44
|
comments(key) { return this.to(key).comments(key); }
|