@accord-dev/accord 0.9.0 → 0.9.1

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 (3) hide show
  1. package/README.md +12 -12
  2. package/dist/cli.js +1834 -1760
  3. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -21506,16 +21506,18 @@ function configLists(text) {
21506
21506
  sensitive
21507
21507
  };
21508
21508
  }
21509
+ /** The shape of the `accord` pin in schemas/config.schema.json (U-1: keep the two the same). */
21510
+ const PIN_SHAPE = /^[0-9]+\.[0-9]+\.[0-9]+(?:-[0-9A-Za-z.-]+)?$/;
21509
21511
  /**
21510
- * Phase 8.1 D-18: the `accord` pin of a config text, read without validating it against this CLI's schema, so a config that carries a key a newer
21511
- * release added (the schemas refuse unknown keys) still gives the pin the audit reports. Never throws; no text, text that is not a mapping, or a pin that is not a string gives undefined.
21512
+ * Phase 8.1 D-18: the `accord` pin of a config text, read without validating the rest of it against this CLI's schema, so a config that carries a key a newer
21513
+ * release added (the schemas refuse unknown keys) still gives the pin the audit reports. Never throws; no text, text that is not a mapping, a pin that is not a string, or a string that is not a version gives undefined.
21512
21514
  */
21513
21515
  function configPin(text) {
21514
21516
  if (text === void 0) return void 0;
21515
21517
  try {
21516
21518
  const { map } = parseYamlMap("accord/config.yml", normaliseText(text), 0);
21517
21519
  const pin = map?.accord;
21518
- return typeof pin === "string" ? pin : void 0;
21520
+ return typeof pin === "string" && PIN_SHAPE.test(pin) ? pin : void 0;
21519
21521
  } catch {
21520
21522
  return;
21521
21523
  }
@@ -22804,6 +22806,7 @@ const CHAIN_REASON = "three or more repeats in a row can match the same text, so
22804
22806
  * Why a line regex can backtrack catastrophically, with how to rewrite it; undefined when the guard finds nothing. `source` has already compiled, `flags` is '' or 'i'.
22805
22807
  * Not a proof: it refuses every shape measured exponential in V8 and every run of three overlapping repeats, and accepts every default and every pattern measured linear.
22806
22808
  * What it accepts is at most two overlapping repeats in a row and at most 16 routes, which the scan bounds per changed line (SCAN_LINE_LIMIT).
22809
+ * Every caller must bound the text the same way: the commit rule fails a first line over SCAN_LINE_LIMIT before it matches (commits/rule.ts).
22807
22810
  */
22808
22811
  function backtrackProblem(source, flags) {
22809
22812
  let auto;
@@ -24357,795 +24360,1179 @@ function forbiddenLines(message) {
24357
24360
  }
24358
24361
  const trailerReason = (sha, line) => `commit ${sha.slice(0, 12)} carries the forbidden line "${line}"; commits.trailers is forbid in accord/config.yml`;
24359
24362
  /**
24360
- * Conventional Commits 1.0.0 shape of a first line, rules 1, 4, 14 and 15: a type, an optional parenthesised scope, an optional `!`, a colon and a space, then a description.
24361
- * The type set is open on purpose (rule 14 allows types beyond feat and fix), so accord's own bookkeeping subjects (`claim: <id>`, `plan: <id> ready`, ...) pass the preset.
24362
- * Case-insensitive (rule 15). Run through `backtrackProblem`: no finding.
24363
- */
24364
- const CONVENTIONAL_PATTERN = String.raw`^[a-z][a-z0-9-]*(?:\([^()\r\n]+\))?!?: \S.*$`;
24365
- function commitRuleOf(config) {
24366
- const m = config?.commits?.message;
24367
- if (m === void 0) return void 0;
24368
- if (m.preset === "conventional") return {
24369
- regex: new RegExp(CONVENTIONAL_PATTERN, "i"),
24370
- text: "commits.message.preset conventional",
24371
- example: m.example ?? "feat(cart): add coupon field"
24372
- };
24373
- if (m.pattern === void 0) return void 0;
24374
- const text = `commits.message.pattern /${m.pattern}/`;
24375
- let regex;
24376
- try {
24377
- regex = new RegExp(m.pattern);
24378
- } catch (e) {
24379
- return { problem: `${text} does not compile: ${e instanceof Error ? e.message : String(e)}` };
24380
- }
24381
- const slow = backtrackProblem(m.pattern, "");
24382
- if (slow !== void 0) return { problem: `${text} can be very slow on some lines: ${slow}` };
24383
- return {
24384
- regex,
24385
- text,
24386
- example: m.example ?? ""
24387
- };
24388
- }
24389
- /** The first line of a message: a byte order mark dropped, CRLF read as LF. The body is free. */
24390
- const firstLine$1$1 = (message) => message.replace(/^\uFEFF/, "").replace(/\r\n/g, "\n").split("\n")[0] ?? "";
24391
- /** A commit subject on its way to a terminal: every control, invisible format and separator character written as `<U+XXXX>`, so a subject cannot hide or reorder what the reader sees (T-08.1-04). */
24392
- const visible$1 = (text) => text.replace(/[\p{Cc}\p{Cf}\p{Zl}\p{Zp}]/gu, (ch) => "<U+" + (ch.codePointAt(0) ?? 0).toString(16).toUpperCase().padStart(4, "0") + ">");
24393
- /**
24394
- * Why `message` breaks `rule`, or undefined when it passes. Merge commits and commits already on the default branch are exempt by the caller (they are never offered here);
24395
- * a subject that starts `Revert "` is git's own revert subject and passes, so the executor's `git revert` of its own fix never blocks task-done.
24396
- */
24397
- function commitRuleProblem(rule, message) {
24398
- const subject = firstLine$1$1(message);
24399
- if (subject.startsWith("Revert \"")) return void 0;
24400
- return rule.regex.test(subject) ? void 0 : `"${visible$1(subject)}" does not match ${rule.text}`;
24401
- }
24402
- /**
24403
- * The one reason task-done prints and `gate.commit-message` reports for a commit that breaks the rule (D-07: every refusal names its fix). A commit accord wrote from a
24404
- * `commits.subjects` template is fixed at the template first, and `accord lint` names the key and one that passes; a code commit is reworded.
24363
+ * The entries of the ticket's `research:` key that are Markdown records under accord/research/ and that the branch
24364
+ * adds (relative to the merge base). Empty when the ticket, the branch fact or its changes are missing.
24405
24365
  */
24406
- function commitRuleRefusal(sha, problem) {
24407
- return `commit ${sha.slice(0, 8)} ${problem} - fix: reword it so its first line passes (check the message first with accord commit check <file>); for a subject accord wrote from a commits.subjects template, set that template first (accord lint names the key and one that passes), then reword the commit to what accord subject <name> <id> prints`;
24408
- }
24409
- /** The reason when `commits.message` cannot be put in force (D-04: a broken rule never passes silently): it names `accord lint`, which reports the pattern. */
24410
- const commitRuleNotInForce = (problem) => `${problem} - fix: run accord lint, which names the pattern to change; until it is in force no commit is judged, so the gate fails closed`;
24411
- /** One line naming the rule, for the brief and the anchor. */
24412
- function commitRuleLine(rule) {
24413
- return `the first line of every commit message matches ${rule.text}`;
24366
+ function addedResearch(snapshot, id) {
24367
+ const listed = (Object.hasOwn(snapshot.tickets, id) ? snapshot.tickets[id] : void 0)?.frontmatter?.research;
24368
+ const facts = snapshot.branchFacts;
24369
+ const fact = facts !== void 0 && Object.hasOwn(facts, id) ? facts[id] : void 0;
24370
+ if (listed === void 0 || fact === void 0 || "error" in fact || !Array.isArray(fact.changes)) return [];
24371
+ const added = new Set(fact.changes.filter((c) => c.kind === "added").map((c) => c.path));
24372
+ return listed.filter((p) => isResearchRecord(p) && added.has(p));
24414
24373
  }
24415
- const ticketFile$6 = (id) => "accord/tickets/" + id + ".md";
24416
- const verificationFile = (id) => "accord/tickets/" + id + "/verification.md";
24417
- const ticketOf$2 = (snapshot, id) => Object.hasOwn(snapshot.tickets, id) ? snapshot.tickets[id] : void 0;
24418
- const verificationOf$1 = (snapshot, id) => Object.hasOwn(snapshot.verifications, id) ? snapshot.verifications[id] : void 0;
24419
- /** The `## Acceptance criteria` heading line, or undefined when the ticket has no such section. */
24420
- const acLine = (snapshot, id) => ticketOf$2(snapshot, id)?.sections.find((s) => headingKey(s.heading) === "acceptance criteria")?.line;
24421
- const at = (line) => line === void 0 ? {} : { line };
24422
- /** Distinct `ac-n` tags sorted by their numeric part, so a reason reads the same on every host. */
24423
- const tagsOf = (tags) => [...new Set(tags)].sort((a, b) => Number(a.slice(3)) - Number(b.slice(3)));
24424
- /** `nothing` for an empty list, otherwise the `@ac-n` tokens in numeric order. */
24425
- const fmt = (tags) => tags.length === 0 ? "nothing" : tags.map((t) => "@" + t).join(" ");
24426
- const scenarioTags = (snapshot, id) => tagsOf((ticketOf$2(snapshot, id)?.scenarios ?? []).flatMap((s) => s.acTag === void 0 ? [] : [s.acTag]));
24427
- const evidenceTags = (snapshot, id) => tagsOf((verificationOf$1(snapshot, id)?.blocks ?? []).map((b) => b.acTag));
24428
- const tickTags = (snapshot, id) => tagsOf(ticketOf$2(snapshot, id)?.frontmatter?.verified ?? []);
24429
- /** D-81: at least 7 characters and every one of them hexadecimal. Shorter values never compare equal. */
24430
- function isSha(v) {
24431
- return v.length >= 7 && /^[0-9a-fA-F]+$/.test(v);
24374
+ /** Untraced report case ids, sorted in code-point order; [] when no report is loaded. */
24375
+ function untracedTests(snapshot) {
24376
+ if (snapshot.tests === void 0) return [];
24377
+ const named = new Set(Object.values(snapshot.tickets).flatMap((t) => t.scenarios.flatMap((s) => s.tags.filter((x) => x.startsWith("@test:")).map((x) => x.slice(6)))));
24378
+ const baseline = new Set(snapshot.testsBaseline ?? []);
24379
+ return Object.keys(snapshot.tests).filter((id) => !named.has(id) && !baseline.has(id) && !id.includes("risk:")).sort();
24432
24380
  }
24381
+ const UNTRACED = (id) => `test "${id}" is named by no scenario's @test:, carries no risk:, and is not in accord/tests-baseline.txt`;
24433
24382
  /**
24434
- * D-81: equal when, compared case-insensitively, the shorter is a prefix of the longer and both are
24435
- * shas. git abbreviates to variable lengths, so a 7-character value must match a 40-character one.
24383
+ * Silent until the repository holds a lane M, L or P ticket: that ticket opts the repository into the policy; a lane S or lane R
24384
+ * (ST-LN-94 D-10) ticket alone does not.
24436
24385
  */
24437
- function shaEqual(a, b) {
24438
- if (!isSha(a) || !isSha(b)) return false;
24439
- const x = a.toLowerCase();
24440
- const y = b.toLowerCase();
24441
- return x.length <= y.length ? y.startsWith(x) : x.startsWith(y);
24442
- }
24386
+ const OPTS_IN = [
24387
+ "M",
24388
+ "L",
24389
+ "P"
24390
+ ];
24391
+ const testUntraced = (snapshot) => {
24392
+ const report = snapshot.config?.tests?.report;
24393
+ if (report === void 0 || !Object.values(snapshot.tickets).some((t) => OPTS_IN.includes(t.frontmatter?.lane ?? ""))) return [];
24394
+ return untracedTests(snapshot).map((id) => ({
24395
+ file: normaliseKey(report),
24396
+ reason: UNTRACED(id)
24397
+ }));
24398
+ };
24399
+ const planFile = (id) => "accord/tickets/" + id + "/plan.md";
24400
+ const ledgerFile = (id) => "accord/tickets/" + id + "/ledger.md";
24401
+ const reviewFile = (id) => "accord/tickets/" + id + "/review.md";
24402
+ /** Spec §10: the two review verdicts Done accepts. */
24403
+ const VERDICTS = ["converged", "accepted-by-owner"];
24404
+ /** `Object.hasOwn`, never `in`: the id is caller-supplied. */
24405
+ const workOf = (snapshot, id) => snapshot.work !== void 0 && Object.hasOwn(snapshot.work, id) ? snapshot.work[id] : void 0;
24406
+ /** The ticket when it exists and carries `lane:`; every workflow-layer rule is silent otherwise. */
24407
+ const laneTicket = (snapshot, id) => {
24408
+ const t = Object.hasOwn(snapshot.tickets, id) ? snapshot.tickets[id] : void 0;
24409
+ return t?.frontmatter?.lane === void 0 ? void 0 : t;
24410
+ };
24443
24411
  /**
24444
- * GATE-02 empty set: three empty sets are trivially equal, which would let a ticket with no scenario
24445
- * pass Done vacuously. This fires on every ticket type, so an `epic` cannot slip through either.
24412
+ * The debug.md of a lane ticket other than lane S and lane R (the lanes that run the debug stage) whose last open episode still starts with UNFINISHED_MARKER; undefined otherwise. No gate
24413
+ * refuses it: it is the source of the `Unfinished:` line of `accord anchor` (status/anchor.ts) for the debug stage.
24446
24414
  */
24447
- const noScenarios$1 = (snapshot, id) => {
24448
- if (ticketOf$2(snapshot, id) === void 0 || scenarioTags(snapshot, id).length > 0) return [];
24449
- return [{
24450
- file: ticketFile$6(id),
24451
- ...at(acLine(snapshot, id)),
24452
- reason: "no scenario carries an @ac-n tag, so Done has nothing to be claimed about"
24415
+ const unfinishedDebug = (snapshot, id) => {
24416
+ const debug = stageLaneTicket(snapshot, id) === void 0 ? void 0 : workOf(snapshot, id)?.debug;
24417
+ return debug?.unfinished === void 0 ? void 0 : debug;
24418
+ };
24419
+ /** Spec §8: every planned task has a completion line written by `accord task-done`. */
24420
+ const tasksIncomplete = (snapshot, id) => {
24421
+ if (laneTicket(snapshot, id) === void 0) return [];
24422
+ const work = workOf(snapshot, id);
24423
+ if (work?.plan === void 0) return [{
24424
+ file: planFile(id),
24425
+ reason: "no plan; Done needs every planned task recorded in " + ledgerFile(id)
24426
+ }];
24427
+ if (work.plan.tasks.length === 0) return [{
24428
+ file: planFile(id),
24429
+ reason: "the plan has no tasks; Done needs every planned task recorded in " + ledgerFile(id)
24453
24430
  }];
24431
+ const done = work.ledger?.done ?? {};
24432
+ return work.plan.tasks.filter((t) => !Object.hasOwn(done, String(t.n))).map((t) => ({
24433
+ file: planFile(id),
24434
+ line: t.line,
24435
+ reason: `task ${t.n} has no completion line in ${ledgerFile(id)}; run accord task-done ${id} ${t.n}`
24436
+ }));
24454
24437
  };
24455
- /**
24456
- * GATE-02: the scenario tags, the `## @ac-n` evidence blocks, and `verified` must be the same set.
24457
- * One finding naming each side's gap, mirroring lint.plan-tags-differ, in the fixed order scenarios,
24458
- * evidence, verified. `noScenarios` owns the all-empty case.
24459
- */
24460
- const tagsDiffer = (snapshot, id) => {
24461
- if (ticketOf$2(snapshot, id) === void 0) return [];
24462
- const scenarios = scenarioTags(snapshot, id);
24463
- const evidence = evidenceTags(snapshot, id);
24464
- const verified = tickTags(snapshot, id);
24465
- const union = tagsOf([
24466
- ...scenarios,
24467
- ...evidence,
24468
- ...verified
24469
- ]);
24470
- if (union.length === 0 || [
24471
- scenarios,
24472
- evidence,
24473
- verified
24474
- ].every((s) => s.length === union.length)) return [];
24475
- const lacks = (set) => fmt(union.filter((t) => !set.includes(t)));
24438
+ /** Spec §10: there is no Done without a review record. */
24439
+ const reviewMissing = (snapshot, id) => {
24440
+ if (laneTicket(snapshot, id) === void 0 || workOf(snapshot, id)?.review !== void 0) return [];
24476
24441
  return [{
24477
- file: ticketFile$6(id),
24478
- ...at(acLine(snapshot, id)),
24479
- reason: `scenarios lack ${lacks(scenarios)}; evidence lacks ${lacks(evidence)}; verified lacks ${lacks(verified)}`
24442
+ file: reviewFile(id),
24443
+ reason: "no review record; Done needs " + reviewFile(id)
24480
24444
  }];
24481
24445
  };
24482
- /** docs/design.md §5: the Fresh-context layer needs a review record; there is no Done without one. */
24483
- const verificationMissing = (snapshot, id) => {
24484
- if (ticketOf$2(snapshot, id) === void 0 || verificationOf$1(snapshot, id) !== void 0) return [];
24446
+ /** Spec §10: the review loop ended in convergence, or the owner accepted it at the cap. */
24447
+ const reviewUnconverged = (snapshot, id) => {
24448
+ const review = laneTicket(snapshot, id) === void 0 ? void 0 : workOf(snapshot, id)?.review;
24449
+ if (review === void 0 || VERDICTS.includes(review.verdict ?? "")) return [];
24485
24450
  return [{
24486
- file: verificationFile(id),
24487
- reason: "no review record; Done needs " + verificationFile(id)
24451
+ file: review.file,
24452
+ ...review.line === void 0 ? {} : { line: review.line },
24453
+ reason: review.verdict === void 0 ? "the review record has no verdict: line" : `the review verdict is "${review.verdict}"; Done needs converged or accepted-by-owner`
24488
24454
  }];
24489
24455
  };
24490
24456
  /**
24491
- * The ticket when it carries `lane:` other than S and R: the lanes whose gate tables hold the plan, Done and debug rules of lane M, so the ones the unfinished-marker rules apply to (unfinishedPlan, unfinishedVerification
24492
- * and unfinishedDebug; ST-LN-72 review round 2). The one lane test of the three. It lives here, and work.ts re-exports it next to laneTicket, because work.ts imports this file.
24493
- */
24494
- const stageLaneTicket = (snapshot, id) => {
24495
- const t = ticketOf$2(snapshot, id);
24496
- const lane = t?.frontmatter?.lane;
24497
- return lane === void 0 || lane === "S" || lane === "R" ? void 0 : t;
24498
- };
24499
- /**
24500
- * The verification.md of a lane ticket that runs the Done table of lane M (stageLaneTicket) and still carries UNFINISHED_MARKER; undefined otherwise. The one predicate for gate done's refusal and for the
24501
- * Unfinished line of `accord anchor` (status/anchor.ts).
24502
- */
24503
- const unfinishedVerification = (snapshot, id) => {
24504
- const v = verificationOf$1(snapshot, id);
24505
- return v?.unfinished === void 0 || stageLaneTicket(snapshot, id) === void 0 ? void 0 : v;
24506
- };
24507
- /**
24508
- * ST-LN-72 D-11 and D-18: a verification.md that still carries UNFINISHED_MARKER is a record the verifier has not finished, so it never passes Done, at any strictness setting (the rule is on the
24509
- * floor, gate/floor.ts). A lane M, L or P ticket, whatever its claim pin: the owner's decision of 2026-11-16, an exception to D-16 (only a 0.6.0 agent writes the marker, so a ticket claimed earlier cannot be
24510
- * refused wrongly, and exempting it would let a stalled agent's half-written record through after an upgrade).
24511
- * It reads no `config.runtimes`: the rule is a CLI check, so it holds in all four tools whether or not an accord agent is installed.
24457
+ * Spec §11: the report is the full suite's output, and any failed case fails Done. A lane ticket needs a
24458
+ * loaded report even when every scenario is @ui, so an all-@ui ticket cannot pass with no suite at all.
24512
24459
  */
24513
- const verificationUnfinished = (snapshot, id) => {
24514
- const v = unfinishedVerification(snapshot, id);
24515
- if (v?.unfinished === void 0) return [];
24460
+ const suiteNotPassed = (snapshot, id) => {
24461
+ if (laneTicket(snapshot, id) === void 0) return [];
24462
+ const report = reportPath$1(snapshot);
24463
+ if (report === void 0) return [{
24464
+ file: "accord/config.yml",
24465
+ pointer: "/tests",
24466
+ reason: "no test report is configured; Done for a lane ticket needs the full suite's report in tests.report"
24467
+ }];
24468
+ if (!reportLoaded(snapshot)) return [{
24469
+ file: "accord/config.yml",
24470
+ pointer: "/tests/report",
24471
+ reason: `no report at ${normaliseKey(report)}; Done for a lane ticket needs the full suite's report`
24472
+ }];
24473
+ const tests = snapshot.tests ?? {};
24474
+ const failed = Object.keys(tests).filter((k) => tests[k] === "failed").sort();
24475
+ if (failed.length === 0) return [];
24476
+ const shown = failed.slice(0, 5).join(", ") + (failed.length > 5 ? ", ..." : "");
24516
24477
  return [{
24517
- file: v.file,
24518
- line: v.unfinished,
24519
- reason: `${v.file} still carries the line ${UNFINISHED_MARKER}: the verifier has not finished; the verify stage resumes it, or starts it over when HEAD moved`
24478
+ file: normaliseKey(report),
24479
+ reason: `${failed.length} test case${failed.length === 1 ? "" : "s"} failed in the report: ${shown}`
24520
24480
  }];
24521
24481
  };
24522
- /** docs/design.md §5: `blocked` fails Done exactly as `fail` does. A missing or invalid `Result:` is
24523
- * already load.result-invalid at error in ticket scope, so it needs no rule here (D-58). */
24524
- const resultNotPass = (snapshot, id) => {
24525
- const v = verificationOf$1(snapshot, id);
24526
- if (v === void 0) return [];
24527
- return v.blocks.filter((b) => b.result === "fail" || b.result === "blocked").map((b) => ({
24528
- file: v.file,
24529
- line: b.line,
24530
- reason: `evidence block "@${b.acTag}" records Result: ${b.result}`
24482
+ /** Spec §9 at Done: the warning lint gives becomes an error for a lane ticket. */
24483
+ const testUntracedAtDone = (snapshot, id) => {
24484
+ const report = reportPath$1(snapshot);
24485
+ if (laneTicket(snapshot, id) === void 0 || report === void 0 || !reportLoaded(snapshot)) return [];
24486
+ return untracedTests(snapshot).map((t) => ({
24487
+ file: normaliseKey(report),
24488
+ reason: UNTRACED(t)
24531
24489
  }));
24532
24490
  };
24533
- const frontmatterOf = (snapshot, id) => ticketOf$2(snapshot, id)?.frontmatter;
24534
- /** The AC hash as it stands now; undefined only when no scenario carries an `@ac-n` tag (`noScenarios`). */
24535
- const computed = (snapshot, id) => acHash(ticketOf$2(snapshot, id)?.scenarios ?? []);
24536
- /**
24537
- * D-81 and the D-80 no-bypass reasoning: a host that supplies no commit cannot have Done reported as
24538
- * skipped, or deleting one field from the input would remove every commit check at once.
24539
- */
24540
- const commitMissing = (snapshot, id) => {
24541
- if (ticketOf$2(snapshot, id) === void 0 || snapshot.git?.commit !== void 0) return [];
24542
- return [{
24543
- file: ticketFile$6(id),
24544
- reason: "the host supplied no commit for the gated tree; Done cannot bind a tick"
24545
- }];
24546
- };
24547
- /**
24548
- * D-81: anything shorter than 7 hex characters is not a sha and never compares equal. One draft per
24549
- * source, so one bad character produces one reason rather than a mismatch finding on top of it.
24550
- */
24551
- const shaTooShort = (snapshot, id) => {
24552
- if (ticketOf$2(snapshot, id) === void 0) return [];
24553
- const host = snapshot.git?.commit;
24554
- const tick = frontmatterOf(snapshot, id)?.verified_commit;
24555
- const review = verificationOf$1(snapshot, id)?.frontmatter?.commit;
24556
- const bad = (v) => `"${v}" is not a commit sha; at least 7 hexadecimal characters are needed`;
24557
- return [
24558
- ...host !== void 0 && !isSha(host) ? [{
24559
- file: ticketFile$6(id),
24560
- reason: "host commit " + bad(host)
24561
- }] : [],
24562
- ...tick !== void 0 && !isSha(tick) ? [{
24563
- file: ticketFile$6(id),
24564
- pointer: "/verified_commit",
24565
- reason: "verified_commit " + bad(tick)
24566
- }] : [],
24567
- ...review !== void 0 && !isSha(review) ? [{
24568
- file: verificationFile(id),
24569
- pointer: "/commit",
24570
- reason: "the review commit " + bad(review)
24571
- }] : []
24572
- ];
24573
- };
24574
- /** GATE-03: Done cannot tell whether the criteria moved if Ready never recorded where they were. */
24575
- const acHashMissing = (snapshot, id) => {
24576
- const fm = frontmatterOf(snapshot, id);
24577
- if (fm === void 0 || fm.ac_hash !== void 0 || computed(snapshot, id) === void 0) return [];
24578
- return [{
24579
- file: ticketFile$6(id),
24580
- pointer: "/ac_hash",
24581
- reason: "Ready has recorded no ac_hash for this ticket"
24582
- }];
24583
- };
24584
24491
  /**
24585
- * GATE-03: exact string comparison, prefix included, so a change of hash algorithm fails loudly instead
24586
- * of comparing a new digest against an old one and reading as a change of criteria (D-75).
24492
+ * Spec §10: changed paths that no task's `files:` names exactly or, for a token ending in `/`, contains.
24493
+ * The ticket's own records are never listed. Sorted, unique; undefined when the ticket has no plan.
24587
24494
  */
24588
- const acChanged = (snapshot, id) => {
24589
- const recorded = frontmatterOf(snapshot, id)?.ac_hash;
24590
- const now = computed(snapshot, id);
24591
- if (recorded === void 0 || now === void 0 || recorded === now) return [];
24592
- return [{
24593
- file: ticketFile$6(id),
24594
- pointer: "/ac_hash",
24595
- reason: `the acceptance criteria changed since Ready: ac_hash records ${recorded}, they hash to ${now} now`
24596
- }];
24597
- };
24598
- /** D-76: a tick with no binding is a claim about nothing; there is no compatibility path in v0.1. */
24599
- const tickUnbound = (snapshot, id) => {
24600
- const fm = frontmatterOf(snapshot, id);
24601
- if (fm === void 0 || (fm.verified ?? []).length === 0) return [];
24602
- const missing = [...fm.verified_hash === void 0 ? ["verified_hash"] : [], ...fm.verified_commit === void 0 ? ["verified_commit"] : []];
24603
- if (missing.length === 0) return [];
24604
- return [{
24605
- file: ticketFile$6(id),
24606
- pointer: "/verified",
24607
- reason: `verified is set but ${missing.join(" and ")} ${missing.length > 1 ? "are" : "is"} not recorded`
24608
- }];
24609
- };
24610
- /** GATE-11: the ticks were made against criteria that have since moved. */
24611
- const tickStaleHash = (snapshot, id) => {
24612
- const recorded = frontmatterOf(snapshot, id)?.verified_hash;
24613
- const now = computed(snapshot, id);
24614
- if (recorded === void 0 || now === void 0 || recorded === now) return [];
24615
- return [{
24616
- file: ticketFile$6(id),
24617
- pointer: "/verified_hash",
24618
- reason: `the ticks were made against ${recorded}; the acceptance criteria hash to ${now} now`
24495
+ function undeclaredFiles(snapshot, id, changed) {
24496
+ const tasks = laneTicket(snapshot, id) === void 0 ? void 0 : workOf(snapshot, id)?.plan?.tasks;
24497
+ if (tasks === void 0) return void 0;
24498
+ const declared = tasks.flatMap((t) => [...t.files, ...t.newFiles]);
24499
+ const own = "accord/tickets/" + id;
24500
+ const research = addedResearch(snapshot, id);
24501
+ return [...new Set(changed)].filter((p) => p !== own + ".md" && !p.startsWith(own + "/") && !research.includes(p)).filter((p) => !declared.some((d) => d.endsWith("/") ? p.startsWith(d) : p === d)).sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
24502
+ }
24503
+ const ticketFile$6 = (id) => "accord/tickets/" + id + ".md";
24504
+ const cmp$9 = (a, b) => a < b ? -1 : a > b ? 1 : 0;
24505
+ /** The paths a ticket's `## Scope` section lists, one per line, or undefined when it has no such section. */
24506
+ function scopeLines(text) {
24507
+ const { body, bodyOffset } = splitFrontmatter(normaliseText(text));
24508
+ const section = scan(body, bodyOffset).sections.find((s) => headingKey(s.heading) === "scope");
24509
+ if (section === void 0) return void 0;
24510
+ return stripHtmlComments(section.lines).map((l) => l.text.trim().replace(/^[-*+]\s+/, "").trim()).map((t) => t.length >= 2 && t.startsWith("`") && t.endsWith("`") ? t.slice(1, -1) : t).map((t) => t.replace(/\\/g, "/")).filter((t) => t !== "");
24511
+ }
24512
+ const factOf$1 = (s, id) => s.branchFacts !== void 0 && Object.hasOwn(s.branchFacts, id) ? s.branchFacts[id] : void 0;
24513
+ /** An entry matches a path when it ends in `/` and the path starts with it, or when the two are equal. No globs. */
24514
+ const matches = (entry, path) => entry.endsWith("/") ? path.startsWith(entry) : entry === path;
24515
+ /** Ledger Ruling 9: the ticket's own files, the files `accord skills sync` writes, and the merge-base config's `generated:` paths. */
24516
+ function isExempt(id, fact, path, own = []) {
24517
+ if (path === ticketFile$6(id) || path.startsWith("accord/tickets/" + id + "/")) return true;
24518
+ if (own.includes(path)) return true;
24519
+ if (fact.synced.includes(path)) return true;
24520
+ if (path === ".claude/settings.json") return false;
24521
+ return configLists(fact.baseConfig).generated.some((e) => matches(e, path));
24522
+ }
24523
+ /** A change that only moves whitespace, blank lines or line endings has `lines: 0` and is never counted (D-02). */
24524
+ const isCounted = (c) => c.kind !== "modified" || c.binary === true || c.lines > 0;
24525
+ /** Lane S: the counted, non-exempt changed paths outside the recorded scope; `cannot` when no scope can be read. */
24526
+ function outsideScope(s, id) {
24527
+ if (laneTicket(s, id)?.frontmatter?.lane !== "S") return void 0;
24528
+ const fact = factOf$1(s, id);
24529
+ if (fact === void 0 || "error" in fact) return void 0;
24530
+ if (fact.scope === void 0) return { cannot: `no commit on this branch records ac_hash in ${ticketFile$6(id)}, so the ## Scope that gate ready fixed cannot be read; commit the ticket after accord gate ready ${id}` };
24531
+ const { commit, paths } = fact.scope;
24532
+ if (paths.length === 0) return { cannot: `## Scope held no path when ac_hash was first recorded (commit ${commit}); a lane S ticket lists the files it expects to touch before any change, so it must be lifted to lane M` };
24533
+ const own = addedResearch(s, id);
24534
+ return { paths: fact.changes.filter((c) => isCounted(c) && !isExempt(id, fact, c.path, own) && !paths.includes(c.path)).map((c) => c.path).sort(cmp$9) };
24535
+ }
24536
+ const changesTicket = (fact, id) => fact.changes.some((c) => c.path === ticketFile$6(id));
24537
+ const hasChanges = (fact) => fact.changes.length > 0;
24538
+ const branchUnknown = (s, id) => {
24539
+ if (laneTicket(s, id) === void 0) return [];
24540
+ const file = ticketFile$6(id);
24541
+ const fact = factOf$1(s, id);
24542
+ if (fact === void 0) return [{
24543
+ file,
24544
+ reason: "the host loaded no branch diff for this ticket, so the files it changed cannot be checked"
24619
24545
  }];
24620
- };
24621
- /** Every path is the ticket's own file, lies in its folder (spec §11), or is accord/product/conventions.md (ST-LN-8 D-08). */
24622
- const ownRecordsOnly = (id, paths) => paths.every((p) => p === ticketFile$6(id) || p === "accord/product/conventions.md" || p.startsWith("accord/tickets/" + id + "/"));
24623
- /** A commit that changes a path outside the ticket's own records, or a merge whose own changes git could not show. */
24624
- const handMade = (id, c) => c.files === void 0 || !ownRecordsOnly(id, c.files);
24625
- /** A later commit that changed only this ticket's own records (its file and folder) or accord/product/conventions.md is the same reviewed code. */
24626
- const onlyOwnRecords = (snapshot, id, recorded) => {
24627
- const since = snapshot.recordsSince;
24628
- if (since === void 0 || !Object.hasOwn(since, recorded)) return false;
24629
- return ownRecordsOnly(id, since[recorded]);
24630
- };
24631
- /**
24632
- * ST-LN-96 D-04: the recorded commit is not in the gated commit's history, so the host compared the contents of the ticket's files.
24633
- * `{ pass }`: none differs; `{ reason }`: the refusal's wording; undefined: the host supplied no fact for it, and today's reason stands.
24634
- */
24635
- const contentVerdict = (snapshot, recorded, host, what, today) => {
24636
- const facts = snapshot.contentSince;
24637
- const key = recorded.toLowerCase();
24638
- if (facts === void 0 || !Object.hasOwn(facts, key)) return void 0;
24639
- const fact = facts[key];
24640
- if ("absent" in fact) return { reason: `${today}; the verified commit is not in this clone, so its contents cannot be compared - verify again` };
24641
- if (fact.changed.length === 0) return { pass: true };
24642
- return { reason: `${what === "ticks" ? "the ticks were made" : "the review was written"} against commit ${recorded}, which is not in the history of the gated commit ${host}; these ticket files changed since: ${fact.changed.join(", ")}` };
24643
- };
24644
- /** GATE-11: the ticks were made against a different commit. Both values are guarded on `isSha` first,
24645
- * so a too-short value produces `gate.sha-too-short` alone and never two reasons for one typo (D-81). */
24646
- const tickStaleCommit = (snapshot, id) => {
24647
- const tick = frontmatterOf(snapshot, id)?.verified_commit;
24648
- const host = snapshot.git?.commit;
24649
- if (tick === void 0 || host === void 0 || !isSha(tick) || !isSha(host) || shaEqual(tick, host)) return [];
24650
- if (onlyOwnRecords(snapshot, id, tick)) return [];
24651
- const today = `the ticks were made against commit ${tick}; the gated commit is ${host}`;
24652
- const content = contentVerdict(snapshot, tick, host, "ticks", today);
24653
- if (content !== void 0 && "pass" in content) return [];
24654
- return [{
24655
- file: ticketFile$6(id),
24656
- pointer: "/verified_commit",
24657
- reason: content === void 0 ? today : content.reason
24546
+ if ("error" in fact) return [{
24547
+ file,
24548
+ reason: fact.error
24658
24549
  }];
24659
- };
24660
- /** ROADMAP criterion 2 and docs/design.md §5: the review must be of the code being gated. */
24661
- const staleReview = (snapshot, id) => {
24662
- const review = verificationOf$1(snapshot, id)?.frontmatter?.commit;
24663
- const host = snapshot.git?.commit;
24664
- if (review === void 0 || host === void 0 || !isSha(review) || !isSha(host) || shaEqual(review, host)) return [];
24665
- if (onlyOwnRecords(snapshot, id, review)) return [];
24666
- const today = `the review was written against commit ${review}; the gated commit is ${host}`;
24667
- const content = contentVerdict(snapshot, review, host, "review", today);
24668
- if (content !== void 0 && "pass" in content) return [];
24669
- return [{
24670
- file: verificationFile(id),
24671
- pointer: "/commit",
24672
- reason: content === void 0 ? today : content.reason
24550
+ if (!hasChanges(fact)) return [{
24551
+ file,
24552
+ reason: `the branch diff from ${fact.base}, the merge base with the default branch, to HEAD is empty: HEAD adds no change over the merge base; lane work is committed on the ticket's own branch, never on the default branch`
24673
24553
  }];
24674
- };
24675
- const CONFIG$3 = "accord/config.yml";
24676
- /** ST-LN-8 D-02: under commits.trailers forbid, every commit the host loaded for this branch is read for forbidden lines; undefined commits fail closed. */
24677
- const commitTrailer = (snapshot, id) => {
24678
- if (ticketOf$2(snapshot, id) === void 0 || snapshot.config?.commits?.trailers !== "forbid") return [];
24679
- const at = {
24680
- file: CONFIG$3,
24681
- pointer: "/commits/trailers"
24682
- };
24683
- if (snapshot.commits === void 0) return [{
24684
- ...at,
24685
- reason: "commits.trailers is forbid, but the host loaded no commits of this branch, so they cannot be checked"
24554
+ if (laneTicket(s, id)?.frontmatter?.lane === "S" && !changesTicket(fact, id)) return [{
24555
+ file,
24556
+ reason: `the branch diff from ${fact.base}, the merge base with the default branch, does not change ${file}; lane work is committed on the ticket's own branch, never on the default branch`
24686
24557
  }];
24687
- return snapshot.commits.flatMap((c) => forbiddenLines(c.message).map((l) => ({
24688
- ...at,
24689
- reason: trailerReason(c.sha, l)
24690
- })));
24558
+ return [];
24691
24559
  };
24692
- /**
24693
- * Phase 8.1 D-06, D-07: under `commits.message` every commit the host loaded for this branch (the first-parent commits not on the default ref) is judged by the one core function
24694
- * `commitRuleProblem`, a merge commit and a `Revert "` subject excepted. Read through claimPinBefore: a ticket claimed before COMMIT_MESSAGE_FROM is not judged. A pattern that is not in
24695
- * force, and commits the host did not load, fail closed; every reason names its fix.
24696
- */
24697
- const commitMessage$1 = (snapshot, id) => {
24698
- if (ticketOf$2(snapshot, id) === void 0 || snapshot.config?.commits?.message === void 0 || claimPinBefore(snapshot, id, "0.9.0")) return [];
24699
- const at = {
24700
- file: CONFIG$3,
24701
- pointer: "/commits/message"
24702
- };
24703
- const rule = commitRuleOf(snapshot.config);
24704
- if (rule === void 0) return [];
24705
- if ("problem" in rule) return [{
24706
- ...at,
24707
- reason: commitRuleNotInForce(rule.problem)
24708
- }];
24709
- if (snapshot.commits === void 0) return [{
24710
- ...at,
24711
- reason: "commits.message is set, but the host loaded no commits of this branch, so they cannot be checked - fix: run accord gate done in the ticket's checkout, where git reads the branch"
24560
+ const outOfScope = (s, id) => {
24561
+ const fact = factOf$1(s, id);
24562
+ if (fact === void 0 || "error" in fact || !changesTicket(fact, id)) return [];
24563
+ const out = outsideScope(s, id);
24564
+ if (out === void 0) return [];
24565
+ const file = ticketFile$6(id);
24566
+ if ("cannot" in out) return [{
24567
+ file,
24568
+ reason: out.cannot
24712
24569
  }];
24713
- return snapshot.commits.flatMap((c) => {
24714
- const problem = c.merge === true ? void 0 : commitRuleProblem(rule, c.message);
24715
- return problem === void 0 ? [] : [{
24716
- ...at,
24717
- reason: commitRuleRefusal(c.sha, problem)
24570
+ const commit = fact.scope?.commit ?? "";
24571
+ const work = workOf(s, id);
24572
+ const declared = new Set((work?.ledger?.wordingOnly ?? []).map((w) => w.path));
24573
+ const confirmed = work?.review?.confirmed ?? [];
24574
+ return out.paths.flatMap((p) => {
24575
+ if (!declared.has(p)) return [{
24576
+ file,
24577
+ reason: `${p} is changed on this branch but not listed in ## Scope as recorded at commit ${commit}; the ticket must be lifted to lane M`
24578
+ }];
24579
+ const why = wordingOnlyFault(fact.changes.find((c) => c.path === p), p, confirmed, id);
24580
+ return why === void 0 ? [] : [{
24581
+ file,
24582
+ reason: `${p} is declared wording-only in ${ledgerFile(id)} but ${why}; the ticket must be lifted to lane M`
24718
24583
  }];
24719
24584
  });
24720
24585
  };
24721
- const isTest$1 = (tag) => tag.startsWith("@test:");
24722
- /** Every scenario the machine layer applies to: `@ui` leans on the human layer instead (D-90, GATE-09). */
24723
- const machineScenarios = (snapshot, id) => (ticketOf$2(snapshot, id)?.scenarios ?? []).filter((s) => !s.tags.includes("@ui"));
24724
- /** The configured report path, or undefined when `config.yml` declares no `tests.report`. */
24725
- const reportPath$1 = (snapshot) => snapshot.config?.tests?.report;
24726
- /** True only when a report was declared *and* its file reached the snapshot; the join runs on nothing else. */
24727
- const reportLoaded = (snapshot) => {
24728
- const report = reportPath$1(snapshot);
24729
- return report !== void 0 && Object.hasOwn(snapshot.files, normaliseKey(report));
24730
- };
24731
- /**
24732
- * GATE-08: a scenario is either machine-checked or `@ui`. This is a property of the ticket, not of the
24733
- * report, so it fires whether or not a report is configured — the two configuration reasons below
24734
- * suppress the per-scenario join, never this.
24735
- */
24736
- const testTagMissing$1 = (snapshot, id) => machineScenarios(snapshot, id).filter((s) => !s.tags.some(isTest$1)).map((s) => ({
24737
- file: ticketFile$6(id),
24738
- line: s.line,
24739
- reason: `scenario "${s.name}" carries no @test:<id> tag and is not @ui, so Done cannot check it against the report`
24740
- }));
24741
- /**
24742
- * D-80: no `tests.report` at all fails Done. It is not reported skipped — GATE-06 forbids a bypass, and
24743
- * deleting one line from `config.yml` would otherwise remove the whole Machine layer at once.
24744
- */
24745
- const testsUnconfigured = (snapshot, id) => {
24746
- if (reportPath$1(snapshot) !== void 0 || machineScenarios(snapshot, id).length === 0) return [];
24747
- return [{
24748
- file: CONFIG$3,
24749
- pointer: "/tests",
24750
- reason: "no test report is declared, so the machine layer cannot run and Done cannot pass; set tests.report"
24751
- }];
24752
- };
24753
- /** D-80 extended: declaring the key and deleting the file is the same hole, so it closes the same way. */
24754
- const reportMissing$1 = (snapshot, id) => {
24755
- const report = reportPath$1(snapshot);
24756
- if (report === void 0 || reportLoaded(snapshot) || machineScenarios(snapshot, id).length === 0) return [];
24757
- return [{
24758
- file: CONFIG$3,
24759
- pointer: "/tests/report",
24760
- reason: `tests.report "${report}" is not in the snapshot`
24761
- }];
24762
- };
24763
- /** The `@test:` ids of the machine-checked scenarios, paired with the line to report them on. */
24764
- const testIds = (snapshot, id) => machineScenarios(snapshot, id).flatMap((s) => s.tags.filter(isTest$1).map((tag) => ({
24765
- line: s.line,
24766
- testId: tag.slice(6)
24767
- })));
24768
- /**
24769
- * GATE-08: exact code-point lookup with `Object.hasOwn` — no case folding, no basename fallback, no
24770
- * prototype chain (T-04-21). Silent when the report is undeclared or absent, so one configuration
24771
- * problem yields one reason rather than one per scenario, as `tokensMissing` does under D-67.
24772
- */
24773
- const testUnknown = (snapshot, id) => {
24774
- if (!reportLoaded(snapshot)) return [];
24775
- const report = reportPath$1(snapshot);
24776
- return testIds(snapshot, id).filter(({ testId }) => !Object.hasOwn(snapshot.tests ?? {}, testId)).map(({ line, testId }) => ({
24777
- file: ticketFile$6(id),
24778
- line,
24779
- reason: `@test:${testId} not found in ${report}; ids are classname#name with spaces as '-'`
24780
- }));
24781
- };
24782
- /**
24783
- * GATE-08 and docs/design.md §5: only `passed` passes. A muted test fails Done exactly as a failing one
24784
- * does — naming the status verbatim keeps the two distinguishable without softening either.
24785
- */
24786
- const testNotPassed = (snapshot, id) => {
24787
- if (!reportLoaded(snapshot)) return [];
24788
- const tests = snapshot.tests ?? {};
24789
- const report = reportPath$1(snapshot);
24790
- return testIds(snapshot, id).filter(({ testId }) => Object.hasOwn(tests, testId) && tests[testId] !== "passed").map(({ line, testId }) => ({
24791
- file: ticketFile$6(id),
24792
- line,
24793
- reason: `@test:${testId} is recorded ${tests[testId]} in ${report}; Done passes on passed alone`
24794
- }));
24795
- };
24796
- /** D-78: the gated commit's author rides under a key equal to `git.commit`; file authors under their
24797
- * repo-relative posix path. A sha can never collide with a path, so one flat record serves both. */
24798
- const authorsOf = (snapshot, id) => {
24799
- const git = snapshot.git;
24800
- if (git === void 0) return {};
24801
- const own = (key) => Object.hasOwn(git.authors, key) ? git.authors[key] : void 0;
24802
- return {
24803
- commitAuthor: own(git.commit),
24804
- fileAuthor: own(verificationFile(id))
24805
- };
24806
- };
24807
- /**
24808
- * GATE-05 (D-79), warning and never more: docs/design.md §4 makes the reviewer not a role, so in the
24809
- * workflow accord itself prescribes the two identities match on nearly every honest ticket. An error
24810
- * here would block every solo developer, which is why D-79 fixed the level at warning.
24811
- */
24812
- const authorMatch = (snapshot, id) => {
24813
- if (verificationOf$1(snapshot, id) === void 0) return [];
24814
- const { commitAuthor, fileAuthor } = authorsOf(snapshot, id);
24815
- if (commitAuthor === void 0 || fileAuthor === void 0) return [];
24816
- if (commitAuthor.toLowerCase() !== fileAuthor.toLowerCase()) return [];
24817
- return [{
24818
- file: verificationFile(id),
24819
- reason: `the review and the gated commit share an author (${fileAuthor}), so no second pair of eyes touched this ticket`
24820
- }];
24821
- };
24822
- /** D-80's skipped-as-a-Finding rule: the comparison the host could not supply is reported rather than
24823
- * silently dropped. Suppressed when the review file is missing, because `gate.verification-missing`
24824
- * already owns that case and one absent review should read as one reason. */
24825
- const authorSkipped = (snapshot, id) => {
24826
- if (verificationOf$1(snapshot, id) === void 0) return [];
24827
- const { commitAuthor, fileAuthor } = authorsOf(snapshot, id);
24828
- const which = [...commitAuthor === void 0 ? ["the gated commit"] : [], ...fileAuthor === void 0 ? ["the review file"] : []];
24829
- if (which.length === 0) return [];
24830
- return [{
24831
- file: verificationFile(id),
24832
- reason: `the host supplied no author for ${which.join(" and ")}, so the review and the commit could not be compared`
24833
- }];
24586
+ /** The base entries of `sensitive:` then the HEAD entries, in key order, each (area, path) pair once. */
24587
+ function sensitiveEntries(s, fact) {
24588
+ const head = Object.entries(s.config?.sensitive ?? {}).flatMap(([area, paths]) => paths.map((path) => ({
24589
+ area,
24590
+ path
24591
+ })));
24592
+ const seen = /* @__PURE__ */ new Set();
24593
+ return [...configLists(fact.baseConfig).sensitive, ...head].filter((e) => {
24594
+ const key = e.area + "\0" + e.path;
24595
+ if (seen.has(key)) return false;
24596
+ seen.add(key);
24597
+ return true;
24598
+ });
24599
+ }
24600
+ /** Lane S: a counted change under a listed sensitive entry fails, whatever its scope, declaration or exemption (D-04, Ruling 29). */
24601
+ const sensitiveTouched = (s, id) => {
24602
+ if (laneTicket(s, id)?.frontmatter?.lane !== "S") return [];
24603
+ const fact = factOf$1(s, id);
24604
+ if (fact === void 0 || "error" in fact) return [];
24605
+ const entries = sensitiveEntries(s, fact);
24606
+ const file = ticketFile$6(id);
24607
+ return fact.changes.filter(isCounted).flatMap((c) => {
24608
+ const hit = entries.find((e) => matches(e.path, c.path));
24609
+ return hit === void 0 ? [] : [{
24610
+ file,
24611
+ reason: `${c.path} is in the sensitive area ${hit.area} (accord/config.yml lists ${hit.path} under sensitive); the ticket must be lifted to lane M`
24612
+ }];
24613
+ });
24834
24614
  };
24835
- /**
24836
- * The entries of the ticket's `research:` key that are Markdown records under accord/research/ and that the branch
24837
- * adds (relative to the merge base). Empty when the ticket, the branch fact or its changes are missing.
24838
- */
24839
- function addedResearch(snapshot, id) {
24840
- const listed = (Object.hasOwn(snapshot.tickets, id) ? snapshot.tickets[id] : void 0)?.frontmatter?.research;
24841
- const facts = snapshot.branchFacts;
24842
- const fact = facts !== void 0 && Object.hasOwn(facts, id) ? facts[id] : void 0;
24843
- if (listed === void 0 || fact === void 0 || "error" in fact || !Array.isArray(fact.changes)) return [];
24844
- const added = new Set(fact.changes.filter((c) => c.kind === "added").map((c) => c.path));
24845
- return listed.filter((p) => isResearchRecord(p) && added.has(p));
24615
+ /** Ledger Ruling 13: an added line that calls a commander-style `command` or `option`. */
24616
+ const CALL_SIGN = /\.(command|option)\(/;
24617
+ /** The keys of the `exports` or `bin` map of a package.json text; a string value counts as the key `.`. */
24618
+ function keysOf(text, map) {
24619
+ if (text === void 0) return [];
24620
+ try {
24621
+ const value = JSON.parse(text)?.[map];
24622
+ if (typeof value === "string") return ["."];
24623
+ return typeof value === "object" && value !== null && !Array.isArray(value) ? Object.keys(value) : [];
24624
+ } catch {
24625
+ return [];
24626
+ }
24846
24627
  }
24847
- /** Untraced report case ids, sorted in code-point order; [] when no report is loaded. */
24848
- function untracedTests(snapshot) {
24849
- if (snapshot.tests === void 0) return [];
24850
- const named = new Set(Object.values(snapshot.tickets).flatMap((t) => t.scenarios.flatMap((s) => s.tags.filter((x) => x.startsWith("@test:")).map((x) => x.slice(6)))));
24851
- const baseline = new Set(snapshot.testsBaseline ?? []);
24852
- return Object.keys(snapshot.tests).filter((id) => !named.has(id) && !baseline.has(id) && !id.includes("risk:")).sort();
24628
+ const isPackageJson = (path) => path === "package.json" || path.endsWith("/package.json");
24629
+ /** Ledger Ruling 20: a call sign is read only in a non-Markdown file the ticket's own exemptions do not cover. */
24630
+ const callsOf = (c, id, fact) => c.calls === void 0 || /\.(md|markdown)$/i.test(c.path) || isExempt(id, fact, c.path) ? [] : [...new Set(c.calls.flatMap((l) => [...l.matchAll(new RegExp(CALL_SIGN.source, "g"))].map((m) => m[1])))];
24631
+ /** D-04: signs of a new interface in paths no sensitive entry matches; undefined without a lane ticket or a readable diff. */
24632
+ function interfaceSigns(s, id) {
24633
+ if (laneTicket(s, id) === void 0) return void 0;
24634
+ const fact = factOf$1(s, id);
24635
+ if (fact === void 0 || "error" in fact) return void 0;
24636
+ const entries = sensitiveEntries(s, fact);
24637
+ const out = [];
24638
+ for (const c of fact.changes) {
24639
+ if (entries.some((e) => matches(e.path, c.path))) continue;
24640
+ const add = (sign) => out.push({
24641
+ path: c.path,
24642
+ sign
24643
+ });
24644
+ if (c.kind === "added" && (c.path.split("/").slice(0, -1).includes("schemas") || c.path.endsWith(".schema.json"))) add("a new schema file");
24645
+ if (isPackageJson(c.path)) for (const map of ["exports", "bin"]) {
24646
+ const before = keysOf(c.pkg?.base, map);
24647
+ keysOf(c.pkg?.head, map).filter((k) => !before.includes(k)).forEach((k) => add(`a new key "${k}" in the ${map} map of package.json`));
24648
+ }
24649
+ callsOf(c, id, fact).forEach((name) => add(`an added line that calls .${name}(`));
24650
+ }
24651
+ return out.sort((a, b) => cmp$9(a.path, b.path) || cmp$9(a.sign, b.sign));
24853
24652
  }
24854
- const UNTRACED = (id) => `test "${id}" is named by no scenario's @test:, carries no risk:, and is not in accord/tests-baseline.txt`;
24855
- /**
24856
- * Silent until the repository holds a lane M, L or P ticket: that ticket opts the repository into the policy; a lane S or lane R
24857
- * (ST-LN-94 D-10) ticket alone does not.
24858
- */
24859
- const OPTS_IN = [
24860
- "M",
24861
- "L",
24862
- "P"
24863
- ];
24864
- const testUntraced = (snapshot) => {
24865
- const report = snapshot.config?.tests?.report;
24866
- if (report === void 0 || !Object.values(snapshot.tickets).some((t) => OPTS_IN.includes(t.frontmatter?.lane ?? ""))) return [];
24867
- return untracedTests(snapshot).map((id) => ({
24868
- file: normaliseKey(report),
24869
- reason: UNTRACED(id)
24653
+ const interfaceSign = (s, id) => {
24654
+ const signs = interfaceSigns(s, id);
24655
+ if (signs === void 0) return [];
24656
+ const file = ticketFile$6(id);
24657
+ if (laneTicket(s, id)?.frontmatter?.lane === "S") return signs.map(({ path, sign }) => ({
24658
+ file,
24659
+ reason: `${path} adds ${sign}, a sign of a new interface; the ticket must be lifted to lane M`
24660
+ }));
24661
+ const excused = workOf(s, id)?.review?.notInterface ?? [];
24662
+ return signs.filter(({ path }) => !excused.includes(path)).map(({ path, sign }) => ({
24663
+ file,
24664
+ reason: `${path} adds ${sign}, a sign of a new interface no sensitive entry matches; add an entry matching it under sensitive: in accord/config.yml, or have the reviewer record "Not an interface: ${path} — <reason>" in the last ## Round of ${reviewFile(id)}`
24870
24665
  }));
24871
24666
  };
24872
- const planFile = (id) => "accord/tickets/" + id + "/plan.md";
24873
- const ledgerFile = (id) => "accord/tickets/" + id + "/ledger.md";
24874
- const reviewFile = (id) => "accord/tickets/" + id + "/review.md";
24875
- /** Spec §10: the two review verdicts Done accepts. */
24876
- const VERDICTS = ["converged", "accepted-by-owner"];
24877
- /** `Object.hasOwn`, never `in`: the id is caller-supplied. */
24878
- const workOf = (snapshot, id) => snapshot.work !== void 0 && Object.hasOwn(snapshot.work, id) ? snapshot.work[id] : void 0;
24879
- /** The ticket when it exists and carries `lane:`; every workflow-layer rule is silent otherwise. */
24880
- const laneTicket = (snapshot, id) => {
24881
- const t = Object.hasOwn(snapshot.tickets, id) ? snapshot.tickets[id] : void 0;
24882
- return t?.frontmatter?.lane === void 0 ? void 0 : t;
24667
+ /** D-02, D-07: why a declared wording-only file does not qualify, or undefined when it does. */
24668
+ function wordingOnlyFault(c, path, confirmed, id) {
24669
+ if (c?.kind === "added") return "is new";
24670
+ if (c?.kind === "deleted") return "is deleted";
24671
+ if (c?.kind === "type" || c?.kind === "mode") return "changes its file type or mode";
24672
+ if (c?.binary === true) return "is binary";
24673
+ if (c !== void 0 && c.lines > 3) return `changes ${c.lines} lines, more than 3`;
24674
+ if (!confirmed.includes(path)) return `has no "Confirmed wording-only: ${path}" line in the last ## Round of ${reviewFile(id)}`;
24675
+ }
24676
+ const HUNK = /^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/;
24677
+ const headerPath = (rest, prefix) => {
24678
+ const t = rest.replace(/\t$/, "");
24679
+ return t.startsWith(prefix) ? t.slice(2) : void 0;
24883
24680
  };
24681
+ /** `diff --git a/<p> b/<p>`: the path when both halves are equal (a rename or a quoted name is read from its own lines instead). */
24682
+ function pathOfGitHeader(rest) {
24683
+ if (!rest.startsWith("a/")) return void 0;
24684
+ const total = rest.length - 5;
24685
+ if (total <= 0 || total % 2 !== 0) return void 0;
24686
+ const p = rest.slice(2, 2 + total / 2);
24687
+ return rest === `a/${p} b/${p}` ? p : void 0;
24688
+ }
24884
24689
  /**
24885
- * The debug.md of a lane ticket other than lane S and lane R (the lanes that run the debug stage) whose last open episode still starts with UNFINISHED_MARKER; undefined otherwise. No gate
24886
- * refuses it: it is the source of the `Unfinished:` line of `accord anchor` (status/anchor.ts) for the debug stage.
24690
+ * Split a diff text on its `diff --git` lines. Header lines are read only outside a hunk; inside one the hunk's own counts decide where it ends,
24691
+ * so a removed `-- x` line (`--- x` in the text) or a context line that looks like a header is never read as one.
24887
24692
  */
24888
- const unfinishedDebug = (snapshot, id) => {
24889
- const debug = stageLaneTicket(snapshot, id) === void 0 ? void 0 : workOf(snapshot, id)?.debug;
24890
- return debug?.unfinished === void 0 ? void 0 : debug;
24891
- };
24892
- /** Spec §8: every planned task has a completion line written by `accord task-done`. */
24893
- const tasksIncomplete = (snapshot, id) => {
24894
- if (laneTicket(snapshot, id) === void 0) return [];
24895
- const work = workOf(snapshot, id);
24896
- if (work?.plan === void 0) return [{
24897
- file: planFile(id),
24898
- reason: "no plan; Done needs every planned task recorded in " + ledgerFile(id)
24899
- }];
24900
- if (work.plan.tasks.length === 0) return [{
24901
- file: planFile(id),
24902
- reason: "the plan has no tasks; Done needs every planned task recorded in " + ledgerFile(id)
24693
+ function diffFiles(diffText) {
24694
+ const files = [];
24695
+ let cur;
24696
+ let oldLeft = 0;
24697
+ let newLeft = 0;
24698
+ let oldNo = 0;
24699
+ let newNo = 0;
24700
+ let renameTo;
24701
+ let deleted = false;
24702
+ let hunk;
24703
+ const finish = () => {
24704
+ if (cur === void 0) return;
24705
+ if (renameTo !== void 0) cur.path = renameTo;
24706
+ if (deleted && cur.path === void 0 && cur.oldPath !== void 0) cur.path = cur.oldPath;
24707
+ };
24708
+ for (const raw of diffText.split("\n")) {
24709
+ const text = raw.endsWith("\r") ? raw.slice(0, -1) : raw;
24710
+ if (cur !== void 0 && (oldLeft > 0 || newLeft > 0)) {
24711
+ const c = text[0];
24712
+ if (c === "+") {
24713
+ newLeft--;
24714
+ const l = {
24715
+ line: newNo++,
24716
+ text: text.slice(1)
24717
+ };
24718
+ cur.added.push(l);
24719
+ hunk?.added.push(l);
24720
+ hunk?.lines.push(text);
24721
+ continue;
24722
+ }
24723
+ if (c === "-") {
24724
+ oldLeft--;
24725
+ const l = {
24726
+ line: oldNo++,
24727
+ text: text.slice(1)
24728
+ };
24729
+ cur.removed.push(l);
24730
+ hunk?.removed.push(l);
24731
+ hunk?.lines.push(text);
24732
+ continue;
24733
+ }
24734
+ if (c === " " || text === "") {
24735
+ oldLeft--;
24736
+ newLeft--;
24737
+ oldNo++;
24738
+ newNo++;
24739
+ hunk?.lines.push(text);
24740
+ continue;
24741
+ }
24742
+ if (c === "\\") {
24743
+ hunk?.lines.push(text);
24744
+ continue;
24745
+ }
24746
+ oldLeft = 0;
24747
+ newLeft = 0;
24748
+ }
24749
+ if (text.startsWith("diff --git ")) {
24750
+ finish();
24751
+ renameTo = void 0;
24752
+ deleted = false;
24753
+ cur = {
24754
+ path: pathOfGitHeader(text.slice(11)),
24755
+ binary: false,
24756
+ added: [],
24757
+ removed: [],
24758
+ header: [text],
24759
+ hunks: []
24760
+ };
24761
+ hunk = void 0;
24762
+ files.push(cur);
24763
+ continue;
24764
+ }
24765
+ if (cur === void 0) continue;
24766
+ if (hunk !== void 0 && text.startsWith("\\")) {
24767
+ hunk.lines.push(text);
24768
+ continue;
24769
+ }
24770
+ const h = HUNK.exec(text);
24771
+ if (h !== null) {
24772
+ hunk = {
24773
+ lines: [text],
24774
+ added: [],
24775
+ removed: []
24776
+ };
24777
+ cur.hunks.push(hunk);
24778
+ oldNo = Number(h[1]);
24779
+ oldLeft = h[2] === void 0 ? 1 : Number(h[2]);
24780
+ newNo = Number(h[3]);
24781
+ newLeft = h[4] === void 0 ? 1 : Number(h[4]);
24782
+ if (oldLeft === 0) oldNo++;
24783
+ if (newLeft === 0) newNo++;
24784
+ continue;
24785
+ }
24786
+ if (hunk === void 0 && text !== "") cur.header.push(text);
24787
+ if (text.startsWith("+++ ")) {
24788
+ if (text === "+++ /dev/null") deleted = true;
24789
+ else {
24790
+ const p = headerPath(text.slice(4), "b/");
24791
+ if (p !== void 0) cur.path = p;
24792
+ }
24793
+ } else if (text.startsWith("--- ")) {
24794
+ if (text !== "--- /dev/null") {
24795
+ const p = headerPath(text.slice(4), "a/");
24796
+ if (p !== void 0) {
24797
+ cur.oldPath = p;
24798
+ if (cur.path === void 0) cur.path = p;
24799
+ }
24800
+ }
24801
+ } else if (text.startsWith("rename from ")) cur.oldPath = text.slice(12).replace(/\t$/, "");
24802
+ else if (text.startsWith("rename to ")) renameTo = text.slice(10).replace(/\t$/, "");
24803
+ else if (text.startsWith("Binary files ") || text === "GIT binary patch") {
24804
+ cur.binary = true;
24805
+ if (cur.path === void 0 && text.startsWith("Binary files ") && text.endsWith(" differ")) {
24806
+ const mid = text.slice(13, -7);
24807
+ if (mid.startsWith("/dev/null and b/")) cur.path = mid.slice(16);
24808
+ else if (mid.endsWith(" and /dev/null") && mid.startsWith("a/")) cur.path = mid.slice(2, -14);
24809
+ }
24810
+ }
24811
+ }
24812
+ finish();
24813
+ return files;
24814
+ }
24815
+ /**
24816
+ * The one scan bound (D-09): a changed line is matched on its first SCAN_LINE_LIMIT characters only. The bound caps the time an allowed pattern may take per changed line, which is at most
24817
+ * two overlapping repeats in a row and 16 routes for one text; exponential shapes, longer runs and more routes are refused at read by backtrack.ts. The total still grows with the number of
24818
+ * changed lines, each one costing at most the sum of the patterns' cost on SCAN_LINE_LIMIT characters (08-08b states the figures); no total cap is built.
24819
+ */
24820
+ const SCAN_LINE_LIMIT = 1e3;
24821
+ /** The label of the trigger a cut line gets: a line over the bound is never scanned whole and says so (fail closed). */
24822
+ const LONG_LINE$1 = `line longer than ${SCAN_LINE_LIMIT} characters, not fully scanned`;
24823
+ const UNREADABLE = "too large to read as text, so its lines were not scanned";
24824
+ const tooLong = (text) => text.length > SCAN_LINE_LIMIT;
24825
+ /** The label of the trigger a file git calls binary gets when it is not a known binary type (D-20): a NUL byte on a changed line makes git call a code file binary, and its lines were then never scanned. */
24826
+ const BINARY_LABEL = "binary file, its lines were not scanned";
24827
+ /** Image, font and archive types git rightly calls binary; any other binary file with no text twin is a `cannot` trigger (fail closed). */
24828
+ const KNOWN_BINARY = /* @__PURE__ */ new Set([
24829
+ "png",
24830
+ "jpg",
24831
+ "jpeg",
24832
+ "gif",
24833
+ "webp",
24834
+ "ico",
24835
+ "bmp",
24836
+ "avif",
24837
+ "woff",
24838
+ "woff2",
24839
+ "ttf",
24840
+ "otf",
24841
+ "eot",
24842
+ "zip",
24843
+ "gz",
24844
+ "tgz",
24845
+ "tar",
24846
+ "bz2",
24847
+ "xz",
24848
+ "7z",
24849
+ "pdf"
24850
+ ]);
24851
+ /** The extension of a path: the text after the last `.` of its name, lower-cased; empty when the name holds none. */
24852
+ const extensionOf$1 = (path) => {
24853
+ const name = path.slice(path.lastIndexOf("/") + 1);
24854
+ const dot = name.lastIndexOf(".");
24855
+ return dot < 0 ? "" : name.slice(dot + 1).toLowerCase();
24856
+ };
24857
+ const MARKDOWN$1 = /\.(md|mdx|markdown)$/i;
24858
+ const TEST_FOLDER$1 = /* @__PURE__ */ new Set([
24859
+ "test",
24860
+ "tests",
24861
+ "__tests__"
24862
+ ]);
24863
+ /** lane.md's definition: under a folder named `test`, `tests` or `__tests__`, or a name holding `.test.` or `.spec.`. */
24864
+ const isTestFile$1 = (path) => {
24865
+ const parts = path.split("/");
24866
+ const name = parts[parts.length - 1];
24867
+ return parts.slice(0, -1).some((d) => TEST_FOLDER$1.has(d)) || name.includes(".test.") || name.includes(".spec.");
24868
+ };
24869
+ /** A path entry of a security pattern compares ignoring letter case: Windows and default macOS open `.MCP.json` as `.mcp.json`. The trigger still names the path as the diff spells it. */
24870
+ const pathMatches = (entry, path) => {
24871
+ const e = entry.toLowerCase();
24872
+ const p = path.toLowerCase();
24873
+ if (e.endsWith("/") || e.includes("/")) return matches(e, p);
24874
+ return p === e || p.endsWith("/" + e);
24875
+ };
24876
+ /** Code point order, so the same input sorts the same on every runtime. */
24877
+ function cmp$8(a, b) {
24878
+ const x = [...a];
24879
+ const y = [...b];
24880
+ for (let i = 0; i < Math.min(x.length, y.length); i++) {
24881
+ const d = x[i].codePointAt(0) - y[i].codePointAt(0);
24882
+ if (d !== 0) return d < 0 ? -1 : 1;
24883
+ }
24884
+ return x.length === y.length ? 0 : x.length < y.length ? -1 : 1;
24885
+ }
24886
+ /** The line patterns of a spec as regular expressions; a pattern that does not compile (parseSecurityFile reported it as a problem) matches nothing. */
24887
+ function compileLines(spec) {
24888
+ const out = [];
24889
+ for (const p of spec.patterns) {
24890
+ if (p.kind !== "line" || p.source === void 0) continue;
24891
+ try {
24892
+ out.push({
24893
+ p,
24894
+ re: new RegExp(p.source, p.flags ?? "")
24895
+ });
24896
+ } catch {}
24897
+ }
24898
+ return out;
24899
+ }
24900
+ /** The folders an agent loads and runs code from (D-22): a skill's scripts, a sub-agent's files and the panel. Compared ignoring letter case, as path entries are. */
24901
+ const AGENT_FOLDERS = [
24902
+ ".claude/skills/",
24903
+ ".agents/skills/",
24904
+ ".claude/agents/",
24905
+ ".claude/accord-panel/"
24906
+ ];
24907
+ const underAgentFolder = (path) => {
24908
+ const p = path.toLowerCase();
24909
+ return AGENT_FOLDERS.some((f) => p.startsWith(f));
24910
+ };
24911
+ /**
24912
+ * Phase 8.1 D-20: the part of the content skip every content scan shares: a path in `exempt` (exactly an unmodified copy `accord skills sync` writes, decided by the caller), a path the
24913
+ * repository's `generated:` lists, and a Markdown file. The slop scan skips exactly these (and the package-manager files slop/match.ts lists) and judges test files; the security scan adds its test clause below.
24914
+ */
24915
+ const copyGeneratedOrMarkdown = (path, generated, exempt) => exempt.includes(path) || generated.some((e) => matches(e, path)) || MARKDOWN$1.test(path);
24916
+ /**
24917
+ * Content patterns are not run over Markdown, test files, the repository's generated paths or a path in `exempt` (exactly an unmodified copy `accord skills sync`
24918
+ * writes, decided by the caller). No folder is skipped as a whole: a file accord does not write, or a copy changed by hand, is scanned.
24919
+ * D-22: a test-named file under an agent-loaded folder (AGENT_FOLDERS) is not skipped as a test, because an agent session can run it; Markdown there stays skipped, and an
24920
+ * exempt copy or a generated path is skipped first.
24921
+ */
24922
+ const contentSkipped = (path, generated, exempt) => copyGeneratedOrMarkdown(path, generated, exempt) || isTestFile$1(path) && !underAgentFolder(path);
24923
+ /**
24924
+ * The triggers of a package: path patterns over every changed path (both sides of a rename); content patterns over the added and removed lines of
24925
+ * files that are not binary, not Markdown, not test files, not generated and not an exact `exempt` path (nothing is exempt when absent); one `cannot` trigger for each changed path the diff text does not
24926
+ * show. Deduplicated and sorted by path, then line, then pattern id.
24927
+ */
24928
+ function securityTriggers(spec, diffText, changed, options) {
24929
+ const files = diffFiles(diffText);
24930
+ const shown = /* @__PURE__ */ new Set();
24931
+ for (const f of files) {
24932
+ if (f.path !== void 0) shown.add(f.path);
24933
+ if (f.oldPath !== void 0) shown.add(f.oldPath);
24934
+ }
24935
+ const out = /* @__PURE__ */ new Map();
24936
+ const add = (t) => {
24937
+ const key = [
24938
+ t.path,
24939
+ t.line ?? "",
24940
+ t.removed === true ? "r" : "a",
24941
+ t.pattern,
24942
+ t.cannot === true ? "c" : ""
24943
+ ].join("\0");
24944
+ if (!out.has(key)) out.set(key, t);
24945
+ };
24946
+ const pathPatterns = spec.patterns.filter((p) => p.kind === "path" && p.entries !== void 0);
24947
+ for (const path of /* @__PURE__ */ new Set([...changed, ...shown])) for (const p of pathPatterns) if (p.entries.some((e) => pathMatches(e, path))) add({
24948
+ path,
24949
+ pattern: p.id,
24950
+ label: p.label
24951
+ });
24952
+ const lineRes = compileLines(spec);
24953
+ const skipped = (path) => contentSkipped(path, options.generated, options.exempt ?? []);
24954
+ const unreadable = new Set(options.unreadable ?? []);
24955
+ for (const f of files) {
24956
+ if (f.binary && f.path !== void 0 && !skipped(f.path) && !unreadable.has(f.path) && !KNOWN_BINARY.has(extensionOf$1(f.path)) && !files.some((g) => !g.binary && g.path === f.path)) add({
24957
+ path: f.path,
24958
+ pattern: "",
24959
+ label: BINARY_LABEL,
24960
+ cannot: true
24961
+ });
24962
+ if (f.binary || f.path === void 0 || skipped(f.path)) continue;
24963
+ const scanLines = (lines, removed) => {
24964
+ for (const l of lines) {
24965
+ const head = tooLong(l.text) ? l.text.slice(0, SCAN_LINE_LIMIT) : l.text;
24966
+ if (tooLong(l.text)) add({
24967
+ path: f.path,
24968
+ line: l.line,
24969
+ ...removed ? { removed: true } : {},
24970
+ pattern: "",
24971
+ label: LONG_LINE$1,
24972
+ cannot: true
24973
+ });
24974
+ for (const { p, re } of lineRes) if (re.test(head)) add({
24975
+ path: f.path,
24976
+ line: l.line,
24977
+ ...removed ? { removed: true } : {},
24978
+ pattern: p.id,
24979
+ label: p.label
24980
+ });
24981
+ }
24982
+ };
24983
+ scanLines(f.added, false);
24984
+ scanLines(f.removed, true);
24985
+ }
24986
+ for (const path of changed) if (!shown.has(path)) add({
24987
+ path,
24988
+ pattern: "",
24989
+ label: "",
24990
+ cannot: true
24991
+ });
24992
+ for (const path of options.unreadable ?? []) add({
24993
+ path,
24994
+ pattern: "",
24995
+ label: UNREADABLE,
24996
+ cannot: true
24997
+ });
24998
+ return [...out.values()].sort((a, b) => cmp$8(a.path, b.path) || (a.line ?? 0) - (b.line ?? 0) || cmp$8(a.pattern, b.pattern) || Number(a.removed === true) - Number(b.removed === true));
24999
+ }
25000
+ /** The line form of a trigger, as `accord review-package` prints it. */
25001
+ function triggerText(t) {
25002
+ if (t.cannot === true && t.line !== void 0) return `${t.path}:${t.line}${t.removed === true ? " (removed)" : ""}: (cannot tell: ${t.label})`;
25003
+ if (t.cannot === true && t.label !== "") return `(cannot tell: ${t.path}: ${t.label})`;
25004
+ if (t.cannot === true) return `(cannot tell: ${t.path} is not in the diff text)`;
25005
+ if (t.line === void 0) return `${t.path}: ${t.pattern} (${t.label})`;
25006
+ return `${t.path}:${t.line}${t.removed === true ? " (removed)" : ""}: ${t.pattern} (${t.label})`;
25007
+ }
25008
+ /**
25009
+ * The security package's hunks (D-05 (4)): for each file with a trigger, in path order, one block of text. A file with a content match prints its header lines and every
25010
+ * hunk that holds a match, whole (the package's `-U10` context), never another hunk. A file with a path match prints every hunk up to `cap` lines (300) and then
25011
+ * `(truncated: <n> more lines in <path>)`; a hunk that holds a content match is printed whole even past the cap, so a cut never hides a match. A path the diff text does not
25012
+ * show is one block, `(cannot tell: …)`. Content matches are read from the hunks themselves, with the patterns and skips securityTriggers uses, so the two agree.
25013
+ */
25014
+ function matchedHunks(spec, diffText, changed, options) {
25015
+ const cap = options.cap ?? 300;
25016
+ const triggers = securityTriggers(spec, diffText, changed, {
25017
+ generated: options.generated,
25018
+ unreadable: options.unreadable,
25019
+ exempt: options.exempt
25020
+ });
25021
+ const pathHit = new Set(triggers.filter((t) => t.cannot !== true && t.line === void 0).map((t) => t.path));
25022
+ const lineRes = compileLines(spec);
25023
+ const holds = (h) => [...h.added, ...h.removed].some((l) => {
25024
+ if (tooLong(l.text)) return true;
25025
+ return lineRes.some(({ re }) => re.test(l.text));
25026
+ });
25027
+ const blocks = [];
25028
+ const files = diffFiles(diffText);
25029
+ for (const f of files) {
25030
+ if (f.binary && f.path !== void 0 && files.some((g) => !g.binary && g.path === f.path)) continue;
25031
+ const name = f.path ?? f.oldPath;
25032
+ const byPath = f.path !== void 0 && pathHit.has(f.path) || f.oldPath !== void 0 && pathHit.has(f.oldPath);
25033
+ const content = f.binary || f.path === void 0 || contentSkipped(f.path, options.generated, options.exempt ?? []) ? /* @__PURE__ */ new Set() : new Set(f.hunks.filter(holds));
25034
+ if (!byPath && content.size === 0) continue;
25035
+ const lines = [...f.header];
25036
+ let budget = cap;
25037
+ let left = 0;
25038
+ for (const h of f.hunks) if (content.has(h)) {
25039
+ lines.push(...h.lines);
25040
+ budget = Math.max(0, budget - h.lines.length);
25041
+ } else if (byPath) {
25042
+ const take = Math.min(budget, h.lines.length);
25043
+ lines.push(...h.lines.slice(0, take));
25044
+ budget -= take;
25045
+ left += h.lines.length - take;
25046
+ }
25047
+ if (left > 0) lines.push(`(truncated: ${left} more lines in ${name})`);
25048
+ blocks.push({
25049
+ key: name ?? "",
25050
+ text: lines.join("\n")
25051
+ });
25052
+ }
25053
+ for (const t of triggers) if (t.cannot === true && t.line === void 0) blocks.push({
25054
+ key: t.path,
25055
+ text: triggerText(t)
25056
+ });
25057
+ return blocks.sort((a, b) => cmp$8(a.key, b.key)).map((b) => b.text);
25058
+ }
25059
+ /**
25060
+ * Conventional Commits 1.0.0 shape of a first line, rules 1, 4, 14 and 15: a type, an optional parenthesised scope, an optional `!`, a colon and a space, then a description.
25061
+ * The type set is open on purpose (rule 14 allows types beyond feat and fix), so accord's own bookkeeping subjects (`claim: <id>`, `plan: <id> ready`, ...) pass the preset.
25062
+ * Case-insensitive (rule 15). Run through `backtrackProblem`: no finding.
25063
+ */
25064
+ const CONVENTIONAL_PATTERN = String.raw`^[a-z][a-z0-9-]*(?:\([^()\r\n]+\))?!?: \S.*$`;
25065
+ function commitRuleOf(config) {
25066
+ const m = config?.commits?.message;
25067
+ if (m === void 0) return void 0;
25068
+ if (m.preset === "conventional") return {
25069
+ regex: new RegExp(CONVENTIONAL_PATTERN, "i"),
25070
+ text: "commits.message.preset conventional",
25071
+ example: m.example ?? "feat(cart): add coupon field"
25072
+ };
25073
+ if (m.pattern === void 0) return void 0;
25074
+ const text = `commits.message.pattern /${m.pattern}/`;
25075
+ let regex;
25076
+ try {
25077
+ regex = new RegExp(m.pattern);
25078
+ } catch (e) {
25079
+ return { problem: `${text} does not compile: ${e instanceof Error ? e.message : String(e)}` };
25080
+ }
25081
+ const slow = backtrackProblem(m.pattern, "");
25082
+ if (slow !== void 0) return { problem: `${text} can be very slow on some lines: ${slow}` };
25083
+ return {
25084
+ regex,
25085
+ text,
25086
+ example: m.example ?? ""
25087
+ };
25088
+ }
25089
+ /** The first line of a message: a byte order mark dropped, CRLF read as LF. The body is free. */
25090
+ const firstLine$1$1 = (message) => message.replace(/^\uFEFF/, "").replace(/\r\n/g, "\n").split("\n")[0] ?? "";
25091
+ /** A commit subject on its way to a terminal: every control, invisible format and separator character written as `<U+XXXX>`, so a subject cannot hide or reorder what the reader sees (T-08.1-04). */
25092
+ const visible$1 = (text) => text.replace(/[\p{Cc}\p{Cf}\p{Zl}\p{Zp}]/gu, (ch) => "<U+" + (ch.codePointAt(0) ?? 0).toString(16).toUpperCase().padStart(4, "0") + ">");
25093
+ /**
25094
+ * Why `message` breaks `rule`, or undefined when it passes. Merge commits and commits already on the default branch are exempt by the caller (they are never offered here);
25095
+ * a subject that starts `Revert "` is git's own revert subject and passes, so the executor's `git revert` of its own fix never blocks task-done.
25096
+ */
25097
+ function commitRuleProblem(rule, message) {
25098
+ const subject = firstLine$1$1(message);
25099
+ if (subject.startsWith("Revert \"")) return void 0;
25100
+ if (subject.length > 1e3) return `the first line is ${subject.length} characters, over the ${SCAN_LINE_LIMIT} accord checks against ${rule.text} - fix: shorten the first line and move detail into the message body`;
25101
+ return rule.regex.test(subject) ? void 0 : `"${visible$1(subject)}" does not match ${rule.text}`;
25102
+ }
25103
+ /**
25104
+ * The one reason task-done prints and `gate.commit-message` reports for a commit that breaks the rule (D-07: every refusal names its fix). A commit accord wrote from a
25105
+ * `commits.subjects` template is fixed at the template first, and `accord lint` names the key and one that passes; a code commit is reworded.
25106
+ */
25107
+ function commitRuleRefusal(sha, problem) {
25108
+ return `commit ${sha.slice(0, 8)} ${problem} - fix: reword it so its first line passes (check the message first with accord commit check <file>); for a subject accord wrote from a commits.subjects template, set that template first (accord lint names the key and one that passes), then reword the commit to what accord subject <name> <id> prints`;
25109
+ }
25110
+ /** The reason when `commits.message` cannot be put in force (D-04: a broken rule never passes silently): it names `accord lint`, which reports the pattern. */
25111
+ const commitRuleNotInForce = (problem) => `${problem} - fix: run accord lint, which names the pattern to change; until it is in force no commit is judged, so the gate fails closed`;
25112
+ /** One line naming the rule, for the brief and the anchor. */
25113
+ function commitRuleLine(rule) {
25114
+ return `the first line of every commit message matches ${rule.text}`;
25115
+ }
25116
+ const ticketFile$5 = (id) => "accord/tickets/" + id + ".md";
25117
+ const verificationFile = (id) => "accord/tickets/" + id + "/verification.md";
25118
+ const ticketOf$2 = (snapshot, id) => Object.hasOwn(snapshot.tickets, id) ? snapshot.tickets[id] : void 0;
25119
+ const verificationOf$1 = (snapshot, id) => Object.hasOwn(snapshot.verifications, id) ? snapshot.verifications[id] : void 0;
25120
+ /** The `## Acceptance criteria` heading line, or undefined when the ticket has no such section. */
25121
+ const acLine = (snapshot, id) => ticketOf$2(snapshot, id)?.sections.find((s) => headingKey(s.heading) === "acceptance criteria")?.line;
25122
+ const at = (line) => line === void 0 ? {} : { line };
25123
+ /** Distinct `ac-n` tags sorted by their numeric part, so a reason reads the same on every host. */
25124
+ const tagsOf = (tags) => [...new Set(tags)].sort((a, b) => Number(a.slice(3)) - Number(b.slice(3)));
25125
+ /** `nothing` for an empty list, otherwise the `@ac-n` tokens in numeric order. */
25126
+ const fmt = (tags) => tags.length === 0 ? "nothing" : tags.map((t) => "@" + t).join(" ");
25127
+ const scenarioTags = (snapshot, id) => tagsOf((ticketOf$2(snapshot, id)?.scenarios ?? []).flatMap((s) => s.acTag === void 0 ? [] : [s.acTag]));
25128
+ const evidenceTags = (snapshot, id) => tagsOf((verificationOf$1(snapshot, id)?.blocks ?? []).map((b) => b.acTag));
25129
+ const tickTags = (snapshot, id) => tagsOf(ticketOf$2(snapshot, id)?.frontmatter?.verified ?? []);
25130
+ /** D-81: at least 7 characters and every one of them hexadecimal. Shorter values never compare equal. */
25131
+ function isSha(v) {
25132
+ return v.length >= 7 && /^[0-9a-fA-F]+$/.test(v);
25133
+ }
25134
+ /**
25135
+ * D-81: equal when, compared case-insensitively, the shorter is a prefix of the longer and both are
25136
+ * shas. git abbreviates to variable lengths, so a 7-character value must match a 40-character one.
25137
+ */
25138
+ function shaEqual(a, b) {
25139
+ if (!isSha(a) || !isSha(b)) return false;
25140
+ const x = a.toLowerCase();
25141
+ const y = b.toLowerCase();
25142
+ return x.length <= y.length ? y.startsWith(x) : x.startsWith(y);
25143
+ }
25144
+ /**
25145
+ * GATE-02 empty set: three empty sets are trivially equal, which would let a ticket with no scenario
25146
+ * pass Done vacuously. This fires on every ticket type, so an `epic` cannot slip through either.
25147
+ */
25148
+ const noScenarios$1 = (snapshot, id) => {
25149
+ if (ticketOf$2(snapshot, id) === void 0 || scenarioTags(snapshot, id).length > 0) return [];
25150
+ return [{
25151
+ file: ticketFile$5(id),
25152
+ ...at(acLine(snapshot, id)),
25153
+ reason: "no scenario carries an @ac-n tag, so Done has nothing to be claimed about"
24903
25154
  }];
24904
- const done = work.ledger?.done ?? {};
24905
- return work.plan.tasks.filter((t) => !Object.hasOwn(done, String(t.n))).map((t) => ({
24906
- file: planFile(id),
24907
- line: t.line,
24908
- reason: `task ${t.n} has no completion line in ${ledgerFile(id)}; run accord task-done ${id} ${t.n}`
25155
+ };
25156
+ /**
25157
+ * GATE-02: the scenario tags, the `## @ac-n` evidence blocks, and `verified` must be the same set.
25158
+ * One finding naming each side's gap, mirroring lint.plan-tags-differ, in the fixed order scenarios,
25159
+ * evidence, verified. `noScenarios` owns the all-empty case.
25160
+ */
25161
+ const tagsDiffer = (snapshot, id) => {
25162
+ if (ticketOf$2(snapshot, id) === void 0) return [];
25163
+ const scenarios = scenarioTags(snapshot, id);
25164
+ const evidence = evidenceTags(snapshot, id);
25165
+ const verified = tickTags(snapshot, id);
25166
+ const union = tagsOf([
25167
+ ...scenarios,
25168
+ ...evidence,
25169
+ ...verified
25170
+ ]);
25171
+ if (union.length === 0 || [
25172
+ scenarios,
25173
+ evidence,
25174
+ verified
25175
+ ].every((s) => s.length === union.length)) return [];
25176
+ const lacks = (set) => fmt(union.filter((t) => !set.includes(t)));
25177
+ return [{
25178
+ file: ticketFile$5(id),
25179
+ ...at(acLine(snapshot, id)),
25180
+ reason: `scenarios lack ${lacks(scenarios)}; evidence lacks ${lacks(evidence)}; verified lacks ${lacks(verified)}`
25181
+ }];
25182
+ };
25183
+ /** docs/design.md §5: the Fresh-context layer needs a review record; there is no Done without one. */
25184
+ const verificationMissing = (snapshot, id) => {
25185
+ if (ticketOf$2(snapshot, id) === void 0 || verificationOf$1(snapshot, id) !== void 0) return [];
25186
+ return [{
25187
+ file: verificationFile(id),
25188
+ reason: "no review record; Done needs " + verificationFile(id)
25189
+ }];
25190
+ };
25191
+ /**
25192
+ * The ticket when it carries `lane:` other than S and R: the lanes whose gate tables hold the plan, Done and debug rules of lane M, so the ones the unfinished-marker rules apply to (unfinishedPlan, unfinishedVerification
25193
+ * and unfinishedDebug; ST-LN-72 review round 2). The one lane test of the three. It lives here, and work.ts re-exports it next to laneTicket, because work.ts imports this file.
25194
+ */
25195
+ const stageLaneTicket = (snapshot, id) => {
25196
+ const t = ticketOf$2(snapshot, id);
25197
+ const lane = t?.frontmatter?.lane;
25198
+ return lane === void 0 || lane === "S" || lane === "R" ? void 0 : t;
25199
+ };
25200
+ /**
25201
+ * The verification.md of a lane ticket that runs the Done table of lane M (stageLaneTicket) and still carries UNFINISHED_MARKER; undefined otherwise. The one predicate for gate done's refusal and for the
25202
+ * Unfinished line of `accord anchor` (status/anchor.ts).
25203
+ */
25204
+ const unfinishedVerification = (snapshot, id) => {
25205
+ const v = verificationOf$1(snapshot, id);
25206
+ return v?.unfinished === void 0 || stageLaneTicket(snapshot, id) === void 0 ? void 0 : v;
25207
+ };
25208
+ /**
25209
+ * ST-LN-72 D-11 and D-18: a verification.md that still carries UNFINISHED_MARKER is a record the verifier has not finished, so it never passes Done, at any strictness setting (the rule is on the
25210
+ * floor, gate/floor.ts). A lane M, L or P ticket, whatever its claim pin: the owner's decision of 2026-11-16, an exception to D-16 (only a 0.6.0 agent writes the marker, so a ticket claimed earlier cannot be
25211
+ * refused wrongly, and exempting it would let a stalled agent's half-written record through after an upgrade).
25212
+ * It reads no `config.runtimes`: the rule is a CLI check, so it holds in all four tools whether or not an accord agent is installed.
25213
+ */
25214
+ const verificationUnfinished = (snapshot, id) => {
25215
+ const v = unfinishedVerification(snapshot, id);
25216
+ if (v?.unfinished === void 0) return [];
25217
+ return [{
25218
+ file: v.file,
25219
+ line: v.unfinished,
25220
+ reason: `${v.file} still carries the line ${UNFINISHED_MARKER}: the verifier has not finished; the verify stage resumes it, or starts it over when HEAD moved`
25221
+ }];
25222
+ };
25223
+ /** docs/design.md §5: `blocked` fails Done exactly as `fail` does. A missing or invalid `Result:` is
25224
+ * already load.result-invalid at error in ticket scope, so it needs no rule here (D-58). */
25225
+ const resultNotPass = (snapshot, id) => {
25226
+ const v = verificationOf$1(snapshot, id);
25227
+ if (v === void 0) return [];
25228
+ return v.blocks.filter((b) => b.result === "fail" || b.result === "blocked").map((b) => ({
25229
+ file: v.file,
25230
+ line: b.line,
25231
+ reason: `evidence block "@${b.acTag}" records Result: ${b.result}`
24909
25232
  }));
24910
25233
  };
24911
- /** Spec §10: there is no Done without a review record. */
24912
- const reviewMissing = (snapshot, id) => {
24913
- if (laneTicket(snapshot, id) === void 0 || workOf(snapshot, id)?.review !== void 0) return [];
25234
+ const frontmatterOf = (snapshot, id) => ticketOf$2(snapshot, id)?.frontmatter;
25235
+ /** The AC hash as it stands now; undefined only when no scenario carries an `@ac-n` tag (`noScenarios`). */
25236
+ const computed = (snapshot, id) => acHash(ticketOf$2(snapshot, id)?.scenarios ?? []);
25237
+ /**
25238
+ * D-81 and the D-80 no-bypass reasoning: a host that supplies no commit cannot have Done reported as
25239
+ * skipped, or deleting one field from the input would remove every commit check at once.
25240
+ */
25241
+ const commitMissing = (snapshot, id) => {
25242
+ if (ticketOf$2(snapshot, id) === void 0 || snapshot.git?.commit !== void 0) return [];
24914
25243
  return [{
24915
- file: reviewFile(id),
24916
- reason: "no review record; Done needs " + reviewFile(id)
25244
+ file: ticketFile$5(id),
25245
+ reason: "the host supplied no commit for the gated tree; Done cannot bind a tick"
24917
25246
  }];
24918
25247
  };
24919
- /** Spec §10: the review loop ended in convergence, or the owner accepted it at the cap. */
24920
- const reviewUnconverged = (snapshot, id) => {
24921
- const review = laneTicket(snapshot, id) === void 0 ? void 0 : workOf(snapshot, id)?.review;
24922
- if (review === void 0 || VERDICTS.includes(review.verdict ?? "")) return [];
25248
+ /**
25249
+ * D-81: anything shorter than 7 hex characters is not a sha and never compares equal. One draft per
25250
+ * source, so one bad character produces one reason rather than a mismatch finding on top of it.
25251
+ */
25252
+ const shaTooShort = (snapshot, id) => {
25253
+ if (ticketOf$2(snapshot, id) === void 0) return [];
25254
+ const host = snapshot.git?.commit;
25255
+ const tick = frontmatterOf(snapshot, id)?.verified_commit;
25256
+ const review = verificationOf$1(snapshot, id)?.frontmatter?.commit;
25257
+ const bad = (v) => `"${v}" is not a commit sha; at least 7 hexadecimal characters are needed`;
25258
+ return [
25259
+ ...host !== void 0 && !isSha(host) ? [{
25260
+ file: ticketFile$5(id),
25261
+ reason: "host commit " + bad(host)
25262
+ }] : [],
25263
+ ...tick !== void 0 && !isSha(tick) ? [{
25264
+ file: ticketFile$5(id),
25265
+ pointer: "/verified_commit",
25266
+ reason: "verified_commit " + bad(tick)
25267
+ }] : [],
25268
+ ...review !== void 0 && !isSha(review) ? [{
25269
+ file: verificationFile(id),
25270
+ pointer: "/commit",
25271
+ reason: "the review commit " + bad(review)
25272
+ }] : []
25273
+ ];
25274
+ };
25275
+ /** GATE-03: Done cannot tell whether the criteria moved if Ready never recorded where they were. */
25276
+ const acHashMissing = (snapshot, id) => {
25277
+ const fm = frontmatterOf(snapshot, id);
25278
+ if (fm === void 0 || fm.ac_hash !== void 0 || computed(snapshot, id) === void 0) return [];
25279
+ return [{
25280
+ file: ticketFile$5(id),
25281
+ pointer: "/ac_hash",
25282
+ reason: "Ready has recorded no ac_hash for this ticket"
25283
+ }];
25284
+ };
25285
+ /**
25286
+ * GATE-03: exact string comparison, prefix included, so a change of hash algorithm fails loudly instead
25287
+ * of comparing a new digest against an old one and reading as a change of criteria (D-75).
25288
+ */
25289
+ const acChanged = (snapshot, id) => {
25290
+ const recorded = frontmatterOf(snapshot, id)?.ac_hash;
25291
+ const now = computed(snapshot, id);
25292
+ if (recorded === void 0 || now === void 0 || recorded === now) return [];
25293
+ return [{
25294
+ file: ticketFile$5(id),
25295
+ pointer: "/ac_hash",
25296
+ reason: `the acceptance criteria changed since Ready: ac_hash records ${recorded}, they hash to ${now} now`
25297
+ }];
25298
+ };
25299
+ /** D-76: a tick with no binding is a claim about nothing; there is no compatibility path in v0.1. */
25300
+ const tickUnbound = (snapshot, id) => {
25301
+ const fm = frontmatterOf(snapshot, id);
25302
+ if (fm === void 0 || (fm.verified ?? []).length === 0) return [];
25303
+ const missing = [...fm.verified_hash === void 0 ? ["verified_hash"] : [], ...fm.verified_commit === void 0 ? ["verified_commit"] : []];
25304
+ if (missing.length === 0) return [];
25305
+ return [{
25306
+ file: ticketFile$5(id),
25307
+ pointer: "/verified",
25308
+ reason: `verified is set but ${missing.join(" and ")} ${missing.length > 1 ? "are" : "is"} not recorded`
25309
+ }];
25310
+ };
25311
+ /** GATE-11: the ticks were made against criteria that have since moved. */
25312
+ const tickStaleHash = (snapshot, id) => {
25313
+ const recorded = frontmatterOf(snapshot, id)?.verified_hash;
25314
+ const now = computed(snapshot, id);
25315
+ if (recorded === void 0 || now === void 0 || recorded === now) return [];
24923
25316
  return [{
24924
- file: review.file,
24925
- ...review.line === void 0 ? {} : { line: review.line },
24926
- reason: review.verdict === void 0 ? "the review record has no verdict: line" : `the review verdict is "${review.verdict}"; Done needs converged or accepted-by-owner`
25317
+ file: ticketFile$5(id),
25318
+ pointer: "/verified_hash",
25319
+ reason: `the ticks were made against ${recorded}; the acceptance criteria hash to ${now} now`
24927
25320
  }];
24928
25321
  };
25322
+ /** Every path is the ticket's own file, lies in its folder (spec §11), or is accord/product/conventions.md (ST-LN-8 D-08). */
25323
+ const ownRecordsOnly = (id, paths) => paths.every((p) => p === ticketFile$5(id) || p === "accord/product/conventions.md" || p.startsWith("accord/tickets/" + id + "/"));
25324
+ /** A commit that changes a path outside the ticket's own records, or a merge whose own changes git could not show. */
25325
+ const handMade = (id, c) => c.files === void 0 || !ownRecordsOnly(id, c.files);
25326
+ /** A later commit that changed only this ticket's own records (its file and folder) or accord/product/conventions.md is the same reviewed code. */
25327
+ const onlyOwnRecords = (snapshot, id, recorded) => {
25328
+ const since = snapshot.recordsSince;
25329
+ if (since === void 0 || !Object.hasOwn(since, recorded)) return false;
25330
+ return ownRecordsOnly(id, since[recorded]);
25331
+ };
24929
25332
  /**
24930
- * Spec §11: the report is the full suite's output, and any failed case fails Done. A lane ticket needs a
24931
- * loaded report even when every scenario is @ui, so an all-@ui ticket cannot pass with no suite at all.
25333
+ * ST-LN-96 D-04: the recorded commit is not in the gated commit's history, so the host compared the contents of the ticket's files.
25334
+ * `{ pass }`: none differs; `{ reason }`: the refusal's wording; undefined: the host supplied no fact for it, and today's reason stands.
24932
25335
  */
24933
- const suiteNotPassed = (snapshot, id) => {
24934
- if (laneTicket(snapshot, id) === void 0) return [];
24935
- const report = reportPath$1(snapshot);
24936
- if (report === void 0) return [{
24937
- file: "accord/config.yml",
24938
- pointer: "/tests",
24939
- reason: "no test report is configured; Done for a lane ticket needs the full suite's report in tests.report"
24940
- }];
24941
- if (!reportLoaded(snapshot)) return [{
24942
- file: "accord/config.yml",
24943
- pointer: "/tests/report",
24944
- reason: `no report at ${normaliseKey(report)}; Done for a lane ticket needs the full suite's report`
25336
+ const contentVerdict = (snapshot, recorded, host, what, today) => {
25337
+ const facts = snapshot.contentSince;
25338
+ const key = recorded.toLowerCase();
25339
+ if (facts === void 0 || !Object.hasOwn(facts, key)) return void 0;
25340
+ const fact = facts[key];
25341
+ if ("absent" in fact) return { reason: `${today}; the verified commit is not in this clone, so its contents cannot be compared - verify again` };
25342
+ if (fact.changed.length === 0) return { pass: true };
25343
+ return { reason: `${what === "ticks" ? "the ticks were made" : "the review was written"} against commit ${recorded}, which is not in the history of the gated commit ${host}; these ticket files changed since: ${fact.changed.join(", ")}` };
25344
+ };
25345
+ /** GATE-11: the ticks were made against a different commit. Both values are guarded on `isSha` first,
25346
+ * so a too-short value produces `gate.sha-too-short` alone and never two reasons for one typo (D-81). */
25347
+ const tickStaleCommit = (snapshot, id) => {
25348
+ const tick = frontmatterOf(snapshot, id)?.verified_commit;
25349
+ const host = snapshot.git?.commit;
25350
+ if (tick === void 0 || host === void 0 || !isSha(tick) || !isSha(host) || shaEqual(tick, host)) return [];
25351
+ if (onlyOwnRecords(snapshot, id, tick)) return [];
25352
+ const today = `the ticks were made against commit ${tick}; the gated commit is ${host}`;
25353
+ const content = contentVerdict(snapshot, tick, host, "ticks", today);
25354
+ if (content !== void 0 && "pass" in content) return [];
25355
+ return [{
25356
+ file: ticketFile$5(id),
25357
+ pointer: "/verified_commit",
25358
+ reason: content === void 0 ? today : content.reason
24945
25359
  }];
24946
- const tests = snapshot.tests ?? {};
24947
- const failed = Object.keys(tests).filter((k) => tests[k] === "failed").sort();
24948
- if (failed.length === 0) return [];
24949
- const shown = failed.slice(0, 5).join(", ") + (failed.length > 5 ? ", ..." : "");
25360
+ };
25361
+ /** ROADMAP criterion 2 and docs/design.md §5: the review must be of the code being gated. */
25362
+ const staleReview = (snapshot, id) => {
25363
+ const review = verificationOf$1(snapshot, id)?.frontmatter?.commit;
25364
+ const host = snapshot.git?.commit;
25365
+ if (review === void 0 || host === void 0 || !isSha(review) || !isSha(host) || shaEqual(review, host)) return [];
25366
+ if (onlyOwnRecords(snapshot, id, review)) return [];
25367
+ const today = `the review was written against commit ${review}; the gated commit is ${host}`;
25368
+ const content = contentVerdict(snapshot, review, host, "review", today);
25369
+ if (content !== void 0 && "pass" in content) return [];
24950
25370
  return [{
24951
- file: normaliseKey(report),
24952
- reason: `${failed.length} test case${failed.length === 1 ? "" : "s"} failed in the report: ${shown}`
25371
+ file: verificationFile(id),
25372
+ pointer: "/commit",
25373
+ reason: content === void 0 ? today : content.reason
24953
25374
  }];
24954
25375
  };
24955
- /** Spec §9 at Done: the warning lint gives becomes an error for a lane ticket. */
24956
- const testUntracedAtDone = (snapshot, id) => {
24957
- const report = reportPath$1(snapshot);
24958
- if (laneTicket(snapshot, id) === void 0 || report === void 0 || !reportLoaded(snapshot)) return [];
24959
- return untracedTests(snapshot).map((t) => ({
24960
- file: normaliseKey(report),
24961
- reason: UNTRACED(t)
24962
- }));
25376
+ const CONFIG$3 = "accord/config.yml";
25377
+ /** ST-LN-8 D-02: under commits.trailers forbid, every commit the host loaded for this branch is read for forbidden lines; undefined commits fail closed. */
25378
+ const commitTrailer = (snapshot, id) => {
25379
+ if (ticketOf$2(snapshot, id) === void 0 || snapshot.config?.commits?.trailers !== "forbid") return [];
25380
+ const at = {
25381
+ file: CONFIG$3,
25382
+ pointer: "/commits/trailers"
25383
+ };
25384
+ if (snapshot.commits === void 0) return [{
25385
+ ...at,
25386
+ reason: "commits.trailers is forbid, but the host loaded no commits of this branch, so they cannot be checked"
25387
+ }];
25388
+ return snapshot.commits.flatMap((c) => forbiddenLines(c.message).map((l) => ({
25389
+ ...at,
25390
+ reason: trailerReason(c.sha, l)
25391
+ })));
24963
25392
  };
24964
25393
  /**
24965
- * Spec §10: changed paths that no task's `files:` names exactly or, for a token ending in `/`, contains.
24966
- * The ticket's own records are never listed. Sorted, unique; undefined when the ticket has no plan.
25394
+ * Phase 8.1 D-06, D-07: under `commits.message` every commit the host loaded for this branch (the first-parent commits not on the default ref) is judged by the one core function
25395
+ * `commitRuleProblem`, a merge commit and a `Revert "` subject excepted. Read through claimPinBefore: a ticket claimed before COMMIT_MESSAGE_FROM is not judged. A pattern that is not in
25396
+ * force, and commits the host did not load, fail closed; every reason names its fix.
24967
25397
  */
24968
- function undeclaredFiles(snapshot, id, changed) {
24969
- const tasks = laneTicket(snapshot, id) === void 0 ? void 0 : workOf(snapshot, id)?.plan?.tasks;
24970
- if (tasks === void 0) return void 0;
24971
- const declared = tasks.flatMap((t) => [...t.files, ...t.newFiles]);
24972
- const own = "accord/tickets/" + id;
24973
- const research = addedResearch(snapshot, id);
24974
- return [...new Set(changed)].filter((p) => p !== own + ".md" && !p.startsWith(own + "/") && !research.includes(p)).filter((p) => !declared.some((d) => d.endsWith("/") ? p.startsWith(d) : p === d)).sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
24975
- }
24976
- const ticketFile$5 = (id) => "accord/tickets/" + id + ".md";
24977
- const cmp$9 = (a, b) => a < b ? -1 : a > b ? 1 : 0;
24978
- /** The paths a ticket's `## Scope` section lists, one per line, or undefined when it has no such section. */
24979
- function scopeLines(text) {
24980
- const { body, bodyOffset } = splitFrontmatter(normaliseText(text));
24981
- const section = scan(body, bodyOffset).sections.find((s) => headingKey(s.heading) === "scope");
24982
- if (section === void 0) return void 0;
24983
- return stripHtmlComments(section.lines).map((l) => l.text.trim().replace(/^[-*+]\s+/, "").trim()).map((t) => t.length >= 2 && t.startsWith("`") && t.endsWith("`") ? t.slice(1, -1) : t).map((t) => t.replace(/\\/g, "/")).filter((t) => t !== "");
24984
- }
24985
- const factOf$1 = (s, id) => s.branchFacts !== void 0 && Object.hasOwn(s.branchFacts, id) ? s.branchFacts[id] : void 0;
24986
- /** An entry matches a path when it ends in `/` and the path starts with it, or when the two are equal. No globs. */
24987
- const matches = (entry, path) => entry.endsWith("/") ? path.startsWith(entry) : entry === path;
24988
- /** Ledger Ruling 9: the ticket's own files, the files `accord skills sync` writes, and the merge-base config's `generated:` paths. */
24989
- function isExempt(id, fact, path, own = []) {
24990
- if (path === ticketFile$5(id) || path.startsWith("accord/tickets/" + id + "/")) return true;
24991
- if (own.includes(path)) return true;
24992
- if (fact.synced.includes(path)) return true;
24993
- if (path === ".claude/settings.json") return false;
24994
- return configLists(fact.baseConfig).generated.some((e) => matches(e, path));
24995
- }
24996
- /** A change that only moves whitespace, blank lines or line endings has `lines: 0` and is never counted (D-02). */
24997
- const isCounted = (c) => c.kind !== "modified" || c.binary === true || c.lines > 0;
24998
- /** Lane S: the counted, non-exempt changed paths outside the recorded scope; `cannot` when no scope can be read. */
24999
- function outsideScope(s, id) {
25000
- if (laneTicket(s, id)?.frontmatter?.lane !== "S") return void 0;
25001
- const fact = factOf$1(s, id);
25002
- if (fact === void 0 || "error" in fact) return void 0;
25003
- if (fact.scope === void 0) return { cannot: `no commit on this branch records ac_hash in ${ticketFile$5(id)}, so the ## Scope that gate ready fixed cannot be read; commit the ticket after accord gate ready ${id}` };
25004
- const { commit, paths } = fact.scope;
25005
- if (paths.length === 0) return { cannot: `## Scope held no path when ac_hash was first recorded (commit ${commit}); a lane S ticket lists the files it expects to touch before any change, so it must be lifted to lane M` };
25006
- const own = addedResearch(s, id);
25007
- return { paths: fact.changes.filter((c) => isCounted(c) && !isExempt(id, fact, c.path, own) && !paths.includes(c.path)).map((c) => c.path).sort(cmp$9) };
25008
- }
25009
- const changesTicket = (fact, id) => fact.changes.some((c) => c.path === ticketFile$5(id));
25010
- const hasChanges = (fact) => fact.changes.length > 0;
25011
- const branchUnknown = (s, id) => {
25012
- if (laneTicket(s, id) === void 0) return [];
25013
- const file = ticketFile$5(id);
25014
- const fact = factOf$1(s, id);
25015
- if (fact === void 0) return [{
25016
- file,
25017
- reason: "the host loaded no branch diff for this ticket, so the files it changed cannot be checked"
25018
- }];
25019
- if ("error" in fact) return [{
25020
- file,
25021
- reason: fact.error
25022
- }];
25023
- if (!hasChanges(fact)) return [{
25024
- file,
25025
- reason: `the branch diff from ${fact.base}, the merge base with the default branch, to HEAD is empty: HEAD adds no change over the merge base; lane work is committed on the ticket's own branch, never on the default branch`
25026
- }];
25027
- if (laneTicket(s, id)?.frontmatter?.lane === "S" && !changesTicket(fact, id)) return [{
25028
- file,
25029
- reason: `the branch diff from ${fact.base}, the merge base with the default branch, does not change ${file}; lane work is committed on the ticket's own branch, never on the default branch`
25398
+ const commitMessage$1 = (snapshot, id) => {
25399
+ if (ticketOf$2(snapshot, id) === void 0 || snapshot.config?.commits?.message === void 0 || claimPinBefore(snapshot, id, "0.9.0")) return [];
25400
+ const at = {
25401
+ file: CONFIG$3,
25402
+ pointer: "/commits/message"
25403
+ };
25404
+ const rule = commitRuleOf(snapshot.config);
25405
+ if (rule === void 0) return [];
25406
+ if ("problem" in rule) return [{
25407
+ ...at,
25408
+ reason: commitRuleNotInForce(rule.problem)
25030
25409
  }];
25031
- return [];
25032
- };
25033
- const outOfScope = (s, id) => {
25034
- const fact = factOf$1(s, id);
25035
- if (fact === void 0 || "error" in fact || !changesTicket(fact, id)) return [];
25036
- const out = outsideScope(s, id);
25037
- if (out === void 0) return [];
25038
- const file = ticketFile$5(id);
25039
- if ("cannot" in out) return [{
25040
- file,
25041
- reason: out.cannot
25410
+ if (snapshot.commits === void 0) return [{
25411
+ ...at,
25412
+ reason: "commits.message is set, but the host loaded no commits of this branch, so they cannot be checked - fix: run accord gate done in the ticket's checkout, where git reads the branch"
25042
25413
  }];
25043
- const commit = fact.scope?.commit ?? "";
25044
- const work = workOf(s, id);
25045
- const declared = new Set((work?.ledger?.wordingOnly ?? []).map((w) => w.path));
25046
- const confirmed = work?.review?.confirmed ?? [];
25047
- return out.paths.flatMap((p) => {
25048
- if (!declared.has(p)) return [{
25049
- file,
25050
- reason: `${p} is changed on this branch but not listed in ## Scope as recorded at commit ${commit}; the ticket must be lifted to lane M`
25051
- }];
25052
- const why = wordingOnlyFault(fact.changes.find((c) => c.path === p), p, confirmed, id);
25053
- return why === void 0 ? [] : [{
25054
- file,
25055
- reason: `${p} is declared wording-only in ${ledgerFile(id)} but ${why}; the ticket must be lifted to lane M`
25414
+ return snapshot.commits.flatMap((c) => {
25415
+ const problem = c.merge === true ? void 0 : commitRuleProblem(rule, c.message);
25416
+ return problem === void 0 ? [] : [{
25417
+ ...at,
25418
+ reason: commitRuleRefusal(c.sha, problem)
25056
25419
  }];
25057
25420
  });
25058
25421
  };
25059
- /** The base entries of `sensitive:` then the HEAD entries, in key order, each (area, path) pair once. */
25060
- function sensitiveEntries(s, fact) {
25061
- const head = Object.entries(s.config?.sensitive ?? {}).flatMap(([area, paths]) => paths.map((path) => ({
25062
- area,
25063
- path
25064
- })));
25065
- const seen = /* @__PURE__ */ new Set();
25066
- return [...configLists(fact.baseConfig).sensitive, ...head].filter((e) => {
25067
- const key = e.area + "\0" + e.path;
25068
- if (seen.has(key)) return false;
25069
- seen.add(key);
25070
- return true;
25071
- });
25072
- }
25073
- /** Lane S: a counted change under a listed sensitive entry fails, whatever its scope, declaration or exemption (D-04, Ruling 29). */
25074
- const sensitiveTouched = (s, id) => {
25075
- if (laneTicket(s, id)?.frontmatter?.lane !== "S") return [];
25076
- const fact = factOf$1(s, id);
25077
- if (fact === void 0 || "error" in fact) return [];
25078
- const entries = sensitiveEntries(s, fact);
25079
- const file = ticketFile$5(id);
25080
- return fact.changes.filter(isCounted).flatMap((c) => {
25081
- const hit = entries.find((e) => matches(e.path, c.path));
25082
- return hit === void 0 ? [] : [{
25083
- file,
25084
- reason: `${c.path} is in the sensitive area ${hit.area} (accord/config.yml lists ${hit.path} under sensitive); the ticket must be lifted to lane M`
25085
- }];
25086
- });
25422
+ const isTest$1 = (tag) => tag.startsWith("@test:");
25423
+ /** Every scenario the machine layer applies to: `@ui` leans on the human layer instead (D-90, GATE-09). */
25424
+ const machineScenarios = (snapshot, id) => (ticketOf$2(snapshot, id)?.scenarios ?? []).filter((s) => !s.tags.includes("@ui"));
25425
+ /** The configured report path, or undefined when `config.yml` declares no `tests.report`. */
25426
+ const reportPath$1 = (snapshot) => snapshot.config?.tests?.report;
25427
+ /** True only when a report was declared *and* its file reached the snapshot; the join runs on nothing else. */
25428
+ const reportLoaded = (snapshot) => {
25429
+ const report = reportPath$1(snapshot);
25430
+ return report !== void 0 && Object.hasOwn(snapshot.files, normaliseKey(report));
25431
+ };
25432
+ /**
25433
+ * GATE-08: a scenario is either machine-checked or `@ui`. This is a property of the ticket, not of the
25434
+ * report, so it fires whether or not a report is configured — the two configuration reasons below
25435
+ * suppress the per-scenario join, never this.
25436
+ */
25437
+ const testTagMissing$1 = (snapshot, id) => machineScenarios(snapshot, id).filter((s) => !s.tags.some(isTest$1)).map((s) => ({
25438
+ file: ticketFile$5(id),
25439
+ line: s.line,
25440
+ reason: `scenario "${s.name}" carries no @test:<id> tag and is not @ui, so Done cannot check it against the report`
25441
+ }));
25442
+ /**
25443
+ * D-80: no `tests.report` at all fails Done. It is not reported skipped — GATE-06 forbids a bypass, and
25444
+ * deleting one line from `config.yml` would otherwise remove the whole Machine layer at once.
25445
+ */
25446
+ const testsUnconfigured = (snapshot, id) => {
25447
+ if (reportPath$1(snapshot) !== void 0 || machineScenarios(snapshot, id).length === 0) return [];
25448
+ return [{
25449
+ file: CONFIG$3,
25450
+ pointer: "/tests",
25451
+ reason: "no test report is declared, so the machine layer cannot run and Done cannot pass; set tests.report"
25452
+ }];
25087
25453
  };
25088
- /** Ledger Ruling 13: an added line that calls a commander-style `command` or `option`. */
25089
- const CALL_SIGN = /\.(command|option)\(/;
25090
- /** The keys of the `exports` or `bin` map of a package.json text; a string value counts as the key `.`. */
25091
- function keysOf(text, map) {
25092
- if (text === void 0) return [];
25093
- try {
25094
- const value = JSON.parse(text)?.[map];
25095
- if (typeof value === "string") return ["."];
25096
- return typeof value === "object" && value !== null && !Array.isArray(value) ? Object.keys(value) : [];
25097
- } catch {
25098
- return [];
25099
- }
25100
- }
25101
- const isPackageJson = (path) => path === "package.json" || path.endsWith("/package.json");
25102
- /** Ledger Ruling 20: a call sign is read only in a non-Markdown file the ticket's own exemptions do not cover. */
25103
- const callsOf = (c, id, fact) => c.calls === void 0 || /\.(md|markdown)$/i.test(c.path) || isExempt(id, fact, c.path) ? [] : [...new Set(c.calls.flatMap((l) => [...l.matchAll(new RegExp(CALL_SIGN.source, "g"))].map((m) => m[1])))];
25104
- /** D-04: signs of a new interface in paths no sensitive entry matches; undefined without a lane ticket or a readable diff. */
25105
- function interfaceSigns(s, id) {
25106
- if (laneTicket(s, id) === void 0) return void 0;
25107
- const fact = factOf$1(s, id);
25108
- if (fact === void 0 || "error" in fact) return void 0;
25109
- const entries = sensitiveEntries(s, fact);
25110
- const out = [];
25111
- for (const c of fact.changes) {
25112
- if (entries.some((e) => matches(e.path, c.path))) continue;
25113
- const add = (sign) => out.push({
25114
- path: c.path,
25115
- sign
25116
- });
25117
- if (c.kind === "added" && (c.path.split("/").slice(0, -1).includes("schemas") || c.path.endsWith(".schema.json"))) add("a new schema file");
25118
- if (isPackageJson(c.path)) for (const map of ["exports", "bin"]) {
25119
- const before = keysOf(c.pkg?.base, map);
25120
- keysOf(c.pkg?.head, map).filter((k) => !before.includes(k)).forEach((k) => add(`a new key "${k}" in the ${map} map of package.json`));
25121
- }
25122
- callsOf(c, id, fact).forEach((name) => add(`an added line that calls .${name}(`));
25123
- }
25124
- return out.sort((a, b) => cmp$9(a.path, b.path) || cmp$9(a.sign, b.sign));
25125
- }
25126
- const interfaceSign = (s, id) => {
25127
- const signs = interfaceSigns(s, id);
25128
- if (signs === void 0) return [];
25129
- const file = ticketFile$5(id);
25130
- if (laneTicket(s, id)?.frontmatter?.lane === "S") return signs.map(({ path, sign }) => ({
25131
- file,
25132
- reason: `${path} adds ${sign}, a sign of a new interface; the ticket must be lifted to lane M`
25454
+ /** D-80 extended: declaring the key and deleting the file is the same hole, so it closes the same way. */
25455
+ const reportMissing$1 = (snapshot, id) => {
25456
+ const report = reportPath$1(snapshot);
25457
+ if (report === void 0 || reportLoaded(snapshot) || machineScenarios(snapshot, id).length === 0) return [];
25458
+ return [{
25459
+ file: CONFIG$3,
25460
+ pointer: "/tests/report",
25461
+ reason: `tests.report "${report}" is not in the snapshot`
25462
+ }];
25463
+ };
25464
+ /** The `@test:` ids of the machine-checked scenarios, paired with the line to report them on. */
25465
+ const testIds = (snapshot, id) => machineScenarios(snapshot, id).flatMap((s) => s.tags.filter(isTest$1).map((tag) => ({
25466
+ line: s.line,
25467
+ testId: tag.slice(6)
25468
+ })));
25469
+ /**
25470
+ * GATE-08: exact code-point lookup with `Object.hasOwn` — no case folding, no basename fallback, no
25471
+ * prototype chain (T-04-21). Silent when the report is undeclared or absent, so one configuration
25472
+ * problem yields one reason rather than one per scenario, as `tokensMissing` does under D-67.
25473
+ */
25474
+ const testUnknown = (snapshot, id) => {
25475
+ if (!reportLoaded(snapshot)) return [];
25476
+ const report = reportPath$1(snapshot);
25477
+ return testIds(snapshot, id).filter(({ testId }) => !Object.hasOwn(snapshot.tests ?? {}, testId)).map(({ line, testId }) => ({
25478
+ file: ticketFile$5(id),
25479
+ line,
25480
+ reason: `@test:${testId} not found in ${report}; ids are classname#name with spaces as '-'`
25133
25481
  }));
25134
- const excused = workOf(s, id)?.review?.notInterface ?? [];
25135
- return signs.filter(({ path }) => !excused.includes(path)).map(({ path, sign }) => ({
25136
- file,
25137
- reason: `${path} adds ${sign}, a sign of a new interface no sensitive entry matches; add an entry matching it under sensitive: in accord/config.yml, or have the reviewer record "Not an interface: ${path} — <reason>" in the last ## Round of ${reviewFile(id)}`
25482
+ };
25483
+ /**
25484
+ * GATE-08 and docs/design.md §5: only `passed` passes. A muted test fails Done exactly as a failing one
25485
+ * does — naming the status verbatim keeps the two distinguishable without softening either.
25486
+ */
25487
+ const testNotPassed = (snapshot, id) => {
25488
+ if (!reportLoaded(snapshot)) return [];
25489
+ const tests = snapshot.tests ?? {};
25490
+ const report = reportPath$1(snapshot);
25491
+ return testIds(snapshot, id).filter(({ testId }) => Object.hasOwn(tests, testId) && tests[testId] !== "passed").map(({ line, testId }) => ({
25492
+ file: ticketFile$5(id),
25493
+ line,
25494
+ reason: `@test:${testId} is recorded ${tests[testId]} in ${report}; Done passes on passed alone`
25138
25495
  }));
25139
25496
  };
25140
- /** D-02, D-07: why a declared wording-only file does not qualify, or undefined when it does. */
25141
- function wordingOnlyFault(c, path, confirmed, id) {
25142
- if (c?.kind === "added") return "is new";
25143
- if (c?.kind === "deleted") return "is deleted";
25144
- if (c?.kind === "type" || c?.kind === "mode") return "changes its file type or mode";
25145
- if (c?.binary === true) return "is binary";
25146
- if (c !== void 0 && c.lines > 3) return `changes ${c.lines} lines, more than 3`;
25147
- if (!confirmed.includes(path)) return `has no "Confirmed wording-only: ${path}" line in the last ## Round of ${reviewFile(id)}`;
25148
- }
25497
+ /** D-78: the gated commit's author rides under a key equal to `git.commit`; file authors under their
25498
+ * repo-relative posix path. A sha can never collide with a path, so one flat record serves both. */
25499
+ const authorsOf = (snapshot, id) => {
25500
+ const git = snapshot.git;
25501
+ if (git === void 0) return {};
25502
+ const own = (key) => Object.hasOwn(git.authors, key) ? git.authors[key] : void 0;
25503
+ return {
25504
+ commitAuthor: own(git.commit),
25505
+ fileAuthor: own(verificationFile(id))
25506
+ };
25507
+ };
25508
+ /**
25509
+ * GATE-05 (D-79), warning and never more: docs/design.md §4 makes the reviewer not a role, so in the
25510
+ * workflow accord itself prescribes the two identities match on nearly every honest ticket. An error
25511
+ * here would block every solo developer, which is why D-79 fixed the level at warning.
25512
+ */
25513
+ const authorMatch = (snapshot, id) => {
25514
+ if (verificationOf$1(snapshot, id) === void 0) return [];
25515
+ const { commitAuthor, fileAuthor } = authorsOf(snapshot, id);
25516
+ if (commitAuthor === void 0 || fileAuthor === void 0) return [];
25517
+ if (commitAuthor.toLowerCase() !== fileAuthor.toLowerCase()) return [];
25518
+ return [{
25519
+ file: verificationFile(id),
25520
+ reason: `the review and the gated commit share an author (${fileAuthor}), so no second pair of eyes touched this ticket`
25521
+ }];
25522
+ };
25523
+ /** D-80's skipped-as-a-Finding rule: the comparison the host could not supply is reported rather than
25524
+ * silently dropped. Suppressed when the review file is missing, because `gate.verification-missing`
25525
+ * already owns that case and one absent review should read as one reason. */
25526
+ const authorSkipped = (snapshot, id) => {
25527
+ if (verificationOf$1(snapshot, id) === void 0) return [];
25528
+ const { commitAuthor, fileAuthor } = authorsOf(snapshot, id);
25529
+ const which = [...commitAuthor === void 0 ? ["the gated commit"] : [], ...fileAuthor === void 0 ? ["the review file"] : []];
25530
+ if (which.length === 0) return [];
25531
+ return [{
25532
+ file: verificationFile(id),
25533
+ reason: `the host supplied no author for ${which.join(" and ")}, so the review and the commit could not be compared`
25534
+ }];
25535
+ };
25149
25536
  /**
25150
25537
  * D-88/GATE-07: the token and size rules that `maintain` softens to warnings. Defined here, as the data of PRESETS.maintain, and re-exported by gate/rules.ts, so the gate
25151
25538
  * module graph (which reaches this file through round/next.ts) is never read while this file is still being evaluated. Disjoint from READY_PROMOTE.
@@ -26724,7 +27111,7 @@ const options$1 = {
26724
27111
  schema: "core",
26725
27112
  customTags: stringNumerics
26726
27113
  };
26727
- const cmp$8 = (a, b) => a < b ? -1 : a > b ? 1 : 0;
27114
+ const cmp$7 = (a, b) => a < b ? -1 : a > b ? 1 : 0;
26728
27115
  function source(key) {
26729
27116
  const text = agents[key];
26730
27117
  if (text === void 0) throw new Error("unknown agent definition: " + key);
@@ -26772,7 +27159,7 @@ function agentTargets(config) {
26772
27159
  text: renderAgent(key, route("reviewer.final"), "accord-final-reviewer")
26773
27160
  });
26774
27161
  }
26775
- return out.sort((a, b) => cmp$8(a.path, b.path));
27162
+ return out.sort((a, b) => cmp$7(a.path, b.path));
26776
27163
  }
26777
27164
  /**
26778
27165
  * True when the fix record rules apply to the ticket: a lane ticket with a version 2 review record, not skipped (D-10: HEAD on the default branch, or the ticket done in the default ref's
@@ -28211,7 +28598,7 @@ const commitRule = (snapshot) => {
28211
28598
  for (const p of subjectRuleProblems(snapshot, rule)) out.push({
28212
28599
  file,
28213
28600
  pointer: `/commits/subjects/${p.name}`,
28214
- reason: `commits.subjects.${p.name} renders "${p.subject}", which breaks the commit rule: ${p.problem} - fix: ${p.fix}; \`accord commit check <file>\` checks a message first`
28601
+ reason: `commits.subjects.${p.name} renders "${visible$1(p.subject)}", which breaks the commit rule: ${p.problem} - fix: ${p.fix}; \`accord commit check <file>\` checks a message first`
28215
28602
  });
28216
28603
  return out;
28217
28604
  };
@@ -29158,8 +29545,8 @@ const RULES = [
29158
29545
  check: templateSection
29159
29546
  }
29160
29547
  ];
29161
- const cmp$7 = (a, b) => a < b ? -1 : a > b ? 1 : 0;
29162
- const byFileLineRule$1 = (a, b) => cmp$7(a.file, b.file) || (a.line ?? 0) - (b.line ?? 0) || cmp$7(a.rule, b.rule) || cmp$7(a.reason, b.reason) || cmp$7(a.pointer ?? "", b.pointer ?? "");
29548
+ const cmp$6 = (a, b) => a < b ? -1 : a > b ? 1 : 0;
29549
+ const byFileLineRule$1 = (a, b) => cmp$6(a.file, b.file) || (a.line ?? 0) - (b.line ?? 0) || cmp$6(a.rule, b.rule) || cmp$6(a.reason, b.reason) || cmp$6(a.pointer ?? "", b.pointer ?? "");
29163
29550
  /** The ticket id a finding's file belongs to: `accord/tickets/<id>.md` or a file under `accord/tickets/<id>/`; string work only, so an id with `.` or `-` never widens the match. */
29164
29551
  function ticketOfFile(file) {
29165
29552
  if (!file.startsWith("accord/tickets/")) return void 0;
@@ -30767,1131 +31154,748 @@ const DONE_RULES = [
30767
31154
  id: "gate.verification-unfinished",
30768
31155
  level: "error",
30769
31156
  profiles: ["build", "maintain"],
30770
- check: verificationUnfinished
30771
- },
30772
- {
30773
- id: "gate.no-scenarios",
30774
- level: "error",
30775
- profiles: ["build", "maintain"],
30776
- check: noScenarios$1
30777
- },
30778
- {
30779
- id: "gate.tags-differ",
30780
- level: "error",
30781
- profiles: ["build", "maintain"],
30782
- check: tagsDiffer
30783
- },
30784
- {
30785
- id: "gate.verification-missing",
30786
- level: "error",
30787
- profiles: ["build", "maintain"],
30788
- check: verificationMissing
30789
- },
30790
- {
30791
- id: "gate.result-not-pass",
30792
- level: "error",
30793
- profiles: ["build", "maintain"],
30794
- check: resultNotPass
30795
- },
30796
- {
30797
- id: "gate.commit-missing",
30798
- level: "error",
30799
- profiles: ["build", "maintain"],
30800
- check: commitMissing
30801
- },
30802
- {
30803
- id: "gate.sha-too-short",
30804
- level: "error",
30805
- profiles: ["build", "maintain"],
30806
- check: shaTooShort
30807
- },
30808
- {
30809
- id: "gate.ac-hash-missing",
30810
- level: "error",
30811
- profiles: ["build", "maintain"],
30812
- check: acHashMissing
30813
- },
30814
- {
30815
- id: "gate.ac-changed",
30816
- level: "error",
30817
- profiles: ["build", "maintain"],
30818
- check: acChanged
30819
- },
30820
- {
30821
- id: "gate.tick-unbound",
30822
- level: "error",
30823
- profiles: ["build", "maintain"],
30824
- check: tickUnbound
30825
- },
30826
- {
30827
- id: "gate.tick-stale-hash",
30828
- level: "error",
30829
- profiles: ["build", "maintain"],
30830
- check: tickStaleHash
30831
- },
30832
- {
30833
- id: "gate.tick-stale-commit",
30834
- level: "error",
30835
- profiles: ["build", "maintain"],
30836
- check: tickStaleCommit
30837
- },
30838
- {
30839
- id: "gate.stale-review",
30840
- level: "error",
30841
- profiles: ["build", "maintain"],
30842
- check: staleReview
30843
- },
30844
- COMMIT_TRAILER,
30845
- COMMIT_MESSAGE,
30846
- BRANCH_UNKNOWN,
30847
- INTERFACE_SIGN,
30848
- {
30849
- id: "gate.evidence-unresolved",
30850
- level: "error",
30851
- profiles: ["build", "maintain"],
30852
- check: evidenceUnresolved
30853
- },
30854
- {
30855
- id: "gate.reference-unknown",
30856
- level: "warning",
30857
- profiles: ["build", "maintain"],
30858
- check: referenceUnknown
30859
- },
30860
- {
30861
- id: "gate.note-missing",
30862
- level: "error",
30863
- profiles: ["build", "maintain"],
30864
- check: noteMissing
30865
- },
30866
- {
30867
- id: "gate.note-unresolved",
30868
- level: "error",
30869
- profiles: ["build", "maintain"],
30870
- check: noteUnresolved
30871
- },
30872
- {
30873
- id: "gate.note-pasted",
30874
- level: "error",
30875
- profiles: ["build", "maintain"],
30876
- check: notePasted
30877
- },
30878
- {
30879
- id: "gate.test-tag-missing",
30880
- level: "error",
30881
- profiles: ["build", "maintain"],
30882
- check: testTagMissing$1
30883
- },
30884
- {
30885
- id: "gate.tests-unconfigured",
30886
- level: "error",
30887
- profiles: ["build", "maintain"],
30888
- check: testsUnconfigured
31157
+ check: verificationUnfinished
30889
31158
  },
30890
31159
  {
30891
- id: "gate.report-missing",
31160
+ id: "gate.no-scenarios",
30892
31161
  level: "error",
30893
31162
  profiles: ["build", "maintain"],
30894
- check: reportMissing$1
31163
+ check: noScenarios$1
30895
31164
  },
30896
31165
  {
30897
- id: "gate.test-unknown",
31166
+ id: "gate.tags-differ",
30898
31167
  level: "error",
30899
31168
  profiles: ["build", "maintain"],
30900
- check: testUnknown
31169
+ check: tagsDiffer
30901
31170
  },
30902
31171
  {
30903
- id: "gate.test-not-passed",
31172
+ id: "gate.verification-missing",
30904
31173
  level: "error",
30905
31174
  profiles: ["build", "maintain"],
30906
- check: testNotPassed
31175
+ check: verificationMissing
30907
31176
  },
30908
- APPROVAL_MISSING,
30909
- APPROVAL_STALE,
30910
31177
  {
30911
- id: "gate.task-incomplete",
31178
+ id: "gate.result-not-pass",
30912
31179
  level: "error",
30913
31180
  profiles: ["build", "maintain"],
30914
- check: tasksIncomplete
31181
+ check: resultNotPass
30915
31182
  },
30916
- REVIEW_MISSING,
30917
- REVIEW_UNCONVERGED,
30918
- REVIEW_ROUNDS,
30919
- REVIEW_SCOPE,
30920
- REVIEW_SCOPE_SKIPPED,
30921
- FINDING_EVIDENCE,
30922
- FINDING_GROUNDS,
30923
- FIX_FILE_UNEXPLAINED,
30924
- FIX_PLACES_MISSING,
30925
- FIX_NOT_ADDRESSED,
30926
- FIX_OUTSIDE_OPEN,
30927
- SECURITY_UNREVIEWED,
30928
- SLOP_UNRESOLVED,
30929
- SUITE_NOT_PASSED,
30930
31183
  {
30931
- id: "gate.test-untraced",
31184
+ id: "gate.commit-missing",
30932
31185
  level: "error",
30933
31186
  profiles: ["build", "maintain"],
30934
- check: testUntracedAtDone
31187
+ check: commitMissing
30935
31188
  },
30936
31189
  {
30937
- id: "gate.author-match",
30938
- level: "warning",
31190
+ id: "gate.sha-too-short",
31191
+ level: "error",
30939
31192
  profiles: ["build", "maintain"],
30940
- check: authorMatch
31193
+ check: shaTooShort
30941
31194
  },
30942
31195
  {
30943
- id: "gate.author-skipped",
30944
- level: "warning",
31196
+ id: "gate.ac-hash-missing",
31197
+ level: "error",
30945
31198
  profiles: ["build", "maintain"],
30946
- check: authorSkipped
30947
- }
30948
- ];
30949
- /**
30950
- * ST-LN-94 D-10, research Pitfall 8: the plan gate of a lane R ticket. gatePlan picks it for lane R as gateDone picks DONE_S_RULES for
30951
- * lane S, so every PLAN_RULES row (the plan.ts rules, the plan rounds, the plan format rules) is out of R's reach through one choice.
30952
- */
30953
- const PLAN_R_RULES = [
30954
- TICKET_UNKNOWN,
30955
- RULESET_CHANGED,
30956
- RULESET_MISSING,
31199
+ check: acHashMissing
31200
+ },
30957
31201
  {
30958
- id: "gate.lane-r-plan",
31202
+ id: "gate.ac-changed",
30959
31203
  level: "error",
30960
31204
  profiles: ["build", "maintain"],
30961
- check: laneRPlan
30962
- }
30963
- ];
30964
- /**
30965
- * ST-LN-31 and ST-LN-94: lanes S and R both hash their sections at Ready, so one row each serves both Done tables (GATE-06). Each half is silent
30966
- * for the other lane.
30967
- */
30968
- const READY_MISSING = {
30969
- id: "gate.ready-missing",
30970
- level: "error",
30971
- profiles: ["build", "maintain"],
30972
- check: (s, id) => [...readyMissing(s, id), ...researchReadyMissing(s, id)]
30973
- };
30974
- const SECTIONS_CHANGED = {
30975
- id: "gate.sections-changed",
30976
- level: "error",
30977
- profiles: ["build", "maintain"],
30978
- check: (s, id) => [...sectionsChanged(s, id), ...researchSectionsChanged(s, id)]
30979
- };
30980
- /** ST-LN-31 D-04, D-12: the lane S Done table, with the suite rule; no plan, task, criteria or approval rows. */
30981
- const DONE_S_RULES = [
30982
- TICKET_UNKNOWN,
30983
- RULESET_CHANGED,
30984
- RULESET_MISSING,
30985
- SECTION_EMPTY,
30986
- READY_MISSING,
30987
- SECTIONS_CHANGED,
30988
- REVIEW_MISSING,
30989
- REVIEW_UNCONVERGED,
30990
- REVIEW_ROUNDS,
30991
- REVIEW_SCOPE,
30992
- REVIEW_SCOPE_SKIPPED,
30993
- FINDING_EVIDENCE,
30994
- FINDING_GROUNDS,
30995
- FIX_FILE_UNEXPLAINED,
30996
- FIX_PLACES_MISSING,
30997
- FIX_NOT_ADDRESSED,
30998
- FIX_OUTSIDE_OPEN,
30999
- SECURITY_UNREVIEWED,
31000
- SLOP_UNRESOLVED,
31205
+ check: acChanged
31206
+ },
31001
31207
  {
31002
- id: "gate.review-trailing",
31208
+ id: "gate.tick-unbound",
31003
31209
  level: "error",
31004
31210
  profiles: ["build", "maintain"],
31005
- check: reviewTrailing
31211
+ check: tickUnbound
31006
31212
  },
31007
31213
  {
31008
- id: "gate.review-uncommitted",
31214
+ id: "gate.tick-stale-hash",
31009
31215
  level: "error",
31010
31216
  profiles: ["build", "maintain"],
31011
- check: reviewUncommitted
31217
+ check: tickStaleHash
31012
31218
  },
31013
31219
  {
31014
- id: "gate.review-commit-code",
31220
+ id: "gate.tick-stale-commit",
31015
31221
  level: "error",
31016
31222
  profiles: ["build", "maintain"],
31017
- check: reviewCommitCode
31223
+ check: tickStaleCommit
31018
31224
  },
31019
31225
  {
31020
- id: "gate.commit-after-review",
31226
+ id: "gate.stale-review",
31021
31227
  level: "error",
31022
31228
  profiles: ["build", "maintain"],
31023
- check: commitAfterReview
31229
+ check: staleReview
31024
31230
  },
31025
- SUITE_NOT_PASSED,
31026
31231
  COMMIT_TRAILER,
31027
31232
  COMMIT_MESSAGE,
31028
31233
  BRANCH_UNKNOWN,
31234
+ INTERFACE_SIGN,
31029
31235
  {
31030
- id: "gate.out-of-scope",
31236
+ id: "gate.evidence-unresolved",
31031
31237
  level: "error",
31032
31238
  profiles: ["build", "maintain"],
31033
- check: outOfScope
31239
+ check: evidenceUnresolved
31034
31240
  },
31035
31241
  {
31036
- id: "gate.sensitive-touched",
31037
- level: "error",
31242
+ id: "gate.reference-unknown",
31243
+ level: "warning",
31038
31244
  profiles: ["build", "maintain"],
31039
- check: sensitiveTouched
31245
+ check: referenceUnknown
31040
31246
  },
31041
- INTERFACE_SIGN
31042
- ];
31043
- /**
31044
- * ST-LN-94 D-10, D-11, 94-ac-2, 94-ac-3, research Pitfall 8: the lane R Done table. gateDone picks it for lane R, so no lane M Done row (plan,
31045
- * tasks, ticks, review, verification, suite, scope, interface signs) reaches an R ticket, whatever stray records it holds. It is done on a
31046
- * listed research record with its Spent line, spent within the ticket's allowance or answered by the owner (D-14), and a branch that changes
31047
- * nothing outside accord/ (UAT decision 3, 2026-11-14).
31048
- */
31049
- const DONE_R_RULES = [
31050
- TICKET_UNKNOWN,
31051
- RULESET_CHANGED,
31052
- RULESET_MISSING,
31053
- RESEARCH_FIELD_MISSING,
31054
- RESEARCH_BUDGET_UNANSWERED,
31055
- READY_MISSING,
31056
- SECTIONS_CHANGED,
31057
31247
  {
31058
- id: "gate.research-record-missing",
31248
+ id: "gate.note-missing",
31059
31249
  level: "error",
31060
31250
  profiles: ["build", "maintain"],
31061
- check: researchRecordMissing
31251
+ check: noteMissing
31062
31252
  },
31063
31253
  {
31064
- id: "gate.research-spent-missing",
31254
+ id: "gate.note-unresolved",
31065
31255
  level: "error",
31066
31256
  profiles: ["build", "maintain"],
31067
- check: researchSpentMissing
31257
+ check: noteUnresolved
31068
31258
  },
31069
31259
  {
31070
- id: "gate.research-over-budget",
31260
+ id: "gate.note-pasted",
31071
31261
  level: "error",
31072
31262
  profiles: ["build", "maintain"],
31073
- check: researchOverBudget
31263
+ check: notePasted
31074
31264
  },
31075
31265
  {
31076
- id: "gate.research-shipped",
31266
+ id: "gate.test-tag-missing",
31077
31267
  level: "error",
31078
31268
  profiles: ["build", "maintain"],
31079
- check: researchShipped
31269
+ check: testTagMissing$1
31080
31270
  },
31081
- BRANCH_UNKNOWN,
31082
- COMMIT_TRAILER,
31083
- COMMIT_MESSAGE
31084
- ];
31085
- /** D-89: the three LINT-06 hygiene rules Ready promotes from warning to blocking. */
31086
- const READY_PROMOTE = [
31087
- "lint.sentinel",
31088
- "lint.open-question",
31089
- "lint.assumption-unconfirmed"
31090
- ];
31091
- /**
31092
- * GATE-07: the whole profile matrix, applied once in the shared engine body so every gate inherits it.
31093
- * `build` has no preset level, so a finding changes there only by a team key. On `maintain` a finding of one of the four MAINTAIN_DOWNGRADE rules takes the level the resolved strictness holds for it:
31094
- * the preset's warning, or the team's own `strictness.levels` key, which wins over the preset (D-09). The lint stamp has already applied that level to a table
31095
- * finding; this pass is what reaches a finding stamped elsewhere (a loader finding is stamped error, D-58). A rule the team turned off is left alone here: its table findings
31096
- * were dropped at the stamp. GATE-12 is then a one-cell table edit (D-88). `levels` defaults to the profile's preset.
31097
- */
31098
- function downgradeMaintain(findings, profile, levels = PRESETS[profile].levels) {
31099
- return findings.map((f) => {
31100
- const level = MAINTAIN_DOWNGRADE.includes(f.rule) && Object.hasOwn(levels, f.rule) ? levels[f.rule] : void 0;
31101
- return level === "error" || level === "warning" ? {
31102
- ...f,
31103
- level
31104
- } : f;
31105
- });
31106
- }
31107
- const cmp$6 = (a, b) => a < b ? -1 : a > b ? 1 : 0;
31108
- function byFileLineRule(a, b) {
31109
- return cmp$6(a.file, b.file) || (a.line ?? 0) - (b.line ?? 0) || cmp$6(a.rule, b.rule) || cmp$6(a.reason, b.reason) || cmp$6(a.pointer ?? "", b.pointer ?? "");
31110
- }
31111
- /**
31112
- * D-89 ticket scope: the ticket file, its folder, and its assets folder. String comparison only — an id
31113
- * may contain `.`, `-`, and `_`, so a regular expression built from it would widen the scope and pull a
31114
- * neighbouring ticket's findings into this result (T-04-01).
31115
- */
31116
- function scoped(findings, id) {
31117
- const file = "accord/tickets/" + id + ".md";
31118
- const folder = "accord/tickets/" + id + "/";
31119
- const assets = "accord/assets/" + id + "/";
31120
- return findings.filter((f) => f.file === file || f.file.startsWith(folder) || f.file.startsWith(assets));
31121
- }
31122
- /**
31123
- * The shared gate body. One function, so `downgradeMaintain` keeps exactly one call site and every gate
31124
- * inherits the GATE-07 matrix: a second copy is how one gate silently falls out of that matrix the
31125
- * moment GATE-12 flips a level (D-88). `promote` is the D-89 hygiene promotion, which is Ready's alone.
31126
- * Pure: reads the snapshot only, never mutates it, and returns the same result on every call.
31127
- */
31128
- function run(gate, rules, promote, snapshot, id) {
31129
- const profile = snapshot.config?.profile ?? "build";
31130
- const strictness = resolveStrictness(snapshot.config);
31131
- const memo = /* @__PURE__ */ new Map();
31132
- const once = (key, compute) => {
31133
- if (!memo.has(key)) memo.set(key, compute());
31134
- return memo.get(key);
31135
- };
31136
- const gated = rules.filter((r) => r.profiles.includes(profile)).filter((r) => !Object.hasOwn(STAGE_OF, r.id) || !stageOff(snapshot, id, STAGE_OF[r.id])).flatMap((r) => {
31137
- const level = effectiveLevel(r.id, r.level, strictness);
31138
- return level === "off" ? [] : r.check(snapshot, id, once).map((d) => ({
31139
- ...d,
31140
- rule: r.id,
31141
- level
31142
- }));
31143
- });
31144
- const known = Object.hasOwn(snapshot.tickets, id);
31145
- const findings = [...known ? downgradeMaintain(scoped(lintSnapshot(snapshot).findings, id), profile, strictness.levels).map((f) => promote.includes(f.rule) ? {
31146
- ...f,
31147
- level: "error"
31148
- } : f) : [], ...gated].sort(byFileLineRule);
31149
- const hash = known ? readyHash(snapshot.tickets[id]) : void 0;
31150
- return {
31151
- gate,
31152
- ticket: id,
31153
- verdict: findings.some((f) => f.level === "error") ? "fail" : "pass",
31154
- findings,
31155
- ...hash === void 0 ? {} : { acHash: hash }
31156
- };
31157
- }
31158
- /** GATE-01: the Ready table plus the three LINT-06 hygiene rules promoted to blocking (D-89). */
31159
- function gateReady(snapshot, id) {
31160
- return run("ready", READY_RULES, READY_PROMOTE, snapshot, id);
31161
- }
31162
- /** Spec §7: the plan gate plus the ticket-scoped lint findings, which include load findings on plan.md. Lane R runs PLAN_R_RULES. */
31163
- function gatePlan(snapshot, id) {
31164
- if ((Object.hasOwn(snapshot.tickets, id) ? snapshot.tickets[id].frontmatter?.lane : void 0) === "R") return run("plan", PLAN_R_RULES, [], snapshot, id);
31165
- const result = run("plan", PLAN_RULES, [], snapshot, id);
31166
- const planHash = laneTicket(snapshot, id) === void 0 ? void 0 : workOf(snapshot, id)?.plan?.bodyHash;
31167
- return planHash === void 0 ? result : {
31168
- ...result,
31169
- planHash
31170
- };
31171
- }
31271
+ {
31272
+ id: "gate.tests-unconfigured",
31273
+ level: "error",
31274
+ profiles: ["build", "maintain"],
31275
+ check: testsUnconfigured
31276
+ },
31277
+ {
31278
+ id: "gate.report-missing",
31279
+ level: "error",
31280
+ profiles: ["build", "maintain"],
31281
+ check: reportMissing$1
31282
+ },
31283
+ {
31284
+ id: "gate.test-unknown",
31285
+ level: "error",
31286
+ profiles: ["build", "maintain"],
31287
+ check: testUnknown
31288
+ },
31289
+ {
31290
+ id: "gate.test-not-passed",
31291
+ level: "error",
31292
+ profiles: ["build", "maintain"],
31293
+ check: testNotPassed
31294
+ },
31295
+ APPROVAL_MISSING,
31296
+ APPROVAL_STALE,
31297
+ {
31298
+ id: "gate.task-incomplete",
31299
+ level: "error",
31300
+ profiles: ["build", "maintain"],
31301
+ check: tasksIncomplete
31302
+ },
31303
+ REVIEW_MISSING,
31304
+ REVIEW_UNCONVERGED,
31305
+ REVIEW_ROUNDS,
31306
+ REVIEW_SCOPE,
31307
+ REVIEW_SCOPE_SKIPPED,
31308
+ FINDING_EVIDENCE,
31309
+ FINDING_GROUNDS,
31310
+ FIX_FILE_UNEXPLAINED,
31311
+ FIX_PLACES_MISSING,
31312
+ FIX_NOT_ADDRESSED,
31313
+ FIX_OUTSIDE_OPEN,
31314
+ SECURITY_UNREVIEWED,
31315
+ SLOP_UNRESOLVED,
31316
+ SUITE_NOT_PASSED,
31317
+ {
31318
+ id: "gate.test-untraced",
31319
+ level: "error",
31320
+ profiles: ["build", "maintain"],
31321
+ check: testUntracedAtDone
31322
+ },
31323
+ {
31324
+ id: "gate.author-match",
31325
+ level: "warning",
31326
+ profiles: ["build", "maintain"],
31327
+ check: authorMatch
31328
+ },
31329
+ {
31330
+ id: "gate.author-skipped",
31331
+ level: "warning",
31332
+ profiles: ["build", "maintain"],
31333
+ check: authorSkipped
31334
+ }
31335
+ ];
31172
31336
  /**
31173
- * GATE-02/GATE-03/GATE-11: the Done table plus every ticket-scoped lint finding at the level lint
31174
- * stamped. No hygiene promotion and no design rule — Done does not re-run Ready (D-89 applied to Done).
31337
+ * ST-LN-94 D-10, research Pitfall 8: the plan gate of a lane R ticket. gatePlan picks it for lane R as gateDone picks DONE_S_RULES for
31338
+ * lane S, so every PLAN_RULES row (the plan.ts rules, the plan rounds, the plan format rules) is out of R's reach through one choice.
31175
31339
  */
31176
- function gateDone(snapshot, id) {
31177
- const lane = Object.hasOwn(snapshot.tickets, id) ? snapshot.tickets[id].frontmatter?.lane : void 0;
31178
- return run("done", lane === "S" ? DONE_S_RULES : lane === "R" ? DONE_R_RULES : DONE_RULES, [], snapshot, id);
31179
- }
31180
- const HEADER$2 = [
31181
- "claim",
31182
- "pattern",
31183
- "folders",
31184
- "allowed hits"
31185
- ];
31186
- const SKIPPED = /^\s*(?:[-*+]\s+)?skipped:\s*(\S.*)$/;
31187
- const CITATION = /(?<![\p{L}\p{N}_.@+\-[\]/:])((?:[\p{L}\p{N}_.@+\-[\]]+\/)*[\p{L}\p{N}_.@+\-[\]]+):(\d+(?:-\d+)?(?:,\d+(?:-\d+)?)*)(?![\p{L}\p{N}_])/gu;
31188
- /** One wrapping pair of backticks, when the text is at least two characters and starts and ends with one. */
31189
- function unwrap(text) {
31190
- return text.length >= 2 && text.startsWith("`") && text.endsWith("`") ? text.slice(1, -1) : text;
31191
- }
31192
- /** The lines of a section outside fences and HTML comments. */
31193
- function bodyLines(section, fences) {
31194
- const inFence = (n) => fences.some((f) => n >= f.open && n <= f.close);
31195
- return stripHtmlComments(section.lines.filter((l) => !inFence(l.line)));
31196
- }
31197
- /** The paths of a `## Files` or `## New files` list: the first token of each list line, cleaned. */
31198
- function listEntries(lines) {
31199
- const out = [];
31200
- for (const { text } of lines) {
31201
- if (!LIST_MARKER.test(text)) continue;
31202
- const entry = unwrap(unwrap(text.replace(LIST_MARKER, "").trim().split(/\s+/)[0] ?? "").replace(/:$/, "")).replace(/\\/g, "/").replace(/^\.\//, "").replace(/:\d+(?:[-,]\d+)*$/, "");
31203
- if (entry !== "") out.push(entry);
31204
- }
31205
- return out;
31206
- }
31207
- /** The cells of one table line: edge pipes dropped, split on a pipe that is not `\|`, each cell unescaped. */
31208
- function cellsOf(text) {
31209
- let t = text.trim();
31210
- if (t.startsWith("|")) t = t.slice(1);
31211
- if (t.endsWith("|") && !t.endsWith("\\|")) t = t.slice(0, -1);
31212
- return t.split(/(?<!\\)\|/).map((c) => unwrap(c.replace(/\\\|/g, "|").trim()));
31213
- }
31214
- /** A Folders or Allowed hits cell: entries split on whitespace and commas, each losing a wrapping backtick. */
31215
- function entriesOf(cell) {
31216
- return cell.split(/[\s,]+/).map((e) => e.replace(/^`/, "").replace(/`$/, "")).filter((e) => e !== "");
31217
- }
31218
- function parseScoutReport(text) {
31219
- const norm = normaliseText(text);
31220
- const { sections, fences } = scan(norm, 0);
31221
- const section = (key) => sections.find((s) => headingKey(s.heading) === key);
31222
- const filesSection = section("files");
31223
- const newSection = section("new files");
31224
- const absentSection = section("absent");
31225
- const report = {
31226
- newFiles: newSection === void 0 ? [] : listEntries(bodyLines(newSection, fences)),
31227
- absent: [],
31228
- faults: [],
31229
- citations: []
31230
- };
31231
- if (filesSection !== void 0) report.files = listEntries(bodyLines(filesSection, fences));
31232
- if (absentSection !== void 0) {
31233
- const table = bodyLines(absentSection, fences).filter((l) => l.text.trim().startsWith("|"));
31234
- if (table.length > 0) {
31235
- const header = cellsOf(table[0].text).map((c) => c.toLowerCase());
31236
- if (header.length !== HEADER$2.length || header.some((c, i) => c !== HEADER$2[i])) report.faults.push("the ## Absent table header is not | Claim | Pattern | Folders | Allowed hits |");
31237
- else for (const { line, text: rowText } of table.slice(1)) {
31238
- const cells = cellsOf(rowText);
31239
- if (cells.every((c) => /^:?-+:?$/.test(c))) continue;
31240
- if (cells.length !== 4) {
31241
- report.faults.push("## Absent row at line " + line + " has " + cells.length + " cells, not 4: escape a pipe inside a cell");
31242
- continue;
31243
- }
31244
- const folders = entriesOf(cells[2]);
31245
- report.absent.push({
31246
- line,
31247
- claim: cells[0],
31248
- pattern: cells[1],
31249
- folders: folders.length === 0 ? [""] : folders,
31250
- allowed: entriesOf(cells[3])
31251
- });
31252
- }
31253
- }
31254
- }
31255
- const seen = /* @__PURE__ */ new Set();
31256
- for (const m of norm.replace(/\\/g, "/").matchAll(CITATION)) {
31257
- const path = m[1];
31258
- if (!path.includes("/") && !path.includes(".") || seen.has(m[0])) continue;
31259
- seen.add(m[0]);
31260
- report.citations.push({
31261
- text: m[0],
31262
- path,
31263
- numbers: (m[2].match(/\d+/g) ?? []).map(Number)
31264
- });
31265
- }
31266
- const inFence = (n) => fences.some((f) => n >= f.open && n <= f.close);
31267
- const raw = norm.split("\n");
31268
- for (let i = 0; i < raw.length; i++) {
31269
- if (inFence(i + 1)) continue;
31270
- const m = SKIPPED.exec(raw[i]);
31271
- if (m) {
31272
- report.skipped = m[1].trim();
31273
- break;
31274
- }
31340
+ const PLAN_R_RULES = [
31341
+ TICKET_UNKNOWN,
31342
+ RULESET_CHANGED,
31343
+ RULESET_MISSING,
31344
+ {
31345
+ id: "gate.lane-r-plan",
31346
+ level: "error",
31347
+ profiles: ["build", "maintain"],
31348
+ check: laneRPlan
31275
31349
  }
31276
- return report;
31277
- }
31278
- const SLICE = 100;
31279
- const CLAIM_CAP = 80;
31280
- /** A claim as printed: backslashes to slashes, whitespace runs to one space, cut at 80 characters with `...`. */
31281
- function printedClaim(claim) {
31282
- const flat = claim.replace(/\\/g, "/").replace(/\s+/g, " ");
31283
- return flat.length > CLAIM_CAP ? flat.slice(0, CLAIM_CAP) + "..." : flat;
31284
- }
31285
- const byCodePoint$2 = (a, b) => {
31286
- const x = Array.from(a);
31287
- const y = Array.from(b);
31288
- for (let i = 0; i < Math.min(x.length, y.length); i++) if (x[i] !== y[i]) return x[i].codePointAt(0) - y[i].codePointAt(0);
31289
- return x.length - y.length;
31290
- };
31291
- /** The lines of a file's text after BOM and CRLF normalisation, one trailing empty element dropped. */
31292
- function linesOf$1(text) {
31293
- const lines = normaliseText(text).split("\n");
31294
- if (lines.length > 0 && lines[lines.length - 1] === "") lines.pop();
31295
- return lines;
31296
- }
31350
+ ];
31297
31351
  /**
31298
- * Which tracked paths a list of folder or file entries covers: `\` becomes `/`, a leading `./` goes, and `.`, `/`
31299
- * and the empty string mean the root. An entry covers a path when it is the root, ends in `/` and the path starts
31300
- * with it, is a folder (some tracked path sits below it) the path is below, or is the path itself.
31352
+ * ST-LN-31 and ST-LN-94: lanes S and R both hash their sections at Ready, so one row each serves both Done tables (GATE-06). Each half is silent
31353
+ * for the other lane.
31301
31354
  */
31302
- function coverage(entries, tracked) {
31303
- const tests = entries.map((raw) => {
31304
- const e = raw.replace(/\\/g, "/").replace(/^\.\//, "");
31305
- if (e === "." || e === "/" || e === "") return () => true;
31306
- const folder = !e.endsWith("/") && tracked.some((t) => t.startsWith(e + "/"));
31307
- return (p) => e.endsWith("/") && p.startsWith(e) || folder && p.startsWith(e + "/") || p === e;
31308
- });
31309
- return (p) => tests.some((t) => t(p));
31310
- }
31311
- /** The text of each path, read in slices of at most 100; undefined where a file cannot be read. */
31312
- function readAll(facts, paths) {
31313
- const out = [];
31314
- for (let i = 0; i < paths.length; i += SLICE) out.push(...facts.read(paths.slice(i, i + SLICE)));
31315
- return out;
31316
- }
31355
+ const READY_MISSING = {
31356
+ id: "gate.ready-missing",
31357
+ level: "error",
31358
+ profiles: ["build", "maintain"],
31359
+ check: (s, id) => [...readyMissing(s, id), ...researchReadyMissing(s, id)]
31360
+ };
31361
+ const SECTIONS_CHANGED = {
31362
+ id: "gate.sections-changed",
31363
+ level: "error",
31364
+ profiles: ["build", "maintain"],
31365
+ check: (s, id) => [...sectionsChanged(s, id), ...researchSectionsChanged(s, id)]
31366
+ };
31367
+ /** ST-LN-31 D-04, D-12: the lane S Done table, with the suite rule; no plan, task, criteria or approval rows. */
31368
+ const DONE_S_RULES = [
31369
+ TICKET_UNKNOWN,
31370
+ RULESET_CHANGED,
31371
+ RULESET_MISSING,
31372
+ SECTION_EMPTY,
31373
+ READY_MISSING,
31374
+ SECTIONS_CHANGED,
31375
+ REVIEW_MISSING,
31376
+ REVIEW_UNCONVERGED,
31377
+ REVIEW_ROUNDS,
31378
+ REVIEW_SCOPE,
31379
+ REVIEW_SCOPE_SKIPPED,
31380
+ FINDING_EVIDENCE,
31381
+ FINDING_GROUNDS,
31382
+ FIX_FILE_UNEXPLAINED,
31383
+ FIX_PLACES_MISSING,
31384
+ FIX_NOT_ADDRESSED,
31385
+ FIX_OUTSIDE_OPEN,
31386
+ SECURITY_UNREVIEWED,
31387
+ SLOP_UNRESOLVED,
31388
+ {
31389
+ id: "gate.review-trailing",
31390
+ level: "error",
31391
+ profiles: ["build", "maintain"],
31392
+ check: reviewTrailing
31393
+ },
31394
+ {
31395
+ id: "gate.review-uncommitted",
31396
+ level: "error",
31397
+ profiles: ["build", "maintain"],
31398
+ check: reviewUncommitted
31399
+ },
31400
+ {
31401
+ id: "gate.review-commit-code",
31402
+ level: "error",
31403
+ profiles: ["build", "maintain"],
31404
+ check: reviewCommitCode
31405
+ },
31406
+ {
31407
+ id: "gate.commit-after-review",
31408
+ level: "error",
31409
+ profiles: ["build", "maintain"],
31410
+ check: commitAfterReview
31411
+ },
31412
+ SUITE_NOT_PASSED,
31413
+ COMMIT_TRAILER,
31414
+ COMMIT_MESSAGE,
31415
+ BRANCH_UNKNOWN,
31416
+ {
31417
+ id: "gate.out-of-scope",
31418
+ level: "error",
31419
+ profiles: ["build", "maintain"],
31420
+ check: outOfScope
31421
+ },
31422
+ {
31423
+ id: "gate.sensitive-touched",
31424
+ level: "error",
31425
+ profiles: ["build", "maintain"],
31426
+ check: sensitiveTouched
31427
+ },
31428
+ INTERFACE_SIGN
31429
+ ];
31317
31430
  /**
31318
- * The one tracked path that ends with `/` + `path`, so a shortened path reads as the file it names; undefined when no
31319
- * tracked path or more than one does. The caller expands only a path git does not track as written.
31431
+ * ST-LN-94 D-10, D-11, 94-ac-2, 94-ac-3, research Pitfall 8: the lane R Done table. gateDone picks it for lane R, so no lane M Done row (plan,
31432
+ * tasks, ticks, review, verification, suite, scope, interface signs) reaches an R ticket, whatever stray records it holds. It is done on a
31433
+ * listed research record with its Spent line, spent within the ticket's allowance or answered by the owner (D-14), and a branch that changes
31434
+ * nothing outside accord/ (UAT decision 3, 2026-11-14).
31320
31435
  */
31321
- function expandPath(path, tracked) {
31322
- if (path === "") return void 0;
31323
- const tail = "/" + path;
31324
- const hits = tracked.filter((t) => t.endsWith(tail));
31325
- return hits.length === 1 ? hits[0] : void 0;
31326
- }
31327
- const SAVED_REPORT = /^accord\/tickets\/([^/]+)\/scout\.md$/;
31436
+ const DONE_R_RULES = [
31437
+ TICKET_UNKNOWN,
31438
+ RULESET_CHANGED,
31439
+ RULESET_MISSING,
31440
+ RESEARCH_FIELD_MISSING,
31441
+ RESEARCH_BUDGET_UNANSWERED,
31442
+ READY_MISSING,
31443
+ SECTIONS_CHANGED,
31444
+ {
31445
+ id: "gate.research-record-missing",
31446
+ level: "error",
31447
+ profiles: ["build", "maintain"],
31448
+ check: researchRecordMissing
31449
+ },
31450
+ {
31451
+ id: "gate.research-spent-missing",
31452
+ level: "error",
31453
+ profiles: ["build", "maintain"],
31454
+ check: researchSpentMissing
31455
+ },
31456
+ {
31457
+ id: "gate.research-over-budget",
31458
+ level: "error",
31459
+ profiles: ["build", "maintain"],
31460
+ check: researchOverBudget
31461
+ },
31462
+ {
31463
+ id: "gate.research-shipped",
31464
+ level: "error",
31465
+ profiles: ["build", "maintain"],
31466
+ check: researchShipped
31467
+ },
31468
+ BRANCH_UNKNOWN,
31469
+ COMMIT_TRAILER,
31470
+ COMMIT_MESSAGE
31471
+ ];
31472
+ /** D-89: the three LINT-06 hygiene rules Ready promotes from warning to blocking. */
31473
+ const READY_PROMOTE = [
31474
+ "lint.sentinel",
31475
+ "lint.open-question",
31476
+ "lint.assumption-unconfirmed"
31477
+ ];
31328
31478
  /**
31329
- * The files no Absent row searches: the report itself and, for a report of a ticket (a saved report, or any report
31330
- * checked with a ticket id), its ticket file, everything under the ticket's folder, and the research records its
31331
- * ticket lists. A missing or unreadable ticket adds no record.
31479
+ * GATE-07: the whole profile matrix, applied once in the shared engine body so every gate inherits it.
31480
+ * `build` has no preset level, so a finding changes there only by a team key. On `maintain` a finding of one of the four MAINTAIN_DOWNGRADE rules takes the level the resolved strictness holds for it:
31481
+ * the preset's warning, or the team's own `strictness.levels` key, which wins over the preset (D-09). The lint stamp has already applied that level to a table
31482
+ * finding; this pass is what reaches a finding stamped elsewhere (a loader finding is stamped error, D-58). A rule the team turned off is left alone here: its table findings
31483
+ * were dropped at the stamp. GATE-12 is then a one-cell table edit (D-88). `levels` defaults to the profile's preset.
31332
31484
  */
31333
- function ownFiles(facts, tracked) {
31334
- const own = /* @__PURE__ */ new Set();
31335
- if (facts.path !== void 0) own.add(facts.path);
31336
- const id = facts.ticket ?? (facts.path === void 0 ? void 0 : SAVED_REPORT.exec(facts.path)?.[1]);
31337
- if (id === void 0) return own;
31338
- const ticket = "accord/tickets/" + id + ".md";
31339
- own.add(ticket);
31340
- for (const p of tracked) if (p.startsWith("accord/tickets/" + id + "/")) own.add(p);
31341
- const text = facts.read([ticket])[0];
31342
- if (text === void 0) return own;
31343
- const yaml = splitFrontmatter(text).yaml;
31344
- if (yaml === null) return own;
31345
- const research = parseYamlMap(ticket, yaml, 1).map?.research;
31346
- if (!Array.isArray(research)) return own;
31347
- for (const entry of research) if (typeof entry === "string" && isResearchRecord(entry)) own.add(entry);
31348
- return own;
31349
- }
31350
- const TEST_FOLDER$1 = /* @__PURE__ */ new Set([
31351
- "test",
31352
- "tests",
31353
- "__tests__"
31354
- ]);
31355
- const isTestFile$1 = (path) => {
31356
- const segments = path.split("/");
31357
- const name = segments[segments.length - 1];
31358
- return segments.slice(0, -1).some((s) => TEST_FOLDER$1.has(s)) || name.includes(".test.") || name.includes(".spec.");
31359
- };
31360
- /** The lane numbers of lane.md over the listed files: expected files, code areas, sensitive matches and the lifts. */
31361
- function laneOf(facts, listed) {
31362
- const lists = configLists(facts.config);
31363
- const rendered = new Set(facts.rendered ?? []);
31364
- const expected = listed.filter((p) => !isTestFile$1(p) && !rendered.has(p) && !lists.generated.some((e) => matches(e, p)));
31365
- const areas = [...new Set(expected.map((p) => p.includes("/") ? p.split("/").slice(0, -1).slice(0, 4).join("/") : "."))].sort(byCodePoint$2);
31366
- const sensitive = listed.flatMap((path) => lists.sensitive.filter((e) => matches(e.path, path)).map((e) => ({
31367
- path,
31368
- entry: e.path,
31369
- area: e.area,
31370
- line: e.line
31371
- })));
31372
- return {
31373
- expected,
31374
- areas,
31375
- sensitive,
31376
- lifts: [
31377
- ...expected.length > 5 ? ["more than 5 expected files"] : [],
31378
- ...areas.length > 3 ? ["more than 3 code areas"] : [],
31379
- ...sensitive.length > 0 ? ["a listed sensitive area"] : []
31380
- ]
31381
- };
31485
+ function downgradeMaintain(findings, profile, levels = PRESETS[profile].levels) {
31486
+ return findings.map((f) => {
31487
+ const level = MAINTAIN_DOWNGRADE.includes(f.rule) && Object.hasOwn(levels, f.rule) ? levels[f.rule] : void 0;
31488
+ return level === "error" || level === "warning" ? {
31489
+ ...f,
31490
+ level
31491
+ } : f;
31492
+ });
31382
31493
  }
31383
- function scoutCheck(facts) {
31384
- const report = parseScoutReport(facts.text);
31385
- const tracked = [...facts.tracked].sort(byCodePoint$2);
31386
- const trackedSet = new Set(tracked);
31387
- const failures = [];
31388
- const expanded = [];
31389
- const expand = (path) => {
31390
- if (trackedSet.has(path)) return path;
31391
- const to = expandPath(path, tracked);
31392
- if (to === void 0) return path;
31393
- if (!expanded.some((e) => e.from === path)) expanded.push({
31394
- from: path,
31395
- to
31396
- });
31397
- return to;
31398
- };
31399
- const files = report.files?.map(expand);
31400
- const citations = report.citations.map((c) => ({
31401
- ...c,
31402
- path: expand(c.path)
31403
- }));
31404
- if (report.files === void 0) failures.push("the report has no ## Files section, so no lane numbers can be computed");
31405
- failures.push(...report.faults);
31406
- for (const path of files ?? []) if (!trackedSet.has(path)) failures.push("## Files lists " + path + ", which git does not track");
31407
- for (const path of report.newFiles) if (trackedSet.has(path)) failures.push("## New files lists " + path + ", which git already tracks");
31408
- const cited = [...new Set(citations.map((c) => c.path).filter((p) => trackedSet.has(p)))];
31409
- const citedTexts = /* @__PURE__ */ new Map();
31410
- readAll(facts, cited).forEach((text, i) => citedTexts.set(cited[i], text));
31411
- for (const c of citations) {
31412
- const where = "citation " + c.text + " does not resolve: ";
31413
- if (!trackedSet.has(c.path)) {
31414
- failures.push(where + "git does not track " + c.path);
31415
- continue;
31416
- }
31417
- const text = citedTexts.get(c.path);
31418
- if (text === void 0) {
31419
- failures.push(where + c.path + " cannot be read");
31420
- continue;
31421
- }
31422
- const count = linesOf$1(text).length;
31423
- if (c.numbers.some((n) => n < 1 || n > count)) failures.push(where + c.path + " has " + count + " lines");
31424
- }
31425
- const own = report.absent.length > 0 ? ownFiles(facts, tracked) : /* @__PURE__ */ new Set();
31426
- for (const row of report.absent) {
31427
- const where = "absent claim \"" + printedClaim(row.claim) + "\" (row " + row.line + "): ";
31428
- let pattern;
31429
- try {
31430
- pattern = new RegExp(row.pattern);
31431
- } catch {
31432
- failures.push(where + "its pattern is not a valid JavaScript regular expression");
31433
- continue;
31434
- }
31435
- const covers = coverage(row.folders, tracked);
31436
- const searched = tracked.filter((p) => covers(p) && !own.has(p) && !p.startsWith(".claude/") && !p.startsWith(".agents/"));
31437
- if (searched.length === 0) {
31438
- failures.push(where + "its folders cover no tracked file");
31439
- continue;
31440
- }
31441
- const allowed = coverage(row.allowed, tracked);
31442
- const unallowed = searched.filter((p) => !allowed(p));
31443
- const texts = readAll(facts, unallowed);
31444
- unallowed.forEach((path, i) => {
31445
- const text = texts[i];
31446
- if (text === void 0) return;
31447
- const n = linesOf$1(text).findIndex((l) => pattern.test(l));
31448
- if (n >= 0) failures.push(where + path + ":" + (n + 1) + " matches its pattern outside its allowed hits");
31449
- });
31450
- }
31451
- const result = {
31452
- failures,
31453
- expanded
31454
- };
31455
- if (files !== void 0) result.lane = laneOf(facts, [.../* @__PURE__ */ new Set([...files, ...report.newFiles])].sort(byCodePoint$2));
31456
- if (report.skipped !== void 0) result.skipped = report.skipped;
31457
- return result;
31494
+ const cmp$5 = (a, b) => a < b ? -1 : a > b ? 1 : 0;
31495
+ function byFileLineRule(a, b) {
31496
+ return cmp$5(a.file, b.file) || (a.line ?? 0) - (b.line ?? 0) || cmp$5(a.rule, b.rule) || cmp$5(a.reason, b.reason) || cmp$5(a.pointer ?? "", b.pointer ?? "");
31458
31497
  }
31459
- const fail = (reason) => ({
31460
- verdict: "fail",
31461
- reasons: [reason]
31462
- });
31463
- function taskVerdict(snapshot, id, n) {
31464
- const plan = workOf(snapshot, id)?.plan;
31465
- if (plan === void 0) return fail("no plan at " + planFile(id));
31466
- const task = plan.tasks.find((t) => t.n === n);
31467
- if (plan.planHash === void 0) return fail(`plan.md has no plan_hash:; run accord gate plan ${id}`);
31468
- if (plan.planHash !== plan.bodyHash) return fail(`plan.md changed after accord gate plan last passed; run accord gate plan ${id} again`);
31469
- if (task === void 0) return fail(`the plan has no "## Task ${n}"`);
31470
- if (task.verify.length === 0) return fail(`task ${n} has no verify: line`);
31471
- const tests = snapshot.tests;
31472
- if (!reportLoaded(snapshot) || tests === void 0) return fail("no test report is loaded; set tests.report and run the tests");
31473
- const report = normaliseKey(reportPath$1(snapshot) ?? "");
31474
- const reasons = task.verify.flatMap((v) => !Object.hasOwn(tests, v) ? [`${v} is not in ${report}`] : tests[v] !== "passed" ? [`${v} is recorded ${tests[v]} in ${report}`] : []);
31475
- return reasons.length === 0 ? {
31476
- verdict: "pass",
31477
- reasons: []
31478
- } : {
31479
- verdict: "fail",
31480
- reasons
31481
- };
31498
+ /**
31499
+ * D-89 ticket scope: the ticket file, its folder, and its assets folder. String comparison only — an id
31500
+ * may contain `.`, `-`, and `_`, so a regular expression built from it would widen the scope and pull a
31501
+ * neighbouring ticket's findings into this result (T-04-01).
31502
+ */
31503
+ function scoped(findings, id) {
31504
+ const file = "accord/tickets/" + id + ".md";
31505
+ const folder = "accord/tickets/" + id + "/";
31506
+ const assets = "accord/assets/" + id + "/";
31507
+ return findings.filter((f) => f.file === file || f.file.startsWith(folder) || f.file.startsWith(assets));
31482
31508
  }
31483
31509
  /**
31484
- * ST-LN-50 D-08 Ruling: with the plan stage off task 1 is the whole ticket, and its tests are named at task-done by `maps` (`ac` as `@ac-n`, like a plan
31485
- * task's maps). The verdict is a pass when every scenario that is not @ui is mapped exactly once, every map names a scenario of the ticket, and each named test
31486
- * passed in the report: the verification floor (gate.test-tag-missing, LOCKED) never depends on the plan stage.
31510
+ * The shared gate body. One function, so `downgradeMaintain` keeps exactly one call site and every gate
31511
+ * inherits the GATE-07 matrix: a second copy is how one gate silently falls out of that matrix the
31512
+ * moment GATE-12 flips a level (D-88). `promote` is the D-89 hygiene promotion, which is Ready's alone.
31513
+ * Pure: reads the snapshot only, never mutates it, and returns the same result on every call.
31487
31514
  */
31488
- function ticketTaskVerdict(snapshot, id, maps) {
31489
- const ticket = Object.hasOwn(snapshot.tickets, id) ? snapshot.tickets[id] : void 0;
31490
- if (ticket === void 0) return fail(`no ticket ${id}`);
31491
- const tests = snapshot.tests;
31492
- if (!reportLoaded(snapshot) || tests === void 0) return fail("no test report is loaded; set tests.report and run the tests");
31493
- const report = normaliseKey(reportPath$1(snapshot) ?? "");
31494
- const known = new Set(ticket.scenarios.flatMap((s) => s.acTag === void 0 ? [] : ["@" + s.acTag]));
31495
- const reasons = [];
31496
- for (const ac of new Set(maps.map((m) => m.ac))) if (!known.has(ac)) reasons.push(`${ac} is not a scenario of the ticket`);
31497
- else if (maps.filter((m) => m.ac === ac).length > 1) reasons.push(`${ac} is named by more than one --test`);
31498
- if (reasons.length > 0) return {
31499
- verdict: "fail",
31500
- reasons
31515
+ function run(gate, rules, promote, snapshot, id) {
31516
+ const profile = snapshot.config?.profile ?? "build";
31517
+ const strictness = resolveStrictness(snapshot.config);
31518
+ const memo = /* @__PURE__ */ new Map();
31519
+ const once = (key, compute) => {
31520
+ if (!memo.has(key)) memo.set(key, compute());
31521
+ return memo.get(key);
31501
31522
  };
31502
- for (const s of ticket.scenarios) if (s.acTag !== void 0 && !s.tags.includes("@ui") && !maps.some((m) => m.ac === "@" + s.acTag)) reasons.push(`@${s.acTag} has no --test: every scenario that is not @ui needs one test`);
31503
- for (const test of new Set(maps.map((m) => m.test))) if (!Object.hasOwn(tests, test)) reasons.push(`${test} is not in ${report}`);
31504
- else if (tests[test] !== "passed") reasons.push(`${test} is recorded ${tests[test]} in ${report}`);
31505
- return reasons.length === 0 ? {
31506
- verdict: "pass",
31507
- reasons: []
31508
- } : {
31509
- verdict: "fail",
31510
- reasons
31523
+ const gated = rules.filter((r) => r.profiles.includes(profile)).filter((r) => !Object.hasOwn(STAGE_OF, r.id) || !stageOff(snapshot, id, STAGE_OF[r.id])).flatMap((r) => {
31524
+ const level = effectiveLevel(r.id, r.level, strictness);
31525
+ return level === "off" ? [] : r.check(snapshot, id, once).map((d) => ({
31526
+ ...d,
31527
+ rule: r.id,
31528
+ level
31529
+ }));
31530
+ });
31531
+ const known = Object.hasOwn(snapshot.tickets, id);
31532
+ const findings = [...known ? downgradeMaintain(scoped(lintSnapshot(snapshot).findings, id), profile, strictness.levels).map((f) => promote.includes(f.rule) ? {
31533
+ ...f,
31534
+ level: "error"
31535
+ } : f) : [], ...gated].sort(byFileLineRule);
31536
+ const hash = known ? readyHash(snapshot.tickets[id]) : void 0;
31537
+ return {
31538
+ gate,
31539
+ ticket: id,
31540
+ verdict: findings.some((f) => f.level === "error") ? "fail" : "pass",
31541
+ findings,
31542
+ ...hash === void 0 ? {} : { acHash: hash }
31511
31543
  };
31512
31544
  }
31513
- const HUNK = /^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/;
31514
- const headerPath = (rest, prefix) => {
31515
- const t = rest.replace(/\t$/, "");
31516
- return t.startsWith(prefix) ? t.slice(2) : void 0;
31517
- };
31518
- /** `diff --git a/<p> b/<p>`: the path when both halves are equal (a rename or a quoted name is read from its own lines instead). */
31519
- function pathOfGitHeader(rest) {
31520
- if (!rest.startsWith("a/")) return void 0;
31521
- const total = rest.length - 5;
31522
- if (total <= 0 || total % 2 !== 0) return void 0;
31523
- const p = rest.slice(2, 2 + total / 2);
31524
- return rest === `a/${p} b/${p}` ? p : void 0;
31545
+ /** GATE-01: the Ready table plus the three LINT-06 hygiene rules promoted to blocking (D-89). */
31546
+ function gateReady(snapshot, id) {
31547
+ return run("ready", READY_RULES, READY_PROMOTE, snapshot, id);
31548
+ }
31549
+ /** Spec §7: the plan gate plus the ticket-scoped lint findings, which include load findings on plan.md. Lane R runs PLAN_R_RULES. */
31550
+ function gatePlan(snapshot, id) {
31551
+ if ((Object.hasOwn(snapshot.tickets, id) ? snapshot.tickets[id].frontmatter?.lane : void 0) === "R") return run("plan", PLAN_R_RULES, [], snapshot, id);
31552
+ const result = run("plan", PLAN_RULES, [], snapshot, id);
31553
+ const planHash = laneTicket(snapshot, id) === void 0 ? void 0 : workOf(snapshot, id)?.plan?.bodyHash;
31554
+ return planHash === void 0 ? result : {
31555
+ ...result,
31556
+ planHash
31557
+ };
31525
31558
  }
31526
31559
  /**
31527
- * Split a diff text on its `diff --git` lines. Header lines are read only outside a hunk; inside one the hunk's own counts decide where it ends,
31528
- * so a removed `-- x` line (`--- x` in the text) or a context line that looks like a header is never read as one.
31560
+ * GATE-02/GATE-03/GATE-11: the Done table plus every ticket-scoped lint finding at the level lint
31561
+ * stamped. No hygiene promotion and no design rule — Done does not re-run Ready (D-89 applied to Done).
31529
31562
  */
31530
- function diffFiles(diffText) {
31531
- const files = [];
31532
- let cur;
31533
- let oldLeft = 0;
31534
- let newLeft = 0;
31535
- let oldNo = 0;
31536
- let newNo = 0;
31537
- let renameTo;
31538
- let deleted = false;
31539
- let hunk;
31540
- const finish = () => {
31541
- if (cur === void 0) return;
31542
- if (renameTo !== void 0) cur.path = renameTo;
31543
- if (deleted && cur.path === void 0 && cur.oldPath !== void 0) cur.path = cur.oldPath;
31563
+ function gateDone(snapshot, id) {
31564
+ const lane = Object.hasOwn(snapshot.tickets, id) ? snapshot.tickets[id].frontmatter?.lane : void 0;
31565
+ return run("done", lane === "S" ? DONE_S_RULES : lane === "R" ? DONE_R_RULES : DONE_RULES, [], snapshot, id);
31566
+ }
31567
+ const HEADER$2 = [
31568
+ "claim",
31569
+ "pattern",
31570
+ "folders",
31571
+ "allowed hits"
31572
+ ];
31573
+ const SKIPPED = /^\s*(?:[-*+]\s+)?skipped:\s*(\S.*)$/;
31574
+ const CITATION = /(?<![\p{L}\p{N}_.@+\-[\]/:])((?:[\p{L}\p{N}_.@+\-[\]]+\/)*[\p{L}\p{N}_.@+\-[\]]+):(\d+(?:-\d+)?(?:,\d+(?:-\d+)?)*)(?![\p{L}\p{N}_])/gu;
31575
+ /** One wrapping pair of backticks, when the text is at least two characters and starts and ends with one. */
31576
+ function unwrap(text) {
31577
+ return text.length >= 2 && text.startsWith("`") && text.endsWith("`") ? text.slice(1, -1) : text;
31578
+ }
31579
+ /** The lines of a section outside fences and HTML comments. */
31580
+ function bodyLines(section, fences) {
31581
+ const inFence = (n) => fences.some((f) => n >= f.open && n <= f.close);
31582
+ return stripHtmlComments(section.lines.filter((l) => !inFence(l.line)));
31583
+ }
31584
+ /** The paths of a `## Files` or `## New files` list: the first token of each list line, cleaned. */
31585
+ function listEntries(lines) {
31586
+ const out = [];
31587
+ for (const { text } of lines) {
31588
+ if (!LIST_MARKER.test(text)) continue;
31589
+ const entry = unwrap(unwrap(text.replace(LIST_MARKER, "").trim().split(/\s+/)[0] ?? "").replace(/:$/, "")).replace(/\\/g, "/").replace(/^\.\//, "").replace(/:\d+(?:[-,]\d+)*$/, "");
31590
+ if (entry !== "") out.push(entry);
31591
+ }
31592
+ return out;
31593
+ }
31594
+ /** The cells of one table line: edge pipes dropped, split on a pipe that is not `\|`, each cell unescaped. */
31595
+ function cellsOf(text) {
31596
+ let t = text.trim();
31597
+ if (t.startsWith("|")) t = t.slice(1);
31598
+ if (t.endsWith("|") && !t.endsWith("\\|")) t = t.slice(0, -1);
31599
+ return t.split(/(?<!\\)\|/).map((c) => unwrap(c.replace(/\\\|/g, "|").trim()));
31600
+ }
31601
+ /** A Folders or Allowed hits cell: entries split on whitespace and commas, each losing a wrapping backtick. */
31602
+ function entriesOf(cell) {
31603
+ return cell.split(/[\s,]+/).map((e) => e.replace(/^`/, "").replace(/`$/, "")).filter((e) => e !== "");
31604
+ }
31605
+ function parseScoutReport(text) {
31606
+ const norm = normaliseText(text);
31607
+ const { sections, fences } = scan(norm, 0);
31608
+ const section = (key) => sections.find((s) => headingKey(s.heading) === key);
31609
+ const filesSection = section("files");
31610
+ const newSection = section("new files");
31611
+ const absentSection = section("absent");
31612
+ const report = {
31613
+ newFiles: newSection === void 0 ? [] : listEntries(bodyLines(newSection, fences)),
31614
+ absent: [],
31615
+ faults: [],
31616
+ citations: []
31544
31617
  };
31545
- for (const raw of diffText.split("\n")) {
31546
- const text = raw.endsWith("\r") ? raw.slice(0, -1) : raw;
31547
- if (cur !== void 0 && (oldLeft > 0 || newLeft > 0)) {
31548
- const c = text[0];
31549
- if (c === "+") {
31550
- newLeft--;
31551
- const l = {
31552
- line: newNo++,
31553
- text: text.slice(1)
31554
- };
31555
- cur.added.push(l);
31556
- hunk?.added.push(l);
31557
- hunk?.lines.push(text);
31558
- continue;
31559
- }
31560
- if (c === "-") {
31561
- oldLeft--;
31562
- const l = {
31563
- line: oldNo++,
31564
- text: text.slice(1)
31565
- };
31566
- cur.removed.push(l);
31567
- hunk?.removed.push(l);
31568
- hunk?.lines.push(text);
31569
- continue;
31570
- }
31571
- if (c === " " || text === "") {
31572
- oldLeft--;
31573
- newLeft--;
31574
- oldNo++;
31575
- newNo++;
31576
- hunk?.lines.push(text);
31577
- continue;
31578
- }
31579
- if (c === "\\") {
31580
- hunk?.lines.push(text);
31581
- continue;
31582
- }
31583
- oldLeft = 0;
31584
- newLeft = 0;
31585
- }
31586
- if (text.startsWith("diff --git ")) {
31587
- finish();
31588
- renameTo = void 0;
31589
- deleted = false;
31590
- cur = {
31591
- path: pathOfGitHeader(text.slice(11)),
31592
- binary: false,
31593
- added: [],
31594
- removed: [],
31595
- header: [text],
31596
- hunks: []
31597
- };
31598
- hunk = void 0;
31599
- files.push(cur);
31600
- continue;
31601
- }
31602
- if (cur === void 0) continue;
31603
- if (hunk !== void 0 && text.startsWith("\\")) {
31604
- hunk.lines.push(text);
31605
- continue;
31606
- }
31607
- const h = HUNK.exec(text);
31608
- if (h !== null) {
31609
- hunk = {
31610
- lines: [text],
31611
- added: [],
31612
- removed: []
31613
- };
31614
- cur.hunks.push(hunk);
31615
- oldNo = Number(h[1]);
31616
- oldLeft = h[2] === void 0 ? 1 : Number(h[2]);
31617
- newNo = Number(h[3]);
31618
- newLeft = h[4] === void 0 ? 1 : Number(h[4]);
31619
- if (oldLeft === 0) oldNo++;
31620
- if (newLeft === 0) newNo++;
31621
- continue;
31622
- }
31623
- if (hunk === void 0 && text !== "") cur.header.push(text);
31624
- if (text.startsWith("+++ ")) {
31625
- if (text === "+++ /dev/null") deleted = true;
31626
- else {
31627
- const p = headerPath(text.slice(4), "b/");
31628
- if (p !== void 0) cur.path = p;
31629
- }
31630
- } else if (text.startsWith("--- ")) {
31631
- if (text !== "--- /dev/null") {
31632
- const p = headerPath(text.slice(4), "a/");
31633
- if (p !== void 0) {
31634
- cur.oldPath = p;
31635
- if (cur.path === void 0) cur.path = p;
31618
+ if (filesSection !== void 0) report.files = listEntries(bodyLines(filesSection, fences));
31619
+ if (absentSection !== void 0) {
31620
+ const table = bodyLines(absentSection, fences).filter((l) => l.text.trim().startsWith("|"));
31621
+ if (table.length > 0) {
31622
+ const header = cellsOf(table[0].text).map((c) => c.toLowerCase());
31623
+ if (header.length !== HEADER$2.length || header.some((c, i) => c !== HEADER$2[i])) report.faults.push("the ## Absent table header is not | Claim | Pattern | Folders | Allowed hits |");
31624
+ else for (const { line, text: rowText } of table.slice(1)) {
31625
+ const cells = cellsOf(rowText);
31626
+ if (cells.every((c) => /^:?-+:?$/.test(c))) continue;
31627
+ if (cells.length !== 4) {
31628
+ report.faults.push("## Absent row at line " + line + " has " + cells.length + " cells, not 4: escape a pipe inside a cell");
31629
+ continue;
31636
31630
  }
31637
- }
31638
- } else if (text.startsWith("rename from ")) cur.oldPath = text.slice(12).replace(/\t$/, "");
31639
- else if (text.startsWith("rename to ")) renameTo = text.slice(10).replace(/\t$/, "");
31640
- else if (text.startsWith("Binary files ") || text === "GIT binary patch") {
31641
- cur.binary = true;
31642
- if (cur.path === void 0 && text.startsWith("Binary files ") && text.endsWith(" differ")) {
31643
- const mid = text.slice(13, -7);
31644
- if (mid.startsWith("/dev/null and b/")) cur.path = mid.slice(16);
31645
- else if (mid.endsWith(" and /dev/null") && mid.startsWith("a/")) cur.path = mid.slice(2, -14);
31631
+ const folders = entriesOf(cells[2]);
31632
+ report.absent.push({
31633
+ line,
31634
+ claim: cells[0],
31635
+ pattern: cells[1],
31636
+ folders: folders.length === 0 ? [""] : folders,
31637
+ allowed: entriesOf(cells[3])
31638
+ });
31646
31639
  }
31647
31640
  }
31648
31641
  }
31649
- finish();
31650
- return files;
31642
+ const seen = /* @__PURE__ */ new Set();
31643
+ for (const m of norm.replace(/\\/g, "/").matchAll(CITATION)) {
31644
+ const path = m[1];
31645
+ if (!path.includes("/") && !path.includes(".") || seen.has(m[0])) continue;
31646
+ seen.add(m[0]);
31647
+ report.citations.push({
31648
+ text: m[0],
31649
+ path,
31650
+ numbers: (m[2].match(/\d+/g) ?? []).map(Number)
31651
+ });
31652
+ }
31653
+ const inFence = (n) => fences.some((f) => n >= f.open && n <= f.close);
31654
+ const raw = norm.split("\n");
31655
+ for (let i = 0; i < raw.length; i++) {
31656
+ if (inFence(i + 1)) continue;
31657
+ const m = SKIPPED.exec(raw[i]);
31658
+ if (m) {
31659
+ report.skipped = m[1].trim();
31660
+ break;
31661
+ }
31662
+ }
31663
+ return report;
31664
+ }
31665
+ const SLICE = 100;
31666
+ const CLAIM_CAP = 80;
31667
+ /** A claim as printed: backslashes to slashes, whitespace runs to one space, cut at 80 characters with `...`. */
31668
+ function printedClaim(claim) {
31669
+ const flat = claim.replace(/\\/g, "/").replace(/\s+/g, " ");
31670
+ return flat.length > CLAIM_CAP ? flat.slice(0, CLAIM_CAP) + "..." : flat;
31671
+ }
31672
+ const byCodePoint$2 = (a, b) => {
31673
+ const x = Array.from(a);
31674
+ const y = Array.from(b);
31675
+ for (let i = 0; i < Math.min(x.length, y.length); i++) if (x[i] !== y[i]) return x[i].codePointAt(0) - y[i].codePointAt(0);
31676
+ return x.length - y.length;
31677
+ };
31678
+ /** The lines of a file's text after BOM and CRLF normalisation, one trailing empty element dropped. */
31679
+ function linesOf$1(text) {
31680
+ const lines = normaliseText(text).split("\n");
31681
+ if (lines.length > 0 && lines[lines.length - 1] === "") lines.pop();
31682
+ return lines;
31651
31683
  }
31652
31684
  /**
31653
- * The one scan bound (D-09): a changed line is matched on its first SCAN_LINE_LIMIT characters only. The bound caps the time an allowed pattern may take per changed line, which is at most
31654
- * two overlapping repeats in a row and 16 routes for one text; exponential shapes, longer runs and more routes are refused at read by backtrack.ts. The total still grows with the number of
31655
- * changed lines, each one costing at most the sum of the patterns' cost on SCAN_LINE_LIMIT characters (08-08b states the figures); no total cap is built.
31685
+ * Which tracked paths a list of folder or file entries covers: `\` becomes `/`, a leading `./` goes, and `.`, `/`
31686
+ * and the empty string mean the root. An entry covers a path when it is the root, ends in `/` and the path starts
31687
+ * with it, is a folder (some tracked path sits below it) the path is below, or is the path itself.
31656
31688
  */
31657
- const SCAN_LINE_LIMIT = 1e3;
31658
- /** The label of the trigger a cut line gets: a line over the bound is never scanned whole and says so (fail closed). */
31659
- const LONG_LINE = `line longer than ${SCAN_LINE_LIMIT} characters, not fully scanned`;
31660
- const UNREADABLE = "too large to read as text, so its lines were not scanned";
31661
- const tooLong = (text) => text.length > SCAN_LINE_LIMIT;
31662
- /** The label of the trigger a file git calls binary gets when it is not a known binary type (D-20): a NUL byte on a changed line makes git call a code file binary, and its lines were then never scanned. */
31663
- const BINARY_LABEL = "binary file, its lines were not scanned";
31664
- /** Image, font and archive types git rightly calls binary; any other binary file with no text twin is a `cannot` trigger (fail closed). */
31665
- const KNOWN_BINARY = /* @__PURE__ */ new Set([
31666
- "png",
31667
- "jpg",
31668
- "jpeg",
31669
- "gif",
31670
- "webp",
31671
- "ico",
31672
- "bmp",
31673
- "avif",
31674
- "woff",
31675
- "woff2",
31676
- "ttf",
31677
- "otf",
31678
- "eot",
31679
- "zip",
31680
- "gz",
31681
- "tgz",
31682
- "tar",
31683
- "bz2",
31684
- "xz",
31685
- "7z",
31686
- "pdf"
31687
- ]);
31688
- /** The extension of a path: the text after the last `.` of its name, lower-cased; empty when the name holds none. */
31689
- const extensionOf$1 = (path) => {
31690
- const name = path.slice(path.lastIndexOf("/") + 1);
31691
- const dot = name.lastIndexOf(".");
31692
- return dot < 0 ? "" : name.slice(dot + 1).toLowerCase();
31693
- };
31694
- const MARKDOWN$1 = /\.(md|mdx|markdown)$/i;
31695
- const TEST_FOLDER = /* @__PURE__ */ new Set([
31696
- "test",
31697
- "tests",
31698
- "__tests__"
31699
- ]);
31700
- /** lane.md's definition: under a folder named `test`, `tests` or `__tests__`, or a name holding `.test.` or `.spec.`. */
31701
- const isTestFile = (path) => {
31702
- const parts = path.split("/");
31703
- const name = parts[parts.length - 1];
31704
- return parts.slice(0, -1).some((d) => TEST_FOLDER.has(d)) || name.includes(".test.") || name.includes(".spec.");
31705
- };
31706
- /** A path entry of a security pattern compares ignoring letter case: Windows and default macOS open `.MCP.json` as `.mcp.json`. The trigger still names the path as the diff spells it. */
31707
- const pathMatches = (entry, path) => {
31708
- const e = entry.toLowerCase();
31709
- const p = path.toLowerCase();
31710
- if (e.endsWith("/") || e.includes("/")) return matches(e, p);
31711
- return p === e || p.endsWith("/" + e);
31712
- };
31713
- /** Code point order, so the same input sorts the same on every runtime. */
31714
- function cmp$5(a, b) {
31715
- const x = [...a];
31716
- const y = [...b];
31717
- for (let i = 0; i < Math.min(x.length, y.length); i++) {
31718
- const d = x[i].codePointAt(0) - y[i].codePointAt(0);
31719
- if (d !== 0) return d < 0 ? -1 : 1;
31720
- }
31721
- return x.length === y.length ? 0 : x.length < y.length ? -1 : 1;
31689
+ function coverage(entries, tracked) {
31690
+ const tests = entries.map((raw) => {
31691
+ const e = raw.replace(/\\/g, "/").replace(/^\.\//, "");
31692
+ if (e === "." || e === "/" || e === "") return () => true;
31693
+ const folder = !e.endsWith("/") && tracked.some((t) => t.startsWith(e + "/"));
31694
+ return (p) => e.endsWith("/") && p.startsWith(e) || folder && p.startsWith(e + "/") || p === e;
31695
+ });
31696
+ return (p) => tests.some((t) => t(p));
31722
31697
  }
31723
- /** The line patterns of a spec as regular expressions; a pattern that does not compile (parseSecurityFile reported it as a problem) matches nothing. */
31724
- function compileLines(spec) {
31698
+ /** The text of each path, read in slices of at most 100; undefined where a file cannot be read. */
31699
+ function readAll(facts, paths) {
31725
31700
  const out = [];
31726
- for (const p of spec.patterns) {
31727
- if (p.kind !== "line" || p.source === void 0) continue;
31728
- try {
31729
- out.push({
31730
- p,
31731
- re: new RegExp(p.source, p.flags ?? "")
31732
- });
31733
- } catch {}
31734
- }
31701
+ for (let i = 0; i < paths.length; i += SLICE) out.push(...facts.read(paths.slice(i, i + SLICE)));
31735
31702
  return out;
31736
31703
  }
31737
- /** The folders an agent loads and runs code from (D-22): a skill's scripts, a sub-agent's files and the panel. Compared ignoring letter case, as path entries are. */
31738
- const AGENT_FOLDERS = [
31739
- ".claude/skills/",
31740
- ".agents/skills/",
31741
- ".claude/agents/",
31742
- ".claude/accord-panel/"
31743
- ];
31744
- const underAgentFolder = (path) => {
31745
- const p = path.toLowerCase();
31746
- return AGENT_FOLDERS.some((f) => p.startsWith(f));
31747
- };
31748
- /**
31749
- * Phase 8.1 D-20: the part of the content skip every content scan shares: a path in `exempt` (exactly an unmodified copy `accord skills sync` writes, decided by the caller), a path the
31750
- * repository's `generated:` lists, and a Markdown file. The slop scan skips exactly these (and the package-manager files slop/match.ts lists) and judges test files; the security scan adds its test clause below.
31751
- */
31752
- const copyGeneratedOrMarkdown = (path, generated, exempt) => exempt.includes(path) || generated.some((e) => matches(e, path)) || MARKDOWN$1.test(path);
31753
31704
  /**
31754
- * Content patterns are not run over Markdown, test files, the repository's generated paths or a path in `exempt` (exactly an unmodified copy `accord skills sync`
31755
- * writes, decided by the caller). No folder is skipped as a whole: a file accord does not write, or a copy changed by hand, is scanned.
31756
- * D-22: a test-named file under an agent-loaded folder (AGENT_FOLDERS) is not skipped as a test, because an agent session can run it; Markdown there stays skipped, and an
31757
- * exempt copy or a generated path is skipped first.
31705
+ * The one tracked path that ends with `/` + `path`, so a shortened path reads as the file it names; undefined when no
31706
+ * tracked path or more than one does. The caller expands only a path git does not track as written.
31758
31707
  */
31759
- const contentSkipped = (path, generated, exempt) => copyGeneratedOrMarkdown(path, generated, exempt) || isTestFile(path) && !underAgentFolder(path);
31708
+ function expandPath(path, tracked) {
31709
+ if (path === "") return void 0;
31710
+ const tail = "/" + path;
31711
+ const hits = tracked.filter((t) => t.endsWith(tail));
31712
+ return hits.length === 1 ? hits[0] : void 0;
31713
+ }
31714
+ const SAVED_REPORT = /^accord\/tickets\/([^/]+)\/scout\.md$/;
31760
31715
  /**
31761
- * The triggers of a package: path patterns over every changed path (both sides of a rename); content patterns over the added and removed lines of
31762
- * files that are not binary, not Markdown, not test files, not generated and not an exact `exempt` path (nothing is exempt when absent); one `cannot` trigger for each changed path the diff text does not
31763
- * show. Deduplicated and sorted by path, then line, then pattern id.
31716
+ * The files no Absent row searches: the report itself and, for a report of a ticket (a saved report, or any report
31717
+ * checked with a ticket id), its ticket file, everything under the ticket's folder, and the research records its
31718
+ * ticket lists. A missing or unreadable ticket adds no record.
31764
31719
  */
31765
- function securityTriggers(spec, diffText, changed, options) {
31766
- const files = diffFiles(diffText);
31767
- const shown = /* @__PURE__ */ new Set();
31768
- for (const f of files) {
31769
- if (f.path !== void 0) shown.add(f.path);
31770
- if (f.oldPath !== void 0) shown.add(f.oldPath);
31771
- }
31772
- const out = /* @__PURE__ */ new Map();
31773
- const add = (t) => {
31774
- const key = [
31775
- t.path,
31776
- t.line ?? "",
31777
- t.removed === true ? "r" : "a",
31778
- t.pattern,
31779
- t.cannot === true ? "c" : ""
31780
- ].join("\0");
31781
- if (!out.has(key)) out.set(key, t);
31720
+ function ownFiles(facts, tracked) {
31721
+ const own = /* @__PURE__ */ new Set();
31722
+ if (facts.path !== void 0) own.add(facts.path);
31723
+ const id = facts.ticket ?? (facts.path === void 0 ? void 0 : SAVED_REPORT.exec(facts.path)?.[1]);
31724
+ if (id === void 0) return own;
31725
+ const ticket = "accord/tickets/" + id + ".md";
31726
+ own.add(ticket);
31727
+ for (const p of tracked) if (p.startsWith("accord/tickets/" + id + "/")) own.add(p);
31728
+ const text = facts.read([ticket])[0];
31729
+ if (text === void 0) return own;
31730
+ const yaml = splitFrontmatter(text).yaml;
31731
+ if (yaml === null) return own;
31732
+ const research = parseYamlMap(ticket, yaml, 1).map?.research;
31733
+ if (!Array.isArray(research)) return own;
31734
+ for (const entry of research) if (typeof entry === "string" && isResearchRecord(entry)) own.add(entry);
31735
+ return own;
31736
+ }
31737
+ const TEST_FOLDER = /* @__PURE__ */ new Set([
31738
+ "test",
31739
+ "tests",
31740
+ "__tests__"
31741
+ ]);
31742
+ const isTestFile = (path) => {
31743
+ const segments = path.split("/");
31744
+ const name = segments[segments.length - 1];
31745
+ return segments.slice(0, -1).some((s) => TEST_FOLDER.has(s)) || name.includes(".test.") || name.includes(".spec.");
31746
+ };
31747
+ /** The lane numbers of lane.md over the listed files: expected files, code areas, sensitive matches and the lifts. */
31748
+ function laneOf(facts, listed) {
31749
+ const lists = configLists(facts.config);
31750
+ const rendered = new Set(facts.rendered ?? []);
31751
+ const expected = listed.filter((p) => !isTestFile(p) && !rendered.has(p) && !lists.generated.some((e) => matches(e, p)));
31752
+ const areas = [...new Set(expected.map((p) => p.includes("/") ? p.split("/").slice(0, -1).slice(0, 4).join("/") : "."))].sort(byCodePoint$2);
31753
+ const sensitive = listed.flatMap((path) => lists.sensitive.filter((e) => matches(e.path, path)).map((e) => ({
31754
+ path,
31755
+ entry: e.path,
31756
+ area: e.area,
31757
+ line: e.line
31758
+ })));
31759
+ return {
31760
+ expected,
31761
+ areas,
31762
+ sensitive,
31763
+ lifts: [
31764
+ ...expected.length > 5 ? ["more than 5 expected files"] : [],
31765
+ ...areas.length > 3 ? ["more than 3 code areas"] : [],
31766
+ ...sensitive.length > 0 ? ["a listed sensitive area"] : []
31767
+ ]
31782
31768
  };
31783
- const pathPatterns = spec.patterns.filter((p) => p.kind === "path" && p.entries !== void 0);
31784
- for (const path of /* @__PURE__ */ new Set([...changed, ...shown])) for (const p of pathPatterns) if (p.entries.some((e) => pathMatches(e, path))) add({
31785
- path,
31786
- pattern: p.id,
31787
- label: p.label
31788
- });
31789
- const lineRes = compileLines(spec);
31790
- const skipped = (path) => contentSkipped(path, options.generated, options.exempt ?? []);
31791
- const unreadable = new Set(options.unreadable ?? []);
31792
- for (const f of files) {
31793
- if (f.binary && f.path !== void 0 && !skipped(f.path) && !unreadable.has(f.path) && !KNOWN_BINARY.has(extensionOf$1(f.path)) && !files.some((g) => !g.binary && g.path === f.path)) add({
31794
- path: f.path,
31795
- pattern: "",
31796
- label: BINARY_LABEL,
31797
- cannot: true
31769
+ }
31770
+ function scoutCheck(facts) {
31771
+ const report = parseScoutReport(facts.text);
31772
+ const tracked = [...facts.tracked].sort(byCodePoint$2);
31773
+ const trackedSet = new Set(tracked);
31774
+ const failures = [];
31775
+ const expanded = [];
31776
+ const expand = (path) => {
31777
+ if (trackedSet.has(path)) return path;
31778
+ const to = expandPath(path, tracked);
31779
+ if (to === void 0) return path;
31780
+ if (!expanded.some((e) => e.from === path)) expanded.push({
31781
+ from: path,
31782
+ to
31798
31783
  });
31799
- if (f.binary || f.path === void 0 || skipped(f.path)) continue;
31800
- const scanLines = (lines, removed) => {
31801
- for (const l of lines) {
31802
- const head = tooLong(l.text) ? l.text.slice(0, SCAN_LINE_LIMIT) : l.text;
31803
- if (tooLong(l.text)) add({
31804
- path: f.path,
31805
- line: l.line,
31806
- ...removed ? { removed: true } : {},
31807
- pattern: "",
31808
- label: LONG_LINE,
31809
- cannot: true
31810
- });
31811
- for (const { p, re } of lineRes) if (re.test(head)) add({
31812
- path: f.path,
31813
- line: l.line,
31814
- ...removed ? { removed: true } : {},
31815
- pattern: p.id,
31816
- label: p.label
31817
- });
31818
- }
31819
- };
31820
- scanLines(f.added, false);
31821
- scanLines(f.removed, true);
31784
+ return to;
31785
+ };
31786
+ const files = report.files?.map(expand);
31787
+ const citations = report.citations.map((c) => ({
31788
+ ...c,
31789
+ path: expand(c.path)
31790
+ }));
31791
+ if (report.files === void 0) failures.push("the report has no ## Files section, so no lane numbers can be computed");
31792
+ failures.push(...report.faults);
31793
+ for (const path of files ?? []) if (!trackedSet.has(path)) failures.push("## Files lists " + path + ", which git does not track");
31794
+ for (const path of report.newFiles) if (trackedSet.has(path)) failures.push("## New files lists " + path + ", which git already tracks");
31795
+ const cited = [...new Set(citations.map((c) => c.path).filter((p) => trackedSet.has(p)))];
31796
+ const citedTexts = /* @__PURE__ */ new Map();
31797
+ readAll(facts, cited).forEach((text, i) => citedTexts.set(cited[i], text));
31798
+ for (const c of citations) {
31799
+ const where = "citation " + c.text + " does not resolve: ";
31800
+ if (!trackedSet.has(c.path)) {
31801
+ failures.push(where + "git does not track " + c.path);
31802
+ continue;
31803
+ }
31804
+ const text = citedTexts.get(c.path);
31805
+ if (text === void 0) {
31806
+ failures.push(where + c.path + " cannot be read");
31807
+ continue;
31808
+ }
31809
+ const count = linesOf$1(text).length;
31810
+ if (c.numbers.some((n) => n < 1 || n > count)) failures.push(where + c.path + " has " + count + " lines");
31822
31811
  }
31823
- for (const path of changed) if (!shown.has(path)) add({
31824
- path,
31825
- pattern: "",
31826
- label: "",
31827
- cannot: true
31828
- });
31829
- for (const path of options.unreadable ?? []) add({
31830
- path,
31831
- pattern: "",
31832
- label: UNREADABLE,
31833
- cannot: true
31834
- });
31835
- return [...out.values()].sort((a, b) => cmp$5(a.path, b.path) || (a.line ?? 0) - (b.line ?? 0) || cmp$5(a.pattern, b.pattern) || Number(a.removed === true) - Number(b.removed === true));
31812
+ const own = report.absent.length > 0 ? ownFiles(facts, tracked) : /* @__PURE__ */ new Set();
31813
+ for (const row of report.absent) {
31814
+ const where = "absent claim \"" + printedClaim(row.claim) + "\" (row " + row.line + "): ";
31815
+ let pattern;
31816
+ try {
31817
+ pattern = new RegExp(row.pattern);
31818
+ } catch {
31819
+ failures.push(where + "its pattern is not a valid JavaScript regular expression");
31820
+ continue;
31821
+ }
31822
+ const covers = coverage(row.folders, tracked);
31823
+ const searched = tracked.filter((p) => covers(p) && !own.has(p) && !p.startsWith(".claude/") && !p.startsWith(".agents/"));
31824
+ if (searched.length === 0) {
31825
+ failures.push(where + "its folders cover no tracked file");
31826
+ continue;
31827
+ }
31828
+ const allowed = coverage(row.allowed, tracked);
31829
+ const unallowed = searched.filter((p) => !allowed(p));
31830
+ const texts = readAll(facts, unallowed);
31831
+ unallowed.forEach((path, i) => {
31832
+ const text = texts[i];
31833
+ if (text === void 0) return;
31834
+ const n = linesOf$1(text).findIndex((l) => pattern.test(l));
31835
+ if (n >= 0) failures.push(where + path + ":" + (n + 1) + " matches its pattern outside its allowed hits");
31836
+ });
31837
+ }
31838
+ const result = {
31839
+ failures,
31840
+ expanded
31841
+ };
31842
+ if (files !== void 0) result.lane = laneOf(facts, [.../* @__PURE__ */ new Set([...files, ...report.newFiles])].sort(byCodePoint$2));
31843
+ if (report.skipped !== void 0) result.skipped = report.skipped;
31844
+ return result;
31836
31845
  }
31837
- /** The line form of a trigger, as `accord review-package` prints it. */
31838
- function triggerText(t) {
31839
- if (t.cannot === true && t.line !== void 0) return `${t.path}:${t.line}${t.removed === true ? " (removed)" : ""}: (cannot tell: ${t.label})`;
31840
- if (t.cannot === true && t.label !== "") return `(cannot tell: ${t.path}: ${t.label})`;
31841
- if (t.cannot === true) return `(cannot tell: ${t.path} is not in the diff text)`;
31842
- if (t.line === void 0) return `${t.path}: ${t.pattern} (${t.label})`;
31843
- return `${t.path}:${t.line}${t.removed === true ? " (removed)" : ""}: ${t.pattern} (${t.label})`;
31846
+ const fail = (reason) => ({
31847
+ verdict: "fail",
31848
+ reasons: [reason]
31849
+ });
31850
+ function taskVerdict(snapshot, id, n) {
31851
+ const plan = workOf(snapshot, id)?.plan;
31852
+ if (plan === void 0) return fail("no plan at " + planFile(id));
31853
+ const task = plan.tasks.find((t) => t.n === n);
31854
+ if (plan.planHash === void 0) return fail(`plan.md has no plan_hash:; run accord gate plan ${id}`);
31855
+ if (plan.planHash !== plan.bodyHash) return fail(`plan.md changed after accord gate plan last passed; run accord gate plan ${id} again`);
31856
+ if (task === void 0) return fail(`the plan has no "## Task ${n}"`);
31857
+ if (task.verify.length === 0) return fail(`task ${n} has no verify: line`);
31858
+ const tests = snapshot.tests;
31859
+ if (!reportLoaded(snapshot) || tests === void 0) return fail("no test report is loaded; set tests.report and run the tests");
31860
+ const report = normaliseKey(reportPath$1(snapshot) ?? "");
31861
+ const reasons = task.verify.flatMap((v) => !Object.hasOwn(tests, v) ? [`${v} is not in ${report}`] : tests[v] !== "passed" ? [`${v} is recorded ${tests[v]} in ${report}`] : []);
31862
+ return reasons.length === 0 ? {
31863
+ verdict: "pass",
31864
+ reasons: []
31865
+ } : {
31866
+ verdict: "fail",
31867
+ reasons
31868
+ };
31844
31869
  }
31845
31870
  /**
31846
- * The security package's hunks (D-05 (4)): for each file with a trigger, in path order, one block of text. A file with a content match prints its header lines and every
31847
- * hunk that holds a match, whole (the package's `-U10` context), never another hunk. A file with a path match prints every hunk up to `cap` lines (300) and then
31848
- * `(truncated: <n> more lines in <path>)`; a hunk that holds a content match is printed whole even past the cap, so a cut never hides a match. A path the diff text does not
31849
- * show is one block, `(cannot tell: …)`. Content matches are read from the hunks themselves, with the patterns and skips securityTriggers uses, so the two agree.
31871
+ * ST-LN-50 D-08 Ruling: with the plan stage off task 1 is the whole ticket, and its tests are named at task-done by `maps` (`ac` as `@ac-n`, like a plan
31872
+ * task's maps). The verdict is a pass when every scenario that is not @ui is mapped exactly once, every map names a scenario of the ticket, and each named test
31873
+ * passed in the report: the verification floor (gate.test-tag-missing, LOCKED) never depends on the plan stage.
31850
31874
  */
31851
- function matchedHunks(spec, diffText, changed, options) {
31852
- const cap = options.cap ?? 300;
31853
- const triggers = securityTriggers(spec, diffText, changed, {
31854
- generated: options.generated,
31855
- unreadable: options.unreadable,
31856
- exempt: options.exempt
31857
- });
31858
- const pathHit = new Set(triggers.filter((t) => t.cannot !== true && t.line === void 0).map((t) => t.path));
31859
- const lineRes = compileLines(spec);
31860
- const holds = (h) => [...h.added, ...h.removed].some((l) => {
31861
- if (tooLong(l.text)) return true;
31862
- return lineRes.some(({ re }) => re.test(l.text));
31863
- });
31864
- const blocks = [];
31865
- const files = diffFiles(diffText);
31866
- for (const f of files) {
31867
- if (f.binary && f.path !== void 0 && files.some((g) => !g.binary && g.path === f.path)) continue;
31868
- const name = f.path ?? f.oldPath;
31869
- const byPath = f.path !== void 0 && pathHit.has(f.path) || f.oldPath !== void 0 && pathHit.has(f.oldPath);
31870
- const content = f.binary || f.path === void 0 || contentSkipped(f.path, options.generated, options.exempt ?? []) ? /* @__PURE__ */ new Set() : new Set(f.hunks.filter(holds));
31871
- if (!byPath && content.size === 0) continue;
31872
- const lines = [...f.header];
31873
- let budget = cap;
31874
- let left = 0;
31875
- for (const h of f.hunks) if (content.has(h)) {
31876
- lines.push(...h.lines);
31877
- budget = Math.max(0, budget - h.lines.length);
31878
- } else if (byPath) {
31879
- const take = Math.min(budget, h.lines.length);
31880
- lines.push(...h.lines.slice(0, take));
31881
- budget -= take;
31882
- left += h.lines.length - take;
31883
- }
31884
- if (left > 0) lines.push(`(truncated: ${left} more lines in ${name})`);
31885
- blocks.push({
31886
- key: name ?? "",
31887
- text: lines.join("\n")
31888
- });
31889
- }
31890
- for (const t of triggers) if (t.cannot === true && t.line === void 0) blocks.push({
31891
- key: t.path,
31892
- text: triggerText(t)
31893
- });
31894
- return blocks.sort((a, b) => cmp$5(a.key, b.key)).map((b) => b.text);
31875
+ function ticketTaskVerdict(snapshot, id, maps) {
31876
+ const ticket = Object.hasOwn(snapshot.tickets, id) ? snapshot.tickets[id] : void 0;
31877
+ if (ticket === void 0) return fail(`no ticket ${id}`);
31878
+ const tests = snapshot.tests;
31879
+ if (!reportLoaded(snapshot) || tests === void 0) return fail("no test report is loaded; set tests.report and run the tests");
31880
+ const report = normaliseKey(reportPath$1(snapshot) ?? "");
31881
+ const known = new Set(ticket.scenarios.flatMap((s) => s.acTag === void 0 ? [] : ["@" + s.acTag]));
31882
+ const reasons = [];
31883
+ for (const ac of new Set(maps.map((m) => m.ac))) if (!known.has(ac)) reasons.push(`${ac} is not a scenario of the ticket`);
31884
+ else if (maps.filter((m) => m.ac === ac).length > 1) reasons.push(`${ac} is named by more than one --test`);
31885
+ if (reasons.length > 0) return {
31886
+ verdict: "fail",
31887
+ reasons
31888
+ };
31889
+ for (const s of ticket.scenarios) if (s.acTag !== void 0 && !s.tags.includes("@ui") && !maps.some((m) => m.ac === "@" + s.acTag)) reasons.push(`@${s.acTag} has no --test: every scenario that is not @ui needs one test`);
31890
+ for (const test of new Set(maps.map((m) => m.test))) if (!Object.hasOwn(tests, test)) reasons.push(`${test} is not in ${report}`);
31891
+ else if (tests[test] !== "passed") reasons.push(`${test} is recorded ${tests[test]} in ${report}`);
31892
+ return reasons.length === 0 ? {
31893
+ verdict: "pass",
31894
+ reasons: []
31895
+ } : {
31896
+ verdict: "fail",
31897
+ reasons
31898
+ };
31895
31899
  }
31896
31900
  /**
31897
31901
  * D-20 (plan-level Ruling): a dependency lockfile is written by its package manager, never by hand, so for the slop scan it is a generated file even when `generated:` does not list it. Base names,
@@ -31955,19 +31959,43 @@ function compile(spec) {
31955
31959
  return out;
31956
31960
  }
31957
31961
  /**
31958
- * The slop hits of a package: each pattern of `spec` over the added lines of every changed text file its scope allows. A binary file has no added text lines in the diff, so it gives no hit.
31959
- * A line is matched on its first SCAN_LINE_LIMIT characters; slop is a quality signal, not a security boundary, so the rest of a longer line adds no hit.
31962
+ * WR-02: the kind of the hit a line or a file the scan could not read whole gets, as the security scan reports `cannot` (fail closed). It is not a pattern and not in the `Removed:` list, so only a
31963
+ * fix or a justification line (`slop:unscanned <path>:<line> — <reason>`) clears it; padding a line past SCAN_LINE_LIMIT or hiding a NUL byte in a code file cannot.
31964
+ */
31965
+ const UNSCANNED = "unscanned";
31966
+ const LONG_LINE = `line longer than ${SCAN_LINE_LIMIT} characters, only its first ${SCAN_LINE_LIMIT} were scanned`;
31967
+ const BINARY_FILE = "binary file, its lines were not scanned";
31968
+ /**
31969
+ * The slop hits of a package: each pattern of `spec` over the added lines of every changed text file its scope allows. A line is matched on its first SCAN_LINE_LIMIT characters (which bounds the time
31970
+ * a pattern may take); a longer line, and a file git calls binary that is not a known image, font or archive and has no text section of the same path, are an `unscanned` hit (WR-02), never silence.
31960
31971
  */
31961
31972
  function slopHits(spec, diffText, options) {
31962
31973
  const res = compile(spec);
31963
31974
  const hits = [];
31964
- for (const f of diffFiles(diffText)) {
31965
- if (f.binary || f.path === void 0 || slopSkipped(f.path, options.generated, options.exempt ?? [])) continue;
31975
+ const files = diffFiles(diffText);
31976
+ for (const f of files) {
31977
+ if (f.path === void 0 || slopSkipped(f.path, options.generated, options.exempt ?? [])) continue;
31966
31978
  const ext = extensionOf(f.path);
31967
31979
  const scoped = res.filter(({ p }) => p.exts === void 0 || p.exts.includes(ext));
31968
31980
  if (scoped.length === 0) continue;
31981
+ if (f.binary) {
31982
+ if (!KNOWN_BINARY.has(ext.slice(1)) && !files.some((g) => !g.binary && g.path === f.path)) hits.push({
31983
+ kind: UNSCANNED,
31984
+ path: f.path,
31985
+ line: 1,
31986
+ label: BINARY_FILE
31987
+ });
31988
+ continue;
31989
+ }
31969
31990
  for (const l of f.added) {
31970
- const head = l.text.length > 1e3 ? l.text.slice(0, SCAN_LINE_LIMIT) : l.text;
31991
+ const long = l.text.length > SCAN_LINE_LIMIT;
31992
+ const head = long ? l.text.slice(0, SCAN_LINE_LIMIT) : l.text;
31993
+ if (long) hits.push({
31994
+ kind: UNSCANNED,
31995
+ path: f.path,
31996
+ line: l.line,
31997
+ label: LONG_LINE
31998
+ });
31971
31999
  for (const { p, re } of scoped) if (re.test(head)) hits.push({
31972
32000
  kind: p.id,
31973
32001
  path: f.path,
@@ -32083,6 +32111,31 @@ function xmlDeps(text) {
32083
32111
  }
32084
32112
  return out;
32085
32113
  }
32114
+ /**
32115
+ * The part of a TOML array line before its closing `]` and before a `#` comment, both found outside quotes (WR-01): a requirement such as `"rich[jupyter]>=13"` holds a `]` of its own.
32116
+ * `closed` is true when the array ends on this line.
32117
+ */
32118
+ function arrayPart(s) {
32119
+ let q;
32120
+ for (let i = 0; i < s.length; i++) {
32121
+ const c = s[i];
32122
+ if (q !== void 0) {
32123
+ if (c === q) q = void 0;
32124
+ } else if (c === "\"" || c === "'") q = c;
32125
+ else if (c === "#") return {
32126
+ text: s.slice(0, i),
32127
+ closed: false
32128
+ };
32129
+ else if (c === "]") return {
32130
+ text: s.slice(0, i),
32131
+ closed: true
32132
+ };
32133
+ }
32134
+ return {
32135
+ text: s,
32136
+ closed: false
32137
+ };
32138
+ }
32086
32139
  function pyprojectDeps(text) {
32087
32140
  const out = [];
32088
32141
  let table = "";
@@ -32100,9 +32153,9 @@ function pyprojectDeps(text) {
32100
32153
  for (const [i, raw] of text.split("\n").entries()) {
32101
32154
  const line = i + 1;
32102
32155
  if (inArray) {
32103
- const end = raw.indexOf("]");
32104
- fromArray(end < 0 ? raw : raw.slice(0, end), line);
32105
- if (end >= 0) inArray = false;
32156
+ const part = arrayPart(raw);
32157
+ fromArray(part.text, line);
32158
+ if (part.closed) inArray = false;
32106
32159
  continue;
32107
32160
  }
32108
32161
  const header = /^\s*\[([^\]]+)\]\s*(?:#.*)?$/.exec(raw);
@@ -32112,9 +32165,9 @@ function pyprojectDeps(text) {
32112
32165
  }
32113
32166
  const arrays = table === "project" ? /^\s*dependencies\s*=\s*\[(.*)$/.exec(raw) : table === "project.optional-dependencies" || table === "dependency-groups" ? /^\s*[\w."'-]+\s*=\s*\[(.*)$/.exec(raw) : null;
32114
32167
  if (arrays !== null) {
32115
- const end = arrays[1].indexOf("]");
32116
- fromArray(end < 0 ? arrays[1] : arrays[1].slice(0, end), line);
32117
- inArray = end < 0;
32168
+ const part = arrayPart(arrays[1]);
32169
+ fromArray(part.text, line);
32170
+ inArray = !part.closed;
32118
32171
  continue;
32119
32172
  }
32120
32173
  if (/^tool\.poetry(?:\.group\.[^.]+)?\.(?:dev-)?dependencies$/.test(table)) {
@@ -32292,7 +32345,7 @@ function isEntryPoint(path) {
32292
32345
  const name = parts[parts.length - 1];
32293
32346
  const dot = name.lastIndexOf(".");
32294
32347
  const ext = dot < 0 ? "" : name.slice(dot + 1).toLowerCase();
32295
- return isTestFile(path) || name.startsWith(".") || parts.slice(0, -1).includes("bin") || NOT_CODE_FOLDERS.some((f) => path.startsWith(f)) || CONFIG_OR_DATA.has(ext) || IMAGE_FONT_ARCHIVE.has(ext) || MARKDOWN.test(path);
32348
+ return isTestFile$1(path) || name.startsWith(".") || parts.slice(0, -1).includes("bin") || NOT_CODE_FOLDERS.some((f) => path.startsWith(f)) || CONFIG_OR_DATA.has(ext) || IMAGE_FONT_ARCHIVE.has(ext) || MARKDOWN.test(path);
32296
32349
  }
32297
32350
  /** The new files worth a search for a file that names them: `files` without the entry points, sorted and deduplicated. */
32298
32351
  function orphanCandidates(files) {
@@ -34702,7 +34755,7 @@ function mergeHooks(existing, entries) {
34702
34755
  //#region package.json
34703
34756
  var package_default = {
34704
34757
  name: "@accord-dev/accord",
34705
- version: "0.9.0",
34758
+ version: "0.9.1",
34706
34759
  type: "module",
34707
34760
  license: "MIT",
34708
34761
  repository: {
@@ -44063,7 +44116,26 @@ const interesting = (base) => OTHER.has(base) || ESLINT.test(base) || PRETTIER.t
44063
44116
  /** Quoted rule names set to error, warn, 2 or 1, alone or first in an array, in a config's text. */
44064
44117
  const RULE = /["']([@A-Za-z0-9][@A-Za-z0-9/._-]*)["']\s*:\s*(?:["'](?:error|warn)["']|[12]\b|\[\s*(?:["'](?:error|warn)["']|[12]\b))/g;
44065
44118
  const DOTNET_RULE = /dotnet_diagnostic\.([A-Za-z0-9]+)\.severity\s*=\s*(?:warning|error)\b/g;
44066
- const SELECT = /(?:extend-)?select\s*=\s*\[([^\]]*)\]/g;
44119
+ const SELECT_OPEN = /(?:extend-)?select\s*=\s*\[/g;
44120
+ /**
44121
+ * The text between `select = [` (or `extend-select = [`) and the next `]`, for each list in order (U-2). One pass: the search for a closing bracket starts where the previous list ended and stops at
44122
+ * the first list with none, so repeated `select=[` in a hostile file costs time linear in its size, not the square of it (a `[^\]]*` group tried from every start took 20 s on 640 KB).
44123
+ */
44124
+ function selectLists(text) {
44125
+ const lists = [];
44126
+ let from = 0;
44127
+ for (;;) {
44128
+ SELECT_OPEN.lastIndex = from;
44129
+ const open = SELECT_OPEN.exec(text);
44130
+ if (open === null) break;
44131
+ const start = open.index + open[0].length;
44132
+ const close = text.indexOf("]", start);
44133
+ if (close < 0) break;
44134
+ lists.push(text.slice(start, close));
44135
+ from = close + 1;
44136
+ }
44137
+ return lists;
44138
+ }
44067
44139
  function namesIn(text, pattern, group = 1) {
44068
44140
  return [...text.matchAll(pattern)].map((m) => m[group]);
44069
44141
  }
@@ -44144,12 +44216,12 @@ function machineFacts(root, tracked) {
44144
44216
  } else if (base === "ruff.toml" || base === ".ruff.toml") {
44145
44217
  linter("ruff", rel);
44146
44218
  if (/^\[(?:format|lint\.format)\]/m.test(text)) formatter("ruff format", rel);
44147
- for (const list of namesIn(text, SELECT)) keep(namesIn(list, /["']([A-Za-z0-9]+)["']/g));
44219
+ for (const list of selectLists(text)) keep(namesIn(list, /["']([A-Za-z0-9]+)["']/g));
44148
44220
  } else if (base === "pyproject.toml") {
44149
44221
  if (text.includes("[tool.ruff")) {
44150
44222
  linter("ruff", rel);
44151
44223
  if (text.includes("[tool.ruff.format")) formatter("ruff format", rel);
44152
- for (const list of namesIn(text, SELECT)) keep(namesIn(list, /["']([A-Za-z0-9]+)["']/g));
44224
+ for (const list of selectLists(text)) keep(namesIn(list, /["']([A-Za-z0-9]+)["']/g));
44153
44225
  }
44154
44226
  if (text.includes("[tool.pylint")) linter("pylint", rel);
44155
44227
  if (text.includes("[tool.black")) formatter("black", rel);
@@ -44643,7 +44715,7 @@ function commitCheck(ctx, file, cwd) {
44643
44715
  * Run `commits.message.command` in this checkout with the ticket only in the environment (ACCORD_TICKET, ACCORD_TICKET_FILE, ACCORD_BASE_REF, ACCORD_ROOT), write what it printed
44644
44716
  * (the first line the subject, the rest the body, CRLF read as LF) to `<git-path>/accord-commit-<id>.txt`, print `message-file: <path>`, then judge it like `accord commit check`.
44645
44717
  * An untrusted script never runs (exit 2, the refusal names `accord trust`); a non-zero exit, a timeout, too much output or an empty first line is exit 2 quoting the stderr tail
44646
- * and writes no file.
44718
+ * and writes no file. ACCORD_TICKET_FILE is the ticket file's absolute path with forward slashes, as `accord pr` gives it to its script, so one helper reads it in both.
44647
44719
  */
44648
44720
  function commitMessage(ctx, id) {
44649
44721
  if (!ID.test(id)) throw new UsageError("not a valid ticket id: " + id);
@@ -44660,7 +44732,7 @@ function commitMessage(ctx, id) {
44660
44732
  ...process.env,
44661
44733
  ...ctx.env,
44662
44734
  ACCORD_TICKET: id,
44663
- ACCORD_TICKET_FILE: ctx.snapshot.tickets[id].file,
44735
+ ACCORD_TICKET_FILE: resolve(ctx.root, ctx.snapshot.tickets[id].file).replaceAll("\\", "/"),
44664
44736
  ACCORD_BASE_REF: gitDefaultRef(ctx.root) ?? "",
44665
44737
  ACCORD_ROOT: ctx.root
44666
44738
  },
@@ -44908,6 +44980,10 @@ function conventionsWrite(ctx, file, cwd) {
44908
44980
  }
44909
44981
  const wanted = acceptedLines(text, file);
44910
44982
  if (wanted.length === 0) throw new UsageError(`${shown(file)} holds no accepted line - fix: write the lines the owner said yes to, one per line${NOTHING$3}`);
44983
+ const date = utcDate();
44984
+ const subject = renderSubject(ctx.snapshot.config, "conventions", date);
44985
+ const unfit = prTitleProblem(subject);
44986
+ if (unfit !== void 0) throw new UsageError(`${unfit.split(" - fix:")[0]} (commits.subjects.conventions renders ${shown(subject)}) - fix: change commits.subjects.conventions in accord/config.yml to a template without it (accord config set commits.subjects.conventions 'conventions: {id}')${NOTHING$3}`);
44911
44987
  if (!gitOk(root, [
44912
44988
  "remote",
44913
44989
  "get-url",
@@ -44926,7 +45002,6 @@ function conventionsWrite(ctx, file, cwd) {
44926
45002
  if (ref === void 0) throw new UsageError("no origin/main in this clone - run git fetch origin, then try again" + NOTHING$3);
44927
45003
  const short = ref.replace("refs/remotes/origin/", "");
44928
45004
  const base = git$2(root, ["rev-parse", ref]).trim();
44929
- const date = utcDate();
44930
45005
  const branch = "conventions/" + date;
44931
45006
  if (!gitOk(root, [
44932
45007
  "check-ref-format",
@@ -44964,7 +45039,6 @@ function conventionsWrite(ctx, file, cwd) {
44964
45039
  if (added.length === 0) throw new UsageError(`every accepted line is already in ${CONVENTIONS$1} on ${short}${NOTHING$3}`);
44965
45040
  const eol = current.includes("\r\n") ? "\r\n" : "\n";
44966
45041
  const body = (current === "" || /\n$/.test(current) ? current : current + eol) + added.map((l) => l + eol).join("");
44967
- const subject = renderSubject(ctx.snapshot.config, "conventions", date);
44968
45042
  const folder = realpathSync.native(mkdtempSync(join(tmpdir(), "accord-conventions-")));
44969
45043
  const wt = join(folder, "wt");
44970
45044
  let sha;