@tiinex/core 0.17.0 → 0.19.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.
Files changed (31) hide show
  1. package/package.json +7 -5
  2. package/src/tooling/portable/adapters/cli/cli.command-input.js +8 -1
  3. package/src/tooling/portable/adapters/cli/cli.common-author.js +29 -5
  4. package/src/tooling/portable/adapters/cli/cli.common-output.js +38 -3
  5. package/src/tooling/portable/adapters/cli/cli.handoff-manufacture.js +33 -17
  6. package/src/tooling/portable/adapters/cli/cli.handoff-sibling-allocation.js +139 -2
  7. package/src/tooling/portable/adapters/cli/cli.help.js +1 -1
  8. package/src/tooling/portable/adapters/cli/cli.run.js +4 -0
  9. package/src/tooling/portable/adapters/node/handoff.manufacture.js +25 -12
  10. package/src/tooling/portable/adapters/node/handoff.manufacture.packageParent.js +43 -0
  11. package/src/tooling/portable/grounding/grounding.capsule.js +22 -3
  12. package/src/tooling/portable/grounding/grounding.holderBindingAuthorization.js +81 -0
  13. package/src/tooling/portable/grounding/grounding.implementationSourceAuthority.js +109 -0
  14. package/src/tooling/portable/grounding/grounding.orchestrationReadiness.js +33 -0
  15. package/src/tooling/portable/grounding/grounding.participantAuthority.js +1 -1
  16. package/src/tooling/portable/grounding/grounding.participantContext.js +58 -0
  17. package/src/tooling/portable/grounding/grounding.processApplicability.js +38 -0
  18. package/src/tooling/portable/grounding/grounding.readiness.authority.js +63 -3
  19. package/src/tooling/portable/grounding/grounding.readiness.js +72 -12
  20. package/src/tooling/portable/grounding/grounding.readiness.support.js +5 -1
  21. package/src/tooling/portable/grounding/grounding.sourceEvidence.js +151 -9
  22. package/src/tooling/portable/handoff/carrierProjection.routeQualification.js +12 -1
  23. package/src/tooling/portable/handoff/coldStartQualification.grounding.js +62 -3
  24. package/src/tooling/portable/handoff/coldStartQualification.materials.js +19 -1
  25. package/src/tooling/portable/handoff/contextAudit.js +1 -1
  26. package/src/tooling/portable/handoff/delegationReturnReservation.js +4 -2
  27. package/src/tooling/portable/handoff/manufacture.js +1 -0
  28. package/src/tooling/portable/handoff/recipientV2.inspect.projection.js +3 -0
  29. package/src/tooling/portable/handoff/recipientV2.packageV1.inspect.js +1 -1
  30. package/src/tooling/portable/handoff/recoveryAcceptanceAudit.js +5 -3
  31. package/src/tooling/portable/schema/contract.field-domain.js +43 -2
@@ -1,6 +1,8 @@
1
1
  import { packageFileBytes, sha256Hex } from '../../../../export/package.bytes.js';
2
2
  import { inspectRecipientFacingV2Topology } from '../../handoff/recipientV2.inspect.js';
3
3
  import { parseHandoffPackageV1, RECIPIENT_V2_PACKAGE_V1_ROOT_PATH } from '../../handoff/recipientV2.packageV1.js';
4
+ import { projectHandoffMaterialRequirements } from '../../handoff/materialClosure.requirements.js';
5
+ import { parseWorkspaceQualifiedReference } from '../../handoff/workspaceQualifiedReference.js';
4
6
 
5
7
  export function preparePackageParentWorkspaceReuse(input = {}) {
6
8
  const bundle = input.bundle || null;
@@ -63,6 +65,7 @@ export function preparePackageParentWorkspaceReuse(input = {}) {
63
65
  providers: Object.freeze(providers),
64
66
  providerState: 'qualified',
65
67
  providerWorkspaceIds: Object.freeze(providers.map((item) => normalizeId(item.id))),
68
+ providerWorkspaceTargets: Object.freeze([...providerTargetById.entries()].map(([workspaceId, targetPath]) => Object.freeze({ workspaceId, path: targetPath }))),
66
69
  inherited: Object.freeze(inherited),
67
70
  workspaceTargets: Object.freeze(workspaceTargets),
68
71
  inspectionStatus: inspection.status,
@@ -74,6 +77,44 @@ export function preparePackageParentWorkspaceReuse(input = {}) {
74
77
  });
75
78
  }
76
79
 
80
+ export function projectRequiredContextWorkspaceSelectionPreflight(input = {}) {
81
+ const reuse = input.packageParentReuse || input.reuse || {};
82
+ const currentWorkspaceIds = new Set([...(input.currentWorkspaceIds || [])].map(normalizeId).filter(Boolean));
83
+ const inheritedWorkspaceIds = new Set((reuse.inherited || []).map((item) => normalizeId(item.id || item.enumeration?.materialization?.id || '')).filter(Boolean));
84
+ const providerTargets = new Map((reuse.providerWorkspaceTargets || []).map((item) => [normalizeId(item.workspaceId), normalizeWorkspacePath(item.path)]));
85
+ const requirements = projectHandoffMaterialRequirements({ markdown: String(input.handoffMarkdown || '') }).required || [];
86
+ const missing = [];
87
+ for (const requirement of requirements) {
88
+ const target = parseWorkspaceQualifiedReference(String(requirement.reference?.target || requirement.materialReference || ''));
89
+ if (!target) continue;
90
+ const workspaceId = normalizeId(target.workspaceId);
91
+ if (!workspaceId || currentWorkspaceIds.has(workspaceId) || inheritedWorkspaceIds.has(workspaceId)) continue;
92
+ const providerTarget = providerTargets.get(workspaceId) || '';
93
+ if (!providerTarget || providerTarget !== normalizeWorkspacePath(target.path)) continue;
94
+ if (!/\bworkspace\b/i.test(String(requirement.material || ''))) continue;
95
+ missing.push(Object.freeze({
96
+ requirementId: String(requirement.id || ''),
97
+ name: String(requirement.name || ''),
98
+ workspaceId,
99
+ material: String(requirement.material || ''),
100
+ purpose: String(requirement.purpose || ''),
101
+ referenceTarget: String(requirement.reference?.target || requirement.materialReference || ''),
102
+ providerWorkspaceTarget: providerTarget,
103
+ basis: 'explicit-required-context-workspace-material-matches-qualified-package-parent-workspace-target'
104
+ }));
105
+ }
106
+ const missingWorkspaceIds = Object.freeze([...new Set(missing.map((item) => item.workspaceId))].sort());
107
+ return Object.freeze({
108
+ state: missingWorkspaceIds.length ? 'action-required' : 'ready',
109
+ missingWorkspaceIds,
110
+ requirements: Object.freeze(missing),
111
+ nextAction: missingWorkspaceIds.length
112
+ ? `Re-run manufacture with --package-parent-workspaces ${missingWorkspaceIds.join(',')} to carry the explicitly required Workspace material from the qualified package parent.`
113
+ : 'No mechanically required package-parent Workspace carriage selection is missing.',
114
+ boundary: 'This preflight fires only when exact Handoff Required Context explicitly describes Workspace material and its workspace-qualified Material Reference exactly matches a qualified package-parent Workspace target. It never auto-selects source, infers Workspace intent from filenames alone, or treats carrier lineage as source authority.'
115
+ });
116
+ }
117
+
77
118
  export function normalizePackageParentWorkspaceSelection(value = []) {
78
119
  const raw = Array.isArray(value) ? value : [value];
79
120
  const tokens = raw.flatMap((item) => String(item || '').split(',')).map((item) => String(item || '').trim()).filter(Boolean);
@@ -205,6 +246,7 @@ function emptyReuse(state, options = {}) {
205
246
  providers: Object.freeze([]),
206
247
  providerState: String(options.providerState || 'unavailable'),
207
248
  providerWorkspaceIds: Object.freeze([]),
249
+ providerWorkspaceTargets: Object.freeze([]),
208
250
  inherited: Object.freeze([]),
209
251
  workspaceTargets: Object.freeze([]),
210
252
  inspectionStatus: String(options.inspectionStatus || ''),
@@ -218,6 +260,7 @@ function emptyReuse(state, options = {}) {
218
260
  });
219
261
  }
220
262
  function normalizeId(value = '') { return String(value || '').trim().toLowerCase().replace(/[^a-z0-9._-]+/g, '-').replace(/^-+|-+$/g, ''); }
263
+ function normalizeWorkspacePath(value = '') { return String(value || '').trim().replace(/\\/g, '/').replace(/^\/+/, ''); }
221
264
  function mediaTypeForPath(value = '') { const lower = String(value || '').toLowerCase(); if (lower.endsWith('.md')) return 'text/markdown'; if (lower.endsWith('.json')) return 'application/json'; if (/\.(?:m?js|cjs)$/.test(lower)) return 'text/javascript'; if (lower.endsWith('.ts')) return 'text/typescript'; if (lower.endsWith('.css')) return 'text/css'; if (lower.endsWith('.html')) return 'text/html'; if (/\.(?:yml|yaml)$/.test(lower)) return 'text/yaml'; if (lower.endsWith('.txt')) return 'text/plain'; return 'application/octet-stream'; }
222
265
  function stableJson(value) { return JSON.stringify(sortJson(value)); }
223
266
  function sortJson(value) { if (Array.isArray(value)) return value.map(sortJson); if (!value || typeof value !== 'object') return value; return Object.fromEntries(Object.keys(value).sort().map((key) => [key, sortJson(value[key])])); }
@@ -2,6 +2,9 @@ import { projectParticipantAuthority } from './grounding.participantAuthority.js
2
2
  import { projectWorkProvenance } from './grounding.workProvenance.js';
3
3
  import { projectGroundingSourceEvidence } from './grounding.sourceEvidence.js';
4
4
  import { projectGroundingPlanningContext } from './grounding.planningContext.js';
5
+ import { projectGroundingParticipantContext } from './grounding.participantContext.js';
6
+ import { projectGroundingProcessApplicability } from './grounding.processApplicability.js';
7
+ import { projectGroundingImplementationSourceAuthority } from './grounding.implementationSourceAuthority.js';
5
8
 
6
9
  export const PORTABLE_GROUNDING_CAPSULE_SCHEMA_ID = 'tiinex.portable.grounding-capsule.v1';
7
10
 
@@ -12,23 +15,39 @@ export function projectGroundingCapsule({ authority = null, continuation = null,
12
15
  const routeRecords = selectedRouteRecords(authority, records);
13
16
  const workProvenance = projectWorkProvenance({ records, topology });
14
17
  const participantAuthority = projectParticipantAuthority(authority);
18
+ const participantContext = projectGroundingParticipantContext(authority);
19
+ const processApplicability = projectGroundingProcessApplicability(authority);
20
+ const implementationSourceAuthority = projectGroundingImplementationSourceAuthority({ authority, records, contextAudit, requiredContext });
21
+ const sourceEvidence = projectGroundingSourceEvidence({ records, contextAudit, continuation, requiredContext });
15
22
  return Object.freeze({
16
23
  schema: PORTABLE_GROUNDING_CAPSULE_SCHEMA_ID,
17
24
  semanticReductions: Object.freeze(requiredContext.slice(0, MAX_CONTEXT).map(reduceRequiredContext)),
18
25
  frontier: projectFrontier(topology, blockers),
19
26
  exclusions: Object.freeze(routeRecords.flatMap((record) => parseExclusions(record.markdown || '')).slice(0, MAX_EXCLUSIONS)),
20
- sourceEvidence: projectGroundingSourceEvidence({ records, contextAudit, continuation }),
27
+ sourceEvidence,
21
28
  planningContext: projectGroundingPlanningContext(requiredContext),
22
29
  roleState: Object.freeze({
23
30
  recipient: String(authority?.role?.endpoint?.label || authority?.handoff?.to || ''),
24
31
  recipientState: String(authority?.role?.state || 'unresolved'),
25
32
  holder: String(authority?.holderBinding?.roleLabel || ''),
26
33
  holderState: String(authority?.holderBinding?.state || 'unresolved'),
27
- compatibility: String(authority?.holderBinding?.recipientCompatibility || 'unresolved')
34
+ compatibility: String(authority?.holderBinding?.recipientCompatibility || 'unresolved'),
35
+ authorizationState: String(authority?.holderBinding?.authorization?.state || (String(authority?.holderBinding?.state || '') === 'not-applicable' ? 'not-applicable' : 'unresolved')),
36
+ authorizationSource: String(authority?.holderBinding?.authorization?.source || ''),
37
+ durableIdentityState: String(authority?.holderBinding?.durableIdentity?.state || 'not-established')
28
38
  }),
29
39
  participantAuthority,
40
+ participantContext,
41
+ processApplicability,
42
+ implementationSourceAuthority,
30
43
  workProvenance,
31
- unresolved: Object.freeze([...workProvenance.unresolved]),
44
+ unresolved: Object.freeze([
45
+ ...workProvenance.unresolved,
46
+ ...participantContext.unresolved,
47
+ ...processApplicability.unresolved,
48
+ ...implementationSourceAuthority.unresolved,
49
+ ...sourceEvidence.blockers.map((item) => ({ code: item.code, detail: item.request }))
50
+ ]),
32
51
  boundary: 'Full Required Context bodies remain selector-gated.'
33
52
  });
34
53
  }
@@ -0,0 +1,81 @@
1
+ import { deepFreeze, normalizeComparable, normalizeToken } from '../handoff/coldStartQualification.shared.js';
2
+
3
+ export const EXPLICIT_SESSION_OR_HANDOFF_HOLDER_STATE = 'assignable per explicit session or Handoff';
4
+ export const CURRENT_ROLE_EXPLICIT_SESSION_OR_HANDOFF_HOLDER_STATE = 'assignable per explicit session, role invocation, or Handoff; no permanent holder asserted';
5
+ export const ANCHOR_EXPLICIT_SESSION_OR_HANDOFF_HOLDER_STATE = 'assignable per explicit session or Handoff; no permanent holder asserted';
6
+
7
+ const AUTHORIZED_EXPLICIT_SESSION_OR_HANDOFF_STATES = new Set([
8
+ normalizeComparable(EXPLICIT_SESSION_OR_HANDOFF_HOLDER_STATE),
9
+ normalizeComparable(CURRENT_ROLE_EXPLICIT_SESSION_OR_HANDOFF_HOLDER_STATE),
10
+ normalizeComparable(ANCHOR_EXPLICIT_SESSION_OR_HANDOFF_HOLDER_STATE)
11
+ ]);
12
+
13
+ export function projectHolderBindingAuthorization(role = {}) {
14
+ const endpointKind = normalizeToken(role?.endpoint?.kind || '');
15
+ if (endpointKind !== 'role') return deepFreeze({
16
+ state: 'not-applicable',
17
+ assignmentMode: '',
18
+ holderState: '',
19
+ source: 'none',
20
+ reasonCode: 'recipient-not-role',
21
+ provenance: {
22
+ basis: 'recipient-not-role',
23
+ roleArtifactPath: '',
24
+ roleArtifactSha256: '',
25
+ section: 'Holder Relationship',
26
+ field: 'Holder State',
27
+ boundary: 'Holder-assignment authorization is only applicable when the selected Handoff recipient is a Role endpoint.'
28
+ },
29
+ boundary: 'No Role assignment authorization is required for a non-Role recipient.'
30
+ });
31
+
32
+ const material = role?.material?.artifact || null;
33
+ const relationship = role?.holderRelationshipLoaded || {};
34
+ const holderState = String(relationship.holderState || '').trim();
35
+ const qualifiedMaterial = String(role?.state || '') === 'qualified'
36
+ && String(role?.material?.state || '') === 'qualified'
37
+ && Boolean(material?.path)
38
+ && Boolean(material?.sha256);
39
+ const provenance = {
40
+ basis: qualifiedMaterial ? 'exact-qualified-role-holder-relationship' : 'exact-qualified-role-holder-relationship-not-established',
41
+ roleArtifactPath: String(material?.path || ''),
42
+ roleArtifactSha256: String(material?.sha256 || ''),
43
+ roleSchemaId: String(material?.schemaId || ''),
44
+ roleLabel: String(material?.roleLabel || role?.endpoint?.label || ''),
45
+ section: 'Holder Relationship',
46
+ field: 'Holder State',
47
+ exactValue: holderState,
48
+ boundary: 'Only exact qualified recipient Role material may authorize the bounded session assignment mode. Handoff endpoints, transport identity, explicit session input, filenames, and package placement do not provide this authority.'
49
+ };
50
+
51
+ if (!qualifiedMaterial) return deepFreeze({
52
+ state: 'unresolved',
53
+ assignmentMode: '',
54
+ holderState,
55
+ source: 'none',
56
+ reasonCode: 'qualified-role-holder-authority-not-established',
57
+ provenance,
58
+ boundary: 'A matching session Role assertion remains unauthorized until exact qualified Role material establishes the assignment mode.'
59
+ });
60
+
61
+ const assignmentAuthorized = AUTHORIZED_EXPLICIT_SESSION_OR_HANDOFF_STATES.has(normalizeComparable(holderState));
62
+ if (!assignmentAuthorized) return deepFreeze({
63
+ state: 'unresolved',
64
+ assignmentMode: '',
65
+ holderState,
66
+ source: 'qualified-recipient-role-material',
67
+ reasonCode: holderState ? 'holder-assignment-mode-not-authorized' : 'holder-assignment-mode-unresolved',
68
+ provenance,
69
+ boundary: 'The exact qualified Role does not establish authorization for explicit-session/Handoff assignment. Core preserves this as unresolved and does not reinterpret other Holder State wording.'
70
+ });
71
+
72
+ return deepFreeze({
73
+ state: 'qualified',
74
+ assignmentMode: 'explicit-session-or-handoff',
75
+ holderState,
76
+ source: 'qualified-recipient-role-material',
77
+ reasonCode: 'holder-assignment-mode-authorized',
78
+ provenance,
79
+ boundary: 'Exact qualified Role Holder Relationship authorizes this assignment mode for the bounded current session only; it does not establish durable holder identity or broader participant/process/source authority.'
80
+ });
81
+ }
@@ -0,0 +1,109 @@
1
+ const MAX_FACTS = 12;
2
+ const MAX_WORKSPACE_FACTS = 12;
3
+
4
+ export function projectGroundingImplementationSourceAuthority({ authority = null, records = [], contextAudit = null, requiredContext = [] } = {}) {
5
+ const supplied = authority?.implementationSourceAuthority || null;
6
+ const exactUpstream = qualifiesExactUpstreamProjection(supplied);
7
+ const descriptiveFacts = projectDescriptiveWorkspaceFacts({ records, contextAudit, requiredContext });
8
+
9
+ if (!exactUpstream) return Object.freeze({
10
+ state: 'unresolved',
11
+ facts: Object.freeze([]),
12
+ descriptiveFacts,
13
+ provenance: Object.freeze({
14
+ basis: 'no-exact-upstream-qualified-implementation-source-authority-projection',
15
+ sourceArtifact: null,
16
+ boundary: 'Core does not derive implementation-source creation authority from Workspace carriage, completeness, boundedness, writability language, path adjacency, repository identity, or current Task wording.'
17
+ }),
18
+ unresolved: Object.freeze([Object.freeze({
19
+ code: 'implementation-source-authority-not-established',
20
+ detail: 'No exact upstream-qualified implementation-source authority projection is present. Workspace purpose/boundary facts remain descriptive only; do not infer permission to create or select implementation source from carriage, writability, repository identity, path adjacency, or executable Task presence.'
21
+ })]),
22
+ boundary: 'Semantics-neutral diagnostic only. Core exposes exact upstream authority projections when independently qualified, but does not define allow/deny meaning or manufacture source-creation permission.'
23
+ });
24
+
25
+ const facts = Array.isArray(supplied.facts) ? supplied.facts : Array.isArray(supplied.items) ? supplied.items : [];
26
+ return Object.freeze({
27
+ state: 'explicit-qualified-upstream-projection',
28
+ facts: Object.freeze(facts.slice(0, MAX_FACTS).map((item) => Object.freeze({ ...(item || {}) }))),
29
+ descriptiveFacts,
30
+ provenance: Object.freeze({
31
+ basis: 'exact-upstream-qualified-implementation-source-authority-projection',
32
+ sourceArtifact: Object.freeze(projectSourceArtifact(supplied)),
33
+ upstreamProvenance: supplied.provenance ? Object.freeze({ ...(supplied.provenance || {}) }) : null,
34
+ boundary: 'Core passes through the already-qualified upstream projection and exact source-artifact identity without interpreting its semantic allow/deny meaning.'
35
+ }),
36
+ unresolved: Object.freeze([]),
37
+ boundary: 'Semantics-neutral pass-through only. The upstream semantic owner defines the meaning of projected facts; Core neither broadens nor converts them into generic source authority.'
38
+ });
39
+ }
40
+
41
+ function qualifiesExactUpstreamProjection(value = null) {
42
+ if (!value || typeof value !== 'object' || value.explicit !== true) return false;
43
+ if (String(value.qualification || value.state || '').trim().toLowerCase() !== 'qualified') return false;
44
+ const source = projectSourceArtifact(value);
45
+ return Boolean(source.path && /^[0-9a-f]{64}$/i.test(source.sha256));
46
+ }
47
+
48
+ function projectSourceArtifact(value = {}) {
49
+ const source = value.sourceArtifact || value.provenance?.sourceArtifact || {};
50
+ return {
51
+ workspaceId: String(source.workspaceId || source.workspace || ''),
52
+ path: String(source.path || source.workspaceRelativePath || value.provenance?.sourceArtifactPath || ''),
53
+ sha256: String(source.sha256 || value.provenance?.sourceArtifactSha256 || '').trim().toLowerCase(),
54
+ schemaId: String(source.schemaId || '')
55
+ };
56
+ }
57
+
58
+ function projectDescriptiveWorkspaceFacts({ records = [], contextAudit = null, requiredContext = [] } = {}) {
59
+ const byPath = new Map((records || []).map((record) => [String(record.path || ''), record]));
60
+ const out = [];
61
+ for (const workspace of contextAudit?.workspaceMaterializations || []) {
62
+ if (out.length >= MAX_WORKSPACE_FACTS) break;
63
+ if (String(workspace.qualification || '') !== 'qualified') continue;
64
+ const workspaceId = String(workspace.workspaceId || '');
65
+ const innerPath = normalizePath(workspace.sourceWorkspaceTargetInnerPath || '');
66
+ const exactPath = workspaceId && innerPath ? `${workspaceId}/${innerPath}` : '';
67
+ const record = exactPath ? byPath.get(exactPath) : null;
68
+ if (!record || !record.hasContinuityContext || !record.hasIntegrity) continue;
69
+ const boundary = section(record.markdown || '', 'Workspace Boundary');
70
+ if (!boundary) continue;
71
+ out.push(Object.freeze({
72
+ kind: 'workspace-boundary',
73
+ workspace: workspaceId,
74
+ text: compact(boundary, 500),
75
+ authorityEffect: 'descriptive-only',
76
+ provenance: Object.freeze({
77
+ basis: 'exact-qualified-workspace-artifact-section',
78
+ sourceArtifactPath: exactPath,
79
+ sourceArtifactSha256: String(workspace.sourceWorkspaceTargetSha256 || ''),
80
+ section: 'Workspace Boundary',
81
+ boundary: 'Exact carried Workspace metadata is exposed as a fact only; Core does not reinterpret boundary prose as implementation-source creation permission.'
82
+ })
83
+ }));
84
+ }
85
+ for (const entry of requiredContext || []) {
86
+ if (out.length >= MAX_WORKSPACE_FACTS) break;
87
+ if (String(entry.state || '') !== 'qualified' || !String(entry.purpose || '').trim()) continue;
88
+ out.push(Object.freeze({
89
+ kind: 'required-context-purpose',
90
+ workspace: String(entry.workspaceId || ''),
91
+ text: compact(entry.purpose, 500),
92
+ authorityEffect: 'descriptive-only',
93
+ provenance: Object.freeze({
94
+ basis: String(entry.provenance?.basis || 'selected-handoff-required-context-declaration'),
95
+ declarationSource: entry.provenance?.declarationSource ? Object.freeze({ ...(entry.provenance.declarationSource || {}) }) : null,
96
+ requirementId: String(entry.requirementId || ''),
97
+ boundary: 'Selected-Handoff purpose text is exposed verbatim as route context; it is not converted into implementation-source creation authority.'
98
+ })
99
+ }));
100
+ }
101
+ return Object.freeze(out);
102
+ }
103
+
104
+ function section(markdown = '', heading = '') {
105
+ const escaped = String(heading || '').replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
106
+ return String(markdown || '').match(new RegExp(`(?:^|\\n)##\\s+${escaped}\\s*\\r?\\n([\\s\\S]*?)(?=\\n##\\s+|\\n#\\s+Continuity Integrity|$)`, 'i'))?.[1]?.trim() || '';
107
+ }
108
+ function compact(value = '', limit = 500) { const text = String(value || '').replace(/\s+/g, ' ').trim(); return text.length > limit ? `${text.slice(0, limit - 1).trimEnd()}…` : text; }
109
+ function normalizePath(value = '') { return String(value || '').replace(/\\/g, '/').replace(/^\/+/, ''); }
@@ -0,0 +1,33 @@
1
+ export function projectGroundingOrchestrationReadiness({ readinessState = '', participantContext = null, processApplicability = null, sourceEvidence = null, topology = {} } = {}) {
2
+ const boundedAction = String(readinessState || '');
3
+ const participantMap = String(participantContext?.participantMapState || 'not-established');
4
+ const unavailableSources = sourceEvidence?.blockers || [];
5
+ const sourceScope = sourceScopeState(sourceEvidence);
6
+ const processState = String(processApplicability?.state || 'not-established');
7
+ const blockers = [];
8
+ if (participantMap !== 'explicit-bounded-map') blockers.push(Object.freeze({ code: 'participant-capability-map-not-established', detail: 'Current route grounding does not establish a semantic participant/capability map. Grounding-only Role pointers and endpoint labels are insufficient.' }));
9
+ if (unavailableSources.length) blockers.push(...unavailableSources.map((item) => Object.freeze({ code: item.code || 'authoritative-material-unavailable', detail: item.request || item.name || item.referenceTarget || '' })));
10
+ if (sourceScope !== 'explicit-multi-source') blockers.push(Object.freeze({ code: 'source-authority-scope-bounded', detail: 'Source evidence is bounded to exact carried/current-route material and does not establish whole-program source authority.' }));
11
+ if (processState !== 'explicit-qualified-authority') blockers.push(Object.freeze({
12
+ code: 'process-applicability-semantic-authority-not-established',
13
+ detail: String(processApplicability?.unresolved?.[0]?.detail || 'Current grounding does not contain an explicit upstream-qualified process-applicability projection; process inventory and Role carriage are not substitutes.')
14
+ }));
15
+ if (!(topology.currentFrontier || []).length) blockers.push(Object.freeze({ code: 'current-work-frontier-unresolved', detail: 'No exact current Task frontier is resolved for orchestration.' }));
16
+ return Object.freeze({
17
+ state: blockers.length ? 'bounded-route-only' : 'sufficiently-grounded-for-current-orchestration-scope',
18
+ boundedActionReadiness: boundedAction,
19
+ widerOrchestration: Object.freeze({ state: blockers.length ? 'not-established' : 'bounded-established', blockers: Object.freeze(blockers.slice(0, 8)) }),
20
+ participantMap,
21
+ sourceScope,
22
+ processApplicability: processApplicability || Object.freeze({ state: processState, unresolved: Object.freeze([]) }),
23
+ boundary: 'Diagnostic projection only; this is not a new lifecycle state and does not weaken or broaden grounded-to-act. Route authorization is not treated as whole-program understanding.'
24
+ });
25
+ }
26
+
27
+ function sourceScopeState(sourceEvidence = {}) {
28
+ const workspaces = sourceEvidence?.workspaces || [];
29
+ const qualified = workspaces.filter((item) => ['qualified', 'explicit-profile'].includes(String(item.state || '')));
30
+ if (qualified.length > 1 && qualified.every((item) => item.sources?.length || item.repository || item.rootPath)) return 'explicit-multi-source';
31
+ if (qualified.length) return 'bounded-current-route';
32
+ return 'unresolved';
33
+ }
@@ -10,7 +10,7 @@ export function projectParticipantAuthority(authority = null) {
10
10
  recipientRole: String(role.endpoint?.label || authority?.handoff?.to || ''),
11
11
  roleMaterial: Object.freeze({ path: String(material.path || ''), schemaId: String(material.schemaId || ''), roleLabel: String(material.roleLabel || '') }),
12
12
  authorityBoundary: Object.freeze({ mayDo: compact(declared.mayDo), doesNotAuthorize: compact(declared.doesNotAuthorize), reviewBoundary: compact(declared.reviewBoundary) }),
13
- holderBinding: Object.freeze({ state: String(holder.state || 'unresolved'), roleLabel: String(holder.roleLabel || ''), source: String(holder.source || 'none'), explicit: Boolean(holder.explicit), inferredFromTransport: Boolean(holder.inferredFromTransport) }),
13
+ holderBinding: Object.freeze({ state: String(holder.state || 'unresolved'), bindingPresent: String(holder.state || '') === 'qualified', declarationPresent: Boolean(holder.explicit), roleLabel: String(holder.roleLabel || ''), source: String(holder.source || 'none'), sourceDetail: holder.sourceDetail ? Object.freeze({ ...(holder.sourceDetail || {}) }) : null, authorization: holder.authorization ? Object.freeze({ ...holder.authorization, provenance: holder.authorization.provenance ? Object.freeze({ ...holder.authorization.provenance }) : null }) : null, durableIdentity: holder.durableIdentity ? Object.freeze({ ...holder.durableIdentity }) : Object.freeze({ state: 'not-established' }), semanticAuthorityState: String(holder.sourceDetail?.semanticAuthorityState || 'not-established'), explicit: Boolean(holder.explicit), inferredFromTransport: Boolean(holder.inferredFromTransport) }),
14
14
  participantIdentityCreatesAuthority: false,
15
15
  conversationPositionCreatesAuthority: false,
16
16
  universalHumanFeedbackRule: false,
@@ -0,0 +1,58 @@
1
+ const MAX_PARTICIPANTS = 8;
2
+ const MAX_ROLES = 8;
3
+
4
+ export function projectGroundingParticipantContext(authority = null) {
5
+ const participation = authority?.participation || {};
6
+ const semanticParticipants = (participation.participants || []).slice(0, MAX_PARTICIPANTS).map((item) => Object.freeze({
7
+ id: String(item.id || ''),
8
+ label: String(item.label || ''),
9
+ roles: Object.freeze([...(item.roles || [])].map(String)),
10
+ verification: String(item.verification || 'declared'),
11
+ semanticParticipant: true,
12
+ basis: 'explicit-participant-declaration',
13
+ provenance: Object.freeze({
14
+ basis: 'explicit-qualified-participation-input',
15
+ source: String(item.source || item.provenance?.source || ''),
16
+ boundary: 'Only explicit semantic participant authority is projected as participation.'
17
+ })
18
+ }));
19
+ const roleGrounding = (participation.packageRoleGrounding || participation.packageRoleParticipants || []).slice(0, MAX_ROLES).map((item) => Object.freeze({
20
+ label: String(item.label || item.roleArtifact?.roleLabel || ''),
21
+ pointerPath: String(item.pointerPath || ''),
22
+ roleArtifact: Object.freeze({ ...(item.roleArtifact || {}) }),
23
+ groundingOnly: true,
24
+ semanticParticipant: false,
25
+ basis: 'explicit-package-role-grounding-pointer',
26
+ provenance: Object.freeze({
27
+ basis: 'package-role-grounding-pointer',
28
+ pointerPath: String(item.pointerPath || ''),
29
+ boundary: 'This proves only package-local Role grounding availability, not semantic participation.'
30
+ })
31
+ }));
32
+ const endpoints = (participation.handoffCapacities || []).slice(0, 2).map((item) => Object.freeze({
33
+ direction: String(item.direction || ''),
34
+ label: String(item.label || ''),
35
+ kind: String(item.kind || ''),
36
+ semanticClass: 'handoff-capacity',
37
+ semanticParticipant: false,
38
+ provenance: Object.freeze({
39
+ basis: 'selected-handoff-endpoint',
40
+ boundary: 'Handoff endpoint capacity is not a participant declaration.'
41
+ })
42
+ }));
43
+ const mapState = semanticParticipants.length ? 'explicit-bounded-map' : 'not-established';
44
+ return Object.freeze({
45
+ state: semanticParticipants.length ? 'explicit-semantic-participants' : roleGrounding.length ? 'qualified-role-grounding-only' : 'unresolved',
46
+ participantMapState: mapState,
47
+ semanticParticipants: Object.freeze(semanticParticipants),
48
+ roleGrounding: Object.freeze(roleGrounding),
49
+ endpoints: Object.freeze(endpoints),
50
+ unresolved: Object.freeze(semanticParticipants.length ? [] : [{
51
+ code: 'participant-map-not-established',
52
+ detail: 'No explicit semantic participant declaration or authoritative participant Relation is present in the current grounding input. Carried Role pointers remain grounding-only.',
53
+ basis: 'absence-of-explicit-semantic-participant-authority',
54
+ nextAuthorityNeeded: 'Provide an explicit qualified participant declaration/projection from semantic authority; do not infer it from Roles or Handoff endpoints.'
55
+ }]),
56
+ boundary: 'Only explicit semantic participant declarations count as participants here. Package Role grounding pointers and Handoff endpoints are projected separately and never infer participation, holder identity, delegation, or relevance from Role inventory, filenames, transport, chat position, or package adjacency.'
57
+ });
58
+ }
@@ -0,0 +1,38 @@
1
+ const MAX_FACTS = 12;
2
+
3
+ export function projectGroundingProcessApplicability(authority = null) {
4
+ const supplied = authority?.processApplicability || null;
5
+ const explicitlyQualified = Boolean(
6
+ supplied
7
+ && supplied.explicit === true
8
+ && String(supplied.qualification || supplied.state || '') === 'qualified'
9
+ );
10
+ if (!explicitlyQualified) return Object.freeze({
11
+ state: 'not-established',
12
+ facts: Object.freeze([]),
13
+ provenance: Object.freeze({
14
+ basis: 'no-upstream-qualified-explicit-process-applicability-projection',
15
+ source: '',
16
+ boundary: 'Core does not discover process inventory or define the semantic declaration pattern. It consumes only an upstream projection already marked explicit and qualified by semantic authority.'
17
+ }),
18
+ unresolved: Object.freeze([Object.freeze({
19
+ code: 'process-applicability-semantic-authority-not-established',
20
+ detail: 'Current qualified grounding authority contains no explicit, upstream-qualified process-applicability projection. Supply semantic-owner-qualified applicability authority; do not infer applicability from carried Roles, Handoff endpoints, filenames, folders, process inventory, or repository adjacency.'
21
+ })]),
22
+ boundary: 'Semantics-neutral pass-through only. Absence stays unresolved; carriage and inventory never become applicability.'
23
+ });
24
+
25
+ const facts = Array.isArray(supplied.facts) ? supplied.facts : Array.isArray(supplied.items) ? supplied.items : [];
26
+ return Object.freeze({
27
+ state: 'explicit-qualified-authority',
28
+ facts: Object.freeze(facts.slice(0, MAX_FACTS).map((item) => Object.freeze({ ...(item || {}) }))),
29
+ provenance: Object.freeze({
30
+ basis: 'upstream-qualified-explicit-process-applicability-projection',
31
+ source: String(supplied.source || supplied.provenance?.source || ''),
32
+ upstreamProvenance: supplied.provenance ? Object.freeze({ ...(supplied.provenance || {}) }) : null,
33
+ boundary: 'Facts are passed through without Core interpreting process inventory or inventing process-to-participant semantics.'
34
+ }),
35
+ unresolved: Object.freeze([]),
36
+ boundary: 'Semantics-neutral pass-through only. Core does not define or expand the declaration pattern that established these facts.'
37
+ });
38
+ }
@@ -1,12 +1,72 @@
1
1
  export function projectGroundingAuthority(authority, mode) {
2
2
  if (!authority || mode !== 'routed-handoff-package') return Object.freeze({ state: 'not-supplied', route: null, handoff: null, role: null, holderBinding: null, operationBoundary: null });
3
3
  const mutationBoundary = authority.mutationBoundary || null;
4
+ const selectedRoute = authority.selectedRoute || null;
5
+ const handoff = authority.handoff || null;
4
6
  return Object.freeze({
5
7
  state: String(authority.status || ''),
6
- route: authority.selectedRoute ? Object.freeze({ id: authority.selectedRoute.id || '', pointerPath: authority.selectedRoute.pointerPath || '', workspaceId: authority.selectedRoute.workspaceId || '' }) : null,
7
- handoff: authority.handoff ? Object.freeze({ purpose: authority.handoff.purpose || '', from: authority.handoff.from || '', to: authority.handoff.to || '', completionExpectation: authority.handoff.completionExpectation || null }) : null,
8
+ route: selectedRoute ? Object.freeze({
9
+ id: selectedRoute.id || '',
10
+ pointerPath: selectedRoute.pointerPath || '',
11
+ workspaceId: selectedRoute.workspaceId || '',
12
+ workspaceRelativePath: selectedRoute.workspaceRelativeHandoffPath || selectedRoute.workspaceRelativePath || '',
13
+ sha256: selectedRoute.sha256 || '',
14
+ provenance: Object.freeze({
15
+ basis: 'explicit-qualified-route-selection',
16
+ pointerPath: selectedRoute.pointerPath || '',
17
+ workspaceId: selectedRoute.workspaceId || '',
18
+ workspaceRelativePath: selectedRoute.workspaceRelativeHandoffPath || selectedRoute.workspaceRelativePath || '',
19
+ boundary: 'Route authority is bounded to the exact qualified selected route; nearby package routes and filenames are not substituted.'
20
+ })
21
+ }) : null,
22
+ handoff: handoff ? Object.freeze({
23
+ purpose: handoff.purpose || '',
24
+ from: handoff.from || '',
25
+ to: handoff.to || '',
26
+ transfers: Object.freeze((handoff.transfers || []).map((item) => Object.freeze({ ...item }))),
27
+ completionExpectation: handoff.completionExpectation || null,
28
+ provenance: Object.freeze({
29
+ basis: 'exact-selected-handoff-bytes',
30
+ routeId: handoff.routeId || selectedRoute?.id || '',
31
+ workspaceId: handoff.workspaceId || selectedRoute?.workspaceId || '',
32
+ workspaceRelativePath: handoff.workspaceRelativePath || selectedRoute?.workspaceRelativeHandoffPath || '',
33
+ packagePath: handoff.packagePath || selectedRoute?.packagePath || '',
34
+ sha256: handoff.sha256 || selectedRoute?.sha256 || '',
35
+ boundary: handoff.boundary || 'Exact selected Handoff bytes are semantic authority for Handoff parties, purpose, transfers and completion expectation.'
36
+ })
37
+ }) : null,
8
38
  role: authority.role ? Object.freeze({ state: authority.role.state || '', label: authority.role.endpoint?.label || '', kind: authority.role.endpoint?.kind || '' }) : null,
9
- holderBinding: authority.holderBinding ? Object.freeze({ state: authority.holderBinding.state || '', holderId: authority.holderBinding.holderId || '', roleLabel: authority.holderBinding.roleLabel || '', recipientRoleLabel: authority.holderBinding.recipientRoleLabel || '', recipientCompatibility: authority.holderBinding.recipientCompatibility || '', source: authority.holderBinding.source || '', explicit: Boolean(authority.holderBinding.explicit), inferredFromTransport: Boolean(authority.holderBinding.inferredFromTransport), boundary: authority.holderBinding.boundary || '' }) : null,
39
+ holderBinding: authority.holderBinding ? Object.freeze({
40
+ state: authority.holderBinding.state || '',
41
+ bindingPresent: String(authority.holderBinding.state || '') === 'qualified',
42
+ declarationPresent: Boolean(authority.holderBinding.explicit),
43
+ holderId: authority.holderBinding.holderId || '',
44
+ roleLabel: authority.holderBinding.roleLabel || '',
45
+ recipientRoleLabel: authority.holderBinding.recipientRoleLabel || '',
46
+ recipientCompatibility: authority.holderBinding.recipientCompatibility || '',
47
+ source: authority.holderBinding.source || '',
48
+ sourceDetail: authority.holderBinding.sourceDetail ? Object.freeze({ ...(authority.holderBinding.sourceDetail || {}) }) : null,
49
+ authorization: authority.holderBinding.authorization ? Object.freeze({
50
+ ...(authority.holderBinding.authorization || {}),
51
+ provenance: authority.holderBinding.authorization.provenance ? Object.freeze({ ...(authority.holderBinding.authorization.provenance || {}) }) : null
52
+ }) : null,
53
+ durableIdentity: authority.holderBinding.durableIdentity ? Object.freeze({ ...(authority.holderBinding.durableIdentity || {}) }) : Object.freeze({ state: 'not-established' }),
54
+ semanticAuthorityState: authority.holderBinding.sourceDetail?.semanticAuthorityState || 'not-established',
55
+ explicit: Boolean(authority.holderBinding.explicit),
56
+ inferredFromTransport: Boolean(authority.holderBinding.inferredFromTransport),
57
+ provenance: Object.freeze({
58
+ basis: authority.holderBinding.explicit ? 'explicit-consuming-session-holder-binding' : 'unresolved-or-non-explicit-holder-binding',
59
+ source: authority.holderBinding.source || '',
60
+ sourceKind: authority.holderBinding.sourceDetail?.kind || '',
61
+ sourceLocator: authority.holderBinding.sourceDetail?.locator || '',
62
+ semanticAuthorityState: authority.holderBinding.sourceDetail?.semanticAuthorityState || 'not-established',
63
+ qualifiedMaterialSource: Boolean(authority.holderBinding.sourceDetail?.qualifiedMaterialSource),
64
+ authorizationState: authority.holderBinding.authorization?.state || 'unresolved',
65
+ authorizationBasis: authority.holderBinding.authorization?.provenance?.basis || '',
66
+ boundary: authority.holderBinding.boundary || 'Consuming-session holder identity is never inferred from route transport or recipient position.'
67
+ }),
68
+ boundary: authority.holderBinding.boundary || ''
69
+ }) : null,
10
70
  operationBoundary: mutationBoundary ? Object.freeze({
11
71
  ...mutationBoundary,
12
72
  scope: 'current-grounding-operation-only',