@melite/estate-drafts 0.0.0-stage → 0.1.5-pre-alpha

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/lib/bench.d.ts ADDED
@@ -0,0 +1,376 @@
1
+ import type { Domain } from "@deepseek-ai/dsh-storage-domain";
2
+ import type { DraftsDomainSpec } from "./spec.js";
3
+ import type { JsonValue } from "./remote.js";
4
+ /** The bench's Remote failure codes, merged into the protocol's one
5
+ * vocabulary (cookbook §2: declaration merging, next to the throw). */
6
+ declare module "@deepseek-ai/dsh-typert-protocol" {
7
+ interface RemoteErrorDetailsMap {
8
+ /** The session key fails the [A-Za-z0-9_-]{1,64} bench law. */
9
+ "bench/bad-session": Record<string, never>;
10
+ /** The body failed the bench contract (non-object / unknown keys). */
11
+ "bench/bad-body": Record<string, never>;
12
+ /** THE MODEL ADMISSION (no-silent-drop law, hour 26 stroke 17):
13
+ * the stage's model is not offered by the card, or boarded but
14
+ * not downloaded on this machine — the write refuses with the
15
+ * card + the offered (present) models. */
16
+ "bench/bad-model": {
17
+ readonly card: string;
18
+ readonly offered: readonly string[];
19
+ };
20
+
21
+
22
+
23
+
24
+
25
+
26
+ "bench/lane-refusal": {
27
+ readonly card: string;
28
+ };
29
+ /** The CAS law: expect_rev missing, or the bench moved under the
30
+ * caller — current_rev is the rev to re-read from. */
31
+ "bench/cas-conflict": {
32
+ readonly current_rev: number;
33
+ readonly expect_rev?: number;
34
+ };
35
+
36
+
37
+
38
+ "bench/overwrite-required": {
39
+ readonly current_rev: number;
40
+ readonly stages: number;
41
+ };
42
+ /** No bench doc carries that session. */
43
+ "bench/not-found": {
44
+ readonly session: string;
45
+ };
46
+ /** No stage of that id sits on the bench. */
47
+ "bench/stage-not-found": {
48
+ readonly session: string;
49
+ readonly stage: string;
50
+ };
51
+ /** The anchored reorder's target is gone (the F1-residue cure,
52
+ * round 25): the id the drop named as its anchor is not on the
53
+ * CURRENT list — a second author removed it between the press
54
+ * and the apply. The honest re-ask, never a silent fallback to
55
+ * the stale numeric slot. */
56
+ "bench/anchor-gone": {
57
+ readonly session: string;
58
+ readonly anchor: string;
59
+ };
60
+
61
+
62
+
63
+ "bench/bad-wire": {
64
+ readonly session: string;
65
+ readonly stage: string;
66
+ readonly input: string;
67
+ };
68
+ /** A stage wired to itself — a cycle composes nothing. */
69
+ "bench/self-wire": {
70
+ readonly session: string;
71
+ readonly stage: string;
72
+ readonly input: string;
73
+ };
74
+ /** A wiring input pointing at a stage id not on the bench (the
75
+ * phantom-upstream cure: 'stage-1' never existed; the mint
76
+ * mints s_N). */
77
+ "bench/wire-stage-not-found": {
78
+ readonly session: string;
79
+ readonly stage: string;
80
+ readonly input: string;
81
+ readonly live: readonly string[];
82
+ };
83
+
84
+
85
+
86
+ "bench/grouped-row-wired": {
87
+ readonly session: string;
88
+ readonly stage: string;
89
+ };
90
+ /** A wiring channel no param spells ($channel) — the wiring
91
+ * feeds nothing and the run would silently ignore it. */
92
+ "bench/dead-wire": {
93
+ readonly session: string;
94
+ readonly stage: string;
95
+ readonly input: string;
96
+ };
97
+ /** A stage of that id is already on the bench. */
98
+ "bench/duplicate-stage": {
99
+ readonly session: string;
100
+ readonly stage: string;
101
+ };
102
+ /** The undo walk found no live, filter-matching action. */
103
+ "bench/nothing-to-undo": Record<string, never>;
104
+ /** The storage open refused an otherwise valid call. */
105
+ "bench/store-failed": Record<string, never>;
106
+ }
107
+ }
108
+
109
+
110
+
111
+
112
+
113
+
114
+
115
+
116
+
117
+
118
+ import { SESSION_RE } from "@melite/contracts/benchStage";
119
+ export { SESSION_RE };
120
+ declare const AUTHORS: readonly ["agent", "user"];
121
+ type Author = (typeof AUTHORS)[number];
122
+ interface BenchEntry {
123
+ /** Filled by the persister (rev/at are the domain's, not the caller's). */
124
+ rev: number;
125
+ at: number;
126
+ author: Author;
127
+ kind: "patch" | "add_stage" | "remove_stage" | "rewire" | "reorder" | "group" | "ungroup" | "load" | "clear" | "undo";
128
+ stage?: string;
129
+ summary?: string;
130
+ /** Kind-specific inverse payload (undo applies it). */
131
+ inverse?: Record<string, unknown>;
132
+ /** Filled on undo entries: the revs this entry reverted. */
133
+ reverted?: number[];
134
+ }
135
+ export interface BenchBlock {
136
+ rev: number;
137
+ log: BenchEntry[];
138
+ }
139
+ export declare function benchBlockOf(doc: Record<string, unknown>): BenchBlock;
140
+
141
+
142
+
143
+
144
+
145
+
146
+
147
+
148
+
149
+
150
+
151
+
152
+
153
+
154
+ export declare function mintStageId(rows: readonly Record<string, unknown>[], body: Record<string, unknown>): string;
155
+ /** Birth defaults per the composer's law (id, inputs, provenance)
156
+ * with the runner's object inputs. */
157
+ export declare function normalizeStages(stagesIn: unknown, author: Author): Record<string, unknown>[];
158
+ /** The ensure row: create marker, rev, intent, stages. */
159
+ export interface BenchEnsureRow {
160
+ readonly draft_id: string;
161
+ readonly session: string;
162
+ readonly rev: number;
163
+ readonly intent: JsonValue;
164
+ readonly stages: JsonValue;
165
+ readonly created: boolean;
166
+ }
167
+ /** The get row: the bench as it stands, log HEADS only (rev/at /
168
+ * author / kind / stage / summary / reverted — inverses never
169
+ * leave the domain). */
170
+ export interface BenchGetRow {
171
+ readonly draft_id: string;
172
+ readonly session: string;
173
+ readonly rev: number;
174
+ readonly intent: JsonValue;
175
+ readonly stages: JsonValue;
176
+ readonly log: readonly {
177
+ readonly [key: string]: JsonValue;
178
+ }[];
179
+ }
180
+ export declare function ensureBench(drafts: Domain<DraftsDomainSpec>, body: Record<string, unknown>, admit?: StageAdmission): Promise<BenchEnsureRow>;
181
+ /** get — one session's bench block as the served row. */
182
+ export declare function getBench(drafts: Domain<DraftsDomainSpec>, session: string): BenchGetRow;
183
+ /** The patch row: the touched stage + the params keys merged. */
184
+ export interface BenchPatchRow {
185
+ readonly draft_id: string;
186
+ readonly session: string;
187
+ readonly rev: number;
188
+ readonly stage: string;
189
+ readonly patched: readonly string[];
190
+ }
191
+
192
+
193
+
194
+
195
+
196
+
197
+
198
+
199
+
200
+ export declare function patchBench(drafts: Domain<DraftsDomainSpec>, session: string, body: Record<string, unknown>, admit?: StageAdmission, migrate?: LaneMigration): Promise<BenchPatchRow>;
201
+ /** The stage row: the arm's answer (stage id + rev). */
202
+ export interface BenchStageRow {
203
+ readonly draft_id: string;
204
+ readonly session: string;
205
+ readonly rev: number;
206
+ readonly stage: string;
207
+ }
208
+
209
+
210
+
211
+
212
+
213
+
214
+
215
+
216
+
217
+
218
+
219
+
220
+
221
+
222
+
223
+ export type StageAdmission = (card: string, params: Record<string, unknown>, provenance: unknown) => void;
224
+
225
+
226
+
227
+
228
+
229
+
230
+
231
+ export type LaneMigration = (card: string, params: Record<string, unknown>, priorParams: Record<string, unknown>) => Record<string, unknown>;
232
+
233
+
234
+
235
+
236
+
237
+ export declare function strippedForAdmission(card: string, params: Record<string, unknown>): Record<string, unknown>;
238
+ /** The wiring admission over ONE row (params = the MERGED view the
239
+ * next run composes; inputs = the MERGED wiring; liveIds = the
240
+ * bench's stage ids after the write; selfId = the row's own id —
241
+ * self-wiring is a cycle, refused). Throws bench/* named. */
242
+ export declare function admitWiring(row: Record<string, unknown>, params: Record<string, unknown>, inputs: Record<string, unknown>, liveIds: readonly string[], selfId: string, session: string, tolerate?: ReadonlySet<string>): void;
243
+ /** The un-wedge law's tolerance table: for every row in the list
244
+ * being JUDGED, the upstreams it wires that are absent from the
245
+ * PRE-verb live set — refs the verb did not create (they were
246
+ * already dead, or ride a restored snapshot the log itself
247
+ * recorded) and must not be refused for. Keyed by row/child id.
248
+ *
249
+ * The walk is over the JUDGED rows (not the pre rows): a verb
250
+ * like clear leaves no pre rows at all, and undo restores rows
251
+ * the pre state doesn't hold — the ref a row CARRIES is the
252
+ * thing to classify, against what was live before the verb. A
253
+ * ref newly introduced by a verb (rewire's `from`, a patch's
254
+ * spell changes) never rides this table: those seats build their
255
+ * tolerate sets from the PRE ROW's own inputs, so a fresh dead
256
+ * target stays strict. */
257
+ /** Exported for the drafts seat (audit S-S1): the un-wedge table is
258
+ * the same law at every author seat. */
259
+ export declare function toleratedByRow(stages: Array<Record<string, unknown>>, preLive: ReadonlySet<string>): Map<string, Set<string>>;
260
+ /** add_stage — append a card stage with optional wiring (the
261
+ * runner's input convention rides the row). */
262
+ export declare function addStageBench(drafts: Domain<DraftsDomainSpec>, session: string, body: Record<string, unknown>, admit?: StageAdmission): Promise<BenchStageRow>;
263
+
264
+
265
+
266
+
267
+
268
+
269
+
270
+
271
+
272
+
273
+
274
+
275
+
276
+ export declare function reorderBench(drafts: Domain<DraftsDomainSpec>, session: string, body: Record<string, unknown>): Promise<BenchReorderRow>;
277
+ /** The reorder row: the move's coordinates for the caller's optimistic
278
+ * update (from → to, both POST-splice-clamp). */
279
+ export interface BenchReorderRow {
280
+ readonly draft_id: string;
281
+ readonly session: string;
282
+ readonly rev: number;
283
+ readonly stage: string;
284
+ readonly from: number;
285
+ readonly to: number;
286
+ }
287
+
288
+
289
+
290
+
291
+
292
+
293
+ export declare function groupBench(drafts: Domain<DraftsDomainSpec>, session: string, body: Record<string, unknown>, admit?: StageAdmission | undefined): Promise<BenchStageRow>;
294
+ /** ungroup — the compound's door: spill the children back at the
295
+ * compound's index, in their stored order. */
296
+ export declare function ungroupBench(drafts: Domain<DraftsDomainSpec>, session: string, body: Record<string, unknown>, admit?: StageAdmission | undefined): Promise<BenchStageRow>;
297
+ /** remove_stage — splice one stage out (the inverse carries row +
298
+ * index for undo). */
299
+ export declare function removeStageBench(drafts: Domain<DraftsDomainSpec>, session: string, body: Record<string, unknown>): Promise<BenchStageRow>;
300
+ /** The clear row. */
301
+ export interface BenchClearRow {
302
+ readonly draft_id: string;
303
+ readonly session: string;
304
+ readonly rev: number;
305
+ readonly cleared: number;
306
+ }
307
+
308
+
309
+
310
+
311
+
312
+
313
+
314
+ export declare function clearBench(drafts: Domain<DraftsDomainSpec>, session: string, body: Record<string, unknown>): Promise<BenchClearRow>;
315
+ /** The rewire row. */
316
+ export interface BenchRewireRow {
317
+ readonly draft_id: string;
318
+ readonly session: string;
319
+ readonly rev: number;
320
+ readonly stage: string;
321
+ readonly input: string;
322
+ }
323
+ /** rewire — set or clear one input binding. from:
324
+ * {stage, output} | {initial: "image"} | absent → clear. */
325
+ export declare function rewireBench(drafts: Domain<DraftsDomainSpec>, session: string, body: Record<string, unknown>): Promise<BenchRewireRow>;
326
+ /** The undo row: the undone revs + the stages as they stand. */
327
+ export interface BenchUndoRow {
328
+ readonly draft_id: string;
329
+ readonly session: string;
330
+ readonly rev: number;
331
+ readonly undone: readonly number[];
332
+ readonly stages: JsonValue;
333
+ }
334
+ /** undo — walk the log tail, skip already-reverted entries and
335
+ * entries the author filter excludes, apply inverses
336
+ * newest-first, append ONE undo entry carrying the pre-undo
337
+ * snapshot. Undo entries are NEVER candidates — a plain undo
338
+ * walks ACTIONS (targeting them would ping-pong). */
339
+ export declare function undoBench(drafts: Domain<DraftsDomainSpec>, session: string, body: Record<string, unknown>, admit?: StageAdmission): Promise<BenchUndoRow>;
340
+ type BenchChangeListener = (session: string) => void;
341
+ /** The event seam this pure domain module reaches the bus through.
342
+ * `bench.ts` owns no Context (it is the domain layer, not a plugin),
343
+ * so the plugin installs the pair once and every writer here keeps
344
+ * calling {@link notifyBenchChange}. */
345
+ export interface BenchChangeSeam {
346
+ emit: (session: string) => void;
347
+ on: (fn: BenchChangeListener) => () => void;
348
+ }
349
+ /** Install the seam (the plugin does this with its Context; tests do
350
+ * it with their own). Pass null to detach. */
351
+ export declare function setBenchChangeSeam(seam: BenchChangeSeam | null): void;
352
+ /** Detach the seam ONLY if `seam` is still the installed one — the
353
+ * ownership stamp that keeps dispose honest: a fiber that installed
354
+ * EARLIER (a newer install displaced it) detaches nothing, so the
355
+ * live seam survives the older fiber's unwind.
356
+ * @param seam - the seam instance the caller installed.
357
+ */
358
+ export declare function clearBenchChangeSeam(seam: BenchChangeSeam): void;
359
+
360
+
361
+
362
+
363
+
364
+
365
+
366
+
367
+ export declare function onBenchChange(fn: BenchChangeListener): () => void;
368
+ /** Fire the write event — the remote layer calls this after every
369
+ * successful bench write (the door seam: every in-process and
370
+ * host-routed write crosses the remote arms). */
371
+ export declare function notifyBenchChange(session: string): void;
372
+ /** The public notify (the drafts-patch door writes bench docs from
373
+ * remote.ts — outside this module; it fires this with the session
374
+ * parsed from the bench-shaped draft id). */
375
+ export declare function notifyBenchDocWrite(draftId: string): void;
376
+ //# sourceMappingURL=bench.d.ts.map