@tiinex/core 0.30.0 → 0.31.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tiinex/core",
3
- "version": "0.30.0",
3
+ "version": "0.31.0",
4
4
  "description": "Shared host-neutral Tiinex implementation core for artifacts, schemas, validation, lineage, grounding, Handoffs, provenance and deterministic workflows.",
5
5
  "type": "module",
6
6
  "sideEffects": true,
@@ -173,12 +173,12 @@
173
173
  "type": "git",
174
174
  "url": "git+https://github.com/Tiinex/core.git"
175
175
  },
176
- "gitHead": "5d51273d4c10f8a15367c32bcef8bbce11484ca8",
176
+ "gitHead": "54c359f5d721194579aec2089cae096643912f07",
177
177
  "tiinexRelease": {
178
178
  "policy": "tiinex.master-npm-release.v1",
179
- "sourceCommit": "5d51273d4c10f8a15367c32bcef8bbce11484ca8",
180
- "sourceTree": "1372b29b40dbee5e11d2a52d9cac7731f41941a2",
179
+ "sourceCommit": "54c359f5d721194579aec2089cae096643912f07",
180
+ "sourceTree": "fbf8219dabf97f9939544b63387372c2c705726e",
181
181
  "repository": "Tiinex/core",
182
- "previousVersion": "0.29.0"
182
+ "previousVersion": "0.30.0"
183
183
  }
184
184
  }
@@ -0,0 +1,120 @@
1
+ export const SCHEMA_LINEAGE_SOURCE_AUTHORITY_QUALIFICATION_SCHEMA_ID = 'tiinex.core.schema-lineage-source-authority-qualification.v1';
2
+
3
+ export function qualifyCompiledSchemaLineageSourceAuthority(validationContract = {}) {
4
+ const lineage = Array.isArray(validationContract?.lineage) ? validationContract.lineage.map((item) => String(item || '').trim()) : [];
5
+ const projected = Array.isArray(validationContract?.lineageAuthority) ? validationContract.lineageAuthority : [];
6
+ const findings = [];
7
+ const edges = [];
8
+
9
+ if (!lineage.length || validationContract?.lineageQualification?.state !== 'valid') {
10
+ findings.push('Compiled validation lineage is unavailable or not valid.');
11
+ }
12
+ if (projected.length !== lineage.length) {
13
+ findings.push(`Compiled validation lineage source authority cardinality is ${projected.length}; expected ${lineage.length}.`);
14
+ }
15
+
16
+ const count = Math.min(projected.length, lineage.length);
17
+ for (let index = 0; index < count; index += 1) {
18
+ const entry = projected[index] || {};
19
+ const expectedSchemaId = lineage[index] || '';
20
+ const actualSchemaId = String(entry?.schemaId || '').trim();
21
+ if (!actualSchemaId || actualSchemaId !== expectedSchemaId) {
22
+ findings.push(`Compiled lineage source authority identity mismatch at index ${index}: expected ${expectedSchemaId || '(missing schema id)'} but observed ${actualSchemaId || '(missing schema id)'}.`);
23
+ }
24
+ }
25
+
26
+ for (let index = 1; index < count; index += 1) {
27
+ const parent = projected[index - 1] || {};
28
+ const child = projected[index] || {};
29
+ const parentSchemaId = String(parent?.schemaId || '').trim();
30
+ const childSchemaId = String(child?.schemaId || '').trim();
31
+ const declaredParentSchemaId = String(child?.parentSchemaId || '').trim();
32
+ const parentSource = normalizeSourceTuple(parent?.source || {});
33
+ const candidates = Object.freeze((Array.isArray(child?.parentSourceCandidates) ? child.parentSourceCandidates : []).map(normalizeSourceTuple));
34
+
35
+ if (!declaredParentSchemaId || declaredParentSchemaId !== parentSchemaId) {
36
+ findings.push(`Compiled lineage identity is incoherent across ${parentSchemaId || '(unknown parent)'} -> ${childSchemaId || '(unknown child)'}.`);
37
+ edges.push(freezeEdge({ state: 'contradictory', parentSchemaId, childSchemaId, actual: parentSource, candidates, reason: 'parent-schema-identity-mismatch' }));
38
+ continue;
39
+ }
40
+
41
+ if (isQualifiedLocalUnpublishedSchemaSource(parent?.source || {})) {
42
+ edges.push(freezeEdge({ state: 'qualified-local-supersession', parentSchemaId, childSchemaId, actual: parentSource, candidates, reason: 'qualified-local-unpublished-parent-authority' }));
43
+ continue;
44
+ }
45
+
46
+ const exactCandidates = candidates.filter(completeSourceTuple);
47
+ if (candidates.length !== 1 || exactCandidates.length !== 1) {
48
+ const reason = candidates.length > 1 ? 'ambiguous-parent-source-authority' : 'parent-source-authority-unavailable';
49
+ findings.push(candidates.length > 1
50
+ ? `Declared parent source authority is ambiguous for ${childSchemaId}: ${candidates.length} exact pinned candidates.`
51
+ : `Declared parent source authority is unavailable for ${childSchemaId} -> ${parentSchemaId}.`);
52
+ edges.push(freezeEdge({ state: 'unresolved', parentSchemaId, childSchemaId, actual: parentSource, candidates, reason }));
53
+ continue;
54
+ }
55
+
56
+ const expected = exactCandidates[0];
57
+ if (!sameSourceTuple(parentSource, expected)) {
58
+ findings.push(`Compiled lineage substitutes source authority for ${childSchemaId} -> ${parentSchemaId}: declared ${formatSource(expected)} but compiled ${formatSource(parentSource)}.`);
59
+ edges.push(freezeEdge({ state: 'contradictory', parentSchemaId, childSchemaId, actual: parentSource, candidates, reason: 'compiled-parent-source-substitution' }));
60
+ continue;
61
+ }
62
+
63
+ edges.push(freezeEdge({ state: 'qualified', parentSchemaId, childSchemaId, actual: parentSource, candidates, reason: 'exact-parent-source-match' }));
64
+ }
65
+
66
+ const contradictory = edges.some((edge) => edge.state === 'contradictory') || findings.some((finding) => finding.includes('identity mismatch') || finding.includes('identity is incoherent') || finding.includes('substitutes source authority'));
67
+ const unresolved = !contradictory && (findings.length > 0 || edges.some((edge) => edge.state === 'unresolved'));
68
+ const state = contradictory ? 'contradictory' : unresolved ? 'unresolved' : 'qualified';
69
+ return deepFreeze({
70
+ schema: SCHEMA_LINEAGE_SOURCE_AUTHORITY_QUALIFICATION_SCHEMA_ID,
71
+ state,
72
+ complete: state === 'qualified',
73
+ lineage: Object.freeze([...lineage]),
74
+ edges: Object.freeze(edges),
75
+ findings: Object.freeze(findings),
76
+ boundary: 'Exact runtime validation authority requires source-coherent compiled inheritance. Qualified local unpublished Parent authority may intentionally supersede published Parent locators; all other inheritance edges require one exact declared Parent source tuple matching the compiled Parent material.'
77
+ });
78
+ }
79
+
80
+ export function isQualifiedLocalUnpublishedSchemaSource(source = {}) {
81
+ return String(source?.publicationState || '').trim().toLowerCase() === 'accepted-local-unpublished'
82
+ && String(source?.snapshotCompleteness || '').trim() === 'exact-axiom-canonical-unpublished-bounded-workspace-contract';
83
+ }
84
+
85
+ function normalizeSourceTuple(value = {}) {
86
+ return Object.freeze({
87
+ repository: String(value?.repository || '').trim(),
88
+ commit: String(value?.commit || '').trim().toLowerCase(),
89
+ path: String(value?.path || '').trim()
90
+ });
91
+ }
92
+
93
+ function completeSourceTuple(value = {}) {
94
+ return Boolean(value.repository && /^[0-9a-f]{40}$/.test(value.commit) && value.path);
95
+ }
96
+
97
+ function sameSourceTuple(left = {}, right = {}) {
98
+ return left.repository === right.repository && left.commit === right.commit && left.path === right.path;
99
+ }
100
+
101
+ function formatSource(value = {}) {
102
+ return `${value.repository || '(unknown repo)'}@${value.commit || '(unknown commit)'}/${value.path || '(unknown path)'}`;
103
+ }
104
+
105
+ function freezeEdge(value = {}) {
106
+ return Object.freeze({
107
+ state: String(value.state || 'unresolved'),
108
+ parentSchemaId: String(value.parentSchemaId || ''),
109
+ childSchemaId: String(value.childSchemaId || ''),
110
+ actual: value.actual || Object.freeze({ repository: '', commit: '', path: '' }),
111
+ candidates: value.candidates || Object.freeze([]),
112
+ reason: String(value.reason || '')
113
+ });
114
+ }
115
+
116
+ function deepFreeze(value) {
117
+ if (!value || typeof value !== 'object' || Object.isFrozen(value)) return value;
118
+ for (const child of Object.values(value)) deepFreeze(child);
119
+ return Object.freeze(value);
120
+ }
@@ -1,5 +1,6 @@
1
1
  import { sha256Hex, utf8Bytes } from '../export/package.bytes.js';
2
2
  import { qualifyGithubSchemaSourceProvider } from './schema.githubSourceTarget.js';
3
+ import { qualifyCompiledSchemaLineageSourceAuthority } from './schema.lineageAuthority.js';
3
4
 
4
5
  export const BUNDLED_SCHEMA_SOURCE_SCHEMA_ID = 'tiinex.site.bundled-schema-source.v1';
5
6
  export const SCHEMA_RUNTIME_PROJECTION_SCHEMA_ID = 'tiinex.site.schema-runtime-projection.v1';
@@ -48,6 +49,7 @@ export function defineBundledSchemaSource(binding = {}, projection = {}, options
48
49
  ...(!loadedBlobSha ? ['Loaded schema Git-blob identity is unavailable from the runtime projection.'] : [])
49
50
  ])
50
51
  });
52
+ const validationLineageAuthority = qualifyCompiledSchemaLineageSourceAuthority(runtimeProjection.validationContract || {});
51
53
  const validationContract = projectionExact && runtimeProjection.validationContract?.schemaId === schemaId && runtimeProjection.validationContract?.lineageQualification?.state === 'valid'
52
54
  ? runtimeProjection.validationContract
53
55
  : null;
@@ -85,6 +87,7 @@ export function defineBundledSchemaSource(binding = {}, projection = {}, options
85
87
  authority,
86
88
  bindingMaterialCoherence,
87
89
  materialIdentity,
90
+ validationLineageAuthority,
88
91
  compiledContract,
89
92
  projection: runtimeProjection,
90
93
  findings: Object.freeze([
@@ -93,7 +96,8 @@ export function defineBundledSchemaSource(binding = {}, projection = {}, options
93
96
  ...(runtimeProjection.sourceChecksum !== expectedChecksum ? ['Schema runtime projection source checksum does not match binding.'] : []),
94
97
  ...(runtimeProjection.bindingChecksum !== expectedChecksum ? ['Schema runtime projection binding checksum does not match binding.'] : []),
95
98
  ...(runtimeProjection.validationContract && runtimeProjection.validationContract?.schemaId !== schemaId ? ['Schema runtime validation projection identity does not match binding.'] : []),
96
- ...(runtimeProjection.validationContract && runtimeProjection.validationContract?.lineageQualification?.state !== 'valid' ? ['Schema runtime validation projection lineage is not exact/valid.'] : [])
99
+ ...(runtimeProjection.validationContract && runtimeProjection.validationContract?.lineageQualification?.state !== 'valid' ? ['Schema runtime validation projection lineage is not exact/valid.'] : []),
100
+ ...(validationLineageAuthority.state !== 'qualified' ? validationLineageAuthority.findings : [])
97
101
  ])
98
102
  });
99
103
  return cached;
@@ -13,10 +13,19 @@ export function portableRuntimeValidationContractForSchema(schemaId = '', resolu
13
13
  const resolution = resolutionInput || resolveSchemaModule({ schemaId });
14
14
  if (resolution?.fallbackUsed || !resolution?.module) return unavailable('registered-schema-resolution-unavailable', { resolution });
15
15
  const qualification = typeof resolution.module.schemaSource?.qualify === 'function' ? resolution.module.schemaSource.qualify() : null;
16
+ const lineageAuthority = qualification?.validationLineageAuthority || null;
17
+ if (qualification?.state === 'qualified' && lineageAuthority && lineageAuthority.state !== 'qualified') {
18
+ return unavailable('compiled-validation-lineage-source-authority-unqualified', {
19
+ resolution,
20
+ findings: Object.freeze([...(lineageAuthority.findings || [])]),
21
+ lineageAuthority,
22
+ baseQualificationState: String(qualification?.state || 'unavailable')
23
+ });
24
+ }
16
25
  const baseContract = qualification?.state === 'qualified' ? qualification?.compiledContract?.validationContract || null : null;
17
- if (!baseContract) return unavailable(qualification?.state === 'qualified' ? 'compiled-validation-contract-unavailable' : 'schema-source-unqualified', { resolution });
26
+ if (!baseContract) return unavailable(qualification?.state === 'qualified' ? 'compiled-validation-contract-unavailable' : 'schema-source-unqualified', { resolution, findings: Object.freeze([...(qualification?.findings || [])]), baseQualificationState: String(qualification?.state || 'unavailable') });
18
27
  const projected = projectPortableValidationContractWithQualifiedLocalRoot(baseContract);
19
- return deepFreeze({ ...projected, resolution, baseQualificationState: String(qualification?.state || 'unavailable') });
28
+ return deepFreeze({ ...projected, resolution, lineageAuthority, baseQualificationState: String(qualification?.state || 'unavailable') });
20
29
  }
21
30
 
22
31
  export function portableRuntimeValidationAuthorityForRecord(record = {}) {
@@ -26,7 +35,10 @@ export function portableRuntimeValidationAuthorityForRecord(record = {}) {
26
35
  const schemaId = String(declaredSchema.id || record?.schemaId || record?.currentSchemaId || '').trim();
27
36
  const runtime = portableRuntimeValidationContractForSchema(schemaId);
28
37
  if (runtime.state !== 'qualified' || !runtime.compiledContract) {
29
- return unavailableAuthority(schemaId, runtime, ['Registered compiled validation authority is unavailable for the declared Current Schema.']);
38
+ const runtimeFindings = Array.isArray(runtime?.findings) && runtime.findings.length
39
+ ? runtime.findings
40
+ : ['Registered compiled validation authority is unavailable for the declared Current Schema.'];
41
+ return unavailableAuthority(schemaId, runtime, runtimeFindings);
30
42
  }
31
43
 
32
44
  const findings = [];