soulbridge 0.0.26 → 0.0.98
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 +202 -202
- package/dist/packages/cli/src/cli.js +0 -0
- package/dist/packages/core/src/config/dimensions.d.ts +18 -0
- package/dist/packages/core/src/config/dimensions.js +33 -0
- package/dist/packages/core/src/config/domains.d.ts +70 -0
- package/dist/packages/core/src/config/domains.js +70 -0
- package/dist/packages/core/src/config/labels.d.ts +22 -0
- package/dist/packages/core/src/config/labels.js +21 -0
- package/dist/packages/core/src/config/status.d.ts +51 -0
- package/dist/packages/core/src/config/status.js +47 -0
- package/dist/packages/core/src/consolidate.d.ts +170 -0
- package/dist/packages/core/src/consolidate.js +311 -0
- package/dist/packages/core/src/context.d.ts +2 -0
- package/dist/packages/core/src/context.js +48 -17
- package/dist/packages/core/src/dimension-text.d.ts +6 -0
- package/dist/packages/core/src/dimension-text.js +24 -0
- package/dist/packages/core/src/dimensions.d.ts +28 -0
- package/dist/packages/core/src/dimensions.js +53 -0
- package/dist/packages/core/src/extract.d.ts +140 -0
- package/dist/packages/core/src/extract.js +611 -0
- package/dist/packages/core/src/index.d.ts +362 -10
- package/dist/packages/core/src/index.js +983 -127
- package/dist/packages/core/src/inject-text.d.ts +16 -0
- package/dist/packages/core/src/inject-text.js +24 -0
- package/dist/packages/core/src/profile-prompt.d.ts +18 -0
- package/dist/packages/core/src/profile-prompt.js +103 -0
- package/dist/packages/core/src/prompts.d.ts +122 -0
- package/dist/packages/core/src/prompts.generated.d.ts +9 -0
- package/dist/packages/core/src/prompts.generated.js +9 -0
- package/dist/packages/core/src/prompts.js +293 -0
- package/dist/packages/core/src/reflect.d.ts +7 -0
- package/dist/packages/core/src/reflect.js +25 -27
- package/dist/packages/core/src/retrieval.d.ts +39 -0
- package/dist/packages/core/src/retrieval.js +105 -0
- package/dist/packages/core/src/roles.d.ts +18 -0
- package/dist/packages/core/src/roles.js +17 -0
- package/dist/packages/core/src/rules.d.ts +69 -0
- package/dist/packages/core/src/rules.js +152 -0
- package/dist/packages/core/src/sqlite.d.ts +26 -5
- package/dist/packages/core/src/sqlite.js +944 -33
- package/dist/packages/core/src/store.d.ts +92 -3
- package/dist/packages/core/src/types.d.ts +442 -1
- package/dist/packages/core/src/types.js +1 -0
- package/package.json +5 -3
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* The only port. Every added method is a storage engine's opinion leaking into
|
|
3
3
|
* the domain, so the surface stays deliberately small.
|
|
4
4
|
*/
|
|
5
|
-
import type { AffectSignal, Correction, Emotion, Identity, Memory, QuerySpec, TurnPair, TurnPairSpec } from './types.ts';
|
|
5
|
+
import type { AffectSignal, Correction, Emotion, Entity, EntityQuery, EntitySpec, Fact, FactQuery, FactSpec, Gap, GapSpec, Identity, Memory, QuerySpec, SessionSummary, SlotValue, TurnPair, TurnPairSpec, TurnFindResult, TurnFindSpec, TurnSpec, TurnStep, TurnThread, ThreadSpec } from './types.ts';
|
|
6
6
|
export interface SoulStore {
|
|
7
7
|
ensureSoul(identity: Identity): void;
|
|
8
8
|
identity(soulId: string): Identity | null;
|
|
@@ -15,10 +15,94 @@ export interface SoulStore {
|
|
|
15
15
|
* Store one exchange. Idempotent on `(soul, user, session, turn)`: a repeat is
|
|
16
16
|
* ignored, never merged — the original text is immutable (RFC 0007).
|
|
17
17
|
*/
|
|
18
|
-
putTurnPair(pair: TurnPair): void;
|
|
18
|
+
putTurnPair(pair: TurnPair, steps?: TurnStep[]): void;
|
|
19
|
+
/** Write one turn with its ordered steps (briefs/0014). */
|
|
20
|
+
putTurn(spec: TurnSpec): void;
|
|
21
|
+
/** Steps of one turn, in order. */
|
|
22
|
+
stepsOf(turnId: string): TurnStep[];
|
|
23
|
+
/** Exhaustive fetch by substring/filters — for counts and overviews. */
|
|
24
|
+
findTurns(spec: TurnFindSpec): TurnFindResult;
|
|
25
|
+
/** Create or refresh a person/thing/place/self; keys on name within a type. */
|
|
26
|
+
putEntity(spec: EntitySpec): Entity;
|
|
27
|
+
entity(id: string): Entity | null;
|
|
28
|
+
findEntities(query: EntityQuery): Entity[];
|
|
29
|
+
/** One connection between things, with its ends. */
|
|
30
|
+
putFact(spec: FactSpec): Fact;
|
|
31
|
+
fact(id: string): Fact | null;
|
|
32
|
+
facts(query: FactQuery): Fact[];
|
|
33
|
+
/** Open a topic thread. */
|
|
34
|
+
openThread(spec: ThreadSpec): TurnThread;
|
|
35
|
+
/** Put one turn into a thread; a turn belongs to exactly one. */
|
|
36
|
+
attachTurn(turnId: string, threadId: string): void;
|
|
37
|
+
/** Remember the newest turn number seen in a thread (used for ordering). */
|
|
38
|
+
touchThread(id: string, turnNo: number): void;
|
|
39
|
+
/**
|
|
40
|
+
* Replace a thread's one-line topic.
|
|
41
|
+
*
|
|
42
|
+
* The topic is written when the thread opens, so a thread that continues for an hour
|
|
43
|
+
* would otherwise stay labelled with its first (often two-word) turn — and the label
|
|
44
|
+
* is what "上次聊到哪" shows.
|
|
45
|
+
*/
|
|
46
|
+
updateThreadTopic(id: string, topic: string): void;
|
|
47
|
+
/** Open threads, most recently used first — the candidate list for attribution. */
|
|
48
|
+
openThreads(soulId: string, userId: string, limit?: number): TurnThread[];
|
|
49
|
+
/**
|
|
50
|
+
* The user text of the turn before `turnNo` in a session, or null.
|
|
51
|
+
*
|
|
52
|
+
* Extraction is per turn; without the previous line it cannot tell "继续" from a
|
|
53
|
+
* new subject, and pronouns have nothing to bind to (ADR 0034).
|
|
54
|
+
*/
|
|
55
|
+
previousTurnText(sessionId: string, turnNo: number): string | null;
|
|
56
|
+
thread(id: string): TurnThread | null;
|
|
57
|
+
closeThread(id: string, at: number, summaryFactId?: string): void;
|
|
58
|
+
/** Close threads whose last turn is at least idleTurns behind now; returns the ids. */
|
|
59
|
+
closeIdleThreads(soulId: string, userId: string, sessionId: string, idleTurns: number, idleMs: number, archivedSessionIds: string[], at: number): Array<{
|
|
60
|
+
id: string;
|
|
61
|
+
reason: 'archived' | 'quiet-turns' | 'quiet-time';
|
|
62
|
+
}>;
|
|
63
|
+
/** Append slots to an existing fact, skipping ones it has. Returns how many were added. */
|
|
64
|
+
addSlots(factId: string, slots: {
|
|
65
|
+
slot: string;
|
|
66
|
+
value: SlotValue;
|
|
67
|
+
}[]): number;
|
|
68
|
+
setFactTypeName(factId: string, typeName: string): void;
|
|
69
|
+
setFactConfidence(factId: string, confidence: number): void;
|
|
70
|
+
/** Count that retrieval surfaced these facts (0019: use slows decay). */
|
|
71
|
+
recordRecalls(factIds: string[], at: number): void;
|
|
72
|
+
/** Facts about one entity, newest event first; predicate narrows within it. */
|
|
73
|
+
latestAbout(soulId: string, userId: string, entityName: string, options?: {
|
|
74
|
+
predicate?: string;
|
|
75
|
+
query?: string;
|
|
76
|
+
limit?: number;
|
|
77
|
+
now?: number;
|
|
78
|
+
}): Fact[];
|
|
79
|
+
/** A turn by (session, turn number) — how a repeat gets its real id. */
|
|
80
|
+
turnByTurnNo(sessionId: string, turnNo: number): TurnPair | null;
|
|
81
|
+
/** The thread the previous turn belonged to, if any. */
|
|
82
|
+
threadBefore(sessionId: string, turnNo: number): string | null;
|
|
83
|
+
/** The most recently closed thread, or null when none has closed yet. */
|
|
84
|
+
lastClosedThread(soulId: string, userId: string): TurnThread | null;
|
|
85
|
+
/** Every turn of a thread, in order — the chapter, not one page. */
|
|
86
|
+
threadTurns(threadId: string): TurnPair[];
|
|
87
|
+
/** Facts whose source turn belongs to the given turns. */
|
|
88
|
+
factsByTurns(turnIds: string[]): Fact[];
|
|
89
|
+
/** One turn by id, for expanding a fact back into its conversation. */
|
|
90
|
+
turn(id: string): TurnPair | null;
|
|
91
|
+
/** Retire a fact: the new one replaces it, the old row stays for the record. */
|
|
92
|
+
supersedeFact(oldId: string, newId: string): void;
|
|
93
|
+
/** Something wanted but not known; the highest tension is worth asking about. */
|
|
94
|
+
putGap(spec: GapSpec): Gap;
|
|
95
|
+
openGaps(soulId: string, userId: string, limit?: number): Gap[];
|
|
96
|
+
closeGap(id: string, closedByFactId?: string, at?: number): void;
|
|
19
97
|
/** Exchanges visible to `userId`; scored against `spec.query` when given. */
|
|
20
98
|
recallTurnPairs(spec: TurnPairSpec): TurnPair[];
|
|
21
|
-
countTurnPairs(soulId: string, userId: string): number;
|
|
99
|
+
countTurnPairs(soulId: string, userId: string, sessionId?: string): number;
|
|
100
|
+
/** Conversations derived from pairs, most recent first. */
|
|
101
|
+
listSessions(soulId: string, userId: string, limit: number): SessionSummary[];
|
|
102
|
+
/** Exchanges of one conversation, oldest first. */
|
|
103
|
+
sessionPairs(sessionId: string, soulId: string, userId: string, limit: number): TurnPair[];
|
|
104
|
+
/** Last exchanges of one conversation, oldest first. */
|
|
105
|
+
sessionTail(sessionId: string, soulId: string, userId: string, limit: number): TurnPair[];
|
|
22
106
|
/** Recall bookkeeping: recallCount++, lastRecalledAt = now. */
|
|
23
107
|
touch(ids: string[], now?: number): void;
|
|
24
108
|
/**
|
|
@@ -32,6 +116,11 @@ export interface SoulStore {
|
|
|
32
116
|
* is not active.
|
|
33
117
|
*/
|
|
34
118
|
supersede(oldId: string, newId: string, now?: number): boolean;
|
|
119
|
+
/**
|
|
120
|
+
* Retire a legacy memory whose replacement is not a memory (the migration replaces
|
|
121
|
+
* rows with facts). Same bookkeeping, no cross-table existence check.
|
|
122
|
+
*/
|
|
123
|
+
retireMemory(oldId: string, replacedBy?: string, now?: number): boolean;
|
|
35
124
|
/** Persist one affect sample (payload only; no raw text). */
|
|
36
125
|
saveAffect(soulId: string, userId: string, signal: AffectSignal, at: number, deviceId?: string): void;
|
|
37
126
|
/** Samples newer than `sinceMs`, newest first. */
|
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
*/
|
|
7
7
|
export type MemoryType = 'semantic' | 'episodic' | 'strategy' | 'cognition' | 'relationship' | 'trait' | 'fact';
|
|
8
8
|
export type Visibility = 'private' | 'shared';
|
|
9
|
-
export type MemoryStatus
|
|
9
|
+
export type { MemoryStatus } from './config/status.ts';
|
|
10
|
+
import type { MemoryStatus } from './config/status.ts';
|
|
10
11
|
export interface Memory {
|
|
11
12
|
id: string;
|
|
12
13
|
soulId: string;
|
|
@@ -70,6 +71,382 @@ export interface TurnPairSpec {
|
|
|
70
71
|
/** Only pairs at or after this timestamp. */
|
|
71
72
|
since?: number;
|
|
72
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* One conversation, derived from `turn_pairs` (briefs/0011). It is a boundary,
|
|
76
|
+
* not a stored entity: the same data regrouped, so nothing new to migrate.
|
|
77
|
+
*/
|
|
78
|
+
export interface SessionSummary {
|
|
79
|
+
sessionId: string;
|
|
80
|
+
/** First and last exchange times in this session. */
|
|
81
|
+
start: number;
|
|
82
|
+
end: number;
|
|
83
|
+
/** Number of exchanges recorded for this session. */
|
|
84
|
+
turns: number;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* What a new session inherits from the previous one: when it happened, and the
|
|
88
|
+
* first plus last exchanges. Boundaries and the tail are what recall hangs on
|
|
89
|
+
* (event segmentation), not the middle.
|
|
90
|
+
*/
|
|
91
|
+
export interface SessionHandoff {
|
|
92
|
+
session: SessionSummary;
|
|
93
|
+
first: TurnPair;
|
|
94
|
+
last: TurnPair[];
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* What happened inside one turn, in order. A DSH turn averages 5.2 steps and
|
|
98
|
+
* 70% of them call tools, so `user + assistant text` is the outline, not the
|
|
99
|
+
* turn. Steps keep the shape without keeping the reasoning text.
|
|
100
|
+
*/
|
|
101
|
+
export interface TurnStep {
|
|
102
|
+
idx: number;
|
|
103
|
+
kind: 'reasoning' | 'text' | 'tool';
|
|
104
|
+
/** Text for `text` steps; never the reasoning content (only its size). */
|
|
105
|
+
text?: string;
|
|
106
|
+
toolName?: string;
|
|
107
|
+
toolArgsChars?: number;
|
|
108
|
+
toolResultChars?: number;
|
|
109
|
+
ok?: boolean;
|
|
110
|
+
at: number;
|
|
111
|
+
}
|
|
112
|
+
export interface TurnSpec {
|
|
113
|
+
id?: string;
|
|
114
|
+
soulId: string;
|
|
115
|
+
userId: string;
|
|
116
|
+
sessionId: string;
|
|
117
|
+
turnNo: number;
|
|
118
|
+
startedAt: number;
|
|
119
|
+
endedAt?: number;
|
|
120
|
+
userText: string;
|
|
121
|
+
/** What changed by the end of the turn (decision, artifact, open item). */
|
|
122
|
+
outcome?: string;
|
|
123
|
+
status?: 'open' | 'closed';
|
|
124
|
+
steps: TurnStep[];
|
|
125
|
+
createdAt?: number;
|
|
126
|
+
}
|
|
127
|
+
/** A turn read back with its steps. */
|
|
128
|
+
export interface TurnRecord {
|
|
129
|
+
id: string;
|
|
130
|
+
soulId: string;
|
|
131
|
+
userId: string;
|
|
132
|
+
sessionId: string;
|
|
133
|
+
turnNo: number;
|
|
134
|
+
startedAt: number;
|
|
135
|
+
endedAt?: number;
|
|
136
|
+
userText: string;
|
|
137
|
+
/** Concatenated text steps, kept for search and back-compat. */
|
|
138
|
+
assistantText: string;
|
|
139
|
+
outcome?: string;
|
|
140
|
+
status: 'open' | 'closed';
|
|
141
|
+
steps: TurnStep[];
|
|
142
|
+
createdAt: number;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Exhaustive fetch (ADR 0027 + eval-boundary-0027): for questions whose answer
|
|
146
|
+
* is a count or an overview, ranking is the wrong tool — the caller needs every
|
|
147
|
+
* row that matches, and the model does the counting.
|
|
148
|
+
*/
|
|
149
|
+
export interface TurnFindSpec {
|
|
150
|
+
soulId: string;
|
|
151
|
+
userId: string;
|
|
152
|
+
/** Substring over user and assistant text. No tokenizer, no ranking. */
|
|
153
|
+
text?: string;
|
|
154
|
+
sessionId?: string;
|
|
155
|
+
since?: number;
|
|
156
|
+
until?: number;
|
|
157
|
+
/** Hard cap, so a broad filter cannot return the whole history. */
|
|
158
|
+
limit?: number;
|
|
159
|
+
}
|
|
160
|
+
export interface TurnFindResult {
|
|
161
|
+
turns: TurnPair[];
|
|
162
|
+
/** How many rows match, before the cap. */
|
|
163
|
+
total: number;
|
|
164
|
+
/** True when `total` exceeded the cap. */
|
|
165
|
+
truncated: boolean;
|
|
166
|
+
}
|
|
167
|
+
export type EntityType = (typeof ENTITY_TYPES)[number];
|
|
168
|
+
export interface Entity {
|
|
169
|
+
id: string;
|
|
170
|
+
soulId: string;
|
|
171
|
+
userId: string;
|
|
172
|
+
/** person / thing / place / self. `self` is the soul itself. */
|
|
173
|
+
type: EntityType;
|
|
174
|
+
name: string;
|
|
175
|
+
aliases: string[];
|
|
176
|
+
/** Open container: whatever the events taught us, no fixed columns (0010 §8). */
|
|
177
|
+
attrs: Record<string, unknown>;
|
|
178
|
+
firstSeenAt: number;
|
|
179
|
+
lastMentionedAt: number;
|
|
180
|
+
createdAt: number;
|
|
181
|
+
}
|
|
182
|
+
export interface EntitySpec {
|
|
183
|
+
id?: string;
|
|
184
|
+
soulId: string;
|
|
185
|
+
userId: string;
|
|
186
|
+
type: EntityType;
|
|
187
|
+
name: string;
|
|
188
|
+
aliases?: string[];
|
|
189
|
+
attrs?: Record<string, unknown>;
|
|
190
|
+
/** When it was mentioned; defaults to now. Updates lastMentionedAt. */
|
|
191
|
+
seenAt?: number;
|
|
192
|
+
}
|
|
193
|
+
export interface EntityQuery {
|
|
194
|
+
soulId: string;
|
|
195
|
+
userId: string;
|
|
196
|
+
/** Substring over name and aliases. */
|
|
197
|
+
name?: string;
|
|
198
|
+
type?: EntityType;
|
|
199
|
+
limit?: number;
|
|
200
|
+
}
|
|
201
|
+
export interface EntityDraft {
|
|
202
|
+
name: string;
|
|
203
|
+
type: EntityType;
|
|
204
|
+
aliases?: string[];
|
|
205
|
+
attrs?: Record<string, unknown>;
|
|
206
|
+
}
|
|
207
|
+
/** A slot as drafted: it can name an entity that may not exist yet. */
|
|
208
|
+
export type DraftSlotValue = {
|
|
209
|
+
kind: 'entity';
|
|
210
|
+
entityName: string;
|
|
211
|
+
entityType?: EntityType;
|
|
212
|
+
} | {
|
|
213
|
+
kind: 'number';
|
|
214
|
+
value: number;
|
|
215
|
+
} | {
|
|
216
|
+
kind: 'text';
|
|
217
|
+
value: string;
|
|
218
|
+
};
|
|
219
|
+
export interface FactDraft {
|
|
220
|
+
statement: string;
|
|
221
|
+
/** world or a person's name — where the fact holds (ADR 0032). */
|
|
222
|
+
holder?: string;
|
|
223
|
+
typeName?: string;
|
|
224
|
+
at?: number;
|
|
225
|
+
atText?: string;
|
|
226
|
+
atPrecision?: AtPrecision;
|
|
227
|
+
source: FactSource;
|
|
228
|
+
confidence: number;
|
|
229
|
+
/**
|
|
230
|
+
* The model's yes/no answer to "is this an experience about how to work?".
|
|
231
|
+
*
|
|
232
|
+
* A classification input, not a score: the promotion rules (brief 0023) read it to
|
|
233
|
+
* decide whether the experience may be promoted to a rule or a profile line.
|
|
234
|
+
* Absent means no — a wrongly promoted lesson is worse than an unrecorded one.
|
|
235
|
+
*/
|
|
236
|
+
principle?: boolean;
|
|
237
|
+
slots: Array<{
|
|
238
|
+
slot: string;
|
|
239
|
+
value: DraftSlotValue;
|
|
240
|
+
}>;
|
|
241
|
+
}
|
|
242
|
+
export interface GapDraft {
|
|
243
|
+
topic: string;
|
|
244
|
+
aboutEntityName?: string;
|
|
245
|
+
tension: number;
|
|
246
|
+
}
|
|
247
|
+
/** What the model decided to do with one piece of information. */
|
|
248
|
+
export type FactOpKind = 'add' | 'supersede' | 'update' | 'noop';
|
|
249
|
+
export interface FactOperation {
|
|
250
|
+
op: FactOpKind;
|
|
251
|
+
/** The existing fact this operation acts on (supersede / update). */
|
|
252
|
+
targetId?: string;
|
|
253
|
+
fact: FactDraft;
|
|
254
|
+
}
|
|
255
|
+
export interface ExtractDraft {
|
|
256
|
+
entities: EntityDraft[];
|
|
257
|
+
facts: FactDraft[];
|
|
258
|
+
/** Model output: operations instead of raw facts, so merging is explicit. */
|
|
259
|
+
operations?: FactOperation[];
|
|
260
|
+
gaps: GapDraft[];
|
|
261
|
+
by: 'rules' | 'llm';
|
|
262
|
+
/** Why the rules path was used, so a silent fallback cannot hide. */
|
|
263
|
+
reason?: string;
|
|
264
|
+
/** Which topic thread this turn belongs to, when the model said. */
|
|
265
|
+
thread?: ThreadAttribution;
|
|
266
|
+
/**
|
|
267
|
+
* What the model's thread line was: a usable answer, absent, or present but
|
|
268
|
+
* unparseable. Without this the fallback rate is inferred from behaviour instead of
|
|
269
|
+
* measured, and "the model stopped answering" looks identical to "the model chose
|
|
270
|
+
* to continue".
|
|
271
|
+
*/
|
|
272
|
+
threadLine?: 'present' | 'absent' | 'invalid';
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Where a turn belongs. `continue` must name a thread the model was shown; it may also
|
|
276
|
+
* carry a new topic when the subject has moved inside the same thread.
|
|
277
|
+
*
|
|
278
|
+
* An unparseable or unknown answer is not evidence for a new topic: the caller falls
|
|
279
|
+
* back to the previous turn's thread (ADR 0034), because a wrong split leaves fragments
|
|
280
|
+
* that starve consolidation while a wrong merge can be split later.
|
|
281
|
+
*/
|
|
282
|
+
export type ThreadAttribution = {
|
|
283
|
+
kind: 'continue';
|
|
284
|
+
id: string;
|
|
285
|
+
topic?: string;
|
|
286
|
+
} | {
|
|
287
|
+
kind: 'new';
|
|
288
|
+
topic?: string;
|
|
289
|
+
};
|
|
290
|
+
/** What a commit actually created or merged. */
|
|
291
|
+
export interface CommitResult {
|
|
292
|
+
entities: Entity[];
|
|
293
|
+
facts: Fact[];
|
|
294
|
+
gaps: Gap[];
|
|
295
|
+
/** Drafts refused outright: unreadable statements and exact duplicates. */
|
|
296
|
+
skipped: Array<{
|
|
297
|
+
what: string;
|
|
298
|
+
reason: string;
|
|
299
|
+
}>;
|
|
300
|
+
/**
|
|
301
|
+
* Slots that named something undeclared: the words are kept as text and no entity
|
|
302
|
+
* is created. Recorded so degradation is visible instead of silent.
|
|
303
|
+
*/
|
|
304
|
+
droppedSlots: Array<{
|
|
305
|
+
fact: string;
|
|
306
|
+
slot: string;
|
|
307
|
+
value: string;
|
|
308
|
+
}>;
|
|
309
|
+
/** Holders that were not known: the fact stays, in the world layer. */
|
|
310
|
+
holderFallbacks: Array<{
|
|
311
|
+
fact: string;
|
|
312
|
+
holder: string;
|
|
313
|
+
}>;
|
|
314
|
+
}
|
|
315
|
+
export type SlotValue = {
|
|
316
|
+
kind: 'entity';
|
|
317
|
+
entityId: string;
|
|
318
|
+
} | {
|
|
319
|
+
kind: 'number';
|
|
320
|
+
value: number;
|
|
321
|
+
} | {
|
|
322
|
+
kind: 'text';
|
|
323
|
+
value: string;
|
|
324
|
+
} | {
|
|
325
|
+
kind: 'fact';
|
|
326
|
+
factId: string;
|
|
327
|
+
};
|
|
328
|
+
/** One named end of a fact, e.g. `离职者` → 小林, `裁员人数` → 300. */
|
|
329
|
+
export interface FactSlot {
|
|
330
|
+
slot: string;
|
|
331
|
+
value: SlotValue;
|
|
332
|
+
}
|
|
333
|
+
export type { FactStatus, FactSource, AtPrecision } from './config/status.ts';
|
|
334
|
+
import type { FactStatus, FactSource, AtPrecision } from './config/status.ts';
|
|
335
|
+
import { ENTITY_TYPES } from './config/domains.ts';
|
|
336
|
+
/** One of FACT_ROLES; declared with the values so the two cannot drift. */
|
|
337
|
+
export type FactRole = (typeof import('./config/domains.ts').FACT_ROLES)[number];
|
|
338
|
+
export interface Fact {
|
|
339
|
+
id: string;
|
|
340
|
+
soulId: string;
|
|
341
|
+
userId: string;
|
|
342
|
+
statement: string;
|
|
343
|
+
/** Free text ("裁员" / "道歉" / "请求"); code never branches on it. */
|
|
344
|
+
typeName?: string;
|
|
345
|
+
/**
|
|
346
|
+
* What the fact is *for* (closed set in config/domains.ts). Optional during the transition:
|
|
347
|
+
* older rows have no role, and readers fall back to typeName through `roleOf()`.
|
|
348
|
+
*/
|
|
349
|
+
role?: FactRole;
|
|
350
|
+
/** Where it holds: `world`, `self`, or an entity id (in someone's mind). */
|
|
351
|
+
holder: string;
|
|
352
|
+
/** Event time. Optional: a preference is a standing fact without one. */
|
|
353
|
+
at?: number;
|
|
354
|
+
/** The fuzzy time expression as said ("上周三"), when `at` is approximate. */
|
|
355
|
+
atText?: string;
|
|
356
|
+
atEnd?: number;
|
|
357
|
+
/** Locatability, not precision: unknown is a value (ADR 0032). */
|
|
358
|
+
atPrecision?: AtPrecision;
|
|
359
|
+
placeId?: string;
|
|
360
|
+
status: FactStatus;
|
|
361
|
+
confidence: number;
|
|
362
|
+
source: FactSource;
|
|
363
|
+
sourceTurnId?: string;
|
|
364
|
+
supersededBy?: string;
|
|
365
|
+
createdAt: number;
|
|
366
|
+
/** How many times retrieval has surfaced it. Decay slows with use (0019). */
|
|
367
|
+
recallCount: number;
|
|
368
|
+
/** Last time retrieval surfaced it. */
|
|
369
|
+
lastRecalledAt?: number;
|
|
370
|
+
slots: FactSlot[];
|
|
371
|
+
}
|
|
372
|
+
export interface FactSpec {
|
|
373
|
+
id?: string;
|
|
374
|
+
soulId: string;
|
|
375
|
+
userId: string;
|
|
376
|
+
statement: string;
|
|
377
|
+
typeName?: string;
|
|
378
|
+
/** Structural role (config/domains.ts FACT_ROLES); the writer derives it if omitted. */
|
|
379
|
+
role?: FactRole;
|
|
380
|
+
holder?: string;
|
|
381
|
+
at?: number;
|
|
382
|
+
atText?: string;
|
|
383
|
+
atEnd?: number;
|
|
384
|
+
atPrecision?: AtPrecision;
|
|
385
|
+
placeId?: string;
|
|
386
|
+
status?: FactStatus;
|
|
387
|
+
confidence?: number;
|
|
388
|
+
source?: FactSource;
|
|
389
|
+
sourceTurnId?: string;
|
|
390
|
+
supersededBy?: string;
|
|
391
|
+
slots?: FactSlot[];
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
394
|
+
* One fact plus the conversation it came from: the memory's hook on top, the
|
|
395
|
+
* detail underneath. The model reads hooks first and asks for this only when it
|
|
396
|
+
* needs the original words.
|
|
397
|
+
*/
|
|
398
|
+
export interface FactDetail {
|
|
399
|
+
fact: Fact;
|
|
400
|
+
turn?: {
|
|
401
|
+
id: string;
|
|
402
|
+
userText: string;
|
|
403
|
+
assistantText: string;
|
|
404
|
+
at: number;
|
|
405
|
+
};
|
|
406
|
+
}
|
|
407
|
+
export interface FactQuery {
|
|
408
|
+
soulId: string;
|
|
409
|
+
userId: string;
|
|
410
|
+
/** Only facts that have a slot pointing at this entity. */
|
|
411
|
+
entityId?: string;
|
|
412
|
+
since?: number;
|
|
413
|
+
until?: number;
|
|
414
|
+
status?: FactStatus;
|
|
415
|
+
/** Only facts whose holder is this (world / self / entity id). */
|
|
416
|
+
holder?: string;
|
|
417
|
+
/** Sort by event time. Default desc (newest first); asc gives the earliest. */
|
|
418
|
+
order?: 'asc' | 'desc';
|
|
419
|
+
limit?: number;
|
|
420
|
+
}
|
|
421
|
+
export type GapStatus = 'open' | 'closed' | 'dropped';
|
|
422
|
+
/** Something the soul wants to know and does not (0009 §4.6.1). */
|
|
423
|
+
export interface Gap {
|
|
424
|
+
id: string;
|
|
425
|
+
soulId: string;
|
|
426
|
+
userId: string;
|
|
427
|
+
aboutEntityId?: string;
|
|
428
|
+
aboutFactId?: string;
|
|
429
|
+
topic: string;
|
|
430
|
+
/** Grows with time; the highest one is the one worth asking about. */
|
|
431
|
+
tension: number;
|
|
432
|
+
status: GapStatus;
|
|
433
|
+
openedAt: number;
|
|
434
|
+
closedAt?: number;
|
|
435
|
+
closedByFactId?: string;
|
|
436
|
+
}
|
|
437
|
+
export interface GapSpec {
|
|
438
|
+
id?: string;
|
|
439
|
+
soulId: string;
|
|
440
|
+
userId: string;
|
|
441
|
+
aboutEntityId?: string;
|
|
442
|
+
aboutFactId?: string;
|
|
443
|
+
topic: string;
|
|
444
|
+
tension?: number;
|
|
445
|
+
status?: GapStatus;
|
|
446
|
+
openedAt?: number;
|
|
447
|
+
closedAt?: number;
|
|
448
|
+
closedByFactId?: string;
|
|
449
|
+
}
|
|
73
450
|
/** Six dimensions, each -2..+2. Baseline is slightly positive. */
|
|
74
451
|
export interface Emotion {
|
|
75
452
|
passion: number;
|
|
@@ -102,6 +479,27 @@ export interface ContextRequest {
|
|
|
102
479
|
minImportance?: number;
|
|
103
480
|
/** Cap the number of injected memory lines. */
|
|
104
481
|
maxItems?: number;
|
|
482
|
+
/** Include the identity block. Defaults to true. */
|
|
483
|
+
includeSoul?: boolean;
|
|
484
|
+
/** Include the style block. Defaults to true. */
|
|
485
|
+
includeStyle?: boolean;
|
|
486
|
+
/**
|
|
487
|
+
* Include the affect block. Defaults to true.
|
|
488
|
+
*
|
|
489
|
+
* Same reason as includeStyle: the affect sample changes almost every turn, so a
|
|
490
|
+
* host that puts context() output into a stable system prompt must exclude it —
|
|
491
|
+
* otherwise every turn appends a new prompt version. Affects belong in the
|
|
492
|
+
* per-turn message channel, which is where the adapter puts them.
|
|
493
|
+
*/
|
|
494
|
+
includeAffect?: boolean;
|
|
495
|
+
/**
|
|
496
|
+
* Include the anchor memories block. Defaults to true.
|
|
497
|
+
*
|
|
498
|
+
* Hosts put this in the system prompt, which DSH appends as a new prompt
|
|
499
|
+
* version whenever the text changes; anchors drift as recency shifts, so a
|
|
500
|
+
* long session accumulates versions. Passing false keeps the stable part only.
|
|
501
|
+
*/
|
|
502
|
+
includeAnchors?: boolean;
|
|
105
503
|
}
|
|
106
504
|
export interface ContextResult {
|
|
107
505
|
text: string;
|
|
@@ -225,3 +623,46 @@ export interface Correction {
|
|
|
225
623
|
rule?: string;
|
|
226
624
|
deviceId?: string;
|
|
227
625
|
}
|
|
626
|
+
/**
|
|
627
|
+
* One conclusion the model proposes. `evidence` holds fact ids: the gate refuses
|
|
628
|
+
* anything citing fewer than two, because one observation is a fact, not a
|
|
629
|
+
* conclusion.
|
|
630
|
+
*/
|
|
631
|
+
export interface ConclusionDraft {
|
|
632
|
+
statement: string;
|
|
633
|
+
evidence: string[];
|
|
634
|
+
confidence: number;
|
|
635
|
+
/** Old conclusion this replaces, when the new evidence contradicts it. */
|
|
636
|
+
supersedes?: string;
|
|
637
|
+
/** The evidence text, used only to tell quoting from over-generalising. */
|
|
638
|
+
evidenceText?: string;
|
|
639
|
+
}
|
|
640
|
+
/**
|
|
641
|
+
* A topic thread: the unit of "understanding" a conversation.
|
|
642
|
+
*
|
|
643
|
+
* Deliberately not a contiguous segment — a conversation interleaves (A B A),
|
|
644
|
+
* and a segment model would cut A in half. A thread's turns need not be adjacent.
|
|
645
|
+
*/
|
|
646
|
+
export interface TurnThread {
|
|
647
|
+
id: string;
|
|
648
|
+
soulId: string;
|
|
649
|
+
userId: string;
|
|
650
|
+
sessionId: string;
|
|
651
|
+
topic: string;
|
|
652
|
+
status: 'open' | 'closed';
|
|
653
|
+
openedAt: number;
|
|
654
|
+
closedAt?: number;
|
|
655
|
+
/** Last turn number seen in this thread; used to order candidates. */
|
|
656
|
+
lastTurnNo?: number;
|
|
657
|
+
/** The conclusion written when the thread closed. */
|
|
658
|
+
summaryFactId?: string;
|
|
659
|
+
}
|
|
660
|
+
export interface ThreadSpec {
|
|
661
|
+
id?: string;
|
|
662
|
+
soulId: string;
|
|
663
|
+
userId: string;
|
|
664
|
+
sessionId: string;
|
|
665
|
+
topic: string;
|
|
666
|
+
openedAt: number;
|
|
667
|
+
turnNo?: number;
|
|
668
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "soulbridge",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.98",
|
|
4
4
|
"description": "A personality layer for any agent: continuity, forgetting, and growth across tools.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -46,11 +46,13 @@
|
|
|
46
46
|
"claude-code"
|
|
47
47
|
],
|
|
48
48
|
"scripts": {
|
|
49
|
-
"build": "tsc -p tsconfig.build.json",
|
|
49
|
+
"build": "node scripts/sync-prompts.mjs --check && tsc -p tsconfig.build.json",
|
|
50
50
|
"test": "node --test \"packages/core/test/*.test.ts\"",
|
|
51
51
|
"demo": "node packages/cli/src/cli.ts demo",
|
|
52
52
|
"typecheck": "tsc --noEmit",
|
|
53
|
-
"prepublishOnly": "npm run build && npm test"
|
|
53
|
+
"prepublishOnly": "npm run build && npm test",
|
|
54
|
+
"sync:prompts": "node scripts/sync-prompts.mjs",
|
|
55
|
+
"prepare": "node scripts/install-hooks.mjs"
|
|
54
56
|
},
|
|
55
57
|
"devDependencies": {
|
|
56
58
|
"@types/node": "^26.6.5",
|