adaptive-bitmask 1.0.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +454 -0
- package/dist/ai/index.d.mts +123 -0
- package/dist/ai/index.d.ts +123 -0
- package/dist/ai/index.js +1141 -0
- package/dist/ai/index.mjs +173 -0
- package/dist/chunk-ZWEXRT33.mjs +2402 -0
- package/dist/coordinator-Df48t6yJ.d.mts +521 -0
- package/dist/coordinator-Df48t6yJ.d.ts +521 -0
- package/dist/index.d.mts +431 -0
- package/dist/index.d.ts +431 -0
- package/dist/index.js +2484 -0
- package/dist/index.mjs +118 -0
- package/package.json +82 -0
|
@@ -0,0 +1,521 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SchemaManager — Dynamic feature-to-bit mapping with frequency-based pruning.
|
|
3
|
+
*
|
|
4
|
+
* Implements Section 3.2-3.4 of the Adaptive Bitmask Protocol:
|
|
5
|
+
* - Deterministic surjection Φ_t: S_t → {0..63}
|
|
6
|
+
* - Frequency-based pruning (power-law: 20% of features → 80% of activations)
|
|
7
|
+
* - Emergency bit reservation (bits 56-63, never pruned)
|
|
8
|
+
* - Collision-aware schema evolution with versioned epochs
|
|
9
|
+
*/
|
|
10
|
+
interface SchemaConfig {
|
|
11
|
+
/** Maximum features before triggering a prune. Default: BITMASK_WIDTH */
|
|
12
|
+
maxFeatures?: number;
|
|
13
|
+
/** Emergency feature prefix. Features starting with this are pinned to bits 56-63. */
|
|
14
|
+
emergencyPrefix?: string;
|
|
15
|
+
/** Custom emergency features (alternative to prefix matching). */
|
|
16
|
+
emergencyFeatures?: string[];
|
|
17
|
+
}
|
|
18
|
+
interface PruneResult {
|
|
19
|
+
/** Number of features removed from active schema. */
|
|
20
|
+
pruned: number;
|
|
21
|
+
/** Number of features retained. */
|
|
22
|
+
retained: number;
|
|
23
|
+
/** Schema version after pruning. */
|
|
24
|
+
version: number;
|
|
25
|
+
/** Features that were excluded. */
|
|
26
|
+
excludedFeatures: string[];
|
|
27
|
+
}
|
|
28
|
+
interface SchemaSnapshot {
|
|
29
|
+
/** Current version (incremented on every schema change). */
|
|
30
|
+
version: number;
|
|
31
|
+
/** Feature → bit position mapping. */
|
|
32
|
+
featureToBit: ReadonlyMap<string, number>;
|
|
33
|
+
/** Bit position → feature(s) mapping (reverse lookup). */
|
|
34
|
+
bitToFeatures: ReadonlyMap<number, string[]>;
|
|
35
|
+
/** Total features tracked (including inactive). */
|
|
36
|
+
totalTracked: number;
|
|
37
|
+
/** Number of active (mapped) features. */
|
|
38
|
+
activeFeatures: number;
|
|
39
|
+
/** Number of emergency features mapped. */
|
|
40
|
+
emergencyCount: number;
|
|
41
|
+
}
|
|
42
|
+
interface ExportedSchema {
|
|
43
|
+
/** Schema version. */
|
|
44
|
+
version: number;
|
|
45
|
+
/** Canonical mapping entries (feature -> bit). */
|
|
46
|
+
entries: Array<[feature: string, bit: number]>;
|
|
47
|
+
/** Emergency feature prefix. */
|
|
48
|
+
emergencyPrefix: string;
|
|
49
|
+
/** Explicit emergency features. */
|
|
50
|
+
emergencyFeatures: string[];
|
|
51
|
+
/** Deterministic fingerprint for compatibility checks. */
|
|
52
|
+
fingerprint: string;
|
|
53
|
+
}
|
|
54
|
+
declare class SchemaManager {
|
|
55
|
+
private _version;
|
|
56
|
+
private _featureToBit;
|
|
57
|
+
private _bitToFeatures;
|
|
58
|
+
private _activationCounts;
|
|
59
|
+
private _totalActivations;
|
|
60
|
+
private _emergencyFeatures;
|
|
61
|
+
private _emergencyPrefix;
|
|
62
|
+
private _maxFeatures;
|
|
63
|
+
constructor(config?: SchemaConfig);
|
|
64
|
+
/** Current schema version. */
|
|
65
|
+
get version(): number;
|
|
66
|
+
/** Read-only view of feature → bit mapping. */
|
|
67
|
+
get featureToBit(): ReadonlyMap<string, number>;
|
|
68
|
+
/** Read-only view of bit → features mapping. */
|
|
69
|
+
get bitToFeatures(): ReadonlyMap<number, string[]>;
|
|
70
|
+
/** Number of actively mapped features. */
|
|
71
|
+
get activeFeatureCount(): number;
|
|
72
|
+
/** Deterministic fingerprint of current schema mapping and version. */
|
|
73
|
+
get fingerprint(): string;
|
|
74
|
+
/** Check if a feature is an emergency feature. */
|
|
75
|
+
isEmergency(feature: string): boolean;
|
|
76
|
+
/**
|
|
77
|
+
* Register a feature in the schema.
|
|
78
|
+
* Emergency features are pinned to bits 56-63.
|
|
79
|
+
* Regular features fill bits 0-55 in order.
|
|
80
|
+
*
|
|
81
|
+
* Returns the assigned bit position, or -1 if schema is full.
|
|
82
|
+
*/
|
|
83
|
+
register(feature: string): number;
|
|
84
|
+
/**
|
|
85
|
+
* Register multiple features at once.
|
|
86
|
+
* Returns a map of feature → assigned bit position.
|
|
87
|
+
*/
|
|
88
|
+
registerAll(features: string[]): Map<string, number>;
|
|
89
|
+
/**
|
|
90
|
+
* Record feature activations for frequency tracking.
|
|
91
|
+
* Call this every coordination round with the observed features.
|
|
92
|
+
*/
|
|
93
|
+
recordActivations(features: string[]): void;
|
|
94
|
+
/**
|
|
95
|
+
* Frequency-based pruning (Section 3.3).
|
|
96
|
+
*
|
|
97
|
+
* Sorts features by activation frequency, retains:
|
|
98
|
+
* - All emergency features in bits 56-63 (never pruned)
|
|
99
|
+
* - Top 48 regular features in bits 0-47 (high-frequency)
|
|
100
|
+
* - Next 8 regular features in bits 48-55 (medium-frequency)
|
|
101
|
+
*
|
|
102
|
+
* Increments schema version.
|
|
103
|
+
*/
|
|
104
|
+
prune(): PruneResult;
|
|
105
|
+
/** Get a serializable snapshot of the current schema state. */
|
|
106
|
+
snapshot(): SchemaSnapshot;
|
|
107
|
+
/**
|
|
108
|
+
* Export canonical schema state for distribution.
|
|
109
|
+
* Entries are sorted by bit (then feature) for deterministic serialization.
|
|
110
|
+
*/
|
|
111
|
+
exportSchema(): ExportedSchema;
|
|
112
|
+
/**
|
|
113
|
+
* Import an exported schema state.
|
|
114
|
+
* Replaces active mappings and resets activation counters.
|
|
115
|
+
*/
|
|
116
|
+
importSchema(schema: ExportedSchema): void;
|
|
117
|
+
/** Get activation frequency for a feature. */
|
|
118
|
+
getFrequency(feature: string): number;
|
|
119
|
+
/** Get all features ranked by activation frequency. */
|
|
120
|
+
getRankedFeatures(): Array<{
|
|
121
|
+
feature: string;
|
|
122
|
+
count: number;
|
|
123
|
+
bit: number | undefined;
|
|
124
|
+
}>;
|
|
125
|
+
/** Reset all activation counts (but keep schema mappings). */
|
|
126
|
+
resetCounts(): void;
|
|
127
|
+
/**
|
|
128
|
+
* Collision probability for a specific feature:
|
|
129
|
+
* P(collision) = 1 - (1 - 1/64)^(m - 1)
|
|
130
|
+
* where m is active feature count.
|
|
131
|
+
*/
|
|
132
|
+
get theoreticalCollisionRate(): number;
|
|
133
|
+
/**
|
|
134
|
+
* Expected excluded feature count under uniform assignment:
|
|
135
|
+
* E[excluded] = m - 64 * (1 - (1 - 1/64)^m)
|
|
136
|
+
*/
|
|
137
|
+
expectedExcludedFeatures(featureCount?: number): number;
|
|
138
|
+
private _registerEmergency;
|
|
139
|
+
private _registerRegular;
|
|
140
|
+
private _collectKnownFeatures;
|
|
141
|
+
private _compareByFrequencyThenName;
|
|
142
|
+
private _mapsEqual;
|
|
143
|
+
private _assertExportedSchema;
|
|
144
|
+
private _computeFingerprint;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Bitmask — 64-bit semantic feature encoding.
|
|
149
|
+
*
|
|
150
|
+
* Core primitive of the Adaptive Bitmask Protocol.
|
|
151
|
+
* Encodes boolean feature vectors as a single uint64,
|
|
152
|
+
* enabling O(N) coordination with 85× bandwidth reduction.
|
|
153
|
+
*
|
|
154
|
+
* Uses BigInt for true 64-bit precision (no floating-point truncation).
|
|
155
|
+
*/
|
|
156
|
+
declare const BITMASK_WIDTH = 64;
|
|
157
|
+
declare const EMERGENCY_RANGE: [number, number];
|
|
158
|
+
declare const HIGH_FREQ_RANGE: [number, number];
|
|
159
|
+
declare const MED_FREQ_RANGE: [number, number];
|
|
160
|
+
/** A 64-bit bitmask represented as BigInt. */
|
|
161
|
+
type Bitmask = bigint;
|
|
162
|
+
/** Create an empty bitmask. */
|
|
163
|
+
declare function empty(): Bitmask;
|
|
164
|
+
/** Set a specific bit position (0-63). */
|
|
165
|
+
declare function setBit(mask: Bitmask, position: number): Bitmask;
|
|
166
|
+
/** Clear a specific bit position. */
|
|
167
|
+
declare function clearBit(mask: Bitmask, position: number): Bitmask;
|
|
168
|
+
/** Test if a specific bit is set. */
|
|
169
|
+
declare function testBit(mask: Bitmask, position: number): boolean;
|
|
170
|
+
/** Count set bits (population count). */
|
|
171
|
+
declare function popcount(mask: Bitmask): number;
|
|
172
|
+
/** Get all set bit positions. */
|
|
173
|
+
declare function activeBits(mask: Bitmask): number[];
|
|
174
|
+
/** Invoke callback for each set bit position (ascending). */
|
|
175
|
+
declare function forEachSetBit(mask: Bitmask, fn: (position: number) => void): void;
|
|
176
|
+
/** OR-merge two bitmasks (union of features). */
|
|
177
|
+
declare function merge(a: Bitmask, b: Bitmask): Bitmask;
|
|
178
|
+
/** AND-intersect two bitmasks (common features). */
|
|
179
|
+
declare function intersect(a: Bitmask, b: Bitmask): Bitmask;
|
|
180
|
+
/** XOR-delta between two bitmasks (changed features). */
|
|
181
|
+
declare function delta(prev: Bitmask, next: Bitmask): Bitmask;
|
|
182
|
+
/** Hamming distance between two bitmasks. */
|
|
183
|
+
declare function hammingDistance(a: Bitmask, b: Bitmask): number;
|
|
184
|
+
/** Check if emergency bits (56-63) are active. */
|
|
185
|
+
declare function hasEmergency(mask: Bitmask): boolean;
|
|
186
|
+
/** Extract only emergency bits. */
|
|
187
|
+
declare function emergencyBits(mask: Bitmask): Bitmask;
|
|
188
|
+
/**
|
|
189
|
+
* Serialize bitmask to 8-byte Uint8Array (little-endian).
|
|
190
|
+
* This is the raw bitmask without metadata.
|
|
191
|
+
*/
|
|
192
|
+
declare function toBytes(mask: Bitmask): Uint8Array;
|
|
193
|
+
/** Deserialize 8-byte Uint8Array to bitmask. */
|
|
194
|
+
declare function fromBytes(buf: Uint8Array): Bitmask;
|
|
195
|
+
interface EncodeOptions {
|
|
196
|
+
/** Throw if any feature is not present in schema mapping. */
|
|
197
|
+
throwOnUnknownFeatures?: boolean;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Encode a set of features into a bitmask given a schema mapping.
|
|
201
|
+
* Features not in the schema are silently ignored.
|
|
202
|
+
* Returns the mask and count of mapped/unmapped features.
|
|
203
|
+
*/
|
|
204
|
+
declare function encode(features: string[], schema: ReadonlyMap<string, number>, options?: EncodeOptions): {
|
|
205
|
+
mask: Bitmask;
|
|
206
|
+
mapped: number;
|
|
207
|
+
unmapped: number;
|
|
208
|
+
};
|
|
209
|
+
/**
|
|
210
|
+
* Decode a bitmask back to feature names.
|
|
211
|
+
* Ambiguous when collisions exist (multiple features per bit).
|
|
212
|
+
*/
|
|
213
|
+
declare function decode(mask: Bitmask, reverseSchema: ReadonlyMap<number, string[]>): string[];
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* BitmaskMessage — Wire format for agent coordination.
|
|
217
|
+
*
|
|
218
|
+
* Layout (24 bytes):
|
|
219
|
+
* [0..7] uint64 mask — 64-bit feature bitmask
|
|
220
|
+
* [8..11] uint32 agentId — Unique agent identifier
|
|
221
|
+
* [12..19] int64 timestampMs — Unix timestamp (millis)
|
|
222
|
+
* [20..23] uint32 schemaVersion — Schema epoch for validation
|
|
223
|
+
*
|
|
224
|
+
* All fields little-endian for consistency with x86-64.
|
|
225
|
+
*/
|
|
226
|
+
|
|
227
|
+
declare const MESSAGE_SIZE_BYTES = 24;
|
|
228
|
+
interface BitmaskMessageData {
|
|
229
|
+
/** 64-bit feature bitmask. */
|
|
230
|
+
mask: Bitmask;
|
|
231
|
+
/** Unique agent identifier. */
|
|
232
|
+
agentId: number;
|
|
233
|
+
/** Unix timestamp in milliseconds. */
|
|
234
|
+
timestampMs: number;
|
|
235
|
+
/** Schema version this mask was encoded against. */
|
|
236
|
+
schemaVersion: number;
|
|
237
|
+
}
|
|
238
|
+
declare class BitmaskMessage implements BitmaskMessageData {
|
|
239
|
+
readonly mask: Bitmask;
|
|
240
|
+
readonly agentId: number;
|
|
241
|
+
readonly timestampMs: number;
|
|
242
|
+
readonly schemaVersion: number;
|
|
243
|
+
constructor(data: BitmaskMessageData);
|
|
244
|
+
/** Create a message with current timestamp. */
|
|
245
|
+
static now(mask: Bitmask, agentId: number, schemaVersion: number): BitmaskMessage;
|
|
246
|
+
/** Wire size in bytes. */
|
|
247
|
+
get sizeBytes(): number;
|
|
248
|
+
/**
|
|
249
|
+
* Serialize to 24-byte ArrayBuffer (little-endian).
|
|
250
|
+
*
|
|
251
|
+
* This is the canonical wire format. gRPC/WebSocket transports
|
|
252
|
+
* should send these bytes directly.
|
|
253
|
+
*/
|
|
254
|
+
serialize(): ArrayBuffer;
|
|
255
|
+
/** Serialize to Uint8Array. */
|
|
256
|
+
toBytes(): Uint8Array;
|
|
257
|
+
/**
|
|
258
|
+
* Deserialize from ArrayBuffer or Uint8Array.
|
|
259
|
+
* Validates length before parsing.
|
|
260
|
+
*/
|
|
261
|
+
static deserialize(data: ArrayBuffer | Uint8Array): BitmaskMessage;
|
|
262
|
+
/**
|
|
263
|
+
* JSON-equivalent size for comparison.
|
|
264
|
+
* Useful for demonstrating compression ratio.
|
|
265
|
+
*/
|
|
266
|
+
get jsonSize(): number;
|
|
267
|
+
/** Compression ratio vs JSON encoding. */
|
|
268
|
+
get compressionVsJson(): number;
|
|
269
|
+
/** Human-readable string for debugging. */
|
|
270
|
+
toString(): string;
|
|
271
|
+
private _assertValid;
|
|
272
|
+
private _assertUint32;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* Arbiter — Weighted linear scoring and decision synthesis.
|
|
277
|
+
*
|
|
278
|
+
* Implements Section 6 of the Adaptive Bitmask Protocol:
|
|
279
|
+
* - Weighted linear scoring: ŝ = Σ(w_k · b_k) / Σ(w_k)
|
|
280
|
+
* - Three-tier decision logic: EXECUTE / SYNTHESIZE / REJECT
|
|
281
|
+
* - Configurable thresholds and weight vectors
|
|
282
|
+
* - Sub-millisecond execution (measured: 15μs mean, 26μs p99)
|
|
283
|
+
*/
|
|
284
|
+
|
|
285
|
+
/** Decision outcome from the arbiter. */
|
|
286
|
+
type Decision = 'EXECUTE' | 'SYNTHESIZE' | 'REJECT';
|
|
287
|
+
/** Full decision result with audit trail. */
|
|
288
|
+
interface ArbiterResult {
|
|
289
|
+
/** The decision: EXECUTE, SYNTHESIZE, or REJECT. */
|
|
290
|
+
decision: Decision;
|
|
291
|
+
/** Raw weighted score [0, 1]. */
|
|
292
|
+
rawScore: number;
|
|
293
|
+
/** Confidence-adjusted score [0, 1]. */
|
|
294
|
+
confidenceScore: number;
|
|
295
|
+
/** Final composite score [0, 1]. */
|
|
296
|
+
finalScore: number;
|
|
297
|
+
/** Number of active bits in the aggregated mask. */
|
|
298
|
+
activeBitCount: number;
|
|
299
|
+
/** Whether emergency bits were active. */
|
|
300
|
+
hasEmergency: boolean;
|
|
301
|
+
/** Scoring computation time in microseconds. */
|
|
302
|
+
scoringTimeUs: number;
|
|
303
|
+
}
|
|
304
|
+
/** Per-bit confidence from aggregation (what fraction of agents set this bit). */
|
|
305
|
+
type BitConfidence = Map<number, number>;
|
|
306
|
+
interface StrategyCandidate {
|
|
307
|
+
/** Stable strategy identifier. */
|
|
308
|
+
id: string;
|
|
309
|
+
/** Candidate bitmask for strategy evaluation. */
|
|
310
|
+
mask: Bitmask;
|
|
311
|
+
/** Optional per-bit confidence specific to this strategy. */
|
|
312
|
+
confidence?: BitConfidence;
|
|
313
|
+
}
|
|
314
|
+
interface ScoreStrategiesOptions {
|
|
315
|
+
/** Minimum lead required for direct execute. Default: 0.15 (15 points). */
|
|
316
|
+
leadThreshold?: number;
|
|
317
|
+
/** Minimum top score required to avoid reject. Default: 0.40. */
|
|
318
|
+
rejectThreshold?: number;
|
|
319
|
+
/** Fallback confidence map when candidate-level confidence is absent. */
|
|
320
|
+
globalConfidence?: BitConfidence;
|
|
321
|
+
}
|
|
322
|
+
interface StrategyScore {
|
|
323
|
+
/** Strategy identifier. */
|
|
324
|
+
id: string;
|
|
325
|
+
/** Strategy mask. */
|
|
326
|
+
mask: Bitmask;
|
|
327
|
+
/** Raw weighted score ŝ_raw. */
|
|
328
|
+
rawScore: number;
|
|
329
|
+
/** Confidence score c. */
|
|
330
|
+
confidenceScore: number;
|
|
331
|
+
/** Final composite score ŝ_final = 0.6*ŝ_raw + 0.4*c. */
|
|
332
|
+
finalScore: number;
|
|
333
|
+
}
|
|
334
|
+
interface StrategyDecisionResult {
|
|
335
|
+
/** Final decision outcome. */
|
|
336
|
+
decision: Decision;
|
|
337
|
+
/** Selected strategy when decision is EXECUTE. */
|
|
338
|
+
selectedStrategyId?: string;
|
|
339
|
+
/** Synthesized mask when decision is SYNTHESIZE. */
|
|
340
|
+
synthesizedMask?: Bitmask;
|
|
341
|
+
/** Lead score (top1 - top2, or top1 if only one strategy). */
|
|
342
|
+
leadScore: number;
|
|
343
|
+
/** Ranked strategy scores (descending finalScore). */
|
|
344
|
+
rankings: StrategyScore[];
|
|
345
|
+
}
|
|
346
|
+
type ArbiterTelemetryEvent = {
|
|
347
|
+
type: 'decision';
|
|
348
|
+
result: ArbiterResult;
|
|
349
|
+
} | {
|
|
350
|
+
type: 'score_messages';
|
|
351
|
+
messageCount: number;
|
|
352
|
+
staleCount: number;
|
|
353
|
+
result: ArbiterResult;
|
|
354
|
+
} | {
|
|
355
|
+
type: 'strategy_decision';
|
|
356
|
+
result: StrategyDecisionResult;
|
|
357
|
+
};
|
|
358
|
+
interface ArbiterConfig {
|
|
359
|
+
/** Weight vector: importance of each bit position [0..63]. */
|
|
360
|
+
weights?: number[];
|
|
361
|
+
/**
|
|
362
|
+
* Score threshold above which to EXECUTE.
|
|
363
|
+
* Default: 0.55 (paper Section 6.1).
|
|
364
|
+
*/
|
|
365
|
+
executeThreshold?: number;
|
|
366
|
+
/**
|
|
367
|
+
* Score threshold above which to SYNTHESIZE (below execute).
|
|
368
|
+
* Default: 0.40 (paper Section 6.1).
|
|
369
|
+
*/
|
|
370
|
+
synthesizeThreshold?: number;
|
|
371
|
+
/**
|
|
372
|
+
* If true, emergency bits trigger immediate REJECT regardless of score.
|
|
373
|
+
* Default: true.
|
|
374
|
+
*/
|
|
375
|
+
emergencyOverride?: boolean;
|
|
376
|
+
/** Optional telemetry callback for runtime observability. */
|
|
377
|
+
onTelemetry?: (event: ArbiterTelemetryEvent) => void;
|
|
378
|
+
}
|
|
379
|
+
declare class Arbiter {
|
|
380
|
+
private _weights;
|
|
381
|
+
private _weightSum;
|
|
382
|
+
private _executeThreshold;
|
|
383
|
+
private _synthesizeThreshold;
|
|
384
|
+
private _emergencyOverride;
|
|
385
|
+
private _onTelemetry;
|
|
386
|
+
private _decisionCount;
|
|
387
|
+
constructor(config?: ArbiterConfig);
|
|
388
|
+
/** Number of decisions made since creation. */
|
|
389
|
+
get decisionCount(): number;
|
|
390
|
+
/** Set the weight for a specific bit position. */
|
|
391
|
+
setWeight(position: number, weight: number): void;
|
|
392
|
+
/** Get the current weight vector (copy). */
|
|
393
|
+
get weights(): number[];
|
|
394
|
+
/**
|
|
395
|
+
* Score an aggregated bitmask and produce a decision.
|
|
396
|
+
*
|
|
397
|
+
* @param aggregatedMask — OR-aggregated mask from all agents
|
|
398
|
+
* @param confidence — Optional per-bit confidence (fraction of agents that set each bit)
|
|
399
|
+
*/
|
|
400
|
+
score(aggregatedMask: Bitmask, confidence?: BitConfidence): ArbiterResult;
|
|
401
|
+
/**
|
|
402
|
+
* Convenience: aggregate messages then score.
|
|
403
|
+
* OR-merges all message masks, computes per-bit confidence,
|
|
404
|
+
* validates schema versions, then runs scoring.
|
|
405
|
+
*/
|
|
406
|
+
scoreMessages(messages: BitmaskMessage[], expectedSchemaVersion?: number): ArbiterResult & {
|
|
407
|
+
staleCount: number;
|
|
408
|
+
};
|
|
409
|
+
/**
|
|
410
|
+
* Paper-canonical strategy ranking and decision logic (Section 6).
|
|
411
|
+
* Uses ŝ_final = 0.6*ŝ_raw + 0.4*c, then applies:
|
|
412
|
+
* - EXECUTE if lead > 15 points
|
|
413
|
+
* - SYNTHESIZE if top strategies are within threshold
|
|
414
|
+
* - REJECT if top score < 40%
|
|
415
|
+
*/
|
|
416
|
+
scoreStrategies(candidates: StrategyCandidate[], options?: ScoreStrategiesOptions): StrategyDecisionResult;
|
|
417
|
+
private _scoreMaskComponents;
|
|
418
|
+
private _synthesizeMask;
|
|
419
|
+
private _emitTelemetry;
|
|
420
|
+
}
|
|
421
|
+
/**
|
|
422
|
+
* Create a financial trading arbiter with domain-specific weights.
|
|
423
|
+
* Matches the weight configuration from the paper's evaluation.
|
|
424
|
+
*/
|
|
425
|
+
declare function createFinancialArbiter(overrides?: Partial<ArbiterConfig>): Arbiter;
|
|
426
|
+
/**
|
|
427
|
+
* Create a robotic coordination arbiter with safety-first weights.
|
|
428
|
+
*/
|
|
429
|
+
declare function createRoboticArbiter(overrides?: Partial<ArbiterConfig>): Arbiter;
|
|
430
|
+
|
|
431
|
+
/**
|
|
432
|
+
* Coordinator — Aggregates bitmasks from multiple agents.
|
|
433
|
+
*
|
|
434
|
+
* Implements the Meta-Coordinator layer:
|
|
435
|
+
* - Collects BitmaskMessages from worker agents
|
|
436
|
+
* - OR-aggregates into unified consensus mask
|
|
437
|
+
* - Computes per-bit confidence (vote fraction)
|
|
438
|
+
* - Provides deadline-based collection with timeout
|
|
439
|
+
*/
|
|
440
|
+
|
|
441
|
+
type StaleMessagePolicy = 'accept' | 'warn' | 'drop';
|
|
442
|
+
type CoordinatorDropReason = 'deadline' | 'stale';
|
|
443
|
+
type CoordinatorTelemetryEvent = {
|
|
444
|
+
type: 'message_accepted';
|
|
445
|
+
agentId: number;
|
|
446
|
+
stale: boolean;
|
|
447
|
+
replaced: boolean;
|
|
448
|
+
} | {
|
|
449
|
+
type: 'message_dropped';
|
|
450
|
+
agentId: number;
|
|
451
|
+
reason: CoordinatorDropReason;
|
|
452
|
+
} | {
|
|
453
|
+
type: 'round_aggregated';
|
|
454
|
+
result: AggregationResult;
|
|
455
|
+
};
|
|
456
|
+
interface AggregationResult {
|
|
457
|
+
/** OR-aggregated mask (union of all agent observations). */
|
|
458
|
+
aggregatedMask: Bitmask;
|
|
459
|
+
/** Per-bit confidence: fraction of agents that set each bit. */
|
|
460
|
+
confidence: BitConfidence;
|
|
461
|
+
/** Number of messages aggregated. */
|
|
462
|
+
messageCount: number;
|
|
463
|
+
/** Number of unique agents represented. */
|
|
464
|
+
uniqueAgents: number;
|
|
465
|
+
/** Number of schema-stale messages (mismatched version). */
|
|
466
|
+
staleMessages: number;
|
|
467
|
+
/** Number of stale messages dropped at receive-time. */
|
|
468
|
+
droppedStaleMessages: number;
|
|
469
|
+
/** Aggregation time in microseconds. */
|
|
470
|
+
aggregationTimeUs: number;
|
|
471
|
+
}
|
|
472
|
+
interface CoordinatorConfig {
|
|
473
|
+
/** Expected number of agents (for pre-allocation). */
|
|
474
|
+
expectedAgents?: number;
|
|
475
|
+
/** Deadline in ms — messages arriving after this are dropped. */
|
|
476
|
+
deadlineMs?: number;
|
|
477
|
+
/** Expected schema version. Messages with different versions are flagged. */
|
|
478
|
+
schemaVersion?: number;
|
|
479
|
+
/** Policy when schema versions mismatch. Default: 'accept'. */
|
|
480
|
+
staleMessagePolicy?: StaleMessagePolicy;
|
|
481
|
+
/** Optional telemetry callback for runtime observability. */
|
|
482
|
+
onTelemetry?: (event: CoordinatorTelemetryEvent) => void;
|
|
483
|
+
}
|
|
484
|
+
declare class Coordinator {
|
|
485
|
+
private _buffer;
|
|
486
|
+
private _seenAgents;
|
|
487
|
+
private _schemaVersion;
|
|
488
|
+
private _deadlineMs;
|
|
489
|
+
private _staleMessagePolicy;
|
|
490
|
+
private _onTelemetry;
|
|
491
|
+
private _roundStartTime;
|
|
492
|
+
private _aggregationCount;
|
|
493
|
+
private _droppedStaleMessages;
|
|
494
|
+
constructor(config?: CoordinatorConfig);
|
|
495
|
+
/** Number of messages in current buffer. */
|
|
496
|
+
get bufferedCount(): number;
|
|
497
|
+
/** Total aggregation rounds performed. */
|
|
498
|
+
get aggregationCount(): number;
|
|
499
|
+
/** Update expected schema version. */
|
|
500
|
+
set schemaVersion(version: number);
|
|
501
|
+
/** Start a new coordination round. Clears the buffer. */
|
|
502
|
+
startRound(): void;
|
|
503
|
+
/**
|
|
504
|
+
* Receive a message from an agent.
|
|
505
|
+
* Returns false if the message was dropped (deadline exceeded or duplicate agent).
|
|
506
|
+
*/
|
|
507
|
+
receive(message: BitmaskMessage): boolean;
|
|
508
|
+
/**
|
|
509
|
+
* Receive multiple messages at once.
|
|
510
|
+
* Returns number of messages accepted.
|
|
511
|
+
*/
|
|
512
|
+
receiveAll(messages: BitmaskMessage[]): number;
|
|
513
|
+
/**
|
|
514
|
+
* Aggregate all buffered messages into a consensus result.
|
|
515
|
+
* Clears the buffer after aggregation.
|
|
516
|
+
*/
|
|
517
|
+
aggregate(): AggregationResult;
|
|
518
|
+
private _emitTelemetry;
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
export { Arbiter as A, BitmaskMessage as B, Coordinator as C, type Decision as D, EMERGENCY_RANGE as E, delta as F, emergencyBits as G, HIGH_FREQ_RANGE as H, empty as I, encode as J, forEachSetBit as K, fromBytes as L, MED_FREQ_RANGE as M, hammingDistance as N, hasEmergency as O, type PruneResult as P, intersect as Q, merge as R, SchemaManager as S, popcount as T, setBit as U, testBit as V, toBytes as W, type SchemaConfig as a, type CoordinatorConfig as b, type ArbiterConfig as c, type ArbiterResult as d, type AggregationResult as e, type ArbiterTelemetryEvent as f, BITMASK_WIDTH as g, type BitConfidence as h, type Bitmask as i, type BitmaskMessageData as j, type CoordinatorDropReason as k, type CoordinatorTelemetryEvent as l, type EncodeOptions as m, type ExportedSchema as n, MESSAGE_SIZE_BYTES as o, type SchemaSnapshot as p, type ScoreStrategiesOptions as q, type StaleMessagePolicy as r, type StrategyCandidate as s, type StrategyDecisionResult as t, type StrategyScore as u, activeBits as v, clearBit as w, createFinancialArbiter as x, createRoboticArbiter as y, decode as z };
|