@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,336 @@
1
+ import { z } from "zod"
2
+ import { RolloutAccounting, RolloutEvidence, RolloutSchema } from "@ericsanchezok/synergy-harness/rollout"
3
+ import { Usage } from "@ericsanchezok/synergy-harness/usage"
4
+ import { BusEvent } from "@ericsanchezok/synergy-harness/bus/bus-event"
5
+ import { MessageV2 } from "@ericsanchezok/synergy-harness/session/message-v2"
6
+ import { SessionInteraction } from "@ericsanchezok/synergy-harness/session/interaction"
7
+ import { CortexTypes } from "@ericsanchezok/synergy-harness/cortex/types"
8
+ import { ExecutionPresentation } from "./presentation"
9
+ import { ContextUsageEstimateSchema } from "@ericsanchezok/synergy-harness/context"
10
+
11
+ export namespace ExecutionSchema {
12
+ const Json = z.unknown().meta({ ref: "ExecutionJson" })
13
+ export const Query = z.object({
14
+ mode: z.enum(["process", "records"]).default("records"),
15
+ order: z.enum(["time", "round", "call"]).default("time"),
16
+ runID: z.string().optional(),
17
+ session: z.string().optional(),
18
+ actor: z.enum(["main", "all"]).default("main"),
19
+ query: z.string().max(500).optional(),
20
+ kind: z
21
+ .enum([
22
+ "turn",
23
+ "input",
24
+ "context",
25
+ "reasoning",
26
+ "output",
27
+ "model",
28
+ "retry",
29
+ "tool",
30
+ "process",
31
+ "compaction",
32
+ "subtask",
33
+ ])
34
+ .optional(),
35
+ status: z.enum(["running", "completed", "failed", "cancelled", "interrupted", "unknown"]).optional(),
36
+ kinds: z.string().max(200).optional(),
37
+ statuses: z.string().max(100).optional(),
38
+ anomalies: z.preprocess((value) => (value === "false" ? false : value), z.coerce.boolean()).default(false),
39
+ from: z.coerce.number().nonnegative().optional(),
40
+ to: z.coerce.number().nonnegative().optional(),
41
+ activityFrom: z.coerce.number().int().nonnegative().optional(),
42
+ activityTo: z.coerce.number().int().nonnegative().optional(),
43
+ cursor: z.string().max(4096).optional(),
44
+ anchor: z.string().optional(),
45
+ position: z.enum(["before", "after", "around"]).optional(),
46
+ limit: z.coerce.number().int().min(1).max(500).default(100),
47
+ })
48
+ export type Query = z.infer<typeof Query>
49
+ export const Node = z
50
+ .object({
51
+ id: z.string(),
52
+ sessionID: z.string(),
53
+ runID: z.string(),
54
+ rootRunID: z.string().nullable().optional(),
55
+ parentID: z.string().nullable(),
56
+ kind: Query.shape.kind.unwrap(),
57
+ title: z.string(),
58
+ preview: z.string(),
59
+ started: z.number(),
60
+ ended: z.number().optional(),
61
+ status: Query.shape.status.unwrap(),
62
+ revision: z.number(),
63
+ messageID: z.string().optional(),
64
+ tool: z.string().optional(),
65
+ modelID: z.string().optional(),
66
+ modelKind: RolloutSchema.CallRecord.shape.kind,
67
+ agent: z.string().optional(),
68
+ callID: z.string().optional(),
69
+ source: z.enum(["recorded", "messages"]),
70
+ evidenceKind: RolloutEvidence.Kind.optional(),
71
+ attemptIndex: z.number().int().nonnegative().optional(),
72
+ purpose: z.string().optional(),
73
+ usageRole: z.string().optional(),
74
+ attribution: z.enum(["known", "unassigned"]).optional(),
75
+ tokens: RolloutAccounting.Metric.optional(),
76
+ group: z
77
+ .object({
78
+ id: z.string(),
79
+ started: z.number().optional(),
80
+ callCount: z.number().int().positive().optional(),
81
+ memberCount: z.number(),
82
+ attemptCount: z.number(),
83
+ retryCount: z.number(),
84
+ anomalies: z.number(),
85
+ purpose: z.string().nullable(),
86
+ })
87
+ .optional(),
88
+ ancestors: z.array(z.object({ id: z.string(), title: z.string(), kind: Query.shape.kind.unwrap() })).optional(),
89
+ activity: z
90
+ .object({ index: z.number(), count: z.number(), endIndex: z.number(), instruction: z.boolean() })
91
+ .optional(),
92
+ })
93
+ .meta({ ref: "ExecutionTrajectoryNode" })
94
+ export type Node = z.infer<typeof Node>
95
+ export const Task = z
96
+ .object({
97
+ sessionID: z.string(),
98
+ nodeID: z.string().nullable(),
99
+ parentID: z.string().nullable(),
100
+ title: z.string(),
101
+ status: z.enum([
102
+ "running",
103
+ "completed",
104
+ "failed",
105
+ "cancelled",
106
+ "interrupted",
107
+ "unknown",
108
+ "queued",
109
+ "paused",
110
+ "waiting",
111
+ ]),
112
+ elapsedMs: z.number().nullable(),
113
+ elapsedActive: z.boolean(),
114
+ elapsedLowerBound: z.boolean(),
115
+ tokens: RolloutAccounting.Metric,
116
+ runs: z.array(z.string()),
117
+ interaction: SessionInteraction.Info.optional(),
118
+ cortex: z
119
+ .object({
120
+ taskID: CortexTypes.Task.shape.id,
121
+ agent: CortexTypes.Task.shape.agent,
122
+ status: CortexTypes.TaskStatus,
123
+ visibility: CortexTypes.Task.shape.visibility,
124
+ })
125
+ .optional(),
126
+ })
127
+ .meta({ ref: "ExecutionTask" })
128
+ export const ContextQuery = z.object({
129
+ runID: z.string().optional(),
130
+ cursor: z.string().max(4096).optional(),
131
+ limit: z.coerce.number().int().min(1).max(100).default(30),
132
+ })
133
+ export const ContextSnapshot = z
134
+ .object({
135
+ sessionID: z.string(),
136
+ callID: z.string(),
137
+ nodeID: z.string(),
138
+ runID: z.string(),
139
+ started: z.number(),
140
+ requestNumber: z.number().int().positive(),
141
+ roundNumber: z.number().int().positive(),
142
+ status: RolloutSchema.Status,
143
+ modelID: z.string(),
144
+ providerID: z.string(),
145
+ inputTokens: z.number().nonnegative().nullable(),
146
+ contextLimit: z.number().nonnegative().nullable(),
147
+ outputTokens: z.number().nonnegative().nullable(),
148
+ cacheHit: z.number().min(0).max(1).nullable(),
149
+ elapsedMs: z.number().nonnegative().nullable(),
150
+ retries: z.number().int().nonnegative(),
151
+ usage: MessageV2.Assistant.shape.contextUsage.unwrap().nullable(),
152
+ estimate: ContextUsageEstimateSchema.optional(),
153
+ compactedBefore: z.boolean(),
154
+ requestAvailable: z.boolean(),
155
+ })
156
+ .meta({ ref: "ExecutionContextSnapshot" })
157
+ export type ContextSnapshot = z.infer<typeof ContextSnapshot>
158
+ export const ContextHistory = z
159
+ .object({
160
+ sessionID: z.string(),
161
+ revision: z.number(),
162
+ total: z.number(),
163
+ items: z.array(ContextSnapshot),
164
+ nextCursor: z.string().nullable(),
165
+ })
166
+ .meta({ ref: "ExecutionContextHistory" })
167
+ export const ContextItemsQuery = ContextQuery.extend({
168
+ category: MessageV2.ContextSource.shape.category.optional(),
169
+ query: z.string().max(500).optional(),
170
+ version: z.string().max(4096).optional(),
171
+ })
172
+ export const ContextItem = MessageV2.ContextSource.extend({
173
+ id: z.string(),
174
+ offset: z.number().nonnegative(),
175
+ bytes: z.number().nonnegative(),
176
+ }).meta({ ref: "ExecutionContextItem" })
177
+ export const ContextItems = z
178
+ .object({
179
+ callID: z.string(),
180
+ nodeID: z.string(),
181
+ contentVersion: z.string().nullable(),
182
+ status: z.enum(["available", "legacy", "unavailable"]),
183
+ items: z.array(ContextItem),
184
+ total: z.number(),
185
+ nextCursor: z.string().nullable(),
186
+ truncated: z.boolean(),
187
+ })
188
+ .meta({ ref: "ExecutionContextItems" })
189
+ export const Summary = z
190
+ .object({
191
+ sessionID: z.string(),
192
+ revision: z.number(),
193
+ runID: z.string().optional(),
194
+ computedAt: z.number(),
195
+ clockID: z.string(),
196
+ sampledAt: z.number(),
197
+ status: Task.shape.status,
198
+ elapsedMs: z.number().nullable(),
199
+ elapsedActive: z.boolean(),
200
+ elapsedLowerBound: z.boolean(),
201
+ accounting: RolloutAccounting.Summary,
202
+ cost: ExecutionPresentation.Cost,
203
+ own: RolloutAccounting.Summary,
204
+ descendants: RolloutAccounting.Summary,
205
+ rates: Usage.Summary.shape.rates,
206
+ cache: Usage.Summary.shape.cache,
207
+ latency: Usage.Summary.shape.latency,
208
+ outcomes: Usage.Summary.shape.outcomes,
209
+ tools: Usage.Summary.shape.tools,
210
+ context: Usage.Summary.shape.context,
211
+ contextDistribution: MessageV2.Assistant.shape.contextUsage.unwrap().nullable(),
212
+ tasks: z.array(Task),
213
+ rounds: z.array(
214
+ z.object({
215
+ id: z.string(),
216
+ title: z.string(),
217
+ started: z.number(),
218
+ status: Task.shape.status,
219
+ elapsedMs: z.number().nullable(),
220
+ elapsedActive: z.boolean(),
221
+ elapsedLowerBound: z.boolean(),
222
+ }),
223
+ ),
224
+ coverage: z.object({
225
+ recorded: z.number(),
226
+ messages: z.number(),
227
+ gaps: z.number().nullable(),
228
+ partial: z.boolean(),
229
+ }),
230
+ lanes: z.array(
231
+ z.object({
232
+ kind: z.enum(["input", "model", "tool"]),
233
+ start: z.number(),
234
+ end: z.number(),
235
+ nodes: z.array(Node),
236
+ total: z.number(),
237
+ }),
238
+ ),
239
+ activityTotal: z.number(),
240
+ activitySegments: z
241
+ .array(
242
+ z.object({
243
+ runID: z.string().nullable(),
244
+ from: z.number(),
245
+ to: z.number(),
246
+ count: z.number(),
247
+ rounds: z.number(),
248
+ }),
249
+ )
250
+ .optional(),
251
+ humanInputs: z.number(),
252
+ taskInstructions: z.number(),
253
+ })
254
+ .meta({ ref: "ExecutionSummary" })
255
+ export type Summary = z.infer<typeof Summary>
256
+ export const Page = z
257
+ .object({
258
+ sessionID: z.string(),
259
+ revision: z.number(),
260
+ total: z.number(),
261
+ items: z.array(Node),
262
+ nextCursor: z.string().nullable(),
263
+ previousCursor: z.string().nullable(),
264
+ })
265
+ .meta({ ref: "ExecutionTrajectoryPage" })
266
+ export const Detail = z
267
+ .object({
268
+ node: Node,
269
+ execution: Summary.pick({
270
+ status: true,
271
+ elapsedMs: true,
272
+ elapsedActive: true,
273
+ elapsedLowerBound: true,
274
+ clockID: true,
275
+ sampledAt: true,
276
+ revision: true,
277
+ }).optional(),
278
+ record: Json.nullable(),
279
+ sources: z.array(z.object({ field: z.string(), artifact: RolloutSchema.ArtifactRef })),
280
+ definitions: Json.nullable(),
281
+ related: z.array(Node),
282
+ })
283
+ .meta({ ref: "ExecutionNodeDetail" })
284
+ export const Content = RolloutEvidence.Content
285
+ export const Updated = BusEvent.define(
286
+ "execution.updated",
287
+ z.object({
288
+ sessionID: z.string(),
289
+ revision: z.number(),
290
+ summary: Summary,
291
+ roundSummaries: z.array(Summary),
292
+ contextUpserts: z.array(ContextSnapshot).optional(),
293
+ previousRevision: z.number().int().nonnegative().optional(),
294
+ upserts: z.array(Node),
295
+ processUpserts: z.array(Node).optional(),
296
+ processRemoved: z.array(z.string()).optional(),
297
+ removed: z.array(z.string()),
298
+ }),
299
+ )
300
+ const ProjectionBase = z.object({
301
+ sessionID: z.string(),
302
+ revision: z.number().int().nonnegative(),
303
+ previousRevision: z.number().int().nonnegative(),
304
+ contexts: z.array(ContextSnapshot),
305
+ contextTotal: z.number().int().nonnegative(),
306
+ })
307
+ export const Projection = z
308
+ .discriminatedUnion("state", [
309
+ ProjectionBase.extend({ state: z.literal("root") }),
310
+ ProjectionBase.extend({
311
+ state: z.literal("preparing"),
312
+ progress: z.object({
313
+ stage: z.enum(["metadata", "messages", "parts"]),
314
+ prepared: z.number().int().nonnegative(),
315
+ total: z.number().int().nonnegative().optional(),
316
+ }),
317
+ }),
318
+ ProjectionBase.extend({
319
+ state: z.literal("failed"),
320
+ error: z.object({ kind: z.string(), message: z.string(), retryable: z.boolean() }),
321
+ }),
322
+ ProjectionBase.extend({
323
+ state: z.literal("ready"),
324
+ summary: Summary,
325
+ detailPreviousRevision: z.number().int().nonnegative(),
326
+ roundSummaries: z.array(Summary),
327
+ upserts: z.array(Node),
328
+ processUpserts: z.array(Node),
329
+ processRemoved: z.array(z.string()),
330
+ removed: z.array(z.string()),
331
+ }),
332
+ ])
333
+ .meta({ ref: "ExecutionProjection" })
334
+ export type Projection = z.infer<typeof Projection>
335
+ export const ProjectionUpdated = BusEvent.define("execution.projection", Projection)
336
+ }