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/graph/cli.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// src/core/graph/codePreparation.ts
|
|
2
2
|
import { randomUUID as randomUUID3 } from "crypto";
|
|
3
|
-
import { mkdir as
|
|
4
|
-
import
|
|
3
|
+
import { mkdir as mkdir5, rm as rm4 } from "fs/promises";
|
|
4
|
+
import path10 from "path";
|
|
5
5
|
|
|
6
6
|
// src/shared/assets.ts
|
|
7
7
|
import { existsSync } from "fs";
|
|
@@ -263,13 +263,13 @@ var runGraphProcess = async (command, args, options) => {
|
|
|
263
263
|
|
|
264
264
|
// src/core/graph/reuse.ts
|
|
265
265
|
import os from "os";
|
|
266
|
-
import
|
|
266
|
+
import path9 from "path";
|
|
267
267
|
import { randomUUID as randomUUID2 } from "crypto";
|
|
268
268
|
import {
|
|
269
269
|
cp,
|
|
270
|
-
lstat as
|
|
271
|
-
mkdir as
|
|
272
|
-
readFile,
|
|
270
|
+
lstat as lstat6,
|
|
271
|
+
mkdir as mkdir4,
|
|
272
|
+
readFile as readFile3,
|
|
273
273
|
readdir as readdir3,
|
|
274
274
|
realpath as realpath2,
|
|
275
275
|
rename as rename2,
|
|
@@ -278,8 +278,798 @@ import {
|
|
|
278
278
|
} from "fs/promises";
|
|
279
279
|
|
|
280
280
|
// src/core/graph/analysis.ts
|
|
281
|
+
import path8 from "path";
|
|
282
|
+
import { copyFile, lstat as lstat5, mkdir as mkdir3, readdir as readdir2, rm as rm2 } from "fs/promises";
|
|
283
|
+
|
|
284
|
+
// src/core/config.ts
|
|
285
|
+
import { access as access2, readFile } from "fs/promises";
|
|
281
286
|
import path5 from "path";
|
|
282
|
-
import {
|
|
287
|
+
import { parse as parseYaml } from "yaml";
|
|
288
|
+
|
|
289
|
+
// src/shared/shippedWorkflowNames.ts
|
|
290
|
+
var SHIPPED_WORKFLOW_NAMES = /* @__PURE__ */ new Set([
|
|
291
|
+
"qfai-validate.yml",
|
|
292
|
+
"qfai-tests.yml",
|
|
293
|
+
"qfai-docs.yml"
|
|
294
|
+
]);
|
|
295
|
+
|
|
296
|
+
// src/core/config.ts
|
|
297
|
+
var defaultConfig = {
|
|
298
|
+
paths: {
|
|
299
|
+
contractsDir: ".qfai/spec/03_contract",
|
|
300
|
+
specsDir: ".qfai/spec",
|
|
301
|
+
deliberationDir: ".qfai/deliberation",
|
|
302
|
+
outDir: ".qfai/report",
|
|
303
|
+
skillsDir: ".qfai/assistant/skill",
|
|
304
|
+
srcDir: "src",
|
|
305
|
+
testsDir: "tests"
|
|
306
|
+
},
|
|
307
|
+
validation: {
|
|
308
|
+
failOn: "error",
|
|
309
|
+
testStrategy: {
|
|
310
|
+
forbidTestTodoStubs: true
|
|
311
|
+
},
|
|
312
|
+
traceability: {
|
|
313
|
+
testFileGlobs: [],
|
|
314
|
+
testFileExcludeGlobs: []
|
|
315
|
+
}
|
|
316
|
+
},
|
|
317
|
+
output: {
|
|
318
|
+
validateJsonPath: ".qfai/report/validate.json"
|
|
319
|
+
},
|
|
320
|
+
prototyping: {
|
|
321
|
+
execution: {
|
|
322
|
+
targetUrl: null,
|
|
323
|
+
browserTool: "playwright"
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
};
|
|
327
|
+
function getConfigPath(root) {
|
|
328
|
+
return path5.join(root, "qfai.config.yaml");
|
|
329
|
+
}
|
|
330
|
+
async function loadConfig(root) {
|
|
331
|
+
const configPath = getConfigPath(root);
|
|
332
|
+
const issues = [];
|
|
333
|
+
let parsed;
|
|
334
|
+
try {
|
|
335
|
+
const raw = await readFile(configPath, "utf-8");
|
|
336
|
+
parsed = parseYaml(raw);
|
|
337
|
+
} catch (error) {
|
|
338
|
+
if (isEnoent(error)) {
|
|
339
|
+
return { config: defaultConfig, issues, configPath };
|
|
340
|
+
}
|
|
341
|
+
issues.push(configIssue(configPath, "The configuration file could not be read or parsed."));
|
|
342
|
+
return { config: defaultConfig, issues, configPath };
|
|
343
|
+
}
|
|
344
|
+
const normalized = normalizeConfig(parsed, configPath, issues);
|
|
345
|
+
if (readWorkflowMode(parsed) === null) {
|
|
346
|
+
issues.push(configIssue(configPath, WORKFLOW_MODE_MESSAGE));
|
|
347
|
+
}
|
|
348
|
+
if (readSkippedWorkflows(parsed) === null) {
|
|
349
|
+
issues.push(configIssue(configPath, SKIPPED_WORKFLOWS_MESSAGE));
|
|
350
|
+
}
|
|
351
|
+
if (readAcceptedDrift(parsed) === null) {
|
|
352
|
+
issues.push(configIssue(configPath, ACCEPTED_DRIFT_MESSAGE));
|
|
353
|
+
}
|
|
354
|
+
if (readStopGate(parsed) === null) {
|
|
355
|
+
issues.push(configIssue(configPath, STOP_GATE_MESSAGE));
|
|
356
|
+
}
|
|
357
|
+
return { config: normalized, issues, configPath, document: parsed };
|
|
358
|
+
}
|
|
359
|
+
var STOP_GATE_MESSAGE = "workflow.stopGate must be true or false; an absent key means true.";
|
|
360
|
+
function readStopGate(document) {
|
|
361
|
+
const workflow = isRecord(document) ? document.workflow : void 0;
|
|
362
|
+
if (workflow === void 0) return true;
|
|
363
|
+
if (!isRecord(workflow)) return null;
|
|
364
|
+
if (workflow.stopGate === void 0) return true;
|
|
365
|
+
return typeof workflow.stopGate === "boolean" ? workflow.stopGate : null;
|
|
366
|
+
}
|
|
367
|
+
var WORKFLOW_MODES = ["active", "shadow", "off"];
|
|
368
|
+
var WORKFLOW_MODE_MESSAGE = "workflow.mode must be active, shadow or off; an absent key means active.";
|
|
369
|
+
function readWorkflowMode(document) {
|
|
370
|
+
const workflow = isRecord(document) ? document.workflow : void 0;
|
|
371
|
+
if (workflow === void 0) return "active";
|
|
372
|
+
if (!isRecord(workflow)) return null;
|
|
373
|
+
const mode = workflow.mode;
|
|
374
|
+
if (mode === void 0) return "active";
|
|
375
|
+
return WORKFLOW_MODES.find((known) => known === mode) ?? null;
|
|
376
|
+
}
|
|
377
|
+
var 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.`;
|
|
378
|
+
function readSkippedWorkflows(document) {
|
|
379
|
+
const workflow = isRecord(document) ? document.workflow : void 0;
|
|
380
|
+
if (!isRecord(workflow) || workflow.skipShipped === void 0) return /* @__PURE__ */ new Set();
|
|
381
|
+
const listed = workflow.skipShipped;
|
|
382
|
+
if (!Array.isArray(listed)) return null;
|
|
383
|
+
const names = /* @__PURE__ */ new Set();
|
|
384
|
+
for (const name of listed) {
|
|
385
|
+
if (typeof name !== "string" || !SHIPPED_WORKFLOW_NAMES.has(name)) return null;
|
|
386
|
+
names.add(name);
|
|
387
|
+
}
|
|
388
|
+
return names;
|
|
389
|
+
}
|
|
390
|
+
var 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.`;
|
|
391
|
+
var DRIFT_DIGEST = /^sha256:[0-9a-f]{64}$/;
|
|
392
|
+
function readAcceptedDrift(document) {
|
|
393
|
+
const workflow = isRecord(document) ? document.workflow : void 0;
|
|
394
|
+
if (!isRecord(workflow) || workflow.acceptedDrift === void 0) return /* @__PURE__ */ new Map();
|
|
395
|
+
const listed = workflow.acceptedDrift;
|
|
396
|
+
if (!Array.isArray(listed)) return null;
|
|
397
|
+
const accepted = /* @__PURE__ */ new Map();
|
|
398
|
+
for (const entry of listed) {
|
|
399
|
+
if (!isRecord(entry)) return null;
|
|
400
|
+
const { file, digest, reason } = entry;
|
|
401
|
+
if (typeof file !== "string" || !SHIPPED_WORKFLOW_NAMES.has(file) || accepted.has(file)) {
|
|
402
|
+
return null;
|
|
403
|
+
}
|
|
404
|
+
if (typeof digest !== "string" || !DRIFT_DIGEST.test(digest)) return null;
|
|
405
|
+
if (typeof reason !== "string" || reason.trim() === "") return null;
|
|
406
|
+
accepted.set(file, { digest, reason: reason.trim() });
|
|
407
|
+
}
|
|
408
|
+
return accepted;
|
|
409
|
+
}
|
|
410
|
+
function resolvePath(root, config, key) {
|
|
411
|
+
return path5.resolve(root, config.paths[key]);
|
|
412
|
+
}
|
|
413
|
+
function normalizeConfig(raw, configPath, issues) {
|
|
414
|
+
if (!isRecord(raw)) {
|
|
415
|
+
issues.push(configIssue(configPath, "The configuration file format is invalid."));
|
|
416
|
+
return defaultConfig;
|
|
417
|
+
}
|
|
418
|
+
const uiux = normalizeUiux(raw.uiux, configPath, issues);
|
|
419
|
+
const prototyping = normalizePrototyping(raw.prototyping, configPath, issues);
|
|
420
|
+
const report = normalizeReport(raw.report, configPath, issues);
|
|
421
|
+
const base = {
|
|
422
|
+
paths: normalizePaths(raw.paths, configPath, issues),
|
|
423
|
+
validation: normalizeValidation(raw.validation, configPath, issues),
|
|
424
|
+
output: normalizeOutput(raw.output, configPath, issues)
|
|
425
|
+
};
|
|
426
|
+
if (uiux) {
|
|
427
|
+
base.uiux = uiux;
|
|
428
|
+
}
|
|
429
|
+
if (prototyping) {
|
|
430
|
+
base.prototyping = prototyping;
|
|
431
|
+
}
|
|
432
|
+
if (report) {
|
|
433
|
+
base.report = report;
|
|
434
|
+
}
|
|
435
|
+
const baseBranch = readOptionalString(raw.baseBranch, "baseBranch", configPath, issues);
|
|
436
|
+
if (baseBranch !== void 0) {
|
|
437
|
+
base.baseBranch = baseBranch;
|
|
438
|
+
}
|
|
439
|
+
return base;
|
|
440
|
+
}
|
|
441
|
+
function normalizePaths(raw, configPath, issues) {
|
|
442
|
+
const base = defaultConfig.paths;
|
|
443
|
+
if (!raw) {
|
|
444
|
+
return base;
|
|
445
|
+
}
|
|
446
|
+
if (!isRecord(raw)) {
|
|
447
|
+
issues.push(configIssue(configPath, "paths must be an object."));
|
|
448
|
+
return base;
|
|
449
|
+
}
|
|
450
|
+
const migrationsDir = readOptionalString(
|
|
451
|
+
raw.migrationsDir,
|
|
452
|
+
"paths.migrationsDir",
|
|
453
|
+
configPath,
|
|
454
|
+
issues
|
|
455
|
+
);
|
|
456
|
+
return {
|
|
457
|
+
...migrationsDir !== void 0 ? { migrationsDir } : {},
|
|
458
|
+
contractsDir: readTreeDirString(
|
|
459
|
+
raw.contractsDir,
|
|
460
|
+
base.contractsDir,
|
|
461
|
+
"paths.contractsDir",
|
|
462
|
+
configPath,
|
|
463
|
+
issues
|
|
464
|
+
),
|
|
465
|
+
specsDir: readTreeDirString(raw.specsDir, base.specsDir, "paths.specsDir", configPath, issues),
|
|
466
|
+
deliberationDir: readDeliberationDir(
|
|
467
|
+
raw.deliberationDir,
|
|
468
|
+
base.deliberationDir,
|
|
469
|
+
configPath,
|
|
470
|
+
issues
|
|
471
|
+
),
|
|
472
|
+
outDir: readDirString(raw.outDir, base.outDir, "paths.outDir", configPath, issues),
|
|
473
|
+
skillsDir: readDirString(raw.skillsDir, base.skillsDir, "paths.skillsDir", configPath, issues),
|
|
474
|
+
srcDir: readDirString(raw.srcDir, base.srcDir, "paths.srcDir", configPath, issues),
|
|
475
|
+
testsDir: readDirString(raw.testsDir, base.testsDir, "paths.testsDir", configPath, issues)
|
|
476
|
+
};
|
|
477
|
+
}
|
|
478
|
+
function normalizeValidation(raw, configPath, issues) {
|
|
479
|
+
const base = defaultConfig.validation;
|
|
480
|
+
if (!raw) {
|
|
481
|
+
return base;
|
|
482
|
+
}
|
|
483
|
+
if (!isRecord(raw)) {
|
|
484
|
+
issues.push(configIssue(configPath, "validation must be an object."));
|
|
485
|
+
return base;
|
|
486
|
+
}
|
|
487
|
+
let traceabilityRaw;
|
|
488
|
+
if (raw.traceability === void 0) {
|
|
489
|
+
traceabilityRaw = void 0;
|
|
490
|
+
} else if (isRecord(raw.traceability)) {
|
|
491
|
+
traceabilityRaw = raw.traceability;
|
|
492
|
+
} else {
|
|
493
|
+
issues.push(configIssue(configPath, "validation.traceability must be an object."));
|
|
494
|
+
traceabilityRaw = void 0;
|
|
495
|
+
}
|
|
496
|
+
let testStrategyRaw;
|
|
497
|
+
if (raw.testStrategy === void 0) {
|
|
498
|
+
testStrategyRaw = void 0;
|
|
499
|
+
} else if (isRecord(raw.testStrategy)) {
|
|
500
|
+
testStrategyRaw = raw.testStrategy;
|
|
501
|
+
} else {
|
|
502
|
+
issues.push(configIssue(configPath, "validation.testStrategy must be an object."));
|
|
503
|
+
testStrategyRaw = void 0;
|
|
504
|
+
}
|
|
505
|
+
reportRetiredTraceabilityKeys(traceabilityRaw, configPath, issues);
|
|
506
|
+
const forbiddenIdentifiers = normalizeForbiddenIdentifiers(
|
|
507
|
+
raw.forbiddenIdentifiers,
|
|
508
|
+
configPath,
|
|
509
|
+
issues
|
|
510
|
+
);
|
|
511
|
+
const staleTerms = readStringArray(
|
|
512
|
+
raw.staleTerms,
|
|
513
|
+
[],
|
|
514
|
+
"validation.staleTerms",
|
|
515
|
+
configPath,
|
|
516
|
+
issues
|
|
517
|
+
);
|
|
518
|
+
const diagramBudget = readDiagramBudget(raw.diagramBudget, configPath, issues);
|
|
519
|
+
return {
|
|
520
|
+
failOn: readFailOn(raw.failOn, base.failOn, "validation.failOn", configPath, issues),
|
|
521
|
+
...staleTerms.length > 0 ? { staleTerms } : {},
|
|
522
|
+
...diagramBudget !== void 0 ? { diagramBudget } : {},
|
|
523
|
+
...forbiddenIdentifiers !== void 0 ? { forbiddenIdentifiers } : {},
|
|
524
|
+
testStrategy: {
|
|
525
|
+
forbidTestTodoStubs: readBoolean(
|
|
526
|
+
testStrategyRaw?.forbidTestTodoStubs,
|
|
527
|
+
base.testStrategy.forbidTestTodoStubs,
|
|
528
|
+
"validation.testStrategy.forbidTestTodoStubs",
|
|
529
|
+
configPath,
|
|
530
|
+
issues
|
|
531
|
+
)
|
|
532
|
+
},
|
|
533
|
+
traceability: {
|
|
534
|
+
testFileGlobs: readStringArray(
|
|
535
|
+
traceabilityRaw?.testFileGlobs,
|
|
536
|
+
base.traceability.testFileGlobs,
|
|
537
|
+
"validation.traceability.testFileGlobs",
|
|
538
|
+
configPath,
|
|
539
|
+
issues
|
|
540
|
+
),
|
|
541
|
+
testFileExcludeGlobs: readStringArray(
|
|
542
|
+
traceabilityRaw?.testFileExcludeGlobs,
|
|
543
|
+
base.traceability.testFileExcludeGlobs,
|
|
544
|
+
"validation.traceability.testFileExcludeGlobs",
|
|
545
|
+
configPath,
|
|
546
|
+
issues
|
|
547
|
+
)
|
|
548
|
+
}
|
|
549
|
+
};
|
|
550
|
+
}
|
|
551
|
+
function normalizeForbiddenIdentifiers(raw, configPath, issues) {
|
|
552
|
+
if (raw === void 0) return void 0;
|
|
553
|
+
const invalid = () => {
|
|
554
|
+
issues.push(configIssue(configPath, "validation.forbiddenIdentifiers is invalid."));
|
|
555
|
+
return void 0;
|
|
556
|
+
};
|
|
557
|
+
if (!Array.isArray(raw) || raw.length > 64) {
|
|
558
|
+
invalid();
|
|
559
|
+
return void 0;
|
|
560
|
+
}
|
|
561
|
+
const entries = [];
|
|
562
|
+
const pairs = /* @__PURE__ */ new Set();
|
|
563
|
+
const lengths = /* @__PURE__ */ new Set();
|
|
564
|
+
for (const entry of raw) {
|
|
565
|
+
if (!isRecord(entry) || Object.keys(entry).length !== 2 || Object.keys(entry).some((key) => key !== "sha256" && key !== "byteLength") || typeof entry.sha256 !== "string" || !/^[0-9a-f]{64}$/.test(entry.sha256) || typeof entry.byteLength !== "number" || !Number.isInteger(entry.byteLength) || entry.byteLength < 1 || entry.byteLength > 128) {
|
|
566
|
+
invalid();
|
|
567
|
+
return void 0;
|
|
568
|
+
}
|
|
569
|
+
const pair = `${entry.sha256}:${entry.byteLength}`;
|
|
570
|
+
if (pairs.has(pair)) {
|
|
571
|
+
invalid();
|
|
572
|
+
return void 0;
|
|
573
|
+
}
|
|
574
|
+
pairs.add(pair);
|
|
575
|
+
lengths.add(entry.byteLength);
|
|
576
|
+
if (lengths.size > 8) {
|
|
577
|
+
invalid();
|
|
578
|
+
return void 0;
|
|
579
|
+
}
|
|
580
|
+
entries.push({ sha256: entry.sha256, byteLength: entry.byteLength });
|
|
581
|
+
}
|
|
582
|
+
return entries;
|
|
583
|
+
}
|
|
584
|
+
function normalizeOutput(raw, configPath, issues) {
|
|
585
|
+
const base = defaultConfig.output;
|
|
586
|
+
if (!raw) {
|
|
587
|
+
return base;
|
|
588
|
+
}
|
|
589
|
+
if (!isRecord(raw)) {
|
|
590
|
+
issues.push(configIssue(configPath, "output must be an object."));
|
|
591
|
+
return base;
|
|
592
|
+
}
|
|
593
|
+
return {
|
|
594
|
+
validateJsonPath: readString(
|
|
595
|
+
raw.validateJsonPath,
|
|
596
|
+
base.validateJsonPath,
|
|
597
|
+
"output.validateJsonPath",
|
|
598
|
+
configPath,
|
|
599
|
+
issues
|
|
600
|
+
)
|
|
601
|
+
};
|
|
602
|
+
}
|
|
603
|
+
function normalizePrototyping(raw, configPath, issues) {
|
|
604
|
+
if (raw === void 0 || raw === null) {
|
|
605
|
+
return void 0;
|
|
606
|
+
}
|
|
607
|
+
if (!isRecord(raw)) {
|
|
608
|
+
issues.push(configIssue(configPath, "prototyping must be an object."));
|
|
609
|
+
return void 0;
|
|
610
|
+
}
|
|
611
|
+
const execution = normalizePrototypingExecution(raw.execution, configPath, issues);
|
|
612
|
+
if (Object.prototype.hasOwnProperty.call(raw, "primarySpecId")) {
|
|
613
|
+
issues.push(
|
|
614
|
+
configIssue(
|
|
615
|
+
configPath,
|
|
616
|
+
"prototyping.primarySpecId is retired; use prototyping.primaryUiContract: UI-NNNN."
|
|
617
|
+
)
|
|
618
|
+
);
|
|
619
|
+
}
|
|
620
|
+
const primaryUiContract = normalizePrimaryUiContract(raw.primaryUiContract, configPath, issues);
|
|
621
|
+
if (!execution && primaryUiContract === void 0) {
|
|
622
|
+
return void 0;
|
|
623
|
+
}
|
|
624
|
+
return {
|
|
625
|
+
...execution ? { execution } : {},
|
|
626
|
+
...primaryUiContract !== void 0 ? { primaryUiContract } : {}
|
|
627
|
+
};
|
|
628
|
+
}
|
|
629
|
+
function normalizePrimaryUiContract(raw, configPath, issues) {
|
|
630
|
+
if (raw === void 0 || raw === null) {
|
|
631
|
+
return void 0;
|
|
632
|
+
}
|
|
633
|
+
if (typeof raw !== "string" || !/^UI-\d{4}$/.test(raw)) {
|
|
634
|
+
issues.push(configIssue(configPath, primaryUiContractMessage(raw)));
|
|
635
|
+
return void 0;
|
|
636
|
+
}
|
|
637
|
+
return raw;
|
|
638
|
+
}
|
|
639
|
+
function primaryUiContractMessage(raw) {
|
|
640
|
+
return `prototyping.primaryUiContract must be a full UI-NNNN ID; received ${JSON.stringify(raw)}.`;
|
|
641
|
+
}
|
|
642
|
+
function normalizePrototypingExecution(raw, configPath, issues) {
|
|
643
|
+
const base = defaultConfig.prototyping?.execution;
|
|
644
|
+
if (raw === void 0 || raw === null) {
|
|
645
|
+
return base ? { ...base } : void 0;
|
|
646
|
+
}
|
|
647
|
+
if (!isRecord(raw)) {
|
|
648
|
+
issues.push(configIssue(configPath, "prototyping.execution must be an object."));
|
|
649
|
+
return base ? { ...base } : void 0;
|
|
650
|
+
}
|
|
651
|
+
const browserToolRaw = raw.browserTool;
|
|
652
|
+
const browserTool = "playwright";
|
|
653
|
+
if (browserToolRaw !== void 0 && browserToolRaw !== browserTool) {
|
|
654
|
+
issues.push(
|
|
655
|
+
configIssue(
|
|
656
|
+
configPath,
|
|
657
|
+
`prototyping.execution.browserTool must be "playwright". Received: ${JSON.stringify(browserToolRaw)}`
|
|
658
|
+
)
|
|
659
|
+
);
|
|
660
|
+
}
|
|
661
|
+
return {
|
|
662
|
+
targetUrl: raw.targetUrl === null ? null : readOptionalString(
|
|
663
|
+
raw.targetUrl,
|
|
664
|
+
"prototyping.execution.targetUrl",
|
|
665
|
+
configPath,
|
|
666
|
+
issues
|
|
667
|
+
) ?? null,
|
|
668
|
+
browserTool
|
|
669
|
+
};
|
|
670
|
+
}
|
|
671
|
+
function readNonNegativeInteger(raw, field, configPath, issues) {
|
|
672
|
+
if (typeof raw === "number" && Number.isFinite(raw) && Number.isInteger(raw) && raw >= 0) {
|
|
673
|
+
return raw;
|
|
674
|
+
}
|
|
675
|
+
issues.push(configIssue(configPath, `${field} must be an integer greater than or equal to 0.`));
|
|
676
|
+
return void 0;
|
|
677
|
+
}
|
|
678
|
+
function normalizeReport(raw, configPath, issues) {
|
|
679
|
+
if (raw === void 0 || raw === null) {
|
|
680
|
+
return void 0;
|
|
681
|
+
}
|
|
682
|
+
if (!isRecord(raw)) {
|
|
683
|
+
issues.push(configIssue(configPath, "report must be an object."));
|
|
684
|
+
return void 0;
|
|
685
|
+
}
|
|
686
|
+
const result = {};
|
|
687
|
+
if (raw.staleTtlDays !== void 0) {
|
|
688
|
+
const value = readNonNegativeInteger(
|
|
689
|
+
raw.staleTtlDays,
|
|
690
|
+
"report.staleTtlDays",
|
|
691
|
+
configPath,
|
|
692
|
+
issues
|
|
693
|
+
);
|
|
694
|
+
if (value !== void 0) {
|
|
695
|
+
result.staleTtlDays = value;
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
if (raw.keepLatestRuns !== void 0) {
|
|
699
|
+
const value = readNonNegativeInteger(
|
|
700
|
+
raw.keepLatestRuns,
|
|
701
|
+
"report.keepLatestRuns",
|
|
702
|
+
configPath,
|
|
703
|
+
issues
|
|
704
|
+
);
|
|
705
|
+
if (value !== void 0) {
|
|
706
|
+
result.keepLatestRuns = value;
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
return Object.keys(result).length === 0 ? void 0 : result;
|
|
710
|
+
}
|
|
711
|
+
function readString(value, fallback, label, configPath, issues) {
|
|
712
|
+
if (typeof value === "string" && value.trim().length > 0) {
|
|
713
|
+
return value;
|
|
714
|
+
}
|
|
715
|
+
if (value !== void 0) {
|
|
716
|
+
issues.push(configIssue(configPath, `${label} must be a string.`));
|
|
717
|
+
}
|
|
718
|
+
return fallback;
|
|
719
|
+
}
|
|
720
|
+
function readDirString(value, fallback, label, configPath, issues) {
|
|
721
|
+
const raw = readString(value, fallback, label, configPath, issues);
|
|
722
|
+
const trimmed = raw.replace(/[\\/]+$/, "");
|
|
723
|
+
return trimmed.length > 0 ? trimmed : raw;
|
|
724
|
+
}
|
|
725
|
+
function readTreeDirString(value, fallback, label, configPath, issues) {
|
|
726
|
+
return readDirString(value, fallback, label, configPath, issues).replace(/\\/g, "/");
|
|
727
|
+
}
|
|
728
|
+
function readDeliberationDir(value, fallback, configPath, issues) {
|
|
729
|
+
const dir = readTreeDirString(value, fallback, "paths.deliberationDir", configPath, issues);
|
|
730
|
+
if (isDirectoryInsideRoot(path5.dirname(configPath), dir)) return dir;
|
|
731
|
+
issues.push(configIssue(configPath, DELIBERATION_DIR_OUTSIDE_ROOT_MESSAGE));
|
|
732
|
+
return fallback;
|
|
733
|
+
}
|
|
734
|
+
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.";
|
|
735
|
+
function isDirectoryInsideRoot(root, dir) {
|
|
736
|
+
const relative = path5.relative(root, path5.resolve(root, dir));
|
|
737
|
+
return !dir.split(/[\\/]/).some((part) => part !== "." && part !== ".." && /[. ]$/.test(part)) && relative !== "" && relative !== ".." && !relative.startsWith(`..${path5.sep}`) && !path5.isAbsolute(relative);
|
|
738
|
+
}
|
|
739
|
+
function readOptionalString(value, label, configPath, issues) {
|
|
740
|
+
if (value === void 0) {
|
|
741
|
+
return void 0;
|
|
742
|
+
}
|
|
743
|
+
if (typeof value === "string" && value.trim().length > 0) {
|
|
744
|
+
return value;
|
|
745
|
+
}
|
|
746
|
+
issues.push(configIssue(configPath, `${label} must be a non-empty string.`));
|
|
747
|
+
return void 0;
|
|
748
|
+
}
|
|
749
|
+
function readStringArray(value, fallback, label, configPath, issues) {
|
|
750
|
+
if (Array.isArray(value) && value.every((item) => typeof item === "string")) {
|
|
751
|
+
return value;
|
|
752
|
+
}
|
|
753
|
+
if (value !== void 0) {
|
|
754
|
+
issues.push(configIssue(configPath, `${label} must be an array of strings.`));
|
|
755
|
+
}
|
|
756
|
+
return fallback;
|
|
757
|
+
}
|
|
758
|
+
function readDiagramBudget(value, configPath, issues) {
|
|
759
|
+
if (value === void 0) {
|
|
760
|
+
return void 0;
|
|
761
|
+
}
|
|
762
|
+
if (!isRecord(value)) {
|
|
763
|
+
issues.push(configIssue(configPath, "validation.diagramBudget must be an object."));
|
|
764
|
+
return void 0;
|
|
765
|
+
}
|
|
766
|
+
for (const key of Object.keys(value)) {
|
|
767
|
+
if (key !== "nodes" && key !== "edges") {
|
|
768
|
+
issues.push(configIssue(configPath, `validation.diagramBudget.${key} is not a setting.`));
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
const budget = {};
|
|
772
|
+
for (const key of ["nodes", "edges"]) {
|
|
773
|
+
const limit = value[key];
|
|
774
|
+
if (limit === void 0) {
|
|
775
|
+
continue;
|
|
776
|
+
}
|
|
777
|
+
if (typeof limit === "number" && Number.isInteger(limit) && limit >= 1) {
|
|
778
|
+
budget[key] = limit;
|
|
779
|
+
} else {
|
|
780
|
+
issues.push(
|
|
781
|
+
configIssue(configPath, `validation.diagramBudget.${key} must be an integer of 1 or more.`)
|
|
782
|
+
);
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
return budget;
|
|
786
|
+
}
|
|
787
|
+
function readBoolean(value, fallback, label, configPath, issues) {
|
|
788
|
+
if (typeof value === "boolean") {
|
|
789
|
+
return value;
|
|
790
|
+
}
|
|
791
|
+
if (value !== void 0) {
|
|
792
|
+
issues.push(configIssue(configPath, `${label} must be a boolean.`));
|
|
793
|
+
}
|
|
794
|
+
return fallback;
|
|
795
|
+
}
|
|
796
|
+
function readFailOn(value, fallback, label, configPath, issues) {
|
|
797
|
+
if (value === "never" || value === "warning" || value === "error") {
|
|
798
|
+
return value;
|
|
799
|
+
}
|
|
800
|
+
if (value !== void 0) {
|
|
801
|
+
issues.push(configIssue(configPath, `${label} must be one of never|warning|error.`));
|
|
802
|
+
}
|
|
803
|
+
return fallback;
|
|
804
|
+
}
|
|
805
|
+
var RETIRED_TRACEABILITY_KEYS = ["scMustHaveTest", "unknownContractIdSeverity"];
|
|
806
|
+
function reportRetiredTraceabilityKeys(traceabilityRaw, configPath, issues) {
|
|
807
|
+
if (!traceabilityRaw) {
|
|
808
|
+
return;
|
|
809
|
+
}
|
|
810
|
+
for (const key of RETIRED_TRACEABILITY_KEYS) {
|
|
811
|
+
if (traceabilityRaw[key] === void 0) {
|
|
812
|
+
continue;
|
|
813
|
+
}
|
|
814
|
+
issues.push(
|
|
815
|
+
configDeprecatedIssue(
|
|
816
|
+
configPath,
|
|
817
|
+
`validation.traceability.${key} is retired. No check reads it, so setting it changes nothing. Remove it from qfai.config.yaml.`
|
|
818
|
+
)
|
|
819
|
+
);
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
function normalizeUiux(raw, configPath, issues) {
|
|
823
|
+
if (raw === void 0 || raw === null) {
|
|
824
|
+
return void 0;
|
|
825
|
+
}
|
|
826
|
+
if (!isRecord(raw)) {
|
|
827
|
+
issues.push(configIssue(configPath, "uiux must be an object."));
|
|
828
|
+
return void 0;
|
|
829
|
+
}
|
|
830
|
+
const result = {};
|
|
831
|
+
if (raw.platform !== void 0) {
|
|
832
|
+
if (typeof raw.platform === "string" && raw.platform.trim().length > 0) {
|
|
833
|
+
result.platform = raw.platform;
|
|
834
|
+
} else {
|
|
835
|
+
issues.push(configIssue(configPath, "uiux.platform must be a non-empty string."));
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
if (raw.designTokensDir !== void 0) {
|
|
839
|
+
if (typeof raw.designTokensDir === "string" && raw.designTokensDir.trim().length > 0) {
|
|
840
|
+
result.designTokensDir = raw.designTokensDir;
|
|
841
|
+
} else {
|
|
842
|
+
issues.push(configIssue(configPath, "uiux.designTokensDir must be a non-empty string."));
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
if (raw.htmlMockTimeout !== void 0) {
|
|
846
|
+
if (typeof raw.htmlMockTimeout === "number" && Number.isFinite(raw.htmlMockTimeout) && raw.htmlMockTimeout > 0) {
|
|
847
|
+
result.htmlMockTimeout = raw.htmlMockTimeout;
|
|
848
|
+
} else {
|
|
849
|
+
issues.push(configIssue(configPath, "uiux.htmlMockTimeout must be a positive number."));
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
if (raw.qualityProfile !== void 0) {
|
|
853
|
+
if (typeof raw.qualityProfile === "string" && ["strict", "high", "default"].includes(raw.qualityProfile)) {
|
|
854
|
+
result.qualityProfile = raw.qualityProfile;
|
|
855
|
+
} else {
|
|
856
|
+
issues.push(
|
|
857
|
+
configIssue(configPath, "uiux.qualityProfile must be one of strict|high|default.")
|
|
858
|
+
);
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
if (raw.surfacePaths !== void 0) {
|
|
862
|
+
const surfacePaths = raw.surfacePaths;
|
|
863
|
+
if (Array.isArray(surfacePaths) && surfacePaths.every(
|
|
864
|
+
(entry) => typeof entry === "string" && entry.trim().length > 0
|
|
865
|
+
)) {
|
|
866
|
+
result.surfacePaths = surfacePaths.map((entry) => entry.trim());
|
|
867
|
+
} else {
|
|
868
|
+
issues.push(
|
|
869
|
+
configIssue(configPath, "uiux.surfacePaths must be a list of non-empty glob strings.")
|
|
870
|
+
);
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
if (raw.registries !== void 0) {
|
|
874
|
+
const registries = normalizeUiuxRegistries(raw.registries, configPath, issues);
|
|
875
|
+
if (registries) {
|
|
876
|
+
result.registries = registries;
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
if (raw.audit !== void 0) {
|
|
880
|
+
const audit = normalizeUiuxAudit(raw.audit, configPath, issues);
|
|
881
|
+
if (audit) {
|
|
882
|
+
result.audit = audit;
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
return Object.keys(result).length > 0 ? result : void 0;
|
|
886
|
+
}
|
|
887
|
+
function normalizeUiuxRegistries(raw, configPath, issues) {
|
|
888
|
+
if (!isRecord(raw)) {
|
|
889
|
+
issues.push(configIssue(configPath, "uiux.registries must be an object."));
|
|
890
|
+
return void 0;
|
|
891
|
+
}
|
|
892
|
+
const result = {};
|
|
893
|
+
for (const [name, url] of Object.entries(raw)) {
|
|
894
|
+
if (typeof url !== "string" || url.trim().length === 0) {
|
|
895
|
+
issues.push(configIssue(configPath, `uiux.registries.${name} must be a non-empty string.`));
|
|
896
|
+
continue;
|
|
897
|
+
}
|
|
898
|
+
if (!url.includes("{name}")) {
|
|
899
|
+
issues.push(
|
|
900
|
+
configIssue(
|
|
901
|
+
configPath,
|
|
902
|
+
`uiux.registries.${name} must contain the {name} placeholder, or it resolves no component.`
|
|
903
|
+
)
|
|
904
|
+
);
|
|
905
|
+
continue;
|
|
906
|
+
}
|
|
907
|
+
result[name] = url;
|
|
908
|
+
}
|
|
909
|
+
return Object.keys(result).length > 0 ? result : void 0;
|
|
910
|
+
}
|
|
911
|
+
function normalizeUiuxAudit(raw, configPath, issues) {
|
|
912
|
+
if (!isRecord(raw)) {
|
|
913
|
+
issues.push(configIssue(configPath, "uiux.audit must be an object."));
|
|
914
|
+
return void 0;
|
|
915
|
+
}
|
|
916
|
+
const result = {};
|
|
917
|
+
if (raw.enabled !== void 0) {
|
|
918
|
+
if (typeof raw.enabled === "boolean") {
|
|
919
|
+
result.enabled = raw.enabled;
|
|
920
|
+
} else {
|
|
921
|
+
issues.push(configIssue(configPath, "uiux.audit.enabled must be a boolean."));
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
if (raw.slopDetection !== void 0) {
|
|
925
|
+
if (typeof raw.slopDetection === "boolean") {
|
|
926
|
+
result.slopDetection = raw.slopDetection;
|
|
927
|
+
} else {
|
|
928
|
+
issues.push(configIssue(configPath, "uiux.audit.slopDetection must be a boolean."));
|
|
929
|
+
}
|
|
930
|
+
}
|
|
931
|
+
if (raw.maxRawTokenLiteralWarnings !== void 0) {
|
|
932
|
+
if (typeof raw.maxRawTokenLiteralWarnings === "number" && Number.isFinite(raw.maxRawTokenLiteralWarnings) && raw.maxRawTokenLiteralWarnings >= 0) {
|
|
933
|
+
result.maxRawTokenLiteralWarnings = raw.maxRawTokenLiteralWarnings;
|
|
934
|
+
} else {
|
|
935
|
+
issues.push(
|
|
936
|
+
configIssue(
|
|
937
|
+
configPath,
|
|
938
|
+
"uiux.audit.maxRawTokenLiteralWarnings must be a number greater than or equal to 0."
|
|
939
|
+
)
|
|
940
|
+
);
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
if (raw.maxDuplicateFindingsPerRule !== void 0) {
|
|
944
|
+
if (typeof raw.maxDuplicateFindingsPerRule === "number" && Number.isFinite(raw.maxDuplicateFindingsPerRule) && raw.maxDuplicateFindingsPerRule >= 0) {
|
|
945
|
+
result.maxDuplicateFindingsPerRule = raw.maxDuplicateFindingsPerRule;
|
|
946
|
+
} else {
|
|
947
|
+
issues.push(
|
|
948
|
+
configIssue(
|
|
949
|
+
configPath,
|
|
950
|
+
"uiux.audit.maxDuplicateFindingsPerRule must be a number greater than or equal to 0."
|
|
951
|
+
)
|
|
952
|
+
);
|
|
953
|
+
}
|
|
954
|
+
}
|
|
955
|
+
return Object.keys(result).length > 0 ? result : void 0;
|
|
956
|
+
}
|
|
957
|
+
function configIssue(file, message) {
|
|
958
|
+
return {
|
|
959
|
+
code: "QFAI-CFG-002",
|
|
960
|
+
severity: "error",
|
|
961
|
+
category: "canonical",
|
|
962
|
+
message,
|
|
963
|
+
file,
|
|
964
|
+
rule: "config.invalid"
|
|
965
|
+
};
|
|
966
|
+
}
|
|
967
|
+
function configDeprecatedIssue(file, message) {
|
|
968
|
+
return {
|
|
969
|
+
code: "QFAI-CFG-001",
|
|
970
|
+
severity: "error",
|
|
971
|
+
category: "canonical",
|
|
972
|
+
message,
|
|
973
|
+
file,
|
|
974
|
+
rule: "config.deprecatedKey"
|
|
975
|
+
};
|
|
976
|
+
}
|
|
977
|
+
function isRecord(value) {
|
|
978
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
979
|
+
}
|
|
980
|
+
|
|
981
|
+
// src/core/graph/localFiles.ts
|
|
982
|
+
import { lstat as lstat4, mkdir as mkdir2, open as open2 } from "fs/promises";
|
|
983
|
+
import path7 from "path";
|
|
984
|
+
|
|
985
|
+
// src/core/init/fsGuards.ts
|
|
986
|
+
import { constants } from "fs";
|
|
987
|
+
import { access as access3, lstat as lstat3, open, readFile as readFile2, stat } from "fs/promises";
|
|
988
|
+
import path6 from "path";
|
|
989
|
+
async function readPinnedRegularFileBytes(filePath, maxBytes) {
|
|
990
|
+
let handle;
|
|
991
|
+
try {
|
|
992
|
+
handle = await open(filePath, OPEN_READ_FLAGS);
|
|
993
|
+
const pinned = await handle.stat();
|
|
994
|
+
if (!pinned.isFile() || pinned.size > maxBytes) return null;
|
|
995
|
+
const buffer = Buffer.alloc(maxBytes + 1);
|
|
996
|
+
let filled = 0;
|
|
997
|
+
while (filled < buffer.length) {
|
|
998
|
+
const { bytesRead } = await handle.read(buffer, filled, buffer.length - filled, filled);
|
|
999
|
+
if (bytesRead === 0) break;
|
|
1000
|
+
filled += bytesRead;
|
|
1001
|
+
}
|
|
1002
|
+
if (filled > maxBytes) return null;
|
|
1003
|
+
return {
|
|
1004
|
+
content: Buffer.from(buffer.subarray(0, filled)),
|
|
1005
|
+
mode: pinned.mode & 4095,
|
|
1006
|
+
uid: pinned.uid,
|
|
1007
|
+
gid: pinned.gid,
|
|
1008
|
+
dev: pinned.dev,
|
|
1009
|
+
ino: pinned.ino
|
|
1010
|
+
};
|
|
1011
|
+
} catch (error) {
|
|
1012
|
+
const code = error?.code;
|
|
1013
|
+
if (code === "ENXIO" || code === "EISDIR") return null;
|
|
1014
|
+
throw error;
|
|
1015
|
+
} finally {
|
|
1016
|
+
await handle?.close();
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
var OPEN_READ_FLAGS = typeof constants.O_NONBLOCK === "number" ? constants.O_RDONLY | constants.O_NONBLOCK : constants.O_RDONLY;
|
|
1020
|
+
|
|
1021
|
+
// src/core/graph/localFiles.ts
|
|
1022
|
+
var GRAPH_STATE_BYTES = 32768;
|
|
1023
|
+
var GRAPH_UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
|
|
1024
|
+
var GraphLocalStateError = class extends Error {
|
|
1025
|
+
constructor(message, recovery, options) {
|
|
1026
|
+
super(message, options);
|
|
1027
|
+
this.recovery = recovery;
|
|
1028
|
+
}
|
|
1029
|
+
};
|
|
1030
|
+
async function graphStateDirectory(root) {
|
|
1031
|
+
const directory = path7.join(root, ".qfai", "tools", "state", graphEnvironmentKey());
|
|
1032
|
+
await assertGraphStoragePath(root, directory);
|
|
1033
|
+
await mkdir2(directory, { recursive: true });
|
|
1034
|
+
await assertGraphStoragePath(root, directory);
|
|
1035
|
+
return directory;
|
|
1036
|
+
}
|
|
1037
|
+
function invalidGraphState() {
|
|
1038
|
+
return new GraphLocalStateError(
|
|
1039
|
+
"Project graph permission state is invalid.",
|
|
1040
|
+
"Retain the local state and repair .qfai/tools/state before retrying the graph CLI or hook."
|
|
1041
|
+
);
|
|
1042
|
+
}
|
|
1043
|
+
function graphStateText(value, maximum) {
|
|
1044
|
+
return typeof value === "string" && value.trim().length > 0 && value.length <= maximum && !value.includes("\0");
|
|
1045
|
+
}
|
|
1046
|
+
async function readGraphLocalFile(file) {
|
|
1047
|
+
try {
|
|
1048
|
+
const before = await lstat4(file);
|
|
1049
|
+
if (!before.isFile() || before.isSymbolicLink() || before.nlink !== 1)
|
|
1050
|
+
throw invalidGraphState();
|
|
1051
|
+
const pinned = await readPinnedRegularFileBytes(file, GRAPH_STATE_BYTES);
|
|
1052
|
+
const after = await lstat4(file);
|
|
1053
|
+
if (!pinned || before.dev !== pinned.dev || before.ino !== pinned.ino || after.dev !== pinned.dev || after.ino !== pinned.ino || !after.isFile() || after.isSymbolicLink() || after.nlink !== 1)
|
|
1054
|
+
throw invalidGraphState();
|
|
1055
|
+
return pinned.content.toString("utf8");
|
|
1056
|
+
} catch (cause) {
|
|
1057
|
+
if (isEnoent(cause)) return void 0;
|
|
1058
|
+
throw cause;
|
|
1059
|
+
}
|
|
1060
|
+
}
|
|
1061
|
+
async function writeGraphLocalFile(file, value) {
|
|
1062
|
+
const text = JSON.stringify(value);
|
|
1063
|
+
if (Buffer.byteLength(text) > GRAPH_STATE_BYTES) throw invalidGraphState();
|
|
1064
|
+
const handle = await open2(file, "wx", 384);
|
|
1065
|
+
try {
|
|
1066
|
+
await handle.writeFile(text, "utf8");
|
|
1067
|
+
} finally {
|
|
1068
|
+
await handle.close();
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1071
|
+
|
|
1072
|
+
// src/core/graph/analysis.ts
|
|
283
1073
|
async function inspectCodeCoverage(root, run) {
|
|
284
1074
|
const unknown = { complete: false, unsupported: [], unreadable: [], unparsed: [] };
|
|
285
1075
|
const runtime = graphRuntimePaths(root);
|
|
@@ -288,7 +1078,7 @@ async function inspectCodeCoverage(root, run) {
|
|
|
288
1078
|
runtime.codegraphNode,
|
|
289
1079
|
[
|
|
290
1080
|
"--liftoff-only",
|
|
291
|
-
|
|
1081
|
+
path8.resolve(getInitAssetsDir(), "..", "graph", "codegraph-native.mjs"),
|
|
292
1082
|
runtime.codegraphSdk,
|
|
293
1083
|
analysis,
|
|
294
1084
|
"coverage"
|
|
@@ -321,7 +1111,7 @@ async function inspectCurrentCodeAnalysis(root, run) {
|
|
|
321
1111
|
async function inspectCodeAnalysisAt(root, analysis, run) {
|
|
322
1112
|
await assertGraphStoragePath(root, analysis);
|
|
323
1113
|
try {
|
|
324
|
-
if (!(await
|
|
1114
|
+
if (!(await lstat5(path8.join(analysis, ".codegraph", "codegraph.db"))).isFile()) return false;
|
|
325
1115
|
} catch (cause) {
|
|
326
1116
|
if (isEnoent(cause)) return false;
|
|
327
1117
|
throw cause;
|
|
@@ -363,10 +1153,30 @@ var excludedDirectories = /* @__PURE__ */ new Set([
|
|
|
363
1153
|
".aws",
|
|
364
1154
|
".azure"
|
|
365
1155
|
]);
|
|
366
|
-
|
|
1156
|
+
var GraphConfigUnreadableError = class extends GraphLocalStateError {
|
|
1157
|
+
constructor(configFile, unreadable) {
|
|
1158
|
+
super(
|
|
1159
|
+
unreadable ? `${configFile} could not be read or parsed.` : `${configFile} gives no usable paths.deliberationDir.`,
|
|
1160
|
+
`Correct ${configFile}, then retry.`
|
|
1161
|
+
);
|
|
1162
|
+
}
|
|
1163
|
+
};
|
|
1164
|
+
async function graphDeliberationDir(root) {
|
|
1165
|
+
const { config, document, issues, configPath } = await loadConfig(root);
|
|
1166
|
+
const file = path8.basename(configPath);
|
|
1167
|
+
if (document === void 0 && issues.length > 0) throw new GraphConfigUnreadableError(file, true);
|
|
1168
|
+
const paths = object(document) ? document.paths : void 0;
|
|
1169
|
+
const value = object(paths) ? paths.deliberationDir : void 0;
|
|
1170
|
+
if (document !== void 0 && document !== null && !object(document) || paths !== void 0 && paths !== null && !object(paths) || value !== void 0 && (typeof value !== "string" || value.trim() === "" || !isDirectoryInsideRoot(root, value.replace(/\\/g, "/"))))
|
|
1171
|
+
throw new GraphConfigUnreadableError(file, false);
|
|
1172
|
+
return path8.relative(root, resolvePath(root, config, "deliberationDir")).split(path8.sep).join("/");
|
|
1173
|
+
}
|
|
1174
|
+
function excludedGraphInput(relative, deliberationDir) {
|
|
367
1175
|
const parts = relative.split("/");
|
|
368
1176
|
const name = parts.at(-1) ?? "";
|
|
369
|
-
|
|
1177
|
+
const lowered = relative.toLowerCase();
|
|
1178
|
+
const deliberation = deliberationDir.toLowerCase();
|
|
1179
|
+
return parts.some((part) => excludedDirectories.has(part.toLowerCase())) || /^\.qfai\/(?:tools|report|evidence|review)(?:\/|$)/i.test(relative) || lowered === deliberation || lowered.startsWith(`${deliberation}/`) || lowered === ".qfai/graph-processing.json" || /^(?:\.npmrc|\.pypirc|\.netrc|\.git-credentials)$/i.test(name) || /^\.env(?:\.|$)/i.test(name) || /\.(?:pem|key|p12|pfx|keystore)$/i.test(name) || /^(?:id_(?:rsa|dsa|ecdsa|ed25519)|credentials?(?:\.|$)|secrets?(?:\.|$)|\.mcp\.json$)/i.test(
|
|
370
1180
|
name
|
|
371
1181
|
);
|
|
372
1182
|
}
|
|
@@ -374,14 +1184,15 @@ async function mirrorGraphCorpus(root, destination, scope) {
|
|
|
374
1184
|
await assertGraphStoragePath(root, destination);
|
|
375
1185
|
await assertIndependentAnalysis(destination);
|
|
376
1186
|
const files = /* @__PURE__ */ new Set();
|
|
1187
|
+
const deliberationDir = await graphDeliberationDir(root);
|
|
377
1188
|
await visit("");
|
|
378
1189
|
await removeAbsent("");
|
|
379
1190
|
async function visit(relative) {
|
|
380
|
-
for (const entry of await readdir2(
|
|
1191
|
+
for (const entry of await readdir2(path8.join(root, ...relative.split("/")), {
|
|
381
1192
|
withFileTypes: true
|
|
382
1193
|
})) {
|
|
383
1194
|
const next = relative ? `${relative}/${entry.name}` : entry.name;
|
|
384
|
-
if (excludedGraphInput(next) || entry.isSymbolicLink()) continue;
|
|
1195
|
+
if (excludedGraphInput(next, deliberationDir) || entry.isSymbolicLink()) continue;
|
|
385
1196
|
if (scope && !scope.some(
|
|
386
1197
|
(item) => item === next || next.startsWith(`${item}/`) || item.startsWith(`${next}/`)
|
|
387
1198
|
))
|
|
@@ -389,24 +1200,24 @@ async function mirrorGraphCorpus(root, destination, scope) {
|
|
|
389
1200
|
if (entry.isDirectory()) {
|
|
390
1201
|
await visit(next);
|
|
391
1202
|
} else if (entry.isFile()) {
|
|
392
|
-
const source =
|
|
393
|
-
const stats = await
|
|
1203
|
+
const source = path8.join(root, ...next.split("/"));
|
|
1204
|
+
const stats = await lstat5(source);
|
|
394
1205
|
if (!stats.isFile() || stats.nlink > 1) continue;
|
|
395
|
-
const target =
|
|
396
|
-
await
|
|
1206
|
+
const target = path8.join(destination, ...next.split("/"));
|
|
1207
|
+
await mkdir3(path8.dirname(target), { recursive: true });
|
|
397
1208
|
await copyFile(source, target);
|
|
398
1209
|
files.add(next);
|
|
399
1210
|
}
|
|
400
1211
|
}
|
|
401
1212
|
}
|
|
402
1213
|
async function removeAbsent(relative) {
|
|
403
|
-
for (const entry of await readdir2(
|
|
1214
|
+
for (const entry of await readdir2(path8.join(destination, ...relative.split("/")), {
|
|
404
1215
|
withFileTypes: true
|
|
405
1216
|
})) {
|
|
406
1217
|
const next = relative ? `${relative}/${entry.name}` : entry.name;
|
|
407
1218
|
if (entry.name === ".codegraph" || entry.name === ".git" || entry.name === "graphify-out")
|
|
408
1219
|
continue;
|
|
409
|
-
const target =
|
|
1220
|
+
const target = path8.join(destination, ...next.split("/"));
|
|
410
1221
|
if (entry.isDirectory()) await removeAbsent(next);
|
|
411
1222
|
else if (!files.has(next)) await rm2(target);
|
|
412
1223
|
}
|
|
@@ -440,24 +1251,26 @@ async function restoreCompletedCodeAnalysis(root, run, environment = graphReuseE
|
|
|
440
1251
|
if (isEnoent(cause)) return "cold";
|
|
441
1252
|
throw cause;
|
|
442
1253
|
}
|
|
1254
|
+
const deliberationDir = await graphDeliberationDir(root);
|
|
443
1255
|
for (const entry of candidates) {
|
|
444
1256
|
if (!entry.isDirectory() || entry.isSymbolicLink() || entry.name.startsWith(".")) continue;
|
|
445
|
-
const candidate =
|
|
1257
|
+
const candidate = path9.join(location.directory, entry.name);
|
|
446
1258
|
if (!await cacheDirectorySafe(location.repository, candidate)) continue;
|
|
447
1259
|
const metadata = await readSnapshotMetadata(candidate);
|
|
448
1260
|
if (!metadata || Object.keys(metadata).some(
|
|
449
1261
|
(key) => !["layout", "corpusPolicy", "repository", "engineVersion", "environment"].includes(key)
|
|
450
1262
|
) || metadata.layout !== 1 || metadata.corpusPolicy !== 1 || metadata.repository !== location.repository || metadata.engineVersion !== GRAPH_VERSIONS.codegraph || !sameEnvironment(metadata.environment, environment))
|
|
451
1263
|
continue;
|
|
452
|
-
if (!await safeCompletedCorpus(
|
|
453
|
-
if (!await safeCodegraphInputs(root,
|
|
1264
|
+
if (!await safeCompletedCorpus(path9.join(candidate, "analysis"), deliberationDir)) continue;
|
|
1265
|
+
if (!await safeCodegraphInputs(root, path9.join(candidate, "analysis"), run, deliberationDir))
|
|
1266
|
+
continue;
|
|
454
1267
|
const current = graphAnalysisRoot(root, "codegraph");
|
|
455
|
-
const staged =
|
|
1268
|
+
const staged = path9.join(path9.dirname(current), `.restoring-codegraph-${randomUUID2()}`);
|
|
456
1269
|
await assertGraphStoragePath(root, staged);
|
|
457
1270
|
try {
|
|
458
|
-
const cached =
|
|
1271
|
+
const cached = path9.join(candidate, "analysis");
|
|
459
1272
|
await assertIndependentAnalysis(cached);
|
|
460
|
-
await
|
|
1273
|
+
await mkdir4(path9.dirname(staged), { recursive: true });
|
|
461
1274
|
await cp(cached, staged, { recursive: true, dereference: false });
|
|
462
1275
|
await assertIndependentAnalysis(staged);
|
|
463
1276
|
if (!await inspectCodeAnalysisAt(root, staged, run)) continue;
|
|
@@ -473,11 +1286,11 @@ async function completedAnalysisCache(root, engine, run, environment = graphReus
|
|
|
473
1286
|
const git = await run("git", ["rev-parse", "--path-format=absolute", "--git-common-dir"], {
|
|
474
1287
|
cwd: root
|
|
475
1288
|
});
|
|
476
|
-
if (git.exitCode !== 0 || !
|
|
1289
|
+
if (git.exitCode !== 0 || !path9.isAbsolute(git.stdout.trim())) return void 0;
|
|
477
1290
|
const repository = await realpath2(git.stdout.trim());
|
|
478
1291
|
return {
|
|
479
1292
|
repository,
|
|
480
|
-
directory:
|
|
1293
|
+
directory: path9.join(repository, "qfai-graph-cache", graphEnvironmentKey(environment), engine)
|
|
481
1294
|
};
|
|
482
1295
|
}
|
|
483
1296
|
async function publishCompletedCodeAnalysis(root, run, environment = graphReuseEnvironment()) {
|
|
@@ -494,19 +1307,20 @@ async function publishCompletedCodeAnalysis(root, run, environment = graphReuseE
|
|
|
494
1307
|
if (!cache) return "unavailable";
|
|
495
1308
|
await ensureCacheDirectory(cache.repository, cache.directory);
|
|
496
1309
|
const analysis = graphAnalysisRoot(root, "codegraph");
|
|
497
|
-
|
|
1310
|
+
const deliberationDir = await graphDeliberationDir(root);
|
|
1311
|
+
if (!await safeCompletedCorpus(analysis, deliberationDir) || !await safeCodegraphInputs(root, analysis, run, deliberationDir))
|
|
498
1312
|
return "unavailable";
|
|
499
1313
|
const identity = randomUUID2();
|
|
500
|
-
staged =
|
|
501
|
-
await
|
|
502
|
-
await cp(analysis,
|
|
503
|
-
await assertIndependentAnalysis(
|
|
504
|
-
if (!await safeCompletedCorpus(
|
|
1314
|
+
staged = path9.join(cache.directory, `.publishing-${identity}`);
|
|
1315
|
+
await mkdir4(staged);
|
|
1316
|
+
await cp(analysis, path9.join(staged, "analysis"), { recursive: true, dereference: false });
|
|
1317
|
+
await assertIndependentAnalysis(path9.join(staged, "analysis"));
|
|
1318
|
+
if (!await safeCompletedCorpus(path9.join(staged, "analysis"), deliberationDir) || !await safeCodegraphInputs(root, path9.join(staged, "analysis"), run, deliberationDir))
|
|
505
1319
|
return "unavailable";
|
|
506
|
-
if (!await nativeCodeAnalysisCurrent(root,
|
|
1320
|
+
if (!await nativeCodeAnalysisCurrent(root, path9.join(staged, "analysis"), run))
|
|
507
1321
|
return "unavailable";
|
|
508
1322
|
await writeFile(
|
|
509
|
-
|
|
1323
|
+
path9.join(staged, "completed.json"),
|
|
510
1324
|
JSON.stringify({
|
|
511
1325
|
layout: 1,
|
|
512
1326
|
corpusPolicy: 1,
|
|
@@ -515,7 +1329,7 @@ async function publishCompletedCodeAnalysis(root, run, environment = graphReuseE
|
|
|
515
1329
|
environment
|
|
516
1330
|
}) + "\n"
|
|
517
1331
|
);
|
|
518
|
-
await rename2(staged,
|
|
1332
|
+
await rename2(staged, path9.join(cache.directory, identity));
|
|
519
1333
|
return "published";
|
|
520
1334
|
} catch {
|
|
521
1335
|
return "unavailable";
|
|
@@ -524,41 +1338,41 @@ async function publishCompletedCodeAnalysis(root, run, environment = graphReuseE
|
|
|
524
1338
|
}
|
|
525
1339
|
}
|
|
526
1340
|
async function ensureCacheDirectory(repository, directory) {
|
|
527
|
-
const relative =
|
|
528
|
-
const parts = relative.split(
|
|
529
|
-
if (
|
|
1341
|
+
const relative = path9.relative(repository, directory);
|
|
1342
|
+
const parts = relative.split(path9.sep);
|
|
1343
|
+
if (path9.isAbsolute(relative) || parts.includes("..") || parts[0] !== "qfai-graph-cache")
|
|
530
1344
|
throw new Error("Unsafe completed analysis path.");
|
|
531
1345
|
for (let depth = 1; depth <= parts.length; depth += 1) {
|
|
532
|
-
const component =
|
|
1346
|
+
const component = path9.join(repository, ...parts.slice(0, depth));
|
|
533
1347
|
let stats;
|
|
534
1348
|
try {
|
|
535
|
-
stats = await
|
|
1349
|
+
stats = await lstat6(component);
|
|
536
1350
|
} catch (cause) {
|
|
537
1351
|
if (!isEnoent(cause)) throw cause;
|
|
538
|
-
await
|
|
539
|
-
stats = await
|
|
1352
|
+
await mkdir4(component);
|
|
1353
|
+
stats = await lstat6(component);
|
|
540
1354
|
}
|
|
541
1355
|
if (stats.isSymbolicLink() || !stats.isDirectory())
|
|
542
1356
|
throw new Error("Unsafe completed analysis path.");
|
|
543
1357
|
}
|
|
544
1358
|
}
|
|
545
1359
|
async function cacheDirectorySafe(repository, candidate) {
|
|
546
|
-
const relative =
|
|
547
|
-
const parts = relative.split(
|
|
548
|
-
if (
|
|
1360
|
+
const relative = path9.relative(repository, candidate);
|
|
1361
|
+
const parts = relative.split(path9.sep);
|
|
1362
|
+
if (path9.isAbsolute(relative) || parts.includes("..") || parts[0] !== "qfai-graph-cache")
|
|
549
1363
|
return false;
|
|
550
1364
|
for (let depth = 1; depth <= parts.length; depth += 1) {
|
|
551
|
-
const stats = await
|
|
1365
|
+
const stats = await lstat6(path9.join(repository, ...parts.slice(0, depth)));
|
|
552
1366
|
if (stats.isSymbolicLink() || !stats.isDirectory()) return false;
|
|
553
1367
|
}
|
|
554
1368
|
return true;
|
|
555
1369
|
}
|
|
556
1370
|
async function readSnapshotMetadata(candidate) {
|
|
557
1371
|
try {
|
|
558
|
-
const stats = await
|
|
1372
|
+
const stats = await lstat6(path9.join(candidate, "completed.json"));
|
|
559
1373
|
if (!stats.isFile() || stats.isSymbolicLink() || stats.nlink !== 1) return void 0;
|
|
560
1374
|
const metadata = JSON.parse(
|
|
561
|
-
await
|
|
1375
|
+
await readFile3(path9.join(candidate, "completed.json"), "utf8")
|
|
562
1376
|
);
|
|
563
1377
|
return object2(metadata) ? metadata : void 0;
|
|
564
1378
|
} catch (cause) {
|
|
@@ -569,18 +1383,18 @@ async function readSnapshotMetadata(candidate) {
|
|
|
569
1383
|
function sameEnvironment(value, environment) {
|
|
570
1384
|
return object2(value) && Object.keys(value).length === 3 && value.platform === environment.platform && value.architecture === environment.architecture && value.machine === environment.machine;
|
|
571
1385
|
}
|
|
572
|
-
async function safeCompletedCorpus(directory, relative = "", engineDirectory = ".codegraph") {
|
|
1386
|
+
async function safeCompletedCorpus(directory, deliberationDir, relative = "", engineDirectory = ".codegraph") {
|
|
573
1387
|
try {
|
|
574
|
-
for (const entry of await readdir3(
|
|
1388
|
+
for (const entry of await readdir3(path9.join(directory, ...relative.split("/")), {
|
|
575
1389
|
withFileTypes: true
|
|
576
1390
|
})) {
|
|
577
1391
|
const next = relative ? `${relative}/${entry.name}` : entry.name;
|
|
578
1392
|
const input = next.startsWith(`${engineDirectory}/`) ? next.slice(engineDirectory.length + 1) : next;
|
|
579
|
-
if (next !== engineDirectory && excludedGraphInput(input) || /\.(?:pid|lock)$/i.test(entry.name))
|
|
1393
|
+
if (next !== engineDirectory && excludedGraphInput(input, deliberationDir) || /\.(?:pid|lock)$/i.test(entry.name))
|
|
580
1394
|
return false;
|
|
581
|
-
const stats = await
|
|
1395
|
+
const stats = await lstat6(path9.join(directory, ...next.split("/")));
|
|
582
1396
|
if (stats.isSymbolicLink() || stats.isFile() && stats.nlink !== 1) return false;
|
|
583
|
-
if (stats.isDirectory() && !await safeCompletedCorpus(directory, next, engineDirectory))
|
|
1397
|
+
if (stats.isDirectory() && !await safeCompletedCorpus(directory, deliberationDir, next, engineDirectory))
|
|
584
1398
|
return false;
|
|
585
1399
|
if (!stats.isDirectory() && !stats.isFile()) return false;
|
|
586
1400
|
}
|
|
@@ -592,13 +1406,13 @@ async function safeCompletedCorpus(directory, relative = "", engineDirectory = "
|
|
|
592
1406
|
function object2(value) {
|
|
593
1407
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
594
1408
|
}
|
|
595
|
-
async function safeCodegraphInputs(root, analysis, run) {
|
|
1409
|
+
async function safeCodegraphInputs(root, analysis, run, deliberationDir) {
|
|
596
1410
|
const runtime = graphRuntimePaths(root);
|
|
597
1411
|
const result = await run(
|
|
598
1412
|
runtime.codegraphNode,
|
|
599
1413
|
[
|
|
600
1414
|
"--liftoff-only",
|
|
601
|
-
|
|
1415
|
+
path9.resolve(getInitAssetsDir(), "..", "graph", "codegraph-native.mjs"),
|
|
602
1416
|
runtime.codegraphSdk,
|
|
603
1417
|
analysis,
|
|
604
1418
|
"inventory"
|
|
@@ -610,13 +1424,13 @@ async function safeCodegraphInputs(root, analysis, run) {
|
|
|
610
1424
|
const inventory = JSON.parse(result.stdout);
|
|
611
1425
|
if (!object2(inventory) || !Array.isArray(inventory.files)) return false;
|
|
612
1426
|
for (const file of inventory.files) {
|
|
613
|
-
if (typeof file !== "string" || !file ||
|
|
1427
|
+
if (typeof file !== "string" || !file || path9.posix.isAbsolute(file) || path9.win32.isAbsolute(file))
|
|
614
1428
|
return false;
|
|
615
1429
|
const normalized = file.replaceAll("\\", "/");
|
|
616
1430
|
const parts = normalized.split("/");
|
|
617
|
-
if (parts.some((part) => !part || part === "." || part === "..") || excludedGraphInput(normalized))
|
|
1431
|
+
if (parts.some((part) => !part || part === "." || part === "..") || excludedGraphInput(normalized, deliberationDir))
|
|
618
1432
|
return false;
|
|
619
|
-
const stats = await
|
|
1433
|
+
const stats = await lstat6(path9.join(analysis, ...parts));
|
|
620
1434
|
if (!stats.isFile() || stats.isSymbolicLink() || stats.nlink !== 1) return false;
|
|
621
1435
|
}
|
|
622
1436
|
return true;
|
|
@@ -628,7 +1442,7 @@ async function safeCodegraphInputs(root, analysis, run) {
|
|
|
628
1442
|
// src/core/graph/codePreparation.ts
|
|
629
1443
|
async function prepareCodeAnalysis(root, run, environment) {
|
|
630
1444
|
const current = graphAnalysisRoot(root, "codegraph");
|
|
631
|
-
const staged =
|
|
1445
|
+
const staged = path10.join(path10.dirname(current), `.preparing-codegraph-${randomUUID3()}`);
|
|
632
1446
|
let created = false;
|
|
633
1447
|
try {
|
|
634
1448
|
if (await inspectCurrentCodeAnalysis(root, run))
|
|
@@ -636,7 +1450,7 @@ async function prepareCodeAnalysis(root, run, environment) {
|
|
|
636
1450
|
if (await restoreCompletedCodeAnalysis(root, run, environment) === "restored")
|
|
637
1451
|
return { status: "prepared", source: "restored" };
|
|
638
1452
|
await assertGraphStoragePath(root, staged);
|
|
639
|
-
await
|
|
1453
|
+
await mkdir5(staged, { recursive: true });
|
|
640
1454
|
created = true;
|
|
641
1455
|
await mirrorGraphCorpus(root, staged);
|
|
642
1456
|
const runtime = graphRuntimePaths(root);
|
|
@@ -644,7 +1458,7 @@ async function prepareCodeAnalysis(root, run, environment) {
|
|
|
644
1458
|
runtime.codegraphNode,
|
|
645
1459
|
[
|
|
646
1460
|
"--liftoff-only",
|
|
647
|
-
|
|
1461
|
+
path10.resolve(getInitAssetsDir(), "..", "graph", "codegraph-native.mjs"),
|
|
648
1462
|
runtime.codegraphSdk,
|
|
649
1463
|
staged
|
|
650
1464
|
],
|
|
@@ -658,7 +1472,8 @@ async function prepareCodeAnalysis(root, run, environment) {
|
|
|
658
1472
|
source: "generated",
|
|
659
1473
|
reuse: await publishCompletedCodeAnalysis(root, run, environment)
|
|
660
1474
|
};
|
|
661
|
-
} catch {
|
|
1475
|
+
} catch (cause) {
|
|
1476
|
+
if (cause instanceof GraphConfigUnreadableError) throw cause;
|
|
662
1477
|
return failed();
|
|
663
1478
|
} finally {
|
|
664
1479
|
if (created) await rm4(staged, { recursive: true, force: true });
|
|
@@ -672,13 +1487,13 @@ function failed() {
|
|
|
672
1487
|
}
|
|
673
1488
|
|
|
674
1489
|
// src/core/graph/documents.ts
|
|
675
|
-
import { mkdir as mkdir7, readFile as
|
|
1490
|
+
import { mkdir as mkdir7, readFile as readFile4, rm as rm6, writeFile as writeFile3 } from "fs/promises";
|
|
676
1491
|
import { randomUUID as randomUUID6 } from "crypto";
|
|
677
1492
|
|
|
678
1493
|
// src/core/graph/documentReuse.ts
|
|
679
1494
|
import { randomUUID as randomUUID4 } from "crypto";
|
|
680
|
-
import { cp as cp2, lstat as
|
|
681
|
-
import
|
|
1495
|
+
import { cp as cp2, lstat as lstat7, mkdir as mkdir6, readdir as readdir4, rename as rename3, rm as rm5, writeFile as writeFile2 } from "fs/promises";
|
|
1496
|
+
import path11 from "path";
|
|
682
1497
|
async function restoreCompletedDocumentAnalysis(root, run, inspect, environment = graphReuseEnvironment()) {
|
|
683
1498
|
let staged;
|
|
684
1499
|
try {
|
|
@@ -687,17 +1502,17 @@ async function restoreCompletedDocumentAnalysis(root, run, inspect, environment
|
|
|
687
1502
|
if (!cache) return "cold";
|
|
688
1503
|
for (const entry of await readdir4(cache.directory, { withFileTypes: true })) {
|
|
689
1504
|
if (!entry.isDirectory() || entry.isSymbolicLink() || entry.name.startsWith(".")) continue;
|
|
690
|
-
const candidate =
|
|
1505
|
+
const candidate = path11.join(cache.directory, entry.name);
|
|
691
1506
|
if (!await cacheDirectorySafe(cache.repository, candidate)) continue;
|
|
692
1507
|
const metadata = await readSnapshotMetadata(candidate);
|
|
693
1508
|
if (!metadata || Object.keys(metadata).length !== 5 || metadata.layout !== 1 || metadata.corpusPolicy !== 1 || metadata.repository !== cache.repository || metadata.engineVersion !== GRAPH_VERSIONS.graphify || !sameEnvironment(metadata.environment, environment))
|
|
694
1509
|
continue;
|
|
695
|
-
const analysis =
|
|
1510
|
+
const analysis = path11.join(candidate, "analysis");
|
|
696
1511
|
if (!await safeDocumentCopy(root, analysis, run)) continue;
|
|
697
1512
|
const current = graphAnalysisRoot(root, "graphify");
|
|
698
|
-
staged =
|
|
1513
|
+
staged = path11.join(path11.dirname(current), `.restoring-graphify-${randomUUID4()}`);
|
|
699
1514
|
await assertGraphStoragePath(root, staged);
|
|
700
|
-
await
|
|
1515
|
+
await mkdir6(path11.dirname(staged), { recursive: true });
|
|
701
1516
|
await cp2(analysis, staged, { recursive: true, dereference: false });
|
|
702
1517
|
await assertIndependentAnalysis(staged);
|
|
703
1518
|
if (await inspect(staged, true)) {
|
|
@@ -724,15 +1539,15 @@ async function publishCompletedDocumentAnalysis(root, run, inspect, environment
|
|
|
724
1539
|
const analysis = graphAnalysisRoot(root, "graphify");
|
|
725
1540
|
if (!await safeDocumentCopy(root, analysis, run)) return "unavailable";
|
|
726
1541
|
const identity = randomUUID4();
|
|
727
|
-
staged =
|
|
728
|
-
await
|
|
729
|
-
const copy =
|
|
1542
|
+
staged = path11.join(cache.directory, `.publishing-${identity}`);
|
|
1543
|
+
await mkdir6(staged);
|
|
1544
|
+
const copy = path11.join(staged, "analysis");
|
|
730
1545
|
await cp2(analysis, copy, { recursive: true, dereference: false });
|
|
731
1546
|
await assertIndependentAnalysis(copy);
|
|
732
1547
|
if (!await safeDocumentCopy(root, copy, run) || !await inspect(copy, false))
|
|
733
1548
|
return "unavailable";
|
|
734
1549
|
await writeFile2(
|
|
735
|
-
|
|
1550
|
+
path11.join(staged, "completed.json"),
|
|
736
1551
|
JSON.stringify({
|
|
737
1552
|
layout: 1,
|
|
738
1553
|
corpusPolicy: 1,
|
|
@@ -741,7 +1556,7 @@ async function publishCompletedDocumentAnalysis(root, run, inspect, environment
|
|
|
741
1556
|
environment
|
|
742
1557
|
}) + "\n"
|
|
743
1558
|
);
|
|
744
|
-
await rename3(staged,
|
|
1559
|
+
await rename3(staged, path11.join(cache.directory, identity));
|
|
745
1560
|
return "published";
|
|
746
1561
|
} catch {
|
|
747
1562
|
return "unavailable";
|
|
@@ -759,13 +1574,14 @@ async function compatible(root, run, environment) {
|
|
|
759
1574
|
return result.exitCode === 0 && result.stdout.trim() === "3.12.13";
|
|
760
1575
|
}
|
|
761
1576
|
async function safeDocumentCopy(root, analysis, run) {
|
|
762
|
-
|
|
1577
|
+
const deliberationDir = await graphDeliberationDir(root);
|
|
1578
|
+
if (!await safeCompletedCorpus(analysis, deliberationDir, "", "graphify-out")) return false;
|
|
763
1579
|
const result = await run(
|
|
764
1580
|
graphRuntimePaths(root).python,
|
|
765
1581
|
[
|
|
766
1582
|
...GRAPH_PYTHON_FLAGS,
|
|
767
|
-
|
|
768
|
-
|
|
1583
|
+
path11.resolve(getInitAssetsDir(), "..", "graph", "graphify-native.py"),
|
|
1584
|
+
path11.toNamespacedPath(analysis),
|
|
769
1585
|
"inventory"
|
|
770
1586
|
],
|
|
771
1587
|
{ cwd: analysis, env: graphifyCorpusEnvironment(root, analysis) }
|
|
@@ -776,12 +1592,12 @@ async function safeDocumentCopy(root, analysis, run) {
|
|
|
776
1592
|
if (typeof inventory !== "object" || inventory === null || Object.keys(inventory).length !== 1 || !("files" in inventory) || !Array.isArray(inventory.files))
|
|
777
1593
|
return false;
|
|
778
1594
|
for (const file of inventory.files) {
|
|
779
|
-
if (typeof file !== "string" ||
|
|
1595
|
+
if (typeof file !== "string" || path11.posix.isAbsolute(file) || path11.win32.isAbsolute(file))
|
|
780
1596
|
return false;
|
|
781
1597
|
const parts = file.replaceAll("\\", "/").split("/");
|
|
782
|
-
if (parts.some((part) => !part || part === "." || part === "..") || excludedGraphInput(parts.join("/")))
|
|
1598
|
+
if (parts.some((part) => !part || part === "." || part === "..") || excludedGraphInput(parts.join("/"), deliberationDir))
|
|
783
1599
|
return false;
|
|
784
|
-
const stats = await
|
|
1600
|
+
const stats = await lstat7(path11.join(analysis, ...parts));
|
|
785
1601
|
if (!stats.isFile() || stats.isSymbolicLink() || stats.nlink !== 1) return false;
|
|
786
1602
|
}
|
|
787
1603
|
return true;
|
|
@@ -799,103 +1615,10 @@ async function discard(directory) {
|
|
|
799
1615
|
// src/core/graph/locks.ts
|
|
800
1616
|
import { randomUUID as randomUUID5 } from "crypto";
|
|
801
1617
|
import { unlink } from "fs/promises";
|
|
802
|
-
import
|
|
803
|
-
|
|
804
|
-
// src/core/graph/localFiles.ts
|
|
805
|
-
import { lstat as lstat7, mkdir as mkdir6, open as open2 } from "fs/promises";
|
|
806
|
-
import path10 from "path";
|
|
807
|
-
|
|
808
|
-
// src/core/init/fsGuards.ts
|
|
809
|
-
import { constants } from "fs";
|
|
810
|
-
import { access as access2, lstat as lstat6, open, readFile as readFile2, stat } from "fs/promises";
|
|
811
|
-
import path9 from "path";
|
|
812
|
-
async function readPinnedRegularFileBytes(filePath, maxBytes) {
|
|
813
|
-
let handle;
|
|
814
|
-
try {
|
|
815
|
-
handle = await open(filePath, OPEN_READ_FLAGS);
|
|
816
|
-
const pinned = await handle.stat();
|
|
817
|
-
if (!pinned.isFile() || pinned.size > maxBytes) return null;
|
|
818
|
-
const buffer = Buffer.alloc(maxBytes + 1);
|
|
819
|
-
let filled = 0;
|
|
820
|
-
while (filled < buffer.length) {
|
|
821
|
-
const { bytesRead } = await handle.read(buffer, filled, buffer.length - filled, filled);
|
|
822
|
-
if (bytesRead === 0) break;
|
|
823
|
-
filled += bytesRead;
|
|
824
|
-
}
|
|
825
|
-
if (filled > maxBytes) return null;
|
|
826
|
-
return {
|
|
827
|
-
content: Buffer.from(buffer.subarray(0, filled)),
|
|
828
|
-
mode: pinned.mode & 4095,
|
|
829
|
-
uid: pinned.uid,
|
|
830
|
-
gid: pinned.gid,
|
|
831
|
-
dev: pinned.dev,
|
|
832
|
-
ino: pinned.ino
|
|
833
|
-
};
|
|
834
|
-
} catch (error) {
|
|
835
|
-
const code = error?.code;
|
|
836
|
-
if (code === "ENXIO" || code === "EISDIR") return null;
|
|
837
|
-
throw error;
|
|
838
|
-
} finally {
|
|
839
|
-
await handle?.close();
|
|
840
|
-
}
|
|
841
|
-
}
|
|
842
|
-
var OPEN_READ_FLAGS = typeof constants.O_NONBLOCK === "number" ? constants.O_RDONLY | constants.O_NONBLOCK : constants.O_RDONLY;
|
|
843
|
-
|
|
844
|
-
// src/core/graph/localFiles.ts
|
|
845
|
-
var GRAPH_STATE_BYTES = 32768;
|
|
846
|
-
var GRAPH_UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
|
|
847
|
-
var GraphLocalStateError = class extends Error {
|
|
848
|
-
constructor(message, recovery, options) {
|
|
849
|
-
super(message, options);
|
|
850
|
-
this.recovery = recovery;
|
|
851
|
-
}
|
|
852
|
-
};
|
|
853
|
-
async function graphStateDirectory(root) {
|
|
854
|
-
const directory = path10.join(root, ".qfai", "tools", "state", graphEnvironmentKey());
|
|
855
|
-
await assertGraphStoragePath(root, directory);
|
|
856
|
-
await mkdir6(directory, { recursive: true });
|
|
857
|
-
await assertGraphStoragePath(root, directory);
|
|
858
|
-
return directory;
|
|
859
|
-
}
|
|
860
|
-
function invalidGraphState() {
|
|
861
|
-
return new GraphLocalStateError(
|
|
862
|
-
"Project graph permission state is invalid.",
|
|
863
|
-
"Retain the local state and repair .qfai/tools/state before retrying the graph CLI or hook."
|
|
864
|
-
);
|
|
865
|
-
}
|
|
866
|
-
function graphStateText(value, maximum) {
|
|
867
|
-
return typeof value === "string" && value.trim().length > 0 && value.length <= maximum && !value.includes("\0");
|
|
868
|
-
}
|
|
869
|
-
async function readGraphLocalFile(file) {
|
|
870
|
-
try {
|
|
871
|
-
const before = await lstat7(file);
|
|
872
|
-
if (!before.isFile() || before.isSymbolicLink() || before.nlink !== 1)
|
|
873
|
-
throw invalidGraphState();
|
|
874
|
-
const pinned = await readPinnedRegularFileBytes(file, GRAPH_STATE_BYTES);
|
|
875
|
-
const after = await lstat7(file);
|
|
876
|
-
if (!pinned || before.dev !== pinned.dev || before.ino !== pinned.ino || after.dev !== pinned.dev || after.ino !== pinned.ino || !after.isFile() || after.isSymbolicLink() || after.nlink !== 1)
|
|
877
|
-
throw invalidGraphState();
|
|
878
|
-
return pinned.content.toString("utf8");
|
|
879
|
-
} catch (cause) {
|
|
880
|
-
if (isEnoent(cause)) return void 0;
|
|
881
|
-
throw cause;
|
|
882
|
-
}
|
|
883
|
-
}
|
|
884
|
-
async function writeGraphLocalFile(file, value) {
|
|
885
|
-
const text = JSON.stringify(value);
|
|
886
|
-
if (Buffer.byteLength(text) > GRAPH_STATE_BYTES) throw invalidGraphState();
|
|
887
|
-
const handle = await open2(file, "wx", 384);
|
|
888
|
-
try {
|
|
889
|
-
await handle.writeFile(text, "utf8");
|
|
890
|
-
} finally {
|
|
891
|
-
await handle.close();
|
|
892
|
-
}
|
|
893
|
-
}
|
|
894
|
-
|
|
895
|
-
// src/core/graph/locks.ts
|
|
1618
|
+
import path12 from "path";
|
|
896
1619
|
async function withGraphLock(root, kind, action) {
|
|
897
1620
|
const directory = await graphStateDirectory(root);
|
|
898
|
-
const file =
|
|
1621
|
+
const file = path12.join(directory, `${kind}.lock`);
|
|
899
1622
|
const owner = {
|
|
900
1623
|
kind: "graph-lock",
|
|
901
1624
|
pid: process.pid,
|
|
@@ -946,7 +1669,7 @@ async function releaseGraphLock(file, owner) {
|
|
|
946
1669
|
}
|
|
947
1670
|
|
|
948
1671
|
// src/core/graph/documents.ts
|
|
949
|
-
import
|
|
1672
|
+
import path13 from "path";
|
|
950
1673
|
function notCurrent() {
|
|
951
1674
|
return { current: false, unsupported: [], unreadable: [] };
|
|
952
1675
|
}
|
|
@@ -1005,7 +1728,7 @@ async function prepareDocumentAnalysisLocked(root, run = runGraphProcess, approv
|
|
|
1005
1728
|
}
|
|
1006
1729
|
}
|
|
1007
1730
|
const current = graphAnalysisRoot(root, "graphify");
|
|
1008
|
-
const staged =
|
|
1731
|
+
const staged = path13.join(path13.dirname(current), `.preparing-graphify-${randomUUID6()}`);
|
|
1009
1732
|
await assertGraphStoragePath(root, staged);
|
|
1010
1733
|
await mkdir7(staged, { recursive: true });
|
|
1011
1734
|
try {
|
|
@@ -1017,7 +1740,7 @@ async function prepareDocumentAnalysisLocked(root, run = runGraphProcess, approv
|
|
|
1017
1740
|
"-m",
|
|
1018
1741
|
"graphify",
|
|
1019
1742
|
"extract",
|
|
1020
|
-
|
|
1743
|
+
path13.toNamespacedPath(staged),
|
|
1021
1744
|
"--backend",
|
|
1022
1745
|
backend,
|
|
1023
1746
|
"--model",
|
|
@@ -1045,7 +1768,7 @@ async function prepareDocumentAnalysisLocked(root, run = runGraphProcess, approv
|
|
|
1045
1768
|
};
|
|
1046
1769
|
}
|
|
1047
1770
|
await writeFile3(
|
|
1048
|
-
|
|
1771
|
+
path13.join(staged, "graphify-out", "managed.json"),
|
|
1049
1772
|
JSON.stringify({ engineVersion: GRAPH_VERSIONS.graphify, scope: "documents", processing })
|
|
1050
1773
|
);
|
|
1051
1774
|
await assertIndependentAnalysis(staged);
|
|
@@ -1060,7 +1783,7 @@ async function prepareDocumentAnalysisLocked(root, run = runGraphProcess, approv
|
|
|
1060
1783
|
}
|
|
1061
1784
|
}
|
|
1062
1785
|
async function readGraphProcessing(root) {
|
|
1063
|
-
const processing = await readOptionalJson(
|
|
1786
|
+
const processing = await readOptionalJson(path13.join(root, ".qfai", "graph-processing.json"));
|
|
1064
1787
|
return validGraphProcessing(processing) ? processing : void 0;
|
|
1065
1788
|
}
|
|
1066
1789
|
function validGraphProcessing(processing) {
|
|
@@ -1088,7 +1811,7 @@ async function inspectDocumentScope(root, run) {
|
|
|
1088
1811
|
return inspectDocumentScopeAt(root, analysis, run);
|
|
1089
1812
|
}
|
|
1090
1813
|
async function inspectDocumentScopeAt(root, analysis, run, refresh = true) {
|
|
1091
|
-
const managed = await readOptionalJson(
|
|
1814
|
+
const managed = await readOptionalJson(path13.join(analysis, "graphify-out", "managed.json"));
|
|
1092
1815
|
const selected = await readGraphProcessing(root);
|
|
1093
1816
|
const processing = await processingForCompletedQuery(
|
|
1094
1817
|
root,
|
|
@@ -1105,7 +1828,7 @@ async function inspectDocumentScopeAt(root, analysis, run, refresh = true) {
|
|
|
1105
1828
|
async function processingForCompletedQuery(root, selected, recorded) {
|
|
1106
1829
|
if (selected !== void 0) return selected;
|
|
1107
1830
|
try {
|
|
1108
|
-
await
|
|
1831
|
+
await readFile4(path13.join(root, ".qfai", "graph-processing.json"));
|
|
1109
1832
|
return void 0;
|
|
1110
1833
|
} catch (cause) {
|
|
1111
1834
|
if (!isEnoent(cause)) throw cause;
|
|
@@ -1122,8 +1845,8 @@ async function nativeGraphifyScope(root, analysis, python, run, kind = "semantic
|
|
|
1122
1845
|
python,
|
|
1123
1846
|
[
|
|
1124
1847
|
...GRAPH_PYTHON_FLAGS,
|
|
1125
|
-
|
|
1126
|
-
|
|
1848
|
+
path13.resolve(getInitAssetsDir(), "..", "graph", "graphify-native.py"),
|
|
1849
|
+
path13.toNamespacedPath(analysis),
|
|
1127
1850
|
kind
|
|
1128
1851
|
],
|
|
1129
1852
|
{
|
|
@@ -1141,7 +1864,7 @@ async function nativeGraphifyScope(root, analysis, python, run, kind = "semantic
|
|
|
1141
1864
|
}
|
|
1142
1865
|
if (!object3(state) || typeof state.current !== "boolean" || !stringArray2(state.unsupported) || !stringArray2(state.unreadable))
|
|
1143
1866
|
return notCurrent();
|
|
1144
|
-
const sourcePath = (file) =>
|
|
1867
|
+
const sourcePath = (file) => path13.isAbsolute(file) ? path13.relative(path13.toNamespacedPath(analysis), path13.toNamespacedPath(file)).split(path13.sep).join("/") : file;
|
|
1145
1868
|
return {
|
|
1146
1869
|
current: state.current,
|
|
1147
1870
|
unsupported: state.unsupported.map(sourcePath),
|
|
@@ -1150,7 +1873,7 @@ async function nativeGraphifyScope(root, analysis, python, run, kind = "semantic
|
|
|
1150
1873
|
}
|
|
1151
1874
|
async function readOptionalJson(file) {
|
|
1152
1875
|
try {
|
|
1153
|
-
return JSON.parse(await
|
|
1876
|
+
return JSON.parse(await readFile4(file, "utf8"));
|
|
1154
1877
|
} catch (cause) {
|
|
1155
1878
|
if (isEnoent(cause) || cause instanceof SyntaxError) return void 0;
|
|
1156
1879
|
throw cause;
|
|
@@ -1170,7 +1893,7 @@ function stringArray2(value) {
|
|
|
1170
1893
|
}
|
|
1171
1894
|
function validDocumentScope(value) {
|
|
1172
1895
|
return Array.isArray(value) && value.length > 0 && value.every(
|
|
1173
|
-
(item) => typeof item === "string" && item !== "" && !
|
|
1896
|
+
(item) => typeof item === "string" && item !== "" && !path13.isAbsolute(item) && !item.split(/[\\/]/).some((part) => part === ".." || part === "." || part === "")
|
|
1174
1897
|
);
|
|
1175
1898
|
}
|
|
1176
1899
|
function providerConflict() {
|
|
@@ -1181,13 +1904,14 @@ function providerConflict() {
|
|
|
1181
1904
|
}
|
|
1182
1905
|
|
|
1183
1906
|
// src/core/graph/query.ts
|
|
1184
|
-
import { readFile as
|
|
1185
|
-
import
|
|
1907
|
+
import { readFile as readFile5 } from "fs/promises";
|
|
1908
|
+
import path14 from "path";
|
|
1186
1909
|
async function exploreGraph(root, request, run = runGraphProcess) {
|
|
1187
1910
|
const requestedScope = Object.freeze({ ...request });
|
|
1188
1911
|
try {
|
|
1189
1912
|
return { ...await exploreGraphScope(root, request, run), requestedScope };
|
|
1190
|
-
} catch {
|
|
1913
|
+
} catch (cause) {
|
|
1914
|
+
if (cause instanceof GraphConfigUnreadableError) throw cause;
|
|
1191
1915
|
const engine = request.domain === "code" ? "codegraph" : "graphify";
|
|
1192
1916
|
return {
|
|
1193
1917
|
requestedScope,
|
|
@@ -1210,8 +1934,8 @@ async function exploreGraphScope(root, request, run) {
|
|
|
1210
1934
|
"query",
|
|
1211
1935
|
request.question,
|
|
1212
1936
|
"--graph",
|
|
1213
|
-
|
|
1214
|
-
|
|
1937
|
+
path14.toNamespacedPath(
|
|
1938
|
+
path14.join(graphAnalysisRoot(root, "graphify"), "graphify-out", "graph.json")
|
|
1215
1939
|
)
|
|
1216
1940
|
],
|
|
1217
1941
|
{
|
|
@@ -1358,11 +2082,31 @@ async function queryPreparedGraph(root, request, run = runGraphProcess) {
|
|
|
1358
2082
|
// src/core/graph/fallbackState.ts
|
|
1359
2083
|
import { randomUUID as randomUUID7 } from "crypto";
|
|
1360
2084
|
import { rename as rename4, unlink as unlink3 } from "fs/promises";
|
|
2085
|
+
import path17 from "path";
|
|
2086
|
+
|
|
2087
|
+
// src/core/graph/hooks.ts
|
|
1361
2088
|
import path15 from "path";
|
|
2089
|
+
var redirectionSource = String.raw`(?:\d*|&|\{[A-Za-z_][A-Za-z0-9_]*\})`;
|
|
2090
|
+
var redirectionStart = new RegExp(String.raw`^${redirectionSource}(?:<|>)`);
|
|
2091
|
+
var detachedRedirection = new RegExp(String.raw`^${redirectionSource}(?:<>|>{1,2}|<{1,3})[&|]?$`);
|
|
2092
|
+
var DATA_FILE = String.raw`(?!/dev/|/proc/)[\w./-]+`;
|
|
2093
|
+
var DATA_OPERAND = String.raw`[ \t]+(?:-[A-Za-z]+|>>?[ \t]*${DATA_FILE}|>[ \t]*/dev/null|${DATA_FILE})`;
|
|
2094
|
+
var DATA_HEREDOC_LINE = new RegExp(
|
|
2095
|
+
String.raw`^[ \t]*(?:cat|tee)(?:${DATA_OPERAND})*[ \t]*<<-?[ \t]*(?:(['"])[A-Za-z_]\w*\1|\\[A-Za-z_]\w*)(?:${DATA_OPERAND})*[ \t]*$`
|
|
2096
|
+
);
|
|
2097
|
+
var DATA_PRELUDE_LINE = new RegExp(
|
|
2098
|
+
String.raw`^[ \t]*(?:mkdir[ \t]+-p(?:[ \t]+${DATA_FILE})+[ \t]*)?$`
|
|
2099
|
+
);
|
|
2100
|
+
var MESSAGE_WORD = String.raw`[ \t]+[\w./=:@-]+`;
|
|
2101
|
+
var MESSAGE_HEREDOC_LINE = new RegExp(
|
|
2102
|
+
String.raw`^[ \t]*(?:git[ \t]+(?:commit|tag)|gh[ \t]+(?:pr|issue|release)[ \t]+(?:create|edit|comment))(?:${MESSAGE_WORD})*[ \t]+"\$\(cat[ \t]+<<-?[ \t]*(?:(['"])[A-Za-z_]\w*\1|\\[A-Za-z_]\w*)[ \t]*$`
|
|
2103
|
+
);
|
|
2104
|
+
var MESSAGE_CLOSE_LINE = new RegExp(String.raw`^[ \t]*\)"(?:${MESSAGE_WORD})*[ \t]*$`);
|
|
2105
|
+
var MESSAGE_PRELUDE_LINE = new RegExp(String.raw`^[ \t]*git[ \t]+add(?:${MESSAGE_WORD})*[ \t]*$`);
|
|
1362
2106
|
|
|
1363
2107
|
// src/core/graph/permissionRecords.ts
|
|
1364
2108
|
import { opendir, unlink as unlink2 } from "fs/promises";
|
|
1365
|
-
import
|
|
2109
|
+
import path16 from "path";
|
|
1366
2110
|
async function readGraphSearchRecords(root, directory) {
|
|
1367
2111
|
const records = [];
|
|
1368
2112
|
const entries = await opendir(directory);
|
|
@@ -1371,7 +2115,7 @@ async function readGraphSearchRecords(root, directory) {
|
|
|
1371
2115
|
if (records.length >= 128) throw fullGraphState();
|
|
1372
2116
|
const match = /^(.+)\.(pending|grant|draft)\.json$/.exec(entry.name);
|
|
1373
2117
|
if (!match || !GRAPH_UUID.test(match[1] ?? "")) throw invalidGraphState();
|
|
1374
|
-
const file =
|
|
2118
|
+
const file = path16.join(directory, entry.name);
|
|
1375
2119
|
const text = await readGraphLocalFile(file);
|
|
1376
2120
|
if (text === void 0) throw invalidGraphState();
|
|
1377
2121
|
let input;
|
|
@@ -1413,7 +2157,7 @@ function parseGraphSearchRecord(input, root) {
|
|
|
1413
2157
|
"expiresAt"
|
|
1414
2158
|
];
|
|
1415
2159
|
if (value.kind === "grant") fields.push("reason");
|
|
1416
|
-
if (Object.keys(value).length !== fields.length || fields.some((field) => !Object.hasOwn(value, field)) || typeof value.id !== "string" || !GRAPH_UUID.test(value.id) || value.kind !== "pending" && value.kind !== "grant" || value.domain !== "code" && value.domain !== "documents" || !graphStateText(value.target, 4096) || !graphStateText(value.operation, 128) || !graphStateText(value.worktree, 4096) || value.worktree !==
|
|
2160
|
+
if (Object.keys(value).length !== fields.length || fields.some((field) => !Object.hasOwn(value, field)) || typeof value.id !== "string" || !GRAPH_UUID.test(value.id) || value.kind !== "pending" && value.kind !== "grant" || value.domain !== "code" && value.domain !== "documents" || !graphStateText(value.target, 4096) || !graphStateText(value.operation, 128) || !graphStateText(value.worktree, 4096) || value.worktree !== path16.resolve(root) || !graphStateText(value.session, 4096) || typeof value.createdAt !== "number" || typeof value.expiresAt !== "number" || !Number.isSafeInteger(value.createdAt) || value.createdAt < 0 || value.createdAt > Date.now() || !Number.isSafeInteger(value.expiresAt) || value.expiresAt !== value.createdAt + (value.kind === "pending" ? 6e5 : 6e4))
|
|
1417
2161
|
return void 0;
|
|
1418
2162
|
const scope = {
|
|
1419
2163
|
id: value.id,
|
|
@@ -1458,7 +2202,7 @@ async function requestStoredGraphFallback(root, attemptId, question, reason, run
|
|
|
1458
2202
|
createdAt,
|
|
1459
2203
|
expiresAt: createdAt + 6e4
|
|
1460
2204
|
};
|
|
1461
|
-
const draft =
|
|
2205
|
+
const draft = path17.join(directory, `${grant.id}.draft.json`);
|
|
1462
2206
|
await writeGraphLocalFile(draft, grant);
|
|
1463
2207
|
await unlink3(pending.file);
|
|
1464
2208
|
return { directory, draft, grant };
|
|
@@ -1467,7 +2211,7 @@ async function requestStoredGraphFallback(root, attemptId, question, reason, run
|
|
|
1467
2211
|
if (Date.now() >= publication.grant.expiresAt) throw invalidGraphState();
|
|
1468
2212
|
await rename4(
|
|
1469
2213
|
publication.draft,
|
|
1470
|
-
|
|
2214
|
+
path17.join(publication.directory, `${publication.grant.id}.grant.json`)
|
|
1471
2215
|
);
|
|
1472
2216
|
const { target, operation, worktree, session, expiresAt } = publication.grant;
|
|
1473
2217
|
return {
|