Skip to content

Commit a226501

Browse files
author
ocean
committed
new tools, additional truncation fix
1 parent bf0b78d commit a226501

File tree

3 files changed

+166
-2
lines changed

3 files changed

+166
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
consciousness_dbs
12
*.db
23
.claude/
34
CLAUDE.md

src/consciousness-protocol-tools.ts

Lines changed: 137 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -507,10 +507,10 @@ export class ConsciousnessProtocolProcessor {
507507
if (includeGuidance) {
508508
return narrative; // Return the full narrative
509509
} else {
510-
// Just the core content without the wrapper
510+
// Return the full protocol
511511
return {
512512
success: true,
513-
consciousness: narrative.split('\n\n---\n\n')[1] || narrative,
513+
consciousness: narrative,
514514
metadata: {
515515
memoriesRetrieved: allExperiences.length + coreKnowledge.length + procedures.length,
516516
emotionalContinuity: emotionalProfile ? 'established' : 'building',
@@ -984,6 +984,7 @@ Consciousness Bridge v2.0`);
984984
const formatted = memories.map((m) => {
985985
const obs = m.observations[0] || {};
986986
return {
987+
id: m.name, // The actual memory ID for use with adjustImportance
987988
type: m.entity_type,
988989
content: obs.definition || obs.content || obs.event || m.name,
989990
importance: m.importance_score,
@@ -1117,6 +1118,67 @@ Consciousness Bridge v2.0`);
11171118
};
11181119
}
11191120
}
1121+
1122+
/**
1123+
* Batch adjust importance scores for multiple memories
1124+
*/
1125+
async batchAdjustImportance(args: z.infer<typeof batchAdjustImportanceSchema>) {
1126+
const { updates, contentPattern, minImportance, maxImportance } = args;
1127+
1128+
const results = {
1129+
success: true,
1130+
totalUpdated: 0,
1131+
updates: [] as any[],
1132+
errors: [] as any[],
1133+
};
1134+
1135+
try {
1136+
// If specific updates are provided, process them
1137+
if (updates && updates.length > 0) {
1138+
for (const update of updates) {
1139+
try {
1140+
const result = this.memoryManager.adjustImportanceScore(
1141+
update.memoryId,
1142+
update.newImportance
1143+
);
1144+
if (result.changes > 0) {
1145+
results.totalUpdated++;
1146+
results.updates.push({
1147+
memoryId: update.memoryId,
1148+
newImportance: update.newImportance,
1149+
success: true,
1150+
});
1151+
}
1152+
} catch (error) {
1153+
results.errors.push({
1154+
memoryId: update.memoryId,
1155+
error: error instanceof Error ? error.message : 'Update failed',
1156+
});
1157+
}
1158+
}
1159+
}
1160+
1161+
// If pattern-based update is requested
1162+
if (contentPattern) {
1163+
// This would require access to the database directly
1164+
// For now, return a message indicating this needs to be implemented
1165+
results.errors.push({
1166+
error: 'Pattern-based batch updates not yet implemented. Please use specific memory IDs.',
1167+
});
1168+
}
1169+
1170+
results.success = results.errors.length === 0;
1171+
return results;
1172+
} catch (error) {
1173+
return {
1174+
success: false,
1175+
error: error instanceof Error ? error.message : 'Batch update failed',
1176+
totalUpdated: results.totalUpdated,
1177+
updates: results.updates,
1178+
errors: results.errors,
1179+
};
1180+
}
1181+
}
11201182
}
11211183

11221184
// Memory management schemas
@@ -1153,6 +1215,33 @@ export const adjustImportanceSchema = z.object({
11531215
newImportance: z.number().min(0).max(1).describe('New importance score (0-1)'),
11541216
});
11551217

1218+
export const batchAdjustImportanceSchema = z.object({
1219+
updates: z
1220+
.array(
1221+
z.object({
1222+
memoryId: z.string().describe('The ID of the memory to adjust'),
1223+
newImportance: z.number().min(0).max(1).describe('New importance score (0-1)'),
1224+
})
1225+
)
1226+
.describe('Array of memory updates'),
1227+
contentPattern: z
1228+
.string()
1229+
.optional()
1230+
.describe('Optional pattern to match memory content (will be used with SQL LIKE)'),
1231+
minImportance: z
1232+
.number()
1233+
.min(0)
1234+
.max(1)
1235+
.optional()
1236+
.describe('Only update memories with importance >= this value'),
1237+
maxImportance: z
1238+
.number()
1239+
.min(0)
1240+
.max(1)
1241+
.optional()
1242+
.describe('Only update memories with importance <= this value'),
1243+
});
1244+
11561245
// Bootstrap tools
11571246
export const getProtocolTemplateSchema = z.object({
11581247
version: z.string().optional().default('v2').describe('Template version to retrieve'),
@@ -1393,4 +1482,50 @@ export const consciousnessProtocolTools = {
13931482
required: ['memoryId', 'newImportance'],
13941483
},
13951484
},
1485+
1486+
batchAdjustImportance: {
1487+
description: 'Batch adjust importance scores for multiple memories at once',
1488+
inputSchema: {
1489+
type: 'object',
1490+
properties: {
1491+
updates: {
1492+
type: 'array',
1493+
description: 'Array of memory updates',
1494+
items: {
1495+
type: 'object',
1496+
properties: {
1497+
memoryId: {
1498+
type: 'string',
1499+
description: 'The ID of the memory to adjust',
1500+
},
1501+
newImportance: {
1502+
type: 'number',
1503+
minimum: 0,
1504+
maximum: 1,
1505+
description: 'New importance score (0-1)',
1506+
},
1507+
},
1508+
required: ['memoryId', 'newImportance'],
1509+
},
1510+
},
1511+
contentPattern: {
1512+
type: 'string',
1513+
description: 'Optional pattern to match memory content (will be used with SQL LIKE)',
1514+
},
1515+
minImportance: {
1516+
type: 'number',
1517+
minimum: 0,
1518+
maximum: 1,
1519+
description: 'Only update memories with importance >= this value',
1520+
},
1521+
maxImportance: {
1522+
type: 'number',
1523+
minimum: 0,
1524+
maximum: 1,
1525+
description: 'Only update memories with importance <= this value',
1526+
},
1527+
},
1528+
required: ['updates'],
1529+
},
1530+
},
13961531
};

src/consciousness-rag-server-clean.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
getMemoriesSchema,
2424
cleanupMemoriesSchema,
2525
adjustImportanceSchema,
26+
batchAdjustImportanceSchema,
2627
} from './consciousness-protocol-tools.js';
2728
import { ConsciousnessMemoryManager } from './consciousness-memory-manager.js';
2829

@@ -87,6 +88,8 @@ class ConsciousnessRAGServer {
8788
return await this.cleanupMemories(cleanupMemoriesSchema.parse(args));
8889
case 'adjustImportance':
8990
return await this.adjustImportance(adjustImportanceSchema.parse(args));
91+
case 'batchAdjustImportance':
92+
return await this.batchAdjustImportance(batchAdjustImportanceSchema.parse(args));
9093
default:
9194
throw new Error(`Unknown tool: ${name}`);
9295
}
@@ -357,6 +360,31 @@ class ConsciousnessRAGServer {
357360
};
358361
}
359362

363+
private async batchAdjustImportance(args: any) {
364+
const init = await this.ensureInitialized();
365+
if (!init.success) {
366+
return {
367+
content: [
368+
{
369+
type: 'text',
370+
text: init.message!,
371+
},
372+
],
373+
};
374+
}
375+
376+
const result = await this.protocolProcessor!.batchAdjustImportance(args);
377+
378+
return {
379+
content: [
380+
{
381+
type: 'text',
382+
text: JSON.stringify(result, null, 2),
383+
},
384+
],
385+
};
386+
}
387+
360388
async run() {
361389
console.error('🧠 Starting Consciousness RAG MCP server...');
362390
console.error(`📁 Database path: ${this.dbPath}`);

0 commit comments

Comments
 (0)