@siduri-x/core 2.0.4 → 2.0.5

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.
@@ -6,7 +6,7 @@ exports.settleMemoryProposals = settleMemoryProposals;
6
6
  * and LLM behavior proposals to the MemoryOrgan.
7
7
  */
8
8
  async function settleMemoryProposals(params) {
9
- const { companionId, perceivedText, role, requestContext, memory, explicitTeaching, plan, effectiveMode, } = params;
9
+ const { companionId, perceivedText, role, requestContext, memory, self, explicitTeaching, plan, effectiveMode, } = params;
10
10
  // Zero Memory Drift: Casual mode completely suppresses all proposal generation
11
11
  const mode = effectiveMode || requestContext.mode || 'hybrid';
12
12
  if (mode === 'casual') {
@@ -43,6 +43,7 @@ async function settleMemoryProposals(params) {
43
43
  if (memory && typeof memory.proposeClaim === 'function') {
44
44
  for (const claim of explicitTeaching.claims) {
45
45
  const proposal = await memory.proposeClaim({
46
+ companionId,
46
47
  subject: claim.subject,
47
48
  predicate: claim.predicate,
48
49
  value: claim.value,
@@ -61,6 +62,7 @@ async function settleMemoryProposals(params) {
61
62
  if (plan.memoryProposals && plan.memoryProposals.length > 0) {
62
63
  for (const p of plan.memoryProposals) {
63
64
  const proposal = await memory.proposeClaim({
65
+ companionId,
64
66
  subject: p.subject || `actor:${requestContext.actor.actorId}`,
65
67
  predicate: p.predicate,
66
68
  value: p.value,
@@ -74,17 +76,72 @@ async function settleMemoryProposals(params) {
74
76
  }
75
77
  }
76
78
  }
77
- if (memory &&
78
- plan.behaviorProposals &&
79
- plan.behaviorProposals.length > 0 &&
80
- typeof memory.proposeDirective === 'function') {
81
- for (const bp of plan.behaviorProposals) {
82
- await memory.proposeDirective({
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,
83
90
  directive: bp.directive,
84
91
  priority: bp.priority || 50,
85
- scopeMatcher: [role],
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,
86
100
  });
87
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
+ });
88
145
  }
89
146
  const memoryProposalReceipts = createdMemoryProposals.map((p) => ({
90
147
  proposal_id: p.id,
@@ -92,9 +149,13 @@ async function settleMemoryProposals(params) {
92
149
  predicate: p.predicate,
93
150
  value: p.value,
94
151
  status: (p.status || 'pending').toLowerCase().replace(/_/g, '-'),
152
+ claim_type: p.claimType,
153
+ content: p.content,
95
154
  }));
96
155
  return {
97
156
  createdMemoryProposals,
98
157
  memoryProposalReceipts,
158
+ createdBehavioralProposals,
159
+ behavioralProposalReceipts,
99
160
  };
100
161
  }
@@ -88,6 +88,9 @@ const promptCompilationStage = async (context) => {
88
88
  requestContext: context.input.requestContext,
89
89
  behavior: context.organs.behavior,
90
90
  activeDirectives: context.contextRetrieval.activeDirectives,
91
+ selfIdentity: context.contextRetrieval.selfIdentity,
92
+ selfRelationship: context.contextRetrieval.selfRelationship,
93
+ personality: context.contextRetrieval.personality,
91
94
  subsystemDiagnostics: context.contextRetrieval.subsystemDiagnostics,
92
95
  knowledgeData: context.contextRetrieval.knowledgeData,
93
96
  memoryData: context.contextRetrieval.memoryData,
@@ -121,8 +124,14 @@ const responseGatingStage = async (context) => {
121
124
  candidateSpeech: context.plan.speech,
122
125
  candidateLanguage: context.plan.language || 'ja',
123
126
  internalMonologue: context.plan.internalMonologue,
124
- memoryProposals: context.plan.memoryProposals,
125
- behaviorProposals: context.plan.behaviorProposals,
127
+ memoryProposals: [
128
+ ...(context.intent?.explicitTeaching?.claims || []),
129
+ ...(context.plan.memoryProposals || []),
130
+ ],
131
+ behaviorProposals: [
132
+ ...(context.intent?.explicitTeaching?.behaviorProposals || []),
133
+ ...(context.plan.behaviorProposals || []),
134
+ ],
126
135
  evidenceRecords: context.contextRetrieval.collectedEvidence,
127
136
  citations: context.contextRetrieval.citations,
128
137
  });
@@ -146,6 +155,7 @@ const memorySettlementStage = async (context) => {
146
155
  role: context.input.role,
147
156
  requestContext: context.input.requestContext,
148
157
  memory: context.organs.memory,
158
+ self: context.organs.self,
149
159
  explicitTeaching: context.intent.explicitTeaching,
150
160
  plan: context.plan,
151
161
  effectiveMode: context.intent.effectiveMode,
@@ -236,6 +246,7 @@ const envelopeAssemblyStage = async (context) => {
236
246
  speechId: context.experienceEmission?.speechId,
237
247
  createdMemoryProposals: context.memorySettlement.createdMemoryProposals,
238
248
  memoryProposalReceipts: context.memorySettlement.memoryProposalReceipts,
249
+ behavioralProposalReceipts: context.memorySettlement.behavioralProposalReceipts,
239
250
  actionResults: context.actionResults || [],
240
251
  filteredEvidenceIds: context.gateEval.filteredEvidenceIds,
241
252
  filteredCitations: context.gateEval.filteredCitations,
@@ -6,6 +6,9 @@ export interface PromptCompilationParams {
6
6
  requestContext: RequestContext;
7
7
  behavior?: BehaviorOrgan;
8
8
  activeDirectives: BehaviorDirective[];
9
+ selfIdentity?: any;
10
+ selfRelationship?: any;
11
+ personality?: any;
9
12
  subsystemDiagnostics: Record<string, string>;
10
13
  knowledgeData: KnowledgeItem[];
11
14
  memoryData: Claim[];
@@ -5,7 +5,7 @@ exports.compilePrompts = compilePrompts;
5
5
  * Compiles neutral system prompt and formatted context prompt from structured data.
6
6
  */
7
7
  async function compilePrompts(params) {
8
- const { companionName, companionId, role, requestContext, behavior, activeDirectives, subsystemDiagnostics, knowledgeData, memoryData, lifeContext, effectiveMode, subtitleLanguage, } = params;
8
+ const { companionName, companionId, role, requestContext, behavior, activeDirectives, selfIdentity, selfRelationship, personality, subsystemDiagnostics, knowledgeData, memoryData, lifeContext, effectiveMode, subtitleLanguage, } = params;
9
9
  let contextPrompt = '';
10
10
  if (Object.keys(subsystemDiagnostics).length > 0) {
11
11
  contextPrompt +=
@@ -40,6 +40,9 @@ async function compilePrompts(params) {
40
40
  ? await behavior.compile({
41
41
  directives: activeDirectives,
42
42
  companionId,
43
+ identity: selfIdentity,
44
+ relationship: selfRelationship,
45
+ personality,
43
46
  actorId: requestContext.actor.actorId,
44
47
  })
45
48
  : '';
@@ -11,6 +11,7 @@ export interface AssembleResponseEnvelopeParams {
11
11
  speechId?: string;
12
12
  createdMemoryProposals: Claim[];
13
13
  memoryProposalReceipts: MemoryProposalReceipt[];
14
+ behavioralProposalReceipts?: any[];
14
15
  actionResults: ActionExecutionResult[];
15
16
  filteredEvidenceIds?: string[];
16
17
  filteredCitations?: ResponseCitation[];
@@ -29,7 +29,7 @@ function createGateRejectionEnvelope(stagedPlan, gateEval) {
29
29
  * Assembles the standardized response structure for approved companion responses.
30
30
  */
31
31
  function assembleResponseEnvelope(params) {
32
- const { stagedPlan, speech, language, subtitle, subtitles, subtitleLanguage, speechId, createdMemoryProposals, memoryProposalReceipts, actionResults, filteredEvidenceIds, filteredCitations, subsystemDiagnostics, experienceEvents, mouthDelivery, effectiveMode, } = params;
32
+ const { stagedPlan, speech, language, subtitle, subtitles, subtitleLanguage, speechId, createdMemoryProposals, memoryProposalReceipts, behavioralProposalReceipts, actionResults, filteredEvidenceIds, filteredCitations, subsystemDiagnostics, experienceEvents, mouthDelivery, effectiveMode, } = params;
33
33
  const resolvedSubtitles = {
34
34
  ...(mouthDelivery?.subtitles || {}),
35
35
  ...(subtitles || {}),
@@ -56,6 +56,7 @@ function assembleResponseEnvelope(params) {
56
56
  language,
57
57
  proposals: createdMemoryProposals,
58
58
  memory_proposals: memoryProposalReceipts,
59
+ behavioral_proposals: behavioralProposalReceipts || [],
59
60
  action_results: actionResults,
60
61
  evidence_ids: filteredEvidenceIds,
61
62
  citations: filteredCitations,
package/dist/runtime.d.ts CHANGED
@@ -38,6 +38,48 @@ export declare class SiduriRuntime {
38
38
  initialize(): Promise<void>;
39
39
  getSessionHistory(sessionKey: string): Message[];
40
40
  clearHistory(sessionKey?: string): void;
41
+ /**
42
+ * Approves a memory proposal or behavior proposal and canonically promotes
43
+ * Self-affecting mutations to SelfRepository.
44
+ */
45
+ approveProposal(proposalId: string, options?: {
46
+ companionId?: string;
47
+ }): Promise<{
48
+ success: boolean;
49
+ target?: string;
50
+ }>;
51
+ /**
52
+ * Rejects a memory or behavior proposal.
53
+ */
54
+ rejectProposal(proposalId: string, options?: {
55
+ companionId?: string;
56
+ }): Promise<{
57
+ success: boolean;
58
+ }>;
59
+ /**
60
+ * Approves a behavioral directive in Self and Memory.
61
+ */
62
+ approveDirective(directiveId: string, options?: {
63
+ companionId?: string;
64
+ }): Promise<{
65
+ success: boolean;
66
+ }>;
67
+ /**
68
+ * Rejects a behavioral directive in Self and Memory.
69
+ */
70
+ rejectDirective(directiveId: string, options?: {
71
+ companionId?: string;
72
+ }): Promise<{
73
+ success: boolean;
74
+ }>;
75
+ /**
76
+ * Revokes a behavioral directive in Self and Memory.
77
+ */
78
+ revokeDirective(directiveId: string, options?: {
79
+ companionId?: string;
80
+ }): Promise<{
81
+ success: boolean;
82
+ }>;
41
83
  /**
42
84
  * Processes an incoming perception (sensory audio, text, platform event, or observation alert)
43
85
  * through the decoupled PerceptionPipeline.
@@ -48,3 +90,7 @@ export declare class SiduriRuntime {
48
90
  */
49
91
  handleUserMessage(message: string, roleOrContext?: 'OWNER' | 'VIEWER' | 'OPERATOR' | RequestContext | string, history?: Message[], medium?: MouthMedium, signal?: AbortSignal, subtitleLanguage?: string): Promise<any>;
50
92
  }
93
+ /**
94
+ * Canonically promotes an approved Claim into SelfRepository state.
95
+ */
96
+ export declare function promoteApprovedClaimToSelf(claim: any, self: SelfRepository, companionId?: string): Promise<void>;
package/dist/runtime.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SiduriRuntime = void 0;
4
+ exports.promoteApprovedClaimToSelf = promoteApprovedClaimToSelf;
4
5
  const perception_pipeline_1 = require("./perception-pipeline");
5
6
  const container_1 = require("./container");
6
7
  /**
@@ -52,7 +53,25 @@ class SiduriRuntime {
52
53
  this.container.sessionHistory.setHistory('default', messages);
53
54
  }
54
55
  async initialize() {
55
- return this.container.initialize();
56
+ await this.container.initialize();
57
+ if (this.memory && this.self && typeof this.memory.approveClaim === 'function') {
58
+ const originalApproveClaim = this.memory.approveClaim.bind(this.memory);
59
+ this.memory.approveClaim = async (id) => {
60
+ await originalApproveClaim(id);
61
+ const targetCompId = this.id;
62
+ const claims = typeof this.memory.getAllClaims === 'function'
63
+ ? await this.memory.getAllClaims(500)
64
+ : await this.memory.getClaims(500);
65
+ let found = claims.find((c) => c.id === id);
66
+ if (!found && typeof this.memory.getPendingClaims === 'function') {
67
+ const pending = await this.memory.getPendingClaims(500);
68
+ found = pending.find((c) => c.id === id);
69
+ }
70
+ if (found && this.self) {
71
+ await promoteApprovedClaimToSelf(found, this.self, targetCompId);
72
+ }
73
+ };
74
+ }
56
75
  }
57
76
  getSessionHistory(sessionKey) {
58
77
  return this.container.sessionHistory.getHistory(sessionKey);
@@ -60,6 +79,102 @@ class SiduriRuntime {
60
79
  clearHistory(sessionKey) {
61
80
  this.container.sessionHistory.clear(sessionKey);
62
81
  }
82
+ /**
83
+ * Approves a memory proposal or behavior proposal and canonically promotes
84
+ * Self-affecting mutations to SelfRepository.
85
+ */
86
+ async approveProposal(proposalId, options) {
87
+ const companionId = options?.companionId || this.id;
88
+ // 1. Approve claim in memory if present
89
+ if (this.memory && typeof this.memory.approveClaim === 'function') {
90
+ await this.memory.approveClaim(proposalId);
91
+ }
92
+ // 2. Fetch claim
93
+ let claim;
94
+ if (this.memory) {
95
+ const claims = typeof this.memory.getAllClaims === 'function'
96
+ ? await this.memory.getAllClaims(500)
97
+ : await this.memory.getClaims(500);
98
+ claim = claims.find((c) => c.id === proposalId);
99
+ if (!claim && typeof this.memory.getPendingClaims === 'function') {
100
+ const pending = await this.memory.getPendingClaims(500);
101
+ claim = pending.find((c) => c.id === proposalId);
102
+ }
103
+ }
104
+ // 3. Promote to Self if Self exists and claim is Self-affecting
105
+ if (claim && this.self) {
106
+ await promoteApprovedClaimToSelf(claim, this.self, companionId);
107
+ return { success: true, target: 'self' };
108
+ }
109
+ // 4. Also check if proposalId is a directive ID
110
+ if (this.self && typeof this.self.approveDirective === 'function') {
111
+ try {
112
+ await this.self.approveDirective(proposalId, companionId);
113
+ return { success: true, target: 'self_directive' };
114
+ }
115
+ catch {
116
+ // Not a pending directive or already active
117
+ }
118
+ }
119
+ return { success: true, target: 'memory' };
120
+ }
121
+ /**
122
+ * Rejects a memory or behavior proposal.
123
+ */
124
+ async rejectProposal(proposalId, options) {
125
+ const companionId = options?.companionId || this.id;
126
+ if (this.memory && typeof this.memory.rejectClaim === 'function') {
127
+ await this.memory.rejectClaim(proposalId);
128
+ }
129
+ if (this.self && typeof this.self.rejectDirective === 'function') {
130
+ try {
131
+ await this.self.rejectDirective(proposalId, companionId);
132
+ }
133
+ catch {
134
+ // ignore
135
+ }
136
+ }
137
+ return { success: true };
138
+ }
139
+ /**
140
+ * Approves a behavioral directive in Self and Memory.
141
+ */
142
+ async approveDirective(directiveId, options) {
143
+ const companionId = options?.companionId || this.id;
144
+ if (this.self && typeof this.self.approveDirective === 'function') {
145
+ await this.self.approveDirective(directiveId, companionId);
146
+ }
147
+ if (this.memory && typeof this.memory.approveDirective === 'function') {
148
+ await this.memory.approveDirective(directiveId, companionId);
149
+ }
150
+ return { success: true };
151
+ }
152
+ /**
153
+ * Rejects a behavioral directive in Self and Memory.
154
+ */
155
+ async rejectDirective(directiveId, options) {
156
+ const companionId = options?.companionId || this.id;
157
+ if (this.self && typeof this.self.rejectDirective === 'function') {
158
+ await this.self.rejectDirective(directiveId, companionId);
159
+ }
160
+ if (this.memory && typeof this.memory.rejectDirective === 'function') {
161
+ await this.memory.rejectDirective(directiveId, companionId);
162
+ }
163
+ return { success: true };
164
+ }
165
+ /**
166
+ * Revokes a behavioral directive in Self and Memory.
167
+ */
168
+ async revokeDirective(directiveId, options) {
169
+ const companionId = options?.companionId || this.id;
170
+ if (this.self && typeof this.self.revokeDirective === 'function') {
171
+ await this.self.revokeDirective(directiveId, companionId);
172
+ }
173
+ if (this.memory && typeof this.memory.revokeDirective === 'function') {
174
+ await this.memory.revokeDirective(directiveId, companionId);
175
+ }
176
+ return { success: true };
177
+ }
63
178
  /**
64
179
  * Processes an incoming perception (sensory audio, text, platform event, or observation alert)
65
180
  * through the decoupled PerceptionPipeline.
@@ -94,3 +209,94 @@ class SiduriRuntime {
94
209
  }
95
210
  }
96
211
  exports.SiduriRuntime = SiduriRuntime;
212
+ /**
213
+ * Canonically promotes an approved Claim into SelfRepository state.
214
+ */
215
+ async function promoteApprovedClaimToSelf(claim, self, companionId) {
216
+ const targetCompanionId = companionId || claim.companionId || 'default';
217
+ const subject = (claim.subject || '').toLowerCase();
218
+ const predicate = (claim.predicate || '').toLowerCase();
219
+ const value = claim.value || '';
220
+ if (!value)
221
+ return;
222
+ // 1. Identity mutations: companion identity/role/origin/name/ethos
223
+ if (subject.startsWith('companion:') ||
224
+ subject === 'companion' ||
225
+ subject === 'siduri' ||
226
+ subject === 'self') {
227
+ const existing = (await self.getIdentity(targetCompanionId)) || {
228
+ companionId: targetCompanionId,
229
+ name: 'Siduri',
230
+ version: '1.0.0',
231
+ updatedAt: new Date().toISOString(),
232
+ };
233
+ if (predicate === 'role' || predicate === 'archetype') {
234
+ existing.archetype = value;
235
+ existing.role = value;
236
+ existing.updatedAt = new Date().toISOString();
237
+ await self.setIdentity(existing);
238
+ await self.commitDirectives(targetCompanionId, [
239
+ {
240
+ id: `dir-role-${claim.id || Date.now()}`,
241
+ companionId: targetCompanionId,
242
+ priority: 70,
243
+ directive: `Acknowledge role as ${value}`,
244
+ status: 'active',
245
+ category: 'relational',
246
+ createdAt: new Date().toISOString(),
247
+ },
248
+ ]);
249
+ }
250
+ else if (predicate === 'origin' || predicate === 'created_by') {
251
+ existing.origin = value;
252
+ existing.updatedAt = new Date().toISOString();
253
+ await self.setIdentity(existing);
254
+ }
255
+ else if (predicate === 'name') {
256
+ existing.name = value;
257
+ existing.updatedAt = new Date().toISOString();
258
+ await self.setIdentity(existing);
259
+ }
260
+ else if (predicate === 'ethos') {
261
+ existing.ethos = value;
262
+ existing.updatedAt = new Date().toISOString();
263
+ await self.setIdentity(existing);
264
+ }
265
+ return;
266
+ }
267
+ // 2. Relationship mutations: creator or user stated relationship
268
+ if (claim.claimType === 'relationship' ||
269
+ predicate === 'stated_relationship' ||
270
+ predicate === 'relationship' ||
271
+ predicate === 'relationship_to_siduri') {
272
+ const rawSubject = (claim.subject || 'actor:user').replace(/^actor:actor:/, 'actor:');
273
+ const isCreator = value.toLowerCase() === 'creator';
274
+ await self.updateRelationship(targetCompanionId, {
275
+ companionId: targetCompanionId,
276
+ entityId: rawSubject,
277
+ entityType: 'human',
278
+ role: value,
279
+ stance: isCreator ? 'familiar_loyal' : 'neutral',
280
+ trustScore: isCreator ? 1.0 : 0.8,
281
+ familiarity: isCreator ? 0.9 : 0.5,
282
+ interactionConventions: isCreator
283
+ ? ['Direct communication', 'Highest administrative trust']
284
+ : [],
285
+ });
286
+ return;
287
+ }
288
+ // 3. Behavioral rule claim
289
+ if (predicate === 'behavioral_rule' || predicate === 'rule') {
290
+ await self.commitDirectives(targetCompanionId, [
291
+ {
292
+ id: `dir-rule-${claim.id || Date.now()}`,
293
+ companionId: targetCompanionId,
294
+ priority: 60,
295
+ directive: value,
296
+ status: 'active',
297
+ category: 'behavioral',
298
+ createdAt: new Date().toISOString(),
299
+ },
300
+ ]);
301
+ }
302
+ }
@@ -3,6 +3,7 @@ export interface SelfIdentity {
3
3
  companionId: string;
4
4
  name: string;
5
5
  archetype?: string;
6
+ role?: string;
6
7
  origin?: string;
7
8
  ethos?: string;
8
9
  version: string;
@@ -148,6 +149,10 @@ export declare class SiduriDatabase {
148
149
  status?: string;
149
150
  }): MemoryClaim;
150
151
  approveClaim(id: string, companionId?: string): void;
152
+ /**
153
+ * Canonically promotes a Claim into Self domain tables.
154
+ */
155
+ promoteClaimToSelf(claim: MemoryClaim | any): void;
151
156
  rejectClaim(id: string, companionId?: string): void;
152
157
  revokeClaim(id: string, companionId?: string): void;
153
158
  expireClaim(id: string, companionId?: string): void;