codex-workflow-v2 2.0.0-beta.13.8 → 2.0.0-beta.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -388
- package/dist/reviewer-runtime-build.json +96 -32
- package/dist/src/alpha6/adoption.d.ts +2 -0
- package/dist/src/alpha6/adoption.js +22 -0
- package/dist/src/alpha6/adoption.js.map +1 -1
- package/dist/src/alpha6/captured-check-evidence.d.ts +51 -0
- package/dist/src/alpha6/captured-check-evidence.js +152 -0
- package/dist/src/alpha6/captured-check-evidence.js.map +1 -0
- package/dist/src/alpha6/component-owner.d.ts +15 -1
- package/dist/src/alpha6/component-owner.js +44 -2
- package/dist/src/alpha6/component-owner.js.map +1 -1
- package/dist/src/alpha6/corrective-decision-boundary.d.ts +4 -0
- package/dist/src/alpha6/corrective-decision-boundary.js +47 -0
- package/dist/src/alpha6/corrective-decision-boundary.js.map +1 -0
- package/dist/src/alpha6/downstream-proof.d.ts +1 -25
- package/dist/src/alpha6/downstream-proof.js +0 -171
- package/dist/src/alpha6/downstream-proof.js.map +1 -1
- package/dist/src/alpha6/failed-step-planning-recovery.d.ts +10 -0
- package/dist/src/alpha6/failed-step-planning-recovery.js +93 -0
- package/dist/src/alpha6/failed-step-planning-recovery.js.map +1 -0
- package/dist/src/alpha6/literal-test-invocation.d.ts +2 -0
- package/dist/src/alpha6/literal-test-invocation.js +106 -0
- package/dist/src/alpha6/literal-test-invocation.js.map +1 -0
- package/dist/src/alpha6/milestone.d.ts +2 -0
- package/dist/src/alpha6/milestone.js +10 -1
- package/dist/src/alpha6/milestone.js.map +1 -1
- package/dist/src/alpha6/navigation-dirty-carryover.d.ts +11 -0
- package/dist/src/alpha6/navigation-dirty-carryover.js +130 -0
- package/dist/src/alpha6/navigation-dirty-carryover.js.map +1 -0
- package/dist/src/alpha6/plan-integrity.js +7 -5
- package/dist/src/alpha6/plan-integrity.js.map +1 -1
- package/dist/src/alpha6/plan-risk.d.ts +2 -0
- package/dist/src/alpha6/plan-risk.js +10 -3
- package/dist/src/alpha6/plan-risk.js.map +1 -1
- package/dist/src/alpha6/remediation.d.ts +6 -21
- package/dist/src/alpha6/remediation.js +161 -476
- package/dist/src/alpha6/remediation.js.map +1 -1
- package/dist/src/alpha6/root-cause-replan-carryover.d.ts +4 -1
- package/dist/src/alpha6/root-cause-replan-carryover.js +29 -5
- package/dist/src/alpha6/root-cause-replan-carryover.js.map +1 -1
- package/dist/src/beta1/project-transaction.d.ts +3 -1
- package/dist/src/beta1/project-transaction.js +6 -2
- package/dist/src/beta1/project-transaction.js.map +1 -1
- package/dist/src/checks/runner.d.ts +26 -0
- package/dist/src/checks/runner.js +223 -0
- package/dist/src/checks/runner.js.map +1 -0
- package/dist/src/checks/task-sync.d.ts +10 -0
- package/dist/src/checks/task-sync.js +41 -0
- package/dist/src/checks/task-sync.js.map +1 -0
- package/dist/src/checks/worker.d.ts +1 -0
- package/dist/src/checks/worker.js +154 -0
- package/dist/src/checks/worker.js.map +1 -0
- package/dist/src/cli-actions.d.ts +2 -2
- package/dist/src/cli-actions.js +3 -15
- package/dist/src/cli-actions.js.map +1 -1
- package/dist/src/cli.js +14 -98
- package/dist/src/cli.js.map +1 -1
- package/dist/src/contracts.d.ts +35 -32
- package/dist/src/dependency-provenance.d.ts +2 -2
- package/dist/src/dependency-provenance.js +12 -69
- package/dist/src/dependency-provenance.js.map +1 -1
- package/dist/src/domain/base-sync-conflict.d.ts +13 -0
- package/dist/src/domain/base-sync-conflict.js +32 -0
- package/dist/src/domain/base-sync-conflict.js.map +1 -0
- package/dist/src/domain/step-start-admission.d.ts +4 -0
- package/dist/src/domain/step-start-admission.js +9 -0
- package/dist/src/domain/step-start-admission.js.map +1 -0
- package/dist/src/domain/virgin-registration.d.ts +3 -0
- package/dist/src/domain/virgin-registration.js +65 -0
- package/dist/src/domain/virgin-registration.js.map +1 -0
- package/dist/src/errors.d.ts +1 -1
- package/dist/src/errors.js.map +1 -1
- package/dist/src/gateway-handshake.js +0 -8
- package/dist/src/gateway-handshake.js.map +1 -1
- package/dist/src/git.d.ts +3 -1
- package/dist/src/git.js +41 -14
- package/dist/src/git.js.map +1 -1
- package/dist/src/graph.js +25 -3
- package/dist/src/graph.js.map +1 -1
- package/dist/src/index.d.ts +1 -0
- package/dist/src/lifecycle/corrective-replan.js +3 -3
- package/dist/src/lifecycle/corrective-replan.js.map +1 -1
- package/dist/src/navigation-actions.d.ts +9 -0
- package/dist/src/navigation-actions.js +72 -0
- package/dist/src/navigation-actions.js.map +1 -0
- package/dist/src/navigation-update-artifact.d.ts +5 -0
- package/dist/src/navigation-update-artifact.js +227 -0
- package/dist/src/navigation-update-artifact.js.map +1 -0
- package/dist/src/navigation-update.d.ts +39 -0
- package/dist/src/navigation-update.js +82 -0
- package/dist/src/navigation-update.js.map +1 -0
- package/dist/src/observation.js +52 -29
- package/dist/src/observation.js.map +1 -1
- package/dist/src/observed-routes.js +5 -6
- package/dist/src/observed-routes.js.map +1 -1
- package/dist/src/pending-review-update.d.ts +0 -13
- package/dist/src/pending-review-update.js +1 -6
- package/dist/src/pending-review-update.js.map +1 -1
- package/dist/src/reviewer.d.ts +1 -1
- package/dist/src/reviewer.js +20 -17
- package/dist/src/reviewer.js.map +1 -1
- package/dist/src/runtime.d.ts +3 -0
- package/dist/src/runtime.js +6 -0
- package/dist/src/runtime.js.map +1 -0
- package/dist/src/state/corrective-replan-executor.d.ts +10 -0
- package/dist/src/state/corrective-replan-executor.js +37 -1
- package/dist/src/state/corrective-replan-executor.js.map +1 -1
- package/dist/src/state/corrective-replan-public-schema.js +15 -2
- package/dist/src/state/corrective-replan-public-schema.js.map +1 -1
- package/dist/src/state/corrective-replan-public.js +6 -5
- package/dist/src/state/corrective-replan-public.js.map +1 -1
- package/dist/src/state/corrective-replan-transaction.d.ts +1 -0
- package/dist/src/state/corrective-replan-transaction.js +12 -11
- package/dist/src/state/corrective-replan-transaction.js.map +1 -1
- package/dist/src/state/corrective-yield-executor.js +2 -2
- package/dist/src/state/corrective-yield-executor.js.map +1 -1
- package/dist/src/state/corrective-yield-transaction.d.ts +1 -0
- package/dist/src/state/corrective-yield-transaction.js +11 -10
- package/dist/src/state/corrective-yield-transaction.js.map +1 -1
- package/dist/src/state/lock.d.ts +4 -0
- package/dist/src/state/lock.js +21 -0
- package/dist/src/state/lock.js.map +1 -1
- package/dist/src/version.d.ts +1 -1
- package/dist/src/version.js +1 -1
- package/dist/src/version.js.map +1 -1
- package/dist/src/workflow-blocker-route.d.ts +8 -0
- package/dist/src/workflow-blocker-route.js +106 -0
- package/dist/src/workflow-blocker-route.js.map +1 -0
- package/dist/src/workflow.d.ts +48 -63
- package/dist/src/workflow.js +698 -1470
- package/dist/src/workflow.js.map +1 -1
- package/docs/autonomy-guardrails.md +26 -304
- package/docs/decisions.md +14 -112
- package/docs/development-flow.md +35 -238
- package/docs/project-memory.md +31 -50
- package/docs/release-app-evidence.md +190 -0
- package/docs/release.md +95 -363
- package/docs/updating-existing-project.md +19 -717
- package/package.json +11 -13
- package/plugins/codex-workflow-gateway/.codex-plugin/plugin.json +2 -2
- package/plugins/codex-workflow-gateway/references/chat-dispatch.md +73 -197
- package/plugins/codex-workflow-gateway/references/codebase-memory-routing.md +57 -0
- package/plugins/codex-workflow-gateway/references/protocol.md +42 -445
- package/plugins/codex-workflow-gateway/scripts/chat-dispatch.mjs +7 -1
- package/plugins/codex-workflow-gateway/scripts/chat-model-policy.mjs +10 -8
- package/plugins/codex-workflow-gateway/scripts/chat-registry.mjs +23 -5
- package/plugins/codex-workflow-gateway/skills/codex-workflow-gateway/SKILL.md +66 -740
- package/references/state-machine.md +4 -4
- package/roles/technical-planner.md +1 -1
- package/schemas/corrective-decision-event.schema.json +3 -1
- package/schemas/project-knowledge-map.schema.json +3 -1
- package/schemas/remediation-event.schema.json +10 -1
- package/schemas/task.schema.json +46 -2
- package/schemas/transition-payloads.schema.json +16 -1
- package/src/alpha6/adoption.ts +1123 -0
- package/src/alpha6/captured-check-evidence.ts +132 -0
- package/src/alpha6/check-support-anchor.ts +128 -0
- package/src/alpha6/component-owner.ts +168 -0
- package/src/alpha6/corrective-decision-boundary.ts +39 -0
- package/src/alpha6/downstream-proof.ts +520 -0
- package/src/alpha6/failed-step-planning-recovery.ts +88 -0
- package/src/alpha6/handoff.ts +1443 -0
- package/src/alpha6/journal.ts +473 -0
- package/src/alpha6/literal-test-invocation.ts +84 -0
- package/src/alpha6/mechanical-feasibility.ts +488 -0
- package/src/alpha6/milestone.ts +2192 -0
- package/src/alpha6/navigation-dirty-carryover.ts +154 -0
- package/src/alpha6/npm-check-contract.ts +47 -0
- package/src/alpha6/plan-integrity.ts +298 -0
- package/src/alpha6/plan-risk.ts +1480 -0
- package/src/alpha6/preexecution-replan.ts +187 -0
- package/src/alpha6/remediation-cause.ts +98 -0
- package/src/alpha6/remediation.ts +2438 -0
- package/src/alpha6/review.ts +1198 -0
- package/src/alpha6/root-cause-replan-carryover.ts +491 -0
- package/src/alpha6/store-sidecars.ts +335 -0
- package/src/alpha7/autonomy.ts +411 -0
- package/src/alpha7/corrective-recovery.ts +1332 -0
- package/src/artifacts.ts +130 -0
- package/src/beta1/project-transaction.ts +355 -0
- package/src/change-explanation.ts +153 -0
- package/src/checks/runner.ts +245 -0
- package/src/checks/task-sync.ts +41 -0
- package/src/checks/worker.ts +149 -0
- package/src/cli-actions.ts +107 -0
- package/src/cli.ts +1457 -0
- package/src/contracts.ts +1494 -0
- package/src/credential-output.ts +89 -0
- package/src/credential-transport.ts +215 -0
- package/src/delegation.ts +190 -0
- package/src/dependency-provenance.ts +472 -0
- package/src/diagnostics.ts +93 -0
- package/src/domain/base-sync-conflict.ts +35 -0
- package/src/domain/completed-step-carryover.ts +76 -0
- package/src/domain/discovery.ts +27 -0
- package/src/domain/plan-semantics.ts +58 -0
- package/src/domain/step-start-admission.ts +10 -0
- package/src/domain/validation.ts +177 -0
- package/src/domain/virgin-registration.ts +46 -0
- package/src/errors.ts +24 -0
- package/src/fs-utils.ts +61 -0
- package/src/gateway-handshake.ts +95 -0
- package/src/git.ts +183 -0
- package/src/graph.ts +342 -0
- package/src/historical-step-provenance.ts +136 -0
- package/src/index.ts +23 -0
- package/src/lifecycle/canonical-hash.ts +28 -0
- package/src/lifecycle/catalog.ts +202 -0
- package/src/lifecycle/compiler-inspection.ts +29 -0
- package/src/lifecycle/core-static-readiness.ts +132 -0
- package/src/lifecycle/corrective-replan-authority.ts +136 -0
- package/src/lifecycle/corrective-replan-binding-manifest.ts +51 -0
- package/src/lifecycle/corrective-replan-credential-core.ts +408 -0
- package/src/lifecycle/corrective-replan-credential-schema.ts +54 -0
- package/src/lifecycle/corrective-replan-credentials.ts +48 -0
- package/src/lifecycle/corrective-replan.ts +843 -0
- package/src/lifecycle/evaluator.ts +48 -0
- package/src/lifecycle/fingerprint.ts +488 -0
- package/src/lifecycle/immutable.ts +8 -0
- package/src/lifecycle/implementation-table.ts +118 -0
- package/src/lifecycle/index.ts +8 -0
- package/src/lifecycle/schema-artifact.ts +263 -0
- package/src/lifecycle/semantic-registry.ts +572 -0
- package/src/lifecycle/types.ts +838 -0
- package/src/memory.ts +273 -0
- package/src/migration.ts +161 -0
- package/src/navigation-actions.ts +70 -0
- package/src/navigation-update-artifact.ts +198 -0
- package/src/navigation-update.ts +121 -0
- package/src/observation.ts +225 -0
- package/src/observed-routes.ts +660 -0
- package/src/operational-contract.ts +125 -0
- package/src/pending-review-update.ts +175 -0
- package/src/repository.ts +99 -0
- package/src/reviewer.ts +1879 -0
- package/src/runtime.ts +6 -0
- package/src/state/corrective-replan-executor.ts +818 -0
- package/src/state/corrective-replan-public-schema.ts +83 -0
- package/src/state/corrective-replan-public.ts +908 -0
- package/src/state/corrective-replan-transaction.ts +949 -0
- package/src/state/corrective-yield-executor.ts +327 -0
- package/src/state/corrective-yield-transaction.ts +730 -0
- package/src/state/lock.ts +902 -0
- package/src/state/store.ts +567 -0
- package/src/transition-core.ts +330 -0
- package/src/ulid.ts +24 -0
- package/src/version.ts +2 -0
- package/src/workflow-blocker-route.ts +109 -0
- package/src/workflow.ts +10172 -0
- package/docs/alpha7.1-implementation-brief.md +0 -268
- package/docs/alpha7.2-corrective-context-refresh-brief.md +0 -484
- package/docs/alpha7.2.1-remediation-recovery-brief.md +0 -86
- package/docs/beta1-stabilization-brief.md +0 -165
- package/docs/beta11-plan-integrity-recovery-brief.md +0 -38
- package/docs/beta13.2-signal-review-recovery.md +0 -38
- package/docs/beta2-initial-assembly-navigation-brief.md +0 -616
- package/docs/change-model.md +0 -118
- package/docs/delegated-approval.md +0 -254
- package/docs/lifecycle/state-machine-stabilization.md +0 -641
- package/docs/pdf/README.md +0 -24
- package/docs/pdf/codex-workflow-v2-architecture-ru.pdf +0 -0
- package/docs/pdf/codex-workflow-v2-chat-only-guide-ru.pdf +0 -0
- package/docs/pdf/codex-workflow-v2-technical-reference-ru.pdf +0 -0
- package/docs/pdf/requirements.txt +0 -1
- package/docs/pdf/sources/codex-workflow-v2-architecture-ru.md +0 -478
- package/docs/pdf/sources/codex-workflow-v2-chat-only-guide-ru.md +0 -508
- package/docs/pdf/sources/codex-workflow-v2-technical-reference-ru.md +0 -778
- package/docs/pending-review-update.md +0 -15
- package/docs/problem-briefs/01-pre-implementation-integrity.md +0 -482
- package/docs/problem-briefs/02-minimal-step-integrity.md +0 -411
- package/docs/problem-briefs/03-minimal-agent-context-integrity.md +0 -358
- package/docs/problem-briefs/04-task-dependency-and-structural-replacement-integrity.md +0 -573
- package/docs/problem-briefs/BRIEF-TEMPLATE.md +0 -56
- package/docs/problem-briefs/README.md +0 -120
- package/docs/problem-briefs/evidence/p01-mechanical-feasibility-corpus.md +0 -90
- package/docs/problem-briefs/evidence/signal-v4-pre-m3-replay.md +0 -246
- package/docs/split-required-recovery.md +0 -47
- package/docs/stable-release-defect-register.md +0 -730
- package/docs/validation-report.md +0 -182
- package/scripts/generate-pdf-docs.py +0 -524
- package/scripts/run-pdf-docs.mjs +0 -62
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { readFileSync } from 'node:fs';
|
|
3
|
+
|
|
4
|
+
import { Ajv2020 } from 'ajv/dist/2020.js';
|
|
5
|
+
|
|
6
|
+
import { hashCanonical } from './fingerprint.js';
|
|
7
|
+
import { deepFreeze } from './immutable.js';
|
|
8
|
+
import {
|
|
9
|
+
correctiveReplanCredentialSchemaArtifacts,
|
|
10
|
+
correctiveReplanCredentialSchemaValidators,
|
|
11
|
+
} from './corrective-replan-credential-schema.js';
|
|
12
|
+
import type {
|
|
13
|
+
SemanticRegistry,
|
|
14
|
+
PayloadSchemaArtifactBinding,
|
|
15
|
+
PayloadSchemaValidatorBinding,
|
|
16
|
+
TransitionSchemaArtifact,
|
|
17
|
+
VersionedRegistryEntry,
|
|
18
|
+
} from './types.js';
|
|
19
|
+
|
|
20
|
+
const schemaUrl = new URL('../../../schemas/transition-definition.schema.json', import.meta.url);
|
|
21
|
+
const schemaBytes = readFileSync(schemaUrl);
|
|
22
|
+
const schemaDocument = JSON.parse(schemaBytes.toString('utf8')) as object;
|
|
23
|
+
const vocabularyDocument = extractVocabulary(schemaDocument);
|
|
24
|
+
const ajv = new Ajv2020({ allErrors: true, strict: true, formats: { 'date-time': true } });
|
|
25
|
+
if (!ajv.validateSchema(schemaDocument)) {
|
|
26
|
+
throw new TypeError(`Transition definition schema artifact is invalid: ${ajv.errorsText(ajv.errors)}`);
|
|
27
|
+
}
|
|
28
|
+
const validateSchemaDocument = ajv.compile(schemaDocument);
|
|
29
|
+
const payloadSchemaUrl = new URL('../../../schemas/transition-payloads.schema.json', import.meta.url);
|
|
30
|
+
const payloadSchemaBytes = readFileSync(payloadSchemaUrl);
|
|
31
|
+
const payloadSchemaDocument = JSON.parse(payloadSchemaBytes.toString('utf8')) as {
|
|
32
|
+
readonly $id: string;
|
|
33
|
+
readonly $defs: Readonly<Record<string, unknown>>;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export const transitionDefinitionDocumentSha256 = createHash('sha256').update(schemaBytes).digest('hex');
|
|
37
|
+
export const transitionDefinitionVocabularySha256 = hashCanonical(vocabularyDocument);
|
|
38
|
+
|
|
39
|
+
const transitionDefinitionArtifact: PayloadSchemaArtifactBinding = {
|
|
40
|
+
id: 'schema.transition-definition',
|
|
41
|
+
version: 1,
|
|
42
|
+
implementationId: 'implementation.schema-artifact.transition-definition',
|
|
43
|
+
implementationVersion: 1,
|
|
44
|
+
documentSha256: transitionDefinitionDocumentSha256,
|
|
45
|
+
schemaPointer: '#',
|
|
46
|
+
subschemaSha256: hashCanonical(schemaDocument),
|
|
47
|
+
document: schemaDocument,
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const transitionDefinitionValidator: PayloadSchemaValidatorBinding = {
|
|
51
|
+
id: transitionDefinitionArtifact.id,
|
|
52
|
+
version: transitionDefinitionArtifact.version,
|
|
53
|
+
implementationId: 'implementation.schema-validator.ajv-draft-2020-12.transition-definition',
|
|
54
|
+
implementationVersion: 1,
|
|
55
|
+
artifactSha256: transitionDefinitionArtifact.documentSha256,
|
|
56
|
+
subschemaSha256: transitionDefinitionArtifact.subschemaSha256,
|
|
57
|
+
callable: (raw: unknown) => validateSchemaDocument(raw) === true,
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const payloadDefinitionBySchemaId = {
|
|
61
|
+
'schema.task-id': 'taskId',
|
|
62
|
+
'schema.expected-revision': 'expectedRevision',
|
|
63
|
+
'schema.task-plan-input': 'taskPlanInput',
|
|
64
|
+
'schema.plan-risk-audit-input': 'planRiskAuditInput',
|
|
65
|
+
'schema.corrective-replan-snapshot': 'correctiveReplanSnapshot',
|
|
66
|
+
'schema.corrective-replan-bindings': 'correctiveReplanBindings',
|
|
67
|
+
'schema.task-state-readback': 'taskStateReadback',
|
|
68
|
+
} as const;
|
|
69
|
+
|
|
70
|
+
export const transitionPayloadDocumentSha256 = createHash('sha256').update(payloadSchemaBytes).digest('hex');
|
|
71
|
+
|
|
72
|
+
const payloadArtifactRows = Object.entries(payloadDefinitionBySchemaId).map(([id, definitionName]) => ({
|
|
73
|
+
id, version: 1,
|
|
74
|
+
implementationId: `implementation.schema-artifact.transition-payloads.${definitionName}`,
|
|
75
|
+
implementationVersion: 1,
|
|
76
|
+
documentSha256: transitionPayloadDocumentSha256,
|
|
77
|
+
schemaPointer: `#/$defs/${definitionName}`,
|
|
78
|
+
subschemaSha256: hashCanonical(payloadSchemaDocument.$defs[definitionName]),
|
|
79
|
+
document: payloadSchemaDocument,
|
|
80
|
+
} as PayloadSchemaArtifactBinding));
|
|
81
|
+
|
|
82
|
+
ajv.addSchema(payloadSchemaDocument, payloadSchemaDocument.$id);
|
|
83
|
+
|
|
84
|
+
const payloadValidatorRows = payloadArtifactRows.map((artifact) => {
|
|
85
|
+
const definitionName = payloadDefinitionBySchemaId[artifact.id as keyof typeof payloadDefinitionBySchemaId];
|
|
86
|
+
const validate = ajv.compile({ $ref: `${payloadSchemaDocument.$id}#/$defs/${definitionName}` });
|
|
87
|
+
return {
|
|
88
|
+
id: artifact.id,
|
|
89
|
+
version: artifact.version,
|
|
90
|
+
implementationId: `implementation.schema-validator.ajv-draft-2020-12.${definitionName}`,
|
|
91
|
+
implementationVersion: 1,
|
|
92
|
+
artifactSha256: artifact.documentSha256,
|
|
93
|
+
subschemaSha256: artifact.subschemaSha256,
|
|
94
|
+
callable: (raw: unknown) => validate(raw) === true,
|
|
95
|
+
} as PayloadSchemaValidatorBinding;
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
const credentialPayloadIds = new Set([
|
|
99
|
+
'schema.corrective-replan-binding',
|
|
100
|
+
'schema.corrective-replan-plan-validation-attestation',
|
|
101
|
+
'schema.corrective-replan-receipt',
|
|
102
|
+
]);
|
|
103
|
+
const credentialPayloadArtifacts = correctiveReplanCredentialSchemaArtifacts
|
|
104
|
+
.filter((entry) => credentialPayloadIds.has(entry.id))
|
|
105
|
+
.map((entry) => ({
|
|
106
|
+
id: entry.id, version: entry.version, implementationId: entry.implementationId,
|
|
107
|
+
implementationVersion: entry.implementationVersion, documentSha256: entry.documentBytesSha256,
|
|
108
|
+
schemaPointer: entry.schemaPointer, subschemaSha256: entry.subschemaCanonicalSha256, document: entry.document,
|
|
109
|
+
} as PayloadSchemaArtifactBinding));
|
|
110
|
+
const credentialPayloadValidators = correctiveReplanCredentialSchemaValidators
|
|
111
|
+
.filter((entry) => credentialPayloadIds.has(entry.id))
|
|
112
|
+
.map((entry) => ({
|
|
113
|
+
id: entry.id, version: entry.version, implementationId: entry.implementationId,
|
|
114
|
+
implementationVersion: entry.implementationVersion, artifactSha256: entry.artifactDocumentBytesSha256,
|
|
115
|
+
subschemaSha256: entry.subschemaCanonicalSha256, callable: entry.callable,
|
|
116
|
+
} as PayloadSchemaValidatorBinding));
|
|
117
|
+
|
|
118
|
+
const taskTransactionUrl = new URL('../../../schemas/corrective-replan-task-transaction.private.schema.json', import.meta.url);
|
|
119
|
+
const taskTransactionBytes = readFileSync(taskTransactionUrl);
|
|
120
|
+
const taskTransactionDocument = JSON.parse(taskTransactionBytes.toString('utf8')) as object;
|
|
121
|
+
const taskTransactionSha256 = createHash('sha256').update(taskTransactionBytes).digest('hex');
|
|
122
|
+
const validateTaskTransaction = ajv.compile(taskTransactionDocument);
|
|
123
|
+
const taskTransactionArtifact: PayloadSchemaArtifactBinding = {
|
|
124
|
+
id: 'schema.corrective-replan-task-transaction', version: 1,
|
|
125
|
+
implementationId: 'implementation.schema-artifact.corrective-replan-task-transaction', implementationVersion: 1,
|
|
126
|
+
documentSha256: taskTransactionSha256, schemaPointer: '#', subschemaSha256: hashCanonical(taskTransactionDocument),
|
|
127
|
+
document: taskTransactionDocument,
|
|
128
|
+
};
|
|
129
|
+
const taskTransactionValidator: PayloadSchemaValidatorBinding = {
|
|
130
|
+
id: taskTransactionArtifact.id, version: 1,
|
|
131
|
+
implementationId: 'implementation.schema-validator.ajv-draft-2020-12.corrective-replan-task-transaction', implementationVersion: 1,
|
|
132
|
+
artifactSha256: taskTransactionArtifact.documentSha256, subschemaSha256: taskTransactionArtifact.subschemaSha256,
|
|
133
|
+
callable: (raw: unknown) => validateTaskTransaction(raw) === true,
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
export const installedTransitionDefinitionArtifact = deepFreeze(transitionDefinitionArtifact);
|
|
137
|
+
export const installedTransitionDefinitionValidator = deepFreeze(transitionDefinitionValidator);
|
|
138
|
+
export const installedPayloadSchemaArtifacts: readonly PayloadSchemaArtifactBinding[] = deepFreeze([
|
|
139
|
+
...payloadArtifactRows, ...credentialPayloadArtifacts, taskTransactionArtifact,
|
|
140
|
+
]);
|
|
141
|
+
export const installedPayloadSchemaValidators: readonly PayloadSchemaValidatorBinding[] = deepFreeze([
|
|
142
|
+
...payloadValidatorRows, ...credentialPayloadValidators, taskTransactionValidator,
|
|
143
|
+
]);
|
|
144
|
+
|
|
145
|
+
export function createTransitionSchemaArtifact(registry: SemanticRegistry): TransitionSchemaArtifact {
|
|
146
|
+
if (registryVocabularySha256(registry) !== hashCanonical(vocabularyDocument)) {
|
|
147
|
+
throw new TypeError('Transition definition vocabulary artifact is stale for the installed semantic registry.');
|
|
148
|
+
}
|
|
149
|
+
validateSchemaReferenceVocabulary(schemaDocument, vocabularyDocument);
|
|
150
|
+
return {
|
|
151
|
+
documentSha256: transitionDefinitionDocumentSha256,
|
|
152
|
+
vocabularySha256: transitionDefinitionVocabularySha256,
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export function registryVocabularySha256(registry: SemanticRegistry): string {
|
|
157
|
+
return hashCanonical(registryVocabulary(registry));
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export function registryVocabulary(registry: SemanticRegistry): Readonly<Record<string, readonly string[]>> {
|
|
161
|
+
const entries = Object.fromEntries(
|
|
162
|
+
Object.entries(registry)
|
|
163
|
+
.filter((entry): entry is [string, readonly VersionedRegistryEntry<string>[]] =>
|
|
164
|
+
Array.isArray(entry[1])
|
|
165
|
+
&& entry[1].every((candidate) => candidate !== null
|
|
166
|
+
&& typeof candidate === 'object'
|
|
167
|
+
&& typeof (candidate as { id?: unknown }).id === 'string'
|
|
168
|
+
&& Number.isInteger((candidate as { version?: unknown }).version)))
|
|
169
|
+
.map(([category, entries]) => [
|
|
170
|
+
category,
|
|
171
|
+
entries.map((entry) => `${entry.id}@${entry.version}`).sort((left, right) => left.localeCompare(right)),
|
|
172
|
+
] as const)
|
|
173
|
+
.sort(([left], [right]) => left.localeCompare(right)),
|
|
174
|
+
) as Record<string, readonly string[]>;
|
|
175
|
+
return {
|
|
176
|
+
...entries,
|
|
177
|
+
projectionFields: registry.projections
|
|
178
|
+
.flatMap((projection) => projection.fieldIds.map((fieldId) => `${projection.id}@${projection.version}:${fieldId}`))
|
|
179
|
+
.sort((left, right) => left.localeCompare(right)),
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export function installedTransitionDefinitionVocabulary(): Readonly<Record<string, readonly string[]>> {
|
|
184
|
+
return vocabularyDocument;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function extractVocabulary(document: object): Readonly<Record<string, readonly string[]>> {
|
|
188
|
+
const candidate = document as {
|
|
189
|
+
$defs?: {
|
|
190
|
+
semanticRegistryVocabulary?: {
|
|
191
|
+
const?: unknown;
|
|
192
|
+
};
|
|
193
|
+
};
|
|
194
|
+
};
|
|
195
|
+
const vocabulary = candidate.$defs?.semanticRegistryVocabulary?.const;
|
|
196
|
+
if (vocabulary === null || typeof vocabulary !== 'object' || Array.isArray(vocabulary)) {
|
|
197
|
+
throw new TypeError('Transition definition schema has no embedded semantic registry vocabulary.');
|
|
198
|
+
}
|
|
199
|
+
for (const [category, entries] of Object.entries(vocabulary)) {
|
|
200
|
+
if (!Array.isArray(entries) || !entries.every((entry) => typeof entry === 'string')) {
|
|
201
|
+
throw new TypeError(`Transition definition schema vocabulary category ${category} is invalid.`);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return vocabulary as Readonly<Record<string, readonly string[]>>;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function validateSchemaReferenceVocabulary(
|
|
208
|
+
document: object,
|
|
209
|
+
vocabulary: Readonly<Record<string, readonly string[]>>,
|
|
210
|
+
): void {
|
|
211
|
+
const definitionByCategory: Readonly<Record<string, string>> = {
|
|
212
|
+
inputs: 'inputRef',
|
|
213
|
+
projections: 'projectionRef',
|
|
214
|
+
hashPolicies: 'hashPolicyRef',
|
|
215
|
+
identities: 'identityRef',
|
|
216
|
+
identityComparators: 'identityComparatorRef',
|
|
217
|
+
principalBases: 'principalBasisRef',
|
|
218
|
+
capabilities: 'capabilityRef',
|
|
219
|
+
credentialPolicies: 'credentialPolicyRef',
|
|
220
|
+
credentialVerifiers: 'credentialVerifierRef',
|
|
221
|
+
delegationPolicies: 'delegationPolicyRef',
|
|
222
|
+
ownershipPolicies: 'ownershipPolicyRef',
|
|
223
|
+
guardEvaluators: 'guardEvaluatorRef',
|
|
224
|
+
effectAdapters: 'effectAdapterRef',
|
|
225
|
+
resources: 'resourceRef',
|
|
226
|
+
lockPolicies: 'lockPolicyRef',
|
|
227
|
+
executionKeyPolicies: 'executionKeyPolicyRef',
|
|
228
|
+
journalSchemas: 'journalSchemaRef',
|
|
229
|
+
journalAdapters: 'journalAdapterRef',
|
|
230
|
+
recoveryAdapters: 'recoveryAdapterRef',
|
|
231
|
+
readbackAdapters: 'readbackAdapterRef',
|
|
232
|
+
releaseProfiles: 'releaseProfileRef',
|
|
233
|
+
coverageProfiles: 'coverageProfileRef',
|
|
234
|
+
limitations: 'limitationRef',
|
|
235
|
+
};
|
|
236
|
+
for (const [category, definitionName] of Object.entries(definitionByCategory)) {
|
|
237
|
+
const registered = (vocabulary[category] ?? []).map((entry) => entry.slice(0, entry.lastIndexOf('@'))).sort();
|
|
238
|
+
const schemaIds = referenceIds(document, definitionName);
|
|
239
|
+
if (hashCanonical(registered) !== hashCanonical(schemaIds)) {
|
|
240
|
+
throw new TypeError(`Transition definition schema reference ${definitionName} is stale for ${category}.`);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
const projectionFields = new Set((vocabulary.projectionFields ?? []).map((entry) => entry.slice(entry.indexOf(':') + 1)));
|
|
244
|
+
if (hashCanonical([...projectionFields].sort()) !== hashCanonical(referenceIds(document, 'fieldId'))) {
|
|
245
|
+
throw new TypeError('Transition definition schema field vocabulary is stale for registered projections.');
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
function referenceIds(document: object, definitionName: string): string[] {
|
|
250
|
+
const definition = (document as { $defs?: Record<string, unknown> }).$defs?.[definitionName] as {
|
|
251
|
+
enum?: unknown;
|
|
252
|
+
const?: unknown;
|
|
253
|
+
properties?: { id?: { enum?: unknown; const?: unknown }; version?: { const?: unknown } };
|
|
254
|
+
} | undefined;
|
|
255
|
+
const idSchema = definitionName === 'fieldId' ? definition : definition?.properties?.id;
|
|
256
|
+
const ids = Array.isArray(idSchema?.enum)
|
|
257
|
+
? idSchema.enum.filter((entry): entry is string => typeof entry === 'string')
|
|
258
|
+
: typeof idSchema?.const === 'string' ? [idSchema.const] : [];
|
|
259
|
+
if (definitionName !== 'fieldId' && definition?.properties?.version?.const !== 1) {
|
|
260
|
+
throw new TypeError(`Transition definition schema reference ${definitionName} has no exact version binding.`);
|
|
261
|
+
}
|
|
262
|
+
return ids.sort((left, right) => left.localeCompare(right));
|
|
263
|
+
}
|