yadflow 4.10.0 → 4.12.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.
Files changed (120) hide show
  1. package/CHANGELOG.md +152 -0
  2. package/README.md +14 -3
  3. package/bin/commands.mjs +7 -1
  4. package/bin/yad.mjs +163 -16
  5. package/cli/agent-guard-worker.mjs +13 -0
  6. package/cli/agent-guard.mjs +1053 -57
  7. package/cli/agent-rules.mjs +59 -3
  8. package/cli/argv-flags.mjs +2 -2
  9. package/cli/brain/vendor/LICENSE-graphology-library.txt +21 -0
  10. package/cli/brain/vendor/LICENSE-graphology.txt +21 -0
  11. package/cli/brain/vendor/LICENSE-sigma.txt +12 -0
  12. package/cli/brain/vendor/graphology-library.min.js +2 -0
  13. package/cli/brain/vendor/graphology.umd.min.js +2 -0
  14. package/cli/brain/vendor/sigma.min.js +1369 -0
  15. package/cli/brain/view/app.js +382 -0
  16. package/cli/brain/view/index.html +63 -0
  17. package/cli/brain/view/live.css +228 -0
  18. package/cli/brain/view/live.html +110 -0
  19. package/cli/brain/view/live.js +884 -0
  20. package/cli/brain/view/style.css +141 -0
  21. package/cli/brain-about.mjs +206 -0
  22. package/cli/brain-activity.mjs +285 -0
  23. package/cli/brain-skills.mjs +118 -0
  24. package/cli/brain-vendor.mjs +71 -0
  25. package/cli/brain-view.mjs +345 -0
  26. package/cli/brain.mjs +810 -0
  27. package/cli/brand-cmd.mjs +326 -0
  28. package/cli/brand.mjs +327 -0
  29. package/cli/ci-check.mjs +3 -3
  30. package/cli/doctor.mjs +145 -14
  31. package/cli/epic-state.mjs +93 -1
  32. package/cli/epic.mjs +15 -3
  33. package/cli/errors.mjs +2 -1
  34. package/cli/find-product.mjs +69 -15
  35. package/cli/foundation-publish.mjs +256 -0
  36. package/cli/gate.mjs +29 -3
  37. package/cli/git-read.mjs +38 -0
  38. package/cli/guard-stream.mjs +409 -0
  39. package/cli/guide.mjs +26 -3
  40. package/cli/hook.mjs +59 -9
  41. package/cli/issues-act.mjs +57 -13
  42. package/cli/issues-write.mjs +19 -6
  43. package/cli/issues.mjs +69 -24
  44. package/cli/lib.mjs +37 -2
  45. package/cli/local-page.mjs +138 -0
  46. package/cli/local-setup-record.mjs +71 -0
  47. package/cli/local-setup-steps.mjs +186 -0
  48. package/cli/local-setup.mjs +611 -0
  49. package/cli/machine.mjs +1 -1
  50. package/cli/manifest.mjs +55 -0
  51. package/cli/map/view/app.js +712 -0
  52. package/cli/map/view/index.html +50 -0
  53. package/cli/map/view/style.css +142 -0
  54. package/cli/map-view.mjs +190 -0
  55. package/cli/map.mjs +637 -0
  56. package/cli/members.mjs +9 -15
  57. package/cli/next.mjs +1 -1
  58. package/cli/openpr.mjs +2 -2
  59. package/cli/plain-text.mjs +22 -0
  60. package/cli/plan.mjs +310 -36
  61. package/cli/platform.mjs +5 -5
  62. package/cli/product-index.mjs +1 -1
  63. package/cli/protection.mjs +32 -0
  64. package/cli/reconcile.mjs +61 -13
  65. package/cli/report.mjs +9 -3
  66. package/cli/reports-dir.mjs +393 -0
  67. package/cli/reports.mjs +65 -0
  68. package/cli/run-checks.mjs +5 -2
  69. package/cli/scan.mjs +4 -6
  70. package/cli/secret-text.mjs +66 -0
  71. package/cli/setup.mjs +54 -8
  72. package/cli/standup.mjs +94 -72
  73. package/cli/status.mjs +6 -5
  74. package/cli/test-agents-file.mjs +614 -8
  75. package/cli/test-brain-activity.mjs +753 -0
  76. package/cli/test-brain-view.mjs +381 -0
  77. package/cli/test-brain.mjs +795 -0
  78. package/cli/test-brand.mjs +558 -0
  79. package/cli/test-guide.mjs +438 -0
  80. package/cli/test-local-setup.mjs +1188 -0
  81. package/cli/test-machine.mjs +59 -0
  82. package/cli/test-map.mjs +615 -0
  83. package/cli/test-reports.mjs +382 -0
  84. package/cli/test-run-checks.mjs +4 -0
  85. package/cli/test-worktree.mjs +24 -3
  86. package/cli/toolbox-connect.mjs +21 -6
  87. package/cli/toolbox.mjs +74 -5
  88. package/cli/update-commit.mjs +118 -9
  89. package/cli/usage.mjs +17 -7
  90. package/cli/workspace.mjs +11 -2
  91. package/package.json +8 -4
  92. package/skills/sdlc/module-help.csv +1 -0
  93. package/skills/yad-architecture/SKILL.md +22 -4
  94. package/skills/yad-brand/SKILL.md +69 -0
  95. package/skills/yad-change/SKILL.md +3 -1
  96. package/skills/yad-change/references/triage.md +2 -0
  97. package/skills/yad-checks/SKILL.md +2 -0
  98. package/skills/yad-checks/references/check-gates.md +8 -5
  99. package/skills/yad-checks/templates/checks/build-test-lint.sh +7 -0
  100. package/skills/yad-checks/templates/checks/install-deps.sh +6 -0
  101. package/skills/yad-checks/templates/checks/package-manager.sh +42 -0
  102. package/skills/yad-checks/templates/github/yad-checks.yml +3 -2
  103. package/skills/yad-checks/templates/gitlab/yad-checks.gitlab-ci.yml +3 -2
  104. package/skills/yad-checks/templates/hooks/local-setup-notice.mjs +96 -0
  105. package/skills/yad-checks/templates/hooks/yad-activity.mjs +238 -0
  106. package/skills/yad-connect-repos/SKILL.md +14 -0
  107. package/skills/yad-discovery/SKILL.md +11 -0
  108. package/skills/yad-discovery/references/foundation-schema.md +11 -0
  109. package/skills/yad-docs/templates/app/package-lock.json +18 -10
  110. package/skills/yad-docs/templates/app/package.json +6 -1
  111. package/skills/yad-epic/SKILL.md +3 -0
  112. package/skills/yad-epic/references/state-schema.md +35 -1
  113. package/skills/yad-guide/SKILL.md +10 -7
  114. package/skills/yad-implement/SKILL.md +76 -15
  115. package/skills/yad-issues/SKILL.md +2 -1
  116. package/skills/yad-pr-template/templates/checks/pr-template.sh +8 -4
  117. package/skills/yad-pr-template/templates/checks/pr-title.sh +8 -4
  118. package/skills/yad-spec/SKILL.md +19 -0
  119. package/skills/yad-stories/SKILL.md +22 -4
  120. package/skills/yad-stories/references/story-schema.md +1 -1
@@ -11,7 +11,7 @@ import fs from 'node:fs';
11
11
  import { run, forTerminal, c, log, fail, hand, info, warn, emitJSON } from './lib.mjs';
12
12
  import { addItemLabels, removeItemLabels, commentOnItem, closeItem, newItem, editItem, reopenItem, setAssignee, makeConfidential, platformLogin } from './platform.mjs';
13
13
  import { api, httpStatus } from './protection.mjs';
14
- import { labelRules, ITEM_TYPES, PRIORITIES } from './issues.mjs';
14
+ import { labelRules, labelOwner, labelKey, readLabels, ITEM_TYPES, PRIORITIES } from './issues.mjs';
15
15
  import { readItem, resolveTarget } from './issues-write.mjs';
16
16
  import { allLinks, itemKey } from './issue-links.mjs';
17
17
  import { redactTokens, repoFacts, routeFor } from './scan.mjs';
@@ -70,7 +70,7 @@ function bodyOf({ body, bodyFile }) {
70
70
  }
71
71
 
72
72
  // The repo: the Product unless a registered one is named. `ref` resolution does the registry and login checks.
73
- function targetOf(root, repo, { env, runner }) {
73
+ export function targetOf(root, repo, { env, runner }) {
74
74
  const r = resolveTarget(root, repo && repo !== 'Product' ? `${repo}#1` : '1', { env, runner });
75
75
  if (!r.ok) throw new Refused(r.why, r.hint);
76
76
  if (!r.t.ok) throw new Refused(`${forTerminal(r.label)}: ${r.t.why}`);
@@ -197,11 +197,27 @@ export async function runIssuesAssign(root, { ref, assignee = null, me = false,
197
197
  });
198
198
  }
199
199
 
200
- export async function runIssuesLabel(root, { ref, priority: rawPriority = null, type: rawType = null, json = false, env = process.env, runner = run } = {}) {
200
+ // `--add` / `--remove` (#514) take any label but yad's own: those have a flag of their own, or yad writes them.
201
+ const OWNER_HINT = {
202
+ priority: 'set the priority with --priority',
203
+ type: 'set the type with --type',
204
+ status: 'yad writes the status label itself, from what the item and its epic say (`yad issues sync`)',
205
+ epic: 'yad writes an epic label itself: link the item with `yad issues link <ref> <EP-id>`',
206
+ };
207
+ const names = (v) => (v == null ? [] : Array.isArray(v) ? v : [v]).map((n) => String(n).trim());
208
+ // Every comparison of two label names is `labelKey` (cli/issues.mjs), never a spelling of its own (#514 reviews 1-2).
209
+ const fold = labelKey;
210
+
211
+ export async function runIssuesLabel(root, { ref, priority: rawPriority = null, type: rawType = null, add: rawAdd = [], remove: rawRemove = [], json = false, env = process.env, runner = run } = {}) {
201
212
  const priority = normPriority(rawPriority);
202
213
  const type = normType(rawType);
214
+ const plus = names(rawAdd);
215
+ const minus = names(rawRemove);
203
216
  return act(root, ref, { json, env, runner }, async (got, out) => {
204
- if (priority === null && type === null) throw new Refused('pass --priority, --type or both');
217
+ if (priority === null && type === null && !plus.length && !minus.length) throw new Refused('pass --priority, --type, --add or --remove');
218
+ if ([...plus, ...minus].some((n) => !n)) throw new Refused('--add and --remove need a label name');
219
+ const both = plus.filter((n) => minus.some((m) => fold(m) === fold(n)));
220
+ if (both.length) throw new Refused(`${forTerminal(both.join(', '))} is in both --add and --remove`, 'name each label once');
205
221
  if (priority !== null && !PRIORITIES.includes(priority)) throw new Refused(`unknown --priority ${forTerminal(String(priority))}`, `use one of ${PRIORITIES.join(', ')}`);
206
222
  if (type !== null && !ITEM_TYPES.includes(type)) throw new Refused(`unknown --type ${forTerminal(String(type))}`, `use one of ${ITEM_TYPES.join(', ')}`);
207
223
  if (type === 'security' && got.t.platform === 'github' && !got.item.confidential && routeFor('security', 'github', repoFacts(got.t, runner).vis) !== 'issue') {
@@ -210,17 +226,44 @@ export async function runIssuesLabel(root, { ref, priority: rawPriority = null,
210
226
  // A confidential item's labels are not read, so the old ones could not be removed.
211
227
  if (got.item.confidential) throw new Refused('a confidential item\'s labels are not read, so they cannot be replaced here', 'change them on GitLab');
212
228
  const rules = labelRules(got.productConfig);
213
- const have = new Set(got.item.labels.map((l) => l.toLowerCase()));
229
+ for (const n of [...plus, ...minus]) {
230
+ const owner = labelOwner(n, rules);
231
+ if (owner) throw new Refused(`${forTerminal(n)} is a${owner === 'epic' ? 'n epic' : ` ${owner}`} label, which --add and --remove do not change`, OWNER_HINT[owner]);
232
+ }
233
+ const have = new Set(got.item.labels.map(fold));
214
234
  const add = [];
215
235
  const remove = [];
236
+ // The repo's labels, read once and only when needed.
237
+ let known = null;
238
+ const repoLabels = () => (known ??= readLabels(got.t, runner));
239
+ // A label is added only as the repo already spells it: a missing one is refused, never made by the platform.
240
+ if (plus.length) {
241
+ repoLabels();
242
+ if (!known.ok) throw new Refused(`the repo's labels could not be read, so --add was not checked: ${known.why}`, 'try again, or set the label on the platform');
243
+ const missing = plus.filter((n) => !known.keys.has(fold(n)));
244
+ if (missing.length) throw new Refused(`the repo has no label ${forTerminal(missing.join(', '))}`, 'create it on the platform first, then run this again; nothing was changed');
245
+ for (const n of plus) if (!have.has(fold(n)) && !add.some((a) => fold(a) === fold(n))) add.push(known.real.get(fold(n)) ?? n);
246
+ const already = [...new Map(plus.filter((n) => have.has(fold(n))).map((n) => [fold(n), n])).values()];
247
+ if (already.length) out.notes.push(`it already has ${already.map(forTerminal).join(', ')}`);
248
+ }
249
+ for (const n of minus) {
250
+ if (remove.some((r) => fold(r) === fold(n))) continue; // named twice: one removal, never a second that fails
251
+ if (have.has(fold(n))) remove.push(n);
252
+ else out.notes.push(`it has no label ${forTerminal(n)}, so there was nothing to remove`);
253
+ }
216
254
  for (const [kind, value] of [['priority', priority], ['type', type]]) {
217
255
  if (value === null) continue;
218
256
  const want = rules[kind][value][0];
219
- if (!rules[kind][value].some((l) => have.has(l.toLowerCase()))) add.push(want);
220
- for (const [other, names] of Object.entries(rules[kind])) if (other !== value) remove.push(...names.filter((l) => have.has(l.toLowerCase())));
257
+ if (!rules[kind][value].some((l) => have.has(fold(l)))) add.push(want);
258
+ for (const [other, names] of Object.entries(rules[kind])) if (other !== value) remove.push(...names.filter((l) => have.has(fold(l))));
221
259
  }
222
- const realNames = new Map(got.item.labels.map((l) => [l.toLowerCase(), l]));
223
- const stale = remove.map((l) => realNames.get(l.toLowerCase()) ?? l);
260
+ // Removed as the repo spells it: an item's labels are read cleaned (spaces folded), and a DELETE or a GitLab
261
+ // remove_labels of the cleaned spelling misses a label like `needs design`. If the repo's labels cannot be
262
+ // read, the item's own spelling is sent, and the read-back says if it stayed.
263
+ const realNames = new Map(got.item.labels.map((l) => [fold(l), l]));
264
+ if (remove.length) repoLabels();
265
+ const spelled = (l) => (known?.ok ? known.real.get(fold(l)) : null) ?? realNames.get(fold(l)) ?? l;
266
+ const stale = [...new Map(remove.map((l) => [fold(l), spelled(l)])).values()];
224
267
  if (got.t.platform === 'gitlab' && [...add, ...stale].some((l) => l.includes(','))) throw new Refused('a GitLab label name with a comma cannot be sent', 'rename that label in the issues settings of .sdlc/product.json');
225
268
  // On GitLab a vulnerability is confidential first, so the label is never on a public item. This runs even when
226
269
  // the label is already there: a public item that carries it is exactly what must not stay.
@@ -233,7 +276,7 @@ export async function runIssuesLabel(root, { ref, priority: rawPriority = null,
233
276
  out.changed.push('made confidential');
234
277
  madeConfidential = true;
235
278
  }
236
- if (!add.length && !stale.length) { out.notes.push('it already has those labels'); return null; }
279
+ if (!add.length && !stale.length) { if (priority !== null || type !== null || !out.notes.length) out.notes.push('it already has those labels'); return null; }
237
280
  if (add.length) {
238
281
  const r = addItemLabels(got.t, got.number, add, { runner });
239
282
  if (!r.ok && !madeConfidential) return r;
@@ -245,8 +288,9 @@ export async function runIssuesLabel(root, { ref, priority: rawPriority = null,
245
288
  if (madeConfidential) out.notes.push('it is confidential now, so its labels could not be read back to check');
246
289
  else if (!after) out.notes.push('the item could not be read again to check the change');
247
290
  else {
248
- const now = new Set(after.labels.map((l) => l.toLowerCase()));
249
- for (const l of add) if (!now.has(l.toLowerCase())) out.dropped.push(`the label ${l} was not set`);
291
+ const now = new Set(after.labels.map(fold));
292
+ for (const l of add) if (!now.has(fold(l))) out.dropped.push(`the label ${l} was not set`);
293
+ for (const l of stale) if (now.has(fold(l))) out.dropped.push(`the label ${l} is still there`);
250
294
  }
251
295
  return null;
252
296
  });
@@ -318,7 +362,7 @@ export async function runIssuesReopen(root, { ref, json = false, env = process.e
318
362
  const ACT_FLAGS = {
319
363
  new: ['--title', '--body', '--body-file', '--type', '--priority', '--assignee', '--me', '--repo'],
320
364
  assign: ['--me', '--none'],
321
- label: ['--priority', '--type'],
365
+ label: ['--priority', '--type', '--add', '--remove'],
322
366
  edit: ['--title', '--body', '--body-file'],
323
367
  comment: ['--body', '--body-file'],
324
368
  close: [], reopen: [],
@@ -7,14 +7,14 @@
7
7
  import fs from 'node:fs';
8
8
  import path from 'node:path';
9
9
  import { run, readJSON, forTerminal, c, log, fail, hand, info, ok as said, warn, emitJSON } from './lib.mjs';
10
- import { epicFiles, productConfigPath } from './manifest.mjs';
10
+ import { epicFiles, isVerifiedLedger, productConfigPath } from './manifest.mjs';
11
11
  import { epicIds, epicRoot, isGenesisType, isValidEpicId, PRODUCT_EPICS, WORK_ITEM_TYPES } from './epic-state.mjs';
12
12
  import { addItemLabels, closeItem, commentOnItem, removeItemLabels } from './platform.mjs';
13
13
  import { productIdentity } from './members.mjs';
14
14
  import { prTarget } from './pr-list.mjs';
15
15
  import { repoSources } from './standup.mjs';
16
16
  import { api, shown, whyFailed, httpStatus, TIMEOUT } from './protection.mjs';
17
- import { labelRules, pick, pickType, itemStatus } from './issues.mjs';
17
+ import { labelRules, pick, pickType, itemStatus, otherLabels } from './issues.mjs';
18
18
  import { runEpicNew, epicIdFrom } from './epic.mjs';
19
19
  import { allLinks, combinedStage, epicStage, itemKey, readLinks, writeLinks } from './issue-links.mjs';
20
20
 
@@ -117,6 +117,9 @@ export async function runIssuesShow(root, { ref, json = false, env = process.env
117
117
  if (json) return emitJSON({ ok: true, ...out });
118
118
  log(`${c.bold(out.ref)} ${out.title ?? '(confidential: open it on GitLab to read it)'}`);
119
119
  info(`${out.state} · priority ${out.priority ?? 'none'} · type ${out.type ?? 'none'} · assigned ${out.assignees.join(', ') || 'nobody'}`);
120
+ // #514: the labels that are none of yad's own. Each was made safe to print when it was read.
121
+ const others = otherLabels(out.labels, rules);
122
+ if (others.length) info(`labels ${others.join(', ')}`);
120
123
  if (out.url) info(out.url);
121
124
  if (out.body) log(`\n${out.body}`);
122
125
  return undefined;
@@ -163,7 +166,7 @@ function makeEntry(t, item, now) {
163
166
  }
164
167
 
165
168
  // Add the link (or find the one there) and write back. `{ entry, created, back }`.
166
- function linkAndWriteBack(root, epic, t, item, { rules, epicType, now, runner }) {
169
+ export function linkAndWriteBack(root, epic, t, item, { rules, epicType, now, runner }) {
167
170
  const items = readLinks(root, epic);
168
171
  const key = itemKey({ host: t.host, repo: t.repo, number: item.number });
169
172
  let entry = items.find((l) => itemKey(l) === key);
@@ -221,6 +224,16 @@ function registeredTargets(root, { env, runner }) {
221
224
  }
222
225
 
223
226
  // Bring each linked item up to date. `only` limits it to one epic's items. Returns the plan of what happened.
227
+ // How a changed record reaches the team (#512): `commit <file>` and, on a verified Product, the PR route. The
228
+ // Product's pr-title and pr-template checks let a PR of these records alone (issue-links files, the roadmap-items
229
+ // file, step owner files) through from any branch, and a review/EP-* branch would advance a step. The gates run
230
+ // the default branch's copy of the checks (#426), so that holds once a `yad update` carrying them has merged.
231
+ // Like `yad assign` (owners.mjs): with no verified Product there are no Product checks to name.
232
+ export function recordRoute(root, file) {
233
+ if (!isVerifiedLedger(readJSON(productConfigPath(root), null))) return `commit ${file}`;
234
+ return `commit ${file} on a branch of its own, not review/…, in a PR titled like \`chore: record tracker links\` — the Product checks let a PR of these records alone through, once a \`yad update\` that carries them has merged on the default branch`;
235
+ }
236
+
224
237
  export function syncItems(root, { only = null, dryRun = false, close = true, env = process.env, runner = run, now = Date.now() } = {}) {
225
238
  const links = allLinks(root);
226
239
  const epicsOf = (key) => links.byItem.get(key) || [];
@@ -296,7 +309,7 @@ export async function runIssuesSync(root, { dryRun = false, json = false, env =
296
309
  for (const s of r.skipped) warn(s);
297
310
  for (const e of r.unreadable) warn(`${e}: its .sdlc/issue-links.json could not be read, so status labels and closes were held back`);
298
311
  if (!r.items.length && !r.skipped.length && !r.unreadable.length) info('no items are linked to an epic');
299
- else if (!dryRun) info('commit any .sdlc/issue-links.json this changed, so the team keeps the record');
312
+ else if (!dryRun) info(`${recordRoute(root, 'any .sdlc/issue-links.json this changed')}, so the team keeps the record`);
300
313
  return undefined;
301
314
  }
302
315
 
@@ -310,7 +323,7 @@ export function syncAfterGate(root, epic, { env = process.env, runner = run, now
310
323
  const r = syncItems(root, { only: epic, close: false, env, runner, now });
311
324
  const changed = r.items.filter((i) => i.commented || i.labelled.length || i.removed.length);
312
325
  for (const i of changed) info(`updated ${i.ref}: ${[i.commented && 'comment', ...i.labelled.map((l) => `+${forTerminal(l)}`), ...i.removed.map((l) => `-${forTerminal(l)}`)].filter(Boolean).join(', ')}`);
313
- if (changed.some((i) => i.commented)) info('commit .sdlc/issue-links.json so the team keeps the record');
326
+ if (changed.some((i) => i.commented)) info(`${recordRoute(root, '.sdlc/issue-links.json')}, so the team keeps the record`);
314
327
  for (const i of r.items) for (const f of i.failed) warn(`${i.ref}: ${forTerminal(f)}. The gate still passed; \`yad issues sync\` catches up`);
315
328
  for (const s of r.skipped) warn(s);
316
329
  } catch (e) {
@@ -332,7 +345,7 @@ export async function runIssuesLink(root, { ref, epic: raw, json = false, now =
332
345
  if (json) return emitJSON({ ok: true, epic, url: entry.url, number: entry.number, created, commented: back.commented, labelled: back.labelled, failed: back.failed, notes: back.notes });
333
346
  said(`${created ? 'linked' : 'already linked:'} ${got.label === 'Product' ? '' : forTerminal(got.label)}#${entry.number} → ${epic}`);
334
347
  sayBack(back);
335
- if (created) info('commit .sdlc/issue-links.json on the epic\'s branch so the team sees the link');
348
+ if (created) info(`${recordRoute(root, '.sdlc/issue-links.json')}, so the team sees the link`);
336
349
  return undefined;
337
350
  }
338
351
 
package/cli/issues.mjs CHANGED
@@ -9,14 +9,16 @@
9
9
  // - a GitLab confidential item keeps its number and facts, and its title is never read into the model.
10
10
  // Status is worked out from facts (open or closed, and later the linked epic). A `status:` label is never read.
11
11
  import fs from 'node:fs';
12
- import { run, readJSON, forTerminal, c, log, fail, hand, info, note } from './lib.mjs';
12
+ import { run, readJSON, forTerminal, c, log, fail, hand, info, note, warn } from './lib.mjs';
13
+ import { brandForPage } from './brand.mjs';
13
14
  import { productConfigPath } from './manifest.mjs';
14
15
  import { platformLogin } from './platform.mjs';
15
16
  import { readMembers, productIdentity } from './members.mjs';
16
17
  import { prTarget } from './pr-list.mjs';
17
18
  import { repoSources, whoseAccount } from './standup.mjs';
18
19
  import { api, httpStatus, shown, whyFailed, PAGE, TIMEOUT } from './protection.mjs';
19
- import { esc, writeReport } from './usage.mjs';
20
+ import { esc } from './usage.mjs';
21
+ import { writeOrSave } from './reports-dir.mjs';
20
22
  import { allLinks, combinedStage, epicStage, itemKey } from './issue-links.mjs';
21
23
 
22
24
  export const MAX_ITEMS = 1000;
@@ -71,6 +73,22 @@ export function pickType(labels, table) {
71
73
  return ordinary.value ? ordinary : pick(labels, part((f) => f));
72
74
  }
73
75
 
76
+ // #514 — what a label is to yad: one of its own (a priority, type or status spelling, or an item's `epic:` link) or
77
+ // any other. `owner` names which, so a write can say which flag sets it.
78
+ export function labelOwner(name, rules) {
79
+ const l = labelKey(name);
80
+ if (/^epic:/.test(l)) return 'epic';
81
+ for (const kind of ['priority', 'type', 'status']) if (Object.values(rules[kind]).some((names) => names.some((n) => labelKey(n) === l))) return kind;
82
+ return null;
83
+ }
84
+ // THE one way #514 compares two label names: as an item's labels are read (`clean`: control and invisible
85
+ // characters out, each run of spaces one space, trimmed), in any case. Every comparison of a name a person
86
+ // typed, an item carries, a repo has or a rule lists goes through it — two spellings of one rule let a
87
+ // double-spaced `priority: P1` past the refusal of yad's own labels (review 2).
88
+ export const labelKey = (name) => clean(name).toLowerCase();
89
+ // An item's labels that are none of yad's own, in the order the platform gave them.
90
+ export const otherLabels = (labels, rules) => labels.filter((l) => labelOwner(l, rules) === null);
91
+
74
92
  // ---- reading ---------------------------------------------------------------------------------------
75
93
 
76
94
  const str = (v) => (typeof v === 'string' && v ? v : null);
@@ -247,9 +265,13 @@ const list = (v) => String(v).split(',').map((x) => x.trim()).filter(Boolean);
247
265
  const lower = (v) => String(v).toLowerCase();
248
266
 
249
267
  // Narrow and sort. `mine` (from `--me`) is a map `platform\0host` → this person's login.
250
- export function applyFilters(items, { priority, type, status, assignee, repo, since, until, date = 'created', sort = 'priority', mine = null } = {}) {
268
+ // `label` (#514): each value is a comma list, and an item must carry one name of EVERY value — so
269
+ // `--label a --label b` asks for both and `--label a,b` for either. Whole names, any case.
270
+ export function applyFilters(items, { priority, type, status, assignee, repo, label = [], since, until, date = 'created', sort = 'priority', mine = null } = {}) {
251
271
  const inList = (want, v, none) => !want || list(want).map(lower).includes(lower(v ?? none));
252
- const out = items.filter((i) => inList(priority, i.priority, 'none') && inList(type, i.type, 'none') && inList(status, i.status, '') && inList(repo, i.repo, '')
272
+ const labelSets = (Array.isArray(label) ? label : [label]).filter((v) => v != null).map((v) => list(v).map(labelKey));
273
+ const hasLabels = (i) => { const have = new Set(i.labels.map(labelKey)); return labelSets.every((any) => any.some((n) => have.has(n))); };
274
+ const out = items.filter((i) => inList(priority, i.priority, 'none') && inList(type, i.type, 'none') && inList(status, i.status, '') && inList(repo, i.repo, '') && hasLabels(i)
253
275
  && (!assignee || (lower(assignee) === 'none' ? i.assignees.length === 0 : i.assignees.some((a) => [a.login, a.member].filter(Boolean).map(lower).includes(lower(assignee)))))
254
276
  && (!mine || i.assignees.some((a) => mine.get(`${i.platform}\0${i.host}`)?.toLowerCase() === a.login.toLowerCase()))
255
277
  && (!since || (i[date] && i[date] >= since)) && (!until || (i[date] && i[date] <= until)));
@@ -269,10 +291,14 @@ const who = (i) => (i.assignees.length ? i.assignees.map((a) => a.member || a.lo
269
291
  const counts = (s) => `${s.total} item${s.total === 1 ? '' : 's'}: ${STATUSES.map((v) => `${s.status[v]} ${v}`).join(', ')}; ${s.priority.none} with no priority, ${s.type.none} with no type, ${s.unassigned} unassigned`;
270
292
  const gaps = (m) => [...m.notRead, ...m.notes];
271
293
 
272
- function renderText(m) {
294
+ // An item's other labels as text, or '' (#514). Label names are the platform's text: `clean` made them safe to print.
295
+ const othersOf = (i, rules) => otherLabels(i.labels, rules);
296
+
297
+ function renderText(m, rules = labelRules(null)) {
273
298
  info(c.bold(counts(m.summary)));
274
299
  for (const i of m.items) {
275
- log(` ${i.ref.padEnd(14)} ${(i.priority ?? '--').padEnd(3)} ${(i.type ?? '-').padEnd(12)} ${i.status.padEnd(12)} ${who(i).padEnd(16)} ${i.title}${i.flags.length ? c.yellow(` [${i.flags.join('; ')}]`) : ''}`);
300
+ const others = othersOf(i, rules);
301
+ log(` ${i.ref.padEnd(14)} ${(i.priority ?? '--').padEnd(3)} ${(i.type ?? '-').padEnd(12)} ${i.status.padEnd(12)} ${who(i).padEnd(16)} ${i.title}${others.length ? c.dim(` {${others.join(', ')}}`) : ''}${i.flags.length ? c.yellow(` [${i.flags.join('; ')}]`) : ''}`);
276
302
  }
277
303
  if (!m.items.length) log(m.notRead.length ? ' nothing found in the repos that answered' : ' no items');
278
304
  for (const g of gaps(m)) note(c.yellow(g));
@@ -282,10 +308,10 @@ function renderText(m) {
282
308
  // are the triggers of GitHub's automatic links (`https:`, `www.`, an address's `@`).
283
309
  export const mdEscape = (s) => String(s ?? '').replace(/\r?\n/g, ' ').replace(/([\\`*_{}[\]()<>#|!~&:@])/g, '\\$1').replace(/(?<![a-z0-9])www\./gi, (w) => `${w.slice(0, 3)}\\.`);
284
310
 
285
- export function renderMarkdown(m) {
286
- const L = ['# Issues and work items', '', `- ${counts(m.summary)}`, `- Closed items since ${m.closedSince}`, '', '| Item | Priority | Type | Status | Assignee | Due | Title | Notes |', '|---|---|---|---|---|---|---|---|'];
311
+ export function renderMarkdown(m, rules = labelRules(null)) {
312
+ const L = ['# Issues and work items', '', `- ${counts(m.summary)}`, `- Closed items since ${m.closedSince}`, '', '| Item | Priority | Type | Status | Assignee | Due | Title | Labels | Notes |', '|---|---|---|---|---|---|---|---|---|'];
287
313
  for (const i of m.items) {
288
- L.push(`| ${i.url ? `[${mdEscape(i.ref)}](${i.url.replace(/[()|]/g, (ch) => `%${ch.charCodeAt(0).toString(16).toUpperCase()}`)})` : mdEscape(i.ref)} | ${i.priority ?? 'none'} | ${i.type ?? 'none'} | ${i.status} | ${mdEscape(who(i))} | ${i.due ?? ''} | ${mdEscape(i.title)} | ${mdEscape(i.flags.join('; '))} |`);
314
+ L.push(`| ${i.url ? `[${mdEscape(i.ref)}](${i.url.replace(/[()|]/g, (ch) => `%${ch.charCodeAt(0).toString(16).toUpperCase()}`)})` : mdEscape(i.ref)} | ${i.priority ?? 'none'} | ${i.type ?? 'none'} | ${i.status} | ${mdEscape(who(i))} | ${i.due ?? ''} | ${mdEscape(i.title)} | ${mdEscape(othersOf(i, rules).join(', '))} | ${mdEscape(i.flags.join('; '))} |`);
289
315
  }
290
316
  if (gaps(m).length) L.push('', '## Not read, or incomplete', '', ...gaps(m).map((g) => `- ${mdEscape(g)}`));
291
317
  L.push('', `_${FOOTER}_`, '');
@@ -296,24 +322,33 @@ const options = (values) => values.map((v) => `<option value="${esc(lower(v))}">
296
322
 
297
323
  // One self-contained file. The table is written here, escaped, and reads with scripting off. The script only
298
324
  // hides and re-orders those rows using their data attributes; it never builds markup from an item's text.
299
- export function renderHtml(m) {
325
+ // The page with the Product's brand (E184) added after its own CSS, so the brand's colours and fonts win.
326
+ export function renderHtml(m, rules = labelRules(null), { brandCss = '' } = {}) {
327
+ const html = renderHtmlPage(m, rules);
328
+ return brandCss ? html.replace('</style>', () => `\n${brandCss}\n</style>`) : html;
329
+ }
330
+ function renderHtmlPage(m, rules = labelRules(null)) {
300
331
  const people = [...new Set(m.items.flatMap((i) => i.assignees.map((a) => a.member || a.login)))].sort();
332
+ // #514: every other label seen, once each (the first spelling met), for the Label filter.
333
+ const labelNames = [...new Map(m.items.flatMap((i) => othersOf(i, rules)).map((l) => [lower(l), l]).reverse()).values()].sort((a, b) => lower(a).localeCompare(lower(b)));
301
334
  const repos = [...new Set(m.items.map((i) => i.repo))].sort();
302
335
  const cell = (label, inner, cls = '') => `<td data-label="${label}"${cls ? ` class="${cls}"` : ''}>${inner}</td>`;
303
336
  const row = (i) => {
304
337
  const members = i.assignees.map((a) => lower(a.member || a.login)).join('\n');
338
+ const others = othersOf(i, rules);
305
339
  const num = i.url ? `<a href="${esc(i.url)}" rel="noopener noreferrer">${esc(i.ref)}</a>` : esc(i.ref);
306
- return `<tr data-priority="${rank(PRIORITIES, i.priority)}" data-p="${esc(lower(i.priority ?? 'none'))}" data-type="${rank(ITEM_TYPES, i.type)}" data-t="${esc(lower(i.type ?? 'none'))}" data-status="${rank(STATUSES, i.status)}" data-s="${esc(i.status)}" data-repo="${esc(lower(i.repo))}" data-members="${esc(members)}" data-created="${esc(i.created ?? '')}" data-updated="${esc(i.updated ?? '')}" data-due="${esc(i.due ?? '')}" data-ref="${esc(i.ref)}">`
340
+ return `<tr data-priority="${rank(PRIORITIES, i.priority)}" data-p="${esc(lower(i.priority ?? 'none'))}" data-type="${rank(ITEM_TYPES, i.type)}" data-t="${esc(lower(i.type ?? 'none'))}" data-status="${rank(STATUSES, i.status)}" data-s="${esc(i.status)}" data-repo="${esc(lower(i.repo))}" data-members="${esc(members)}" data-l="${esc(others.map(lower).join('\n'))}" data-created="${esc(i.created ?? '')}" data-updated="${esc(i.updated ?? '')}" data-due="${esc(i.due ?? '')}" data-ref="${esc(i.ref)}">`
307
341
  + cell('Item', num, 'ref') + cell('Priority', i.priority ? `<span class="pri pri-${esc(lower(i.priority))}">${esc(i.priority)}</span>` : '<span class="dim">none</span>')
308
342
  + cell('Type', i.type ? esc(i.type) : '<span class="dim">none</span>') + cell('Status', `<span class="st st-${rank(STATUSES, i.status)}">${esc(i.status)}</span>`)
309
343
  + cell('Title', `${esc(i.title)}${i.flags.map((f) => `<span class="flag">${esc(f)}</span>`).join('')}`, 'title') + cell('Assignee', i.assignees.length ? esc(who(i)) : '<span class="dim">unassigned</span>')
344
+ + cell('Labels', others.length ? others.map((l) => `<span class="lbl">${esc(l)}</span>`).join(' ') : '<span class="dim">none</span>')
310
345
  + cell('Epic', i.epic ? esc(i.epic.id) : '<span class="dim">none</span>') + cell('Created', esc(i.created ?? ''), 'date') + cell('Updated', esc(i.updated ?? ''), 'date') + cell('Due', esc(i.due ?? ''), 'date') + '</tr>';
311
346
  };
312
347
  const th = (key, label) => `<th scope="col"${key ? ` aria-sort="none"` : ''}>${key ? `<button type="button" data-sort="${key}">${label}</button>` : label}</th>`;
313
348
  const select = (id, label, opts) => `<label>${label}<select id="${id}"><option value="">All</option>${opts}</select></label>`;
314
349
  const missing = gaps(m);
315
350
  return `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
316
- <meta http-equiv="Content-Security-Policy" content="default-src 'none'; style-src 'unsafe-inline'; script-src 'unsafe-inline'">
351
+ <meta http-equiv="Content-Security-Policy" content="default-src 'none'; style-src 'unsafe-inline'; script-src 'unsafe-inline'; img-src data:; font-src data:">
317
352
  <title>Issues and work items</title><style>
318
353
  :root{--bg:#fff;--fg:#1d2026;--dim:#5d6470;--card:#f6f7f9;--line:#e1e4ea;--link:#0b57d0;--warn:#8a4b00;--p0:#b3261e;--p1:#b3541e}
319
354
  @media (prefers-color-scheme:dark){:root{--bg:#0f1115;--fg:#e6e8ee;--dim:#9aa0ad;--card:#181b22;--line:#2b303a;--link:#8ab4f8;--warn:#f0b35a;--p0:#f28b82;--p1:#f6ae74}}
@@ -324,15 +359,15 @@ export function renderHtml(m) {
324
359
  .filters label{display:flex;flex-direction:column;font-size:12px;color:var(--dim);gap:2px}select,input,#reset{font:inherit;color:var(--fg);background:var(--bg);border:1px solid var(--line);border-radius:5px;padding:4px 6px;min-height:32px}#reset{align-self:flex-end;cursor:pointer}
325
360
  #count{margin:0 0 8px;color:var(--dim)}table{width:100%;border-collapse:collapse}th,td{text-align:left;padding:7px 8px;border-bottom:1px solid var(--line);vertical-align:top}th{font-size:12px;color:var(--dim);white-space:nowrap}th button{all:unset;cursor:pointer}th button:focus-visible{outline:2px solid var(--link)}
326
361
  [aria-sort=ascending] button::after{content:" ▲"}[aria-sort=descending] button::after{content:" ▼"}td.ref,td.date{white-space:nowrap}td.title{min-width:260px;overflow-wrap:anywhere}
327
- .pri{font-weight:600}.pri-p0{color:var(--p0)}.pri-p1{color:var(--p1)}.st{white-space:nowrap}.st-0{color:var(--dim)}.flag{display:block;color:var(--warn);font-size:12px}
362
+ .pri{font-weight:600}.pri-p0{color:var(--p0)}.pri-p1{color:var(--p1)}.st{white-space:nowrap}.st-0{color:var(--dim)}.flag{display:block;color:var(--warn);font-size:12px}.lbl{display:inline-block;border:1px solid var(--line);border-radius:10px;padding:0 6px;font-size:12px;white-space:nowrap}
328
363
  footer{color:var(--dim);font-size:12px;margin-top:20px;border-top:1px solid var(--line);padding-top:10px}
329
364
  @media (max-width:720px){thead{position:absolute;left:-9999px}tr{display:block;border:1px solid var(--line);border-radius:8px;margin:0 0 10px;padding:6px 10px}td{display:flex;gap:10px;border:0;padding:3px 0}td::before{content:attr(data-label);color:var(--dim);flex:0 0 72px;font-size:12px}td:empty{display:none}td.title{min-width:0;display:block}td.title::before{display:block}}
330
365
  </style></head><body><div class="wrap"><h1>Issues and work items</h1>
331
366
  <p class="sub">${esc(counts(m.summary))}. Closed items since ${esc(m.closedSince)}.</p>
332
367
  ${missing.length ? `<section class="gaps"><h2>Not read, or incomplete</h2><ul>${missing.map((g) => `<li>${esc(g)}</li>`).join('')}</ul></section>` : ''}
333
- <form class="filters" id="filters">${select('f-member', 'Member', `<option value="\n">Unassigned</option>${options(people)}`)}${select('f-t', 'Type', `${options(ITEM_TYPES)}<option value="none">None</option>`)}${select('f-p', 'Priority', `${options(PRIORITIES)}<option value="none">None</option>`)}${select('f-s', 'Status', options(STATUSES))}${select('f-repo', 'Repo', options(repos))}
368
+ <form class="filters" id="filters">${select('f-member', 'Member', `<option value="\n">Unassigned</option>${options(people)}`)}${select('f-t', 'Type', `${options(ITEM_TYPES)}<option value="none">None</option>`)}${select('f-p', 'Priority', `${options(PRIORITIES)}<option value="none">None</option>`)}${select('f-s', 'Status', options(STATUSES))}${select('f-repo', 'Repo', options(repos))}${select('f-l', 'Label', options(labelNames))}
334
369
  <label>Date<select id="f-date">${DATE_FIELDS.map((d) => `<option value="${d}">${d[0].toUpperCase()}${d.slice(1)}</option>`).join('')}</select></label><label>From<input type="date" id="f-from"></label><label>To<input type="date" id="f-to"></label><button type="reset" id="reset">Clear</button></form>
335
- <p id="count" role="status"></p><table><thead><tr>${th('ref', 'Item')}${th('priority', 'Priority')}${th('type', 'Type')}${th('status', 'Status')}${th('', 'Title')}${th('', 'Assignee')}${th('', 'Epic')}${th('created', 'Created')}${th('updated', 'Updated')}${th('due', 'Due')}</tr></thead>
370
+ <p id="count" role="status"></p><table><thead><tr>${th('ref', 'Item')}${th('priority', 'Priority')}${th('type', 'Type')}${th('status', 'Status')}${th('', 'Title')}${th('', 'Assignee')}${th('', 'Labels')}${th('', 'Epic')}${th('created', 'Created')}${th('updated', 'Updated')}${th('due', 'Due')}</tr></thead>
336
371
  <tbody id="rows">${m.items.map(row).join('\n')}</tbody></table>${m.items.length ? '' : `<p class="dim">${m.notRead.length ? 'Nothing found in the repos that answered.' : 'No items.'}</p>`}
337
372
  <footer>${esc(FOOTER)}</footer></div>
338
373
  <script>${PAGE_SCRIPT}</script></body></html>\n`;
@@ -340,13 +375,13 @@ ${missing.length ? `<section class="gaps"><h2>Not read, or incomplete</h2><ul>${
340
375
 
341
376
  // Fixed text: no value from an item is ever part of this script.
342
377
  const PAGE_SCRIPT = `(function(){var body=document.getElementById('rows'),rows=[].slice.call(body.rows),all=rows.length,$=function(i){return document.getElementById(i)},count=$('count');
343
- function apply(){var m=$('f-member').value,t=$('f-t').value,p=$('f-p').value,s=$('f-s').value,r=$('f-repo').value,d=$('f-date').value,a=$('f-from').value,b=$('f-to').value,n=0;rows.forEach(function(x){var v=x.dataset[d],on=(!t||x.dataset.t===t)&&(!p||x.dataset.p===p)&&(!s||x.dataset.s===s)&&(!r||x.dataset.repo===r)&&(!m||(m==='\\n'?x.dataset.members==='':x.dataset.members.split('\\n').indexOf(m)>=0))&&(!a||(v&&v>=a))&&(!b||(v&&v<=b));x.hidden=!on;if(on)n++});count.textContent='Showing '+n+' of '+all}
378
+ function apply(){var m=$('f-member').value,t=$('f-t').value,p=$('f-p').value,s=$('f-s').value,r=$('f-repo').value,l=$('f-l').value,d=$('f-date').value,a=$('f-from').value,b=$('f-to').value,n=0;rows.forEach(function(x){var v=x.dataset[d],on=(!t||x.dataset.t===t)&&(!p||x.dataset.p===p)&&(!s||x.dataset.s===s)&&(!r||x.dataset.repo===r)&&(!l||x.dataset.l.split('\\n').indexOf(l)>=0)&&(!m||(m==='\\n'?x.dataset.members==='':x.dataset.members.split('\\n').indexOf(m)>=0))&&(!a||(v&&v>=a))&&(!b||(v&&v<=b));x.hidden=!on;if(on)n++});count.textContent='Showing '+n+' of '+all}
344
379
  var form=$('filters');form.addEventListener('input',apply);form.addEventListener('change',apply);form.addEventListener('reset',function(){setTimeout(apply,0)});form.addEventListener('submit',function(e){e.preventDefault()});
345
380
  var num={priority:1,type:1,status:1};document.querySelectorAll('[data-sort]').forEach(function(btn){btn.addEventListener('click',function(){var k=btn.dataset.sort,th=btn.parentNode,up=th.getAttribute('aria-sort')!=='ascending';document.querySelectorAll('th[aria-sort]').forEach(function(h){h.setAttribute('aria-sort','none')});th.setAttribute('aria-sort',up?'ascending':'descending');rows.sort(function(x,y){var a=x.dataset[k],b=y.dataset[k];if(!a!==!b)return a?-1:1;var c=num[k]?a-b:a.localeCompare(b,undefined,{numeric:true});return up?c:-c});rows.forEach(function(x){body.appendChild(x)})})});apply()})();`;
346
381
 
347
382
  // ---- the commands ----------------------------------------------------------------------------------
348
383
 
349
- const LIST_ONLY = new Set(['--priority', '--type', '--status', '--assignee', '--me', '--repo', '--since', '--until', '--date', '--sort', '--closed-since', '--format', '--out', '--json', '--dir']);
384
+ const LIST_ONLY = new Set(['--priority', '--type', '--status', '--label', '--assignee', '--me', '--repo', '--since', '--until', '--date', '--sort', '--closed-since', '--format', '--out', '--json', '--dir']);
350
385
  // The Markdown link of an item's URL, with the characters that would end it encoded.
351
386
  export const mdUrl = (u) => u.replace(/[()|]/g, (ch) => `%${ch.charCodeAt(0).toString(16).toUpperCase()}`);
352
387
 
@@ -372,12 +407,14 @@ function closedSince(value, now) {
372
407
  }
373
408
 
374
409
  // `yad issues [list]`. Returns the model (E1 makes it the `--json` answer), or undefined after refusing.
375
- export async function runIssuesList(root, { priority = null, type = null, status = null, assignee = null, me = false, repo = null, since = null, until = null, date = null, sort = null, closedSince: closed = null, format = null, out = null, json = false, now = Date.now(), env = process.env, runner, loginOf = platformLogin } = {}) {
410
+ export async function runIssuesList(root, { priority = null, type = null, status = null, label = [], assignee = null, me = false, repo = null, since = null, until = null, date = null, sort = null, closedSince: closed = null, format = null, out = null, json = false, now = Date.now(), env = process.env, runner, loginOf = platformLogin } = {}) {
376
411
  const refuse = (msg, hint) => { fail(msg); if (hint) hand(hint); process.exitCode = 1; };
377
412
  if (!fs.existsSync(productConfigPath(root))) return refuse('not a Product (no .sdlc/product.json here)', 'run it from the Product, or pass --dir');
378
413
  if (!format && out) format = /\.html?$/i.test(out) ? 'html' : 'md';
379
414
  if (format && !['md', 'html'].includes(format)) return refuse(`unknown --format ${forTerminal(String(format))}`, 'use --format md or --format html (or --json for the data)');
380
415
  if (assignee && me) return refuse('pass --assignee <login> or --me, not both');
416
+ const labels = (Array.isArray(label) ? label : [label]).filter((v) => v != null);
417
+ if (labels.some((v) => !list(v).length)) return refuse('--label needs a label name', 'pass --label <name>; repeat it to ask for more than one, or give a comma list for any of them');
381
418
  for (const bad of [checkValues('--priority', priority, [...PRIORITIES, 'none']), checkValues('--type', type, [...ITEM_TYPES, 'none']), checkValues('--status', status, STATUSES), oneValue('--sort', sort, SORTS), oneValue('--date', date, DATE_FIELDS)]) if (bad) return refuse(bad);
382
419
  for (const [flag, v] of [['--since', since], ['--until', until]]) if (v && !realDate(v)) return refuse(`${flag} must be a real date, YYYY-MM-DD (got ${forTerminal(String(v))})`);
383
420
  const window = closedSince(closed, now);
@@ -400,16 +437,21 @@ export async function runIssuesList(root, { priority = null, type = null, status
400
437
  const bad = list(repo).filter((v) => !known.map(lower).includes(lower(v)));
401
438
  if (bad.length) return refuse(`no repo named ${forTerminal(bad.join(', '))}`, `use one of: ${known.join(', ')}`);
402
439
  }
403
- const items = applyFilters(whole.items, { priority, type, status, assignee, repo, since, until, date: date ? lower(date) : 'created', sort: sort ? lower(sort) : 'priority', mine });
440
+ const items = applyFilters(whole.items, { priority, type, status, label: labels, assignee, repo, since, until, date: date ? lower(date) : 'created', sort: sort ? lower(sort) : 'priority', mine });
404
441
  const model = { ...whole, items, summary: summarize(items), unfiltered: whole.items.length };
442
+ const rules = labelRules(readJSON(productConfigPath(root), null));
405
443
  if (format) {
406
- const dest = out || `issues-report.${format}`;
407
- writeReport(dest, format === 'md' ? renderMarkdown(model) : renderHtml(model));
444
+ // E180: with no --out, saved in the local reports folder, named by the repos it covers and its count.
445
+ const scope = repo ? list(repo).join(' ') : 'all repos';
446
+ const saved = writeOrSave(root, { out, kind: 'issues', scope, state: `${items.length} items`, ext: format, content: format === 'md' ? renderMarkdown(model, rules) : renderHtml(model, rules, { brandCss: brandForPage(root, 'issues').css }), command: 'issues list', env });
447
+ if (saved.problem) return refuse(saved.problem);
448
+ for (const w of saved.warnings) warn(w);
449
+ const dest = saved.file;
408
450
  if (json) note(`wrote ${format.toUpperCase()} report → ${dest}`); else info(`wrote ${format.toUpperCase()} report → ${c.bold(dest)}`);
409
451
  for (const g of gaps(model)) if (!json) note(c.yellow(g));
410
452
  return { ...model, out: dest };
411
453
  }
412
- if (!json) renderText(model);
454
+ if (!json) renderText(model, rules);
413
455
  return { ...model, out: null };
414
456
  }
415
457
 
@@ -418,11 +460,14 @@ export function readLabels(t, runner) {
418
460
  const gh = t.platform === 'github';
419
461
  const at = gh ? `repos/${t.repo}/labels?per_page=${PAGE}` : `projects/${encodeURIComponent(t.repo)}/labels?per_page=${PAGE}`;
420
462
  const names = new Set();
463
+ // #514: `keys` and `real` are by `labelKey`; `names` stays lower-cased only, as its other callers read it.
464
+ const keys = new Set();
465
+ const real = new Map(); // labelKey → the repo's own spelling, so a label is added and removed as the repo spells it
421
466
  for (let page = 1; page <= MAX_PAGES; page++) {
422
467
  const res = api(runner, t.cli, t.host, `${at}&page=${page}`);
423
468
  if (!res.ok || !Array.isArray(res.body)) return { ok: false, why: whyFailed(res.ok ? { unreadable: true } : res, { platform: t.platform, host: t.host, what: `the labels of ${shown(t.repo)}`, plural: true }) };
424
- for (const l of res.body) if (typeof l?.name === 'string') names.add(l.name.toLowerCase());
425
- if (res.body.length < PAGE) return { ok: true, names };
469
+ for (const l of res.body) if (typeof l?.name === 'string') { names.add(l.name.toLowerCase()); const k = labelKey(l.name); keys.add(k); if (!real.has(k)) real.set(k, l.name); }
470
+ if (res.body.length < PAGE) return { ok: true, names, keys, real };
426
471
  }
427
472
  return { ok: false, why: `${shown(t.repo)} has more labels than yad reads` };
428
473
  }
package/cli/lib.mjs CHANGED
@@ -403,14 +403,49 @@ export function run(cmd, args = [], opts = {}) {
403
403
  // --json run its stdout is our stderr instead (E1).
404
404
  const stdio = jsonRun && opts.stdio === 'inherit' ? ['inherit', 2, 'inherit'] : opts.stdio;
405
405
  const r = spawnSync(cmd, args, { encoding: 'utf8', ...opts, ...(stdio === undefined ? {} : { stdio }) });
406
+ const ok = r.status === 0;
407
+ let stderr = (r.stderr || '').trim();
408
+ // git too (#526): with glab as git's login helper (`glab auth login`), git passes glab's warning through on a
409
+ // push, fetch, pull, ls-remote or clone.
410
+ if (/^(?:glab|git)(?:\.exe)?$/i.test(path.basename(String(cmd)))) stderr = withoutGlabConfigWarning(stderr, { ok });
406
411
  return {
407
- ok: r.status === 0,
412
+ ok,
408
413
  code: r.status,
409
414
  stdout: (r.stdout || '').trim(),
410
- stderr: (r.stderr || '').trim(),
415
+ stderr,
411
416
  error: r.error,
412
417
  };
413
418
  }
419
+
420
+ // #509 — glab with more than one config file prints a warning block on EVERY run, before its own output:
421
+ // Warning: Multiple config files found. Only the first one will be used.
422
+ // Using: <file>
423
+ // Ignoring: <file>
424
+ // Consider consolidating to one location to avoid confusion.
425
+ // It is not an error (the run still exits 0 when it works), but every caller that shows stderr as the
426
+ // reason cuts that reason short, so the warning was all a person saw and the real error was cut off. So the
427
+ // block is dropped from what yad reads. When the run FAILED, one short line goes BEFORE the real error
428
+ // instead, because a login saved in the ignored file is not used — often the very reason the run failed — and
429
+ // a line after glab's long error would be cut off. It shares its line with the error's first line, so a caller
430
+ // that shows only stderr's first line still shows the error. Only that exact block is removed. git's own calls get
431
+ // the same (#526): git passes its login helper's stderr through, and that helper can be glab.
432
+ export function withoutGlabConfigWarning(stderr = '', { ok = true } = {}) {
433
+ const lines = String(stderr).split('\n');
434
+ const isStart = (l) => /^Warning: Multiple config files found\b/i.test(l.trim());
435
+ if (!lines.some(isStart)) return stderr;
436
+ // Every block: one git push runs its login helper more than once (`get`, then `store` or `erase`), and glab
437
+ // prints the block each time (#526 review).
438
+ const kept = [];
439
+ for (let i = 0; i < lines.length; i++) {
440
+ if (!isStart(lines[i])) { kept.push(lines[i]); continue; }
441
+ while (i + 1 < lines.length && /^\s+(?:Using|Ignoring):/.test(lines[i + 1])) i += 1;
442
+ if (i + 1 < lines.length && /^Consider consolidating\b/i.test(lines[i + 1].trim())) i += 1;
443
+ }
444
+ const rest = kept.join('\n').trim();
445
+ if (ok) return rest;
446
+ const hint = 'glab reads only one of its two config files, so a login saved in the other is not used (see `yad doctor`, glab-config)';
447
+ return rest ? `${hint} — ${rest}` : hint;
448
+ }
414
449
  export const has = (cmd) => run(process.platform === 'win32' ? 'where' : 'which', [cmd]).ok;
415
450
 
416
451
  // An npm launcher (`npm`, `npx`) is a `.cmd` file on Windows, which Node will not start without a shell