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.cjs
CHANGED
|
@@ -36,8 +36,8 @@ module.exports = __toCommonJS(graphCli_exports);
|
|
|
36
36
|
|
|
37
37
|
// src/core/graph/codePreparation.ts
|
|
38
38
|
var import_node_crypto3 = require("crypto");
|
|
39
|
-
var
|
|
40
|
-
var
|
|
39
|
+
var import_promises8 = require("fs/promises");
|
|
40
|
+
var import_node_path10 = __toESM(require("path"), 1);
|
|
41
41
|
|
|
42
42
|
// src/shared/assets.ts
|
|
43
43
|
var import_node_fs = require("fs");
|
|
@@ -299,13 +299,803 @@ var runGraphProcess = async (command, args, options) => {
|
|
|
299
299
|
|
|
300
300
|
// src/core/graph/reuse.ts
|
|
301
301
|
var import_node_os = __toESM(require("os"), 1);
|
|
302
|
-
var
|
|
302
|
+
var import_node_path9 = __toESM(require("path"), 1);
|
|
303
303
|
var import_node_crypto2 = require("crypto");
|
|
304
|
-
var
|
|
304
|
+
var import_promises7 = require("fs/promises");
|
|
305
305
|
|
|
306
306
|
// src/core/graph/analysis.ts
|
|
307
|
-
var
|
|
307
|
+
var import_node_path8 = __toESM(require("path"), 1);
|
|
308
|
+
var import_promises6 = require("fs/promises");
|
|
309
|
+
|
|
310
|
+
// src/core/config.ts
|
|
308
311
|
var import_promises3 = require("fs/promises");
|
|
312
|
+
var import_node_path5 = __toESM(require("path"), 1);
|
|
313
|
+
var import_yaml = require("yaml");
|
|
314
|
+
|
|
315
|
+
// src/shared/shippedWorkflowNames.ts
|
|
316
|
+
var SHIPPED_WORKFLOW_NAMES = /* @__PURE__ */ new Set([
|
|
317
|
+
"qfai-validate.yml",
|
|
318
|
+
"qfai-tests.yml",
|
|
319
|
+
"qfai-docs.yml"
|
|
320
|
+
]);
|
|
321
|
+
|
|
322
|
+
// src/core/config.ts
|
|
323
|
+
var defaultConfig = {
|
|
324
|
+
paths: {
|
|
325
|
+
contractsDir: ".qfai/spec/03_contract",
|
|
326
|
+
specsDir: ".qfai/spec",
|
|
327
|
+
deliberationDir: ".qfai/deliberation",
|
|
328
|
+
outDir: ".qfai/report",
|
|
329
|
+
skillsDir: ".qfai/assistant/skill",
|
|
330
|
+
srcDir: "src",
|
|
331
|
+
testsDir: "tests"
|
|
332
|
+
},
|
|
333
|
+
validation: {
|
|
334
|
+
failOn: "error",
|
|
335
|
+
testStrategy: {
|
|
336
|
+
forbidTestTodoStubs: true
|
|
337
|
+
},
|
|
338
|
+
traceability: {
|
|
339
|
+
testFileGlobs: [],
|
|
340
|
+
testFileExcludeGlobs: []
|
|
341
|
+
}
|
|
342
|
+
},
|
|
343
|
+
output: {
|
|
344
|
+
validateJsonPath: ".qfai/report/validate.json"
|
|
345
|
+
},
|
|
346
|
+
prototyping: {
|
|
347
|
+
execution: {
|
|
348
|
+
targetUrl: null,
|
|
349
|
+
browserTool: "playwright"
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
};
|
|
353
|
+
function getConfigPath(root) {
|
|
354
|
+
return import_node_path5.default.join(root, "qfai.config.yaml");
|
|
355
|
+
}
|
|
356
|
+
async function loadConfig(root) {
|
|
357
|
+
const configPath = getConfigPath(root);
|
|
358
|
+
const issues = [];
|
|
359
|
+
let parsed;
|
|
360
|
+
try {
|
|
361
|
+
const raw = await (0, import_promises3.readFile)(configPath, "utf-8");
|
|
362
|
+
parsed = (0, import_yaml.parse)(raw);
|
|
363
|
+
} catch (error) {
|
|
364
|
+
if (isEnoent(error)) {
|
|
365
|
+
return { config: defaultConfig, issues, configPath };
|
|
366
|
+
}
|
|
367
|
+
issues.push(configIssue(configPath, "The configuration file could not be read or parsed."));
|
|
368
|
+
return { config: defaultConfig, issues, configPath };
|
|
369
|
+
}
|
|
370
|
+
const normalized = normalizeConfig(parsed, configPath, issues);
|
|
371
|
+
if (readWorkflowMode(parsed) === null) {
|
|
372
|
+
issues.push(configIssue(configPath, WORKFLOW_MODE_MESSAGE));
|
|
373
|
+
}
|
|
374
|
+
if (readSkippedWorkflows(parsed) === null) {
|
|
375
|
+
issues.push(configIssue(configPath, SKIPPED_WORKFLOWS_MESSAGE));
|
|
376
|
+
}
|
|
377
|
+
if (readAcceptedDrift(parsed) === null) {
|
|
378
|
+
issues.push(configIssue(configPath, ACCEPTED_DRIFT_MESSAGE));
|
|
379
|
+
}
|
|
380
|
+
if (readStopGate(parsed) === null) {
|
|
381
|
+
issues.push(configIssue(configPath, STOP_GATE_MESSAGE));
|
|
382
|
+
}
|
|
383
|
+
return { config: normalized, issues, configPath, document: parsed };
|
|
384
|
+
}
|
|
385
|
+
var STOP_GATE_MESSAGE = "workflow.stopGate must be true or false; an absent key means true.";
|
|
386
|
+
function readStopGate(document) {
|
|
387
|
+
const workflow = isRecord(document) ? document.workflow : void 0;
|
|
388
|
+
if (workflow === void 0) return true;
|
|
389
|
+
if (!isRecord(workflow)) return null;
|
|
390
|
+
if (workflow.stopGate === void 0) return true;
|
|
391
|
+
return typeof workflow.stopGate === "boolean" ? workflow.stopGate : null;
|
|
392
|
+
}
|
|
393
|
+
var WORKFLOW_MODES = ["active", "shadow", "off"];
|
|
394
|
+
var WORKFLOW_MODE_MESSAGE = "workflow.mode must be active, shadow or off; an absent key means active.";
|
|
395
|
+
function readWorkflowMode(document) {
|
|
396
|
+
const workflow = isRecord(document) ? document.workflow : void 0;
|
|
397
|
+
if (workflow === void 0) return "active";
|
|
398
|
+
if (!isRecord(workflow)) return null;
|
|
399
|
+
const mode = workflow.mode;
|
|
400
|
+
if (mode === void 0) return "active";
|
|
401
|
+
return WORKFLOW_MODES.find((known) => known === mode) ?? null;
|
|
402
|
+
}
|
|
403
|
+
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.`;
|
|
404
|
+
function readSkippedWorkflows(document) {
|
|
405
|
+
const workflow = isRecord(document) ? document.workflow : void 0;
|
|
406
|
+
if (!isRecord(workflow) || workflow.skipShipped === void 0) return /* @__PURE__ */ new Set();
|
|
407
|
+
const listed = workflow.skipShipped;
|
|
408
|
+
if (!Array.isArray(listed)) return null;
|
|
409
|
+
const names = /* @__PURE__ */ new Set();
|
|
410
|
+
for (const name of listed) {
|
|
411
|
+
if (typeof name !== "string" || !SHIPPED_WORKFLOW_NAMES.has(name)) return null;
|
|
412
|
+
names.add(name);
|
|
413
|
+
}
|
|
414
|
+
return names;
|
|
415
|
+
}
|
|
416
|
+
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.`;
|
|
417
|
+
var DRIFT_DIGEST = /^sha256:[0-9a-f]{64}$/;
|
|
418
|
+
function readAcceptedDrift(document) {
|
|
419
|
+
const workflow = isRecord(document) ? document.workflow : void 0;
|
|
420
|
+
if (!isRecord(workflow) || workflow.acceptedDrift === void 0) return /* @__PURE__ */ new Map();
|
|
421
|
+
const listed = workflow.acceptedDrift;
|
|
422
|
+
if (!Array.isArray(listed)) return null;
|
|
423
|
+
const accepted = /* @__PURE__ */ new Map();
|
|
424
|
+
for (const entry of listed) {
|
|
425
|
+
if (!isRecord(entry)) return null;
|
|
426
|
+
const { file, digest, reason } = entry;
|
|
427
|
+
if (typeof file !== "string" || !SHIPPED_WORKFLOW_NAMES.has(file) || accepted.has(file)) {
|
|
428
|
+
return null;
|
|
429
|
+
}
|
|
430
|
+
if (typeof digest !== "string" || !DRIFT_DIGEST.test(digest)) return null;
|
|
431
|
+
if (typeof reason !== "string" || reason.trim() === "") return null;
|
|
432
|
+
accepted.set(file, { digest, reason: reason.trim() });
|
|
433
|
+
}
|
|
434
|
+
return accepted;
|
|
435
|
+
}
|
|
436
|
+
function resolvePath(root, config, key) {
|
|
437
|
+
return import_node_path5.default.resolve(root, config.paths[key]);
|
|
438
|
+
}
|
|
439
|
+
function normalizeConfig(raw, configPath, issues) {
|
|
440
|
+
if (!isRecord(raw)) {
|
|
441
|
+
issues.push(configIssue(configPath, "The configuration file format is invalid."));
|
|
442
|
+
return defaultConfig;
|
|
443
|
+
}
|
|
444
|
+
const uiux = normalizeUiux(raw.uiux, configPath, issues);
|
|
445
|
+
const prototyping = normalizePrototyping(raw.prototyping, configPath, issues);
|
|
446
|
+
const report = normalizeReport(raw.report, configPath, issues);
|
|
447
|
+
const base = {
|
|
448
|
+
paths: normalizePaths(raw.paths, configPath, issues),
|
|
449
|
+
validation: normalizeValidation(raw.validation, configPath, issues),
|
|
450
|
+
output: normalizeOutput(raw.output, configPath, issues)
|
|
451
|
+
};
|
|
452
|
+
if (uiux) {
|
|
453
|
+
base.uiux = uiux;
|
|
454
|
+
}
|
|
455
|
+
if (prototyping) {
|
|
456
|
+
base.prototyping = prototyping;
|
|
457
|
+
}
|
|
458
|
+
if (report) {
|
|
459
|
+
base.report = report;
|
|
460
|
+
}
|
|
461
|
+
const baseBranch = readOptionalString(raw.baseBranch, "baseBranch", configPath, issues);
|
|
462
|
+
if (baseBranch !== void 0) {
|
|
463
|
+
base.baseBranch = baseBranch;
|
|
464
|
+
}
|
|
465
|
+
return base;
|
|
466
|
+
}
|
|
467
|
+
function normalizePaths(raw, configPath, issues) {
|
|
468
|
+
const base = defaultConfig.paths;
|
|
469
|
+
if (!raw) {
|
|
470
|
+
return base;
|
|
471
|
+
}
|
|
472
|
+
if (!isRecord(raw)) {
|
|
473
|
+
issues.push(configIssue(configPath, "paths must be an object."));
|
|
474
|
+
return base;
|
|
475
|
+
}
|
|
476
|
+
const migrationsDir = readOptionalString(
|
|
477
|
+
raw.migrationsDir,
|
|
478
|
+
"paths.migrationsDir",
|
|
479
|
+
configPath,
|
|
480
|
+
issues
|
|
481
|
+
);
|
|
482
|
+
return {
|
|
483
|
+
...migrationsDir !== void 0 ? { migrationsDir } : {},
|
|
484
|
+
contractsDir: readTreeDirString(
|
|
485
|
+
raw.contractsDir,
|
|
486
|
+
base.contractsDir,
|
|
487
|
+
"paths.contractsDir",
|
|
488
|
+
configPath,
|
|
489
|
+
issues
|
|
490
|
+
),
|
|
491
|
+
specsDir: readTreeDirString(raw.specsDir, base.specsDir, "paths.specsDir", configPath, issues),
|
|
492
|
+
deliberationDir: readDeliberationDir(
|
|
493
|
+
raw.deliberationDir,
|
|
494
|
+
base.deliberationDir,
|
|
495
|
+
configPath,
|
|
496
|
+
issues
|
|
497
|
+
),
|
|
498
|
+
outDir: readDirString(raw.outDir, base.outDir, "paths.outDir", configPath, issues),
|
|
499
|
+
skillsDir: readDirString(raw.skillsDir, base.skillsDir, "paths.skillsDir", configPath, issues),
|
|
500
|
+
srcDir: readDirString(raw.srcDir, base.srcDir, "paths.srcDir", configPath, issues),
|
|
501
|
+
testsDir: readDirString(raw.testsDir, base.testsDir, "paths.testsDir", configPath, issues)
|
|
502
|
+
};
|
|
503
|
+
}
|
|
504
|
+
function normalizeValidation(raw, configPath, issues) {
|
|
505
|
+
const base = defaultConfig.validation;
|
|
506
|
+
if (!raw) {
|
|
507
|
+
return base;
|
|
508
|
+
}
|
|
509
|
+
if (!isRecord(raw)) {
|
|
510
|
+
issues.push(configIssue(configPath, "validation must be an object."));
|
|
511
|
+
return base;
|
|
512
|
+
}
|
|
513
|
+
let traceabilityRaw;
|
|
514
|
+
if (raw.traceability === void 0) {
|
|
515
|
+
traceabilityRaw = void 0;
|
|
516
|
+
} else if (isRecord(raw.traceability)) {
|
|
517
|
+
traceabilityRaw = raw.traceability;
|
|
518
|
+
} else {
|
|
519
|
+
issues.push(configIssue(configPath, "validation.traceability must be an object."));
|
|
520
|
+
traceabilityRaw = void 0;
|
|
521
|
+
}
|
|
522
|
+
let testStrategyRaw;
|
|
523
|
+
if (raw.testStrategy === void 0) {
|
|
524
|
+
testStrategyRaw = void 0;
|
|
525
|
+
} else if (isRecord(raw.testStrategy)) {
|
|
526
|
+
testStrategyRaw = raw.testStrategy;
|
|
527
|
+
} else {
|
|
528
|
+
issues.push(configIssue(configPath, "validation.testStrategy must be an object."));
|
|
529
|
+
testStrategyRaw = void 0;
|
|
530
|
+
}
|
|
531
|
+
reportRetiredTraceabilityKeys(traceabilityRaw, configPath, issues);
|
|
532
|
+
const forbiddenIdentifiers = normalizeForbiddenIdentifiers(
|
|
533
|
+
raw.forbiddenIdentifiers,
|
|
534
|
+
configPath,
|
|
535
|
+
issues
|
|
536
|
+
);
|
|
537
|
+
const staleTerms = readStringArray(
|
|
538
|
+
raw.staleTerms,
|
|
539
|
+
[],
|
|
540
|
+
"validation.staleTerms",
|
|
541
|
+
configPath,
|
|
542
|
+
issues
|
|
543
|
+
);
|
|
544
|
+
const diagramBudget = readDiagramBudget(raw.diagramBudget, configPath, issues);
|
|
545
|
+
return {
|
|
546
|
+
failOn: readFailOn(raw.failOn, base.failOn, "validation.failOn", configPath, issues),
|
|
547
|
+
...staleTerms.length > 0 ? { staleTerms } : {},
|
|
548
|
+
...diagramBudget !== void 0 ? { diagramBudget } : {},
|
|
549
|
+
...forbiddenIdentifiers !== void 0 ? { forbiddenIdentifiers } : {},
|
|
550
|
+
testStrategy: {
|
|
551
|
+
forbidTestTodoStubs: readBoolean(
|
|
552
|
+
testStrategyRaw?.forbidTestTodoStubs,
|
|
553
|
+
base.testStrategy.forbidTestTodoStubs,
|
|
554
|
+
"validation.testStrategy.forbidTestTodoStubs",
|
|
555
|
+
configPath,
|
|
556
|
+
issues
|
|
557
|
+
)
|
|
558
|
+
},
|
|
559
|
+
traceability: {
|
|
560
|
+
testFileGlobs: readStringArray(
|
|
561
|
+
traceabilityRaw?.testFileGlobs,
|
|
562
|
+
base.traceability.testFileGlobs,
|
|
563
|
+
"validation.traceability.testFileGlobs",
|
|
564
|
+
configPath,
|
|
565
|
+
issues
|
|
566
|
+
),
|
|
567
|
+
testFileExcludeGlobs: readStringArray(
|
|
568
|
+
traceabilityRaw?.testFileExcludeGlobs,
|
|
569
|
+
base.traceability.testFileExcludeGlobs,
|
|
570
|
+
"validation.traceability.testFileExcludeGlobs",
|
|
571
|
+
configPath,
|
|
572
|
+
issues
|
|
573
|
+
)
|
|
574
|
+
}
|
|
575
|
+
};
|
|
576
|
+
}
|
|
577
|
+
function normalizeForbiddenIdentifiers(raw, configPath, issues) {
|
|
578
|
+
if (raw === void 0) return void 0;
|
|
579
|
+
const invalid = () => {
|
|
580
|
+
issues.push(configIssue(configPath, "validation.forbiddenIdentifiers is invalid."));
|
|
581
|
+
return void 0;
|
|
582
|
+
};
|
|
583
|
+
if (!Array.isArray(raw) || raw.length > 64) {
|
|
584
|
+
invalid();
|
|
585
|
+
return void 0;
|
|
586
|
+
}
|
|
587
|
+
const entries = [];
|
|
588
|
+
const pairs = /* @__PURE__ */ new Set();
|
|
589
|
+
const lengths = /* @__PURE__ */ new Set();
|
|
590
|
+
for (const entry of raw) {
|
|
591
|
+
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) {
|
|
592
|
+
invalid();
|
|
593
|
+
return void 0;
|
|
594
|
+
}
|
|
595
|
+
const pair = `${entry.sha256}:${entry.byteLength}`;
|
|
596
|
+
if (pairs.has(pair)) {
|
|
597
|
+
invalid();
|
|
598
|
+
return void 0;
|
|
599
|
+
}
|
|
600
|
+
pairs.add(pair);
|
|
601
|
+
lengths.add(entry.byteLength);
|
|
602
|
+
if (lengths.size > 8) {
|
|
603
|
+
invalid();
|
|
604
|
+
return void 0;
|
|
605
|
+
}
|
|
606
|
+
entries.push({ sha256: entry.sha256, byteLength: entry.byteLength });
|
|
607
|
+
}
|
|
608
|
+
return entries;
|
|
609
|
+
}
|
|
610
|
+
function normalizeOutput(raw, configPath, issues) {
|
|
611
|
+
const base = defaultConfig.output;
|
|
612
|
+
if (!raw) {
|
|
613
|
+
return base;
|
|
614
|
+
}
|
|
615
|
+
if (!isRecord(raw)) {
|
|
616
|
+
issues.push(configIssue(configPath, "output must be an object."));
|
|
617
|
+
return base;
|
|
618
|
+
}
|
|
619
|
+
return {
|
|
620
|
+
validateJsonPath: readString(
|
|
621
|
+
raw.validateJsonPath,
|
|
622
|
+
base.validateJsonPath,
|
|
623
|
+
"output.validateJsonPath",
|
|
624
|
+
configPath,
|
|
625
|
+
issues
|
|
626
|
+
)
|
|
627
|
+
};
|
|
628
|
+
}
|
|
629
|
+
function normalizePrototyping(raw, configPath, issues) {
|
|
630
|
+
if (raw === void 0 || raw === null) {
|
|
631
|
+
return void 0;
|
|
632
|
+
}
|
|
633
|
+
if (!isRecord(raw)) {
|
|
634
|
+
issues.push(configIssue(configPath, "prototyping must be an object."));
|
|
635
|
+
return void 0;
|
|
636
|
+
}
|
|
637
|
+
const execution = normalizePrototypingExecution(raw.execution, configPath, issues);
|
|
638
|
+
if (Object.prototype.hasOwnProperty.call(raw, "primarySpecId")) {
|
|
639
|
+
issues.push(
|
|
640
|
+
configIssue(
|
|
641
|
+
configPath,
|
|
642
|
+
"prototyping.primarySpecId is retired; use prototyping.primaryUiContract: UI-NNNN."
|
|
643
|
+
)
|
|
644
|
+
);
|
|
645
|
+
}
|
|
646
|
+
const primaryUiContract = normalizePrimaryUiContract(raw.primaryUiContract, configPath, issues);
|
|
647
|
+
if (!execution && primaryUiContract === void 0) {
|
|
648
|
+
return void 0;
|
|
649
|
+
}
|
|
650
|
+
return {
|
|
651
|
+
...execution ? { execution } : {},
|
|
652
|
+
...primaryUiContract !== void 0 ? { primaryUiContract } : {}
|
|
653
|
+
};
|
|
654
|
+
}
|
|
655
|
+
function normalizePrimaryUiContract(raw, configPath, issues) {
|
|
656
|
+
if (raw === void 0 || raw === null) {
|
|
657
|
+
return void 0;
|
|
658
|
+
}
|
|
659
|
+
if (typeof raw !== "string" || !/^UI-\d{4}$/.test(raw)) {
|
|
660
|
+
issues.push(configIssue(configPath, primaryUiContractMessage(raw)));
|
|
661
|
+
return void 0;
|
|
662
|
+
}
|
|
663
|
+
return raw;
|
|
664
|
+
}
|
|
665
|
+
function primaryUiContractMessage(raw) {
|
|
666
|
+
return `prototyping.primaryUiContract must be a full UI-NNNN ID; received ${JSON.stringify(raw)}.`;
|
|
667
|
+
}
|
|
668
|
+
function normalizePrototypingExecution(raw, configPath, issues) {
|
|
669
|
+
const base = defaultConfig.prototyping?.execution;
|
|
670
|
+
if (raw === void 0 || raw === null) {
|
|
671
|
+
return base ? { ...base } : void 0;
|
|
672
|
+
}
|
|
673
|
+
if (!isRecord(raw)) {
|
|
674
|
+
issues.push(configIssue(configPath, "prototyping.execution must be an object."));
|
|
675
|
+
return base ? { ...base } : void 0;
|
|
676
|
+
}
|
|
677
|
+
const browserToolRaw = raw.browserTool;
|
|
678
|
+
const browserTool = "playwright";
|
|
679
|
+
if (browserToolRaw !== void 0 && browserToolRaw !== browserTool) {
|
|
680
|
+
issues.push(
|
|
681
|
+
configIssue(
|
|
682
|
+
configPath,
|
|
683
|
+
`prototyping.execution.browserTool must be "playwright". Received: ${JSON.stringify(browserToolRaw)}`
|
|
684
|
+
)
|
|
685
|
+
);
|
|
686
|
+
}
|
|
687
|
+
return {
|
|
688
|
+
targetUrl: raw.targetUrl === null ? null : readOptionalString(
|
|
689
|
+
raw.targetUrl,
|
|
690
|
+
"prototyping.execution.targetUrl",
|
|
691
|
+
configPath,
|
|
692
|
+
issues
|
|
693
|
+
) ?? null,
|
|
694
|
+
browserTool
|
|
695
|
+
};
|
|
696
|
+
}
|
|
697
|
+
function readNonNegativeInteger(raw, field, configPath, issues) {
|
|
698
|
+
if (typeof raw === "number" && Number.isFinite(raw) && Number.isInteger(raw) && raw >= 0) {
|
|
699
|
+
return raw;
|
|
700
|
+
}
|
|
701
|
+
issues.push(configIssue(configPath, `${field} must be an integer greater than or equal to 0.`));
|
|
702
|
+
return void 0;
|
|
703
|
+
}
|
|
704
|
+
function normalizeReport(raw, configPath, issues) {
|
|
705
|
+
if (raw === void 0 || raw === null) {
|
|
706
|
+
return void 0;
|
|
707
|
+
}
|
|
708
|
+
if (!isRecord(raw)) {
|
|
709
|
+
issues.push(configIssue(configPath, "report must be an object."));
|
|
710
|
+
return void 0;
|
|
711
|
+
}
|
|
712
|
+
const result = {};
|
|
713
|
+
if (raw.staleTtlDays !== void 0) {
|
|
714
|
+
const value = readNonNegativeInteger(
|
|
715
|
+
raw.staleTtlDays,
|
|
716
|
+
"report.staleTtlDays",
|
|
717
|
+
configPath,
|
|
718
|
+
issues
|
|
719
|
+
);
|
|
720
|
+
if (value !== void 0) {
|
|
721
|
+
result.staleTtlDays = value;
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
if (raw.keepLatestRuns !== void 0) {
|
|
725
|
+
const value = readNonNegativeInteger(
|
|
726
|
+
raw.keepLatestRuns,
|
|
727
|
+
"report.keepLatestRuns",
|
|
728
|
+
configPath,
|
|
729
|
+
issues
|
|
730
|
+
);
|
|
731
|
+
if (value !== void 0) {
|
|
732
|
+
result.keepLatestRuns = value;
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
return Object.keys(result).length === 0 ? void 0 : result;
|
|
736
|
+
}
|
|
737
|
+
function readString(value, fallback, label, configPath, issues) {
|
|
738
|
+
if (typeof value === "string" && value.trim().length > 0) {
|
|
739
|
+
return value;
|
|
740
|
+
}
|
|
741
|
+
if (value !== void 0) {
|
|
742
|
+
issues.push(configIssue(configPath, `${label} must be a string.`));
|
|
743
|
+
}
|
|
744
|
+
return fallback;
|
|
745
|
+
}
|
|
746
|
+
function readDirString(value, fallback, label, configPath, issues) {
|
|
747
|
+
const raw = readString(value, fallback, label, configPath, issues);
|
|
748
|
+
const trimmed = raw.replace(/[\\/]+$/, "");
|
|
749
|
+
return trimmed.length > 0 ? trimmed : raw;
|
|
750
|
+
}
|
|
751
|
+
function readTreeDirString(value, fallback, label, configPath, issues) {
|
|
752
|
+
return readDirString(value, fallback, label, configPath, issues).replace(/\\/g, "/");
|
|
753
|
+
}
|
|
754
|
+
function readDeliberationDir(value, fallback, configPath, issues) {
|
|
755
|
+
const dir = readTreeDirString(value, fallback, "paths.deliberationDir", configPath, issues);
|
|
756
|
+
if (isDirectoryInsideRoot(import_node_path5.default.dirname(configPath), dir)) return dir;
|
|
757
|
+
issues.push(configIssue(configPath, DELIBERATION_DIR_OUTSIDE_ROOT_MESSAGE));
|
|
758
|
+
return fallback;
|
|
759
|
+
}
|
|
760
|
+
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.";
|
|
761
|
+
function isDirectoryInsideRoot(root, dir) {
|
|
762
|
+
const relative = import_node_path5.default.relative(root, import_node_path5.default.resolve(root, dir));
|
|
763
|
+
return !dir.split(/[\\/]/).some((part) => part !== "." && part !== ".." && /[. ]$/.test(part)) && relative !== "" && relative !== ".." && !relative.startsWith(`..${import_node_path5.default.sep}`) && !import_node_path5.default.isAbsolute(relative);
|
|
764
|
+
}
|
|
765
|
+
function readOptionalString(value, label, configPath, issues) {
|
|
766
|
+
if (value === void 0) {
|
|
767
|
+
return void 0;
|
|
768
|
+
}
|
|
769
|
+
if (typeof value === "string" && value.trim().length > 0) {
|
|
770
|
+
return value;
|
|
771
|
+
}
|
|
772
|
+
issues.push(configIssue(configPath, `${label} must be a non-empty string.`));
|
|
773
|
+
return void 0;
|
|
774
|
+
}
|
|
775
|
+
function readStringArray(value, fallback, label, configPath, issues) {
|
|
776
|
+
if (Array.isArray(value) && value.every((item) => typeof item === "string")) {
|
|
777
|
+
return value;
|
|
778
|
+
}
|
|
779
|
+
if (value !== void 0) {
|
|
780
|
+
issues.push(configIssue(configPath, `${label} must be an array of strings.`));
|
|
781
|
+
}
|
|
782
|
+
return fallback;
|
|
783
|
+
}
|
|
784
|
+
function readDiagramBudget(value, configPath, issues) {
|
|
785
|
+
if (value === void 0) {
|
|
786
|
+
return void 0;
|
|
787
|
+
}
|
|
788
|
+
if (!isRecord(value)) {
|
|
789
|
+
issues.push(configIssue(configPath, "validation.diagramBudget must be an object."));
|
|
790
|
+
return void 0;
|
|
791
|
+
}
|
|
792
|
+
for (const key of Object.keys(value)) {
|
|
793
|
+
if (key !== "nodes" && key !== "edges") {
|
|
794
|
+
issues.push(configIssue(configPath, `validation.diagramBudget.${key} is not a setting.`));
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
const budget = {};
|
|
798
|
+
for (const key of ["nodes", "edges"]) {
|
|
799
|
+
const limit = value[key];
|
|
800
|
+
if (limit === void 0) {
|
|
801
|
+
continue;
|
|
802
|
+
}
|
|
803
|
+
if (typeof limit === "number" && Number.isInteger(limit) && limit >= 1) {
|
|
804
|
+
budget[key] = limit;
|
|
805
|
+
} else {
|
|
806
|
+
issues.push(
|
|
807
|
+
configIssue(configPath, `validation.diagramBudget.${key} must be an integer of 1 or more.`)
|
|
808
|
+
);
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
return budget;
|
|
812
|
+
}
|
|
813
|
+
function readBoolean(value, fallback, label, configPath, issues) {
|
|
814
|
+
if (typeof value === "boolean") {
|
|
815
|
+
return value;
|
|
816
|
+
}
|
|
817
|
+
if (value !== void 0) {
|
|
818
|
+
issues.push(configIssue(configPath, `${label} must be a boolean.`));
|
|
819
|
+
}
|
|
820
|
+
return fallback;
|
|
821
|
+
}
|
|
822
|
+
function readFailOn(value, fallback, label, configPath, issues) {
|
|
823
|
+
if (value === "never" || value === "warning" || value === "error") {
|
|
824
|
+
return value;
|
|
825
|
+
}
|
|
826
|
+
if (value !== void 0) {
|
|
827
|
+
issues.push(configIssue(configPath, `${label} must be one of never|warning|error.`));
|
|
828
|
+
}
|
|
829
|
+
return fallback;
|
|
830
|
+
}
|
|
831
|
+
var RETIRED_TRACEABILITY_KEYS = ["scMustHaveTest", "unknownContractIdSeverity"];
|
|
832
|
+
function reportRetiredTraceabilityKeys(traceabilityRaw, configPath, issues) {
|
|
833
|
+
if (!traceabilityRaw) {
|
|
834
|
+
return;
|
|
835
|
+
}
|
|
836
|
+
for (const key of RETIRED_TRACEABILITY_KEYS) {
|
|
837
|
+
if (traceabilityRaw[key] === void 0) {
|
|
838
|
+
continue;
|
|
839
|
+
}
|
|
840
|
+
issues.push(
|
|
841
|
+
configDeprecatedIssue(
|
|
842
|
+
configPath,
|
|
843
|
+
`validation.traceability.${key} is retired. No check reads it, so setting it changes nothing. Remove it from qfai.config.yaml.`
|
|
844
|
+
)
|
|
845
|
+
);
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
function normalizeUiux(raw, configPath, issues) {
|
|
849
|
+
if (raw === void 0 || raw === null) {
|
|
850
|
+
return void 0;
|
|
851
|
+
}
|
|
852
|
+
if (!isRecord(raw)) {
|
|
853
|
+
issues.push(configIssue(configPath, "uiux must be an object."));
|
|
854
|
+
return void 0;
|
|
855
|
+
}
|
|
856
|
+
const result = {};
|
|
857
|
+
if (raw.platform !== void 0) {
|
|
858
|
+
if (typeof raw.platform === "string" && raw.platform.trim().length > 0) {
|
|
859
|
+
result.platform = raw.platform;
|
|
860
|
+
} else {
|
|
861
|
+
issues.push(configIssue(configPath, "uiux.platform must be a non-empty string."));
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
if (raw.designTokensDir !== void 0) {
|
|
865
|
+
if (typeof raw.designTokensDir === "string" && raw.designTokensDir.trim().length > 0) {
|
|
866
|
+
result.designTokensDir = raw.designTokensDir;
|
|
867
|
+
} else {
|
|
868
|
+
issues.push(configIssue(configPath, "uiux.designTokensDir must be a non-empty string."));
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
if (raw.htmlMockTimeout !== void 0) {
|
|
872
|
+
if (typeof raw.htmlMockTimeout === "number" && Number.isFinite(raw.htmlMockTimeout) && raw.htmlMockTimeout > 0) {
|
|
873
|
+
result.htmlMockTimeout = raw.htmlMockTimeout;
|
|
874
|
+
} else {
|
|
875
|
+
issues.push(configIssue(configPath, "uiux.htmlMockTimeout must be a positive number."));
|
|
876
|
+
}
|
|
877
|
+
}
|
|
878
|
+
if (raw.qualityProfile !== void 0) {
|
|
879
|
+
if (typeof raw.qualityProfile === "string" && ["strict", "high", "default"].includes(raw.qualityProfile)) {
|
|
880
|
+
result.qualityProfile = raw.qualityProfile;
|
|
881
|
+
} else {
|
|
882
|
+
issues.push(
|
|
883
|
+
configIssue(configPath, "uiux.qualityProfile must be one of strict|high|default.")
|
|
884
|
+
);
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
if (raw.surfacePaths !== void 0) {
|
|
888
|
+
const surfacePaths = raw.surfacePaths;
|
|
889
|
+
if (Array.isArray(surfacePaths) && surfacePaths.every(
|
|
890
|
+
(entry) => typeof entry === "string" && entry.trim().length > 0
|
|
891
|
+
)) {
|
|
892
|
+
result.surfacePaths = surfacePaths.map((entry) => entry.trim());
|
|
893
|
+
} else {
|
|
894
|
+
issues.push(
|
|
895
|
+
configIssue(configPath, "uiux.surfacePaths must be a list of non-empty glob strings.")
|
|
896
|
+
);
|
|
897
|
+
}
|
|
898
|
+
}
|
|
899
|
+
if (raw.registries !== void 0) {
|
|
900
|
+
const registries = normalizeUiuxRegistries(raw.registries, configPath, issues);
|
|
901
|
+
if (registries) {
|
|
902
|
+
result.registries = registries;
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
if (raw.audit !== void 0) {
|
|
906
|
+
const audit = normalizeUiuxAudit(raw.audit, configPath, issues);
|
|
907
|
+
if (audit) {
|
|
908
|
+
result.audit = audit;
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
return Object.keys(result).length > 0 ? result : void 0;
|
|
912
|
+
}
|
|
913
|
+
function normalizeUiuxRegistries(raw, configPath, issues) {
|
|
914
|
+
if (!isRecord(raw)) {
|
|
915
|
+
issues.push(configIssue(configPath, "uiux.registries must be an object."));
|
|
916
|
+
return void 0;
|
|
917
|
+
}
|
|
918
|
+
const result = {};
|
|
919
|
+
for (const [name, url] of Object.entries(raw)) {
|
|
920
|
+
if (typeof url !== "string" || url.trim().length === 0) {
|
|
921
|
+
issues.push(configIssue(configPath, `uiux.registries.${name} must be a non-empty string.`));
|
|
922
|
+
continue;
|
|
923
|
+
}
|
|
924
|
+
if (!url.includes("{name}")) {
|
|
925
|
+
issues.push(
|
|
926
|
+
configIssue(
|
|
927
|
+
configPath,
|
|
928
|
+
`uiux.registries.${name} must contain the {name} placeholder, or it resolves no component.`
|
|
929
|
+
)
|
|
930
|
+
);
|
|
931
|
+
continue;
|
|
932
|
+
}
|
|
933
|
+
result[name] = url;
|
|
934
|
+
}
|
|
935
|
+
return Object.keys(result).length > 0 ? result : void 0;
|
|
936
|
+
}
|
|
937
|
+
function normalizeUiuxAudit(raw, configPath, issues) {
|
|
938
|
+
if (!isRecord(raw)) {
|
|
939
|
+
issues.push(configIssue(configPath, "uiux.audit must be an object."));
|
|
940
|
+
return void 0;
|
|
941
|
+
}
|
|
942
|
+
const result = {};
|
|
943
|
+
if (raw.enabled !== void 0) {
|
|
944
|
+
if (typeof raw.enabled === "boolean") {
|
|
945
|
+
result.enabled = raw.enabled;
|
|
946
|
+
} else {
|
|
947
|
+
issues.push(configIssue(configPath, "uiux.audit.enabled must be a boolean."));
|
|
948
|
+
}
|
|
949
|
+
}
|
|
950
|
+
if (raw.slopDetection !== void 0) {
|
|
951
|
+
if (typeof raw.slopDetection === "boolean") {
|
|
952
|
+
result.slopDetection = raw.slopDetection;
|
|
953
|
+
} else {
|
|
954
|
+
issues.push(configIssue(configPath, "uiux.audit.slopDetection must be a boolean."));
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
if (raw.maxRawTokenLiteralWarnings !== void 0) {
|
|
958
|
+
if (typeof raw.maxRawTokenLiteralWarnings === "number" && Number.isFinite(raw.maxRawTokenLiteralWarnings) && raw.maxRawTokenLiteralWarnings >= 0) {
|
|
959
|
+
result.maxRawTokenLiteralWarnings = raw.maxRawTokenLiteralWarnings;
|
|
960
|
+
} else {
|
|
961
|
+
issues.push(
|
|
962
|
+
configIssue(
|
|
963
|
+
configPath,
|
|
964
|
+
"uiux.audit.maxRawTokenLiteralWarnings must be a number greater than or equal to 0."
|
|
965
|
+
)
|
|
966
|
+
);
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
if (raw.maxDuplicateFindingsPerRule !== void 0) {
|
|
970
|
+
if (typeof raw.maxDuplicateFindingsPerRule === "number" && Number.isFinite(raw.maxDuplicateFindingsPerRule) && raw.maxDuplicateFindingsPerRule >= 0) {
|
|
971
|
+
result.maxDuplicateFindingsPerRule = raw.maxDuplicateFindingsPerRule;
|
|
972
|
+
} else {
|
|
973
|
+
issues.push(
|
|
974
|
+
configIssue(
|
|
975
|
+
configPath,
|
|
976
|
+
"uiux.audit.maxDuplicateFindingsPerRule must be a number greater than or equal to 0."
|
|
977
|
+
)
|
|
978
|
+
);
|
|
979
|
+
}
|
|
980
|
+
}
|
|
981
|
+
return Object.keys(result).length > 0 ? result : void 0;
|
|
982
|
+
}
|
|
983
|
+
function configIssue(file, message) {
|
|
984
|
+
return {
|
|
985
|
+
code: "QFAI-CFG-002",
|
|
986
|
+
severity: "error",
|
|
987
|
+
category: "canonical",
|
|
988
|
+
message,
|
|
989
|
+
file,
|
|
990
|
+
rule: "config.invalid"
|
|
991
|
+
};
|
|
992
|
+
}
|
|
993
|
+
function configDeprecatedIssue(file, message) {
|
|
994
|
+
return {
|
|
995
|
+
code: "QFAI-CFG-001",
|
|
996
|
+
severity: "error",
|
|
997
|
+
category: "canonical",
|
|
998
|
+
message,
|
|
999
|
+
file,
|
|
1000
|
+
rule: "config.deprecatedKey"
|
|
1001
|
+
};
|
|
1002
|
+
}
|
|
1003
|
+
function isRecord(value) {
|
|
1004
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
1005
|
+
}
|
|
1006
|
+
|
|
1007
|
+
// src/core/graph/localFiles.ts
|
|
1008
|
+
var import_promises5 = require("fs/promises");
|
|
1009
|
+
var import_node_path7 = __toESM(require("path"), 1);
|
|
1010
|
+
|
|
1011
|
+
// src/core/init/fsGuards.ts
|
|
1012
|
+
var import_node_fs2 = require("fs");
|
|
1013
|
+
var import_promises4 = require("fs/promises");
|
|
1014
|
+
var import_node_path6 = __toESM(require("path"), 1);
|
|
1015
|
+
async function readPinnedRegularFileBytes(filePath, maxBytes) {
|
|
1016
|
+
let handle;
|
|
1017
|
+
try {
|
|
1018
|
+
handle = await (0, import_promises4.open)(filePath, OPEN_READ_FLAGS);
|
|
1019
|
+
const pinned = await handle.stat();
|
|
1020
|
+
if (!pinned.isFile() || pinned.size > maxBytes) return null;
|
|
1021
|
+
const buffer = Buffer.alloc(maxBytes + 1);
|
|
1022
|
+
let filled = 0;
|
|
1023
|
+
while (filled < buffer.length) {
|
|
1024
|
+
const { bytesRead } = await handle.read(buffer, filled, buffer.length - filled, filled);
|
|
1025
|
+
if (bytesRead === 0) break;
|
|
1026
|
+
filled += bytesRead;
|
|
1027
|
+
}
|
|
1028
|
+
if (filled > maxBytes) return null;
|
|
1029
|
+
return {
|
|
1030
|
+
content: Buffer.from(buffer.subarray(0, filled)),
|
|
1031
|
+
mode: pinned.mode & 4095,
|
|
1032
|
+
uid: pinned.uid,
|
|
1033
|
+
gid: pinned.gid,
|
|
1034
|
+
dev: pinned.dev,
|
|
1035
|
+
ino: pinned.ino
|
|
1036
|
+
};
|
|
1037
|
+
} catch (error) {
|
|
1038
|
+
const code = error?.code;
|
|
1039
|
+
if (code === "ENXIO" || code === "EISDIR") return null;
|
|
1040
|
+
throw error;
|
|
1041
|
+
} finally {
|
|
1042
|
+
await handle?.close();
|
|
1043
|
+
}
|
|
1044
|
+
}
|
|
1045
|
+
var OPEN_READ_FLAGS = typeof import_node_fs2.constants.O_NONBLOCK === "number" ? import_node_fs2.constants.O_RDONLY | import_node_fs2.constants.O_NONBLOCK : import_node_fs2.constants.O_RDONLY;
|
|
1046
|
+
|
|
1047
|
+
// src/core/graph/localFiles.ts
|
|
1048
|
+
var GRAPH_STATE_BYTES = 32768;
|
|
1049
|
+
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}$/;
|
|
1050
|
+
var GraphLocalStateError = class extends Error {
|
|
1051
|
+
constructor(message, recovery, options) {
|
|
1052
|
+
super(message, options);
|
|
1053
|
+
this.recovery = recovery;
|
|
1054
|
+
}
|
|
1055
|
+
};
|
|
1056
|
+
async function graphStateDirectory(root) {
|
|
1057
|
+
const directory = import_node_path7.default.join(root, ".qfai", "tools", "state", graphEnvironmentKey());
|
|
1058
|
+
await assertGraphStoragePath(root, directory);
|
|
1059
|
+
await (0, import_promises5.mkdir)(directory, { recursive: true });
|
|
1060
|
+
await assertGraphStoragePath(root, directory);
|
|
1061
|
+
return directory;
|
|
1062
|
+
}
|
|
1063
|
+
function invalidGraphState() {
|
|
1064
|
+
return new GraphLocalStateError(
|
|
1065
|
+
"Project graph permission state is invalid.",
|
|
1066
|
+
"Retain the local state and repair .qfai/tools/state before retrying the graph CLI or hook."
|
|
1067
|
+
);
|
|
1068
|
+
}
|
|
1069
|
+
function graphStateText(value, maximum) {
|
|
1070
|
+
return typeof value === "string" && value.trim().length > 0 && value.length <= maximum && !value.includes("\0");
|
|
1071
|
+
}
|
|
1072
|
+
async function readGraphLocalFile(file) {
|
|
1073
|
+
try {
|
|
1074
|
+
const before = await (0, import_promises5.lstat)(file);
|
|
1075
|
+
if (!before.isFile() || before.isSymbolicLink() || before.nlink !== 1)
|
|
1076
|
+
throw invalidGraphState();
|
|
1077
|
+
const pinned = await readPinnedRegularFileBytes(file, GRAPH_STATE_BYTES);
|
|
1078
|
+
const after = await (0, import_promises5.lstat)(file);
|
|
1079
|
+
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)
|
|
1080
|
+
throw invalidGraphState();
|
|
1081
|
+
return pinned.content.toString("utf8");
|
|
1082
|
+
} catch (cause) {
|
|
1083
|
+
if (isEnoent(cause)) return void 0;
|
|
1084
|
+
throw cause;
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
1087
|
+
async function writeGraphLocalFile(file, value) {
|
|
1088
|
+
const text = JSON.stringify(value);
|
|
1089
|
+
if (Buffer.byteLength(text) > GRAPH_STATE_BYTES) throw invalidGraphState();
|
|
1090
|
+
const handle = await (0, import_promises5.open)(file, "wx", 384);
|
|
1091
|
+
try {
|
|
1092
|
+
await handle.writeFile(text, "utf8");
|
|
1093
|
+
} finally {
|
|
1094
|
+
await handle.close();
|
|
1095
|
+
}
|
|
1096
|
+
}
|
|
1097
|
+
|
|
1098
|
+
// src/core/graph/analysis.ts
|
|
309
1099
|
async function inspectCodeCoverage(root, run) {
|
|
310
1100
|
const unknown = { complete: false, unsupported: [], unreadable: [], unparsed: [] };
|
|
311
1101
|
const runtime = graphRuntimePaths(root);
|
|
@@ -314,7 +1104,7 @@ async function inspectCodeCoverage(root, run) {
|
|
|
314
1104
|
runtime.codegraphNode,
|
|
315
1105
|
[
|
|
316
1106
|
"--liftoff-only",
|
|
317
|
-
|
|
1107
|
+
import_node_path8.default.resolve(getInitAssetsDir(), "..", "graph", "codegraph-native.mjs"),
|
|
318
1108
|
runtime.codegraphSdk,
|
|
319
1109
|
analysis,
|
|
320
1110
|
"coverage"
|
|
@@ -347,7 +1137,7 @@ async function inspectCurrentCodeAnalysis(root, run) {
|
|
|
347
1137
|
async function inspectCodeAnalysisAt(root, analysis, run) {
|
|
348
1138
|
await assertGraphStoragePath(root, analysis);
|
|
349
1139
|
try {
|
|
350
|
-
if (!(await (0,
|
|
1140
|
+
if (!(await (0, import_promises6.lstat)(import_node_path8.default.join(analysis, ".codegraph", "codegraph.db"))).isFile()) return false;
|
|
351
1141
|
} catch (cause) {
|
|
352
1142
|
if (isEnoent(cause)) return false;
|
|
353
1143
|
throw cause;
|
|
@@ -389,10 +1179,30 @@ var excludedDirectories = /* @__PURE__ */ new Set([
|
|
|
389
1179
|
".aws",
|
|
390
1180
|
".azure"
|
|
391
1181
|
]);
|
|
392
|
-
|
|
1182
|
+
var GraphConfigUnreadableError = class extends GraphLocalStateError {
|
|
1183
|
+
constructor(configFile, unreadable) {
|
|
1184
|
+
super(
|
|
1185
|
+
unreadable ? `${configFile} could not be read or parsed.` : `${configFile} gives no usable paths.deliberationDir.`,
|
|
1186
|
+
`Correct ${configFile}, then retry.`
|
|
1187
|
+
);
|
|
1188
|
+
}
|
|
1189
|
+
};
|
|
1190
|
+
async function graphDeliberationDir(root) {
|
|
1191
|
+
const { config, document, issues, configPath } = await loadConfig(root);
|
|
1192
|
+
const file = import_node_path8.default.basename(configPath);
|
|
1193
|
+
if (document === void 0 && issues.length > 0) throw new GraphConfigUnreadableError(file, true);
|
|
1194
|
+
const paths = object(document) ? document.paths : void 0;
|
|
1195
|
+
const value = object(paths) ? paths.deliberationDir : void 0;
|
|
1196
|
+
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, "/"))))
|
|
1197
|
+
throw new GraphConfigUnreadableError(file, false);
|
|
1198
|
+
return import_node_path8.default.relative(root, resolvePath(root, config, "deliberationDir")).split(import_node_path8.default.sep).join("/");
|
|
1199
|
+
}
|
|
1200
|
+
function excludedGraphInput(relative, deliberationDir) {
|
|
393
1201
|
const parts = relative.split("/");
|
|
394
1202
|
const name = parts.at(-1) ?? "";
|
|
395
|
-
|
|
1203
|
+
const lowered = relative.toLowerCase();
|
|
1204
|
+
const deliberation = deliberationDir.toLowerCase();
|
|
1205
|
+
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(
|
|
396
1206
|
name
|
|
397
1207
|
);
|
|
398
1208
|
}
|
|
@@ -400,14 +1210,15 @@ async function mirrorGraphCorpus(root, destination, scope) {
|
|
|
400
1210
|
await assertGraphStoragePath(root, destination);
|
|
401
1211
|
await assertIndependentAnalysis(destination);
|
|
402
1212
|
const files = /* @__PURE__ */ new Set();
|
|
1213
|
+
const deliberationDir = await graphDeliberationDir(root);
|
|
403
1214
|
await visit("");
|
|
404
1215
|
await removeAbsent("");
|
|
405
1216
|
async function visit(relative) {
|
|
406
|
-
for (const entry of await (0,
|
|
1217
|
+
for (const entry of await (0, import_promises6.readdir)(import_node_path8.default.join(root, ...relative.split("/")), {
|
|
407
1218
|
withFileTypes: true
|
|
408
1219
|
})) {
|
|
409
1220
|
const next = relative ? `${relative}/${entry.name}` : entry.name;
|
|
410
|
-
if (excludedGraphInput(next) || entry.isSymbolicLink()) continue;
|
|
1221
|
+
if (excludedGraphInput(next, deliberationDir) || entry.isSymbolicLink()) continue;
|
|
411
1222
|
if (scope && !scope.some(
|
|
412
1223
|
(item) => item === next || next.startsWith(`${item}/`) || item.startsWith(`${next}/`)
|
|
413
1224
|
))
|
|
@@ -415,26 +1226,26 @@ async function mirrorGraphCorpus(root, destination, scope) {
|
|
|
415
1226
|
if (entry.isDirectory()) {
|
|
416
1227
|
await visit(next);
|
|
417
1228
|
} else if (entry.isFile()) {
|
|
418
|
-
const source =
|
|
419
|
-
const stats = await (0,
|
|
1229
|
+
const source = import_node_path8.default.join(root, ...next.split("/"));
|
|
1230
|
+
const stats = await (0, import_promises6.lstat)(source);
|
|
420
1231
|
if (!stats.isFile() || stats.nlink > 1) continue;
|
|
421
|
-
const target =
|
|
422
|
-
await (0,
|
|
423
|
-
await (0,
|
|
1232
|
+
const target = import_node_path8.default.join(destination, ...next.split("/"));
|
|
1233
|
+
await (0, import_promises6.mkdir)(import_node_path8.default.dirname(target), { recursive: true });
|
|
1234
|
+
await (0, import_promises6.copyFile)(source, target);
|
|
424
1235
|
files.add(next);
|
|
425
1236
|
}
|
|
426
1237
|
}
|
|
427
1238
|
}
|
|
428
1239
|
async function removeAbsent(relative) {
|
|
429
|
-
for (const entry of await (0,
|
|
1240
|
+
for (const entry of await (0, import_promises6.readdir)(import_node_path8.default.join(destination, ...relative.split("/")), {
|
|
430
1241
|
withFileTypes: true
|
|
431
1242
|
})) {
|
|
432
1243
|
const next = relative ? `${relative}/${entry.name}` : entry.name;
|
|
433
1244
|
if (entry.name === ".codegraph" || entry.name === ".git" || entry.name === "graphify-out")
|
|
434
1245
|
continue;
|
|
435
|
-
const target =
|
|
1246
|
+
const target = import_node_path8.default.join(destination, ...next.split("/"));
|
|
436
1247
|
if (entry.isDirectory()) await removeAbsent(next);
|
|
437
|
-
else if (!files.has(next)) await (0,
|
|
1248
|
+
else if (!files.has(next)) await (0, import_promises6.rm)(target);
|
|
438
1249
|
}
|
|
439
1250
|
}
|
|
440
1251
|
}
|
|
@@ -461,36 +1272,38 @@ async function restoreCompletedCodeAnalysis(root, run, environment = graphReuseE
|
|
|
461
1272
|
if (!location) return "cold";
|
|
462
1273
|
let candidates;
|
|
463
1274
|
try {
|
|
464
|
-
candidates = await (0,
|
|
1275
|
+
candidates = await (0, import_promises7.readdir)(location.directory, { withFileTypes: true });
|
|
465
1276
|
} catch (cause) {
|
|
466
1277
|
if (isEnoent(cause)) return "cold";
|
|
467
1278
|
throw cause;
|
|
468
1279
|
}
|
|
1280
|
+
const deliberationDir = await graphDeliberationDir(root);
|
|
469
1281
|
for (const entry of candidates) {
|
|
470
1282
|
if (!entry.isDirectory() || entry.isSymbolicLink() || entry.name.startsWith(".")) continue;
|
|
471
|
-
const candidate =
|
|
1283
|
+
const candidate = import_node_path9.default.join(location.directory, entry.name);
|
|
472
1284
|
if (!await cacheDirectorySafe(location.repository, candidate)) continue;
|
|
473
1285
|
const metadata = await readSnapshotMetadata(candidate);
|
|
474
1286
|
if (!metadata || Object.keys(metadata).some(
|
|
475
1287
|
(key) => !["layout", "corpusPolicy", "repository", "engineVersion", "environment"].includes(key)
|
|
476
1288
|
) || metadata.layout !== 1 || metadata.corpusPolicy !== 1 || metadata.repository !== location.repository || metadata.engineVersion !== GRAPH_VERSIONS.codegraph || !sameEnvironment(metadata.environment, environment))
|
|
477
1289
|
continue;
|
|
478
|
-
if (!await safeCompletedCorpus(
|
|
479
|
-
if (!await safeCodegraphInputs(root,
|
|
1290
|
+
if (!await safeCompletedCorpus(import_node_path9.default.join(candidate, "analysis"), deliberationDir)) continue;
|
|
1291
|
+
if (!await safeCodegraphInputs(root, import_node_path9.default.join(candidate, "analysis"), run, deliberationDir))
|
|
1292
|
+
continue;
|
|
480
1293
|
const current = graphAnalysisRoot(root, "codegraph");
|
|
481
|
-
const staged =
|
|
1294
|
+
const staged = import_node_path9.default.join(import_node_path9.default.dirname(current), `.restoring-codegraph-${(0, import_node_crypto2.randomUUID)()}`);
|
|
482
1295
|
await assertGraphStoragePath(root, staged);
|
|
483
1296
|
try {
|
|
484
|
-
const cached =
|
|
1297
|
+
const cached = import_node_path9.default.join(candidate, "analysis");
|
|
485
1298
|
await assertIndependentAnalysis(cached);
|
|
486
|
-
await (0,
|
|
487
|
-
await (0,
|
|
1299
|
+
await (0, import_promises7.mkdir)(import_node_path9.default.dirname(staged), { recursive: true });
|
|
1300
|
+
await (0, import_promises7.cp)(cached, staged, { recursive: true, dereference: false });
|
|
488
1301
|
await assertIndependentAnalysis(staged);
|
|
489
1302
|
if (!await inspectCodeAnalysisAt(root, staged, run)) continue;
|
|
490
1303
|
await replaceGraphDirectory(staged, current, root);
|
|
491
1304
|
return "restored";
|
|
492
1305
|
} finally {
|
|
493
|
-
await (0,
|
|
1306
|
+
await (0, import_promises7.rm)(staged, { recursive: true, force: true });
|
|
494
1307
|
}
|
|
495
1308
|
}
|
|
496
1309
|
return "cold";
|
|
@@ -499,11 +1312,11 @@ async function completedAnalysisCache(root, engine, run, environment = graphReus
|
|
|
499
1312
|
const git = await run("git", ["rev-parse", "--path-format=absolute", "--git-common-dir"], {
|
|
500
1313
|
cwd: root
|
|
501
1314
|
});
|
|
502
|
-
if (git.exitCode !== 0 || !
|
|
503
|
-
const repository = await (0,
|
|
1315
|
+
if (git.exitCode !== 0 || !import_node_path9.default.isAbsolute(git.stdout.trim())) return void 0;
|
|
1316
|
+
const repository = await (0, import_promises7.realpath)(git.stdout.trim());
|
|
504
1317
|
return {
|
|
505
1318
|
repository,
|
|
506
|
-
directory:
|
|
1319
|
+
directory: import_node_path9.default.join(repository, "qfai-graph-cache", graphEnvironmentKey(environment), engine)
|
|
507
1320
|
};
|
|
508
1321
|
}
|
|
509
1322
|
async function publishCompletedCodeAnalysis(root, run, environment = graphReuseEnvironment()) {
|
|
@@ -520,19 +1333,20 @@ async function publishCompletedCodeAnalysis(root, run, environment = graphReuseE
|
|
|
520
1333
|
if (!cache) return "unavailable";
|
|
521
1334
|
await ensureCacheDirectory(cache.repository, cache.directory);
|
|
522
1335
|
const analysis = graphAnalysisRoot(root, "codegraph");
|
|
523
|
-
|
|
1336
|
+
const deliberationDir = await graphDeliberationDir(root);
|
|
1337
|
+
if (!await safeCompletedCorpus(analysis, deliberationDir) || !await safeCodegraphInputs(root, analysis, run, deliberationDir))
|
|
524
1338
|
return "unavailable";
|
|
525
1339
|
const identity = (0, import_node_crypto2.randomUUID)();
|
|
526
|
-
staged =
|
|
527
|
-
await (0,
|
|
528
|
-
await (0,
|
|
529
|
-
await assertIndependentAnalysis(
|
|
530
|
-
if (!await safeCompletedCorpus(
|
|
1340
|
+
staged = import_node_path9.default.join(cache.directory, `.publishing-${identity}`);
|
|
1341
|
+
await (0, import_promises7.mkdir)(staged);
|
|
1342
|
+
await (0, import_promises7.cp)(analysis, import_node_path9.default.join(staged, "analysis"), { recursive: true, dereference: false });
|
|
1343
|
+
await assertIndependentAnalysis(import_node_path9.default.join(staged, "analysis"));
|
|
1344
|
+
if (!await safeCompletedCorpus(import_node_path9.default.join(staged, "analysis"), deliberationDir) || !await safeCodegraphInputs(root, import_node_path9.default.join(staged, "analysis"), run, deliberationDir))
|
|
531
1345
|
return "unavailable";
|
|
532
|
-
if (!await nativeCodeAnalysisCurrent(root,
|
|
1346
|
+
if (!await nativeCodeAnalysisCurrent(root, import_node_path9.default.join(staged, "analysis"), run))
|
|
533
1347
|
return "unavailable";
|
|
534
|
-
await (0,
|
|
535
|
-
|
|
1348
|
+
await (0, import_promises7.writeFile)(
|
|
1349
|
+
import_node_path9.default.join(staged, "completed.json"),
|
|
536
1350
|
JSON.stringify({
|
|
537
1351
|
layout: 1,
|
|
538
1352
|
corpusPolicy: 1,
|
|
@@ -541,50 +1355,50 @@ async function publishCompletedCodeAnalysis(root, run, environment = graphReuseE
|
|
|
541
1355
|
environment
|
|
542
1356
|
}) + "\n"
|
|
543
1357
|
);
|
|
544
|
-
await (0,
|
|
1358
|
+
await (0, import_promises7.rename)(staged, import_node_path9.default.join(cache.directory, identity));
|
|
545
1359
|
return "published";
|
|
546
1360
|
} catch {
|
|
547
1361
|
return "unavailable";
|
|
548
1362
|
} finally {
|
|
549
|
-
if (staged) await (0,
|
|
1363
|
+
if (staged) await (0, import_promises7.rm)(staged, { recursive: true, force: true });
|
|
550
1364
|
}
|
|
551
1365
|
}
|
|
552
1366
|
async function ensureCacheDirectory(repository, directory) {
|
|
553
|
-
const relative =
|
|
554
|
-
const parts = relative.split(
|
|
555
|
-
if (
|
|
1367
|
+
const relative = import_node_path9.default.relative(repository, directory);
|
|
1368
|
+
const parts = relative.split(import_node_path9.default.sep);
|
|
1369
|
+
if (import_node_path9.default.isAbsolute(relative) || parts.includes("..") || parts[0] !== "qfai-graph-cache")
|
|
556
1370
|
throw new Error("Unsafe completed analysis path.");
|
|
557
1371
|
for (let depth = 1; depth <= parts.length; depth += 1) {
|
|
558
|
-
const component =
|
|
1372
|
+
const component = import_node_path9.default.join(repository, ...parts.slice(0, depth));
|
|
559
1373
|
let stats;
|
|
560
1374
|
try {
|
|
561
|
-
stats = await (0,
|
|
1375
|
+
stats = await (0, import_promises7.lstat)(component);
|
|
562
1376
|
} catch (cause) {
|
|
563
1377
|
if (!isEnoent(cause)) throw cause;
|
|
564
|
-
await (0,
|
|
565
|
-
stats = await (0,
|
|
1378
|
+
await (0, import_promises7.mkdir)(component);
|
|
1379
|
+
stats = await (0, import_promises7.lstat)(component);
|
|
566
1380
|
}
|
|
567
1381
|
if (stats.isSymbolicLink() || !stats.isDirectory())
|
|
568
1382
|
throw new Error("Unsafe completed analysis path.");
|
|
569
1383
|
}
|
|
570
1384
|
}
|
|
571
1385
|
async function cacheDirectorySafe(repository, candidate) {
|
|
572
|
-
const relative =
|
|
573
|
-
const parts = relative.split(
|
|
574
|
-
if (
|
|
1386
|
+
const relative = import_node_path9.default.relative(repository, candidate);
|
|
1387
|
+
const parts = relative.split(import_node_path9.default.sep);
|
|
1388
|
+
if (import_node_path9.default.isAbsolute(relative) || parts.includes("..") || parts[0] !== "qfai-graph-cache")
|
|
575
1389
|
return false;
|
|
576
1390
|
for (let depth = 1; depth <= parts.length; depth += 1) {
|
|
577
|
-
const stats = await (0,
|
|
1391
|
+
const stats = await (0, import_promises7.lstat)(import_node_path9.default.join(repository, ...parts.slice(0, depth)));
|
|
578
1392
|
if (stats.isSymbolicLink() || !stats.isDirectory()) return false;
|
|
579
1393
|
}
|
|
580
1394
|
return true;
|
|
581
1395
|
}
|
|
582
1396
|
async function readSnapshotMetadata(candidate) {
|
|
583
1397
|
try {
|
|
584
|
-
const stats = await (0,
|
|
1398
|
+
const stats = await (0, import_promises7.lstat)(import_node_path9.default.join(candidate, "completed.json"));
|
|
585
1399
|
if (!stats.isFile() || stats.isSymbolicLink() || stats.nlink !== 1) return void 0;
|
|
586
1400
|
const metadata = JSON.parse(
|
|
587
|
-
await (0,
|
|
1401
|
+
await (0, import_promises7.readFile)(import_node_path9.default.join(candidate, "completed.json"), "utf8")
|
|
588
1402
|
);
|
|
589
1403
|
return object2(metadata) ? metadata : void 0;
|
|
590
1404
|
} catch (cause) {
|
|
@@ -595,18 +1409,18 @@ async function readSnapshotMetadata(candidate) {
|
|
|
595
1409
|
function sameEnvironment(value, environment) {
|
|
596
1410
|
return object2(value) && Object.keys(value).length === 3 && value.platform === environment.platform && value.architecture === environment.architecture && value.machine === environment.machine;
|
|
597
1411
|
}
|
|
598
|
-
async function safeCompletedCorpus(directory, relative = "", engineDirectory = ".codegraph") {
|
|
1412
|
+
async function safeCompletedCorpus(directory, deliberationDir, relative = "", engineDirectory = ".codegraph") {
|
|
599
1413
|
try {
|
|
600
|
-
for (const entry of await (0,
|
|
1414
|
+
for (const entry of await (0, import_promises7.readdir)(import_node_path9.default.join(directory, ...relative.split("/")), {
|
|
601
1415
|
withFileTypes: true
|
|
602
1416
|
})) {
|
|
603
1417
|
const next = relative ? `${relative}/${entry.name}` : entry.name;
|
|
604
1418
|
const input = next.startsWith(`${engineDirectory}/`) ? next.slice(engineDirectory.length + 1) : next;
|
|
605
|
-
if (next !== engineDirectory && excludedGraphInput(input) || /\.(?:pid|lock)$/i.test(entry.name))
|
|
1419
|
+
if (next !== engineDirectory && excludedGraphInput(input, deliberationDir) || /\.(?:pid|lock)$/i.test(entry.name))
|
|
606
1420
|
return false;
|
|
607
|
-
const stats = await (0,
|
|
1421
|
+
const stats = await (0, import_promises7.lstat)(import_node_path9.default.join(directory, ...next.split("/")));
|
|
608
1422
|
if (stats.isSymbolicLink() || stats.isFile() && stats.nlink !== 1) return false;
|
|
609
|
-
if (stats.isDirectory() && !await safeCompletedCorpus(directory, next, engineDirectory))
|
|
1423
|
+
if (stats.isDirectory() && !await safeCompletedCorpus(directory, deliberationDir, next, engineDirectory))
|
|
610
1424
|
return false;
|
|
611
1425
|
if (!stats.isDirectory() && !stats.isFile()) return false;
|
|
612
1426
|
}
|
|
@@ -618,13 +1432,13 @@ async function safeCompletedCorpus(directory, relative = "", engineDirectory = "
|
|
|
618
1432
|
function object2(value) {
|
|
619
1433
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
620
1434
|
}
|
|
621
|
-
async function safeCodegraphInputs(root, analysis, run) {
|
|
1435
|
+
async function safeCodegraphInputs(root, analysis, run, deliberationDir) {
|
|
622
1436
|
const runtime = graphRuntimePaths(root);
|
|
623
1437
|
const result = await run(
|
|
624
1438
|
runtime.codegraphNode,
|
|
625
1439
|
[
|
|
626
1440
|
"--liftoff-only",
|
|
627
|
-
|
|
1441
|
+
import_node_path9.default.resolve(getInitAssetsDir(), "..", "graph", "codegraph-native.mjs"),
|
|
628
1442
|
runtime.codegraphSdk,
|
|
629
1443
|
analysis,
|
|
630
1444
|
"inventory"
|
|
@@ -636,13 +1450,13 @@ async function safeCodegraphInputs(root, analysis, run) {
|
|
|
636
1450
|
const inventory = JSON.parse(result.stdout);
|
|
637
1451
|
if (!object2(inventory) || !Array.isArray(inventory.files)) return false;
|
|
638
1452
|
for (const file of inventory.files) {
|
|
639
|
-
if (typeof file !== "string" || !file ||
|
|
1453
|
+
if (typeof file !== "string" || !file || import_node_path9.default.posix.isAbsolute(file) || import_node_path9.default.win32.isAbsolute(file))
|
|
640
1454
|
return false;
|
|
641
1455
|
const normalized = file.replaceAll("\\", "/");
|
|
642
1456
|
const parts = normalized.split("/");
|
|
643
|
-
if (parts.some((part) => !part || part === "." || part === "..") || excludedGraphInput(normalized))
|
|
1457
|
+
if (parts.some((part) => !part || part === "." || part === "..") || excludedGraphInput(normalized, deliberationDir))
|
|
644
1458
|
return false;
|
|
645
|
-
const stats = await (0,
|
|
1459
|
+
const stats = await (0, import_promises7.lstat)(import_node_path9.default.join(analysis, ...parts));
|
|
646
1460
|
if (!stats.isFile() || stats.isSymbolicLink() || stats.nlink !== 1) return false;
|
|
647
1461
|
}
|
|
648
1462
|
return true;
|
|
@@ -654,7 +1468,7 @@ async function safeCodegraphInputs(root, analysis, run) {
|
|
|
654
1468
|
// src/core/graph/codePreparation.ts
|
|
655
1469
|
async function prepareCodeAnalysis(root, run, environment) {
|
|
656
1470
|
const current = graphAnalysisRoot(root, "codegraph");
|
|
657
|
-
const staged =
|
|
1471
|
+
const staged = import_node_path10.default.join(import_node_path10.default.dirname(current), `.preparing-codegraph-${(0, import_node_crypto3.randomUUID)()}`);
|
|
658
1472
|
let created = false;
|
|
659
1473
|
try {
|
|
660
1474
|
if (await inspectCurrentCodeAnalysis(root, run))
|
|
@@ -662,7 +1476,7 @@ async function prepareCodeAnalysis(root, run, environment) {
|
|
|
662
1476
|
if (await restoreCompletedCodeAnalysis(root, run, environment) === "restored")
|
|
663
1477
|
return { status: "prepared", source: "restored" };
|
|
664
1478
|
await assertGraphStoragePath(root, staged);
|
|
665
|
-
await (0,
|
|
1479
|
+
await (0, import_promises8.mkdir)(staged, { recursive: true });
|
|
666
1480
|
created = true;
|
|
667
1481
|
await mirrorGraphCorpus(root, staged);
|
|
668
1482
|
const runtime = graphRuntimePaths(root);
|
|
@@ -670,7 +1484,7 @@ async function prepareCodeAnalysis(root, run, environment) {
|
|
|
670
1484
|
runtime.codegraphNode,
|
|
671
1485
|
[
|
|
672
1486
|
"--liftoff-only",
|
|
673
|
-
|
|
1487
|
+
import_node_path10.default.resolve(getInitAssetsDir(), "..", "graph", "codegraph-native.mjs"),
|
|
674
1488
|
runtime.codegraphSdk,
|
|
675
1489
|
staged
|
|
676
1490
|
],
|
|
@@ -684,10 +1498,11 @@ async function prepareCodeAnalysis(root, run, environment) {
|
|
|
684
1498
|
source: "generated",
|
|
685
1499
|
reuse: await publishCompletedCodeAnalysis(root, run, environment)
|
|
686
1500
|
};
|
|
687
|
-
} catch {
|
|
1501
|
+
} catch (cause) {
|
|
1502
|
+
if (cause instanceof GraphConfigUnreadableError) throw cause;
|
|
688
1503
|
return failed();
|
|
689
1504
|
} finally {
|
|
690
|
-
if (created) await (0,
|
|
1505
|
+
if (created) await (0, import_promises8.rm)(staged, { recursive: true, force: true });
|
|
691
1506
|
}
|
|
692
1507
|
}
|
|
693
1508
|
function failed() {
|
|
@@ -698,39 +1513,39 @@ function failed() {
|
|
|
698
1513
|
}
|
|
699
1514
|
|
|
700
1515
|
// src/core/graph/documents.ts
|
|
701
|
-
var
|
|
1516
|
+
var import_promises11 = require("fs/promises");
|
|
702
1517
|
var import_node_crypto6 = require("crypto");
|
|
703
1518
|
|
|
704
1519
|
// src/core/graph/documentReuse.ts
|
|
705
1520
|
var import_node_crypto4 = require("crypto");
|
|
706
|
-
var
|
|
707
|
-
var
|
|
1521
|
+
var import_promises9 = require("fs/promises");
|
|
1522
|
+
var import_node_path11 = __toESM(require("path"), 1);
|
|
708
1523
|
async function restoreCompletedDocumentAnalysis(root, run, inspect, environment = graphReuseEnvironment()) {
|
|
709
1524
|
let staged;
|
|
710
1525
|
try {
|
|
711
1526
|
if (!await compatible(root, run, environment)) return "cold";
|
|
712
1527
|
const cache = await completedAnalysisCache(root, "graphify", run, environment);
|
|
713
1528
|
if (!cache) return "cold";
|
|
714
|
-
for (const entry of await (0,
|
|
1529
|
+
for (const entry of await (0, import_promises9.readdir)(cache.directory, { withFileTypes: true })) {
|
|
715
1530
|
if (!entry.isDirectory() || entry.isSymbolicLink() || entry.name.startsWith(".")) continue;
|
|
716
|
-
const candidate =
|
|
1531
|
+
const candidate = import_node_path11.default.join(cache.directory, entry.name);
|
|
717
1532
|
if (!await cacheDirectorySafe(cache.repository, candidate)) continue;
|
|
718
1533
|
const metadata = await readSnapshotMetadata(candidate);
|
|
719
1534
|
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))
|
|
720
1535
|
continue;
|
|
721
|
-
const analysis =
|
|
1536
|
+
const analysis = import_node_path11.default.join(candidate, "analysis");
|
|
722
1537
|
if (!await safeDocumentCopy(root, analysis, run)) continue;
|
|
723
1538
|
const current = graphAnalysisRoot(root, "graphify");
|
|
724
|
-
staged =
|
|
1539
|
+
staged = import_node_path11.default.join(import_node_path11.default.dirname(current), `.restoring-graphify-${(0, import_node_crypto4.randomUUID)()}`);
|
|
725
1540
|
await assertGraphStoragePath(root, staged);
|
|
726
|
-
await (0,
|
|
727
|
-
await (0,
|
|
1541
|
+
await (0, import_promises9.mkdir)(import_node_path11.default.dirname(staged), { recursive: true });
|
|
1542
|
+
await (0, import_promises9.cp)(analysis, staged, { recursive: true, dereference: false });
|
|
728
1543
|
await assertIndependentAnalysis(staged);
|
|
729
1544
|
if (await inspect(staged, true)) {
|
|
730
1545
|
await replaceGraphDirectory(staged, current, root);
|
|
731
1546
|
return "restored";
|
|
732
1547
|
}
|
|
733
|
-
await (0,
|
|
1548
|
+
await (0, import_promises9.rm)(staged, { recursive: true, force: true });
|
|
734
1549
|
staged = void 0;
|
|
735
1550
|
}
|
|
736
1551
|
} catch {
|
|
@@ -750,15 +1565,15 @@ async function publishCompletedDocumentAnalysis(root, run, inspect, environment
|
|
|
750
1565
|
const analysis = graphAnalysisRoot(root, "graphify");
|
|
751
1566
|
if (!await safeDocumentCopy(root, analysis, run)) return "unavailable";
|
|
752
1567
|
const identity = (0, import_node_crypto4.randomUUID)();
|
|
753
|
-
staged =
|
|
754
|
-
await (0,
|
|
755
|
-
const copy =
|
|
756
|
-
await (0,
|
|
1568
|
+
staged = import_node_path11.default.join(cache.directory, `.publishing-${identity}`);
|
|
1569
|
+
await (0, import_promises9.mkdir)(staged);
|
|
1570
|
+
const copy = import_node_path11.default.join(staged, "analysis");
|
|
1571
|
+
await (0, import_promises9.cp)(analysis, copy, { recursive: true, dereference: false });
|
|
757
1572
|
await assertIndependentAnalysis(copy);
|
|
758
1573
|
if (!await safeDocumentCopy(root, copy, run) || !await inspect(copy, false))
|
|
759
1574
|
return "unavailable";
|
|
760
|
-
await (0,
|
|
761
|
-
|
|
1575
|
+
await (0, import_promises9.writeFile)(
|
|
1576
|
+
import_node_path11.default.join(staged, "completed.json"),
|
|
762
1577
|
JSON.stringify({
|
|
763
1578
|
layout: 1,
|
|
764
1579
|
corpusPolicy: 1,
|
|
@@ -767,7 +1582,7 @@ async function publishCompletedDocumentAnalysis(root, run, inspect, environment
|
|
|
767
1582
|
environment
|
|
768
1583
|
}) + "\n"
|
|
769
1584
|
);
|
|
770
|
-
await (0,
|
|
1585
|
+
await (0, import_promises9.rename)(staged, import_node_path11.default.join(cache.directory, identity));
|
|
771
1586
|
return "published";
|
|
772
1587
|
} catch {
|
|
773
1588
|
return "unavailable";
|
|
@@ -785,13 +1600,14 @@ async function compatible(root, run, environment) {
|
|
|
785
1600
|
return result.exitCode === 0 && result.stdout.trim() === "3.12.13";
|
|
786
1601
|
}
|
|
787
1602
|
async function safeDocumentCopy(root, analysis, run) {
|
|
788
|
-
|
|
1603
|
+
const deliberationDir = await graphDeliberationDir(root);
|
|
1604
|
+
if (!await safeCompletedCorpus(analysis, deliberationDir, "", "graphify-out")) return false;
|
|
789
1605
|
const result = await run(
|
|
790
1606
|
graphRuntimePaths(root).python,
|
|
791
1607
|
[
|
|
792
1608
|
...GRAPH_PYTHON_FLAGS,
|
|
793
|
-
|
|
794
|
-
|
|
1609
|
+
import_node_path11.default.resolve(getInitAssetsDir(), "..", "graph", "graphify-native.py"),
|
|
1610
|
+
import_node_path11.default.toNamespacedPath(analysis),
|
|
795
1611
|
"inventory"
|
|
796
1612
|
],
|
|
797
1613
|
{ cwd: analysis, env: graphifyCorpusEnvironment(root, analysis) }
|
|
@@ -802,12 +1618,12 @@ async function safeDocumentCopy(root, analysis, run) {
|
|
|
802
1618
|
if (typeof inventory !== "object" || inventory === null || Object.keys(inventory).length !== 1 || !("files" in inventory) || !Array.isArray(inventory.files))
|
|
803
1619
|
return false;
|
|
804
1620
|
for (const file of inventory.files) {
|
|
805
|
-
if (typeof file !== "string" ||
|
|
1621
|
+
if (typeof file !== "string" || import_node_path11.default.posix.isAbsolute(file) || import_node_path11.default.win32.isAbsolute(file))
|
|
806
1622
|
return false;
|
|
807
1623
|
const parts = file.replaceAll("\\", "/").split("/");
|
|
808
|
-
if (parts.some((part) => !part || part === "." || part === "..") || excludedGraphInput(parts.join("/")))
|
|
1624
|
+
if (parts.some((part) => !part || part === "." || part === "..") || excludedGraphInput(parts.join("/"), deliberationDir))
|
|
809
1625
|
return false;
|
|
810
|
-
const stats = await (0,
|
|
1626
|
+
const stats = await (0, import_promises9.lstat)(import_node_path11.default.join(analysis, ...parts));
|
|
811
1627
|
if (!stats.isFile() || stats.isSymbolicLink() || stats.nlink !== 1) return false;
|
|
812
1628
|
}
|
|
813
1629
|
return true;
|
|
@@ -817,111 +1633,18 @@ async function safeDocumentCopy(root, analysis, run) {
|
|
|
817
1633
|
}
|
|
818
1634
|
async function discard(directory) {
|
|
819
1635
|
try {
|
|
820
|
-
await (0,
|
|
1636
|
+
await (0, import_promises9.rm)(directory, { recursive: true, force: true });
|
|
821
1637
|
} catch {
|
|
822
1638
|
}
|
|
823
1639
|
}
|
|
824
1640
|
|
|
825
1641
|
// src/core/graph/locks.ts
|
|
826
1642
|
var import_node_crypto5 = require("crypto");
|
|
827
|
-
var
|
|
828
|
-
var
|
|
829
|
-
|
|
830
|
-
// src/core/graph/localFiles.ts
|
|
831
|
-
var import_promises8 = require("fs/promises");
|
|
832
|
-
var import_node_path10 = __toESM(require("path"), 1);
|
|
833
|
-
|
|
834
|
-
// src/core/init/fsGuards.ts
|
|
835
|
-
var import_node_fs2 = require("fs");
|
|
836
|
-
var import_promises7 = require("fs/promises");
|
|
837
|
-
var import_node_path9 = __toESM(require("path"), 1);
|
|
838
|
-
async function readPinnedRegularFileBytes(filePath, maxBytes) {
|
|
839
|
-
let handle;
|
|
840
|
-
try {
|
|
841
|
-
handle = await (0, import_promises7.open)(filePath, OPEN_READ_FLAGS);
|
|
842
|
-
const pinned = await handle.stat();
|
|
843
|
-
if (!pinned.isFile() || pinned.size > maxBytes) return null;
|
|
844
|
-
const buffer = Buffer.alloc(maxBytes + 1);
|
|
845
|
-
let filled = 0;
|
|
846
|
-
while (filled < buffer.length) {
|
|
847
|
-
const { bytesRead } = await handle.read(buffer, filled, buffer.length - filled, filled);
|
|
848
|
-
if (bytesRead === 0) break;
|
|
849
|
-
filled += bytesRead;
|
|
850
|
-
}
|
|
851
|
-
if (filled > maxBytes) return null;
|
|
852
|
-
return {
|
|
853
|
-
content: Buffer.from(buffer.subarray(0, filled)),
|
|
854
|
-
mode: pinned.mode & 4095,
|
|
855
|
-
uid: pinned.uid,
|
|
856
|
-
gid: pinned.gid,
|
|
857
|
-
dev: pinned.dev,
|
|
858
|
-
ino: pinned.ino
|
|
859
|
-
};
|
|
860
|
-
} catch (error) {
|
|
861
|
-
const code = error?.code;
|
|
862
|
-
if (code === "ENXIO" || code === "EISDIR") return null;
|
|
863
|
-
throw error;
|
|
864
|
-
} finally {
|
|
865
|
-
await handle?.close();
|
|
866
|
-
}
|
|
867
|
-
}
|
|
868
|
-
var OPEN_READ_FLAGS = typeof import_node_fs2.constants.O_NONBLOCK === "number" ? import_node_fs2.constants.O_RDONLY | import_node_fs2.constants.O_NONBLOCK : import_node_fs2.constants.O_RDONLY;
|
|
869
|
-
|
|
870
|
-
// src/core/graph/localFiles.ts
|
|
871
|
-
var GRAPH_STATE_BYTES = 32768;
|
|
872
|
-
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}$/;
|
|
873
|
-
var GraphLocalStateError = class extends Error {
|
|
874
|
-
constructor(message, recovery, options) {
|
|
875
|
-
super(message, options);
|
|
876
|
-
this.recovery = recovery;
|
|
877
|
-
}
|
|
878
|
-
};
|
|
879
|
-
async function graphStateDirectory(root) {
|
|
880
|
-
const directory = import_node_path10.default.join(root, ".qfai", "tools", "state", graphEnvironmentKey());
|
|
881
|
-
await assertGraphStoragePath(root, directory);
|
|
882
|
-
await (0, import_promises8.mkdir)(directory, { recursive: true });
|
|
883
|
-
await assertGraphStoragePath(root, directory);
|
|
884
|
-
return directory;
|
|
885
|
-
}
|
|
886
|
-
function invalidGraphState() {
|
|
887
|
-
return new GraphLocalStateError(
|
|
888
|
-
"Project graph permission state is invalid.",
|
|
889
|
-
"Retain the local state and repair .qfai/tools/state before retrying the graph CLI or hook."
|
|
890
|
-
);
|
|
891
|
-
}
|
|
892
|
-
function graphStateText(value, maximum) {
|
|
893
|
-
return typeof value === "string" && value.trim().length > 0 && value.length <= maximum && !value.includes("\0");
|
|
894
|
-
}
|
|
895
|
-
async function readGraphLocalFile(file) {
|
|
896
|
-
try {
|
|
897
|
-
const before = await (0, import_promises8.lstat)(file);
|
|
898
|
-
if (!before.isFile() || before.isSymbolicLink() || before.nlink !== 1)
|
|
899
|
-
throw invalidGraphState();
|
|
900
|
-
const pinned = await readPinnedRegularFileBytes(file, GRAPH_STATE_BYTES);
|
|
901
|
-
const after = await (0, import_promises8.lstat)(file);
|
|
902
|
-
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)
|
|
903
|
-
throw invalidGraphState();
|
|
904
|
-
return pinned.content.toString("utf8");
|
|
905
|
-
} catch (cause) {
|
|
906
|
-
if (isEnoent(cause)) return void 0;
|
|
907
|
-
throw cause;
|
|
908
|
-
}
|
|
909
|
-
}
|
|
910
|
-
async function writeGraphLocalFile(file, value) {
|
|
911
|
-
const text = JSON.stringify(value);
|
|
912
|
-
if (Buffer.byteLength(text) > GRAPH_STATE_BYTES) throw invalidGraphState();
|
|
913
|
-
const handle = await (0, import_promises8.open)(file, "wx", 384);
|
|
914
|
-
try {
|
|
915
|
-
await handle.writeFile(text, "utf8");
|
|
916
|
-
} finally {
|
|
917
|
-
await handle.close();
|
|
918
|
-
}
|
|
919
|
-
}
|
|
920
|
-
|
|
921
|
-
// src/core/graph/locks.ts
|
|
1643
|
+
var import_promises10 = require("fs/promises");
|
|
1644
|
+
var import_node_path12 = __toESM(require("path"), 1);
|
|
922
1645
|
async function withGraphLock(root, kind, action) {
|
|
923
1646
|
const directory = await graphStateDirectory(root);
|
|
924
|
-
const file =
|
|
1647
|
+
const file = import_node_path12.default.join(directory, `${kind}.lock`);
|
|
925
1648
|
const owner = {
|
|
926
1649
|
kind: "graph-lock",
|
|
927
1650
|
pid: process.pid,
|
|
@@ -968,11 +1691,11 @@ async function releaseGraphLock(file, owner) {
|
|
|
968
1691
|
"Project graph lock ownership changed.",
|
|
969
1692
|
"Retain the lock and repair the worktree graph state before retrying."
|
|
970
1693
|
);
|
|
971
|
-
await (0,
|
|
1694
|
+
await (0, import_promises10.unlink)(file);
|
|
972
1695
|
}
|
|
973
1696
|
|
|
974
1697
|
// src/core/graph/documents.ts
|
|
975
|
-
var
|
|
1698
|
+
var import_node_path13 = __toESM(require("path"), 1);
|
|
976
1699
|
function notCurrent() {
|
|
977
1700
|
return { current: false, unsupported: [], unreadable: [] };
|
|
978
1701
|
}
|
|
@@ -1031,9 +1754,9 @@ async function prepareDocumentAnalysisLocked(root, run = runGraphProcess, approv
|
|
|
1031
1754
|
}
|
|
1032
1755
|
}
|
|
1033
1756
|
const current = graphAnalysisRoot(root, "graphify");
|
|
1034
|
-
const staged =
|
|
1757
|
+
const staged = import_node_path13.default.join(import_node_path13.default.dirname(current), `.preparing-graphify-${(0, import_node_crypto6.randomUUID)()}`);
|
|
1035
1758
|
await assertGraphStoragePath(root, staged);
|
|
1036
|
-
await (0,
|
|
1759
|
+
await (0, import_promises11.mkdir)(staged, { recursive: true });
|
|
1037
1760
|
try {
|
|
1038
1761
|
await mirrorGraphCorpus(root, staged, scope);
|
|
1039
1762
|
const result = await run(
|
|
@@ -1043,7 +1766,7 @@ async function prepareDocumentAnalysisLocked(root, run = runGraphProcess, approv
|
|
|
1043
1766
|
"-m",
|
|
1044
1767
|
"graphify",
|
|
1045
1768
|
"extract",
|
|
1046
|
-
|
|
1769
|
+
import_node_path13.default.toNamespacedPath(staged),
|
|
1047
1770
|
"--backend",
|
|
1048
1771
|
backend,
|
|
1049
1772
|
"--model",
|
|
@@ -1070,8 +1793,8 @@ async function prepareDocumentAnalysisLocked(root, run = runGraphProcess, approv
|
|
|
1070
1793
|
recovery: "Check the selected local model and repair Graphify document analysis."
|
|
1071
1794
|
};
|
|
1072
1795
|
}
|
|
1073
|
-
await (0,
|
|
1074
|
-
|
|
1796
|
+
await (0, import_promises11.writeFile)(
|
|
1797
|
+
import_node_path13.default.join(staged, "graphify-out", "managed.json"),
|
|
1075
1798
|
JSON.stringify({ engineVersion: GRAPH_VERSIONS.graphify, scope: "documents", processing })
|
|
1076
1799
|
);
|
|
1077
1800
|
await assertIndependentAnalysis(staged);
|
|
@@ -1082,11 +1805,11 @@ async function prepareDocumentAnalysisLocked(root, run = runGraphProcess, approv
|
|
|
1082
1805
|
reuse: await publishCompletedDocumentAnalysis(root, run, inspect, environment)
|
|
1083
1806
|
};
|
|
1084
1807
|
} finally {
|
|
1085
|
-
await (0,
|
|
1808
|
+
await (0, import_promises11.rm)(staged, { recursive: true, force: true });
|
|
1086
1809
|
}
|
|
1087
1810
|
}
|
|
1088
1811
|
async function readGraphProcessing(root) {
|
|
1089
|
-
const processing = await readOptionalJson(
|
|
1812
|
+
const processing = await readOptionalJson(import_node_path13.default.join(root, ".qfai", "graph-processing.json"));
|
|
1090
1813
|
return validGraphProcessing(processing) ? processing : void 0;
|
|
1091
1814
|
}
|
|
1092
1815
|
function validGraphProcessing(processing) {
|
|
@@ -1114,7 +1837,7 @@ async function inspectDocumentScope(root, run) {
|
|
|
1114
1837
|
return inspectDocumentScopeAt(root, analysis, run);
|
|
1115
1838
|
}
|
|
1116
1839
|
async function inspectDocumentScopeAt(root, analysis, run, refresh = true) {
|
|
1117
|
-
const managed = await readOptionalJson(
|
|
1840
|
+
const managed = await readOptionalJson(import_node_path13.default.join(analysis, "graphify-out", "managed.json"));
|
|
1118
1841
|
const selected = await readGraphProcessing(root);
|
|
1119
1842
|
const processing = await processingForCompletedQuery(
|
|
1120
1843
|
root,
|
|
@@ -1131,7 +1854,7 @@ async function inspectDocumentScopeAt(root, analysis, run, refresh = true) {
|
|
|
1131
1854
|
async function processingForCompletedQuery(root, selected, recorded) {
|
|
1132
1855
|
if (selected !== void 0) return selected;
|
|
1133
1856
|
try {
|
|
1134
|
-
await (0,
|
|
1857
|
+
await (0, import_promises11.readFile)(import_node_path13.default.join(root, ".qfai", "graph-processing.json"));
|
|
1135
1858
|
return void 0;
|
|
1136
1859
|
} catch (cause) {
|
|
1137
1860
|
if (!isEnoent(cause)) throw cause;
|
|
@@ -1148,8 +1871,8 @@ async function nativeGraphifyScope(root, analysis, python, run, kind = "semantic
|
|
|
1148
1871
|
python,
|
|
1149
1872
|
[
|
|
1150
1873
|
...GRAPH_PYTHON_FLAGS,
|
|
1151
|
-
|
|
1152
|
-
|
|
1874
|
+
import_node_path13.default.resolve(getInitAssetsDir(), "..", "graph", "graphify-native.py"),
|
|
1875
|
+
import_node_path13.default.toNamespacedPath(analysis),
|
|
1153
1876
|
kind
|
|
1154
1877
|
],
|
|
1155
1878
|
{
|
|
@@ -1167,7 +1890,7 @@ async function nativeGraphifyScope(root, analysis, python, run, kind = "semantic
|
|
|
1167
1890
|
}
|
|
1168
1891
|
if (!object3(state) || typeof state.current !== "boolean" || !stringArray2(state.unsupported) || !stringArray2(state.unreadable))
|
|
1169
1892
|
return notCurrent();
|
|
1170
|
-
const sourcePath = (file) =>
|
|
1893
|
+
const sourcePath = (file) => import_node_path13.default.isAbsolute(file) ? import_node_path13.default.relative(import_node_path13.default.toNamespacedPath(analysis), import_node_path13.default.toNamespacedPath(file)).split(import_node_path13.default.sep).join("/") : file;
|
|
1171
1894
|
return {
|
|
1172
1895
|
current: state.current,
|
|
1173
1896
|
unsupported: state.unsupported.map(sourcePath),
|
|
@@ -1176,7 +1899,7 @@ async function nativeGraphifyScope(root, analysis, python, run, kind = "semantic
|
|
|
1176
1899
|
}
|
|
1177
1900
|
async function readOptionalJson(file) {
|
|
1178
1901
|
try {
|
|
1179
|
-
return JSON.parse(await (0,
|
|
1902
|
+
return JSON.parse(await (0, import_promises11.readFile)(file, "utf8"));
|
|
1180
1903
|
} catch (cause) {
|
|
1181
1904
|
if (isEnoent(cause) || cause instanceof SyntaxError) return void 0;
|
|
1182
1905
|
throw cause;
|
|
@@ -1196,7 +1919,7 @@ function stringArray2(value) {
|
|
|
1196
1919
|
}
|
|
1197
1920
|
function validDocumentScope(value) {
|
|
1198
1921
|
return Array.isArray(value) && value.length > 0 && value.every(
|
|
1199
|
-
(item) => typeof item === "string" && item !== "" && !
|
|
1922
|
+
(item) => typeof item === "string" && item !== "" && !import_node_path13.default.isAbsolute(item) && !item.split(/[\\/]/).some((part) => part === ".." || part === "." || part === "")
|
|
1200
1923
|
);
|
|
1201
1924
|
}
|
|
1202
1925
|
function providerConflict() {
|
|
@@ -1207,13 +1930,14 @@ function providerConflict() {
|
|
|
1207
1930
|
}
|
|
1208
1931
|
|
|
1209
1932
|
// src/core/graph/query.ts
|
|
1210
|
-
var
|
|
1211
|
-
var
|
|
1933
|
+
var import_promises12 = require("fs/promises");
|
|
1934
|
+
var import_node_path14 = __toESM(require("path"), 1);
|
|
1212
1935
|
async function exploreGraph(root, request, run = runGraphProcess) {
|
|
1213
1936
|
const requestedScope = Object.freeze({ ...request });
|
|
1214
1937
|
try {
|
|
1215
1938
|
return { ...await exploreGraphScope(root, request, run), requestedScope };
|
|
1216
|
-
} catch {
|
|
1939
|
+
} catch (cause) {
|
|
1940
|
+
if (cause instanceof GraphConfigUnreadableError) throw cause;
|
|
1217
1941
|
const engine = request.domain === "code" ? "codegraph" : "graphify";
|
|
1218
1942
|
return {
|
|
1219
1943
|
requestedScope,
|
|
@@ -1236,8 +1960,8 @@ async function exploreGraphScope(root, request, run) {
|
|
|
1236
1960
|
"query",
|
|
1237
1961
|
request.question,
|
|
1238
1962
|
"--graph",
|
|
1239
|
-
|
|
1240
|
-
|
|
1963
|
+
import_node_path14.default.toNamespacedPath(
|
|
1964
|
+
import_node_path14.default.join(graphAnalysisRoot(root, "graphify"), "graphify-out", "graph.json")
|
|
1241
1965
|
)
|
|
1242
1966
|
],
|
|
1243
1967
|
{
|
|
@@ -1383,21 +2107,41 @@ async function queryPreparedGraph(root, request, run = runGraphProcess) {
|
|
|
1383
2107
|
|
|
1384
2108
|
// src/core/graph/fallbackState.ts
|
|
1385
2109
|
var import_node_crypto7 = require("crypto");
|
|
1386
|
-
var
|
|
2110
|
+
var import_promises14 = require("fs/promises");
|
|
2111
|
+
var import_node_path17 = __toESM(require("path"), 1);
|
|
2112
|
+
|
|
2113
|
+
// src/core/graph/hooks.ts
|
|
1387
2114
|
var import_node_path15 = __toESM(require("path"), 1);
|
|
2115
|
+
var redirectionSource = String.raw`(?:\d*|&|\{[A-Za-z_][A-Za-z0-9_]*\})`;
|
|
2116
|
+
var redirectionStart = new RegExp(String.raw`^${redirectionSource}(?:<|>)`);
|
|
2117
|
+
var detachedRedirection = new RegExp(String.raw`^${redirectionSource}(?:<>|>{1,2}|<{1,3})[&|]?$`);
|
|
2118
|
+
var DATA_FILE = String.raw`(?!/dev/|/proc/)[\w./-]+`;
|
|
2119
|
+
var DATA_OPERAND = String.raw`[ \t]+(?:-[A-Za-z]+|>>?[ \t]*${DATA_FILE}|>[ \t]*/dev/null|${DATA_FILE})`;
|
|
2120
|
+
var DATA_HEREDOC_LINE = new RegExp(
|
|
2121
|
+
String.raw`^[ \t]*(?:cat|tee)(?:${DATA_OPERAND})*[ \t]*<<-?[ \t]*(?:(['"])[A-Za-z_]\w*\1|\\[A-Za-z_]\w*)(?:${DATA_OPERAND})*[ \t]*$`
|
|
2122
|
+
);
|
|
2123
|
+
var DATA_PRELUDE_LINE = new RegExp(
|
|
2124
|
+
String.raw`^[ \t]*(?:mkdir[ \t]+-p(?:[ \t]+${DATA_FILE})+[ \t]*)?$`
|
|
2125
|
+
);
|
|
2126
|
+
var MESSAGE_WORD = String.raw`[ \t]+[\w./=:@-]+`;
|
|
2127
|
+
var MESSAGE_HEREDOC_LINE = new RegExp(
|
|
2128
|
+
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]*$`
|
|
2129
|
+
);
|
|
2130
|
+
var MESSAGE_CLOSE_LINE = new RegExp(String.raw`^[ \t]*\)"(?:${MESSAGE_WORD})*[ \t]*$`);
|
|
2131
|
+
var MESSAGE_PRELUDE_LINE = new RegExp(String.raw`^[ \t]*git[ \t]+add(?:${MESSAGE_WORD})*[ \t]*$`);
|
|
1388
2132
|
|
|
1389
2133
|
// src/core/graph/permissionRecords.ts
|
|
1390
|
-
var
|
|
1391
|
-
var
|
|
2134
|
+
var import_promises13 = require("fs/promises");
|
|
2135
|
+
var import_node_path16 = __toESM(require("path"), 1);
|
|
1392
2136
|
async function readGraphSearchRecords(root, directory) {
|
|
1393
2137
|
const records = [];
|
|
1394
|
-
const entries = await (0,
|
|
2138
|
+
const entries = await (0, import_promises13.opendir)(directory);
|
|
1395
2139
|
for await (const entry of entries) {
|
|
1396
2140
|
if (entry.name === "state.lock" || entry.name === "analysis.lock") continue;
|
|
1397
2141
|
if (records.length >= 128) throw fullGraphState();
|
|
1398
2142
|
const match = /^(.+)\.(pending|grant|draft)\.json$/.exec(entry.name);
|
|
1399
2143
|
if (!match || !GRAPH_UUID.test(match[1] ?? "")) throw invalidGraphState();
|
|
1400
|
-
const file =
|
|
2144
|
+
const file = import_node_path16.default.join(directory, entry.name);
|
|
1401
2145
|
const text = await readGraphLocalFile(file);
|
|
1402
2146
|
if (text === void 0) throw invalidGraphState();
|
|
1403
2147
|
let input;
|
|
@@ -1413,7 +2157,7 @@ async function readGraphSearchRecords(root, directory) {
|
|
|
1413
2157
|
}
|
|
1414
2158
|
const current = [];
|
|
1415
2159
|
for (const item of records) {
|
|
1416
|
-
if (Date.now() >= item.record.expiresAt) await (0,
|
|
2160
|
+
if (Date.now() >= item.record.expiresAt) await (0, import_promises13.unlink)(item.file);
|
|
1417
2161
|
else current.push(item);
|
|
1418
2162
|
}
|
|
1419
2163
|
return current;
|
|
@@ -1439,7 +2183,7 @@ function parseGraphSearchRecord(input, root) {
|
|
|
1439
2183
|
"expiresAt"
|
|
1440
2184
|
];
|
|
1441
2185
|
if (value.kind === "grant") fields.push("reason");
|
|
1442
|
-
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 !==
|
|
2186
|
+
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 !== import_node_path16.default.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))
|
|
1443
2187
|
return void 0;
|
|
1444
2188
|
const scope = {
|
|
1445
2189
|
id: value.id,
|
|
@@ -1484,16 +2228,16 @@ async function requestStoredGraphFallback(root, attemptId, question, reason, run
|
|
|
1484
2228
|
createdAt,
|
|
1485
2229
|
expiresAt: createdAt + 6e4
|
|
1486
2230
|
};
|
|
1487
|
-
const draft =
|
|
2231
|
+
const draft = import_node_path17.default.join(directory, `${grant.id}.draft.json`);
|
|
1488
2232
|
await writeGraphLocalFile(draft, grant);
|
|
1489
|
-
await (0,
|
|
2233
|
+
await (0, import_promises14.unlink)(pending.file);
|
|
1490
2234
|
return { directory, draft, grant };
|
|
1491
2235
|
});
|
|
1492
2236
|
await assertGraphStoragePath(root, publication.directory);
|
|
1493
2237
|
if (Date.now() >= publication.grant.expiresAt) throw invalidGraphState();
|
|
1494
|
-
await (0,
|
|
2238
|
+
await (0, import_promises14.rename)(
|
|
1495
2239
|
publication.draft,
|
|
1496
|
-
|
|
2240
|
+
import_node_path17.default.join(publication.directory, `${publication.grant.id}.grant.json`)
|
|
1497
2241
|
);
|
|
1498
2242
|
const { target, operation, worktree, session, expiresAt } = publication.grant;
|
|
1499
2243
|
return {
|