@ornexus/neocortex 4.60.73 → 4.60.75
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/release-source.json +1 -1
- package/dist/sbom.cdx.json +1216 -1210
- package/install.ps1 +1 -1
- package/install.sh +1 -1
- package/package.json +2 -2
- package/packages/client/dist/adapters/adapter-registry.js +1 -108
- package/packages/client/dist/adapters/antigravity-adapter.js +2 -77
- package/packages/client/dist/adapters/claude-code-adapter.js +3 -79
- package/packages/client/dist/adapters/codex-adapter.js +2 -80
- package/packages/client/dist/adapters/cursor-adapter.js +4 -115
- package/packages/client/dist/adapters/gemini-adapter.js +2 -71
- package/packages/client/dist/adapters/grok-adapter.js +2 -42
- package/packages/client/dist/adapters/index.js +1 -22
- package/packages/client/dist/adapters/platform-detector.js +1 -212
- package/packages/client/dist/adapters/target-adapter.js +0 -12
- package/packages/client/dist/adapters/vscode-adapter.js +2 -72
- package/packages/client/dist/agent/refresh-stubs.js +2 -417
- package/packages/client/dist/agent/update-agent-yaml.js +1 -102
- package/packages/client/dist/agent/update-description.js +1 -251
- package/packages/client/dist/cache/crypto-utils.js +1 -78
- package/packages/client/dist/cache/encrypted-cache.d.ts +27 -0
- package/packages/client/dist/cache/encrypted-cache.js +1 -108
- package/packages/client/dist/cache/in-memory-asset-cache.js +1 -73
- package/packages/client/dist/cache/index.js +1 -13
- package/packages/client/dist/cache/protected-pi-boundary.js +1 -44
- package/packages/client/dist/checkpoint/checkpoint-client-reader.js +2 -127
- package/packages/client/dist/checkpoint/index.js +1 -11
- package/packages/client/dist/checkpoint/shared-checkpoint-types.js +1 -32
- package/packages/client/dist/cli.js +5 -358
- package/packages/client/dist/commands/activate.js +8 -394
- package/packages/client/dist/commands/architecture-answers.js +7 -274
- package/packages/client/dist/commands/architecture-memory-terminal.js +4 -253
- package/packages/client/dist/commands/architecture-non-ui-continuation.js +1 -100
- package/packages/client/dist/commands/architecture-root-binding.js +1 -51
- package/packages/client/dist/commands/cache-status.js +2 -112
- package/packages/client/dist/commands/config.js +1 -88
- package/packages/client/dist/commands/doctor.js +2 -635
- package/packages/client/dist/commands/invoke.d.ts +38 -1
- package/packages/client/dist/commands/invoke.js +143 -7200
- package/packages/client/dist/commands/legacy-epic-terminal.js +1 -71
- package/packages/client/dist/commands/legacy-story-branch.js +1 -96
- package/packages/client/dist/commands/legacy-story-pr.js +1 -276
- package/packages/client/dist/commands/mutation-qa-checkpoint.js +5 -285
- package/packages/client/dist/commands/mutation-qa-gate.js +1 -54
- package/packages/client/dist/commands/mutation-qa-git.js +1 -41
- package/packages/client/dist/commands/mutation-qa-policy.js +1 -102
- package/packages/client/dist/commands/mutation-qa-run.js +3 -219
- package/packages/client/dist/commands/mutation-qa-verdict.js +1 -149
- package/packages/client/dist/commands/mutation-qa.js +1 -220
- package/packages/client/dist/commands/native-agent.js +2 -136
- package/packages/client/dist/commands/planning-diagnosis.js +1 -43
- package/packages/client/dist/commands/planning-generation.js +1 -53
- package/packages/client/dist/commands/planning-memory.js +1 -40
- package/packages/client/dist/commands/planning-research.js +1 -42
- package/packages/client/dist/commands/private-session.js +1 -75
- package/packages/client/dist/commands/property-qa.js +1 -139
- package/packages/client/dist/commands/qa-control.js +1 -16
- package/packages/client/dist/commands/qa-scan-browser-launch.js +1 -55
- package/packages/client/dist/commands/qa-scan-browser-route.js +1 -28
- package/packages/client/dist/commands/qa-scan-capture.js +5 -663
- package/packages/client/dist/commands/qa-scan-discovery.js +3 -376
- package/packages/client/dist/commands/qa-scan-review.js +5 -826
- package/packages/client/dist/commands/qa-synthetic-backend-capture.js +1 -266
- package/packages/client/dist/commands/qa-synthetic-backend-review.js +1 -297
- package/packages/client/dist/commands/qa-synthetic-backend.js +2 -340
- package/packages/client/dist/commands/qa-synthetic-broker-port.js +1 -85
- package/packages/client/dist/commands/qa-synthetic-browser.js +1 -39
- package/packages/client/dist/commands/refactor-characterization.js +21 -671
- package/packages/client/dist/commands/refactor-commit.js +13 -399
- package/packages/client/dist/commands/refactor-control.js +3 -142
- package/packages/client/dist/commands/refactor-cpp-assertions.js +3 -93
- package/packages/client/dist/commands/refactor-review.js +5 -283
- package/packages/client/dist/commands/refactor-root.js +7 -588
- package/packages/client/dist/commands/refresh-memory.js +3 -156
- package/packages/client/dist/commands/shared-architecture-non-ui.js +1 -24
- package/packages/client/dist/commands/story-checkpoint.js +1 -171
- package/packages/client/dist/config/host-auth-broker.d.ts +31 -0
- package/packages/client/dist/config/host-auth-broker.js +1 -0
- package/packages/client/dist/config/host-auth-reference.d.ts +32 -0
- package/packages/client/dist/config/host-auth-reference.js +1 -0
- package/packages/client/dist/config/profile-directory.js +1 -13
- package/packages/client/dist/config/resolver-selection.js +1 -278
- package/packages/client/dist/config/secure-config.js +12 -281
- package/packages/client/dist/config.js +2 -223
- package/packages/client/dist/constants.js +1 -25
- package/packages/client/dist/context/context-collector.js +2 -222
- package/packages/client/dist/context/context-sanitizer.js +1 -145
- package/packages/client/dist/continuity/autonomous-governance.js +1 -285
- package/packages/client/dist/continuity/continuity-client-state-store.js +1 -1587
- package/packages/client/dist/continuity/invoke-hooks.js +1 -129
- package/packages/client/dist/continuity/migrations/001-initial-schema.js +2 -12
- package/packages/client/dist/continuity/migrations/002-processing-output-summary-indexes.js +2 -12
- package/packages/client/dist/continuity/migrations/003-headless-execution-attempts.js +2 -12
- package/packages/client/dist/continuity/migrations/004-outbox-delivery-state.js +2 -12
- package/packages/client/dist/continuity/migrations/005-bounded-headless-queue.js +2 -12
- package/packages/client/dist/continuity/migrations/006-native-agent-dispatches.js +2 -10
- package/packages/client/dist/continuity/native-agent-store.js +1 -69
- package/packages/client/dist/continuity/native-agent-types.d.ts +11 -0
- package/packages/client/dist/continuity/native-agent-types.js +1 -90
- package/packages/client/dist/continuity/outbox.js +1 -117
- package/packages/client/dist/continuity/runner-bootstrap-policy.js +1 -172
- package/packages/client/dist/continuity/sqlite-store.js +81 -2612
- package/packages/client/dist/effects/invoke-effect-gateways.js +1 -62
- package/packages/client/dist/errors/error-messages.d.ts +3 -0
- package/packages/client/dist/errors/error-messages.js +2 -228
- package/packages/client/dist/errors/frontmatter-diagnostics.js +1 -125
- package/packages/client/dist/evidence/collector.js +1 -347
- package/packages/client/dist/evidence/index.js +1 -1
- package/packages/client/dist/evidence/types.js +0 -2
- package/packages/client/dist/fs/atomic-state-replace.js +1 -152
- package/packages/client/dist/generated/command-registry.generated.js +1 -4076
- package/packages/client/dist/generated/public-projections.generated.js +1 -149
- package/packages/client/dist/git/direct-yolo-c01-retry.js +4 -138
- package/packages/client/dist/git/direct-yolo-checkpoint.d.ts +11 -1
- package/packages/client/dist/git/direct-yolo-checkpoint.js +4 -1234
- package/packages/client/dist/git/epic-operational-state.js +2 -672
- package/packages/client/dist/git/git-lifecycle-step-ids.js +1 -14
- package/packages/client/dist/git/git-lifecycle-store.d.ts +23 -0
- package/packages/client/dist/git/git-lifecycle-store.js +10 -1981
- package/packages/client/dist/git/legacy-story-branch-checkpoint.js +9 -259
- package/packages/client/dist/git/legacy-story-branch-setup.js +4 -348
- package/packages/client/dist/git/legacy-story-pr.js +70 -3538
- package/packages/client/dist/git/secure-filesystem-boundary.js +5 -182
- package/packages/client/dist/graph-retrieval/pre-command-hook.js +1 -284
- package/packages/client/dist/graph-retrieval/shared-graph-retrieval-contract.js +1 -237
- package/packages/client/dist/i18n/first-run.js +2 -60
- package/packages/client/dist/index.d.ts +2 -0
- package/packages/client/dist/index.js +1 -47
- package/packages/client/dist/invocation/invoke-input.js +1 -24
- package/packages/client/dist/license/host-auth-recovery.d.ts +158 -0
- package/packages/client/dist/license/host-auth-recovery.js +1 -0
- package/packages/client/dist/license/index.js +1 -5
- package/packages/client/dist/license/license-client.d.ts +10 -1
- package/packages/client/dist/license/license-client.js +1 -304
- package/packages/client/dist/machine/fingerprint.js +2 -163
- package/packages/client/dist/machine/index.js +1 -5
- package/packages/client/dist/memory/project-memory-path-scope.js +1 -62
- package/packages/client/dist/memory/project-memory-writer.js +40 -1007
- package/packages/client/dist/memory/shared-project-memory-types.js +2 -253
- package/packages/client/dist/migrations/epic-lifecycle-backfill.js +3 -1060
- package/packages/client/dist/migrations/project-identity-capability.js +1 -50
- package/packages/client/dist/migrations/project-identity.js +7 -493
- package/packages/client/dist/migrations/state-json.js +4 -393
- package/packages/client/dist/policy/architecture-policy.js +2 -184
- package/packages/client/dist/policy/index.js +1 -7
- package/packages/client/dist/policy/shared-policy-types.js +0 -38
- package/packages/client/dist/policy/subagent-approval-policy.js +1 -55
- package/packages/client/dist/private-execution/clean-baseline.js +2 -279
- package/packages/client/dist/private-execution/codex-executor.js +4 -574
- package/packages/client/dist/private-execution/codex-host-runtime.js +1 -137
- package/packages/client/dist/private-execution/codex-lifecycle-guard.js +1 -97
- package/packages/client/dist/private-execution/codex-scoped-permissions.js +1 -128
- package/packages/client/dist/private-execution/delivery.js +13 -410
- package/packages/client/dist/private-execution/diagnosis-root-review.js +2 -294
- package/packages/client/dist/private-execution/frozen-handoff.js +6 -19
- package/packages/client/dist/private-execution/implementation-validation.js +2 -106
- package/packages/client/dist/private-execution/isolated-admission.js +23 -1432
- package/packages/client/dist/private-execution/isolated-session.js +5 -725
- package/packages/client/dist/private-execution/isolated-workspace.js +1 -122
- package/packages/client/dist/private-execution/pact-consumer-runtime.js +3 -409
- package/packages/client/dist/private-execution/pact-test-source.js +1 -258
- package/packages/client/dist/private-execution/pact-toolchain.js +3 -290
- package/packages/client/dist/private-execution/pact-write-set.js +1 -172
- package/packages/client/dist/private-execution/planning-diagnosis-checkpoint.js +5 -406
- package/packages/client/dist/private-execution/planning-generation-checkpoint.js +5 -462
- package/packages/client/dist/private-execution/planning-memory-checkpoint.js +3 -139
- package/packages/client/dist/private-execution/planning-research-checkpoint.js +4 -325
- package/packages/client/dist/private-execution/private-report-store.js +1 -42
- package/packages/client/dist/private-execution/property-test-candidate.js +1 -103
- package/packages/client/dist/private-execution/property-test-choices.js +3 -147
- package/packages/client/dist/private-execution/property-test-plan.js +7 -271
- package/packages/client/dist/private-execution/property-test-review.js +4 -258
- package/packages/client/dist/private-execution/property-test-runtime.js +9 -372
- package/packages/client/dist/private-execution/property-test-source.js +1 -139
- package/packages/client/dist/private-execution/root-checkpoint.js +1 -80
- package/packages/client/dist/private-execution/root-memory-git-evidence.js +3 -135
- package/packages/client/dist/private-execution/root-memory-recovery.js +1 -93
- package/packages/client/dist/private-execution/root-memory-request.js +1 -29
- package/packages/client/dist/private-execution/root-memory-scope.js +1 -178
- package/packages/client/dist/private-execution/root-memory-writer.js +1 -102
- package/packages/client/dist/private-execution/session-lease.js +1 -63
- package/packages/client/dist/private-execution/shared-private-admission-types.js +1 -50
- package/packages/client/dist/private-execution/shared-project-validation.js +1 -66
- package/packages/client/dist/private-execution/shared-root-memory-types.js +1 -61
- package/packages/client/dist/private-execution/ux-source-validation.js +1 -372
- package/packages/client/dist/private-execution/ux-write-set.js +2 -191
- package/packages/client/dist/registry/registry-reconciliation.js +1 -234
- package/packages/client/dist/resilience/circuit-breaker.js +1 -170
- package/packages/client/dist/resilience/degradation-manager.js +1 -164
- package/packages/client/dist/resilience/freshness-indicator.js +1 -100
- package/packages/client/dist/resilience/index.js +1 -8
- package/packages/client/dist/resilience/recovery-detector.js +1 -74
- package/packages/client/dist/resolvers/asset-resolver.js +0 -13
- package/packages/client/dist/resolvers/local-resolver.js +8 -255
- package/packages/client/dist/resolvers/remote-resolver.js +1 -233
- package/packages/client/dist/runner/binary.js +1 -404
- package/packages/client/dist/runner/cli.js +17 -1571
- package/packages/client/dist/runner/epic-background-dispatcher.d.ts +61 -0
- package/packages/client/dist/runner/epic-background-dispatcher.js +1 -0
- package/packages/client/dist/runner/headless/adapters.js +1 -49
- package/packages/client/dist/runner/headless/background-root.d.ts +65 -0
- package/packages/client/dist/runner/headless/background-root.js +1 -0
- package/packages/client/dist/runner/headless/claude-code-adapter.js +1 -79
- package/packages/client/dist/runner/headless/continuous-story-workspace.js +11 -1628
- package/packages/client/dist/runner/headless/epic-git-reconciliation-inventory.js +1 -69
- package/packages/client/dist/runner/headless/epic-merge-candidate-qa.d.ts +1 -1
- package/packages/client/dist/runner/headless/epic-merge-candidate-qa.js +2 -110
- package/packages/client/dist/runner/headless/epic-terminal-git-cli-adapter.d.ts +2 -0
- package/packages/client/dist/runner/headless/epic-terminal-git-cli-adapter.js +10 -1236
- package/packages/client/dist/runner/headless/epic-terminal-git-runner.d.ts +27 -2
- package/packages/client/dist/runner/headless/epic-terminal-git-runner.js +2 -318
- package/packages/client/dist/runner/headless/fake-adapter.js +1 -62
- package/packages/client/dist/runner/headless/managed-environment-cleanup.d.ts +95 -0
- package/packages/client/dist/runner/headless/managed-environment-cleanup.js +1 -0
- package/packages/client/dist/runner/headless/managed-profile.js +1 -132
- package/packages/client/dist/runner/headless/opencode-adapter.js +2 -145
- package/packages/client/dist/runner/headless/prepared-story-bundle.js +1 -43
- package/packages/client/dist/runner/headless/resolver.js +1 -231
- package/packages/client/dist/runner/headless/run-yolo.js +1 -885
- package/packages/client/dist/runner/headless/run-yoloop.d.ts +1 -0
- package/packages/client/dist/runner/headless/run-yoloop.js +2 -2574
- package/packages/client/dist/runner/headless/types.js +2 -574
- package/packages/client/dist/runner/local-console.js +13 -396
- package/packages/client/dist/runner/portal-sync-worker.js +1 -1487
- package/packages/client/dist/runner/project-identity.js +1 -106
- package/packages/client/dist/runner/scheduler.js +7 -995
- package/packages/client/dist/runner-cli.js +2 -18
- package/packages/client/dist/state/invocation-shape.js +1 -13
- package/packages/client/dist/state/project-state-snapshot.d.ts +7 -0
- package/packages/client/dist/state/project-state-snapshot.js +1 -1731
- package/packages/client/dist/state/state-json-repair.js +3 -785
- package/packages/client/dist/state/structural-dag-projection.js +1 -118
- package/packages/client/dist/telemetry/index.js +1 -5
- package/packages/client/dist/telemetry/offline-queue.js +1 -131
- package/packages/client/dist/tier/index.js +1 -5
- package/packages/client/dist/tier/tier-aware-client.js +1 -405
- package/packages/client/dist/types/index.js +1 -38
- package/packages/client/dist/version.js +1 -27
- package/packages/client/dist/yolo/change-evidence-collector.d.ts +21 -1
- package/packages/client/dist/yolo/change-evidence-collector.js +1 -126
- package/packages/client/dist/yolo/invoke-envelope-capability.js +1 -62
- package/packages/client/dist/yolo/spec-envelope-collector.js +5 -184
- package/packages/client/dist/yoloop/discovery-hook.js +2 -300
- package/packages/client/dist/yoloop/index.js +1 -8
- package/packages/client/dist/yoloop/invoke-hooks.js +12 -669
- package/packages/client/dist/yoloop/shared-discover-epics.js +1 -1007
- package/packages/client/dist/yoloop/shared-yoloop-types.js +1 -33
- package/packages/client/dist/yoloop/target-normalization.js +1 -180
- package/packages/client/dist/yoloop/yoloop-client-state-store.js +1 -1920
- package/packages/shared/dist/invocation/explicit-intent-recovery.d.ts +83 -0
- package/packages/shared/dist/invocation/explicit-intent-recovery.js +187 -0
- package/packages/shared/dist/invocation/index.d.ts +7 -0
- package/packages/shared/dist/invocation/index.js +22 -0
- package/packages/shared/dist/yolo/change-evidence.js +1 -1
- package/packages/shared/dist/yoloop/epic-terminal-git.js +144 -2
- 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 +24 -21
- package/targets-stubs/codex/README.md +6 -1
- package/targets-stubs/codex/neocortex.toml +7 -2
- package/targets-stubs/cursor/agent.md +2 -2
- package/targets-stubs/gemini-cli/agent.md +2 -2
- package/targets-stubs/opencode/neocortex-root.md +16 -1
- package/targets-stubs/opencode/neocortex.md +6 -0
- package/targets-stubs/vscode/neocortex.agent.md +2 -2
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { type EpicGitReconciliationDirective, type EpicTerminalGitDirective, type EpicTerminalGitReceipt, type GitReconciliationCandidate, type GitReconciliationDecision, type GitReconciliationReceipt } from '../../../../shared/dist/yoloop/epic-terminal-git.js';
|
|
2
|
-
import { type P205TransientExecutionAuthority } from '../../git/git-lifecycle-store.js';
|
|
2
|
+
import { type EpicTerminalReleaseAuthority, type P205TransientExecutionAuthority } from '../../git/git-lifecycle-store.js';
|
|
3
3
|
import { type EpicMergeCandidateQaAuthority } from './epic-merge-candidate-qa.js';
|
|
4
4
|
import type { EpicMergeCandidateQaReceipt } from '../../../../shared/dist/yoloop/epic-terminal-git.js';
|
|
5
5
|
import type { EpicPullRequestMergeGuardReceipt } from '../../../../shared/dist/yoloop/epic-terminal-git.js';
|
|
6
|
+
import { type ManagedEnvironmentCleanupAdapter, type ManagedEnvironmentCleanupReceiptV1, type ManagedEnvironmentCleanupRequestV1 } from './managed-environment-cleanup.js';
|
|
6
7
|
export interface EpicTerminalGitSnapshot {
|
|
7
8
|
readonly executionHeadSha: string;
|
|
8
9
|
readonly originHeadSha: string;
|
|
@@ -11,9 +12,12 @@ export interface EpicTerminalGitSnapshot {
|
|
|
11
12
|
readonly acceptedCheckpointIds: readonly string[];
|
|
12
13
|
readonly existingReceipt?: EpicTerminalGitReceipt | null;
|
|
13
14
|
readonly aggregateQaReceipt?: import('../../../../shared/dist/yoloop/epic-terminal-git.js').EpicAggregateQaReceipt | null;
|
|
15
|
+
readonly headReconciliationReceipt?: import('../../../../shared/dist/yoloop/epic-terminal-git.js').EpicHeadReconciliationReceiptV1 | null;
|
|
14
16
|
readonly originBinding?: import('../../../../shared/dist/yoloop/epic-terminal-git.js').EpicOriginBindingEvidence | null;
|
|
15
17
|
readonly nowIso?: string;
|
|
16
18
|
readonly reconciliationCandidates: readonly GitReconciliationCandidate[];
|
|
19
|
+
/** Optional capability-bound resources. Absence means no environment effect is authorized. */
|
|
20
|
+
readonly managedEnvironmentCleanupRequests?: readonly ManagedEnvironmentCleanupRequestV1[];
|
|
17
21
|
}
|
|
18
22
|
export type EpicTerminalEffectResult<T extends object = object> = ({
|
|
19
23
|
readonly ok: true;
|
|
@@ -24,6 +28,8 @@ export type EpicTerminalEffectResult<T extends object = object> = ({
|
|
|
24
28
|
readonly externalPolicy: boolean;
|
|
25
29
|
};
|
|
26
30
|
export interface EpicTerminalGitAdapter {
|
|
31
|
+
/** Optional installed capability. Missing capability preserves managed resources as pending. */
|
|
32
|
+
readonly managedEnvironmentCleanup?: ManagedEnvironmentCleanupAdapter;
|
|
27
33
|
/** Produce missing physical origin/aggregate-QA evidence before server projection. */
|
|
28
34
|
prepareLifecycleEvidence?(input: {
|
|
29
35
|
readonly epicId: string;
|
|
@@ -31,6 +37,9 @@ export interface EpicTerminalGitAdapter {
|
|
|
31
37
|
}): Promise<EpicTerminalEffectResult<{
|
|
32
38
|
readonly originBindingCaptured: boolean;
|
|
33
39
|
readonly aggregateQaRecorded: boolean;
|
|
40
|
+
readonly headReconciliationRecorded?: boolean;
|
|
41
|
+
readonly terminalAuthority?: EpicTerminalReleaseAuthority;
|
|
42
|
+
/** Backward-compatible alias for same-process fresh aggregate producers. */
|
|
34
43
|
readonly p205Authority?: P205TransientExecutionAuthority;
|
|
35
44
|
}>>;
|
|
36
45
|
inspect(directive: EpicTerminalGitDirective): Promise<EpicTerminalEffectResult<{
|
|
@@ -73,10 +82,17 @@ export interface EpicTerminalGitAdapter {
|
|
|
73
82
|
readonly candidateQa: EpicMergeCandidateQaReceipt;
|
|
74
83
|
readonly candidateAuthority: EpicMergeCandidateQaAuthority;
|
|
75
84
|
readonly idempotencyKey: string;
|
|
85
|
+
readonly terminalBinding?: {
|
|
86
|
+
readonly graphRevision: string;
|
|
87
|
+
readonly storyCheckpointIds: readonly string[];
|
|
88
|
+
readonly aggregateQaReceipt: EpicTerminalGitDirective['localGates']['aggregateQaReceipt'];
|
|
89
|
+
readonly nowIso: string;
|
|
90
|
+
};
|
|
76
91
|
}): Promise<EpicTerminalEffectResult<{
|
|
77
92
|
readonly prNumber: number;
|
|
78
93
|
}>>;
|
|
79
94
|
mergeEpicPullRequest(input: {
|
|
95
|
+
readonly epicId?: string;
|
|
80
96
|
readonly prNumber: number;
|
|
81
97
|
readonly originBranch: string;
|
|
82
98
|
readonly executionBranch: string;
|
|
@@ -86,6 +102,11 @@ export interface EpicTerminalGitAdapter {
|
|
|
86
102
|
readonly candidateQa?: EpicMergeCandidateQaReceipt;
|
|
87
103
|
readonly candidateAuthority?: EpicMergeCandidateQaAuthority;
|
|
88
104
|
readonly nowIso: string;
|
|
105
|
+
readonly terminalBinding?: {
|
|
106
|
+
readonly graphRevision: string;
|
|
107
|
+
readonly storyCheckpointIds: readonly string[];
|
|
108
|
+
readonly aggregateQaReceipt: EpicTerminalGitDirective['localGates']['aggregateQaReceipt'];
|
|
109
|
+
};
|
|
89
110
|
}): Promise<EpicTerminalEffectResult<{
|
|
90
111
|
readonly mergeSha: string;
|
|
91
112
|
readonly pushedSha: string;
|
|
@@ -112,6 +133,8 @@ export interface EpicTerminalGitAdapter {
|
|
|
112
133
|
readonly terminalReceipt: EpicTerminalGitReceipt;
|
|
113
134
|
readonly reconciliationReceipts: readonly GitReconciliationReceipt[];
|
|
114
135
|
readonly preservedDecisions: readonly GitReconciliationDecision[];
|
|
136
|
+
/** Kept separate from merge/Git reconciliation; production persistence requires an accepted store claim. */
|
|
137
|
+
readonly managedEnvironmentCleanupReceipts?: readonly ManagedEnvironmentCleanupReceiptV1[];
|
|
115
138
|
}): Promise<EpicTerminalEffectResult>;
|
|
116
139
|
}
|
|
117
140
|
export interface EpicTerminalGitExecutionResult {
|
|
@@ -119,6 +142,8 @@ export interface EpicTerminalGitExecutionResult {
|
|
|
119
142
|
readonly receipt: EpicTerminalGitReceipt;
|
|
120
143
|
readonly reconciliationReceipts: readonly GitReconciliationReceipt[];
|
|
121
144
|
readonly preservedDecisions: readonly GitReconciliationDecision[];
|
|
145
|
+
readonly managedEnvironmentCleanupReceipts: readonly ManagedEnvironmentCleanupReceiptV1[];
|
|
146
|
+
readonly managedEnvironmentCleanupPending: boolean;
|
|
122
147
|
readonly reasonCodes: readonly string[];
|
|
123
148
|
readonly publicSafe: true;
|
|
124
149
|
}
|
|
@@ -131,4 +156,4 @@ export interface EpicGitReconciliationExecutionResult {
|
|
|
131
156
|
}
|
|
132
157
|
/** Run the same fail-closed reconciler at start/resume or explicit audit. */
|
|
133
158
|
export declare function executeEpicGitReconciliation(directive: EpicGitReconciliationDirective, adapter: EpicTerminalGitAdapter, now: () => string): Promise<EpicGitReconciliationExecutionResult>;
|
|
134
|
-
export declare function executeEpicTerminalGit(directive: EpicTerminalGitDirective, adapter: EpicTerminalGitAdapter, now: () => string, preparedAuthority?:
|
|
159
|
+
export declare function executeEpicTerminalGit(directive: EpicTerminalGitDirective, adapter: EpicTerminalGitAdapter, now: () => string, preparedAuthority?: EpicTerminalReleaseAuthority): Promise<EpicTerminalGitExecutionResult>;
|
|
@@ -1,318 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* never mutate real refs or provider resources.
|
|
4
|
-
*/
|
|
5
|
-
import { createHash } from 'node:crypto';
|
|
6
|
-
import { EPIC_TERMINAL_GIT_REASON_CODES, classifyGitReconciliationCandidate, validateEpicTerminalGitDirective, } from '../../../../shared/dist/yoloop/epic-terminal-git.js';
|
|
7
|
-
import { p205TransientAuthorityMatchesAggregate, } from '../../git/git-lifecycle-store.js';
|
|
8
|
-
import { verifiedEpicMergeCandidateReceipt, } from './epic-merge-candidate-qa.js';
|
|
9
|
-
/** Run the same fail-closed reconciler at start/resume or explicit audit. */
|
|
10
|
-
export async function executeEpicGitReconciliation(directive, adapter, now) {
|
|
11
|
-
const inspected = await adapter.inspectReconciliation(directive);
|
|
12
|
-
if (!inspected.ok) {
|
|
13
|
-
return { ok: false, reconciliationReceipts: [], preservedDecisions: [], reasonCodes: [inspected.reasonCode], publicSafe: true };
|
|
14
|
-
}
|
|
15
|
-
const reconciliation = await reconcileCandidates({
|
|
16
|
-
idempotencyKey: directive.idempotencyKey,
|
|
17
|
-
enabled: true,
|
|
18
|
-
dryRun: directive.dryRun,
|
|
19
|
-
}, inspected.candidates, adapter, now);
|
|
20
|
-
const persisted = await adapter.persistReconciliation({
|
|
21
|
-
epicId: directive.epicId,
|
|
22
|
-
reconciliationReceipts: reconciliation.receipts,
|
|
23
|
-
preservedDecisions: reconciliation.preserved,
|
|
24
|
-
});
|
|
25
|
-
const reasonCodes = unique([...reconciliation.reasonCodes, ...(persisted.ok ? [] : [persisted.reasonCode])]);
|
|
26
|
-
return {
|
|
27
|
-
ok: reconciliation.ok && persisted.ok,
|
|
28
|
-
reconciliationReceipts: reconciliation.receipts,
|
|
29
|
-
preservedDecisions: reconciliation.preserved,
|
|
30
|
-
reasonCodes,
|
|
31
|
-
publicSafe: true,
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
export async function executeEpicTerminalGit(directive, adapter, now, preparedAuthority) {
|
|
35
|
-
const startedAt = now();
|
|
36
|
-
if (!adapter.prepareLifecycleEvidence) {
|
|
37
|
-
return failedBeforeSnapshot(directive, {
|
|
38
|
-
ok: false, reasonCode: 'epic-aggregate-qa-producer-required', retryEligible: false, externalPolicy: false,
|
|
39
|
-
}, startedAt);
|
|
40
|
-
}
|
|
41
|
-
const produced = preparedAuthority
|
|
42
|
-
? { ok: true, originBindingCaptured: false, aggregateQaRecorded: true, p205Authority: preparedAuthority }
|
|
43
|
-
: await adapter.prepareLifecycleEvidence({ epicId: directive.epicId, nowIso: startedAt });
|
|
44
|
-
if (!produced.ok)
|
|
45
|
-
return failedBeforeSnapshot(directive, produced, startedAt);
|
|
46
|
-
if (!produced.p205Authority) {
|
|
47
|
-
return failedBeforeSnapshot(directive, {
|
|
48
|
-
ok: false, reasonCode: 'epic-aggregate-qa-authority-required', retryEligible: false, externalPolicy: false,
|
|
49
|
-
}, startedAt);
|
|
50
|
-
}
|
|
51
|
-
const inspected = await adapter.inspect(directive);
|
|
52
|
-
if (!inspected.ok)
|
|
53
|
-
return failedBeforeSnapshot(directive, inspected, startedAt);
|
|
54
|
-
const snapshot = inspected.snapshot;
|
|
55
|
-
if (!p205TransientAuthorityMatchesAggregate(produced.p205Authority, snapshot.executionHeadSha, directive.graphRevision)) {
|
|
56
|
-
return failedBeforeSnapshot(directive, {
|
|
57
|
-
ok: false, reasonCode: 'epic-aggregate-qa-authority-binding-mismatch', retryEligible: false, externalPolicy: false,
|
|
58
|
-
}, startedAt);
|
|
59
|
-
}
|
|
60
|
-
const readiness = validateEpicTerminalGitDirective(directive, { ...snapshot, nowIso: startedAt });
|
|
61
|
-
if (!readiness.ready) {
|
|
62
|
-
return terminalResult(false, baseReceipt(directive, snapshot, startedAt, {
|
|
63
|
-
strategy: directive.strategy === 'single_pr' ? 'single_pr' : 'direct',
|
|
64
|
-
physicalStatus: 'blocked_local_or_repo',
|
|
65
|
-
retryEligible: readiness.reasonCodes.some((code) => code.endsWith('mismatch') || code.endsWith('active')),
|
|
66
|
-
reasonCodes: readiness.reasonCodes,
|
|
67
|
-
}), [], [], readiness.reasonCodes);
|
|
68
|
-
}
|
|
69
|
-
if (readiness.reasonCodes.includes(EPIC_TERMINAL_GIT_REASON_CODES.ALREADY_COMPLETE) && snapshot.existingReceipt) {
|
|
70
|
-
const verified = await adapter.verifyTerminalReceipt(directive, snapshot.existingReceipt, startedAt);
|
|
71
|
-
if (!verified.ok)
|
|
72
|
-
return terminalResult(false, snapshot.existingReceipt, [], [], [verified.reasonCode]);
|
|
73
|
-
const candidateQa = verifiedEpicMergeCandidateReceipt(verified.candidateAuthority, {
|
|
74
|
-
mergeSha: snapshot.existingReceipt.mergeSha, originHeadSha: snapshot.existingReceipt.baseSha,
|
|
75
|
-
executionHeadSha: snapshot.existingReceipt.executionHeadSha, graphRevision: directive.graphRevision,
|
|
76
|
-
});
|
|
77
|
-
if (!candidateQa)
|
|
78
|
-
return terminalResult(false, snapshot.existingReceipt, [], [], ['epic-merge-candidate-authority-required']);
|
|
79
|
-
const verifiedReceipt = {
|
|
80
|
-
...snapshot.existingReceipt, candidateQa,
|
|
81
|
-
...(verified.providerGuard ? { providerGuard: verified.providerGuard } : {}),
|
|
82
|
-
};
|
|
83
|
-
const reconciliation = await reconcileCandidates({ idempotencyKey: directive.idempotencyKey, enabled: directive.reconcile.enabled, dryRun: directive.reconcile.dryRun }, snapshot.reconciliationCandidates, adapter, now);
|
|
84
|
-
const persisted = await adapter.persist({
|
|
85
|
-
terminalReceipt: verifiedReceipt,
|
|
86
|
-
reconciliationReceipts: reconciliation.receipts,
|
|
87
|
-
preservedDecisions: reconciliation.preserved,
|
|
88
|
-
});
|
|
89
|
-
const reasons = unique([...readiness.reasonCodes, ...reconciliation.reasonCodes, ...(persisted.ok ? [] : [persisted.reasonCode])]);
|
|
90
|
-
return terminalResult(persisted.ok && reconciliation.ok, verifiedReceipt, reconciliation.receipts, reconciliation.preserved, reasons);
|
|
91
|
-
}
|
|
92
|
-
let receipt;
|
|
93
|
-
const prepared = await adapter.prepareMergeObject({
|
|
94
|
-
originBranch: directive.originBranch,
|
|
95
|
-
executionBranch: directive.executionBranch,
|
|
96
|
-
originHeadSha: snapshot.originHeadSha,
|
|
97
|
-
executionHeadSha: snapshot.executionHeadSha,
|
|
98
|
-
graphRevision: directive.graphRevision,
|
|
99
|
-
nowIso: startedAt,
|
|
100
|
-
message: [
|
|
101
|
-
`merge(${directive.epicId}): integrate ${directive.executionBranch} into ${directive.originBranch}`,
|
|
102
|
-
'',
|
|
103
|
-
`Neocortex-Epic: ${directive.epicId}`,
|
|
104
|
-
`Neocortex-Origin-Branch: ${directive.originBranch}`,
|
|
105
|
-
`Neocortex-Execution-Branch: ${directive.executionBranch}`,
|
|
106
|
-
`Neocortex-Execution-Head: ${snapshot.executionHeadSha}`,
|
|
107
|
-
`Neocortex-Origin-Base: ${snapshot.originHeadSha}`,
|
|
108
|
-
`Neocortex-Graph-Revision: ${directive.graphRevision}`,
|
|
109
|
-
`Neocortex-Aggregate-QA: ${directive.localGates.aggregateQaReceipt.receiptRef}`,
|
|
110
|
-
`Neocortex-Idempotency: ${directive.idempotencyKey}`,
|
|
111
|
-
].join('\n'),
|
|
112
|
-
});
|
|
113
|
-
if (!prepared.ok) {
|
|
114
|
-
receipt = baseReceipt(directive, snapshot, startedAt, {
|
|
115
|
-
strategy: 'direct',
|
|
116
|
-
physicalStatus: 'blocked_local_or_repo',
|
|
117
|
-
retryEligible: prepared.retryEligible,
|
|
118
|
-
reasonCodes: [prepared.reasonCode],
|
|
119
|
-
});
|
|
120
|
-
await adapter.persist({ terminalReceipt: receipt, reconciliationReceipts: [], preservedDecisions: [] });
|
|
121
|
-
return terminalResult(false, receipt, [], [], receipt.reasonCodes);
|
|
122
|
-
}
|
|
123
|
-
const candidateQa = verifiedEpicMergeCandidateReceipt(prepared.candidateAuthority, {
|
|
124
|
-
originHeadSha: snapshot.originHeadSha, executionHeadSha: snapshot.executionHeadSha,
|
|
125
|
-
mergeSha: prepared.mergeSha, graphRevision: directive.graphRevision,
|
|
126
|
-
});
|
|
127
|
-
if (!candidateQa)
|
|
128
|
-
return failedBeforeSnapshot(directive, {
|
|
129
|
-
ok: false, reasonCode: 'epic-merge-candidate-authority-required', retryEligible: false, externalPolicy: false,
|
|
130
|
-
}, startedAt);
|
|
131
|
-
if (directive.strategy !== 'single_pr') {
|
|
132
|
-
const pushed = await adapter.pushMergeObject({
|
|
133
|
-
epicId: directive.epicId,
|
|
134
|
-
originBranch: directive.originBranch,
|
|
135
|
-
executionBranch: directive.executionBranch,
|
|
136
|
-
executionHeadSha: snapshot.executionHeadSha,
|
|
137
|
-
expectedOriginSha: snapshot.originHeadSha,
|
|
138
|
-
mergeSha: prepared.mergeSha,
|
|
139
|
-
graphRevision: directive.graphRevision,
|
|
140
|
-
candidateAuthority: prepared.candidateAuthority,
|
|
141
|
-
storyCheckpointIds: directive.storyCheckpointIds,
|
|
142
|
-
aggregateQaReceipt: directive.localGates.aggregateQaReceipt,
|
|
143
|
-
nowIso: now(),
|
|
144
|
-
});
|
|
145
|
-
if (pushed.ok) {
|
|
146
|
-
receipt = baseReceipt(directive, snapshot, startedAt, {
|
|
147
|
-
strategy: 'direct', mergeSha: prepared.mergeSha, pushedSha: pushed.pushedSha, candidateQa,
|
|
148
|
-
physicalStatus: 'pushed', retryEligible: false,
|
|
149
|
-
reasonCodes: [EPIC_TERMINAL_GIT_REASON_CODES.READY], completedAt: now(),
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
else if (directive.strategy === 'direct_or_single_pr' && pushed.externalPolicy) {
|
|
153
|
-
receipt = await executePullRequestFallback(directive, snapshot, adapter, startedAt, now, candidateQa, prepared.candidateAuthority);
|
|
154
|
-
}
|
|
155
|
-
else {
|
|
156
|
-
receipt = baseReceipt(directive, snapshot, startedAt, {
|
|
157
|
-
strategy: 'direct', mergeSha: prepared.mergeSha,
|
|
158
|
-
physicalStatus: pushed.externalPolicy ? 'denied_external_gate' : 'blocked_local_or_repo',
|
|
159
|
-
retryEligible: pushed.retryEligible,
|
|
160
|
-
reasonCodes: [pushed.reasonCode, ...(pushed.retryEligible ? [EPIC_TERMINAL_GIT_REASON_CODES.RETRY_ELIGIBLE] : [])],
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
else {
|
|
165
|
-
receipt = await executePullRequestFallback(directive, snapshot, adapter, startedAt, now, candidateQa, prepared.candidateAuthority);
|
|
166
|
-
}
|
|
167
|
-
const verified = receipt.physicalStatus === 'pushed'
|
|
168
|
-
? await adapter.verifyTerminalReceipt(directive, receipt, now())
|
|
169
|
-
: null;
|
|
170
|
-
if (verified && !verified.ok) {
|
|
171
|
-
const failedReceipt = baseReceipt(directive, snapshot, startedAt, {
|
|
172
|
-
...receipt,
|
|
173
|
-
physicalStatus: 'blocked_local_or_repo',
|
|
174
|
-
retryEligible: verified.retryEligible,
|
|
175
|
-
reasonCodes: [verified.reasonCode],
|
|
176
|
-
});
|
|
177
|
-
await adapter.persist({ terminalReceipt: failedReceipt, reconciliationReceipts: [], preservedDecisions: [] });
|
|
178
|
-
return terminalResult(false, failedReceipt, [], [], failedReceipt.reasonCodes);
|
|
179
|
-
}
|
|
180
|
-
if (verified?.ok) {
|
|
181
|
-
const accepted = verifiedEpicMergeCandidateReceipt(verified.candidateAuthority, {
|
|
182
|
-
mergeSha: receipt.mergeSha, originHeadSha: receipt.baseSha,
|
|
183
|
-
executionHeadSha: receipt.executionHeadSha, graphRevision: directive.graphRevision,
|
|
184
|
-
});
|
|
185
|
-
if (!accepted)
|
|
186
|
-
return terminalResult(false, receipt, [], [], ['epic-merge-candidate-authority-required']);
|
|
187
|
-
receipt = {
|
|
188
|
-
...receipt, candidateQa: accepted,
|
|
189
|
-
...(verified.providerGuard ? { providerGuard: verified.providerGuard } : {}),
|
|
190
|
-
};
|
|
191
|
-
}
|
|
192
|
-
const reconciliation = receipt.physicalStatus === 'pushed'
|
|
193
|
-
? await reconcileCandidates({ idempotencyKey: directive.idempotencyKey, enabled: directive.reconcile.enabled, dryRun: directive.reconcile.dryRun }, snapshot.reconciliationCandidates, adapter, now)
|
|
194
|
-
: { ok: true, receipts: [], preserved: [], reasonCodes: [] };
|
|
195
|
-
const persisted = await adapter.persist({
|
|
196
|
-
terminalReceipt: receipt,
|
|
197
|
-
reconciliationReceipts: reconciliation.receipts,
|
|
198
|
-
preservedDecisions: reconciliation.preserved,
|
|
199
|
-
});
|
|
200
|
-
const reasons = unique([...receipt.reasonCodes, ...reconciliation.reasonCodes, ...(persisted.ok ? [] : [persisted.reasonCode])]);
|
|
201
|
-
return terminalResult(receipt.physicalStatus === 'pushed' && reconciliation.ok && persisted.ok, receipt, reconciliation.receipts, reconciliation.preserved, reasons);
|
|
202
|
-
}
|
|
203
|
-
async function executePullRequestFallback(directive, snapshot, adapter, startedAt, now, candidateQa, candidateAuthority) {
|
|
204
|
-
const pr = await adapter.ensureSingleEpicPullRequest({
|
|
205
|
-
epicId: directive.epicId,
|
|
206
|
-
originBranch: directive.originBranch,
|
|
207
|
-
executionBranch: directive.executionBranch,
|
|
208
|
-
expectedStoryHeadSha: snapshot.executionHeadSha,
|
|
209
|
-
expectedPullRequestHeadSha: candidateQa.mergeSha,
|
|
210
|
-
candidateQa,
|
|
211
|
-
candidateAuthority,
|
|
212
|
-
idempotencyKey: directive.idempotencyKey,
|
|
213
|
-
});
|
|
214
|
-
if (!pr.ok)
|
|
215
|
-
return baseReceipt(directive, snapshot, startedAt, {
|
|
216
|
-
strategy: 'single_pr', physicalStatus: pr.externalPolicy ? 'denied_external_gate' : 'blocked_local_or_repo',
|
|
217
|
-
retryEligible: pr.retryEligible, reasonCodes: [pr.reasonCode],
|
|
218
|
-
});
|
|
219
|
-
const merged = await adapter.mergeEpicPullRequest({
|
|
220
|
-
prNumber: pr.prNumber,
|
|
221
|
-
originBranch: directive.originBranch,
|
|
222
|
-
executionBranch: directive.executionBranch,
|
|
223
|
-
expectedStoryHeadSha: snapshot.executionHeadSha,
|
|
224
|
-
expectedPullRequestHeadSha: candidateQa.mergeSha,
|
|
225
|
-
expectedOriginHeadSha: snapshot.originHeadSha,
|
|
226
|
-
candidateQa, candidateAuthority, nowIso: now(),
|
|
227
|
-
});
|
|
228
|
-
if (!merged.ok)
|
|
229
|
-
return baseReceipt(directive, snapshot, startedAt, {
|
|
230
|
-
strategy: 'single_pr', prNumber: pr.prNumber,
|
|
231
|
-
physicalStatus: merged.externalPolicy ? 'denied_external_gate' : 'blocked_local_or_repo',
|
|
232
|
-
retryEligible: merged.retryEligible,
|
|
233
|
-
reasonCodes: [merged.reasonCode, ...(merged.retryEligible ? [EPIC_TERMINAL_GIT_REASON_CODES.RETRY_ELIGIBLE] : [])],
|
|
234
|
-
});
|
|
235
|
-
return baseReceipt(directive, snapshot, startedAt, {
|
|
236
|
-
strategy: 'single_pr', prNumber: pr.prNumber, mergeSha: merged.mergeSha, pushedSha: merged.pushedSha, candidateQa,
|
|
237
|
-
providerGuard: merged.providerGuard,
|
|
238
|
-
physicalStatus: 'pushed', retryEligible: false,
|
|
239
|
-
reasonCodes: [EPIC_TERMINAL_GIT_REASON_CODES.READY], completedAt: now(),
|
|
240
|
-
});
|
|
241
|
-
}
|
|
242
|
-
async function reconcileCandidates(directive, candidates, adapter, now) {
|
|
243
|
-
if (!directive.enabled)
|
|
244
|
-
return { ok: true, receipts: [], preserved: [], reasonCodes: [] };
|
|
245
|
-
const receipts = [];
|
|
246
|
-
const preserved = [];
|
|
247
|
-
const reasons = [];
|
|
248
|
-
let ok = true;
|
|
249
|
-
const failedPrBranches = new Set();
|
|
250
|
-
const order = { pull_request: 0, local_branch: 1, remote_branch: 2 };
|
|
251
|
-
for (const candidate of [...candidates].sort((a, b) => order[a.kind] - order[b.kind] || a.resourceId.localeCompare(b.resourceId))) {
|
|
252
|
-
const decision = classifyGitReconciliationCandidate(candidate);
|
|
253
|
-
reasons.push(...decision.reasonCodes);
|
|
254
|
-
if (decision.action === 'preserve') {
|
|
255
|
-
preserved.push(decision);
|
|
256
|
-
continue;
|
|
257
|
-
}
|
|
258
|
-
if (candidate.kind !== 'pull_request' && failedPrBranches.has(candidate.branchName)) {
|
|
259
|
-
preserved.push({ ...decision, action: 'preserve', reasonCodes: ['git-resource-related-pr-close-pending'] });
|
|
260
|
-
reasons.push('git-resource-related-pr-close-pending');
|
|
261
|
-
continue;
|
|
262
|
-
}
|
|
263
|
-
// Stable across start/resume/terminal directives; no long branch name or
|
|
264
|
-
// unbounded parent id can overflow the public receipt schema.
|
|
265
|
-
const receiptKey = `reconciliation:v2:${createHash('sha256').update([candidate.resourceId, decision.action].join('\0')).digest('hex')}`;
|
|
266
|
-
const applied = await adapter.applyReconciliation(candidate, decision, directive.dryRun);
|
|
267
|
-
if (!applied.ok) {
|
|
268
|
-
ok = false;
|
|
269
|
-
if (candidate.kind === 'pull_request')
|
|
270
|
-
failedPrBranches.add(candidate.branchName);
|
|
271
|
-
reasons.push(applied.reasonCode);
|
|
272
|
-
receipts.push({
|
|
273
|
-
schemaVersion: 1, resourceId: candidate.resourceId, action: decision.action,
|
|
274
|
-
outcome: 'failed', idempotencyKey: receiptKey,
|
|
275
|
-
reasonCodes: [applied.reasonCode], recordedAt: now(), publicSafe: true,
|
|
276
|
-
});
|
|
277
|
-
continue;
|
|
278
|
-
}
|
|
279
|
-
receipts.push({
|
|
280
|
-
schemaVersion: 1, resourceId: candidate.resourceId, action: decision.action,
|
|
281
|
-
outcome: applied.outcome, idempotencyKey: receiptKey,
|
|
282
|
-
reasonCodes: decision.reasonCodes, recordedAt: now(), publicSafe: true,
|
|
283
|
-
});
|
|
284
|
-
}
|
|
285
|
-
return { ok, receipts, preserved, reasonCodes: unique(reasons) };
|
|
286
|
-
}
|
|
287
|
-
function baseReceipt(directive, snapshot, startedAt, override) {
|
|
288
|
-
return Object.freeze({
|
|
289
|
-
schemaVersion: 1,
|
|
290
|
-
epicId: directive.epicId,
|
|
291
|
-
executionBranch: directive.executionBranch,
|
|
292
|
-
originBranch: directive.originBranch,
|
|
293
|
-
baseSha: snapshot.originHeadSha,
|
|
294
|
-
executionHeadSha: snapshot.executionHeadSha,
|
|
295
|
-
localGateReceiptRefs: directive.localGates.receiptRefs,
|
|
296
|
-
idempotencyKey: directive.idempotencyKey,
|
|
297
|
-
attemptStartedAt: startedAt,
|
|
298
|
-
publicSafe: true,
|
|
299
|
-
...override,
|
|
300
|
-
});
|
|
301
|
-
}
|
|
302
|
-
function failedBeforeSnapshot(directive, failure, startedAt) {
|
|
303
|
-
const placeholder = '0'.repeat(40);
|
|
304
|
-
const receipt = {
|
|
305
|
-
schemaVersion: 1, epicId: directive.epicId, executionBranch: directive.executionBranch, originBranch: directive.originBranch,
|
|
306
|
-
baseSha: placeholder, executionHeadSha: directive.expectedExecutionHeadSha, strategy: directive.strategy === 'single_pr' ? 'single_pr' : 'direct',
|
|
307
|
-
physicalStatus: failure.externalPolicy ? 'denied_external_gate' : 'blocked_local_or_repo',
|
|
308
|
-
localGateReceiptRefs: directive.localGates.receiptRefs, idempotencyKey: directive.idempotencyKey,
|
|
309
|
-
attemptStartedAt: startedAt, retryEligible: failure.retryEligible, reasonCodes: [failure.reasonCode], publicSafe: true,
|
|
310
|
-
};
|
|
311
|
-
return terminalResult(false, receipt, [], [], receipt.reasonCodes);
|
|
312
|
-
}
|
|
313
|
-
function terminalResult(ok, receipt, reconciliationReceipts, preservedDecisions, reasonCodes) {
|
|
314
|
-
return { ok, receipt, reconciliationReceipts, preservedDecisions, reasonCodes: unique(reasonCodes), publicSafe: true };
|
|
315
|
-
}
|
|
316
|
-
function unique(values) {
|
|
317
|
-
return [...new Set(values)];
|
|
318
|
-
}
|
|
1
|
+
import{createHash as K}from"node:crypto";import{EPIC_TERMINAL_GIT_REASON_CODES as x,classifyGitReconciliationCandidate as D,validateEpicTerminalGitDirective as $}from"../../../../shared/dist/yoloop/epic-terminal-git.js";import{consumeEpicTerminalReleaseAuthority as Q}from"../../git/git-lifecycle-store.js";import{verifiedEpicMergeCandidateReceipt as I}from"./epic-merge-candidate-qa.js";import{executeManagedEnvironmentCleanup as A}from"./managed-environment-cleanup.js";async function Y(e,n,t){const p=await n.inspectReconciliation(e);if(!p.ok)return{ok:!1,reconciliationReceipts:[],preservedDecisions:[],reasonCodes:[p.reasonCode],publicSafe:!0};const r=await B({idempotencyKey:e.idempotencyKey,enabled:!0,dryRun:e.dryRun},p.candidates,n,t),c=await n.persistReconciliation({epicId:e.epicId,reconciliationReceipts:r.receipts,preservedDecisions:r.preserved}),u=C([...r.reasonCodes,...c.ok?[]:[c.reasonCode]]);return{ok:r.ok&&c.ok,reconciliationReceipts:r.receipts,preservedDecisions:r.preserved,reasonCodes:u,publicSafe:!0}}async function V(e,n,t,p){const r=t();if(!n.prepareLifecycleEvidence)return S(e,{ok:!1,reasonCode:"epic-aggregate-qa-producer-required",retryEligible:!1,externalPolicy:!1},r);const c=p?{ok:!0,originBindingCaptured:!1,aggregateQaRecorded:!0,terminalAuthority:p}:await n.prepareLifecycleEvidence({epicId:e.epicId,nowIso:r});if(!c.ok)return S(e,c,r);const u=c.terminalAuthority??c.p205Authority;if(!u)return S(e,{ok:!1,reasonCode:"epic-aggregate-qa-authority-required",retryEligible:!1,externalPolicy:!1},r);const l=await n.inspect(e);if(!l.ok)return S(e,l,r);const a=l.snapshot,h=$(e,{...a,nowIso:r});if(!h.ready)return y(!1,m(e,a,r,{strategy:e.strategy==="single_pr"?"single_pr":"direct",physicalStatus:"blocked_local_or_repo",retryEligible:h.reasonCodes.some(s=>s.endsWith("mismatch")||s.endsWith("active")),reasonCodes:h.reasonCodes}),[],[],h.reasonCodes);if(!a.aggregateQaReceipt||!Q(u,{executionHeadSha:a.executionHeadSha,graphRevision:e.graphRevision,aggregateQaReceipt:a.aggregateQaReceipt,headReconciliationReceipt:a.headReconciliationReceipt}))return S(e,{ok:!1,reasonCode:"epic-aggregate-qa-authority-binding-mismatch",retryEligible:!1,externalPolicy:!1},r);if(h.reasonCodes.includes(x.ALREADY_COMPLETE)&&a.existingReceipt){const s=await n.verifyTerminalReceipt(e,a.existingReceipt,r);if(!s.ok)return y(!1,a.existingReceipt,[],[],[s.reasonCode]);const H=I(s.candidateAuthority,{mergeSha:a.existingReceipt.mergeSha,originHeadSha:a.existingReceipt.baseSha,executionHeadSha:a.existingReceipt.executionHeadSha,graphRevision:e.graphRevision});if(!H)return y(!1,a.existingReceipt,[],[],["epic-merge-candidate-authority-required"]);const G={...a.existingReceipt,candidateQa:H,...s.providerGuard?{providerGuard:s.providerGuard}:{}},f=await B({idempotencyKey:e.idempotencyKey,enabled:e.reconcile.enabled,dryRun:e.reconcile.dryRun},a.reconciliationCandidates,n,t),E=await A(a.managedEnvironmentCleanupRequests??[],n.managedEnvironmentCleanup,t),k=await n.persist({terminalReceipt:G,reconciliationReceipts:f.receipts,preservedDecisions:f.preserved,managedEnvironmentCleanupReceipts:E.receipts}),P=C([...h.reasonCodes,...f.reasonCodes,...E.reasonCodes,...k.ok?[]:[k.reasonCode]]);return y(k.ok&&f.ok&&E.ok,G,f.receipts,f.preserved,P,E)}let o;const i=await n.prepareMergeObject({originBranch:e.originBranch,executionBranch:e.executionBranch,originHeadSha:a.originHeadSha,executionHeadSha:a.executionHeadSha,graphRevision:e.graphRevision,nowIso:r,message:[`merge(${e.epicId}): integrate ${e.executionBranch} into ${e.originBranch}`,"",`Neocortex-Epic: ${e.epicId}`,`Neocortex-Origin-Branch: ${e.originBranch}`,`Neocortex-Execution-Branch: ${e.executionBranch}`,`Neocortex-Execution-Head: ${a.executionHeadSha}`,`Neocortex-Origin-Base: ${a.originHeadSha}`,`Neocortex-Graph-Revision: ${e.graphRevision}`,`Neocortex-Aggregate-QA: ${e.localGates.aggregateQaReceipt.receiptRef}`,`Neocortex-Idempotency: ${e.idempotencyKey}`].join(`
|
|
2
|
+
`)});if(!i.ok)return o=m(e,a,r,{strategy:"direct",physicalStatus:"blocked_local_or_repo",retryEligible:i.retryEligible,reasonCodes:[i.reasonCode]}),await n.persist({terminalReceipt:o,reconciliationReceipts:[],preservedDecisions:[]}),y(!1,o,[],[],o.reasonCodes);const g=I(i.candidateAuthority,{originHeadSha:a.originHeadSha,executionHeadSha:a.executionHeadSha,mergeSha:i.mergeSha,graphRevision:e.graphRevision});if(!g)return S(e,{ok:!1,reasonCode:"epic-merge-candidate-authority-required",retryEligible:!1,externalPolicy:!1},r);if(e.strategy!=="single_pr"){const s=await n.pushMergeObject({epicId:e.epicId,originBranch:e.originBranch,executionBranch:e.executionBranch,executionHeadSha:a.executionHeadSha,expectedOriginSha:a.originHeadSha,mergeSha:i.mergeSha,graphRevision:e.graphRevision,candidateAuthority:i.candidateAuthority,storyCheckpointIds:e.storyCheckpointIds,aggregateQaReceipt:e.localGates.aggregateQaReceipt,nowIso:t()});s.ok?o=m(e,a,r,{strategy:"direct",mergeSha:i.mergeSha,pushedSha:s.pushedSha,candidateQa:g,physicalStatus:"pushed",retryEligible:!1,reasonCodes:[x.READY],completedAt:t()}):e.strategy==="direct_or_single_pr"&&s.externalPolicy?o=await q(e,a,n,r,t,g,i.candidateAuthority):o=m(e,a,r,{strategy:"direct",mergeSha:i.mergeSha,physicalStatus:s.externalPolicy?"denied_external_gate":"blocked_local_or_repo",retryEligible:s.retryEligible,reasonCodes:[s.reasonCode,...s.retryEligible?[x.RETRY_ELIGIBLE]:[]]})}else o=await q(e,a,n,r,t,g,i.candidateAuthority);const d=o.physicalStatus==="pushed"?await n.verifyTerminalReceipt(e,o,t()):null;if(d&&!d.ok){const s=m(e,a,r,{...o,physicalStatus:"blocked_local_or_repo",retryEligible:d.retryEligible,reasonCodes:[d.reasonCode]});return await n.persist({terminalReceipt:s,reconciliationReceipts:[],preservedDecisions:[]}),y(!1,s,[],[],s.reasonCodes)}if(d?.ok){const s=I(d.candidateAuthority,{mergeSha:o.mergeSha,originHeadSha:o.baseSha,executionHeadSha:o.executionHeadSha,graphRevision:e.graphRevision});if(!s)return y(!1,o,[],[],["epic-merge-candidate-authority-required"]);o={...o,candidateQa:s,...d.providerGuard?{providerGuard:d.providerGuard}:{}}}const R=o.physicalStatus==="pushed"?await B({idempotencyKey:e.idempotencyKey,enabled:e.reconcile.enabled,dryRun:e.reconcile.dryRun},a.reconciliationCandidates,n,t):{ok:!0,receipts:[],preserved:[],reasonCodes:[]},b=o.physicalStatus==="pushed"?await A(a.managedEnvironmentCleanupRequests??[],n.managedEnvironmentCleanup,t):w(),_=await n.persist({terminalReceipt:o,reconciliationReceipts:R.receipts,preservedDecisions:R.preserved,managedEnvironmentCleanupReceipts:b.receipts}),N=C([...o.reasonCodes,...R.reasonCodes,...b.reasonCodes,..._.ok?[]:[_.reasonCode]]);return y(o.physicalStatus==="pushed"&&R.ok&&b.ok&&_.ok,o,R.receipts,R.preserved,N,b)}async function q(e,n,t,p,r,c,u){const l=await t.ensureSingleEpicPullRequest({epicId:e.epicId,originBranch:e.originBranch,executionBranch:e.executionBranch,expectedStoryHeadSha:n.executionHeadSha,expectedPullRequestHeadSha:c.mergeSha,candidateQa:c,candidateAuthority:u,idempotencyKey:e.idempotencyKey,terminalBinding:{graphRevision:e.graphRevision,storyCheckpointIds:e.storyCheckpointIds,aggregateQaReceipt:e.localGates.aggregateQaReceipt,nowIso:r()}});if(!l.ok)return m(e,n,p,{strategy:"single_pr",physicalStatus:l.externalPolicy?"denied_external_gate":"blocked_local_or_repo",retryEligible:l.retryEligible,reasonCodes:[l.reasonCode]});const a=await t.mergeEpicPullRequest({epicId:e.epicId,prNumber:l.prNumber,originBranch:e.originBranch,executionBranch:e.executionBranch,expectedStoryHeadSha:n.executionHeadSha,expectedPullRequestHeadSha:c.mergeSha,expectedOriginHeadSha:n.originHeadSha,candidateQa:c,candidateAuthority:u,nowIso:r(),terminalBinding:{graphRevision:e.graphRevision,storyCheckpointIds:e.storyCheckpointIds,aggregateQaReceipt:e.localGates.aggregateQaReceipt}});return a.ok?m(e,n,p,{strategy:"single_pr",prNumber:l.prNumber,mergeSha:a.mergeSha,pushedSha:a.pushedSha,candidateQa:c,providerGuard:a.providerGuard,physicalStatus:"pushed",retryEligible:!1,reasonCodes:[x.READY],completedAt:r()}):m(e,n,p,{strategy:"single_pr",prNumber:l.prNumber,physicalStatus:a.externalPolicy?"denied_external_gate":"blocked_local_or_repo",retryEligible:a.retryEligible,reasonCodes:[a.reasonCode,...a.retryEligible?[x.RETRY_ELIGIBLE]:[]]})}async function B(e,n,t,p){if(!e.enabled)return{ok:!0,receipts:[],preserved:[],reasonCodes:[]};const r=[],c=[],u=[];let l=!0;const a=new Set,h={pull_request:0,local_branch:1,remote_branch:2};for(const o of[...n].sort((i,g)=>h[i.kind]-h[g.kind]||i.resourceId.localeCompare(g.resourceId))){const i=D(o);if(u.push(...i.reasonCodes),i.action==="preserve"){c.push(i);continue}if(o.kind!=="pull_request"&&a.has(o.branchName)){c.push({...i,action:"preserve",reasonCodes:["git-resource-related-pr-close-pending"]}),u.push("git-resource-related-pr-close-pending");continue}const g=`reconciliation:v2:${K("sha256").update([o.resourceId,i.action].join("\0")).digest("hex")}`,d=await t.applyReconciliation(o,i,e.dryRun);if(!d.ok){l=!1,o.kind==="pull_request"&&a.add(o.branchName),u.push(d.reasonCode),r.push({schemaVersion:1,resourceId:o.resourceId,action:i.action,outcome:"failed",idempotencyKey:g,reasonCodes:[d.reasonCode],recordedAt:p(),publicSafe:!0});continue}r.push({schemaVersion:1,resourceId:o.resourceId,action:i.action,outcome:d.outcome,idempotencyKey:g,reasonCodes:i.reasonCodes,recordedAt:p(),publicSafe:!0})}return{ok:l,receipts:r,preserved:c,reasonCodes:C(u)}}function m(e,n,t,p){return Object.freeze({schemaVersion:1,epicId:e.epicId,executionBranch:e.executionBranch,originBranch:e.originBranch,baseSha:n.originHeadSha,executionHeadSha:n.executionHeadSha,localGateReceiptRefs:e.localGates.receiptRefs,idempotencyKey:e.idempotencyKey,attemptStartedAt:t,publicSafe:!0,...p})}function S(e,n,t){const p="0".repeat(40),r={schemaVersion:1,epicId:e.epicId,executionBranch:e.executionBranch,originBranch:e.originBranch,baseSha:p,executionHeadSha:e.expectedExecutionHeadSha,strategy:e.strategy==="single_pr"?"single_pr":"direct",physicalStatus:n.externalPolicy?"denied_external_gate":"blocked_local_or_repo",localGateReceiptRefs:e.localGates.receiptRefs,idempotencyKey:e.idempotencyKey,attemptStartedAt:t,retryEligible:n.retryEligible,reasonCodes:[n.reasonCode],publicSafe:!0};return y(!1,r,[],[],r.reasonCodes)}function y(e,n,t,p,r,c=w()){return{ok:e,receipt:n,reconciliationReceipts:t,preservedDecisions:p,managedEnvironmentCleanupReceipts:c.receipts,managedEnvironmentCleanupPending:c.pending,reasonCodes:C(r),publicSafe:!0}}function w(){return{ok:!0,pending:!1,receipts:[],reasonCodes:[],publicSafe:!0}}function C(e){return[...new Set(e)]}export{Y as executeEpicGitReconciliation,V as executeEpicTerminalGit};
|
|
@@ -1,62 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* @license FSL-1.1
|
|
3
|
-
* Copyright (c) 2026 OrNexus AI
|
|
4
|
-
*
|
|
5
|
-
* P190.04 -- deterministic fake headless adapter for tests.
|
|
6
|
-
*/
|
|
7
|
-
import { HEADLESS_REASON_CODES, adapterAvailabilitySuccess, createRejectedExecutionResult, hashPublicValue, redaction, renderHeadlessPrompt, validateHeadlessAdapterExecutionInput, } from './types.js';
|
|
8
|
-
export function createFakeHeadlessAdapter(id = 'fake') {
|
|
9
|
-
return {
|
|
10
|
-
id,
|
|
11
|
-
displayName: id === 'test' ? 'Headless Test Adapter' : 'Headless Fake Adapter',
|
|
12
|
-
async checkAvailability() {
|
|
13
|
-
return adapterAvailabilitySuccess(id, 'neocortex-headless-fake', 'Fake headless adapter is available for deterministic tests.');
|
|
14
|
-
},
|
|
15
|
-
buildInvocation(input) {
|
|
16
|
-
const validation = validateHeadlessAdapterExecutionInput(input, id);
|
|
17
|
-
if (!validation.ok)
|
|
18
|
-
return validation;
|
|
19
|
-
return {
|
|
20
|
-
ok: true,
|
|
21
|
-
invocation: {
|
|
22
|
-
adapterId: id,
|
|
23
|
-
commandName: 'neocortex-headless-fake',
|
|
24
|
-
args: [validation.input.promptKind, validation.input.targetRef],
|
|
25
|
-
promptHash: validation.promptHash,
|
|
26
|
-
...(validation.input.modelId ? { modelId: validation.input.modelId } : {}),
|
|
27
|
-
timeoutMs: validation.input.timeoutMs ?? 10 * 60 * 1000,
|
|
28
|
-
publicSafe: true,
|
|
29
|
-
},
|
|
30
|
-
publicSafe: true,
|
|
31
|
-
};
|
|
32
|
-
},
|
|
33
|
-
async execute(input, _options) {
|
|
34
|
-
const validation = validateHeadlessAdapterExecutionInput(input, id);
|
|
35
|
-
if (!validation.ok)
|
|
36
|
-
return createRejectedExecutionResult(id, id, validation);
|
|
37
|
-
const prompt = renderHeadlessPrompt(validation.input);
|
|
38
|
-
return {
|
|
39
|
-
status: 'completed',
|
|
40
|
-
adapterId: id,
|
|
41
|
-
runtimeId: id,
|
|
42
|
-
...(validation.input.modelId ? { modelId: validation.input.modelId } : {}),
|
|
43
|
-
...(validation.input.runtimeSource ? { runtimeSource: validation.input.runtimeSource } : {}),
|
|
44
|
-
reasonCode: HEADLESS_REASON_CODES.EXECUTION_COMPLETED,
|
|
45
|
-
reasonCodes: [HEADLESS_REASON_CODES.EXECUTION_COMPLETED, HEADLESS_REASON_CODES.RECEIPT_REDACTED],
|
|
46
|
-
exitCode: 0,
|
|
47
|
-
signal: null,
|
|
48
|
-
durationMs: 0,
|
|
49
|
-
counts: { prompts: 1, syntheticRuns: 1 },
|
|
50
|
-
hashes: {
|
|
51
|
-
prompt: hashPublicValue(prompt),
|
|
52
|
-
receipt: hashPublicValue(`${id}:${validation.input.targetRef}:${validation.input.modelId ?? ''}`),
|
|
53
|
-
},
|
|
54
|
-
publicSummary: 'Fake headless adapter completed deterministic public-safe execution.',
|
|
55
|
-
redactionSummary: [redaction('prompt', 'prompt_body', hashPublicValue(prompt))],
|
|
56
|
-
relativePaths: [validation.input.targetRef],
|
|
57
|
-
...(validation.input.receipt ? { receipt: validation.input.receipt } : {}),
|
|
58
|
-
publicSafe: true,
|
|
59
|
-
};
|
|
60
|
-
},
|
|
61
|
-
};
|
|
62
|
-
}
|
|
1
|
+
import{HEADLESS_REASON_CODES as i,adapterAvailabilitySuccess as u,createRejectedExecutionResult as s,hashPublicValue as n,redaction as d,renderHeadlessPrompt as c,validateHeadlessAdapterExecutionInput as p}from"./types.js";function m(t="fake"){return{id:t,displayName:t==="test"?"Headless Test Adapter":"Headless Fake Adapter",async checkAvailability(){return u(t,"neocortex-headless-fake","Fake headless adapter is available for deterministic tests.")},buildInvocation(r){const a=p(r,t);return a.ok?{ok:!0,invocation:{adapterId:t,commandName:"neocortex-headless-fake",args:[a.input.promptKind,a.input.targetRef],promptHash:a.promptHash,...a.input.modelId?{modelId:a.input.modelId}:{},timeoutMs:a.input.timeoutMs??600*1e3,publicSafe:!0},publicSafe:!0}:a},async execute(r,a){const e=p(r,t);if(!e.ok)return s(t,t,e);const o=c(e.input);return{status:"completed",adapterId:t,runtimeId:t,...e.input.modelId?{modelId:e.input.modelId}:{},...e.input.runtimeSource?{runtimeSource:e.input.runtimeSource}:{},reasonCode:i.EXECUTION_COMPLETED,reasonCodes:[i.EXECUTION_COMPLETED,i.RECEIPT_REDACTED],exitCode:0,signal:null,durationMs:0,counts:{prompts:1,syntheticRuns:1},hashes:{prompt:n(o),receipt:n(`${t}:${e.input.targetRef}:${e.input.modelId??""}`)},publicSummary:"Fake headless adapter completed deterministic public-safe execution.",redactionSummary:[d("prompt","prompt_body",n(o))],relativePaths:[e.input.targetRef],...e.input.receipt?{receipt:e.input.receipt}:{},publicSafe:!0}}}}export{m as createFakeHeadlessAdapter};
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* P224.05 -- fail-closed cleanup of explicitly managed temporary resources.
|
|
3
|
+
*
|
|
4
|
+
* This module owns policy and replay ordering only. Concrete host, process and
|
|
5
|
+
* interface effects stay behind an injected adapter. Production callers that
|
|
6
|
+
* do not have a supported adapter preserve resources as pending.
|
|
7
|
+
*/
|
|
8
|
+
export type ManagedEnvironmentResourceKind = 'worktree' | 'process' | 'interface_entry';
|
|
9
|
+
export type ManagedEnvironmentEffect = 'remove_managed_worktree' | 'stop_owned_process' | 'remove_interface_entry';
|
|
10
|
+
export interface ManagedEnvironmentCleanupReceiptV1 {
|
|
11
|
+
readonly schemaVersion: 1;
|
|
12
|
+
readonly resourceId: string;
|
|
13
|
+
readonly effect: ManagedEnvironmentEffect;
|
|
14
|
+
readonly outcome: 'applied' | 'already_absent' | 'preserved' | 'failed';
|
|
15
|
+
readonly expectedOwnerDigest: string;
|
|
16
|
+
readonly expectedRevision: string;
|
|
17
|
+
readonly idempotencyKey: string;
|
|
18
|
+
readonly reasonCodes: readonly string[];
|
|
19
|
+
readonly checkedAt: string;
|
|
20
|
+
readonly recordedAt: string;
|
|
21
|
+
readonly publicSafe: true;
|
|
22
|
+
}
|
|
23
|
+
export interface ManagedEnvironmentCleanupRequestV1 {
|
|
24
|
+
readonly schemaVersion: 1;
|
|
25
|
+
readonly resourceId: string;
|
|
26
|
+
readonly epicId: string;
|
|
27
|
+
readonly expectedKind: ManagedEnvironmentResourceKind;
|
|
28
|
+
readonly expectedOwnerDigest: string;
|
|
29
|
+
readonly expectedRevision: string;
|
|
30
|
+
readonly effect: ManagedEnvironmentEffect;
|
|
31
|
+
readonly existingReceipt?: ManagedEnvironmentCleanupReceiptV1;
|
|
32
|
+
readonly publicSafe: true;
|
|
33
|
+
}
|
|
34
|
+
export interface ManagedEnvironmentSnapshotV1 {
|
|
35
|
+
readonly schemaVersion: 1;
|
|
36
|
+
readonly resourceId: string;
|
|
37
|
+
readonly epicId: string;
|
|
38
|
+
readonly ownerDigest: string;
|
|
39
|
+
readonly revision: string;
|
|
40
|
+
readonly kind: ManagedEnvironmentResourceKind;
|
|
41
|
+
readonly presence: 'present' | 'absent' | 'unknown';
|
|
42
|
+
readonly managed: boolean;
|
|
43
|
+
readonly active: boolean;
|
|
44
|
+
readonly clean: boolean | 'unknown';
|
|
45
|
+
readonly integrated: boolean;
|
|
46
|
+
readonly capability: 'supported' | 'unsupported';
|
|
47
|
+
readonly protected: boolean;
|
|
48
|
+
readonly primary: boolean;
|
|
49
|
+
readonly locked: boolean;
|
|
50
|
+
readonly submoduleActive: boolean;
|
|
51
|
+
readonly preservableIgnored: boolean;
|
|
52
|
+
readonly publicSafe: true;
|
|
53
|
+
}
|
|
54
|
+
export type ManagedEnvironmentEffectResult<T extends object> = ({
|
|
55
|
+
readonly ok: true;
|
|
56
|
+
} & T) | {
|
|
57
|
+
readonly ok: false;
|
|
58
|
+
readonly reasonCode: string;
|
|
59
|
+
};
|
|
60
|
+
export interface ManagedEnvironmentCleanupAdapter {
|
|
61
|
+
inspect(request: ManagedEnvironmentCleanupRequestV1): Promise<ManagedEnvironmentEffectResult<{
|
|
62
|
+
readonly snapshot: ManagedEnvironmentSnapshotV1;
|
|
63
|
+
}>>;
|
|
64
|
+
apply(input: {
|
|
65
|
+
readonly request: ManagedEnvironmentCleanupRequestV1;
|
|
66
|
+
readonly snapshot: ManagedEnvironmentSnapshotV1;
|
|
67
|
+
readonly effect: ManagedEnvironmentEffect;
|
|
68
|
+
readonly idempotencyKey: string;
|
|
69
|
+
}): Promise<ManagedEnvironmentEffectResult<{
|
|
70
|
+
readonly receipt: ManagedEnvironmentCleanupReceiptV1;
|
|
71
|
+
}>>;
|
|
72
|
+
reconcile(input: {
|
|
73
|
+
readonly request: ManagedEnvironmentCleanupRequestV1;
|
|
74
|
+
readonly receipt: ManagedEnvironmentCleanupReceiptV1;
|
|
75
|
+
}): Promise<ManagedEnvironmentEffectResult<{
|
|
76
|
+
readonly receipt: ManagedEnvironmentCleanupReceiptV1;
|
|
77
|
+
}>>;
|
|
78
|
+
}
|
|
79
|
+
export interface ManagedEnvironmentCleanupResult {
|
|
80
|
+
readonly ok: boolean;
|
|
81
|
+
readonly pending: boolean;
|
|
82
|
+
readonly receipts: readonly ManagedEnvironmentCleanupReceiptV1[];
|
|
83
|
+
readonly reasonCodes: readonly string[];
|
|
84
|
+
readonly publicSafe: true;
|
|
85
|
+
}
|
|
86
|
+
interface Classification {
|
|
87
|
+
readonly action: 'apply' | 'already_absent' | 'preserve';
|
|
88
|
+
readonly pending: boolean;
|
|
89
|
+
readonly reasonCodes: readonly string[];
|
|
90
|
+
}
|
|
91
|
+
/** Reconcile durable evidence before any new effect, then apply at most once. */
|
|
92
|
+
export declare function executeManagedEnvironmentCleanup(requests: readonly ManagedEnvironmentCleanupRequestV1[], adapter: ManagedEnvironmentCleanupAdapter | undefined, now: () => string): Promise<ManagedEnvironmentCleanupResult>;
|
|
93
|
+
export declare function classifyManagedEnvironmentSnapshot(request: ManagedEnvironmentCleanupRequestV1, snapshot: ManagedEnvironmentSnapshotV1): Classification;
|
|
94
|
+
export declare function managedEnvironmentCleanupIdempotencyKey(request: Pick<ManagedEnvironmentCleanupRequestV1, 'resourceId' | 'effect' | 'expectedOwnerDigest' | 'expectedRevision'>): string;
|
|
95
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createHash as E}from"node:crypto";const D={remove_managed_worktree:"worktree",stop_owned_process:"process",remove_interface_entry:"interface_entry"};async function M(e,n,c){const t=[],a=[],h=new Set;let d=!1,s=!1;for(const r of e){const R=`${r.resourceId}\0${r.effect}`;if(h.has(R)){const i=m(r,I(r),"managed-environment-request-duplicate",c());t.push(i),a.push(...i.reasonCodes),d=!0,s=!0;continue}h.add(R);const w=$(r);if(w){const i=m(r,I(r),w,c());t.push(i),a.push(w),d=!0,s=!0;continue}const u=I(r);if(!n){const i=x(r,u,"preserved",["managed-environment-capability-unsupported"],c());t.push(i),a.push(...i.reasonCodes),d=!0;continue}if(r.existingReceipt){if(!k(r.existingReceipt,r)||r.existingReceipt.idempotencyKey!==u){const b=m(r,u,"managed-environment-receipt-binding-mismatch",c());t.push(b),a.push(...b.reasonCodes),d=!0,s=!0;continue}const i=await n.reconcile({request:r,receipt:r.existingReceipt});if(!i.ok||!k(i.receipt,r)||i.receipt.idempotencyKey!==u){const b=i.ok?"managed-environment-receipt-binding-mismatch":i.reasonCode,A=m(r,u,b,c());t.push(A),a.push(b),d=!0,s=!0;continue}const f=K(i.receipt);if(f.failed||!f.pending){t.push(i.receipt),a.push(...i.receipt.reasonCodes),d||=f.pending,s||=f.failed;continue}}const y=await n.inspect(r);if(!y.ok){const i=m(r,u,y.reasonCode,c());t.push(i),a.push(y.reasonCode),d=!0,s=!0;continue}const l=V(r,y.snapshot);if(a.push(...l.reasonCodes),l.action==="preserve"){t.push(x(r,u,"preserved",l.reasonCodes,c())),d||=l.pending;continue}if(l.action==="already_absent"){t.push(x(r,u,"already_absent",l.reasonCodes,c()));continue}const g=await n.apply({request:r,snapshot:y.snapshot,effect:r.effect,idempotencyKey:u});if(!g.ok||!k(g.receipt,r)||g.receipt.idempotencyKey!==u){const i=g.ok?"managed-environment-receipt-binding-mismatch":g.reasonCode,f=m(r,u,i,c());t.push(f),a.push(i),d=!0,s=!0;continue}const p=await n.reconcile({request:r,receipt:g.receipt});if(!p.ok||!k(p.receipt,r)||p.receipt.idempotencyKey!==u){const i=p.ok?"managed-environment-receipt-binding-mismatch":p.reasonCode,f=m(r,u,i,c());t.push(f),a.push(i),d=!0,s=!0;continue}t.push(p.receipt),a.push(...p.receipt.reasonCodes);const _=K(p.receipt);d||=_.pending,s||=_.failed}return{ok:!s&&!d,pending:d,receipts:t,reasonCodes:S(a),publicSafe:!0}}function V(e,n){return N(n)?n.resourceId!==e.resourceId||n.epicId!==e.epicId?o(!1,"managed-environment-identity-mismatch"):n.kind!==e.expectedKind||D[e.effect]!==n.kind?o(!1,"managed-environment-kind-mismatch"):n.managed?n.ownerDigest!==e.expectedOwnerDigest?o(!1,"managed-environment-owner-replaced"):n.revision!==e.expectedRevision?o(!1,"managed-environment-revision-stale"):n.presence==="absent"?{action:"already_absent",pending:!1,reasonCodes:["managed-environment-already-absent"]}:n.presence!=="present"?o(!0,"managed-environment-presence-unknown"):n.capability!=="supported"?o(!0,"managed-environment-capability-unsupported"):n.primary?o(!0,"managed-environment-primary-preserved"):n.protected?o(!0,"managed-environment-protected"):n.active?o(!0,"managed-environment-active"):n.locked?o(!0,"managed-environment-locked"):n.submoduleActive?o(!0,"managed-environment-submodule-active"):n.clean==="unknown"?o(!0,"managed-environment-cleanliness-unknown"):n.clean?n.preservableIgnored?o(!0,"managed-environment-preservable-ignored"):n.integrated?{action:"apply",pending:!1,reasonCodes:[]}:o(!0,"managed-environment-integration-unproven"):o(!0,"managed-environment-dirty"):o(!1,"managed-environment-ownership-unproven"):o(!0,"managed-environment-snapshot-invalid")}function I(e){return`environment-cleanup:v1:${E("sha256").update([e.resourceId,e.effect,e.expectedOwnerDigest,e.expectedRevision].join("\0")).digest("hex")}`}function $(e){return e.schemaVersion!==1||e.publicSafe!==!0||!v(e.resourceId)||!v(e.epicId)||!C(e.expectedOwnerDigest)||!C(e.expectedRevision)||D[e.effect]!==e.expectedKind?"managed-environment-request-invalid":null}function N(e){return e.schemaVersion===1&&e.publicSafe===!0&&v(e.resourceId)&&v(e.epicId)&&C(e.ownerDigest)&&C(e.revision)&&["worktree","process","interface_entry"].includes(e.kind)&&["present","absent","unknown"].includes(e.presence)&&["supported","unsupported"].includes(e.capability)&&(typeof e.clean=="boolean"||e.clean==="unknown")&&[e.managed,e.active,e.integrated,e.protected,e.primary,e.locked,e.submoduleActive,e.preservableIgnored].every(n=>typeof n=="boolean")}function k(e,n){return e.schemaVersion===1&&e.publicSafe===!0&&e.resourceId===n.resourceId&&e.effect===n.effect&&e.expectedOwnerDigest===n.expectedOwnerDigest&&e.expectedRevision===n.expectedRevision&&["applied","already_absent","preserved","failed"].includes(e.outcome)&&v(e.idempotencyKey)&&e.reasonCodes.length<=128&&e.reasonCodes.every(v)&&O(e.checkedAt)&&O(e.recordedAt)}function K(e){return e.outcome==="failed"?{pending:!0,failed:!0}:e.outcome!=="preserved"?{pending:!1,failed:!1}:{pending:!e.reasonCodes.every(c=>["managed-environment-ownership-unproven","managed-environment-owner-replaced","managed-environment-revision-stale","managed-environment-kind-mismatch","managed-environment-identity-mismatch"].includes(c)),failed:!1}}function o(e,n){return{action:"preserve",pending:e,reasonCodes:[n]}}function x(e,n,c,t,a){return{schemaVersion:1,resourceId:e.resourceId,effect:e.effect,outcome:c,expectedOwnerDigest:e.expectedOwnerDigest,expectedRevision:e.expectedRevision,idempotencyKey:n,reasonCodes:S(t),checkedAt:a,recordedAt:a,publicSafe:!0}}function m(e,n,c,t){return x(e,n,"failed",[c],t)}function v(e){return typeof e=="string"&&e.length>0&&e.length<=240&&/^[A-Za-z0-9._:/@#-]+$/.test(e)}function C(e){return typeof e=="string"&&/^[a-f0-9]{64}$/.test(e)}function O(e){return typeof e=="string"&&Number.isFinite(Date.parse(e))}function S(e){return[...new Set(e)]}export{V as classifyManagedEnvironmentSnapshot,M as executeManagedEnvironmentCleanup,I as managedEnvironmentCleanupIdempotencyKey};
|