pi-mega-compact 0.8.7 → 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 (110) 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/html.js +46 -1
  23. package/dist/extensions/dashboard-server/perf-server.test.js +80 -0
  24. package/dist/extensions/dashboard-server/server.js +269 -30
  25. package/dist/extensions/dashboard-server/tailscale.js +8 -0
  26. package/dist/extensions/dashboard-server/types.js +4 -0
  27. package/dist/extensions/mega-dashboard.js +9 -0
  28. package/dist/extensions/mega-events/perf-handler.js +71 -0
  29. package/dist/extensions/mega-events/register.js +2 -0
  30. package/dist/extensions/mega-events.js +1 -0
  31. package/dist/extensions/mega-runtime/state.js +59 -1
  32. package/dist/src/store/sqlite/connection.js +35 -0
  33. package/dist/src/store/sqlite/index-store.js +167 -0
  34. package/dist/src/store/sqlite/memory.js +54 -0
  35. package/dist/src/store/sqlite/minhash-lsh.js +47 -0
  36. package/dist/src/store/sqlite/perf-samples.js +81 -0
  37. package/dist/src/store/sqlite/perf-samples.test.js +54 -0
  38. package/dist/src/store/sqlite/schema.js +14 -0
  39. package/dist/src/store/sqlite/sessions.js +39 -0
  40. package/dist/src/store/sqlite/transaction.js +19 -0
  41. package/dist/src/store/sqlite.js +1 -0
  42. package/dist/src/vectorStore/add.js +260 -0
  43. package/dist/src/vectorStore/dedup.js +52 -0
  44. package/dist/src/vectorStore/index.js +10 -0
  45. package/dist/src/vectorStore/queries.js +83 -0
  46. package/dist/src/vectorStore/search.js +95 -0
  47. package/dist/src/vectorStore/session.js +19 -0
  48. package/dist/src/vectorStore/store.js +105 -0
  49. package/dist/src/vectorStore/types.js +6 -0
  50. package/dist/src/vectorStore/utils.js +23 -0
  51. package/extensions/dashboard-client/package-lock.json +1771 -0
  52. package/extensions/dashboard-client/package.json +27 -0
  53. package/extensions/dashboard-client/src/App.tsx +82 -0
  54. package/extensions/dashboard-client/src/api/client.ts +145 -0
  55. package/extensions/dashboard-client/src/components/CacheStatusPerModel.tsx +44 -0
  56. package/extensions/dashboard-client/src/components/CompressionCard.tsx +61 -0
  57. package/extensions/dashboard-client/src/components/ContextGauge.tsx +59 -0
  58. package/extensions/dashboard-client/src/components/DataSafetyCard.tsx +49 -0
  59. package/extensions/dashboard-client/src/components/ErrorBoundary.tsx +53 -0
  60. package/extensions/dashboard-client/src/components/EventCategoryFilter.tsx +16 -0
  61. package/extensions/dashboard-client/src/components/EventStream.tsx +152 -0
  62. package/extensions/dashboard-client/src/components/LoadingSpinner.tsx +7 -0
  63. package/extensions/dashboard-client/src/components/MemoryStatusCard.tsx +24 -0
  64. package/extensions/dashboard-client/src/components/ModelBadge.tsx +41 -0
  65. package/extensions/dashboard-client/src/components/PerfChart.tsx +160 -0
  66. package/extensions/dashboard-client/src/components/RepoDetailModal.tsx +126 -0
  67. package/extensions/dashboard-client/src/components/RepoTable.tsx +150 -0
  68. package/extensions/dashboard-client/src/components/SessionInfo.tsx +65 -0
  69. package/extensions/dashboard-client/src/components/SummaryTiles.tsx +52 -0
  70. package/extensions/dashboard-client/src/components/TabBar.tsx +34 -0
  71. package/extensions/dashboard-client/src/components/TriggerStatus.tsx +62 -0
  72. package/extensions/dashboard-client/src/hooks/useApi.ts +77 -0
  73. package/extensions/dashboard-client/src/hooks/useSSE.ts +87 -0
  74. package/extensions/dashboard-client/src/index.html +12 -0
  75. package/extensions/dashboard-client/src/main.tsx +23 -0
  76. package/extensions/dashboard-client/src/styles/base.css +121 -0
  77. package/extensions/dashboard-client/src/styles/overview-events.css +318 -0
  78. package/extensions/dashboard-client/src/styles/repos-metrics.css +307 -0
  79. package/extensions/dashboard-client/src/tabs/ConfigTab.tsx +16 -0
  80. package/extensions/dashboard-client/src/tabs/EventsTab.tsx +37 -0
  81. package/extensions/dashboard-client/src/tabs/MetricsTab.tsx +49 -0
  82. package/extensions/dashboard-client/src/tabs/OverviewTab.tsx +80 -0
  83. package/extensions/dashboard-client/src/tabs/ReposTab.tsx +59 -0
  84. package/extensions/dashboard-client/tsconfig.json +28 -0
  85. package/extensions/dashboard-client/vite.config.ts +38 -0
  86. package/extensions/dashboard-server/api-contracts/core.ts +302 -0
  87. package/extensions/dashboard-server/api-contracts/endpoints.ts +476 -0
  88. package/extensions/dashboard-server/api-contracts/game.ts +145 -0
  89. package/extensions/dashboard-server/api-contracts/index.ts +159 -0
  90. package/extensions/dashboard-server/api-contracts/infrastructure.ts +465 -0
  91. package/extensions/dashboard-server/api-contracts/multi-repo.ts +328 -0
  92. package/extensions/dashboard-server/api-contracts/snapshot.ts +386 -0
  93. package/extensions/dashboard-server/api-contracts.test.ts +1050 -0
  94. package/extensions/dashboard-server/api-contracts.ts +96 -0
  95. package/extensions/dashboard-server/auth.ts +20 -0
  96. package/extensions/dashboard-server/html.ts +46 -1
  97. package/extensions/dashboard-server/perf-server.test.ts +101 -0
  98. package/extensions/dashboard-server/server.ts +862 -503
  99. package/extensions/dashboard-server/tailscale.ts +7 -0
  100. package/extensions/dashboard-server/types.ts +23 -114
  101. package/extensions/mega-dashboard.ts +17 -0
  102. package/extensions/mega-events/perf-handler.ts +113 -0
  103. package/extensions/mega-events/register.ts +2 -0
  104. package/extensions/mega-events.ts +1 -0
  105. package/extensions/mega-runtime/state.ts +57 -0
  106. package/package.json +2 -1
  107. package/src/store/sqlite/perf-samples.test.ts +65 -0
  108. package/src/store/sqlite/perf-samples.ts +125 -0
  109. package/src/store/sqlite/schema.ts +14 -0
  110. package/src/store/sqlite.ts +1 -0
@@ -0,0 +1,328 @@
1
+ /**
2
+ * api-contracts/multi-repo.ts — Multi-repo index and repo management contracts.
3
+ *
4
+ * Contains: RepoListItem, RepoSnapshotEntry, RepoSnapshotMap,
5
+ * IndexesIndexRow, IndexesSummaryResponse, IndexesDiffEntry,
6
+ * DiffRequest, DiffResponse, UpdateRepoConfigRequest.
7
+ * Extracted from api-contracts.ts (Sprint A1 split).
8
+ */
9
+
10
+ // ─── /api/repos ────────────────────────────────────────────────────────────
11
+
12
+ /**
13
+ * Response item for `GET /api/repos`.
14
+ *
15
+ * Represents a single repository in the multi-repo index list.
16
+ */
17
+ export interface RepoListItem {
18
+ /** Unique repository identifier. */
19
+ id: string;
20
+ /** Filesystem path to the repository root. */
21
+ path: string;
22
+ /** Human-readable repository display name. */
23
+ name: string;
24
+ /** Number of sessions recorded for this repository. */
25
+ sessionCount: number;
26
+ /** Total token count across all sessions for this repository (tokens). */
27
+ tokenTotal: number;
28
+ /** Epoch timestamp of the last activity for this repository (milliseconds since Unix epoch). */
29
+ lastSeen: number;
30
+ }
31
+
32
+ // ─── /api/repo-snapshot ────────────────────────────────────────────────────
33
+
34
+ /**
35
+ * Response item for `GET /api/repo-snapshot`.
36
+ *
37
+ * Per-repository snapshot entry containing tier, pressure, session, context,
38
+ * store, compression, and model information.
39
+ */
40
+ export interface RepoSnapshotEntry {
41
+ /** ISO 8601 timestamp of the last update, or `null` if never updated. */
42
+ updatedAt: string | null;
43
+ /** Currently active compaction tier name for this repo. */
44
+ tier: string;
45
+ /** Preset (default) compaction tier name for this repo. */
46
+ presetTier: string;
47
+ /** Current context pressure for this repo (percent, 0–100). */
48
+ pressure: number;
49
+ /** Session state for this repo. */
50
+ session: {
51
+ /** Active session ID, or `null` when no session is active. */
52
+ id: string | null;
53
+ /** Session lifecycle state (e.g. `'idle'`, `'compacting'`), or `null` when no session is active. */
54
+ state: string | null;
55
+ };
56
+ /** Context window utilization for this repo. */
57
+ context: {
58
+ /** Current token count, or `null` if unknown (tokens). */
59
+ tokens: number | null;
60
+ /** Context window usage, or `null` if unknown (percent, 0–100). */
61
+ percent: number | null;
62
+ /** Maximum context window size for the active model (tokens). */
63
+ contextWindow: number;
64
+ };
65
+ /** Store metrics for this repo. */
66
+ store: {
67
+ /** Number of checkpoints for this repo. */
68
+ checkpointCount: number;
69
+ /** Tokens saved for this repo (tokens). */
70
+ tokensSaved: number;
71
+ /** Number of duplicate chunks collapsed for this repo. */
72
+ dedupCollapsed: number;
73
+ /** Storage deduplication rate for this repo (percent, 0–100). */
74
+ storageDedupRate: number;
75
+ };
76
+ /** Compression statistics for this repo. */
77
+ compression: {
78
+ /** Session-level compression. */
79
+ session: {
80
+ /** Input tokens for the session (tokens). */
81
+ tokensIn: number;
82
+ /** Output tokens after compression (tokens). */
83
+ tokensOut: number;
84
+ /** Tokens freed by compression (tokens). */
85
+ tokensFreed: number;
86
+ /** Compression ratio (percent, 0–100). */
87
+ compressionPct: number;
88
+ /** Dedup contribution (percent, 0–100). */
89
+ dedupPct: number;
90
+ };
91
+ /** Repo-level compression. */
92
+ repo: {
93
+ /** Input tokens for the repo (tokens). */
94
+ tokensIn: number;
95
+ /** Output tokens after compression (tokens). */
96
+ tokensOut: number;
97
+ /** Tokens freed by compression (tokens). */
98
+ tokensFreed: number;
99
+ /** Compression ratio (percent, 0–100). */
100
+ compressionPct: number;
101
+ /** Dedup contribution (percent, 0–100). */
102
+ dedupPct: number;
103
+ };
104
+ };
105
+ /** Active model information for this repo. Present when a model is configured; absent otherwise. */
106
+ model?: {
107
+ /** Model name/identifier. */
108
+ name: string;
109
+ /** Machine-readable provider identifier. */
110
+ provider: string;
111
+ /** Human-readable provider name. */
112
+ providerName: string;
113
+ /** Model input processing rate (tokens per second). */
114
+ inputRate: number;
115
+ /** Model output processing rate (tokens per second). */
116
+ outputRate: number;
117
+ };
118
+ }
119
+
120
+ /**
121
+ * Map of repository IDs to their snapshot entries.
122
+ *
123
+ * Used as the response body for `GET /api/repo-snapshot`.
124
+ * Values are `null` when a repo has no snapshot data.
125
+ */
126
+ export type RepoSnapshotMap = Record<string, RepoSnapshotEntry | null>;
127
+
128
+ // ─── /api/indexes ──────────────────────────────────────────────────────────
129
+
130
+ /**
131
+ * Row in the `GET /api/index` response.
132
+ *
133
+ * Represents a single repository's index entry with checkpoint, token,
134
+ * compression, model, and configuration details.
135
+ */
136
+ export interface IndexesIndexRow {
137
+ /** Filesystem path to the repository root. */
138
+ repoRoot: string;
139
+ /** Human-readable display name for the repository. */
140
+ displayName: string;
141
+ /** State directory path for this repo's mega-compact data. */
142
+ stateDir: string;
143
+ /** Number of checkpoints stored for this repo. */
144
+ checkpointCount: number;
145
+ /** Total tokens saved for this repo (tokens). */
146
+ tokensSaved: number;
147
+ /** Original byte size of compressed data (bytes). */
148
+ compressedOriginalBytes: number;
149
+ /** Epoch timestamp of the last compaction, or `null` if never compacted (milliseconds since Unix epoch). */
150
+ lastCompactedAt: number | null;
151
+ /** Machine-readable provider identifier, or `null` if not configured. */
152
+ provider: string | null;
153
+ /** Human-readable provider name, or `null` if not configured. */
154
+ providerName: string | null;
155
+ /** Model name/identifier, or `null` if not configured. */
156
+ modelName: string | null;
157
+ /** Model input processing rate, or `null` if not configured (tokens per second). */
158
+ inputRate: number | null;
159
+ /** Model output processing rate, or `null` if not configured (tokens per second). */
160
+ outputRate: number | null;
161
+ /** Epoch timestamp of the last activity (milliseconds since Unix epoch). */
162
+ lastSeen: number;
163
+ /** Tokens retained after compaction (tokens). */
164
+ tokensKept: number;
165
+ /** Tokens dropped during compaction (tokens). */
166
+ tokensDropped: number;
167
+ /** Number of sessions recorded for this repo. */
168
+ sessions: number;
169
+ /** Maximum context window size, or `null` if not configured (tokens). */
170
+ contextWindow: number | null;
171
+ /** Maximum token limit, or `null` if not configured (tokens). */
172
+ maxTokens: number | null;
173
+ /** Whether reasoning/extended-thinking mode is enabled, or `null` if not configured. */
174
+ reasoning: boolean | null;
175
+ }
176
+
177
+ /**
178
+ * Response body for `GET /api/index`.
179
+ *
180
+ * Provides an aggregated summary of all repos plus a per-repo index row list.
181
+ */
182
+ export interface IndexesSummaryResponse {
183
+ /** ISO 8601 timestamp of the last index update. */
184
+ updatedAt: string;
185
+ /** Total number of repos in the index. */
186
+ totalRepos: number;
187
+ /** Total number of checkpoints across all repos. */
188
+ totalCheckpoints: number;
189
+ /** Total tokens saved across all repos (tokens). */
190
+ totalTokensSaved: number;
191
+ /** Total original compressed byte size across all repos (bytes). */
192
+ totalCompressedOriginalBytes: number;
193
+ /** Per-repo index rows. */
194
+ repos: IndexesIndexRow[];
195
+ }
196
+
197
+ // ─── /api/indexes/diff ─────────────────────────────────────────────────────
198
+
199
+ /**
200
+ * Single diff entry in the `GET /api/indexes/diff` response.
201
+ *
202
+ * Describes one change between a client-provided snapshot and the server's
203
+ * current state.
204
+ */
205
+ export interface IndexesDiffEntry {
206
+ /** Unique identifier for this diff entry. */
207
+ id: string;
208
+ /**
209
+ * Type of change detected.
210
+ * Allowed values: `'add'`, `'remove'`, `'change'`.
211
+ */
212
+ type: 'add' | 'remove' | 'change';
213
+ /** Repository involved in the diff. Present when the change is repo-specific; absent otherwise. */
214
+ repo?: string;
215
+ /** Field name that changed. Present for `'change'` type; absent otherwise. */
216
+ field?: string;
217
+ /** Previous value of the changed field. Present for `'change'` type; absent otherwise. */
218
+ before?: unknown;
219
+ /** New value of the changed field. Present for `'change'` and `'add'` types; absent otherwise. */
220
+ after?: unknown;
221
+ /**
222
+ * Severity of the change.
223
+ * Allowed values: `'info'`, `'warn'`, `'critical'`.
224
+ */
225
+ severity: 'info' | 'warn' | 'critical';
226
+ }
227
+
228
+ /**
229
+ * Request body for `POST /api/indexes/diff`.
230
+ *
231
+ * Specifies which side (client or server) is providing the snapshot for
232
+ * comparison, and optionally includes the snapshot itself.
233
+ */
234
+ export interface DiffRequest {
235
+ /**
236
+ * Which side is providing the snapshot for comparison.
237
+ * Allowed values: `'client'`, `'server'`.
238
+ */
239
+ side: 'client' | 'server';
240
+ /** Snapshot to compare against. Present when `side` is `'client'`; absent when `side` is `'server'` (server uses its own). */
241
+ snapshot?: SnapshotLike;
242
+ }
243
+
244
+ /**
245
+ * Minimal shape for snapshot comparison (avoids coupling to full SnapshotResponse).
246
+ *
247
+ * Used by `DiffRequest` and `DiffResponse` to represent a partial snapshot
248
+ * for drift detection.
249
+ */
250
+ export interface SnapshotLike {
251
+ /** ISO 8601 timestamp of the snapshot, or `null`. Absent when not available. */
252
+ updatedAt?: string | null;
253
+ /** Store metrics subset. Absent when not available. */
254
+ store?: {
255
+ /** Number of checkpoints. Absent when not available. */
256
+ checkpointCount?: number;
257
+ /** Tokens saved (tokens). Absent when not available. */
258
+ tokensSaved?: number;
259
+ };
260
+ /** Compression statistics subset. Absent when not available. */
261
+ compression?: {
262
+ /** Repo-level compression subset. Absent when not available. */
263
+ repo?: {
264
+ /** Input tokens (tokens). Absent when not available. */
265
+ tokensIn?: number;
266
+ /** Output tokens (tokens). Absent when not available. */
267
+ tokensOut?: number;
268
+ /** Compression ratio (percent, 0–100). Absent when not available. */
269
+ compressionPct?: number;
270
+ /** Dedup contribution (percent, 0–100). Absent when not available. */
271
+ dedupPct?: number;
272
+ };
273
+ /** Session-level compression subset. Absent when not available. */
274
+ session?: {
275
+ /** Input tokens (tokens). Absent when not available. */
276
+ tokensIn?: number;
277
+ /** Output tokens (tokens). Absent when not available. */
278
+ tokensOut?: number;
279
+ };
280
+ };
281
+ /** Session state subset. Absent when not available. */
282
+ session?: {
283
+ /** Active session ID, or `null`. Absent when not available. */
284
+ id?: string | null;
285
+ /** Session lifecycle state, or `null`. Absent when not available. */
286
+ state?: string | null;
287
+ };
288
+ /** Model info subset. Absent when not available. */
289
+ model?: {
290
+ /** Model name. Absent when not available. */
291
+ name?: string;
292
+ /** Provider identifier. Absent when not available. */
293
+ provider?: string;
294
+ };
295
+ /** Trigger state subset. Absent when not available. */
296
+ trigger?: {
297
+ /** Whether the trigger is armed. Absent when not available. */
298
+ armed?: boolean;
299
+ /** Whether the trigger is ready. Absent when not available. */
300
+ ready?: boolean;
301
+ };
302
+ }
303
+
304
+ /**
305
+ * Response body for `POST /api/indexes/diff`.
306
+ *
307
+ * Contains the list of detected diffs and the server's current snapshot.
308
+ */
309
+ export interface DiffResponse {
310
+ /** List of detected differences between client and server snapshots. */
311
+ diffs: IndexesDiffEntry[];
312
+ /** The server's current snapshot used as the comparison baseline. */
313
+ serverSnapshot: SnapshotLike;
314
+ }
315
+
316
+ // ─── PUT /api/repo-config ─────────────────────────────────────────────────
317
+
318
+ /**
319
+ * Request body for `PUT /api/repo-config`.
320
+ *
321
+ * Updates display configuration for a specific repository.
322
+ */
323
+ export interface UpdateRepoConfigRequest {
324
+ /** Repository identifier to update. */
325
+ repoId: string;
326
+ /** New display name for the repository. Absent when the display name should not be changed. */
327
+ displayName?: string;
328
+ }