pi-mega-compact 0.8.8 → 0.8.10

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 (88) hide show
  1. package/dist/extensions/dashboard-server/api-contracts/core.js +7 -0
  2. package/dist/extensions/dashboard-server/api-contracts/endpoints.js +104 -0
  3. package/dist/extensions/dashboard-server/api-contracts/game.js +9 -0
  4. package/dist/extensions/dashboard-server/api-contracts/index.js +9 -0
  5. package/dist/extensions/dashboard-server/api-contracts/infrastructure.js +10 -0
  6. package/dist/extensions/dashboard-server/api-contracts/multi-repo.js +9 -0
  7. package/dist/extensions/dashboard-server/api-contracts/snapshot.js +8 -0
  8. package/dist/extensions/dashboard-server/api-contracts.js +8 -0
  9. package/dist/extensions/dashboard-server/api-contracts.test.js +869 -0
  10. package/dist/extensions/dashboard-server/auth.js +18 -0
  11. package/dist/extensions/dashboard-server/helpers.js +37 -0
  12. package/dist/extensions/dashboard-server/html/all-repos-tab.js +26 -0
  13. package/dist/extensions/dashboard-server/html/body-open.js +23 -0
  14. package/dist/extensions/dashboard-server/html/current-repo-tab.js +130 -0
  15. package/dist/extensions/dashboard-server/html/head-open.js +16 -0
  16. package/dist/extensions/dashboard-server/html/high-score-tab.js +25 -0
  17. package/dist/extensions/dashboard-server/html/repo-detail-modal.js +26 -0
  18. package/dist/extensions/dashboard-server/html/script.js +259 -0
  19. package/dist/extensions/dashboard-server/html/styles.js +103 -0
  20. package/dist/extensions/dashboard-server/html/summary-tab.js +19 -0
  21. package/dist/extensions/dashboard-server/html-template.js +41 -0
  22. package/dist/extensions/dashboard-server/server.js +191 -39
  23. package/dist/extensions/dashboard-server/tailscale.js +8 -0
  24. package/dist/extensions/dashboard-server/types.js +4 -0
  25. package/dist/src/store/sqlite/connection.js +35 -0
  26. package/dist/src/store/sqlite/index-store.js +167 -0
  27. package/dist/src/store/sqlite/memory.js +54 -0
  28. package/dist/src/store/sqlite/minhash-lsh.js +47 -0
  29. package/dist/src/store/sqlite/sessions.js +39 -0
  30. package/dist/src/store/sqlite/transaction.js +19 -0
  31. package/dist/src/vectorStore/add.js +260 -0
  32. package/dist/src/vectorStore/dedup.js +52 -0
  33. package/dist/src/vectorStore/index.js +10 -0
  34. package/dist/src/vectorStore/queries.js +83 -0
  35. package/dist/src/vectorStore/search.js +95 -0
  36. package/dist/src/vectorStore/session.js +19 -0
  37. package/dist/src/vectorStore/store.js +105 -0
  38. package/dist/src/vectorStore/types.js +6 -0
  39. package/dist/src/vectorStore/utils.js +23 -0
  40. package/extensions/dashboard-client/package-lock.json +1771 -0
  41. package/extensions/dashboard-client/package.json +27 -0
  42. package/extensions/dashboard-client/src/App.tsx +82 -0
  43. package/extensions/dashboard-client/src/api/client.ts +145 -0
  44. package/extensions/dashboard-client/src/components/CacheStatusPerModel.tsx +44 -0
  45. package/extensions/dashboard-client/src/components/CompressionCard.tsx +61 -0
  46. package/extensions/dashboard-client/src/components/ContextGauge.tsx +59 -0
  47. package/extensions/dashboard-client/src/components/DataSafetyCard.tsx +49 -0
  48. package/extensions/dashboard-client/src/components/ErrorBoundary.tsx +53 -0
  49. package/extensions/dashboard-client/src/components/EventCategoryFilter.tsx +16 -0
  50. package/extensions/dashboard-client/src/components/EventStream.tsx +152 -0
  51. package/extensions/dashboard-client/src/components/LoadingSpinner.tsx +7 -0
  52. package/extensions/dashboard-client/src/components/MemoryStatusCard.tsx +24 -0
  53. package/extensions/dashboard-client/src/components/ModelBadge.tsx +41 -0
  54. package/extensions/dashboard-client/src/components/PerfChart.tsx +160 -0
  55. package/extensions/dashboard-client/src/components/RepoDetailModal.tsx +126 -0
  56. package/extensions/dashboard-client/src/components/RepoTable.tsx +150 -0
  57. package/extensions/dashboard-client/src/components/SessionInfo.tsx +65 -0
  58. package/extensions/dashboard-client/src/components/SummaryTiles.tsx +52 -0
  59. package/extensions/dashboard-client/src/components/TabBar.tsx +34 -0
  60. package/extensions/dashboard-client/src/components/TriggerStatus.tsx +62 -0
  61. package/extensions/dashboard-client/src/hooks/useApi.ts +77 -0
  62. package/extensions/dashboard-client/src/hooks/useSSE.ts +87 -0
  63. package/extensions/dashboard-client/src/index.html +12 -0
  64. package/extensions/dashboard-client/src/main.tsx +23 -0
  65. package/extensions/dashboard-client/src/styles/base.css +121 -0
  66. package/extensions/dashboard-client/src/styles/overview-events.css +318 -0
  67. package/extensions/dashboard-client/src/styles/repos-metrics.css +307 -0
  68. package/extensions/dashboard-client/src/tabs/ConfigTab.tsx +16 -0
  69. package/extensions/dashboard-client/src/tabs/EventsTab.tsx +37 -0
  70. package/extensions/dashboard-client/src/tabs/MetricsTab.tsx +49 -0
  71. package/extensions/dashboard-client/src/tabs/OverviewTab.tsx +80 -0
  72. package/extensions/dashboard-client/src/tabs/ReposTab.tsx +59 -0
  73. package/extensions/dashboard-client/tsconfig.json +28 -0
  74. package/extensions/dashboard-client/vite.config.ts +38 -0
  75. package/extensions/dashboard-server/api-contracts/core.ts +302 -0
  76. package/extensions/dashboard-server/api-contracts/endpoints.ts +476 -0
  77. package/extensions/dashboard-server/api-contracts/game.ts +145 -0
  78. package/extensions/dashboard-server/api-contracts/index.ts +159 -0
  79. package/extensions/dashboard-server/api-contracts/infrastructure.ts +465 -0
  80. package/extensions/dashboard-server/api-contracts/multi-repo.ts +328 -0
  81. package/extensions/dashboard-server/api-contracts/snapshot.ts +386 -0
  82. package/extensions/dashboard-server/api-contracts.test.ts +1050 -0
  83. package/extensions/dashboard-server/api-contracts.ts +96 -0
  84. package/extensions/dashboard-server/auth.ts +20 -0
  85. package/extensions/dashboard-server/server.ts +862 -582
  86. package/extensions/dashboard-server/tailscale.ts +7 -0
  87. package/extensions/dashboard-server/types.ts +23 -114
  88. package/package.json +2 -1
@@ -0,0 +1,159 @@
1
+ /**
2
+ * api-contracts/index.ts — Barrel re-export for all API contract domains.
3
+ *
4
+ * Import from this file to access all types:
5
+ * import type { SnapshotResponse, RepoListItem } from '../api-contracts';
6
+ * // or explicitly:
7
+ * import type { SnapshotResponse } from '../api-contracts/snapshot';
8
+ */
9
+
10
+ // Core types
11
+ export type {
12
+ HttpMethod,
13
+ EndpointDef,
14
+ SseCompactStart,
15
+ SseCompactEnd,
16
+ SseCompactTrigger,
17
+ SseCompactSkip,
18
+ SseTierChanged,
19
+ SseModelChanged,
20
+ SsePressureLifted,
21
+ SseCheckpointPersisted,
22
+ SseRecallInject,
23
+ SseAnchorsUpdated,
24
+ SseConfigUpdated,
25
+ SseConfigPreset,
26
+ SseCrewPresenceChanged,
27
+ SseCrewTurnChanged,
28
+ SseCrewBanditChosen,
29
+ } from './core.js';
30
+
31
+ // Snapshot / store / compression / session
32
+ export type {
33
+ SnapshotResponse,
34
+ TriggerResponse,
35
+ CompressionTotalsResponse,
36
+ CompactHistoryEntry,
37
+ CompactionRequest,
38
+ CompactionResponse,
39
+ } from './snapshot.js';
40
+
41
+ // Multi-repo index and repo management
42
+ export type {
43
+ RepoListItem,
44
+ RepoSnapshotEntry,
45
+ RepoSnapshotMap,
46
+ IndexesIndexRow,
47
+ IndexesSummaryResponse,
48
+ IndexesDiffEntry,
49
+ DiffRequest,
50
+ SnapshotLike,
51
+ DiffResponse,
52
+ UpdateRepoConfigRequest,
53
+ } from './multi-repo.js';
54
+
55
+ // Game mode and mega-game
56
+ export type {
57
+ GameConfig,
58
+ GameStateResponse,
59
+ GameRitualStage,
60
+ SseGameRitualStart,
61
+ SseGameRitualStage,
62
+ SseGameRitualEnd,
63
+ SseGameModeChanged,
64
+ SseGameRender,
65
+ } from './game.js';
66
+
67
+ // Infrastructure, diagnostics, and monitoring
68
+ export type {
69
+ InfraHealthResponse,
70
+ InfraPerfSampleResponse,
71
+ InfraRateLimitStatus,
72
+ InfraRateLimitResponse,
73
+ ContextLevelState,
74
+ TierOverrideState,
75
+ FallbackState,
76
+ RepeatInjectionState,
77
+ SupersedeGatingState,
78
+ MinHashBandState,
79
+ } from './infrastructure.js';
80
+
81
+ // Composite SSE event union (domain imports for type composition)
82
+ import type {
83
+ SseGameRitualStart,
84
+ SseGameRitualStage,
85
+ SseGameRitualEnd,
86
+ SseGameModeChanged,
87
+ SseGameRender,
88
+ } from './game.js';
89
+
90
+ import type {
91
+ SseCompactStart,
92
+ SseCompactEnd,
93
+ SseCompactTrigger,
94
+ SseCompactSkip,
95
+ SseTierChanged,
96
+ SseModelChanged,
97
+ SsePressureLifted,
98
+ SseCheckpointPersisted,
99
+ SseRecallInject,
100
+ SseAnchorsUpdated,
101
+ SseConfigUpdated,
102
+ SseConfigPreset,
103
+ SseCrewPresenceChanged,
104
+ SseCrewTurnChanged,
105
+ SseCrewBanditChosen,
106
+ } from './core.js';
107
+
108
+ // Endpoints registry (Sprint A1)
109
+ export type {
110
+ VersionResponse,
111
+ IndexSummary,
112
+ IndexFallbackResponse,
113
+ ReposQuery,
114
+ ReposResponse,
115
+ SummaryResponse,
116
+ DriftSeverity,
117
+ DriftSignal,
118
+ RepoDrift,
119
+ DriftReportResponse,
120
+ ServerEntry,
121
+ ServersResponse,
122
+ PerfPercentile,
123
+ PerfAverage,
124
+ PerfLatest,
125
+ PerfCacheHit,
126
+ PerfDiag,
127
+ PerfQuery,
128
+ PerfResponse,
129
+ GameScoreRow,
130
+ GameScoresQuery,
131
+ AchievementRow,
132
+ GameStatePatch,
133
+ SseEndpointDef,
134
+ } from './endpoints.js';
135
+
136
+ export { ENDPOINTS } from './endpoints.js';
137
+
138
+ /** Union of all SSE event types the client may receive. */
139
+ export type SseEvent =
140
+ | SseCompactStart
141
+ | SseCompactEnd
142
+ | SseCompactTrigger
143
+ | SseCompactSkip
144
+ | SseTierChanged
145
+ | SseModelChanged
146
+ | SsePressureLifted
147
+ | SseCheckpointPersisted
148
+ | SseRecallInject
149
+ | SseAnchorsUpdated
150
+ | SseConfigUpdated
151
+ | SseConfigPreset
152
+ | SseCrewPresenceChanged
153
+ | SseCrewTurnChanged
154
+ | SseCrewBanditChosen
155
+ | SseGameRitualStart
156
+ | SseGameRitualStage
157
+ | SseGameRitualEnd
158
+ | SseGameModeChanged
159
+ | SseGameRender;
@@ -0,0 +1,465 @@
1
+ /**
2
+ * api-contracts/infrastructure.ts — Infrastructure, diagnostics, and monitoring contracts.
3
+ *
4
+ * Contains: InfraHealthResponse, InfraPerfSampleResponse,
5
+ * InfraRateLimitStatus, InfraRateLimitResponse, ContextLevelState,
6
+ * TierOverrideState, FallbackState, RepeatInjectionState,
7
+ * SupersedeGatingState, MinHashBandState.
8
+ * Extracted from api-contracts.ts (Sprint A1 split).
9
+ */
10
+
11
+ // ─── /api/health ───────────────────────────────────────────────────────────
12
+
13
+ /**
14
+ * Response body for `GET /api/health`.
15
+ *
16
+ * Reports the overall health, uptime, version, and database status of the
17
+ * dashboard server.
18
+ */
19
+ export interface InfraHealthResponse {
20
+ /**
21
+ * Overall health status.
22
+ * Allowed values: `'ok'`, `'degraded'`, `'error'`.
23
+ */
24
+ status: 'ok' | 'degraded' | 'error';
25
+ /** Server uptime since last restart (seconds). */
26
+ uptime: number;
27
+ /** Extension version string. */
28
+ version: string;
29
+ /**
30
+ * Database health status.
31
+ * Allowed values: `'ok'`, `'error'`.
32
+ */
33
+ db: 'ok' | 'error';
34
+ }
35
+
36
+ // ─── /api/perf ─────────────────────────────────────────────────────────────
37
+
38
+ /**
39
+ * Response body for `GET /api/perf`.
40
+ *
41
+ * Provides performance samples (percentiles, TPS, cache hit rate, latency),
42
+ * aggregate counters, storage statistics, and active model information.
43
+ */
44
+ export interface InfraPerfSampleResponse {
45
+ /** ISO 8601 timestamp of the last performance sample update. */
46
+ updatedAt: string;
47
+ /** Performance percentile samples, or `null` when no samples are available. */
48
+ samples: {
49
+ /** p50 compaction duration (milliseconds). */
50
+ compactP50: number;
51
+ /** p95 compaction duration (milliseconds). */
52
+ compactP95: number;
53
+ /** Tokens per second processing rate (tokens per second). */
54
+ tps: number;
55
+ /** Cache hit rate (percent, 0–100). */
56
+ cacheHitPct: number;
57
+ /** p50 request latency (milliseconds). */
58
+ latencyP50: number;
59
+ /** p95 request latency (milliseconds). */
60
+ latencyP95: number;
61
+ /** Per-tier dedup check counts. */
62
+ checks: {
63
+ /** L0 exact-hash dedup check count. */
64
+ l0_exact: number;
65
+ /** L1 MinHash dedup check count. */
66
+ l1_minhash: number;
67
+ /** L1 LSH dedup check count. */
68
+ l1_lsh: number;
69
+ /** L2 semantic dedup check count. */
70
+ l2_dedup: number;
71
+ /** RAPTOR tree dedup check count. */
72
+ raptor_tree: number;
73
+ };
74
+ } | null;
75
+ /** Aggregate operational counters. */
76
+ counters: {
77
+ /** Compaction run counts. */
78
+ compacts: {
79
+ /** Compactions performed this session. */
80
+ session: number;
81
+ /** Total compactions performed. */
82
+ total: number;
83
+ };
84
+ /** Cache hit statistics. */
85
+ cacheHits: {
86
+ /** Cache hits in the current session. */
87
+ session: number;
88
+ /** Total cache hits across all sessions. */
89
+ total: number;
90
+ /** Tokens saved by cache hits this session (tokens). */
91
+ sessionTokensSaved: number;
92
+ /** Total tokens saved by cache hits (tokens). */
93
+ totalTokensSaved: number;
94
+ };
95
+ /** Time saved by compaction and cache hits. */
96
+ timeSaved: {
97
+ /** Time saved by compaction. */
98
+ compact: {
99
+ /** Seconds saved by compaction this session (seconds). */
100
+ sessionSec: number;
101
+ /** Total seconds saved by compaction (seconds). */
102
+ totalSec: number;
103
+ };
104
+ /** Time saved by cache hits. */
105
+ cacheHit: {
106
+ /** Seconds saved by cache hits this session (seconds). */
107
+ sessionSec: number;
108
+ /** Total seconds saved by cache hits (seconds). */
109
+ totalSec: number;
110
+ };
111
+ };
112
+ /** Storage-level dedup statistics. */
113
+ storage: {
114
+ /** Number of dedup hits at the storage level. */
115
+ dedupHits: number;
116
+ /** Number of dedup attempts at the storage level. */
117
+ dedupAttempts: number;
118
+ /** Compressed byte size (bytes). */
119
+ compressedBytes: number;
120
+ /** Compression ratio at the storage level (percent, 0–100). */
121
+ compressionPct: number;
122
+ };
123
+ };
124
+ /** Active model information, or `null` when no model is configured. */
125
+ model: {
126
+ /** Model name/identifier. */
127
+ name: string;
128
+ /** Machine-readable provider identifier. */
129
+ provider: string;
130
+ /** Human-readable provider name. */
131
+ providerName: string;
132
+ /** Model input processing rate (tokens per second). */
133
+ inputRate: number;
134
+ /** Model output processing rate (tokens per second). */
135
+ outputRate: number;
136
+ } | null;
137
+ }
138
+
139
+ // ─── /api/rate-limit ───────────────────────────────────────────────────────
140
+
141
+ /**
142
+ * Rate-limit status for the dashboard API.
143
+ *
144
+ * Used as the `status` field in `InfraRateLimitResponse`.
145
+ */
146
+ export interface InfraRateLimitStatus {
147
+ /** Request rate-limit window configuration. */
148
+ requests: {
149
+ /** Duration of the rate-limit window (milliseconds). */
150
+ windowMs: number;
151
+ /** Maximum requests allowed within the window. */
152
+ limit: number;
153
+ /** Remaining requests in the current window. */
154
+ remaining: number;
155
+ /** ISO 8601 timestamp when the window resets. */
156
+ resetAt: string;
157
+ };
158
+ /** Compaction rate-limit status. */
159
+ compact: {
160
+ /** Number of pending compaction requests. */
161
+ pending: number;
162
+ /** Number of actively running compactions. */
163
+ active: number;
164
+ /** ISO 8601 timestamp of the earliest queued compaction, or `null` when no compactions are queued. */
165
+ queuedAt: string | null;
166
+ };
167
+ }
168
+
169
+ /**
170
+ * Response body for `GET /api/rate-limit`.
171
+ *
172
+ * Wraps the rate-limit status object.
173
+ */
174
+ export interface InfraRateLimitResponse {
175
+ /** Current rate-limit status. */
176
+ status: InfraRateLimitStatus;
177
+ }
178
+
179
+ // ─── /api/context-level ────────────────────────────────────────────────────
180
+
181
+ /**
182
+ * Response body for `GET /api/context-level`.
183
+ *
184
+ * Reports the current context pressure level, configured thresholds, tier
185
+ * information, and tier transition history.
186
+ */
187
+ export interface ContextLevelState {
188
+ /** Current context pressure (percent, 0–100). */
189
+ currentPct: number;
190
+ /** Pressure thresholds for each level. */
191
+ thresholds: {
192
+ /** Pressure at which the `'watch'` level activates (percent, 0–100). */
193
+ watch: number;
194
+ /** Pressure at which the `'alert'` level activates (percent, 0–100). */
195
+ alert: number;
196
+ /** Pressure at which the `'critical'` level activates (percent, 0–100). */
197
+ critical: number;
198
+ };
199
+ /**
200
+ * Current context level based on pressure vs thresholds.
201
+ * Allowed values: `'normal'`, `'watch'`, `'alert'`, `'critical'`.
202
+ */
203
+ currentLevel: 'normal' | 'watch' | 'alert' | 'critical';
204
+ /** Configuration affecting context pressure and tier selection. */
205
+ config: {
206
+ /** Pressure baseline (percent, 0–100). */
207
+ pressure: number;
208
+ /** Fast-gate pressure threshold (percent, 0–100). */
209
+ fastGatePct: number;
210
+ /** Tier multiplier applied to thresholds. */
211
+ tierMultiplier: number;
212
+ };
213
+ /** Currently active compaction tier name. */
214
+ activeTier: string;
215
+ /** Preset (default) compaction tier name. */
216
+ presetTier: string;
217
+ /** History of recent tier transitions. */
218
+ tierHistory: Array<{
219
+ /** ISO 8601 timestamp of the transition. */
220
+ at: string;
221
+ /** Previous tier name. */
222
+ from: string;
223
+ /** New tier name. */
224
+ to: string;
225
+ /** Context pressure at the time of transition (percent, 0–100). */
226
+ contextPct: number;
227
+ }>;
228
+ /** Maximum context window size for the active model (tokens). */
229
+ contextWindow: number;
230
+ }
231
+
232
+ // ─── /api/tier-override ────────────────────────────────────────────────────
233
+
234
+ /**
235
+ * Response body for `GET /api/tier-override`.
236
+ *
237
+ * Reports whether the compaction tier is currently overridden and, if so,
238
+ * the override details.
239
+ */
240
+ export interface TierOverrideState {
241
+ /** Currently active compaction tier name (may be overridden). */
242
+ currentTier: string;
243
+ /** Preset (default) compaction tier name. */
244
+ presetTier: string;
245
+ /** Whether the tier is currently overridden. */
246
+ isOverridden: boolean;
247
+ /** Override details. Present when `isOverridden` is `true`; `null` when no override is active. */
248
+ override: {
249
+ /** Compaction tier name set by the override. */
250
+ tier: string;
251
+ /** Human-readable reason for the override. */
252
+ reason: string;
253
+ /** ISO 8601 timestamp when the override was set. */
254
+ setAt: string;
255
+ } | null;
256
+ }
257
+
258
+ // ─── /api/fallback ────────────────────────────────────────────────────────
259
+
260
+ /**
261
+ * Response body for `GET /api/fallback`.
262
+ *
263
+ * Reports the model fallback state, including degradation status, attempt
264
+ * counts, and fallback transition history.
265
+ */
266
+ export interface FallbackState {
267
+ /** Current number of fallback attempts. */
268
+ currentAttempts: number;
269
+ /** Maximum fallback attempts before entering degraded mode. */
270
+ maxAttempts: number;
271
+ /** Threshold at which degradation kicks in. */
272
+ degradeThreshold: number;
273
+ /** Current fallback mode name, or `null` when no fallback is active. */
274
+ fallbackMode: string | null;
275
+ /** Whether the system is currently in degraded mode. */
276
+ degraded: boolean;
277
+ /** History of fallback transitions. */
278
+ history: Array<{
279
+ /** ISO 8601 timestamp of the transition. */
280
+ at: string;
281
+ /** Previous mode name. */
282
+ from: string;
283
+ /** New mode name. */
284
+ to: string;
285
+ /** Trigger that caused the transition. */
286
+ trigger: string;
287
+ }>;
288
+ }
289
+
290
+ // ─── /api/repeat-injection ─────────────────────────────────────────────────
291
+
292
+ /**
293
+ * Response body for `GET /api/repeat-injection`.
294
+ *
295
+ * Reports the state of repeat-injection protection, including protected
296
+ * messages, seen hashes, retention configuration, and memory/index statistics.
297
+ */
298
+ export interface RepeatInjectionState {
299
+ /** Indices of messages currently protected from re-injection. */
300
+ protectedMessages: number[];
301
+ /** Content hashes already seen by the repeat-injection guard. */
302
+ seenHashes: string[];
303
+ /** Number of recent messages in the retention window. */
304
+ retentionWindow: number;
305
+ /** Repeat-injection statistics. */
306
+ stats: {
307
+ /** Total number of chunks injected. */
308
+ totalInjected: number;
309
+ /** Number of repeat injections blocked. */
310
+ repeatBlocked: number;
311
+ /** Ratio of repeats blocked to total injections (0–1). */
312
+ repeatRatio: number;
313
+ /** Number of anchor messages preserved. */
314
+ anchorPreserved: number;
315
+ /** Configured `preserveRecent` value (number of messages). */
316
+ configPreserveRecent: number;
317
+ /** Effective retention window after configuration adjustments. */
318
+ effectiveRetention: number;
319
+ };
320
+ /** Interaction-level protection state. */
321
+ interaction: {
322
+ /** Number of recent messages actually preserved in the last interaction. */
323
+ preservedRecent: number;
324
+ /** Protection floor — minimum messages always preserved. */
325
+ protectionFloor: number;
326
+ /** Fast-gate pressure threshold (percent, 0–100). */
327
+ fastGatePct: number;
328
+ /** Size of the current context payload (bytes). */
329
+ payloadSize: number;
330
+ /** Number of compactions performed. */
331
+ compactCount: number;
332
+ };
333
+ /** Memory and index configuration. */
334
+ memory: {
335
+ /** Number of RAPTOR prototypes stored. */
336
+ raptorPrototypes: number;
337
+ /** Number of semantic hash prototypes. */
338
+ semHashProto: number;
339
+ /** Embedding vector dimensionality (dimensions). */
340
+ embedDim: number;
341
+ /** Band similarity threshold for MinHash LSH (0–1). */
342
+ bandThreshold: number;
343
+ /** Top-K recall limit. */
344
+ topK: number;
345
+ /** Number of recent messages in the memory window. */
346
+ recentWindow: number;
347
+ };
348
+ }
349
+
350
+ // ─── /api/supersede-gating ─────────────────────────────────────────────────
351
+
352
+ /**
353
+ * Response body for `GET /api/supersede-gating`.
354
+ *
355
+ * Reports the state of the supersede gating mechanism, including thresholds,
356
+ * strategy, statistics, and history.
357
+ */
358
+ export interface SupersedeGatingState {
359
+ /** Whether supersede gating is currently active. */
360
+ gating: boolean;
361
+ /** Low token threshold below which supersede is disabled (tokens). */
362
+ low: number;
363
+ /** High token threshold above which supersede is enabled (tokens). */
364
+ high: number;
365
+ /** Effective minimum token count for supersede eligibility (tokens). */
366
+ effectiveMin: number;
367
+ /** Supersede configuration. */
368
+ config: {
369
+ /** Configured minimum token threshold (tokens). */
370
+ minTokens: number;
371
+ /** Total original tokens in the eligible set (tokens). */
372
+ totalOriginal: number;
373
+ /** Maximum supersede nesting depth. */
374
+ maxDepth: number;
375
+ };
376
+ /** Current supersede strategy. */
377
+ strategy: {
378
+ /** Compaction tier applied by the strategy. */
379
+ tier: string;
380
+ /** Age threshold for eligibility (hours). */
381
+ ageHours: number;
382
+ /** Query shrink factor applied by the strategy (percent, 0–100). */
383
+ queryShrink: number;
384
+ };
385
+ /** Supersede statistics. */
386
+ stats: {
387
+ /** Number of chunks superseded. */
388
+ superseded: number;
389
+ /** Number of chunks not eligible for supersede. */
390
+ notEligible: number;
391
+ /** Number of chunks below the minimum token threshold (tokens). */
392
+ belowMinTokens: number;
393
+ /** Sum of tokens pinned (not superseded) (tokens). */
394
+ sumTokensPinned: number;
395
+ /** Sum of bytes pinned (not superseded) (bytes). */
396
+ sumBytesPinned: number;
397
+ /** Sum of bytes in duplicate chunks (bytes). */
398
+ sumBytesDuplicate: number;
399
+ /** Sum of bytes before eligibility filtering (bytes). */
400
+ sumBytesBeforeEligible: number;
401
+ /** Sum of bytes after eligibility filtering (bytes). */
402
+ sumBytesAfterEligible: number;
403
+ };
404
+ /** History of supersede gating events. */
405
+ history: Array<{
406
+ /** ISO 8601 timestamp of the event. */
407
+ at: string;
408
+ /** Chunk identifier involved. */
409
+ chunkId: string;
410
+ /** Reason for the gating decision. */
411
+ reason: string;
412
+ }>;
413
+ }
414
+
415
+ // ─── /api/minhash-bands ───────────────────────────────────────────────────
416
+
417
+ /**
418
+ * Response body for `GET /api/minhash-bands`.
419
+ *
420
+ * Reports the state of the MinHash LSH banding configuration, including band
421
+ * parameters, matching statistics, and estimated dedup rates.
422
+ */
423
+ export interface MinHashBandState {
424
+ /** Number of hashes per band. */
425
+ bandSize: number;
426
+ /** Total number of bands in the LSH index. */
427
+ numBands: number;
428
+ /** Number of bands with matching hash pairs. */
429
+ matchingBands: number;
430
+ /** Number of candidate pairs generated by band matching. */
431
+ candidatePairs: number;
432
+ /** Total number of hashes stored. */
433
+ totalHashes: number;
434
+ /** MinHash LSH configuration. */
435
+ config: {
436
+ /** Similarity threshold for candidate selection (0–1). */
437
+ threshold: number;
438
+ /** Total number of hash functions used. */
439
+ numHashes: number;
440
+ /** Salt value used for hash randomization. */
441
+ salt: string;
442
+ };
443
+ /** Dedup estimation and accuracy statistics. */
444
+ stats: {
445
+ /** Estimated number of duplicates detected (count). */
446
+ estimatedDedup: number;
447
+ /** Estimated false negative rate (0–1). */
448
+ falseNegativeRate: number;
449
+ /** Estimated false positive rate (0–1). */
450
+ falsePositiveRate: number;
451
+ /** Number of cosine-similarity dedup hits. */
452
+ cosDedup: number;
453
+ /** Number of exact-hash dedup hits. */
454
+ exactDedup: number;
455
+ };
456
+ /** History of MinHash band events. */
457
+ history: Array<{
458
+ /** ISO 8601 timestamp of the event. */
459
+ at: string;
460
+ /** Hash identifier involved. */
461
+ hashId: string;
462
+ /** Band number that matched. */
463
+ band: number;
464
+ }>;
465
+ }