qfai 2.4.0 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -16
- package/assets/defaults/workflows/apply-settled.yml +2 -0
- package/assets/defaults/workflows/decide-design.yml +1 -6
- package/assets/defaults/workflows/decompose-epic.yml +1 -1
- package/assets/init/.claude/settings.json +1 -1
- package/assets/init/.qfai/assistant/agent/architecture-reviewer.md +1 -0
- package/assets/init/.qfai/assistant/agent/fullstack-engineer.md +6 -9
- package/assets/init/.qfai/assistant/agent/implementation-reviewer.md +9 -1
- package/assets/init/.qfai/assistant/agent/product-surface-reviewer.md +70 -4
- package/assets/init/.qfai/assistant/agent/requirements-reviewer.md +1 -0
- package/assets/init/.qfai/assistant/rule/constitution.md +3 -2
- package/assets/init/.qfai/assistant/rule/drift-protocol.md +5 -5
- package/assets/init/.qfai/assistant/rule/references/deliberation-record-template.md +23 -0
- package/assets/init/.qfai/assistant/rule/references/deliberation-record.md +36 -0
- package/assets/init/.qfai/assistant/rule/references/griller-recommendations.md +3 -3
- package/assets/init/.qfai/assistant/rule/references/launcher-preflight.md +27 -0
- package/assets/init/.qfai/assistant/rule/references/reviewer-findings.md +9 -0
- package/assets/init/.qfai/assistant/rule/references/reviewer-remit.md +23 -15
- package/assets/init/.qfai/assistant/rule/references/visual-reference-survey.md +146 -0
- package/assets/init/.qfai/assistant/rule/references/worker-edit-boundary.md +2 -0
- package/assets/init/.qfai/assistant/rule/research-first-protocol.md +49 -11
- package/assets/init/.qfai/assistant/rule/review-convergence.md +15 -16
- package/assets/init/.qfai/assistant/rule/shared-skill-delegation-baseline.md +3 -0
- package/assets/init/.qfai/assistant/rule/shared-skill-operating-baseline.md +13 -25
- package/assets/init/.qfai/assistant/rule/test-layers.md +8 -0
- package/assets/init/.qfai/assistant/rule/thinking.md +10 -5
- package/assets/init/.qfai/assistant/rule/ui-definition-protocol.md +4 -4
- package/assets/init/.qfai/assistant/rule/ui-procurement.md +50 -10
- package/assets/init/.qfai/assistant/rule/workflow.md +4 -3
- package/assets/init/.qfai/assistant/skill/qfai-configure/SKILL.md +3 -1
- package/assets/init/.qfai/assistant/skill/qfai-discussion/SKILL.md +22 -56
- package/assets/init/.qfai/assistant/skill/qfai-discussion/references/design-dna-intake.md +11 -14
- package/assets/init/.qfai/assistant/skill/qfai-discussion/references/discussion-coverage-checklist.md +1 -1
- package/assets/init/.qfai/assistant/skill/qfai-grilling/SKILL.md +6 -4
- package/assets/init/.qfai/assistant/skill/qfai-grilling/references/discussion-delegation.md +46 -0
- package/assets/init/.qfai/assistant/skill/qfai-grilling/references/glossary-check.md +23 -0
- package/assets/init/.qfai/assistant/skill/qfai-grilling/references/session-check.md +25 -0
- package/assets/init/.qfai/assistant/skill/qfai-implement/SKILL.md +12 -1
- package/assets/init/.qfai/assistant/skill/qfai-implement/references/parallelization-policy.md +2 -3
- package/assets/init/.qfai/assistant/skill/qfai-implement/references/ui-affecting.md +47 -8
- package/assets/init/.qfai/assistant/skill/qfai-maintain/SKILL.md +2 -0
- package/assets/init/.qfai/assistant/skill/qfai-migration-v1-to-v2/SKILL.md +1 -1
- package/assets/init/.qfai/assistant/skill/qfai-prototyping/SKILL.md +6 -2
- package/assets/init/.qfai/assistant/skill/qfai-prototyping/references/generator-prompt.md +6 -9
- package/assets/init/.qfai/assistant/skill/qfai-prototyping/references/reviewer-prompt.md +24 -15
- package/assets/init/.qfai/assistant/skill/qfai-run/SKILL.md +2 -2
- package/assets/init/.qfai/assistant/skill/qfai-run/references/extraction.md +2 -1
- package/assets/init/.qfai/assistant/skill/qfai-run/references/operator-screens.md +7 -3
- package/assets/init/.qfai/assistant/skill/qfai-run/references/stage-points.md +4 -1
- package/assets/init/.qfai/assistant/skill/qfai-sdd/references/business-ui-patterns.md +180 -0
- package/assets/init/.qfai/assistant/skill/qfai-sdd/references/contract-artifact-rules.md +14 -3
- package/assets/init/.qfai/assistant/skill/qfai-sdd/references/design-anti-patterns.md +14 -3
- package/assets/init/.qfai/assistant/skill/qfai-sdd/references/design-md-authoring.md +39 -24
- package/assets/init/.qfai/assistant/skill/qfai-sdd/references/design-md-brand-catalog.md +2 -2
- package/assets/init/.qfai/assistant/skill/qfai-sdd/references/marketing-ui-patterns.md +194 -0
- package/assets/init/.qfai/assistant/skill/qfai-sdd/references/requirements-decomposition.md +27 -3
- package/assets/init/.qfai/assistant/skill/qfai-sdd/references/sdd-execution-playbook.md +29 -22
- package/assets/init/.qfai/assistant/skill/qfai-sdd/references/sdd-phase-checklists.md +3 -3
- package/assets/init/.qfai/assistant/skill/qfai-sdd/references/sdd-pre-draft-grilling.md +4 -4
- package/assets/init/.qfai/assistant/skill/qfai-sdd/references/sdd-quality-gate.md +1 -1
- package/assets/init/.qfai/assistant/skill/qfai-sdd/references/sdd-triage.md +4 -2
- package/assets/init/.qfai/assistant/skill/qfai-sdd/references/spec-traceability-rules.md +6 -6
- package/assets/init/.qfai/assistant/skill/qfai-sdd/references/ui-contract-guide.md +87 -4
- package/assets/init/.qfai/assistant/skill/qfai-sdd/references/ui-design-contract-normalization.md +6 -7
- package/assets/init/.qfai/assistant/skill/qfai-sdd/templates/contracts/api-contract.sample.yaml +3 -0
- package/assets/init/.qfai/assistant/skill/qfai-sdd/templates/contracts/db-contract.sample.sql +3 -0
- package/assets/init/.qfai/assistant/skill/qfai-sdd/templates/contracts/ui-contract.sample.yaml +40 -1
- package/assets/init/.qfai/assistant/skill/qfai-sdd/templates/report/preflight_summary.md +10 -16
- package/assets/init/.qfai/assistant/skill/qfai-sdd/templates/spec/01_policy/constraint.md +10 -0
- package/assets/init/.qfai/assistant/skill/qfai-sdd/templates/spec/01_policy/initiative.md +5 -0
- package/assets/init/.qfai/assistant/skill/qfai-sdd/templates/spec/03_contract/tech.md +1 -0
- package/assets/init/.qfai/assistant/skill/qfai-sdd/templates/spec/decisions.md +8 -2
- package/assets/init/.qfai/assistant/skill/qfai-triage/SKILL.md +4 -0
- package/assets/init/.qfai/assistant/skill/qfai-verify/SKILL.md +4 -2
- package/assets/init/.qfai/assistant/skill/qfai-verify/references/context-load.md +2 -1
- package/assets/init/.qfai/assistant/skill/qfai-verify/references/verify-output-contract.md +4 -1
- package/assets/init/.qfai/assistant/step/common-design-md/STEP.md +11 -8
- package/assets/init/.qfai/assistant/step/common-gate-run/STEP.md +1 -1
- package/assets/init/.qfai/assistant/step/common-grilling-record/STEP.md +25 -60
- package/assets/init/.qfai/assistant/step/common-review-cycle/STEP.md +18 -6
- package/assets/init/.qfai/assistant/step/discussion-interview/STEP.md +45 -95
- package/assets/init/.qfai/assistant/step/discussion-research/STEP.md +11 -13
- package/assets/init/.qfai/assistant/step/implement-diagnose/STEP.md +2 -2
- package/assets/init/.qfai/assistant/step/implement-scaffold/STEP.md +52 -8
- package/assets/init/.qfai/assistant/step/implement-settled-edit/STEP.md +78 -0
- package/assets/init/.qfai/assistant/step/implement-sweep/STEP.md +3 -3
- package/assets/init/.qfai/assistant/step/implement-tdd/STEP.md +20 -2
- package/assets/init/.qfai/assistant/step/prototyping-grill/STEP.md +4 -0
- package/assets/init/.qfai/assistant/step/prototyping-handoff/STEP.md +3 -2
- package/assets/init/.qfai/assistant/step/prototyping-loop/STEP.md +6 -1
- package/assets/init/.qfai/assistant/step/sdd-contract/STEP.md +58 -11
- package/assets/init/.qfai/assistant/step/sdd-flow/STEP.md +41 -27
- package/assets/init/.qfai/assistant/step/sdd-story/STEP.md +2 -1
- package/assets/init/.qfai/assistant/step/sdd-triage/STEP.md +43 -26
- package/assets/init/.qfai/assistant/step/triage-answer/STEP.md +8 -3
- package/assets/init/.qfai/assistant/step/triage-close/STEP.md +12 -6
- package/assets/init/.qfai/assistant/step/triage-decompose/STEP.md +2 -1
- package/assets/init/.qfai/assistant/step/triage-operate/STEP.md +36 -6
- package/assets/init/.qfai/assistant/step/triage-security-intake/STEP.md +2 -0
- package/assets/init/.qfai/assistant/step/verify-commit/STEP.md +3 -1
- package/assets/init/.qfai/assistant/step/verify-context/STEP.md +3 -3
- package/assets/init/.qfai/assistant/step/verify-release-notes/STEP.md +11 -3
- package/assets/init/.qfai/assistant/step/verify-repo-gate/STEP.md +22 -0
- package/assets/init/root/.agents/rules/delegation-steering.md +4 -2
- package/assets/init/root/.agents/rules/distributed-surface.md +1 -1
- package/assets/init/root/.agents/rules/grilling.md +28 -76
- package/assets/init/root/.agents/rules/interface-clarity.md +98 -6
- package/assets/init/root/.gitattributes +7 -5
- package/assets/init/root/.github/workflows/qfai-docs.yml +1 -1
- package/assets/init/root/qfai.config.yaml +1 -1
- package/assets/mdschema/story/01_policy/constraint.mdschema.yml +46 -2
- package/assets/mdschema/story/01_policy/initiative.mdschema.yml +18 -0
- package/assets/mdschema/story/03_contract/tech.mdschema.yml +5 -2
- package/assets/uix-rev/strategy-review.md +1 -1
- package/dist/cli/index.cjs +3787 -7097
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.mjs +3647 -6970
- package/dist/cli/index.mjs.map +1 -1
- package/dist/graph/cli.cjs +966 -222
- package/dist/graph/cli.cjs.map +1 -1
- package/dist/graph/cli.mjs +942 -198
- package/dist/graph/cli.mjs.map +1 -1
- package/dist/graph/hook.cjs +999 -88
- package/dist/graph/hook.cjs.map +1 -1
- package/dist/graph/hook.mjs +996 -85
- package/dist/graph/hook.mjs.map +1 -1
- package/dist/hook/turn-end.cjs +15 -45
- package/dist/hook/turn-end.cjs.map +1 -1
- package/dist/hook/turn-end.mjs +15 -45
- package/dist/hook/turn-end.mjs.map +1 -1
- package/dist/index.cjs +15398 -18327
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +32 -41
- package/dist/index.d.ts +32 -41
- package/dist/index.mjs +19276 -22214
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/assets/init/.qfai/assistant/skill/qfai-discussion/references/discussion-artifact-rules.md +0 -53
- package/assets/init/.qfai/assistant/skill/qfai-discussion/references/discussion-completion-matrix.md +0 -133
- package/assets/init/.qfai/assistant/skill/qfai-discussion/references/example-mapping-guide.md +0 -18
- package/assets/init/.qfai/assistant/skill/qfai-discussion/references/oq-and-deferred-rules.md +0 -84
- package/assets/init/.qfai/assistant/skill/qfai-discussion/references/ui-bearing-playbook.md +0 -95
- package/assets/init/.qfai/assistant/skill/qfai-discussion/references/ui_ux/platform_baselines.md +0 -118
- package/assets/init/.qfai/assistant/skill/qfai-discussion/references/ui_ux/review_audit_playbook.md +0 -115
- package/assets/init/.qfai/assistant/skill/qfai-discussion/references/ui_ux/trend_scan_playbook.md +0 -81
- package/assets/init/.qfai/assistant/skill/qfai-discussion/references/ui_ux_best_practices.md +0 -184
- package/assets/init/.qfai/assistant/skill/qfai-discussion/templates/01_Context.md +0 -143
- package/assets/init/.qfai/assistant/skill/qfai-discussion/templates/03_Story-Workshop.md +0 -104
- package/assets/init/.qfai/assistant/skill/qfai-discussion/templates/04_Sources.md +0 -276
- package/assets/init/.qfai/assistant/skill/qfai-discussion/templates/05_Scope.md +0 -36
- package/assets/init/.qfai/assistant/skill/qfai-discussion/templates/06_REQ.md +0 -26
- package/assets/init/.qfai/assistant/skill/qfai-discussion/templates/07_NFR.md +0 -24
- package/assets/init/.qfai/assistant/skill/qfai-discussion/templates/08_Glossary.md +0 -23
- package/assets/init/.qfai/assistant/skill/qfai-discussion/templates/09_Constraints.md +0 -60
- package/assets/init/.qfai/assistant/skill/qfai-discussion/templates/11_OQ-Register.md +0 -38
- package/assets/init/.qfai/assistant/skill/qfai-discussion/templates/prototyping.yaml +0 -8
- package/assets/init/.qfai/assistant/skill/qfai-discussion/templates/uiux/00_index.md +0 -35
- package/assets/init/.qfai/assistant/skill/qfai-discussion/templates/uiux/40_screen_contracts.md +0 -62
- package/assets/init/.qfai/assistant/skill/qfai-discussion/templates/uiux/50_review_input_bundle.md +0 -38
- package/assets/init/.qfai/assistant/step/discussion-oq/STEP.md +0 -70
- package/assets/init/.qfai/assistant/step/discussion-pack/STEP.md +0 -199
- package/assets/init/.qfai/assistant/step/discussion-uiux/STEP.md +0 -82
- package/assets/uix-rev/contracts-review.md +0 -27
package/dist/hook/turn-end.cjs
CHANGED
|
@@ -57,7 +57,7 @@ var defaultConfig = {
|
|
|
57
57
|
paths: {
|
|
58
58
|
contractsDir: ".qfai/spec/03_contract",
|
|
59
59
|
specsDir: ".qfai/spec",
|
|
60
|
-
|
|
60
|
+
deliberationDir: ".qfai/deliberation",
|
|
61
61
|
outDir: ".qfai/report",
|
|
62
62
|
skillsDir: ".qfai/assistant/skill",
|
|
63
63
|
srcDir: "src",
|
|
@@ -242,10 +242,9 @@ function normalizePaths(raw, configPath, issues) {
|
|
|
242
242
|
issues
|
|
243
243
|
),
|
|
244
244
|
specsDir: readTreeDirString(raw.specsDir, base.specsDir, "paths.specsDir", configPath, issues),
|
|
245
|
-
|
|
246
|
-
raw.
|
|
247
|
-
base.
|
|
248
|
-
"paths.discussionDir",
|
|
245
|
+
deliberationDir: readDeliberationDir(
|
|
246
|
+
raw.deliberationDir,
|
|
247
|
+
base.deliberationDir,
|
|
249
248
|
configPath,
|
|
250
249
|
issues
|
|
251
250
|
),
|
|
@@ -505,6 +504,17 @@ function readDirString(value, fallback, label, configPath, issues) {
|
|
|
505
504
|
function readTreeDirString(value, fallback, label, configPath, issues) {
|
|
506
505
|
return readDirString(value, fallback, label, configPath, issues).replace(/\\/g, "/");
|
|
507
506
|
}
|
|
507
|
+
function readDeliberationDir(value, fallback, configPath, issues) {
|
|
508
|
+
const dir = readTreeDirString(value, fallback, "paths.deliberationDir", configPath, issues);
|
|
509
|
+
if (isDirectoryInsideRoot(import_node_path.default.dirname(configPath), dir)) return dir;
|
|
510
|
+
issues.push(configIssue(configPath, DELIBERATION_DIR_OUTSIDE_ROOT_MESSAGE));
|
|
511
|
+
return fallback;
|
|
512
|
+
}
|
|
513
|
+
var DELIBERATION_DIR_OUTSIDE_ROOT_MESSAGE = "paths.deliberationDir must name a directory inside the project root, not the root itself or a directory outside it, and no part of it may end in a dot or a space.";
|
|
514
|
+
function isDirectoryInsideRoot(root, dir) {
|
|
515
|
+
const relative = import_node_path.default.relative(root, import_node_path.default.resolve(root, dir));
|
|
516
|
+
return !dir.split(/[\\/]/).some((part) => part !== "." && part !== ".." && /[. ]$/.test(part)) && relative !== "" && relative !== ".." && !relative.startsWith(`..${import_node_path.default.sep}`) && !import_node_path.default.isAbsolute(relative);
|
|
517
|
+
}
|
|
508
518
|
function readOptionalString(value, label, configPath, issues) {
|
|
509
519
|
if (value === void 0) {
|
|
510
520
|
return void 0;
|
|
@@ -627,34 +637,6 @@ function normalizeUiux(raw, configPath, issues) {
|
|
|
627
637
|
);
|
|
628
638
|
}
|
|
629
639
|
}
|
|
630
|
-
if (raw.requireResearchSummary !== void 0) {
|
|
631
|
-
if (typeof raw.requireResearchSummary === "boolean") {
|
|
632
|
-
result.requireResearchSummary = raw.requireResearchSummary;
|
|
633
|
-
} else {
|
|
634
|
-
issues.push(configIssue(configPath, "uiux.requireResearchSummary must be a boolean."));
|
|
635
|
-
}
|
|
636
|
-
}
|
|
637
|
-
if (raw.competitive_refs_min !== void 0) {
|
|
638
|
-
if (typeof raw.competitive_refs_min === "number" && Number.isInteger(raw.competitive_refs_min) && raw.competitive_refs_min >= 0) {
|
|
639
|
-
result.competitive_refs_min = raw.competitive_refs_min;
|
|
640
|
-
} else {
|
|
641
|
-
issues.push(
|
|
642
|
-
configIssue(
|
|
643
|
-
configPath,
|
|
644
|
-
"uiux.competitive_refs_min must be an integer greater than or equal to 0."
|
|
645
|
-
)
|
|
646
|
-
);
|
|
647
|
-
}
|
|
648
|
-
}
|
|
649
|
-
if (raw.catalogue_refs_min !== void 0) {
|
|
650
|
-
if (typeof raw.catalogue_refs_min === "number" && Number.isInteger(raw.catalogue_refs_min) && raw.catalogue_refs_min >= 0) {
|
|
651
|
-
result.catalogue_refs_min = raw.catalogue_refs_min;
|
|
652
|
-
} else {
|
|
653
|
-
issues.push(
|
|
654
|
-
configIssue(configPath, "uiux.catalogue_refs_min must be an integer of 0 or more.")
|
|
655
|
-
);
|
|
656
|
-
}
|
|
657
|
-
}
|
|
658
640
|
if (raw.surfacePaths !== void 0) {
|
|
659
641
|
const surfacePaths = raw.surfacePaths;
|
|
660
642
|
if (Array.isArray(surfacePaths) && surfacePaths.every(
|
|
@@ -725,18 +707,6 @@ function normalizeUiuxAudit(raw, configPath, issues) {
|
|
|
725
707
|
issues.push(configIssue(configPath, "uiux.audit.slopDetection must be a boolean."));
|
|
726
708
|
}
|
|
727
709
|
}
|
|
728
|
-
if (raw.maxPrimaryCtas !== void 0) {
|
|
729
|
-
if (typeof raw.maxPrimaryCtas === "number" && Number.isFinite(raw.maxPrimaryCtas) && raw.maxPrimaryCtas >= 0) {
|
|
730
|
-
result.maxPrimaryCtas = raw.maxPrimaryCtas;
|
|
731
|
-
} else {
|
|
732
|
-
issues.push(
|
|
733
|
-
configIssue(
|
|
734
|
-
configPath,
|
|
735
|
-
"uiux.audit.maxPrimaryCtas must be a number greater than or equal to 0."
|
|
736
|
-
)
|
|
737
|
-
);
|
|
738
|
-
}
|
|
739
|
-
}
|
|
740
710
|
if (raw.maxRawTokenLiteralWarnings !== void 0) {
|
|
741
711
|
if (typeof raw.maxRawTokenLiteralWarnings === "number" && Number.isFinite(raw.maxRawTokenLiteralWarnings) && raw.maxRawTokenLiteralWarnings >= 0) {
|
|
742
712
|
result.maxRawTokenLiteralWarnings = raw.maxRawTokenLiteralWarnings;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/cli/turnEndHook.ts","../../src/core/turnEndHook.ts","../../src/core/config.ts","../../src/core/fs/errno.ts","../../src/shared/shippedWorkflowNames.ts"],"sourcesContent":["import { readFileSync } from \"node:fs\";\nimport os from \"node:os\";\n\nimport { runTurnEndHook } from \"../core/turnEndHook.js\";\n\n/**\n * The Stop and SubagentStop hook `qfai init` installs, run by the guard in the host hook file.\n *\n * It never fails the host: every error is swallowed and the hook exits 0 with nothing printed, so\n * a broken install lets the turn end rather than holding it open.\n */\nasync function main(): Promise<void> {\n try {\n let input: unknown;\n try {\n input = JSON.parse(readFileSync(0, \"utf8\"));\n } catch {\n input = undefined;\n }\n const output = await runTurnEndHook(input, {\n processDir: process.cwd(),\n stateDir: os.tmpdir(),\n });\n if (output !== \"\") process.stdout.write(output);\n } catch (error: unknown) {\n // The turn ends as if no check were listed; one line on stderr says why, for the host's log.\n const message = error instanceof Error ? error.message : String(error);\n process.stderr.write(`QFAI turn-end check could not run: ${message}\\n`);\n }\n process.exitCode = 0;\n}\n\n// The entry is loaded by `require` from the guard and has no caller to return to; `main` handles\n// every failure itself, so the promise it returns cannot reject.\nvoid main();\n","import { spawn, spawnSync, type ChildProcess } from \"node:child_process\";\nimport { createHash } from \"node:crypto\";\nimport { readFile, rm, writeFile } from \"node:fs/promises\";\nimport path from \"node:path\";\n\nimport { findConfigRoot, loadConfig, readStopGate, resolvePath } from \"./config.js\";\n\n/** One Standard command the project marks for turn end. */\nexport interface TurnEndCheck {\n readonly label: string;\n readonly command: string;\n}\n\nexport interface TurnEndOptions {\n /** Where the hook process runs; the config search starts here when the event names no `cwd`. */\n readonly processDir: string;\n /** Where the last blocked failure of each session is kept. */\n readonly stateDir: string;\n /** How long one command may run. */\n readonly timeoutMs?: number;\n}\n\nconst DEFAULT_TIMEOUT_MS = 60_000;\nconst TAIL_LINES = 40;\nconst TAIL_CHARS = 4000;\n/** Output kept while a command runs; only the tail is ever reported. */\nconst KEEP_CHARS = 64 * 1024;\n/** How long output is still read after a command exits, for a child that keeps the pipes open. */\nconst EXIT_GRACE_MS = 1000;\n/** Blocks in one continued turn after which the hook lets the turn end whatever the failure. */\nconst MAX_CONTINUED_BLOCKS = 3;\nconst COMMANDS_HEADING = /^##\\s+Standard commands\\b/i;\nconst TURN_END_LABEL = \"turn-end check\";\n\n/**\n * The commands the Standard commands section of a tech.md marks for turn end, in the order its\n * `Turn-end check:` item lists their labels. A label the section does not list is skipped.\n */\nexport function readTurnEndChecks(techText: string): TurnEndCheck[] {\n const commands = new Map<string, string>();\n let marked: string[] = [];\n let inSection = false;\n for (const line of techText.split(/\\r?\\n/)) {\n if (/^#{1,2}\\s/.test(line)) {\n inSection = COMMANDS_HEADING.test(line);\n continue;\n }\n if (!inSection) continue;\n const item = /^\\s*-\\s+([^:`]+):\\s*(.*)$/.exec(line);\n if (item === null) continue;\n const label = (item[1] ?? \"\").trim();\n const rest = item[2] ?? \"\";\n if (label.toLowerCase() === TURN_END_LABEL) {\n marked = rest\n .split(\",\")\n .map((name) => name.replace(/`/g, \"\").trim())\n .filter((name) => name !== \"\");\n continue;\n }\n const command = /`([^`]+)`/.exec(rest)?.[1];\n if (command !== undefined) commands.set(label.toLowerCase(), command);\n }\n const checks: TurnEndCheck[] = [];\n for (const label of marked) {\n const command = commands.get(label.toLowerCase());\n if (command !== undefined) checks.push({ label, command });\n }\n return checks;\n}\n\ninterface CommandResult {\n readonly code: number | null;\n readonly signal: NodeJS.Signals | null;\n /** stdout and stderr in the order they arrived, as shown to the agent. */\n readonly output: string;\n /** stdout, then stderr: the same failure gives the same text whatever the interleaving. */\n readonly ordered: string;\n readonly timedOut: boolean;\n}\n\n/**\n * Stops a command and everything it started. A shell does not pass its own termination on to\n * the program it runs, so the whole tree is stopped: by process group on POSIX, by `taskkill /T`\n * on Windows, falling back to the shell alone where neither works.\n */\nfunction stopTree(child: ChildProcess): void {\n const pid = child.pid;\n if (pid === undefined) return;\n try {\n if (process.platform === \"win32\") {\n const killed = spawnSync(\"taskkill\", [\"/pid\", String(pid), \"/T\", \"/F\"], {\n windowsHide: true,\n });\n if (killed.status !== 0) child.kill(\"SIGKILL\");\n } else {\n process.kill(-pid, \"SIGKILL\");\n }\n } catch {\n child.kill(\"SIGKILL\");\n }\n}\n\nfunction runCommand(command: string, cwd: string, timeoutMs: number): Promise<CommandResult> {\n return new Promise((resolve) => {\n let output = \"\";\n let stdout = \"\";\n let stderr = \"\";\n let settled = false;\n let grace: ReturnType<typeof setTimeout> | undefined;\n const child = spawn(command, {\n cwd,\n shell: true,\n windowsHide: true,\n detached: process.platform !== \"win32\",\n stdio: [\"ignore\", \"pipe\", \"pipe\"],\n });\n const finish = (\n code: number | null,\n signal: NodeJS.Signals | null,\n timedOut: boolean,\n extra = \"\",\n ): void => {\n if (settled) return;\n settled = true;\n clearTimeout(timer);\n clearTimeout(grace);\n child.stdout.destroy();\n child.stderr.destroy();\n resolve({\n code,\n signal,\n output: output + extra,\n ordered: stdout + stderr + extra,\n timedOut,\n });\n };\n child.stdout.setEncoding(\"utf8\");\n child.stderr.setEncoding(\"utf8\");\n child.stdout.on(\"data\", (chunk: string) => {\n output = (output + chunk).slice(-KEEP_CHARS);\n stdout = (stdout + chunk).slice(-KEEP_CHARS);\n });\n child.stderr.on(\"data\", (chunk: string) => {\n output = (output + chunk).slice(-KEEP_CHARS);\n stderr = (stderr + chunk).slice(-KEEP_CHARS);\n });\n const timer = setTimeout(() => {\n stopTree(child);\n finish(null, null, true);\n }, timeoutMs);\n child.on(\"error\", (error) => {\n finish(null, null, false, `${error.message}\\n`);\n });\n // The exit code is settled when the command exits. A program it left running may still hold\n // the pipes, so the output is read a little longer and, on POSIX, what is left of the process\n // group is stopped.\n // SIMPLIFIED: on Windows the tree cannot be reached once the shell has exited: `taskkill /T`\n // needs a live root, and the shell's pid may already be reused. The leftover program keeps\n // running.\n // Lift when: a check is seen leaving a program running on Windows; then hold the tree in a\n // Job Object.\n child.on(\"exit\", (code, signal) => {\n clearTimeout(timer);\n grace = setTimeout(() => {\n if (process.platform !== \"win32\") stopTree(child);\n finish(code, signal, false);\n }, EXIT_GRACE_MS);\n });\n child.on(\"close\", (code, signal) => {\n finish(code, signal, false);\n });\n });\n}\n\n/** How a failed command ended, in words. */\nfunction endingOf(result: CommandResult, timeoutMs: number): string {\n if (result.timedOut) {\n const seconds = Math.max(1, Math.round(timeoutMs / 1000));\n return `did not finish within ${seconds} second${seconds === 1 ? \"\" : \"s\"}`;\n }\n if (result.code !== null) return `ended with exit ${result.code}`;\n return result.signal === null ? \"ended with exit unknown\" : `was stopped by ${result.signal}`;\n}\n\n/** The last lines of a command's output, within both bounds. */\nfunction tail(output: string): string {\n const lines = output.replace(/\\s+$/, \"\").split(/\\r?\\n/);\n return lines.slice(-TAIL_LINES).join(\"\\n\").slice(-TAIL_CHARS);\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction stringField(event: Record<string, unknown>, key: string): string | undefined {\n const value = event[key];\n return typeof value === \"string\" && value !== \"\" ? value : undefined;\n}\n\n/**\n * Whose turn a state file belongs to. A subagent's stop is kept apart from the main agent's even\n * when the host sends no agent id, so a subagent's block never releases the main agent's turn.\n */\nfunction agentKey(event: Record<string, unknown>): string {\n const agent = stringField(event, \"agent_id\");\n if (agent !== undefined) return agent;\n return event.hook_event_name === \"SubagentStop\" ? \"subagent\" : \"main\";\n}\n\nfunction stateFile(stateDir: string, session: string, agent: string): string {\n const name = [\"qfai-turn-end\", session, agent].join(\"-\").replace(/[^\\w.-]/g, \"_\");\n return path.join(stateDir, name);\n}\n\n/** The failure the hook last blocked on for one session and agent, and the blocks in a row. */\ninterface BlockState {\n readonly digest: string;\n readonly blocks: number;\n}\n\nasync function readState(file: string | null): Promise<BlockState | null> {\n if (file === null) return null;\n try {\n const value: unknown = JSON.parse(await readFile(file, \"utf8\"));\n if (!isRecord(value)) return null;\n const { digest, blocks } = value;\n return typeof digest === \"string\" && typeof blocks === \"number\" ? { digest, blocks } : null;\n } catch {\n return null;\n }\n}\n\n/**\n * What the turn-end hook prints for one Stop or SubagentStop event: an empty string to let the\n * turn end silently, or one JSON object that blocks the stop or lets it through with a message.\n */\nexport async function runTurnEndHook(input: unknown, options: TurnEndOptions): Promise<string> {\n const event = isRecord(input) ? input : {};\n const found = await findConfigRoot(stringField(event, \"cwd\") ?? options.processDir);\n if (!found.found) return \"\";\n const loaded = await loadConfig(found.root);\n if (readStopGate(loaded.document) !== true) return \"\";\n let techText: string;\n try {\n techText = await readFile(\n path.join(resolvePath(found.root, loaded.config, \"contractsDir\"), \"tech.md\"),\n \"utf8\",\n );\n } catch (error) {\n // A project without tech.md lists no check; any other read error is reported by the caller.\n if (isRecord(error) && error.code === \"ENOENT\") return \"\";\n throw error;\n }\n const checks = readTurnEndChecks(techText);\n const session = stringField(event, \"session_id\");\n const file = session === undefined ? null : stateFile(options.stateDir, session, agentKey(event));\n const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;\n\n for (const check of checks) {\n const result = await runCommand(check.command, found.root, timeoutMs);\n if (!result.timedOut && result.code === 0) continue;\n const shown = tail(result.output);\n const ending = endingOf(result, timeoutMs);\n const digest = createHash(\"sha256\")\n .update([check.label, ending, tail(result.ordered)].join(\"\\n\").replace(/\\d+/g, \"#\"))\n .digest(\"hex\");\n const continued = event.stop_hook_active === true;\n const last = await readState(file);\n const blocks = continued && last !== null ? last.blocks + 1 : 1;\n const release =\n file === null\n ? continued\n : continued && (last?.digest === digest || blocks > MAX_CONTINUED_BLOCKS);\n if (release) {\n if (file !== null) await rm(file, { force: true });\n return `${JSON.stringify({\n systemMessage: `QFAI turn-end check: ${check.label} still fails, and the turn ended anyway. Run ${check.command} in ${found.root} to see the failure.`,\n })}\\n`;\n }\n if (file !== null) await writeFile(file, JSON.stringify({ digest, blocks }), \"utf8\");\n const reason = [\n `The turn-end check ${check.label} failed: ${check.command} ${ending}.`,\n shown === \"\" ? \"It printed nothing.\" : `End of its output:\\n${shown}`,\n event.hook_event_name === \"SubagentStop\"\n ? \"Fix the cause before ending the turn. If fixing it is outside your task, say so in your reply and end the turn. The check is listed under Turn-end check in tech.md.\"\n : \"Fix the cause before ending the turn. The check is listed under Turn-end check in tech.md.\",\n ].join(\"\\n\\n\");\n return `${JSON.stringify({ decision: \"block\", reason })}\\n`;\n }\n if (file !== null) await rm(file, { force: true });\n return \"\";\n}\n","import { access, readFile } from \"node:fs/promises\";\nimport path from \"node:path\";\n\nimport { parse as parseYaml } from \"yaml\";\n\nimport type { Issue } from \"./types.js\";\nimport { isEnoent } from \"./fs/errno.js\";\nimport { SHIPPED_WORKFLOW_NAMES } from \"../shared/shippedWorkflowNames.js\";\n\nexport type FailOn = \"never\" | \"warning\" | \"error\";\nexport type OutputFormat = \"text\" | \"github\";\n\nexport type QfaiPaths = {\n contractsDir: string;\n specsDir: string;\n discussionDir: string;\n outDir: string;\n skillsDir: string;\n srcDir: string;\n testsDir: string;\n /**\n * Where the project's migrations live, if it has any.\n *\n * Optional and unset by default, because qfai cannot guess it and a project\n * without migrations is not in violation of anything. `qfai db-drift` is the\n * only reader: with no value it says the project is out of scope and stops,\n * rather than comparing the contracts against an empty directory and calling\n * every column a difference.\n */\n migrationsDir?: string;\n};\n\nexport type QfaiForbiddenIdentifier = {\n sha256: string;\n byteLength: number;\n};\n\nexport type DiagramBudget = { nodes: number; edges: number };\n\nexport const DEFAULT_DIAGRAM_BUDGET: DiagramBudget = { nodes: 12, edges: 16 };\n\nexport type QfaiValidationConfig = {\n failOn: FailOn;\n /**\n * Terms the specs must no longer state, such as an option a decision rejected.\n * `qfai validate` warns on each line of a spec document that still holds one\n * (QFAI-STORY-016). Unset means no term is checked.\n */\n staleTerms?: string[];\n /**\n * The largest node and edge counts a Mermaid diagram may have before\n * `qfai validate` warns (QFAI-FLOW-006). A limit left unset is the default\n * of `DEFAULT_DIAGRAM_BUDGET`.\n */\n diagramBudget?: Partial<DiagramBudget>;\n /** Hash-only identifiers checked against tracked names and current file bytes. */\n forbiddenIdentifiers?: QfaiForbiddenIdentifier[];\n testStrategy: {\n /**\n * When true (default), `qfai validate` reports the silent-placeholder\n * construct of each supported stack in test files (QFAI-TEST-001). On\n * JS/TS that is `it.todo` / `test.todo` / `describe.todo` (error) and\n * `it.skip` / `test.skip` / `describe.skip` (warning).\n * Set to false to opt out while migrating an existing project.\n */\n forbidTestTodoStubs: boolean;\n };\n traceability: {\n testFileGlobs: string[];\n testFileExcludeGlobs: string[];\n };\n};\n\nexport type QfaiOutputConfig = {\n validateJsonPath: string;\n};\n\nexport type QfaiUiuxAuditConfig = {\n enabled?: boolean;\n slopDetection?: boolean;\n maxPrimaryCtas?: number;\n maxRawTokenLiteralWarnings?: number;\n maxDuplicateFindingsPerRule?: number;\n};\n\nexport type QfaiUiuxConfig = {\n platform?: string;\n /**\n * Component registries the project can procure from, as name to URL\n * template. The shape mirrors the `registries` map a `components.json`\n * already carries, so a project that has one restates it rather than\n * translating it.\n *\n * Which registry is primary is named by the `Component catalogue` row of the\n * Stack table in `.qfai/spec/03_contract/tech.md`. Nothing here ranks them.\n */\n registries?: Record<string, string>;\n designTokensDir?: string;\n htmlMockTimeout?: number;\n qualityProfile?: \"strict\" | \"high\" | \"default\";\n requireResearchSummary?: boolean;\n competitive_refs_min?: number;\n /**\n * Minimum complete component-catalogue references a UI-bearing pack must\n * register. Absent means the count is not gated; entries that are\n * registered are still held to the same three fields.\n */\n catalogue_refs_min?: number;\n /**\n * Repository-relative POSIX globs of the paths that render a user-visible\n * surface. An empty list states that the project renders none; an absent\n * key declares nothing.\n */\n surfacePaths?: string[];\n audit?: QfaiUiuxAuditConfig;\n};\n\nexport type QfaiPrototypingExecutionConfig = {\n targetUrl?: string | null;\n /**\n * Browser tool handed to the AI evaluator sub-agent. Only `\"playwright\"` is\n * accepted.\n */\n browserTool: \"playwright\";\n};\n\nexport type QfaiPrototypingConfig = {\n execution?: QfaiPrototypingExecutionConfig;\n /**\n * Explicit primary UI contract for `/qfai-prototyping`.\n * Uses the full `UI-NNNN` identifier.\n */\n primaryUiContract?: string;\n};\n\nexport type QfaiReportConfig = {\n /**\n * Stale run-log TTL (calendar days) used by `qfai doctor --clean` to\n * decide whether a `<paths.outDir>/run-*` directory may be pruned.\n * `0` opts out entirely (never prune). Default (when unset) is applied\n * at the call-site by `RUN_LOG_STALE_TTL_DAYS_DEFAULT`.\n */\n staleTtlDays?: number;\n /**\n * Number of newest `run-*` directories retained regardless of age, so\n * `validate.log`'s `run_log:` pointer can never be pruned away.\n * Default (when unset) is applied at the call-site by\n * `RUN_LOG_KEEP_LATEST_DEFAULT`; `0` is clamped up to\n * `RUN_LOG_KEEP_LATEST_MIN` (1) there, because keeping nothing would\n * strand that pointer. Use `staleTtlDays: 0` to keep every run.\n */\n keepLatestRuns?: number;\n};\n\nexport type QfaiConfig = {\n paths: QfaiPaths;\n validation: QfaiValidationConfig;\n output: QfaiOutputConfig;\n uiux?: QfaiUiuxConfig;\n prototyping?: QfaiPrototypingConfig;\n report?: QfaiReportConfig;\n baseBranch?: string;\n};\n\n/**\n * The path keys `resolvePath` can resolve: the ones every config has.\n *\n * An optional key is excluded by its type rather than by a list, so a path\n * added later joins or stays out on its own. `resolvePath` returns a string,\n * and there is no directory to return for a key the project did not set — its\n * reader has to decide what absence means, which is not something a resolver\n * can do for it.\n */\nexport type ConfigPathKey = {\n [K in keyof QfaiPaths]-?: undefined extends QfaiPaths[K] ? never : K;\n}[keyof QfaiPaths];\n\nexport type ConfigLoadResult = {\n config: QfaiConfig;\n issues: Issue[];\n configPath: string;\n /**\n * The parsed YAML document, before normalization. `undefined` when the\n * file is absent (`issues` empty) or could not be read / parsed at all\n * (`issues` non-empty) — the two cases a caller distinguishes by the\n * issue list.\n *\n * `issues` records *that* something was rejected but not *which* key,\n * so it cannot answer \"was the value I depend on honoured, or silently\n * replaced by its default?\". Normalization is per-key and independent,\n * so an unrelated rejection (a bad `baseBranch`, say) says nothing\n * about `paths.discussionDir`. A caller whose correctness hinges on one\n * key reads it here and checks that key alone, rather than treating any\n * issue anywhere in the file as a reason to distrust the whole config.\n */\n document?: unknown;\n};\n\nexport type ConfigSearchResult = {\n root: string;\n configPath: string;\n found: boolean;\n};\n\nexport const defaultConfig: QfaiConfig = {\n paths: {\n contractsDir: \".qfai/spec/03_contract\",\n specsDir: \".qfai/spec\",\n discussionDir: \".qfai/discussion\",\n outDir: \".qfai/report\",\n skillsDir: \".qfai/assistant/skill\",\n srcDir: \"src\",\n testsDir: \"tests\",\n },\n validation: {\n failOn: \"error\",\n testStrategy: {\n forbidTestTodoStubs: true,\n },\n traceability: {\n testFileGlobs: [],\n testFileExcludeGlobs: [],\n },\n },\n output: {\n validateJsonPath: \".qfai/report/validate.json\",\n },\n prototyping: {\n execution: {\n targetUrl: null,\n browserTool: \"playwright\",\n },\n },\n};\n\nexport function getConfigPath(root: string): string {\n return path.join(root, \"qfai.config.yaml\");\n}\n\nexport async function findConfigRoot(startDir: string): Promise<ConfigSearchResult> {\n const resolvedStart = path.resolve(startDir);\n let current = resolvedStart;\n\n for (;;) {\n const configPath = getConfigPath(current);\n if (await exists(configPath)) {\n return { root: current, configPath, found: true };\n }\n const parent = path.dirname(current);\n if (parent === current) {\n break;\n }\n current = parent;\n }\n\n return {\n root: resolvedStart,\n configPath: getConfigPath(resolvedStart),\n found: false,\n };\n}\n\nexport async function loadConfig(root: string): Promise<ConfigLoadResult> {\n const configPath = getConfigPath(root);\n const issues: Issue[] = [];\n\n let parsed: unknown;\n try {\n const raw = await readFile(configPath, \"utf-8\");\n parsed = parseYaml(raw);\n } catch (error) {\n if (isEnoent(error)) {\n return { config: defaultConfig, issues, configPath };\n }\n issues.push(configIssue(configPath, \"The configuration file could not be read or parsed.\"));\n return { config: defaultConfig, issues, configPath };\n }\n\n const normalized = normalizeConfig(parsed, configPath, issues);\n if (readWorkflowMode(parsed) === null) {\n issues.push(configIssue(configPath, WORKFLOW_MODE_MESSAGE));\n }\n if (readSkippedWorkflows(parsed) === null) {\n issues.push(configIssue(configPath, SKIPPED_WORKFLOWS_MESSAGE));\n }\n if (readAcceptedDrift(parsed) === null) {\n issues.push(configIssue(configPath, ACCEPTED_DRIFT_MESSAGE));\n }\n if (readStopGate(parsed) === null) {\n issues.push(configIssue(configPath, STOP_GATE_MESSAGE));\n }\n return { config: normalized, issues, configPath, document: parsed };\n}\n\n/** The config issue an invalid `workflow.stopGate` raises. */\nexport const STOP_GATE_MESSAGE =\n \"workflow.stopGate must be true or false; an absent key means true.\";\n\n/**\n * Whether the turn-end hook runs the project's turn-end checks, read from the parsed config\n * document. `null` means the value is not a boolean, which the hook treats as `false`.\n */\nexport function readStopGate(document: unknown): boolean | null {\n const workflow = isRecord(document) ? document.workflow : undefined;\n if (workflow === undefined) return true;\n if (!isRecord(workflow)) return null;\n if (workflow.stopGate === undefined) return true;\n return typeof workflow.stopGate === \"boolean\" ? workflow.stopGate : null;\n}\n\nconst WORKFLOW_MODES = [\"active\", \"shadow\", \"off\"] as const;\n\n/** The config issue an invalid `workflow.mode` raises. */\nexport const WORKFLOW_MODE_MESSAGE =\n \"workflow.mode must be active, shadow or off; an absent key means active.\";\n\nexport type WorkflowMode = (typeof WORKFLOW_MODES)[number];\n\n/**\n * The workflow mode in force, read from the parsed config document. `null` means the value is\n * none of the three, and no mode is guessed in its place.\n */\nexport function readWorkflowMode(document: unknown): WorkflowMode | null {\n const workflow = isRecord(document) ? document.workflow : undefined;\n if (workflow === undefined) return \"active\";\n if (!isRecord(workflow)) return null;\n const mode = workflow.mode;\n if (mode === undefined) return \"active\";\n return WORKFLOW_MODES.find((known) => known === mode) ?? null;\n}\n\n/** The config issue an invalid `workflow.skipShipped` raises. */\nexport const SKIPPED_WORKFLOWS_MESSAGE = `workflow.skipShipped must be a list of shipped workflow file names (${[...SHIPPED_WORKFLOW_NAMES].join(\", \")}); an absent key means none are skipped.`;\n\n/**\n * The shipped workflow names `workflow.skipShipped` lists, read from the parsed config document.\n * `null` means the value is not a list of shipped names, and no entry is guessed in its place.\n */\nexport function readSkippedWorkflows(document: unknown): ReadonlySet<string> | null {\n const workflow = isRecord(document) ? document.workflow : undefined;\n if (!isRecord(workflow) || workflow.skipShipped === undefined) return new Set();\n const listed = workflow.skipShipped;\n if (!Array.isArray(listed)) return null;\n const names = new Set<string>();\n for (const name of listed) {\n if (typeof name !== \"string\" || !SHIPPED_WORKFLOW_NAMES.has(name)) return null;\n names.add(name);\n }\n return names;\n}\n\n/** The config issue an invalid `workflow.acceptedDrift` raises. */\nexport const ACCEPTED_DRIFT_MESSAGE = `workflow.acceptedDrift must be a list of entries, each with a file, one of the shipped workflow file names (${[...SHIPPED_WORKFLOW_NAMES].join(\", \")}) listed once, the digest qfai doctor prints for it (sha256: and 64 lowercase hexadecimal characters), and a reason that is not empty; an absent key means no difference is accepted.`;\n\n/** One `workflow.acceptedDrift` entry: the digest of the accepted text and why it is kept. */\nexport type AcceptedDrift = { readonly digest: string; readonly reason: string };\n\nconst DRIFT_DIGEST = /^sha256:[0-9a-f]{64}$/;\n\n/**\n * The shipped workflows `workflow.acceptedDrift` accepts as differing from the shipped text, each\n * with the digest of the accepted text and its trimmed reason, read from the parsed config\n * document. `null` means the value is not a list of such entries, and no entry is accepted in its\n * place.\n */\nexport function readAcceptedDrift(document: unknown): ReadonlyMap<string, AcceptedDrift> | null {\n const workflow = isRecord(document) ? document.workflow : undefined;\n if (!isRecord(workflow) || workflow.acceptedDrift === undefined) return new Map();\n const listed = workflow.acceptedDrift;\n if (!Array.isArray(listed)) return null;\n const accepted = new Map<string, AcceptedDrift>();\n for (const entry of listed) {\n if (!isRecord(entry)) return null;\n const { file, digest, reason } = entry;\n if (typeof file !== \"string\" || !SHIPPED_WORKFLOW_NAMES.has(file) || accepted.has(file)) {\n return null;\n }\n if (typeof digest !== \"string\" || !DRIFT_DIGEST.test(digest)) return null;\n if (typeof reason !== \"string\" || reason.trim() === \"\") return null;\n accepted.set(file, { digest, reason: reason.trim() });\n }\n return accepted;\n}\n\nexport function resolvePath(root: string, config: QfaiConfig, key: ConfigPathKey): string {\n return path.resolve(root, config.paths[key]);\n}\n\nfunction normalizeConfig(raw: unknown, configPath: string, issues: Issue[]): QfaiConfig {\n if (!isRecord(raw)) {\n issues.push(configIssue(configPath, \"The configuration file format is invalid.\"));\n return defaultConfig;\n }\n\n const uiux = normalizeUiux(raw.uiux, configPath, issues);\n const prototyping = normalizePrototyping(raw.prototyping, configPath, issues);\n const report = normalizeReport(raw.report, configPath, issues);\n const base: QfaiConfig = {\n paths: normalizePaths(raw.paths, configPath, issues),\n validation: normalizeValidation(raw.validation, configPath, issues),\n output: normalizeOutput(raw.output, configPath, issues),\n };\n if (uiux) {\n base.uiux = uiux;\n }\n if (prototyping) {\n base.prototyping = prototyping;\n }\n if (report) {\n base.report = report;\n }\n const baseBranch = readOptionalString(raw.baseBranch, \"baseBranch\", configPath, issues);\n if (baseBranch !== undefined) {\n base.baseBranch = baseBranch;\n }\n return base;\n}\n\nfunction normalizePaths(raw: unknown, configPath: string, issues: Issue[]): QfaiPaths {\n const base = defaultConfig.paths;\n if (!raw) {\n return base;\n }\n if (!isRecord(raw)) {\n issues.push(configIssue(configPath, \"paths must be an object.\"));\n return base;\n }\n\n const migrationsDir = readOptionalString(\n raw.migrationsDir,\n \"paths.migrationsDir\",\n configPath,\n issues,\n );\n\n return {\n ...(migrationsDir !== undefined ? { migrationsDir } : {}),\n contractsDir: readTreeDirString(\n raw.contractsDir,\n base.contractsDir,\n \"paths.contractsDir\",\n configPath,\n issues,\n ),\n specsDir: readTreeDirString(raw.specsDir, base.specsDir, \"paths.specsDir\", configPath, issues),\n discussionDir: readDirString(\n raw.discussionDir,\n base.discussionDir,\n \"paths.discussionDir\",\n configPath,\n issues,\n ),\n outDir: readDirString(raw.outDir, base.outDir, \"paths.outDir\", configPath, issues),\n skillsDir: readDirString(raw.skillsDir, base.skillsDir, \"paths.skillsDir\", configPath, issues),\n srcDir: readDirString(raw.srcDir, base.srcDir, \"paths.srcDir\", configPath, issues),\n testsDir: readDirString(raw.testsDir, base.testsDir, \"paths.testsDir\", configPath, issues),\n };\n}\n\nfunction normalizeValidation(\n raw: unknown,\n configPath: string,\n issues: Issue[],\n): QfaiValidationConfig {\n const base = defaultConfig.validation;\n if (!raw) {\n return base;\n }\n if (!isRecord(raw)) {\n issues.push(configIssue(configPath, \"validation must be an object.\"));\n return base;\n }\n\n let traceabilityRaw: Record<string, unknown> | undefined;\n if (raw.traceability === undefined) {\n traceabilityRaw = undefined;\n } else if (isRecord(raw.traceability)) {\n traceabilityRaw = raw.traceability;\n } else {\n issues.push(configIssue(configPath, \"validation.traceability must be an object.\"));\n traceabilityRaw = undefined;\n }\n\n let testStrategyRaw: Record<string, unknown> | undefined;\n if (raw.testStrategy === undefined) {\n testStrategyRaw = undefined;\n } else if (isRecord(raw.testStrategy)) {\n testStrategyRaw = raw.testStrategy;\n } else {\n issues.push(configIssue(configPath, \"validation.testStrategy must be an object.\"));\n testStrategyRaw = undefined;\n }\n\n reportRetiredTraceabilityKeys(traceabilityRaw, configPath, issues);\n\n const forbiddenIdentifiers = normalizeForbiddenIdentifiers(\n raw.forbiddenIdentifiers,\n configPath,\n issues,\n );\n\n const staleTerms = readStringArray(\n raw.staleTerms,\n [],\n \"validation.staleTerms\",\n configPath,\n issues,\n );\n\n const diagramBudget = readDiagramBudget(raw.diagramBudget, configPath, issues);\n\n return {\n failOn: readFailOn(raw.failOn, base.failOn, \"validation.failOn\", configPath, issues),\n ...(staleTerms.length > 0 ? { staleTerms } : {}),\n ...(diagramBudget !== undefined ? { diagramBudget } : {}),\n ...(forbiddenIdentifiers !== undefined ? { forbiddenIdentifiers } : {}),\n testStrategy: {\n forbidTestTodoStubs: readBoolean(\n testStrategyRaw?.forbidTestTodoStubs,\n base.testStrategy.forbidTestTodoStubs,\n \"validation.testStrategy.forbidTestTodoStubs\",\n configPath,\n issues,\n ),\n },\n traceability: {\n testFileGlobs: readStringArray(\n traceabilityRaw?.testFileGlobs,\n base.traceability.testFileGlobs,\n \"validation.traceability.testFileGlobs\",\n configPath,\n issues,\n ),\n testFileExcludeGlobs: readStringArray(\n traceabilityRaw?.testFileExcludeGlobs,\n base.traceability.testFileExcludeGlobs,\n \"validation.traceability.testFileExcludeGlobs\",\n configPath,\n issues,\n ),\n },\n };\n}\n\nfunction normalizeForbiddenIdentifiers(\n raw: unknown,\n configPath: string,\n issues: Issue[],\n): QfaiForbiddenIdentifier[] | undefined {\n if (raw === undefined) return undefined;\n const invalid = (): undefined => {\n issues.push(configIssue(configPath, \"validation.forbiddenIdentifiers is invalid.\"));\n return undefined;\n };\n if (!Array.isArray(raw) || raw.length > 64) {\n invalid();\n return undefined;\n }\n\n const entries: QfaiForbiddenIdentifier[] = [];\n const pairs = new Set<string>();\n const lengths = new Set<number>();\n for (const entry of raw) {\n if (\n !isRecord(entry) ||\n Object.keys(entry).length !== 2 ||\n Object.keys(entry).some((key) => key !== \"sha256\" && key !== \"byteLength\") ||\n typeof entry.sha256 !== \"string\" ||\n !/^[0-9a-f]{64}$/.test(entry.sha256) ||\n typeof entry.byteLength !== \"number\" ||\n !Number.isInteger(entry.byteLength) ||\n entry.byteLength < 1 ||\n entry.byteLength > 128\n ) {\n invalid();\n return undefined;\n }\n const pair = `${entry.sha256}:${entry.byteLength}`;\n if (pairs.has(pair)) {\n invalid();\n return undefined;\n }\n pairs.add(pair);\n lengths.add(entry.byteLength);\n if (lengths.size > 8) {\n invalid();\n return undefined;\n }\n entries.push({ sha256: entry.sha256, byteLength: entry.byteLength });\n }\n return entries;\n}\n\nfunction normalizeOutput(raw: unknown, configPath: string, issues: Issue[]): QfaiOutputConfig {\n const base = defaultConfig.output;\n if (!raw) {\n return base;\n }\n if (!isRecord(raw)) {\n issues.push(configIssue(configPath, \"output must be an object.\"));\n return base;\n }\n\n return {\n validateJsonPath: readString(\n raw.validateJsonPath,\n base.validateJsonPath,\n \"output.validateJsonPath\",\n configPath,\n issues,\n ),\n };\n}\n\nfunction normalizePrototyping(\n raw: unknown,\n configPath: string,\n issues: Issue[],\n): QfaiPrototypingConfig | undefined {\n if (raw === undefined || raw === null) {\n return undefined;\n }\n if (!isRecord(raw)) {\n issues.push(configIssue(configPath, \"prototyping must be an object.\"));\n return undefined;\n }\n\n const execution = normalizePrototypingExecution(raw.execution, configPath, issues);\n if (Object.prototype.hasOwnProperty.call(raw, \"primarySpecId\")) {\n issues.push(\n configIssue(\n configPath,\n \"prototyping.primarySpecId is retired; use prototyping.primaryUiContract: UI-NNNN.\",\n ),\n );\n }\n const primaryUiContract = normalizePrimaryUiContract(raw.primaryUiContract, configPath, issues);\n if (!execution && primaryUiContract === undefined) {\n return undefined;\n }\n return {\n ...(execution ? { execution } : {}),\n ...(primaryUiContract !== undefined ? { primaryUiContract } : {}),\n };\n}\n\nfunction normalizePrimaryUiContract(\n raw: unknown,\n configPath: string,\n issues: Issue[],\n): string | undefined {\n if (raw === undefined || raw === null) {\n return undefined;\n }\n if (typeof raw !== \"string\" || !/^UI-\\d{4}$/.test(raw)) {\n issues.push(configIssue(configPath, primaryUiContractMessage(raw)));\n return undefined;\n }\n return raw;\n}\n\nfunction primaryUiContractMessage(raw: unknown): string {\n return `prototyping.primaryUiContract must be a full UI-NNNN ID; received ${JSON.stringify(raw)}.`;\n}\n\n/**\n * Why the file's `prototyping.primaryUiContract` was rejected, or `undefined` when the file sets\n * none or the value was accepted. A command that selects the primary UI contract refuses on it,\n * because the loaded config would otherwise fall back to the first UI contract.\n */\nexport function readRejectedPrimaryUiContract(loaded: ConfigLoadResult): string | undefined {\n const prototyping = isRecord(loaded.document) ? loaded.document.prototyping : undefined;\n const raw = isRecord(prototyping) ? prototyping.primaryUiContract : undefined;\n if (raw === undefined || raw === null) return undefined;\n if (loaded.config.prototyping?.primaryUiContract !== undefined) return undefined;\n return primaryUiContractMessage(raw);\n}\n\nfunction normalizePrototypingExecution(\n raw: unknown,\n configPath: string,\n issues: Issue[],\n): NonNullable<QfaiPrototypingConfig[\"execution\"]> | undefined {\n const base = defaultConfig.prototyping?.execution;\n if (raw === undefined || raw === null) {\n return base ? { ...base } : undefined;\n }\n if (!isRecord(raw)) {\n issues.push(configIssue(configPath, \"prototyping.execution must be an object.\"));\n return base ? { ...base } : undefined;\n }\n\n const browserToolRaw = raw.browserTool;\n const browserTool = \"playwright\";\n if (browserToolRaw !== undefined && browserToolRaw !== browserTool) {\n // `browserTool` keeps its `playwright` default, so a run that ignores the\n // issue proceeds against the supported launcher.\n issues.push(\n configIssue(\n configPath,\n `prototyping.execution.browserTool must be \"playwright\".` +\n ` Received: ${JSON.stringify(browserToolRaw)}`,\n ),\n );\n }\n\n return {\n targetUrl:\n raw.targetUrl === null\n ? null\n : (readOptionalString(\n raw.targetUrl,\n \"prototyping.execution.targetUrl\",\n configPath,\n issues,\n ) ?? null),\n browserTool,\n };\n}\n\nfunction readNonNegativeInteger(\n raw: unknown,\n field: string,\n configPath: string,\n issues: Issue[],\n): number | undefined {\n if (typeof raw === \"number\" && Number.isFinite(raw) && Number.isInteger(raw) && raw >= 0) {\n return raw;\n }\n issues.push(configIssue(configPath, `${field} must be an integer greater than or equal to 0.`));\n return undefined;\n}\n\nfunction normalizeReport(\n raw: unknown,\n configPath: string,\n issues: Issue[],\n): QfaiReportConfig | undefined {\n if (raw === undefined || raw === null) {\n return undefined;\n }\n if (!isRecord(raw)) {\n issues.push(configIssue(configPath, \"report must be an object.\"));\n return undefined;\n }\n const result: QfaiReportConfig = {};\n if (raw.staleTtlDays !== undefined) {\n const value = readNonNegativeInteger(\n raw.staleTtlDays,\n \"report.staleTtlDays\",\n configPath,\n issues,\n );\n if (value !== undefined) {\n result.staleTtlDays = value;\n }\n }\n if (raw.keepLatestRuns !== undefined) {\n const value = readNonNegativeInteger(\n raw.keepLatestRuns,\n \"report.keepLatestRuns\",\n configPath,\n issues,\n );\n if (value !== undefined) {\n result.keepLatestRuns = value;\n }\n }\n return Object.keys(result).length === 0 ? undefined : result;\n}\n\nfunction readString(\n value: unknown,\n fallback: string,\n label: string,\n configPath: string,\n issues: Issue[],\n): string {\n if (typeof value === \"string\" && value.trim().length > 0) {\n return value;\n }\n if (value !== undefined) {\n issues.push(configIssue(configPath, `${label} must be a string.`));\n }\n return fallback;\n}\n\n/**\n * A configured directory, with any trailing separators removed.\n *\n * Readers use these values two ways: joined with a child path, where a trailing\n * separator is harmless, and tested as a prefix, where it is not. `\".qfai/spec/\"`\n * builds the prefix `\".qfai/spec//\"`, which no repository path starts with, so a\n * gate keyed on it selects nothing and reports a pass over an empty set. Settling\n * the spelling here is what stops one reader from working on a value another\n * silently drops.\n *\n * A value that is only separators keeps what was written: trimming it to the\n * empty string would silently retarget the reader at the repository root.\n */\nfunction readDirString(\n value: unknown,\n fallback: string,\n label: string,\n configPath: string,\n issues: Issue[],\n): string {\n const raw = readString(value, fallback, label, configPath, issues);\n const trimmed = raw.replace(/[\\\\/]+$/, \"\");\n return trimmed.length > 0 ? trimmed : raw;\n}\n\n/**\n * A story-tree root, with every backslash read as `/` on every platform.\n *\n * The shipped document-schema checker reads these two keys itself, without\n * loading the configuration module, and takes a backslash as a separator. Folding here as well keeps\n * `qfai validate` and that checker on one directory for one value: on Linux and\n * macOS the platform's own path rules would otherwise read `.qfai\\spec` as a\n * single directory name.\n */\nfunction readTreeDirString(\n value: unknown,\n fallback: string,\n label: string,\n configPath: string,\n issues: Issue[],\n): string {\n return readDirString(value, fallback, label, configPath, issues).replace(/\\\\/g, \"/\");\n}\n\nfunction readOptionalString(\n value: unknown,\n label: string,\n configPath: string,\n issues: Issue[],\n): string | undefined {\n if (value === undefined) {\n return undefined;\n }\n if (typeof value === \"string\" && value.trim().length > 0) {\n return value;\n }\n issues.push(configIssue(configPath, `${label} must be a non-empty string.`));\n return undefined;\n}\n\nfunction readStringArray(\n value: unknown,\n fallback: string[],\n label: string,\n configPath: string,\n issues: Issue[],\n): string[] {\n if (Array.isArray(value) && value.every((item) => typeof item === \"string\")) {\n return value;\n }\n if (value !== undefined) {\n issues.push(configIssue(configPath, `${label} must be an array of strings.`));\n }\n return fallback;\n}\n\nfunction readDiagramBudget(\n value: unknown,\n configPath: string,\n issues: Issue[],\n): Partial<DiagramBudget> | undefined {\n if (value === undefined) {\n return undefined;\n }\n if (!isRecord(value)) {\n issues.push(configIssue(configPath, \"validation.diagramBudget must be an object.\"));\n return undefined;\n }\n for (const key of Object.keys(value)) {\n if (key !== \"nodes\" && key !== \"edges\") {\n issues.push(configIssue(configPath, `validation.diagramBudget.${key} is not a setting.`));\n }\n }\n const budget: Partial<DiagramBudget> = {};\n for (const key of [\"nodes\", \"edges\"] as const) {\n const limit = value[key];\n if (limit === undefined) {\n continue;\n }\n if (typeof limit === \"number\" && Number.isInteger(limit) && limit >= 1) {\n budget[key] = limit;\n } else {\n issues.push(\n configIssue(configPath, `validation.diagramBudget.${key} must be an integer of 1 or more.`),\n );\n }\n }\n return budget;\n}\n\nfunction readBoolean(\n value: unknown,\n fallback: boolean,\n label: string,\n configPath: string,\n issues: Issue[],\n): boolean {\n if (typeof value === \"boolean\") {\n return value;\n }\n if (value !== undefined) {\n issues.push(configIssue(configPath, `${label} must be a boolean.`));\n }\n return fallback;\n}\n\nfunction readFailOn(\n value: unknown,\n fallback: FailOn,\n label: string,\n configPath: string,\n issues: Issue[],\n): FailOn {\n if (value === \"never\" || value === \"warning\" || value === \"error\") {\n return value;\n }\n if (value !== undefined) {\n issues.push(configIssue(configPath, `${label} must be one of never|warning|error.`));\n }\n return fallback;\n}\n\n/**\n * `validation.traceability` keys no validator reads. The migration from the\n * spec-pack layout recognises the finding for each one that is still present,\n * and `QFAI-CFG-001` reports it until the key is deleted.\n */\nconst RETIRED_TRACEABILITY_KEYS = [\"scMustHaveTest\", \"unknownContractIdSeverity\"] as const;\n\nfunction reportRetiredTraceabilityKeys(\n traceabilityRaw: Record<string, unknown> | undefined,\n configPath: string,\n issues: Issue[],\n): void {\n if (!traceabilityRaw) {\n return;\n }\n for (const key of RETIRED_TRACEABILITY_KEYS) {\n if (traceabilityRaw[key] === undefined) {\n continue;\n }\n issues.push(\n configDeprecatedIssue(\n configPath,\n `validation.traceability.${key} is retired.` +\n ` No check reads it, so setting it changes nothing.` +\n ` Remove it from qfai.config.yaml.`,\n ),\n );\n }\n}\n\nfunction normalizeUiux(\n raw: unknown,\n configPath: string,\n issues: Issue[],\n): QfaiUiuxConfig | undefined {\n if (raw === undefined || raw === null) {\n return undefined;\n }\n if (!isRecord(raw)) {\n issues.push(configIssue(configPath, \"uiux must be an object.\"));\n return undefined;\n }\n const result: QfaiUiuxConfig = {};\n if (raw.platform !== undefined) {\n if (typeof raw.platform === \"string\" && raw.platform.trim().length > 0) {\n result.platform = raw.platform;\n } else {\n issues.push(configIssue(configPath, \"uiux.platform must be a non-empty string.\"));\n }\n }\n if (raw.designTokensDir !== undefined) {\n if (typeof raw.designTokensDir === \"string\" && raw.designTokensDir.trim().length > 0) {\n result.designTokensDir = raw.designTokensDir;\n } else {\n issues.push(configIssue(configPath, \"uiux.designTokensDir must be a non-empty string.\"));\n }\n }\n if (raw.htmlMockTimeout !== undefined) {\n if (\n typeof raw.htmlMockTimeout === \"number\" &&\n Number.isFinite(raw.htmlMockTimeout) &&\n raw.htmlMockTimeout > 0\n ) {\n result.htmlMockTimeout = raw.htmlMockTimeout;\n } else {\n issues.push(configIssue(configPath, \"uiux.htmlMockTimeout must be a positive number.\"));\n }\n }\n if (raw.qualityProfile !== undefined) {\n if (\n typeof raw.qualityProfile === \"string\" &&\n [\"strict\", \"high\", \"default\"].includes(raw.qualityProfile)\n ) {\n result.qualityProfile = raw.qualityProfile as \"strict\" | \"high\" | \"default\";\n } else {\n issues.push(\n configIssue(configPath, \"uiux.qualityProfile must be one of strict|high|default.\"),\n );\n }\n }\n if (raw.requireResearchSummary !== undefined) {\n if (typeof raw.requireResearchSummary === \"boolean\") {\n result.requireResearchSummary = raw.requireResearchSummary;\n } else {\n issues.push(configIssue(configPath, \"uiux.requireResearchSummary must be a boolean.\"));\n }\n }\n if (raw.competitive_refs_min !== undefined) {\n // Integers only. A count of references is discrete, and now that the knob\n // is a blocking gate a fractional bound is silently rounded up by the\n // comparison while the finding still reports the fraction — `2.5` demands\n // three references and says \"at least 2.5\".\n if (\n typeof raw.competitive_refs_min === \"number\" &&\n Number.isInteger(raw.competitive_refs_min) &&\n raw.competitive_refs_min >= 0\n ) {\n result.competitive_refs_min = raw.competitive_refs_min;\n } else {\n issues.push(\n configIssue(\n configPath,\n \"uiux.competitive_refs_min must be an integer greater than or equal to 0.\",\n ),\n );\n }\n }\n\n if (raw.catalogue_refs_min !== undefined) {\n if (\n typeof raw.catalogue_refs_min === \"number\" &&\n Number.isInteger(raw.catalogue_refs_min) &&\n raw.catalogue_refs_min >= 0\n ) {\n result.catalogue_refs_min = raw.catalogue_refs_min;\n } else {\n issues.push(\n configIssue(configPath, \"uiux.catalogue_refs_min must be an integer of 0 or more.\"),\n );\n }\n }\n if (raw.surfacePaths !== undefined) {\n const surfacePaths = raw.surfacePaths;\n if (\n Array.isArray(surfacePaths) &&\n surfacePaths.every(\n (entry: unknown): entry is string => typeof entry === \"string\" && entry.trim().length > 0,\n )\n ) {\n result.surfacePaths = surfacePaths.map((entry) => entry.trim());\n } else {\n issues.push(\n configIssue(configPath, \"uiux.surfacePaths must be a list of non-empty glob strings.\"),\n );\n }\n }\n if (raw.registries !== undefined) {\n const registries = normalizeUiuxRegistries(raw.registries, configPath, issues);\n if (registries) {\n result.registries = registries;\n }\n }\n if (raw.audit !== undefined) {\n const audit = normalizeUiuxAudit(raw.audit, configPath, issues);\n if (audit) {\n result.audit = audit;\n }\n }\n return Object.keys(result).length > 0 ? result : undefined;\n}\n\n/**\n * A registry entry resolves one component name, so the template has to say\n * where the name goes. A URL without the placeholder resolves nothing and is\n * the typo this catches; everything else about the URL is the registry's\n * business, including its scheme, because a private one may sit on localhost.\n */\nfunction normalizeUiuxRegistries(\n raw: unknown,\n configPath: string,\n issues: Issue[],\n): Record<string, string> | undefined {\n if (!isRecord(raw)) {\n issues.push(configIssue(configPath, \"uiux.registries must be an object.\"));\n return undefined;\n }\n const result: Record<string, string> = {};\n for (const [name, url] of Object.entries(raw)) {\n if (typeof url !== \"string\" || url.trim().length === 0) {\n issues.push(configIssue(configPath, `uiux.registries.${name} must be a non-empty string.`));\n continue;\n }\n if (!url.includes(\"{name}\")) {\n issues.push(\n configIssue(\n configPath,\n `uiux.registries.${name} must contain the {name} placeholder, or it resolves no component.`,\n ),\n );\n continue;\n }\n result[name] = url;\n }\n return Object.keys(result).length > 0 ? result : undefined;\n}\n\nfunction normalizeUiuxAudit(\n raw: unknown,\n configPath: string,\n issues: Issue[],\n): QfaiUiuxAuditConfig | undefined {\n if (!isRecord(raw)) {\n issues.push(configIssue(configPath, \"uiux.audit must be an object.\"));\n return undefined;\n }\n const result: QfaiUiuxAuditConfig = {};\n if (raw.enabled !== undefined) {\n if (typeof raw.enabled === \"boolean\") {\n result.enabled = raw.enabled;\n } else {\n issues.push(configIssue(configPath, \"uiux.audit.enabled must be a boolean.\"));\n }\n }\n if (raw.slopDetection !== undefined) {\n if (typeof raw.slopDetection === \"boolean\") {\n result.slopDetection = raw.slopDetection;\n } else {\n issues.push(configIssue(configPath, \"uiux.audit.slopDetection must be a boolean.\"));\n }\n }\n if (raw.maxPrimaryCtas !== undefined) {\n if (\n typeof raw.maxPrimaryCtas === \"number\" &&\n Number.isFinite(raw.maxPrimaryCtas) &&\n raw.maxPrimaryCtas >= 0\n ) {\n result.maxPrimaryCtas = raw.maxPrimaryCtas;\n } else {\n issues.push(\n configIssue(\n configPath,\n \"uiux.audit.maxPrimaryCtas must be a number greater than or equal to 0.\",\n ),\n );\n }\n }\n if (raw.maxRawTokenLiteralWarnings !== undefined) {\n if (\n typeof raw.maxRawTokenLiteralWarnings === \"number\" &&\n Number.isFinite(raw.maxRawTokenLiteralWarnings) &&\n raw.maxRawTokenLiteralWarnings >= 0\n ) {\n result.maxRawTokenLiteralWarnings = raw.maxRawTokenLiteralWarnings;\n } else {\n issues.push(\n configIssue(\n configPath,\n \"uiux.audit.maxRawTokenLiteralWarnings must be a number greater than or equal to 0.\",\n ),\n );\n }\n }\n if (raw.maxDuplicateFindingsPerRule !== undefined) {\n if (\n typeof raw.maxDuplicateFindingsPerRule === \"number\" &&\n Number.isFinite(raw.maxDuplicateFindingsPerRule) &&\n raw.maxDuplicateFindingsPerRule >= 0\n ) {\n result.maxDuplicateFindingsPerRule = raw.maxDuplicateFindingsPerRule;\n } else {\n issues.push(\n configIssue(\n configPath,\n \"uiux.audit.maxDuplicateFindingsPerRule must be a number greater than or equal to 0.\",\n ),\n );\n }\n }\n return Object.keys(result).length > 0 ? result : undefined;\n}\n\nfunction configIssue(file: string, message: string): Issue {\n return {\n code: \"QFAI-CFG-002\",\n severity: \"error\",\n category: \"canonical\",\n message,\n file,\n rule: \"config.invalid\",\n };\n}\n\nfunction configDeprecatedIssue(file: string, message: string): Issue {\n return {\n code: \"QFAI-CFG-001\",\n severity: \"error\",\n category: \"canonical\",\n message,\n file,\n rule: \"config.deprecatedKey\",\n };\n}\n\nasync function exists(target: string): Promise<boolean> {\n try {\n await access(target);\n return true;\n } catch {\n return false;\n }\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return value !== null && typeof value === \"object\" && !Array.isArray(value);\n}\n","/**\n * Shared errno helpers for Node.js fs error narrowing.\n *\n * Avoids ad-hoc `(err as { code?: string }).code === \"ENOENT\"` repetition\n * across init / config / prototyping commands. Future errno codes\n * (`EACCES`, `EBUSY`, `EPERM`, ...) extend this module rather than\n * sprouting new inline checks.\n */\n\n/**\n * True iff `err` is a Node.js fs error whose `code` is `\"ENOENT\"`\n * (file or directory does not exist).\n */\nexport function isEnoent(err: unknown): boolean {\n return hasErrnoCode(err) && err.code === \"ENOENT\";\n}\n\n/**\n * True iff `err` is a Node.js fs error whose `code` is `\"EPERM\"`.\n *\n * On Windows this is what `stat` raises for a **file** symlink whose target is\n * a directory: the link is intact and `readlink` returns the right target, but\n * the reparse tag is the wrong kind and the OS refuses to follow it. `git\n * worktree add` produces exactly that for `.claude/skills/*`, because at the\n * moment git writes the link its target does not yet exist in the new worktree\n * and it has no reftype hint. So a reader that treats EPERM as a filesystem\n * fault to propagate crashes on a condition that is structural damage to the\n * path it is inspecting.\n */\nexport function isEperm(err: unknown): boolean {\n return hasErrnoCode(err) && err.code === \"EPERM\";\n}\n\n/**\n * True iff `err` is a Node.js error-shaped object carrying a string\n * `code` (e.g. `\"ENOENT\"`, `\"EACCES\"`, `\"ENOSPC\"`). Narrowing helper\n * shared across the codebase so individual call sites do not sprout\n * ad-hoc `(err as { code?: string }).code` casts (CLAUDE.md\n * \"avoid bare `as` type assertions; prefer type narrowing\").\n */\nexport function hasErrnoCode(err: unknown): err is { code: string } {\n return (\n err !== null &&\n typeof err === \"object\" &&\n \"code\" in err &&\n typeof (err as { code?: unknown }).code === \"string\"\n );\n}\n","/**\n * The workflow file names this package writes into an adopter's\n * `.github/workflows/` directory.\n *\n * The list is IN-BINARY. It is never computed by globbing the asset\n * tree at runtime or the adopter's disk: a write set derived from whatever\n * happens to be on disk cannot distinguish a file this package ships from one\n * somebody else put there, which is the distinction the whole\n * shipped-workflows contract rests on. The shipped-asset shape gate keeps this\n * list equal to the packaged workflow assets.\n *\n * They live in `shared/` rather than beside the command that writes them\n * because two layers need the same answer: the `init` command, which copies\n * them, and the `doctor` integrity reader, which has to know what a healthy\n * packaged tree contains before it can call a gutted one healthy. `core/` may\n * not import from `cli/`, and a second copy of the list is how the two\n * answers drift apart. `cli/commands/init.ts` re-exports it, so the public\n * surface is unchanged.\n */\n\n/**\n * Names the current package version ships into the adopter's\n * `.github/workflows/` directory (the shipped-workflows contract's write set).\n */\nexport const SHIPPED_WORKFLOW_NAMES: ReadonlySet<string> = new Set<string>([\n \"qfai-validate.yml\",\n \"qfai-tests.yml\",\n \"qfai-docs.yml\",\n]);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qBAA6B;AAC7B,qBAAe;;;ACDf,gCAAoD;AACpD,yBAA2B;AAC3B,IAAAA,mBAAwC;AACxC,IAAAC,oBAAiB;;;ACHjB,sBAAiC;AACjC,uBAAiB;AAEjB,kBAAmC;;;ACU5B,SAAS,SAAS,KAAuB;AAC9C,SAAO,aAAa,GAAG,KAAK,IAAI,SAAS;AAC3C;AAyBO,SAAS,aAAa,KAAuC;AAClE,SACE,QAAQ,QACR,OAAO,QAAQ,YACf,UAAU,OACV,OAAQ,IAA2B,SAAS;AAEhD;;;ACvBO,IAAM,yBAA8C,oBAAI,IAAY;AAAA,EACzE;AAAA,EACA;AAAA,EACA;AACF,CAAC;;;AFgLM,IAAM,gBAA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AAO;AACT;;;ADxRA,eAAe,OAAsB;AACnC,MAAI;AACF,QAAI;AACJ,QAAI;AACF,cAAQ,KAAK,UAAM,6BAAa,GAAG,MAAM,CAAC;AAAA,IAC5C,QAAQ;AACN,cAAQ;AAAA,IACV;AACA,UAAM,SAAS,MAAM,eAAe,OAAO;AAAA,MACzC,YAAY,QAAQ,IAAI;AAAA,MACxB,UAAU,eAAAE,QAAG,OAAO;AAAA,IACtB,CAAC;AACD,QAAI,WAAW,GAAI,SAAQ,OAAO,MAAM,MAAM;AAAA,EAChD,SAAS,OAAgB;AAEvB,UAAM,UAAU,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AACrE,YAAQ,OAAO,MAAM,sCAAsC,OAAO;AAAA,CAAI;AAAA,EACxE;AACA,UAAQ,WAAW;AACrB;AAIA,KAAK,KAAK;","names":["import_promises","import_node_path","path","parseYaml","isRecord","path","os"]}
|
|
1
|
+
{"version":3,"sources":["../../src/cli/turnEndHook.ts","../../src/core/turnEndHook.ts","../../src/core/config.ts","../../src/core/fs/errno.ts","../../src/shared/shippedWorkflowNames.ts"],"sourcesContent":["import { readFileSync } from \"node:fs\";\nimport os from \"node:os\";\n\nimport { runTurnEndHook } from \"../core/turnEndHook.js\";\n\n/**\n * The Stop and SubagentStop hook `qfai init` installs, run by the guard in the host hook file.\n *\n * It never fails the host: every error is swallowed and the hook exits 0 with nothing printed, so\n * a broken install lets the turn end rather than holding it open.\n */\nasync function main(): Promise<void> {\n try {\n let input: unknown;\n try {\n input = JSON.parse(readFileSync(0, \"utf8\"));\n } catch {\n input = undefined;\n }\n const output = await runTurnEndHook(input, {\n processDir: process.cwd(),\n stateDir: os.tmpdir(),\n });\n if (output !== \"\") process.stdout.write(output);\n } catch (error: unknown) {\n // The turn ends as if no check were listed; one line on stderr says why, for the host's log.\n const message = error instanceof Error ? error.message : String(error);\n process.stderr.write(`QFAI turn-end check could not run: ${message}\\n`);\n }\n process.exitCode = 0;\n}\n\n// The entry is loaded by `require` from the guard and has no caller to return to; `main` handles\n// every failure itself, so the promise it returns cannot reject.\nvoid main();\n","import { spawn, spawnSync, type ChildProcess } from \"node:child_process\";\nimport { createHash } from \"node:crypto\";\nimport { readFile, rm, writeFile } from \"node:fs/promises\";\nimport path from \"node:path\";\n\nimport { findConfigRoot, loadConfig, readStopGate, resolvePath } from \"./config.js\";\n\n/** One Standard command the project marks for turn end. */\nexport interface TurnEndCheck {\n readonly label: string;\n readonly command: string;\n}\n\nexport interface TurnEndOptions {\n /** Where the hook process runs; the config search starts here when the event names no `cwd`. */\n readonly processDir: string;\n /** Where the last blocked failure of each session is kept. */\n readonly stateDir: string;\n /** How long one command may run. */\n readonly timeoutMs?: number;\n}\n\nconst DEFAULT_TIMEOUT_MS = 60_000;\nconst TAIL_LINES = 40;\nconst TAIL_CHARS = 4000;\n/** Output kept while a command runs; only the tail is ever reported. */\nconst KEEP_CHARS = 64 * 1024;\n/** How long output is still read after a command exits, for a child that keeps the pipes open. */\nconst EXIT_GRACE_MS = 1000;\n/** Blocks in one continued turn after which the hook lets the turn end whatever the failure. */\nconst MAX_CONTINUED_BLOCKS = 3;\nconst COMMANDS_HEADING = /^##\\s+Standard commands\\b/i;\nconst TURN_END_LABEL = \"turn-end check\";\n\n/**\n * The commands the Standard commands section of a tech.md marks for turn end, in the order its\n * `Turn-end check:` item lists their labels. A label the section does not list is skipped.\n */\nexport function readTurnEndChecks(techText: string): TurnEndCheck[] {\n const commands = new Map<string, string>();\n let marked: string[] = [];\n let inSection = false;\n for (const line of techText.split(/\\r?\\n/)) {\n if (/^#{1,2}\\s/.test(line)) {\n inSection = COMMANDS_HEADING.test(line);\n continue;\n }\n if (!inSection) continue;\n const item = /^\\s*-\\s+([^:`]+):\\s*(.*)$/.exec(line);\n if (item === null) continue;\n const label = (item[1] ?? \"\").trim();\n const rest = item[2] ?? \"\";\n if (label.toLowerCase() === TURN_END_LABEL) {\n marked = rest\n .split(\",\")\n .map((name) => name.replace(/`/g, \"\").trim())\n .filter((name) => name !== \"\");\n continue;\n }\n const command = /`([^`]+)`/.exec(rest)?.[1];\n if (command !== undefined) commands.set(label.toLowerCase(), command);\n }\n const checks: TurnEndCheck[] = [];\n for (const label of marked) {\n const command = commands.get(label.toLowerCase());\n if (command !== undefined) checks.push({ label, command });\n }\n return checks;\n}\n\ninterface CommandResult {\n readonly code: number | null;\n readonly signal: NodeJS.Signals | null;\n /** stdout and stderr in the order they arrived, as shown to the agent. */\n readonly output: string;\n /** stdout, then stderr: the same failure gives the same text whatever the interleaving. */\n readonly ordered: string;\n readonly timedOut: boolean;\n}\n\n/**\n * Stops a command and everything it started. A shell does not pass its own termination on to\n * the program it runs, so the whole tree is stopped: by process group on POSIX, by `taskkill /T`\n * on Windows, falling back to the shell alone where neither works.\n */\nfunction stopTree(child: ChildProcess): void {\n const pid = child.pid;\n if (pid === undefined) return;\n try {\n if (process.platform === \"win32\") {\n const killed = spawnSync(\"taskkill\", [\"/pid\", String(pid), \"/T\", \"/F\"], {\n windowsHide: true,\n });\n if (killed.status !== 0) child.kill(\"SIGKILL\");\n } else {\n process.kill(-pid, \"SIGKILL\");\n }\n } catch {\n child.kill(\"SIGKILL\");\n }\n}\n\nfunction runCommand(command: string, cwd: string, timeoutMs: number): Promise<CommandResult> {\n return new Promise((resolve) => {\n let output = \"\";\n let stdout = \"\";\n let stderr = \"\";\n let settled = false;\n let grace: ReturnType<typeof setTimeout> | undefined;\n const child = spawn(command, {\n cwd,\n shell: true,\n windowsHide: true,\n detached: process.platform !== \"win32\",\n stdio: [\"ignore\", \"pipe\", \"pipe\"],\n });\n const finish = (\n code: number | null,\n signal: NodeJS.Signals | null,\n timedOut: boolean,\n extra = \"\",\n ): void => {\n if (settled) return;\n settled = true;\n clearTimeout(timer);\n clearTimeout(grace);\n child.stdout.destroy();\n child.stderr.destroy();\n resolve({\n code,\n signal,\n output: output + extra,\n ordered: stdout + stderr + extra,\n timedOut,\n });\n };\n child.stdout.setEncoding(\"utf8\");\n child.stderr.setEncoding(\"utf8\");\n child.stdout.on(\"data\", (chunk: string) => {\n output = (output + chunk).slice(-KEEP_CHARS);\n stdout = (stdout + chunk).slice(-KEEP_CHARS);\n });\n child.stderr.on(\"data\", (chunk: string) => {\n output = (output + chunk).slice(-KEEP_CHARS);\n stderr = (stderr + chunk).slice(-KEEP_CHARS);\n });\n const timer = setTimeout(() => {\n stopTree(child);\n finish(null, null, true);\n }, timeoutMs);\n child.on(\"error\", (error) => {\n finish(null, null, false, `${error.message}\\n`);\n });\n // The exit code is settled when the command exits. A program it left running may still hold\n // the pipes, so the output is read a little longer and, on POSIX, what is left of the process\n // group is stopped.\n // SIMPLIFIED: on Windows the tree cannot be reached once the shell has exited: `taskkill /T`\n // needs a live root, and the shell's pid may already be reused. The leftover program keeps\n // running.\n // Lift when: a check is seen leaving a program running on Windows; then hold the tree in a\n // Job Object.\n child.on(\"exit\", (code, signal) => {\n clearTimeout(timer);\n grace = setTimeout(() => {\n if (process.platform !== \"win32\") stopTree(child);\n finish(code, signal, false);\n }, EXIT_GRACE_MS);\n });\n child.on(\"close\", (code, signal) => {\n finish(code, signal, false);\n });\n });\n}\n\n/** How a failed command ended, in words. */\nfunction endingOf(result: CommandResult, timeoutMs: number): string {\n if (result.timedOut) {\n const seconds = Math.max(1, Math.round(timeoutMs / 1000));\n return `did not finish within ${seconds} second${seconds === 1 ? \"\" : \"s\"}`;\n }\n if (result.code !== null) return `ended with exit ${result.code}`;\n return result.signal === null ? \"ended with exit unknown\" : `was stopped by ${result.signal}`;\n}\n\n/** The last lines of a command's output, within both bounds. */\nfunction tail(output: string): string {\n const lines = output.replace(/\\s+$/, \"\").split(/\\r?\\n/);\n return lines.slice(-TAIL_LINES).join(\"\\n\").slice(-TAIL_CHARS);\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction stringField(event: Record<string, unknown>, key: string): string | undefined {\n const value = event[key];\n return typeof value === \"string\" && value !== \"\" ? value : undefined;\n}\n\n/**\n * Whose turn a state file belongs to. A subagent's stop is kept apart from the main agent's even\n * when the host sends no agent id, so a subagent's block never releases the main agent's turn.\n */\nfunction agentKey(event: Record<string, unknown>): string {\n const agent = stringField(event, \"agent_id\");\n if (agent !== undefined) return agent;\n return event.hook_event_name === \"SubagentStop\" ? \"subagent\" : \"main\";\n}\n\nfunction stateFile(stateDir: string, session: string, agent: string): string {\n const name = [\"qfai-turn-end\", session, agent].join(\"-\").replace(/[^\\w.-]/g, \"_\");\n return path.join(stateDir, name);\n}\n\n/** The failure the hook last blocked on for one session and agent, and the blocks in a row. */\ninterface BlockState {\n readonly digest: string;\n readonly blocks: number;\n}\n\nasync function readState(file: string | null): Promise<BlockState | null> {\n if (file === null) return null;\n try {\n const value: unknown = JSON.parse(await readFile(file, \"utf8\"));\n if (!isRecord(value)) return null;\n const { digest, blocks } = value;\n return typeof digest === \"string\" && typeof blocks === \"number\" ? { digest, blocks } : null;\n } catch {\n return null;\n }\n}\n\n/**\n * What the turn-end hook prints for one Stop or SubagentStop event: an empty string to let the\n * turn end silently, or one JSON object that blocks the stop or lets it through with a message.\n */\nexport async function runTurnEndHook(input: unknown, options: TurnEndOptions): Promise<string> {\n const event = isRecord(input) ? input : {};\n const found = await findConfigRoot(stringField(event, \"cwd\") ?? options.processDir);\n if (!found.found) return \"\";\n const loaded = await loadConfig(found.root);\n if (readStopGate(loaded.document) !== true) return \"\";\n let techText: string;\n try {\n techText = await readFile(\n path.join(resolvePath(found.root, loaded.config, \"contractsDir\"), \"tech.md\"),\n \"utf8\",\n );\n } catch (error) {\n // A project without tech.md lists no check; any other read error is reported by the caller.\n if (isRecord(error) && error.code === \"ENOENT\") return \"\";\n throw error;\n }\n const checks = readTurnEndChecks(techText);\n const session = stringField(event, \"session_id\");\n const file = session === undefined ? null : stateFile(options.stateDir, session, agentKey(event));\n const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;\n\n for (const check of checks) {\n const result = await runCommand(check.command, found.root, timeoutMs);\n if (!result.timedOut && result.code === 0) continue;\n const shown = tail(result.output);\n const ending = endingOf(result, timeoutMs);\n const digest = createHash(\"sha256\")\n .update([check.label, ending, tail(result.ordered)].join(\"\\n\").replace(/\\d+/g, \"#\"))\n .digest(\"hex\");\n const continued = event.stop_hook_active === true;\n const last = await readState(file);\n const blocks = continued && last !== null ? last.blocks + 1 : 1;\n const release =\n file === null\n ? continued\n : continued && (last?.digest === digest || blocks > MAX_CONTINUED_BLOCKS);\n if (release) {\n if (file !== null) await rm(file, { force: true });\n return `${JSON.stringify({\n systemMessage: `QFAI turn-end check: ${check.label} still fails, and the turn ended anyway. Run ${check.command} in ${found.root} to see the failure.`,\n })}\\n`;\n }\n if (file !== null) await writeFile(file, JSON.stringify({ digest, blocks }), \"utf8\");\n const reason = [\n `The turn-end check ${check.label} failed: ${check.command} ${ending}.`,\n shown === \"\" ? \"It printed nothing.\" : `End of its output:\\n${shown}`,\n event.hook_event_name === \"SubagentStop\"\n ? \"Fix the cause before ending the turn. If fixing it is outside your task, say so in your reply and end the turn. The check is listed under Turn-end check in tech.md.\"\n : \"Fix the cause before ending the turn. The check is listed under Turn-end check in tech.md.\",\n ].join(\"\\n\\n\");\n return `${JSON.stringify({ decision: \"block\", reason })}\\n`;\n }\n if (file !== null) await rm(file, { force: true });\n return \"\";\n}\n","import { access, readFile } from \"node:fs/promises\";\nimport path from \"node:path\";\n\nimport { parse as parseYaml } from \"yaml\";\n\nimport type { Issue } from \"./types.js\";\nimport { isEnoent } from \"./fs/errno.js\";\nimport { SHIPPED_WORKFLOW_NAMES } from \"../shared/shippedWorkflowNames.js\";\n\nexport type FailOn = \"never\" | \"warning\" | \"error\";\nexport type OutputFormat = \"text\" | \"github\";\n\nexport type QfaiPaths = {\n contractsDir: string;\n specsDir: string;\n /** Where the per-run deliberation records live, read with `\\` taken as `/`. */\n deliberationDir: string;\n outDir: string;\n skillsDir: string;\n srcDir: string;\n testsDir: string;\n /**\n * Where the project's migrations live, if it has any.\n *\n * Optional and unset by default, because qfai cannot guess it and a project\n * without migrations is not in violation of anything. `qfai db-drift` is the\n * only reader: with no value it says the project is out of scope and stops,\n * rather than comparing the contracts against an empty directory and calling\n * every column a difference.\n */\n migrationsDir?: string;\n};\n\nexport type QfaiForbiddenIdentifier = {\n sha256: string;\n byteLength: number;\n};\n\nexport type DiagramBudget = { nodes: number; edges: number };\n\nexport const DEFAULT_DIAGRAM_BUDGET: DiagramBudget = { nodes: 12, edges: 16 };\n\nexport type QfaiValidationConfig = {\n failOn: FailOn;\n /**\n * Terms the specs must no longer state, such as an option a decision rejected.\n * `qfai validate` warns on each line of a spec document that still holds one\n * (QFAI-STORY-016). Unset means no term is checked.\n */\n staleTerms?: string[];\n /**\n * The largest node and edge counts a Mermaid diagram may have before\n * `qfai validate` warns (QFAI-FLOW-006). A limit left unset is the default\n * of `DEFAULT_DIAGRAM_BUDGET`.\n */\n diagramBudget?: Partial<DiagramBudget>;\n /** Hash-only identifiers checked against tracked names and current file bytes. */\n forbiddenIdentifiers?: QfaiForbiddenIdentifier[];\n testStrategy: {\n /**\n * When true (default), `qfai validate` reports the silent-placeholder\n * construct of each supported stack in test files (QFAI-TEST-001). On\n * JS/TS that is `it.todo` / `test.todo` / `describe.todo` (error) and\n * `it.skip` / `test.skip` / `describe.skip` (warning).\n * Set to false to opt out while migrating an existing project.\n */\n forbidTestTodoStubs: boolean;\n };\n traceability: {\n testFileGlobs: string[];\n testFileExcludeGlobs: string[];\n };\n};\n\nexport type QfaiOutputConfig = {\n validateJsonPath: string;\n};\n\nexport type QfaiUiuxAuditConfig = {\n enabled?: boolean;\n slopDetection?: boolean;\n maxRawTokenLiteralWarnings?: number;\n maxDuplicateFindingsPerRule?: number;\n};\n\nexport type QfaiUiuxConfig = {\n platform?: string;\n /**\n * Component registries the project can procure from, as name to URL\n * template. The shape mirrors the `registries` map a `components.json`\n * already carries, so a project that has one restates it rather than\n * translating it.\n *\n * Which registry is primary is named by the `Component catalogue` row of the\n * Stack table in `.qfai/spec/03_contract/tech.md`. Nothing here ranks them.\n */\n registries?: Record<string, string>;\n designTokensDir?: string;\n htmlMockTimeout?: number;\n qualityProfile?: \"strict\" | \"high\" | \"default\";\n /**\n * Repository-relative POSIX globs of the paths that render a user-visible\n * surface. An empty list states that the project renders none; an absent\n * key declares nothing.\n */\n surfacePaths?: string[];\n audit?: QfaiUiuxAuditConfig;\n};\n\nexport type QfaiPrototypingExecutionConfig = {\n targetUrl?: string | null;\n /**\n * Browser tool handed to the AI evaluator sub-agent. Only `\"playwright\"` is\n * accepted.\n */\n browserTool: \"playwright\";\n};\n\nexport type QfaiPrototypingConfig = {\n execution?: QfaiPrototypingExecutionConfig;\n /**\n * Explicit primary UI contract for `/qfai-prototyping`.\n * Uses the full `UI-NNNN` identifier.\n */\n primaryUiContract?: string;\n};\n\nexport type QfaiReportConfig = {\n /**\n * Stale run-log TTL (calendar days) used by `qfai doctor --clean` to\n * decide whether a `<paths.outDir>/run-*` directory may be pruned.\n * `0` opts out entirely (never prune). Default (when unset) is applied\n * at the call-site by `RUN_LOG_STALE_TTL_DAYS_DEFAULT`.\n */\n staleTtlDays?: number;\n /**\n * Number of newest `run-*` directories retained regardless of age, so\n * `validate.log`'s `run_log:` pointer can never be pruned away.\n * Default (when unset) is applied at the call-site by\n * `RUN_LOG_KEEP_LATEST_DEFAULT`; `0` is clamped up to\n * `RUN_LOG_KEEP_LATEST_MIN` (1) there, because keeping nothing would\n * strand that pointer. Use `staleTtlDays: 0` to keep every run.\n */\n keepLatestRuns?: number;\n};\n\nexport type QfaiConfig = {\n paths: QfaiPaths;\n validation: QfaiValidationConfig;\n output: QfaiOutputConfig;\n uiux?: QfaiUiuxConfig;\n prototyping?: QfaiPrototypingConfig;\n report?: QfaiReportConfig;\n baseBranch?: string;\n};\n\n/**\n * The path keys `resolvePath` can resolve: the ones every config has.\n *\n * An optional key is excluded by its type rather than by a list, so a path\n * added later joins or stays out on its own. `resolvePath` returns a string,\n * and there is no directory to return for a key the project did not set — its\n * reader has to decide what absence means, which is not something a resolver\n * can do for it.\n */\nexport type ConfigPathKey = {\n [K in keyof QfaiPaths]-?: undefined extends QfaiPaths[K] ? never : K;\n}[keyof QfaiPaths];\n\nexport type ConfigLoadResult = {\n config: QfaiConfig;\n issues: Issue[];\n configPath: string;\n /**\n * The parsed YAML document, before normalization. `undefined` when the\n * file is absent (`issues` empty) or could not be read / parsed at all\n * (`issues` non-empty) — the two cases a caller distinguishes by the\n * issue list.\n *\n * `issues` records *that* something was rejected but not *which* key,\n * so it cannot answer \"was the value I depend on honoured, or silently\n * replaced by its default?\". Normalization is per-key and independent,\n * so an unrelated rejection (a bad `baseBranch`, say) says nothing\n * about `paths.specsDir`. A caller whose correctness hinges on one\n * key reads it here and checks that key alone, rather than treating any\n * issue anywhere in the file as a reason to distrust the whole config.\n */\n document?: unknown;\n};\n\nexport type ConfigSearchResult = {\n root: string;\n configPath: string;\n found: boolean;\n};\n\nexport const defaultConfig: QfaiConfig = {\n paths: {\n contractsDir: \".qfai/spec/03_contract\",\n specsDir: \".qfai/spec\",\n deliberationDir: \".qfai/deliberation\",\n outDir: \".qfai/report\",\n skillsDir: \".qfai/assistant/skill\",\n srcDir: \"src\",\n testsDir: \"tests\",\n },\n validation: {\n failOn: \"error\",\n testStrategy: {\n forbidTestTodoStubs: true,\n },\n traceability: {\n testFileGlobs: [],\n testFileExcludeGlobs: [],\n },\n },\n output: {\n validateJsonPath: \".qfai/report/validate.json\",\n },\n prototyping: {\n execution: {\n targetUrl: null,\n browserTool: \"playwright\",\n },\n },\n};\n\nexport function getConfigPath(root: string): string {\n return path.join(root, \"qfai.config.yaml\");\n}\n\nexport async function findConfigRoot(startDir: string): Promise<ConfigSearchResult> {\n const resolvedStart = path.resolve(startDir);\n let current = resolvedStart;\n\n for (;;) {\n const configPath = getConfigPath(current);\n if (await exists(configPath)) {\n return { root: current, configPath, found: true };\n }\n const parent = path.dirname(current);\n if (parent === current) {\n break;\n }\n current = parent;\n }\n\n return {\n root: resolvedStart,\n configPath: getConfigPath(resolvedStart),\n found: false,\n };\n}\n\nexport async function loadConfig(root: string): Promise<ConfigLoadResult> {\n const configPath = getConfigPath(root);\n const issues: Issue[] = [];\n\n let parsed: unknown;\n try {\n const raw = await readFile(configPath, \"utf-8\");\n parsed = parseYaml(raw);\n } catch (error) {\n if (isEnoent(error)) {\n return { config: defaultConfig, issues, configPath };\n }\n issues.push(configIssue(configPath, \"The configuration file could not be read or parsed.\"));\n return { config: defaultConfig, issues, configPath };\n }\n\n const normalized = normalizeConfig(parsed, configPath, issues);\n if (readWorkflowMode(parsed) === null) {\n issues.push(configIssue(configPath, WORKFLOW_MODE_MESSAGE));\n }\n if (readSkippedWorkflows(parsed) === null) {\n issues.push(configIssue(configPath, SKIPPED_WORKFLOWS_MESSAGE));\n }\n if (readAcceptedDrift(parsed) === null) {\n issues.push(configIssue(configPath, ACCEPTED_DRIFT_MESSAGE));\n }\n if (readStopGate(parsed) === null) {\n issues.push(configIssue(configPath, STOP_GATE_MESSAGE));\n }\n return { config: normalized, issues, configPath, document: parsed };\n}\n\n/** The config issue an invalid `workflow.stopGate` raises. */\nexport const STOP_GATE_MESSAGE =\n \"workflow.stopGate must be true or false; an absent key means true.\";\n\n/**\n * Whether the turn-end hook runs the project's turn-end checks, read from the parsed config\n * document. `null` means the value is not a boolean, which the hook treats as `false`.\n */\nexport function readStopGate(document: unknown): boolean | null {\n const workflow = isRecord(document) ? document.workflow : undefined;\n if (workflow === undefined) return true;\n if (!isRecord(workflow)) return null;\n if (workflow.stopGate === undefined) return true;\n return typeof workflow.stopGate === \"boolean\" ? workflow.stopGate : null;\n}\n\nconst WORKFLOW_MODES = [\"active\", \"shadow\", \"off\"] as const;\n\n/** The config issue an invalid `workflow.mode` raises. */\nexport const WORKFLOW_MODE_MESSAGE =\n \"workflow.mode must be active, shadow or off; an absent key means active.\";\n\nexport type WorkflowMode = (typeof WORKFLOW_MODES)[number];\n\n/**\n * The workflow mode in force, read from the parsed config document. `null` means the value is\n * none of the three, and no mode is guessed in its place.\n */\nexport function readWorkflowMode(document: unknown): WorkflowMode | null {\n const workflow = isRecord(document) ? document.workflow : undefined;\n if (workflow === undefined) return \"active\";\n if (!isRecord(workflow)) return null;\n const mode = workflow.mode;\n if (mode === undefined) return \"active\";\n return WORKFLOW_MODES.find((known) => known === mode) ?? null;\n}\n\n/** The config issue an invalid `workflow.skipShipped` raises. */\nexport const SKIPPED_WORKFLOWS_MESSAGE = `workflow.skipShipped must be a list of shipped workflow file names (${[...SHIPPED_WORKFLOW_NAMES].join(\", \")}); an absent key means none are skipped.`;\n\n/**\n * The shipped workflow names `workflow.skipShipped` lists, read from the parsed config document.\n * `null` means the value is not a list of shipped names, and no entry is guessed in its place.\n */\nexport function readSkippedWorkflows(document: unknown): ReadonlySet<string> | null {\n const workflow = isRecord(document) ? document.workflow : undefined;\n if (!isRecord(workflow) || workflow.skipShipped === undefined) return new Set();\n const listed = workflow.skipShipped;\n if (!Array.isArray(listed)) return null;\n const names = new Set<string>();\n for (const name of listed) {\n if (typeof name !== \"string\" || !SHIPPED_WORKFLOW_NAMES.has(name)) return null;\n names.add(name);\n }\n return names;\n}\n\n/** The config issue an invalid `workflow.acceptedDrift` raises. */\nexport const ACCEPTED_DRIFT_MESSAGE = `workflow.acceptedDrift must be a list of entries, each with a file, one of the shipped workflow file names (${[...SHIPPED_WORKFLOW_NAMES].join(\", \")}) listed once, the digest qfai doctor prints for it (sha256: and 64 lowercase hexadecimal characters), and a reason that is not empty; an absent key means no difference is accepted.`;\n\n/** One `workflow.acceptedDrift` entry: the digest of the accepted text and why it is kept. */\nexport type AcceptedDrift = { readonly digest: string; readonly reason: string };\n\nconst DRIFT_DIGEST = /^sha256:[0-9a-f]{64}$/;\n\n/**\n * The shipped workflows `workflow.acceptedDrift` accepts as differing from the shipped text, each\n * with the digest of the accepted text and its trimmed reason, read from the parsed config\n * document. `null` means the value is not a list of such entries, and no entry is accepted in its\n * place.\n */\nexport function readAcceptedDrift(document: unknown): ReadonlyMap<string, AcceptedDrift> | null {\n const workflow = isRecord(document) ? document.workflow : undefined;\n if (!isRecord(workflow) || workflow.acceptedDrift === undefined) return new Map();\n const listed = workflow.acceptedDrift;\n if (!Array.isArray(listed)) return null;\n const accepted = new Map<string, AcceptedDrift>();\n for (const entry of listed) {\n if (!isRecord(entry)) return null;\n const { file, digest, reason } = entry;\n if (typeof file !== \"string\" || !SHIPPED_WORKFLOW_NAMES.has(file) || accepted.has(file)) {\n return null;\n }\n if (typeof digest !== \"string\" || !DRIFT_DIGEST.test(digest)) return null;\n if (typeof reason !== \"string\" || reason.trim() === \"\") return null;\n accepted.set(file, { digest, reason: reason.trim() });\n }\n return accepted;\n}\n\nexport function resolvePath(root: string, config: QfaiConfig, key: ConfigPathKey): string {\n return path.resolve(root, config.paths[key]);\n}\n\nfunction normalizeConfig(raw: unknown, configPath: string, issues: Issue[]): QfaiConfig {\n if (!isRecord(raw)) {\n issues.push(configIssue(configPath, \"The configuration file format is invalid.\"));\n return defaultConfig;\n }\n\n const uiux = normalizeUiux(raw.uiux, configPath, issues);\n const prototyping = normalizePrototyping(raw.prototyping, configPath, issues);\n const report = normalizeReport(raw.report, configPath, issues);\n const base: QfaiConfig = {\n paths: normalizePaths(raw.paths, configPath, issues),\n validation: normalizeValidation(raw.validation, configPath, issues),\n output: normalizeOutput(raw.output, configPath, issues),\n };\n if (uiux) {\n base.uiux = uiux;\n }\n if (prototyping) {\n base.prototyping = prototyping;\n }\n if (report) {\n base.report = report;\n }\n const baseBranch = readOptionalString(raw.baseBranch, \"baseBranch\", configPath, issues);\n if (baseBranch !== undefined) {\n base.baseBranch = baseBranch;\n }\n return base;\n}\n\nfunction normalizePaths(raw: unknown, configPath: string, issues: Issue[]): QfaiPaths {\n const base = defaultConfig.paths;\n if (!raw) {\n return base;\n }\n if (!isRecord(raw)) {\n issues.push(configIssue(configPath, \"paths must be an object.\"));\n return base;\n }\n\n const migrationsDir = readOptionalString(\n raw.migrationsDir,\n \"paths.migrationsDir\",\n configPath,\n issues,\n );\n\n return {\n ...(migrationsDir !== undefined ? { migrationsDir } : {}),\n contractsDir: readTreeDirString(\n raw.contractsDir,\n base.contractsDir,\n \"paths.contractsDir\",\n configPath,\n issues,\n ),\n specsDir: readTreeDirString(raw.specsDir, base.specsDir, \"paths.specsDir\", configPath, issues),\n deliberationDir: readDeliberationDir(\n raw.deliberationDir,\n base.deliberationDir,\n configPath,\n issues,\n ),\n outDir: readDirString(raw.outDir, base.outDir, \"paths.outDir\", configPath, issues),\n skillsDir: readDirString(raw.skillsDir, base.skillsDir, \"paths.skillsDir\", configPath, issues),\n srcDir: readDirString(raw.srcDir, base.srcDir, \"paths.srcDir\", configPath, issues),\n testsDir: readDirString(raw.testsDir, base.testsDir, \"paths.testsDir\", configPath, issues),\n };\n}\n\nfunction normalizeValidation(\n raw: unknown,\n configPath: string,\n issues: Issue[],\n): QfaiValidationConfig {\n const base = defaultConfig.validation;\n if (!raw) {\n return base;\n }\n if (!isRecord(raw)) {\n issues.push(configIssue(configPath, \"validation must be an object.\"));\n return base;\n }\n\n let traceabilityRaw: Record<string, unknown> | undefined;\n if (raw.traceability === undefined) {\n traceabilityRaw = undefined;\n } else if (isRecord(raw.traceability)) {\n traceabilityRaw = raw.traceability;\n } else {\n issues.push(configIssue(configPath, \"validation.traceability must be an object.\"));\n traceabilityRaw = undefined;\n }\n\n let testStrategyRaw: Record<string, unknown> | undefined;\n if (raw.testStrategy === undefined) {\n testStrategyRaw = undefined;\n } else if (isRecord(raw.testStrategy)) {\n testStrategyRaw = raw.testStrategy;\n } else {\n issues.push(configIssue(configPath, \"validation.testStrategy must be an object.\"));\n testStrategyRaw = undefined;\n }\n\n reportRetiredTraceabilityKeys(traceabilityRaw, configPath, issues);\n\n const forbiddenIdentifiers = normalizeForbiddenIdentifiers(\n raw.forbiddenIdentifiers,\n configPath,\n issues,\n );\n\n const staleTerms = readStringArray(\n raw.staleTerms,\n [],\n \"validation.staleTerms\",\n configPath,\n issues,\n );\n\n const diagramBudget = readDiagramBudget(raw.diagramBudget, configPath, issues);\n\n return {\n failOn: readFailOn(raw.failOn, base.failOn, \"validation.failOn\", configPath, issues),\n ...(staleTerms.length > 0 ? { staleTerms } : {}),\n ...(diagramBudget !== undefined ? { diagramBudget } : {}),\n ...(forbiddenIdentifiers !== undefined ? { forbiddenIdentifiers } : {}),\n testStrategy: {\n forbidTestTodoStubs: readBoolean(\n testStrategyRaw?.forbidTestTodoStubs,\n base.testStrategy.forbidTestTodoStubs,\n \"validation.testStrategy.forbidTestTodoStubs\",\n configPath,\n issues,\n ),\n },\n traceability: {\n testFileGlobs: readStringArray(\n traceabilityRaw?.testFileGlobs,\n base.traceability.testFileGlobs,\n \"validation.traceability.testFileGlobs\",\n configPath,\n issues,\n ),\n testFileExcludeGlobs: readStringArray(\n traceabilityRaw?.testFileExcludeGlobs,\n base.traceability.testFileExcludeGlobs,\n \"validation.traceability.testFileExcludeGlobs\",\n configPath,\n issues,\n ),\n },\n };\n}\n\nfunction normalizeForbiddenIdentifiers(\n raw: unknown,\n configPath: string,\n issues: Issue[],\n): QfaiForbiddenIdentifier[] | undefined {\n if (raw === undefined) return undefined;\n const invalid = (): undefined => {\n issues.push(configIssue(configPath, \"validation.forbiddenIdentifiers is invalid.\"));\n return undefined;\n };\n if (!Array.isArray(raw) || raw.length > 64) {\n invalid();\n return undefined;\n }\n\n const entries: QfaiForbiddenIdentifier[] = [];\n const pairs = new Set<string>();\n const lengths = new Set<number>();\n for (const entry of raw) {\n if (\n !isRecord(entry) ||\n Object.keys(entry).length !== 2 ||\n Object.keys(entry).some((key) => key !== \"sha256\" && key !== \"byteLength\") ||\n typeof entry.sha256 !== \"string\" ||\n !/^[0-9a-f]{64}$/.test(entry.sha256) ||\n typeof entry.byteLength !== \"number\" ||\n !Number.isInteger(entry.byteLength) ||\n entry.byteLength < 1 ||\n entry.byteLength > 128\n ) {\n invalid();\n return undefined;\n }\n const pair = `${entry.sha256}:${entry.byteLength}`;\n if (pairs.has(pair)) {\n invalid();\n return undefined;\n }\n pairs.add(pair);\n lengths.add(entry.byteLength);\n if (lengths.size > 8) {\n invalid();\n return undefined;\n }\n entries.push({ sha256: entry.sha256, byteLength: entry.byteLength });\n }\n return entries;\n}\n\nfunction normalizeOutput(raw: unknown, configPath: string, issues: Issue[]): QfaiOutputConfig {\n const base = defaultConfig.output;\n if (!raw) {\n return base;\n }\n if (!isRecord(raw)) {\n issues.push(configIssue(configPath, \"output must be an object.\"));\n return base;\n }\n\n return {\n validateJsonPath: readString(\n raw.validateJsonPath,\n base.validateJsonPath,\n \"output.validateJsonPath\",\n configPath,\n issues,\n ),\n };\n}\n\nfunction normalizePrototyping(\n raw: unknown,\n configPath: string,\n issues: Issue[],\n): QfaiPrototypingConfig | undefined {\n if (raw === undefined || raw === null) {\n return undefined;\n }\n if (!isRecord(raw)) {\n issues.push(configIssue(configPath, \"prototyping must be an object.\"));\n return undefined;\n }\n\n const execution = normalizePrototypingExecution(raw.execution, configPath, issues);\n if (Object.prototype.hasOwnProperty.call(raw, \"primarySpecId\")) {\n issues.push(\n configIssue(\n configPath,\n \"prototyping.primarySpecId is retired; use prototyping.primaryUiContract: UI-NNNN.\",\n ),\n );\n }\n const primaryUiContract = normalizePrimaryUiContract(raw.primaryUiContract, configPath, issues);\n if (!execution && primaryUiContract === undefined) {\n return undefined;\n }\n return {\n ...(execution ? { execution } : {}),\n ...(primaryUiContract !== undefined ? { primaryUiContract } : {}),\n };\n}\n\nfunction normalizePrimaryUiContract(\n raw: unknown,\n configPath: string,\n issues: Issue[],\n): string | undefined {\n if (raw === undefined || raw === null) {\n return undefined;\n }\n if (typeof raw !== \"string\" || !/^UI-\\d{4}$/.test(raw)) {\n issues.push(configIssue(configPath, primaryUiContractMessage(raw)));\n return undefined;\n }\n return raw;\n}\n\nfunction primaryUiContractMessage(raw: unknown): string {\n return `prototyping.primaryUiContract must be a full UI-NNNN ID; received ${JSON.stringify(raw)}.`;\n}\n\n/**\n * Why the file's `prototyping.primaryUiContract` was rejected, or `undefined` when the file sets\n * none or the value was accepted. A command that selects the primary UI contract refuses on it,\n * because the loaded config would otherwise fall back to the first UI contract.\n */\nexport function readRejectedPrimaryUiContract(loaded: ConfigLoadResult): string | undefined {\n const prototyping = isRecord(loaded.document) ? loaded.document.prototyping : undefined;\n const raw = isRecord(prototyping) ? prototyping.primaryUiContract : undefined;\n if (raw === undefined || raw === null) return undefined;\n if (loaded.config.prototyping?.primaryUiContract !== undefined) return undefined;\n return primaryUiContractMessage(raw);\n}\n\nfunction normalizePrototypingExecution(\n raw: unknown,\n configPath: string,\n issues: Issue[],\n): NonNullable<QfaiPrototypingConfig[\"execution\"]> | undefined {\n const base = defaultConfig.prototyping?.execution;\n if (raw === undefined || raw === null) {\n return base ? { ...base } : undefined;\n }\n if (!isRecord(raw)) {\n issues.push(configIssue(configPath, \"prototyping.execution must be an object.\"));\n return base ? { ...base } : undefined;\n }\n\n const browserToolRaw = raw.browserTool;\n const browserTool = \"playwright\";\n if (browserToolRaw !== undefined && browserToolRaw !== browserTool) {\n // `browserTool` keeps its `playwright` default, so a run that ignores the\n // issue proceeds against the supported launcher.\n issues.push(\n configIssue(\n configPath,\n `prototyping.execution.browserTool must be \"playwright\".` +\n ` Received: ${JSON.stringify(browserToolRaw)}`,\n ),\n );\n }\n\n return {\n targetUrl:\n raw.targetUrl === null\n ? null\n : (readOptionalString(\n raw.targetUrl,\n \"prototyping.execution.targetUrl\",\n configPath,\n issues,\n ) ?? null),\n browserTool,\n };\n}\n\nfunction readNonNegativeInteger(\n raw: unknown,\n field: string,\n configPath: string,\n issues: Issue[],\n): number | undefined {\n if (typeof raw === \"number\" && Number.isFinite(raw) && Number.isInteger(raw) && raw >= 0) {\n return raw;\n }\n issues.push(configIssue(configPath, `${field} must be an integer greater than or equal to 0.`));\n return undefined;\n}\n\nfunction normalizeReport(\n raw: unknown,\n configPath: string,\n issues: Issue[],\n): QfaiReportConfig | undefined {\n if (raw === undefined || raw === null) {\n return undefined;\n }\n if (!isRecord(raw)) {\n issues.push(configIssue(configPath, \"report must be an object.\"));\n return undefined;\n }\n const result: QfaiReportConfig = {};\n if (raw.staleTtlDays !== undefined) {\n const value = readNonNegativeInteger(\n raw.staleTtlDays,\n \"report.staleTtlDays\",\n configPath,\n issues,\n );\n if (value !== undefined) {\n result.staleTtlDays = value;\n }\n }\n if (raw.keepLatestRuns !== undefined) {\n const value = readNonNegativeInteger(\n raw.keepLatestRuns,\n \"report.keepLatestRuns\",\n configPath,\n issues,\n );\n if (value !== undefined) {\n result.keepLatestRuns = value;\n }\n }\n return Object.keys(result).length === 0 ? undefined : result;\n}\n\nfunction readString(\n value: unknown,\n fallback: string,\n label: string,\n configPath: string,\n issues: Issue[],\n): string {\n if (typeof value === \"string\" && value.trim().length > 0) {\n return value;\n }\n if (value !== undefined) {\n issues.push(configIssue(configPath, `${label} must be a string.`));\n }\n return fallback;\n}\n\n/**\n * A configured directory, with any trailing separators removed.\n *\n * Readers use these values two ways: joined with a child path, where a trailing\n * separator is harmless, and tested as a prefix, where it is not. `\".qfai/spec/\"`\n * builds the prefix `\".qfai/spec//\"`, which no repository path starts with, so a\n * gate keyed on it selects nothing and reports a pass over an empty set. Settling\n * the spelling here is what stops one reader from working on a value another\n * silently drops.\n *\n * A value that is only separators keeps what was written: trimming it to the\n * empty string would silently retarget the reader at the repository root.\n */\nfunction readDirString(\n value: unknown,\n fallback: string,\n label: string,\n configPath: string,\n issues: Issue[],\n): string {\n const raw = readString(value, fallback, label, configPath, issues);\n const trimmed = raw.replace(/[\\\\/]+$/, \"\");\n return trimmed.length > 0 ? trimmed : raw;\n}\n\n/**\n * A story-tree root, with every backslash read as `/` on every platform.\n *\n * The shipped document-schema checker reads these two keys itself, without\n * loading the configuration module, and takes a backslash as a separator. Folding here as well keeps\n * `qfai validate` and that checker on one directory for one value: on Linux and\n * macOS the platform's own path rules would otherwise read `.qfai\\spec` as a\n * single directory name.\n */\nfunction readTreeDirString(\n value: unknown,\n fallback: string,\n label: string,\n configPath: string,\n issues: Issue[],\n): string {\n return readDirString(value, fallback, label, configPath, issues).replace(/\\\\/g, \"/\");\n}\n\n/**\n * `paths.deliberationDir`, kept only where it names a directory inside the project root.\n *\n * The graph keeps deliberation records out of its document corpus by excluding this\n * directory. The root itself, or a directory outside it, leaves nothing to exclude, so\n * such a value is reported and the default is kept.\n */\nfunction readDeliberationDir(\n value: unknown,\n fallback: string,\n configPath: string,\n issues: Issue[],\n): string {\n const dir = readTreeDirString(value, fallback, \"paths.deliberationDir\", configPath, issues);\n if (isDirectoryInsideRoot(path.dirname(configPath), dir)) return dir;\n issues.push(configIssue(configPath, DELIBERATION_DIR_OUTSIDE_ROOT_MESSAGE));\n return fallback;\n}\n\nexport const DELIBERATION_DIR_OUTSIDE_ROOT_MESSAGE =\n \"paths.deliberationDir must name a directory inside the project root, not the root itself or a directory outside it, and no part of it may end in a dot or a space.\";\n\n/**\n * Whether `dir`, read against `root`, names a directory strictly inside `root`.\n *\n * A part that ends in a dot or a space, such as `...` or `docs.`, is refused: Windows drops\n * those characters, so `...` would land in the root while this check reads it as a child.\n */\nexport function isDirectoryInsideRoot(root: string, dir: string): boolean {\n const relative = path.relative(root, path.resolve(root, dir));\n return (\n !dir.split(/[\\\\/]/).some((part) => part !== \".\" && part !== \"..\" && /[. ]$/.test(part)) &&\n relative !== \"\" &&\n relative !== \"..\" &&\n !relative.startsWith(`..${path.sep}`) &&\n !path.isAbsolute(relative)\n );\n}\n\nfunction readOptionalString(\n value: unknown,\n label: string,\n configPath: string,\n issues: Issue[],\n): string | undefined {\n if (value === undefined) {\n return undefined;\n }\n if (typeof value === \"string\" && value.trim().length > 0) {\n return value;\n }\n issues.push(configIssue(configPath, `${label} must be a non-empty string.`));\n return undefined;\n}\n\nfunction readStringArray(\n value: unknown,\n fallback: string[],\n label: string,\n configPath: string,\n issues: Issue[],\n): string[] {\n if (Array.isArray(value) && value.every((item) => typeof item === \"string\")) {\n return value;\n }\n if (value !== undefined) {\n issues.push(configIssue(configPath, `${label} must be an array of strings.`));\n }\n return fallback;\n}\n\nfunction readDiagramBudget(\n value: unknown,\n configPath: string,\n issues: Issue[],\n): Partial<DiagramBudget> | undefined {\n if (value === undefined) {\n return undefined;\n }\n if (!isRecord(value)) {\n issues.push(configIssue(configPath, \"validation.diagramBudget must be an object.\"));\n return undefined;\n }\n for (const key of Object.keys(value)) {\n if (key !== \"nodes\" && key !== \"edges\") {\n issues.push(configIssue(configPath, `validation.diagramBudget.${key} is not a setting.`));\n }\n }\n const budget: Partial<DiagramBudget> = {};\n for (const key of [\"nodes\", \"edges\"] as const) {\n const limit = value[key];\n if (limit === undefined) {\n continue;\n }\n if (typeof limit === \"number\" && Number.isInteger(limit) && limit >= 1) {\n budget[key] = limit;\n } else {\n issues.push(\n configIssue(configPath, `validation.diagramBudget.${key} must be an integer of 1 or more.`),\n );\n }\n }\n return budget;\n}\n\nfunction readBoolean(\n value: unknown,\n fallback: boolean,\n label: string,\n configPath: string,\n issues: Issue[],\n): boolean {\n if (typeof value === \"boolean\") {\n return value;\n }\n if (value !== undefined) {\n issues.push(configIssue(configPath, `${label} must be a boolean.`));\n }\n return fallback;\n}\n\nfunction readFailOn(\n value: unknown,\n fallback: FailOn,\n label: string,\n configPath: string,\n issues: Issue[],\n): FailOn {\n if (value === \"never\" || value === \"warning\" || value === \"error\") {\n return value;\n }\n if (value !== undefined) {\n issues.push(configIssue(configPath, `${label} must be one of never|warning|error.`));\n }\n return fallback;\n}\n\n/**\n * `validation.traceability` keys no validator reads. The migration from the\n * spec-pack layout recognises the finding for each one that is still present,\n * and `QFAI-CFG-001` reports it until the key is deleted.\n */\nconst RETIRED_TRACEABILITY_KEYS = [\"scMustHaveTest\", \"unknownContractIdSeverity\"] as const;\n\nfunction reportRetiredTraceabilityKeys(\n traceabilityRaw: Record<string, unknown> | undefined,\n configPath: string,\n issues: Issue[],\n): void {\n if (!traceabilityRaw) {\n return;\n }\n for (const key of RETIRED_TRACEABILITY_KEYS) {\n if (traceabilityRaw[key] === undefined) {\n continue;\n }\n issues.push(\n configDeprecatedIssue(\n configPath,\n `validation.traceability.${key} is retired.` +\n ` No check reads it, so setting it changes nothing.` +\n ` Remove it from qfai.config.yaml.`,\n ),\n );\n }\n}\n\nfunction normalizeUiux(\n raw: unknown,\n configPath: string,\n issues: Issue[],\n): QfaiUiuxConfig | undefined {\n if (raw === undefined || raw === null) {\n return undefined;\n }\n if (!isRecord(raw)) {\n issues.push(configIssue(configPath, \"uiux must be an object.\"));\n return undefined;\n }\n const result: QfaiUiuxConfig = {};\n if (raw.platform !== undefined) {\n if (typeof raw.platform === \"string\" && raw.platform.trim().length > 0) {\n result.platform = raw.platform;\n } else {\n issues.push(configIssue(configPath, \"uiux.platform must be a non-empty string.\"));\n }\n }\n if (raw.designTokensDir !== undefined) {\n if (typeof raw.designTokensDir === \"string\" && raw.designTokensDir.trim().length > 0) {\n result.designTokensDir = raw.designTokensDir;\n } else {\n issues.push(configIssue(configPath, \"uiux.designTokensDir must be a non-empty string.\"));\n }\n }\n if (raw.htmlMockTimeout !== undefined) {\n if (\n typeof raw.htmlMockTimeout === \"number\" &&\n Number.isFinite(raw.htmlMockTimeout) &&\n raw.htmlMockTimeout > 0\n ) {\n result.htmlMockTimeout = raw.htmlMockTimeout;\n } else {\n issues.push(configIssue(configPath, \"uiux.htmlMockTimeout must be a positive number.\"));\n }\n }\n if (raw.qualityProfile !== undefined) {\n if (\n typeof raw.qualityProfile === \"string\" &&\n [\"strict\", \"high\", \"default\"].includes(raw.qualityProfile)\n ) {\n result.qualityProfile = raw.qualityProfile as \"strict\" | \"high\" | \"default\";\n } else {\n issues.push(\n configIssue(configPath, \"uiux.qualityProfile must be one of strict|high|default.\"),\n );\n }\n }\n if (raw.surfacePaths !== undefined) {\n const surfacePaths = raw.surfacePaths;\n if (\n Array.isArray(surfacePaths) &&\n surfacePaths.every(\n (entry: unknown): entry is string => typeof entry === \"string\" && entry.trim().length > 0,\n )\n ) {\n result.surfacePaths = surfacePaths.map((entry) => entry.trim());\n } else {\n issues.push(\n configIssue(configPath, \"uiux.surfacePaths must be a list of non-empty glob strings.\"),\n );\n }\n }\n if (raw.registries !== undefined) {\n const registries = normalizeUiuxRegistries(raw.registries, configPath, issues);\n if (registries) {\n result.registries = registries;\n }\n }\n if (raw.audit !== undefined) {\n const audit = normalizeUiuxAudit(raw.audit, configPath, issues);\n if (audit) {\n result.audit = audit;\n }\n }\n return Object.keys(result).length > 0 ? result : undefined;\n}\n\n/**\n * A registry entry resolves one component name, so the template has to say\n * where the name goes. A URL without the placeholder resolves nothing and is\n * the typo this catches; everything else about the URL is the registry's\n * business, including its scheme, because a private one may sit on localhost.\n */\nfunction normalizeUiuxRegistries(\n raw: unknown,\n configPath: string,\n issues: Issue[],\n): Record<string, string> | undefined {\n if (!isRecord(raw)) {\n issues.push(configIssue(configPath, \"uiux.registries must be an object.\"));\n return undefined;\n }\n const result: Record<string, string> = {};\n for (const [name, url] of Object.entries(raw)) {\n if (typeof url !== \"string\" || url.trim().length === 0) {\n issues.push(configIssue(configPath, `uiux.registries.${name} must be a non-empty string.`));\n continue;\n }\n if (!url.includes(\"{name}\")) {\n issues.push(\n configIssue(\n configPath,\n `uiux.registries.${name} must contain the {name} placeholder, or it resolves no component.`,\n ),\n );\n continue;\n }\n result[name] = url;\n }\n return Object.keys(result).length > 0 ? result : undefined;\n}\n\nfunction normalizeUiuxAudit(\n raw: unknown,\n configPath: string,\n issues: Issue[],\n): QfaiUiuxAuditConfig | undefined {\n if (!isRecord(raw)) {\n issues.push(configIssue(configPath, \"uiux.audit must be an object.\"));\n return undefined;\n }\n const result: QfaiUiuxAuditConfig = {};\n if (raw.enabled !== undefined) {\n if (typeof raw.enabled === \"boolean\") {\n result.enabled = raw.enabled;\n } else {\n issues.push(configIssue(configPath, \"uiux.audit.enabled must be a boolean.\"));\n }\n }\n if (raw.slopDetection !== undefined) {\n if (typeof raw.slopDetection === \"boolean\") {\n result.slopDetection = raw.slopDetection;\n } else {\n issues.push(configIssue(configPath, \"uiux.audit.slopDetection must be a boolean.\"));\n }\n }\n if (raw.maxRawTokenLiteralWarnings !== undefined) {\n if (\n typeof raw.maxRawTokenLiteralWarnings === \"number\" &&\n Number.isFinite(raw.maxRawTokenLiteralWarnings) &&\n raw.maxRawTokenLiteralWarnings >= 0\n ) {\n result.maxRawTokenLiteralWarnings = raw.maxRawTokenLiteralWarnings;\n } else {\n issues.push(\n configIssue(\n configPath,\n \"uiux.audit.maxRawTokenLiteralWarnings must be a number greater than or equal to 0.\",\n ),\n );\n }\n }\n if (raw.maxDuplicateFindingsPerRule !== undefined) {\n if (\n typeof raw.maxDuplicateFindingsPerRule === \"number\" &&\n Number.isFinite(raw.maxDuplicateFindingsPerRule) &&\n raw.maxDuplicateFindingsPerRule >= 0\n ) {\n result.maxDuplicateFindingsPerRule = raw.maxDuplicateFindingsPerRule;\n } else {\n issues.push(\n configIssue(\n configPath,\n \"uiux.audit.maxDuplicateFindingsPerRule must be a number greater than or equal to 0.\",\n ),\n );\n }\n }\n return Object.keys(result).length > 0 ? result : undefined;\n}\n\nfunction configIssue(file: string, message: string): Issue {\n return {\n code: \"QFAI-CFG-002\",\n severity: \"error\",\n category: \"canonical\",\n message,\n file,\n rule: \"config.invalid\",\n };\n}\n\nfunction configDeprecatedIssue(file: string, message: string): Issue {\n return {\n code: \"QFAI-CFG-001\",\n severity: \"error\",\n category: \"canonical\",\n message,\n file,\n rule: \"config.deprecatedKey\",\n };\n}\n\nasync function exists(target: string): Promise<boolean> {\n try {\n await access(target);\n return true;\n } catch {\n return false;\n }\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return value !== null && typeof value === \"object\" && !Array.isArray(value);\n}\n","/**\n * Shared errno helpers for Node.js fs error narrowing.\n *\n * Avoids ad-hoc `(err as { code?: string }).code === \"ENOENT\"` repetition\n * across init / config / prototyping commands. Future errno codes\n * (`EACCES`, `EBUSY`, `EPERM`, ...) extend this module rather than\n * sprouting new inline checks.\n */\n\n/**\n * True iff `err` is a Node.js fs error whose `code` is `\"ENOENT\"`\n * (file or directory does not exist).\n */\nexport function isEnoent(err: unknown): boolean {\n return hasErrnoCode(err) && err.code === \"ENOENT\";\n}\n\n/**\n * True iff `err` is a Node.js fs error whose `code` is `\"EPERM\"`.\n *\n * On Windows this is what `stat` raises for a **file** symlink whose target is\n * a directory: the link is intact and `readlink` returns the right target, but\n * the reparse tag is the wrong kind and the OS refuses to follow it. `git\n * worktree add` produces exactly that for `.claude/skills/*`, because at the\n * moment git writes the link its target does not yet exist in the new worktree\n * and it has no reftype hint. So a reader that treats EPERM as a filesystem\n * fault to propagate crashes on a condition that is structural damage to the\n * path it is inspecting.\n */\nexport function isEperm(err: unknown): boolean {\n return hasErrnoCode(err) && err.code === \"EPERM\";\n}\n\n/**\n * True iff `err` is a Node.js error-shaped object carrying a string\n * `code` (e.g. `\"ENOENT\"`, `\"EACCES\"`, `\"ENOSPC\"`). Narrowing helper\n * shared across the codebase so individual call sites do not sprout\n * ad-hoc `(err as { code?: string }).code` casts (CLAUDE.md\n * \"avoid bare `as` type assertions; prefer type narrowing\").\n */\nexport function hasErrnoCode(err: unknown): err is { code: string } {\n return (\n err !== null &&\n typeof err === \"object\" &&\n \"code\" in err &&\n typeof (err as { code?: unknown }).code === \"string\"\n );\n}\n","/**\n * The workflow file names this package writes into an adopter's\n * `.github/workflows/` directory.\n *\n * The list is IN-BINARY. It is never computed by globbing the asset\n * tree at runtime or the adopter's disk: a write set derived from whatever\n * happens to be on disk cannot distinguish a file this package ships from one\n * somebody else put there, which is the distinction the whole\n * shipped-workflows contract rests on. The shipped-asset shape gate keeps this\n * list equal to the packaged workflow assets.\n *\n * They live in `shared/` rather than beside the command that writes them\n * because two layers need the same answer: the `init` command, which copies\n * them, and the `doctor` integrity reader, which has to know what a healthy\n * packaged tree contains before it can call a gutted one healthy. `core/` may\n * not import from `cli/`, and a second copy of the list is how the two\n * answers drift apart. `cli/commands/init.ts` re-exports it, so the public\n * surface is unchanged.\n */\n\n/**\n * Names the current package version ships into the adopter's\n * `.github/workflows/` directory (the shipped-workflows contract's write set).\n */\nexport const SHIPPED_WORKFLOW_NAMES: ReadonlySet<string> = new Set<string>([\n \"qfai-validate.yml\",\n \"qfai-tests.yml\",\n \"qfai-docs.yml\",\n]);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qBAA6B;AAC7B,qBAAe;;;ACDf,gCAAoD;AACpD,yBAA2B;AAC3B,IAAAA,mBAAwC;AACxC,IAAAC,oBAAiB;;;ACHjB,sBAAiC;AACjC,uBAAiB;AAEjB,kBAAmC;;;ACU5B,SAAS,SAAS,KAAuB;AAC9C,SAAO,aAAa,GAAG,KAAK,IAAI,SAAS;AAC3C;AAyBO,SAAS,aAAa,KAAuC;AAClE,SACE,QAAQ,QACR,OAAO,QAAQ,YACf,UAAU,OACV,OAAQ,IAA2B,SAAS;AAEhD;;;ACvBO,IAAM,yBAA8C,oBAAI,IAAY;AAAA,EACzE;AAAA,EACA;AAAA,EACA;AACF,CAAC;;;AFwKM,IAAM,gBAA4B;AAAA,EACvC,OAAO;AAAA,IACL,cAAc;AAAA,IACd,UAAU;AAAA,IACV,iBAAiB;AAAA,IACjB,QAAQ;AAAA,IACR,WAAW;AAAA,IACX,QAAQ;AAAA,IACR,UAAU;AAAA,EACZ;AAAA,EACA,YAAY;AAAA,IACV,QAAQ;AAAA,IACR,cAAc;AAAA,MACZ,qBAAqB;AAAA,IACvB;AAAA,IACA,cAAc;AAAA,MACZ,eAAe,CAAC;AAAA,MAChB,sBAAsB,CAAC;AAAA,IACzB;AAAA,EACF;AAAA,EACA,QAAQ;AAAA,IACN,kBAAkB;AAAA,EACpB;AAAA,EACA,aAAa;AAAA,IACX,WAAW;AAAA,MACT,WAAW;AAAA,MACX,aAAa;AAAA,IACf;AAAA,EACF;AACF;AAEO,SAAS,cAAc,MAAsB;AAClD,SAAO,iBAAAC,QAAK,KAAK,MAAM,kBAAkB;AAC3C;AAEA,eAAsB,eAAe,UAA+C;AA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AM,KAAK,YAAY,MAAM,OAAO,IAAI,MAAM;AAAA,MACpE,UAAU,KAAK,wBAAwB;AAAA,EAAuB,KAAK;AAAA,MACnE,MAAM,oBAAoB,iBACtB,yKACA;AAAA,IACN,EAAE,KAAK,MAAM;AACb,WAAO,GAAG,KAAK,UAAU,EAAE,UAAU,SAAS,OAAO,CAAC,CAAC;AAAA;AAAA,EACzD;AACA,MAAI,SAAS,KAAM,WAAM,qBAAG,MAAM,EAAE,OAAO,KAAK,CAAC;AACjD,SAAO;AACT;;;ADxRA,eAAe,OAAsB;AACnC,MAAI;AACF,QAAI;AACJ,QAAI;AACF,cAAQ,KAAK,UAAM,6BAAa,GAAG,MAAM,CAAC;AAAA,IAC5C,QAAQ;AACN,cAAQ;AAAA,IACV;AACA,UAAM,SAAS,MAAM,eAAe,OAAO;AAAA,MACzC,YAAY,QAAQ,IAAI;AAAA,MACxB,UAAU,eAAAE,QAAG,OAAO;AAAA,IACtB,CAAC;AACD,QAAI,WAAW,GAAI,SAAQ,OAAO,MAAM,MAAM;AAAA,EAChD,SAAS,OAAgB;AAEvB,UAAM,UAAU,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AACrE,YAAQ,OAAO,MAAM,sCAAsC,OAAO;AAAA,CAAI;AAAA,EACxE;AACA,UAAQ,WAAW;AACrB;AAIA,KAAK,KAAK;","names":["import_promises","import_node_path","path","parseYaml","path","isRecord","path","os"]}
|
package/dist/hook/turn-end.mjs
CHANGED
|
@@ -33,7 +33,7 @@ var defaultConfig = {
|
|
|
33
33
|
paths: {
|
|
34
34
|
contractsDir: ".qfai/spec/03_contract",
|
|
35
35
|
specsDir: ".qfai/spec",
|
|
36
|
-
|
|
36
|
+
deliberationDir: ".qfai/deliberation",
|
|
37
37
|
outDir: ".qfai/report",
|
|
38
38
|
skillsDir: ".qfai/assistant/skill",
|
|
39
39
|
srcDir: "src",
|
|
@@ -218,10 +218,9 @@ function normalizePaths(raw, configPath, issues) {
|
|
|
218
218
|
issues
|
|
219
219
|
),
|
|
220
220
|
specsDir: readTreeDirString(raw.specsDir, base.specsDir, "paths.specsDir", configPath, issues),
|
|
221
|
-
|
|
222
|
-
raw.
|
|
223
|
-
base.
|
|
224
|
-
"paths.discussionDir",
|
|
221
|
+
deliberationDir: readDeliberationDir(
|
|
222
|
+
raw.deliberationDir,
|
|
223
|
+
base.deliberationDir,
|
|
225
224
|
configPath,
|
|
226
225
|
issues
|
|
227
226
|
),
|
|
@@ -481,6 +480,17 @@ function readDirString(value, fallback, label, configPath, issues) {
|
|
|
481
480
|
function readTreeDirString(value, fallback, label, configPath, issues) {
|
|
482
481
|
return readDirString(value, fallback, label, configPath, issues).replace(/\\/g, "/");
|
|
483
482
|
}
|
|
483
|
+
function readDeliberationDir(value, fallback, configPath, issues) {
|
|
484
|
+
const dir = readTreeDirString(value, fallback, "paths.deliberationDir", configPath, issues);
|
|
485
|
+
if (isDirectoryInsideRoot(path.dirname(configPath), dir)) return dir;
|
|
486
|
+
issues.push(configIssue(configPath, DELIBERATION_DIR_OUTSIDE_ROOT_MESSAGE));
|
|
487
|
+
return fallback;
|
|
488
|
+
}
|
|
489
|
+
var DELIBERATION_DIR_OUTSIDE_ROOT_MESSAGE = "paths.deliberationDir must name a directory inside the project root, not the root itself or a directory outside it, and no part of it may end in a dot or a space.";
|
|
490
|
+
function isDirectoryInsideRoot(root, dir) {
|
|
491
|
+
const relative = path.relative(root, path.resolve(root, dir));
|
|
492
|
+
return !dir.split(/[\\/]/).some((part) => part !== "." && part !== ".." && /[. ]$/.test(part)) && relative !== "" && relative !== ".." && !relative.startsWith(`..${path.sep}`) && !path.isAbsolute(relative);
|
|
493
|
+
}
|
|
484
494
|
function readOptionalString(value, label, configPath, issues) {
|
|
485
495
|
if (value === void 0) {
|
|
486
496
|
return void 0;
|
|
@@ -603,34 +613,6 @@ function normalizeUiux(raw, configPath, issues) {
|
|
|
603
613
|
);
|
|
604
614
|
}
|
|
605
615
|
}
|
|
606
|
-
if (raw.requireResearchSummary !== void 0) {
|
|
607
|
-
if (typeof raw.requireResearchSummary === "boolean") {
|
|
608
|
-
result.requireResearchSummary = raw.requireResearchSummary;
|
|
609
|
-
} else {
|
|
610
|
-
issues.push(configIssue(configPath, "uiux.requireResearchSummary must be a boolean."));
|
|
611
|
-
}
|
|
612
|
-
}
|
|
613
|
-
if (raw.competitive_refs_min !== void 0) {
|
|
614
|
-
if (typeof raw.competitive_refs_min === "number" && Number.isInteger(raw.competitive_refs_min) && raw.competitive_refs_min >= 0) {
|
|
615
|
-
result.competitive_refs_min = raw.competitive_refs_min;
|
|
616
|
-
} else {
|
|
617
|
-
issues.push(
|
|
618
|
-
configIssue(
|
|
619
|
-
configPath,
|
|
620
|
-
"uiux.competitive_refs_min must be an integer greater than or equal to 0."
|
|
621
|
-
)
|
|
622
|
-
);
|
|
623
|
-
}
|
|
624
|
-
}
|
|
625
|
-
if (raw.catalogue_refs_min !== void 0) {
|
|
626
|
-
if (typeof raw.catalogue_refs_min === "number" && Number.isInteger(raw.catalogue_refs_min) && raw.catalogue_refs_min >= 0) {
|
|
627
|
-
result.catalogue_refs_min = raw.catalogue_refs_min;
|
|
628
|
-
} else {
|
|
629
|
-
issues.push(
|
|
630
|
-
configIssue(configPath, "uiux.catalogue_refs_min must be an integer of 0 or more.")
|
|
631
|
-
);
|
|
632
|
-
}
|
|
633
|
-
}
|
|
634
616
|
if (raw.surfacePaths !== void 0) {
|
|
635
617
|
const surfacePaths = raw.surfacePaths;
|
|
636
618
|
if (Array.isArray(surfacePaths) && surfacePaths.every(
|
|
@@ -701,18 +683,6 @@ function normalizeUiuxAudit(raw, configPath, issues) {
|
|
|
701
683
|
issues.push(configIssue(configPath, "uiux.audit.slopDetection must be a boolean."));
|
|
702
684
|
}
|
|
703
685
|
}
|
|
704
|
-
if (raw.maxPrimaryCtas !== void 0) {
|
|
705
|
-
if (typeof raw.maxPrimaryCtas === "number" && Number.isFinite(raw.maxPrimaryCtas) && raw.maxPrimaryCtas >= 0) {
|
|
706
|
-
result.maxPrimaryCtas = raw.maxPrimaryCtas;
|
|
707
|
-
} else {
|
|
708
|
-
issues.push(
|
|
709
|
-
configIssue(
|
|
710
|
-
configPath,
|
|
711
|
-
"uiux.audit.maxPrimaryCtas must be a number greater than or equal to 0."
|
|
712
|
-
)
|
|
713
|
-
);
|
|
714
|
-
}
|
|
715
|
-
}
|
|
716
686
|
if (raw.maxRawTokenLiteralWarnings !== void 0) {
|
|
717
687
|
if (typeof raw.maxRawTokenLiteralWarnings === "number" && Number.isFinite(raw.maxRawTokenLiteralWarnings) && raw.maxRawTokenLiteralWarnings >= 0) {
|
|
718
688
|
result.maxRawTokenLiteralWarnings = raw.maxRawTokenLiteralWarnings;
|