@4da/mcp-server 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (123) hide show
  1. package/README.md +135 -0
  2. package/dist/db.d.ts +64 -0
  3. package/dist/db.d.ts.map +1 -0
  4. package/dist/db.js +578 -0
  5. package/dist/db.js.map +1 -0
  6. package/dist/index.d.ts +37 -0
  7. package/dist/index.d.ts.map +1 -0
  8. package/dist/index.js +422 -0
  9. package/dist/index.js.map +1 -0
  10. package/dist/llm.d.ts +144 -0
  11. package/dist/llm.d.ts.map +1 -0
  12. package/dist/llm.js +447 -0
  13. package/dist/llm.js.map +1 -0
  14. package/dist/output-manager.d.ts +156 -0
  15. package/dist/output-manager.d.ts.map +1 -0
  16. package/dist/output-manager.js +156 -0
  17. package/dist/output-manager.js.map +1 -0
  18. package/dist/schema-registry.d.ts +46 -0
  19. package/dist/schema-registry.d.ts.map +1 -0
  20. package/dist/schema-registry.js +133 -0
  21. package/dist/schema-registry.js.map +1 -0
  22. package/dist/schemas/config-validator.json +18 -0
  23. package/dist/schemas/context-analysis.json +25 -0
  24. package/dist/schemas/daily-briefing.json +34 -0
  25. package/dist/schemas/explain-relevance.json +19 -0
  26. package/dist/schemas/get-actionable-signals.json +29 -0
  27. package/dist/schemas/get-context.json +17 -0
  28. package/dist/schemas/get-relevant-content.json +26 -0
  29. package/dist/schemas/llm-status.json +13 -0
  30. package/dist/schemas/record-feedback.json +24 -0
  31. package/dist/schemas/score-autopsy.json +30 -0
  32. package/dist/schemas/source-health.json +17 -0
  33. package/dist/schemas/topic-connections.json +34 -0
  34. package/dist/schemas/trend-analysis.json +29 -0
  35. package/dist/tools/attention-report.d.ts +39 -0
  36. package/dist/tools/attention-report.d.ts.map +1 -0
  37. package/dist/tools/attention-report.js +72 -0
  38. package/dist/tools/attention-report.js.map +1 -0
  39. package/dist/tools/config-validator.d.ts +59 -0
  40. package/dist/tools/config-validator.d.ts.map +1 -0
  41. package/dist/tools/config-validator.js +375 -0
  42. package/dist/tools/config-validator.js.map +1 -0
  43. package/dist/tools/context-analysis.d.ts +108 -0
  44. package/dist/tools/context-analysis.d.ts.map +1 -0
  45. package/dist/tools/context-analysis.js +300 -0
  46. package/dist/tools/context-analysis.js.map +1 -0
  47. package/dist/tools/daily-briefing.d.ts +103 -0
  48. package/dist/tools/daily-briefing.d.ts.map +1 -0
  49. package/dist/tools/daily-briefing.js +278 -0
  50. package/dist/tools/daily-briefing.js.map +1 -0
  51. package/dist/tools/explain-relevance.d.ts +36 -0
  52. package/dist/tools/explain-relevance.d.ts.map +1 -0
  53. package/dist/tools/explain-relevance.js +50 -0
  54. package/dist/tools/explain-relevance.js.map +1 -0
  55. package/dist/tools/export-context.d.ts +43 -0
  56. package/dist/tools/export-context.d.ts.map +1 -0
  57. package/dist/tools/export-context.js +104 -0
  58. package/dist/tools/export-context.js.map +1 -0
  59. package/dist/tools/get-actionable-signals.d.ts +65 -0
  60. package/dist/tools/get-actionable-signals.d.ts.map +1 -0
  61. package/dist/tools/get-actionable-signals.js +268 -0
  62. package/dist/tools/get-actionable-signals.js.map +1 -0
  63. package/dist/tools/get-context.d.ts +34 -0
  64. package/dist/tools/get-context.d.ts.map +1 -0
  65. package/dist/tools/get-context.js +43 -0
  66. package/dist/tools/get-context.js.map +1 -0
  67. package/dist/tools/get-relevant-content.d.ts +44 -0
  68. package/dist/tools/get-relevant-content.d.ts.map +1 -0
  69. package/dist/tools/get-relevant-content.js +56 -0
  70. package/dist/tools/get-relevant-content.js.map +1 -0
  71. package/dist/tools/index.d.ts +40 -0
  72. package/dist/tools/index.d.ts.map +1 -0
  73. package/dist/tools/index.js +44 -0
  74. package/dist/tools/index.js.map +1 -0
  75. package/dist/tools/knowledge-gaps.d.ts +36 -0
  76. package/dist/tools/knowledge-gaps.d.ts.map +1 -0
  77. package/dist/tools/knowledge-gaps.js +76 -0
  78. package/dist/tools/knowledge-gaps.js.map +1 -0
  79. package/dist/tools/llm-status.d.ts +45 -0
  80. package/dist/tools/llm-status.d.ts.map +1 -0
  81. package/dist/tools/llm-status.js +92 -0
  82. package/dist/tools/llm-status.js.map +1 -0
  83. package/dist/tools/project-health.d.ts +41 -0
  84. package/dist/tools/project-health.d.ts.map +1 -0
  85. package/dist/tools/project-health.js +71 -0
  86. package/dist/tools/project-health.js.map +1 -0
  87. package/dist/tools/record-feedback.d.ts +39 -0
  88. package/dist/tools/record-feedback.d.ts.map +1 -0
  89. package/dist/tools/record-feedback.js +60 -0
  90. package/dist/tools/record-feedback.js.map +1 -0
  91. package/dist/tools/reverse-mentions.d.ts +38 -0
  92. package/dist/tools/reverse-mentions.d.ts.map +1 -0
  93. package/dist/tools/reverse-mentions.js +57 -0
  94. package/dist/tools/reverse-mentions.js.map +1 -0
  95. package/dist/tools/score-autopsy.d.ts +93 -0
  96. package/dist/tools/score-autopsy.d.ts.map +1 -0
  97. package/dist/tools/score-autopsy.js +288 -0
  98. package/dist/tools/score-autopsy.js.map +1 -0
  99. package/dist/tools/semantic-shifts.d.ts +37 -0
  100. package/dist/tools/semantic-shifts.d.ts.map +1 -0
  101. package/dist/tools/semantic-shifts.js +73 -0
  102. package/dist/tools/semantic-shifts.js.map +1 -0
  103. package/dist/tools/signal-chains.d.ts +45 -0
  104. package/dist/tools/signal-chains.d.ts.map +1 -0
  105. package/dist/tools/signal-chains.js +60 -0
  106. package/dist/tools/signal-chains.js.map +1 -0
  107. package/dist/tools/source-health.d.ts +64 -0
  108. package/dist/tools/source-health.d.ts.map +1 -0
  109. package/dist/tools/source-health.js +176 -0
  110. package/dist/tools/source-health.js.map +1 -0
  111. package/dist/tools/topic-connections.d.ts +112 -0
  112. package/dist/tools/topic-connections.d.ts.map +1 -0
  113. package/dist/tools/topic-connections.js +318 -0
  114. package/dist/tools/topic-connections.js.map +1 -0
  115. package/dist/tools/trend-analysis.d.ts +105 -0
  116. package/dist/tools/trend-analysis.d.ts.map +1 -0
  117. package/dist/tools/trend-analysis.js +295 -0
  118. package/dist/tools/trend-analysis.js.map +1 -0
  119. package/dist/types.d.ts +163 -0
  120. package/dist/types.d.ts.map +1 -0
  121. package/dist/types.js +7 -0
  122. package/dist/types.js.map +1 -0
  123. package/package.json +61 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"score-autopsy.d.ts","sourceRoot":"","sources":["../../src/tools/score-autopsy.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE/C,OAAO,EAA6B,KAAK,aAAa,EAAE,KAAK,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAE/G,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwC5B,CAAC;AAEF,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,UAAU,cAAc;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,UAAU,WAAW;IACnB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,gBAAgB,EAAE,MAAM,CAAC;IACzB,cAAc,EAAE,MAAM,CAAC;CACxB;AAED,UAAU,aAAa;IACrB,IAAI,EAAE;QACJ,EAAE,EAAE,MAAM,CAAC;QACX,KAAK,EAAE,MAAM,CAAC;QACd,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;QACnB,WAAW,EAAE,MAAM,CAAC;QACpB,UAAU,EAAE,MAAM,CAAC;QACnB,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC;IACF,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,cAAc,EAAE,CAAC;IAC7B,gBAAgB,EAAE;QAChB,SAAS,EAAE,MAAM,EAAE,CAAC;QACpB,UAAU,EAAE,MAAM,EAAE,CAAC;QACrB,aAAa,EAAE,MAAM,EAAE,CAAC;QACxB,kBAAkB,EAAE,MAAM,EAAE,CAAC;QAC7B,cAAc,EAAE,MAAM,EAAE,CAAC;KAC1B,CAAC;IACF,aAAa,EAAE,WAAW,EAAE,CAAC;IAC7B,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,SAAS,EAAE,MAAM,CAAC;IAElB,WAAW,CAAC,EAAE;QACZ,OAAO,EAAE,MAAM,CAAC;QAChB,gBAAgB,EAAE,UAAU,GAAG,UAAU,GAAG,SAAS,GAAG,WAAW,CAAC;QACpE,SAAS,EAAE,MAAM,CAAC;QAClB,gBAAgB,EAAE,MAAM,CAAC;QACzB,UAAU,EAAE,MAAM,CAAC;KACpB,CAAC;CACH;AAED,wBAAsB,mBAAmB,CACvC,EAAE,EAAE,cAAc,EAClB,MAAM,EAAE,kBAAkB,GACzB,OAAO,CAAC,aAAa,GAAG,aAAa,CAAC,mBAAmB,CAAC,CAAC,CAsL7D"}
@@ -0,0 +1,288 @@
1
+ /**
2
+ * Score Autopsy Tool
3
+ *
4
+ * Deep forensic analysis of why content scored the way it did.
5
+ * This is a SUPERPOWER - it reveals the complete scoring breakdown.
6
+ *
7
+ * With synthesize=true, uses LLM to explain whether the score makes sense.
8
+ */
9
+ import { getLLMConfig, canSynthesize, synthesize, SYNTHESIS_PROMPTS } from "../llm.js";
10
+ import { createScoreAutopsyCompact } from "../output-manager.js";
11
+ export const scoreAutopsyTool = {
12
+ name: "score_autopsy",
13
+ description: `Perform a complete forensic analysis of why an item scored the way it did.
14
+
15
+ With synthesize=true (recommended), uses AI to explain whether the score seems correct.
16
+
17
+ Returns:
18
+ - Component-by-component score breakdown
19
+ - Matching context (interests, tech, topics)
20
+ - Comparison with similar items
21
+ - Recommendations for improving relevance
22
+ - AI analysis (when enabled)
23
+
24
+ Use this when you need to understand or debug relevance scores.`,
25
+ inputSchema: {
26
+ type: "object",
27
+ properties: {
28
+ item_id: {
29
+ type: "number",
30
+ description: "The item ID to analyze",
31
+ },
32
+ source_type: {
33
+ type: "string",
34
+ description: "Source type (e.g., 'hackernews', 'arxiv')",
35
+ },
36
+ compare_count: {
37
+ type: "number",
38
+ description: "Number of similar items to compare (default: 5)",
39
+ },
40
+ synthesize: {
41
+ type: "boolean",
42
+ description: "Use AI to analyze if the score makes sense (default: true if LLM configured)",
43
+ },
44
+ compact: {
45
+ type: "boolean",
46
+ description: "Return compact result with file reference (default: true for ~80% token reduction)",
47
+ },
48
+ },
49
+ required: ["item_id", "source_type"],
50
+ },
51
+ };
52
+ export async function executeScoreAutopsy(db, params) {
53
+ const { item_id, source_type, compare_count = 5 } = params;
54
+ const useCompact = params.compact !== false; // Default to compact=true
55
+ // Check LLM availability
56
+ const dbInstance = db.db;
57
+ const llmConfig = getLLMConfig(dbInstance);
58
+ const shouldSynthesize = params.synthesize ?? canSynthesize(llmConfig);
59
+ // Get the item
60
+ const item = db.getSourceItem(item_id, source_type);
61
+ if (!item) {
62
+ throw new Error(`Item ${item_id} of type ${source_type} not found`);
63
+ }
64
+ // Get full context
65
+ const context = db.getUserContext(true, true);
66
+ // Get detailed explanation
67
+ const explanation = db.explainRelevance(item_id, source_type);
68
+ if (!explanation) {
69
+ throw new Error("Failed to compute relevance explanation");
70
+ }
71
+ // Calculate age
72
+ const createdAt = new Date(item.created_at.replace(" ", "T") + "Z");
73
+ const ageHours = Math.round((Date.now() - createdAt.getTime()) / (1000 * 60 * 60));
74
+ // Build component breakdown
75
+ const components = [
76
+ {
77
+ name: "Interest Match",
78
+ raw_value: explanation.matching_context.matching_interests.length > 0 ? 0.8 : 0,
79
+ weight: 0.30,
80
+ contribution: explanation.score_breakdown.static_match_score * 0.5,
81
+ explanation: explanation.matching_context.matching_interests.length > 0
82
+ ? `Matches interests: ${explanation.matching_context.matching_interests.join(", ")}`
83
+ : "No direct interest matches",
84
+ },
85
+ {
86
+ name: "Tech Stack Match",
87
+ raw_value: explanation.matching_context.matching_tech.length > 0 ? 0.7 : 0,
88
+ weight: 0.20,
89
+ contribution: explanation.matching_context.matching_tech.length * 0.2,
90
+ explanation: explanation.matching_context.matching_tech.length > 0
91
+ ? `Matches tech: ${explanation.matching_context.matching_tech.join(", ")}`
92
+ : "No tech stack matches",
93
+ },
94
+ {
95
+ name: "Active Topics (ACE)",
96
+ raw_value: explanation.score_breakdown.ace_match_score,
97
+ weight: 0.15,
98
+ contribution: explanation.score_breakdown.ace_match_score,
99
+ explanation: explanation.matching_context.matching_topics.length > 0
100
+ ? `Recent work topics: ${explanation.matching_context.matching_topics.join(", ")}`
101
+ : "No active topic matches",
102
+ },
103
+ {
104
+ name: "Learned Affinities",
105
+ raw_value: explanation.score_breakdown.learned_affinity_score,
106
+ weight: 0.15,
107
+ contribution: explanation.score_breakdown.learned_affinity_score,
108
+ explanation: explanation.matching_context.matching_affinities.length > 0
109
+ ? `Learned preferences: ${explanation.matching_context.matching_affinities.join(", ")}`
110
+ : "No learned affinity matches",
111
+ },
112
+ {
113
+ name: "Recency Boost",
114
+ raw_value: ageHours < 24 ? 0.9 : ageHours < 72 ? 0.6 : 0.3,
115
+ weight: 0.10,
116
+ contribution: ageHours < 24 ? 0.09 : ageHours < 72 ? 0.06 : 0.03,
117
+ explanation: ageHours < 24
118
+ ? `Fresh content (${ageHours}h old)`
119
+ : `Older content (${Math.round(ageHours / 24)}d old)`,
120
+ },
121
+ {
122
+ name: "Anti-Penalty",
123
+ raw_value: -explanation.score_breakdown.anti_penalty,
124
+ weight: 1.0,
125
+ contribution: -explanation.score_breakdown.anti_penalty,
126
+ explanation: explanation.score_breakdown.anti_penalty > 0
127
+ ? "Score reduced due to exclusions or anti-topics"
128
+ : "No penalties applied",
129
+ },
130
+ ];
131
+ // Get similar items for comparison
132
+ const similarItems = getSimilarItems(db, item, source_type, compare_count);
133
+ // Generate recommendations
134
+ const recommendations = generateRecommendations(explanation.score_breakdown, explanation.matching_context, context, item);
135
+ // Generate narrative explanation
136
+ const narrative = generateNarrative(item, explanation.score_breakdown.final_score, explanation.matching_context, ageHours);
137
+ const result = {
138
+ item: {
139
+ id: item.id,
140
+ title: item.title,
141
+ url: item.url,
142
+ source_type: item.source_type,
143
+ created_at: item.created_at,
144
+ age_hours: ageHours,
145
+ },
146
+ final_score: explanation.score_breakdown.final_score,
147
+ components,
148
+ matching_context: {
149
+ interests: explanation.matching_context.matching_interests,
150
+ tech_stack: explanation.matching_context.matching_tech,
151
+ active_topics: explanation.matching_context.matching_topics,
152
+ learned_affinities: explanation.matching_context.matching_affinities,
153
+ exclusions_hit: explanation.score_breakdown.anti_penalty > 0
154
+ ? ["Exclusion or anti-topic triggered"]
155
+ : [],
156
+ },
157
+ similar_items: similarItems,
158
+ recommendations,
159
+ narrative,
160
+ };
161
+ // AI Analysis - the actual superpower
162
+ if (shouldSynthesize && canSynthesize(llmConfig)) {
163
+ try {
164
+ const autopsyData = {
165
+ item: { title: item.title, content: item.content?.substring(0, 500) },
166
+ final_score: result.final_score,
167
+ components: result.components,
168
+ matching_context: result.matching_context,
169
+ };
170
+ const contextData = {
171
+ interests: context.interests.slice(0, 10),
172
+ tech_stack: context.tech_stack,
173
+ role: context.role,
174
+ };
175
+ const synthesis = await synthesize(llmConfig, {
176
+ system: SYNTHESIS_PROMPTS.scoreAutopsy.system,
177
+ prompt: SYNTHESIS_PROMPTS.scoreAutopsy.buildPrompt(autopsyData, contextData),
178
+ max_tokens: 350,
179
+ complexity: SYNTHESIS_PROMPTS.scoreAutopsy.complexity,
180
+ });
181
+ // Parse the synthesis to extract structured assessment
182
+ const text = synthesis.synthesis.toLowerCase();
183
+ let scoreAssessment = "uncertain";
184
+ if (text.includes("too high") || text.includes("overscored") || text.includes("inflated")) {
185
+ scoreAssessment = "too_high";
186
+ }
187
+ else if (text.includes("too low") || text.includes("underscored") || text.includes("should be higher")) {
188
+ scoreAssessment = "too_low";
189
+ }
190
+ else if (text.includes("makes sense") || text.includes("accurate") || text.includes("correct") || text.includes("appropriate")) {
191
+ scoreAssessment = "accurate";
192
+ }
193
+ result.ai_analysis = {
194
+ verdict: synthesis.synthesis,
195
+ score_assessment: scoreAssessment,
196
+ reasoning: synthesis.synthesis.split("\n")[0] || "",
197
+ suggested_action: recommendations[0] || "No specific action needed",
198
+ model_used: synthesis.model_used,
199
+ };
200
+ }
201
+ catch (error) {
202
+ console.error("AI analysis failed:", error);
203
+ }
204
+ }
205
+ // Return compact or full result based on parameter
206
+ if (useCompact) {
207
+ return createScoreAutopsyCompact(result);
208
+ }
209
+ return result;
210
+ }
211
+ function getSimilarItems(db, item, sourceType, count) {
212
+ // Get recent items from same source to compare
213
+ const recentItems = db.getRelevantContent(0, sourceType, count * 2, 168); // Last week
214
+ return recentItems
215
+ .filter((ri) => ri.id !== item.id)
216
+ .slice(0, count)
217
+ .map((ri) => {
218
+ const scoreDiff = ri.relevance_score - db.explainRelevance(item.id, sourceType).score_breakdown.final_score;
219
+ return {
220
+ id: ri.id,
221
+ title: ri.title,
222
+ score: ri.relevance_score,
223
+ score_difference: Math.round(scoreDiff * 100) / 100,
224
+ key_difference: scoreDiff > 0
225
+ ? "Higher: likely more keyword matches"
226
+ : "Lower: fewer context matches",
227
+ };
228
+ });
229
+ }
230
+ function generateRecommendations(scores, matching, context, item) {
231
+ const recommendations = [];
232
+ // Low interest match
233
+ if (matching.matching_interests.length === 0 && scores.static_match_score < 0.2) {
234
+ // Extract potential keywords from item
235
+ const words = item.title.toLowerCase().split(/\s+/).filter(w => w.length > 4);
236
+ const topWord = words[0] || "this topic";
237
+ recommendations.push(`Add "${topWord}" as an explicit interest to boost similar content`);
238
+ }
239
+ // Low tech match
240
+ if (matching.matching_tech.length === 0 && context.tech_stack.length > 0) {
241
+ recommendations.push("Item doesn't mention your tech stack - relevance may improve if content aligns with: " +
242
+ context.tech_stack.slice(0, 3).join(", "));
243
+ }
244
+ // Low ACE match
245
+ if (scores.ace_match_score < 0.05) {
246
+ recommendations.push("No recent work context matches - ensure ACE is scanning your active projects");
247
+ }
248
+ // Low learned score
249
+ if (scores.learned_affinity_score < 0.05) {
250
+ recommendations.push("Give feedback on similar items to help 4DA learn your preferences");
251
+ }
252
+ // General recommendation if score is decent
253
+ if (recommendations.length === 0) {
254
+ recommendations.push("Score looks healthy - continue providing feedback to refine");
255
+ }
256
+ return recommendations;
257
+ }
258
+ function generateNarrative(item, score, matching, ageHours) {
259
+ const parts = [];
260
+ // Score assessment
261
+ if (score >= 0.8) {
262
+ parts.push(`"${item.title}" is highly relevant to you (${Math.round(score * 100)}% match).`);
263
+ }
264
+ else if (score >= 0.5) {
265
+ parts.push(`"${item.title}" has moderate relevance (${Math.round(score * 100)}% match).`);
266
+ }
267
+ else {
268
+ parts.push(`"${item.title}" has low relevance (${Math.round(score * 100)}% match).`);
269
+ }
270
+ // Why
271
+ const matches = [
272
+ ...matching.matching_interests.map(i => `interest "${i}"`),
273
+ ...matching.matching_tech.map(t => `tech "${t}"`),
274
+ ...matching.matching_topics.map(t => `recent work on "${t}"`),
275
+ ];
276
+ if (matches.length > 0) {
277
+ parts.push(`It matches your ${matches.slice(0, 2).join(" and ")}.`);
278
+ }
279
+ else {
280
+ parts.push("No strong matches to your declared interests or recent work.");
281
+ }
282
+ // Recency
283
+ if (ageHours < 24) {
284
+ parts.push("The freshness boost helps (published within 24 hours).");
285
+ }
286
+ return parts.join(" ");
287
+ }
288
+ //# sourceMappingURL=score-autopsy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"score-autopsy.js","sourceRoot":"","sources":["../../src/tools/score-autopsy.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AACvF,OAAO,EAAE,yBAAyB,EAAgD,MAA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AC;IAED,UAAU;IACV,IAAI,QAAQ,GAAG,EAAE,EAAE,CAAC;QAClB,KAAK,CAAC,IAAI,CAAC,wDAAwD,CAAC,CAAC;IACvE,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACzB,CAAC"}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * semantic_shifts tool
3
+ *
4
+ * Detect how topic narratives shift over time.
5
+ */
6
+ import type { FourDADatabase } from "../db.js";
7
+ export interface SemanticShiftsParams {
8
+ period_days?: number;
9
+ min_magnitude?: number;
10
+ }
11
+ export declare const semanticShiftsTool: {
12
+ name: string;
13
+ description: string;
14
+ inputSchema: {
15
+ type: "object";
16
+ properties: {
17
+ period_days: {
18
+ type: string;
19
+ description: string;
20
+ default: number;
21
+ };
22
+ min_magnitude: {
23
+ type: string;
24
+ description: string;
25
+ default: number;
26
+ };
27
+ };
28
+ };
29
+ };
30
+ export declare function executeSemanticShifts(db: FourDADatabase, params: SemanticShiftsParams): {
31
+ shifts: any[];
32
+ total: number;
33
+ period_days: number;
34
+ topics_tracked: number;
35
+ summary: string;
36
+ };
37
+ //# sourceMappingURL=semantic-shifts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"semantic-shifts.d.ts","sourceRoot":"","sources":["../../src/tools/semantic-shifts.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE/C,MAAM,WAAW,oBAAoB;IACnC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;CAkB9B,CAAC;AAEF,wBAAgB,qBAAqB,CACnC,EAAE,EAAE,cAAc,EAClB,MAAM,EAAE,oBAAoB;;;;;;EAuD7B"}
@@ -0,0 +1,73 @@
1
+ /**
2
+ * semantic_shifts tool
3
+ *
4
+ * Detect how topic narratives shift over time.
5
+ */
6
+ export const semanticShiftsTool = {
7
+ name: "semantic_shifts",
8
+ description: `Detect narrative shifts in topics you follow. Instead of "new post about X", see "the conversation about X shifted from A to B."`,
9
+ inputSchema: {
10
+ type: "object",
11
+ properties: {
12
+ period_days: {
13
+ type: "number",
14
+ description: "Look-back period in days. Default: 7",
15
+ default: 7,
16
+ },
17
+ min_magnitude: {
18
+ type: "number",
19
+ description: "Minimum drift magnitude (0-1). Default: 0.1",
20
+ default: 0.1,
21
+ },
22
+ },
23
+ },
24
+ };
25
+ export function executeSemanticShifts(db, params) {
26
+ const rawDb = db.getRawDb();
27
+ const periodDays = params.period_days || 7;
28
+ const rows = rawDb
29
+ .prepare(`SELECT id, subject, data, created_at
30
+ FROM temporal_events
31
+ WHERE event_type = 'topic_centroid'
32
+ AND created_at >= datetime('now', '-' || ? || ' days')
33
+ ORDER BY created_at DESC`)
34
+ .all(periodDays);
35
+ // Group centroids by subject (topic)
36
+ const byTopic = new Map();
37
+ for (const row of rows) {
38
+ const existing = byTopic.get(row.subject) || [];
39
+ existing.push({
40
+ data: JSON.parse(row.data),
41
+ created_at: row.created_at,
42
+ });
43
+ byTopic.set(row.subject, existing);
44
+ }
45
+ // Detect shifts where we have at least 2 snapshots
46
+ const shifts = [];
47
+ for (const [topic, snapshots] of byTopic) {
48
+ if (snapshots.length < 2)
49
+ continue;
50
+ const latest = snapshots[0];
51
+ const earliest = snapshots[snapshots.length - 1];
52
+ const magnitude = latest.data.drift_magnitude || 0;
53
+ if (magnitude >= (params.min_magnitude || 0.1)) {
54
+ shifts.push({
55
+ topic,
56
+ drift_magnitude: magnitude,
57
+ direction: latest.data.direction || "unknown",
58
+ period: `last ${periodDays} days`,
59
+ snapshots: snapshots.length,
60
+ detected_at: latest.created_at,
61
+ });
62
+ }
63
+ }
64
+ shifts.sort((a, b) => b.drift_magnitude - a.drift_magnitude);
65
+ return {
66
+ shifts,
67
+ total: shifts.length,
68
+ period_days: periodDays,
69
+ topics_tracked: byTopic.size,
70
+ summary: `${shifts.length} narrative shift${shifts.length !== 1 ? "s" : ""} detected across ${byTopic.size} topics`,
71
+ };
72
+ }
73
+ //# sourceMappingURL=semantic-shifts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"semantic-shifts.js","sourceRoot":"","sources":["../../src/tools/semantic-shifts.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AASH,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,IAAI,EAAE,iBAAiB;IACvB,WAAW,EAAE,kIAAkI;IAC/I,WAAW,EAAE;QACX,IAAI,EAAE,QAAiB;QACvB,UAAU,EAAE;YACV,WAAW,EAAE;gBACX,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,sCAAsC;gBACnD,OAAO,EAAE,CAAC;aACX;YACD,aAAa,EAAE;gBACb,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,6CAA6C;gBAC1D,OAAO,EAAE,GAAG;aACb;SACF;KACF;CACF,CAAC;AAEF,MAAM,UAAU,qBAAqB,CACnC,EAAkB,EAClB,MAA4B;IAE5B,MAAM,KAAK,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC;IAC5B,MAAM,UAAU,GAAG,MAAM,CAAC,WAAW,IAAI,CAAC,CAAC;IAE3C,MAAM,IAAI,GAAG,KAAK;SACf,OAAO,CACN;;;;gCAI0B,CAC3B;SACA,GAAG,CAAC,UAAU,CAAU,CAAC;IAE5B,qCAAqC;IACrC,MAAM,OAAO,GAAG,IAAI,GAAG,EAAiB,CAAC;IACzC,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;QAChD,QAAQ,CAAC,IAAI,CAAC;YACZ,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC;YAC1B,UAAU,EAAE,GAAG,CAAC,UAAU;SAC3B,CAAC,CA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AAI,SAAS;KACpH,CAAC;AACJ,CAAC"}
@@ -0,0 +1,45 @@
1
+ /**
2
+ * signal_chains tool
3
+ *
4
+ * Get active signal chains - connected signals that form causal narratives over time.
5
+ */
6
+ import type { FourDADatabase } from "../db.js";
7
+ export interface SignalChainsParams {
8
+ resolution?: string;
9
+ min_priority?: string;
10
+ }
11
+ export declare const signalChainsTool: {
12
+ name: string;
13
+ description: string;
14
+ inputSchema: {
15
+ type: "object";
16
+ properties: {
17
+ resolution: {
18
+ type: string;
19
+ enum: string[];
20
+ description: string;
21
+ default: string;
22
+ };
23
+ min_priority: {
24
+ type: string;
25
+ enum: string[];
26
+ description: string;
27
+ default: string;
28
+ };
29
+ };
30
+ };
31
+ };
32
+ export declare function executeSignalChains(db: FourDADatabase, params: SignalChainsParams): {
33
+ chains: {
34
+ id: any;
35
+ chain_name: any;
36
+ links: any;
37
+ overall_priority: any;
38
+ resolution: any;
39
+ suggested_action: any;
40
+ created_at: any;
41
+ }[];
42
+ total: number;
43
+ summary: string;
44
+ };
45
+ //# sourceMappingURL=signal-chains.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signal-chains.d.ts","sourceRoot":"","sources":["../../src/tools/signal-chains.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE/C,MAAM,WAAW,kBAAkB;IACjC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;CAoB5B,CAAC;AAEF,wBAAgB,mBAAmB,CACjC,EAAE,EAAE,cAAc,EAClB,MAAM,EAAE,kBAAkB;;;;;;;;;;;;EAyC3B"}
@@ -0,0 +1,60 @@
1
+ /**
2
+ * signal_chains tool
3
+ *
4
+ * Get active signal chains - connected signals that form causal narratives over time.
5
+ */
6
+ export const signalChainsTool = {
7
+ name: "signal_chains",
8
+ description: `Get active signal chains - connected signals that form causal narratives over time. E.g., "CVE found Monday + your dep uses it Tuesday + patch released today = act now."`,
9
+ inputSchema: {
10
+ type: "object",
11
+ properties: {
12
+ resolution: {
13
+ type: "string",
14
+ enum: ["open", "resolved", "expired", "all"],
15
+ description: "Filter by chain resolution status. Default: open",
16
+ default: "open",
17
+ },
18
+ min_priority: {
19
+ type: "string",
20
+ enum: ["critical", "high", "medium", "low"],
21
+ description: "Minimum chain priority to include. Default: low",
22
+ default: "low",
23
+ },
24
+ },
25
+ },
26
+ };
27
+ export function executeSignalChains(db, params) {
28
+ const rawDb = db.getRawDb();
29
+ const resolution = params.resolution || "open";
30
+ let query = `SELECT id, event_type, subject, data, created_at
31
+ FROM temporal_events
32
+ WHERE event_type = 'signal_chain'`;
33
+ if (resolution !== "all") {
34
+ query += ` AND json_extract(data, '$.resolution') = '${resolution}'`;
35
+ }
36
+ query += " ORDER BY created_at DESC LIMIT 50";
37
+ const rows = rawDb.prepare(query).all();
38
+ const chains = rows.map((row) => {
39
+ const data = JSON.parse(row.data);
40
+ return {
41
+ id: row.id,
42
+ chain_name: data.chain_name || row.subject,
43
+ links: data.links || [],
44
+ overall_priority: data.overall_priority || "medium",
45
+ resolution: data.resolution || "open",
46
+ suggested_action: data.suggested_action || "",
47
+ created_at: row.created_at,
48
+ };
49
+ });
50
+ // Filter by priority
51
+ const priorityOrder = { critical: 4, high: 3, medium: 2, low: 1 };
52
+ const minLevel = priorityOrder[params.min_priority || "low"] || 1;
53
+ const filtered = chains.filter((c) => (priorityOrder[c.overall_priority] || 0) >= minLevel);
54
+ return {
55
+ chains: filtered,
56
+ total: filtered.length,
57
+ summary: `${filtered.length} signal chain${filtered.length !== 1 ? "s" : ""} (${resolution})`,
58
+ };
59
+ }
60
+ //# sourceMappingURL=signal-chains.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signal-chains.js","sourceRoot":"","sources":["../../src/tools/signal-chains.ts"],"names":[],"mappings":"AAAA;;;;GAI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AI,CAAC,KAAK,IAAI,EAAE;YACvB,gBAAgB,EAAE,IAAI,CAAC,gBAAgB,IAAI,QAAQ;YACnD,UAAU,EAAE,IAAI,CAAC,UAAU,IAAI,MAAM;YACrC,gBAAgB,EAAE,IAAI,CAAC,gBAAgB,IAAI,EAAE;YAC7C,UAAU,EAAE,GAAG,CAAC,UAAU;SAC3B,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,qBAAqB;IACrB,MAAM,aAAa,GAA2B,EAAE,QAAQ,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC;IAC1F,MAAM,QAAQ,GAAG,aAAa,CAAC,MAAM,CAAC,YAAY,IAAI,KAAK,CAAC,IAAI,CAAC,CAAC;IAClE,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAC5B,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,IAAI,QAAQ,CAC5D,CAAC;IAEF,OAAO;QACL,MAAM,EAAE,QAAQ;QAChB,KAAK,EAAE,QAAQ,CAAC,MAAM;QACtB,OAAO,EAAE,GAAG,QAAQ,CAAC,MAAM,gBAAgB,QAAQ,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,KAAK,UAAU,GAAG;KAC9F,CAAC;AACJ,CAAC"}
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Source Health Tool
3
+ *
4
+ * Diagnose source fetching, parsing, and data flow issues.
5
+ * This is a SUPERPOWER - it reveals pipeline problems before they become mysteries.
6
+ */
7
+ import type { FourDADatabase } from "../db.js";
8
+ export declare const sourceHealthTool: {
9
+ name: string;
10
+ description: string;
11
+ inputSchema: {
12
+ type: string;
13
+ properties: {
14
+ source: {
15
+ type: string;
16
+ description: string;
17
+ };
18
+ hours: {
19
+ type: string;
20
+ description: string;
21
+ };
22
+ };
23
+ };
24
+ };
25
+ export interface SourceHealthParams {
26
+ source?: string;
27
+ hours?: number;
28
+ }
29
+ interface SourceStatus {
30
+ source: string;
31
+ status: "healthy" | "degraded" | "failing" | "unknown";
32
+ last_item_at: string | null;
33
+ hours_since_last: number | null;
34
+ items_24h: number;
35
+ items_7d: number;
36
+ avg_items_per_day: number;
37
+ quality_metrics: {
38
+ has_url_rate: number;
39
+ has_content_rate: number;
40
+ avg_content_length: number;
41
+ };
42
+ issues: string[];
43
+ recommendations: string[];
44
+ }
45
+ interface SourceHealthResult {
46
+ analysis_period: {
47
+ start: string;
48
+ end: string;
49
+ hours: number;
50
+ };
51
+ overall_status: "healthy" | "degraded" | "critical";
52
+ sources: SourceStatus[];
53
+ summary: {
54
+ total_sources: number;
55
+ healthy: number;
56
+ degraded: number;
57
+ failing: number;
58
+ total_items_24h: number;
59
+ };
60
+ global_recommendations: string[];
61
+ }
62
+ export declare function executeSourceHealth(db: FourDADatabase, params: SourceHealthParams): SourceHealthResult;
63
+ export {};
64
+ //# sourceMappingURL=source-health.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"source-health.d.ts","sourceRoot":"","sources":["../../src/tools/source-health.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE/C,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;CAwB5B,CAAC;AAEF,MAAM,WAAW,kBAAkB;IACjC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,UAAU,YAAY;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,SAAS,GAAG,UAAU,GAAG,SAAS,GAAG,SAAS,CAAC;IACvD,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,SAAS,EAAE,MAAM,CAAC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