@ornexus/neocortex 4.65.1 → 4.66.0
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 +243 -77
- package/install.sh +221 -102
- package/package.json +2 -2
- package/packages/client/dist/adapters/platform-detector.js +1 -1
- package/packages/client/dist/agent/refresh-stubs.d.ts +50 -0
- package/packages/client/dist/agent/refresh-stubs.js +2 -2
- package/packages/client/dist/cli.js +5 -4
- package/packages/client/dist/commands/invoke.d.ts +35 -5
- package/packages/client/dist/commands/invoke.js +86 -84
- package/packages/client/dist/commands/planning-qa.d.ts +7 -0
- package/packages/client/dist/commands/planning-qa.js +1 -0
- package/packages/client/dist/commands/refactor-control.js +3 -3
- package/packages/client/dist/commands/story-checkpoint.d.ts +1 -1
- package/packages/client/dist/commands/story-checkpoint.js +1 -1
- package/packages/client/dist/git/direct-yolo-checkpoint.d.ts +13 -1
- package/packages/client/dist/git/direct-yolo-checkpoint.js +3 -3
- package/packages/client/dist/git/git-lifecycle-store.d.ts +14 -0
- package/packages/client/dist/git/git-lifecycle-store.js +8 -8
- package/packages/client/dist/git/governance-runtime-store.d.ts +172 -0
- package/packages/client/dist/git/governance-runtime-store.js +3 -0
- package/packages/client/dist/git/story-worktree-integration.js +3 -3
- package/packages/client/dist/memory/shared-project-memory-types.d.ts +39 -2
- package/packages/client/dist/memory/shared-project-memory-types.js +2 -2
- package/packages/client/dist/policy/subagent-approval-policy.js +1 -1
- package/packages/client/dist/private-execution/codex-executor.d.ts +8 -1
- package/packages/client/dist/private-execution/delivery.d.ts +17 -11
- package/packages/client/dist/private-execution/delivery.js +8 -6
- package/packages/client/dist/private-execution/diagnosis-root-review.d.ts +89 -0
- package/packages/client/dist/private-execution/diagnosis-root-review.js +2 -2
- package/packages/client/dist/private-execution/frozen-handoff.js +3 -3
- package/packages/client/dist/private-execution/planning-diagnosis-checkpoint.d.ts +75 -1
- package/packages/client/dist/private-execution/planning-diagnosis-checkpoint.js +5 -5
- package/packages/client/dist/private-execution/planning-generation-checkpoint.d.ts +9 -1
- package/packages/client/dist/private-execution/planning-generation-checkpoint.js +4 -4
- package/packages/client/dist/private-execution/planning-research-checkpoint.d.ts +9 -1
- package/packages/client/dist/private-execution/planning-research-checkpoint.js +4 -4
- package/packages/client/dist/private-execution/root-memory-request.d.ts +4 -1
- package/packages/client/dist/private-execution/root-memory-request.js +1 -1
- package/packages/client/dist/runner/epic-background-dispatcher.d.ts +3 -1
- package/packages/client/dist/runner/epic-background-dispatcher.js +1 -1
- package/packages/client/dist/runner/headless/claude-code-adapter.js +1 -1
- package/packages/client/dist/runner/headless/managed-profile.d.ts +20 -0
- package/packages/client/dist/runner/headless/managed-profile.js +1 -1
- package/packages/client/dist/runner/headless/opencode-adapter.js +2 -2
- package/packages/client/dist/runner/headless/run-yoloop.d.ts +40 -0
- package/packages/client/dist/runner/headless/run-yoloop.js +2 -2
- package/packages/client/dist/runner/headless/types.d.ts +20 -0
- package/packages/client/dist/runner/headless/types.js +2 -2
- package/packages/client/dist/state/project-state-snapshot.js +1 -1
- package/packages/client/dist/yoloop/target-normalization.js +1 -1
- package/packages/shared/dist/compatibility/index.js +68 -0
- package/packages/shared/dist/planning/diagnosis-state.js +105 -1
- package/packages/shared/dist/project-memory-targets.js +36 -5
- package/targets-stubs/antigravity/README.md +1 -1
- package/targets-stubs/antigravity/gemini.md +1 -1
- package/targets-stubs/antigravity/install-antigravity.sh +1 -1
- package/targets-stubs/antigravity/mcp-config.json +0 -3
- package/targets-stubs/antigravity/neocortex.md +25 -13
- package/targets-stubs/antigravity/skill/SKILL.md +4 -4
- package/targets-stubs/claude-code/.mcp.json +0 -4
- package/targets-stubs/claude-code/neocortex-root.agent.yaml +2 -4
- package/targets-stubs/claude-code/neocortex-root.md +33 -43
- package/targets-stubs/claude-code/neocortex-sentinel.md +261 -0
- package/targets-stubs/claude-code/neocortex.agent.yaml +1 -3
- package/targets-stubs/claude-code/neocortex.md +61 -84
- package/targets-stubs/codex/AGENTS.md +19 -18
- package/targets-stubs/codex/README.md +1 -1
- package/targets-stubs/codex/config-mcp.toml +0 -3
- package/targets-stubs/codex/neocortex-sentinel.toml +87 -0
- package/targets-stubs/codex/neocortex.toml +23 -44
- package/targets-stubs/cursor/README.md +1 -1
- package/targets-stubs/cursor/agent.md +26 -15
- package/targets-stubs/cursor/mcp.json +0 -3
- package/targets-stubs/deepseek-harness/SKILL.md +11 -8
- package/targets-stubs/gemini-cli/README.md +1 -1
- package/targets-stubs/gemini-cli/agent.md +25 -12
- package/targets-stubs/gemini-cli/agents/neocortex-sentinel.md +75 -0
- package/targets-stubs/gemini-cli/agents/neocortex.md +280 -49
- package/targets-stubs/gemini-cli/settings-mcp.json +0 -3
- package/targets-stubs/grok/SKILL.md +12 -0
- package/targets-stubs/grok/agents/neocortex.md +64 -0
- package/targets-stubs/grok/config-mcp.toml +0 -3
- package/targets-stubs/grok/install-grok.sh +14 -1
- package/targets-stubs/kimi/mcp.json +0 -6
- package/targets-stubs/kimi/neocortex.md +21 -8
- package/targets-stubs/lib/managed-config-merge.js +281 -6
- package/targets-stubs/lib/managed-profile.sh +12 -1
- package/targets-stubs/lib/mcp-merge.js +110 -5
- package/targets-stubs/openclaw/SKILL.md +33 -4
- package/targets-stubs/opencode/neocortex-root.md +41 -41
- package/targets-stubs/opencode/neocortex-sentinel.md +115 -0
- package/targets-stubs/opencode/neocortex.md +292 -67
- package/targets-stubs/opencode/opencode-mcp.json +0 -7
- package/targets-stubs/vscode/README.md +1 -1
- package/targets-stubs/vscode/mcp.json +0 -4
- package/targets-stubs/vscode/neocortex.agent.md +29 -18
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* P228-CON-QA-EVIDENCE: the root records host-neutral QA for an admitted planning artifact.
|
|
3
|
+
* The command is read-only; it prints a `qaEvidenceId` bound to the admission patch and
|
|
4
|
+
* artifact digests, which the matching `planning-<phase> seal` then requires.
|
|
5
|
+
*/
|
|
6
|
+
export declare function planningQaCliHandler(args: readonly string[]): Promise<number>;
|
|
7
|
+
export declare function planningQaCliHandlerWithIO(args: readonly string[], input: AsyncIterable<string | Buffer>, output: Pick<Console, 'log' | 'error'>): Promise<number>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{recordPlanningDiagnosisQaEvidence as s}from"../private-execution/planning-diagnosis-checkpoint.js";import{recordPlanningResearchQaEvidence as c}from"../private-execution/planning-research-checkpoint.js";import{recordPlanningGenerationQaEvidence as l}from"../private-execution/planning-generation-checkpoint.js";const d=64*1024,f=["diagnosis","research","generation"],p="usage: planning-qa record --phase <diagnosis|research|generation> [--project-root <path>] < review.json";async function u(n){const o=[];let e=0;for await(const r of n){const i=Buffer.isBuffer(r)?r:Buffer.from(r);if(e+=i.length,e>d)throw new Error("planning-qa-review-too-large");o.push(i)}if(e===0)throw new Error("planning-qa-review-missing");try{return JSON.parse(Buffer.concat(o).toString("utf8"))}catch{throw new Error("planning-qa-review-invalid")}}function g(n){if(n[0]!=="record")return null;let o,e;for(let r=1;r<n.length;r+=2){const i=n[r],t=n[r+1];if(t===void 0)return null;if(i==="--phase"&&o===void 0&&f.includes(t))o=t;else if(i==="--project-root"&&e===void 0)e=t;else return null}return o?{phase:o,...e===void 0?{}:{projectRoot:e}}:null}function h(n,o){if(/^planning-qa-[a-z-]+$/.test(n))return n;const e=`planning-${o}-`;return n.startsWith(e)&&/^[a-z-]+$/.test(n.slice(e.length))?`planning-qa-${n.slice(e.length)}`:/^planning-(research|generation)-predecessor-invalid$/.test(n)?"planning-qa-predecessor-invalid":"planning-qa-record-failed"}async function S(n){return v(n,process.stdin,console)}async function v(n,o,e){const r=g(n);if(!r)return e.error(p),1;try{const i=await u(o),t=r.projectRoot??process.cwd(),a=r.phase==="diagnosis"?s(t,i):r.phase==="research"?c(t,i):l(t,i);return e.log(JSON.stringify({ok:!0,phase:r.phase,epicId:a.epicId,qaEvidenceId:a.qaEvidenceId,publicSafe:!0})),0}catch(i){const t=i instanceof Error?i.message:"";return e.error(JSON.stringify({ok:!1,reasonCode:h(t,r.phase),publicSafe:!0})),1}}export{S as planningQaCliHandler,v as planningQaCliHandlerWithIO};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{lstatSync as
|
|
2
|
-
`),0}catch(n){const t=n instanceof Error?n.message.replace(/^qa-/,"refactor-"):"",c=
|
|
3
|
-
`),1}}export{
|
|
1
|
+
import{lstatSync as R,readFileSync as b,realpathSync as k}from"node:fs";import{join as y,resolve as g}from"node:path";import{signNxInvokeRequest as q}from"../../../shared/dist/nx-invoke-signature.js";import{createCompatibilityOffer as N}from"../../../shared/dist/compatibility/index.js";import{COMMAND_REGISTRY_VERSION as w,COMMAND_REGISTRY_CHECKSUM as E}from"../generated/command-registry.generated.js";import{CLIENT_VERSION as O}from"../version.js";import{loadSecureConfig as _}from"../config/secure-config.js";import{neocortexProfileDirectory as A}from"../config/profile-directory.js";import{EncryptedCache as T}from"../cache/encrypted-cache.js";import{LicenseClient as I}from"../license/license-client.js";import{detectPlatform as L}from"../adapters/platform-detector.js";const S=new Set(["refactor-control-input-invalid","refactor-control-auth-required","refactor-control-tier-required","refactor-control-read-only","refactor-control-signature-required","refactor-control-client-unsupported","refactor-control-registry-mismatch","refactor-control-executor-unavailable"]),j=new Set(["arguments-invalid","authorization-required","project-unbound","auth-required","response-invalid","request-refused","outcome-unknown"].map(e=>`refactor-root-control-${e}`));async function $(e){const o=e.body?.getReader();if(!o)throw new Error("refactor-root-control-response-invalid");let n=!1;try{const t=[];let c=0;for(;;){const a=await o.read();if(a.done){n=!0;break}if(c+=a.value.byteLength,c>16384)throw new Error("refactor-root-control-response-invalid");t.push(Buffer.from(a.value))}return JSON.parse(new TextDecoder("utf-8",{fatal:!0}).decode(Buffer.concat(t,c)))}catch{throw new Error("refactor-root-control-response-invalid")}finally{n||await o.cancel().catch(()=>{}),o.releaseLock()}}async function v(e,o,n=fetch){if(e!=="refactor"&&e!=="qa")throw new Error("refactor-root-control-arguments-invalid");const t=`/api/v1/invoke/${e}/control`,c=q({method:"POST",target:t,body:Buffer.from(JSON.stringify({projectId:o.projectId,storyId:o.storyId,platformTarget:o.platformTarget,registryVersion:w,registryChecksum:E,compatibility:N({clientVersion:O,registryVersion:w,registryChecksum:E})})),bearerToken:o.token,clientVersion:O}),a=await n(`${o.serverUrl.replace(/\/+$/,"")}${t}`,{method:"POST",redirect:"error",signal:AbortSignal.timeout(2e5),headers:{...c.headers,Authorization:`Bearer ${o.token}`},body:c.body}),r=await $(a);if(!a.ok)throw new Error(typeof r?.error_code=="string"&&S.has(r.error_code.replace(/^qa-/,"refactor-"))&&r.error_code.startsWith(`${e}-`)?r.error_code:"refactor-root-control-request-refused");const d=["schemaVersion","kind","status","completedStages","authority","qaAccepted","gitAuthority","billingAuthority","publicSafe"];if(!r||typeof r!="object"||Array.isArray(r)||Object.keys(r).some(s=>!d.includes(s))||r.schemaVersion!==1||r.kind!==`root-${e}-control`||typeof r.status!="string"||!["advanced","waiting","blocked","candidate-ready",...e==="qa"?["debt"]:[]].includes(r.status)||r.authority!==(e==="qa"?"LOCAL_ROOT_QA_CANDIDATE_ONLY":"LOCAL_ROOT_CANDIDATE_ONLY")||r.qaAccepted!==!1||r.gitAuthority!=="NONE"||r.billingAuthority!=="NONE"||r.publicSafe!==!0||r.completedStages!==void 0&&(typeof r.completedStages!="number"||!Number.isInteger(r.completedStages)||r.completedStages<0||r.completedStages>(e==="qa"?3:7)))throw new Error("refactor-root-control-response-invalid");return r}async function F(e,o=fetch){return v("refactor",e,o)}async function G(e,o="refactor"){try{let n="",t="",c=!1,a="json";const r=[...e];if(r.shift()!=="control")throw new Error("refactor-root-control-arguments-invalid");for(let i=0;i<r.length;i++){const f=r[i];if(f==="--authorize-root-control")c=!0;else if(f==="--project-root")n=r[++i]??"";else if(f==="--story")t=r[++i]??"";else if(f==="--format")a=r[++i]??"";else throw new Error("refactor-root-control-arguments-invalid")}if(!c||!n||a!=="json"||!/^P[0-9]{1,12}(?:\.[0-9]{1,12}){1,3}$/.test(t))throw new Error("refactor-root-control-authorization-required");const d=L({cwd:g(n),env:process.env}).targetId,s=y(g(n),".neocortex","state.json"),u=R(s);if(!u.isFile()||u.isSymbolicLink()||k(s)!==s||u.size>16*1024*1024)throw new Error("refactor-root-control-project-unbound");const p=JSON.parse(b(s,"utf8")).config?.project_id;if(typeof p!="string"||!/^[A-Za-z0-9][A-Za-z0-9_-]{15,127}$/.test(p))throw new Error("refactor-root-control-project-unbound");const l=_({strictReadOnly:!0});if(!l?.licenseKey)throw new Error("refactor-root-control-auth-required");const h=process.env.NEOCORTEX_SERVER_URL??l.serverUrl;if(!h)throw new Error("refactor-root-control-auth-required");const m=await new I({serverUrl:h,licenseKey:l.licenseKey,cacheProvider:new T({cacheDir:y(A(),"cache"),passphrase:l.licenseKey})}).getToken();if(!m)throw new Error("refactor-root-control-auth-required");const C=await v(o,{serverUrl:h,token:m,projectId:p,storyId:t,platformTarget:d});return process.stdout.write(`${JSON.stringify({ok:!0,control:C})}
|
|
2
|
+
`),0}catch(n){const t=n instanceof Error?n.message.replace(/^qa-/,"refactor-"):"",c=j.has(t)||S.has(t)?t:"refactor-root-control-outcome-unknown";return process.stdout.write(`${JSON.stringify({ok:!1,reasonCode:o==="qa"?c.replace(/^refactor-/,"qa-"):c})}
|
|
3
|
+
`),1}}export{G as refactorControlCliHandler,F as requestRefactorControl,v as requestRootControl};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
type StoryCheckpointAction = 'setup' | 'accept-setup' | 'handoff' | 'begin' | 'finalize' | 'recover' | 'retry-c01' | 'integrate-worktree' | 'extend-write-set';
|
|
1
|
+
type StoryCheckpointAction = 'setup' | 'accept-setup' | 'handoff' | 'begin' | 'finalize' | 'recover' | 'retry-c01' | 'integrate-worktree' | 'extend-write-set' | 'capture-governance';
|
|
2
2
|
interface StoryCheckpointCliOptions {
|
|
3
3
|
readonly action: StoryCheckpointAction;
|
|
4
4
|
readonly storyId: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{readFile as S}from"node:fs/promises";import{resolve as $}from"node:path";import{acceptDirectYoloSetupCheckpoint as E,beginDirectYoloStoryCommit as I,finalizeDirectYoloStoryCheckpoint as
|
|
1
|
+
import{readFile as S}from"node:fs/promises";import{resolve as $}from"node:path";import{acceptDirectYoloSetupCheckpoint as E,beginDirectYoloStoryCommit as j,captureDirectYoloStoryGovernance as I,finalizeDirectYoloStoryCheckpoint as C,issueDirectYoloSetupLeaseHandoff as x,prepareDirectYoloSetup as H,recoverLegacyDirectYoloStoryCheckpoint as R}from"../git/direct-yolo-checkpoint.js";import{applyDirectYoloC01Retry as W,inspectDirectYoloC01Retry as D}from"../git/direct-yolo-c01-retry.js";import{integrateStoryWorktree as Y,integrateStoryWorktreeWave as z}from"../git/story-worktree-integration.js";import{extendStoryWriteSet as b}from"../git/story-write-set-extension.js";function q(h){const e=h[0];if(e!=="setup"&&e!=="accept-setup"&&e!=="handoff"&&e!=="begin"&&e!=="finalize"&&e!=="recover"&&e!=="retry-c01"&&e!=="integrate-worktree"&&e!=="extend-write-set"&&e!=="capture-governance")throw new Error("story-checkpoint-action-invalid");let c="",n=process.cwd(),o,r="origin",i=!1,v="plain",d,u,y,g=!1,l,m,w;for(let s=1;s<h.length;s++){const t=h[s],a=()=>h[++s]??"";if(t==="--story")c=a();else if(t.startsWith("--story="))c=t.slice(8);else if(t==="--paths")w=a();else if(t.startsWith("--paths="))w=t.slice(8);else if(t==="--stories")m=a();else if(t.startsWith("--stories="))m=t.slice(10);else if(t==="--project-root")n=a()||n;else if(t.startsWith("--project-root="))n=t.slice(15);else if(t==="--commit")o=a();else if(t.startsWith("--commit="))o=t.slice(9);else if(t==="--remote")r=a();else if(t.startsWith("--remote="))r=t.slice(9);else if(t==="--push"||t==="--require-remote")i=!0;else if(t==="--setup-handoff-session")d=a();else if(t.startsWith("--setup-handoff-session="))d=t.slice(24);else if(t==="--setup-handoff-token-file")u=a();else if(t.startsWith("--setup-handoff-token-file="))u=t.slice(27);else if(t==="--expected-head")y=a();else if(t.startsWith("--expected-head="))y=t.slice(16);else if(t==="--apply")g=!0;else if(t==="--lease")l=a();else if(t.startsWith("--lease="))l=t.slice(8);else if(t==="--format"){const p=a();if(p!=="json"&&p!=="plain")throw new Error("story-checkpoint-format-invalid");v=p}else if(t.startsWith("--format=")){const p=t.slice(9);if(p!=="json"&&p!=="plain")throw new Error("story-checkpoint-format-invalid");v=p}else throw new Error("story-checkpoint-argument-invalid")}let f;if(m!==void 0){if(e!=="integrate-worktree"||c||l!==void 0)throw new Error("story-checkpoint-option-invalid");if(f=m.split(",").map(s=>s.trim()),f.length===0||f.some(s=>!/^P[1-9][0-9]*(?:\.[0-9]+)+$/.test(s))||new Set(f).size!==f.length)throw new Error("story-checkpoint-stories-invalid")}if(!c&&!f)throw new Error("story-checkpoint-story-required");let k;if(e==="extend-write-set"){if(w===void 0)throw new Error("story-checkpoint-paths-required");if(o||i||r!=="origin"||l!==void 0)throw new Error("story-checkpoint-option-invalid");if(k=w.split(",").map(s=>s.trim()),k.length===0||k.some(s=>s.length===0))throw new Error("story-checkpoint-paths-invalid")}else if(w!==void 0)throw new Error("story-checkpoint-option-invalid");if(e==="recover"&&!o)throw new Error("story-checkpoint-commit-required");if(e==="recover"&&!i)throw new Error("story-checkpoint-remote-proof-required");if(e==="finalize"&&!i)throw new Error("story-checkpoint-push-required");if(e==="integrate-worktree"&&(!i||o))throw new Error(i?"story-checkpoint-option-invalid":"story-checkpoint-push-required");if(l!==void 0&&(e!=="integrate-worktree"||!/^swt-[a-f0-9]{24}$/.test(l)))throw new Error("story-checkpoint-option-invalid");if(e==="begin"&&(o||i||r!=="origin"))throw new Error("story-checkpoint-option-invalid");if((e==="setup"||e==="accept-setup"||e==="handoff"||e==="capture-governance")&&(o||i||r!=="origin"||l!==void 0))throw new Error("story-checkpoint-option-invalid");if(e==="finalize"&&o)throw new Error("story-checkpoint-option-invalid");if(d===void 0!=(u===void 0))throw new Error("story-checkpoint-setup-handoff-incomplete");if(e!=="begin"&&(d||u))throw new Error("story-checkpoint-option-invalid");if(e!=="retry-c01"&&(y||g))throw new Error("story-checkpoint-option-invalid");if(e==="retry-c01"&&(o||i||r!=="origin"||g&&!/^[a-f0-9]{40,64}$/.test(y??"")))throw new Error("story-checkpoint-option-invalid");return{action:e,storyId:c,projectRoot:$(n),commitSha:o,remote:r,push:i,format:v,...y?{expectedHeadSha:y}:{},...g?{apply:g}:{},...l?{leaseId:l}:{},...f?{storyIds:f}:{},...k?{paths:k}:{},...d?{setupHandoffSessionId:d}:{},...u?{setupHandoffTokenFile:$(u)}:{}}}async function T(h){let e;try{e=q(h)}catch(o){return console.error(o instanceof Error?o.message:"story-checkpoint-arguments-invalid"),1}if(e.action==="retry-c01")try{const o=e.apply?await W(e.projectRoot,e.storyId,e.expectedHeadSha):await D(e.projectRoot,e.storyId);return console.log(e.format==="json"?JSON.stringify(o,null,2):`story-checkpoint retry-c01: ${e.apply?"committed":"eligible"}`),0}catch(o){return console.error(o instanceof Error?o.message:"direct-yolo-retry-unverified"),1}let c;if(e.setupHandoffSessionId&&e.setupHandoffTokenFile)try{c={sessionId:e.setupHandoffSessionId,token:(await S(e.setupHandoffTokenFile,"utf8")).trim()}}catch{return console.error("story-checkpoint-setup-handoff-read-failed"),1}if(e.action==="extend-write-set"){const o=await b({projectRoot:e.projectRoot,storyId:e.storyId,paths:e.paths??[]});return e.format==="json"?console.log(JSON.stringify({action:e.action,...o},null,2)):o.ok?(console.log(`story-checkpoint ${e.action}: ${o.value.outcome}`),console.log(`paths=${o.value.extensionPathCount} authorized=${o.value.authorizedPathCount}`),console.log(`claim=${o.value.claimRevision}`)):console.error(`story-checkpoint ${e.action}: ${o.reasonCode}`),o.ok?0:1}if(e.action==="integrate-worktree"&&e.storyIds){const o=await z({projectRoot:e.projectRoot,storyIds:e.storyIds,push:e.push,remote:e.remote});if(e.format==="json")console.log(JSON.stringify({action:e.action,mode:"wave",...o},null,2));else if(o.ok){const r=o.value;console.log(`story-checkpoint ${e.action}: wave ${r.outcome}`),console.log(`integrated=${r.integratedStoryIds.length} gate-runs=${r.gateRuns}/${r.gateRunCap}`),console.log(`head=${r.epicHeadAfterSha}`);for(const i of r.stories)console.log(`story=${i.storyId} ${i.outcome}${i.reasonCode?` ${i.reasonCode}`:""}`)}else console.error(`story-checkpoint ${e.action}: ${o.reasonCode}`);return o.ok&&o.value.outcome!=="gate-failed"?0:1}if(e.action==="integrate-worktree"){const o=await Y({projectRoot:e.projectRoot,storyId:e.storyId,push:e.push,remote:e.remote,...e.leaseId?{leaseId:e.leaseId}:{}});if(e.format==="json")console.log(JSON.stringify({action:e.action,...o},null,2));else if(o.ok){console.log(`story-checkpoint ${e.action}: ${o.value.outcome}`),o.value.checkpointHeadSha&&console.log(`head=${o.value.checkpointHeadSha}`);for(const r of o.value.conflictPaths??[])console.log(`conflict=${r}`)}else console.error(`story-checkpoint ${e.action}: ${o.reasonCode}`);return o.ok?0:1}if(e.action==="capture-governance"){const o=await I(e);return e.format==="json"?console.log(JSON.stringify({action:e.action,...o},null,2)):o.ok?(console.log(`story-checkpoint ${e.action}: ok`),console.log(`governance=${o.value.governanceDigest} revision=${o.value.revision}`)):console.error(`story-checkpoint ${e.action}: ${o.reasonCode}`),o.ok?0:1}const n=e.action==="setup"?await H(e):e.action==="accept-setup"?await E(e):e.action==="handoff"?await x(e):e.action==="begin"?await j({...e,...c?{setupLeaseHandoff:c}:{}}):e.action==="finalize"?await C(e):await R({...e,commitSha:e.commitSha});if(e.format==="json")console.log(JSON.stringify({action:e.action,...n},null,2));else if(n.ok)if(console.log(`story-checkpoint ${e.action}: ok`),e.action==="begin"&&"trailers"in n.value)for(const o of n.value.trailers)console.log(o);else"headSha"in n.value&&console.log(`head=${n.value.headSha}`);else console.error(`story-checkpoint ${e.action}: ${n.reasonCode}`);return n.ok?0:1}export{q as parseStoryCheckpointArgs,T as storyCheckpointCliHandler};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { RootProjectMemoryEffect } from '@neocortex/shared';
|
|
2
2
|
import { type StoryCommitCheckpoint } from '../../../shared/dist/yoloop/branch-unit.js';
|
|
3
3
|
import { type GitLifecyclePhysicalIntegrationLockOwner, type P205TransientExecutionAuthority } from './git-lifecycle-store.js';
|
|
4
|
+
import { type GovernanceMode, type StoryGovernanceReceipt } from './governance-runtime-store.js';
|
|
4
5
|
/** P226.08 CON-ORIGIN-08-03: closed public remediation hints; never free text. */
|
|
5
6
|
export type DirectYoloFailureHint = 'fetch-origin-branch' | 'checkout-origin-or-rebase';
|
|
6
7
|
export type DirectYoloCheckpointResult<T> = {
|
|
@@ -24,6 +25,8 @@ export interface DirectYoloCommitPlan {
|
|
|
24
25
|
readonly idempotencyKey: string;
|
|
25
26
|
readonly changedPaths: readonly string[];
|
|
26
27
|
readonly trailers: readonly string[];
|
|
28
|
+
/** P228.26 (DEC-01): present only in `runtime-store`. */
|
|
29
|
+
readonly governance?: StoryGovernanceReceipt;
|
|
27
30
|
}
|
|
28
31
|
export interface DirectYoloSetupHandoffReceipt {
|
|
29
32
|
readonly schemaVersion: 1;
|
|
@@ -36,6 +39,8 @@ export interface DirectYoloSetupHandoffReceipt {
|
|
|
36
39
|
readonly expiresAt: string;
|
|
37
40
|
readonly reused: boolean;
|
|
38
41
|
readonly publicSafe: true;
|
|
42
|
+
/** P228.26 (DEC-01): present only in `runtime-store`. */
|
|
43
|
+
readonly governance?: StoryGovernanceReceipt;
|
|
39
44
|
}
|
|
40
45
|
export interface DirectYoloSetupReceipt {
|
|
41
46
|
readonly schemaVersion: 1;
|
|
@@ -126,9 +131,10 @@ export declare function resolveDirectYoloIntegrationAuthority(projectRootInput:
|
|
|
126
131
|
graphRevision: string;
|
|
127
132
|
authorizedWriteSet: readonly string[];
|
|
128
133
|
rootMemoryEffect: import("../private-execution/shared-root-memory-types.js").RootProjectMemoryEffect | undefined;
|
|
134
|
+
governanceMode: GovernanceMode;
|
|
129
135
|
}>;
|
|
130
136
|
/** P225.07: the direct C08 write-set rule, shared with root integration. */
|
|
131
|
-
export declare function validateDirectYoloWriteSet(paths: readonly string[], authorizedWriteSet: readonly string[], storyId: string, rootMemoryEffect?: RootProjectMemoryEffect): {
|
|
137
|
+
export declare function validateDirectYoloWriteSet(paths: readonly string[], authorizedWriteSet: readonly string[], storyId: string, rootMemoryEffect?: RootProjectMemoryEffect, governanceMode?: GovernanceMode): {
|
|
132
138
|
readonly ok: true;
|
|
133
139
|
} | {
|
|
134
140
|
readonly ok: false;
|
|
@@ -214,6 +220,12 @@ export declare function persistDirectYoloWaveStoryCheckpoint(input: {
|
|
|
214
220
|
readonly remote?: string;
|
|
215
221
|
readonly nowIso?: string;
|
|
216
222
|
}): Promise<DirectYoloCheckpointResult<StoryCommitCheckpoint>>;
|
|
223
|
+
/**
|
|
224
|
+
* P228.26 (DEC-04): capture the local governance of a story into the runtime
|
|
225
|
+
* store from the root checkout. `tracked` projects keep governance in Git and
|
|
226
|
+
* are refused with `governance-capture-not-applicable` (nothing is written).
|
|
227
|
+
*/
|
|
228
|
+
export declare function captureDirectYoloStoryGovernance(options: Pick<DirectYoloCheckpointOptions, 'projectRoot' | 'storyId'>): Promise<DirectYoloCheckpointResult<StoryGovernanceReceipt>>;
|
|
217
229
|
/**
|
|
218
230
|
* P227.03 (P227.06 DEBT-1, C11 F1/F2): a root write-set extension scope
|
|
219
231
|
* admitted by the direct checkpoint. It follows the shared P226.05 grammar
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{execFile as it}from"node:child_process";import{createHash as nt,randomBytes as $e,timingSafeEqual as at}from"node:crypto";import{existsSync as qe}from"node:fs";import{readFile as q,realpath as he}from"node:fs/promises";import{join as G,resolve as O}from"node:path";import{promisify as ct}from"node:util";import{readRootMemoryEffectForCheckpoint as st}from"../private-execution/root-memory-scope.js";import{rootMemoryEffectDigest as dt,verifyRootMemoryPhysicalWriteSet as ue}from"../private-execution/root-memory-git-evidence.js";import{resolveBranchUnit as ft,resolveEpicStoryIds as ht}from"../../../shared/dist/yoloop/branch-unit.js";import{expandStoryWriteScope as Pe,storyWriteSetCovers as ut,validateStoryWriteScope as lt}from"../../../shared/dist/yoloop/story-write-scope.js";import{acquireGitLifecyclePhysicalIntegrationLock as F,applyGitLifecycleRuntimeOverlay as le,computeImmutableStoryQaEvidenceDigest as pt,computeGitLifecyclePhysicalIntegrationLockOwnerDigest as pe,computeP205StoryQaEvidenceDigest as yt,computeLegacyDirectYoloRecoveryReceiptRef as gt,ensureRuntimeEpic as M,ensureRuntimeStory as ye,ensureGitLifecyclePrivateChildDirectory as Ne,executeP205TransientAuthorities as mt,executeP205TransientAuthority as wt,isP226GateReasonCode as ge,projectP205TransientExecutionEvidence as ze,publicStoryReviewArtifactFromGit as oe,LEGACY_DIRECT_YOLO_RECOVERY_COMMITS as vt,mutateGitLifecycleRuntime as L,P205_COMPLETE_COMMAND as Te,readGitLifecycleRuntime as C,gitLifecycleRuntimeDirectory as Me,STORY_WRITE_SET_MAX_ENTRIES as Rt,storyWriteSetExtensionPaths as It,assertGitLifecyclePrivateFile as ie,releaseGitLifecyclePhysicalIntegrationLock as Y,releaseGitLifecyclePhysicalIntegrationLockForCheckpoint as St,verifyGitLifecyclePhysicalIntegrationLock as ne,verifyAcceptedGitLifecycleStoryCheckpoint as me}from"./git-lifecycle-store.js";import{anchoredAtomicWriteFile as We,anchoredRemoveFile as xt}from"./secure-filesystem-boundary.js";import{parseNeocortexTrailers as bt,trailerReasonKey as we,trailerValue as ve}from"./neocortex-trailers.js";import{StoryWorktreeManager as kt}from"./story-worktree-manager.js";import{GIT_LIFECYCLE_COMMIT_PUSH_STEP_ID as Dt,GIT_LIFECYCLE_REVIEW_PR_STEP_ID as Ge,GIT_LIFECYCLE_SETUP_BRANCH_STEP_ID as W}from"./git-lifecycle-step-ids.js";const ee=ct(it),ae=3600*1e3;async function fr(e){let t,o=!1;try{const r=await Re(e.projectRoot,e.storyId);if(await Ke(r.projectRoot)){if(e.expiredSetupRecovery)return s("direct-yolo-expired-setup-recovery-invalid");const m=await Fe(r);return{ok:!0,value:Ye(r,m,!1)}}const i=N(e.nowIso),n=Date.parse(i),d=await u(r.projectRoot,["symbolic-ref","--quiet","--short","HEAD"]),c=await u(r.projectRoot,["rev-parse","HEAD"]),f=await C(r.projectRoot,{required:!0}),a=p(f.epics[r.epicId]),l=p(a?.branch_lease),g=e.expiredSetupRecovery;if(g&&!Nt(g,f.revision,l,e.storyId,n))return s("direct-yolo-expired-setup-recovery-invalid");const w=l&&Number.isFinite(Date.parse(String(l.expiresAt)))&&Date.parse(String(l.expiresAt))>n;if(w&&l?.ownerStoryId!==e.storyId)return s("direct-yolo-writer-active");let h=K(a?.origin_binding,r.executionBranch,r.originBranch),v;if(d===r.executionBranch){if(!h){if(a?.origin_binding!==void 0&&a?.origin_binding!==null||w)return s("direct-yolo-origin-binding-invalid");const m=await Wt(r,c,i);if(!m.ok)return m;h=m.value.binding,v={originRef:m.value.originRef,originHeadSha:m.value.binding.originHeadSha}}}else{if(d!==r.originBranch)return s("direct-yolo-current-branch-mismatch");if(h&&h.originHeadSha!==c){if(!g||!await B(r.projectRoot,["merge-base","--is-ancestor",h.originHeadSha,c]))return s("direct-yolo-origin-binding-conflict");const y=`refs/heads/${r.executionBranch}`;if(!await B(r.projectRoot,["show-ref","--verify","--quiet",y]))return s("direct-yolo-execution-branch-missing");const x=await u(r.projectRoot,["rev-parse",y]);if(!await B(r.projectRoot,["merge-base","--is-ancestor",x,c]))return s("direct-yolo-execution-branch-diverged")}if(h??={schemaVersion:1,originBranch:r.originBranch,originHeadSha:c,executionBranch:r.executionBranch,capturedFromCurrentCheckout:!0,capturedAt:i},(await re(r.projectRoot)).some(y=>y.branch===r.executionBranch&&O(y.path)!==r.projectRoot))return s("direct-yolo-execution-branch-checked-out-elsewhere");const S=await z(r.projectRoot),I=`refs/heads/${r.executionBranch}`;if(await B(r.projectRoot,["show-ref","--verify","--quiet",I])){const y=await u(r.projectRoot,["rev-parse",I]);if(y!==c){if(!await B(r.projectRoot,["merge-base","--is-ancestor",y,c]))return s("direct-yolo-execution-branch-diverged");g||await u(r.projectRoot,["update-ref",I,c,y])}g?t={checkoutBefore:S,executionRef:I,executionBranch:r.executionBranch,executionHead:y,originBranch:r.originBranch,originHead:c}:await u(r.projectRoot,["switch",r.executionBranch])}else{if(g)return s("direct-yolo-execution-branch-missing");await u(r.projectRoot,["switch","-c",r.executionBranch])}if(!t&&await z(r.projectRoot)!==S)return s("direct-yolo-checkout-payload-raced")}const R=t?.originHead??await u(r.projectRoot,["rev-parse","HEAD"]);if(!t&&await u(r.projectRoot,["symbolic-ref","--quiet","--short","HEAD"])!==r.executionBranch)return s("direct-yolo-current-branch-mismatch");if(w&&l?.ownerStoryId===e.storyId)return l.setupHeadSha!==R?s("direct-yolo-setup-lease-head-unbound"):{ok:!0,value:de(r,h,String(l.expiresAt),!0)};const b=i,k=new Date(n+3600*1e3).toISOString(),D=`setup-${$e(32).toString("hex")}`,j=g?f:await C(r.projectRoot,{required:!0});return await L(r.projectRoot,m=>{const S=M(m,r.epicId),I=p(S.branch_lease);if(g&&JSON.stringify(I)!==JSON.stringify(g.expectedLease))throw new Error("direct-yolo-expired-setup-recovery-raced");if(I&&Date.parse(String(I.expiresAt))>n&&I.ownerStoryId!==e.storyId)throw new Error("direct-yolo-writer-active");const y=K(S.origin_binding,r.executionBranch,r.originBranch);if(S.origin_binding&&!y)throw new Error("direct-yolo-origin-binding-conflict");if(y&&JSON.stringify(y)!==JSON.stringify(h))throw new Error("direct-yolo-origin-binding-conflict");S.branch_mode="epic",S.execution_branch=r.executionBranch,S.origin_branch=r.originBranch,S.graph_revision=r.graphRevision,S.origin_binding=h,S.branch_lease={schemaVersion:1,ownerStoryId:e.storyId,sessionId:D,idempotencyKey:D,acquiredAt:b,expiresAt:k,setupHeadSha:R}},{expectedRevision:g?.expectedRuntimeRevision??j.revision,preCommit:async()=>{if(t){if((await re(r.projectRoot)).some(S=>S.branch===r.executionBranch&&O(S.path)!==r.projectRoot)||await u(r.projectRoot,["symbolic-ref","--quiet","--short","HEAD"])!==r.originBranch||await u(r.projectRoot,["rev-parse","HEAD"])!==t.originHead||await z(r.projectRoot)!==t.checkoutBefore||!await B(r.projectRoot,["show-ref","--verify","--quiet",t.executionRef])||await u(r.projectRoot,["rev-parse",t.executionRef])!==t.executionHead)throw new Error("direct-yolo-expired-setup-recovery-raced");if(o=!0,t.executionHead!==t.originHead&&await u(r.projectRoot,["update-ref",t.executionRef,t.originHead,t.executionHead]),await u(r.projectRoot,["switch",r.executionBranch]),await z(r.projectRoot)!==t.checkoutBefore)throw new Error("direct-yolo-checkout-payload-raced")}if(await u(r.projectRoot,["symbolic-ref","--quiet","--short","HEAD"])!==r.executionBranch||await u(r.projectRoot,["rev-parse","HEAD"])!==R)throw new Error("direct-yolo-setup-physical-state-raced");if(v&&(await u(r.projectRoot,["rev-parse","--verify","--quiet",`${v.originRef}^{commit}`]).catch(()=>"")!==v.originHeadSha||await He(r.projectRoot,["merge-base","--is-ancestor",v.originHeadSha,R])!==0))throw new Error("direct-yolo-origin-ref-raced")}}),{ok:!0,value:de(r,h,k,!1)}}catch(r){return o&&t&&await zt(O(e.projectRoot),t).catch(()=>{}),s(X(r,"direct-yolo-setup-failed"))}}async function hr(e){let t;try{const o=await Re(e.projectRoot,e.storyId);if(await Ke(o.projectRoot))return await jt(o);const r=await V(e.projectRoot,e.storyId),i=N(e.nowIso),n=G(r.projectRoot,".neocortex/state.json"),d=await q(n,"utf8"),c=await z(r.projectRoot),f=await u(r.projectRoot,["rev-parse","HEAD"]),a=`refs/heads/${r.executionBranch}`,l=await C(r.projectRoot,{required:!0}),g=p(l.epics[r.epicId]),w=K(g?.origin_binding,r.executionBranch,r.originBranch),h=p(g?.branch_lease);if(!w)return s("direct-yolo-origin-binding-invalid");if(!h||!ke(h,e.storyId,i)||h?.sessionId!==h?.idempotencyKey)return s("direct-yolo-setup-lease-invalid");const v=await F(r.projectRoot,{kind:"direct",storyId:e.storyId,sessionId:String(h.sessionId),idempotencyKey:String(h.idempotencyKey),expiresAt:new Date(Date.now()+300*1e3).toISOString(),persistent:!1});if(!v.ok)return s(v.reasonCode);if(t=v,f!==h.setupHeadSha||!await B(r.projectRoot,["merge-base","--is-ancestor",w.originHeadSha,f])||await u(r.projectRoot,["rev-parse",a])!==f)return s("direct-yolo-setup-head-mismatch");if((await re(r.projectRoot)).some(S=>S.branch===r.executionBranch&&O(S.path)!==r.projectRoot))return s("direct-yolo-execution-branch-checked-out-elsewhere");const b=p(JSON.parse(d)),k=p(p(b?.stories)?.[e.storyId]),D=p(l.stories[e.storyId]);if(!k||!["backlog","ready_to_start"].includes(String(k.status))||k.steps_completed!==void 0&&(!Array.isArray(k.steps_completed)||k.steps_completed.length>0)||k.branch_name||k.checkpoint)return s("direct-yolo-setup-story-progress-conflict");const j=D?.status==="branch-ready"&&D.last_step===W&&Array.isArray(D.steps_completed)&&D.steps_completed.length===1&&D.steps_completed[0]===W&&U(D).sort().join(",")==="last_step,status,steps_completed";if(D&&U(D).length>0&&!j)return s("direct-yolo-setup-story-progress-conflict");const m=async()=>{if(Date.parse(String(h.expiresAt))<=(e.nowIso?Date.parse(i):Date.now())||!t||!await ne(t.path,t.owner)||await q(n,"utf8")!==d||await z(r.projectRoot)!==c||await u(r.projectRoot,["symbolic-ref","--quiet","--short","HEAD"])!==r.executionBranch||await u(r.projectRoot,["rev-parse","HEAD"])!==f||!await B(r.projectRoot,["merge-base","--is-ancestor",w.originHeadSha,f])||await u(r.projectRoot,["rev-parse",a])!==f)throw new Error("direct-yolo-setup-physical-state-raced")};return j?await m():await L(r.projectRoot,S=>{const I=p(S.epics[r.epicId]),y=ye(S,e.storyId);if(JSON.stringify(I?.branch_lease)!==JSON.stringify(h)||JSON.stringify(I?.origin_binding)!==JSON.stringify(w)||I?.graph_revision!==r.graphRevision||U(y).length>0)throw new Error("direct-yolo-setup-runtime-raced");y.status="branch-ready",y.last_step=W,y.steps_completed=[W]},{expectedRevision:l.revision,preCommit:m}),{ok:!0,value:Object.freeze({...de(r,w,String(h.expiresAt),j),checkpointAccepted:!0,graphRevision:r.graphRevision,headSha:f})}}catch(o){return s(X(o,"direct-yolo-setup-acceptance-failed"))}finally{t&&await Y(t.path,t.owner).catch(()=>{})}}async function ur(e){try{const t=await V(e.projectRoot,e.storyId),o=P(await _(t.projectRoot,["diff","--cached","--name-only","-z"])),r=Z(o,t.authorizedWriteSet,e.storyId,t.rootMemoryEffect);if(!r.ok)return s(r.reasonCode);if(t.rootMemoryEffect&&ue(t.projectRoot,t.rootMemoryEffect,{storyId:e.storyId,executionBranch:t.executionBranch,baseSha:await u(t.projectRoot,["rev-parse","HEAD"]),headRef:":",childPaths:t.authorizedWriteSet}),oe(t.projectRoot,e.storyId,":")?.verdict!=="approved")return s("direct-yolo-review-artifact-not-approved");if(P(await _(t.projectRoot,["diff","--name-only","-z"])).some(y=>o.includes(y)))return s("direct-yolo-user-overlap");const d=await _(t.projectRoot,["diff","--cached","--binary","--full-index"]);if(!d)return s("direct-yolo-staged-diff-empty");const c=A(d),f=A([...t.authorizedWriteSet].sort().join("\0")),a=N(e.nowIso),l=await C(t.projectRoot,{required:!0}),g=p(l.epics[t.epicId]?.branch_lease);if(!ke(g,e.storyId,a))return s("direct-yolo-setup-handoff-owner-invalid");const w=String(g.sessionId),h=String(g.expiresAt),v=new Date(Math.min(Date.parse(h),Date.parse(a)+300*1e3)).toISOString(),R=await J(t.projectRoot,e.storyId),b=R?.state==="issued"&&R.fromSessionId===w&&R.bundleDigest===c&&R.claimRevision===f&&Date.parse(R.expiresAt)>Date.parse(a),k=b?R.expiresAt:v,D=b?R.token:$e(32).toString("base64url"),j=A(D),m=Object.freeze({schemaVersion:1,kind:"direct-yolo-setup-handoff",storyId:e.storyId,fromSessionId:w,tokenDigest:j,bundleDigest:c,claimRevision:f,expiresAt:k}),S=A(JSON.stringify(m)),I=await F(t.projectRoot,{kind:"direct",storyId:e.storyId,sessionId:w,idempotencyKey:w,expiresAt:k,persistent:!1,createdAt:a});if(!I.ok)return s(I.reasonCode==="git-lifecycle-integration-backpressure"?"direct-yolo-integration-backpressure":"direct-yolo-integration-lock-failed");try{await De(t.projectRoot,{schemaVersion:1,kind:"direct-yolo-setup-handoff-token",state:"issued",storyId:e.storyId,fromSessionId:w,token:D,tokenDigest:j,bundleDigest:c,claimRevision:f,grantDigest:S,expiresAt:k}),await L(t.projectRoot,y=>{const x=p(M(y,t.epicId).branch_lease);if(!ke(x,e.storyId,a)||x?.sessionId!==w||x.idempotencyKey!==w)throw new Error("direct-yolo-setup-handoff-owner-raced");x.handoffGrant=m},{expectedRevision:l.revision,preCommit:async()=>{if(!await ne(I.path,I.owner))throw new Error("direct-yolo-integration-lock-raced");const y=await J(t.projectRoot,e.storyId);if(!y||y.state!=="issued"||y.grantDigest!==S||y.tokenDigest!==j)throw new Error("direct-yolo-setup-handoff-token-raced")}})}finally{await Y(I.path,I.owner).catch(()=>{})}return{ok:!0,value:Object.freeze({schemaVersion:1,kind:"direct-yolo-setup-handoff-receipt",storyId:e.storyId,sessionId:w,bundleDigest:c,claimRevision:f,grantDigest:S,expiresAt:k,reused:b,publicSafe:!0})}}catch(t){return s(t instanceof Error&&/^direct-yolo-/.test(t.message)?t.message:"direct-yolo-setup-handoff-failed")}}async function lr(e){try{const t=await V(e.projectRoot,e.storyId),o=await u(t.projectRoot,["rev-parse","HEAD"]),r=P(await _(t.projectRoot,["diff","--cached","--name-only","-z"])),i=Z(r,t.authorizedWriteSet,e.storyId,t.rootMemoryEffect);if(!i.ok)return s(i.reasonCode);t.rootMemoryEffect&&ue(t.projectRoot,t.rootMemoryEffect,{storyId:e.storyId,executionBranch:t.executionBranch,baseSha:o,headRef:":",childPaths:t.authorizedWriteSet});const n=oe(t.projectRoot,e.storyId,":");if(n?.verdict!=="approved")return s("direct-yolo-review-artifact-not-approved");if(P(await _(t.projectRoot,["diff","--name-only","-z"])).some(x=>r.includes(x)))return s("direct-yolo-user-overlap");const c=await _(t.projectRoot,["diff","--cached","--binary","--full-index"]);if(!c)return s("direct-yolo-staged-diff-empty");const f=A(c),a=A([...t.authorizedWriteSet].sort().join("\0")),l=await Ze(t.projectRoot,e.storyId),g=l.state==="valid"&&l.plan.epicId===t.epicId&&l.plan.executionBranch===t.executionBranch&&l.plan.preparedBase===o&&l.plan.bundleDigest===f&&l.plan.claimRevision===a?l.plan:void 0,w=g?.graphRevision??t.graphRevision,h=xe({storyId:e.storyId,epicId:t.epicId,executionBranch:t.executionBranch,baseSha:o,bundleDigest:f,graphRevision:w,claimRevision:a}),v=N(e.nowIso),R={schemaVersion:1,kind:"direct-yolo-commit-plan",storyId:e.storyId,epicId:t.epicId,executionBranch:t.executionBranch,graphRevision:w,preparedBase:o,bundleDigest:f,claimRevision:a,idempotencyKey:h,issuedAt:g?.issuedAt??v};let b=e.setupLeaseHandoff??await Ct(t.projectRoot,e.storyId,f,a,v);const k=await C(t.projectRoot,{required:!0}),D=p(k.epics[t.epicId]?.branch_lease),j=D?.ownerStoryId===e.storyId&&D.sessionId===h&&D.idempotencyKey===h&&typeof D.expiresAt=="string"&&Date.parse(D.expiresAt)>Date.parse(v)?D:void 0;if(j&&e.setupLeaseHandoff)return s("direct-yolo-setup-handoff-replayed");const m=p(j?.handoffConsumption);if(m){const x=await J(t.projectRoot,e.storyId);if(!x||!["consuming","consumed"].includes(x.state)||x.fromSessionId!==m.fromSessionId||x.tokenDigest!==m.tokenDigest||x.bundleDigest!==f||x.claimRevision!==a||m.bundleDigest!==f||m.claimRevision!==a||x.consumedBySessionId!==h||m.consumedBySessionId!==h)return s("direct-yolo-setup-handoff-consume-invalid");if(x.state==="consuming"){if(!x.token||A(x.token)!==x.tokenDigest)return s("direct-yolo-setup-handoff-consume-invalid");b={sessionId:x.fromSessionId,token:x.token}}}const S=j?String(j.expiresAt):new Date(Date.parse(v)+ae).toISOString(),I=await F(t.projectRoot,{kind:"direct",storyId:e.storyId,sessionId:h,idempotencyKey:h,expiresAt:S,persistent:!0,createdAt:j&&typeof j.acquiredAt=="string"?j.acquiredAt:v});if(!I.ok)return s(I.reasonCode==="git-lifecycle-integration-backpressure"?"direct-yolo-integration-backpressure":"direct-yolo-integration-lock-failed");try{b&&e.setupLeaseHandoff===void 0&&(await Ht(t.projectRoot,e.storyId,b.sessionId,b.token,h,v),await e.setupHandoffFault?.("after-consuming-persisted")),await L(t.projectRoot,x=>{const $=M(x,t.epicId),E=p($.branch_lease),H=E&&Date.parse(String(E.expiresAt))>Date.parse(v),T=E?.ownerStoryId===e.storyId&&E.sessionId===h&&E.idempotencyKey===h,ot=E?.ownerStoryId===e.storyId&&E.sessionId===E.idempotencyKey&&typeof E.idempotencyKey=="string"&&/^setup-[a-f0-9]{64}$/.test(E.idempotencyKey),fe=H&&ot&&Lt({current:E,handoff:b,storyId:e.storyId,bundleDigest:f,claimRevision:a,nowIso:v});if(b&&H&&!T&&!fe)throw new Error("direct-yolo-setup-handoff-invalid");if(H&&!T&&!fe)throw new Error("direct-yolo-writer-active");const Oe=fe?p(E?.handoffGrant):void 0,Le=Oe?{schemaVersion:1,kind:"direct-yolo-setup-handoff-consumption",state:"consumed",storyId:e.storyId,fromSessionId:String(E?.sessionId),tokenDigest:String(Oe.tokenDigest),bundleDigest:f,claimRevision:a,consumedBySessionId:h,consumedAt:v}:void 0;$.branch_mode="epic",$.execution_branch=t.executionBranch,$.origin_branch=t.originBranch,$.graph_revision=t.graphRevision,$.branch_lease=H&&T?E:{schemaVersion:1,ownerStoryId:e.storyId,sessionId:h,idempotencyKey:h,acquiredAt:v,expiresAt:S,...Le?{handoffConsumption:Le}:{}}},{expectedRevision:k.revision,preCommit:async()=>{if(!await ne(I.path,I.owner))throw new Error("direct-yolo-integration-lock-raced");await _t(t.projectRoot,R)}})}catch(x){throw await Y(I.path,I.owner).catch(()=>{}),x}b&&e.setupLeaseHandoff===void 0&&(await e.setupHandoffFault?.("before-consumed-persist"),await Ot(t.projectRoot,t.epicId,e.storyId,b.sessionId,b.token,f,a,h,v));const y=Object.freeze([`Neocortex-Story: ${e.storyId}`,`Neocortex-Epic: ${t.epicId}`,`Neocortex-Execution-Branch: ${t.executionBranch}`,`Neocortex-Prepared-Base: ${o}`,`Neocortex-Bundle-Digest: ${f}`,`Neocortex-Review-Artifact-Digest: ${n.digest}`,`Neocortex-Graph-Revision: ${w}`,`Neocortex-Claim-Revision: ${a}`,...t.rootMemoryEffect?[`Neocortex-Root-Memory-Effect: ${dt(t.rootMemoryEffect)}`]:[]]);return{ok:!0,value:Object.freeze({schemaVersion:1,storyId:e.storyId,epicId:t.epicId,executionBranch:t.executionBranch,baseSha:o,bundleDigest:f,reviewArtifactDigest:n.digest,graphRevision:w,claimRevision:a,idempotencyKey:h,changedPaths:Object.freeze(r),trailers:y})}}catch(t){return s(X(t,"direct-yolo-begin-failed"))}}async function pr(e){let t,o,r;try{const i=await V(e.projectRoot,e.storyId);t=i;const n=await u(i.projectRoot,["rev-parse","HEAD"]);let d=await C(i.projectRoot,{required:!0});const c=p(d.stories[e.storyId]?.checkpoint);if(c){const S=typeof c.headSha=="string"?c.headSha:"",I=typeof c.graphRevision=="string"?c.graphRevision:"",y=/^[a-f0-9]{40,64}$/.test(S)?P(await _(i.projectRoot,["diff-tree","--no-commit-id","--name-only","-r","-z",S])):[],x=Z(y,i.authorizedWriteSet,e.storyId,i.rootMemoryEffect);if(!(/^[a-f0-9]{40,64}$/.test(S)&&await B(i.projectRoot,["merge-base","--is-ancestor",S,n]))||!/^[a-f0-9]{64}$/.test(I)||!x.ok)return s("direct-yolo-replay-invalid");const E=await Ae(e,i.projectRoot,n,I);if(!await me(i.projectRoot,c,e.storyId,i.epicId,i.executionBranch,E.transientAuthority,i.authorizedWriteSet))return s("direct-yolo-replay-invalid");if(!await Be(i.projectRoot,i.executionBranch,n,y))return s("direct-yolo-replay-head-raced");if(e.push&&!await Je(i.projectRoot,e.remote??"origin",i.executionBranch,S))return s("direct-yolo-remote-head-mismatch");const H=Array.isArray(c.receiptRefs)?c.receiptRefs.find(T=>typeof T=="string"&&/^physical-lock-owner:[a-f0-9]{64}$/.test(T)):void 0;return H&&typeof c.idempotencyKey=="string"&&await St(i.projectRoot,{storyId:e.storyId,idempotencyKey:c.idempotencyKey,ownerDigest:H.slice(20)}),await ce(i.projectRoot,e.storyId).catch(()=>{}),{ok:!0,value:c}}const f=n,a=await Ve(i,e.storyId,f);if(!a.ok)return s(a.reasonCode);const{baseSha:l,changedPaths:g,bundleDigest:w,graphRevision:h,claimRevision:v,idempotencyKey:R}=a.value,b=p(d.epics[i.epicId]?.branch_lease),k=N(e.nowIso),D=b?.ownerStoryId===e.storyId&&b.idempotencyKey===R&&b.sessionId===R&&Date.parse(String(b.expiresAt))>Date.now()?b:void 0;if(b&&Date.parse(String(b.expiresAt))>Date.now()&&!D)return s("direct-yolo-writer-active");const j=D??{schemaVersion:1,ownerStoryId:e.storyId,sessionId:R,idempotencyKey:R,acquiredAt:k,expiresAt:new Date(Date.parse(k)+ae).toISOString()},m=await F(i.projectRoot,{kind:"direct",storyId:e.storyId,sessionId:R,idempotencyKey:R,expiresAt:String(j.expiresAt),persistent:!0,createdAt:String(j.acquiredAt)});if(!m.ok)return s(m.reasonCode==="git-lifecycle-integration-backpressure"?"direct-yolo-integration-backpressure":"direct-yolo-integration-lock-failed");r=m,D||(d=(await L(i.projectRoot,I=>{const y=M(I,i.epicId),x=p(y.branch_lease);if(x&&Date.parse(String(x.expiresAt))>Date.parse(k))throw new Error("direct-yolo-writer-active");if(y.graph_revision!==i.graphRevision)throw new Error("direct-yolo-graph-revision-raced");y.branch_lease=j},{expectedRevision:d.revision})).document),o=j;{const S=await Ae(e,i.projectRoot,f,h);if(!await Be(i.projectRoot,i.executionBranch,f,g))return s("direct-yolo-head-raced");if(e.push){const x=te(e.remote??"origin");if(await u(i.projectRoot,["push",x,i.executionBranch]),!await _e(i.projectRoot,x,i.executionBranch,f))return s("direct-yolo-remote-head-mismatch")}const I=await Ie({projectRoot:i.projectRoot,storyId:e.storyId,epicId:i.epicId,executionBranch:i.executionBranch,baseSha:l,headSha:f,bundleDigest:w,graphRevision:h,claimRevision:v,idempotencyKey:R,qaExecution:S,physicalLockOwnerDigest:pe(m.owner),nowIso:N(e.nowIso),legacyReceiptRef:void 0,rootMemoryEffect:i.rootMemoryEffect});return await e.beforeCheckpointPersist?.(),await Se({projectRoot:i.projectRoot,checkpoint:I,remote:e.push?e.remote??"origin":void 0,expectedRevision:d.revision,expectedLease:j,expectedGraphRevision:i.graphRevision,expectedCheckpointGraphRevision:h,physicalLockPath:m.path,physicalLockOwner:m.owner,transientAuthority:S.transientAuthority,authorizedWriteSet:i.authorizedWriteSet})?(await ce(i.projectRoot,e.storyId).catch(()=>{}),await e.afterCheckpointPersist?.(),{ok:!0,value:I}):s("direct-yolo-checkpoint-persist-failed")}}catch(i){return s(X(i,"direct-yolo-finalize-failed"))}finally{r&&await Y(r.path,r.owner).catch(()=>{}),t&&o?await Ee(t.projectRoot,t.epicId,o).catch(()=>{}):t&&await qt(t,e.storyId).catch(()=>{})}}async function Ve(e,t,o){const r=await u(e.projectRoot,["rev-parse",`${o}^`]),i=await _(e.projectRoot,["show","--no-patch","--format=%B",o]),n=P(await _(e.projectRoot,["diff-tree","--no-commit-id","--name-only","-r","-z",o])),d=Z(n,e.authorizedWriteSet,t,e.rootMemoryEffect);if(!d.ok)return s(d.reasonCode);e.rootMemoryEffect&&ue(e.projectRoot,e.rootMemoryEffect,{storyId:t,executionBranch:e.executionBranch,baseSha:r,headRef:o,childPaths:e.authorizedWriteSet});const c=A([...e.authorizedWriteSet].sort().join("\0")),f=await Ze(e.projectRoot,t);if(f.state==="invalid")return s("direct-yolo-commit-plan-invalid");const a=f.state==="valid"?f.plan:void 0;if(a&&(a.epicId!==e.epicId||a.executionBranch!==e.executionBranch))return s("direct-yolo-commit-plan-invalid");if(a&&a.claimRevision!==c)return s("direct-yolo-commit-plan-claim-changed");if(a&&a.preparedBase!==r)return s("direct-yolo-commit-plan-base-mismatch");const l=bt(i);if(!l.ok)return s(`direct-yolo-trailer-duplicate:${l.key}`);const g=l.values,w=a?.graphRevision??e.graphRevision,h=c,v=[["Neocortex-Story",t],["Neocortex-Epic",e.epicId],["Neocortex-Execution-Branch",e.executionBranch],["Neocortex-Prepared-Base",r],["Neocortex-Bundle-Digest",a?.bundleDigest??""],["Neocortex-Graph-Revision",w],["Neocortex-Claim-Revision",h]];for(const[m,S]of v){const I=ve(g,m);if(I===void 0)return s(`direct-yolo-trailer-missing:${we(m)}`);if(m==="Neocortex-Bundle-Digest"&&!a){if(!/^[a-f0-9]{64}$/.test(I))return s(`direct-yolo-trailer-mismatch:${we(m)}`);continue}if(I!==S)return s(`direct-yolo-trailer-mismatch:${we(m)}`)}const R=ve(g,"Neocortex-Bundle-Digest"),b=oe(e.projectRoot,t,o);if(b?.verdict!=="approved")return s("direct-yolo-review-artifact-not-approved");const k=ve(g,"Neocortex-Review-Artifact-Digest");if(k!==void 0&&k!==b.digest)return s("direct-yolo-review-artifact-digest-mismatch");const D=A(await _(e.projectRoot,["diff","--binary","--full-index",`${r}..${o}`]));if(R!==D)return s("direct-yolo-bundle-digest-mismatch");const j=xe({storyId:t,epicId:e.epicId,executionBranch:e.executionBranch,baseSha:r,bundleDigest:R,graphRevision:w,claimRevision:h});return a&&a.idempotencyKey!==j?s("direct-yolo-commit-plan-invalid"):{ok:!0,value:{baseSha:r,changedPaths:n,bundleDigest:R,graphRevision:w,claimRevision:h,idempotencyKey:j}}}async function yr(e){try{const t=await V(e.projectRoot,e.storyId);if(!/^[a-f0-9]{40,64}$/.test(e.commitSha))return s("direct-yolo-recovery-commit-invalid");const o=await u(t.projectRoot,["rev-parse",e.commitSha]);if(vt[e.storyId]!==o)return s("direct-yolo-recovery-not-allowlisted");if(await u(t.projectRoot,["rev-parse","HEAD"])!==o)return s("direct-yolo-recovery-head-mismatch");await u(t.projectRoot,["merge-base","--is-ancestor",o,`refs/heads/${t.executionBranch}`]);const r=await u(t.projectRoot,["rev-parse",`${o}^`]),i=await _(t.projectRoot,["diff","--binary","--full-index",`${r}..${o}`]),n=P(await _(t.projectRoot,["diff-tree","--no-commit-id","--name-only","-r","-z",o]));if(!Z(n,t.authorizedWriteSet.length>0?t.authorizedWriteSet:n,e.storyId).ok)return s("direct-yolo-recovery-write-set-invalid");const c=A(i),f=A([...n].sort().join("\0")),a=A(["legacy-direct-yolo-recovery-v1",e.storyId,o].join("\0")),l=N(e.nowIso),g=new Date(Date.parse(l)+ae).toISOString(),w=await C(t.projectRoot,{required:!0}),h=await F(t.projectRoot,{kind:"direct",storyId:e.storyId,sessionId:a,idempotencyKey:a,expiresAt:g,persistent:!0,createdAt:l});if(!h.ok)return s(h.reasonCode==="git-lifecycle-integration-backpressure"?"direct-yolo-recovery-integration-backpressure":"direct-yolo-recovery-integration-lock-failed");const v={schemaVersion:1,ownerStoryId:e.storyId,sessionId:a,idempotencyKey:a,acquiredAt:l,expiresAt:g};let R=!1;try{const b=await L(t.projectRoot,I=>{const y=M(I,t.epicId),x=p(y.branch_lease);if(x&&Date.parse(String(x.expiresAt))>Date.parse(l)&&!je(x,v))throw new Error("direct-yolo-recovery-writer-active");if(y.graph_revision!==t.graphRevision)throw new Error("direct-yolo-recovery-graph-raced");y.branch_mode="epic",y.execution_branch=t.executionBranch,y.origin_branch=t.originBranch,y.branch_lease=v},{expectedRevision:w.revision});R=!0;const k=await Ae(e,t.projectRoot,o,t.graphRevision);if(!await Be(t.projectRoot,t.executionBranch,o,n))return s("direct-yolo-recovery-head-raced");if(e.push){const I=te(e.remote??"origin"),y=(await u(t.projectRoot,["ls-remote","--heads",I,`refs/heads/${t.executionBranch}`])).split(/\s+/)[0];if(!y||!await B(t.projectRoot,["merge-base","--is-ancestor",o,y]))return s("direct-yolo-recovery-remote-proof-missing")}const D=await Ie({projectRoot:t.projectRoot,storyId:e.storyId,epicId:t.epicId,executionBranch:t.executionBranch,baseSha:r,headSha:o,bundleDigest:c,graphRevision:t.graphRevision,claimRevision:f,idempotencyKey:a,qaExecution:k,physicalLockOwnerDigest:pe(h.owner),nowIso:l,legacyReceiptRef:void 0}),j=await gt(t.projectRoot,{storyId:e.storyId,epicId:t.epicId,executionBranch:t.executionBranch,baseSha:r,headSha:o,bundleDigest:c,graphRevision:t.graphRevision});if(!j)return s("direct-yolo-recovery-evidence-invalid");const m=Object.freeze({...D,receiptRefs:Object.freeze([...D.receiptRefs,j])});return await Se({projectRoot:t.projectRoot,checkpoint:m,remote:e.push?e.remote??"origin":void 0,remotePolicy:"ancestor-recovery",expectedRevision:b.document.revision,expectedLease:v,expectedGraphRevision:t.graphRevision,physicalLockPath:h.path,physicalLockOwner:h.owner,transientAuthority:k.transientAuthority,authorizedWriteSet:t.authorizedWriteSet})?{ok:!0,value:m}:s("direct-yolo-recovery-persist-failed")}finally{await Y(h.path,h.owner).catch(()=>{}),R&&await Ee(t.projectRoot,t.epicId,v).catch(()=>{})}}catch(t){return s(X(t,"direct-yolo-recovery-failed"))}}async function Ke(e){const t=await he(await u(e,["rev-parse","--absolute-git-dir"])),o=await he(await u(e,["rev-parse","--path-format=absolute","--git-common-dir"]));return t!==o}async function Fe(e){const t=await C(e.projectRoot,{required:!0}),o=Object.values(t.storyWorktrees?.entries??{}).filter(g=>g.storyId===e.storyId&&g.epicId===e.epicId&&g.state==="active");if(o.length===0)throw new Error("direct-yolo-worktree-lease-missing");if(o.length>1)throw new Error("direct-yolo-worktree-lease-ambiguous");const r=o[0];if(r.executionBranch!==e.executionBranch)throw new Error("direct-yolo-worktree-branch-mismatch");if(await he(await u(e.projectRoot,["rev-parse","--show-toplevel"]))!==r.worktreePath)throw new Error("direct-yolo-worktree-path-mismatch");if(await u(e.projectRoot,["symbolic-ref","--quiet","--short","HEAD"]).catch(()=>"")!==r.temporaryBranch)throw new Error("direct-yolo-worktree-branch-mismatch");const d=await new kt({projectRoot:e.projectRoot}).probe(r.leaseId);if(!d.ok||d.value.ownership!=="proven")throw new Error("direct-yolo-worktree-ownership-unproven");const c=K(p(t.epics[e.epicId])?.origin_binding,e.executionBranch,e.originBranch);if(!c)throw new Error("direct-yolo-origin-binding-invalid");const f=r.syncedSha??r.baseSha,a=await u(e.projectRoot,["rev-parse","HEAD"]),l=`refs/heads/${e.executionBranch}`;if(a!==f||!await B(e.projectRoot,["merge-base","--is-ancestor",f,l])||!await B(e.projectRoot,["merge-base","--is-ancestor",c.originHeadSha,f]))throw new Error("direct-yolo-worktree-base-divergent");if(d.value.clean!==!0||(await _(e.projectRoot,["status","--porcelain=v1","-z","--untracked-files=all"])).length>0)throw new Error("direct-yolo-worktree-dirty");return{leaseId:r.leaseId,temporaryBranch:r.temporaryBranch,authorizedBase:f,headSha:a,expiresAt:r.expiresAt,binding:c}}function Ye(e,t,o){return Object.freeze({...de(e,t.binding,t.expiresAt,o),workspace:"story-worktree",temporaryBranch:t.temporaryBranch,baseSha:t.authorizedBase})}async function jt(e){const t=await Fe(e),o=G(e.projectRoot,".neocortex/state.json"),r=await q(o,"utf8"),i=p(JSON.parse(r)),n=p(p(i?.stories)?.[e.storyId]),d=await C(e.projectRoot,{required:!0}),c=p(d.stories[e.storyId]);if(!n||!["backlog","ready_to_start"].includes(String(n.status))||n.steps_completed!==void 0&&(!Array.isArray(n.steps_completed)||n.steps_completed.length>0)||n.branch_name||n.checkpoint)return s("direct-yolo-setup-story-progress-conflict");const f=c?.status==="branch-ready"&&c.last_step===W&&Array.isArray(c.steps_completed)&&c.steps_completed.length===1&&c.steps_completed[0]===W&&U(c).sort().join(",")==="last_step,status,steps_completed";return c&&U(c).length>0&&!f?s("direct-yolo-setup-story-progress-conflict"):(f||await L(e.projectRoot,a=>{const l=ye(a,e.storyId);if(U(l).length>0)throw new Error("direct-yolo-setup-runtime-raced");l.status="branch-ready",l.last_step=W,l.steps_completed=[W]},{expectedRevision:d.revision,preCommit:async()=>{if(await q(o,"utf8")!==r||await u(e.projectRoot,["symbolic-ref","--quiet","--short","HEAD"])!==t.temporaryBranch||await u(e.projectRoot,["rev-parse","HEAD"])!==t.headSha||(await _(e.projectRoot,["status","--porcelain=v1","-z","--untracked-files=all"])).length>0)throw new Error("direct-yolo-setup-physical-state-raced")}}),{ok:!0,value:Object.freeze({...Ye(e,t,f),checkpointAccepted:!0,graphRevision:e.graphRevision,headSha:t.headSha})})}async function gr(e,t){const o=await V(e,t),r=await C(o.projectRoot,{required:!0}),i=K(p(r.epics[o.epicId])?.origin_binding,o.executionBranch,o.originBranch);return{...o,originBinding:i}}function mr(e,t,o,r){return Z(e,t,o,r)}function wr(e){return A(["direct-yolo-commit-v1",e.storyId,e.epicId,e.executionBranch,e.baseSha,e.bundleDigest,e.graphRevision,e.claimRevision].join("\0"))}const vr=ae,Et="p205-wave:";function Rr(e){if(e.waveStoryIds.length===0||e.waveStoryIds.length!==e.waveCommitShas.length||e.waveCommitShas[e.waveCommitShas.length-1]!==e.waveHeadSha||e.waveCommitShas.some(o=>!/^[a-f0-9]{40,64}$/.test(o)))throw new Error("direct-yolo-wave-coverage-invalid");const t=A(["p205-wave-coverage-v1",e.epicId,e.executionBranch,e.waveHeadSha,...e.waveStoryIds.map((o,r)=>`${o}=${e.waveCommitShas[r]}`)].join("\0"));return Object.freeze({kind:"wave",waveHeadSha:e.waveHeadSha,waveStoryIds:Object.freeze([...e.waveStoryIds]),waveCommitShas:Object.freeze([...e.waveCommitShas]),waveDigest:t})}function At(e){return`${Et}${e.waveHeadSha}:${e.waveDigest}`}async function Ir(e){let t;try{t=await mt(e.projectRoot,{headSha:e.headSha,graphRevisions:e.graphRevisions,...e.nowIso!==void 0?{nowIso:e.nowIso}:{}})}catch(o){const r=o instanceof Error?o.message:"";return/^p205-transient-[a-z0-9-]{1,64}$/.test(r)?{ok:!1,headSha:e.headSha,kind:"infrastructure",reasonCode:r}:{ok:!1,headSha:e.headSha,kind:"gate-failed",reasonCode:ge(r)?r:"p205-complete-gate-failed"}}try{await e.qaRunner?.({projectRoot:e.projectRoot,storyId:e.storyId,headSha:e.headSha})}catch(o){const r=o instanceof Error?o.message:"";return/^p205-transient-[a-z0-9-]{1,64}$/.test(r)?{ok:!1,headSha:e.headSha,kind:"infrastructure",reasonCode:r}:{ok:!1,headSha:e.headSha,kind:"gate-failed",reasonCode:ge(r)||/^p205-[a-z0-9-]{1,64}$/.test(r)?r:"p205-complete-gate-failed"}}return{ok:!0,headSha:e.headSha,authorities:t}}async function Sr(e,t,o,r){const i=te(t);return await u(e,["push",i,o]),_e(e,i,o,r)}async function xr(e){try{const t=await V(e.projectRoot,e.storyId),o=e.coverage.waveHeadSha,r=e.coverage.waveStoryIds.indexOf(e.storyId);if(r<0||e.coverage.waveCommitShas[r]!==e.headSha)return s("direct-yolo-wave-coverage-invalid");if(await u(t.projectRoot,["rev-parse","HEAD"])!==o||await u(t.projectRoot,["rev-parse",`refs/heads/${t.executionBranch}`])!==o||!await B(t.projectRoot,["merge-base","--is-ancestor",e.headSha,o]))return s("direct-yolo-wave-head-raced");const i=await C(t.projectRoot,{required:!0}),n=p(i.stories[e.storyId]?.checkpoint);if(n){if(n.headSha!==e.headSha)return s("direct-yolo-checkpoint-conflict");const k=e.authorities.get(String(n.graphRevision));return await me(t.projectRoot,n,e.storyId,t.epicId,t.executionBranch,k??null,t.authorizedWriteSet)?(await ce(t.projectRoot,e.storyId).catch(()=>{}),{ok:!0,value:n}):s("direct-yolo-replay-invalid")}const d=await Ve(t,e.storyId,e.headSha);if(!d.ok)return s(d.reasonCode);const{baseSha:c,bundleDigest:f,graphRevision:a,claimRevision:l,idempotencyKey:g}=d.value,w=r===0?void 0:e.coverage.waveCommitShas[r-1];if(w!==void 0&&c!==w)return s("direct-yolo-wave-chain-invalid");const h=e.authorities.get(a),v=ze(h);if(!h||!v||v.executionHeadSha!==o||v.graphRevision!==a)return s("direct-yolo-wave-qa-unbound");const R=await Ie({projectRoot:t.projectRoot,storyId:e.storyId,epicId:t.epicId,executionBranch:t.executionBranch,baseSha:c,headSha:e.headSha,bundleDigest:f,graphRevision:a,claimRevision:l,idempotencyKey:g,qaExecution:{contract:"P205-CI-02",command:Te,manifestDigest:v.manifestDigest,gateIds:v.gateIds,resultDigest:v.resultDigest,transientAuthority:h},physicalLockOwnerDigest:pe(e.physicalLock.owner),nowIso:N(e.nowIso),legacyReceiptRef:void 0,rootMemoryEffect:t.rootMemoryEffect,extraReceiptRefs:[At(e.coverage)]});return await Se({projectRoot:t.projectRoot,checkpoint:R,remote:e.remote,expectedRevision:i.revision,expectedLease:e.expectedLease,expectedGraphRevision:t.graphRevision,expectedCheckpointGraphRevision:a,physicalLockPath:e.physicalLock.path,physicalLockOwner:e.physicalLock.owner,transientAuthority:h,authorizedWriteSet:t.authorizedWriteSet,expectedHeadSha:o,keepLease:!0})?(await ce(t.projectRoot,e.storyId).catch(()=>{}),{ok:!0,value:R}):s("direct-yolo-checkpoint-persist-failed")}catch(t){return s(X(t,"direct-yolo-wave-persist-failed"))}}async function Re(e,t){if(!/^[A-Za-z][A-Za-z0-9_-]*\.[A-Za-z0-9._-]+$/.test(t))throw new Error("direct-yolo-story-id-invalid");const o=O(e),r=p(JSON.parse(await q(G(o,".neocortex/state.json"),"utf8"))),i=await C(o,{required:!0}),n=le(r,i),d=p(n.stories),c=p(n.epics),f=p(d?.[t]),a=String(f?.epic_id??t.split(".")[0]),l=p(c?.[a]),g=String(l?.execution_branch??""),w=String(l?.origin_branch??""),h=String(l?.graph_revision??""),v=Array.isArray(f?.files_to_modify)?f.files_to_modify:[],R=It(f).filter(Pt),b=[...v,...R],k=b.length>0?Pe(t,b):void 0,D=k?.ok?k.scopes:[];if(!f)throw new Error("direct-yolo-story-state-missing");if(R.length>0&&D.length>Rt)throw new Error("direct-yolo-write-set-too-large");if(l?.branch_mode!=="epic")throw new Error("direct-yolo-branch-mode-invalid");if(!Q(g)||!await B(o,["check-ref-format","--branch",g]))throw new Error("direct-yolo-execution-branch-invalid");if(!Q(w)||!await B(o,["check-ref-format","--branch",w]))throw new Error("direct-yolo-origin-branch-invalid");if(!/^[a-f0-9]{64}$/.test(h))throw new Error("direct-yolo-graph-revision-invalid");const j=await st({projectRoot:o,storyId:t,graphRevision:h,executionBranch:g,childPaths:D});return{projectRoot:o,storyId:t,story:f,epicId:a,executionBranch:g,originBranch:w,graphRevision:h,authorizedWriteSet:D,rootMemoryEffect:j}}async function V(e,t){const o=await Re(e,t);if(await u(o.projectRoot,["symbolic-ref","--quiet","--short","HEAD"])!==o.executionBranch)throw new Error("direct-yolo-current-branch-mismatch");return o}async function Ie(e){const t=e.nowIso,o=await _(e.projectRoot,["show","--no-patch","--format=%H%n%P%n%B",e.headSha]),r=P(await _(e.projectRoot,["diff-tree","--no-commit-id","--name-only","-r","-z",e.headSha])),i=pt({storyId:e.storyId,baseSha:e.baseSha,headSha:e.headSha,bundleDigest:e.bundleDigest,graphRevision:e.graphRevision,commitBody:o,changedPaths:r}),n=yt({gitEvidenceDigest:i,headSha:e.headSha,graphRevision:e.graphRevision,manifestDigest:e.qaExecution.manifestDigest,gateIds:e.qaExecution.gateIds,resultDigest:e.qaExecution.resultDigest}),d=`story-qa:${n}`,c=Object.freeze({schemaVersion:1,kind:"story_qa_evidence",producer:"local-yolo-tdd",evidenceVersion:"p205-execution-v2",storyId:e.storyId,epicId:e.epicId,baseSha:e.baseSha,headSha:e.headSha,bundleDigest:e.bundleDigest,graphRevision:e.graphRevision,contract:e.qaExecution.contract,command:e.qaExecution.command,manifestDigest:e.qaExecution.manifestDigest,gateIds:e.qaExecution.gateIds,resultDigest:e.qaExecution.resultDigest,sourceEvidenceDigest:n,verdict:"passed",checkedAt:t,receiptRef:d}),f=oe(e.projectRoot,e.storyId,e.headSha);if(f?.verdict!=="approved")throw new Error("direct-yolo-review-artifact-not-approved");const a=A(["root-commit-range-review-v2",e.storyId,e.baseSha,e.headSha,e.bundleDigest,e.graphRevision,d,A(o),[...r].sort().join(","),f.digest].join("\0")),l=`story-review:${a}`,g=Object.freeze({schemaVersion:1,kind:"story_review_evidence",producer:"root-commit-range-review",storyId:e.storyId,epicId:e.epicId,baseSha:e.baseSha,headSha:e.headSha,bundleDigest:e.bundleDigest,graphRevision:e.graphRevision,sourceEvidenceDigest:a,reviewArtifactDigest:f.digest,qaReceiptRef:d,verdict:"approved",reviewedAt:t,receiptRef:l}),w=[`.neocortex/stories/${e.storyId}/qa-gate-result.json`,`.neocortex/stories/${e.storyId}/validation-evidence.md`,d,l,...e.physicalLockOwnerDigest?[`physical-lock-owner:${e.physicalLockOwnerDigest}`]:[],...e.legacyReceiptRef?[e.legacyReceiptRef]:[],...e.extraReceiptRefs??[]];return Object.freeze({schemaVersion:1,storyId:e.storyId,epicId:e.epicId,branch:e.executionBranch,baseSha:e.baseSha,headSha:e.headSha,commits:Object.freeze([e.headSha]),idempotencyKey:e.idempotencyKey,bundleDigest:e.bundleDigest,graphRevision:e.graphRevision,claimRevision:e.claimRevision,receiptRefs:Object.freeze(w),qaVerdict:"passed",reviewVerdict:"approved",qaReceipt:c,reviewReceipt:g,recordedAt:t,...e.rootMemoryEffect?{rootMemoryEffect:e.rootMemoryEffect}:{}})}async function Se(e){const{projectRoot:t,checkpoint:o,remote:r}=e;let i=!1;return await L(t,n=>{const d=M(n,o.epicId);if(e.expectedLease){const l=p(d.branch_lease);if(!je(l,e.expectedLease))throw new Error("direct-yolo-runtime-revision-conflict");if(Date.parse(String(l?.expiresAt))<=Date.now())throw new Error("direct-yolo-writer-lease-expired");if(d.graph_revision!==e.expectedGraphRevision||o.graphRevision!==(e.expectedCheckpointGraphRevision??e.expectedGraphRevision))throw new Error("direct-yolo-graph-revision-raced")}const c=ye(n,o.storyId),f=p(c.checkpoint);if(f&&f.headSha!==o.headSha){i=!0;return}c.checkpoint=o,c.status="done",c.last_step=Ge;const a=Array.isArray(c.steps_completed)?c.steps_completed.filter(l=>typeof l=="string"):[];c.steps_completed=[...new Set([...a,Dt,Ge])],e.keepLease||(d.branch_lease=null)},{expectedRevision:e.expectedRevision,preCommit:async()=>{if(i)throw new Error("direct-yolo-checkpoint-conflict");const n=e.expectedHeadSha??o.headSha;if(await u(t,["symbolic-ref","--quiet","--short","HEAD"])!==o.branch||await u(t,["rev-parse","HEAD"])!==n||await u(t,["rev-parse",`refs/heads/${o.branch}`])!==n||!await B(t,["merge-base","--is-ancestor",o.headSha,n]))throw new Error("direct-yolo-checkpoint-head-raced");if(!await me(t,o,o.storyId,o.epicId,o.branch,e.transientAuthority,e.authorizedWriteSet))throw new Error("direct-yolo-checkpoint-physical-invalid");if(e.physicalLockPath&&e.physicalLockOwner&&!await ne(e.physicalLockPath,e.physicalLockOwner))throw new Error("direct-yolo-integration-lock-raced");if(r&&!(e.remotePolicy==="ancestor-recovery"?await Je(t,r,o.branch,o.headSha):await _e(t,r,o.branch,n)))throw new Error("direct-yolo-checkpoint-remote-raced")}}),!i}async function Je(e,t,o,r){const i=te(t),n=(await u(e,["ls-remote","--heads",i,`refs/heads/${o}`])).split(/\s+/)[0];return!!(n&&await B(e,["merge-base","--is-ancestor",r,n]))}function xe(e){return A(["direct-yolo-commit-v1",e.storyId,e.epicId,e.executionBranch,e.baseSha,e.bundleDigest,e.graphRevision,e.claimRevision].join("\0"))}const Bt=["schemaVersion","kind","storyId","epicId","executionBranch","graphRevision","preparedBase","bundleDigest","claimRevision","idempotencyKey","issuedAt"];async function be(e,t){const o=await Me(e),r=await Ne(o,"commit-plans"),i=`direct-${A(t)}.json`;return{parent:r,name:i,path:G(r,i)}}async function _t(e,t){const o=await be(e,t.storyId);await We(o.parent,o.name,`${JSON.stringify(t,null,2)}
|
|
2
|
-
`),await
|
|
3
|
-
`),await ie(o.path,o.parent)}async function J(e,t){try{const o=await Ue(e,t);await ie(o.path,o.parent);const r=JSON.parse(await q(o.path,"utf8")),i=r.state==="issued"?["schemaVersion","kind","state","storyId","fromSessionId","token","tokenDigest","bundleDigest","claimRevision","grantDigest","expiresAt"]:r.state==="consuming"?["schemaVersion","kind","state","storyId","fromSessionId","token","tokenDigest","bundleDigest","claimRevision","grantDigest","expiresAt","consumedBySessionId","consumeStartedAt"]:["schemaVersion","kind","state","storyId","fromSessionId","tokenDigest","bundleDigest","claimRevision","grantDigest","expiresAt","consumedBySessionId","consumedAt"];return Object.keys(r).sort().join("\0")!==[...i].sort().join("\0")||r.schemaVersion!==1||r.kind!=="direct-yolo-setup-handoff-token"||r.state!=="issued"&&r.state!=="consuming"&&r.state!=="consumed"||r.storyId!==t||typeof r.fromSessionId!="string"||!/^setup-[a-f0-9]{64}$/.test(r.fromSessionId)||![r.tokenDigest,r.bundleDigest,r.claimRevision,r.grantDigest].every(n=>typeof n=="string"&&/^[a-f0-9]{64}$/.test(n))||typeof r.expiresAt!="string"||!Number.isFinite(Date.parse(r.expiresAt))||(r.state==="issued"||r.state==="consuming")&&(typeof r.token!="string"||!/^[A-Za-z0-9_-]{32,256}$/.test(r.token))||r.state==="consuming"&&(typeof r.consumedBySessionId!="string"||!/^[a-f0-9]{64}$/.test(r.consumedBySessionId)||typeof r.consumeStartedAt!="string"||!Number.isFinite(Date.parse(r.consumeStartedAt)))||r.state==="consumed"&&(typeof r.consumedBySessionId!="string"||!/^[a-f0-9]{64}$/.test(r.consumedBySessionId)||typeof r.consumedAt!="string"||!Number.isFinite(Date.parse(r.consumedAt)))?void 0:r}catch{return}}async function Ct(e,t,o,r,i){const n=await J(e,t);if(!(!n||n.state==="consumed"||!n.token||n.bundleDigest!==o||n.claimRevision!==r||Date.parse(n.expiresAt)<=Date.parse(i)||A(n.token)!==n.tokenDigest))return{sessionId:n.fromSessionId,token:n.token}}async function Ht(e,t,o,r,i,n){const d=await J(e,t);if(!d||d.state==="consumed"||d.fromSessionId!==o||d.token!==r||d.tokenDigest!==A(r))throw new Error("direct-yolo-setup-handoff-consume-invalid");if(d.state==="consuming"){if(d.consumedBySessionId!==i)throw new Error("direct-yolo-setup-handoff-consume-raced");return}await De(e,{...d,state:"consuming",consumedBySessionId:i,consumeStartedAt:n})}async function Ot(e,t,o,r,i,n,d,c,f){const a=await J(e,o);if(a?.state==="consumed"&&a.fromSessionId===r&&a.consumedBySessionId===c)return;const l=await C(e,{required:!0}),g=p(l.epics[t]?.branch_lease),w=p(g?.handoffConsumption);if(!a||a.state!=="consuming"||a.fromSessionId!==r||a.token!==i||a.tokenDigest!==A(i)||a.bundleDigest!==n||a.claimRevision!==d||a.consumedBySessionId!==c||g?.ownerStoryId!==o||g.sessionId!==c||w?.kind!=="direct-yolo-setup-handoff-consumption"||w.state!=="consumed"||w.fromSessionId!==r||w.tokenDigest!==a.tokenDigest||w.bundleDigest!==n||w.claimRevision!==d||w.consumedBySessionId!==c)throw new Error("direct-yolo-setup-handoff-consume-invalid");try{await De(e,{schemaVersion:1,kind:a.kind,state:"consumed",storyId:o,fromSessionId:r,tokenDigest:a.tokenDigest,bundleDigest:a.bundleDigest,claimRevision:a.claimRevision,grantDigest:a.grantDigest,expiresAt:a.expiresAt,consumedBySessionId:c,consumedAt:f})}catch{throw new Error("direct-yolo-setup-handoff-consume-persist-failed")}}function Lt(e){const t=p(e.current?.handoffGrant),o=e.handoff?.token,r=typeof o=="string"&&/^[A-Za-z0-9_-]{32,256}$/.test(o)?A(o):void 0;return!!(t&&r&&e.handoff&&e.handoff.sessionId===e.current?.sessionId&&t.schemaVersion===1&&t.kind==="direct-yolo-setup-handoff"&&t.storyId===e.storyId&&t.fromSessionId===e.current?.sessionId&&t.bundleDigest===e.bundleDigest&&t.claimRevision===e.claimRevision&&typeof t.expiresAt=="string"&&Date.parse(t.expiresAt)>Date.parse(e.nowIso)&&typeof t.tokenDigest=="string"&&/^[a-f0-9]{64}$/.test(t.tokenDigest)&&$t(t.tokenDigest,r))}function $t(e,t){const o=Buffer.from(e,"hex"),r=Buffer.from(t,"hex");return o.length===32&&r.length===32&&at(o,r)}function je(e,t){return!!(e&&["schemaVersion","ownerStoryId","sessionId","idempotencyKey","acquiredAt","expiresAt"].every(o=>e[o]===t[o]))}async function Ee(e,t,o){await L(e,r=>{const i=M(r,t),n=p(i.branch_lease);je(n,o)&&(i.branch_lease=null)})}async function qt(e,t){const o=await C(e.projectRoot,{required:!0}),r=p(o.epics[e.epicId]?.branch_lease);if(!r||r.ownerStoryId!==t||!Qe(r.sessionId)||!Qe(r.idempotencyKey)||!Number.isFinite(Date.parse(String(r.acquiredAt)))||!Number.isFinite(Date.parse(String(r.expiresAt))))return;const i=await F(e.projectRoot,{kind:"direct",storyId:t,sessionId:String(r.sessionId),idempotencyKey:String(r.idempotencyKey),createdAt:String(r.acquiredAt),expiresAt:String(r.expiresAt),persistent:!0});if(!i.ok)return;await Y(i.path,i.owner)&&await Ee(e.projectRoot,e.epicId,r)}async function Ae(e,t,o,r){const i=await wt(t,{headSha:o,graphRevision:r,nowIso:e.nowIso});await e.qaRunner?.({projectRoot:t,storyId:e.storyId,headSha:o});const n=ze(i);if(!n)throw new Error("p205-transient-authority-invalid");return{contract:"P205-CI-02",command:Te,manifestDigest:n.manifestDigest,gateIds:n.gateIds,resultDigest:n.resultDigest,transientAuthority:i}}async function Be(e,t,o,r){return await u(e,["rev-parse","HEAD"])!==o||await u(e,["symbolic-ref","--quiet","--short","HEAD"])!==t||!await B(e,["diff","--cached","--quiet"])?!1:B(e,["diff","--quiet","HEAD","--",...r])}async function _e(e,t,o,r){const i=te(t);return(await u(e,["ls-remote","--heads",i,`refs/heads/${o}`])).split(/\s+/)[0]===r}function Z(e,t,o,r){if(e.length===0||e.some(d=>!Ce(d)))return{ok:!1,reasonCode:"direct-yolo-write-set-invalid"};const i=t.length>0?Pe(o,t):void 0;return i?.ok?[".neocortex/state.json",`docs/stories/${o}.story.md`,`.neocortex/stories/${o}/qa-gate-result.json`,`.neocortex/stories/${o}/validation-evidence.md`,`.neocortex/stories/${o}/review.md`].every(d=>e.includes(d))?r&&(r.storyId!==o||r.childClaimRevision!==A([...i.scopes].sort().join("\0")))?{ok:!1,reasonCode:"direct-yolo-root-memory-claim-mismatch"}:e.some(d=>!ut(i.scopes,d)&&!r?.files.some(c=>c.path===d))?{ok:!1,reasonCode:"direct-yolo-write-set-unauthorized"}:{ok:!0}:{ok:!1,reasonCode:"direct-yolo-write-set-invalid"}:{ok:!1,reasonCode:"direct-yolo-write-set-invalid"}}function U(e){return Object.keys(e).filter(t=>t!=="write_set_extension")}function Pt(e){return typeof e!="string"||e.length>512||!Ce(e)||!lt(e).ok||/^(?:\.neocortex|\.claude|\.git[^/]*)(?:\/|$)/i.test(e)||/^docs\/stories(?:\/|$)/i.test(e)?!1:!e.split("/")[0].includes("*")}function Ce(e){return e.length>0&&e.length<=1024&&!e.startsWith("/")&&!e.includes("\\")&&!e.split("/").includes("..")&&!e.startsWith(".git/")&&!e.includes("\0")}function Qe(e){return typeof e=="string"&&e.length>0&&e.length<=512&&/^[A-Za-z0-9._:@/+\-=]+$/.test(e)}function Q(e){return e.length>0&&e.length<=240&&!e.startsWith("-")&&!/[\s~^:?*[\\]/.test(e)&&!e.includes("..")}function te(e){if(!/^[A-Za-z0-9._-]{1,128}$/.test(e))throw new Error("direct-yolo-remote-invalid");return e}function A(e){return nt("sha256").update(e).digest("hex")}function P(e){return e.split("\0").filter(Boolean)}function N(e){return e&&Number.isFinite(Date.parse(e))?new Date(Date.parse(e)).toISOString():new Date().toISOString()}function p(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:void 0}function Nt(e,t,o,r,i){const n=p(e.expectedLease),d=n?.sessionId,c=Date.parse(String(n?.expiresAt??""));return e.schemaVersion===1&&Number.isSafeInteger(e.expectedRuntimeRevision)&&e.expectedRuntimeRevision===t&&!!o&&JSON.stringify(o)===JSON.stringify(n)&&n?.schemaVersion===1&&n.ownerStoryId===r&&typeof d=="string"&&/^setup-[a-f0-9]{64}$/.test(d)&&n.idempotencyKey===d&&Number.isFinite(c)&&c<=i}async function zt(e,t){let o=await u(e,["symbolic-ref","--quiet","--short","HEAD"]);if(o===t.executionBranch){if(await u(e,["rev-parse","HEAD"])!==t.originHead||await z(e)!==t.checkoutBefore)return;await u(e,["switch",t.originBranch]),o=t.originBranch}if(o!==t.originBranch||await u(e,["rev-parse","HEAD"])!==t.originHead||await z(e)!==t.checkoutBefore||t.executionHead===t.originHead||!await B(e,["show-ref","--verify","--quiet",t.executionRef]))return;await u(e,["rev-parse",t.executionRef])===t.originHead&&await u(e,["update-ref",t.executionRef,t.executionHead,t.originHead])}const Tt=["capturedAt","capturedFromCurrentCheckout","executionBranch","originBranch","originHeadSha","schemaVersion"],Mt=["capturedAt","capturedFrom","executionBranch","originBranch","originHeadSha","schemaVersion"];function K(e,t,o){const r=p(e);if(!r||r.originBranch!==o||r.executionBranch!==t||typeof r.originHeadSha!="string"||!/^[a-f0-9]{40,64}$/.test(r.originHeadSha)||typeof r.capturedAt!="string"||!Number.isFinite(Date.parse(r.capturedAt)))return;const i=Object.keys(r).sort().join("\0");if(r.schemaVersion===1)return r.capturedFromCurrentCheckout!==!0||i!==Tt.join("\0")?void 0:r;if(r.schemaVersion===2)return r.capturedFrom!=="current-checkout"&&r.capturedFrom!=="branch-ref"||i!==Mt.join("\0")?void 0:r}async function Wt(e,t,o){const r=`refs/heads/${e.originBranch}`;if(!await B(e.projectRoot,["show-ref","--verify","--quiet",r]))return s("direct-yolo-origin-ref-missing","fetch-origin-branch");const i=await u(e.projectRoot,["rev-parse","--verify","--quiet",`${r}^{commit}`]).catch(()=>"");if(!/^[a-f0-9]{40,64}$/.test(i))return s("direct-yolo-origin-ref-missing","fetch-origin-branch");if((await re(e.projectRoot)).some(f=>f.branch===e.executionBranch&&O(f.path)!==e.projectRoot))return s("direct-yolo-execution-branch-checked-out-elsewhere");const d=`refs/heads/${e.executionBranch}`;if(await u(e.projectRoot,["rev-parse","--verify","--quiet",d]).catch(()=>"")!==t)return s("direct-yolo-setup-physical-state-raced");const c=await He(e.projectRoot,["merge-base","--is-ancestor",i,t]);return c===1?s("direct-yolo-origin-not-ancestor","checkout-origin-or-rebase"):c!==0?s("direct-yolo-origin-ancestry-unverifiable"):{ok:!0,value:{originRef:r,binding:{schemaVersion:2,originBranch:e.originBranch,originHeadSha:i,executionBranch:e.executionBranch,capturedFrom:"branch-ref",capturedAt:o}}}}const Xe=3e4,Gt=3,Vt="ssh -o BatchMode=yes -o ConnectTimeout=15 -o ServerAliveInterval=15 -o ServerAliveCountMax=2";class se extends Error{}function Kt(e,t=Xe){return{timeout:t,killSignal:"SIGKILL",env:{...e,GIT_TERMINAL_PROMPT:"0",GCM_INTERACTIVE:"never",GIT_HTTP_LOW_SPEED_LIMIT:"1000",GIT_HTTP_LOW_SPEED_TIME:"30",...e.GIT_SSH_COMMAND?{}:{GIT_SSH_COMMAND:Vt}}}}async function Ft(e){if(!Q(e.originBranch))return{ok:!1,reasonCode:"origin-binding-start-fetch-unavailable"};try{return await ee("git",["fetch","--no-tags","origin",`refs/heads/${e.originBranch}:refs/remotes/origin/${e.originBranch}`],{cwd:O(e.projectRoot),maxBuffer:1024*1024,encoding:"utf8",...Kt(process.env,e.fetchTimeoutMs??Xe)}),{ok:!0}}catch(t){const o=String(t.stderr??"");return{ok:!1,reasonCode:/non-fast-forward|\[rejected\]/.test(o)?"origin-binding-start-fetch-non-fast-forward":"origin-binding-start-fetch-unavailable"}}}const Yt=new Set(["done","completed","complete","closed","cancelled","canceled","archived","terminal"]);async function br(e,t){const o=Object.freeze({exists:!1,mode:"not-epic",terminal:!1,bound:!1});try{const r=O(e),i=p(JSON.parse(await q(G(r,".neocortex/state.json"),"utf8")));if(!i)return o;const n=await C(r),d=le(i,n),c=p(p(d.epics)?.[t]);if(!c)return o;const f=tt(d,t,c),a=typeof c.execution_branch=="string"&&c.execution_branch.length>0?c.execution_branch:`epic/${t}`,l=await et(r,c,i),g=p(n.epics[t])?.origin_binding??c.origin_binding;return Object.freeze({exists:!0,mode:f,terminal:Yt.has(String(c.status??"").toLowerCase()),bound:!!K(g,a,l),executionBranch:a,originBranch:l})}catch{return o}}async function et(e,t,o){if(typeof t.origin_branch=="string"&&t.origin_branch.length>0)return t.origin_branch;const r=p(o.config)?.default_branch;if(r!=null&&String(r).length>0)return String(r);const i=await u(e,["symbolic-ref","--quiet","--short","refs/remotes/origin/HEAD"]).catch(()=>"");if(i.startsWith("origin/")&&i.length>7)return i.slice(7);const n=[];for(const d of["main","master"])await B(e,["rev-parse","--verify","--quiet",`refs/heads/${d}^{commit}`])&&await B(e,["rev-parse","--verify","--quiet",`refs/remotes/origin/${d}^{commit}`])&&n.push(d);return n.length===1?n[0]:""}function tt(e,t,o){if(o.branch_mode==="epic")return"recorded-epic";if(o.branch_mode!==void 0&&o.branch_mode!==null)return"not-epic";const r=p(e.stories)??{},n=ht(t,Array.isArray(o.stories)?o.stories:void 0,Object.keys(r)).flatMap(c=>{const f=p(r[c]);return f?[{...f,id:c}]:[]}),d=ft({...o,id:t},n);return d.mode==="epic"&&(d.source==="new-epic-default"||d.source==="epic-boundary")?"resolved-epic":"not-epic"}function rt(e,t){if(!e)return!1;const o=Date.parse(String(e.expiresAt));return!(Number.isFinite(o)&&o<=t)}async function kr(e){const t=N(e.nowIso),o=Date.parse(t),r=(c,f={})=>Object.freeze({schemaVersion:1,kind:"origin-binding-start",epicId:e.epicId,...f,outcome:"refused",reasonCode:c,executionRefCreated:!1,capturedAt:t});if(!/^[A-Za-z][A-Za-z0-9_-]{0,63}$/.test(e.epicId))return r("origin-binding-start-target-ambiguous");const i=O(e.projectRoot);let n=e.originFetch,d="origin-binding-start-raced";for(let c=0;c<Gt;c+=1){let f,a={};try{const l=p(JSON.parse(await q(G(i,".neocortex/state.json"),"utf8")));if(!l)return r("origin-binding-start-state-invalid");const g=await C(i),w=le(l,g),h=p(p(w.epics)?.[e.epicId]);if(!h)return r("origin-binding-start-target-ambiguous");if(tt(w,e.epicId,h)==="not-epic")return r("origin-binding-start-branch-mode-not-epic");const v=typeof h.execution_branch=="string"&&h.execution_branch.length>0?h.execution_branch:`epic/${e.epicId}`,R=await et(i,h,l);if(a={executionBranch:v,originBranch:R},!Q(v)||!Q(R)||v===R||!await B(i,["check-ref-format","--branch",v])||!await B(i,["check-ref-format","--branch",R]))return r("origin-binding-start-branch-invalid",a);const b=p(g.epics[e.epicId]),k=b?.origin_binding??h.origin_binding;if(k!=null){const E=K(k,v,R);return E?Object.freeze({schemaVersion:1,kind:"origin-binding-start",epicId:e.epicId,...a,originHeadSha:E.originHeadSha,outcome:"already-bound",executionRefCreated:!1,capturedAt:t}):r("origin-binding-start-binding-invalid",a)}if(rt(p(b?.branch_lease??h.branch_lease),o))return r("origin-binding-start-lease-inconsistent",a);if(n??=await Ft({projectRoot:i,originBranch:R,...e.fetchTimeoutMs?{fetchTimeoutMs:e.fetchTimeoutMs}:{}}),!n.ok)return r(n.reasonCode,a);const D=`refs/remotes/origin/${R}`,j=`refs/heads/${R}`,m=await u(i,["rev-parse","--verify","--quiet",`${j}^{commit}`]).catch(()=>""),S=await u(i,["rev-parse","--verify","--quiet",`${D}^{commit}`]).catch(()=>"");if(!/^[a-f0-9]{40,64}$/.test(m)||m!==S)return r("origin-binding-start-origin-stale",a);if((await re(i)).some(E=>E.branch===v&&O(E.path)!==i))return r("direct-yolo-execution-branch-checked-out-elsewhere",a);const y=`refs/heads/${v}`,x=await u(i,["rev-parse","--verify","--quiet",`${y}^{commit}`]).catch(()=>"");if(x){const E=await He(i,["merge-base","--is-ancestor",m,x]);if(E===1)return r("direct-yolo-origin-not-ancestor",a);if(E!==0)return r("direct-yolo-origin-ancestry-unverifiable",a)}const $={schemaVersion:2,originBranch:R,originHeadSha:m,executionBranch:v,capturedFrom:"branch-ref",capturedAt:t};return await L(i,E=>{const H=M(E,e.epicId);if(H.origin_binding!==void 0&&H.origin_binding!==null)throw new se("origin-binding-start-raced");if(rt(p(H.branch_lease),o))throw new se("origin-binding-start-lease-inconsistent");H.origin_binding=$},{expectedRevision:g.revision,preCommit:async()=>{const E=await u(i,["rev-parse","--verify","--quiet",`${j}^{commit}`]).catch(()=>""),H=await u(i,["rev-parse","--verify","--quiet",`${D}^{commit}`]).catch(()=>""),T=await u(i,["rev-parse","--verify","--quiet",`${y}^{commit}`]).catch(()=>"");if(E!==m||H!==m||T!==x)throw new se("origin-binding-start-raced");x||(await u(i,["update-ref",y,m,""]),f={ref:y,sha:m})}}),Object.freeze({schemaVersion:1,kind:"origin-binding-start",epicId:e.epicId,...a,originHeadSha:m,outcome:"captured",executionRefCreated:f!==void 0,capturedAt:t})}catch(l){if(f&&await u(i,["update-ref","-d",f.ref,f.sha]).catch(()=>{}),l instanceof Error&&l.message==="git-lifecycle-runtime-revision-conflict"){d="origin-binding-start-raced";continue}return l instanceof se?r(l.message,a):r("origin-binding-start-failed",a)}}return r(d)}function de(e,t,o,r){return Object.freeze({schemaVersion:1,kind:"direct-yolo-setup-receipt",storyId:e.storyId,epicId:e.epicId,executionBranch:e.executionBranch,originBranch:e.originBranch,originHeadSha:t.originHeadSha,leaseExpiresAt:o,reused:r,publicSafe:!0})}async function z(e){const t=P(await _(e,["ls-files","--others","--exclude-standard","-z"])).sort(),o=await Promise.all(t.map(async r=>{if(!Ce(r))throw new Error("direct-yolo-checkout-payload-invalid");return`${r}\0${await u(e,["hash-object","--no-filters","--",r])}`}));return A([await _(e,["diff","--cached","--binary","--full-index"]),await _(e,["diff","--binary","--full-index"]),await _(e,["status","--porcelain=v1","-z","--untracked-files=all"]),...o].join("\0"))}async function Dr(e){const t=O(e),o=await u(t,["rev-parse","HEAD"]),r=await u(t,["symbolic-ref","--quiet","--short","HEAD"]),i=await z(t);if(await u(t,["rev-parse","HEAD"])!==o||await u(t,["symbolic-ref","--quiet","--short","HEAD"])!==r)throw new Error("direct-yolo-checkout-observation-raced");return Object.freeze({headSha:o,branch:r,payloadDigest:i})}async function re(e){const t=[];let o;for(const r of(await _(e,["worktree","list","--porcelain","-z"])).split("\0"))r.startsWith("worktree ")?(o={path:r.slice(9)},t.push(o)):o&&r.startsWith("branch refs/heads/")&&(o.branch=r.slice(18));return t}function X(e,t){return e instanceof Error&&e.message==="git-lifecycle-runtime-revision-conflict"?"direct-yolo-runtime-revision-conflict":e instanceof Error&&ge(e.message)||e instanceof Error&&/^direct-yolo-[a-z0-9-]+(?::[a-z0-9-]+)?$/.test(e.message)?e.message:t}function s(e,t){return t?{ok:!1,reasonCode:e,hint:t}:{ok:!1,reasonCode:e}}async function He(e,t){try{return await ee("git",[...t],{cwd:e,maxBuffer:8*1024*1024}),0}catch(o){const r=o.code;return typeof r=="number"?r:-1}}async function u(e,t){return String((await ee("git",[...t],{cwd:e,encoding:"utf8",maxBuffer:32*1024*1024})).stdout).trim()}async function _(e,t){return String((await ee("git",[...t],{cwd:e,encoding:"utf8",maxBuffer:32*1024*1024})).stdout)}async function B(e,t){try{return await ee("git",[...t],{cwd:e,maxBuffer:8*1024*1024}),!0}catch{return!1}}export{vr as DIRECT_YOLO_STORY_CHECKPOINT_LEASE_MS,Et as DIRECT_YOLO_WAVE_RECEIPT_REF_PREFIX,Xe as ORIGIN_BINDING_START_FETCH_TIMEOUT_MS,hr as acceptDirectYoloSetupCheckpoint,lr as beginDirectYoloStoryCommit,Dr as captureDirectYoloCheckoutEvidence,kr as captureEpicOriginBindingAtYoloopStart,wr as directYoloCommitIdempotencyKey,Rr as directYoloWaveQaCoverage,At as directYoloWaveReceiptRef,Ft as fetchOriginForYoloopStart,pr as finalizeDirectYoloStoryCheckpoint,Pt as isDirectYoloWriteSetExtensionScope,ur as issueDirectYoloSetupLeaseHandoff,xr as persistDirectYoloWaveStoryCheckpoint,fr as prepareDirectYoloSetup,Sr as pushDirectYoloWaveHead,br as readYoloopStartEpic,yr as recoverLegacyDirectYoloStoryCheckpoint,gr as resolveDirectYoloIntegrationAuthority,Ir as runDirectYoloWaveP205,mr as validateDirectYoloWriteSet,Kt as yoloopStartGitNetworkExecOptions};
|
|
1
|
+
import{execFile as ht}from"node:child_process";import{createHash as lt,randomBytes as Ge,timingSafeEqual as pt}from"node:crypto";import{existsSync as We}from"node:fs";import{readFile as F,realpath as ye}from"node:fs/promises";import{join as ee,resolve as L}from"node:path";import{promisify as yt}from"node:util";import{readRootMemoryEffectForCheckpoint as gt}from"../private-execution/root-memory-scope.js";import{rootMemoryEffectDigest as mt,verifyRootMemoryPhysicalWriteSet as ge}from"../private-execution/root-memory-git-evidence.js";import{resolveBranchUnit as wt,resolveEpicStoryIds as vt}from"../../../shared/dist/yoloop/branch-unit.js";import{expandStoryWriteScope as me,storyWriteSetCovers as Ve,validateStoryWriteScope as Rt}from"../../../shared/dist/yoloop/story-write-scope.js";import{acquireGitLifecyclePhysicalIntegrationLock as Y,applyGitLifecycleRuntimeOverlay as we,computeImmutableStoryQaEvidenceDigest as St,computeGitLifecyclePhysicalIntegrationLockOwnerDigest as ve,computeP205StoryQaEvidenceDigest as It,computeLegacyDirectYoloRecoveryReceiptRef as xt,ensureRuntimeEpic as z,ensureRuntimeStory as Re,ensureGitLifecyclePrivateChildDirectory as Ke,executeP205TransientAuthorities as bt,executeP205TransientAuthority as kt,isP226GateReasonCode as Se,projectP205TransientExecutionEvidence as Fe,publicStoryReviewArtifactFromBytes as Dt,publicStoryReviewArtifactFromGit as ie,LEGACY_DIRECT_YOLO_RECOVERY_COMMITS as Et,mutateGitLifecycleRuntime as $,P205_COMPLETE_COMMAND as Ye,readGitLifecycleRuntime as O,gitLifecycleRuntimeDirectory as Je,STORY_WRITE_SET_MAX_ENTRIES as jt,storyWriteSetExtensionPaths as At,assertGitLifecyclePrivateFile as ne,releaseGitLifecyclePhysicalIntegrationLock as J,releaseGitLifecyclePhysicalIntegrationLockForCheckpoint as _t,verifyGitLifecyclePhysicalIntegrationLock as ae,verifyAcceptedGitLifecycleStoryCheckpoint as Ie}from"./git-lifecycle-store.js";import{anchoredAtomicWriteFile as Ze,anchoredRemoveFile as Bt}from"./secure-filesystem-boundary.js";import{GOVERNANCE_CHECKPOINT_TRAILER_KEYS as Ct,GOVERNANCE_DIGEST_TRAILER as Ue,GOVERNANCE_REASON_CODES as ce,captureStoryGovernanceSync as Ht,detectGovernanceModeSync as Ot,governanceReceiptRefs as Lt,isGovernanceRepositoryPath as $t,readGovernanceStateSourceSync as Nt,storyReviewGovernancePath as Pt,verifyStoryGovernanceBinding as qt}from"./governance-runtime-store.js";import{parseNeocortexTrailers as Tt,trailerReasonKey as xe,trailerValue as se}from"./neocortex-trailers.js";import{StoryWorktreeManager as zt}from"./story-worktree-manager.js";import{GIT_LIFECYCLE_COMMIT_PUSH_STEP_ID as Mt,GIT_LIFECYCLE_REVIEW_PR_STEP_ID as Qe,GIT_LIFECYCLE_SETUP_BRANCH_STEP_ID as M}from"./git-lifecycle-step-ids.js";const te=yt(ht),de=3600*1e3;async function jr(e){let t,o=!1;try{const r=await fe(e.projectRoot,e.storyId);if(await be(r.projectRoot)){if(e.expiredSetupRecovery)return s("direct-yolo-expired-setup-recovery-invalid");const v=await et(r);return{ok:!0,value:tt(r,v,!1)}}const i=q(e.nowIso),n=Date.parse(i),d=await u(r.projectRoot,["symbolic-ref","--quiet","--short","HEAD"]),c=await u(r.projectRoot,["rev-parse","HEAD"]),h=await O(r.projectRoot,{required:!0}),a=m(h.epics[r.epicId]),f=m(a?.branch_lease),y=e.expiredSetupRecovery;if(y&&!rr(y,h.revision,f,e.storyId,n))return s("direct-yolo-expired-setup-recovery-invalid");const I=f&&Number.isFinite(Date.parse(String(f.expiresAt)))&&Date.parse(String(f.expiresAt))>n;if(I&&f?.ownerStoryId!==e.storyId)return s("direct-yolo-writer-active");let l=W(a?.origin_binding,r.executionBranch,r.originBranch),w;if(d===r.executionBranch){if(!l){if(a?.origin_binding!==void 0&&a?.origin_binding!==null||I)return s("direct-yolo-origin-binding-invalid");const v=await ar(r,c,i);if(!v.ok)return v;l=v.value.binding,w={originRef:v.value.originRef,originHeadSha:v.value.binding.originHeadSha}}}else{if(d!==r.originBranch)return s("direct-yolo-current-branch-mismatch");if(l&&l.originHeadSha!==c){if(!y||!await _(r.projectRoot,["merge-base","--is-ancestor",l.originHeadSha,c]))return s("direct-yolo-origin-binding-conflict");const p=`refs/heads/${r.executionBranch}`;if(!await _(r.projectRoot,["show-ref","--verify","--quiet",p]))return s("direct-yolo-execution-branch-missing");const D=await u(r.projectRoot,["rev-parse",p]);if(!await _(r.projectRoot,["merge-base","--is-ancestor",D,c]))return s("direct-yolo-execution-branch-diverged")}if(l??={schemaVersion:1,originBranch:r.originBranch,originHeadSha:c,executionBranch:r.executionBranch,capturedFromCurrentCheckout:!0,capturedAt:i},(await oe(r.projectRoot)).some(p=>p.branch===r.executionBranch&&L(p.path)!==r.projectRoot))return s("direct-yolo-execution-branch-checked-out-elsewhere");const S=await T(r.projectRoot),x=`refs/heads/${r.executionBranch}`;if(await _(r.projectRoot,["show-ref","--verify","--quiet",x])){const p=await u(r.projectRoot,["rev-parse",x]);if(p!==c){if(!await _(r.projectRoot,["merge-base","--is-ancestor",p,c]))return s("direct-yolo-execution-branch-diverged");y||await u(r.projectRoot,["update-ref",x,c,p])}y?t={checkoutBefore:S,executionRef:x,executionBranch:r.executionBranch,executionHead:p,originBranch:r.originBranch,originHead:c}:await u(r.projectRoot,["switch",r.executionBranch])}else{if(y)return s("direct-yolo-execution-branch-missing");await u(r.projectRoot,["switch","-c",r.executionBranch])}if(!t&&await T(r.projectRoot)!==S)return s("direct-yolo-checkout-payload-raced")}const g=t?.originHead??await u(r.projectRoot,["rev-parse","HEAD"]);if(!t&&await u(r.projectRoot,["symbolic-ref","--quiet","--short","HEAD"])!==r.executionBranch)return s("direct-yolo-current-branch-mismatch");if(I&&f?.ownerStoryId===e.storyId)return f.setupHeadSha!==g?s("direct-yolo-setup-lease-head-unbound"):{ok:!0,value:le(r,l,String(f.expiresAt),!0)};const j=i,R=new Date(n+3600*1e3).toISOString(),b=`setup-${Ge(32).toString("hex")}`,E=y?h:await O(r.projectRoot,{required:!0});return await $(r.projectRoot,v=>{const S=z(v,r.epicId),x=m(S.branch_lease);if(y&&JSON.stringify(x)!==JSON.stringify(y.expectedLease))throw new Error("direct-yolo-expired-setup-recovery-raced");if(x&&Date.parse(String(x.expiresAt))>n&&x.ownerStoryId!==e.storyId)throw new Error("direct-yolo-writer-active");const p=W(S.origin_binding,r.executionBranch,r.originBranch);if(S.origin_binding&&!p)throw new Error("direct-yolo-origin-binding-conflict");if(p&&JSON.stringify(p)!==JSON.stringify(l))throw new Error("direct-yolo-origin-binding-conflict");S.branch_mode="epic",S.execution_branch=r.executionBranch,S.origin_branch=r.originBranch,S.graph_revision=r.graphRevision,S.origin_binding=l,S.branch_lease={schemaVersion:1,ownerStoryId:e.storyId,sessionId:b,idempotencyKey:b,acquiredAt:j,expiresAt:R,setupHeadSha:g}},{expectedRevision:y?.expectedRuntimeRevision??E.revision,preCommit:async()=>{if(t){if((await oe(r.projectRoot)).some(S=>S.branch===r.executionBranch&&L(S.path)!==r.projectRoot)||await u(r.projectRoot,["symbolic-ref","--quiet","--short","HEAD"])!==r.originBranch||await u(r.projectRoot,["rev-parse","HEAD"])!==t.originHead||await T(r.projectRoot)!==t.checkoutBefore||!await _(r.projectRoot,["show-ref","--verify","--quiet",t.executionRef])||await u(r.projectRoot,["rev-parse",t.executionRef])!==t.executionHead)throw new Error("direct-yolo-expired-setup-recovery-raced");if(o=!0,t.executionHead!==t.originHead&&await u(r.projectRoot,["update-ref",t.executionRef,t.originHead,t.executionHead]),await u(r.projectRoot,["switch",r.executionBranch]),await T(r.projectRoot)!==t.checkoutBefore)throw new Error("direct-yolo-checkout-payload-raced")}if(await u(r.projectRoot,["symbolic-ref","--quiet","--short","HEAD"])!==r.executionBranch||await u(r.projectRoot,["rev-parse","HEAD"])!==g)throw new Error("direct-yolo-setup-physical-state-raced");if(w&&(await u(r.projectRoot,["rev-parse","--verify","--quiet",`${w.originRef}^{commit}`]).catch(()=>"")!==w.originHeadSha||await Te(r.projectRoot,["merge-base","--is-ancestor",w.originHeadSha,g])!==0))throw new Error("direct-yolo-origin-ref-raced")}}),{ok:!0,value:le(r,l,R,!1)}}catch(r){return o&&t&&await or(L(e.projectRoot),t).catch(()=>{}),s(V(r,"direct-yolo-setup-failed"))}}async function Ar(e){let t;try{const o=await fe(e.projectRoot,e.storyId);if(await be(o.projectRoot))return await Gt(o);const r=await G(e.projectRoot,e.storyId),i=q(e.nowIso),n=ee(r.projectRoot,".neocortex/state.json"),d=await F(n,"utf8"),c=await T(r.projectRoot),h=await u(r.projectRoot,["rev-parse","HEAD"]),a=`refs/heads/${r.executionBranch}`,f=await O(r.projectRoot,{required:!0}),y=m(f.epics[r.epicId]),I=W(y?.origin_binding,r.executionBranch,r.originBranch),l=m(y?.branch_lease);if(!I)return s("direct-yolo-origin-binding-invalid");if(!l||!Ce(l,e.storyId,i)||l?.sessionId!==l?.idempotencyKey)return s("direct-yolo-setup-lease-invalid");const w=await Y(r.projectRoot,{kind:"direct",storyId:e.storyId,sessionId:String(l.sessionId),idempotencyKey:String(l.idempotencyKey),expiresAt:new Date(Date.now()+300*1e3).toISOString(),persistent:!1});if(!w.ok)return s(w.reasonCode);if(t=w,h!==l.setupHeadSha||!await _(r.projectRoot,["merge-base","--is-ancestor",I.originHeadSha,h])||await u(r.projectRoot,["rev-parse",a])!==h)return s("direct-yolo-setup-head-mismatch");if((await oe(r.projectRoot)).some(S=>S.branch===r.executionBranch&&L(S.path)!==r.projectRoot))return s("direct-yolo-execution-branch-checked-out-elsewhere");const j=m(JSON.parse(d)),R=m(m(j?.stories)?.[e.storyId]),b=m(f.stories[e.storyId]);if(!R||!["backlog","ready_to_start"].includes(String(R.status))||R.steps_completed!==void 0&&(!Array.isArray(R.steps_completed)||R.steps_completed.length>0)||R.branch_name||R.checkpoint)return s("direct-yolo-setup-story-progress-conflict");const E=b?.status==="branch-ready"&&b.last_step===M&&Array.isArray(b.steps_completed)&&b.steps_completed.length===1&&b.steps_completed[0]===M&&Q(b).sort().join(",")==="last_step,status,steps_completed";if(b&&Q(b).length>0&&!E)return s("direct-yolo-setup-story-progress-conflict");const v=async()=>{if(Date.parse(String(l.expiresAt))<=(e.nowIso?Date.parse(i):Date.now())||!t||!await ae(t.path,t.owner)||await F(n,"utf8")!==d||await T(r.projectRoot)!==c||await u(r.projectRoot,["symbolic-ref","--quiet","--short","HEAD"])!==r.executionBranch||await u(r.projectRoot,["rev-parse","HEAD"])!==h||!await _(r.projectRoot,["merge-base","--is-ancestor",I.originHeadSha,h])||await u(r.projectRoot,["rev-parse",a])!==h)throw new Error("direct-yolo-setup-physical-state-raced")};return E?await v():await $(r.projectRoot,S=>{const x=m(S.epics[r.epicId]),p=Re(S,e.storyId);if(JSON.stringify(x?.branch_lease)!==JSON.stringify(l)||JSON.stringify(x?.origin_binding)!==JSON.stringify(I)||x?.graph_revision!==r.graphRevision||Q(p).length>0)throw new Error("direct-yolo-setup-runtime-raced");p.status="branch-ready",p.last_step=M,p.steps_completed=[M]},{expectedRevision:f.revision,preCommit:v}),{ok:!0,value:Object.freeze({...le(r,I,String(l.expiresAt),E),checkpointAccepted:!0,graphRevision:r.graphRevision,headSha:h})}}catch(o){return s(V(o,"direct-yolo-setup-acceptance-failed"))}finally{t&&await J(t.path,t.owner).catch(()=>{})}}async function _r(e){try{const t=await G(e.projectRoot,e.storyId),o=P(await C(t.projectRoot,["diff","--cached","--name-only","-z"])),r=U(o,t.authorizedWriteSet,e.storyId,t.rootMemoryEffect,t.governanceMode);if(!r.ok)return s(r.reasonCode);t.rootMemoryEffect&&ge(t.projectRoot,t.rootMemoryEffect,{storyId:e.storyId,executionBranch:t.executionBranch,baseSha:await u(t.projectRoot,["rev-parse","HEAD"]),headRef:":",childPaths:t.authorizedWriteSet});const i=t.governanceMode==="runtime-store"?De(t):void 0;if((i?i.review:ie(t.projectRoot,e.storyId,":"))?.verdict!=="approved")return s("direct-yolo-review-artifact-not-approved");if(P(await C(t.projectRoot,["diff","--name-only","-z"])).some(D=>o.includes(D)))return s("direct-yolo-user-overlap");const c=await C(t.projectRoot,["diff","--cached","--binary","--full-index"]);if(!c)return s("direct-yolo-staged-diff-empty");const h=A(c),a=A([...t.authorizedWriteSet].sort().join("\0")),f=q(e.nowIso),y=await O(t.projectRoot,{required:!0}),I=m(y.epics[t.epicId]?.branch_lease);if(!Ce(I,e.storyId,f))return s("direct-yolo-setup-handoff-owner-invalid");const l=String(I.sessionId),w=String(I.expiresAt),g=new Date(Math.min(Date.parse(w),Date.parse(f)+300*1e3)).toISOString(),j=await Z(t.projectRoot,e.storyId),R=j?.state==="issued"&&j.fromSessionId===l&&j.bundleDigest===h&&j.claimRevision===a&&Date.parse(j.expiresAt)>Date.parse(f),b=R?j.expiresAt:g,E=R?j.token:Ge(32).toString("base64url"),v=A(E),S=Object.freeze({schemaVersion:1,kind:"direct-yolo-setup-handoff",storyId:e.storyId,fromSessionId:l,tokenDigest:v,bundleDigest:h,claimRevision:a,expiresAt:b}),x=A(JSON.stringify(S)),p=await Y(t.projectRoot,{kind:"direct",storyId:e.storyId,sessionId:l,idempotencyKey:l,expiresAt:b,persistent:!1,createdAt:f});if(!p.ok)return s(p.reasonCode==="git-lifecycle-integration-backpressure"?"direct-yolo-integration-backpressure":"direct-yolo-integration-lock-failed");try{await He(t.projectRoot,{schemaVersion:1,kind:"direct-yolo-setup-handoff-token",state:"issued",storyId:e.storyId,fromSessionId:l,token:E,tokenDigest:v,bundleDigest:h,claimRevision:a,grantDigest:x,expiresAt:b}),await $(t.projectRoot,D=>{const k=m(z(D,t.epicId).branch_lease);if(!Ce(k,e.storyId,f)||k?.sessionId!==l||k.idempotencyKey!==l)throw new Error("direct-yolo-setup-handoff-owner-raced");k.handoffGrant=S},{expectedRevision:y.revision,preCommit:async()=>{if(!await ae(p.path,p.owner))throw new Error("direct-yolo-integration-lock-raced");const D=await Z(t.projectRoot,e.storyId);if(!D||D.state!=="issued"||D.grantDigest!==x||D.tokenDigest!==v)throw new Error("direct-yolo-setup-handoff-token-raced")}})}finally{await J(p.path,p.owner).catch(()=>{})}return{ok:!0,value:Object.freeze({schemaVersion:1,kind:"direct-yolo-setup-handoff-receipt",storyId:e.storyId,sessionId:l,bundleDigest:h,claimRevision:a,grantDigest:x,expiresAt:b,reused:R,publicSafe:!0,...i?{governance:i.receipt}:{}})}}catch(t){return s(t instanceof Error&&(/^direct-yolo-/.test(t.message)||ft.has(t.message))?t.message:"direct-yolo-setup-handoff-failed")}}async function Br(e){try{const t=await G(e.projectRoot,e.storyId),o=await u(t.projectRoot,["rev-parse","HEAD"]),r=P(await C(t.projectRoot,["diff","--cached","--name-only","-z"])),i=U(r,t.authorizedWriteSet,e.storyId,t.rootMemoryEffect,t.governanceMode);if(!i.ok)return s(i.reasonCode);t.rootMemoryEffect&&ge(t.projectRoot,t.rootMemoryEffect,{storyId:e.storyId,executionBranch:t.executionBranch,baseSha:o,headRef:":",childPaths:t.authorizedWriteSet});const n=t.governanceMode==="runtime-store"?De(t):void 0,d=n?n.review:ie(t.projectRoot,e.storyId,":");if(d?.verdict!=="approved")return s("direct-yolo-review-artifact-not-approved");if(P(await C(t.projectRoot,["diff","--name-only","-z"])).some(k=>r.includes(k)))return s("direct-yolo-user-overlap");const h=await C(t.projectRoot,["diff","--cached","--binary","--full-index"]);if(!h)return s("direct-yolo-staged-diff-empty");const a=A(h),f=A([...t.authorizedWriteSet].sort().join("\0")),y=await ot(t.projectRoot,e.storyId),I=y.state==="valid"&&y.plan.epicId===t.epicId&&y.plan.executionBranch===t.executionBranch&&y.plan.preparedBase===o&&y.plan.bundleDigest===a&&y.plan.claimRevision===f?y.plan:void 0,l=I?.graphRevision??t.graphRevision,w=_e({storyId:e.storyId,epicId:t.epicId,executionBranch:t.executionBranch,baseSha:o,bundleDigest:a,graphRevision:l,claimRevision:f}),g=q(e.nowIso),j={schemaVersion:1,kind:"direct-yolo-commit-plan",storyId:e.storyId,epicId:t.epicId,executionBranch:t.executionBranch,graphRevision:l,preparedBase:o,bundleDigest:a,claimRevision:f,idempotencyKey:w,issuedAt:I?.issuedAt??g};let R=e.setupLeaseHandoff??await Yt(t.projectRoot,e.storyId,a,f,g);const b=await O(t.projectRoot,{required:!0}),E=m(b.epics[t.epicId]?.branch_lease),v=E?.ownerStoryId===e.storyId&&E.sessionId===w&&E.idempotencyKey===w&&typeof E.expiresAt=="string"&&Date.parse(E.expiresAt)>Date.parse(g)?E:void 0;if(v&&e.setupLeaseHandoff)return s("direct-yolo-setup-handoff-replayed");const S=m(v?.handoffConsumption);if(S){const k=await Z(t.projectRoot,e.storyId);if(!k||!["consuming","consumed"].includes(k.state)||k.fromSessionId!==S.fromSessionId||k.tokenDigest!==S.tokenDigest||k.bundleDigest!==a||k.claimRevision!==f||S.bundleDigest!==a||S.claimRevision!==f||k.consumedBySessionId!==w||S.consumedBySessionId!==w)return s("direct-yolo-setup-handoff-consume-invalid");if(k.state==="consuming"){if(!k.token||A(k.token)!==k.tokenDigest)return s("direct-yolo-setup-handoff-consume-invalid");R={sessionId:k.fromSessionId,token:k.token}}}const x=v?String(v.expiresAt):new Date(Date.parse(g)+de).toISOString(),p=await Y(t.projectRoot,{kind:"direct",storyId:e.storyId,sessionId:w,idempotencyKey:w,expiresAt:x,persistent:!0,createdAt:v&&typeof v.acquiredAt=="string"?v.acquiredAt:g});if(!p.ok)return s(p.reasonCode==="git-lifecycle-integration-backpressure"?"direct-yolo-integration-backpressure":"direct-yolo-integration-lock-failed");try{R&&e.setupLeaseHandoff===void 0&&(await Jt(t.projectRoot,e.storyId,R.sessionId,R.token,w,g),await e.setupHandoffFault?.("after-consuming-persisted")),await $(t.projectRoot,k=>{const H=z(k,t.epicId),B=m(H.branch_lease),N=B&&Date.parse(String(B.expiresAt))>Date.parse(g),K=B?.ownerStoryId===e.storyId&&B.sessionId===w&&B.idempotencyKey===w,ut=B?.ownerStoryId===e.storyId&&B.sessionId===B.idempotencyKey&&typeof B.idempotencyKey=="string"&&/^setup-[a-f0-9]{64}$/.test(B.idempotencyKey),pe=N&&ut&&Ut({current:B,handoff:R,storyId:e.storyId,bundleDigest:a,claimRevision:f,nowIso:g});if(R&&N&&!K&&!pe)throw new Error("direct-yolo-setup-handoff-invalid");if(N&&!K&&!pe)throw new Error("direct-yolo-writer-active");const ze=pe?m(B?.handoffGrant):void 0,Me=ze?{schemaVersion:1,kind:"direct-yolo-setup-handoff-consumption",state:"consumed",storyId:e.storyId,fromSessionId:String(B?.sessionId),tokenDigest:String(ze.tokenDigest),bundleDigest:a,claimRevision:f,consumedBySessionId:w,consumedAt:g}:void 0;H.branch_mode="epic",H.execution_branch=t.executionBranch,H.origin_branch=t.originBranch,H.graph_revision=t.graphRevision,H.branch_lease=N&&K?B:{schemaVersion:1,ownerStoryId:e.storyId,sessionId:w,idempotencyKey:w,acquiredAt:g,expiresAt:x,...Me?{handoffConsumption:Me}:{}}},{expectedRevision:b.revision,preCommit:async()=>{if(!await ae(p.path,p.owner))throw new Error("direct-yolo-integration-lock-raced");await Ft(t.projectRoot,j)}})}catch(k){throw await J(p.path,p.owner).catch(()=>{}),k}R&&e.setupLeaseHandoff===void 0&&(await e.setupHandoffFault?.("before-consumed-persist"),await Zt(t.projectRoot,t.epicId,e.storyId,R.sessionId,R.token,a,f,w,g));const D=Object.freeze([`Neocortex-Story: ${e.storyId}`,`Neocortex-Epic: ${t.epicId}`,`Neocortex-Execution-Branch: ${t.executionBranch}`,`Neocortex-Prepared-Base: ${o}`,`Neocortex-Bundle-Digest: ${a}`,`Neocortex-Review-Artifact-Digest: ${d.digest}`,`Neocortex-Graph-Revision: ${l}`,`Neocortex-Claim-Revision: ${f}`,...t.rootMemoryEffect?[`Neocortex-Root-Memory-Effect: ${mt(t.rootMemoryEffect)}`]:[],...n?[`${Ue}: ${n.receipt.governanceDigest}`]:[]]);return{ok:!0,value:Object.freeze({schemaVersion:1,storyId:e.storyId,epicId:t.epicId,executionBranch:t.executionBranch,baseSha:o,bundleDigest:a,reviewArtifactDigest:d.digest,graphRevision:l,claimRevision:f,idempotencyKey:w,changedPaths:Object.freeze(r),trailers:D,...n?{governance:n.receipt}:{}})}}catch(t){return s(V(t,"direct-yolo-begin-failed"))}}async function Cr(e){let t,o,r;try{const i=await G(e.projectRoot,e.storyId);t=i;const n=await u(i.projectRoot,["rev-parse","HEAD"]);let d=await O(i.projectRoot,{required:!0});const c=m(d.stories[e.storyId]?.checkpoint);if(c){const x=typeof c.headSha=="string"?c.headSha:"",p=typeof c.graphRevision=="string"?c.graphRevision:"",D=/^[a-f0-9]{40,64}$/.test(x)?P(await C(i.projectRoot,["diff-tree","--no-commit-id","--name-only","-r","-z",x])):[],k=U(D,i.authorizedWriteSet,e.storyId,i.rootMemoryEffect,i.governanceMode);if(!(/^[a-f0-9]{40,64}$/.test(x)&&await _(i.projectRoot,["merge-base","--is-ancestor",x,n]))||!/^[a-f0-9]{64}$/.test(p)||!k.ok)return s("direct-yolo-replay-invalid");const B=await $e(e,i.projectRoot,n,p);if(!await Ie(i.projectRoot,c,e.storyId,i.epicId,i.executionBranch,B.transientAuthority,i.authorizedWriteSet))return s("direct-yolo-replay-invalid");if(!await Ne(i.projectRoot,i.executionBranch,n,D))return s("direct-yolo-replay-head-raced");if(e.push&&!await rt(i.projectRoot,e.remote??"origin",i.executionBranch,x))return s("direct-yolo-remote-head-mismatch");const N=Array.isArray(c.receiptRefs)?c.receiptRefs.find(K=>typeof K=="string"&&/^physical-lock-owner:[a-f0-9]{64}$/.test(K)):void 0;return N&&typeof c.idempotencyKey=="string"&&await _t(i.projectRoot,{storyId:e.storyId,idempotencyKey:c.idempotencyKey,ownerDigest:N.slice(20)}),await ue(i.projectRoot,e.storyId).catch(()=>{}),{ok:!0,value:c}}const h=n,a=await Xe(i,e.storyId,h);if(!a.ok)return s(a.reasonCode);const{baseSha:f,changedPaths:y,bundleDigest:I,graphRevision:l,claimRevision:w,idempotencyKey:g,governance:j}=a.value,R=m(d.epics[i.epicId]?.branch_lease),b=q(e.nowIso),E=R?.ownerStoryId===e.storyId&&R.idempotencyKey===g&&R.sessionId===g&&Date.parse(String(R.expiresAt))>Date.now()?R:void 0;if(R&&Date.parse(String(R.expiresAt))>Date.now()&&!E)return s("direct-yolo-writer-active");const v=E??{schemaVersion:1,ownerStoryId:e.storyId,sessionId:g,idempotencyKey:g,acquiredAt:b,expiresAt:new Date(Date.parse(b)+de).toISOString()},S=await Y(i.projectRoot,{kind:"direct",storyId:e.storyId,sessionId:g,idempotencyKey:g,expiresAt:String(v.expiresAt),persistent:!0,createdAt:String(v.acquiredAt)});if(!S.ok)return s(S.reasonCode==="git-lifecycle-integration-backpressure"?"direct-yolo-integration-backpressure":"direct-yolo-integration-lock-failed");r=S,E||(d=(await $(i.projectRoot,p=>{const D=z(p,i.epicId),k=m(D.branch_lease);if(k&&Date.parse(String(k.expiresAt))>Date.parse(b))throw new Error("direct-yolo-writer-active");if(D.graph_revision!==i.graphRevision)throw new Error("direct-yolo-graph-revision-raced");D.branch_lease=v},{expectedRevision:d.revision})).document),o=v;{const x=await $e(e,i.projectRoot,h,l);if(!await Ne(i.projectRoot,i.executionBranch,h,y))return s("direct-yolo-head-raced");if(e.push){const k=re(e.remote??"origin");if(await u(i.projectRoot,["push",k,i.executionBranch]),!await Pe(i.projectRoot,k,i.executionBranch,h))return s("direct-yolo-remote-head-mismatch")}const p=await je({projectRoot:i.projectRoot,storyId:e.storyId,epicId:i.epicId,executionBranch:i.executionBranch,baseSha:f,headSha:h,bundleDigest:I,graphRevision:l,claimRevision:w,idempotencyKey:g,qaExecution:x,physicalLockOwnerDigest:ve(S.owner),nowIso:q(e.nowIso),legacyReceiptRef:void 0,rootMemoryEffect:i.rootMemoryEffect,...j?{governance:j}:{}});return await e.beforeCheckpointPersist?.(),await Ae({projectRoot:i.projectRoot,checkpoint:p,remote:e.push?e.remote??"origin":void 0,expectedRevision:d.revision,expectedLease:v,expectedGraphRevision:i.graphRevision,expectedCheckpointGraphRevision:l,physicalLockPath:S.path,physicalLockOwner:S.owner,transientAuthority:x.transientAuthority,authorizedWriteSet:i.authorizedWriteSet})?(await ue(i.projectRoot,e.storyId).catch(()=>{}),await e.afterCheckpointPersist?.(),{ok:!0,value:p}):s("direct-yolo-checkpoint-persist-failed")}}catch(i){return s(V(i,"direct-yolo-finalize-failed"))}finally{r&&await J(r.path,r.owner).catch(()=>{}),t&&o?await Le(t.projectRoot,t.epicId,o).catch(()=>{}):t&&await Xt(t,e.storyId).catch(()=>{})}}async function Xe(e,t,o){const r=await u(e.projectRoot,["rev-parse",`${o}^`]),i=await C(e.projectRoot,["show","--no-patch","--format=%B",o]),n=P(await C(e.projectRoot,["diff-tree","--no-commit-id","--name-only","-r","-z",o])),d=U(n,e.authorizedWriteSet,t,e.rootMemoryEffect,e.governanceMode);if(!d.ok)return s(d.reasonCode);e.rootMemoryEffect&&ge(e.projectRoot,e.rootMemoryEffect,{storyId:t,executionBranch:e.executionBranch,baseSha:r,headRef:o,childPaths:e.authorizedWriteSet});const c=A([...e.authorizedWriteSet].sort().join("\0")),h=await ot(e.projectRoot,t);if(h.state==="invalid")return s("direct-yolo-commit-plan-invalid");const a=h.state==="valid"?h.plan:void 0;if(a&&(a.epicId!==e.epicId||a.executionBranch!==e.executionBranch))return s("direct-yolo-commit-plan-invalid");if(a&&a.claimRevision!==c)return s("direct-yolo-commit-plan-claim-changed");if(a&&a.preparedBase!==r)return s("direct-yolo-commit-plan-base-mismatch");const f=Tt(i,Ct);if(!f.ok)return s(`direct-yolo-trailer-duplicate:${f.key}`);const y=f.values,I=a?.graphRevision??e.graphRevision,l=c,w=[["Neocortex-Story",t],["Neocortex-Epic",e.epicId],["Neocortex-Execution-Branch",e.executionBranch],["Neocortex-Prepared-Base",r],["Neocortex-Bundle-Digest",a?.bundleDigest??""],["Neocortex-Graph-Revision",I],["Neocortex-Claim-Revision",l]];for(const[x,p]of w){const D=se(y,x);if(D===void 0)return s(`direct-yolo-trailer-missing:${xe(x)}`);if(x==="Neocortex-Bundle-Digest"&&!a){if(!/^[a-f0-9]{64}$/.test(D))return s(`direct-yolo-trailer-mismatch:${xe(x)}`);continue}if(D!==p)return s(`direct-yolo-trailer-mismatch:${xe(x)}`)}const g=se(y,"Neocortex-Bundle-Digest"),j=se(y,Ue);if(e.governanceMode!=="runtime-store"&&j!==void 0)return s(ce.MISMATCH);const R=e.governanceMode==="runtime-store"?Ee({projectRoot:e.projectRoot,epicId:e.epicId,storyId:t},j):void 0,b=R?R.review:ie(e.projectRoot,t,o);if(b?.verdict!=="approved")return s("direct-yolo-review-artifact-not-approved");const E=se(y,"Neocortex-Review-Artifact-Digest");if(E!==void 0&&E!==b.digest)return s("direct-yolo-review-artifact-digest-mismatch");const v=A(await C(e.projectRoot,["diff","--binary","--full-index",`${r}..${o}`]));if(g!==v)return s("direct-yolo-bundle-digest-mismatch");const S=_e({storyId:t,epicId:e.epicId,executionBranch:e.executionBranch,baseSha:r,bundleDigest:g,graphRevision:I,claimRevision:l});return a&&a.idempotencyKey!==S?s("direct-yolo-commit-plan-invalid"):{ok:!0,value:{baseSha:r,changedPaths:n,bundleDigest:g,graphRevision:I,claimRevision:l,idempotencyKey:S,...R?{governance:R.receipt}:{}}}}async function Hr(e){try{const t=await G(e.projectRoot,e.storyId);if(!/^[a-f0-9]{40,64}$/.test(e.commitSha))return s("direct-yolo-recovery-commit-invalid");const o=await u(t.projectRoot,["rev-parse",e.commitSha]);if(Et[e.storyId]!==o)return s("direct-yolo-recovery-not-allowlisted");if(await u(t.projectRoot,["rev-parse","HEAD"])!==o)return s("direct-yolo-recovery-head-mismatch");await u(t.projectRoot,["merge-base","--is-ancestor",o,`refs/heads/${t.executionBranch}`]);const r=await u(t.projectRoot,["rev-parse",`${o}^`]),i=await C(t.projectRoot,["diff","--binary","--full-index",`${r}..${o}`]),n=P(await C(t.projectRoot,["diff-tree","--no-commit-id","--name-only","-r","-z",o]));if(!U(n,t.authorizedWriteSet.length>0?t.authorizedWriteSet:n,e.storyId).ok)return s("direct-yolo-recovery-write-set-invalid");const c=A(i),h=A([...n].sort().join("\0")),a=A(["legacy-direct-yolo-recovery-v1",e.storyId,o].join("\0")),f=q(e.nowIso),y=new Date(Date.parse(f)+de).toISOString(),I=await O(t.projectRoot,{required:!0}),l=await Y(t.projectRoot,{kind:"direct",storyId:e.storyId,sessionId:a,idempotencyKey:a,expiresAt:y,persistent:!0,createdAt:f});if(!l.ok)return s(l.reasonCode==="git-lifecycle-integration-backpressure"?"direct-yolo-recovery-integration-backpressure":"direct-yolo-recovery-integration-lock-failed");const w={schemaVersion:1,ownerStoryId:e.storyId,sessionId:a,idempotencyKey:a,acquiredAt:f,expiresAt:y};let g=!1;try{const j=await $(t.projectRoot,x=>{const p=z(x,t.epicId),D=m(p.branch_lease);if(D&&Date.parse(String(D.expiresAt))>Date.parse(f)&&!Oe(D,w))throw new Error("direct-yolo-recovery-writer-active");if(p.graph_revision!==t.graphRevision)throw new Error("direct-yolo-recovery-graph-raced");p.branch_mode="epic",p.execution_branch=t.executionBranch,p.origin_branch=t.originBranch,p.branch_lease=w},{expectedRevision:I.revision});g=!0;const R=await $e(e,t.projectRoot,o,t.graphRevision);if(!await Ne(t.projectRoot,t.executionBranch,o,n))return s("direct-yolo-recovery-head-raced");if(e.push){const x=re(e.remote??"origin"),p=(await u(t.projectRoot,["ls-remote","--heads",x,`refs/heads/${t.executionBranch}`])).split(/\s+/)[0];if(!p||!await _(t.projectRoot,["merge-base","--is-ancestor",o,p]))return s("direct-yolo-recovery-remote-proof-missing")}const b=await je({projectRoot:t.projectRoot,storyId:e.storyId,epicId:t.epicId,executionBranch:t.executionBranch,baseSha:r,headSha:o,bundleDigest:c,graphRevision:t.graphRevision,claimRevision:h,idempotencyKey:a,qaExecution:R,physicalLockOwnerDigest:ve(l.owner),nowIso:f,legacyReceiptRef:void 0}),E=await xt(t.projectRoot,{storyId:e.storyId,epicId:t.epicId,executionBranch:t.executionBranch,baseSha:r,headSha:o,bundleDigest:c,graphRevision:t.graphRevision});if(!E)return s("direct-yolo-recovery-evidence-invalid");const v=Object.freeze({...b,receiptRefs:Object.freeze([...b.receiptRefs,E])});return await Ae({projectRoot:t.projectRoot,checkpoint:v,remote:e.push?e.remote??"origin":void 0,remotePolicy:"ancestor-recovery",expectedRevision:j.document.revision,expectedLease:w,expectedGraphRevision:t.graphRevision,physicalLockPath:l.path,physicalLockOwner:l.owner,transientAuthority:R.transientAuthority,authorizedWriteSet:t.authorizedWriteSet})?{ok:!0,value:v}:s("direct-yolo-recovery-persist-failed")}finally{await J(l.path,l.owner).catch(()=>{}),g&&await Le(t.projectRoot,t.epicId,w).catch(()=>{})}}catch(t){return s(V(t,"direct-yolo-recovery-failed"))}}async function be(e){const t=await ye(await u(e,["rev-parse","--absolute-git-dir"])),o=await ye(await u(e,["rev-parse","--path-format=absolute","--git-common-dir"]));return t!==o}async function et(e){const t=await O(e.projectRoot,{required:!0}),o=Object.values(t.storyWorktrees?.entries??{}).filter(y=>y.storyId===e.storyId&&y.epicId===e.epicId&&y.state==="active");if(o.length===0)throw new Error("direct-yolo-worktree-lease-missing");if(o.length>1)throw new Error("direct-yolo-worktree-lease-ambiguous");const r=o[0];if(r.executionBranch!==e.executionBranch)throw new Error("direct-yolo-worktree-branch-mismatch");if(await ye(await u(e.projectRoot,["rev-parse","--show-toplevel"]))!==r.worktreePath)throw new Error("direct-yolo-worktree-path-mismatch");if(await u(e.projectRoot,["symbolic-ref","--quiet","--short","HEAD"]).catch(()=>"")!==r.temporaryBranch)throw new Error("direct-yolo-worktree-branch-mismatch");const d=await new zt({projectRoot:e.projectRoot}).probe(r.leaseId);if(!d.ok||d.value.ownership!=="proven")throw new Error("direct-yolo-worktree-ownership-unproven");const c=W(m(t.epics[e.epicId])?.origin_binding,e.executionBranch,e.originBranch);if(!c)throw new Error("direct-yolo-origin-binding-invalid");const h=r.syncedSha??r.baseSha,a=await u(e.projectRoot,["rev-parse","HEAD"]),f=`refs/heads/${e.executionBranch}`;if(a!==h||!await _(e.projectRoot,["merge-base","--is-ancestor",h,f])||!await _(e.projectRoot,["merge-base","--is-ancestor",c.originHeadSha,h]))throw new Error("direct-yolo-worktree-base-divergent");if(d.value.clean!==!0||(await C(e.projectRoot,["status","--porcelain=v1","-z","--untracked-files=all"])).length>0)throw new Error("direct-yolo-worktree-dirty");return{leaseId:r.leaseId,temporaryBranch:r.temporaryBranch,authorizedBase:h,headSha:a,expiresAt:r.expiresAt,binding:c}}function tt(e,t,o){return Object.freeze({...le(e,t.binding,t.expiresAt,o),workspace:"story-worktree",temporaryBranch:t.temporaryBranch,baseSha:t.authorizedBase})}async function Gt(e){const t=await et(e),o=ke(e.projectRoot),r=m(JSON.parse(o)),i=m(m(r?.stories)?.[e.storyId]),n=await O(e.projectRoot,{required:!0}),d=m(n.stories[e.storyId]);if(!i||!["backlog","ready_to_start"].includes(String(i.status))||i.steps_completed!==void 0&&(!Array.isArray(i.steps_completed)||i.steps_completed.length>0)||i.branch_name||i.checkpoint)return s("direct-yolo-setup-story-progress-conflict");const c=d?.status==="branch-ready"&&d.last_step===M&&Array.isArray(d.steps_completed)&&d.steps_completed.length===1&&d.steps_completed[0]===M&&Q(d).sort().join(",")==="last_step,status,steps_completed";return d&&Q(d).length>0&&!c?s("direct-yolo-setup-story-progress-conflict"):(c||await $(e.projectRoot,h=>{const a=Re(h,e.storyId);if(Q(a).length>0)throw new Error("direct-yolo-setup-runtime-raced");a.status="branch-ready",a.last_step=M,a.steps_completed=[M]},{expectedRevision:n.revision,preCommit:async()=>{if(ke(e.projectRoot)!==o||await u(e.projectRoot,["symbolic-ref","--quiet","--short","HEAD"])!==t.temporaryBranch||await u(e.projectRoot,["rev-parse","HEAD"])!==t.headSha||(await C(e.projectRoot,["status","--porcelain=v1","-z","--untracked-files=all"])).length>0)throw new Error("direct-yolo-setup-physical-state-raced")}}),{ok:!0,value:Object.freeze({...tt(e,t,c),checkpointAccepted:!0,graphRevision:e.graphRevision,headSha:t.headSha})})}async function Or(e,t){const o=await G(e,t),r=await O(o.projectRoot,{required:!0}),i=W(m(r.epics[o.epicId])?.origin_binding,o.executionBranch,o.originBranch);return{...o,originBinding:i}}function Lr(e,t,o,r,i="tracked"){return U(e,t,o,r,i)}function $r(e){return A(["direct-yolo-commit-v1",e.storyId,e.epicId,e.executionBranch,e.baseSha,e.bundleDigest,e.graphRevision,e.claimRevision].join("\0"))}const Nr=de,Wt="p205-wave:";function Pr(e){if(e.waveStoryIds.length===0||e.waveStoryIds.length!==e.waveCommitShas.length||e.waveCommitShas[e.waveCommitShas.length-1]!==e.waveHeadSha||e.waveCommitShas.some(o=>!/^[a-f0-9]{40,64}$/.test(o)))throw new Error("direct-yolo-wave-coverage-invalid");const t=A(["p205-wave-coverage-v1",e.epicId,e.executionBranch,e.waveHeadSha,...e.waveStoryIds.map((o,r)=>`${o}=${e.waveCommitShas[r]}`)].join("\0"));return Object.freeze({kind:"wave",waveHeadSha:e.waveHeadSha,waveStoryIds:Object.freeze([...e.waveStoryIds]),waveCommitShas:Object.freeze([...e.waveCommitShas]),waveDigest:t})}function Vt(e){return`${Wt}${e.waveHeadSha}:${e.waveDigest}`}async function qr(e){let t;try{t=await bt(e.projectRoot,{headSha:e.headSha,graphRevisions:e.graphRevisions,...e.nowIso!==void 0?{nowIso:e.nowIso}:{}})}catch(o){const r=o instanceof Error?o.message:"";return/^p205-transient-[a-z0-9-]{1,64}$/.test(r)?{ok:!1,headSha:e.headSha,kind:"infrastructure",reasonCode:r}:{ok:!1,headSha:e.headSha,kind:"gate-failed",reasonCode:Se(r)?r:"p205-complete-gate-failed"}}try{await e.qaRunner?.({projectRoot:e.projectRoot,storyId:e.storyId,headSha:e.headSha})}catch(o){const r=o instanceof Error?o.message:"";return/^p205-transient-[a-z0-9-]{1,64}$/.test(r)?{ok:!1,headSha:e.headSha,kind:"infrastructure",reasonCode:r}:{ok:!1,headSha:e.headSha,kind:"gate-failed",reasonCode:Se(r)||/^p205-[a-z0-9-]{1,64}$/.test(r)?r:"p205-complete-gate-failed"}}return{ok:!0,headSha:e.headSha,authorities:t}}async function Tr(e,t,o,r){const i=re(t);return await u(e,["push",i,o]),Pe(e,i,o,r)}async function zr(e){try{const t=await G(e.projectRoot,e.storyId),o=e.coverage.waveHeadSha,r=e.coverage.waveStoryIds.indexOf(e.storyId);if(r<0||e.coverage.waveCommitShas[r]!==e.headSha)return s("direct-yolo-wave-coverage-invalid");if(await u(t.projectRoot,["rev-parse","HEAD"])!==o||await u(t.projectRoot,["rev-parse",`refs/heads/${t.executionBranch}`])!==o||!await _(t.projectRoot,["merge-base","--is-ancestor",e.headSha,o]))return s("direct-yolo-wave-head-raced");const i=await O(t.projectRoot,{required:!0}),n=m(i.stories[e.storyId]?.checkpoint);if(n){if(n.headSha!==e.headSha)return s("direct-yolo-checkpoint-conflict");const b=e.authorities.get(String(n.graphRevision));return await Ie(t.projectRoot,n,e.storyId,t.epicId,t.executionBranch,b??null,t.authorizedWriteSet)?(await ue(t.projectRoot,e.storyId).catch(()=>{}),{ok:!0,value:n}):s("direct-yolo-replay-invalid")}const d=await Xe(t,e.storyId,e.headSha);if(!d.ok)return s(d.reasonCode);const{baseSha:c,bundleDigest:h,graphRevision:a,claimRevision:f,idempotencyKey:y,governance:I}=d.value,l=r===0?void 0:e.coverage.waveCommitShas[r-1];if(l!==void 0&&c!==l)return s("direct-yolo-wave-chain-invalid");const w=e.authorities.get(a),g=Fe(w);if(!w||!g||g.executionHeadSha!==o||g.graphRevision!==a)return s("direct-yolo-wave-qa-unbound");const j=await je({projectRoot:t.projectRoot,storyId:e.storyId,epicId:t.epicId,executionBranch:t.executionBranch,baseSha:c,headSha:e.headSha,bundleDigest:h,graphRevision:a,claimRevision:f,idempotencyKey:y,qaExecution:{contract:"P205-CI-02",command:Ye,manifestDigest:g.manifestDigest,gateIds:g.gateIds,resultDigest:g.resultDigest,transientAuthority:w},physicalLockOwnerDigest:ve(e.physicalLock.owner),nowIso:q(e.nowIso),legacyReceiptRef:void 0,rootMemoryEffect:t.rootMemoryEffect,extraReceiptRefs:[Vt(e.coverage)],...I?{governance:I}:{}});return await Ae({projectRoot:t.projectRoot,checkpoint:j,remote:e.remote,expectedRevision:i.revision,expectedLease:e.expectedLease,expectedGraphRevision:t.graphRevision,expectedCheckpointGraphRevision:a,physicalLockPath:e.physicalLock.path,physicalLockOwner:e.physicalLock.owner,transientAuthority:w,authorizedWriteSet:t.authorizedWriteSet,expectedHeadSha:o,keepLease:!0})?(await ue(t.projectRoot,e.storyId).catch(()=>{}),{ok:!0,value:j}):s("direct-yolo-checkpoint-persist-failed")}catch(t){return s(V(t,"direct-yolo-wave-persist-failed"))}}async function fe(e,t){if(!/^[A-Za-z][A-Za-z0-9_-]*\.[A-Za-z0-9._-]+$/.test(t))throw new Error("direct-yolo-story-id-invalid");const o=L(e),r=m(JSON.parse(ke(o))),i=await O(o,{required:!0}),n=we(r,i),d=Ot({projectRoot:o,storyId:t});if(!d.ok)throw new Error(d.reasonCode);const c=d.mode,h=m(n.stories),a=m(n.epics),f=m(h?.[t]),y=String(f?.epic_id??t.split(".")[0]),I=m(a?.[y]),l=String(I?.execution_branch??""),w=String(I?.origin_branch??""),g=String(I?.graph_revision??""),j=Array.isArray(f?.files_to_modify)?f.files_to_modify:[],R=At(f).filter(tr),b=[...j,...R],E=b.length>0?me(t,b):void 0,v=E?.ok?E.scopes:[];if(!f)throw new Error("direct-yolo-story-state-missing");if(R.length>0&&v.length>jt)throw new Error("direct-yolo-write-set-too-large");if(I?.branch_mode!=="epic")throw new Error("direct-yolo-branch-mode-invalid");if(!X(l)||!await _(o,["check-ref-format","--branch",l]))throw new Error("direct-yolo-execution-branch-invalid");if(!X(w)||!await _(o,["check-ref-format","--branch",w]))throw new Error("direct-yolo-origin-branch-invalid");if(!/^[a-f0-9]{64}$/.test(g))throw new Error("direct-yolo-graph-revision-invalid");const S=await gt({projectRoot:o,storyId:t,graphRevision:g,executionBranch:l,childPaths:v});return{projectRoot:o,storyId:t,story:f,epicId:y,executionBranch:l,originBranch:w,graphRevision:g,authorizedWriteSet:v,rootMemoryEffect:S,governanceMode:c}}async function Mr(e){try{const t=await fe(e.projectRoot,e.storyId);return t.governanceMode!=="runtime-store"?s("governance-capture-not-applicable"):await be(t.projectRoot)?s("governance-capture-root-required"):{ok:!0,value:De(t).receipt}}catch(t){return s(V(t,"governance-capture-failed"))}}function ke(e){const t=Nt(e);if(!t.ok)throw new Error(t.reasonCode);if(!t.value)throw new Error("direct-yolo-story-state-missing");return t.value.toString("utf8")}function De(e){const t=Ht(e);if(!t.ok)throw new Error(t.reasonCode);return Ee(e,t.value.governanceDigest)}function Ee(e,t){const o=qt({...e,expectedGovernanceDigest:t});if(!o.ok)throw new Error(o.reasonCode);const r=o.value.files.get(Pt(e.storyId));if(!r)throw new Error(ce.MISMATCH);return{receipt:o.value.receipt,review:Dt(e.storyId,r)}}async function G(e,t){const o=await fe(e,t);if(await u(o.projectRoot,["symbolic-ref","--quiet","--short","HEAD"])!==o.executionBranch)throw new Error("direct-yolo-current-branch-mismatch");return o}async function je(e){const t=e.nowIso,o=await C(e.projectRoot,["show","--no-patch","--format=%H%n%P%n%B",e.headSha]),r=P(await C(e.projectRoot,["diff-tree","--no-commit-id","--name-only","-r","-z",e.headSha])),i=St({storyId:e.storyId,baseSha:e.baseSha,headSha:e.headSha,bundleDigest:e.bundleDigest,graphRevision:e.graphRevision,commitBody:o,changedPaths:r}),n=It({gitEvidenceDigest:i,headSha:e.headSha,graphRevision:e.graphRevision,manifestDigest:e.qaExecution.manifestDigest,gateIds:e.qaExecution.gateIds,resultDigest:e.qaExecution.resultDigest}),d=`story-qa:${n}`,c=Object.freeze({schemaVersion:1,kind:"story_qa_evidence",producer:"local-yolo-tdd",evidenceVersion:"p205-execution-v2",storyId:e.storyId,epicId:e.epicId,baseSha:e.baseSha,headSha:e.headSha,bundleDigest:e.bundleDigest,graphRevision:e.graphRevision,contract:e.qaExecution.contract,command:e.qaExecution.command,manifestDigest:e.qaExecution.manifestDigest,gateIds:e.qaExecution.gateIds,resultDigest:e.qaExecution.resultDigest,sourceEvidenceDigest:n,verdict:"passed",checkedAt:t,receiptRef:d}),h=e.governance?Ee(e,e.governance.governanceDigest).review:ie(e.projectRoot,e.storyId,e.headSha);if(h?.verdict!=="approved")throw new Error("direct-yolo-review-artifact-not-approved");const a=A(["root-commit-range-review-v2",e.storyId,e.baseSha,e.headSha,e.bundleDigest,e.graphRevision,d,A(o),[...r].sort().join(","),h.digest].join("\0")),f=`story-review:${a}`,y=Object.freeze({schemaVersion:1,kind:"story_review_evidence",producer:"root-commit-range-review",storyId:e.storyId,epicId:e.epicId,baseSha:e.baseSha,headSha:e.headSha,bundleDigest:e.bundleDigest,graphRevision:e.graphRevision,sourceEvidenceDigest:a,reviewArtifactDigest:h.digest,qaReceiptRef:d,verdict:"approved",reviewedAt:t,receiptRef:f}),I=[`.neocortex/stories/${e.storyId}/qa-gate-result.json`,`.neocortex/stories/${e.storyId}/validation-evidence.md`,d,f,...e.physicalLockOwnerDigest?[`physical-lock-owner:${e.physicalLockOwnerDigest}`]:[],...e.legacyReceiptRef?[e.legacyReceiptRef]:[],...e.extraReceiptRefs??[],...e.governance?Lt(e.governance):[]];return Object.freeze({schemaVersion:1,storyId:e.storyId,epicId:e.epicId,branch:e.executionBranch,baseSha:e.baseSha,headSha:e.headSha,commits:Object.freeze([e.headSha]),idempotencyKey:e.idempotencyKey,bundleDigest:e.bundleDigest,graphRevision:e.graphRevision,claimRevision:e.claimRevision,receiptRefs:Object.freeze(I),qaVerdict:"passed",reviewVerdict:"approved",qaReceipt:c,reviewReceipt:y,recordedAt:t,...e.rootMemoryEffect?{rootMemoryEffect:e.rootMemoryEffect}:{}})}async function Ae(e){const{projectRoot:t,checkpoint:o,remote:r}=e;let i=!1;return await $(t,n=>{const d=z(n,o.epicId);if(e.expectedLease){const f=m(d.branch_lease);if(!Oe(f,e.expectedLease))throw new Error("direct-yolo-runtime-revision-conflict");if(Date.parse(String(f?.expiresAt))<=Date.now())throw new Error("direct-yolo-writer-lease-expired");if(d.graph_revision!==e.expectedGraphRevision||o.graphRevision!==(e.expectedCheckpointGraphRevision??e.expectedGraphRevision))throw new Error("direct-yolo-graph-revision-raced")}const c=Re(n,o.storyId),h=m(c.checkpoint);if(h&&h.headSha!==o.headSha){i=!0;return}c.checkpoint=o,c.status="done",c.last_step=Qe;const a=Array.isArray(c.steps_completed)?c.steps_completed.filter(f=>typeof f=="string"):[];c.steps_completed=[...new Set([...a,Mt,Qe])],e.keepLease||(d.branch_lease=null)},{expectedRevision:e.expectedRevision,preCommit:async()=>{if(i)throw new Error("direct-yolo-checkpoint-conflict");const n=e.expectedHeadSha??o.headSha;if(await u(t,["symbolic-ref","--quiet","--short","HEAD"])!==o.branch||await u(t,["rev-parse","HEAD"])!==n||await u(t,["rev-parse",`refs/heads/${o.branch}`])!==n||!await _(t,["merge-base","--is-ancestor",o.headSha,n]))throw new Error("direct-yolo-checkpoint-head-raced");if(!await Ie(t,o,o.storyId,o.epicId,o.branch,e.transientAuthority,e.authorizedWriteSet))throw new Error("direct-yolo-checkpoint-physical-invalid");if(e.physicalLockPath&&e.physicalLockOwner&&!await ae(e.physicalLockPath,e.physicalLockOwner))throw new Error("direct-yolo-integration-lock-raced");if(r&&!(e.remotePolicy==="ancestor-recovery"?await rt(t,r,o.branch,o.headSha):await Pe(t,r,o.branch,n)))throw new Error("direct-yolo-checkpoint-remote-raced")}}),!i}async function rt(e,t,o,r){const i=re(t),n=(await u(e,["ls-remote","--heads",i,`refs/heads/${o}`])).split(/\s+/)[0];return!!(n&&await _(e,["merge-base","--is-ancestor",r,n]))}function _e(e){return A(["direct-yolo-commit-v1",e.storyId,e.epicId,e.executionBranch,e.baseSha,e.bundleDigest,e.graphRevision,e.claimRevision].join("\0"))}const Kt=["schemaVersion","kind","storyId","epicId","executionBranch","graphRevision","preparedBase","bundleDigest","claimRevision","idempotencyKey","issuedAt"];async function Be(e,t){const o=await Je(e),r=await Ke(o,"commit-plans"),i=`direct-${A(t)}.json`;return{parent:r,name:i,path:ee(r,i)}}async function Ft(e,t){const o=await Be(e,t.storyId);await Ze(o.parent,o.name,`${JSON.stringify(t,null,2)}
|
|
2
|
+
`),await ne(o.path,o.parent)}async function ot(e,t){let o;try{o=await Be(e,t)}catch{return{state:"invalid"}}try{if(!We(o.path))return{state:"absent"};await ne(o.path,o.parent);const r=await F(o.path,"utf8");if(r.length>16*1024)return{state:"invalid"};const i=m(JSON.parse(r));if(!i||Object.keys(i).sort().join("\0")!==[...Kt].sort().join("\0")||i.schemaVersion!==1||i.kind!=="direct-yolo-commit-plan"||i.storyId!==t||typeof i.epicId!="string"||typeof i.executionBranch!="string"||!X(i.executionBranch)||typeof i.preparedBase!="string"||!/^[a-f0-9]{40,64}$/.test(i.preparedBase)||![i.graphRevision,i.bundleDigest,i.claimRevision,i.idempotencyKey].every(d=>typeof d=="string"&&/^[a-f0-9]{64}$/.test(d))||typeof i.issuedAt!="string"||!Number.isFinite(Date.parse(i.issuedAt)))return{state:"invalid"};const n=i;return n.idempotencyKey!==_e({...n,baseSha:n.preparedBase})?{state:"invalid"}:{state:"valid",plan:n}}catch{return{state:"invalid"}}}async function ue(e,t){const o=await Be(e,t);We(o.path)&&await Bt(o.parent,o.name)}function Ce(e,t,o){return!!(e?.ownerStoryId===t&&e.sessionId===e.idempotencyKey&&typeof e.idempotencyKey=="string"&&/^setup-[a-f0-9]{64}$/.test(e.idempotencyKey)&&typeof e.expiresAt=="string"&&Date.parse(e.expiresAt)>Date.parse(o))}async function it(e,t){const o=await Je(e),r=await Ke(o,"handoffs"),i=`direct-${A(t)}.json`;return{parent:r,name:i,path:ee(r,i)}}async function He(e,t){const o=await it(e,t.storyId);await Ze(o.parent,o.name,`${JSON.stringify(t,null,2)}
|
|
3
|
+
`),await ne(o.path,o.parent)}async function Z(e,t){try{const o=await it(e,t);await ne(o.path,o.parent);const r=JSON.parse(await F(o.path,"utf8")),i=r.state==="issued"?["schemaVersion","kind","state","storyId","fromSessionId","token","tokenDigest","bundleDigest","claimRevision","grantDigest","expiresAt"]:r.state==="consuming"?["schemaVersion","kind","state","storyId","fromSessionId","token","tokenDigest","bundleDigest","claimRevision","grantDigest","expiresAt","consumedBySessionId","consumeStartedAt"]:["schemaVersion","kind","state","storyId","fromSessionId","tokenDigest","bundleDigest","claimRevision","grantDigest","expiresAt","consumedBySessionId","consumedAt"];return Object.keys(r).sort().join("\0")!==[...i].sort().join("\0")||r.schemaVersion!==1||r.kind!=="direct-yolo-setup-handoff-token"||r.state!=="issued"&&r.state!=="consuming"&&r.state!=="consumed"||r.storyId!==t||typeof r.fromSessionId!="string"||!/^setup-[a-f0-9]{64}$/.test(r.fromSessionId)||![r.tokenDigest,r.bundleDigest,r.claimRevision,r.grantDigest].every(n=>typeof n=="string"&&/^[a-f0-9]{64}$/.test(n))||typeof r.expiresAt!="string"||!Number.isFinite(Date.parse(r.expiresAt))||(r.state==="issued"||r.state==="consuming")&&(typeof r.token!="string"||!/^[A-Za-z0-9_-]{32,256}$/.test(r.token))||r.state==="consuming"&&(typeof r.consumedBySessionId!="string"||!/^[a-f0-9]{64}$/.test(r.consumedBySessionId)||typeof r.consumeStartedAt!="string"||!Number.isFinite(Date.parse(r.consumeStartedAt)))||r.state==="consumed"&&(typeof r.consumedBySessionId!="string"||!/^[a-f0-9]{64}$/.test(r.consumedBySessionId)||typeof r.consumedAt!="string"||!Number.isFinite(Date.parse(r.consumedAt)))?void 0:r}catch{return}}async function Yt(e,t,o,r,i){const n=await Z(e,t);if(!(!n||n.state==="consumed"||!n.token||n.bundleDigest!==o||n.claimRevision!==r||Date.parse(n.expiresAt)<=Date.parse(i)||A(n.token)!==n.tokenDigest))return{sessionId:n.fromSessionId,token:n.token}}async function Jt(e,t,o,r,i,n){const d=await Z(e,t);if(!d||d.state==="consumed"||d.fromSessionId!==o||d.token!==r||d.tokenDigest!==A(r))throw new Error("direct-yolo-setup-handoff-consume-invalid");if(d.state==="consuming"){if(d.consumedBySessionId!==i)throw new Error("direct-yolo-setup-handoff-consume-raced");return}await He(e,{...d,state:"consuming",consumedBySessionId:i,consumeStartedAt:n})}async function Zt(e,t,o,r,i,n,d,c,h){const a=await Z(e,o);if(a?.state==="consumed"&&a.fromSessionId===r&&a.consumedBySessionId===c)return;const f=await O(e,{required:!0}),y=m(f.epics[t]?.branch_lease),I=m(y?.handoffConsumption);if(!a||a.state!=="consuming"||a.fromSessionId!==r||a.token!==i||a.tokenDigest!==A(i)||a.bundleDigest!==n||a.claimRevision!==d||a.consumedBySessionId!==c||y?.ownerStoryId!==o||y.sessionId!==c||I?.kind!=="direct-yolo-setup-handoff-consumption"||I.state!=="consumed"||I.fromSessionId!==r||I.tokenDigest!==a.tokenDigest||I.bundleDigest!==n||I.claimRevision!==d||I.consumedBySessionId!==c)throw new Error("direct-yolo-setup-handoff-consume-invalid");try{await He(e,{schemaVersion:1,kind:a.kind,state:"consumed",storyId:o,fromSessionId:r,tokenDigest:a.tokenDigest,bundleDigest:a.bundleDigest,claimRevision:a.claimRevision,grantDigest:a.grantDigest,expiresAt:a.expiresAt,consumedBySessionId:c,consumedAt:h})}catch{throw new Error("direct-yolo-setup-handoff-consume-persist-failed")}}function Ut(e){const t=m(e.current?.handoffGrant),o=e.handoff?.token,r=typeof o=="string"&&/^[A-Za-z0-9_-]{32,256}$/.test(o)?A(o):void 0;return!!(t&&r&&e.handoff&&e.handoff.sessionId===e.current?.sessionId&&t.schemaVersion===1&&t.kind==="direct-yolo-setup-handoff"&&t.storyId===e.storyId&&t.fromSessionId===e.current?.sessionId&&t.bundleDigest===e.bundleDigest&&t.claimRevision===e.claimRevision&&typeof t.expiresAt=="string"&&Date.parse(t.expiresAt)>Date.parse(e.nowIso)&&typeof t.tokenDigest=="string"&&/^[a-f0-9]{64}$/.test(t.tokenDigest)&&Qt(t.tokenDigest,r))}function Qt(e,t){const o=Buffer.from(e,"hex"),r=Buffer.from(t,"hex");return o.length===32&&r.length===32&&pt(o,r)}function Oe(e,t){return!!(e&&["schemaVersion","ownerStoryId","sessionId","idempotencyKey","acquiredAt","expiresAt"].every(o=>e[o]===t[o]))}async function Le(e,t,o){await $(e,r=>{const i=z(r,t),n=m(i.branch_lease);Oe(n,o)&&(i.branch_lease=null)})}async function Xt(e,t){const o=await O(e.projectRoot,{required:!0}),r=m(o.epics[e.epicId]?.branch_lease);if(!r||r.ownerStoryId!==t||!nt(r.sessionId)||!nt(r.idempotencyKey)||!Number.isFinite(Date.parse(String(r.acquiredAt)))||!Number.isFinite(Date.parse(String(r.expiresAt))))return;const i=await Y(e.projectRoot,{kind:"direct",storyId:t,sessionId:String(r.sessionId),idempotencyKey:String(r.idempotencyKey),createdAt:String(r.acquiredAt),expiresAt:String(r.expiresAt),persistent:!0});if(!i.ok)return;await J(i.path,i.owner)&&await Le(e.projectRoot,e.epicId,r)}async function $e(e,t,o,r){const i=await kt(t,{headSha:o,graphRevision:r,nowIso:e.nowIso});await e.qaRunner?.({projectRoot:t,storyId:e.storyId,headSha:o});const n=Fe(i);if(!n)throw new Error("p205-transient-authority-invalid");return{contract:"P205-CI-02",command:Ye,manifestDigest:n.manifestDigest,gateIds:n.gateIds,resultDigest:n.resultDigest,transientAuthority:i}}async function Ne(e,t,o,r){return await u(e,["rev-parse","HEAD"])!==o||await u(e,["symbolic-ref","--quiet","--short","HEAD"])!==t||!await _(e,["diff","--cached","--quiet"])?!1:_(e,["diff","--quiet","HEAD","--",...r])}async function Pe(e,t,o,r){const i=re(t);return(await u(e,["ls-remote","--heads",i,`refs/heads/${o}`])).split(/\s+/)[0]===r}function U(e,t,o,r,i="tracked"){if(e.length===0||e.some(c=>!qe(c)))return{ok:!1,reasonCode:"direct-yolo-write-set-invalid"};if(i==="runtime-store")return er(e,t,o,r);const n=t.length>0?me(o,t):void 0;return n?.ok?[".neocortex/state.json",`docs/stories/${o}.story.md`,`.neocortex/stories/${o}/qa-gate-result.json`,`.neocortex/stories/${o}/validation-evidence.md`,`.neocortex/stories/${o}/review.md`].every(c=>e.includes(c))?r&&(r.storyId!==o||r.childClaimRevision!==A([...n.scopes].sort().join("\0")))?{ok:!1,reasonCode:"direct-yolo-root-memory-claim-mismatch"}:e.some(c=>!Ve(n.scopes,c)&&!r?.files.some(h=>h.path===c))?{ok:!1,reasonCode:"direct-yolo-write-set-unauthorized"}:{ok:!0}:{ok:!1,reasonCode:"direct-yolo-write-set-invalid"}:{ok:!1,reasonCode:"direct-yolo-write-set-invalid"}}function er(e,t,o,r){if(e.some($t))return{ok:!1,reasonCode:ce.WRITE_SET_FORBIDDEN};const i=t.length>0?me(o,t):void 0;if(!i?.ok)return{ok:!1,reasonCode:"direct-yolo-write-set-invalid"};const n=`docs/stories/${o}.story.md`;return!e.includes(n)||!e.some(d=>d!==n)?{ok:!1,reasonCode:"direct-yolo-write-set-invalid"}:r&&(r.storyId!==o||r.childClaimRevision!==A([...i.scopes].sort().join("\0")))?{ok:!1,reasonCode:"direct-yolo-root-memory-claim-mismatch"}:e.some(d=>!Ve(i.scopes,d)&&!r?.files.some(c=>c.path===d))?{ok:!1,reasonCode:"direct-yolo-write-set-unauthorized"}:{ok:!0}}function Q(e){return Object.keys(e).filter(t=>t!=="write_set_extension")}function tr(e){return typeof e!="string"||e.length>512||!qe(e)||!Rt(e).ok||/^(?:\.neocortex|\.claude|\.git[^/]*)(?:\/|$)/i.test(e)||/^docs\/stories(?:\/|$)/i.test(e)?!1:!e.split("/")[0].includes("*")}function qe(e){return e.length>0&&e.length<=1024&&!e.startsWith("/")&&!e.includes("\\")&&!e.split("/").includes("..")&&!e.startsWith(".git/")&&!e.includes("\0")}function nt(e){return typeof e=="string"&&e.length>0&&e.length<=512&&/^[A-Za-z0-9._:@/+\-=]+$/.test(e)}function X(e){return e.length>0&&e.length<=240&&!e.startsWith("-")&&!/[\s~^:?*[\\]/.test(e)&&!e.includes("..")}function re(e){if(!/^[A-Za-z0-9._-]{1,128}$/.test(e))throw new Error("direct-yolo-remote-invalid");return e}function A(e){return lt("sha256").update(e).digest("hex")}function P(e){return e.split("\0").filter(Boolean)}function q(e){return e&&Number.isFinite(Date.parse(e))?new Date(Date.parse(e)).toISOString():new Date().toISOString()}function m(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:void 0}function rr(e,t,o,r,i){const n=m(e.expectedLease),d=n?.sessionId,c=Date.parse(String(n?.expiresAt??""));return e.schemaVersion===1&&Number.isSafeInteger(e.expectedRuntimeRevision)&&e.expectedRuntimeRevision===t&&!!o&&JSON.stringify(o)===JSON.stringify(n)&&n?.schemaVersion===1&&n.ownerStoryId===r&&typeof d=="string"&&/^setup-[a-f0-9]{64}$/.test(d)&&n.idempotencyKey===d&&Number.isFinite(c)&&c<=i}async function or(e,t){let o=await u(e,["symbolic-ref","--quiet","--short","HEAD"]);if(o===t.executionBranch){if(await u(e,["rev-parse","HEAD"])!==t.originHead||await T(e)!==t.checkoutBefore)return;await u(e,["switch",t.originBranch]),o=t.originBranch}if(o!==t.originBranch||await u(e,["rev-parse","HEAD"])!==t.originHead||await T(e)!==t.checkoutBefore||t.executionHead===t.originHead||!await _(e,["show-ref","--verify","--quiet",t.executionRef]))return;await u(e,["rev-parse",t.executionRef])===t.originHead&&await u(e,["update-ref",t.executionRef,t.executionHead,t.originHead])}const ir=["capturedAt","capturedFromCurrentCheckout","executionBranch","originBranch","originHeadSha","schemaVersion"],nr=["capturedAt","capturedFrom","executionBranch","originBranch","originHeadSha","schemaVersion"];function W(e,t,o){const r=m(e);if(!r||r.originBranch!==o||r.executionBranch!==t||typeof r.originHeadSha!="string"||!/^[a-f0-9]{40,64}$/.test(r.originHeadSha)||typeof r.capturedAt!="string"||!Number.isFinite(Date.parse(r.capturedAt)))return;const i=Object.keys(r).sort().join("\0");if(r.schemaVersion===1)return r.capturedFromCurrentCheckout!==!0||i!==ir.join("\0")?void 0:r;if(r.schemaVersion===2)return r.capturedFrom!=="current-checkout"&&r.capturedFrom!=="branch-ref"||i!==nr.join("\0")?void 0:r}async function ar(e,t,o){const r=`refs/heads/${e.originBranch}`;if(!await _(e.projectRoot,["show-ref","--verify","--quiet",r]))return s("direct-yolo-origin-ref-missing","fetch-origin-branch");const i=await u(e.projectRoot,["rev-parse","--verify","--quiet",`${r}^{commit}`]).catch(()=>"");if(!/^[a-f0-9]{40,64}$/.test(i))return s("direct-yolo-origin-ref-missing","fetch-origin-branch");if((await oe(e.projectRoot)).some(h=>h.branch===e.executionBranch&&L(h.path)!==e.projectRoot))return s("direct-yolo-execution-branch-checked-out-elsewhere");const d=`refs/heads/${e.executionBranch}`;if(await u(e.projectRoot,["rev-parse","--verify","--quiet",d]).catch(()=>"")!==t)return s("direct-yolo-setup-physical-state-raced");const c=await Te(e.projectRoot,["merge-base","--is-ancestor",i,t]);return c===1?s("direct-yolo-origin-not-ancestor","checkout-origin-or-rebase"):c!==0?s("direct-yolo-origin-ancestry-unverifiable"):{ok:!0,value:{originRef:r,binding:{schemaVersion:2,originBranch:e.originBranch,originHeadSha:i,executionBranch:e.executionBranch,capturedFrom:"branch-ref",capturedAt:o}}}}const at=3e4,cr=3,sr="ssh -o BatchMode=yes -o ConnectTimeout=15 -o ServerAliveInterval=15 -o ServerAliveCountMax=2";class he extends Error{}function dr(e,t=at){return{timeout:t,killSignal:"SIGKILL",env:{...e,GIT_TERMINAL_PROMPT:"0",GCM_INTERACTIVE:"never",GIT_HTTP_LOW_SPEED_LIMIT:"1000",GIT_HTTP_LOW_SPEED_TIME:"30",...e.GIT_SSH_COMMAND?{}:{GIT_SSH_COMMAND:sr}}}}async function fr(e){if(!X(e.originBranch))return{ok:!1,reasonCode:"origin-binding-start-fetch-unavailable"};try{return await te("git",["fetch","--no-tags","origin",`refs/heads/${e.originBranch}:refs/remotes/origin/${e.originBranch}`],{cwd:L(e.projectRoot),maxBuffer:1024*1024,encoding:"utf8",...dr(process.env,e.fetchTimeoutMs??at)}),{ok:!0}}catch(t){const o=String(t.stderr??"");return{ok:!1,reasonCode:/non-fast-forward|\[rejected\]/.test(o)?"origin-binding-start-fetch-non-fast-forward":"origin-binding-start-fetch-unavailable"}}}const ur=new Set(["done","completed","complete","closed","cancelled","canceled","archived","terminal"]);async function Gr(e,t){const o=Object.freeze({exists:!1,mode:"not-epic",terminal:!1,bound:!1});try{const r=L(e),i=m(JSON.parse(await F(ee(r,".neocortex/state.json"),"utf8")));if(!i)return o;const n=await O(r),d=we(i,n),c=m(m(d.epics)?.[t]);if(!c)return o;const h=st(d,t,c),a=typeof c.execution_branch=="string"&&c.execution_branch.length>0?c.execution_branch:`epic/${t}`,f=await ct(r,c,i),y=m(n.epics[t])?.origin_binding??c.origin_binding;return Object.freeze({exists:!0,mode:h,terminal:ur.has(String(c.status??"").toLowerCase()),bound:!!W(y,a,f),executionBranch:a,originBranch:f})}catch{return o}}async function ct(e,t,o){if(typeof t.origin_branch=="string"&&t.origin_branch.length>0)return t.origin_branch;const r=m(o.config)?.default_branch;if(r!=null&&String(r).length>0)return String(r);const i=await u(e,["symbolic-ref","--quiet","--short","refs/remotes/origin/HEAD"]).catch(()=>"");if(i.startsWith("origin/")&&i.length>7)return i.slice(7);const n=[];for(const d of["main","master"])await _(e,["rev-parse","--verify","--quiet",`refs/heads/${d}^{commit}`])&&await _(e,["rev-parse","--verify","--quiet",`refs/remotes/origin/${d}^{commit}`])&&n.push(d);return n.length===1?n[0]:""}function st(e,t,o){if(o.branch_mode==="epic")return"recorded-epic";if(o.branch_mode!==void 0&&o.branch_mode!==null)return"not-epic";const r=m(e.stories)??{},n=vt(t,Array.isArray(o.stories)?o.stories:void 0,Object.keys(r)).flatMap(c=>{const h=m(r[c]);return h?[{...h,id:c}]:[]}),d=wt({...o,id:t},n);return d.mode==="epic"&&(d.source==="new-epic-default"||d.source==="epic-boundary")?"resolved-epic":"not-epic"}function dt(e,t){if(!e)return!1;const o=Date.parse(String(e.expiresAt));return!(Number.isFinite(o)&&o<=t)}async function Wr(e){const t=q(e.nowIso),o=Date.parse(t),r=(c,h={})=>Object.freeze({schemaVersion:1,kind:"origin-binding-start",epicId:e.epicId,...h,outcome:"refused",reasonCode:c,executionRefCreated:!1,capturedAt:t});if(!/^[A-Za-z][A-Za-z0-9_-]{0,63}$/.test(e.epicId))return r("origin-binding-start-target-ambiguous");const i=L(e.projectRoot);let n=e.originFetch,d="origin-binding-start-raced";for(let c=0;c<cr;c+=1){let h,a={};try{const f=m(JSON.parse(await F(ee(i,".neocortex/state.json"),"utf8")));if(!f)return r("origin-binding-start-state-invalid");const y=await O(i),I=we(f,y),l=m(m(I.epics)?.[e.epicId]);if(!l)return r("origin-binding-start-target-ambiguous");if(st(I,e.epicId,l)==="not-epic")return r("origin-binding-start-branch-mode-not-epic");const w=typeof l.execution_branch=="string"&&l.execution_branch.length>0?l.execution_branch:`epic/${e.epicId}`,g=await ct(i,l,f);if(a={executionBranch:w,originBranch:g},!X(w)||!X(g)||w===g||!await _(i,["check-ref-format","--branch",w])||!await _(i,["check-ref-format","--branch",g]))return r("origin-binding-start-branch-invalid",a);const j=m(y.epics[e.epicId]),R=j?.origin_binding??l.origin_binding;if(R!=null){const H=W(R,w,g);return H?Object.freeze({schemaVersion:1,kind:"origin-binding-start",epicId:e.epicId,...a,originHeadSha:H.originHeadSha,outcome:"already-bound",executionRefCreated:!1,capturedAt:t}):r("origin-binding-start-binding-invalid",a)}if(dt(m(j?.branch_lease??l.branch_lease),o))return r("origin-binding-start-lease-inconsistent",a);if(n??=await fr({projectRoot:i,originBranch:g,...e.fetchTimeoutMs?{fetchTimeoutMs:e.fetchTimeoutMs}:{}}),!n.ok)return r(n.reasonCode,a);const b=`refs/remotes/origin/${g}`,E=`refs/heads/${g}`,v=await u(i,["rev-parse","--verify","--quiet",`${E}^{commit}`]).catch(()=>""),S=await u(i,["rev-parse","--verify","--quiet",`${b}^{commit}`]).catch(()=>"");if(!/^[a-f0-9]{40,64}$/.test(v)||v!==S)return r("origin-binding-start-origin-stale",a);if((await oe(i)).some(H=>H.branch===w&&L(H.path)!==i))return r("direct-yolo-execution-branch-checked-out-elsewhere",a);const p=`refs/heads/${w}`,D=await u(i,["rev-parse","--verify","--quiet",`${p}^{commit}`]).catch(()=>"");if(D){const H=await Te(i,["merge-base","--is-ancestor",v,D]);if(H===1)return r("direct-yolo-origin-not-ancestor",a);if(H!==0)return r("direct-yolo-origin-ancestry-unverifiable",a)}const k={schemaVersion:2,originBranch:g,originHeadSha:v,executionBranch:w,capturedFrom:"branch-ref",capturedAt:t};return await $(i,H=>{const B=z(H,e.epicId);if(B.origin_binding!==void 0&&B.origin_binding!==null)throw new he("origin-binding-start-raced");if(dt(m(B.branch_lease),o))throw new he("origin-binding-start-lease-inconsistent");B.origin_binding=k},{expectedRevision:y.revision,preCommit:async()=>{const H=await u(i,["rev-parse","--verify","--quiet",`${E}^{commit}`]).catch(()=>""),B=await u(i,["rev-parse","--verify","--quiet",`${b}^{commit}`]).catch(()=>""),N=await u(i,["rev-parse","--verify","--quiet",`${p}^{commit}`]).catch(()=>"");if(H!==v||B!==v||N!==D)throw new he("origin-binding-start-raced");D||(await u(i,["update-ref",p,v,""]),h={ref:p,sha:v})}}),Object.freeze({schemaVersion:1,kind:"origin-binding-start",epicId:e.epicId,...a,originHeadSha:v,outcome:"captured",executionRefCreated:h!==void 0,capturedAt:t})}catch(f){if(h&&await u(i,["update-ref","-d",h.ref,h.sha]).catch(()=>{}),f instanceof Error&&f.message==="git-lifecycle-runtime-revision-conflict"){d="origin-binding-start-raced";continue}return f instanceof he?r(f.message,a):r("origin-binding-start-failed",a)}}return r(d)}function le(e,t,o,r){return Object.freeze({schemaVersion:1,kind:"direct-yolo-setup-receipt",storyId:e.storyId,epicId:e.epicId,executionBranch:e.executionBranch,originBranch:e.originBranch,originHeadSha:t.originHeadSha,leaseExpiresAt:o,reused:r,publicSafe:!0})}async function T(e){const t=P(await C(e,["ls-files","--others","--exclude-standard","-z"])).sort(),o=await Promise.all(t.map(async r=>{if(!qe(r))throw new Error("direct-yolo-checkout-payload-invalid");return`${r}\0${await u(e,["hash-object","--no-filters","--",r])}`}));return A([await C(e,["diff","--cached","--binary","--full-index"]),await C(e,["diff","--binary","--full-index"]),await C(e,["status","--porcelain=v1","-z","--untracked-files=all"]),...o].join("\0"))}async function Vr(e){const t=L(e),o=await u(t,["rev-parse","HEAD"]),r=await u(t,["symbolic-ref","--quiet","--short","HEAD"]),i=await T(t);if(await u(t,["rev-parse","HEAD"])!==o||await u(t,["symbolic-ref","--quiet","--short","HEAD"])!==r)throw new Error("direct-yolo-checkout-observation-raced");return Object.freeze({headSha:o,branch:r,payloadDigest:i})}async function oe(e){const t=[];let o;for(const r of(await C(e,["worktree","list","--porcelain","-z"])).split("\0"))r.startsWith("worktree ")?(o={path:r.slice(9)},t.push(o)):o&&r.startsWith("branch refs/heads/")&&(o.branch=r.slice(18));return t}const ft=new Set(Object.values(ce));function V(e,t){return e instanceof Error&&e.message==="git-lifecycle-runtime-revision-conflict"?"direct-yolo-runtime-revision-conflict":e instanceof Error&&Se(e.message)||e instanceof Error&&ft.has(e.message)||e instanceof Error&&/^direct-yolo-[a-z0-9-]+(?::[a-z0-9-]+)?$/.test(e.message)?e.message:t}function s(e,t){return t?{ok:!1,reasonCode:e,hint:t}:{ok:!1,reasonCode:e}}async function Te(e,t){try{return await te("git",[...t],{cwd:e,maxBuffer:8*1024*1024}),0}catch(o){const r=o.code;return typeof r=="number"?r:-1}}async function u(e,t){return String((await te("git",[...t],{cwd:e,encoding:"utf8",maxBuffer:32*1024*1024})).stdout).trim()}async function C(e,t){return String((await te("git",[...t],{cwd:e,encoding:"utf8",maxBuffer:32*1024*1024})).stdout)}async function _(e,t){try{return await te("git",[...t],{cwd:e,maxBuffer:8*1024*1024}),!0}catch{return!1}}export{Nr as DIRECT_YOLO_STORY_CHECKPOINT_LEASE_MS,Wt as DIRECT_YOLO_WAVE_RECEIPT_REF_PREFIX,at as ORIGIN_BINDING_START_FETCH_TIMEOUT_MS,Ar as acceptDirectYoloSetupCheckpoint,Br as beginDirectYoloStoryCommit,Vr as captureDirectYoloCheckoutEvidence,Mr as captureDirectYoloStoryGovernance,Wr as captureEpicOriginBindingAtYoloopStart,$r as directYoloCommitIdempotencyKey,Pr as directYoloWaveQaCoverage,Vt as directYoloWaveReceiptRef,fr as fetchOriginForYoloopStart,Cr as finalizeDirectYoloStoryCheckpoint,tr as isDirectYoloWriteSetExtensionScope,_r as issueDirectYoloSetupLeaseHandoff,zr as persistDirectYoloWaveStoryCheckpoint,jr as prepareDirectYoloSetup,Tr as pushDirectYoloWaveHead,Gr as readYoloopStartEpic,Hr as recoverLegacyDirectYoloStoryCheckpoint,Or as resolveDirectYoloIntegrationAuthority,qr as runDirectYoloWaveP205,Lr as validateDirectYoloWriteSet,dr as yoloopStartGitNetworkExecOptions};
|
|
@@ -315,6 +315,10 @@ export interface StoryWorktreeSpecAcceptanceRecord {
|
|
|
315
315
|
readonly storyId: string;
|
|
316
316
|
readonly specDigest: string;
|
|
317
317
|
readonly graphRevision: string;
|
|
318
|
+
/** P228.24 v2 (ADR-P228-06): present together with `specInputDigest`. */
|
|
319
|
+
readonly schemaVersion?: 2;
|
|
320
|
+
/** P228.24 v2: digest of the story's own spec inputs; revalidated by the server. */
|
|
321
|
+
readonly specInputDigest?: string;
|
|
318
322
|
}
|
|
319
323
|
export interface StoryWorktreeEvidenceContainer {
|
|
320
324
|
readonly schemaVersion: 1;
|
|
@@ -323,6 +327,8 @@ export interface StoryWorktreeEvidenceContainer {
|
|
|
323
327
|
}
|
|
324
328
|
export declare const STORY_WORKTREE_EVIDENCE_MAX_RECEIPTS = 512;
|
|
325
329
|
export declare const STORY_WORKTREE_EVIDENCE_MAX_SPEC_ACCEPTANCES = 256;
|
|
330
|
+
/** P228.24 (AM-04): serialized container bound for read, persist and forward. */
|
|
331
|
+
export declare const STORY_WORKTREE_EVIDENCE_MAX_BYTES = 262144;
|
|
326
332
|
/**
|
|
327
333
|
* Closed local validator for the P225-CON-RECEIPTS kinds the root persists in
|
|
328
334
|
* `story_worktree_evidence` (phase-one, spec-barrier, integration). Kept in the
|
|
@@ -430,6 +436,14 @@ export declare function publicStoryReviewArtifactFromGit(projectRoot: string, st
|
|
|
430
436
|
readonly verdict: 'approved' | 'pending' | 'changes-requested';
|
|
431
437
|
readonly digest: string;
|
|
432
438
|
} | undefined;
|
|
439
|
+
/**
|
|
440
|
+
* P228.26 (DEC-03): the review parser shared by the Git reader above and the
|
|
441
|
+
* `runtime-store` governance reader. Same rules, same digest of the raw bytes.
|
|
442
|
+
*/
|
|
443
|
+
export declare function publicStoryReviewArtifactFromBytes(storyId: string, bytes: Buffer, allowLegacyDecision?: boolean): {
|
|
444
|
+
readonly verdict: 'approved' | 'pending' | 'changes-requested';
|
|
445
|
+
readonly digest: string;
|
|
446
|
+
} | undefined;
|
|
433
447
|
/** Binds a later root approval to the exact immutable range of a legacy checkpoint. */
|
|
434
448
|
export declare function computeHistoricalReviewReconciliationDigest(input: {
|
|
435
449
|
readonly storyId: string;
|