@miroshnik/elves 2026.1026.4 → 2026.1026.5
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.
|
@@ -78,8 +78,8 @@ function fieldAliases() {
|
|
|
78
78
|
}
|
|
79
79
|
var BUILTIN_FIELDS = new Set(["TITLE", "ASSIGNEES", "LABELS", "LINKED_PULL_REQUESTS", "MILESTONE", "REPOSITORY", "REVIEWERS", "PARENT_ISSUE", "SUB_ISSUES_PROGRESS", "CREATED", "UPDATED", "CLOSED", "TRACKS", "TRACKED_BY", "ISSUE_TYPE"]);
|
|
80
80
|
var NOT_DONE_REASONS = new Set(["NOT_PLANNED", "DUPLICATE"]);
|
|
81
|
-
function realRun(cmd, args, cwd) {
|
|
82
|
-
const r = spawnSync(cmd, args, { cwd, encoding: "utf8", maxBuffer: 64 * 1024 * 1024 });
|
|
81
|
+
function realRun(cmd, args, cwd, env) {
|
|
82
|
+
const r = spawnSync(cmd, args, { cwd, encoding: "utf8", maxBuffer: 64 * 1024 * 1024, ...env ? { env: { ...process.env, ...env } } : {} });
|
|
83
83
|
return { status: r.error ? null : r.status, stdout: r.stdout ?? "", stderr: r.error ? String(r.error.message) : r.stderr ?? "" };
|
|
84
84
|
}
|
|
85
85
|
function git(io, cwd, ...args) {
|
|
@@ -4152,6 +4152,8 @@ function missingPrLabels(io, slug, number) {
|
|
|
4152
4152
|
return out;
|
|
4153
4153
|
}
|
|
4154
4154
|
var PREMERGE_SCRIPTS = ["typecheck", "test:spec"];
|
|
4155
|
+
var STACK_TASK_VAR = "ELVES_TASK";
|
|
4156
|
+
var STACK_FAILED_VAR = "ELVES_TASK_ENV_FAILED";
|
|
4155
4157
|
var SPEC_ROOTS = ["tests/standards", "tests/architecture"];
|
|
4156
4158
|
var specRoots = (dir) => SPEC_ROOTS.filter((d) => statSync(path.join(dir, d), { throwIfNoEntry: false })?.isDirectory());
|
|
4157
4159
|
var MERGE_REF_SLACK_MS = 60000;
|
|
@@ -4194,7 +4196,7 @@ function scriptsOf(dir) {
|
|
|
4194
4196
|
const pkg = path.join(dir, "package.json");
|
|
4195
4197
|
return existsSync(pkg) ? JSON.parse(readFileSync(pkg, "utf8")).scripts ?? {} : {};
|
|
4196
4198
|
}
|
|
4197
|
-
function checkTree(io, dir, steps) {
|
|
4199
|
+
function checkTree(io, dir, steps, env) {
|
|
4198
4200
|
const run = io.run ?? realRun;
|
|
4199
4201
|
const cmds = projectCommands(dir);
|
|
4200
4202
|
const install = cmds.install ? { cmd: cmds.install.join(" "), result: run(cmds.install[0], cmds.install.slice(1), dir) } : null;
|
|
@@ -4204,7 +4206,7 @@ function checkTree(io, dir, steps) {
|
|
|
4204
4206
|
for (const s of steps) {
|
|
4205
4207
|
const args = s.args ?? [];
|
|
4206
4208
|
const argv = [...cmds.run(s.script), ...args.length && packageManager(dir).name === "npm" ? ["--"] : [], ...args];
|
|
4207
|
-
const result = run(argv[0], argv.slice(1), dir);
|
|
4209
|
+
const result = env ? run(argv[0], argv.slice(1), dir, env) : run(argv[0], argv.slice(1), dir);
|
|
4208
4210
|
ran.push(s.script);
|
|
4209
4211
|
if (result.status !== 0)
|
|
4210
4212
|
return { install, ran, red: { script: s.script, cmd: argv.join(" "), result } };
|
|
@@ -4476,12 +4478,22 @@ function cmdPrPremerge(io, slug, number) {
|
|
|
4476
4478
|
io.out(`${base} moved on past the head of PR #${number} (origin/${base} — ${tip.slice(0, 7) || "not read"}) — checking the merge with origin/${base}`);
|
|
4477
4479
|
}
|
|
4478
4480
|
const ON_MERGE = "on the merge";
|
|
4481
|
+
const task = taskBranch(String(pr.head?.ref ?? ""))?.issue;
|
|
4482
|
+
const failedFile = path.join(mkdtempSync(path.join(os.tmpdir(), "elves-premerge-stack-")), "failed");
|
|
4483
|
+
const stackEnv = { [STACK_FAILED_VAR]: failedFile, ...task ? { [STACK_TASK_VAR]: String(task) } : {} };
|
|
4484
|
+
const stackFailed = () => existsSync(failedFile) ? readFileSync(failedFile, "utf8").split(`
|
|
4485
|
+
`).filter(Boolean) : null;
|
|
4486
|
+
const unchecked = (where, script, lines) => {
|
|
4487
|
+
io.out(`❌ couldn't check: the stack of ${task ? `task #${task}` : "the PR's task (its branch has no task number)"} didn't come up for ${script} ${where} — ${lines.join("; ")}`);
|
|
4488
|
+
io.out(`the red ${script} isn't counted against ${base} or the PR: bring the stack up (task-env up${task ? ` ${task}` : " <N>"}) and pr premerge ${number} again`);
|
|
4489
|
+
return 2;
|
|
4490
|
+
};
|
|
4479
4491
|
const checks = (dir, where, scripts) => {
|
|
4480
4492
|
const defined = scriptsOf(dir);
|
|
4481
4493
|
const present = scripts.filter((s) => defined[s]);
|
|
4482
4494
|
if (!present.length)
|
|
4483
4495
|
return null;
|
|
4484
|
-
const { install, ran, red } = checkTree(io, dir, present.map((script) => ({ script })));
|
|
4496
|
+
const { install, ran, red } = checkTree(io, dir, present.map((script) => ({ script })), stackEnv);
|
|
4485
4497
|
if (install) {
|
|
4486
4498
|
if (install.result.status !== 0)
|
|
4487
4499
|
throw new GhError(`installing dependencies ${where} failed (${install.cmd}): ${tail(install.result, 5).join(" / ")}`);
|
|
@@ -4495,57 +4507,67 @@ ${red.result.stderr}`).split(`
|
|
|
4495
4507
|
return { ran, red: { ...red, failed } };
|
|
4496
4508
|
};
|
|
4497
4509
|
const breaks = (script) => `❌ don't merge: ${script} is red on the merge with origin/${base} — fix the root cause in the PR: rebase onto origin/${base}, edit, push --force-with-lease, ${recheck}`;
|
|
4498
|
-
|
|
4499
|
-
|
|
4500
|
-
|
|
4501
|
-
|
|
4502
|
-
|
|
4510
|
+
try {
|
|
4511
|
+
return inTempWorktree(io, "premerge", `origin/${base}`, (dir) => {
|
|
4512
|
+
const short = (ref) => git(io, dir, "rev-parse", "--short=7", ref).stdout.trim();
|
|
4513
|
+
const merge = git(io, dir, "-c", "user.name=elves", "-c", "user.email=elves@localhost", "-c", "commit.gpgsign=false", "merge", "-q", "--no-ff", "--no-verify", "--no-edit", head);
|
|
4514
|
+
if (merge.status !== 0) {
|
|
4515
|
+
const files = git(io, dir, "diff", "--name-only", "--diff-filter=U").stdout.split(`
|
|
4503
4516
|
`).filter(Boolean);
|
|
4504
|
-
|
|
4505
|
-
|
|
4506
|
-
|
|
4507
|
-
|
|
4508
|
-
|
|
4509
|
-
|
|
4510
|
-
|
|
4511
|
-
|
|
4512
|
-
|
|
4513
|
-
|
|
4514
|
-
|
|
4515
|
-
|
|
4516
|
-
|
|
4517
|
-
|
|
4518
|
-
|
|
4519
|
-
|
|
4520
|
-
|
|
4521
|
-
|
|
4522
|
-
|
|
4523
|
-
|
|
4524
|
-
|
|
4525
|
-
|
|
4526
|
-
|
|
4527
|
-
|
|
4528
|
-
|
|
4529
|
-
|
|
4530
|
-
io.out(
|
|
4531
|
-
|
|
4532
|
-
|
|
4533
|
-
|
|
4534
|
-
|
|
4535
|
-
|
|
4536
|
-
|
|
4537
|
-
|
|
4538
|
-
|
|
4517
|
+
if (!files.length)
|
|
4518
|
+
throw new GhError(`git merge: ${merge.stderr.trim()}`);
|
|
4519
|
+
io.out(`❌ don't merge: a merge conflict with origin/${base} — ${files.join(", ")}; rebase onto origin/${base}, push --force-with-lease, ${recheck}`);
|
|
4520
|
+
return 1;
|
|
4521
|
+
}
|
|
4522
|
+
io.out(`+ merge of ${head.slice(0, 7)} with origin/${base} ${short("HEAD^1")} — no conflicts`);
|
|
4523
|
+
const roots = specRoots(dir);
|
|
4524
|
+
if (roots.length && !scriptsOf(dir)["test:spec"])
|
|
4525
|
+
io.out(`○ ${roots.join(", ")} aren't checked on the merge: the merge's package.json has no test:spec script — the project's check names the line to add (bunx github:miroshnik/elves check)`);
|
|
4526
|
+
const merged = checks(dir, ON_MERGE, PREMERGE_SCRIPTS);
|
|
4527
|
+
if (!merged) {
|
|
4528
|
+
io.out(`○ no fast checks: the merge's package.json has no ${PREMERGE_SCRIPTS.join(" or ")} scripts — step skipped`);
|
|
4529
|
+
io.out(`✅ merge: the merge with origin/${base} has no conflicts`);
|
|
4530
|
+
return 0;
|
|
4531
|
+
}
|
|
4532
|
+
const red = merged.red;
|
|
4533
|
+
if (!red) {
|
|
4534
|
+
io.out(`✅ merge: ${merged.ran.join(" and ")} ${merged.ran.length > 1 ? "are" : "is"} green on the merge with origin/${base}`);
|
|
4535
|
+
return 0;
|
|
4536
|
+
}
|
|
4537
|
+
io.out(`${red.cmd} failed:`);
|
|
4538
|
+
for (const l of red.failed.length ? red.failed.slice(0, 20) : tail(red.result))
|
|
4539
|
+
io.out(` ${l.trim()}`);
|
|
4540
|
+
const down = stackFailed();
|
|
4541
|
+
if (down)
|
|
4542
|
+
return unchecked(ON_MERGE, red.script, down);
|
|
4543
|
+
io.out(`checking bare origin/${base}: is it red by itself`);
|
|
4544
|
+
const bare = inTempWorktree(io, "premerge", `origin/${base}`, (bareDir) => checks(bareDir, `on origin/${base}`, [red.script])?.red);
|
|
4545
|
+
const bareDown = stackFailed();
|
|
4546
|
+
if (bareDown)
|
|
4547
|
+
return unchecked(`on origin/${base}`, red.script, bareDown);
|
|
4548
|
+
if (!bare) {
|
|
4549
|
+
io.out(breaks(red.script));
|
|
4550
|
+
return 1;
|
|
4551
|
+
}
|
|
4552
|
+
const onMain = new Set(bare.failed.map(failure));
|
|
4553
|
+
const own = red.failed.filter((l) => !onMain.has(failure(l)));
|
|
4554
|
+
if (own.length && bare.failed.length) {
|
|
4555
|
+
io.out(`${base} is red by itself, the PR breaks beyond it:`);
|
|
4556
|
+
for (const l of own.slice(0, 20))
|
|
4557
|
+
io.out(` ${l}`);
|
|
4558
|
+
io.out(breaks(red.script));
|
|
4559
|
+
return 1;
|
|
4560
|
+
}
|
|
4561
|
+
const reason = `${red.script} is red on bare origin/${base} too, with the same failures`;
|
|
4562
|
+
const code = mainRed(`${base} is red by itself: ${reason}`, reason, git(io, dir, "rev-parse", `origin/${base}`).stdout.trim(), [red.script], (names) => names.join(", "));
|
|
4563
|
+
if (code !== null)
|
|
4564
|
+
return code;
|
|
4539
4565
|
io.out(breaks(red.script));
|
|
4540
4566
|
return 1;
|
|
4541
|
-
}
|
|
4542
|
-
|
|
4543
|
-
|
|
4544
|
-
|
|
4545
|
-
return code;
|
|
4546
|
-
io.out(breaks(red.script));
|
|
4547
|
-
return 1;
|
|
4548
|
-
});
|
|
4567
|
+
});
|
|
4568
|
+
} finally {
|
|
4569
|
+
rmSync(path.dirname(failedFile), { recursive: true, force: true });
|
|
4570
|
+
}
|
|
4549
4571
|
}
|
|
4550
4572
|
var HELP = {
|
|
4551
4573
|
"project check": `github project check [--repo owner/repo]
|
|
@@ -4794,8 +4816,9 @@ Examples:
|
|
|
4794
4816
|
|
|
4795
4817
|
Before gh pr merge, after ci-wait PASS: the default branch moved after the PR's CI — the PR head merged with it in a
|
|
4796
4818
|
temporary worktree and ${PREMERGE_SCRIPTS.join(", then ")} from package.json (those that exist, as in CI). Code 0 —
|
|
4797
|
-
merge, 1 — don't merge (red, conflict), 2 — couldn't check
|
|
4798
|
-
|
|
4819
|
+
merge, 1 — don't merge (red, conflict), 2 — couldn't check (the stack of the PR's task didn't come up: the checks get
|
|
4820
|
+
ELVES_TASK — the number of the PR's branch — for task-env up on the detached HEAD), 3 — main is red by itself (the same
|
|
4821
|
+
check on bare main, a red check on its last commit): don't merge, one bug for it — wait for it to close. A PR into a batch branch runs no
|
|
4799
4822
|
CI, so no ci-wait before it: the head on a fresh origin/<batch> — code 0 without checks (the checks before a commit
|
|
4800
4823
|
checked this tree), the batch moved on — the fast checks on the merge with it. The
|
|
4801
4824
|
batch's release PR open — code 1 and the wait for its close, but red with the PR of one of its tasks — the guilty task's
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@miroshnik/elves",
|
|
3
|
-
"version": "2026.1026.
|
|
3
|
+
"version": "2026.1026.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Elves — a development flow with AI agents: shared rules and skills for any agent; install — bunx @miroshnik/elves install -g; the installer and skill scripts — TypeScript under Bun, tests — bun test in tests/",
|
|
6
6
|
"repository": {
|
|
@@ -72,5 +72,5 @@
|
|
|
72
72
|
"eslint-plugin-boundaries": "^7.2.0",
|
|
73
73
|
"knip": "^6.41.0"
|
|
74
74
|
},
|
|
75
|
-
"gitHead": "
|
|
75
|
+
"gitHead": "b1ea11a6e70c2ffa47d0f8f1141964af54c79f4a"
|
|
76
76
|
}
|
|
@@ -184,8 +184,11 @@ export interface Io {
|
|
|
184
184
|
env: Record<string, string | undefined>;
|
|
185
185
|
/** A pause before re-reading (GitHub doesn't show additions right away); in tests — no waiting. */
|
|
186
186
|
sleep?: (ms: number) => void;
|
|
187
|
-
/**
|
|
188
|
-
|
|
187
|
+
/**
|
|
188
|
+
* A subprocess (`est`, `git` of `task close`) — an external edge: replaced in tests; `env` — variables on top of the
|
|
189
|
+
* process's.
|
|
190
|
+
*/
|
|
191
|
+
run?: (cmd: string, args: string[], cwd?: string, env?: Record<string, string>) => RunResult;
|
|
189
192
|
/**
|
|
190
193
|
* The project checkout: its language (`.agents/elves.json`) is the language of names, `task close` runs its git
|
|
191
194
|
* steps in it; the current directory by default.
|
|
@@ -199,8 +202,8 @@ export interface RunResult {
|
|
|
199
202
|
stderr: string;
|
|
200
203
|
}
|
|
201
204
|
|
|
202
|
-
export function realRun(cmd: string, args: string[], cwd?: string): RunResult {
|
|
203
|
-
const r = spawnSync(cmd, args, { cwd, encoding: "utf8", maxBuffer: 64 * 1024 * 1024 });
|
|
205
|
+
export function realRun(cmd: string, args: string[], cwd?: string, env?: Record<string, string>): RunResult {
|
|
206
|
+
const r = spawnSync(cmd, args, { cwd, encoding: "utf8", maxBuffer: 64 * 1024 * 1024, ...(env ? { env: { ...process.env, ...env } } : {}) });
|
|
204
207
|
return { status: r.error ? null : r.status, stdout: r.stdout ?? "", stderr: r.error ? String(r.error.message) : (r.stderr ?? "") };
|
|
205
208
|
}
|
|
206
209
|
|
|
@@ -5623,6 +5626,14 @@ function missingPrLabels(io: Io, slug: string, number: number): string[] {
|
|
|
5623
5626
|
* of two PRs, seconds), then standards and architecture — minutes, not the whole `test`.
|
|
5624
5627
|
*/
|
|
5625
5628
|
export const PREMERGE_SCRIPTS = ["typecheck", "test:spec"];
|
|
5629
|
+
/**
|
|
5630
|
+
* The PR's task for task-env in the temporary worktree (#759) — a copy of `TASK_VAR` and `FAILED_VAR` of the task-env
|
|
5631
|
+
* script: the github skill imports no other skill (tests/standards/scripts/skill-imports). `ELVES_TASK` — the number of the
|
|
5632
|
+
* PR's branch: `up` on a detached HEAD takes that task's stack; `ELVES_TASK_ENV_FAILED` — the file a stack that didn't
|
|
5633
|
+
* come up appends its reason to.
|
|
5634
|
+
*/
|
|
5635
|
+
const STACK_TASK_VAR = "ELVES_TASK";
|
|
5636
|
+
const STACK_FAILED_VAR = "ELVES_TASK_ENV_FAILED";
|
|
5626
5637
|
/**
|
|
5627
5638
|
* Spec roots whose checks `test:spec` runs — standards and architecture (the spec skill): there two green PRs break
|
|
5628
5639
|
* main. A tree with them and without the script — premerge names what isn't checked on the merge, the project's
|
|
@@ -5728,10 +5739,10 @@ interface TreeRed {
|
|
|
5728
5739
|
/**
|
|
5729
5740
|
* A tree's check — `pr premerge` on the merge and on bare origin/<base>, the bisect of a red release at a boundary:
|
|
5730
5741
|
* dependencies by its lockfile (`projectCommands`), then the steps — a project script with its arguments (the test
|
|
5731
|
-
* files; npm — after `--`) — in order, up to the first red one
|
|
5732
|
-
* failed — no step ran.
|
|
5742
|
+
* files; npm — after `--`) — in order, up to the first red one, `env` — on top of the process's. `install` — its command
|
|
5743
|
+
* and result, no lockfile — null; failed — no step ran.
|
|
5733
5744
|
*/
|
|
5734
|
-
function checkTree(io: Io, dir: string, steps: { script: string; args?: string[] }[]): { install: { cmd: string; result: RunResult } | null; ran: string[]; red: TreeRed | null } {
|
|
5745
|
+
function checkTree(io: Io, dir: string, steps: { script: string; args?: string[] }[], env?: Record<string, string>): { install: { cmd: string; result: RunResult } | null; ran: string[]; red: TreeRed | null } {
|
|
5735
5746
|
const run = io.run ?? realRun;
|
|
5736
5747
|
const cmds = projectCommands(dir);
|
|
5737
5748
|
const install = cmds.install ? { cmd: cmds.install.join(" "), result: run(cmds.install[0]!, cmds.install.slice(1), dir) } : null;
|
|
@@ -5740,7 +5751,7 @@ function checkTree(io: Io, dir: string, steps: { script: string; args?: string[]
|
|
|
5740
5751
|
for (const s of steps) {
|
|
5741
5752
|
const args = s.args ?? [];
|
|
5742
5753
|
const argv = [...cmds.run(s.script), ...(args.length && packageManager(dir).name === "npm" ? ["--"] : []), ...args];
|
|
5743
|
-
const result = run(argv[0]!, argv.slice(1), dir);
|
|
5754
|
+
const result = env ? run(argv[0]!, argv.slice(1), dir, env) : run(argv[0]!, argv.slice(1), dir);
|
|
5744
5755
|
ran.push(s.script);
|
|
5745
5756
|
if (result.status !== 0) return { install, ran, red: { script: s.script, cmd: argv.join(" "), result } };
|
|
5746
5757
|
}
|
|
@@ -6109,6 +6120,18 @@ export function cmdPrPremerge(io: Io, slug: string, number: number): number {
|
|
|
6109
6120
|
|
|
6110
6121
|
const ON_MERGE = "on the merge";
|
|
6111
6122
|
type Red = TreeRed & { failed: string[] };
|
|
6123
|
+
// the database of the PR's task stack (#759): the temporary worktree is on a detached HEAD, task-env takes the task
|
|
6124
|
+
// from ELVES_TASK — the number of the PR's branch — and appends a stack that didn't come up to ELVES_TASK_ENV_FAILED
|
|
6125
|
+
const task = taskBranch(String(pr.head?.ref ?? ""))?.issue;
|
|
6126
|
+
const failedFile = path.join(mkdtempSync(path.join(os.tmpdir(), "elves-premerge-stack-")), "failed");
|
|
6127
|
+
const stackEnv: Record<string, string> = { [STACK_FAILED_VAR]: failedFile, ...(task ? { [STACK_TASK_VAR]: String(task) } : {}) };
|
|
6128
|
+
/** A stack that didn't come up during a check — its reasons; none — null. */
|
|
6129
|
+
const stackFailed = () => (existsSync(failedFile) ? readFileSync(failedFile, "utf8").split("\n").filter(Boolean) : null);
|
|
6130
|
+
const unchecked = (where: string, script: string, lines: string[]) => {
|
|
6131
|
+
io.out(`❌ couldn't check: the stack of ${task ? `task #${task}` : "the PR's task (its branch has no task number)"} didn't come up for ${script} ${where} — ${lines.join("; ")}`);
|
|
6132
|
+
io.out(`the red ${script} isn't counted against ${base} or the PR: bring the stack up (task-env up${task ? ` ${task}` : " <N>"}) and pr premerge ${number} again`);
|
|
6133
|
+
return 2;
|
|
6134
|
+
};
|
|
6112
6135
|
/**
|
|
6113
6136
|
* The tree's fast checks (`scripts` — those that exist) with dependencies from its lockfile, up to the first red one;
|
|
6114
6137
|
* none — null.
|
|
@@ -6117,7 +6140,7 @@ export function cmdPrPremerge(io: Io, slug: string, number: number): number {
|
|
|
6117
6140
|
const defined = scriptsOf(dir);
|
|
6118
6141
|
const present = scripts.filter((s) => defined[s]);
|
|
6119
6142
|
if (!present.length) return null;
|
|
6120
|
-
const { install, ran, red } = checkTree(io, dir, present.map((script) => ({ script })));
|
|
6143
|
+
const { install, ran, red } = checkTree(io, dir, present.map((script) => ({ script })), stackEnv);
|
|
6121
6144
|
if (install) {
|
|
6122
6145
|
if (install.result.status !== 0) throw new GhError(`installing dependencies ${where} failed (${install.cmd}): ${tail(install.result, 5).join(" / ")}`);
|
|
6123
6146
|
io.out(`+ dependencies${where === ON_MERGE ? "" : ` ${where}`}: ${install.cmd}`);
|
|
@@ -6127,57 +6150,65 @@ export function cmdPrPremerge(io: Io, slug: string, number: number): number {
|
|
|
6127
6150
|
return { ran, red: { ...red, failed } };
|
|
6128
6151
|
};
|
|
6129
6152
|
const breaks = (script: string) => `❌ don't merge: ${script} is red on the merge with origin/${base} — fix the root cause in the PR: rebase onto origin/${base}, edit, push --force-with-lease, ${recheck}`;
|
|
6130
|
-
|
|
6131
|
-
|
|
6132
|
-
|
|
6133
|
-
|
|
6134
|
-
|
|
6135
|
-
|
|
6136
|
-
|
|
6137
|
-
|
|
6138
|
-
|
|
6139
|
-
|
|
6140
|
-
|
|
6141
|
-
|
|
6142
|
-
|
|
6143
|
-
|
|
6144
|
-
|
|
6145
|
-
|
|
6146
|
-
|
|
6147
|
-
|
|
6148
|
-
|
|
6149
|
-
|
|
6150
|
-
|
|
6151
|
-
|
|
6152
|
-
|
|
6153
|
-
|
|
6154
|
-
|
|
6155
|
-
|
|
6156
|
-
|
|
6157
|
-
|
|
6158
|
-
|
|
6159
|
-
|
|
6160
|
-
|
|
6161
|
-
|
|
6162
|
-
|
|
6163
|
-
io.out(
|
|
6164
|
-
|
|
6165
|
-
|
|
6166
|
-
|
|
6167
|
-
|
|
6168
|
-
|
|
6169
|
-
|
|
6170
|
-
|
|
6171
|
-
|
|
6153
|
+
try {
|
|
6154
|
+
return inTempWorktree(io, "premerge", `origin/${base}`, (dir) => {
|
|
6155
|
+
const short = (ref: string) => git(io, dir, "rev-parse", "--short=7", ref).stdout.trim();
|
|
6156
|
+
// like GitHub's merge-ref; a rebase merge without conflicts gives the same tree. A temporary merge doesn't need the
|
|
6157
|
+
// project's hooks
|
|
6158
|
+
const merge = git(io, dir, "-c", "user.name=elves", "-c", "user.email=elves@localhost", "-c", "commit.gpgsign=false", "merge", "-q", "--no-ff", "--no-verify", "--no-edit", head);
|
|
6159
|
+
if (merge.status !== 0) {
|
|
6160
|
+
const files = git(io, dir, "diff", "--name-only", "--diff-filter=U").stdout.split("\n").filter(Boolean);
|
|
6161
|
+
if (!files.length) throw new GhError(`git merge: ${merge.stderr.trim()}`);
|
|
6162
|
+
io.out(`❌ don't merge: a merge conflict with origin/${base} — ${files.join(", ")}; rebase onto origin/${base}, push --force-with-lease, ${recheck}`);
|
|
6163
|
+
return 1;
|
|
6164
|
+
}
|
|
6165
|
+
io.out(`+ merge of ${head.slice(0, 7)} with origin/${base} ${short("HEAD^1")} — no conflicts`);
|
|
6166
|
+
// standards without test:spec don't stop the merge: the project's check holds the script, here — that they weren't run
|
|
6167
|
+
const roots = specRoots(dir);
|
|
6168
|
+
if (roots.length && !scriptsOf(dir)["test:spec"]) io.out(`○ ${roots.join(", ")} aren't checked on the merge: the merge's package.json has no test:spec script — the project's check names the line to add (bunx github:miroshnik/elves check)`);
|
|
6169
|
+
const merged = checks(dir, ON_MERGE, PREMERGE_SCRIPTS);
|
|
6170
|
+
if (!merged) {
|
|
6171
|
+
io.out(`○ no fast checks: the merge's package.json has no ${PREMERGE_SCRIPTS.join(" or ")} scripts — step skipped`);
|
|
6172
|
+
io.out(`✅ merge: the merge with origin/${base} has no conflicts`);
|
|
6173
|
+
return 0;
|
|
6174
|
+
}
|
|
6175
|
+
const red = merged.red;
|
|
6176
|
+
if (!red) {
|
|
6177
|
+
io.out(`✅ merge: ${merged.ran.join(" and ")} ${merged.ran.length > 1 ? "are" : "is"} green on the merge with origin/${base}`);
|
|
6178
|
+
return 0;
|
|
6179
|
+
}
|
|
6180
|
+
io.out(`${red.cmd} failed:`);
|
|
6181
|
+
for (const l of (red.failed.length ? red.failed.slice(0, 20) : tail(red.result))) io.out(` ${l.trim()}`);
|
|
6182
|
+
const down = stackFailed();
|
|
6183
|
+
if (down) return unchecked(ON_MERGE, red.script, down);
|
|
6184
|
+
|
|
6185
|
+
// a red merge — is bare main red by the same thing: then it's not this PR that breaks it
|
|
6186
|
+
io.out(`checking bare origin/${base}: is it red by itself`);
|
|
6187
|
+
const bare = inTempWorktree(io, "premerge", `origin/${base}`, (bareDir) => checks(bareDir, `on origin/${base}`, [red.script])?.red);
|
|
6188
|
+
const bareDown = stackFailed();
|
|
6189
|
+
if (bareDown) return unchecked(`on origin/${base}`, red.script, bareDown);
|
|
6190
|
+
if (!bare) {
|
|
6191
|
+
io.out(breaks(red.script));
|
|
6192
|
+
return 1;
|
|
6193
|
+
}
|
|
6194
|
+
const onMain = new Set(bare.failed.map(failure));
|
|
6195
|
+
const own = red.failed.filter((l) => !onMain.has(failure(l)));
|
|
6196
|
+
// can't tell what failed — can't tell them apart: main is red, after its fix premerge checks the PR again
|
|
6197
|
+
if (own.length && bare.failed.length) {
|
|
6198
|
+
io.out(`${base} is red by itself, the PR breaks beyond it:`);
|
|
6199
|
+
for (const l of own.slice(0, 20)) io.out(` ${l}`);
|
|
6200
|
+
io.out(breaks(red.script));
|
|
6201
|
+
return 1;
|
|
6202
|
+
}
|
|
6203
|
+
const reason = `${red.script} is red on bare origin/${base} too, with the same failures`;
|
|
6204
|
+
const code = mainRed(`${base} is red by itself: ${reason}`, reason, git(io, dir, "rev-parse", `origin/${base}`).stdout.trim(), [red.script], (names) => names.join(", "));
|
|
6205
|
+
if (code !== null) return code;
|
|
6172
6206
|
io.out(breaks(red.script));
|
|
6173
6207
|
return 1;
|
|
6174
|
-
}
|
|
6175
|
-
|
|
6176
|
-
|
|
6177
|
-
|
|
6178
|
-
io.out(breaks(red.script));
|
|
6179
|
-
return 1;
|
|
6180
|
-
});
|
|
6208
|
+
});
|
|
6209
|
+
} finally {
|
|
6210
|
+
rmSync(path.dirname(failedFile), { recursive: true, force: true });
|
|
6211
|
+
}
|
|
6181
6212
|
}
|
|
6182
6213
|
|
|
6183
6214
|
// ----------------------------------------------------------------------------
|
|
@@ -6436,8 +6467,9 @@ Examples:
|
|
|
6436
6467
|
|
|
6437
6468
|
Before gh pr merge, after ci-wait PASS: the default branch moved after the PR's CI — the PR head merged with it in a
|
|
6438
6469
|
temporary worktree and ${PREMERGE_SCRIPTS.join(", then ")} from package.json (those that exist, as in CI). Code 0 —
|
|
6439
|
-
merge, 1 — don't merge (red, conflict), 2 — couldn't check
|
|
6440
|
-
|
|
6470
|
+
merge, 1 — don't merge (red, conflict), 2 — couldn't check (the stack of the PR's task didn't come up: the checks get
|
|
6471
|
+
ELVES_TASK — the number of the PR's branch — for task-env up on the detached HEAD), 3 — main is red by itself (the same
|
|
6472
|
+
check on bare main, a red check on its last commit): don't merge, one bug for it — wait for it to close. A PR into a batch branch runs no
|
|
6441
6473
|
CI, so no ci-wait before it: the head on a fresh origin/<batch> — code 0 without checks (the checks before a commit
|
|
6442
6474
|
checked this tree), the batch moved on — the fast checks on the merge with it. The
|
|
6443
6475
|
batch's release PR open — code 1 and the wait for its close, but red with the PR of one of its tasks — the guilty task's
|
package/skills/task-env/SKILL.md
CHANGED
|
@@ -43,7 +43,7 @@ task's own Compose project, and nothing of it is shared with other tasks.
|
|
|
43
43
|
|
|
44
44
|
| what | value |
|
|
45
45
|
|---|---|
|
|
46
|
-
| task | the number from the branch `[<area>/]<type>/<N>-<slug>`; in the middle of a rebase — the branch being rebased (`rebase-merge/head-name`); no number — the main checkout's stack, but never from a linked worktree: there `up` and `down` without a number refuse (give `up <N>` or finish the rebase) |
|
|
46
|
+
| task | the number from the branch `[<area>/]<type>/<N>-<slug>`; in the middle of a rebase — the branch being rebased (`rebase-merge/head-name`); no number — the main checkout's stack, but never from a linked worktree: there `up` and `down` without a number take `ELVES_TASK=<N>` (`pr premerge` gives the PR's task to the checks on its detached HEAD), without it refuse (give `up <N>` or finish the rebase); a stack that didn't come up appends its reason to the file of `ELVES_TASK_ENV_FAILED` |
|
|
47
47
|
| `<project>` | the repository of `origin` (the last part of its URL without `.git`), no remote — the main checkout's directory; lowercase letters, digits and `-`. Not the directory Compose takes by default — a worktree's is random |
|
|
48
48
|
| stack | Compose project `<project>-<N>`, e2e — `<project>-<N>-e2e`, without a task — `<project>`, `<project>-e2e` |
|
|
49
49
|
| profiles | `--profile <name>` (repeated) goes to Compose: a heavy service in `profiles` runs only in a task that asks for it |
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
* unsandboxed call — an `excludedCommands` entry for it doesn't take it out (SKILL.md, «Docker and the sandbox»).
|
|
44
44
|
*/
|
|
45
45
|
import { spawnSync } from "node:child_process";
|
|
46
|
-
import { existsSync, readFileSync } from "node:fs";
|
|
46
|
+
import { appendFileSync, existsSync, readFileSync } from "node:fs";
|
|
47
47
|
import path from "node:path";
|
|
48
48
|
import { fileURLToPath } from "node:url";
|
|
49
49
|
|
|
@@ -58,11 +58,12 @@ export const HELP: Record<string, string> = {
|
|
|
58
58
|
up: `task-env up [<N>] [--profile <p>]...
|
|
59
59
|
|
|
60
60
|
Brings the task's stack up — the Compose project <project>-<N> by the branch <type>/<N>-slug, <project> without a
|
|
61
|
-
number (in the middle of a rebase — the branch being rebased; a linked worktree without a task branch
|
|
62
|
-
refused: give N) — and prints its addresses: env.http services of .agents/elves.json through the proxy, published ports on
|
|
61
|
+
number (in the middle of a rebase — the branch being rebased; a linked worktree without a task branch — the task of
|
|
62
|
+
ELVES_TASK=<N>, without it refused: give N) — and prints its addresses: env.http services of .agents/elves.json through the proxy, published ports on
|
|
63
63
|
127.0.0.1; the HTTP addresses go to the compose file's interpolation in TASK_ENV_<SERVICE>_URL; --profile — Compose
|
|
64
64
|
profiles. The bring-up takes a place in the machine queue (slot) until the containers are healthy. Code 0 — up, 1 — a
|
|
65
|
-
service failed (its state and log), 2 — not tried
|
|
65
|
+
service failed (its state and log), 2 — not tried; not up — the reason is appended to the file of
|
|
66
|
+
ELVES_TASK_ENV_FAILED, if given (pr premerge of the github skill: «couldn't check», not a red check).
|
|
66
67
|
|
|
67
68
|
Examples:
|
|
68
69
|
task-env up
|
|
@@ -879,7 +880,7 @@ function shown(addresses: Address[], withVar: boolean): string[] {
|
|
|
879
880
|
function stackUp(project: Project, profiles: string[], env: NodeJS.ProcessEnv): number {
|
|
880
881
|
const stack = stackOf(project.name, project.task);
|
|
881
882
|
const r = inSlot(`up ${stack.name}`, () => upStack(project, stack, profiles, env));
|
|
882
|
-
if (r.code) return console.log(r.lines.join("\n")), r.code;
|
|
883
|
+
if (r.code) return console.log(r.lines.join("\n")), stackFailed(env, "up", r.code, r.lines);
|
|
883
884
|
const addresses = addressesOf(project, stack, env);
|
|
884
885
|
console.log([...r.lines, `stack ${stack.name}: up${addresses.length ? "" : " — no HTTP service in env.http and no published port"}`, ...shown(addresses, false)].join("\n"));
|
|
885
886
|
console.log(`logs: docker compose -p ${stack.name} logs <service>; down: bun --no-env-file ${fileURLToPath(import.meta.url)} down${project.task === undefined ? "" : ` ${project.task}`}`);
|
|
@@ -894,9 +895,9 @@ function stackUp(project: Project, profiles: string[], env: NodeJS.ProcessEnv):
|
|
|
894
895
|
function stackE2e(project: Project, profiles: string[], command: string[], env: NodeJS.ProcessEnv): number {
|
|
895
896
|
const stack = stackOf(project.name, project.task, true);
|
|
896
897
|
const clean = downStack(stack.name, env);
|
|
897
|
-
if (!clean.ok) return console.log(clean.line), 2;
|
|
898
|
+
if (!clean.ok) return console.log(clean.line), stackFailed(env, "e2e", 2, [clean.line]);
|
|
898
899
|
const r = inSlot(`e2e ${stack.name}`, () => upStack(project, stack, profiles, env));
|
|
899
|
-
if (r.code) return console.log(r.lines.join("\n")), r.code;
|
|
900
|
+
if (r.code) return console.log(r.lines.join("\n")), stackFailed(env, "e2e", r.code, r.lines);
|
|
900
901
|
const addresses = addressesOf(project, stack, env);
|
|
901
902
|
console.log([...r.lines, `stack ${stack.name}: up, clean volumes — TASK_ENV_PROJECT=${stack.name}`, ...shown(addresses, true)].join("\n"));
|
|
902
903
|
if (!command.length) return 0;
|
|
@@ -1008,6 +1009,28 @@ function profilesOf(args: string[]): { profiles: string[]; rest: string[] } | un
|
|
|
1008
1009
|
return { profiles, rest: args.slice(i + 1) };
|
|
1009
1010
|
}
|
|
1010
1011
|
|
|
1012
|
+
/**
|
|
1013
|
+
* The task of a checkout without a task branch — `ELVES_TASK=<N>`: `pr premerge` of the github skill checks the merge
|
|
1014
|
+
* in a temporary worktree on a detached HEAD and gives the PR's task (#759) — `up`, `e2e` and `down` without a number
|
|
1015
|
+
* take its stack instead of refusing. A task branch comes first; not a positive number — none.
|
|
1016
|
+
*/
|
|
1017
|
+
export const TASK_VAR = "ELVES_TASK";
|
|
1018
|
+
/**
|
|
1019
|
+
* The file a stack command that didn't bring the stack up appends its reason to — `ELVES_TASK_ENV_FAILED=<file>`:
|
|
1020
|
+
* `pr premerge` tells «couldn't check» from a red check by it (#759) — a test that failed on the connection says
|
|
1021
|
+
* nothing about the stack.
|
|
1022
|
+
*/
|
|
1023
|
+
export const FAILED_VAR = "ELVES_TASK_ENV_FAILED";
|
|
1024
|
+
const taskOfEnv = (env: NodeJS.ProcessEnv) => (/^[1-9]\d*$/.test(env[TASK_VAR] ?? "") ? Number(env[TASK_VAR]) : undefined);
|
|
1025
|
+
|
|
1026
|
+
/** A stack that didn't come up — its reason into FAILED_VAR, if given; the code as is. */
|
|
1027
|
+
function stackFailed(env: NodeJS.ProcessEnv, group: string, code: number, lines: string[]): number {
|
|
1028
|
+
const file = env[FAILED_VAR];
|
|
1029
|
+
const why = lines.filter((l) => l.trim()).slice(-3).join(" / ") || `code ${code}`;
|
|
1030
|
+
if (file && code !== 0) appendFileSync(file, `${why.startsWith("task-env ") ? "" : `task-env ${group}: `}${why}\n`);
|
|
1031
|
+
return code;
|
|
1032
|
+
}
|
|
1033
|
+
|
|
1011
1034
|
/** The stack commands: undefined — not one of them or wrong arguments. */
|
|
1012
1035
|
function stackCommand(group: string, args: string[], env: NodeJS.ProcessEnv): number | undefined {
|
|
1013
1036
|
if (group !== "up" && group !== "e2e" && group !== "down" && group !== "prune") return undefined;
|
|
@@ -1016,21 +1039,24 @@ function stackCommand(group: string, args: string[], env: NodeJS.ProcessEnv): nu
|
|
|
1016
1039
|
// the stacks are found by the Compose project: the task's worktree may be gone already
|
|
1017
1040
|
const root = git(process.cwd(), "rev-parse", "--show-toplevel") || process.cwd();
|
|
1018
1041
|
if (group === "prune") return prune(root, env);
|
|
1019
|
-
|
|
1042
|
+
const branch = taskBranch(currentBranch(root))?.issue ?? taskOfEnv(env);
|
|
1043
|
+
if (!args[0] && branch === undefined) {
|
|
1020
1044
|
const refusal = noTaskRefusal(root, "down");
|
|
1021
1045
|
if (refusal) return console.log(refusal), 2;
|
|
1022
1046
|
}
|
|
1023
|
-
return stackDown(root, args[0] ? Number(args[0]) :
|
|
1047
|
+
return stackDown(root, args[0] ? Number(args[0]) : branch, env);
|
|
1024
1048
|
}
|
|
1025
|
-
const
|
|
1026
|
-
const opts = profilesOf(
|
|
1049
|
+
const given = group === "up" && /^\d+$/.test(args[0] ?? "") ? Number(args[0]) : undefined;
|
|
1050
|
+
const opts = profilesOf(given === undefined ? args : args.slice(1));
|
|
1027
1051
|
if (!opts || (group === "up" && opts.rest.length)) return undefined;
|
|
1052
|
+
const root = git(process.cwd(), "rev-parse", "--show-toplevel") || process.cwd();
|
|
1053
|
+
const number = given ?? (taskBranch(currentBranch(root)) ? undefined : taskOfEnv(env));
|
|
1028
1054
|
if (number === undefined) {
|
|
1029
|
-
const refusal = noTaskRefusal(
|
|
1030
|
-
if (refusal) return console.log(refusal), 2;
|
|
1055
|
+
const refusal = noTaskRefusal(root, group);
|
|
1056
|
+
if (refusal) return console.log(refusal), stackFailed(env, group, 2, [refusal]);
|
|
1031
1057
|
}
|
|
1032
1058
|
const project = projectOf(process.cwd(), number);
|
|
1033
|
-
if (typeof project === "string") return console.log(`task-env ${group}: ${project}`), 2;
|
|
1059
|
+
if (typeof project === "string") return console.log(`task-env ${group}: ${project}`), stackFailed(env, group, 2, [project]);
|
|
1034
1060
|
return group === "up" ? stackUp(project, opts.profiles, env) : stackE2e(project, opts.profiles, opts.rest, env);
|
|
1035
1061
|
}
|
|
1036
1062
|
|