@ornexus/neocortex 4.61.5 → 4.61.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/release-source.json +1 -1
- package/dist/sbom.cdx.json +1193 -1193
- package/install.ps1 +1 -1
- package/install.sh +1 -1
- package/package.json +2 -2
- package/packages/client/dist/adapters/adapter-registry.js +1 -108
- package/packages/client/dist/adapters/antigravity-adapter.js +2 -77
- package/packages/client/dist/adapters/claude-code-adapter.js +3 -79
- package/packages/client/dist/adapters/codex-adapter.js +2 -80
- package/packages/client/dist/adapters/cursor-adapter.js +4 -115
- package/packages/client/dist/adapters/gemini-adapter.js +2 -71
- package/packages/client/dist/adapters/grok-adapter.js +2 -42
- package/packages/client/dist/adapters/index.js +1 -22
- package/packages/client/dist/adapters/platform-detector.js +1 -220
- package/packages/client/dist/adapters/target-adapter.js +0 -12
- package/packages/client/dist/adapters/vscode-adapter.js +2 -72
- package/packages/client/dist/agent/refresh-stubs.js +2 -443
- package/packages/client/dist/agent/update-agent-yaml.js +1 -102
- package/packages/client/dist/agent/update-description.js +1 -260
- package/packages/client/dist/cache/crypto-utils.js +1 -78
- package/packages/client/dist/cache/encrypted-cache.js +1 -338
- package/packages/client/dist/cache/in-memory-asset-cache.js +1 -73
- package/packages/client/dist/cache/index.js +1 -13
- package/packages/client/dist/cache/protected-pi-boundary.js +1 -44
- package/packages/client/dist/checkpoint/checkpoint-client-reader.js +2 -127
- package/packages/client/dist/checkpoint/index.js +1 -11
- package/packages/client/dist/checkpoint/shared-checkpoint-types.js +1 -32
- package/packages/client/dist/cli.js +5 -364
- package/packages/client/dist/commands/activate.js +8 -394
- package/packages/client/dist/commands/architecture-answers.js +7 -274
- package/packages/client/dist/commands/architecture-memory-terminal.js +4 -253
- package/packages/client/dist/commands/architecture-non-ui-continuation.js +1 -100
- package/packages/client/dist/commands/architecture-root-binding.js +1 -51
- package/packages/client/dist/commands/cache-status.js +2 -112
- package/packages/client/dist/commands/config.js +1 -88
- package/packages/client/dist/commands/doctor.js +2 -635
- package/packages/client/dist/commands/invoke.js +148 -7822
- package/packages/client/dist/commands/legacy-epic-terminal.js +1 -71
- package/packages/client/dist/commands/legacy-story-branch.js +1 -96
- package/packages/client/dist/commands/legacy-story-pr.js +1 -276
- package/packages/client/dist/commands/mutation-qa-checkpoint.js +5 -285
- package/packages/client/dist/commands/mutation-qa-gate.js +1 -54
- package/packages/client/dist/commands/mutation-qa-git.js +1 -41
- package/packages/client/dist/commands/mutation-qa-policy.js +1 -102
- package/packages/client/dist/commands/mutation-qa-run.js +3 -219
- package/packages/client/dist/commands/mutation-qa-verdict.js +1 -149
- package/packages/client/dist/commands/mutation-qa.js +1 -220
- package/packages/client/dist/commands/native-agent.js +2 -136
- package/packages/client/dist/commands/planning-diagnosis.js +1 -43
- package/packages/client/dist/commands/planning-generation.js +1 -53
- package/packages/client/dist/commands/planning-memory.js +1 -40
- package/packages/client/dist/commands/planning-research.js +1 -42
- package/packages/client/dist/commands/private-session.js +1 -75
- package/packages/client/dist/commands/property-qa.js +1 -139
- package/packages/client/dist/commands/qa-control.js +1 -16
- package/packages/client/dist/commands/qa-scan-browser-launch.js +1 -55
- package/packages/client/dist/commands/qa-scan-browser-route.js +1 -28
- package/packages/client/dist/commands/qa-scan-capture.js +5 -663
- package/packages/client/dist/commands/qa-scan-discovery.js +3 -376
- package/packages/client/dist/commands/qa-scan-review.js +5 -826
- package/packages/client/dist/commands/qa-synthetic-backend-capture.js +1 -266
- package/packages/client/dist/commands/qa-synthetic-backend-review.js +1 -297
- package/packages/client/dist/commands/qa-synthetic-backend.js +2 -340
- package/packages/client/dist/commands/qa-synthetic-broker-port.js +1 -85
- package/packages/client/dist/commands/qa-synthetic-browser.js +1 -39
- package/packages/client/dist/commands/refactor-characterization.js +21 -671
- package/packages/client/dist/commands/refactor-commit.js +13 -399
- package/packages/client/dist/commands/refactor-control.js +3 -142
- package/packages/client/dist/commands/refactor-cpp-assertions.js +3 -93
- package/packages/client/dist/commands/refactor-review.js +5 -283
- package/packages/client/dist/commands/refactor-root.js +7 -588
- package/packages/client/dist/commands/refresh-memory.js +3 -174
- package/packages/client/dist/commands/shared-architecture-non-ui.js +1 -24
- package/packages/client/dist/commands/story-checkpoint.d.ts +5 -1
- package/packages/client/dist/commands/story-checkpoint.js +1 -203
- package/packages/client/dist/commands/story-worktree.js +5 -258
- package/packages/client/dist/config/host-auth-broker.js +1 -60
- package/packages/client/dist/config/host-auth-reference.js +1 -93
- package/packages/client/dist/config/profile-directory.js +1 -13
- package/packages/client/dist/config/resolver-selection.js +1 -278
- package/packages/client/dist/config/secure-config.js +12 -281
- package/packages/client/dist/config.js +2 -224
- package/packages/client/dist/constants.js +1 -25
- package/packages/client/dist/context/context-collector.js +2 -222
- package/packages/client/dist/context/context-sanitizer.js +1 -145
- package/packages/client/dist/continuity/autonomous-governance.js +1 -285
- package/packages/client/dist/continuity/continuity-client-state-store.js +1 -1587
- package/packages/client/dist/continuity/invoke-hooks.js +1 -129
- package/packages/client/dist/continuity/migrations/001-initial-schema.js +2 -12
- package/packages/client/dist/continuity/migrations/002-processing-output-summary-indexes.js +2 -12
- package/packages/client/dist/continuity/migrations/003-headless-execution-attempts.js +2 -12
- package/packages/client/dist/continuity/migrations/004-outbox-delivery-state.js +2 -12
- package/packages/client/dist/continuity/migrations/005-bounded-headless-queue.js +2 -12
- package/packages/client/dist/continuity/migrations/006-native-agent-dispatches.js +2 -10
- package/packages/client/dist/continuity/native-agent-store.js +1 -69
- package/packages/client/dist/continuity/native-agent-types.js +1 -105
- package/packages/client/dist/continuity/outbox.js +1 -117
- package/packages/client/dist/continuity/runner-bootstrap-policy.js +1 -172
- package/packages/client/dist/continuity/sqlite-store.js +81 -2612
- package/packages/client/dist/effects/invoke-effect-gateways.js +1 -62
- package/packages/client/dist/errors/error-messages.js +2 -258
- package/packages/client/dist/errors/frontmatter-diagnostics.js +1 -125
- package/packages/client/dist/evidence/collector.js +1 -347
- package/packages/client/dist/evidence/index.js +1 -1
- package/packages/client/dist/evidence/types.js +0 -2
- package/packages/client/dist/fs/atomic-state-replace.js +1 -152
- package/packages/client/dist/generated/command-registry.generated.js +1 -4076
- package/packages/client/dist/generated/public-projections.generated.js +1 -149
- package/packages/client/dist/git/direct-yolo-c01-retry.js +4 -138
- package/packages/client/dist/git/direct-yolo-checkpoint.d.ts +70 -0
- package/packages/client/dist/git/direct-yolo-checkpoint.js +4 -1592
- package/packages/client/dist/git/epic-operational-state.js +2 -672
- package/packages/client/dist/git/git-lifecycle-step-ids.js +1 -14
- package/packages/client/dist/git/git-lifecycle-store.d.ts +22 -0
- package/packages/client/dist/git/git-lifecycle-store.js +8 -2529
- package/packages/client/dist/git/legacy-story-branch-checkpoint.js +9 -259
- package/packages/client/dist/git/legacy-story-branch-setup.js +4 -348
- package/packages/client/dist/git/legacy-story-pr.js +70 -3538
- package/packages/client/dist/git/neocortex-trailers.js +2 -53
- package/packages/client/dist/git/secure-filesystem-boundary.js +5 -182
- package/packages/client/dist/git/story-worktree-cleanup.js +4 -1058
- package/packages/client/dist/git/story-worktree-integration.d.ts +62 -0
- package/packages/client/dist/git/story-worktree-integration.js +3 -603
- package/packages/client/dist/git/story-worktree-manager.js +3 -843
- package/packages/client/dist/git/story-worktree-paths.js +1 -150
- package/packages/client/dist/git/story-write-set-extension.d.ts +44 -0
- package/packages/client/dist/git/story-write-set-extension.js +1 -0
- package/packages/client/dist/graph-retrieval/pre-command-hook.js +1 -284
- package/packages/client/dist/graph-retrieval/shared-graph-retrieval-contract.js +1 -237
- package/packages/client/dist/i18n/first-run.js +2 -60
- package/packages/client/dist/index.js +1 -50
- package/packages/client/dist/invocation/invoke-input.js +1 -24
- package/packages/client/dist/license/host-auth-recovery.js +1 -401
- package/packages/client/dist/license/index.js +1 -5
- package/packages/client/dist/license/license-client.js +1 -337
- package/packages/client/dist/machine/fingerprint.js +2 -163
- package/packages/client/dist/machine/index.js +1 -5
- package/packages/client/dist/memory/project-memory-path-scope.js +1 -62
- package/packages/client/dist/memory/project-memory-writer.js +41 -1117
- package/packages/client/dist/memory/shared-project-memory-types.js +2 -259
- package/packages/client/dist/migrations/epic-lifecycle-backfill.js +3 -1060
- package/packages/client/dist/migrations/project-identity-capability.js +1 -50
- package/packages/client/dist/migrations/project-identity.js +7 -493
- package/packages/client/dist/migrations/state-json.js +4 -393
- package/packages/client/dist/policy/architecture-policy.js +2 -184
- package/packages/client/dist/policy/index.js +1 -7
- package/packages/client/dist/policy/shared-policy-types.js +0 -38
- package/packages/client/dist/policy/subagent-approval-policy.js +1 -57
- package/packages/client/dist/private-execution/clean-baseline.js +2 -279
- package/packages/client/dist/private-execution/codex-executor.js +4 -574
- package/packages/client/dist/private-execution/codex-host-runtime.js +1 -137
- package/packages/client/dist/private-execution/codex-lifecycle-guard.js +1 -97
- package/packages/client/dist/private-execution/codex-scoped-permissions.js +1 -128
- package/packages/client/dist/private-execution/delivery.js +13 -410
- package/packages/client/dist/private-execution/diagnosis-root-review.js +2 -294
- package/packages/client/dist/private-execution/frozen-handoff.js +6 -19
- package/packages/client/dist/private-execution/implementation-validation.js +2 -106
- package/packages/client/dist/private-execution/isolated-admission.js +23 -1432
- package/packages/client/dist/private-execution/isolated-session.js +5 -725
- package/packages/client/dist/private-execution/isolated-workspace.js +1 -122
- package/packages/client/dist/private-execution/pact-consumer-runtime.js +3 -409
- package/packages/client/dist/private-execution/pact-test-source.js +1 -258
- package/packages/client/dist/private-execution/pact-toolchain.js +3 -290
- package/packages/client/dist/private-execution/pact-write-set.js +1 -172
- package/packages/client/dist/private-execution/planning-diagnosis-checkpoint.js +5 -406
- package/packages/client/dist/private-execution/planning-generation-checkpoint.js +5 -462
- package/packages/client/dist/private-execution/planning-memory-checkpoint.js +3 -139
- package/packages/client/dist/private-execution/planning-research-checkpoint.js +4 -325
- package/packages/client/dist/private-execution/private-report-store.js +1 -42
- package/packages/client/dist/private-execution/property-test-candidate.js +1 -103
- package/packages/client/dist/private-execution/property-test-choices.js +3 -147
- package/packages/client/dist/private-execution/property-test-plan.js +7 -271
- package/packages/client/dist/private-execution/property-test-review.js +4 -258
- package/packages/client/dist/private-execution/property-test-runtime.js +9 -372
- package/packages/client/dist/private-execution/property-test-source.js +1 -139
- package/packages/client/dist/private-execution/root-checkpoint.js +1 -80
- package/packages/client/dist/private-execution/root-memory-git-evidence.js +3 -135
- package/packages/client/dist/private-execution/root-memory-recovery.js +1 -93
- package/packages/client/dist/private-execution/root-memory-request.js +1 -29
- package/packages/client/dist/private-execution/root-memory-scope.js +1 -178
- package/packages/client/dist/private-execution/root-memory-writer.js +1 -102
- package/packages/client/dist/private-execution/session-lease.js +1 -63
- package/packages/client/dist/private-execution/shared-private-admission-types.js +1 -50
- package/packages/client/dist/private-execution/shared-project-validation.js +1 -66
- package/packages/client/dist/private-execution/shared-root-memory-types.js +1 -61
- package/packages/client/dist/private-execution/ux-source-validation.js +1 -372
- package/packages/client/dist/private-execution/ux-write-set.js +2 -191
- package/packages/client/dist/registry/registry-reconciliation.js +1 -234
- package/packages/client/dist/resilience/circuit-breaker.js +1 -170
- package/packages/client/dist/resilience/degradation-manager.js +1 -164
- package/packages/client/dist/resilience/freshness-indicator.js +1 -100
- package/packages/client/dist/resilience/index.js +1 -8
- package/packages/client/dist/resilience/recovery-detector.js +1 -74
- package/packages/client/dist/resolvers/asset-resolver.js +0 -13
- package/packages/client/dist/resolvers/local-resolver.js +8 -255
- package/packages/client/dist/resolvers/remote-resolver.js +1 -233
- package/packages/client/dist/runner/binary.js +1 -404
- package/packages/client/dist/runner/cli.js +17 -1571
- package/packages/client/dist/runner/epic-background-dispatcher.js +1 -124
- package/packages/client/dist/runner/headless/adapters.js +1 -49
- package/packages/client/dist/runner/headless/background-root.js +1 -85
- package/packages/client/dist/runner/headless/claude-code-adapter.js +1 -79
- package/packages/client/dist/runner/headless/continuous-story-workspace.js +11 -1776
- package/packages/client/dist/runner/headless/epic-git-reconciliation-inventory.js +1 -69
- package/packages/client/dist/runner/headless/epic-merge-candidate-qa.js +2 -111
- package/packages/client/dist/runner/headless/epic-terminal-git-cli-adapter.js +10 -1464
- package/packages/client/dist/runner/headless/epic-terminal-git-runner.js +2 -357
- package/packages/client/dist/runner/headless/fake-adapter.js +1 -62
- package/packages/client/dist/runner/headless/managed-environment-cleanup.js +1 -274
- package/packages/client/dist/runner/headless/managed-profile.js +1 -149
- package/packages/client/dist/runner/headless/opencode-adapter.js +2 -145
- package/packages/client/dist/runner/headless/prepared-story-bundle.js +1 -43
- package/packages/client/dist/runner/headless/resolver.js +1 -231
- package/packages/client/dist/runner/headless/run-yolo.js +1 -886
- package/packages/client/dist/runner/headless/run-yoloop.js +2 -2657
- package/packages/client/dist/runner/headless/types.js +2 -575
- package/packages/client/dist/runner/host-capacity.js +1 -59
- package/packages/client/dist/runner/local-console.js +13 -396
- package/packages/client/dist/runner/portal-sync-worker.js +1 -1487
- package/packages/client/dist/runner/project-identity.js +1 -106
- package/packages/client/dist/runner/scheduler.js +7 -995
- package/packages/client/dist/runner-cli.js +2 -18
- package/packages/client/dist/state/invocation-shape.js +1 -13
- package/packages/client/dist/state/project-state-snapshot.js +1 -1754
- package/packages/client/dist/state/state-json-repair.js +3 -785
- package/packages/client/dist/state/structural-dag-projection.js +1 -118
- package/packages/client/dist/telemetry/index.js +1 -5
- package/packages/client/dist/telemetry/offline-queue.js +1 -131
- package/packages/client/dist/tier/index.js +1 -5
- package/packages/client/dist/tier/tier-aware-client.js +1 -405
- package/packages/client/dist/types/index.js +1 -38
- package/packages/client/dist/version.js +1 -27
- package/packages/client/dist/yolo/change-evidence-collector.d.ts +10 -0
- package/packages/client/dist/yolo/change-evidence-collector.js +1 -262
- package/packages/client/dist/yolo/invoke-envelope-capability.js +1 -65
- package/packages/client/dist/yolo/spec-envelope-collector.js +5 -184
- package/packages/client/dist/yoloop/discovery-hook.js +2 -300
- package/packages/client/dist/yoloop/index.js +1 -8
- package/packages/client/dist/yoloop/invoke-hooks.js +12 -669
- package/packages/client/dist/yoloop/shared-discover-epics.js +1 -1007
- package/packages/client/dist/yoloop/shared-yoloop-types.js +1 -33
- package/packages/client/dist/yoloop/target-normalization.js +1 -180
- package/packages/client/dist/yoloop/yoloop-client-state-store.js +1 -1920
- 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,231 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* @license FSL-1.1
|
|
3
|
-
* Copyright (c) 2026 OrNexus AI
|
|
4
|
-
*
|
|
5
|
-
* P190.04 -- deterministic headless runtime/model resolver.
|
|
6
|
-
*/
|
|
7
|
-
import { existsSync, readFileSync, statSync } from 'node:fs';
|
|
8
|
-
import { homedir } from 'node:os';
|
|
9
|
-
import { isAbsolute, join, resolve } from 'node:path';
|
|
10
|
-
import { HEADLESS_REASON_CODES, boundPublicSummary, isHeadlessAdapterId, isSafeHeadlessModelId, redaction, } from './types.js';
|
|
11
|
-
const DEFAULT_FALLBACK_HINT = Object.freeze({
|
|
12
|
-
runtimeId: 'opencode',
|
|
13
|
-
source: 'fallback',
|
|
14
|
-
publicSafe: true,
|
|
15
|
-
});
|
|
16
|
-
const DEFAULT_CONFIG_RELATIVE_PATH = '.neocortex/headless-runtime.json';
|
|
17
|
-
const DEFAULT_CONFIG_MAX_BYTES = 8 * 1024;
|
|
18
|
-
const RUNTIME_HINT_ALLOWED_KEYS = new Set(['runtimeId', 'modelId', 'source', 'reasonCode', 'publicSafe']);
|
|
19
|
-
const UNSAFE_HINT_KEY_PATTERN = /(raw|prompt|private|secret|token|password|authorization|api[_-]?key|license|argv|args|executable|binary|shell|cwd|command|path|url|vendor|stdout|stderr|transcript|workflow|step|customer|pii)/i;
|
|
20
|
-
export function resolveHeadlessRuntime(input = {}) {
|
|
21
|
-
const registry = input.registry ?? DEFAULT_REGISTRY_LIKE;
|
|
22
|
-
const candidates = buildCandidateList(input);
|
|
23
|
-
const normalized = [];
|
|
24
|
-
const redactions = [];
|
|
25
|
-
for (const candidate of candidates) {
|
|
26
|
-
if (candidate.value === undefined)
|
|
27
|
-
continue;
|
|
28
|
-
const result = normalizeCandidate(candidate, registry);
|
|
29
|
-
if (!result.ok)
|
|
30
|
-
return result.resolution;
|
|
31
|
-
redactions.push(...result.candidate.redactions);
|
|
32
|
-
normalized.push(result.candidate);
|
|
33
|
-
}
|
|
34
|
-
const runtimeCandidate = normalized.find((candidate) => candidate.runtimeId);
|
|
35
|
-
const modelCandidate = normalized.find((candidate) => candidate.modelId);
|
|
36
|
-
if (!runtimeCandidate?.runtimeId) {
|
|
37
|
-
return {
|
|
38
|
-
ok: false,
|
|
39
|
-
runtimeSource: 'unresolved',
|
|
40
|
-
reasonCode: HEADLESS_REASON_CODES.RUNTIME_UNRESOLVED,
|
|
41
|
-
reasonCodes: [HEADLESS_REASON_CODES.RUNTIME_UNRESOLVED],
|
|
42
|
-
publicSummary: 'Headless runtime could not be resolved from explicit, origin, default or fallback sources.',
|
|
43
|
-
redactionSummary: redactions,
|
|
44
|
-
publicSafe: true,
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
const reasonCode = sourceReasonCode(runtimeCandidate.source);
|
|
48
|
-
return {
|
|
49
|
-
ok: true,
|
|
50
|
-
runtimeId: runtimeCandidate.runtimeId,
|
|
51
|
-
...(modelCandidate?.modelId ? { modelId: modelCandidate.modelId } : {}),
|
|
52
|
-
runtimeSource: runtimeCandidate.source,
|
|
53
|
-
...(modelCandidate?.source ? { modelSource: modelCandidate.source } : {}),
|
|
54
|
-
reasonCode,
|
|
55
|
-
reasonCodes: [reasonCode],
|
|
56
|
-
publicSummary: `Resolved headless runtime from ${runtimeCandidate.source} source.`,
|
|
57
|
-
redactionSummary: redactions,
|
|
58
|
-
publicSafe: true,
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
export function loadHeadlessRuntimeDefaults(options = {}) {
|
|
62
|
-
const maxBytes = options.maxBytes ?? DEFAULT_CONFIG_MAX_BYTES;
|
|
63
|
-
const candidates = boundedDefaultPaths(options);
|
|
64
|
-
for (const candidate of candidates) {
|
|
65
|
-
if (!existsSync(candidate.path))
|
|
66
|
-
continue;
|
|
67
|
-
try {
|
|
68
|
-
const stat = statSync(candidate.path);
|
|
69
|
-
if (!stat.isFile() || stat.size > maxBytes) {
|
|
70
|
-
return defaultsFailure('Default headless runtime config was not a bounded file.', 'defaultConfig', 'unbounded_file');
|
|
71
|
-
}
|
|
72
|
-
const parsed = JSON.parse(readFileSync(candidate.path, 'utf8'));
|
|
73
|
-
const defaults = extractDefaults(parsed);
|
|
74
|
-
if (!defaults)
|
|
75
|
-
return defaultsFailure('Default headless runtime config did not contain a public object.', 'defaultConfig', 'unsafe_key');
|
|
76
|
-
return {
|
|
77
|
-
ok: true,
|
|
78
|
-
defaults: { ...defaults, source: 'default', publicSafe: true },
|
|
79
|
-
source: candidate.kind,
|
|
80
|
-
reasonCodes: [HEADLESS_REASON_CODES.RUNTIME_DEFAULT],
|
|
81
|
-
publicSummary: `Loaded ${candidate.kind} headless runtime defaults.`,
|
|
82
|
-
publicSafe: true,
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
catch {
|
|
86
|
-
return defaultsFailure('Default headless runtime config could not be parsed safely.', 'defaultConfig', 'unsafe_key');
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
return {
|
|
90
|
-
ok: true,
|
|
91
|
-
defaults: undefined,
|
|
92
|
-
reasonCodes: [],
|
|
93
|
-
publicSummary: 'No headless runtime defaults were found; resolver will continue without guessing.',
|
|
94
|
-
publicSafe: true,
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
function buildCandidateList(input) {
|
|
98
|
-
const candidates = [
|
|
99
|
-
{ source: 'explicit', value: input.explicit },
|
|
100
|
-
{ source: 'origin', value: input.origin },
|
|
101
|
-
];
|
|
102
|
-
for (const value of normalizeDefaults(input))
|
|
103
|
-
candidates.push({ source: 'default', value });
|
|
104
|
-
if (input.projectDefault !== undefined)
|
|
105
|
-
candidates.push({ source: 'default', value: input.projectDefault });
|
|
106
|
-
if (input.userDefault !== undefined)
|
|
107
|
-
candidates.push({ source: 'default', value: input.userDefault });
|
|
108
|
-
if (input.fallback !== false)
|
|
109
|
-
candidates.push({ source: 'fallback', value: input.fallback ?? DEFAULT_FALLBACK_HINT });
|
|
110
|
-
return candidates;
|
|
111
|
-
}
|
|
112
|
-
function normalizeDefaults(input) {
|
|
113
|
-
if (input.defaults === undefined)
|
|
114
|
-
return [];
|
|
115
|
-
return Array.isArray(input.defaults) ? input.defaults : [input.defaults];
|
|
116
|
-
}
|
|
117
|
-
function normalizeCandidate(candidate, registry) {
|
|
118
|
-
const value = unwrapDefaultLookup(candidate.value);
|
|
119
|
-
if (value === undefined)
|
|
120
|
-
return { ok: true, candidate: { source: candidate.source, redactions: [] } };
|
|
121
|
-
if (!isRecord(value)) {
|
|
122
|
-
return candidateFailure(HEADLESS_REASON_CODES.RUNTIME_UNTRUSTED, 'Headless runtime hint must be a public object.', candidate.source, [redaction('runtime', 'unsafe_key', 'value-denied')]);
|
|
123
|
-
}
|
|
124
|
-
const redactions = [];
|
|
125
|
-
for (const key of Object.keys(value)) {
|
|
126
|
-
if (!RUNTIME_HINT_ALLOWED_KEYS.has(key) || UNSAFE_HINT_KEY_PATTERN.test(key)) {
|
|
127
|
-
redactions.push(redaction(`runtime.${key}`, 'unsafe_key', 'key-denied'));
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
if (value.publicSafe !== true)
|
|
131
|
-
redactions.push(redaction('runtime.publicSafe', 'unsafe_key', 'value-denied'));
|
|
132
|
-
const source = typeof value.source === 'string' ? value.source : candidate.source;
|
|
133
|
-
if (source !== candidate.source)
|
|
134
|
-
redactions.push(redaction('runtime.source', 'unsafe_key', 'value-denied'));
|
|
135
|
-
const runtimeText = typeof value.runtimeId === 'string' ? value.runtimeId : undefined;
|
|
136
|
-
const modelText = typeof value.modelId === 'string' ? value.modelId : undefined;
|
|
137
|
-
let runtimeId;
|
|
138
|
-
if (runtimeText !== undefined) {
|
|
139
|
-
if (!isSafeRuntimeId(runtimeText) || !isHeadlessAdapterId(runtimeText) || !registry.hasAdapter(runtimeText)) {
|
|
140
|
-
redactions.push(redaction('runtime.runtimeId', 'unsafe_key', 'value-denied'));
|
|
141
|
-
return candidateFailure(HEADLESS_REASON_CODES.RUNTIME_UNTRUSTED, 'Headless runtime was not trusted or allowlisted.', candidate.source, redactions);
|
|
142
|
-
}
|
|
143
|
-
runtimeId = runtimeText;
|
|
144
|
-
}
|
|
145
|
-
let modelId;
|
|
146
|
-
if (modelText !== undefined) {
|
|
147
|
-
if (!isSafeHeadlessModelId(modelText)) {
|
|
148
|
-
redactions.push(redaction('runtime.modelId', 'unsafe_key', 'value-denied'));
|
|
149
|
-
return candidateFailure(HEADLESS_REASON_CODES.MODEL_REJECTED, 'Headless model id failed bounded public-safety validation.', candidate.source, redactions);
|
|
150
|
-
}
|
|
151
|
-
modelId = modelText;
|
|
152
|
-
}
|
|
153
|
-
if (redactions.length > 0) {
|
|
154
|
-
return candidateFailure(HEADLESS_REASON_CODES.RUNTIME_UNTRUSTED, 'Headless runtime hint failed public-safety validation.', candidate.source, redactions);
|
|
155
|
-
}
|
|
156
|
-
return { ok: true, candidate: { source: candidate.source, ...(runtimeId ? { runtimeId } : {}), ...(modelId ? { modelId } : {}), redactions: [] } };
|
|
157
|
-
}
|
|
158
|
-
function unwrapDefaultLookup(value) {
|
|
159
|
-
if (isRecord(value) && value.ok === true && 'defaults' in value)
|
|
160
|
-
return value.defaults;
|
|
161
|
-
return value;
|
|
162
|
-
}
|
|
163
|
-
function candidateFailure(reasonCode, publicSummary, source, redactions) {
|
|
164
|
-
return {
|
|
165
|
-
ok: false,
|
|
166
|
-
resolution: {
|
|
167
|
-
ok: false,
|
|
168
|
-
runtimeSource: 'unresolved',
|
|
169
|
-
reasonCode,
|
|
170
|
-
reasonCodes: [reasonCode],
|
|
171
|
-
publicSummary: boundPublicSummary(`${publicSummary} Source=${source}.`),
|
|
172
|
-
redactionSummary: redactions,
|
|
173
|
-
publicSafe: true,
|
|
174
|
-
},
|
|
175
|
-
};
|
|
176
|
-
}
|
|
177
|
-
function sourceReasonCode(source) {
|
|
178
|
-
switch (source) {
|
|
179
|
-
case 'explicit': return HEADLESS_REASON_CODES.RUNTIME_EXPLICIT;
|
|
180
|
-
case 'origin': return HEADLESS_REASON_CODES.RUNTIME_ORIGIN;
|
|
181
|
-
case 'default': return HEADLESS_REASON_CODES.RUNTIME_DEFAULT;
|
|
182
|
-
case 'fallback': return HEADLESS_REASON_CODES.RUNTIME_FALLBACK;
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
function boundedDefaultPaths(options) {
|
|
186
|
-
const paths = [];
|
|
187
|
-
const projectRoot = normalizeAbsoluteDirectory(options.projectRoot);
|
|
188
|
-
if (projectRoot)
|
|
189
|
-
paths.push({ kind: 'project', path: join(projectRoot, DEFAULT_CONFIG_RELATIVE_PATH) });
|
|
190
|
-
const home = normalizeAbsoluteDirectory(options.homeDir ?? homedir());
|
|
191
|
-
if (home)
|
|
192
|
-
paths.push({ kind: 'user', path: join(home, DEFAULT_CONFIG_RELATIVE_PATH) });
|
|
193
|
-
return paths;
|
|
194
|
-
}
|
|
195
|
-
function normalizeAbsoluteDirectory(value) {
|
|
196
|
-
if (!value || /[\r\n\0]/.test(value))
|
|
197
|
-
return undefined;
|
|
198
|
-
const absolute = isAbsolute(value) ? value : resolve(value);
|
|
199
|
-
return isAbsolute(absolute) ? absolute : undefined;
|
|
200
|
-
}
|
|
201
|
-
function extractDefaults(parsed) {
|
|
202
|
-
if (!isRecord(parsed))
|
|
203
|
-
return undefined;
|
|
204
|
-
const candidate = isRecord(parsed.headless) ? parsed.headless : parsed;
|
|
205
|
-
return {
|
|
206
|
-
...(typeof candidate.runtimeId === 'string' ? { runtimeId: candidate.runtimeId } : {}),
|
|
207
|
-
...(typeof candidate.modelId === 'string' ? { modelId: candidate.modelId } : {}),
|
|
208
|
-
publicSafe: true,
|
|
209
|
-
};
|
|
210
|
-
}
|
|
211
|
-
function defaultsFailure(publicSummary, field, reason) {
|
|
212
|
-
return {
|
|
213
|
-
ok: false,
|
|
214
|
-
reasonCode: HEADLESS_REASON_CODES.RUNTIME_UNTRUSTED,
|
|
215
|
-
reasonCodes: [HEADLESS_REASON_CODES.RUNTIME_UNTRUSTED],
|
|
216
|
-
publicSummary,
|
|
217
|
-
redactionSummary: [redaction(field, reason, 'value-denied')],
|
|
218
|
-
publicSafe: true,
|
|
219
|
-
};
|
|
220
|
-
}
|
|
221
|
-
function isSafeRuntimeId(value) {
|
|
222
|
-
return /^[A-Za-z0-9][A-Za-z0-9._:-]{0,79}$/.test(value) && !/[\/\s;&|`$<>]/.test(value);
|
|
223
|
-
}
|
|
224
|
-
function isRecord(value) {
|
|
225
|
-
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
226
|
-
}
|
|
227
|
-
const DEFAULT_REGISTRY_LIKE = Object.freeze({
|
|
228
|
-
hasAdapter(id) {
|
|
229
|
-
return isHeadlessAdapterId(id);
|
|
230
|
-
},
|
|
231
|
-
});
|
|
1
|
+
import{existsSync as h,readFileSync as T,statSync as _}from"node:fs";import{homedir as k}from"node:os";import{isAbsolute as I,join as S,resolve as R}from"node:path";import{HEADLESS_REASON_CODES as o,boundPublicSummary as D,isHeadlessAdapterId as b,isSafeHeadlessModelId as U,redaction as c}from"./types.js";const N=Object.freeze({runtimeId:"opencode",source:"fallback",publicSafe:!0}),E=".neocortex/headless-runtime.json",A=8*1024,C=new Set(["runtimeId","modelId","source","reasonCode","publicSafe"]),g=/(raw|prompt|private|secret|token|password|authorization|api[_-]?key|license|argv|args|executable|binary|shell|cwd|command|path|url|vendor|stdout|stderr|transcript|workflow|step|customer|pii)/i;function P(e={}){const t=e.registry??O,u=L(e),r=[],d=[];for(const i of u){if(i.value===void 0)continue;const a=M(i,t);if(!a.ok)return a.resolution;d.push(...a.candidate.redactions),r.push(a.candidate)}const n=r.find(i=>i.runtimeId),s=r.find(i=>i.modelId);if(!n?.runtimeId)return{ok:!1,runtimeSource:"unresolved",reasonCode:o.RUNTIME_UNRESOLVED,reasonCodes:[o.RUNTIME_UNRESOLVED],publicSummary:"Headless runtime could not be resolved from explicit, origin, default or fallback sources.",redactionSummary:d,publicSafe:!0};const l=w(n.source);return{ok:!0,runtimeId:n.runtimeId,...s?.modelId?{modelId:s.modelId}:{},runtimeSource:n.source,...s?.source?{modelSource:s.source}:{},reasonCode:l,reasonCodes:[l],publicSummary:`Resolved headless runtime from ${n.source} source.`,redactionSummary:d,publicSafe:!0}}function G(e={}){const t=e.maxBytes??A,u=x(e);for(const r of u)if(h(r.path))try{const d=_(r.path);if(!d.isFile()||d.size>t)return p("Default headless runtime config was not a bounded file.","defaultConfig","unbounded_file");const n=JSON.parse(T(r.path,"utf8")),s=H(n);return s?{ok:!0,defaults:{...s,source:"default",publicSafe:!0},source:r.kind,reasonCodes:[o.RUNTIME_DEFAULT],publicSummary:`Loaded ${r.kind} headless runtime defaults.`,publicSafe:!0}:p("Default headless runtime config did not contain a public object.","defaultConfig","unsafe_key")}catch{return p("Default headless runtime config could not be parsed safely.","defaultConfig","unsafe_key")}return{ok:!0,defaults:void 0,reasonCodes:[],publicSummary:"No headless runtime defaults were found; resolver will continue without guessing.",publicSafe:!0}}function L(e){const t=[{source:"explicit",value:e.explicit},{source:"origin",value:e.origin}];for(const u of v(e))t.push({source:"default",value:u});return e.projectDefault!==void 0&&t.push({source:"default",value:e.projectDefault}),e.userDefault!==void 0&&t.push({source:"default",value:e.userDefault}),e.fallback!==!1&&t.push({source:"fallback",value:e.fallback??N}),t}function v(e){return e.defaults===void 0?[]:Array.isArray(e.defaults)?e.defaults:[e.defaults]}function M(e,t){const u=F(e.value);if(u===void 0)return{ok:!0,candidate:{source:e.source,redactions:[]}};if(!m(u))return f(o.RUNTIME_UNTRUSTED,"Headless runtime hint must be a public object.",e.source,[c("runtime","unsafe_key","value-denied")]);const r=[];for(const a of Object.keys(u))(!C.has(a)||g.test(a))&&r.push(c(`runtime.${a}`,"unsafe_key","key-denied"));u.publicSafe!==!0&&r.push(c("runtime.publicSafe","unsafe_key","value-denied")),(typeof u.source=="string"?u.source:e.source)!==e.source&&r.push(c("runtime.source","unsafe_key","value-denied"));const n=typeof u.runtimeId=="string"?u.runtimeId:void 0,s=typeof u.modelId=="string"?u.modelId:void 0;let l;if(n!==void 0){if(!j(n)||!b(n)||!t.hasAdapter(n))return r.push(c("runtime.runtimeId","unsafe_key","value-denied")),f(o.RUNTIME_UNTRUSTED,"Headless runtime was not trusted or allowlisted.",e.source,r);l=n}let i;if(s!==void 0){if(!U(s))return r.push(c("runtime.modelId","unsafe_key","value-denied")),f(o.MODEL_REJECTED,"Headless model id failed bounded public-safety validation.",e.source,r);i=s}return r.length>0?f(o.RUNTIME_UNTRUSTED,"Headless runtime hint failed public-safety validation.",e.source,r):{ok:!0,candidate:{source:e.source,...l?{runtimeId:l}:{},...i?{modelId:i}:{},redactions:[]}}}function F(e){return m(e)&&e.ok===!0&&"defaults"in e?e.defaults:e}function f(e,t,u,r){return{ok:!1,resolution:{ok:!1,runtimeSource:"unresolved",reasonCode:e,reasonCodes:[e],publicSummary:D(`${t} Source=${u}.`),redactionSummary:r,publicSafe:!0}}}function w(e){switch(e){case"explicit":return o.RUNTIME_EXPLICIT;case"origin":return o.RUNTIME_ORIGIN;case"default":return o.RUNTIME_DEFAULT;case"fallback":return o.RUNTIME_FALLBACK}}function x(e){const t=[],u=y(e.projectRoot);u&&t.push({kind:"project",path:S(u,E)});const r=y(e.homeDir??k());return r&&t.push({kind:"user",path:S(r,E)}),t}function y(e){if(!e||/[\r\n\0]/.test(e))return;const t=I(e)?e:R(e);return I(t)?t:void 0}function H(e){if(!m(e))return;const t=m(e.headless)?e.headless:e;return{...typeof t.runtimeId=="string"?{runtimeId:t.runtimeId}:{},...typeof t.modelId=="string"?{modelId:t.modelId}:{},publicSafe:!0}}function p(e,t,u){return{ok:!1,reasonCode:o.RUNTIME_UNTRUSTED,reasonCodes:[o.RUNTIME_UNTRUSTED],publicSummary:e,redactionSummary:[c(t,u,"value-denied")],publicSafe:!0}}function j(e){return/^[A-Za-z0-9][A-Za-z0-9._:-]{0,79}$/.test(e)&&!/[\/\s;&|`$<>]/.test(e)}function m(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}const O=Object.freeze({hasAdapter(e){return b(e)}});export{G as loadHeadlessRuntimeDefaults,P as resolveHeadlessRuntime};
|