@sidurijs/core 1.0.0 → 1.0.2

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 (41) hide show
  1. package/LICENSE +190 -0
  2. package/dist/adversarial.test.js +27 -19
  3. package/dist/chat-contract.d.ts +9 -0
  4. package/dist/cognition-planner.d.ts +2 -2
  5. package/dist/container.d.ts +6 -4
  6. package/dist/container.js +1 -4
  7. package/dist/context-retriever.d.ts +5 -4
  8. package/dist/context-retriever.js +43 -25
  9. package/dist/conversational-teach.test.js +61 -53
  10. package/dist/evidence.d.ts +3 -3
  11. package/dist/gating.d.ts +2 -2
  12. package/dist/gating.js +1 -1
  13. package/dist/index.d.ts +43 -51
  14. package/dist/index.js +1 -1
  15. package/dist/intent-classifier.d.ts +1 -1
  16. package/dist/intent-classifier.js +4 -4
  17. package/dist/intent-classifier.test.js +1 -1
  18. package/dist/{memory-settler.d.ts → interaction-settler.d.ts} +12 -11
  19. package/dist/interaction-settler.js +173 -0
  20. package/dist/perception-cycle.test.js +18 -34
  21. package/dist/perception-pipeline.d.ts +6 -5
  22. package/dist/perception-pipeline.js +17 -15
  23. package/dist/prompt-compiler.d.ts +1 -1
  24. package/dist/prompt-compiler.js +11 -11
  25. package/dist/prompt-compiler.test.js +5 -5
  26. package/dist/proposals.d.ts +1 -2
  27. package/dist/response-envelope.d.ts +3 -3
  28. package/dist/response-envelope.js +5 -4
  29. package/dist/runtime-facades.test.js +12 -35
  30. package/dist/runtime.d.ts +16 -10
  31. package/dist/runtime.js +85 -107
  32. package/dist/schema-validator.test.js +3 -3
  33. package/dist/session-history.d.ts +3 -3
  34. package/dist/session-history.js +1 -1
  35. package/dist/siduri-db.d.ts +11 -29
  36. package/dist/siduri-db.js +159 -445
  37. package/dist/siduri-db.test.js +113 -281
  38. package/dist/teaching.d.ts +3 -3
  39. package/dist/teaching.js +1 -1
  40. package/package.json +7 -7
  41. package/dist/memory-settler.js +0 -161
@@ -1,161 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.settleMemoryProposals = settleMemoryProposals;
4
- /**
5
- * Persists source events, deterministic teaching claims, LLM memory proposals,
6
- * and LLM behavior proposals to the MemoryOrgan.
7
- */
8
- async function settleMemoryProposals(params) {
9
- const { companionId, perceivedText, role, requestContext, memory, self, explicitTeaching, plan, effectiveMode, } = params;
10
- // Zero Memory Drift: Casual mode completely suppresses all proposal generation
11
- const mode = effectiveMode || requestContext.mode || 'hybrid';
12
- if (mode === 'casual') {
13
- return {
14
- createdMemoryProposals: [],
15
- memoryProposalReceipts: [],
16
- };
17
- }
18
- const createdMemoryProposals = [];
19
- let sourceEventId;
20
- const hasTeaching = explicitTeaching.claims.length > 0 ||
21
- explicitTeaching.behaviorProposals.length > 0;
22
- const hasPlanProposals = Boolean(plan.memoryProposals?.length) ||
23
- Boolean(plan.behaviorProposals?.length);
24
- if (memory &&
25
- (hasTeaching || hasPlanProposals) &&
26
- typeof memory.addSourceEvent === 'function') {
27
- const sourceEvent = {
28
- id: `evt-${Date.now()}-${Math.random().toString(36).slice(2, 7)}`,
29
- sourceType: 'user_chat_explicit',
30
- occurredAt: new Date().toISOString(),
31
- payload: {
32
- message: perceivedText,
33
- role,
34
- companionId,
35
- actorId: requestContext.actor?.actorId || 'owner-user',
36
- channel: requestContext.conversation?.channel || 'direct',
37
- },
38
- };
39
- await memory.addSourceEvent(sourceEvent);
40
- sourceEventId = sourceEvent.id;
41
- }
42
- // Persist deterministic memory proposals as PENDING if memory is available
43
- if (memory && typeof memory.proposeClaim === 'function') {
44
- for (const claim of explicitTeaching.claims) {
45
- const proposal = await memory.proposeClaim({
46
- companionId,
47
- subject: claim.subject,
48
- predicate: claim.predicate,
49
- value: claim.value,
50
- scope: claim.subject?.startsWith('companion:') ? 'companion' : 'user',
51
- provenance: claim.provenance || 'deterministic_teaching',
52
- sourceEventId,
53
- claimType: claim.claimType || 'preference',
54
- authority: 'user_explicit',
55
- userConfirmation: 'none',
56
- sensitivity: claim.sensitivity ||
57
- (requestContext.conversation?.channel === 'public' ? 'public' : 'private'),
58
- });
59
- createdMemoryProposals.push(proposal);
60
- }
61
- // Also persist plan memory proposals if model returned structured proposals
62
- if (plan.memoryProposals && plan.memoryProposals.length > 0) {
63
- for (const p of plan.memoryProposals) {
64
- const proposal = await memory.proposeClaim({
65
- companionId,
66
- subject: p.subject || `actor:${requestContext.actor.actorId}`,
67
- predicate: p.predicate,
68
- value: p.value,
69
- scope: p.subject?.startsWith('companion:') ? 'companion' : 'user',
70
- provenance: p.provenance || 'llm_proposal',
71
- sourceEventId: sourceEventId || p.sourceEventId,
72
- claimType: p.claimType || 'semantic',
73
- sensitivity: p.sensitivity || 'private',
74
- });
75
- createdMemoryProposals.push(proposal);
76
- }
77
- }
78
- }
79
- const createdBehavioralProposals = [];
80
- const behavioralProposalReceipts = [];
81
- const allBehaviorProposals = [
82
- ...explicitTeaching.behaviorProposals,
83
- ...(plan.behaviorProposals || []),
84
- ];
85
- for (const bp of allBehaviorProposals) {
86
- let directive;
87
- if (memory && typeof memory.proposeDirective === 'function') {
88
- directive = await memory.proposeDirective({
89
- companionId,
90
- directive: bp.directive,
91
- priority: bp.priority || 50,
92
- category: bp.category || 'behavioral',
93
- supersedesId: bp.supersedesId,
94
- scopeActor: bp.scopeActor || (bp.subject?.startsWith('actor:') ? bp.subject.slice(6) : undefined),
95
- memoryClass: bp.memoryClass,
96
- subject: bp.subject,
97
- predicate: bp.predicate,
98
- value: bp.value,
99
- sourceEventId: sourceEventId || bp.sourceEventId,
100
- });
101
- }
102
- if (!directive || !directive.id) {
103
- directive = {
104
- id: directive?.id || `dir-${Date.now()}-${Math.random().toString(36).slice(2, 7)}`,
105
- companionId,
106
- directive: bp.directive,
107
- priority: bp.priority || 50,
108
- status: 'pending',
109
- category: (bp.category || 'behavioral'),
110
- scopeActor: bp.scopeActor,
111
- supersedesId: bp.supersedesId,
112
- createdAt: new Date().toISOString(),
113
- };
114
- }
115
- createdBehavioralProposals.push(directive);
116
- if (self && typeof self.commitDirectives === 'function') {
117
- await self.commitDirectives(companionId, [{
118
- id: directive.id,
119
- companionId,
120
- directive: bp.directive,
121
- priority: bp.priority || 50,
122
- status: 'pending',
123
- category: (bp.category || 'behavioral'),
124
- scopeActor: bp.scopeActor,
125
- supersedesId: bp.supersedesId,
126
- createdAt: new Date().toISOString(),
127
- }]);
128
- }
129
- behavioralProposalReceipts.push({
130
- directive_id: directive.id,
131
- domain: 'behavioral',
132
- knowledge_domain: 'behavioral',
133
- memory_class: bp.memoryClass || 'behavioral',
134
- runtime_effect: bp.memoryClass || 'behavioral',
135
- subject: bp.subject || `companion:${companionId}`,
136
- predicate: bp.predicate || 'rule',
137
- value: bp.value || bp.directive,
138
- status: 'pending',
139
- behavior: {
140
- instruction: bp.directive,
141
- frequency: 'continuous',
142
- preferred_positions: [],
143
- },
144
- });
145
- }
146
- const memoryProposalReceipts = createdMemoryProposals.map((p) => ({
147
- proposal_id: p.id,
148
- subject: p.subject,
149
- predicate: p.predicate,
150
- value: p.value,
151
- status: (p.status || 'pending').toLowerCase().replace(/_/g, '-'),
152
- claim_type: p.claimType,
153
- content: p.content,
154
- }));
155
- return {
156
- createdMemoryProposals,
157
- memoryProposalReceipts,
158
- createdBehavioralProposals,
159
- behavioralProposalReceipts,
160
- };
161
- }