@ornexus/neocortex 4.60.58 → 4.60.60
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/dist/sbom.cdx.json +241 -82
- package/install.ps1 +1 -1
- package/install.sh +1 -1
- package/package.json +6 -2
- package/packages/client/dist/cli.js +37 -4
- package/packages/client/dist/commands/architecture-answers.d.ts +26 -0
- package/packages/client/dist/commands/architecture-answers.js +7 -0
- package/packages/client/dist/commands/architecture-memory-terminal.d.ts +21 -0
- package/packages/client/dist/commands/architecture-memory-terminal.js +2 -0
- package/packages/client/dist/commands/architecture-root-binding.d.ts +2 -0
- package/packages/client/dist/commands/architecture-root-binding.js +1 -0
- package/packages/client/dist/commands/invoke.d.ts +43 -2
- package/packages/client/dist/commands/invoke.js +98 -70
- package/packages/client/dist/commands/legacy-story-branch.d.ts +10 -0
- package/packages/client/dist/commands/legacy-story-branch.js +1 -0
- package/packages/client/dist/commands/legacy-story-pr.d.ts +18 -0
- package/packages/client/dist/commands/legacy-story-pr.js +1 -0
- package/packages/client/dist/commands/planning-diagnosis.d.ts +4 -0
- package/packages/client/dist/commands/planning-diagnosis.js +1 -0
- package/packages/client/dist/commands/planning-generation.d.ts +2 -0
- package/packages/client/dist/commands/planning-generation.js +1 -0
- package/packages/client/dist/commands/planning-research.d.ts +3 -0
- package/packages/client/dist/commands/planning-research.js +1 -0
- package/packages/client/dist/commands/refresh-memory.d.ts +10 -0
- package/packages/client/dist/commands/refresh-memory.js +3 -1
- package/packages/client/dist/commands/story-checkpoint.d.ts +1 -1
- package/packages/client/dist/commands/story-checkpoint.js +1 -1
- package/packages/client/dist/config/profile-directory.d.ts +2 -0
- package/packages/client/dist/config/profile-directory.js +1 -0
- package/packages/client/dist/config/secure-config.js +5 -5
- package/packages/client/dist/continuity/runner-bootstrap-policy.d.ts +1 -1
- package/packages/client/dist/continuity/runner-bootstrap-policy.js +1 -1
- package/packages/client/dist/generated/command-registry.generated.d.ts +11 -11
- package/packages/client/dist/generated/command-registry.generated.js +1 -1
- package/packages/client/dist/generated/public-projections.generated.d.ts +20 -20
- package/packages/client/dist/generated/public-projections.generated.js +1 -1
- package/packages/client/dist/git/direct-yolo-checkpoint.d.ts +9 -0
- package/packages/client/dist/git/direct-yolo-checkpoint.js +4 -4
- package/packages/client/dist/git/git-lifecycle-step-ids.d.ts +5 -0
- package/packages/client/dist/git/git-lifecycle-step-ids.js +1 -1
- package/packages/client/dist/git/git-lifecycle-store.d.ts +16 -0
- package/packages/client/dist/git/git-lifecycle-store.js +9 -4
- package/packages/client/dist/git/legacy-story-branch-checkpoint.d.ts +38 -0
- package/packages/client/dist/git/legacy-story-branch-checkpoint.js +9 -0
- package/packages/client/dist/git/legacy-story-branch-setup.d.ts +56 -0
- package/packages/client/dist/git/legacy-story-branch-setup.js +4 -0
- package/packages/client/dist/git/legacy-story-pr.d.ts +514 -0
- package/packages/client/dist/git/legacy-story-pr.js +62 -0
- package/packages/client/dist/git/secure-filesystem-boundary.d.ts +2 -0
- package/packages/client/dist/git/secure-filesystem-boundary.js +34 -7
- package/packages/client/dist/machine/fingerprint.js +2 -2
- package/packages/client/dist/memory/project-memory-writer.js +17 -17
- package/packages/client/dist/memory/shared-project-memory-types.d.ts +23 -13
- package/packages/client/dist/memory/shared-project-memory-types.js +2 -2
- package/packages/client/dist/migrations/state-json.d.ts +23 -1
- package/packages/client/dist/migrations/state-json.js +4 -4
- package/packages/client/dist/private-execution/delivery.d.ts +131 -3
- package/packages/client/dist/private-execution/delivery.js +2 -2
- package/packages/client/dist/private-execution/isolated-admission.d.ts +28 -1
- package/packages/client/dist/private-execution/isolated-admission.js +11 -2
- package/packages/client/dist/private-execution/isolated-session.js +2 -2
- package/packages/client/dist/private-execution/isolated-workspace.d.ts +8 -0
- package/packages/client/dist/private-execution/isolated-workspace.js +1 -1
- package/packages/client/dist/private-execution/pact-consumer-runtime.d.ts +19 -0
- package/packages/client/dist/private-execution/pact-consumer-runtime.js +3 -0
- package/packages/client/dist/private-execution/pact-test-source.d.ts +9 -0
- package/packages/client/dist/private-execution/pact-test-source.js +1 -0
- package/packages/client/dist/private-execution/pact-toolchain.d.ts +37 -0
- package/packages/client/dist/private-execution/pact-toolchain.js +3 -0
- package/packages/client/dist/private-execution/pact-write-set.d.ts +24 -0
- package/packages/client/dist/private-execution/pact-write-set.js +1 -0
- package/packages/client/dist/private-execution/planning-diagnosis-checkpoint.d.ts +38 -0
- package/packages/client/dist/private-execution/planning-diagnosis-checkpoint.js +5 -0
- package/packages/client/dist/private-execution/planning-generation-checkpoint.d.ts +34 -0
- package/packages/client/dist/private-execution/planning-generation-checkpoint.js +4 -0
- package/packages/client/dist/private-execution/planning-research-checkpoint.d.ts +38 -0
- package/packages/client/dist/private-execution/planning-research-checkpoint.js +4 -0
- package/packages/client/dist/private-execution/ux-source-validation.d.ts +2 -0
- package/packages/client/dist/private-execution/ux-source-validation.js +1 -0
- package/packages/client/dist/private-execution/ux-write-set.d.ts +30 -0
- package/packages/client/dist/private-execution/ux-write-set.js +2 -0
- package/packages/client/dist/resolvers/remote-resolver.d.ts +5 -22
- package/packages/client/dist/resolvers/remote-resolver.js +1 -1
- package/packages/client/dist/runner/project-identity.js +1 -1
- package/packages/client/dist/runner/scheduler.d.ts +20 -0
- package/packages/client/dist/runner/scheduler.js +7 -7
- package/packages/client/dist/state/project-state-snapshot.js +1 -1
- package/packages/client/dist/yolo/change-evidence-collector.d.ts +8 -0
- package/packages/client/dist/yolo/change-evidence-collector.js +1 -1
- package/packages/client/dist/yolo/spec-envelope-collector.d.ts +2 -0
- package/packages/client/dist/yolo/spec-envelope-collector.js +3 -3
- package/packages/client/dist/yoloop/invoke-hooks.js +7 -7
- package/packages/client/dist/yoloop/shared-yoloop-types.d.ts +15 -1
- package/packages/client/dist/yoloop/yoloop-client-state-store.d.ts +5 -1
- package/packages/client/dist/yoloop/yoloop-client-state-store.js +1 -1
- package/packages/shared/dist/generated/command-registry.generated.js +12 -10
- package/packages/shared/dist/generated/invocation-schema.generated.js +14 -6
- package/packages/shared/dist/generated/public-projections.generated.js +18 -18
- package/packages/shared/dist/invocation/index.d.ts +1 -1
- package/packages/shared/dist/merge-readiness/c12-remote-observation.js +80 -0
- package/packages/shared/dist/planning/diagnosis-state.js +143 -0
- package/packages/shared/dist/yoloop/branch-unit.js +23 -1
- package/targets-stubs/antigravity/gemini.md +1 -1
- package/targets-stubs/antigravity/skill/SKILL.md +1 -1
- package/targets-stubs/claude-code/neocortex-root.agent.yaml +1 -1
- package/targets-stubs/claude-code/neocortex-root.md +2 -2
- package/targets-stubs/claude-code/neocortex.agent.yaml +1 -1
- package/targets-stubs/claude-code/neocortex.md +2 -2
- package/targets-stubs/codex/AGENTS.md +1 -1
- package/targets-stubs/cursor/agent.md +2 -2
- package/targets-stubs/gemini-cli/agent.md +2 -2
- package/targets-stubs/opencode/neocortex-root.md +1 -1
- package/targets-stubs/vscode/neocortex.agent.md +2 -2
|
@@ -46,17 +46,121 @@ export interface PrivateExecutionPublicEpicClaimBindingV3 {
|
|
|
46
46
|
readonly schemaVersion: 3;
|
|
47
47
|
readonly authorityKind: 'epic-claim';
|
|
48
48
|
readonly projectId: string;
|
|
49
|
-
readonly commandId: 'create-epic';
|
|
49
|
+
readonly commandId: 'create-epic' | 'idea-diagnose';
|
|
50
50
|
readonly stepId: string;
|
|
51
51
|
readonly claimId: string;
|
|
52
52
|
readonly epicId: string;
|
|
53
|
+
readonly writeSetId?: 'idea-diagnosis-v1';
|
|
53
54
|
readonly stateSnapshotSha256: string;
|
|
54
55
|
readonly generationId: string;
|
|
55
56
|
readonly inputSha256: string;
|
|
56
57
|
readonly hostKind: 'codex-cli';
|
|
57
58
|
readonly hostVersion: string;
|
|
58
59
|
}
|
|
59
|
-
export
|
|
60
|
+
export interface PrivateExecutionPublicProjectStepBindingV4 {
|
|
61
|
+
readonly schemaVersion: 4;
|
|
62
|
+
readonly authorityKind: 'project-snapshot';
|
|
63
|
+
readonly projectId: string;
|
|
64
|
+
readonly commandId: 'sync-openapi' | 'tech-debt';
|
|
65
|
+
readonly stepId: string;
|
|
66
|
+
readonly writeSetId: 'sync-openapi-contract-v1' | 'tech-debt-registry-v1';
|
|
67
|
+
readonly stateSnapshotSha256: string;
|
|
68
|
+
readonly generationId: string;
|
|
69
|
+
readonly inputSha256: string;
|
|
70
|
+
readonly hostKind: 'codex-cli';
|
|
71
|
+
readonly hostVersion: string;
|
|
72
|
+
}
|
|
73
|
+
export interface PrivateExecutionPublicArchitectureStageBindingV5 {
|
|
74
|
+
readonly schemaVersion: 5;
|
|
75
|
+
readonly authorityKind: 'architecture-stage';
|
|
76
|
+
readonly projectId: string;
|
|
77
|
+
readonly commandId: 'arch-prd' | 'arch-architecture' | 'arch-fitness-functions' | 'arch-api-contracts' | 'arch-api-integrations' | 'arch-database' | 'arch-security' | 'arch-design-system' | 'arch-performance' | 'arch-testing' | 'arch-infrastructure' | 'arch-review' | 'update-memory';
|
|
78
|
+
readonly stepId: string;
|
|
79
|
+
readonly targetEpicId: string;
|
|
80
|
+
readonly graphRevision: string;
|
|
81
|
+
readonly writeSetId: 'arch-prd-docs-v1' | 'arch-architecture-doc-v1' | 'arch-fitness-tools-v1' | 'arch-api-contracts-docs-v1' | 'arch-api-integrations-doc-v1' | 'arch-database-doc-v1' | 'arch-security-doc-v1' | 'arch-design-system-doc-v1' | 'arch-performance-doc-v1' | 'arch-testing-doc-v1' | 'arch-infrastructure-doc-v1' | 'arch-review-doc-v1' | 'arch-memory-canonical-v1';
|
|
82
|
+
readonly stateSnapshotSha256: string;
|
|
83
|
+
readonly generationId: string;
|
|
84
|
+
readonly inputSha256: string;
|
|
85
|
+
readonly hostKind: 'codex-cli';
|
|
86
|
+
readonly hostVersion: string;
|
|
87
|
+
}
|
|
88
|
+
export interface PrivateExecutionPublicPactStageBindingV6 {
|
|
89
|
+
readonly schemaVersion: 6;
|
|
90
|
+
readonly authorityKind: 'pact-stage';
|
|
91
|
+
readonly projectId: string;
|
|
92
|
+
readonly commandId: 'generate-pacts';
|
|
93
|
+
readonly stepId: string;
|
|
94
|
+
readonly targetEpicId: string;
|
|
95
|
+
readonly graphRevision: string;
|
|
96
|
+
readonly answersSha256: string;
|
|
97
|
+
readonly specSha256: string;
|
|
98
|
+
readonly pathsSha256: string;
|
|
99
|
+
readonly endpointCount: number;
|
|
100
|
+
readonly pathCount: number;
|
|
101
|
+
readonly stateSnapshotSha256: string;
|
|
102
|
+
readonly generationId: string;
|
|
103
|
+
readonly inputSha256: string;
|
|
104
|
+
readonly hostKind: 'codex-cli';
|
|
105
|
+
readonly hostVersion: string;
|
|
106
|
+
}
|
|
107
|
+
export interface PrivateExecutionPublicUxStageBindingV7 {
|
|
108
|
+
readonly schemaVersion: 7;
|
|
109
|
+
readonly authorityKind: 'ux-stage';
|
|
110
|
+
readonly projectId: string;
|
|
111
|
+
readonly commandId: 'arch-ux-design';
|
|
112
|
+
readonly stepId: string;
|
|
113
|
+
readonly targetEpicId: string;
|
|
114
|
+
readonly graphRevision: string;
|
|
115
|
+
readonly adapterId: 'storybook-react-vite' | 'storybook-nextjs-vite';
|
|
116
|
+
readonly authoritySha256: string;
|
|
117
|
+
readonly pathsSha256: string;
|
|
118
|
+
readonly screenCount: number;
|
|
119
|
+
readonly pathCount: number;
|
|
120
|
+
readonly stateSnapshotSha256: string;
|
|
121
|
+
readonly generationId: string;
|
|
122
|
+
readonly inputSha256: string;
|
|
123
|
+
readonly hostKind: 'codex-cli';
|
|
124
|
+
readonly hostVersion: string;
|
|
125
|
+
}
|
|
126
|
+
export interface PrivateExecutionPublicPlanningStageBindingV8 {
|
|
127
|
+
readonly schemaVersion: 8;
|
|
128
|
+
readonly authorityKind: 'planning-stage';
|
|
129
|
+
readonly projectId: string;
|
|
130
|
+
readonly commandId: 'idea-research';
|
|
131
|
+
readonly stepId: string;
|
|
132
|
+
readonly claimId: string;
|
|
133
|
+
readonly epicId: string;
|
|
134
|
+
readonly diagnosisReceiptId: string;
|
|
135
|
+
readonly intakeRevision: string;
|
|
136
|
+
readonly physicalAcceptanceReceiptId: string;
|
|
137
|
+
readonly writeSetId: 'idea-research-v1';
|
|
138
|
+
readonly stateSnapshotSha256: string;
|
|
139
|
+
readonly generationId: string;
|
|
140
|
+
readonly inputSha256: string;
|
|
141
|
+
readonly hostKind: 'codex-cli';
|
|
142
|
+
readonly hostVersion: string;
|
|
143
|
+
}
|
|
144
|
+
export interface PrivateExecutionPublicPlanningGenerationBindingV9 {
|
|
145
|
+
readonly schemaVersion: 9;
|
|
146
|
+
readonly authorityKind: 'planning-generation';
|
|
147
|
+
readonly projectId: string;
|
|
148
|
+
readonly commandId: 'generate-epic';
|
|
149
|
+
readonly stepId: string;
|
|
150
|
+
readonly claimId: string;
|
|
151
|
+
readonly epicId: string;
|
|
152
|
+
readonly diagnosisReceiptId: string;
|
|
153
|
+
readonly researchReceiptId: string;
|
|
154
|
+
readonly intakeRevision: string;
|
|
155
|
+
readonly physicalAcceptanceReceiptId: string;
|
|
156
|
+
readonly writeSetId: 'generate-epic-v1';
|
|
157
|
+
readonly stateSnapshotSha256: string;
|
|
158
|
+
readonly generationId: string;
|
|
159
|
+
readonly inputSha256: string;
|
|
160
|
+
readonly hostKind: 'codex-cli';
|
|
161
|
+
readonly hostVersion: string;
|
|
162
|
+
}
|
|
163
|
+
export type PrivateExecutionPublicBinding = PrivateExecutionPublicBindingV1 | PrivateExecutionPublicStepBindingV2 | PrivateExecutionPublicEpicClaimBindingV3 | PrivateExecutionPublicProjectStepBindingV4 | PrivateExecutionPublicArchitectureStageBindingV5 | PrivateExecutionPublicPactStageBindingV6 | PrivateExecutionPublicUxStageBindingV7 | PrivateExecutionPublicPlanningStageBindingV8 | PrivateExecutionPublicPlanningGenerationBindingV9;
|
|
60
164
|
export interface PrivateExecutionDescriptorV1 {
|
|
61
165
|
readonly schemaVersion: 1;
|
|
62
166
|
readonly leaseId: string;
|
|
@@ -75,7 +179,31 @@ export interface PrivateExecutionDescriptorV3 extends Omit<PrivateExecutionDescr
|
|
|
75
179
|
readonly schemaVersion: 3;
|
|
76
180
|
readonly binding: PrivateExecutionPublicEpicClaimBindingV3;
|
|
77
181
|
}
|
|
78
|
-
export
|
|
182
|
+
export interface PrivateExecutionDescriptorV4 extends Omit<PrivateExecutionDescriptorV1, 'schemaVersion' | 'binding'> {
|
|
183
|
+
readonly schemaVersion: 4;
|
|
184
|
+
readonly binding: PrivateExecutionPublicProjectStepBindingV4;
|
|
185
|
+
}
|
|
186
|
+
export interface PrivateExecutionDescriptorV5 extends Omit<PrivateExecutionDescriptorV1, 'schemaVersion' | 'binding'> {
|
|
187
|
+
readonly schemaVersion: 5;
|
|
188
|
+
readonly binding: PrivateExecutionPublicArchitectureStageBindingV5;
|
|
189
|
+
}
|
|
190
|
+
export interface PrivateExecutionDescriptorV6 extends Omit<PrivateExecutionDescriptorV1, 'schemaVersion' | 'binding'> {
|
|
191
|
+
readonly schemaVersion: 6;
|
|
192
|
+
readonly binding: PrivateExecutionPublicPactStageBindingV6;
|
|
193
|
+
}
|
|
194
|
+
export interface PrivateExecutionDescriptorV7 extends Omit<PrivateExecutionDescriptorV1, 'schemaVersion' | 'binding'> {
|
|
195
|
+
readonly schemaVersion: 7;
|
|
196
|
+
readonly binding: PrivateExecutionPublicUxStageBindingV7;
|
|
197
|
+
}
|
|
198
|
+
export interface PrivateExecutionDescriptorV8 extends Omit<PrivateExecutionDescriptorV1, 'schemaVersion' | 'binding'> {
|
|
199
|
+
readonly schemaVersion: 8;
|
|
200
|
+
readonly binding: PrivateExecutionPublicPlanningStageBindingV8;
|
|
201
|
+
}
|
|
202
|
+
export interface PrivateExecutionDescriptorV9 extends Omit<PrivateExecutionDescriptorV1, 'schemaVersion' | 'binding'> {
|
|
203
|
+
readonly schemaVersion: 9;
|
|
204
|
+
readonly binding: PrivateExecutionPublicPlanningGenerationBindingV9;
|
|
205
|
+
}
|
|
206
|
+
export type PrivateExecutionDescriptor = PrivateExecutionDescriptorV1 | PrivateExecutionDescriptorV2 | PrivateExecutionDescriptorV3 | PrivateExecutionDescriptorV4 | PrivateExecutionDescriptorV5 | PrivateExecutionDescriptorV6 | PrivateExecutionDescriptorV7 | PrivateExecutionDescriptorV8 | PrivateExecutionDescriptorV9;
|
|
79
207
|
export declare function privateExecutionStateSnapshotSha256(stateSnapshot: unknown): string;
|
|
80
208
|
export declare function parsePrivateExecutionDescriptor(value: unknown, expected?: Readonly<Record<string, unknown>>): PrivateExecutionDescriptor;
|
|
81
209
|
export declare function verifyPrivateExecutionMaterial(descriptor: PrivateExecutionDescriptor, material: unknown, nowMs?: number): string;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{createHash as
|
|
1
|
+
import{createHash as g}from"node:crypto";const u=`# Neocortex private execution pending
|
|
2
2
|
|
|
3
|
-
The authorized Codex CLI executor must consume the one-time delivery and produce a physical receipt.`;function l(r){if(!r||typeof r!="object"||Array.isArray(r))return!1;const o=r,t=o.metadata;if(Object.keys(o).sort().join(",")!=="instructions,metadata"||o.instructions!==g||!t||typeof t!="object"||Array.isArray(t))return!1;const e=t,s=e.privateExecution;let i;try{i=u(s)}catch{return!1}if(i.schemaVersion===2)return Object.keys(e).sort().join(",")===["mode","storyId","stepId","resolvedTrigger","privateExecution"].sort().join(",")&&(e.mode==="step"&&e.resolvedTrigger==="research"&&i.binding.commandId==="research"||e.mode==="pipeline"&&e.resolvedTrigger==="exec"&&i.binding.commandId==="exec")&&e.storyId===i.binding.storyId&&e.stepId===i.binding.stepId;if(i.schemaVersion===3){const y=e.epicClaim,d=y&&typeof y=="object"&&!Array.isArray(y)?y:void 0;return Object.keys(e).sort().join(",")===["mode","stepId","resolvedTrigger","privateExecution","epicClaim"].sort().join(",")&&e.mode==="create-epic"&&e.resolvedTrigger==="create-epic"&&e.stepId===i.binding.stepId&&i.binding.commandId==="create-epic"&&!!d&&Object.keys(d).sort().join(",")===["schemaVersion","claimId","epicId","outcome","publicSafe"].sort().join(",")&&d.schemaVersion===1&&d.outcome==="reserved"&&d.publicSafe===!0&&d.claimId===i.binding.claimId&&d.epicId===i.binding.epicId}const a=e.privateExecutionRootAction,c=["mode","storyId","stepId","resolvedTrigger","gitLifecycleGraphAuthority","privateExecution",...a===void 0?[]:["privateExecutionRootAction"]],h=e.gitLifecycleGraphAuthority,p=h&&typeof h=="object"&&!Array.isArray(h)?h:void 0,n=a&&typeof a=="object"&&!Array.isArray(a)?a:void 0;return Object.keys(e).sort().join(",")===c.sort().join(",")&&e.mode==="yolo"&&e.resolvedTrigger==="yolo"&&typeof e.storyId=="string"&&typeof e.stepId=="string"&&!!p&&p.storyId===e.storyId&&p.graphRevision===i.binding.graphRevision&&i.binding.commandId==="yolo"&&i.binding.stepId===e.stepId&&(a===void 0||!!n&&Object.keys(n).sort().join(",")===["schemaVersion","action","storyId","executionBranch","graphRevision","publicSafe",...n.action==="checkpoint-epic-story"?["stepId"]:[]].sort().join(",")&&n.schemaVersion===1&&(n.action==="prepare-epic-checkout"||n.action==="checkpoint-epic-story")&&(n.action!=="checkpoint-epic-story"||n.stepId===e.stepId)&&n.publicSafe===!0&&n.storyId===e.storyId&&n.storyId===p.storyId&&n.executionBranch===p.executionBranch&&n.graphRevision===p.graphRevision)}function b(r){return m("sha256").update("private-step-state-v1\0").update(JSON.stringify(r)).digest("hex")}function u(r,o){if(!r||typeof r!="object"||Array.isArray(r))throw new Error("private-execution-descriptor-invalid");const t=r,e=t.binding,s=t.schemaVersion===2||t.schemaVersion===3,i=s?["schemaVersion","authorityKind","projectId","commandId","stepId",...t.schemaVersion===3?["claimId","epicId"]:["storyId"],"stateSnapshotSha256","generationId","inputSha256","hostKind","hostVersion"]:["commandId","generationId","graphRevision","hostKind","hostVersion","inputSha256","projectId","stepId"];if(Object.keys(t).sort().join(",")!==["schemaVersion","leaseId","materialSha256","byteLength","expiresAt","delivery","publicSafe","binding"].sort().join(",")||t.schemaVersion!==1&&!s||t.delivery!=="private-one-time"||t.publicSafe!==!0||typeof t.leaseId!="string"||!/^px_[a-f0-9]{48}$/.test(t.leaseId)||typeof t.materialSha256!="string"||!/^[a-f0-9]{64}$/.test(t.materialSha256)||!Number.isSafeInteger(t.byteLength)||t.byteLength<1||t.byteLength>256*1024||typeof t.expiresAt!="string"||!Number.isFinite(Date.parse(t.expiresAt))||!e||Object.keys(e).sort().join(",")!==i.sort().join(",")||Object.entries(e).some(([a,c])=>a!=="schemaVersion"&&(typeof c!="string"||c.length<1||c.length>256))||!/^[a-f0-9]{64}$/.test(String(e.inputSha256))||e.hostKind!=="codex-cli"||s&&!/^[a-f0-9]{64}$/.test(String(e.stateSnapshotSha256))||t.schemaVersion===2&&(e.schemaVersion!==2||e.authorityKind!=="state-snapshot"||!/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/.test(String(e.storyId)))||t.schemaVersion===3&&(e.schemaVersion!==3||e.authorityKind!=="epic-claim"||e.commandId!=="create-epic"||!/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/.test(String(e.claimId))||!/^P[1-9][0-9]*$/.test(String(e.epicId)))||o&&Object.entries(o).some(([a,c])=>e[a]!==c))throw new Error("private-execution-descriptor-invalid");return t}function I(r,o,t=Date.now()){if(typeof o!="string"||t>=Date.parse(r.expiresAt)||Buffer.byteLength(o,"utf8")!==r.byteLength||m("sha256").update(o,"utf8").digest("hex")!==r.materialSha256)throw new Error("private-execution-material-invalid");return o}async function x(r,o,t,e=Date.now()){const s=u(r,o);if(e>=Date.parse(s.expiresAt))throw new Error("private-execution-material-expired");const i=await t({leaseId:s.leaseId,...s.binding});if(!i||typeof i!="object"||Array.isArray(i)||Object.keys(i).sort().join(",")!=="material,schemaVersion"||i.schemaVersion!==1)throw new Error("private-execution-delivery-invalid");return I(s,i.material,Math.max(e,Date.now()))}export{g as PRIVATE_EXECUTION_PUBLIC_INSTRUCTION_V1,x as consumePrivateExecutionDelivery,l as isPrivateExecutionPublicEnvelope,u as parsePrivateExecutionDescriptor,b as privateExecutionStateSnapshotSha256,I as verifyPrivateExecutionMaterial};
|
|
3
|
+
The authorized Codex CLI executor must consume the one-time delivery and produce a physical receipt.`;function b(r){if(!r||typeof r!="object"||Array.isArray(r))return!1;const a=r,i=a.metadata;if(Object.keys(a).sort().join(",")!=="instructions,metadata"||a.instructions!==u||!i||typeof i!="object"||Array.isArray(i))return!1;const e=i,s=e.privateExecution;let t;try{t=I(s)}catch{return!1}if(t.schemaVersion===2)return Object.keys(e).sort().join(",")===["mode","storyId","stepId","resolvedTrigger","privateExecution"].sort().join(",")&&(e.mode==="step"&&(e.resolvedTrigger==="research"||e.resolvedTrigger==="write-spec"||e.resolvedTrigger==="create-tasks"||e.resolvedTrigger==="implement")&&t.binding.commandId===e.resolvedTrigger||e.mode==="pipeline"&&e.resolvedTrigger==="exec"&&t.binding.commandId==="exec")&&e.storyId===t.binding.storyId&&e.stepId===t.binding.stepId;if(t.schemaVersion===3){const h=e.epicClaim,c=h&&typeof h=="object"&&!Array.isArray(h)?h:void 0;return Object.keys(e).sort().join(",")===["mode","stepId","resolvedTrigger","privateExecution","epicClaim"].sort().join(",")&&(e.mode==="create-epic"&&e.resolvedTrigger==="create-epic"&&t.binding.commandId==="create-epic"&&t.binding.writeSetId===void 0||e.mode==="step"&&e.resolvedTrigger==="idea-diagnose"&&t.binding.commandId==="idea-diagnose"&&t.binding.writeSetId==="idea-diagnosis-v1")&&e.stepId===t.binding.stepId&&!!c&&Object.keys(c).sort().join(",")===["schemaVersion","claimId","epicId","outcome","publicSafe"].sort().join(",")&&c.schemaVersion===1&&c.outcome==="reserved"&&c.publicSafe===!0&&c.claimId===t.binding.claimId&&c.epicId===t.binding.epicId}if(t.schemaVersion===4){const h=e.mode==="utility"&&e.resolvedTrigger==="sync-openapi"&&t.binding.commandId==="sync-openapi"&&t.binding.writeSetId==="sync-openapi-contract-v1"||e.mode==="tech-debt"&&e.resolvedTrigger==="tech-debt"&&t.binding.commandId==="tech-debt"&&t.binding.writeSetId==="tech-debt-registry-v1";return Object.keys(e).sort().join(",")===["mode","stepId","resolvedTrigger","privateExecution"].sort().join(",")&&e.stepId===t.binding.stepId&&h}if(t.schemaVersion===5)return Object.keys(e).sort().join(",")===["mode","stepId","resolvedTrigger","privateExecution"].sort().join(",")&&e.mode==="step"&&e.resolvedTrigger===t.binding.commandId&&e.stepId===t.binding.stepId&&(t.binding.commandId==="arch-prd"&&t.binding.writeSetId==="arch-prd-docs-v1"||t.binding.commandId==="arch-architecture"&&t.binding.writeSetId==="arch-architecture-doc-v1"||t.binding.commandId==="arch-fitness-functions"&&t.binding.writeSetId==="arch-fitness-tools-v1"||t.binding.commandId==="arch-api-contracts"&&t.binding.writeSetId==="arch-api-contracts-docs-v1"||t.binding.commandId==="arch-api-integrations"&&t.binding.writeSetId==="arch-api-integrations-doc-v1"||t.binding.commandId==="arch-database"&&t.binding.writeSetId==="arch-database-doc-v1"||t.binding.commandId==="arch-security"&&t.binding.writeSetId==="arch-security-doc-v1"||t.binding.commandId==="arch-design-system"&&t.binding.writeSetId==="arch-design-system-doc-v1"||t.binding.commandId==="arch-performance"&&t.binding.writeSetId==="arch-performance-doc-v1"||t.binding.commandId==="arch-testing"&&t.binding.writeSetId==="arch-testing-doc-v1"||t.binding.commandId==="arch-infrastructure"&&t.binding.writeSetId==="arch-infrastructure-doc-v1"||t.binding.commandId==="arch-review"&&t.binding.writeSetId==="arch-review-doc-v1"||t.binding.commandId==="update-memory"&&t.binding.writeSetId==="arch-memory-canonical-v1");if(t.schemaVersion===6)return Object.keys(e).sort().join(",")===["mode","stepId","resolvedTrigger","privateExecution"].sort().join(",")&&e.mode==="step"&&e.resolvedTrigger==="generate-pacts"&&e.stepId===t.binding.stepId;if(t.schemaVersion===7)return Object.keys(e).sort().join(",")===["mode","stepId","resolvedTrigger","privateExecution"].sort().join(",")&&e.mode==="step"&&e.resolvedTrigger==="arch-ux-design"&&e.stepId===t.binding.stepId;if(t.schemaVersion===8)return Object.keys(e).sort().join(",")===["mode","stepId","resolvedTrigger","privateExecution"].sort().join(",")&&e.mode==="step"&&e.resolvedTrigger==="idea-research"&&e.stepId===t.binding.stepId&&t.binding.commandId==="idea-research"&&t.binding.writeSetId==="idea-research-v1";if(t.schemaVersion===9)return Object.keys(e).sort().join(",")===["mode","stepId","resolvedTrigger","privateExecution"].sort().join(",")&&e.mode==="step"&&e.resolvedTrigger==="generate-epic"&&e.stepId===t.binding.stepId&&t.binding.commandId==="generate-epic"&&t.binding.writeSetId==="generate-epic-v1";const n=e.privateExecutionRootAction,d=["mode","storyId","stepId","resolvedTrigger","gitLifecycleGraphAuthority","privateExecution",...n===void 0?[]:["privateExecutionRootAction"]],m=e.gitLifecycleGraphAuthority,p=m&&typeof m=="object"&&!Array.isArray(m)?m:void 0,o=n&&typeof n=="object"&&!Array.isArray(n)?n:void 0;return Object.keys(e).sort().join(",")===d.sort().join(",")&&e.mode==="yolo"&&e.resolvedTrigger==="yolo"&&typeof e.storyId=="string"&&typeof e.stepId=="string"&&!!p&&p.storyId===e.storyId&&p.graphRevision===t.binding.graphRevision&&t.binding.commandId==="yolo"&&t.binding.stepId===e.stepId&&(n===void 0||!!o&&Object.keys(o).sort().join(",")===["schemaVersion","action","storyId","executionBranch","graphRevision","publicSafe",...o.action==="checkpoint-epic-story"?["stepId"]:[]].sort().join(",")&&o.schemaVersion===1&&(o.action==="prepare-epic-checkout"||o.action==="checkpoint-epic-story")&&(o.action!=="checkpoint-epic-story"||o.stepId===e.stepId)&&o.publicSafe===!0&&o.storyId===e.storyId&&o.storyId===p.storyId&&o.executionBranch===p.executionBranch&&o.graphRevision===p.graphRevision)}function f(r){return g("sha256").update("private-step-state-v1\0").update(JSON.stringify(r)).digest("hex")}function I(r,a){if(!r||typeof r!="object"||Array.isArray(r))throw new Error("private-execution-descriptor-invalid");const i=r,e=i.binding,s=i.schemaVersion===2||i.schemaVersion===3||i.schemaVersion===4||i.schemaVersion===5||i.schemaVersion===6||i.schemaVersion===7||i.schemaVersion===8||i.schemaVersion===9,t=s?["schemaVersion","authorityKind","projectId","commandId","stepId",...i.schemaVersion===3?["claimId","epicId",...e?.commandId==="idea-diagnose"?["writeSetId"]:[]]:i.schemaVersion===4?["writeSetId"]:i.schemaVersion===5?["targetEpicId","graphRevision","writeSetId"]:i.schemaVersion===6?["targetEpicId","graphRevision","answersSha256","specSha256","pathsSha256","endpointCount","pathCount"]:i.schemaVersion===7?["targetEpicId","graphRevision","adapterId","authoritySha256","pathsSha256","screenCount","pathCount"]:i.schemaVersion===8?["claimId","epicId","diagnosisReceiptId","intakeRevision","physicalAcceptanceReceiptId","writeSetId"]:i.schemaVersion===9?["claimId","epicId","diagnosisReceiptId","researchReceiptId","intakeRevision","physicalAcceptanceReceiptId","writeSetId"]:["storyId"],"stateSnapshotSha256","generationId","inputSha256","hostKind","hostVersion"]:["commandId","generationId","graphRevision","hostKind","hostVersion","inputSha256","projectId","stepId"];if(Object.keys(i).sort().join(",")!==["schemaVersion","leaseId","materialSha256","byteLength","expiresAt","delivery","publicSafe","binding"].sort().join(",")||i.schemaVersion!==1&&!s||i.delivery!=="private-one-time"||i.publicSafe!==!0||typeof i.leaseId!="string"||!/^px_[a-f0-9]{48}$/.test(i.leaseId)||typeof i.materialSha256!="string"||!/^[a-f0-9]{64}$/.test(i.materialSha256)||!Number.isSafeInteger(i.byteLength)||i.byteLength<1||i.byteLength>256*1024||typeof i.expiresAt!="string"||!Number.isFinite(Date.parse(i.expiresAt))||!e||Object.keys(e).sort().join(",")!==t.sort().join(",")||Object.entries(e).some(([n,d])=>n!=="schemaVersion"&&n!=="endpointCount"&&n!=="screenCount"&&n!=="pathCount"&&(typeof d!="string"||d.length<1||d.length>256))||!/^[a-f0-9]{64}$/.test(String(e.inputSha256))||e.hostKind!=="codex-cli"||s&&!/^[a-f0-9]{64}$/.test(String(e.stateSnapshotSha256))||i.schemaVersion===2&&(e.schemaVersion!==2||e.authorityKind!=="state-snapshot"||!/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/.test(String(e.storyId)))||i.schemaVersion===3&&(e.schemaVersion!==3||e.authorityKind!=="epic-claim"||!(e.commandId==="create-epic"&&e.writeSetId===void 0||e.commandId==="idea-diagnose"&&e.writeSetId==="idea-diagnosis-v1")||!/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/.test(String(e.claimId))||!/^P[1-9][0-9]*$/.test(String(e.epicId)))||i.schemaVersion===4&&(e.schemaVersion!==4||e.authorityKind!=="project-snapshot"||!(e.commandId==="sync-openapi"&&e.writeSetId==="sync-openapi-contract-v1"||e.commandId==="tech-debt"&&e.writeSetId==="tech-debt-registry-v1"))||i.schemaVersion===5&&(e.schemaVersion!==5||e.authorityKind!=="architecture-stage"||!(e.commandId==="arch-prd"&&e.writeSetId==="arch-prd-docs-v1"||e.commandId==="arch-architecture"&&e.writeSetId==="arch-architecture-doc-v1"||e.commandId==="arch-fitness-functions"&&e.writeSetId==="arch-fitness-tools-v1"||e.commandId==="arch-api-contracts"&&e.writeSetId==="arch-api-contracts-docs-v1"||e.commandId==="arch-api-integrations"&&e.writeSetId==="arch-api-integrations-doc-v1"||e.commandId==="arch-database"&&e.writeSetId==="arch-database-doc-v1"||e.commandId==="arch-security"&&e.writeSetId==="arch-security-doc-v1"||e.commandId==="arch-design-system"&&e.writeSetId==="arch-design-system-doc-v1"||e.commandId==="arch-performance"&&e.writeSetId==="arch-performance-doc-v1"||e.commandId==="arch-testing"&&e.writeSetId==="arch-testing-doc-v1"||e.commandId==="arch-infrastructure"&&e.writeSetId==="arch-infrastructure-doc-v1"||e.commandId==="arch-review"&&e.writeSetId==="arch-review-doc-v1"||e.commandId==="update-memory"&&e.writeSetId==="arch-memory-canonical-v1")||!/^P[1-9][0-9]{0,11}$/.test(String(e.targetEpicId))||!/^[a-f0-9]{64}$/.test(String(e.graphRevision)))||i.schemaVersion===6&&(e.schemaVersion!==6||e.authorityKind!=="pact-stage"||e.commandId!=="generate-pacts"||!/^P[1-9][0-9]{0,11}$/.test(String(e.targetEpicId))||!/^[a-f0-9]{64}$/.test(String(e.graphRevision))||!/^[a-f0-9]{64}$/.test(String(e.answersSha256))||!/^[a-f0-9]{64}$/.test(String(e.specSha256))||!/^[a-f0-9]{64}$/.test(String(e.pathsSha256))||!Number.isSafeInteger(e.endpointCount)||e.endpointCount<1||e.endpointCount>256||!Number.isSafeInteger(e.pathCount)||e.pathCount<e.endpointCount||e.pathCount>e.endpointCount+1)||i.schemaVersion===7&&(e.schemaVersion!==7||e.authorityKind!=="ux-stage"||e.commandId!=="arch-ux-design"||!/^P[1-9][0-9]{0,11}$/.test(String(e.targetEpicId))||!/^[a-f0-9]{64}$/.test(String(e.graphRevision))||!["storybook-react-vite","storybook-nextjs-vite"].includes(String(e.adapterId))||!/^[a-f0-9]{64}$/.test(String(e.authoritySha256))||!/^[a-f0-9]{64}$/.test(String(e.pathsSha256))||!Number.isSafeInteger(e.screenCount)||e.screenCount<1||e.screenCount>48||!Number.isSafeInteger(e.pathCount)||e.pathCount!==e.screenCount*6+3)||i.schemaVersion===8&&(e.schemaVersion!==8||e.authorityKind!=="planning-stage"||e.commandId!=="idea-research"||e.writeSetId!=="idea-research-v1"||!/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/.test(String(e.claimId))||!/^P[1-9][0-9]{0,11}$/.test(String(e.epicId))||[e.diagnosisReceiptId,e.intakeRevision,e.physicalAcceptanceReceiptId].some(n=>!/^[a-f0-9]{64}$/.test(String(n))))||i.schemaVersion===9&&(e.schemaVersion!==9||e.authorityKind!=="planning-generation"||e.commandId!=="generate-epic"||e.writeSetId!=="generate-epic-v1"||!/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/.test(String(e.claimId))||!/^P[1-9][0-9]{0,11}$/.test(String(e.epicId))||[e.diagnosisReceiptId,e.researchReceiptId,e.intakeRevision,e.physicalAcceptanceReceiptId].some(n=>!/^[a-f0-9]{64}$/.test(String(n))))||a&&Object.entries(a).some(([n,d])=>e[n]!==d))throw new Error("private-execution-descriptor-invalid");return i}function y(r,a,i=Date.now()){if(typeof a!="string"||i>=Date.parse(r.expiresAt)||Buffer.byteLength(a,"utf8")!==r.byteLength||g("sha256").update(a,"utf8").digest("hex")!==r.materialSha256)throw new Error("private-execution-material-invalid");return a}async function S(r,a,i,e=Date.now()){const s=I(r,a);if(e>=Date.parse(s.expiresAt))throw new Error("private-execution-material-expired");const t=await i({leaseId:s.leaseId,...s.binding});if(!t||typeof t!="object"||Array.isArray(t)||Object.keys(t).sort().join(",")!=="material,schemaVersion"||t.schemaVersion!==1)throw new Error("private-execution-delivery-invalid");return y(s,t.material,Math.max(e,Date.now()))}export{u as PRIVATE_EXECUTION_PUBLIC_INSTRUCTION_V1,S as consumePrivateExecutionDelivery,b as isPrivateExecutionPublicEnvelope,I as parsePrivateExecutionDescriptor,f as privateExecutionStateSnapshotSha256,y as verifyPrivateExecutionMaterial};
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { type PrivateYoloIsolatedWorkspaceV1 } from './isolated-workspace.js';
|
|
2
|
+
import { type PactAnswerReceipt } from '../commands/architecture-answers.js';
|
|
3
|
+
import { type PactWriteSetV1 } from './pact-write-set.js';
|
|
4
|
+
import { type UxWriteSetV1 } from './ux-write-set.js';
|
|
5
|
+
import { type PactToolchainCandidateV1 } from './pact-toolchain.js';
|
|
2
6
|
export interface PrivateYoloIsolatedAdmissionV1 {
|
|
3
7
|
readonly schemaVersion: 1;
|
|
4
8
|
readonly outcome: 'admitted-unverified';
|
|
@@ -7,15 +11,38 @@ export interface PrivateYoloIsolatedAdmissionV1 {
|
|
|
7
11
|
readonly changedPaths: readonly string[];
|
|
8
12
|
readonly patchSha256: string;
|
|
9
13
|
}
|
|
14
|
+
export interface PrivatePactAdmissionV1 extends PrivateYoloIsolatedAdmissionV1 {
|
|
15
|
+
/** Static candidates only; no generated code was run by admission. */
|
|
16
|
+
readonly consumerBindingCandidateCount: number;
|
|
17
|
+
readonly consumerScaffoldCount: number;
|
|
18
|
+
}
|
|
10
19
|
/** A persisted snapshot must still match both physical checkouts before reuse. */
|
|
11
20
|
export declare function verifyPrivateYoloSnapshotBoundary(workspace: PrivateYoloIsolatedWorkspaceV1, frozenPaths: readonly string[], snapshotSha: string): void;
|
|
12
21
|
/** Bind one-shot admission to the physically verified C01 claim and graph. */
|
|
13
|
-
export declare function admitPrivateYoloFrozenWorkspace(workspace: PrivateYoloIsolatedWorkspaceV1, storyId: string, graphRevision: string, snapshotSha?: string): Promise<PrivateYoloIsolatedAdmissionV1>;
|
|
22
|
+
export declare function admitPrivateYoloFrozenWorkspace(workspace: PrivateYoloIsolatedWorkspaceV1, storyId: string, graphRevision: string, snapshotSha?: string, rootOwnedSetup?: boolean): Promise<PrivateYoloIsolatedAdmissionV1>;
|
|
14
23
|
/**
|
|
15
24
|
* Admit only a generated epic whose physical artifacts agree with the reserved
|
|
16
25
|
* epic ID. The claim is still unverified: this checks structure and write scope,
|
|
17
26
|
* not the quality of the agent's planning or story acceptance criteria.
|
|
18
27
|
*/
|
|
19
28
|
export declare function admitPrivateEpicClaimWorkspace(workspace: PrivateYoloIsolatedWorkspaceV1, claimId: string, epicId: string, logicalFingerprint: string, pendingSidecarSha256: string): PrivateYoloIsolatedAdmissionV1;
|
|
29
|
+
/** P01 may admit planning artifacts only. Canonical state and QA remain root-owned. */
|
|
30
|
+
export declare function admitPrivateIdeaDiagnosisWorkspace(workspace: PrivateYoloIsolatedWorkspaceV1, claimId: string, epicId: string, logicalFingerprint: string, pendingSidecarSha256: string, expectedIdea: string): PrivateYoloIsolatedAdmissionV1;
|
|
31
|
+
/** P02 admits only a research candidate on a committed, physically accepted P01. */
|
|
32
|
+
export declare function admitPrivateIdeaResearchWorkspace(workspace: PrivateYoloIsolatedWorkspaceV1, claimId: string, epicId: string, diagnosisReceiptId: string, intakeRevision: string, stateSnapshotSha256: string): PrivateYoloIsolatedAdmissionV1;
|
|
33
|
+
/** Admit only a bounded P03 document/index candidate; root owns QA and state integration. */
|
|
34
|
+
export declare function admitPrivateGenerateEpicWorkspace(workspace: PrivateYoloIsolatedWorkspaceV1, claimId: string, epicId: string, diagnosisReceiptId: string, researchReceiptId: string, intakeRevision: string, sourceStateSha256: string): PrivateYoloIsolatedAdmissionV1;
|
|
20
35
|
/** Admit a state-bound step without granting the agent direct source writes. */
|
|
21
36
|
export declare function admitPrivateStateBoundStepWorkspace(workspace: PrivateYoloIsolatedWorkspaceV1, storyId: string): PrivateYoloIsolatedAdmissionV1;
|
|
37
|
+
/** One project-level utility contract, with no state/Git/other-file write grant. */
|
|
38
|
+
export declare function admitPrivateProjectStepWorkspace(workspace: PrivateYoloIsolatedWorkspaceV1, commandId: string, writeSetId: string): PrivateYoloIsolatedAdmissionV1;
|
|
39
|
+
/** Architecture agent writes only its closed documents; stage/graph progression remains root-owned. */
|
|
40
|
+
export declare function admitPrivateArchitectureStageWorkspace(workspace: PrivateYoloIsolatedWorkspaceV1, commandId: string, writeSetId: string, targetEpicId: string, graphRevision: string): PrivateYoloIsolatedAdmissionV1;
|
|
41
|
+
/** A08 paths come only from a committed root approval, never the child result. */
|
|
42
|
+
export declare function admitPrivateUxWorkspace(workspace: PrivateYoloIsolatedWorkspaceV1, targetEpicId: string, graphRevision: string, expectedWriteSet: UxWriteSetV1): PrivateYoloIsolatedAdmissionV1;
|
|
43
|
+
/**
|
|
44
|
+
* The private agent writes only the exact OpenAPI-derived test set. Optional
|
|
45
|
+
* package/lockfile integration is staged by the root after validating that set,
|
|
46
|
+
* then admitted in the same exact patch. This still proves no test execution.
|
|
47
|
+
*/
|
|
48
|
+
export declare function admitPrivatePactWorkspace(workspace: PrivateYoloIsolatedWorkspaceV1, targetEpicId: string, graphRevision: string, expectedAnswers: PactAnswerReceipt, expectedWriteSet: PactWriteSetV1, toolchainCandidate?: PactToolchainCandidateV1): PrivatePactAdmissionV1;
|
|
@@ -1,2 +1,11 @@
|
|
|
1
|
-
import{execFileSync as
|
|
2
|
-
`)])));if(
|
|
1
|
+
import{execFileSync as Re,spawnSync as ye}from"node:child_process";import{createHash as F}from"node:crypto";import{existsSync as re,lstatSync as R,readFileSync as l,realpathSync as ae,writeFileSync as Ee}from"node:fs";import{isAbsolute as oe,join as i,relative as ce,sep as Pe}from"node:path";import{isDeepStrictEqual as T}from"node:util";import{readPrivateYoloFrozenWriteSet as Ae,verifyPrivateYoloCandidateWriteSet as Se,verifyPrivateYoloCleanBaseline as $e}from"./clean-baseline.js";import{PRIVATE_EPIC_PENDING_SIDECAR as te}from"./isolated-workspace.js";import{loadPactPrivateAnswers as Oe}from"../commands/architecture-answers.js";import{derivePactWriteSet as ve}from"./pact-write-set.js";import{deriveUxCandidateWriteSet as je,deriveUxWriteSet as Ne}from"./ux-write-set.js";import{validateUxCandidateSource as Te}from"./ux-source-validation.js";import{validatePactTestSource as De}from"./pact-test-source.js";import{classifyProjectMemoryUpdate as Be}from"../memory/project-memory-writer.js";import{inspectPactToolchain as Le,planPactToolchainManifest as Ce}from"./pact-toolchain.js";import{acceptedPlanningDiagnosisPredecessor as Fe}from"./planning-diagnosis-checkpoint.js";import{acceptedPlanningResearchPredecessor as ze}from"./planning-research-checkpoint.js";const Q=16*1024*1024,he=1024,de="acd455ed0e39d98b90fb57391db75e366e4c5604db043e03a89a20e33d643c3c",He="81f50aaa801c1660eabe46e645501acbfb3e9873410c991e1496c014ca75c369",we="fa2194f89c01f07e225fd6f39e98e679f628e072239b6cd0af3ee527f0722518",Je="8636f22ec5950410902448ee1e9cb4947359ac98df518742bddbbb367468e3ae";function I(e,t){return typeof e=="string"&&e.length<=128&&F("sha256").update(e).digest("hex")===t}function le(){const e={...process.env};for(const t of["GIT_DIR","GIT_WORK_TREE","GIT_INDEX_FILE","GIT_OBJECT_DIRECTORY","GIT_ALTERNATE_OBJECT_DIRECTORIES","GIT_COMMON_DIR","GIT_NAMESPACE","GIT_CEILING_DIRECTORIES"])delete e[t];return e}function k(e,t){return Re("git",[...t],{cwd:e,env:le(),stdio:["ignore","pipe","pipe"],timeout:3e4,maxBuffer:Q})}function J(e,t){return k(e,t).toString("utf8").trim()}function z(e,t=!1){return k(e,["status","--porcelain=v1","-z","--untracked-files=all",...t?["--ignored=matching"]:[]])}function ue(e){return!!e&&!oe(e)&&!e.includes("\\")&&!e.includes("\0")&&!e.split("/").some(t=>!t||t==="."||t===".."||t===".git")}function E(e,t){const r=t.split("/");let o=e;for(const n of r.slice(0,-1)){o=i(o,n);try{const a=R(o);if(!a.isDirectory()||a.isSymbolicLink())throw new Error("path-boundary")}catch(a){if(a.code==="ENOENT")return;throw a}}try{const n=R(i(e,t));if(!n.isFile()||n.isSymbolicLink()||n.size>Q)throw new Error("path-boundary")}catch(n){if(n.code!=="ENOENT")throw n}}function _e(e){const t=[...e.matchAll(/\/\/\s*arch:keep-start[^\n]*\n[\s\S]*?\/\/\s*arch:keep-end[^\n]*/g)].map(n=>n[0]),r=(e.match(/arch:keep-start/g)??[]).length,o=(e.match(/arch:keep-end/g)??[]).length;if(r!==o||r!==t.length)throw new Error("architecture-keep-marker-invalid");return t}function G(e,t=!1,r=!1){const o=[],n=[];for(const a of e.toString("utf8").split("\0").filter(Boolean)){if(a.length<4||a[2]!==" ")throw new Error("status-invalid");const s=a.slice(0,2),c=a.slice(3);if(!ue(c)||s!=="??"&&s!==" M"&&s!==" D"&&!(r&&s==="!!"&&c===te))throw new Error("status-invalid");o.push(c),s==="??"&&n.push(c)}if(!t&&o.length===0||o.length>he||new Set(o).size!==o.length)throw new Error("status-invalid");return{paths:o.sort(),untracked:n.sort()}}function pe(e,t,r,o){const n=k(t,["ls-tree","-z",r,"--",o]).toString("utf8");if(!n)try{return R(i(e,o)),!1}catch(s){return s.code==="ENOENT"}const a=/^([0-7]{6}) blob [a-f0-9]{40,64}\t([^\0]+)\0$/.exec(n);if(!a||a[2]!==o||!["100644","100755"].includes(a[1]))return!1;try{const s=R(i(e,o));return!s.isFile()||s.isSymbolicLink()||s.size>Q||!!(s.mode&73)!=(a[1]==="100755")?!1:l(i(e,o)).equals(k(t,["show",`${r}:${o}`]))}catch{return!1}}function ne(e,t){try{const r=i(e,te),o=R(i(e,".neocortex")),n=R(r);return o.isDirectory()&&!o.isSymbolicLink()&&o.uid===process.getuid?.()&&(o.mode&18)===0&&n.isFile()&&!n.isSymbolicLink()&&n.uid===process.getuid?.()&&(n.mode&63)===0&&n.size>0&&n.size<=128*1024&&F("sha256").update(l(r)).digest("hex")===t}catch{return!1}}function fe(e,t,r,o,n){const a=new Set(o),s=G(z(e),!0,!!n);return(!n||ne(e,n))&&s.paths.every(c=>a.has(c)||c===te&&!!n&&ne(e,n))&&o.every(c=>pe(e,t,r,c))}function Me(e,t){const r=ye("git",["diff","--no-index","--binary","--no-ext-diff","--","/dev/null",t],{cwd:e,env:le(),encoding:"buffer",timeout:3e4,maxBuffer:Q});if(r.error||r.status!==1||!Buffer.isBuffer(r.stdout)||r.stdout.byteLength===0)throw new Error("patch-invalid");return r.stdout}function be(e,t,r){const o=ye("git",["apply",...r?["--check"]:[],"--binary","-"],{cwd:e,env:le(),input:t,encoding:"buffer",timeout:3e4,maxBuffer:Q});if(o.error||o.status!==0)throw new Error("apply-failed")}function Ge(e,t,r){const o=i(e,r),n=i(t,r);try{const a=R(o),s=R(n);return a.isFile()&&s.isFile()&&(a.mode&73)===(s.mode&73)&&l(o).equals(l(n))}catch(a){if(a.code!=="ENOENT")return!1;try{return R(o),!1}catch(s){if(s.code!=="ENOENT")return!1}try{return R(n),!1}catch(s){return s.code==="ENOENT"}}}function st(e,t,r){try{if(process.platform!=="linux"||e.schemaVersion!==1||!oe(e.sourceRoot)||!oe(e.workspacePath)||ae(e.sourceRoot)!==e.sourceRoot||ae(e.workspacePath)!==e.workspacePath||!R(e.workspacePath).isDirectory()||(R(e.workspacePath).mode&63)!==0||ce(e.sourceRoot,e.workspacePath)===""||ce(e.sourceRoot,e.workspacePath).split(Pe)[0]!==".."||!/^[a-f0-9]{40,64}$/.test(e.baseSha)||!/^[a-f0-9]{40,64}$/.test(r)||J(e.sourceRoot,["rev-parse","--show-toplevel"])!==e.sourceRoot||J(e.workspacePath,["rev-parse","--show-toplevel"])!==e.workspacePath||J(e.sourceRoot,["rev-parse","HEAD"])!==e.baseSha||J(e.workspacePath,["rev-parse","HEAD"])!==r||J(e.sourceRoot,["symbolic-ref","--short","HEAD"])!==e.executionBranch||J(e.workspacePath,["symbolic-ref","--short","HEAD"])!==e.executionBranch||re(i(e.workspacePath,".git","objects","info","alternates"))||z(e.workspacePath,!0).byteLength!==0||t.length===0||t.length>he||t.some(o=>!ue(o))||new Set(t).size!==t.length)throw new Error("boundary-invalid");if(k(e.workspacePath,["merge-base","--is-ancestor",e.baseSha,r]),!fe(e.sourceRoot,e.workspacePath,r,t))throw new Error("boundary-raced")}catch{throw new Error("private-execution-isolated-snapshot-unverified")}}function W(e,t,r,o,n,a=[]){try{if(process.platform!=="linux"||e.schemaVersion!==1||!oe(e.sourceRoot)||!oe(e.workspacePath)||ae(e.sourceRoot)!==e.sourceRoot||ae(e.workspacePath)!==e.workspacePath||!R(e.workspacePath).isDirectory()||(R(e.workspacePath).mode&63)!==0||ce(e.sourceRoot,e.workspacePath)===""||ce(e.sourceRoot,e.workspacePath).split(Pe)[0]!==".."||J(e.sourceRoot,["rev-parse","--show-toplevel"])!==e.sourceRoot||J(e.workspacePath,["rev-parse","--show-toplevel"])!==e.workspacePath||J(e.sourceRoot,["rev-parse","HEAD"])!==e.baseSha||!/^[a-f0-9]{40,64}$/.test(r)||J(e.workspacePath,["rev-parse","HEAD"])!==r||J(e.sourceRoot,["symbolic-ref","--short","HEAD"])!==e.executionBranch||J(e.workspacePath,["symbolic-ref","--short","HEAD"])!==e.executionBranch||t.length===0||t.length>he||t.some(f=>!ue(f))||new Set(t).size!==t.length)throw new Error("authority-invalid");if(k(e.workspacePath,["merge-base","--is-ancestor",e.baseSha,r]),!fe(e.sourceRoot,e.workspacePath,r,t,o))throw new Error("source-snapshot-mismatch");const s=z(e.workspacePath,!0),c=G(s),y=new Set(t);if(c.paths.some(f=>!y.has(f)||a.includes(f)))throw new Error("path-unclaimed");if(n&&!n())throw new Error("candidate-raced");for(const f of c.paths)E(e.workspacePath,f),E(e.sourceRoot,f);const P=[k(e.workspacePath,["diff","--binary","--no-ext-diff","--no-textconv","HEAD","--"]),...c.untracked.map(f=>Me(e.workspacePath,f))],d=Buffer.concat(P.map(f=>Buffer.concat([f,Buffer.from(`
|
|
2
|
+
`)])));if(d.byteLength===0||d.byteLength>Q||!z(e.workspacePath,!0).equals(s)||n&&!n()||!fe(e.sourceRoot,e.workspacePath,r,t,o))throw new Error("patch-raced");if(be(e.sourceRoot,d,!0),!z(e.workspacePath,!0).equals(s)||n&&!n()||!fe(e.sourceRoot,e.workspacePath,r,t,o))throw new Error("patch-raced");if(be(e.sourceRoot,d,!1),G(z(e.sourceRoot),!0,!!o).paths.some(f=>!y.has(f)&&f!==te)||o&&!ne(e.sourceRoot,o)||t.some(f=>!Ge(e.workspacePath,e.sourceRoot,f))||J(e.sourceRoot,["rev-parse","HEAD"])!==e.baseSha||J(e.sourceRoot,["symbolic-ref","--short","HEAD"])!==e.executionBranch)throw new Error("admission-raced");return Object.freeze({schemaVersion:1,outcome:"admitted-unverified",baseSha:e.baseSha,executionBranch:e.executionBranch,changedPaths:Object.freeze([...c.paths]),patchSha256:F("sha256").update(d).digest("hex")})}catch{throw new Error("private-execution-isolated-admission-unverified")}}async function it(e,t,r,o=e.baseSha,n=!1){try{const a=await Ae(e.sourceRoot,t,e.executionBranch,r),s=i(e.workspacePath,".neocortex","state.json"),c=R(s);if(!c.isFile()||c.isSymbolicLink()||c.size>Q)throw new Error("candidate-state-invalid");Se(l(s,"utf8"),t,a);const y=W(e,a,o,void 0,void 0,n?[".neocortex/state.json"]:[]);return await $e(e.sourceRoot,t,e.executionBranch,r),y}catch{throw new Error("private-execution-isolated-admission-unverified")}}function at(e,t,r,o,n){try{if(!/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/.test(t)||!/^P[1-9][0-9]*$/.test(r)||!/^[a-f0-9]{64}$/.test(o)||!/^[a-f0-9]{64}$/.test(n)||!ne(e.sourceRoot,n))throw new Error("claim-invalid");const a=JSON.parse(l(i(e.sourceRoot,te),"utf8")),s=a&&typeof a=="object"&&!Array.isArray(a)?a.operations?.[o]:void 0;if(!s||typeof s!="object"||Array.isArray(s)||s.claimId!==t||s.epicId!==r)throw new Error("claim-sidecar-mismatch");const c=G(z(e.workspacePath,!0)),y=`docs/epics/epic-${r}.md`,h=".neocortex/state.json",P=new RegExp(`^docs/stories/${r}\\.[0-9]{2}\\.story\\.md$`),d=c.paths.filter(w=>P.test(w));if(!c.paths.includes(y)||!c.paths.includes(h)||d.length===0||d.length>99||c.paths.some(w=>w!==y&&w!==h&&w!=="NEOCORTEX.md"&&!P.test(w)))throw new Error("artifact-scope-invalid");const p=d.map(w=>w.slice(13,-9)).sort();if(p.some((w,x)=>w!==`${r}.${String(x+1).padStart(2,"0")}`))throw new Error("story-sequence-invalid");for(const w of[y,...d])try{throw R(i(e.sourceRoot,w)),new Error("artifact-already-exists")}catch(x){if(x.code!=="ENOENT")throw x}const f=(w,x)=>{E(e.workspacePath,w);const Y=l(i(e.workspacePath,w),"utf8");return Buffer.byteLength(Y)>Q?null:/^---\r?\n([\s\S]{1,8192}?)\r?\n---(?:\r?\n|$)/.exec(Y)?.[1]?.split(/\r?\n/).find(ie=>ie.startsWith(`${x}:`))?.slice(x.length+1).trim()?.replace(/^(["'])(.*)\1$/,"$2")??null};if(f(y,"id")!==r||d.some((w,x)=>f(w,"id")!==p[x]||f(w,"epic_id")!==r))throw new Error("artifact-id-invalid");E(e.workspacePath,h);const g=JSON.parse(l(i(e.workspacePath,h),"utf8"));if(!g||typeof g!="object"||Array.isArray(g))throw new Error("state-invalid");const _=g,v=_.epics,O=_.stories,A=v?.[r],j=_.epic_id_ledger;if(_.schema_version!==1||!A||A.id!==r||A.status!=="memory-updated"||!Array.isArray(A.stories)||A.stories.length!==p.length||A.stories.some((w,x)=>w!==p[x])||!O||p.some(w=>{const x=O[w];return!x||x.id!==w||x.epic_id!==r})||!j||!Array.isArray(j.reserved_ids)||!j.reserved_ids.includes(r))throw new Error("state-claim-mismatch");E(e.sourceRoot,h);const u=JSON.parse(l(i(e.sourceRoot,h),"utf8")),S=u.epics,b=u.stories;if(!S||!b||S[r]!==void 0||p.some(w=>b[w]!==void 0))throw new Error("state-claim-conflict");const{[r]:q,...C}=v,$={...O};for(const w of p)delete $[w];const{epic_id_ledger:M,last_updated:B,...L}=u,{epic_id_ledger:V,last_updated:X,...K}=_;if(!T(C,S)||!T($,b)||!T({...K,epics:void 0,stories:void 0},{...L,epics:void 0,stories:void 0}))throw new Error("state-unrelated-drift");const D=u.epic_id_ledger&&typeof u.epic_id_ledger=="object"?u.epic_id_ledger.reserved_ids:void 0,{reserved_ids:U,...m}=j,N=u.epic_id_ledger&&typeof u.epic_id_ledger=="object"?u.epic_id_ledger:{schema_version:1},{reserved_ids:H,...ee}=N;if(D!==void 0&&(!Array.isArray(D)||D.some(w=>!j.reserved_ids.includes(w)))||!T(m,ee))throw new Error("ledger-drift");return W(e,c.paths,e.baseSha,n)}catch{throw new Error("private-execution-epic-claim-admission-unverified")}}function ct(e,t,r,o,n,a){try{if(!/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/.test(t)||!/^P[1-9][0-9]{0,11}$/.test(r)||!/^[a-f0-9]{64}$/.test(o)||!/^[a-f0-9]{64}$/.test(n)||typeof a!="string"||!a.trim()||a.length>16384||!ne(e.sourceRoot,n))throw new Error("planning-claim-invalid");const s=JSON.parse(l(i(e.sourceRoot,te),"utf8")),c=s&&typeof s=="object"&&!Array.isArray(s)?s.operations?.[o]:void 0;if(!c||typeof c!="object"||Array.isArray(c)||c.claimId!==t||c.epicId!==r)throw new Error("planning-claim-sidecar-mismatch");const y=`.neocortex/planning/epic-${r}`,h=`${y}/idea.json`,P=`${y}/diagnosis.md`,d=`${y}/enriched-prompt.md`,p=".neocortex/planning/planning.json",f=[h,P,d,p],g=G(z(e.workspacePath,!0));if(g.paths.length!==f.length||g.paths.some(x=>!f.includes(x)))throw new Error("planning-artifact-scope-invalid");for(const x of[h,P,d]){E(e.workspacePath,x);try{throw R(i(e.sourceRoot,x)),new Error("planning-artifact-already-exists")}catch(Y){if(Y.code!=="ENOENT")throw Y}}const _=(x,Y)=>{const Z=R(i(e.workspacePath,x));if(!Z.isFile()||Z.isSymbolicLink()||Z.size<1||Z.size>Y)throw new Error("planning-artifact-invalid");return l(i(e.workspacePath,x),"utf8")},v=JSON.parse(_(h,32*1024));if(!v||typeof v!="object"||Array.isArray(v)||v.epic_id!==r||v.status!=="diagnosed"||typeof v.raw_input!="string"||v.raw_input!==a)throw new Error("planning-idea-invalid");const O=_(P,256*1024),A=_(d,256*1024),j=(x,Y)=>{const Z=/^---\n([\s\S]{1,8192}?)\n---\n/.exec(x.replace(/\r\n/g,`
|
|
3
|
+
`))?.[1];if(!Z)return!1;const ge=Z.split(`
|
|
4
|
+
`),se=ie=>{const me=ge.filter(xe=>xe.startsWith(`${ie}:`));return me.length===1?me[0].slice(ie.length+1).trim().replace(/^(?:"(.*)"|'(.*)')$/,"$1$2"):void 0};return se("epic_id")===r&&I(se("step"),Y)&&se("status")==="completed"};if(!j(O,de)||!j(A,He))throw new Error("planning-document-identity-invalid");E(e.workspacePath,p),E(e.sourceRoot,p);const u=JSON.parse(_(p,128*1024)),S=re(i(e.sourceRoot,p))?JSON.parse(l(i(e.sourceRoot,p),"utf8")):void 0;if(!u||typeof u!="object"||Array.isArray(u)||!("epics"in u)||!u.epics||typeof u.epics!="object"||Array.isArray(u.epics)||S!==void 0&&(!S||typeof S!="object"||Array.isArray(S)||!("epics"in S)||!S.epics||typeof S.epics!="object"||Array.isArray(S.epics)))throw new Error("planning-index-invalid");const b=u,q=b.epics,C=q[r],$=C,M=$?.output_files;if(!C||typeof C!="object"||Array.isArray(C)||$?.id!==r||$.status!=="diagnosed"||$.idea!==v.raw_input||!Array.isArray($.steps_completed)||$.steps_completed.length!==1||!I($.steps_completed[0],de)||typeof $.created_at!="string"||!Number.isFinite(Date.parse($.created_at))||$.completed_at!==null||!M||typeof M!="object"||Array.isArray(M)||!T(M,{diagnosis:`${y}/diagnosis.md`})||!T(Object.keys($).sort(),["id","idea","status","steps_completed","created_at","completed_at","output_files"].sort()))throw new Error("planning-index-epic-invalid");const{last_scan:B,epics:L,...V}=b,X=S,K=X?.epics,{last_scan:D,epics:U,...m}=X??{},{[r]:N,...H}=q;if(K?.[r]!==void 0||!T(H,K??{})||X!==void 0&&!T(V,m)||X===void 0&&(Object.keys(q).length!==1||!T(Object.keys(b).sort(),["version","next_epic_id","last_scan","existing_epics_discovered","epics"].sort())||b.version!=="1.0.0"||b.next_epic_id!==1||!T(b.existing_epics_discovered,[]))||typeof b.last_scan!="string"||!Number.isFinite(Date.parse(b.last_scan)))throw new Error("planning-index-drift");const ee=f.map(x=>F("sha256").update(l(i(e.workspacePath,x))).digest("hex")),w=()=>f.every((x,Y)=>{try{return E(e.workspacePath,x),F("sha256").update(l(i(e.workspacePath,x))).digest("hex")===ee[Y]}catch{return!1}});return W(e,f,e.baseSha,n,w)}catch{throw new Error("private-execution-planning-diagnosis-admission-unverified")}}function ht(e,t,r,o,n,a){try{if(!/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/.test(t)||!/^P[1-9][0-9]{0,11}$/.test(r)||!/^[a-f0-9]{64}$/.test(o)||!/^[a-f0-9]{64}$/.test(n)||!/^[a-f0-9]{64}$/.test(a))throw new Error("planning-research-binding-invalid");const s=".neocortex/state.json",c=".neocortex/planning/planning.json",y=`.neocortex/planning/epic-${r}`,h=`${y}/research.md`;if(E(e.sourceRoot,s),E(e.workspacePath,s),E(e.sourceRoot,c),E(e.workspacePath,c),E(e.sourceRoot,h),E(e.workspacePath,h),R(i(e.sourceRoot,s)).size>8*1024*1024||R(i(e.workspacePath,s)).size>8*1024*1024||R(i(e.sourceRoot,c)).size>128*1024||R(i(e.workspacePath,c)).size>128*1024)throw new Error("planning-research-source-size-invalid");const P=l(i(e.sourceRoot,s));if(F("sha256").update(P).digest("hex")!==a||!P.equals(l(i(e.workspacePath,s))))throw new Error("planning-research-state-drift");const d=JSON.parse(P.toString("utf8")),p=Fe(d,t,r);if(p.diagnosisReceiptId!==o||p.intakeRevision!==n)throw new Error("planning-research-predecessor-mismatch");const g=d.epics[r].createEpicPlanningPhysical.artifactDigests;for(const[D,U]of Object.entries({idea:`${y}/idea.json`,diagnosis:`${y}/diagnosis.md`,enrichment:`${y}/enriched-prompt.md`,index:c}))if(E(e.sourceRoot,U),F("sha256").update(l(i(e.sourceRoot,U))).digest("hex")!==g[D])throw new Error("planning-research-source-artifact-drift");try{throw R(i(e.sourceRoot,h)),new Error("planning-research-already-exists")}catch(D){if(D.code!=="ENOENT")throw D}const _=[h,c],v=G(z(e.workspacePath,!0));if(v.paths.length!==_.length||v.paths.some(D=>!_.includes(D)))throw new Error("planning-research-write-scope-invalid");const O=R(i(e.workspacePath,h));if(!O.isFile()||O.isSymbolicLink()||O.size<64||O.size>256*1024)throw new Error("planning-research-document-invalid");const A=l(i(e.workspacePath,h),"utf8"),j=/^---\n([\s\S]{1,8192}?)\n---\n/.exec(A.replace(/\r\n/g,`
|
|
5
|
+
`))?.[1],u=D=>{const U=j?.split(`
|
|
6
|
+
`).filter(m=>m.startsWith(`${D}:`))??[];return U.length===1?U[0].slice(D.length+1).trim().replace(/^(?:"(.*)"|'(.*)')$/,"$1$2"):void 0};if(!j||u("epic_id")!==r||u("status")!=="completed"||!I(u("step"),we)||!A.slice(j.length+8).trim())throw new Error("planning-research-document-identity-invalid");const S=JSON.parse(l(i(e.sourceRoot,c),"utf8")),b=JSON.parse(l(i(e.workspacePath,c),"utf8"));if(!S||typeof S!="object"||Array.isArray(S)||!b||typeof b!="object"||Array.isArray(b))throw new Error("planning-research-index-invalid");const q=S,C=b,$=q.epics,M=C.epics,B=$?.[r];if(!$||Array.isArray($)||!M||Array.isArray(M)||!B||Array.isArray(B)||B.id!==r||B.idea!==p.rawIntent||B.status!=="diagnosed"||!Array.isArray(B.steps_completed)||B.steps_completed.length!==1||!I(B.steps_completed[0],de)||!T(B.output_files,{diagnosis:`${y}/diagnosis.md`})||typeof C.last_scan!="string"||!Number.isFinite(Date.parse(C.last_scan)))throw new Error("planning-research-index-predecessor-invalid");const L={...B,status:"researched",steps_completed:[...B.steps_completed,u("step")],output_files:{diagnosis:`${y}/diagnosis.md`,research:h}},V={...q,last_scan:C.last_scan,epics:{...$,[r]:L}};if(!T(C,V))throw new Error("planning-research-index-drift");const X=_.map(D=>F("sha256").update(l(i(e.workspacePath,D))).digest("hex")),K=()=>_.every((D,U)=>{try{return E(e.workspacePath,D),F("sha256").update(l(i(e.workspacePath,D))).digest("hex")===X[U]}catch{return!1}});return W(e,_,e.baseSha,void 0,K)}catch{throw new Error("private-execution-planning-research-admission-unverified")}}function dt(e,t,r,o,n,a,s){try{if(!/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/.test(t)||!/^P[1-9][0-9]{0,11}$/.test(r)||[o,n,a,s].some(m=>!/^[a-f0-9]{64}$/.test(m)))throw new Error("planning-generation-binding-invalid");const c=".neocortex/state.json",y=".neocortex/planning/planning.json",h=`.neocortex/planning/epic-${r}`,P=`docs/epics/epic-${r}.md`;for(const m of[c,y,`${h}/idea.json`,`${h}/diagnosis.md`,`${h}/enriched-prompt.md`,`${h}/research.md`]){E(e.sourceRoot,m),E(e.workspacePath,m);const N=l(i(e.sourceRoot,m));if(m!==y&&!N.equals(l(i(e.workspacePath,m)))||!N.equals(k(e.sourceRoot,["show",`HEAD:${m}`])))throw new Error("planning-generation-predecessor-uncommitted")}const d=l(i(e.sourceRoot,c));if(d.byteLength>8*1024*1024||F("sha256").update(d).digest("hex")!==s)throw new Error("planning-generation-state-drift");const p=JSON.parse(d.toString("utf8")),f=ze(p,t,r);if(f.diagnosisReceiptId!==o||f.researchReceiptId!==n||f.intakeRevision!==a)throw new Error("planning-generation-predecessor-mismatch");const g=p.epics[r],_=g.createEpicPlanningPhysical.artifactDigests,v=g.createEpicPlanningResearchPhysical.artifactDigests,O={idea:`${h}/idea.json`,diagnosis:`${h}/diagnosis.md`,enrichment:`${h}/enriched-prompt.md`,research:`${h}/research.md`};for(const[m,N]of Object.entries(O)){const H=m==="research"?v.research:_[m];if(F("sha256").update(l(i(e.sourceRoot,N))).digest("hex")!==H)throw new Error("planning-generation-artifact-drift")}if(F("sha256").update(l(i(e.sourceRoot,y))).digest("hex")!==v.index)throw new Error("planning-generation-index-drift");const A=G(z(e.workspacePath,!0)),j=new RegExp(`^docs/stories/${r}\\.([0-9]{2})\\.story\\.md$`),u=A.paths.filter(m=>j.test(m)).sort((m,N)=>Number(j.exec(m)[1])-Number(j.exec(N)[1]));if(u.length<1||u.length>24||u.some((m,N)=>j.exec(m)[1]!==String(N+1).padStart(2,"0"))||A.paths.length!==u.length+2||A.paths.some(m=>m!==P&&m!==y&&!j.test(m)))throw new Error("planning-generation-write-scope-invalid");const S=[P,y,...u];for(const m of[P,...u]){E(e.sourceRoot,m),E(e.workspacePath,m);try{throw R(i(e.sourceRoot,m)),new Error("planning-generation-path-collision")}catch(H){if(H.code!=="ENOENT")throw H}const N=R(i(e.workspacePath,m));if(!N.isFile()||N.isSymbolicLink()||N.size<128||N.size>(m===P?512:128)*1024)throw new Error("planning-generation-document-invalid")}const b=(m,N)=>{const ee=/^---\n([\s\S]{1,8192}?)\n---\n/.exec(m.replace(/\r\n/g,`
|
|
7
|
+
`))?.[1]?.split(`
|
|
8
|
+
`).filter(w=>w.startsWith(`${N}:`))??[];return ee.length===1?ee[0].slice(N.length+1).trim().replace(/^(?:"(.*)"|'(.*)')$/,"$1$2"):void 0},q=l(i(e.workspacePath,P),"utf8");if(b(q,"id")!==r||b(q,"stories_count")!==String(u.length)||!q.includes("## Stories"))throw new Error("planning-generation-epic-invalid");for(const[m,N]of u.entries()){const H=l(i(e.workspacePath,N),"utf8");if(b(H,"id")!==`${r}.${String(m+1).padStart(2,"0")}`||b(H,"epic")!==r||b(H,"status")!=="backlog"||!H.includes("## Acceptance Criteria")||!/\bGiven\b[\s\S]*\bWhen\b[\s\S]*\bThen\b/.test(H))throw new Error("planning-generation-story-invalid")}const C=JSON.parse(l(i(e.sourceRoot,y),"utf8")),$=JSON.parse(l(i(e.workspacePath,y),"utf8")),M=C.epics,B=$.epics,L=M?.[r],V=B?.[r];if(!M||!B||!L||!V||L.id!==r||L.status!=="researched"||!Array.isArray(L.steps_completed)||L.steps_completed.length!==2||!I(L.steps_completed[0],de)||!I(L.steps_completed[1],we)||!T(L.output_files,{diagnosis:`${h}/diagnosis.md`,research:`${h}/research.md`})||typeof $.last_scan!="string"||!Number.isFinite(Date.parse($.last_scan))||typeof V.completed_at!="string"||!Number.isFinite(Date.parse(V.completed_at)))throw new Error("planning-generation-index-predecessor-invalid");const X=V.steps_completed?.[2];if(!I(X,Je))throw new Error("planning-generation-index-transition-invalid");const K={...C,last_scan:$.last_scan,epics:{...M,[r]:{...L,status:"generated",steps_completed:[...L.steps_completed,X],completed_at:V.completed_at,output_files:{...L.output_files,epic:P,stories:u}}}};if(!T($,K))throw new Error("planning-generation-index-transition-invalid");const D=S.map(m=>F("sha256").update(l(i(e.workspacePath,m))).digest("hex")),U=()=>S.every((m,N)=>{try{return E(e.workspacePath,m),F("sha256").update(l(i(e.workspacePath,m))).digest("hex")===D[N]}catch{return!1}});return W(e,S,e.baseSha,void 0,U)}catch{throw new Error("private-execution-planning-generation-admission-unverified")}}function ut(e,t){try{if(!/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/.test(t))throw new Error("story-id-invalid");const r=".neocortex/state.json";E(e.sourceRoot,r),E(e.workspacePath,r);const o=JSON.parse(l(i(e.sourceRoot,r),"utf8")),n=JSON.parse(l(i(e.workspacePath,r),"utf8"));if(!o||typeof o!="object"||Array.isArray(o)||!n||typeof n!="object"||Array.isArray(n))throw new Error("state-invalid");const a=o,s=n,c=a.stories,y=s.stories,h=c?.[t],P=y?.[t],d=h?.files_to_modify;if(a.schema_version!==1||s.schema_version!==1||!c||!y||!h||!P||h.id!==t||P.id!==t||P.epic_id!==h.epic_id||!Array.isArray(d)||d.length===0||d.length>he||d.some(b=>typeof b!="string"||!ue(b)||b.length>1024)||new Set(d).size!==d.length||!T(P.files_to_modify,d))throw new Error("write-set-invalid");const{[t]:p,...f}=c,{[t]:g,..._}=y,{stories:v,last_updated:O,...A}=a,{stories:j,last_updated:u,...S}=s;if(!T(_,f)||!T(S,A))throw new Error("state-unrelated-drift");return W(e,[...d].sort(),e.baseSha)}catch{throw new Error("private-execution-state-step-admission-unverified")}}function ft(e,t,r){const o=t==="sync-openapi"&&r==="sync-openapi-contract-v1"?["docs/architecture/api-contracts.md","docs/api/openapi.yaml"]:t==="tech-debt"&&r==="tech-debt-registry-v1"?[".neocortex/tech-debt-registry.json"]:void 0;if(!o)throw new Error("private-execution-project-step-admission-unverified");try{if(t==="tech-debt"){const n=".neocortex/tech-debt-registry.json";E(e.workspacePath,n);const a=JSON.parse(l(i(e.workspacePath,n),"utf8"));if(!a||typeof a!="object"||Array.isArray(a))throw new Error("registry-invalid");const s=a;if(s.schema_version!==2||s.version!==void 0&&s.version!==2||!Array.isArray(s.items))throw new Error("registry-invalid")}return W(e,o,e.baseSha)}catch{throw new Error("private-execution-project-step-admission-unverified")}}function lt(e,t,r,o,n){const a=t==="arch-prd"&&r==="arch-prd-docs-v1"?["docs/architecture/prd.md","docs/architecture/product-experience.md"]:t==="arch-architecture"&&r==="arch-architecture-doc-v1"?["docs/architecture/architecture.md"]:t==="arch-fitness-functions"&&r==="arch-fitness-tools-v1"?["tools/architecture/dependency-cruiser.config.js","tools/architecture/archunit-test.ts","tools/architecture/.eslintrc.boundaries.js"]:t==="arch-api-contracts"&&r==="arch-api-contracts-docs-v1"?["docs/architecture/api-contracts.md","docs/api/openapi.yaml"]:t==="arch-api-integrations"&&r==="arch-api-integrations-doc-v1"?["docs/architecture/api-integrations.md"]:t==="arch-database"&&r==="arch-database-doc-v1"?["docs/architecture/database-schema.md"]:t==="arch-security"&&r==="arch-security-doc-v1"?["docs/architecture/cyber-security.md"]:t==="arch-design-system"&&r==="arch-design-system-doc-v1"?["docs/architecture/atomic-design-system.md"]:t==="arch-performance"&&r==="arch-performance-doc-v1"?["docs/architecture/performance-strategy.md"]:t==="arch-testing"&&r==="arch-testing-doc-v1"?["docs/architecture/testing-strategy.md"]:t==="arch-infrastructure"&&r==="arch-infrastructure-doc-v1"?["docs/architecture/infrastructure-deploy.md"]:t==="arch-review"&&r==="arch-review-doc-v1"?["docs/architecture/review-consolidation.md"]:t==="update-memory"&&r==="arch-memory-canonical-v1"?["NEOCORTEX.md"]:null;if(!a||!/^P[1-9][0-9]{0,11}$/.test(o)||!/^[a-f0-9]{64}$/.test(n))throw new Error("private-execution-architecture-admission-unverified");try{E(e.workspacePath,".neocortex/state.json");const s=JSON.parse(l(i(e.workspacePath,".neocortex/state.json"),"utf8"));if(!s||typeof s!="object"||Array.isArray(s))throw new Error("state-invalid");const c=s,h=c.archPlan?.execution,P=c.epics;if(!h||h.currentStageCommand!==t||h.targetEpicId!==o||h.graphRevision!==n||!P||!Object.hasOwn(P,o))throw new Error("state-binding-mismatch");if(t==="update-memory"){if(h.continuationState!=="delegate"||h.reviewDecision?.decision!=="approved")throw new Error("memory-root-review-missing");const d="NEOCORTEX.md";if(!G(z(e.workspacePath,!0)).paths.includes(d))throw new Error("memory-effect-missing");E(e.sourceRoot,d),E(e.workspacePath,d);const p=l(i(e.sourceRoot,d),"utf8"),f=l(i(e.workspacePath,d),"utf8"),g="<!-- NEOCORTEX-MEMORY-START -->",_="<!-- NEOCORTEX-MEMORY-END -->",v=u=>{if(u.split(g).length!==2||u.split(_).length!==2||u.indexOf(g)>=u.indexOf(_))throw new Error("memory-markers-invalid");const S=u.indexOf(g)+g.length,b=u.indexOf(_);return{before:u.slice(0,S),body:u.slice(S,b),after:u.slice(b)}},O=v(p),A=v(f);if(O.before!==A.before||O.after!==A.after||O.body===A.body||Buffer.byteLength(f,"utf8")>32768||f.split(`
|
|
9
|
+
`).length>240)throw new Error("memory-managed-block-invalid");const j=new Set(O.body.split(`
|
|
10
|
+
`));for(const u of A.body.split(`
|
|
11
|
+
`))j.has(u)||Be(u)}if(t==="arch-prd"){const d="docs/architecture/prd.md";if(!G(z(e.workspacePath,!0)).paths.includes(d))throw new Error("prd-effect-missing");if(E(e.workspacePath,d),R(i(e.workspacePath,d)).size===0)throw new Error("prd-empty")}if(t==="arch-api-contracts"||t==="arch-fitness-functions"||t==="arch-api-integrations"||t==="arch-database"||t==="arch-security"||t==="arch-design-system"||t==="arch-performance"||t==="arch-testing"||t==="arch-infrastructure"||t==="arch-review"){const d=G(z(e.workspacePath,!0)).paths;for(const p of a){if(!d.includes(p))throw new Error("architecture-required-effect-missing");if(E(e.workspacePath,p),R(i(e.workspacePath,p)).size===0)throw new Error("architecture-required-effect-empty");if(t==="arch-fitness-functions"){E(e.sourceRoot,p);const f=re(i(e.sourceRoot,p))?l(i(e.sourceRoot,p),"utf8"):"",g=l(i(e.workspacePath,p),"utf8"),_=_e(f),v=_e(g);if(!T(v,_))throw new Error("architecture-keep-marker-changed")}}}return W(e,a,e.baseSha)}catch{throw new Error("private-execution-architecture-admission-unverified")}}function pt(e,t,r,o){try{if(!/^P[1-9][0-9]{0,11}$/.test(t)||!/^[a-f0-9]{64}$/.test(r)||o.schemaVersion!==1||o.targetEpicId!==t)throw new Error("binding-invalid");const n=Ne(e.sourceRoot,t),a=je(e.workspacePath,t);if(!T(n,o)||!T(a,o))throw new Error("write-set-invalid");E(e.workspacePath,".neocortex/state.json");const s=JSON.parse(l(i(e.workspacePath,".neocortex/state.json"),"utf8"));if(!s||typeof s!="object"||Array.isArray(s))throw new Error("state-invalid");const c=s,h=c.archPlan?.execution,P=c.epics;if(!h||h.currentStageCommand!=="arch-ux-design"||h.continuationState!=="delegate"||h.targetEpicId!==t||h.graphRevision!==r||!P||!Object.hasOwn(P,t))throw new Error("stage-invalid");const d=G(z(e.workspacePath,!0)).paths;if(d.length!==o.pathCount||d.some(p=>!o.paths.includes(p)))throw new Error("agent-path-unclaimed");for(const p of o.paths){E(e.sourceRoot,p),E(e.workspacePath,p);const f=R(i(e.workspacePath,p));if(!f.isFile()||f.isSymbolicLink()||f.size<1)throw new Error("effect-empty");const g=new TextDecoder("utf-8",{fatal:!0}).decode(l(i(e.workspacePath,p)));if(!g.trim()||g.includes("\0"))throw new Error("effect-invalid")}return Te(e.workspacePath,o),W(e,o.paths,e.baseSha)}catch{throw new Error("private-execution-ux-admission-unverified")}}function gt(e,t,r,o,n,a){try{if(!/^P[1-9][0-9]{0,11}$/.test(t)||!/^[a-f0-9]{64}$/.test(r)||o.targetEpicId!==t||o.graphRevision!==r||n.schemaVersion!==1)throw new Error("binding-invalid");const s=Oe(e.sourceRoot);if(!s||!T(s.receipt,o))throw new Error("answers-invalid");const c=ve(e.sourceRoot,s.answers.generateProvider),y=ve(e.workspacePath,s.answers.generateProvider);if(c.outcome!=="ready"||y.outcome!=="ready"||!T(c.writeSet,n)||!T(y.writeSet,n))throw new Error("write-set-invalid");const h=G(z(e.workspacePath,!0)).paths;if(h.some(g=>!n.paths.includes(g)))throw new Error("agent-path-unclaimed");let P=0,d=0;for(const g of n.paths){if(E(e.sourceRoot,g),re(i(e.sourceRoot,g))||!h.includes(g))throw new Error("effect-missing-or-overwrite");E(e.workspacePath,g);const _=R(i(e.workspacePath,g));if(!_.isFile()||_.size<1)throw new Error("effect-empty");const v=new TextDecoder("utf-8",{fatal:!0}).decode(l(i(e.workspacePath,g))),O=n.interactions.find(j=>j.filePath===g);if(g!==n.providerPath&&!O)throw new Error("private-execution-pact-interaction-missing");const A=De(g,v,s.answers.brokerUrl,O,e.workspacePath);A.consumerBinding==="app-import-candidate"&&P++,A.consumerBinding==="mock-only-scaffold"&&d++}let p=n.paths;if(a){const g=Ce(e.sourceRoot,s.answers.generateProvider),_=v=>F("sha256").update(v).digest("hex");if(a.schemaVersion!==1||a.outcome!=="candidate-unverified"||a.executionVerified!==!1||a.sourceManifestSha256!==_(g.sourceText)||a.sourceLockSha256!==(g.sourceLockText===null?null:_(g.sourceLockText))||a.manifestText!==g.candidateText||!pe(e.sourceRoot,e.workspacePath,e.baseSha,"package.json")||!pe(e.sourceRoot,e.workspacePath,e.baseSha,"package-lock.json"))throw new Error("toolchain-binding-invalid");for(const v of["package.json","package-lock.json"]){E(e.sourceRoot,v),E(e.workspacePath,v);const O=v==="package.json"?g.sourceText:g.sourceLockText,A=re(i(e.workspacePath,v))?l(i(e.workspacePath,v),"utf8"):null;if(O!==A)throw new Error("toolchain-clone-raced")}if(Ee(i(e.workspacePath,"package.json"),a.manifestText),Ee(i(e.workspacePath,"package-lock.json"),a.lockText),Le(e.workspacePath,s.answers.generateProvider).outcome!=="manifest-aligned")throw new Error("toolchain-candidate-invalid");p=[...n.paths,"package.json","package-lock.json"]}const f=W(e,p,e.baseSha);return Object.freeze({...f,consumerBindingCandidateCount:P,consumerScaffoldCount:d})}catch{throw new Error("private-execution-pact-admission-unverified")}}export{lt as admitPrivateArchitectureStageWorkspace,at as admitPrivateEpicClaimWorkspace,dt as admitPrivateGenerateEpicWorkspace,ct as admitPrivateIdeaDiagnosisWorkspace,ht as admitPrivateIdeaResearchWorkspace,gt as admitPrivatePactWorkspace,ft as admitPrivateProjectStepWorkspace,ut as admitPrivateStateBoundStepWorkspace,pt as admitPrivateUxWorkspace,it as admitPrivateYoloFrozenWorkspace,st as verifyPrivateYoloSnapshotBoundary};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{execFileSync as k,spawnSync as A}from"node:child_process";import{createHash as x}from"node:crypto";import{existsSync as q,mkdirSync as C,readFileSync as D}from"node:fs";import{homedir as z}from"node:os";import{join as T,resolve as p}from"node:path";import{acquireGitLifecyclePhysicalIntegrationLock as N,assertGitLifecyclePrivateFile as B,ensureGitLifecyclePrivateChildDirectory as j,gitLifecycleRuntimeDirectory as H,readGitLifecycleRuntimeSync as L,releaseGitLifecyclePhysicalIntegrationLock as $}from"../git/git-lifecycle-store.js";import{anchoredAtomicWriteFile as Y}from"../git/secure-filesystem-boundary.js";import{readPrivateYoloFrozenWriteSet as d,readPrivateYoloFrozenWriteSetForTransition as F}from"./clean-baseline.js";import{admitPrivateYoloFrozenWorkspace as M,verifyPrivateYoloSnapshotBoundary as m}from"./isolated-admission.js";import{preparePrivateYoloIsolatedWorkspace as J}from"./isolated-workspace.js";function l(n,t){const e={...process.env};for(const s of["GIT_DIR","GIT_WORK_TREE","GIT_INDEX_FILE","GIT_OBJECT_DIRECTORY","GIT_ALTERNATE_OBJECT_DIRECTORIES","GIT_COMMON_DIR","GIT_NAMESPACE","GIT_CEILING_DIRECTORIES"])delete e[s];return k("git",[...t],{cwd:n,env:e,encoding:"utf8",stdio:["ignore","pipe","pipe"],timeout:3e4,maxBuffer:16*1024*1024}).trim()}function y(n,t){const e={...process.env};for(const s of["GIT_DIR","GIT_WORK_TREE","GIT_INDEX_FILE","GIT_OBJECT_DIRECTORY","GIT_ALTERNATE_OBJECT_DIRECTORIES","GIT_COMMON_DIR","GIT_NAMESPACE","GIT_CEILING_DIRECTORIES"])delete e[s];return k("git",[...t],{cwd:n,env:e,stdio:["ignore","pipe","pipe"],timeout:3e4,maxBuffer:16*1024*1024})}function b(n,t){const e={...process.env};for(const
|
|
2
|
-
`)}async function E(n,t,e,s){const
|
|
1
|
+
import{execFileSync as k,spawnSync as A}from"node:child_process";import{createHash as x}from"node:crypto";import{existsSync as q,mkdirSync as C,readFileSync as D}from"node:fs";import{homedir as z}from"node:os";import{join as T,resolve as p}from"node:path";import{acquireGitLifecyclePhysicalIntegrationLock as N,assertGitLifecyclePrivateFile as B,ensureGitLifecyclePrivateChildDirectory as j,gitLifecycleRuntimeDirectory as H,readGitLifecycleRuntimeSync as L,releaseGitLifecyclePhysicalIntegrationLock as $}from"../git/git-lifecycle-store.js";import{anchoredAtomicWriteFile as Y}from"../git/secure-filesystem-boundary.js";import{readPrivateYoloFrozenWriteSet as d,readPrivateYoloFrozenWriteSetForTransition as F}from"./clean-baseline.js";import{admitPrivateYoloFrozenWorkspace as M,verifyPrivateYoloSnapshotBoundary as m}from"./isolated-admission.js";import{preparePrivateYoloIsolatedWorkspace as J}from"./isolated-workspace.js";function l(n,t){const e={...process.env};for(const s of["GIT_DIR","GIT_WORK_TREE","GIT_INDEX_FILE","GIT_OBJECT_DIRECTORY","GIT_ALTERNATE_OBJECT_DIRECTORIES","GIT_COMMON_DIR","GIT_NAMESPACE","GIT_CEILING_DIRECTORIES"])delete e[s];return k("git",[...t],{cwd:n,env:e,encoding:"utf8",stdio:["ignore","pipe","pipe"],timeout:3e4,maxBuffer:16*1024*1024}).trim()}function y(n,t){const e={...process.env};for(const s of["GIT_DIR","GIT_WORK_TREE","GIT_INDEX_FILE","GIT_OBJECT_DIRECTORY","GIT_ALTERNATE_OBJECT_DIRECTORIES","GIT_COMMON_DIR","GIT_NAMESPACE","GIT_CEILING_DIRECTORIES"])delete e[s];return k("git",[...t],{cwd:n,env:e,stdio:["ignore","pipe","pipe"],timeout:3e4,maxBuffer:16*1024*1024})}function b(n,t){const e={...process.env};for(const o of["GIT_DIR","GIT_WORK_TREE","GIT_INDEX_FILE","GIT_OBJECT_DIRECTORY","GIT_ALTERNATE_OBJECT_DIRECTORIES","GIT_COMMON_DIR","GIT_NAMESPACE","GIT_CEILING_DIRECTORIES"])delete e[o];const s=A("git",[...t],{cwd:n,env:e,stdio:"ignore",timeout:3e4});if(s.error||s.signal)throw new Error("git-unverified");return s.status===0}async function P(n,t){const e=await H(n),s=await j(e,"private-execution"),o=`session-${x("sha256").update(t).digest("hex")}.json`;return{parent:s,name:o,path:T(s,o)}}function h(n,t){const e=t.split(".")[0],o=L(n,{required:!0}).epics[e]?.branch_lease,i=o&&typeof o=="object"&&!Array.isArray(o)?o:void 0,r=i?.sessionId;if(i?.ownerStoryId!==t||typeof r!="string"||!/^setup-[a-f0-9]{64}$/.test(r)||r!==i.idempotencyKey)throw new Error("session-lease-invalid");return r}function W(n){const t=JSON.parse(n);if(!t||typeof t!="object"||Array.isArray(t))throw new Error("session-invalid");const e=t,s=e.workspace;if(Object.keys(e).sort().join(",")!==["schemaVersion","kind","storyId","initialGraphRevision","graphRevision","graphHistory","setupSessionId","workspace","snapshotSha","sequence","lastPatchSha256"].sort().join(",")||e.schemaVersion!==1||e.kind!=="private-yolo-isolated-session"||typeof e.storyId!="string"||!/^[A-Za-z][A-Za-z0-9_-]*\.[A-Za-z0-9._-]+$/.test(e.storyId)||typeof e.initialGraphRevision!="string"||!/^[a-f0-9]{64}$/.test(e.initialGraphRevision)||typeof e.graphRevision!="string"||!/^[a-f0-9]{64}$/.test(e.graphRevision)||!Array.isArray(e.graphHistory)||e.graphHistory.length<1||e.graphHistory.length>65||e.graphHistory.some(i=>typeof i!="string"||!/^[a-f0-9]{64}$/.test(i))||new Set(e.graphHistory).size!==e.graphHistory.length||e.graphHistory[0]!==e.initialGraphRevision||e.graphHistory[e.graphHistory.length-1]!==e.graphRevision||typeof e.setupSessionId!="string"||!/^setup-[a-f0-9]{64}$/.test(e.setupSessionId)||typeof e.snapshotSha!="string"||!/^[a-f0-9]{40,64}$/.test(e.snapshotSha)||!Number.isSafeInteger(e.sequence)||Number(e.sequence)<0||Number(e.sequence)>64||Number(e.sequence)===0&&e.initialGraphRevision!==e.graphRevision||Number(e.sequence)===0&&e.lastPatchSha256!==null||Number(e.sequence)>0&&e.lastPatchSha256===null||e.lastPatchSha256!==null&&(typeof e.lastPatchSha256!="string"||!/^[a-f0-9]{64}$/.test(e.lastPatchSha256))||!s||typeof s!="object"||Array.isArray(s))throw new Error("session-invalid");const o=s;if(Object.keys(o).sort().join(",")!==["schemaVersion","sourceRoot","workspacePath","baseSha","executionBranch"].sort().join(",")||o.schemaVersion!==1||typeof o.sourceRoot!="string"||typeof o.workspacePath!="string"||typeof o.baseSha!="string"||!/^[a-f0-9]{40,64}$/.test(o.baseSha)||typeof o.executionBranch!="string"||!o.executionBranch)throw new Error("session-invalid");return e}async function f(n,t){const e=await P(n,t);if(q(e.path))return await B(e.path,e.parent),W(D(e.path,"utf8"))}async function v(n,t){const e=await P(n,t.storyId);await Y(e.parent,e.name,`${JSON.stringify(t)}
|
|
2
|
+
`)}async function E(n,t,e,s){const o=await N(n,{kind:"direct",storyId:t,sessionId:e,idempotencyKey:e,expiresAt:new Date(Date.now()+3e5).toISOString(),persistent:!1});if(!o.ok)throw new Error("private-execution-isolated-session-backpressure");try{return await s()}finally{if(!await $(o.path,o.owner))throw new Error("private-execution-isolated-session-lock-unverified")}}async function g(n,t,e,s){G(n,t,e,s);const o=await d(t,e,n.workspace.executionBranch,s);m(n.workspace,o,n.snapshotSha)}function G(n,t,e,s){if(n.storyId!==e||n.graphRevision!==s||n.workspace.sourceRoot!==t||n.setupSessionId!==h(t,e)||n.sequence===0&&n.snapshotSha!==n.workspace.baseSha||n.sequence>0&&n.snapshotSha===n.workspace.baseSha)throw new Error("session-binding-invalid")}async function ie(n,t,e){const s=p(n.sourceRoot);try{const o=h(s,t);return await E(s,t,o,async()=>{const i=await f(s,t);if(i){if(await g(i,s,t,e),i.workspace.workspacePath!==n.workspacePath)throw new Error("session-replacement-denied");return i}const r=await d(s,t,n.executionBranch,e);m(n,r,n.baseSha);const c=Object.freeze({schemaVersion:1,kind:"private-yolo-isolated-session",storyId:t,initialGraphRevision:e,graphRevision:e,graphHistory:[e],setupSessionId:o,workspace:n,snapshotSha:n.baseSha,sequence:0,lastPatchSha256:null});return await v(s,c),c})}catch{throw new Error("private-execution-isolated-session-unverified")}}async function R(n,t,e,s){if(n.graphRevision===s)return await g(n,t,e,s),n;if(n.storyId!==e||n.workspace.sourceRoot!==t||n.setupSessionId!==h(t,e)||n.sequence===0||n.lastPatchSha256===null||n.graphHistory.includes(s)||n.graphHistory.length>=65)throw new Error("session-graph-transition-invalid");const o=await F(t,e,n.workspace.executionBranch,n.initialGraphRevision,s);m(n.workspace,o,n.snapshotSha);const i=Object.freeze({...n,graphRevision:s,graphHistory:Object.freeze([...n.graphHistory,s])});return await v(t,i),await g(i,t,e,s),i}async function oe(n,t,e){const s=p(n);try{const o=h(s,t);return await E(s,t,o,async()=>{const i=await f(s,t);if(!i)throw new Error("session-missing");return R(i,s,t,e)})}catch{throw new Error("private-execution-isolated-session-unverified")}}async function ae(n,t,e,s){const o=p(n);try{const i=h(o,t);return await E(o,t,i,async()=>{const r=await f(o,t);if(r)return R(r,o,t,e);const c=s??T(z(),".local","share","neocortex","private-yolo-workspaces");s===void 0&&C(c,{recursive:!0,mode:448});const a=J(o,c),u=await d(o,t,a.executionBranch,e);m(a,u,a.baseSha);const w=Object.freeze({schemaVersion:1,kind:"private-yolo-isolated-session",storyId:t,initialGraphRevision:e,graphRevision:e,graphHistory:[e],setupSessionId:i,workspace:a,snapshotSha:a.baseSha,sequence:0,lastPatchSha256:null});return await v(o,w),w})}catch{throw new Error("private-execution-isolated-session-unverified")}}async function re(n,t,e){const s=p(n);try{const o=await f(s,t);if(!o)throw new Error("session-missing");return await g(o,s,t,e),o}catch{throw new Error("private-execution-isolated-session-unverified")}}async function ce(n,t,e){const s=p(n);try{const o=h(s,t);return await E(s,t,o,async()=>{const i=await f(s,t);if(!i)throw new Error("session-missing");G(i,s,t,e);const r=await M(i.workspace,t,e,i.snapshotSha,i.sequence===0);l(i.workspace.workspacePath,["add","-A","--",...r.changedPaths]),l(i.workspace.workspacePath,["-c","core.hooksPath=/dev/null","-c","commit.gpgsign=false","-c","user.name=Neocortex Private Session","-c","user.email=private-session@neocortex.invalid","commit","-q","-m",`private snapshot ${t} ${i.sequence+1}`]);const c=l(i.workspace.workspacePath,["rev-parse","HEAD"]),a=await d(s,t,i.workspace.executionBranch,e);m(i.workspace,a,c);const u=Object.freeze({...i,snapshotSha:c,sequence:i.sequence+1,lastPatchSha256:r.patchSha256});return await v(s,u),{session:u,admission:r}})}catch{throw new Error("private-execution-isolated-session-unverified")}}async function he(n,t,e){const s=p(n);try{const o=h(s,t);return await E(s,t,o,async()=>{const i=await f(s,t);if(!i||i.sequence<1)throw new Error("session-incomplete");await g(i,s,t,e);const r=await d(s,t,i.workspace.executionBranch,e),c=i.workspace.workspacePath,a=y(c,["diff","--name-only","-z",i.workspace.baseSha,i.snapshotSha]).toString("utf8").split("\0").filter(Boolean).sort(),u=[".neocortex/state.json",`docs/stories/${t}.story.md`,`.neocortex/stories/${t}/qa-gate-result.json`,`.neocortex/stories/${t}/validation-evidence.md`,`.neocortex/stories/${t}/review.md`];if(a.length===0||a.length>1024||new Set(a).size!==a.length||a.some(S=>!r.includes(S))||u.some(S=>!a.includes(S)))throw new Error("bundle-incomplete");if(!b(s,["diff","--cached","--quiet"])||y(s,["ls-files","-u","-z"]).byteLength!==0)throw new Error("index-not-clean");const w=y(c,["diff","--binary","--full-index",i.workspace.baseSha,i.snapshotSha]);if(w.byteLength===0)throw new Error("bundle-empty");l(s,["add","-A","--",...a]);const I=y(s,["diff","--cached","--binary","--full-index"]),_=y(s,["diff","--cached","--name-only","-z"]).toString("utf8").split("\0").filter(Boolean).sort();if(!I.equals(w)||_.length!==a.length||_.some((S,O)=>S!==a[O])||!b(s,["diff","--quiet"])||l(s,["rev-parse","HEAD"])!==i.workspace.baseSha||l(s,["symbolic-ref","--quiet","--short","HEAD"])!==i.workspace.executionBranch)throw new Error("bundle-raced");return Object.freeze({schemaVersion:1,outcome:"staged-unverified",snapshotSha:i.snapshotSha,bundleSha256:x("sha256").update(I).digest("hex"),changedPaths:Object.freeze(a)})})}catch{throw new Error("private-execution-root-stage-unverified")}}export{ce as admitPrivateYoloIsolatedSessionStep,ie as beginPrivateYoloIsolatedSession,ae as ensurePrivateYoloIsolatedSession,oe as reconcilePrivateYoloIsolatedSession,re as resumePrivateYoloIsolatedSession,he as stagePrivateYoloIsolatedSessionBundle};
|
|
@@ -5,7 +5,15 @@ export interface PrivateYoloIsolatedWorkspaceV1 {
|
|
|
5
5
|
readonly baseSha: string;
|
|
6
6
|
readonly executionBranch: string;
|
|
7
7
|
}
|
|
8
|
+
export interface PrivateProjectStepBaselineV1 {
|
|
9
|
+
readonly headSha: string;
|
|
10
|
+
readonly stateSha256: string;
|
|
11
|
+
}
|
|
8
12
|
export declare const PRIVATE_EPIC_PENDING_SIDECAR = ".neocortex/pending-epic-claims.json";
|
|
13
|
+
/** Pin the request's physical source before projecting a private project-step snapshot. */
|
|
14
|
+
export declare function capturePrivateProjectStepBaseline(projectRoot: string): PrivateProjectStepBaselineV1;
|
|
15
|
+
/** A later commit or state rewrite cannot execute against an older server lease. */
|
|
16
|
+
export declare function assertPrivateProjectStepBaseline(workspace: PrivateYoloIsolatedWorkspaceV1, baseline: PrivateProjectStepBaselineV1): void;
|
|
9
17
|
/**
|
|
10
18
|
* Build a separate object store and index from a clean, committed checkout.
|
|
11
19
|
* The caller must retain the workspace until its bytes are independently
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{execFileSync as
|
|
1
|
+
import{execFileSync as v}from"node:child_process";import{createHash as S}from"node:crypto";import{chmodSync as I,existsSync as D,lstatSync as h,mkdtempSync as _,readFileSync as w,realpathSync as l}from"node:fs";import{isAbsolute as E,join as u,resolve as d}from"node:path";const y=".neocortex/pending-epic-claims.json";function p(e,t){const s={...process.env};for(const r of["GIT_DIR","GIT_WORK_TREE","GIT_INDEX_FILE","GIT_OBJECT_DIRECTORY","GIT_ALTERNATE_OBJECT_DIRECTORIES","GIT_COMMON_DIR","GIT_NAMESPACE","GIT_CEILING_DIRECTORIES"])delete s[r];return v("git",[...t],{cwd:e,env:s,stdio:["ignore","pipe","pipe"],timeout:3e4,maxBuffer:16*1024*1024})}function c(e,t){return p(e,t).toString("utf8").trim()}function m(e,t,s,r=!1){const n=p(e,["status","--porcelain=v1","-z","--untracked-files=all"]).toString("utf8");let a=!r;if(r)try{const i=h(u(e,".neocortex")),o=h(u(e,y));a=i.isDirectory()&&!i.isSymbolicLink()&&i.uid===process.getuid?.()&&(i.mode&18)===0&&o.isFile()&&!o.isSymbolicLink()&&o.uid===process.getuid?.()&&(o.mode&63)===0&&o.size>0&&o.size<=128*1024}catch{a=!1}return c(e,["rev-parse","HEAD"])===t&&c(e,["symbolic-ref","--quiet","--short","HEAD"])===s&&a&&(n.length===0||r&&n===`?? ${y}\0`)}function f(e){const t=u(e,".neocortex","state.json"),s=h(t);if(!s.isFile()||s.isSymbolicLink())throw new Error("state-invalid");return S("sha256").update(w(t)).digest("hex")}function g(e){try{const t=c(e,["rev-parse","--verify","HEAD"]);if(!/^[a-f0-9]{40,64}$/.test(t))throw new Error("head-invalid");return Object.freeze({headSha:t,stateSha256:f(e)})}catch{throw new Error("private-execution-project-snapshot-unverified")}}function b(e,t){try{if(e.baseSha!==t.headSha||c(e.sourceRoot,["rev-parse","--verify","HEAD"])!==t.headSha||f(e.sourceRoot)!==t.stateSha256||f(e.workspacePath)!==t.stateSha256)throw new Error("snapshot-mismatch")}catch{throw new Error("private-execution-project-snapshot-unverified")}}function C(e,t,s=!1){let r,n;try{if(process.platform!=="linux"||typeof process.getuid!="function"||!E(e)||!E(t))throw new Error("path-invalid");if(r=d(e),n=d(t),l(r)!==r||!h(r).isDirectory()||l(n)!==n||!h(n).isDirectory()||h(n).uid!==process.getuid()||(h(n).mode&18)!==0||c(r,["rev-parse","--show-toplevel"])!==r)throw new Error("path-invalid");const a=c(r,["rev-parse","HEAD"]),i=c(r,["symbolic-ref","--quiet","--short","HEAD"]);if(!/^[a-f0-9]{40,64}$/.test(a)||!i||!m(r,a,i,s))throw new Error("source-dirty");const o=_(u(n,"p222-private-yolo-"));if(I(o,448),p(o,["init","-q"]),p(o,["fetch","-q","--no-tags","--depth=1",r,a]),p(o,["checkout","-q","-b",i,"FETCH_HEAD"]),!m(r,a,i,s)||c(o,["rev-parse","HEAD"])!==a||c(o,["symbolic-ref","--quiet","--short","HEAD"])!==i||p(o,["status","--porcelain=v1","-z","--untracked-files=all"]).byteLength!==0||D(u(o,".git","objects","info","alternates")))throw new Error("physical-mismatch");return Object.freeze({schemaVersion:1,sourceRoot:r,workspacePath:o,baseSha:a,executionBranch:i})}catch{throw new Error("private-execution-isolated-workspace-unverified")}}export{y as PRIVATE_EPIC_PENDING_SIDECAR,b as assertPrivateProjectStepBaseline,g as capturePrivateProjectStepBaseline,C as preparePrivateYoloIsolatedWorkspace};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type PactWriteSetV1 } from './pact-write-set.js';
|
|
2
|
+
type Reason = 'consumer-proven' | 'toolchain-unavailable' | 'app-binding-missing' | 'source-unsupported' | 'install-failed' | 'sandbox-unavailable' | 'consumer-failed' | 'pact-artifact-missing' | 'mutation-not-causal';
|
|
3
|
+
export interface PactConsumerRuntimeReceiptV1 {
|
|
4
|
+
readonly schemaVersion: 1;
|
|
5
|
+
readonly outcome: 'consumer-proven' | 'unverified';
|
|
6
|
+
readonly reasonCode: Reason;
|
|
7
|
+
readonly sourceRevision: string | null;
|
|
8
|
+
readonly filesSha256: string | null;
|
|
9
|
+
readonly expectedInteractions: number;
|
|
10
|
+
readonly passedTests: number;
|
|
11
|
+
readonly mutationFailedTests: number;
|
|
12
|
+
readonly appConsumerProven: boolean;
|
|
13
|
+
readonly providerVerified: false;
|
|
14
|
+
readonly qaAccepted: false;
|
|
15
|
+
readonly publicSafe: true;
|
|
16
|
+
}
|
|
17
|
+
/** Only aggregate causal evidence leaves this process; private reports are removed. */
|
|
18
|
+
export declare function verifyPactConsumerRuntime(projectRoot: string, expectedWriteSet: PactWriteSetV1, generateProvider: boolean): PactConsumerRuntimeReceiptV1;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import{spawnSync as O}from"node:child_process";import{createHash as Z}from"node:crypto";import{constants as z}from"node:fs";import{closeSync as J,existsSync as w,fstatSync as W,lstatSync as R,mkdirSync as G,mkdtempSync as K,openSync as Q,readFileSync as ee,readdirSync as te,realpathSync as se,rmSync as ne,writeFileSync as P}from"node:fs";import{tmpdir as oe}from"node:os";import{dirname as re,join as m,posix as T,resolve as ie}from"node:path";import{isDeepStrictEqual as ae}from"node:util";import{parse as F}from"@babel/parser";import{derivePactWriteSet as ce}from"./pact-write-set.js";import{validatePactTestSource as ue}from"./pact-test-source.js";import{inspectPactToolchain as pe,planPactToolchainManifest as le}from"./pact-toolchain.js";const fe=1024,de=16*1024*1024,me=2*1024*1024,I="P222_APP_CONSUMER_CAUSAL_CANARY",B=/^(?:src|app|lib|packages|clients)\//,ye=/\.(?:ts|tsx|js|jsx|mjs|cjs|json)$/;class U extends Error{reason;constructor(c){super(c),this.reason=c}}function n(p){throw new U(p)}function L(p,c,i,o,l=0,u=0){const s=p==="consumer-proven";return Object.freeze({schemaVersion:1,outcome:s?"consumer-proven":"unverified",reasonCode:p,sourceRevision:c,filesSha256:i,expectedInteractions:o,passedTests:l,mutationFailedTests:u,appConsumerProven:s,providerVerified:!1,qaAccepted:!1,publicSafe:!0})}function A(p,c,i){let o=p;for(const s of c.split("/").slice(0,-1)){o=m(o,s);const e=R(o);(!e.isDirectory()||e.isSymbolicLink())&&n("source-unsupported")}const l=m(p,c),u=Q(l,z.O_RDONLY|z.O_NOFOLLOW);try{const s=W(u);return(!s.isFile()||s.size<1||s.size>i)&&n("source-unsupported"),ee(u)}finally{J(u)}}function _(p,c){const i={PATH:process.env.PATH,HOME:process.env.HOME},o=O("git",c,{cwd:p,env:i,timeout:3e4,maxBuffer:2*1024*1024,stdio:["ignore","pipe","ignore"]});return(o.error||o.status!==0||!Buffer.isBuffer(o.stdout))&&n("source-unsupported"),o.stdout}function ge(p,c,i){const o=new Map,l=F(c,{sourceType:"module",plugins:["typescript"]});for(const u of l.program.body){if(u.type!=="ImportDeclaration"||u.source.value==="@pact-foundation/pact"||u.source.value==="vitest")continue;const s=u.source.value;/^\.\.?\/[A-Za-z0-9_./-]{1,240}$/.test(s)||n("source-unsupported");const e=T.normalize(T.join(T.dirname(p),s));(!B.test(e)||e.split("/").includes(".."))&&n("source-unsupported");const a=(/\.(?:ts|tsx|js|mjs)$/.test(e)?[e,...e.endsWith(".js")?[`${e.slice(0,-3)}.ts`,`${e.slice(0,-3)}.tsx`]:[]]:[`${e}.ts`,`${e}.tsx`,`${e}.js`,`${e}.mjs`,`${e}/index.ts`,`${e}/index.tsx`,`${e}/index.js`]).filter(f=>i.has(f));a.length!==1&&n("source-unsupported");const y=o.get(a[0])??new Set;for(const f of u.specifiers){f.type==="ImportNamespaceSpecifier"&&n("source-unsupported");const g=f.type==="ImportDefaultSpecifier"?"default":f.imported.type==="Identifier"?f.imported.name:f.imported.value;/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(g)||n("source-unsupported"),y.add(g)}y.size===0&&n("source-unsupported"),o.set(a[0],y)}return o}function he(p){const i=[F(p,{sourceType:"module",plugins:["typescript"]}).program];let o=null,l=0;for(;i.length>0;){const u=i.pop();if(!u||typeof u!="object"||Array.isArray(u))continue;++l>1e5&&n("source-unsupported");const s=u;if(s.type==="NewExpression"&&s.callee&&typeof s.callee=="object"&&s.callee.type==="Identifier"&&s.callee.name==="PactV3"){(o!==null||!Array.isArray(s.arguments)||s.arguments.length!==1)&&n("source-unsupported");const e=s.arguments[0];(!e||e.type!=="ObjectExpression"||!Array.isArray(e.properties))&&n("source-unsupported");let t="pacts",a=!1;for(const y of e.properties){const f=y;(f.type!=="ObjectProperty"||f.computed===!0)&&n("source-unsupported");const g=f.key;if((g.type==="Identifier"?g.name:g.type==="StringLiteral"?g.value:void 0)!=="dir")continue;a&&n("source-unsupported"),a=!0;const b=f.value;(b.type!=="StringLiteral"||typeof b.value!="string")&&n("source-unsupported"),b.value==="./pact-files"||b.value==="pact-files"?t="pact-files":b.value!=="./pacts"&&b.value!=="pacts"&&n("source-unsupported")}o=t}for(const[e,t]of Object.entries(s))["loc","extra","comments","leadingComments","trailingComments","innerComments"].includes(e)||(Array.isArray(t)?i.push(...t):t&&typeof t=="object"&&i.push(t))}return o===null&&n("source-unsupported"),o}function be(p,c){const i=["--die-with-parent","--new-session","--unshare-all","--clearenv","--setenv","HOME","/work","--setenv","TMPDIR","/tmp","--setenv","PATH","/home/linuxbrew/.linuxbrew/bin:/usr/bin:/bin","--setenv","CI","true","--setenv","NODE_ENV","test","--ro-bind","/usr","/usr","--ro-bind","/lib","/lib","--ro-bind","/lib64","/lib64","--ro-bind","/bin","/bin","--ro-bind","/etc","/etc"];return w("/home/linuxbrew/.linuxbrew")&&i.push("--ro-bind","/home/linuxbrew/.linuxbrew","/home/linuxbrew/.linuxbrew"),[...i,"--dev","/dev","--proc","/proc","--tmpfs","/tmp","--bind",p,"/work","--chdir","/work","--",process.execPath,"node_modules/vitest/vitest.mjs","run","--maxWorkers=1","tests/pact/consumer/","--reporter=json",`--outputFile=/work/${c}`]}function q(p,c){const i=O("/usr/bin/bwrap",be(p,c),{env:{PATH:"/usr/bin:/bin"},timeout:18e4,stdio:"ignore"});return(i.error||i.signal||i.status===null)&&n("sandbox-unavailable"),i.status}function X(p,c,i){w(m(p,c))||n("sandbox-unavailable");let o;try{o=JSON.parse(A(p,c,me).toString("utf8"))}catch{n("consumer-failed")}(!o||typeof o!="object"||Array.isArray(o))&&n("consumer-failed");const l=o.testResults;(!Array.isArray(l)||l.length!==i.length)&&n("consumer-failed");const u=new Map;for(const s of l){(!s||typeof s!="object"||Array.isArray(s))&&n("consumer-failed");const e=s;(typeof e.name!="string"||!i.some(t=>e.name===`/work/${t}`)||u.has(e.name)||!Array.isArray(e.assertionResults)||e.assertionResults.length<1)&&n("consumer-failed"),u.set(e.name,e)}return i.flatMap(s=>u.get(`/work/${s}`).assertionResults)}function ve(p,c){const i=p.split("/"),o=c.split("/");return i.length===o.length&&i.every((l,u)=>{const s=o[u];if(!l.includes("{"))return l===s;const e=/^([^{}]*)\{[^{}]+\}([^{}]*)$/.exec(l);return!!e&&s.startsWith(e[1])&&s.endsWith(e[2])&&s.length>e[1].length+e[2].length})}function Ae(p,c,i){const o=m(p,c);if(!w(o)||!R(o).isDirectory())return!1;const l=te(o).filter(e=>/^[A-Za-z0-9_.-]+\.json$/.test(e));if(l.length<1||l.length>16)return!1;const u=[];for(const e of l){let t;try{t=JSON.parse(A(o,e,1024*1024).toString("utf8"))}catch{return!1}if(!t||typeof t!="object"||Array.isArray(t))return!1;const a=t.interactions;if(!Array.isArray(a))return!1;for(const y of a){if(!y||typeof y!="object"||Array.isArray(y))return!1;const f=y.request;if(!f||typeof f!="object"||Array.isArray(f))return!1;const{method:g,path:h}=f;if(typeof g!="string"||typeof h!="string")return!1;u.push({method:g,path:h})}}const s=[...u];for(const e of i){const t=s.findIndex(a=>a.method.toUpperCase()===e.method&&ve(e.endpointPath,a.path));if(t===-1)return!1;s.splice(t,1)}return s.length===0}function Me(p,c,i){let o=null,l=null,u=0,s=0;const e=c.interactions.length;let t;try{(process.platform!=="linux"||!w("/usr/bin/bwrap"))&&n("sandbox-unavailable");const a=ie(p);(se(a)!==a||!R(a).isDirectory())&&n("source-unsupported"),o=_(a,["rev-parse","HEAD"]).toString("utf8").trim(),(!/^[a-f0-9]{40,64}$/.test(o)||_(a,["rev-parse","--show-toplevel"]).toString("utf8").trim()!==a)&&n("source-unsupported");const y=ce(a,i);(y.outcome!=="ready"||!ae(y.writeSet,c))&&n("source-unsupported"),pe(a,i).outcome!=="manifest-aligned"&&n("toolchain-unavailable"),le(a,i);const f=new Set(_(a,["ls-files","-z","--","src","app","lib","packages","clients"]).toString("utf8").split("\0").filter(Boolean)),g=[...f].filter(r=>B.test(r)&&ye.test(r));(g.length>fe||[...f].some(r=>r.includes("\\")||r.split("/").some(d=>!d||d==="."||d==="..")))&&n("source-unsupported");const h=c.interactions.map(r=>r.filePath);(new Set(h).size!==h.length||h.length<1)&&n("source-unsupported");const b=new Map,k=new Map;let x=null;for(const r of c.interactions){const d=A(a,r.filePath,262144),v=new TextDecoder("utf-8",{fatal:!0}).decode(d);ue(r.filePath,v,null,r,a).consumerBinding!=="app-import-candidate"&&n("app-binding-missing");const C=he(v);x!==null&&x!==C&&n("source-unsupported"),x=C;for(const[H,Y]of ge(r.filePath,v,f)){const N=k.get(H)??new Set;for(const V of Y)N.add(V);k.set(H,N)}b.set(r.filePath,d)}(k.size<1||x===null)&&n("app-binding-missing");const j=new Map([["package.json",A(a,"package.json",1024*1024)],["package-lock.json",A(a,"package-lock.json",8*1024*1024)],...b.entries()]);for(const r of g)j.set(r,A(a,r,1024*1024));[...j.values()].reduce((r,d)=>r+d.length,0)>de&&n("source-unsupported");const M=Z("sha256");for(const[r,d]of[...j.entries()].sort(([v],[S])=>v<S?-1:v>S?1:0))M.update(r).update("\0").update(d).update("\0");l=M.digest("hex"),t=K(m(oe(),"p222-pact-runtime-"));for(const r of["package.json","package-lock.json"])P(m(t,r),j.get(r),{mode:384});P(m(t,"user.npmrc"),"",{mode:384}),P(m(t,"global.npmrc"),"",{mode:384});const D=O("npm",["ci","--ignore-scripts","--no-audit","--no-fund","--registry=https://registry.npmjs.org/",`--userconfig=${m(t,"user.npmrc")}`,`--globalconfig=${m(t,"global.npmrc")}`],{cwd:t,env:{PATH:process.env.PATH,HOME:t,TMPDIR:t,npm_config_cache:m(t,".npm-cache"),CI:"true",NO_UPDATE_NOTIFIER:"1"},timeout:18e4,stdio:"ignore"});(D.error||D.status!==0)&&n("install-failed");for(const[r,d]of j)r==="package.json"||r==="package-lock.json"||(G(m(t,re(r)),{recursive:!0,mode:448}),P(m(t,r),d,{mode:384}));q(t,"positive.json")!==0&&n(w(m(t,"positive.json"))?"consumer-failed":"sandbox-unavailable");const $=X(t,"positive.json",h);($.some(r=>r.status!=="passed")||!Ae(t,x,c.interactions))&&n("pact-artifact-missing"),u=$.length;for(const[r,d]of k){const v=[...d].map(S=>S==="default"?`export default function(){throw new Error('${I}')}`:`export const ${S}=function(){throw new Error('${I}')}`).join(`
|
|
2
|
+
`);P(m(t,r),`${v}
|
|
3
|
+
`,{mode:384})}(q(t,"mutation.json")===0||!w(m(t,"mutation.json")))&&n("mutation-not-causal");const E=X(t,"mutation.json",h);return(E.length!==$.length||E.some(r=>r.status!=="failed"||!Array.isArray(r.failureMessages)||!r.failureMessages.some(d=>typeof d=="string"&&d.includes(I))))&&n("mutation-not-causal"),s=E.length,(_(a,["rev-parse","HEAD"]).toString("utf8").trim()!==o||[...j].some(([r,d])=>!A(a,r,8*1024*1024).equals(d)))&&n("source-unsupported"),L("consumer-proven",o,l,e,u,s)}catch(a){const y=a instanceof U?a.reason:"source-unsupported";return L(y,o,l,e,u,s)}finally{t&&ne(t,{recursive:!0,force:!0})}}export{Me as verifyPactConsumerRuntime};
|