@ornexus/neocortex 4.60.68 → 4.60.70
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 +1194 -1194
- package/install.ps1 +1 -1
- package/install.sh +1 -1
- package/package.json +3 -3
- 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.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 +3 -290
- 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 +6 -0
- package/packages/client/dist/commands/invoke.js +142 -7140
- 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/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.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 -2536
- package/packages/client/dist/effects/invoke-effect-gateways.js +1 -62
- 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.js +4 -1234
- package/packages/client/dist/git/git-lifecycle-step-ids.js +1 -14
- package/packages/client/dist/git/git-lifecycle-store.js +9 -1938
- 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.js +1 -47
- package/packages/client/dist/invocation/invoke-input.js +1 -24
- package/packages/client/dist/license/index.js +1 -5
- 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/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 -344
- 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/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/headless/adapters.js +1 -49
- 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.js +2 -110
- package/packages/client/dist/runner/headless/epic-terminal-git-cli-adapter.js +8 -1236
- 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-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.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.js +1 -1677
- 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.js +1 -126
- package/packages/client/dist/yolo/invoke-envelope-capability.js +1 -62
- package/packages/client/dist/yolo/spec-envelope-collector.js +5 -185
- 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 -1723
- 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,55 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export const SUBAGENT_APPROVAL_MANAGED_DEFAULT = 'max';
|
|
3
|
-
export const SUBAGENT_APPROVAL_EVIDENCE = '[P201-EV-MAX-POLICY]';
|
|
4
|
-
const TARGETS = new Set(['claude-code', 'cursor', 'vscode', 'gemini', 'codex', 'opencode', 'github-copilot-cli', 'kimi', 'antigravity', 'openclaw', 'grok', 'runner', 'unknown']);
|
|
5
|
-
const normalizeTarget = (value) => TARGETS.has(value) ? value : 'unknown';
|
|
6
|
-
const MATRIX = Object.freeze({
|
|
7
|
-
'claude-code': { status: 'validated', scope: 'child', fallbackMode: 'none', fallbackReasonCode: null },
|
|
8
|
-
opencode: { status: 'unvalidated', scope: 'child', fallbackMode: 'shell-loop', fallbackReasonCode: 'platform-child-unvalidated' },
|
|
9
|
-
codex: { status: 'unvalidated', scope: 'inherited', fallbackMode: 'shell-loop', fallbackReasonCode: 'platform-child-unvalidated' },
|
|
10
|
-
gemini: { status: 'unvalidated', scope: 'inherited', fallbackMode: 'shell-loop', fallbackReasonCode: 'platform-child-unvalidated' },
|
|
11
|
-
vscode: { status: 'unvalidated', scope: 'session', fallbackMode: 'root-inline', fallbackReasonCode: 'platform-child-unvalidated' },
|
|
12
|
-
'github-copilot-cli': { status: 'unvalidated', scope: 'session', fallbackMode: 'root-inline', fallbackReasonCode: 'platform-child-unvalidated' },
|
|
13
|
-
kimi: { status: 'unvalidated', scope: 'inherited', fallbackMode: 'shell-loop', fallbackReasonCode: 'platform-child-unvalidated' },
|
|
14
|
-
cursor: { status: 'unvalidated', scope: 'session', fallbackMode: 'root-inline', fallbackReasonCode: 'platform-child-unvalidated' },
|
|
15
|
-
antigravity: { status: 'unvalidated', scope: 'inherited', fallbackMode: 'shell-loop', fallbackReasonCode: 'platform-child-unvalidated' },
|
|
16
|
-
grok: { status: 'unvalidated', scope: 'inherited', fallbackMode: 'shell-loop', fallbackReasonCode: 'platform-child-unvalidated' },
|
|
17
|
-
openclaw: { status: 'unsupported', scope: 'none', fallbackMode: 'root-inline', fallbackReasonCode: 'platform-child-unsupported' },
|
|
18
|
-
runner: { status: 'unsupported', scope: 'none', fallbackMode: 'shell-loop', fallbackReasonCode: 'platform-child-unsupported' },
|
|
19
|
-
unknown: { status: 'unsupported', scope: 'none', fallbackMode: 'shell-loop', fallbackReasonCode: 'platform-target-unknown' },
|
|
20
|
-
});
|
|
21
|
-
const MODE_RANK = Object.freeze({ disabled: 0, standard: 1, max: 2 });
|
|
22
|
-
export function isSubagentApprovalMode(value) {
|
|
23
|
-
return value === 'max' || value === 'standard' || value === 'disabled';
|
|
24
|
-
}
|
|
25
|
-
export function deriveSubagentHostApprovalPolicy(platformTarget) {
|
|
26
|
-
const target = normalizeTarget(platformTarget);
|
|
27
|
-
const capability = MATRIX[target];
|
|
28
|
-
if (target === 'unknown')
|
|
29
|
-
return Object.freeze({ platformTarget: target, maximumMode: 'disabled', scope: capability.scope, reductionReason: 'platform-target-unknown' });
|
|
30
|
-
if (capability.status === 'unsupported')
|
|
31
|
-
return Object.freeze({ platformTarget: target, maximumMode: 'disabled', scope: capability.scope, reductionReason: 'host-capability-unsupported' });
|
|
32
|
-
if (capability.status === 'unvalidated')
|
|
33
|
-
return Object.freeze({ platformTarget: target, maximumMode: 'standard', scope: capability.scope, reductionReason: 'host-capability-unvalidated' });
|
|
34
|
-
return Object.freeze({ platformTarget: target, maximumMode: 'max', scope: capability.scope, reductionReason: 'host-policy-reduced' });
|
|
35
|
-
}
|
|
36
|
-
export function resolveSubagentApprovalPolicy(input = {}) {
|
|
37
|
-
const requestedMode = input.userOverride ?? SUBAGENT_APPROVAL_MANAGED_DEFAULT;
|
|
38
|
-
const hostPolicy = input.hostPolicy ?? deriveSubagentHostApprovalPolicy(input.platformTarget);
|
|
39
|
-
const capability = MATRIX[hostPolicy.platformTarget];
|
|
40
|
-
const reduced = MODE_RANK[requestedMode] > MODE_RANK[hostPolicy.maximumMode];
|
|
41
|
-
return Object.freeze({
|
|
42
|
-
schemaVersion: 1,
|
|
43
|
-
requestedMode,
|
|
44
|
-
effectiveMode: reduced ? hostPolicy.maximumMode : requestedMode,
|
|
45
|
-
source: input.userOverride ? 'user-override' : 'managed-default',
|
|
46
|
-
platformTarget: hostPolicy.platformTarget,
|
|
47
|
-
scope: hostPolicy.scope,
|
|
48
|
-
effectiveReason: reduced ? hostPolicy.reductionReason : 'requested-mode-honored',
|
|
49
|
-
fallbackMode: capability.fallbackMode,
|
|
50
|
-
fallbackReasonCode: capability.fallbackReasonCode,
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
export function createSubagentApprovalAuditEvent(event, resolution, occurredAt) {
|
|
54
|
-
return Object.freeze({ evidence: SUBAGENT_APPROVAL_EVIDENCE, event, occurredAt, ...resolution });
|
|
55
|
-
}
|
|
1
|
+
const u=1,p="max",s="[P201-EV-MAX-POLICY]",c=new Set(["claude-code","cursor","vscode","gemini","codex","opencode","github-copilot-cli","kimi","antigravity","openclaw","grok","runner","unknown"]),r=e=>c.has(e)?e:"unknown",d=Object.freeze({"claude-code":{status:"validated",scope:"child",fallbackMode:"none",fallbackReasonCode:null},opencode:{status:"unvalidated",scope:"child",fallbackMode:"shell-loop",fallbackReasonCode:"platform-child-unvalidated"},codex:{status:"unvalidated",scope:"inherited",fallbackMode:"shell-loop",fallbackReasonCode:"platform-child-unvalidated"},gemini:{status:"unvalidated",scope:"inherited",fallbackMode:"shell-loop",fallbackReasonCode:"platform-child-unvalidated"},vscode:{status:"unvalidated",scope:"session",fallbackMode:"root-inline",fallbackReasonCode:"platform-child-unvalidated"},"github-copilot-cli":{status:"unvalidated",scope:"session",fallbackMode:"root-inline",fallbackReasonCode:"platform-child-unvalidated"},kimi:{status:"unvalidated",scope:"inherited",fallbackMode:"shell-loop",fallbackReasonCode:"platform-child-unvalidated"},cursor:{status:"unvalidated",scope:"session",fallbackMode:"root-inline",fallbackReasonCode:"platform-child-unvalidated"},antigravity:{status:"unvalidated",scope:"inherited",fallbackMode:"shell-loop",fallbackReasonCode:"platform-child-unvalidated"},grok:{status:"unvalidated",scope:"inherited",fallbackMode:"shell-loop",fallbackReasonCode:"platform-child-unvalidated"},openclaw:{status:"unsupported",scope:"none",fallbackMode:"root-inline",fallbackReasonCode:"platform-child-unsupported"},runner:{status:"unsupported",scope:"none",fallbackMode:"shell-loop",fallbackReasonCode:"platform-child-unsupported"},unknown:{status:"unsupported",scope:"none",fallbackMode:"shell-loop",fallbackReasonCode:"platform-target-unknown"}}),n=Object.freeze({disabled:0,standard:1,max:2});function f(e){return e==="max"||e==="standard"||e==="disabled"}function i(e){const a=r(e),o=d[a];return a==="unknown"?Object.freeze({platformTarget:a,maximumMode:"disabled",scope:o.scope,reductionReason:"platform-target-unknown"}):o.status==="unsupported"?Object.freeze({platformTarget:a,maximumMode:"disabled",scope:o.scope,reductionReason:"host-capability-unsupported"}):o.status==="unvalidated"?Object.freeze({platformTarget:a,maximumMode:"standard",scope:o.scope,reductionReason:"host-capability-unvalidated"}):Object.freeze({platformTarget:a,maximumMode:"max",scope:o.scope,reductionReason:"host-policy-reduced"})}function b(e={}){const a=e.userOverride??"max",o=e.hostPolicy??i(e.platformTarget),t=d[o.platformTarget],l=n[a]>n[o.maximumMode];return Object.freeze({schemaVersion:1,requestedMode:a,effectiveMode:l?o.maximumMode:a,source:e.userOverride?"user-override":"managed-default",platformTarget:o.platformTarget,scope:o.scope,effectiveReason:l?o.reductionReason:"requested-mode-honored",fallbackMode:t.fallbackMode,fallbackReasonCode:t.fallbackReasonCode})}function m(e,a,o){return Object.freeze({evidence:s,event:e,occurredAt:o,...a})}export{s as SUBAGENT_APPROVAL_EVIDENCE,p as SUBAGENT_APPROVAL_MANAGED_DEFAULT,u as SUBAGENT_APPROVAL_POLICY_SCHEMA_VERSION,m as createSubagentApprovalAuditEvent,i as deriveSubagentHostApprovalPolicy,f as isSubagentApprovalMode,b as resolveSubagentApprovalPolicy};
|
|
@@ -1,279 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { createHash } from 'node:crypto';
|
|
4
|
-
import { existsSync, lstatSync, readFileSync } from 'node:fs';
|
|
5
|
-
import { join, resolve } from 'node:path';
|
|
6
|
-
import { assertGitLifecyclePrivateFile, ensureGitLifecyclePrivateChildDirectory, gitLifecycleRuntimeDirectory, readGitLifecycleRuntimeSync, } from '../git/git-lifecycle-store.js';
|
|
7
|
-
import { anchoredAtomicWriteFile } from '../git/secure-filesystem-boundary.js';
|
|
8
|
-
// Compare the server-owned setup stage through its pinned digest. The
|
|
9
|
-
// published client must not carry the workflow step identifier in plaintext.
|
|
10
|
-
const ROOT_ONLY_SETUP_STEP_SHA256 = '809db253d486b5d2620d318666219e8a2b4df05016174ba3c8a33fa17b65802a';
|
|
11
|
-
export function privateYoloRootOnlySetupReady(story) {
|
|
12
|
-
if (!story || typeof story !== 'object' || Array.isArray(story))
|
|
13
|
-
return false;
|
|
14
|
-
const record = story;
|
|
15
|
-
const steps = record.steps_completed;
|
|
16
|
-
if (record.status !== 'branch-ready' || typeof record.last_step !== 'string'
|
|
17
|
-
|| !Array.isArray(steps) || steps.length !== 1 || typeof steps[0] !== 'string'
|
|
18
|
-
|| record.last_step.length > 128 || steps[0].length > 128
|
|
19
|
-
|| record.last_step !== steps[0])
|
|
20
|
-
return false;
|
|
21
|
-
return createHash('sha256').update(record.last_step).digest('hex') === ROOT_ONLY_SETUP_STEP_SHA256;
|
|
22
|
-
}
|
|
23
|
-
/** Freeze the clean C01 claim; an agent must not enlarge its own C08 write set. */
|
|
24
|
-
function authorizedWriteSet(stateText, storyId) {
|
|
25
|
-
const state = JSON.parse(stateText);
|
|
26
|
-
if (!state || typeof state !== 'object' || Array.isArray(state)) {
|
|
27
|
-
throw new Error('private-execution-clean-baseline-write-set-invalid');
|
|
28
|
-
}
|
|
29
|
-
const stories = state.stories;
|
|
30
|
-
const story = stories && typeof stories === 'object' && !Array.isArray(stories)
|
|
31
|
-
? stories[storyId] : undefined;
|
|
32
|
-
const files = story && typeof story === 'object' && !Array.isArray(story)
|
|
33
|
-
? story.files_to_modify : undefined;
|
|
34
|
-
if (files !== undefined && (!Array.isArray(files) || files.length > 1024 || files.some((item) => typeof item !== 'string' || item.length === 0 || item.length > 1024
|
|
35
|
-
|| item.startsWith('/') || item.includes('\\') || item.includes('\0')
|
|
36
|
-
|| item.startsWith('.git/') || item.split('/').includes('..')))) {
|
|
37
|
-
throw new Error('private-execution-clean-baseline-write-set-invalid');
|
|
38
|
-
}
|
|
39
|
-
if (!story)
|
|
40
|
-
throw new Error('private-execution-clean-baseline-write-set-invalid');
|
|
41
|
-
return [...new Set(files ?? [])].sort();
|
|
42
|
-
}
|
|
43
|
-
function authorizedWriteSetSha256(stateText, storyId) {
|
|
44
|
-
const paths = authorizedWriteSet(stateText, storyId);
|
|
45
|
-
return createHash('sha256').update('private-yolo-authorized-write-set-v1\0')
|
|
46
|
-
.update(JSON.stringify(paths)).digest('hex');
|
|
47
|
-
}
|
|
48
|
-
function workingWriteSetSha256(root, storyId) {
|
|
49
|
-
const statePath = join(root, '.neocortex', 'state.json');
|
|
50
|
-
const stateFile = lstatSync(statePath);
|
|
51
|
-
if (!stateFile.isFile() || stateFile.isSymbolicLink()) {
|
|
52
|
-
throw new Error('private-execution-clean-baseline-write-set-invalid');
|
|
53
|
-
}
|
|
54
|
-
return authorizedWriteSetSha256(readFileSync(statePath, 'utf8'), storyId);
|
|
55
|
-
}
|
|
56
|
-
function committedWriteSetSha256(root, storyId) {
|
|
57
|
-
return authorizedWriteSetSha256(git(root, ['show', 'HEAD:.neocortex/state.json'], 16 * 1024 * 1024).toString('utf8'), storyId);
|
|
58
|
-
}
|
|
59
|
-
function git(root, args, maxBuffer = 1024 * 1024) {
|
|
60
|
-
const environment = { ...process.env };
|
|
61
|
-
for (const key of [
|
|
62
|
-
'GIT_DIR', 'GIT_WORK_TREE', 'GIT_INDEX_FILE', 'GIT_OBJECT_DIRECTORY',
|
|
63
|
-
'GIT_ALTERNATE_OBJECT_DIRECTORIES', 'GIT_COMMON_DIR', 'GIT_NAMESPACE', 'GIT_CEILING_DIRECTORIES',
|
|
64
|
-
])
|
|
65
|
-
delete environment[key];
|
|
66
|
-
return execFileSync('git', [...args], {
|
|
67
|
-
cwd: root, env: environment, stdio: ['ignore', 'pipe', 'pipe'],
|
|
68
|
-
timeout: 15_000, maxBuffer,
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
function physicalHead(root) {
|
|
72
|
-
return git(root, ['rev-parse', 'HEAD']).toString('utf8').trim();
|
|
73
|
-
}
|
|
74
|
-
function physicalBranch(root) {
|
|
75
|
-
return git(root, ['symbolic-ref', '--quiet', '--short', 'HEAD']).toString('utf8').trim();
|
|
76
|
-
}
|
|
77
|
-
function setupSessionId(root, epicId, storyId) {
|
|
78
|
-
const runtime = readGitLifecycleRuntimeSync(root, { required: true });
|
|
79
|
-
const rawLease = runtime.epics[epicId]?.branch_lease;
|
|
80
|
-
const lease = rawLease && typeof rawLease === 'object' && !Array.isArray(rawLease)
|
|
81
|
-
? rawLease : undefined;
|
|
82
|
-
const sessionId = lease?.ownerStoryId === storyId ? lease.sessionId : undefined;
|
|
83
|
-
if (typeof sessionId !== 'string' || !/^setup-[a-f0-9]{64}$/.test(sessionId)
|
|
84
|
-
|| sessionId !== lease?.idempotencyKey || typeof lease?.expiresAt !== 'string'
|
|
85
|
-
|| !Number.isFinite(Date.parse(lease.expiresAt)) || Date.parse(lease.expiresAt) <= Date.now()) {
|
|
86
|
-
throw new Error('private-execution-clean-baseline-lease-invalid');
|
|
87
|
-
}
|
|
88
|
-
return sessionId;
|
|
89
|
-
}
|
|
90
|
-
async function location(root, storyId) {
|
|
91
|
-
const runtimeDirectory = await gitLifecycleRuntimeDirectory(root);
|
|
92
|
-
const parent = await ensureGitLifecyclePrivateChildDirectory(runtimeDirectory, 'private-execution');
|
|
93
|
-
const name = `baseline-${createHash('sha256').update(storyId).digest('hex')}.json`;
|
|
94
|
-
return { parent, name, path: join(parent, name) };
|
|
95
|
-
}
|
|
96
|
-
async function sessionGraphContinuationMatches(root, storyId, baseline, graphRevision) {
|
|
97
|
-
try {
|
|
98
|
-
const runtimeDirectory = await gitLifecycleRuntimeDirectory(root);
|
|
99
|
-
const parent = await ensureGitLifecyclePrivateChildDirectory(runtimeDirectory, 'private-execution');
|
|
100
|
-
const name = `session-${createHash('sha256').update(storyId).digest('hex')}.json`;
|
|
101
|
-
const path = join(parent, name);
|
|
102
|
-
if (!existsSync(path))
|
|
103
|
-
return false;
|
|
104
|
-
await assertGitLifecyclePrivateFile(path, parent);
|
|
105
|
-
const value = JSON.parse(readFileSync(path, 'utf8'));
|
|
106
|
-
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
107
|
-
return false;
|
|
108
|
-
const session = value;
|
|
109
|
-
const workspace = session.workspace && typeof session.workspace === 'object'
|
|
110
|
-
&& !Array.isArray(session.workspace) ? session.workspace : undefined;
|
|
111
|
-
const sequence = Number(session.sequence);
|
|
112
|
-
const runtimeStory = readGitLifecycleRuntimeSync(root, { required: true }).stories[storyId];
|
|
113
|
-
const rootOnlySetupTransition = sequence === 0
|
|
114
|
-
&& session.lastPatchSha256 === null
|
|
115
|
-
&& session.snapshotSha === workspace?.baseSha
|
|
116
|
-
&& Array.isArray(session.graphHistory) && session.graphHistory.length === 2
|
|
117
|
-
&& privateYoloRootOnlySetupReady(runtimeStory);
|
|
118
|
-
return session.schemaVersion === 1 && session.kind === 'private-yolo-isolated-session'
|
|
119
|
-
&& session.storyId === storyId && session.initialGraphRevision === baseline.graphRevision
|
|
120
|
-
&& session.graphRevision === graphRevision && session.setupSessionId === baseline.setupSessionId
|
|
121
|
-
&& Array.isArray(session.graphHistory) && session.graphHistory.length > 1
|
|
122
|
-
&& session.graphHistory.length <= 65
|
|
123
|
-
&& session.graphHistory[0] === baseline.graphRevision
|
|
124
|
-
&& session.graphHistory[session.graphHistory.length - 1] === graphRevision
|
|
125
|
-
&& new Set(session.graphHistory).size === session.graphHistory.length
|
|
126
|
-
&& Number.isSafeInteger(session.sequence) && (sequence > 0 || rootOnlySetupTransition)
|
|
127
|
-
&& typeof session.snapshotSha === 'string' && /^[a-f0-9]{40,64}$/.test(session.snapshotSha)
|
|
128
|
-
&& workspace?.sourceRoot === root && workspace.baseSha === baseline.headSha
|
|
129
|
-
&& workspace.executionBranch === baseline.executionBranch;
|
|
130
|
-
}
|
|
131
|
-
catch {
|
|
132
|
-
return false;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
/** Call immediately before root C01 setup; a dirty or ambiguous checkout fails closed. */
|
|
136
|
-
function checkoutCleanAfterInvoke(root, entryCleanHead) {
|
|
137
|
-
const status = git(root, ['status', '--porcelain=v1', '-z', '--untracked-files=all']);
|
|
138
|
-
if (status.byteLength === 0)
|
|
139
|
-
return true;
|
|
140
|
-
// The invoke continuity recorder may update its tracked SQLite file before
|
|
141
|
-
// C01 setup. Admit only that exact worktree-only change after a clean entry
|
|
142
|
-
// observation bound to the same physical HEAD.
|
|
143
|
-
return entryCleanHead !== undefined && physicalHead(root) === entryCleanHead
|
|
144
|
-
&& status.toString('utf8') === ' M .neocortex/continuity/continuity.sqlite\0'
|
|
145
|
-
&& lstatSync(join(root, '.neocortex/continuity/continuity.sqlite')).isFile();
|
|
146
|
-
}
|
|
147
|
-
export function capturePrivateYoloCleanHead(projectRoot, entryCleanHead) {
|
|
148
|
-
const root = resolve(projectRoot);
|
|
149
|
-
try {
|
|
150
|
-
const before = physicalHead(root);
|
|
151
|
-
if (!checkoutCleanAfterInvoke(root, entryCleanHead)) {
|
|
152
|
-
throw new Error('private-execution-checkout-dirty');
|
|
153
|
-
}
|
|
154
|
-
if (physicalHead(root) !== before)
|
|
155
|
-
throw new Error('private-execution-checkout-raced');
|
|
156
|
-
return before;
|
|
157
|
-
}
|
|
158
|
-
catch (error) {
|
|
159
|
-
if (error instanceof Error && /^private-execution-[a-z-]+$/.test(error.message))
|
|
160
|
-
throw error;
|
|
161
|
-
throw new Error('private-execution-checkout-unverified');
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
/** Persist only after physical setup succeeded without changing the clean HEAD. */
|
|
165
|
-
export async function recordPrivateYoloCleanBaseline(projectRoot, setup, cleanHeadSha, entryCleanHead) {
|
|
166
|
-
const root = resolve(projectRoot);
|
|
167
|
-
if (!/^[a-f0-9]{40,64}$/.test(cleanHeadSha) || setup.kind !== 'direct-yolo-setup-receipt'
|
|
168
|
-
|| physicalHead(root) !== cleanHeadSha
|
|
169
|
-
|| physicalBranch(root) !== setup.executionBranch
|
|
170
|
-
|| !checkoutCleanAfterInvoke(root, entryCleanHead)) {
|
|
171
|
-
throw new Error('private-execution-clean-baseline-raced');
|
|
172
|
-
}
|
|
173
|
-
const runtime = readGitLifecycleRuntimeSync(root, { required: true });
|
|
174
|
-
const lease = runtime.epics[setup.epicId]?.branch_lease;
|
|
175
|
-
if (lease?.ownerStoryId !== setup.storyId || lease.setupHeadSha !== cleanHeadSha
|
|
176
|
-
|| git(root, ['merge-base', '--is-ancestor', setup.originHeadSha, cleanHeadSha]).byteLength !== 0) {
|
|
177
|
-
throw new Error('private-execution-clean-baseline-raced');
|
|
178
|
-
}
|
|
179
|
-
const committedWriteSet = committedWriteSetSha256(root, setup.storyId);
|
|
180
|
-
if (committedWriteSet !== workingWriteSetSha256(root, setup.storyId)
|
|
181
|
-
|| physicalHead(root) !== cleanHeadSha) {
|
|
182
|
-
throw new Error('private-execution-clean-baseline-raced');
|
|
183
|
-
}
|
|
184
|
-
const graphRevision = runtime.epics[setup.epicId]?.graph_revision;
|
|
185
|
-
if (typeof graphRevision !== 'string' || !/^[a-f0-9]{64}$/.test(graphRevision)) {
|
|
186
|
-
throw new Error('private-execution-clean-baseline-graph-invalid');
|
|
187
|
-
}
|
|
188
|
-
const record = Object.freeze({
|
|
189
|
-
schemaVersion: 3, kind: 'private-yolo-clean-baseline', storyId: setup.storyId,
|
|
190
|
-
epicId: setup.epicId, executionBranch: setup.executionBranch, headSha: cleanHeadSha,
|
|
191
|
-
setupSessionId: setupSessionId(root, setup.epicId, setup.storyId),
|
|
192
|
-
graphRevision,
|
|
193
|
-
authorizedWriteSetSha256: committedWriteSet,
|
|
194
|
-
});
|
|
195
|
-
const target = await location(root, setup.storyId);
|
|
196
|
-
await anchoredAtomicWriteFile(target.parent, target.name, `${JSON.stringify(record)}\n`);
|
|
197
|
-
}
|
|
198
|
-
/** A C08 commit can only consume the exact C01 session that began from clean Git. */
|
|
199
|
-
async function verifyPrivateYoloCleanBaselineInternal(projectRoot, storyId, executionBranch, expectedGraphRevision, transitionFromGraphRevision) {
|
|
200
|
-
const root = resolve(projectRoot);
|
|
201
|
-
try {
|
|
202
|
-
const target = await location(root, storyId);
|
|
203
|
-
await assertGitLifecyclePrivateFile(target.path, target.parent);
|
|
204
|
-
const parsed = JSON.parse(readFileSync(target.path, 'utf8'));
|
|
205
|
-
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
|
206
|
-
throw new Error('private-execution-clean-baseline-invalid');
|
|
207
|
-
}
|
|
208
|
-
const record = parsed;
|
|
209
|
-
const runtimeGraphRevision = readGitLifecycleRuntimeSync(root, { required: true }).epics[record.epicId]?.graph_revision;
|
|
210
|
-
const graphMatches = runtimeGraphRevision === record.graphRevision
|
|
211
|
-
|| transitionFromGraphRevision === record.graphRevision
|
|
212
|
-
&& runtimeGraphRevision === expectedGraphRevision
|
|
213
|
-
|| typeof runtimeGraphRevision === 'string'
|
|
214
|
-
&& await sessionGraphContinuationMatches(root, storyId, record, runtimeGraphRevision);
|
|
215
|
-
if (Object.keys(record).sort().join(',') !== [
|
|
216
|
-
'schemaVersion', 'kind', 'storyId', 'epicId', 'executionBranch', 'headSha', 'setupSessionId',
|
|
217
|
-
'graphRevision', 'authorizedWriteSetSha256',
|
|
218
|
-
].sort().join(',') || record.schemaVersion !== 3 || record.kind !== 'private-yolo-clean-baseline'
|
|
219
|
-
|| record.storyId !== storyId || record.executionBranch !== executionBranch
|
|
220
|
-
|| record.epicId !== storyId.split('.')[0] || typeof record.headSha !== 'string'
|
|
221
|
-
|| !/^[a-f0-9]{40,64}$/.test(record.headSha)
|
|
222
|
-
|| typeof record.authorizedWriteSetSha256 !== 'string'
|
|
223
|
-
|| !/^[a-f0-9]{64}$/.test(record.authorizedWriteSetSha256)
|
|
224
|
-
|| typeof record.graphRevision !== 'string' || !/^[a-f0-9]{64}$/.test(record.graphRevision)
|
|
225
|
-
|| expectedGraphRevision !== undefined && runtimeGraphRevision !== expectedGraphRevision
|
|
226
|
-
|| !graphMatches
|
|
227
|
-
|| record.authorizedWriteSetSha256 !== committedWriteSetSha256(root, storyId)
|
|
228
|
-
|| record.authorizedWriteSetSha256 !== workingWriteSetSha256(root, storyId)
|
|
229
|
-
|| record.setupSessionId !== setupSessionId(root, record.epicId, storyId)
|
|
230
|
-
|| physicalHead(root) !== record.headSha || physicalBranch(root) !== executionBranch) {
|
|
231
|
-
throw new Error('private-execution-clean-baseline-invalid');
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
catch {
|
|
235
|
-
throw new Error('private-execution-clean-baseline-unverified');
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
export async function verifyPrivateYoloCleanBaseline(projectRoot, storyId, executionBranch, expectedGraphRevision) {
|
|
239
|
-
return verifyPrivateYoloCleanBaselineInternal(projectRoot, storyId, executionBranch, expectedGraphRevision);
|
|
240
|
-
}
|
|
241
|
-
/** Read the exact C01 claim only after its physical session and graph still verify. */
|
|
242
|
-
export async function readPrivateYoloFrozenWriteSet(projectRoot, storyId, executionBranch, graphRevision) {
|
|
243
|
-
await verifyPrivateYoloCleanBaseline(projectRoot, storyId, executionBranch, graphRevision);
|
|
244
|
-
try {
|
|
245
|
-
const paths = authorizedWriteSet(git(resolve(projectRoot), ['show', 'HEAD:.neocortex/state.json'], 16 * 1024 * 1024).toString('utf8'), storyId);
|
|
246
|
-
if (paths.length === 0)
|
|
247
|
-
throw new Error('write-set-empty');
|
|
248
|
-
return Object.freeze([...paths]);
|
|
249
|
-
}
|
|
250
|
-
catch {
|
|
251
|
-
throw new Error('private-execution-clean-baseline-unverified');
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
/** Used only while the root reconciles a server-persisted successor graph. */
|
|
255
|
-
export async function readPrivateYoloFrozenWriteSetForTransition(projectRoot, storyId, executionBranch, initialGraphRevision, nextGraphRevision) {
|
|
256
|
-
await verifyPrivateYoloCleanBaselineInternal(projectRoot, storyId, executionBranch, nextGraphRevision, initialGraphRevision);
|
|
257
|
-
try {
|
|
258
|
-
const paths = authorizedWriteSet(git(resolve(projectRoot), ['show', 'HEAD:.neocortex/state.json'], 16 * 1024 * 1024).toString('utf8'), storyId);
|
|
259
|
-
if (paths.length === 0)
|
|
260
|
-
throw new Error('write-set-empty');
|
|
261
|
-
return Object.freeze([...paths]);
|
|
262
|
-
}
|
|
263
|
-
catch {
|
|
264
|
-
throw new Error('private-execution-clean-baseline-unverified');
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
/** A clone may advance step state, but cannot rewrite the frozen C01 path claim. */
|
|
268
|
-
export function verifyPrivateYoloCandidateWriteSet(stateText, storyId, frozenPaths) {
|
|
269
|
-
try {
|
|
270
|
-
const candidate = authorizedWriteSet(stateText, storyId);
|
|
271
|
-
if (candidate.length !== frozenPaths.length
|
|
272
|
-
|| candidate.some((path, index) => path !== frozenPaths[index])) {
|
|
273
|
-
throw new Error('write-set-drift');
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
catch {
|
|
277
|
-
throw new Error('private-execution-clean-baseline-write-set-unverified');
|
|
278
|
-
}
|
|
279
|
-
}
|
|
1
|
+
import{execFileSync as z}from"node:child_process";import{createHash as d}from"node:crypto";import{existsSync as C,lstatSync as x,readFileSync as v}from"node:fs";import{join as y,resolve as f}from"node:path";import{assertGitLifecyclePrivateFile as b,ensureGitLifecyclePrivateChildDirectory as E,gitLifecycleRuntimeDirectory as m,readGitLifecycleRuntimeSync as w}from"../git/git-lifecycle-store.js";import{anchoredAtomicWriteFile as H}from"../git/secure-filesystem-boundary.js";const N="809db253d486b5d2620d318666219e8a2b4df05016174ba3c8a33fa17b65802a";function G(r){if(!r||typeof r!="object"||Array.isArray(r))return!1;const e=r,t=e.steps_completed;return e.status!=="branch-ready"||typeof e.last_step!="string"||!Array.isArray(t)||t.length!==1||typeof t[0]!="string"||e.last_step.length>128||t[0].length>128||e.last_step!==t[0]?!1:d("sha256").update(e.last_step).digest("hex")===N}function g(r,e){const t=JSON.parse(r);if(!t||typeof t!="object"||Array.isArray(t))throw new Error("private-execution-clean-baseline-write-set-invalid");const i=t.stories,n=i&&typeof i=="object"&&!Array.isArray(i)?i[e]:void 0,a=n&&typeof n=="object"&&!Array.isArray(n)?n.files_to_modify:void 0;if(a!==void 0&&(!Array.isArray(a)||a.length>1024||a.some(c=>typeof c!="string"||c.length===0||c.length>1024||c.startsWith("/")||c.includes("\\")||c.includes("\0")||c.startsWith(".git/")||c.split("/").includes(".."))))throw new Error("private-execution-clean-baseline-write-set-invalid");if(!n)throw new Error("private-execution-clean-baseline-write-set-invalid");return[...new Set(a??[])].sort()}function I(r,e){const t=g(r,e);return d("sha256").update("private-yolo-authorized-write-set-v1\0").update(JSON.stringify(t)).digest("hex")}function A(r,e){const t=y(r,".neocortex","state.json"),i=x(t);if(!i.isFile()||i.isSymbolicLink())throw new Error("private-execution-clean-baseline-write-set-invalid");return I(v(t,"utf8"),e)}function _(r,e){return I(p(r,["show","HEAD:.neocortex/state.json"],16*1024*1024).toString("utf8"),e)}function p(r,e,t=1024*1024){const i={...process.env};for(const n of["GIT_DIR","GIT_WORK_TREE","GIT_INDEX_FILE","GIT_OBJECT_DIRECTORY","GIT_ALTERNATE_OBJECT_DIRECTORIES","GIT_COMMON_DIR","GIT_NAMESPACE","GIT_CEILING_DIRECTORIES"])delete i[n];return z("git",[...e],{cwd:r,env:i,stdio:["ignore","pipe","pipe"],timeout:15e3,maxBuffer:t})}function l(r){return p(r,["rev-parse","HEAD"]).toString("utf8").trim()}function R(r){return p(r,["symbolic-ref","--quiet","--short","HEAD"]).toString("utf8").trim()}function O(r,e,t){const n=w(r,{required:!0}).epics[e]?.branch_lease,a=n&&typeof n=="object"&&!Array.isArray(n)?n:void 0,c=a?.ownerStoryId===t?a.sessionId:void 0;if(typeof c!="string"||!/^setup-[a-f0-9]{64}$/.test(c)||c!==a?.idempotencyKey||typeof a?.expiresAt!="string"||!Number.isFinite(Date.parse(a.expiresAt))||Date.parse(a.expiresAt)<=Date.now())throw new Error("private-execution-clean-baseline-lease-invalid");return c}async function T(r,e){const t=await m(r),i=await E(t,"private-execution"),n=`baseline-${d("sha256").update(e).digest("hex")}.json`;return{parent:i,name:n,path:y(i,n)}}async function P(r,e,t,i){try{const n=await m(r),a=await E(n,"private-execution"),c=`session-${d("sha256").update(e).digest("hex")}.json`,h=y(a,c);if(!C(h))return!1;await b(h,a);const s=JSON.parse(v(h,"utf8"));if(!s||typeof s!="object"||Array.isArray(s))return!1;const o=s,u=o.workspace&&typeof o.workspace=="object"&&!Array.isArray(o.workspace)?o.workspace:void 0,S=Number(o.sequence),D=w(r,{required:!0}).stories[e],W=S===0&&o.lastPatchSha256===null&&o.snapshotSha===u?.baseSha&&Array.isArray(o.graphHistory)&&o.graphHistory.length===2&&G(D);return o.schemaVersion===1&&o.kind==="private-yolo-isolated-session"&&o.storyId===e&&o.initialGraphRevision===t.graphRevision&&o.graphRevision===i&&o.setupSessionId===t.setupSessionId&&Array.isArray(o.graphHistory)&&o.graphHistory.length>1&&o.graphHistory.length<=65&&o.graphHistory[0]===t.graphRevision&&o.graphHistory[o.graphHistory.length-1]===i&&new Set(o.graphHistory).size===o.graphHistory.length&&Number.isSafeInteger(o.sequence)&&(S>0||W)&&typeof o.snapshotSha=="string"&&/^[a-f0-9]{40,64}$/.test(o.snapshotSha)&&u?.sourceRoot===r&&u.baseSha===t.headSha&&u.executionBranch===t.executionBranch}catch{return!1}}function k(r,e){const t=p(r,["status","--porcelain=v1","-z","--untracked-files=all"]);return t.byteLength===0?!0:e!==void 0&&l(r)===e&&t.toString("utf8")===" M .neocortex/continuity/continuity.sqlite\0"&&x(y(r,".neocortex/continuity/continuity.sqlite")).isFile()}function M(r,e){const t=f(r);try{const i=l(t);if(!k(t,e))throw new Error("private-execution-checkout-dirty");if(l(t)!==i)throw new Error("private-execution-checkout-raced");return i}catch(i){throw i instanceof Error&&/^private-execution-[a-z-]+$/.test(i.message)?i:new Error("private-execution-checkout-unverified")}}async function V(r,e,t,i){const n=f(r);if(!/^[a-f0-9]{40,64}$/.test(t)||e.kind!=="direct-yolo-setup-receipt"||l(n)!==t||R(n)!==e.executionBranch||!k(n,i))throw new Error("private-execution-clean-baseline-raced");const a=w(n,{required:!0}),c=a.epics[e.epicId]?.branch_lease;if(c?.ownerStoryId!==e.storyId||c.setupHeadSha!==t||p(n,["merge-base","--is-ancestor",e.originHeadSha,t]).byteLength!==0)throw new Error("private-execution-clean-baseline-raced");const h=_(n,e.storyId);if(h!==A(n,e.storyId)||l(n)!==t)throw new Error("private-execution-clean-baseline-raced");const s=a.epics[e.epicId]?.graph_revision;if(typeof s!="string"||!/^[a-f0-9]{64}$/.test(s))throw new Error("private-execution-clean-baseline-graph-invalid");const o=Object.freeze({schemaVersion:3,kind:"private-yolo-clean-baseline",storyId:e.storyId,epicId:e.epicId,executionBranch:e.executionBranch,headSha:t,setupSessionId:O(n,e.epicId,e.storyId),graphRevision:s,authorizedWriteSetSha256:h}),u=await T(n,e.storyId);await H(u.parent,u.name,`${JSON.stringify(o)}
|
|
2
|
+
`)}async function j(r,e,t,i,n){const a=f(r);try{const c=await T(a,e);await b(c.path,c.parent);const h=JSON.parse(v(c.path,"utf8"));if(!h||typeof h!="object"||Array.isArray(h))throw new Error("private-execution-clean-baseline-invalid");const s=h,o=w(a,{required:!0}).epics[s.epicId]?.graph_revision,u=o===s.graphRevision||n===s.graphRevision&&o===i||typeof o=="string"&&await P(a,e,s,o);if(Object.keys(s).sort().join(",")!==["schemaVersion","kind","storyId","epicId","executionBranch","headSha","setupSessionId","graphRevision","authorizedWriteSetSha256"].sort().join(",")||s.schemaVersion!==3||s.kind!=="private-yolo-clean-baseline"||s.storyId!==e||s.executionBranch!==t||s.epicId!==e.split(".")[0]||typeof s.headSha!="string"||!/^[a-f0-9]{40,64}$/.test(s.headSha)||typeof s.authorizedWriteSetSha256!="string"||!/^[a-f0-9]{64}$/.test(s.authorizedWriteSetSha256)||typeof s.graphRevision!="string"||!/^[a-f0-9]{64}$/.test(s.graphRevision)||i!==void 0&&o!==i||!u||s.authorizedWriteSetSha256!==_(a,e)||s.authorizedWriteSetSha256!==A(a,e)||s.setupSessionId!==O(a,s.epicId,e)||l(a)!==s.headSha||R(a)!==t)throw new Error("private-execution-clean-baseline-invalid")}catch{throw new Error("private-execution-clean-baseline-unverified")}}async function B(r,e,t,i){return j(r,e,t,i)}async function K(r,e,t,i){await B(r,e,t,i);try{const n=g(p(f(r),["show","HEAD:.neocortex/state.json"],16777216).toString("utf8"),e);if(n.length===0)throw new Error("write-set-empty");return Object.freeze([...n])}catch{throw new Error("private-execution-clean-baseline-unverified")}}async function U(r,e,t,i,n){await j(r,e,t,n,i);try{const a=g(p(f(r),["show","HEAD:.neocortex/state.json"],16777216).toString("utf8"),e);if(a.length===0)throw new Error("write-set-empty");return Object.freeze([...a])}catch{throw new Error("private-execution-clean-baseline-unverified")}}function X(r,e,t){try{const i=g(r,e);if(i.length!==t.length||i.some((n,a)=>n!==t[a]))throw new Error("write-set-drift")}catch{throw new Error("private-execution-clean-baseline-write-set-unverified")}}export{M as capturePrivateYoloCleanHead,G as privateYoloRootOnlySetupReady,K as readPrivateYoloFrozenWriteSet,U as readPrivateYoloFrozenWriteSetForTransition,V as recordPrivateYoloCleanBaseline,X as verifyPrivateYoloCandidateWriteSet,B as verifyPrivateYoloCleanBaseline};
|