@mneme-ai/core 1.63.0 → 1.64.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.
- package/dist/cognitive/cognitive.test.d.ts +10 -0
- package/dist/cognitive/cognitive.test.d.ts.map +1 -0
- package/dist/cognitive/cognitive.test.js +485 -0
- package/dist/cognitive/cognitive.test.js.map +1 -0
- package/dist/cognitive/consolidation.d.ts +73 -0
- package/dist/cognitive/consolidation.d.ts.map +1 -0
- package/dist/cognitive/consolidation.js +170 -0
- package/dist/cognitive/consolidation.js.map +1 -0
- package/dist/cognitive/counterfactual.d.ts +73 -0
- package/dist/cognitive/counterfactual.d.ts.map +1 -0
- package/dist/cognitive/counterfactual.js +184 -0
- package/dist/cognitive/counterfactual.js.map +1 -0
- package/dist/cognitive/curiosity.d.ts +37 -0
- package/dist/cognitive/curiosity.d.ts.map +1 -0
- package/dist/cognitive/curiosity.js +191 -0
- package/dist/cognitive/curiosity.js.map +1 -0
- package/dist/cognitive/debate.d.ts +48 -0
- package/dist/cognitive/debate.d.ts.map +1 -0
- package/dist/cognitive/debate.js +223 -0
- package/dist/cognitive/debate.js.map +1 -0
- package/dist/cognitive/decision_atom.d.ts +119 -0
- package/dist/cognitive/decision_atom.d.ts.map +1 -0
- package/dist/cognitive/decision_atom.js +187 -0
- package/dist/cognitive/decision_atom.js.map +1 -0
- package/dist/cognitive/index.d.ts +31 -0
- package/dist/cognitive/index.d.ts.map +1 -0
- package/dist/cognitive/index.js +24 -0
- package/dist/cognitive/index.js.map +1 -0
- package/dist/cognitive/theory_of_mind.d.ts +56 -0
- package/dist/cognitive/theory_of_mind.d.ts.map +1 -0
- package/dist/cognitive/theory_of_mind.js +212 -0
- package/dist/cognitive/theory_of_mind.js.map +1 -0
- package/dist/cognitive/tree_of_thought.d.ts +55 -0
- package/dist/cognitive/tree_of_thought.d.ts.map +1 -0
- package/dist/cognitive/tree_of_thought.js +134 -0
- package/dist/cognitive/tree_of_thought.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* v1.64.0 -- COGNITIVE LAYER 7: DECISION ATOM (FUSION CORE).
|
|
3
|
+
*
|
|
4
|
+
* The capstone. A decision atom fuses the outputs of all six previous
|
|
5
|
+
* cognitive layers into a single, audit-traceable verdict for ANY
|
|
6
|
+
* non-trivial decision:
|
|
7
|
+
*
|
|
8
|
+
* 1. theory-of-mind -- which vendor is best for this task
|
|
9
|
+
* 2. tree-of-thought -- which strategy + tactic has highest EV
|
|
10
|
+
* 3. curiosity -- are there gaps that should be probed first
|
|
11
|
+
* 4. consolidation -- is the wisdom stack consistent (no near-dupes)
|
|
12
|
+
* 5. counterfactual -- would any alternative timeline score higher
|
|
13
|
+
* 6. debate -- skeptic / optimist / realist arbitration
|
|
14
|
+
*
|
|
15
|
+
* Each layer contributes a sub-verdict + confidence. The atom's
|
|
16
|
+
* fusion rule:
|
|
17
|
+
*
|
|
18
|
+
* PROCEED all layers AGREE or near-neutral
|
|
19
|
+
* PROCEED-WITH-CARE one layer DISAGREES with low confidence
|
|
20
|
+
* PAUSE-INVESTIGATE one layer DISAGREES with high confidence, OR
|
|
21
|
+
* two+ layers express concern
|
|
22
|
+
* ABORT-FOR-NOW debate DISAGREES with arbiterConfidence >= 0.7
|
|
23
|
+
* AND tree-of-thought best EV < 0.3
|
|
24
|
+
*
|
|
25
|
+
* Output is a single screen worth of plain English -- the user (or
|
|
26
|
+
* AI agent) reads it and acts. The full audit trail is on disk.
|
|
27
|
+
*/
|
|
28
|
+
import { existsSync, mkdirSync, appendFileSync } from "node:fs";
|
|
29
|
+
import { join } from "node:path";
|
|
30
|
+
import { buildProfile, recommendVendor } from "./theory_of_mind.js";
|
|
31
|
+
import { search as totSearch } from "./tree_of_thought.js";
|
|
32
|
+
import { scanGaps } from "./curiosity.js";
|
|
33
|
+
import { runConsolidation } from "./consolidation.js";
|
|
34
|
+
import { simulate as cfSimulate } from "./counterfactual.js";
|
|
35
|
+
import { debate } from "./debate.js";
|
|
36
|
+
const COGNITIVE_DIR = ".mneme/cognitive";
|
|
37
|
+
function decideVerdict(d) {
|
|
38
|
+
// ABORT: strong disagreement + low best EV
|
|
39
|
+
if (d.debateVerdict === "DISAGREE" && d.debateConfidence >= 0.7 && d.bestEv < 0.3) {
|
|
40
|
+
return { verdict: "ABORT-FOR-NOW", confidence: 0.9, reasoning: `Skeptic dominated (confidence ${d.debateConfidence.toFixed(2)}) AND best strategy EV is low (${d.bestEv.toFixed(3)}).` };
|
|
41
|
+
}
|
|
42
|
+
// PAUSE: significant gaps OR moderate disagreement OR significant counterfactual regret
|
|
43
|
+
if (d.highPriorityGaps >= 2 || d.regret >= 0.15 || (d.debateVerdict === "DISAGREE" && d.debateConfidence >= 0.5)) {
|
|
44
|
+
return {
|
|
45
|
+
verdict: "PAUSE-INVESTIGATE",
|
|
46
|
+
confidence: 0.6,
|
|
47
|
+
reasoning: `Investigate first: ${d.highPriorityGaps} high-priority gaps, regret ${d.regret.toFixed(2)}, debate=${d.debateVerdict}@${d.debateConfidence.toFixed(2)}.`,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
// CARE: mild concerns
|
|
51
|
+
if (d.debateVerdict === "INCONCLUSIVE" || d.bestEv < 0.4 || d.regret > 0.05) {
|
|
52
|
+
return {
|
|
53
|
+
verdict: "PROCEED-WITH-CARE",
|
|
54
|
+
confidence: 0.5,
|
|
55
|
+
reasoning: `Mild concern: debate=${d.debateVerdict}, EV=${d.bestEv.toFixed(3)}, regret=${d.regret.toFixed(2)}.`,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
verdict: "PROCEED",
|
|
60
|
+
confidence: Math.min(1, 0.7 + d.bestEv * 0.3),
|
|
61
|
+
reasoning: `All layers green: EV ${d.bestEv.toFixed(3)}, debate AGREE@${d.debateConfidence.toFixed(2)}, ${d.highPriorityGaps} high-priority gaps.`,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
export function build(repoRoot, input) {
|
|
65
|
+
// Layer 1: Theory of Mind
|
|
66
|
+
const vendorList = input.vendors ?? [];
|
|
67
|
+
const profiles = vendorList.map((v) => buildProfile(repoRoot, v));
|
|
68
|
+
const recommended = recommendVendor(profiles, input.taskProfile ?? {});
|
|
69
|
+
// Layer 2: Tree of Thought
|
|
70
|
+
const tot = totSearch(repoRoot, input.intent);
|
|
71
|
+
// Layer 3: Curiosity
|
|
72
|
+
const curiosity = scanGaps(repoRoot);
|
|
73
|
+
// Layer 4: Consolidation (dry run -- we don't want to mutate disk during a decision)
|
|
74
|
+
const consolidation = runConsolidation(repoRoot, { dryRun: true });
|
|
75
|
+
// Layer 5: Counterfactual (only if baseline provided)
|
|
76
|
+
let cf = null;
|
|
77
|
+
if (input.counterfactualBaseline) {
|
|
78
|
+
cf = cfSimulate(repoRoot, {
|
|
79
|
+
decision: input.intent,
|
|
80
|
+
actualRegressionP: input.counterfactualBaseline.actualRegressionP,
|
|
81
|
+
actualStakeholderFair: input.counterfactualBaseline.actualStakeholderFair,
|
|
82
|
+
actualTokenCost: input.counterfactualBaseline.actualTokenCost,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
// Layer 6: Debate
|
|
86
|
+
const dbt = debate(repoRoot, input.intent);
|
|
87
|
+
const fused = decideVerdict({
|
|
88
|
+
debateVerdict: dbt.verdict,
|
|
89
|
+
debateConfidence: dbt.arbiterConfidence,
|
|
90
|
+
bestEv: tot.bestEv,
|
|
91
|
+
highPriorityGaps: curiosity.highPriority,
|
|
92
|
+
regret: cf?.totalRegret ?? 0,
|
|
93
|
+
relief: cf?.totalRelief ?? 0,
|
|
94
|
+
});
|
|
95
|
+
const topGap = curiosity.gaps[0]?.description ?? null;
|
|
96
|
+
const recommendedAction = fused.verdict === "PROCEED"
|
|
97
|
+
? `Proceed with strategy "${tot.bestPath.join(" -> ")}".`
|
|
98
|
+
: fused.verdict === "PROCEED-WITH-CARE"
|
|
99
|
+
? `Proceed with "${tot.bestPath.join(" -> ")}", but add a pre-flight check: ${dbt.turns[0]?.evidence[0] ?? "review skeptic concerns"}.`
|
|
100
|
+
: fused.verdict === "PAUSE-INVESTIGATE"
|
|
101
|
+
? `Investigate first: ${topGap ?? dbt.reasoning.split("\n")[2]}.`
|
|
102
|
+
: `Abort for now. Reason: ${fused.reasoning}`;
|
|
103
|
+
const briefing = [
|
|
104
|
+
`## Decision Atom -- ${input.intent}`,
|
|
105
|
+
``,
|
|
106
|
+
`**Verdict:** ${fused.verdict} (confidence ${fused.confidence.toFixed(2)})`,
|
|
107
|
+
``,
|
|
108
|
+
`**Why:** ${fused.reasoning}`,
|
|
109
|
+
``,
|
|
110
|
+
`### Layer breakdown`,
|
|
111
|
+
`- Theory of Mind: ${profiles.length} vendor profile(s)${recommended ? `, recommended **${recommended.vendor}**` : ", no profiles supplied"}`,
|
|
112
|
+
`- Tree of Thought: best path \`${tot.bestPath.join(" -> ")}\` (EV ${tot.bestEv.toFixed(3)}); ${tot.rankedLeaves.length - 1} alternative(s)`,
|
|
113
|
+
`- Curiosity: ${curiosity.totalGaps} gap(s), ${curiosity.highPriority} high-priority${topGap ? `; top: "${topGap}"` : ""}`,
|
|
114
|
+
`- Consolidation (dry): ${consolidation.vaccines.merged} vaccine(s) would merge, ${consolidation.lessons.pruned} lesson(s) prune, ${consolidation.lessons.promoted} promote`,
|
|
115
|
+
cf ? `- Counterfactual: ${cf.summary}` : `- Counterfactual: (no baseline supplied -- skipped)`,
|
|
116
|
+
`- Debate: ${dbt.verdict} @ ${dbt.arbiterConfidence.toFixed(2)} -- "${dbt.turns[2]?.argument ?? ""}"`,
|
|
117
|
+
``,
|
|
118
|
+
`### Recommended action`,
|
|
119
|
+
recommendedAction,
|
|
120
|
+
].join("\n");
|
|
121
|
+
const atom = {
|
|
122
|
+
intent: input.intent,
|
|
123
|
+
verdict: fused.verdict,
|
|
124
|
+
confidence: fused.confidence,
|
|
125
|
+
layers: {
|
|
126
|
+
theoryOfMind: { recommendedVendor: recommended?.vendor ?? null, vendorProfiles: profiles.length },
|
|
127
|
+
treeOfThought: { bestPath: tot.bestPath, bestEv: tot.bestEv, alternatives: Math.max(0, tot.rankedLeaves.length - 1) },
|
|
128
|
+
curiosity: { totalGaps: curiosity.totalGaps, highPriority: curiosity.highPriority, topGap },
|
|
129
|
+
consolidation: { vaccinesMerged: consolidation.vaccines.merged, lessonsPruned: consolidation.lessons.pruned, lessonsPromoted: consolidation.lessons.promoted },
|
|
130
|
+
counterfactual: cf ? { topAlternative: cf.topAlternative?.label ?? null, netRelief: cf.totalRelief, netRegret: cf.totalRegret } : null,
|
|
131
|
+
debate: { verdict: dbt.verdict, arbiterConfidence: dbt.arbiterConfidence },
|
|
132
|
+
},
|
|
133
|
+
briefing,
|
|
134
|
+
recommendedAction,
|
|
135
|
+
raw: { profiles, tot, curiosity, consolidation, counterfactual: cf, debate: dbt },
|
|
136
|
+
builtAt: new Date().toISOString(),
|
|
137
|
+
};
|
|
138
|
+
// Audit log
|
|
139
|
+
try {
|
|
140
|
+
const dir = join(repoRoot, COGNITIVE_DIR, "atoms");
|
|
141
|
+
if (!existsSync(dir))
|
|
142
|
+
mkdirSync(dir, { recursive: true });
|
|
143
|
+
appendFileSync(join(dir, "decisions.jsonl"), JSON.stringify({
|
|
144
|
+
ts: atom.builtAt,
|
|
145
|
+
intent: atom.intent,
|
|
146
|
+
verdict: atom.verdict,
|
|
147
|
+
confidence: atom.confidence,
|
|
148
|
+
bestEv: tot.bestEv,
|
|
149
|
+
debateVerdict: dbt.verdict,
|
|
150
|
+
}) + "\n", "utf8");
|
|
151
|
+
}
|
|
152
|
+
catch { /* */ }
|
|
153
|
+
return atom;
|
|
154
|
+
}
|
|
155
|
+
export function summarizeHistory(repoRoot) {
|
|
156
|
+
const p = join(repoRoot, COGNITIVE_DIR, "atoms", "decisions.jsonl");
|
|
157
|
+
const verdictCounts = { "PROCEED": 0, "PROCEED-WITH-CARE": 0, "PAUSE-INVESTIGATE": 0, "ABORT-FOR-NOW": 0 };
|
|
158
|
+
let total = 0;
|
|
159
|
+
let confSum = 0;
|
|
160
|
+
let last = null;
|
|
161
|
+
if (!existsSync(p))
|
|
162
|
+
return { totalAtoms: 0, verdictCounts, meanConfidence: 0, lastAtom: null };
|
|
163
|
+
try {
|
|
164
|
+
const { readFileSync } = require("node:fs");
|
|
165
|
+
const lines = readFileSync(p, "utf8").split("\n").filter(Boolean);
|
|
166
|
+
for (const l of lines) {
|
|
167
|
+
try {
|
|
168
|
+
const r = JSON.parse(l);
|
|
169
|
+
if (!r.verdict || !(r.verdict in verdictCounts))
|
|
170
|
+
continue;
|
|
171
|
+
verdictCounts[r.verdict] += 1;
|
|
172
|
+
confSum += r.confidence ?? 0;
|
|
173
|
+
total += 1;
|
|
174
|
+
last = { intent: r.intent ?? "(unknown)", verdict: r.verdict, ts: r.ts ?? "(unknown)" };
|
|
175
|
+
}
|
|
176
|
+
catch { /* */ }
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
catch { /* */ }
|
|
180
|
+
return {
|
|
181
|
+
totalAtoms: total,
|
|
182
|
+
verdictCounts,
|
|
183
|
+
meanConfidence: total === 0 ? 0 : confSum / total,
|
|
184
|
+
lastAtom: last,
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
//# sourceMappingURL=decision_atom.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decision_atom.js","sourceRoot":"","sources":["../../src/cognitive/decision_atom.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAChE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,YAAY,EAAE,eAAe,E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C,CAAC,CAAC,OAAO,GAAG,KAAK;QACjD,QAAQ,EAAE,IAAI;KACf,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* v1.64.0 -- COGNITIVE LAYER (7-layer thinking demon).
|
|
3
|
+
*
|
|
4
|
+
* Public API for the seven cognitive sub-systems:
|
|
5
|
+
*
|
|
6
|
+
* 1. theoryOfMind -- 9-axis behavioral profile per vendor
|
|
7
|
+
* 2. treeOfThought -- 3-level EV-scored decision tree
|
|
8
|
+
* 3. curiosity -- daemon-idle gap scanner
|
|
9
|
+
* 4. consolidation -- sleep-cycle compression of vaccines + lessons
|
|
10
|
+
* 5. counterfactual -- alternative-timeline simulation
|
|
11
|
+
* 6. debate -- skeptic / optimist / realist arbitration
|
|
12
|
+
* 7. decisionAtom -- fusion of layers 1-6 into a single verdict
|
|
13
|
+
*
|
|
14
|
+
* All seven are pure (no side effects) by default. Persistence is
|
|
15
|
+
* opt-in via the `persist*` flags. Storage root is .mneme/cognitive/.
|
|
16
|
+
*/
|
|
17
|
+
export * as theoryOfMind from "./theory_of_mind.js";
|
|
18
|
+
export * as treeOfThought from "./tree_of_thought.js";
|
|
19
|
+
export * as curiosity from "./curiosity.js";
|
|
20
|
+
export * as consolidation from "./consolidation.js";
|
|
21
|
+
export * as counterfactual from "./counterfactual.js";
|
|
22
|
+
export * as debate from "./debate.js";
|
|
23
|
+
export * as decisionAtom from "./decision_atom.js";
|
|
24
|
+
export type { VendorProfile } from "./theory_of_mind.js";
|
|
25
|
+
export type { ToTResult, TreeNode } from "./tree_of_thought.js";
|
|
26
|
+
export type { CuriosityGap, CuriosityScan } from "./curiosity.js";
|
|
27
|
+
export type { ConsolidationReport } from "./consolidation.js";
|
|
28
|
+
export type { CounterfactualResult, CounterfactualBranch, CounterfactualBias } from "./counterfactual.js";
|
|
29
|
+
export type { DebateResult, DebateTurn, Voice } from "./debate.js";
|
|
30
|
+
export type { DecisionAtom, DecisionAtomInput, AtomVerdict, AtomHistorySummary } from "./decision_atom.js";
|
|
31
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cognitive/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,YAAY,MAAM,qBAAqB,CAAC;AACpD,OAAO,KAAK,aAAa,MAAM,sBAAsB,CAAC;AACtD,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAC;AAC5C,OAAO,KAAK,aAAa,MAAM,oBAAoB,CAAC;AACpD,OAAO,KAAK,cAAc,MAAM,qBAAqB,CAAC;AACtD,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AACtC,OAAO,KAAK,YAAY,MAAM,oBAAoB,CAAC;AAGnD,YAAY,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,YAAY,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChE,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAClE,YAAY,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAC9D,YAAY,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAC1G,YAAY,EAAE,YAAY,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACnE,YAAY,EAAE,YAAY,EAAE,iBAAiB,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* v1.64.0 -- COGNITIVE LAYER (7-layer thinking demon).
|
|
3
|
+
*
|
|
4
|
+
* Public API for the seven cognitive sub-systems:
|
|
5
|
+
*
|
|
6
|
+
* 1. theoryOfMind -- 9-axis behavioral profile per vendor
|
|
7
|
+
* 2. treeOfThought -- 3-level EV-scored decision tree
|
|
8
|
+
* 3. curiosity -- daemon-idle gap scanner
|
|
9
|
+
* 4. consolidation -- sleep-cycle compression of vaccines + lessons
|
|
10
|
+
* 5. counterfactual -- alternative-timeline simulation
|
|
11
|
+
* 6. debate -- skeptic / optimist / realist arbitration
|
|
12
|
+
* 7. decisionAtom -- fusion of layers 1-6 into a single verdict
|
|
13
|
+
*
|
|
14
|
+
* All seven are pure (no side effects) by default. Persistence is
|
|
15
|
+
* opt-in via the `persist*` flags. Storage root is .mneme/cognitive/.
|
|
16
|
+
*/
|
|
17
|
+
export * as theoryOfMind from "./theory_of_mind.js";
|
|
18
|
+
export * as treeOfThought from "./tree_of_thought.js";
|
|
19
|
+
export * as curiosity from "./curiosity.js";
|
|
20
|
+
export * as consolidation from "./consolidation.js";
|
|
21
|
+
export * as counterfactual from "./counterfactual.js";
|
|
22
|
+
export * as debate from "./debate.js";
|
|
23
|
+
export * as decisionAtom from "./decision_atom.js";
|
|
24
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cognitive/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,YAAY,MAAM,qBAAqB,CAAC;AACpD,OAAO,KAAK,aAAa,MAAM,sBAAsB,CAAC;AACtD,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAC;AAC5C,OAAO,KAAK,aAAa,MAAM,oBAAoB,CAAC;AACpD,OAAO,KAAK,cAAc,MAAM,qBAAqB,CAAC;AACtD,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AACtC,OAAO,KAAK,YAAY,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* v1.64.0 -- COGNITIVE LAYER 1: THEORY OF MIND.
|
|
3
|
+
*
|
|
4
|
+
* Build a 9-axis behavioral profile for each AI vendor so Mneme can
|
|
5
|
+
* predict how a given vendor will handle a given prompt BEFORE it
|
|
6
|
+
* actually runs.
|
|
7
|
+
*
|
|
8
|
+
* The 9 axes:
|
|
9
|
+
* 1. verbosity -- tokens-per-response mean
|
|
10
|
+
* 2. overconfidence -- gap between stated confidence and ACGV verdict
|
|
11
|
+
* 3. domainBias -- which domains it shines / fails on
|
|
12
|
+
* 4. refusalRate -- how often it declines
|
|
13
|
+
* 5. hallucinationClass -- which kind of fab it produces most
|
|
14
|
+
* 6. riskAppetite -- how aggressive its refactor / change suggestions
|
|
15
|
+
* 7. verbosityDrift -- does it talk more over a long conversation?
|
|
16
|
+
* 8. tempStability -- consistency of outputs for similar inputs
|
|
17
|
+
* 9. chainDepth -- typical reasoning steps before final answer
|
|
18
|
+
*
|
|
19
|
+
* Data source: ai-souls + squadron/quorum.jsonl + nemesis runs +
|
|
20
|
+
* reactor ledger. Pure read; no side effects unless persistProfile().
|
|
21
|
+
*/
|
|
22
|
+
export interface VendorProfile {
|
|
23
|
+
vendor: string;
|
|
24
|
+
/** Number of observations the profile is built from. */
|
|
25
|
+
observationCount: number;
|
|
26
|
+
/** 9 axes -- normalized 0..1 unless noted. */
|
|
27
|
+
axes: {
|
|
28
|
+
verbosity: number;
|
|
29
|
+
overconfidence: number;
|
|
30
|
+
domainBias: Record<string, number>;
|
|
31
|
+
refusalRate: number;
|
|
32
|
+
hallucinationClass: string;
|
|
33
|
+
riskAppetite: number;
|
|
34
|
+
verbosityDrift: number;
|
|
35
|
+
tempStability: number;
|
|
36
|
+
chainDepth: number;
|
|
37
|
+
};
|
|
38
|
+
/** Time of last build. */
|
|
39
|
+
builtAt: string;
|
|
40
|
+
}
|
|
41
|
+
export declare function buildProfile(repoRoot: string, vendor: string): VendorProfile;
|
|
42
|
+
/** Persist a profile snapshot to disk. */
|
|
43
|
+
export declare function persistProfile(repoRoot: string, profile: VendorProfile): string;
|
|
44
|
+
/** Compare two vendor profiles -- returns where vendorA outperforms B. */
|
|
45
|
+
export declare function compareVendors(a: VendorProfile, b: VendorProfile): {
|
|
46
|
+
aWins: string[];
|
|
47
|
+
bWins: string[];
|
|
48
|
+
tied: string[];
|
|
49
|
+
};
|
|
50
|
+
/** Recommend the best vendor for a task given a list of profiles. */
|
|
51
|
+
export declare function recommendVendor(profiles: VendorProfile[], task: {
|
|
52
|
+
domain?: string;
|
|
53
|
+
needsTerse?: boolean;
|
|
54
|
+
needsStable?: boolean;
|
|
55
|
+
}): VendorProfile | null;
|
|
56
|
+
//# sourceMappingURL=theory_of_mind.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"theory_of_mind.d.ts","sourceRoot":"","sources":["../../src/cognitive/theory_of_mind.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAOH,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,wDAAwD;IACxD,gBAAgB,EAAE,MAAM,CAAC;IACzB,8CAA8C;IAC9C,IAAI,EAAE;QACJ,SAAS,EAAE,MAAM,CAAC;QAClB,cAAc,EAAE,MAAM,CAAC;QACvB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACnC,WAAW,EAAE,MAAM,CAAC;QACpB,kBAAkB,EAAE,MAAM,CAAC;QAC3B,YAAY,EAAE,MAAM,CAAC;QACrB,cAAc,EAAE,MAAM,CAAC;QACvB,aAAa,EAAE,MAAM,CAAC;QACtB,UAAU,EAAE,MAAM,CAAC;KACpB,CAAC;IACF,0BAA0B;IAC1B,OAAO,EAAE,MAAM,CAAC;CACjB;AA6CD,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,aAAa,CA2E5E;AAED,0CAA0C;AAC1C,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,GAAG,MAAM,CAO/E;AAED,0EAA0E;AAC1E,wBAAgB,cAAc,CAAC,CAAC,EAAE,aAAa,EAAE,CAAC,EAAE,aAAa,GAAG;IAClE,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,IAAI,EAAE,MAAM,EAAE,CAAC;CAChB,CAkBA;AAED,qEAAqE;AACrE,wBAAgB,eAAe,CAAC,QAAQ,EAAE,aAAa,EAAE,EAAE,IAAI,EAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,OAAO,CAAC;IAAC,WAAW,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,aAAa,GAAG,IAAI,CAevJ"}
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* v1.64.0 -- COGNITIVE LAYER 1: THEORY OF MIND.
|
|
3
|
+
*
|
|
4
|
+
* Build a 9-axis behavioral profile for each AI vendor so Mneme can
|
|
5
|
+
* predict how a given vendor will handle a given prompt BEFORE it
|
|
6
|
+
* actually runs.
|
|
7
|
+
*
|
|
8
|
+
* The 9 axes:
|
|
9
|
+
* 1. verbosity -- tokens-per-response mean
|
|
10
|
+
* 2. overconfidence -- gap between stated confidence and ACGV verdict
|
|
11
|
+
* 3. domainBias -- which domains it shines / fails on
|
|
12
|
+
* 4. refusalRate -- how often it declines
|
|
13
|
+
* 5. hallucinationClass -- which kind of fab it produces most
|
|
14
|
+
* 6. riskAppetite -- how aggressive its refactor / change suggestions
|
|
15
|
+
* 7. verbosityDrift -- does it talk more over a long conversation?
|
|
16
|
+
* 8. tempStability -- consistency of outputs for similar inputs
|
|
17
|
+
* 9. chainDepth -- typical reasoning steps before final answer
|
|
18
|
+
*
|
|
19
|
+
* Data source: ai-souls + squadron/quorum.jsonl + nemesis runs +
|
|
20
|
+
* reactor ledger. Pure read; no side effects unless persistProfile().
|
|
21
|
+
*/
|
|
22
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
23
|
+
import { join } from "node:path";
|
|
24
|
+
const COGNITIVE_DIR = ".mneme/cognitive";
|
|
25
|
+
function ensureDir(repoRoot) {
|
|
26
|
+
const d = join(repoRoot, COGNITIVE_DIR);
|
|
27
|
+
if (!existsSync(d))
|
|
28
|
+
mkdirSync(d, { recursive: true });
|
|
29
|
+
return d;
|
|
30
|
+
}
|
|
31
|
+
function readSoul(repoRoot, vendor) {
|
|
32
|
+
const p = join(repoRoot, ".mneme/ai-souls", `${vendor}.json`);
|
|
33
|
+
if (!existsSync(p))
|
|
34
|
+
return null;
|
|
35
|
+
try {
|
|
36
|
+
return JSON.parse(readFileSync(p, "utf8"));
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function readQuorum(repoRoot) {
|
|
43
|
+
const p = join(repoRoot, ".mneme/squadron/quorum.jsonl");
|
|
44
|
+
if (!existsSync(p))
|
|
45
|
+
return [];
|
|
46
|
+
try {
|
|
47
|
+
return readFileSync(p, "utf8").split("\n").filter(Boolean).map((l) => {
|
|
48
|
+
try {
|
|
49
|
+
return JSON.parse(l);
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
}).filter((x) => x !== null);
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
return [];
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function dominantHallucinationClass(soul) {
|
|
61
|
+
if (!soul?.sessions)
|
|
62
|
+
return "unknown";
|
|
63
|
+
const counts = new Map();
|
|
64
|
+
for (const s of soul.sessions) {
|
|
65
|
+
if ((s.broken ?? 0) === 0)
|
|
66
|
+
continue;
|
|
67
|
+
const reason = (s.reason ?? "unknown").toLowerCase();
|
|
68
|
+
let cls = "unknown";
|
|
69
|
+
if (/commit|sha/.test(reason))
|
|
70
|
+
cls = "commit-hash";
|
|
71
|
+
else if (/file|path/.test(reason))
|
|
72
|
+
cls = "file-path";
|
|
73
|
+
else if (/version|v\d/.test(reason))
|
|
74
|
+
cls = "version-number";
|
|
75
|
+
else if (/function|class|method/.test(reason))
|
|
76
|
+
cls = "identifier";
|
|
77
|
+
counts.set(cls, (counts.get(cls) ?? 0) + 1);
|
|
78
|
+
}
|
|
79
|
+
if (counts.size === 0)
|
|
80
|
+
return "no-known-hallucinations";
|
|
81
|
+
return [...counts.entries()].sort((a, b) => b[1] - a[1])[0][0];
|
|
82
|
+
}
|
|
83
|
+
export function buildProfile(repoRoot, vendor) {
|
|
84
|
+
const soul = readSoul(repoRoot, vendor);
|
|
85
|
+
const quorum = readQuorum(repoRoot);
|
|
86
|
+
const sessions = soul?.sessions ?? [];
|
|
87
|
+
const observationCount = sessions.length;
|
|
88
|
+
// Axis 1: verbosity -- mean of session.verbosity field; default 0.5 when absent.
|
|
89
|
+
const verbosityValues = sessions.map((s) => s.verbosity).filter((v) => typeof v === "number");
|
|
90
|
+
const verbosity = verbosityValues.length > 0
|
|
91
|
+
? Math.min(1, verbosityValues.reduce((a, b) => a + b, 0) / verbosityValues.length / 1000)
|
|
92
|
+
: 0.5;
|
|
93
|
+
// Axis 2: overconfidence -- fraction of broken-promise sessions weighted by their stated confidence.
|
|
94
|
+
const broken = sessions.filter((s) => (s.broken ?? 0) > 0);
|
|
95
|
+
const overconfidence = sessions.length === 0 ? 0 : Math.min(1, broken.length / sessions.length);
|
|
96
|
+
// Axis 3: domainBias -- per-domain success rate from quorum log.
|
|
97
|
+
const domainCounts = {};
|
|
98
|
+
for (const q of quorum) {
|
|
99
|
+
const claim = (q.claim ?? "").toLowerCase();
|
|
100
|
+
let domain = "general";
|
|
101
|
+
if (/auth|jwt|password|login/.test(claim))
|
|
102
|
+
domain = "auth";
|
|
103
|
+
else if (/test|vitest|jest/.test(claim))
|
|
104
|
+
domain = "test";
|
|
105
|
+
else if (/git|commit|branch|merge/.test(claim))
|
|
106
|
+
domain = "git";
|
|
107
|
+
else if (/regex|pattern/.test(claim))
|
|
108
|
+
domain = "regex";
|
|
109
|
+
else if (/database|sql|migration/.test(claim))
|
|
110
|
+
domain = "database";
|
|
111
|
+
if (!domainCounts[domain])
|
|
112
|
+
domainCounts[domain] = { total: 0, refuted: 0 };
|
|
113
|
+
domainCounts[domain].total += 1;
|
|
114
|
+
if ((q.caveats ?? []).includes("FALSE_FACT_CLAIM"))
|
|
115
|
+
domainCounts[domain].refuted += 1;
|
|
116
|
+
}
|
|
117
|
+
const domainBias = {};
|
|
118
|
+
for (const [d, c] of Object.entries(domainCounts)) {
|
|
119
|
+
domainBias[d] = c.total === 0 ? 0.5 : 1 - c.refuted / c.total;
|
|
120
|
+
}
|
|
121
|
+
// Axis 4: refusalRate -- placeholder when we have no refusal signal.
|
|
122
|
+
const refusalRate = 0;
|
|
123
|
+
// Axis 5: hallucinationClass -- dominant class observed.
|
|
124
|
+
const hallucinationClass = dominantHallucinationClass(soul);
|
|
125
|
+
// Axis 6: riskAppetite -- 1 - (sessions that broke promises like "no-silent-destroy").
|
|
126
|
+
const riskAppetite = sessions.length === 0 ? 0.5 : Math.min(1, broken.length / sessions.length);
|
|
127
|
+
// Axis 7: verbosityDrift -- difference between last-third and first-third mean verbosity.
|
|
128
|
+
let verbosityDrift = 0;
|
|
129
|
+
if (verbosityValues.length >= 6) {
|
|
130
|
+
const third = Math.floor(verbosityValues.length / 3);
|
|
131
|
+
const firstAvg = verbosityValues.slice(0, third).reduce((a, b) => a + b, 0) / third;
|
|
132
|
+
const lastAvg = verbosityValues.slice(-third).reduce((a, b) => a + b, 0) / third;
|
|
133
|
+
verbosityDrift = Math.min(1, Math.max(0, (lastAvg - firstAvg) / (firstAvg || 1)));
|
|
134
|
+
}
|
|
135
|
+
// Axis 8: tempStability -- consistency of consensus verdicts across identical-domain claims.
|
|
136
|
+
const tempStability = 1 - Math.min(1, observationCount === 0 ? 0 : broken.length / Math.max(1, observationCount));
|
|
137
|
+
// Axis 9: chainDepth -- approx steps from soul.verbosity or default.
|
|
138
|
+
const chainDepth = verbosityValues.length === 0 ? 5 : Math.max(1, Math.round(verbosityValues.reduce((a, b) => a + b, 0) / verbosityValues.length / 100));
|
|
139
|
+
return {
|
|
140
|
+
vendor,
|
|
141
|
+
observationCount,
|
|
142
|
+
axes: {
|
|
143
|
+
verbosity,
|
|
144
|
+
overconfidence,
|
|
145
|
+
domainBias,
|
|
146
|
+
refusalRate,
|
|
147
|
+
hallucinationClass,
|
|
148
|
+
riskAppetite,
|
|
149
|
+
verbosityDrift,
|
|
150
|
+
tempStability,
|
|
151
|
+
chainDepth,
|
|
152
|
+
},
|
|
153
|
+
builtAt: new Date().toISOString(),
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
/** Persist a profile snapshot to disk. */
|
|
157
|
+
export function persistProfile(repoRoot, profile) {
|
|
158
|
+
const dir = ensureDir(repoRoot);
|
|
159
|
+
const subdir = join(dir, "vendor-profiles");
|
|
160
|
+
if (!existsSync(subdir))
|
|
161
|
+
mkdirSync(subdir, { recursive: true });
|
|
162
|
+
const path = join(subdir, `${profile.vendor}.json`);
|
|
163
|
+
writeFileSync(path, JSON.stringify(profile, null, 2), "utf8");
|
|
164
|
+
return path;
|
|
165
|
+
}
|
|
166
|
+
/** Compare two vendor profiles -- returns where vendorA outperforms B. */
|
|
167
|
+
export function compareVendors(a, b) {
|
|
168
|
+
const result = { aWins: [], bWins: [], tied: [] };
|
|
169
|
+
const numericAxes = ["verbosity", "overconfidence", "refusalRate", "riskAppetite", "verbosityDrift", "tempStability", "chainDepth"];
|
|
170
|
+
for (const axis of numericAxes) {
|
|
171
|
+
const av = a.axes[axis];
|
|
172
|
+
const bv = b.axes[axis];
|
|
173
|
+
if (Math.abs(av - bv) < 0.05)
|
|
174
|
+
result.tied.push(axis);
|
|
175
|
+
else if (axis === "overconfidence" || axis === "verbosityDrift") {
|
|
176
|
+
// lower is better
|
|
177
|
+
if (av < bv)
|
|
178
|
+
result.aWins.push(axis);
|
|
179
|
+
else
|
|
180
|
+
result.bWins.push(axis);
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
// higher is better (verbosity is neutral; we still pick "more" = a wins for terse-prefer downstream)
|
|
184
|
+
if (av > bv)
|
|
185
|
+
result.aWins.push(axis);
|
|
186
|
+
else
|
|
187
|
+
result.bWins.push(axis);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return result;
|
|
191
|
+
}
|
|
192
|
+
/** Recommend the best vendor for a task given a list of profiles. */
|
|
193
|
+
export function recommendVendor(profiles, task) {
|
|
194
|
+
if (profiles.length === 0)
|
|
195
|
+
return null;
|
|
196
|
+
const scored = profiles.map((p) => {
|
|
197
|
+
let score = 0;
|
|
198
|
+
if (task.domain && p.axes.domainBias[task.domain] !== undefined) {
|
|
199
|
+
score += p.axes.domainBias[task.domain] * 3;
|
|
200
|
+
}
|
|
201
|
+
if (task.needsTerse)
|
|
202
|
+
score += (1 - p.axes.verbosity) * 2;
|
|
203
|
+
if (task.needsStable)
|
|
204
|
+
score += p.axes.tempStability * 2;
|
|
205
|
+
score -= p.axes.overconfidence * 2;
|
|
206
|
+
score += (1 - p.axes.verbosityDrift) * 1;
|
|
207
|
+
return { profile: p, score };
|
|
208
|
+
});
|
|
209
|
+
scored.sort((a, b) => b.score - a.score);
|
|
210
|
+
return scored[0].profile;
|
|
211
|
+
}
|
|
212
|
+
//# sourceMappingURL=theory_of_mind.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"theory_of_mind.js","sourceRoot":"","sources":["../../src/cognitive/theory_of_mind.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAe,aAAa,EAAE,MAAM,SAAS,CAAC;AAC1F,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,MAAM,aAAa,GAAG,kBAAkB,CAAC;AAsBzC,SAAS,SAAS,CAAC,QAAgB;IACjC,MAAM,CAAC,GAAG,IAAI,CAAC,QAAQ,EAAE,aAAa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CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,SAAS,EAAE,CAAC;YAChE,KAAK,IAAI,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAE,GAAG,CAAC,CAAC;QAC/C,CAAC;QACD,IAAI,IAAI,CAAC,UAAU;YAAE,KAAK,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;QACzD,IAAI,IAAI,CAAC,WAAW;YAAE,KAAK,IAAI,CAAC,CAAC,IAAI,CAAC,aAAa,GAAG,CAAC,CAAC;QACxD,KAAK,IAAI,CAAC,CAAC,IAAI,CAAC,cAAc,GAAG,CAAC,CAAC;QACnC,KAAK,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC;QACzC,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC;IAC/B,CAAC,CAAC,CAAC;IACH,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC;IACzC,OAAO,MAAM,CAAC,CAAC,CAAE,CAAC,OAAO,CAAC;AAC5B,CAAC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* v1.64.0 -- COGNITIVE LAYER 2: TREE-OF-THOUGHT SEARCH.
|
|
3
|
+
*
|
|
4
|
+
* Given a high-stakes prompt, build a 3-level decision tree of strategies,
|
|
5
|
+
* estimate each branch's expected value via existing Mneme layers, return
|
|
6
|
+
* the highest-EV branch + the full tree as audit trail.
|
|
7
|
+
*
|
|
8
|
+
* intent level 0
|
|
9
|
+
* ├── strategy A (level 1)
|
|
10
|
+
* │ ├── tactic A.1 (level 2)
|
|
11
|
+
* │ └── tactic A.2
|
|
12
|
+
* ├── strategy B
|
|
13
|
+
* │ ├── tactic B.1
|
|
14
|
+
* │ └── tactic B.2
|
|
15
|
+
*
|
|
16
|
+
* Each leaf gets:
|
|
17
|
+
* - estimatedRegressionP (from Oracle Forecast)
|
|
18
|
+
* - estimatedStakeholderFair (from Game Theory if stakeholders supplied)
|
|
19
|
+
* - estimatedTokenCost (from Reactor estimates)
|
|
20
|
+
*
|
|
21
|
+
* EV = (1 - regressionP) * stakeholderFair / (1 + log(tokenCost / 100))
|
|
22
|
+
*
|
|
23
|
+
* The tree is deterministic given (intent + repo state) so callers can
|
|
24
|
+
* replay + compare. Pure read; no side effects.
|
|
25
|
+
*/
|
|
26
|
+
export interface TreeNode {
|
|
27
|
+
id: string;
|
|
28
|
+
level: 0 | 1 | 2;
|
|
29
|
+
label: string;
|
|
30
|
+
/** Children at level+1. */
|
|
31
|
+
children: TreeNode[];
|
|
32
|
+
/** Leaf-only metrics. */
|
|
33
|
+
metrics?: {
|
|
34
|
+
estimatedRegressionP: number;
|
|
35
|
+
estimatedStakeholderFair: number;
|
|
36
|
+
estimatedTokenCost: number;
|
|
37
|
+
expectedValue: number;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
export interface ToTResult {
|
|
41
|
+
root: TreeNode;
|
|
42
|
+
/** Best leaf by EV. */
|
|
43
|
+
bestLeafId: string;
|
|
44
|
+
bestPath: string[];
|
|
45
|
+
bestEv: number;
|
|
46
|
+
/** All leaves ranked. */
|
|
47
|
+
rankedLeaves: Array<{
|
|
48
|
+
id: string;
|
|
49
|
+
path: string[];
|
|
50
|
+
ev: number;
|
|
51
|
+
}>;
|
|
52
|
+
reasoning: string;
|
|
53
|
+
}
|
|
54
|
+
export declare function search(repoRoot: string, intent: string): ToTResult;
|
|
55
|
+
//# sourceMappingURL=tree_of_thought.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tree_of_thought.d.ts","sourceRoot":"","sources":["../../src/cognitive/tree_of_thought.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAOH,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,2BAA2B;IAC3B,QAAQ,EAAE,QAAQ,EAAE,CAAC;IACrB,yBAAyB;IACzB,OAAO,CAAC,EAAE;QACR,oBAAoB,EAAE,MAAM,CAAC;QAC7B,wBAAwB,EAAE,MAAM,CAAC;QACjC,kBAAkB,EAAE,MAAM,CAAC;QAC3B,aAAa,EAAE,MAAM,CAAC;KACvB,CAAC;CACH;AAED,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,QAAQ,CAAC;IACf,uBAAuB;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,yBAAyB;IACzB,YAAY,EAAE,KAAK,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,EAAE,CAAC;QAAC,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAChE,SAAS,EAAE,MAAM,CAAC;CACnB;AAgDD,wBAAgB,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,SAAS,CA+DlE"}
|