@ornexus/neocortex 4.66.18 → 4.66.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/release-source.json +1 -1
- package/dist/sbom.cdx.json +1194 -1194
- package/install.ps1 +1 -1
- package/install.sh +1 -1
- package/package.json +3 -2
- package/packages/client/dist/commands/invoke.js +58 -58
- package/packages/client/dist/git/epic-execution-checkout.d.ts +3 -0
- package/packages/client/dist/git/epic-execution-checkout.js +1 -0
- package/packages/client/dist/git/epic-state-recovery.d.ts +3 -1
- package/packages/client/dist/git/epic-state-recovery.js +2 -2
- package/packages/client/dist/git/published-story-reconciliation.d.ts +7 -6
- package/packages/client/dist/git/published-story-reconciliation.js +5 -5
- package/packages/client/dist/git/story-write-set-extension.js +1 -1
- package/packages/client/dist/runner/headless/run-yoloop.d.ts +26 -6
- package/packages/client/dist/runner/headless/run-yoloop.js +4 -4
- package/packages/client/dist/yoloop/target-normalization.d.ts +1 -0
- package/packages/client/dist/yoloop/target-normalization.js +1 -1
- package/packages/client/dist/yoloop/yoloop-client-state-store.d.ts +2 -6
- package/packages/client/dist/yoloop/yoloop-client-state-store.js +1 -1
- package/packages/shared/dist/yoloop/execution-plan-v4-contract.js +332 -0
- package/targets-stubs/antigravity/gemini.md +1 -1
- package/targets-stubs/antigravity/neocortex.md +1 -1
- package/targets-stubs/antigravity/skill/SKILL.md +1 -1
- package/targets-stubs/claude-code/neocortex-root.agent.yaml +1 -1
- package/targets-stubs/claude-code/neocortex-root.md +2 -2
- package/targets-stubs/claude-code/neocortex-sentinel.md +1 -1
- package/targets-stubs/claude-code/neocortex.agent.yaml +1 -1
- package/targets-stubs/claude-code/neocortex.md +2 -2
- package/targets-stubs/codex/AGENTS.md +1 -1
- package/targets-stubs/codex/neocortex.toml +1 -1
- package/targets-stubs/cursor/agent.md +2 -2
- package/targets-stubs/deepseek-harness/SKILL.md +1 -1
- package/targets-stubs/gemini-cli/agent.md +2 -2
- package/targets-stubs/gemini-cli/agents/neocortex.md +2 -2
- package/targets-stubs/grok/SKILL.md +1 -1
- package/targets-stubs/kimi/neocortex.md +1 -1
- package/targets-stubs/openclaw/SKILL.md +1 -1
- package/targets-stubs/opencode/neocortex-root.md +2 -2
- package/targets-stubs/opencode/neocortex.md +2 -2
- package/targets-stubs/vscode/neocortex.agent.md +2 -2
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { GitLifecycleRuntimeDocument } from './git-lifecycle-store.js';
|
|
2
|
+
/** The registered epic branch identifies the root even when it is linked. */
|
|
3
|
+
export declare function resolveEpicExecutionCheckout(projectRoot: string, epicId: string, runtime: GitLifecycleRuntimeDocument): Promise<string | undefined>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{execFile as _}from"node:child_process";import{realpath as n}from"node:fs/promises";import{resolve as v}from"node:path";import{promisify as b}from"node:util";const I=b(_);async function y(a,p,c){const m=c.epics[p],s=m?.execution_branch;if(m?.branch_mode!=="epic"||!s||["GIT_DIR","GIT_WORK_TREE","GIT_COMMON_DIR"].some(i=>process.env[i]))return;const u=`refs/heads/${s}`,r=async(i,o)=>(await I("git",o,{cwd:i,encoding:"utf8",timeout:8e3,maxBuffer:1024*1024,env:{...process.env,GIT_OPTIONAL_LOCKS:"0",GIT_TERMINAL_PROMPT:"0"}})).stdout;try{const o=(await r(a,["worktree","list","--porcelain","-z"])).split("\0\0").map(e=>e.split("\0")).filter(e=>e.includes(`branch ${u}`)),l=o[0]?.[0];if(o.length!==1||!l?.startsWith("worktree ")||o[0].some(e=>e==="prunable"||e.startsWith("prunable ")))return;const t=await n(l.slice(9));if(Object.values(c.storyWorktrees?.entries??{}).some(e=>e.temporaryBranch===s||v(e.worktreePath)===t))return;const[f,h,d,w]=await Promise.all([r(t,["symbolic-ref","--quiet","HEAD"]),r(t,["rev-parse","--show-toplevel"]),r(a,["rev-parse","--path-format=absolute","--git-common-dir"]),r(t,["rev-parse","--path-format=absolute","--git-common-dir"])]);return f.trim()!==u||await n(h.trim())!==t||await n(d.trim())!==await n(w.trim())?void 0:t}catch{return}}export{y as resolveEpicExecutionCheckout};
|
|
@@ -3,4 +3,6 @@
|
|
|
3
3
|
* The current branch and target spec must agree with that exact HEAD/index.
|
|
4
4
|
* No Git checkout operation, history search, or state synthesis participates.
|
|
5
5
|
*/
|
|
6
|
-
export declare function reconcileMissingTrackedEpicState(projectRoot: string, args: string
|
|
6
|
+
export declare function reconcileMissingTrackedEpicState(projectRoot: string, args: string, options?: {
|
|
7
|
+
preview?: boolean;
|
|
8
|
+
}): boolean;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{execFileSync as
|
|
2
|
-
`))))return!1;const
|
|
1
|
+
import{execFileSync as U}from"node:child_process";import{randomUUID as V}from"node:crypto";import{closeSync as W,fstatSync as X,fsyncSync as j,linkSync as J,lstatSync as l,openSync as K,readFileSync as Z,realpathSync as m,unlinkSync as Q,writeFileSync as ee}from"node:fs";import{dirname as te,join as P}from"node:path";import{parseYoloopInvocation as re,parseYoloStoryInvocation as se}from"../yoloop/target-normalization.js";import{GOVERNANCE_RUNTIME_MAX_PROJECT_STATE_BYTES as L,GOVERNANCE_STATE_PATH as w}from"./governance-runtime-store.js";import{readGitLifecycleRuntimeSync as ne}from"./git-lifecycle-store.js";const k=/^[a-f0-9]{40}(?:[a-f0-9]{24})?$/,oe=/^@?(docs\/epics\/epic-(P[1-9][0-9]*)\.md)$/u,ie=["GIT_DIR","GIT_WORK_TREE","GIT_COMMON_DIR","GIT_INDEX_FILE"];function h(s){return s&&typeof s=="object"&&!Array.isArray(s)?s:void 0}function ce(s,i,A,u){const E=h(JSON.parse(s.toString("utf8"))),r=h(h(E?.epics)?.[i]),p=h(E?.stories);return r?.id===i&&r.branch_mode==="epic"&&r.execution_branch===A&&Array.isArray(r.stories)&&r.stories.length>0&&p!==void 0&&(!u||r.stories.includes(u))&&r.stories.every(a=>{if(typeof a!="string"||!a.startsWith(`${i}.`))return!1;const f=h(p[a]);return(f?.epic_id??f?.epic)===i})}function me(s,i,A={}){if(ie.some(t=>process.env[t]))return!1;const u=re(i)?.remainder??"",E=oe.exec(u),r=/^@?(P[1-9][0-9]*)$/u.exec(u)?.[1],p=se(i)?.remainder??"",a=/^@?(?:\.\/)?docs\/stories\/(P[1-9][0-9]*(?:\.[0-9]+)+)\.story\.md$/u.exec(p)?.[1]??/^@?(P[1-9][0-9]*(?:\.[0-9]+)+)$/u.exec(p)?.[1],f=E?.[2]??r??a?.split(".")[0];if(!f)return!1;const v=`docs/epics/epic-${f}.md`;let n;try{const t=m(s),b=e=>U("git",e,{cwd:t,stdio:["ignore","pipe","ignore"],timeout:3e3,maxBuffer:L,env:{...process.env,GIT_OPTIONAL_LOCKS:"0",GIT_NO_LAZY_FETCH:"1"}}),y=e=>b(e).toString("utf8");if(m(y(["rev-parse","--show-toplevel"]).trim())!==t)return!1;const x=P(t,w),c=te(x),S=P(t,v),O=l(c),C=()=>{const e=l(S);if(!e.isFile()||m(S)!==S||e.size>L)throw new Error("unsafe-epic-spec");return Z(S)};if(!O.isDirectory()||m(c)!==c||l(x,{throwIfNoEntry:!1}))return!1;const F=()=>y(["rev-parse","--verify","HEAD^{commit}"]).trim(),z=()=>y(["symbolic-ref","--quiet","HEAD"]).trim(),R=F(),D=z();if(!k.test(R)||!D.startsWith("refs/heads/"))return!1;const d=[w,v],B=()=>y(["ls-files","-v","--stage","-z","--",...d]),M=B(),q=new Set(M.split("\0").filter(Boolean)),Y=y(["ls-tree","-z",R,"--",...d]).split("\0").filter(Boolean),T=new Map;for(const e of Y){const o=/^(100644) blob ([a-f0-9]+)\t(.+)$/u.exec(e);if(!o||!k.test(o[2])||!d.includes(o[3])||!q.has(`H ${o[1]} ${o[2]} 0 ${o[3]}`))return!1;T.set(o[3],o[2])}if(T.size!==d.length||q.size!==d.length)return!1;const H=b(["cat-file","blob",T.get(v)]),G=C();if(!G.equals(H)&&!G.equals(Buffer.from(H.toString("utf8").replace(/\r?\n/g,`\r
|
|
2
|
+
`))))return!1;const N=b(["cat-file","blob",T.get(w)]);if(!ce(N,f,D.slice(11),a))return!1;try{ne(t,{required:!0})}catch(e){if(!(e instanceof Error)||e.message!=="git-lifecycle-runtime-missing")return!1}if(A.preview)return!0;const _=P(c,`.state-recovery-${V()}.tmp`),g=K(_,"wx",384);try{n={path:_,stat:X(g)},ee(g,N),j(g)}finally{W(g)}if(F()!==R||z()!==D||B()!==M)return!1;const $=l(c);if(!$.isDirectory()||$.dev!==O.dev||$.ino!==O.ino||m(c)!==c||!C().equals(G))return!1;const I=l(_);return!I.isFile()||I.dev!==n.stat.dev||I.ino!==n.stat.ino||I.size!==N.length?!1:(J(_,x),!0)}catch{return!1}finally{if(n)try{const t=l(n.path);t.dev===n.stat.dev&&t.ino===n.stat.ino&&Q(n.path)}catch{}}}export{me as reconcileMissingTrackedEpicState};
|
|
@@ -2,11 +2,7 @@ import { type PublishedStoryReconciliation } from './git-lifecycle-store.js';
|
|
|
2
2
|
export type { PublishedStoryReconciliation } from './git-lifecycle-store.js';
|
|
3
3
|
/** Bind a historical C13 artifact to the proof as evidence, never as fresh P205. */
|
|
4
4
|
export declare function historicalStoryQaDigest(raw: string, storyId: string): string | undefined;
|
|
5
|
-
/**
|
|
6
|
-
* Reconcile one explicitly targeted epic, only from its primary checkout. The
|
|
7
|
-
* old graph and original child are untouched. The durable audit receipt is
|
|
8
|
-
* returned for scheduling only after a fresh physical verification each time.
|
|
9
|
-
*/
|
|
5
|
+
/** A physical epic root alone may publish a reconciliation receipt. */
|
|
10
6
|
export declare function reconcilePublishedStoriesForYoloop(projectRoot: string, args: string): Promise<readonly PublishedStoryReconciliation[]>;
|
|
11
7
|
type PublishedCheckpointRecovery = {
|
|
12
8
|
readonly status: 'recovered';
|
|
@@ -23,6 +19,11 @@ type PublishedCheckpointRecovery = {
|
|
|
23
19
|
* integration. Reuse checkpoint recovery before scheduling a replacement task.
|
|
24
20
|
*/
|
|
25
21
|
export declare function recoverPublishedCheckpointForYoloop(projectRoot: string, args: string, reconciliations: readonly PublishedStoryReconciliation[]): Promise<PublishedCheckpointRecovery | undefined>;
|
|
26
|
-
/**
|
|
22
|
+
/** Child phases revalidate evidence from the registered epic checkout. */
|
|
27
23
|
export declare function revalidatePublishedStoriesForYolo(projectRoot: string, args: string): Promise<readonly PublishedStoryReconciliation[]>;
|
|
24
|
+
/** Shared preflight for explicit story and epic targets, including resumes. */
|
|
25
|
+
export declare function reconcilePublishedWorkflowState(projectRoot: string, args: string): Promise<{
|
|
26
|
+
reconciliations: readonly PublishedStoryReconciliation[];
|
|
27
|
+
checkpoint?: PublishedCheckpointRecovery;
|
|
28
|
+
}>;
|
|
28
29
|
export declare function revalidatePublishedStoryDependencies(projectRoot: string, epicId: string): Promise<readonly PublishedStoryReconciliation[]>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import{execFile as se}from"node:child_process";import{createHash as ce}from"node:crypto";import{realpath as
|
|
2
|
-
`).filter(Boolean),
|
|
3
|
-
`);if(
|
|
4
|
-
`),["Neocortex-Story","Neocortex-Epic","Neocortex-Execution-Branch","Neocortex-Prepared-Base","Neocortex-Bundle-Digest","Neocortex-Graph-Revision","Neocortex-Claim-Revision"]);if(!
|
|
5
|
-
`).filter(Boolean);if(
|
|
1
|
+
import{execFile as se}from"node:child_process";import{createHash as ce}from"node:crypto";import{realpath as z}from"node:fs/promises";import{promisify as ue}from"node:util";import{parseYoloopInvocation as de,parseYoloStoryInvocation as he}from"../yoloop/target-normalization.js";import{resolveEpicExecutionCheckout as G}from"./epic-execution-checkout.js";import{recoverLegacyDirectYoloStoryCheckpoint as fe,resolveDirectYoloIntegrationAuthority as le,verifyDirectYoloIntegrationCommit as pe}from"./direct-yolo-checkpoint.js";import{resolveRemoteHeadFreshOptional as Z}from"./epic-lifecycle-evidence.js";import{appendStoryWorktreeEvidence as ye,isStoryWorktreeEvidenceReceiptRecord as we,mutateGitLifecycleRuntime as me,publishedStoryReconciliationId as W,readGitLifecycleRuntime as b,readStoryWorktreeEvidence as V}from"./git-lifecycle-store.js";import{readGovernanceStateSourceSync as ve}from"./governance-runtime-store.js";import{parseNeocortexTrailers as K,trailerValue as C}from"./neocortex-trailers.js";import{StoryWorktreeManager as U}from"./story-worktree-manager.js";const ge=ue(se),q=/^[a-f0-9]{64}$/,H=/^(?:[a-f0-9]{40}|[a-f0-9]{64})$/,Se=16;function Y(e){return ce("sha256").update(e).digest("hex")}function k(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:void 0}function xe(e,t){let r;try{r=k(JSON.parse(e))}catch{return}if(!(r?.schemaVersion!==2||r.storyId!==t||r.publicSafe!==!0||r.status!=="qa-passed"||r.safeToContinueYoloop!==!0||!Array.isArray(r.blockingChecks)||r.blockingChecks.length!==0))return Y(e)}function X(e){const t=de(e)?.remainder;return t?.match(/^@?(?:\.\/)?docs\/epics\/epic-([A-Za-z][A-Za-z0-9_-]{0,63})\.md$/)?.[1]??t?.match(/^@?((?:P|EPIC-)[0-9]+)$/i)?.[1]?.toUpperCase()}function j(e){const t=he(e)?.remainder,r=t?.match(/^@?(?:\.\/)?docs\/stories\/([A-Za-z][A-Za-z0-9_-]*(?:\.[A-Za-z0-9_-]+)+)\.story\.md(?:[ \t]+(story-worktree-phase-[12]))?$/)??t?.match(/^@?([A-Za-z][A-Za-z0-9_-]*(?:\.[A-Za-z0-9_-]+)+)$/);return r?{storyId:r[1],phase:!!r[2]}:void 0}async function ke(e,t){const r=X(t);return r?R(e,r,!0):[]}async function Ie(e,t,r){const i=X(t);return i?ee(e,i,r):void 0}async function ee(e,t,r,i){const s=te(e);let u;try{const l=(await s("symbolic-ref","--quiet","--short","HEAD")).trim(),n=await b(e,{required:!0}),v=n.epics[t];if(v?.branch_mode!=="epic"||v.execution_branch!==l||await G(e,t,n)!==await z(e))return;const A=(await s("log","--first-parent","--max-count=16","--format=%H","--fixed-strings",`--grep=Neocortex-Epic: ${t}`,"HEAD")).trim().split(`
|
|
2
|
+
`).filter(Boolean),a=ve(e);if(!a.ok||!a.value)return;const p=k(k(JSON.parse(a.value.toString("utf8")))?.stories),w=[];for(const N of A){if(!H.test(N))continue;const[$,...B]=(await s("show","-s","--format=%P%n%B",N)).split(`
|
|
3
|
+
`);if(!$||!H.test($))continue;const I=K(B.join(`
|
|
4
|
+
`),["Neocortex-Story","Neocortex-Epic","Neocortex-Execution-Branch","Neocortex-Prepared-Base","Neocortex-Bundle-Digest","Neocortex-Graph-Revision","Neocortex-Claim-Revision"]);if(!I.ok)continue;const y=x=>C(I.values,x),h=y("Neocortex-Story");!h||i&&h!==i||!/^[A-Za-z][A-Za-z0-9_-]*\.[A-Za-z0-9._-]+$/.test(h)||y("Neocortex-Epic")!==t||y("Neocortex-Execution-Branch")!==l||y("Neocortex-Prepared-Base")!==$||!["Neocortex-Bundle-Digest","Neocortex-Graph-Revision","Neocortex-Claim-Revision"].every(x=>q.test(y(x)??""))||n.stories[h]?.checkpoint||r.some(x=>x.storyId===h)||k(p?.[h])?.epic_id!==t||w.push({storyId:h,headSha:N,executionBranch:l})}if(w.length!==1)return;u=w[0]}catch{return}const{storyId:f,headSha:c,executionBranch:d}=u;try{const l=await Z(s,d);if(!l)return;try{await s("merge-base","--is-ancestor",c,l)}catch{return}}catch{return{status:"pending",storyId:f,headSha:c,reasonCode:"direct-yolo-recovery-remote-proof-unavailable"}}const m=await fe({projectRoot:e,storyId:f,commitSha:c});if(m.ok)return{status:"recovered",storyId:f,headSha:c};if(m.reasonCode==="direct-yolo-checkpoint-conflict"){const l=await b(e,{required:!0});if(k(l.stories[f]?.checkpoint)?.headSha===c)return}return{status:"pending",storyId:f,headSha:c,reasonCode:m.reasonCode}}function te(e){return async(...t)=>(await ge("git",[...t],{cwd:e,encoding:"utf8",timeout:8e3,maxBuffer:4*1024*1024,env:{...process.env,GIT_OPTIONAL_LOCKS:"0",GIT_TERMINAL_PROMPT:"0"}})).stdout}async function Ge(e,t){return j(t)?.phase!==!0?[]:(await be(e,t)).reconciliations}async function be(e,t){const r=j(t);if(!r){const s=await ke(e,t),u=await Ie(e,t,s);return{reconciliations:s,checkpoint:u}}const i=r.storyId.split(".")[0];if(!r.phase){const s=await R(e,i,!0),u=await ee(e,i,s,r.storyId);return{reconciliations:s,checkpoint:u}}try{const s=await b(e,{required:!0}),u=await G(e,i,s),f=await z(e),c=Object.values(s.storyWorktrees?.entries??{}).filter(d=>d.storyId===r.storyId&&d.state==="active"&&d.worktreePath===f);return{reconciliations:u&&c.length===1?await Ae(u,i):[]}}catch{return{reconciliations:[]}}}function Ae(e,t){return R(e,t,!1)}async function R(e,t,r){const i=te(e),s=async c=>(await i("rev-parse","--verify","--quiet",`${c}^{commit}`)).trim(),u=async(c,d)=>{try{return await i("merge-base","--is-ancestor",c,d),!0}catch{return!1}},f=[];try{const c=(await i("symbolic-ref","--quiet","--short","HEAD")).trim(),d=await s("HEAD"),m=await b(e,{required:!0});if(m.epics[t]?.execution_branch!==c||await G(e,t,m)!==await z(e))return[];const l=Object.values(m.storyWorktrees?.entries??{}).filter(n=>n.epicId===t&&n.executionBranch===c&&n.state==="active");if(l.length>Se)return[];for(const n of l)try{const v=await b(e,{required:!0});if(v.stories[n.storyId]?.checkpoint||l.filter(o=>o.storyId===n.storyId).length!==1||Date.parse(n.expiresAt)>Date.now())continue;const A=k(v.epics[t]?.branch_lease);if(A&&Date.parse(String(A.expiresAt))>Date.now())continue;const a=V(v,t)?.receipts??[];if(a.some(o=>o.kind==="integration-receipt"&&o.storyId===n.storyId))continue;const p=a.filter(o=>o.kind==="phase-one-receipt"&&o.storyId===n.storyId&&o.leaseId===n.leaseId&&o.graphRevision===n.graphRevision);if(p.length!==1)continue;const w=p[0],N=String(w.graphRevision),$=String(w.receiptId);if(!q.test(N)||!H.test(String(w.headSha))||w.specRef!==`docs/stories/${n.storyId}.spec.md`)continue;const B=a.filter(o=>o.kind==="published-story-reconciliation"&&o.storyId===n.storyId&&o.graphRevision===N);if(B.length>1||!r&&B.length===0)continue;const I=await le(e,n.storyId),y=I.originBinding;if(I.epicId!==t||I.executionBranch!==c||!y||y.originBranch===c||!await u(y.originHeadSha,d))continue;const h=await new U({projectRoot:e}).probe(n.leaseId);if(!h.ok||h.value.ownership!=="proven"||h.value.clean!==!0||!h.value.headSha||!H.test(h.value.headSha)||!await u(String(w.headSha),h.value.headSha))continue;const x=(await i("log","--max-count=2","--fixed-strings","--format=%H",`--grep=Neocortex-Story-Worktree-Tip: ${h.value.headSha}`,`${y.originHeadSha}..${d}`)).trim().split(`
|
|
5
|
+
`).filter(Boolean);if(x.length!==1||!H.test(x[0]))continue;const g=x[0],re=(await i("show","-s","--format=%P",g)).trim();if(!H.test(re))continue;const D=K(await i("show","-s","--format=%B",g),["Neocortex-Story-Worktree-Tip","Neocortex-Graph-Revision","Neocortex-Review-Artifact-Digest"]);if(!D.ok||C(D.values,"Neocortex-Story-Worktree-Tip")!==h.value.headSha)continue;const E=C(D.values,"Neocortex-Graph-Revision"),F=C(D.values,"Neocortex-Review-Artifact-Digest");if(!E||!q.test(E)||!F||!q.test(F))continue;const ie=(await i("rev-parse",`${g}^{tree}`)).trim(),ne=(await i("rev-parse",`${h.value.headSha}^{tree}`)).trim();if(ie!==ne)continue;const L=await pe(I,n.storyId,g,{expectedGraphRevision:E});if(!L.ok)continue;const oe=k(JSON.parse(await i("show",`${g}:.neocortex/state.json`))),J=k(k(oe?.stories)?.[n.storyId]);if(J?.epic_id!==t||JSON.stringify(J.depends_on??[])!==JSON.stringify(I.story.depends_on??[]))continue;const _=String(w.specRef),P=`docs/stories/${n.storyId}.story.md`;if(Y(await i("show",`${g}:${_}`))!==w.specDigest||Y(await i("show",`${d}:${_}`))!==w.specDigest||await i("show",`${g}:${P}`)!==await i("show",`${d}:${P}`))continue;await i("diff","--quiet","HEAD","--",".neocortex/state.json",_,P);const M=xe(await i("show",`${g}:.neocortex/stories/${n.storyId}/qa-gate-result.json`),n.storyId);if(!M)continue;const S=await Z(i,y.originBranch);if(!S)continue;try{await s(S)}catch{if(!r||(await i("fetch","--quiet","--no-tags","--no-write-fetch-head","--refmap=","origin",S),await s(S)!==S))continue}if(!await u(y.originHeadSha,S)||!await u(g,S))continue;const O={schemaVersion:1,kind:"published-story-reconciliation",epicId:t,storyId:n.storyId,graphRevision:N,historicalGraphRevision:E,phaseOneReceiptId:$,executionBranch:c,executionHeadSha:d,originBranch:y.originBranch,originHeadSha:S,commitSha:g,bundleDigest:L.value.bundleDigest,historicalQaDigest:M},Q=async()=>{if(await s("HEAD")!==d||await s(`refs/heads/${c}`)!==d||await Z(i,y.originBranch)!==S)throw new Error("published-story-reconciliation-ref-raced");const o=await new U({projectRoot:e}).probe(n.leaseId);if(!o.ok||o.value.ownership!=="proven"||o.value.clean!==!0||o.value.headSha!==h.value.headSha)throw new Error("published-story-reconciliation-worktree-raced");await i("diff","--quiet","HEAD","--",".neocortex/state.json",_,P)};if(B[0]){const o=B[0],ae={...O,executionHeadSha:o.executionHeadSha,originHeadSha:o.originHeadSha};if(o.receiptId!==W(ae)||!await u(o.executionHeadSha,d)||!await u(o.originHeadSha,S)||(await Q(),(await b(e,{required:!0})).revision!==v.revision))continue;f.push(o);continue}const T=Object.freeze({...O,receiptId:W(O)});if(!we(T))continue;await me(e,o=>{ye(o,t,{receipts:[T]})},{expectedRevision:v.revision,preCommit:Q}),f.push(T)}catch{}}catch{}return f.length===0?f:Ne(e,t,f,i)}async function Ne(e,t,r,i){try{const s=await b(e,{required:!0}),u=(V(s,t)?.receipts??[]).filter(a=>a.kind==="integration-receipt"&&a.outcome==="integrated").sort((a,p)=>Number(p.integrationIndex)-Number(a.integrationIndex));if(u.length===0)return r;const f=String(u[0].epicHeadAfterSha),c=r[0].executionBranch;if(s.epics[t]?.execution_branch!==c)return r;const d=`refs/heads/${c}`,m=(await i("rev-parse","--verify",d)).trim(),l=async(a,p)=>{if(a===p)return!0;try{return await i("merge-base","--is-ancestor",a,p),!0}catch{return!1}},n=[...new Set([f,...r.map(a=>a.commitSha)])],v=[...n,...r.map(a=>a.executionHeadSha)];if(!(await Promise.all(v.map(a=>l(a,m)))).every(Boolean))return r;let A=m;for(const a of n)if((await Promise.all(n.map(p=>l(p,a)))).every(Boolean)){A=a;break}return(await i("rev-parse","--verify",d)).trim()!==m||(await b(e,{required:!0})).revision!==s.revision?r:r.map(a=>{const p={...a,syncBaseSha:A,syncIntegrationHeadSha:f};return Object.freeze({...p,receiptId:W(p)})})}catch{return r}}export{xe as historicalStoryQaDigest,ke as reconcilePublishedStoriesForYoloop,be as reconcilePublishedWorkflowState,Ie as recoverPublishedCheckpointForYoloop,Ge as revalidatePublishedStoriesForYolo,Ae as revalidatePublishedStoryDependencies};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{execFile as O}from"node:child_process";import{createHash as V}from"node:crypto";import{readFile as
|
|
1
|
+
import{execFile as O}from"node:child_process";import{createHash as V}from"node:crypto";import{readFile as x,realpath as A}from"node:fs/promises";import{join as v,resolve as I}from"node:path";import{resolveEpicExecutionCheckout as J}from"./epic-execution-checkout.js";import{acquireGitLifecyclePhysicalIntegrationLockWithin as Z,ensureRuntimeStory as K,isStoryWorktreeIntegrationReceiptRecord as X,isStoryWriteSetExtension as Q,isStoryWriteSetExtensionPath as W,mutateGitLifecycleRuntime as ee,readGitLifecycleRuntime as _,readStoryWorktreeEvidence as $,releaseGitLifecyclePhysicalIntegrationLock as te,STORY_WRITE_SET_MAX_ENTRIES as k,storyWriteSetExtensionDigest as B,storyWriteSetExtensionPaths as q,verifyGitLifecyclePhysicalIntegrationLock as re}from"./git-lifecycle-store.js";const C=/^P[1-9][0-9]*(?:\.[0-9]+)+$/;class D extends Error{reasonCode;constructor(t){super(t),this.reasonCode=t}}function c(e){throw new D(e)}function z(e,t){return new Promise((r,n)=>{O("git",[...t],{cwd:e,encoding:"utf8",timeout:3e4,env:{...process.env,GIT_TERMINAL_PROMPT:"0",LC_ALL:"C"}},(i,o)=>i?n(new D("story-write-set-extension-not-root")):r(String(o).trim()))})}function l(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:void 0}async function L(e,t,r){await J(e,t.split(".")[0],r)!==e&&c("story-write-set-extension-not-root")}function M(e){try{return Q(e)}catch{return!1}}function ne(e){return V("sha256").update([...e].sort().join("\0")).digest("hex")}function N(e,t,r,n,i){const o=l(l(t.stories)?.[r]);o||c("story-write-set-extension-story-missing");const s=typeof o.epic_id=="string"?o.epic_id:r.split(".")[0];r.startsWith(`${s}.`)||c("story-write-set-extension-story-missing");const a=e.stories[r];($(e,s)?.receipts??[]).filter(X).some(f=>f.storyId===r&&f.outcome==="integrated")&&c("story-write-set-extension-story-integrated"),(a?.checkpoint||o.checkpoint)&&c("story-write-set-extension-checkpoint-accepted");const w=l(e.epics[s]?.branch_lease);w&&Date.parse(String(w.expiresAt))>i&&c("story-write-set-extension-writer-active"),a?.write_set_extension!==void 0&&!M(a.write_set_extension)&&c("story-write-set-extension-invalid");const u=q(a);u.some(f=>!n.includes(f))&&c("story-write-set-extension-not-superset");const d=Array.isArray(o.files_to_modify)?o.files_to_modify.filter(f=>typeof f=="string"):[],h=[...new Set([...d,...n])].sort();return h.length>k&&c("story-write-set-extension-too-large"),{epicId:s,union:h,unchanged:u.length===n.length}}async function le(e){let t=I(e.projectRoot),r;try{(typeof e.storyId!="string"||!C.test(e.storyId))&&c("story-write-set-extension-story-invalid"),(!Array.isArray(e.paths)||e.paths.length===0||e.paths.length>k||e.paths.some(y=>!W(y)))&&c("story-write-set-extension-path-invalid");const n=[...new Set(e.paths)].sort();t=await A(t);const i=await A(await z(t,["rev-parse","--absolute-git-dir"])),o=await A(await z(t,["rev-parse","--path-format=absolute","--git-common-dir"])),s=i!==o;s&&await L(t,e.storyId,await _(t,{required:!0}));const a=await F({projectRoot:t,storyId:e.storyId});a.ok||c(a.reasonCode);const g=new Date(e.nowIso??Date.now()).toISOString(),w=v(t,".neocortex","state.json"),u=async()=>{const y=await x(w,"utf8"),m=l(JSON.parse(y))??c("story-write-set-extension-state-invalid"),E=await _(t,{required:!0});return s&&await L(t,e.storyId,E),{trackedBytes:y,tracked:m,runtime:E,plan:N(E,m,e.storyId,n,Date.now())}},d=B(n),h=(y,m)=>({ok:!0,value:Object.freeze({storyId:e.storyId,epicId:y.epicId,outcome:m,extensionPathCount:n.length,extensionDigest:d,authorizedPathCount:y.union.length,claimRevision:ne(y.union)})}),f=await u();if(f.plan.unchanged)return h(f.plan,"unchanged");const p=`write-set-extension-${d.slice(0,40)}`;r=await Z(t,{kind:"direct",storyId:e.storyId,sessionId:p,idempotencyKey:p,expiresAt:new Date(Date.now()+300*1e3).toISOString(),persistent:!1},e.lockWait),r.ok||c(r.reasonCode==="git-lifecycle-integration-backpressure"?"story-write-set-extension-backpressure":"story-write-set-extension-lock-failed");const P=r,{trackedBytes:H,tracked:Y,runtime:b,plan:R}=await u();if(R.unchanged)return h(R,"unchanged");await e.beforeCas?.();const U={schemaVersion:1,kind:"root-write-set-extension",paths:n,digest:d,approvedAt:g,approvedBy:"root_agent"};try{await ee(t,y=>{N(y,Y,e.storyId,n,Date.now()).unchanged&&c("story-write-set-extension-raced"),K(y,e.storyId).write_set_extension=U},{expectedRevision:b.revision,preCommit:async()=>{await re(P.path,P.owner)||c("story-write-set-extension-lock-raced"),s&&await L(t,e.storyId,b),await x(w,"utf8")!==H&&c("story-write-set-extension-raced")}})}catch(y){throw y instanceof Error&&y.message==="git-lifecycle-runtime-revision-conflict"&&c("story-write-set-extension-raced"),y}return h(R,"recorded")}catch(n){if(n instanceof D)return{ok:!1,reasonCode:n.reasonCode};const i=n instanceof Error?n.message:"";return/^git-lifecycle-[a-z0-9-]{1,80}$/.test(i)?{ok:!1,reasonCode:i}:{ok:!1,reasonCode:"story-write-set-extension-failed"}}finally{r?.ok&&await te(r.path,r.owner).catch(()=>{})}}const se="story-write-set-manual-edit-refused",ie="story-write-set-manual-edit-unverified",oe="neocortex-client story-checkpoint extend-write-set",T=/^[A-Za-z0-9][A-Za-z0-9._/-]{0,199}$/;function S(e,t){return new Promise(r=>{O("git",[...t],{cwd:e,encoding:"utf8",timeout:3e4,maxBuffer:64*1024*1024,env:{...process.env,GIT_TERMINAL_PROMPT:"0",LC_ALL:"C"}},(n,i)=>r(n?void 0:String(i)))})}function j(e){if(e!==void 0)try{return l(JSON.parse(e))}catch{return}}function G(e){const t=l(e.stories)??{},r=new Map;for(const[n,i]of Object.entries(t)){const o=l(i)?.files_to_modify;o!==void 0&&r.set(n,Array.isArray(o)?JSON.stringify([...new Set(o.filter(s=>typeof s=="string"))].sort()):"!invalid")}return r}async function F(e){let t=I(e.projectRoot);const r={ok:!1,reasonCode:ie};if(typeof e.storyId!="string"||!C.test(e.storyId)||e.candidateRef!==void 0&&(!T.test(e.candidateRef)||e.candidateRef.includes("..")))return r;const n=e.candidateRef===void 0?await x(v(t,".neocortex","state.json"),"utf8").catch(()=>{}):await S(t,["show",`refs/heads/${e.candidateRef}:.neocortex/state.json`]),i=j(n);if(!i)return r;const o=l(l(i.stories)?.[e.storyId]),s=typeof o?.epic_id=="string"?o.epic_id:e.storyId.split(".")[0],a=l(l(i.epics)?.[s])?.execution_branch,g=e.candidateRef===void 0?"HEAD":`refs/heads/${e.candidateRef}`;let w;if(typeof a=="string"&&T.test(a)&&!a.includes("..")&&await S(t,["rev-parse","--verify","--quiet",`refs/heads/${a}^{commit}`])!==void 0){const f=(await S(t,["merge-base",g,`refs/heads/${a}`]))?.trim();if(!f||!/^[a-f0-9]{40,64}$/.test(f))return r;w=f}else if(e.candidateRef===void 0)w="HEAD";else return r;const u=j(await S(t,["show",`${w}:.neocortex/state.json`]));if(!u)return r;const d=G(u),h=G(i);for(const[f,p]of d)if(h.get(f)!==p)return{ok:!1,reasonCode:se};return{ok:!0,value:Object.freeze({storiesCompared:d.size})}}async function we(e){let t=I(e.projectRoot);if(typeof e.storyId!="string"||!C.test(e.storyId))return{ok:!1,reasonCode:"story-write-set-extension-story-invalid"};if(!Array.isArray(e.paths)||e.paths.length===0||e.paths.length>k||e.paths.some(d=>!W(d)))return{ok:!1,reasonCode:"story-write-set-extension-path-invalid"};const r=await F({projectRoot:t,storyId:e.storyId});if(!r.ok)return r;const n=j(await x(v(t,".neocortex","state.json"),"utf8").catch(()=>{}));if(!n)return{ok:!1,reasonCode:"story-write-set-extension-state-invalid"};const i=l(l(n.stories)?.[e.storyId]);if(!i)return{ok:!1,reasonCode:"story-write-set-extension-story-missing"};const o=typeof i.epic_id=="string"?i.epic_id:e.storyId.split(".")[0];if(!e.storyId.startsWith(`${o}.`))return{ok:!1,reasonCode:"story-write-set-extension-story-missing"};let s;try{const h=(await _(t)).stories[e.storyId];if(h?.write_set_extension!==void 0&&!M(h.write_set_extension))return{ok:!1,reasonCode:"story-write-set-extension-invalid"};s=q(h)}catch{return{ok:!1,reasonCode:"story-write-set-extension-state-invalid"}}const a=new Set(Array.isArray(i.files_to_modify)?i.files_to_modify.filter(d=>typeof d=="string"):[]),g=new Set([...a,...s]),w=[...new Set(e.paths)].filter(d=>!g.has(d)),u=[...new Set([...s,...e.paths.filter(d=>!a.has(d))])].sort();return a.size+u.length>k?{ok:!1,reasonCode:"story-write-set-extension-too-large"}:{ok:!0,value:Object.freeze({schemaVersion:1,kind:"story-write-set-extension-request",storyId:e.storyId,epicId:o,outcome:w.length===0?"already-authorized":"requested",paths:Object.freeze(u),requestedPathCount:w.length,digest:B(u),requestedBy:"story_child",applyCommand:u.length>0?`${oe} --story ${e.storyId} --paths ${u.join(",")}`:""})}}async function he(e,t){try{const r=await _(I(e)),n=t.split(".")[0],o=($(r,n)?.receipts??[]).map(s=>l(s)).filter(s=>s?.kind==="story-worktree-lease"&&s.storyId===t&&typeof s.temporaryBranch=="string"&&T.test(s.temporaryBranch)).sort((s,a)=>String(s.acquiredAt??"").localeCompare(String(a.acquiredAt??""))).at(-1);return o?String(o.temporaryBranch):void 0}catch{return}}export{se as STORY_WRITE_SET_MANUAL_EDIT_REFUSED,ie as STORY_WRITE_SET_MANUAL_EDIT_UNVERIFIED,F as detectStoryWriteSetManualEdit,le as extendStoryWriteSet,we as requestStoryWriteSetExtension,he as storyWorktreeTemporaryBranchForManualEditGate};
|
|
@@ -150,6 +150,24 @@ export interface RunYoloopExecutionPhaseSummary {
|
|
|
150
150
|
readonly reasonCodes: readonly string[];
|
|
151
151
|
readonly publicSafe: true;
|
|
152
152
|
}
|
|
153
|
+
interface YoloopDriverResult {
|
|
154
|
+
readonly status: Extract<ContinuityHeadlessExecutionAttemptStatus, 'completed' | 'failed' | 'backoff'>;
|
|
155
|
+
readonly receiptStatus: RunYoloopExecutionReceipt['outcome'];
|
|
156
|
+
readonly reasonCode: string;
|
|
157
|
+
readonly publicSummary: string;
|
|
158
|
+
readonly retryable: boolean;
|
|
159
|
+
readonly retryNotBeforeAt?: string;
|
|
160
|
+
readonly durationMs: number;
|
|
161
|
+
readonly counts: RunYoloopAggregateCounts;
|
|
162
|
+
readonly workerPoolSummary: RunYoloopWorkerPoolSummary;
|
|
163
|
+
readonly hashes: Readonly<Record<string, string>>;
|
|
164
|
+
readonly redactionSummary: readonly HeadlessRedactionEvidence[];
|
|
165
|
+
readonly relativePaths: readonly string[];
|
|
166
|
+
readonly childStoryIds: readonly string[];
|
|
167
|
+
readonly stateTransitions: readonly RunYoloopDriverState[];
|
|
168
|
+
readonly terminalClass?: 'release-blocked';
|
|
169
|
+
readonly releaseBlocked?: ReleaseBlockedResultV1;
|
|
170
|
+
}
|
|
153
171
|
/** Mirror of the server `STORY_WORKTREE_DISPATCH_DOMAIN` (parity-tested). */
|
|
154
172
|
export declare const YOLOOP_V4_STORY_WORKTREE_DISPATCH_DOMAIN: "neocortex.p225.story-worktree-dispatch.v1";
|
|
155
173
|
/** P227.23 (ADR-4): the server dispatch id for one story at one graph revision. */
|
|
@@ -186,6 +204,13 @@ export declare function executeYoloopV4IntegrationOrder(plan: unknown, options:
|
|
|
186
204
|
export declare function isCanonicalDelegatedStoryPrompt(prompt: string): boolean;
|
|
187
205
|
export declare function defaultYoloopRootInvoker(input: RunYoloopRootInvokeInput, invokeTransport?: RunYoloopRootInvokeTransport): Promise<RunYoloopRootInvokeResult>;
|
|
188
206
|
export declare function runDirectYoloop(options: InvokeOptions): Promise<InvokeResult>;
|
|
207
|
+
/** Driver attempt states and persisted root job states have different lifecycles. */
|
|
208
|
+
export declare function persistDirectYoloopJobOutcome(store: Pick<ContinuitySqliteStore, 'updateJobStatus'>, jobId: string, result: Pick<YoloopDriverResult, 'status' | 'reasonCode' | 'stateTransitions'>, updatedAt: string): import("../../continuity/sqlite-store.js").ContinuitySqliteWriteResult;
|
|
209
|
+
export declare function recordDirectYoloopJobOutcome(store: Pick<ContinuitySqliteStore, 'updateJobStatus'>, jobId: string, result: Pick<YoloopDriverResult, 'status' | 'reasonCode' | 'stateTransitions'>, updatedAt: string): Readonly<{
|
|
210
|
+
reasonCode: "yoloop-runner-outcome-persist-failed";
|
|
211
|
+
originalReasonCode: string | undefined;
|
|
212
|
+
publicSafe: true;
|
|
213
|
+
}> | undefined;
|
|
189
214
|
export declare function runYoloopExecutionPhase(options: RunYoloopExecutionPhaseOptions): Promise<RunYoloopExecutionPhaseSummary>;
|
|
190
215
|
/** P227.23 (L3): public reason for a v4 plan that has nothing to dispatch yet. */
|
|
191
216
|
export declare const YOLOOP_V4_WAITING_REASON_CODE: "story-worktree-v4-waiting";
|
|
@@ -266,10 +291,5 @@ export declare function prepareYoloopV4ChildWorkspace(input: {
|
|
|
266
291
|
readonly graphRevision: string;
|
|
267
292
|
readonly temporaryBranch?: string;
|
|
268
293
|
}): Promise<YoloopV4StoryWorktreeWorkspace>;
|
|
269
|
-
/**
|
|
270
|
-
* P227.23 (DEC-16): validity of a v4 plan with the semantics of shared
|
|
271
|
-
* `validateYoloopExecutionPlanV4(plan).valid`, except that phase and barrier
|
|
272
|
-
* step ids are checked by shape (non-empty, unique, step-id pattern) instead of
|
|
273
|
-
* against the server-owned closed lists. Exported only for the parity test.
|
|
274
|
-
*/
|
|
294
|
+
/** Public step identities are checked by shape; the server binds their exact lists. */
|
|
275
295
|
export declare function isRunnerYoloopV4PlanValid(plan: unknown): boolean;
|