artifact-graph 0.13.0 → 0.14.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -3388,11 +3388,10 @@ async function detectPnpmVersion() {
3388
3388
  return void 0;
3389
3389
  }
3390
3390
  }
3391
- function bindingInstallBase(cli, root) {
3391
+ function bindingInstallBase(cli, _root) {
3392
3392
  if (!cli.path || !cli.source) return void 0;
3393
3393
  switch (cli.source) {
3394
3394
  case "node_modules":
3395
- return join5(root, "package.json");
3396
3395
  case "plugin-bundled":
3397
3396
  case "path":
3398
3397
  case "legacy":
@@ -3401,11 +3400,10 @@ function bindingInstallBase(cli, root) {
3401
3400
  return void 0;
3402
3401
  }
3403
3402
  }
3404
- function bindingInstallRoot(cli, root) {
3403
+ function bindingInstallRoot(cli, _root) {
3405
3404
  if (!cli.path || !cli.source) return void 0;
3406
3405
  switch (cli.source) {
3407
3406
  case "node_modules":
3408
- return root;
3409
3407
  case "plugin-bundled":
3410
3408
  case "path":
3411
3409
  case "legacy":
@@ -3924,6 +3922,378 @@ var init_hook_installer = __esm({
3924
3922
  }
3925
3923
  });
3926
3924
 
3925
+ // src/professional-conclusion.ts
3926
+ import { access as access2 } from "fs/promises";
3927
+ import { createRequire as createRequire2 } from "module";
3928
+ import { basename as basename3, dirname as dirname5, isAbsolute as isAbsolute4, join as join7, resolve as resolve5 } from "path";
3929
+ import { pathToFileURL } from "url";
3930
+ async function loadContracts() {
3931
+ return await import(CONTRACTS_PACKAGE_NAME);
3932
+ }
3933
+ async function loadHarness() {
3934
+ return await import("skill-family-harness-node");
3935
+ }
3936
+ function providerVersion() {
3937
+ const anchor = typeof __filename === "string" ? __filename : import.meta.url;
3938
+ const parsed = createRequire2(anchor)("../package.json");
3939
+ if (typeof parsed.version !== "string" || parsed.version.length === 0) {
3940
+ throw new Error("artifact-graph package.json is missing version");
3941
+ }
3942
+ return parsed.version;
3943
+ }
3944
+ function errorMessage(error) {
3945
+ return error instanceof Error ? error.message : String(error);
3946
+ }
3947
+ function harnessKind(error) {
3948
+ if (error === null || typeof error !== "object" || !("details" in error)) {
3949
+ return void 0;
3950
+ }
3951
+ const details = error.details;
3952
+ return typeof details?.kind === "string" ? details.kind : void 0;
3953
+ }
3954
+ async function missingRequiredConfig(root) {
3955
+ const configPath = join7(root, "artifact-graph.config.yaml");
3956
+ try {
3957
+ await access2(configPath);
3958
+ return void 0;
3959
+ } catch (error) {
3960
+ if (error.code === "ENOENT") {
3961
+ return `required configuration is missing: ${configPath}`;
3962
+ }
3963
+ return errorMessage(error);
3964
+ }
3965
+ }
3966
+ async function runValidate(root) {
3967
+ const config = await loadConfig(root);
3968
+ const graph = await scanArtifacts(root, config);
3969
+ const issues = validateGraph(graph, config);
3970
+ issues.push(...await validateScenarioPrdLinkIndex(root, graph));
3971
+ issues.push(...await validateExecutableTraceability(root, config));
3972
+ const includeCoverage = config.e2e?.executable_ref_warning !== void 0 || config.e2e?.executable_ref_error !== void 0;
3973
+ if (includeCoverage) {
3974
+ const e2eConfig = config.e2e ?? {};
3975
+ const coverageStats = await computeE2eCoverageStats(graph, root, {
3976
+ executableRefWarning: e2eConfig.executable_ref_warning,
3977
+ executableRefError: e2eConfig.executable_ref_error,
3978
+ reportUncoveredScenarios: e2eConfig.report_uncovered_scenarios,
3979
+ reportUncoveredFeatures: e2eConfig.report_uncovered_features,
3980
+ scenarioWaivers: e2eConfig.scenario_waivers,
3981
+ featureWaivers: e2eConfig.feature_waivers
3982
+ });
3983
+ for (const msg of coverageStats.thresholdWarnings) {
3984
+ issues.push({
3985
+ code: "E2E_COVERAGE_WARNING",
3986
+ severity: "warning",
3987
+ message: msg,
3988
+ path: "e2e-coverage",
3989
+ line: 1
3990
+ });
3991
+ }
3992
+ for (const msg of coverageStats.thresholdErrors) {
3993
+ issues.push({
3994
+ code: "E2E_COVERAGE_ERROR",
3995
+ severity: "error",
3996
+ message: msg,
3997
+ path: "e2e-coverage",
3998
+ line: 1
3999
+ });
4000
+ }
4001
+ }
4002
+ return { name: CHECK_VALIDATE, status: "completed", issues };
4003
+ }
4004
+ async function runLockAudit(root) {
4005
+ const result = await auditVersionLock(root);
4006
+ return { name: CHECK_LOCK, status: "completed", issues: result.issues };
4007
+ }
4008
+ async function runCoverage(root) {
4009
+ const report = await computeCoverageBoundary(root);
4010
+ return {
4011
+ name: CHECK_COVERAGE,
4012
+ status: "completed",
4013
+ issues: [],
4014
+ coverage: {
4015
+ assessment: report.graphHealth.assessment,
4016
+ changedPathScope: report.scanCoverage.changedPathScope,
4017
+ behaviorStatus: report.behaviorVerification.status
4018
+ }
4019
+ };
4020
+ }
4021
+ async function settleCheck(name, run) {
4022
+ try {
4023
+ return await run();
4024
+ } catch (error) {
4025
+ return { name, status: "not-performed", issues: [], reason: errorMessage(error) };
4026
+ }
4027
+ }
4028
+ function mapDomain(checks) {
4029
+ const completed = checks.filter((check) => check.status === "completed");
4030
+ const missing = checks.filter((check) => check.status === "not-performed");
4031
+ const hasFindings = completed.some((check) => check.issues.length > 0);
4032
+ if (completed.length === 0) {
4033
+ return {
4034
+ code: GRAPH_DOMAIN_CODES.UNAVAILABLE,
4035
+ completion: "not-performed",
4036
+ summary: "Graph checks did not start because configuration, runtime, or inputs were unavailable."
4037
+ };
4038
+ }
4039
+ if (hasFindings) {
4040
+ return {
4041
+ code: GRAPH_DOMAIN_CODES.FINDINGS,
4042
+ completion: missing.length > 0 ? "partial" : "complete",
4043
+ summary: "At least one completed graph check reported issues. Original issues are preserved."
4044
+ };
4045
+ }
4046
+ if (missing.length > 0) {
4047
+ return {
4048
+ code: GRAPH_DOMAIN_CODES.INCOMPLETE,
4049
+ completion: "partial",
4050
+ summary: "Some declared graph checks completed without findings; others lacked input or could not finish."
4051
+ };
4052
+ }
4053
+ return {
4054
+ code: GRAPH_DOMAIN_CODES.CLEAR,
4055
+ completion: "complete",
4056
+ summary: "Declared graph checks completed without issues. This does not prove unregistered relations or content correctness."
4057
+ };
4058
+ }
4059
+ function buildLimitations(checks) {
4060
+ const limitations = [STANDING_LIMITATION];
4061
+ for (const check of checks) {
4062
+ if (check.status === "not-performed") {
4063
+ limitations.push(`${check.name} did not complete: ${check.reason ?? "unknown error"}`);
4064
+ }
4065
+ if (check.coverage?.behaviorStatus === "not-evaluated") {
4066
+ limitations.push("coverage does not evaluate whether declared verification actually ran.");
4067
+ }
4068
+ if (check.coverage?.changedPathScope === "unavailable") {
4069
+ limitations.push("coverage could not observe Git worktree changes.");
4070
+ }
4071
+ }
4072
+ return [...new Set(limitations)];
4073
+ }
4074
+ function buildConclusion(root, checks) {
4075
+ const absoluteRoot = resolve5(root);
4076
+ const mapped = mapDomain(checks);
4077
+ const checked = checks.filter((check) => check.status === "completed").map((check) => check.name);
4078
+ const limitations = buildLimitations(checks);
4079
+ const issues = checks.flatMap((check) => check.issues);
4080
+ return {
4081
+ schemaVersion: 1,
4082
+ kind: "skill-family.professional-conclusion",
4083
+ provider: {
4084
+ id: GRAPH_PROVIDER_ID,
4085
+ version: providerVersion(),
4086
+ entry: GRAPH_PROVIDER_ENTRY
4087
+ },
4088
+ subject: {
4089
+ ref: pathToFileURL(absoluteRoot).href
4090
+ },
4091
+ scope: {
4092
+ checked: mapped.completion === "not-performed" ? [] : checked,
4093
+ limitations
4094
+ },
4095
+ outcome: {
4096
+ completion: mapped.completion,
4097
+ code: mapped.code,
4098
+ summary: mapped.summary
4099
+ },
4100
+ details: {
4101
+ checks: checks.map((check) => ({
4102
+ name: check.name,
4103
+ status: check.status,
4104
+ issueCount: check.issues.length,
4105
+ ...check.reason ? { reason: check.reason } : {},
4106
+ ...check.coverage ? { coverage: check.coverage } : {}
4107
+ })),
4108
+ issues
4109
+ }
4110
+ };
4111
+ }
4112
+ async function assertConclusionShape(conclusion) {
4113
+ const contracts = await loadContracts();
4114
+ const registration = contracts.findSchemaByObject(PROFESSIONAL_CONCLUSION_OBJECT);
4115
+ if (registration === null) {
4116
+ throw new Error("skill-family-contracts 0.22.0 does not register professional-conclusion");
4117
+ }
4118
+ const verdict = contracts.validateDocument(conclusion, {
4119
+ schemaId: registration.$id,
4120
+ dialect: registration.dialect,
4121
+ policy: "strict"
4122
+ });
4123
+ if (!verdict.valid) {
4124
+ throw new Error(`constructed professional conclusion failed public schema validation (${verdict.errorCode ?? "invalid"})`);
4125
+ }
4126
+ }
4127
+ async function publishConclusion(absoluteOutput, conclusion) {
4128
+ if (!isAbsolute4(absoluteOutput)) {
4129
+ return "--conclusion-output must be an absolute path";
4130
+ }
4131
+ const outputRoot = dirname5(absoluteOutput);
4132
+ const relPath = basename3(absoluteOutput);
4133
+ if (relPath.length === 0 || relPath === "." || relPath === "..") {
4134
+ return "--conclusion-output must name a file";
4135
+ }
4136
+ try {
4137
+ const harness = await loadHarness();
4138
+ await harness.publishFileExclusive(outputRoot, relPath, `${JSON.stringify(conclusion, null, 2)}
4139
+ `);
4140
+ return void 0;
4141
+ } catch (error) {
4142
+ const kind = harnessKind(error);
4143
+ if (kind === "exclusive-publish-conflict") {
4144
+ return `exclusive publication target already exists: ${absoluteOutput}`;
4145
+ }
4146
+ return errorMessage(error);
4147
+ }
4148
+ }
4149
+ async function runCheckProfessional(options) {
4150
+ const root = resolve5(options.root);
4151
+ const configGap = await missingRequiredConfig(root);
4152
+ const checks = configGap === void 0 ? await Promise.all([
4153
+ settleCheck(CHECK_VALIDATE, () => runValidate(root)),
4154
+ settleCheck(CHECK_LOCK, () => runLockAudit(root)),
4155
+ settleCheck(CHECK_COVERAGE, () => runCoverage(root))
4156
+ ]) : [
4157
+ { name: CHECK_VALIDATE, status: "not-performed", issues: [], reason: configGap },
4158
+ { name: CHECK_LOCK, status: "not-performed", issues: [], reason: configGap },
4159
+ { name: CHECK_COVERAGE, status: "not-performed", issues: [], reason: configGap }
4160
+ ];
4161
+ const conclusion = buildConclusion(root, checks);
4162
+ await assertConclusionShape(conclusion);
4163
+ if (options.conclusionOutput === void 0) {
4164
+ return { conclusion };
4165
+ }
4166
+ if (!isAbsolute4(options.conclusionOutput)) {
4167
+ return { conclusion, writeError: "--conclusion-output must be an absolute path" };
4168
+ }
4169
+ const writeError = await publishConclusion(resolve5(options.conclusionOutput), conclusion);
4170
+ return { conclusion, ...writeError ? { writeError } : {} };
4171
+ }
4172
+ function asRecord(value) {
4173
+ if (value === null || typeof value !== "object" || Array.isArray(value)) {
4174
+ return null;
4175
+ }
4176
+ return value;
4177
+ }
4178
+ function readProvider(value) {
4179
+ const record = asRecord(value);
4180
+ if (record === null) {
4181
+ return null;
4182
+ }
4183
+ const provider = {};
4184
+ if (typeof record.id === "string") provider.id = record.id;
4185
+ if (typeof record.version === "string") provider.version = record.version;
4186
+ if (typeof record.entry === "string") provider.entry = record.entry;
4187
+ return Object.keys(provider).length > 0 ? provider : null;
4188
+ }
4189
+ function interpretConclusion(conclusion) {
4190
+ const provider = conclusion.provider;
4191
+ if (provider.id !== GRAPH_PROVIDER_ID) {
4192
+ return {
4193
+ status: "unavailable",
4194
+ reason: `proof provider ${provider.id} is not ${GRAPH_PROVIDER_ID}`,
4195
+ provider,
4196
+ conclusion
4197
+ };
4198
+ }
4199
+ if (!KNOWN_DOMAIN_CODES.has(conclusion.outcome.code)) {
4200
+ return {
4201
+ status: "unavailable",
4202
+ reason: `unknown same-version domain code: ${conclusion.outcome.code}`,
4203
+ provider,
4204
+ conclusion
4205
+ };
4206
+ }
4207
+ if (conclusion.outcome.code === GRAPH_DOMAIN_CODES.CLEAR && conclusion.outcome.completion === "complete") {
4208
+ return {
4209
+ status: "pass",
4210
+ reason: "GRAPH_CLEAR with complete scope is acceptable for this provider version.",
4211
+ provider,
4212
+ conclusion
4213
+ };
4214
+ }
4215
+ return {
4216
+ status: "not_pass",
4217
+ reason: `proof records ${conclusion.outcome.code} (${conclusion.outcome.completion}); complete does not mean pass.`,
4218
+ provider,
4219
+ conclusion
4220
+ };
4221
+ }
4222
+ async function runReadProof(options) {
4223
+ const unavailable = (reason, provider = null, conclusion = null) => ({
4224
+ result: { status: "unavailable", reason, provider, conclusion },
4225
+ exitCode: 2
4226
+ });
4227
+ let receipt;
4228
+ try {
4229
+ const harness = await loadHarness();
4230
+ receipt = await harness.readFileStrict(options.proofRoot, options.proof, { encoding: "utf8" });
4231
+ } catch (error) {
4232
+ const kind = harnessKind(error);
4233
+ if (kind === "missing-resource") {
4234
+ return unavailable(`proof file does not exist: ${options.proof}`, null, null);
4235
+ }
4236
+ return unavailable(errorMessage(error), null, null);
4237
+ }
4238
+ const raw = typeof receipt.content === "string" ? receipt.content : receipt.content.toString("utf8");
4239
+ let parsed;
4240
+ try {
4241
+ parsed = JSON.parse(raw);
4242
+ } catch (error) {
4243
+ return unavailable(`proof is not valid JSON: ${errorMessage(error)}`, null, null);
4244
+ }
4245
+ const previewProvider = readProvider(asRecord(parsed)?.provider);
4246
+ let contracts;
4247
+ try {
4248
+ contracts = await loadContracts();
4249
+ } catch (error) {
4250
+ return unavailable(`cannot load skill-family-contracts: ${errorMessage(error)}`, previewProvider, null);
4251
+ }
4252
+ const registration = contracts.findSchemaByObject(PROFESSIONAL_CONCLUSION_OBJECT);
4253
+ if (registration === null) {
4254
+ return unavailable("professional-conclusion schema is not registered", previewProvider, null);
4255
+ }
4256
+ const verdict = contracts.validateDocument(parsed, {
4257
+ schemaId: registration.$id,
4258
+ dialect: registration.dialect,
4259
+ policy: "strict"
4260
+ });
4261
+ if (!verdict.valid) {
4262
+ return unavailable(
4263
+ `proof failed professional-conclusion schema validation (${verdict.errorCode ?? "invalid"})`,
4264
+ previewProvider,
4265
+ null
4266
+ );
4267
+ }
4268
+ const interpreted = interpretConclusion(parsed);
4269
+ const exitCode = interpreted.status === "pass" ? 0 : interpreted.status === "not_pass" ? 1 : 2;
4270
+ return { result: interpreted, exitCode };
4271
+ }
4272
+ var GRAPH_PROVIDER_ID, GRAPH_PROVIDER_ENTRY, PROFESSIONAL_CONCLUSION_OBJECT, GRAPH_DOMAIN_CODES, KNOWN_DOMAIN_CODES, CHECK_VALIDATE, CHECK_LOCK, CHECK_COVERAGE, STANDING_LIMITATION, CONTRACTS_PACKAGE_NAME;
4273
+ var init_professional_conclusion = __esm({
4274
+ "src/professional-conclusion.ts"() {
4275
+ "use strict";
4276
+ init_coverage();
4277
+ init_index();
4278
+ init_versioned_traceability();
4279
+ GRAPH_PROVIDER_ID = "artifact-graph";
4280
+ GRAPH_PROVIDER_ENTRY = "check-professional";
4281
+ PROFESSIONAL_CONCLUSION_OBJECT = "professional-conclusion";
4282
+ GRAPH_DOMAIN_CODES = Object.freeze({
4283
+ CLEAR: "GRAPH_CLEAR",
4284
+ FINDINGS: "GRAPH_FINDINGS",
4285
+ INCOMPLETE: "GRAPH_CHECK_INCOMPLETE",
4286
+ UNAVAILABLE: "GRAPH_CHECK_UNAVAILABLE"
4287
+ });
4288
+ KNOWN_DOMAIN_CODES = new Set(Object.values(GRAPH_DOMAIN_CODES));
4289
+ CHECK_VALIDATE = "validate";
4290
+ CHECK_LOCK = "version-lock-audit";
4291
+ CHECK_COVERAGE = "coverage";
4292
+ STANDING_LIMITATION = "Graph checks do not prove content semantics, method execution, or publication facts.";
4293
+ CONTRACTS_PACKAGE_NAME = "skill-family-contracts";
4294
+ }
4295
+ });
4296
+
3927
4297
  // src/review-result-validator.ts
3928
4298
  function validateReviewResult(input) {
3929
4299
  const errors = [];
@@ -4275,7 +4645,7 @@ __export(contract_kernel_exports, {
4275
4645
  });
4276
4646
  import { createHash as createHash2 } from "crypto";
4277
4647
  import { readFile as readFile2, readdir as readdir2 } from "fs/promises";
4278
- import { join as join7 } from "path";
4648
+ import { join as join8 } from "path";
4279
4649
  import _AjvModule from "ajv";
4280
4650
  function isOfficialNamespace(namespace) {
4281
4651
  return OFFICIAL_NAMESPACE_PATTERN.test(namespace);
@@ -4688,7 +5058,7 @@ async function loadContractsFromDirectory(contractsDir, options) {
4688
5058
  const entries = await readdir2(contractsDir, { withFileTypes: true });
4689
5059
  for (const entry of entries) {
4690
5060
  if (entry.isDirectory()) {
4691
- const schemaPath = join7(contractsDir, entry.name, "schema.json");
5061
+ const schemaPath = join8(contractsDir, entry.name, "schema.json");
4692
5062
  const contract = await loadContract(schemaPath, options);
4693
5063
  contracts.push(contract);
4694
5064
  }
@@ -5280,12 +5650,12 @@ var init_restructure_software = __esm({
5280
5650
  // src/restructure-file-set.ts
5281
5651
  import { createHash as createHash3 } from "crypto";
5282
5652
  import { chmod, lstat as lstat2, mkdir as mkdir4, realpath, statfs } from "fs/promises";
5283
- import { join as join8, resolve as resolve5 } from "path";
5653
+ import { join as join9, resolve as resolve6 } from "path";
5284
5654
  async function loadFoundationModule() {
5285
5655
  return await import(FOUNDATION_PACKAGE_NAME);
5286
5656
  }
5287
5657
  async function loadContractsModule() {
5288
- return await import(CONTRACTS_PACKAGE_NAME);
5658
+ return await import(CONTRACTS_PACKAGE_NAME2);
5289
5659
  }
5290
5660
  async function verifyMechanismResult(result) {
5291
5661
  if (typeof result !== "object" || result === null || Array.isArray(result)) {
@@ -5338,7 +5708,7 @@ function rawDigest(value, path) {
5338
5708
  async function resolveRealRoot(root) {
5339
5709
  let canonical;
5340
5710
  try {
5341
- canonical = await realpath(resolve5(root));
5711
+ canonical = await realpath(resolve6(root));
5342
5712
  } catch (cause) {
5343
5713
  return failure("ROOT_INVALID", `Project root cannot be resolved: ${cause.message}`);
5344
5714
  }
@@ -5377,7 +5747,7 @@ async function qualifyRestructureMechanism(root) {
5377
5747
  return { ok: true, data: { root: canonical.data, filesystem: RESTRUCTURE_QUALIFIED_FILESYSTEM } };
5378
5748
  }
5379
5749
  async function ensureRestructureMechanismRoot(canonicalRoot, options) {
5380
- const target = join8(canonicalRoot, RESTRUCTURE_RECOVERY_REL_PATH);
5750
+ const target = join9(canonicalRoot, RESTRUCTURE_RECOVERY_REL_PATH);
5381
5751
  const current = async () => lstat2(target).catch((cause) => cause.code === "ENOENT" ? null : Promise.reject(cause));
5382
5752
  let info = await current();
5383
5753
  if (info === null) {
@@ -5491,7 +5861,7 @@ async function applyRestructureFileSet(canonicalRoot, plan, options) {
5491
5861
  return await verifyMechanismResult(raw);
5492
5862
  }
5493
5863
  async function observeRestructureJournal(canonicalRoot) {
5494
- const journalRoot = join8(canonicalRoot, RESTRUCTURE_RECOVERY_REL_PATH, "journal");
5864
+ const journalRoot = join9(canonicalRoot, RESTRUCTURE_RECOVERY_REL_PATH, "journal");
5495
5865
  const module = await loadFoundationModule();
5496
5866
  try {
5497
5867
  return { ok: true, data: await module.inspectStateStoreLock(journalRoot, { recoveryObservation: true }) };
@@ -5678,7 +6048,7 @@ function projectRestructureFileSetResult(result, planPath = "", planDigest = "")
5678
6048
  const reading = result.operation === "apply" ? applyProjection(result) : result.operation === "recover" ? recoverProjection(result) : pruneProjection(result);
5679
6049
  return { ...base, ...reading };
5680
6050
  }
5681
- var RESTRUCTURE_RECOVERY_REL_PATH, RESTRUCTURE_RECOVERY_JOURNAL_REL_PATH, RESTRUCTURE_RECOVERY_ROOT_MODE, RESTRUCTURE_QUALIFIED_PLATFORM, RESTRUCTURE_QUALIFIED_ARCH, RESTRUCTURE_QUALIFIED_FILESYSTEM, APFS_STATFS_TYPE, DIGEST_PREFIX, RAW_SHA256_PATTERN, FOUNDATION_PACKAGE_NAME, CONTRACTS_PACKAGE_NAME, FILE_SET_RESULT_OBJECT, APPLY_MAINTENANCE_ERROR_KINDS;
6051
+ var RESTRUCTURE_RECOVERY_REL_PATH, RESTRUCTURE_RECOVERY_JOURNAL_REL_PATH, RESTRUCTURE_RECOVERY_ROOT_MODE, RESTRUCTURE_QUALIFIED_PLATFORM, RESTRUCTURE_QUALIFIED_ARCH, RESTRUCTURE_QUALIFIED_FILESYSTEM, APFS_STATFS_TYPE, DIGEST_PREFIX, RAW_SHA256_PATTERN, FOUNDATION_PACKAGE_NAME, CONTRACTS_PACKAGE_NAME2, FILE_SET_RESULT_OBJECT, APPLY_MAINTENANCE_ERROR_KINDS;
5682
6052
  var init_restructure_file_set = __esm({
5683
6053
  "src/restructure-file-set.ts"() {
5684
6054
  "use strict";
@@ -5692,7 +6062,7 @@ var init_restructure_file_set = __esm({
5692
6062
  DIGEST_PREFIX = "sha256:";
5693
6063
  RAW_SHA256_PATTERN = /^[a-f0-9]{64}$/;
5694
6064
  FOUNDATION_PACKAGE_NAME = "skill-family-harness-node";
5695
- CONTRACTS_PACKAGE_NAME = "skill-family-contracts";
6065
+ CONTRACTS_PACKAGE_NAME2 = "skill-family-contracts";
5696
6066
  FILE_SET_RESULT_OBJECT = "file-set-result";
5697
6067
  APPLY_MAINTENANCE_ERROR_KINDS = ["lock-release-failed"];
5698
6068
  }
@@ -5719,7 +6089,7 @@ __export(restructure_exports, {
5719
6089
  });
5720
6090
  import { createHash as createHash4, randomUUID as randomUUID2 } from "crypto";
5721
6091
  import { lstat as lstat3, readFile as readFile3, readdir as readdir3, realpath as realpath2, stat } from "fs/promises";
5722
- import { dirname as dirname5, isAbsolute as isAbsolute4, join as join9, posix, relative as relative4, resolve as resolve6 } from "path";
6092
+ import { dirname as dirname6, isAbsolute as isAbsolute5, join as join10, posix, relative as relative4, resolve as resolve7 } from "path";
5723
6093
  import { fileURLToPath as fileURLToPath2 } from "url";
5724
6094
  function digestBytes(value) {
5725
6095
  return `sha256:${createHash4("sha256").update(value).digest("hex")}`;
@@ -5735,7 +6105,7 @@ function digestRestructureValue(value) {
5735
6105
  return digestBytes(canonicalJson(value));
5736
6106
  }
5737
6107
  function normalizeRelativePath2(value) {
5738
- if (!value || value.includes("\0") || isAbsolute4(value)) return void 0;
6108
+ if (!value || value.includes("\0") || isAbsolute5(value)) return void 0;
5739
6109
  const normalized = value.replace(/\\/g, "/").replace(/^\.\//, "");
5740
6110
  if (!normalized || normalized === "." || normalized.split("/").some((part) => part === ".." || part === "")) return void 0;
5741
6111
  return normalized;
@@ -5749,8 +6119,8 @@ function isPathAllowed(path, allowed) {
5749
6119
  async function readContainedFileWithMode(root, path) {
5750
6120
  const normalized = normalizeRelativePath2(path);
5751
6121
  if (!normalized) throw new Error(`Path must be a project-relative path without traversal: ${path}`);
5752
- const absoluteRoot = resolve6(root);
5753
- const absolutePath = resolve6(absoluteRoot, normalized);
6122
+ const absoluteRoot = resolve7(root);
6123
+ const absolutePath = resolve7(absoluteRoot, normalized);
5754
6124
  if (relative4(absoluteRoot, absolutePath).startsWith("..")) throw new Error(`Path escapes project root: ${path}`);
5755
6125
  try {
5756
6126
  const info = await lstat3(absolutePath);
@@ -5783,7 +6153,7 @@ async function configSnapshot(root) {
5783
6153
  return snapshotFile(root, "artifact-graph.config.yaml");
5784
6154
  }
5785
6155
  async function loadRestructureContract(name) {
5786
- return loadContract(join9(CONTRACT_ROOT, `restructure-${name}`, "schema.json"), { expectedAuthority: "artifact" });
6156
+ return loadContract(join10(CONTRACT_ROOT, `restructure-${name}`, "schema.json"), { expectedAuthority: "artifact" });
5787
6157
  }
5788
6158
  async function validateDomainContract(name, value) {
5789
6159
  const contract = await loadRestructureContract(name);
@@ -6058,7 +6428,7 @@ async function scanUnsupportedReferences(root, sourcePaths, targetPaths) {
6058
6428
  async function visit(directory) {
6059
6429
  for (const entry of await readdir3(directory, { withFileTypes: true })) {
6060
6430
  if (entry.isDirectory() && SKIPPED_SCAN_DIRS.has(entry.name)) continue;
6061
- const absolute = join9(directory, entry.name);
6431
+ const absolute = join10(directory, entry.name);
6062
6432
  if (entry.isDirectory()) {
6063
6433
  await visit(absolute);
6064
6434
  continue;
@@ -6087,7 +6457,7 @@ async function scanUnsupportedReferences(root, sourcePaths, targetPaths) {
6087
6457
  path,
6088
6458
  lineNumber
6089
6459
  ));
6090
- } else if (!await pathExists2(resolve6(root, resolved))) {
6460
+ } else if (!await pathExists2(resolve7(root, resolved))) {
6091
6461
  findings.push(finding(
6092
6462
  "SIBLING_RELATIVE_REFERENCE_UNRESOLVED",
6093
6463
  `The relative reference "${literal}" does not resolve inside the project although its file name matches a migration path; its intended destination must be decided explicitly`,
@@ -6112,7 +6482,7 @@ async function scanUnsupportedReferences(root, sourcePaths, targetPaths) {
6112
6482
  }
6113
6483
  }
6114
6484
  }
6115
- await visit(resolve6(root));
6485
+ await visit(resolve7(root));
6116
6486
  const unique = new Map(findings.map((item) => [`${item.code} ${item.path} ${item.line} ${item.message}`, item]));
6117
6487
  return [...unique.values()].sort((left, right) => (left.path ?? "").localeCompare(right.path ?? "") || (left.line ?? 0) - (right.line ?? 0) || left.code.localeCompare(right.code));
6118
6488
  }
@@ -6130,7 +6500,7 @@ async function scanConsumerCandidates(root, references, excludedPaths = /* @__PU
6130
6500
  async function visit(directory) {
6131
6501
  for (const entry of await readdir3(directory, { withFileTypes: true })) {
6132
6502
  if (entry.isDirectory() && SKIPPED_SCAN_DIRS.has(entry.name)) continue;
6133
- const absolute = join9(directory, entry.name);
6503
+ const absolute = join10(directory, entry.name);
6134
6504
  if (entry.isDirectory()) {
6135
6505
  await visit(absolute);
6136
6506
  } else if (entry.isFile() && TEXT_EXTENSIONS.test(entry.name)) {
@@ -6145,7 +6515,7 @@ async function scanConsumerCandidates(root, references, excludedPaths = /* @__PU
6145
6515
  }
6146
6516
  }
6147
6517
  }
6148
- await visit(resolve6(root));
6518
+ await visit(resolve7(root));
6149
6519
  return results.sort((left, right) => left.path.localeCompare(right.path) || left.line - right.line || left.reference.localeCompare(right.reference));
6150
6520
  }
6151
6521
  function expectedRelationTargets(mapping) {
@@ -6185,7 +6555,7 @@ function restructureBoundaryFindings(operations, limits) {
6185
6555
  const expectedCreateMode = createModeForUmask(limits.umask);
6186
6556
  const applyModeContract = limits.mode_contract === "apply";
6187
6557
  for (const operation of operations) {
6188
- const parent = dirname5(operation.path) || ".";
6558
+ const parent = dirname6(operation.path) || ".";
6189
6559
  if (!operation.parent_exists) {
6190
6560
  findings.push(finding("PARENT_DIRECTORY_MISSING", `Parent directory does not exist or is not a directory: ${parent}`, operation.path));
6191
6561
  } else if (operation.parent_device !== null && operation.parent_device !== operation.root_device) {
@@ -6376,7 +6746,7 @@ async function planRestructure(root, input) {
6376
6746
  }
6377
6747
  pathMoves.push(move);
6378
6748
  rangesByPath.set(sourcePath, pathMoves);
6379
- if (dirname5(sourcePath) !== dirname5(targetPath)) {
6749
+ if (dirname6(sourcePath) !== dirname6(targetPath)) {
6380
6750
  for (const link of findRelativeLinks(fragment.toString("utf8"))) {
6381
6751
  const explicitlyEdited = mapping.prose_edits.some((edit) => edit.target_path === targetPath && edit.old_text.includes(link));
6382
6752
  if (!explicitlyEdited) blockers.push(finding("RELATIVE_LINK_REQUIRES_MAPPING", `Relative reference "${link}" changes base directory when moved to ${targetPath}`, sourcePath));
@@ -6493,15 +6863,15 @@ async function planRestructure(root, input) {
6493
6863
  diff: readableDiff(path, original?.toString("utf8"), deleteFile ? void 0 : candidate.toString("utf8"))
6494
6864
  });
6495
6865
  }
6496
- const rootDirectory = await probeDirectory(resolve6(root));
6866
+ const rootDirectory = await probeDirectory(resolve7(root));
6497
6867
  const parentProbes = /* @__PURE__ */ new Map();
6498
6868
  for (const candidate of candidates) {
6499
- const parent = dirname5(candidate.path);
6500
- if (!parentProbes.has(parent)) parentProbes.set(parent, await probeDirectory(resolve6(root, parent)));
6869
+ const parent = dirname6(candidate.path);
6870
+ if (!parentProbes.has(parent)) parentProbes.set(parent, await probeDirectory(resolve7(root, parent)));
6501
6871
  }
6502
6872
  blockers.push(...restructureBoundaryFindings(
6503
6873
  candidates.map((candidate) => {
6504
- const parent = parentProbes.get(dirname5(candidate.path));
6874
+ const parent = parentProbes.get(dirname6(candidate.path));
6505
6875
  return {
6506
6876
  path: candidate.path,
6507
6877
  action: candidate.action,
@@ -6627,7 +6997,7 @@ function refusal(code, message, findings = []) {
6627
6997
  return { ok: false, error: { code, message, ...findings.length === 0 ? {} : { details: findings } } };
6628
6998
  }
6629
6999
  async function loadRestructurePlanDocument(operation, canonicalRoot, planPath) {
6630
- const absolute = resolve6(planPath);
7000
+ const absolute = resolve7(planPath);
6631
7001
  let info;
6632
7002
  try {
6633
7003
  info = await lstat3(absolute);
@@ -6671,18 +7041,18 @@ function planRootIdentityFindings(document) {
6671
7041
  findings.push(finding("ROOT_IDENTITY_MISMATCH", `The plan does not record this project's configuration file: ${document.plan.config_snapshot.path}`));
6672
7042
  }
6673
7043
  const relativePlan = relative4(document.root, document.realPath);
6674
- if (!relativePlan || relativePlan.startsWith("..") || isAbsolute4(relativePlan)) {
7044
+ if (!relativePlan || relativePlan.startsWith("..") || isAbsolute5(relativePlan)) {
6675
7045
  findings.push(finding("ROOT_IDENTITY_MISMATCH", `The plan document is outside the project root: ${document.realPath}`, document.realPath));
6676
7046
  }
6677
7047
  return findings;
6678
7048
  }
6679
7049
  async function operationBoundaries(root, plan) {
6680
- const rootDirectory = await probeDirectory(resolve6(root));
7050
+ const rootDirectory = await probeDirectory(resolve7(root));
6681
7051
  const parents = /* @__PURE__ */ new Map();
6682
7052
  const boundaries = [];
6683
7053
  for (const candidate of plan.candidates) {
6684
- const parent = dirname5(candidate.path) || ".";
6685
- if (!parents.has(parent)) parents.set(parent, await probeDirectory(resolve6(root, parent)));
7054
+ const parent = dirname6(candidate.path) || ".";
7055
+ if (!parents.has(parent)) parents.set(parent, await probeDirectory(resolve7(root, parent)));
6686
7056
  const probe = parents.get(parent);
6687
7057
  boundaries.push({
6688
7058
  path: candidate.path,
@@ -6861,8 +7231,8 @@ var init_restructure = __esm({
6861
7231
  RESTRUCTURE_MAX_TOTAL_BYTES = 256 * 1024 * 1024;
6862
7232
  MAX_POSIX_MODE = 511;
6863
7233
  CREATE_MODE_BASE = 438;
6864
- MODULE_DIRECTORY = typeof __dirname === "string" ? __dirname : dirname5(fileURLToPath2(import.meta.url));
6865
- CONTRACT_ROOT = join9(MODULE_DIRECTORY, "..", "contracts");
7234
+ MODULE_DIRECTORY = typeof __dirname === "string" ? __dirname : dirname6(fileURLToPath2(import.meta.url));
7235
+ CONTRACT_ROOT = join10(MODULE_DIRECTORY, "..", "contracts");
6866
7236
  SKIPPED_SCAN_DIRS = /* @__PURE__ */ new Set([".git", "node_modules", "dist", "coverage", ".tmp", ".codex", ".worktrees", ".foundation-file-apply", ".artifact-graph"]);
6867
7237
  TEXT_EXTENSIONS = /\.(?:md|markdown|json|ya?ml|[cm]?[jt]sx?)$/i;
6868
7238
  MARKDOWN_LINK_PATTERN = /!?\[([^\]\n]*)\]\(([^)\n]+)\)/g;
@@ -6877,7 +7247,7 @@ import matter from "gray-matter";
6877
7247
  import yaml from "js-yaml";
6878
7248
  import { accessSync, constants as fsConstants, existsSync as existsSync3, statSync } from "fs";
6879
7249
  import { mkdir as mkdir5, readFile as readFile4, writeFile as writeFile3 } from "fs/promises";
6880
- import { basename as basename4, dirname as dirname6, extname, isAbsolute as isAbsolute5, join as join10, resolve as resolve7 } from "path";
7250
+ import { basename as basename5, dirname as dirname7, extname, isAbsolute as isAbsolute6, join as join11, resolve as resolve8 } from "path";
6881
7251
  function isTargetArtifactType(type) {
6882
7252
  return isPacketTargetType(type);
6883
7253
  }
@@ -6919,7 +7289,7 @@ function resolveArtifactTypeName(schema, token) {
6919
7289
  return void 0;
6920
7290
  }
6921
7291
  async function loadConfig(root) {
6922
- const configPath = join10(root, "artifact-graph.config.yaml");
7292
+ const configPath = join11(root, "artifact-graph.config.yaml");
6923
7293
  let parsed = {};
6924
7294
  try {
6925
7295
  const raw = await readFile4(configPath, "utf-8");
@@ -6963,8 +7333,31 @@ async function loadConfig(root) {
6963
7333
  idRanges: mergeRecord(DEFAULT_SCHEMA.idRanges, parsed.idRanges),
6964
7334
  e2e: mergedE2e
6965
7335
  };
7336
+ validateJsonArtifactTypes(merged.types);
6966
7337
  return merged;
6967
7338
  }
7339
+ function validateJsonArtifactTypes(types) {
7340
+ for (const [type, definition] of Object.entries(types)) {
7341
+ const raw = definition;
7342
+ const format = raw.format;
7343
+ const idField = raw.idField;
7344
+ if (format === void 0) {
7345
+ if (idField !== void 0) {
7346
+ throw new Error(`Invalid types.${type}.idField: idField requires format json.`);
7347
+ }
7348
+ continue;
7349
+ }
7350
+ if (format !== "json") {
7351
+ throw new Error(`Invalid types.${type}.format: only json is supported. Omit format to keep Markdown parsing.`);
7352
+ }
7353
+ if (SPECIALIZED_PARSER_TYPES.has(type)) {
7354
+ throw new Error(`Invalid types.${type}.format: JSON format applies only to custom types. ${type} keeps its dedicated parser.`);
7355
+ }
7356
+ if (typeof idField !== "string" || idField.length === 0 || idField.trim() !== idField) {
7357
+ throw new Error(`Invalid types.${type}.idField: format json requires the name of one root property.`);
7358
+ }
7359
+ }
7360
+ }
6968
7361
  function validateRelationSemanticsConfig(value) {
6969
7362
  if (value === void 0) return;
6970
7363
  if (typeof value !== "object" || value === null || Array.isArray(value)) {
@@ -7048,7 +7441,7 @@ function validateE2eConfig(e2e) {
7048
7441
  if (typeof runner.root !== "string" || !runner.root.trim()) {
7049
7442
  throw new Error(`Invalid e2e.runners[${runner.name}].root: must be a non-empty string.`);
7050
7443
  }
7051
- if (isAbsolute5(runner.root)) {
7444
+ if (isAbsolute6(runner.root)) {
7052
7445
  throw new Error(`Invalid e2e.runners[${runner.name}].root: "${runner.root}" must not be an absolute path.`);
7053
7446
  }
7054
7447
  if (runner.root.replace(/\\/g, "/").split("/").includes("..")) {
@@ -7137,15 +7530,15 @@ async function scanArtifacts(root, schema, options = {}) {
7137
7530
  continue;
7138
7531
  }
7139
7532
  scannedFiles.set(file, type);
7140
- const raw = contentOverrides.has(file) ? contentOverrides.get(file) : await readFile4(join10(root, file), "utf-8");
7533
+ const raw = contentOverrides.has(file) ? contentOverrides.get(file) : await readFile4(join11(root, file), "utf-8");
7141
7534
  const parsed = parseFile(type, file, raw, config);
7142
- const semantic = parseConfiguredRelations(type, file, raw, parsed.nodes, config);
7535
+ const semantic = isJsonOriginalType(type, config) ? { edges: [], diagnostics: [] } : parseConfiguredRelations(type, file, raw, parsed.nodes, config);
7143
7536
  nodes.push(...parsed.nodes);
7144
7537
  edges.push(...parsed.edges, ...semantic.edges);
7145
7538
  scanDiagnostics.push(...parsed.diagnostics, ...semantic.diagnostics);
7146
7539
  }
7147
7540
  }
7148
- const absoluteRoot = isAbsolute5(root) ? root : resolve7(root);
7541
+ const absoluteRoot = isAbsolute6(root) ? root : resolve8(root);
7149
7542
  const graph = buildGraph(nodes, edges, scanDiagnostics, absoluteRoot);
7150
7543
  return resolveMatrixEdges(graph);
7151
7544
  }
@@ -7350,33 +7743,6 @@ function validateGraph(graph, schema = DEFAULT_SCHEMA) {
7350
7743
  issues.push(issue("CYCLE_DETECTED", `depends_on cycle detected: ${cycle.join(" -> ")}`, "", 1, { node: cycle[0] }));
7351
7744
  }
7352
7745
  const defaultTypeKeys = new Set(Object.keys(DEFAULT_SCHEMA.types));
7353
- const specializedParserTypes = /* @__PURE__ */ new Set([
7354
- "feature",
7355
- "scenario",
7356
- "entity",
7357
- "decision",
7358
- "test",
7359
- "design",
7360
- "e2e_test",
7361
- "e2e_registry",
7362
- "rule-golden-cases",
7363
- "test-strategy",
7364
- "traceability-matrix-v2",
7365
- "traceability-version-lock",
7366
- "interface_contracts",
7367
- "data_contracts",
7368
- "application_state_machines",
7369
- "error_model",
7370
- "domain-glossary",
7371
- "bounded-context-map",
7372
- "domain-invariants",
7373
- "generation-packet-spec",
7374
- "report-contracts",
7375
- "verification-fixtures",
7376
- "ui-flow-contracts",
7377
- "non-functional-budgets",
7378
- "implementation-blueprint"
7379
- ]);
7380
7746
  const uidsWithEdges = /* @__PURE__ */ new Set();
7381
7747
  for (const edge2 of graph.edges) {
7382
7748
  uidsWithEdges.add(edge2.from);
@@ -7384,7 +7750,7 @@ function validateGraph(graph, schema = DEFAULT_SCHEMA) {
7384
7750
  }
7385
7751
  for (const node of graph.nodes) {
7386
7752
  if (defaultTypeKeys.has(node.type)) continue;
7387
- if (specializedParserTypes.has(node.type)) continue;
7753
+ if (SPECIALIZED_PARSER_TYPES.has(node.type)) continue;
7388
7754
  if (!schema.types[node.type]) continue;
7389
7755
  if (!uidsWithEdges.has(node.uid)) {
7390
7756
  issues.push(issue(
@@ -7508,7 +7874,7 @@ async function validateScenarioPrdLinkIndex(root, graph) {
7508
7874
  const indexPath = "artifacts/prd/feature-index.md";
7509
7875
  let raw = "";
7510
7876
  try {
7511
- raw = await readFile4(join10(root, indexPath), "utf-8");
7877
+ raw = await readFile4(join11(root, indexPath), "utf-8");
7512
7878
  } catch (error) {
7513
7879
  if (error.code === "ENOENT") {
7514
7880
  return [];
@@ -7756,12 +8122,12 @@ function nextId(graph, schema, type, rangeName) {
7756
8122
  throw new Error(`ID range ${type}.${rangeName} is exhausted`);
7757
8123
  }
7758
8124
  async function writeGraphCache(root, graph) {
7759
- const cacheDir = join10(root, ".artifact-graph");
8125
+ const cacheDir = join11(root, ".artifact-graph");
7760
8126
  await mkdir5(cacheDir, { recursive: true });
7761
- await writeFile3(join10(cacheDir, "index.json"), `${JSON.stringify(graph, null, 2)}
8127
+ await writeFile3(join11(cacheDir, "index.json"), `${JSON.stringify(graph, null, 2)}
7762
8128
  `);
7763
8129
  const { default: Database } = await import("better-sqlite3");
7764
- const db = new Database(join10(cacheDir, "graph.sqlite"));
8130
+ const db = new Database(join11(cacheDir, "graph.sqlite"));
7765
8131
  try {
7766
8132
  db.exec(`
7767
8133
  DROP TABLE IF EXISTS nodes;
@@ -7802,7 +8168,13 @@ async function writeGraphCache(root, graph) {
7802
8168
  db.close();
7803
8169
  }
7804
8170
  }
8171
+ function isJsonOriginalType(type, schema) {
8172
+ return schema.types[type]?.format === "json" && !SPECIALIZED_PARSER_TYPES.has(type);
8173
+ }
7805
8174
  function parseFile(type, path, raw, schema = DEFAULT_SCHEMA) {
8175
+ if (isJsonOriginalType(type, schema)) {
8176
+ return parseGenericJson(type, path, raw, schema);
8177
+ }
7806
8178
  if (type === "feature") {
7807
8179
  return { ...parseFeature(path, raw), diagnostics: [] };
7808
8180
  }
@@ -7871,6 +8243,184 @@ function parseFile(type, path, raw, schema = DEFAULT_SCHEMA) {
7871
8243
  }
7872
8244
  return parseGenericMarkdown(type, path, raw, schema);
7873
8245
  }
8246
+ function isJsonObject(value) {
8247
+ return typeof value === "object" && value !== null && !Array.isArray(value);
8248
+ }
8249
+ function jsonRootKind(value) {
8250
+ if (Array.isArray(value)) return "array";
8251
+ if (value === null) return "null";
8252
+ return typeof value;
8253
+ }
8254
+ function parseGenericJson(type, path, raw, schema) {
8255
+ const diagnostics = [];
8256
+ const idField = schema.types[type]?.idField;
8257
+ if (typeof idField !== "string" || idField.length === 0 || idField.trim() !== idField) {
8258
+ diagnostics.push(issue(
8259
+ "INVALID_JSON",
8260
+ `types.${type}.idField must name one root property when format is json`,
8261
+ path,
8262
+ 1
8263
+ ));
8264
+ return { nodes: [], edges: [], diagnostics };
8265
+ }
8266
+ let parsed;
8267
+ try {
8268
+ parsed = JSON.parse(raw);
8269
+ } catch (error) {
8270
+ diagnostics.push(issue(
8271
+ "INVALID_JSON",
8272
+ `JSON artifact ${path} is not valid JSON: ${error.message}`,
8273
+ path,
8274
+ 1
8275
+ ));
8276
+ return { nodes: [], edges: [], diagnostics };
8277
+ }
8278
+ if (!isJsonObject(parsed)) {
8279
+ diagnostics.push(issue(
8280
+ "INVALID_JSON_ROOT",
8281
+ `JSON artifact ${path} must be one root object, got ${jsonRootKind(parsed)}`,
8282
+ path,
8283
+ 1
8284
+ ));
8285
+ return { nodes: [], edges: [], diagnostics };
8286
+ }
8287
+ if (!Object.prototype.hasOwnProperty.call(parsed, idField)) {
8288
+ diagnostics.push(issue(
8289
+ "ARTIFACT_ID_MISSING",
8290
+ `Artifact of type ${type} at ${path} has no root property ${idField}`,
8291
+ path,
8292
+ 1,
8293
+ { severity: "warning" }
8294
+ ));
8295
+ return { nodes: [], edges: [], diagnostics };
8296
+ }
8297
+ const idValue = parsed[idField];
8298
+ if (typeof idValue !== "string") {
8299
+ diagnostics.push(issue(
8300
+ "INVALID_ID",
8301
+ `Artifact of type ${type} at ${path} field ${idField} must be a non-empty string`,
8302
+ path,
8303
+ 1
8304
+ ));
8305
+ return { nodes: [], edges: [], diagnostics };
8306
+ }
8307
+ if (idValue.trim() === "") {
8308
+ diagnostics.push(issue(
8309
+ "ARTIFACT_ID_MISSING",
8310
+ `Artifact of type ${type} at ${path} field ${idField} must be a non-empty string`,
8311
+ path,
8312
+ 1,
8313
+ { severity: "warning" }
8314
+ ));
8315
+ return { nodes: [], edges: [], diagnostics };
8316
+ }
8317
+ const code = idValue;
8318
+ const idPattern = schema.idPatterns[type];
8319
+ if (idPattern && !new RegExp(idPattern).test(code)) {
8320
+ diagnostics.push(issue(
8321
+ "INVALID_ID",
8322
+ `Artifact ${type}:${code} field ${idField} does not match ${idPattern}`,
8323
+ path,
8324
+ 1,
8325
+ { node: toUid(type, code) }
8326
+ ));
8327
+ }
8328
+ const node = {
8329
+ type,
8330
+ code,
8331
+ title: code,
8332
+ path,
8333
+ line: 1
8334
+ };
8335
+ const relations = jsonConfiguredRelations(type, path, parsed, schema, toUid(type, code));
8336
+ diagnostics.push(...relations.diagnostics);
8337
+ return { nodes: [node], edges: relations.edges, diagnostics };
8338
+ }
8339
+ function readJsonRelation(record, field) {
8340
+ const segments = field.split(".");
8341
+ if (segments.some((segment) => segment.length === 0)) {
8342
+ return { status: "illegal-path" };
8343
+ }
8344
+ let current = record;
8345
+ for (let index = 0; index < segments.length; index += 1) {
8346
+ const key = segments[index] ?? "";
8347
+ if (!isJsonObject(current)) {
8348
+ return { status: "type-error", at: segments.slice(0, index).join(".") };
8349
+ }
8350
+ if (!Object.prototype.hasOwnProperty.call(current, key)) {
8351
+ return { status: "absent" };
8352
+ }
8353
+ const next = current[key];
8354
+ const last = index === segments.length - 1;
8355
+ if (!last && !isJsonObject(next)) {
8356
+ return { status: "type-error", at: segments.slice(0, index + 1).join(".") };
8357
+ }
8358
+ current = next;
8359
+ }
8360
+ return { status: "value", value: current };
8361
+ }
8362
+ function jsonRelationTerminal(value, field, path, sourceUid, diagnostics) {
8363
+ const message = `Relation field ${field} in ${path} must be a non-empty string or an array of non-empty strings`;
8364
+ if (typeof value === "string") {
8365
+ if (value.trim() === "") {
8366
+ diagnostics.push(issue("RELATION_VALUE_TYPE", message, path, 1, { node: sourceUid }));
8367
+ return [];
8368
+ }
8369
+ return [value];
8370
+ }
8371
+ if (Array.isArray(value)) {
8372
+ const refs = [];
8373
+ for (const item of value) {
8374
+ if (typeof item !== "string" || item.trim() === "") {
8375
+ diagnostics.push(issue(
8376
+ "RELATION_VALUE_TYPE",
8377
+ `Relation field ${field} in ${path} must contain only non-empty strings`,
8378
+ path,
8379
+ 1,
8380
+ { node: sourceUid }
8381
+ ));
8382
+ continue;
8383
+ }
8384
+ refs.push(item);
8385
+ }
8386
+ return refs;
8387
+ }
8388
+ diagnostics.push(issue("RELATION_VALUE_TYPE", message, path, 1, { node: sourceUid }));
8389
+ return [];
8390
+ }
8391
+ function jsonConfiguredRelations(type, path, record, schema, sourceUid) {
8392
+ const edges = [];
8393
+ const diagnostics = [];
8394
+ for (const [kind, spec] of Object.entries(schema.relationSemantics ?? {})) {
8395
+ for (const field of spec.fields) {
8396
+ const read = readJsonRelation(record, field);
8397
+ if (read.status === "absent") continue;
8398
+ if (read.status === "illegal-path") {
8399
+ diagnostics.push(issue(
8400
+ "INVALID_RELATION_FIELD",
8401
+ `Relation field ${field} is not a fixed path of own properties`,
8402
+ path,
8403
+ 1,
8404
+ { node: sourceUid }
8405
+ ));
8406
+ continue;
8407
+ }
8408
+ if (read.status === "type-error") {
8409
+ diagnostics.push(issue(
8410
+ "RELATION_VALUE_TYPE",
8411
+ `Relation field ${field} in ${path} cannot be read at ${read.at}: expected an object`,
8412
+ path,
8413
+ 1,
8414
+ { node: sourceUid }
8415
+ ));
8416
+ continue;
8417
+ }
8418
+ const values = jsonRelationTerminal(read.value, field, path, sourceUid, diagnostics);
8419
+ appendConfiguredRelationEdges(sourceUid, kind, field, values, spec, schema, path, "json", edges, diagnostics);
8420
+ }
8421
+ }
8422
+ return { edges, diagnostics };
8423
+ }
7874
8424
  function parseGenericMarkdown(type, path, raw, schema) {
7875
8425
  const diagnostics = [];
7876
8426
  const ext = extname(path).toLowerCase();
@@ -7989,38 +8539,18 @@ function parseConfiguredRelations(type, path, raw, nodes, schema) {
7989
8539
  const diagnostics = [];
7990
8540
  for (const [kind, spec] of Object.entries(schema.relationSemantics ?? {})) {
7991
8541
  for (const field of spec.fields) {
7992
- for (const value of toArray(data[field])) {
7993
- const parsed = parseConfiguredRelationTarget(value, spec, schema);
7994
- if (!parsed?.code) continue;
7995
- const matchingTargetTypes = parsed.targetType ? [] : relationTargetTypeMatches(parsed.code, spec.targetTypes, schema);
7996
- const targetType = parsed.targetType ?? inferRelationTargetType(parsed.code, spec.targetTypes, schema);
7997
- if (!parsed.targetType && matchingTargetTypes.length > 1) {
7998
- diagnostics.push(issue(
7999
- "AMBIGUOUS_RELATION_TARGET",
8000
- `${sourceUid} relation ${kind} target "${parsed.code}" matches ${matchingTargetTypes.join(", ")}; use a qualified type:id reference`,
8001
- path,
8002
- 1,
8003
- { node: sourceUid }
8004
- ));
8005
- }
8006
- const targetUid = targetType ? toUid(targetType, parsed.code) : `resolve:${parsed.code}`;
8007
- if (targetType) {
8008
- const pattern = schema.idPatterns[targetType];
8009
- if (pattern && !new RegExp(pattern).test(parsed.code)) {
8010
- diagnostics.push(issue(
8011
- "FORMAT_ERROR",
8012
- `${sourceUid} has invalid ${targetType} reference "${parsed.code}" in field ${field} (expected ${pattern})`,
8013
- path,
8014
- 1,
8015
- { node: sourceUid }
8016
- ));
8017
- }
8018
- }
8019
- edges.push({
8020
- ...edge(sourceUid, targetUid, kind, "frontmatter", path, 1),
8021
- ...parsed.sections.length > 0 ? { attrs: { sections: parsed.sections } } : {}
8022
- });
8023
- }
8542
+ appendConfiguredRelationEdges(
8543
+ sourceUid,
8544
+ kind,
8545
+ field,
8546
+ toArray(data[field]),
8547
+ spec,
8548
+ schema,
8549
+ path,
8550
+ "frontmatter",
8551
+ edges,
8552
+ diagnostics
8553
+ );
8024
8554
  }
8025
8555
  }
8026
8556
  const external = getExternalEntryInfo({
@@ -8039,6 +8569,40 @@ function parseConfiguredRelations(type, path, raw, nodes, schema) {
8039
8569
  }
8040
8570
  return { edges, diagnostics };
8041
8571
  }
8572
+ function appendConfiguredRelationEdges(sourceUid, kind, field, values, spec, schema, path, edgeSource, edges, diagnostics) {
8573
+ for (const value of values) {
8574
+ const parsed = parseConfiguredRelationTarget(value, spec, schema);
8575
+ if (!parsed?.code) continue;
8576
+ const matchingTargetTypes = parsed.targetType ? [] : relationTargetTypeMatches(parsed.code, spec.targetTypes, schema);
8577
+ const targetType = parsed.targetType ?? inferRelationTargetType(parsed.code, spec.targetTypes, schema);
8578
+ if (!parsed.targetType && matchingTargetTypes.length > 1) {
8579
+ diagnostics.push(issue(
8580
+ "AMBIGUOUS_RELATION_TARGET",
8581
+ `${sourceUid} relation ${kind} target "${parsed.code}" matches ${matchingTargetTypes.join(", ")}; use a qualified type:id reference`,
8582
+ path,
8583
+ 1,
8584
+ { node: sourceUid }
8585
+ ));
8586
+ }
8587
+ const targetUid = targetType ? toUid(targetType, parsed.code) : `resolve:${parsed.code}`;
8588
+ if (targetType) {
8589
+ const pattern = schema.idPatterns[targetType];
8590
+ if (pattern && !new RegExp(pattern).test(parsed.code)) {
8591
+ diagnostics.push(issue(
8592
+ "FORMAT_ERROR",
8593
+ `${sourceUid} has invalid ${targetType} reference "${parsed.code}" in field ${field} (expected ${pattern})`,
8594
+ path,
8595
+ 1,
8596
+ { node: sourceUid }
8597
+ ));
8598
+ }
8599
+ }
8600
+ edges.push({
8601
+ ...edge(sourceUid, targetUid, kind, edgeSource, path, 1),
8602
+ ...parsed.sections.length > 0 ? { attrs: { sections: parsed.sections } } : {}
8603
+ });
8604
+ }
8605
+ }
8042
8606
  function parseConfiguredRelationTarget(value, spec, schema) {
8043
8607
  if (typeof value === "string" || typeof value === "number") {
8044
8608
  const raw = String(value).trim();
@@ -8229,7 +8793,7 @@ function parseDecisions(path, raw) {
8229
8793
  }
8230
8794
  function isTestFile(filePath) {
8231
8795
  const normalized = filePath.replace(/\\/g, "/");
8232
- const name = basename4(normalized);
8796
+ const name = basename5(normalized);
8233
8797
  if (/\.(test|spec)\.[^.]+$/.test(name)) return true;
8234
8798
  if (/(^|\/)(tests|test|__tests__)\//.test(normalized)) return true;
8235
8799
  if (/\w+Tests?\.java$/.test(name)) return true;
@@ -8544,10 +9108,10 @@ function parseE2eTest(path, raw) {
8544
9108
  const starts = extractE2eTestCaseStarts(lines);
8545
9109
  const nodes = [];
8546
9110
  const edges = [];
8547
- const batch = String(data.test_batch ?? basename4(path, extname(path))).trim();
9111
+ const batch = String(data.test_batch ?? basename5(path, extname(path))).trim();
8548
9112
  const frontmatterScenarios = toArray(data.related_scenarios).map((value) => String(value).trim()).filter(Boolean);
8549
9113
  const scopeFeatures = extractCodes(String(data.scope ?? ""), "feature");
8550
- const frontmatterFeatures = [.../* @__PURE__ */ new Set([...Object.keys(asRecord(data.ac_coverage)), ...scopeFeatures])];
9114
+ const frontmatterFeatures = [.../* @__PURE__ */ new Set([...Object.keys(asRecord2(data.ac_coverage)), ...scopeFeatures])];
8551
9115
  const frontmatterDecisions = toArray(data.related_decisions).map((value) => String(value).trim()).filter(Boolean);
8552
9116
  const frontmatterEntities = toArray(data.related_entities).map((value) => String(value).trim()).filter(Boolean);
8553
9117
  for (let index = 0; index < starts.length; index += 1) {
@@ -8607,7 +9171,7 @@ function parseE2eRegistry(path, raw) {
8607
9171
  data = { parseError: error.message };
8608
9172
  }
8609
9173
  return {
8610
- nodes: [{ type: "e2e_registry", code: basename4(path, extname(path)), title: "E2E Test Registry", path, line: 1, attrs: data }],
9174
+ nodes: [{ type: "e2e_registry", code: basename5(path, extname(path)), title: "E2E Test Registry", path, line: 1, attrs: data }],
8611
9175
  edges: []
8612
9176
  };
8613
9177
  }
@@ -9415,13 +9979,13 @@ function markdownRelationOccurrences(path, scenario, block, codeLines, label, ta
9415
9979
  return result;
9416
9980
  }
9417
9981
  function relationOccurrences2(node, field, targetType) {
9418
- const relationRecord = asRecord(node.attrs?.relationOccurrences);
9982
+ const relationRecord = asRecord2(node.attrs?.relationOccurrences);
9419
9983
  const rawOccurrences = toArray(relationRecord[field]);
9420
9984
  return rawOccurrences.flatMap((value) => {
9421
9985
  if (typeof value === "string") {
9422
9986
  return [{ field, targetType, target: value, path: node.path, line: node.line }];
9423
9987
  }
9424
- const record = asRecord(value);
9988
+ const record = asRecord2(value);
9425
9989
  const target = String(record.target ?? "").trim();
9426
9990
  if (!target) {
9427
9991
  return [];
@@ -9528,7 +10092,7 @@ function validateE2eTests(graph) {
9528
10092
  issues.push(issue("E2E_REQUIRED_FRONTMATTER", `${node.uid} missing required frontmatter ${field}`, node.path, 1, { node: node.uid, severity: "warning" }));
9529
10093
  }
9530
10094
  }
9531
- const fields = asRecord(attrs.tcFields);
10095
+ const fields = asRecord2(attrs.tcFields);
9532
10096
  const requiredTcFields = [
9533
10097
  ["\u6807\u9898", node.title],
9534
10098
  ["\u524D\u7F6E\u6761\u4EF6", fields["\u524D\u7F6E\u6761\u4EF6"]],
@@ -9578,7 +10142,7 @@ function validateE2eTests(graph) {
9578
10142
  }
9579
10143
  for (const [path, nodes] of nodesByPath) {
9580
10144
  const first = nodes[0];
9581
- const declared = flattenAcCoverage(asRecord(first.attrs?.ac_coverage));
10145
+ const declared = flattenAcCoverage(asRecord2(first.attrs?.ac_coverage));
9582
10146
  const covered = new Set(nodes.flatMap((node) => toArray(node.attrs?.coveredFeatures).map((value) => {
9583
10147
  const ref = value;
9584
10148
  return `${String(ref.feature)}:${String(ref.ac)}`;
@@ -9622,7 +10186,7 @@ function validateE2eRegistry(graph) {
9622
10186
  const first = actualNodes[0];
9623
10187
  compareRegistryValue(issues, registry, batch, "batch_id", first.attrs?.test_batch);
9624
10188
  compareRegistryValue(issues, registry, batch, "scope", first.attrs?.scope);
9625
- compareRegistryAcCoverage(issues, registry, batch, asRecord(first.attrs?.ac_coverage));
10189
+ compareRegistryAcCoverage(issues, registry, batch, asRecord2(first.attrs?.ac_coverage));
9626
10190
  compareRegistryArray(issues, registry, batch, "related_scenarios", toArray(first.attrs?.related_scenarios).map((value) => String(value)));
9627
10191
  compareRegistryValue(issues, registry, batch, "test_case_count", actualNodes.filter((node) => node.attrs?.fileLevelOnly !== true).length);
9628
10192
  }
@@ -9645,10 +10209,10 @@ async function validateExecutableTraceability(root, config) {
9645
10209
  const tcKeyToFields = /* @__PURE__ */ new Map();
9646
10210
  const mdBatches = /* @__PURE__ */ new Set();
9647
10211
  for (const relPath of e2eFiles) {
9648
- const raw = await readFile4(join10(root, relPath), "utf-8");
10212
+ const raw = await readFile4(join11(root, relPath), "utf-8");
9649
10213
  const parsed = matter(raw);
9650
10214
  const data = parsed.data;
9651
- const batch = String(data.test_batch ?? basename4(relPath, extname(relPath))).trim();
10215
+ const batch = String(data.test_batch ?? basename5(relPath, extname(relPath))).trim();
9652
10216
  const lines = raw.split(/\r?\n/);
9653
10217
  const tcStarts = extractE2eTestCaseStarts(lines);
9654
10218
  for (let i = 0; i < tcStarts.length; i += 1) {
@@ -9687,7 +10251,7 @@ async function validateExecutableTraceability(root, config) {
9687
10251
  const tcAnnotationRegex = /\/\/!?\s*@(?:e2e_test|tc)\s+(\S+?)\s+\[(\w+)\]/;
9688
10252
  const tcAnnotationNoLevelRegex = /\/\/!?\s*@(?:e2e_test|tc)\s+(\S+)/;
9689
10253
  for (const specFile of specFiles) {
9690
- const fullSpecPath = join10(root, specFile);
10254
+ const fullSpecPath = join11(root, specFile);
9691
10255
  let content;
9692
10256
  try {
9693
10257
  content = await readFile4(fullSpecPath, "utf-8");
@@ -9769,7 +10333,7 @@ async function validateExecutableTraceability(root, config) {
9769
10333
  if (entry.testId) {
9770
10334
  let content;
9771
10335
  try {
9772
- content = await readFile4(join10(root, normalizedRefFile), "utf-8");
10336
+ content = await readFile4(join11(root, normalizedRefFile), "utf-8");
9773
10337
  } catch {
9774
10338
  continue;
9775
10339
  }
@@ -9948,11 +10512,11 @@ async function computeE2eCoverageStats(graph, root, thresholds = {}) {
9948
10512
  const chainTypeBreakdown = {};
9949
10513
  const tcFieldsMap = new Map(e2eNodes.map((node) => [
9950
10514
  node.code,
9951
- asRecord(node.attrs?.tcFields)
10515
+ asRecord2(node.attrs?.tcFields)
9952
10516
  ]));
9953
10517
  for (const node of e2eNodes) {
9954
10518
  const tcKey = node.code;
9955
- const fields = tcFieldsMap.get(tcKey) ?? asRecord(node.attrs?.tcFields);
10519
+ const fields = tcFieldsMap.get(tcKey) ?? asRecord2(node.attrs?.tcFields);
9956
10520
  const execRef = String(fields["executable_ref"] ?? "").trim();
9957
10521
  if (execRef && !isPendingExecutableRef(execRef)) {
9958
10522
  withExecutableRef++;
@@ -9982,8 +10546,8 @@ async function computeE2eCoverageStats(graph, root, thresholds = {}) {
9982
10546
  }
9983
10547
  }
9984
10548
  for (const node of e2eNodes) {
9985
- const fields = tcFieldsMap.get(node.code) ?? asRecord(node.attrs?.tcFields);
9986
- const acCoverage = asRecord(fields["ac_coverage"] ?? node.attrs?.ac_coverage);
10549
+ const fields = tcFieldsMap.get(node.code) ?? asRecord2(node.attrs?.tcFields);
10550
+ const acCoverage = asRecord2(fields["ac_coverage"] ?? node.attrs?.ac_coverage);
9987
10551
  for (const feature of Object.keys(acCoverage)) {
9988
10552
  acCoveredFeatures.add(feature);
9989
10553
  }
@@ -9995,7 +10559,7 @@ async function computeE2eCoverageStats(graph, root, thresholds = {}) {
9995
10559
  const runners = (await loadConfig(root)).e2e?.runners ?? [];
9996
10560
  const allProjectFiles = await walkFiles(root);
9997
10561
  for (const node of e2eNodes) {
9998
- const fields = tcFieldsMap.get(node.code) ?? asRecord(node.attrs?.tcFields);
10562
+ const fields = tcFieldsMap.get(node.code) ?? asRecord2(node.attrs?.tcFields);
9999
10563
  const status = String(fields["status"] ?? "").trim().toLowerCase();
10000
10564
  const execRef = String(fields["executable_ref"] ?? "").trim();
10001
10565
  if (status !== "verified") continue;
@@ -10004,7 +10568,7 @@ async function computeE2eCoverageStats(graph, root, thresholds = {}) {
10004
10568
  let hasActiveE2eRef = false;
10005
10569
  for (const entry of parseExecutableRefLines(execRef)) {
10006
10570
  const normalized = resolveExecutableRefFile(entry.file, allProjectFiles);
10007
- if (!normalized || !existsSync3(join10(root, normalized))) continue;
10571
+ if (!normalized || !existsSync3(join11(root, normalized))) continue;
10008
10572
  const accepting = await getAcceptingRunners(root, normalized, runners);
10009
10573
  if (accepting.some((runner) => runner.kind === "e2e")) {
10010
10574
  hasActiveE2eRef = true;
@@ -10016,7 +10580,7 @@ async function computeE2eCoverageStats(graph, root, thresholds = {}) {
10016
10580
  for (const scenario of relatedScenarios) {
10017
10581
  verifiedScenarios.add(scenario);
10018
10582
  }
10019
- const acCoverage = asRecord(fields["ac_coverage"] ?? node.attrs?.ac_coverage);
10583
+ const acCoverage = asRecord2(fields["ac_coverage"] ?? node.attrs?.ac_coverage);
10020
10584
  for (const feature of Object.keys(acCoverage)) {
10021
10585
  verifiedFeatures.add(feature);
10022
10586
  }
@@ -10063,13 +10627,13 @@ async function computeE2eCoverageStats(graph, root, thresholds = {}) {
10063
10627
  const acCoverageRateByFeature = {};
10064
10628
  const featureAcMap = /* @__PURE__ */ new Map();
10065
10629
  for (const node of featureNodes) {
10066
- const acs = parseAcceptanceCriteria(await readFile4(join10(root, node.path), "utf-8"));
10630
+ const acs = parseAcceptanceCriteria(await readFile4(join11(root, node.path), "utf-8"));
10067
10631
  featureAcMap.set(node.code, new Set(acs));
10068
10632
  }
10069
10633
  const coveredAcByFeature = /* @__PURE__ */ new Map();
10070
10634
  for (const node of e2eNodes) {
10071
- const fields = tcFieldsMap.get(node.code) ?? asRecord(node.attrs?.tcFields);
10072
- const acCoverage = asRecord(fields["ac_coverage"] ?? node.attrs?.ac_coverage);
10635
+ const fields = tcFieldsMap.get(node.code) ?? asRecord2(node.attrs?.tcFields);
10636
+ const acCoverage = asRecord2(fields["ac_coverage"] ?? node.attrs?.ac_coverage);
10073
10637
  for (const [feature, acs] of Object.entries(acCoverage)) {
10074
10638
  const existing = coveredAcByFeature.get(feature) ?? /* @__PURE__ */ new Set();
10075
10639
  for (const ac of toArray(acs)) {
@@ -10111,11 +10675,11 @@ async function generateE2eRegistry(root, opts) {
10111
10675
  const batchIds = /* @__PURE__ */ new Set();
10112
10676
  let totalTestCases = 0;
10113
10677
  for (const file of files) {
10114
- const filePath = join10(root, file);
10678
+ const filePath = join11(root, file);
10115
10679
  const raw = await readFile4(filePath, "utf-8");
10116
10680
  const parsed = matter(raw);
10117
10681
  const data = parsed.data;
10118
- const batch = String(data.test_batch ?? basename4(file, extname(file))).trim();
10682
+ const batch = String(data.test_batch ?? basename5(file, extname(file))).trim();
10119
10683
  const relPath = file;
10120
10684
  const scope = String(data.scope ?? "").trim();
10121
10685
  const acCoverage = normalizeAcCoverageForRegistry(data.ac_coverage);
@@ -10237,7 +10801,7 @@ async function validatePartialRustEvidence(tcFields, tcKey, root, allFiles) {
10237
10801
  if (!normalizedPath) {
10238
10802
  return { hasValidPartialRust: false, detail: `partial_rust file not found: ${ref.file}` };
10239
10803
  }
10240
- const fullPath = join10(root, normalizedPath);
10804
+ const fullPath = join11(root, normalizedPath);
10241
10805
  let content;
10242
10806
  try {
10243
10807
  content = await readFile4(fullPath, "utf-8");
@@ -10274,7 +10838,7 @@ function detectTestLevel(specFile, content) {
10274
10838
  }
10275
10839
  function resolveExecutableRefFile(refFile, allFiles) {
10276
10840
  const normalized = refFile.replace(/\\/g, "/").replace(/^\.\//, "");
10277
- if (!normalized || isAbsolute5(refFile) || normalized.split("/").includes("..")) {
10841
+ if (!normalized || isAbsolute6(refFile) || normalized.split("/").includes("..")) {
10278
10842
  return void 0;
10279
10843
  }
10280
10844
  if (allFiles.includes(normalized)) {
@@ -10449,7 +11013,7 @@ function flattenAcCoverage(value) {
10449
11013
  return Object.entries(value).flatMap(([feature, refs]) => toArray(refs).map((ac) => ({ feature, ac: String(ac).replace(/^AC[-\s]?(\d+)$/i, (_match, digits) => `AC${Number(digits)}`) })));
10450
11014
  }
10451
11015
  function needsDesktopChainWarning(node) {
10452
- const tcFields = asRecord(node.attrs?.tcFields);
11016
+ const tcFields = asRecord2(node.attrs?.tcFields);
10453
11017
  const chainType = String(tcFields["chain_type"] ?? "").trim().toLowerCase();
10454
11018
  if (chainType && VALID_CHAIN_TYPES.has(chainType) && chainType !== "desktop_chain" || chainType in DEPRECATED_CHAIN_TYPE_ALIASES) {
10455
11019
  return false;
@@ -10506,7 +11070,7 @@ function compareRegistryAcCoverage(issues, registry, batch, actual) {
10506
11070
  issues.push(issue("E2E_REGISTRY_MISMATCH", `registry batch ${String(batch.batch_id ?? "")} ac_coverage cannot be determined`, registry.path, registry.line, { node: registry.uid, severity: "warning" }));
10507
11071
  return;
10508
11072
  }
10509
- if (normalizeAcCoverage(asRecord(batch.ac_coverage)) !== normalizeAcCoverage(actual)) {
11073
+ if (normalizeAcCoverage(asRecord2(batch.ac_coverage)) !== normalizeAcCoverage(actual)) {
10510
11074
  issues.push(issue("E2E_REGISTRY_MISMATCH", `registry batch ${String(batch.batch_id ?? "")} ac_coverage does not match actual file`, registry.path, registry.line, { node: registry.uid, severity: "warning" }));
10511
11075
  }
10512
11076
  }
@@ -10521,7 +11085,7 @@ function groupBy(values, key) {
10521
11085
  }
10522
11086
  return result;
10523
11087
  }
10524
- function asRecord(value) {
11088
+ function asRecord2(value) {
10525
11089
  return typeof value === "object" && value !== null && !Array.isArray(value) ? value : {};
10526
11090
  }
10527
11091
  function isEmptyValue(value) {
@@ -10580,7 +11144,7 @@ function normalizeDesignCode(value) {
10580
11144
  if (!raw) {
10581
11145
  return "";
10582
11146
  }
10583
- return basename4(raw, extname(raw));
11147
+ return basename5(raw, extname(raw));
10584
11148
  }
10585
11149
  function toUid(type, code) {
10586
11150
  return `${type}:${code}`;
@@ -10856,7 +11420,7 @@ function resolveArtifactContext(graph, opts) {
10856
11420
  }
10857
11421
  if (root) {
10858
11422
  for (const ap of ALWAYS_PRESENT_ITEMS) {
10859
- const fullPath = join10(root, ap.path);
11423
+ const fullPath = join11(root, ap.path);
10860
11424
  let stat3;
10861
11425
  try {
10862
11426
  stat3 = statSync(fullPath);
@@ -11098,7 +11662,7 @@ function formatContextMarkdown(manifest) {
11098
11662
  }
11099
11663
  return lines.join("\n");
11100
11664
  }
11101
- var TARGET_ARTIFACT_TYPES, NON_TARGET_ROLES, DEFAULT_SCHEMA, EMPTY_RELATION_FIELD_VALUES, VALID_TC_STATUSES, VALID_CHAIN_TYPES, DEPRECATED_CHAIN_TYPE_ALIASES, CONTEXT_CATEGORIES, TIER_ORDER;
11665
+ var TARGET_ARTIFACT_TYPES, NON_TARGET_ROLES, DEFAULT_SCHEMA, SPECIALIZED_PARSER_TYPES, EMPTY_RELATION_FIELD_VALUES, VALID_TC_STATUSES, VALID_CHAIN_TYPES, DEPRECATED_CHAIN_TYPE_ALIASES, CONTEXT_CATEGORIES, TIER_ORDER;
11102
11666
  var init_index = __esm({
11103
11667
  "src/index.ts"() {
11104
11668
  "use strict";
@@ -11120,6 +11684,7 @@ var init_index = __esm({
11120
11684
  init_git_changes();
11121
11685
  init_git_hook_path();
11122
11686
  init_hook_installer();
11687
+ init_professional_conclusion();
11123
11688
  init_review_result_validator();
11124
11689
  init_contract_kernel();
11125
11690
  init_restructure();
@@ -11172,6 +11737,33 @@ var init_index = __esm({
11172
11737
  runners: []
11173
11738
  }
11174
11739
  };
11740
+ SPECIALIZED_PARSER_TYPES = /* @__PURE__ */ new Set([
11741
+ "feature",
11742
+ "scenario",
11743
+ "entity",
11744
+ "decision",
11745
+ "test",
11746
+ "design",
11747
+ "e2e_test",
11748
+ "e2e_registry",
11749
+ "rule-golden-cases",
11750
+ "test-strategy",
11751
+ "traceability-matrix-v2",
11752
+ "traceability-version-lock",
11753
+ "interface_contracts",
11754
+ "data_contracts",
11755
+ "application_state_machines",
11756
+ "error_model",
11757
+ "domain-glossary",
11758
+ "bounded-context-map",
11759
+ "domain-invariants",
11760
+ "generation-packet-spec",
11761
+ "report-contracts",
11762
+ "verification-fixtures",
11763
+ "ui-flow-contracts",
11764
+ "non-functional-budgets",
11765
+ "implementation-blueprint"
11766
+ ]);
11175
11767
  EMPTY_RELATION_FIELD_VALUES = /* @__PURE__ */ new Set(["\u65E0", "none", "n/a", "-"]);
11176
11768
  VALID_TC_STATUSES = /* @__PURE__ */ new Set(["created", "automated", "verified", "waived"]);
11177
11769
  VALID_CHAIN_TYPES = /* @__PURE__ */ new Set([
@@ -11216,7 +11808,7 @@ var init_index = __esm({
11216
11808
 
11217
11809
  // src/packet-prompt-audit.ts
11218
11810
  import { mkdir as mkdir6, writeFile as writeFile4 } from "fs/promises";
11219
- import { join as join11 } from "path";
11811
+ import { join as join12 } from "path";
11220
11812
  function promptFilename(target) {
11221
11813
  return `prompt-${target.type}-${target.id}.md`;
11222
11814
  }
@@ -11268,7 +11860,7 @@ async function auditSinglePromptTarget(target, graph, options) {
11268
11860
  }
11269
11861
  if (options.outDir) {
11270
11862
  const filename = promptFilename(target);
11271
- const outPath = join11(options.outDir, filename);
11863
+ const outPath = join12(options.outDir, filename);
11272
11864
  await writeFile4(outPath, prompt, "utf-8");
11273
11865
  entry.outputPath = outPath;
11274
11866
  }
@@ -11374,9 +11966,9 @@ async function auditPromptBatch(root, targets, options, graph) {
11374
11966
  };
11375
11967
  if (options.outDir) {
11376
11968
  await mkdir6(options.outDir, { recursive: true });
11377
- const jsonPath = join11(options.outDir, "prompt-audit-summary.json");
11969
+ const jsonPath = join12(options.outDir, "prompt-audit-summary.json");
11378
11970
  await writeFile4(jsonPath, JSON.stringify(summary, null, 2) + "\n", "utf-8");
11379
- const mdPath = join11(options.outDir, "prompt-audit-summary.md");
11971
+ const mdPath = join12(options.outDir, "prompt-audit-summary.md");
11380
11972
  await writeFile4(mdPath, renderPromptAuditSummaryMarkdown(summary), "utf-8");
11381
11973
  }
11382
11974
  return summary;
@@ -11418,7 +12010,7 @@ __export(refactor_id_exports, {
11418
12010
  });
11419
12011
  import { chmod as chmod2, readFile as readFile5, rename as rename2, rm, readdir as readdir4, stat as stat2, writeFile as writeFile5 } from "fs/promises";
11420
12012
  import { randomBytes } from "crypto";
11421
- import { basename as basename5, dirname as dirname7, join as join12, relative as relative5 } from "path";
12013
+ import { basename as basename6, dirname as dirname8, join as join13, relative as relative5 } from "path";
11422
12014
  import yaml2 from "js-yaml";
11423
12015
  function escapeRegExp2(value) {
11424
12016
  return value.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&");
@@ -11596,7 +12188,7 @@ async function walkTextFiles(root) {
11596
12188
  for (const entry of entries) {
11597
12189
  if (entry.name.startsWith(".") && PROSE_SCAN_SKIP_DIRS.has(entry.name)) continue;
11598
12190
  if (PROSE_SCAN_SKIP_DIRS.has(entry.name)) continue;
11599
- const full = join12(dir, entry.name);
12191
+ const full = join13(dir, entry.name);
11600
12192
  if (entry.isDirectory()) {
11601
12193
  await visit(full);
11602
12194
  } else if (entry.isFile()) {
@@ -11611,7 +12203,7 @@ async function walkTextFiles(root) {
11611
12203
  return found.sort();
11612
12204
  }
11613
12205
  async function computeLockImpact(root, type, oldId) {
11614
- const lockPath = join12(root, VERSION_LOCK_PATH);
12206
+ const lockPath = join13(root, VERSION_LOCK_PATH);
11615
12207
  const impact = {
11616
12208
  lockPath: VERSION_LOCK_PATH,
11617
12209
  affectedImplementationLocks: [],
@@ -11703,7 +12295,7 @@ async function refactorId(options) {
11703
12295
  const fileContents = /* @__PURE__ */ new Map();
11704
12296
  const readArtifactFile = async (path) => {
11705
12297
  if (!fileContents.has(path)) {
11706
- fileContents.set(path, await readFile5(join12(root, path), "utf-8"));
12298
+ fileContents.set(path, await readFile5(join13(root, path), "utf-8"));
11707
12299
  }
11708
12300
  return fileContents.get(path);
11709
12301
  };
@@ -11779,7 +12371,7 @@ async function refactorId(options) {
11779
12371
  for (const relativePath of await walkTextFiles(root)) {
11780
12372
  if (relativePath === VERSION_LOCK_PATH) continue;
11781
12373
  if (relativePath === "artifact-graph.config.yaml") continue;
11782
- const raw = await readFile5(join12(root, relativePath), "utf-8");
12374
+ const raw = await readFile5(join13(root, relativePath), "utf-8");
11783
12375
  if (!containsIdToken(raw, oldId)) continue;
11784
12376
  const lines = raw.split(/\r?\n/);
11785
12377
  lines.forEach((line, index) => {
@@ -11855,7 +12447,7 @@ async function refactorId(options) {
11855
12447
  }
11856
12448
  if (options.__beforeWriteVerify) await options.__beforeWriteVerify();
11857
12449
  for (const path of targetFiles) {
11858
- const disk = await readFile5(join12(root, path), "utf-8");
12450
+ const disk = await readFile5(join13(root, path), "utf-8");
11859
12451
  if (disk !== fileContents.get(path)) {
11860
12452
  return fail("PLAN_DRIFT", `\u8BA1\u5212\u4E0E\u5199\u5165\u4E4B\u95F4\u76EE\u6807\u6587\u4EF6\u53D1\u751F\u53D8\u5316\uFF08apply \u4E2D\u6B62\uFF0C\u96F6\u5199\u5165\uFF09\uFF1A${path}`, { path });
11861
12453
  }
@@ -11866,7 +12458,7 @@ async function refactorId(options) {
11866
12458
  const tempPathFor = options.__tempPathFor ?? ((targetPath) => {
11867
12459
  tempSequence += 1;
11868
12460
  const suffix = randomBytes(4).toString("hex");
11869
- return join12(dirname7(targetPath), `.${basename5(targetPath)}.${process.pid}.${tempSequence}.${suffix}.refactor-id.tmp`);
12461
+ return join13(dirname8(targetPath), `.${basename6(targetPath)}.${process.pid}.${tempSequence}.${suffix}.refactor-id.tmp`);
11870
12462
  });
11871
12463
  let stage = "write";
11872
12464
  try {
@@ -11875,8 +12467,8 @@ async function refactorId(options) {
11875
12467
  if (options.__injectWriteFailure?.(path)) {
11876
12468
  throw Object.assign(new Error(`injected write failure: ${path}`), { code: "EINJECTED" });
11877
12469
  }
11878
- const original = fileContents.has(path) ? fileContents.get(path) : await readFile5(join12(root, path), "utf-8");
11879
- const targetPath = join12(root, path);
12470
+ const original = fileContents.has(path) ? fileContents.get(path) : await readFile5(join13(root, path), "utf-8");
12471
+ const targetPath = join13(root, path);
11880
12472
  const originalMode = (await stat2(targetPath)).mode & 4095;
11881
12473
  const tempPath = tempPathFor(targetPath);
11882
12474
  await writeFile5(tempPath, newContents.get(path), { encoding: "utf-8", flag: "wx" });
@@ -11899,8 +12491,8 @@ async function refactorId(options) {
11899
12491
  if (options.__injectRollbackFailure?.(entry.path)) {
11900
12492
  throw Object.assign(new Error(`injected rollback failure: ${entry.path}`), { code: "EROLLBACKINJECTED" });
11901
12493
  }
11902
- await writeFile5(join12(root, entry.path), entry.original, "utf-8");
11903
- await chmod2(join12(root, entry.path), entry.originalMode);
12494
+ await writeFile5(join13(root, entry.path), entry.original, "utf-8");
12495
+ await chmod2(join13(root, entry.path), entry.originalMode);
11904
12496
  } catch (rollbackError) {
11905
12497
  rollbackErrors.push({ path: entry.path, message: rollbackError.message });
11906
12498
  }
@@ -12033,8 +12625,8 @@ __export(cli_exports, {
12033
12625
  });
12034
12626
  import yaml3 from "js-yaml";
12035
12627
  import { realpathSync as realpathSync2 } from "fs";
12036
- import { access as access2, mkdir as mkdir7, readFile as readFile6, writeFile as writeFile6 } from "fs/promises";
12037
- import { dirname as dirname8, isAbsolute as isAbsolute6, join as join13 } from "path";
12628
+ import { access as access3, mkdir as mkdir7, readFile as readFile6, writeFile as writeFile6 } from "fs/promises";
12629
+ import { dirname as dirname9, isAbsolute as isAbsolute7, join as join14 } from "path";
12038
12630
  import { fileURLToPath as fileURLToPath3 } from "url";
12039
12631
  async function runCli(argv, io = {}) {
12040
12632
  const parsed = parseArgs(argv);
@@ -12062,7 +12654,7 @@ async function runCli(argv, io = {}) {
12062
12654
  switch (parsed.command) {
12063
12655
  case "init": {
12064
12656
  await initConfig(root);
12065
- out(`Created ${join13(root, "artifact-graph.config.yaml")}
12657
+ out(`Created ${join14(root, "artifact-graph.config.yaml")}
12066
12658
  `);
12067
12659
  return 0;
12068
12660
  }
@@ -12075,6 +12667,53 @@ async function runCli(argv, io = {}) {
12075
12667
  `);
12076
12668
  return 0;
12077
12669
  }
12670
+ case "check-professional": {
12671
+ const format = typeof parsed.flags.format === "string" ? parsed.flags.format : "json";
12672
+ if (format !== "json") {
12673
+ err(`Invalid --format: "${String(parsed.flags.format)}". Allowed values: json
12674
+ `);
12675
+ return 2;
12676
+ }
12677
+ const conclusionOutput = parsed.flags["conclusion-output"];
12678
+ if (conclusionOutput === true || conclusionOutput !== void 0 && typeof conclusionOutput !== "string") {
12679
+ err("Usage: artifact-graph check-professional --root <target> --format json [--conclusion-output <absolute-path>]\n");
12680
+ return 1;
12681
+ }
12682
+ if (typeof conclusionOutput === "string" && !isAbsolute7(conclusionOutput)) {
12683
+ err("--conclusion-output must be an absolute path\n");
12684
+ return 1;
12685
+ }
12686
+ const { conclusion, writeError } = await runCheckProfessional({
12687
+ root,
12688
+ conclusionOutput: typeof conclusionOutput === "string" ? conclusionOutput : void 0
12689
+ });
12690
+ out(`${JSON.stringify(conclusion, null, 2)}
12691
+ `);
12692
+ if (writeError) {
12693
+ err(`${writeError}
12694
+ `);
12695
+ return 1;
12696
+ }
12697
+ return 0;
12698
+ }
12699
+ case "read-proof": {
12700
+ const format = typeof parsed.flags.format === "string" ? parsed.flags.format : "json";
12701
+ if (format !== "json") {
12702
+ err(`Invalid --format: "${String(parsed.flags.format)}". Allowed values: json
12703
+ `);
12704
+ return 2;
12705
+ }
12706
+ const proofRoot = parsed.flags["proof-root"];
12707
+ const proof = parsed.flags.proof;
12708
+ if (typeof proofRoot !== "string" || typeof proof !== "string") {
12709
+ err("Usage: artifact-graph read-proof --proof-root <root> --proof <relative> --format json\n");
12710
+ return 1;
12711
+ }
12712
+ const { result, exitCode } = await runReadProof({ proofRoot, proof });
12713
+ out(`${JSON.stringify(result, null, 2)}
12714
+ `);
12715
+ return exitCode;
12716
+ }
12078
12717
  case "validate": {
12079
12718
  const includes = new Set(
12080
12719
  typeof parsed.flags.include === "string" ? parsed.flags.include.split(",") : []
@@ -13081,7 +13720,7 @@ async function runCli(argv, io = {}) {
13081
13720
  err("Usage: artifact-graph validate-review-result --file <path> [--format json]\n");
13082
13721
  return 1;
13083
13722
  }
13084
- const resolvedPath = isAbsolute6(filePath) ? filePath : join13(root, filePath);
13723
+ const resolvedPath = isAbsolute7(filePath) ? filePath : join14(root, filePath);
13085
13724
  let content;
13086
13725
  try {
13087
13726
  content = await readFile6(resolvedPath, "utf-8");
@@ -13119,7 +13758,7 @@ async function runCli(argv, io = {}) {
13119
13758
  const deterministic = checkMode || parsed.flags.deterministic === true;
13120
13759
  const registry = await generateE2eRegistry(root, { deterministic });
13121
13760
  const output = JSON.stringify(registry, null, 2) + "\n";
13122
- const outPath = typeof parsed.flags.out === "string" ? parsed.flags.out : join13(root, "artifacts/tests/e2e/e2e-test-registry.json");
13761
+ const outPath = typeof parsed.flags.out === "string" ? parsed.flags.out : join14(root, "artifacts/tests/e2e/e2e-test-registry.json");
13123
13762
  if (checkMode) {
13124
13763
  let existing = "";
13125
13764
  try {
@@ -13171,7 +13810,7 @@ async function runCli(argv, io = {}) {
13171
13810
  `);
13172
13811
  return 1;
13173
13812
  }
13174
- const planPath = isAbsolute6(planFlag) ? planFlag : join13(cwd, planFlag);
13813
+ const planPath = isAbsolute7(planFlag) ? planFlag : join14(cwd, planFlag);
13175
13814
  let planDocument;
13176
13815
  try {
13177
13816
  planDocument = JSON.parse(await readFile6(planPath, "utf8"));
@@ -13238,7 +13877,7 @@ async function runCli(argv, io = {}) {
13238
13877
  `);
13239
13878
  return 1;
13240
13879
  }
13241
- const resolvedInput = isAbsolute6(inputPath) ? inputPath : join13(cwd, inputPath);
13880
+ const resolvedInput = isAbsolute7(inputPath) ? inputPath : join14(cwd, inputPath);
13242
13881
  let input;
13243
13882
  try {
13244
13883
  input = JSON.parse(await readFile6(resolvedInput, "utf8"));
@@ -13266,8 +13905,8 @@ async function runCli(argv, io = {}) {
13266
13905
  `);
13267
13906
  return 1;
13268
13907
  }
13269
- const packageDir = dirname8(fileURLToPath3(import.meta.url));
13270
- const contractsDir = typeof parsed.flags["contracts-dir"] === "string" ? parsed.flags["contracts-dir"] : join13(packageDir, "..", "contracts");
13908
+ const packageDir = dirname9(fileURLToPath3(import.meta.url));
13909
+ const contractsDir = typeof parsed.flags["contracts-dir"] === "string" ? parsed.flags["contracts-dir"] : join14(packageDir, "..", "contracts");
13271
13910
  const revisionDigest = typeof parsed.flags["revision-digest"] === "string" ? parsed.flags["revision-digest"] : void 0;
13272
13911
  async function resolveContract(contractId) {
13273
13912
  const catalog = await loadContractCatalog(contractsDir);
@@ -13580,9 +14219,9 @@ function isGraphRelevantPath(path, schema) {
13580
14219
  return path === "artifact-graph.config.yaml" || path === VERSION_LOCK_PATH || matchesConfiguredArtifactPath(path, schema);
13581
14220
  }
13582
14221
  async function initConfig(root) {
13583
- const configPath = join13(root, "artifact-graph.config.yaml");
14222
+ const configPath = join14(root, "artifact-graph.config.yaml");
13584
14223
  try {
13585
- await access2(configPath);
14224
+ await access3(configPath);
13586
14225
  throw new Error(`Config already exists: ${configPath}`);
13587
14226
  } catch (error) {
13588
14227
  if (error.code !== "ENOENT") {
@@ -13634,9 +14273,9 @@ function parseTimeViewFlag(value, err) {
13634
14273
  }
13635
14274
  async function readReleaseInput(root, value) {
13636
14275
  if (value.includes(",")) return value.split(",");
13637
- const candidate = isAbsolute6(value) ? value : join13(root, value);
14276
+ const candidate = isAbsolute7(value) ? value : join14(root, value);
13638
14277
  try {
13639
- await access2(candidate);
14278
+ await access3(candidate);
13640
14279
  } catch {
13641
14280
  return [value];
13642
14281
  }
@@ -13655,6 +14294,12 @@ Commands:
13655
14294
  init
13656
14295
  scan
13657
14296
  validate [--format json] [--warning-only] [--include scenario-prd-links,e2e-coverage]
14297
+ check-professional --root <target> --format json [--conclusion-output <absolute-path>]
14298
+ Read-only composition of validate, version-lock audit, and coverage. Does not write graph cache.
14299
+ Absent artifact-graph.config.yaml is GRAPH_CHECK_UNAVAILABLE / not-performed; default loadConfig is not used here.
14300
+ Optional proof file is created exclusively and never overwrites an existing proof.
14301
+ read-proof --proof-root <root> --proof <relative> --format json
14302
+ Read one artifact-graph professional proof. Does not rescan the target or treat review-result as this contract.
13658
14303
  query [<target> | --from <code>] [--to <code>] [--depth <n>] [--view current|planned|history|all] [--format json]
13659
14304
  context (--target <type>:<id> | --feature <id> | --scenario <id> | --decision <id> | --design <id> | --e2e-test <id>) [--mode full|implementation] [--max-per-category <n>] [--view current|planned|history|all] [--format json]
13660
14305
  packet (--target <type>:<id> | --feature <id> | --scenario <id> | --decision <id> | --design <id> | --e2e-test <id>) [--mode full|implementation] [--max-per-category <n>] [--view current|planned|history|all] [--format json|markdown] [--out <path>] [--no-validate]
@@ -13742,6 +14387,7 @@ var init_cli = __esm({
13742
14387
  init_git_hook_path();
13743
14388
  init_hook_installer();
13744
14389
  init_versioned_traceability();
14390
+ init_professional_conclusion();
13745
14391
  if (isCliEntrypoint(process.argv[1])) {
13746
14392
  void runCli(process.argv.slice(2)).then((code) => {
13747
14393
  process.exitCode = code;