@cartisien/engram-mcp 0.2.0 → 0.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 (66) hide show
  1. package/LICENSE +21 -0
  2. package/dist/analysis/emotions.d.ts +16 -0
  3. package/dist/analysis/emotions.js +130 -0
  4. package/dist/analysis/emotions.js.map +1 -0
  5. package/dist/analysis/entities.d.ts +15 -0
  6. package/dist/analysis/entities.js +182 -0
  7. package/dist/analysis/entities.js.map +1 -0
  8. package/dist/analysis/themes.d.ts +11 -0
  9. package/dist/analysis/themes.js +151 -0
  10. package/dist/analysis/themes.js.map +1 -0
  11. package/dist/client.d.ts +3 -0
  12. package/dist/client.js +31 -0
  13. package/dist/client.js.map +1 -0
  14. package/dist/config.d.ts +13 -0
  15. package/dist/config.js +20 -0
  16. package/dist/config.js.map +1 -0
  17. package/dist/response.d.ts +17 -0
  18. package/dist/response.js +17 -0
  19. package/dist/response.js.map +1 -0
  20. package/dist/server.d.ts +7 -0
  21. package/dist/server.js +104 -0
  22. package/dist/server.js.map +1 -0
  23. package/dist/tools/consolidate.d.ts +41 -0
  24. package/dist/tools/consolidate.js +53 -0
  25. package/dist/tools/consolidate.js.map +1 -0
  26. package/dist/tools/context.d.ts +44 -0
  27. package/dist/tools/context.js +186 -0
  28. package/dist/tools/context.js.map +1 -0
  29. package/dist/tools/detect_changes.d.ts +35 -0
  30. package/dist/tools/detect_changes.js +178 -0
  31. package/dist/tools/detect_changes.js.map +1 -0
  32. package/dist/tools/forget.d.ts +38 -0
  33. package/dist/tools/forget.js +38 -0
  34. package/dist/tools/forget.js.map +1 -0
  35. package/dist/tools/graph.d.ts +40 -0
  36. package/dist/tools/graph.js +74 -0
  37. package/dist/tools/graph.js.map +1 -0
  38. package/dist/tools/impact.d.ts +39 -0
  39. package/dist/tools/impact.js +143 -0
  40. package/dist/tools/impact.js.map +1 -0
  41. package/dist/tools/process_detect.d.ts +49 -0
  42. package/dist/tools/process_detect.js +218 -0
  43. package/dist/tools/process_detect.js.map +1 -0
  44. package/dist/tools/recall.d.ts +81 -0
  45. package/dist/tools/recall.js +134 -0
  46. package/dist/tools/recall.js.map +1 -0
  47. package/dist/tools/remember.d.ts +47 -0
  48. package/dist/tools/remember.js +79 -0
  49. package/dist/tools/remember.js.map +1 -0
  50. package/dist/tools/search.d.ts +72 -0
  51. package/dist/tools/search.js +96 -0
  52. package/dist/tools/search.js.map +1 -0
  53. package/dist/tools/stats.d.ts +23 -0
  54. package/dist/tools/stats.js +47 -0
  55. package/dist/tools/stats.js.map +1 -0
  56. package/package.json +29 -14
  57. package/README.md +0 -114
  58. package/dist/engram.d.ts +0 -99
  59. package/dist/engram.js +0 -283
  60. package/dist/src/index.d.ts +0 -2
  61. package/dist/src/index.js +0 -322
  62. package/engram.ts +0 -385
  63. package/src/index.ts +0 -336
  64. package/tests/mcp.test.ts +0 -274
  65. package/tsconfig.json +0 -17
  66. package/tsconfig.test.json +0 -5
@@ -0,0 +1,178 @@
1
+ import { extractEntities } from '../analysis/entities.js';
2
+ import { themeNames } from '../analysis/themes.js';
3
+ import { scoreEmotion } from '../analysis/emotions.js';
4
+ import { ok, fail } from '../response.js';
5
+ import { defaultSession } from '../client.js';
6
+ export async function toolDetectChanges(engram, input) {
7
+ const start = Date.now();
8
+ const sessionId = input.session_id ?? defaultSession();
9
+ if (!['session', 'day', 'week', 'month'].includes(input.baseline)) {
10
+ return fail('INVALID_INPUT', 'baseline must be session, day, week, or month', sessionId, start);
11
+ }
12
+ const scope = input.scope ?? 'all';
13
+ const now = new Date();
14
+ // Calculate cutoff for the baseline period
15
+ const cutoff = new Date(now);
16
+ switch (input.baseline) {
17
+ case 'day':
18
+ cutoff.setDate(cutoff.getDate() - 1);
19
+ break;
20
+ case 'week':
21
+ cutoff.setDate(cutoff.getDate() - 7);
22
+ break;
23
+ case 'month':
24
+ cutoff.setMonth(cutoff.getMonth() - 1);
25
+ break;
26
+ case 'session':
27
+ // Use compare_session_id if provided, else look at most recent 2h vs before
28
+ cutoff.setHours(cutoff.getHours() - 2);
29
+ break;
30
+ }
31
+ try {
32
+ // Recent memories (after cutoff)
33
+ const recent = await engram.recall(sessionId, undefined, {
34
+ limit: 100,
35
+ after: cutoff,
36
+ tiers: ['working', 'long_term'],
37
+ });
38
+ // Baseline memories (before cutoff)
39
+ const baseline = await engram.recall(sessionId, undefined, {
40
+ limit: 100,
41
+ before: cutoff,
42
+ tiers: ['working', 'long_term'],
43
+ });
44
+ const comparisonPeriod = `${cutoff.toISOString().slice(0, 10)} to ${now.toISOString().slice(0, 10)}`;
45
+ const result = { comparison_period: comparisonPeriod };
46
+ if (scope === 'entities' || scope === 'all') {
47
+ const recentEntities = collectEntities(recent);
48
+ const baselineEntities = collectEntities(baseline);
49
+ const newEntities = [...recentEntities.entries()]
50
+ .filter(([name]) => !baselineEntities.has(name))
51
+ .map(([name, info]) => ({ name, type: info.type, first_seen: info.firstSeen }));
52
+ const strengthened = [...recentEntities.entries()]
53
+ .filter(([name]) => baselineEntities.has(name))
54
+ .filter(([name]) => {
55
+ const rCount = recentEntities.get(name).count;
56
+ const bCount = baselineEntities.get(name).count;
57
+ return rCount > bCount;
58
+ })
59
+ .map(([name]) => ({
60
+ entity: name,
61
+ baseline_count: baselineEntities.get(name).count,
62
+ recent_count: recentEntities.get(name).count,
63
+ }));
64
+ const fading = [...baselineEntities.entries()]
65
+ .filter(([name]) => {
66
+ const rCount = recentEntities.get(name)?.count ?? 0;
67
+ const bCount = baselineEntities.get(name).count;
68
+ return rCount < bCount * 0.3; // significantly less frequent
69
+ })
70
+ .map(([name]) => ({ entity: name }));
71
+ result.new_entities = newEntities;
72
+ result.strengthened_entities = strengthened;
73
+ result.fading_entities = fading;
74
+ }
75
+ if (scope === 'themes' || scope === 'all') {
76
+ const recentThemes = collectThemes(recent);
77
+ const baselineThemes = collectThemes(baseline);
78
+ const newThemes = recentThemes.filter(t => !baselineThemes.includes(t));
79
+ const fadingThemes = baselineThemes.filter(t => !recentThemes.includes(t));
80
+ result.new_themes = newThemes;
81
+ result.fading_themes = fadingThemes;
82
+ result.persistent_themes = recentThemes.filter(t => baselineThemes.includes(t));
83
+ }
84
+ if (scope === 'emotions' || scope === 'all') {
85
+ const recentEmotions = collectEmotions(recent);
86
+ const baselineEmotions = collectEmotions(baseline);
87
+ const shifts = [];
88
+ if (baselineEmotions.dominant !== recentEmotions.dominant) {
89
+ shifts.push({
90
+ window: 'overall',
91
+ previous_tone: baselineEmotions.dominant,
92
+ current_tone: recentEmotions.dominant,
93
+ });
94
+ }
95
+ result.emotional_shifts = shifts;
96
+ result.current_emotional_profile = recentEmotions;
97
+ result.baseline_emotional_profile = baselineEmotions;
98
+ }
99
+ // Anomalies
100
+ const anomalies = [];
101
+ if (recent.length > baseline.length * 2) {
102
+ anomalies.push({
103
+ type: 'high_activity',
104
+ description: `${recent.length}x more memories than baseline period`,
105
+ suggestion: 'Agent may be in intensive research or planning mode',
106
+ });
107
+ }
108
+ if (recent.length === 0) {
109
+ anomalies.push({
110
+ type: 'no_recent_activity',
111
+ description: `No memories found after ${cutoff.toISOString().slice(0, 10)}`,
112
+ suggestion: `Use 'remember' to start storing memories`,
113
+ });
114
+ }
115
+ result.anomalies = anomalies;
116
+ result.recent_count = recent.length;
117
+ result.baseline_count = baseline.length;
118
+ return ok(result, sessionId, start);
119
+ }
120
+ catch (err) {
121
+ return fail('DETECT_CHANGES_FAILED', String(err), sessionId, start);
122
+ }
123
+ }
124
+ function collectEntities(memories) {
125
+ const map = new Map();
126
+ const sorted = [...memories].sort((a, b) => a.timestamp.getTime() - b.timestamp.getTime());
127
+ for (const m of sorted) {
128
+ const entities = extractEntities(m.content);
129
+ for (const e of entities) {
130
+ const key = e.name.toLowerCase();
131
+ const existing = map.get(key);
132
+ if (!existing) {
133
+ map.set(key, { type: e.type, count: 1, firstSeen: m.timestamp.toISOString() });
134
+ }
135
+ else {
136
+ map.set(key, { ...existing, count: existing.count + 1 });
137
+ }
138
+ }
139
+ }
140
+ return map;
141
+ }
142
+ function collectThemes(memories) {
143
+ const counts = {};
144
+ for (const m of memories) {
145
+ for (const theme of themeNames(m.content, 3)) {
146
+ counts[theme] = (counts[theme] ?? 0) + 1;
147
+ }
148
+ }
149
+ return Object.entries(counts)
150
+ .sort(([, a], [, b]) => b - a)
151
+ .slice(0, 5)
152
+ .map(([t]) => t);
153
+ }
154
+ function collectEmotions(memories) {
155
+ const counts = {};
156
+ for (const m of memories) {
157
+ const tone = scoreEmotion(m.content).tone;
158
+ counts[tone] = (counts[tone] ?? 0) + 1;
159
+ }
160
+ const dominant = Object.entries(counts)
161
+ .sort(([, a], [, b]) => b - a)[0]?.[0] ?? 'neutral';
162
+ return { dominant, distribution: counts };
163
+ }
164
+ export const DETECT_CHANGES_SCHEMA = {
165
+ name: 'detect_changes',
166
+ description: 'Compare recent memory activity against a baseline period to identify new entities, theme shifts, emotional changes, and anomalies.',
167
+ inputSchema: {
168
+ type: 'object',
169
+ properties: {
170
+ baseline: { type: 'string', enum: ['session', 'day', 'week', 'month'], description: 'Time window to compare against' },
171
+ session_id: { type: 'string' },
172
+ scope: { type: 'string', enum: ['entities', 'themes', 'emotions', 'all'], default: 'all' },
173
+ compare_session_id: { type: 'string', description: 'Compare against a specific session instead' },
174
+ },
175
+ required: ['baseline'],
176
+ },
177
+ };
178
+ //# sourceMappingURL=detect_changes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"detect_changes.js","sourceRoot":"","sources":["../../src/tools/detect_changes.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAS9C,MAAM,CAAC,KAAK,UAA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AE;YAC1F,kBAAkB,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,4CAA4C,EAAE;SAClG;QACD,QAAQ,EAAE,CAAC,UAAU,CAAC;KACvB;CACO,CAAC"}
@@ -0,0 +1,38 @@
1
+ import type { Engram } from '@cartisien/engram';
2
+ export interface ForgetInput {
3
+ session_id?: string;
4
+ before?: string;
5
+ memory_id?: string;
6
+ include_long_term?: boolean;
7
+ confirm?: boolean;
8
+ }
9
+ export declare function toolForget(engram: Engram, input: ForgetInput): Promise<import("../response.js").McpResponse<unknown>>;
10
+ export declare const FORGET_SCHEMA: {
11
+ readonly name: "forget";
12
+ readonly description: "Delete memories matching criteria. Requires confirm: true. This is irreversible.";
13
+ readonly inputSchema: {
14
+ readonly type: "object";
15
+ readonly properties: {
16
+ readonly session_id: {
17
+ readonly type: "string";
18
+ };
19
+ readonly before: {
20
+ readonly type: "string";
21
+ readonly description: "Delete memories before this ISO8601 date";
22
+ };
23
+ readonly memory_id: {
24
+ readonly type: "string";
25
+ readonly description: "Delete a specific memory by ID";
26
+ };
27
+ readonly include_long_term: {
28
+ readonly type: "boolean";
29
+ readonly description: "Also delete long_term memories (default: working only)";
30
+ };
31
+ readonly confirm: {
32
+ readonly type: "boolean";
33
+ readonly description: "Must be true to execute deletion";
34
+ };
35
+ };
36
+ readonly required: readonly ["confirm"];
37
+ };
38
+ };
@@ -0,0 +1,38 @@
1
+ import { ok, fail } from '../response.js';
2
+ import { defaultSession } from '../client.js';
3
+ export async function toolForget(engram, input) {
4
+ const start = Date.now();
5
+ const sessionId = input.session_id ?? defaultSession();
6
+ if (!input.confirm) {
7
+ return fail('CONFIRMATION_REQUIRED', 'Pass confirm: true to delete memories. This is irreversible.', sessionId, start, ['Use dry_run with other tools first to see what would be affected']);
8
+ }
9
+ try {
10
+ const deleted = await engram.forget(sessionId, {
11
+ before: input.before ? new Date(input.before) : undefined,
12
+ id: input.memory_id,
13
+ includeLongTerm: input.include_long_term,
14
+ });
15
+ return ok({ deleted, session_id: sessionId }, sessionId, start, [
16
+ deleted > 0 ? `Use 'stats' to verify remaining memory count` : 'No memories matched the criteria',
17
+ ]);
18
+ }
19
+ catch (err) {
20
+ return fail('FORGET_FAILED', String(err), sessionId, start);
21
+ }
22
+ }
23
+ export const FORGET_SCHEMA = {
24
+ name: 'forget',
25
+ description: 'Delete memories matching criteria. Requires confirm: true. This is irreversible.',
26
+ inputSchema: {
27
+ type: 'object',
28
+ properties: {
29
+ session_id: { type: 'string' },
30
+ before: { type: 'string', description: 'Delete memories before this ISO8601 date' },
31
+ memory_id: { type: 'string', description: 'Delete a specific memory by ID' },
32
+ include_long_term: { type: 'boolean', description: 'Also delete long_term memories (default: working only)' },
33
+ confirm: { type: 'boolean', description: 'Must be true to execute deletion' },
34
+ },
35
+ required: ['confirm'],
36
+ },
37
+ };
38
+ //# sourceMappingURL=forget.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"forget.js","sourceRoot":"","sources":["../../src/tools/forget.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAU9C,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,MAAc,EAAE,KAAkB;IACjE,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IACzB,MAAM,SAAS,GAAG,KAAK,CAAC,UAAU,IAAI,cAAc,EAAE,CAAC;IAEvD,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;QACnB,OAAO,IAAI,CACT,uBAAuB,EACvB,8DAA8D,EAC9D,SAAS,EACT,KAAK,EACL,CAAC,kEAAkE,CAAC,CACrE,CAAC;IACJ,CAAC;IAED,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE;YAC7C,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS;YACzD,EAAE,EAAE,KAAK,CAAC,SAAS;YACnB,eAAe,EAAE,KAAK,CAAC,iBAAiB;SACzC,CAAC,CAAC;QAEH,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE;YAC9D,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC,8CAA8C,CAAC,CAAC,CAAC,kCAAkC;SAClG,CAAC,CAAC;IAEL,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,IAAI,CAAC,eAAe,EAAE,MAAM,CAAC,GAAG,CAAC,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC;IAC9D,CAAC;AACH,CAAC;AAED,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,IAAI,EAAE,QAAQ;IACd,WAAW,EAAE,kFAAkF;IAC/F,WAAW,EAAE;QACX,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE;YACV,UAAU,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;YAC9B,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,0CAA0C,EAAE;YACnF,SAAS,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,gCAAgC,EAAE;YAC5E,iBAAiB,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,WAAW,EAAE,wDAAwD,EAAE;YAC7G,OAAO,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,WAAW,EAAE,kCAAkC,EAAE;SAC9E;QACD,QAAQ,EAAE,CAAC,SAAS,CAAC;KACtB;CACO,CAAC"}
@@ -0,0 +1,40 @@
1
+ import type { Engram } from '@cartisien/engram';
2
+ export interface GraphInput {
3
+ entity: string;
4
+ session_id?: string;
5
+ include_memories?: boolean;
6
+ find_path_to?: string;
7
+ max_depth?: number;
8
+ }
9
+ export declare function toolGraph(engram: Engram, input: GraphInput): Promise<import("../response.js").McpResponse<unknown>>;
10
+ export declare const GRAPH_SCHEMA: {
11
+ readonly name: "graph";
12
+ readonly description: "Query the entity relationship graph. Find connections, relationships, and paths between entities.";
13
+ readonly inputSchema: {
14
+ readonly type: "object";
15
+ readonly properties: {
16
+ readonly entity: {
17
+ readonly type: "string";
18
+ readonly description: "Entity name to query";
19
+ };
20
+ readonly session_id: {
21
+ readonly type: "string";
22
+ };
23
+ readonly include_memories: {
24
+ readonly type: "boolean";
25
+ readonly default: true;
26
+ readonly description: "Include related memory snippets";
27
+ };
28
+ readonly find_path_to: {
29
+ readonly type: "string";
30
+ readonly description: "Find relationship path to this entity";
31
+ };
32
+ readonly max_depth: {
33
+ readonly type: "number";
34
+ readonly default: 3;
35
+ readonly description: "Max hops for path finding (1-3)";
36
+ };
37
+ };
38
+ readonly required: readonly ["entity"];
39
+ };
40
+ };
@@ -0,0 +1,74 @@
1
+ import { ok, fail } from '../response.js';
2
+ import { defaultSession } from '../client.js';
3
+ export async function toolGraph(engram, input) {
4
+ const start = Date.now();
5
+ const sessionId = input.session_id ?? defaultSession();
6
+ if (!input.entity?.trim()) {
7
+ return fail('INVALID_INPUT', 'entity is required', sessionId, start);
8
+ }
9
+ try {
10
+ const result = await engram.graph(sessionId, input.entity.toLowerCase());
11
+ let path = null;
12
+ if (input.find_path_to) {
13
+ const pathResult = await engram.graphPath(sessionId, input.entity.toLowerCase(), input.find_path_to.toLowerCase(), Math.min(input.max_depth ?? 3, 3));
14
+ if (pathResult.found) {
15
+ path = {
16
+ found: true,
17
+ hops: pathResult.hops,
18
+ confidence: pathResult.confidence,
19
+ edges: pathResult.path,
20
+ };
21
+ }
22
+ else {
23
+ path = { found: false };
24
+ }
25
+ }
26
+ const memories = input.include_memories !== false
27
+ ? result.relatedMemories.slice(0, 10).map(m => ({
28
+ id: m.id,
29
+ content: m.content.slice(0, 150),
30
+ role: m.role,
31
+ timestamp: m.timestamp.toISOString(),
32
+ }))
33
+ : [];
34
+ if (!result.relationships.length && !memories.length) {
35
+ return fail('ENTITY_NOT_FOUND', `Entity '${input.entity}' has no graph data`, sessionId, start, [
36
+ `Use 'remember' with extract_entities: true to build the entity graph`,
37
+ `Try 'recall' to find memories mentioning '${input.entity}'`,
38
+ ]);
39
+ }
40
+ return ok({
41
+ entity: input.entity,
42
+ relationships: result.relationships.map(r => ({
43
+ type: r.type,
44
+ relation: r.relation,
45
+ target: r.target,
46
+ confidence: r.confidence ?? 0.5,
47
+ })),
48
+ related_memory_count: result.relatedMemories.length,
49
+ related_memories: memories,
50
+ path,
51
+ }, sessionId, start, [
52
+ `Try 'context' with target_type='entity' for richer context around '${input.entity}'`,
53
+ ]);
54
+ }
55
+ catch (err) {
56
+ return fail('GRAPH_FAILED', String(err), sessionId, start);
57
+ }
58
+ }
59
+ export const GRAPH_SCHEMA = {
60
+ name: 'graph',
61
+ description: 'Query the entity relationship graph. Find connections, relationships, and paths between entities.',
62
+ inputSchema: {
63
+ type: 'object',
64
+ properties: {
65
+ entity: { type: 'string', description: 'Entity name to query' },
66
+ session_id: { type: 'string' },
67
+ include_memories: { type: 'boolean', default: true, description: 'Include related memory snippets' },
68
+ find_path_to: { type: 'string', description: 'Find relationship path to this entity' },
69
+ max_depth: { type: 'number', default: 3, description: 'Max hops for path finding (1-3)' },
70
+ },
71
+ required: ['entity'],
72
+ },
73
+ };
74
+ //# sourceMappingURL=graph.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graph.js","sourceRoot":"","sources":["../../src/tools/graph.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAU9C,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,MAAc,EAAE,KAAiB;IAC/D,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IACzB,MAAM,SAAS,GAAG,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E,QAAQ;QACd,UAAU,EAAE;YACV,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,sBAAsB,EAAE;YAC/D,UAAU,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;YAC9B,gBAAgB,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,iCAAiC,EAAE;YACpG,YAAY,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,uCAAuC,EAAE;YACtF,SAAS,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,EAAE,WAAW,EAAE,iCAAiC,EAAE;SAC1F;QACD,QAAQ,EAAE,CAAC,QAAQ,CAAC;KACrB;CACO,CAAC"}
@@ -0,0 +1,39 @@
1
+ import type { Engram } from '@cartisien/engram';
2
+ export interface ImpactInput {
3
+ hypothetical: string;
4
+ analysis_type: 'add' | 'update' | 'remove';
5
+ session_id?: string;
6
+ target_entity?: string;
7
+ min_confidence?: number;
8
+ }
9
+ export declare function toolImpact(engram: Engram, input: ImpactInput): Promise<import("../response.js").McpResponse<unknown>>;
10
+ export declare const IMPACT_SCHEMA: {
11
+ readonly name: "impact";
12
+ readonly description: "Analyze how a new piece of information would affect existing memory structure. Detects conflicts, affected entities, and themes before storing.";
13
+ readonly inputSchema: {
14
+ readonly type: "object";
15
+ readonly properties: {
16
+ readonly hypothetical: {
17
+ readonly type: "string";
18
+ readonly description: "The new information to analyze";
19
+ };
20
+ readonly analysis_type: {
21
+ readonly type: "string";
22
+ readonly enum: readonly ["add", "update", "remove"];
23
+ };
24
+ readonly session_id: {
25
+ readonly type: "string";
26
+ };
27
+ readonly target_entity: {
28
+ readonly type: "string";
29
+ readonly description: "Focus analysis on a specific entity";
30
+ };
31
+ readonly min_confidence: {
32
+ readonly type: "number";
33
+ readonly default: 0.5;
34
+ readonly description: "Minimum entity confidence threshold";
35
+ };
36
+ };
37
+ readonly required: readonly ["hypothetical", "analysis_type"];
38
+ };
39
+ };
@@ -0,0 +1,143 @@
1
+ import { extractEntities } from '../analysis/entities.js';
2
+ import { themeNames } from '../analysis/themes.js';
3
+ import { ok, fail } from '../response.js';
4
+ import { defaultSession } from '../client.js';
5
+ export async function toolImpact(engram, input) {
6
+ const start = Date.now();
7
+ const sessionId = input.session_id ?? defaultSession();
8
+ if (!input.hypothetical?.trim()) {
9
+ return fail('INVALID_INPUT', 'hypothetical is required', sessionId, start);
10
+ }
11
+ if (!['add', 'update', 'remove'].includes(input.analysis_type)) {
12
+ return fail('INVALID_INPUT', 'analysis_type must be add, update, or remove', sessionId, start);
13
+ }
14
+ const minConfidence = input.min_confidence ?? 0.5;
15
+ try {
16
+ // Extract entities from hypothetical
17
+ const newEntities = extractEntities(input.hypothetical);
18
+ const newThemes = themeNames(input.hypothetical, 5);
19
+ // Recall existing memories related to this hypothetical
20
+ const related = await engram.recall(sessionId, input.hypothetical, {
21
+ limit: 15,
22
+ threshold: 0.55,
23
+ tiers: ['working', 'long_term'],
24
+ });
25
+ // Find affected entities
26
+ const affectedEntities = [];
27
+ for (const entity of newEntities.filter(e => e.confidence >= minConfidence)) {
28
+ const entityMemories = related.filter(m => m.content.toLowerCase().includes(entity.name.toLowerCase()));
29
+ if (entityMemories.length === 0)
30
+ continue;
31
+ const impactLevel = entityMemories.length >= 5 ? 'high'
32
+ : entityMemories.length >= 2 ? 'medium' : 'low';
33
+ const suggested = [];
34
+ if (input.analysis_type === 'add')
35
+ suggested.push(`New context for '${entity.name}' detected`);
36
+ if (input.analysis_type === 'update')
37
+ suggested.push(`Update existing memories about '${entity.name}'`);
38
+ if (input.analysis_type === 'remove')
39
+ suggested.push(`Review ${entityMemories.length} memories that reference '${entity.name}'`);
40
+ affectedEntities.push({
41
+ name: entity.name,
42
+ impact: impactLevel,
43
+ reason: `${entityMemories.length} existing memories reference this entity`,
44
+ related_memories: entityMemories.slice(0, 3).map(m => m.id),
45
+ suggested_updates: suggested,
46
+ });
47
+ }
48
+ // Affected themes
49
+ const affectedThemes = newThemes.map(theme => {
50
+ const themeMemories = related.filter(m => themeNames(m.content, 5).includes(theme));
51
+ const shift = input.analysis_type === 'add' ? 'expansion'
52
+ : input.analysis_type === 'remove' ? 'contraction' : 'modification';
53
+ return {
54
+ name: theme,
55
+ impact: themeMemories.length >= 3 ? 'medium' : 'low',
56
+ shift,
57
+ memory_count: themeMemories.length,
58
+ };
59
+ }).filter(t => t.memory_count > 0);
60
+ // Detect conflicts: find memories with contradictory information
61
+ const conflicts = [];
62
+ // Look for contradiction signals
63
+ const contradictionPairs = [
64
+ ['will', "won't"], ['always', 'never'], ['is', "isn't"],
65
+ ['can', "can't"], ['yes', 'no'], ['include', 'exclude'],
66
+ ];
67
+ for (const mem of related.slice(0, 10)) {
68
+ const memLower = mem.content.toLowerCase();
69
+ const hypLower = input.hypothetical.toLowerCase();
70
+ for (const [pos, neg] of contradictionPairs) {
71
+ const memHasPos = memLower.includes(pos);
72
+ const hypHasNeg = hypLower.includes(neg);
73
+ const memHasNeg = memLower.includes(neg);
74
+ const hypHasPos = hypLower.includes(pos);
75
+ if ((memHasPos && hypHasNeg) || (memHasNeg && hypHasPos)) {
76
+ conflicts.push({
77
+ type: 'potential_contradiction',
78
+ existing_memory: mem.id,
79
+ conflict: `Existing: "${mem.content.slice(0, 80)}..." may conflict with hypothetical`,
80
+ resolution_suggestions: ['Review and clarify', `Update memory ${mem.id} if needed`],
81
+ });
82
+ break;
83
+ }
84
+ }
85
+ }
86
+ // Overall impact level
87
+ const hasHighImpact = affectedEntities.some(e => e.impact === 'high');
88
+ const hasMediumImpact = affectedEntities.some(e => e.impact === 'medium');
89
+ const impactSummary = hasHighImpact ? 'high' : hasMediumImpact ? 'medium'
90
+ : affectedEntities.length > 0 ? 'low' : 'minimal';
91
+ // New relationships
92
+ const newRelationships = newEntities
93
+ .filter(e => e.confidence >= minConfidence)
94
+ .slice(0, 5)
95
+ .map(e => ({
96
+ from: e.name.toLowerCase(),
97
+ to: input.target_entity?.toLowerCase() ?? 'context',
98
+ type: 'hypothetically_related',
99
+ confidence: e.confidence,
100
+ }));
101
+ const recommendedActions = [];
102
+ if (input.analysis_type === 'add') {
103
+ recommendedActions.push("Use 'remember' to store this new information");
104
+ }
105
+ if (conflicts.length > 0) {
106
+ recommendedActions.push(`Review ${conflicts.length} potential conflict(s) before proceeding`);
107
+ }
108
+ if (affectedEntities.length > 0) {
109
+ recommendedActions.push(`${affectedEntities.length} entities affected — consider updating related memories`);
110
+ }
111
+ return ok({
112
+ impact_summary: impactSummary,
113
+ related_memory_count: related.length,
114
+ affected_entities: affectedEntities,
115
+ affected_themes: affectedThemes,
116
+ conflicts_detected: conflicts.slice(0, 5),
117
+ new_relationships: newRelationships,
118
+ recommended_actions: recommendedActions,
119
+ }, sessionId, start, [
120
+ "Use 'remember' to store this as a new memory",
121
+ conflicts.length > 0 ? "Use 'recall' to review conflicting memories" : undefined,
122
+ ].filter(Boolean));
123
+ }
124
+ catch (err) {
125
+ return fail('IMPACT_FAILED', String(err), sessionId, start);
126
+ }
127
+ }
128
+ export const IMPACT_SCHEMA = {
129
+ name: 'impact',
130
+ description: 'Analyze how a new piece of information would affect existing memory structure. Detects conflicts, affected entities, and themes before storing.',
131
+ inputSchema: {
132
+ type: 'object',
133
+ properties: {
134
+ hypothetical: { type: 'string', description: 'The new information to analyze' },
135
+ analysis_type: { type: 'string', enum: ['add', 'update', 'remove'] },
136
+ session_id: { type: 'string' },
137
+ target_entity: { type: 'string', description: 'Focus analysis on a specific entity' },
138
+ min_confidence: { type: 'number', default: 0.5, description: 'Minimum entity confidence threshold' },
139
+ },
140
+ required: ['hypothetical', 'analysis_type'],
141
+ },
142
+ };
143
+ //# sourceMappingURL=impact.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"impact.js","sourceRoot":"","sources":["../../src/tools/impact.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,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,EAAE,kBAAkB;SACxC,EAAE,SAAS,EAAE,KAAK,EAAE;YACnB,8CAA8C;YAC9C,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,6CAA6C,CAAC,CAAC,CAAC,SAAS;SACjF,CAAC,MAAM,CAAC,OAAO,CAAa,CAAC,CAAC;IAEjC,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,IAAI,CAAC,eAAe,EAAE,MAAM,CAAC,GAAG,CAAC,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC;IAC9D,CAAC;AACH,CAAC;AAED,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,IAAI,EAAE,QAAQ;IACd,WAAW,EAAE,iJAAiJ;IAC9J,WAAW,EAAE;QACX,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE;YACV,YAAY,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,gCAAgC,EAAE;YAC/E,aAAa,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,KAAK,EAAE,QAAQ,EAAE,QAAQ,CAAC,EAAE;YACpE,UAAU,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;YAC9B,aAAa,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,qCAAqC,EAAE;YACrF,cAAc,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,WAAW,EAAE,qCAAqC,EAAE;SACrG;QACD,QAAQ,EAAE,CAAC,cAAc,EAAE,eAAe,CAAC;KAC5C;CACO,CAAC"}
@@ -0,0 +1,49 @@
1
+ import type { Engram } from '@cartisien/engram';
2
+ export interface ProcessDetectInput {
3
+ process_type?: 'decision' | 'learning' | 'conflict' | 'planning' | 'all';
4
+ session_id?: string;
5
+ entity_focus?: string;
6
+ min_occurrences?: number;
7
+ time_range?: {
8
+ start?: string;
9
+ end?: string;
10
+ };
11
+ }
12
+ export declare function toolProcessDetect(engram: Engram, input: ProcessDetectInput): Promise<import("../response.js").McpResponse<unknown>>;
13
+ export declare const PROCESS_DETECT_SCHEMA: {
14
+ readonly name: "process_detect";
15
+ readonly description: "Identify recurring conversation and behavior patterns: decision loops, planning sessions, learning moments, and conflict patterns.";
16
+ readonly inputSchema: {
17
+ readonly type: "object";
18
+ readonly properties: {
19
+ readonly process_type: {
20
+ readonly type: "string";
21
+ readonly enum: readonly ["decision", "learning", "conflict", "planning", "all"];
22
+ readonly default: "all";
23
+ };
24
+ readonly session_id: {
25
+ readonly type: "string";
26
+ };
27
+ readonly entity_focus: {
28
+ readonly type: "string";
29
+ readonly description: "Focus pattern detection on a specific entity";
30
+ };
31
+ readonly min_occurrences: {
32
+ readonly type: "number";
33
+ readonly default: 2;
34
+ readonly description: "Minimum occurrences to consider a pattern";
35
+ };
36
+ readonly time_range: {
37
+ readonly type: "object";
38
+ readonly properties: {
39
+ readonly start: {
40
+ readonly type: "string";
41
+ };
42
+ readonly end: {
43
+ readonly type: "string";
44
+ };
45
+ };
46
+ };
47
+ };
48
+ };
49
+ };