@cogitator-ai/core 0.3.0 → 0.5.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 (169) hide show
  1. package/README.md +117 -0
  2. package/dist/causal/capabilities/causal-explainer.d.ts +33 -0
  3. package/dist/causal/capabilities/causal-explainer.d.ts.map +1 -0
  4. package/dist/causal/capabilities/causal-explainer.js +334 -0
  5. package/dist/causal/capabilities/causal-explainer.js.map +1 -0
  6. package/dist/causal/capabilities/causal-planner.d.ts +42 -0
  7. package/dist/causal/capabilities/causal-planner.d.ts.map +1 -0
  8. package/dist/causal/capabilities/causal-planner.js +291 -0
  9. package/dist/causal/capabilities/causal-planner.js.map +1 -0
  10. package/dist/causal/capabilities/effect-predictor.d.ts +30 -0
  11. package/dist/causal/capabilities/effect-predictor.d.ts.map +1 -0
  12. package/dist/causal/capabilities/effect-predictor.js +266 -0
  13. package/dist/causal/capabilities/effect-predictor.js.map +1 -0
  14. package/dist/causal/causal-reasoner.d.ts +63 -0
  15. package/dist/causal/causal-reasoner.d.ts.map +1 -0
  16. package/dist/causal/causal-reasoner.js +328 -0
  17. package/dist/causal/causal-reasoner.js.map +1 -0
  18. package/dist/causal/discovery/causal-extractor.d.ts +46 -0
  19. package/dist/causal/discovery/causal-extractor.d.ts.map +1 -0
  20. package/dist/causal/discovery/causal-extractor.js +154 -0
  21. package/dist/causal/discovery/causal-extractor.js.map +1 -0
  22. package/dist/causal/discovery/causal-validator.d.ts +50 -0
  23. package/dist/causal/discovery/causal-validator.d.ts.map +1 -0
  24. package/dist/causal/discovery/causal-validator.js +237 -0
  25. package/dist/causal/discovery/causal-validator.js.map +1 -0
  26. package/dist/causal/discovery/hypothesis-generator.d.ts +37 -0
  27. package/dist/causal/discovery/hypothesis-generator.d.ts.map +1 -0
  28. package/dist/causal/discovery/hypothesis-generator.js +228 -0
  29. package/dist/causal/discovery/hypothesis-generator.js.map +1 -0
  30. package/dist/causal/discovery/prompts.d.ts +99 -0
  31. package/dist/causal/discovery/prompts.d.ts.map +1 -0
  32. package/dist/causal/discovery/prompts.js +265 -0
  33. package/dist/causal/discovery/prompts.js.map +1 -0
  34. package/dist/causal/graph/causal-graph.d.ts +38 -0
  35. package/dist/causal/graph/causal-graph.d.ts.map +1 -0
  36. package/dist/causal/graph/causal-graph.js +321 -0
  37. package/dist/causal/graph/causal-graph.js.map +1 -0
  38. package/dist/causal/graph/graph-builder.d.ts +68 -0
  39. package/dist/causal/graph/graph-builder.d.ts.map +1 -0
  40. package/dist/causal/graph/graph-builder.js +128 -0
  41. package/dist/causal/graph/graph-builder.js.map +1 -0
  42. package/dist/causal/index.d.ts +28 -0
  43. package/dist/causal/index.d.ts.map +1 -0
  44. package/dist/causal/index.js +18 -0
  45. package/dist/causal/index.js.map +1 -0
  46. package/dist/causal/inference/adjustment.d.ts +5 -0
  47. package/dist/causal/inference/adjustment.d.ts.map +1 -0
  48. package/dist/causal/inference/adjustment.js +188 -0
  49. package/dist/causal/inference/adjustment.js.map +1 -0
  50. package/dist/causal/inference/counterfactual.d.ts +24 -0
  51. package/dist/causal/inference/counterfactual.d.ts.map +1 -0
  52. package/dist/causal/inference/counterfactual.js +198 -0
  53. package/dist/causal/inference/counterfactual.js.map +1 -0
  54. package/dist/causal/inference/d-separation.d.ts +4 -0
  55. package/dist/causal/inference/d-separation.d.ts.map +1 -0
  56. package/dist/causal/inference/d-separation.js +168 -0
  57. package/dist/causal/inference/d-separation.js.map +1 -0
  58. package/dist/causal/inference/inference-engine.d.ts +33 -0
  59. package/dist/causal/inference/inference-engine.d.ts.map +1 -0
  60. package/dist/causal/inference/inference-engine.js +252 -0
  61. package/dist/causal/inference/inference-engine.js.map +1 -0
  62. package/dist/causal/stores/causal-graph-store.d.ts +12 -0
  63. package/dist/causal/stores/causal-graph-store.d.ts.map +1 -0
  64. package/dist/causal/stores/causal-graph-store.js +60 -0
  65. package/dist/causal/stores/causal-graph-store.js.map +1 -0
  66. package/dist/causal/stores/causal-pattern-store.d.ts +19 -0
  67. package/dist/causal/stores/causal-pattern-store.d.ts.map +1 -0
  68. package/dist/causal/stores/causal-pattern-store.js +117 -0
  69. package/dist/causal/stores/causal-pattern-store.js.map +1 -0
  70. package/dist/causal/stores/intervention-log.d.ts +16 -0
  71. package/dist/causal/stores/intervention-log.d.ts.map +1 -0
  72. package/dist/causal/stores/intervention-log.js +113 -0
  73. package/dist/causal/stores/intervention-log.js.map +1 -0
  74. package/dist/cogitator.d.ts.map +1 -1
  75. package/dist/cogitator.js +10 -5
  76. package/dist/cogitator.js.map +1 -1
  77. package/dist/index.d.ts +4 -0
  78. package/dist/index.d.ts.map +1 -1
  79. package/dist/index.js +2 -0
  80. package/dist/index.js.map +1 -1
  81. package/dist/learning/ab-testing.d.ts.map +1 -1
  82. package/dist/learning/ab-testing.js +6 -5
  83. package/dist/learning/ab-testing.js.map +1 -1
  84. package/dist/learning/auto-optimizer.d.ts.map +1 -1
  85. package/dist/learning/auto-optimizer.js +4 -2
  86. package/dist/learning/auto-optimizer.js.map +1 -1
  87. package/dist/learning/postgres-trace-store.d.ts.map +1 -1
  88. package/dist/learning/postgres-trace-store.js +15 -5
  89. package/dist/learning/postgres-trace-store.js.map +1 -1
  90. package/dist/learning/prompt-monitor.d.ts.map +1 -1
  91. package/dist/learning/prompt-monitor.js.map +1 -1
  92. package/dist/learning/rollback-manager.d.ts.map +1 -1
  93. package/dist/learning/rollback-manager.js.map +1 -1
  94. package/dist/llm/google.d.ts.map +1 -1
  95. package/dist/llm/google.js +5 -3
  96. package/dist/llm/google.js.map +1 -1
  97. package/package.json +5 -5
  98. package/dist/__tests__/agent.test.d.ts +0 -2
  99. package/dist/__tests__/agent.test.d.ts.map +0 -1
  100. package/dist/__tests__/agent.test.js +0 -91
  101. package/dist/__tests__/agent.test.js.map +0 -1
  102. package/dist/__tests__/base64.test.d.ts +0 -2
  103. package/dist/__tests__/base64.test.d.ts.map +0 -1
  104. package/dist/__tests__/base64.test.js +0 -62
  105. package/dist/__tests__/base64.test.js.map +0 -1
  106. package/dist/__tests__/calculator.test.d.ts +0 -2
  107. package/dist/__tests__/calculator.test.d.ts.map +0 -1
  108. package/dist/__tests__/calculator.test.js +0 -146
  109. package/dist/__tests__/calculator.test.js.map +0 -1
  110. package/dist/__tests__/cogitator-memory.test.d.ts +0 -2
  111. package/dist/__tests__/cogitator-memory.test.d.ts.map +0 -1
  112. package/dist/__tests__/cogitator-memory.test.js +0 -176
  113. package/dist/__tests__/cogitator-memory.test.js.map +0 -1
  114. package/dist/__tests__/datetime.test.d.ts +0 -2
  115. package/dist/__tests__/datetime.test.d.ts.map +0 -1
  116. package/dist/__tests__/datetime.test.js +0 -87
  117. package/dist/__tests__/datetime.test.js.map +0 -1
  118. package/dist/__tests__/exec.test.d.ts +0 -2
  119. package/dist/__tests__/exec.test.d.ts.map +0 -1
  120. package/dist/__tests__/exec.test.js +0 -59
  121. package/dist/__tests__/exec.test.js.map +0 -1
  122. package/dist/__tests__/filesystem.test.d.ts +0 -2
  123. package/dist/__tests__/filesystem.test.d.ts.map +0 -1
  124. package/dist/__tests__/filesystem.test.js +0 -148
  125. package/dist/__tests__/filesystem.test.js.map +0 -1
  126. package/dist/__tests__/google-backend.test.d.ts +0 -5
  127. package/dist/__tests__/google-backend.test.d.ts.map +0 -1
  128. package/dist/__tests__/google-backend.test.js +0 -429
  129. package/dist/__tests__/google-backend.test.js.map +0 -1
  130. package/dist/__tests__/hash.test.d.ts +0 -2
  131. package/dist/__tests__/hash.test.d.ts.map +0 -1
  132. package/dist/__tests__/hash.test.js +0 -50
  133. package/dist/__tests__/hash.test.js.map +0 -1
  134. package/dist/__tests__/http.test.d.ts +0 -2
  135. package/dist/__tests__/http.test.d.ts.map +0 -1
  136. package/dist/__tests__/http.test.js +0 -64
  137. package/dist/__tests__/http.test.js.map +0 -1
  138. package/dist/__tests__/json.test.d.ts +0 -2
  139. package/dist/__tests__/json.test.d.ts.map +0 -1
  140. package/dist/__tests__/json.test.js +0 -65
  141. package/dist/__tests__/json.test.js.map +0 -1
  142. package/dist/__tests__/logger.test.d.ts +0 -2
  143. package/dist/__tests__/logger.test.d.ts.map +0 -1
  144. package/dist/__tests__/logger.test.js +0 -186
  145. package/dist/__tests__/logger.test.js.map +0 -1
  146. package/dist/__tests__/random.test.d.ts +0 -2
  147. package/dist/__tests__/random.test.d.ts.map +0 -1
  148. package/dist/__tests__/random.test.js +0 -81
  149. package/dist/__tests__/random.test.js.map +0 -1
  150. package/dist/__tests__/regex.test.d.ts +0 -2
  151. package/dist/__tests__/regex.test.d.ts.map +0 -1
  152. package/dist/__tests__/regex.test.js +0 -75
  153. package/dist/__tests__/regex.test.js.map +0 -1
  154. package/dist/__tests__/registry.test.d.ts +0 -2
  155. package/dist/__tests__/registry.test.d.ts.map +0 -1
  156. package/dist/__tests__/registry.test.js +0 -102
  157. package/dist/__tests__/registry.test.js.map +0 -1
  158. package/dist/__tests__/sleep.test.d.ts +0 -2
  159. package/dist/__tests__/sleep.test.d.ts.map +0 -1
  160. package/dist/__tests__/sleep.test.js +0 -29
  161. package/dist/__tests__/sleep.test.js.map +0 -1
  162. package/dist/__tests__/tool.test.d.ts +0 -2
  163. package/dist/__tests__/tool.test.d.ts.map +0 -1
  164. package/dist/__tests__/tool.test.js +0 -103
  165. package/dist/__tests__/tool.test.js.map +0 -1
  166. package/dist/__tests__/uuid.test.d.ts +0 -2
  167. package/dist/__tests__/uuid.test.d.ts.map +0 -1
  168. package/dist/__tests__/uuid.test.js +0 -37
  169. package/dist/__tests__/uuid.test.js.map +0 -1
@@ -0,0 +1,99 @@
1
+ import type { CausalNode, CausalHypothesis, ExecutionTrace } from '@cogitator-ai/types';
2
+ export declare function buildCausalExtractionPrompt(source: string, existingNodes: CausalNode[], context?: {
3
+ taskDescription?: string;
4
+ recentActions?: string[];
5
+ }): string;
6
+ export declare function buildHypothesisGenerationPrompt(patterns: Array<{
7
+ trigger: string;
8
+ effect: string;
9
+ occurrences: number;
10
+ }>, traces: Array<{
11
+ id: string;
12
+ summary: string;
13
+ success: boolean;
14
+ }>, context: {
15
+ agentId: string;
16
+ goal?: string;
17
+ }): string;
18
+ export declare function buildCausalValidationPrompt(hypothesis: CausalHypothesis, originalTrace: {
19
+ id: string;
20
+ summary: string;
21
+ outcome: string;
22
+ }, forkTraces: Array<{
23
+ intervention: string;
24
+ outcome: string;
25
+ diffFromOriginal: string;
26
+ }>): string;
27
+ export declare function buildErrorCausalAnalysisPrompt(error: {
28
+ message: string;
29
+ stack?: string;
30
+ }, trace: ExecutionTrace, context: {
31
+ recentActions: string[];
32
+ systemState: Record<string, unknown>;
33
+ }): string;
34
+ export interface ExtractedRelationship {
35
+ cause: {
36
+ id: string;
37
+ name: string;
38
+ type: string;
39
+ };
40
+ effect: {
41
+ id: string;
42
+ name: string;
43
+ type: string;
44
+ };
45
+ relationType: string;
46
+ strength: number;
47
+ confidence: number;
48
+ mechanism: string;
49
+ }
50
+ export interface CausalExtractionResult {
51
+ relationships: ExtractedRelationship[];
52
+ reasoning: string;
53
+ }
54
+ export declare function parseCausalExtractionResponse(response: string): CausalExtractionResult | null;
55
+ export interface GeneratedHypothesis {
56
+ cause: string;
57
+ effect: string;
58
+ relationType: string;
59
+ expectedStrength: number;
60
+ rationale: string;
61
+ testable: boolean;
62
+ testStrategy: string;
63
+ }
64
+ export interface HypothesisGenerationResult {
65
+ hypotheses: GeneratedHypothesis[];
66
+ }
67
+ export declare function parseHypothesisResponse(response: string): HypothesisGenerationResult | null;
68
+ export interface ValidationResult {
69
+ verdict: 'validated' | 'rejected' | 'inconclusive';
70
+ confidence: number;
71
+ evidence: Array<{
72
+ type: 'supporting' | 'refuting';
73
+ description: string;
74
+ }>;
75
+ adjustedStrength: number;
76
+ reasoning: string;
77
+ }
78
+ export declare function parseValidationResponse(response: string): ValidationResult | null;
79
+ export interface RootCauseAnalysisResult {
80
+ rootCauses: Array<{
81
+ variable: string;
82
+ description: string;
83
+ contribution: number;
84
+ actionable: boolean;
85
+ }>;
86
+ causalChain: Array<{
87
+ from: string;
88
+ to: string;
89
+ mechanism: string;
90
+ }>;
91
+ preventiveInterventions: Array<{
92
+ target: string;
93
+ action: string;
94
+ expectedEffect: string;
95
+ }>;
96
+ reasoning: string;
97
+ }
98
+ export declare function parseRootCauseResponse(response: string): RootCauseAnalysisResult | null;
99
+ //# sourceMappingURL=prompts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompts.d.ts","sourceRoot":"","sources":["../../../src/causal/discovery/prompts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAExF,wBAAgB,2BAA2B,CACzC,MAAM,EAAE,MAAM,EACd,aAAa,EAAE,UAAU,EAAE,EAC3B,OAAO,CAAC,EAAE;IAAE,eAAe,CAAC,EAAE,MAAM,CAAC;IAAC,aAAa,CAAC,EAAE,MAAM,EAAE,CAAA;CAAE,GAC/D,MAAM,CA2CR;AAED,wBAAgB,+BAA+B,CAC7C,QAAQ,EAAE,KAAK,CAAC;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,CAAC,EACzE,MAAM,EAAE,KAAK,CAAC;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC,EAChE,OAAO,EAAE;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,GAC1C,MAAM,CAqCR;AAED,wBAAgB,2BAA2B,CACzC,UAAU,EAAE,gBAAgB,EAC5B,aAAa,EAAE;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,EAC/D,UAAU,EAAE,KAAK,CAAC;IAAE,YAAY,EAAE,MAAM,CAAC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E,mBAAmB,EAAE,CAAC;CACnC;AAED,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,MAAM,GAAG,0BAA0B,GAAG,IAAI,CAyB3F;AAED,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,WAAW,GAAG,UAAU,GAAG,cAAc,CAAC;IACnD,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,YAAY,GAAG,UAAU,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC1E,gBAAgB,EAAE,MAAM,CAAC;IACzB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,MAAM,GAAG,gBAAgB,GAAG,IAAI,CA2BjF;AAED,MAAM,WAAW,uBAAuB;IACtC,UAAU,EAAE,KAAK,CAAC;QAChB,QAAQ,EAAE,MAAM,CAAC;QACjB,WAAW,EAAE,MAAM,CAAC;QACpB,YAAY,EAAE,MAAM,CAAC;QACrB,UAAU,EAAE,OAAO,CAAC;KACrB,CAAC,CAAC;IACH,WAAW,EAAE,KAAK,CAAC;QACjB,IAAI,EAAE,MAAM,CAAC;QACb,EAAE,EAAE,MAAM,CAAC;QACX,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC,CAAC;IACH,uBAAuB,EAAE,KAAK,CAAC;QAC7B,MAAM,EAAE,MAAM,CAAC;QACf,MAAM,EAAE,MAAM,CAAC;QACf,cAAc,EAAE,MAAM,CAAC;KACxB,CAAC,CAAC;IACH,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,GAAG,uBAAuB,GAAG,IAAI,CAmCvF"}
@@ -0,0 +1,265 @@
1
+ export function buildCausalExtractionPrompt(source, existingNodes, context) {
2
+ const existingNodeList = existingNodes.length > 0
3
+ ? `\nExisting variables in the causal graph:\n${existingNodes.map((n) => `- ${n.id}: ${n.name} (${n.variableType})`).join('\n')}`
4
+ : '';
5
+ const contextSection = context
6
+ ? `\nContext:\n- Task: ${context.taskDescription || 'Not specified'}\n- Recent actions: ${context.recentActions?.join(', ') || 'None'}`
7
+ : '';
8
+ return `Analyze the following text and extract causal relationships.
9
+
10
+ For each causal relationship found, identify:
11
+ 1. The cause variable (what produces the effect)
12
+ 2. The effect variable (what is affected)
13
+ 3. The relationship type: causes, enables, prevents, mediates, confounds, or moderates
14
+ 4. Estimated strength (0.0 to 1.0)
15
+ 5. Confidence in this relationship (0.0 to 1.0)
16
+ 6. Brief mechanism description
17
+ ${existingNodeList}
18
+ ${contextSection}
19
+
20
+ Text to analyze:
21
+ """
22
+ ${source}
23
+ """
24
+
25
+ Respond in JSON format:
26
+ {
27
+ "relationships": [
28
+ {
29
+ "cause": { "id": "variable_id", "name": "Human readable name", "type": "observed|treatment|outcome|confounder|mediator|latent" },
30
+ "effect": { "id": "variable_id", "name": "Human readable name", "type": "observed|treatment|outcome|confounder|mediator|latent" },
31
+ "relationType": "causes|enables|prevents|mediates|confounds|moderates",
32
+ "strength": 0.8,
33
+ "confidence": 0.7,
34
+ "mechanism": "Brief description of how cause affects effect"
35
+ }
36
+ ],
37
+ "reasoning": "Brief explanation of the analysis"
38
+ }
39
+
40
+ Be conservative - only extract relationships that are clearly implied or stated. Prefer using existing variables when they match.`;
41
+ }
42
+ export function buildHypothesisGenerationPrompt(patterns, traces, context) {
43
+ const patternSection = patterns.length > 0
44
+ ? `\nObserved patterns:\n${patterns.map((p) => `- "${p.trigger}" → "${p.effect}" (observed ${p.occurrences} times)`).join('\n')}`
45
+ : '';
46
+ const traceSection = traces.length > 0
47
+ ? `\nRecent execution traces:\n${traces.map((t) => `- [${t.success ? 'SUCCESS' : 'FAILURE'}] ${t.summary}`).join('\n')}`
48
+ : '';
49
+ return `Generate causal hypotheses for agent ${context.agentId}.
50
+ ${context.goal ? `Agent goal: ${context.goal}` : ''}
51
+ ${patternSection}
52
+ ${traceSection}
53
+
54
+ Generate hypotheses about causal relationships that could explain the observed patterns and outcomes.
55
+
56
+ Respond in JSON format:
57
+ {
58
+ "hypotheses": [
59
+ {
60
+ "cause": "variable_id",
61
+ "effect": "variable_id",
62
+ "relationType": "causes|enables|prevents",
63
+ "expectedStrength": 0.7,
64
+ "rationale": "Why this relationship might exist",
65
+ "testable": true,
66
+ "testStrategy": "How to test this hypothesis"
67
+ }
68
+ ]
69
+ }
70
+
71
+ Focus on:
72
+ 1. Relationships that explain failures
73
+ 2. Patterns that predict success
74
+ 3. Hidden confounders that might explain spurious correlations`;
75
+ }
76
+ export function buildCausalValidationPrompt(hypothesis, originalTrace, forkTraces) {
77
+ return `Validate the following causal hypothesis based on execution traces.
78
+
79
+ Hypothesis:
80
+ - Cause: ${hypothesis.cause}
81
+ - Effect: ${hypothesis.effect}
82
+ - Relationship: ${hypothesis.relationType}
83
+ - Expected strength: ${hypothesis.strength}
84
+
85
+ Original execution:
86
+ - Trace ID: ${originalTrace.id}
87
+ - Summary: ${originalTrace.summary}
88
+ - Outcome: ${originalTrace.outcome}
89
+
90
+ Forked executions (with interventions):
91
+ ${forkTraces.map((f) => `- Intervention: ${f.intervention}\n Outcome: ${f.outcome}\n Difference: ${f.diffFromOriginal}`).join('\n\n')}
92
+
93
+ Analyze whether the evidence supports or refutes the hypothesis.
94
+
95
+ Respond in JSON format:
96
+ {
97
+ "verdict": "validated|rejected|inconclusive",
98
+ "confidence": 0.8,
99
+ "evidence": [
100
+ { "type": "supporting|refuting", "description": "..." }
101
+ ],
102
+ "adjustedStrength": 0.75,
103
+ "reasoning": "Detailed analysis of the evidence"
104
+ }`;
105
+ }
106
+ export function buildErrorCausalAnalysisPrompt(error, trace, context) {
107
+ const steps = trace.steps.slice(-10).map((s) => ({
108
+ action: s.toolCall ? `${s.toolCall.name}(${JSON.stringify(s.toolCall.arguments)})` : s.type,
109
+ result: s.toolResult
110
+ ? String(s.toolResult.result).substring(0, 200)
111
+ : s.response?.substring(0, 200),
112
+ success: !s.toolResult?.error,
113
+ }));
114
+ return `Analyze the causal chain that led to this error.
115
+
116
+ Error:
117
+ ${error.message}
118
+ ${error.stack ? `Stack: ${error.stack.substring(0, 500)}` : ''}
119
+
120
+ Recent execution steps:
121
+ ${steps.map((s, i) => `${i + 1}. [${s.success ? 'OK' : 'FAIL'}] ${s.action}: ${s.result || 'no result'}`).join('\n')}
122
+
123
+ System context:
124
+ - Recent actions: ${context.recentActions.join(', ')}
125
+ - State: ${JSON.stringify(context.systemState, null, 2).substring(0, 500)}
126
+
127
+ Identify:
128
+ 1. The root cause(s) of the error
129
+ 2. Contributing factors
130
+ 3. The causal chain from root cause to error
131
+ 4. Preventive interventions
132
+
133
+ Respond in JSON format:
134
+ {
135
+ "rootCauses": [
136
+ {
137
+ "variable": "cause_id",
138
+ "description": "What went wrong",
139
+ "contribution": 0.8,
140
+ "actionable": true
141
+ }
142
+ ],
143
+ "causalChain": [
144
+ { "from": "cause1", "to": "cause2", "mechanism": "how it propagated" }
145
+ ],
146
+ "preventiveInterventions": [
147
+ { "target": "variable", "action": "what to do", "expectedEffect": "outcome" }
148
+ ],
149
+ "reasoning": "Analysis explanation"
150
+ }`;
151
+ }
152
+ export function parseCausalExtractionResponse(response) {
153
+ try {
154
+ const jsonMatch = /\{[\s\S]*\}/.exec(response);
155
+ if (!jsonMatch)
156
+ return null;
157
+ const parsed = JSON.parse(jsonMatch[0]);
158
+ if (!parsed.relationships || !Array.isArray(parsed.relationships)) {
159
+ return null;
160
+ }
161
+ return {
162
+ relationships: parsed.relationships.map((r) => ({
163
+ cause: r.cause,
164
+ effect: r.effect,
165
+ relationType: r.relationType,
166
+ strength: typeof r.strength === 'number' ? r.strength : 0.5,
167
+ confidence: typeof r.confidence === 'number' ? r.confidence : 0.5,
168
+ mechanism: r.mechanism || '',
169
+ })),
170
+ reasoning: parsed.reasoning || '',
171
+ };
172
+ }
173
+ catch {
174
+ return null;
175
+ }
176
+ }
177
+ export function parseHypothesisResponse(response) {
178
+ try {
179
+ const jsonMatch = /\{[\s\S]*\}/.exec(response);
180
+ if (!jsonMatch)
181
+ return null;
182
+ const parsed = JSON.parse(jsonMatch[0]);
183
+ if (!parsed.hypotheses || !Array.isArray(parsed.hypotheses)) {
184
+ return null;
185
+ }
186
+ return {
187
+ hypotheses: parsed.hypotheses.map((h) => ({
188
+ cause: h.cause,
189
+ effect: h.effect,
190
+ relationType: h.relationType || 'causes',
191
+ expectedStrength: typeof h.expectedStrength === 'number' ? h.expectedStrength : 0.5,
192
+ rationale: h.rationale || '',
193
+ testable: h.testable !== false,
194
+ testStrategy: h.testStrategy || '',
195
+ })),
196
+ };
197
+ }
198
+ catch {
199
+ return null;
200
+ }
201
+ }
202
+ export function parseValidationResponse(response) {
203
+ try {
204
+ const jsonMatch = /\{[\s\S]*\}/.exec(response);
205
+ if (!jsonMatch)
206
+ return null;
207
+ const parsed = JSON.parse(jsonMatch[0]);
208
+ const verdict = parsed.verdict;
209
+ if (!['validated', 'rejected', 'inconclusive'].includes(verdict)) {
210
+ return null;
211
+ }
212
+ return {
213
+ verdict: verdict,
214
+ confidence: typeof parsed.confidence === 'number' ? parsed.confidence : 0.5,
215
+ evidence: Array.isArray(parsed.evidence)
216
+ ? parsed.evidence.map((e) => ({
217
+ type: e.type,
218
+ description: e.description,
219
+ }))
220
+ : [],
221
+ adjustedStrength: typeof parsed.adjustedStrength === 'number' ? parsed.adjustedStrength : 0.5,
222
+ reasoning: parsed.reasoning || '',
223
+ };
224
+ }
225
+ catch {
226
+ return null;
227
+ }
228
+ }
229
+ export function parseRootCauseResponse(response) {
230
+ try {
231
+ const jsonMatch = /\{[\s\S]*\}/.exec(response);
232
+ if (!jsonMatch)
233
+ return null;
234
+ const parsed = JSON.parse(jsonMatch[0]);
235
+ return {
236
+ rootCauses: Array.isArray(parsed.rootCauses)
237
+ ? parsed.rootCauses.map((r) => ({
238
+ variable: r.variable,
239
+ description: r.description,
240
+ contribution: typeof r.contribution === 'number' ? r.contribution : 0.5,
241
+ actionable: r.actionable !== false,
242
+ }))
243
+ : [],
244
+ causalChain: Array.isArray(parsed.causalChain)
245
+ ? parsed.causalChain.map((c) => ({
246
+ from: c.from,
247
+ to: c.to,
248
+ mechanism: c.mechanism,
249
+ }))
250
+ : [],
251
+ preventiveInterventions: Array.isArray(parsed.preventiveInterventions)
252
+ ? parsed.preventiveInterventions.map((p) => ({
253
+ target: p.target,
254
+ action: p.action,
255
+ expectedEffect: p.expectedEffect,
256
+ }))
257
+ : [],
258
+ reasoning: parsed.reasoning || '',
259
+ };
260
+ }
261
+ catch {
262
+ return null;
263
+ }
264
+ }
265
+ //# sourceMappingURL=prompts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompts.js","sourceRoot":"","sources":["../../../src/causal/discovery/prompts.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,2BAA2B,CACzC,MAAc,EACd,aAA2B,EAC3B,OAAgE;IAEhE,MAAM,gBAAgB,GACpB,aAAa,CAAC,MAAM,GAAG,CAAC;QACtB,CAAC,CAAC,8CAA8C,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,YAAY,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;QACjI,CAAC,CAAC,EAAE,CAAC;IAET,MAAM,cAAc,GAAG,OAAO;QAC5B,CAAC,CAAC,uBAAuB,OAAO,CAAC,eAAe,IAAI,eAAe,uBAAuB,OAAO,CAAC,aAAa,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,MAAM,EAAE;QACvI,CAAC,CAAC,EAAE,CAAC;IAEP,OAAO;;;;;;;;;EASP,gBAAgB;EAChB,cAAc;;;;EAId,MAAM;;;;;;;;;;;;;;;;;;kIAkB0H,CAAC;AACnI,CAAC;AAED,MAAM,UAAU,+BAA+B,CAC7C,QAAyE,EACzE,MAAgE,EAChE,OAA2C;IAE3C,MAAM,cAAc,GAClB,Q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+1,38 @@
1
+ import type { CausalGraph, CausalGraphData, CausalNode, CausalEdge, CausalPath, TripleType } from '@cogitator-ai/types';
2
+ export declare class CausalGraphImpl implements CausalGraph {
3
+ readonly id: string;
4
+ readonly name: string;
5
+ private nodes;
6
+ private edges;
7
+ private parentMap;
8
+ private childMap;
9
+ private edgeIndex;
10
+ private createdAt;
11
+ private updatedAt;
12
+ private version;
13
+ constructor(id: string, name: string);
14
+ static fromData(data: CausalGraphData): CausalGraphImpl;
15
+ addNode(node: CausalNode): void;
16
+ removeNode(nodeId: string): void;
17
+ getNode(nodeId: string): CausalNode | undefined;
18
+ getNodes(): CausalNode[];
19
+ hasNode(nodeId: string): boolean;
20
+ addEdge(edge: CausalEdge): void;
21
+ removeEdge(edgeId: string): void;
22
+ getEdge(edgeId: string): CausalEdge | undefined;
23
+ getEdges(): CausalEdge[];
24
+ getEdgeBetween(source: string, target: string): CausalEdge | undefined;
25
+ getParents(nodeId: string): CausalNode[];
26
+ getChildren(nodeId: string): CausalNode[];
27
+ getAncestors(nodeId: string): CausalNode[];
28
+ getDescendants(nodeId: string): CausalNode[];
29
+ findPaths(from: string, to: string, maxLength?: number): CausalPath[];
30
+ getMarkovBlanket(nodeId: string): CausalNode[];
31
+ topologicalSort(): string[];
32
+ hasCycle(): boolean;
33
+ clone(): CausalGraph;
34
+ toData(): CausalGraphData;
35
+ private touch;
36
+ }
37
+ export declare function getTripleType(graph: CausalGraph, a: string, b: string, c: string): TripleType | null;
38
+ //# sourceMappingURL=causal-graph.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"causal-graph.d.ts","sourceRoot":"","sources":["../../../src/causal/graph/causal-graph.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,eAAe,EACf,UAAU,EACV,UAAU,EACV,UAAU,EACV,UAAU,EACX,MAAM,qBAAqB,CAAC;AAE7B,qBAAa,eAAgB,YAAW,WAAW;IACjD,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;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