@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,2 +1,223 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, renameSync, unlinkSync, writeFileSync, } from 'node:fs';
|
|
2
|
+
import { homedir } from 'node:os';
|
|
3
|
+
import { dirname, join } from 'node:path';
|
|
4
|
+
import { SUBAGENT_APPROVAL_MANAGED_DEFAULT, SUBAGENT_APPROVAL_EVIDENCE, SUBAGENT_APPROVAL_POLICY_SCHEMA_VERSION, createSubagentApprovalAuditEvent, isSubagentApprovalMode, resolveSubagentApprovalPolicy, } from './policy/subagent-approval-policy.js';
|
|
5
|
+
import { setSecureDirPermissions, setSecureFilePermissions, } from './config/secure-config.js';
|
|
6
|
+
const POLICY_KEY = 'subagentApprovalPolicy';
|
|
7
|
+
const AUDIT_KEY = 'subagentApprovalPolicyAudit';
|
|
8
|
+
const MAX_AUDIT_EVENTS = 25;
|
|
9
|
+
const AUDIT_EVENTS = new Set([
|
|
10
|
+
'managed-default-materialized',
|
|
11
|
+
'user-override-updated',
|
|
12
|
+
'user-override-reset',
|
|
13
|
+
]);
|
|
14
|
+
const APPROVAL_SOURCES = new Set(['managed-default', 'user-override']);
|
|
15
|
+
const APPROVAL_SCOPES = new Set([
|
|
16
|
+
'child',
|
|
17
|
+
'session',
|
|
18
|
+
'global',
|
|
19
|
+
'inherited',
|
|
20
|
+
'none',
|
|
21
|
+
]);
|
|
22
|
+
const EFFECTIVE_REASONS = new Set([
|
|
23
|
+
'requested-mode-honored',
|
|
24
|
+
'host-policy-reduced',
|
|
25
|
+
'host-capability-unvalidated',
|
|
26
|
+
'host-capability-unsupported',
|
|
27
|
+
'platform-target-unknown',
|
|
28
|
+
]);
|
|
29
|
+
const FALLBACK_MODES = new Set(['none', 'root-inline', 'shell-loop']);
|
|
30
|
+
const PLATFORM_TARGETS = new Set([
|
|
31
|
+
'claude-code',
|
|
32
|
+
'opencode',
|
|
33
|
+
'codex',
|
|
34
|
+
'gemini',
|
|
35
|
+
'vscode',
|
|
36
|
+
'github-copilot-cli',
|
|
37
|
+
'kimi',
|
|
38
|
+
'cursor',
|
|
39
|
+
'antigravity',
|
|
40
|
+
'openclaw',
|
|
41
|
+
'grok',
|
|
42
|
+
'runner',
|
|
43
|
+
'unknown',
|
|
44
|
+
]);
|
|
45
|
+
export class ApprovalPolicyConfigError extends Error {
|
|
46
|
+
reasonCode;
|
|
47
|
+
constructor(reasonCode, message) {
|
|
48
|
+
super(message);
|
|
49
|
+
this.reasonCode = reasonCode;
|
|
50
|
+
this.name = 'ApprovalPolicyConfigError';
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function configFilePath(options) {
|
|
54
|
+
return options.configFilePath ?? join(homedir(), '.neocortex', 'config.json');
|
|
55
|
+
}
|
|
56
|
+
function readConfig(options) {
|
|
57
|
+
const path = configFilePath(options);
|
|
58
|
+
if (!existsSync(path))
|
|
59
|
+
return {};
|
|
60
|
+
try {
|
|
61
|
+
const parsed = JSON.parse(readFileSync(path, 'utf8').replace(/^\uFEFF/, ''));
|
|
62
|
+
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
|
63
|
+
throw new Error('Config root must be an object');
|
|
64
|
+
}
|
|
65
|
+
return parsed;
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
if (error instanceof ApprovalPolicyConfigError)
|
|
69
|
+
throw error;
|
|
70
|
+
throw new ApprovalPolicyConfigError('approval-config-invalid', 'Neocortex config is not valid JSON; approval policy was not changed.');
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
function readStoredPolicy(config) {
|
|
74
|
+
const value = config[POLICY_KEY];
|
|
75
|
+
if (value === undefined)
|
|
76
|
+
return undefined;
|
|
77
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
78
|
+
throw new ApprovalPolicyConfigError('approval-config-invalid', 'Stored subagent approval policy is invalid.');
|
|
79
|
+
}
|
|
80
|
+
const policy = value;
|
|
81
|
+
if (policy.schemaVersion !== SUBAGENT_APPROVAL_POLICY_SCHEMA_VERSION) {
|
|
82
|
+
throw new ApprovalPolicyConfigError('approval-policy-schema-unsupported', 'Stored subagent approval policy schema is not supported.');
|
|
83
|
+
}
|
|
84
|
+
if (policy.userOverride !== undefined &&
|
|
85
|
+
!isSubagentApprovalMode(policy.userOverride)) {
|
|
86
|
+
throw new ApprovalPolicyConfigError('approval-policy-mode-invalid', 'Stored subagent approval mode is invalid.');
|
|
87
|
+
}
|
|
88
|
+
return policy;
|
|
89
|
+
}
|
|
90
|
+
function resolveFromConfig(config, options) {
|
|
91
|
+
const policy = readStoredPolicy(config);
|
|
92
|
+
return resolveSubagentApprovalPolicy({
|
|
93
|
+
userOverride: policy?.userOverride,
|
|
94
|
+
hostPolicy: options.hostPolicy,
|
|
95
|
+
platformTarget: options.platformTarget,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
function appendAudit(config, event) {
|
|
99
|
+
const existing = Array.isArray(config[AUDIT_KEY])
|
|
100
|
+
? config[AUDIT_KEY]
|
|
101
|
+
.map(normalizeStoredAuditEvent)
|
|
102
|
+
.filter((entry) => entry !== null)
|
|
103
|
+
: [];
|
|
104
|
+
config[AUDIT_KEY] = [...existing, event].slice(-MAX_AUDIT_EVENTS);
|
|
105
|
+
}
|
|
106
|
+
function normalizeStoredAuditEvent(value) {
|
|
107
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
108
|
+
return null;
|
|
109
|
+
const entry = value;
|
|
110
|
+
if (entry.evidence !== SUBAGENT_APPROVAL_EVIDENCE ||
|
|
111
|
+
entry.schemaVersion !== SUBAGENT_APPROVAL_POLICY_SCHEMA_VERSION ||
|
|
112
|
+
!AUDIT_EVENTS.has(String(entry.event)) ||
|
|
113
|
+
!isSubagentApprovalMode(entry.requestedMode) ||
|
|
114
|
+
!isSubagentApprovalMode(entry.effectiveMode) ||
|
|
115
|
+
!APPROVAL_SOURCES.has(String(entry.source)) ||
|
|
116
|
+
!PLATFORM_TARGETS.has(String(entry.platformTarget)) ||
|
|
117
|
+
!APPROVAL_SCOPES.has(String(entry.scope)) ||
|
|
118
|
+
!EFFECTIVE_REASONS.has(String(entry.effectiveReason)) ||
|
|
119
|
+
typeof entry.occurredAt !== 'string' ||
|
|
120
|
+
!Number.isFinite(Date.parse(entry.occurredAt))) {
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
const derivedFallback = resolveSubagentApprovalPolicy({
|
|
124
|
+
userOverride: entry.requestedMode,
|
|
125
|
+
platformTarget: String(entry.platformTarget),
|
|
126
|
+
});
|
|
127
|
+
const fallbackMode = FALLBACK_MODES.has(String(entry.fallbackMode))
|
|
128
|
+
? entry.fallbackMode
|
|
129
|
+
: derivedFallback.fallbackMode;
|
|
130
|
+
const fallbackReasonCode = entry.fallbackReasonCode === null ||
|
|
131
|
+
typeof entry.fallbackReasonCode === 'string'
|
|
132
|
+
? entry.fallbackReasonCode
|
|
133
|
+
: derivedFallback.fallbackReasonCode;
|
|
134
|
+
return createSubagentApprovalAuditEvent(entry.event, {
|
|
135
|
+
schemaVersion: SUBAGENT_APPROVAL_POLICY_SCHEMA_VERSION,
|
|
136
|
+
requestedMode: entry.requestedMode,
|
|
137
|
+
effectiveMode: entry.effectiveMode,
|
|
138
|
+
source: entry.source,
|
|
139
|
+
platformTarget: entry.platformTarget,
|
|
140
|
+
scope: entry.scope,
|
|
141
|
+
effectiveReason: entry.effectiveReason,
|
|
142
|
+
fallbackMode,
|
|
143
|
+
fallbackReasonCode,
|
|
144
|
+
}, entry.occurredAt);
|
|
145
|
+
}
|
|
146
|
+
function writeConfig(config, options) {
|
|
147
|
+
const path = configFilePath(options);
|
|
148
|
+
const dir = dirname(path);
|
|
149
|
+
const temporaryPath = `${path}.tmp`;
|
|
150
|
+
mkdirSync(dir, { recursive: true });
|
|
151
|
+
setSecureDirPermissions(dir);
|
|
152
|
+
try {
|
|
153
|
+
writeFileSync(temporaryPath, `${JSON.stringify(config, null, 2)}\n`, 'utf8');
|
|
154
|
+
setSecureFilePermissions(temporaryPath);
|
|
155
|
+
renameSync(temporaryPath, path);
|
|
156
|
+
setSecureFilePermissions(path);
|
|
157
|
+
}
|
|
158
|
+
catch (error) {
|
|
159
|
+
try {
|
|
160
|
+
if (existsSync(temporaryPath))
|
|
161
|
+
unlinkSync(temporaryPath);
|
|
162
|
+
}
|
|
163
|
+
catch {
|
|
164
|
+
// Best-effort cleanup; preserve the original write failure.
|
|
165
|
+
}
|
|
166
|
+
throw error;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
function occurredAt(options) {
|
|
170
|
+
return (options.now?.() ?? new Date()).toISOString();
|
|
171
|
+
}
|
|
172
|
+
export function getSubagentApprovalPolicy(options = {}) {
|
|
173
|
+
return { resolution: resolveFromConfig(readConfig(options), options) };
|
|
174
|
+
}
|
|
175
|
+
export function ensureManagedSubagentApprovalPolicy(options = {}) {
|
|
176
|
+
const config = readConfig(options);
|
|
177
|
+
const existing = readStoredPolicy(config);
|
|
178
|
+
if (existing) {
|
|
179
|
+
return { resolution: resolveFromConfig(config, options) };
|
|
180
|
+
}
|
|
181
|
+
const at = occurredAt(options);
|
|
182
|
+
config[POLICY_KEY] = {
|
|
183
|
+
schemaVersion: SUBAGENT_APPROVAL_POLICY_SCHEMA_VERSION,
|
|
184
|
+
managedDefault: SUBAGENT_APPROVAL_MANAGED_DEFAULT,
|
|
185
|
+
updatedAt: at,
|
|
186
|
+
};
|
|
187
|
+
const resolution = resolveFromConfig(config, options);
|
|
188
|
+
const auditEvent = createSubagentApprovalAuditEvent('managed-default-materialized', resolution, at);
|
|
189
|
+
appendAudit(config, auditEvent);
|
|
190
|
+
writeConfig(config, options);
|
|
191
|
+
return { resolution, auditEvent };
|
|
192
|
+
}
|
|
193
|
+
export function setSubagentApprovalMode(mode, options = {}) {
|
|
194
|
+
if (!isSubagentApprovalMode(mode)) {
|
|
195
|
+
throw new ApprovalPolicyConfigError('approval-policy-mode-invalid', 'Requested subagent approval mode is invalid.');
|
|
196
|
+
}
|
|
197
|
+
const config = readConfig(options);
|
|
198
|
+
const existing = readStoredPolicy(config);
|
|
199
|
+
const at = occurredAt(options);
|
|
200
|
+
config[POLICY_KEY] = {
|
|
201
|
+
...(existing ?? {}),
|
|
202
|
+
schemaVersion: SUBAGENT_APPROVAL_POLICY_SCHEMA_VERSION,
|
|
203
|
+
managedDefault: SUBAGENT_APPROVAL_MANAGED_DEFAULT,
|
|
204
|
+
userOverride: mode,
|
|
205
|
+
updatedAt: at,
|
|
206
|
+
};
|
|
207
|
+
const resolution = resolveFromConfig(config, options);
|
|
208
|
+
const auditEvent = createSubagentApprovalAuditEvent('user-override-updated', resolution, at);
|
|
209
|
+
appendAudit(config, auditEvent);
|
|
210
|
+
writeConfig(config, options);
|
|
211
|
+
return { resolution, auditEvent };
|
|
212
|
+
}
|
|
213
|
+
export function resetSubagentApprovalMode(options = {}) {
|
|
214
|
+
const config = readConfig(options);
|
|
215
|
+
readStoredPolicy(config);
|
|
216
|
+
delete config[POLICY_KEY];
|
|
217
|
+
const at = occurredAt(options);
|
|
218
|
+
const resolution = resolveFromConfig(config, options);
|
|
219
|
+
const auditEvent = createSubagentApprovalAuditEvent('user-override-reset', resolution, at);
|
|
220
|
+
appendAudit(config, auditEvent);
|
|
221
|
+
writeConfig(config, options);
|
|
222
|
+
return { resolution, auditEvent };
|
|
223
|
+
}
|
|
@@ -1 +1,25 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @license FSL-1.1
|
|
3
|
+
* Copyright (c) 2026 OrNexus AI
|
|
4
|
+
*
|
|
5
|
+
* This file is part of Neocortex CLI, licensed under the
|
|
6
|
+
* Functional Source License, Version 1.1 (FSL-1.1).
|
|
7
|
+
*
|
|
8
|
+
* Change Date: February 20, 2029
|
|
9
|
+
* Change License: MIT
|
|
10
|
+
*
|
|
11
|
+
* See the LICENSE file in the project root for full license text.
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Production server URL.
|
|
15
|
+
*
|
|
16
|
+
* Single Source of Truth for the default Neocortex IP Protection Server URL.
|
|
17
|
+
* All client-side code MUST import this constant instead of hardcoding the URL.
|
|
18
|
+
*
|
|
19
|
+
* Shell scripts (install.sh, install.ps1) cannot import from TypeScript,
|
|
20
|
+
* so they maintain a hardcoded copy with a comment referencing this file.
|
|
21
|
+
*
|
|
22
|
+
* Epic 70 - Story 70.03
|
|
23
|
+
* Epic P46 - Story P46.01: migrated legacy API host to api.neocortex.sh
|
|
24
|
+
*/
|
|
25
|
+
export const DEFAULT_SERVER_URL = 'https://api.neocortex.sh';
|
|
@@ -1,2 +1,222 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @license FSL-1.1
|
|
3
|
+
* Copyright (c) 2026 OrNexus AI
|
|
4
|
+
*
|
|
5
|
+
* This file is part of Neocortex CLI, licensed under the
|
|
6
|
+
* Functional Source License, Version 1.1 (FSL-1.1).
|
|
7
|
+
*
|
|
8
|
+
* Change Date: February 20, 2029
|
|
9
|
+
* Change License: MIT
|
|
10
|
+
*
|
|
11
|
+
* See the LICENSE file in the project root for full license text.
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* @neocortex/client - Context Collector
|
|
15
|
+
*
|
|
16
|
+
* Collects pipeline context from state.json, package.json, and story files.
|
|
17
|
+
* Sanitizes all sensitive data before returning the context.
|
|
18
|
+
*/
|
|
19
|
+
import { readFile } from 'node:fs/promises';
|
|
20
|
+
import { join } from 'node:path';
|
|
21
|
+
import { sanitizeObject } from './context-sanitizer.js';
|
|
22
|
+
// ── Frontmatter extraction (reused from local-resolver) ──────────────────
|
|
23
|
+
const FRONTMATTER_REGEX = /^---\n([\s\S]*?)\n---/;
|
|
24
|
+
function extractFrontmatter(content) {
|
|
25
|
+
const match = content.match(FRONTMATTER_REGEX);
|
|
26
|
+
if (!match)
|
|
27
|
+
return {};
|
|
28
|
+
const result = {};
|
|
29
|
+
for (const line of match[1].split('\n')) {
|
|
30
|
+
const colonIndex = line.indexOf(':');
|
|
31
|
+
if (colonIndex === -1)
|
|
32
|
+
continue;
|
|
33
|
+
const key = line.slice(0, colonIndex).trim().replace(/^['"]|['"]$/g, '');
|
|
34
|
+
const value = line.slice(colonIndex + 1).trim().replace(/^['"]|['"]$/g, '');
|
|
35
|
+
result[key] = value;
|
|
36
|
+
}
|
|
37
|
+
return result;
|
|
38
|
+
}
|
|
39
|
+
// ── Acceptance Criteria Extraction ───────────────────────────────────────
|
|
40
|
+
function extractAcceptanceCriteria(content) {
|
|
41
|
+
const criteria = [];
|
|
42
|
+
const acPattern = /\*\*AC\d+:?\s*([^*]+)\*\*/g;
|
|
43
|
+
let match;
|
|
44
|
+
while ((match = acPattern.exec(content)) !== null) {
|
|
45
|
+
criteria.push(match[1].trim());
|
|
46
|
+
}
|
|
47
|
+
return criteria;
|
|
48
|
+
}
|
|
49
|
+
// ── Framework Detection ──────────────────────────────────────────────────
|
|
50
|
+
const FRAMEWORK_INDICATORS = {
|
|
51
|
+
react: 'React',
|
|
52
|
+
next: 'Next.js',
|
|
53
|
+
vue: 'Vue',
|
|
54
|
+
nuxt: 'Nuxt',
|
|
55
|
+
angular: 'Angular',
|
|
56
|
+
svelte: 'Svelte',
|
|
57
|
+
express: 'Express',
|
|
58
|
+
fastify: 'Fastify',
|
|
59
|
+
nest: 'NestJS',
|
|
60
|
+
koa: 'Koa',
|
|
61
|
+
hapi: 'Hapi',
|
|
62
|
+
};
|
|
63
|
+
function detectFrameworks(deps) {
|
|
64
|
+
const frameworks = [];
|
|
65
|
+
for (const [dep, name] of Object.entries(FRAMEWORK_INDICATORS)) {
|
|
66
|
+
if (dep in deps) {
|
|
67
|
+
frameworks.push(name);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return frameworks;
|
|
71
|
+
}
|
|
72
|
+
// ── Language Detection ───────────────────────────────────────────────────
|
|
73
|
+
function detectLanguages(deps) {
|
|
74
|
+
const languages = new Set();
|
|
75
|
+
languages.add('JavaScript'); // Always present in Node.js projects
|
|
76
|
+
if ('typescript' in deps || Object.keys(deps).some((d) => d.includes('ts-'))) {
|
|
77
|
+
languages.add('TypeScript');
|
|
78
|
+
}
|
|
79
|
+
return [...languages];
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Collect complete pipeline context.
|
|
83
|
+
*
|
|
84
|
+
* Reads state.json, package.json, and story file to build
|
|
85
|
+
* a sanitized PipelineContext for the remote server.
|
|
86
|
+
*/
|
|
87
|
+
export async function collectContext(options) {
|
|
88
|
+
const { projectRoot, storyFilePath, storyId, stepId, platformTarget } = options;
|
|
89
|
+
// Collect state context
|
|
90
|
+
const stateContext = await collectStateContext(projectRoot, storyId);
|
|
91
|
+
// Collect codebase metadata
|
|
92
|
+
const codebaseMetadata = await collectCodebaseMetadata(projectRoot);
|
|
93
|
+
// Collect story metadata
|
|
94
|
+
const storyMetadata = await collectStoryMetadata(storyFilePath);
|
|
95
|
+
// Build context
|
|
96
|
+
const context = {
|
|
97
|
+
storyId,
|
|
98
|
+
stepId,
|
|
99
|
+
epicId: storyMetadata.epicId || stateContext.epicId || '',
|
|
100
|
+
storyTitle: storyMetadata.title,
|
|
101
|
+
currentStatus: stateContext.status,
|
|
102
|
+
stepsCompleted: stateContext.stepsCompleted,
|
|
103
|
+
branchName: stateContext.branchName,
|
|
104
|
+
platformTarget: platformTarget || detectPlatform(),
|
|
105
|
+
codebaseMetadata,
|
|
106
|
+
storyMetadata,
|
|
107
|
+
};
|
|
108
|
+
// Sanitize before returning
|
|
109
|
+
return sanitizeObject(context, projectRoot);
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Collect state context from state.json.
|
|
113
|
+
*/
|
|
114
|
+
async function collectStateContext(projectRoot, storyId) {
|
|
115
|
+
try {
|
|
116
|
+
const statePath = join(projectRoot, '.neocortex', 'state.json');
|
|
117
|
+
const raw = await readFile(statePath, 'utf-8');
|
|
118
|
+
const state = JSON.parse(raw);
|
|
119
|
+
const story = state.stories?.[storyId];
|
|
120
|
+
return {
|
|
121
|
+
status: story?.status || 'unknown',
|
|
122
|
+
stepsCompleted: story?.steps_completed || [],
|
|
123
|
+
branchName: story?.branch_name || '',
|
|
124
|
+
epicId: story?.epic_id || '',
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
catch {
|
|
128
|
+
return {
|
|
129
|
+
status: 'unknown',
|
|
130
|
+
stepsCompleted: [],
|
|
131
|
+
branchName: '',
|
|
132
|
+
epicId: '',
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Collect codebase metadata from package.json.
|
|
138
|
+
*/
|
|
139
|
+
async function collectCodebaseMetadata(projectRoot) {
|
|
140
|
+
try {
|
|
141
|
+
const pkgPath = join(projectRoot, 'package.json');
|
|
142
|
+
const raw = await readFile(pkgPath, 'utf-8');
|
|
143
|
+
const pkg = JSON.parse(raw);
|
|
144
|
+
const allDeps = {
|
|
145
|
+
...(pkg.dependencies || {}),
|
|
146
|
+
...(pkg.devDependencies || {}),
|
|
147
|
+
};
|
|
148
|
+
return {
|
|
149
|
+
projectName: pkg.name || 'unknown',
|
|
150
|
+
languages: detectLanguages(allDeps),
|
|
151
|
+
frameworks: detectFrameworks(allDeps),
|
|
152
|
+
dependencies: pkg.dependencies || {},
|
|
153
|
+
nodeVersion: process.version,
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
catch {
|
|
157
|
+
return {
|
|
158
|
+
projectName: 'unknown',
|
|
159
|
+
languages: ['JavaScript'],
|
|
160
|
+
frameworks: [],
|
|
161
|
+
dependencies: {},
|
|
162
|
+
nodeVersion: process.version,
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Collect story metadata from the story file.
|
|
168
|
+
*/
|
|
169
|
+
async function collectStoryMetadata(storyFilePath) {
|
|
170
|
+
try {
|
|
171
|
+
const raw = await readFile(storyFilePath, 'utf-8');
|
|
172
|
+
const fm = extractFrontmatter(raw);
|
|
173
|
+
const acs = extractAcceptanceCriteria(raw);
|
|
174
|
+
// Parse dependencies array from frontmatter
|
|
175
|
+
let deps = [];
|
|
176
|
+
const depsStr = fm['dependencies'];
|
|
177
|
+
if (depsStr) {
|
|
178
|
+
try {
|
|
179
|
+
deps = JSON.parse(depsStr.replace(/'/g, '"'));
|
|
180
|
+
}
|
|
181
|
+
catch {
|
|
182
|
+
deps = depsStr.split(',').map((d) => d.trim().replace(/[[\]"']/g, ''));
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return {
|
|
186
|
+
id: fm['id'] || '',
|
|
187
|
+
epicId: fm['epic_id'] || '',
|
|
188
|
+
title: fm['title'] || '',
|
|
189
|
+
status: fm['status'] || fm['currentStatus'] || '',
|
|
190
|
+
dependencies: deps,
|
|
191
|
+
acceptanceCriteria: acs,
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
catch {
|
|
195
|
+
return {
|
|
196
|
+
id: '',
|
|
197
|
+
epicId: '',
|
|
198
|
+
title: '',
|
|
199
|
+
status: '',
|
|
200
|
+
dependencies: [],
|
|
201
|
+
acceptanceCriteria: [],
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Detect the platform target from environment.
|
|
207
|
+
*/
|
|
208
|
+
function detectPlatform() {
|
|
209
|
+
if (process.env['CLAUDE_CODE'] || process.env['CLAUDE_AGENT']) {
|
|
210
|
+
return 'claude-code';
|
|
211
|
+
}
|
|
212
|
+
if (process.env['CURSOR_SESSION_ID']) {
|
|
213
|
+
return 'cursor';
|
|
214
|
+
}
|
|
215
|
+
if (process.env['VSCODE_PID']) {
|
|
216
|
+
return 'vscode';
|
|
217
|
+
}
|
|
218
|
+
if (process.env['GEMINI_CLI']) {
|
|
219
|
+
return 'gemini';
|
|
220
|
+
}
|
|
221
|
+
return 'unknown';
|
|
222
|
+
}
|
|
@@ -1 +1,145 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @license FSL-1.1
|
|
3
|
+
* Copyright (c) 2026 OrNexus AI
|
|
4
|
+
*
|
|
5
|
+
* This file is part of Neocortex CLI, licensed under the
|
|
6
|
+
* Functional Source License, Version 1.1 (FSL-1.1).
|
|
7
|
+
*
|
|
8
|
+
* Change Date: February 20, 2029
|
|
9
|
+
* Change License: MIT
|
|
10
|
+
*
|
|
11
|
+
* See the LICENSE file in the project root for full license text.
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* @neocortex/client - Context Sanitizer
|
|
15
|
+
*
|
|
16
|
+
* Removes sensitive data from pipeline context before sending
|
|
17
|
+
* to the remote server. Strips absolute paths, tokens, credentials,
|
|
18
|
+
* and other sensitive information.
|
|
19
|
+
*/
|
|
20
|
+
import { homedir } from 'node:os';
|
|
21
|
+
// ── Sensitive Patterns ───────────────────────────────────────────────────
|
|
22
|
+
/** Environment variable name patterns that indicate sensitive values */
|
|
23
|
+
const SENSITIVE_ENV_PATTERNS = [
|
|
24
|
+
/token/i,
|
|
25
|
+
/key/i,
|
|
26
|
+
/secret/i,
|
|
27
|
+
/password/i,
|
|
28
|
+
/credential/i,
|
|
29
|
+
/auth/i,
|
|
30
|
+
/github_pat_/i,
|
|
31
|
+
/npm_token/i,
|
|
32
|
+
/api_key/i,
|
|
33
|
+
];
|
|
34
|
+
/** Regex patterns for sensitive values in strings */
|
|
35
|
+
const SENSITIVE_VALUE_PATTERNS = [
|
|
36
|
+
/github_pat_[A-Za-z0-9_]{36,}/g,
|
|
37
|
+
/ghp_[A-Za-z0-9]{36,}/g,
|
|
38
|
+
/gho_[A-Za-z0-9]{36,}/g,
|
|
39
|
+
/sk-[A-Za-z0-9]{32,}/g,
|
|
40
|
+
/Bearer\s+[A-Za-z0-9._\-]+/g,
|
|
41
|
+
/-----BEGIN\s+(RSA\s+)?PRIVATE\s+KEY-----[\s\S]*?-----END/g,
|
|
42
|
+
];
|
|
43
|
+
/** Maximum allowed string length before truncation */
|
|
44
|
+
const MAX_VALUE_LENGTH = 1000;
|
|
45
|
+
// ── Sanitization Functions ───────────────────────────────────────────────
|
|
46
|
+
/**
|
|
47
|
+
* Replace absolute paths with relative ones.
|
|
48
|
+
*
|
|
49
|
+
* Converts paths like /Users/john/projects/neocortex/src/file.ts
|
|
50
|
+
* to ./src/file.ts based on the project root.
|
|
51
|
+
*/
|
|
52
|
+
function sanitizePaths(value, projectRoot) {
|
|
53
|
+
let result = value;
|
|
54
|
+
// Replace project root path with ./
|
|
55
|
+
if (projectRoot) {
|
|
56
|
+
const escapedRoot = projectRoot.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
57
|
+
result = result.replace(new RegExp(escapedRoot, 'g'), '.');
|
|
58
|
+
}
|
|
59
|
+
// Replace home directory with ~
|
|
60
|
+
const home = homedir();
|
|
61
|
+
if (home) {
|
|
62
|
+
const escapedHome = home.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
63
|
+
result = result.replace(new RegExp(escapedHome, 'g'), '~');
|
|
64
|
+
}
|
|
65
|
+
return result;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Remove sensitive tokens and credentials from a string.
|
|
69
|
+
*/
|
|
70
|
+
function sanitizeTokens(value) {
|
|
71
|
+
let result = value;
|
|
72
|
+
for (const pattern of SENSITIVE_VALUE_PATTERNS) {
|
|
73
|
+
result = result.replace(pattern, '[REDACTED]');
|
|
74
|
+
}
|
|
75
|
+
return result;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Truncate a string value if it exceeds the maximum length.
|
|
79
|
+
*/
|
|
80
|
+
function truncateValue(value) {
|
|
81
|
+
if (value.length <= MAX_VALUE_LENGTH) {
|
|
82
|
+
return value;
|
|
83
|
+
}
|
|
84
|
+
return `${value.slice(0, MAX_VALUE_LENGTH)}...[truncated, ${value.length} chars total]`;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Check if an environment variable name indicates a sensitive value.
|
|
88
|
+
*/
|
|
89
|
+
function isSensitiveKey(key) {
|
|
90
|
+
return SENSITIVE_ENV_PATTERNS.some((pattern) => pattern.test(key));
|
|
91
|
+
}
|
|
92
|
+
// ── Public API ───────────────────────────────────────────────────────────
|
|
93
|
+
/**
|
|
94
|
+
* Sanitize a single string value.
|
|
95
|
+
*
|
|
96
|
+
* Applies path sanitization, token removal, and truncation.
|
|
97
|
+
*/
|
|
98
|
+
export function sanitizeValue(value, projectRoot) {
|
|
99
|
+
let result = sanitizePaths(value, projectRoot);
|
|
100
|
+
result = sanitizeTokens(result);
|
|
101
|
+
result = truncateValue(result);
|
|
102
|
+
return result;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Sanitize a record of key-value pairs.
|
|
106
|
+
*
|
|
107
|
+
* Removes entries with sensitive keys and sanitizes remaining values.
|
|
108
|
+
*/
|
|
109
|
+
export function sanitizeRecord(record, projectRoot) {
|
|
110
|
+
const sanitized = {};
|
|
111
|
+
for (const [key, value] of Object.entries(record)) {
|
|
112
|
+
if (isSensitiveKey(key)) {
|
|
113
|
+
continue; // Drop sensitive keys entirely
|
|
114
|
+
}
|
|
115
|
+
sanitized[key] = sanitizeValue(value, projectRoot);
|
|
116
|
+
}
|
|
117
|
+
return sanitized;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Deep sanitize an object, processing all string values recursively.
|
|
121
|
+
*/
|
|
122
|
+
export function sanitizeObject(obj, projectRoot) {
|
|
123
|
+
if (obj === null || obj === undefined) {
|
|
124
|
+
return obj;
|
|
125
|
+
}
|
|
126
|
+
if (typeof obj === 'string') {
|
|
127
|
+
return sanitizeValue(obj, projectRoot);
|
|
128
|
+
}
|
|
129
|
+
if (Array.isArray(obj)) {
|
|
130
|
+
return obj.map((item) => sanitizeObject(item, projectRoot));
|
|
131
|
+
}
|
|
132
|
+
if (typeof obj === 'object') {
|
|
133
|
+
const result = {};
|
|
134
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
135
|
+
if (isSensitiveKey(key) && typeof value === 'string') {
|
|
136
|
+
result[key] = '[REDACTED]';
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
result[key] = sanitizeObject(value, projectRoot);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return result;
|
|
143
|
+
}
|
|
144
|
+
return obj;
|
|
145
|
+
}
|