@ornexus/neocortex 4.65.0 → 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 +285 -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
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{createHash as V}from"node:crypto";import{spawn as z}from"node:child_process";import{P205_RELEASE_GATE_BUDGETS as $,P205_ROOT_INVOKE_TIMEOUT_MS as F}from"../../../../shared/dist/yoloop/epic-terminal-git.js";import{createLocalJobConsoleServer as X}from"../local-console.js";const G=Object.freeze(["fake","test","opencode","claude-code"]);function L(e){return e==="yolo"||e==="yolo-branchless-preparation"||e==="yolo-story-worktree-phase-1"||e==="yolo-story-worktree-phase-2"}const l=Object.freeze({OK:"continuity-ok",RUNTIME_EXPLICIT:"headless-runtime-explicit",RUNTIME_ORIGIN:"headless-runtime-origin",RUNTIME_DEFAULT:"headless-runtime-default",RUNTIME_FALLBACK:"headless-runtime-fallback",RUNTIME_UNRESOLVED:"headless-runtime-unresolved",RUNTIME_UNTRUSTED:"headless-runtime-untrusted",MODEL_REJECTED:"headless-model-rejected",DIRECTIVE_REJECTED:"headless-directive-rejected",STORY_WORKTREE_PHASE_BINDING_REQUIRED:"story-worktree-phase-binding-required",PROMPT_REJECTED:"headless-prompt-rejected",ADAPTER_UNAVAILABLE:"headless-adapter-unavailable",RUNTIME_AUTH_REQUIRED:"headless-runtime-auth-required",MANAGED_PROFILE_MISSING:"headless-managed-profile-missing",MANAGED_PROFILE_INVALID:"headless-managed-profile-invalid",APPROVAL_POLICY_INVALID:"headless-approval-policy-invalid",APPROVAL_POLICY_MISMATCH:"headless-approval-policy-mismatch",EXECUTION_CANCELLED:"headless-execution-cancelled",EXECUTION_TIMEOUT:"headless-execution-timeout",EXECUTION_BACKOFF:"headless-execution-backoff",EXECUTION_COMPLETED:"headless-execution-completed",EXECUTION_FAILED:"headless-execution-failed",RECEIPT_REDACTED:"headless-receipt-redacted",YOLOOP_METADATA_INVALID:"headless-yoloop-metadata-invalid",YOLOOP_ISOLATION_VIOLATION:"headless-yoloop-isolation-violation",WORKER_POOL_SERIAL_FALLBACK:"worker-pool-serial-fallback",WORKER_POOL_PARALLEL_ACTIVE:"worker-pool-parallel-active",WORKER_POOL_BACKPRESSURE_PAUSED:"worker-pool-backpressure-paused"}),Y=120,C=240,q=F,w=$.terminalWorkflowMaxDurationMs,J=/^[A-Za-z0-9][A-Za-z0-9._:+/-]{0,119}$/,W=/^docs\/stories\/[A-Za-z0-9._-]+\.story\.md$/,Z=/^docs\/epics\/epic-[A-Za-z0-9._-]+\.md$/,Q=/(raw[_-]?(?:logs?|payloads?)|std(?:out|err)|stack(?:[_-]?trace)?|transcript|objective(?:[_-]?(?:text|body|prompt))|prompt(?:[_-]?(?:body|text))?|private[_-]?(?:urls?|prompts?)|secret|token|password|protected(?:[_-]?(?:field|body|bodies|internals))?|workflow(?:[_-]?body)?|step(?:[_-]?body)?|customer(?:[_-]?(?:pii|data))?|\bpii\b|authorization|api[_-]?key|license[_-]?key|argv|args|executable(?:[_-]?path)?|binary(?:[_-]?path)?|shell|cwd|command[_-]?path|vendor(?:[_-]?(?:payload|corpus|response|output)))/i,k=/(https?:\/\/\S+|(?:^|\s)(?:\/(?:home|Users|media|mnt|tmp|var|etc|private)\/\S+|[A-Za-z]:\\\S+)|ghp_[A-Za-z0-9_]+|sk-[A-Za-z0-9_-]+|-----BEGIN [A-Z ]*PRIVATE KEY-----|authorization\s*:|password\s*=|token\s*=|api[_-]?key\s*=|license[_-]?key\s*=|raw[_-]?(?:logs?)\s*[:=]|transcript|stack\s*trace|stderr:|stdout:|system prompt|workflow body|step body|PROTECTED_|PRIVATE_INTERNALS|CUSTOMER_PII|\bPII\b|VENDOR_CORPUS)/i,D=/(?:[;&|`$<>]|\$\(|\n|\r|\0)/,ee=new Set(["promptKind","targetKind","targetRef","storyId","epicId","runtimeId","modelId","runtimeSource","timeoutMs","receipt","publicSummary","publicSafe"]),te=new Set(["executionId","attemptId","jobId","operationId","idempotencyKey","runnerId","subagentId"]);function re(e){return G.includes(e)}function me(e,r){const t=[],o=[];if(!B(e))return t.push(i("input","unsafe_key","value-denied")),H(l.DIRECTIVE_REJECTED,"Headless adapter input must be a public object.",t);for(const _ of Object.keys(e))ee.has(_)||(o.push(_),t.push(i(_,M(_),"key-denied")));const u=e.publicSafe===!0;u||t.push(i("publicSafe","unsafe_key","value-denied"));const a=h(e.promptKind);!L(a)&&a!=="yoloop"&&t.push(i("promptKind","unsafe_key","value-denied"));const p=h(e.targetKind);p!=="story"&&p!=="epic"&&t.push(i("targetKind","unsafe_key","value-denied"));const s=h(e.targetRef);(!s||!N(s)||D.test(s)||s.includes(".."))&&t.push(i("targetRef","prompt_body","value-denied")),L(a)&&(p!=="story"||!s||!W.test(s))&&t.push(i("targetRef","prompt_body","value-denied")),a==="yoloop"&&(p!=="epic"||!s||!Z.test(s))&&t.push(i("targetRef","prompt_body","value-denied"));const d=x(e.storyId,"storyId",t),f=x(e.epicId,"epicId",t);d&&s&&L(a)&&d!==s.replace(/^docs\/stories\//,"").replace(/\.story\.md$/,"")&&t.push(i("storyId","prompt_body","value-denied")),f&&s&&a==="yoloop"&&f!==s.replace(/^docs\/epics\/epic-/,"").replace(/\.md$/,"")&&t.push(i("epicId","prompt_body","value-denied"));const E=h(e.runtimeId);(!E||!re(E)||r&&E!==r)&&t.push(i("runtimeId","unsafe_key","value-denied"));const b=se(e.modelId,t),y=ne(e.runtimeSource,t),m=ie(e.timeoutMs,t),T=de(e.publicSummary,t),S=ue(e.receipt,t);if(t.length>0||o.length>0||!u||!a||!p||!s||!E){const _=t.some(n=>n.field==="modelId"),g=t.some(n=>n.reason==="prompt_body");return H(_?l.MODEL_REJECTED:g?l.PROMPT_REJECTED:l.DIRECTIVE_REJECTED,g?"Headless adapter target did not match a public prompt shape.":"Headless adapter input failed public-safety validation.",t)}const A={promptKind:a,targetKind:p,targetRef:s,...d?{storyId:d}:{},...f?{epicId:f}:{},runtimeId:E,...b?{modelId:b}:{},...y?{runtimeSource:y}:{},...m?{timeoutMs:m}:{},...S?{receipt:S}:{},...T?{publicSummary:T}:{},publicSafe:!0},R=P(A);return{ok:!0,input:A,prompt:R,promptHash:I(R),reasonCodes:[l.OK],publicSafe:!0}}function P(e){return e.promptKind==="yolo"?`*yolo @${e.targetRef}`:e.promptKind==="yolo-branchless-preparation"?`*yolo @${e.targetRef} branchless-preparation`:e.promptKind==="yolo-story-worktree-phase-1"?`*yolo @${e.targetRef} story-worktree-phase-1`:e.promptKind==="yolo-story-worktree-phase-2"?`*yolo @${e.targetRef} story-worktree-phase-2`:`*yoloop @${e.targetRef}`}function I(e){return`sha256:${V("sha256").update(e).digest("hex")}`}function be(e,r,t,o=0){return{status:"failed",adapterId:e,runtimeId:r,reasonCode:t.reasonCode,reasonCodes:t.reasonCodes,durationMs:o,counts:{},hashes:{},publicSummary:O(t.publicSummary),redactionSummary:t.redactionSummary,relativePaths:[],publicSafe:!0}}function Ie(e,r,t,o=0){return{status:"failed",adapterId:e,runtimeId:r.runtimeId,...r.modelId?{modelId:r.modelId}:{},...r.runtimeSource?{runtimeSource:r.runtimeSource}:{},reasonCode:t.reasonCode,reasonCodes:t.reasonCodes,durationMs:o,counts:{},hashes:{prompt:I(P(r))},publicSummary:O(t.publicSummary),redactionSummary:t.redactionSummary,relativePaths:[r.targetRef],...r.receipt?{receipt:r.receipt}:{},publicSafe:!0}}function he(e,r,t){const o=P(r),u=I(t.stdout),a=I(t.stderr),p=t.timedOut||t.exitCode===0?0:le(t.stdout,t.stderr),s=t.cancelled?"failed":t.timedOut?"timed_out":t.exitCode===0?"completed":"failed",d=t.cancelled?l.EXECUTION_CANCELLED:t.timedOut?l.EXECUTION_TIMEOUT:t.exitCode===0?l.EXECUTION_COMPLETED:p>0?l.RUNTIME_AUTH_REQUIRED:l.EXECUTION_FAILED,f=[i("prompt","prompt_body",I(o))];return t.stdoutBytes>0&&f.push(i("stdout","raw_log",u)),t.stderrBytes>0&&f.push(i("stderr","raw_log",a)),{status:s,adapterId:e,runtimeId:r.runtimeId,...r.modelId?{modelId:r.modelId}:{},...r.runtimeSource?{runtimeSource:r.runtimeSource}:{},reasonCode:d,reasonCodes:[d,l.RECEIPT_REDACTED],exitCode:t.exitCode,signal:t.signal??null,durationMs:t.durationMs,counts:{stdoutBytes:t.stdoutBytes,stderrBytes:t.stderrBytes,stdoutLines:K(t.stdout),stderrLines:K(t.stderr),...p>0?{authEvidenceMatches:p}:{}},hashes:{prompt:I(o),stdout:u,stderr:a},publicSummary:s==="completed"?"Headless adapter completed with public-safe redacted output summary.":d===l.EXECUTION_CANCELLED?"Headless adapter was cancelled; raw output was redacted.":s==="timed_out"?"Headless adapter timed out; raw output was redacted.":d===l.RUNTIME_AUTH_REQUIRED?"Headless adapter requires local runtime authentication; raw output was redacted.":"Headless adapter failed; raw output was redacted.",redactionSummary:f,relativePaths:[r.targetRef],...r.receipt?{receipt:r.receipt}:{},publicSafe:!0}}async function ye(e,r,t={}){const o=Date.now(),u=ae(t.timeoutMs),a=t.maxOutputBytes??64e3;return t.signal?.aborted?{exitCode:null,signal:"SIGTERM",timedOut:!1,cancelled:!0,durationMs:Date.now()-o,stdout:"",stderr:"",stdoutBytes:0,stderrBytes:0}:await new Promise(p=>{const s=z(e,[...r],{cwd:t.cwd,env:t.env,shell:!1,stdio:[t.localConsole?"pipe":"ignore","pipe","pipe"]}),d=t.localConsole?.jobId?X({...t.localConsole,projectRoot:t.localConsole.projectRoot??t.cwd,writeStdin:n=>{s.stdin?.write(n)},signalProcess:n=>s.kill(n)}):void 0;d?.start();let f="",E="",b=0,y=0,m=!1,T=!1,S=!1;const A=()=>{m||(S=!0,s.kill("SIGTERM"))};t.signal?.addEventListener("abort",A,{once:!0});const R=()=>{t.signal?.removeEventListener("abort",A)},_=(n,c,j)=>{const U=j+c.length;if(n.length<a){const v=a-n.length;return{text:n+c.toString("utf8").slice(0,v),bytes:U}}return{text:n,bytes:U}};s.stdout?.on("data",n=>{const c=_(f,n,b);f=c.text,b=c.bytes,d?.broadcastStdout(n)}),s.stderr?.on("data",n=>{const c=_(E,n,y);E=c.text,y=c.bytes,d?.broadcastStderr(n)});const g=setTimeout(()=>{T=!0,s.kill("SIGTERM")},u);s.on("error",n=>{if(m)return;m=!0,clearTimeout(g),R(),d?.close({exitCode:127,signal:null});const c=n instanceof Error?n.message:String(n);p({exitCode:127,signal:null,timedOut:!1,cancelled:S,durationMs:Date.now()-o,stdout:f,stderr:c,stdoutBytes:b,stderrBytes:Buffer.byteLength(c)})}),s.on("close",(n,c)=>{m||(m=!0,clearTimeout(g),R(),d?.close({exitCode:n,signal:c}),p({exitCode:n,signal:c,timedOut:T,cancelled:S,durationMs:Date.now()-o,stdout:f,stderr:E,stdoutBytes:b,stderrBytes:y}))})})}function Se(e,r,t,o,u=[]){return{ok:!1,adapterId:e,...r?{commandName:r}:{},reasonCode:t,reasonCodes:[t],publicSummary:O(o),redactionSummary:u,publicSafe:!0}}function Te(e,r,t,o={}){const u={ok:!0,adapterId:e,commandName:r,...o.versionText?{versionHash:I(o.versionText)}:{},reasonCodes:[l.OK],publicSummary:O(t),publicSafe:!0};return o.executablePath&&Object.defineProperty(u,"executablePath",{value:o.executablePath,enumerable:!1,configurable:!1}),u}function i(e,r,t){return{field:e,reason:r,evidence:t,publicSafe:!0}}function O(e){return e.length<=C?e:`${e.slice(0,C)}\u2026[TRUNCATED:${e.length-C}]`}function oe(e){return e.length<=Y&&J.test(e)&&!k.test(e)&&!D.test(e)&&!e.includes("..")&&!e.startsWith("/")}function H(e,r,t){return{ok:!1,reasonCode:e,reasonCodes:[e],publicSummary:O(r),redactionSummary:t,publicSafe:!0}}function x(e,r,t){if(e===void 0)return;const o=h(e);if(!o||!N(o)||D.test(o)){t.push(i(r,M(r),"value-denied"));return}return o}function se(e,r){if(e===void 0)return;const t=h(e);if(!t||!oe(t)){r.push(i("modelId","unsafe_key","value-denied"));return}return t}function ne(e,r){if(e!==void 0){if(e==="explicit"||e==="origin"||e==="default"||e==="fallback")return e;r.push(i("runtimeSource","unsafe_key","value-denied"))}}function ie(e,r){if(e!==void 0){if(typeof e!="number"||!Number.isInteger(e)||e<=0||e>w){r.push(i("timeoutMs","unbounded_number","value-denied"));return}return e}}function ae(e){return!e||!Number.isInteger(e)||e<=0||e>w?q:e}function de(e,r){if(e===void 0)return;const t=h(e);if(!t||t.length>C||!N(t)){r.push(i("publicSummary","unbounded_text","value-denied"));return}return t}function ue(e,r){if(e===void 0)return;if(!B(e)){r.push(i("receipt","unsafe_key","value-denied"));return}const t={};for(const[o,u]of Object.entries(e)){if(!te.has(o)||Q.test(o)){r.push(i(`receipt.${o}`,M(o),"key-denied"));continue}const a=x(u,`receipt.${o}`,r);a&&(t[o]=a)}return Object.keys(t).length>0?t:void 0}function M(e){return/prompt/i.test(e)?"prompt_body":/std(?:out|err)|raw|log|transcript|stack/i.test(e)?"raw_log":/url/i.test(e)?"private_url":/path|cwd|argv|args|shell|command|binary|executable/i.test(e)?"executable_path":/secret|token|password|authorization|api[_-]?key|license/i.test(e)?"secret_or_pii":"unsafe_key"}function h(e){return typeof e=="string"?e:void 0}function N(e){return e.length>0&&!k.test(e)&&!/\0/.test(e)}function K(e){return e?e.split(/\r?\n/).filter(r=>r.length>0).length:0}const ce=Object.freeze([/\bauth(?:entication|orization)?\s+(?:is\s+)?required\b/i,/\brequires?\s+authentication\b/i,/\bmust\s+(?:log\s?in|authenticate|be\s+authenticated)\b/i,/\bunauthenticated\b/i,/\b(?:not|unauthenticated)\s+(?:logged\s+in|authenticated)\b/i,/\blog\s?in\s+(?:required|to\s+continue|before\s+continuing)\b/i,/\bplease\s+(?:log\s?in|authenticate|sign\s?in)\b/i,/\bsign\s?in\s+(?:required|to\s+continue|before\s+continuing)\b/i,/\bsession\s+(?:expired|not\s+found|invalid)\b/i,/\bcredentials?\s+(?:missing|required|not\s+found)\b/i]);function le(...e){const r=e.filter(t=>t.length>0).map(t=>t.slice(0,8e3)).join(`
|
|
2
|
-
`);return r?
|
|
1
|
+
import{createHash as F}from"node:crypto";import{spawn as V}from"node:child_process";import{P205_RELEASE_GATE_BUDGETS as $,P205_ROOT_INVOKE_TIMEOUT_MS as G}from"../../../../shared/dist/yoloop/epic-terminal-git.js";import{createLocalJobConsoleServer as X}from"../local-console.js";const Y=Object.freeze(["fake","test","opencode","claude-code"]),q="neocortex-sentinel",be="neocortex";function I(e,r){return Object.freeze({adapterId:e,childProfile:q,status:r})}const he=Object.freeze([I("opencode","executable"),I("claude-code","executable"),I("codex","declared"),I("gemini","declared"),I("kimi","declared"),I("grok","declared"),I("openclaw","declared"),I("antigravity","declared")]);function D(e){return e==="yolo"||e==="yolo-branchless-preparation"||e==="yolo-story-worktree-phase-1"||e==="yolo-story-worktree-phase-2"}const l=Object.freeze({OK:"continuity-ok",RUNTIME_EXPLICIT:"headless-runtime-explicit",RUNTIME_ORIGIN:"headless-runtime-origin",RUNTIME_DEFAULT:"headless-runtime-default",RUNTIME_FALLBACK:"headless-runtime-fallback",RUNTIME_UNRESOLVED:"headless-runtime-unresolved",RUNTIME_UNTRUSTED:"headless-runtime-untrusted",MODEL_REJECTED:"headless-model-rejected",DIRECTIVE_REJECTED:"headless-directive-rejected",STORY_WORKTREE_PHASE_BINDING_REQUIRED:"story-worktree-phase-binding-required",PROMPT_REJECTED:"headless-prompt-rejected",ADAPTER_UNAVAILABLE:"headless-adapter-unavailable",RUNTIME_AUTH_REQUIRED:"headless-runtime-auth-required",MANAGED_PROFILE_MISSING:"headless-managed-profile-missing",MANAGED_PROFILE_INVALID:"headless-managed-profile-invalid",CHILD_PROFILE_IS_ORCHESTRATOR:"headless-child-profile-is-orchestrator",CHILD_PROFILE_NAME_DUPLICATE:"headless-child-profile-name-duplicate",APPROVAL_POLICY_INVALID:"headless-approval-policy-invalid",APPROVAL_POLICY_MISMATCH:"headless-approval-policy-mismatch",EXECUTION_CANCELLED:"headless-execution-cancelled",EXECUTION_TIMEOUT:"headless-execution-timeout",EXECUTION_BACKOFF:"headless-execution-backoff",EXECUTION_COMPLETED:"headless-execution-completed",EXECUTION_FAILED:"headless-execution-failed",RECEIPT_REDACTED:"headless-receipt-redacted",YOLOOP_METADATA_INVALID:"headless-yoloop-metadata-invalid",YOLOOP_ISOLATION_VIOLATION:"headless-yoloop-isolation-violation",WORKER_POOL_SERIAL_FALLBACK:"worker-pool-serial-fallback",WORKER_POOL_PARALLEL_ACTIVE:"worker-pool-parallel-active",WORKER_POOL_BACKPRESSURE_PAUSED:"worker-pool-backpressure-paused"}),J=120,L=240,W=G,k=$.terminalWorkflowMaxDurationMs,Z=/^[A-Za-z0-9][A-Za-z0-9._:+/-]{0,119}$/,Q=/^docs\/stories\/[A-Za-z0-9._-]+\.story\.md$/,ee=/^docs\/epics\/epic-[A-Za-z0-9._-]+\.md$/,te=/(raw[_-]?(?:logs?|payloads?)|std(?:out|err)|stack(?:[_-]?trace)?|transcript|objective(?:[_-]?(?:text|body|prompt))|prompt(?:[_-]?(?:body|text))?|private[_-]?(?:urls?|prompts?)|secret|token|password|protected(?:[_-]?(?:field|body|bodies|internals))?|workflow(?:[_-]?body)?|step(?:[_-]?body)?|customer(?:[_-]?(?:pii|data))?|\bpii\b|authorization|api[_-]?key|license[_-]?key|argv|args|executable(?:[_-]?path)?|binary(?:[_-]?path)?|shell|cwd|command[_-]?path|vendor(?:[_-]?(?:payload|corpus|response|output)))/i,H=/(https?:\/\/\S+|(?:^|\s)(?:\/(?:home|Users|media|mnt|tmp|var|etc|private)\/\S+|[A-Za-z]:\\\S+)|ghp_[A-Za-z0-9_]+|sk-[A-Za-z0-9_-]+|-----BEGIN [A-Z ]*PRIVATE KEY-----|authorization\s*:|password\s*=|token\s*=|api[_-]?key\s*=|license[_-]?key\s*=|raw[_-]?(?:logs?)\s*[:=]|transcript|stack\s*trace|stderr:|stdout:|system prompt|workflow body|step body|PROTECTED_|PRIVATE_INTERNALS|CUSTOMER_PII|\bPII\b|VENDOR_CORPUS)/i,P=/(?:[;&|`$<>]|\$\(|\n|\r|\0)/,re=new Set(["promptKind","targetKind","targetRef","storyId","epicId","runtimeId","modelId","runtimeSource","timeoutMs","receipt","publicSummary","publicSafe"]),oe=new Set(["executionId","attemptId","jobId","operationId","idempotencyKey","runnerId","subagentId"]);function se(e){return Y.includes(e)}function ye(e,r){const t=[],o=[];if(!j(e))return t.push(i("input","unsafe_key","value-denied")),K(l.DIRECTIVE_REJECTED,"Headless adapter input must be a public object.",t);for(const _ of Object.keys(e))re.has(_)||(o.push(_),t.push(i(_,N(_),"key-denied")));const u=e.publicSafe===!0;u||t.push(i("publicSafe","unsafe_key","value-denied"));const a=y(e.promptKind);!D(a)&&a!=="yoloop"&&t.push(i("promptKind","unsafe_key","value-denied"));const p=y(e.targetKind);p!=="story"&&p!=="epic"&&t.push(i("targetKind","unsafe_key","value-denied"));const s=y(e.targetRef);(!s||!U(s)||P.test(s)||s.includes(".."))&&t.push(i("targetRef","prompt_body","value-denied")),D(a)&&(p!=="story"||!s||!Q.test(s))&&t.push(i("targetRef","prompt_body","value-denied")),a==="yoloop"&&(p!=="epic"||!s||!ee.test(s))&&t.push(i("targetRef","prompt_body","value-denied"));const d=M(e.storyId,"storyId",t),E=M(e.epicId,"epicId",t);d&&s&&D(a)&&d!==s.replace(/^docs\/stories\//,"").replace(/\.story\.md$/,"")&&t.push(i("storyId","prompt_body","value-denied")),E&&s&&a==="yoloop"&&E!==s.replace(/^docs\/epics\/epic-/,"").replace(/\.md$/,"")&&t.push(i("epicId","prompt_body","value-denied"));const f=y(e.runtimeId);(!f||!se(f)||r&&f!==r)&&t.push(i("runtimeId","unsafe_key","value-denied"));const b=ie(e.modelId,t),S=ae(e.runtimeSource,t),m=de(e.timeoutMs,t),A=ce(e.publicSummary,t),T=le(e.receipt,t);if(t.length>0||o.length>0||!u||!a||!p||!s||!f){const _=t.some(n=>n.field==="modelId"),C=t.some(n=>n.reason==="prompt_body");return K(_?l.MODEL_REJECTED:C?l.PROMPT_REJECTED:l.DIRECTIVE_REJECTED,C?"Headless adapter target did not match a public prompt shape.":"Headless adapter input failed public-safety validation.",t)}const R={promptKind:a,targetKind:p,targetRef:s,...d?{storyId:d}:{},...E?{epicId:E}:{},runtimeId:f,...b?{modelId:b}:{},...S?{runtimeSource:S}:{},...m?{timeoutMs:m}:{},...T?{receipt:T}:{},...A?{publicSummary:A}:{},publicSafe:!0},O=x(R);return{ok:!0,input:R,prompt:O,promptHash:h(O),reasonCodes:[l.OK],publicSafe:!0}}function x(e){return e.promptKind==="yolo"?`*yolo @${e.targetRef}`:e.promptKind==="yolo-branchless-preparation"?`*yolo @${e.targetRef} branchless-preparation`:e.promptKind==="yolo-story-worktree-phase-1"?`*yolo @${e.targetRef} story-worktree-phase-1`:e.promptKind==="yolo-story-worktree-phase-2"?`*yolo @${e.targetRef} story-worktree-phase-2`:`*yoloop @${e.targetRef}`}function h(e){return`sha256:${F("sha256").update(e).digest("hex")}`}function Se(e,r,t,o=0){return{status:"failed",adapterId:e,runtimeId:r,reasonCode:t.reasonCode,reasonCodes:t.reasonCodes,durationMs:o,counts:{},hashes:{},publicSummary:g(t.publicSummary),redactionSummary:t.redactionSummary,relativePaths:[],publicSafe:!0}}function Te(e,r,t,o=0){return{status:"failed",adapterId:e,runtimeId:r.runtimeId,...r.modelId?{modelId:r.modelId}:{},...r.runtimeSource?{runtimeSource:r.runtimeSource}:{},reasonCode:t.reasonCode,reasonCodes:t.reasonCodes,durationMs:o,counts:{},hashes:{prompt:h(x(r))},publicSummary:g(t.publicSummary),redactionSummary:t.redactionSummary,relativePaths:[r.targetRef],...r.receipt?{receipt:r.receipt}:{},publicSafe:!0}}function Ae(e,r,t){const o=x(r),u=h(t.stdout),a=h(t.stderr),p=t.timedOut||t.exitCode===0?0:Ee(t.stdout,t.stderr),s=t.cancelled?"failed":t.timedOut?"timed_out":t.exitCode===0?"completed":"failed",d=t.cancelled?l.EXECUTION_CANCELLED:t.timedOut?l.EXECUTION_TIMEOUT:t.exitCode===0?l.EXECUTION_COMPLETED:p>0?l.RUNTIME_AUTH_REQUIRED:l.EXECUTION_FAILED,E=[i("prompt","prompt_body",h(o))];return t.stdoutBytes>0&&E.push(i("stdout","raw_log",u)),t.stderrBytes>0&&E.push(i("stderr","raw_log",a)),{status:s,adapterId:e,runtimeId:r.runtimeId,...r.modelId?{modelId:r.modelId}:{},...r.runtimeSource?{runtimeSource:r.runtimeSource}:{},reasonCode:d,reasonCodes:[d,l.RECEIPT_REDACTED],exitCode:t.exitCode,signal:t.signal??null,durationMs:t.durationMs,counts:{stdoutBytes:t.stdoutBytes,stderrBytes:t.stderrBytes,stdoutLines:B(t.stdout),stderrLines:B(t.stderr),...p>0?{authEvidenceMatches:p}:{}},hashes:{prompt:h(o),stdout:u,stderr:a},publicSummary:s==="completed"?"Headless adapter completed with public-safe redacted output summary.":d===l.EXECUTION_CANCELLED?"Headless adapter was cancelled; raw output was redacted.":s==="timed_out"?"Headless adapter timed out; raw output was redacted.":d===l.RUNTIME_AUTH_REQUIRED?"Headless adapter requires local runtime authentication; raw output was redacted.":"Headless adapter failed; raw output was redacted.",redactionSummary:E,relativePaths:[r.targetRef],...r.receipt?{receipt:r.receipt}:{},publicSafe:!0}}async function Re(e,r,t={}){const o=Date.now(),u=ue(t.timeoutMs),a=t.maxOutputBytes??64e3;return t.signal?.aborted?{exitCode:null,signal:"SIGTERM",timedOut:!1,cancelled:!0,durationMs:Date.now()-o,stdout:"",stderr:"",stdoutBytes:0,stderrBytes:0}:await new Promise(p=>{const s=V(e,[...r],{cwd:t.cwd,env:t.env,shell:!1,stdio:[t.localConsole?"pipe":"ignore","pipe","pipe"]}),d=t.localConsole?.jobId?X({...t.localConsole,projectRoot:t.localConsole.projectRoot??t.cwd,writeStdin:n=>{s.stdin?.write(n)},signalProcess:n=>s.kill(n)}):void 0;d?.start();let E="",f="",b=0,S=0,m=!1,A=!1,T=!1;const R=()=>{m||(T=!0,s.kill("SIGTERM"))};t.signal?.addEventListener("abort",R,{once:!0});const O=()=>{t.signal?.removeEventListener("abort",R)},_=(n,c,v)=>{const w=v+c.length;if(n.length<a){const z=a-n.length;return{text:n+c.toString("utf8").slice(0,z),bytes:w}}return{text:n,bytes:w}};s.stdout?.on("data",n=>{const c=_(E,n,b);E=c.text,b=c.bytes,d?.broadcastStdout(n)}),s.stderr?.on("data",n=>{const c=_(f,n,S);f=c.text,S=c.bytes,d?.broadcastStderr(n)});const C=setTimeout(()=>{A=!0,s.kill("SIGTERM")},u);s.on("error",n=>{if(m)return;m=!0,clearTimeout(C),O(),d?.close({exitCode:127,signal:null});const c=n instanceof Error?n.message:String(n);p({exitCode:127,signal:null,timedOut:!1,cancelled:T,durationMs:Date.now()-o,stdout:E,stderr:c,stdoutBytes:b,stderrBytes:Buffer.byteLength(c)})}),s.on("close",(n,c)=>{m||(m=!0,clearTimeout(C),O(),d?.close({exitCode:n,signal:c}),p({exitCode:n,signal:c,timedOut:A,cancelled:T,durationMs:Date.now()-o,stdout:E,stderr:f,stdoutBytes:b,stderrBytes:S}))})})}function Oe(e,r,t,o,u=[]){return{ok:!1,adapterId:e,...r?{commandName:r}:{},reasonCode:t,reasonCodes:[t],publicSummary:g(o),redactionSummary:u,publicSafe:!0}}function Ce(e,r,t,o={}){const u={ok:!0,adapterId:e,commandName:r,...o.versionText?{versionHash:h(o.versionText)}:{},reasonCodes:[l.OK],publicSummary:g(t),publicSafe:!0};return o.executablePath&&Object.defineProperty(u,"executablePath",{value:o.executablePath,enumerable:!1,configurable:!1}),u}function i(e,r,t){return{field:e,reason:r,evidence:t,publicSafe:!0}}function g(e){return e.length<=L?e:`${e.slice(0,L)}\u2026[TRUNCATED:${e.length-L}]`}function ne(e){return e.length<=J&&Z.test(e)&&!H.test(e)&&!P.test(e)&&!e.includes("..")&&!e.startsWith("/")}function K(e,r,t){return{ok:!1,reasonCode:e,reasonCodes:[e],publicSummary:g(r),redactionSummary:t,publicSafe:!0}}function M(e,r,t){if(e===void 0)return;const o=y(e);if(!o||!U(o)||P.test(o)){t.push(i(r,N(r),"value-denied"));return}return o}function ie(e,r){if(e===void 0)return;const t=y(e);if(!t||!ne(t)){r.push(i("modelId","unsafe_key","value-denied"));return}return t}function ae(e,r){if(e!==void 0){if(e==="explicit"||e==="origin"||e==="default"||e==="fallback")return e;r.push(i("runtimeSource","unsafe_key","value-denied"))}}function de(e,r){if(e!==void 0){if(typeof e!="number"||!Number.isInteger(e)||e<=0||e>k){r.push(i("timeoutMs","unbounded_number","value-denied"));return}return e}}function ue(e){return!e||!Number.isInteger(e)||e<=0||e>k?W:e}function ce(e,r){if(e===void 0)return;const t=y(e);if(!t||t.length>L||!U(t)){r.push(i("publicSummary","unbounded_text","value-denied"));return}return t}function le(e,r){if(e===void 0)return;if(!j(e)){r.push(i("receipt","unsafe_key","value-denied"));return}const t={};for(const[o,u]of Object.entries(e)){if(!oe.has(o)||te.test(o)){r.push(i(`receipt.${o}`,N(o),"key-denied"));continue}const a=M(u,`receipt.${o}`,r);a&&(t[o]=a)}return Object.keys(t).length>0?t:void 0}function N(e){return/prompt/i.test(e)?"prompt_body":/std(?:out|err)|raw|log|transcript|stack/i.test(e)?"raw_log":/url/i.test(e)?"private_url":/path|cwd|argv|args|shell|command|binary|executable/i.test(e)?"executable_path":/secret|token|password|authorization|api[_-]?key|license/i.test(e)?"secret_or_pii":"unsafe_key"}function y(e){return typeof e=="string"?e:void 0}function U(e){return e.length>0&&!H.test(e)&&!/\0/.test(e)}function B(e){return e?e.split(/\r?\n/).filter(r=>r.length>0).length:0}const pe=Object.freeze([/\bauth(?:entication|orization)?\s+(?:is\s+)?required\b/i,/\brequires?\s+authentication\b/i,/\bmust\s+(?:log\s?in|authenticate|be\s+authenticated)\b/i,/\bunauthenticated\b/i,/\b(?:not|unauthenticated)\s+(?:logged\s+in|authenticated)\b/i,/\blog\s?in\s+(?:required|to\s+continue|before\s+continuing)\b/i,/\bplease\s+(?:log\s?in|authenticate|sign\s?in)\b/i,/\bsign\s?in\s+(?:required|to\s+continue|before\s+continuing)\b/i,/\bsession\s+(?:expired|not\s+found|invalid)\b/i,/\bcredentials?\s+(?:missing|required|not\s+found)\b/i]);function Ee(...e){const r=e.filter(t=>t.length>0).map(t=>t.slice(0,8e3)).join(`
|
|
2
|
+
`);return r?pe.reduce((t,o)=>t+(o.test(r)?1:0),0):0}function j(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}export{Y as HEADLESS_ADAPTER_IDS,q as HEADLESS_CHILD_AGENT_PROFILE,he as HEADLESS_DECLARED_ADAPTERS,be as HEADLESS_LEGACY_CHILD_AGENT_PROFILE,l as HEADLESS_REASON_CODES,Oe as adapterAvailabilityFailure,Ce as adapterAvailabilitySuccess,g as boundPublicSummary,Se as createRejectedExecutionResult,Te as createUnavailableExecutionResult,h as hashPublicValue,se as isHeadlessAdapterId,D as isHeadlessStoryPromptKind,ne as isSafeHeadlessModelId,Ae as normalizeHeadlessCommandResult,i as redaction,x as renderHeadlessPrompt,Re as runHeadlessCommand,ye as validateHeadlessAdapterExecutionInput};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createHash as W}from"node:crypto";import{analyzeDependencyDag as C,StructuralDagError as y}from"./structural-dag-projection.js";import{classifyInvocationShapeV2 as O}from"./invocation-shape.js";const U=12,J=16,k=["active","archived","rolled-back","synthetic","orphan"],X=new Set(["in-progress","branch-ready","diagnose","research","write-spec","create-tasks","implemented","refactor-suggest-done","property-tests-emitted","tests-validated","qa-gate-passed","memory-updated","committed","synced","pr-created","pr-reviewed","partial"]);function Q(r){return r==="STRUCTURAL_TARGET_NOT_FOUND"?"registration-missing":r==="STRUCTURAL_DEPENDENCY_CYCLE"?"dependency-cycle":"dependency-missing"}function Fe(r){const e=/^[a-f0-9]{64}$/,t=/^P[1-9][0-9]*(?:\.[0-9]+)*$/,i=/^[A-Za-z0-9][A-Za-z0-9._/-]{0,239}$/;if(r.schemaVersion!=="EpicOperationalPublicProjection/1.0"||!e.test(r.repositoryFingerprint)||!e.test(r.identityHash)||!t.test(r.epicId)||!i.test(r.executionBranch)||!e.test(r.graphRevision)||!Number.isSafeInteger(r.storeRevision)||r.storeRevision<0||!Number.isSafeInteger(r.writerEpoch)||r.writerEpoch<1||r.runId!==null&&r.runId.length>128||r.runStatus!==null&&r.runStatus.length>32||r.runRevision!==null&&(!Number.isSafeInteger(r.runRevision)||r.runRevision<0)||r.snapshotHash!==null&&!e.test(r.snapshotHash)||!e.test(r.continuationSessionHash)||!e.test(r.pendingAuthorityHash)||!Number.isSafeInteger(r.pendingAuthorityCount)||r.pendingAuthorityCount<0||r.pendingAuthorityCount>1024||r.reasonCodes.length>16||r.reasonCodes.some(c=>!/^[a-z0-9][a-z0-9-]{0,79}$/.test(c))||r.publicSafe!==!0)throw new Error("epic-operational-projection-invalid");return Object.freeze({schemaVersion:r.schemaVersion,repositoryFingerprint:r.repositoryFingerprint,identityHash:r.identityHash,epicId:r.epicId,executionBranch:r.executionBranch,graphRevision:r.graphRevision,storeRevision:r.storeRevision,writerEpoch:r.writerEpoch,runId:r.runId,runStatus:r.runStatus,runRevision:r.runRevision,snapshotHash:r.snapshotHash,continuationSessionHash:r.continuationSessionHash,pendingAuthorityHash:r.pendingAuthorityHash,pendingAuthorityCount:r.pendingAuthorityCount,lockActive:r.lockActive,currentSessionActive:r.currentSessionActive,journalActive:r.journalActive,reasonCodes:[...r.reasonCodes],publicSafe:!0})}const n=(r,e,t={})=>({commandId:r,stateProjectionPolicy:e,...t}),A=Object.freeze({status:n("status","full"),"arch-plan":n("arch-plan","full"),"arch-prd":n("arch-prd","full"),"arch-architecture":n("arch-architecture","epic-targeted",{structuralRequired:!0}),"arch-api-contracts":n("arch-api-contracts","epic-targeted",{structuralRequired:!0}),"arch-api-integrations":n("arch-api-integrations","epic-targeted",{structuralRequired:!0}),"arch-database":n("arch-database","epic-targeted",{structuralRequired:!0}),"arch-security":n("arch-security","epic-targeted",{structuralRequired:!0}),"arch-design-system":n("arch-design-system","epic-targeted",{structuralRequired:!0}),"arch-ux-design":n("arch-ux-design","epic-targeted",{structuralRequired:!0}),"arch-performance":n("arch-performance","epic-targeted",{structuralRequired:!0}),"arch-testing":n("arch-testing","epic-targeted",{structuralRequired:!0}),"arch-infrastructure":n("arch-infrastructure","epic-targeted",{structuralRequired:!0}),"arch-review":n("arch-review","epic-targeted",{structuralRequired:!0}),"arch-fitness-functions":n("arch-fitness-functions","epic-targeted",{structuralRequired:!0}),"create-epic":n("create-epic","epic-summary"),"idea-diagnose":n("idea-diagnose","full"),"idea-research":n("idea-research","epic-targeted",{structuralRequired:!0}),"generate-epic":n("generate-epic","epic-targeted",{structuralRequired:!0}),exec:n("exec","story-targeted",{structuralRequired:!0}),yolo:n("yolo","story-targeted",{structuralRequired:!0}),"yolo-inline":n("yolo-inline","story-targeted",{structuralRequired:!0}),epic:n("epic","epic-targeted",{structuralRequired:!0}),"setup-branch":n("setup-branch","story-targeted",{structuralRequired:!0}),diagnose:n("diagnose","adaptive-targeted"),"diagnose-inline":n("diagnose-inline","full"),research:n("research","adaptive-targeted"),"research-inline":n("research-inline","full"),"write-spec":n("write-spec","story-targeted",{structuralRequired:!0}),"create-tasks":n("create-tasks","story-targeted",{structuralRequired:!0}),implement:n("implement","story-targeted",{structuralRequired:!0}),commit:n("commit","story-targeted",{structuralRequired:!0}),"commit-push":n("commit","story-targeted",{structuralRequired:!0}),sync:n("sync","story-targeted",{structuralRequired:!0}),"sync-main":n("sync","story-targeted",{structuralRequired:!0}),"create-pr":n("create-pr","story-targeted",{structuralRequired:!0}),review:n("review","story-targeted"),"review-pr":n("review","story-targeted"),merge:n("merge","story-targeted",{structuralRequired:!0}),"merge-pr":n("merge","story-targeted",{structuralRequired:!0}),"fix-blocked":n("fix-blocked","story-targeted"),"finalize-epic":n("finalize-epic","epic-targeted"),"resolve-conflicts":n("resolve-conflicts","story-targeted"),"update-memory":n("update-memory","full"),"update-project-memory":n("update-memory","story-targeted",{structuralRequired:!0}),refactor:n("refactor","adaptive-targeted"),"refactor-suggest":n("refactor","story-targeted",{structuralRequired:!0}),cleanup:n("cleanup","full"),audit:n("audit","full"),"tech-debt":n("tech-debt","full"),menu:n("menu","full"),plans:n("plans","full"),billing:n("billing","full"),subscribe:n("subscribe","full"),"qa-scan":n("qa-scan","full"),yoloop:n("yoloop","yoloop-targeted",{structuralRequired:!0}),"migrate-state":n("migrate-state","full"),"migrate-project-id":n("migrate-project-id","full"),"policy-audit":n("policy-audit","full"),"mutation-test":n("mutation-test","full"),"sync-openapi":n("sync-openapi","full"),"generate-pacts":n("generate-pacts","full"),"verify-pacts":n("verify-pacts","full"),"property-test":n("property-test","full"),"property-tests":n("property-test","story-targeted",{structuralRequired:!0}),"chaos-plan":n("chaos-plan","full"),"ui-ux-review":n("ui-ux-review","adaptive-targeted"),"solyd-system":n("solyd-system","adaptive-targeted"),goal:n("goal","continuity-scoped"),loop:n("loop","continuity-scoped"),jobs:n("jobs","continuity-scoped"),runner:n("runner","continuity-scoped"),"goal-tick":n("goal-tick","continuity-scoped"),"loop-tick":n("loop-tick","continuity-scoped"),"validate-tests":n("validate-tests","story-targeted",{structuralRequired:!0}),"qa-gate":n("qa-gate","story-targeted",{structuralRequired:!0})}),ee=Object.freeze({st:"status",arquitetura:"arch-plan",architecture:"arch-plan",arch:"arch-plan",prd:"arch-prd","product-requirements":"arch-prd","arch-doc":"arch-architecture","tech-architecture":"arch-architecture","api-contracts":"arch-api-contracts","api-contract":"arch-api-contracts","api-integrations":"arch-api-integrations","api-int":"arch-api-integrations","database-schema":"arch-database","db-schema":"arch-database",db:"arch-database","cyber-security":"arch-security",security:"arch-security",sec:"arch-security","design-system":"arch-design-system",ds:"arch-design-system","atomic-design":"arch-design-system","ux-design":"arch-ux-design",ux:"arch-ux-design",wireframes:"arch-ux-design",wireframe:"arch-ux-design","user-flows":"arch-ux-design",performance:"arch-performance",perf:"arch-performance","capacity-planning":"arch-performance",capacity:"arch-performance","arch-perf":"arch-performance","performance-strategy":"arch-performance","testing-strategy":"arch-testing","test-plan":"arch-testing","test-strategy":"arch-testing","arch-test":"arch-testing",infrastructure:"arch-infrastructure",infra:"arch-infrastructure","deploy-plan":"arch-infrastructure",deployment:"arch-infrastructure","arch-infra":"arch-infrastructure","arch-deploy":"arch-infrastructure","review-consolidation":"arch-review",consolidation:"arch-review","architecture-review":"arch-review","arch-consolidation":"arch-review",fitness:"arch-fitness-functions","fitness-functions":"arch-fitness-functions",archfit:"arch-fitness-functions","arch-fit":"arch-fitness-functions","fit-funcs":"arch-fitness-functions","criar-epic":"create-epic",planejamento:"create-epic","idea-diag":"idea-diagnose","idea-pesq":"idea-research","gerar-epic":"generate-epic",executar:"exec",pipeline:"exec","parallel-epic":"epic",setup:"setup-branch",branch:"setup-branch",diag:"diagnose",diagnostico:"diagnose",c02:"diagnose",pesquisar:"research",pesq:"research","research-fix":"research",c03:"research",spec:"write-spec",especificacao:"write-spec",c04:"write-spec",tasks:"create-tasks",tarefas:"create-tasks",c05:"create-tasks",impl:"implement",implementar:"implement",c06:"implement",push:"commit",commit_push:"commit",cp:"commit",c07:"commit",sincronizar:"sync",c08:"sync",pr:"create-pr",c09:"create-pr",revisar:"review",c11:"review",mesclar:"merge",c12:"merge",fix:"fix-blocked",corrigir:"fix-blocked",finalizar:"finalize-epic",conflitos:"resolve-conflicts",memoria:"update-memory",refactoring:"refactor",refact:"refactor",refac:"refactor",rf:"refactor","cleanup-code":"refactor","code-cleanup":"refactor","code-quality":"refactor","improve-code":"refactor",modernize:"refactor",modernization:"refactor",legacy:"refactor","legacy-code":"refactor","debt-pay":"refactor","pay-debt":"refactor","debt-reduction":"refactor","smell-fix":"refactor","fix-smells":"refactor","code-smells":"refactor",strangler:"refactor","strangler-fig":"refactor",limpar:"cleanup",limpeza:"cleanup",auditar:"audit",auditoria:"audit",debt:"tech-debt",debts:"tech-debt","debt-list":"tech-debt","tech-debts":"tech-debt",td:"tech-debt",help:"menu",ajuda:"menu","?":"menu",commands:"menu",cmds:"menu",planos:"plans",pricing:"plans",bill:"billing",subscription:"billing",sub:"billing",upgrade:"subscribe",checkout:"subscribe",qa:"qa-scan","qa-test":"qa-scan","visual-qa":"qa-scan","e2e-scan":"qa-scan",troubleshoot:"qa-scan","debug-ui":"qa-scan",scan:"qa-scan",a11y:"qa-scan",accessibility:"qa-scan",wcag:"qa-scan","auto-yolo":"yoloop","epic-runner":"yoloop","story-runner":"yoloop","loop-yolo":"yoloop","auto-epic":"yoloop",migrate:"migrate-state","state-migrate":"migrate-state","schema-migrate":"migrate-state",policy:"policy-audit","audit-policy":"policy-audit","policy-history":"policy-audit",policies:"policy-audit",mutation:"mutation-test",stryker:"mutation-test","kill-mutants":"mutation-test","openapi-sync":"sync-openapi","api-sync":"sync-openapi","spec-sync":"sync-openapi","regen-openapi":"sync-openapi",pacts:"generate-pacts","gen-pacts":"generate-pacts","regen-pacts":"generate-pacts","create-pacts":"generate-pacts","verify-pact":"verify-pacts","pact-verify":"verify-pacts","check-pacts":"verify-pacts","pact-check":"verify-pacts",property:"property-test",pbt:"property-test",proptest:"property-test","invariant-test":"property-test",chaos:"chaos-plan",gameday:"chaos-plan","resilience-test":"chaos-plan","ux-review":"ui-ux-review","design-review":"ui-ux-review","visual-review":"ui-ux-review","product-polish":"ui-ux-review","security-system":"solyd-system","authorized-security":"solyd-system","sec-system":"solyd-system",goals:"goal","durable-goal":"goal","continuity-goal":"goal",loops:"loop","durable-loop":"loop","continuity-loop":"loop",job:"jobs","continuity-jobs":"jobs","neocortex-runner":"runner","continuity-runner":"runner"}),te=Object.freeze({1:"status",3:"arch-plan",4:"arch-prd",5:"arch-architecture",6:"arch-api-contracts",7:"arch-api-integrations",8:"arch-database",9:"arch-security",10:"arch-design-system",11:"arch-ux-design",12:"arch-performance",13:"arch-testing",14:"arch-infrastructure",15:"arch-review",16:"arch-fitness-functions",17:"create-epic",18:"idea-diagnose",19:"idea-research",20:"generate-epic",21:"exec",22:"yolo",23:"epic",24:"setup-branch",25:"diagnose",26:"research",27:"write-spec",28:"create-tasks",29:"implement",30:"commit",31:"sync",32:"create-pr",33:"review",34:"merge",35:"fix-blocked",36:"finalize-epic",37:"resolve-conflicts",38:"update-memory",39:"refactor",40:"cleanup",41:"audit",42:"tech-debt",43:"menu",44:"plans",45:"billing",46:"subscribe",47:"qa-scan",48:"yoloop",49:"migrate-state",50:"policy-audit",51:"mutation-test",52:"sync-openapi",53:"generate-pacts",54:"verify-pacts",55:"property-test",56:"chaos-plan",57:"ui-ux-review",58:"solyd-system",59:"goal",60:"loop",61:"jobs",62:"runner"});function d(r,e=120){if(typeof r!="string")return;const t=r.trim();if(t)return t.replace(/[^a-z0-9_.:-]+/gi,"_").slice(0,e)}function w(r,e=120){if(typeof r!="string")return;const t=r.trim(),i=d(r,e);return i===t?i:void 0}function T(r){if(typeof r!="string")return;const e=r.trim();if(!(!e||e.length>240||!/^[A-Za-z0-9][A-Za-z0-9._/-]*$/.test(e)||e.includes("..")||e.includes("//")||e.includes("@{")||e.endsWith("/")||e.endsWith(".")||e.split("/").some(t=>!t||t.startsWith(".")||t.endsWith(".lock"))))return e}function re(r){if(typeof r!="string")return;const e=r.replace(/\\/g,"/");if(!(!e||e.length>240||e.startsWith("/")||/^[A-Za-z]:/.test(e)||e.includes("..")||e.includes("//")||e.split("/").includes(".")||!/^[A-Za-z0-9._/:@#-]+$/.test(e)))return e}function S(r){if(r===void 0||!Array.isArray(r)||r.length>128)return;const e=r.map(re);if(!e.some(t=>t===void 0))return[...new Set(e)].sort((t,i)=>t.localeCompare(i,"en"))}function ie(r){return typeof r=="string"&&X.has(r.trim().toLowerCase().replace(/_/g,"-"))}function v(r,e){const t={};for(const i of e){const c=r[i];typeof c=="string"||typeof c=="boolean"||typeof c=="number"&&Number.isFinite(c)?t[i]=c:Array.isArray(c)&&c.every(o=>typeof o=="string")&&(t[i]=[...c])}return t}function ce(r,e){const t=e.checkpoint;if(!h(t)||t.schemaVersion!==1||t.storyId!==r||t.epicId!==e.epic_id||!T(t.branch)||typeof t.baseSha!="string"||!/^[0-9a-f]{7,64}$/i.test(t.baseSha)||typeof t.headSha!="string"||!/^[0-9a-f]{7,64}$/i.test(t.headSha)||t.baseSha===t.headSha||!w(t.idempotencyKey)||typeof t.recordedAt!="string"||!Number.isFinite(Date.parse(t.recordedAt))||!Array.isArray(t.commits)||t.commits.length===0||t.commits.length>256||t.commits.some(c=>typeof c!="string"||!/^[0-9a-f]{7,64}$/i.test(c))||!Array.isArray(t.receiptRefs)||t.receiptRefs.length===0||t.receiptRefs.length>256||t.receiptRefs.some(c=>typeof c!="string"||c.length>240||c.includes("..")||!/^[A-Za-z0-9._:/#\-[\]]+$/.test(c))||!h(t.qaReceipt)||t.qaReceipt.kind!=="story_qa_evidence"||t.qaReceipt.producer!=="local-yolo-tdd"||!["passed","blocked"].includes(String(t.qaVerdict))||!["approved","changes-requested","pending"].includes(String(t.reviewVerdict))||(t.reviewVerdict==="pending"?t.reviewReceipt!==void 0:!h(t.reviewReceipt)))return;const i=v(t,["schemaVersion","storyId","epicId","branch","baseSha","headSha","idempotencyKey","dispatchId","bundleId","bundleDigest","graphRevision","claimRevision","qaVerdict","reviewVerdict","recordedAt","commits","receiptRefs"]);return i.qaReceipt=v(t.qaReceipt,["schemaVersion","kind","producer","evidenceVersion","storyId","epicId","contract","command","manifestDigest","gateIds","resultDigest","baseSha","headSha","bundleDigest","graphRevision","sourceEvidenceDigest","verdict","checkedAt","receiptRef"]),h(t.reviewReceipt)&&(i.reviewReceipt=v(t.reviewReceipt,["schemaVersion","kind","producer","storyId","epicId","baseSha","headSha","bundleDigest","graphRevision","sourceEvidenceDigest","qaReceiptRef","verdict","reviewedAt","receiptRef"])),i}function oe(r,e){const t=e.checkpoint_verification;if(!(!h(t)||t.schemaVersion!==1||t.kind!=="story_checkpoint_physical_verification"||t.producer!=="client-p205-transient-v1"||t.publicSafe!==!0||t.storyId!==r||t.epicId!==e.epic_id||!["verified","rejected"].includes(String(t.verdict))))return v(t,["schemaVersion","kind","producer","storyId","epicId","branch","baseSha","headSha","aggregateHeadSha","commitBodyDigest","changedPathsDigest","claimVerification","effectiveClaimRevision","command","manifestDigest","gateIds","resultDigest","graphRevision","executionEvidenceDigest","sourceEvidenceDigest","verifiedAt","verdict","reasonCodes","publicSafe"])}function M(r,e){const t=e.scheduling_checkpoint_evidence,i=new Set(["schemaVersion","kind","producer","storyId","epicId","branch","baseSha","headSha","graphRevision","effectiveClaimRevision","sourceEvidenceDigest","verifiedAt","reasonCodes","integrationAuthorized","publicSafe"]);if(!(!h(t)||Object.keys(t).some(c=>!i.has(c))||t.schemaVersion!==1||t.kind!=="story_scheduling_checkpoint_evidence"||t.producer!=="client-git-physical-v1"||t.publicSafe!==!0||t.integrationAuthorized!==!1||t.storyId!==r||t.epicId!==e.epic_id||!T(t.branch)||typeof t.baseSha!="string"||!/^[0-9a-f]{40,64}$/i.test(t.baseSha)||typeof t.headSha!="string"||!/^[0-9a-f]{40,64}$/i.test(t.headSha)||typeof t.graphRevision!="string"||!/^[0-9a-f]{64}$/i.test(t.graphRevision)||typeof t.effectiveClaimRevision!="string"||!/^[0-9a-f]{64}$/i.test(t.effectiveClaimRevision)||typeof t.sourceEvidenceDigest!="string"||!/^[0-9a-f]{64}$/i.test(t.sourceEvidenceDigest)||typeof t.verifiedAt!="string"||!Number.isFinite(Date.parse(t.verifiedAt))||!Array.isArray(t.reasonCodes)||t.reasonCodes.length!==1||t.reasonCodes[0]!=="checkpoint-git-scheduling-verified"))return v(t,[...i])}function ne(r,e){const t={...e},i=M(r,e);return i?(t.scheduling_checkpoint_evidence=i,delete t.checkpoint,delete t.checkpoint_verification):delete t.scheduling_checkpoint_evidence,t}function h(r){return r!==null&&typeof r=="object"&&!Array.isArray(r)}function _(...r){const e=new Set,t=[];for(const i of r)for(const c of i??[]){const o=d(c,80);if(!(!o||e.has(o))&&(e.add(o),t.push(o),t.length>=J))return t}return t}function se(r){return r.trim().replace(/^@?\*/,"").replace(/^@/,"").toLowerCase()}function ae(r){return r.trim().split(/\s+/,1)[0]??""}function z(r){if(/^@epic-P[0-9]{1,12}$/.test(r.trim()))return A.epic;const e=ae(r);if(!e)return A.menu;const t=se(e),i=te[t]??ee[t]??t;return A[i]??null}function de(r,e,t,i="full-compatible",c=["full-state"]){return{kind:"full",commandId:t?.commandId??null,stateProjectionPolicy:t?.stateProjectionPolicy??null,projectionMode:i,trigger:r,targetEpicId:null,targetStoryId:null,includedStoryCount:Object.keys(e.stories).length,includedEpicCount:Object.keys(e.epics).length,omittedStoryCount:0,omittedEpicCount:0,reason:"full-state",reasonCodes:_(c)}}function Le(r,e,t,i="full-compatible",c=["full-state"]){const o=de(r,e,t,i,c);return I({...e,scope:o},e,o)}function ue(r){const[e]=r.trim().split(/\s+/,1);return e?/^[A-Z]?\d+(?:\.\d+)+$/i.test(e.replace(/^@/,""))||/(?:^|\/)[A-Z]?\d+(?:\.\d+)+\.story\.md$/i.test(e.replace(/^@/,"")):!1}function F(r){const e=r.match(/(?:^|[/@\s])([A-Z]?\d+(?:\.\d+)+)\.story\.md\b/i);return e?.[1]?e[1]:r.match(/(?:^|\s|@)([A-Z]?\d+(?:\.\d+)+)(?=$|\s)/i)?.[1]??null}function le(r){const e=r.trim(),t=e.search(/\s/);return t===-1?"":e.slice(t).trim()}function q(r){return le(r).split(/\s+/).map(e=>e.replace(/^@/,"").replace(/^['"]|['"]$/g,"")).filter(e=>e.length>0&&!e.startsWith("-"))}function $e(r){return q(r)[0]??null}function P(r,e){const i=r.replace(/^@/,"").replace(/^epic-/i,"").replace(/\.md$/i,""),c=[i,i.toUpperCase(),/^p\d+$/i.test(i)?`P${i.replace(/^p/i,"")}`:null,/^\d+$/.test(i)?`P${i}`:null].filter(o=>typeof o=="string"&&o.length>0);for(const o of c)if(e.epics[o])return o;return null}function pe(r,e){const t=r.match(/(?:^|[/@\s])epic-(P?\d+)\.md\b/i);return t?.[1]?P(t[1],e):null}function R(r,e){const t=r.trim().match(/^@epic-(P[0-9]{1,12})$/);if(t)return P(t[1],e);const i=pe(r,e);if(i)return i;for(const c of q(r)){if(/^[A-Z]?\d+(?:\.\d+)+$/i.test(c))continue;const o=P(c,e);if(o)return o}return null}function fe(r,e){const t=R(r,e);if(t)return t;const i=e.yoloop,c=i?.state?.currentSession?.currentEpicId;if(typeof c=="string"&&e.epics[c])return c;const o=i?.lock?.currentEpicId??i?.lock?.epicId;return typeof o=="string"&&e.epics[o]?o:null}function ye(r){const e=r.match(/(?:^|[/@\s])epic-(P?\d+)\.md\b/i)?.[1];if(e)return/^P/i.test(e)?e.toUpperCase():`P${e}`;for(const t of q(r)){if(/^P\d+$/i.test(t))return t.toUpperCase();if(/^\d+$/.test(t))return`P${t}`}return null}function j(r,e){if(typeof r.epic_id=="string"&&r.epic_id.length>0)return r.epic_id;const t=e.split(".").slice(0,-1).join(".");return t.length>0?t:null}function L(r){return typeof r=="string"&&["done","completed","merged","cancelled","canceled","abandoned"].includes(r.toLowerCase())}function x(r,e,t){if(t.has(r))return;const i=e.stories[r];if(!i)return;t.add(r);const c=i.depends_on;if(Array.isArray(c))for(const o of c)typeof o=="string"&&x(o,e,t)}function me(r,e){const t=C(e.stories,[r]),i={};for(const c of t.orderedIds){const o=e.stories[c];o&&(i[c]=o)}return i}function $(r,e,t=[]){const i={};for(const c of t)e.epics[c]&&(i[c]=e.epics[c]);for(const[c,o]of Object.entries(r)){const s=j(o,c);s&&e.epics[s]&&(i[s]=e.epics[s])}return i}function ge(r,e,t){if(t.has(r))return;const i=e.epics[r];if(!i)return;t.add(r);const c=i.depends_on;if(Array.isArray(c))for(const o of c)typeof o=="string"&&o.length>0&&ge(o,e,t)}function V(r,e,t){const i=C(t.epics,[r]),c=new Set(i.orderedIds);for(const[s,a]of Object.entries(e)){const u=j(a,s);u&&t.epics[u]&&c.add(u)}const o={};for(const s of[...c].sort((a,u)=>a.localeCompare(u,"en"))){const a=t.epics[s];a&&(o[s]=s===r?a:H(s,a))}return o}function G(r,e,t){const i=e.stories;if(!Array.isArray(i)||i.some(s=>typeof s!="string"||s.length===0))throw new y("STRUCTURAL_DEPENDENCY_MISSING",{nodes:0,edges:0,malformedStoryMemberships:1});const c=C(t.stories,i),o={};for(const s of c.orderedIds){const a=t.stories[s];a&&(o[s]=j(a,s)===r?ne(s,a):Y(s,a))}return o}function he(r,e,t){const i=[...e.stories].sort((s,a)=>s.localeCompare(a,"en")),c=Object.entries(t).filter(([s,a])=>j(a,s)===r).map(([s])=>s).sort((s,a)=>s.localeCompare(a,"en")),o=W("sha256").update(`target-epic-coverage-v1\0${JSON.stringify({targetEpicId:r,declaredStoryIds:i,includedStoryIds:c})}`).digest("hex");return{schemaVersion:"TargetEpicCoverage/1.0",targetEpicId:r,declaredStoryIds:i,includedStoryIds:c,membershipSha256:o,publicSafe:!0}}function Y(r,e){const t=Array.isArray(e.depends_on)?[...new Set(e.depends_on.filter(m=>typeof m=="string"&&m.length>0))].sort((m,E)=>m.localeCompare(E,"en")):void 0,i={id:d(e.id)??r,...d(e.epic_id)?{epic_id:d(e.epic_id)}:{},...d(e.status,40)?{status:d(e.status,40)}:{},...t?{depends_on:t}:{},...h(e.supersededBy)?{supersededBy:e.supersededBy}:{}},c=M(r,e);if(!ie(e.status))return{...i,...c?{scheduling_checkpoint_evidence:c}:{}};const o=e.source==="create-epic"||e.source==="discovered"?e.source:void 0,s=T(e.branch_name),a=w(e.last_step,120),u=Array.isArray(e.steps_completed)&&e.steps_completed.length<=64?e.steps_completed.map(m=>w(m,120)):[],l=u.length>0&&u.every(m=>m!==void 0)?u:void 0,f=typeof e.pr_number=="number"&&Number.isSafeInteger(e.pr_number)&&e.pr_number>0?e.pr_number:void 0,p=ce(r,e),g=p?oe(r,e):void 0;return{...i,...o?{source:o}:{},...s?{branch_name:s}:{},...a?{last_step:a}:{},...l?{steps_completed:l}:{},...f?{pr_number:f}:{},...p?{checkpoint:p}:{},...g?{checkpoint_verification:g}:{},...c?{scheduling_checkpoint_evidence:c}:{},...S(e.files_to_modify)!==void 0?{files_to_modify:S(e.files_to_modify)}:{},...S(e.contracts)!==void 0?{contracts:S(e.contracts)}:{},...S(e.contract_refs)!==void 0?{contract_refs:S(e.contract_refs)}:{},...S(e.shared_surfaces)!==void 0?{shared_surfaces:S(e.shared_surfaces)}:{}}}function H(r,e){const t=Array.isArray(e.stories)?[...new Set(e.stories.filter(c=>typeof c=="string"&&c.length>0))].sort((c,o)=>c.localeCompare(o,"en")):[],i=Array.isArray(e.depends_on)?[...new Set(e.depends_on.filter(c=>typeof c=="string"&&c.length>0))].sort((c,o)=>c.localeCompare(o,"en")):[];return{id:d(e.id)??r,...d(e.status,40)?{status:d(e.status,40)}:{},...d(e.lifecycle_classification,40)?{lifecycle_classification:d(e.lifecycle_classification,40)}:{},stories:t,depends_on:i}}function be(r,e,t){const i=C(e.stories),c=C(e.epics),o=Object.fromEntries(i.orderedIds.map(u=>[u,Y(u,e.stories[u])])),s=Object.fromEntries(c.orderedIds.map(u=>[u,H(u,e.epics[u])])),a={kind:"projected",commandId:t.commandId,stateProjectionPolicy:t.stateProjectionPolicy,projectionMode:"yoloop-discovery",trigger:r,targetEpicId:null,targetStoryId:null,includedStoryCount:i.orderedIds.length,includedEpicCount:c.orderedIds.length,omittedStoryCount:0,omittedEpicCount:0,reason:"targeted-invocation",reasonCodes:_(["structural-required","yoloop-discovery",`structural-edges-${i.edgeCount+c.edgeCount}`,"content-fields-omitted"])};return I({...e,stories:o,epics:s,scope:a},e,a)}function _e(r,e){const t=new Set,i=r.stories;if(Array.isArray(i))for(const o of i)typeof o=="string"&&x(o,e,t);const c={};for(const o of t){const s=e.stories[o];s&&(c[o]=s)}return c}function Se(r){const e={};for(const[t,i]of Object.entries(r.epics))e[t]={id:d(i.id)??t,...d(i.status)?{status:d(i.status)}:{},...k.includes(i.lifecycle_classification)?{lifecycle_classification:i.lifecycle_classification}:{},...typeof i.total_stories=="number"&&Number.isFinite(i.total_stories)?{total_stories:i.total_stories}:{},...typeof i.completed_stories=="number"&&Number.isFinite(i.completed_stories)?{completed_stories:i.completed_stories}:{}};return e}function K(r){const e={};for(const t of Object.values(r)){const i=d(t.status,40)??"unknown";e[i]=(e[i]??0)+1}return e}function je(r){const e=Object.fromEntries(k.map(t=>[t,0]));for(const t of Object.values(r)){const i=k.includes(t.lifecycle_classification)?t.lifecycle_classification:"active";e[i]=(e[i]??0)+1}return e}function N(r,e){if(!e)return!0;const t=r.epics[e];return t?!k.includes(t.lifecycle_classification)||t.lifecycle_classification==="active":!0}function Z(r){for(const e of["last_updated","updated_at","completed_at","created_at","discovered_at"]){const t=r[e];if(typeof t!="string")continue;const i=Date.parse(t);if(Number.isFinite(i))return i}return 0}function Ie(r){return Object.entries(r.stories).map(([e,t])=>({id:e,story:t,timestamp:Z(t)})).sort((e,t)=>t.timestamp-e.timestamp||e.id.localeCompare(t.id)).slice(0,U).map(({id:e,story:t})=>({id:e,...d(t.epic_id)?{epicId:d(t.epic_id)}:{},...d(t.status,40)?{status:d(t.status,40)}:{},...d(t.last_step??t.lastStep)?{lastStep:d(t.last_step??t.lastStep)}:{},...d(t.last_updated??t.updated_at??t.completed_at??t.created_at)?{lastUpdated:d(t.last_updated??t.updated_at??t.completed_at??t.created_at)}:{}}))}function Ce(r){const e=r.current_session;if(!e)return;const t={activeEpicId:d(e.active_epic_id)??null,activeStoryId:d(e.active_story_id)??null,activeStepId:d(e.active_step_id)??null,sessionId:d(e.session_id)??null,startedAt:d(e.started_at)??null};return Object.values(t).some(i=>i!=null)?t:void 0}function ke(r){const e=r.yoloop;if(!h(e))return;const t=h(e.state)?e.state:void 0,i=h(t?.currentSession)?t.currentSession:void 0,c=h(e.lock)?e.lock:void 0,o={...typeof e.active=="boolean"?{active:e.active}:{},currentEpicId:d(i?.currentEpicId??e.currentEpicId)??null,currentStoryId:d(i?.currentStoryId??e.currentStoryId)??null,sessionId:d(i?.sessionId??e.sessionId)??null,lockEpicId:d(c?.currentEpicId??c?.epicId)??null};return Object.keys(o).length>0?o:void 0}function ve(r){const e=r.continuity;if(!h(e))return;const t=Array.isArray(e.reasonCodes)?e.reasonCodes.filter(i=>typeof i=="string"):void 0;return{present:!0,activeJobId:d(e.activeJobId??e.jobId)??null,activeGoalId:d(e.activeGoalId??e.goalId)??null,activeLoopId:d(e.activeLoopId??e.loopId)??null,...t&&t.length>0?{reasonCodes:_(t)}:{}}}function Ee(r,e,t){const i=d(e?.activeStoryId),c=d(e?.activeEpicId),o=d(e?.activeStepId),s=i&&r.stories[i]?j(r.stories[i],i):null;if((i||c||o)&&N(r,c??s))return{epicId:c??null,storyId:i??null,stepId:o??null};const a=d(t?.currentStoryId),u=d(t?.currentEpicId??t?.lockEpicId);if((a||u)&&N(r,u))return{epicId:u??null,storyId:a??null,stepId:null};const l=Object.entries(r.stories).map(([f,p])=>({id:f,story:p,timestamp:Z(p)})).filter(({id:f,story:p})=>!L(p.status)&&N(r,j(p,f))).sort((f,p)=>p.timestamp-f.timestamp||f.id.localeCompare(p.id))[0];return l?{epicId:j(l.story,l.id),storyId:l.id,stepId:d(l.story.last_step??l.story.lastStep)??null}:{epicId:null,storyId:null,stepId:null}}function Re(r,e){const t=K(r.stories),i=K(r.epics),c=je(r.epics),o=Object.values(r.epics).filter(g=>(k.includes(g.lifecycle_classification)?g.lifecycle_classification:"active")==="active"&&!L(g.status)).length,s=Ce(r),a=ke(r),u=ve(r),l=Ee(r,s,a),f=Ie(r),p=_(e.reasonCodes,["state-summary-attached","state-summary-bounded",`projection-${e.projectionMode??e.kind}`,e.stateProjectionPolicy?`policy-${e.stateProjectionPolicy}`:"policy-unknown",f.length>=U?"recent-stories-capped":"recent-stories-bounded",l.storyId||l.epicId?"active-ref-derived":"active-ref-empty",a?"yoloop-session-present":"yoloop-session-absent",u?"continuity-session-present":"continuity-session-absent"]);return{schemaVersion:1,totals:{stories:Object.keys(r.stories).length,epics:Object.keys(r.epics).length,storyStatus:t,epicStatus:i,epicLifecycle:c,activeEpics:o,blockedStories:t.blocked??0},active:l,blockedCount:t.blocked??0,recentStories:f,...s?{currentSession:s}:{},...a?{currentYoloopSession:a}:{},...u?{currentContinuitySession:u}:{},projection:{commandId:e.commandId??null,stateProjectionPolicy:e.stateProjectionPolicy??null,projectionMode:e.projectionMode,scopeKind:e.kind,includedStoryCount:e.includedStoryCount,includedEpicCount:e.includedEpicCount??Object.keys(r.epics).length,omittedStoryCount:e.omittedStoryCount,omittedEpicCount:e.omittedEpicCount,reason:e.reason},reasonCodes:p,publicSafe:!0}}function I(r,e,t){return{...r,stateSummary:Re(e,t)}}function Oe(r,e,t){const i={};for(const o of Object.keys(e.epics))i[o]={id:o};const c={kind:"projected",commandId:t.commandId,stateProjectionPolicy:t.stateProjectionPolicy,projectionMode:"summary-only",trigger:r,targetEpicId:null,targetStoryId:null,includedStoryCount:0,includedEpicCount:Object.keys(i).length,omittedStoryCount:Object.keys(e.stories).length,omittedEpicCount:0,reason:"epic-summary",reasonCodes:["epic-summary","stories-omitted","epic-stubs-only"]};return I({...e,stories:{},epics:i,scope:c},e,c)}function b(r,e,t,i=["summary-only","stories-omitted"],c="summary-only"){const o=Se(e),s={kind:"projected",commandId:t.commandId,stateProjectionPolicy:t.stateProjectionPolicy,projectionMode:c,trigger:r,targetEpicId:null,targetStoryId:null,includedStoryCount:0,includedEpicCount:Object.keys(o).length,omittedStoryCount:Object.keys(e.stories).length,omittedEpicCount:Math.max(0,Object.keys(e.epics).length-Object.keys(o).length),reason:"summary-only",reasonCodes:_(i)};return I({...e,stories:{},epics:o,scope:s},e,s)}function D(r,e,t,i,c,o){const s=e.stories[i];if(!s)throw new y("STRUCTURAL_TARGET_NOT_FOUND",{stories:Object.keys(e.stories).length,epics:Object.keys(e.epics).length,targetKind:"story"});const a=j(s,i);if(!a)throw new y("STRUCTURAL_TARGET_NOT_FOUND",{stories:Object.keys(e.stories).length,epics:Object.keys(e.epics).length,targetKind:"epic"});const u=e.epics[a];if(!u)throw new y("STRUCTURAL_TARGET_NOT_FOUND",{stories:Object.keys(e.stories).length,epics:Object.keys(e.epics).length,targetKind:"epic"});const l=c==="yolo-story",f=l?G(a,u,e):me(i,e),p=l?V(a,f,e):$(f,e);if(!f[i]||!p[a])throw new y("STRUCTURAL_TARGET_NOT_FOUND",{stories:Object.keys(f).length,epics:Object.keys(p).length,targetKind:"story"});const g={kind:"projected",commandId:t.commandId,stateProjectionPolicy:t.stateProjectionPolicy,projectionMode:c,trigger:r,targetEpicId:a,targetStoryId:i,includedStoryCount:Object.keys(f).length,includedEpicCount:Object.keys(p).length,omittedStoryCount:Math.max(0,Object.keys(e.stories).length-Object.keys(f).length),omittedEpicCount:Math.max(0,Object.keys(e.epics).length-Object.keys(p).length),reason:"targeted-invocation",reasonCodes:_(o,l?["epic-graph-authority-complete"]:[])};return I({...e,stories:f,epics:p,scope:g},e,g)}function B(r,e,t,i,c,o){const s=e.epics[i];if(!s)throw new y("STRUCTURAL_TARGET_NOT_FOUND",{stories:Object.keys(e.stories).length,epics:Object.keys(e.epics).length,targetKind:"epic"});const a=_e(s,e),u=$(a,e,[i]);if(!u[i])throw new y("STRUCTURAL_TARGET_NOT_FOUND",{stories:Object.keys(a).length,epics:Object.keys(u).length,targetKind:"epic"});const l={kind:"projected",commandId:t.commandId,stateProjectionPolicy:t.stateProjectionPolicy,projectionMode:c,trigger:r,targetEpicId:i,targetStoryId:null,includedStoryCount:Object.keys(a).length,includedEpicCount:Object.keys(u).length,omittedStoryCount:Math.max(0,Object.keys(e.stories).length-Object.keys(a).length),omittedEpicCount:Math.max(0,Object.keys(e.epics).length-Object.keys(u).length),reason:"targeted-invocation",reasonCodes:_(o)};return I({...e,stories:a,epics:u,scope:l},e,l)}function Ae(r,e,t){const i=ye(r),c=R(r,e);if(i&&!c)throw new y("STRUCTURAL_TARGET_NOT_FOUND",{stories:Object.keys(e.stories).length,epics:Object.keys(e.epics).length,targetKind:"epic"});const o=fe(r,e),s=O({commandId:t.commandId,explicitYoloopEpicId:c,sessionYoloopEpicId:c?null:o});if(s==="yoloop-discovery")return be(r,e,t);if(!o||s!=="yoloop-target"&&s!=="yoloop-session")throw new y("STRUCTURAL_TARGET_NOT_FOUND",{stories:Object.keys(e.stories).length,epics:Object.keys(e.epics).length,targetKind:"epic"});const a=e.epics[o];if(!a)throw new y("STRUCTURAL_TARGET_NOT_FOUND",{stories:Object.keys(e.stories).length,epics:Object.keys(e.epics).length,targetKind:"epic"});const u=G(o,a,e),l=V(o,u,e);if(!l[o])throw new y("STRUCTURAL_TARGET_NOT_FOUND",{stories:Object.keys(u).length,epics:Object.keys(l).length,targetKind:"epic"});const f=s,p={kind:"projected",commandId:t.commandId,stateProjectionPolicy:t.stateProjectionPolicy,projectionMode:f,trigger:r,targetEpicId:o,targetStoryId:null,targetEpicCoverage:he(o,a,u),includedStoryCount:Object.keys(u).length,includedEpicCount:Object.keys(l).length,omittedStoryCount:Math.max(0,Object.keys(e.stories).length-Object.keys(u).length),omittedEpicCount:Math.max(0,Object.keys(e.epics).length-Object.keys(l).length),reason:"targeted-invocation",reasonCodes:["structural-required",f,"yoloop-targeted"]};return I({...e,stories:u,epics:l,scope:p},e,p)}function we(r,e){const t={};for(const[i,c]of Object.entries(r.epics)){const o=Array.isArray(c.stories)?c.stories.filter(s=>typeof s=="string"&&e.has(s)):[];t[i]={id:d(c.id)??i,...d(c.status,40)?{status:d(c.status,40)}:{},...typeof c.total_stories=="number"&&Number.isFinite(c.total_stories)?{total_stories:c.total_stories}:{},...typeof c.completed_stories=="number"&&Number.isFinite(c.completed_stories)?{completed_stories:c.completed_stories}:{},...o.length>0?{stories:o}:{},...o.length>0&&Array.isArray(c.depends_on)?{depends_on:c.depends_on.filter(s=>typeof s=="string"&&s.length>0)}:{},...o.length>0&&(c.branch_mode==="epic"||c.branch_mode==="story")?{branch_mode:c.branch_mode}:{},...o.length>0&&typeof c.execution_branch=="string"?{execution_branch:c.execution_branch}:{},...o.length>0&&typeof c.origin_branch=="string"?{origin_branch:c.origin_branch}:{},...o.length>0&&(c.branch_lease===null||typeof c.branch_lease=="object")?{branch_lease:c.branch_lease}:{},...o.length>0&&(c.origin_binding===null||typeof c.origin_binding=="object")?{origin_binding:c.origin_binding}:{},...o.length>0&&(c.aggregate_qa_receipt===null||typeof c.aggregate_qa_receipt=="object")?{aggregate_qa_receipt:c.aggregate_qa_receipt}:{},...o.length>0&&(c.head_reconciliation_receipt===null||typeof c.head_reconciliation_receipt=="object")?{head_reconciliation_receipt:c.head_reconciliation_receipt}:{},...o.length>0&&c.story_worktree_evidence!==null&&typeof c.story_worktree_evidence=="object"?{story_worktree_evidence:c.story_worktree_evidence}:{},...o.length>0&&Array.isArray(c.story_worktree_leases)&&c.story_worktree_leases.length>0?{story_worktree_leases:c.story_worktree_leases}:{},...o.length>0&&c.branch_mode_conversion_receipt!==null&&typeof c.branch_mode_conversion_receipt=="object"&&!Array.isArray(c.branch_mode_conversion_receipt)?{branch_mode_conversion_receipt:c.branch_mode_conversion_receipt}:{}}}return t}function Te(r){return r.stateSummary?.totals.stories??(r.scope?.includedStoryCount??Object.keys(r.stories).length)+(r.scope?.omittedStoryCount??0)}function qe(r){return r.stateSummary?.totals.epics??(r.scope?.includedEpicCount??Object.keys(r.epics).length)+(r.scope?.omittedEpicCount??0)}function Pe(r,e){if(r.stateSummary)return{...r.stateSummary,projection:{...r.stateSummary.projection,scopeKind:"projected",projectionMode:e.projectionMode,includedStoryCount:e.includedStoryCount,includedEpicCount:e.includedEpicCount??r.stateSummary.projection.includedEpicCount,omittedStoryCount:e.omittedStoryCount,omittedEpicCount:e.omittedEpicCount,reason:"body-size"},reasonCodes:_(r.stateSummary.reasonCodes,["payload-size-guardrail","state-summary-preserved","nonessential-state-degraded"])}}function Ve(r){const e=r.scope,t=new Set,i=e?.projectionMode==="structural-required"||e?.projectionMode==="yolo-story"||e?.projectionMode==="yoloop-target"||e?.projectionMode==="yoloop-session"||e?.projectionMode==="yoloop-discovery";if(i)for(const m of Object.keys(r.stories))t.add(m);else e?.targetStoryId&&x(e.targetStoryId,r,t);const c={};for(const m of t){const E=r.stories[m];E&&(c[m]=E)}const o=we(r,t),s=Object.keys(c).length,a=Object.keys(o).length,u=Math.max(0,Te(r)-s),l=Math.max(0,qe(r)-a),f=i?e?.projectionMode??"structural-required":e?.projectionMode==="yolo-story"?"yolo-story":"summary-only",p={kind:"projected",commandId:e?.commandId??null,stateProjectionPolicy:e?.stateProjectionPolicy??null,projectionMode:f,targetEpicId:e?.targetEpicId??null,targetStoryId:e?.targetStoryId??null,...e?.targetEpicCoverage?{targetEpicCoverage:e.targetEpicCoverage}:{},includedStoryCount:s,includedEpicCount:a,omittedStoryCount:u,omittedEpicCount:l,reason:"body-size",reasonCodes:_(e?.reasonCodes,["payload-size-guardrail",t.size>0?"structural-targets-preserved":"stories-omitted","epics-stubbed","state-summary-preserved","redundant-trigger-omitted"])},g=Pe(r,p);return{...r,stories:c,epics:o,scope:p,...g?{stateSummary:g}:{}}}function xe(r,e){const t=r.trim(),i=z(t);try{if(!i){if(ue(t)){const o=n("story-reference","story-targeted"),s=F(t);if(s)return D(t,e,o,s,"targeted-story",["story-reference-targeted"])}return b(t,e,n("unknown","adaptive-targeted"),["unknown-command-summary-only"])}if(i.stateProjectionPolicy==="epic-summary")return Oe(t,e,i);if(i.stateProjectionPolicy==="yoloop-targeted")return Ae(t,e,i);const c=F(t);if(i.stateProjectionPolicy==="story-targeted"){if(c){const s=O({commandId:i.commandId,targetStoryId:c})==="yolo-story";return D(t,e,i,c,s?"yolo-story":i.structuralRequired?"structural-required":"targeted-story",[s?"yolo-story":i.structuralRequired?"structural-required":"targeted-story"])}if(i.commandId==="yolo"||i.commandId==="yolo-inline"){const o=O({commandId:i.commandId});return b(t,e,i,["yolo-inline","stories-omitted","historical-content-omitted"],o??"yolo-inline")}return i.commandId==="commit"&&/^\*?(?:commit|commit-push)$/i.test(t)?b(t,e,i,["working-tree-commit","stories-omitted","historical-content-omitted"]):i.structuralRequired?(()=>{throw new y("STRUCTURAL_TARGET_NOT_FOUND",{stories:Object.keys(e.stories).length,epics:Object.keys(e.epics).length,targetKind:"story"})})():b(t,e,i,["story-target-missing-summary-only"])}if(i.stateProjectionPolicy==="adaptive-targeted"){if(c&&e.stories[c])return D(t,e,i,c,"targeted-story",["adaptive-story-targeted"]);const o=R(t,e);return o?B(t,e,i,o,"targeted-epic",["adaptive-epic-targeted"]):b(t,e,i,["adaptive-summary-only","target-unresolved-summary-only"])}if(i.stateProjectionPolicy==="epic-targeted"){if(i.commandId.startsWith("arch-")&&/(?:^|\s)epic-arch\s*$/i.test(t)&&e.archPlan?.execution?.currentStageCommand===i.commandId)return b(t,e,i,["architecture-root-delegated"]);const o=R(t,e);return o?B(t,e,i,o,i.structuralRequired?"structural-required":"targeted-epic",[i.structuralRequired?"structural-required":"targeted-epic"]):i.structuralRequired?(()=>{throw new y("STRUCTURAL_TARGET_NOT_FOUND",{stories:Object.keys(e.stories).length,epics:Object.keys(e.epics).length,targetKind:"epic"})})():b(t,e,i,["epic-target-missing-summary-only"])}return i.stateProjectionPolicy==="continuity-scoped"?b(t,e,i,["continuity-scoped-summary-only"]):b(t,e,i,["policy-full-summary-only"])}catch(c){if(c instanceof y)throw c;if(i?.structuralRequired)throw new y("STRUCTURAL_DEPENDENCY_MISSING",{stories:Object.keys(e.stories).length,epics:Object.keys(e.epics).length,projectionErrors:1});return b(t,e,i??n("unknown","adaptive-targeted"),["projection-error-summary-only"])}}const Ne=new Set(["yolo-story","yolo-inline","yoloop-target","yoloop-session","yoloop-discovery"]);function De(r){let e=0;for(const t of[r.stories,r.epics])for(const i of Object.values(t))Array.isArray(i.depends_on)&&(e+=i.depends_on.filter(c=>typeof c=="string").length);return e}function Ge(r,e){const t=z(r.trim());if(!t||!["yolo","yolo-inline","yoloop"].includes(t.commandId))return null;try{const i=xe(r,e),c=i.scope?.projectionMode;if(!c||!Ne.has(c))throw new y("STRUCTURAL_DEPENDENCY_MISSING",{stories:Object.keys(i.stories).length,epics:Object.keys(i.epics).length,projectionShapeErrors:1});return Object.freeze({ok:!0,version:2,shape:c,snapshot:i,included:{epics:i.scope?.includedEpicCount??Object.keys(i.epics).length,stories:i.scope?.includedStoryCount??Object.keys(i.stories).length,edges:De(i)},omitted:{epics:i.scope?.omittedEpicCount??0,stories:i.scope?.omittedStoryCount??0},cycleCount:0})}catch(i){if(!(i instanceof y))throw i;return Object.freeze({ok:!1,code:i.code,publicDetails:{...i.publicDetails,...i.code==="STRUCTURAL_CONTEXT_TOO_LARGE"?{}:{planningCause:Q(i.code)}}})}}export{Ve as degradeStateSnapshotForPayloadLimit,Q as planningProjectionCauseForStructuralCode,Fe as projectEpicOperationalEvidenceForRequest,xe as projectStateSnapshotForInvoke,Ge as projectStateSnapshotResultV2ForInvoke};
|
|
1
|
+
import{createHash as W}from"node:crypto";import{analyzeDependencyDag as C,StructuralDagError as y}from"./structural-dag-projection.js";import{classifyInvocationShapeV2 as O}from"./invocation-shape.js";const U=12,J=16,k=["active","archived","rolled-back","synthetic","orphan"],X=new Set(["in-progress","branch-ready","diagnose","research","write-spec","create-tasks","implemented","refactor-suggest-done","property-tests-emitted","tests-validated","qa-gate-passed","memory-updated","committed","synced","pr-created","pr-reviewed","partial"]);function Q(r){return r==="STRUCTURAL_TARGET_NOT_FOUND"?"registration-missing":r==="STRUCTURAL_DEPENDENCY_CYCLE"?"dependency-cycle":"dependency-missing"}function Fe(r){const e=/^[a-f0-9]{64}$/,t=/^P[1-9][0-9]*(?:\.[0-9]+)*$/,i=/^[A-Za-z0-9][A-Za-z0-9._/-]{0,239}$/;if(r.schemaVersion!=="EpicOperationalPublicProjection/1.0"||!e.test(r.repositoryFingerprint)||!e.test(r.identityHash)||!t.test(r.epicId)||!i.test(r.executionBranch)||!e.test(r.graphRevision)||!Number.isSafeInteger(r.storeRevision)||r.storeRevision<0||!Number.isSafeInteger(r.writerEpoch)||r.writerEpoch<1||r.runId!==null&&r.runId.length>128||r.runStatus!==null&&r.runStatus.length>32||r.runRevision!==null&&(!Number.isSafeInteger(r.runRevision)||r.runRevision<0)||r.snapshotHash!==null&&!e.test(r.snapshotHash)||!e.test(r.continuationSessionHash)||!e.test(r.pendingAuthorityHash)||!Number.isSafeInteger(r.pendingAuthorityCount)||r.pendingAuthorityCount<0||r.pendingAuthorityCount>1024||r.reasonCodes.length>16||r.reasonCodes.some(c=>!/^[a-z0-9][a-z0-9-]{0,79}$/.test(c))||r.publicSafe!==!0)throw new Error("epic-operational-projection-invalid");return Object.freeze({schemaVersion:r.schemaVersion,repositoryFingerprint:r.repositoryFingerprint,identityHash:r.identityHash,epicId:r.epicId,executionBranch:r.executionBranch,graphRevision:r.graphRevision,storeRevision:r.storeRevision,writerEpoch:r.writerEpoch,runId:r.runId,runStatus:r.runStatus,runRevision:r.runRevision,snapshotHash:r.snapshotHash,continuationSessionHash:r.continuationSessionHash,pendingAuthorityHash:r.pendingAuthorityHash,pendingAuthorityCount:r.pendingAuthorityCount,lockActive:r.lockActive,currentSessionActive:r.currentSessionActive,journalActive:r.journalActive,reasonCodes:[...r.reasonCodes],publicSafe:!0})}const o=(r,e,t={})=>({commandId:r,stateProjectionPolicy:e,...t}),A=Object.freeze({status:o("status","full"),"arch-plan":o("arch-plan","full"),"arch-prd":o("arch-prd","full"),"arch-architecture":o("arch-architecture","epic-targeted",{structuralRequired:!0}),"arch-api-contracts":o("arch-api-contracts","epic-targeted",{structuralRequired:!0}),"arch-api-integrations":o("arch-api-integrations","epic-targeted",{structuralRequired:!0}),"arch-database":o("arch-database","epic-targeted",{structuralRequired:!0}),"arch-security":o("arch-security","epic-targeted",{structuralRequired:!0}),"arch-design-system":o("arch-design-system","epic-targeted",{structuralRequired:!0}),"arch-ux-design":o("arch-ux-design","epic-targeted",{structuralRequired:!0}),"arch-performance":o("arch-performance","epic-targeted",{structuralRequired:!0}),"arch-testing":o("arch-testing","epic-targeted",{structuralRequired:!0}),"arch-infrastructure":o("arch-infrastructure","epic-targeted",{structuralRequired:!0}),"arch-review":o("arch-review","epic-targeted",{structuralRequired:!0}),"arch-fitness-functions":o("arch-fitness-functions","epic-targeted",{structuralRequired:!0}),"create-epic":o("create-epic","epic-summary"),"idea-diagnose":o("idea-diagnose","full"),"idea-research":o("idea-research","epic-targeted",{structuralRequired:!0}),"generate-epic":o("generate-epic","epic-targeted",{structuralRequired:!0}),exec:o("exec","story-targeted",{structuralRequired:!0}),yolo:o("yolo","story-targeted",{structuralRequired:!0}),"yolo-inline":o("yolo-inline","story-targeted",{structuralRequired:!0}),epic:o("epic","epic-targeted",{structuralRequired:!0}),"setup-branch":o("setup-branch","story-targeted",{structuralRequired:!0}),diagnose:o("diagnose","adaptive-targeted"),"diagnose-inline":o("diagnose-inline","full"),research:o("research","adaptive-targeted"),"research-inline":o("research-inline","full"),"write-spec":o("write-spec","story-targeted",{structuralRequired:!0}),"create-tasks":o("create-tasks","story-targeted",{structuralRequired:!0}),implement:o("implement","story-targeted",{structuralRequired:!0}),commit:o("commit","story-targeted",{structuralRequired:!0}),"commit-push":o("commit","story-targeted",{structuralRequired:!0}),sync:o("sync","story-targeted",{structuralRequired:!0}),"sync-main":o("sync","story-targeted",{structuralRequired:!0}),"create-pr":o("create-pr","story-targeted",{structuralRequired:!0}),review:o("review","story-targeted"),"review-pr":o("review","story-targeted"),merge:o("merge","story-targeted",{structuralRequired:!0}),"merge-pr":o("merge","story-targeted",{structuralRequired:!0}),"fix-blocked":o("fix-blocked","story-targeted"),"finalize-epic":o("finalize-epic","epic-targeted"),"resolve-conflicts":o("resolve-conflicts","story-targeted"),"update-memory":o("update-memory","full"),"update-project-memory":o("update-memory","story-targeted",{structuralRequired:!0}),refactor:o("refactor","adaptive-targeted"),"refactor-suggest":o("refactor","story-targeted",{structuralRequired:!0}),cleanup:o("cleanup","full"),audit:o("audit","full"),"tech-debt":o("tech-debt","full"),menu:o("menu","full"),plans:o("plans","full"),billing:o("billing","full"),subscribe:o("subscribe","full"),"qa-scan":o("qa-scan","full"),yoloop:o("yoloop","yoloop-targeted",{structuralRequired:!0}),"migrate-state":o("migrate-state","full"),"migrate-project-id":o("migrate-project-id","full"),"policy-audit":o("policy-audit","full"),"mutation-test":o("mutation-test","full"),"sync-openapi":o("sync-openapi","full"),"generate-pacts":o("generate-pacts","full"),"verify-pacts":o("verify-pacts","full"),"property-test":o("property-test","full"),"property-tests":o("property-test","story-targeted",{structuralRequired:!0}),"chaos-plan":o("chaos-plan","full"),"ui-ux-review":o("ui-ux-review","adaptive-targeted"),"solyd-system":o("solyd-system","adaptive-targeted"),goal:o("goal","continuity-scoped"),loop:o("loop","continuity-scoped"),jobs:o("jobs","continuity-scoped"),runner:o("runner","continuity-scoped"),"goal-tick":o("goal-tick","continuity-scoped"),"loop-tick":o("loop-tick","continuity-scoped"),"validate-tests":o("validate-tests","story-targeted",{structuralRequired:!0}),"qa-gate":o("qa-gate","story-targeted",{structuralRequired:!0})}),ee=Object.freeze({st:"status",arquitetura:"arch-plan",architecture:"arch-plan",arch:"arch-plan",prd:"arch-prd","product-requirements":"arch-prd","arch-doc":"arch-architecture","tech-architecture":"arch-architecture","api-contracts":"arch-api-contracts","api-contract":"arch-api-contracts","api-integrations":"arch-api-integrations","api-int":"arch-api-integrations","database-schema":"arch-database","db-schema":"arch-database",db:"arch-database","cyber-security":"arch-security",security:"arch-security",sec:"arch-security","design-system":"arch-design-system",ds:"arch-design-system","atomic-design":"arch-design-system","ux-design":"arch-ux-design",ux:"arch-ux-design",wireframes:"arch-ux-design",wireframe:"arch-ux-design","user-flows":"arch-ux-design",performance:"arch-performance",perf:"arch-performance","capacity-planning":"arch-performance",capacity:"arch-performance","arch-perf":"arch-performance","performance-strategy":"arch-performance","testing-strategy":"arch-testing","test-plan":"arch-testing","test-strategy":"arch-testing","arch-test":"arch-testing",infrastructure:"arch-infrastructure",infra:"arch-infrastructure","deploy-plan":"arch-infrastructure",deployment:"arch-infrastructure","arch-infra":"arch-infrastructure","arch-deploy":"arch-infrastructure","review-consolidation":"arch-review",consolidation:"arch-review","architecture-review":"arch-review","arch-consolidation":"arch-review",fitness:"arch-fitness-functions","fitness-functions":"arch-fitness-functions",archfit:"arch-fitness-functions","arch-fit":"arch-fitness-functions","fit-funcs":"arch-fitness-functions","criar-epic":"create-epic",planejamento:"create-epic","idea-diag":"idea-diagnose","idea-pesq":"idea-research","gerar-epic":"generate-epic",executar:"exec",pipeline:"exec","parallel-epic":"epic",setup:"setup-branch",branch:"setup-branch",diag:"diagnose",diagnostico:"diagnose",c02:"diagnose",pesquisar:"research",pesq:"research","research-fix":"research",c03:"research",spec:"write-spec",especificacao:"write-spec",c04:"write-spec",tasks:"create-tasks",tarefas:"create-tasks",c05:"create-tasks",impl:"implement",implementar:"implement",c06:"implement",push:"commit",commit_push:"commit",cp:"commit",c07:"commit",sincronizar:"sync",c08:"sync",pr:"create-pr",c09:"create-pr",revisar:"review",c11:"review",mesclar:"merge",c12:"merge",fix:"fix-blocked",corrigir:"fix-blocked",finalizar:"finalize-epic",conflitos:"resolve-conflicts",memoria:"update-memory",refactoring:"refactor",refact:"refactor",refac:"refactor",rf:"refactor","cleanup-code":"refactor","code-cleanup":"refactor","code-quality":"refactor","improve-code":"refactor",modernize:"refactor",modernization:"refactor",legacy:"refactor","legacy-code":"refactor","debt-pay":"refactor","pay-debt":"refactor","debt-reduction":"refactor","smell-fix":"refactor","fix-smells":"refactor","code-smells":"refactor",strangler:"refactor","strangler-fig":"refactor",limpar:"cleanup",limpeza:"cleanup",auditar:"audit",auditoria:"audit",debt:"tech-debt",debts:"tech-debt","debt-list":"tech-debt","tech-debts":"tech-debt",td:"tech-debt",help:"menu",ajuda:"menu","?":"menu",commands:"menu",cmds:"menu",planos:"plans",pricing:"plans",bill:"billing",subscription:"billing",sub:"billing",upgrade:"subscribe",checkout:"subscribe",qa:"qa-scan","qa-test":"qa-scan","visual-qa":"qa-scan","e2e-scan":"qa-scan",troubleshoot:"qa-scan","debug-ui":"qa-scan",scan:"qa-scan",a11y:"qa-scan",accessibility:"qa-scan",wcag:"qa-scan","auto-yolo":"yoloop","epic-runner":"yoloop","story-runner":"yoloop","loop-yolo":"yoloop","auto-epic":"yoloop",migrate:"migrate-state","state-migrate":"migrate-state","schema-migrate":"migrate-state",policy:"policy-audit","audit-policy":"policy-audit","policy-history":"policy-audit",policies:"policy-audit",mutation:"mutation-test",stryker:"mutation-test","kill-mutants":"mutation-test","openapi-sync":"sync-openapi","api-sync":"sync-openapi","spec-sync":"sync-openapi","regen-openapi":"sync-openapi",pacts:"generate-pacts","gen-pacts":"generate-pacts","regen-pacts":"generate-pacts","create-pacts":"generate-pacts","verify-pact":"verify-pacts","pact-verify":"verify-pacts","check-pacts":"verify-pacts","pact-check":"verify-pacts",property:"property-test",pbt:"property-test",proptest:"property-test","invariant-test":"property-test",chaos:"chaos-plan",gameday:"chaos-plan","resilience-test":"chaos-plan","ux-review":"ui-ux-review","design-review":"ui-ux-review","visual-review":"ui-ux-review","product-polish":"ui-ux-review","security-system":"solyd-system","authorized-security":"solyd-system","sec-system":"solyd-system",goals:"goal","durable-goal":"goal","continuity-goal":"goal",loops:"loop","durable-loop":"loop","continuity-loop":"loop",job:"jobs","continuity-jobs":"jobs","neocortex-runner":"runner","continuity-runner":"runner"}),te=Object.freeze({1:"status",3:"arch-plan",4:"arch-prd",5:"arch-architecture",6:"arch-api-contracts",7:"arch-api-integrations",8:"arch-database",9:"arch-security",10:"arch-design-system",11:"arch-ux-design",12:"arch-performance",13:"arch-testing",14:"arch-infrastructure",15:"arch-review",16:"arch-fitness-functions",17:"create-epic",18:"idea-diagnose",19:"idea-research",20:"generate-epic",21:"exec",22:"yolo",23:"epic",24:"setup-branch",25:"diagnose",26:"research",27:"write-spec",28:"create-tasks",29:"implement",30:"commit",31:"sync",32:"create-pr",33:"review",34:"merge",35:"fix-blocked",36:"finalize-epic",37:"resolve-conflicts",38:"update-memory",39:"refactor",40:"cleanup",41:"audit",42:"tech-debt",43:"menu",44:"plans",45:"billing",46:"subscribe",47:"qa-scan",48:"yoloop",49:"migrate-state",50:"policy-audit",51:"mutation-test",52:"sync-openapi",53:"generate-pacts",54:"verify-pacts",55:"property-test",56:"chaos-plan",57:"ui-ux-review",58:"solyd-system",59:"goal",60:"loop",61:"jobs",62:"runner"});function d(r,e=120){if(typeof r!="string")return;const t=r.trim();if(t)return t.replace(/[^a-z0-9_.:-]+/gi,"_").slice(0,e)}function w(r,e=120){if(typeof r!="string")return;const t=r.trim(),i=d(r,e);return i===t?i:void 0}function T(r){if(typeof r!="string")return;const e=r.trim();if(!(!e||e.length>240||!/^[A-Za-z0-9][A-Za-z0-9._/-]*$/.test(e)||e.includes("..")||e.includes("//")||e.includes("@{")||e.endsWith("/")||e.endsWith(".")||e.split("/").some(t=>!t||t.startsWith(".")||t.endsWith(".lock"))))return e}function re(r){if(typeof r!="string")return;const e=r.replace(/\\/g,"/");if(!(!e||e.length>240||e.startsWith("/")||/^[A-Za-z]:/.test(e)||e.includes("..")||e.includes("//")||e.split("/").includes(".")||!/^[A-Za-z0-9._/:@#-]+$/.test(e)))return e}function S(r){if(r===void 0||!Array.isArray(r)||r.length>128)return;const e=r.map(re);if(!e.some(t=>t===void 0))return[...new Set(e)].sort((t,i)=>t.localeCompare(i,"en"))}function ie(r){return typeof r=="string"&&X.has(r.trim().toLowerCase().replace(/_/g,"-"))}function v(r,e){const t={};for(const i of e){const c=r[i];typeof c=="string"||typeof c=="boolean"||typeof c=="number"&&Number.isFinite(c)?t[i]=c:Array.isArray(c)&&c.every(n=>typeof n=="string")&&(t[i]=[...c])}return t}function ce(r,e){const t=e.checkpoint;if(!h(t)||t.schemaVersion!==1||t.storyId!==r||t.epicId!==e.epic_id||!T(t.branch)||typeof t.baseSha!="string"||!/^[0-9a-f]{7,64}$/i.test(t.baseSha)||typeof t.headSha!="string"||!/^[0-9a-f]{7,64}$/i.test(t.headSha)||t.baseSha===t.headSha||!w(t.idempotencyKey)||typeof t.recordedAt!="string"||!Number.isFinite(Date.parse(t.recordedAt))||!Array.isArray(t.commits)||t.commits.length===0||t.commits.length>256||t.commits.some(c=>typeof c!="string"||!/^[0-9a-f]{7,64}$/i.test(c))||!Array.isArray(t.receiptRefs)||t.receiptRefs.length===0||t.receiptRefs.length>256||t.receiptRefs.some(c=>typeof c!="string"||c.length>240||c.includes("..")||!/^[A-Za-z0-9._:/#\-[\]]+$/.test(c))||!h(t.qaReceipt)||t.qaReceipt.kind!=="story_qa_evidence"||t.qaReceipt.producer!=="local-yolo-tdd"||!["passed","blocked"].includes(String(t.qaVerdict))||!["approved","changes-requested","pending"].includes(String(t.reviewVerdict))||(t.reviewVerdict==="pending"?t.reviewReceipt!==void 0:!h(t.reviewReceipt)))return;const i=v(t,["schemaVersion","storyId","epicId","branch","baseSha","headSha","idempotencyKey","dispatchId","bundleId","bundleDigest","graphRevision","claimRevision","qaVerdict","reviewVerdict","recordedAt","commits","receiptRefs"]);return i.qaReceipt=v(t.qaReceipt,["schemaVersion","kind","producer","evidenceVersion","storyId","epicId","contract","command","manifestDigest","gateIds","resultDigest","baseSha","headSha","bundleDigest","graphRevision","sourceEvidenceDigest","verdict","checkedAt","receiptRef"]),h(t.reviewReceipt)&&(i.reviewReceipt=v(t.reviewReceipt,["schemaVersion","kind","producer","storyId","epicId","baseSha","headSha","bundleDigest","graphRevision","sourceEvidenceDigest","qaReceiptRef","verdict","reviewedAt","receiptRef"])),i}function ne(r,e){const t=e.checkpoint_verification;if(!(!h(t)||t.schemaVersion!==1||t.kind!=="story_checkpoint_physical_verification"||t.producer!=="client-p205-transient-v1"||t.publicSafe!==!0||t.storyId!==r||t.epicId!==e.epic_id||!["verified","rejected"].includes(String(t.verdict))))return v(t,["schemaVersion","kind","producer","storyId","epicId","branch","baseSha","headSha","aggregateHeadSha","commitBodyDigest","changedPathsDigest","claimVerification","effectiveClaimRevision","command","manifestDigest","gateIds","resultDigest","graphRevision","executionEvidenceDigest","sourceEvidenceDigest","verifiedAt","verdict","reasonCodes","publicSafe"])}function M(r,e){const t=e.scheduling_checkpoint_evidence,i=new Set(["schemaVersion","kind","producer","storyId","epicId","branch","baseSha","headSha","graphRevision","effectiveClaimRevision","sourceEvidenceDigest","verifiedAt","reasonCodes","integrationAuthorized","publicSafe"]);if(!(!h(t)||Object.keys(t).some(c=>!i.has(c))||t.schemaVersion!==1||t.kind!=="story_scheduling_checkpoint_evidence"||t.producer!=="client-git-physical-v1"||t.publicSafe!==!0||t.integrationAuthorized!==!1||t.storyId!==r||t.epicId!==e.epic_id||!T(t.branch)||typeof t.baseSha!="string"||!/^[0-9a-f]{40,64}$/i.test(t.baseSha)||typeof t.headSha!="string"||!/^[0-9a-f]{40,64}$/i.test(t.headSha)||typeof t.graphRevision!="string"||!/^[0-9a-f]{64}$/i.test(t.graphRevision)||typeof t.effectiveClaimRevision!="string"||!/^[0-9a-f]{64}$/i.test(t.effectiveClaimRevision)||typeof t.sourceEvidenceDigest!="string"||!/^[0-9a-f]{64}$/i.test(t.sourceEvidenceDigest)||typeof t.verifiedAt!="string"||!Number.isFinite(Date.parse(t.verifiedAt))||!Array.isArray(t.reasonCodes)||t.reasonCodes.length!==1||t.reasonCodes[0]!=="checkpoint-git-scheduling-verified"))return v(t,[...i])}function oe(r,e){const t={...e},i=M(r,e);return i?(t.scheduling_checkpoint_evidence=i,delete t.checkpoint,delete t.checkpoint_verification):delete t.scheduling_checkpoint_evidence,t}function h(r){return r!==null&&typeof r=="object"&&!Array.isArray(r)}function _(...r){const e=new Set,t=[];for(const i of r)for(const c of i??[]){const n=d(c,80);if(!(!n||e.has(n))&&(e.add(n),t.push(n),t.length>=J))return t}return t}function se(r){return r.trim().replace(/^@?\*/,"").replace(/^@/,"").toLowerCase()}function ae(r){return r.trim().split(/\s+/,1)[0]??""}function z(r){if(/^@epic-P[0-9]{1,12}$/.test(r.trim()))return A.epic;const e=ae(r);if(!e)return A.menu;const t=se(e),i=te[t]??ee[t]??t;return A[i]??null}function de(r,e,t,i="full-compatible",c=["full-state"]){return{kind:"full",commandId:t?.commandId??null,stateProjectionPolicy:t?.stateProjectionPolicy??null,projectionMode:i,trigger:r,targetEpicId:null,targetStoryId:null,includedStoryCount:Object.keys(e.stories).length,includedEpicCount:Object.keys(e.epics).length,omittedStoryCount:0,omittedEpicCount:0,reason:"full-state",reasonCodes:_(c)}}function Le(r,e,t,i="full-compatible",c=["full-state"]){const n=de(r,e,t,i,c);return I({...e,scope:n},e,n)}function ue(r){const[e]=r.trim().split(/\s+/,1);return e?/^[A-Z]?\d+(?:\.\d+)+$/i.test(e.replace(/^@/,""))||/(?:^|\/)[A-Z]?\d+(?:\.\d+)+\.story\.md$/i.test(e.replace(/^@/,"")):!1}function F(r){const e=r.match(/(?:^|[/@\s])([A-Z]?\d+(?:\.\d+)+)\.story\.md\b/i);return e?.[1]?e[1]:r.match(/(?:^|\s|@)([A-Z]?\d+(?:\.\d+)+)(?=$|\s)/i)?.[1]??null}function le(r){const e=r.trim(),t=e.search(/\s/);return t===-1?"":e.slice(t).trim()}function q(r){return le(r).split(/\s+/).map(e=>e.replace(/^@/,"").replace(/^['"]|['"]$/g,"")).filter(e=>e.length>0&&!e.startsWith("-"))}function $e(r){return q(r)[0]??null}function P(r,e){const i=r.replace(/^@/,"").replace(/^epic-/i,"").replace(/\.md$/i,""),c=[i,i.toUpperCase(),/^p\d+$/i.test(i)?`P${i.replace(/^p/i,"")}`:null,/^\d+$/.test(i)?`P${i}`:null].filter(n=>typeof n=="string"&&n.length>0);for(const n of c)if(e.epics[n])return n;return null}function pe(r,e){const t=r.match(/(?:^|[/@\s])epic-(P?\d+)\.md\b/i);return t?.[1]?P(t[1],e):null}function R(r,e){const t=r.trim().match(/^@epic-(P[0-9]{1,12})$/);if(t)return P(t[1],e);const i=pe(r,e);if(i)return i;for(const c of q(r)){if(/^[A-Z]?\d+(?:\.\d+)+$/i.test(c))continue;const n=P(c,e);if(n)return n}return null}function fe(r,e){const t=R(r,e);if(t)return t;const i=e.yoloop,c=i?.state?.currentSession?.currentEpicId;if(typeof c=="string"&&e.epics[c])return c;const n=i?.lock?.currentEpicId??i?.lock?.epicId;return typeof n=="string"&&e.epics[n]?n:null}function ye(r){const e=r.match(/(?:^|[/@\s])epic-(P?\d+)\.md\b/i)?.[1];if(e)return/^P/i.test(e)?e.toUpperCase():`P${e}`;for(const t of q(r)){if(/^P\d+$/i.test(t))return t.toUpperCase();if(/^\d+$/.test(t))return`P${t}`}return null}function j(r,e){if(typeof r.epic_id=="string"&&r.epic_id.length>0)return r.epic_id;const t=e.split(".").slice(0,-1).join(".");return t.length>0?t:null}function L(r){return typeof r=="string"&&["done","completed","merged","cancelled","canceled","abandoned"].includes(r.toLowerCase())}function x(r,e,t){if(t.has(r))return;const i=e.stories[r];if(!i)return;t.add(r);const c=i.depends_on;if(Array.isArray(c))for(const n of c)typeof n=="string"&&x(n,e,t)}function me(r,e){const t=C(e.stories,[r]),i={};for(const c of t.orderedIds){const n=e.stories[c];n&&(i[c]=n)}return i}function $(r,e,t=[]){const i={};for(const c of t)e.epics[c]&&(i[c]=e.epics[c]);for(const[c,n]of Object.entries(r)){const s=j(n,c);s&&e.epics[s]&&(i[s]=e.epics[s])}return i}function ge(r,e,t){if(t.has(r))return;const i=e.epics[r];if(!i)return;t.add(r);const c=i.depends_on;if(Array.isArray(c))for(const n of c)typeof n=="string"&&n.length>0&&ge(n,e,t)}function V(r,e,t){const i=C(t.epics,[r]),c=new Set(i.orderedIds);for(const[s,a]of Object.entries(e)){const u=j(a,s);u&&t.epics[u]&&c.add(u)}const n={};for(const s of[...c].sort((a,u)=>a.localeCompare(u,"en"))){const a=t.epics[s];a&&(n[s]=s===r?a:H(s,a))}return n}function G(r,e,t){const i=e.stories;if(!Array.isArray(i)||i.some(s=>typeof s!="string"||s.length===0))throw new y("STRUCTURAL_DEPENDENCY_MISSING",{nodes:0,edges:0,malformedStoryMemberships:1});const c=C(t.stories,i),n={};for(const s of c.orderedIds){const a=t.stories[s];a&&(n[s]=j(a,s)===r?oe(s,a):Y(s,a))}return n}function he(r,e,t){const i=[...e.stories].sort((s,a)=>s.localeCompare(a,"en")),c=Object.entries(t).filter(([s,a])=>j(a,s)===r).map(([s])=>s).sort((s,a)=>s.localeCompare(a,"en")),n=W("sha256").update(`target-epic-coverage-v1\0${JSON.stringify({targetEpicId:r,declaredStoryIds:i,includedStoryIds:c})}`).digest("hex");return{schemaVersion:"TargetEpicCoverage/1.0",targetEpicId:r,declaredStoryIds:i,includedStoryIds:c,membershipSha256:n,publicSafe:!0}}function Y(r,e){const t=Array.isArray(e.depends_on)?[...new Set(e.depends_on.filter(m=>typeof m=="string"&&m.length>0))].sort((m,E)=>m.localeCompare(E,"en")):void 0,i={id:d(e.id)??r,...d(e.epic_id)?{epic_id:d(e.epic_id)}:{},...d(e.status,40)?{status:d(e.status,40)}:{},...t?{depends_on:t}:{},...h(e.supersededBy)?{supersededBy:e.supersededBy}:{}},c=M(r,e);if(!ie(e.status))return{...i,...c?{scheduling_checkpoint_evidence:c}:{}};const n=e.source==="create-epic"||e.source==="discovered"?e.source:void 0,s=T(e.branch_name),a=w(e.last_step,120),u=Array.isArray(e.steps_completed)&&e.steps_completed.length<=64?e.steps_completed.map(m=>w(m,120)):[],l=u.length>0&&u.every(m=>m!==void 0)?u:void 0,f=typeof e.pr_number=="number"&&Number.isSafeInteger(e.pr_number)&&e.pr_number>0?e.pr_number:void 0,p=ce(r,e),g=p?ne(r,e):void 0;return{...i,...n?{source:n}:{},...s?{branch_name:s}:{},...a?{last_step:a}:{},...l?{steps_completed:l}:{},...f?{pr_number:f}:{},...p?{checkpoint:p}:{},...g?{checkpoint_verification:g}:{},...c?{scheduling_checkpoint_evidence:c}:{},...S(e.files_to_modify)!==void 0?{files_to_modify:S(e.files_to_modify)}:{},...typeof e.artifact_sha256=="string"&&/^[a-f0-9]{64}$/.test(e.artifact_sha256)?{artifact_sha256:e.artifact_sha256}:{},...S(e.contracts)!==void 0?{contracts:S(e.contracts)}:{},...S(e.contract_refs)!==void 0?{contract_refs:S(e.contract_refs)}:{},...S(e.shared_surfaces)!==void 0?{shared_surfaces:S(e.shared_surfaces)}:{}}}function H(r,e){const t=Array.isArray(e.stories)?[...new Set(e.stories.filter(c=>typeof c=="string"&&c.length>0))].sort((c,n)=>c.localeCompare(n,"en")):[],i=Array.isArray(e.depends_on)?[...new Set(e.depends_on.filter(c=>typeof c=="string"&&c.length>0))].sort((c,n)=>c.localeCompare(n,"en")):[];return{id:d(e.id)??r,...d(e.status,40)?{status:d(e.status,40)}:{},...d(e.lifecycle_classification,40)?{lifecycle_classification:d(e.lifecycle_classification,40)}:{},stories:t,depends_on:i}}function be(r,e,t){const i=C(e.stories),c=C(e.epics),n=Object.fromEntries(i.orderedIds.map(u=>[u,Y(u,e.stories[u])])),s=Object.fromEntries(c.orderedIds.map(u=>[u,H(u,e.epics[u])])),a={kind:"projected",commandId:t.commandId,stateProjectionPolicy:t.stateProjectionPolicy,projectionMode:"yoloop-discovery",trigger:r,targetEpicId:null,targetStoryId:null,includedStoryCount:i.orderedIds.length,includedEpicCount:c.orderedIds.length,omittedStoryCount:0,omittedEpicCount:0,reason:"targeted-invocation",reasonCodes:_(["structural-required","yoloop-discovery",`structural-edges-${i.edgeCount+c.edgeCount}`,"content-fields-omitted"])};return I({...e,stories:n,epics:s,scope:a},e,a)}function _e(r,e){const t=new Set,i=r.stories;if(Array.isArray(i))for(const n of i)typeof n=="string"&&x(n,e,t);const c={};for(const n of t){const s=e.stories[n];s&&(c[n]=s)}return c}function Se(r){const e={};for(const[t,i]of Object.entries(r.epics))e[t]={id:d(i.id)??t,...d(i.status)?{status:d(i.status)}:{},...k.includes(i.lifecycle_classification)?{lifecycle_classification:i.lifecycle_classification}:{},...typeof i.total_stories=="number"&&Number.isFinite(i.total_stories)?{total_stories:i.total_stories}:{},...typeof i.completed_stories=="number"&&Number.isFinite(i.completed_stories)?{completed_stories:i.completed_stories}:{}};return e}function K(r){const e={};for(const t of Object.values(r)){const i=d(t.status,40)??"unknown";e[i]=(e[i]??0)+1}return e}function je(r){const e=Object.fromEntries(k.map(t=>[t,0]));for(const t of Object.values(r)){const i=k.includes(t.lifecycle_classification)?t.lifecycle_classification:"active";e[i]=(e[i]??0)+1}return e}function N(r,e){if(!e)return!0;const t=r.epics[e];return t?!k.includes(t.lifecycle_classification)||t.lifecycle_classification==="active":!0}function Z(r){for(const e of["last_updated","updated_at","completed_at","created_at","discovered_at"]){const t=r[e];if(typeof t!="string")continue;const i=Date.parse(t);if(Number.isFinite(i))return i}return 0}function Ie(r){return Object.entries(r.stories).map(([e,t])=>({id:e,story:t,timestamp:Z(t)})).sort((e,t)=>t.timestamp-e.timestamp||e.id.localeCompare(t.id)).slice(0,U).map(({id:e,story:t})=>({id:e,...d(t.epic_id)?{epicId:d(t.epic_id)}:{},...d(t.status,40)?{status:d(t.status,40)}:{},...d(t.last_step??t.lastStep)?{lastStep:d(t.last_step??t.lastStep)}:{},...d(t.last_updated??t.updated_at??t.completed_at??t.created_at)?{lastUpdated:d(t.last_updated??t.updated_at??t.completed_at??t.created_at)}:{}}))}function Ce(r){const e=r.current_session;if(!e)return;const t={activeEpicId:d(e.active_epic_id)??null,activeStoryId:d(e.active_story_id)??null,activeStepId:d(e.active_step_id)??null,sessionId:d(e.session_id)??null,startedAt:d(e.started_at)??null};return Object.values(t).some(i=>i!=null)?t:void 0}function ke(r){const e=r.yoloop;if(!h(e))return;const t=h(e.state)?e.state:void 0,i=h(t?.currentSession)?t.currentSession:void 0,c=h(e.lock)?e.lock:void 0,n={...typeof e.active=="boolean"?{active:e.active}:{},currentEpicId:d(i?.currentEpicId??e.currentEpicId)??null,currentStoryId:d(i?.currentStoryId??e.currentStoryId)??null,sessionId:d(i?.sessionId??e.sessionId)??null,lockEpicId:d(c?.currentEpicId??c?.epicId)??null};return Object.keys(n).length>0?n:void 0}function ve(r){const e=r.continuity;if(!h(e))return;const t=Array.isArray(e.reasonCodes)?e.reasonCodes.filter(i=>typeof i=="string"):void 0;return{present:!0,activeJobId:d(e.activeJobId??e.jobId)??null,activeGoalId:d(e.activeGoalId??e.goalId)??null,activeLoopId:d(e.activeLoopId??e.loopId)??null,...t&&t.length>0?{reasonCodes:_(t)}:{}}}function Ee(r,e,t){const i=d(e?.activeStoryId),c=d(e?.activeEpicId),n=d(e?.activeStepId),s=i&&r.stories[i]?j(r.stories[i],i):null;if((i||c||n)&&N(r,c??s))return{epicId:c??null,storyId:i??null,stepId:n??null};const a=d(t?.currentStoryId),u=d(t?.currentEpicId??t?.lockEpicId);if((a||u)&&N(r,u))return{epicId:u??null,storyId:a??null,stepId:null};const l=Object.entries(r.stories).map(([f,p])=>({id:f,story:p,timestamp:Z(p)})).filter(({id:f,story:p})=>!L(p.status)&&N(r,j(p,f))).sort((f,p)=>p.timestamp-f.timestamp||f.id.localeCompare(p.id))[0];return l?{epicId:j(l.story,l.id),storyId:l.id,stepId:d(l.story.last_step??l.story.lastStep)??null}:{epicId:null,storyId:null,stepId:null}}function Re(r,e){const t=K(r.stories),i=K(r.epics),c=je(r.epics),n=Object.values(r.epics).filter(g=>(k.includes(g.lifecycle_classification)?g.lifecycle_classification:"active")==="active"&&!L(g.status)).length,s=Ce(r),a=ke(r),u=ve(r),l=Ee(r,s,a),f=Ie(r),p=_(e.reasonCodes,["state-summary-attached","state-summary-bounded",`projection-${e.projectionMode??e.kind}`,e.stateProjectionPolicy?`policy-${e.stateProjectionPolicy}`:"policy-unknown",f.length>=U?"recent-stories-capped":"recent-stories-bounded",l.storyId||l.epicId?"active-ref-derived":"active-ref-empty",a?"yoloop-session-present":"yoloop-session-absent",u?"continuity-session-present":"continuity-session-absent"]);return{schemaVersion:1,totals:{stories:Object.keys(r.stories).length,epics:Object.keys(r.epics).length,storyStatus:t,epicStatus:i,epicLifecycle:c,activeEpics:n,blockedStories:t.blocked??0},active:l,blockedCount:t.blocked??0,recentStories:f,...s?{currentSession:s}:{},...a?{currentYoloopSession:a}:{},...u?{currentContinuitySession:u}:{},projection:{commandId:e.commandId??null,stateProjectionPolicy:e.stateProjectionPolicy??null,projectionMode:e.projectionMode,scopeKind:e.kind,includedStoryCount:e.includedStoryCount,includedEpicCount:e.includedEpicCount??Object.keys(r.epics).length,omittedStoryCount:e.omittedStoryCount,omittedEpicCount:e.omittedEpicCount,reason:e.reason},reasonCodes:p,publicSafe:!0}}function I(r,e,t){return{...r,stateSummary:Re(e,t)}}function Oe(r,e,t){const i={};for(const n of Object.keys(e.epics))i[n]={id:n};const c={kind:"projected",commandId:t.commandId,stateProjectionPolicy:t.stateProjectionPolicy,projectionMode:"summary-only",trigger:r,targetEpicId:null,targetStoryId:null,includedStoryCount:0,includedEpicCount:Object.keys(i).length,omittedStoryCount:Object.keys(e.stories).length,omittedEpicCount:0,reason:"epic-summary",reasonCodes:["epic-summary","stories-omitted","epic-stubs-only"]};return I({...e,stories:{},epics:i,scope:c},e,c)}function b(r,e,t,i=["summary-only","stories-omitted"],c="summary-only"){const n=Se(e),s={kind:"projected",commandId:t.commandId,stateProjectionPolicy:t.stateProjectionPolicy,projectionMode:c,trigger:r,targetEpicId:null,targetStoryId:null,includedStoryCount:0,includedEpicCount:Object.keys(n).length,omittedStoryCount:Object.keys(e.stories).length,omittedEpicCount:Math.max(0,Object.keys(e.epics).length-Object.keys(n).length),reason:"summary-only",reasonCodes:_(i)};return I({...e,stories:{},epics:n,scope:s},e,s)}function D(r,e,t,i,c,n){const s=e.stories[i];if(!s)throw new y("STRUCTURAL_TARGET_NOT_FOUND",{stories:Object.keys(e.stories).length,epics:Object.keys(e.epics).length,targetKind:"story"});const a=j(s,i);if(!a)throw new y("STRUCTURAL_TARGET_NOT_FOUND",{stories:Object.keys(e.stories).length,epics:Object.keys(e.epics).length,targetKind:"epic"});const u=e.epics[a];if(!u)throw new y("STRUCTURAL_TARGET_NOT_FOUND",{stories:Object.keys(e.stories).length,epics:Object.keys(e.epics).length,targetKind:"epic"});const l=c==="yolo-story",f=l?G(a,u,e):me(i,e),p=l?V(a,f,e):$(f,e);if(!f[i]||!p[a])throw new y("STRUCTURAL_TARGET_NOT_FOUND",{stories:Object.keys(f).length,epics:Object.keys(p).length,targetKind:"story"});const g={kind:"projected",commandId:t.commandId,stateProjectionPolicy:t.stateProjectionPolicy,projectionMode:c,trigger:r,targetEpicId:a,targetStoryId:i,includedStoryCount:Object.keys(f).length,includedEpicCount:Object.keys(p).length,omittedStoryCount:Math.max(0,Object.keys(e.stories).length-Object.keys(f).length),omittedEpicCount:Math.max(0,Object.keys(e.epics).length-Object.keys(p).length),reason:"targeted-invocation",reasonCodes:_(n,l?["epic-graph-authority-complete"]:[])};return I({...e,stories:f,epics:p,scope:g},e,g)}function B(r,e,t,i,c,n){const s=e.epics[i];if(!s)throw new y("STRUCTURAL_TARGET_NOT_FOUND",{stories:Object.keys(e.stories).length,epics:Object.keys(e.epics).length,targetKind:"epic"});const a=_e(s,e),u=$(a,e,[i]);if(!u[i])throw new y("STRUCTURAL_TARGET_NOT_FOUND",{stories:Object.keys(a).length,epics:Object.keys(u).length,targetKind:"epic"});const l={kind:"projected",commandId:t.commandId,stateProjectionPolicy:t.stateProjectionPolicy,projectionMode:c,trigger:r,targetEpicId:i,targetStoryId:null,includedStoryCount:Object.keys(a).length,includedEpicCount:Object.keys(u).length,omittedStoryCount:Math.max(0,Object.keys(e.stories).length-Object.keys(a).length),omittedEpicCount:Math.max(0,Object.keys(e.epics).length-Object.keys(u).length),reason:"targeted-invocation",reasonCodes:_(n)};return I({...e,stories:a,epics:u,scope:l},e,l)}function Ae(r,e,t){const i=ye(r),c=R(r,e);if(i&&!c)throw new y("STRUCTURAL_TARGET_NOT_FOUND",{stories:Object.keys(e.stories).length,epics:Object.keys(e.epics).length,targetKind:"epic"});const n=fe(r,e),s=O({commandId:t.commandId,explicitYoloopEpicId:c,sessionYoloopEpicId:c?null:n});if(s==="yoloop-discovery")return be(r,e,t);if(!n||s!=="yoloop-target"&&s!=="yoloop-session")throw new y("STRUCTURAL_TARGET_NOT_FOUND",{stories:Object.keys(e.stories).length,epics:Object.keys(e.epics).length,targetKind:"epic"});const a=e.epics[n];if(!a)throw new y("STRUCTURAL_TARGET_NOT_FOUND",{stories:Object.keys(e.stories).length,epics:Object.keys(e.epics).length,targetKind:"epic"});const u=G(n,a,e),l=V(n,u,e);if(!l[n])throw new y("STRUCTURAL_TARGET_NOT_FOUND",{stories:Object.keys(u).length,epics:Object.keys(l).length,targetKind:"epic"});const f=s,p={kind:"projected",commandId:t.commandId,stateProjectionPolicy:t.stateProjectionPolicy,projectionMode:f,trigger:r,targetEpicId:n,targetStoryId:null,targetEpicCoverage:he(n,a,u),includedStoryCount:Object.keys(u).length,includedEpicCount:Object.keys(l).length,omittedStoryCount:Math.max(0,Object.keys(e.stories).length-Object.keys(u).length),omittedEpicCount:Math.max(0,Object.keys(e.epics).length-Object.keys(l).length),reason:"targeted-invocation",reasonCodes:["structural-required",f,"yoloop-targeted"]};return I({...e,stories:u,epics:l,scope:p},e,p)}function we(r,e){const t={};for(const[i,c]of Object.entries(r.epics)){const n=Array.isArray(c.stories)?c.stories.filter(s=>typeof s=="string"&&e.has(s)):[];t[i]={id:d(c.id)??i,...d(c.status,40)?{status:d(c.status,40)}:{},...typeof c.total_stories=="number"&&Number.isFinite(c.total_stories)?{total_stories:c.total_stories}:{},...typeof c.completed_stories=="number"&&Number.isFinite(c.completed_stories)?{completed_stories:c.completed_stories}:{},...n.length>0?{stories:n}:{},...n.length>0&&Array.isArray(c.depends_on)?{depends_on:c.depends_on.filter(s=>typeof s=="string"&&s.length>0)}:{},...n.length>0&&(c.branch_mode==="epic"||c.branch_mode==="story")?{branch_mode:c.branch_mode}:{},...n.length>0&&typeof c.execution_branch=="string"?{execution_branch:c.execution_branch}:{},...n.length>0&&typeof c.origin_branch=="string"?{origin_branch:c.origin_branch}:{},...n.length>0&&(c.branch_lease===null||typeof c.branch_lease=="object")?{branch_lease:c.branch_lease}:{},...n.length>0&&(c.origin_binding===null||typeof c.origin_binding=="object")?{origin_binding:c.origin_binding}:{},...n.length>0&&(c.aggregate_qa_receipt===null||typeof c.aggregate_qa_receipt=="object")?{aggregate_qa_receipt:c.aggregate_qa_receipt}:{},...n.length>0&&(c.head_reconciliation_receipt===null||typeof c.head_reconciliation_receipt=="object")?{head_reconciliation_receipt:c.head_reconciliation_receipt}:{},...n.length>0&&c.story_worktree_evidence!==null&&typeof c.story_worktree_evidence=="object"?{story_worktree_evidence:c.story_worktree_evidence}:{},...n.length>0&&Array.isArray(c.story_worktree_leases)&&c.story_worktree_leases.length>0?{story_worktree_leases:c.story_worktree_leases}:{},...n.length>0&&c.branch_mode_conversion_receipt!==null&&typeof c.branch_mode_conversion_receipt=="object"&&!Array.isArray(c.branch_mode_conversion_receipt)?{branch_mode_conversion_receipt:c.branch_mode_conversion_receipt}:{}}}return t}function Te(r){return r.stateSummary?.totals.stories??(r.scope?.includedStoryCount??Object.keys(r.stories).length)+(r.scope?.omittedStoryCount??0)}function qe(r){return r.stateSummary?.totals.epics??(r.scope?.includedEpicCount??Object.keys(r.epics).length)+(r.scope?.omittedEpicCount??0)}function Pe(r,e){if(r.stateSummary)return{...r.stateSummary,projection:{...r.stateSummary.projection,scopeKind:"projected",projectionMode:e.projectionMode,includedStoryCount:e.includedStoryCount,includedEpicCount:e.includedEpicCount??r.stateSummary.projection.includedEpicCount,omittedStoryCount:e.omittedStoryCount,omittedEpicCount:e.omittedEpicCount,reason:"body-size"},reasonCodes:_(r.stateSummary.reasonCodes,["payload-size-guardrail","state-summary-preserved","nonessential-state-degraded"])}}function Ve(r){const e=r.scope,t=new Set,i=e?.projectionMode==="structural-required"||e?.projectionMode==="yolo-story"||e?.projectionMode==="yoloop-target"||e?.projectionMode==="yoloop-session"||e?.projectionMode==="yoloop-discovery";if(i)for(const m of Object.keys(r.stories))t.add(m);else e?.targetStoryId&&x(e.targetStoryId,r,t);const c={};for(const m of t){const E=r.stories[m];E&&(c[m]=E)}const n=we(r,t),s=Object.keys(c).length,a=Object.keys(n).length,u=Math.max(0,Te(r)-s),l=Math.max(0,qe(r)-a),f=i?e?.projectionMode??"structural-required":e?.projectionMode==="yolo-story"?"yolo-story":"summary-only",p={kind:"projected",commandId:e?.commandId??null,stateProjectionPolicy:e?.stateProjectionPolicy??null,projectionMode:f,targetEpicId:e?.targetEpicId??null,targetStoryId:e?.targetStoryId??null,...e?.targetEpicCoverage?{targetEpicCoverage:e.targetEpicCoverage}:{},includedStoryCount:s,includedEpicCount:a,omittedStoryCount:u,omittedEpicCount:l,reason:"body-size",reasonCodes:_(e?.reasonCodes,["payload-size-guardrail",t.size>0?"structural-targets-preserved":"stories-omitted","epics-stubbed","state-summary-preserved","redundant-trigger-omitted"])},g=Pe(r,p);return{...r,stories:c,epics:n,scope:p,...g?{stateSummary:g}:{}}}function xe(r,e){const t=r.trim(),i=z(t);try{if(!i){if(ue(t)){const n=o("story-reference","story-targeted"),s=F(t);if(s)return D(t,e,n,s,"targeted-story",["story-reference-targeted"])}return b(t,e,o("unknown","adaptive-targeted"),["unknown-command-summary-only"])}if(i.stateProjectionPolicy==="epic-summary")return Oe(t,e,i);if(i.stateProjectionPolicy==="yoloop-targeted")return Ae(t,e,i);const c=F(t);if(i.stateProjectionPolicy==="story-targeted"){if(c){const s=O({commandId:i.commandId,targetStoryId:c})==="yolo-story";return D(t,e,i,c,s?"yolo-story":i.structuralRequired?"structural-required":"targeted-story",[s?"yolo-story":i.structuralRequired?"structural-required":"targeted-story"])}if(i.commandId==="yolo"||i.commandId==="yolo-inline"){const n=O({commandId:i.commandId});return b(t,e,i,["yolo-inline","stories-omitted","historical-content-omitted"],n??"yolo-inline")}return i.commandId==="commit"&&/^\*?(?:commit|commit-push)$/i.test(t)?b(t,e,i,["working-tree-commit","stories-omitted","historical-content-omitted"]):i.structuralRequired?(()=>{throw new y("STRUCTURAL_TARGET_NOT_FOUND",{stories:Object.keys(e.stories).length,epics:Object.keys(e.epics).length,targetKind:"story"})})():b(t,e,i,["story-target-missing-summary-only"])}if(i.stateProjectionPolicy==="adaptive-targeted"){if(c&&e.stories[c])return D(t,e,i,c,"targeted-story",["adaptive-story-targeted"]);const n=R(t,e);return n?B(t,e,i,n,"targeted-epic",["adaptive-epic-targeted"]):b(t,e,i,["adaptive-summary-only","target-unresolved-summary-only"])}if(i.stateProjectionPolicy==="epic-targeted"){if(i.commandId.startsWith("arch-")&&/(?:^|\s)epic-arch\s*$/i.test(t)&&e.archPlan?.execution?.currentStageCommand===i.commandId)return b(t,e,i,["architecture-root-delegated"]);const n=R(t,e);return n?B(t,e,i,n,i.structuralRequired?"structural-required":"targeted-epic",[i.structuralRequired?"structural-required":"targeted-epic"]):i.structuralRequired?(()=>{throw new y("STRUCTURAL_TARGET_NOT_FOUND",{stories:Object.keys(e.stories).length,epics:Object.keys(e.epics).length,targetKind:"epic"})})():b(t,e,i,["epic-target-missing-summary-only"])}return i.stateProjectionPolicy==="continuity-scoped"?b(t,e,i,["continuity-scoped-summary-only"]):b(t,e,i,["policy-full-summary-only"])}catch(c){if(c instanceof y)throw c;if(i?.structuralRequired)throw new y("STRUCTURAL_DEPENDENCY_MISSING",{stories:Object.keys(e.stories).length,epics:Object.keys(e.epics).length,projectionErrors:1});return b(t,e,i??o("unknown","adaptive-targeted"),["projection-error-summary-only"])}}const Ne=new Set(["yolo-story","yolo-inline","yoloop-target","yoloop-session","yoloop-discovery"]);function De(r){let e=0;for(const t of[r.stories,r.epics])for(const i of Object.values(t))Array.isArray(i.depends_on)&&(e+=i.depends_on.filter(c=>typeof c=="string").length);return e}function Ge(r,e){const t=z(r.trim());if(!t||!["yolo","yolo-inline","yoloop"].includes(t.commandId))return null;try{const i=xe(r,e),c=i.scope?.projectionMode;if(!c||!Ne.has(c))throw new y("STRUCTURAL_DEPENDENCY_MISSING",{stories:Object.keys(i.stories).length,epics:Object.keys(i.epics).length,projectionShapeErrors:1});return Object.freeze({ok:!0,version:2,shape:c,snapshot:i,included:{epics:i.scope?.includedEpicCount??Object.keys(i.epics).length,stories:i.scope?.includedStoryCount??Object.keys(i.stories).length,edges:De(i)},omitted:{epics:i.scope?.omittedEpicCount??0,stories:i.scope?.omittedStoryCount??0},cycleCount:0})}catch(i){if(!(i instanceof y))throw i;return Object.freeze({ok:!1,code:i.code,publicDetails:{...i.publicDetails,...i.code==="STRUCTURAL_CONTEXT_TOO_LARGE"?{}:{planningCause:Q(i.code)}}})}}export{Ve as degradeStateSnapshotForPayloadLimit,Q as planningProjectionCauseForStructuralCode,Fe as projectEpicOperationalEvidenceForRequest,xe as projectStateSnapshotForInvoke,Ge as projectStateSnapshotResultV2ForInvoke};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{existsSync as h}from"node:fs";import{resolve as p}from"node:path";import{formatFrontmatterDiagnostic as A}from"../errors/frontmatter-diagnostics.js";const O=/^\*?(yoloop|auto-yolo|epic-runner|story-runner|loop-yolo|auto-epic)\b/i,T=/^@neocortex\
|
|
1
|
+
import{existsSync as h}from"node:fs";import{resolve as p}from"node:path";import{formatFrontmatterDiagnostic as A}from"../errors/frontmatter-diagnostics.js";const O=/^\*?(yoloop|auto-yolo|epic-runner|story-runner|loop-yolo|auto-epic)\b/i,T=/^@neocortex(?:-root)?(?![-\w])\s*/i,_=/\[[^\]\r\n]*\]\(([^)\r\n]+)\)/g,E=/^[A-Za-z0-9._-]+(?:\/[A-Za-z0-9._-]+)*\/?$/,R=/^epic-[A-Za-z0-9._-]+\.md$/i;function g(t){if(typeof t!="string")return null;let e=t.trimStart(),n=!1;const r=e.match(T);r&&(e=e.slice(r[0].length).trimStart(),n=!0);const o=e.match(O);return o?Object.freeze({triggerToken:o[0],remainder:e.slice(o[0].length).trim(),agentSelectorRemoved:n}):null}function v(t){return g(t)!==null}function u(t){return Object.freeze({ok:!1,errorCode:"INVALID_YOLOOP_TARGET",reasonCode:t,message:`INVALID_YOLOOP_TARGET: ${A(t)}`})}function k(t){let e=t.trim().replace(/^@/,"").replace(/^\.\//,"");if(/^[A-Za-z][A-Za-z0-9+.-]*:/.test(e)||e.startsWith("//"))return{ok:!1,failure:"external"};if(e.startsWith("/")||e.startsWith("~")||/^[A-Za-z]:[\\/]/.test(e)||e.includes("\\")||e.includes("\0"))return{ok:!1,failure:"unsafe-path"};const n=e.split("/").filter(Boolean);return!e||!E.test(e)||n.some(r=>r==="."||r==="..")?{ok:!1,failure:"unsafe-path"}:!e.endsWith("/")&&!e.toLowerCase().endsWith(".md")?{ok:!1,failure:"malformed"}:(e=e.replace(/^\.\//,""),{ok:!0,target:e})}function $(t){return`markdown-link-target-${t}`}function w(t){return`raw-target-${t}`}function b(t,e){return t.startsWith("@")||e.includes("/")||e.includes("\\")||e.startsWith(".")||e.startsWith("~")||e.toLowerCase().endsWith(".md")||/^[A-Za-z][A-Za-z0-9+.-]*:/.test(e)}function z(t,e){if(!e||!R.test(t)||h(p(e,t)))return t;const n=`docs/epics/${t}`;return h(p(e,n))?n:t}function f(t){return Object.freeze([...t])}function W(t,e={}){const n=g(t);if(!n)return Object.freeze({ok:!0,args:typeof t=="string"?t:"",changed:!1,reasonCodes:f(["yoloop-target-unchanged"])});const r=[];n.agentSelectorRemoved&&r.push("agent-selector-removed");const o=n.remainder;if(!o){const a=n.triggerToken;return Object.freeze({ok:!0,args:a,changed:a!==t,reasonCodes:f(r.length>0?r:["yoloop-target-unchanged"])})}const i=[...o.matchAll(_)],d=o.startsWith("[")||o.includes("](");if(i.length>1)return u("markdown-link-target-ambiguous");if(d&&i.length===0)return u("markdown-link-target-malformed");if(i.length===1){const a=i[0];if(a[0]!==o)return u("markdown-link-target-ambiguous");const s=k(a[1]);if(!s.ok)return u($(s.failure));const l=z(s.target,e.projectRoot);return r.push("markdown-link-target-normalized"),l!==s.target&&r.push("basename-target-canonicalized"),Object.freeze({ok:!0,args:`${n.triggerToken} @${l}`,changed:!0,reasonCodes:f(r)})}const c=o.match(/^@?([^\s]+)$/)?.[1];if(c){let a=c;if(b(o,c)){const l=k(c);if(!l.ok)return u(w(l.failure));a=l.target}const s=z(a,e.projectRoot);if(s!==c)return r.push("basename-target-canonicalized"),Object.freeze({ok:!0,args:`${n.triggerToken} @${s}`,changed:!0,reasonCodes:f(r)})}const m=`${n.triggerToken}${o?` ${o}`:""}`;return Object.freeze({ok:!0,args:m,changed:m!==t,reasonCodes:f(r.length>0?r:["yoloop-target-unchanged"])})}function P(t,e){const n=W(t,{projectRoot:e});if(!n.ok)return null;const r=g(n.args);if(!r?.remainder)return null;const o=r.remainder.match(/(?:^|\s)@([^\s]+)/);if(o)return o[1];const i=r.remainder.split(/\s+/).find(d=>d.length>0&&!d.startsWith("-"));return i?i.replace(/^(?:"|')|(?:"|')$/g,""):null}export{P as extractYoloopTargetPath,v as isYoloopInvocation,W as normalizeYoloopTargetArgs,g as parseYoloopInvocation};
|
|
@@ -23,7 +23,75 @@ export const COMPATIBILITY_CAPABILITIES = Object.freeze({
|
|
|
23
23
|
* its pre-P227.23 `continuous_dag` plan.
|
|
24
24
|
*/
|
|
25
25
|
YOLOOP_V4_RUNNER_DISPATCH: 'yoloop-v4-runner-dispatch-v1',
|
|
26
|
+
/**
|
|
27
|
+
* P228.14 (P228-CON-CHILD-CAPABILITY): the client accepts the delegated
|
|
28
|
+
* child `neocortex-sentinel` in task directives. Without it the server keeps
|
|
29
|
+
* the legacy `subagentType: 'neocortex'`.
|
|
30
|
+
*/
|
|
31
|
+
AGENT_SENTINEL_CHILD: 'agent-sentinel-child-v1',
|
|
32
|
+
/**
|
|
33
|
+
* P228.14 (P228-CON-SPEC-BARRIER-SCOPE): the client understands v4 plans
|
|
34
|
+
* whose C04 barrier uses `specBarrier.scope: 'frontier'`. Without it the
|
|
35
|
+
* server keeps the legacy `epic` scope.
|
|
36
|
+
*/
|
|
37
|
+
YOLOOP_V4_FRONTIER_BARRIER: 'yoloop-v4-frontier-barrier-v1',
|
|
38
|
+
/**
|
|
39
|
+
* P228.18 (ADR-P228-01): the client sends the private-execution envelope
|
|
40
|
+
* with a `hostKind` from {@link PRIVATE_EXECUTION_HOST_KINDS}. Without it the
|
|
41
|
+
* server admits only the legacy Codex envelope.
|
|
42
|
+
*/
|
|
43
|
+
PRIVATE_EXECUTION_HOST_NEUTRAL: 'private-execution-host-neutral-v1',
|
|
44
|
+
/**
|
|
45
|
+
* P228.23 (G5): the client can drive the root refactor/QA control from any
|
|
46
|
+
* harness. Replaces the former `platformTarget === 'codex'` host test.
|
|
47
|
+
*/
|
|
48
|
+
ROOT_REFACTOR_QA_CONTROL: 'root-refactor-qa-control-v1',
|
|
49
|
+
/**
|
|
50
|
+
* P228.26 (P228-CON-GOVERNANCE-RUNTIME-STORE): the client keeps story
|
|
51
|
+
* governance of untracked `.neocortex/` projects in the Git common-dir
|
|
52
|
+
* runtime store and checkpoints code only. Without it the server keeps the
|
|
53
|
+
* `story-worktree-state-untracked` fallback for such projects.
|
|
54
|
+
*/
|
|
55
|
+
STORY_GOVERNANCE_RUNTIME_STORE: 'story-governance-runtime-store-v1',
|
|
56
|
+
});
|
|
57
|
+
/**
|
|
58
|
+
* P228.18: closed host enum for the private-execution envelope, one value per
|
|
59
|
+
* supported harness. Codex keeps its legacy literal `codex-cli`; `runner` and
|
|
60
|
+
* `unknown` are never private-execution hosts. The `satisfies` clause makes a
|
|
61
|
+
* new canonical platform a compile error until its host is decided.
|
|
62
|
+
*/
|
|
63
|
+
const PRIVATE_EXECUTION_HOST_BY_PLATFORM = Object.freeze({
|
|
64
|
+
'claude-code': 'claude-code',
|
|
65
|
+
opencode: 'opencode',
|
|
66
|
+
codex: 'codex-cli',
|
|
67
|
+
gemini: 'gemini',
|
|
68
|
+
vscode: 'vscode',
|
|
69
|
+
'github-copilot-cli': 'github-copilot-cli',
|
|
70
|
+
kimi: 'kimi',
|
|
71
|
+
cursor: 'cursor',
|
|
72
|
+
antigravity: 'antigravity',
|
|
73
|
+
openclaw: 'openclaw',
|
|
74
|
+
grok: 'grok',
|
|
75
|
+
deepseek: 'deepseek',
|
|
26
76
|
});
|
|
77
|
+
export const PRIVATE_EXECUTION_HOST_KINDS = Object.freeze(Object.values(PRIVATE_EXECUTION_HOST_BY_PLATFORM));
|
|
78
|
+
export const PRIVATE_EXECUTION_CODEX_HOST_KIND = PRIVATE_EXECUTION_HOST_BY_PLATFORM.codex;
|
|
79
|
+
export function isPrivateExecutionHostKind(value) {
|
|
80
|
+
return typeof value === 'string'
|
|
81
|
+
&& PRIVATE_EXECUTION_HOST_KINDS.includes(value);
|
|
82
|
+
}
|
|
83
|
+
/** Maps a canonical platform target to its host; anything else is `undefined`. */
|
|
84
|
+
export function hostKindForPlatformTarget(platformTarget) {
|
|
85
|
+
if (typeof platformTarget !== 'string'
|
|
86
|
+
|| !Object.prototype.hasOwnProperty.call(PRIVATE_EXECUTION_HOST_BY_PLATFORM, platformTarget))
|
|
87
|
+
return undefined;
|
|
88
|
+
return PRIVATE_EXECUTION_HOST_BY_PLATFORM[platformTarget];
|
|
89
|
+
}
|
|
90
|
+
/** True only for a valid `CompatibilityOffer/1.0` that advertises the capability. */
|
|
91
|
+
export function supportsPrivateExecutionHostNeutral(offer) {
|
|
92
|
+
return isCompatibilityOfferV1(offer)
|
|
93
|
+
&& offer.capabilityIds.includes(COMPATIBILITY_CAPABILITIES.PRIVATE_EXECUTION_HOST_NEUTRAL);
|
|
94
|
+
}
|
|
27
95
|
export const COMPATIBILITY_SCHEMAS = Object.freeze({
|
|
28
96
|
INVOKE_REQUEST: 'invoke-request/1',
|
|
29
97
|
INVOKE_RESPONSE: 'invoke-response/1',
|
|
@@ -33,9 +33,113 @@ function allowedKeys(value, allowed) {
|
|
|
33
33
|
if (Object.keys(value).some((key) => !allowed.includes(key)))
|
|
34
34
|
throw new Error('planning-unknown-field');
|
|
35
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* P228.03 (CON-PB-01): one byte budget for the projected planning checkpoint.
|
|
38
|
+
* All values are UTF-8 bytes of `JSON.stringify`, never UTF-16 lengths. The
|
|
39
|
+
* intake budget is derived from the checkpoint ceiling minus worst-case
|
|
40
|
+
* reserves, so an accepted intake always fits with both receipts.
|
|
41
|
+
*/
|
|
42
|
+
export const PLANNING_CHECKPOINT_MAX_BYTES = 32_768;
|
|
43
|
+
/** Envelope plus both receipts' fixed fields with empty summaries (measured 962). */
|
|
44
|
+
export const PLANNING_CHECKPOINT_ENVELOPE_RESERVE_BYTES = 1_024;
|
|
45
|
+
/** Worst UTF-8 size of the 1,024-unit receipt summary (3 bytes per BMP unit). */
|
|
46
|
+
export const PLANNING_RECEIPT_SUMMARY_MAX_BYTES = 3_072;
|
|
47
|
+
/** Worst `degradeAuthorization` with 2 x 32 kebab-case ASCII codes of <= 128 chars. */
|
|
48
|
+
export const PLANNING_DEGRADE_AUTHORIZATION_RESERVE_BYTES = 8_704;
|
|
49
|
+
export const PLANNING_INTAKE_MAX_BYTES = PLANNING_CHECKPOINT_MAX_BYTES
|
|
50
|
+
- PLANNING_CHECKPOINT_ENVELOPE_RESERVE_BYTES
|
|
51
|
+
- 2 * PLANNING_RECEIPT_SUMMARY_MAX_BYTES
|
|
52
|
+
- PLANNING_DEGRADE_AUTHORIZATION_RESERVE_BYTES;
|
|
53
|
+
/** Compatibility floor: every intake accepted before P228.03 stays acceptable. */
|
|
54
|
+
const PLANNING_INTAKE_COMPAT_FLOOR_BYTES = 16_384;
|
|
55
|
+
if (PLANNING_INTAKE_MAX_BYTES < PLANNING_INTAKE_COMPAT_FLOOR_BYTES) {
|
|
56
|
+
throw new Error('planning-budget-constants-invalid');
|
|
57
|
+
}
|
|
58
|
+
/** Typed P01 refusal; carries integer counts only, never intake content. */
|
|
59
|
+
export class PlanningIntakeBudgetError extends Error {
|
|
60
|
+
byteLength;
|
|
61
|
+
targetBytes;
|
|
62
|
+
reasonCode = 'planning-intake-budget-exceeded';
|
|
63
|
+
constructor(byteLength, targetBytes) {
|
|
64
|
+
super('planning-intake-budget-exceeded');
|
|
65
|
+
this.byteLength = byteLength;
|
|
66
|
+
this.targetBytes = targetBytes;
|
|
67
|
+
this.name = 'PlanningIntakeBudgetError';
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
function collapse(value) {
|
|
71
|
+
return typeof value === 'string' ? value.trim().replace(/\s+/g, ' ') : value;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* CON-PB-02: lossless, deterministic and idempotent compaction applied by P01
|
|
75
|
+
* before the revision. `rawIntent` is never touched (P01 binds it to the idea
|
|
76
|
+
* artifact). Unknown keys and non-string values pass through unchanged so the
|
|
77
|
+
* canonical validator still rejects them with its own reason codes.
|
|
78
|
+
*/
|
|
79
|
+
export function compactPlanningIntake(value) {
|
|
80
|
+
if (!record(value))
|
|
81
|
+
throw new Error('planning-intake-shape');
|
|
82
|
+
const result = { ...value };
|
|
83
|
+
for (const key of SCALARS) {
|
|
84
|
+
if (key !== 'rawIntent' && result[key] !== undefined)
|
|
85
|
+
result[key] = collapse(result[key]);
|
|
86
|
+
}
|
|
87
|
+
for (const key of LISTS) {
|
|
88
|
+
const entries = result[key];
|
|
89
|
+
if (!Array.isArray(entries))
|
|
90
|
+
continue;
|
|
91
|
+
const seen = new Set();
|
|
92
|
+
const compacted = [];
|
|
93
|
+
for (const entry of entries) {
|
|
94
|
+
const item = collapse(entry);
|
|
95
|
+
if (typeof item === 'string') {
|
|
96
|
+
if (!item || seen.has(item))
|
|
97
|
+
continue;
|
|
98
|
+
seen.add(item);
|
|
99
|
+
}
|
|
100
|
+
compacted.push(item);
|
|
101
|
+
}
|
|
102
|
+
result[key] = compacted;
|
|
103
|
+
}
|
|
104
|
+
for (const key of ['examples', 'contracts']) {
|
|
105
|
+
const entries = result[key];
|
|
106
|
+
if (!Array.isArray(entries))
|
|
107
|
+
continue;
|
|
108
|
+
const seen = new Set();
|
|
109
|
+
const compacted = [];
|
|
110
|
+
for (const entry of entries) {
|
|
111
|
+
if (!record(entry)) {
|
|
112
|
+
compacted.push(entry);
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
const copy = {};
|
|
116
|
+
for (const [field, item] of Object.entries(entry))
|
|
117
|
+
copy[field] = collapse(item);
|
|
118
|
+
// Structural identity is independent of client key order.
|
|
119
|
+
const identity = JSON.stringify(Object.keys(copy).sort().map((field) => [field, copy[field]]));
|
|
120
|
+
if (seen.has(identity))
|
|
121
|
+
continue;
|
|
122
|
+
seen.add(identity);
|
|
123
|
+
compacted.push(copy);
|
|
124
|
+
}
|
|
125
|
+
result[key] = compacted;
|
|
126
|
+
}
|
|
127
|
+
return result;
|
|
128
|
+
}
|
|
129
|
+
/** P01 entry point: compact, enforce the derived budget, then canonicalize and revise. */
|
|
130
|
+
export function preparePlanningIntake(value) {
|
|
131
|
+
const compacted = compactPlanningIntake(value);
|
|
132
|
+
const byteLength = Buffer.byteLength(JSON.stringify(compacted));
|
|
133
|
+
if (byteLength > PLANNING_INTAKE_MAX_BYTES) {
|
|
134
|
+
throw new PlanningIntakeBudgetError(byteLength, PLANNING_INTAKE_MAX_BYTES);
|
|
135
|
+
}
|
|
136
|
+
const intake = canonicalPlanningIntake(compacted);
|
|
137
|
+
return { intake, intakeRevision: planningIntakeRevision(intake), byteLength,
|
|
138
|
+
compacted: !isDeepStrictEqual(compacted, value) };
|
|
139
|
+
}
|
|
36
140
|
/** Stable revision input shared by the server and the physical root checkpoint. */
|
|
37
141
|
export function canonicalPlanningIntake(value) {
|
|
38
|
-
if (!record(value) || Buffer.byteLength(JSON.stringify(value)) >
|
|
142
|
+
if (!record(value) || Buffer.byteLength(JSON.stringify(value)) > PLANNING_INTAKE_MAX_BYTES) {
|
|
39
143
|
throw new Error('planning-intake-shape');
|
|
40
144
|
}
|
|
41
145
|
allowedKeys(value, [...SCALARS, ...LISTS, ...BOOLEANS, 'examples', 'contracts']);
|