tachibot-mcp 2.0.2

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 (214) hide show
  1. package/.env.example +260 -0
  2. package/CHANGELOG.md +54 -0
  3. package/CODE_OF_CONDUCT.md +56 -0
  4. package/CONTRIBUTING.md +54 -0
  5. package/Dockerfile +36 -0
  6. package/LICENSE +644 -0
  7. package/README.md +201 -0
  8. package/SECURITY.md +95 -0
  9. package/dist/personality/komaai-expressions.js +12 -0
  10. package/dist/profiles/balanced.json +33 -0
  11. package/dist/profiles/code_focus.json +33 -0
  12. package/dist/profiles/full.json +33 -0
  13. package/dist/profiles/minimal.json +33 -0
  14. package/dist/profiles/research_power.json +33 -0
  15. package/dist/scripts/build-profiles.js +46 -0
  16. package/dist/src/application/services/focus/FocusModeRegistry.js +46 -0
  17. package/dist/src/application/services/focus/FocusTool.service.js +109 -0
  18. package/dist/src/application/services/focus/ModeRegistry.js +46 -0
  19. package/dist/src/application/services/focus/modes/focus-deep.mode.js +27 -0
  20. package/dist/src/application/services/focus/modes/status.mode.js +50 -0
  21. package/dist/src/application/services/focus/modes/tachibot-status.mode.js +50 -0
  22. package/dist/src/collaborative-orchestrator.js +391 -0
  23. package/dist/src/config/model-constants.js +188 -0
  24. package/dist/src/config/model-defaults.js +57 -0
  25. package/dist/src/config/model-preferences.js +382 -0
  26. package/dist/src/config/timeout-config.js +130 -0
  27. package/dist/src/config.js +173 -0
  28. package/dist/src/domain/interfaces/IFocusMode.js +5 -0
  29. package/dist/src/domain/interfaces/IProvider.js +6 -0
  30. package/dist/src/domain/interfaces/ITool.js +5 -0
  31. package/dist/src/focus-deep.js +245 -0
  32. package/dist/src/infrastructure/ascii/art/robots.ascii.js +16 -0
  33. package/dist/src/mcp-client.js +90 -0
  34. package/dist/src/memory/index.js +17 -0
  35. package/dist/src/memory/memory-config.js +135 -0
  36. package/dist/src/memory/memory-interface.js +174 -0
  37. package/dist/src/memory/memory-manager.js +383 -0
  38. package/dist/src/memory/providers/devlog-provider.js +385 -0
  39. package/dist/src/memory/providers/hybrid-provider.js +399 -0
  40. package/dist/src/memory/providers/local-provider.js +388 -0
  41. package/dist/src/memory/providers/mem0-provider.js +337 -0
  42. package/dist/src/modes/architect.js +477 -0
  43. package/dist/src/modes/auditor.js +362 -0
  44. package/dist/src/modes/challenger.js +841 -0
  45. package/dist/src/modes/code-reviewer.js +382 -0
  46. package/dist/src/modes/commit-guardian.js +424 -0
  47. package/dist/src/modes/documentation-writer.js +572 -0
  48. package/dist/src/modes/scout.js +587 -0
  49. package/dist/src/modes/shared/helpers/challenger-helpers.js +454 -0
  50. package/dist/src/modes/shared/helpers/index.js +17 -0
  51. package/dist/src/modes/shared/helpers/scout-helpers.js +270 -0
  52. package/dist/src/modes/shared/helpers/verifier-helpers.js +332 -0
  53. package/dist/src/modes/test-architect.js +767 -0
  54. package/dist/src/modes/verifier.js +378 -0
  55. package/dist/src/monitoring/performance-monitor.js +435 -0
  56. package/dist/src/optimization/batch-executor.js +121 -0
  57. package/dist/src/optimization/context-pruner.js +196 -0
  58. package/dist/src/optimization/cost-monitor.js +338 -0
  59. package/dist/src/optimization/index.js +65 -0
  60. package/dist/src/optimization/model-router.js +264 -0
  61. package/dist/src/optimization/result-cache.js +114 -0
  62. package/dist/src/optimization/token-optimizer.js +257 -0
  63. package/dist/src/optimization/token-tracker.js +118 -0
  64. package/dist/src/orchestrator-instructions.js +128 -0
  65. package/dist/src/orchestrator-lite.js +139 -0
  66. package/dist/src/orchestrator.js +191 -0
  67. package/dist/src/orchestrators/collaborative/interfaces/IToolExecutionEngine.js +1 -0
  68. package/dist/src/orchestrators/collaborative/interfaces/IToolExecutionStrategy.js +5 -0
  69. package/dist/src/orchestrators/collaborative/interfaces/IVisualizationRenderer.js +1 -0
  70. package/dist/src/orchestrators/collaborative/registries/ModelProviderRegistry.js +95 -0
  71. package/dist/src/orchestrators/collaborative/registries/ToolAdapterRegistry.js +64 -0
  72. package/dist/src/orchestrators/collaborative/services/tool-execution/ToolExecutionService.js +502 -0
  73. package/dist/src/orchestrators/collaborative/services/visualization/VisualizationService.js +206 -0
  74. package/dist/src/orchestrators/collaborative/types/session-types.js +5 -0
  75. package/dist/src/profiles/balanced.js +37 -0
  76. package/dist/src/profiles/code_focus.js +37 -0
  77. package/dist/src/profiles/debug_intensive.js +59 -0
  78. package/dist/src/profiles/full.js +37 -0
  79. package/dist/src/profiles/minimal.js +37 -0
  80. package/dist/src/profiles/research_code.js +59 -0
  81. package/dist/src/profiles/research_power.js +37 -0
  82. package/dist/src/profiles/types.js +5 -0
  83. package/dist/src/profiles/workflow_builder.js +53 -0
  84. package/dist/src/prompt-engineer-lite.js +78 -0
  85. package/dist/src/prompt-engineer.js +399 -0
  86. package/dist/src/reasoning-chain.js +508 -0
  87. package/dist/src/sequential-thinking.js +291 -0
  88. package/dist/src/server-diagnostic.js +74 -0
  89. package/dist/src/server-raw.js +158 -0
  90. package/dist/src/server-simple.js +58 -0
  91. package/dist/src/server.js +514 -0
  92. package/dist/src/session/session-logger.js +617 -0
  93. package/dist/src/session/session-manager.js +571 -0
  94. package/dist/src/session/session-tools.js +400 -0
  95. package/dist/src/tools/advanced-modes.js +200 -0
  96. package/dist/src/tools/claude-integration.js +356 -0
  97. package/dist/src/tools/consolidated/ai-router.js +174 -0
  98. package/dist/src/tools/consolidated/ai-tool.js +48 -0
  99. package/dist/src/tools/consolidated/brainstorm-tool.js +87 -0
  100. package/dist/src/tools/consolidated/environment-detector.js +80 -0
  101. package/dist/src/tools/consolidated/index.js +50 -0
  102. package/dist/src/tools/consolidated/search-tool.js +110 -0
  103. package/dist/src/tools/consolidated/workflow-tool.js +238 -0
  104. package/dist/src/tools/gemini-tools.js +329 -0
  105. package/dist/src/tools/grok-enhanced.js +376 -0
  106. package/dist/src/tools/grok-tools.js +299 -0
  107. package/dist/src/tools/lmstudio-tools.js +223 -0
  108. package/dist/src/tools/openai-tools.js +498 -0
  109. package/dist/src/tools/openrouter-tools.js +317 -0
  110. package/dist/src/tools/optimized-wrapper.js +204 -0
  111. package/dist/src/tools/perplexity-tools.js +294 -0
  112. package/dist/src/tools/pingpong-tool.js +343 -0
  113. package/dist/src/tools/qwen-wrapper.js +74 -0
  114. package/dist/src/tools/tool-router.js +444 -0
  115. package/dist/src/tools/unified-ai-provider.js +260 -0
  116. package/dist/src/tools/workflow-runner.js +425 -0
  117. package/dist/src/tools/workflow-validator-tool.js +107 -0
  118. package/dist/src/types.js +23 -0
  119. package/dist/src/utils/input-validator.js +130 -0
  120. package/dist/src/utils/model-router.js +91 -0
  121. package/dist/src/utils/progress-stream.js +255 -0
  122. package/dist/src/utils/provider-router.js +88 -0
  123. package/dist/src/utils/smart-api-client.js +146 -0
  124. package/dist/src/utils/table-builder.js +218 -0
  125. package/dist/src/utils/timestamp-formatter.js +134 -0
  126. package/dist/src/utils/tool-compressor.js +257 -0
  127. package/dist/src/utils/tool-config.js +201 -0
  128. package/dist/src/validators/dependency-graph-validator.js +147 -0
  129. package/dist/src/validators/interpolation-validator.js +222 -0
  130. package/dist/src/validators/output-usage-validator.js +151 -0
  131. package/dist/src/validators/syntax-validator.js +102 -0
  132. package/dist/src/validators/tool-registry-validator.js +123 -0
  133. package/dist/src/validators/tool-types.js +97 -0
  134. package/dist/src/validators/types.js +8 -0
  135. package/dist/src/validators/workflow-validator.js +134 -0
  136. package/dist/src/visualizer-lite.js +42 -0
  137. package/dist/src/visualizer.js +179 -0
  138. package/dist/src/workflows/circuit-breaker.js +199 -0
  139. package/dist/src/workflows/custom-workflows.js +451 -0
  140. package/dist/src/workflows/engine/AutoSynthesizer.js +97 -0
  141. package/dist/src/workflows/engine/StepParameterResolver.js +74 -0
  142. package/dist/src/workflows/engine/VariableInterpolator.js +123 -0
  143. package/dist/src/workflows/engine/WorkflowDiscovery.js +125 -0
  144. package/dist/src/workflows/engine/WorkflowExecutionEngine.js +485 -0
  145. package/dist/src/workflows/engine/WorkflowExecutor.js +113 -0
  146. package/dist/src/workflows/engine/WorkflowFileManager.js +244 -0
  147. package/dist/src/workflows/engine/WorkflowHelpers.js +114 -0
  148. package/dist/src/workflows/engine/WorkflowOutputFormatter.js +83 -0
  149. package/dist/src/workflows/engine/events/WorkflowEventBus.js +132 -0
  150. package/dist/src/workflows/engine/events/interfaces/IEventBus.js +5 -0
  151. package/dist/src/workflows/engine/handlers/ErrorRecoveryHandler.js +162 -0
  152. package/dist/src/workflows/engine/handlers/PromptEnhancementHandler.js +115 -0
  153. package/dist/src/workflows/engine/handlers/SessionPersistenceHandler.js +167 -0
  154. package/dist/src/workflows/engine/handlers/StepExecutionHandler.js +231 -0
  155. package/dist/src/workflows/engine/handlers/ToolInvocationHandler.js +46 -0
  156. package/dist/src/workflows/engine/interfaces/IAutoSynthesizer.js +5 -0
  157. package/dist/src/workflows/engine/interfaces/IStepParameterResolver.js +5 -0
  158. package/dist/src/workflows/engine/interfaces/IVariableInterpolator.js +5 -0
  159. package/dist/src/workflows/engine/interfaces/IWorkflowDiscovery.js +4 -0
  160. package/dist/src/workflows/engine/interfaces/IWorkflowFileManager.js +5 -0
  161. package/dist/src/workflows/engine/interfaces/IWorkflowOutputFormatter.js +5 -0
  162. package/dist/src/workflows/engine/state/WorkflowStateMachine.js +194 -0
  163. package/dist/src/workflows/engine/state/interfaces/IStateMachine.js +17 -0
  164. package/dist/src/workflows/fallback-strategies.js +373 -0
  165. package/dist/src/workflows/message-queue.js +455 -0
  166. package/dist/src/workflows/model-router.js +189 -0
  167. package/dist/src/workflows/orchestrator-examples.js +174 -0
  168. package/dist/src/workflows/orchestrator-integration.js +200 -0
  169. package/dist/src/workflows/self-healing.js +524 -0
  170. package/dist/src/workflows/tool-mapper.js +407 -0
  171. package/dist/src/workflows/tool-orchestrator.js +796 -0
  172. package/dist/src/workflows/workflow-engine.js +573 -0
  173. package/dist/src/workflows/workflow-parser.js +283 -0
  174. package/dist/src/workflows/workflow-types.js +95 -0
  175. package/dist/src/workflows.js +568 -0
  176. package/dist/test-workflow-file-output.js +93 -0
  177. package/docs/API_KEYS.md +570 -0
  178. package/docs/CLAUDE_CODE_SETUP.md +181 -0
  179. package/docs/CLAUDE_DESKTOP_MANUAL.md +127 -0
  180. package/docs/CONFIGURATION.md +745 -0
  181. package/docs/FOCUS_MODES.md +240 -0
  182. package/docs/INSTALLATION_BOTH.md +145 -0
  183. package/docs/TERMS.md +352 -0
  184. package/docs/TOOLS_REFERENCE.md +1622 -0
  185. package/docs/TOOL_PARAMETERS.md +496 -0
  186. package/docs/TOOL_PROFILES.md +236 -0
  187. package/docs/WORKFLOWS.md +987 -0
  188. package/docs/WORKFLOW_OUTPUT.md +198 -0
  189. package/docs/WORKFLOW_PROGRESS_TRACKING.md +305 -0
  190. package/docs/workflows/design-brainstorm.md +335 -0
  191. package/package.json +97 -0
  192. package/profiles/balanced.json +37 -0
  193. package/profiles/code_focus.json +37 -0
  194. package/profiles/debug_intensive.json +34 -0
  195. package/profiles/full.json +37 -0
  196. package/profiles/minimal.json +37 -0
  197. package/profiles/research_power.json +37 -0
  198. package/profiles/workflow_builder.json +37 -0
  199. package/smithery.yaml +66 -0
  200. package/start.sh +8 -0
  201. package/tools.config.json +81 -0
  202. package/tsconfig.json +18 -0
  203. package/workflows/accessibility-code-audit.yaml +92 -0
  204. package/workflows/code-architecture-review.yaml +202 -0
  205. package/workflows/code-review.yaml +142 -0
  206. package/workflows/core/iterative-problem-solver.yaml +283 -0
  207. package/workflows/creative-brainstorm-yaml.yaml +215 -0
  208. package/workflows/pingpong.yaml +141 -0
  209. package/workflows/system/README.md +412 -0
  210. package/workflows/system/challenger.yaml +175 -0
  211. package/workflows/system/scout.yaml +164 -0
  212. package/workflows/system/verifier.yaml +133 -0
  213. package/workflows/ultra-creative-brainstorm.yaml +318 -0
  214. package/workflows/ux-research-flow.yaml +92 -0
@@ -0,0 +1,362 @@
1
+ export class Auditor {
2
+ constructor() {
3
+ this.defaultModel = 'perplexity-sonar-pro';
4
+ this.defaultMaxTokens = 5000;
5
+ }
6
+ async audit(context, options = {}) {
7
+ const model = options.model || this.defaultModel;
8
+ const maxTokens = options.maxTokens || this.defaultMaxTokens;
9
+ const evidenceRequired = options.evidenceRequired !== false;
10
+ // Extract claims from context
11
+ const claims = await this.extractClaims(context, maxTokens * 0.2);
12
+ // Gather evidence
13
+ const evidence = await this.gatherEvidence(claims, model, maxTokens * 0.4, evidenceRequired);
14
+ // Identify assumptions
15
+ const assumptions = this.identifyAssumptions(claims, evidence);
16
+ // Find information gaps
17
+ const gaps = this.findInformationGaps(claims, evidence, assumptions);
18
+ // Verify claims with evidence
19
+ const auditedClaims = await this.verifyClaims(claims, evidence, model, maxTokens * 0.3);
20
+ // Calculate verification status
21
+ const verificationStatus = this.calculateVerificationStatus(auditedClaims);
22
+ // Generate synthesis
23
+ const synthesis = await this.generateSynthesis(auditedClaims, evidence, assumptions, gaps, verificationStatus, maxTokens * 0.1);
24
+ return {
25
+ claims: auditedClaims,
26
+ evidence,
27
+ assumptions,
28
+ gaps,
29
+ verificationStatus,
30
+ synthesis
31
+ };
32
+ }
33
+ async extractClaims(context, maxTokens) {
34
+ const text = this.contextToText(context);
35
+ const claims = [];
36
+ // Parse context for statements that need verification
37
+ const statements = this.parseStatements(text);
38
+ for (let i = 0; i < statements.length; i++) {
39
+ const statement = statements[i];
40
+ const type = this.classifyStatement(statement);
41
+ claims.push({
42
+ id: `claim-${i}`,
43
+ statement,
44
+ type,
45
+ verificationStatus: 'unverified',
46
+ confidence: 0,
47
+ evidence: []
48
+ });
49
+ }
50
+ return claims;
51
+ }
52
+ parseStatements(text) {
53
+ // Extract meaningful statements
54
+ const sentences = text.split(/[.!?]+/).filter(s => s.trim().length > 20);
55
+ // Filter for statements that make claims
56
+ return sentences.filter(s => {
57
+ const lower = s.toLowerCase();
58
+ return (lower.includes('is') ||
59
+ lower.includes('will') ||
60
+ lower.includes('should') ||
61
+ lower.includes('must') ||
62
+ lower.includes('always') ||
63
+ lower.includes('never') ||
64
+ lower.includes('because') ||
65
+ lower.includes('therefore'));
66
+ });
67
+ }
68
+ classifyStatement(statement) {
69
+ const lower = statement.toLowerCase();
70
+ if (lower.includes('assume') || lower.includes('probably') || lower.includes('likely')) {
71
+ return 'assumption';
72
+ }
73
+ if (lower.includes('believe') || lower.includes('think') || lower.includes('feel')) {
74
+ return 'opinion';
75
+ }
76
+ if (lower.includes('therefore') || lower.includes('thus') || lower.includes('so')) {
77
+ return 'conclusion';
78
+ }
79
+ return 'fact';
80
+ }
81
+ async gatherEvidence(claims, model, maxTokens, required) {
82
+ const evidence = [];
83
+ if (!required) {
84
+ return evidence;
85
+ }
86
+ // Query for evidence using Perplexity for web search
87
+ const searchPrompt = this.buildEvidenceSearchPrompt(claims);
88
+ const searchResults = await this.searchForEvidence(model, searchPrompt, maxTokens);
89
+ // Parse search results into evidence
90
+ const parsedEvidence = this.parseSearchResults(searchResults, claims);
91
+ evidence.push(...parsedEvidence);
92
+ // Look for code-based evidence
93
+ const codeEvidence = await this.findCodeEvidence(claims);
94
+ evidence.push(...codeEvidence);
95
+ // Check documentation
96
+ const docEvidence = await this.findDocumentationEvidence(claims);
97
+ evidence.push(...docEvidence);
98
+ return evidence;
99
+ }
100
+ buildEvidenceSearchPrompt(claims) {
101
+ let prompt = 'Find evidence to verify or refute the following claims:\n\n';
102
+ claims.slice(0, 5).forEach(claim => {
103
+ prompt += `- ${claim.statement}\n`;
104
+ });
105
+ prompt += '\nProvide specific facts, citations, and sources.';
106
+ return prompt;
107
+ }
108
+ async searchForEvidence(model, prompt, maxTokens) {
109
+ // Simulated search - would use actual Perplexity API
110
+ return {
111
+ results: [
112
+ {
113
+ claim: 'claim-0',
114
+ evidence: 'According to documentation...',
115
+ source: 'https://docs.example.com',
116
+ confidence: 0.8
117
+ }
118
+ ]
119
+ };
120
+ }
121
+ parseSearchResults(results, claims) {
122
+ const evidence = [];
123
+ if (results.results) {
124
+ results.results.forEach((result, index) => {
125
+ evidence.push({
126
+ id: `evidence-web-${index}`,
127
+ source: result.source || 'web search',
128
+ type: 'external',
129
+ content: result.evidence || result.content || '',
130
+ reliability: result.confidence || 0.5,
131
+ supportsClaims: [result.claim]
132
+ });
133
+ });
134
+ }
135
+ return evidence;
136
+ }
137
+ async findCodeEvidence(claims) {
138
+ const evidence = [];
139
+ // Simulated code evidence finding
140
+ evidence.push({
141
+ id: 'evidence-code-1',
142
+ source: 'src/auth/validator.ts:45',
143
+ type: 'code',
144
+ content: 'if (!token || token.expired) { throw new Error("Invalid token"); }',
145
+ reliability: 0.9,
146
+ supportsClaims: ['claim-0']
147
+ });
148
+ return evidence;
149
+ }
150
+ async findDocumentationEvidence(claims) {
151
+ const evidence = [];
152
+ // Simulated documentation evidence
153
+ evidence.push({
154
+ id: 'evidence-doc-1',
155
+ source: 'README.md',
156
+ type: 'documentation',
157
+ content: 'The system uses JWT tokens for authentication',
158
+ reliability: 0.7,
159
+ supportsClaims: ['claim-1']
160
+ });
161
+ return evidence;
162
+ }
163
+ identifyAssumptions(claims, evidence) {
164
+ const assumptions = [];
165
+ // Find claims without sufficient evidence
166
+ for (const claim of claims) {
167
+ if (claim.type === 'assumption' || claim.evidence.length === 0) {
168
+ const supportingEvidence = evidence.filter(e => e.supportsClaims.includes(claim.id));
169
+ if (supportingEvidence.length === 0) {
170
+ assumptions.push({
171
+ id: `assumption-${assumptions.length}`,
172
+ description: claim.statement,
173
+ risk: this.assessAssumptionRisk(claim),
174
+ needsValidation: true,
175
+ validationMethod: this.suggestValidationMethod(claim),
176
+ impact: this.assessImpact(claim)
177
+ });
178
+ }
179
+ }
180
+ }
181
+ return assumptions;
182
+ }
183
+ assessAssumptionRisk(claim) {
184
+ const criticalKeywords = ['security', 'authentication', 'payment', 'critical'];
185
+ const statement = claim.statement.toLowerCase();
186
+ if (criticalKeywords.some(keyword => statement.includes(keyword))) {
187
+ return 'high';
188
+ }
189
+ if (claim.type === 'conclusion') {
190
+ return 'medium';
191
+ }
192
+ return 'low';
193
+ }
194
+ suggestValidationMethod(claim) {
195
+ if (claim.statement.includes('performance')) {
196
+ return 'Performance testing and benchmarking';
197
+ }
198
+ if (claim.statement.includes('security')) {
199
+ return 'Security audit and penetration testing';
200
+ }
201
+ if (claim.statement.includes('user')) {
202
+ return 'User testing and feedback collection';
203
+ }
204
+ return 'Empirical testing and measurement';
205
+ }
206
+ assessImpact(claim) {
207
+ if (claim.type === 'conclusion') {
208
+ return 'High - affects decision making';
209
+ }
210
+ if (claim.type === 'assumption') {
211
+ return 'Medium - may affect implementation';
212
+ }
213
+ return 'Low - informational';
214
+ }
215
+ findInformationGaps(claims, evidence, assumptions) {
216
+ const gaps = [];
217
+ // Check for claims without evidence
218
+ const unverifiedClaims = claims.filter(c => c.evidence.length === 0);
219
+ if (unverifiedClaims.length > 0) {
220
+ gaps.push({
221
+ area: 'Evidence Coverage',
222
+ description: `${unverifiedClaims.length} claims lack supporting evidence`,
223
+ severity: unverifiedClaims.some(c => c.type === 'fact') ? 'critical' : 'moderate',
224
+ suggestedAction: 'Gather additional evidence through testing or documentation',
225
+ requiredEvidence: unverifiedClaims.map(c => c.statement)
226
+ });
227
+ }
228
+ // Check for high-risk assumptions
229
+ const highRiskAssumptions = assumptions.filter(a => a.risk === 'high');
230
+ if (highRiskAssumptions.length > 0) {
231
+ gaps.push({
232
+ area: 'Critical Assumptions',
233
+ description: `${highRiskAssumptions.length} high-risk assumptions need validation`,
234
+ severity: 'critical',
235
+ suggestedAction: 'Validate assumptions through testing or expert review',
236
+ requiredEvidence: highRiskAssumptions.map(a => a.validationMethod || '')
237
+ });
238
+ }
239
+ // Check for contradictory evidence
240
+ const contradictions = evidence.filter(e => e.contradictsClaims && e.contradictsClaims.length > 0);
241
+ if (contradictions.length > 0) {
242
+ gaps.push({
243
+ area: 'Contradictory Information',
244
+ description: 'Found conflicting evidence that needs resolution',
245
+ severity: 'moderate',
246
+ suggestedAction: 'Investigate and resolve contradictions',
247
+ requiredEvidence: ['Additional verification', 'Expert consultation']
248
+ });
249
+ }
250
+ return gaps;
251
+ }
252
+ async verifyClaims(claims, evidence, model, maxTokens) {
253
+ const auditedClaims = [];
254
+ for (const claim of claims) {
255
+ const supportingEvidence = evidence.filter(e => e.supportsClaims.includes(claim.id));
256
+ const contradictingEvidence = evidence.filter(e => e.contradictsClaims?.includes(claim.id));
257
+ let status;
258
+ let confidence;
259
+ if (contradictingEvidence.length > 0) {
260
+ status = 'disputed';
261
+ confidence = 0.3;
262
+ }
263
+ else if (supportingEvidence.length >= 2) {
264
+ status = 'verified';
265
+ confidence = Math.min(0.9, supportingEvidence.reduce((sum, e) => sum + e.reliability, 0) / supportingEvidence.length);
266
+ }
267
+ else if (supportingEvidence.length === 1) {
268
+ status = 'unverified';
269
+ confidence = supportingEvidence[0].reliability * 0.7;
270
+ }
271
+ else {
272
+ status = 'insufficient_evidence';
273
+ confidence = 0.1;
274
+ }
275
+ auditedClaims.push({
276
+ ...claim,
277
+ verificationStatus: status,
278
+ confidence,
279
+ evidence: supportingEvidence.map(e => e.id),
280
+ contradictions: contradictingEvidence.length > 0 ?
281
+ contradictingEvidence.map(e => e.id) : undefined
282
+ });
283
+ }
284
+ return auditedClaims;
285
+ }
286
+ calculateVerificationStatus(claims) {
287
+ const total = claims.length;
288
+ const verified = claims.filter(c => c.verificationStatus === 'verified').length;
289
+ const unverified = claims.filter(c => c.verificationStatus === 'unverified').length;
290
+ const disputed = claims.filter(c => c.verificationStatus === 'disputed').length;
291
+ const avgConfidence = claims.reduce((sum, c) => sum + c.confidence, 0) / total;
292
+ const completeness = (verified + unverified * 0.5) / total;
293
+ return {
294
+ totalClaims: total,
295
+ verified,
296
+ unverified,
297
+ disputed,
298
+ confidenceScore: avgConfidence,
299
+ completeness
300
+ };
301
+ }
302
+ async generateSynthesis(claims, evidence, assumptions, gaps, status, maxTokens) {
303
+ let synthesis = `## Audit Summary\n\n`;
304
+ synthesis += `### Verification Status\n`;
305
+ synthesis += `- **Total Claims**: ${status.totalClaims}\n`;
306
+ synthesis += `- **Verified**: ${status.verified} (${(status.verified / status.totalClaims * 100).toFixed(1)}%)\n`;
307
+ synthesis += `- **Disputed**: ${status.disputed}\n`;
308
+ synthesis += `- **Confidence Score**: ${(status.confidenceScore * 100).toFixed(1)}%\n\n`;
309
+ synthesis += `### Key Findings\n`;
310
+ // Highlight verified facts
311
+ const verifiedFacts = claims.filter(c => c.verificationStatus === 'verified' && c.type === 'fact');
312
+ if (verifiedFacts.length > 0) {
313
+ synthesis += `**Verified Facts**:\n`;
314
+ verifiedFacts.slice(0, 3).forEach(fact => {
315
+ synthesis += `✓ ${fact.statement}\n`;
316
+ });
317
+ synthesis += '\n';
318
+ }
319
+ // Highlight disputed claims
320
+ const disputed = claims.filter(c => c.verificationStatus === 'disputed');
321
+ if (disputed.length > 0) {
322
+ synthesis += `**Disputed Claims** ⚠️:\n`;
323
+ disputed.forEach(claim => {
324
+ synthesis += `✗ ${claim.statement}\n`;
325
+ });
326
+ synthesis += '\n';
327
+ }
328
+ // Critical assumptions
329
+ const criticalAssumptions = assumptions.filter(a => a.risk === 'high');
330
+ if (criticalAssumptions.length > 0) {
331
+ synthesis += `**Critical Assumptions** 🔴:\n`;
332
+ criticalAssumptions.forEach(assumption => {
333
+ synthesis += `- ${assumption.description}\n`;
334
+ synthesis += ` Validation: ${assumption.validationMethod}\n`;
335
+ });
336
+ synthesis += '\n';
337
+ }
338
+ // Information gaps
339
+ if (gaps.length > 0) {
340
+ synthesis += `### Information Gaps\n`;
341
+ gaps.forEach(gap => {
342
+ synthesis += `- **${gap.area}** (${gap.severity}): ${gap.description}\n`;
343
+ synthesis += ` Action: ${gap.suggestedAction}\n`;
344
+ });
345
+ }
346
+ return synthesis;
347
+ }
348
+ contextToText(context) {
349
+ if (typeof context === 'string')
350
+ return context;
351
+ if (context && typeof context === 'object') {
352
+ if (context.query)
353
+ return context.query;
354
+ if (context.text)
355
+ return context.text;
356
+ if (context.content)
357
+ return context.content;
358
+ return JSON.stringify(context);
359
+ }
360
+ return '';
361
+ }
362
+ }