@siduri-x/core 2.0.8 → 2.0.9

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.
package/LICENSE ADDED
@@ -0,0 +1,190 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or exemplary damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright 2026 VXNUS Creative Technology Studio
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
@@ -122,6 +122,9 @@ describe('Conversational Teach Mode End-to-End Lifecycle', () => {
122
122
  if (ctx.identity.archetype || ctx.identity.role) {
123
123
  parts.push(`- Role: ${ctx.identity.role || ctx.identity.archetype}`);
124
124
  }
125
+ if (ctx.identity.origin) {
126
+ parts.push(`- Origin/Created By: ${ctx.identity.origin}`);
127
+ }
125
128
  }
126
129
  if (ctx.relationship) {
127
130
  const nameStr = ctx.relationship.name ? ` [Name: ${ctx.relationship.name}]` : '';
@@ -640,4 +643,163 @@ describe('Conversational Teach Mode End-to-End Lifecycle', () => {
640
643
  expect(lastCallCtx.systemPrompt).toContain('Kur Zagin');
641
644
  db.close();
642
645
  });
646
+ // =========================================================================
647
+ // Test I: Benchmark replication (name, creator, new chat turn-1 recognition)
648
+ // =========================================================================
649
+ it('Test I: reproduces benchmark scenario: teaches name, teaches creator relationship, and verifies new session recognizes creator in origin and relationship', async () => {
650
+ const db = new index_1.SiduriDatabase({ dbPath });
651
+ const companionId = 'comp-test-i';
652
+ const self = createSelfRepository(db);
653
+ const memory = createMemoryOrgan(db);
654
+ const behavior = createBehaviorCompiler();
655
+ const mockBrain = {
656
+ generatePlan: jest.fn().mockImplementation(async (brainCtx) => {
657
+ const lastMsg = brainCtx.recentMessages?.[brainCtx.recentMessages.length - 1]?.content || '';
658
+ const memoryProposals = [];
659
+ const behaviorProposals = [];
660
+ if (/your name is Siduri/i.test(lastMsg)) {
661
+ memoryProposals.push({
662
+ subject: 'companion:self',
663
+ predicate: 'name',
664
+ value: 'Siduri',
665
+ });
666
+ behaviorProposals.push({
667
+ directive: 'Address self as Siduri',
668
+ category: 'relational',
669
+ subject: 'companion:self',
670
+ predicate: 'name',
671
+ value: 'Siduri',
672
+ });
673
+ }
674
+ if (/i am Kur Zagin, your creator/i.test(lastMsg)) {
675
+ memoryProposals.push({
676
+ subject: 'actor:kur_zagin',
677
+ predicate: 'name',
678
+ value: 'Kur Zagin',
679
+ });
680
+ memoryProposals.push({
681
+ subject: 'actor:kur_zagin',
682
+ predicate: 'stated_relationship',
683
+ value: 'creator of companion Siduri',
684
+ });
685
+ behaviorProposals.push({
686
+ directive: 'Acknowledge actor:kur_zagin as creator of companion Siduri',
687
+ category: 'relational',
688
+ subject: 'actor:kur_zagin',
689
+ predicate: 'stated_relationship',
690
+ value: 'creator of companion Siduri',
691
+ });
692
+ behaviorProposals.push({
693
+ directive: 'Address actor:kur_zagin as Kur Zagin',
694
+ category: 'behavioral',
695
+ subject: 'actor:kur_zagin',
696
+ predicate: 'name',
697
+ value: 'Kur Zagin',
698
+ });
699
+ }
700
+ return {
701
+ speech: 'I understand and acknowledge.',
702
+ language: 'en',
703
+ memoryProposals: memoryProposals.length > 0 ? memoryProposals : undefined,
704
+ behaviorProposals: behaviorProposals.length > 0 ? behaviorProposals : undefined,
705
+ _receivedSystemPrompt: brainCtx.systemPrompt,
706
+ };
707
+ }),
708
+ };
709
+ const runtime = new index_1.SiduriRuntime(companionId, { name: 'Siduri' }, {
710
+ brain: mockBrain,
711
+ memory,
712
+ self,
713
+ behavior,
714
+ });
715
+ await runtime.initialize();
716
+ // Session 1 - Turn 1: "your name is Siduri"
717
+ const res1 = await runtime.processPerception({
718
+ source: 'text_chat',
719
+ text: 'your name is Siduri',
720
+ context: createRequestContext(companionId, 'teach', 'owner-user'),
721
+ });
722
+ expect(res1.status).toBe('APPROVED');
723
+ const nameProp = res1.metadata?.proposals?.find((p) => p.predicate === 'name');
724
+ expect(nameProp).toBeDefined();
725
+ await runtime.approveProposal(nameProp.id, { companionId });
726
+ // Verify companion name in self_identity
727
+ const idStep1 = await self.getIdentity(companionId);
728
+ expect(idStep1?.name).toBe('Siduri');
729
+ // Session 1 - Turn 2: "i am Kur Zagin, your creator"
730
+ const res2 = await runtime.processPerception({
731
+ source: 'text_chat',
732
+ text: 'i am Kur Zagin, your creator',
733
+ context: createRequestContext(companionId, 'teach', 'owner-user'),
734
+ });
735
+ expect(res2.status).toBe('APPROVED');
736
+ // Approve both proposals (name and creator of companion Siduri)
737
+ const proposals2 = res2.metadata?.proposals || [];
738
+ const creatorProp = proposals2.find((p) => p.predicate === 'stated_relationship');
739
+ const userProp = proposals2.find((p) => p.predicate === 'name');
740
+ expect(creatorProp).toBeDefined();
741
+ expect(userProp).toBeDefined();
742
+ await runtime.approveProposal(creatorProp.id, { companionId });
743
+ await runtime.approveProposal(userProp.id, { companionId });
744
+ // Also approve the behavioral directives
745
+ const dirProps = res2.metadata?.behavioral_proposals || [];
746
+ for (const d of dirProps) {
747
+ if (d.directive_id) {
748
+ await runtime.approveDirective(d.directive_id, { companionId });
749
+ }
750
+ }
751
+ // Verify self_identity.origin has been dual-promoted!
752
+ const idStep2 = await self.getIdentity(companionId);
753
+ expect(idStep2?.name).toBe('Siduri');
754
+ expect(idStep2?.origin).toBe('Kur Zagin');
755
+ // Verify relationship has creator role, loyal stance, and user name
756
+ const relStep2 = await self.getRelationship(companionId, 'actor:kur_zagin');
757
+ expect(relStep2).toBeDefined();
758
+ expect(relStep2?.role).toBe('creator');
759
+ expect(relStep2?.stance).toBe('familiar_loyal');
760
+ expect(relStep2?.trustScore).toBe(1.0);
761
+ expect(relStep2?.name).toBe('Kur Zagin');
762
+ // Verify single-owner fallback: an incoming request with 'owner-user' gets the primary relationship!
763
+ const relOwnerUser = await self.getRelationship(companionId, 'owner-user');
764
+ expect(relOwnerUser).toBeDefined();
765
+ expect(relOwnerUser?.name).toBe('Kur Zagin');
766
+ expect(relOwnerUser?.role).toBe('creator');
767
+ expect(relOwnerUser?.stance).toBe('familiar_loyal');
768
+ // =======================================================================
769
+ // Session 2 ("New Chat"): user opens a fresh session as 'owner-user'
770
+ // =======================================================================
771
+ // Turn 1: "hey, who are you?"
772
+ await runtime.processPerception({
773
+ source: 'text_chat',
774
+ text: 'hey, who are you?',
775
+ context: createRequestContext(companionId, 'hybrid', 'owner-user'),
776
+ });
777
+ const calls = mockBrain.generatePlan.mock.calls;
778
+ const newChatTurn1Ctx = calls[calls.length - 1][0];
779
+ // Identity nucleus has origin
780
+ expect(newChatTurn1Ctx.systemPrompt).toContain('Name: Siduri');
781
+ expect(newChatTurn1Ctx.systemPrompt).toContain('Origin/Created By: Kur Zagin');
782
+ // Relationship stance recognizes Kur Zagin as creator
783
+ expect(newChatTurn1Ctx.systemPrompt).toContain('Kur Zagin');
784
+ expect(newChatTurn1Ctx.systemPrompt).toContain('familiar_loyal');
785
+ // Turn 2: "who is your creator?"
786
+ await runtime.processPerception({
787
+ source: 'text_chat',
788
+ text: 'who is your creator?',
789
+ context: createRequestContext(companionId, 'hybrid', 'owner-user'),
790
+ });
791
+ const newChatTurn2Ctx = calls[calls.length - 1][0];
792
+ expect(newChatTurn2Ctx.systemPrompt).toContain('Origin/Created By: Kur Zagin');
793
+ // Turn 3: From an anonymous guest session:
794
+ // Should NOT get the personal relationship stance, but Identity origin remains!
795
+ await runtime.processPerception({
796
+ source: 'text_chat',
797
+ text: 'who is your creator?',
798
+ context: createRequestContext(companionId, 'hybrid', 'anonymous-session'),
799
+ });
800
+ const guestTurnCtx = calls[calls.length - 1][0];
801
+ expect(guestTurnCtx.systemPrompt).toContain('Origin/Created By: Kur Zagin');
802
+ expect(guestTurnCtx.systemPrompt).not.toContain('Stance toward anonymous-session [Name: Kur Zagin]');
803
+ db.close();
804
+ });
643
805
  });
package/dist/runtime.js CHANGED
@@ -273,19 +273,22 @@ async function promoteApprovedClaimToSelf(claim, self, companionId) {
273
273
  predicate === 'preferred_address' ||
274
274
  predicate === 'affiliation') {
275
275
  const rawSubject = (claim.subject || 'actor:user').replace(/^actor:actor:/, 'actor:');
276
- const isCreator = value.toLowerCase() === 'creator';
276
+ const isCreator = value.toLowerCase().includes('creator');
277
277
  const isName = predicate === 'name' || predicate === 'preferred_address';
278
278
  const isAffil = predicate === 'affiliation';
279
279
  const existingRel = typeof self.getRelationship === 'function'
280
280
  ? await self.getRelationship(targetCompanionId, rawSubject)
281
281
  : null;
282
- const role = isCreator ? value : (existingRel?.role || (isName || isAffil ? existingRel?.role : value));
282
+ const isPriorCreator = existingRel?.role === 'creator' || (existingRel?.stance === 'familiar_loyal' && existingRel.trustScore === 1.0);
283
+ const role = isCreator
284
+ ? 'creator'
285
+ : (isPriorCreator ? 'creator' : (existingRel?.role && existingRel.role !== 'user' ? existingRel.role : (isName || isAffil ? existingRel?.role || 'user' : value)));
283
286
  const name = isName ? value : existingRel?.name;
284
287
  const affiliation = isAffil ? value : existingRel?.affiliation;
285
- const stance = isCreator ? 'familiar_loyal' : (existingRel?.stance || 'neutral');
286
- const trustScore = isCreator ? 1.0 : (existingRel?.trustScore ?? 0.8);
287
- const familiarity = isCreator ? 0.9 : (existingRel?.familiarity ?? 0.5);
288
- const interactionConventions = isCreator
288
+ const stance = isCreator || isPriorCreator ? 'familiar_loyal' : (existingRel?.stance || 'neutral');
289
+ const trustScore = isCreator || isPriorCreator ? 1.0 : (existingRel?.trustScore ?? 0.8);
290
+ const familiarity = isCreator || isPriorCreator ? 0.9 : (existingRel?.familiarity ?? 0.5);
291
+ const interactionConventions = isCreator || isPriorCreator
289
292
  ? Array.from(new Set([...(existingRel?.interactionConventions || []), 'Direct communication', 'Highest administrative trust']))
290
293
  : (existingRel?.interactionConventions || []);
291
294
  await self.updateRelationship(targetCompanionId, {
@@ -300,6 +303,19 @@ async function promoteApprovedClaimToSelf(claim, self, companionId) {
300
303
  familiarity,
301
304
  interactionConventions,
302
305
  });
306
+ // Dual promotion: If this actor is established as creator, also populate companion's origin in self_identity
307
+ if (isCreator || (isName && isPriorCreator)) {
308
+ const existingIdentity = (await self.getIdentity(targetCompanionId)) || {
309
+ companionId: targetCompanionId,
310
+ name: 'Siduri',
311
+ version: '1.0.0',
312
+ updatedAt: new Date().toISOString(),
313
+ };
314
+ const creatorName = name || existingRel?.name || (rawSubject.startsWith('actor:') && rawSubject !== 'actor:user' && rawSubject !== 'actor:primary' ? rawSubject.slice(6) : value);
315
+ existingIdentity.origin = creatorName !== 'user' && creatorName !== 'primary' ? creatorName : value;
316
+ existingIdentity.updatedAt = new Date().toISOString();
317
+ await self.setIdentity(existingIdentity);
318
+ }
303
319
  if (isName) {
304
320
  await self.commitDirectives(targetCompanionId, [
305
321
  {
package/dist/siduri-db.js CHANGED
@@ -236,6 +236,34 @@ class SiduriDatabase {
236
236
  catch {
237
237
  // Column already exists
238
238
  }
239
+ try {
240
+ // Reconcile creator claims that may have been recorded before origin dual-promotion
241
+ const creatorClaims = this.db.prepare(`
242
+ SELECT * FROM memory_claims
243
+ WHERE predicate = 'stated_relationship'
244
+ AND LOWER(value) LIKE '%creator%'
245
+ AND LOWER(status) = 'approved'
246
+ `).all();
247
+ for (const claim of creatorClaims) {
248
+ const identity = this.db.prepare(`SELECT * FROM self_identity WHERE companion_id = ?`).get(claim.companion_id);
249
+ if (identity && !identity.origin) {
250
+ const nameClaim = this.db.prepare(`
251
+ SELECT value FROM memory_claims
252
+ WHERE companion_id = ? AND subject = ? AND predicate = 'name' AND LOWER(status) = 'approved'
253
+ ORDER BY asserted_at DESC LIMIT 1
254
+ `).get(claim.companion_id, claim.subject);
255
+ const originName = nameClaim?.value || (claim.subject.startsWith('actor:') ? claim.subject.slice(6) : claim.subject);
256
+ this.db.prepare(`UPDATE self_identity SET origin = ? WHERE companion_id = ?`).run(originName, claim.companion_id);
257
+ }
258
+ const rel = this.db.prepare(`SELECT * FROM self_relationships WHERE companion_id = ? AND entity_id = ?`).get(claim.companion_id, claim.subject);
259
+ if (rel && (rel.role !== 'creator' || rel.stance !== 'familiar_loyal')) {
260
+ this.db.prepare(`UPDATE self_relationships SET role = 'creator', stance = 'familiar_loyal', trust_score = 1.0 WHERE companion_id = ? AND entity_id = ?`).run(claim.companion_id, claim.subject);
261
+ }
262
+ }
263
+ }
264
+ catch {
265
+ // Best-effort auto-reconciliation
266
+ }
239
267
  }
240
268
  close() {
241
269
  this.db.close();
@@ -446,7 +474,11 @@ class SiduriDatabase {
446
474
  const stripped = entityId.startsWith('actor:') ? entityId.slice(6) : entityId;
447
475
  const prefixed = entityId.startsWith('actor:') ? entityId : `actor:${entityId}`;
448
476
  const stmt = this.db.prepare('SELECT * FROM self_relationships WHERE companion_id = ? AND (entity_id = ? OR entity_id = ? OR entity_id = ?)');
449
- const row = stmt.get(companionId, entityId, stripped, prefixed);
477
+ let row = stmt.get(companionId, entityId, stripped, prefixed);
478
+ if (!row && (entityId === 'owner-user' || entityId === 'local-user' || entityId === 'owner' || entityId === 'primary' || entityId === 'user')) {
479
+ const fallbackStmt = this.db.prepare("SELECT * FROM self_relationships WHERE companion_id = ? AND entity_type = 'human' ORDER BY updated_at DESC LIMIT 1");
480
+ row = fallbackStmt.get(companionId);
481
+ }
450
482
  if (!row)
451
483
  return undefined;
452
484
  return {
@@ -789,17 +821,20 @@ class SiduriDatabase {
789
821
  predicate === 'preferred_address' ||
790
822
  predicate === 'affiliation') {
791
823
  const rawSubject = (claim.subject || 'actor:user').replace(/^actor:actor:/, 'actor:');
792
- const isCreator = value.toLowerCase() === 'creator';
824
+ const isCreator = value.toLowerCase().includes('creator');
793
825
  const isName = predicate === 'name' || predicate === 'preferred_address';
794
826
  const isAffil = predicate === 'affiliation';
795
827
  const existingRel = this.getRelationship(companionId, rawSubject);
796
- const role = isCreator ? value : (existingRel?.role || (isName || isAffil ? existingRel?.role : value));
828
+ const isPriorCreator = existingRel?.role === 'creator' || (existingRel?.stance === 'familiar_loyal' && existingRel.trustScore === 1.0);
829
+ const role = isCreator
830
+ ? 'creator'
831
+ : (isPriorCreator ? 'creator' : (existingRel?.role && existingRel.role !== 'user' ? existingRel.role : (isName || isAffil ? existingRel?.role || 'user' : value)));
797
832
  const name = isName ? value : existingRel?.name;
798
833
  const affiliation = isAffil ? value : existingRel?.affiliation;
799
- const stance = isCreator ? 'familiar_loyal' : (existingRel?.stance || 'neutral');
800
- const trustScore = isCreator ? 1.0 : (existingRel?.trustScore ?? 0.8);
801
- const familiarity = isCreator ? 0.9 : (existingRel?.familiarity ?? 0.5);
802
- const interactionConventions = isCreator
834
+ const stance = isCreator || isPriorCreator ? 'familiar_loyal' : (existingRel?.stance || 'neutral');
835
+ const trustScore = isCreator || isPriorCreator ? 1.0 : (existingRel?.trustScore ?? 0.8);
836
+ const familiarity = isCreator || isPriorCreator ? 0.9 : (existingRel?.familiarity ?? 0.5);
837
+ const interactionConventions = isCreator || isPriorCreator
803
838
  ? Array.from(new Set([...(existingRel?.interactionConventions || []), 'Direct communication', 'Highest administrative trust']))
804
839
  : (existingRel?.interactionConventions || []);
805
840
  this.upsertRelationship({
@@ -814,6 +849,19 @@ class SiduriDatabase {
814
849
  familiarity,
815
850
  interactionConventions,
816
851
  });
852
+ // Dual promotion: If this actor is established as creator, also populate companion's origin in self_identity
853
+ if (isCreator || (isName && isPriorCreator)) {
854
+ const existingIdentity = this.getIdentity(companionId) || {
855
+ companionId,
856
+ name: 'Siduri',
857
+ version: '1.0.0',
858
+ updatedAt: new Date().toISOString(),
859
+ };
860
+ const creatorName = name || existingRel?.name || (rawSubject.startsWith('actor:') && rawSubject !== 'actor:user' && rawSubject !== 'actor:primary' ? rawSubject.slice(6) : value);
861
+ existingIdentity.origin = creatorName !== 'user' && creatorName !== 'primary' ? creatorName : value;
862
+ existingIdentity.updatedAt = new Date().toISOString();
863
+ this.setIdentity(existingIdentity);
864
+ }
817
865
  if (isName) {
818
866
  this.commitDirective({
819
867
  id: `dir-name-${claim.id || Date.now()}`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@siduri-x/core",
3
- "version": "2.0.8",
3
+ "version": "2.0.9",
4
4
  "description": "Core runtime types, evidence protocol, action dispatcher, capability validation, and SiduriRuntime protocol",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -28,16 +28,16 @@
28
28
  "default": "./dist/index.js"
29
29
  }
30
30
  },
31
- "scripts": {
32
- "build": "tsc",
33
- "dev": "tsc -w",
34
- "test": "jest --config jest.config.json"
35
- },
36
31
  "devDependencies": {
37
32
  "@types/jest": "^30.0.0",
38
33
  "@types/node": "^26.5.1",
39
34
  "jest": "^30.5.1",
40
35
  "ts-jest": "^29.4.12",
41
36
  "typescript": "^5.9.3"
37
+ },
38
+ "scripts": {
39
+ "build": "tsc",
40
+ "dev": "tsc -w",
41
+ "test": "jest --config jest.config.json"
42
42
  }
43
- }
43
+ }