@ornexus/neocortex 4.60.71 → 4.60.73
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 +1211 -1217
- package/install.ps1 +1 -1
- package/install.sh +1 -1
- package/package.json +2 -2
- package/packages/client/dist/adapters/adapter-registry.js +108 -1
- package/packages/client/dist/adapters/antigravity-adapter.js +77 -2
- package/packages/client/dist/adapters/claude-code-adapter.js +79 -3
- package/packages/client/dist/adapters/codex-adapter.js +80 -2
- package/packages/client/dist/adapters/cursor-adapter.js +115 -4
- package/packages/client/dist/adapters/gemini-adapter.js +71 -2
- package/packages/client/dist/adapters/grok-adapter.js +42 -2
- package/packages/client/dist/adapters/index.js +22 -1
- package/packages/client/dist/adapters/platform-detector.js +212 -1
- package/packages/client/dist/adapters/target-adapter.js +12 -0
- package/packages/client/dist/adapters/vscode-adapter.js +72 -2
- package/packages/client/dist/agent/refresh-stubs.js +417 -2
- package/packages/client/dist/agent/update-agent-yaml.js +102 -1
- package/packages/client/dist/agent/update-description.js +251 -1
- package/packages/client/dist/cache/crypto-utils.js +78 -1
- package/packages/client/dist/cache/encrypted-cache.js +108 -1
- package/packages/client/dist/cache/in-memory-asset-cache.js +73 -1
- package/packages/client/dist/cache/index.js +13 -1
- package/packages/client/dist/cache/protected-pi-boundary.js +44 -1
- package/packages/client/dist/checkpoint/checkpoint-client-reader.js +127 -2
- package/packages/client/dist/checkpoint/index.js +11 -1
- package/packages/client/dist/checkpoint/shared-checkpoint-types.js +32 -1
- package/packages/client/dist/cli.js +358 -5
- package/packages/client/dist/commands/activate.js +394 -8
- package/packages/client/dist/commands/architecture-answers.js +274 -7
- package/packages/client/dist/commands/architecture-memory-terminal.js +253 -4
- package/packages/client/dist/commands/architecture-non-ui-continuation.js +100 -1
- package/packages/client/dist/commands/architecture-root-binding.js +51 -1
- package/packages/client/dist/commands/cache-status.js +112 -2
- package/packages/client/dist/commands/config.js +88 -1
- package/packages/client/dist/commands/doctor.js +635 -2
- package/packages/client/dist/commands/invoke.js +7200 -143
- package/packages/client/dist/commands/legacy-epic-terminal.js +71 -1
- package/packages/client/dist/commands/legacy-story-branch.js +96 -1
- package/packages/client/dist/commands/legacy-story-pr.js +276 -1
- package/packages/client/dist/commands/mutation-qa-checkpoint.js +285 -5
- package/packages/client/dist/commands/mutation-qa-gate.js +54 -1
- package/packages/client/dist/commands/mutation-qa-git.js +41 -1
- package/packages/client/dist/commands/mutation-qa-policy.js +102 -1
- package/packages/client/dist/commands/mutation-qa-run.js +219 -3
- package/packages/client/dist/commands/mutation-qa-verdict.js +149 -1
- package/packages/client/dist/commands/mutation-qa.js +220 -1
- package/packages/client/dist/commands/native-agent.js +136 -2
- package/packages/client/dist/commands/planning-diagnosis.js +43 -1
- package/packages/client/dist/commands/planning-generation.js +53 -1
- package/packages/client/dist/commands/planning-memory.js +40 -1
- package/packages/client/dist/commands/planning-research.js +42 -1
- package/packages/client/dist/commands/private-session.js +75 -1
- package/packages/client/dist/commands/property-qa.js +139 -1
- package/packages/client/dist/commands/qa-control.js +16 -1
- package/packages/client/dist/commands/qa-scan-browser-launch.js +55 -1
- package/packages/client/dist/commands/qa-scan-browser-route.js +28 -1
- package/packages/client/dist/commands/qa-scan-capture.js +663 -5
- package/packages/client/dist/commands/qa-scan-discovery.js +376 -3
- package/packages/client/dist/commands/qa-scan-review.js +826 -5
- package/packages/client/dist/commands/qa-synthetic-backend-capture.js +266 -1
- package/packages/client/dist/commands/qa-synthetic-backend-review.js +297 -1
- package/packages/client/dist/commands/qa-synthetic-backend.js +340 -2
- package/packages/client/dist/commands/qa-synthetic-broker-port.js +85 -1
- package/packages/client/dist/commands/qa-synthetic-browser.js +39 -1
- package/packages/client/dist/commands/refactor-characterization.js +671 -21
- package/packages/client/dist/commands/refactor-commit.js +399 -13
- package/packages/client/dist/commands/refactor-control.js +142 -3
- package/packages/client/dist/commands/refactor-cpp-assertions.js +93 -3
- package/packages/client/dist/commands/refactor-review.js +283 -5
- package/packages/client/dist/commands/refactor-root.js +588 -7
- package/packages/client/dist/commands/refresh-memory.js +156 -3
- package/packages/client/dist/commands/shared-architecture-non-ui.js +24 -1
- package/packages/client/dist/commands/story-checkpoint.js +171 -1
- package/packages/client/dist/config/profile-directory.js +13 -1
- package/packages/client/dist/config/resolver-selection.js +278 -1
- package/packages/client/dist/config/secure-config.js +281 -12
- package/packages/client/dist/config.js +223 -2
- package/packages/client/dist/constants.js +25 -1
- package/packages/client/dist/context/context-collector.js +222 -2
- package/packages/client/dist/context/context-sanitizer.js +145 -1
- package/packages/client/dist/continuity/autonomous-governance.js +285 -1
- package/packages/client/dist/continuity/continuity-client-state-store.js +1587 -1
- package/packages/client/dist/continuity/invoke-hooks.js +129 -1
- package/packages/client/dist/continuity/migrations/001-initial-schema.js +12 -2
- package/packages/client/dist/continuity/migrations/002-processing-output-summary-indexes.js +12 -2
- package/packages/client/dist/continuity/migrations/003-headless-execution-attempts.js +12 -2
- package/packages/client/dist/continuity/migrations/004-outbox-delivery-state.js +12 -2
- package/packages/client/dist/continuity/migrations/005-bounded-headless-queue.js +12 -2
- package/packages/client/dist/continuity/migrations/006-native-agent-dispatches.js +10 -2
- package/packages/client/dist/continuity/native-agent-store.js +69 -1
- package/packages/client/dist/continuity/native-agent-types.js +90 -1
- package/packages/client/dist/continuity/outbox.js +117 -1
- package/packages/client/dist/continuity/runner-bootstrap-policy.js +172 -1
- package/packages/client/dist/continuity/sqlite-store.d.ts +22 -1
- package/packages/client/dist/continuity/sqlite-store.js +2612 -81
- package/packages/client/dist/effects/invoke-effect-gateways.js +62 -1
- package/packages/client/dist/errors/error-messages.js +228 -2
- package/packages/client/dist/errors/frontmatter-diagnostics.js +125 -1
- package/packages/client/dist/evidence/collector.js +347 -1
- package/packages/client/dist/evidence/index.js +1 -1
- package/packages/client/dist/evidence/types.js +2 -0
- package/packages/client/dist/fs/atomic-state-replace.js +152 -1
- package/packages/client/dist/generated/command-registry.generated.js +4076 -1
- package/packages/client/dist/generated/public-projections.generated.js +149 -1
- package/packages/client/dist/git/direct-yolo-c01-retry.js +138 -4
- package/packages/client/dist/git/direct-yolo-checkpoint.js +1234 -4
- package/packages/client/dist/git/epic-operational-state.d.ts +198 -0
- package/packages/client/dist/git/epic-operational-state.js +672 -0
- package/packages/client/dist/git/git-lifecycle-step-ids.js +14 -1
- package/packages/client/dist/git/git-lifecycle-store.d.ts +9 -1
- package/packages/client/dist/git/git-lifecycle-store.js +1981 -9
- package/packages/client/dist/git/legacy-story-branch-checkpoint.js +259 -9
- package/packages/client/dist/git/legacy-story-branch-setup.js +348 -4
- package/packages/client/dist/git/legacy-story-pr.js +3538 -70
- package/packages/client/dist/git/secure-filesystem-boundary.js +182 -5
- package/packages/client/dist/graph-retrieval/pre-command-hook.js +284 -1
- package/packages/client/dist/graph-retrieval/shared-graph-retrieval-contract.js +237 -1
- package/packages/client/dist/i18n/first-run.js +60 -2
- package/packages/client/dist/index.js +47 -1
- package/packages/client/dist/invocation/invoke-input.js +24 -1
- package/packages/client/dist/license/index.js +5 -1
- package/packages/client/dist/license/license-client.js +304 -1
- package/packages/client/dist/machine/fingerprint.js +163 -2
- package/packages/client/dist/machine/index.js +5 -1
- package/packages/client/dist/memory/project-memory-path-scope.js +62 -1
- package/packages/client/dist/memory/project-memory-writer.js +1007 -40
- package/packages/client/dist/memory/shared-project-memory-types.js +253 -2
- package/packages/client/dist/migrations/epic-lifecycle-backfill.d.ts +97 -0
- package/packages/client/dist/migrations/epic-lifecycle-backfill.js +1060 -0
- package/packages/client/dist/migrations/project-identity-capability.js +50 -1
- package/packages/client/dist/migrations/project-identity.js +493 -7
- package/packages/client/dist/migrations/state-json.d.ts +22 -0
- package/packages/client/dist/migrations/state-json.js +393 -4
- package/packages/client/dist/policy/architecture-policy.js +184 -2
- package/packages/client/dist/policy/index.js +7 -1
- package/packages/client/dist/policy/shared-policy-types.js +38 -0
- package/packages/client/dist/policy/subagent-approval-policy.js +55 -1
- package/packages/client/dist/private-execution/clean-baseline.js +279 -2
- package/packages/client/dist/private-execution/codex-executor.js +574 -4
- package/packages/client/dist/private-execution/codex-host-runtime.js +137 -1
- package/packages/client/dist/private-execution/codex-lifecycle-guard.js +97 -1
- package/packages/client/dist/private-execution/codex-scoped-permissions.js +128 -1
- package/packages/client/dist/private-execution/delivery.js +410 -13
- package/packages/client/dist/private-execution/diagnosis-root-review.js +294 -2
- package/packages/client/dist/private-execution/frozen-handoff.js +19 -6
- package/packages/client/dist/private-execution/implementation-validation.js +106 -2
- package/packages/client/dist/private-execution/isolated-admission.js +1432 -23
- package/packages/client/dist/private-execution/isolated-session.js +725 -5
- package/packages/client/dist/private-execution/isolated-workspace.js +122 -1
- package/packages/client/dist/private-execution/pact-consumer-runtime.js +409 -3
- package/packages/client/dist/private-execution/pact-test-source.js +258 -1
- package/packages/client/dist/private-execution/pact-toolchain.js +290 -3
- package/packages/client/dist/private-execution/pact-write-set.js +172 -1
- package/packages/client/dist/private-execution/planning-diagnosis-checkpoint.js +406 -5
- package/packages/client/dist/private-execution/planning-generation-checkpoint.js +462 -5
- package/packages/client/dist/private-execution/planning-memory-checkpoint.js +139 -3
- package/packages/client/dist/private-execution/planning-research-checkpoint.js +325 -4
- package/packages/client/dist/private-execution/private-report-store.js +42 -1
- package/packages/client/dist/private-execution/property-test-candidate.js +103 -1
- package/packages/client/dist/private-execution/property-test-choices.js +147 -3
- package/packages/client/dist/private-execution/property-test-plan.js +271 -7
- package/packages/client/dist/private-execution/property-test-review.js +258 -4
- package/packages/client/dist/private-execution/property-test-runtime.js +372 -9
- package/packages/client/dist/private-execution/property-test-source.js +139 -1
- package/packages/client/dist/private-execution/root-checkpoint.js +80 -1
- package/packages/client/dist/private-execution/root-memory-git-evidence.js +135 -3
- package/packages/client/dist/private-execution/root-memory-recovery.js +93 -1
- package/packages/client/dist/private-execution/root-memory-request.js +29 -1
- package/packages/client/dist/private-execution/root-memory-scope.js +178 -1
- package/packages/client/dist/private-execution/root-memory-writer.js +102 -1
- package/packages/client/dist/private-execution/session-lease.js +63 -1
- package/packages/client/dist/private-execution/shared-private-admission-types.js +50 -1
- package/packages/client/dist/private-execution/shared-project-validation.js +66 -1
- package/packages/client/dist/private-execution/shared-root-memory-types.js +61 -1
- package/packages/client/dist/private-execution/ux-source-validation.js +372 -1
- package/packages/client/dist/private-execution/ux-write-set.js +191 -2
- package/packages/client/dist/registry/registry-reconciliation.js +234 -1
- package/packages/client/dist/resilience/circuit-breaker.js +170 -1
- package/packages/client/dist/resilience/degradation-manager.js +164 -1
- package/packages/client/dist/resilience/freshness-indicator.js +100 -1
- package/packages/client/dist/resilience/index.js +8 -1
- package/packages/client/dist/resilience/recovery-detector.js +74 -1
- package/packages/client/dist/resolvers/asset-resolver.js +13 -0
- package/packages/client/dist/resolvers/local-resolver.js +255 -8
- package/packages/client/dist/resolvers/remote-resolver.js +233 -1
- package/packages/client/dist/runner/binary.js +404 -1
- package/packages/client/dist/runner/cli.js +1571 -17
- package/packages/client/dist/runner/headless/adapters.js +49 -1
- package/packages/client/dist/runner/headless/claude-code-adapter.js +79 -1
- package/packages/client/dist/runner/headless/continuous-story-workspace.js +1628 -11
- package/packages/client/dist/runner/headless/epic-git-reconciliation-inventory.js +69 -1
- package/packages/client/dist/runner/headless/epic-merge-candidate-qa.js +110 -2
- package/packages/client/dist/runner/headless/epic-terminal-git-cli-adapter.js +1236 -8
- package/packages/client/dist/runner/headless/epic-terminal-git-runner.js +318 -2
- package/packages/client/dist/runner/headless/fake-adapter.js +62 -1
- package/packages/client/dist/runner/headless/managed-profile.js +132 -1
- package/packages/client/dist/runner/headless/opencode-adapter.js +145 -2
- package/packages/client/dist/runner/headless/prepared-story-bundle.js +43 -1
- package/packages/client/dist/runner/headless/resolver.js +231 -1
- package/packages/client/dist/runner/headless/run-yolo.js +885 -1
- package/packages/client/dist/runner/headless/run-yoloop.js +2574 -2
- package/packages/client/dist/runner/headless/types.js +574 -2
- package/packages/client/dist/runner/local-console.js +396 -13
- package/packages/client/dist/runner/portal-sync-worker.js +1487 -1
- package/packages/client/dist/runner/project-identity.js +106 -1
- package/packages/client/dist/runner/scheduler.js +995 -7
- package/packages/client/dist/runner-cli.js +18 -2
- package/packages/client/dist/state/invocation-shape.js +13 -1
- package/packages/client/dist/state/project-state-snapshot.d.ts +8 -0
- package/packages/client/dist/state/project-state-snapshot.js +1731 -1
- package/packages/client/dist/state/state-json-repair.js +785 -3
- package/packages/client/dist/state/structural-dag-projection.js +118 -1
- package/packages/client/dist/telemetry/index.js +5 -1
- package/packages/client/dist/telemetry/offline-queue.js +131 -1
- package/packages/client/dist/tier/index.js +5 -1
- package/packages/client/dist/tier/tier-aware-client.js +405 -1
- package/packages/client/dist/types/index.js +38 -1
- package/packages/client/dist/version.js +27 -1
- package/packages/client/dist/yolo/change-evidence-collector.js +126 -1
- package/packages/client/dist/yolo/invoke-envelope-capability.js +62 -1
- package/packages/client/dist/yolo/spec-envelope-collector.js +184 -5
- package/packages/client/dist/yoloop/discovery-hook.js +300 -2
- package/packages/client/dist/yoloop/index.js +8 -1
- package/packages/client/dist/yoloop/invoke-hooks.js +669 -12
- package/packages/client/dist/yoloop/shared-discover-epics.js +1007 -1
- package/packages/client/dist/yoloop/shared-yoloop-types.d.ts +65 -1
- package/packages/client/dist/yoloop/shared-yoloop-types.js +33 -1
- package/packages/client/dist/yoloop/target-normalization.js +180 -1
- package/packages/client/dist/yoloop/yoloop-client-state-store.d.ts +8 -0
- package/packages/client/dist/yoloop/yoloop-client-state-store.js +1920 -1
- package/packages/shared/dist/yolo/spec-envelope.js +3 -6
- package/targets-stubs/antigravity/gemini.md +1 -1
- package/targets-stubs/antigravity/skill/SKILL.md +1 -1
- package/targets-stubs/claude-code/neocortex-root.agent.yaml +1 -1
- package/targets-stubs/claude-code/neocortex-root.md +2 -2
- package/targets-stubs/claude-code/neocortex.agent.yaml +1 -1
- package/targets-stubs/claude-code/neocortex.md +2 -2
- package/targets-stubs/codex/AGENTS.md +1 -1
- package/targets-stubs/cursor/agent.md +2 -2
- package/targets-stubs/gemini-cli/agent.md +2 -2
- package/targets-stubs/opencode/neocortex-root.md +1 -1
- package/targets-stubs/vscode/neocortex.agent.md +2 -2
|
@@ -1 +1,137 @@
|
|
|
1
|
-
import{startPrivateCodexHomeGuard
|
|
1
|
+
import { startPrivateCodexHomeGuard } from './codex-lifecycle-guard.js';
|
|
2
|
+
/** Host control state for one subscription execution. Never a QA checkout or image. */
|
|
3
|
+
import { createHash } from 'node:crypto';
|
|
4
|
+
import { closeSync, constants, fstatSync, lstatSync, mkdtempSync, openSync, readFileSync, realpathSync, rmSync, writeFileSync } from 'node:fs';
|
|
5
|
+
import { isAbsolute, join, relative } from 'node:path';
|
|
6
|
+
const digest = (bytes) => createHash('sha256').update(bytes).digest('hex');
|
|
7
|
+
const liveRuntimes = new Set();
|
|
8
|
+
let exitCleanupInstalled = false;
|
|
9
|
+
function fail() { throw new Error('private-codex-host-runtime-unverified'); }
|
|
10
|
+
function readFile(path, credential) {
|
|
11
|
+
const fd = openSync(path, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
|
|
12
|
+
try {
|
|
13
|
+
const before = fstatSync(fd);
|
|
14
|
+
if (!before.isFile() || before.uid !== process.getuid?.() || before.nlink !== 1
|
|
15
|
+
|| before.mode & 0o022 || credential && (before.mode & 0o777) !== 0o600
|
|
16
|
+
|| before.size < 1 || before.size > 1048576)
|
|
17
|
+
fail();
|
|
18
|
+
const bytes = readFileSync(fd), after = fstatSync(fd), current = lstatSync(path);
|
|
19
|
+
if (bytes.length !== before.size || [after, current].some(s => s.dev !== before.dev || s.ino !== before.ino
|
|
20
|
+
|| s.size !== before.size || s.mtimeMs !== before.mtimeMs || s.ctimeMs !== before.ctimeMs
|
|
21
|
+
|| s.mode !== before.mode || s.nlink !== 1))
|
|
22
|
+
fail();
|
|
23
|
+
return bytes;
|
|
24
|
+
}
|
|
25
|
+
finally {
|
|
26
|
+
closeSync(fd);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/** The CLI may record project trust in its own configuration. Keep that write in
|
|
30
|
+
* short-lived, owner-private host control storage using the existing account.
|
|
31
|
+
* No credential is placed in, mounted into or passed to the model checkout. */
|
|
32
|
+
export function createPrivateCodexHostRuntime(projectRoot, sourceHome) {
|
|
33
|
+
try {
|
|
34
|
+
const root = realpathSync(projectRoot), source = realpathSync(sourceHome), relation = relative(root, source);
|
|
35
|
+
const parent = lstatSync(source);
|
|
36
|
+
if (!relation || !relation.startsWith('..') && !isAbsolute(relation)
|
|
37
|
+
|| !parent.isDirectory() || parent.uid !== process.getuid?.() || parent.mode & 0o022)
|
|
38
|
+
fail();
|
|
39
|
+
const auth = readFile(join(source, 'auth.json'), true);
|
|
40
|
+
let config;
|
|
41
|
+
try {
|
|
42
|
+
config = readFile(join(source, 'config.toml'), false);
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
if (error.code !== 'ENOENT')
|
|
46
|
+
throw error;
|
|
47
|
+
}
|
|
48
|
+
const authDigest = digest(auth), configDigest = config ? digest(config) : undefined;
|
|
49
|
+
const home = mkdtempSync(join(source, '.neocortex-executor-')), identity = lstatSync(home);
|
|
50
|
+
const guard = process.platform === 'linux' ? startPrivateCodexHomeGuard(home) : undefined;
|
|
51
|
+
let closed = false;
|
|
52
|
+
const custody = () => {
|
|
53
|
+
const current = lstatSync(home), directory = lstatSync(source);
|
|
54
|
+
if (realpathSync(source) !== source || directory.dev !== parent.dev || directory.ino !== parent.ino
|
|
55
|
+
|| directory.uid !== parent.uid || directory.mode & 0o022 || current.dev !== identity.dev || current.ino !== identity.ino
|
|
56
|
+
|| current.uid !== process.getuid?.() || (current.mode & 0o777) !== 0o700 || !current.isDirectory()
|
|
57
|
+
|| current.isSymbolicLink())
|
|
58
|
+
fail();
|
|
59
|
+
};
|
|
60
|
+
let runtime;
|
|
61
|
+
const close = () => {
|
|
62
|
+
if (closed)
|
|
63
|
+
return;
|
|
64
|
+
try {
|
|
65
|
+
custody();
|
|
66
|
+
rmSync(home, { recursive: true });
|
|
67
|
+
closed = true;
|
|
68
|
+
if (runtime)
|
|
69
|
+
liveRuntimes.delete(runtime);
|
|
70
|
+
if (guard?.connected)
|
|
71
|
+
guard.disconnect();
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
fail();
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
try {
|
|
78
|
+
writeFileSync(join(home, 'auth.json'), auth, { mode: 0o600, flag: 'wx' });
|
|
79
|
+
if (config)
|
|
80
|
+
writeFileSync(join(home, 'config.toml'), config, { mode: 0o600, flag: 'wx' });
|
|
81
|
+
auth.fill(0);
|
|
82
|
+
config?.fill(0);
|
|
83
|
+
const verify = () => {
|
|
84
|
+
try {
|
|
85
|
+
if (closed || guard && (!guard.connected || guard.exitCode !== null || guard.signalCode !== null))
|
|
86
|
+
fail();
|
|
87
|
+
custody();
|
|
88
|
+
if (digest(readFile(join(source, 'auth.json'), true)) !== authDigest)
|
|
89
|
+
fail();
|
|
90
|
+
let current;
|
|
91
|
+
try {
|
|
92
|
+
current = readFile(join(source, 'config.toml'), false);
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
if (error.code !== 'ENOENT')
|
|
96
|
+
throw error;
|
|
97
|
+
}
|
|
98
|
+
if ((current ? digest(current) : undefined) !== configDigest)
|
|
99
|
+
fail();
|
|
100
|
+
readFile(join(home, 'auth.json'), true);
|
|
101
|
+
try {
|
|
102
|
+
readFile(join(home, 'config.toml'), true);
|
|
103
|
+
}
|
|
104
|
+
catch (error) {
|
|
105
|
+
if (error.code !== 'ENOENT')
|
|
106
|
+
throw error;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
fail();
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
verify();
|
|
114
|
+
runtime = Object.freeze({ home, sourceHome: source, verify, close });
|
|
115
|
+
liveRuntimes.add(runtime);
|
|
116
|
+
if (!exitCleanupInstalled) {
|
|
117
|
+
exitCleanupInstalled = true;
|
|
118
|
+
process.once('exit', () => {
|
|
119
|
+
for (const pending of liveRuntimes) {
|
|
120
|
+
try {
|
|
121
|
+
pending.close();
|
|
122
|
+
}
|
|
123
|
+
catch { /* Preserve a directory whose custody became ambiguous. */ }
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
return runtime;
|
|
128
|
+
}
|
|
129
|
+
catch (error) {
|
|
130
|
+
close();
|
|
131
|
+
throw error;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
catch {
|
|
135
|
+
fail();
|
|
136
|
+
}
|
|
137
|
+
}
|
|
@@ -1 +1,97 @@
|
|
|
1
|
-
|
|
1
|
+
/** Mechanical Linux process/custody lifetime; no workflow material or authority. */
|
|
2
|
+
import { spawn } from 'node:child_process';
|
|
3
|
+
import { lstatSync, realpathSync, rmSync } from 'node:fs';
|
|
4
|
+
import { basename } from 'node:path';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
// Source-driven development tests launch the same compiled helper as the CLI.
|
|
7
|
+
export const codexLifecycleGuardPath = fileURLToPath(new URL(import.meta.url.endsWith('.ts')
|
|
8
|
+
? '../../dist/private-execution/codex-lifecycle-guard.js' : './codex-lifecycle-guard.js', import.meta.url));
|
|
9
|
+
export function startPrivateCodexHomeGuard(home) {
|
|
10
|
+
const identity = lstatSync(home);
|
|
11
|
+
const guard = spawn(process.execPath, [codexLifecycleGuardPath, 'home', home, String(identity.dev), String(identity.ino)], {
|
|
12
|
+
detached: true, env: {}, stdio: ['ignore', 'ignore', 'ignore', 'ipc'],
|
|
13
|
+
});
|
|
14
|
+
// A failed guard is observed by runtime.verify(); never print host paths.
|
|
15
|
+
guard.on('error', () => undefined);
|
|
16
|
+
guard.unref();
|
|
17
|
+
guard.channel?.unref();
|
|
18
|
+
return guard;
|
|
19
|
+
}
|
|
20
|
+
function stopOwnGroup() {
|
|
21
|
+
// This process remains the group leader until this syscall: no stale PID kill.
|
|
22
|
+
process.kill(-process.pid, 'SIGKILL');
|
|
23
|
+
process.exit(1);
|
|
24
|
+
}
|
|
25
|
+
function homeGuard() {
|
|
26
|
+
const [home, dev, ino] = process.argv.slice(3);
|
|
27
|
+
let handled = false;
|
|
28
|
+
const close = () => {
|
|
29
|
+
if (handled)
|
|
30
|
+
return;
|
|
31
|
+
handled = true;
|
|
32
|
+
try {
|
|
33
|
+
if (!home || !basename(home).startsWith('.neocortex-executor-'))
|
|
34
|
+
throw new Error();
|
|
35
|
+
const identity = lstatSync(home);
|
|
36
|
+
if (realpathSync(home) !== home || !identity.isDirectory() || identity.isSymbolicLink()
|
|
37
|
+
|| identity.uid !== process.getuid?.() || (identity.mode & 0o777) !== 0o700
|
|
38
|
+
|| String(identity.dev) !== dev || String(identity.ino) !== ino)
|
|
39
|
+
throw new Error();
|
|
40
|
+
rmSync(home, { recursive: true });
|
|
41
|
+
process.exit(0);
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
// Missing means the root already closed it. Ambiguous custody is retained.
|
|
45
|
+
process.exit(error.code === 'ENOENT' ? 0 : 1);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
process.on('disconnect', close);
|
|
49
|
+
if (!process.connected)
|
|
50
|
+
close();
|
|
51
|
+
}
|
|
52
|
+
function processGuard() {
|
|
53
|
+
process.on('disconnect', stopOwnGroup);
|
|
54
|
+
process.on('SIGTERM', stopOwnGroup);
|
|
55
|
+
process.on('SIGINT', stopOwnGroup);
|
|
56
|
+
process.stdout.on('error', stopOwnGroup);
|
|
57
|
+
process.stderr.on('error', stopOwnGroup);
|
|
58
|
+
if (!process.connected)
|
|
59
|
+
stopOwnGroup();
|
|
60
|
+
process.once('message', (value) => {
|
|
61
|
+
const input = value;
|
|
62
|
+
if (!input || input.kind !== 'private-codex-launch' || !Array.isArray(input.args)
|
|
63
|
+
|| input.args.some(arg => typeof arg !== 'string')
|
|
64
|
+
|| input.codexHome !== undefined && typeof input.codexHome !== 'string')
|
|
65
|
+
stopOwnGroup();
|
|
66
|
+
const args = input.args;
|
|
67
|
+
const child = spawn(input.codexHome === undefined ? 'codex' : '/bin/sh', input.codexHome === undefined
|
|
68
|
+
? args : ['-c', 'umask 077; exec codex "$@"', 'neocortex-private-codex', ...args], {
|
|
69
|
+
cwd: process.cwd(), env: Object.fromEntries(['PATH', 'HOME', 'LANG', 'LC_ALL', 'TERM', 'CODEX_HOME']
|
|
70
|
+
.filter(key => process.env[key] !== undefined).map(key => [key, process.env[key]])),
|
|
71
|
+
detached: false, stdio: ['pipe', 'pipe', 'pipe'],
|
|
72
|
+
});
|
|
73
|
+
process.stdin.pipe(child.stdin);
|
|
74
|
+
child.stdin.on('error', () => undefined);
|
|
75
|
+
child.stdout.pipe(process.stdout);
|
|
76
|
+
child.stderr.pipe(process.stderr);
|
|
77
|
+
child.on('error', stopOwnGroup);
|
|
78
|
+
child.on('close', code => {
|
|
79
|
+
// close waits for inherited pipes, retaining this live group anchor.
|
|
80
|
+
process.stdin.unpipe(child.stdin);
|
|
81
|
+
process.stdin.pause();
|
|
82
|
+
process.removeListener('disconnect', stopOwnGroup);
|
|
83
|
+
if (process.connected)
|
|
84
|
+
process.disconnect?.();
|
|
85
|
+
// Natural exit drains forwarded stdout/stderr before the root reads close.
|
|
86
|
+
process.exitCode = typeof code === 'number' ? code : 1;
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
if (process.argv[1] === codexLifecycleGuardPath && process.platform === 'linux') {
|
|
91
|
+
if (process.argv[2] === 'home')
|
|
92
|
+
homeGuard();
|
|
93
|
+
else if (process.argv[2] === 'process')
|
|
94
|
+
processGuard();
|
|
95
|
+
else
|
|
96
|
+
process.exit(1);
|
|
97
|
+
}
|
|
@@ -1 +1,128 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { randomBytes } from 'node:crypto';
|
|
2
|
+
import { accessSync, constants, lstatSync, readdirSync, realpathSync } from 'node:fs';
|
|
3
|
+
import { homedir } from 'node:os';
|
|
4
|
+
import { createRequire } from 'node:module';
|
|
5
|
+
import { basename, delimiter, dirname, join, resolve, sep } from 'node:path';
|
|
6
|
+
import { gitLifecycleRuntimeDirectory } from '../git/git-lifecycle-store.js';
|
|
7
|
+
/** SDK state shares the Git control directory but is not model-readable Git metadata. */
|
|
8
|
+
function rootOwnedGitStores(directories) {
|
|
9
|
+
const paths = new Set();
|
|
10
|
+
for (const directory of directories) {
|
|
11
|
+
const control = lstatSync(directory);
|
|
12
|
+
if (!control.isDirectory() || control.isSymbolicLink() || realpathSync(directory) !== directory) {
|
|
13
|
+
throw new Error('private-codex-root-state-isolation-unproven');
|
|
14
|
+
}
|
|
15
|
+
for (const name of readdirSync(directory)) {
|
|
16
|
+
if (!name.startsWith('neocortex-'))
|
|
17
|
+
continue;
|
|
18
|
+
const path = join(directory, name), entry = lstatSync(path);
|
|
19
|
+
if (!/^[A-Za-z0-9._-]{1,128}$/.test(name) || entry.isSymbolicLink()
|
|
20
|
+
|| !entry.isDirectory() && !entry.isFile())
|
|
21
|
+
throw new Error('private-codex-root-state-isolation-unproven');
|
|
22
|
+
paths.add(path);
|
|
23
|
+
if (paths.size > 64)
|
|
24
|
+
throw new Error('private-codex-root-state-isolation-unproven');
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return [...paths].sort();
|
|
28
|
+
}
|
|
29
|
+
function executableReadRoots() {
|
|
30
|
+
for (const directory of (process.env.PATH ?? '').split(delimiter).filter(Boolean)) {
|
|
31
|
+
try {
|
|
32
|
+
const executable = realpathSync(join(directory, 'codex'));
|
|
33
|
+
accessSync(executable, constants.X_OK);
|
|
34
|
+
if (!lstatSync(executable).isFile())
|
|
35
|
+
continue;
|
|
36
|
+
if (basename(executable) !== 'codex.js' || basename(dirname(executable)) !== 'bin')
|
|
37
|
+
return [dirname(executable)];
|
|
38
|
+
const roots = [dirname(dirname(executable))];
|
|
39
|
+
const platformPackage = process.arch === 'x64' ? '@openai/codex-linux-x64'
|
|
40
|
+
: process.arch === 'arm64' ? '@openai/codex-linux-arm64' : undefined;
|
|
41
|
+
if (platformPackage) {
|
|
42
|
+
try {
|
|
43
|
+
roots.push(realpathSync(dirname(createRequire(executable).resolve(`${platformPackage}/package.json`))));
|
|
44
|
+
}
|
|
45
|
+
catch { /* Older installations keep the native executable in the CLI package. */ }
|
|
46
|
+
}
|
|
47
|
+
return [...new Set(roots)];
|
|
48
|
+
}
|
|
49
|
+
catch { /* Continue searching the same executable path used by spawn. */ }
|
|
50
|
+
}
|
|
51
|
+
throw new Error('private-codex-version-unavailable');
|
|
52
|
+
}
|
|
53
|
+
/** Per-invocation permissions; never modifies the operator's configuration. */
|
|
54
|
+
export async function createPrivateCodexScopedRunner(projectRoot, base, options) {
|
|
55
|
+
const root = realpathSync(resolve(projectRoot));
|
|
56
|
+
const controlDirectories = Object.freeze([...options.gitControlDirectories]);
|
|
57
|
+
const userHome = options.userHome ?? homedir();
|
|
58
|
+
const codexHome = options.codexHome ?? process.env.CODEX_HOME ?? join(userHome, '.codex');
|
|
59
|
+
const binaryRoots = executableReadRoots();
|
|
60
|
+
if (binaryRoots.some((path) => [sep, resolve(userHome), resolve(codexHome), root].includes(path)
|
|
61
|
+
|| path.startsWith(root + sep)))
|
|
62
|
+
throw new Error('private-codex-executable-scope-unsafe');
|
|
63
|
+
const lifecycle = await gitLifecycleRuntimeDirectory(root);
|
|
64
|
+
const stores = rootOwnedGitStores(controlDirectories);
|
|
65
|
+
const filesystem = {
|
|
66
|
+
':root': 'deny', ':minimal': 'read', [root]: 'write',
|
|
67
|
+
[join(userHome, '.ssh')]: 'deny', [join(codexHome, 'auth.json')]: 'deny',
|
|
68
|
+
};
|
|
69
|
+
if (options.credentialSourceHome) {
|
|
70
|
+
const sourceHome = resolve(options.credentialSourceHome), privateHome = resolve(codexHome);
|
|
71
|
+
filesystem[sourceHome] = 'deny';
|
|
72
|
+
if (privateHome !== sourceHome && !privateHome.startsWith(sourceHome + sep))
|
|
73
|
+
filesystem[privateHome] = 'deny';
|
|
74
|
+
// A denied ancestor covers the credential file. A second bind beneath an
|
|
75
|
+
// already denied directory cannot be created by the Linux sandbox.
|
|
76
|
+
delete filesystem[join(codexHome, 'auth.json')];
|
|
77
|
+
}
|
|
78
|
+
for (const directory of binaryRoots)
|
|
79
|
+
filesystem[directory] = 'read';
|
|
80
|
+
for (const directory of controlDirectories)
|
|
81
|
+
filesystem[directory] = 'read';
|
|
82
|
+
// Linked worktrees also have a .git control file inside the writable checkout.
|
|
83
|
+
filesystem[join(root, '.git')] = 'read';
|
|
84
|
+
filesystem[lifecycle] = 'deny';
|
|
85
|
+
for (const path of stores)
|
|
86
|
+
filesystem[path] = 'deny';
|
|
87
|
+
const profile = `p222-isolated-${randomBytes(16).toString('hex')}`;
|
|
88
|
+
const configuration = `permissions.${profile}={filesystem={${Object.entries(filesystem)
|
|
89
|
+
.map(([path, mode]) => `${JSON.stringify(path)}=${JSON.stringify(mode)}`).join(',')}},network={enabled=false}}`;
|
|
90
|
+
return async (args, runOptions) => {
|
|
91
|
+
if (realpathSync(resolve(runOptions.cwd)) !== root)
|
|
92
|
+
throw new Error('private-codex-execution-root-drift');
|
|
93
|
+
if (JSON.stringify(rootOwnedGitStores(controlDirectories)) !== JSON.stringify(stores)) {
|
|
94
|
+
throw new Error('private-codex-root-state-isolation-unproven');
|
|
95
|
+
}
|
|
96
|
+
if (args[0] !== 'sandbox' && args[0] !== 'exec')
|
|
97
|
+
return base(args, runOptions);
|
|
98
|
+
const scoped = [...args];
|
|
99
|
+
if (args[0] === 'sandbox') {
|
|
100
|
+
if (args[1] !== '-P' || args[2] !== 'p222-isolated')
|
|
101
|
+
throw new Error('private-codex-permission-profile-invalid');
|
|
102
|
+
scoped[2] = profile;
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
const index = scoped.findIndex((arg, i) => arg === 'default_permissions="p222-isolated"' && scoped[i - 1] === '-c');
|
|
106
|
+
if (index < 0)
|
|
107
|
+
throw new Error('private-codex-permission-profile-invalid');
|
|
108
|
+
scoped[index] = `default_permissions="${profile}"`;
|
|
109
|
+
// Prove every currently registered private SDK store is unreadable at
|
|
110
|
+
// the material boundary. Probes receive no model material on stdin.
|
|
111
|
+
for (const path of stores) {
|
|
112
|
+
const probe = await base(['-c', configuration, 'sandbox', '-P', profile,
|
|
113
|
+
'--', 'sh', '-c', 'test ! -r "$1"', 'sh', path], {
|
|
114
|
+
cwd: root, timeoutMs: 10000, maxOutputBytes: 16384,
|
|
115
|
+
});
|
|
116
|
+
if (probe.exitCode !== 0 || probe.timedOut || probe.outputExceeded
|
|
117
|
+
|| JSON.stringify(rootOwnedGitStores(controlDirectories)) !== JSON.stringify(stores)) {
|
|
118
|
+
throw new Error('private-codex-root-state-isolation-unproven');
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
// exec owns its own -c parser. Keep the profile in the same override set
|
|
123
|
+
// as default_permissions; a root-level override can be shadowed there.
|
|
124
|
+
return base(args[0] === 'exec'
|
|
125
|
+
? ['exec', '-c', configuration, ...scoped.slice(1)]
|
|
126
|
+
: ['-c', configuration, ...scoped], runOptions);
|
|
127
|
+
};
|
|
128
|
+
}
|