avorelo 0.1.0 → 0.3.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 +23 -16
- package/README.md +90 -51
- package/bin/avorelo.mjs +7 -0
- package/dist/avorelo.mjs +19741 -0
- package/package.json +135 -120
- package/bin/avorelo +0 -9
- package/scripts/README.md +0 -40
- package/scripts/cco-dashboard.js +0 -252
- package/scripts/cco-status.js +0 -430
- package/scripts/lib/activation/account-state.js +0 -37
- package/scripts/lib/activation/activation-runner.js +0 -546
- package/scripts/lib/activation/activation-self-healing.js +0 -480
- package/scripts/lib/activation/activation-state.js +0 -83
- package/scripts/lib/activation/activation-summary.js +0 -191
- package/scripts/lib/activation/adapters/claude-code.js +0 -77
- package/scripts/lib/activation/adapters/codex-cli.js +0 -52
- package/scripts/lib/activation/adapters/cursor.js +0 -37
- package/scripts/lib/activation/adapters/github-agent.js +0 -39
- package/scripts/lib/activation/adapters/terminal.js +0 -42
- package/scripts/lib/activation/adapters/vscode.js +0 -39
- package/scripts/lib/activation/adapters/windsurf.js +0 -37
- package/scripts/lib/activation/ai-surface-detector.js +0 -151
- package/scripts/lib/activation/connect-account.js +0 -145
- package/scripts/lib/activation/detect-environment.js +0 -75
- package/scripts/lib/activation/detect-hosts.js +0 -62
- package/scripts/lib/activation/format-activation-output.js +0 -109
- package/scripts/lib/activation/next-action.js +0 -43
- package/scripts/lib/activation/repair-engine.js +0 -219
- package/scripts/lib/activation-distribution-readiness.js +0 -507
- package/scripts/lib/adapter-conformance.js +0 -176
- package/scripts/lib/adapter-readiness.js +0 -417
- package/scripts/lib/adapter-safety-boundaries.js +0 -335
- package/scripts/lib/adapter-technical-readiness-gate.js +0 -205
- package/scripts/lib/agent-access-governance.js +0 -455
- package/scripts/lib/agent-enforcement.js +0 -765
- package/scripts/lib/agent-policy-profile.js +0 -210
- package/scripts/lib/agent-security/action-evaluator.js +0 -507
- package/scripts/lib/agent-security/adapter-registry.js +0 -98
- package/scripts/lib/agent-security/auto-policy.js +0 -139
- package/scripts/lib/agent-security/bounded-scan.js +0 -93
- package/scripts/lib/agent-security/enforcement-adapter.js +0 -174
- package/scripts/lib/agent-security/enforcement-engine.js +0 -1129
- package/scripts/lib/agent-security/file-write-adapter.js +0 -183
- package/scripts/lib/agent-security/file-write-rules.js +0 -178
- package/scripts/lib/agent-security/index.js +0 -3342
- package/scripts/lib/agent-security/instruction-risk.js +0 -181
- package/scripts/lib/agent-security/mcp-action-adapter.js +0 -185
- package/scripts/lib/agent-security/mcp-action-rules.js +0 -184
- package/scripts/lib/agent-security/package-action-adapter.js +0 -175
- package/scripts/lib/agent-security/package-action-rules.js +0 -233
- package/scripts/lib/agent-security/performance.js +0 -148
- package/scripts/lib/agent-security/permission-minimizer.js +0 -403
- package/scripts/lib/agent-security/scan-cache.js +0 -74
- package/scripts/lib/agent-security/source-trust.js +0 -146
- package/scripts/lib/ai-install-prompt.js +0 -288
- package/scripts/lib/ai-workspace-hygiene.js +0 -1499
- package/scripts/lib/alpha-activation.js +0 -520
- package/scripts/lib/alpha-feedback.js +0 -263
- package/scripts/lib/alpha-readiness-gate.js +0 -332
- package/scripts/lib/anti-gaming.js +0 -169
- package/scripts/lib/artifact-health.js +0 -431
- package/scripts/lib/attribution.js +0 -180
- package/scripts/lib/audit.js +0 -289
- package/scripts/lib/avorelo-skill-registry.js +0 -810
- package/scripts/lib/batch-jobs.js +0 -71
- package/scripts/lib/brain-pack.js +0 -578
- package/scripts/lib/brand-boundary.js +0 -424
- package/scripts/lib/brand.js +0 -74
- package/scripts/lib/browser-capability.js +0 -1048
- package/scripts/lib/browser-proof-preflight.js +0 -321
- package/scripts/lib/cache-readiness.js +0 -187
- package/scripts/lib/canonical-reentry.js +0 -162
- package/scripts/lib/capability-packs.js +0 -314
- package/scripts/lib/capability-recommender.js +0 -512
- package/scripts/lib/capability-registry.js +0 -1059
- package/scripts/lib/carry-forward-surfacing.js +0 -194
- package/scripts/lib/ccusage-adapter.js +0 -188
- package/scripts/lib/company-loop.js +0 -1149
- package/scripts/lib/config.js +0 -637
- package/scripts/lib/context-acquisition-plan.js +0 -287
- package/scripts/lib/context-budget-guard.js +0 -170
- package/scripts/lib/context-budget-scanner.js +0 -257
- package/scripts/lib/context-optimizer.js +0 -715
- package/scripts/lib/context-reduction-plan.js +0 -178
- package/scripts/lib/context-safety.js +0 -88
- package/scripts/lib/context-savings-engine.js +0 -158
- package/scripts/lib/cost-evidence.js +0 -254
- package/scripts/lib/cross-host-install-plan.js +0 -308
- package/scripts/lib/cross-host-install-readiness.js +0 -237
- package/scripts/lib/cross-host-value-flow.js +0 -268
- package/scripts/lib/dashboard.js +0 -900
- package/scripts/lib/design-partner-feedback.js +0 -346
- package/scripts/lib/entitlements.js +0 -100
- package/scripts/lib/execution-packet.js +0 -559
- package/scripts/lib/experimentation-events.js +0 -547
- package/scripts/lib/external-capability-compliance.js +0 -107
- package/scripts/lib/external-user-simulation.js +0 -166
- package/scripts/lib/failure-recovery-readiness.js +0 -81
- package/scripts/lib/failure-recovery.js +0 -419
- package/scripts/lib/feedback-intelligence.js +0 -537
- package/scripts/lib/feedback-signals.js +0 -205
- package/scripts/lib/file-integrity.js +0 -68
- package/scripts/lib/fsx.js +0 -127
- package/scripts/lib/full-readiness-gate.js +0 -451
- package/scripts/lib/guidance-builder.js +0 -174
- package/scripts/lib/hook-apply.js +0 -1019
- package/scripts/lib/hook-baseline.js +0 -310
- package/scripts/lib/hook-config-preview.js +0 -275
- package/scripts/lib/hook-contracts.js +0 -290
- package/scripts/lib/hook-safety-boundary-readiness.js +0 -80
- package/scripts/lib/host-capability-matrix.js +0 -351
- package/scripts/lib/host-support-context.js +0 -254
- package/scripts/lib/http-hook-action.js +0 -538
- package/scripts/lib/install-ai-readiness.js +0 -84
- package/scripts/lib/install-intake-risk.js +0 -1037
- package/scripts/lib/install-journey-intelligence.js +0 -329
- package/scripts/lib/intervention-guidance.js +0 -57
- package/scripts/lib/known-limitations.js +0 -115
- package/scripts/lib/l8-path-truth.js +0 -146
- package/scripts/lib/launch-hardening-gate.js +0 -436
- package/scripts/lib/launch-readiness.js +0 -628
- package/scripts/lib/learning-memory.js +0 -686
- package/scripts/lib/lifecycle-hooks.js +0 -802
- package/scripts/lib/local-package-smoke.js +0 -423
- package/scripts/lib/local-pricing.js +0 -299
- package/scripts/lib/mcp-enforcement.js +0 -311
- package/scripts/lib/mcp-least-privilege-policy.js +0 -303
- package/scripts/lib/mcp-tool-inventory.js +0 -388
- package/scripts/lib/mcp-tool-risk.js +0 -0
- package/scripts/lib/memory.js +0 -335
- package/scripts/lib/metrics.js +0 -699
- package/scripts/lib/micro-proof.js +0 -133
- package/scripts/lib/next-run-context.js +0 -436
- package/scripts/lib/operating-value.js +0 -1648
- package/scripts/lib/optimization-v3.js +0 -122
- package/scripts/lib/orchestration/adapters/_shared.js +0 -49
- package/scripts/lib/orchestration/adapters/aider.js +0 -18
- package/scripts/lib/orchestration/adapters/claude-code.js +0 -35
- package/scripts/lib/orchestration/adapters/codex.js +0 -35
- package/scripts/lib/orchestration/adapters/gemini-cli.js +0 -18
- package/scripts/lib/orchestration/adapters/git.js +0 -25
- package/scripts/lib/orchestration/adapters/index.js +0 -31
- package/scripts/lib/orchestration/adapters/lm-studio.js +0 -18
- package/scripts/lib/orchestration/adapters/ollama.js +0 -18
- package/scripts/lib/orchestration/adapters/opencode.js +0 -18
- package/scripts/lib/orchestration/adapters/openrouter.js +0 -18
- package/scripts/lib/orchestration/adapters/test-runner.js +0 -25
- package/scripts/lib/orchestration/cli.js +0 -438
- package/scripts/lib/orchestration/execution-manager.js +0 -279
- package/scripts/lib/orchestration/handoff.js +0 -314
- package/scripts/lib/orchestration/index.js +0 -456
- package/scripts/lib/orchestration/inventory.js +0 -47
- package/scripts/lib/orchestration/model-discovery.js +0 -498
- package/scripts/lib/orchestration/model-profiler.js +0 -170
- package/scripts/lib/orchestration/model-profiles.js +0 -252
- package/scripts/lib/orchestration/model-refresh-policy.js +0 -72
- package/scripts/lib/orchestration/proof-writer.js +0 -349
- package/scripts/lib/orchestration/provider-discovery/aider.js +0 -49
- package/scripts/lib/orchestration/provider-discovery/claude-code.js +0 -56
- package/scripts/lib/orchestration/provider-discovery/codex.js +0 -49
- package/scripts/lib/orchestration/provider-discovery/common.js +0 -186
- package/scripts/lib/orchestration/provider-discovery/gemini.js +0 -106
- package/scripts/lib/orchestration/provider-discovery/lm-studio.js +0 -118
- package/scripts/lib/orchestration/provider-discovery/models-dev.js +0 -12
- package/scripts/lib/orchestration/provider-discovery/ollama.js +0 -100
- package/scripts/lib/orchestration/provider-discovery/opencode.js +0 -47
- package/scripts/lib/orchestration/provider-discovery/openrouter.js +0 -44
- package/scripts/lib/orchestration/risk-classifier.js +0 -130
- package/scripts/lib/orchestration/routing-policy.js +0 -486
- package/scripts/lib/orchestration/settings.js +0 -112
- package/scripts/lib/orchestration/state.js +0 -165
- package/scripts/lib/orchestration/verification-manager.js +0 -138
- package/scripts/lib/output-profiles.js +0 -146
- package/scripts/lib/package-content-audit.js +0 -368
- package/scripts/lib/package-runtime.js +0 -278
- package/scripts/lib/plan-surface.js +0 -53
- package/scripts/lib/plans.js +0 -2318
- package/scripts/lib/policy-provider.js +0 -27
- package/scripts/lib/prelaunch-activation-readiness.js +0 -409
- package/scripts/lib/prelaunch-evidence-store.js +0 -816
- package/scripts/lib/prelaunch-intelligence.js +0 -869
- package/scripts/lib/pricing-experiment.js +0 -118
- package/scripts/lib/pro-moment-events.js +0 -77
- package/scripts/lib/pro-moment-state.js +0 -227
- package/scripts/lib/pro-moments.js +0 -1216
- package/scripts/lib/product-learning-events.js +0 -629
- package/scripts/lib/project-profile.js +0 -555
- package/scripts/lib/prompt-compiler.js +0 -280
- package/scripts/lib/prompt-lint.js +0 -32
- package/scripts/lib/prompt-suggestions.js +0 -52
- package/scripts/lib/proof-canonical.js +0 -398
- package/scripts/lib/proof-drilldown.js +0 -383
- package/scripts/lib/proof-events.js +0 -342
- package/scripts/lib/proof-history.js +0 -243
- package/scripts/lib/proof-metrics.js +0 -296
- package/scripts/lib/proof-outcome-evidence.js +0 -134
- package/scripts/lib/proof-receipt.js +0 -335
- package/scripts/lib/proof-record.js +0 -461
- package/scripts/lib/public-activation-distribution-gate.js +0 -258
- package/scripts/lib/public-cli.js +0 -3891
- package/scripts/lib/public-distribution-truth.js +0 -211
- package/scripts/lib/public-install-claim-checker.js +0 -294
- package/scripts/lib/publish-provenance-readiness.js +0 -283
- package/scripts/lib/readiness-delta.js +0 -218
- package/scripts/lib/readiness-evidence-closure.js +0 -196
- package/scripts/lib/reentry-memory-capture.js +0 -241
- package/scripts/lib/reentry-memory-retrieval.js +0 -302
- package/scripts/lib/reentry-memory-status.js +0 -146
- package/scripts/lib/reentry-memory-store.js +0 -178
- package/scripts/lib/reentry-state.js +0 -66
- package/scripts/lib/release-candidate-bundle.js +0 -166
- package/scripts/lib/remediation.js +0 -81
- package/scripts/lib/repo-map.js +0 -391
- package/scripts/lib/run-improvements-lifecycle.js +0 -330
- package/scripts/lib/run-improvements.js +0 -789
- package/scripts/lib/runtime-decision-policy.js +0 -387
- package/scripts/lib/safe-path-engine.js +0 -705
- package/scripts/lib/safe-run-controller.js +0 -887
- package/scripts/lib/score.js +0 -262
- package/scripts/lib/seamless-enforcement.js +0 -329
- package/scripts/lib/seamless-outcome.js +0 -689
- package/scripts/lib/seamless-reality-gate.js +0 -5043
- package/scripts/lib/security-risk-classifier.js +0 -511
- package/scripts/lib/security-scan.js +0 -384
- package/scripts/lib/session-context-optimizer.js +0 -1211
- package/scripts/lib/session-timing.js +0 -315
- package/scripts/lib/skill-hygiene.js +0 -805
- package/scripts/lib/skill-packs.js +0 -161
- package/scripts/lib/skills-operating-layer.js +0 -580
- package/scripts/lib/smart-work-routing.js +0 -768
- package/scripts/lib/source-catalog.js +0 -700
- package/scripts/lib/status-value-summary.js +0 -32
- package/scripts/lib/support-bundle.js +0 -578
- package/scripts/lib/task-continuation.js +0 -440
- package/scripts/lib/test-helpers.js +0 -15
- package/scripts/lib/tier.js +0 -38
- package/scripts/lib/token-context-quality-gate.js +0 -370
- package/scripts/lib/token-cost-capture.js +0 -187
- package/scripts/lib/token-cost-intelligence.js +0 -358
- package/scripts/lib/token-efficiency-evidence.js +0 -213
- package/scripts/lib/token-evidence.js +0 -699
- package/scripts/lib/tokenish.js +0 -17
- package/scripts/lib/tool-output-sandbox.js +0 -304
- package/scripts/lib/trust-audit.js +0 -136
- package/scripts/lib/unified-events.js +0 -396
- package/scripts/lib/upgrade-interruption-recovery.js +0 -407
- package/scripts/lib/usage-ledger.js +0 -201
- package/scripts/lib/value-ledger.js +0 -130
- package/scripts/lib/value-proof-calibration.js +0 -531
- package/scripts/lib/visual-qa.js +0 -231
- package/scripts/lib/voice-alpha.js +0 -29
- package/scripts/lib/work-aware-orchestration.js +0 -976
- package/scripts/lib/work-control-receipts.js +0 -577
- package/scripts/lib/work-ledger.js +0 -1123
- package/scripts/lib/work-panel-preview.js +0 -352
- package/scripts/lib/workflow-discipline.js +0 -280
- package/scripts/lib/workflow-signals.js +0 -419
- package/scripts/lib/workspace-map.js +0 -281
- package/scripts/lib/workspace-registry.js +0 -1367
- package/scripts/lib/workspace-resolver.js +0 -480
package/scripts/lib/config.js
DELETED
|
@@ -1,637 +0,0 @@
|
|
|
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
|
-
};
|