agenr 2.0.1 → 3.0.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/CHANGELOG.md +64 -0
- package/dist/adapters/openclaw/index.d.ts +1 -1
- package/dist/adapters/openclaw/index.js +994 -1420
- package/dist/adapters/skeln/index.d.ts +1951 -0
- package/dist/adapters/skeln/index.js +3899 -0
- package/dist/chunk-575MUIW5.js +1039 -0
- package/dist/{chunk-MEHOGUZE.js → chunk-5LADPJ4C.js} +989 -70
- package/dist/{chunk-Y2BC7RCE.js → chunk-ELR2HSVC.js} +6008 -4618
- package/dist/chunk-GELCEVFA.js +14 -0
- package/dist/{chunk-XD3446YW.js → chunk-LAXNNWHM.js} +3397 -4527
- package/dist/chunk-MYZ2CWY6.js +2738 -0
- package/dist/chunk-P5SB75FK.js +3061 -0
- package/dist/chunk-TBFAARM5.js +1196 -0
- package/dist/claim-slot-policy-CdrW_1l4.d.ts +13 -0
- package/dist/cli.js +292 -613
- package/dist/core/recall/index.d.ts +538 -119
- package/dist/core/recall/index.js +37 -3
- package/dist/internal-eval-server.d.ts +1 -0
- package/dist/internal-eval-server.js +7 -0
- package/dist/internal-recall-eval-server.js +6 -1816
- package/dist/ports-CpzWESmZ.d.ts +925 -0
- package/package.json +9 -6
- package/dist/ports-D2NOK2gR.d.ts +0 -256
|
@@ -0,0 +1,1951 @@
|
|
|
1
|
+
import { ExtensionContext, ExtensionAPI } from 'skeln';
|
|
2
|
+
import { C as ClaimSlotPolicyConfig, a as ClaimSlotPolicy } from '../../claim-slot-policy-CdrW_1l4.js';
|
|
3
|
+
import { E as EntryType, b as RecallPorts, r as ProcedureDatabasePort, t as Entry, u as DatabasePort, v as EpisodeDatabasePort, w as EmbeddingPort, L as LlmPort } from '../../ports-CpzWESmZ.js';
|
|
4
|
+
import { AgentMessage } from '@earendil-works/pi-agent-core';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Canonical feature flags for staged working-memory, session-memory, and goal rollout.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Feature-flag keys supported across agenr config and app services.
|
|
11
|
+
*/
|
|
12
|
+
declare const AGENR_FEATURE_FLAG_KEYS: readonly ["workingMemory", "sessionTreeLineage", "sessionTreeCompaction", "goalContinuation"];
|
|
13
|
+
/**
|
|
14
|
+
* Union of feature-flag keys supported by agenr config.
|
|
15
|
+
*/
|
|
16
|
+
type AgenrFeatureFlagKey = (typeof AGENR_FEATURE_FLAG_KEYS)[number];
|
|
17
|
+
/**
|
|
18
|
+
* Sparse persisted feature-flag overrides.
|
|
19
|
+
*
|
|
20
|
+
* Only `true` values are written to disk. Explicit `false` is accepted during
|
|
21
|
+
* parse and reflected in resolved runtime flags, but canonicalization strips
|
|
22
|
+
* false entries because every flag defaults to off.
|
|
23
|
+
*/
|
|
24
|
+
type AgenrFeatureFlagConfig = Partial<Record<AgenrFeatureFlagKey, boolean>>;
|
|
25
|
+
/**
|
|
26
|
+
* Fully resolved runtime feature flags.
|
|
27
|
+
*/
|
|
28
|
+
type AgenrFeatureFlags = Record<AgenrFeatureFlagKey, boolean>;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Runtime configuration for optional claim-key extraction.
|
|
32
|
+
*/
|
|
33
|
+
interface ClaimExtractionConfig {
|
|
34
|
+
enabled: boolean;
|
|
35
|
+
confidenceThreshold: number;
|
|
36
|
+
eligibleTypes: EntryType[];
|
|
37
|
+
/** Maximum preview workers used by cleanup flows that parallelize claim extraction. Defaults to `10`. */
|
|
38
|
+
concurrency?: number;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Dependencies needed by the app-layer before-turn service.
|
|
43
|
+
*/
|
|
44
|
+
interface BeforeTurnDeps {
|
|
45
|
+
/** Shared durable recall ports reused for turn-time memory selection. */
|
|
46
|
+
recall: RecallPorts;
|
|
47
|
+
/** Dedicated procedure database port used for proactive procedure selection. */
|
|
48
|
+
procedures: ProcedureDatabasePort;
|
|
49
|
+
/** Optional semantic embedding helper reused by dedicated procedure recall. */
|
|
50
|
+
embedQuery?: (text: string) => Promise<number[]>;
|
|
51
|
+
/** Optional runtime claim-slot-policy overrides used during claim-aware shaping. */
|
|
52
|
+
slotPolicyConfig?: ClaimSlotPolicyConfig;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Recent recall event metadata returned by memory trace surfaces.
|
|
57
|
+
*/
|
|
58
|
+
interface EntryRecallEvent {
|
|
59
|
+
query?: string;
|
|
60
|
+
sessionKey?: string;
|
|
61
|
+
recalledAt: string;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Narrow claim-family lineage view returned by trace surfaces.
|
|
65
|
+
*/
|
|
66
|
+
interface ClaimFamily {
|
|
67
|
+
/** Shared claim key for the family. */
|
|
68
|
+
claimKey: string;
|
|
69
|
+
/** Runtime slot-policy used when reading this lineage. */
|
|
70
|
+
slotPolicy: ClaimSlotPolicy;
|
|
71
|
+
/** Human-readable explanation of how the slot policy was chosen. */
|
|
72
|
+
slotPolicyReason?: string;
|
|
73
|
+
/** Family rows ordered oldest-first for lineage inspection. */
|
|
74
|
+
entries: Entry[];
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Minimal provenance view available from the current v1 schema.
|
|
78
|
+
*/
|
|
79
|
+
interface EntryTrace {
|
|
80
|
+
entry: Entry;
|
|
81
|
+
supersededBy?: Entry;
|
|
82
|
+
supersedes: Entry[];
|
|
83
|
+
claimFamily?: ClaimFamily;
|
|
84
|
+
recallEvents: EntryRecallEvent[];
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Aggregate memory status facts used by host memory runtimes.
|
|
88
|
+
*/
|
|
89
|
+
interface MemoryStatusSnapshot {
|
|
90
|
+
activeEntries: number;
|
|
91
|
+
coreEntries: number;
|
|
92
|
+
sourceFiles: number;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Host-neutral memory read model used by prompt injection, trace, and status flows.
|
|
96
|
+
*/
|
|
97
|
+
interface MemoryRepository {
|
|
98
|
+
/**
|
|
99
|
+
* Finds the most recent entry matching a subject string.
|
|
100
|
+
*
|
|
101
|
+
* @param subject - Free-form subject text to resolve.
|
|
102
|
+
* @returns Matching entry, or `null` when no match exists.
|
|
103
|
+
*/
|
|
104
|
+
findEntryBySubject(subject: string): Promise<Entry | null>;
|
|
105
|
+
/**
|
|
106
|
+
* Finds the most recently created entry from any state.
|
|
107
|
+
*
|
|
108
|
+
* @returns Newest entry, or `null` when none exist.
|
|
109
|
+
*/
|
|
110
|
+
findMostRecentEntry(): Promise<Entry | null>;
|
|
111
|
+
/**
|
|
112
|
+
* Loads the current trace view for one entry.
|
|
113
|
+
*
|
|
114
|
+
* @param entryId - Entry identifier to inspect.
|
|
115
|
+
* @returns Trace payload, or `null` when the entry is missing.
|
|
116
|
+
*/
|
|
117
|
+
getEntryTrace(entryId: string): Promise<EntryTrace | null>;
|
|
118
|
+
/**
|
|
119
|
+
* Reads aggregate counts for host status surfaces.
|
|
120
|
+
*
|
|
121
|
+
* @returns Current memory status snapshot.
|
|
122
|
+
*/
|
|
123
|
+
getMemoryStatusSnapshot(): Promise<MemoryStatusSnapshot>;
|
|
124
|
+
/**
|
|
125
|
+
* Checks whether the configured vector index is available.
|
|
126
|
+
*
|
|
127
|
+
* @returns `true` when vector search is usable.
|
|
128
|
+
*/
|
|
129
|
+
probeVectorAvailability(): Promise<boolean>;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* One next action in a working snapshot.
|
|
134
|
+
*/
|
|
135
|
+
interface WorkingNextAction {
|
|
136
|
+
/** Human-readable action text. */
|
|
137
|
+
text: string;
|
|
138
|
+
/** Current action status. */
|
|
139
|
+
status?: "pending" | "in_progress" | "blocked" | "done";
|
|
140
|
+
/** Optional reference to a file, issue, or event. */
|
|
141
|
+
ref?: string;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Checkpoint payload used before handoff, compaction, fork, or shutdown.
|
|
145
|
+
*/
|
|
146
|
+
interface WorkingCheckpoint {
|
|
147
|
+
/** Compact summary of current progress. */
|
|
148
|
+
summary: string;
|
|
149
|
+
/** ISO timestamp when the checkpoint was recorded. */
|
|
150
|
+
recordedAt: string;
|
|
151
|
+
/** Expected next actions after the checkpoint. */
|
|
152
|
+
nextActions?: string[];
|
|
153
|
+
/** Known blockers at checkpoint time. */
|
|
154
|
+
blockers?: string[];
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* File observation attached to a working set.
|
|
158
|
+
*/
|
|
159
|
+
interface WorkingFileNote {
|
|
160
|
+
/** File path as observed by the host or model. */
|
|
161
|
+
path: string;
|
|
162
|
+
/** Optional note about why the file matters. */
|
|
163
|
+
note?: string;
|
|
164
|
+
/** ISO timestamp when the observation was made. */
|
|
165
|
+
observedAt?: string;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Command observation attached to a working set.
|
|
169
|
+
*/
|
|
170
|
+
interface WorkingCommandNote {
|
|
171
|
+
/** Command text. */
|
|
172
|
+
command: string;
|
|
173
|
+
/** Compact observed outcome. */
|
|
174
|
+
outcome?: string;
|
|
175
|
+
/** ISO timestamp when the command was observed. */
|
|
176
|
+
observedAt?: string;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Decision note attached to a working set.
|
|
180
|
+
*/
|
|
181
|
+
interface WorkingDecisionNote {
|
|
182
|
+
/** Decision text. */
|
|
183
|
+
decision: string;
|
|
184
|
+
/** Optional rationale. */
|
|
185
|
+
rationale?: string;
|
|
186
|
+
/** ISO timestamp when the decision was made. */
|
|
187
|
+
decidedAt?: string;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Assumption note attached to a working set.
|
|
191
|
+
*/
|
|
192
|
+
interface WorkingAssumptionNote {
|
|
193
|
+
/** Assumption text. */
|
|
194
|
+
assumption: string;
|
|
195
|
+
/** Confidence in the assumption. */
|
|
196
|
+
confidence?: "low" | "medium" | "high";
|
|
197
|
+
/** Whether the assumption has been validated. */
|
|
198
|
+
validated?: boolean;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* External reference attached to a working set.
|
|
202
|
+
*/
|
|
203
|
+
interface WorkingReference {
|
|
204
|
+
/** Display label for the reference. */
|
|
205
|
+
label: string;
|
|
206
|
+
/** Optional URI or stable identifier. */
|
|
207
|
+
uri?: string;
|
|
208
|
+
/** Reference kind. */
|
|
209
|
+
kind?: "doc" | "issue" | "pr" | "url" | "entry" | "episode";
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Continuation state stored for future host-side schedulers.
|
|
213
|
+
*/
|
|
214
|
+
interface WorkingContinuationState {
|
|
215
|
+
/** Host continuation policy. */
|
|
216
|
+
policy?: WorkingContinuationPolicy;
|
|
217
|
+
/** ISO timestamp after which the host may resume. */
|
|
218
|
+
resumeAfter?: string;
|
|
219
|
+
/** ISO timestamp after which context should be treated as stale. */
|
|
220
|
+
staleAfter?: string;
|
|
221
|
+
/** Reason continuation is currently stopped. */
|
|
222
|
+
stopReason?: string;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Budget state stored for future host-side schedulers.
|
|
226
|
+
*/
|
|
227
|
+
interface WorkingBudgetState {
|
|
228
|
+
/** Token budget assigned by the host. */
|
|
229
|
+
tokenBudget?: number;
|
|
230
|
+
/** Tokens used so far according to the host. */
|
|
231
|
+
tokenUsed?: number;
|
|
232
|
+
/** Wall-clock budget in seconds. */
|
|
233
|
+
wallClockBudgetSeconds?: number;
|
|
234
|
+
/** Wall-clock seconds used so far according to the host. */
|
|
235
|
+
wallClockUsedSeconds?: number;
|
|
236
|
+
/** Maximum continuation turns allowed by the host. */
|
|
237
|
+
turnBudget?: number;
|
|
238
|
+
/** Continuation turns used so far according to the host. */
|
|
239
|
+
turnsUsed?: number;
|
|
240
|
+
/** Review interval in seconds before the host should pause for user review. */
|
|
241
|
+
requireReviewAfterSeconds?: number;
|
|
242
|
+
/** ISO timestamp when review becomes due. */
|
|
243
|
+
reviewDueAt?: string;
|
|
244
|
+
/** Budget dimension that most recently limited continuation. */
|
|
245
|
+
limitReason?: WorkingBudgetLimitReason;
|
|
246
|
+
/** ISO timestamp when a budget limit was reached. */
|
|
247
|
+
limitedAt?: string;
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Delta supplied by host accounting hooks after a goal turn or tool result.
|
|
251
|
+
*/
|
|
252
|
+
interface WorkingUsageDelta {
|
|
253
|
+
/** Additional tokens consumed since the last accounting write. */
|
|
254
|
+
tokenDelta?: number;
|
|
255
|
+
/** Additional wall-clock seconds consumed since the last accounting write. */
|
|
256
|
+
wallClockSecondsDelta?: number;
|
|
257
|
+
/** Additional continuation turns consumed since the last accounting write. */
|
|
258
|
+
turnDelta?: number;
|
|
259
|
+
/** ISO timestamp when the host recorded this accounting update. */
|
|
260
|
+
recordedAt?: string;
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Provenance for a memory candidate derived from working events.
|
|
264
|
+
*/
|
|
265
|
+
interface CandidateProvenance {
|
|
266
|
+
/** Working-event sequence numbers that support the candidate. */
|
|
267
|
+
evidenceEventSequences: number[];
|
|
268
|
+
/** Optional compact source reference. */
|
|
269
|
+
sourceRef?: string;
|
|
270
|
+
/** Optional reviewer note. */
|
|
271
|
+
note?: string;
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Episode candidate emitted by close or consolidation.
|
|
275
|
+
*/
|
|
276
|
+
interface WorkingEpisodicCandidate {
|
|
277
|
+
/** Candidate discriminator. */
|
|
278
|
+
kind: "episodic";
|
|
279
|
+
/** Candidate episode summary. */
|
|
280
|
+
summary: string;
|
|
281
|
+
/** Event-level provenance for the candidate. */
|
|
282
|
+
provenance: CandidateProvenance;
|
|
283
|
+
/** Promotion lifecycle state. */
|
|
284
|
+
promotionStatus: WorkingCandidatePromotionStatus;
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Semantic or procedural candidate emitted by close or consolidation.
|
|
288
|
+
*/
|
|
289
|
+
interface WorkingDurableCandidate {
|
|
290
|
+
/** Candidate discriminator. */
|
|
291
|
+
kind: "semantic" | "procedural";
|
|
292
|
+
/** Suggested durable subject or procedure name. */
|
|
293
|
+
subject: string;
|
|
294
|
+
/** Suggested durable content. */
|
|
295
|
+
content: string;
|
|
296
|
+
/** Optional suggested claim key for semantic promotion. */
|
|
297
|
+
suggestedClaimKey?: string;
|
|
298
|
+
/** Event-level provenance for the candidate. */
|
|
299
|
+
provenance: CandidateProvenance;
|
|
300
|
+
/** Promotion lifecycle state. */
|
|
301
|
+
promotionStatus: WorkingCandidatePromotionStatus;
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Candidate emitted from a working set for later review.
|
|
305
|
+
*/
|
|
306
|
+
type WorkingCandidate = WorkingEpisodicCandidate | WorkingDurableCandidate;
|
|
307
|
+
/**
|
|
308
|
+
* Snapshot JSON stored for the active task state.
|
|
309
|
+
*
|
|
310
|
+
* This is the authoritative task-state payload. Row-level indexes may mirror
|
|
311
|
+
* scope facts, but task content lives here only.
|
|
312
|
+
*/
|
|
313
|
+
interface WorkingSnapshot {
|
|
314
|
+
/** Monotonic goal identity generation; assigned on create and bumps on objective replace. */
|
|
315
|
+
goalGeneration?: number;
|
|
316
|
+
/** Current task objective. */
|
|
317
|
+
objective?: string;
|
|
318
|
+
/** Success criteria for the task. */
|
|
319
|
+
successCriteria?: string[];
|
|
320
|
+
/** Compact task-state summary. */
|
|
321
|
+
summary?: string;
|
|
322
|
+
/** Current ordered plan steps. */
|
|
323
|
+
currentPlan?: string[];
|
|
324
|
+
/** Next actions the agent or user expects. */
|
|
325
|
+
nextActions?: WorkingNextAction[];
|
|
326
|
+
/** Completed task steps. */
|
|
327
|
+
completedSteps?: string[];
|
|
328
|
+
/** Latest checkpoint for handoff or lifecycle transitions. */
|
|
329
|
+
checkpoint?: WorkingCheckpoint;
|
|
330
|
+
/** File observations relevant to the active task. */
|
|
331
|
+
files?: WorkingFileNote[];
|
|
332
|
+
/** Command observations relevant to the active task. */
|
|
333
|
+
commands?: WorkingCommandNote[];
|
|
334
|
+
/** Decisions made during the active task. */
|
|
335
|
+
decisions?: WorkingDecisionNote[];
|
|
336
|
+
/** Assumptions that may need validation. */
|
|
337
|
+
assumptions?: WorkingAssumptionNote[];
|
|
338
|
+
/** Open questions that block or shape the task. */
|
|
339
|
+
openQuestions?: string[];
|
|
340
|
+
/** Current blockers. */
|
|
341
|
+
blockers?: string[];
|
|
342
|
+
/** External references used by the task. */
|
|
343
|
+
references?: WorkingReference[];
|
|
344
|
+
/** Candidate memories emitted from the working set. */
|
|
345
|
+
candidates?: WorkingCandidate[];
|
|
346
|
+
/** Continuation state stored for the host scheduler. */
|
|
347
|
+
continuation?: WorkingContinuationState;
|
|
348
|
+
/** Budget state stored for the host scheduler. */
|
|
349
|
+
budgets?: WorkingBudgetState;
|
|
350
|
+
/** ISO timestamp or short reason for the last material change. */
|
|
351
|
+
lastMaterialChange?: string;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* Typed mutation operations accepted by the normal working-memory tool path.
|
|
356
|
+
*/
|
|
357
|
+
type AgenrWorkUpdateOperation = {
|
|
358
|
+
type: "set_objective";
|
|
359
|
+
objective: string;
|
|
360
|
+
title?: string;
|
|
361
|
+
} | {
|
|
362
|
+
type: "replace_plan";
|
|
363
|
+
currentPlan: string[];
|
|
364
|
+
nextActions?: WorkingNextAction[];
|
|
365
|
+
} | {
|
|
366
|
+
type: "merge_checkpoint";
|
|
367
|
+
checkpoint: WorkingCheckpoint;
|
|
368
|
+
} | {
|
|
369
|
+
type: "add_file_note";
|
|
370
|
+
file: WorkingFileNote;
|
|
371
|
+
} | {
|
|
372
|
+
type: "add_command_note";
|
|
373
|
+
command: WorkingCommandNote;
|
|
374
|
+
} | {
|
|
375
|
+
type: "record_decision";
|
|
376
|
+
decision: WorkingDecisionNote;
|
|
377
|
+
} | {
|
|
378
|
+
type: "record_assumption";
|
|
379
|
+
assumption: WorkingAssumptionNote;
|
|
380
|
+
} | {
|
|
381
|
+
type: "set_next_actions";
|
|
382
|
+
nextActions: WorkingNextAction[];
|
|
383
|
+
} | {
|
|
384
|
+
type: "set_status";
|
|
385
|
+
status: WorkingSetStatus;
|
|
386
|
+
} | {
|
|
387
|
+
type: "add_candidate";
|
|
388
|
+
candidate: WorkingCandidate;
|
|
389
|
+
} | {
|
|
390
|
+
type: "configure_budget";
|
|
391
|
+
budget: WorkingBudgetState;
|
|
392
|
+
} | {
|
|
393
|
+
type: "account_usage";
|
|
394
|
+
usage: WorkingUsageDelta;
|
|
395
|
+
} | {
|
|
396
|
+
type: "set_continuation_policy";
|
|
397
|
+
policy: WorkingContinuationPolicy;
|
|
398
|
+
resumeAfter?: string;
|
|
399
|
+
staleAfter?: string;
|
|
400
|
+
stopReason?: string;
|
|
401
|
+
};
|
|
402
|
+
/** External goal mutation intents that require progress accounting first. */
|
|
403
|
+
type WorkingExternalGoalMutationKind = "set" | "clear" | "pause" | "resume" | "compact" | "fork" | "handoff" | "scheduled_delay" | "shutdown" | "other";
|
|
404
|
+
/** Explicit terminal intent for close actions. */
|
|
405
|
+
type AgenrWorkCloseMode = "close" | "abandon";
|
|
406
|
+
/**
|
|
407
|
+
* Parameters accepted by the `agenr_work` tool.
|
|
408
|
+
*/
|
|
409
|
+
interface AgenrWorkParams {
|
|
410
|
+
/** Action to execute. */
|
|
411
|
+
action: AgenrWorkAction;
|
|
412
|
+
/** Explicit working-set id when known. */
|
|
413
|
+
workingSetId?: string;
|
|
414
|
+
/** Raw scope facts supplied by the host. */
|
|
415
|
+
scope?: Partial<WorkingScope>;
|
|
416
|
+
/** Granular operation for `create` and `update`. */
|
|
417
|
+
operation?: AgenrWorkUpdateOperation;
|
|
418
|
+
/** Required observed revision for update and close operations. */
|
|
419
|
+
expectedRevision?: number;
|
|
420
|
+
/** Required audit reason for create and update operations. */
|
|
421
|
+
updateReason?: string;
|
|
422
|
+
/** Actor that initiated update or close. */
|
|
423
|
+
actor?: AgenrWorkMutationActor;
|
|
424
|
+
/** Runtime surface that emitted update or close. */
|
|
425
|
+
source?: AgenrWorkMutationSource;
|
|
426
|
+
/** Whether event details should be included in read responses. */
|
|
427
|
+
includeEvents?: boolean;
|
|
428
|
+
/** Maximum event count to include in read responses. */
|
|
429
|
+
eventLimit?: number;
|
|
430
|
+
/** Maximum working sets to return for list responses. */
|
|
431
|
+
listLimit?: number;
|
|
432
|
+
/** Reason supplied when closing or abandoning a working set. */
|
|
433
|
+
closeReason?: string;
|
|
434
|
+
/** Explicit terminal intent for close actions. */
|
|
435
|
+
closeMode?: AgenrWorkCloseMode;
|
|
436
|
+
/** Whether close should request an episode when thresholds pass. */
|
|
437
|
+
createEpisode?: boolean;
|
|
438
|
+
/** Initial budget state supplied by a goal alias or host command. */
|
|
439
|
+
initialBudget?: WorkingBudgetState;
|
|
440
|
+
/** Initial continuation policy supplied by a trusted host command. */
|
|
441
|
+
continuationPolicy?: WorkingContinuationPolicy;
|
|
442
|
+
}
|
|
443
|
+
/**
|
|
444
|
+
* Trusted host request to account progress before mutating goal state externally.
|
|
445
|
+
*/
|
|
446
|
+
interface PrepareExternalGoalMutationParams {
|
|
447
|
+
/** External mutation that is about to run. */
|
|
448
|
+
mutationKind: WorkingExternalGoalMutationKind;
|
|
449
|
+
/** Explicit working-set id when known. */
|
|
450
|
+
workingSetId?: string;
|
|
451
|
+
/** Raw scope facts supplied by the host. */
|
|
452
|
+
scope?: Partial<WorkingScope>;
|
|
453
|
+
/** Optional checkpoint to merge before the external mutation. */
|
|
454
|
+
checkpoint?: WorkingCheckpoint;
|
|
455
|
+
/** Optional usage delta to account before the external mutation. */
|
|
456
|
+
usage?: WorkingUsageDelta;
|
|
457
|
+
/** Whether an active goal must have a checkpoint before the mutation proceeds. */
|
|
458
|
+
requireCheckpoint?: boolean;
|
|
459
|
+
/** Actor that initiated the external mutation. */
|
|
460
|
+
actor?: AgenrWorkMutationActor;
|
|
461
|
+
/** Trusted host surface that emitted the mutation. */
|
|
462
|
+
source: TrustedHostMutationSource;
|
|
463
|
+
/** Optional audit reason used for generated accounting writes. */
|
|
464
|
+
updateReason?: string;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
/**
|
|
468
|
+
* Status values accepted by working sets.
|
|
469
|
+
*/
|
|
470
|
+
declare const WORKING_SET_STATUSES: readonly ["active", "paused", "blocked", "waiting", "needs_review", "budget_limited", "complete", "closed", "abandoned"];
|
|
471
|
+
/**
|
|
472
|
+
* Canonical scope kinds produced by the working-memory scope resolver.
|
|
473
|
+
*/
|
|
474
|
+
declare const WORKING_SCOPE_KINDS: readonly ["task", "conversation", "git_branch", "git_cwd", "session", "session_id"];
|
|
475
|
+
/**
|
|
476
|
+
* Supported working-memory tool actions.
|
|
477
|
+
*/
|
|
478
|
+
declare const AGENR_WORK_ACTIONS: readonly ["get", "list", "create", "update", "close"];
|
|
479
|
+
/**
|
|
480
|
+
* Actors allowed to mutate the working-memory ledger.
|
|
481
|
+
*/
|
|
482
|
+
declare const AGENR_WORK_MUTATION_ACTORS: readonly ["model", "user", "runtime", "system"];
|
|
483
|
+
/**
|
|
484
|
+
* Source surfaces that can emit working-memory mutations.
|
|
485
|
+
*/
|
|
486
|
+
declare const AGENR_WORK_MUTATION_SOURCES: readonly ["tool", "goal_command", "lifecycle_hook", "consolidation_job"];
|
|
487
|
+
/**
|
|
488
|
+
* Trusted host surfaces allowed to close working sets and omit expectedRevision.
|
|
489
|
+
*/
|
|
490
|
+
declare const TRUSTED_HOST_MUTATION_SOURCES: readonly ["goal_command", "lifecycle_hook", "consolidation_job"];
|
|
491
|
+
/**
|
|
492
|
+
* Candidate promotion states emitted by close and consolidation paths.
|
|
493
|
+
*/
|
|
494
|
+
declare const WORKING_CANDIDATE_PROMOTION_STATUSES: readonly ["pending", "promoted", "dismissed"];
|
|
495
|
+
/**
|
|
496
|
+
* Host continuation policies stored on active working sets.
|
|
497
|
+
*/
|
|
498
|
+
declare const WORKING_CONTINUATION_POLICIES: readonly ["manual", "on_idle"];
|
|
499
|
+
/**
|
|
500
|
+
* Budget dimensions that can stop autonomous goal continuation.
|
|
501
|
+
*/
|
|
502
|
+
declare const WORKING_BUDGET_LIMIT_REASONS: readonly ["token", "wall_clock", "turn"];
|
|
503
|
+
|
|
504
|
+
/**
|
|
505
|
+
* Union of all supported working-set statuses.
|
|
506
|
+
*/
|
|
507
|
+
type WorkingSetStatus = (typeof WORKING_SET_STATUSES)[number];
|
|
508
|
+
/**
|
|
509
|
+
* Union of canonical working-scope kinds.
|
|
510
|
+
*/
|
|
511
|
+
type WorkingScopeKind = (typeof WORKING_SCOPE_KINDS)[number];
|
|
512
|
+
/**
|
|
513
|
+
* Union of supported working-memory tool actions.
|
|
514
|
+
*/
|
|
515
|
+
type AgenrWorkAction = (typeof AGENR_WORK_ACTIONS)[number];
|
|
516
|
+
/**
|
|
517
|
+
* Union of actors that can mutate a working set.
|
|
518
|
+
*/
|
|
519
|
+
type AgenrWorkMutationActor = (typeof AGENR_WORK_MUTATION_ACTORS)[number];
|
|
520
|
+
/**
|
|
521
|
+
* Union of surfaces that can emit working-memory mutations.
|
|
522
|
+
*/
|
|
523
|
+
type AgenrWorkMutationSource = (typeof AGENR_WORK_MUTATION_SOURCES)[number];
|
|
524
|
+
/**
|
|
525
|
+
* Union of trusted host surfaces that may close working sets and default revision.
|
|
526
|
+
*/
|
|
527
|
+
type TrustedHostMutationSource = (typeof TRUSTED_HOST_MUTATION_SOURCES)[number];
|
|
528
|
+
/**
|
|
529
|
+
* Union of candidate promotion states.
|
|
530
|
+
*/
|
|
531
|
+
type WorkingCandidatePromotionStatus = (typeof WORKING_CANDIDATE_PROMOTION_STATUSES)[number];
|
|
532
|
+
/**
|
|
533
|
+
* Union of host continuation policies.
|
|
534
|
+
*/
|
|
535
|
+
type WorkingContinuationPolicy = (typeof WORKING_CONTINUATION_POLICIES)[number];
|
|
536
|
+
/**
|
|
537
|
+
* Union of budget dimensions that can stop continuation.
|
|
538
|
+
*/
|
|
539
|
+
type WorkingBudgetLimitReason = (typeof WORKING_BUDGET_LIMIT_REASONS)[number];
|
|
540
|
+
|
|
541
|
+
/**
|
|
542
|
+
* Raw scope facts supplied by a host runtime.
|
|
543
|
+
*/
|
|
544
|
+
interface WorkingScope {
|
|
545
|
+
/** Host session id used for provenance columns. */
|
|
546
|
+
sessionId?: string;
|
|
547
|
+
/** Git repository root when known. */
|
|
548
|
+
gitRoot?: string;
|
|
549
|
+
/** Active Git branch when known. */
|
|
550
|
+
gitBranch?: string;
|
|
551
|
+
/** Current working directory when known. */
|
|
552
|
+
cwd?: string;
|
|
553
|
+
/** Project label supplied by the host or config. */
|
|
554
|
+
project?: string;
|
|
555
|
+
/** Explicit task identifier for multiple concurrent work items. */
|
|
556
|
+
taskId?: string;
|
|
557
|
+
/** Host-neutral conversation identifier. */
|
|
558
|
+
conversationKey?: string;
|
|
559
|
+
}
|
|
560
|
+
/**
|
|
561
|
+
* Canonical working scope selected by agenr.
|
|
562
|
+
*/
|
|
563
|
+
interface ResolvedWorkingScope extends WorkingScope {
|
|
564
|
+
/** Canonical scope key used by persistence and cardinality checks. */
|
|
565
|
+
scopeKey: string;
|
|
566
|
+
/** Resolution strategy that produced the canonical scope key. */
|
|
567
|
+
scopeKind: WorkingScopeKind;
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
/**
|
|
571
|
+
* Phase 2 session-memory contracts.
|
|
572
|
+
*/
|
|
573
|
+
/**
|
|
574
|
+
* Artifact kinds accepted by schema v12.
|
|
575
|
+
*/
|
|
576
|
+
declare const SESSION_ARTIFACT_KINDS: readonly ["continuity_summary", "recent_session", "compaction_checkpoint", "branch_abandonment", "session_episode"];
|
|
577
|
+
/**
|
|
578
|
+
* Host transition reasons that create session-lineage edges.
|
|
579
|
+
*/
|
|
580
|
+
declare const SESSION_LINEAGE_REASONS: readonly ["fork", "clone", "resume", "subagent_spawn"];
|
|
581
|
+
/**
|
|
582
|
+
* Host transition reasons accepted at session start.
|
|
583
|
+
*/
|
|
584
|
+
declare const SESSION_START_TRANSITION_REASONS: readonly ["new", "unknown", "fork", "clone", "resume", "subagent_spawn"];
|
|
585
|
+
/**
|
|
586
|
+
* Lifecycle trigger names that can matter to session-memory routing.
|
|
587
|
+
*/
|
|
588
|
+
declare const SESSION_MEMORY_TRIGGER_TYPES: readonly ["session_start", "session_before_fork", "session_before_compact", "session_compact", "session_before_tree", "session_tree", "session_shutdown"];
|
|
589
|
+
|
|
590
|
+
/**
|
|
591
|
+
* Union of schema v12 session-artifact kinds.
|
|
592
|
+
*/
|
|
593
|
+
type SessionArtifactKind = (typeof SESSION_ARTIFACT_KINDS)[number];
|
|
594
|
+
/**
|
|
595
|
+
* Union of host transition reasons that create lineage edges.
|
|
596
|
+
*/
|
|
597
|
+
type SessionLineageReason = (typeof SESSION_LINEAGE_REASONS)[number];
|
|
598
|
+
/**
|
|
599
|
+
* Union of accepted session-start transition reasons.
|
|
600
|
+
*/
|
|
601
|
+
type SessionStartTransitionReason = (typeof SESSION_START_TRANSITION_REASONS)[number];
|
|
602
|
+
/**
|
|
603
|
+
* Union of lifecycle triggers accepted by the session-memory router.
|
|
604
|
+
*/
|
|
605
|
+
type SessionMemoryTriggerType = (typeof SESSION_MEMORY_TRIGGER_TYPES)[number];
|
|
606
|
+
/**
|
|
607
|
+
* Schema v12 lineage edge row shape frozen for the session-tree phase.
|
|
608
|
+
*/
|
|
609
|
+
interface SessionLineageEdge {
|
|
610
|
+
/** Primary key. */
|
|
611
|
+
id: string;
|
|
612
|
+
/** Child session key. */
|
|
613
|
+
childSessionKey: string;
|
|
614
|
+
/** Parent session key when known. */
|
|
615
|
+
parentSessionKey?: string;
|
|
616
|
+
/** Parent source reference when a parent key is unavailable. */
|
|
617
|
+
parentSourceRef?: string;
|
|
618
|
+
/** Host-supplied transition reason. */
|
|
619
|
+
reason: SessionLineageReason;
|
|
620
|
+
/** Host entry id at fork time when known. */
|
|
621
|
+
forkEntryId?: string;
|
|
622
|
+
/** Host fork position when known. */
|
|
623
|
+
forkPosition?: string;
|
|
624
|
+
/** ISO timestamp when the edge was observed. */
|
|
625
|
+
observedAt: string;
|
|
626
|
+
}
|
|
627
|
+
/**
|
|
628
|
+
* Parent session facts carried by host lifecycle events.
|
|
629
|
+
*/
|
|
630
|
+
interface SessionPredecessorRef {
|
|
631
|
+
/** Parent session key when the host can resolve it. */
|
|
632
|
+
sessionKey?: string;
|
|
633
|
+
/** Compact parent source reference when no stable key exists. */
|
|
634
|
+
sourceRef?: string;
|
|
635
|
+
/** Host entry id at fork time when known. */
|
|
636
|
+
forkEntryId?: string;
|
|
637
|
+
/** Host fork position when known. */
|
|
638
|
+
forkPosition?: string;
|
|
639
|
+
}
|
|
640
|
+
/**
|
|
641
|
+
* Schema v12 session-artifact row shape frozen for the session-tree phase.
|
|
642
|
+
*/
|
|
643
|
+
interface SessionArtifact {
|
|
644
|
+
/** Primary key. */
|
|
645
|
+
id: string;
|
|
646
|
+
/** Artifact kind. */
|
|
647
|
+
kind: SessionArtifactKind;
|
|
648
|
+
/** Host session key. */
|
|
649
|
+
sessionKey: string;
|
|
650
|
+
/** Source adapter or runtime. */
|
|
651
|
+
source: string;
|
|
652
|
+
/** Source-local id. */
|
|
653
|
+
sourceId: string;
|
|
654
|
+
/** Optional compact source reference. */
|
|
655
|
+
sourceRef?: string;
|
|
656
|
+
/** Hash of artifact content. */
|
|
657
|
+
contentHash: string;
|
|
658
|
+
/** Artifact summary. */
|
|
659
|
+
summary: string;
|
|
660
|
+
/** Optional typed metadata. */
|
|
661
|
+
metadata?: unknown;
|
|
662
|
+
/** Creation timestamp. */
|
|
663
|
+
createdAt: string;
|
|
664
|
+
/** Expiry timestamp when retention is bounded. */
|
|
665
|
+
expiresAt?: string;
|
|
666
|
+
}
|
|
667
|
+
/**
|
|
668
|
+
* Session artifact payload accepted by lifecycle intake.
|
|
669
|
+
*/
|
|
670
|
+
interface SessionArtifactInput {
|
|
671
|
+
/** Artifact kind. */
|
|
672
|
+
kind: SessionArtifactKind;
|
|
673
|
+
/** Optional explicit session key. Defaults to the trigger session key. */
|
|
674
|
+
sessionKey?: string;
|
|
675
|
+
/** Source adapter or runtime. */
|
|
676
|
+
source: string;
|
|
677
|
+
/** Source-local id. */
|
|
678
|
+
sourceId: string;
|
|
679
|
+
/** Optional compact source reference. */
|
|
680
|
+
sourceRef?: string;
|
|
681
|
+
/** Artifact summary stored in schema v12. */
|
|
682
|
+
summary: string;
|
|
683
|
+
/** Optional caller-supplied content hash. */
|
|
684
|
+
contentHash?: string;
|
|
685
|
+
/** Optional typed metadata. */
|
|
686
|
+
metadata?: unknown;
|
|
687
|
+
/** Expiry timestamp when retention is bounded. */
|
|
688
|
+
expiresAt?: string;
|
|
689
|
+
}
|
|
690
|
+
/**
|
|
691
|
+
* Normalized session artifact payload ready for repository persistence.
|
|
692
|
+
*/
|
|
693
|
+
type NormalizedSessionArtifactInput = SessionArtifactInput & Required<Pick<SessionArtifactInput, "sessionKey" | "source" | "sourceId" | "summary" | "contentHash">>;
|
|
694
|
+
/**
|
|
695
|
+
* Host lifecycle event routed into future session-memory services.
|
|
696
|
+
*/
|
|
697
|
+
interface SessionMemoryTriggerEvent {
|
|
698
|
+
/** Trigger discriminator. */
|
|
699
|
+
type: SessionMemoryTriggerType;
|
|
700
|
+
/** Host session key when known. */
|
|
701
|
+
sessionKey?: string;
|
|
702
|
+
/** Explicit child session key when different from `sessionKey`. */
|
|
703
|
+
childSessionKey?: string;
|
|
704
|
+
/** Host transition reason when this event represents session movement. */
|
|
705
|
+
transitionReason?: SessionStartTransitionReason;
|
|
706
|
+
/** Parent session facts for lineage persistence. */
|
|
707
|
+
predecessor?: SessionPredecessorRef;
|
|
708
|
+
/** Optional session artifact to persist for this trigger. */
|
|
709
|
+
artifact?: SessionArtifactInput;
|
|
710
|
+
/** Optional working-memory scope facts for lifecycle checkpoint refreshes. */
|
|
711
|
+
workingScope?: Partial<WorkingScope>;
|
|
712
|
+
/** Normalized shutdown reason when `type` is `session_shutdown`. */
|
|
713
|
+
shutdownReason?: string;
|
|
714
|
+
/** Optional raw host payload retained for adapter-specific parsing. */
|
|
715
|
+
payload?: unknown;
|
|
716
|
+
/** ISO timestamp when the trigger was observed. */
|
|
717
|
+
observedAt: string;
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
/** Input used to persist one schema v12 lineage edge. */
|
|
721
|
+
interface UpsertSessionLineageEdgeInput {
|
|
722
|
+
/** Child session key receiving predecessor context. */
|
|
723
|
+
childSessionKey: string;
|
|
724
|
+
/** Parent session key when known. */
|
|
725
|
+
parentSessionKey?: string;
|
|
726
|
+
/** Parent source reference when a parent key is unavailable. */
|
|
727
|
+
parentSourceRef?: string;
|
|
728
|
+
/** Host-supplied transition reason. */
|
|
729
|
+
reason: SessionLineageReason;
|
|
730
|
+
/** Host entry id at fork time when known. */
|
|
731
|
+
forkEntryId?: string;
|
|
732
|
+
/** Host fork position when known. */
|
|
733
|
+
forkPosition?: string;
|
|
734
|
+
/** ISO timestamp when the edge was observed. */
|
|
735
|
+
observedAt: string;
|
|
736
|
+
}
|
|
737
|
+
/** Filter accepted by session-artifact list queries scoped to one session key. */
|
|
738
|
+
interface SessionArtifactListFilter {
|
|
739
|
+
/** Session key that owns the artifacts. */
|
|
740
|
+
sessionKey: string;
|
|
741
|
+
/** Optional artifact kinds to include. */
|
|
742
|
+
kinds?: SessionArtifactKind[];
|
|
743
|
+
/** Maximum number of artifacts to return. */
|
|
744
|
+
limit?: number;
|
|
745
|
+
}
|
|
746
|
+
/** Filter accepted by session-artifact list queries scoped to one source ref. */
|
|
747
|
+
interface SessionArtifactSourceRefListFilter {
|
|
748
|
+
/** Compact source reference stored on artifact rows. */
|
|
749
|
+
sourceRef: string;
|
|
750
|
+
/** Optional artifact kinds to include. */
|
|
751
|
+
kinds?: SessionArtifactKind[];
|
|
752
|
+
/** Maximum number of artifacts to return. */
|
|
753
|
+
limit?: number;
|
|
754
|
+
}
|
|
755
|
+
/** Optional facts persisted together from one lifecycle trigger intake. */
|
|
756
|
+
interface RecordTriggerIntakeInput {
|
|
757
|
+
/** Normalized artifact payload when the trigger includes artifact facts. */
|
|
758
|
+
artifact?: NormalizedSessionArtifactInput;
|
|
759
|
+
/** Normalized lineage payload when the trigger includes lineage facts. */
|
|
760
|
+
lineage?: UpsertSessionLineageEdgeInput;
|
|
761
|
+
}
|
|
762
|
+
/** Persisted facts returned from one lifecycle trigger intake. */
|
|
763
|
+
interface RecordTriggerIntakeResult {
|
|
764
|
+
/** Persisted artifact when one was written. */
|
|
765
|
+
artifact?: SessionArtifact;
|
|
766
|
+
/** Persisted lineage edge when one was written. */
|
|
767
|
+
lineageEdge?: SessionLineageEdge;
|
|
768
|
+
}
|
|
769
|
+
/** Persistence port for schema v12 session-memory storage. */
|
|
770
|
+
interface SessionMemoryRepository {
|
|
771
|
+
/**
|
|
772
|
+
* Inserts one lineage edge, or returns the existing matching edge.
|
|
773
|
+
*
|
|
774
|
+
* @param input - Normalized lineage edge payload.
|
|
775
|
+
* @returns Persisted lineage edge.
|
|
776
|
+
*/
|
|
777
|
+
upsertLineageEdge(input: UpsertSessionLineageEdgeInput): Promise<SessionLineageEdge>;
|
|
778
|
+
/**
|
|
779
|
+
* Inserts or updates one session artifact by `(kind, source, sourceId)`.
|
|
780
|
+
*
|
|
781
|
+
* @param input - Normalized artifact payload.
|
|
782
|
+
* @returns Persisted session artifact.
|
|
783
|
+
*/
|
|
784
|
+
upsertSessionArtifact(input: NormalizedSessionArtifactInput): Promise<SessionArtifact>;
|
|
785
|
+
/**
|
|
786
|
+
* Persists one or more trigger facts atomically.
|
|
787
|
+
*
|
|
788
|
+
* @param input - Optional artifact and lineage payloads from one lifecycle event.
|
|
789
|
+
* @returns Persisted facts written during the intake.
|
|
790
|
+
*/
|
|
791
|
+
recordTriggerIntake(input: RecordTriggerIntakeInput): Promise<RecordTriggerIntakeResult>;
|
|
792
|
+
/**
|
|
793
|
+
* Lists artifacts for one session key.
|
|
794
|
+
*
|
|
795
|
+
* @param filter - Session key, optional kinds, and bounded limit.
|
|
796
|
+
* @returns Matching artifacts ordered by newest first.
|
|
797
|
+
*/
|
|
798
|
+
listSessionArtifacts(filter: SessionArtifactListFilter): Promise<SessionArtifact[]>;
|
|
799
|
+
/**
|
|
800
|
+
* Lists artifacts linked to one source reference.
|
|
801
|
+
*
|
|
802
|
+
* @param filter - Source ref, optional kinds, and bounded limit.
|
|
803
|
+
* @returns Matching artifacts ordered by newest first.
|
|
804
|
+
*/
|
|
805
|
+
listSessionArtifactsBySourceRef(filter: SessionArtifactSourceRefListFilter): Promise<SessionArtifact[]>;
|
|
806
|
+
/**
|
|
807
|
+
* Loads the newest lineage edge for one child session.
|
|
808
|
+
*
|
|
809
|
+
* @param childSessionKey - Child session key.
|
|
810
|
+
* @returns Matching lineage edge, or null when none exists.
|
|
811
|
+
*/
|
|
812
|
+
getLatestLineageEdgeForChild(childSessionKey: string): Promise<SessionLineageEdge | null>;
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
/**
|
|
816
|
+
* Lifecycle event types written outside typed mutation operations.
|
|
817
|
+
*/
|
|
818
|
+
declare const WORKING_LIFECYCLE_EVENT_TYPES: readonly ["created", "closed", "abandoned", "heartbeat", "lease_acquired", "lease_released"];
|
|
819
|
+
|
|
820
|
+
/**
|
|
821
|
+
* Union of lifecycle event types stored in the working-event ledger.
|
|
822
|
+
*/
|
|
823
|
+
type WorkingLifecycleEventType = (typeof WORKING_LIFECYCLE_EVENT_TYPES)[number];
|
|
824
|
+
/**
|
|
825
|
+
* Closed union of event types stored in schema v11 `working_events.event_type`.
|
|
826
|
+
*/
|
|
827
|
+
type WorkingEventType = AgenrWorkUpdateOperation["type"] | WorkingLifecycleEventType;
|
|
828
|
+
|
|
829
|
+
/**
|
|
830
|
+
* Lean working-set row shape for the goal control plane.
|
|
831
|
+
*
|
|
832
|
+
* Task state lives in `snapshot` only. Top-level scope columns exist for
|
|
833
|
+
* provenance and one-open-set cardinality checks, not as a second source of truth.
|
|
834
|
+
*/
|
|
835
|
+
interface WorkingSetRecord {
|
|
836
|
+
/** Primary key. */
|
|
837
|
+
id: string;
|
|
838
|
+
/** Canonical scope key used for one-open-set cardinality. */
|
|
839
|
+
scopeKey: string;
|
|
840
|
+
/** Canonical scope kind. */
|
|
841
|
+
scopeKind: WorkingScopeKind;
|
|
842
|
+
/** Optional display title. */
|
|
843
|
+
title?: string;
|
|
844
|
+
/** Objective mirrored from the snapshot for list and audit surfaces. */
|
|
845
|
+
objective?: string;
|
|
846
|
+
/** Current working-set status. */
|
|
847
|
+
status: WorkingSetStatus;
|
|
848
|
+
/** Summary mirrored from the snapshot for list and audit surfaces. */
|
|
849
|
+
summary?: string;
|
|
850
|
+
/** Canonical snapshot JSON and sole source of task-state truth. */
|
|
851
|
+
snapshot: WorkingSnapshot;
|
|
852
|
+
/** Monotonic optimistic-concurrency revision advanced only on semantic writes. */
|
|
853
|
+
revision: number;
|
|
854
|
+
/** Optional project label. */
|
|
855
|
+
project?: string;
|
|
856
|
+
/** Optional host session id. */
|
|
857
|
+
sessionId?: string;
|
|
858
|
+
/** Optional host-neutral conversation key. */
|
|
859
|
+
conversationKey?: string;
|
|
860
|
+
/** Optional current working directory. */
|
|
861
|
+
cwd?: string;
|
|
862
|
+
/** Optional Git repository root. */
|
|
863
|
+
gitRoot?: string;
|
|
864
|
+
/** Optional Git branch. */
|
|
865
|
+
gitBranch?: string;
|
|
866
|
+
/** Optional explicit task id. */
|
|
867
|
+
taskId?: string;
|
|
868
|
+
/** Source adapter or runtime that created the set. */
|
|
869
|
+
source?: string;
|
|
870
|
+
/** Creation timestamp. */
|
|
871
|
+
createdAt: string;
|
|
872
|
+
/** Last update timestamp. */
|
|
873
|
+
updatedAt: string;
|
|
874
|
+
/** Last material activity timestamp. */
|
|
875
|
+
lastActiveAt: string;
|
|
876
|
+
/** Close timestamp when closed. */
|
|
877
|
+
closedAt?: string;
|
|
878
|
+
/** Close or abandon reason. */
|
|
879
|
+
closeReason?: string;
|
|
880
|
+
/** Episode emitted from this set when one exists. */
|
|
881
|
+
episodeId?: string;
|
|
882
|
+
}
|
|
883
|
+
/**
|
|
884
|
+
* Working-event row shape stored in the append-only event log.
|
|
885
|
+
*/
|
|
886
|
+
interface WorkingEventRecord {
|
|
887
|
+
/** Primary key. */
|
|
888
|
+
id: string;
|
|
889
|
+
/** Owning working-set id. */
|
|
890
|
+
workingSetId: string;
|
|
891
|
+
/** Monotonic sequence within the working set, aligned with revision on semantic writes. */
|
|
892
|
+
sequence: number;
|
|
893
|
+
/** Closed event type union. */
|
|
894
|
+
eventType: WorkingEventType;
|
|
895
|
+
/** JSON-serializable payload. */
|
|
896
|
+
payload: unknown;
|
|
897
|
+
/** Actor that caused the event. */
|
|
898
|
+
actor?: AgenrWorkMutationActor;
|
|
899
|
+
/** Runtime source that emitted the event. */
|
|
900
|
+
source?: AgenrWorkMutationSource;
|
|
901
|
+
/** Optional host event id for idempotency or tracing. */
|
|
902
|
+
hostEventId?: string;
|
|
903
|
+
/** Optional host turn id. */
|
|
904
|
+
turnId?: string;
|
|
905
|
+
/** Creation timestamp. */
|
|
906
|
+
createdAt: string;
|
|
907
|
+
}
|
|
908
|
+
|
|
909
|
+
/**
|
|
910
|
+
* Non-persistent projection returned to host adapters for model-visible context.
|
|
911
|
+
*/
|
|
912
|
+
interface WorkingContextProjection {
|
|
913
|
+
/** Projection discriminator used by host adapters. */
|
|
914
|
+
kind: "working_set";
|
|
915
|
+
/** Rendering depth selected by agenr. */
|
|
916
|
+
renderMode: "stub" | "full";
|
|
917
|
+
/** Fully rendered context block or conservative stub. */
|
|
918
|
+
content: string;
|
|
919
|
+
/** Working set that produced the projection when one was selected. */
|
|
920
|
+
workingSetId?: string;
|
|
921
|
+
/** Snapshot revision represented by the projection. */
|
|
922
|
+
revision?: number;
|
|
923
|
+
/** Stable provenance pointer for audits and debugging. */
|
|
924
|
+
sourceRef: string;
|
|
925
|
+
/** UTF-8 byte length of `content`. */
|
|
926
|
+
byteLength: number;
|
|
927
|
+
}
|
|
928
|
+
/**
|
|
929
|
+
* Compact audit pointer a host may persist outside replay text.
|
|
930
|
+
*/
|
|
931
|
+
interface WorkingContextAuditPointer {
|
|
932
|
+
/** Pointer source discriminator. */
|
|
933
|
+
source: "agenr_work";
|
|
934
|
+
/** Working set that produced the rendered projection. */
|
|
935
|
+
workingSetId: string;
|
|
936
|
+
/** Snapshot revision represented by the projection. */
|
|
937
|
+
revision: number;
|
|
938
|
+
/** Stable provenance pointer for audits and debugging. */
|
|
939
|
+
sourceRef: string;
|
|
940
|
+
/** UTF-8 byte length of the rendered projection. */
|
|
941
|
+
bytes: number;
|
|
942
|
+
/** Optional compact summary safe for audit views. */
|
|
943
|
+
summary?: string;
|
|
944
|
+
}
|
|
945
|
+
|
|
946
|
+
/** Filter accepted by working-set list queries. */
|
|
947
|
+
interface WorkingSetListFilter {
|
|
948
|
+
/** Optional raw scope facts used to narrow the list to one resolved scope. */
|
|
949
|
+
scope?: ResolvedWorkingScope;
|
|
950
|
+
/** Optional explicit statuses to include. */
|
|
951
|
+
statuses?: WorkingSetStatus[];
|
|
952
|
+
/** Maximum number of rows to return. */
|
|
953
|
+
limit?: number;
|
|
954
|
+
}
|
|
955
|
+
/** Successful create response from the repository. */
|
|
956
|
+
interface WorkingSetCreateSuccess {
|
|
957
|
+
/** Newly persisted working set. */
|
|
958
|
+
workingSet: WorkingSetRecord;
|
|
959
|
+
/** Created lifecycle event. */
|
|
960
|
+
event: WorkingEventRecord;
|
|
961
|
+
}
|
|
962
|
+
/** Failure returned when one open set already exists for the scope. */
|
|
963
|
+
interface WorkingSetCreateFailure {
|
|
964
|
+
/** Failure discriminator. */
|
|
965
|
+
kind: "active_set_exists";
|
|
966
|
+
/** Canonical scope key that already has an open set. */
|
|
967
|
+
scopeKey: string;
|
|
968
|
+
}
|
|
969
|
+
/** Result returned when a repository creates one working set. */
|
|
970
|
+
type WorkingSetCreateResult = WorkingSetCreateSuccess | WorkingSetCreateFailure;
|
|
971
|
+
/** Result returned when a repository mutates one working set. */
|
|
972
|
+
interface WorkingSetMutationResult {
|
|
973
|
+
/** Updated working set after the event is committed. */
|
|
974
|
+
workingSet: WorkingSetRecord;
|
|
975
|
+
/** Event written for the mutation. */
|
|
976
|
+
event: WorkingEventRecord;
|
|
977
|
+
}
|
|
978
|
+
/** Input used to persist a newly created working set. */
|
|
979
|
+
interface CreateWorkingSetInput {
|
|
980
|
+
/** Resolved canonical scope for the set. */
|
|
981
|
+
scope: ResolvedWorkingScope;
|
|
982
|
+
/** Initial display title. */
|
|
983
|
+
title?: string;
|
|
984
|
+
/** Initial objective mirrored for list surfaces. */
|
|
985
|
+
objective?: string;
|
|
986
|
+
/** Initial status. */
|
|
987
|
+
status: WorkingSetStatus;
|
|
988
|
+
/** Initial snapshot. */
|
|
989
|
+
snapshot: WorkingSnapshot;
|
|
990
|
+
/** Actor that initiated creation. */
|
|
991
|
+
actor?: AgenrWorkMutationActor;
|
|
992
|
+
/** Source surface that initiated creation. */
|
|
993
|
+
source?: AgenrWorkMutationSource;
|
|
994
|
+
/** Adapter or runtime source label stored on the row. */
|
|
995
|
+
sourceLabel?: string;
|
|
996
|
+
/** Stable host session id when available. */
|
|
997
|
+
sessionId?: string;
|
|
998
|
+
/** Timestamp to use for row and event creation. */
|
|
999
|
+
now: string;
|
|
1000
|
+
}
|
|
1001
|
+
/** Input used to persist an update event and snapshot revision. */
|
|
1002
|
+
interface UpdateWorkingSetInput {
|
|
1003
|
+
/** Working-set id to mutate. */
|
|
1004
|
+
workingSetId: string;
|
|
1005
|
+
/** Revision observed by the caller. */
|
|
1006
|
+
expectedRevision: number;
|
|
1007
|
+
/** Event type to append. */
|
|
1008
|
+
eventType: WorkingEventType;
|
|
1009
|
+
/** JSON-serializable event payload. */
|
|
1010
|
+
payload: unknown;
|
|
1011
|
+
/** Next status for the working set. */
|
|
1012
|
+
status: WorkingSetStatus;
|
|
1013
|
+
/** Next snapshot payload. */
|
|
1014
|
+
snapshot: WorkingSnapshot;
|
|
1015
|
+
/** Optional display title update. */
|
|
1016
|
+
title?: string;
|
|
1017
|
+
/** Optional objective mirror update. */
|
|
1018
|
+
objective?: string;
|
|
1019
|
+
/** Close timestamp for terminal updates. */
|
|
1020
|
+
closedAt?: string;
|
|
1021
|
+
/** Close or abandon reason for terminal updates. */
|
|
1022
|
+
closeReason?: string;
|
|
1023
|
+
/** Episode id emitted from the set when one exists. */
|
|
1024
|
+
episodeId?: string;
|
|
1025
|
+
/** Actor that initiated the mutation. */
|
|
1026
|
+
actor?: AgenrWorkMutationActor;
|
|
1027
|
+
/** Source surface that initiated the mutation. */
|
|
1028
|
+
source?: AgenrWorkMutationSource;
|
|
1029
|
+
/** Timestamp to use for row and event updates. */
|
|
1030
|
+
now: string;
|
|
1031
|
+
}
|
|
1032
|
+
/** Failure returned when a revision-guarded repository mutation cannot apply. */
|
|
1033
|
+
type WorkingSetWriteFailure = {
|
|
1034
|
+
kind: "not_found";
|
|
1035
|
+
} | {
|
|
1036
|
+
kind: "revision_conflict";
|
|
1037
|
+
actualRevision: number;
|
|
1038
|
+
} | {
|
|
1039
|
+
kind: "terminal_status";
|
|
1040
|
+
status: WorkingSetStatus;
|
|
1041
|
+
};
|
|
1042
|
+
/** Repository response for revision-guarded updates. */
|
|
1043
|
+
type WorkingSetWriteResult = WorkingSetMutationResult | WorkingSetWriteFailure;
|
|
1044
|
+
/** Input used to persist a trusted usage patch without advancing revision. */
|
|
1045
|
+
interface PatchWorkingSetUsageInput {
|
|
1046
|
+
/** Working-set id to mutate. */
|
|
1047
|
+
workingSetId: string;
|
|
1048
|
+
/** Revision observed by the caller; must match the stored row without incrementing. */
|
|
1049
|
+
expectedRevision: number;
|
|
1050
|
+
/** Next status for the working set. */
|
|
1051
|
+
status: WorkingSetStatus;
|
|
1052
|
+
/** Next snapshot payload. */
|
|
1053
|
+
snapshot: WorkingSnapshot;
|
|
1054
|
+
/** Optional display title update. */
|
|
1055
|
+
title?: string;
|
|
1056
|
+
/** Optional objective mirror update. */
|
|
1057
|
+
objective?: string;
|
|
1058
|
+
/** Timestamp to use for row updates. */
|
|
1059
|
+
now: string;
|
|
1060
|
+
}
|
|
1061
|
+
/** Successful usage patch response from the repository. */
|
|
1062
|
+
interface WorkingSetUsagePatchResult {
|
|
1063
|
+
/** Updated working set after the patch is committed. */
|
|
1064
|
+
workingSet: WorkingSetRecord;
|
|
1065
|
+
}
|
|
1066
|
+
/** Repository response for trusted usage patches. */
|
|
1067
|
+
type WorkingSetUsagePatchWriteResult = WorkingSetUsagePatchResult | WorkingSetWriteFailure;
|
|
1068
|
+
/** Persistence port for Phase 1 working-memory storage. */
|
|
1069
|
+
interface WorkingMemoryRepository {
|
|
1070
|
+
/**
|
|
1071
|
+
* Loads one working set by id.
|
|
1072
|
+
*
|
|
1073
|
+
* @param id - Working-set identifier.
|
|
1074
|
+
* @returns Stored set, or null when it does not exist.
|
|
1075
|
+
*/
|
|
1076
|
+
getWorkingSet(id: string): Promise<WorkingSetRecord | null>;
|
|
1077
|
+
/**
|
|
1078
|
+
* Finds current working sets for one resolved scope, including completed
|
|
1079
|
+
* goals that still occupy the scope until explicit user clear.
|
|
1080
|
+
*
|
|
1081
|
+
* @param scope - Canonical scope selected by the app service.
|
|
1082
|
+
* @returns Matching current working sets ordered by recency.
|
|
1083
|
+
*/
|
|
1084
|
+
findCurrentWorkingSets(scope: ResolvedWorkingScope): Promise<WorkingSetRecord[]>;
|
|
1085
|
+
/**
|
|
1086
|
+
* Lists working sets for inspection or tool output.
|
|
1087
|
+
*
|
|
1088
|
+
* @param filter - Optional scope, status, and limit filters.
|
|
1089
|
+
* @returns Matching working sets ordered by recency.
|
|
1090
|
+
*/
|
|
1091
|
+
listWorkingSets(filter: WorkingSetListFilter): Promise<WorkingSetRecord[]>;
|
|
1092
|
+
/**
|
|
1093
|
+
* Lists recent events for one working set.
|
|
1094
|
+
*
|
|
1095
|
+
* @param workingSetId - Working set to inspect.
|
|
1096
|
+
* @param limit - Maximum number of events to return.
|
|
1097
|
+
* @returns Events ordered by sequence ascending.
|
|
1098
|
+
*/
|
|
1099
|
+
listWorkingEvents(workingSetId: string, limit?: number): Promise<WorkingEventRecord[]>;
|
|
1100
|
+
/**
|
|
1101
|
+
* Creates one working set and its initial event atomically.
|
|
1102
|
+
*
|
|
1103
|
+
* @param input - Initial working-set state.
|
|
1104
|
+
* @returns Persisted working set plus created event.
|
|
1105
|
+
*/
|
|
1106
|
+
createWorkingSet(input: CreateWorkingSetInput): Promise<WorkingSetCreateResult>;
|
|
1107
|
+
/**
|
|
1108
|
+
* Applies one revision-guarded working-set mutation atomically.
|
|
1109
|
+
*
|
|
1110
|
+
* @param input - Update event, expected revision, and next snapshot.
|
|
1111
|
+
* @returns Updated row and event, or a stable write failure.
|
|
1112
|
+
*/
|
|
1113
|
+
updateWorkingSet(input: UpdateWorkingSetInput): Promise<WorkingSetWriteResult>;
|
|
1114
|
+
/**
|
|
1115
|
+
* Applies one trusted usage patch without advancing revision or appending events.
|
|
1116
|
+
*
|
|
1117
|
+
* @param input - Next snapshot and status guarded by expectedRevision compare-and-swap.
|
|
1118
|
+
* @returns Updated row or a stable write failure.
|
|
1119
|
+
*/
|
|
1120
|
+
patchWorkingSetUsage(input: PatchWorkingSetUsageInput): Promise<WorkingSetUsagePatchWriteResult>;
|
|
1121
|
+
}
|
|
1122
|
+
|
|
1123
|
+
/**
|
|
1124
|
+
* Stable error codes returned by the working-memory service.
|
|
1125
|
+
*/
|
|
1126
|
+
type WorkingMemoryErrorCode = "feature_disabled" | "misconfigured" | "invalid_request" | "missing_scope" | "missing_active_set" | "ambiguous_scope" | "active_set_exists" | "close_not_allowed" | "not_found" | "revision_conflict" | "terminal_status";
|
|
1127
|
+
/** Failed working-memory service result. */
|
|
1128
|
+
interface WorkingMemoryFailure {
|
|
1129
|
+
/** Failure discriminator. */
|
|
1130
|
+
ok: false;
|
|
1131
|
+
/** Stable failure code. */
|
|
1132
|
+
code: WorkingMemoryErrorCode;
|
|
1133
|
+
/** Human-readable failure message. */
|
|
1134
|
+
message: string;
|
|
1135
|
+
/** Optional machine-readable details. */
|
|
1136
|
+
details?: Record<string, unknown>;
|
|
1137
|
+
}
|
|
1138
|
+
/** Successful working-memory get result. */
|
|
1139
|
+
interface WorkingMemoryGetSuccess {
|
|
1140
|
+
/** Success discriminator. */
|
|
1141
|
+
ok: true;
|
|
1142
|
+
/** Action discriminator. */
|
|
1143
|
+
action: "get";
|
|
1144
|
+
/** Selected working set. */
|
|
1145
|
+
workingSet: WorkingSetRecord;
|
|
1146
|
+
/** Optional bounded event tail. */
|
|
1147
|
+
events?: WorkingEventRecord[];
|
|
1148
|
+
/** Full transient projection for the selected set. */
|
|
1149
|
+
projection: WorkingContextProjection;
|
|
1150
|
+
}
|
|
1151
|
+
/** Successful working-memory list result. */
|
|
1152
|
+
interface WorkingMemoryListSuccess {
|
|
1153
|
+
/** Success discriminator. */
|
|
1154
|
+
ok: true;
|
|
1155
|
+
/** Action discriminator. */
|
|
1156
|
+
action: "list";
|
|
1157
|
+
/** Matching working sets. */
|
|
1158
|
+
workingSets: WorkingSetRecord[];
|
|
1159
|
+
}
|
|
1160
|
+
/** Successful working-memory create result. */
|
|
1161
|
+
interface WorkingMemoryCreateSuccess {
|
|
1162
|
+
/** Success discriminator. */
|
|
1163
|
+
ok: true;
|
|
1164
|
+
/** Action discriminator. */
|
|
1165
|
+
action: "create";
|
|
1166
|
+
/** Newly created working set. */
|
|
1167
|
+
workingSet: WorkingSetRecord;
|
|
1168
|
+
/** Event committed for the creation. */
|
|
1169
|
+
event: WorkingEventRecord;
|
|
1170
|
+
/** Full transient projection after creation. */
|
|
1171
|
+
projection: WorkingContextProjection;
|
|
1172
|
+
}
|
|
1173
|
+
/** Successful working-memory update result. */
|
|
1174
|
+
interface WorkingMemoryUpdateSuccess {
|
|
1175
|
+
/** Success discriminator. */
|
|
1176
|
+
ok: true;
|
|
1177
|
+
/** Action discriminator. */
|
|
1178
|
+
action: "update";
|
|
1179
|
+
/** Updated working set. */
|
|
1180
|
+
workingSet: WorkingSetRecord;
|
|
1181
|
+
/** Event committed for semantic mutations; omitted for trusted usage patches. */
|
|
1182
|
+
event?: WorkingEventRecord;
|
|
1183
|
+
/** Full transient projection after the mutation. */
|
|
1184
|
+
projection: WorkingContextProjection;
|
|
1185
|
+
}
|
|
1186
|
+
/** Successful working-memory close result. */
|
|
1187
|
+
interface WorkingMemoryCloseSuccess {
|
|
1188
|
+
/** Success discriminator. */
|
|
1189
|
+
ok: true;
|
|
1190
|
+
/** Action discriminator. */
|
|
1191
|
+
action: "close";
|
|
1192
|
+
/** Closed working set. */
|
|
1193
|
+
workingSet: WorkingSetRecord;
|
|
1194
|
+
/** Terminal event committed for the close. */
|
|
1195
|
+
event: WorkingEventRecord;
|
|
1196
|
+
/** Candidates retained or emitted for later review. */
|
|
1197
|
+
candidates: WorkingCandidate[];
|
|
1198
|
+
}
|
|
1199
|
+
/** Successful prepare-before-external-mutation result. */
|
|
1200
|
+
interface WorkingMemoryPrepareExternalMutationSuccess {
|
|
1201
|
+
/** Success discriminator. */
|
|
1202
|
+
ok: true;
|
|
1203
|
+
/** Action discriminator. */
|
|
1204
|
+
action: "prepare_external_goal_mutation";
|
|
1205
|
+
/** Whether an active working set was found and prepared. */
|
|
1206
|
+
prepared: boolean;
|
|
1207
|
+
/** Active working set after preparation when one matched. */
|
|
1208
|
+
workingSet?: WorkingSetRecord;
|
|
1209
|
+
/** Events committed during preparation. */
|
|
1210
|
+
events: WorkingEventRecord[];
|
|
1211
|
+
}
|
|
1212
|
+
/** Result returned by `agenr_work` actions. */
|
|
1213
|
+
type WorkingMemoryResult = WorkingMemoryFailure | WorkingMemoryGetSuccess | WorkingMemoryListSuccess | WorkingMemoryCreateSuccess | WorkingMemoryUpdateSuccess | WorkingMemoryCloseSuccess | WorkingMemoryPrepareExternalMutationSuccess;
|
|
1214
|
+
|
|
1215
|
+
/** Result emitted when lifecycle refresh touches an active working set. */
|
|
1216
|
+
interface WorkingCheckpointRefreshSuccess {
|
|
1217
|
+
/** Success discriminator. */
|
|
1218
|
+
ok: true;
|
|
1219
|
+
/** Stable action discriminator. */
|
|
1220
|
+
action: "working_checkpoint_refreshed";
|
|
1221
|
+
/** Working set updated from the lifecycle checkpoint. */
|
|
1222
|
+
workingSetId: string;
|
|
1223
|
+
/** New working-set revision. */
|
|
1224
|
+
revision: number;
|
|
1225
|
+
}
|
|
1226
|
+
/** Result emitted when lifecycle refresh cannot or should not update WIP. */
|
|
1227
|
+
interface WorkingCheckpointRefreshSkipped {
|
|
1228
|
+
/** Failure or skip discriminator. */
|
|
1229
|
+
ok: false;
|
|
1230
|
+
/** Stable reason for the skipped refresh. */
|
|
1231
|
+
reason: "not_applicable" | "missing_scope" | "missing_summary" | "no_active_working_set" | "working_memory_unavailable";
|
|
1232
|
+
/** Working-memory error code when the working service rejected the update. */
|
|
1233
|
+
code?: WorkingMemoryErrorCode;
|
|
1234
|
+
/** Human-readable status for diagnostics. */
|
|
1235
|
+
message: string;
|
|
1236
|
+
}
|
|
1237
|
+
/** Result returned from lifecycle working-checkpoint refresh. */
|
|
1238
|
+
type WorkingCheckpointRefreshResult = WorkingCheckpointRefreshSuccess | WorkingCheckpointRefreshSkipped;
|
|
1239
|
+
|
|
1240
|
+
/**
|
|
1241
|
+
* Stable reasons returned when session-memory intake cannot run.
|
|
1242
|
+
*/
|
|
1243
|
+
type SessionMemoryTriggerFailureReason = "feature_disabled" | "misconfigured" | "invalid_event";
|
|
1244
|
+
/**
|
|
1245
|
+
* Successful session-memory intake action.
|
|
1246
|
+
*/
|
|
1247
|
+
type SessionMemoryTriggerAction = "lineage_recorded" | "artifact_recorded" | "recorded" | "checkpoint_relevant" | "no_lineage";
|
|
1248
|
+
/** Result returned when session-memory intake accepts an event. */
|
|
1249
|
+
interface SessionMemoryTriggerAcceptedResult {
|
|
1250
|
+
/** Whether the event was accepted for persistence or lifecycle handling. */
|
|
1251
|
+
accepted: true;
|
|
1252
|
+
/** Stable action performed by the intake service. */
|
|
1253
|
+
action: SessionMemoryTriggerAction;
|
|
1254
|
+
/** Human-readable status message. */
|
|
1255
|
+
message: string;
|
|
1256
|
+
/** Persisted lineage edge when one was recorded. */
|
|
1257
|
+
lineageEdge?: SessionLineageEdge;
|
|
1258
|
+
/** Persisted artifact when one was recorded. */
|
|
1259
|
+
artifact?: SessionArtifact;
|
|
1260
|
+
/** Working-set checkpoint refresh result for compaction lifecycle events. */
|
|
1261
|
+
workingCheckpointRefresh?: WorkingCheckpointRefreshResult;
|
|
1262
|
+
}
|
|
1263
|
+
/** Result returned when session-memory intake rejects an event. */
|
|
1264
|
+
interface SessionMemoryTriggerRejectedResult {
|
|
1265
|
+
/** Whether the event was accepted for persistence or lifecycle handling. */
|
|
1266
|
+
accepted: false;
|
|
1267
|
+
/** Stable reason no behavior ran. */
|
|
1268
|
+
reason: SessionMemoryTriggerFailureReason;
|
|
1269
|
+
/** Human-readable status message. */
|
|
1270
|
+
message: string;
|
|
1271
|
+
}
|
|
1272
|
+
/** Result returned by the session-memory trigger router. */
|
|
1273
|
+
type SessionMemoryTriggerResult = SessionMemoryTriggerAcceptedResult | SessionMemoryTriggerRejectedResult;
|
|
1274
|
+
|
|
1275
|
+
/** Input accepted by projection rendering. */
|
|
1276
|
+
interface WorkingProjectionRequest {
|
|
1277
|
+
/** Stable source reference for the render decision. */
|
|
1278
|
+
sourceRef: string;
|
|
1279
|
+
/** Explicit working set id when known. */
|
|
1280
|
+
workingSetId?: string;
|
|
1281
|
+
/** Raw scope facts used to find an active set. */
|
|
1282
|
+
scope?: Partial<WorkingScope>;
|
|
1283
|
+
}
|
|
1284
|
+
/** Working-memory service surface. */
|
|
1285
|
+
interface WorkingMemoryService {
|
|
1286
|
+
/**
|
|
1287
|
+
* Handles `agenr_work` actions.
|
|
1288
|
+
*
|
|
1289
|
+
* @param params - Tool parameters from the host adapter.
|
|
1290
|
+
* @returns Working-memory action result.
|
|
1291
|
+
*/
|
|
1292
|
+
run(params: AgenrWorkParams): Promise<WorkingMemoryResult>;
|
|
1293
|
+
/**
|
|
1294
|
+
* Accounts progress before a trusted host mutates goal state externally.
|
|
1295
|
+
*
|
|
1296
|
+
* @param params - Trusted external mutation preparation request.
|
|
1297
|
+
* @returns Preparation result, including any committed accounting events.
|
|
1298
|
+
*/
|
|
1299
|
+
prepareExternalGoalMutation(params: PrepareExternalGoalMutationParams): Promise<WorkingMemoryResult>;
|
|
1300
|
+
/**
|
|
1301
|
+
* Builds a transient working-context projection for host adapters.
|
|
1302
|
+
*
|
|
1303
|
+
* @param input - Source reference or full projection request.
|
|
1304
|
+
* @returns A full projection when an active set resolves, otherwise a conservative stub.
|
|
1305
|
+
*/
|
|
1306
|
+
renderProjection(input: string | WorkingProjectionRequest): Promise<WorkingContextProjection>;
|
|
1307
|
+
}
|
|
1308
|
+
|
|
1309
|
+
/**
|
|
1310
|
+
* Feature-scoped durable-memory lookup contract used by session-start selection.
|
|
1311
|
+
*/
|
|
1312
|
+
interface SessionStartRepository {
|
|
1313
|
+
/**
|
|
1314
|
+
* Lists active always-on core entries ordered for session-start use.
|
|
1315
|
+
*
|
|
1316
|
+
* @param limit - Maximum number of core entries to return.
|
|
1317
|
+
* @returns Ordered active core entries.
|
|
1318
|
+
*/
|
|
1319
|
+
listCoreEntries(limit: number): Promise<Entry[]>;
|
|
1320
|
+
}
|
|
1321
|
+
/**
|
|
1322
|
+
* Dependencies needed by the app-layer session-start service.
|
|
1323
|
+
*/
|
|
1324
|
+
interface SessionStartDeps {
|
|
1325
|
+
/** Feature-scoped repository for always-on core memory lookup. */
|
|
1326
|
+
repository: SessionStartRepository;
|
|
1327
|
+
/** Shared durable recall ports reused for artifact-grounded memory selection. */
|
|
1328
|
+
recall: RecallPorts;
|
|
1329
|
+
/** Optional runtime claim-slot-policy overrides used during claim-aware shaping. */
|
|
1330
|
+
slotPolicyConfig?: ClaimSlotPolicyConfig;
|
|
1331
|
+
}
|
|
1332
|
+
|
|
1333
|
+
/**
|
|
1334
|
+
* Slot-policy overrides shared by host plugin adapters at runtime.
|
|
1335
|
+
*/
|
|
1336
|
+
interface PluginClaimSlotPolicyConfig extends ClaimSlotPolicyConfig {
|
|
1337
|
+
/** Optional attribute-head policy overrides keyed by canonical attribute head. */
|
|
1338
|
+
attributeHeads?: Readonly<Record<string, ClaimSlotPolicy>>;
|
|
1339
|
+
}
|
|
1340
|
+
/**
|
|
1341
|
+
* Narrow read-time memory-policy settings shared by host plugin adapters.
|
|
1342
|
+
*/
|
|
1343
|
+
interface PluginMemoryPolicyConfig {
|
|
1344
|
+
/** Read-time slot-policy overrides used by recall surfaces. */
|
|
1345
|
+
slotPolicies?: PluginClaimSlotPolicyConfig;
|
|
1346
|
+
}
|
|
1347
|
+
/**
|
|
1348
|
+
* Session-start overrides for prompt-time memory injection behavior.
|
|
1349
|
+
*/
|
|
1350
|
+
interface PluginSessionStartMemoryPolicyConfig {
|
|
1351
|
+
/** Enables or disables session-start memory injection. Defaults to true. */
|
|
1352
|
+
enabled?: boolean;
|
|
1353
|
+
/** Enables or disables always-on core memory injection at session start. Defaults to true. */
|
|
1354
|
+
coreMemory?: boolean;
|
|
1355
|
+
/** Enables or disables artifact-grounded relevant durable memory injection. */
|
|
1356
|
+
relevantDurableMemory?: boolean;
|
|
1357
|
+
}
|
|
1358
|
+
/**
|
|
1359
|
+
* Before-turn overrides for proactive prompt-time memory injection behavior.
|
|
1360
|
+
*/
|
|
1361
|
+
interface PluginBeforeTurnMemoryPolicyConfig {
|
|
1362
|
+
/** Enables or disables the proactive before-turn patch path. */
|
|
1363
|
+
enabled?: boolean;
|
|
1364
|
+
/** Enables or disables proactive procedure suggestion inside the patch. */
|
|
1365
|
+
procedureSuggestion?: boolean;
|
|
1366
|
+
/** Normal durable-item cap before very-high-confidence expansion applies. */
|
|
1367
|
+
maxDurableEntries?: number;
|
|
1368
|
+
/** Durable-recall score threshold required before an entry can surface. */
|
|
1369
|
+
recallThreshold?: number;
|
|
1370
|
+
/** Durable-recall score threshold required before surfacing more than the normal cap. */
|
|
1371
|
+
highConfidenceRecallThreshold?: number;
|
|
1372
|
+
/** Procedure-recall score threshold required before a proactive procedure can surface. */
|
|
1373
|
+
procedureThreshold?: number;
|
|
1374
|
+
}
|
|
1375
|
+
/**
|
|
1376
|
+
* Working-context overrides for transient per-turn WIP injection.
|
|
1377
|
+
*/
|
|
1378
|
+
interface PluginWorkingContextMemoryPolicyConfig {
|
|
1379
|
+
/** Enables or disables automatic working-context injection. Defaults to true when working memory is enabled. */
|
|
1380
|
+
enabled?: boolean;
|
|
1381
|
+
}
|
|
1382
|
+
/**
|
|
1383
|
+
* Memory-policy settings shared by host plugin adapters, including injection knobs.
|
|
1384
|
+
*/
|
|
1385
|
+
interface PluginInjectionMemoryPolicyConfig extends PluginMemoryPolicyConfig {
|
|
1386
|
+
/** Session-start overrides for prompt-time memory injection behavior. */
|
|
1387
|
+
sessionStart?: PluginSessionStartMemoryPolicyConfig;
|
|
1388
|
+
/** Before-turn overrides for proactive prompt-time memory injection behavior. */
|
|
1389
|
+
beforeTurn?: PluginBeforeTurnMemoryPolicyConfig;
|
|
1390
|
+
/** Working-context overrides for transient per-turn WIP injection. */
|
|
1391
|
+
workingContext?: PluginWorkingContextMemoryPolicyConfig;
|
|
1392
|
+
}
|
|
1393
|
+
/**
|
|
1394
|
+
* Infrastructure path overrides shared by host plugin adapters.
|
|
1395
|
+
*/
|
|
1396
|
+
interface PluginPathConfig {
|
|
1397
|
+
/** Path to the shared agenr SQLite database. */
|
|
1398
|
+
dbPath?: string;
|
|
1399
|
+
/** Path to the agenr config.json file. */
|
|
1400
|
+
configPath?: string;
|
|
1401
|
+
}
|
|
1402
|
+
/**
|
|
1403
|
+
* Concrete runtime paths derived from plugin config and agenr defaults.
|
|
1404
|
+
*/
|
|
1405
|
+
interface ResolvedPluginPaths {
|
|
1406
|
+
dbPath: string;
|
|
1407
|
+
configPath: string;
|
|
1408
|
+
}
|
|
1409
|
+
/**
|
|
1410
|
+
* Static embedding availability facts derived from agenr configuration.
|
|
1411
|
+
*/
|
|
1412
|
+
interface PluginEmbeddingStatus {
|
|
1413
|
+
available: boolean;
|
|
1414
|
+
provider: string;
|
|
1415
|
+
requestedProvider: string;
|
|
1416
|
+
model: string;
|
|
1417
|
+
error?: string;
|
|
1418
|
+
}
|
|
1419
|
+
/**
|
|
1420
|
+
* Optional claim-extraction runtime wired by host plugin composition.
|
|
1421
|
+
*/
|
|
1422
|
+
interface PluginClaimExtractionRuntime {
|
|
1423
|
+
llm: LlmPort;
|
|
1424
|
+
config: ClaimExtractionConfig;
|
|
1425
|
+
}
|
|
1426
|
+
/**
|
|
1427
|
+
* Process-lifetime memory services shared by host plugin runtimes.
|
|
1428
|
+
*/
|
|
1429
|
+
interface PluginMemoryRuntimeServices {
|
|
1430
|
+
entries: DatabasePort;
|
|
1431
|
+
episodes: EpisodeDatabasePort;
|
|
1432
|
+
procedures: ProcedureDatabasePort;
|
|
1433
|
+
memory: MemoryRepository;
|
|
1434
|
+
workingMemoryRepository?: WorkingMemoryRepository;
|
|
1435
|
+
sessionMemoryRepository?: SessionMemoryRepository;
|
|
1436
|
+
sessionStart: SessionStartDeps;
|
|
1437
|
+
beforeTurn: BeforeTurnDeps;
|
|
1438
|
+
embedding: EmbeddingPort;
|
|
1439
|
+
recall: RecallPorts;
|
|
1440
|
+
claimExtraction?: PluginClaimExtractionRuntime;
|
|
1441
|
+
embeddingStatus: PluginEmbeddingStatus;
|
|
1442
|
+
close(): Promise<void>;
|
|
1443
|
+
}
|
|
1444
|
+
|
|
1445
|
+
/**
|
|
1446
|
+
* Skeln-native scope facts gathered by the host extension and passed into the
|
|
1447
|
+
* agenr adapter for recall, store provenance, and session-start routing.
|
|
1448
|
+
*/
|
|
1449
|
+
interface SkelnHostContext {
|
|
1450
|
+
/** Current working directory for the active Skeln session. */
|
|
1451
|
+
cwd: string;
|
|
1452
|
+
/** Repository root when the session cwd is inside a git work tree. */
|
|
1453
|
+
gitRoot?: string;
|
|
1454
|
+
/** Current git branch when available from the host extension. */
|
|
1455
|
+
gitBranch?: string;
|
|
1456
|
+
/** Optional project label supplied by the host extension. */
|
|
1457
|
+
project?: string;
|
|
1458
|
+
/** Optional host-neutral conversation identifier supplied by Skeln. */
|
|
1459
|
+
conversationKey?: string;
|
|
1460
|
+
/** Stable recall/session key derived from Skeln session identity and cwd. */
|
|
1461
|
+
sessionKey: string;
|
|
1462
|
+
}
|
|
1463
|
+
/**
|
|
1464
|
+
* Options accepted by {@link registerAgenrSkelnMemory}.
|
|
1465
|
+
*/
|
|
1466
|
+
interface RegisterAgenrSkelnMemoryOptions {
|
|
1467
|
+
/** Path to the shared agenr SQLite database. */
|
|
1468
|
+
dbPath?: string;
|
|
1469
|
+
/** Path to the agenr config.json file. */
|
|
1470
|
+
configPath?: string;
|
|
1471
|
+
/** Narrow runtime memory-policy overrides for claim-aware read surfaces. */
|
|
1472
|
+
memoryPolicy?: PluginInjectionMemoryPolicyConfig;
|
|
1473
|
+
/** Optional Skeln host feature-flag overrides merged over agenr config features. */
|
|
1474
|
+
featureFlags?: AgenrFeatureFlagConfig;
|
|
1475
|
+
/**
|
|
1476
|
+
* Optional host callback that supplies Skeln-native scope facts. When absent,
|
|
1477
|
+
* the adapter derives cwd and sessionKey from the active extension context.
|
|
1478
|
+
*/
|
|
1479
|
+
getHostContext?: (context: ExtensionContext) => Partial<SkelnHostContext> | Promise<Partial<SkelnHostContext>>;
|
|
1480
|
+
}
|
|
1481
|
+
/**
|
|
1482
|
+
* Resolved session scope used by Skeln lifecycle hooks and recall routing.
|
|
1483
|
+
*/
|
|
1484
|
+
interface AgenrSkelnSessionScope {
|
|
1485
|
+
/** Ephemeral Skeln session identifier. */
|
|
1486
|
+
sessionId: string;
|
|
1487
|
+
/** Stable recall/session key for durable memory routing. */
|
|
1488
|
+
sessionKey: string;
|
|
1489
|
+
/** Current working directory for the active session. */
|
|
1490
|
+
cwd: string;
|
|
1491
|
+
/** Repository root when available. */
|
|
1492
|
+
gitRoot?: string;
|
|
1493
|
+
/** Current git branch when available. */
|
|
1494
|
+
gitBranch?: string;
|
|
1495
|
+
/** Optional project label when available. */
|
|
1496
|
+
project?: string;
|
|
1497
|
+
/** Optional host-neutral conversation identifier. */
|
|
1498
|
+
conversationKey?: string;
|
|
1499
|
+
}
|
|
1500
|
+
|
|
1501
|
+
/**
|
|
1502
|
+
* Supported auth methods for agenr-managed LLM access.
|
|
1503
|
+
*/
|
|
1504
|
+
type AgenrAuthMethod = "openai-api-key" | "openai-subscription" | "anthropic-api-key" | "anthropic-oauth" | "anthropic-token";
|
|
1505
|
+
/**
|
|
1506
|
+
* Manually entered credentials persisted in `config.json`.
|
|
1507
|
+
*
|
|
1508
|
+
* OAuth and subscription credentials are auto-detected from external CLIs and
|
|
1509
|
+
* should not be stored here.
|
|
1510
|
+
*/
|
|
1511
|
+
interface AgenrStoredCredentials {
|
|
1512
|
+
/** OpenAI API key used for extraction, embeddings, or both. */
|
|
1513
|
+
openaiApiKey?: string;
|
|
1514
|
+
/** Anthropic API key used for extraction requests. */
|
|
1515
|
+
anthropicApiKey?: string;
|
|
1516
|
+
/** Anthropic long-lived token used for subscription auth. */
|
|
1517
|
+
anthropicOauthToken?: string;
|
|
1518
|
+
}
|
|
1519
|
+
/**
|
|
1520
|
+
* Per-pipeline model configuration.
|
|
1521
|
+
*
|
|
1522
|
+
* Each pipeline stage can use a different provider/model combination.
|
|
1523
|
+
* Falls back to the top-level provider/model when not set.
|
|
1524
|
+
*/
|
|
1525
|
+
interface ModelConfig {
|
|
1526
|
+
/** Provider name (for example `openai` or `anthropic`). */
|
|
1527
|
+
provider?: string;
|
|
1528
|
+
/** Model ID (for example `gpt-5.4` or `gpt-5.4-nano`). */
|
|
1529
|
+
model?: string;
|
|
1530
|
+
}
|
|
1531
|
+
/**
|
|
1532
|
+
* Per-pass surgeon configuration.
|
|
1533
|
+
*/
|
|
1534
|
+
interface SurgeonPassConfig {
|
|
1535
|
+
/** Protect entries recalled within this many days. */
|
|
1536
|
+
protectRecalledDays?: number;
|
|
1537
|
+
/** Protect entries at or above this importance. */
|
|
1538
|
+
protectMinImportance?: number;
|
|
1539
|
+
/** Skip entries evaluated by surgeon in the last N days. */
|
|
1540
|
+
skipRecentlyEvaluatedDays?: number;
|
|
1541
|
+
}
|
|
1542
|
+
/**
|
|
1543
|
+
* Surgeon module configuration persisted in `config.json`.
|
|
1544
|
+
*/
|
|
1545
|
+
interface SurgeonConfig {
|
|
1546
|
+
/** Model override for surgeon runs. */
|
|
1547
|
+
model?: ModelConfig;
|
|
1548
|
+
/** Maximum cost per run in USD. */
|
|
1549
|
+
costCap?: number;
|
|
1550
|
+
/** Maximum total surgeon cost in the last 24 hours. */
|
|
1551
|
+
dailyCostCap?: number;
|
|
1552
|
+
/** Context token limit override. */
|
|
1553
|
+
contextLimit?: number;
|
|
1554
|
+
/** Custom instructions appended to the surgeon system prompt. */
|
|
1555
|
+
customInstructions?: string;
|
|
1556
|
+
/** Per-pass configuration. */
|
|
1557
|
+
passes?: {
|
|
1558
|
+
retirement?: SurgeonPassConfig;
|
|
1559
|
+
};
|
|
1560
|
+
}
|
|
1561
|
+
/**
|
|
1562
|
+
* Persisted config overrides for optional claim-key extraction.
|
|
1563
|
+
*/
|
|
1564
|
+
interface AgenrClaimExtractionConfig extends Partial<ClaimExtractionConfig> {
|
|
1565
|
+
/** Model override for claim-key extraction. */
|
|
1566
|
+
model?: ModelConfig;
|
|
1567
|
+
}
|
|
1568
|
+
/**
|
|
1569
|
+
* Raw persisted agenr config shape as it appears on disk.
|
|
1570
|
+
*/
|
|
1571
|
+
interface AgenrConfigInput {
|
|
1572
|
+
/** Selected auth method for the default extraction provider. */
|
|
1573
|
+
auth?: AgenrAuthMethod;
|
|
1574
|
+
/** Default LLM provider. */
|
|
1575
|
+
provider?: string;
|
|
1576
|
+
/** Default model for LLM tasks. */
|
|
1577
|
+
model?: string;
|
|
1578
|
+
/** Stored manual credentials. */
|
|
1579
|
+
credentials?: AgenrStoredCredentials;
|
|
1580
|
+
/** Embedding model override. */
|
|
1581
|
+
embeddingModel?: string;
|
|
1582
|
+
/** Prompt context appended to extraction requests. */
|
|
1583
|
+
extractionContext?: string;
|
|
1584
|
+
/** Model override for extraction. */
|
|
1585
|
+
extractionModel?: ModelConfig;
|
|
1586
|
+
/** Model override for dedup. */
|
|
1587
|
+
dedupModel?: ModelConfig;
|
|
1588
|
+
/** Model override for episode summaries. */
|
|
1589
|
+
episodeModel?: ModelConfig;
|
|
1590
|
+
/**
|
|
1591
|
+
* Model override for the cross-encoder rerank stage.
|
|
1592
|
+
*
|
|
1593
|
+
* The cross-encoder requires OpenAI chat completions with
|
|
1594
|
+
* `logprobs`/`logit_bias` support. Set `provider` to `openai` and
|
|
1595
|
+
* `model` to any model with logprob support (for example
|
|
1596
|
+
* `gpt-4.1-nano`).
|
|
1597
|
+
*/
|
|
1598
|
+
crossEncoderModel?: ModelConfig;
|
|
1599
|
+
/** Best-effort claim-key extraction settings. */
|
|
1600
|
+
claimExtraction?: AgenrClaimExtractionConfig;
|
|
1601
|
+
/** Surgeon module configuration. */
|
|
1602
|
+
surgeon?: SurgeonConfig;
|
|
1603
|
+
/** Staged rollout feature flags. All default to false. */
|
|
1604
|
+
features?: AgenrFeatureFlagConfig;
|
|
1605
|
+
/** Database file path. */
|
|
1606
|
+
dbPath?: string;
|
|
1607
|
+
/** HTTP API port. */
|
|
1608
|
+
apiPort?: number;
|
|
1609
|
+
}
|
|
1610
|
+
/**
|
|
1611
|
+
* Backward-compatible alias for the persisted config shape.
|
|
1612
|
+
*/
|
|
1613
|
+
type AgenrConfig = AgenrConfigInput;
|
|
1614
|
+
|
|
1615
|
+
/**
|
|
1616
|
+
* Stable failure codes returned by the goal-continuation boundary.
|
|
1617
|
+
*/
|
|
1618
|
+
type GoalContinuationErrorCode = "feature_disabled" | "host_callback_missing";
|
|
1619
|
+
/** Failed goal-continuation service result. */
|
|
1620
|
+
interface GoalContinuationFailure {
|
|
1621
|
+
/** Failure discriminator. */
|
|
1622
|
+
ok: false;
|
|
1623
|
+
/** Stable failure code. */
|
|
1624
|
+
code: GoalContinuationErrorCode;
|
|
1625
|
+
/** Human-readable failure message. */
|
|
1626
|
+
message: string;
|
|
1627
|
+
}
|
|
1628
|
+
/**
|
|
1629
|
+
* Successful host-owned goal-continuation result.
|
|
1630
|
+
*/
|
|
1631
|
+
interface GoalContinuationSuccess {
|
|
1632
|
+
/** Success discriminator. */
|
|
1633
|
+
ok: true;
|
|
1634
|
+
/** Optional host-authored result message. */
|
|
1635
|
+
message?: string;
|
|
1636
|
+
}
|
|
1637
|
+
/** Result returned by the goal-continuation boundary. */
|
|
1638
|
+
type GoalContinuationResult = GoalContinuationSuccess | GoalContinuationFailure;
|
|
1639
|
+
/**
|
|
1640
|
+
* Goal-continuation service surface.
|
|
1641
|
+
*/
|
|
1642
|
+
interface GoalContinuationService {
|
|
1643
|
+
/**
|
|
1644
|
+
* Routes future `/goal` or host-equivalent continuation commands to the host.
|
|
1645
|
+
*
|
|
1646
|
+
* @param params - Host command payload reserved for later phases.
|
|
1647
|
+
* @returns A fail-closed result unless a host callback is registered.
|
|
1648
|
+
*/
|
|
1649
|
+
runCommand(params: {
|
|
1650
|
+
command: string;
|
|
1651
|
+
}): Promise<GoalContinuationResult>;
|
|
1652
|
+
}
|
|
1653
|
+
|
|
1654
|
+
/** Resolved runtime capability state for one feature surface. */
|
|
1655
|
+
type RuntimeCapabilityState = "enabled" | "disabled" | "misconfigured";
|
|
1656
|
+
/** Derived runtime capabilities resolved once per host adapter startup. */
|
|
1657
|
+
interface RuntimeCapabilities {
|
|
1658
|
+
/** Working-memory ledger and tool surface. */
|
|
1659
|
+
workingMemory: RuntimeCapabilityState;
|
|
1660
|
+
/** Session-memory lifecycle intake and persistence. */
|
|
1661
|
+
sessionMemory: RuntimeCapabilityState;
|
|
1662
|
+
/** Whether shutdown lifecycle hooks may attempt bounded episode writes. */
|
|
1663
|
+
shutdownEpisodes: boolean;
|
|
1664
|
+
/** Goal-continuation host contract surface. */
|
|
1665
|
+
goalContinuation: RuntimeCapabilityState;
|
|
1666
|
+
}
|
|
1667
|
+
|
|
1668
|
+
/** Unified runtime policy resolved once per host adapter startup. */
|
|
1669
|
+
interface RuntimePolicy {
|
|
1670
|
+
/** Fully resolved runtime feature flags. */
|
|
1671
|
+
featureFlags: AgenrFeatureFlags;
|
|
1672
|
+
/** Derived capability map for host adapters. */
|
|
1673
|
+
capabilities: RuntimeCapabilities;
|
|
1674
|
+
/** Optional host memory-policy overrides for prompt injection. */
|
|
1675
|
+
memoryPolicy?: PluginInjectionMemoryPolicyConfig;
|
|
1676
|
+
}
|
|
1677
|
+
|
|
1678
|
+
/**
|
|
1679
|
+
* Host-facing memory surface exposed on plugin runtime services.
|
|
1680
|
+
*/
|
|
1681
|
+
interface AgenrHostMemorySurface {
|
|
1682
|
+
/** Feature-gated working-memory service used by host tools and projections. */
|
|
1683
|
+
workingMemory: WorkingMemoryService;
|
|
1684
|
+
/** Goal-continuation service for host-owned /goal runtime parity. */
|
|
1685
|
+
goalContinuation: GoalContinuationService;
|
|
1686
|
+
/**
|
|
1687
|
+
* Routes session-memory lifecycle triggers through feature gates and persistence.
|
|
1688
|
+
*
|
|
1689
|
+
* @param event - Host lifecycle event.
|
|
1690
|
+
* @returns Accepted intake result when enabled and configured, otherwise a fail-closed rejection.
|
|
1691
|
+
*/
|
|
1692
|
+
routeSessionMemoryTrigger(event: SessionMemoryTriggerEvent): Promise<SessionMemoryTriggerResult>;
|
|
1693
|
+
}
|
|
1694
|
+
|
|
1695
|
+
/**
|
|
1696
|
+
* Runtime configuration accepted by the agenr Skeln adapter.
|
|
1697
|
+
*
|
|
1698
|
+
* Infrastructure fields point the plugin at the shared agenr database and
|
|
1699
|
+
* config file on disk. Embeddings and claim extraction resolve from agenr
|
|
1700
|
+
* config credentials, not Skeln host auth.
|
|
1701
|
+
*/
|
|
1702
|
+
interface AgenrSkelnConfig extends PluginPathConfig {
|
|
1703
|
+
/** Narrow runtime memory-policy overrides for claim-aware read surfaces. */
|
|
1704
|
+
memoryPolicy?: PluginInjectionMemoryPolicyConfig;
|
|
1705
|
+
/** Optional Skeln host feature-flag overrides merged over agenr config features. */
|
|
1706
|
+
featureFlags?: AgenrFeatureFlagConfig;
|
|
1707
|
+
}
|
|
1708
|
+
/**
|
|
1709
|
+
* Shared Skeln runtime services composed outside the adapter package.
|
|
1710
|
+
*/
|
|
1711
|
+
interface AgenrSkelnServices extends PluginMemoryRuntimeServices, AgenrHostMemorySurface {
|
|
1712
|
+
config: ResolvedPluginPaths;
|
|
1713
|
+
skelnConfig: AgenrSkelnConfig;
|
|
1714
|
+
agenrConfig: AgenrConfig;
|
|
1715
|
+
/** Derived runtime capabilities resolved once at startup. */
|
|
1716
|
+
capabilities: RuntimePolicy["capabilities"];
|
|
1717
|
+
/** Unified runtime policy resolved once at startup. */
|
|
1718
|
+
runtimePolicy: RuntimePolicy;
|
|
1719
|
+
}
|
|
1720
|
+
|
|
1721
|
+
/**
|
|
1722
|
+
* Creates the shared Skeln runtime services used by the plugin process.
|
|
1723
|
+
*
|
|
1724
|
+
* @param config - Optional plugin config with path overrides and memory policy.
|
|
1725
|
+
* @returns Shared services reused for the process lifetime.
|
|
1726
|
+
*/
|
|
1727
|
+
declare function createAgenrSkelnServices(config?: AgenrSkelnConfig): Promise<AgenrSkelnServices>;
|
|
1728
|
+
|
|
1729
|
+
/** Trusted Skeln host surfaces allowed to bypass model-facing work-tool limits. */
|
|
1730
|
+
type AgenrSkelnWorkCommandSource = TrustedHostMutationSource;
|
|
1731
|
+
/** Shared trusted mutation metadata for Skeln work-command calls. */
|
|
1732
|
+
interface AgenrSkelnWorkCommandMutationMetadata {
|
|
1733
|
+
/** Actor that initiated the trusted host command. */
|
|
1734
|
+
actor?: AgenrWorkMutationActor;
|
|
1735
|
+
/** Trusted host surface that emitted the command. */
|
|
1736
|
+
source: AgenrSkelnWorkCommandSource;
|
|
1737
|
+
}
|
|
1738
|
+
/** Read command accepted by the trusted Skeln work-command controller. */
|
|
1739
|
+
interface AgenrSkelnWorkGetCommandParams {
|
|
1740
|
+
/** Read the current working set. */
|
|
1741
|
+
action: "get";
|
|
1742
|
+
/** Explicit working-set id when known. */
|
|
1743
|
+
workingSetId?: string;
|
|
1744
|
+
/** Raw scope facts supplied by Skeln. */
|
|
1745
|
+
scope?: Partial<WorkingScope>;
|
|
1746
|
+
/** Whether recent event details should be included. */
|
|
1747
|
+
includeEvents?: boolean;
|
|
1748
|
+
/** Maximum event count to include. */
|
|
1749
|
+
eventLimit?: number;
|
|
1750
|
+
}
|
|
1751
|
+
/** List command accepted by the trusted Skeln work-command controller. */
|
|
1752
|
+
interface AgenrSkelnWorkListCommandParams {
|
|
1753
|
+
/** List working sets. */
|
|
1754
|
+
action: "list";
|
|
1755
|
+
/** Raw scope facts supplied by Skeln. */
|
|
1756
|
+
scope?: Partial<WorkingScope>;
|
|
1757
|
+
/** Maximum working sets to return. */
|
|
1758
|
+
listLimit?: number;
|
|
1759
|
+
}
|
|
1760
|
+
/** Create command accepted by the trusted Skeln work-command controller. */
|
|
1761
|
+
interface AgenrSkelnWorkCreateCommandParams extends AgenrSkelnWorkCommandMutationMetadata {
|
|
1762
|
+
/** Create one scoped working set. */
|
|
1763
|
+
action: "create";
|
|
1764
|
+
/** Raw scope facts supplied by Skeln. */
|
|
1765
|
+
scope?: Partial<WorkingScope>;
|
|
1766
|
+
/** Initial objective operation. */
|
|
1767
|
+
operation: Extract<AgenrWorkUpdateOperation, {
|
|
1768
|
+
type: "set_objective";
|
|
1769
|
+
}>;
|
|
1770
|
+
/** Human-readable audit reason. */
|
|
1771
|
+
updateReason: string;
|
|
1772
|
+
/** Initial budget state supplied by the trusted host command. */
|
|
1773
|
+
initialBudget?: WorkingBudgetState;
|
|
1774
|
+
/** Initial continuation policy supplied by trusted Skeln `/goal set`. */
|
|
1775
|
+
continuationPolicy?: WorkingContinuationPolicy;
|
|
1776
|
+
}
|
|
1777
|
+
/** Update command accepted by the trusted Skeln work-command controller. */
|
|
1778
|
+
interface AgenrSkelnWorkUpdateCommandParams extends AgenrSkelnWorkCommandMutationMetadata {
|
|
1779
|
+
/** Update an existing working set. */
|
|
1780
|
+
action: "update";
|
|
1781
|
+
/** Explicit working-set id when known. */
|
|
1782
|
+
workingSetId?: string;
|
|
1783
|
+
/** Raw scope facts supplied by Skeln. */
|
|
1784
|
+
scope?: Partial<WorkingScope>;
|
|
1785
|
+
/** Revision observed before mutation. Omit to inherit the selected working-set revision. */
|
|
1786
|
+
expectedRevision?: number;
|
|
1787
|
+
/** Granular mutation operation. */
|
|
1788
|
+
operation: AgenrWorkUpdateOperation;
|
|
1789
|
+
/** Human-readable audit reason. */
|
|
1790
|
+
updateReason: string;
|
|
1791
|
+
}
|
|
1792
|
+
/** Close command accepted by the trusted Skeln work-command controller. */
|
|
1793
|
+
interface AgenrSkelnWorkCloseCommandParams extends AgenrSkelnWorkCommandMutationMetadata {
|
|
1794
|
+
/** Close or abandon an existing working set. */
|
|
1795
|
+
action: "close";
|
|
1796
|
+
/** Explicit working-set id when known. */
|
|
1797
|
+
workingSetId?: string;
|
|
1798
|
+
/** Raw scope facts supplied by Skeln. */
|
|
1799
|
+
scope?: Partial<WorkingScope>;
|
|
1800
|
+
/** Revision observed before close. Omit to inherit the selected working-set revision. */
|
|
1801
|
+
expectedRevision?: number;
|
|
1802
|
+
/** User-visible close reason. */
|
|
1803
|
+
closeReason: string;
|
|
1804
|
+
/** Explicit terminal close intent. */
|
|
1805
|
+
closeMode?: AgenrWorkCloseMode;
|
|
1806
|
+
/** Whether close should request episode creation when thresholds pass. */
|
|
1807
|
+
createEpisode?: boolean;
|
|
1808
|
+
}
|
|
1809
|
+
/** Prepare command accepted before trusted external goal mutations. */
|
|
1810
|
+
interface AgenrSkelnWorkPrepareExternalGoalMutationCommandParams extends AgenrSkelnWorkCommandMutationMetadata {
|
|
1811
|
+
/** Account progress before a host mutates goal state externally. */
|
|
1812
|
+
action: "prepare_external_goal_mutation";
|
|
1813
|
+
/** External mutation that is about to run. */
|
|
1814
|
+
mutationKind: WorkingExternalGoalMutationKind;
|
|
1815
|
+
/** Explicit working-set id when known. */
|
|
1816
|
+
workingSetId?: string;
|
|
1817
|
+
/** Raw scope facts supplied by Skeln. */
|
|
1818
|
+
scope?: Partial<WorkingScope>;
|
|
1819
|
+
/** Optional checkpoint to merge before the external mutation. */
|
|
1820
|
+
checkpoint?: WorkingCheckpoint;
|
|
1821
|
+
/** Optional usage delta to account before the external mutation. */
|
|
1822
|
+
usage?: WorkingUsageDelta;
|
|
1823
|
+
/** Whether an active goal must have a checkpoint before the mutation proceeds. */
|
|
1824
|
+
requireCheckpoint?: boolean;
|
|
1825
|
+
/** Optional audit reason used for generated accounting writes. */
|
|
1826
|
+
updateReason?: string;
|
|
1827
|
+
}
|
|
1828
|
+
/** Trusted command params accepted by the Skeln controller. */
|
|
1829
|
+
type AgenrSkelnWorkCommandParams = AgenrSkelnWorkGetCommandParams | AgenrSkelnWorkListCommandParams | AgenrSkelnWorkCreateCommandParams | AgenrSkelnWorkUpdateCommandParams | AgenrSkelnWorkCloseCommandParams | AgenrSkelnWorkPrepareExternalGoalMutationCommandParams;
|
|
1830
|
+
/** Trusted working-memory command result returned to Skeln UI code. */
|
|
1831
|
+
interface AgenrSkelnWorkCommandOutcome {
|
|
1832
|
+
/** Text formatted the same way as the model-facing agenr_work tool. */
|
|
1833
|
+
text: string;
|
|
1834
|
+
/** Structured details formatted the same way as the model-facing agenr_work tool. */
|
|
1835
|
+
details: Record<string, unknown>;
|
|
1836
|
+
/** True when Agenr returned a failed working-memory result. */
|
|
1837
|
+
failed: boolean;
|
|
1838
|
+
}
|
|
1839
|
+
/** Trusted host command capability returned by {@link registerAgenrSkelnMemory}. */
|
|
1840
|
+
interface AgenrSkelnMemoryController {
|
|
1841
|
+
/**
|
|
1842
|
+
* Executes a working-memory command from trusted Skeln UI or lifecycle code.
|
|
1843
|
+
*
|
|
1844
|
+
* @param context - Active Skeln extension context.
|
|
1845
|
+
* @param params - Working-memory params supplied by the trusted host command.
|
|
1846
|
+
* @returns Host-neutral working-memory outcome.
|
|
1847
|
+
*/
|
|
1848
|
+
executeWorkCommand(context: ExtensionContext, params: AgenrSkelnWorkCommandParams): Promise<AgenrSkelnWorkCommandOutcome>;
|
|
1849
|
+
}
|
|
1850
|
+
|
|
1851
|
+
/**
|
|
1852
|
+
* Structured tracking facts returned by the session-start tracker.
|
|
1853
|
+
*/
|
|
1854
|
+
interface SessionStartConsumeResult {
|
|
1855
|
+
/**
|
|
1856
|
+
* Reports whether the caller should run session-start recall.
|
|
1857
|
+
*/
|
|
1858
|
+
isFirst: boolean;
|
|
1859
|
+
/**
|
|
1860
|
+
* Reports how many distinct session identities are currently tracked.
|
|
1861
|
+
*/
|
|
1862
|
+
activeCount: number;
|
|
1863
|
+
}
|
|
1864
|
+
/**
|
|
1865
|
+
* Tracks which host sessions have already consumed session-start recall.
|
|
1866
|
+
*/
|
|
1867
|
+
interface SessionStartTracker {
|
|
1868
|
+
/**
|
|
1869
|
+
* Marks a session as started and reports whether this is the first start signal.
|
|
1870
|
+
*
|
|
1871
|
+
* @param sessionId - Ephemeral host session identifier when available.
|
|
1872
|
+
* @param sessionKey - Stable host session key fallback.
|
|
1873
|
+
* @returns Tracking facts for the attempted session-start event.
|
|
1874
|
+
*/
|
|
1875
|
+
consume(sessionId?: string, sessionKey?: string): SessionStartConsumeResult;
|
|
1876
|
+
/**
|
|
1877
|
+
* Remembers a session-start transition emitted by the host.
|
|
1878
|
+
*
|
|
1879
|
+
* @param sessionId - New ephemeral host session identifier.
|
|
1880
|
+
* @param sessionKey - Stable host session key for the active lane.
|
|
1881
|
+
* @param resumedFrom - Previous session identifier when the host provides it.
|
|
1882
|
+
*/
|
|
1883
|
+
rememberSessionStart(sessionId?: string, sessionKey?: string, resumedFrom?: string): void;
|
|
1884
|
+
/**
|
|
1885
|
+
* Returns the predecessor session identifier remembered for a new session.
|
|
1886
|
+
*
|
|
1887
|
+
* @param sessionId - New ephemeral host session identifier lookup.
|
|
1888
|
+
* @returns Previous session identifier, or `undefined` when unavailable.
|
|
1889
|
+
*/
|
|
1890
|
+
getResumedFrom(sessionId?: string): string | undefined;
|
|
1891
|
+
}
|
|
1892
|
+
|
|
1893
|
+
/** Describes one agenr memory surface observed during a prompt turn. */
|
|
1894
|
+
type MemoryTraceKind = "working_context" | "session_start_recall" | "before_turn_recall" | "system_prompt";
|
|
1895
|
+
/** Describes whether a memory surface changed provider context for the turn. */
|
|
1896
|
+
type MemoryTraceAction = "injected" | "skipped" | "failed";
|
|
1897
|
+
/** Structured audit event for one agenr memory decision on a turn. */
|
|
1898
|
+
interface MemoryTraceEvent {
|
|
1899
|
+
kind: MemoryTraceKind;
|
|
1900
|
+
action: MemoryTraceAction;
|
|
1901
|
+
reason?: string;
|
|
1902
|
+
bytes?: number;
|
|
1903
|
+
summary?: string;
|
|
1904
|
+
preview?: string;
|
|
1905
|
+
workingSetId?: string;
|
|
1906
|
+
revision?: number;
|
|
1907
|
+
sourceRef?: string;
|
|
1908
|
+
}
|
|
1909
|
+
|
|
1910
|
+
/** Skeln before_agent_start event payload used by the agenr adapter. */
|
|
1911
|
+
interface AgenrSkelnBeforeAgentStartEvent {
|
|
1912
|
+
type: "before_agent_start";
|
|
1913
|
+
prompt: string;
|
|
1914
|
+
systemPrompt: string;
|
|
1915
|
+
}
|
|
1916
|
+
/** Skeln before_agent_start result payload returned by the agenr adapter. */
|
|
1917
|
+
interface AgenrSkelnBeforeAgentStartResult {
|
|
1918
|
+
message?: AgentMessage;
|
|
1919
|
+
messages?: AgentMessage[];
|
|
1920
|
+
transientMessages?: AgentMessage[];
|
|
1921
|
+
workingContextAudit?: WorkingContextAuditPointer;
|
|
1922
|
+
memoryTrace?: MemoryTraceEvent[];
|
|
1923
|
+
systemPrompt?: string;
|
|
1924
|
+
}
|
|
1925
|
+
/** Dependencies required by the Skeln before_agent_start handler. */
|
|
1926
|
+
interface AgenrSkelnBeforeAgentStartDeps {
|
|
1927
|
+
servicesPromise: Promise<AgenrSkelnServices>;
|
|
1928
|
+
sessionStartTracker: SessionStartTracker;
|
|
1929
|
+
resolveScope: (context: ExtensionContext) => Promise<AgenrSkelnSessionScope>;
|
|
1930
|
+
}
|
|
1931
|
+
/**
|
|
1932
|
+
* Runs agenr session-start or before-turn recall and injects the result into one Skeln turn.
|
|
1933
|
+
*
|
|
1934
|
+
* @param event - Current before-agent-start payload from Skeln.
|
|
1935
|
+
* @param context - Active extension context with session branch access.
|
|
1936
|
+
* @param deps - Shared services, session-start tracker, and scope resolver.
|
|
1937
|
+
* @returns Hidden user messages, transient working context, and optional system-prompt mutation.
|
|
1938
|
+
*/
|
|
1939
|
+
declare function handleAgenrSkelnBeforeAgentStart(event: AgenrSkelnBeforeAgentStartEvent, context: ExtensionContext, deps: AgenrSkelnBeforeAgentStartDeps): Promise<AgenrSkelnBeforeAgentStartResult>;
|
|
1940
|
+
|
|
1941
|
+
/**
|
|
1942
|
+
* Registers agenr durable-memory tools and lifecycle hooks on a Skeln extension API.
|
|
1943
|
+
*
|
|
1944
|
+
* @param skeln - Skeln extension API for the active runtime.
|
|
1945
|
+
* @param options - Optional path overrides and host scope callback.
|
|
1946
|
+
*/
|
|
1947
|
+
declare function registerAgenrSkelnMemory(skeln: ExtensionAPI, options?: RegisterAgenrSkelnMemoryOptions): AgenrSkelnMemoryController;
|
|
1948
|
+
/** Default Skeln extension factory for direct `@agenr/skeln-plugin` loads. */
|
|
1949
|
+
declare function extension(skeln: ExtensionAPI): void;
|
|
1950
|
+
|
|
1951
|
+
export { type AgenrSkelnConfig, type AgenrSkelnMemoryController, type AgenrSkelnServices, type AgenrSkelnSessionScope, type AgenrSkelnWorkCloseCommandParams, type AgenrSkelnWorkCommandMutationMetadata, type AgenrSkelnWorkCommandOutcome, type AgenrSkelnWorkCommandParams, type AgenrSkelnWorkCommandSource, type AgenrSkelnWorkCreateCommandParams, type AgenrSkelnWorkGetCommandParams, type AgenrSkelnWorkListCommandParams, type AgenrSkelnWorkPrepareExternalGoalMutationCommandParams, type AgenrSkelnWorkUpdateCommandParams, type RegisterAgenrSkelnMemoryOptions, type SkelnHostContext, createAgenrSkelnServices, extension as default, handleAgenrSkelnBeforeAgentStart, registerAgenrSkelnMemory };
|