@ericsanchezok/synergy-workbench 0.0.0-stage → 3.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 (153) hide show
  1. package/AGENTS.md +30 -0
  2. package/README.md +16 -2
  3. package/dist/agents.js +11 -0
  4. package/dist/cli-adapter.js +8 -0
  5. package/dist/component.js +65 -0
  6. package/dist/config-schema.js +265 -0
  7. package/dist/execution/activity.js +78 -0
  8. package/dist/execution/content.js +184 -0
  9. package/dist/execution/json-sections.js +231 -0
  10. package/dist/execution/presentation.js +79 -0
  11. package/dist/execution/preview.js +13 -0
  12. package/dist/execution/process.js +125 -0
  13. package/dist/execution/projection.js +327 -0
  14. package/dist/execution/query.js +18 -0
  15. package/dist/execution/routes.js +189 -0
  16. package/dist/execution/schema.js +322 -0
  17. package/dist/execution/service.js +1993 -0
  18. package/dist/features.js +22 -0
  19. package/dist/http.js +65 -0
  20. package/dist/performance/analysis.js +330 -0
  21. package/dist/performance/catalog.js +391 -0
  22. package/dist/performance/dashboard.js +483 -0
  23. package/dist/performance/error.js +15 -0
  24. package/dist/performance/index.js +6 -0
  25. package/dist/performance/inflight.js +43 -0
  26. package/dist/performance/projection.js +138 -0
  27. package/dist/performance/prompt/base.txt +38 -0
  28. package/dist/performance/prompt/builder.js +21 -0
  29. package/dist/performance/routes/performance-route.js +439 -0
  30. package/dist/performance/schema.js +628 -0
  31. package/dist/performance/timeline.js +98 -0
  32. package/dist/performance/trace-detail.js +91 -0
  33. package/dist/presentation/service.js +270 -0
  34. package/dist/presentation/tools/workbench-view.js +65 -0
  35. package/dist/presentation/tools.js +10 -0
  36. package/dist/project/directories.js +363 -0
  37. package/dist/project/git-health.js +498 -0
  38. package/dist/project/ide.js +66 -0
  39. package/dist/project/migration.js +22 -0
  40. package/dist/project/routes/directories.js +89 -0
  41. package/dist/project/routes/git.js +30 -0
  42. package/dist/project/routes/task-defaults.js +42 -0
  43. package/dist/project/session-health.js +9 -0
  44. package/dist/project/startup.js +28 -0
  45. package/dist/project/task-defaults.js +68 -0
  46. package/dist/project/tools/session-control.js +664 -0
  47. package/dist/project/tools/session-control.txt +60 -0
  48. package/dist/project/tools/worktree-archive.js +76 -0
  49. package/dist/project/tools/worktree-enter.js +175 -0
  50. package/dist/project/tools/worktree-leave.js +119 -0
  51. package/dist/project/tools/worktree-list.js +52 -0
  52. package/dist/project/tools.js +26 -0
  53. package/dist/project/vcs-branch-watcher.js +76 -0
  54. package/dist/project/vcs.js +114 -0
  55. package/dist/project/worktree-janitor.js +140 -0
  56. package/dist/project/worktrees.js +98 -0
  57. package/dist/push/bridge.js +171 -0
  58. package/dist/push/index.js +4 -0
  59. package/dist/push/routes/push.js +224 -0
  60. package/dist/push/service.js +93 -0
  61. package/dist/push/store.js +121 -0
  62. package/dist/push/types.js +58 -0
  63. package/dist/review/git.js +226 -0
  64. package/dist/review/routes.js +45 -0
  65. package/dist/review/schema.js +32 -0
  66. package/dist/review/state.js +79 -0
  67. package/dist/stats/aggregator.js +252 -0
  68. package/dist/stats/canonical.js +89 -0
  69. package/dist/stats/cli/stats.js +302 -0
  70. package/dist/stats/engine.js +176 -0
  71. package/dist/stats/index.js +5 -0
  72. package/dist/stats/rollup.js +460 -0
  73. package/dist/stats/routes/stats.js +94 -0
  74. package/dist/stats/routes/usage.js +83 -0
  75. package/dist/stats/storage.js +86 -0
  76. package/dist/stats/types.js +267 -0
  77. package/dist/worker.js +6 -0
  78. package/package.json +232 -4
  79. package/src/agents.ts +15 -0
  80. package/src/cli-adapter.ts +11 -0
  81. package/src/component.ts +73 -0
  82. package/src/config-schema.ts +289 -0
  83. package/src/execution/activity.ts +83 -0
  84. package/src/execution/content.ts +189 -0
  85. package/src/execution/json-sections.ts +230 -0
  86. package/src/execution/presentation.ts +91 -0
  87. package/src/execution/preview.ts +12 -0
  88. package/src/execution/process.ts +118 -0
  89. package/src/execution/projection.ts +330 -0
  90. package/src/execution/query.ts +19 -0
  91. package/src/execution/routes.ts +324 -0
  92. package/src/execution/schema.ts +336 -0
  93. package/src/execution/service.ts +2149 -0
  94. package/src/features.ts +22 -0
  95. package/src/http.ts +75 -0
  96. package/src/performance/analysis.ts +356 -0
  97. package/src/performance/catalog.ts +902 -0
  98. package/src/performance/dashboard.ts +521 -0
  99. package/src/performance/error.ts +32 -0
  100. package/src/performance/index.ts +6 -0
  101. package/src/performance/inflight.ts +46 -0
  102. package/src/performance/projection.ts +143 -0
  103. package/src/performance/prompt/base.txt +38 -0
  104. package/src/performance/prompt/builder.ts +24 -0
  105. package/src/performance/routes/performance-route.ts +541 -0
  106. package/src/performance/schema.ts +695 -0
  107. package/src/performance/timeline.ts +100 -0
  108. package/src/performance/trace-detail.ts +97 -0
  109. package/src/presentation/service.ts +303 -0
  110. package/src/presentation/tools/workbench-view.ts +75 -0
  111. package/src/presentation/tools.ts +11 -0
  112. package/src/project/directories.ts +391 -0
  113. package/src/project/git-health.ts +577 -0
  114. package/src/project/ide.ts +80 -0
  115. package/src/project/migration.ts +24 -0
  116. package/src/project/routes/directories.ts +124 -0
  117. package/src/project/routes/git.ts +42 -0
  118. package/src/project/routes/task-defaults.ts +50 -0
  119. package/src/project/session-health.ts +10 -0
  120. package/src/project/startup.ts +28 -0
  121. package/src/project/task-defaults.ts +70 -0
  122. package/src/project/tools/session-control.ts +725 -0
  123. package/src/project/tools/session-control.txt +60 -0
  124. package/src/project/tools/worktree-archive.ts +92 -0
  125. package/src/project/tools/worktree-enter.ts +227 -0
  126. package/src/project/tools/worktree-leave.ts +140 -0
  127. package/src/project/tools/worktree-list.ts +68 -0
  128. package/src/project/tools.ts +29 -0
  129. package/src/project/vcs-branch-watcher.ts +81 -0
  130. package/src/project/vcs.ts +124 -0
  131. package/src/project/worktree-janitor.ts +153 -0
  132. package/src/project/worktrees.ts +110 -0
  133. package/src/push/bridge.ts +182 -0
  134. package/src/push/index.ts +4 -0
  135. package/src/push/routes/push.ts +267 -0
  136. package/src/push/service.ts +108 -0
  137. package/src/push/store.ts +120 -0
  138. package/src/push/types.ts +67 -0
  139. package/src/review/git.ts +221 -0
  140. package/src/review/routes.ts +65 -0
  141. package/src/review/schema.ts +34 -0
  142. package/src/review/state.ts +77 -0
  143. package/src/stats/aggregator.ts +277 -0
  144. package/src/stats/canonical.ts +93 -0
  145. package/src/stats/cli/stats.ts +348 -0
  146. package/src/stats/engine.ts +197 -0
  147. package/src/stats/index.ts +5 -0
  148. package/src/stats/rollup.ts +522 -0
  149. package/src/stats/routes/stats.ts +107 -0
  150. package/src/stats/routes/usage.ts +103 -0
  151. package/src/stats/storage.ts +78 -0
  152. package/src/stats/types.ts +351 -0
  153. package/src/worker.ts +7 -0
@@ -0,0 +1,695 @@
1
+ import { ObservabilityConfig } from "@ericsanchezok/synergy-harness/observability/config"
2
+ import { ObservabilitySchema } from "@ericsanchezok/synergy-harness/observability/schema"
3
+ import { SessionManager } from "@ericsanchezok/synergy-harness/session/manager"
4
+ import z from "zod"
5
+
6
+ export namespace PerformanceSchema {
7
+ export const Source = ObservabilitySchema.Source.meta({ ref: "PerfSource" })
8
+ export type Source = z.infer<typeof Source>
9
+
10
+ export const Module = ObservabilitySchema.Module.meta({ ref: "PerfModule" })
11
+ export type Module = z.infer<typeof Module>
12
+
13
+ export const Unit = ObservabilitySchema.Unit.meta({ ref: "PerfUnit" })
14
+ export type Unit = z.infer<typeof Unit>
15
+
16
+ export const LabelValue = ObservabilitySchema.LabelValue.meta({ ref: "PerfLabelValue" })
17
+ export type LabelValue = z.infer<typeof LabelValue>
18
+ export const Labels = ObservabilitySchema.Labels.meta({ ref: "PerfLabels" })
19
+ export type Labels = z.infer<typeof Labels>
20
+
21
+ export const Metric = z
22
+ .object({
23
+ metricId: z.string(),
24
+ time: z.number(),
25
+ iso: z.string(),
26
+ name: z.string(),
27
+ value: z.number(),
28
+ unit: Unit,
29
+ source: Source,
30
+ module: Module,
31
+ correlationId: z.string().optional(),
32
+ scopeID: z.string().optional(),
33
+ sessionID: z.string().optional(),
34
+ messageID: z.string().optional(),
35
+ callID: z.string().optional(),
36
+ traceId: z.string().optional(),
37
+ spanId: z.string().optional(),
38
+ parentSpanId: z.string().optional(),
39
+ rid: z.string().optional(),
40
+ processId: z.string().optional(),
41
+ pid: z.number().int().optional(),
42
+ tool: z.string().optional(),
43
+ labels: Labels,
44
+ sampleRate: z.number().min(0).max(1).default(1),
45
+ })
46
+ .meta({ ref: "PerfMetric" })
47
+ export type Metric = z.infer<typeof Metric>
48
+
49
+ export const SpanStatus = z
50
+ .enum(["running", "ok", "error", "cancelled", "timeout", "interrupted"])
51
+ .meta({ ref: "PerfSpanStatus" })
52
+ export type SpanStatus = z.infer<typeof SpanStatus>
53
+ export const Span = z
54
+ .object({
55
+ traceId: z.string(),
56
+ correlationId: z.string().optional(),
57
+ spanId: z.string(),
58
+ parentSpanId: z.string().optional(),
59
+ kind: z.string().optional(),
60
+ name: z.string(),
61
+ module: Module,
62
+ source: Source,
63
+ startTime: z.number(),
64
+ endTime: z.number().optional(),
65
+ durationMs: z.number().optional(),
66
+ status: SpanStatus.default("ok"),
67
+ lastActivityTime: z.number().optional(),
68
+ heartbeatTime: z.number().optional(),
69
+ heartbeatCount: z.number().int().optional(),
70
+ stalled: z.boolean().optional(),
71
+ errorCode: z.string().optional(),
72
+ errorMessage: z.string().optional(),
73
+ scopeID: z.string().optional(),
74
+ sessionID: z.string().optional(),
75
+ messageID: z.string().optional(),
76
+ callID: z.string().optional(),
77
+ rid: z.string().optional(),
78
+ processId: z.string().optional(),
79
+ pid: z.number().int().optional(),
80
+ tool: z.string().optional(),
81
+ attributes: Labels,
82
+ })
83
+ .meta({ ref: "PerfSpan" })
84
+
85
+ export const ResourceSample = z
86
+ .object({
87
+ sampleId: z.string(),
88
+ time: z.number(),
89
+ iso: z.string(),
90
+ source: Source,
91
+ process: z.object({ pid: z.number().int().optional(), processId: z.string().optional(), role: z.string() }),
92
+ cpu: z
93
+ .object({
94
+ userMicros: z.number().optional(),
95
+ systemMicros: z.number().optional(),
96
+ utilizationRatio: z
97
+ .number()
98
+ .describe("Process CPU time per wall-clock time; 1 is one fully used CPU core and values may exceed 1")
99
+ .optional(),
100
+ })
101
+ .default({}),
102
+ memory: z
103
+ .object({
104
+ rssBytes: z.number().optional(),
105
+ heapTotalBytes: z.number().optional(),
106
+ heapUsedBytes: z.number().optional(),
107
+ externalBytes: z.number().optional(),
108
+ arrayBuffersBytes: z.number().optional(),
109
+ })
110
+ .default({}),
111
+ cgroup: z
112
+ .object({
113
+ currentBytes: z.number().optional(),
114
+ highBytes: z.number().optional(),
115
+ maxBytes: z.number().optional(),
116
+ peakBytes: z.number().optional(),
117
+ oomCount: z.number().optional(),
118
+ oomKillCount: z.number().optional(),
119
+ })
120
+ .optional(),
121
+ serviceMemory: z
122
+ .object({
123
+ rssBytes: z.number().optional(),
124
+ source: z.enum(["cgroup_v2", "process_api"]),
125
+ completeness: z.enum(["full", "partial"]),
126
+ })
127
+ .optional(),
128
+ eventLoop: z.object({ lagMs: z.number().optional(), sampleWindowMs: z.number() }),
129
+ io: z
130
+ .object({
131
+ appReadBytes: z.number().optional(),
132
+ appWrittenBytes: z.number().optional(),
133
+ appReadOps: z.number().optional(),
134
+ appWriteOps: z.number().optional(),
135
+ osReadBytes: z.number().optional(),
136
+ osWrittenBytes: z.number().optional(),
137
+ osAvailable: z.boolean().default(false),
138
+ })
139
+ .default({ osAvailable: false }),
140
+ correlationId: z.string().optional(),
141
+ scopeID: z.string().optional(),
142
+ sessionID: z.string().optional(),
143
+ traceId: z.string().optional(),
144
+ labels: Labels,
145
+ })
146
+ .meta({ ref: "PerfResourceSample" })
147
+ export type ResourceSample = z.infer<typeof ResourceSample>
148
+
149
+ export const IssueSeverity = z.enum(["info", "warning", "error", "critical"]).meta({ ref: "PerfIssueSeverity" })
150
+ export const IssueStatus = z.enum(["open", "resolved", "suppressed"]).meta({ ref: "PerfIssueStatus" })
151
+ export type IssueSeverity = z.infer<typeof IssueSeverity>
152
+ export type IssueStatus = z.infer<typeof IssueStatus>
153
+ export const Issue = z
154
+ .object({
155
+ issueId: z.string(),
156
+ time: z.number(),
157
+ iso: z.string(),
158
+ severity: IssueSeverity,
159
+ status: IssueStatus.default("open"),
160
+ code: z.string(),
161
+ title: z.string(),
162
+ message: z.string(),
163
+ recommendation: z.string().optional(),
164
+ module: Module,
165
+ correlationId: z.string().optional(),
166
+ scopeID: z.string().optional(),
167
+ traceId: z.string().optional(),
168
+ spanId: z.string().optional(),
169
+ sessionID: z.string().optional(),
170
+ messageID: z.string().optional(),
171
+ callID: z.string().optional(),
172
+ rid: z.string().optional(),
173
+ evidence: Labels,
174
+ firstSeenTime: z.number(),
175
+ lastSeenTime: z.number(),
176
+ occurrenceCount: z.number().int(),
177
+ fingerprint: z.string(),
178
+ })
179
+ .meta({ ref: "PerfIssue" })
180
+ export type Issue = z.infer<typeof Issue>
181
+
182
+ export const RankedItem = z
183
+ .object({
184
+ id: z.string(),
185
+ label: z.string(),
186
+ module: Module.optional(),
187
+ value: z.number(),
188
+ unit: Unit,
189
+ traceId: z.string().optional(),
190
+ sessionID: z.string().optional(),
191
+ tool: z.string().optional(),
192
+ status: z.string().optional(),
193
+ processId: z.string().optional(),
194
+ pid: z.number().int().optional(),
195
+ })
196
+ .meta({ ref: "PerfRankedItem" })
197
+ export type RankedItem = z.infer<typeof RankedItem>
198
+
199
+ export const ToolFailureCategory = z
200
+ .object({
201
+ errorClass: z.string(),
202
+ count: z.number().int().nonnegative(),
203
+ })
204
+ .meta({ ref: "PerfToolFailureCategory" })
205
+ export type ToolFailureCategory = z.infer<typeof ToolFailureCategory>
206
+
207
+ export const ToolFailureItem = z
208
+ .object({
209
+ tool: z.string(),
210
+ callCount: z.number().int().nonnegative(),
211
+ errorCount: z.number().int().nonnegative(),
212
+ errorRate: z.number().min(0).max(1),
213
+ categories: z.array(ToolFailureCategory),
214
+ })
215
+ .meta({ ref: "PerfToolFailureItem" })
216
+ export type ToolFailureItem = z.infer<typeof ToolFailureItem>
217
+
218
+ export const TimelineQuality = z
219
+ .object({
220
+ truncated: z.boolean().optional(),
221
+ sampled: z.boolean().optional(),
222
+ partial: z.boolean().optional(),
223
+ retentionLimited: z.boolean().optional(),
224
+ unavailableReason: z.string().optional(),
225
+ })
226
+ .meta({ ref: "PerfTimelineQuality" })
227
+
228
+ export const ResourceOwnerKind = z
229
+ .enum(["control_plane", "agent", "policy", "plugin", "browser", "mcp", "local_process"])
230
+ .meta({ ref: "PerfResourceOwnerKind" })
231
+ export const ResourceRecovery = z
232
+ .object({
233
+ action: z.enum(["gc", "recycle", "idle_retire", "close"]),
234
+ reason: z.string(),
235
+ at: z.number(),
236
+ beforeBytes: z.number().nonnegative().optional(),
237
+ afterBytes: z.number().nonnegative().optional(),
238
+ reclaimedBytes: z.number().nonnegative().optional(),
239
+ timedOut: z.boolean().optional(),
240
+ })
241
+ .meta({ ref: "PerfResourceRecovery" })
242
+ export const ResourceOwner = z
243
+ .object({
244
+ owner: ResourceOwnerKind,
245
+ processCount: z.number().int().nonnegative(),
246
+ measuredProcessCount: z.number().int().nonnegative(),
247
+ currentBytes: z.number().nonnegative().optional(),
248
+ peakBytes: z.number().nonnegative().optional(),
249
+ baselineBytes: z.number().nonnegative().optional(),
250
+ retainedBytes: z.number().nonnegative().optional(),
251
+ heapUsedBytes: z.number().nonnegative().optional(),
252
+ externalBytes: z.number().nonnegative().optional(),
253
+ arrayBuffersBytes: z.number().nonnegative().optional(),
254
+ source: z.enum([
255
+ "process_api",
256
+ "worker_ipc",
257
+ "plugin_monitor",
258
+ "browser_runtime",
259
+ "mcp_stdio",
260
+ "process_registry",
261
+ ]),
262
+ completeness: z.enum(["full", "partial", "unavailable"]),
263
+ attributes: z.record(z.string(), z.union([z.string(), z.number(), z.boolean()])).default({}),
264
+ lastRecovery: ResourceRecovery.optional(),
265
+ })
266
+ .meta({ ref: "PerfResourceOwner" })
267
+
268
+ export const DashboardSummary = z
269
+ .object({
270
+ generatedAt: z.string(),
271
+ windowMs: z.number(),
272
+ quality: TimelineQuality.optional(),
273
+ health: z.object({
274
+ status: z.enum(["healthy", "degraded", "critical", "unknown"]),
275
+ score: z.number(),
276
+ openIssueCount: z.number().int(),
277
+ criticalIssueCount: z.number().int(),
278
+ }),
279
+ backend: z.object({
280
+ requestCount: z.number().int(),
281
+ errorRate: z.number(),
282
+ p50RequestMs: z.number().optional(),
283
+ p95RequestMs: z.number().optional(),
284
+ p99RequestMs: z.number().optional(),
285
+ activeSessions: z.number().int(),
286
+ pendingSessions: z.number().int(),
287
+ }),
288
+ resources: z.object({
289
+ rssBytes: z.number().optional(),
290
+ heapUsedBytes: z.number().optional(),
291
+ heapTotalBytes: z.number().optional(),
292
+ externalBytes: z.number().optional(),
293
+ arrayBuffersBytes: z.number().optional(),
294
+ cpuUtilizationRatio: z
295
+ .number()
296
+ .describe("Process CPU time per wall-clock time; 1 is one fully used CPU core and values may exceed 1")
297
+ .optional(),
298
+ eventLoopLagP95Ms: z.number().optional(),
299
+ appReadBytes: z.number().optional(),
300
+ appWrittenBytes: z.number().optional(),
301
+ appReadOps: z.number().int().optional(),
302
+ appWriteOps: z.number().int().optional(),
303
+ childProcessCount: z.number().int().optional(),
304
+ measuredChildProcessCount: z.number().int().optional(),
305
+ serviceMemory: z
306
+ .object({
307
+ rssBytes: z.number().optional(),
308
+ currentBytes: z.number().optional(),
309
+ workingSetBytes: z.number().optional(),
310
+ reclaimableBytes: z.number().optional(),
311
+ peakBytes: z.number().optional(),
312
+ source: z.enum(["cgroup_v2", "process_api"]),
313
+ completeness: z.enum(["full", "partial"]),
314
+ })
315
+ .optional(),
316
+ childProcessRssBytes: z.number().optional(),
317
+ owners: z.array(ResourceOwner),
318
+ }),
319
+ sessions: z.object({
320
+ turnCount: z.number().int(),
321
+ p95TurnMs: z.number().optional(),
322
+ llmCallCount: z.number().int(),
323
+ toolCallCount: z.number().int(),
324
+ }),
325
+ frontend: z.object({
326
+ inpMs: z.number().optional(),
327
+ lcpMs: z.number().optional(),
328
+ cls: z.number().optional(),
329
+ fcpMs: z.number().optional(),
330
+ ttfbMs: z.number().optional(),
331
+ longTaskCount: z.number().int(),
332
+ resourceP95Ms: z.number().optional(),
333
+ }),
334
+ runtime: z.object({
335
+ alive: z.boolean().optional(),
336
+ healthy: z.boolean().optional(),
337
+ pid: z.number().int().optional(),
338
+ mode: z.string().optional(),
339
+ mirrorFiles: z.number().int(),
340
+ traceFiles: z.number().int().optional(),
341
+ recentErrors: z.number().int(),
342
+ pendingSessions: z.number().int(),
343
+ sessionRuntimes: z.object({
344
+ totalCount: z.number().int(),
345
+ runningCount: z.number().int(),
346
+ idleCount: z.number().int(),
347
+ childCount: z.number().int(),
348
+ userCount: z.number().int(),
349
+ waiterCount: z.number().int(),
350
+ executionPhases: z.partialRecord(SessionManager.ExecutionPhase, z.number().int().nonnegative()).optional(),
351
+ }),
352
+ execution: z
353
+ .object({
354
+ agentWorkers: z.object({
355
+ configured: z.number().int().positive(),
356
+ minIdle: z.number().int().nonnegative(),
357
+ idleTimeoutMs: z.number().int().positive(),
358
+ maxQueued: z.number().int().nonnegative(),
359
+ maxQueuedBytes: z.number().int().positive(),
360
+ workers: z.number().int().nonnegative(),
361
+ ready: z.number().int().nonnegative(),
362
+ active: z.number().int().nonnegative(),
363
+ queued: z.number().int().nonnegative(),
364
+ queuedBytes: z.number().int().nonnegative(),
365
+ rssBytes: z.number().int().nonnegative(),
366
+ heapUsedBytes: z.number().int().nonnegative(),
367
+ heapTotalBytes: z.number().int().nonnegative(),
368
+ externalBytes: z.number().int().nonnegative(),
369
+ arrayBuffersBytes: z.number().int().nonnegative(),
370
+ }),
371
+ policyWorkers: z.object({
372
+ configured: z.number().int().positive(),
373
+ maxQueued: z.number().int().nonnegative(),
374
+ maxQueuedBytes: z.number().int().positive(),
375
+ workers: z.number().int().nonnegative(),
376
+ ready: z.number().int().nonnegative(),
377
+ active: z.number().int().nonnegative(),
378
+ queued: z.number().int().nonnegative(),
379
+ queuedBytes: z.number().int().nonnegative(),
380
+ rssBytes: z.number().int().nonnegative(),
381
+ heapUsedBytes: z.number().int().nonnegative(),
382
+ heapTotalBytes: z.number().int().nonnegative(),
383
+ externalBytes: z.number().int().nonnegative(),
384
+ arrayBuffersBytes: z.number().int().nonnegative(),
385
+ }),
386
+ toolTasks: z.object({
387
+ active: z.number().int().nonnegative(),
388
+ queued: z.number().int().nonnegative(),
389
+ tracked: z.number().int().nonnegative(),
390
+ queuedBytes: z.number().int().nonnegative(),
391
+ maxConcurrent: z.number().int().positive(),
392
+ maxQueued: z.number().int().nonnegative(),
393
+ maxQueuedBytes: z.number().int().positive().optional(),
394
+ byExecutor: z
395
+ .partialRecord(
396
+ z.enum(["local_process", "file", "plugin", "mcp", "browser", "control_plane"]),
397
+ z.object({
398
+ active: z.number().int().nonnegative(),
399
+ queued: z.number().int().nonnegative(),
400
+ limit: z.number().int().positive(),
401
+ }),
402
+ )
403
+ .optional(),
404
+ }),
405
+ })
406
+ .optional(),
407
+ messageCache: z
408
+ .object({
409
+ totalBytes: z.number().int().nonnegative(),
410
+ activeCount: z.number().int().nonnegative(),
411
+ entryCount: z.number().int().nonnegative(),
412
+ hits: z.number().int().nonnegative(),
413
+ misses: z.number().int().nonnegative(),
414
+ evictions: z.number().int().nonnegative(),
415
+ protectedOverbudget: z.number().int().nonnegative(),
416
+ entries: z.array(z.object({ estimatedBytes: z.number().int().nonnegative() })),
417
+ truncatedEntryCount: z.number().int().nonnegative(),
418
+ })
419
+ .optional(),
420
+ llmTurns: z
421
+ .object({
422
+ activeTurnCount: z.number().int().nonnegative(),
423
+ activeStreamCount: z.number().int().nonnegative(),
424
+ turns: z.array(
425
+ z.object({
426
+ ageMs: z.number().nonnegative(),
427
+ streamActive: z.boolean(),
428
+ providerID: z.string(),
429
+ modelID: z.string(),
430
+ historyBeforeBytes: z.number().int().nonnegative(),
431
+ historyAfterBytes: z.number().int().nonnegative(),
432
+ requestBytes: z.number().int().nonnegative(),
433
+ toolSchemaBytes: z.number().int().nonnegative(),
434
+ outputChars: z.number().int().nonnegative(),
435
+ toolRawChars: z.number().int().nonnegative(),
436
+ }),
437
+ ),
438
+ })
439
+ .optional(),
440
+ cortexTasks: z.object({
441
+ totalCount: z.number().int(),
442
+ queuedCount: z.number().int(),
443
+ runningCount: z.number().int(),
444
+ completedCount: z.number().int(),
445
+ errorCount: z.number().int(),
446
+ cancelledCount: z.number().int(),
447
+ interruptedCount: z.number().int(),
448
+ retainedPromptChars: z.number().int(),
449
+ retainedOutputChars: z.number().int(),
450
+ retainedErrorChars: z.number().int(),
451
+ retainedProgressToolCount: z.number().int(),
452
+ }),
453
+ }),
454
+ top: z.object({
455
+ slowRoutes: z.array(RankedItem),
456
+ slowSessions: z.array(RankedItem),
457
+ slowTools: z.array(RankedItem),
458
+ toolFailures: z.array(ToolFailureItem),
459
+ slowProviders: z.array(RankedItem),
460
+ slowStorage: z.array(RankedItem),
461
+ slowLibrary: z.array(RankedItem),
462
+ childProcesses: z.array(RankedItem),
463
+ slowFrontend: z.array(RankedItem),
464
+ }),
465
+ issues: z.array(Issue),
466
+ })
467
+ .meta({ ref: "PerfDashboardSummary" })
468
+ export type DashboardSummary = z.infer<typeof DashboardSummary>
469
+
470
+ export const TimelineQuery = z
471
+ .object({
472
+ from: z.string().optional(),
473
+ to: z.string().optional(),
474
+ bucketMs: z.coerce.number().int().positive().optional(),
475
+ metric: z.union([z.string(), z.array(z.string())]).optional(),
476
+ stat: z.enum(["avg", "latest", "sum", "rate", "p50", "p95", "p99", "max"]).optional(),
477
+ scopeID: z.string().optional(),
478
+ sessionID: z.string().optional(),
479
+ tool: z.string().optional(),
480
+ providerID: z.string().optional(),
481
+ module: Module.optional(),
482
+ windowMs: z.coerce.number().int().positive().optional(),
483
+ })
484
+ .meta({ ref: "PerfTimelineQuery" })
485
+ export type TimelineQuery = z.infer<typeof TimelineQuery>
486
+
487
+ export const TimelineStat = z
488
+ .enum(["avg", "latest", "sum", "rate", "p50", "p95", "p99", "max"])
489
+ .meta({ ref: "PerfTimelineStat" })
490
+ export const MetricKind = z
491
+ .enum(["duration", "gauge", "counter", "rate", "size", "ratio"])
492
+ .meta({ ref: "PerfMetricKind" })
493
+ export const TimelinePoint = z
494
+ .object({ time: z.number(), value: z.number().nullable(), sampleCount: z.number().int().optional() })
495
+ .meta({ ref: "PerfTimelinePoint" })
496
+ export const TimelineSeries = z
497
+ .object({
498
+ name: z.string(),
499
+ label: z.string().optional(),
500
+ unit: Unit,
501
+ kind: MetricKind.optional(),
502
+ stat: TimelineStat.optional(),
503
+ sampleCount: z.number().int().optional(),
504
+ module: Module.optional(),
505
+ source: Source.optional(),
506
+ quality: TimelineQuality.optional(),
507
+ points: z.array(TimelinePoint),
508
+ })
509
+ .meta({ ref: "PerfTimelineSeries" })
510
+ export const Timeline = z
511
+ .object({
512
+ generatedAt: z.string(),
513
+ from: z.number(),
514
+ to: z.number(),
515
+ bucketMs: z.number(),
516
+ quality: TimelineQuality.optional(),
517
+ series: z.array(TimelineSeries),
518
+ })
519
+ .meta({ ref: "PerfTimeline" })
520
+ export type Timeline = z.infer<typeof Timeline>
521
+
522
+ export const TraceListQuery = z
523
+ .object({
524
+ from: z.string().optional(),
525
+ to: z.string().optional(),
526
+ limit: z.coerce.number().int().positive().max(200).optional(),
527
+ cursor: z.string().optional(),
528
+ kind: z
529
+ .enum(["request", "session", "tool", "provider", "runtime", "storage", "frontend", "mcp", "plugin", "channel"])
530
+ .optional(),
531
+ status: SpanStatus.optional(),
532
+ minDurationMs: z.coerce.number().nonnegative().optional(),
533
+ scopeID: z.string().optional(),
534
+ sessionID: z.string().optional(),
535
+ })
536
+ .meta({ ref: "PerfTraceListQuery" })
537
+ export type TraceListQuery = z.infer<typeof TraceListQuery>
538
+
539
+ export const TraceListItem = z
540
+ .object({
541
+ traceId: z.string(),
542
+ correlationId: z.string().optional(),
543
+ kind: z.string(),
544
+ name: z.string(),
545
+ status: SpanStatus,
546
+ startedAt: z.string(),
547
+ endedAt: z.string().optional(),
548
+ durationMs: z.number().optional(),
549
+ module: Module,
550
+ source: Source,
551
+ sessionID: z.string().optional(),
552
+ scopeID: z.string().optional(),
553
+ rid: z.string().optional(),
554
+ tool: z.string().optional(),
555
+ errorCode: z.string().optional(),
556
+ redactionApplied: z.boolean(),
557
+ })
558
+ .meta({ ref: "PerfTraceListItem" })
559
+ export type TraceListItem = z.infer<typeof TraceListItem>
560
+
561
+ export const TraceList = z
562
+ .object({ generatedAt: z.string(), items: z.array(TraceListItem), nextCursor: z.string().optional() })
563
+ .meta({ ref: "PerfTraceList" })
564
+ export type TraceList = z.infer<typeof TraceList>
565
+
566
+ export const InflightSpan = Span.extend({
567
+ ageMs: z.number(),
568
+ idleMs: z.number(),
569
+ stale: z.boolean(),
570
+ activeSince: z.number().optional(),
571
+ }).meta({ ref: "PerfInflightSpan" })
572
+ export type InflightSpan = z.infer<typeof InflightSpan>
573
+
574
+ export const Inflight = z
575
+ .object({ generatedAt: z.string(), spans: z.array(InflightSpan) })
576
+ .meta({ ref: "PerfInflight" })
577
+ export type Inflight = z.infer<typeof Inflight>
578
+
579
+ export const AnalysisRequest = z
580
+ .object({
581
+ windowMs: z.coerce.number().int().min(1000).max(86_400_000).default(900_000),
582
+ })
583
+ .meta({ ref: "PerformanceAnalysisRequest" })
584
+ export type AnalysisRequest = z.infer<typeof AnalysisRequest>
585
+
586
+ export const AnalysisStatus = z
587
+ .enum(["queued", "running", "completed", "error", "cancelled", "interrupted"])
588
+ .meta({ ref: "PerformanceAnalysisStatus" })
589
+ export type AnalysisStatus = z.infer<typeof AnalysisStatus>
590
+
591
+ export const AnalysisView = z
592
+ .object({
593
+ sessionID: z.string(),
594
+ status: AnalysisStatus,
595
+ startedAt: z.number(),
596
+ completedAt: z.number().optional(),
597
+ result: z.string().optional(),
598
+ error: z.string().optional(),
599
+ })
600
+ .meta({ ref: "PerformanceAnalysisView" })
601
+ export type AnalysisView = z.infer<typeof AnalysisView>
602
+
603
+ export const TraceEvent = z
604
+ .object({
605
+ time: z.number(),
606
+ iso: z.string(),
607
+ type: z.string(),
608
+ level: z.string().optional(),
609
+ traceId: z.string().optional(),
610
+ correlationId: z.string().optional(),
611
+ sessionID: z.string().optional(),
612
+ messageID: z.string().optional(),
613
+ callID: z.string().optional(),
614
+ rid: z.string().optional(),
615
+ tool: z.string().optional(),
616
+ processId: z.string().optional(),
617
+ pid: z.number().int().optional(),
618
+ dataKeys: z.array(z.string()).default([]),
619
+ redactionApplied: z.boolean(),
620
+ })
621
+ .meta({ ref: "PerfTraceEvent" })
622
+ export type TraceEvent = z.infer<typeof TraceEvent>
623
+
624
+ export const TraceDetail = z
625
+ .object({
626
+ generatedAt: z.string(),
627
+ traceId: z.string(),
628
+ root: Span.optional(),
629
+ spans: z.array(Span),
630
+ events: z.array(TraceEvent),
631
+ redaction: z.object({ applied: z.boolean(), omittedAttributes: z.number().int() }),
632
+ })
633
+ .meta({ ref: "PerfTraceDetail" })
634
+ export type TraceDetail = z.infer<typeof TraceDetail>
635
+
636
+ export const BrowserMetric = z
637
+ .object({
638
+ name: z.string().max(96),
639
+ value: z.number(),
640
+ unit: Unit,
641
+ time: z.number().optional(),
642
+ labels: Labels.optional(),
643
+ })
644
+ .meta({ ref: "PerfBrowserMetric" })
645
+ export type BrowserMetric = z.infer<typeof BrowserMetric>
646
+
647
+ export const BrowserMetricBatch = z
648
+ .object({
649
+ batchId: z.string().max(128).optional(),
650
+ sentAt: z.number(),
651
+ page: z
652
+ .object({
653
+ routeName: z.string().max(256).optional(),
654
+ pathTemplate: z.string().max(512).optional(),
655
+ sessionID: z.string().max(128).optional(),
656
+ scopeID: z.string().max(128).optional(),
657
+ correlationId: z.string().max(128).optional(),
658
+ navigationId: z.string().max(128).optional(),
659
+ sessionSwitchId: z.string().max(128).optional(),
660
+ })
661
+ .default({}),
662
+ metrics: z.array(BrowserMetric).max(100),
663
+ resourceEntries: z
664
+ .array(
665
+ z.object({
666
+ name: z.string().max(2048),
667
+ initiatorType: z.string().max(64).optional(),
668
+ startTime: z.number(),
669
+ duration: z.number(),
670
+ transferSize: z.number().optional(),
671
+ encodedBodySize: z.number().optional(),
672
+ decodedBodySize: z.number().optional(),
673
+ requestStart: z.number().finite().nonnegative().optional(),
674
+ responseStart: z.number().finite().nonnegative().optional(),
675
+ responseEnd: z.number().finite().nonnegative().optional(),
676
+ }),
677
+ )
678
+ .max(100)
679
+ .optional(),
680
+ longTasks: z
681
+ .array(z.object({ startTime: z.number(), duration: z.number(), attribution: z.string().max(128).optional() }))
682
+ .max(100)
683
+ .optional(),
684
+ })
685
+ .meta({ ref: "PerfBrowserMetricBatch" })
686
+ export type BrowserMetricBatch = z.infer<typeof BrowserMetricBatch>
687
+
688
+ export const BrowserMetricIngestResult = z
689
+ .object({ batchId: z.string(), accepted: z.number().int(), rejected: z.number().int(), receivedAt: z.string() })
690
+ .meta({ ref: "PerfBrowserMetricIngestResult" })
691
+ export type BrowserMetricIngestResult = z.infer<typeof BrowserMetricIngestResult>
692
+
693
+ export const Config = ObservabilityConfig.Schema.meta({ ref: "PerfConfig" })
694
+ export type Config = z.infer<typeof Config>
695
+ }