@mcoda/mswarm 0.1.56 → 0.1.60
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/README.md +20 -1
- package/dist/codali-executor.d.ts +266 -0
- package/dist/codali-executor.d.ts.map +1 -0
- package/dist/codali-executor.js +227 -0
- package/dist/codali-executor.js.map +1 -0
- package/dist/runtime.d.ts +47 -1
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +248 -30
- package/dist/runtime.js.map +1 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +83 -3
- package/dist/server.js.map +1 -1
- package/dist/vendor/codali/agents/AgentProtocol.d.ts +287 -0
- package/dist/vendor/codali/agents/AgentProtocol.d.ts.map +1 -0
- package/dist/vendor/codali/agents/AgentProtocol.js +365 -0
- package/dist/vendor/codali/agents/AgentResolver.d.ts +23 -0
- package/dist/vendor/codali/agents/AgentResolver.d.ts.map +1 -0
- package/dist/vendor/codali/agents/AgentResolver.js +77 -0
- package/dist/vendor/codali/agents/PhaseAgentSelector.d.ts +23 -0
- package/dist/vendor/codali/agents/PhaseAgentSelector.d.ts.map +1 -0
- package/dist/vendor/codali/agents/PhaseAgentSelector.js +287 -0
- package/dist/vendor/codali/cli/EvalCommand.d.ts +37 -0
- package/dist/vendor/codali/cli/EvalCommand.d.ts.map +1 -0
- package/dist/vendor/codali/cli/EvalCommand.js +333 -0
- package/dist/vendor/codali/cli/FeedbackCommand.d.ts +22 -0
- package/dist/vendor/codali/cli/FeedbackCommand.d.ts.map +1 -0
- package/dist/vendor/codali/cli/FeedbackCommand.js +163 -0
- package/dist/vendor/codali/cli/RunCommand.d.ts +78 -0
- package/dist/vendor/codali/cli/RunCommand.d.ts.map +1 -0
- package/dist/vendor/codali/cli/RunCommand.js +2261 -0
- package/dist/vendor/codali/cli.d.ts +3 -0
- package/dist/vendor/codali/cli.d.ts.map +1 -0
- package/dist/vendor/codali/cli.js +109 -0
- package/dist/vendor/codali/cognitive/ArchitectPlanner.d.ts +107 -0
- package/dist/vendor/codali/cognitive/ArchitectPlanner.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/ArchitectPlanner.js +1726 -0
- package/dist/vendor/codali/cognitive/BuilderOutputParser.d.ts +25 -0
- package/dist/vendor/codali/cognitive/BuilderOutputParser.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/BuilderOutputParser.js +164 -0
- package/dist/vendor/codali/cognitive/BuilderRunner.d.ts +76 -0
- package/dist/vendor/codali/cognitive/BuilderRunner.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/BuilderRunner.js +1159 -0
- package/dist/vendor/codali/cognitive/ContextAssembler.d.ts +91 -0
- package/dist/vendor/codali/cognitive/ContextAssembler.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/ContextAssembler.js +4547 -0
- package/dist/vendor/codali/cognitive/ContextBudget.d.ts +19 -0
- package/dist/vendor/codali/cognitive/ContextBudget.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/ContextBudget.js +35 -0
- package/dist/vendor/codali/cognitive/ContextFileLoader.d.ts +30 -0
- package/dist/vendor/codali/cognitive/ContextFileLoader.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/ContextFileLoader.js +307 -0
- package/dist/vendor/codali/cognitive/ContextManager.d.ts +47 -0
- package/dist/vendor/codali/cognitive/ContextManager.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/ContextManager.js +272 -0
- package/dist/vendor/codali/cognitive/ContextRedactor.d.ts +18 -0
- package/dist/vendor/codali/cognitive/ContextRedactor.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/ContextRedactor.js +53 -0
- package/dist/vendor/codali/cognitive/ContextSelector.d.ts +22 -0
- package/dist/vendor/codali/cognitive/ContextSelector.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/ContextSelector.js +431 -0
- package/dist/vendor/codali/cognitive/ContextSerializer.d.ts +8 -0
- package/dist/vendor/codali/cognitive/ContextSerializer.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/ContextSerializer.js +882 -0
- package/dist/vendor/codali/cognitive/ContextStore.d.ts +27 -0
- package/dist/vendor/codali/cognitive/ContextStore.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/ContextStore.js +79 -0
- package/dist/vendor/codali/cognitive/ContextSummarizer.d.ts +16 -0
- package/dist/vendor/codali/cognitive/ContextSummarizer.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/ContextSummarizer.js +45 -0
- package/dist/vendor/codali/cognitive/CostEstimator.d.ts +31 -0
- package/dist/vendor/codali/cognitive/CostEstimator.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/CostEstimator.js +66 -0
- package/dist/vendor/codali/cognitive/CriticEvaluator.d.ts +32 -0
- package/dist/vendor/codali/cognitive/CriticEvaluator.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/CriticEvaluator.js +297 -0
- package/dist/vendor/codali/cognitive/EvidenceGate.d.ts +9 -0
- package/dist/vendor/codali/cognitive/EvidenceGate.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/EvidenceGate.js +75 -0
- package/dist/vendor/codali/cognitive/GoldenExampleIndexer.d.ts +12 -0
- package/dist/vendor/codali/cognitive/GoldenExampleIndexer.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/GoldenExampleIndexer.js +34 -0
- package/dist/vendor/codali/cognitive/GoldenSetStore.d.ts +33 -0
- package/dist/vendor/codali/cognitive/GoldenSetStore.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/GoldenSetStore.js +159 -0
- package/dist/vendor/codali/cognitive/IntentSignals.d.ts +7 -0
- package/dist/vendor/codali/cognitive/IntentSignals.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/IntentSignals.js +285 -0
- package/dist/vendor/codali/cognitive/LearningGovernance.d.ts +100 -0
- package/dist/vendor/codali/cognitive/LearningGovernance.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/LearningGovernance.js +276 -0
- package/dist/vendor/codali/cognitive/MemoryWriteback.d.ts +64 -0
- package/dist/vendor/codali/cognitive/MemoryWriteback.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/MemoryWriteback.js +287 -0
- package/dist/vendor/codali/cognitive/PatchApplier.d.ts +49 -0
- package/dist/vendor/codali/cognitive/PatchApplier.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/PatchApplier.js +199 -0
- package/dist/vendor/codali/cognitive/PatchInterpreter.d.ts +35 -0
- package/dist/vendor/codali/cognitive/PatchInterpreter.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/PatchInterpreter.js +100 -0
- package/dist/vendor/codali/cognitive/PatchOutputNormalizer.d.ts +7 -0
- package/dist/vendor/codali/cognitive/PatchOutputNormalizer.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/PatchOutputNormalizer.js +59 -0
- package/dist/vendor/codali/cognitive/PostMortemAnalyzer.d.ts +17 -0
- package/dist/vendor/codali/cognitive/PostMortemAnalyzer.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/PostMortemAnalyzer.js +131 -0
- package/dist/vendor/codali/cognitive/PreferenceExtraction.d.ts +3 -0
- package/dist/vendor/codali/cognitive/PreferenceExtraction.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/PreferenceExtraction.js +85 -0
- package/dist/vendor/codali/cognitive/Prompts.d.ts +15 -0
- package/dist/vendor/codali/cognitive/Prompts.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/Prompts.js +326 -0
- package/dist/vendor/codali/cognitive/ProviderRouting.d.ts +16 -0
- package/dist/vendor/codali/cognitive/ProviderRouting.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/ProviderRouting.js +24 -0
- package/dist/vendor/codali/cognitive/QueryExtraction.d.ts +12 -0
- package/dist/vendor/codali/cognitive/QueryExtraction.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/QueryExtraction.js +262 -0
- package/dist/vendor/codali/cognitive/RunHistoryIndexer.d.ts +13 -0
- package/dist/vendor/codali/cognitive/RunHistoryIndexer.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/RunHistoryIndexer.js +125 -0
- package/dist/vendor/codali/cognitive/SmartPipeline.d.ts +92 -0
- package/dist/vendor/codali/cognitive/SmartPipeline.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/SmartPipeline.js +4804 -0
- package/dist/vendor/codali/cognitive/Types.d.ts +474 -0
- package/dist/vendor/codali/cognitive/Types.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/Types.js +7 -0
- package/dist/vendor/codali/cognitive/ValidationRunner.d.ts +57 -0
- package/dist/vendor/codali/cognitive/ValidationRunner.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/ValidationRunner.js +515 -0
- package/dist/vendor/codali/config/Config.d.ts +249 -0
- package/dist/vendor/codali/config/Config.d.ts.map +1 -0
- package/dist/vendor/codali/config/Config.js +200 -0
- package/dist/vendor/codali/config/ConfigLoader.d.ts +56 -0
- package/dist/vendor/codali/config/ConfigLoader.d.ts.map +1 -0
- package/dist/vendor/codali/config/ConfigLoader.js +1246 -0
- package/dist/vendor/codali/docdex/DocdexClient.d.ts +113 -0
- package/dist/vendor/codali/docdex/DocdexClient.d.ts.map +1 -0
- package/dist/vendor/codali/docdex/DocdexClient.js +524 -0
- package/dist/vendor/codali/eval/EvalRunner.d.ts +35 -0
- package/dist/vendor/codali/eval/EvalRunner.d.ts.map +1 -0
- package/dist/vendor/codali/eval/EvalRunner.js +38 -0
- package/dist/vendor/codali/eval/EvalTaskExecutor.d.ts +81 -0
- package/dist/vendor/codali/eval/EvalTaskExecutor.d.ts.map +1 -0
- package/dist/vendor/codali/eval/EvalTaskExecutor.js +371 -0
- package/dist/vendor/codali/eval/GateEvaluator.d.ts +31 -0
- package/dist/vendor/codali/eval/GateEvaluator.d.ts.map +1 -0
- package/dist/vendor/codali/eval/GateEvaluator.js +134 -0
- package/dist/vendor/codali/eval/MetricTypes.d.ts +28 -0
- package/dist/vendor/codali/eval/MetricTypes.d.ts.map +1 -0
- package/dist/vendor/codali/eval/MetricTypes.js +1 -0
- package/dist/vendor/codali/eval/MetricsAggregator.d.ts +4 -0
- package/dist/vendor/codali/eval/MetricsAggregator.d.ts.map +1 -0
- package/dist/vendor/codali/eval/MetricsAggregator.js +97 -0
- package/dist/vendor/codali/eval/RegressionComparator.d.ts +29 -0
- package/dist/vendor/codali/eval/RegressionComparator.d.ts.map +1 -0
- package/dist/vendor/codali/eval/RegressionComparator.js +155 -0
- package/dist/vendor/codali/eval/ReportInputAdapter.d.ts +52 -0
- package/dist/vendor/codali/eval/ReportInputAdapter.d.ts.map +1 -0
- package/dist/vendor/codali/eval/ReportInputAdapter.js +229 -0
- package/dist/vendor/codali/eval/ReportSerializer.d.ts +32 -0
- package/dist/vendor/codali/eval/ReportSerializer.d.ts.map +1 -0
- package/dist/vendor/codali/eval/ReportSerializer.js +33 -0
- package/dist/vendor/codali/eval/ReportStore.d.ts +18 -0
- package/dist/vendor/codali/eval/ReportStore.d.ts.map +1 -0
- package/dist/vendor/codali/eval/ReportStore.js +96 -0
- package/dist/vendor/codali/eval/SuiteLoader.d.ts +12 -0
- package/dist/vendor/codali/eval/SuiteLoader.d.ts.map +1 -0
- package/dist/vendor/codali/eval/SuiteLoader.js +51 -0
- package/dist/vendor/codali/eval/SuiteSchema.d.ts +56 -0
- package/dist/vendor/codali/eval/SuiteSchema.d.ts.map +1 -0
- package/dist/vendor/codali/eval/SuiteSchema.js +357 -0
- package/dist/vendor/codali/index.d.ts +11 -0
- package/dist/vendor/codali/index.d.ts.map +1 -0
- package/dist/vendor/codali/index.js +5 -0
- package/dist/vendor/codali/providers/CodexCliProvider.d.ts +8 -0
- package/dist/vendor/codali/providers/CodexCliProvider.d.ts.map +1 -0
- package/dist/vendor/codali/providers/CodexCliProvider.js +282 -0
- package/dist/vendor/codali/providers/OllamaRemoteProvider.d.ts +8 -0
- package/dist/vendor/codali/providers/OllamaRemoteProvider.d.ts.map +1 -0
- package/dist/vendor/codali/providers/OllamaRemoteProvider.js +300 -0
- package/dist/vendor/codali/providers/OpenAiCompatibleProvider.d.ts +8 -0
- package/dist/vendor/codali/providers/OpenAiCompatibleProvider.d.ts.map +1 -0
- package/dist/vendor/codali/providers/OpenAiCompatibleProvider.js +192 -0
- package/dist/vendor/codali/providers/ProviderRegistry.d.ts +12 -0
- package/dist/vendor/codali/providers/ProviderRegistry.d.ts.map +1 -0
- package/dist/vendor/codali/providers/ProviderRegistry.js +28 -0
- package/dist/vendor/codali/providers/ProviderTypes.d.ts +81 -0
- package/dist/vendor/codali/providers/ProviderTypes.d.ts.map +1 -0
- package/dist/vendor/codali/providers/ProviderTypes.js +1 -0
- package/dist/vendor/codali/runtime/CodaliRuntime.d.ts +183 -0
- package/dist/vendor/codali/runtime/CodaliRuntime.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/CodaliRuntime.js +1363 -0
- package/dist/vendor/codali/runtime/DeepInvestigationErrors.d.ts +39 -0
- package/dist/vendor/codali/runtime/DeepInvestigationErrors.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/DeepInvestigationErrors.js +57 -0
- package/dist/vendor/codali/runtime/RunContext.d.ts +27 -0
- package/dist/vendor/codali/runtime/RunContext.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/RunContext.js +51 -0
- package/dist/vendor/codali/runtime/RunLogQuery.d.ts +48 -0
- package/dist/vendor/codali/runtime/RunLogQuery.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/RunLogQuery.js +36 -0
- package/dist/vendor/codali/runtime/RunLogReader.d.ts +19 -0
- package/dist/vendor/codali/runtime/RunLogReader.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/RunLogReader.js +361 -0
- package/dist/vendor/codali/runtime/RunLogger.d.ts +71 -0
- package/dist/vendor/codali/runtime/RunLogger.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/RunLogger.js +100 -0
- package/dist/vendor/codali/runtime/RunTelemetryTypes.d.ts +117 -0
- package/dist/vendor/codali/runtime/RunTelemetryTypes.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/RunTelemetryTypes.js +299 -0
- package/dist/vendor/codali/runtime/Runner.d.ts +66 -0
- package/dist/vendor/codali/runtime/Runner.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/Runner.js +215 -0
- package/dist/vendor/codali/runtime/StoragePaths.d.ts +3 -0
- package/dist/vendor/codali/runtime/StoragePaths.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/StoragePaths.js +19 -0
- package/dist/vendor/codali/runtime/WorkspaceLock.d.ts +30 -0
- package/dist/vendor/codali/runtime/WorkspaceLock.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/WorkspaceLock.js +141 -0
- package/dist/vendor/codali/session/InstructionLoader.d.ts +14 -0
- package/dist/vendor/codali/session/InstructionLoader.d.ts.map +1 -0
- package/dist/vendor/codali/session/InstructionLoader.js +107 -0
- package/dist/vendor/codali/session/SessionStore.d.ts +81 -0
- package/dist/vendor/codali/session/SessionStore.d.ts.map +1 -0
- package/dist/vendor/codali/session/SessionStore.js +244 -0
- package/dist/vendor/codali/subagents/SubagentOrchestrator.d.ts +68 -0
- package/dist/vendor/codali/subagents/SubagentOrchestrator.d.ts.map +1 -0
- package/dist/vendor/codali/subagents/SubagentOrchestrator.js +150 -0
- package/dist/vendor/codali/tools/ToolRegistry.d.ts +9 -0
- package/dist/vendor/codali/tools/ToolRegistry.d.ts.map +1 -0
- package/dist/vendor/codali/tools/ToolRegistry.js +263 -0
- package/dist/vendor/codali/tools/ToolTypes.d.ts +66 -0
- package/dist/vendor/codali/tools/ToolTypes.d.ts.map +1 -0
- package/dist/vendor/codali/tools/ToolTypes.js +32 -0
- package/dist/vendor/codali/tools/diff/DiffTool.d.ts +3 -0
- package/dist/vendor/codali/tools/diff/DiffTool.d.ts.map +1 -0
- package/dist/vendor/codali/tools/diff/DiffTool.js +34 -0
- package/dist/vendor/codali/tools/docdex/DocdexTools.d.ts +4 -0
- package/dist/vendor/codali/tools/docdex/DocdexTools.d.ts.map +1 -0
- package/dist/vendor/codali/tools/docdex/DocdexTools.js +453 -0
- package/dist/vendor/codali/tools/filesystem/FileTools.d.ts +3 -0
- package/dist/vendor/codali/tools/filesystem/FileTools.d.ts.map +1 -0
- package/dist/vendor/codali/tools/filesystem/FileTools.js +141 -0
- package/dist/vendor/codali/tools/search/SearchTool.d.ts +3 -0
- package/dist/vendor/codali/tools/search/SearchTool.d.ts.map +1 -0
- package/dist/vendor/codali/tools/search/SearchTool.js +46 -0
- package/dist/vendor/codali/tools/shell/ShellTool.d.ts +3 -0
- package/dist/vendor/codali/tools/shell/ShellTool.d.ts.map +1 -0
- package/dist/vendor/codali/tools/shell/ShellTool.js +104 -0
- package/package.json +5 -3
|
@@ -0,0 +1,1246 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { DEFAULT_WORKFLOW_PROFILE, DEFAULT_WORKFLOW_PROFILES, WORKFLOW_PROFILE_NAMES, DEFAULT_EVAL, DEFAULT_LEARNING, DEFAULT_DOCDEX_BASE_URL, DEFAULT_BUILDER, DEFAULT_CONTEXT, DEFAULT_COST, DEFAULT_DEEP_INVESTIGATION, DEFAULT_INTERPRETER, DEFAULT_LOCAL_CONTEXT, DEFAULT_LIMITS, DEFAULT_LOGGING, DEFAULT_SECURITY, DEFAULT_STREAMING, DEFAULT_TOOL_CONFIG, } from "./Config.js";
|
|
5
|
+
const WORKFLOW_OUTPUT_CONTRACTS = [
|
|
6
|
+
"general",
|
|
7
|
+
"patch_summary",
|
|
8
|
+
"review_findings",
|
|
9
|
+
"explanation",
|
|
10
|
+
"verification_summary",
|
|
11
|
+
];
|
|
12
|
+
const COMMAND_PROFILE_MAP = {
|
|
13
|
+
fix: "fix",
|
|
14
|
+
review: "review",
|
|
15
|
+
explain: "explain",
|
|
16
|
+
test: "test",
|
|
17
|
+
};
|
|
18
|
+
const parseNumber = (value) => {
|
|
19
|
+
if (!value)
|
|
20
|
+
return undefined;
|
|
21
|
+
const parsed = Number(value);
|
|
22
|
+
return Number.isFinite(parsed) ? parsed : undefined;
|
|
23
|
+
};
|
|
24
|
+
const parseBoolean = (value) => {
|
|
25
|
+
if (!value)
|
|
26
|
+
return undefined;
|
|
27
|
+
const normalized = value.trim().toLowerCase();
|
|
28
|
+
if (["1", "true", "yes", "on"].includes(normalized))
|
|
29
|
+
return true;
|
|
30
|
+
if (["0", "false", "no", "off"].includes(normalized))
|
|
31
|
+
return false;
|
|
32
|
+
return undefined;
|
|
33
|
+
};
|
|
34
|
+
const parseNumberStrict = (value, label) => {
|
|
35
|
+
if (!value)
|
|
36
|
+
return undefined;
|
|
37
|
+
const parsed = Number(value);
|
|
38
|
+
if (!Number.isFinite(parsed)) {
|
|
39
|
+
throw new Error(`Invalid ${label}: expected number.`);
|
|
40
|
+
}
|
|
41
|
+
return parsed;
|
|
42
|
+
};
|
|
43
|
+
const parseBooleanStrict = (value, label) => {
|
|
44
|
+
if (!value)
|
|
45
|
+
return undefined;
|
|
46
|
+
const normalized = value.trim().toLowerCase();
|
|
47
|
+
if (["1", "true", "yes", "on"].includes(normalized))
|
|
48
|
+
return true;
|
|
49
|
+
if (["0", "false", "no", "off"].includes(normalized))
|
|
50
|
+
return false;
|
|
51
|
+
throw new Error(`Invalid ${label}: expected boolean.`);
|
|
52
|
+
};
|
|
53
|
+
const parseList = (value) => {
|
|
54
|
+
if (!value)
|
|
55
|
+
return undefined;
|
|
56
|
+
const items = value
|
|
57
|
+
.split(",")
|
|
58
|
+
.map((entry) => entry.trim())
|
|
59
|
+
.filter(Boolean);
|
|
60
|
+
return items.length ? items : undefined;
|
|
61
|
+
};
|
|
62
|
+
const parseJson = (value) => {
|
|
63
|
+
if (!value)
|
|
64
|
+
return undefined;
|
|
65
|
+
try {
|
|
66
|
+
return JSON.parse(value);
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
return undefined;
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
const isWorkflowProfileName = (value) => WORKFLOW_PROFILE_NAMES.includes(value);
|
|
73
|
+
const normalizeStringField = (value, label) => {
|
|
74
|
+
if (value === undefined)
|
|
75
|
+
return undefined;
|
|
76
|
+
if (typeof value !== "string") {
|
|
77
|
+
throw new Error(`Invalid ${label}: expected string.`);
|
|
78
|
+
}
|
|
79
|
+
const normalized = value.trim();
|
|
80
|
+
if (!normalized) {
|
|
81
|
+
throw new Error(`Invalid ${label}: expected non-empty string.`);
|
|
82
|
+
}
|
|
83
|
+
return normalized;
|
|
84
|
+
};
|
|
85
|
+
const normalizeWorkflowProfileName = (value, label) => {
|
|
86
|
+
if (value === undefined)
|
|
87
|
+
return undefined;
|
|
88
|
+
if (typeof value !== "string") {
|
|
89
|
+
throw new Error(`Invalid ${label}: expected workflow profile name.`);
|
|
90
|
+
}
|
|
91
|
+
const normalized = value.trim().toLowerCase();
|
|
92
|
+
if (!isWorkflowProfileName(normalized)) {
|
|
93
|
+
throw new Error(`Invalid ${label}: unsupported workflow profile "${value}".`);
|
|
94
|
+
}
|
|
95
|
+
return normalized;
|
|
96
|
+
};
|
|
97
|
+
const normalizeNumberField = (value, label) => {
|
|
98
|
+
if (value === undefined)
|
|
99
|
+
return undefined;
|
|
100
|
+
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
101
|
+
throw new Error(`Invalid ${label}: expected number.`);
|
|
102
|
+
}
|
|
103
|
+
return value;
|
|
104
|
+
};
|
|
105
|
+
const normalizeBooleanField = (value, label) => {
|
|
106
|
+
if (value === undefined)
|
|
107
|
+
return undefined;
|
|
108
|
+
if (typeof value !== "boolean") {
|
|
109
|
+
throw new Error(`Invalid ${label}: expected boolean.`);
|
|
110
|
+
}
|
|
111
|
+
return value;
|
|
112
|
+
};
|
|
113
|
+
const normalizeWorkflowProfileOverride = (value, label) => {
|
|
114
|
+
if (value === undefined)
|
|
115
|
+
return undefined;
|
|
116
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
117
|
+
throw new Error(`Invalid ${label}: expected object.`);
|
|
118
|
+
}
|
|
119
|
+
const source = value;
|
|
120
|
+
const normalized = {};
|
|
121
|
+
const name = normalizeWorkflowProfileName(source.name, `${label}.name`);
|
|
122
|
+
if (name !== undefined)
|
|
123
|
+
normalized.name = name;
|
|
124
|
+
const description = normalizeStringField(source.description, `${label}.description`);
|
|
125
|
+
if (description !== undefined)
|
|
126
|
+
normalized.description = description;
|
|
127
|
+
const smart = normalizeBooleanField(source.smart, `${label}.smart`);
|
|
128
|
+
if (smart !== undefined)
|
|
129
|
+
normalized.smart = smart;
|
|
130
|
+
const builderMode = source.builderMode;
|
|
131
|
+
if (builderMode !== undefined) {
|
|
132
|
+
if (builderMode !== "tool_calls"
|
|
133
|
+
&& builderMode !== "patch_json"
|
|
134
|
+
&& builderMode !== "freeform") {
|
|
135
|
+
throw new Error(`Invalid ${label}.builderMode: expected tool_calls|patch_json|freeform.`);
|
|
136
|
+
}
|
|
137
|
+
normalized.builderMode = builderMode;
|
|
138
|
+
}
|
|
139
|
+
const fallbackToInterpreter = normalizeBooleanField(source.fallbackToInterpreter, `${label}.fallbackToInterpreter`);
|
|
140
|
+
if (fallbackToInterpreter !== undefined) {
|
|
141
|
+
normalized.fallbackToInterpreter = fallbackToInterpreter;
|
|
142
|
+
}
|
|
143
|
+
const retryBudget = normalizeNumberField(source.retryBudget, `${label}.retryBudget`);
|
|
144
|
+
if (retryBudget !== undefined)
|
|
145
|
+
normalized.retryBudget = retryBudget;
|
|
146
|
+
const verificationPolicy = normalizeStringField(source.verificationPolicy, `${label}.verificationPolicy`);
|
|
147
|
+
if (verificationPolicy !== undefined)
|
|
148
|
+
normalized.verificationPolicy = verificationPolicy;
|
|
149
|
+
const verificationMinimumChecks = normalizeNumberField(source.verificationMinimumChecks, `${label}.verificationMinimumChecks`);
|
|
150
|
+
if (verificationMinimumChecks !== undefined) {
|
|
151
|
+
normalized.verificationMinimumChecks = verificationMinimumChecks;
|
|
152
|
+
}
|
|
153
|
+
const verificationEnforceHighConfidence = normalizeBooleanField(source.verificationEnforceHighConfidence, `${label}.verificationEnforceHighConfidence`);
|
|
154
|
+
if (verificationEnforceHighConfidence !== undefined) {
|
|
155
|
+
normalized.verificationEnforceHighConfidence = verificationEnforceHighConfidence;
|
|
156
|
+
}
|
|
157
|
+
const outputContract = source.outputContract;
|
|
158
|
+
if (outputContract !== undefined) {
|
|
159
|
+
if (typeof outputContract !== "string"
|
|
160
|
+
|| !WORKFLOW_OUTPUT_CONTRACTS.includes(outputContract)) {
|
|
161
|
+
throw new Error(`Invalid ${label}.outputContract: expected ${WORKFLOW_OUTPUT_CONTRACTS.join("|")}.`);
|
|
162
|
+
}
|
|
163
|
+
normalized.outputContract = outputContract;
|
|
164
|
+
}
|
|
165
|
+
const allowWrites = normalizeBooleanField(source.allowWrites, `${label}.allowWrites`);
|
|
166
|
+
if (allowWrites !== undefined)
|
|
167
|
+
normalized.allowWrites = allowWrites;
|
|
168
|
+
return Object.keys(normalized).length ? normalized : undefined;
|
|
169
|
+
};
|
|
170
|
+
const normalizeWorkflowConfig = (value, label) => {
|
|
171
|
+
if (value === undefined)
|
|
172
|
+
return undefined;
|
|
173
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
174
|
+
throw new Error(`Invalid ${label}: expected object.`);
|
|
175
|
+
}
|
|
176
|
+
const config = value;
|
|
177
|
+
const normalized = {};
|
|
178
|
+
const profile = normalizeWorkflowProfileName(config.profile, `${label}.profile`);
|
|
179
|
+
if (profile !== undefined)
|
|
180
|
+
normalized.profile = profile;
|
|
181
|
+
const profilesValue = config.profiles;
|
|
182
|
+
if (profilesValue !== undefined) {
|
|
183
|
+
if (!profilesValue || typeof profilesValue !== "object" || Array.isArray(profilesValue)) {
|
|
184
|
+
throw new Error(`Invalid ${label}.profiles: expected object.`);
|
|
185
|
+
}
|
|
186
|
+
const entries = profilesValue;
|
|
187
|
+
const profiles = {};
|
|
188
|
+
for (const [profileName, override] of Object.entries(entries)) {
|
|
189
|
+
const normalizedName = normalizeWorkflowProfileName(profileName, `${label}.profiles.${profileName}`);
|
|
190
|
+
if (!normalizedName)
|
|
191
|
+
continue;
|
|
192
|
+
const normalizedOverride = normalizeWorkflowProfileOverride(override, `${label}.profiles.${profileName}`);
|
|
193
|
+
if (normalizedOverride) {
|
|
194
|
+
profiles[normalizedName] = normalizedOverride;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
if (Object.keys(profiles).length) {
|
|
198
|
+
normalized.profiles = profiles;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
return Object.keys(normalized).length ? normalized : undefined;
|
|
202
|
+
};
|
|
203
|
+
const normalizeToolQuota = (value, label) => {
|
|
204
|
+
if (value === undefined)
|
|
205
|
+
return undefined;
|
|
206
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
207
|
+
throw new Error(`Invalid ${label}: expected object.`);
|
|
208
|
+
}
|
|
209
|
+
const quota = value;
|
|
210
|
+
const normalized = {};
|
|
211
|
+
const search = normalizeNumberField(quota.search, `${label}.search`);
|
|
212
|
+
if (search !== undefined)
|
|
213
|
+
normalized.search = search;
|
|
214
|
+
const openOrSnippet = normalizeNumberField(quota.openOrSnippet, `${label}.openOrSnippet`);
|
|
215
|
+
if (openOrSnippet !== undefined)
|
|
216
|
+
normalized.openOrSnippet = openOrSnippet;
|
|
217
|
+
const symbolsOrAst = normalizeNumberField(quota.symbolsOrAst, `${label}.symbolsOrAst`);
|
|
218
|
+
if (symbolsOrAst !== undefined)
|
|
219
|
+
normalized.symbolsOrAst = symbolsOrAst;
|
|
220
|
+
const impact = normalizeNumberField(quota.impact, `${label}.impact`);
|
|
221
|
+
if (impact !== undefined)
|
|
222
|
+
normalized.impact = impact;
|
|
223
|
+
const tree = normalizeNumberField(quota.tree, `${label}.tree`);
|
|
224
|
+
if (tree !== undefined)
|
|
225
|
+
normalized.tree = tree;
|
|
226
|
+
const dagExport = normalizeNumberField(quota.dagExport, `${label}.dagExport`);
|
|
227
|
+
if (dagExport !== undefined)
|
|
228
|
+
normalized.dagExport = dagExport;
|
|
229
|
+
return Object.keys(normalized).length ? normalized : undefined;
|
|
230
|
+
};
|
|
231
|
+
const normalizeBudget = (value, label) => {
|
|
232
|
+
if (value === undefined)
|
|
233
|
+
return undefined;
|
|
234
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
235
|
+
throw new Error(`Invalid ${label}: expected object.`);
|
|
236
|
+
}
|
|
237
|
+
const budget = value;
|
|
238
|
+
const normalized = {};
|
|
239
|
+
const minCycles = normalizeNumberField(budget.minCycles, `${label}.minCycles`);
|
|
240
|
+
if (minCycles !== undefined)
|
|
241
|
+
normalized.minCycles = minCycles;
|
|
242
|
+
const minSeconds = normalizeNumberField(budget.minSeconds, `${label}.minSeconds`);
|
|
243
|
+
if (minSeconds !== undefined)
|
|
244
|
+
normalized.minSeconds = minSeconds;
|
|
245
|
+
const maxCycles = normalizeNumberField(budget.maxCycles, `${label}.maxCycles`);
|
|
246
|
+
if (maxCycles !== undefined)
|
|
247
|
+
normalized.maxCycles = maxCycles;
|
|
248
|
+
return Object.keys(normalized).length ? normalized : undefined;
|
|
249
|
+
};
|
|
250
|
+
const normalizeEvidence = (value, label) => {
|
|
251
|
+
if (value === undefined)
|
|
252
|
+
return undefined;
|
|
253
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
254
|
+
throw new Error(`Invalid ${label}: expected object.`);
|
|
255
|
+
}
|
|
256
|
+
const evidence = value;
|
|
257
|
+
const normalized = {};
|
|
258
|
+
const minSearchHits = normalizeNumberField(evidence.minSearchHits, `${label}.minSearchHits`);
|
|
259
|
+
if (minSearchHits !== undefined)
|
|
260
|
+
normalized.minSearchHits = minSearchHits;
|
|
261
|
+
const minOpenOrSnippet = normalizeNumberField(evidence.minOpenOrSnippet, `${label}.minOpenOrSnippet`);
|
|
262
|
+
if (minOpenOrSnippet !== undefined)
|
|
263
|
+
normalized.minOpenOrSnippet = minOpenOrSnippet;
|
|
264
|
+
const minSymbolsOrAst = normalizeNumberField(evidence.minSymbolsOrAst, `${label}.minSymbolsOrAst`);
|
|
265
|
+
if (minSymbolsOrAst !== undefined)
|
|
266
|
+
normalized.minSymbolsOrAst = minSymbolsOrAst;
|
|
267
|
+
const minImpact = normalizeNumberField(evidence.minImpact, `${label}.minImpact`);
|
|
268
|
+
if (minImpact !== undefined)
|
|
269
|
+
normalized.minImpact = minImpact;
|
|
270
|
+
const maxWarnings = normalizeNumberField(evidence.maxWarnings, `${label}.maxWarnings`);
|
|
271
|
+
if (maxWarnings !== undefined)
|
|
272
|
+
normalized.maxWarnings = maxWarnings;
|
|
273
|
+
return Object.keys(normalized).length ? normalized : undefined;
|
|
274
|
+
};
|
|
275
|
+
const normalizeDeepInvestigationConfig = (value, label) => {
|
|
276
|
+
if (value === undefined)
|
|
277
|
+
return undefined;
|
|
278
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
279
|
+
throw new Error(`Invalid ${label}: expected object.`);
|
|
280
|
+
}
|
|
281
|
+
const config = value;
|
|
282
|
+
const normalized = {};
|
|
283
|
+
const enabled = normalizeBooleanField(config.enabled, `${label}.enabled`);
|
|
284
|
+
if (enabled !== undefined)
|
|
285
|
+
normalized.enabled = enabled;
|
|
286
|
+
const deepScanPreset = normalizeBooleanField(config.deepScanPreset, `${label}.deepScanPreset`);
|
|
287
|
+
if (deepScanPreset !== undefined)
|
|
288
|
+
normalized.deepScanPreset = deepScanPreset;
|
|
289
|
+
const toolQuota = normalizeToolQuota(config.toolQuota, `${label}.toolQuota`);
|
|
290
|
+
if (toolQuota)
|
|
291
|
+
normalized.toolQuota = toolQuota;
|
|
292
|
+
const investigationBudget = normalizeBudget(config.investigationBudget, `${label}.investigationBudget`);
|
|
293
|
+
if (investigationBudget)
|
|
294
|
+
normalized.investigationBudget = investigationBudget;
|
|
295
|
+
const evidenceGate = normalizeEvidence(config.evidenceGate, `${label}.evidenceGate`);
|
|
296
|
+
if (evidenceGate)
|
|
297
|
+
normalized.evidenceGate = evidenceGate;
|
|
298
|
+
return Object.keys(normalized).length ? normalized : undefined;
|
|
299
|
+
};
|
|
300
|
+
const normalizeEvalConfig = (value, label) => {
|
|
301
|
+
if (value === undefined)
|
|
302
|
+
return undefined;
|
|
303
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
304
|
+
throw new Error(`Invalid ${label}: expected object.`);
|
|
305
|
+
}
|
|
306
|
+
const source = value;
|
|
307
|
+
const normalized = {};
|
|
308
|
+
const reportDir = normalizeStringField(source.report_dir ?? source.reportDir, `${label}.report_dir`);
|
|
309
|
+
if (reportDir !== undefined)
|
|
310
|
+
normalized.report_dir = reportDir;
|
|
311
|
+
const gatesValue = source.gates;
|
|
312
|
+
if (gatesValue !== undefined) {
|
|
313
|
+
if (!gatesValue || typeof gatesValue !== "object" || Array.isArray(gatesValue)) {
|
|
314
|
+
throw new Error(`Invalid ${label}.gates: expected object.`);
|
|
315
|
+
}
|
|
316
|
+
const gatesSource = gatesValue;
|
|
317
|
+
const gates = {};
|
|
318
|
+
const patchApplyDropMax = normalizeNumberField(gatesSource.patch_apply_drop_max ?? gatesSource.patchApplyDropMax, `${label}.gates.patch_apply_drop_max`);
|
|
319
|
+
if (patchApplyDropMax !== undefined)
|
|
320
|
+
gates.patch_apply_drop_max = patchApplyDropMax;
|
|
321
|
+
const verificationPassRateMin = normalizeNumberField(gatesSource.verification_pass_rate_min ?? gatesSource.verificationPassRateMin, `${label}.gates.verification_pass_rate_min`);
|
|
322
|
+
if (verificationPassRateMin !== undefined) {
|
|
323
|
+
gates.verification_pass_rate_min = verificationPassRateMin;
|
|
324
|
+
}
|
|
325
|
+
const hallucinationRateMax = normalizeNumberField(gatesSource.hallucination_rate_max ?? gatesSource.hallucinationRateMax, `${label}.gates.hallucination_rate_max`);
|
|
326
|
+
if (hallucinationRateMax !== undefined)
|
|
327
|
+
gates.hallucination_rate_max = hallucinationRateMax;
|
|
328
|
+
const scopeViolationRateMax = normalizeNumberField(gatesSource.scope_violation_rate_max ?? gatesSource.scopeViolationRateMax, `${label}.gates.scope_violation_rate_max`);
|
|
329
|
+
if (scopeViolationRateMax !== undefined) {
|
|
330
|
+
gates.scope_violation_rate_max = scopeViolationRateMax;
|
|
331
|
+
}
|
|
332
|
+
if (Object.keys(gates).length)
|
|
333
|
+
normalized.gates = gates;
|
|
334
|
+
}
|
|
335
|
+
return Object.keys(normalized).length ? normalized : undefined;
|
|
336
|
+
};
|
|
337
|
+
const normalizeLearningConfig = (value, label) => {
|
|
338
|
+
if (value === undefined)
|
|
339
|
+
return undefined;
|
|
340
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
341
|
+
throw new Error(`Invalid ${label}: expected object.`);
|
|
342
|
+
}
|
|
343
|
+
const source = value;
|
|
344
|
+
const normalized = {};
|
|
345
|
+
const persistenceMinConfidence = normalizeNumberField(source.persistence_min_confidence ?? source.persistenceMinConfidence, `${label}.persistence_min_confidence`);
|
|
346
|
+
if (persistenceMinConfidence !== undefined) {
|
|
347
|
+
normalized.persistence_min_confidence = persistenceMinConfidence;
|
|
348
|
+
}
|
|
349
|
+
const enforcementMinConfidence = normalizeNumberField(source.enforcement_min_confidence ?? source.enforcementMinConfidence, `${label}.enforcement_min_confidence`);
|
|
350
|
+
if (enforcementMinConfidence !== undefined) {
|
|
351
|
+
normalized.enforcement_min_confidence = enforcementMinConfidence;
|
|
352
|
+
}
|
|
353
|
+
const requireConfirmation = normalizeBooleanField(source.require_confirmation_for_low_confidence ?? source.requireConfirmationForLowConfidence, `${label}.require_confirmation_for_low_confidence`);
|
|
354
|
+
if (requireConfirmation !== undefined) {
|
|
355
|
+
normalized.require_confirmation_for_low_confidence = requireConfirmation;
|
|
356
|
+
}
|
|
357
|
+
const autoEnforceHigh = normalizeBooleanField(source.auto_enforce_high_confidence ?? source.autoEnforceHighConfidence, `${label}.auto_enforce_high_confidence`);
|
|
358
|
+
if (autoEnforceHigh !== undefined) {
|
|
359
|
+
normalized.auto_enforce_high_confidence = autoEnforceHigh;
|
|
360
|
+
}
|
|
361
|
+
const candidateStoreFile = normalizeStringField(source.candidate_store_file ?? source.candidateStoreFile, `${label}.candidate_store_file`);
|
|
362
|
+
if (candidateStoreFile !== undefined) {
|
|
363
|
+
normalized.candidate_store_file = candidateStoreFile;
|
|
364
|
+
}
|
|
365
|
+
return Object.keys(normalized).length ? normalized : undefined;
|
|
366
|
+
};
|
|
367
|
+
const findConfigFile = (cwd) => {
|
|
368
|
+
const candidates = ["codali.config.json", ".codalirc"];
|
|
369
|
+
for (const candidate of candidates) {
|
|
370
|
+
const candidatePath = path.join(cwd, candidate);
|
|
371
|
+
if (existsSync(candidatePath)) {
|
|
372
|
+
return candidatePath;
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
return undefined;
|
|
376
|
+
};
|
|
377
|
+
const readConfigFile = async (configPath) => {
|
|
378
|
+
if (!configPath)
|
|
379
|
+
return undefined;
|
|
380
|
+
if (!existsSync(configPath))
|
|
381
|
+
return undefined;
|
|
382
|
+
const content = await readFile(configPath, "utf8");
|
|
383
|
+
if (!content.trim())
|
|
384
|
+
return undefined;
|
|
385
|
+
return JSON.parse(content);
|
|
386
|
+
};
|
|
387
|
+
const loadEnvConfig = (env) => {
|
|
388
|
+
const limits = {};
|
|
389
|
+
const maxSteps = parseNumber(env.CODALI_LIMIT_MAX_STEPS);
|
|
390
|
+
if (maxSteps !== undefined)
|
|
391
|
+
limits.maxSteps = maxSteps;
|
|
392
|
+
const maxToolCalls = parseNumber(env.CODALI_LIMIT_MAX_TOOL_CALLS);
|
|
393
|
+
if (maxToolCalls !== undefined)
|
|
394
|
+
limits.maxToolCalls = maxToolCalls;
|
|
395
|
+
const maxRetries = parseNumber(env.CODALI_LIMIT_MAX_RETRIES);
|
|
396
|
+
if (maxRetries !== undefined)
|
|
397
|
+
limits.maxRetries = maxRetries;
|
|
398
|
+
const maxTokens = parseNumber(env.CODALI_LIMIT_MAX_TOKENS);
|
|
399
|
+
if (maxTokens !== undefined)
|
|
400
|
+
limits.maxTokens = maxTokens;
|
|
401
|
+
const timeoutMs = parseNumber(env.CODALI_LIMIT_TIMEOUT_MS);
|
|
402
|
+
if (timeoutMs !== undefined)
|
|
403
|
+
limits.timeoutMs = timeoutMs;
|
|
404
|
+
const routing = {};
|
|
405
|
+
const setRouting = (phase, key, value) => {
|
|
406
|
+
if (value === undefined || value === "")
|
|
407
|
+
return;
|
|
408
|
+
routing[phase] = {
|
|
409
|
+
...(routing[phase] ?? {}),
|
|
410
|
+
[key]: value,
|
|
411
|
+
};
|
|
412
|
+
};
|
|
413
|
+
setRouting("librarian", "model", env.CODALI_MODEL_LIBRARIAN);
|
|
414
|
+
setRouting("architect", "model", env.CODALI_MODEL_ARCHITECT);
|
|
415
|
+
setRouting("builder", "model", env.CODALI_MODEL_BUILDER);
|
|
416
|
+
setRouting("critic", "model", env.CODALI_MODEL_CRITIC);
|
|
417
|
+
setRouting("interpreter", "model", env.CODALI_MODEL_INTERPRETER);
|
|
418
|
+
setRouting("librarian", "agent", env.CODALI_AGENT_LIBRARIAN);
|
|
419
|
+
setRouting("architect", "agent", env.CODALI_AGENT_ARCHITECT);
|
|
420
|
+
setRouting("builder", "agent", env.CODALI_AGENT_BUILDER);
|
|
421
|
+
setRouting("critic", "agent", env.CODALI_AGENT_CRITIC);
|
|
422
|
+
setRouting("interpreter", "agent", env.CODALI_AGENT_INTERPRETER);
|
|
423
|
+
setRouting("librarian", "provider", env.CODALI_PROVIDER_LIBRARIAN);
|
|
424
|
+
setRouting("architect", "provider", env.CODALI_PROVIDER_ARCHITECT);
|
|
425
|
+
setRouting("builder", "provider", env.CODALI_PROVIDER_BUILDER);
|
|
426
|
+
setRouting("critic", "provider", env.CODALI_PROVIDER_CRITIC);
|
|
427
|
+
setRouting("interpreter", "provider", env.CODALI_PROVIDER_INTERPRETER);
|
|
428
|
+
setRouting("librarian", "format", env.CODALI_FORMAT_LIBRARIAN);
|
|
429
|
+
setRouting("architect", "format", env.CODALI_FORMAT_ARCHITECT);
|
|
430
|
+
setRouting("builder", "format", env.CODALI_FORMAT_BUILDER);
|
|
431
|
+
setRouting("critic", "format", env.CODALI_FORMAT_CRITIC);
|
|
432
|
+
setRouting("interpreter", "format", env.CODALI_FORMAT_INTERPRETER);
|
|
433
|
+
setRouting("librarian", "grammar", env.CODALI_GRAMMAR_LIBRARIAN);
|
|
434
|
+
setRouting("architect", "grammar", env.CODALI_GRAMMAR_ARCHITECT);
|
|
435
|
+
setRouting("builder", "grammar", env.CODALI_GRAMMAR_BUILDER);
|
|
436
|
+
setRouting("critic", "grammar", env.CODALI_GRAMMAR_CRITIC);
|
|
437
|
+
setRouting("interpreter", "grammar", env.CODALI_GRAMMAR_INTERPRETER);
|
|
438
|
+
const tools = {};
|
|
439
|
+
const enabledTools = parseList(env.CODALI_TOOLS_ENABLED);
|
|
440
|
+
if (enabledTools)
|
|
441
|
+
tools.enabled = enabledTools;
|
|
442
|
+
const allowShell = parseBoolean(env.CODALI_ALLOW_SHELL);
|
|
443
|
+
if (allowShell !== undefined)
|
|
444
|
+
tools.allowShell = allowShell;
|
|
445
|
+
const shellAllowlist = parseList(env.CODALI_SHELL_ALLOWLIST);
|
|
446
|
+
if (shellAllowlist)
|
|
447
|
+
tools.shellAllowlist = shellAllowlist;
|
|
448
|
+
const allowOutsideWorkspace = parseBoolean(env.CODALI_ALLOW_OUTSIDE_WORKSPACE);
|
|
449
|
+
if (allowOutsideWorkspace !== undefined)
|
|
450
|
+
tools.allowOutsideWorkspace = allowOutsideWorkspace;
|
|
451
|
+
const allowDestructiveOperations = parseBoolean(env.CODALI_ALLOW_DESTRUCTIVE_OPERATIONS) ??
|
|
452
|
+
parseBoolean(env.CODALI_ALLOW_DESTRUCTIVE_ACTIONS);
|
|
453
|
+
if (allowDestructiveOperations !== undefined) {
|
|
454
|
+
tools.allowDestructiveOperations = allowDestructiveOperations;
|
|
455
|
+
}
|
|
456
|
+
const docdex = {};
|
|
457
|
+
const docdexBaseUrl = env.CODALI_DOCDEX_BASE_URL ?? env.DOCDEX_HTTP_BASE_URL;
|
|
458
|
+
if (docdexBaseUrl)
|
|
459
|
+
docdex.baseUrl = docdexBaseUrl;
|
|
460
|
+
if (env.CODALI_DOCDEX_REPO_ROOT)
|
|
461
|
+
docdex.repoRoot = env.CODALI_DOCDEX_REPO_ROOT;
|
|
462
|
+
if (env.CODALI_DOCDEX_REPO_ID)
|
|
463
|
+
docdex.repoId = env.CODALI_DOCDEX_REPO_ID;
|
|
464
|
+
const logging = {};
|
|
465
|
+
if (env.CODALI_LOG_DIR)
|
|
466
|
+
logging.directory = env.CODALI_LOG_DIR;
|
|
467
|
+
const context = {};
|
|
468
|
+
const contextMode = env.CODALI_CONTEXT_MODE;
|
|
469
|
+
if (contextMode === "bundle_text" || contextMode === "json")
|
|
470
|
+
context.mode = contextMode;
|
|
471
|
+
const contextMaxFiles = parseNumber(env.CODALI_CONTEXT_MAX_FILES);
|
|
472
|
+
if (contextMaxFiles !== undefined)
|
|
473
|
+
context.maxFiles = contextMaxFiles;
|
|
474
|
+
const contextMaxTotalBytes = parseNumber(env.CODALI_CONTEXT_MAX_TOTAL_BYTES);
|
|
475
|
+
if (contextMaxTotalBytes !== undefined)
|
|
476
|
+
context.maxTotalBytes = contextMaxTotalBytes;
|
|
477
|
+
const contextTokenBudget = parseNumber(env.CODALI_CONTEXT_TOKEN_BUDGET);
|
|
478
|
+
if (contextTokenBudget !== undefined)
|
|
479
|
+
context.tokenBudget = contextTokenBudget;
|
|
480
|
+
const focusMaxBytes = parseNumber(env.CODALI_CONTEXT_FOCUS_MAX_BYTES);
|
|
481
|
+
if (focusMaxBytes !== undefined)
|
|
482
|
+
context.focusMaxFileBytes = focusMaxBytes;
|
|
483
|
+
const peripheryMaxBytes = parseNumber(env.CODALI_CONTEXT_PERIPHERY_MAX_BYTES);
|
|
484
|
+
if (peripheryMaxBytes !== undefined)
|
|
485
|
+
context.peripheryMaxBytes = peripheryMaxBytes;
|
|
486
|
+
const includeRepoMap = parseBoolean(env.CODALI_CONTEXT_INCLUDE_REPO_MAP);
|
|
487
|
+
if (includeRepoMap !== undefined)
|
|
488
|
+
context.includeRepoMap = includeRepoMap;
|
|
489
|
+
const includeImpact = parseBoolean(env.CODALI_CONTEXT_INCLUDE_IMPACT);
|
|
490
|
+
if (includeImpact !== undefined)
|
|
491
|
+
context.includeImpact = includeImpact;
|
|
492
|
+
const includeSnippets = parseBoolean(env.CODALI_CONTEXT_INCLUDE_SNIPPETS);
|
|
493
|
+
if (includeSnippets !== undefined)
|
|
494
|
+
context.includeSnippets = includeSnippets;
|
|
495
|
+
const readStrategy = env.CODALI_CONTEXT_READ_STRATEGY;
|
|
496
|
+
if (readStrategy === "docdex" || readStrategy === "fs")
|
|
497
|
+
context.readStrategy = readStrategy;
|
|
498
|
+
const maxRefreshes = parseNumber(env.CODALI_CONTEXT_MAX_REFRESHES);
|
|
499
|
+
if (maxRefreshes !== undefined)
|
|
500
|
+
context.maxContextRefreshes = maxRefreshes;
|
|
501
|
+
const skeletonize = parseBoolean(env.CODALI_CONTEXT_SKELETONIZE);
|
|
502
|
+
if (skeletonize !== undefined)
|
|
503
|
+
context.skeletonizeLargeFiles = skeletonize;
|
|
504
|
+
const redactSecrets = parseBoolean(env.CODALI_CONTEXT_REDACT_SECRETS);
|
|
505
|
+
if (redactSecrets !== undefined)
|
|
506
|
+
context.redactSecrets = redactSecrets;
|
|
507
|
+
const ignoreFilesFrom = parseList(env.CODALI_CONTEXT_IGNORE_FILES_FROM);
|
|
508
|
+
if (ignoreFilesFrom)
|
|
509
|
+
context.ignoreFilesFrom = ignoreFilesFrom;
|
|
510
|
+
const preferredFiles = parseList(env.CODALI_CONTEXT_PREFERRED_FILES);
|
|
511
|
+
if (preferredFiles)
|
|
512
|
+
context.preferredFiles = preferredFiles;
|
|
513
|
+
const recentFiles = parseList(env.CODALI_CONTEXT_RECENT_FILES);
|
|
514
|
+
if (recentFiles)
|
|
515
|
+
context.recentFiles = recentFiles;
|
|
516
|
+
const skipSearchWhenPreferred = parseBoolean(env.CODALI_CONTEXT_SKIP_SEARCH);
|
|
517
|
+
if (skipSearchWhenPreferred !== undefined) {
|
|
518
|
+
context.skipSearchWhenPreferred = skipSearchWhenPreferred;
|
|
519
|
+
}
|
|
520
|
+
const deepInvestigation = {};
|
|
521
|
+
const deepInvestigationEnabled = parseBooleanStrict(env.CODALI_DEEP_INVESTIGATION_ENABLED, "CODALI_DEEP_INVESTIGATION_ENABLED");
|
|
522
|
+
if (deepInvestigationEnabled !== undefined) {
|
|
523
|
+
deepInvestigation.enabled = deepInvestigationEnabled;
|
|
524
|
+
}
|
|
525
|
+
const deepScanPreset = parseBooleanStrict(env.CODALI_DEEP_INVESTIGATION_DEEP_SCAN_PRESET, "CODALI_DEEP_INVESTIGATION_DEEP_SCAN_PRESET");
|
|
526
|
+
if (deepScanPreset !== undefined) {
|
|
527
|
+
deepInvestigation.deepScanPreset = deepScanPreset;
|
|
528
|
+
}
|
|
529
|
+
const toolQuota = {};
|
|
530
|
+
const toolQuotaSearch = parseNumberStrict(env.CODALI_DEEP_INVESTIGATION_TOOL_QUOTA_SEARCH, "CODALI_DEEP_INVESTIGATION_TOOL_QUOTA_SEARCH");
|
|
531
|
+
if (toolQuotaSearch !== undefined)
|
|
532
|
+
toolQuota.search = toolQuotaSearch;
|
|
533
|
+
const toolQuotaOpen = parseNumberStrict(env.CODALI_DEEP_INVESTIGATION_TOOL_QUOTA_OPEN_OR_SNIPPET, "CODALI_DEEP_INVESTIGATION_TOOL_QUOTA_OPEN_OR_SNIPPET");
|
|
534
|
+
if (toolQuotaOpen !== undefined)
|
|
535
|
+
toolQuota.openOrSnippet = toolQuotaOpen;
|
|
536
|
+
const toolQuotaSymbols = parseNumberStrict(env.CODALI_DEEP_INVESTIGATION_TOOL_QUOTA_SYMBOLS_OR_AST, "CODALI_DEEP_INVESTIGATION_TOOL_QUOTA_SYMBOLS_OR_AST");
|
|
537
|
+
if (toolQuotaSymbols !== undefined)
|
|
538
|
+
toolQuota.symbolsOrAst = toolQuotaSymbols;
|
|
539
|
+
const toolQuotaImpact = parseNumberStrict(env.CODALI_DEEP_INVESTIGATION_TOOL_QUOTA_IMPACT, "CODALI_DEEP_INVESTIGATION_TOOL_QUOTA_IMPACT");
|
|
540
|
+
if (toolQuotaImpact !== undefined)
|
|
541
|
+
toolQuota.impact = toolQuotaImpact;
|
|
542
|
+
const toolQuotaTree = parseNumberStrict(env.CODALI_DEEP_INVESTIGATION_TOOL_QUOTA_TREE, "CODALI_DEEP_INVESTIGATION_TOOL_QUOTA_TREE");
|
|
543
|
+
if (toolQuotaTree !== undefined)
|
|
544
|
+
toolQuota.tree = toolQuotaTree;
|
|
545
|
+
const toolQuotaDag = parseNumberStrict(env.CODALI_DEEP_INVESTIGATION_TOOL_QUOTA_DAG_EXPORT, "CODALI_DEEP_INVESTIGATION_TOOL_QUOTA_DAG_EXPORT");
|
|
546
|
+
if (toolQuotaDag !== undefined)
|
|
547
|
+
toolQuota.dagExport = toolQuotaDag;
|
|
548
|
+
if (Object.values(toolQuota).some((value) => value !== undefined)) {
|
|
549
|
+
deepInvestigation.toolQuota = toolQuota;
|
|
550
|
+
}
|
|
551
|
+
const investigationBudget = {};
|
|
552
|
+
const budgetMinCycles = parseNumberStrict(env.CODALI_DEEP_INVESTIGATION_BUDGET_MIN_CYCLES, "CODALI_DEEP_INVESTIGATION_BUDGET_MIN_CYCLES");
|
|
553
|
+
if (budgetMinCycles !== undefined)
|
|
554
|
+
investigationBudget.minCycles = budgetMinCycles;
|
|
555
|
+
const budgetMinSeconds = parseNumberStrict(env.CODALI_DEEP_INVESTIGATION_BUDGET_MIN_SECONDS, "CODALI_DEEP_INVESTIGATION_BUDGET_MIN_SECONDS");
|
|
556
|
+
if (budgetMinSeconds !== undefined)
|
|
557
|
+
investigationBudget.minSeconds = budgetMinSeconds;
|
|
558
|
+
const budgetMaxCycles = parseNumberStrict(env.CODALI_DEEP_INVESTIGATION_BUDGET_MAX_CYCLES, "CODALI_DEEP_INVESTIGATION_BUDGET_MAX_CYCLES");
|
|
559
|
+
if (budgetMaxCycles !== undefined)
|
|
560
|
+
investigationBudget.maxCycles = budgetMaxCycles;
|
|
561
|
+
if (Object.values(investigationBudget).some((value) => value !== undefined)) {
|
|
562
|
+
deepInvestigation.investigationBudget = investigationBudget;
|
|
563
|
+
}
|
|
564
|
+
const evidenceGate = {};
|
|
565
|
+
const evidenceMinSearch = parseNumberStrict(env.CODALI_DEEP_INVESTIGATION_EVIDENCE_MIN_SEARCH_HITS, "CODALI_DEEP_INVESTIGATION_EVIDENCE_MIN_SEARCH_HITS");
|
|
566
|
+
if (evidenceMinSearch !== undefined)
|
|
567
|
+
evidenceGate.minSearchHits = evidenceMinSearch;
|
|
568
|
+
const evidenceMinOpen = parseNumberStrict(env.CODALI_DEEP_INVESTIGATION_EVIDENCE_MIN_OPEN_OR_SNIPPET, "CODALI_DEEP_INVESTIGATION_EVIDENCE_MIN_OPEN_OR_SNIPPET");
|
|
569
|
+
if (evidenceMinOpen !== undefined)
|
|
570
|
+
evidenceGate.minOpenOrSnippet = evidenceMinOpen;
|
|
571
|
+
const evidenceMinSymbols = parseNumberStrict(env.CODALI_DEEP_INVESTIGATION_EVIDENCE_MIN_SYMBOLS_OR_AST, "CODALI_DEEP_INVESTIGATION_EVIDENCE_MIN_SYMBOLS_OR_AST");
|
|
572
|
+
if (evidenceMinSymbols !== undefined)
|
|
573
|
+
evidenceGate.minSymbolsOrAst = evidenceMinSymbols;
|
|
574
|
+
const evidenceMinImpact = parseNumberStrict(env.CODALI_DEEP_INVESTIGATION_EVIDENCE_MIN_IMPACT, "CODALI_DEEP_INVESTIGATION_EVIDENCE_MIN_IMPACT");
|
|
575
|
+
if (evidenceMinImpact !== undefined)
|
|
576
|
+
evidenceGate.minImpact = evidenceMinImpact;
|
|
577
|
+
const evidenceMaxWarnings = parseNumberStrict(env.CODALI_DEEP_INVESTIGATION_EVIDENCE_MAX_WARNINGS, "CODALI_DEEP_INVESTIGATION_EVIDENCE_MAX_WARNINGS");
|
|
578
|
+
if (evidenceMaxWarnings !== undefined)
|
|
579
|
+
evidenceGate.maxWarnings = evidenceMaxWarnings;
|
|
580
|
+
if (Object.values(evidenceGate).some((value) => value !== undefined)) {
|
|
581
|
+
deepInvestigation.evidenceGate = evidenceGate;
|
|
582
|
+
}
|
|
583
|
+
const security = {};
|
|
584
|
+
const redactPatterns = parseList(env.CODALI_SECURITY_REDACT_PATTERNS);
|
|
585
|
+
if (redactPatterns)
|
|
586
|
+
security.redactPatterns = redactPatterns;
|
|
587
|
+
const readOnlyPaths = parseList(env.CODALI_SECURITY_READONLY_PATHS) ?? parseList(env.CODALI_SECURITY_READ_ONLY_PATHS);
|
|
588
|
+
if (readOnlyPaths)
|
|
589
|
+
security.readOnlyPaths = readOnlyPaths;
|
|
590
|
+
const allowDocEdits = parseBoolean(env.CODALI_SECURITY_ALLOW_DOC_EDITS);
|
|
591
|
+
if (allowDocEdits !== undefined)
|
|
592
|
+
security.allowDocEdits = allowDocEdits;
|
|
593
|
+
const allowCloudModels = parseBoolean(env.CODALI_SECURITY_ALLOW_CLOUD_MODELS) ??
|
|
594
|
+
parseBoolean(env.CODALI_ALLOW_CLOUD_MODELS);
|
|
595
|
+
if (allowCloudModels !== undefined)
|
|
596
|
+
security.allowCloudModels = allowCloudModels;
|
|
597
|
+
const builder = {};
|
|
598
|
+
const builderMode = env.CODALI_BUILDER_MODE;
|
|
599
|
+
if (builderMode === "tool_calls" || builderMode === "patch_json" || builderMode === "freeform") {
|
|
600
|
+
builder.mode = builderMode;
|
|
601
|
+
}
|
|
602
|
+
const patchFormat = env.CODALI_BUILDER_PATCH_FORMAT;
|
|
603
|
+
if (patchFormat === "search_replace" || patchFormat === "file_writes")
|
|
604
|
+
builder.patchFormat = patchFormat;
|
|
605
|
+
const fallbackInterpreter = parseBoolean(env.CODALI_BUILDER_FALLBACK_INTERPRETER);
|
|
606
|
+
if (fallbackInterpreter !== undefined)
|
|
607
|
+
builder.fallbackToInterpreter = fallbackInterpreter;
|
|
608
|
+
const fallbackMode = env.CODALI_BUILDER_FALLBACK;
|
|
609
|
+
if (fallbackMode) {
|
|
610
|
+
const normalized = fallbackMode.trim().toLowerCase();
|
|
611
|
+
builder.fallbackToInterpreter =
|
|
612
|
+
normalized === "interpreter" || normalized === "freeform" || normalized === "true" || normalized === "1";
|
|
613
|
+
}
|
|
614
|
+
const interpreter = {};
|
|
615
|
+
if (env.CODALI_INTERPRETER_PROVIDER)
|
|
616
|
+
interpreter.provider = env.CODALI_INTERPRETER_PROVIDER;
|
|
617
|
+
if (env.CODALI_INTERPRETER_MODEL)
|
|
618
|
+
interpreter.model = env.CODALI_INTERPRETER_MODEL;
|
|
619
|
+
if (env.CODALI_INTERPRETER_FORMAT)
|
|
620
|
+
interpreter.format = env.CODALI_INTERPRETER_FORMAT;
|
|
621
|
+
if (env.CODALI_INTERPRETER_GRAMMAR)
|
|
622
|
+
interpreter.grammar = env.CODALI_INTERPRETER_GRAMMAR;
|
|
623
|
+
const interpreterMaxRetries = parseNumber(env.CODALI_INTERPRETER_MAX_RETRIES);
|
|
624
|
+
if (interpreterMaxRetries !== undefined)
|
|
625
|
+
interpreter.maxRetries = interpreterMaxRetries;
|
|
626
|
+
const interpreterTimeoutMs = parseNumber(env.CODALI_INTERPRETER_TIMEOUT_MS);
|
|
627
|
+
if (interpreterTimeoutMs !== undefined)
|
|
628
|
+
interpreter.timeoutMs = interpreterTimeoutMs;
|
|
629
|
+
const streaming = {};
|
|
630
|
+
const streamingFlush = parseNumber(env.CODALI_STREAMING_FLUSH_MS);
|
|
631
|
+
if (streamingFlush !== undefined)
|
|
632
|
+
streaming.flushEveryMs = streamingFlush;
|
|
633
|
+
const cost = {};
|
|
634
|
+
const maxCostPerRun = parseNumber(env.CODALI_COST_MAX_PER_RUN);
|
|
635
|
+
if (maxCostPerRun !== undefined)
|
|
636
|
+
cost.maxCostPerRun = maxCostPerRun;
|
|
637
|
+
const charPerToken = parseNumber(env.CODALI_COST_CHAR_PER_TOKEN);
|
|
638
|
+
if (charPerToken !== undefined)
|
|
639
|
+
cost.charPerToken = charPerToken;
|
|
640
|
+
const pricingOverrides = parseJson(env.CODALI_COST_PRICING_OVERRIDES);
|
|
641
|
+
if (pricingOverrides)
|
|
642
|
+
cost.pricingOverrides = pricingOverrides;
|
|
643
|
+
const localContext = {};
|
|
644
|
+
const localContextEnabled = parseBoolean(env.CODALI_LOCAL_CONTEXT_ENABLED);
|
|
645
|
+
if (localContextEnabled !== undefined)
|
|
646
|
+
localContext.enabled = localContextEnabled;
|
|
647
|
+
if (env.CODALI_LOCAL_CONTEXT_STORAGE_DIR)
|
|
648
|
+
localContext.storageDir = env.CODALI_LOCAL_CONTEXT_STORAGE_DIR;
|
|
649
|
+
const persistToolMessages = parseBoolean(env.CODALI_LOCAL_CONTEXT_PERSIST_TOOL_MESSAGES);
|
|
650
|
+
if (persistToolMessages !== undefined)
|
|
651
|
+
localContext.persistToolMessages = persistToolMessages;
|
|
652
|
+
const maxMessages = parseNumber(env.CODALI_LOCAL_CONTEXT_MAX_MESSAGES);
|
|
653
|
+
if (maxMessages !== undefined)
|
|
654
|
+
localContext.maxMessages = maxMessages;
|
|
655
|
+
const maxBytesPerLane = parseNumber(env.CODALI_LOCAL_CONTEXT_MAX_BYTES_PER_LANE);
|
|
656
|
+
if (maxBytesPerLane !== undefined)
|
|
657
|
+
localContext.maxBytesPerLane = maxBytesPerLane;
|
|
658
|
+
const modelTokenLimits = parseJson(env.CODALI_LOCAL_CONTEXT_MODEL_TOKEN_LIMITS);
|
|
659
|
+
if (modelTokenLimits)
|
|
660
|
+
localContext.modelTokenLimits = modelTokenLimits;
|
|
661
|
+
const summarize = {};
|
|
662
|
+
const summarizeEnabled = parseBoolean(env.CODALI_LOCAL_CONTEXT_SUMMARIZE_ENABLED);
|
|
663
|
+
if (summarizeEnabled !== undefined)
|
|
664
|
+
summarize.enabled = summarizeEnabled;
|
|
665
|
+
if (env.CODALI_LOCAL_CONTEXT_SUMMARIZE_PROVIDER) {
|
|
666
|
+
summarize.provider = env.CODALI_LOCAL_CONTEXT_SUMMARIZE_PROVIDER;
|
|
667
|
+
}
|
|
668
|
+
if (env.CODALI_LOCAL_CONTEXT_SUMMARIZE_MODEL) {
|
|
669
|
+
summarize.model = env.CODALI_LOCAL_CONTEXT_SUMMARIZE_MODEL;
|
|
670
|
+
}
|
|
671
|
+
const summarizeTargetTokens = parseNumber(env.CODALI_LOCAL_CONTEXT_SUMMARIZE_TARGET_TOKENS);
|
|
672
|
+
if (summarizeTargetTokens !== undefined)
|
|
673
|
+
summarize.targetTokens = summarizeTargetTokens;
|
|
674
|
+
const summarizeThreshold = parseNumber(env.CODALI_LOCAL_CONTEXT_SUMMARIZE_THRESHOLD_PCT);
|
|
675
|
+
if (summarizeThreshold !== undefined) {
|
|
676
|
+
summarize.thresholdPct = summarizeThreshold > 1 ? summarizeThreshold / 100 : summarizeThreshold;
|
|
677
|
+
}
|
|
678
|
+
if (Object.keys(summarize).length) {
|
|
679
|
+
localContext.summarize = summarize;
|
|
680
|
+
}
|
|
681
|
+
const workflow = {};
|
|
682
|
+
if (env.CODALI_WORKFLOW_PROFILE || env.CODALI_PROFILE) {
|
|
683
|
+
workflow.profile = (env.CODALI_WORKFLOW_PROFILE ?? env.CODALI_PROFILE)?.trim().toLowerCase();
|
|
684
|
+
}
|
|
685
|
+
const workflowProfiles = parseJson(env.CODALI_WORKFLOW_PROFILES);
|
|
686
|
+
if (workflowProfiles) {
|
|
687
|
+
workflow.profiles = workflowProfiles;
|
|
688
|
+
}
|
|
689
|
+
const evalConfig = {};
|
|
690
|
+
if (env.CODALI_EVAL_REPORT_DIR)
|
|
691
|
+
evalConfig.report_dir = env.CODALI_EVAL_REPORT_DIR;
|
|
692
|
+
const evalGates = {};
|
|
693
|
+
const patchApplyDropMax = parseNumberStrict(env.CODALI_EVAL_GATE_PATCH_APPLY_DROP_MAX, "CODALI_EVAL_GATE_PATCH_APPLY_DROP_MAX");
|
|
694
|
+
if (patchApplyDropMax !== undefined)
|
|
695
|
+
evalGates.patch_apply_drop_max = patchApplyDropMax;
|
|
696
|
+
const verificationPassRateMin = parseNumberStrict(env.CODALI_EVAL_GATE_VERIFICATION_PASS_RATE_MIN, "CODALI_EVAL_GATE_VERIFICATION_PASS_RATE_MIN");
|
|
697
|
+
if (verificationPassRateMin !== undefined) {
|
|
698
|
+
evalGates.verification_pass_rate_min = verificationPassRateMin;
|
|
699
|
+
}
|
|
700
|
+
const hallucinationRateMax = parseNumberStrict(env.CODALI_EVAL_GATE_HALLUCINATION_RATE_MAX, "CODALI_EVAL_GATE_HALLUCINATION_RATE_MAX");
|
|
701
|
+
if (hallucinationRateMax !== undefined)
|
|
702
|
+
evalGates.hallucination_rate_max = hallucinationRateMax;
|
|
703
|
+
const scopeViolationRateMax = parseNumberStrict(env.CODALI_EVAL_GATE_SCOPE_VIOLATION_RATE_MAX, "CODALI_EVAL_GATE_SCOPE_VIOLATION_RATE_MAX");
|
|
704
|
+
if (scopeViolationRateMax !== undefined) {
|
|
705
|
+
evalGates.scope_violation_rate_max = scopeViolationRateMax;
|
|
706
|
+
}
|
|
707
|
+
if (Object.keys(evalGates).length)
|
|
708
|
+
evalConfig.gates = evalGates;
|
|
709
|
+
const learning = {};
|
|
710
|
+
const persistenceMinConfidence = parseNumberStrict(env.CODALI_LEARNING_PERSISTENCE_MIN_CONFIDENCE, "CODALI_LEARNING_PERSISTENCE_MIN_CONFIDENCE");
|
|
711
|
+
if (persistenceMinConfidence !== undefined) {
|
|
712
|
+
learning.persistence_min_confidence = persistenceMinConfidence;
|
|
713
|
+
}
|
|
714
|
+
const enforcementMinConfidence = parseNumberStrict(env.CODALI_LEARNING_ENFORCEMENT_MIN_CONFIDENCE, "CODALI_LEARNING_ENFORCEMENT_MIN_CONFIDENCE");
|
|
715
|
+
if (enforcementMinConfidence !== undefined) {
|
|
716
|
+
learning.enforcement_min_confidence = enforcementMinConfidence;
|
|
717
|
+
}
|
|
718
|
+
const requireConfirmation = parseBoolean(env.CODALI_LEARNING_REQUIRE_CONFIRMATION_FOR_LOW_CONFIDENCE);
|
|
719
|
+
if (requireConfirmation !== undefined) {
|
|
720
|
+
learning.require_confirmation_for_low_confidence = requireConfirmation;
|
|
721
|
+
}
|
|
722
|
+
const autoEnforceHigh = parseBoolean(env.CODALI_LEARNING_AUTO_ENFORCE_HIGH_CONFIDENCE);
|
|
723
|
+
if (autoEnforceHigh !== undefined) {
|
|
724
|
+
learning.auto_enforce_high_confidence = autoEnforceHigh;
|
|
725
|
+
}
|
|
726
|
+
if (env.CODALI_LEARNING_CANDIDATE_STORE_FILE) {
|
|
727
|
+
learning.candidate_store_file = env.CODALI_LEARNING_CANDIDATE_STORE_FILE;
|
|
728
|
+
}
|
|
729
|
+
const hasDeepInvestigation = Object.values(deepInvestigation).some((value) => value !== undefined);
|
|
730
|
+
const config = {
|
|
731
|
+
limits,
|
|
732
|
+
tools,
|
|
733
|
+
docdex,
|
|
734
|
+
logging,
|
|
735
|
+
context,
|
|
736
|
+
deepInvestigation: hasDeepInvestigation ? deepInvestigation : undefined,
|
|
737
|
+
security,
|
|
738
|
+
builder,
|
|
739
|
+
interpreter,
|
|
740
|
+
streaming,
|
|
741
|
+
cost,
|
|
742
|
+
localContext,
|
|
743
|
+
eval: Object.keys(evalConfig).length ? evalConfig : undefined,
|
|
744
|
+
learning: Object.keys(learning).length ? learning : undefined,
|
|
745
|
+
workflow: Object.keys(workflow).length ? workflow : undefined,
|
|
746
|
+
routing: Object.keys(routing).length ? routing : undefined,
|
|
747
|
+
};
|
|
748
|
+
if (env.CODALI_WORKSPACE_ROOT)
|
|
749
|
+
config.workspaceRoot = env.CODALI_WORKSPACE_ROOT;
|
|
750
|
+
if (env.CODALI_PROJECT)
|
|
751
|
+
config.project = env.CODALI_PROJECT;
|
|
752
|
+
if (env.CODALI_COMMAND)
|
|
753
|
+
config.command = env.CODALI_COMMAND;
|
|
754
|
+
if (env.CODALI_COMMAND_RUN_ID)
|
|
755
|
+
config.commandRunId = env.CODALI_COMMAND_RUN_ID;
|
|
756
|
+
if (env.CODALI_JOB_ID)
|
|
757
|
+
config.jobId = env.CODALI_JOB_ID;
|
|
758
|
+
if (env.CODALI_RUN_ID)
|
|
759
|
+
config.runId = env.CODALI_RUN_ID;
|
|
760
|
+
if (env.CODALI_TASK_ID)
|
|
761
|
+
config.taskId = env.CODALI_TASK_ID;
|
|
762
|
+
if (env.CODALI_TASK_KEY)
|
|
763
|
+
config.taskKey = env.CODALI_TASK_KEY;
|
|
764
|
+
if (env.CODALI_AGENT_ID)
|
|
765
|
+
config.agentId = env.CODALI_AGENT_ID;
|
|
766
|
+
if (env.CODALI_AGENT_SLUG)
|
|
767
|
+
config.agentSlug = env.CODALI_AGENT_SLUG;
|
|
768
|
+
const smart = parseBoolean(env.CODALI_SMART);
|
|
769
|
+
if (smart !== undefined)
|
|
770
|
+
config.smart = smart;
|
|
771
|
+
if (env.CODALI_PLAN_HINT)
|
|
772
|
+
config.planHint = env.CODALI_PLAN_HINT;
|
|
773
|
+
if (env.CODALI_PROVIDER)
|
|
774
|
+
config.provider = env.CODALI_PROVIDER;
|
|
775
|
+
if (env.CODALI_MODEL)
|
|
776
|
+
config.model = env.CODALI_MODEL;
|
|
777
|
+
if (env.CODALI_API_KEY)
|
|
778
|
+
config.apiKey = env.CODALI_API_KEY;
|
|
779
|
+
if (env.CODALI_BASE_URL)
|
|
780
|
+
config.baseUrl = env.CODALI_BASE_URL;
|
|
781
|
+
return config;
|
|
782
|
+
};
|
|
783
|
+
const mergeDeepInvestigationConfigs = (defaults, ...sources) => {
|
|
784
|
+
const hasAny = Boolean(defaults) || sources.some(Boolean);
|
|
785
|
+
if (!hasAny)
|
|
786
|
+
return undefined;
|
|
787
|
+
const merged = Object.assign({}, defaults ?? {}, ...sources.filter(Boolean));
|
|
788
|
+
const toolQuotaSources = sources.map((source) => source?.toolQuota);
|
|
789
|
+
const budgetSources = sources.map((source) => source?.investigationBudget);
|
|
790
|
+
const evidenceSources = sources.map((source) => source?.evidenceGate);
|
|
791
|
+
merged.toolQuota = Object.assign({}, defaults?.toolQuota ?? {}, ...toolQuotaSources.filter(Boolean));
|
|
792
|
+
merged.investigationBudget = Object.assign({}, defaults?.investigationBudget ?? {}, ...budgetSources.filter(Boolean));
|
|
793
|
+
merged.evidenceGate = Object.assign({}, defaults?.evidenceGate ?? {}, ...evidenceSources.filter(Boolean));
|
|
794
|
+
return merged;
|
|
795
|
+
};
|
|
796
|
+
const mergeWorkflowConfig = (defaults, ...sources) => {
|
|
797
|
+
const profiles = Object.fromEntries(WORKFLOW_PROFILE_NAMES.map((profileName) => [
|
|
798
|
+
profileName,
|
|
799
|
+
{
|
|
800
|
+
...DEFAULT_WORKFLOW_PROFILES[profileName],
|
|
801
|
+
...(defaults?.profiles?.[profileName] ?? {}),
|
|
802
|
+
},
|
|
803
|
+
]));
|
|
804
|
+
for (const source of sources) {
|
|
805
|
+
if (!source?.profiles)
|
|
806
|
+
continue;
|
|
807
|
+
for (const profileName of WORKFLOW_PROFILE_NAMES) {
|
|
808
|
+
const override = source.profiles[profileName];
|
|
809
|
+
if (!override)
|
|
810
|
+
continue;
|
|
811
|
+
profiles[profileName] = {
|
|
812
|
+
...profiles[profileName],
|
|
813
|
+
...override,
|
|
814
|
+
name: profileName,
|
|
815
|
+
};
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
let profile = defaults?.profile;
|
|
819
|
+
for (const source of sources) {
|
|
820
|
+
if (source?.profile) {
|
|
821
|
+
profile = source.profile;
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
return { profile: profile ?? DEFAULT_WORKFLOW_PROFILE, profiles };
|
|
825
|
+
};
|
|
826
|
+
const mergeEvalConfig = (defaults, ...sources) => {
|
|
827
|
+
const merged = {
|
|
828
|
+
...defaults,
|
|
829
|
+
report_dir: defaults.report_dir,
|
|
830
|
+
gates: {
|
|
831
|
+
...defaults.gates,
|
|
832
|
+
},
|
|
833
|
+
};
|
|
834
|
+
for (const source of sources) {
|
|
835
|
+
if (!source)
|
|
836
|
+
continue;
|
|
837
|
+
if (source.report_dir !== undefined)
|
|
838
|
+
merged.report_dir = source.report_dir;
|
|
839
|
+
if (source.gates) {
|
|
840
|
+
merged.gates = {
|
|
841
|
+
...merged.gates,
|
|
842
|
+
...source.gates,
|
|
843
|
+
};
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
return merged;
|
|
847
|
+
};
|
|
848
|
+
const mergeLearningConfig = (defaults, ...sources) => {
|
|
849
|
+
const merged = {
|
|
850
|
+
...defaults,
|
|
851
|
+
};
|
|
852
|
+
for (const source of sources) {
|
|
853
|
+
if (!source)
|
|
854
|
+
continue;
|
|
855
|
+
if (source.persistence_min_confidence !== undefined) {
|
|
856
|
+
merged.persistence_min_confidence = source.persistence_min_confidence;
|
|
857
|
+
}
|
|
858
|
+
if (source.enforcement_min_confidence !== undefined) {
|
|
859
|
+
merged.enforcement_min_confidence = source.enforcement_min_confidence;
|
|
860
|
+
}
|
|
861
|
+
if (source.require_confirmation_for_low_confidence !== undefined) {
|
|
862
|
+
merged.require_confirmation_for_low_confidence =
|
|
863
|
+
source.require_confirmation_for_low_confidence;
|
|
864
|
+
}
|
|
865
|
+
if (source.auto_enforce_high_confidence !== undefined) {
|
|
866
|
+
merged.auto_enforce_high_confidence = source.auto_enforce_high_confidence;
|
|
867
|
+
}
|
|
868
|
+
if (source.candidate_store_file !== undefined) {
|
|
869
|
+
merged.candidate_store_file = source.candidate_store_file;
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
return merged;
|
|
873
|
+
};
|
|
874
|
+
const resolveCommandProfileName = (command) => {
|
|
875
|
+
if (!command)
|
|
876
|
+
return undefined;
|
|
877
|
+
const normalized = command.trim().toLowerCase();
|
|
878
|
+
if (!normalized || normalized === "run")
|
|
879
|
+
return undefined;
|
|
880
|
+
return COMMAND_PROFILE_MAP[normalized];
|
|
881
|
+
};
|
|
882
|
+
const resolveWorkflowProfile = (params) => {
|
|
883
|
+
const profiles = params.mergedWorkflow?.profiles;
|
|
884
|
+
const availableProfiles = profiles ?? DEFAULT_WORKFLOW_PROFILES;
|
|
885
|
+
const commandProfile = resolveCommandProfileName(params.command);
|
|
886
|
+
if (commandProfile) {
|
|
887
|
+
return { profile: availableProfiles[commandProfile], source: "command" };
|
|
888
|
+
}
|
|
889
|
+
const selectedProfile = params.cliWorkflow?.profile
|
|
890
|
+
?? params.envWorkflow?.profile
|
|
891
|
+
?? params.fileWorkflow?.profile
|
|
892
|
+
?? params.mergedWorkflow?.profile
|
|
893
|
+
?? DEFAULT_WORKFLOW_PROFILE;
|
|
894
|
+
const source = params.cliWorkflow?.profile ? "cli"
|
|
895
|
+
: params.envWorkflow?.profile ? "env"
|
|
896
|
+
: params.fileWorkflow?.profile ? "config"
|
|
897
|
+
: "default";
|
|
898
|
+
return {
|
|
899
|
+
profile: availableProfiles[selectedProfile],
|
|
900
|
+
source,
|
|
901
|
+
};
|
|
902
|
+
};
|
|
903
|
+
const mergeConfigs = (defaults, fileConfig, envConfig, cliConfig) => {
|
|
904
|
+
const fileWorkflow = normalizeWorkflowConfig(fileConfig?.workflow, "config.workflow");
|
|
905
|
+
const envWorkflow = normalizeWorkflowConfig(envConfig?.workflow, "env.workflow");
|
|
906
|
+
const cliWorkflow = normalizeWorkflowConfig(cliConfig?.workflow, "cli.workflow");
|
|
907
|
+
const fileEval = normalizeEvalConfig(fileConfig?.eval, "config.eval");
|
|
908
|
+
const envEval = normalizeEvalConfig(envConfig?.eval, "env.eval");
|
|
909
|
+
const cliEval = normalizeEvalConfig(cliConfig?.eval, "cli.eval");
|
|
910
|
+
const fileLearning = normalizeLearningConfig(fileConfig?.learning, "config.learning");
|
|
911
|
+
const envLearning = normalizeLearningConfig(envConfig?.learning, "env.learning");
|
|
912
|
+
const cliLearning = normalizeLearningConfig(cliConfig?.learning, "cli.learning");
|
|
913
|
+
const deepInvestigation = mergeDeepInvestigationConfigs(defaults.deepInvestigation, normalizeDeepInvestigationConfig(fileConfig?.deepInvestigation, "config.deepInvestigation"), normalizeDeepInvestigationConfig(envConfig?.deepInvestigation, "env.deepInvestigation"), normalizeDeepInvestigationConfig(cliConfig?.deepInvestigation, "cli.deepInvestigation"));
|
|
914
|
+
const workflow = mergeWorkflowConfig(defaults.workflow, fileWorkflow, envWorkflow, cliWorkflow);
|
|
915
|
+
const evalConfig = mergeEvalConfig(defaults.eval, fileEval, envEval, cliEval);
|
|
916
|
+
const learningConfig = mergeLearningConfig(defaults.learning, fileLearning, envLearning, cliLearning);
|
|
917
|
+
const docdex = {
|
|
918
|
+
...defaults.docdex,
|
|
919
|
+
...fileConfig?.docdex,
|
|
920
|
+
...envConfig?.docdex,
|
|
921
|
+
...cliConfig?.docdex,
|
|
922
|
+
};
|
|
923
|
+
const tools = {
|
|
924
|
+
...defaults.tools,
|
|
925
|
+
...fileConfig?.tools,
|
|
926
|
+
...envConfig?.tools,
|
|
927
|
+
...cliConfig?.tools,
|
|
928
|
+
};
|
|
929
|
+
const limits = {
|
|
930
|
+
...defaults.limits,
|
|
931
|
+
...fileConfig?.limits,
|
|
932
|
+
...envConfig?.limits,
|
|
933
|
+
...cliConfig?.limits,
|
|
934
|
+
};
|
|
935
|
+
const context = {
|
|
936
|
+
...defaults.context,
|
|
937
|
+
...fileConfig?.context,
|
|
938
|
+
...envConfig?.context,
|
|
939
|
+
...cliConfig?.context,
|
|
940
|
+
};
|
|
941
|
+
const security = {
|
|
942
|
+
...defaults.security,
|
|
943
|
+
...fileConfig?.security,
|
|
944
|
+
...envConfig?.security,
|
|
945
|
+
...cliConfig?.security,
|
|
946
|
+
};
|
|
947
|
+
const builder = {
|
|
948
|
+
...defaults.builder,
|
|
949
|
+
...fileConfig?.builder,
|
|
950
|
+
...envConfig?.builder,
|
|
951
|
+
...cliConfig?.builder,
|
|
952
|
+
};
|
|
953
|
+
const interpreter = {
|
|
954
|
+
...defaults.interpreter,
|
|
955
|
+
...fileConfig?.interpreter,
|
|
956
|
+
...envConfig?.interpreter,
|
|
957
|
+
...cliConfig?.interpreter,
|
|
958
|
+
};
|
|
959
|
+
const streaming = {
|
|
960
|
+
...defaults.streaming,
|
|
961
|
+
...fileConfig?.streaming,
|
|
962
|
+
...envConfig?.streaming,
|
|
963
|
+
...cliConfig?.streaming,
|
|
964
|
+
};
|
|
965
|
+
const cost = {
|
|
966
|
+
...defaults.cost,
|
|
967
|
+
...fileConfig?.cost,
|
|
968
|
+
...envConfig?.cost,
|
|
969
|
+
...cliConfig?.cost,
|
|
970
|
+
};
|
|
971
|
+
const localContext = {
|
|
972
|
+
...defaults.localContext,
|
|
973
|
+
...fileConfig?.localContext,
|
|
974
|
+
...envConfig?.localContext,
|
|
975
|
+
...cliConfig?.localContext,
|
|
976
|
+
modelTokenLimits: {
|
|
977
|
+
...defaults.localContext.modelTokenLimits,
|
|
978
|
+
...fileConfig?.localContext?.modelTokenLimits,
|
|
979
|
+
...envConfig?.localContext?.modelTokenLimits,
|
|
980
|
+
...cliConfig?.localContext?.modelTokenLimits,
|
|
981
|
+
},
|
|
982
|
+
summarize: {
|
|
983
|
+
...defaults.localContext.summarize,
|
|
984
|
+
...fileConfig?.localContext?.summarize,
|
|
985
|
+
...envConfig?.localContext?.summarize,
|
|
986
|
+
...cliConfig?.localContext?.summarize,
|
|
987
|
+
},
|
|
988
|
+
};
|
|
989
|
+
const routing = mergeRoutingConfigs(defaults.routing, fileConfig?.routing, envConfig?.routing, cliConfig?.routing);
|
|
990
|
+
const logging = {
|
|
991
|
+
...defaults.logging,
|
|
992
|
+
...fileConfig?.logging,
|
|
993
|
+
...envConfig?.logging,
|
|
994
|
+
...cliConfig?.logging,
|
|
995
|
+
};
|
|
996
|
+
return {
|
|
997
|
+
...defaults,
|
|
998
|
+
...fileConfig,
|
|
999
|
+
...envConfig,
|
|
1000
|
+
...cliConfig,
|
|
1001
|
+
deepInvestigation,
|
|
1002
|
+
docdex,
|
|
1003
|
+
tools,
|
|
1004
|
+
limits,
|
|
1005
|
+
context,
|
|
1006
|
+
security,
|
|
1007
|
+
builder,
|
|
1008
|
+
interpreter,
|
|
1009
|
+
streaming,
|
|
1010
|
+
cost,
|
|
1011
|
+
localContext,
|
|
1012
|
+
eval: evalConfig,
|
|
1013
|
+
learning: learningConfig,
|
|
1014
|
+
workflow,
|
|
1015
|
+
logging,
|
|
1016
|
+
routing,
|
|
1017
|
+
};
|
|
1018
|
+
};
|
|
1019
|
+
const mergeRoutingConfigs = (...sources) => {
|
|
1020
|
+
const phases = [
|
|
1021
|
+
"librarian",
|
|
1022
|
+
"architect",
|
|
1023
|
+
"builder",
|
|
1024
|
+
"critic",
|
|
1025
|
+
"interpreter",
|
|
1026
|
+
];
|
|
1027
|
+
const merged = {};
|
|
1028
|
+
for (const phase of phases) {
|
|
1029
|
+
const phaseConfigs = sources.map((source) => {
|
|
1030
|
+
if (!source)
|
|
1031
|
+
return undefined;
|
|
1032
|
+
return Object.prototype.hasOwnProperty.call(source, phase) ? source[phase] : undefined;
|
|
1033
|
+
});
|
|
1034
|
+
const combined = Object.assign({}, ...phaseConfigs.filter(Boolean));
|
|
1035
|
+
const hasPhase = phaseConfigs.some((config) => config !== undefined);
|
|
1036
|
+
if (hasPhase) {
|
|
1037
|
+
merged[phase] = combined;
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
1040
|
+
return Object.keys(merged).length ? merged : undefined;
|
|
1041
|
+
};
|
|
1042
|
+
const finalizeConfig = (cwd, config) => {
|
|
1043
|
+
const workspaceRoot = path.resolve(cwd, config.workspaceRoot);
|
|
1044
|
+
return {
|
|
1045
|
+
...config,
|
|
1046
|
+
streaming: {
|
|
1047
|
+
...config.streaming,
|
|
1048
|
+
enabled: true,
|
|
1049
|
+
},
|
|
1050
|
+
workspaceRoot,
|
|
1051
|
+
};
|
|
1052
|
+
};
|
|
1053
|
+
const assertRequired = (config) => {
|
|
1054
|
+
const missing = [];
|
|
1055
|
+
if (!config.workspaceRoot)
|
|
1056
|
+
missing.push("workspaceRoot");
|
|
1057
|
+
const hasRoutingAgent = config.smart &&
|
|
1058
|
+
Object.values(config.routing ?? {}).some((phase) => Boolean(phase?.agent));
|
|
1059
|
+
if (!config.smart && !config.provider)
|
|
1060
|
+
missing.push("provider");
|
|
1061
|
+
if (!config.smart && !config.model)
|
|
1062
|
+
missing.push("model");
|
|
1063
|
+
if (config.smart && !config.provider && !hasRoutingAgent) {
|
|
1064
|
+
// allow auto-selection from agent DB
|
|
1065
|
+
}
|
|
1066
|
+
if (missing.length) {
|
|
1067
|
+
throw new Error(`Missing required config: ${missing.join(", ")}`);
|
|
1068
|
+
}
|
|
1069
|
+
};
|
|
1070
|
+
const assertValid = (config) => {
|
|
1071
|
+
const errors = [];
|
|
1072
|
+
const { localContext } = config;
|
|
1073
|
+
if (localContext.maxMessages < 0)
|
|
1074
|
+
errors.push("localContext.maxMessages");
|
|
1075
|
+
if (localContext.maxBytesPerLane < 0)
|
|
1076
|
+
errors.push("localContext.maxBytesPerLane");
|
|
1077
|
+
if (localContext.summarize.targetTokens < 0)
|
|
1078
|
+
errors.push("localContext.summarize.targetTokens");
|
|
1079
|
+
if (localContext.summarize.thresholdPct <= 0 ||
|
|
1080
|
+
localContext.summarize.thresholdPct > 1) {
|
|
1081
|
+
errors.push("localContext.summarize.thresholdPct");
|
|
1082
|
+
}
|
|
1083
|
+
if (config.interpreter.maxRetries < 0)
|
|
1084
|
+
errors.push("interpreter.maxRetries");
|
|
1085
|
+
if (config.interpreter.timeoutMs < 0)
|
|
1086
|
+
errors.push("interpreter.timeoutMs");
|
|
1087
|
+
for (const [key, value] of Object.entries(localContext.modelTokenLimits)) {
|
|
1088
|
+
if (value <= 0)
|
|
1089
|
+
errors.push(`localContext.modelTokenLimits.${key}`);
|
|
1090
|
+
}
|
|
1091
|
+
const workflowProfile = config.resolvedWorkflowProfile;
|
|
1092
|
+
if (workflowProfile) {
|
|
1093
|
+
if (workflowProfile.retryBudget < 0)
|
|
1094
|
+
errors.push("resolvedWorkflowProfile.retryBudget");
|
|
1095
|
+
if (!workflowProfile.verificationPolicy.trim()) {
|
|
1096
|
+
errors.push("resolvedWorkflowProfile.verificationPolicy");
|
|
1097
|
+
}
|
|
1098
|
+
if (workflowProfile.verificationMinimumChecks < 0) {
|
|
1099
|
+
errors.push("resolvedWorkflowProfile.verificationMinimumChecks");
|
|
1100
|
+
}
|
|
1101
|
+
if (!workflowProfile.description.trim()) {
|
|
1102
|
+
errors.push("resolvedWorkflowProfile.description");
|
|
1103
|
+
}
|
|
1104
|
+
}
|
|
1105
|
+
const deepInvestigation = config.deepInvestigation;
|
|
1106
|
+
if (deepInvestigation) {
|
|
1107
|
+
const nonNegative = (value, label) => {
|
|
1108
|
+
if (value !== undefined && value < 0)
|
|
1109
|
+
errors.push(label);
|
|
1110
|
+
};
|
|
1111
|
+
const { toolQuota, investigationBudget, evidenceGate } = deepInvestigation;
|
|
1112
|
+
if (toolQuota) {
|
|
1113
|
+
nonNegative(toolQuota.search, "deepInvestigation.toolQuota.search");
|
|
1114
|
+
nonNegative(toolQuota.openOrSnippet, "deepInvestigation.toolQuota.openOrSnippet");
|
|
1115
|
+
nonNegative(toolQuota.symbolsOrAst, "deepInvestigation.toolQuota.symbolsOrAst");
|
|
1116
|
+
nonNegative(toolQuota.impact, "deepInvestigation.toolQuota.impact");
|
|
1117
|
+
nonNegative(toolQuota.tree, "deepInvestigation.toolQuota.tree");
|
|
1118
|
+
nonNegative(toolQuota.dagExport, "deepInvestigation.toolQuota.dagExport");
|
|
1119
|
+
}
|
|
1120
|
+
if (investigationBudget) {
|
|
1121
|
+
nonNegative(investigationBudget.minCycles, "deepInvestigation.investigationBudget.minCycles");
|
|
1122
|
+
nonNegative(investigationBudget.minSeconds, "deepInvestigation.investigationBudget.minSeconds");
|
|
1123
|
+
nonNegative(investigationBudget.maxCycles, "deepInvestigation.investigationBudget.maxCycles");
|
|
1124
|
+
if (investigationBudget.minCycles !== undefined
|
|
1125
|
+
&& investigationBudget.maxCycles !== undefined
|
|
1126
|
+
&& investigationBudget.maxCycles < investigationBudget.minCycles) {
|
|
1127
|
+
errors.push("deepInvestigation.investigationBudget.maxCycles");
|
|
1128
|
+
}
|
|
1129
|
+
}
|
|
1130
|
+
if (evidenceGate) {
|
|
1131
|
+
nonNegative(evidenceGate.minSearchHits, "deepInvestigation.evidenceGate.minSearchHits");
|
|
1132
|
+
nonNegative(evidenceGate.minOpenOrSnippet, "deepInvestigation.evidenceGate.minOpenOrSnippet");
|
|
1133
|
+
nonNegative(evidenceGate.minSymbolsOrAst, "deepInvestigation.evidenceGate.minSymbolsOrAst");
|
|
1134
|
+
nonNegative(evidenceGate.minImpact, "deepInvestigation.evidenceGate.minImpact");
|
|
1135
|
+
nonNegative(evidenceGate.maxWarnings, "deepInvestigation.evidenceGate.maxWarnings");
|
|
1136
|
+
}
|
|
1137
|
+
}
|
|
1138
|
+
const evalGates = config.eval.gates;
|
|
1139
|
+
const validateRate = (value, label) => {
|
|
1140
|
+
if (!Number.isFinite(value) || value < 0 || value > 1)
|
|
1141
|
+
errors.push(label);
|
|
1142
|
+
};
|
|
1143
|
+
validateRate(evalGates.patch_apply_drop_max, "eval.gates.patch_apply_drop_max");
|
|
1144
|
+
validateRate(evalGates.verification_pass_rate_min, "eval.gates.verification_pass_rate_min");
|
|
1145
|
+
validateRate(evalGates.hallucination_rate_max, "eval.gates.hallucination_rate_max");
|
|
1146
|
+
validateRate(evalGates.scope_violation_rate_max, "eval.gates.scope_violation_rate_max");
|
|
1147
|
+
if (!config.eval.report_dir.trim())
|
|
1148
|
+
errors.push("eval.report_dir");
|
|
1149
|
+
validateRate(config.learning.persistence_min_confidence, "learning.persistence_min_confidence");
|
|
1150
|
+
validateRate(config.learning.enforcement_min_confidence, "learning.enforcement_min_confidence");
|
|
1151
|
+
if (config.learning.enforcement_min_confidence < config.learning.persistence_min_confidence) {
|
|
1152
|
+
errors.push("learning.enforcement_min_confidence");
|
|
1153
|
+
}
|
|
1154
|
+
if (!config.learning.candidate_store_file.trim()) {
|
|
1155
|
+
errors.push("learning.candidate_store_file");
|
|
1156
|
+
}
|
|
1157
|
+
if (errors.length) {
|
|
1158
|
+
throw new Error(`Invalid config values: ${errors.join(", ")}`);
|
|
1159
|
+
}
|
|
1160
|
+
};
|
|
1161
|
+
export const loadConfig = async (options = {}) => {
|
|
1162
|
+
const cwd = options.cwd ?? process.cwd();
|
|
1163
|
+
const env = options.env ?? process.env;
|
|
1164
|
+
const configPath = options.configPath ?? findConfigFile(cwd);
|
|
1165
|
+
const fileConfig = await readConfigFile(configPath);
|
|
1166
|
+
const envConfig = loadEnvConfig(env);
|
|
1167
|
+
const fileWorkflow = normalizeWorkflowConfig(fileConfig?.workflow, "config.workflow");
|
|
1168
|
+
const envWorkflow = normalizeWorkflowConfig(envConfig?.workflow, "env.workflow");
|
|
1169
|
+
const cliWorkflow = normalizeWorkflowConfig(options.cli?.workflow, "cli.workflow");
|
|
1170
|
+
const defaults = {
|
|
1171
|
+
workspaceRoot: ".",
|
|
1172
|
+
provider: "",
|
|
1173
|
+
model: "",
|
|
1174
|
+
apiKey: undefined,
|
|
1175
|
+
baseUrl: undefined,
|
|
1176
|
+
smart: true,
|
|
1177
|
+
docdex: {
|
|
1178
|
+
baseUrl: envConfig.docdex?.baseUrl ?? DEFAULT_DOCDEX_BASE_URL,
|
|
1179
|
+
repoRoot: envConfig.docdex?.repoRoot,
|
|
1180
|
+
repoId: envConfig.docdex?.repoId,
|
|
1181
|
+
},
|
|
1182
|
+
tools: DEFAULT_TOOL_CONFIG,
|
|
1183
|
+
limits: DEFAULT_LIMITS,
|
|
1184
|
+
context: DEFAULT_CONTEXT,
|
|
1185
|
+
deepInvestigation: DEFAULT_DEEP_INVESTIGATION,
|
|
1186
|
+
security: DEFAULT_SECURITY,
|
|
1187
|
+
builder: DEFAULT_BUILDER,
|
|
1188
|
+
interpreter: DEFAULT_INTERPRETER,
|
|
1189
|
+
streaming: DEFAULT_STREAMING,
|
|
1190
|
+
cost: DEFAULT_COST,
|
|
1191
|
+
localContext: DEFAULT_LOCAL_CONTEXT,
|
|
1192
|
+
eval: DEFAULT_EVAL,
|
|
1193
|
+
learning: DEFAULT_LEARNING,
|
|
1194
|
+
workflow: {
|
|
1195
|
+
profile: DEFAULT_WORKFLOW_PROFILE,
|
|
1196
|
+
profiles: DEFAULT_WORKFLOW_PROFILES,
|
|
1197
|
+
},
|
|
1198
|
+
logging: DEFAULT_LOGGING,
|
|
1199
|
+
routing: undefined,
|
|
1200
|
+
};
|
|
1201
|
+
const merged = mergeConfigs(defaults, fileConfig, envConfig, options.cli);
|
|
1202
|
+
const hasExplicitSmart = fileConfig?.smart !== undefined
|
|
1203
|
+
|| envConfig.smart !== undefined
|
|
1204
|
+
|| options.cli?.smart !== undefined;
|
|
1205
|
+
const hasExplicitBuilderMode = fileConfig?.builder?.mode !== undefined
|
|
1206
|
+
|| envConfig.builder?.mode !== undefined
|
|
1207
|
+
|| options.cli?.builder?.mode !== undefined;
|
|
1208
|
+
const hasExplicitBuilderFallback = fileConfig?.builder?.fallbackToInterpreter !== undefined
|
|
1209
|
+
|| envConfig.builder?.fallbackToInterpreter !== undefined
|
|
1210
|
+
|| options.cli?.builder?.fallbackToInterpreter !== undefined;
|
|
1211
|
+
const hasExplicitRetryBudget = fileConfig?.limits?.maxRetries !== undefined
|
|
1212
|
+
|| envConfig.limits?.maxRetries !== undefined
|
|
1213
|
+
|| options.cli?.limits?.maxRetries !== undefined;
|
|
1214
|
+
const workflowResolution = resolveWorkflowProfile({
|
|
1215
|
+
command: merged.command,
|
|
1216
|
+
mergedWorkflow: merged.workflow,
|
|
1217
|
+
fileWorkflow,
|
|
1218
|
+
envWorkflow,
|
|
1219
|
+
cliWorkflow,
|
|
1220
|
+
});
|
|
1221
|
+
merged.resolvedWorkflowProfile = {
|
|
1222
|
+
...workflowResolution.profile,
|
|
1223
|
+
source: workflowResolution.source,
|
|
1224
|
+
command: (merged.command ?? "run").trim().toLowerCase() || "run",
|
|
1225
|
+
};
|
|
1226
|
+
merged.workflow = {
|
|
1227
|
+
profile: merged.resolvedWorkflowProfile.name,
|
|
1228
|
+
profiles: merged.workflow?.profiles ?? DEFAULT_WORKFLOW_PROFILES,
|
|
1229
|
+
};
|
|
1230
|
+
if (!hasExplicitSmart) {
|
|
1231
|
+
merged.smart = merged.resolvedWorkflowProfile.smart;
|
|
1232
|
+
}
|
|
1233
|
+
if (!hasExplicitBuilderMode) {
|
|
1234
|
+
merged.builder.mode = merged.resolvedWorkflowProfile.builderMode;
|
|
1235
|
+
}
|
|
1236
|
+
if (!hasExplicitBuilderFallback) {
|
|
1237
|
+
merged.builder.fallbackToInterpreter = merged.resolvedWorkflowProfile.fallbackToInterpreter;
|
|
1238
|
+
}
|
|
1239
|
+
if (!hasExplicitRetryBudget) {
|
|
1240
|
+
merged.limits.maxRetries = merged.resolvedWorkflowProfile.retryBudget;
|
|
1241
|
+
}
|
|
1242
|
+
const finalized = finalizeConfig(cwd, merged);
|
|
1243
|
+
assertRequired(finalized);
|
|
1244
|
+
assertValid(finalized);
|
|
1245
|
+
return finalized;
|
|
1246
|
+
};
|