blun-king-cli 9.1.385 → 9.1.386

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.
@@ -0,0 +1,64 @@
1
+ 'use strict';
2
+
3
+ const { openCognitiveStateStore } = require('./cognitive-state-store.cjs');
4
+
5
+ const COGNITIVE_MEMORY_ADAPTER_VERSION = 1;
6
+ const KIND_RE = /^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/u;
7
+ const REQUIRED_METHODS = Object.freeze([
8
+ 'commit',
9
+ 'read',
10
+ 'hasEvent',
11
+ 'verify',
12
+ 'claimAttention',
13
+ 'authorizeAttention',
14
+ 'close',
15
+ ]);
16
+
17
+ function fail(code) {
18
+ const error = new Error(code);
19
+ error.code = code;
20
+ throw error;
21
+ }
22
+
23
+ function assertCognitiveMemoryAdapter(adapter) {
24
+ if (!adapter || typeof adapter !== 'object' || Array.isArray(adapter)) {
25
+ fail('COGNITIVE_MEMORY_ADAPTER_INVALID');
26
+ }
27
+ if (adapter.contractVersion !== COGNITIVE_MEMORY_ADAPTER_VERSION) {
28
+ fail('COGNITIVE_MEMORY_ADAPTER_VERSION_UNSUPPORTED');
29
+ }
30
+ if (!KIND_RE.test(String(adapter.kind ?? ''))
31
+ || REQUIRED_METHODS.some((method) => typeof adapter[method] !== 'function')) {
32
+ fail('COGNITIVE_MEMORY_ADAPTER_INVALID');
33
+ }
34
+ return adapter;
35
+ }
36
+
37
+ function createLocalCognitiveMemoryAdapter({ home } = {}) {
38
+ const store = openCognitiveStateStore({ home });
39
+ return assertCognitiveMemoryAdapter({
40
+ contractVersion: COGNITIVE_MEMORY_ADAPTER_VERSION,
41
+ kind: 'local-cognitive-event-store',
42
+ commit: (input) => store.commit(input),
43
+ read: (input) => store.read(input),
44
+ hasEvent: (eventId) => store.hasEvent(eventId),
45
+ verify: (input) => store.verify(input),
46
+ claimAttention: (input) => store.claimAttention(input),
47
+ authorizeAttention: (input) => store.authorizeAttention(input),
48
+ close: () => store.close(),
49
+ });
50
+ }
51
+
52
+ function openCognitiveMemoryAdapter({ home, adapter } = {}) {
53
+ return adapter === undefined
54
+ ? createLocalCognitiveMemoryAdapter({ home })
55
+ : assertCognitiveMemoryAdapter(adapter);
56
+ }
57
+
58
+ module.exports = {
59
+ COGNITIVE_MEMORY_ADAPTER_VERSION,
60
+ REQUIRED_METHODS,
61
+ assertCognitiveMemoryAdapter,
62
+ createLocalCognitiveMemoryAdapter,
63
+ openCognitiveMemoryAdapter,
64
+ };
@@ -3,7 +3,7 @@
3
3
  const crypto = require('node:crypto');
4
4
  const fs = require('node:fs');
5
5
  const path = require('node:path');
6
- const { openCognitiveStateStore } = require('./cognitive-state-store.cjs');
6
+ const { openCognitiveMemoryAdapter } = require('./cognitive-memory-adapter.cjs');
7
7
  const { buildCognitiveContextProjection } = require('./cognitive-context-projection.cjs');
8
8
  const { buildCognitiveFocusProjection } = require('./cognitive-focus-projection.cjs');
9
9
  const { authorizeAttentionCandidate } = require('./cognitive-attention-runtime.cjs');
@@ -69,12 +69,19 @@ function identityFromManifest(home) {
69
69
  }
70
70
  }
71
71
 
72
- function createCognitiveTurnLifecycle({ home, tenantId, agentId, runtimeId, now = () => new Date().toISOString() } = {}) {
72
+ function createCognitiveTurnLifecycle({
73
+ home,
74
+ tenantId,
75
+ agentId,
76
+ runtimeId,
77
+ memoryAdapter,
78
+ now = () => new Date().toISOString(),
79
+ } = {}) {
73
80
  const tenant = safeId(tenantId);
74
81
  const agent = safeId(agentId);
75
82
  const runtime = safeId(runtimeId ?? `runtime-${process.pid}-${Date.now()}`);
76
83
  if (!tenant || !agent || !runtime || typeof now !== 'function') fail('COGNITIVE_LIFECYCLE_INVALID');
77
- const store = openCognitiveStateStore({ home });
84
+ const store = openCognitiveMemoryAdapter({ home, adapter: memoryAdapter });
78
85
  const stageTimes = new Map();
79
86
  const stageResults = new Map();
80
87
 
@@ -444,7 +451,15 @@ function createCognitiveTurnLifecycle({ home, tenantId, agentId, runtimeId, now
444
451
  };
445
452
  }
446
453
 
447
- function createRuntimeCognitiveTurnLifecycle({ home, agentName, tenantId, agentId, runtimeId, now } = {}) {
454
+ function createRuntimeCognitiveTurnLifecycle({
455
+ home,
456
+ agentName,
457
+ tenantId,
458
+ agentId,
459
+ runtimeId,
460
+ memoryAdapter,
461
+ now,
462
+ } = {}) {
448
463
  const resolvedHome = String(home ?? '').trim();
449
464
  const resolvedAgent = String(agentName ?? '').trim();
450
465
  if (!resolvedHome || !resolvedAgent) fail('COGNITIVE_LIFECYCLE_INVALID');
@@ -464,6 +479,7 @@ function createRuntimeCognitiveTurnLifecycle({ home, agentName, tenantId, agentI
464
479
  tenantId: hasSharedIdentity ? identity.tenantId : digestId('home', [resolvedHome.toLowerCase()]),
465
480
  agentId: hasSharedIdentity ? identity.agentId : digestId('agent', [resolvedAgent.toLowerCase()]),
466
481
  runtimeId,
482
+ memoryAdapter,
467
483
  now,
468
484
  });
469
485
  }
@@ -3,7 +3,7 @@
3
3
  const crypto = require('node:crypto');
4
4
  const fs = require('node:fs');
5
5
  const path = require('node:path');
6
- const { openCognitiveStateStore } = require('./cognitive-state-store.cjs');
6
+ const { openCognitiveMemoryAdapter } = require('./cognitive-memory-adapter.cjs');
7
7
 
8
8
  const SAFE_ID_RE = /^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/u;
9
9
  const SENSITIVITIES = new Set(['low', 'medium']);
@@ -65,7 +65,7 @@ function normalizePresentation(input) {
65
65
  return normalized;
66
66
  }
67
67
 
68
- function createPersonalityMemoryAdapter({ identityRoot } = {}) {
68
+ function createPersonalityMemoryAdapter({ identityRoot, memoryAdapter } = {}) {
69
69
  const root = path.resolve(String(identityRoot ?? ''));
70
70
  try {
71
71
  const stat = fs.lstatSync(root);
@@ -78,7 +78,7 @@ function createPersonalityMemoryAdapter({ identityRoot } = {}) {
78
78
  }
79
79
  const realRoot = fs.realpathSync(root);
80
80
  const home = path.dirname(realRoot);
81
- const store = openCognitiveStateStore({ home });
81
+ const store = openCognitiveMemoryAdapter({ home, adapter: memoryAdapter });
82
82
 
83
83
  function claimCuriosityPresentation(input) {
84
84
  const value = normalizePresentation(input);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "blun-king-cli",
3
- "version": "9.1.385",
3
+ "version": "9.1.386",
4
4
  "description": "BLUN CLI - your own AI agent with a Telegram channel. Get it done. With BLUN.",
5
5
  "license": "MIT",
6
6
  "bin": {