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,302 @@
1
+ /**
2
+ * api-contracts/core.ts — Core types shared across all API domains.
3
+ *
4
+ * Contains: generic endpoint definition, HTTP method, SSE event types.
5
+ * Extracted from api-contracts.ts (Sprint A1 split).
6
+ */
7
+
8
+ // ─── Endpoint Method ────────────────────────────────────────────────────────
9
+
10
+ /**
11
+ * HTTP methods supported by the dashboard API.
12
+ *
13
+ * Allowed values: `'GET'`, `'PUT'`, `'POST'`.
14
+ */
15
+ export type HttpMethod = 'GET' | 'PUT' | 'POST';
16
+
17
+ // ─── Generic Endpoint Definition ────────────────────────────────────────────
18
+
19
+ /**
20
+ * Generic definition for a dashboard API endpoint.
21
+ *
22
+ * Each concrete endpoint in the `ENDPOINTS` registry is an instance of this
23
+ * interface, carrying the HTTP method, path, human-readable description, and
24
+ * optional typed request/response schemas.
25
+ *
26
+ * @template M - The HTTP method (GET, PUT, or POST).
27
+ * @template Req - The request body or query-string shape (if any).
28
+ * @template Res - The response body shape.
29
+ */
30
+ export interface EndpointDef<M extends HttpMethod, Req, Res> {
31
+ /** HTTP method for this endpoint. */
32
+ readonly method: M;
33
+ /** URL path beginning with `/api/`. */
34
+ readonly path: string;
35
+ /** Human-readable summary of the endpoint's purpose. */
36
+ readonly description: string;
37
+ /** Request schema (body or query params), present when the endpoint accepts input. */
38
+ readonly requestSchema?: Req;
39
+ /** Response schema, present when the endpoint returns a typed body. */
40
+ readonly responseSchema?: Res;
41
+ }
42
+
43
+ // ─── SSE Event Types ────────────────────────────────────────────────────────
44
+
45
+ /**
46
+ * SSE event emitted when a compaction cycle starts.
47
+ *
48
+ * Served via `GET /api/events` (Server-Sent Events stream).
49
+ */
50
+ export interface SseCompactStart {
51
+ /** Discriminator. Always `'compact_start'`. */
52
+ type: 'compact_start';
53
+ /** ISO 8601 timestamp of the event. */
54
+ ts: string;
55
+ /**
56
+ * What triggered the compaction.
57
+ * Allowed values: `'auto'`, `'manual'`, `'fast-gate'`, `'ctx-pressure'`.
58
+ */
59
+ trigger: 'auto' | 'manual' | 'fast-gate' | 'ctx-pressure';
60
+ /** Session identifier the compaction is running in. */
61
+ sessionId: string;
62
+ }
63
+
64
+ /**
65
+ * SSE event emitted when a compaction cycle finishes.
66
+ *
67
+ * Served via `GET /api/events` (Server-Sent Events stream).
68
+ */
69
+ export interface SseCompactEnd {
70
+ /** Discriminator. Always `'compact_end'`. */
71
+ type: 'compact_end';
72
+ /** ISO 8601 timestamp of the event. */
73
+ ts: string;
74
+ /** Session identifier the compaction ran in. */
75
+ sessionId: string;
76
+ /** Checkpoint ID produced by the compaction. */
77
+ checkpointId: string;
78
+ /** Number of input tokens consumed by the compaction (tokens). */
79
+ tokensIn: number;
80
+ /** Number of output tokens after compaction (tokens). */
81
+ tokensOut: number;
82
+ /** Number of tokens freed (tokensIn − tokensOut, in tokens). */
83
+ tokensFreed: number;
84
+ /** Whether the compaction completed successfully. */
85
+ success: boolean;
86
+ }
87
+
88
+ /**
89
+ * SSE event emitted when the compaction trigger state changes
90
+ * (pressure crossing a threshold or being armed/disarmed).
91
+ *
92
+ * Served via `GET /api/events` (Server-Sent Events stream).
93
+ */
94
+ export interface SseCompactTrigger {
95
+ /** Discriminator. Always `'compact_trigger'`. */
96
+ type: 'compact_trigger';
97
+ /** ISO 8601 timestamp of the event. */
98
+ ts: string;
99
+ /** Current context pressure (percent, 0–100). */
100
+ pressure: number;
101
+ /** Threshold at which compaction will fire (percent, 0–100). */
102
+ threshold: number;
103
+ /** Whether the trigger is currently armed. */
104
+ armed: boolean;
105
+ }
106
+
107
+ /**
108
+ * SSE event emitted when a compaction is skipped (e.g. pressure insufficient).
109
+ *
110
+ * Served via `GET /api/events` (Server-Sent Events stream).
111
+ */
112
+ export interface SseCompactSkip {
113
+ /** Discriminator. Always `'compact_skip'`. */
114
+ type: 'compact_skip';
115
+ /** ISO 8601 timestamp of the event. */
116
+ ts: string;
117
+ /** Human-readable reason the compaction was skipped. */
118
+ reason: string;
119
+ }
120
+
121
+ /**
122
+ * SSE event emitted when the active compaction tier changes.
123
+ *
124
+ * Served via `GET /api/events` (Server-Sent Events stream).
125
+ */
126
+ export interface SseTierChanged {
127
+ /** Discriminator. Always `'tier_changed'`. */
128
+ type: 'tier_changed';
129
+ /** ISO 8601 timestamp of the event. */
130
+ ts: string;
131
+ /** Previous tier name. */
132
+ from: string;
133
+ /** New tier name. */
134
+ to: string;
135
+ /** Context pressure at the time of the change (percent, 0–100). */
136
+ contextPct: number;
137
+ }
138
+
139
+ /**
140
+ * SSE event emitted when the active LLM model or provider changes.
141
+ *
142
+ * Served via `GET /api/events` (Server-Sent Events stream).
143
+ */
144
+ export interface SseModelChanged {
145
+ /** Discriminator. Always `'model_changed'`. */
146
+ type: 'model_changed';
147
+ /** ISO 8601 timestamp of the event. */
148
+ ts: string;
149
+ /** Machine-readable provider identifier. */
150
+ provider: string;
151
+ /** Human-readable provider name. */
152
+ providerName: string;
153
+ /** Model name/identifier. */
154
+ model: string;
155
+ }
156
+
157
+ /**
158
+ * SSE event emitted when context pressure drops below the trigger threshold
159
+ * (pressure lifted).
160
+ *
161
+ * Served via `GET /api/events` (Server-Sent Events stream).
162
+ */
163
+ export interface SsePressureLifted {
164
+ /** Discriminator. Always `'pressure_lifted'`. */
165
+ type: 'pressure_lifted';
166
+ /** ISO 8601 timestamp of the event. */
167
+ ts: string;
168
+ /** Pressure percentage before lifting (percent, 0–100). */
169
+ beforePct: number;
170
+ /** Pressure percentage after lifting (percent, 0–100). */
171
+ afterPct: number;
172
+ }
173
+
174
+ /**
175
+ * SSE event emitted when a checkpoint is persisted to the store.
176
+ *
177
+ * Served via `GET /api/events` (Server-Sent Events stream).
178
+ */
179
+ export interface SseCheckpointPersisted {
180
+ /** Discriminator. Always `'checkpoint_persisted'`. */
181
+ type: 'checkpoint_persisted';
182
+ /** ISO 8601 timestamp of the event. */
183
+ ts: string;
184
+ /** Unique checkpoint identifier. */
185
+ checkpointId: string;
186
+ /** Total token count in the session at persistence time (tokens). */
187
+ sessionTokens: number;
188
+ }
189
+
190
+ /**
191
+ * SSE event emitted when recall results are injected into the context window.
192
+ *
193
+ * Served via `GET /api/events` (Server-Sent Events stream).
194
+ */
195
+ export interface SseRecallInject {
196
+ /** Discriminator. Always `'recall_inject'`. */
197
+ type: 'recall_inject';
198
+ /** ISO 8601 timestamp of the event. */
199
+ ts: string;
200
+ /** The recall query string used. */
201
+ query: string;
202
+ /** Number of chunks retrieved and injected. */
203
+ chunks: number;
204
+ /** Total tokens injected (tokens). */
205
+ tokens: number;
206
+ }
207
+
208
+ /**
209
+ * SSE event emitted when anchor messages are updated.
210
+ *
211
+ * Served via `GET /api/events` (Server-Sent Events stream).
212
+ */
213
+ export interface SseAnchorsUpdated {
214
+ /** Discriminator. Always `'anchors_updated'`. */
215
+ type: 'anchors_updated';
216
+ /** ISO 8601 timestamp of the event. */
217
+ ts: string;
218
+ /** Total number of anchor messages. */
219
+ count: number;
220
+ /** Number of anchor messages that are pinned. */
221
+ pinned: number;
222
+ }
223
+
224
+ /**
225
+ * SSE event emitted when a configuration value is updated.
226
+ *
227
+ * Served via `GET /api/events` (Server-Sent Events stream).
228
+ */
229
+ export interface SseConfigUpdated {
230
+ /** Discriminator. Always `'config_updated'`. */
231
+ type: 'config_updated';
232
+ /** ISO 8601 timestamp of the event. */
233
+ ts: string;
234
+ /** Configuration key that was changed. */
235
+ key: string;
236
+ /** New value for the configuration key. */
237
+ value: unknown;
238
+ }
239
+
240
+ /**
241
+ * SSE event emitted when a configuration preset is applied.
242
+ *
243
+ * Served via `GET /api/events` (Server-Sent Events stream).
244
+ */
245
+ export interface SseConfigPreset {
246
+ /** Discriminator. Always `'config_preset'`. */
247
+ type: 'config_preset';
248
+ /** ISO 8601 timestamp of the event. */
249
+ ts: string;
250
+ /** Name of the preset that was applied. */
251
+ preset: string;
252
+ }
253
+
254
+ /**
255
+ * SSE event emitted when crew agent presence changes (agents joining/leaving).
256
+ *
257
+ * Served via `GET /api/events` (Server-Sent Events stream).
258
+ */
259
+ export interface SseCrewPresenceChanged {
260
+ /** Discriminator. Always `'crew_presence_changed'`. */
261
+ type: 'crew_presence_changed';
262
+ /** ISO 8601 timestamp of the event. */
263
+ ts: string;
264
+ /** Number of currently active crew agents. */
265
+ activeAgents: number;
266
+ /** Current turn index in the crew round-robin. */
267
+ currentTurn: number;
268
+ }
269
+
270
+ /**
271
+ * SSE event emitted when the crew turn advances to a new agent.
272
+ *
273
+ * Served via `GET /api/events` (Server-Sent Events stream).
274
+ */
275
+ export interface SseCrewTurnChanged {
276
+ /** Discriminator. Always `'crew_turn_changed'`. */
277
+ type: 'crew_turn_changed';
278
+ /** ISO 8601 timestamp of the event. */
279
+ ts: string;
280
+ /** Zero-based index of the current turn. */
281
+ turnIndex: number;
282
+ /** Name of the agent whose turn it now is. */
283
+ agentName: string;
284
+ }
285
+
286
+ /**
287
+ * SSE event emitted when the multi-armed bandit selects an agent for the next turn.
288
+ *
289
+ * Served via `GET /api/events` (Server-Sent Events stream).
290
+ */
291
+ export interface SseCrewBanditChosen {
292
+ /** Discriminator. Always `'crew_bandit_chosen'`. */
293
+ type: 'crew_bandit_chosen';
294
+ /** ISO 8601 timestamp of the event. */
295
+ ts: string;
296
+ /** Name of the agent chosen by the bandit. */
297
+ chosenAgent: string;
298
+ /** Bandit score for the chosen agent (dimensionless utility value). */
299
+ score: number;
300
+ /** Cumulative regret of the bandit policy (dimensionless). */
301
+ regret: number;
302
+ }