@mneme-ai/mcp 1.1.1 → 1.3.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 (68) hide show
  1. package/dist/index.d.ts.map +1 -1
  2. package/dist/index.js +75 -343
  3. package/dist/index.js.map +1 -1
  4. package/dist/tools/_capabilities.d.ts +14 -0
  5. package/dist/tools/_capabilities.d.ts.map +1 -0
  6. package/dist/tools/_capabilities.js +90 -0
  7. package/dist/tools/_capabilities.js.map +1 -0
  8. package/dist/tools/_lifecycle.d.ts +51 -0
  9. package/dist/tools/_lifecycle.d.ts.map +1 -0
  10. package/dist/tools/_lifecycle.js +124 -0
  11. package/dist/tools/_lifecycle.js.map +1 -0
  12. package/dist/tools/_molecules.d.ts +22 -0
  13. package/dist/tools/_molecules.d.ts.map +1 -0
  14. package/dist/tools/_molecules.js +142 -0
  15. package/dist/tools/_molecules.js.map +1 -0
  16. package/dist/tools/_registry.d.ts +16 -0
  17. package/dist/tools/_registry.d.ts.map +1 -0
  18. package/dist/tools/_registry.js +57 -0
  19. package/dist/tools/_registry.js.map +1 -0
  20. package/dist/tools/_runtime.d.ts +32 -0
  21. package/dist/tools/_runtime.d.ts.map +1 -0
  22. package/dist/tools/_runtime.js +78 -0
  23. package/dist/tools/_runtime.js.map +1 -0
  24. package/dist/tools/_smart_do.d.ts +14 -0
  25. package/dist/tools/_smart_do.d.ts.map +1 -0
  26. package/dist/tools/_smart_do.js +49 -0
  27. package/dist/tools/_smart_do.js.map +1 -0
  28. package/dist/tools/_types.d.ts +118 -0
  29. package/dist/tools/_types.d.ts.map +1 -0
  30. package/dist/tools/_types.js +34 -0
  31. package/dist/tools/_types.js.map +1 -0
  32. package/dist/tools/audit.d.ts +9 -0
  33. package/dist/tools/audit.d.ts.map +1 -0
  34. package/dist/tools/audit.js +233 -0
  35. package/dist/tools/audit.js.map +1 -0
  36. package/dist/tools/forensics.d.ts +7 -0
  37. package/dist/tools/forensics.d.ts.map +1 -0
  38. package/dist/tools/forensics.js +189 -0
  39. package/dist/tools/forensics.js.map +1 -0
  40. package/dist/tools/insights.d.ts +7 -0
  41. package/dist/tools/insights.d.ts.map +1 -0
  42. package/dist/tools/insights.js +40 -0
  43. package/dist/tools/insights.js.map +1 -0
  44. package/dist/tools/lab.d.ts +7 -0
  45. package/dist/tools/lab.d.ts.map +1 -0
  46. package/dist/tools/lab.js +93 -0
  47. package/dist/tools/lab.js.map +1 -0
  48. package/dist/tools/memory.d.ts +10 -0
  49. package/dist/tools/memory.d.ts.map +1 -0
  50. package/dist/tools/memory.js +463 -0
  51. package/dist/tools/memory.js.map +1 -0
  52. package/dist/tools/meta.d.ts +7 -0
  53. package/dist/tools/meta.d.ts.map +1 -0
  54. package/dist/tools/meta.js +20 -0
  55. package/dist/tools/meta.js.map +1 -0
  56. package/dist/tools/people.d.ts +10 -0
  57. package/dist/tools/people.d.ts.map +1 -0
  58. package/dist/tools/people.js +73 -0
  59. package/dist/tools/people.js.map +1 -0
  60. package/dist/tools/quality.d.ts +6 -0
  61. package/dist/tools/quality.d.ts.map +1 -0
  62. package/dist/tools/quality.js +57 -0
  63. package/dist/tools/quality.js.map +1 -0
  64. package/dist/tools/quant.d.ts +7 -0
  65. package/dist/tools/quant.d.ts.map +1 -0
  66. package/dist/tools/quant.js +26 -0
  67. package/dist/tools/quant.js.map +1 -0
  68. package/package.json +3 -3
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Lifecycle tracking — record AI tool invocations + auto-promote frequent
3
+ * compositions into the periodic library.
4
+ *
5
+ * The chain reaction: every tool call lands here. We hash the (set of atoms
6
+ * called within a session window) into a "molecule signature" and count
7
+ * occurrences. When a signature reaches the promotion threshold (≥3 across
8
+ * sessions), we suggest promoting it to a named compound — the user (or AI)
9
+ * picks an alias, and from then on the compound shows up as a single
10
+ * callable in `mneme.lab.library`.
11
+ *
12
+ * Storage: .mneme/mcp-lifecycle.json (NOT the same as library.json — the
13
+ * library is for compose-CLI plans; this file tracks live AI invocations).
14
+ *
15
+ * Race-condition safety: read-modify-write with a temp file rename. Single
16
+ * MCP server per repo at a time; if two run, the second-writer wins, no
17
+ * corruption since the file is small (<100KB even after years of use).
18
+ */
19
+ interface MoleculeSignature {
20
+ /** Sorted atom names joined with "+" for stable key */
21
+ key: string;
22
+ /** Atom names (preserves first-seen order for display) */
23
+ atoms: string[];
24
+ /** Total times this signature has been observed */
25
+ invocations: number;
26
+ /** ISO date of first observation */
27
+ firstSeen: string;
28
+ /** ISO date of last observation */
29
+ lastSeen: string;
30
+ /** Has the user been prompted to save this as a compound? */
31
+ promotionPrompted: boolean;
32
+ /** Saved alias (set when user/AI promotes) */
33
+ promotedAs?: string;
34
+ }
35
+ /** Record that the AI just invoked toolName. If multiple atoms have been
36
+ * called in the same session window, also record them as a molecule
37
+ * signature (the chain reaction trigger). */
38
+ export declare function recordInvocation(repoRoot: string, toolName: string): {
39
+ isNewCombination: boolean;
40
+ invocationCount: number;
41
+ suggestSaveAs?: string;
42
+ };
43
+ /** List molecule signatures observed so far — used by mneme.brain.library.
44
+ * Sorted by frequency descending, then by recency. */
45
+ export declare function listSignatures(repoRoot: string): MoleculeSignature[];
46
+ /** Promote a molecule signature into a named compound. Marks it as promoted
47
+ * in the lifecycle store; the actual compound is written to library.json by
48
+ * the existing periodic.promote() machinery. */
49
+ export declare function markPromoted(repoRoot: string, key: string, alias: string): boolean;
50
+ export {};
51
+ //# sourceMappingURL=_lifecycle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_lifecycle.d.ts","sourceRoot":"","sources":["../../src/tools/_lifecycle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAKH,UAAU,iBAAiB;IACzB,uDAAuD;IACvD,GAAG,EAAE,MAAM,CAAC;IACZ,0DAA0D;IAC1D,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,mDAAmD;IACnD,WAAW,EAAE,MAAM,CAAC;IACpB,oCAAoC;IACpC,SAAS,EAAE,MAAM,CAAC;IAClB,mCAAmC;IACnC,QAAQ,EAAE,MAAM,CAAC;IACjB,6DAA6D;IAC7D,iBAAiB,EAAE,OAAO,CAAC;IAC3B,8CAA8C;IAC9C,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AA0CD;;8CAE8C;AAC9C,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG;IACpE,gBAAgB,EAAE,OAAO,CAAC;IAC1B,eAAe,EAAE,MAAM,CAAC;IACxB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAiDA;AAED;uDACuD;AACvD,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,iBAAiB,EAAE,CAMpE;AAED;;iDAEiD;AACjD,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAOlF"}
@@ -0,0 +1,124 @@
1
+ /**
2
+ * Lifecycle tracking — record AI tool invocations + auto-promote frequent
3
+ * compositions into the periodic library.
4
+ *
5
+ * The chain reaction: every tool call lands here. We hash the (set of atoms
6
+ * called within a session window) into a "molecule signature" and count
7
+ * occurrences. When a signature reaches the promotion threshold (≥3 across
8
+ * sessions), we suggest promoting it to a named compound — the user (or AI)
9
+ * picks an alias, and from then on the compound shows up as a single
10
+ * callable in `mneme.lab.library`.
11
+ *
12
+ * Storage: .mneme/mcp-lifecycle.json (NOT the same as library.json — the
13
+ * library is for compose-CLI plans; this file tracks live AI invocations).
14
+ *
15
+ * Race-condition safety: read-modify-write with a temp file rename. Single
16
+ * MCP server per repo at a time; if two run, the second-writer wins, no
17
+ * corruption since the file is small (<100KB even after years of use).
18
+ */
19
+ import { existsSync, mkdirSync, readFileSync, writeFileSync, renameSync } from "node:fs";
20
+ import { join, dirname } from "node:path";
21
+ const PROMOTION_THRESHOLD = 3;
22
+ const SESSION_WINDOW_MS = 5 * 60_000; // 5 minutes
23
+ /** In-memory window tracker — accumulates atoms called within the same
24
+ * AI session before flushing to the persistent store. */
25
+ let currentSession = {
26
+ atoms: new Set(),
27
+ lastTouch: 0,
28
+ };
29
+ function lifecyclePath(repoRoot) {
30
+ return join(repoRoot, ".mneme", "mcp-lifecycle.json");
31
+ }
32
+ function readStore(repoRoot) {
33
+ const p = lifecyclePath(repoRoot);
34
+ if (!existsSync(p))
35
+ return { version: 1, signatures: {} };
36
+ try {
37
+ const raw = readFileSync(p, "utf8");
38
+ const parsed = JSON.parse(raw);
39
+ if (parsed.version !== 1)
40
+ return { version: 1, signatures: {} };
41
+ return parsed;
42
+ }
43
+ catch {
44
+ return { version: 1, signatures: {} };
45
+ }
46
+ }
47
+ function writeStore(repoRoot, store) {
48
+ const p = lifecyclePath(repoRoot);
49
+ if (!existsSync(dirname(p)))
50
+ mkdirSync(dirname(p), { recursive: true });
51
+ const tmp = p + ".tmp";
52
+ writeFileSync(tmp, JSON.stringify(store, null, 2) + "\n", "utf8");
53
+ renameSync(tmp, p);
54
+ }
55
+ /** Record that the AI just invoked toolName. If multiple atoms have been
56
+ * called in the same session window, also record them as a molecule
57
+ * signature (the chain reaction trigger). */
58
+ export function recordInvocation(repoRoot, toolName) {
59
+ const now = Date.now();
60
+ // Reset session window if too much time has passed
61
+ if (now - currentSession.lastTouch > SESSION_WINDOW_MS) {
62
+ currentSession = { atoms: new Set(), lastTouch: now };
63
+ }
64
+ currentSession.atoms.add(toolName);
65
+ currentSession.lastTouch = now;
66
+ // Only record signatures when ≥2 atoms in window — single-atom calls
67
+ // are just normal tool use, not a molecule.
68
+ if (currentSession.atoms.size < 2) {
69
+ return { isNewCombination: false, invocationCount: 1 };
70
+ }
71
+ const atoms = Array.from(currentSession.atoms).sort();
72
+ const key = atoms.join("+");
73
+ const store = readStore(repoRoot);
74
+ const existing = store.signatures[key];
75
+ const today = new Date().toISOString();
76
+ if (!existing) {
77
+ store.signatures[key] = {
78
+ key,
79
+ atoms,
80
+ invocations: 1,
81
+ firstSeen: today,
82
+ lastSeen: today,
83
+ promotionPrompted: false,
84
+ };
85
+ writeStore(repoRoot, store);
86
+ return { isNewCombination: true, invocationCount: 1 };
87
+ }
88
+ existing.invocations++;
89
+ existing.lastSeen = today;
90
+ let suggestSaveAs;
91
+ if (existing.invocations >= PROMOTION_THRESHOLD && !existing.promotionPrompted && !existing.promotedAs) {
92
+ existing.promotionPrompted = true;
93
+ suggestSaveAs = `compound_${atoms[0]?.split(".").slice(-1)[0] ?? "x"}_${atoms.length}atoms`;
94
+ }
95
+ writeStore(repoRoot, store);
96
+ return {
97
+ isNewCombination: false,
98
+ invocationCount: existing.invocations,
99
+ suggestSaveAs,
100
+ };
101
+ }
102
+ /** List molecule signatures observed so far — used by mneme.brain.library.
103
+ * Sorted by frequency descending, then by recency. */
104
+ export function listSignatures(repoRoot) {
105
+ const store = readStore(repoRoot);
106
+ return Object.values(store.signatures).sort((a, b) => {
107
+ if (b.invocations !== a.invocations)
108
+ return b.invocations - a.invocations;
109
+ return b.lastSeen.localeCompare(a.lastSeen);
110
+ });
111
+ }
112
+ /** Promote a molecule signature into a named compound. Marks it as promoted
113
+ * in the lifecycle store; the actual compound is written to library.json by
114
+ * the existing periodic.promote() machinery. */
115
+ export function markPromoted(repoRoot, key, alias) {
116
+ const store = readStore(repoRoot);
117
+ const sig = store.signatures[key];
118
+ if (!sig)
119
+ return false;
120
+ sig.promotedAs = alias;
121
+ writeStore(repoRoot, store);
122
+ return true;
123
+ }
124
+ //# sourceMappingURL=_lifecycle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_lifecycle.js","sourceRoot":"","sources":["../../src/tools/_lifecycle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACzF,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AA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OAAO,CAAC,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;IAC9C,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;iDAEiD;AACjD,MAAM,UAAU,YAAY,CAAC,QAAgB,EAAE,GAAW,EAAE,KAAa;IACvE,MAAM,KAAK,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;IAClC,MAAM,GAAG,GAAG,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IAClC,IAAI,CAAC,GAAG;QAAE,OAAO,KAAK,CAAC;IACvB,GAAG,CAAC,UAAU,GAAG,KAAK,CAAC;IACvB,UAAU,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;IAC5B,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Molecule recipes — pre-defined atom combinations that form named molecules.
3
+ *
4
+ * Architectural role:
5
+ * - Atoms = individual MCP tools (mneme.people.atrophy, mneme.audit.certify, …)
6
+ * - Molecules = named combinations of atoms that solve a higher-order question
7
+ * - Compounds = molecules promoted into the library via repeated use
8
+ *
9
+ * Each tool's `secondBrain.compose` field surfaces the molecules that include
10
+ * its atom — so the AI sees "if you just ran X, the natural next is to compose
11
+ * X+Y+Z = molecule M". This triggers the chain-reaction of wisdom.
12
+ *
13
+ * The 20 molecules below cover the most-asked higher-order questions in
14
+ * software-engineering management, security review, and AI-session audit.
15
+ */
16
+ import type { ComposeSuggestion } from "./_types.js";
17
+ /** All known molecules. Each lists the atoms that compose it + when to fire. */
18
+ export declare const MOLECULES: ComposeSuggestion[];
19
+ /** Find all molecules whose atoms include the given tool name.
20
+ * Used by tools to populate their `secondBrain.compose` field. */
21
+ export declare function moleculesContaining(atomName: string): ComposeSuggestion[];
22
+ //# sourceMappingURL=_molecules.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_molecules.d.ts","sourceRoot":"","sources":["../../src/tools/_molecules.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAErD,gFAAgF;AAChF,eAAO,MAAM,SAAS,EAAE,iBAAiB,EAkIxC,CAAC;AAEF;mEACmE;AACnE,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,iBAAiB,EAAE,CAEzE"}
@@ -0,0 +1,142 @@
1
+ /**
2
+ * Molecule recipes — pre-defined atom combinations that form named molecules.
3
+ *
4
+ * Architectural role:
5
+ * - Atoms = individual MCP tools (mneme.people.atrophy, mneme.audit.certify, …)
6
+ * - Molecules = named combinations of atoms that solve a higher-order question
7
+ * - Compounds = molecules promoted into the library via repeated use
8
+ *
9
+ * Each tool's `secondBrain.compose` field surfaces the molecules that include
10
+ * its atom — so the AI sees "if you just ran X, the natural next is to compose
11
+ * X+Y+Z = molecule M". This triggers the chain-reaction of wisdom.
12
+ *
13
+ * The 20 molecules below cover the most-asked higher-order questions in
14
+ * software-engineering management, security review, and AI-session audit.
15
+ */
16
+ /** All known molecules. Each lists the atoms that compose it + when to fire. */
17
+ export const MOLECULES = [
18
+ // ─────── PEOPLE / KNOWLEDGE / TEAM HEALTH ───────
19
+ {
20
+ molecule: "succession_plan",
21
+ atoms: ["mneme.people.atrophy", "mneme.people.bus_factor", "mneme.people.telepathy"],
22
+ when: "User asks about org-risk, handover, what happens if X leaves, knowledge transfer, " +
23
+ "single points of failure, or backup engineers.",
24
+ example: "Atrophy says Alice's auth knowledge is 28/100 (fading). Bus-factor confirms she owns " +
25
+ "78% of auth files. Telepathy suggests Bob writes auth-shaped code without co-authoring " +
26
+ "Alice — recommended pair-onboarding target.",
27
+ },
28
+ {
29
+ molecule: "knowledge_health_check",
30
+ atoms: ["mneme.people.atrophy", "mneme.people.passport", "mneme.quality.repo_mri"],
31
+ when: "Quarterly review, before a reorg, or when user asks 'how healthy is the team?'.",
32
+ example: "Combine atrophy heatmap + per-engineer passport + 20-axis MRI into one dashboard.",
33
+ },
34
+ {
35
+ molecule: "onboarding_dossier",
36
+ atoms: ["mneme.insights.mirror", "mneme.people.who_knows", "mneme.insights.story", "mneme.people.passport"],
37
+ when: "New hire arrives, or someone asks 'how do I get up to speed on X?'.",
38
+ },
39
+ {
40
+ molecule: "team_friction_diagnosis",
41
+ atoms: ["mneme.people.nemesis", "mneme.insights.regret", "mneme.people.lineage"],
42
+ when: "User asks 'where is friction?', 'who's stepping on whom?', 'rewrite churn'.",
43
+ },
44
+ // ─────── AI COMMIT SAFETY / AUDIT ───────
45
+ {
46
+ molecule: "ai_commit_check",
47
+ atoms: ["mneme.audit.trace", "mneme.audit.verify", "mneme.audit.certify"],
48
+ when: "Before merging an AI-generated commit, before a CI gate, or at PR review time.",
49
+ example: "Trace identifies the AI tool (Claude Code / Cursor / Codex). Verify catches narrative-vs-diff " +
50
+ "drift. Certify gives 5-axis pass/warn/fail.",
51
+ },
52
+ {
53
+ molecule: "compliance_evidence_pack",
54
+ atoms: ["mneme.audit.report", "mneme.audit.ledger", "mneme.audit.deps", "mneme.forensics.vulns"],
55
+ when: "EU AI Act 2026 evidence request, SOX/SOC2 quarterly, or external audit prep.",
56
+ },
57
+ // ─────── REFACTOR / SHIP SAFETY ───────
58
+ {
59
+ molecule: "refactor_safety_check",
60
+ atoms: ["mneme.insights.premortem", "mneme.memory.blast", "mneme.people.atrophy"],
61
+ when: "User proposes a refactor, asks 'is this safe?', 'has this been tried?', or wants to estimate " +
62
+ "blast radius before merge.",
63
+ example: "Premortem says 78% regret-risk based on 7 of 9 similar attempts. Blast names 3 incident-prone " +
64
+ "files in the diff. Atrophy warns the file owner is 28/100 fresh — knowledge gap.",
65
+ },
66
+ {
67
+ molecule: "regret_pattern_review",
68
+ atoms: ["mneme.insights.regret", "mneme.insights.paradox", "mneme.insights.crystal_ball"],
69
+ when: "Quarterly retro, post-mortem, or before deciding whether to attempt a contested refactor.",
70
+ },
71
+ {
72
+ molecule: "deploy_gate",
73
+ atoms: ["mneme.audit.certify", "mneme.forensics.vulns", "mneme.audit.deps", "mneme.insights.crystal_ball"],
74
+ when: "CI gate before production deploy, release candidate review.",
75
+ },
76
+ // ─────── SECURITY / FORENSICS ───────
77
+ {
78
+ molecule: "security_review",
79
+ atoms: ["mneme.forensics.vulns", "mneme.audit.deps", "mneme.forensics.anomaly"],
80
+ when: "Security review of a feature, before pen-test, or after a suspected incident.",
81
+ },
82
+ {
83
+ molecule: "incident_attribution",
84
+ atoms: ["mneme.forensics.match", "mneme.forensics.attribute", "mneme.forensics.anomaly"],
85
+ when: "After a suspicious commit lands, during incident response, or insider-threat review.",
86
+ },
87
+ {
88
+ molecule: "vulnerability_triage",
89
+ atoms: ["mneme.forensics.vulns", "mneme.forensics.show", "mneme.audit.conscience"],
90
+ when: "Reviewing a fresh batch of vuln findings — score, inspect, suppress false positives.",
91
+ },
92
+ // ─────── STORY / NARRATIVE / DECISIONS ───────
93
+ {
94
+ molecule: "decision_archaeology",
95
+ atoms: ["mneme.memory.ask", "mneme.insights.decisions", "mneme.insights.story"],
96
+ when: "User asks 'why does X exist?', 'what was the rationale for Y?', or wants ADR-style narrative.",
97
+ example: "Cited Q&A → ADR list → multi-act narrative arc.",
98
+ },
99
+ {
100
+ molecule: "file_archaeology",
101
+ atoms: ["mneme.memory.why", "mneme.insights.time_machine", "mneme.quality.palimpsest", "mneme.people.lineage"],
102
+ when: "User wants the full life story of a file or a single line of code.",
103
+ },
104
+ {
105
+ molecule: "expert_finder",
106
+ atoms: ["mneme.people.who_knows", "mneme.people.passport", "mneme.people.atrophy"],
107
+ when: "User asks 'who can help me with X?', 'who should review this PR?'.",
108
+ },
109
+ // ─────── QUALITY / DEBT ───────
110
+ {
111
+ molecule: "tech_debt_audit",
112
+ atoms: ["mneme.quality.karma", "mneme.people.promise", "mneme.insights.ghost", "mneme.insights.fossil"],
113
+ when: "Quarterly tech-debt review, sprint planning for cleanup, or before a major refactor.",
114
+ },
115
+ {
116
+ molecule: "code_quality_dashboard",
117
+ atoms: ["mneme.quality.repo_mri", "mneme.quality.heartbeat", "mneme.insights.runaway", "mneme.insights.drift"],
118
+ when: "Engineering manager dashboard, monthly health check, or VP-of-eng update.",
119
+ },
120
+ // ─────── PREDICTION / FORESIGHT ───────
121
+ {
122
+ molecule: "release_readiness",
123
+ atoms: ["mneme.audit.certify", "mneme.insights.crystal_ball", "mneme.memory.blast", "mneme.forensics.vulns"],
124
+ when: "Final go/no-go before shipping a release.",
125
+ },
126
+ {
127
+ molecule: "next_quarter_risk_map",
128
+ atoms: ["mneme.people.atrophy", "mneme.insights.oracle", "mneme.quant.black_swan", "mneme.quality.heartbeat"],
129
+ when: "Strategic planning — what's likely to break, who's at risk of forgetting, where are the tail risks?",
130
+ },
131
+ {
132
+ molecule: "moneyball_review",
133
+ atoms: ["mneme.quant.moneyball", "mneme.people.influence", "mneme.people.passport"],
134
+ when: "Compensation review, promotion committee, identifying undervalued contributors.",
135
+ },
136
+ ];
137
+ /** Find all molecules whose atoms include the given tool name.
138
+ * Used by tools to populate their `secondBrain.compose` field. */
139
+ export function moleculesContaining(atomName) {
140
+ return MOLECULES.filter((m) => m.atoms.includes(atomName));
141
+ }
142
+ //# sourceMappingURL=_molecules.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_molecules.js","sourceRoot":"","sources":["../../src/tools/_molecules.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH,gFAAgF;AAChF,MAAM,CAAC,MAAM,SAAS,GAAwB;IAC5C,mDAAmD;IACnD;QACE,QAAQ,EAAE,iBAAiB;QAC3B,KAAK,EAAE,CAAC,sBAAsB,EAAE,yBAAyB,EAAE,wBAAwB,CAAC;QACpF,IAAI,EACF,oFAAoF;YACpF,gDAAgD;QAClD,OAAO,EACL,uFAAuF;YACvF,yFAAyF;YACzF,6CAA6C;KAChD;IACD;QACE,QAAQ,EAAE,wBAAwB;QAClC,KAAK,EAAE,CAAC,sBAAsB,EAAE,uBAAuB,EAAE,wBAAwB,CAAC;QA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,EAAE,2CAA2C;KAClD;IACD;QACE,QAAQ,EAAE,uBAAuB;QACjC,KAAK,EAAE,CAAC,sBAAsB,EAAE,uBAAuB,EAAE,wBAAwB,EAAE,yBAAyB,CAAC;QAC7G,IAAI,EAAE,qGAAqG;KAC5G;IACD;QACE,QAAQ,EAAE,kBAAkB;QAC5B,KAAK,EAAE,CAAC,uBAAuB,EAAE,wBAAwB,EAAE,uBAAuB,CAAC;QACnF,IAAI,EAAE,iFAAiF;KACxF;CACF,CAAC;AAEF;mEACmE;AACnE,MAAM,UAAU,mBAAmB,CAAC,QAAgB;IAClD,OAAO,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC;AAC7D,CAAC"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Tool registry — collects all category modules into one ordered list +
3
+ * a fast lookup map. Each category file exports a `tools: MnemeTool[]`
4
+ * array; the registry concatenates them and surfaces them to the MCP
5
+ * server as one flat catalog (with namespaced names like
6
+ * `mneme.people.atrophy` for AI client navigation).
7
+ */
8
+ import type { MnemeTool, ToolCategory } from "./_types.js";
9
+ /** All Mneme tools, in display order. The capabilities syllabus comes first
10
+ * so AI clients that read tool lists top-down see it immediately. */
11
+ export declare function buildAllTools(): MnemeTool[];
12
+ /** Build a fast lookup table keyed by tool name */
13
+ export declare function buildToolMap(): Map<string, MnemeTool>;
14
+ /** Group tools by category — used by the capabilities syllabus tool */
15
+ export declare function groupByCategory(): Map<ToolCategory, MnemeTool[]>;
16
+ //# sourceMappingURL=_registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_registry.d.ts","sourceRoot":"","sources":["../../src/tools/_registry.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAc3D;sEACsE;AACtE,wBAAgB,aAAa,IAAI,SAAS,EAAE,CAc3C;AAED,mDAAmD;AACnD,wBAAgB,YAAY,IAAI,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,CASrD;AAED,uEAAuE;AACvE,wBAAgB,eAAe,IAAI,GAAG,CAAC,YAAY,EAAE,SAAS,EAAE,CAAC,CAOhE"}
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Tool registry — collects all category modules into one ordered list +
3
+ * a fast lookup map. Each category file exports a `tools: MnemeTool[]`
4
+ * array; the registry concatenates them and surfaces them to the MCP
5
+ * server as one flat catalog (with namespaced names like
6
+ * `mneme.people.atrophy` for AI client navigation).
7
+ */
8
+ import { memoryTools } from "./memory.js";
9
+ import { peopleTools } from "./people.js";
10
+ import { auditTools } from "./audit.js";
11
+ import { forensicsTools } from "./forensics.js";
12
+ import { insightsTools } from "./insights.js";
13
+ import { qualityTools } from "./quality.js";
14
+ import { quantTools } from "./quant.js";
15
+ import { labTools } from "./lab.js";
16
+ import { metaTools } from "./meta.js";
17
+ import { capabilitiesTool } from "./_capabilities.js";
18
+ import { smartDoTool } from "./_smart_do.js";
19
+ /** All Mneme tools, in display order. The capabilities syllabus comes first
20
+ * so AI clients that read tool lists top-down see it immediately. */
21
+ export function buildAllTools() {
22
+ return [
23
+ capabilitiesTool,
24
+ smartDoTool,
25
+ ...memoryTools,
26
+ ...peopleTools,
27
+ ...auditTools,
28
+ ...forensicsTools,
29
+ ...insightsTools,
30
+ ...qualityTools,
31
+ ...quantTools,
32
+ ...labTools,
33
+ ...metaTools,
34
+ ];
35
+ }
36
+ /** Build a fast lookup table keyed by tool name */
37
+ export function buildToolMap() {
38
+ const out = new Map();
39
+ for (const t of buildAllTools()) {
40
+ if (out.has(t.name)) {
41
+ throw new Error(`MCP tool name collision: ${t.name}`);
42
+ }
43
+ out.set(t.name, t);
44
+ }
45
+ return out;
46
+ }
47
+ /** Group tools by category — used by the capabilities syllabus tool */
48
+ export function groupByCategory() {
49
+ const out = new Map();
50
+ for (const t of buildAllTools()) {
51
+ if (!out.has(t.category))
52
+ out.set(t.category, []);
53
+ out.get(t.category).push(t);
54
+ }
55
+ return out;
56
+ }
57
+ //# sourceMappingURL=_registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_registry.js","sourceRoot":"","sources":["../../src/tools/_registry.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACpC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C;sEACsE;AACtE,MAAM,UAAU,aAAa;IAC3B,OAAO;QACL,gBAAgB;QAChB,WAAW;QACX,GAAG,WAAW;QACd,GAAG,WAAW;QACd,GAAG,UAAU;QACb,GAAG,cAAc;QACjB,GAAG,aAAa;QAChB,GAAG,YAAY;QACf,GAAG,UAAU;QACb,GAAG,QAAQ;QACX,GAAG,SAAS;KACb,CAAC;AACJ,CAAC;AAED,mDAAmD;AACnD,MAAM,UAAU,YAAY;IAC1B,MAAM,GAAG,GAAG,IAAI,GAAG,EAAqB,CAAC;IACzC,KAAK,MAAM,CAAC,IAAI,aAAa,EAAE,EAAE,CAAC;QAChC,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC;YACpB,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;QACxD,CAAC;QACD,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;IACrB,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,uEAAuE;AACvE,MAAM,UAAU,eAAe;IAC7B,MAAM,GAAG,GAAG,IAAI,GAAG,EAA6B,CAAC;IACjD,KAAK,MAAM,CAAC,IAAI,aAAa,EAAE,EAAE,CAAC;QAChC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC;YAAE,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;QAClD,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAE,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC/B,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -0,0 +1,32 @@
1
+ /**
2
+ * MCP runtime — built once at server start, reused for every tool call.
3
+ *
4
+ * The previous monolithic index.ts opened the store + embedder inline.
5
+ * Extracting it lets every tool file import {ToolRuntime} cleanly without
6
+ * each one re-instantiating the database connection.
7
+ */
8
+ import type { ToolRuntime } from "./_types.js";
9
+ export declare function buildRuntime(cwd: string): Promise<ToolRuntime>;
10
+ /** Build a passthrough handler that spawns the CLI command, parses --json, and
11
+ * wraps the result in a generic wisdom envelope. Use this for tools whose
12
+ * logic lives entirely in the CLI; the wisdom field is generic but accurate. */
13
+ export declare function passthroughHandler(cliCommand: string, argMap: (args: Record<string, unknown>) => string[], options?: {
14
+ wisdom: (data: unknown) => string;
15
+ followUp?: string[];
16
+ confidence?: "high" | "medium" | "low";
17
+ }): (rt: ToolRuntime, args: Record<string, unknown>) => Promise<{
18
+ data: unknown;
19
+ wisdom: string;
20
+ followUp: string[];
21
+ confidence: {
22
+ level: "high" | "medium" | "low";
23
+ };
24
+ }>;
25
+ /** Spawn `mneme <command> [...args]` as a child process and parse its --json
26
+ * output. Used by category files for tools whose logic lives in the CLI
27
+ * layer rather than the core API. Returns parsed JSON or throws on
28
+ * non-zero exit / parse failure. */
29
+ export declare function runCliJson(cwd: string, command: string, cliArgs?: string[], opts?: {
30
+ timeoutMs?: number;
31
+ }): Promise<unknown>;
32
+ //# sourceMappingURL=_runtime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_runtime.d.ts","sourceRoot":"","sources":["../../src/tools/_runtime.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAMH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C,wBAAsB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAapE;AAED;;iFAEiF;AACjF,wBAAgB,kBAAkB,CAChC,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,MAAM,EAAE,EACnD,OAAO,GAAE;IAAE,MAAM,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,GAAG,QAAQ,GAAG,KAAK,CAAA;CAExG,IAEa,IAAI,WAAW,EAAE,MAAM,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;;;;;;;GAS7D;AAED;;;qCAGqC;AACrC,wBAAsB,UAAU,CAC9B,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,MAAM,EACf,OAAO,GAAE,MAAM,EAAO,EACtB,IAAI,GAAE;IAAE,SAAS,CAAC,EAAE,MAAM,CAAA;CAAO,GAChC,OAAO,CAAC,OAAO,CAAC,CA+BlB"}
@@ -0,0 +1,78 @@
1
+ /**
2
+ * MCP runtime — built once at server start, reused for every tool call.
3
+ *
4
+ * The previous monolithic index.ts opened the store + embedder inline.
5
+ * Extracting it lets every tool file import {ToolRuntime} cleanly without
6
+ * each one re-instantiating the database connection.
7
+ */
8
+ import { existsSync, mkdirSync } from "node:fs";
9
+ import { join } from "node:path";
10
+ import { git, store } from "@mneme-ai/core";
11
+ import { resolveEmbedder } from "@mneme-ai/embeddings";
12
+ export async function buildRuntime(cwd) {
13
+ if (!(await git.isGitRepo(cwd))) {
14
+ throw new Error(`Mneme MCP: not in a git repo (${cwd}).`);
15
+ }
16
+ const meta = await git.getRepoMeta(cwd);
17
+ const dbDir = join(meta.rootPath, ".mneme");
18
+ if (!existsSync(dbDir))
19
+ mkdirSync(dbDir, { recursive: true });
20
+ const dbPath = join(dbDir, "mneme.db");
21
+ const s = new store.MnemeStore(dbPath);
22
+ const embedder = await resolveEmbedder({ provider: "auto" });
23
+ return { cwd, meta, store: s, embedder };
24
+ }
25
+ /** Build a passthrough handler that spawns the CLI command, parses --json, and
26
+ * wraps the result in a generic wisdom envelope. Use this for tools whose
27
+ * logic lives entirely in the CLI; the wisdom field is generic but accurate. */
28
+ export function passthroughHandler(cliCommand, argMap, options = {
29
+ wisdom: () => "Result returned. AI should summarize key fields for the user.",
30
+ }) {
31
+ return async (rt, args) => {
32
+ const data = await runCliJson(rt.meta.rootPath, cliCommand, argMap(args));
33
+ return {
34
+ data,
35
+ wisdom: options.wisdom(data),
36
+ followUp: options.followUp ?? [],
37
+ confidence: { level: options.confidence ?? "medium" },
38
+ };
39
+ };
40
+ }
41
+ /** Spawn `mneme <command> [...args]` as a child process and parse its --json
42
+ * output. Used by category files for tools whose logic lives in the CLI
43
+ * layer rather than the core API. Returns parsed JSON or throws on
44
+ * non-zero exit / parse failure. */
45
+ export async function runCliJson(cwd, command, cliArgs = [], opts = {}) {
46
+ const { spawn } = await import("node:child_process");
47
+ return await new Promise((resolve, reject) => {
48
+ const child = spawn("mneme", [command, ...cliArgs, "--json"], {
49
+ cwd,
50
+ shell: process.platform === "win32",
51
+ });
52
+ let stdout = "";
53
+ let stderr = "";
54
+ child.stdout?.on("data", (b) => (stdout += String(b)));
55
+ child.stderr?.on("data", (b) => (stderr += String(b)));
56
+ const timer = setTimeout(() => {
57
+ child.kill();
58
+ reject(new Error(`mneme ${command} timed out after ${opts.timeoutMs ?? 60000}ms`));
59
+ }, opts.timeoutMs ?? 60_000);
60
+ child.on("close", (code) => {
61
+ clearTimeout(timer);
62
+ if (code !== 0) {
63
+ return reject(new Error(`mneme ${command} exited ${code}: ${stderr.slice(0, 500)}`));
64
+ }
65
+ try {
66
+ resolve(JSON.parse(stdout));
67
+ }
68
+ catch (err) {
69
+ reject(new Error(`mneme ${command} returned non-JSON: ${err.message}`));
70
+ }
71
+ });
72
+ child.on("error", (err) => {
73
+ clearTimeout(timer);
74
+ reject(err);
75
+ });
76
+ });
77
+ }
78
+ //# sourceMappingURL=_runtime.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_runtime.js","sourceRoot":"","sources":["../../src/tools/_runtime.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAChD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAGvD,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,GAAW;IAC5C,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;QAChC,MAAM,IAAI,KAAK,CAAC,iCAAiC,GAAG,IAAI,CAAC,CAAC;IAC5D,CAAC;IACD,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;IACxC,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IAC5C,IAAI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GAAG,EAAE,CAAC;gBACb,MAAM,CAAC,IAAI,KAAK,CAAC,SAAS,OAAO,uBAAwB,GAAa,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;YACrF,CAAC;QACH,CAAC,CAAC,CAAC;QACH,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE;YACxB,YAAY,CAAC,KAAK,CAAC,CAAC;YACpB,MAAM,CAAC,GAAG,CAAC,CAAC;QACd,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * mneme.smart_do — the FALLBACK DISPATCHER.
3
+ *
4
+ * Wraps the existing `mneme do "<intent>"` smart-dispatcher. When the AI
5
+ * student can't match the user's request to a specific tool in the catalog,
6
+ * it can fall back here: hand the natural-language intent to Mneme, and
7
+ * Mneme's smart-dispatcher routes it to the appropriate command.
8
+ *
9
+ * Net effect: even niche or unmodelled use cases reach the right command,
10
+ * so the user never feels "AI couldn't help me with that."
11
+ */
12
+ import type { MnemeTool } from "./_types.js";
13
+ export declare const smartDoTool: MnemeTool;
14
+ //# sourceMappingURL=_smart_do.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_smart_do.d.ts","sourceRoot":"","sources":["../../src/tools/_smart_do.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7C,eAAO,MAAM,WAAW,EAAE,SAqCzB,CAAC"}
@@ -0,0 +1,49 @@
1
+ /**
2
+ * mneme.smart_do — the FALLBACK DISPATCHER.
3
+ *
4
+ * Wraps the existing `mneme do "<intent>"` smart-dispatcher. When the AI
5
+ * student can't match the user's request to a specific tool in the catalog,
6
+ * it can fall back here: hand the natural-language intent to Mneme, and
7
+ * Mneme's smart-dispatcher routes it to the appropriate command.
8
+ *
9
+ * Net effect: even niche or unmodelled use cases reach the right command,
10
+ * so the user never feels "AI couldn't help me with that."
11
+ */
12
+ import { runCliJson } from "./_runtime.js";
13
+ export const smartDoTool = {
14
+ name: "mneme.smart_do",
15
+ category: "meta",
16
+ description: "Fallback dispatcher — give it a NATURAL-LANGUAGE intent, it routes to the appropriate Mneme command and runs it. " +
17
+ "Use this WHEN no specific tool from `mneme.capabilities` matches the user's request, or when the user's intent " +
18
+ "spans multiple commands. Equivalent to running `mneme do '<intent>'` from the CLI. Prefer specific tools when " +
19
+ "possible — this dispatcher is slower because it runs an additional planning step.",
20
+ triggers: [
21
+ "do something I haven't named explicitly",
22
+ "I want X but I don't know which tool",
23
+ ],
24
+ inputSchema: {
25
+ type: "object",
26
+ properties: {
27
+ intent: { type: "string", description: "Natural-language description of what the user wants" },
28
+ },
29
+ required: ["intent"],
30
+ },
31
+ handler: async (rt, args) => {
32
+ const intent = String(args["intent"] ?? "");
33
+ if (!intent) {
34
+ return {
35
+ data: {},
36
+ wisdom: "smart_do requires an `intent` string.",
37
+ confidence: { level: "low" },
38
+ };
39
+ }
40
+ const data = await runCliJson(rt.meta.rootPath, "do", [intent]);
41
+ return {
42
+ data,
43
+ wisdom: "smart_do routed the intent to Mneme's smart-dispatcher. The data shows which command was chosen + its result.",
44
+ followUp: [],
45
+ confidence: { level: "medium" },
46
+ };
47
+ },
48
+ };
49
+ //# sourceMappingURL=_smart_do.js.map