specrails-hub 0.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.
@@ -0,0 +1,360 @@
1
+ export type PhaseName = string
2
+ export type PhaseState = 'idle' | 'running' | 'done' | 'error'
3
+
4
+ export interface PhaseDefinition {
5
+ key: string
6
+ label: string
7
+ description: string
8
+ }
9
+
10
+ // ─── ProjectRow (hub-level) — re-exported from hub-db for WS message use ─────
11
+
12
+ import type { ProjectRow } from './hub-db'
13
+ export type { ProjectRow }
14
+
15
+ // ─── ProposalRow re-export ────────────────────────────────────────────────────
16
+
17
+ export type { ProposalRow } from './db'
18
+
19
+ export interface LogMessage {
20
+ type: 'log'
21
+ source: 'stdout' | 'stderr'
22
+ line: string
23
+ timestamp: string
24
+ processId: string
25
+ projectId?: string
26
+ }
27
+
28
+ export interface PhaseMessage {
29
+ type: 'phase'
30
+ phase: PhaseName
31
+ state: PhaseState
32
+ timestamp: string
33
+ projectId?: string
34
+ }
35
+
36
+ export type JobStatus = 'queued' | 'running' | 'completed' | 'failed' | 'canceled'
37
+
38
+ export interface JobRow {
39
+ id: string
40
+ command: string
41
+ started_at: string
42
+ finished_at: string | null
43
+ status: JobStatus
44
+ exit_code: number | null
45
+ queue_position: number | null
46
+ tokens_in: number | null
47
+ tokens_out: number | null
48
+ tokens_cache_read: number | null
49
+ tokens_cache_create: number | null
50
+ total_cost_usd: number | null
51
+ num_turns: number | null
52
+ model: string | null
53
+ duration_ms: number | null
54
+ duration_api_ms: number | null
55
+ session_id: string | null
56
+ }
57
+
58
+ export interface EventRow {
59
+ id: number
60
+ job_id: string
61
+ seq: number
62
+ event_type: string
63
+ source: string | null
64
+ payload: string
65
+ timestamp: string
66
+ }
67
+
68
+ export interface StatsRow {
69
+ totalJobs: number
70
+ jobsToday: number
71
+ totalCostUsd: number
72
+ costToday: number
73
+ avgDurationMs: number | null
74
+ }
75
+
76
+ export type AnalyticsPeriod = '7d' | '30d' | '90d' | 'all' | 'custom'
77
+
78
+ export interface AnalyticsOpts {
79
+ period: AnalyticsPeriod
80
+ from?: string
81
+ to?: string
82
+ }
83
+
84
+ export interface AnalyticsResponse {
85
+ period: {
86
+ label: string
87
+ from: string | null
88
+ to: string | null
89
+ }
90
+ kpi: {
91
+ totalCostUsd: number
92
+ totalJobs: number
93
+ successRate: number
94
+ avgDurationMs: number | null
95
+ costDelta: number | null
96
+ jobsDelta: number | null
97
+ successRateDelta: number | null
98
+ avgDurationDelta: number | null
99
+ }
100
+ costTimeline: Array<{ date: string; costUsd: number }>
101
+ statusBreakdown: Array<{ status: string; count: number }>
102
+ durationHistogram: Array<{ bucket: string; count: number }>
103
+ durationPercentiles: { p50: number | null; p75: number | null; p95: number | null }
104
+ tokenEfficiency: Array<{
105
+ command: string
106
+ tokensOut: number
107
+ tokensCacheRead: number
108
+ totalTokens: number
109
+ }>
110
+ commandPerformance: Array<{
111
+ command: string
112
+ totalRuns: number
113
+ successRate: number
114
+ avgCostUsd: number | null
115
+ avgDurationMs: number | null
116
+ totalCostUsd: number
117
+ }>
118
+ dailyThroughput: Array<{ date: string; completed: number; failed: number; canceled: number }>
119
+ costPerCommand: Array<{ command: string; totalCostUsd: number; jobCount: number }>
120
+ bonusMetrics: {
121
+ costPerSuccess: number | null
122
+ apiEfficiencyPct: number | null
123
+ failureCostUsd: number
124
+ modelBreakdown: Array<{ model: string; jobCount: number; totalCostUsd: number }>
125
+ }
126
+ }
127
+
128
+ export interface ChatConversationRow {
129
+ id: string
130
+ title: string | null
131
+ model: string
132
+ session_id: string | null
133
+ created_at: string
134
+ updated_at: string
135
+ }
136
+
137
+ export interface ChatMessageRow {
138
+ id: number
139
+ conversation_id: string
140
+ role: 'user' | 'assistant'
141
+ content: string
142
+ created_at: string
143
+ }
144
+
145
+ export interface JobSummary {
146
+ id: string
147
+ command: string
148
+ started_at: string
149
+ status: JobStatus
150
+ total_cost_usd: number | null
151
+ }
152
+
153
+ export interface Job {
154
+ id: string
155
+ command: string
156
+ status: JobStatus
157
+ queuePosition: number | null
158
+ startedAt: string | null
159
+ finishedAt: string | null
160
+ exitCode: number | null
161
+ }
162
+
163
+ export interface QueueMessage {
164
+ type: 'queue'
165
+ jobs: Job[]
166
+ activeJobId: string | null
167
+ paused: boolean
168
+ timestamp: string
169
+ projectId?: string
170
+ }
171
+
172
+ export interface InitMessage {
173
+ type: 'init'
174
+ projectName: string
175
+ phases: Record<PhaseName, PhaseState>
176
+ phaseDefinitions: PhaseDefinition[]
177
+ logBuffer: LogMessage[]
178
+ recentJobs: JobSummary[]
179
+ queue: {
180
+ jobs: Job[]
181
+ activeJobId: string | null
182
+ paused: boolean
183
+ }
184
+ projectId?: string
185
+ }
186
+
187
+ export interface EventMessage {
188
+ type: 'event'
189
+ jobId: string
190
+ event_type: string
191
+ source: string
192
+ payload: string
193
+ timestamp: string
194
+ seq: number
195
+ projectId?: string
196
+ }
197
+
198
+ export interface ChatStreamMessage {
199
+ type: 'chat_stream'
200
+ conversationId: string
201
+ delta: string
202
+ timestamp: string
203
+ projectId?: string
204
+ }
205
+
206
+ export interface ChatDoneMessage {
207
+ type: 'chat_done'
208
+ conversationId: string
209
+ fullText: string
210
+ timestamp: string
211
+ projectId?: string
212
+ }
213
+
214
+ export interface ChatErrorMessage {
215
+ type: 'chat_error'
216
+ conversationId: string
217
+ error: string
218
+ timestamp: string
219
+ projectId?: string
220
+ }
221
+
222
+ export interface ChatCommandProposalMessage {
223
+ type: 'chat_command_proposal'
224
+ conversationId: string
225
+ command: string
226
+ timestamp: string
227
+ projectId?: string
228
+ }
229
+
230
+ export interface ChatTitleUpdateMessage {
231
+ type: 'chat_title_update'
232
+ conversationId: string
233
+ title: string
234
+ timestamp: string
235
+ projectId?: string
236
+ }
237
+
238
+ // ─── Hub-level message types ──────────────────────────────────────────────────
239
+
240
+ export interface HubProjectsMessage {
241
+ type: 'hub.projects'
242
+ projects: ProjectRow[]
243
+ timestamp: string
244
+ }
245
+
246
+ export interface HubProjectAddedMessage {
247
+ type: 'hub.project_added'
248
+ project: ProjectRow
249
+ timestamp: string
250
+ }
251
+
252
+ export interface HubProjectRemovedMessage {
253
+ type: 'hub.project_removed'
254
+ projectId: string
255
+ timestamp: string
256
+ }
257
+
258
+ // ─── Setup message types ──────────────────────────────────────────────────────
259
+
260
+ export interface SetupLogMessage {
261
+ type: 'setup_log'
262
+ projectId: string
263
+ line: string
264
+ stream: 'stdout' | 'stderr'
265
+ }
266
+
267
+ export interface SetupCheckpointMessage {
268
+ type: 'setup_checkpoint'
269
+ projectId: string
270
+ checkpoint: string
271
+ status: 'running' | 'done'
272
+ detail?: string
273
+ duration_ms?: number
274
+ }
275
+
276
+ export interface SetupChatMessage {
277
+ type: 'setup_chat'
278
+ projectId: string
279
+ text: string
280
+ role: 'assistant' | 'user'
281
+ }
282
+
283
+ export interface SetupInstallDoneMessage {
284
+ type: 'setup_install_done'
285
+ projectId: string
286
+ timestamp: string
287
+ }
288
+
289
+ export interface SetupCompleteMessage {
290
+ type: 'setup_complete'
291
+ projectId: string
292
+ sessionId?: string
293
+ summary: { agents: number; personas: number; commands: number }
294
+ }
295
+
296
+ export interface SetupErrorMessage {
297
+ type: 'setup_error'
298
+ projectId: string
299
+ error: string
300
+ }
301
+
302
+ export interface SetupTurnDoneMessage {
303
+ type: 'setup_turn_done'
304
+ projectId: string
305
+ sessionId?: string
306
+ }
307
+
308
+ // ─── Proposal message types ───────────────────────────────────────────────────
309
+
310
+ export interface ProposalStreamMessage {
311
+ type: 'proposal_stream'
312
+ projectId: string
313
+ proposalId: string
314
+ delta: string
315
+ timestamp: string
316
+ }
317
+
318
+ export interface ProposalReadyMessage {
319
+ type: 'proposal_ready'
320
+ projectId: string
321
+ proposalId: string
322
+ markdown: string
323
+ timestamp: string
324
+ }
325
+
326
+ export interface ProposalRefinedMessage {
327
+ type: 'proposal_refined'
328
+ projectId: string
329
+ proposalId: string
330
+ markdown: string
331
+ timestamp: string
332
+ }
333
+
334
+ export interface ProposalIssueCreatedMessage {
335
+ type: 'proposal_issue_created'
336
+ projectId: string
337
+ proposalId: string
338
+ issueUrl: string
339
+ timestamp: string
340
+ }
341
+
342
+ export interface ProposalErrorMessage {
343
+ type: 'proposal_error'
344
+ projectId: string
345
+ proposalId: string
346
+ error: string
347
+ timestamp: string
348
+ }
349
+
350
+ export type WsMessage =
351
+ | LogMessage | PhaseMessage | InitMessage | QueueMessage | EventMessage
352
+ | ChatStreamMessage | ChatDoneMessage | ChatErrorMessage
353
+ | ChatCommandProposalMessage | ChatTitleUpdateMessage
354
+ | HubProjectsMessage | HubProjectAddedMessage | HubProjectRemovedMessage
355
+ | SetupLogMessage | SetupCheckpointMessage | SetupChatMessage
356
+ | SetupInstallDoneMessage | SetupCompleteMessage | SetupErrorMessage
357
+ | SetupTurnDoneMessage
358
+ | ProposalStreamMessage | ProposalReadyMessage | ProposalRefinedMessage
359
+ | ProposalIssueCreatedMessage | ProposalErrorMessage
360
+