@ornexus/neocortex 4.65.1 → 4.66.1
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 +1206 -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/doctor.d.ts +26 -1
- package/packages/client/dist/commands/doctor.js +2 -2
- package/packages/client/dist/commands/invoke.d.ts +183 -5
- package/packages/client/dist/commands/invoke.js +94 -87
- package/packages/client/dist/commands/planning-qa.d.ts +64 -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 +3 -1
- package/packages/client/dist/commands/story-checkpoint.js +1 -1
- package/packages/client/dist/commands/story-worktree.d.ts +1 -1
- package/packages/client/dist/commands/story-worktree.js +1 -1
- package/packages/client/dist/git/direct-yolo-checkpoint.d.ts +64 -1
- package/packages/client/dist/git/direct-yolo-checkpoint.js +4 -3
- package/packages/client/dist/git/epic-lifecycle-evidence.d.ts +184 -0
- package/packages/client/dist/git/epic-lifecycle-evidence.js +6 -0
- package/packages/client/dist/git/git-lifecycle-store.d.ts +23 -0
- package/packages/client/dist/git/git-lifecycle-store.js +9 -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-cleanup.js +1 -1
- package/packages/client/dist/git/story-worktree-integration.js +3 -3
- package/packages/client/dist/git/story-worktree-manager.d.ts +39 -0
- package/packages/client/dist/git/story-worktree-manager.js +3 -3
- package/packages/client/dist/git/story-write-set-extension.d.ts +62 -0
- package/packages/client/dist/git/story-write-set-extension.js +1 -1
- 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 +21 -1
- package/packages/client/dist/private-execution/codex-executor.js +4 -4
- 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/harness-adapters/antigravity.d.ts +9 -0
- package/packages/client/dist/private-execution/harness-adapters/antigravity.js +1 -0
- package/packages/client/dist/private-execution/harness-adapters/claude-code.d.ts +8 -0
- package/packages/client/dist/private-execution/harness-adapters/claude-code.js +1 -0
- package/packages/client/dist/private-execution/harness-adapters/codex.d.ts +7 -0
- package/packages/client/dist/private-execution/harness-adapters/codex.js +1 -0
- package/packages/client/dist/private-execution/harness-adapters/copilot-cli.d.ts +8 -0
- package/packages/client/dist/private-execution/harness-adapters/copilot-cli.js +1 -0
- package/packages/client/dist/private-execution/harness-adapters/cursor.d.ts +9 -0
- package/packages/client/dist/private-execution/harness-adapters/cursor.js +1 -0
- package/packages/client/dist/private-execution/harness-adapters/deepseek.d.ts +9 -0
- package/packages/client/dist/private-execution/harness-adapters/deepseek.js +1 -0
- package/packages/client/dist/private-execution/harness-adapters/gemini.d.ts +8 -0
- package/packages/client/dist/private-execution/harness-adapters/gemini.js +1 -0
- package/packages/client/dist/private-execution/harness-adapters/grok.d.ts +9 -0
- package/packages/client/dist/private-execution/harness-adapters/grok.js +1 -0
- package/packages/client/dist/private-execution/harness-adapters/index.d.ts +73 -0
- package/packages/client/dist/private-execution/harness-adapters/index.js +1 -0
- package/packages/client/dist/private-execution/harness-adapters/kimi.d.ts +9 -0
- package/packages/client/dist/private-execution/harness-adapters/kimi.js +1 -0
- package/packages/client/dist/private-execution/harness-adapters/openclaw.d.ts +9 -0
- package/packages/client/dist/private-execution/harness-adapters/openclaw.js +1 -0
- package/packages/client/dist/private-execution/harness-adapters/opencode.d.ts +7 -0
- package/packages/client/dist/private-execution/harness-adapters/opencode.js +1 -0
- package/packages/client/dist/private-execution/harness-ephemeral-home.d.ts +19 -0
- package/packages/client/dist/private-execution/harness-ephemeral-home.js +1 -0
- package/packages/client/dist/private-execution/harness-executor.d.ts +79 -0
- package/packages/client/dist/private-execution/harness-executor.js +1 -0
- package/packages/client/dist/private-execution/harness-process.d.ts +43 -0
- package/packages/client/dist/private-execution/harness-process.js +1 -0
- package/packages/client/dist/private-execution/isolated-admission.js +12 -12
- package/packages/client/dist/private-execution/isolated-workspace.d.ts +16 -1
- package/packages/client/dist/private-execution/isolated-workspace.js +1 -1
- 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/epic-terminal-git-cli-adapter.d.ts +1 -22
- package/packages/client/dist/runner/headless/epic-terminal-git-cli-adapter.js +6 -10
- 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.d.ts +10 -0
- package/packages/client/dist/state/project-state-snapshot.js +1 -1
- package/packages/client/dist/state/structural-dag-projection.d.ts +26 -0
- package/packages/client/dist/state/structural-dag-projection.js +1 -1
- package/packages/client/dist/yoloop/target-normalization.js +1 -1
- package/packages/client/dist/yoloop/yoloop-client-state-store.d.ts +67 -0
- package/packages/client/dist/yoloop/yoloop-client-state-store.js +1 -1
- package/packages/shared/dist/compatibility/index.js +96 -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 +13 -1
- package/targets-stubs/grok/agents/neocortex-sentinel.md +64 -0
- package/targets-stubs/grok/config-mcp.toml +0 -3
- package/targets-stubs/grok/install-grok.sh +51 -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 +301 -6
- package/targets-stubs/lib/managed-profile.sh +12 -1
- package/targets-stubs/lib/mcp-merge.js +122 -8
- package/targets-stubs/openclaw/SKILL.md +33 -4
- package/targets-stubs/opencode/neocortex-root.md +41 -41
- package/targets-stubs/opencode/neocortex-sentinel.md +115 -0
- package/targets-stubs/opencode/neocortex.md +292 -67
- package/targets-stubs/opencode/opencode-mcp.json +0 -7
- package/targets-stubs/vscode/README.md +1 -1
- package/targets-stubs/vscode/mcp.json +0 -4
- package/targets-stubs/vscode/neocortex.agent.md +29 -18
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { PrivateExecutionHostKind } from '../../../../shared/dist/compatibility/index.js';
|
|
2
|
+
import { type PrivateHarnessAdapter, type PrivateHarnessExecutionReceiptV2, type PrivateHarnessPreflight, type PrivateHarnessProcessRunner } from '../harness-executor.js';
|
|
3
|
+
import type { PrivateHarnessPlatform } from '../harness-process.js';
|
|
4
|
+
export declare const PRIVATE_HARNESS_ADAPTERS: Readonly<Partial<Record<PrivateExecutionHostKind, PrivateHarnessAdapter>>>;
|
|
5
|
+
/**
|
|
6
|
+
* P229.03 (DEC-1, DEC-2): the remaining stdin-capable headless hosts. Kept
|
|
7
|
+
* apart from `PRIVATE_HARNESS_ADAPTERS` so the P229.02 group stays unchanged.
|
|
8
|
+
*/
|
|
9
|
+
export declare const PRIVATE_HARNESS_EXTENDED_ADAPTERS: Readonly<Partial<Record<PrivateExecutionHostKind, PrivateHarnessAdapter>>>;
|
|
10
|
+
/** Own-property lookup in the P229.02 group, then the P229.03 extended group. */
|
|
11
|
+
export declare function getPrivateHarnessAdapter(hostKind: unknown): PrivateHarnessAdapter | undefined;
|
|
12
|
+
/** P229.03 (DEC-1, P229-CON-REFUSAL): a host without stdin headless support. */
|
|
13
|
+
export interface PrivateHarnessRefusalDecision {
|
|
14
|
+
readonly kind: 'refusal';
|
|
15
|
+
readonly reasonCode: 'private-executor-headless-unavailable';
|
|
16
|
+
}
|
|
17
|
+
export type PrivateHarnessDecision = {
|
|
18
|
+
readonly kind: 'adapter';
|
|
19
|
+
} | PrivateHarnessRefusalDecision;
|
|
20
|
+
/**
|
|
21
|
+
* P229.03 (DEC-1): one decision per closed host enum value. A new enum value
|
|
22
|
+
* without a decision is a compile error; `adapter` iff an adapter is registered
|
|
23
|
+
* (asserted at runtime by the P229.03 contract test).
|
|
24
|
+
*/
|
|
25
|
+
export declare const PRIVATE_HARNESS_DECISIONS: Readonly<{
|
|
26
|
+
readonly 'claude-code': {
|
|
27
|
+
readonly kind: "adapter";
|
|
28
|
+
};
|
|
29
|
+
readonly opencode: {
|
|
30
|
+
readonly kind: "adapter";
|
|
31
|
+
};
|
|
32
|
+
readonly 'codex-cli': {
|
|
33
|
+
readonly kind: "adapter";
|
|
34
|
+
};
|
|
35
|
+
readonly gemini: {
|
|
36
|
+
readonly kind: "adapter";
|
|
37
|
+
};
|
|
38
|
+
readonly kimi: {
|
|
39
|
+
readonly kind: "adapter";
|
|
40
|
+
};
|
|
41
|
+
readonly 'github-copilot-cli': {
|
|
42
|
+
readonly kind: "adapter";
|
|
43
|
+
};
|
|
44
|
+
readonly openclaw: {
|
|
45
|
+
readonly kind: "adapter";
|
|
46
|
+
};
|
|
47
|
+
readonly antigravity: {
|
|
48
|
+
readonly kind: "adapter";
|
|
49
|
+
};
|
|
50
|
+
readonly vscode: PrivateHarnessRefusalDecision;
|
|
51
|
+
readonly cursor: PrivateHarnessRefusalDecision;
|
|
52
|
+
readonly grok: PrivateHarnessRefusalDecision;
|
|
53
|
+
readonly deepseek: PrivateHarnessRefusalDecision;
|
|
54
|
+
}>;
|
|
55
|
+
/** Decision for an enum value; `undefined` outside the enum (own properties only). */
|
|
56
|
+
export declare function resolvePrivateHarnessDecision(hostKind: unknown): PrivateHarnessDecision | undefined;
|
|
57
|
+
export interface PrivateHarnessExecutorPort {
|
|
58
|
+
readonly hostKind: PrivateExecutionHostKind;
|
|
59
|
+
preflight(): Promise<PrivateHarnessPreflight>;
|
|
60
|
+
run(material: string): Promise<PrivateHarnessExecutionReceiptV2>;
|
|
61
|
+
}
|
|
62
|
+
export interface PrivateHarnessExecutorPortOptions {
|
|
63
|
+
readonly cwd?: string;
|
|
64
|
+
readonly platform?: PrivateHarnessPlatform;
|
|
65
|
+
readonly timeoutMs?: number;
|
|
66
|
+
readonly maxOutputBytes?: number;
|
|
67
|
+
readonly userHome?: string;
|
|
68
|
+
readonly sourceEnv?: NodeJS.ProcessEnv;
|
|
69
|
+
readonly ephemeralBase?: string;
|
|
70
|
+
readonly processRunner?: PrivateHarnessProcessRunner;
|
|
71
|
+
readonly now?: () => number;
|
|
72
|
+
}
|
|
73
|
+
export declare function createPrivateHarnessExecutorPort(hostKind: unknown, options?: PrivateHarnessExecutorPortOptions): PrivateHarnessExecutorPort | undefined;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{homedir as E}from"node:os";import{isAbsolute as A,join as f}from"node:path";import{preflightPrivateHarness as u,runPrivateHarness as s}from"../harness-executor.js";import{PRIVATE_CLAUDE_CODE_HARNESS_ADAPTER as _}from"./claude-code.js";import{PRIVATE_CODEX_HARNESS_ADAPTER as R}from"./codex.js";import{PRIVATE_GEMINI_HARNESS_ADAPTER as a}from"./gemini.js";import{PRIVATE_OPENCODE_HARNESS_ADAPTER as m}from"./opencode.js";import{PRIVATE_ANTIGRAVITY_HARNESS_ADAPTER as S}from"./antigravity.js";import{PRIVATE_COPILOT_CLI_HARNESS_ADAPTER as p}from"./copilot-cli.js";import{PRIVATE_CURSOR_HARNESS_DECISION as d}from"./cursor.js";import{PRIVATE_DEEPSEEK_HARNESS_DECISION as l}from"./deepseek.js";import{PRIVATE_GROK_HARNESS_DECISION as P}from"./grok.js";import{PRIVATE_KIMI_HARNESS_ADAPTER as T}from"./kimi.js";import{PRIVATE_OPENCLAW_HARNESS_ADAPTER as I}from"./openclaw.js";const D=10*6e4,O=1024*1024,N=Object.freeze({"claude-code":_,opencode:m,gemini:a,"codex-cli":R}),H=Object.freeze({kimi:T,"github-copilot-cli":p,openclaw:I,antigravity:S});function v(r){if(typeof r=="string"){for(const e of[N,H])if(Object.prototype.hasOwnProperty.call(e,r))return e[r]}}const o=Object.freeze({kind:"adapter"}),g=Object.freeze({kind:"refusal",reasonCode:"private-executor-headless-unavailable"}),c=Object.freeze({"claude-code":o,opencode:o,"codex-cli":o,gemini:o,kimi:o,"github-copilot-cli":o,openclaw:o,antigravity:o,vscode:g,cursor:d,grok:P,deepseek:l});function G(r){if(!(typeof r!="string"||!Object.prototype.hasOwnProperty.call(c,r)))return c[r]}function C(r,e){if(r.credentialFiles.length===0)return;const t=r.credentialSource;if(t===void 0)return;const n=t.env===void 0?void 0:(e.sourceEnv??process.env)[t.env];if(typeof n=="string"&&n.length>0&&A(n))return n;const i=e.userHome??E();return t.homeRelative===""?i:f(i,...t.homeRelative.split("/"))}function X(r,e={}){const t=v(r);if(t===void 0)return;const n=e.cwd??process.cwd();return Object.freeze({hostKind:t.hostKind,preflight:()=>u(t,{cwd:n,platform:e.platform,now:e.now,processRunner:e.processRunner}),run:i=>s(t,i,{cwd:n,platform:e.platform,timeoutMs:e.timeoutMs??D,maxOutputBytes:e.maxOutputBytes??O,credentialSourceDirectory:C(t,e),ephemeralBase:e.ephemeralBase,processRunner:e.processRunner})})}export{N as PRIVATE_HARNESS_ADAPTERS,c as PRIVATE_HARNESS_DECISIONS,H as PRIVATE_HARNESS_EXTENDED_ADAPTERS,X as createPrivateHarnessExecutorPort,v as getPrivateHarnessAdapter,G as resolvePrivateHarnessDecision};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* P229.03 (P229-CON-EXECUTOR, DEC-2/DEC-3): Kimi CLI headless private adapter.
|
|
3
|
+
* Print mode with `--input-format text` reads the material from stdin; argv
|
|
4
|
+
* carries only fixed flags. `HOME` is the ephemeral home, where the declared
|
|
5
|
+
* `.kimi/config.toml` credential is mirrored. `--print` implies auto-approval
|
|
6
|
+
* (R-01), mitigated by the core (ephemeral home, stdin, timeout, env allowlist).
|
|
7
|
+
*/
|
|
8
|
+
import type { PrivateHarnessAdapter } from '../harness-executor.js';
|
|
9
|
+
export declare const PRIVATE_KIMI_HARNESS_ADAPTER: PrivateHarnessAdapter;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=Object.freeze({hostKind:"kimi",binary:"kimi",fixedArgs:Object.freeze(["--print","--input-format","text","--output-format","text","--final-message-only"]),stdinFlag:null,nativeFlags:Object.freeze([]),configDirEnv:null,configDirEnvs:Object.freeze({HOME:""}),credentialFiles:Object.freeze([".kimi/config.toml"]),credentialSource:Object.freeze({homeRelative:""}),environmentKeys:Object.freeze(["PATH","HOME","LANG","LC_ALL","TERM"]),versionArgs:Object.freeze(["--version"]),versionPattern:/^(?:kimi(?:,\s*version)?\s+)?v?(\d+\.\d+\.\d+)$/,minimumVersion:"0.0.1",platforms:Object.freeze(["linux","darwin","win32"])});export{e as PRIVATE_KIMI_HARNESS_ADAPTER};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* P229.03 (P229-CON-EXECUTOR, DEC-2/DEC-3): OpenClaw headless private adapter.
|
|
3
|
+
* `agent --local` runs embedded (no gateway, no delivery); `--message-file -`
|
|
4
|
+
* is the explicit stdin channel appended last by the core, so argv never
|
|
5
|
+
* carries the material. `HOME` is the ephemeral home. No credential file is
|
|
6
|
+
* copied (A-01: keychain/env).
|
|
7
|
+
*/
|
|
8
|
+
import type { PrivateHarnessAdapter } from '../harness-executor.js';
|
|
9
|
+
export declare const PRIVATE_OPENCLAW_HARNESS_ADAPTER: PrivateHarnessAdapter;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=Object.freeze({hostKind:"openclaw",binary:"openclaw",fixedArgs:Object.freeze(["agent","--local","--json","--message-file"]),stdinFlag:"-",nativeFlags:Object.freeze([]),configDirEnv:null,configDirEnvs:Object.freeze({HOME:""}),credentialFiles:Object.freeze([]),environmentKeys:Object.freeze(["PATH","HOME","LANG","LC_ALL","TERM"]),versionArgs:Object.freeze(["--version"]),versionPattern:/^(?:openclaw\s+)?v?(\d+\.\d+\.\d+)$/,minimumVersion:"0.0.1",platforms:Object.freeze(["linux","darwin","win32"])});export{e as PRIVATE_OPENCLAW_HARNESS_ADAPTER};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* P229.02 (P229-CON-EXECUTOR, AC1): OpenCode headless private adapter.
|
|
3
|
+
* `opencode run` without a positional message reads the material from stdin,
|
|
4
|
+
* so no prompt ever reaches argv. All XDG dirs point under the ephemeral home.
|
|
5
|
+
*/
|
|
6
|
+
import type { PrivateHarnessAdapter } from '../harness-executor.js';
|
|
7
|
+
export declare const PRIVATE_OPENCODE_HARNESS_ADAPTER: PrivateHarnessAdapter;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=Object.freeze({hostKind:"opencode",binary:"opencode",fixedArgs:Object.freeze(["run","--agent","neocortex-sentinel"]),stdinFlag:null,nativeFlags:Object.freeze([]),configDirEnv:null,configDirEnvs:Object.freeze({XDG_CONFIG_HOME:".config",XDG_DATA_HOME:".local/share",XDG_STATE_HOME:".local/state",XDG_CACHE_HOME:".cache"}),credentialFiles:Object.freeze([".local/share/opencode/auth.json"]),credentialSource:Object.freeze({homeRelative:""}),environmentKeys:Object.freeze(["PATH","HOME","LANG","LC_ALL","TERM"]),versionArgs:Object.freeze(["--version"]),versionPattern:/^(?:opencode\s+)?v?(\d+\.\d+\.\d+)$/,minimumVersion:"1.0.0",platforms:Object.freeze(["linux","darwin","win32"])});export{e as PRIVATE_OPENCODE_HARNESS_ADAPTER};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type PrivateHarnessPlatform } from './harness-process.js';
|
|
2
|
+
export declare const PRIVATE_HARNESS_HOME_PREFIX = ".neocortex-harness-";
|
|
3
|
+
/** `a/b/c/d` with safe segments only; never absolute, `.`, `..`, empty or `\\`. */
|
|
4
|
+
export declare function isSafeHarnessRelativePath(value: unknown): value is string;
|
|
5
|
+
export interface EphemeralHarnessHome {
|
|
6
|
+
/** Local use only: never place this path in receipts or public output. */
|
|
7
|
+
readonly path: string;
|
|
8
|
+
close(): void;
|
|
9
|
+
}
|
|
10
|
+
export interface EphemeralHarnessHomeOptions {
|
|
11
|
+
readonly baseDirectory?: string;
|
|
12
|
+
readonly credentialSourceDirectory?: string;
|
|
13
|
+
readonly credentialFiles?: readonly string[];
|
|
14
|
+
/** P229.02: extra owner-private directories created under the home. */
|
|
15
|
+
readonly directories?: readonly string[];
|
|
16
|
+
readonly platform?: PrivateHarnessPlatform;
|
|
17
|
+
}
|
|
18
|
+
export declare function createEphemeralHarnessHome(options?: EphemeralHarnessHomeOptions): EphemeralHarnessHome;
|
|
19
|
+
export declare function withEphemeralHarnessHome<T>(options: EphemeralHarnessHomeOptions, run: (home: EphemeralHarnessHome) => Promise<T>): Promise<T>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{chmodSync as y,closeSync as S,constants as d,fstatSync as w,lstatSync as a,mkdirSync as v,mkdtempSync as g,openSync as x,readFileSync as D,rmSync as O,writeFileSync as _}from"node:fs";import{tmpdir as b}from"node:os";import{join as l}from"node:path";import{resolvePrivateHarnessPlatform as A}from"./harness-process.js";const L=".neocortex-harness-",N=1024*1024,H=/^[A-Za-z0-9._-]{1,64}$/,R=4;function E(e){if(typeof e!="string")return!1;const r=e.split("/");return r.length<1||r.length>R?!1:r.every(o=>H.test(o)&&o!=="."&&o!=="..")}function u(e){return e.split("/")}function s(){throw new Error("private-executor-credential-unavailable")}function T(e){let r;try{r=x(e,d.O_RDONLY|(d.O_NOFOLLOW??0));const o=w(r);(!o.isFile()||o.size<1||o.size>N)&&s();const t=D(r);return(t.length!==o.size||a(e).isSymbolicLink())&&(t.fill(0),s()),t}catch{return s()}finally{r!==void 0&&S(r)}}function F(e,r){const o=u(r);let t=e;for(const n of o.slice(0,-1)){t=l(t,n);try{const i=a(t);(i.isSymbolicLink()||!i.isDirectory())&&s()}catch{s()}}}function p(e,r,o){let t=e;for(const n of u(r)){t=l(t,n);let i=!1;try{try{v(t,{mode:448})}catch(c){if(c.code!=="EEXIST")throw c}const f=a(t);!f.isSymbolicLink()&&f.isDirectory()&&(o!=="win32"&&y(t,448),i=o==="win32"||(a(t).mode&511)===448)}catch{i=!1}if(!i)throw new Error("private-executor-ephemeral-home-unverified")}}function I(e){const r=u(e);return r.length>1?r.slice(0,-1).join("/"):null}function P(e){try{O(e,{recursive:!0,force:!0})}catch{}try{a(e)}catch(r){if(r.code==="ENOENT")return}throw new Error("private-executor-ephemeral-home-residue")}function k(e={}){const r=A(e.platform??process.platform),o=e.credentialFiles??[];for(const c of o)E(c)||s();const t=e.directories??[];for(const c of t)if(!E(c))throw new Error("private-executor-ephemeral-home-unverified");o.length>0&&e.credentialSourceDirectory===void 0&&s();const n=g(l(e.baseDirectory??b(),L));let i=!1;const f=()=>{i||(P(n),i=!0)};try{if(r!=="win32"&&(y(n,448),(a(n).mode&511)!==448))throw new Error("private-executor-ephemeral-home-unverified");for(const c of t)p(n,c,r);for(const c of o){F(e.credentialSourceDirectory,c);const m=T(l(e.credentialSourceDirectory,...u(c)));try{const h=I(c);h!==null&&p(n,h,r);try{_(l(n,...u(c)),m,{mode:384,flag:"wx"})}catch{throw new Error("private-executor-ephemeral-home-unverified")}}finally{m.fill(0)}}}catch(c){throw f(),c}return Object.freeze({path:n,close:f})}async function C(e,r){const o=k(e);let t=!1,n;try{return await r(o)}catch(i){throw t=!0,n=i,i}finally{try{o.close()}catch(i){if(t&&n instanceof Error&&n.cause===void 0)n.cause=i.message;else if(!t)throw i}}}export{L as PRIVATE_HARNESS_HOME_PREFIX,k as createEphemeralHarnessHome,E as isSafeHarnessRelativePath,C as withEphemeralHarnessHome};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { runBoundedHarnessProcess, type BoundedHarnessProcessResult, type PrivateHarnessPlatform } from './harness-process.js';
|
|
2
|
+
export interface PrivateHarnessAdapter {
|
|
3
|
+
readonly hostKind: string;
|
|
4
|
+
readonly binary: string;
|
|
5
|
+
readonly fixedArgs: readonly string[];
|
|
6
|
+
/** Appended last; `null` means the harness reads stdin implicitly. */
|
|
7
|
+
readonly stdinFlag: string | null;
|
|
8
|
+
/** Native non-persistence / sandbox flags. */
|
|
9
|
+
readonly nativeFlags: readonly string[];
|
|
10
|
+
/** Environment variable that points the harness at the ephemeral home. */
|
|
11
|
+
readonly configDirEnv: string | null;
|
|
12
|
+
readonly credentialFiles: readonly string[];
|
|
13
|
+
readonly environmentKeys: readonly string[];
|
|
14
|
+
readonly versionArgs: readonly string[];
|
|
15
|
+
/** Group 1 must capture an `x.y.z` version. */
|
|
16
|
+
readonly versionPattern: RegExp;
|
|
17
|
+
readonly minimumVersion: string;
|
|
18
|
+
readonly platforms: readonly PrivateHarnessPlatform[];
|
|
19
|
+
/**
|
|
20
|
+
* P229.02 (AC-ENV): extra variables -> relative subdirectory of the ephemeral
|
|
21
|
+
* home (`''` = the home itself). Each directory is created owner-private.
|
|
22
|
+
*/
|
|
23
|
+
readonly configDirEnvs?: Readonly<Record<string, string>>;
|
|
24
|
+
/**
|
|
25
|
+
* P229.02 (AC-CRED): where `credentialFiles` are read from: an absolute
|
|
26
|
+
* `env` value when present, else `homeRelative` under the user home.
|
|
27
|
+
*/
|
|
28
|
+
readonly credentialSource?: {
|
|
29
|
+
readonly env?: string;
|
|
30
|
+
readonly homeRelative: string;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/** Overrides and directories for every config variable, all under the home. */
|
|
34
|
+
export declare function privateHarnessConfigLayout(adapter: PrivateHarnessAdapter): {
|
|
35
|
+
readonly directories: readonly string[];
|
|
36
|
+
readonly overrides: (homePath: string) => Readonly<Record<string, string>>;
|
|
37
|
+
};
|
|
38
|
+
export type PrivateHarnessOutcome = 'executor-returned-unverified' | 'private-executor-timeout' | 'private-executor-output-exceeded' | 'private-executor-exit-nonzero';
|
|
39
|
+
export interface PrivateHarnessExecutionReceiptV2 {
|
|
40
|
+
readonly schemaVersion: 2;
|
|
41
|
+
readonly kind: 'PrivateHarnessExecutionReceipt/2';
|
|
42
|
+
readonly hostKind: string;
|
|
43
|
+
readonly os: PrivateHarnessPlatform;
|
|
44
|
+
readonly outcome: PrivateHarnessOutcome;
|
|
45
|
+
readonly stdoutSha256: string;
|
|
46
|
+
readonly stderrSha256: string;
|
|
47
|
+
readonly stdoutBytes: number;
|
|
48
|
+
readonly stderrBytes: number;
|
|
49
|
+
readonly publicSafe: true;
|
|
50
|
+
}
|
|
51
|
+
export interface PrivateHarnessPreflight {
|
|
52
|
+
readonly hostKind: string;
|
|
53
|
+
readonly hostVersion: string;
|
|
54
|
+
readonly os: PrivateHarnessPlatform;
|
|
55
|
+
readonly observedAtMs: number;
|
|
56
|
+
}
|
|
57
|
+
export type PrivateHarnessProcessRunner = typeof runBoundedHarnessProcess;
|
|
58
|
+
export declare function buildPrivateHarnessArgv(adapter: PrivateHarnessAdapter): readonly string[];
|
|
59
|
+
export declare function sha256Hex(bytes: Buffer): string;
|
|
60
|
+
export declare function createPrivateHarnessReceipt(input: {
|
|
61
|
+
readonly hostKind: string;
|
|
62
|
+
readonly os: PrivateHarnessPlatform;
|
|
63
|
+
readonly result: BoundedHarnessProcessResult;
|
|
64
|
+
}): PrivateHarnessExecutionReceiptV2;
|
|
65
|
+
export declare function preflightPrivateHarness(adapter: PrivateHarnessAdapter, options: {
|
|
66
|
+
readonly cwd: string;
|
|
67
|
+
readonly platform?: PrivateHarnessPlatform;
|
|
68
|
+
readonly now?: () => number;
|
|
69
|
+
readonly processRunner?: PrivateHarnessProcessRunner;
|
|
70
|
+
}): Promise<PrivateHarnessPreflight>;
|
|
71
|
+
export declare function runPrivateHarness(adapter: PrivateHarnessAdapter, material: string, options: {
|
|
72
|
+
readonly cwd: string;
|
|
73
|
+
readonly platform?: PrivateHarnessPlatform;
|
|
74
|
+
readonly timeoutMs: number;
|
|
75
|
+
readonly maxOutputBytes: number;
|
|
76
|
+
readonly credentialSourceDirectory?: string;
|
|
77
|
+
readonly ephemeralBase?: string;
|
|
78
|
+
readonly processRunner?: PrivateHarnessProcessRunner;
|
|
79
|
+
}): Promise<PrivateHarnessExecutionReceiptV2>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createHash as v}from"node:crypto";import{join as x}from"node:path";import{isSafeHarnessRelativePath as y,withEphemeralHarnessHome as h}from"./harness-ephemeral-home.js";import{assertPrivateHarnessMaterial as p,resolvePrivateHarnessPlatform as f,runBoundedHarnessProcess as d}from"./harness-process.js";const b=16*1024,O=5e3,l=/^(\d+)\.(\d+)\.(\d+)$/;function g(e){const t=Object.entries(e.configDirEnvs??{});for(const[r,o]of t)if(r.length===0||r===e.configDirEnv||o!==""&&!y(o))throw new Error("private-executor-ephemeral-home-unverified");return Object.freeze({directories:Object.freeze(t.map(([,r])=>r).filter(r=>r!=="")),overrides:r=>{const o={};e.configDirEnv!==null&&(o[e.configDirEnv]=r);for(const[n,s]of t)o[n]=s===""?r:x(r,...s.split("/"));return Object.freeze(o)}})}function E(e){return Object.freeze([...e.fixedArgs,...e.nativeFlags,...e.stdinFlag===null?[]:[e.stdinFlag]])}function a(e){return v("sha256").update(e).digest("hex")}function w(e){return e.timedOut?"private-executor-timeout":e.outputExceeded?"private-executor-output-exceeded":e.exitCode===0?"executor-returned-unverified":"private-executor-exit-nonzero"}function H(e){const{result:t}=e;return Object.freeze({schemaVersion:2,kind:"PrivateHarnessExecutionReceipt/2",hostKind:e.hostKind,os:f(e.os),outcome:w(t),stdoutSha256:a(t.stdout),stderrSha256:a(t.stderr),stdoutBytes:t.stdout.byteLength,stderrBytes:t.stderr.byteLength,publicSafe:!0})}function P(e,t){const r=l.exec(e),o=l.exec(t);if(!r||!o)return null;for(let n=1;n<=3;n+=1){const s=Number(r[n])-Number(o[n]);if(s!==0)return s}return 0}function m(e,t){const r=f(t??process.platform);if(!e.platforms.includes(r))throw new Error("private-executor-platform-unsupported");return r}async function M(e,t){const r=m(e,t.platform),n=await(t.processRunner??d)(e.binary,e.versionArgs,{cwd:t.cwd,timeoutMs:O,maxOutputBytes:b,environmentKeys:e.environmentKeys,platform:r});try{const i=n.exitCode===0&&!n.timedOut&&!n.outputExceeded?e.versionPattern.exec(n.stdout.toString("utf8").trim())?.[1]:void 0,u=i===void 0?null:P(i,e.minimumVersion);if(i===void 0||u===null||u<0)throw new Error("private-executor-version-unsupported");return Object.freeze({hostKind:e.hostKind,hostVersion:i,os:r,observedAtMs:(t.now??Date.now)()})}finally{n.stdout.fill(0),n.stderr.fill(0)}}async function R(e,t,r){p(t);const o=m(e,r.platform),n=r.processRunner??d,s=g(e);return h({baseDirectory:r.ephemeralBase,credentialSourceDirectory:r.credentialSourceDirectory,credentialFiles:e.credentialFiles,directories:s.directories,platform:o},async i=>{const u=s.overrides(i.path),c=await n(e.binary,E(e),{cwd:r.cwd,stdin:t,timeoutMs:r.timeoutMs,maxOutputBytes:r.maxOutputBytes,environmentKeys:e.environmentKeys,platform:o,environmentOverrides:Object.keys(u).length===0?void 0:u});try{return H({hostKind:e.hostKind,os:o,result:c})}finally{c.stdout.fill(0),c.stderr.fill(0)}})}export{E as buildPrivateHarnessArgv,H as createPrivateHarnessReceipt,M as preflightPrivateHarness,g as privateHarnessConfigLayout,R as runPrivateHarness,a as sha256Hex};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export type PrivateHarnessPlatform = 'linux' | 'darwin' | 'win32';
|
|
2
|
+
export declare const MAX_PRIVATE_HARNESS_MATERIAL_BYTES: number;
|
|
3
|
+
export declare const PRIVATE_HARNESS_KILL_GRACE_MS = 500;
|
|
4
|
+
export type TreeKillStep = {
|
|
5
|
+
readonly kind: 'signal-group';
|
|
6
|
+
readonly signal: 'SIGTERM' | 'SIGKILL';
|
|
7
|
+
readonly pid: number;
|
|
8
|
+
} | {
|
|
9
|
+
readonly kind: 'command';
|
|
10
|
+
readonly command: 'taskkill';
|
|
11
|
+
readonly args: readonly ['/T', '/F', '/PID', string];
|
|
12
|
+
};
|
|
13
|
+
export interface BoundedHarnessProcessResult {
|
|
14
|
+
readonly exitCode: number | null;
|
|
15
|
+
readonly stdout: Buffer;
|
|
16
|
+
readonly stderr: Buffer;
|
|
17
|
+
readonly timedOut: boolean;
|
|
18
|
+
readonly outputExceeded: boolean;
|
|
19
|
+
}
|
|
20
|
+
export interface BoundedHarnessProcessOptions {
|
|
21
|
+
readonly cwd: string;
|
|
22
|
+
readonly stdin?: string;
|
|
23
|
+
readonly timeoutMs: number;
|
|
24
|
+
readonly maxOutputBytes: number;
|
|
25
|
+
readonly environmentKeys: readonly string[];
|
|
26
|
+
readonly environmentOverrides?: Readonly<Record<string, string>>;
|
|
27
|
+
readonly platform?: PrivateHarnessPlatform;
|
|
28
|
+
readonly killGraceMs?: number;
|
|
29
|
+
/** Test seam: receives the full plan once; timing becomes the caller's job. */
|
|
30
|
+
readonly killTree?: (steps: readonly TreeKillStep[], pid: number) => void;
|
|
31
|
+
}
|
|
32
|
+
export declare function resolvePrivateHarnessPlatform(platform?: string): PrivateHarnessPlatform;
|
|
33
|
+
export declare function planTreeKill(platform: PrivateHarnessPlatform, pid: number): readonly TreeKillStep[];
|
|
34
|
+
/**
|
|
35
|
+
* P229.02 (AC-ENV): variables a Windows child needs to start at all. They are
|
|
36
|
+
* added to an adapter allowlist only on win32; linux and darwin are unchanged.
|
|
37
|
+
*/
|
|
38
|
+
export declare const PRIVATE_HARNESS_WIN32_BOOTSTRAP_KEYS: readonly string[];
|
|
39
|
+
export declare function harnessEnvironmentKeys(platform: PrivateHarnessPlatform, keys: readonly string[]): readonly string[];
|
|
40
|
+
/** Only declared keys reach the child; no host secret or proxy is inherited. */
|
|
41
|
+
export declare function harnessEnvironment(source: NodeJS.ProcessEnv, keys: readonly string[]): NodeJS.ProcessEnv;
|
|
42
|
+
export declare function assertPrivateHarnessMaterial(material: unknown): asserts material is string;
|
|
43
|
+
export declare function runBoundedHarnessProcess(command: string, args: readonly string[], options: BoundedHarnessProcessOptions): Promise<BoundedHarnessProcessResult>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{spawn as y}from"node:child_process";const L=256*1024,R=500,b=["linux","darwin","win32"];function E(r=process.platform){if(!b.includes(r))throw new Error("private-executor-platform-unsupported");return r}function M(r,t){const e=E(r);if(!Number.isSafeInteger(t)||t<=0)throw new Error("private-executor-spawn-failed");return Object.freeze(e==="win32"?[Object.freeze({kind:"command",command:"taskkill",args:Object.freeze(["/T","/F","/PID",String(t)])})]:[Object.freeze({kind:"signal-group",signal:"SIGTERM",pid:t}),Object.freeze({kind:"signal-group",signal:"SIGKILL",pid:t})])}const _=Object.freeze(["SYSTEMROOT","USERPROFILE","APPDATA","LOCALAPPDATA","PATHEXT","COMSPEC","TEMP","TMP"]);function H(r,t){return E(r)!=="win32"?t:Object.freeze([...t,..._.filter(e=>!t.includes(e))])}function j(r,t){const e={};for(const s of t)typeof r[s]=="string"&&(e[s]=r[s]);return e}function B(r){if(typeof r!="string")throw new Error("private-executor-material-invalid");const t=Buffer.byteLength(r,"utf8");if(t<1||t>L)throw new Error("private-executor-material-invalid")}function k(r,t){try{return process.kill(-r,t),!0}catch(e){if(e.code==="ESRCH")return!1;throw e}}function K(r){try{const t=y("taskkill",[...r],{stdio:"ignore",windowsHide:!0,shell:!1});t.on("error",()=>{}),t.unref()}catch{}}function C(r,t,e){let s;try{e.stdin!==void 0&&B(e.stdin),s=E(e.platform??process.platform)}catch(a){return Promise.reject(a)}const T=s!=="win32",I=e.killGraceMs??R,w=j(process.env,H(s,e.environmentKeys));for(const[a,c]of Object.entries(e.environmentOverrides??{}))w[a]=c;return new Promise((a,c)=>{let n;try{n=y(r,[...t],{cwd:e.cwd,env:w,stdio:["pipe","pipe","pipe"],detached:T,windowsHide:!0,shell:!1})}catch{c(new Error("private-executor-spawn-failed"));return}const v=[],S=[];let g=0,h=0,O=!1,f=!1,d=!1,l=!1,u;const p=()=>{if(u&&(clearTimeout(u),u=void 0),T&&n.pid!==void 0&&!e.killTree)try{k(n.pid,"SIGKILL")}catch{}},P=()=>{if(d||n.pid===void 0)return;d=!0;const i=M(s,n.pid);if(e.killTree){e.killTree(i,n.pid);return}const[o]=i;try{o?.kind==="command"?K(o.args):o?.kind==="signal-group"&&k(o.pid,o.signal)&&(u=setTimeout(p,I))}catch{try{n.kill("SIGKILL")}catch{}}},A=setTimeout(()=>{O=!0,P()},e.timeoutMs),x=(i,o)=>m=>{o==="stdout"?g+=m.byteLength:h+=m.byteLength,g+h>e.maxOutputBytes?(f=!0,P()):f||i.push(m)};n.stdout.on("data",x(v,"stdout")),n.stderr.on("data",x(S,"stderr")),n.stdin.on("error",()=>{}),n.on("error",i=>{clearTimeout(A),p(),!l&&(l=!0,c(new Error(i.code==="ENOENT"||i.code==="EACCES"?"private-executor-headless-unavailable":"private-executor-spawn-failed")))}),n.on("close",i=>{clearTimeout(A),d&&p(),!l&&(l=!0,a({exitCode:i,stdout:Buffer.concat(v),stderr:Buffer.concat(S),timedOut:O,outputExceeded:f}))}),n.stdin.end(e.stdin)})}export{L as MAX_PRIVATE_HARNESS_MATERIAL_BYTES,R as PRIVATE_HARNESS_KILL_GRACE_MS,_ as PRIVATE_HARNESS_WIN32_BOOTSTRAP_KEYS,B as assertPrivateHarnessMaterial,j as harnessEnvironment,H as harnessEnvironmentKeys,M as planTreeKill,E as resolvePrivateHarnessPlatform,C as runBoundedHarnessProcess};
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import{execFileSync as
|
|
2
|
-
`)])));if(p.byteLength===0||p.byteLength>Z||!B(t.workspacePath,!0).equals(d)||
|
|
1
|
+
import{execFileSync as Ft,spawnSync as vt}from"node:child_process";import{createHash as F}from"node:crypto";import{existsSync as nt,lstatSync as R,readFileSync as m,realpathSync as ht,writeFileSync as mt}from"node:fs";import{isAbsolute as ot,join as a,relative as dt,sep as wt}from"node:path";import{isDeepStrictEqual as S}from"node:util";import{readPrivateYoloFrozenWriteSet as Bt,verifyPrivateYoloCandidateWriteSet as Ct,verifyPrivateYoloCleanBaseline as zt}from"./clean-baseline.js";import{isPrivateIsolatedWorkspacePlatform as _t,PRIVATE_EPIC_PENDING_SIDECAR as et,privateIsolatedWorkspaceModeVerified as bt,privatePendingEpicSidecarVerified as Lt}from"./isolated-workspace.js";import{loadPactPrivateAnswers as Ht}from"../commands/architecture-answers.js";import{derivePactWriteSet as xt}from"./pact-write-set.js";import{deriveUxCandidateWriteSet as Jt,deriveUxWriteSet as Mt}from"./ux-write-set.js";import{validateUxCandidateSource as qt}from"./ux-source-validation.js";import{validatePactTestSource as Gt}from"./pact-test-source.js";import{classifyProjectMemoryUpdate as Wt}from"../memory/project-memory-writer.js";import{privateRootMemoryEffect as yt,privateRootMemorySourceMatches as Yt,privateRootMemorySourceMatchReason as Ut}from"./root-memory-scope.js";import{inspectPactToolchain as Vt,planPactToolchainManifest as Xt}from"./pact-toolchain.js";import{acceptedPlanningDiagnosisPredecessor as Kt,planningPendingSidecarDigest as Rt}from"./planning-diagnosis-checkpoint.js";import{acceptedPlanningResearchPredecessor as Zt}from"./planning-research-checkpoint.js";import{confirmPropertyTestPlan as At,renderPropertyTestConfiguration as Qt}from"./property-test-plan.js";import{validatePropertyTestTypeScriptSource as kt}from"./property-test-source.js";const Z=16*1024*1024,st=1024,ut="acd455ed0e39d98b90fb57391db75e366e4c5604db043e03a89a20e33d643c3c",It="81f50aaa801c1660eabe46e645501acbfb3e9873410c991e1496c014ca75c369",St="fa2194f89c01f07e225fd6f39e98e679f628e072239b6cd0af3ee527f0722518",te="8636f22ec5950410902448ee1e9cb4947359ac98df518742bddbbb367468e3ae";function tt(t,r){return typeof t=="string"&&t.length<=128&&F("sha256").update(t).digest("hex")===r}function Et(){const t={...process.env};for(const r of["GIT_DIR","GIT_WORK_TREE","GIT_INDEX_FILE","GIT_OBJECT_DIRECTORY","GIT_ALTERNATE_OBJECT_DIRECTORIES","GIT_COMMON_DIR","GIT_NAMESPACE","GIT_CEILING_DIRECTORIES"])delete t[r];return t}function G(t,r){return Ft("git",[...r],{cwd:t,env:Et(),stdio:["ignore","pipe","pipe"],timeout:3e4,maxBuffer:Z})}function J(t,r){return G(t,r).toString("utf8").trim()}function B(t,r=!1){return G(t,["status","--porcelain=v1","-z","--untracked-files=all",...r?["--ignored=matching"]:[]])}function rt(t){return!!t&&!ot(t)&&!t.includes("\\")&&!t.includes("\0")&&!t.split("/").some(r=>!r||r==="."||r===".."||r===".git")}function P(t,r){const e=r.split("/");let o=t;for(const s of e.slice(0,-1)){o=a(o,s);try{const i=R(o);if(!i.isDirectory()||i.isSymbolicLink())throw new Error("path-boundary")}catch(i){if(i.code==="ENOENT")return;throw i}}try{const s=R(a(t,r));if(!s.isFile()||s.isSymbolicLink()||s.size>Z)throw new Error("path-boundary")}catch(s){if(s.code!=="ENOENT")throw s}}function $t(t){const r=[...t.matchAll(/\/\/\s*arch:keep-start[^\n]*\n[\s\S]*?\/\/\s*arch:keep-end[^\n]*/g)].map(s=>s[0]),e=(t.match(/arch:keep-start/g)??[]).length,o=(t.match(/arch:keep-end/g)??[]).length;if(e!==o||e!==r.length)throw new Error("architecture-keep-marker-invalid");return r}function M(t,r=!1,e=!1,o=[]){const s=[],i=[];for(const n of t.toString("utf8").split("\0").filter(Boolean)){if(n.length<4||n[2]!==" ")throw new Error("status-invalid");const d=n.slice(0,2),l=n.slice(3);if(!rt(l)||d!=="??"&&d!==" M"&&d!==" D"&&!(d===" T"&&o.includes(l))&&!(e&&d==="!!"&&l===et))throw new Error("status-invalid");s.push(l),d==="??"&&i.push(l)}if(!r&&s.length===0||s.length>st||new Set(s).size!==s.length)throw new Error("status-invalid");return{paths:s.sort(),untracked:i.sort()}}function lt(t,r,e,o){const s=G(r,["ls-tree","-z",e,"--",o]).toString("utf8");if(!s)try{return R(a(t,o)),!1}catch(n){return n.code==="ENOENT"}const i=/^([0-7]{6}) blob [a-f0-9]{40,64}\t([^\0]+)\0$/.exec(s);if(!i||i[2]!==o||!["100644","100755"].includes(i[1]))return!1;try{const n=R(a(t,o));return!n.isFile()||n.isSymbolicLink()||n.size>Z||!!(n.mode&73)!=(i[1]==="100755")?!1:m(a(t,o)).equals(G(r,["show",`${e}:${o}`]))}catch{return!1}}function xe(t,r,e,o){return rt(o)&&/^[a-f0-9]{40,64}$/.test(e)&<(t,r,e,o)}function it(t,r){try{const e=a(t,et);return Lt(t)&&F("sha256").update(m(e)).digest("hex")===r}catch{return!1}}function ft(t,r,e,o,s,i){const n=new Set(o),d=i?yt(i).files.map(f=>f.path):[],l=M(B(t),!0,!!s,d),c=i?Ut(i,t,r,e):"matched";if(c!=="matched")throw new Error(`root-memory-${c}`);if(!l.paths.every(f=>n.has(f)||d.includes(f)||f===et&&!!s&&it(t,s)))throw new Error("source-unclaimed-delta");if(!o.every(f=>lt(t,r,e,f)))throw new Error("source-frozen-mismatch");return!s||it(t,s)}function ee(t,r){const e=vt("git",["diff","--no-index","--binary","--no-ext-diff","--","/dev/null",r],{cwd:t,env:Et(),encoding:"buffer",timeout:3e4,maxBuffer:Z});if(e.error||e.status!==1||!Buffer.isBuffer(e.stdout)||e.stdout.byteLength===0)throw new Error("patch-invalid");return e.stdout}function Ot(t,r,e){const o=vt("git",["apply",...e?["--check"]:[],"--binary","-"],{cwd:t,env:Et(),input:r,encoding:"buffer",timeout:3e4,maxBuffer:Z});if(o.error||o.status!==0)throw new Error("apply-failed")}function pt(t,r,e){const o=a(t,e),s=a(r,e);try{const i=R(o),n=R(s);return i.isFile()&&n.isFile()&&(i.mode&73)===(n.mode&73)&&m(o).equals(m(s))}catch(i){if(i.code!=="ENOENT")return!1;try{return R(o),!1}catch(n){if(n.code!=="ENOENT")return!1}try{return R(s),!1}catch(n){return n.code==="ENOENT"}}}function Re(t,r,e,o){Tt(t,r,e,!0,o)}function Ae(t,r,e,o){if(Tt(t,r,e,!1,o),G(t.workspacePath,["diff","--cached","--name-only"]).byteLength!==0)throw new Error("private-execution-isolated-snapshot-unverified")}function Tt(t,r,e,o,s){try{if(!_t()||t.schemaVersion!==1||!ot(t.sourceRoot)||!ot(t.workspacePath)||ht(t.sourceRoot)!==t.sourceRoot||ht(t.workspacePath)!==t.workspacePath||!R(t.workspacePath).isDirectory()||!bt(R(t.workspacePath))||dt(t.sourceRoot,t.workspacePath)===""||dt(t.sourceRoot,t.workspacePath).split(wt)[0]!==".."||!/^[a-f0-9]{40,64}$/.test(t.baseSha)||!/^[a-f0-9]{40,64}$/.test(e)||J(t.sourceRoot,["rev-parse","--show-toplevel"])!==t.sourceRoot||J(t.workspacePath,["rev-parse","--show-toplevel"])!==t.workspacePath||J(t.sourceRoot,["rev-parse","HEAD"])!==t.baseSha||J(t.workspacePath,["rev-parse","HEAD"])!==e||J(t.sourceRoot,["symbolic-ref","--short","HEAD"])!==t.executionBranch||J(t.workspacePath,["symbolic-ref","--short","HEAD"])!==t.executionBranch||nt(a(t.workspacePath,".git","objects","info","alternates"))||o&&B(t.workspacePath,!0).byteLength!==0||r.length===0||r.length>st||r.some(i=>!rt(i))||new Set(r).size!==r.length)throw new Error("boundary-invalid");if(G(t.workspacePath,["merge-base","--is-ancestor",t.baseSha,e]),!ft(t.sourceRoot,t.workspacePath,e,r,void 0,s))throw new Error("boundary-raced")}catch(i){const n=i instanceof Error&&(["boundary-invalid","boundary-raced","status-invalid","source-unclaimed-delta","source-frozen-mismatch"].includes(i.message)||/^root-memory-(scope-binding|snapshot-ancestry|snapshot-content|source-content|source-projection)(-unsafe)?$/.test(i.message))?i.message:"physical-inspection-failed";throw new Error("private-execution-isolated-snapshot-unverified",{cause:new Error(n)})}}function W(t,r,e,o,s,i=[],n){try{if(!_t()||t.schemaVersion!==1||!ot(t.sourceRoot)||!ot(t.workspacePath)||ht(t.sourceRoot)!==t.sourceRoot||ht(t.workspacePath)!==t.workspacePath||!R(t.workspacePath).isDirectory()||!bt(R(t.workspacePath))||dt(t.sourceRoot,t.workspacePath)===""||dt(t.sourceRoot,t.workspacePath).split(wt)[0]!==".."||J(t.sourceRoot,["rev-parse","--show-toplevel"])!==t.sourceRoot||J(t.workspacePath,["rev-parse","--show-toplevel"])!==t.workspacePath||J(t.sourceRoot,["rev-parse","HEAD"])!==t.baseSha||!/^[a-f0-9]{40,64}$/.test(e)||J(t.workspacePath,["rev-parse","HEAD"])!==e||J(t.sourceRoot,["symbolic-ref","--short","HEAD"])!==t.executionBranch||J(t.workspacePath,["symbolic-ref","--short","HEAD"])!==t.executionBranch||r.length===0||r.length>st||r.some(g=>!rt(g))||new Set(r).size!==r.length)throw new Error("authority-invalid");if(G(t.workspacePath,["merge-base","--is-ancestor",t.baseSha,e]),!ft(t.sourceRoot,t.workspacePath,e,r,o,n))throw new Error("source-snapshot-mismatch");const d=B(t.workspacePath,!0),l=M(d),c=new Set(r);if(l.paths.some(g=>!c.has(g)||i.includes(g)))throw new Error("path-unclaimed");if(s&&!s())throw new Error("candidate-raced");for(const g of l.paths)P(t.workspacePath,g),P(t.sourceRoot,g);const h=[G(t.workspacePath,["diff","--binary","--no-ext-diff","--no-textconv","HEAD","--"]),...l.untracked.map(g=>ee(t.workspacePath,g))],p=Buffer.concat(h.map(g=>Buffer.concat([g,Buffer.from(`
|
|
2
|
+
`)])));if(p.byteLength===0||p.byteLength>Z||!B(t.workspacePath,!0).equals(d)||s&&!s()||!ft(t.sourceRoot,t.workspacePath,e,r,o,n))throw new Error("patch-raced");if(Ot(t.sourceRoot,p,!0),!B(t.workspacePath,!0).equals(d)||s&&!s()||!ft(t.sourceRoot,t.workspacePath,e,r,o,n))throw new Error("patch-raced");Ot(t.sourceRoot,p,!1);const w=n?yt(n).files.map(g=>g.path):[];if(M(B(t.sourceRoot),!0,!!o,w).paths.some(g=>!c.has(g)&&!w.includes(g)&&g!==et)||n&&!Yt(n,t.sourceRoot)||o&&!it(t.sourceRoot,o)||r.some(g=>!pt(t.workspacePath,t.sourceRoot,g))||J(t.sourceRoot,["rev-parse","HEAD"])!==t.baseSha||J(t.sourceRoot,["symbolic-ref","--short","HEAD"])!==t.executionBranch)throw new Error("admission-raced");return Object.freeze({schemaVersion:1,outcome:"admitted-unverified",baseSha:t.baseSha,executionBranch:t.executionBranch,changedPaths:Object.freeze([...l.paths]),patchSha256:F("sha256").update(p).digest("hex")})}catch{throw new Error("private-execution-isolated-admission-unverified")}}async function Se(t,r,e,o=t.baseSha,s=!1,i){try{const n=await Bt(t.sourceRoot,r,t.executionBranch,e);if(i){const f=yt(i);if(f.storyId!==r||f.childClaimRevision!==F("sha256").update([...n].sort().join("\0")).digest("hex"))throw new Error("root-memory-claim-mismatch")}const d=a(t.workspacePath,".neocortex","state.json"),l=R(d);if(!l.isFile()||l.isSymbolicLink()||l.size>Z)throw new Error("candidate-state-invalid");Ct(m(d,"utf8"),r,n);const c=W(t,n,o,void 0,void 0,s?[".neocortex/state.json"]:[],i);return await zt(t.sourceRoot,r,t.executionBranch,e),c}catch{throw new Error("private-execution-isolated-admission-unverified")}}const re=new Set(["id","epic_id","title","description","status","steps_completed","last_step","branch_name","estimated_hours","complexity","priority","type","depends_on","created_at","updated_at","acceptance_criteria"]),ne=new Set(["id","title","description","status","stories","total_stories","completed_stories","estimated_hours","complexity","priority","created_at","updated_at","last_updated","source","tags"]);function jt(t){return["title","description","complexity","priority","type","created_at","updated_at","last_updated","source"].some(e=>t[e]!==void 0&&typeof t[e]!="string")||t.estimated_hours!==void 0&&(typeof t.estimated_hours!="number"||!Number.isFinite(t.estimated_hours)||t.estimated_hours<0)?!1:["depends_on","acceptance_criteria","tags"].every(e=>t[e]===void 0||Array.isArray(t[e])&&t[e].length<=256&&t[e].every(o=>typeof o=="string"))}function oe(t){return Object.keys(t).every(r=>re.has(r))&&t.status==="backlog"&&jt(t)&&(t.steps_completed===void 0||Array.isArray(t.steps_completed)&&t.steps_completed.length===0)&&(t.last_step===void 0||t.last_step===null)&&(t.branch_name===void 0||t.branch_name===null)}function $e(t,r,e,o,s){try{if(!/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/.test(r)||!/^P[1-9][0-9]*$/.test(e)||!/^[a-f0-9]{64}$/.test(o)||!/^[a-f0-9]{64}$/.test(s)||!it(t.sourceRoot,s))throw new Error("claim-invalid");const i=JSON.parse(m(a(t.sourceRoot,et),"utf8")),n=i&&typeof i=="object"&&!Array.isArray(i)?i.operations?.[o]:void 0;if(!n||typeof n!="object"||Array.isArray(n)||n.claimId!==r||n.epicId!==e)throw new Error("claim-sidecar-mismatch");const d=M(B(t.workspacePath,!0)),l=`docs/epics/epic-${e}.md`,c=".neocortex/state.json",f=new RegExp(`^docs/stories/${e}\\.[0-9]{2}\\.story\\.md$`),h=d.paths.filter(E=>f.test(E));if(!d.paths.includes(l)||!d.paths.includes(c)||h.length===0||h.length>99||d.paths.some(E=>E!==l&&E!==c&&E!=="NEOCORTEX.md"&&!f.test(E)))throw new Error("artifact-scope-invalid");const p=h.map(E=>E.slice(13,-9)).sort();if(p.some((E,T)=>E!==`${e}.${String(T+1).padStart(2,"0")}`))throw new Error("story-sequence-invalid");for(const E of[l,...h])try{throw R(a(t.sourceRoot,E)),new Error("artifact-already-exists")}catch(T){if(T.code!=="ENOENT")throw T}const w=(E,T)=>{P(t.workspacePath,E);const K=m(a(t.workspacePath,E),"utf8");return Buffer.byteLength(K)>Z?null:/^---\r?\n([\s\S]{1,8192}?)\r?\n---(?:\r?\n|$)/.exec(K)?.[1]?.split(/\r?\n/).find(ct=>ct.startsWith(`${T}:`))?.slice(T.length+1).trim()?.replace(/^(["'])(.*)\1$/,"$2")??null};if(w(l,"id")!==e||h.some((E,T)=>w(E,"id")!==p[T]||w(E,"epic_id")!==e))throw new Error("artifact-id-invalid");P(t.workspacePath,c);const u=JSON.parse(m(a(t.workspacePath,c),"utf8"));if(!u||typeof u!="object"||Array.isArray(u))throw new Error("state-invalid");const g=u,_=g.epics,j=g.stories,b=_?.[e],N=g.epic_id_ledger;if(g.schema_version!==1||!b||b.id!==e||b.status!=="memory-updated"||Object.keys(b).some(E=>!ne.has(E))||!jt(b)||b.completed_stories!==void 0&&b.completed_stories!==0||b.total_stories!==void 0&&b.total_stories!==p.length||!Array.isArray(b.stories)||b.stories.length!==p.length||b.stories.some((E,T)=>E!==p[T])||!j||p.some(E=>{const T=j[E];return!T||T.id!==E||T.epic_id!==e||!oe(T)})||!N||!Array.isArray(N.reserved_ids)||!N.reserved_ids.includes(e))throw new Error("state-claim-mismatch");P(t.sourceRoot,c);const y=JSON.parse(m(a(t.sourceRoot,c),"utf8")),A=y.epics,x=y.stories;if(!A||!x||A[e]!==void 0||p.some(E=>x[E]!==void 0))throw new Error("state-claim-conflict");const{[e]:Y,...L}=_,$={...j};for(const E of p)delete $[E];const{epic_id_ledger:q,last_updated:C,...z}=y,{epic_id_ledger:V,last_updated:X,...Q}=g;if(!S(L,A)||!S($,x)||!S({...Q,epics:void 0,stories:void 0},{...z,epics:void 0,stories:void 0}))throw new Error("state-unrelated-drift");const O=y.epic_id_ledger&&typeof y.epic_id_ledger=="object"?y.epic_id_ledger.reserved_ids:void 0,{reserved_ids:U,...v}=N,D=y.epic_id_ledger&&typeof y.epic_id_ledger=="object"?y.epic_id_ledger:{schema_version:1},{reserved_ids:H,...k}=D;if(O!==void 0&&(!Array.isArray(O)||O.some(E=>typeof E!="string"||!/^P[1-9][0-9]*$/.test(E))||new Set(O).size!==O.length))throw new Error("ledger-drift");const I=[...Array.isArray(O)?O:[]];if(I.includes(e)||I.push(e),!S(N.reserved_ids,I)||!S(v,k))throw new Error("ledger-drift");return W(t,d.paths,t.baseSha,s)}catch{throw new Error("private-execution-epic-claim-admission-unverified")}}function Oe(t,r,e,o,s,i){try{if(!/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/.test(r)||!/^P[1-9][0-9]{0,11}$/.test(e)||!/^[a-f0-9]{64}$/.test(o)||!/^[a-f0-9]{64}$/.test(s)||typeof i!="string"||!i.trim()||i.length>16384||!it(t.sourceRoot,s))throw new Error("planning-claim-invalid");const n=JSON.parse(m(a(t.sourceRoot,et),"utf8")),d=n&&typeof n=="object"&&!Array.isArray(n)?n.operations?.[o]:void 0;if(!d||typeof d!="object"||Array.isArray(d)||d.claimId!==r||d.epicId!==e)throw new Error("planning-claim-sidecar-mismatch");const l=`.neocortex/planning/epic-${e}`,c=`${l}/idea.json`,f=`${l}/diagnosis.md`,h=`${l}/enriched-prompt.md`,p=".neocortex/planning/planning.json",w=[c,f,h,p],u=M(B(t.workspacePath,!0));if(u.paths.length!==w.length||u.paths.some(E=>!w.includes(E)))throw new Error("planning-artifact-scope-invalid");for(const E of[c,f,h]){P(t.workspacePath,E);try{throw R(a(t.sourceRoot,E)),new Error("planning-artifact-already-exists")}catch(T){if(T.code!=="ENOENT")throw T}}const g=(E,T)=>{const K=R(a(t.workspacePath,E));if(!K.isFile()||K.isSymbolicLink()||K.size<1||K.size>T)throw new Error("planning-artifact-invalid");return m(a(t.workspacePath,E),"utf8")},_=JSON.parse(g(c,32*1024));if(!_||typeof _!="object"||Array.isArray(_)||_.epic_id!==e||_.status!=="diagnosed"||typeof _.raw_input!="string"||_.raw_input!==i)throw new Error("planning-idea-invalid");const j=g(f,256*1024),b=g(h,256*1024),N=(E,T)=>{const K=/^---\n([\s\S]{1,8192}?)\n---\n/.exec(E.replace(/\r\n/g,`
|
|
3
3
|
`))?.[1];if(!K)return!1;const Pt=K.split(`
|
|
4
|
-
`),at=gt=>{const ct=Pt.filter(
|
|
5
|
-
`))?.[1],y=O=>{const
|
|
6
|
-
`).filter(
|
|
4
|
+
`),at=gt=>{const ct=Pt.filter(Dt=>Dt.startsWith(`${gt}:`));return ct.length===1?ct[0].slice(gt.length+1).trim().replace(/^(?:"(.*)"|'(.*)')$/,"$1$2"):void 0};return at("epic_id")===e&&tt(at("step"),T)&&at("status")==="completed"};if(!N(j,ut)||!N(b,It))throw new Error("planning-document-identity-invalid");P(t.workspacePath,p),P(t.sourceRoot,p);const y=JSON.parse(g(p,128*1024)),A=nt(a(t.sourceRoot,p))?JSON.parse(m(a(t.sourceRoot,p),"utf8")):void 0;if(!y||typeof y!="object"||Array.isArray(y)||!("epics"in y)||!y.epics||typeof y.epics!="object"||Array.isArray(y.epics)||A!==void 0&&(!A||typeof A!="object"||Array.isArray(A)||!("epics"in A)||!A.epics||typeof A.epics!="object"||Array.isArray(A.epics)))throw new Error("planning-index-invalid");const x=y,Y=x.epics,L=Y[e],$=L,q=$?.output_files;if(!L||typeof L!="object"||Array.isArray(L)||$?.id!==e||$.status!=="diagnosed"||$.idea!==_.raw_input||!Array.isArray($.steps_completed)||$.steps_completed.length!==1||!tt($.steps_completed[0],ut)||typeof $.created_at!="string"||!Number.isFinite(Date.parse($.created_at))||$.completed_at!==null||!q||typeof q!="object"||Array.isArray(q)||!S(q,{diagnosis:`${l}/diagnosis.md`})||!S(Object.keys($).sort(),["id","idea","status","steps_completed","created_at","completed_at","output_files"].sort()))throw new Error("planning-index-epic-invalid");const{last_scan:C,epics:z,...V}=x,X=A,Q=X?.epics,{last_scan:O,epics:U,...v}=X??{},{[e]:D,...H}=Y;if(Q?.[e]!==void 0||!S(H,Q??{})||X!==void 0&&!S(V,v)||X===void 0&&(Object.keys(Y).length!==1||!S(Object.keys(x).sort(),["version","next_epic_id","last_scan","existing_epics_discovered","epics"].sort())||x.version!=="1.0.0"||x.next_epic_id!==1||!S(x.existing_epics_discovered,[]))||typeof x.last_scan!="string"||!Number.isFinite(Date.parse(x.last_scan)))throw new Error("planning-index-drift");const k=w.map(E=>F("sha256").update(m(a(t.workspacePath,E))).digest("hex")),I=()=>w.every((E,T)=>{try{return P(t.workspacePath,E),F("sha256").update(m(a(t.workspacePath,E))).digest("hex")===k[T]}catch{return!1}});return W(t,w,t.baseSha,s,I)}catch{throw new Error("private-execution-planning-diagnosis-admission-unverified")}}function Te(t,r,e,o,s,i){try{if(!/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/.test(r)||!/^P[1-9][0-9]{0,11}$/.test(e)||!/^[a-f0-9]{64}$/.test(o)||!/^[a-f0-9]{64}$/.test(s)||!/^[a-f0-9]{64}$/.test(i))throw new Error("planning-research-binding-invalid");const n=".neocortex/state.json",d=".neocortex/planning/planning.json",l=`.neocortex/planning/epic-${e}`,c=`${l}/research.md`;if(P(t.sourceRoot,n),P(t.workspacePath,n),P(t.sourceRoot,d),P(t.workspacePath,d),P(t.sourceRoot,c),P(t.workspacePath,c),R(a(t.sourceRoot,n)).size>8*1024*1024||R(a(t.workspacePath,n)).size>8*1024*1024||R(a(t.sourceRoot,d)).size>128*1024||R(a(t.workspacePath,d)).size>128*1024)throw new Error("planning-research-source-size-invalid");const f=m(a(t.sourceRoot,n));if(F("sha256").update(f).digest("hex")!==i||!f.equals(m(a(t.workspacePath,n))))throw new Error("planning-research-state-drift");const h=JSON.parse(f.toString("utf8")),p=Kt(h,r,e);if(p.diagnosisReceiptId!==o||p.intakeRevision!==s)throw new Error("planning-research-predecessor-mismatch");const u=h.epics[e].createEpicPlanningPhysical.artifactDigests;for(const[O,U]of Object.entries({idea:`${l}/idea.json`,diagnosis:`${l}/diagnosis.md`,enrichment:`${l}/enriched-prompt.md`,index:d}))if(P(t.sourceRoot,U),F("sha256").update(m(a(t.sourceRoot,U))).digest("hex")!==u[O])throw new Error("planning-research-source-artifact-drift");try{throw R(a(t.sourceRoot,c)),new Error("planning-research-already-exists")}catch(O){if(O.code!=="ENOENT")throw O}const g=[c,d],_=M(B(t.workspacePath,!0));if(_.paths.length!==g.length||_.paths.some(O=>!g.includes(O)))throw new Error("planning-research-write-scope-invalid");const j=R(a(t.workspacePath,c));if(!j.isFile()||j.isSymbolicLink()||j.size<64||j.size>256*1024)throw new Error("planning-research-document-invalid");const b=m(a(t.workspacePath,c),"utf8"),N=/^---\n([\s\S]{1,8192}?)\n---\n/.exec(b.replace(/\r\n/g,`
|
|
5
|
+
`))?.[1],y=O=>{const U=N?.split(`
|
|
6
|
+
`).filter(v=>v.startsWith(`${O}:`))??[];return U.length===1?U[0].slice(O.length+1).trim().replace(/^(?:"(.*)"|'(.*)')$/,"$1$2"):void 0};if(!N||y("epic_id")!==e||y("status")!=="completed"||!tt(y("step"),St)||!b.slice(N.length+8).trim())throw new Error("planning-research-document-identity-invalid");const A=JSON.parse(m(a(t.sourceRoot,d),"utf8")),x=JSON.parse(m(a(t.workspacePath,d),"utf8"));if(!A||typeof A!="object"||Array.isArray(A)||!x||typeof x!="object"||Array.isArray(x))throw new Error("planning-research-index-invalid");const Y=A,L=x,$=Y.epics,q=L.epics,C=$?.[e];if(!$||Array.isArray($)||!q||Array.isArray(q)||!C||Array.isArray(C)||C.id!==e||C.idea!==p.rawIntent||C.status!=="diagnosed"||!Array.isArray(C.steps_completed)||C.steps_completed.length!==1||!tt(C.steps_completed[0],ut)||!S(C.output_files,{diagnosis:`${l}/diagnosis.md`})||typeof L.last_scan!="string"||!Number.isFinite(Date.parse(L.last_scan)))throw new Error("planning-research-index-predecessor-invalid");const z={...C,status:"researched",steps_completed:[...C.steps_completed,y("step")],output_files:{diagnosis:`${l}/diagnosis.md`,research:c}},V={...Y,last_scan:L.last_scan,epics:{...$,[e]:z}};if(!S(L,V))throw new Error("planning-research-index-drift");const X=g.map(O=>F("sha256").update(m(a(t.workspacePath,O))).digest("hex")),Q=()=>g.every((O,U)=>{try{return P(t.workspacePath,O),F("sha256").update(m(a(t.workspacePath,O))).digest("hex")===X[U]}catch{return!1}});return W(t,g,t.baseSha,Rt(t.sourceRoot),Q)}catch{throw new Error("private-execution-planning-research-admission-unverified")}}function je(t,r,e,o,s,i,n){try{if(!/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/.test(r)||!/^P[1-9][0-9]{0,11}$/.test(e)||[o,s,i,n].some(v=>!/^[a-f0-9]{64}$/.test(v)))throw new Error("planning-generation-binding-invalid");const d=".neocortex/state.json",l=".neocortex/planning/planning.json",c=`.neocortex/planning/epic-${e}`,f=`docs/epics/epic-${e}.md`;for(const v of[d,l,`${c}/idea.json`,`${c}/diagnosis.md`,`${c}/enriched-prompt.md`,`${c}/research.md`]){P(t.sourceRoot,v),P(t.workspacePath,v);const D=m(a(t.sourceRoot,v));if(v!==l&&!D.equals(m(a(t.workspacePath,v)))||!D.equals(G(t.sourceRoot,["show",`HEAD:${v}`])))throw new Error("planning-generation-predecessor-uncommitted")}const h=m(a(t.sourceRoot,d));if(h.byteLength>8*1024*1024||F("sha256").update(h).digest("hex")!==n)throw new Error("planning-generation-state-drift");const p=JSON.parse(h.toString("utf8")),w=Zt(p,r,e);if(w.diagnosisReceiptId!==o||w.researchReceiptId!==s||w.intakeRevision!==i)throw new Error("planning-generation-predecessor-mismatch");const u=p.epics[e],g=u.createEpicPlanningPhysical.artifactDigests,_=u.createEpicPlanningResearchPhysical.artifactDigests,j={idea:`${c}/idea.json`,diagnosis:`${c}/diagnosis.md`,enrichment:`${c}/enriched-prompt.md`,research:`${c}/research.md`};for(const[v,D]of Object.entries(j)){const H=v==="research"?_.research:g[v];if(F("sha256").update(m(a(t.sourceRoot,D))).digest("hex")!==H)throw new Error("planning-generation-artifact-drift")}if(F("sha256").update(m(a(t.sourceRoot,l))).digest("hex")!==_.index)throw new Error("planning-generation-index-drift");const b=M(B(t.workspacePath,!0)),N=new RegExp(`^docs/stories/${e}\\.([0-9]{2})\\.story\\.md$`),y=b.paths.filter(v=>N.test(v)).sort((v,D)=>Number(N.exec(v)[1])-Number(N.exec(D)[1]));if(y.length<1||y.length>24||y.some((v,D)=>N.exec(v)[1]!==String(D+1).padStart(2,"0"))||b.paths.length!==y.length+2||b.paths.some(v=>v!==f&&v!==l&&!N.test(v)))throw new Error("planning-generation-write-scope-invalid");const A=[f,l,...y];for(const v of[f,...y]){P(t.sourceRoot,v),P(t.workspacePath,v);try{throw R(a(t.sourceRoot,v)),new Error("planning-generation-path-collision")}catch(H){if(H.code!=="ENOENT")throw H}const D=R(a(t.workspacePath,v));if(!D.isFile()||D.isSymbolicLink()||D.size<128||D.size>(v===f?512:128)*1024)throw new Error("planning-generation-document-invalid")}const x=(v,D)=>{const k=/^---\n([\s\S]{1,8192}?)\n---\n/.exec(v.replace(/\r\n/g,`
|
|
7
7
|
`))?.[1]?.split(`
|
|
8
|
-
`).filter(I=>I.startsWith(`${D}:`))??[];return k.length===1?k[0].slice(D.length+1).trim().replace(/^(?:"(.*)"|'(.*)')$/,"$1$2"):void 0},
|
|
9
|
-
`))?.[1]??"";if(
|
|
8
|
+
`).filter(I=>I.startsWith(`${D}:`))??[];return k.length===1?k[0].slice(D.length+1).trim().replace(/^(?:"(.*)"|'(.*)')$/,"$1$2"):void 0},Y=m(a(t.workspacePath,f),"utf8");if(x(Y,"id")!==e||x(Y,"stories_count")!==String(y.length)||!Y.includes("## Stories"))throw new Error("planning-generation-epic-invalid");for(const[v,D]of y.entries()){const H=m(a(t.workspacePath,D),"utf8"),k=/^---\n([\s\S]{1,8192}?)\n---\n/.exec(H.replace(/\r\n/g,`
|
|
9
|
+
`))?.[1]??"";if(x(H,"id")!==`${e}.${String(v+1).padStart(2,"0")}`||x(H,"epic_id")!==e||/^\s*epic\s*:/m.test(k)||x(H,"status")!=="backlog"||!H.includes("## Acceptance Criteria")||!/\bGiven\b[\s\S]*\bWhen\b[\s\S]*\bThen\b/.test(H))throw new Error("planning-generation-story-invalid")}const L=JSON.parse(m(a(t.sourceRoot,l),"utf8")),$=JSON.parse(m(a(t.workspacePath,l),"utf8")),q=L.epics,C=$.epics,z=q?.[e],V=C?.[e];if(!q||!C||!z||!V||z.id!==e||z.status!=="researched"||!Array.isArray(z.steps_completed)||z.steps_completed.length!==2||!tt(z.steps_completed[0],ut)||!tt(z.steps_completed[1],St)||!S(z.output_files,{diagnosis:`${c}/diagnosis.md`,research:`${c}/research.md`})||typeof $.last_scan!="string"||!Number.isFinite(Date.parse($.last_scan))||typeof V.completed_at!="string"||!Number.isFinite(Date.parse(V.completed_at)))throw new Error("planning-generation-index-predecessor-invalid");const X=V.steps_completed?.[2];if(!tt(X,te))throw new Error("planning-generation-index-transition-invalid");const Q={...L,last_scan:$.last_scan,epics:{...q,[e]:{...z,status:"generated",steps_completed:[...z.steps_completed,X],completed_at:V.completed_at,output_files:{...z.output_files,epic:f,stories:y}}}};if(!S($,Q))throw new Error("planning-generation-index-transition-invalid");const O=A.map(v=>F("sha256").update(m(a(t.workspacePath,v))).digest("hex")),U=()=>A.every((v,D)=>{try{return P(t.workspacePath,v),F("sha256").update(m(a(t.workspacePath,v))).digest("hex")===O[D]}catch{return!1}});return W(t,A,t.baseSha,Rt(t.sourceRoot),U)}catch{throw new Error("private-execution-planning-generation-admission-unverified")}}function Ne(t,r,e){try{if(!/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/.test(e))throw new Error("story-id-invalid");const o=".neocortex/state.json";P(r.sourceRoot,o),P(r.workspacePath,o);const s=m(a(r.sourceRoot,o));if(!s.equals(m(a(r.workspacePath,o))))throw new Error("state-drift");const i=JSON.parse(s.toString("utf8")),n=i?.stories?.[e],d=n?.files_to_modify;if(i?.schema_version!==1||n?.id!==e||!Array.isArray(d)||d.length<1||d.length>st||d.some(f=>typeof f!="string"||!rt(f)||f.length>1024||/[\r\n]/.test(f))||new Set(d).size!==d.length)throw new Error("write-set-invalid");const l=d,c=l.filter(f=>{if(!f.startsWith("docs/stories/")||!f.endsWith(".story.md"))return!1;P(r.sourceRoot,f),P(r.workspacePath,f);const h=m(a(r.sourceRoot,f));if(!h.equals(m(a(r.workspacePath,f))))throw new Error("story-drift");const w=/^---\r?\n([\s\S]{1,8192}?)\r?\n---(?:\r?\n|$)/.exec(h.toString("utf8"))?.[1]?.split(/\r?\n/).filter(u=>u.startsWith("id:"))??[];return w.length===1&&w[0].slice(3).trim().replace(/^(["'])(.*)\1$/,"$2")===e});if(c.length!==1)throw new Error("story-target-ambiguous");return`${t}
|
|
10
10
|
|
|
11
11
|
Private story handoff (local only):
|
|
12
12
|
${JSON.stringify({storyId:e,storyPath:c[0],allowedPaths:[...l].sort()})}
|
|
13
13
|
Work from this isolated checkout's current directory. Use the exact storyPath above for the delivered current step; do not use an unresolved story-file placeholder or infer a filename. Persist the current step's actual result in the declared files; a final chat response alone is not a saved candidate. Modify only allowedPaths and preserve story identity and the write set. Do not operate Git, change unrelated stories, grant root QA/checkpoint authority, or declare the story, epic or pipeline complete. If required inputs are unavailable, report failure without inventing evidence or completion.
|
|
14
|
-
`}catch{throw new Error("private-execution-state-step-handoff-unverified")}}function
|
|
14
|
+
`}catch{throw new Error("private-execution-state-step-handoff-unverified")}}function De(t,r){try{if(!/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/.test(r))throw new Error("story-id-invalid");const e=".neocortex/state.json";P(t.sourceRoot,e),P(t.workspacePath,e);const o=JSON.parse(m(a(t.sourceRoot,e),"utf8")),s=JSON.parse(m(a(t.workspacePath,e),"utf8"));if(!o||typeof o!="object"||Array.isArray(o)||!s||typeof s!="object"||Array.isArray(s))throw new Error("state-invalid");const i=o,n=s,d=i.stories,l=n.stories,c=d?.[r],f=l?.[r],h=c?.files_to_modify;if(i.schema_version!==1||n.schema_version!==1||!d||!l||!c||!f||c.id!==r||f.id!==r||f.epic_id!==c.epic_id||!Array.isArray(h)||h.length===0||h.length>st||h.some(x=>typeof x!="string"||!rt(x)||x.length>1024)||new Set(h).size!==h.length||!S(f.files_to_modify,h))throw new Error("write-set-invalid");const{[r]:p,...w}=d,{[r]:u,...g}=l,{stories:_,last_updated:j,...b}=i,{stories:N,last_updated:y,...A}=n;if(!S(g,w)||!S(A,b))throw new Error("state-unrelated-drift");return W(t,[...h].sort(),t.baseSha)}catch{throw new Error("private-execution-state-step-admission-unverified")}}function Fe(t,r,e){if(r==="chaos-plan"&&e==="chaos-quarterly-v1")try{const s=new Date,i=`Q${Math.floor(s.getUTCMonth()/3)+1}-${s.getUTCFullYear()}`,n=M(B(t.workspacePath,!0)).paths,d=`tools/chaos/${i}-plan.md`,l=`.neocortex/chaos-history/${i}.md`,c=n.filter(u=>u.startsWith("tools/chaos/experiments/")),f=c.map(u=>/^tools\/chaos\/experiments\/(chaos-mesh|litmus|aws-fis)-(?:PodKill|NetworkChaos|IOChaos|StressChaos|TimeChaos|pod-kill|network-chaos|io-chaos|stress-chaos|time-chaos)-([a-z0-9]+(?:-[a-z0-9]+)*)\.yaml$/.exec(u));if(!n.includes(d)||!n.includes(l)||c.length<5||c.length>10||n.length!==c.length+2||f.some(u=>!u)||new Set(f.map(u=>u[1])).size!==1)throw new Error("chaos-write-set-invalid");for(const u of n)if(P(t.workspacePath,u),R(a(t.workspacePath,u)).size===0)throw new Error("chaos-empty-artifact");const h=m(a(t.workspacePath,l),"utf8");if(!h.includes(i)||!/\bPLANNED\b/.test(h))throw new Error("chaos-history-invalid");const w=G(t.workspacePath,["ls-tree","-z","HEAD","--",l]).length>0?G(t.workspacePath,["show",`HEAD:${l}`]).toString("utf8"):"";if(w&&!h.startsWith(w))throw new Error("chaos-history-not-append-only");return W(t,n,t.baseSha)}catch{throw new Error("private-execution-project-step-admission-unverified")}const o=r==="sync-openapi"&&e==="sync-openapi-contract-v1"?["docs/architecture/api-contracts.md","docs/api/openapi.yaml"]:r==="tech-debt"&&e==="tech-debt-registry-v1"?[".neocortex/tech-debt-registry.json"]:void 0;if(!o)throw new Error("private-execution-project-step-admission-unverified");try{if(r==="tech-debt"){const s=".neocortex/tech-debt-registry.json";P(t.workspacePath,s);const i=JSON.parse(m(a(t.workspacePath,s),"utf8"));if(!i||typeof i!="object"||Array.isArray(i))throw new Error("registry-invalid");const n=i;if(n.schema_version!==2||n.version!==void 0&&n.version!==2||!Array.isArray(n.items))throw new Error("registry-invalid")}return W(t,o,t.baseSha)}catch{throw new Error("private-execution-project-step-admission-unverified")}}function Nt(t,r){const e=t==="arch-prd"&&r==="arch-prd-docs-v1"?["docs/architecture/prd.md","docs/architecture/product-experience.md"]:t==="arch-architecture"&&r==="arch-architecture-doc-v1"?["docs/architecture/architecture.md"]:t==="arch-fitness-functions"&&r==="arch-fitness-tools-v1"?["tools/architecture/dependency-cruiser.config.js","tools/architecture/archunit-test.ts","tools/architecture/.eslintrc.boundaries.js"]:t==="arch-api-contracts"&&r==="arch-api-contracts-docs-v1"?["docs/architecture/api-contracts.md","docs/api/openapi.yaml"]:t==="arch-api-integrations"&&r==="arch-api-integrations-doc-v1"?["docs/architecture/api-integrations.md"]:t==="arch-database"&&r==="arch-database-doc-v1"?["docs/architecture/database-schema.md"]:t==="arch-security"&&r==="arch-security-doc-v1"?["docs/architecture/cyber-security.md"]:t==="arch-design-system"&&r==="arch-design-system-doc-v1"?["docs/architecture/atomic-design-system.md"]:t==="arch-performance"&&r==="arch-performance-doc-v1"?["docs/architecture/performance-strategy.md"]:t==="arch-testing"&&r==="arch-testing-doc-v1"?["docs/architecture/testing-strategy.md"]:t==="arch-infrastructure"&&r==="arch-infrastructure-doc-v1"?["docs/architecture/infrastructure-deploy.md"]:t==="arch-review"&&r==="arch-review-doc-v1"?["docs/architecture/review-consolidation.md"]:t==="update-memory"&&r==="arch-memory-canonical-v1"?["NEOCORTEX.md"]:null;return e===null?null:Object.freeze(e)}function Be(t,r,e,o="all"){const s=Nt(r,e);if(!s)throw new Error("private-execution-architecture-admission-unverified");return`${t}
|
|
15
15
|
|
|
16
16
|
Private architecture handoff (local only):
|
|
17
|
-
${JSON.stringify({allowedPaths:
|
|
18
|
-
${
|
|
17
|
+
${JSON.stringify({allowedPaths:s})}
|
|
18
|
+
${o==="non-ui"?`The server admitted a signed non-UI scope for this snapshot. Preserve the backend-only scope: design-system and UX phases are not applicable. Do not require or generate interface artifacts.
|
|
19
19
|
`:""}Write exactly the listed nonempty artifacts inside this isolated clone. Existing compliant listed artifacts may remain unchanged; all listed artifacts must exist after execution. Place any necessary scope notes inside those artifacts. Do not edit README, package files, other documents, state, Git, QA records or configuration outside the listed paths. Do not install dependencies, use network, deploy or continue to another stage. Preserve existing arch:keep blocks byte-for-byte. Do not add new arch:keep markers. For managed memory, preserve all bytes outside its existing managed block. Root independently reviews artifacts and owns continuation, Git and acceptance.
|
|
20
|
-
`}function
|
|
20
|
+
`}function Ce(t,r,e,o,s){const i=Nt(r,e);if(!i||!/^P[1-9][0-9]{0,11}$/.test(o)||!/^[a-f0-9]{64}$/.test(s))throw new Error("private-execution-architecture-admission-unverified");try{P(t.workspacePath,".neocortex/state.json");const n=JSON.parse(m(a(t.workspacePath,".neocortex/state.json"),"utf8"));if(!n||typeof n!="object"||Array.isArray(n))throw new Error("state-invalid");const d=n,c=d.archPlan?.execution,f=d.epics;if(!c||c.currentStageCommand!==r||c.targetEpicId!==o||c.graphRevision!==s||!f||!Object.hasOwn(f,o))throw new Error("state-binding-mismatch");if(r==="update-memory"){if(c.continuationState!=="delegate"||c.reviewDecision?.decision!=="approved")throw new Error("memory-root-review-missing");const h="NEOCORTEX.md";if(!M(B(t.workspacePath,!0)).paths.includes(h))throw new Error("memory-effect-missing");P(t.sourceRoot,h),P(t.workspacePath,h);const p=m(a(t.sourceRoot,h),"utf8"),w=m(a(t.workspacePath,h),"utf8"),u="<!-- NEOCORTEX-MEMORY-START -->",g="<!-- NEOCORTEX-MEMORY-END -->",_=y=>{if(y.split(u).length!==2||y.split(g).length!==2||y.indexOf(u)>=y.indexOf(g))throw new Error("memory-markers-invalid");const A=y.indexOf(u)+u.length,x=y.indexOf(g);return{before:y.slice(0,A),body:y.slice(A,x),after:y.slice(x)}},j=_(p),b=_(w);if(j.before!==b.before||j.after!==b.after||j.body===b.body||Buffer.byteLength(w,"utf8")>32768||w.split(`
|
|
21
21
|
`).length>240)throw new Error("memory-managed-block-invalid");const N=new Set(j.body.split(`
|
|
22
22
|
`));for(const y of b.body.split(`
|
|
23
|
-
`))N.has(y)||
|
|
23
|
+
`))N.has(y)||Wt(y)}if(r==="arch-prd"){const h="docs/architecture/prd.md";if(!M(B(t.workspacePath,!0)).paths.includes(h))throw new Error("prd-effect-missing");if(P(t.workspacePath,h),R(a(t.workspacePath,h)).size===0)throw new Error("prd-empty")}if(r==="arch-api-contracts"||r==="arch-fitness-functions"||r==="arch-api-integrations"||r==="arch-database"||r==="arch-security"||r==="arch-design-system"||r==="arch-performance"||r==="arch-testing"||r==="arch-infrastructure"||r==="arch-review"){const h=M(B(t.workspacePath,!0)).paths;for(const p of i){if(!h.includes(p)&&G(t.workspacePath,["cat-file","-t",`${t.baseSha}:${p}`]).toString("utf8").trim()!=="blob")throw new Error("architecture-required-effect-missing");if(P(t.workspacePath,p),R(a(t.workspacePath,p)).size===0)throw new Error("architecture-required-effect-empty");if(r==="arch-fitness-functions"){P(t.sourceRoot,p);const w=nt(a(t.sourceRoot,p))?m(a(t.sourceRoot,p),"utf8"):"",u=m(a(t.workspacePath,p),"utf8"),g=$t(w),_=$t(u);if(!S(_,g))throw new Error("architecture-keep-marker-changed")}}}return W(t,i,t.baseSha)}catch{throw new Error("private-execution-architecture-admission-unverified")}}function ze(t,r,e,o){try{if(!/^P[1-9][0-9]{0,11}$/.test(r)||!/^[a-f0-9]{64}$/.test(e)||o.schemaVersion!==1||o.targetEpicId!==r)throw new Error("binding-invalid");const s=Mt(t.sourceRoot,r),i=Jt(t.workspacePath,r);if(!S(s,o)||!S(i,o))throw new Error("write-set-invalid");P(t.workspacePath,".neocortex/state.json");const n=JSON.parse(m(a(t.workspacePath,".neocortex/state.json"),"utf8"));if(!n||typeof n!="object"||Array.isArray(n))throw new Error("state-invalid");const d=n,c=d.archPlan?.execution,f=d.epics;if(!c||c.currentStageCommand!=="arch-ux-design"||c.continuationState!=="delegate"||c.targetEpicId!==r||c.graphRevision!==e||!f||!Object.hasOwn(f,r))throw new Error("stage-invalid");const h=M(B(t.workspacePath,!0)).paths;if(h.length!==o.pathCount||h.some(p=>!o.paths.includes(p)))throw new Error("agent-path-unclaimed");for(const p of o.paths){P(t.sourceRoot,p),P(t.workspacePath,p);const w=R(a(t.workspacePath,p));if(!w.isFile()||w.isSymbolicLink()||w.size<1)throw new Error("effect-empty");const u=new TextDecoder("utf-8",{fatal:!0}).decode(m(a(t.workspacePath,p)));if(!u.trim()||u.includes("\0"))throw new Error("effect-invalid")}return qt(t.workspacePath,o),W(t,o.paths,t.baseSha)}catch{throw new Error("private-execution-ux-admission-unverified")}}function Le(t,r,e,o,s,i){try{if(!/^P[1-9][0-9]{0,11}$/.test(r)||!/^[a-f0-9]{64}$/.test(e)||o.targetEpicId!==r||o.graphRevision!==e||s.schemaVersion!==1)throw new Error("binding-invalid");const n=Ht(t.sourceRoot);if(!n||!S(n.receipt,o))throw new Error("answers-invalid");const d=xt(t.sourceRoot,n.answers.generateProvider),l=xt(t.workspacePath,n.answers.generateProvider);if(d.outcome!=="ready"||l.outcome!=="ready"||!S(d.writeSet,s)||!S(l.writeSet,s))throw new Error("write-set-invalid");const c=M(B(t.workspacePath,!0)).paths;if(c.some(u=>!s.paths.includes(u)))throw new Error("agent-path-unclaimed");let f=0,h=0;for(const u of s.paths){if(P(t.sourceRoot,u),nt(a(t.sourceRoot,u))||!c.includes(u))throw new Error("effect-missing-or-overwrite");P(t.workspacePath,u);const g=R(a(t.workspacePath,u));if(!g.isFile()||g.size<1)throw new Error("effect-empty");const _=new TextDecoder("utf-8",{fatal:!0}).decode(m(a(t.workspacePath,u))),j=s.interactions.find(N=>N.filePath===u);if(u!==s.providerPath&&!j)throw new Error("private-execution-pact-interaction-missing");const b=Gt(u,_,n.answers.brokerUrl,j,t.workspacePath,n.answers.matchersAggressive);b.consumerBinding==="app-import-candidate"&&f++,b.consumerBinding==="mock-only-scaffold"&&h++}let p=s.paths;if(i){const u=Xt(t.sourceRoot,n.answers.generateProvider),g=_=>F("sha256").update(_).digest("hex");if(i.schemaVersion!==1||i.outcome!=="candidate-unverified"||i.executionVerified!==!1||i.sourceManifestSha256!==g(u.sourceText)||i.sourceLockSha256!==(u.sourceLockText===null?null:g(u.sourceLockText))||i.manifestText!==u.candidateText||!lt(t.sourceRoot,t.workspacePath,t.baseSha,"package.json")||!lt(t.sourceRoot,t.workspacePath,t.baseSha,"package-lock.json"))throw new Error("toolchain-binding-invalid");for(const _ of["package.json","package-lock.json"]){P(t.sourceRoot,_),P(t.workspacePath,_);const j=_==="package.json"?u.sourceText:u.sourceLockText,b=nt(a(t.workspacePath,_))?m(a(t.workspacePath,_),"utf8"):null;if(j!==b)throw new Error("toolchain-clone-raced")}if(mt(a(t.workspacePath,"package.json"),i.manifestText),mt(a(t.workspacePath,"package-lock.json"),i.lockText),Vt(t.workspacePath,n.answers.generateProvider).outcome!=="manifest-aligned")throw new Error("toolchain-candidate-invalid");p=[...s.paths,"package.json","package-lock.json"]}const w=W(t,p,t.baseSha);return Object.freeze({...w,consumerBindingCandidateCount:f,consumerScaffoldCount:h})}catch{throw new Error("private-execution-pact-admission-unverified")}}function He(t,r,e,o=new Date().toISOString()){try{const s=At(t.sourceRoot,r);if(!S(s,e)||!pt(t.sourceRoot,t.workspacePath,e.prdPath)||e.aggregates.some(h=>!pt(t.sourceRoot,t.workspacePath,h.implementationFile))||e.writeSet.length===0)throw new Error("plan-drift");const i=M(B(t.workspacePath,!0)).paths;if(!S(i,e.writeSet))throw new Error("agent-path-unclaimed");const n=new Map;for(const h of e.aggregates){P(t.sourceRoot,h.testFile),P(t.workspacePath,h.testFile);const p=R(a(t.workspacePath,h.testFile));if(!p.isFile()||p.isSymbolicLink()||p.size<1||p.size>Z)throw new Error("test-invalid");const w=m(a(t.workspacePath,h.testFile)),u=new TextDecoder("utf-8",{fatal:!0}).decode(w),g=e.language==="typescript"?(u.match(/\b(?:it|test)\s*\(/g)??[]).length:(u.match(/^def\s+test_[A-Za-z0-9_]+\s*\(/gm)??[]).length;if(!u.trim()||u.includes("\0")||g<h.invariantCount||/\b(?:it|test|describe)\s*\.\s*(?:skip|todo|only)\s*\(/.test(u)||!u.includes(String(e.numRuns)))throw new Error("test-invalid");e.language==="typescript"&&kt({source:u,testFile:h.testFile,implementationFile:h.implementationFile,invariantCount:h.invariantCount,numRuns:e.numRuns}),n.set(h.testFile,F("sha256").update(w).digest("hex"))}P(t.sourceRoot,e.prdPath),P(t.workspacePath,e.prdPath);const d=m(a(t.workspacePath,e.prdPath)),l=new TextDecoder("utf-8",{fatal:!0}).decode(d),c=Qt(l,e,o);mt(a(t.workspacePath,e.prdPath),c);const f=F("sha256").update(c).digest("hex");return W(t,[...e.writeSet,e.prdPath],t.baseSha,void 0,()=>{try{return!S(At(t.sourceRoot,r),e)||e.aggregates.some(h=>!pt(t.sourceRoot,t.workspacePath,h.implementationFile))||F("sha256").update(m(a(t.workspacePath,e.prdPath))).digest("hex")!==f?!1:[...n].every(([h,p])=>F("sha256").update(m(a(t.workspacePath,h))).digest("hex")===p)}catch{return!1}})}catch{throw new Error("private-execution-property-admission-unverified")}}export{Ce as admitPrivateArchitectureStageWorkspace,$e as admitPrivateEpicClaimWorkspace,je as admitPrivateGenerateEpicWorkspace,Oe as admitPrivateIdeaDiagnosisWorkspace,Te as admitPrivateIdeaResearchWorkspace,Le as admitPrivatePactWorkspace,Fe as admitPrivateProjectStepWorkspace,He as admitPrivatePropertyTestWorkspace,De as admitPrivateStateBoundStepWorkspace,ze as admitPrivateUxWorkspace,Se as admitPrivateYoloFrozenWorkspace,Be as appendPrivateArchitectureHandoff,Ne as appendPrivateStateBoundStepHandoff,Nt as privateArchitectureStagePaths,xe as privateYoloSourceFileMatchesSnapshot,Ae as verifyPrivateYoloRejectedCandidateOrigin,Re as verifyPrivateYoloSnapshotBoundary};
|