yadflow 4.6.0 → 4.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +259 -0
- package/README.md +46 -4
- package/bin/commands.mjs +9 -2
- package/bin/yad.mjs +309 -30
- package/cli/agent-guard.mjs +511 -0
- package/cli/agent-guide.mjs +83 -0
- package/cli/agent-rules.mjs +381 -0
- package/cli/argv-flags.mjs +7 -0
- package/cli/artifact-status.mjs +88 -20
- package/cli/build.mjs +1372 -0
- package/cli/checkpoint.mjs +2 -2
- package/cli/ci-check.mjs +492 -0
- package/cli/commit.mjs +1 -0
- package/cli/dial.mjs +21 -1
- package/cli/docs.mjs +7 -2
- package/cli/doctor.mjs +176 -33
- package/cli/epic-state.mjs +360 -12
- package/cli/errors.mjs +3 -0
- package/cli/find-product.mjs +36 -2
- package/cli/fold.mjs +9 -5
- package/cli/gate-local.mjs +9 -1
- package/cli/gate.mjs +364 -22
- package/cli/guide.mjs +549 -0
- package/cli/history.mjs +22 -2
- package/cli/hook.mjs +35 -4
- package/cli/index-command.mjs +2 -2
- package/cli/ledger.mjs +60 -0
- package/cli/lib.mjs +46 -0
- package/cli/lifecycle/defaults/2.json +124 -0
- package/cli/lifecycle/lifecycle.schema.json +5 -2
- package/cli/lifecycle.mjs +16 -3
- package/cli/manifest.mjs +75 -0
- package/cli/marked-block.mjs +48 -0
- package/cli/members.mjs +19 -5
- package/cli/migrate.mjs +17 -19
- package/cli/next.mjs +35 -12
- package/cli/openpr.mjs +81 -5
- package/cli/plan.mjs +326 -22
- package/cli/platform.mjs +21 -0
- package/cli/pr-list.mjs +5 -3
- package/cli/product-index.mjs +6 -3
- package/cli/product-token.mjs +186 -0
- package/cli/productcommit.mjs +33 -0
- package/cli/protection.mjs +50 -0
- package/cli/recommend.mjs +3 -1
- package/cli/reconcile.mjs +187 -26
- package/cli/repo-publish.mjs +2 -2
- package/cli/report.mjs +62 -14
- package/cli/run-checks.mjs +586 -0
- package/cli/setup.mjs +244 -25
- package/cli/ship-drift.mjs +49 -18
- package/cli/signing.mjs +377 -0
- package/cli/standup.mjs +1 -1
- package/cli/status.mjs +282 -0
- package/cli/test-agents-file.mjs +993 -0
- package/cli/test-build.mjs +1559 -0
- package/cli/test-ci-check.mjs +616 -0
- package/cli/test-guide.mjs +1267 -0
- package/cli/test-node.mjs +129 -0
- package/cli/test-run-checks.mjs +603 -0
- package/cli/test-setup-agent.mjs +352 -0
- package/cli/test-signing.mjs +524 -0
- package/cli/test-worktree.mjs +520 -0
- package/cli/thread.mjs +4 -0
- package/cli/tidy.mjs +2 -2
- package/cli/toolbox.mjs +37 -6
- package/cli/update-commit.mjs +313 -11
- package/cli/workspace.mjs +38 -10
- package/cli/worktree-record.mjs +53 -0
- package/cli/worktree.mjs +379 -0
- package/package.json +6 -4
- package/skills/sdlc/config.yaml +5 -5
- package/skills/sdlc/module-help.csv +2 -1
- package/skills/yad-backfill/templates/checks/backfill-check.sh +9 -9
- package/skills/yad-change/SKILL.md +5 -1
- package/skills/yad-checks/SKILL.md +61 -12
- package/skills/yad-checks/references/check-gates.md +78 -14
- package/skills/yad-checks/templates/checks/build-test-lint.sh +22 -3
- package/skills/yad-checks/templates/checks/commit-message.sh +8 -2
- package/skills/yad-checks/templates/checks/contract-check.sh +61 -33
- package/skills/yad-checks/templates/checks/epic-open.sh +87 -14
- package/skills/yad-checks/templates/checks/ledger-guard.sh +3 -3
- package/skills/yad-checks/templates/checks/lineage-check.sh +88 -15
- package/skills/yad-checks/templates/checks/member-check.mjs +206 -35
- package/skills/yad-checks/templates/checks/package-manager.sh +42 -5
- package/skills/yad-checks/templates/checks/product-checkout.sh +161 -13
- package/skills/yad-checks/templates/checks/reconcile-debt-check.sh +94 -15
- package/skills/yad-checks/templates/checks/risk-map-check.sh +2 -2
- package/skills/yad-checks/templates/checks/spec-link.sh +63 -4
- package/skills/yad-checks/templates/checks/verified-commits.sh +23 -5
- package/skills/yad-checks/templates/github/yad-checks.yml +9 -9
- package/skills/yad-checks/templates/gitlab/.gitlab-ci.yml +4 -1
- package/skills/yad-checks/templates/gitlab/yad-checks.gitlab-ci.yml +5 -5
- package/skills/yad-checks/templates/gitlab/yad-product-checks.gitlab-ci.yml +16 -3
- package/skills/yad-checks/templates/gitlab/yad-update-guard.gitlab-ci.yml +5 -1
- package/skills/yad-checks/templates/gitlab/yad-verified-commits.gitlab-ci.yml +5 -1
- package/skills/yad-checks/templates/hooks/agent-guard.mjs +116 -0
- package/skills/yad-commit/SKILL.md +8 -5
- package/skills/yad-connect-repos/SKILL.md +5 -3
- package/skills/yad-connect-repos/references/code-context.md +2 -1
- package/skills/yad-connect-repos/references/repos-registry.md +2 -1
- package/skills/yad-docs/templates/app/package-lock.json +395 -106
- package/skills/yad-docs/templates/app/package.json +2 -2
- package/skills/yad-docs-overview/references/pipeline-model.md +2 -2
- package/skills/yad-engineer-review/SKILL.md +55 -25
- package/skills/yad-engineer-review/references/ship-and-record.md +49 -12
- package/skills/yad-epic/SKILL.md +2 -1
- package/skills/yad-epic/references/state-schema.md +76 -17
- package/skills/yad-guide/SKILL.md +192 -0
- package/skills/yad-implement/SKILL.md +75 -13
- package/skills/yad-implement/references/implement-conventions.md +8 -1
- package/skills/yad-implement/templates/.gitmessage +3 -0
- package/skills/yad-open-pr/SKILL.md +21 -0
- package/skills/yad-pair-review/SKILL.md +14 -5
- package/skills/yad-pr-template/SKILL.md +6 -2
- package/skills/yad-pr-template/templates/checks/pr-template.sh +85 -4
- package/skills/yad-pr-template/templates/checks/pr-title.sh +1 -1
- package/skills/yad-pr-template/templates/github/pull_request_template.md +1 -1
- package/skills/yad-pr-template/templates/gitlab/merge_request_templates/Default.md +1 -1
- package/skills/yad-product-bridge/SKILL.md +44 -12
- package/skills/yad-product-bridge/references/bridge.md +11 -5
- package/skills/yad-product-bridge/templates/github/yad-gate-sync.yml +2 -2
- package/skills/yad-product-bridge/templates/gitlab/yad-gate-sync.gitlab-ci.yml +9 -4
- package/skills/yad-reconcile/SKILL.md +9 -3
- package/skills/yad-report/SKILL.md +15 -0
- package/skills/yad-review-companion/SKILL.md +5 -3
- package/skills/yad-review-gate/SKILL.md +16 -8
- package/skills/yad-review-gate/references/gating.md +26 -1
- package/skills/yad-run/SKILL.md +61 -33
- package/skills/yad-run/references/run-loop.md +44 -22
- package/skills/yad-spec/SKILL.md +137 -16
- package/skills/yad-spec/references/spec-handoff.md +50 -3
- package/skills/yad-status/SKILL.md +7 -0
- package/skills/yad-stories/references/story-schema.md +1 -1
- package/skills/yad-sync-repos/SKILL.md +2 -1
- package/skills/yad-ui/SKILL.md +2 -2
package/cli/members.mjs
CHANGED
|
@@ -43,7 +43,7 @@ import path from 'node:path';
|
|
|
43
43
|
import { createHash } from 'node:crypto';
|
|
44
44
|
import { spawnSync } from 'node:child_process';
|
|
45
45
|
|
|
46
|
-
import { c, log, ok, info, warn, fail, hand, run, readJSON, forTerminal, isPlainObject, asset } from './lib.mjs';
|
|
46
|
+
import { c, log, ok, info, warn, fail, hand, run, readJSON, forTerminal, isPlainObject, asset, inJSON, refuse as refuseJSON } from './lib.mjs';
|
|
47
47
|
import { productConfigPath, isVerifiedLedger, SCHEMA_VERSION } from './manifest.mjs';
|
|
48
48
|
import { LOGIN_RE, hostFromGitUrl, plainHost } from './platform.mjs';
|
|
49
49
|
import { repoPathFromGitUrl, httpStatus } from './protection.mjs';
|
|
@@ -670,18 +670,31 @@ export async function runMemberAdd(root, { soft = false, noPush = false, runner
|
|
|
670
670
|
return accounts;
|
|
671
671
|
};
|
|
672
672
|
let accounts = discover();
|
|
673
|
+
// E159: under --json (an agent's run) no login is started — the person runs it, and this says how.
|
|
674
|
+
const startLogin = interactive(env) && !noLogin && !inJSON();
|
|
675
|
+
const loginStep = (cmd) => ({
|
|
676
|
+
act: 'login',
|
|
677
|
+
why: `a member file needs an account the platform can prove, and logging in to ${identity.platform === 'github' ? 'GitHub' : 'GitLab'} is the person's (a secret)`,
|
|
678
|
+
commands: [cmd],
|
|
679
|
+
verify: 'yad member add --json',
|
|
680
|
+
});
|
|
681
|
+
const noLoginYet = (msg, cmd) => {
|
|
682
|
+
if (!inJSON()) return refuse(msg, `run \`${cmd}\`, then \`yad member add\``);
|
|
683
|
+
if (soft) { warn(msg); hand(`run \`${cmd}\`, then \`yad member add\``); return { written: false, person: loginStep(cmd) }; }
|
|
684
|
+
return refuseJSON(msg, `the person runs \`${cmd}\` (\`!\` in front in Claude Code), then \`yad member add\``, { person: loginStep(cmd) });
|
|
685
|
+
};
|
|
673
686
|
const onProduct = () => accounts.some((a) => a.platform === identity.platform && a.host === identity.host && (a.platform === 'gitlab' || validLogin(a.login)));
|
|
674
687
|
if (identity.platform === 'github' && !onProduct()) {
|
|
675
|
-
if (
|
|
688
|
+
if (startLogin) {
|
|
676
689
|
info(`not logged in to GitHub on ${identity.host} — starting \`gh auth login\``);
|
|
677
690
|
spawnSync('gh', ['auth', 'login', '--hostname', identity.host, '--scopes', 'user:email'], { stdio: 'inherit' });
|
|
678
691
|
accounts = discover();
|
|
679
692
|
}
|
|
680
|
-
if (!onProduct()) return
|
|
693
|
+
if (!onProduct()) return noLoginYet(`not logged in to GitHub on ${identity.host}`, `gh auth login --hostname ${identity.host} --scopes user:email`);
|
|
681
694
|
}
|
|
682
695
|
let proofs = accounts.map((a) => accountProof(a, { runner, env }));
|
|
683
696
|
if (identity.platform === 'gitlab' && !proofs.some((p) => p.account.platform === 'gitlab' && p.account.host === identity.host && validLogin(p.account.login))) {
|
|
684
|
-
if (
|
|
697
|
+
if (startLogin) {
|
|
685
698
|
info(`not logged in to GitLab on ${identity.host} — starting \`glab auth login\``);
|
|
686
699
|
spawnSync('glab', ['auth', 'login', '--hostname', identity.host], { stdio: 'inherit' });
|
|
687
700
|
proofs = discover().map((a) => accountProof(a, { runner, env }));
|
|
@@ -706,7 +719,8 @@ export async function runMemberAdd(root, { soft = false, noPush = false, runner
|
|
|
706
719
|
const existingAll = membersAt(root, baseRef, identity);
|
|
707
720
|
const mine = existingAll.members.find((m) => proofs.some((p) => p.account.platform === identity.platform && p.account.host === identity.host && p.account.login.toLowerCase() === m.primary.login.toLowerCase()));
|
|
708
721
|
const built = buildRecord({ identity, proofs, git, today, existing: mine || null, proved: now.replace(/\.\d+Z$/, 'Z') });
|
|
709
|
-
if (built.problem) return
|
|
722
|
+
if (built.problem && built.login) return noLoginYet(built.problem, `${cli} auth login --hostname ${identity.host}`);
|
|
723
|
+
if (built.problem) return refuse(built.problem, built.hint || null);
|
|
710
724
|
const { record, primary, plainByHash } = built;
|
|
711
725
|
if (!Number.isSafeInteger(primary.id)) return refuse(`the platform did not give the numeric id of ${accountLabel(primary)} — the member-check gate needs it`, 'run `yad member add` again; if it keeps failing, report it with `yad report`');
|
|
712
726
|
// A login renamed away and registered again by someone else is another account: the old file is not theirs.
|
package/cli/migrate.mjs
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
import fs from 'node:fs';
|
|
18
18
|
import path from 'node:path';
|
|
19
19
|
|
|
20
|
-
import { ask, c, exists, fail, hand, info, isPlainObject, log, ok, readJSON, warn, writeFileAtomic, writeJSON, writeProductConfig, emitJSON, collectWarning } from './lib.mjs';
|
|
20
|
+
import { ask, c, exists, fail, hand, info, isPlainObject, log, ok, readJSON, warn, writeFileAtomic, writeJSON, writeProductConfig, emitJSON, collectWarning, cpMerge, rmTree } from './lib.mjs';
|
|
21
21
|
import { err } from './errors.mjs';
|
|
22
22
|
import {
|
|
23
23
|
ADVANCE_FROM_AUTOMATION, BACKUP_SUFFIX, DRIVER_FROM_ASSISTANCE, epicFiles, isVerifiedLedger,
|
|
@@ -468,23 +468,18 @@ export function planProductMove(root, { verified = false, ci = false, migrations
|
|
|
468
468
|
// `copy` is a seam for the tests, which need a copy that fails or corrupts on demand.
|
|
469
469
|
// `backup: false` is for the gate bot. In CI the old folder is in git history, a `.yad-orig` copy would be
|
|
470
470
|
// an untracked directory on a throwaway runner, and `yad migrate` is not there to add it to .gitignore.
|
|
471
|
-
export function applyProductMove(root, move, { migrations = MIGRATIONS, copy =
|
|
471
|
+
export function applyProductMove(root, move, { migrations = MIGRATIONS, copy = cpMerge, backup: keepBackup = true } = {}) {
|
|
472
472
|
const from = path.join(root, move.from);
|
|
473
473
|
const to = path.join(root, move.to);
|
|
474
474
|
const backup = path.join(root, move.backup);
|
|
475
|
-
// The folders under `foundation/` the copy will create, deepest first — computed BEFORE copying.
|
|
476
|
-
const made = new Set();
|
|
477
|
-
for (const m of move.moves) {
|
|
478
|
-
for (let d = path.posix.dirname(m.to); d !== move.to && d !== '.'; d = path.posix.dirname(d)) {
|
|
479
|
-
if (!exists(path.join(root, d))) made.add(d);
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
475
|
const toExisted = exists(to);
|
|
476
|
+
const created = []; // every path the copy into `to` made: a failure removes these, and only these
|
|
483
477
|
try {
|
|
484
478
|
const before = artifactHash(from, 'discovery/');
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
copy(from,
|
|
479
|
+
// Folders are joined and a file that is already there is refused (cpMerge: Node 24's cpSync refuses
|
|
480
|
+
// a folder that exists, even with the user's own files in it).
|
|
481
|
+
if (keepBackup) copy(from, backup);
|
|
482
|
+
copy(from, to, created);
|
|
488
483
|
if (artifactHash(to, 'discovery/') !== before) {
|
|
489
484
|
throw new Error(`the copy in ${move.to}/ does not fingerprint like the original`);
|
|
490
485
|
}
|
|
@@ -505,17 +500,20 @@ export function applyProductMove(root, move, { migrations = MIGRATIONS, copy = f
|
|
|
505
500
|
writeJSON(file, stamped(obj, version));
|
|
506
501
|
}
|
|
507
502
|
} catch (e) {
|
|
503
|
+
// rmTree: a folder this copy made may carry a read-only mode copied from the source.
|
|
508
504
|
if (!toExisted) {
|
|
509
|
-
|
|
505
|
+
rmTree(to);
|
|
510
506
|
} else {
|
|
511
|
-
|
|
512
|
-
|
|
507
|
+
// Only what this copy made: a file that came into foundation/ after the plan is the user's, and stays.
|
|
508
|
+
// Its folders are opened first: a file inside a read-only folder it made goes before that folder does.
|
|
509
|
+
for (const p of created) { try { if (fs.lstatSync(p).isDirectory()) fs.chmodSync(p, 0o700); } catch { /* gone */ } }
|
|
510
|
+
for (const p of [...created].reverse()) rmTree(p);
|
|
513
511
|
}
|
|
514
512
|
// Only a backup THIS run made. Without one, the path may still hold an earlier run's copy — the user's.
|
|
515
|
-
if (keepBackup)
|
|
513
|
+
if (keepBackup) rmTree(backup);
|
|
516
514
|
throw new Error(`nothing was moved — ${e.message}`, { cause: e });
|
|
517
515
|
}
|
|
518
|
-
|
|
516
|
+
rmTree(from);
|
|
519
517
|
return productMoveFiles(move);
|
|
520
518
|
}
|
|
521
519
|
|
|
@@ -1010,7 +1008,7 @@ function printNotRenamedHere(root) {
|
|
|
1010
1008
|
// which means no backup, no row in the report, and a preview that under-reports what an apply does. It
|
|
1011
1009
|
// would also be free to overwrite the one file the same run had just declared corrupt or newer than
|
|
1012
1010
|
// this engine. What shape a file is in is recorded in that file, which is the whole point of rule 1.
|
|
1013
|
-
export async function runMigrate(root, { apply = false, json = false, keep = null } = {}, { migrations = MIGRATIONS, copy =
|
|
1011
|
+
export async function runMigrate(root, { apply = false, json = false, keep = null } = {}, { migrations = MIGRATIONS, copy = cpMerge, choose = null } = {}) {
|
|
1014
1012
|
if (keep != null && !KEEP_CHOICES.includes(keep)) {
|
|
1015
1013
|
throw err('YAD-STATE-008', `--keep takes product or hub, not "${keep}"`, '`--keep product` keeps .sdlc/product.json (and each product-prs.json); `--keep hub` keeps the old names');
|
|
1016
1014
|
}
|
|
@@ -1042,7 +1040,7 @@ export async function runMigrate(root, { apply = false, json = false, keep = nul
|
|
|
1042
1040
|
// way to commit it is named: a drift there came from a hand edit that got past the guard already.
|
|
1043
1041
|
const ciOwnedSettled = plan.verified ? settledFiles.filter((f) => !f.startsWith('.sdlc/')) : [];
|
|
1044
1042
|
if (ciOwnedSettled.length) {
|
|
1045
|
-
warn(`${ciOwnedSettled.join(', ')} ${ciOwnedSettled.length === 1 ? 'is' : 'are'} CI-owned on this verified Product: the ledger-guard check refuses a hand commit of ${ciOwnedSettled.length === 1 ? 'it' : 'them'} —
|
|
1043
|
+
warn(`${ciOwnedSettled.join(', ')} ${ciOwnedSettled.length === 1 ? 'is' : 'are'} CI-owned on this verified Product: the ledger-guard check refuses a hand commit of ${ciOwnedSettled.length === 1 ? 'it' : 'them'} — the person commits the repair with \`yad commit --manual --reason "<why>" --type chore -m "<subject>"\` (an AI agent hands it to them, \`!\` in front in Claude Code), which records the reason the check quotes`);
|
|
1046
1044
|
}
|
|
1047
1045
|
const move = plan.product?.action === 'move' ? plan.product : null;
|
|
1048
1046
|
const pending = plan.rows.filter((r) => r.changes);
|
package/cli/next.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// `yad next` — the unified next-step driver. Read-only: it never writes state or acts. It reads the
|
|
2
2
|
// file ledger and prints the ONE concrete, copy-pasteable next action (and a one-line why), so a user
|
|
3
|
-
// never has to remember which of the
|
|
3
|
+
// never has to remember which of the 39 skills / gate commands comes next. "Guide, don't act" — the
|
|
4
4
|
// Shape still never auto-advances. Once an epic is `ready-for-build`, it reads each story's
|
|
5
5
|
// build-state and prints the next BUILD sub-step per repo (spec → tasks → implement → checks → engineer-review)
|
|
6
6
|
// plus the remaining chain — so Build is guided too, not just hinted at.
|
|
@@ -11,15 +11,16 @@
|
|
|
11
11
|
// yad next --all every active epic's next action at once
|
|
12
12
|
// yad next [<epic>] --json the same answer as an action object, for an agent or CI
|
|
13
13
|
import path from 'node:path';
|
|
14
|
-
import { c, log, ok, info, warn, hand, fail, readJSON, exists, emitJSON } from './lib.mjs';
|
|
14
|
+
import { c, log, ok, info, warn, hand, fail, readJSON, exists, emitJSON, forTerminal } from './lib.mjs';
|
|
15
15
|
import { PROJECT_FILES, isVerifiedLedger, productConfigPath, stepAdvance } from './manifest.mjs';
|
|
16
16
|
import { printTeamHint, soloTeamHint } from './people.mjs';
|
|
17
|
+
import { productGit, resolveDefaultBranch } from './productcommit.mjs';
|
|
17
18
|
import { OWNER_STEPS, liveOwner, readState as loadLedgerState } from './owners.mjs';
|
|
18
|
-
import { bindingsForEpic, bindingsForProfile, dedupeConsecutive, epicIds, isGateStep, killSwitchOn, loadAutomation, epicRel, epicRoot, loadLedger, loadSkillBindings, stepSkills, nextAction, preconditionsMet, isValidEpicId, epicLineage, typeNoun, phaseOf, stepPhase, profileSteps, lifecycleProfile, PHASES, PRODUCT_DONE, PRODUCT_EPICS, STEPS } from './epic-state.mjs';
|
|
19
|
+
import { bindingsForEpic, doneStepUnapproved, reviewAsItStands, bindingsForProfile, dedupeConsecutive, epicIds, isGateStep, killSwitchOn, loadAutomation, epicRel, epicRoot, loadLedger, loadSkillBindings, stepSkills, nextAction, preconditionsMet, isValidEpicId, epicLineage, typeNoun, phaseOf, stepPhase, profileSteps, lifecycleProfile, PHASES, PRODUCT_DONE, PRODUCT_EPICS, STEPS } from './epic-state.mjs';
|
|
19
20
|
|
|
20
21
|
// Is solo mode on? Persisted in hub.json by setup (Phase C/D); default false. Read defensively so a
|
|
21
22
|
// missing/old hub.json never breaks the driver.
|
|
22
|
-
const soloOf = (productConfig) => !!(productConfig && (productConfig.solo === true || productConfig.review_gate?.solo === true));
|
|
23
|
+
export const soloOf = (productConfig) => !!(productConfig && (productConfig.solo === true || productConfig.review_gate?.solo === true));
|
|
23
24
|
function isSolo(root) {
|
|
24
25
|
return soloOf(readJSON(productConfigPath(root), null));
|
|
25
26
|
}
|
|
@@ -27,7 +28,7 @@ function isSolo(root) {
|
|
|
27
28
|
const isSetUp = (root) => exists(path.join(root, PROJECT_FILES.version)) || exists(productConfigPath(root));
|
|
28
29
|
|
|
29
30
|
// Every epic that has a state ledger, the Foundation included, in id order.
|
|
30
|
-
function listEpics(root) {
|
|
31
|
+
export function listEpics(root) {
|
|
31
32
|
return epicIds(root).filter((id) => exists(path.join(epicRoot(root, id), '.sdlc', 'state.json')));
|
|
32
33
|
}
|
|
33
34
|
|
|
@@ -51,7 +52,7 @@ function listEpics(root) {
|
|
|
51
52
|
// the printed line. `nextAction` would narrow them itself, but `actionLine` names skills the action
|
|
52
53
|
// never carried (the Build fallback, the hand-off to the next epic) — a view built in two places is two
|
|
53
54
|
// answers for one step.
|
|
54
|
-
function epicAction(root, id, lin = epicLineage(root, id), bindings = loadSkillBindings(root)) {
|
|
55
|
+
export function epicAction(root, id, lin = epicLineage(root, id), bindings = loadSkillBindings(root)) {
|
|
55
56
|
const ledger = loadLedger(epicRoot(root, id));
|
|
56
57
|
const view = bindingsForEpic(bindings, ledger?.state);
|
|
57
58
|
const action = {
|
|
@@ -82,7 +83,22 @@ const actionFor = (root, id, lin, bindings) => epicAction(root, id, lin, binding
|
|
|
82
83
|
const rowFor = (root, id, bindings = loadSkillBindings(root)) => {
|
|
83
84
|
const lin = epicLineage(root, id);
|
|
84
85
|
const { action, view } = epicAction(root, id, lin, bindings);
|
|
85
|
-
return { action, theme: lin.theme, owners: liveOwners(root, id), bindings: view };
|
|
86
|
+
return { action, theme: lin.theme, owners: liveOwners(root, id), changed: changedSinceApproved(root, id), bindings: view };
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
// The done reviews whose artifact changed after they were approved (#418). Beside the action, like the
|
|
90
|
+
// owners below: the action's `--json` keys are frozen. Said on every run until a fresh review passes.
|
|
91
|
+
const changedSinceApproved = (root, id) => {
|
|
92
|
+
let ledger;
|
|
93
|
+
try { ledger = loadLedger(epicRoot(root, id)); } catch { return []; }
|
|
94
|
+
const productConfig = readJSON(productConfigPath(root), null);
|
|
95
|
+
// Not in solo mode, where no approval is counted and the gate says nothing either.
|
|
96
|
+
if (soloOf(productConfig)) return [];
|
|
97
|
+
const steps = Array.isArray(ledger?.state?.steps) ? ledger.state.steps : [];
|
|
98
|
+
const found = steps.filter((s) => doneStepUnapproved(epicRoot(root, id), s, ledger.approvals));
|
|
99
|
+
if (!found.length) return [];
|
|
100
|
+
const trunk = resolveDefaultBranch(productGit(root), productConfig);
|
|
101
|
+
return found.map((s) => ({ step: s.id, artifact: s.artifact, fix: reviewAsItStands(id, s.artifact, trunk) }));
|
|
86
102
|
};
|
|
87
103
|
|
|
88
104
|
// The live step owners of one epic (E47), by step. Beside the action, never in it: `yad next --json`'s
|
|
@@ -138,7 +154,7 @@ const skillList = (a) => a?.skills || (a?.skill ? [a.skill] : []);
|
|
|
138
154
|
// "the yad-architecture skill", or for a bound chain "the shape-it skill, then yad-stories". Closed
|
|
139
155
|
// decision 7: several skills on one step are a CHAIN, not a panel — they run in the order given, each
|
|
140
156
|
// seeing what the one before it produced, and the last output is the artifact.
|
|
141
|
-
function skillPhrase(a, fallback = null) {
|
|
157
|
+
export function skillPhrase(a, fallback = null) {
|
|
142
158
|
const ids = skillList(a);
|
|
143
159
|
if (!ids.length) return `the ${c.bold(fallback || '(no skill)')} skill`;
|
|
144
160
|
const [first, ...rest] = ids;
|
|
@@ -185,7 +201,7 @@ function printBuildLanes(builds, automation = null) {
|
|
|
185
201
|
// fallback printed when no story has a build-state yet. Both are the engine naming a step's skill in
|
|
186
202
|
// prose, so both must name the project's choice — otherwise `yad next` and `yad skill list` disagree
|
|
187
203
|
// about the same project.
|
|
188
|
-
function actionLine(a, { solo, bindings = null, verified = false } = {}) {
|
|
204
|
+
export function actionLine(a, { solo, bindings = null, verified = false } = {}) {
|
|
189
205
|
const runs = (stepId, fallback) => stepSkills(stepId, bindings)[0] || fallback;
|
|
190
206
|
switch (a.kind) {
|
|
191
207
|
case 'new':
|
|
@@ -244,7 +260,7 @@ function actionLine(a, { solo, bindings = null, verified = false } = {}) {
|
|
|
244
260
|
// `printAction` renders `a` and `--json` emits the SAME `a` verbatim, and that JSON is deep-equalled
|
|
245
261
|
// by the golden test, which an added key breaks (see actionFor). It comes from `rowFor`, off the same
|
|
246
262
|
// `epic.md` read the action's own `lineageKind` came from.
|
|
247
|
-
function printAction(a, { solo, theme: tag = null, bindings = null, automation = null, verified = false, owners = null } = {}) {
|
|
263
|
+
function printAction(a, { solo, theme: tag = null, bindings = null, automation = null, verified = false, owners = null, changed = [] } = {}) {
|
|
248
264
|
// Prefix the id with the type noun (Defect / Change request / Hotfix / Chore / Epic) so a glance
|
|
249
265
|
// says what kind of work this is. The product level is not a feature — leave it un-prefixed.
|
|
250
266
|
const noun = a.lineageKind && !PRODUCT_EPICS.includes(a.epicId) ? `${typeNoun(a.lineageKind)} ` : '';
|
|
@@ -291,6 +307,12 @@ function printAction(a, { solo, theme: tag = null, bindings = null, automation =
|
|
|
291
307
|
// DEBT is reminded on every run until it is paid (E41). The line says what is owed and the one command
|
|
292
308
|
// that starts paying it — or, once that has started, what finishes it.
|
|
293
309
|
for (const d of a.debt || []) warn(debtLine(a.epicId, d, verified));
|
|
310
|
+
for (const x of changed) { warn(forTerminal(`${x.step} is done, but ${x.artifact} changed after it was approved`)); hand(forTerminal(x.fix)); }
|
|
311
|
+
// Why the chain walked back, when it did (#322). Read from a file a person can edit: plain text only.
|
|
312
|
+
if (a.lastReopen) {
|
|
313
|
+
const r = a.lastReopen;
|
|
314
|
+
info(c.dim(forTerminal(`reopened ${r.step ?? '?'}${r.date ? ` on ${r.date}` : ''}${r.by ? ` by ${r.by}` : ''}${r.reason ? ` — ${r.reason}` : ''} (\`yad gate reopen\`); every gate from it is required again`)));
|
|
315
|
+
}
|
|
294
316
|
phaseLine(a);
|
|
295
317
|
}
|
|
296
318
|
|
|
@@ -424,11 +446,12 @@ function generalNext(root, { all, headCount = null } = {}) {
|
|
|
424
446
|
// The grouping theme rides this list too. This is the ONE `yad next` view that shows several epics
|
|
425
447
|
// side by side, so it is where seeing which of them belong together is worth most — and leaving it
|
|
426
448
|
// off would have meant bare `yad next`, the command people run by default, never showed the tag.
|
|
427
|
-
for (const { action: a, theme: tag, bindings: view } of rows) {
|
|
449
|
+
for (const { action: a, theme: tag, bindings: view, changed } of rows) {
|
|
428
450
|
const theme = tag ? ` ${c.dim(`#${tag}`)}` : '';
|
|
429
451
|
// Debt is reminded here too (E41): the roll-up is the view people run most, and a reminder that only
|
|
430
452
|
// appears once you already look at the one epic is not a reminder.
|
|
431
|
-
const owed = a.debt?.length ? ` ${c.yellow(`· ${a.debt.length} owed as debt`)}` : ''
|
|
453
|
+
const owed = (a.debt?.length ? ` ${c.yellow(`· ${a.debt.length} owed as debt`)}` : '')
|
|
454
|
+
+ (changed?.length ? ` ${c.yellow(`· ${changed.length} changed since approved`)}` : '');
|
|
432
455
|
log(` ${c.cyan(`${typeNoun(a.lineageKind)} ${a.epicId}`)}${theme} ${actionLine(a, { solo, bindings: view, verified })}${owed}`);
|
|
433
456
|
}
|
|
434
457
|
// Painted per segment, not dim-wrapping a bold: `paint` closes with a full reset, so the nested
|
package/cli/openpr.mjs
CHANGED
|
@@ -7,7 +7,7 @@ import fs from 'node:fs';
|
|
|
7
7
|
import { c, log, ok, info, warn, hand, fail, run, exists, readJSON } from './lib.mjs';
|
|
8
8
|
import { PROJECT_FILES , productConfigPath, settingsEditHint } from './manifest.mjs';
|
|
9
9
|
import {
|
|
10
|
-
detectPlatform, createPr, platformLogin, resolveBaseBranch,
|
|
10
|
+
detectPlatform, createPr, platformLogin, resolveBaseBranch, prNumberFromUrl,
|
|
11
11
|
} from './platform.mjs';
|
|
12
12
|
import { taskFromBranch } from './commit.mjs';
|
|
13
13
|
import { parseReviewBranch, artifactFromBase, gateCapFor, capLimit, peopleWord, gateRuleSum, gateRuleEnforced, legacyLogins } from './epic-state.mjs';
|
|
@@ -18,6 +18,10 @@ import { personLabel } from './riskmap.mjs';
|
|
|
18
18
|
import { gateOpen } from './gate.mjs';
|
|
19
19
|
import { unfoldedPaths, authorStepOf } from './fold.mjs';
|
|
20
20
|
import { registryEntryFor } from './find-product.mjs';
|
|
21
|
+
import { autoOpenCheck, recordAutoOpen, branchTasks, rangeTasks, groupWarnings } from './build.mjs';
|
|
22
|
+
import { productDriftError } from './epic-state.mjs';
|
|
23
|
+
import { err } from './errors.mjs';
|
|
24
|
+
import { recordActor } from './skip.mjs';
|
|
21
25
|
|
|
22
26
|
// Resolve the target code repo: --repo <name> from the registry, else --dir, else cwd. `product` (E80) is
|
|
23
27
|
// the Product found from a code repo beside it: the registry is read there, and a repo run without
|
|
@@ -91,7 +95,8 @@ export function templateBody(repoRoot, platform, { task, summary, risk, contract
|
|
|
91
95
|
}
|
|
92
96
|
// The Spec line's placeholder is the STORY dir `specs/EP-<slug>-S0N/` (no `-T0N`), so the task
|
|
93
97
|
// regex below never touches it — derive the story from the task (task minus its `-T0N` suffix).
|
|
94
|
-
|
|
98
|
+
// A grouped PR's `task` lists its tasks (one story): the story is the first one's.
|
|
99
|
+
const story = task ? task.split('`')[0].replace(/-T\d+$/i, '') : null;
|
|
95
100
|
// Fill the obvious fields; leave the rest of the committed template intact for the author.
|
|
96
101
|
// Function replacers (not string replacements) so a `$` in interpolated free text — a commit-derived
|
|
97
102
|
// summary or a repo name — is inserted verbatim, never read as a `$1`/`$&` replacement token.
|
|
@@ -239,6 +244,8 @@ export function suggestReviewers(repoRoot, baseBranch, platform, { remote } = {}
|
|
|
239
244
|
|
|
240
245
|
export async function runOpenPr(root, opts = {}) {
|
|
241
246
|
log(c.bold('\nyad open-pr'));
|
|
247
|
+
const via = opts.via == null ? 'human' : opts.via;
|
|
248
|
+
if (!['auto', 'human'].includes(via)) throw err('YAD-STATE-009', `--via must be auto or human (got '${via}')`, '--via auto opens it on the standing approval (`yad dial open-pr`)');
|
|
242
249
|
const { repoRoot, meta } = resolveRepo(root, opts);
|
|
243
250
|
if (!exists(path.join(repoRoot, '.git'))) { fail(`not a git repo: ${repoRoot}`); process.exitCode = 1; return; }
|
|
244
251
|
|
|
@@ -248,6 +255,8 @@ export async function runOpenPr(root, opts = {}) {
|
|
|
248
255
|
|
|
249
256
|
const branch = run('git', ['rev-parse', '--abbrev-ref', 'HEAD'], { cwd: repoRoot }).stdout;
|
|
250
257
|
const stage = detectStage(root, repoRoot, branch, meta);
|
|
258
|
+
// Before the Product review hand-off below, which pushes: --via auto never pushes what it refuses.
|
|
259
|
+
if (via === 'auto' && stage !== 'code-repo') throw err('YAD-STATE-009', 'only a task PR/MR in a code repo is opened with --via auto', 'a Product review or tooling PR is opened by a person');
|
|
251
260
|
|
|
252
261
|
// product-shape: this is a Shape artifact-review PR (review/EP-*/<artifact> head on the Product). The
|
|
253
262
|
// artifact-review title, body, and ledger bookkeeping all live in `yad gate open` — delegate to it
|
|
@@ -275,6 +284,32 @@ export async function runOpenPr(root, opts = {}) {
|
|
|
275
284
|
return res;
|
|
276
285
|
}
|
|
277
286
|
|
|
287
|
+
// `--via auto` (#356): opened on the project's standing approval, without asking. Everything it needs is
|
|
288
|
+
// checked HERE, before the push, so a refusal leaves no pushed branch behind.
|
|
289
|
+
let auto = null;
|
|
290
|
+
if (via === 'auto') {
|
|
291
|
+
const productRoot = opts.product || (exists(productConfigPath(root)) ? root : null);
|
|
292
|
+
if (!productRoot) throw err('YAD-STATE-009', 'no Product found, so the open-pr dial and the lane cannot be read', 'run it from a repo inside the workspace, or pass --product <folder>');
|
|
293
|
+
if (!meta?.name) throw err('YAD-STATE-009', `${repoRoot} is not a repo the Product registers, so it has no lane`, 'register it with `yad repo add`, or ask a person to open the PR/MR');
|
|
294
|
+
const drift = productDriftError(productRoot);
|
|
295
|
+
if (drift) throw drift;
|
|
296
|
+
// The task the branch carries: of every reading of its name, the ones that are stories of this Product
|
|
297
|
+
// (`branchTasks`). Exactly one: the branch is what is pushed, so a branch carrying two tasks, or none, is
|
|
298
|
+
// refused, and a --task only confirms the one it carries — it never names a task the branch does not.
|
|
299
|
+
const carried = branchTasks(productRoot, branch);
|
|
300
|
+
if (carried.length > 1) throw err('YAD-STATE-009', `${branch} carries more than one task: ${carried.map((x) => `${x.story}-${x.task}`).join(', ')}`, 'open it from a branch that carries one task; a person opens this one');
|
|
301
|
+
const m = opts.task ? String(opts.task).toLowerCase().match(/^ep-([a-z0-9-]+)-s(\d+)-t(\d+)$/) : null;
|
|
302
|
+
if (opts.task && !m) throw err('YAD-STATE-009', `--task must be a task id such as EP-<slug>-S01-T01 (got '${opts.task}')`, '--task EP-<slug>-S<n>-T<n>');
|
|
303
|
+
if (!carried.length) throw err('YAD-STATE-009', `${branch} carries no task of this Product (expected …EP-<slug>-S<n>-T<n>…, a story that exists)`, 'open it from the task\'s branch; a person opens any other PR/MR');
|
|
304
|
+
const pick = carried[0];
|
|
305
|
+
if (m && `EP-${m[1]}-S${m[2]}-T${m[3]}` !== `${pick.story}-${pick.task}`) {
|
|
306
|
+
throw err('YAD-STATE-009', `--task ${opts.task} is not the task ${branch} carries (${pick.story}-${pick.task})`, 'drop --task, or switch to that task\'s branch');
|
|
307
|
+
}
|
|
308
|
+
const { story, task: taskId } = pick;
|
|
309
|
+
// Checked once the base is known, still before the push: a grouped PR's tasks are read from its commits.
|
|
310
|
+
auto = { productRoot, story, task: taskId, repo: meta.name };
|
|
311
|
+
}
|
|
312
|
+
|
|
278
313
|
// The Product's default_branch, which only applies when the PR targets the Product ITSELF
|
|
279
314
|
// (a product-tooling branch) — for a connected code repo the Product's trunk belongs to a different repo and
|
|
280
315
|
// must never leak in. Resolved AFTER the product-shape hand-off above, which delegates its own base to
|
|
@@ -303,13 +338,45 @@ export async function runOpenPr(root, opts = {}) {
|
|
|
303
338
|
}
|
|
304
339
|
}
|
|
305
340
|
|
|
341
|
+
// The tasks this PR carries (#350): the `Task:` lines of its commits, as spec-link reads them. More than one
|
|
342
|
+
// makes it a grouped PR — several small tasks of one story — which its body lists, and whose size is warned
|
|
343
|
+
// about over the Product's `group_limit`.
|
|
344
|
+
const baseRef = `origin/${baseBranch}`;
|
|
345
|
+
// Fetched first: a stale origin/<base> would count tasks merged since then as this PR's.
|
|
346
|
+
const fetched = run('git', ['fetch', '--quiet', 'origin', `+refs/heads/${baseBranch}:refs/remotes/${baseRef}`], { cwd: repoRoot }).ok;
|
|
347
|
+
if (!fetched && auto) throw err('YAD-STATE-009', `could not fetch ${baseBranch} from origin, so the tasks ${branch} carries are not known`, 'check the network and your login, then run this again');
|
|
348
|
+
if (!fetched) warn(`could not fetch ${baseBranch} from origin — the tasks this PR carries are read against the last fetched ${baseRef}`);
|
|
349
|
+
const haveBase = run('git', ['rev-parse', '--verify', '--quiet', `${baseRef}^{commit}`], { cwd: repoRoot }).ok;
|
|
350
|
+
const commitIds = haveBase ? rangeTasks(repoRoot, `${baseRef}..HEAD`) : null;
|
|
351
|
+
let groupIds = null;
|
|
352
|
+
if (auto) {
|
|
353
|
+
// Every task the PR carries must be the branch's story, and each one's checks must have passed.
|
|
354
|
+
if (!commitIds) throw err('YAD-STATE-009', `could not read the commits of ${branch} against ${baseRef}, so the tasks it carries are not known`, `fetch it (git fetch origin ${baseBranch}), then run this again`);
|
|
355
|
+
const own = `${auto.story}-${auto.task}`;
|
|
356
|
+
const ids = [...new Set([own, ...commitIds])];
|
|
357
|
+
const strangers = ids.filter((t) => t.replace(/-T\d+$/, '') !== auto.story);
|
|
358
|
+
if (strangers.length) throw err('YAD-STATE-009', `${branch} carries tasks of another story: ${strangers.join(', ')}`, 'a grouped PR/MR holds small tasks of ONE story; a person opens this one');
|
|
359
|
+
const tasks = ids.map((t) => t.slice(auto.story.length + 1));
|
|
360
|
+
Object.assign(auto, { tasks, ...autoOpenCheck(auto.productRoot, { story: auto.story, tasks, repo: auto.repo }) });
|
|
361
|
+
if (ids.length > 1) groupIds = ids;
|
|
362
|
+
info(`opened on the standing approval: the checks of ${ids.join(', ')} passed, and the open-pr dial is auto`);
|
|
363
|
+
} else if (commitIds && commitIds.length > 1) groupIds = commitIds;
|
|
364
|
+
if (groupIds) {
|
|
365
|
+
info(`a grouped PR/MR: ${groupIds.join(', ')}`);
|
|
366
|
+
const settings = readJSON(productConfigPath(opts.product || root), {}) || {};
|
|
367
|
+
for (const line of groupWarnings(repoRoot, baseRef, groupIds, settings)) warn(line);
|
|
368
|
+
}
|
|
369
|
+
|
|
306
370
|
// Push the branch (sets upstream) using the user's own auth. Abort on failure — creating a PR for a
|
|
307
371
|
// branch that is not on the remote just fails with a more confusing error.
|
|
308
372
|
info(`pushing ${branch} …`);
|
|
309
373
|
const push = run('git', ['push', '-u', 'origin', branch], { cwd: repoRoot });
|
|
310
374
|
if (!push.ok) { fail(`git push failed — ${push.stderr.split('\n')[0] || 'unknown'}`); process.exitCode = 1; return; }
|
|
311
375
|
|
|
312
|
-
|
|
376
|
+
// Under --via auto, the task it was checked for, written the canonical way; a grouped PR's body lists
|
|
377
|
+
// every task it carries.
|
|
378
|
+
const task = auto ? `${auto.story}-${auto.task}` : opts.task || taskFromBranch(branch);
|
|
379
|
+
const bodyTask = groupIds ? groupIds.join('`, `') : task;
|
|
313
380
|
const subject = run('git', ['log', '-1', '--format=%s'], { cwd: repoRoot }).stdout;
|
|
314
381
|
const title = opts.title || subject || `task ${task || branch}`;
|
|
315
382
|
// Summary = commit subject (Conventional-Commits "type:" prefix stripped) + body paragraphs,
|
|
@@ -323,7 +390,7 @@ export async function runOpenPr(root, opts = {}) {
|
|
|
323
390
|
.trim();
|
|
324
391
|
const summary = [subjectText, bodyText].filter(Boolean).join('\n\n') || undefined;
|
|
325
392
|
const body = templateBody(repoRoot, platform, {
|
|
326
|
-
task, summary, risk: opts.risk || 'low', contract: !!opts.contractChange, domains: meta?.name, stage,
|
|
393
|
+
task: bodyTask, summary, risk: opts.risk || 'low', contract: !!opts.contractChange, domains: meta?.name, stage,
|
|
327
394
|
});
|
|
328
395
|
|
|
329
396
|
// Assignee = the committer: `@me` on GitHub (buildPrArgs sends it when no assignee is named, and `gh`
|
|
@@ -338,6 +405,15 @@ export async function runOpenPr(root, opts = {}) {
|
|
|
338
405
|
const r = creator(platform, { title, body, base: baseBranch, head: branch, assignees, cwd: repoRoot });
|
|
339
406
|
if (!r.ok) { fail(`could not open PR/MR — ${r.reason || 'unknown'}`); process.exitCode = 1; return; }
|
|
340
407
|
ok(`opened ${r.url}`);
|
|
408
|
+
if (auto) {
|
|
409
|
+
// The PR is open whatever happens next: a record that cannot be written is said, never a failure.
|
|
410
|
+
try {
|
|
411
|
+
recordAutoOpen(auto.file, { story: auto.story, repo: auto.repo, tasks: auto.tasks, runs: auto.runs, pr: Number(prNumberFromUrl(r.url)) || null, url: r.url, run: auto.run, by: recordActor(auto.productRoot), date: opts.today || new Date().toISOString().slice(0, 10) });
|
|
412
|
+
hand('recorded on the lane; commit it from the Product with `yad checkpoint --push`');
|
|
413
|
+
} catch (e) {
|
|
414
|
+
warn(`the PR/MR is open, but it could not be recorded on the lane: ${e.message}`);
|
|
415
|
+
}
|
|
416
|
+
}
|
|
341
417
|
hand('no reviewers were requested — ask them on the PR itself');
|
|
342
418
|
// The Product-wide active count (E71), read ONCE here and handed down: `routeCount` works inside a
|
|
343
419
|
// code repo and must not go looking for a Product itself.
|
|
@@ -366,5 +442,5 @@ export async function runOpenPr(root, opts = {}) {
|
|
|
366
442
|
if (stage === 'code-repo') for (const [say, line] of suggestReviewers(repoRoot, baseBranch, platform, { remote }).lines) say(line);
|
|
367
443
|
// The --json answer (E1). The count and the reviewer suggestion are said in prose, and a warning among
|
|
368
444
|
// them reaches `warnings`; nothing here is a request — no reviewer is ever asked for (E62).
|
|
369
|
-
return { url: r.url, platform, stage, base: baseBranch, baseSource, branch, title, task: task || null };
|
|
445
|
+
return { url: r.url, platform, stage, base: baseBranch, baseSource, branch, title, task: task || null, tasks: groupIds || null, via };
|
|
370
446
|
}
|