yadflow 4.6.0 → 4.7.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 +170 -0
- package/README.md +4 -1
- package/bin/commands.mjs +5 -1
- package/bin/yad.mjs +167 -15
- package/cli/artifact-status.mjs +88 -20
- package/cli/build.mjs +1372 -0
- package/cli/checkpoint.mjs +2 -2
- package/cli/commit.mjs +1 -0
- package/cli/dial.mjs +21 -1
- package/cli/docs.mjs +6 -1
- package/cli/doctor.mjs +133 -26
- package/cli/epic-state.mjs +357 -9
- package/cli/errors.mjs +2 -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/history.mjs +22 -2
- package/cli/hook.mjs +3 -1
- package/cli/index-command.mjs +2 -2
- package/cli/ledger.mjs +60 -0
- package/cli/next.mjs +34 -11
- package/cli/openpr.mjs +81 -5
- 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/recommend.mjs +3 -1
- package/cli/repo-publish.mjs +2 -2
- package/cli/run-checks.mjs +586 -0
- package/cli/ship-drift.mjs +49 -18
- package/cli/standup.mjs +1 -1
- package/cli/status.mjs +282 -0
- package/cli/test-build.mjs +1559 -0
- package/cli/test-run-checks.mjs +603 -0
- package/cli/test-worktree.mjs +520 -0
- package/cli/thread.mjs +4 -0
- package/cli/tidy.mjs +2 -2
- package/cli/toolbox.mjs +36 -5
- package/cli/workspace.mjs +4 -1
- package/cli/worktree-record.mjs +53 -0
- package/cli/worktree.mjs +379 -0
- package/package.json +3 -3
- package/skills/sdlc/config.yaml +1 -1
- package/skills/sdlc/module-help.csv +1 -1
- package/skills/yad-backfill/templates/checks/backfill-check.sh +9 -9
- package/skills/yad-change/SKILL.md +3 -0
- package/skills/yad-checks/SKILL.md +34 -5
- package/skills/yad-checks/references/check-gates.md +69 -10
- 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 +41 -4
- 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 +8 -8
- package/skills/yad-checks/templates/gitlab/.gitlab-ci.yml +3 -0
- package/skills/yad-checks/templates/gitlab/yad-checks.gitlab-ci.yml +4 -4
- 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-commit/SKILL.md +4 -2
- package/skills/yad-docs/templates/app/package-lock.json +395 -106
- package/skills/yad-docs/templates/app/package.json +2 -2
- package/skills/yad-engineer-review/SKILL.md +45 -20
- package/skills/yad-engineer-review/references/ship-and-record.md +42 -8
- package/skills/yad-epic/references/state-schema.md +75 -16
- 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-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 +14 -1
- package/skills/yad-product-bridge/references/bridge.md +5 -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-review-gate/SKILL.md +4 -0
- package/skills/yad-review-gate/references/gating.md +26 -1
- package/skills/yad-run/SKILL.md +52 -28
- package/skills/yad-run/references/run-loop.md +42 -21
- 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/cli/history.mjs
CHANGED
|
@@ -133,7 +133,7 @@ const fold = (s) => s.normalize('NFKC').toLowerCase();
|
|
|
133
133
|
// and a digit or two does not match half the hashes in the Product.
|
|
134
134
|
// Only text is matched, and a PR only as a whole number: `String()` of any other value would match text
|
|
135
135
|
// that is not in the file (`[object Object]`).
|
|
136
|
-
export function searchMatches(item, steps, text) {
|
|
136
|
+
export function searchMatches(item, steps, text, reopens = null) {
|
|
137
137
|
const needle = fold(String(text).trim());
|
|
138
138
|
// `12`, `#12`, `PR 12`, `pr12` and `PR #12` all name PR 12.
|
|
139
139
|
const prWanted = needle.replace(/^(pr\s*#?|#)\s*/, '');
|
|
@@ -156,6 +156,13 @@ export function searchMatches(item, steps, text) {
|
|
|
156
156
|
if (pr !== null && prQuery !== null && Number(pr) === prQuery) hit('closed.pr', pr, id);
|
|
157
157
|
if (typeof k.commit === 'string' && needle.length >= 4 && fold(k.commit).startsWith(needle)) hit('closed.commit', k.commit, id);
|
|
158
158
|
}
|
|
159
|
+
// A reopen (#322) is found by its reason and by who made it.
|
|
160
|
+
for (const r of Array.isArray(reopens) ? reopens : []) {
|
|
161
|
+
if (!isPlainObject(r)) continue;
|
|
162
|
+
const step = typeof r.step === 'string' ? r.step : null;
|
|
163
|
+
words('reopen.reason', r.reason, step);
|
|
164
|
+
words('reopen.by', r.by, step);
|
|
165
|
+
}
|
|
159
166
|
return hits;
|
|
160
167
|
}
|
|
161
168
|
|
|
@@ -322,8 +329,17 @@ export function itemHistory(root, item, { productConfig = null, productConfigWhy
|
|
|
322
329
|
thread = { root: null, broken: `the thread could not be walked (${e.code || e.message})` };
|
|
323
330
|
}
|
|
324
331
|
}
|
|
332
|
+
// Each `yad gate reopen` (#322): what walked back, and the approvals it revoked — kept here, no longer counted.
|
|
333
|
+
const reopens = (Array.isArray(stateRead.state?.reopens) ? stateRead.state.reopens : []).filter(isPlainObject).map((x) => ({
|
|
334
|
+
step: typeof x.step === 'string' ? x.step : null, date: typeof x.date === 'string' ? x.date : null,
|
|
335
|
+
by: typeof x.by === 'string' ? x.by : null, reason: typeof x.reason === 'string' ? x.reason : null,
|
|
336
|
+
walkedBack: (Array.isArray(x.steps) ? x.steps : []).map((w) => (typeof w?.id === 'string' ? w.id : null)).filter(Boolean),
|
|
337
|
+
revoked: (Array.isArray(x.revokedApprovals) ? x.revokedApprovals : []).filter(isPlainObject)
|
|
338
|
+
.map((a) => ({ step: typeof a.step === 'string' ? a.step : null, approver: typeof a.approver === 'string' ? a.approver : null })),
|
|
339
|
+
}));
|
|
325
340
|
return {
|
|
326
341
|
thread,
|
|
342
|
+
reopens,
|
|
327
343
|
steps: stateRead.steps ? out : null,
|
|
328
344
|
stepsWhy: stateRead.steps ? null : stateRead.why,
|
|
329
345
|
approvalsWhy,
|
|
@@ -426,7 +442,7 @@ function searchCmd(root, read, keep, text, { json, thread, threadNote }) {
|
|
|
426
442
|
for (const item of newestFirst(read.items.filter(keep))) {
|
|
427
443
|
const r = readState(root, item.id);
|
|
428
444
|
if (!r.steps) summaryOnly.push({ id: item.id, why: r.why });
|
|
429
|
-
const matches = searchMatches(item, r.steps || null, text);
|
|
445
|
+
const matches = searchMatches(item, r.steps || null, text, r.state?.reopens ?? null);
|
|
430
446
|
if (matches.length) found.push({ ...withShapeDone(item), matches });
|
|
431
447
|
}
|
|
432
448
|
if (json) {
|
|
@@ -493,6 +509,10 @@ function showCmd(root, read, id, { json }) {
|
|
|
493
509
|
for (const a of s.approvals || []) log(` ${c.dim(approvalLine(a))}`);
|
|
494
510
|
if (s.staleUnknown) log(` ${c.dim(`whether these approvals are stale cannot be told — ${printable(s.staleUnknown)}`)}`);
|
|
495
511
|
}
|
|
512
|
+
for (const x of story.reopens || []) {
|
|
513
|
+
log(` ${c.dim(`reopened ${printable(x.step) ?? '?'}${x.date ? ` on ${printable(x.date)}` : ''}${x.by ? ` by ${printable(x.by)}` : ''}${x.reason ? ` — ${printable(x.reason)}` : ''}`)}`);
|
|
514
|
+
log(` ${c.dim(`walked back: ${x.walkedBack.map((id) => printable(id)).join(', ') || 'none'}; revoked (not counted): ${x.revoked.length ? x.revoked.map((a) => `${printable(a.approver) ?? '?'} on ${printable(a.step) ?? '?'}`).join(', ') : 'none'}`)}`);
|
|
515
|
+
}
|
|
496
516
|
const closedCount = story.steps.filter((s) => s.closed).length;
|
|
497
517
|
info(`${plural(closedCount, 'step')} of ${story.steps.length} ${closedCount === 1 ? 'has' : 'have'} a closing record`);
|
|
498
518
|
}
|
package/cli/hook.mjs
CHANGED
|
@@ -292,7 +292,7 @@ export function guardConfig(productRoot) {
|
|
|
292
292
|
}
|
|
293
293
|
|
|
294
294
|
const driftLine = (productRoot) =>
|
|
295
|
-
`note: ${path.join(productRoot, PROJECT_FILES.productConfig)} and ${PROJECT_FILES.productConfigLegacy} say different things, and one of them is verified, so this edit is guarded — run \`yad migrate\` to choose the copy to keep`;
|
|
295
|
+
`note: ${path.join(productRoot, PROJECT_FILES.productConfig)} and ${PROJECT_FILES.productConfigLegacy} say different things, and one of them is verified, so this edit is guarded — run \`yad migrate --apply --keep product\` (or \`--keep hub\`) to choose the copy to keep`;
|
|
296
296
|
|
|
297
297
|
// What the agent is told when the edit is refused. Names the command that owns each transition —
|
|
298
298
|
// the whole point of #171 was that the ledger write had no command behind it.
|
|
@@ -308,6 +308,7 @@ export function denyMessage({ epic, rel, productRoot }) {
|
|
|
308
308
|
` author step done → review opened yad gate open ${epic} <artifact>`,
|
|
309
309
|
' the full advance at merge CI runs `yad gate ci --merged` — nothing to do locally',
|
|
310
310
|
` a genuinely broken ledger yad gate repair ${epic} --push`,
|
|
311
|
+
` an approved step to change yad gate reopen ${epic} <step> --reason "<why>" --push`,
|
|
311
312
|
'',
|
|
312
313
|
'Commit the ARTIFACT only (the .md you authored) and hand off to `yad-review-gate`; the ledger',
|
|
313
314
|
'follows on merge.',
|
|
@@ -457,6 +458,7 @@ export function commitDenyMessage({ hits, top }) {
|
|
|
457
458
|
` author step done → review opened yad gate open ${epic} <artifact>`,
|
|
458
459
|
' the full advance at merge CI runs `yad gate ci --merged` — nothing to do locally',
|
|
459
460
|
` a genuinely broken ledger yad gate repair ${epic} --push`,
|
|
461
|
+
` an approved step to change yad gate reopen ${epic} <step> --reason "<why>" --push`,
|
|
460
462
|
] : []),
|
|
461
463
|
...(index ? [' the Product index CI rebuilds it at merge; read it with `yad index --json`'] : []),
|
|
462
464
|
'',
|
package/cli/index-command.mjs
CHANGED
|
@@ -15,7 +15,7 @@ import { c, log, ok, info, warn, fail, hand, exists, emitJSON } from './lib.mjs'
|
|
|
15
15
|
import path from 'node:path';
|
|
16
16
|
import { productConfigPath, isVerifiedLedger, SCHEMA_VERSION, settingsEditHint } from './manifest.mjs';
|
|
17
17
|
import { loadProduct } from './gate.mjs';
|
|
18
|
-
import { productGit, resolveDefaultBranch } from './productcommit.mjs';
|
|
18
|
+
import { productGit, resolveDefaultBranch, branchToCommitOn } from './productcommit.mjs';
|
|
19
19
|
import { buildIndex, writeIndex, indexFreshness, INDEX_FILE } from './product-index.mjs';
|
|
20
20
|
import { printable } from './epic-state.mjs';
|
|
21
21
|
|
|
@@ -58,8 +58,8 @@ export async function runIndex(root, { json = false } = {}) {
|
|
|
58
58
|
return;
|
|
59
59
|
}
|
|
60
60
|
const git = productGit(root);
|
|
61
|
-
const branch = git('rev-parse', '--abbrev-ref', 'HEAD').stdout;
|
|
62
61
|
const defaultBranch = resolveDefaultBranch(git, productConfig);
|
|
62
|
+
const branch = branchToCommitOn(root, git, defaultBranch); // an epic worktree's detached trunk counts (#115)
|
|
63
63
|
if (branch !== defaultBranch) {
|
|
64
64
|
fail(`on '${branch}', not the default branch '${defaultBranch}' — ${INDEX_FILE} is written on the default branch only, so a branch never carries it`);
|
|
65
65
|
hand(`switch to '${defaultBranch}' and re-run (if '${defaultBranch}' is wrong, set default_branch in ${settingsEditHint(root)}); \`yad index --json\` prints it here without writing`);
|
package/cli/ledger.mjs
CHANGED
|
@@ -241,6 +241,66 @@ export function writeRetroShip(epicDir, { story, repo, task = 'retro', mergeComm
|
|
|
241
241
|
}, lockOpts);
|
|
242
242
|
}
|
|
243
243
|
|
|
244
|
+
// Why a ship of (story, task, repo) cannot be written now — `{ reason: 'exists' | 'collision', repo?, file? }` —
|
|
245
|
+
// or null. `yad build merged` asks it too, so it never answers "merged" for a ship this would refuse.
|
|
246
|
+
export function shipBlocked(epicDir, { story, task, repo }) {
|
|
247
|
+
const ships = readShips(epicDir).filter((s) => s.story === story && s.task === task);
|
|
248
|
+
if (ships.some((s) => s.repo === repo)) return { reason: 'exists' };
|
|
249
|
+
const clash = ships.find((s) => safe(s.repo) === safe(repo));
|
|
250
|
+
if (clash) return { reason: 'collision', repo: clash.repo };
|
|
251
|
+
const file = path.join(epicFiles(epicDir).buildLogDir, buildShardName({ story, task, repo }));
|
|
252
|
+
if (fs.existsSync(file)) return { reason: 'collision', file };
|
|
253
|
+
return null;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// Record a ship (`yad build ship`, #346): one shard per (story, task, repo), refused when that ship is
|
|
257
|
+
// already recorded, or when another repo's ship shares its file name (`safe()` folds `api.v2` and `api_v2`
|
|
258
|
+
// into one name, and writing the second would overwrite the first). The guard, the collision check and the
|
|
259
|
+
// write are one critical section, as in `writeRetroShip`. Returns { written, reason?, file?, ship? }.
|
|
260
|
+
export function writeShip(epicDir, ship, lockOpts = {}) {
|
|
261
|
+
const { story, task, repo } = ship;
|
|
262
|
+
if (!story || !task || !repo) throw new Error('writeShip: story, task and repo are required');
|
|
263
|
+
return withLedgerLock(buildLogLock(epicDir), () => {
|
|
264
|
+
const blocked = shipBlocked(epicDir, ship);
|
|
265
|
+
if (blocked) return { written: false, ...blocked };
|
|
266
|
+
const file = path.join(epicFiles(epicDir).buildLogDir, buildShardName(ship));
|
|
267
|
+
writeJSON(file, ship);
|
|
268
|
+
return { written: true, file, ship };
|
|
269
|
+
}, lockOpts);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// Record one trust run (`yad build trust`, #346): a new shard under its own `uid`, never over another file.
|
|
273
|
+
export function writeTrustRun(epicDir, entry, lockOpts = {}) {
|
|
274
|
+
if (!entry?.story || !entry.repo || !entry.step || !entry.uid) throw new Error('writeTrustRun: story, repo, step and uid are required');
|
|
275
|
+
return withLedgerLock(trustLogLock(epicDir), () => {
|
|
276
|
+
const file = path.join(epicFiles(epicDir).trustLogDir, trustShardName(entry));
|
|
277
|
+
if (fs.existsSync(file)) return { written: false, reason: 'collision', file };
|
|
278
|
+
writeJSON(file, entry);
|
|
279
|
+
return { written: true, file };
|
|
280
|
+
}, lockOpts);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
// Finalize a trust run's verdict where it lives: its own shard, or its entry in the folded trust-log.json
|
|
284
|
+
// once `yad tidy up` folded it — the human gate's word on a run the orchestrator recorded.
|
|
285
|
+
export function updateTrustRun(epicDir, match, update, lockOpts = {}) {
|
|
286
|
+
return withLedgerLock(trustLogLock(epicDir), () => {
|
|
287
|
+
const f = epicFiles(epicDir);
|
|
288
|
+
// Both copies when a half-applied tidy left the run in each: readers take the folded one then.
|
|
289
|
+
const foldedObj = readJSONStrict(f.trustLog, null);
|
|
290
|
+
const run = Array.isArray(foldedObj?.runs) ? foldedObj.runs.find(match) : null;
|
|
291
|
+
if (run) { update(run); writeJSON(f.trustLog, foldedObj); }
|
|
292
|
+
for (const { name, obj } of readShardDir(f.trustLogDir)) {
|
|
293
|
+
if (match(obj)) {
|
|
294
|
+
update(obj);
|
|
295
|
+
const file = path.join(f.trustLogDir, name);
|
|
296
|
+
writeJSON(file, obj);
|
|
297
|
+
return { found: true, where: 'shard', file, run: obj };
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
return run ? { found: true, where: 'folded', file: f.trustLog, run } : { found: false };
|
|
301
|
+
}, lockOpts);
|
|
302
|
+
}
|
|
303
|
+
|
|
244
304
|
// Find the ship matching `match(ship)` across loose shards (authoritative until folded) then the
|
|
245
305
|
// folded file, apply `update(ship)`, and write back ONLY the file that holds it. Returns
|
|
246
306
|
// { found, where, file, ship }; found:false writes nothing (the caller warns). The find and the
|
package/cli/next.mjs
CHANGED
|
@@ -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
|
}
|
package/cli/platform.mjs
CHANGED
|
@@ -313,6 +313,27 @@ export function findPrForBranch(platform, branch, { cwd } = {}) {
|
|
|
313
313
|
return { ok: true, number: Number(pr.number), url: pr.url || null };
|
|
314
314
|
}
|
|
315
315
|
|
|
316
|
+
// The highest PR/MR number the repo has given out, open or not (`yad gate reopen`, #322): numbers only grow,
|
|
317
|
+
// so every review opened before the reopen is at or below it. `{ ok: true, number }` (null when the repo has
|
|
318
|
+
// none yet), or `{ ok: false, reason }`. Never throws.
|
|
319
|
+
export function newestPrNumber(platform, { cwd } = {}) {
|
|
320
|
+
if (!platformReady(platform)) return { ok: false, reason: `${cliFor(platform) || 'platform CLI'} not available` };
|
|
321
|
+
if (platform === 'gitlab') {
|
|
322
|
+
const r = run('glab', ['api', 'projects/:id/merge_requests?state=all&order_by=created_at&sort=desc&per_page=1'], { cwd });
|
|
323
|
+
if (!r.ok) return { ok: false, reason: r.stderr || 'glab api merge_requests failed' };
|
|
324
|
+
let rows;
|
|
325
|
+
try { rows = JSON.parse(r.stdout); } catch { return { ok: false, reason: 'unreadable glab api response' }; }
|
|
326
|
+
const n = Array.isArray(rows) ? Number(rows[0]?.iid) : NaN;
|
|
327
|
+
return { ok: true, number: Number.isInteger(n) && n > 0 ? n : null };
|
|
328
|
+
}
|
|
329
|
+
const r = run('gh', ['pr', 'list', '--state', 'all', '--limit', '1', '--json', 'number'], { cwd });
|
|
330
|
+
if (!r.ok) return { ok: false, reason: r.stderr || 'gh pr list failed' };
|
|
331
|
+
let rows;
|
|
332
|
+
try { rows = JSON.parse(r.stdout); } catch { return { ok: false, reason: 'unreadable gh pr list response' }; }
|
|
333
|
+
const n = Array.isArray(rows) ? Number(rows[0]?.number) : NaN;
|
|
334
|
+
return { ok: true, number: Number.isInteger(n) && n > 0 ? n : null };
|
|
335
|
+
}
|
|
336
|
+
|
|
316
337
|
// The head/source branch of a PR/MR, so a caller can confirm a number a human typed actually belongs
|
|
317
338
|
// to the review it is about to bind approvals to. Returns { ok, branch }; never throws.
|
|
318
339
|
export function prBranch(platform, n, { cwd } = {}) {
|
package/cli/pr-list.mjs
CHANGED
|
@@ -19,7 +19,7 @@ import { api, httpStatus, loggedIn, repoPathFromGitUrl, shown, whyFailed, PAGE,
|
|
|
19
19
|
const GH_CHECKS = { SUCCESS: 'passing', FAILURE: 'failing', ERROR: 'failing', PENDING: 'running', EXPECTED: 'running' };
|
|
20
20
|
|
|
21
21
|
const GH_QUERY = `query($owner:String!,$name:String!){repository(owner:$owner,name:$name){
|
|
22
|
-
open:pullRequests(states:OPEN,first:${PAGE},orderBy:{field:CREATED_AT,direction:DESC}){totalCount nodes{number isDraft author{__typename login} reviewDecision reviews{totalCount} latestOpinionatedReviews(first:100){nodes{state}} commits(last:1){nodes{commit{statusCheckRollup{state}}}}}}
|
|
22
|
+
open:pullRequests(states:OPEN,first:${PAGE},orderBy:{field:CREATED_AT,direction:DESC}){totalCount nodes{number isDraft headRefName author{__typename login} reviewDecision reviews{totalCount} latestOpinionatedReviews(first:100){nodes{state}} commits(last:1){nodes{commit{statusCheckRollup{state}}}}}}
|
|
23
23
|
merged:pullRequests(states:MERGED,first:${PAGE},orderBy:{field:UPDATED_AT,direction:DESC}){nodes{number mergedAt updatedAt author{__typename login}}}}}`;
|
|
24
24
|
|
|
25
25
|
// GitHub's review state, in the words the standup prints. `none` = no review of any kind yet.
|
|
@@ -64,7 +64,8 @@ export function prTarget({ platform = null, gitUrl = '' } = {}, { runner = run,
|
|
|
64
64
|
// The PRs/MRs of one repo: `{ ok: true, open: [...], merged: [...], openPartial, mergedPartial }` or
|
|
65
65
|
// `{ ok: false, kind, why }`. `sinceMs` bounds the merged list (epoch milliseconds).
|
|
66
66
|
// open: { number, author, draft, checks: passing|failing|running|none|null, review: none|reviewed|approved|changes-requested|null,
|
|
67
|
-
// status? (GitLab's own word), waits? (GitLab: a status that holds the merge)
|
|
67
|
+
// status? (GitLab's own word), waits? (GitLab: a status that holds the merge),
|
|
68
|
+
// branch (the head branch, or null: `yad status` finds the follow-ups by it, #349) }
|
|
68
69
|
// merged: { number, author, mergedAt (ISO) }
|
|
69
70
|
export function listPrs(target, { sinceMs, runner = run, env = process.env, authCache = new Map() } = {}) {
|
|
70
71
|
const t = target?.cli ? target : prTarget(target, { runner, env, authCache });
|
|
@@ -91,6 +92,7 @@ function listGitHub(t, sinceMs, runner) {
|
|
|
91
92
|
number: n.number, author: author(n.author), draft: n.isDraft === true,
|
|
92
93
|
checks: GH_CHECKS[n.commits?.nodes?.[0]?.commit?.statusCheckRollup?.state] || (n.commits?.nodes?.[0]?.commit?.statusCheckRollup ? null : 'none'),
|
|
93
94
|
review: ghReview(n),
|
|
95
|
+
branch: typeof n.headRefName === 'string' ? n.headRefName : null,
|
|
94
96
|
}));
|
|
95
97
|
const nodes = repo.merged.nodes;
|
|
96
98
|
const merged = nodes.filter((n) => Date.parse(n.mergedAt) >= sinceMs).map((n) => ({ number: n.number, author: author(n.author), mergedAt: n.mergedAt }));
|
|
@@ -117,7 +119,7 @@ function listGitLab(t, sinceMs, runner) {
|
|
|
117
119
|
const open = o.body.map((x) => {
|
|
118
120
|
const st = typeof x.detailed_merge_status === 'string' ? x.detailed_merge_status : null;
|
|
119
121
|
const checks = st && Object.hasOwn(GL_CHECKS, st) ? GL_CHECKS[st] : null;
|
|
120
|
-
return { number: x.iid, author: who(x.author), draft: x.draft === true, checks, review: null, ...(st && !checks ? { status: st } : {}), waits: !!st && GL_WAITS.includes(st) };
|
|
122
|
+
return { number: x.iid, author: who(x.author), draft: x.draft === true, checks, review: null, ...(st && !checks ? { status: st } : {}), waits: !!st && GL_WAITS.includes(st), branch: typeof x.source_branch === 'string' ? x.source_branch : null };
|
|
121
123
|
});
|
|
122
124
|
const merged = m.body.filter((x) => Date.parse(x.merged_at) >= sinceMs).map((x) => ({ number: x.iid, author: who(x.author), mergedAt: x.merged_at }));
|
|
123
125
|
return { ...t, ok: true, open, merged, openPartial: o.body.length >= PAGE, mergedPartial: m.body.length >= PAGE };
|
package/cli/product-index.mjs
CHANGED
|
@@ -24,7 +24,7 @@ import { createHash } from 'node:crypto';
|
|
|
24
24
|
import { spawnSync } from 'node:child_process';
|
|
25
25
|
import { isPlainObject, writeJSON, info, warn } from './lib.mjs';
|
|
26
26
|
import { isVerifiedLedger } from './manifest.mjs';
|
|
27
|
-
import { productGit, resolveDefaultBranch } from './productcommit.mjs';
|
|
27
|
+
import { productGit, resolveDefaultBranch, branchToCommitOn } from './productcommit.mjs';
|
|
28
28
|
import {
|
|
29
29
|
epicIds, epicRel, epicRoot, unlistedLedgerDirs, parseFrontmatter, lineageFrom, stepStatus, STEP_STATES,
|
|
30
30
|
FOUNDATION_EPIC, FOUNDATION_TITLE, titleOf,
|
|
@@ -273,8 +273,11 @@ export function uncommittedIndexInputs(root, commits = null) {
|
|
|
273
273
|
export function refreshIndexAfterWrite(root, productConfig, { quiet = false } = {}) {
|
|
274
274
|
if (isVerifiedLedger(productConfig) || !fs.existsSync(path.join(root, '.git'))) return false;
|
|
275
275
|
const git = productGit(root);
|
|
276
|
-
const
|
|
277
|
-
|
|
276
|
+
const defaultBranch = resolveDefaultBranch(git, productConfig);
|
|
277
|
+
// An epic worktree counts (#115), judged by the local origin/<default>: the index is a derived file this
|
|
278
|
+
// writes and never pushes — the command that commits it fetches first, and refuses on its own — so no
|
|
279
|
+
// fetch on every write.
|
|
280
|
+
if (branchToCommitOn(root, git, defaultBranch, { fetch: false }) !== defaultBranch) return false;
|
|
278
281
|
try {
|
|
279
282
|
const changed = writeIndex(root);
|
|
280
283
|
if (changed && !quiet) info(`rebuilt ${INDEX_FILE}`);
|