@levalicious/server-memory 0.0.0 → 0.0.1

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 (2) hide show
  1. package/dist/index.js +137 -0
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -241,6 +241,129 @@ class KnowledgeGraphManager {
241
241
  });
242
242
  return Array.from(missingEntities);
243
243
  }
244
+ // BCL (Binary Combinatory Logic) evaluator
245
+ async evaluateBCL(program, maxSteps) {
246
+ let current = program;
247
+ let stepCount = 0;
248
+ // Find and apply one reduction rule to the leftmost applicable position
249
+ const applyOneRule = (term) => {
250
+ // Scan left-to-right for rule applications
251
+ for (let pos = 0; pos <= term.length - 6; pos++) { // minimum pattern "1100xy" needs at least 6 chars
252
+ // Rule 1: 1100xy → x
253
+ if (pos <= term.length - 6 && term.substring(pos, pos + 4) === '1100') {
254
+ let parsePos = pos + 4;
255
+ // Parse x
256
+ const xResult = this.parseBCLTerm(term, parsePos);
257
+ if (xResult.success) {
258
+ parsePos = xResult.nextPos;
259
+ // Parse y
260
+ const yResult = this.parseBCLTerm(term, parsePos);
261
+ if (yResult.success) {
262
+ // Apply Rule 1: 1100xy → x
263
+ const before = term.substring(0, pos);
264
+ const after = term.substring(yResult.nextPos);
265
+ const newTerm = before + xResult.term + after;
266
+ return {
267
+ newTerm,
268
+ applied: true,
269
+ rule: `Rule 1: 1100${xResult.term}${yResult.term} → ${xResult.term}`
270
+ };
271
+ }
272
+ }
273
+ }
274
+ // Rule 2: 11101xyz → 11xz1yz (need minimum 8 chars)
275
+ if (pos <= term.length - 8 && term.substring(pos, pos + 5) === '11101') {
276
+ let parsePos = pos + 5;
277
+ // Parse x
278
+ const xResult = this.parseBCLTerm(term, parsePos);
279
+ if (xResult.success) {
280
+ parsePos = xResult.nextPos;
281
+ // Parse y
282
+ const yResult = this.parseBCLTerm(term, parsePos);
283
+ if (yResult.success) {
284
+ parsePos = yResult.nextPos;
285
+ // Parse z
286
+ const zResult = this.parseBCLTerm(term, parsePos);
287
+ if (zResult.success) {
288
+ // Apply Rule 2: 11101xyz → 11xz1yz
289
+ const x = xResult.term;
290
+ const y = yResult.term;
291
+ const z = zResult.term;
292
+ const before = term.substring(0, pos);
293
+ const after = term.substring(zResult.nextPos);
294
+ const replacement = `11${x}${z}1${y}${z}`;
295
+ const newTerm = before + replacement + after;
296
+ return {
297
+ newTerm,
298
+ applied: true,
299
+ rule: `Rule 2: 11101${x}${y}${z} → 11${x}${z}1${y}${z}`
300
+ };
301
+ }
302
+ }
303
+ }
304
+ }
305
+ }
306
+ return { newTerm: term, applied: false, rule: '' };
307
+ };
308
+ // Validate input is a well-formed BCL term
309
+ const validation = this.parseBCLTerm(current, 0);
310
+ if (!validation.success || validation.nextPos !== current.length) {
311
+ return {
312
+ result: current,
313
+ info: `Error: Invalid BCL term - parse failed at position ${validation.nextPos}`,
314
+ halted: false
315
+ };
316
+ }
317
+ let max_size = current.length;
318
+ while (stepCount < maxSteps) {
319
+ const result = applyOneRule(current);
320
+ if (!result.applied) {
321
+ // Normal form reached - no more reductions possible
322
+ break;
323
+ }
324
+ current = result.newTerm;
325
+ if (current.length > max_size) {
326
+ max_size = current.length;
327
+ }
328
+ stepCount++;
329
+ }
330
+ const halted = stepCount < maxSteps;
331
+ return {
332
+ result: current,
333
+ info: `${stepCount} steps, max size ${max_size}`,
334
+ halted
335
+ };
336
+ }
337
+ // Helper function to parse a single BCL term from a given position
338
+ parseBCLTerm(input, startPos) {
339
+ if (startPos >= input.length) {
340
+ return { success: false, term: '', nextPos: startPos };
341
+ }
342
+ // Check for 00 (K combinator)
343
+ if (startPos + 1 < input.length && input.substring(startPos, startPos + 2) === '00') {
344
+ return { success: true, term: '00', nextPos: startPos + 2 };
345
+ }
346
+ // Check for 01 (S combinator)
347
+ if (startPos + 1 < input.length && input.substring(startPos, startPos + 2) === '01') {
348
+ return { success: true, term: '01', nextPos: startPos + 2 };
349
+ }
350
+ // Check for 1 (application)
351
+ if (input[startPos] === '1') {
352
+ // Parse first subterm
353
+ const leftResult = this.parseBCLTerm(input, startPos + 1);
354
+ if (!leftResult.success) {
355
+ return leftResult;
356
+ }
357
+ // Parse second subterm
358
+ const rightResult = this.parseBCLTerm(input, leftResult.nextPos);
359
+ if (!rightResult.success) {
360
+ return rightResult;
361
+ }
362
+ const term = '1' + leftResult.term + rightResult.term;
363
+ return { success: true, term, nextPos: rightResult.nextPos };
364
+ }
365
+ return { success: false, term: '', nextPos: startPos };
366
+ }
244
367
  }
245
368
  const knowledgeGraphManager = new KnowledgeGraphManager();
246
369
  // The server instance and tools exposed to Claude
@@ -516,6 +639,18 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
516
639
  properties: {},
517
640
  },
518
641
  },
642
+ {
643
+ name: "evaluate_bcl",
644
+ description: "Evaluate a Binary Combinatory Logic (BCL) program",
645
+ inputSchema: {
646
+ type: "object",
647
+ properties: {
648
+ program: { type: "string", description: "The BCL program as a binary string (syntax: T:=00|01|1TT) 00=K, 01=S, 1=application." },
649
+ maxSteps: { type: "number", description: "Maximum number of reduction steps to perform (default: 1000000)", default: 1000000 },
650
+ },
651
+ required: ["program"],
652
+ },
653
+ },
519
654
  ],
520
655
  };
521
656
  });
@@ -564,6 +699,8 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
564
699
  return { content: [{ type: "text", text: JSON.stringify(await knowledgeGraphManager.getOrphanedEntities(), null, 2) }] };
565
700
  case "validate_graph":
566
701
  return { content: [{ type: "text", text: JSON.stringify(await knowledgeGraphManager.validateGraph(), null, 2) }] };
702
+ case "evaluate_bcl":
703
+ return { content: [{ type: "text", text: JSON.stringify(await knowledgeGraphManager.evaluateBCL(args.program, args.maxSteps), null, 2) }] };
567
704
  default:
568
705
  throw new Error(`Unknown tool: ${name}`);
569
706
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@levalicious/server-memory",
3
- "version": "0.0.0",
3
+ "version": "0.0.1",
4
4
  "description": "MCP server for enabling memory for Claude through a knowledge graph",
5
5
  "license": "MIT",
6
6
  "author": "Levalicious",
@@ -26,4 +26,4 @@
26
26
  "shx": "^0.3.4",
27
27
  "typescript": "^5.6.2"
28
28
  }
29
- }
29
+ }