codex-workflow-v2 2.0.0-beta.13.9 → 2.0.0-beta.14.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -388
- package/dist/reviewer-runtime-build.json +98 -34
- package/dist/src/alpha6/adoption.d.ts +3 -1
- package/dist/src/alpha6/adoption.js +48 -8
- 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 +53 -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/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/remediation.d.ts +8 -21
- package/dist/src/alpha6/remediation.js +225 -474
- 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/alpha7/autonomy.d.ts +9 -0
- package/dist/src/alpha7/autonomy.js +40 -1
- package/dist/src/alpha7/autonomy.js.map +1 -1
- package/dist/src/beta1/project-transaction.d.ts +3 -1
- package/dist/src/beta1/project-transaction.js +20 -6
- 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 +3 -3
- package/dist/src/cli-actions.js +8 -15
- package/dist/src/cli-actions.js.map +1 -1
- package/dist/src/cli.js +43 -97
- package/dist/src/cli.js.map +1 -1
- package/dist/src/contracts.d.ts +54 -34
- package/dist/src/delegation.d.ts +5 -1
- package/dist/src/delegation.js +4 -0
- package/dist/src/delegation.js.map +1 -1
- 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/failed-checkpoint-update.d.ts +69 -0
- package/dist/src/failed-checkpoint-update.js +171 -0
- package/dist/src/failed-checkpoint-update.js.map +1 -0
- 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-credential-core.d.ts +2 -0
- package/dist/src/lifecycle/corrective-replan-credential-core.js +45 -9
- package/dist/src/lifecycle/corrective-replan-credential-core.js.map +1 -1
- package/dist/src/lifecycle/corrective-replan.js +12 -8
- package/dist/src/lifecycle/corrective-replan.js.map +1 -1
- package/dist/src/lifecycle/semantic-registry.js +4 -2
- package/dist/src/lifecycle/semantic-registry.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 +10 -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 +38 -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.d.ts +9 -1
- package/dist/src/state/corrective-replan-public.js +50 -8
- 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-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/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 +88 -64
- package/dist/src/workflow.js +832 -1456
- 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 +36 -237
- package/docs/project-memory.md +31 -50
- package/docs/release-app-evidence.md +190 -0
- package/docs/release.md +101 -388
- package/docs/updating-existing-project.md +65 -726
- 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 +88 -200
- package/plugins/codex-workflow-gateway/references/codebase-memory-routing.md +57 -0
- package/plugins/codex-workflow-gateway/references/protocol.md +51 -458
- package/plugins/codex-workflow-gateway/scripts/chat-dispatch.mjs +20 -4
- package/plugins/codex-workflow-gateway/scripts/chat-model-policy.mjs +21 -34
- package/plugins/codex-workflow-gateway/scripts/chat-registry.mjs +23 -5
- package/plugins/codex-workflow-gateway/skills/codex-workflow-gateway/SKILL.md +92 -778
- package/references/state-machine.md +7 -5
- package/roles/delivery-coordinator.md +31 -11
- package/roles/scope-lead.md +1 -1
- package/roles/technical-planner.md +5 -2
- package/schemas/adoption-posture-event.schema.json +11 -0
- package/schemas/authorization-event.schema.json +1 -1
- package/schemas/corrective-decision-event.schema.json +26 -4
- package/schemas/corrective-replan-credentials.private.schema.json +8 -5
- package/schemas/corrective-replan-execution-event.private.schema.json +9 -0
- package/schemas/corrective-replan-public.schema.json +2 -1
- package/schemas/delegation-grant.schema.json +1 -1
- package/schemas/project-knowledge-map.schema.json +3 -1
- package/schemas/remediation-event.schema.json +10 -1
- package/schemas/task.schema.json +64 -2
- package/schemas/transition-definition.schema.json +4 -0
- package/schemas/transition-payloads.schema.json +16 -1
- package/src/alpha6/adoption.ts +1146 -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 +45 -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 +2505 -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 +449 -0
- package/src/alpha7/corrective-recovery.ts +1332 -0
- package/src/artifacts.ts +130 -0
- package/src/beta1/project-transaction.ts +364 -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 +112 -0
- package/src/cli.ts +1490 -0
- package/src/contracts.ts +1512 -0
- package/src/credential-output.ts +89 -0
- package/src/credential-transport.ts +215 -0
- package/src/delegation.ts +194 -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/failed-checkpoint-update.ts +203 -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 +437 -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 +847 -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 +574 -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 +665 -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 +819 -0
- package/src/state/corrective-replan-public-schema.ts +83 -0
- package/src/state/corrective-replan-public.ts +952 -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 +10342 -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 -506
- 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,136 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { correctiveReplanBindingManifest } from './corrective-replan-binding-manifest.js';
|
|
3
|
+
import { hashCanonical } from './fingerprint.js';
|
|
4
|
+
import { deepFreeze } from './immutable.js';
|
|
5
|
+
|
|
6
|
+
type JsonRecord = Record<string, unknown>;
|
|
7
|
+
type AuthorityCallable = (...arguments_: readonly unknown[]) => unknown;
|
|
8
|
+
|
|
9
|
+
export interface AuthoritySemanticBinding {
|
|
10
|
+
readonly id: string;
|
|
11
|
+
readonly version: 1;
|
|
12
|
+
readonly kind: 'role-evaluator' | 'identity-comparator';
|
|
13
|
+
readonly implementationId: `implementation.${string}`;
|
|
14
|
+
readonly implementationVersion: number;
|
|
15
|
+
readonly wiring: 'invoked';
|
|
16
|
+
readonly callable: AuthorityCallable;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
interface AuthorityIssue { readonly issueId: string; readonly path: string; readonly message: string }
|
|
20
|
+
|
|
21
|
+
const eligibleRole: AuthorityCallable = (input) => roleVerdict(input);
|
|
22
|
+
const authorValidator: AuthorityCallable = (input) => identityVerdict(input);
|
|
23
|
+
const authorRiskAuditor: AuthorityCallable = (input) => identityVerdict(input);
|
|
24
|
+
const authorHumanPrincipal: AuthorityCallable = (input) => identityVerdict(input);
|
|
25
|
+
|
|
26
|
+
export const installedAuthoritySemanticBindings: readonly AuthoritySemanticBinding[] = deepFreeze([
|
|
27
|
+
binding('authority-role-evaluator.corrective-replan.eligible-role', 'authority-role-evaluator.corrective-replan.eligible-role', 'role-evaluator', eligibleRole),
|
|
28
|
+
binding('identity-comparator.corrective-replan.author-validator', 'identity-comparator.corrective-replan.author-validator', 'identity-comparator', authorValidator),
|
|
29
|
+
binding('identity-comparator.corrective-replan.author-risk-auditor', 'identity-comparator.corrective-replan.author-risk-auditor', 'identity-comparator', authorRiskAuditor),
|
|
30
|
+
binding('identity-comparator.corrective-replan.author-human-principal', 'identity-comparator.corrective-replan.author-human-principal', 'identity-comparator', authorHumanPrincipal),
|
|
31
|
+
]);
|
|
32
|
+
|
|
33
|
+
const ref = (id: string) => ({ id, version: 1 });
|
|
34
|
+
const constraints = [
|
|
35
|
+
constraint('constraint.corrective-replan.author-not-validator', 'author-validator', 'actor.validator'),
|
|
36
|
+
constraint('constraint.corrective-replan.author-not-risk-auditor', 'author-risk-auditor', 'actor.risk-auditor'),
|
|
37
|
+
constraint('constraint.corrective-replan.author-not-human-principal', 'author-human-principal', 'principal.human'),
|
|
38
|
+
];
|
|
39
|
+
|
|
40
|
+
/** Diagnostic-only assessment of the installed static tuple. It cannot issue a Core handle. */
|
|
41
|
+
export function assessCorrectiveReplanAuthorityTuple(tuple: unknown) {
|
|
42
|
+
const value = record(tuple); const issues: AuthorityIssue[] = [];
|
|
43
|
+
extraFields(value, ['transitionId', 'actor', 'eligibleRoles', 'roleEvaluator', 'humanPrincipal', 'capability', 'delegation', 'ownership', 'constraints', 'priorPlanAuthorization'],
|
|
44
|
+
'/','authority.tuple.extra-field', issues);
|
|
45
|
+
extraFields(record(value.actor), ['identity', 'basis'], '/actor/', 'authority.tuple.extra-field', issues);
|
|
46
|
+
extraFields(record(value.humanPrincipal), ['identity', 'basis', 'kind'], '/humanPrincipal/', 'authority.tuple.extra-field', issues);
|
|
47
|
+
extraFields(record(value.capability), ['id', 'version', 'source', 'issuer', 'transitionId', 'scope', 'bindingManifest'], '/capability/', 'authority.tuple.extra-field', issues);
|
|
48
|
+
extraFields(record(value.priorPlanAuthorization), ['disposition', 'authority'], '/priorPlanAuthorization/', 'authority.tuple.extra-field', issues);
|
|
49
|
+
check(value, '/transitionId', 'authority.transition.mismatch', 'task.plan.corrective-replan', issues);
|
|
50
|
+
check(value, '/actor/identity', 'authority.actor.identity-mismatch', ref('identity.actor'), issues);
|
|
51
|
+
check(value, '/actor/basis', 'authority.actor.basis-mismatch', ref('principal-basis.human-confirmation'), issues);
|
|
52
|
+
check(value, '/eligibleRoles', 'authority.role-evaluator.mismatch', ['delivery-coordinator', 'technical-planner'], issues);
|
|
53
|
+
check(value, '/roleEvaluator', 'authority.role-evaluator.mismatch', ref('authority-role-evaluator.corrective-replan.eligible-role'), issues);
|
|
54
|
+
check(value, '/humanPrincipal/identity', 'authority.principal.identity-mismatch', ref('identity.human-principal'), issues);
|
|
55
|
+
check(value, '/humanPrincipal/basis', 'authority.principal.basis-mismatch', ref('principal-basis.human-confirmation'), issues);
|
|
56
|
+
check(value, '/humanPrincipal/kind', 'authority.principal.kind-mismatch', 'human', issues);
|
|
57
|
+
const capability = get(value, '/capability');
|
|
58
|
+
if (!isRecord(capability)) issue(issues, 'authority.capability.missing', '/capability');
|
|
59
|
+
else {
|
|
60
|
+
check(value, '/capability/id', 'authority.capability.id-mismatch', 'capability.task.corrective-replan', issues);
|
|
61
|
+
check(value, '/capability/version', 'authority.capability.version-mismatch', 1, issues);
|
|
62
|
+
check(value, '/capability/source', 'authority.capability.source-mismatch', ref('authority-source.human-confirmation'), issues);
|
|
63
|
+
check(value, '/capability/issuer', 'authority.capability.issuer-mismatch', ref('identity.human-principal'), issues);
|
|
64
|
+
check(value, '/capability/transitionId', 'authority.capability.transition-mismatch', 'task.plan.corrective-replan', issues);
|
|
65
|
+
check(value, '/capability/scope', 'authority.capability.scope-mismatch', { entity: 'task', task: 'taskId', guardedStep: 'guardedStepId' }, issues);
|
|
66
|
+
if (capability.bindingManifest !== correctiveReplanBindingManifest)
|
|
67
|
+
issue(issues, 'authority.capability.binding-manifest-mismatch', '/capability/bindingManifest');
|
|
68
|
+
}
|
|
69
|
+
check(value, '/delegation', 'authority.delegation.not-forbidden', ref('delegation.forbidden'), issues);
|
|
70
|
+
check(value, '/ownership', 'authority.ownership.not-clear', { c1Claim: 'none', writerLease: 'none' }, issues);
|
|
71
|
+
const rows = Array.isArray(value.constraints) ? value.constraints : [];
|
|
72
|
+
const seen = new Set<string>();
|
|
73
|
+
rows.forEach((entry, index) => {
|
|
74
|
+
const id = isRecord(entry) && typeof entry.constraintId === 'string' ? entry.constraintId : '';
|
|
75
|
+
if (seen.has(id)) issue(issues, 'authority.constraint.duplicate', `/constraints/${index}/constraintId`);
|
|
76
|
+
else if (id === 'constraint.corrective-replan.validator-not-risk-auditor') issue(issues, 'authority.constraint.forbidden-validator-risk', `/constraints/${index}`);
|
|
77
|
+
else if (!constraints.some((expected) => expected.constraintId === id)) issue(issues, 'authority.constraint.unknown', `/constraints/${index}/constraintId`);
|
|
78
|
+
seen.add(id);
|
|
79
|
+
if (isRecord(entry)) extraFields(entry, ['constraintId', 'comparator', 'operands', 'relation', 'missing', 'enforcement'],
|
|
80
|
+
`/constraints/${index}/`, 'authority.constraint.extra-field', issues);
|
|
81
|
+
});
|
|
82
|
+
constraints.forEach((expected, index) => {
|
|
83
|
+
const actualIndex = rows.findIndex((entry) => isRecord(entry) && entry.constraintId === expected.constraintId);
|
|
84
|
+
if (actualIndex < 0) return issue(issues, 'authority.constraint.missing', `/constraints/${index}`);
|
|
85
|
+
for (const field of ['comparator', 'operands', 'relation', 'missing', 'enforcement'] as const) {
|
|
86
|
+
check(value, `/constraints/${actualIndex}/${field}`, `authority.constraint.${field === 'comparator' ? 'comparator-id' : field}-mismatch`, expected[field], issues,
|
|
87
|
+
field === 'comparator' ? `/constraints/${index}/${field}/id` : `/constraints/${index}/${field}`);
|
|
88
|
+
if (field === 'comparator') check(value, `/constraints/${actualIndex}/comparator/version`, 'authority.constraint.comparator-version-mismatch', 1, issues, `/constraints/${index}/comparator/version`);
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
check(value, '/priorPlanAuthorization/disposition', 'authority.plan-bound-grant-active', 'superseded', issues);
|
|
92
|
+
check(value, '/priorPlanAuthorization/authority', 'authority.plan-bound-grant-active', 'none', issues);
|
|
93
|
+
const ordered = [...issues].sort((a, b) => `${a.path}\0${a.issueId}`.localeCompare(`${b.path}\0${b.issueId}`));
|
|
94
|
+
const blockers: string[] = [];
|
|
95
|
+
if (ordered.some((entry) => entry.issueId === 'authority.capability.missing')) blockers.push('static.authority.exact-capability-missing');
|
|
96
|
+
if (ordered.some((entry) => entry.issueId === 'authority.plan-bound-grant-active')) blockers.push('static.authority.plan-bound-grant-not-superseded');
|
|
97
|
+
if (ordered.length > 0) blockers.push('static.authority.exact-tuple-invalid');
|
|
98
|
+
const content = { staticTupleValid: ordered.length === 0, blockers: [...new Set(blockers)], issues: ordered,
|
|
99
|
+
bindings: installedAuthoritySemanticBindings };
|
|
100
|
+
return deepFreeze({ ...content, reportHash: hashCanonical({ ...content, bindings: content.bindings.map(projectBinding) }) });
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function binding(id: string, suffix: string, kind: AuthoritySemanticBinding['kind'], callable: AuthorityCallable): AuthoritySemanticBinding {
|
|
104
|
+
return { id, version: 1, kind, implementationId: `implementation.${suffix}`, implementationVersion: 1, wiring: 'invoked', callable };
|
|
105
|
+
}
|
|
106
|
+
export function projectAuthoritySemanticBundle(bindings: readonly AuthoritySemanticBinding[]) {
|
|
107
|
+
const projection = { bundleVersion: 2, bindingManifest: correctiveReplanBindingManifest, bindings: bindings.map(projectBinding) };
|
|
108
|
+
return deepFreeze({ ...projection, bundleSha256: createHash('sha256').update(JSON.stringify(projection)).digest('hex') });
|
|
109
|
+
}
|
|
110
|
+
function constraint(constraintId: string, suffix: string, right: string) { return { constraintId,
|
|
111
|
+
comparator: ref(`identity-comparator.corrective-replan.${suffix}`), operands: ['actor.author', right],
|
|
112
|
+
relation: 'not-equal', missing: 'block', enforcement: 'static-and-runtime' }; }
|
|
113
|
+
function roleVerdict(input: unknown) { const value = record(input); const roles = ['delivery-coordinator', 'technical-planner'];
|
|
114
|
+
if (!/^[a-f0-9]{64}$/.test(String(value.actorIdentityHash ?? '')) || !sameSet(value.eligibleRoles, roles)
|
|
115
|
+
|| typeof value.actorRole !== 'string' || value.actorRole.length === 0) return verdict(false, 'ROLE_INPUT_INVALID');
|
|
116
|
+
return roles.includes(value.actorRole) ? verdict(true, null) : verdict(false, 'ROLE_NOT_ELIGIBLE'); }
|
|
117
|
+
function identityVerdict(input: unknown) { const value = record(input); const valid = /^[a-f0-9]{64}$/;
|
|
118
|
+
if (typeof value.leftIdentityHash !== 'string' || typeof value.rightIdentityHash !== 'string'
|
|
119
|
+
|| !valid.test(value.leftIdentityHash) || !valid.test(value.rightIdentityHash)) return verdict(false, 'IDENTITY_INPUT_INVALID');
|
|
120
|
+
return value.leftIdentityHash !== value.rightIdentityHash ? verdict(true, null) : verdict(false, 'IDENTITY_CONSTRAINT_VIOLATED'); }
|
|
121
|
+
function verdict(passed: boolean, reasonCode: string | null) { return deepFreeze({ passed, blocked: !passed, reasonCode }); }
|
|
122
|
+
function projectBinding({ callable: _callable, wiring: _wiring, ...binding }: AuthoritySemanticBinding) { return binding; }
|
|
123
|
+
function record(value: unknown): JsonRecord { return isRecord(value) ? value : {}; }
|
|
124
|
+
function isRecord(value: unknown): value is JsonRecord { return value !== null && typeof value === 'object' && !Array.isArray(value); }
|
|
125
|
+
function get(value: JsonRecord, path: string): unknown { return path.split('/').filter(Boolean).reduce<unknown>((cursor, key) =>
|
|
126
|
+
Array.isArray(cursor) && /^\d+$/.test(key) ? cursor[Number(key)] : isRecord(cursor) ? cursor[key] : undefined, value); }
|
|
127
|
+
function check(value: JsonRecord, path: string, issueId: string, expected: unknown, issues: AuthorityIssue[], reportedPath = path): void {
|
|
128
|
+
const actual = get(value, path);
|
|
129
|
+
if (actual === undefined || hashCanonical(actual) !== hashCanonical(expected)) issue(issues, issueId, reportedPath);
|
|
130
|
+
}
|
|
131
|
+
function sameSet(value: unknown, expected: readonly string[]): boolean { return Array.isArray(value) && value.length === expected.length
|
|
132
|
+
&& new Set(value).size === expected.length && value.every((entry) => typeof entry === 'string' && expected.includes(entry)); }
|
|
133
|
+
function extraFields(value: JsonRecord, allowed: readonly string[], prefix: string, issueId: string, issues: AuthorityIssue[]): void {
|
|
134
|
+
Object.keys(value).filter((key) => !allowed.includes(key)).forEach((key) => issue(issues, issueId, `${prefix}${key}`));
|
|
135
|
+
}
|
|
136
|
+
function issue(issues: AuthorityIssue[], issueId: string, path: string): void { issues.push({ issueId, path, message: `${issueId} at ${path}.` }); }
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { hashCanonical } from './canonical-hash.js';
|
|
2
|
+
import { deepFreeze } from './immutable.js';
|
|
3
|
+
import type { ProjectionFieldId, ProjectionId } from './types.js';
|
|
4
|
+
|
|
5
|
+
const ref = <TId extends string>(id: TId) => ({ id, version: 1 as const });
|
|
6
|
+
type ValueKind = 'literal' | 'sha256' | 'safe-integer' | 'entity-id' | 'git-oid' | 'actor-role';
|
|
7
|
+
type Canonicalization = 'exact' | 'lowercase-hex' | 'safe-nonnegative-integer' | 'nfc-trim' | 'lowercase-git-oid' | 'registered-enum';
|
|
8
|
+
const row = (bindingId: string, projection: ProjectionId, fieldId: ProjectionFieldId, valueKind: ValueKind, canonicalization: Canonicalization) => ({
|
|
9
|
+
ordinal: rowsOrdinal++, bindingId, projection: ref(projection), fieldId, valueKind, canonicalization,
|
|
10
|
+
receiptPath: `/binding/values/${bindingId}` as `/binding/values/${string}`,
|
|
11
|
+
});
|
|
12
|
+
let rowsOrdinal = 0;
|
|
13
|
+
const protocol = (id: string, field: ProjectionFieldId, kind: ValueKind, canonical: Canonicalization) => row(id, 'projection.corrective-replan.protocol', field, kind, canonical);
|
|
14
|
+
const state = (id: string, field: ProjectionFieldId, kind: ValueKind, canonical: Canonicalization) => row(id, 'projection.corrective-replan.state', field, kind, canonical);
|
|
15
|
+
const candidate = (id: string, field: ProjectionFieldId) => row(id, 'projection.corrective-replan.candidate', field, 'sha256', 'lowercase-hex');
|
|
16
|
+
const candidateState = (id: string, field: ProjectionFieldId, kind: ValueKind, canonical: Canonicalization) => row(id, 'projection.corrective-replan.candidate', field, kind, canonical);
|
|
17
|
+
const authority = (id: string, field: ProjectionFieldId, kind: ValueKind, canonical: Canonicalization) => row(id, 'projection.corrective-replan.authority', field, kind, canonical);
|
|
18
|
+
|
|
19
|
+
const rows = [
|
|
20
|
+
protocol('transitionId', 'field.transition-id', 'literal', 'exact'), protocol('runtimeFingerprint', 'field.runtime-fingerprint', 'sha256', 'lowercase-hex'),
|
|
21
|
+
protocol('catalogHash', 'field.catalog-hash', 'sha256', 'lowercase-hex'), protocol('lifecycleEpoch', 'field.lifecycle-epoch', 'safe-integer', 'safe-nonnegative-integer'),
|
|
22
|
+
state('taskId', 'field.task-id', 'entity-id', 'nfc-trim'), state('revision', 'field.task-revision', 'safe-integer', 'safe-nonnegative-integer'),
|
|
23
|
+
state('currentPlanHash', 'field.current-plan-hash', 'sha256', 'lowercase-hex'), state('briefHash', 'field.brief-hash', 'sha256', 'lowercase-hex'),
|
|
24
|
+
state('knowledgeRevision', 'field.knowledge-revision', 'safe-integer', 'safe-nonnegative-integer'), state('knowledgeHash', 'field.knowledge-hash', 'sha256', 'lowercase-hex'),
|
|
25
|
+
candidateState('targetKnowledgeRevision', 'field.target-knowledge-revision', 'safe-integer', 'safe-nonnegative-integer'), candidate('targetKnowledgeHash', 'field.target-knowledge-hash'),
|
|
26
|
+
state('gitHead', 'field.git-head', 'git-oid', 'lowercase-git-oid'), state('guardedStepId', 'field.guarded-step-id', 'entity-id', 'nfc-trim'),
|
|
27
|
+
state('correctiveDecisionEventId', 'field.corrective-decision-event-id', 'entity-id', 'nfc-trim'), state('correctiveDecisionHash', 'field.corrective-decision-hash', 'sha256', 'lowercase-hex'),
|
|
28
|
+
state('attemptCount', 'field.attempt-count', 'safe-integer', 'safe-nonnegative-integer'), state('remediationTailHash', 'field.remediation-tail-hash', 'sha256', 'lowercase-hex'),
|
|
29
|
+
candidate('candidatePlanHash', 'field.candidate-plan-hash'), candidate('candidateStepSetHash', 'field.candidate-step-set-hash'),
|
|
30
|
+
candidate('planAuthorIdentityHash', 'field.plan-author-identity-hash'), candidate('planValidationHash', 'field.plan-validation-hash'),
|
|
31
|
+
candidate('planValidatorIdentityHash', 'field.plan-validator-identity-hash'), candidate('riskAuditHash', 'field.risk-audit-hash'), candidate('riskAuditorIdentityHash', 'field.risk-auditor-identity-hash'),
|
|
32
|
+
authority('actorIdentityHash', 'field.actor-identity-hash', 'sha256', 'lowercase-hex'), authority('actorRole', 'field.actor-role', 'actor-role', 'registered-enum'),
|
|
33
|
+
authority('humanPrincipalIdentityHash', 'field.human-principal-identity-hash', 'sha256', 'lowercase-hex'), authority('capabilityId', 'field.capability-id', 'literal', 'exact'),
|
|
34
|
+
authority('capabilityVersion', 'field.capability-version', 'safe-integer', 'safe-nonnegative-integer'),
|
|
35
|
+
];
|
|
36
|
+
|
|
37
|
+
const identity = { id: 'binding-manifest.corrective-replan.exact-v1' as const, version: 1 as const, rows };
|
|
38
|
+
export const correctiveReplanBindingManifest = deepFreeze({
|
|
39
|
+
...identity,
|
|
40
|
+
manifestSha256: hashCanonical({ ...identity, rows: [...rows].sort((a, b) => a.bindingId.localeCompare(b.bindingId)) }),
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
export const correctiveReplanBindingIds = deepFreeze(rows.map(({ bindingId }) => bindingId));
|
|
44
|
+
|
|
45
|
+
export const historicalCompletedCorrectiveReplanBindingIdentities = deepFreeze([
|
|
46
|
+
{
|
|
47
|
+
manifestSha256: 'edab7ee7ac4018e759f5fc702a11a0fd113ef4f2cf8ed8fa823a59fde3012a1a',
|
|
48
|
+
runtimeFingerprint: 'bd4e7a0ddfcb6abc0c5eb107775e6aea7e08c4606dda4d945d77af8a4520710d',
|
|
49
|
+
catalogHash: 'fa1d11860d4f07978c3b8e85d1f91cd3d15b17284b05f41e05d462d3bb092aed',
|
|
50
|
+
},
|
|
51
|
+
] as const);
|