@tiinex/core 0.18.0 → 0.20.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 (38) hide show
  1. package/package.json +8 -6
  2. package/src/schemas/creation.contracts.js +1 -1
  3. package/src/schemas/party/role/tiinex.party.role.v1.schema.js +5 -0
  4. package/src/schemas/party/role/tiinex.party.role.v1.schema.json +2 -2
  5. package/src/schemas/party/role/tiinex.party.role.v1.schema.md +313 -0
  6. package/src/schemas/party/role/tiinex.party.role.v1.schema.runtime.json +18 -6
  7. package/src/schemas/party/role/tiinex.party.role.v1.validate.js +36 -0
  8. package/src/schemas/schema.reference.js +29 -0
  9. package/src/tooling/portable/adapters/cli/cli.command-input.js +8 -1
  10. package/src/tooling/portable/adapters/cli/cli.common-author.js +117 -6
  11. package/src/tooling/portable/adapters/cli/cli.common-output.js +26 -0
  12. package/src/tooling/portable/adapters/cli/cli.handoff-manufacture.js +33 -17
  13. package/src/tooling/portable/adapters/cli/cli.handoff-sibling-allocation.js +139 -2
  14. package/src/tooling/portable/adapters/cli/cli.help.js +1 -1
  15. package/src/tooling/portable/adapters/node/handoff.manufacture.js +30 -5
  16. package/src/tooling/portable/adapters/node/handoff.manufacture.packageParent.js +123 -0
  17. package/src/tooling/portable/audit/audit.capability.js +10 -4
  18. package/src/tooling/portable/grounding/grounding.capsule.js +33 -2
  19. package/src/tooling/portable/grounding/grounding.delegationArtifactAuthority.js +220 -0
  20. package/src/tooling/portable/grounding/grounding.delegationReadiness.js +241 -0
  21. package/src/tooling/portable/grounding/grounding.holderAssignmentModes.js +125 -0
  22. package/src/tooling/portable/grounding/grounding.holderBindingAuthorization.js +80 -0
  23. package/src/tooling/portable/grounding/grounding.implementationSourceAuthority.js +109 -0
  24. package/src/tooling/portable/grounding/grounding.participantAuthority.js +1 -1
  25. package/src/tooling/portable/grounding/grounding.readiness.authority.js +15 -0
  26. package/src/tooling/portable/grounding/grounding.readiness.js +86 -13
  27. package/src/tooling/portable/grounding/grounding.readiness.support.js +2 -2
  28. package/src/tooling/portable/handoff/carrierProjection.routeQualification.js +20 -4
  29. package/src/tooling/portable/handoff/coldStartQualification.grounding.js +116 -5
  30. package/src/tooling/portable/handoff/coldStartQualification.materials.js +92 -10
  31. package/src/tooling/portable/handoff/delegationReturnReservation.js +4 -2
  32. package/src/tooling/portable/handoff/manufacture.js +1 -0
  33. package/src/tooling/portable/handoff/recipientV2.endpointRolePointers.js +1 -1
  34. package/src/tooling/portable/handoff/recipientV2.inspect.projection.js +7 -1
  35. package/src/tooling/portable/handoff/recipientV2.packageV1.build.js +2 -2
  36. package/src/tooling/portable/handoff/recipientV2.packageV1.inspect.js +1 -1
  37. package/src/tooling/portable/handoff/recipientV2.topology.js +5 -3
  38. package/src/tooling/portable/handoff/recipientV2.topology.materials.js +0 -0
@@ -0,0 +1,241 @@
1
+ const MAX_CAPABILITIES = 12;
2
+ const MAX_FACTS = 12;
3
+
4
+ export function projectGroundingDelegationReadiness({ authority = null, processApplicability = null, implementationSourceAuthority = null } = {}) {
5
+ const delegateCapabilityAuthority = projectDelegateCapabilityAuthority(authority?.delegateCapabilityAuthority || authority?.delegationContext?.delegateCapabilityAuthority || null);
6
+ const targetAuthority = projectDelegationTargetAuthority(authority?.delegationTargetAuthority || authority?.delegationContext?.targetAuthority || authority?.delegationContext?.delegationTargetAuthority || null);
7
+ const returnReconciliationExpectation = projectDelegationReturnReconciliationExpectation(authority?.delegationReturnReconciliationExpectation || authority?.delegationContext?.returnReconciliationExpectation || authority?.delegationContext?.delegationReturnReconciliationExpectation || null);
8
+ const process = processApplicability || Object.freeze({ state: 'not-established', unresolved: Object.freeze([]) });
9
+ const source = implementationSourceAuthority || Object.freeze({ state: 'unresolved', unresolved: Object.freeze([]) });
10
+ const blockers = [];
11
+
12
+ if (delegateCapabilityAuthority.state !== 'explicit-qualified-forward-selection') blockers.push(blocker(
13
+ 'delegate-capability-authority-not-established',
14
+ delegateCapabilityAuthority.unresolved?.[0]?.detail || 'No explicit upstream-qualified forward-selected delegate/capability authority is established.',
15
+ 'Provide an explicit upstream-qualified forward-selected delegate/capability projection with exact source-artifact identity. Cached Role presence, participant inventory, Handoff endpoint labels, filenames and chat position are not delegate selection authority.'
16
+ ));
17
+ const processReady = String(process.state || '') === 'explicit-qualified-authority' && Array.isArray(process.facts) && process.facts.length > 0 && Boolean(String(process.provenance?.source || process.provenance?.upstreamProvenance?.source || '').trim());
18
+ if (!processReady) blockers.push(blocker(
19
+ 'delegation-process-applicability-not-established',
20
+ process.unresolved?.[0]?.detail || 'Delegation/process applicability is not explicitly established by upstream semantic authority.',
21
+ 'Provide the explicit upstream-qualified process/delegation applicability projection. Do not infer applicability from Role/cache inventory or repository adjacency.'
22
+ ));
23
+ if (targetAuthority.state !== 'explicit-qualified-target-authority') blockers.push(blocker(
24
+ 'delegation-target-authority-not-established',
25
+ targetAuthority.unresolved?.[0]?.detail || 'Target repository/workspace authority and repo-local Task/Handoff placement are not explicitly established.',
26
+ 'Provide an explicit upstream-qualified delegation target projection naming repository, workspaceId, taskDirectory and handoffDirectory with exact source-artifact identity.'
27
+ ));
28
+ const sourceReady = String(source.state || '') === 'explicit-qualified-upstream-projection' && Array.isArray(source.facts) && source.facts.length > 0;
29
+ if (!sourceReady) blockers.push(blocker(
30
+ 'delegation-source-authority-not-established',
31
+ source.unresolved?.[0]?.detail || 'Implementation/source authority is not explicitly established by upstream semantic authority.',
32
+ 'Provide the exact upstream-qualified implementation-source authority projection. Workspace carriage, writability text, repository identity and executable Task presence remain descriptive only.'
33
+ ));
34
+ if (returnReconciliationExpectation.state !== 'explicit-qualified-return-reconciliation') blockers.push(blocker(
35
+ 'delegation-return-reconciliation-expectation-not-established',
36
+ returnReconciliationExpectation.unresolved?.[0]?.detail || 'Return/reconciliation responsibility is not explicitly established.',
37
+ 'Provide an explicit upstream-qualified return/reconciliation projection with Completion Expectation and an explicit reconciliation state/expectation.'
38
+ ));
39
+
40
+ const ready = blockers.length === 0;
41
+ return Object.freeze({
42
+ state: ready ? 'qualified-for-delegation-authoring' : 'not-established',
43
+ delegateCapabilityAuthority,
44
+ processApplicability: process,
45
+ targetAuthority,
46
+ sourceAuthority: source,
47
+ returnReconciliationExpectation,
48
+ blockers: Object.freeze(blockers),
49
+ plainChatFallbackPermitted: false,
50
+ repositoryScanningFallbackPermitted: false,
51
+ nextOperations: ready ? projectNextOperations({ delegateCapabilityAuthority, targetAuthority, returnReconciliationExpectation }) : Object.freeze([]),
52
+ boundary: 'Mechanical delegation qualification only. Core consumes already-explicit, already-qualified semantic projections and exposes the normal Task -> Handoff -> carrier Tooling path; it never selects a delegate, invents process applicability, generates a work plan, grants source authority, or treats cached Role presence as delegation authority.'
53
+ });
54
+ }
55
+
56
+ export function projectDelegateCapabilityAuthority(value = null) {
57
+ const base = qualifyExplicitProjection(value);
58
+ if (!base.qualified) return unresolvedProjection('delegate-capability-authority-not-established', 'No exact upstream-qualified explicit delegate/capability projection is present.');
59
+ const delegate = value?.delegate || value?.selectedDelegate || {};
60
+ const label = String(delegate.label || delegate.roleLabel || value?.delegateLabel || '').trim();
61
+ const kind = String(delegate.kind || value?.delegateKind || 'role').trim();
62
+ const capabilities = Array.isArray(value?.capabilities) ? value.capabilities : Array.isArray(delegate.capabilities) ? delegate.capabilities : [];
63
+ const selectionState = String(value?.selection?.state || value?.selectionState || '').trim().toLowerCase();
64
+ const forwardSelected = value?.selection?.forwardSelected === true || value?.forwardSelected === true || ['forward-selected', 'explicit-forward-selected'].includes(selectionState);
65
+ if (!label || !capabilities.length || !forwardSelected) return unresolvedProjection(
66
+ 'delegate-capability-authority-incomplete',
67
+ 'The upstream delegate/capability projection is marked qualified but does not expose one explicit forward-selected delegate label plus at least one capability.'
68
+ );
69
+ return Object.freeze({
70
+ state: 'explicit-qualified-forward-selection',
71
+ delegate: Object.freeze({ label, kind }),
72
+ capabilities: Object.freeze(capabilities.slice(0, MAX_CAPABILITIES).map((item) => freezeValue(item))),
73
+ sourceArtifact: Object.freeze(base.sourceArtifact),
74
+ facts: Object.freeze(projectFacts(value)),
75
+ provenance: Object.freeze({
76
+ basis: 'exact-upstream-qualified-forward-selected-delegate-capability-projection',
77
+ sourceArtifact: Object.freeze(base.sourceArtifact),
78
+ upstreamProvenance: value?.provenance ? Object.freeze({ ...(value.provenance || {}) }) : null,
79
+ boundary: 'Delegate relevance/capability is passed through from explicit upstream authority. Core does not select a Role from cache or participant inventory.'
80
+ }),
81
+ unresolved: Object.freeze([]),
82
+ boundary: 'Forward selection is semantic input, not a Role-discovery result.'
83
+ });
84
+ }
85
+
86
+ export function projectDelegationTargetAuthority(value = null) {
87
+ const base = qualifyExplicitProjection(value);
88
+ if (!base.qualified) return unresolvedProjection('delegation-target-authority-not-established', 'No exact upstream-qualified delegation target projection is present.');
89
+ const target = value?.target || value?.placement || {};
90
+ const workspaceId = String(target.workspaceId || value?.workspaceId || '').trim();
91
+ const repository = String(target.repository || value?.repository || '').trim();
92
+ const taskDirectory = normalizeDirectory(target.taskDirectory || value?.taskDirectory || '');
93
+ const handoffDirectory = normalizeDirectory(target.handoffDirectory || value?.handoffDirectory || '');
94
+ if (!workspaceId || !repository || !taskDirectory || !handoffDirectory) return unresolvedProjection(
95
+ 'delegation-target-authority-incomplete',
96
+ 'The upstream delegation target projection is marked qualified but does not expose repository, workspaceId, taskDirectory and handoffDirectory.'
97
+ );
98
+ return Object.freeze({
99
+ state: 'explicit-qualified-target-authority',
100
+ target: Object.freeze({ workspaceId, repository, taskDirectory, handoffDirectory, rootPath: String(target.rootPath || value?.rootPath || '').trim() }),
101
+ sourceArtifact: Object.freeze(base.sourceArtifact),
102
+ facts: Object.freeze(projectFacts(value)),
103
+ provenance: Object.freeze({
104
+ basis: 'exact-upstream-qualified-delegation-target-projection',
105
+ sourceArtifact: Object.freeze(base.sourceArtifact),
106
+ upstreamProvenance: value?.provenance ? Object.freeze({ ...(value.provenance || {}) }) : null,
107
+ boundary: 'Repository/Workspace identity and repo-local Task/Handoff placement are passed through from upstream authority; Core does not discover or choose a repository.'
108
+ }),
109
+ unresolved: Object.freeze([]),
110
+ boundary: 'Target placement is explicit authority input only; source mutation permission is separate.'
111
+ });
112
+ }
113
+
114
+ export function projectDelegationReturnReconciliationExpectation(value = null) {
115
+ const base = qualifyExplicitProjection(value);
116
+ if (!base.qualified) return unresolvedProjection('delegation-return-reconciliation-expectation-not-established', 'No exact upstream-qualified return/reconciliation projection is present.');
117
+ const completion = value?.completionExpectation || value?.returnExpectation || {};
118
+ const signalKind = String(completion.signalKind || '').trim();
119
+ const signalMeaning = String(completion.signalMeaning || '').trim();
120
+ const returnTo = String(completion.returnTo || '').trim();
121
+ const reconciliation = normalizeReconciliation(value?.reconciliation || value?.reconciliationExpectation || null);
122
+ if (!signalKind || !signalMeaning || !returnTo || !reconciliation.state) return unresolvedProjection(
123
+ 'delegation-return-reconciliation-expectation-incomplete',
124
+ 'The upstream return/reconciliation projection is marked qualified but does not expose a complete Completion Expectation and an explicit reconciliation state/expectation.'
125
+ );
126
+ return Object.freeze({
127
+ state: 'explicit-qualified-return-reconciliation',
128
+ completionExpectation: Object.freeze({ signalKind, signalMeaning, returnTo }),
129
+ reconciliation,
130
+ sourceArtifact: Object.freeze(base.sourceArtifact),
131
+ facts: Object.freeze(projectFacts(value)),
132
+ provenance: Object.freeze({
133
+ basis: 'exact-upstream-qualified-return-reconciliation-projection',
134
+ sourceArtifact: Object.freeze(base.sourceArtifact),
135
+ upstreamProvenance: value?.provenance ? Object.freeze({ ...(value.provenance || {}) }) : null,
136
+ boundary: 'Return and reconciliation responsibility are passed through exactly; Core does not invent acceptance, completion or merge semantics.'
137
+ }),
138
+ unresolved: Object.freeze([]),
139
+ boundary: 'Completion and reconciliation expectations are semantic-owner inputs; carrier manufacture remains a separate mechanical operation.'
140
+ });
141
+ }
142
+
143
+ function projectNextOperations({ delegateCapabilityAuthority, targetAuthority, returnReconciliationExpectation }) {
144
+ const target = targetAuthority.target;
145
+ const delegate = delegateCapabilityAuthority.delegate;
146
+ return Object.freeze([
147
+ Object.freeze({
148
+ kind: 'author-delegation-task',
149
+ command: 'author',
150
+ schemaId: 'tiinex.task.v1',
151
+ workspaceId: target.workspaceId,
152
+ repository: target.repository,
153
+ directory: target.taskDirectory,
154
+ bodyAuthority: 'caller/upstream-authored-work-semantics-required',
155
+ boundary: 'Mechanical authoring coordinate only. Core does not generate the Task objective, Done Criteria, scope or work plan.'
156
+ }),
157
+ Object.freeze({
158
+ kind: 'author-delegation-handoff',
159
+ command: 'author',
160
+ schemaId: 'tiinex.handoff.v1',
161
+ workspaceId: target.workspaceId,
162
+ repository: target.repository,
163
+ directory: target.handoffDirectory,
164
+ parent: 'newly-authored-qualified-task',
165
+ recipient: Object.freeze({ ...delegate }),
166
+ completionExpectation: Object.freeze({ ...(returnReconciliationExpectation.completionExpectation || {}) }),
167
+ boundary: 'Author the Handoff through normal Tooling with the qualified Task as Parent and the upstream-selected delegate/return semantics; Core does not synthesize transfer semantics.'
168
+ }),
169
+ Object.freeze({
170
+ kind: 'manufacture-delegation-carrier',
171
+ command: 'handoff',
172
+ workspaceId: target.workspaceId,
173
+ recipient: Object.freeze({ ...delegate }),
174
+ carrierAllocation: 'machine-derived-from-qualified-parent-pointer-topology',
175
+ reconciliation: returnReconciliationExpectation.reconciliation,
176
+ boundary: 'Manufacture only after the Task and Handoff qualify. Carrier topology is transport-only and does not create semantic delegation authority.'
177
+ })
178
+ ]);
179
+ }
180
+
181
+ function qualifyExplicitProjection(value = null) {
182
+ if (!value || typeof value !== 'object' || value.explicit !== true) return { qualified: false, sourceArtifact: emptySourceArtifact() };
183
+ if (String(value.qualification || value.state || '').trim().toLowerCase() !== 'qualified') return { qualified: false, sourceArtifact: emptySourceArtifact() };
184
+ const sourceArtifact = projectSourceArtifact(value);
185
+ if (!sourceArtifact.path || !/^[0-9a-f]{64}$/i.test(sourceArtifact.sha256)) return { qualified: false, sourceArtifact };
186
+ return { qualified: true, sourceArtifact };
187
+ }
188
+
189
+ function projectSourceArtifact(value = {}) {
190
+ const source = value.sourceArtifact || value.provenance?.sourceArtifact || {};
191
+ return Object.freeze({
192
+ workspaceId: String(source.workspaceId || source.workspace || '').trim(),
193
+ path: String(source.path || source.workspaceRelativePath || value.provenance?.sourceArtifactPath || '').trim(),
194
+ sha256: String(source.sha256 || value.provenance?.sourceArtifactSha256 || '').trim().toLowerCase(),
195
+ schemaId: String(source.schemaId || '').trim()
196
+ });
197
+ }
198
+
199
+ function unresolvedProjection(code, detail) {
200
+ return Object.freeze({
201
+ state: 'not-established',
202
+ facts: Object.freeze([]),
203
+ sourceArtifact: Object.freeze(emptySourceArtifact()),
204
+ unresolved: Object.freeze([Object.freeze({ code, detail })]),
205
+ boundary: 'No semantic meaning is inferred from Role/cache inventory, Handoff endpoints, filenames, repository adjacency or transport placement.'
206
+ });
207
+ }
208
+
209
+ function blocker(code, detail, request) {
210
+ return Object.freeze({
211
+ code,
212
+ detail: String(detail || ''),
213
+ request: `${String(request || '')} Do not fall back to plain-chat delegation, repository scanning, network discovery, or selecting a Role merely because it is carried.`
214
+ });
215
+ }
216
+
217
+ function projectFacts(value = {}) {
218
+ const facts = Array.isArray(value.facts) ? value.facts : Array.isArray(value.items) ? value.items : [];
219
+ return facts.slice(0, MAX_FACTS).map((item) => freezeValue(item));
220
+ }
221
+
222
+ function freezeValue(value) {
223
+ if (value && typeof value === 'object' && !Array.isArray(value)) return Object.freeze({ ...value });
224
+ if (Array.isArray(value)) return Object.freeze([...value]);
225
+ return value;
226
+ }
227
+
228
+ function normalizeDirectory(value = '') {
229
+ return String(value || '').replace(/\\/g, '/').replace(/^\/+/, '').replace(/\/+$/, '').trim();
230
+ }
231
+
232
+ function normalizeReconciliation(value = null) {
233
+ if (typeof value === 'string') return Object.freeze({ state: String(value || '').trim(), expectation: '' });
234
+ if (!value || typeof value !== 'object') return Object.freeze({ state: '', expectation: '' });
235
+ return Object.freeze({
236
+ state: String(value.state || value.disposition || '').trim(),
237
+ expectation: String(value.expectation || value.description || '').trim()
238
+ });
239
+ }
240
+
241
+ function emptySourceArtifact() { return { workspaceId: '', path: '', sha256: '', schemaId: '' }; }
@@ -0,0 +1,125 @@
1
+ import { deepFreeze, normalizeToken } from '../handoff/coldStartQualification.shared.js';
2
+
3
+ export const HOLDER_ASSIGNMENT_MODE = deepFreeze({
4
+ EXPLICIT_SESSION: 'explicit-session',
5
+ EXPLICIT_USER_SESSION: 'explicit-user-session',
6
+ EXPLICIT_ROLE_INVOCATION: 'explicit-role-invocation',
7
+ HANDOFF: 'handoff',
8
+ EXPLICIT_PARTICIPATION: 'explicit-participation'
9
+ });
10
+
11
+ const KNOWN_MODES = new Set(Object.values(HOLDER_ASSIGNMENT_MODE));
12
+
13
+ export function projectHolderAssignmentModeAuthority(role = {}) {
14
+ const endpointKind = normalizeToken(role?.endpoint?.kind || '');
15
+ if (endpointKind !== 'role') return deepFreeze({
16
+ state: 'not-applicable',
17
+ modes: deepFreeze([]),
18
+ holderState: '',
19
+ source: 'none',
20
+ reasonCode: 'recipient-not-role',
21
+ unknownModes: deepFreeze([]),
22
+ provenance: baseProvenance(role, { basis: 'recipient-not-role', field: 'Assignment Modes' }),
23
+ boundary: 'Holder assignment-mode authority applies only to a selected Role recipient.'
24
+ });
25
+
26
+ const material = role?.material?.artifact || null;
27
+ const relationship = role?.holderRelationshipLoaded || {};
28
+ const holderState = String(relationship.holderState || '').trim();
29
+ const qualifiedMaterial = String(role?.state || '') === 'qualified'
30
+ && String(role?.material?.state || '') === 'qualified'
31
+ && Boolean(material?.path)
32
+ && /^[0-9a-f]{64}$/i.test(String(material?.sha256 || ''));
33
+ if (!qualifiedMaterial) return unresolved(role, holderState, 'qualified-role-holder-authority-not-established', 'none', {
34
+ basis: 'exact-qualified-role-assignment-mode-authority-not-established', field: 'Assignment Modes'
35
+ });
36
+
37
+ const structured = parseStructuredModes(relationship.assignmentModes);
38
+ if (!structured.present) return unresolved(role, holderState, 'holder-assignment-mode-authority-missing', 'qualified-recipient-role-material', {
39
+ basis: 'canonical-assignment-modes-missing', field: 'Assignment Modes'
40
+ });
41
+ if (structured.unknown.length) return unresolved(role, holderState, 'holder-assignment-mode-authority-unknown-token', 'qualified-recipient-role-structured-modes', {
42
+ basis: 'exact-qualified-role-assignment-modes', field: 'Assignment Modes', exactValue: structured.raw, unknownModes: structured.unknown
43
+ });
44
+ if (!structured.modes.length) return unresolved(role, holderState, 'holder-assignment-mode-authority-empty', 'qualified-recipient-role-structured-modes', {
45
+ basis: 'exact-qualified-role-assignment-modes', field: 'Assignment Modes', exactValue: structured.raw
46
+ });
47
+ return deepFreeze({
48
+ state: 'qualified',
49
+ modes: deepFreeze(structured.modes),
50
+ holderState,
51
+ source: 'qualified-recipient-role-structured-modes',
52
+ reasonCode: 'holder-assignment-mode-authority-qualified',
53
+ unknownModes: deepFreeze([]),
54
+ provenance: baseProvenance(role, {
55
+ basis: 'exact-qualified-role-assignment-modes',
56
+ field: 'Assignment Modes',
57
+ exactValue: structured.raw,
58
+ boundary: 'Positive mode authority comes only from the exact structured Assignment Modes field on the qualified current Role. Holder State is diagnostic-only; historical compatibility material does not authorize current holder binding.'
59
+ }),
60
+ boundary: 'Exact structured canonical assignment modes authorize only their named bounded mechanisms; they do not establish a holder, durable identity, participation, delegation, process, source, or acceptance authority.'
61
+ });
62
+ }
63
+
64
+ export function isCanonicalHolderAssignmentMode(value = '') {
65
+ return KNOWN_MODES.has(String(value || '').trim());
66
+ }
67
+
68
+ function parseStructuredModes(value) {
69
+ if (Array.isArray(value)) {
70
+ const raw = value.map((item) => String(item || '').trim()).filter(Boolean);
71
+ const tokens = raw.map(stripCode).filter(Boolean);
72
+ return classifyStructured(tokens, raw.join(', '), true);
73
+ }
74
+ const raw = String(value || '').trim();
75
+ if (!raw) return { present: false, raw: '', modes: [], unknown: [] };
76
+ const tokens = raw.split(',').map((item) => stripCode(item.trim())).filter(Boolean);
77
+ return classifyStructured(tokens, raw, true);
78
+ }
79
+
80
+ function classifyStructured(tokens, raw, present) {
81
+ const modes = [];
82
+ const unknown = [];
83
+ for (const token of tokens) {
84
+ if (KNOWN_MODES.has(token)) {
85
+ if (!modes.includes(token)) modes.push(token);
86
+ } else if (!unknown.includes(token)) unknown.push(token);
87
+ }
88
+ return { present, raw, modes, unknown };
89
+ }
90
+
91
+ function stripCode(value) {
92
+ const text = String(value || '').trim();
93
+ return /^`[^`]+`$/.test(text) ? text.slice(1, -1).trim() : text;
94
+ }
95
+
96
+ function unresolved(role, holderState, reasonCode, source, details = {}) {
97
+ return deepFreeze({
98
+ state: 'unresolved',
99
+ modes: deepFreeze([]),
100
+ holderState,
101
+ source,
102
+ reasonCode,
103
+ unknownModes: deepFreeze([...(details.unknownModes || [])]),
104
+ provenance: baseProvenance(role, details),
105
+ boundary: 'Positive holder assignment-mode authorization is unresolved. Core does not infer canonical modes from Holder State prose, historical Role compatibility, endpoint labels, package placement, session assertions, filenames, or lexical similarity.'
106
+ });
107
+ }
108
+
109
+ function baseProvenance(role = {}, details = {}) {
110
+ const material = role?.material?.artifact || {};
111
+ return deepFreeze({
112
+ basis: String(details.basis || ''),
113
+ roleArtifactPath: String(material.path || ''),
114
+ roleArtifactSha256: String(material.sha256 || ''),
115
+ roleSchemaId: String(material.schemaId || ''),
116
+ roleLabel: String(material.roleLabel || role?.endpoint?.label || ''),
117
+ section: 'Holder Relationship',
118
+ field: String(details.field || 'Assignment Modes'),
119
+ exactValue: String(details.exactValue || ''),
120
+ exactRoleSourcePath: '',
121
+ exactRoleSha256: '',
122
+ decisionArtifact: null,
123
+ boundary: String(details.boundary || 'Only exact structured Assignment Modes on exact qualified current Role material may establish canonical assignment modes. Holder State and historical compatibility material remain non-authoritative for positive authorization.')
124
+ });
125
+ }
@@ -0,0 +1,80 @@
1
+ import { deepFreeze, normalizeToken } from '../handoff/coldStartQualification.shared.js';
2
+ import {
3
+ HOLDER_ASSIGNMENT_MODE,
4
+ isCanonicalHolderAssignmentMode,
5
+ projectHolderAssignmentModeAuthority
6
+ } from './grounding.holderAssignmentModes.js';
7
+
8
+ export function projectHolderBindingAuthorization(role = {}, options = {}) {
9
+ const endpointKind = normalizeToken(role?.endpoint?.kind || '');
10
+ const requestedMode = String(options.assertionMode || options.assignmentMode || HOLDER_ASSIGNMENT_MODE.EXPLICIT_SESSION).trim();
11
+ if (endpointKind !== 'role') return deepFreeze({
12
+ state: 'not-applicable',
13
+ assignmentMode: '',
14
+ authorizedModes: deepFreeze([]),
15
+ holderState: '',
16
+ source: 'none',
17
+ reasonCode: 'recipient-not-role',
18
+ modeAuthority: projectHolderAssignmentModeAuthority(role),
19
+ provenance: {
20
+ basis: 'recipient-not-role', roleArtifactPath: '', roleArtifactSha256: '', section: 'Holder Relationship', field: 'Assignment Modes', exactValue: '', assertionMode: '', boundary: 'Holder-assignment authorization is only applicable when the selected Handoff recipient is a Role endpoint.'
21
+ },
22
+ boundary: 'No Role assignment authorization is required for a non-Role recipient.'
23
+ });
24
+
25
+ const modeAuthority = projectHolderAssignmentModeAuthority(role);
26
+ const holderState = String(modeAuthority.holderState || role?.holderRelationshipLoaded?.holderState || '').trim();
27
+ const provenance = deepFreeze({
28
+ ...(modeAuthority.provenance || {}),
29
+ assertionMode: requestedMode,
30
+ boundary: 'The bounded binding result compares one explicit assertion mechanism to exact qualified canonical assignment-mode authority. Holder State prose remains diagnostic-only.'
31
+ });
32
+
33
+ if (modeAuthority.state !== 'qualified') return deepFreeze({
34
+ state: 'unresolved',
35
+ assignmentMode: requestedMode,
36
+ authorizedModes: deepFreeze([]),
37
+ holderState,
38
+ source: modeAuthority.source || 'none',
39
+ reasonCode: modeAuthority.reasonCode || 'holder-assignment-mode-authority-unresolved',
40
+ modeAuthority,
41
+ provenance,
42
+ boundary: 'A matching Role assertion remains unauthorized until exact qualified canonical assignment-mode authority is established.'
43
+ });
44
+
45
+ if (!isCanonicalHolderAssignmentMode(requestedMode)) return deepFreeze({
46
+ state: 'unresolved',
47
+ assignmentMode: requestedMode,
48
+ authorizedModes: deepFreeze([...(modeAuthority.modes || [])]),
49
+ holderState,
50
+ source: modeAuthority.source,
51
+ reasonCode: 'holder-binding-assertion-mode-unqualified',
52
+ modeAuthority,
53
+ provenance,
54
+ boundary: 'The asserted binding mechanism is not a canonical mode established by semantic authority. Core does not reinterpret arbitrary assertion labels.'
55
+ });
56
+
57
+ if (!(modeAuthority.modes || []).includes(requestedMode)) return deepFreeze({
58
+ state: 'unresolved',
59
+ assignmentMode: requestedMode,
60
+ authorizedModes: deepFreeze([...(modeAuthority.modes || [])]),
61
+ holderState,
62
+ source: modeAuthority.source,
63
+ reasonCode: 'holder-assignment-mode-not-authorized',
64
+ modeAuthority,
65
+ provenance,
66
+ boundary: 'The exact qualified canonical mode set does not authorize the asserted bounded binding mechanism. No widening between session, user-session, invocation, Handoff, or participation modes is permitted.'
67
+ });
68
+
69
+ return deepFreeze({
70
+ state: 'qualified',
71
+ assignmentMode: requestedMode,
72
+ authorizedModes: deepFreeze([...(modeAuthority.modes || [])]),
73
+ holderState,
74
+ source: modeAuthority.source,
75
+ reasonCode: 'holder-assignment-mode-authorized',
76
+ modeAuthority,
77
+ provenance,
78
+ boundary: 'Exact qualified canonical assignment-mode authority authorizes only this bounded assertion mechanism; it does not establish durable holder identity or broader participant/process/delegation/source/acceptance authority.'
79
+ });
80
+ }
@@ -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(/^\/+/, ''); }
@@ -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,
@@ -38,16 +38,31 @@ export function projectGroundingAuthority(authority, mode) {
38
38
  role: authority.role ? Object.freeze({ state: authority.role.state || '', label: authority.role.endpoint?.label || '', kind: authority.role.endpoint?.kind || '' }) : null,
39
39
  holderBinding: authority.holderBinding ? Object.freeze({
40
40
  state: authority.holderBinding.state || '',
41
+ bindingPresent: String(authority.holderBinding.state || '') === 'qualified',
42
+ declarationPresent: Boolean(authority.holderBinding.explicit),
41
43
  holderId: authority.holderBinding.holderId || '',
42
44
  roleLabel: authority.holderBinding.roleLabel || '',
43
45
  recipientRoleLabel: authority.holderBinding.recipientRoleLabel || '',
44
46
  recipientCompatibility: authority.holderBinding.recipientCompatibility || '',
45
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',
46
55
  explicit: Boolean(authority.holderBinding.explicit),
47
56
  inferredFromTransport: Boolean(authority.holderBinding.inferredFromTransport),
48
57
  provenance: Object.freeze({
49
58
  basis: authority.holderBinding.explicit ? 'explicit-consuming-session-holder-binding' : 'unresolved-or-non-explicit-holder-binding',
50
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 || '',
51
66
  boundary: authority.holderBinding.boundary || 'Consuming-session holder identity is never inferred from route transport or recipient position.'
52
67
  }),
53
68
  boundary: authority.holderBinding.boundary || ''