@pixelbyte-software/pixcode 1.55.0 → 1.55.1

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 (171) hide show
  1. package/dist/api-automation.html +110 -0
  2. package/dist/api-docs.html +548 -0
  3. package/dist/assets/KaTeX_AMS-Regular-BQhdFMY1.woff2 +0 -0
  4. package/dist/assets/KaTeX_AMS-Regular-DMm9YOAa.woff +0 -0
  5. package/dist/assets/KaTeX_AMS-Regular-DRggAlZN.ttf +0 -0
  6. package/dist/assets/KaTeX_Caligraphic-Bold-ATXxdsX0.ttf +0 -0
  7. package/dist/assets/KaTeX_Caligraphic-Bold-BEiXGLvX.woff +0 -0
  8. package/dist/assets/KaTeX_Caligraphic-Bold-Dq_IR9rO.woff2 +0 -0
  9. package/dist/assets/KaTeX_Caligraphic-Regular-CTRA-rTL.woff +0 -0
  10. package/dist/assets/KaTeX_Caligraphic-Regular-Di6jR-x-.woff2 +0 -0
  11. package/dist/assets/KaTeX_Caligraphic-Regular-wX97UBjC.ttf +0 -0
  12. package/dist/assets/KaTeX_Fraktur-Bold-BdnERNNW.ttf +0 -0
  13. package/dist/assets/KaTeX_Fraktur-Bold-BsDP51OF.woff +0 -0
  14. package/dist/assets/KaTeX_Fraktur-Bold-CL6g_b3V.woff2 +0 -0
  15. package/dist/assets/KaTeX_Fraktur-Regular-CB_wures.ttf +0 -0
  16. package/dist/assets/KaTeX_Fraktur-Regular-CTYiF6lA.woff2 +0 -0
  17. package/dist/assets/KaTeX_Fraktur-Regular-Dxdc4cR9.woff +0 -0
  18. package/dist/assets/KaTeX_Main-Bold-Cx986IdX.woff2 +0 -0
  19. package/dist/assets/KaTeX_Main-Bold-Jm3AIy58.woff +0 -0
  20. package/dist/assets/KaTeX_Main-Bold-waoOVXN0.ttf +0 -0
  21. package/dist/assets/KaTeX_Main-BoldItalic-DxDJ3AOS.woff2 +0 -0
  22. package/dist/assets/KaTeX_Main-BoldItalic-DzxPMmG6.ttf +0 -0
  23. package/dist/assets/KaTeX_Main-BoldItalic-SpSLRI95.woff +0 -0
  24. package/dist/assets/KaTeX_Main-Italic-3WenGoN9.ttf +0 -0
  25. package/dist/assets/KaTeX_Main-Italic-BMLOBm91.woff +0 -0
  26. package/dist/assets/KaTeX_Main-Italic-NWA7e6Wa.woff2 +0 -0
  27. package/dist/assets/KaTeX_Main-Regular-B22Nviop.woff2 +0 -0
  28. package/dist/assets/KaTeX_Main-Regular-Dr94JaBh.woff +0 -0
  29. package/dist/assets/KaTeX_Main-Regular-ypZvNtVU.ttf +0 -0
  30. package/dist/assets/KaTeX_Math-BoldItalic-B3XSjfu4.ttf +0 -0
  31. package/dist/assets/KaTeX_Math-BoldItalic-CZnvNsCZ.woff2 +0 -0
  32. package/dist/assets/KaTeX_Math-BoldItalic-iY-2wyZ7.woff +0 -0
  33. package/dist/assets/KaTeX_Math-Italic-DA0__PXp.woff +0 -0
  34. package/dist/assets/KaTeX_Math-Italic-flOr_0UB.ttf +0 -0
  35. package/dist/assets/KaTeX_Math-Italic-t53AETM-.woff2 +0 -0
  36. package/dist/assets/KaTeX_SansSerif-Bold-CFMepnvq.ttf +0 -0
  37. package/dist/assets/KaTeX_SansSerif-Bold-D1sUS0GD.woff2 +0 -0
  38. package/dist/assets/KaTeX_SansSerif-Bold-DbIhKOiC.woff +0 -0
  39. package/dist/assets/KaTeX_SansSerif-Italic-C3H0VqGB.woff2 +0 -0
  40. package/dist/assets/KaTeX_SansSerif-Italic-DN2j7dab.woff +0 -0
  41. package/dist/assets/KaTeX_SansSerif-Italic-YYjJ1zSn.ttf +0 -0
  42. package/dist/assets/KaTeX_SansSerif-Regular-BNo7hRIc.ttf +0 -0
  43. package/dist/assets/KaTeX_SansSerif-Regular-CS6fqUqJ.woff +0 -0
  44. package/dist/assets/KaTeX_SansSerif-Regular-DDBCnlJ7.woff2 +0 -0
  45. package/dist/assets/KaTeX_Script-Regular-C5JkGWo-.ttf +0 -0
  46. package/dist/assets/KaTeX_Script-Regular-D3wIWfF6.woff2 +0 -0
  47. package/dist/assets/KaTeX_Script-Regular-D5yQViql.woff +0 -0
  48. package/dist/assets/KaTeX_Size1-Regular-C195tn64.woff +0 -0
  49. package/dist/assets/KaTeX_Size1-Regular-Dbsnue_I.ttf +0 -0
  50. package/dist/assets/KaTeX_Size1-Regular-mCD8mA8B.woff2 +0 -0
  51. package/dist/assets/KaTeX_Size2-Regular-B7gKUWhC.ttf +0 -0
  52. package/dist/assets/KaTeX_Size2-Regular-Dy4dx90m.woff2 +0 -0
  53. package/dist/assets/KaTeX_Size2-Regular-oD1tc_U0.woff +0 -0
  54. package/dist/assets/KaTeX_Size3-Regular-CTq5MqoE.woff +0 -0
  55. package/dist/assets/KaTeX_Size3-Regular-DgpXs0kz.ttf +0 -0
  56. package/dist/assets/KaTeX_Size4-Regular-BF-4gkZK.woff +0 -0
  57. package/dist/assets/KaTeX_Size4-Regular-DWFBv043.ttf +0 -0
  58. package/dist/assets/KaTeX_Size4-Regular-Dl5lxZxV.woff2 +0 -0
  59. package/dist/assets/KaTeX_Typewriter-Regular-C0xS9mPB.woff +0 -0
  60. package/dist/assets/KaTeX_Typewriter-Regular-CO6r4hn1.woff2 +0 -0
  61. package/dist/assets/KaTeX_Typewriter-Regular-D3Ib7_Hf.ttf +0 -0
  62. package/dist/assets/index-B-ySsQqi.js +877 -0
  63. package/dist/assets/index-CWO38aJI.css +32 -0
  64. package/dist/assets/index-ak1p_4ew.js +11 -0
  65. package/dist/assets/localMonaco-DFIbtDNp.js +1 -0
  66. package/dist/assets/vendor-codemirror-CIYNS698.js +41 -0
  67. package/dist/assets/vendor-react-DB6V5Fl1.js +59 -0
  68. package/dist/assets/vendor-xterm-C7tpxJl7.js +9 -0
  69. package/dist/clear-cache.html +85 -0
  70. package/dist/convert-icons.md +53 -0
  71. package/dist/docs.html +308 -0
  72. package/dist/favicon.png +0 -0
  73. package/dist/favicon.svg +8 -0
  74. package/dist/features.html +133 -0
  75. package/dist/generate-icons.js +49 -0
  76. package/dist/humans.txt +15 -0
  77. package/dist/icons/claude-ai-icon.svg +1 -0
  78. package/dist/icons/codex-white.svg +3 -0
  79. package/dist/icons/codex.svg +3 -0
  80. package/dist/icons/cursor-white.svg +12 -0
  81. package/dist/icons/cursor.svg +1 -0
  82. package/dist/icons/gemini-ai-icon.svg +1 -0
  83. package/dist/icons/icon-128x128.png +0 -0
  84. package/dist/icons/icon-128x128.svg +9 -0
  85. package/dist/icons/icon-144x144.png +0 -0
  86. package/dist/icons/icon-144x144.svg +9 -0
  87. package/dist/icons/icon-152x152.png +0 -0
  88. package/dist/icons/icon-152x152.svg +9 -0
  89. package/dist/icons/icon-192x192.png +0 -0
  90. package/dist/icons/icon-192x192.svg +9 -0
  91. package/dist/icons/icon-384x384.png +0 -0
  92. package/dist/icons/icon-384x384.svg +9 -0
  93. package/dist/icons/icon-512x512.png +0 -0
  94. package/dist/icons/icon-512x512.svg +9 -0
  95. package/dist/icons/icon-72x72.png +0 -0
  96. package/dist/icons/icon-72x72.svg +9 -0
  97. package/dist/icons/icon-96x96.png +0 -0
  98. package/dist/icons/icon-96x96.svg +9 -0
  99. package/dist/icons/icon-template.svg +9 -0
  100. package/dist/icons/opencode-logo-dark.svg +1 -0
  101. package/dist/icons/opencode-logo-light.svg +1 -0
  102. package/dist/icons/qwen-ai-icon.png +0 -0
  103. package/dist/icons/qwen-logo.svg +15 -0
  104. package/dist/index.html +62 -0
  105. package/dist/landing.html +268 -0
  106. package/dist/llms-full.txt +119 -0
  107. package/dist/llms.txt +53 -0
  108. package/dist/logo-128.png +0 -0
  109. package/dist/logo-256.png +0 -0
  110. package/dist/logo-32.png +0 -0
  111. package/dist/logo-512.png +0 -0
  112. package/dist/logo-64.png +0 -0
  113. package/dist/logo.png +0 -0
  114. package/dist/logo.svg +12 -0
  115. package/dist/manifest.json +61 -0
  116. package/dist/openapi.yaml +1696 -0
  117. package/dist/orchestration.html +125 -0
  118. package/dist/robots.txt +4 -0
  119. package/dist/screenshots/cli-selection.png +0 -0
  120. package/dist/screenshots/desktop-main.png +0 -0
  121. package/dist/screenshots/mobile-chat.png +0 -0
  122. package/dist/screenshots/tools-modal.png +0 -0
  123. package/dist/site.css +692 -0
  124. package/dist/sitemap.xml +51 -0
  125. package/dist/sw.js +132 -0
  126. package/package.json +1 -1
  127. package/dist-server/server/modules/tasks/git-worktree.js +0 -98
  128. package/dist-server/server/modules/tasks/git-worktree.js.map +0 -1
  129. package/dist-server/server/modules/tasks/index.js +0 -8
  130. package/dist-server/server/modules/tasks/index.js.map +0 -1
  131. package/dist-server/server/modules/tasks/prompt-builder.js +0 -85
  132. package/dist-server/server/modules/tasks/prompt-builder.js.map +0 -1
  133. package/dist-server/server/modules/tasks/role-presets.js +0 -94
  134. package/dist-server/server/modules/tasks/role-presets.js.map +0 -1
  135. package/dist-server/server/modules/tasks/runners/claude-runner.js +0 -109
  136. package/dist-server/server/modules/tasks/runners/claude-runner.js.map +0 -1
  137. package/dist-server/server/modules/tasks/runners/codex-runner.js +0 -67
  138. package/dist-server/server/modules/tasks/runners/codex-runner.js.map +0 -1
  139. package/dist-server/server/modules/tasks/runners/spawn-runner.js +0 -111
  140. package/dist-server/server/modules/tasks/runners/spawn-runner.js.map +0 -1
  141. package/dist-server/server/modules/tasks/runners/types.js +0 -5
  142. package/dist-server/server/modules/tasks/runners/types.js.map +0 -1
  143. package/dist-server/server/modules/tasks/scheduler.js +0 -69
  144. package/dist-server/server/modules/tasks/scheduler.js.map +0 -1
  145. package/dist-server/server/modules/tasks/task-queue.js +0 -81
  146. package/dist-server/server/modules/tasks/task-queue.js.map +0 -1
  147. package/dist-server/server/modules/tasks/task-routes.js +0 -195
  148. package/dist-server/server/modules/tasks/task-routes.js.map +0 -1
  149. package/dist-server/server/modules/tasks/task-runner.js +0 -187
  150. package/dist-server/server/modules/tasks/task-runner.js.map +0 -1
  151. package/dist-server/server/modules/tasks/task-store.js +0 -196
  152. package/dist-server/server/modules/tasks/task-store.js.map +0 -1
  153. package/dist-server/server/modules/tasks/task-types.js +0 -5
  154. package/dist-server/server/modules/tasks/task-types.js.map +0 -1
  155. package/dist-server/server/modules/tasks/user-interaction.js +0 -73
  156. package/dist-server/server/modules/tasks/user-interaction.js.map +0 -1
  157. package/server/modules/tasks/git-worktree.ts +0 -102
  158. package/server/modules/tasks/index.ts +0 -9
  159. package/server/modules/tasks/prompt-builder.ts +0 -98
  160. package/server/modules/tasks/role-presets.ts +0 -113
  161. package/server/modules/tasks/runners/claude-runner.ts +0 -120
  162. package/server/modules/tasks/runners/codex-runner.ts +0 -80
  163. package/server/modules/tasks/runners/spawn-runner.ts +0 -122
  164. package/server/modules/tasks/runners/types.ts +0 -25
  165. package/server/modules/tasks/scheduler.ts +0 -75
  166. package/server/modules/tasks/task-queue.ts +0 -91
  167. package/server/modules/tasks/task-routes.ts +0 -245
  168. package/server/modules/tasks/task-runner.ts +0 -219
  169. package/server/modules/tasks/task-store.ts +0 -223
  170. package/server/modules/tasks/task-types.ts +0 -100
  171. package/server/modules/tasks/user-interaction.ts +0 -93
@@ -1,91 +0,0 @@
1
- // ============================================================
2
- // Task Queue — Manages task dependencies and concurrency
3
- // ============================================================
4
-
5
- import { getTask, updateTask, getTasksByStatus, getPredecessor } from './task-store.js';
6
- import { taskEvents } from './task-runner.js';
7
- import type { Task, TaskStatus } from './task-types.js';
8
-
9
- const TERMINAL_STATUSES: TaskStatus[] = ['COMPLETED', 'FAILED', 'CANCELLED'];
10
-
11
- // Default concurrency: 3 concurrent tasks
12
- let MAX_CONCURRENT = parseInt(process.env.PIXCODE_MAX_CONCURRENT_TASKS || '3', 10);
13
-
14
- export function setMaxConcurrent(n: number): void {
15
- MAX_CONCURRENT = Math.max(1, n);
16
- }
17
-
18
- export function getMaxConcurrent(): number {
19
- return MAX_CONCURRENT;
20
- }
21
-
22
- /**
23
- * Enqueue a task — checks predecessor, transitions to QUEUED if ready.
24
- */
25
- export async function enqueue(taskId: string): Promise<void> {
26
- const task = getTask(taskId);
27
- if (!task) throw new Error(`Task ${taskId} not found`);
28
-
29
- // Check predecessor
30
- if (task.predecessorTaskId) {
31
- const predecessor = getPredecessor(task);
32
- if (predecessor && !TERMINAL_STATUSES.includes(predecessor.status)) {
33
- // Predecessor still running — task stays PENDING
34
- return;
35
- }
36
- if (predecessor && predecessor.status !== 'COMPLETED') {
37
- // Predecessor failed or cancelled — cancel this task too
38
- updateTask(taskId, {
39
- status: 'CANCELLED',
40
- result: `Predecessor task "${predecessor.title}" is ${predecessor.status}`,
41
- });
42
- taskEvents.emit('task:status', { taskId, status: 'CANCELLED' });
43
- return;
44
- }
45
- // Predecessor completed — continue session if requested
46
- if (predecessor && task.continueSession && predecessor.sessionId) {
47
- updateTask(taskId, { sessionId: predecessor.sessionId });
48
- }
49
- }
50
-
51
- // Ready to queue
52
- updateTask(taskId, { status: 'QUEUED' });
53
- taskEvents.emit('task:status', { taskId, status: 'QUEUED' });
54
- }
55
-
56
- /**
57
- * Get tasks that are ready to run (QUEUED + within concurrency limit).
58
- */
59
- export function getTasksToRun(): Task[] {
60
- const runningCount = getTasksByStatus('RUNNING').length +
61
- getTasksByStatus('AWAITING_INPUT').length;
62
-
63
- if (runningCount >= MAX_CONCURRENT) return [];
64
-
65
- const queued = getTasksByStatus('QUEUED');
66
- const slotsAvailable = MAX_CONCURRENT - runningCount;
67
-
68
- // Sort by priority then creation time
69
- const priorityOrder: Record<string, number> = { urgent: 0, high: 1, normal: 2, low: 3 };
70
- return queued
71
- .sort((a, b) => {
72
- const pDiff = (priorityOrder[a.priority] || 2) - (priorityOrder[b.priority] || 2);
73
- if (pDiff !== 0) return pDiff;
74
- return new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime();
75
- })
76
- .slice(0, slotsAvailable);
77
- }
78
-
79
- /**
80
- * Called when a task terminates — check if dependent tasks can proceed.
81
- */
82
- export async function onTaskTerminated(taskId: string): Promise<void> {
83
- // Find tasks that have this task as predecessor
84
- // We need to scan all PENDING tasks
85
- const pending = getTasksByStatus('PENDING');
86
- for (const p of pending) {
87
- if (p.predecessorTaskId === taskId) {
88
- await enqueue(p.id);
89
- }
90
- }
91
- }
@@ -1,245 +0,0 @@
1
- // ============================================================
2
- // Task Routes — Express API endpoints for task management
3
- // ============================================================
4
-
5
- import type { Router, Request, Response } from 'express';
6
- import express from 'express';
7
-
8
- import {
9
- createTask,
10
- getTask,
11
- getTasksByProject,
12
- getAllTasks,
13
- updateTask,
14
- deleteTask,
15
- getLogs,
16
- getPendingInteractions,
17
- addLog,
18
- } from './task-store.js';
19
- import { enqueue } from './task-queue.js';
20
- import { cancelTask, taskEvents } from './task-runner.js';
21
- import { submitAnswer } from './user-interaction.js';
22
- import { getMaxConcurrent, setMaxConcurrent } from './task-queue.js';
23
- import { listRoles } from './role-presets.js';
24
- import type { CreateTaskInput, AgentType, TaskRole, TaskPriority } from './task-types.js';
25
-
26
- export function taskRouter(): Router {
27
- const router = express.Router();
28
-
29
- // ============================================================
30
- // GET /api/tasks — List all tasks
31
- // ============================================================
32
- router.get('/', (req: Request, res: Response) => {
33
- const limit = parseInt(String(req.query.limit)) || 100;
34
- const projectId = String(req.query.projectId);
35
- const tasks = projectId ? getTasksByProject(projectId) : getAllTasks(limit);
36
- res.json({ tasks });
37
- });
38
-
39
- // ============================================================
40
- // GET /api/tasks/:id — Get a single task
41
- // ============================================================
42
- router.get('/:id', (req: Request, res: Response) => {
43
- const task = getTask(String(req.params.id));
44
- if (!task) {
45
- res.status(404).json({ error: 'Task not found' });
46
- return;
47
- }
48
- res.json({ task });
49
- });
50
-
51
- // ============================================================
52
- // POST /api/tasks — Create a new task
53
- // ============================================================
54
- router.post('/', async (req: Request, res: Response) => {
55
- try {
56
- const {
57
- projectId,
58
- title,
59
- prompt,
60
- agentType,
61
- model,
62
- role,
63
- priority,
64
- predecessorTaskId,
65
- continueSession,
66
- maxBudgetUsd,
67
- interactionTimeout,
68
- thinkingEnabled,
69
- permissionMode,
70
- } = req.body;
71
-
72
- if (!projectId || !title || !prompt || !agentType) {
73
- res.status(400).json({
74
- error: 'Missing required fields: projectId, title, prompt, agentType',
75
- });
76
- return;
77
- }
78
-
79
- const validAgents: AgentType[] = ['claude-code', 'codex', 'gemini', 'qwen', 'opencode'];
80
- if (!validAgents.includes(agentType)) {
81
- res.status(400).json({ error: `Invalid agentType. Valid: ${validAgents.join(', ')}` });
82
- return;
83
- }
84
-
85
- const input: CreateTaskInput = {
86
- projectId,
87
- title,
88
- prompt,
89
- agentType,
90
- model,
91
- role: role as TaskRole,
92
- priority: priority as TaskPriority,
93
- predecessorTaskId,
94
- continueSession,
95
- maxBudgetUsd,
96
- interactionTimeout,
97
- thinkingEnabled,
98
- permissionMode,
99
- };
100
-
101
- const task = createTask(input);
102
- await enqueue(task.id);
103
- taskEvents.emit('task:enqueued', task.id);
104
-
105
- res.status(201).json({ task });
106
- } catch (err: any) {
107
- res.status(500).json({ error: err.message });
108
- }
109
- });
110
-
111
- // ============================================================
112
- // POST /api/tasks/:id/cancel — Cancel a task
113
- // ============================================================
114
- router.post('/:id/cancel', async (req: Request, res: Response) => {
115
- const success = await cancelTask(String(req.params.id));
116
- if (!success) {
117
- res.status(404).json({ error: 'Task not found' });
118
- return;
119
- }
120
- res.json({ success: true });
121
- });
122
-
123
- // ============================================================
124
- // DELETE /api/tasks/:id — Delete a task
125
- // ============================================================
126
- router.delete('/:id', (req: Request, res: Response) => {
127
- const success = deleteTask(String(req.params.id));
128
- if (!success) {
129
- res.status(404).json({ error: 'Task not found' });
130
- return;
131
- }
132
- res.json({ success: true });
133
- });
134
-
135
- // ============================================================
136
- // GET /api/tasks/:id/logs — Get task logs
137
- // ============================================================
138
- router.get('/:id/logs', (req: Request, res: Response) => {
139
- const limit = parseInt(String(req.query.limit)) || 200;
140
- const logs = getLogs(String(req.params.id), limit);
141
- res.json({ logs });
142
- });
143
-
144
- // ============================================================
145
- // GET /api/tasks/:id/interactions — Get pending interactions
146
- // ============================================================
147
- router.get('/:id/interactions', (req: Request, res: Response) => {
148
- const interactions = getPendingInteractions(String(req.params.id));
149
- res.json({ interactions });
150
- });
151
-
152
- // ============================================================
153
- // POST /api/tasks/interactions/:interactionId/answer — Answer a question
154
- // ============================================================
155
- router.post('/interactions/:interactionId/answer', (req: Request, res: Response) => {
156
- const { answer } = req.body;
157
- if (!answer) {
158
- res.status(400).json({ error: 'Missing required field: answer' });
159
- return;
160
- }
161
- const success = submitAnswer(String(req.params.interactionId), answer);
162
- if (!success) {
163
- res.status(404).json({ error: 'Interaction not found or already answered' });
164
- return;
165
- }
166
- res.json({ success: true });
167
- });
168
-
169
- // ============================================================
170
- // GET /api/tasks/meta/roles — List available roles
171
- // ============================================================
172
- router.get('/meta/roles', (req: Request, res: Response) => {
173
- res.json({ roles: listRoles() });
174
- });
175
-
176
- // ============================================================
177
- // GET /api/tasks/meta/agents — List available agents
178
- // ============================================================
179
- router.get('/meta/agents', (req: Request, res: Response) => {
180
- res.json({
181
- agents: [
182
- { value: 'claude-code', label: 'Claude Code', provider: 'anthropic' },
183
- { value: 'codex', label: 'Codex CLI', provider: 'openai' },
184
- { value: 'gemini', label: 'Gemini CLI', provider: 'google' },
185
- { value: 'qwen', label: 'Qwen Code', provider: 'alibaba' },
186
- { value: 'opencode', label: 'OpenCode', provider: 'anomaly' },
187
- ],
188
- });
189
- });
190
-
191
- // ============================================================
192
- // GET /api/tasks/meta/config — Get task system config
193
- // ============================================================
194
- router.get('/meta/config', (req: Request, res: Response) => {
195
- res.json({
196
- maxConcurrent: getMaxConcurrent(),
197
- });
198
- });
199
-
200
- // ============================================================
201
- // POST /api/tasks/meta/config — Set task system config
202
- // ============================================================
203
- router.post('/meta/config', (req: Request, res: Response) => {
204
- const { maxConcurrent } = req.body;
205
- if (typeof maxConcurrent === 'number' && maxConcurrent > 0) {
206
- setMaxConcurrent(maxConcurrent);
207
- }
208
- res.json({ maxConcurrent: getMaxConcurrent() });
209
- });
210
-
211
- // ============================================================
212
- // WebSocket event stream (SSE) — /api/tasks/events
213
- // ============================================================
214
- router.get('/events', (req: Request, res: Response) => {
215
- res.writeHead(200, {
216
- 'Content-Type': 'text/event-stream',
217
- 'Cache-Control': 'no-cache',
218
- Connection: 'keep-alive',
219
- });
220
-
221
- const send = (data: any) => {
222
- res.write(`data: ${JSON.stringify(data)}\n\n`);
223
- };
224
-
225
- const handlers: Record<string, (data: any) => void> = {
226
- 'task:status': (data) => send({ type: 'task:status', ...data }),
227
- 'task:log': (data) => send({ type: 'task:log', ...data }),
228
- 'task:completed': (data) => send({ type: 'task:completed', ...data }),
229
- 'task:failed': (data) => send({ type: 'task:failed', ...data }),
230
- 'task:cancelled': (data) => send({ type: 'task:cancelled', ...data }),
231
- };
232
-
233
- for (const [event, handler] of Object.entries(handlers)) {
234
- taskEvents.on(event, handler);
235
- }
236
-
237
- req.on('close', () => {
238
- for (const [event, handler] of Object.entries(handlers)) {
239
- taskEvents.off(event, handler);
240
- }
241
- });
242
- });
243
-
244
- return router;
245
- }
@@ -1,219 +0,0 @@
1
- // ============================================================
2
- // Task Runner — Dispatches tasks to the right agent runner
3
- // ============================================================
4
-
5
- import { updateTask, addLog, getTask } from './task-store.js';
6
- import { createWorktree, removeWorktree, getChangedFiles } from './git-worktree.js';
7
- import { askUser, cancelTaskInteractions } from './user-interaction.js';
8
- import { buildSummaryPrompt } from './prompt-builder.js';
9
- import { claudeRunner } from './runners/claude-runner.js';
10
- import { codexRunner } from './runners/codex-runner.js';
11
- import { createSpawnRunner } from './runners/spawn-runner.js';
12
- import type { Task, AgentType } from './task-types.js';
13
- import type { AgentRunner, RunContext } from './runners/types.js';
14
-
15
- // Runner registry
16
- const runners: Partial<Record<AgentType, AgentRunner>> = {
17
- 'claude-code': claudeRunner,
18
- 'codex': codexRunner,
19
- 'gemini': createSpawnRunner('gemini'),
20
- 'qwen': createSpawnRunner('qwen'),
21
- 'opencode': createSpawnRunner('opencode'),
22
- };
23
-
24
- // Track running tasks for cancellation
25
- const runningTasks = new Map<string, AbortController>();
26
-
27
- export function getAbortController(taskId: string): AbortController | undefined {
28
- return runningTasks.get(taskId);
29
- }
30
-
31
- // Event emitter for WebSocket updates
32
- import { EventEmitter } from 'node:events';
33
- export const taskEvents = new EventEmitter();
34
-
35
- // ============================================================
36
- // Resolve project path from projectId
37
- // ============================================================
38
-
39
- export async function resolveProjectPath(projectId: string): Promise<string> {
40
- // Try to import pixcode's project service
41
- try {
42
- const { getProjects } = await import('../../projects.js');
43
- const projects = await getProjects();
44
- const project = projects.find((p: any) => p.name === projectId || p.id === projectId);
45
- if (project) {
46
- return project.fullPath || project.path || projectId;
47
- }
48
- } catch {
49
- // Fall through to treating projectId as a path
50
- }
51
- return projectId;
52
- }
53
-
54
- // ============================================================
55
- // Generate summary using Claude SDK
56
- // ============================================================
57
-
58
- async function generateSummary(task: Task, projectPath: string): Promise<string> {
59
- try {
60
- const { query } = await import('@anthropic-ai/claude-agent-sdk');
61
- const summaryPrompt = buildSummaryPrompt(task);
62
-
63
- const response = await query({
64
- prompt: summaryPrompt,
65
- options: {
66
- cwd: task.worktreePath || projectPath,
67
- maxTurns: 3,
68
- model: 'claude-sonnet-4-20250514',
69
- permissionMode: 'plan' as any,
70
- },
71
- });
72
-
73
- let summary = '';
74
- for await (const message of response) {
75
- if (message.type === 'result' && message.subtype === 'success') {
76
- const success = message as any;
77
- summary = success.result || '';
78
- }
79
- }
80
- return summary.slice(0, 2000);
81
- } catch {
82
- // Fallback: simple summary
83
- return `Task "${task.title}" completed with ${task.agentType}.`;
84
- }
85
- }
86
-
87
- // ============================================================
88
- // Run a single task
89
- // ============================================================
90
-
91
- export async function runTask(task: Task, projectPath: string): Promise<void> {
92
- const abortController = new AbortController();
93
- runningTasks.set(task.id, abortController);
94
-
95
- const logTask = (level: 'info' | 'warn' | 'error' | 'debug', message: string) => {
96
- addLog(task.id, level, message);
97
- taskEvents.emit('task:log', { taskId: task.id, level, message });
98
- };
99
-
100
- const broadcastStatus = (status: string) => {
101
- taskEvents.emit('task:status', { taskId: task.id, status });
102
- };
103
-
104
- try {
105
- // Update status to RUNNING
106
- updateTask(task.id, {
107
- status: 'RUNNING',
108
- startedAt: new Date().toISOString(),
109
- });
110
- broadcastStatus('RUNNING');
111
-
112
- // Create git worktree for isolation
113
- let worktreePath: string | undefined;
114
- let branchName: string | undefined;
115
- try {
116
- const wt = createWorktree(task, projectPath);
117
- worktreePath = wt.worktreePath;
118
- branchName = wt.branchName;
119
- updateTask(task.id, { worktreePath, branchName });
120
- } catch (err: any) {
121
- logTask('warn', `Could not create worktree: ${err.message}. Running in main directory.`);
122
- }
123
-
124
- // Get the right runner
125
- const runner = runners[task.agentType];
126
- if (!runner) {
127
- throw new Error(`No runner registered for agent type: ${task.agentType}`);
128
- }
129
-
130
- // Build context
131
- const ctx: RunContext = {
132
- task: { ...task, worktreePath, branchName },
133
- projectPath,
134
- abortController,
135
- logTask,
136
- broadcastStatus,
137
- askUser: (question: string, options?: string[]) =>
138
- askUser(task.id, question, options, task.interactionTimeout),
139
- };
140
-
141
- // Run the agent
142
- const { result, costUsd, tokenCount, sessionId } = await runner.run(ctx);
143
-
144
- // Get changed files
145
- const changedFiles = getChangedFiles({ ...task, worktreePath }, projectPath);
146
-
147
- // Generate summary
148
- logTask('info', 'Generating task summary...');
149
- const summary = await generateSummary({ ...task, worktreePath }, projectPath);
150
-
151
- // Update task with results
152
- updateTask(task.id, {
153
- status: 'COMPLETED',
154
- result: result || 'Completed',
155
- summary,
156
- costUsd: costUsd || 0,
157
- tokenCount: tokenCount || { input: 0, output: 0 },
158
- sessionId,
159
- changedFiles,
160
- completedAt: new Date().toISOString(),
161
- });
162
- broadcastStatus('COMPLETED');
163
-
164
- logTask('info', `Task completed. Cost: $${(costUsd || 0).toFixed(4)}, Files changed: ${changedFiles.length}`);
165
-
166
- taskEvents.emit('task:completed', {
167
- taskId: task.id,
168
- summary,
169
- costUsd: costUsd || 0,
170
- changedFiles,
171
- });
172
-
173
- // Clean up worktree (optional — keep for review)
174
- // removeWorktree(updatedTask, projectPath);
175
-
176
- } catch (err: any) {
177
- logTask('error', `Task failed: ${err.message}`);
178
-
179
- updateTask(task.id, {
180
- status: 'FAILED',
181
- result: err.message,
182
- completedAt: new Date().toISOString(),
183
- });
184
- broadcastStatus('FAILED');
185
-
186
- taskEvents.emit('task:failed', { taskId: task.id, error: err.message });
187
- } finally {
188
- runningTasks.delete(task.id);
189
- }
190
- }
191
-
192
- // ============================================================
193
- // Cancel a running task
194
- // ============================================================
195
-
196
- export async function cancelTask(taskId: string): Promise<boolean> {
197
- const task = getTask(taskId);
198
- if (!task) return false;
199
-
200
- // Abort the running process
201
- const abortController = runningTasks.get(taskId);
202
- if (abortController) {
203
- abortController.abort();
204
- }
205
-
206
- // Cancel pending interactions
207
- cancelTaskInteractions(taskId);
208
-
209
- // Update status
210
- updateTask(taskId, {
211
- status: 'CANCELLED',
212
- completedAt: new Date().toISOString(),
213
- });
214
-
215
- taskEvents.emit('task:status', { taskId, status: 'CANCELLED' });
216
- taskEvents.emit('task:cancelled', { taskId });
217
-
218
- return true;
219
- }