avorelo 0.1.0
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/LICENSE +21 -0
- package/README.md +56 -0
- package/bin/avorelo +9 -0
- package/package.json +135 -0
- package/scripts/README.md +40 -0
- package/scripts/cco-dashboard.js +252 -0
- package/scripts/cco-status.js +430 -0
- package/scripts/lib/activation/account-state.js +37 -0
- package/scripts/lib/activation/activation-runner.js +546 -0
- package/scripts/lib/activation/activation-self-healing.js +480 -0
- package/scripts/lib/activation/activation-state.js +83 -0
- package/scripts/lib/activation/activation-summary.js +191 -0
- package/scripts/lib/activation/adapters/claude-code.js +77 -0
- package/scripts/lib/activation/adapters/codex-cli.js +52 -0
- package/scripts/lib/activation/adapters/cursor.js +37 -0
- package/scripts/lib/activation/adapters/github-agent.js +39 -0
- package/scripts/lib/activation/adapters/terminal.js +42 -0
- package/scripts/lib/activation/adapters/vscode.js +39 -0
- package/scripts/lib/activation/adapters/windsurf.js +37 -0
- package/scripts/lib/activation/ai-surface-detector.js +151 -0
- package/scripts/lib/activation/connect-account.js +145 -0
- package/scripts/lib/activation/detect-environment.js +75 -0
- package/scripts/lib/activation/detect-hosts.js +62 -0
- package/scripts/lib/activation/format-activation-output.js +109 -0
- package/scripts/lib/activation/next-action.js +43 -0
- package/scripts/lib/activation/repair-engine.js +219 -0
- package/scripts/lib/activation-distribution-readiness.js +507 -0
- package/scripts/lib/adapter-conformance.js +176 -0
- package/scripts/lib/adapter-readiness.js +417 -0
- package/scripts/lib/adapter-safety-boundaries.js +335 -0
- package/scripts/lib/adapter-technical-readiness-gate.js +205 -0
- package/scripts/lib/agent-access-governance.js +455 -0
- package/scripts/lib/agent-enforcement.js +765 -0
- package/scripts/lib/agent-policy-profile.js +210 -0
- package/scripts/lib/agent-security/action-evaluator.js +507 -0
- package/scripts/lib/agent-security/adapter-registry.js +98 -0
- package/scripts/lib/agent-security/auto-policy.js +139 -0
- package/scripts/lib/agent-security/bounded-scan.js +93 -0
- package/scripts/lib/agent-security/enforcement-adapter.js +174 -0
- package/scripts/lib/agent-security/enforcement-engine.js +1129 -0
- package/scripts/lib/agent-security/file-write-adapter.js +183 -0
- package/scripts/lib/agent-security/file-write-rules.js +178 -0
- package/scripts/lib/agent-security/index.js +3342 -0
- package/scripts/lib/agent-security/instruction-risk.js +181 -0
- package/scripts/lib/agent-security/mcp-action-adapter.js +185 -0
- package/scripts/lib/agent-security/mcp-action-rules.js +184 -0
- package/scripts/lib/agent-security/package-action-adapter.js +175 -0
- package/scripts/lib/agent-security/package-action-rules.js +233 -0
- package/scripts/lib/agent-security/performance.js +148 -0
- package/scripts/lib/agent-security/permission-minimizer.js +403 -0
- package/scripts/lib/agent-security/scan-cache.js +74 -0
- package/scripts/lib/agent-security/source-trust.js +146 -0
- package/scripts/lib/ai-install-prompt.js +288 -0
- package/scripts/lib/ai-workspace-hygiene.js +1499 -0
- package/scripts/lib/alpha-activation.js +520 -0
- package/scripts/lib/alpha-feedback.js +263 -0
- package/scripts/lib/alpha-readiness-gate.js +332 -0
- package/scripts/lib/anti-gaming.js +169 -0
- package/scripts/lib/artifact-health.js +431 -0
- package/scripts/lib/attribution.js +180 -0
- package/scripts/lib/audit.js +289 -0
- package/scripts/lib/avorelo-skill-registry.js +810 -0
- package/scripts/lib/batch-jobs.js +71 -0
- package/scripts/lib/brain-pack.js +578 -0
- package/scripts/lib/brand-boundary.js +424 -0
- package/scripts/lib/brand.js +74 -0
- package/scripts/lib/browser-capability.js +1048 -0
- package/scripts/lib/browser-proof-preflight.js +321 -0
- package/scripts/lib/cache-readiness.js +187 -0
- package/scripts/lib/canonical-reentry.js +162 -0
- package/scripts/lib/capability-packs.js +314 -0
- package/scripts/lib/capability-recommender.js +512 -0
- package/scripts/lib/capability-registry.js +1059 -0
- package/scripts/lib/carry-forward-surfacing.js +194 -0
- package/scripts/lib/ccusage-adapter.js +188 -0
- package/scripts/lib/company-loop.js +1149 -0
- package/scripts/lib/config.js +637 -0
- package/scripts/lib/context-acquisition-plan.js +287 -0
- package/scripts/lib/context-budget-guard.js +170 -0
- package/scripts/lib/context-budget-scanner.js +257 -0
- package/scripts/lib/context-optimizer.js +715 -0
- package/scripts/lib/context-reduction-plan.js +178 -0
- package/scripts/lib/context-safety.js +88 -0
- package/scripts/lib/context-savings-engine.js +158 -0
- package/scripts/lib/cost-evidence.js +254 -0
- package/scripts/lib/cross-host-install-plan.js +308 -0
- package/scripts/lib/cross-host-install-readiness.js +237 -0
- package/scripts/lib/cross-host-value-flow.js +268 -0
- package/scripts/lib/dashboard.js +900 -0
- package/scripts/lib/design-partner-feedback.js +346 -0
- package/scripts/lib/entitlements.js +100 -0
- package/scripts/lib/execution-packet.js +559 -0
- package/scripts/lib/experimentation-events.js +547 -0
- package/scripts/lib/external-capability-compliance.js +107 -0
- package/scripts/lib/external-user-simulation.js +166 -0
- package/scripts/lib/failure-recovery-readiness.js +81 -0
- package/scripts/lib/failure-recovery.js +419 -0
- package/scripts/lib/feedback-intelligence.js +537 -0
- package/scripts/lib/feedback-signals.js +205 -0
- package/scripts/lib/file-integrity.js +68 -0
- package/scripts/lib/fsx.js +127 -0
- package/scripts/lib/full-readiness-gate.js +451 -0
- package/scripts/lib/guidance-builder.js +174 -0
- package/scripts/lib/hook-apply.js +1019 -0
- package/scripts/lib/hook-baseline.js +310 -0
- package/scripts/lib/hook-config-preview.js +275 -0
- package/scripts/lib/hook-contracts.js +290 -0
- package/scripts/lib/hook-safety-boundary-readiness.js +80 -0
- package/scripts/lib/host-capability-matrix.js +351 -0
- package/scripts/lib/host-support-context.js +254 -0
- package/scripts/lib/http-hook-action.js +538 -0
- package/scripts/lib/install-ai-readiness.js +84 -0
- package/scripts/lib/install-intake-risk.js +1037 -0
- package/scripts/lib/install-journey-intelligence.js +329 -0
- package/scripts/lib/intervention-guidance.js +57 -0
- package/scripts/lib/known-limitations.js +115 -0
- package/scripts/lib/l8-path-truth.js +146 -0
- package/scripts/lib/launch-hardening-gate.js +436 -0
- package/scripts/lib/launch-readiness.js +628 -0
- package/scripts/lib/learning-memory.js +686 -0
- package/scripts/lib/lifecycle-hooks.js +802 -0
- package/scripts/lib/local-package-smoke.js +423 -0
- package/scripts/lib/local-pricing.js +299 -0
- package/scripts/lib/mcp-enforcement.js +311 -0
- package/scripts/lib/mcp-least-privilege-policy.js +303 -0
- package/scripts/lib/mcp-tool-inventory.js +388 -0
- package/scripts/lib/mcp-tool-risk.js +0 -0
- package/scripts/lib/memory.js +335 -0
- package/scripts/lib/metrics.js +699 -0
- package/scripts/lib/micro-proof.js +133 -0
- package/scripts/lib/next-run-context.js +436 -0
- package/scripts/lib/operating-value.js +1648 -0
- package/scripts/lib/optimization-v3.js +122 -0
- package/scripts/lib/orchestration/adapters/_shared.js +49 -0
- package/scripts/lib/orchestration/adapters/aider.js +18 -0
- package/scripts/lib/orchestration/adapters/claude-code.js +35 -0
- package/scripts/lib/orchestration/adapters/codex.js +35 -0
- package/scripts/lib/orchestration/adapters/gemini-cli.js +18 -0
- package/scripts/lib/orchestration/adapters/git.js +25 -0
- package/scripts/lib/orchestration/adapters/index.js +31 -0
- package/scripts/lib/orchestration/adapters/lm-studio.js +18 -0
- package/scripts/lib/orchestration/adapters/ollama.js +18 -0
- package/scripts/lib/orchestration/adapters/opencode.js +18 -0
- package/scripts/lib/orchestration/adapters/openrouter.js +18 -0
- package/scripts/lib/orchestration/adapters/test-runner.js +25 -0
- package/scripts/lib/orchestration/cli.js +438 -0
- package/scripts/lib/orchestration/execution-manager.js +279 -0
- package/scripts/lib/orchestration/handoff.js +314 -0
- package/scripts/lib/orchestration/index.js +456 -0
- package/scripts/lib/orchestration/inventory.js +47 -0
- package/scripts/lib/orchestration/model-discovery.js +498 -0
- package/scripts/lib/orchestration/model-profiler.js +170 -0
- package/scripts/lib/orchestration/model-profiles.js +252 -0
- package/scripts/lib/orchestration/model-refresh-policy.js +72 -0
- package/scripts/lib/orchestration/proof-writer.js +349 -0
- package/scripts/lib/orchestration/provider-discovery/aider.js +49 -0
- package/scripts/lib/orchestration/provider-discovery/claude-code.js +56 -0
- package/scripts/lib/orchestration/provider-discovery/codex.js +49 -0
- package/scripts/lib/orchestration/provider-discovery/common.js +186 -0
- package/scripts/lib/orchestration/provider-discovery/gemini.js +106 -0
- package/scripts/lib/orchestration/provider-discovery/lm-studio.js +118 -0
- package/scripts/lib/orchestration/provider-discovery/models-dev.js +12 -0
- package/scripts/lib/orchestration/provider-discovery/ollama.js +100 -0
- package/scripts/lib/orchestration/provider-discovery/opencode.js +47 -0
- package/scripts/lib/orchestration/provider-discovery/openrouter.js +44 -0
- package/scripts/lib/orchestration/risk-classifier.js +130 -0
- package/scripts/lib/orchestration/routing-policy.js +486 -0
- package/scripts/lib/orchestration/settings.js +112 -0
- package/scripts/lib/orchestration/state.js +165 -0
- package/scripts/lib/orchestration/verification-manager.js +138 -0
- package/scripts/lib/output-profiles.js +146 -0
- package/scripts/lib/package-content-audit.js +368 -0
- package/scripts/lib/package-runtime.js +278 -0
- package/scripts/lib/plan-surface.js +53 -0
- package/scripts/lib/plans.js +2318 -0
- package/scripts/lib/policy-provider.js +27 -0
- package/scripts/lib/prelaunch-activation-readiness.js +409 -0
- package/scripts/lib/prelaunch-evidence-store.js +816 -0
- package/scripts/lib/prelaunch-intelligence.js +869 -0
- package/scripts/lib/pricing-experiment.js +118 -0
- package/scripts/lib/pro-moment-events.js +77 -0
- package/scripts/lib/pro-moment-state.js +227 -0
- package/scripts/lib/pro-moments.js +1216 -0
- package/scripts/lib/product-learning-events.js +629 -0
- package/scripts/lib/project-profile.js +555 -0
- package/scripts/lib/prompt-compiler.js +280 -0
- package/scripts/lib/prompt-lint.js +32 -0
- package/scripts/lib/prompt-suggestions.js +52 -0
- package/scripts/lib/proof-canonical.js +398 -0
- package/scripts/lib/proof-drilldown.js +383 -0
- package/scripts/lib/proof-events.js +342 -0
- package/scripts/lib/proof-history.js +243 -0
- package/scripts/lib/proof-metrics.js +296 -0
- package/scripts/lib/proof-outcome-evidence.js +134 -0
- package/scripts/lib/proof-receipt.js +335 -0
- package/scripts/lib/proof-record.js +461 -0
- package/scripts/lib/public-activation-distribution-gate.js +258 -0
- package/scripts/lib/public-cli.js +3891 -0
- package/scripts/lib/public-distribution-truth.js +211 -0
- package/scripts/lib/public-install-claim-checker.js +294 -0
- package/scripts/lib/publish-provenance-readiness.js +283 -0
- package/scripts/lib/readiness-delta.js +218 -0
- package/scripts/lib/readiness-evidence-closure.js +196 -0
- package/scripts/lib/reentry-memory-capture.js +241 -0
- package/scripts/lib/reentry-memory-retrieval.js +302 -0
- package/scripts/lib/reentry-memory-status.js +146 -0
- package/scripts/lib/reentry-memory-store.js +178 -0
- package/scripts/lib/reentry-state.js +66 -0
- package/scripts/lib/release-candidate-bundle.js +166 -0
- package/scripts/lib/remediation.js +81 -0
- package/scripts/lib/repo-map.js +391 -0
- package/scripts/lib/run-improvements-lifecycle.js +330 -0
- package/scripts/lib/run-improvements.js +789 -0
- package/scripts/lib/runtime-decision-policy.js +387 -0
- package/scripts/lib/safe-path-engine.js +705 -0
- package/scripts/lib/safe-run-controller.js +887 -0
- package/scripts/lib/score.js +262 -0
- package/scripts/lib/seamless-enforcement.js +329 -0
- package/scripts/lib/seamless-outcome.js +689 -0
- package/scripts/lib/seamless-reality-gate.js +5043 -0
- package/scripts/lib/security-risk-classifier.js +511 -0
- package/scripts/lib/security-scan.js +384 -0
- package/scripts/lib/session-context-optimizer.js +1211 -0
- package/scripts/lib/session-timing.js +315 -0
- package/scripts/lib/skill-hygiene.js +805 -0
- package/scripts/lib/skill-packs.js +161 -0
- package/scripts/lib/skills-operating-layer.js +580 -0
- package/scripts/lib/smart-work-routing.js +768 -0
- package/scripts/lib/source-catalog.js +700 -0
- package/scripts/lib/status-value-summary.js +32 -0
- package/scripts/lib/support-bundle.js +578 -0
- package/scripts/lib/task-continuation.js +440 -0
- package/scripts/lib/test-helpers.js +15 -0
- package/scripts/lib/tier.js +38 -0
- package/scripts/lib/token-context-quality-gate.js +370 -0
- package/scripts/lib/token-cost-capture.js +187 -0
- package/scripts/lib/token-cost-intelligence.js +358 -0
- package/scripts/lib/token-efficiency-evidence.js +213 -0
- package/scripts/lib/token-evidence.js +699 -0
- package/scripts/lib/tokenish.js +17 -0
- package/scripts/lib/tool-output-sandbox.js +304 -0
- package/scripts/lib/trust-audit.js +136 -0
- package/scripts/lib/unified-events.js +396 -0
- package/scripts/lib/upgrade-interruption-recovery.js +407 -0
- package/scripts/lib/usage-ledger.js +201 -0
- package/scripts/lib/value-ledger.js +130 -0
- package/scripts/lib/value-proof-calibration.js +531 -0
- package/scripts/lib/visual-qa.js +231 -0
- package/scripts/lib/voice-alpha.js +29 -0
- package/scripts/lib/work-aware-orchestration.js +976 -0
- package/scripts/lib/work-control-receipts.js +577 -0
- package/scripts/lib/work-ledger.js +1123 -0
- package/scripts/lib/work-panel-preview.js +352 -0
- package/scripts/lib/workflow-discipline.js +280 -0
- package/scripts/lib/workflow-signals.js +419 -0
- package/scripts/lib/workspace-map.js +281 -0
- package/scripts/lib/workspace-registry.js +1367 -0
- package/scripts/lib/workspace-resolver.js +480 -0
|
@@ -0,0 +1,637 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
|
|
6
|
+
const CONFIG_VERSION = 6;
|
|
7
|
+
const TEAM_POLICY_VERSION = 2;
|
|
8
|
+
|
|
9
|
+
const ORCHESTRATION_WORKER_IDS = [
|
|
10
|
+
"claude_code",
|
|
11
|
+
"codex",
|
|
12
|
+
"gemini_cli",
|
|
13
|
+
"lm_studio",
|
|
14
|
+
"opencode",
|
|
15
|
+
"aider",
|
|
16
|
+
"ollama",
|
|
17
|
+
"openrouter_api",
|
|
18
|
+
"litellm_requesty",
|
|
19
|
+
"test_runner",
|
|
20
|
+
"git",
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
const DEFAULT_CONFIG = {
|
|
24
|
+
configVersion: CONFIG_VERSION,
|
|
25
|
+
tier: "free",
|
|
26
|
+
profile: "balanced",
|
|
27
|
+
securityMode: "ask",
|
|
28
|
+
promptLintEnabled: true,
|
|
29
|
+
loopGuardEnabled: true,
|
|
30
|
+
scanFreshnessHours: 24,
|
|
31
|
+
allowlistPath: ".claude/cco/security-allowlist.json",
|
|
32
|
+
recommendationMode: "signal-ranked",
|
|
33
|
+
ui: {
|
|
34
|
+
panelEnabled: true,
|
|
35
|
+
panelPort: 4173,
|
|
36
|
+
},
|
|
37
|
+
teamPolicyPath: ".claude/cco/team-policy.json",
|
|
38
|
+
trustMode: "baseline",
|
|
39
|
+
agentSecurity: {
|
|
40
|
+
mode: "off",
|
|
41
|
+
basicCheckEnabled: true,
|
|
42
|
+
},
|
|
43
|
+
simplifyMode: {
|
|
44
|
+
enabled: false,
|
|
45
|
+
maxContextChars: 12000,
|
|
46
|
+
maxToolOutputBytes: 18000,
|
|
47
|
+
recommendationCap: 6,
|
|
48
|
+
verbosityLevel: "compact",
|
|
49
|
+
},
|
|
50
|
+
batch: {
|
|
51
|
+
enabled: true,
|
|
52
|
+
provider: "claude",
|
|
53
|
+
mode: "headless",
|
|
54
|
+
queueLimit: 100,
|
|
55
|
+
},
|
|
56
|
+
cloud: {
|
|
57
|
+
enabled: false,
|
|
58
|
+
syncMode: "manual",
|
|
59
|
+
endpoint: "",
|
|
60
|
+
apiKeyEnv: "CCO_CLOUD_API_KEY",
|
|
61
|
+
orgId: "local-org",
|
|
62
|
+
projectId: "",
|
|
63
|
+
},
|
|
64
|
+
pricingExperiment: {
|
|
65
|
+
enabled: true,
|
|
66
|
+
protocolVersion: 1,
|
|
67
|
+
selectedModel: "pending",
|
|
68
|
+
cohort: "unassigned",
|
|
69
|
+
},
|
|
70
|
+
voice: {
|
|
71
|
+
enabled: false,
|
|
72
|
+
localFirst: true,
|
|
73
|
+
cloudFallback: true,
|
|
74
|
+
maxLatencyMs: 1200,
|
|
75
|
+
},
|
|
76
|
+
proofSystem: {
|
|
77
|
+
enabled: true,
|
|
78
|
+
microProofEnabled: true,
|
|
79
|
+
},
|
|
80
|
+
smartRouting: {
|
|
81
|
+
enabled: false,
|
|
82
|
+
},
|
|
83
|
+
orchestration: {
|
|
84
|
+
enabled: true,
|
|
85
|
+
mode: "auto_recommended",
|
|
86
|
+
allowedWorkers: {
|
|
87
|
+
claude_code: true,
|
|
88
|
+
codex: true,
|
|
89
|
+
gemini_cli: true,
|
|
90
|
+
lm_studio: true,
|
|
91
|
+
opencode: true,
|
|
92
|
+
aider: true,
|
|
93
|
+
ollama: true,
|
|
94
|
+
openrouter_api: true,
|
|
95
|
+
litellm_requesty: true,
|
|
96
|
+
test_runner: true,
|
|
97
|
+
git: true,
|
|
98
|
+
},
|
|
99
|
+
safety: {
|
|
100
|
+
blockCheapExternalHighRisk: true,
|
|
101
|
+
blockExternalSecrets: true,
|
|
102
|
+
stopAfterRepeatedFailures: true,
|
|
103
|
+
requireProofBeforeCompletion: true,
|
|
104
|
+
},
|
|
105
|
+
askBeforePremium: false,
|
|
106
|
+
inventoryTtlMinutes: 15,
|
|
107
|
+
refreshPolicy: {
|
|
108
|
+
fullRefreshIntervalHours: 72,
|
|
109
|
+
singleModelRefreshOnNewUsage: true,
|
|
110
|
+
},
|
|
111
|
+
lockTimeoutMinutes: 20,
|
|
112
|
+
maxExecutionAttempts: 2,
|
|
113
|
+
},
|
|
114
|
+
memory: {
|
|
115
|
+
enabled: true,
|
|
116
|
+
mode: "suggest",
|
|
117
|
+
maxCandidates: 5,
|
|
118
|
+
maxAutoInjectTokens: 800,
|
|
119
|
+
maxItemBytes: 8192,
|
|
120
|
+
retentionDays: 30,
|
|
121
|
+
captureSensitive: false,
|
|
122
|
+
showInStatus: true,
|
|
123
|
+
},
|
|
124
|
+
contextBudgetGuard: {
|
|
125
|
+
enabled: false,
|
|
126
|
+
profile: "balanced",
|
|
127
|
+
mode: "let_wuz_reduce_context",
|
|
128
|
+
recommendedLimitTokens: 32000,
|
|
129
|
+
maxFilesScanned: 2000,
|
|
130
|
+
maxFileBytes: 1000000,
|
|
131
|
+
maxDepth: 12,
|
|
132
|
+
warnOnly: true,
|
|
133
|
+
dashboardVisibility: "basic",
|
|
134
|
+
reductionPlan: false,
|
|
135
|
+
},
|
|
136
|
+
workflowDiscipline: {
|
|
137
|
+
enabled: true,
|
|
138
|
+
mode: "suggest",
|
|
139
|
+
maxRecommendations: 3,
|
|
140
|
+
},
|
|
141
|
+
browserCapability: {
|
|
142
|
+
allowedDomains: [],
|
|
143
|
+
blockedDomains: [],
|
|
144
|
+
sensitiveDomains: [],
|
|
145
|
+
requireApprovalForUnlistedDomains: false,
|
|
146
|
+
},
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
const DEFAULT_TEAM_POLICY = {
|
|
150
|
+
policyVersion: TEAM_POLICY_VERSION,
|
|
151
|
+
defaultProfile: null,
|
|
152
|
+
profileLock: false,
|
|
153
|
+
securityModeFloor: "ask",
|
|
154
|
+
defaultRecommendationMode: null,
|
|
155
|
+
scanFreshnessHoursFloor: 24,
|
|
156
|
+
rollupWindowDays: 7,
|
|
157
|
+
allowedSkillSources: ["local-marketplace", "workspace"],
|
|
158
|
+
blockedPatterns: [],
|
|
159
|
+
tierOverrides: {
|
|
160
|
+
free: {},
|
|
161
|
+
pro: {},
|
|
162
|
+
teams: {},
|
|
163
|
+
},
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
function configPath(cwd) {
|
|
167
|
+
return path.join(cwd, ".claude", "cco", "config.json");
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function readJsonFile(absPath, fallback) {
|
|
171
|
+
try {
|
|
172
|
+
return JSON.parse(fs.readFileSync(absPath, "utf8").replace(/^\uFEFF/, ""));
|
|
173
|
+
} catch {
|
|
174
|
+
return fallback;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function securityModeRank(mode) {
|
|
179
|
+
const rank = { off: 0, suggest: 1, ask: 2, block: 3 };
|
|
180
|
+
return rank[mode] ?? rank.ask;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function applySecurityModeFloor(mode, floor) {
|
|
184
|
+
const levels = ["off", "suggest", "ask", "block"];
|
|
185
|
+
const target = Math.max(securityModeRank(mode), securityModeRank(floor));
|
|
186
|
+
return levels[target] || "ask";
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function normalizeSubobjects(cfg) {
|
|
190
|
+
cfg.ui = { ...(DEFAULT_CONFIG.ui || {}), ...(cfg.ui || {}) };
|
|
191
|
+
cfg.agentSecurity = { ...(DEFAULT_CONFIG.agentSecurity || {}), ...(cfg.agentSecurity || {}) };
|
|
192
|
+
cfg.simplifyMode = { ...(DEFAULT_CONFIG.simplifyMode || {}), ...(cfg.simplifyMode || {}) };
|
|
193
|
+
cfg.batch = { ...(DEFAULT_CONFIG.batch || {}), ...(cfg.batch || {}) };
|
|
194
|
+
cfg.cloud = { ...(DEFAULT_CONFIG.cloud || {}), ...(cfg.cloud || {}) };
|
|
195
|
+
cfg.pricingExperiment = {
|
|
196
|
+
...(DEFAULT_CONFIG.pricingExperiment || {}),
|
|
197
|
+
...(cfg.pricingExperiment || {}),
|
|
198
|
+
};
|
|
199
|
+
cfg.voice = { ...(DEFAULT_CONFIG.voice || {}), ...(cfg.voice || {}) };
|
|
200
|
+
cfg.proofSystem = { ...(DEFAULT_CONFIG.proofSystem || {}), ...(cfg.proofSystem || {}) };
|
|
201
|
+
cfg.smartRouting = { ...(DEFAULT_CONFIG.smartRouting || {}), ...(cfg.smartRouting || {}) };
|
|
202
|
+
cfg.orchestration = { ...(DEFAULT_CONFIG.orchestration || {}), ...(cfg.orchestration || {}) };
|
|
203
|
+
cfg.orchestration.allowedWorkers = {
|
|
204
|
+
...(DEFAULT_CONFIG.orchestration?.allowedWorkers || {}),
|
|
205
|
+
...(cfg.orchestration?.allowedWorkers || {}),
|
|
206
|
+
};
|
|
207
|
+
cfg.orchestration.safety = {
|
|
208
|
+
...(DEFAULT_CONFIG.orchestration?.safety || {}),
|
|
209
|
+
...(cfg.orchestration?.safety || {}),
|
|
210
|
+
};
|
|
211
|
+
cfg.orchestration.refreshPolicy = {
|
|
212
|
+
...(DEFAULT_CONFIG.orchestration?.refreshPolicy || {}),
|
|
213
|
+
...(cfg.orchestration?.refreshPolicy || {}),
|
|
214
|
+
};
|
|
215
|
+
cfg.memory = { ...(DEFAULT_CONFIG.memory || {}), ...(cfg.memory || {}) };
|
|
216
|
+
cfg.contextBudgetGuard = { ...(DEFAULT_CONFIG.contextBudgetGuard || {}), ...(cfg.contextBudgetGuard || {}) };
|
|
217
|
+
cfg.workflowDiscipline = { ...(DEFAULT_CONFIG.workflowDiscipline || {}), ...(cfg.workflowDiscipline || {}) };
|
|
218
|
+
cfg.browserCapability = { ...(DEFAULT_CONFIG.browserCapability || {}), ...(cfg.browserCapability || {}) };
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
function migrateLegacyConfig(raw) {
|
|
222
|
+
const cfg = { ...(raw || {}) };
|
|
223
|
+
if (!cfg.configVersion) cfg.configVersion = 1;
|
|
224
|
+
|
|
225
|
+
if (typeof cfg.securityMode === "boolean") {
|
|
226
|
+
cfg.securityMode = cfg.securityMode ? "ask" : "off";
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
if (cfg.configVersion < 2) {
|
|
230
|
+
cfg.recommendationMode = cfg.recommendationMode || "signal-ranked";
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
if (cfg.configVersion < 3) {
|
|
234
|
+
cfg.tier = cfg.tier || "free";
|
|
235
|
+
cfg.teamPolicyPath = cfg.teamPolicyPath || DEFAULT_CONFIG.teamPolicyPath;
|
|
236
|
+
cfg.trustMode = cfg.trustMode || "baseline";
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
if (cfg.configVersion < 4) {
|
|
240
|
+
cfg.agentSecurity = {
|
|
241
|
+
...(DEFAULT_CONFIG.agentSecurity || {}),
|
|
242
|
+
...(cfg.agentSecurity || {}),
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
if (cfg.configVersion < 5) {
|
|
247
|
+
cfg.orchestration = {
|
|
248
|
+
...(DEFAULT_CONFIG.orchestration || {}),
|
|
249
|
+
...(cfg.orchestration || {}),
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
if (cfg.configVersion < 6) {
|
|
254
|
+
cfg.orchestration = {
|
|
255
|
+
...(DEFAULT_CONFIG.orchestration || {}),
|
|
256
|
+
...(cfg.orchestration || {}),
|
|
257
|
+
refreshPolicy: {
|
|
258
|
+
...(DEFAULT_CONFIG.orchestration?.refreshPolicy || {}),
|
|
259
|
+
...(cfg.orchestration?.refreshPolicy || {}),
|
|
260
|
+
},
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
normalizeSubobjects(cfg);
|
|
265
|
+
cfg.configVersion = CONFIG_VERSION;
|
|
266
|
+
return cfg;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
function normalizeConfig(raw) {
|
|
270
|
+
const migrated = migrateLegacyConfig(raw);
|
|
271
|
+
const cfg = {
|
|
272
|
+
...DEFAULT_CONFIG,
|
|
273
|
+
...migrated,
|
|
274
|
+
};
|
|
275
|
+
normalizeSubobjects(cfg);
|
|
276
|
+
|
|
277
|
+
if (!["free", "pro", "teams"].includes(cfg.tier)) cfg.tier = DEFAULT_CONFIG.tier;
|
|
278
|
+
if (!["cost-saver", "balanced", "quality"].includes(cfg.profile)) cfg.profile = DEFAULT_CONFIG.profile;
|
|
279
|
+
if (!["off", "suggest", "ask", "block"].includes(cfg.securityMode)) cfg.securityMode = DEFAULT_CONFIG.securityMode;
|
|
280
|
+
if (!["static", "signal-ranked"].includes(cfg.recommendationMode)) cfg.recommendationMode = DEFAULT_CONFIG.recommendationMode;
|
|
281
|
+
if (!["baseline", "strict"].includes(cfg.trustMode)) cfg.trustMode = DEFAULT_CONFIG.trustMode;
|
|
282
|
+
if (!["off", "basic", "visibility", "warn", "auto"].includes(cfg.agentSecurity.mode)) {
|
|
283
|
+
cfg.agentSecurity.mode = DEFAULT_CONFIG.agentSecurity.mode;
|
|
284
|
+
}
|
|
285
|
+
cfg.agentSecurity.basicCheckEnabled = cfg.agentSecurity.basicCheckEnabled !== false;
|
|
286
|
+
|
|
287
|
+
cfg.scanFreshnessHours = Number.isFinite(Number(cfg.scanFreshnessHours)) ? Math.max(1, Number(cfg.scanFreshnessHours)) : DEFAULT_CONFIG.scanFreshnessHours;
|
|
288
|
+
|
|
289
|
+
if (typeof cfg.allowlistPath !== "string" || !cfg.allowlistPath.trim()) cfg.allowlistPath = DEFAULT_CONFIG.allowlistPath;
|
|
290
|
+
if (typeof cfg.teamPolicyPath !== "string" || !cfg.teamPolicyPath.trim()) cfg.teamPolicyPath = DEFAULT_CONFIG.teamPolicyPath;
|
|
291
|
+
|
|
292
|
+
cfg.promptLintEnabled = cfg.promptLintEnabled !== false;
|
|
293
|
+
cfg.loopGuardEnabled = cfg.loopGuardEnabled !== false;
|
|
294
|
+
|
|
295
|
+
cfg.ui.panelEnabled = cfg.ui.panelEnabled !== false;
|
|
296
|
+
cfg.ui.panelPort = Number.isFinite(Number(cfg.ui.panelPort)) ? Math.max(1024, Number(cfg.ui.panelPort)) : DEFAULT_CONFIG.ui.panelPort;
|
|
297
|
+
|
|
298
|
+
cfg.simplifyMode.enabled = cfg.simplifyMode.enabled === true;
|
|
299
|
+
cfg.simplifyMode.maxContextChars = Number.isFinite(Number(cfg.simplifyMode.maxContextChars)) ? Math.max(4000, Number(cfg.simplifyMode.maxContextChars)) : DEFAULT_CONFIG.simplifyMode.maxContextChars;
|
|
300
|
+
cfg.simplifyMode.maxToolOutputBytes = Number.isFinite(Number(cfg.simplifyMode.maxToolOutputBytes)) ? Math.max(8000, Number(cfg.simplifyMode.maxToolOutputBytes)) : DEFAULT_CONFIG.simplifyMode.maxToolOutputBytes;
|
|
301
|
+
cfg.simplifyMode.recommendationCap = Number.isFinite(Number(cfg.simplifyMode.recommendationCap)) ? Math.max(1, Number(cfg.simplifyMode.recommendationCap)) : DEFAULT_CONFIG.simplifyMode.recommendationCap;
|
|
302
|
+
if (!["compact", "standard", "verbose"].includes(cfg.simplifyMode.verbosityLevel)) cfg.simplifyMode.verbosityLevel = DEFAULT_CONFIG.simplifyMode.verbosityLevel;
|
|
303
|
+
|
|
304
|
+
cfg.batch.enabled = cfg.batch.enabled !== false;
|
|
305
|
+
if (!["claude", "mixed"].includes(cfg.batch.provider)) cfg.batch.provider = DEFAULT_CONFIG.batch.provider;
|
|
306
|
+
if (!["headless", "api_batch"].includes(cfg.batch.mode)) cfg.batch.mode = DEFAULT_CONFIG.batch.mode;
|
|
307
|
+
cfg.batch.queueLimit = Number.isFinite(Number(cfg.batch.queueLimit)) ? Math.max(10, Number(cfg.batch.queueLimit)) : DEFAULT_CONFIG.batch.queueLimit;
|
|
308
|
+
|
|
309
|
+
cfg.cloud.enabled = cfg.cloud.enabled === true;
|
|
310
|
+
if (!["manual", "auto"].includes(cfg.cloud.syncMode)) cfg.cloud.syncMode = DEFAULT_CONFIG.cloud.syncMode;
|
|
311
|
+
if (typeof cfg.cloud.endpoint !== "string") cfg.cloud.endpoint = DEFAULT_CONFIG.cloud.endpoint;
|
|
312
|
+
if (typeof cfg.cloud.apiKeyEnv !== "string" || !cfg.cloud.apiKeyEnv.trim()) cfg.cloud.apiKeyEnv = DEFAULT_CONFIG.cloud.apiKeyEnv;
|
|
313
|
+
if (typeof cfg.cloud.orgId !== "string" || !cfg.cloud.orgId.trim()) cfg.cloud.orgId = DEFAULT_CONFIG.cloud.orgId;
|
|
314
|
+
if (typeof cfg.cloud.projectId !== "string") cfg.cloud.projectId = DEFAULT_CONFIG.cloud.projectId;
|
|
315
|
+
|
|
316
|
+
cfg.pricingExperiment.enabled = cfg.pricingExperiment.enabled !== false;
|
|
317
|
+
cfg.pricingExperiment.protocolVersion = Number.isFinite(Number(cfg.pricingExperiment.protocolVersion))
|
|
318
|
+
? Math.max(1, Number(cfg.pricingExperiment.protocolVersion))
|
|
319
|
+
: DEFAULT_CONFIG.pricingExperiment.protocolVersion;
|
|
320
|
+
if (!["pending", "seat_plus_outcome", "outcome_forward"].includes(cfg.pricingExperiment.selectedModel)) {
|
|
321
|
+
cfg.pricingExperiment.selectedModel = DEFAULT_CONFIG.pricingExperiment.selectedModel;
|
|
322
|
+
}
|
|
323
|
+
if (typeof cfg.pricingExperiment.cohort !== "string" || !cfg.pricingExperiment.cohort.trim()) {
|
|
324
|
+
cfg.pricingExperiment.cohort = DEFAULT_CONFIG.pricingExperiment.cohort;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
cfg.voice.enabled = cfg.voice.enabled === true;
|
|
328
|
+
cfg.voice.localFirst = cfg.voice.localFirst !== false;
|
|
329
|
+
cfg.voice.cloudFallback = cfg.voice.cloudFallback !== false;
|
|
330
|
+
cfg.voice.maxLatencyMs = Number.isFinite(Number(cfg.voice.maxLatencyMs)) ? Math.max(100, Number(cfg.voice.maxLatencyMs)) : DEFAULT_CONFIG.voice.maxLatencyMs;
|
|
331
|
+
|
|
332
|
+
cfg.proofSystem.enabled = cfg.proofSystem.enabled !== false;
|
|
333
|
+
cfg.proofSystem.microProofEnabled = cfg.proofSystem.microProofEnabled !== false;
|
|
334
|
+
|
|
335
|
+
cfg.smartRouting.enabled = cfg.smartRouting.enabled === true;
|
|
336
|
+
|
|
337
|
+
cfg.orchestration.enabled = cfg.orchestration.enabled !== false;
|
|
338
|
+
if (![
|
|
339
|
+
"auto_recommended",
|
|
340
|
+
"prefer_lowest_cost",
|
|
341
|
+
"prefer_highest_quality",
|
|
342
|
+
"local_private_only",
|
|
343
|
+
"ask_before_premium",
|
|
344
|
+
"premium_only_for_risky",
|
|
345
|
+
"disabled",
|
|
346
|
+
].includes(cfg.orchestration.mode)) {
|
|
347
|
+
cfg.orchestration.mode = DEFAULT_CONFIG.orchestration.mode;
|
|
348
|
+
}
|
|
349
|
+
if (cfg.orchestration.mode === "disabled") {
|
|
350
|
+
cfg.orchestration.enabled = false;
|
|
351
|
+
} else if (cfg.orchestration.enabled === false) {
|
|
352
|
+
cfg.orchestration.mode = "disabled";
|
|
353
|
+
}
|
|
354
|
+
ORCHESTRATION_WORKER_IDS.forEach((workerId) => {
|
|
355
|
+
cfg.orchestration.allowedWorkers[workerId] = cfg.orchestration.allowedWorkers[workerId] !== false;
|
|
356
|
+
});
|
|
357
|
+
cfg.orchestration.safety.blockCheapExternalHighRisk = cfg.orchestration.safety.blockCheapExternalHighRisk !== false;
|
|
358
|
+
cfg.orchestration.safety.blockExternalSecrets = cfg.orchestration.safety.blockExternalSecrets !== false;
|
|
359
|
+
cfg.orchestration.safety.stopAfterRepeatedFailures = cfg.orchestration.safety.stopAfterRepeatedFailures !== false;
|
|
360
|
+
cfg.orchestration.safety.requireProofBeforeCompletion = cfg.orchestration.safety.requireProofBeforeCompletion !== false;
|
|
361
|
+
cfg.orchestration.askBeforePremium = cfg.orchestration.askBeforePremium === true;
|
|
362
|
+
cfg.orchestration.inventoryTtlMinutes = Number.isFinite(Number(cfg.orchestration.inventoryTtlMinutes))
|
|
363
|
+
? Math.max(1, Math.min(1440, Number(cfg.orchestration.inventoryTtlMinutes)))
|
|
364
|
+
: DEFAULT_CONFIG.orchestration.inventoryTtlMinutes;
|
|
365
|
+
cfg.orchestration.refreshPolicy.fullRefreshIntervalHours = Number.isFinite(Number(cfg.orchestration.refreshPolicy?.fullRefreshIntervalHours))
|
|
366
|
+
? Math.max(1, Math.min(24 * 30, Number(cfg.orchestration.refreshPolicy.fullRefreshIntervalHours)))
|
|
367
|
+
: DEFAULT_CONFIG.orchestration.refreshPolicy.fullRefreshIntervalHours;
|
|
368
|
+
cfg.orchestration.refreshPolicy.singleModelRefreshOnNewUsage = cfg.orchestration.refreshPolicy?.singleModelRefreshOnNewUsage !== false;
|
|
369
|
+
cfg.orchestration.lockTimeoutMinutes = Number.isFinite(Number(cfg.orchestration.lockTimeoutMinutes))
|
|
370
|
+
? Math.max(1, Math.min(180, Number(cfg.orchestration.lockTimeoutMinutes)))
|
|
371
|
+
: DEFAULT_CONFIG.orchestration.lockTimeoutMinutes;
|
|
372
|
+
cfg.orchestration.maxExecutionAttempts = Number.isFinite(Number(cfg.orchestration.maxExecutionAttempts))
|
|
373
|
+
? Math.max(1, Math.min(5, Number(cfg.orchestration.maxExecutionAttempts)))
|
|
374
|
+
: DEFAULT_CONFIG.orchestration.maxExecutionAttempts;
|
|
375
|
+
|
|
376
|
+
cfg.memory.enabled = cfg.memory.enabled !== false;
|
|
377
|
+
if (!["off", "suggest", "auto_safe"].includes(cfg.memory.mode)) cfg.memory.mode = DEFAULT_CONFIG.memory.mode;
|
|
378
|
+
cfg.memory.maxCandidates = Number.isFinite(Number(cfg.memory.maxCandidates)) ? Math.max(1, Number(cfg.memory.maxCandidates)) : DEFAULT_CONFIG.memory.maxCandidates;
|
|
379
|
+
cfg.memory.maxAutoInjectTokens = Number.isFinite(Number(cfg.memory.maxAutoInjectTokens)) ? Math.max(100, Number(cfg.memory.maxAutoInjectTokens)) : DEFAULT_CONFIG.memory.maxAutoInjectTokens;
|
|
380
|
+
cfg.memory.maxItemBytes = Number.isFinite(Number(cfg.memory.maxItemBytes)) ? Math.max(1024, Number(cfg.memory.maxItemBytes)) : DEFAULT_CONFIG.memory.maxItemBytes;
|
|
381
|
+
cfg.memory.retentionDays = Number.isFinite(Number(cfg.memory.retentionDays)) ? Math.max(1, Number(cfg.memory.retentionDays)) : DEFAULT_CONFIG.memory.retentionDays;
|
|
382
|
+
cfg.memory.captureSensitive = cfg.memory.captureSensitive === true;
|
|
383
|
+
cfg.memory.showInStatus = cfg.memory.showInStatus !== false;
|
|
384
|
+
|
|
385
|
+
cfg.contextBudgetGuard.enabled = cfg.contextBudgetGuard.enabled === true;
|
|
386
|
+
if (!["cost-saver", "balanced", "quality"].includes(cfg.contextBudgetGuard.profile)) {
|
|
387
|
+
cfg.contextBudgetGuard.profile = DEFAULT_CONFIG.contextBudgetGuard.profile;
|
|
388
|
+
}
|
|
389
|
+
if (!["let_wuz_reduce_context", "block_large_context", "allow_full_context"].includes(cfg.contextBudgetGuard.mode)) {
|
|
390
|
+
cfg.contextBudgetGuard.mode = DEFAULT_CONFIG.contextBudgetGuard.mode;
|
|
391
|
+
}
|
|
392
|
+
cfg.contextBudgetGuard.recommendedLimitTokens = Number.isFinite(Number(cfg.contextBudgetGuard.recommendedLimitTokens))
|
|
393
|
+
? Math.max(1000, Number(cfg.contextBudgetGuard.recommendedLimitTokens))
|
|
394
|
+
: DEFAULT_CONFIG.contextBudgetGuard.recommendedLimitTokens;
|
|
395
|
+
cfg.contextBudgetGuard.maxFilesScanned = Number.isFinite(Number(cfg.contextBudgetGuard.maxFilesScanned))
|
|
396
|
+
? Math.max(1, Math.min(10000, Number(cfg.contextBudgetGuard.maxFilesScanned)))
|
|
397
|
+
: DEFAULT_CONFIG.contextBudgetGuard.maxFilesScanned;
|
|
398
|
+
cfg.contextBudgetGuard.maxFileBytes = Number.isFinite(Number(cfg.contextBudgetGuard.maxFileBytes))
|
|
399
|
+
? Math.max(1024, Number(cfg.contextBudgetGuard.maxFileBytes))
|
|
400
|
+
: DEFAULT_CONFIG.contextBudgetGuard.maxFileBytes;
|
|
401
|
+
cfg.contextBudgetGuard.maxDepth = Number.isFinite(Number(cfg.contextBudgetGuard.maxDepth))
|
|
402
|
+
? Math.max(1, Math.min(50, Number(cfg.contextBudgetGuard.maxDepth)))
|
|
403
|
+
: DEFAULT_CONFIG.contextBudgetGuard.maxDepth;
|
|
404
|
+
cfg.contextBudgetGuard.warnOnly = cfg.contextBudgetGuard.warnOnly !== false;
|
|
405
|
+
if (!["basic", "advanced", "off"].includes(cfg.contextBudgetGuard.dashboardVisibility)) {
|
|
406
|
+
cfg.contextBudgetGuard.dashboardVisibility = DEFAULT_CONFIG.contextBudgetGuard.dashboardVisibility;
|
|
407
|
+
}
|
|
408
|
+
cfg.contextBudgetGuard.reductionPlan = cfg.contextBudgetGuard.reductionPlan === true;
|
|
409
|
+
|
|
410
|
+
cfg.workflowDiscipline.enabled = cfg.workflowDiscipline.enabled !== false;
|
|
411
|
+
if (!["off", "suggest", "warn"].includes(cfg.workflowDiscipline.mode)) {
|
|
412
|
+
cfg.workflowDiscipline.mode = DEFAULT_CONFIG.workflowDiscipline.mode;
|
|
413
|
+
}
|
|
414
|
+
cfg.workflowDiscipline.maxRecommendations = Number.isFinite(Number(cfg.workflowDiscipline.maxRecommendations))
|
|
415
|
+
? Math.max(1, Math.min(10, Number(cfg.workflowDiscipline.maxRecommendations)))
|
|
416
|
+
: DEFAULT_CONFIG.workflowDiscipline.maxRecommendations;
|
|
417
|
+
|
|
418
|
+
if (!Array.isArray(cfg.browserCapability.allowedDomains)) cfg.browserCapability.allowedDomains = [];
|
|
419
|
+
if (!Array.isArray(cfg.browserCapability.blockedDomains)) cfg.browserCapability.blockedDomains = [];
|
|
420
|
+
if (!Array.isArray(cfg.browserCapability.sensitiveDomains)) cfg.browserCapability.sensitiveDomains = [];
|
|
421
|
+
cfg.browserCapability.requireApprovalForUnlistedDomains = cfg.browserCapability.requireApprovalForUnlistedDomains === true;
|
|
422
|
+
|
|
423
|
+
cfg.configVersion = CONFIG_VERSION;
|
|
424
|
+
return cfg;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
function writeProjectConfig(cwd, cfg) {
|
|
428
|
+
const p = configPath(cwd);
|
|
429
|
+
const normalized = normalizeConfig(cfg);
|
|
430
|
+
fs.mkdirSync(path.dirname(p), { recursive: true });
|
|
431
|
+
fs.writeFileSync(p, JSON.stringify(normalized, null, 2), "utf8");
|
|
432
|
+
return normalized;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
function ensureProjectConfig(cwd) {
|
|
436
|
+
const p = configPath(cwd);
|
|
437
|
+
const raw = readJsonFile(p, {});
|
|
438
|
+
const normalized = normalizeConfig(raw);
|
|
439
|
+
const existing = Object.keys(raw).length ? JSON.stringify(raw, null, 2) : null;
|
|
440
|
+
const next = JSON.stringify(normalized, null, 2);
|
|
441
|
+
|
|
442
|
+
if (existing !== next) {
|
|
443
|
+
fs.mkdirSync(path.dirname(p), { recursive: true });
|
|
444
|
+
fs.writeFileSync(p, next, "utf8");
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
return normalized;
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
function readProjectConfig(cwd) {
|
|
451
|
+
const p = configPath(cwd);
|
|
452
|
+
const raw = readJsonFile(p, {});
|
|
453
|
+
return normalizeConfig(raw);
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
function normalizeTeamPolicy(raw) {
|
|
457
|
+
const policy = {
|
|
458
|
+
...DEFAULT_TEAM_POLICY,
|
|
459
|
+
...(raw || {}),
|
|
460
|
+
tierOverrides: {
|
|
461
|
+
...(DEFAULT_TEAM_POLICY.tierOverrides || {}),
|
|
462
|
+
...((raw && raw.tierOverrides) || {}),
|
|
463
|
+
},
|
|
464
|
+
};
|
|
465
|
+
|
|
466
|
+
if (!["off", "suggest", "ask", "block"].includes(policy.securityModeFloor)) {
|
|
467
|
+
policy.securityModeFloor = DEFAULT_TEAM_POLICY.securityModeFloor;
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
if (policy.defaultProfile !== null && !["cost-saver", "balanced", "quality"].includes(policy.defaultProfile)) {
|
|
471
|
+
policy.defaultProfile = null;
|
|
472
|
+
}
|
|
473
|
+
policy.profileLock = policy.profileLock === true;
|
|
474
|
+
|
|
475
|
+
if (policy.defaultRecommendationMode !== null && !["static", "signal-ranked"].includes(policy.defaultRecommendationMode)) {
|
|
476
|
+
policy.defaultRecommendationMode = null;
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
policy.scanFreshnessHoursFloor = Number.isFinite(Number(policy.scanFreshnessHoursFloor))
|
|
480
|
+
? Math.max(1, Number(policy.scanFreshnessHoursFloor))
|
|
481
|
+
: DEFAULT_TEAM_POLICY.scanFreshnessHoursFloor;
|
|
482
|
+
|
|
483
|
+
policy.rollupWindowDays = Number.isFinite(Number(policy.rollupWindowDays))
|
|
484
|
+
? Math.min(30, Math.max(1, Number(policy.rollupWindowDays)))
|
|
485
|
+
: DEFAULT_TEAM_POLICY.rollupWindowDays;
|
|
486
|
+
|
|
487
|
+
if (!Array.isArray(policy.allowedSkillSources)) policy.allowedSkillSources = [...DEFAULT_TEAM_POLICY.allowedSkillSources];
|
|
488
|
+
if (!Array.isArray(policy.blockedPatterns)) policy.blockedPatterns = [];
|
|
489
|
+
|
|
490
|
+
["free", "pro", "teams"].forEach((tier) => {
|
|
491
|
+
if (!policy.tierOverrides[tier] || typeof policy.tierOverrides[tier] !== "object") {
|
|
492
|
+
policy.tierOverrides[tier] = {};
|
|
493
|
+
}
|
|
494
|
+
});
|
|
495
|
+
|
|
496
|
+
policy.policyVersion = TEAM_POLICY_VERSION;
|
|
497
|
+
return policy;
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
function teamPolicyPath(cwd, config) {
|
|
501
|
+
return path.join(cwd, config?.teamPolicyPath || DEFAULT_CONFIG.teamPolicyPath);
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
function ensureTeamPolicy(cwd, config) {
|
|
505
|
+
const p = teamPolicyPath(cwd, config);
|
|
506
|
+
const existing = readJsonFile(p, null);
|
|
507
|
+
if (existing) return normalizeTeamPolicy(existing);
|
|
508
|
+
|
|
509
|
+
fs.mkdirSync(path.dirname(p), { recursive: true });
|
|
510
|
+
fs.writeFileSync(p, JSON.stringify(DEFAULT_TEAM_POLICY, null, 2), "utf8");
|
|
511
|
+
return normalizeTeamPolicy(DEFAULT_TEAM_POLICY);
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
function readTeamPolicy(cwd, config) {
|
|
515
|
+
const p = teamPolicyPath(cwd, config);
|
|
516
|
+
const raw = readJsonFile(p, DEFAULT_TEAM_POLICY);
|
|
517
|
+
return normalizeTeamPolicy(raw);
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
function shouldApplyProfileDefault(base, policy) {
|
|
521
|
+
if (!policy.defaultProfile) return false;
|
|
522
|
+
if (policy.profileLock) return true;
|
|
523
|
+
return base.profile === DEFAULT_CONFIG.profile;
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
function shouldApplyRecommendationDefault(base, policy) {
|
|
527
|
+
if (!policy.defaultRecommendationMode) return false;
|
|
528
|
+
if (policy.profileLock) return true;
|
|
529
|
+
return base.recommendationMode === DEFAULT_CONFIG.recommendationMode;
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
function applyTeamPolicyWithMeta(config, policy) {
|
|
533
|
+
const base = normalizeConfig(config);
|
|
534
|
+
const p = normalizeTeamPolicy(policy);
|
|
535
|
+
let merged = { ...base };
|
|
536
|
+
const teamDefaultsApplied = {
|
|
537
|
+
profile: false,
|
|
538
|
+
profileSource: null,
|
|
539
|
+
securityModeFloor: false,
|
|
540
|
+
recommendationMode: false,
|
|
541
|
+
scanFreshnessHoursFloor: false,
|
|
542
|
+
tierOverride: false,
|
|
543
|
+
rollupWindowDays: p.rollupWindowDays,
|
|
544
|
+
};
|
|
545
|
+
|
|
546
|
+
if (shouldApplyProfileDefault(base, p)) {
|
|
547
|
+
teamDefaultsApplied.profile = merged.profile !== p.defaultProfile;
|
|
548
|
+
teamDefaultsApplied.profileSource = p.profileLock ? "team-lock" : "team-fallback";
|
|
549
|
+
merged.profile = p.defaultProfile;
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
const preFloorSecurity = merged.securityMode;
|
|
553
|
+
merged.securityMode = applySecurityModeFloor(merged.securityMode, p.securityModeFloor);
|
|
554
|
+
teamDefaultsApplied.securityModeFloor = preFloorSecurity !== merged.securityMode;
|
|
555
|
+
|
|
556
|
+
if (shouldApplyRecommendationDefault(base, p)) {
|
|
557
|
+
teamDefaultsApplied.recommendationMode = merged.recommendationMode !== p.defaultRecommendationMode;
|
|
558
|
+
merged.recommendationMode = p.defaultRecommendationMode;
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
const preScanFreshness = merged.scanFreshnessHours;
|
|
562
|
+
merged.scanFreshnessHours = Math.max(Number(merged.scanFreshnessHours || 1), Number(p.scanFreshnessHoursFloor || 1));
|
|
563
|
+
teamDefaultsApplied.scanFreshnessHoursFloor = preScanFreshness !== merged.scanFreshnessHours;
|
|
564
|
+
|
|
565
|
+
const tierOverride = p.tierOverrides?.[merged.tier] || {};
|
|
566
|
+
teamDefaultsApplied.tierOverride = Object.keys(tierOverride).length > 0;
|
|
567
|
+
merged = normalizeConfig({
|
|
568
|
+
...merged,
|
|
569
|
+
...tierOverride,
|
|
570
|
+
ui: { ...merged.ui, ...(tierOverride.ui || {}) },
|
|
571
|
+
simplifyMode: { ...merged.simplifyMode, ...(tierOverride.simplifyMode || {}) },
|
|
572
|
+
batch: { ...merged.batch, ...(tierOverride.batch || {}) },
|
|
573
|
+
cloud: { ...merged.cloud, ...(tierOverride.cloud || {}) },
|
|
574
|
+
pricingExperiment: { ...merged.pricingExperiment, ...(tierOverride.pricingExperiment || {}) },
|
|
575
|
+
voice: { ...merged.voice, ...(tierOverride.voice || {}) },
|
|
576
|
+
});
|
|
577
|
+
|
|
578
|
+
return { config: merged, teamDefaultsApplied };
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
function applyTeamPolicy(config, policy) {
|
|
582
|
+
return applyTeamPolicyWithMeta(config, policy).config;
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
function getEffectiveConfig(cwd) {
|
|
586
|
+
const projectConfig = readProjectConfig(cwd);
|
|
587
|
+
const teamPolicy = readTeamPolicy(cwd, projectConfig);
|
|
588
|
+
const result = applyTeamPolicyWithMeta(projectConfig, teamPolicy);
|
|
589
|
+
return {
|
|
590
|
+
projectConfig,
|
|
591
|
+
teamPolicy,
|
|
592
|
+
config: result.config,
|
|
593
|
+
teamDefaultsApplied: result.teamDefaultsApplied,
|
|
594
|
+
};
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
function writeTeamPolicy(cwd, config, nextPolicy) {
|
|
598
|
+
const p = teamPolicyPath(cwd, config);
|
|
599
|
+
const normalized = normalizeTeamPolicy(nextPolicy);
|
|
600
|
+
fs.mkdirSync(path.dirname(p), { recursive: true });
|
|
601
|
+
fs.writeFileSync(p, JSON.stringify(normalized, null, 2), "utf8");
|
|
602
|
+
return normalized;
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
function readSecurityAllowlist(cwd, config) {
|
|
606
|
+
const rel = config?.allowlistPath || DEFAULT_CONFIG.allowlistPath;
|
|
607
|
+
const p = path.join(cwd, rel);
|
|
608
|
+
const raw = readJsonFile(p, { reasonCodes: [], pathPatterns: [] });
|
|
609
|
+
|
|
610
|
+
return {
|
|
611
|
+
reasonCodes: Array.isArray(raw.reasonCodes) ? raw.reasonCodes.map(String) : [],
|
|
612
|
+
pathPatterns: Array.isArray(raw.pathPatterns) ? raw.pathPatterns.map(String) : [],
|
|
613
|
+
};
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
module.exports = {
|
|
617
|
+
CONFIG_VERSION,
|
|
618
|
+
TEAM_POLICY_VERSION,
|
|
619
|
+
DEFAULT_CONFIG,
|
|
620
|
+
DEFAULT_TEAM_POLICY,
|
|
621
|
+
ORCHESTRATION_WORKER_IDS,
|
|
622
|
+
configPath,
|
|
623
|
+
normalizeConfig,
|
|
624
|
+
ensureProjectConfig,
|
|
625
|
+
readProjectConfig,
|
|
626
|
+
writeProjectConfig,
|
|
627
|
+
normalizeTeamPolicy,
|
|
628
|
+
readTeamPolicy,
|
|
629
|
+
ensureTeamPolicy,
|
|
630
|
+
writeTeamPolicy,
|
|
631
|
+
applyTeamPolicy,
|
|
632
|
+
applyTeamPolicyWithMeta,
|
|
633
|
+
getEffectiveConfig,
|
|
634
|
+
readSecurityAllowlist,
|
|
635
|
+
securityModeRank,
|
|
636
|
+
applySecurityModeFloor,
|
|
637
|
+
};
|