@gmitch215/folio 1.0.0 → 1.1.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.
Files changed (71) hide show
  1. package/README.md +455 -26
  2. package/dist/affine-state.d.ts +171 -0
  3. package/dist/affine-state.js +763 -0
  4. package/dist/affine.d.ts +160 -0
  5. package/dist/affine.js +571 -0
  6. package/dist/bake.d.ts +8 -3
  7. package/dist/bake.js +5 -2
  8. package/dist/boundaries.d.ts +59 -0
  9. package/dist/boundaries.js +127 -0
  10. package/dist/certified.d.ts +66 -0
  11. package/dist/certified.js +192 -0
  12. package/dist/certify.d.ts +98 -0
  13. package/dist/certify.js +2628 -0
  14. package/dist/compiler.d.ts +37 -1
  15. package/dist/compiler.js +116 -1
  16. package/dist/context.d.ts +47 -0
  17. package/dist/context.js +139 -0
  18. package/dist/coordinator.d.ts +1 -1
  19. package/dist/coordinator.js +54 -5
  20. package/dist/extract.d.ts +114 -1
  21. package/dist/extract.js +1011 -242
  22. package/dist/fold.d.ts +32 -0
  23. package/dist/fold.js +105 -0
  24. package/dist/frames.d.ts +20 -2
  25. package/dist/frames.js +205 -10
  26. package/dist/inline.d.ts +182 -0
  27. package/dist/inline.js +766 -0
  28. package/dist/iteration-admission.d.ts +185 -0
  29. package/dist/iteration-admission.js +201 -0
  30. package/dist/iteration-layout.d.ts +135 -0
  31. package/dist/iteration-layout.js +169 -0
  32. package/dist/iteration-owner.d.ts +45 -0
  33. package/dist/iteration-owner.js +223 -0
  34. package/dist/iteration-worker.d.ts +1 -0
  35. package/dist/iteration-worker.js +216 -0
  36. package/dist/iteration.d.ts +329 -0
  37. package/dist/iteration.js +1210 -0
  38. package/dist/lease.d.ts +45 -0
  39. package/dist/lease.js +274 -0
  40. package/dist/managed.d.ts +78 -0
  41. package/dist/managed.js +448 -27
  42. package/dist/memo.d.ts +99 -0
  43. package/dist/memo.js +250 -0
  44. package/dist/node.d.ts +61 -5
  45. package/dist/node.js +421 -23
  46. package/dist/ownership-redirect.d.ts +30 -0
  47. package/dist/ownership-redirect.js +179 -0
  48. package/dist/ownership-slices.d.ts +44 -0
  49. package/dist/ownership-slices.js +72 -0
  50. package/dist/ownership.d.ts +161 -0
  51. package/dist/ownership.js +6568 -0
  52. package/dist/ranges.d.ts +78 -0
  53. package/dist/ranges.js +263 -0
  54. package/dist/read-scan.d.ts +18 -0
  55. package/dist/read-scan.js +94 -0
  56. package/dist/read-windows.d.ts +103 -0
  57. package/dist/read-windows.js +244 -0
  58. package/dist/router-worker.d.ts +1 -0
  59. package/dist/router-worker.js +4 -0
  60. package/dist/router.d.ts +203 -0
  61. package/dist/router.js +667 -0
  62. package/dist/runs.d.ts +44 -0
  63. package/dist/runs.js +182 -0
  64. package/dist/slices-worker.d.ts +1 -0
  65. package/dist/slices-worker.js +38 -0
  66. package/dist/slices.d.ts +126 -0
  67. package/dist/slices.js +441 -0
  68. package/dist/tasks.d.ts +14 -4
  69. package/dist/tasks.js +23 -9
  70. package/dist/transaction.d.ts +10 -0
  71. package/package.json +44 -4
@@ -0,0 +1,171 @@
1
+ import { type AffineCheck, type AffineRing } from './affine.ts';
2
+ import { type FoldChunk } from './fold.ts';
3
+ import { type TaskLink, type TaskPool } from './tasks.ts';
4
+ /** Where the probe puts the context and the data in the kernel's linear memory. */
5
+ export declare const CONTEXT_ADDRESS: number;
6
+ export declare const DATA_ADDRESS: number;
7
+ /** Where the context pointer, the data pointer and the length sit in the entry's parameters. */
8
+ export interface ContextLayout {
9
+ entry: string;
10
+ ctx: number;
11
+ ptr: number;
12
+ len: number;
13
+ /** Bytes of the context the probe examines and every task copies. At most 256. */
14
+ window: number;
15
+ }
16
+ /**
17
+ * What a worker needs to run a context kernel: the module, the parameter layout, the context image
18
+ * the caller initialised, and which bytes of it are state. Every other byte of the image is held at
19
+ * its value in `context`.
20
+ */
21
+ export interface ContextSubject {
22
+ module: WebAssembly.Module | Uint8Array;
23
+ layout: ContextLayout;
24
+ context: Uint8Array;
25
+ state: number[];
26
+ }
27
+ /** One independent part of the state vector, with the ring it is affine over. */
28
+ export interface StateFactor {
29
+ ring: AffineRing;
30
+ /** Context offsets of the bytes of this factor, ascending. */
31
+ offsets: number[];
32
+ /** Positions of those bytes in the state vector of the model. */
33
+ slots: number[];
34
+ wordBytes: number;
35
+ endian: 'le' | 'be';
36
+ words: number;
37
+ /** Bits per word. For `gf2` it is the width of the whole factor. */
38
+ bits: number;
39
+ /** `gf2`: the columns of the one-unit bit matrix. `z2w`: the words x words matrix over Z/2^bits. */
40
+ operator: bigint[] | bigint[][];
41
+ }
42
+ export interface StateCheck extends AffineCheck {
43
+ /** Index of the factor, or -1 for a check on the whole context. */
44
+ factor: number;
45
+ shape: string;
46
+ }
47
+ /** The recovered model of a state vector that lives in the context. */
48
+ export interface StateModel {
49
+ kind: 'state';
50
+ layout: ContextLayout;
51
+ /** The context image the probe ran from. Bytes that are not state stay at these values. */
52
+ context: Uint8Array;
53
+ /** Context offsets of the state: bytes that a call both reads and writes. */
54
+ state: number[];
55
+ /** Bytes a call reads and never writes, and that change the result. Held at `context`. */
56
+ params: number[];
57
+ /** Bytes a call writes and never reads. They are not state and are not carried. */
58
+ scratch: number[];
59
+ factors: StateFactor[];
60
+ align: number;
61
+ checks: StateCheck[];
62
+ calls: number;
63
+ }
64
+ export interface StateRefusal {
65
+ kind: 'refusal';
66
+ reason: string;
67
+ checks: StateCheck[];
68
+ calls: number;
69
+ }
70
+ export interface StateProbeOptions {
71
+ /** Seed of the PRNG. The default is fixed. */
72
+ seed?: number;
73
+ /** Trials per check. The default is 32. */
74
+ trials?: number;
75
+ /** Every probed data length is a multiple of this. */
76
+ align?: number;
77
+ /** The context image as the caller's init function left it. The default is zeros. */
78
+ context?: Uint8Array;
79
+ /** Bytes of the context to examine, at most 256. The default is 256. */
80
+ window?: number;
81
+ }
82
+ export interface StateFoldOptions {
83
+ /** The state vector before the first byte. The default is the state bytes of `model.context`. */
84
+ initial?: Uint8Array;
85
+ chunks?: FoldChunk[];
86
+ }
87
+ export interface StateFoldResult {
88
+ state: Uint8Array;
89
+ chunks: number;
90
+ tasks: number;
91
+ validated: number;
92
+ mismatchAt: number;
93
+ fallbackBytes: number;
94
+ }
95
+ /** One private instance of a context kernel: put and get bytes, call it, count the calls. */
96
+ export declare class ContextKernel {
97
+ #private;
98
+ readonly arity: number;
99
+ readonly entry: string;
100
+ calls: number;
101
+ constructor(module: WebAssembly.Module | Uint8Array, entry: string);
102
+ /** Puts the memory back to what it was after instantiation. */
103
+ restore(): void;
104
+ put(at: number, bytes: Uint8Array): void;
105
+ get(at: number, length: number): Uint8Array;
106
+ raw(args: (number | bigint)[]): number | bigint;
107
+ /** Copies of every byte of memory outside the given ranges, for the hidden state check. */
108
+ outside(ranges: [number, number][]): Uint8Array;
109
+ /**
110
+ * One call: the context image at the context address, the data at the data address. Returns the
111
+ * context window afterwards, or undefined when the kernel traps.
112
+ */
113
+ run(layout: ContextLayout, image: Uint8Array, data: Uint8Array): Uint8Array | undefined;
114
+ }
115
+ /**
116
+ * The context image after one call of an init function, for a subject whose state starts from
117
+ * something other than zeros. `args` gets the context address; `inputs` is placed at the data
118
+ * address first, for init functions that take a key or an IV.
119
+ */
120
+ export declare function initialContext(module: WebAssembly.Module | Uint8Array, entry: string, args: (ctx: number, data: number) => (number | bigint)[], inputs?: Uint8Array, window?: number): Uint8Array;
121
+ /** A subject whose state is the whole window, for chains with no model. */
122
+ export declare function contextSubject(module: WebAssembly.Module | Uint8Array, entry: string, context: Uint8Array, layout?: Partial<ContextLayout>): ContextSubject;
123
+ /** The subject a model describes, for `serveContext`. */
124
+ export declare function modelSubject(module: WebAssembly.Module | Uint8Array, model: StateModel): ContextSubject;
125
+ export declare const pick: (image: Uint8Array, offsets: number[]) => Uint8Array;
126
+ export declare function toHex(bytes: Uint8Array): string;
127
+ export declare function fromHex(hex: string): Uint8Array;
128
+ export declare const bytesEqual: (a: Uint8Array, b: Uint8Array) => boolean;
129
+ /**
130
+ * The state vector after a chunk of `length` bytes from `start`, given `offset`, the state vector
131
+ * after the same chunk from zero: A(length) start + offset, factor by factor. `length` must be a
132
+ * multiple of `model.align`.
133
+ */
134
+ export declare function predictState(model: Pick<StateModel, 'factors' | 'align' | 'state'>, start: Uint8Array, length: number, offset: Uint8Array): Uint8Array;
135
+ /**
136
+ * Probes `entry`, a function (context pointer, data pointer, length) that updates a context struct
137
+ * in place, and decides by trial what its state is and whether the state transition is affine.
138
+ *
139
+ * It finds the parameter order under which the call composes over a split, then, from contexts the
140
+ * function itself produced, flips each of the first `window` context bytes and records which bytes
141
+ * the result depends on. State is the set of bytes a call both reads and writes. A byte that is read
142
+ * and never written is a parameter and stays at its value in `options.context`. State bytes that
143
+ * do not depend on each other form independent factors. Each factor is tested over GF(2) and over
144
+ * Z/2^bits (as one little or big endian integer, or as 32-bit words coupled by a matrix) with the
145
+ * five checks of `probeAffine`, with the other factors set to random bytes in every call, which
146
+ * tests that they do not interact. A factor that is affine in no ring refuses the whole context.
147
+ *
148
+ * A pass is evidence on the sampled inputs only. It cannot see state outside the window, a byte
149
+ * that is read only on rare inputs, or behaviour above the probed lengths. `foldState` in exact
150
+ * mode does not trust the model, but its guarantee needs the state to be complete.
151
+ */
152
+ export declare function probeState(module: WebAssembly.Module | Uint8Array, entry: string, options?: StateProbeOptions): StateModel | StateRefusal;
153
+ /**
154
+ * Runs on the worker side. Answers `ctx:<hex state>` with the end state bytes, and
155
+ * `ctxrec:<hex state>:<step>` with the state after every `step` bytes, concatenated, the last one
156
+ * being the end state. The context image is rebuilt from `subject.context` for every task.
157
+ */
158
+ export declare function serveContext(link: TaskLink, subject: ContextSubject): void;
159
+ /** The serial reference: one call over all the bytes on a private instance. */
160
+ export declare function stateSerial(subject: ContextSubject): (input: Uint8Array, state?: Uint8Array) => Uint8Array;
161
+ /**
162
+ * `foldAffine` exact mode for a state vector in the context: pass 1 runs every chunk but the last
163
+ * from the zero state, the model turns the offsets into predicted start vectors, pass 2 runs
164
+ * chunks 1 to n-1 from them in workers started with `serveContext`, and each end vector is compared
165
+ * with the next predicted start. All equal: the last end vector is the serial state, by induction,
166
+ * whatever the model got wrong. The first difference hands the rest to one serial task.
167
+ *
168
+ * The result is the state bytes only. Bytes a call writes and does not read (`model.scratch`, and
169
+ * the data a call changes in place) are not returned.
170
+ */
171
+ export declare function foldState(pool: TaskPool, input: Uint8Array, model: StateModel, options?: StateFoldOptions): StateFoldResult;