@ornexus/neocortex 4.60.77 → 4.60.79
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 -1206
- 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 +214 -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 +443 -2
- package/packages/client/dist/agent/update-agent-yaml.js +102 -1
- package/packages/client/dist/agent/update-description.js +260 -1
- package/packages/client/dist/cache/crypto-utils.js +78 -1
- package/packages/client/dist/cache/encrypted-cache.js +338 -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 +7712 -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 +159 -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/host-auth-broker.js +60 -1
- package/packages/client/dist/config/host-auth-reference.js +93 -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 +105 -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.js +2612 -81
- package/packages/client/dist/effects/invoke-effect-gateways.js +62 -1
- package/packages/client/dist/errors/error-messages.js +258 -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 +1341 -4
- package/packages/client/dist/git/epic-operational-state.js +672 -2
- package/packages/client/dist/git/git-lifecycle-step-ids.js +14 -1
- package/packages/client/dist/git/git-lifecycle-store.js +2185 -10
- 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 +50 -1
- package/packages/client/dist/invocation/invoke-input.js +24 -1
- package/packages/client/dist/license/host-auth-recovery.js +401 -1
- package/packages/client/dist/license/index.js +5 -1
- package/packages/client/dist/license/license-client.js +337 -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 +1067 -41
- package/packages/client/dist/memory/shared-project-memory-types.js +259 -2
- package/packages/client/dist/migrations/epic-lifecycle-backfill.js +1060 -3
- 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.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/epic-background-dispatcher.js +124 -1
- package/packages/client/dist/runner/headless/adapters.js +49 -1
- package/packages/client/dist/runner/headless/background-root.js +85 -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 +111 -2
- package/packages/client/dist/runner/headless/epic-terminal-git-cli-adapter.js +1464 -10
- package/packages/client/dist/runner/headless/epic-terminal-git-runner.js +357 -2
- package/packages/client/dist/runner/headless/fake-adapter.js +62 -1
- package/packages/client/dist/runner/headless/managed-environment-cleanup.js +274 -1
- package/packages/client/dist/runner/headless/managed-profile.js +149 -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 +886 -1
- package/packages/client/dist/runner/headless/run-yoloop.js +2582 -2
- package/packages/client/dist/runner/headless/types.js +575 -2
- package/packages/client/dist/runner/host-capacity.js +59 -1
- 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.js +1751 -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 +222 -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.js +33 -1
- package/packages/client/dist/yoloop/target-normalization.js +180 -1
- package/packages/client/dist/yoloop/yoloop-client-state-store.js +1920 -1
- 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,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
|
+
});
|