@melite/estate-drafts 0.0.0-stage → 0.1.4-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,329 @@
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
+
52
+
53
+
54
+ "bench/bad-wire": {
55
+ readonly session: string;
56
+ readonly stage: string;
57
+ readonly input: string;
58
+ };
59
+ /** A stage wired to itself — a cycle composes nothing. */
60
+ "bench/self-wire": {
61
+ readonly session: string;
62
+ readonly stage: string;
63
+ readonly input: string;
64
+ };
65
+ /** A wiring input pointing at a stage id not on the bench (the
66
+ * phantom-upstream cure: 'stage-1' never existed; the mint
67
+ * mints s_N). */
68
+ "bench/wire-stage-not-found": {
69
+ readonly session: string;
70
+ readonly stage: string;
71
+ readonly input: string;
72
+ readonly live: readonly string[];
73
+ };
74
+
75
+
76
+
77
+ "bench/grouped-row-wired": {
78
+ readonly session: string;
79
+ readonly stage: string;
80
+ };
81
+ /** A wiring channel no param spells ($channel) — the wiring
82
+ * feeds nothing and the run would silently ignore it. */
83
+ "bench/dead-wire": {
84
+ readonly session: string;
85
+ readonly stage: string;
86
+ readonly input: string;
87
+ };
88
+ /** A stage of that id is already on the bench. */
89
+ "bench/duplicate-stage": {
90
+ readonly session: string;
91
+ readonly stage: string;
92
+ };
93
+ /** The undo walk found no live, filter-matching action. */
94
+ "bench/nothing-to-undo": Record<string, never>;
95
+ /** The storage open refused an otherwise valid call. */
96
+ "bench/store-failed": Record<string, never>;
97
+ }
98
+ }
99
+
100
+
101
+
102
+
103
+
104
+
105
+
106
+
107
+
108
+
109
+ import { SESSION_RE } from "@melite/contracts/benchStage";
110
+ export { SESSION_RE };
111
+ declare const AUTHORS: readonly ["agent", "user"];
112
+ type Author = (typeof AUTHORS)[number];
113
+ interface BenchEntry {
114
+ /** Filled by the persister (rev/at are the domain's, not the caller's). */
115
+ rev: number;
116
+ at: number;
117
+ author: Author;
118
+ kind: "patch" | "add_stage" | "remove_stage" | "rewire" | "reorder" | "group" | "ungroup" | "load" | "clear" | "undo";
119
+ stage?: string;
120
+ summary?: string;
121
+ /** Kind-specific inverse payload (undo applies it). */
122
+ inverse?: Record<string, unknown>;
123
+ /** Filled on undo entries: the revs this entry reverted. */
124
+ reverted?: number[];
125
+ }
126
+ export interface BenchBlock {
127
+ rev: number;
128
+ log: BenchEntry[];
129
+ }
130
+ export declare function benchBlockOf(doc: Record<string, unknown>): BenchBlock;
131
+
132
+
133
+
134
+
135
+
136
+
137
+
138
+
139
+
140
+
141
+
142
+
143
+
144
+
145
+ export declare function mintStageId(rows: readonly Record<string, unknown>[], body: Record<string, unknown>): string;
146
+ /** Birth defaults per the composer's law (id, inputs, provenance)
147
+ * with the runner's object inputs. */
148
+ export declare function normalizeStages(stagesIn: unknown, author: Author): Record<string, unknown>[];
149
+ /** The ensure row: create marker, rev, intent, stages. */
150
+ export interface BenchEnsureRow {
151
+ readonly draft_id: string;
152
+ readonly session: string;
153
+ readonly rev: number;
154
+ readonly intent: JsonValue;
155
+ readonly stages: JsonValue;
156
+ readonly created: boolean;
157
+ }
158
+ /** The get row: the bench as it stands, log HEADS only (rev/at /
159
+ * author / kind / stage / summary / reverted — inverses never
160
+ * leave the domain). */
161
+ export interface BenchGetRow {
162
+ readonly draft_id: string;
163
+ readonly session: string;
164
+ readonly rev: number;
165
+ readonly intent: JsonValue;
166
+ readonly stages: JsonValue;
167
+ readonly log: readonly {
168
+ readonly [key: string]: JsonValue;
169
+ }[];
170
+ }
171
+ export declare function ensureBench(drafts: Domain<DraftsDomainSpec>, body: Record<string, unknown>, admit?: StageAdmission): Promise<BenchEnsureRow>;
172
+ /** get — one session's bench block as the served row. */
173
+ export declare function getBench(drafts: Domain<DraftsDomainSpec>, session: string): BenchGetRow;
174
+ /** The patch row: the touched stage + the params keys merged. */
175
+ export interface BenchPatchRow {
176
+ readonly draft_id: string;
177
+ readonly session: string;
178
+ readonly rev: number;
179
+ readonly stage: string;
180
+ readonly patched: readonly string[];
181
+ }
182
+
183
+
184
+
185
+
186
+
187
+
188
+
189
+
190
+
191
+ export declare function patchBench(drafts: Domain<DraftsDomainSpec>, session: string, body: Record<string, unknown>, admit?: StageAdmission): Promise<BenchPatchRow>;
192
+ /** The stage row: the arm's answer (stage id + rev). */
193
+ export interface BenchStageRow {
194
+ readonly draft_id: string;
195
+ readonly session: string;
196
+ readonly rev: number;
197
+ readonly stage: string;
198
+ }
199
+
200
+
201
+
202
+
203
+
204
+
205
+
206
+
207
+
208
+
209
+
210
+
211
+
212
+
213
+
214
+ export type StageAdmission = (card: string, params: Record<string, unknown>, provenance: unknown) => void;
215
+
216
+
217
+
218
+
219
+
220
+ export declare function strippedForAdmission(card: string, params: Record<string, unknown>): Record<string, unknown>;
221
+ /** The wiring admission over ONE row (params = the MERGED view the
222
+ * next run composes; inputs = the MERGED wiring; liveIds = the
223
+ * bench's stage ids after the write; selfId = the row's own id —
224
+ * self-wiring is a cycle, refused). Throws bench/* named. */
225
+ 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;
226
+ /** add_stage — append a card stage with optional wiring (the
227
+ * runner's input convention rides the row). */
228
+ export declare function addStageBench(drafts: Domain<DraftsDomainSpec>, session: string, body: Record<string, unknown>, admit?: StageAdmission): Promise<BenchStageRow>;
229
+
230
+
231
+
232
+
233
+
234
+
235
+
236
+ export declare function reorderBench(drafts: Domain<DraftsDomainSpec>, session: string, body: Record<string, unknown>): Promise<BenchReorderRow>;
237
+ /** The reorder row: the move's coordinates for the caller's optimistic
238
+ * update (from → to, both POST-splice-clamp). */
239
+ export interface BenchReorderRow {
240
+ readonly draft_id: string;
241
+ readonly session: string;
242
+ readonly rev: number;
243
+ readonly stage: string;
244
+ readonly from: number;
245
+ readonly to: number;
246
+ }
247
+
248
+
249
+
250
+
251
+
252
+
253
+ export declare function groupBench(drafts: Domain<DraftsDomainSpec>, session: string, body: Record<string, unknown>, admit?: StageAdmission | undefined): Promise<BenchStageRow>;
254
+ /** ungroup — the compound's door: spill the children back at the
255
+ * compound's index, in their stored order. */
256
+ export declare function ungroupBench(drafts: Domain<DraftsDomainSpec>, session: string, body: Record<string, unknown>, admit?: StageAdmission | undefined): Promise<BenchStageRow>;
257
+ /** remove_stage — splice one stage out (the inverse carries row +
258
+ * index for undo). */
259
+ export declare function removeStageBench(drafts: Domain<DraftsDomainSpec>, session: string, body: Record<string, unknown>): Promise<BenchStageRow>;
260
+ /** The clear row. */
261
+ export interface BenchClearRow {
262
+ readonly draft_id: string;
263
+ readonly session: string;
264
+ readonly rev: number;
265
+ readonly cleared: number;
266
+ }
267
+
268
+
269
+
270
+
271
+
272
+
273
+
274
+ export declare function clearBench(drafts: Domain<DraftsDomainSpec>, session: string, body: Record<string, unknown>): Promise<BenchClearRow>;
275
+ /** The rewire row. */
276
+ export interface BenchRewireRow {
277
+ readonly draft_id: string;
278
+ readonly session: string;
279
+ readonly rev: number;
280
+ readonly stage: string;
281
+ readonly input: string;
282
+ }
283
+ /** rewire — set or clear one input binding. from:
284
+ * {stage, output} | {initial: "image"} | absent → clear. */
285
+ export declare function rewireBench(drafts: Domain<DraftsDomainSpec>, session: string, body: Record<string, unknown>): Promise<BenchRewireRow>;
286
+ /** The undo row: the undone revs + the stages as they stand. */
287
+ export interface BenchUndoRow {
288
+ readonly draft_id: string;
289
+ readonly session: string;
290
+ readonly rev: number;
291
+ readonly undone: readonly number[];
292
+ readonly stages: JsonValue;
293
+ }
294
+ /** undo — walk the log tail, skip already-reverted entries and
295
+ * entries the author filter excludes, apply inverses
296
+ * newest-first, append ONE undo entry carrying the pre-undo
297
+ * snapshot. Undo entries are NEVER candidates — a plain undo
298
+ * walks ACTIONS (targeting them would ping-pong). */
299
+ export declare function undoBench(drafts: Domain<DraftsDomainSpec>, session: string, body: Record<string, unknown>, admit?: StageAdmission): Promise<BenchUndoRow>;
300
+ type BenchChangeListener = (session: string) => void;
301
+ /** The event seam this pure domain module reaches the bus through.
302
+ * `bench.ts` owns no Context (it is the domain layer, not a plugin),
303
+ * so the plugin installs the pair once and every writer here keeps
304
+ * calling {@link notifyBenchChange}. */
305
+ export interface BenchChangeSeam {
306
+ emit: (session: string) => void;
307
+ on: (fn: BenchChangeListener) => () => void;
308
+ }
309
+ /** Install the seam (the plugin does this with its Context; tests do
310
+ * it with their own). Pass null to detach. */
311
+ export declare function setBenchChangeSeam(seam: BenchChangeSeam | null): void;
312
+
313
+
314
+
315
+
316
+
317
+
318
+
319
+
320
+ export declare function onBenchChange(fn: BenchChangeListener): () => void;
321
+ /** Fire the write event — the remote layer calls this after every
322
+ * successful bench write (the door seam: every in-process and
323
+ * host-routed write crosses the remote arms). */
324
+ export declare function notifyBenchChange(session: string): void;
325
+ /** The public notify (the drafts-patch door writes bench docs from
326
+ * remote.ts — outside this module; it fires this with the session
327
+ * parsed from the bench-shaped draft id). */
328
+ export declare function notifyBenchDocWrite(draftId: string): void;
329
+ //# sourceMappingURL=bench.d.ts.map