agileflow 3.4.1 → 3.4.3
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.
- package/CHANGELOG.md +10 -0
- package/README.md +2 -2
- package/lib/drivers/claude-driver.ts +1 -1
- package/lib/lazy-require.js +1 -1
- package/package.json +1 -1
- package/scripts/agent-loop.js +290 -230
- package/scripts/check-sessions.js +116 -0
- package/scripts/lib/audit-registry.js +36 -0
- package/scripts/lib/quality-gates.js +35 -8
- package/scripts/lib/signal-detectors.js +0 -13
- package/scripts/lib/team-events.js +1 -1
- package/scripts/lib/tmux-audit-monitor.js +2 -1
- package/scripts/lib/tmux-group-colors.js +2 -2
- package/scripts/spawn-audit-sessions.js +1 -1
- package/src/core/commands/ads/audit.md +84 -6
- package/src/core/commands/code/accessibility.md +22 -6
- package/src/core/commands/code/api.md +22 -6
- package/src/core/commands/code/architecture.md +22 -6
- package/src/core/commands/code/completeness.md +22 -6
- package/src/core/commands/code/legal.md +22 -6
- package/src/core/commands/code/logic.md +22 -6
- package/src/core/commands/code/performance.md +22 -6
- package/src/core/commands/code/security.md +22 -6
- package/src/core/commands/code/test.md +22 -6
- package/src/core/commands/ideate/features.md +5 -4
- package/src/core/commands/ideate/new.md +8 -7
- package/src/core/commands/seo/audit.md +78 -7
- package/lib/claude-cli-bridge.js +0 -215
- package/lib/dashboard-automations.js +0 -130
- package/lib/dashboard-git.js +0 -254
- package/lib/dashboard-inbox.js +0 -64
- package/lib/dashboard-protocol.js +0 -605
- package/lib/dashboard-server.js +0 -1296
- package/lib/dashboard-session.js +0 -136
- package/lib/dashboard-status.js +0 -72
- package/lib/dashboard-terminal.js +0 -354
- package/lib/dashboard-websocket.js +0 -88
- package/scripts/dashboard-serve.js +0 -336
- package/src/core/commands/serve.md +0 -127
- package/tools/cli/commands/serve.js +0 -492
|
@@ -1,605 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* dashboard-protocol.js - WebSocket Protocol for Dashboard Communication
|
|
3
|
-
*
|
|
4
|
-
* Defines message types for bidirectional communication between
|
|
5
|
-
* the CLI WebSocket server and the AgileFlow Dashboard.
|
|
6
|
-
*
|
|
7
|
-
* Message Flow:
|
|
8
|
-
* - Dashboard → CLI: User messages, commands, git actions
|
|
9
|
-
* - CLI → Dashboard: Text streaming, tool calls, status updates
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
'use strict';
|
|
13
|
-
|
|
14
|
-
// ============================================================================
|
|
15
|
-
// Message Types: CLI → Dashboard
|
|
16
|
-
// ============================================================================
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Message types sent from CLI to Dashboard
|
|
20
|
-
* @enum {string}
|
|
21
|
-
*/
|
|
22
|
-
const OutboundMessageType = {
|
|
23
|
-
// Connection & Session
|
|
24
|
-
SESSION_STATE: 'session_state', // Session connected/resumed
|
|
25
|
-
SESSION_ERROR: 'session_error', // Session error
|
|
26
|
-
|
|
27
|
-
// Text Streaming
|
|
28
|
-
TEXT: 'text', // Claude text response
|
|
29
|
-
TEXT_DELTA: 'text_delta', // Streaming text chunk
|
|
30
|
-
|
|
31
|
-
// Tool Calls
|
|
32
|
-
TOOL_START: 'tool_start', // Tool call started
|
|
33
|
-
TOOL_RESULT: 'tool_result', // Tool call completed
|
|
34
|
-
|
|
35
|
-
// File Operations
|
|
36
|
-
FILE_READ: 'file_read', // File was read
|
|
37
|
-
FILE_WRITE: 'file_write', // File was written
|
|
38
|
-
FILE_EDIT: 'file_edit', // File was edited (diff)
|
|
39
|
-
|
|
40
|
-
// Shell Operations
|
|
41
|
-
BASH_START: 'bash_start', // Bash command started
|
|
42
|
-
BASH_OUTPUT: 'bash_output', // Bash output chunk
|
|
43
|
-
BASH_END: 'bash_end', // Bash command completed
|
|
44
|
-
|
|
45
|
-
// Task Management
|
|
46
|
-
TASK_CREATED: 'task_created', // Task was created
|
|
47
|
-
TASK_UPDATED: 'task_updated', // Task status changed
|
|
48
|
-
TASK_LIST: 'task_list', // Full task list
|
|
49
|
-
|
|
50
|
-
// Git Status
|
|
51
|
-
GIT_STATUS: 'git_status', // Git status update
|
|
52
|
-
GIT_DIFF: 'git_diff', // Git diff content
|
|
53
|
-
|
|
54
|
-
// Project Status
|
|
55
|
-
STATUS_UPDATE: 'status_update', // Story/epic status update
|
|
56
|
-
|
|
57
|
-
// Agent Communication
|
|
58
|
-
AGENT_SPAWN: 'agent_spawn', // Sub-agent spawned
|
|
59
|
-
AGENT_RESULT: 'agent_result', // Sub-agent completed
|
|
60
|
-
|
|
61
|
-
// Notifications
|
|
62
|
-
NOTIFICATION: 'notification', // General notification
|
|
63
|
-
|
|
64
|
-
// Terminal
|
|
65
|
-
TERMINAL_OUTPUT: 'terminal_output', // Terminal output data
|
|
66
|
-
TERMINAL_RESIZE: 'terminal_resize', // Terminal resize acknowledgment
|
|
67
|
-
TERMINAL_EXIT: 'terminal_exit', // Terminal process exited
|
|
68
|
-
|
|
69
|
-
// Automations
|
|
70
|
-
AUTOMATION_LIST: 'automation_list', // List of all automations
|
|
71
|
-
AUTOMATION_STATUS: 'automation_status', // Automation run status update
|
|
72
|
-
AUTOMATION_RESULT: 'automation_result', // Automation run completed
|
|
73
|
-
|
|
74
|
-
// Inbox
|
|
75
|
-
INBOX_LIST: 'inbox_list', // List of inbox items
|
|
76
|
-
INBOX_ITEM: 'inbox_item', // Single inbox item
|
|
77
|
-
|
|
78
|
-
// User Interaction
|
|
79
|
-
ASK_USER_QUESTION: 'ask_user_question', // Claude is asking user a question
|
|
80
|
-
|
|
81
|
-
// Sessions
|
|
82
|
-
SESSION_LIST: 'session_list', // Session list with sync status
|
|
83
|
-
|
|
84
|
-
// Team Metrics
|
|
85
|
-
TEAM_METRICS: 'team_metrics', // Team metrics update (per-agent, per-gate)
|
|
86
|
-
|
|
87
|
-
// Errors
|
|
88
|
-
ERROR: 'error', // General error
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Message types sent from Dashboard to CLI
|
|
93
|
-
* @enum {string}
|
|
94
|
-
*/
|
|
95
|
-
const InboundMessageType = {
|
|
96
|
-
// Messages
|
|
97
|
-
MESSAGE: 'message', // User message to Claude
|
|
98
|
-
CANCEL: 'cancel', // Cancel current operation
|
|
99
|
-
|
|
100
|
-
// Session
|
|
101
|
-
SESSION_INIT: 'session_init', // Initialize/resume session
|
|
102
|
-
SESSION_CLOSE: 'session_close', // Close session
|
|
103
|
-
|
|
104
|
-
// Requests
|
|
105
|
-
REFRESH: 'refresh', // Request status refresh
|
|
106
|
-
|
|
107
|
-
// Git Operations
|
|
108
|
-
GIT_STAGE: 'git_stage', // Stage file(s)
|
|
109
|
-
GIT_UNSTAGE: 'git_unstage', // Unstage file(s)
|
|
110
|
-
GIT_REVERT: 'git_revert', // Revert file(s)
|
|
111
|
-
GIT_COMMIT: 'git_commit', // Create commit
|
|
112
|
-
GIT_PUSH: 'git_push', // Push to remote
|
|
113
|
-
GIT_PR: 'git_pr', // Create pull request
|
|
114
|
-
GIT_DIFF_REQUEST: 'git_diff_request', // Request diff for a file
|
|
115
|
-
|
|
116
|
-
// Feedback
|
|
117
|
-
INLINE_COMMENT: 'inline_comment', // Comment on diff line
|
|
118
|
-
|
|
119
|
-
// Terminal
|
|
120
|
-
TERMINAL_INPUT: 'terminal_input', // Terminal stdin
|
|
121
|
-
TERMINAL_RESIZE: 'terminal_resize', // Resize terminal
|
|
122
|
-
TERMINAL_SPAWN: 'terminal_spawn', // Spawn new terminal
|
|
123
|
-
TERMINAL_CLOSE: 'terminal_close', // Close terminal
|
|
124
|
-
|
|
125
|
-
// Automation
|
|
126
|
-
AUTOMATION_RUN: 'automation_run', // Run automation
|
|
127
|
-
AUTOMATION_STOP: 'automation_stop', // Stop automation
|
|
128
|
-
AUTOMATION_LIST_REQUEST: 'automation_list_request', // Request automation list
|
|
129
|
-
INBOX_LIST_REQUEST: 'inbox_list_request', // Request inbox list
|
|
130
|
-
INBOX_ACTION: 'inbox_action', // Accept/dismiss inbox item
|
|
131
|
-
|
|
132
|
-
// File Operations
|
|
133
|
-
OPEN_FILE: 'open_file', // Open file in editor
|
|
134
|
-
|
|
135
|
-
// User Interaction Response
|
|
136
|
-
USER_ANSWER: 'user_answer', // User's answer to AskUserQuestion
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
// ============================================================================
|
|
140
|
-
// Message Payload Types
|
|
141
|
-
// ============================================================================
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* Create a session state message
|
|
145
|
-
* @param {string} sessionId - Session identifier
|
|
146
|
-
* @param {string} state - Session state (connected, thinking, idle, error)
|
|
147
|
-
* @param {Object} [meta] - Additional metadata
|
|
148
|
-
*/
|
|
149
|
-
function createSessionState(sessionId, state, meta = {}) {
|
|
150
|
-
return {
|
|
151
|
-
type: OutboundMessageType.SESSION_STATE,
|
|
152
|
-
sessionId,
|
|
153
|
-
state,
|
|
154
|
-
timestamp: new Date().toISOString(),
|
|
155
|
-
...meta,
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* Create a text response message
|
|
161
|
-
* @param {string} content - Text content
|
|
162
|
-
* @param {boolean} [done=false] - Whether this is the final chunk
|
|
163
|
-
*/
|
|
164
|
-
function createTextMessage(content, done = false) {
|
|
165
|
-
return {
|
|
166
|
-
type: OutboundMessageType.TEXT,
|
|
167
|
-
content,
|
|
168
|
-
done,
|
|
169
|
-
timestamp: new Date().toISOString(),
|
|
170
|
-
};
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
/**
|
|
174
|
-
* Create a text delta (streaming chunk) message
|
|
175
|
-
* @param {string} delta - Text chunk
|
|
176
|
-
* @param {boolean} [done=false] - Whether this is the final chunk
|
|
177
|
-
*/
|
|
178
|
-
function createTextDelta(delta, done = false) {
|
|
179
|
-
return {
|
|
180
|
-
type: OutboundMessageType.TEXT_DELTA,
|
|
181
|
-
delta,
|
|
182
|
-
done,
|
|
183
|
-
timestamp: new Date().toISOString(),
|
|
184
|
-
};
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* Create a tool start message
|
|
189
|
-
* @param {string} id - Tool call ID
|
|
190
|
-
* @param {string} tool - Tool name (Read, Write, Edit, Bash, etc.)
|
|
191
|
-
* @param {Object} input - Tool input parameters
|
|
192
|
-
*/
|
|
193
|
-
function createToolStart(id, tool, input) {
|
|
194
|
-
return {
|
|
195
|
-
type: OutboundMessageType.TOOL_START,
|
|
196
|
-
id,
|
|
197
|
-
tool,
|
|
198
|
-
input,
|
|
199
|
-
timestamp: new Date().toISOString(),
|
|
200
|
-
};
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
/**
|
|
204
|
-
* Create a tool result message
|
|
205
|
-
* @param {string} id - Tool call ID
|
|
206
|
-
* @param {*} output - Tool output
|
|
207
|
-
* @param {string} [error] - Error message if failed
|
|
208
|
-
*/
|
|
209
|
-
function createToolResult(id, output, error = null) {
|
|
210
|
-
return {
|
|
211
|
-
type: OutboundMessageType.TOOL_RESULT,
|
|
212
|
-
id,
|
|
213
|
-
output,
|
|
214
|
-
error,
|
|
215
|
-
success: !error,
|
|
216
|
-
timestamp: new Date().toISOString(),
|
|
217
|
-
};
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
/**
|
|
221
|
-
* Create a file read message
|
|
222
|
-
* @param {string} path - File path
|
|
223
|
-
* @param {string} content - File content
|
|
224
|
-
* @param {Object} [meta] - Additional metadata (lines, truncated, etc.)
|
|
225
|
-
*/
|
|
226
|
-
function createFileRead(path, content, meta = {}) {
|
|
227
|
-
return {
|
|
228
|
-
type: OutboundMessageType.FILE_READ,
|
|
229
|
-
path,
|
|
230
|
-
content,
|
|
231
|
-
...meta,
|
|
232
|
-
timestamp: new Date().toISOString(),
|
|
233
|
-
};
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
/**
|
|
237
|
-
* Create a file edit message with diff
|
|
238
|
-
* @param {string} path - File path
|
|
239
|
-
* @param {Object} diff - Diff information
|
|
240
|
-
* @param {string} diff.oldContent - Original content
|
|
241
|
-
* @param {string} diff.newContent - New content
|
|
242
|
-
* @param {Array} [diff.hunks] - Diff hunks
|
|
243
|
-
*/
|
|
244
|
-
function createFileEdit(path, diff) {
|
|
245
|
-
return {
|
|
246
|
-
type: OutboundMessageType.FILE_EDIT,
|
|
247
|
-
path,
|
|
248
|
-
diff,
|
|
249
|
-
timestamp: new Date().toISOString(),
|
|
250
|
-
};
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
/**
|
|
254
|
-
* Create a bash output message
|
|
255
|
-
* @param {string} command - Command that was run
|
|
256
|
-
* @param {string} output - Command output
|
|
257
|
-
* @param {number} [exitCode] - Exit code if completed
|
|
258
|
-
* @param {boolean} [done=false] - Whether command has completed
|
|
259
|
-
*/
|
|
260
|
-
function createBashOutput(command, output, exitCode = null, done = false) {
|
|
261
|
-
return {
|
|
262
|
-
type: done ? OutboundMessageType.BASH_END : OutboundMessageType.BASH_OUTPUT,
|
|
263
|
-
command,
|
|
264
|
-
output,
|
|
265
|
-
exitCode,
|
|
266
|
-
done,
|
|
267
|
-
timestamp: new Date().toISOString(),
|
|
268
|
-
};
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
/**
|
|
272
|
-
* Create a git status message
|
|
273
|
-
* @param {Object} status - Git status information
|
|
274
|
-
* @param {Array} status.staged - Staged files
|
|
275
|
-
* @param {Array} status.unstaged - Unstaged files
|
|
276
|
-
* @param {string} status.branch - Current branch
|
|
277
|
-
*/
|
|
278
|
-
function createGitStatus(status) {
|
|
279
|
-
return {
|
|
280
|
-
type: OutboundMessageType.GIT_STATUS,
|
|
281
|
-
...status,
|
|
282
|
-
timestamp: new Date().toISOString(),
|
|
283
|
-
};
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
/**
|
|
287
|
-
* Create a task update message
|
|
288
|
-
* @param {string} action - Action type (create, update, list)
|
|
289
|
-
* @param {Object} task - Task data
|
|
290
|
-
*/
|
|
291
|
-
function createTaskUpdate(action, task) {
|
|
292
|
-
return {
|
|
293
|
-
type: action === 'list' ? OutboundMessageType.TASK_LIST : OutboundMessageType.TASK_UPDATED,
|
|
294
|
-
action,
|
|
295
|
-
task,
|
|
296
|
-
timestamp: new Date().toISOString(),
|
|
297
|
-
};
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
/**
|
|
301
|
-
* Create a notification message
|
|
302
|
-
* @param {string} level - Notification level (info, success, warning, error)
|
|
303
|
-
* @param {string} title - Notification title
|
|
304
|
-
* @param {string} message - Notification body
|
|
305
|
-
*/
|
|
306
|
-
function createNotification(level, title, message) {
|
|
307
|
-
return {
|
|
308
|
-
type: OutboundMessageType.NOTIFICATION,
|
|
309
|
-
level,
|
|
310
|
-
title,
|
|
311
|
-
message,
|
|
312
|
-
timestamp: new Date().toISOString(),
|
|
313
|
-
};
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
/**
|
|
317
|
-
* Create an error message
|
|
318
|
-
* @param {string} code - Error code
|
|
319
|
-
* @param {string} message - Error message
|
|
320
|
-
* @param {Object} [details] - Additional error details
|
|
321
|
-
*/
|
|
322
|
-
function createError(code, message, details = {}) {
|
|
323
|
-
return {
|
|
324
|
-
type: OutboundMessageType.ERROR,
|
|
325
|
-
code,
|
|
326
|
-
message,
|
|
327
|
-
details,
|
|
328
|
-
timestamp: new Date().toISOString(),
|
|
329
|
-
};
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
/**
|
|
333
|
-
* Create a git diff message
|
|
334
|
-
* @param {string} filePath - Path to the file
|
|
335
|
-
* @param {string} diff - The diff content
|
|
336
|
-
* @param {Object} stats - Diff statistics
|
|
337
|
-
* @param {number} stats.additions - Number of additions
|
|
338
|
-
* @param {number} stats.deletions - Number of deletions
|
|
339
|
-
* @param {boolean} stats.staged - Whether this is a staged diff
|
|
340
|
-
*/
|
|
341
|
-
function createGitDiff(filePath, diff, stats = {}) {
|
|
342
|
-
return {
|
|
343
|
-
type: OutboundMessageType.GIT_DIFF,
|
|
344
|
-
path: filePath,
|
|
345
|
-
diff,
|
|
346
|
-
additions: stats.additions || 0,
|
|
347
|
-
deletions: stats.deletions || 0,
|
|
348
|
-
staged: stats.staged || false,
|
|
349
|
-
timestamp: new Date().toISOString(),
|
|
350
|
-
};
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
/**
|
|
354
|
-
* Create a terminal output message
|
|
355
|
-
* @param {string} terminalId - Terminal instance ID
|
|
356
|
-
* @param {string} data - Output data (can include ANSI codes)
|
|
357
|
-
*/
|
|
358
|
-
function createTerminalOutput(terminalId, data) {
|
|
359
|
-
return {
|
|
360
|
-
type: OutboundMessageType.TERMINAL_OUTPUT,
|
|
361
|
-
terminalId,
|
|
362
|
-
data,
|
|
363
|
-
timestamp: new Date().toISOString(),
|
|
364
|
-
};
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
/**
|
|
368
|
-
* Create a terminal exit message
|
|
369
|
-
* @param {string} terminalId - Terminal instance ID
|
|
370
|
-
* @param {number} exitCode - Process exit code
|
|
371
|
-
*/
|
|
372
|
-
function createTerminalExit(terminalId, exitCode) {
|
|
373
|
-
return {
|
|
374
|
-
type: OutboundMessageType.TERMINAL_EXIT,
|
|
375
|
-
terminalId,
|
|
376
|
-
exitCode,
|
|
377
|
-
timestamp: new Date().toISOString(),
|
|
378
|
-
};
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
/**
|
|
382
|
-
* Create an automation list message
|
|
383
|
-
* @param {Object[]} automations - Array of automation objects
|
|
384
|
-
*/
|
|
385
|
-
function createAutomationList(automations) {
|
|
386
|
-
return {
|
|
387
|
-
type: OutboundMessageType.AUTOMATION_LIST,
|
|
388
|
-
automations,
|
|
389
|
-
timestamp: new Date().toISOString(),
|
|
390
|
-
};
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
/**
|
|
394
|
-
* Create an automation status update message
|
|
395
|
-
* @param {string} automationId - Automation ID
|
|
396
|
-
* @param {string} status - Status (idle, running, completed, error)
|
|
397
|
-
* @param {Object} [progress] - Progress information
|
|
398
|
-
*/
|
|
399
|
-
function createAutomationStatus(automationId, status, progress = {}) {
|
|
400
|
-
return {
|
|
401
|
-
type: OutboundMessageType.AUTOMATION_STATUS,
|
|
402
|
-
automationId,
|
|
403
|
-
status,
|
|
404
|
-
...progress,
|
|
405
|
-
timestamp: new Date().toISOString(),
|
|
406
|
-
};
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
/**
|
|
410
|
-
* Create an automation result message
|
|
411
|
-
* @param {string} automationId - Automation ID
|
|
412
|
-
* @param {Object} result - Automation run result
|
|
413
|
-
*/
|
|
414
|
-
function createAutomationResult(automationId, result) {
|
|
415
|
-
return {
|
|
416
|
-
type: OutboundMessageType.AUTOMATION_RESULT,
|
|
417
|
-
automationId,
|
|
418
|
-
...result,
|
|
419
|
-
timestamp: new Date().toISOString(),
|
|
420
|
-
};
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
/**
|
|
424
|
-
* Create an inbox list message
|
|
425
|
-
* @param {Object[]} items - Array of inbox items
|
|
426
|
-
*/
|
|
427
|
-
function createInboxList(items) {
|
|
428
|
-
return {
|
|
429
|
-
type: OutboundMessageType.INBOX_LIST,
|
|
430
|
-
items,
|
|
431
|
-
timestamp: new Date().toISOString(),
|
|
432
|
-
};
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
/**
|
|
436
|
-
* Create an inbox item message
|
|
437
|
-
* @param {Object} item - Inbox item
|
|
438
|
-
*/
|
|
439
|
-
function createInboxItem(item) {
|
|
440
|
-
return {
|
|
441
|
-
type: OutboundMessageType.INBOX_ITEM,
|
|
442
|
-
...item,
|
|
443
|
-
timestamp: new Date().toISOString(),
|
|
444
|
-
};
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
/**
|
|
448
|
-
* Create a project status update message
|
|
449
|
-
* @param {Object} summary - Status summary
|
|
450
|
-
* @param {number} summary.total - Total stories
|
|
451
|
-
* @param {number} summary.done - Completed stories
|
|
452
|
-
* @param {number} summary.inProgress - In-progress stories
|
|
453
|
-
* @param {number} summary.ready - Ready stories
|
|
454
|
-
* @param {number} summary.blocked - Blocked stories
|
|
455
|
-
* @param {Object[]} summary.epics - Epic summaries
|
|
456
|
-
*/
|
|
457
|
-
function createStatusUpdate(summary) {
|
|
458
|
-
return {
|
|
459
|
-
type: OutboundMessageType.STATUS_UPDATE,
|
|
460
|
-
...summary,
|
|
461
|
-
timestamp: new Date().toISOString(),
|
|
462
|
-
};
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
/**
|
|
466
|
-
* Create a session list message with sync status
|
|
467
|
-
* @param {Object[]} sessions - Array of session objects with sync info
|
|
468
|
-
*/
|
|
469
|
-
function createSessionList(sessions) {
|
|
470
|
-
return {
|
|
471
|
-
type: OutboundMessageType.SESSION_LIST,
|
|
472
|
-
sessions,
|
|
473
|
-
timestamp: new Date().toISOString(),
|
|
474
|
-
};
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
/**
|
|
478
|
-
* Create a team metrics message
|
|
479
|
-
* @param {string} traceId - Trace ID for the team run
|
|
480
|
-
* @param {Object} metrics - Aggregated metrics
|
|
481
|
-
* @param {Object} metrics.per_agent - Per-agent metrics
|
|
482
|
-
* @param {Object} metrics.per_gate - Per-gate metrics
|
|
483
|
-
* @param {number|null} metrics.team_completion_ms - Team completion time in ms
|
|
484
|
-
* @param {string} metrics.computed_at - When metrics were computed
|
|
485
|
-
*/
|
|
486
|
-
function createTeamMetrics(traceId, metrics) {
|
|
487
|
-
return {
|
|
488
|
-
type: OutboundMessageType.TEAM_METRICS,
|
|
489
|
-
trace_id: traceId,
|
|
490
|
-
per_agent: (metrics && metrics.per_agent) || {},
|
|
491
|
-
per_gate: (metrics && metrics.per_gate) || {},
|
|
492
|
-
team_completion_ms: metrics && metrics.team_completion_ms,
|
|
493
|
-
total_cost_usd: (metrics && metrics.total_cost_usd) || 0,
|
|
494
|
-
computed_at: metrics && metrics.computed_at,
|
|
495
|
-
timestamp: new Date().toISOString(),
|
|
496
|
-
};
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
/**
|
|
500
|
-
* Create an AskUserQuestion message
|
|
501
|
-
* @param {string} toolId - Tool call ID for response correlation
|
|
502
|
-
* @param {Object[]} questions - Array of questions with options
|
|
503
|
-
* @param {string} questions[].question - The question text
|
|
504
|
-
* @param {string} questions[].header - Short label for the question
|
|
505
|
-
* @param {Object[]} questions[].options - Available options
|
|
506
|
-
* @param {string} questions[].options[].label - Option label
|
|
507
|
-
* @param {string} questions[].options[].description - Option description
|
|
508
|
-
* @param {boolean} questions[].multiSelect - Whether multiple options can be selected
|
|
509
|
-
*/
|
|
510
|
-
function createAskUserQuestion(toolId, questions) {
|
|
511
|
-
return {
|
|
512
|
-
type: OutboundMessageType.ASK_USER_QUESTION,
|
|
513
|
-
toolId,
|
|
514
|
-
questions,
|
|
515
|
-
timestamp: new Date().toISOString(),
|
|
516
|
-
};
|
|
517
|
-
}
|
|
518
|
-
|
|
519
|
-
// ============================================================================
|
|
520
|
-
// Message Parsing & Validation
|
|
521
|
-
// ============================================================================
|
|
522
|
-
|
|
523
|
-
/**
|
|
524
|
-
* Parse an inbound message from the dashboard
|
|
525
|
-
* @param {string|Buffer} data - Raw message data
|
|
526
|
-
* @returns {{ type: string, payload: Object } | null}
|
|
527
|
-
*/
|
|
528
|
-
function parseInboundMessage(data) {
|
|
529
|
-
try {
|
|
530
|
-
const message = typeof data === 'string' ? JSON.parse(data) : JSON.parse(data.toString());
|
|
531
|
-
|
|
532
|
-
if (!message.type || !Object.values(InboundMessageType).includes(message.type)) {
|
|
533
|
-
console.error('[Protocol] Unknown message type:', message.type);
|
|
534
|
-
return null;
|
|
535
|
-
}
|
|
536
|
-
|
|
537
|
-
return message;
|
|
538
|
-
} catch (error) {
|
|
539
|
-
console.error('[Protocol] Failed to parse message:', error.message);
|
|
540
|
-
return null;
|
|
541
|
-
}
|
|
542
|
-
}
|
|
543
|
-
|
|
544
|
-
/**
|
|
545
|
-
* Validate a user message
|
|
546
|
-
* @param {Object} message - Message object
|
|
547
|
-
* @returns {boolean}
|
|
548
|
-
*/
|
|
549
|
-
function validateUserMessage(message) {
|
|
550
|
-
return (
|
|
551
|
-
message.type === InboundMessageType.MESSAGE &&
|
|
552
|
-
typeof message.content === 'string' &&
|
|
553
|
-
message.content.trim().length > 0
|
|
554
|
-
);
|
|
555
|
-
}
|
|
556
|
-
|
|
557
|
-
/**
|
|
558
|
-
* Serialize an outbound message
|
|
559
|
-
* @param {Object} message - Message object
|
|
560
|
-
* @returns {string}
|
|
561
|
-
*/
|
|
562
|
-
function serializeMessage(message) {
|
|
563
|
-
return JSON.stringify(message);
|
|
564
|
-
}
|
|
565
|
-
|
|
566
|
-
// ============================================================================
|
|
567
|
-
// Exports
|
|
568
|
-
// ============================================================================
|
|
569
|
-
|
|
570
|
-
module.exports = {
|
|
571
|
-
// Enums
|
|
572
|
-
OutboundMessageType,
|
|
573
|
-
InboundMessageType,
|
|
574
|
-
|
|
575
|
-
// Message Creators
|
|
576
|
-
createSessionState,
|
|
577
|
-
createTextMessage,
|
|
578
|
-
createTextDelta,
|
|
579
|
-
createToolStart,
|
|
580
|
-
createToolResult,
|
|
581
|
-
createFileRead,
|
|
582
|
-
createFileEdit,
|
|
583
|
-
createBashOutput,
|
|
584
|
-
createGitStatus,
|
|
585
|
-
createGitDiff,
|
|
586
|
-
createTerminalOutput,
|
|
587
|
-
createTerminalExit,
|
|
588
|
-
createTaskUpdate,
|
|
589
|
-
createNotification,
|
|
590
|
-
createError,
|
|
591
|
-
createAutomationList,
|
|
592
|
-
createAutomationStatus,
|
|
593
|
-
createAutomationResult,
|
|
594
|
-
createInboxList,
|
|
595
|
-
createInboxItem,
|
|
596
|
-
createAskUserQuestion,
|
|
597
|
-
createStatusUpdate,
|
|
598
|
-
createSessionList,
|
|
599
|
-
createTeamMetrics,
|
|
600
|
-
|
|
601
|
-
// Parsing
|
|
602
|
-
parseInboundMessage,
|
|
603
|
-
validateUserMessage,
|
|
604
|
-
serializeMessage,
|
|
605
|
-
};
|