@agenr/skeln-plugin 3.3.0
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 +21 -0
- package/README.md +42 -0
- package/dist/chunk-5LADPJ4C.js +2436 -0
- package/dist/chunk-KH52KJSJ.js +874 -0
- package/dist/chunk-M5M65AYP.js +4079 -0
- package/dist/chunk-RYMSM3OS.js +3063 -0
- package/dist/chunk-Z5X7T4QZ.js +7990 -0
- package/dist/chunk-ZYADFKX3.js +115 -0
- package/dist/claim-slot-policy-CQ-h0GaV.d.ts +880 -0
- package/dist/cli.d.ts +1 -0
- package/dist/index.d.ts +2009 -0
- package/dist/index.js +6508 -0
- package/dist/internal-eval-server.d.ts +1 -0
- package/dist/internal-recall-eval-server.d.ts +1 -0
- package/package.json +61 -0
|
@@ -0,0 +1,880 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core domain types for agenr.
|
|
3
|
+
* These types have zero infrastructure dependencies.
|
|
4
|
+
*/
|
|
5
|
+
/** Ordered list of supported durable knowledge entry categories. */
|
|
6
|
+
declare const ENTRY_TYPES: readonly ["fact", "decision", "preference", "lesson", "relationship", "milestone"];
|
|
7
|
+
/**
|
|
8
|
+
* Union of all supported knowledge entry categories.
|
|
9
|
+
*/
|
|
10
|
+
type EntryType = (typeof ENTRY_TYPES)[number];
|
|
11
|
+
/** Ordered list of supported recall durability levels. */
|
|
12
|
+
declare const EXPIRY_LEVELS: readonly ["core", "permanent", "temporary"];
|
|
13
|
+
/** Ordered list of supported claim-key lifecycle statuses. */
|
|
14
|
+
declare const CLAIM_KEY_STATUSES: readonly ["trusted", "tentative", "unresolved"];
|
|
15
|
+
/** Ordered list of supported claim-key provenance sources. */
|
|
16
|
+
declare const CLAIM_KEY_SOURCES: readonly ["manual", "model", "json_retry", "deterministic_repair", "surgeon_metadata_rewrite", "surgeon_family_reuse", "surgeon_compaction"];
|
|
17
|
+
/** Ordered list of supported claim-support provenance modes. */
|
|
18
|
+
declare const CLAIM_SUPPORT_MODES: readonly ["explicit", "normalized", "inferred"];
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Union of all supported recall durability levels.
|
|
22
|
+
*/
|
|
23
|
+
type Expiry = (typeof EXPIRY_LEVELS)[number];
|
|
24
|
+
/**
|
|
25
|
+
* Union of all supported claim-key lifecycle statuses.
|
|
26
|
+
*/
|
|
27
|
+
type ClaimKeyStatus = (typeof CLAIM_KEY_STATUSES)[number];
|
|
28
|
+
/**
|
|
29
|
+
* Union of all supported claim-key provenance sources.
|
|
30
|
+
*/
|
|
31
|
+
type ClaimKeySource = (typeof CLAIM_KEY_SOURCES)[number];
|
|
32
|
+
/**
|
|
33
|
+
* Union of all supported claim-support provenance modes.
|
|
34
|
+
*/
|
|
35
|
+
type ClaimSupportMode = (typeof CLAIM_SUPPORT_MODES)[number];
|
|
36
|
+
/** Ordered list of supported episode sources. */
|
|
37
|
+
declare const EPISODE_SOURCES: readonly ["openclaw", "skeln", "codex", "cli", "synthesis"];
|
|
38
|
+
/** Ordered list of supported episode activity levels. */
|
|
39
|
+
declare const EPISODE_ACTIVITY_LEVELS: readonly ["substantial", "minimal", "none"];
|
|
40
|
+
/** Ordered list of supported procedure step kinds. */
|
|
41
|
+
declare const PROCEDURE_STEP_KINDS: readonly ["run_command", "read_reference", "inspect_state", "edit_file", "ask_user", "invoke_tool", "verify"];
|
|
42
|
+
/** Ordered list of supported procedure provenance source kinds. */
|
|
43
|
+
declare const PROCEDURE_SOURCE_KINDS: readonly ["skill", "doc", "entry", "episode", "repo_file", "manual"];
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Union of all supported episode sources.
|
|
47
|
+
*/
|
|
48
|
+
type EpisodeSource = (typeof EPISODE_SOURCES)[number];
|
|
49
|
+
/**
|
|
50
|
+
* Union of all supported episode activity levels.
|
|
51
|
+
*/
|
|
52
|
+
type EpisodeActivityLevel = (typeof EPISODE_ACTIVITY_LEVELS)[number];
|
|
53
|
+
/**
|
|
54
|
+
* Union of all supported procedure step kinds.
|
|
55
|
+
*/
|
|
56
|
+
type ProcedureStepKind = (typeof PROCEDURE_STEP_KINDS)[number];
|
|
57
|
+
/**
|
|
58
|
+
* Union of all supported procedure provenance source kinds.
|
|
59
|
+
*/
|
|
60
|
+
type ProcedureSourceKind = (typeof PROCEDURE_SOURCE_KINDS)[number];
|
|
61
|
+
/**
|
|
62
|
+
* Explicit lifecycle and provenance metadata attached to a stored claim key.
|
|
63
|
+
*/
|
|
64
|
+
interface ClaimKeyLifecycleMetadata {
|
|
65
|
+
claim_key_raw?: string;
|
|
66
|
+
claim_key_status?: ClaimKeyStatus;
|
|
67
|
+
claim_key_source?: ClaimKeySource;
|
|
68
|
+
claim_key_confidence?: number;
|
|
69
|
+
claim_key_rationale?: string;
|
|
70
|
+
claim_support_source_kind?: string;
|
|
71
|
+
claim_support_locator?: string;
|
|
72
|
+
claim_support_observed_at?: string;
|
|
73
|
+
claim_support_mode?: ClaimSupportMode;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Canonical stored knowledge record.
|
|
77
|
+
*/
|
|
78
|
+
interface Entry extends ClaimKeyLifecycleMetadata {
|
|
79
|
+
id: string;
|
|
80
|
+
type: EntryType;
|
|
81
|
+
subject: string;
|
|
82
|
+
content: string;
|
|
83
|
+
importance: number;
|
|
84
|
+
expiry: Expiry;
|
|
85
|
+
tags: string[];
|
|
86
|
+
source_file?: string;
|
|
87
|
+
source_context?: string;
|
|
88
|
+
embedding?: number[];
|
|
89
|
+
content_hash?: string;
|
|
90
|
+
norm_content_hash?: string;
|
|
91
|
+
quality_score: number;
|
|
92
|
+
recall_count: number;
|
|
93
|
+
last_recalled_at?: string;
|
|
94
|
+
superseded_by?: string;
|
|
95
|
+
valid_from?: string;
|
|
96
|
+
valid_to?: string;
|
|
97
|
+
claim_key?: string;
|
|
98
|
+
supersession_kind?: string;
|
|
99
|
+
supersession_reason?: string;
|
|
100
|
+
cluster_id?: string;
|
|
101
|
+
user_id?: string;
|
|
102
|
+
project?: string;
|
|
103
|
+
retired: boolean;
|
|
104
|
+
retired_at?: string;
|
|
105
|
+
retired_reason?: string;
|
|
106
|
+
created_at: string;
|
|
107
|
+
updated_at: string;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Mutable entry fields supported by direct update paths.
|
|
111
|
+
*
|
|
112
|
+
* Claim-key lifecycle updates are replacement-style, not merge-style. When any
|
|
113
|
+
* lifecycle field is mutated, callers must provide one complete validated
|
|
114
|
+
* lifecycle payload for the target claim key. Partial lifecycle patches are
|
|
115
|
+
* rejected at the persistence boundary.
|
|
116
|
+
*/
|
|
117
|
+
interface EntryUpdateInput {
|
|
118
|
+
importance?: Entry["importance"];
|
|
119
|
+
expiry?: Entry["expiry"];
|
|
120
|
+
claim_key?: Entry["claim_key"];
|
|
121
|
+
claim_key_raw?: Entry["claim_key_raw"];
|
|
122
|
+
claim_key_status?: Entry["claim_key_status"];
|
|
123
|
+
claim_key_source?: Entry["claim_key_source"];
|
|
124
|
+
claim_key_confidence?: Entry["claim_key_confidence"];
|
|
125
|
+
claim_key_rationale?: Entry["claim_key_rationale"];
|
|
126
|
+
claim_support_source_kind?: Entry["claim_support_source_kind"];
|
|
127
|
+
claim_support_locator?: Entry["claim_support_locator"];
|
|
128
|
+
claim_support_observed_at?: Entry["claim_support_observed_at"];
|
|
129
|
+
claim_support_mode?: Entry["claim_support_mode"];
|
|
130
|
+
valid_from?: Entry["valid_from"];
|
|
131
|
+
valid_to?: Entry["valid_to"];
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Canonical stored episodic-memory record.
|
|
135
|
+
*/
|
|
136
|
+
interface Episode {
|
|
137
|
+
id: string;
|
|
138
|
+
source: EpisodeSource;
|
|
139
|
+
sourceId?: string;
|
|
140
|
+
sourceRef?: string;
|
|
141
|
+
transcriptHash?: string;
|
|
142
|
+
summaryHash?: string;
|
|
143
|
+
agentId?: string;
|
|
144
|
+
surface?: string;
|
|
145
|
+
startedAt: string;
|
|
146
|
+
endedAt?: string;
|
|
147
|
+
summary: string;
|
|
148
|
+
tags: string[];
|
|
149
|
+
activityLevel?: EpisodeActivityLevel;
|
|
150
|
+
userId?: string;
|
|
151
|
+
project?: string;
|
|
152
|
+
genModel?: string;
|
|
153
|
+
genVersion?: string;
|
|
154
|
+
messageCount?: number;
|
|
155
|
+
embedding?: number[];
|
|
156
|
+
retired: boolean;
|
|
157
|
+
retiredAt?: string;
|
|
158
|
+
retiredReason?: string;
|
|
159
|
+
supersededBy?: string;
|
|
160
|
+
createdAt: string;
|
|
161
|
+
updatedAt: string;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Explicit authored provenance attached to a procedure or reference step.
|
|
165
|
+
*/
|
|
166
|
+
interface ProcedureSource {
|
|
167
|
+
kind: ProcedureSourceKind;
|
|
168
|
+
path?: string;
|
|
169
|
+
locator?: string;
|
|
170
|
+
label?: string;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Closed JSON-like value space accepted by `invoke_tool.arguments`.
|
|
174
|
+
*/
|
|
175
|
+
type ProcedureToolArgumentValue = string | number | boolean | null | {
|
|
176
|
+
[key: string]: ProcedureToolArgumentValue;
|
|
177
|
+
} | ProcedureToolArgumentValue[];
|
|
178
|
+
/**
|
|
179
|
+
* Condition that scopes a step to one supported harness value.
|
|
180
|
+
*/
|
|
181
|
+
interface ProcedureHarnessCondition {
|
|
182
|
+
kind: "harness_is";
|
|
183
|
+
value: string;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Condition that scopes a step to one available tool name.
|
|
187
|
+
*/
|
|
188
|
+
interface ProcedureToolAvailableCondition {
|
|
189
|
+
kind: "tool_available";
|
|
190
|
+
value: string;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Condition that requires one exact file path to exist.
|
|
194
|
+
*/
|
|
195
|
+
interface ProcedureFileExistsCondition {
|
|
196
|
+
kind: "file_exists";
|
|
197
|
+
path: string;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Condition that requires one path to exist.
|
|
201
|
+
*/
|
|
202
|
+
interface ProcedurePathExistsCondition {
|
|
203
|
+
kind: "path_exists";
|
|
204
|
+
path: string;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Condition that checks one environment flag by name and optional value.
|
|
208
|
+
*/
|
|
209
|
+
interface ProcedureEnvFlagCondition {
|
|
210
|
+
kind: "env_flag";
|
|
211
|
+
name: string;
|
|
212
|
+
value?: string;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Condition that checks one bounded repository-state marker.
|
|
216
|
+
*/
|
|
217
|
+
interface ProcedureRepoStateCondition {
|
|
218
|
+
kind: "repo_state";
|
|
219
|
+
value: string;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Condition that requires one explicit user confirmation token.
|
|
223
|
+
*/
|
|
224
|
+
interface ProcedureUserConfirmedCondition {
|
|
225
|
+
kind: "user_confirmed";
|
|
226
|
+
value: string;
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Supported bounded declarative condition union for procedure steps.
|
|
230
|
+
*/
|
|
231
|
+
type ProcedureCondition = ProcedureHarnessCondition | ProcedureToolAvailableCondition | ProcedureFileExistsCondition | ProcedurePathExistsCondition | ProcedureEnvFlagCondition | ProcedureRepoStateCondition | ProcedureUserConfirmedCondition;
|
|
232
|
+
/**
|
|
233
|
+
* Shared authored fields carried by every normalized procedure step.
|
|
234
|
+
*/
|
|
235
|
+
interface ProcedureStepBase {
|
|
236
|
+
id: string;
|
|
237
|
+
kind: ProcedureStepKind;
|
|
238
|
+
instruction: string;
|
|
239
|
+
conditions?: ProcedureCondition[];
|
|
240
|
+
stop_if?: ProcedureCondition[];
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Step that records one shell command to run.
|
|
244
|
+
*/
|
|
245
|
+
interface ProcedureRunCommandStep extends ProcedureStepBase {
|
|
246
|
+
kind: "run_command";
|
|
247
|
+
command: string;
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Step that points readers at an external reference.
|
|
251
|
+
*/
|
|
252
|
+
interface ProcedureReadReferenceStep extends ProcedureStepBase {
|
|
253
|
+
kind: "read_reference";
|
|
254
|
+
ref: ProcedureSource;
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Step that asks the agent to inspect current state before continuing.
|
|
258
|
+
*/
|
|
259
|
+
interface ProcedureInspectStateStep extends ProcedureStepBase {
|
|
260
|
+
kind: "inspect_state";
|
|
261
|
+
target?: string;
|
|
262
|
+
query?: string;
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Step that describes one file edit in human-readable terms.
|
|
266
|
+
*/
|
|
267
|
+
interface ProcedureEditFileStep extends ProcedureStepBase {
|
|
268
|
+
kind: "edit_file";
|
|
269
|
+
path: string;
|
|
270
|
+
edit: string;
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Step that asks the agent to collect input from the user.
|
|
274
|
+
*/
|
|
275
|
+
interface ProcedureAskUserStep extends ProcedureStepBase {
|
|
276
|
+
kind: "ask_user";
|
|
277
|
+
prompt: string;
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Step that invokes a structured tool with optional arguments.
|
|
281
|
+
*/
|
|
282
|
+
interface ProcedureInvokeToolStep extends ProcedureStepBase {
|
|
283
|
+
kind: "invoke_tool";
|
|
284
|
+
tool: string;
|
|
285
|
+
arguments?: {
|
|
286
|
+
[key: string]: ProcedureToolArgumentValue;
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Step that checks whether the procedure completed successfully.
|
|
291
|
+
*/
|
|
292
|
+
interface ProcedureVerifyStep extends ProcedureStepBase {
|
|
293
|
+
kind: "verify";
|
|
294
|
+
checks: string[];
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Supported authored procedure-step union.
|
|
298
|
+
*/
|
|
299
|
+
type ProcedureStep = ProcedureRunCommandStep | ProcedureReadReferenceStep | ProcedureInspectStateStep | ProcedureEditFileStep | ProcedureAskUserStep | ProcedureInvokeToolStep | ProcedureVerifyStep;
|
|
300
|
+
/**
|
|
301
|
+
* Canonical normalized procedure body stored in `body_json`.
|
|
302
|
+
*/
|
|
303
|
+
interface ProcedureDefinition {
|
|
304
|
+
procedure_key: string;
|
|
305
|
+
title: string;
|
|
306
|
+
goal: string;
|
|
307
|
+
when_to_use: string[];
|
|
308
|
+
when_not_to_use: string[];
|
|
309
|
+
prerequisites: string[];
|
|
310
|
+
steps: ProcedureStep[];
|
|
311
|
+
verification: string[];
|
|
312
|
+
failure_modes: string[];
|
|
313
|
+
sources: ProcedureSource[];
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* Lifecycle and revision metadata stored alongside a procedure revision.
|
|
317
|
+
*/
|
|
318
|
+
interface ProcedureLifecycleMetadata {
|
|
319
|
+
recall_text: string;
|
|
320
|
+
revision_hash: string;
|
|
321
|
+
source_hash: string;
|
|
322
|
+
retired: boolean;
|
|
323
|
+
retired_at?: string;
|
|
324
|
+
retired_reason?: string;
|
|
325
|
+
superseded_by?: string;
|
|
326
|
+
created_at: string;
|
|
327
|
+
updated_at: string;
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Canonical stored procedural-memory record.
|
|
331
|
+
*/
|
|
332
|
+
interface Procedure extends ProcedureDefinition, ProcedureLifecycleMetadata {
|
|
333
|
+
id: string;
|
|
334
|
+
source_file?: string;
|
|
335
|
+
embedding?: number[];
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* Aggregate active corpus counts for one entity prefix.
|
|
340
|
+
*/
|
|
341
|
+
interface ClaimKeyEntityPrefixStats {
|
|
342
|
+
entityPrefix: string;
|
|
343
|
+
activeEntryCount: number;
|
|
344
|
+
trustedEntryCount: number;
|
|
345
|
+
tentativeEntryCount: number;
|
|
346
|
+
unresolvedEntryCount: number;
|
|
347
|
+
legacyEntryCount: number;
|
|
348
|
+
deterministicRepairEntryCount: number;
|
|
349
|
+
manualEntryCount: number;
|
|
350
|
+
modelEntryCount: number;
|
|
351
|
+
jsonRetryEntryCount: number;
|
|
352
|
+
surgeonFamilyReuseEntryCount: number;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* Write-time episode payload before adapter-managed identity and lifecycle fields are applied.
|
|
357
|
+
*/
|
|
358
|
+
interface EpisodeInput {
|
|
359
|
+
source: EpisodeSource;
|
|
360
|
+
sourceId?: string;
|
|
361
|
+
sourceRef?: string;
|
|
362
|
+
transcriptHash?: string;
|
|
363
|
+
summaryHash?: string;
|
|
364
|
+
agentId?: string;
|
|
365
|
+
surface?: string;
|
|
366
|
+
startedAt: string;
|
|
367
|
+
endedAt?: string;
|
|
368
|
+
summary: string;
|
|
369
|
+
tags?: string[];
|
|
370
|
+
activityLevel?: EpisodeActivityLevel;
|
|
371
|
+
userId?: string;
|
|
372
|
+
project?: string;
|
|
373
|
+
genModel?: string;
|
|
374
|
+
genVersion?: string;
|
|
375
|
+
messageCount?: number;
|
|
376
|
+
embedding?: number[];
|
|
377
|
+
}
|
|
378
|
+
/**
|
|
379
|
+
* Calendar-aware temporal constraint used by future episode retrieval.
|
|
380
|
+
*/
|
|
381
|
+
interface TemporalWindow {
|
|
382
|
+
kind: "interval" | "anchor" | "open_start" | "open_end";
|
|
383
|
+
start?: Date;
|
|
384
|
+
end?: Date;
|
|
385
|
+
anchor?: Date;
|
|
386
|
+
radiusDays?: number;
|
|
387
|
+
source: "explicit" | "inferred";
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* Upsert outcome returned by episode persistence adapters.
|
|
391
|
+
*/
|
|
392
|
+
interface EpisodeUpsertResult {
|
|
393
|
+
episode: Episode;
|
|
394
|
+
action: "inserted" | "updated" | "unchanged";
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* Internal ranking profiles that adjust recall scoring for specific query intents.
|
|
399
|
+
*/
|
|
400
|
+
type RecallRankingProfile = "historical_state" | "entity_attribute";
|
|
401
|
+
/**
|
|
402
|
+
* Supported attribute buckets for precision-first entity recall.
|
|
403
|
+
*/
|
|
404
|
+
type EntityAttributeKind = "identity" | "location" | "email" | "phone" | "address";
|
|
405
|
+
/**
|
|
406
|
+
* Narrow structured query shape for precision-first entity-attribute recall.
|
|
407
|
+
*/
|
|
408
|
+
interface EntityAttributeQueryShape {
|
|
409
|
+
kind: "entity_attribute";
|
|
410
|
+
entityText: string;
|
|
411
|
+
normalizedEntity: string;
|
|
412
|
+
entityTokens: string[];
|
|
413
|
+
attributeKind: EntityAttributeKind;
|
|
414
|
+
attributeTokens: string[];
|
|
415
|
+
}
|
|
416
|
+
/**
|
|
417
|
+
* Input to the v1 recall pipeline.
|
|
418
|
+
*/
|
|
419
|
+
interface RecallInput {
|
|
420
|
+
text: string;
|
|
421
|
+
limit?: number;
|
|
422
|
+
threshold?: number;
|
|
423
|
+
budget?: number;
|
|
424
|
+
types?: EntryType[];
|
|
425
|
+
tags?: string[];
|
|
426
|
+
since?: string;
|
|
427
|
+
until?: string;
|
|
428
|
+
around?: string;
|
|
429
|
+
aroundRadius?: number;
|
|
430
|
+
asOf?: string;
|
|
431
|
+
sessionKey?: string;
|
|
432
|
+
rankingProfile?: RecallRankingProfile;
|
|
433
|
+
queryShape?: EntityAttributeQueryShape;
|
|
434
|
+
}
|
|
435
|
+
/**
|
|
436
|
+
* A single scored recall result with signal breakdown metadata.
|
|
437
|
+
*
|
|
438
|
+
* The composite `score` is built from `relevance`, `recency`, and `importance`.
|
|
439
|
+
* `relevance` is the normalized reciprocal rank fusion (RRF) score computed in
|
|
440
|
+
* `src/core/recall/fusion.ts`. `vector` and `lexical` are retained as
|
|
441
|
+
* evidence-only diagnostics: they explain which retrieval channels admitted
|
|
442
|
+
* the candidate and let traces inspect raw similarity, but neither participates
|
|
443
|
+
* in the composite score directly now that RRF owns the fused signal.
|
|
444
|
+
*/
|
|
445
|
+
interface RecallOutput {
|
|
446
|
+
entry: Entry;
|
|
447
|
+
score: number;
|
|
448
|
+
scores: {
|
|
449
|
+
/** Fused reciprocal rank fusion score used as the composite relevance signal. */
|
|
450
|
+
relevance: number;
|
|
451
|
+
/** Alias of `relevance` that makes the RRF origin explicit in traces. */
|
|
452
|
+
rrf: number;
|
|
453
|
+
/** Evidence-only raw vector similarity score. Not part of the composite. */
|
|
454
|
+
vector: number;
|
|
455
|
+
/** Evidence-only raw lexical overlap score. Not part of the composite. */
|
|
456
|
+
lexical: number;
|
|
457
|
+
recency: number;
|
|
458
|
+
importance: number;
|
|
459
|
+
historicalLineage: number;
|
|
460
|
+
/** Seeded neighborhood rerank boost applied after RRF and historical lineage. */
|
|
461
|
+
neighborhoodBoost: number;
|
|
462
|
+
claimKeyTrustPenalty: number;
|
|
463
|
+
claimKeyRedundancyPenalty: number;
|
|
464
|
+
/**
|
|
465
|
+
* Raw cross-encoder score in the 0-1 range when the rerank stage
|
|
466
|
+
* produced one for this candidate. Absent when the candidate fell
|
|
467
|
+
* outside the shortlist, when the stage was disabled, or when the
|
|
468
|
+
* provider failed.
|
|
469
|
+
*/
|
|
470
|
+
crossEncoder?: number;
|
|
471
|
+
};
|
|
472
|
+
}
|
|
473
|
+
/**
|
|
474
|
+
* Minimal entry fields needed during recall scoring before final hydration.
|
|
475
|
+
*/
|
|
476
|
+
type RecallCandidateEntry = Pick<Entry, "id" | "subject" | "content" | "importance" | "expiry" | "created_at" | "embedding" | "superseded_by" | "claim_key" | "claim_key_status" | "claim_support_observed_at" | "valid_from" | "valid_to" | "retired">;
|
|
477
|
+
/**
|
|
478
|
+
* A candidate returned from vector search with ranking-time entry data.
|
|
479
|
+
*/
|
|
480
|
+
interface VectorCandidate {
|
|
481
|
+
entry: RecallCandidateEntry;
|
|
482
|
+
vectorSim: number;
|
|
483
|
+
}
|
|
484
|
+
/**
|
|
485
|
+
* A candidate returned from lexical FTS search with ranking-time entry data.
|
|
486
|
+
*
|
|
487
|
+
* BM25 rank controls admission order inside the lexical channel. That order
|
|
488
|
+
* is then folded into the reciprocal rank fusion pass in
|
|
489
|
+
* `src/core/recall/fusion.ts`, so the rank value itself is not part of the
|
|
490
|
+
* final composite score.
|
|
491
|
+
*/
|
|
492
|
+
interface FtsCandidate {
|
|
493
|
+
entry: RecallCandidateEntry;
|
|
494
|
+
rank: number;
|
|
495
|
+
tier: "exact" | "all_tokens" | "any_tokens";
|
|
496
|
+
}
|
|
497
|
+
/**
|
|
498
|
+
* Filters that the core recall pipeline can push down into adapter queries.
|
|
499
|
+
*/
|
|
500
|
+
interface EntryFilters {
|
|
501
|
+
types?: EntryType[];
|
|
502
|
+
tags?: string[];
|
|
503
|
+
since?: Date;
|
|
504
|
+
until?: Date;
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
/**
|
|
508
|
+
* Neighborhood expansion and seeded rerank helpers.
|
|
509
|
+
*
|
|
510
|
+
* Bounded graph-style expansion and a distance-style reranker both sit after
|
|
511
|
+
* RRF fusion. agenr does not have a graph DB, so "neighborhood" means a
|
|
512
|
+
* bounded sweep over sibling claim keys, supersession chains, procedure
|
|
513
|
+
* revisions, episode session families, and topical peers as computed from
|
|
514
|
+
* the existing relational model.
|
|
515
|
+
*
|
|
516
|
+
* The helpers in this file are deliberately pure:
|
|
517
|
+
* - `selectStrongSeeds()` picks retrieval leaders whose gap to the rest of
|
|
518
|
+
* the pack clearly earns them seed status.
|
|
519
|
+
* - `seededRerank()` applies a small positive delta to ranked candidates
|
|
520
|
+
* that share lineage with at least one strong seed, without ever lifting
|
|
521
|
+
* a candidate that has no lineage signal.
|
|
522
|
+
* - The domain-specific predicates (`sharesEntryLineage`,
|
|
523
|
+
* `sharesEpisodeLineage`, `sharesProcedureLineage`) encode what "shares
|
|
524
|
+
* lineage" means for entries, episodes, and procedures respectively.
|
|
525
|
+
*/
|
|
526
|
+
/**
|
|
527
|
+
* Discriminated neighborhood family kinds used to describe one expansion
|
|
528
|
+
* direction across the recall pipeline.
|
|
529
|
+
*
|
|
530
|
+
* - `supersession_chain` reaches along `superseded_by` pointers.
|
|
531
|
+
* - `claim_key_sibling` reaches across rows sharing one claim-key slot.
|
|
532
|
+
* - `procedure_revision` reaches across revisions of one procedure key.
|
|
533
|
+
* - `session_family` reaches across episodes originating in the same
|
|
534
|
+
* session identity (same `source` plus `sourceId`).
|
|
535
|
+
* - `topic_family` reaches across rows sharing a strong subject prefix and
|
|
536
|
+
* is the weakest, retired-only fallback for entries.
|
|
537
|
+
*/
|
|
538
|
+
type NeighborhoodFamily = "supersession_chain" | "claim_key_sibling" | "procedure_revision" | "session_family" | "topic_family";
|
|
539
|
+
/**
|
|
540
|
+
* Adapter-facing request for the bounded entry neighborhood expansion port.
|
|
541
|
+
*
|
|
542
|
+
* This is the generalized successor of the phase 1 `fetchPredecessors`
|
|
543
|
+
* lookup. The adapter should honor the requested `families` exactly and
|
|
544
|
+
* respect `includeRetired` as a hard gate so the default entry profile
|
|
545
|
+
* never pulls retired rows into the candidate pool.
|
|
546
|
+
*/
|
|
547
|
+
interface EntryNeighborhoodRequest {
|
|
548
|
+
/** Seed entry IDs to expand around. */
|
|
549
|
+
seedIds: string[];
|
|
550
|
+
/** Maximum total rows the adapter may return. */
|
|
551
|
+
budget: number;
|
|
552
|
+
/** Families the adapter should traverse. */
|
|
553
|
+
families: readonly NeighborhoodFamily[];
|
|
554
|
+
/** When true, retired rows are eligible; when false, only active rows. */
|
|
555
|
+
includeRetired?: boolean;
|
|
556
|
+
}
|
|
557
|
+
/** Default total-rows budget for one neighborhood expansion call. */
|
|
558
|
+
declare const DEFAULT_NEIGHBORHOOD_BUDGET = 24;
|
|
559
|
+
/** Default top-N size used when choosing strong rerank seeds. */
|
|
560
|
+
declare const DEFAULT_STRONG_SEED_TOP_N = 3;
|
|
561
|
+
/**
|
|
562
|
+
* Minimum score gap that separates strong seeds from the pack.
|
|
563
|
+
*
|
|
564
|
+
* Keeping the floor small but non-zero prevents flat score landscapes
|
|
565
|
+
* (common when RRF produces ties) from promoting every candidate into a
|
|
566
|
+
* seed, which would collapse seededRerank into "boost everything".
|
|
567
|
+
*/
|
|
568
|
+
declare const DEFAULT_STRONG_SEED_SCORE_GAP = 0.05;
|
|
569
|
+
/**
|
|
570
|
+
* Default positive delta applied to candidates that share lineage with a
|
|
571
|
+
* strong seed. Intentionally smaller than the existing historical lineage
|
|
572
|
+
* boosts so the stage cannot override claim-key shaping or historical
|
|
573
|
+
* trust suppression.
|
|
574
|
+
*/
|
|
575
|
+
declare const DEFAULT_SEEDED_RERANK_WEIGHT = 0.03;
|
|
576
|
+
|
|
577
|
+
/** Shared shape used by all seededRerank callers. */
|
|
578
|
+
interface SeededRerankCandidate {
|
|
579
|
+
/** Stable identifier used to detect the seed itself and skip rerank. */
|
|
580
|
+
id: string;
|
|
581
|
+
/** Current ranked score in the 0-1 range. */
|
|
582
|
+
score: number;
|
|
583
|
+
}
|
|
584
|
+
/** Tuning knobs for strong-seed selection and seededRerank. */
|
|
585
|
+
interface SeededRerankOptions {
|
|
586
|
+
/** Positive delta applied to lineage-matched candidates. */
|
|
587
|
+
weight?: number;
|
|
588
|
+
/** Top candidate count to consider as potential seeds. */
|
|
589
|
+
topN?: number;
|
|
590
|
+
/** Minimum score gap between the leader and the top-N follower. */
|
|
591
|
+
scoreGapFloor?: number;
|
|
592
|
+
}
|
|
593
|
+
/**
|
|
594
|
+
* Pick the top-ranked candidates that clearly stand apart from the pack.
|
|
595
|
+
*
|
|
596
|
+
* The score gap between the leader and the first candidate past the
|
|
597
|
+
* `topN` cutoff must exceed `scoreGapFloor` for any seeds to qualify.
|
|
598
|
+
* A flat ranking (common when every candidate earned the same RRF score)
|
|
599
|
+
* therefore produces zero seeds and leaves the rest of the pipeline alone.
|
|
600
|
+
*
|
|
601
|
+
* @param candidates - Candidates after scoring but before final shaping.
|
|
602
|
+
* @param options - Optional top-N and score-gap tuning.
|
|
603
|
+
* @returns The strong-seed subset ordered from strongest to weakest.
|
|
604
|
+
*/
|
|
605
|
+
declare function selectStrongSeeds<TCandidate extends SeededRerankCandidate>(candidates: readonly TCandidate[], options?: SeededRerankOptions): TCandidate[];
|
|
606
|
+
/**
|
|
607
|
+
* Boost ranked candidates that share lineage with at least one strong seed.
|
|
608
|
+
*
|
|
609
|
+
* - Seeds themselves are left unchanged.
|
|
610
|
+
* - Candidates without lineage evidence are left unchanged.
|
|
611
|
+
* - Matched candidates receive `weight` added to their score, clamped to
|
|
612
|
+
* the 0-1 range.
|
|
613
|
+
* - The rerank never lifts a candidate that has no lineage relationship
|
|
614
|
+
* to any seed, which is the core safety property called out in the plan.
|
|
615
|
+
*
|
|
616
|
+
* @param candidates - Ranked candidate list prior to rerank.
|
|
617
|
+
* @param seeds - Strong seeds chosen via `selectStrongSeeds`.
|
|
618
|
+
* @param sharesLineage - Domain-specific predicate returning true when the
|
|
619
|
+
* candidate shares structural or topical lineage with the supplied seed.
|
|
620
|
+
* @param options - Tuning knobs (weight only has an effect here).
|
|
621
|
+
* @returns Candidates with any lineage-boosted scores applied.
|
|
622
|
+
*/
|
|
623
|
+
declare function seededRerank<TCandidate extends SeededRerankCandidate>(candidates: readonly TCandidate[], seeds: readonly TCandidate[], sharesLineage: (candidate: TCandidate, seed: TCandidate) => boolean, options?: SeededRerankOptions): {
|
|
624
|
+
candidates: TCandidate[];
|
|
625
|
+
boostedIds: string[];
|
|
626
|
+
};
|
|
627
|
+
/**
|
|
628
|
+
* Decide whether two entry candidates share lineage for rerank purposes.
|
|
629
|
+
*
|
|
630
|
+
* Three relationships qualify as lineage:
|
|
631
|
+
* - Same `claim_key` (same slot in the claim-key model).
|
|
632
|
+
* - Direct `superseded_by` link in either direction.
|
|
633
|
+
* - Shared subject prefix wide enough to count as the same topic.
|
|
634
|
+
*
|
|
635
|
+
* @param candidate - Candidate entry under evaluation.
|
|
636
|
+
* @param seed - Strong-seed entry the candidate is being compared to.
|
|
637
|
+
* @returns True when the two entries share lineage, false otherwise.
|
|
638
|
+
*/
|
|
639
|
+
declare function sharesEntryLineage(candidate: RecallCandidateEntry, seed: RecallCandidateEntry): boolean;
|
|
640
|
+
/**
|
|
641
|
+
* Decide whether two episodes belong to the same session family.
|
|
642
|
+
*
|
|
643
|
+
* - Same `source` plus `sourceId` is the strongest signal; it identifies
|
|
644
|
+
* the same originating session across storage and rehydration paths.
|
|
645
|
+
* - A shared `transcriptHash` is the fallback when one side lacks a
|
|
646
|
+
* persisted `sourceId`, since episodes that land on the same transcript
|
|
647
|
+
* are structurally the same session even after re-ingest.
|
|
648
|
+
*
|
|
649
|
+
* @param candidate - Candidate episode under evaluation.
|
|
650
|
+
* @param seed - Strong-seed episode the candidate is being compared to.
|
|
651
|
+
* @returns True when the episodes share session lineage.
|
|
652
|
+
*/
|
|
653
|
+
declare function sharesEpisodeLineage(candidate: Episode, seed: Episode): boolean;
|
|
654
|
+
/**
|
|
655
|
+
* Decide whether two procedures share the same procedure-key revision chain.
|
|
656
|
+
*
|
|
657
|
+
* @param candidate - Candidate procedure under evaluation.
|
|
658
|
+
* @param seed - Strong-seed procedure the candidate is being compared to.
|
|
659
|
+
* @returns True when both rows share one stable procedure key.
|
|
660
|
+
*/
|
|
661
|
+
declare function sharesProcedureLineage(candidate: Procedure, seed: Procedure): boolean;
|
|
662
|
+
|
|
663
|
+
/**
|
|
664
|
+
* Storage contract for persisting, updating, and querying knowledge entries.
|
|
665
|
+
*/
|
|
666
|
+
interface DatabasePort {
|
|
667
|
+
/** Insert a new entry with its embedding. */
|
|
668
|
+
insertEntry(entry: Entry, embedding: number[], contentHash: string): Promise<string>;
|
|
669
|
+
/** Drop expensive indexes and triggers before a bulk write phase begins. */
|
|
670
|
+
prepareForBulkWrites(): Promise<void>;
|
|
671
|
+
/** Rebuild expensive indexes and triggers after a bulk write phase ends. */
|
|
672
|
+
finalizeBulkWrites(): Promise<void>;
|
|
673
|
+
/** Get entries by IDs. */
|
|
674
|
+
getEntries(ids: string[]): Promise<Entry[]>;
|
|
675
|
+
/** Get a single entry by ID. */
|
|
676
|
+
getEntry(id: string): Promise<Entry | null>;
|
|
677
|
+
/** Check if content hashes already exist. Returns the set of existing hashes. */
|
|
678
|
+
findExistingHashes(hashes: string[]): Promise<Set<string>>;
|
|
679
|
+
/** Check if normalized content hashes already exist. Returns the set of existing hashes. */
|
|
680
|
+
findExistingNormHashes(hashes: string[]): Promise<Set<string>>;
|
|
681
|
+
/** Mark an entry as retired. */
|
|
682
|
+
retireEntry(id: string, reason?: string): Promise<boolean>;
|
|
683
|
+
/** Supersede an active entry, linking it to the new entry that replaces it. */
|
|
684
|
+
supersedeEntry(oldId: string, newId: string, kind?: string, reason?: string): Promise<boolean>;
|
|
685
|
+
/** Find active entries with the given claim key. */
|
|
686
|
+
findActiveEntriesByClaimKey(claimKey: string): Promise<Entry[]>;
|
|
687
|
+
/** Get distinct entity prefixes from existing claim keys. */
|
|
688
|
+
getDistinctClaimKeyPrefixes(): Promise<string[]>;
|
|
689
|
+
/** Get bounded full claim-key examples ordered for extraction hinting. */
|
|
690
|
+
getClaimKeyExamples?(limit?: number): Promise<string[]>;
|
|
691
|
+
/** Get active per-prefix claim-key counts for conservative alias-family handling. */
|
|
692
|
+
getClaimKeyEntityPrefixStats?(): Promise<ClaimKeyEntityPrefixStats[]>;
|
|
693
|
+
/** Update entry fields (importance, expiry, and temporal metadata). */
|
|
694
|
+
updateEntry(id: string, fields: EntryUpdateInput): Promise<boolean>;
|
|
695
|
+
/** Check if a file has been ingested (by path + hash). */
|
|
696
|
+
getIngestLogEntry(filePath: string): Promise<{
|
|
697
|
+
fileHash: string;
|
|
698
|
+
ingestedAt: string;
|
|
699
|
+
} | null>;
|
|
700
|
+
/** Record that a file was ingested. */
|
|
701
|
+
insertIngestLogEntry(filePath: string, fileHash: string, entryCount: number): Promise<void>;
|
|
702
|
+
/** Initialize the database schema. */
|
|
703
|
+
init(): Promise<void>;
|
|
704
|
+
/** Close the database connection. */
|
|
705
|
+
close(): Promise<void>;
|
|
706
|
+
}
|
|
707
|
+
/**
|
|
708
|
+
* Storage contract for persisting and querying episodic memory records.
|
|
709
|
+
*/
|
|
710
|
+
interface EpisodeDatabasePort {
|
|
711
|
+
/** Get one episode by its stable `(source, sourceId)` identity. */
|
|
712
|
+
getEpisodeBySourceId(source: EpisodeSource, sourceId: string): Promise<Episode | null>;
|
|
713
|
+
/** Get one episode by fallback `(source, transcriptHash)` identity. */
|
|
714
|
+
getEpisodeByTranscriptHash(source: EpisodeSource, transcriptHash: string): Promise<Episode | null>;
|
|
715
|
+
/** Insert or update an episode using `summaryHash` change detection. */
|
|
716
|
+
upsertEpisode(input: EpisodeInput): Promise<EpisodeUpsertResult>;
|
|
717
|
+
/** List non-retired episodes whose time range overlaps the requested window. */
|
|
718
|
+
listEpisodesByTimeWindow(window: TemporalWindow, limit?: number): Promise<Episode[]>;
|
|
719
|
+
/** Find episodes by vector similarity to a query embedding. */
|
|
720
|
+
episodeVectorSearch(params: {
|
|
721
|
+
embedding: number[];
|
|
722
|
+
limit: number;
|
|
723
|
+
}): Promise<Array<{
|
|
724
|
+
episode: Episode;
|
|
725
|
+
vectorSim: number;
|
|
726
|
+
}>>;
|
|
727
|
+
/** List non-retired episodes that still need embeddings. */
|
|
728
|
+
listEpisodesWithoutEmbeddings(limit?: number): Promise<Episode[]>;
|
|
729
|
+
/** Update only the embedding payload for an existing episode row. */
|
|
730
|
+
updateEpisodeEmbedding(id: string, embedding: number[]): Promise<void>;
|
|
731
|
+
}
|
|
732
|
+
/**
|
|
733
|
+
* Storage contract for persisting and querying procedural-memory revisions.
|
|
734
|
+
*/
|
|
735
|
+
interface ProcedureDatabasePort {
|
|
736
|
+
/** Insert or update one procedure revision row. */
|
|
737
|
+
upsertProcedure(procedure: Procedure): Promise<Procedure>;
|
|
738
|
+
/** Get one active procedure by primary key. */
|
|
739
|
+
getProcedure(id: string): Promise<Procedure | null>;
|
|
740
|
+
/** Hydrate active procedures by ID while preserving caller order. */
|
|
741
|
+
hydrateProcedures(ids: string[]): Promise<Procedure[]>;
|
|
742
|
+
/** Get the currently active procedure revision for one stable key. */
|
|
743
|
+
findActiveProcedureByKey(procedureKey: string): Promise<Procedure | null>;
|
|
744
|
+
/** Find procedures by vector similarity to a query embedding. */
|
|
745
|
+
procedureVectorSearch(params: {
|
|
746
|
+
embedding: number[];
|
|
747
|
+
limit: number;
|
|
748
|
+
}): Promise<Array<{
|
|
749
|
+
procedure: Procedure;
|
|
750
|
+
vectorSim: number;
|
|
751
|
+
}>>;
|
|
752
|
+
/** Find procedures by lexical search over the procedure FTS index. */
|
|
753
|
+
procedureFtsSearch(params: {
|
|
754
|
+
text: string;
|
|
755
|
+
limit: number;
|
|
756
|
+
}): Promise<Array<{
|
|
757
|
+
procedure: Procedure;
|
|
758
|
+
rank: number;
|
|
759
|
+
}>>;
|
|
760
|
+
/** List active procedures that still need embeddings. */
|
|
761
|
+
listProceduresWithoutEmbeddings(limit?: number): Promise<Procedure[]>;
|
|
762
|
+
/** Update only the embedding payload for an existing procedure row. */
|
|
763
|
+
updateProcedureEmbedding(id: string, embedding: number[]): Promise<void>;
|
|
764
|
+
/** Mark one active procedure revision as retired. */
|
|
765
|
+
retireProcedure(id: string, reason?: string): Promise<boolean>;
|
|
766
|
+
/** Supersede one active procedure revision with a new revision. */
|
|
767
|
+
supersedeProcedure(oldId: string, newId: string, reason?: string): Promise<boolean>;
|
|
768
|
+
}
|
|
769
|
+
/**
|
|
770
|
+
* Embedding provider contract used by core ranking and storage flows.
|
|
771
|
+
*/
|
|
772
|
+
interface EmbeddingPort {
|
|
773
|
+
/** Compute embeddings for one or more texts. */
|
|
774
|
+
embed(texts: string[]): Promise<number[][]>;
|
|
775
|
+
}
|
|
776
|
+
/**
|
|
777
|
+
* Query-time retrieval contract used by the v1 recall pipeline.
|
|
778
|
+
*/
|
|
779
|
+
interface RecallPorts {
|
|
780
|
+
/** Compute a single embedding for a recall query string. */
|
|
781
|
+
embed(text: string): Promise<number[]>;
|
|
782
|
+
/** Search vector candidates with adapter-level filtering applied. */
|
|
783
|
+
vectorSearch(params: {
|
|
784
|
+
embedding: number[];
|
|
785
|
+
limit: number;
|
|
786
|
+
filters?: EntryFilters;
|
|
787
|
+
}): Promise<VectorCandidate[]>;
|
|
788
|
+
/** Search FTS candidates with adapter-level filtering applied. */
|
|
789
|
+
ftsSearch(params: {
|
|
790
|
+
text: string;
|
|
791
|
+
limit: number;
|
|
792
|
+
filters?: EntryFilters;
|
|
793
|
+
}): Promise<FtsCandidate[]>;
|
|
794
|
+
/**
|
|
795
|
+
* Expand a typed neighborhood of entries around the provided seed IDs.
|
|
796
|
+
*
|
|
797
|
+
* The adapter honors `families` exactly and treats `includeRetired` as a
|
|
798
|
+
* hard gate. This is the generalized successor of the phase 1
|
|
799
|
+
* `fetchPredecessors` lookup and is used by every entry ranking profile.
|
|
800
|
+
* The default profile passes `includeRetired: false`; historical-state
|
|
801
|
+
* passes `includeRetired: true` with a wider family set.
|
|
802
|
+
*/
|
|
803
|
+
expandNeighborhood?(request: EntryNeighborhoodRequest): Promise<RecallCandidateEntry[]>;
|
|
804
|
+
/** Hydrate fully populated entries for the final ranked result set. */
|
|
805
|
+
hydrateEntries(ids: string[]): Promise<Entry[]>;
|
|
806
|
+
/** Persist recall events for the returned entry set. */
|
|
807
|
+
recordRecallEvents(params: {
|
|
808
|
+
entryIds: string[];
|
|
809
|
+
query: string;
|
|
810
|
+
sessionKey?: string;
|
|
811
|
+
}): Promise<void>;
|
|
812
|
+
/**
|
|
813
|
+
* Optional cross-encoder rerank port. When present, recall calls the
|
|
814
|
+
* port for the top-K shortlist after MMR diversification and before
|
|
815
|
+
* thresholding. The recall pipeline fails closed on adapter errors so
|
|
816
|
+
* the cross-encoder can never drop recall below its pre-rerank
|
|
817
|
+
* baseline.
|
|
818
|
+
*/
|
|
819
|
+
crossEncoder?: CrossEncoderPort;
|
|
820
|
+
}
|
|
821
|
+
/**
|
|
822
|
+
* LLM provider contract for free-form and structured completions.
|
|
823
|
+
*/
|
|
824
|
+
interface LlmPort {
|
|
825
|
+
/** Generate a completion from a system prompt and user message. */
|
|
826
|
+
complete(systemPrompt: string, userMessage: string): Promise<string>;
|
|
827
|
+
/** Generate a structured completion (JSON output). */
|
|
828
|
+
completeJson<T>(systemPrompt: string, userMessage: string): Promise<T>;
|
|
829
|
+
}
|
|
830
|
+
/**
|
|
831
|
+
* One passage handed to the cross-encoder for relevance scoring.
|
|
832
|
+
*/
|
|
833
|
+
interface CrossEncoderPassage {
|
|
834
|
+
/** Stable identifier used to correlate scores back to the caller. */
|
|
835
|
+
id: string;
|
|
836
|
+
/** Free-form text representation of the passage. */
|
|
837
|
+
text: string;
|
|
838
|
+
}
|
|
839
|
+
/**
|
|
840
|
+
* One scored passage returned by a cross-encoder ranker.
|
|
841
|
+
*/
|
|
842
|
+
interface CrossEncoderScore {
|
|
843
|
+
/** Stable identifier matching the input passage. */
|
|
844
|
+
id: string;
|
|
845
|
+
/** Relevance score in the inclusive 0-1 range. */
|
|
846
|
+
score: number;
|
|
847
|
+
}
|
|
848
|
+
/**
|
|
849
|
+
* Cross-encoder contract used by the recall pipeline to rerank a small
|
|
850
|
+
* top-K shortlist. Implementations must be safe to call concurrently and
|
|
851
|
+
* should bound provider concurrency internally so recall latency does
|
|
852
|
+
* not spiral under load.
|
|
853
|
+
*
|
|
854
|
+
* Identifiers are passed through explicitly so core recall never has to
|
|
855
|
+
* correlate by list position.
|
|
856
|
+
*/
|
|
857
|
+
interface CrossEncoderPort {
|
|
858
|
+
/**
|
|
859
|
+
* Score each passage against the query.
|
|
860
|
+
*
|
|
861
|
+
* @param query - Natural-language recall query.
|
|
862
|
+
* @param passages - Passages ordered in their caller-preferred order.
|
|
863
|
+
* @returns Each passage's relevance score keyed by passage ID.
|
|
864
|
+
*/
|
|
865
|
+
rank(query: string, passages: readonly CrossEncoderPassage[]): Promise<CrossEncoderScore[]>;
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
/**
|
|
869
|
+
* Runtime slot-policy classes used by claim-centric read surfaces.
|
|
870
|
+
*/
|
|
871
|
+
type ClaimSlotPolicy = "exclusive" | "multivalued";
|
|
872
|
+
/**
|
|
873
|
+
* Data-driven slot-policy overrides keyed by canonical claim-key attribute head.
|
|
874
|
+
*/
|
|
875
|
+
interface ClaimSlotPolicyConfig {
|
|
876
|
+
/** Optional attribute-head policy overrides such as `integration -> exclusive`. */
|
|
877
|
+
attributeHeads?: Readonly<Record<string, ClaimSlotPolicy>>;
|
|
878
|
+
}
|
|
879
|
+
|
|
880
|
+
export { type ClaimSlotPolicyConfig as C, DEFAULT_NEIGHBORHOOD_BUDGET as D, type EntryType as E, type FtsCandidate as F, type LlmPort as L, type NeighborhoodFamily as N, type ProcedureDatabasePort as P, type RecallInput as R, type SeededRerankCandidate as S, type VectorCandidate as V, type CrossEncoderPort as a, type Expiry as b, type RecallPorts as c, type RecallOutput as d, DEFAULT_SEEDED_RERANK_WEIGHT as e, DEFAULT_STRONG_SEED_SCORE_GAP as f, DEFAULT_STRONG_SEED_TOP_N as g, type EntityAttributeKind as h, type EntityAttributeQueryShape as i, type EntryFilters as j, type EntryNeighborhoodRequest as k, type RecallCandidateEntry as l, type RecallRankingProfile as m, type SeededRerankOptions as n, selectStrongSeeds as o, sharesEntryLineage as p, sharesEpisodeLineage as q, sharesProcedureLineage as r, seededRerank as s, type Entry as t, type ClaimSlotPolicy as u, type DatabasePort as v, type EpisodeDatabasePort as w, type EmbeddingPort as x };
|