@ornexus/neocortex 4.61.5 → 4.61.6
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 +1193 -1193
- 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 -220
- 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 -443
- package/packages/client/dist/agent/update-agent-yaml.js +1 -102
- package/packages/client/dist/agent/update-description.js +1 -260
- package/packages/client/dist/cache/crypto-utils.js +1 -78
- package/packages/client/dist/cache/encrypted-cache.js +1 -338
- 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 -364
- 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.js +148 -7822
- 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 -174
- package/packages/client/dist/commands/shared-architecture-non-ui.js +1 -24
- package/packages/client/dist/commands/story-checkpoint.d.ts +5 -1
- package/packages/client/dist/commands/story-checkpoint.js +1 -203
- package/packages/client/dist/commands/story-worktree.js +5 -258
- package/packages/client/dist/config/host-auth-broker.js +1 -60
- package/packages/client/dist/config/host-auth-reference.js +1 -93
- 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 -224
- 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.js +1 -105
- 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.js +2 -258
- 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 +70 -0
- package/packages/client/dist/git/direct-yolo-checkpoint.js +4 -1592
- 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 +22 -0
- package/packages/client/dist/git/git-lifecycle-store.js +8 -2529
- 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/neocortex-trailers.js +2 -53
- package/packages/client/dist/git/secure-filesystem-boundary.js +5 -182
- package/packages/client/dist/git/story-worktree-cleanup.js +4 -1058
- package/packages/client/dist/git/story-worktree-integration.d.ts +62 -0
- package/packages/client/dist/git/story-worktree-integration.js +3 -603
- package/packages/client/dist/git/story-worktree-manager.js +3 -843
- package/packages/client/dist/git/story-worktree-paths.js +1 -150
- package/packages/client/dist/git/story-write-set-extension.d.ts +44 -0
- package/packages/client/dist/git/story-write-set-extension.js +1 -0
- 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.js +1 -50
- package/packages/client/dist/invocation/invoke-input.js +1 -24
- package/packages/client/dist/license/host-auth-recovery.js +1 -401
- package/packages/client/dist/license/index.js +1 -5
- package/packages/client/dist/license/license-client.js +1 -337
- 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 +41 -1117
- package/packages/client/dist/memory/shared-project-memory-types.js +2 -259
- 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 -57
- 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.js +1 -124
- package/packages/client/dist/runner/headless/adapters.js +1 -49
- package/packages/client/dist/runner/headless/background-root.js +1 -85
- package/packages/client/dist/runner/headless/claude-code-adapter.js +1 -79
- package/packages/client/dist/runner/headless/continuous-story-workspace.js +11 -1776
- package/packages/client/dist/runner/headless/epic-git-reconciliation-inventory.js +1 -69
- package/packages/client/dist/runner/headless/epic-merge-candidate-qa.js +2 -111
- package/packages/client/dist/runner/headless/epic-terminal-git-cli-adapter.js +10 -1464
- package/packages/client/dist/runner/headless/epic-terminal-git-runner.js +2 -357
- package/packages/client/dist/runner/headless/fake-adapter.js +1 -62
- package/packages/client/dist/runner/headless/managed-environment-cleanup.js +1 -274
- package/packages/client/dist/runner/headless/managed-profile.js +1 -149
- 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 -886
- package/packages/client/dist/runner/headless/run-yoloop.js +2 -2657
- package/packages/client/dist/runner/headless/types.js +2 -575
- package/packages/client/dist/runner/host-capacity.js +1 -59
- 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.js +1 -1754
- 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 +10 -0
- package/packages/client/dist/yolo/change-evidence-collector.js +1 -262
- package/packages/client/dist/yolo/invoke-envelope-capability.js +1 -65
- 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/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
|
@@ -1,357 +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 { consumeEpicTerminalReleaseAuthority, } from '../../git/git-lifecycle-store.js';
|
|
8
|
-
import { verifiedEpicMergeCandidateReceipt, } from './epic-merge-candidate-qa.js';
|
|
9
|
-
import { executeManagedEnvironmentCleanup, } from './managed-environment-cleanup.js';
|
|
10
|
-
/** Run the same fail-closed reconciler at start/resume or explicit audit. */
|
|
11
|
-
export async function executeEpicGitReconciliation(directive, adapter, now) {
|
|
12
|
-
const inspected = await adapter.inspectReconciliation(directive);
|
|
13
|
-
if (!inspected.ok) {
|
|
14
|
-
return { ok: false, reconciliationReceipts: [], preservedDecisions: [], reasonCodes: [inspected.reasonCode], publicSafe: true };
|
|
15
|
-
}
|
|
16
|
-
const reconciliation = await reconcileCandidates({
|
|
17
|
-
idempotencyKey: directive.idempotencyKey,
|
|
18
|
-
enabled: true,
|
|
19
|
-
dryRun: directive.dryRun,
|
|
20
|
-
}, inspected.candidates, adapter, now);
|
|
21
|
-
const persisted = await adapter.persistReconciliation({
|
|
22
|
-
epicId: directive.epicId,
|
|
23
|
-
reconciliationReceipts: reconciliation.receipts,
|
|
24
|
-
preservedDecisions: reconciliation.preserved,
|
|
25
|
-
});
|
|
26
|
-
const reasonCodes = unique([...reconciliation.reasonCodes, ...(persisted.ok ? [] : [persisted.reasonCode])]);
|
|
27
|
-
return {
|
|
28
|
-
ok: reconciliation.ok && persisted.ok,
|
|
29
|
-
reconciliationReceipts: reconciliation.receipts,
|
|
30
|
-
preservedDecisions: reconciliation.preserved,
|
|
31
|
-
reasonCodes,
|
|
32
|
-
publicSafe: true,
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
export async function executeEpicTerminalGit(directive, adapter, now, preparedAuthority) {
|
|
36
|
-
const startedAt = now();
|
|
37
|
-
if (!adapter.prepareLifecycleEvidence) {
|
|
38
|
-
return failedBeforeSnapshot(directive, {
|
|
39
|
-
ok: false, reasonCode: 'epic-aggregate-qa-producer-required', retryEligible: false, externalPolicy: false,
|
|
40
|
-
}, startedAt);
|
|
41
|
-
}
|
|
42
|
-
const produced = preparedAuthority
|
|
43
|
-
? { ok: true, originBindingCaptured: false, aggregateQaRecorded: true, terminalAuthority: preparedAuthority }
|
|
44
|
-
: await adapter.prepareLifecycleEvidence({ epicId: directive.epicId, nowIso: startedAt });
|
|
45
|
-
if (!produced.ok)
|
|
46
|
-
return failedBeforeSnapshot(directive, produced, startedAt);
|
|
47
|
-
const terminalAuthority = produced.terminalAuthority ?? produced.p205Authority;
|
|
48
|
-
if (!terminalAuthority) {
|
|
49
|
-
return failedBeforeSnapshot(directive, {
|
|
50
|
-
ok: false, reasonCode: 'epic-aggregate-qa-authority-required', retryEligible: false, externalPolicy: false,
|
|
51
|
-
}, startedAt);
|
|
52
|
-
}
|
|
53
|
-
const inspected = await adapter.inspect(directive);
|
|
54
|
-
if (!inspected.ok)
|
|
55
|
-
return failedBeforeSnapshot(directive, inspected, startedAt);
|
|
56
|
-
const snapshot = inspected.snapshot;
|
|
57
|
-
const readiness = validateEpicTerminalGitDirective(directive, { ...snapshot, nowIso: startedAt });
|
|
58
|
-
if (!readiness.ready) {
|
|
59
|
-
return terminalResult(false, baseReceipt(directive, snapshot, startedAt, {
|
|
60
|
-
strategy: directive.strategy === 'single_pr' ? 'single_pr' : 'direct',
|
|
61
|
-
physicalStatus: 'blocked_local_or_repo',
|
|
62
|
-
retryEligible: readiness.reasonCodes.some((code) => code.endsWith('mismatch') || code.endsWith('active')),
|
|
63
|
-
reasonCodes: readiness.reasonCodes,
|
|
64
|
-
}), [], [], readiness.reasonCodes);
|
|
65
|
-
}
|
|
66
|
-
if (!snapshot.aggregateQaReceipt || !consumeEpicTerminalReleaseAuthority(terminalAuthority, {
|
|
67
|
-
executionHeadSha: snapshot.executionHeadSha,
|
|
68
|
-
graphRevision: directive.graphRevision,
|
|
69
|
-
aggregateQaReceipt: snapshot.aggregateQaReceipt,
|
|
70
|
-
headReconciliationReceipt: snapshot.headReconciliationReceipt,
|
|
71
|
-
})) {
|
|
72
|
-
return failedBeforeSnapshot(directive, {
|
|
73
|
-
ok: false, reasonCode: 'epic-aggregate-qa-authority-binding-mismatch', retryEligible: false, externalPolicy: false,
|
|
74
|
-
}, startedAt);
|
|
75
|
-
}
|
|
76
|
-
if (readiness.reasonCodes.includes(EPIC_TERMINAL_GIT_REASON_CODES.ALREADY_COMPLETE) && snapshot.existingReceipt) {
|
|
77
|
-
const verified = await adapter.verifyTerminalReceipt(directive, snapshot.existingReceipt, startedAt);
|
|
78
|
-
if (!verified.ok)
|
|
79
|
-
return terminalResult(false, snapshot.existingReceipt, [], [], [verified.reasonCode]);
|
|
80
|
-
const candidateQa = verifiedEpicMergeCandidateReceipt(verified.candidateAuthority, {
|
|
81
|
-
mergeSha: snapshot.existingReceipt.mergeSha, originHeadSha: snapshot.existingReceipt.baseSha,
|
|
82
|
-
executionHeadSha: snapshot.existingReceipt.executionHeadSha, graphRevision: directive.graphRevision,
|
|
83
|
-
});
|
|
84
|
-
if (!candidateQa)
|
|
85
|
-
return terminalResult(false, snapshot.existingReceipt, [], [], ['epic-merge-candidate-authority-required']);
|
|
86
|
-
const verifiedReceipt = {
|
|
87
|
-
...snapshot.existingReceipt, candidateQa,
|
|
88
|
-
...(verified.providerGuard ? { providerGuard: verified.providerGuard } : {}),
|
|
89
|
-
};
|
|
90
|
-
const reconciliation = await reconcileCandidates({ idempotencyKey: directive.idempotencyKey, enabled: directive.reconcile.enabled, dryRun: directive.reconcile.dryRun }, snapshot.reconciliationCandidates, adapter, now);
|
|
91
|
-
const environment = await executeManagedEnvironmentCleanup(snapshot.managedEnvironmentCleanupRequests ?? [], adapter.managedEnvironmentCleanup, now);
|
|
92
|
-
const persisted = await adapter.persist({
|
|
93
|
-
terminalReceipt: verifiedReceipt,
|
|
94
|
-
reconciliationReceipts: reconciliation.receipts,
|
|
95
|
-
preservedDecisions: reconciliation.preserved,
|
|
96
|
-
managedEnvironmentCleanupReceipts: environment.receipts,
|
|
97
|
-
});
|
|
98
|
-
const reasons = unique([...readiness.reasonCodes, ...reconciliation.reasonCodes, ...environment.reasonCodes,
|
|
99
|
-
...(persisted.ok ? [] : [persisted.reasonCode])]);
|
|
100
|
-
return terminalResult(persisted.ok && reconciliation.ok && environment.ok, verifiedReceipt, reconciliation.receipts, reconciliation.preserved, reasons, environment);
|
|
101
|
-
}
|
|
102
|
-
let receipt;
|
|
103
|
-
const prepared = await adapter.prepareMergeObject({
|
|
104
|
-
originBranch: directive.originBranch,
|
|
105
|
-
executionBranch: directive.executionBranch,
|
|
106
|
-
originHeadSha: snapshot.originHeadSha,
|
|
107
|
-
executionHeadSha: snapshot.executionHeadSha,
|
|
108
|
-
graphRevision: directive.graphRevision,
|
|
109
|
-
nowIso: startedAt,
|
|
110
|
-
message: [
|
|
111
|
-
`merge(${directive.epicId}): integrate ${directive.executionBranch} into ${directive.originBranch}`,
|
|
112
|
-
'',
|
|
113
|
-
`Neocortex-Epic: ${directive.epicId}`,
|
|
114
|
-
`Neocortex-Origin-Branch: ${directive.originBranch}`,
|
|
115
|
-
`Neocortex-Execution-Branch: ${directive.executionBranch}`,
|
|
116
|
-
`Neocortex-Execution-Head: ${snapshot.executionHeadSha}`,
|
|
117
|
-
`Neocortex-Origin-Base: ${snapshot.originHeadSha}`,
|
|
118
|
-
`Neocortex-Graph-Revision: ${directive.graphRevision}`,
|
|
119
|
-
`Neocortex-Aggregate-QA: ${directive.localGates.aggregateQaReceipt.receiptRef}`,
|
|
120
|
-
`Neocortex-Idempotency: ${directive.idempotencyKey}`,
|
|
121
|
-
].join('\n'),
|
|
122
|
-
});
|
|
123
|
-
if (!prepared.ok) {
|
|
124
|
-
receipt = baseReceipt(directive, snapshot, startedAt, {
|
|
125
|
-
strategy: 'direct',
|
|
126
|
-
physicalStatus: 'blocked_local_or_repo',
|
|
127
|
-
retryEligible: prepared.retryEligible,
|
|
128
|
-
reasonCodes: [prepared.reasonCode],
|
|
129
|
-
});
|
|
130
|
-
await adapter.persist({ terminalReceipt: receipt, reconciliationReceipts: [], preservedDecisions: [] });
|
|
131
|
-
return terminalResult(false, receipt, [], [], receipt.reasonCodes);
|
|
132
|
-
}
|
|
133
|
-
const candidateQa = verifiedEpicMergeCandidateReceipt(prepared.candidateAuthority, {
|
|
134
|
-
originHeadSha: snapshot.originHeadSha, executionHeadSha: snapshot.executionHeadSha,
|
|
135
|
-
mergeSha: prepared.mergeSha, graphRevision: directive.graphRevision,
|
|
136
|
-
});
|
|
137
|
-
if (!candidateQa)
|
|
138
|
-
return failedBeforeSnapshot(directive, {
|
|
139
|
-
ok: false, reasonCode: 'epic-merge-candidate-authority-required', retryEligible: false, externalPolicy: false,
|
|
140
|
-
}, startedAt);
|
|
141
|
-
if (directive.strategy !== 'single_pr') {
|
|
142
|
-
const pushed = await adapter.pushMergeObject({
|
|
143
|
-
epicId: directive.epicId,
|
|
144
|
-
originBranch: directive.originBranch,
|
|
145
|
-
executionBranch: directive.executionBranch,
|
|
146
|
-
executionHeadSha: snapshot.executionHeadSha,
|
|
147
|
-
expectedOriginSha: snapshot.originHeadSha,
|
|
148
|
-
mergeSha: prepared.mergeSha,
|
|
149
|
-
graphRevision: directive.graphRevision,
|
|
150
|
-
candidateAuthority: prepared.candidateAuthority,
|
|
151
|
-
storyCheckpointIds: directive.storyCheckpointIds,
|
|
152
|
-
aggregateQaReceipt: directive.localGates.aggregateQaReceipt,
|
|
153
|
-
nowIso: now(),
|
|
154
|
-
});
|
|
155
|
-
if (pushed.ok) {
|
|
156
|
-
receipt = baseReceipt(directive, snapshot, startedAt, {
|
|
157
|
-
strategy: 'direct', mergeSha: prepared.mergeSha, pushedSha: pushed.pushedSha, candidateQa,
|
|
158
|
-
physicalStatus: 'pushed', retryEligible: false,
|
|
159
|
-
reasonCodes: [EPIC_TERMINAL_GIT_REASON_CODES.READY], completedAt: now(),
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
else if (directive.strategy === 'direct_or_single_pr' && pushed.externalPolicy) {
|
|
163
|
-
receipt = await executePullRequestFallback(directive, snapshot, adapter, startedAt, now, candidateQa, prepared.candidateAuthority);
|
|
164
|
-
}
|
|
165
|
-
else {
|
|
166
|
-
receipt = baseReceipt(directive, snapshot, startedAt, {
|
|
167
|
-
strategy: 'direct', mergeSha: prepared.mergeSha,
|
|
168
|
-
physicalStatus: pushed.externalPolicy ? 'denied_external_gate' : 'blocked_local_or_repo',
|
|
169
|
-
retryEligible: pushed.retryEligible,
|
|
170
|
-
reasonCodes: [pushed.reasonCode, ...(pushed.retryEligible ? [EPIC_TERMINAL_GIT_REASON_CODES.RETRY_ELIGIBLE] : [])],
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
else {
|
|
175
|
-
receipt = await executePullRequestFallback(directive, snapshot, adapter, startedAt, now, candidateQa, prepared.candidateAuthority);
|
|
176
|
-
}
|
|
177
|
-
const verified = receipt.physicalStatus === 'pushed'
|
|
178
|
-
? await adapter.verifyTerminalReceipt(directive, receipt, now())
|
|
179
|
-
: null;
|
|
180
|
-
if (verified && !verified.ok) {
|
|
181
|
-
const failedReceipt = baseReceipt(directive, snapshot, startedAt, {
|
|
182
|
-
...receipt,
|
|
183
|
-
physicalStatus: 'blocked_local_or_repo',
|
|
184
|
-
retryEligible: verified.retryEligible,
|
|
185
|
-
reasonCodes: [verified.reasonCode],
|
|
186
|
-
});
|
|
187
|
-
await adapter.persist({ terminalReceipt: failedReceipt, reconciliationReceipts: [], preservedDecisions: [] });
|
|
188
|
-
return terminalResult(false, failedReceipt, [], [], failedReceipt.reasonCodes);
|
|
189
|
-
}
|
|
190
|
-
if (verified?.ok) {
|
|
191
|
-
const accepted = verifiedEpicMergeCandidateReceipt(verified.candidateAuthority, {
|
|
192
|
-
mergeSha: receipt.mergeSha, originHeadSha: receipt.baseSha,
|
|
193
|
-
executionHeadSha: receipt.executionHeadSha, graphRevision: directive.graphRevision,
|
|
194
|
-
});
|
|
195
|
-
if (!accepted)
|
|
196
|
-
return terminalResult(false, receipt, [], [], ['epic-merge-candidate-authority-required']);
|
|
197
|
-
receipt = {
|
|
198
|
-
...receipt, candidateQa: accepted,
|
|
199
|
-
...(verified.providerGuard ? { providerGuard: verified.providerGuard } : {}),
|
|
200
|
-
};
|
|
201
|
-
}
|
|
202
|
-
const reconciliation = receipt.physicalStatus === 'pushed'
|
|
203
|
-
? await reconcileCandidates({ idempotencyKey: directive.idempotencyKey, enabled: directive.reconcile.enabled, dryRun: directive.reconcile.dryRun }, snapshot.reconciliationCandidates, adapter, now)
|
|
204
|
-
: { ok: true, receipts: [], preserved: [], reasonCodes: [] };
|
|
205
|
-
const environment = receipt.physicalStatus === 'pushed'
|
|
206
|
-
? await executeManagedEnvironmentCleanup(snapshot.managedEnvironmentCleanupRequests ?? [], adapter.managedEnvironmentCleanup, now)
|
|
207
|
-
: emptyManagedEnvironmentCleanup();
|
|
208
|
-
const persisted = await adapter.persist({
|
|
209
|
-
terminalReceipt: receipt,
|
|
210
|
-
reconciliationReceipts: reconciliation.receipts,
|
|
211
|
-
preservedDecisions: reconciliation.preserved,
|
|
212
|
-
managedEnvironmentCleanupReceipts: environment.receipts,
|
|
213
|
-
});
|
|
214
|
-
const reasons = unique([...receipt.reasonCodes, ...reconciliation.reasonCodes, ...environment.reasonCodes,
|
|
215
|
-
...(persisted.ok ? [] : [persisted.reasonCode])]);
|
|
216
|
-
return terminalResult(receipt.physicalStatus === 'pushed' && reconciliation.ok && environment.ok && persisted.ok, receipt, reconciliation.receipts, reconciliation.preserved, reasons, environment);
|
|
217
|
-
}
|
|
218
|
-
async function executePullRequestFallback(directive, snapshot, adapter, startedAt, now, candidateQa, candidateAuthority) {
|
|
219
|
-
const pr = await adapter.ensureSingleEpicPullRequest({
|
|
220
|
-
epicId: directive.epicId,
|
|
221
|
-
originBranch: directive.originBranch,
|
|
222
|
-
executionBranch: directive.executionBranch,
|
|
223
|
-
expectedStoryHeadSha: snapshot.executionHeadSha,
|
|
224
|
-
expectedPullRequestHeadSha: candidateQa.mergeSha,
|
|
225
|
-
candidateQa,
|
|
226
|
-
candidateAuthority,
|
|
227
|
-
idempotencyKey: directive.idempotencyKey,
|
|
228
|
-
terminalBinding: {
|
|
229
|
-
graphRevision: directive.graphRevision,
|
|
230
|
-
storyCheckpointIds: directive.storyCheckpointIds,
|
|
231
|
-
aggregateQaReceipt: directive.localGates.aggregateQaReceipt,
|
|
232
|
-
nowIso: now(),
|
|
233
|
-
},
|
|
234
|
-
});
|
|
235
|
-
if (!pr.ok)
|
|
236
|
-
return baseReceipt(directive, snapshot, startedAt, {
|
|
237
|
-
strategy: 'single_pr', physicalStatus: pr.externalPolicy ? 'denied_external_gate' : 'blocked_local_or_repo',
|
|
238
|
-
retryEligible: pr.retryEligible, reasonCodes: [pr.reasonCode],
|
|
239
|
-
});
|
|
240
|
-
const merged = await adapter.mergeEpicPullRequest({
|
|
241
|
-
epicId: directive.epicId,
|
|
242
|
-
prNumber: pr.prNumber,
|
|
243
|
-
originBranch: directive.originBranch,
|
|
244
|
-
executionBranch: directive.executionBranch,
|
|
245
|
-
expectedStoryHeadSha: snapshot.executionHeadSha,
|
|
246
|
-
expectedPullRequestHeadSha: candidateQa.mergeSha,
|
|
247
|
-
expectedOriginHeadSha: snapshot.originHeadSha,
|
|
248
|
-
candidateQa, candidateAuthority, nowIso: now(),
|
|
249
|
-
terminalBinding: {
|
|
250
|
-
graphRevision: directive.graphRevision,
|
|
251
|
-
storyCheckpointIds: directive.storyCheckpointIds,
|
|
252
|
-
aggregateQaReceipt: directive.localGates.aggregateQaReceipt,
|
|
253
|
-
},
|
|
254
|
-
});
|
|
255
|
-
if (!merged.ok)
|
|
256
|
-
return baseReceipt(directive, snapshot, startedAt, {
|
|
257
|
-
strategy: 'single_pr', prNumber: pr.prNumber,
|
|
258
|
-
physicalStatus: merged.externalPolicy ? 'denied_external_gate' : 'blocked_local_or_repo',
|
|
259
|
-
retryEligible: merged.retryEligible,
|
|
260
|
-
reasonCodes: [merged.reasonCode, ...(merged.retryEligible ? [EPIC_TERMINAL_GIT_REASON_CODES.RETRY_ELIGIBLE] : [])],
|
|
261
|
-
});
|
|
262
|
-
return baseReceipt(directive, snapshot, startedAt, {
|
|
263
|
-
strategy: 'single_pr', prNumber: pr.prNumber, mergeSha: merged.mergeSha, pushedSha: merged.pushedSha, candidateQa,
|
|
264
|
-
providerGuard: merged.providerGuard,
|
|
265
|
-
physicalStatus: 'pushed', retryEligible: false,
|
|
266
|
-
reasonCodes: [EPIC_TERMINAL_GIT_REASON_CODES.READY], completedAt: now(),
|
|
267
|
-
});
|
|
268
|
-
}
|
|
269
|
-
async function reconcileCandidates(directive, candidates, adapter, now) {
|
|
270
|
-
if (!directive.enabled)
|
|
271
|
-
return { ok: true, receipts: [], preserved: [], reasonCodes: [] };
|
|
272
|
-
const receipts = [];
|
|
273
|
-
const preserved = [];
|
|
274
|
-
const reasons = [];
|
|
275
|
-
let ok = true;
|
|
276
|
-
const failedPrBranches = new Set();
|
|
277
|
-
const order = { pull_request: 0, local_branch: 1, remote_branch: 2 };
|
|
278
|
-
for (const candidate of [...candidates].sort((a, b) => order[a.kind] - order[b.kind] || a.resourceId.localeCompare(b.resourceId))) {
|
|
279
|
-
const decision = classifyGitReconciliationCandidate(candidate);
|
|
280
|
-
reasons.push(...decision.reasonCodes);
|
|
281
|
-
if (decision.action === 'preserve') {
|
|
282
|
-
preserved.push(decision);
|
|
283
|
-
continue;
|
|
284
|
-
}
|
|
285
|
-
if (candidate.kind !== 'pull_request' && failedPrBranches.has(candidate.branchName)) {
|
|
286
|
-
preserved.push({ ...decision, action: 'preserve', reasonCodes: ['git-resource-related-pr-close-pending'] });
|
|
287
|
-
reasons.push('git-resource-related-pr-close-pending');
|
|
288
|
-
continue;
|
|
289
|
-
}
|
|
290
|
-
// Stable across start/resume/terminal directives; no long branch name or
|
|
291
|
-
// unbounded parent id can overflow the public receipt schema.
|
|
292
|
-
const receiptKey = `reconciliation:v2:${createHash('sha256').update([candidate.resourceId, decision.action].join('\0')).digest('hex')}`;
|
|
293
|
-
const applied = await adapter.applyReconciliation(candidate, decision, directive.dryRun);
|
|
294
|
-
if (!applied.ok) {
|
|
295
|
-
ok = false;
|
|
296
|
-
if (candidate.kind === 'pull_request')
|
|
297
|
-
failedPrBranches.add(candidate.branchName);
|
|
298
|
-
reasons.push(applied.reasonCode);
|
|
299
|
-
receipts.push({
|
|
300
|
-
schemaVersion: 1, resourceId: candidate.resourceId, action: decision.action,
|
|
301
|
-
outcome: 'failed', idempotencyKey: receiptKey,
|
|
302
|
-
reasonCodes: [applied.reasonCode], recordedAt: now(), publicSafe: true,
|
|
303
|
-
});
|
|
304
|
-
continue;
|
|
305
|
-
}
|
|
306
|
-
receipts.push({
|
|
307
|
-
schemaVersion: 1, resourceId: candidate.resourceId, action: decision.action,
|
|
308
|
-
outcome: applied.outcome, idempotencyKey: receiptKey,
|
|
309
|
-
reasonCodes: decision.reasonCodes, recordedAt: now(), publicSafe: true,
|
|
310
|
-
});
|
|
311
|
-
}
|
|
312
|
-
return { ok, receipts, preserved, reasonCodes: unique(reasons) };
|
|
313
|
-
}
|
|
314
|
-
function baseReceipt(directive, snapshot, startedAt, override) {
|
|
315
|
-
return Object.freeze({
|
|
316
|
-
schemaVersion: 1,
|
|
317
|
-
epicId: directive.epicId,
|
|
318
|
-
executionBranch: directive.executionBranch,
|
|
319
|
-
originBranch: directive.originBranch,
|
|
320
|
-
baseSha: snapshot.originHeadSha,
|
|
321
|
-
executionHeadSha: snapshot.executionHeadSha,
|
|
322
|
-
localGateReceiptRefs: directive.localGates.receiptRefs,
|
|
323
|
-
idempotencyKey: directive.idempotencyKey,
|
|
324
|
-
attemptStartedAt: startedAt,
|
|
325
|
-
publicSafe: true,
|
|
326
|
-
...override,
|
|
327
|
-
});
|
|
328
|
-
}
|
|
329
|
-
function failedBeforeSnapshot(directive, failure, startedAt) {
|
|
330
|
-
const placeholder = '0'.repeat(40);
|
|
331
|
-
const receipt = {
|
|
332
|
-
schemaVersion: 1, epicId: directive.epicId, executionBranch: directive.executionBranch, originBranch: directive.originBranch,
|
|
333
|
-
baseSha: placeholder, executionHeadSha: directive.expectedExecutionHeadSha, strategy: directive.strategy === 'single_pr' ? 'single_pr' : 'direct',
|
|
334
|
-
physicalStatus: failure.externalPolicy ? 'denied_external_gate' : 'blocked_local_or_repo',
|
|
335
|
-
localGateReceiptRefs: directive.localGates.receiptRefs, idempotencyKey: directive.idempotencyKey,
|
|
336
|
-
attemptStartedAt: startedAt, retryEligible: failure.retryEligible, reasonCodes: [failure.reasonCode], publicSafe: true,
|
|
337
|
-
};
|
|
338
|
-
return terminalResult(false, receipt, [], [], receipt.reasonCodes);
|
|
339
|
-
}
|
|
340
|
-
function terminalResult(ok, receipt, reconciliationReceipts, preservedDecisions, reasonCodes, environment = emptyManagedEnvironmentCleanup()) {
|
|
341
|
-
return {
|
|
342
|
-
ok,
|
|
343
|
-
receipt,
|
|
344
|
-
reconciliationReceipts,
|
|
345
|
-
preservedDecisions,
|
|
346
|
-
managedEnvironmentCleanupReceipts: environment.receipts,
|
|
347
|
-
managedEnvironmentCleanupPending: environment.pending,
|
|
348
|
-
reasonCodes: unique(reasonCodes),
|
|
349
|
-
publicSafe: true,
|
|
350
|
-
};
|
|
351
|
-
}
|
|
352
|
-
function emptyManagedEnvironmentCleanup() {
|
|
353
|
-
return { ok: true, pending: false, receipts: [], reasonCodes: [], publicSafe: true };
|
|
354
|
-
}
|
|
355
|
-
function unique(values) {
|
|
356
|
-
return [...new Set(values)];
|
|
357
|
-
}
|
|
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};
|