@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,75 @@
|
|
|
1
|
+
const toNumber = (value) => {
|
|
2
|
+
if (!Number.isFinite(value))
|
|
3
|
+
return 0;
|
|
4
|
+
return value ?? 0;
|
|
5
|
+
};
|
|
6
|
+
const uniqueStrings = (values) => {
|
|
7
|
+
return Array.from(new Set(values.filter((value) => value.length > 0)));
|
|
8
|
+
};
|
|
9
|
+
const buildRequiredMetrics = (config) => {
|
|
10
|
+
return {
|
|
11
|
+
search_hits: Math.max(0, Math.floor(toNumber(config.minSearchHits))),
|
|
12
|
+
open_or_snippet: Math.max(0, Math.floor(toNumber(config.minOpenOrSnippet))),
|
|
13
|
+
symbols_or_ast: Math.max(0, Math.floor(toNumber(config.minSymbolsOrAst))),
|
|
14
|
+
impact: Math.max(0, Math.floor(toNumber(config.minImpact))),
|
|
15
|
+
warnings: Math.max(0, Math.floor(toNumber(config.maxWarnings))),
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
const buildObservedMetrics = (evidence, toolUsage, warnings) => {
|
|
19
|
+
const warningList = uniqueStrings([
|
|
20
|
+
...(evidence?.warnings ?? []),
|
|
21
|
+
...(warnings ?? []),
|
|
22
|
+
]);
|
|
23
|
+
const searchHits = toNumber(evidence?.search_hits);
|
|
24
|
+
const snippetCount = toNumber(evidence?.snippet_count);
|
|
25
|
+
const symbolFiles = toNumber(evidence?.symbol_files);
|
|
26
|
+
const astFiles = toNumber(evidence?.ast_files);
|
|
27
|
+
const impactFiles = toNumber(evidence?.impact_files);
|
|
28
|
+
const impactEdges = toNumber(evidence?.impact_edges);
|
|
29
|
+
const toolOpenOrSnippet = toNumber(toolUsage?.open_or_snippet);
|
|
30
|
+
const toolSymbolsOrAst = toNumber(toolUsage?.symbols_or_ast);
|
|
31
|
+
const toolImpact = toNumber(toolUsage?.impact);
|
|
32
|
+
const metrics = {
|
|
33
|
+
search_hits: searchHits,
|
|
34
|
+
open_or_snippet: Math.max(snippetCount, toolOpenOrSnippet),
|
|
35
|
+
symbols_or_ast: Math.max(symbolFiles + astFiles, toolSymbolsOrAst),
|
|
36
|
+
impact: Math.max(impactFiles, impactEdges, toolImpact),
|
|
37
|
+
warnings: warningList.length,
|
|
38
|
+
};
|
|
39
|
+
return { metrics, warningList, gaps: evidence?.gaps };
|
|
40
|
+
};
|
|
41
|
+
const buildMissingSignals = (observed, required) => {
|
|
42
|
+
const missing = [];
|
|
43
|
+
if (observed.search_hits < required.search_hits)
|
|
44
|
+
missing.push("search_hits");
|
|
45
|
+
if (observed.open_or_snippet < required.open_or_snippet) {
|
|
46
|
+
missing.push("open_or_snippet");
|
|
47
|
+
}
|
|
48
|
+
if (observed.symbols_or_ast < required.symbols_or_ast) {
|
|
49
|
+
missing.push("symbols_or_ast");
|
|
50
|
+
}
|
|
51
|
+
if (observed.impact < required.impact)
|
|
52
|
+
missing.push("impact");
|
|
53
|
+
if (observed.warnings > required.warnings)
|
|
54
|
+
missing.push("warnings");
|
|
55
|
+
return missing;
|
|
56
|
+
};
|
|
57
|
+
export const evaluateEvidenceGate = ({ config, evidence, toolUsage, warnings, }) => {
|
|
58
|
+
const required = buildRequiredMetrics(config);
|
|
59
|
+
const { metrics: observed, warningList, gaps } = buildObservedMetrics(evidence, toolUsage, warnings);
|
|
60
|
+
const missing = buildMissingSignals(observed, required);
|
|
61
|
+
const totalSignals = 5;
|
|
62
|
+
const score = (totalSignals - missing.length) / totalSignals;
|
|
63
|
+
const threshold = 1;
|
|
64
|
+
const status = missing.length === 0 ? "pass" : "fail";
|
|
65
|
+
return {
|
|
66
|
+
status,
|
|
67
|
+
score,
|
|
68
|
+
threshold,
|
|
69
|
+
missing,
|
|
70
|
+
required,
|
|
71
|
+
observed,
|
|
72
|
+
warnings: warningList.length ? warningList : undefined,
|
|
73
|
+
gaps,
|
|
74
|
+
};
|
|
75
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { DocdexClient } from "../docdex/DocdexClient.js";
|
|
2
|
+
export interface GoldenExample {
|
|
3
|
+
intent: string;
|
|
4
|
+
patch: string;
|
|
5
|
+
score?: number;
|
|
6
|
+
}
|
|
7
|
+
export declare class GoldenExampleIndexer {
|
|
8
|
+
private client;
|
|
9
|
+
constructor(client: DocdexClient);
|
|
10
|
+
findExamples(intent: string, limit?: number): Promise<GoldenExample[]>;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=GoldenExampleIndexer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GoldenExampleIndexer.d.ts","sourceRoot":"","sources":["../../src/cognitive/GoldenExampleIndexer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAE9D,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,qBAAa,oBAAoB;IACnB,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,YAAY;IAElC,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,SAAI,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;CAiCxE"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export class GoldenExampleIndexer {
|
|
2
|
+
constructor(client) {
|
|
3
|
+
this.client = client;
|
|
4
|
+
}
|
|
5
|
+
async findExamples(intent, limit = 3) {
|
|
6
|
+
try {
|
|
7
|
+
// 1. Recall from Repo Memory using the intent
|
|
8
|
+
const result = await this.client.memoryRecall(intent, limit * 3);
|
|
9
|
+
const hits = result.results || [];
|
|
10
|
+
const examples = [];
|
|
11
|
+
for (const hit of hits) {
|
|
12
|
+
if (!hit.content.startsWith("GOLDEN_EXAMPLE"))
|
|
13
|
+
continue;
|
|
14
|
+
// Parse the stored format:
|
|
15
|
+
// GOLDEN_EXAMPLE
|
|
16
|
+
// INTENT: <intent>
|
|
17
|
+
// PATCH: <patch>
|
|
18
|
+
const intentMatch = hit.content.match(/INTENT:\s*(.*?)\nPATCH:/s);
|
|
19
|
+
const patchMatch = hit.content.match(/PATCH:\s*([\s\S]*)$/);
|
|
20
|
+
if (intentMatch && patchMatch) {
|
|
21
|
+
examples.push({
|
|
22
|
+
intent: intentMatch[1].trim(),
|
|
23
|
+
patch: patchMatch[1].trim(),
|
|
24
|
+
score: hit.score
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return examples.slice(0, limit);
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return [];
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export interface GoldenSetEntry {
|
|
2
|
+
intent: string;
|
|
3
|
+
plan_summary: string;
|
|
4
|
+
touched_files: string[];
|
|
5
|
+
review_notes?: string;
|
|
6
|
+
qa_notes?: string;
|
|
7
|
+
patch_summary?: string;
|
|
8
|
+
created_at: string;
|
|
9
|
+
}
|
|
10
|
+
export interface GoldenSetStoreOptions {
|
|
11
|
+
workspaceRoot: string;
|
|
12
|
+
storagePath?: string;
|
|
13
|
+
maxEntries?: number;
|
|
14
|
+
}
|
|
15
|
+
export interface GoldenExampleSummary {
|
|
16
|
+
intent: string;
|
|
17
|
+
patch: string;
|
|
18
|
+
score?: number;
|
|
19
|
+
}
|
|
20
|
+
export declare class GoldenSetStore {
|
|
21
|
+
private workspaceRoot;
|
|
22
|
+
private storagePath;
|
|
23
|
+
private maxEntries;
|
|
24
|
+
constructor(options: GoldenSetStoreOptions);
|
|
25
|
+
private resolveStoragePath;
|
|
26
|
+
private sanitizeEntry;
|
|
27
|
+
load(): Promise<GoldenSetEntry[]>;
|
|
28
|
+
append(entry: Omit<GoldenSetEntry, "created_at"> & {
|
|
29
|
+
created_at?: string;
|
|
30
|
+
}): Promise<GoldenSetEntry[]>;
|
|
31
|
+
findExamples(intent: string, limit?: number): Promise<GoldenExampleSummary[]>;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=GoldenSetStore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GoldenSetStore.d.ts","sourceRoot":"","sources":["../../src/cognitive/GoldenSetStore.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,qBAAqB;IACpC,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AA6ED,qBAAa,cAAc;IACzB,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,UAAU,CAAS;gBAEf,OAAO,EAAE,qBAAqB;IAM1C,OAAO,CAAC,kBAAkB;IAS1B,OAAO,CAAC,aAAa;IAYf,IAAI,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC;IAkBjC,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,cAAc,EAAE,YAAY,CAAC,GAAG;QAAE,UAAU,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC;IAiBtG,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,SAAI,GAAG,OAAO,CAAC,oBAAoB,EAAE,CAAC;CAuB/E"}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { promises as fs } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
const DEFAULT_STORAGE_PATH = ".mcoda/codali/golden-examples.jsonl";
|
|
4
|
+
const DEFAULT_MAX_ENTRIES = 50;
|
|
5
|
+
const REDACTION_PATTERNS = [
|
|
6
|
+
[/AKIA[0-9A-Z]{16}/g, "[REDACTED_AWS_KEY]"],
|
|
7
|
+
[/\bsk-[A-Za-z0-9]{20,}\b/g, "[REDACTED_TOKEN]"],
|
|
8
|
+
[/Bearer\s+[A-Za-z0-9._-]+/gi, "Bearer [REDACTED]"],
|
|
9
|
+
[/-----BEGIN [^-]+ PRIVATE KEY-----[\s\S]*?-----END [^-]+ PRIVATE KEY-----/g, "[REDACTED_PRIVATE_KEY]"],
|
|
10
|
+
];
|
|
11
|
+
const normalizeText = (value) => {
|
|
12
|
+
let next = value;
|
|
13
|
+
for (const [pattern, replacement] of REDACTION_PATTERNS) {
|
|
14
|
+
next = next.replace(pattern, replacement);
|
|
15
|
+
}
|
|
16
|
+
return next.trim();
|
|
17
|
+
};
|
|
18
|
+
const tokenize = (value) => {
|
|
19
|
+
const matches = value.toLowerCase().match(/[a-z0-9_./-]{3,}/g);
|
|
20
|
+
return new Set(matches ?? []);
|
|
21
|
+
};
|
|
22
|
+
const scoreEntry = (queryTokens, entryText) => {
|
|
23
|
+
if (queryTokens.size === 0)
|
|
24
|
+
return 0;
|
|
25
|
+
const entryTokens = tokenize(entryText);
|
|
26
|
+
let overlap = 0;
|
|
27
|
+
for (const token of queryTokens) {
|
|
28
|
+
if (entryTokens.has(token))
|
|
29
|
+
overlap += 1;
|
|
30
|
+
}
|
|
31
|
+
return overlap / queryTokens.size;
|
|
32
|
+
};
|
|
33
|
+
const safeParseJson = (line) => {
|
|
34
|
+
try {
|
|
35
|
+
const parsed = JSON.parse(line);
|
|
36
|
+
if (!parsed || typeof parsed !== "object")
|
|
37
|
+
return undefined;
|
|
38
|
+
if (typeof parsed.intent !== "string" || typeof parsed.plan_summary !== "string")
|
|
39
|
+
return undefined;
|
|
40
|
+
return {
|
|
41
|
+
intent: parsed.intent,
|
|
42
|
+
plan_summary: parsed.plan_summary,
|
|
43
|
+
touched_files: Array.isArray(parsed.touched_files)
|
|
44
|
+
? parsed.touched_files.filter((item) => typeof item === "string")
|
|
45
|
+
: [],
|
|
46
|
+
review_notes: typeof parsed.review_notes === "string" ? parsed.review_notes : undefined,
|
|
47
|
+
qa_notes: typeof parsed.qa_notes === "string" ? parsed.qa_notes : undefined,
|
|
48
|
+
patch_summary: typeof parsed.patch_summary === "string" ? parsed.patch_summary : undefined,
|
|
49
|
+
created_at: typeof parsed.created_at === "string" && parsed.created_at.trim().length > 0
|
|
50
|
+
? parsed.created_at
|
|
51
|
+
: new Date(0).toISOString(),
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
const toPatchSummary = (entry) => {
|
|
59
|
+
const parts = [];
|
|
60
|
+
parts.push(`plan=${entry.plan_summary}`);
|
|
61
|
+
if (entry.touched_files.length > 0) {
|
|
62
|
+
parts.push(`files=${entry.touched_files.join(", ")}`);
|
|
63
|
+
}
|
|
64
|
+
if (entry.review_notes) {
|
|
65
|
+
parts.push(`review=${entry.review_notes}`);
|
|
66
|
+
}
|
|
67
|
+
if (entry.qa_notes) {
|
|
68
|
+
parts.push(`qa=${entry.qa_notes}`);
|
|
69
|
+
}
|
|
70
|
+
if (entry.patch_summary) {
|
|
71
|
+
parts.push(`patch=${entry.patch_summary}`);
|
|
72
|
+
}
|
|
73
|
+
return parts.join(" | ");
|
|
74
|
+
};
|
|
75
|
+
export class GoldenSetStore {
|
|
76
|
+
constructor(options) {
|
|
77
|
+
this.workspaceRoot = path.resolve(options.workspaceRoot);
|
|
78
|
+
this.storagePath = this.resolveStoragePath(options.storagePath ?? DEFAULT_STORAGE_PATH);
|
|
79
|
+
this.maxEntries = options.maxEntries && options.maxEntries > 0 ? Math.floor(options.maxEntries) : DEFAULT_MAX_ENTRIES;
|
|
80
|
+
}
|
|
81
|
+
resolveStoragePath(storagePath) {
|
|
82
|
+
const absolute = path.resolve(this.workspaceRoot, storagePath);
|
|
83
|
+
const relative = path.relative(this.workspaceRoot, absolute);
|
|
84
|
+
if (relative.startsWith("..") || path.isAbsolute(relative)) {
|
|
85
|
+
throw new Error("GoldenSetStore storage path must be inside workspace root");
|
|
86
|
+
}
|
|
87
|
+
return absolute;
|
|
88
|
+
}
|
|
89
|
+
sanitizeEntry(entry) {
|
|
90
|
+
return {
|
|
91
|
+
intent: normalizeText(entry.intent),
|
|
92
|
+
plan_summary: normalizeText(entry.plan_summary),
|
|
93
|
+
touched_files: entry.touched_files.map((item) => item.trim()).filter(Boolean),
|
|
94
|
+
review_notes: entry.review_notes ? normalizeText(entry.review_notes) : undefined,
|
|
95
|
+
qa_notes: entry.qa_notes ? normalizeText(entry.qa_notes) : undefined,
|
|
96
|
+
patch_summary: entry.patch_summary ? normalizeText(entry.patch_summary) : undefined,
|
|
97
|
+
created_at: entry.created_at,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
async load() {
|
|
101
|
+
try {
|
|
102
|
+
const raw = await fs.readFile(this.storagePath, "utf8");
|
|
103
|
+
const entries = raw
|
|
104
|
+
.split(/\r?\n/)
|
|
105
|
+
.map((line) => line.trim())
|
|
106
|
+
.filter(Boolean)
|
|
107
|
+
.map((line) => safeParseJson(line))
|
|
108
|
+
.filter((entry) => Boolean(entry));
|
|
109
|
+
return entries.sort((a, b) => Date.parse(a.created_at) - Date.parse(b.created_at));
|
|
110
|
+
}
|
|
111
|
+
catch (error) {
|
|
112
|
+
if (error && typeof error === "object" && "code" in error && error.code === "ENOENT") {
|
|
113
|
+
return [];
|
|
114
|
+
}
|
|
115
|
+
throw error;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
async append(entry) {
|
|
119
|
+
const nextEntry = this.sanitizeEntry({
|
|
120
|
+
...entry,
|
|
121
|
+
created_at: entry.created_at ?? new Date().toISOString(),
|
|
122
|
+
});
|
|
123
|
+
if (!nextEntry.intent || !nextEntry.plan_summary) {
|
|
124
|
+
throw new Error("GoldenSetStore entries require intent and plan_summary");
|
|
125
|
+
}
|
|
126
|
+
const existing = await this.load();
|
|
127
|
+
const all = [...existing, nextEntry];
|
|
128
|
+
const bounded = all.slice(Math.max(0, all.length - this.maxEntries));
|
|
129
|
+
await fs.mkdir(path.dirname(this.storagePath), { recursive: true });
|
|
130
|
+
const payload = bounded.map((item) => JSON.stringify(item)).join("\n");
|
|
131
|
+
await fs.writeFile(this.storagePath, payload.length > 0 ? `${payload}\n` : "", "utf8");
|
|
132
|
+
return bounded;
|
|
133
|
+
}
|
|
134
|
+
async findExamples(intent, limit = 3) {
|
|
135
|
+
const safeLimit = Math.max(1, Math.floor(limit));
|
|
136
|
+
const entries = await this.load();
|
|
137
|
+
if (entries.length === 0)
|
|
138
|
+
return [];
|
|
139
|
+
const queryTokens = tokenize(intent);
|
|
140
|
+
return entries
|
|
141
|
+
.map((entry) => {
|
|
142
|
+
const text = `${entry.intent}\n${entry.plan_summary}\n${entry.touched_files.join(" ")}\n${entry.review_notes ?? ""}\n${entry.qa_notes ?? ""}`;
|
|
143
|
+
const score = scoreEntry(queryTokens, text);
|
|
144
|
+
return {
|
|
145
|
+
intent: entry.intent,
|
|
146
|
+
patch: toPatchSummary(entry),
|
|
147
|
+
score,
|
|
148
|
+
createdAt: Date.parse(entry.created_at),
|
|
149
|
+
};
|
|
150
|
+
})
|
|
151
|
+
.sort((a, b) => {
|
|
152
|
+
if (b.score !== a.score)
|
|
153
|
+
return b.score - a.score;
|
|
154
|
+
return b.createdAt - a.createdAt;
|
|
155
|
+
})
|
|
156
|
+
.slice(0, safeLimit)
|
|
157
|
+
.map((entry) => ({ intent: entry.intent, patch: entry.patch, score: entry.score }));
|
|
158
|
+
}
|
|
159
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type IntentBucket = "ui" | "content" | "behavior" | "data" | "testing" | "infra" | "security" | "performance" | "observability";
|
|
2
|
+
export interface IntentSignals {
|
|
3
|
+
intents: IntentBucket[];
|
|
4
|
+
matches: Record<IntentBucket, string[]>;
|
|
5
|
+
}
|
|
6
|
+
export declare const deriveIntentSignals: (request: string) => IntentSignals;
|
|
7
|
+
//# sourceMappingURL=IntentSignals.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IntentSignals.d.ts","sourceRoot":"","sources":["../../src/cognitive/IntentSignals.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GACpB,IAAI,GACJ,SAAS,GACT,UAAU,GACV,MAAM,GACN,SAAS,GACT,OAAO,GACP,UAAU,GACV,aAAa,GACb,eAAe,CAAC;AAEpB,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,YAAY,EAAE,CAAC;IACxB,OAAO,EAAE,MAAM,CAAC,YAAY,EAAE,MAAM,EAAE,CAAC,CAAC;CACzC;AAsPD,eAAO,MAAM,mBAAmB,GAAI,SAAS,MAAM,KAAG,aAkDrD,CAAC"}
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
const UI_KEYWORDS = [
|
|
2
|
+
"ui",
|
|
3
|
+
"ux",
|
|
4
|
+
"page",
|
|
5
|
+
"screen",
|
|
6
|
+
"layout",
|
|
7
|
+
"header",
|
|
8
|
+
"hero",
|
|
9
|
+
"navbar",
|
|
10
|
+
"footer",
|
|
11
|
+
"landing",
|
|
12
|
+
"welcome",
|
|
13
|
+
"title",
|
|
14
|
+
"button",
|
|
15
|
+
"style",
|
|
16
|
+
"css",
|
|
17
|
+
"html",
|
|
18
|
+
"markup",
|
|
19
|
+
"template",
|
|
20
|
+
"component",
|
|
21
|
+
"view",
|
|
22
|
+
];
|
|
23
|
+
const CONTENT_KEYWORDS = [
|
|
24
|
+
"copy",
|
|
25
|
+
"text",
|
|
26
|
+
"label",
|
|
27
|
+
"wording",
|
|
28
|
+
"message",
|
|
29
|
+
"string",
|
|
30
|
+
"content",
|
|
31
|
+
];
|
|
32
|
+
const BEHAVIOR_KEYWORDS = [
|
|
33
|
+
"logic",
|
|
34
|
+
"behavior",
|
|
35
|
+
"bug",
|
|
36
|
+
"fix",
|
|
37
|
+
"error",
|
|
38
|
+
"crash",
|
|
39
|
+
"api",
|
|
40
|
+
"backend",
|
|
41
|
+
"server",
|
|
42
|
+
"endpoint",
|
|
43
|
+
"route",
|
|
44
|
+
"router",
|
|
45
|
+
"handler",
|
|
46
|
+
"healthz",
|
|
47
|
+
"health",
|
|
48
|
+
"logging",
|
|
49
|
+
"logger",
|
|
50
|
+
"uptime",
|
|
51
|
+
"flow",
|
|
52
|
+
"auth",
|
|
53
|
+
"estimate",
|
|
54
|
+
"estimation",
|
|
55
|
+
"stats",
|
|
56
|
+
"stat",
|
|
57
|
+
"completion",
|
|
58
|
+
"completions",
|
|
59
|
+
"calculate",
|
|
60
|
+
"computed",
|
|
61
|
+
"compute",
|
|
62
|
+
"count",
|
|
63
|
+
"aggregate",
|
|
64
|
+
"summary",
|
|
65
|
+
];
|
|
66
|
+
const DATA_KEYWORDS = [
|
|
67
|
+
"schema",
|
|
68
|
+
"database",
|
|
69
|
+
"db",
|
|
70
|
+
"model",
|
|
71
|
+
"migration",
|
|
72
|
+
"table",
|
|
73
|
+
"field",
|
|
74
|
+
"column",
|
|
75
|
+
"sql",
|
|
76
|
+
];
|
|
77
|
+
const TESTING_KEYWORDS = [
|
|
78
|
+
"test",
|
|
79
|
+
"tests",
|
|
80
|
+
"testing",
|
|
81
|
+
"unit",
|
|
82
|
+
"integration",
|
|
83
|
+
"e2e",
|
|
84
|
+
"spec",
|
|
85
|
+
"specs",
|
|
86
|
+
"snapshot",
|
|
87
|
+
"snapshots",
|
|
88
|
+
"golden",
|
|
89
|
+
"approval",
|
|
90
|
+
"assertion",
|
|
91
|
+
"assertions",
|
|
92
|
+
"jest",
|
|
93
|
+
"vitest",
|
|
94
|
+
"mocha",
|
|
95
|
+
"pytest",
|
|
96
|
+
"rspec",
|
|
97
|
+
"junit",
|
|
98
|
+
"xunit",
|
|
99
|
+
"cypress",
|
|
100
|
+
"playwright",
|
|
101
|
+
"fixture",
|
|
102
|
+
"fixtures",
|
|
103
|
+
"mock",
|
|
104
|
+
"mocking",
|
|
105
|
+
"coverage",
|
|
106
|
+
];
|
|
107
|
+
const INFRA_BASE_KEYWORDS = [
|
|
108
|
+
"infra",
|
|
109
|
+
"infrastructure",
|
|
110
|
+
"ops",
|
|
111
|
+
"devops",
|
|
112
|
+
"ci",
|
|
113
|
+
"cd",
|
|
114
|
+
"pipeline",
|
|
115
|
+
"deploy",
|
|
116
|
+
"deployment",
|
|
117
|
+
"docker",
|
|
118
|
+
"compose",
|
|
119
|
+
"k8s",
|
|
120
|
+
"kubernetes",
|
|
121
|
+
"helm",
|
|
122
|
+
"terraform",
|
|
123
|
+
"ansible",
|
|
124
|
+
"makefile",
|
|
125
|
+
"workflow",
|
|
126
|
+
"runner",
|
|
127
|
+
"github actions",
|
|
128
|
+
"gitlab",
|
|
129
|
+
"gitlab ci",
|
|
130
|
+
"circleci",
|
|
131
|
+
"artifact",
|
|
132
|
+
"registry",
|
|
133
|
+
];
|
|
134
|
+
const INFRA_CONDITIONAL_KEYWORDS = ["build", "release", "package"];
|
|
135
|
+
const SECURITY_KEYWORDS = [
|
|
136
|
+
"security",
|
|
137
|
+
"secure",
|
|
138
|
+
"auth",
|
|
139
|
+
"authentication",
|
|
140
|
+
"authorization",
|
|
141
|
+
"permission",
|
|
142
|
+
"permissions",
|
|
143
|
+
"rbac",
|
|
144
|
+
"acl",
|
|
145
|
+
"policy",
|
|
146
|
+
"jwt",
|
|
147
|
+
"oauth",
|
|
148
|
+
"sso",
|
|
149
|
+
"csrf",
|
|
150
|
+
"xss",
|
|
151
|
+
"samesite",
|
|
152
|
+
"csp",
|
|
153
|
+
"encrypt",
|
|
154
|
+
"encryption",
|
|
155
|
+
"crypto",
|
|
156
|
+
"secret",
|
|
157
|
+
"secrets",
|
|
158
|
+
"vault",
|
|
159
|
+
"audit",
|
|
160
|
+
"vulnerability",
|
|
161
|
+
"sanitize",
|
|
162
|
+
];
|
|
163
|
+
const PERFORMANCE_KEYWORDS = [
|
|
164
|
+
"performance",
|
|
165
|
+
"perf",
|
|
166
|
+
"slow",
|
|
167
|
+
"slowdown",
|
|
168
|
+
"latency",
|
|
169
|
+
"throughput",
|
|
170
|
+
"optimize",
|
|
171
|
+
"optimization",
|
|
172
|
+
"cache",
|
|
173
|
+
"caching",
|
|
174
|
+
"cache miss",
|
|
175
|
+
"memo",
|
|
176
|
+
"benchmark",
|
|
177
|
+
"profiling",
|
|
178
|
+
"profile",
|
|
179
|
+
"hot path",
|
|
180
|
+
"n+1",
|
|
181
|
+
"memory",
|
|
182
|
+
"cpu",
|
|
183
|
+
"throttle",
|
|
184
|
+
"rate limit",
|
|
185
|
+
"rate-limit",
|
|
186
|
+
"batch",
|
|
187
|
+
"queue",
|
|
188
|
+
"timeout",
|
|
189
|
+
];
|
|
190
|
+
const OBSERVABILITY_KEYWORDS = [
|
|
191
|
+
"observability",
|
|
192
|
+
"telemetry",
|
|
193
|
+
"instrument",
|
|
194
|
+
"instrumentation",
|
|
195
|
+
"logging",
|
|
196
|
+
"log",
|
|
197
|
+
"logger",
|
|
198
|
+
"log level",
|
|
199
|
+
"structured logging",
|
|
200
|
+
"metrics",
|
|
201
|
+
"monitor",
|
|
202
|
+
"monitoring",
|
|
203
|
+
"trace",
|
|
204
|
+
"tracing",
|
|
205
|
+
"trace id",
|
|
206
|
+
"span",
|
|
207
|
+
"otel",
|
|
208
|
+
"opentelemetry",
|
|
209
|
+
"sentry",
|
|
210
|
+
"datadog",
|
|
211
|
+
"prometheus",
|
|
212
|
+
"grafana",
|
|
213
|
+
"alert",
|
|
214
|
+
"alerts",
|
|
215
|
+
];
|
|
216
|
+
const OBSERVABILITY_LOGGING_ONLY = new Set([
|
|
217
|
+
"logging",
|
|
218
|
+
"log",
|
|
219
|
+
"logger",
|
|
220
|
+
"log level",
|
|
221
|
+
"structured logging",
|
|
222
|
+
]);
|
|
223
|
+
const normalize = (value) => value.toLowerCase().replace(/[^a-z0-9\\s]/g, " ");
|
|
224
|
+
const collectMatches = (text, keywords) => {
|
|
225
|
+
const matches = [];
|
|
226
|
+
for (const keyword of keywords) {
|
|
227
|
+
if (text.includes(keyword))
|
|
228
|
+
matches.push(keyword);
|
|
229
|
+
}
|
|
230
|
+
return matches;
|
|
231
|
+
};
|
|
232
|
+
export const deriveIntentSignals = (request) => {
|
|
233
|
+
const normalized = normalize(request ?? "");
|
|
234
|
+
const uiMatches = collectMatches(normalized, UI_KEYWORDS);
|
|
235
|
+
const contentMatches = collectMatches(normalized, CONTENT_KEYWORDS);
|
|
236
|
+
const behaviorMatches = collectMatches(normalized, BEHAVIOR_KEYWORDS);
|
|
237
|
+
const dataMatches = collectMatches(normalized, DATA_KEYWORDS);
|
|
238
|
+
const testingMatches = collectMatches(normalized, TESTING_KEYWORDS);
|
|
239
|
+
const infraBaseMatches = collectMatches(normalized, INFRA_BASE_KEYWORDS);
|
|
240
|
+
const infraConditionalMatches = collectMatches(normalized, INFRA_CONDITIONAL_KEYWORDS);
|
|
241
|
+
const infraMatches = infraBaseMatches.length > 0
|
|
242
|
+
? [...infraBaseMatches, ...infraConditionalMatches]
|
|
243
|
+
: infraBaseMatches;
|
|
244
|
+
const securityMatches = collectMatches(normalized, SECURITY_KEYWORDS);
|
|
245
|
+
const performanceMatches = collectMatches(normalized, PERFORMANCE_KEYWORDS);
|
|
246
|
+
const observabilityMatches = collectMatches(normalized, OBSERVABILITY_KEYWORDS);
|
|
247
|
+
const observabilityHasSignal = observabilityMatches.some((match) => !OBSERVABILITY_LOGGING_ONLY.has(match));
|
|
248
|
+
const observabilityFinal = observabilityHasSignal ? observabilityMatches : [];
|
|
249
|
+
const intents = [];
|
|
250
|
+
if (uiMatches.length)
|
|
251
|
+
intents.push("ui");
|
|
252
|
+
if (contentMatches.length)
|
|
253
|
+
intents.push("content");
|
|
254
|
+
if (behaviorMatches.length)
|
|
255
|
+
intents.push("behavior");
|
|
256
|
+
if (dataMatches.length)
|
|
257
|
+
intents.push("data");
|
|
258
|
+
if (testingMatches.length)
|
|
259
|
+
intents.push("testing");
|
|
260
|
+
if (infraMatches.length)
|
|
261
|
+
intents.push("infra");
|
|
262
|
+
if (securityMatches.length)
|
|
263
|
+
intents.push("security");
|
|
264
|
+
if (performanceMatches.length)
|
|
265
|
+
intents.push("performance");
|
|
266
|
+
if (observabilityFinal.length)
|
|
267
|
+
intents.push("observability");
|
|
268
|
+
if (intents.length === 0) {
|
|
269
|
+
intents.push("behavior");
|
|
270
|
+
}
|
|
271
|
+
return {
|
|
272
|
+
intents,
|
|
273
|
+
matches: {
|
|
274
|
+
ui: uiMatches,
|
|
275
|
+
content: contentMatches,
|
|
276
|
+
behavior: behaviorMatches,
|
|
277
|
+
data: dataMatches,
|
|
278
|
+
testing: testingMatches,
|
|
279
|
+
infra: infraMatches,
|
|
280
|
+
security: securityMatches,
|
|
281
|
+
performance: performanceMatches,
|
|
282
|
+
observability: observabilityFinal,
|
|
283
|
+
},
|
|
284
|
+
};
|
|
285
|
+
};
|