@mcoda/mswarm 0.1.57 → 0.1.61
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 +19 -0
- package/dist/codali-executor.d.ts +278 -0
- package/dist/codali-executor.d.ts.map +1 -0
- package/dist/codali-executor.js +243 -0
- package/dist/codali-executor.js.map +1 -0
- package/dist/runtime.d.ts +46 -1
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +298 -30
- package/dist/runtime.js.map +1 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +66 -1
- 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 +158 -0
- package/dist/vendor/codali/docdex/DocdexClient.d.ts.map +1 -0
- package/dist/vendor/codali/docdex/DocdexClient.js +785 -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 +189 -0
- package/dist/vendor/codali/runtime/CodaliRuntime.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/CodaliRuntime.js +1435 -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 +293 -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 +40 -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 +490 -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,882 @@
|
|
|
1
|
+
const estimateTokens = (content) => Math.max(1, Math.ceil(content.length / 4));
|
|
2
|
+
const SECTION_LIMITS = {
|
|
3
|
+
maxSnippetEntries: 6,
|
|
4
|
+
maxSnippetChars: 1600,
|
|
5
|
+
maxSymbolEntries: 6,
|
|
6
|
+
maxSymbolChars: 1800,
|
|
7
|
+
maxAstEntries: 4,
|
|
8
|
+
maxAstNodes: 40,
|
|
9
|
+
maxAstChars: 2200,
|
|
10
|
+
maxMemoryEntries: 6,
|
|
11
|
+
maxMemoryChars: 320,
|
|
12
|
+
maxProfileEntries: 6,
|
|
13
|
+
maxProfileChars: 240,
|
|
14
|
+
maxResearchItems: 6,
|
|
15
|
+
maxResearchChars: 200,
|
|
16
|
+
};
|
|
17
|
+
const WARNING_GLOSSARY = {
|
|
18
|
+
context_budget_pruned: {
|
|
19
|
+
severity: "warn",
|
|
20
|
+
message: "Some selected files were dropped to satisfy the context budget.",
|
|
21
|
+
},
|
|
22
|
+
context_budget_trimmed: {
|
|
23
|
+
severity: "info",
|
|
24
|
+
message: "Some file content was trimmed in the internal context load.",
|
|
25
|
+
},
|
|
26
|
+
docdex_files_failed: {
|
|
27
|
+
severity: "warn",
|
|
28
|
+
message: "Docdex file listing failed; file hints may be incomplete.",
|
|
29
|
+
},
|
|
30
|
+
docdex_index_empty: {
|
|
31
|
+
severity: "warn",
|
|
32
|
+
message: "Docdex index is empty; search results may be incomplete.",
|
|
33
|
+
},
|
|
34
|
+
docdex_index_stale: {
|
|
35
|
+
severity: "warn",
|
|
36
|
+
message: "Docdex index looks stale; search results may be incomplete.",
|
|
37
|
+
},
|
|
38
|
+
docdex_low_confidence: {
|
|
39
|
+
severity: "info",
|
|
40
|
+
message: "Low-confidence selection; treat context as exploratory.",
|
|
41
|
+
},
|
|
42
|
+
docdex_no_hits: {
|
|
43
|
+
severity: "info",
|
|
44
|
+
message: "Search returned no hits; selection may rely on heuristics.",
|
|
45
|
+
},
|
|
46
|
+
docdex_stats_failed: {
|
|
47
|
+
severity: "warn",
|
|
48
|
+
message: "Docdex stats failed; index status may be unknown.",
|
|
49
|
+
},
|
|
50
|
+
docdex_batch_search_failed: {
|
|
51
|
+
severity: "warn",
|
|
52
|
+
message: "Docdex batch search failed; sequential fallback was used.",
|
|
53
|
+
},
|
|
54
|
+
docdex_rerank_failed: {
|
|
55
|
+
severity: "warn",
|
|
56
|
+
message: "Docdex rerank failed; baseline ranking was used.",
|
|
57
|
+
},
|
|
58
|
+
docdex_batch_search_applied: {
|
|
59
|
+
severity: "info",
|
|
60
|
+
message: "Docdex batch search path was applied.",
|
|
61
|
+
},
|
|
62
|
+
docdex_rerank_applied: {
|
|
63
|
+
severity: "info",
|
|
64
|
+
message: "Docdex rerank path was applied.",
|
|
65
|
+
},
|
|
66
|
+
docdex_tree_failed: {
|
|
67
|
+
severity: "warn",
|
|
68
|
+
message: "Repo tree could not be retrieved; repo map may be missing.",
|
|
69
|
+
},
|
|
70
|
+
docdex_symbols_not_applicable: {
|
|
71
|
+
severity: "info",
|
|
72
|
+
message: "Symbols are not applicable for this file type.",
|
|
73
|
+
},
|
|
74
|
+
docdex_ast_not_applicable: {
|
|
75
|
+
severity: "info",
|
|
76
|
+
message: "AST analysis is not applicable for this file type.",
|
|
77
|
+
},
|
|
78
|
+
impact_graph_sparse: {
|
|
79
|
+
severity: "info",
|
|
80
|
+
message: "Impact graph is sparse; dependency info may be incomplete.",
|
|
81
|
+
},
|
|
82
|
+
librarian_companion_candidates: {
|
|
83
|
+
severity: "info",
|
|
84
|
+
message: "Companion files were added based on proximity or hints.",
|
|
85
|
+
},
|
|
86
|
+
memory_conflicts_pruned: {
|
|
87
|
+
severity: "info",
|
|
88
|
+
message: "Conflicting memory entries were pruned.",
|
|
89
|
+
},
|
|
90
|
+
memory_irrelevant_filtered: {
|
|
91
|
+
severity: "info",
|
|
92
|
+
message: "Irrelevant memory entries were filtered out.",
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
const truncateText = (value, maxChars) => {
|
|
96
|
+
if (maxChars <= 0 || value.length <= maxChars)
|
|
97
|
+
return value;
|
|
98
|
+
const marker = "\n/* ...truncated... */\n";
|
|
99
|
+
if (maxChars <= marker.length)
|
|
100
|
+
return value.slice(0, maxChars);
|
|
101
|
+
return `${value.slice(0, maxChars - marker.length)}${marker}`;
|
|
102
|
+
};
|
|
103
|
+
const truncateSummary = (value, maxChars) => {
|
|
104
|
+
if (maxChars <= 0 || value.length <= maxChars)
|
|
105
|
+
return value;
|
|
106
|
+
if (maxChars <= 3)
|
|
107
|
+
return value.slice(0, maxChars);
|
|
108
|
+
return `${value.slice(0, maxChars - 3)}...`;
|
|
109
|
+
};
|
|
110
|
+
const splitWarning = (warning) => {
|
|
111
|
+
const separator = warning.indexOf(":");
|
|
112
|
+
if (separator === -1)
|
|
113
|
+
return { code: warning };
|
|
114
|
+
return { code: warning.slice(0, separator), detail: warning.slice(separator + 1) };
|
|
115
|
+
};
|
|
116
|
+
const formatFileHeader = (file) => {
|
|
117
|
+
const role = file.role === "focus" ? "FOCUS FILE" : "PERIPHERY FILE";
|
|
118
|
+
const metadata = [`slice=${file.sliceStrategy}`, `origin=${file.origin}`];
|
|
119
|
+
if (file.truncated)
|
|
120
|
+
metadata.push("truncated");
|
|
121
|
+
if (file.warnings?.length)
|
|
122
|
+
metadata.push(`warnings=${file.warnings.join("|")}`);
|
|
123
|
+
return `=== [${role}] ${file.path} (${metadata.join(", ")}) ===`;
|
|
124
|
+
};
|
|
125
|
+
const listOrNone = (values = []) => values.length ? values.join(", ") : "none";
|
|
126
|
+
const uniqueValues = (values) => Array.from(new Set(values));
|
|
127
|
+
const formatSummaryList = (values) => {
|
|
128
|
+
if (!values || values.length === 0)
|
|
129
|
+
return "none";
|
|
130
|
+
const trimmed = values
|
|
131
|
+
.filter((entry) => entry.trim().length > 0)
|
|
132
|
+
.slice(0, SECTION_LIMITS.maxResearchItems)
|
|
133
|
+
.map((entry) => truncateSummary(entry, SECTION_LIMITS.maxResearchChars));
|
|
134
|
+
const remaining = values.length - trimmed.length;
|
|
135
|
+
if (remaining > 0) {
|
|
136
|
+
return `${trimmed.join(" | ")} (+${remaining} more)`;
|
|
137
|
+
}
|
|
138
|
+
return trimmed.join(" | ");
|
|
139
|
+
};
|
|
140
|
+
const isTestPath = (value) => {
|
|
141
|
+
const normalized = value.replace(/\\/g, "/").toLowerCase();
|
|
142
|
+
return (normalized.includes("/__tests__/") ||
|
|
143
|
+
normalized.includes("/tests/") ||
|
|
144
|
+
normalized.includes(".test.") ||
|
|
145
|
+
normalized.endsWith(".spec.ts") ||
|
|
146
|
+
normalized.endsWith(".spec.js"));
|
|
147
|
+
};
|
|
148
|
+
const isDocPath = (value) => {
|
|
149
|
+
const normalized = value.replace(/\\/g, "/").toLowerCase();
|
|
150
|
+
if (normalized.startsWith("docs/"))
|
|
151
|
+
return true;
|
|
152
|
+
return normalized.endsWith(".md") || normalized.endsWith(".mdx") || normalized.endsWith(".rst");
|
|
153
|
+
};
|
|
154
|
+
const formatProjectSummary = (bundle) => {
|
|
155
|
+
const lines = [];
|
|
156
|
+
const info = bundle.project_info;
|
|
157
|
+
const summary = info?.readme_summary?.trim();
|
|
158
|
+
const readmePath = info?.readme_path;
|
|
159
|
+
lines.push("PROJECT SUMMARY (README):");
|
|
160
|
+
if (readmePath)
|
|
161
|
+
lines.push(`- Source: ${readmePath}`);
|
|
162
|
+
if (summary) {
|
|
163
|
+
lines.push(summary);
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
lines.push("Summary unavailable (README not found or empty).");
|
|
167
|
+
}
|
|
168
|
+
lines.push("");
|
|
169
|
+
return lines;
|
|
170
|
+
};
|
|
171
|
+
const formatRunSummary = (bundle) => {
|
|
172
|
+
const lines = [];
|
|
173
|
+
const request = bundle.request?.trim() || "unknown";
|
|
174
|
+
const intentBuckets = bundle.intent?.intents?.join(", ") || "unknown";
|
|
175
|
+
const digest = bundle.request_digest;
|
|
176
|
+
const digestSummary = digest?.summary ?? "not available";
|
|
177
|
+
const digestConfidence = digest?.confidence ?? "unknown";
|
|
178
|
+
const project = bundle.project_info;
|
|
179
|
+
const workspaceRoot = project?.workspace_root ?? "unknown";
|
|
180
|
+
const docs = listOrNone(project?.docs ?? []);
|
|
181
|
+
const manifests = listOrNone(project?.manifests ?? []);
|
|
182
|
+
const fileTypes = listOrNone(project?.file_types ?? []);
|
|
183
|
+
lines.push("RUN SUMMARY:");
|
|
184
|
+
lines.push(`- Repo root: ${workspaceRoot}`);
|
|
185
|
+
lines.push(`- Request (verbatim): ${request}`);
|
|
186
|
+
lines.push(`- Intent buckets: ${intentBuckets}`);
|
|
187
|
+
lines.push(`- Inferred outcome (${digestConfidence}): ${digestSummary}`);
|
|
188
|
+
lines.push(`- Repo docs (purpose hints): ${docs}`);
|
|
189
|
+
lines.push(`- Manifests: ${manifests}`);
|
|
190
|
+
lines.push(`- File types: ${fileTypes}`);
|
|
191
|
+
lines.push("");
|
|
192
|
+
return lines;
|
|
193
|
+
};
|
|
194
|
+
const formatResearchSummary = (bundle) => {
|
|
195
|
+
const research = bundle.research;
|
|
196
|
+
if (!research)
|
|
197
|
+
return [];
|
|
198
|
+
const lines = [];
|
|
199
|
+
const duration = typeof research.duration_ms === "number" ? ` (${research.duration_ms}ms)` : "";
|
|
200
|
+
lines.push("RESEARCH SUMMARY:");
|
|
201
|
+
lines.push(`- Status: ${research.status}${duration}`);
|
|
202
|
+
if (research.tool_usage) {
|
|
203
|
+
lines.push(`- Tool usage: search=${research.tool_usage.search}, open/snippet=${research.tool_usage.open_or_snippet}, symbols/ast=${research.tool_usage.symbols_or_ast}, impact=${research.tool_usage.impact}, tree=${research.tool_usage.tree}, dag_export=${research.tool_usage.dag_export}`);
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
lines.push("- Tool usage: unknown");
|
|
207
|
+
}
|
|
208
|
+
if (research.evidence) {
|
|
209
|
+
lines.push(`- Evidence: search_hits=${research.evidence.search_hits}, snippet_count=${research.evidence.snippet_count}, symbol_files=${research.evidence.symbol_files}, ast_files=${research.evidence.ast_files}, impact_files=${research.evidence.impact_files}, impact_edges=${research.evidence.impact_edges}, repo_map=${research.evidence.repo_map ? "yes" : "no"}, dag_summary=${research.evidence.dag_summary ? "yes" : "no"}`);
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
lines.push("- Evidence: unknown");
|
|
213
|
+
}
|
|
214
|
+
const keyFindings = research.key_findings;
|
|
215
|
+
lines.push(`- Key findings: ${formatSummaryList(keyFindings)}`);
|
|
216
|
+
lines.push(`- Notes: ${formatSummaryList(research.notes)}`);
|
|
217
|
+
const gaps = research.evidence?.gaps;
|
|
218
|
+
lines.push(`- Unresolved gaps: ${formatSummaryList(gaps)}`);
|
|
219
|
+
const warnings = [
|
|
220
|
+
...(research.warnings ?? []),
|
|
221
|
+
...(research.evidence?.warnings ?? []),
|
|
222
|
+
];
|
|
223
|
+
lines.push(`- Warnings: ${formatSummaryList(warnings)}`);
|
|
224
|
+
lines.push("");
|
|
225
|
+
return lines;
|
|
226
|
+
};
|
|
227
|
+
const formatRetrievalReport = (bundle) => {
|
|
228
|
+
const report = bundle.retrieval_report;
|
|
229
|
+
if (!report)
|
|
230
|
+
return [];
|
|
231
|
+
const lines = [];
|
|
232
|
+
lines.push("RETRIEVAL REPORT:");
|
|
233
|
+
lines.push(`- Schema: v${report.schema_version}, mode=${report.mode}, confidence=${report.confidence}, disposition=${report.disposition}`);
|
|
234
|
+
if (report.preflight.length > 0) {
|
|
235
|
+
const preflight = report.preflight
|
|
236
|
+
.map((entry) => `${entry.check}=${entry.status}${entry.detail ? `(${truncateSummary(entry.detail, 80)})` : ""}`)
|
|
237
|
+
.join(", ");
|
|
238
|
+
lines.push(`- Preflight: ${preflight}`);
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
lines.push("- Preflight: none");
|
|
242
|
+
}
|
|
243
|
+
lines.push(`- Selection: focus=${report.selection.focus.length}, periphery=${report.selection.periphery.length}, total=${report.selection.all.length}, low_confidence=${report.selection.low_confidence ? "yes" : "no"}`);
|
|
244
|
+
if (report.selection.reason_summary.length > 0) {
|
|
245
|
+
const reasonSummary = report.selection.reason_summary
|
|
246
|
+
.map((entry) => `${entry.code}=${entry.count}`)
|
|
247
|
+
.join(", ");
|
|
248
|
+
lines.push(`- Reason summary: ${reasonSummary}`);
|
|
249
|
+
}
|
|
250
|
+
else {
|
|
251
|
+
lines.push("- Reason summary: none");
|
|
252
|
+
}
|
|
253
|
+
if (report.dropped.length > 0) {
|
|
254
|
+
const dropped = report.dropped
|
|
255
|
+
.slice(0, SECTION_LIMITS.maxResearchItems)
|
|
256
|
+
.map((entry) => `${entry.path ?? "<none>"}:${entry.reason_code}${entry.detail ? `(${truncateSummary(entry.detail, 80)})` : ""}`);
|
|
257
|
+
const remaining = report.dropped.length - dropped.length;
|
|
258
|
+
lines.push(`- Dropped: ${dropped.join(" | ")}${remaining > 0 ? ` (+${remaining} more)` : ""}`);
|
|
259
|
+
}
|
|
260
|
+
else {
|
|
261
|
+
lines.push("- Dropped: none");
|
|
262
|
+
}
|
|
263
|
+
if (report.truncated.length > 0) {
|
|
264
|
+
const truncated = report.truncated
|
|
265
|
+
.slice(0, SECTION_LIMITS.maxResearchItems)
|
|
266
|
+
.map((entry) => `${entry.path}:${entry.reason_code}${entry.detail ? `(${truncateSummary(entry.detail, 80)})` : ""}`);
|
|
267
|
+
const remaining = report.truncated.length - truncated.length;
|
|
268
|
+
lines.push(`- Truncated: ${truncated.join(" | ")}${remaining > 0 ? ` (+${remaining} more)` : ""}`);
|
|
269
|
+
}
|
|
270
|
+
else {
|
|
271
|
+
lines.push("- Truncated: none");
|
|
272
|
+
}
|
|
273
|
+
lines.push(`- Unresolved gaps: ${formatSummaryList(report.unresolved_gaps)}`);
|
|
274
|
+
if (report.tool_execution.length > 0) {
|
|
275
|
+
const toolSummary = report.tool_execution
|
|
276
|
+
.map((entry) => `${entry.tool}=${entry.disposition}${entry.notes ? `(${truncateSummary(entry.notes, 80)})` : ""}`)
|
|
277
|
+
.join(" | ");
|
|
278
|
+
lines.push(`- Tool execution: ${toolSummary}`);
|
|
279
|
+
}
|
|
280
|
+
else {
|
|
281
|
+
lines.push("- Tool execution: none");
|
|
282
|
+
}
|
|
283
|
+
if (report.capabilities) {
|
|
284
|
+
const capabilitySummary = Object.entries(report.capabilities.capabilities)
|
|
285
|
+
.map(([name, status]) => `${name}=${status}`)
|
|
286
|
+
.join(", ");
|
|
287
|
+
lines.push(`- Capabilities: source=${report.capabilities.source}, cached=${report.capabilities.cached ? "yes" : "no"}, ${capabilitySummary}`);
|
|
288
|
+
}
|
|
289
|
+
else {
|
|
290
|
+
lines.push("- Capabilities: unavailable");
|
|
291
|
+
}
|
|
292
|
+
lines.push(`- Warnings: ${formatSummaryList(report.warnings)}`);
|
|
293
|
+
lines.push("");
|
|
294
|
+
return lines;
|
|
295
|
+
};
|
|
296
|
+
const formatDeliverables = (bundle) => {
|
|
297
|
+
const lines = [];
|
|
298
|
+
const request = bundle.request?.trim() || "unknown";
|
|
299
|
+
const digest = bundle.request_digest;
|
|
300
|
+
const digestSummary = digest?.summary ?? "not available";
|
|
301
|
+
const digestConfidence = digest?.confidence ?? "unknown";
|
|
302
|
+
lines.push("WHAT TO DELIVER:");
|
|
303
|
+
lines.push(`- Must satisfy request exactly: ${request}`);
|
|
304
|
+
lines.push(`- Inferred deliverables (${digestConfidence}): ${digestSummary}`);
|
|
305
|
+
lines.push("");
|
|
306
|
+
return lines;
|
|
307
|
+
};
|
|
308
|
+
const formatAgentProtocol = () => {
|
|
309
|
+
const lines = [];
|
|
310
|
+
lines.push("AGENT PROTOCOL (REQUEST MORE CONTEXT):");
|
|
311
|
+
lines.push("- This bundle lists file paths only; request file contents, symbols, AST, impact, or DAG when needed.");
|
|
312
|
+
lines.push("- Use AGENT_REQUEST v1 with one or more needs. Supported needs:");
|
|
313
|
+
lines.push("- docdex.search, docdex.open, docdex.snippet, docdex.symbols, docdex.ast, docdex.impact, docdex.impact_diagnostics, docdex.tree, docdex.dag_export, docdex.web");
|
|
314
|
+
lines.push("- file.read, file.list, file.diff");
|
|
315
|
+
lines.push("- Protocol reference: docs/codali-agent-protocol.md (request via file.read).");
|
|
316
|
+
lines.push("- Docdex tool list: ~/.docdex/agents.md (request via file.read).");
|
|
317
|
+
lines.push("Example AGENT_REQUEST:");
|
|
318
|
+
lines.push("AGENT_REQUEST v1");
|
|
319
|
+
lines.push("role: architect");
|
|
320
|
+
lines.push("request_id: <uuid>");
|
|
321
|
+
lines.push("needs:");
|
|
322
|
+
lines.push(" - type: docdex.search");
|
|
323
|
+
lines.push(' query: "..."');
|
|
324
|
+
lines.push(" limit: 5");
|
|
325
|
+
lines.push(" - type: docdex.open");
|
|
326
|
+
lines.push(' path: "src/..."');
|
|
327
|
+
lines.push(" start_line: 1");
|
|
328
|
+
lines.push(" end_line: 200");
|
|
329
|
+
lines.push("context:");
|
|
330
|
+
lines.push(' summary: "Need file content to finalize plan"');
|
|
331
|
+
lines.push("");
|
|
332
|
+
return lines;
|
|
333
|
+
};
|
|
334
|
+
const formatContextCoverage = (bundle, options) => {
|
|
335
|
+
const lines = [];
|
|
336
|
+
const files = bundle.files ?? [];
|
|
337
|
+
const focusContent = files.filter((file) => file.role === "focus").map((file) => file.path);
|
|
338
|
+
const peripheryContent = files
|
|
339
|
+
.filter((file) => file.role === "periphery")
|
|
340
|
+
.map((file) => file.path);
|
|
341
|
+
const selection = bundle.selection;
|
|
342
|
+
const focusSelected = selection?.focus ?? [];
|
|
343
|
+
const peripherySelected = selection?.periphery ?? [];
|
|
344
|
+
const missing = bundle.missing?.length ? bundle.missing.join(", ") : "none";
|
|
345
|
+
const warningSummary = bundle.warnings?.length
|
|
346
|
+
? `${bundle.warnings.length} warnings (see WARNINGS section)`
|
|
347
|
+
: "none";
|
|
348
|
+
const formatValue = (value) => typeof value === "number" && value >= 0 ? String(value) : "unknown";
|
|
349
|
+
const indexInfo = bundle.index;
|
|
350
|
+
const indexSummary = `docs_indexed=${formatValue(indexInfo?.num_docs)}, last_updated=${formatValue(indexInfo?.last_updated_epoch_ms)}`;
|
|
351
|
+
lines.push("CONTEXT COVERAGE:");
|
|
352
|
+
lines.push(`- Focus files (selected): ${listOrNone(focusSelected)}`);
|
|
353
|
+
lines.push(`- Periphery files (selected): ${listOrNone(peripherySelected)}`);
|
|
354
|
+
if (options.includeContents) {
|
|
355
|
+
lines.push(`- Full content included (focus): ${listOrNone(focusContent)}`);
|
|
356
|
+
lines.push(`- Content included (periphery): ${listOrNone(peripheryContent)}`);
|
|
357
|
+
}
|
|
358
|
+
else {
|
|
359
|
+
lines.push(`- File references included (focus): ${listOrNone(focusContent)}`);
|
|
360
|
+
lines.push(`- File references included (periphery): ${listOrNone(peripheryContent)}`);
|
|
361
|
+
lines.push("- File contents are withheld by default; request via AGENT_REQUEST if needed.");
|
|
362
|
+
}
|
|
363
|
+
lines.push(`- Index status: ${indexSummary}`);
|
|
364
|
+
lines.push(`- Missing data: ${missing}`);
|
|
365
|
+
lines.push(`- Warnings: ${warningSummary}`);
|
|
366
|
+
lines.push("");
|
|
367
|
+
return lines;
|
|
368
|
+
};
|
|
369
|
+
const formatIntent = (bundle) => {
|
|
370
|
+
const intent = bundle.intent;
|
|
371
|
+
if (!intent)
|
|
372
|
+
return [];
|
|
373
|
+
const lines = [];
|
|
374
|
+
lines.push("INTENT:");
|
|
375
|
+
lines.push(`- Buckets: ${intent.intents.join(", ") || "unknown"}`);
|
|
376
|
+
const matchEntries = Object.entries(intent.matches ?? {});
|
|
377
|
+
for (const [bucket, matches] of matchEntries) {
|
|
378
|
+
if (!Array.isArray(matches) || matches.length === 0)
|
|
379
|
+
continue;
|
|
380
|
+
lines.push(`- ${bucket} matches: ${matches.join(", ")}`);
|
|
381
|
+
}
|
|
382
|
+
lines.push("");
|
|
383
|
+
return lines;
|
|
384
|
+
};
|
|
385
|
+
const formatProjectInfo = (bundle) => {
|
|
386
|
+
const info = bundle.project_info;
|
|
387
|
+
if (!info)
|
|
388
|
+
return [];
|
|
389
|
+
const lines = [];
|
|
390
|
+
lines.push("PROJECT INFO:");
|
|
391
|
+
if (info.workspace_root)
|
|
392
|
+
lines.push(`- Workspace root: ${info.workspace_root}`);
|
|
393
|
+
if (info.manifests && info.manifests.length) {
|
|
394
|
+
lines.push(`- Manifests: ${info.manifests.join(", ")}`);
|
|
395
|
+
}
|
|
396
|
+
if (info.readme_path) {
|
|
397
|
+
lines.push(`- README: ${info.readme_path}`);
|
|
398
|
+
}
|
|
399
|
+
if (info.docs && info.docs.length) {
|
|
400
|
+
lines.push(`- Docs: ${info.docs.join(", ")}`);
|
|
401
|
+
}
|
|
402
|
+
if (info.file_types && info.file_types.length) {
|
|
403
|
+
lines.push(`- File types: ${info.file_types.join(", ")}`);
|
|
404
|
+
}
|
|
405
|
+
lines.push("");
|
|
406
|
+
return lines;
|
|
407
|
+
};
|
|
408
|
+
const formatQueries = (bundle) => {
|
|
409
|
+
if (!bundle.queries?.length)
|
|
410
|
+
return [];
|
|
411
|
+
const lines = [];
|
|
412
|
+
lines.push("QUERIES:");
|
|
413
|
+
for (const query of bundle.queries) {
|
|
414
|
+
lines.push(`- ${query}`);
|
|
415
|
+
}
|
|
416
|
+
lines.push("");
|
|
417
|
+
return lines;
|
|
418
|
+
};
|
|
419
|
+
const formatQuerySignals = (bundle) => {
|
|
420
|
+
const signals = bundle.query_signals;
|
|
421
|
+
if (!signals)
|
|
422
|
+
return [];
|
|
423
|
+
const lines = [];
|
|
424
|
+
lines.push("QUERY SIGNALS:");
|
|
425
|
+
if (signals.phrases.length)
|
|
426
|
+
lines.push(`- Phrases: ${signals.phrases.join(", ")}`);
|
|
427
|
+
if (signals.file_tokens.length)
|
|
428
|
+
lines.push(`- File tokens: ${signals.file_tokens.join(", ")}`);
|
|
429
|
+
if (signals.keyword_phrases.length)
|
|
430
|
+
lines.push(`- Keyword phrases: ${signals.keyword_phrases.join(", ")}`);
|
|
431
|
+
if (signals.keywords.length)
|
|
432
|
+
lines.push(`- Keywords: ${signals.keywords.join(", ")}`);
|
|
433
|
+
lines.push("");
|
|
434
|
+
return lines;
|
|
435
|
+
};
|
|
436
|
+
const formatRequestDigest = (bundle) => {
|
|
437
|
+
const digest = bundle.request_digest;
|
|
438
|
+
if (!digest)
|
|
439
|
+
return [];
|
|
440
|
+
const lines = [];
|
|
441
|
+
lines.push("REQUEST DIGEST:");
|
|
442
|
+
lines.push(`- Summary: ${digest.summary}`);
|
|
443
|
+
lines.push(`- Refined query: ${digest.refined_query}`);
|
|
444
|
+
lines.push(`- Confidence: ${digest.confidence}`);
|
|
445
|
+
if (digest.signals.length) {
|
|
446
|
+
lines.push(`- Signals: ${digest.signals.join(", ")}`);
|
|
447
|
+
}
|
|
448
|
+
if (digest.candidate_files && digest.candidate_files.length) {
|
|
449
|
+
lines.push(`- Candidate files: ${digest.candidate_files.join(", ")}`);
|
|
450
|
+
}
|
|
451
|
+
lines.push("");
|
|
452
|
+
return lines;
|
|
453
|
+
};
|
|
454
|
+
const formatSearchResults = (bundle) => {
|
|
455
|
+
if (!bundle.search_results?.length)
|
|
456
|
+
return [];
|
|
457
|
+
const lines = [];
|
|
458
|
+
lines.push("SEARCH RESULTS:");
|
|
459
|
+
for (const result of bundle.search_results) {
|
|
460
|
+
lines.push(`- Query: ${result.query}`);
|
|
461
|
+
if (!result.hits.length) {
|
|
462
|
+
lines.push(" - (no hits)");
|
|
463
|
+
continue;
|
|
464
|
+
}
|
|
465
|
+
for (const hit of result.hits) {
|
|
466
|
+
const label = hit.path ?? hit.doc_id ?? "hit";
|
|
467
|
+
const score = typeof hit.score === "number" ? ` (score: ${hit.score})` : "";
|
|
468
|
+
lines.push(` - ${label}${score}`);
|
|
469
|
+
if (hit.score_breakdown) {
|
|
470
|
+
const breakdown = [];
|
|
471
|
+
if (typeof hit.score_breakdown.query_relevance === "number") {
|
|
472
|
+
breakdown.push(`query=${hit.score_breakdown.query_relevance}`);
|
|
473
|
+
}
|
|
474
|
+
if (typeof hit.score_breakdown.structural_relevance === "number") {
|
|
475
|
+
breakdown.push(`structural=${hit.score_breakdown.structural_relevance}`);
|
|
476
|
+
}
|
|
477
|
+
if (typeof hit.score_breakdown.recency_diff_relevance === "number") {
|
|
478
|
+
breakdown.push(`recency=${hit.score_breakdown.recency_diff_relevance}`);
|
|
479
|
+
}
|
|
480
|
+
if (typeof hit.score_breakdown.total === "number") {
|
|
481
|
+
breakdown.push(`total=${hit.score_breakdown.total}`);
|
|
482
|
+
}
|
|
483
|
+
if (breakdown.length) {
|
|
484
|
+
lines.push(` - score_breakdown: ${breakdown.join(", ")}`);
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
if (hit.retrieval_explanation?.summary) {
|
|
488
|
+
lines.push(` - explanation: ${truncateSummary(hit.retrieval_explanation.summary, 160)}`);
|
|
489
|
+
}
|
|
490
|
+
if (hit.provenance) {
|
|
491
|
+
const anchor = hit.provenance.anchor_kind ?? "unknown";
|
|
492
|
+
const path = hit.provenance.path ?? hit.provenance.rel_path ?? label;
|
|
493
|
+
const range = typeof hit.provenance.line_start === "number" && typeof hit.provenance.line_end === "number"
|
|
494
|
+
? `:${hit.provenance.line_start}-${hit.provenance.line_end}`
|
|
495
|
+
: "";
|
|
496
|
+
lines.push(` - provenance: ${path}${range} (${anchor})`);
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
lines.push("");
|
|
501
|
+
return lines;
|
|
502
|
+
};
|
|
503
|
+
const formatRelatedHits = (bundle) => {
|
|
504
|
+
if (!bundle.search_results?.length || !bundle.selection)
|
|
505
|
+
return [];
|
|
506
|
+
const selected = new Set(bundle.selection?.all ?? []);
|
|
507
|
+
const allHits = uniqueValues(bundle.search_results
|
|
508
|
+
.flatMap((result) => result.hits)
|
|
509
|
+
.map((hit) => hit.path ?? hit.doc_id ?? "")
|
|
510
|
+
.filter((value) => value.length > 0)).filter((path) => !selected.has(path));
|
|
511
|
+
if (allHits.length === 0)
|
|
512
|
+
return [];
|
|
513
|
+
const testHits = allHits.filter(isTestPath).slice(0, 4);
|
|
514
|
+
const docHits = allHits.filter((path) => !isTestPath(path) && isDocPath(path)).slice(0, 3);
|
|
515
|
+
const otherHits = allHits
|
|
516
|
+
.filter((path) => !isTestPath(path) && !isDocPath(path))
|
|
517
|
+
.slice(0, 3);
|
|
518
|
+
const lines = [];
|
|
519
|
+
lines.push("RELATED HITS (NOT SELECTED):");
|
|
520
|
+
if (testHits.length)
|
|
521
|
+
lines.push(`- Tests: ${testHits.join(", ")}`);
|
|
522
|
+
if (docHits.length)
|
|
523
|
+
lines.push(`- Docs: ${docHits.join(", ")}`);
|
|
524
|
+
if (otherHits.length)
|
|
525
|
+
lines.push(`- Other: ${otherHits.join(", ")}`);
|
|
526
|
+
lines.push("");
|
|
527
|
+
return lines;
|
|
528
|
+
};
|
|
529
|
+
const formatFileReferences = (bundle) => {
|
|
530
|
+
const files = bundle.files ?? [];
|
|
531
|
+
const lines = [];
|
|
532
|
+
lines.push("FILE REFERENCES (CONTENT WITHHELD):");
|
|
533
|
+
if (files.length === 0) {
|
|
534
|
+
lines.push("- none");
|
|
535
|
+
lines.push("");
|
|
536
|
+
return lines;
|
|
537
|
+
}
|
|
538
|
+
for (const file of files) {
|
|
539
|
+
const role = file.role === "focus" ? "FOCUS" : "PERIPHERY";
|
|
540
|
+
const metadata = [`slice=${file.sliceStrategy}`, `origin=${file.origin}`];
|
|
541
|
+
if (typeof file.size === "number")
|
|
542
|
+
metadata.push(`size=${file.size}`);
|
|
543
|
+
if (file.truncated)
|
|
544
|
+
metadata.push("truncated");
|
|
545
|
+
if (file.warnings?.length)
|
|
546
|
+
metadata.push(`warnings=${file.warnings.join("|")}`);
|
|
547
|
+
lines.push(`- [${role}] ${file.path} (${metadata.join(", ")})`);
|
|
548
|
+
}
|
|
549
|
+
lines.push("");
|
|
550
|
+
return lines;
|
|
551
|
+
};
|
|
552
|
+
const formatSymbols = (bundle) => {
|
|
553
|
+
if (!bundle.symbols?.length)
|
|
554
|
+
return [];
|
|
555
|
+
const lines = [];
|
|
556
|
+
lines.push("SYMBOLS:");
|
|
557
|
+
const entries = bundle.symbols.slice(0, SECTION_LIMITS.maxSymbolEntries);
|
|
558
|
+
for (const entry of entries) {
|
|
559
|
+
lines.push(`--- ${entry.path} ---`);
|
|
560
|
+
lines.push(truncateText(entry.summary, SECTION_LIMITS.maxSymbolChars));
|
|
561
|
+
lines.push("");
|
|
562
|
+
}
|
|
563
|
+
if (bundle.symbols.length > SECTION_LIMITS.maxSymbolEntries) {
|
|
564
|
+
lines.push(`- Symbol entries truncated: showing ${SECTION_LIMITS.maxSymbolEntries} of ${bundle.symbols.length}.`);
|
|
565
|
+
lines.push("");
|
|
566
|
+
}
|
|
567
|
+
return lines;
|
|
568
|
+
};
|
|
569
|
+
const formatAst = (bundle) => {
|
|
570
|
+
if (!bundle.ast?.length)
|
|
571
|
+
return [];
|
|
572
|
+
const focusPaths = new Set((bundle.files ?? []).filter((file) => file.role === "focus").map((file) => file.path));
|
|
573
|
+
const hasFocus = focusPaths.size > 0;
|
|
574
|
+
const astEntries = hasFocus
|
|
575
|
+
? bundle.ast.filter((entry) => focusPaths.has(entry.path))
|
|
576
|
+
: bundle.ast;
|
|
577
|
+
if (astEntries.length === 0)
|
|
578
|
+
return [];
|
|
579
|
+
const lines = [];
|
|
580
|
+
lines.push("AST:");
|
|
581
|
+
const entries = astEntries.slice(0, SECTION_LIMITS.maxAstEntries);
|
|
582
|
+
for (const entry of entries) {
|
|
583
|
+
const nodes = entry.nodes.slice(0, SECTION_LIMITS.maxAstNodes);
|
|
584
|
+
const astText = truncateText(JSON.stringify(nodes, null, 2), SECTION_LIMITS.maxAstChars);
|
|
585
|
+
lines.push(`--- ${entry.path} ---`);
|
|
586
|
+
lines.push(astText);
|
|
587
|
+
if (entry.nodes.length > SECTION_LIMITS.maxAstNodes) {
|
|
588
|
+
lines.push(`/* node list truncated: showing ${SECTION_LIMITS.maxAstNodes} of ${entry.nodes.length} */`);
|
|
589
|
+
}
|
|
590
|
+
lines.push("");
|
|
591
|
+
}
|
|
592
|
+
if (astEntries.length > SECTION_LIMITS.maxAstEntries) {
|
|
593
|
+
lines.push(`- AST entries truncated: showing ${SECTION_LIMITS.maxAstEntries} of ${astEntries.length}.`);
|
|
594
|
+
lines.push("");
|
|
595
|
+
}
|
|
596
|
+
return lines;
|
|
597
|
+
};
|
|
598
|
+
const formatImpact = (bundle) => {
|
|
599
|
+
if (!bundle.impact?.length)
|
|
600
|
+
return [];
|
|
601
|
+
const lines = [];
|
|
602
|
+
lines.push("IMPACT GRAPH:");
|
|
603
|
+
for (const entry of bundle.impact) {
|
|
604
|
+
lines.push(`- ${entry.file}`);
|
|
605
|
+
lines.push(` - inbound: ${entry.inbound.join(", ") || "none"}`);
|
|
606
|
+
lines.push(` - outbound: ${entry.outbound.join(", ") || "none"}`);
|
|
607
|
+
}
|
|
608
|
+
lines.push("");
|
|
609
|
+
return lines;
|
|
610
|
+
};
|
|
611
|
+
const formatDagSummary = (bundle) => {
|
|
612
|
+
if (!bundle.dag_summary)
|
|
613
|
+
return [];
|
|
614
|
+
const lines = [];
|
|
615
|
+
lines.push("DAG REASONING:");
|
|
616
|
+
const summary = bundle.dag_summary;
|
|
617
|
+
const parts = summary.split(/\r?\n/).map((line) => line.trim());
|
|
618
|
+
const sessionLine = parts.find((line) => line.startsWith("session_id:"));
|
|
619
|
+
const nodesLine = parts.find((line) => line.startsWith("nodes:"));
|
|
620
|
+
const edgesLine = parts.find((line) => line.startsWith("edges:"));
|
|
621
|
+
if (nodesLine || edgesLine) {
|
|
622
|
+
const compact = [sessionLine, nodesLine, edgesLine].filter(Boolean).join(" ");
|
|
623
|
+
lines.push(`${compact} (full DAG omitted; see logs if needed)`);
|
|
624
|
+
}
|
|
625
|
+
else {
|
|
626
|
+
lines.push(truncateText(summary, 800));
|
|
627
|
+
}
|
|
628
|
+
lines.push("");
|
|
629
|
+
return lines;
|
|
630
|
+
};
|
|
631
|
+
const formatMemory = (bundle) => {
|
|
632
|
+
if (!bundle.memory?.length)
|
|
633
|
+
return [];
|
|
634
|
+
const lines = [];
|
|
635
|
+
lines.push("REPO MEMORY:");
|
|
636
|
+
for (const entry of bundle.memory.slice(0, SECTION_LIMITS.maxMemoryEntries)) {
|
|
637
|
+
lines.push(`- ${truncateText(entry.text, SECTION_LIMITS.maxMemoryChars)}`);
|
|
638
|
+
}
|
|
639
|
+
if (bundle.memory.length > SECTION_LIMITS.maxMemoryEntries) {
|
|
640
|
+
lines.push(`- (additional memory entries omitted: ${bundle.memory.length - SECTION_LIMITS.maxMemoryEntries})`);
|
|
641
|
+
}
|
|
642
|
+
lines.push("");
|
|
643
|
+
return lines;
|
|
644
|
+
};
|
|
645
|
+
const formatEpisodicMemory = (bundle) => {
|
|
646
|
+
if (!bundle.episodic_memory?.length)
|
|
647
|
+
return [];
|
|
648
|
+
const lines = [];
|
|
649
|
+
lines.push("PAST SUCCESSFUL RUNS (EPISODIC MEMORY):");
|
|
650
|
+
for (const entry of bundle.episodic_memory) {
|
|
651
|
+
lines.push(`- Intent: ${entry.intent}`);
|
|
652
|
+
lines.push(` Plan: ${entry.plan.replace(/\n/g, "\\n")}`);
|
|
653
|
+
}
|
|
654
|
+
lines.push("");
|
|
655
|
+
return lines;
|
|
656
|
+
};
|
|
657
|
+
const formatGoldenExamples = (bundle) => {
|
|
658
|
+
if (!bundle.golden_examples?.length)
|
|
659
|
+
return [];
|
|
660
|
+
const lines = [];
|
|
661
|
+
lines.push("GOLDEN EXAMPLES (Follow these patterns):");
|
|
662
|
+
for (const entry of bundle.golden_examples) {
|
|
663
|
+
lines.push(`- Intent: ${entry.intent}`);
|
|
664
|
+
lines.push(` Patch: ${entry.patch.replace(/\n/g, "\\n").slice(0, 500)}...`);
|
|
665
|
+
}
|
|
666
|
+
lines.push("");
|
|
667
|
+
return lines;
|
|
668
|
+
};
|
|
669
|
+
const formatProfile = (bundle) => {
|
|
670
|
+
if (!bundle.profile?.length)
|
|
671
|
+
return [];
|
|
672
|
+
const lines = [];
|
|
673
|
+
lines.push("USER PROFILE:");
|
|
674
|
+
for (const entry of bundle.profile.slice(0, SECTION_LIMITS.maxProfileEntries)) {
|
|
675
|
+
lines.push(`- ${truncateText(entry.content, SECTION_LIMITS.maxProfileChars)}`);
|
|
676
|
+
}
|
|
677
|
+
if (bundle.profile.length > SECTION_LIMITS.maxProfileEntries) {
|
|
678
|
+
lines.push(`- (additional profile entries omitted: ${bundle.profile.length - SECTION_LIMITS.maxProfileEntries})`);
|
|
679
|
+
}
|
|
680
|
+
lines.push("");
|
|
681
|
+
return lines;
|
|
682
|
+
};
|
|
683
|
+
const formatIndexInfo = (bundle) => {
|
|
684
|
+
if (!bundle.index)
|
|
685
|
+
return [];
|
|
686
|
+
const lines = [];
|
|
687
|
+
const formatValue = (value) => value < 0 ? "unknown" : String(value);
|
|
688
|
+
lines.push("INDEX INFO:");
|
|
689
|
+
lines.push(`- Docs indexed: ${formatValue(bundle.index.num_docs)}`);
|
|
690
|
+
lines.push(`- Last updated: ${formatValue(bundle.index.last_updated_epoch_ms)}`);
|
|
691
|
+
lines.push("");
|
|
692
|
+
return lines;
|
|
693
|
+
};
|
|
694
|
+
const formatWarnings = (bundle) => {
|
|
695
|
+
if (!bundle.warnings?.length)
|
|
696
|
+
return [];
|
|
697
|
+
const lines = [];
|
|
698
|
+
lines.push("WARNINGS:");
|
|
699
|
+
for (const warning of bundle.warnings) {
|
|
700
|
+
const { code, detail } = splitWarning(warning);
|
|
701
|
+
const entry = WARNING_GLOSSARY[code];
|
|
702
|
+
if (entry) {
|
|
703
|
+
const detailLabel = detail ? ` (${detail})` : "";
|
|
704
|
+
lines.push(`- [${entry.severity}] ${code}${detailLabel}: ${entry.message}`);
|
|
705
|
+
}
|
|
706
|
+
else {
|
|
707
|
+
lines.push(`- ${warning}`);
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
lines.push("");
|
|
711
|
+
return lines;
|
|
712
|
+
};
|
|
713
|
+
const filterPolicyWarnings = (warnings = []) => warnings.filter((warning) => !warning.startsWith("write_policy_"));
|
|
714
|
+
const sanitizeResearchSummary = (summary) => {
|
|
715
|
+
if (!summary)
|
|
716
|
+
return undefined;
|
|
717
|
+
const toolUsage = summary.tool_usage ? { ...summary.tool_usage } : undefined;
|
|
718
|
+
const evidence = summary.evidence
|
|
719
|
+
? {
|
|
720
|
+
...summary.evidence,
|
|
721
|
+
warnings: summary.evidence.warnings?.filter(Boolean),
|
|
722
|
+
gaps: summary.evidence.gaps?.filter(Boolean),
|
|
723
|
+
}
|
|
724
|
+
: undefined;
|
|
725
|
+
return {
|
|
726
|
+
...summary,
|
|
727
|
+
key_findings: summary.key_findings?.filter(Boolean),
|
|
728
|
+
tool_usage: toolUsage,
|
|
729
|
+
evidence,
|
|
730
|
+
warnings: summary.warnings?.filter(Boolean),
|
|
731
|
+
notes: summary.notes?.filter(Boolean),
|
|
732
|
+
};
|
|
733
|
+
};
|
|
734
|
+
export const sanitizeContextBundleForOutput = (bundle) => {
|
|
735
|
+
const sanitized = { ...bundle };
|
|
736
|
+
delete sanitized.allow_write_paths;
|
|
737
|
+
delete sanitized.read_only_paths;
|
|
738
|
+
sanitized.warnings = filterPolicyWarnings(bundle.warnings);
|
|
739
|
+
sanitized.research = sanitizeResearchSummary(bundle.research);
|
|
740
|
+
return sanitized;
|
|
741
|
+
};
|
|
742
|
+
export const serializeContext = (bundle, options) => {
|
|
743
|
+
const audience = options.audience ?? "builder";
|
|
744
|
+
if (options.mode === "json") {
|
|
745
|
+
const files = bundle.files ?? [];
|
|
746
|
+
const focusFiles = files.filter((file) => file.role === "focus").length;
|
|
747
|
+
const peripheryFiles = files.filter((file) => file.role === "periphery").length;
|
|
748
|
+
const totalBytes = files.reduce((sum, file) => sum + file.content.length, 0);
|
|
749
|
+
return {
|
|
750
|
+
mode: "json",
|
|
751
|
+
audience,
|
|
752
|
+
content: JSON.stringify(bundle, null, 2),
|
|
753
|
+
token_estimate: estimateTokens(JSON.stringify(bundle)),
|
|
754
|
+
stats: { focus_files: focusFiles, periphery_files: peripheryFiles, total_bytes: totalBytes },
|
|
755
|
+
};
|
|
756
|
+
}
|
|
757
|
+
const includeContents = audience === "builder";
|
|
758
|
+
const lines = [];
|
|
759
|
+
lines.push("CODALI LIBRARIAN CONTEXT");
|
|
760
|
+
lines.push("");
|
|
761
|
+
lines.push(...formatProjectSummary(bundle));
|
|
762
|
+
lines.push(...formatRunSummary(bundle));
|
|
763
|
+
lines.push(...formatResearchSummary(bundle));
|
|
764
|
+
lines.push(...formatRetrievalReport(bundle));
|
|
765
|
+
lines.push("USER REQUEST:");
|
|
766
|
+
lines.push(bundle.request);
|
|
767
|
+
lines.push("");
|
|
768
|
+
lines.push(...formatDeliverables(bundle));
|
|
769
|
+
lines.push(...formatContextCoverage(bundle, { includeContents }));
|
|
770
|
+
if (!includeContents) {
|
|
771
|
+
lines.push(...formatAgentProtocol());
|
|
772
|
+
}
|
|
773
|
+
lines.push(...formatIntent(bundle));
|
|
774
|
+
lines.push(...formatProjectInfo(bundle));
|
|
775
|
+
lines.push(...formatQueries(bundle));
|
|
776
|
+
lines.push(...formatQuerySignals(bundle));
|
|
777
|
+
lines.push(...formatRequestDigest(bundle));
|
|
778
|
+
lines.push(...formatSearchResults(bundle));
|
|
779
|
+
if (bundle.selection) {
|
|
780
|
+
const focus = bundle.selection.focus.join(", ") || "none";
|
|
781
|
+
const periphery = bundle.selection.periphery.join(", ") || "none";
|
|
782
|
+
lines.push("SELECTION:");
|
|
783
|
+
lines.push(`- Focus files: ${focus}`);
|
|
784
|
+
lines.push(`- Periphery files: ${periphery}`);
|
|
785
|
+
lines.push(`- Low confidence: ${bundle.selection.low_confidence ? "yes" : "no"}`);
|
|
786
|
+
lines.push("");
|
|
787
|
+
}
|
|
788
|
+
lines.push(...formatRelatedHits(bundle));
|
|
789
|
+
if (bundle.repo_map_raw) {
|
|
790
|
+
lines.push("REPO MAP:");
|
|
791
|
+
lines.push(bundle.repo_map_raw);
|
|
792
|
+
lines.push("");
|
|
793
|
+
}
|
|
794
|
+
else if (bundle.repo_map) {
|
|
795
|
+
lines.push("REPO MAP:");
|
|
796
|
+
lines.push(bundle.repo_map);
|
|
797
|
+
lines.push("");
|
|
798
|
+
}
|
|
799
|
+
const files = bundle.files ?? [];
|
|
800
|
+
if (includeContents) {
|
|
801
|
+
for (const file of files) {
|
|
802
|
+
lines.push(formatFileHeader(file));
|
|
803
|
+
lines.push(file.content);
|
|
804
|
+
lines.push("");
|
|
805
|
+
}
|
|
806
|
+
if (files.length === 0) {
|
|
807
|
+
lines.push("NO FILE CONTENT AVAILABLE");
|
|
808
|
+
lines.push("");
|
|
809
|
+
}
|
|
810
|
+
if (bundle.snippets.length) {
|
|
811
|
+
lines.push("SNIPPETS:");
|
|
812
|
+
for (const snippet of bundle.snippets.slice(0, SECTION_LIMITS.maxSnippetEntries)) {
|
|
813
|
+
const label = snippet.path ?? snippet.doc_id ?? "snippet";
|
|
814
|
+
lines.push(`--- ${label} ---`);
|
|
815
|
+
const metadata = [];
|
|
816
|
+
if (typeof snippet.score === "number")
|
|
817
|
+
metadata.push(`score=${snippet.score}`);
|
|
818
|
+
if (snippet.snippet_origin)
|
|
819
|
+
metadata.push(`origin=${snippet.snippet_origin}`);
|
|
820
|
+
if (snippet.snippet_truncated)
|
|
821
|
+
metadata.push("snippet_truncated");
|
|
822
|
+
if (typeof snippet.line_start === "number" &&
|
|
823
|
+
typeof snippet.line_end === "number") {
|
|
824
|
+
metadata.push(`line_window=${snippet.line_start}-${snippet.line_end}`);
|
|
825
|
+
}
|
|
826
|
+
if (snippet.provenance?.anchor_kind) {
|
|
827
|
+
metadata.push(`anchor_kind=${snippet.provenance.anchor_kind}`);
|
|
828
|
+
}
|
|
829
|
+
if (metadata.length) {
|
|
830
|
+
lines.push(`[meta] ${metadata.join(", ")}`);
|
|
831
|
+
}
|
|
832
|
+
if (snippet.retrieval_explanation?.summary) {
|
|
833
|
+
lines.push(`[why] ${truncateSummary(snippet.retrieval_explanation.summary, 180)}`);
|
|
834
|
+
}
|
|
835
|
+
lines.push(truncateText(snippet.content, SECTION_LIMITS.maxSnippetChars));
|
|
836
|
+
lines.push("");
|
|
837
|
+
}
|
|
838
|
+
if (bundle.snippets.length > SECTION_LIMITS.maxSnippetEntries) {
|
|
839
|
+
lines.push(`- Snippet entries truncated: showing ${SECTION_LIMITS.maxSnippetEntries} of ${bundle.snippets.length}.`);
|
|
840
|
+
lines.push("");
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
lines.push(...formatSymbols(bundle));
|
|
844
|
+
lines.push(...formatAst(bundle));
|
|
845
|
+
lines.push(...formatImpact(bundle));
|
|
846
|
+
lines.push(...formatDagSummary(bundle));
|
|
847
|
+
}
|
|
848
|
+
else {
|
|
849
|
+
lines.push(...formatFileReferences(bundle));
|
|
850
|
+
}
|
|
851
|
+
lines.push(...formatMemory(bundle));
|
|
852
|
+
lines.push(...formatEpisodicMemory(bundle));
|
|
853
|
+
lines.push(...formatGoldenExamples(bundle));
|
|
854
|
+
lines.push(...formatProfile(bundle));
|
|
855
|
+
lines.push(...formatIndexInfo(bundle));
|
|
856
|
+
lines.push(...formatWarnings(bundle));
|
|
857
|
+
if (bundle.missing && bundle.missing.length) {
|
|
858
|
+
lines.push("MISSING DATA:");
|
|
859
|
+
for (const entry of bundle.missing) {
|
|
860
|
+
lines.push(`- ${entry}`);
|
|
861
|
+
}
|
|
862
|
+
lines.push("");
|
|
863
|
+
}
|
|
864
|
+
if (includeContents && bundle.impact_diagnostics.length) {
|
|
865
|
+
lines.push("IMPACT DIAGNOSTICS:");
|
|
866
|
+
for (const entry of bundle.impact_diagnostics) {
|
|
867
|
+
lines.push(`- ${entry.file}: ${JSON.stringify(entry.diagnostics)}`);
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
lines.push("");
|
|
871
|
+
lines.push("END OF CONTEXT");
|
|
872
|
+
const focusFiles = files.filter((file) => file.role === "focus").length;
|
|
873
|
+
const peripheryFiles = files.filter((file) => file.role === "periphery").length;
|
|
874
|
+
const totalBytes = files.reduce((sum, file) => sum + file.content.length, 0);
|
|
875
|
+
return {
|
|
876
|
+
mode: "bundle_text",
|
|
877
|
+
audience,
|
|
878
|
+
content: lines.join("\n"),
|
|
879
|
+
token_estimate: estimateTokens(lines.join("\n")),
|
|
880
|
+
stats: { focus_files: focusFiles, periphery_files: peripheryFiles, total_bytes: totalBytes },
|
|
881
|
+
};
|
|
882
|
+
};
|