@pixelbyte-software/pixcode 1.34.0 → 1.35.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 (155) hide show
  1. package/dist/api-docs.html +162 -9
  2. package/dist/assets/index-B8w57E1r.css +32 -0
  3. package/dist/assets/index-Djuh0wHV.js +854 -0
  4. package/dist/favicon.svg +8 -8
  5. package/dist/icons/icon-128x128.svg +9 -9
  6. package/dist/icons/icon-144x144.svg +9 -9
  7. package/dist/icons/icon-152x152.svg +9 -9
  8. package/dist/icons/icon-192x192.svg +9 -9
  9. package/dist/icons/icon-384x384.svg +9 -9
  10. package/dist/icons/icon-512x512.svg +9 -9
  11. package/dist/icons/icon-72x72.svg +9 -9
  12. package/dist/icons/icon-96x96.svg +9 -9
  13. package/dist/icons/icon-template.svg +9 -9
  14. package/dist/index.html +2 -2
  15. package/dist/logo.svg +12 -12
  16. package/dist/openapi.yaml +383 -1
  17. package/dist-server/server/claude-sdk.js +38 -7
  18. package/dist-server/server/claude-sdk.js.map +1 -1
  19. package/dist-server/server/cli.js +12 -17
  20. package/dist-server/server/cli.js.map +1 -1
  21. package/dist-server/server/daemon-manager.js +98 -51
  22. package/dist-server/server/daemon-manager.js.map +1 -1
  23. package/dist-server/server/database/json-store.js +8 -5
  24. package/dist-server/server/database/json-store.js.map +1 -1
  25. package/dist-server/server/index.js +31 -10
  26. package/dist-server/server/index.js.map +1 -1
  27. package/dist-server/server/modules/orchestration/a2a/adapter-registry.js +45 -19
  28. package/dist-server/server/modules/orchestration/a2a/adapter-registry.js.map +1 -1
  29. package/dist-server/server/modules/orchestration/a2a/adapters/abstract-a2a.adapter.js.map +1 -1
  30. package/dist-server/server/modules/orchestration/a2a/adapters/claude-code.adapter.js +1 -0
  31. package/dist-server/server/modules/orchestration/a2a/adapters/claude-code.adapter.js.map +1 -1
  32. package/dist-server/server/modules/orchestration/a2a/adapters/codex.adapter.js +202 -0
  33. package/dist-server/server/modules/orchestration/a2a/adapters/codex.adapter.js.map +1 -0
  34. package/dist-server/server/modules/orchestration/a2a/adapters/cursor.adapter.js +205 -0
  35. package/dist-server/server/modules/orchestration/a2a/adapters/cursor.adapter.js.map +1 -0
  36. package/dist-server/server/modules/orchestration/a2a/adapters/gemini.adapter.js +205 -0
  37. package/dist-server/server/modules/orchestration/a2a/adapters/gemini.adapter.js.map +1 -0
  38. package/dist-server/server/modules/orchestration/a2a/adapters/opencode.adapter.js +205 -0
  39. package/dist-server/server/modules/orchestration/a2a/adapters/opencode.adapter.js.map +1 -0
  40. package/dist-server/server/modules/orchestration/a2a/adapters/qwen.adapter.js +205 -0
  41. package/dist-server/server/modules/orchestration/a2a/adapters/qwen.adapter.js.map +1 -0
  42. package/dist-server/server/modules/orchestration/a2a/routes.js +298 -34
  43. package/dist-server/server/modules/orchestration/a2a/routes.js.map +1 -1
  44. package/dist-server/server/modules/orchestration/a2a/task-store.js +144 -0
  45. package/dist-server/server/modules/orchestration/a2a/task-store.js.map +1 -0
  46. package/dist-server/server/modules/orchestration/a2a/validator.js +16 -0
  47. package/dist-server/server/modules/orchestration/a2a/validator.js.map +1 -1
  48. package/dist-server/server/modules/orchestration/index.js +14 -0
  49. package/dist-server/server/modules/orchestration/index.js.map +1 -1
  50. package/dist-server/server/modules/orchestration/preview/port-watcher.js +90 -0
  51. package/dist-server/server/modules/orchestration/preview/port-watcher.js.map +1 -0
  52. package/dist-server/server/modules/orchestration/preview/preview-proxy.js +58 -0
  53. package/dist-server/server/modules/orchestration/preview/preview-proxy.js.map +1 -0
  54. package/dist-server/server/modules/orchestration/preview/types.js +2 -0
  55. package/dist-server/server/modules/orchestration/preview/types.js.map +1 -0
  56. package/dist-server/server/modules/orchestration/tasks/orchestration-task-store.js +37 -0
  57. package/dist-server/server/modules/orchestration/tasks/orchestration-task-store.js.map +1 -0
  58. package/dist-server/server/modules/orchestration/tasks/orchestration-task.routes.js +68 -0
  59. package/dist-server/server/modules/orchestration/tasks/orchestration-task.routes.js.map +1 -0
  60. package/dist-server/server/modules/orchestration/tasks/orchestration-task.service.js +128 -0
  61. package/dist-server/server/modules/orchestration/tasks/orchestration-task.service.js.map +1 -0
  62. package/dist-server/server/modules/orchestration/tasks/orchestration-task.types.js +2 -0
  63. package/dist-server/server/modules/orchestration/tasks/orchestration-task.types.js.map +1 -0
  64. package/dist-server/server/modules/orchestration/workflows/built-in-workflows.js +126 -0
  65. package/dist-server/server/modules/orchestration/workflows/built-in-workflows.js.map +1 -0
  66. package/dist-server/server/modules/orchestration/workflows/workflow-runner.js +1047 -0
  67. package/dist-server/server/modules/orchestration/workflows/workflow-runner.js.map +1 -0
  68. package/dist-server/server/modules/orchestration/workflows/workflow-store.js +76 -0
  69. package/dist-server/server/modules/orchestration/workflows/workflow-store.js.map +1 -0
  70. package/dist-server/server/modules/orchestration/workflows/workflow.routes.js +151 -0
  71. package/dist-server/server/modules/orchestration/workflows/workflow.routes.js.map +1 -0
  72. package/dist-server/server/modules/orchestration/workflows/workflow.types.js +2 -0
  73. package/dist-server/server/modules/orchestration/workflows/workflow.types.js.map +1 -0
  74. package/dist-server/server/modules/orchestration/workflows/workspace-target.js +98 -0
  75. package/dist-server/server/modules/orchestration/workflows/workspace-target.js.map +1 -0
  76. package/dist-server/server/modules/orchestration/workspace/docker-workspace.js +122 -0
  77. package/dist-server/server/modules/orchestration/workspace/docker-workspace.js.map +1 -0
  78. package/dist-server/server/modules/orchestration/workspace/path-safety.js +48 -0
  79. package/dist-server/server/modules/orchestration/workspace/path-safety.js.map +1 -0
  80. package/dist-server/server/modules/orchestration/workspace/types.js +11 -0
  81. package/dist-server/server/modules/orchestration/workspace/types.js.map +1 -0
  82. package/dist-server/server/modules/orchestration/workspace/workspace-manager.js +80 -0
  83. package/dist-server/server/modules/orchestration/workspace/workspace-manager.js.map +1 -0
  84. package/dist-server/server/modules/orchestration/workspace/worktree-workspace.js +96 -0
  85. package/dist-server/server/modules/orchestration/workspace/worktree-workspace.js.map +1 -0
  86. package/dist-server/server/modules/providers/index.js +3 -0
  87. package/dist-server/server/modules/providers/index.js.map +1 -0
  88. package/dist-server/server/openai-codex.js +35 -4
  89. package/dist-server/server/openai-codex.js.map +1 -1
  90. package/dist-server/server/routes/taskmaster.js +106 -89
  91. package/dist-server/server/routes/taskmaster.js.map +1 -1
  92. package/package.json +3 -1
  93. package/scripts/smoke/a2a-roundtrip.mjs +167 -98
  94. package/scripts/smoke/orchestration-api.mjs +172 -0
  95. package/scripts/smoke/orchestration-live-run.mjs +176 -0
  96. package/server/claude-sdk.js +48 -7
  97. package/server/cli.js +12 -17
  98. package/server/daemon-manager.js +90 -51
  99. package/server/database/db.js +794 -794
  100. package/server/database/json-store.js +8 -5
  101. package/server/index.js +40 -9
  102. package/server/modules/orchestration/a2a/adapter-registry.ts +108 -58
  103. package/server/modules/orchestration/a2a/adapters/abstract-a2a.adapter.ts +55 -49
  104. package/server/modules/orchestration/a2a/adapters/claude-code.adapter.ts +284 -283
  105. package/server/modules/orchestration/a2a/adapters/codex.adapter.ts +244 -0
  106. package/server/modules/orchestration/a2a/adapters/cursor.adapter.ts +249 -0
  107. package/server/modules/orchestration/a2a/adapters/gemini.adapter.ts +248 -0
  108. package/server/modules/orchestration/a2a/adapters/opencode.adapter.ts +248 -0
  109. package/server/modules/orchestration/a2a/adapters/qwen.adapter.ts +248 -0
  110. package/server/modules/orchestration/a2a/agent-card.ts +55 -55
  111. package/server/modules/orchestration/a2a/auth.middleware.ts +29 -29
  112. package/server/modules/orchestration/a2a/bus.ts +46 -46
  113. package/server/modules/orchestration/a2a/routes.ts +577 -264
  114. package/server/modules/orchestration/a2a/task-store.ts +178 -0
  115. package/server/modules/orchestration/a2a/types.ts +125 -111
  116. package/server/modules/orchestration/a2a/validator.ts +113 -90
  117. package/server/modules/orchestration/index.ts +66 -26
  118. package/server/modules/orchestration/preview/port-watcher.ts +112 -0
  119. package/server/modules/orchestration/preview/preview-proxy.ts +60 -0
  120. package/server/modules/orchestration/preview/types.ts +19 -0
  121. package/server/modules/orchestration/tasks/orchestration-task-store.ts +45 -0
  122. package/server/modules/orchestration/tasks/orchestration-task.routes.ts +73 -0
  123. package/server/modules/orchestration/tasks/orchestration-task.service.ts +145 -0
  124. package/server/modules/orchestration/tasks/orchestration-task.types.ts +29 -0
  125. package/server/modules/orchestration/workflows/built-in-workflows.ts +127 -0
  126. package/server/modules/orchestration/workflows/workflow-runner.ts +1206 -0
  127. package/server/modules/orchestration/workflows/workflow-store.ts +97 -0
  128. package/server/modules/orchestration/workflows/workflow.routes.ts +169 -0
  129. package/server/modules/orchestration/workflows/workflow.types.ts +70 -0
  130. package/server/modules/orchestration/workflows/workspace-target.ts +120 -0
  131. package/server/modules/orchestration/workspace/docker-workspace.ts +135 -0
  132. package/server/modules/orchestration/workspace/path-safety.ts +55 -0
  133. package/server/modules/orchestration/workspace/types.ts +52 -0
  134. package/server/modules/orchestration/workspace/workspace-manager.ts +97 -0
  135. package/server/modules/orchestration/workspace/worktree-workspace.ts +125 -0
  136. package/server/modules/providers/index.ts +2 -0
  137. package/server/modules/providers/list/opencode/opencode-auth.provider.ts +130 -130
  138. package/server/modules/providers/list/opencode/opencode-mcp.provider.ts +126 -126
  139. package/server/modules/providers/list/opencode/opencode.provider.ts +29 -29
  140. package/server/modules/providers/list/qwen/qwen-auth.provider.ts +145 -145
  141. package/server/modules/providers/list/qwen/qwen-mcp.provider.ts +114 -114
  142. package/server/modules/providers/list/qwen/qwen.provider.ts +21 -21
  143. package/server/modules/providers/shared/provider-configs.ts +142 -142
  144. package/server/openai-codex.js +40 -4
  145. package/server/qwen-code-cli.js +395 -395
  146. package/server/qwen-response-handler.js +73 -73
  147. package/server/routes/qwen.js +27 -27
  148. package/server/routes/taskmaster.js +116 -91
  149. package/server/services/external-access.js +171 -171
  150. package/server/services/provider-models.js +381 -381
  151. package/server/services/telegram/telegram-http-client.js +130 -130
  152. package/server/services/vapid-keys.js +36 -36
  153. package/server/utils/port-access.js +209 -209
  154. package/dist/assets/index-B1ghfb4w.css +0 -32
  155. package/dist/assets/index-BvClqlMf.js +0 -852
@@ -0,0 +1,244 @@
1
+ // server/modules/orchestration/a2a/adapters/codex.adapter.ts
2
+ // Wraps the existing server/openai-codex.js queryCodex() runtime.
3
+ // That runtime already emits provider-neutral NormalizedMessage frames,
4
+ // so this adapter mainly translates those frames into A2A bus events.
5
+
6
+ import crypto from 'node:crypto';
7
+
8
+ // eslint-disable-next-line boundaries/no-unknown -- openai-codex.js is a top-level CLI runtime not yet classified by eslint.config.js; cleanup deferred.
9
+ import { abortCodexSession, queryCodex } from '@/openai-codex.js';
10
+ import { AbstractA2AAdapter } from '@/modules/orchestration/a2a/adapters/abstract-a2a.adapter.js';
11
+ import type {
12
+ AdapterContext,
13
+ TaskHandle,
14
+ } from '@/modules/orchestration/a2a/adapters/abstract-a2a.adapter.js';
15
+ import type { AgentCard, Part, Task } from '@/modules/orchestration/a2a/types.js';
16
+ import type { NormalizedMessage } from '@/shared/types.js';
17
+
18
+ interface FakeWriter {
19
+ send(data: unknown): void;
20
+ isSSEStreamWriter: true;
21
+ }
22
+
23
+ function joinPartsToPrompt(parts: Part[]): string {
24
+ return parts
25
+ .map((part) => {
26
+ if (part.kind === 'text') return part.text;
27
+ if (part.kind === 'data') return JSON.stringify(part.data);
28
+ return `[file:${part.name}${part.uri ? ` uri=${part.uri}` : ''}]`;
29
+ })
30
+ .join('\n');
31
+ }
32
+
33
+ function newId(prefix: string): string {
34
+ return `${prefix}_${crypto.randomBytes(8).toString('hex')}`;
35
+ }
36
+
37
+ export class CodexA2AAdapter extends AbstractA2AAdapter {
38
+ readonly id = 'codex';
39
+
40
+ readonly agentCard: AgentCard = {
41
+ name: 'pixcode-codex',
42
+ description: 'OpenAI Codex, accessed via Pixcode',
43
+ url: '/a2a/agents/codex',
44
+ version: '1.0.0',
45
+ capabilities: ['streaming', 'fileEdit', 'commandExec', 'webSearch', 'mcp'],
46
+ skills: [
47
+ {
48
+ id: 'typescript-edit',
49
+ description: 'Edit TypeScript and JavaScript files with CLI-driven reasoning',
50
+ },
51
+ {
52
+ id: 'command-execution',
53
+ description: 'Run shell commands and react to their output',
54
+ },
55
+ {
56
+ id: 'web-research',
57
+ description: 'Use web search as part of the development workflow',
58
+ },
59
+ {
60
+ id: 'task-planning',
61
+ description: 'Create and update TODO-style execution plans',
62
+ },
63
+ ],
64
+ authentication: { type: 'bearer' },
65
+ };
66
+
67
+ private readonly active = new Map<string, { sessionId: string | null }>();
68
+
69
+ async submitTask(task: Task, ctx: AdapterContext): Promise<TaskHandle> {
70
+ const promptText = joinPartsToPrompt(
71
+ task.history[task.history.length - 1]?.parts ?? [],
72
+ );
73
+ const session = { sessionId: null as string | null };
74
+ this.active.set(task.id, session);
75
+
76
+ this.emitState(task.id, 'working');
77
+
78
+ const fakeWriter: FakeWriter = {
79
+ isSSEStreamWriter: true,
80
+ send: (data) => this.handleRuntimeFrame(task.id, data, session),
81
+ };
82
+
83
+ const finished = (async () => {
84
+ try {
85
+ await queryCodex(
86
+ promptText,
87
+ {
88
+ cwd: ctx.cwd,
89
+ permissionMode: ctx.permissionMode ?? 'default',
90
+ model: ctx.model,
91
+ },
92
+ fakeWriter,
93
+ );
94
+
95
+ if (this.active.has(task.id)) {
96
+ this.emitState(task.id, 'completed');
97
+ }
98
+ } catch (err) {
99
+ if (this.active.has(task.id)) {
100
+ this.emitState(task.id, 'failed', {
101
+ code: 'ADAPTER_RUNTIME_ERROR',
102
+ message: err instanceof Error ? err.message : String(err),
103
+ });
104
+ }
105
+ } finally {
106
+ this.active.delete(task.id);
107
+ }
108
+ })();
109
+
110
+ return {
111
+ cancel: () => this.cancelTask(task.id),
112
+ finished,
113
+ };
114
+ }
115
+
116
+ async cancelTask(taskId: string): Promise<void> {
117
+ const session = this.active.get(taskId);
118
+ if (!session) {
119
+ this.emitState(taskId, 'canceled');
120
+ return;
121
+ }
122
+
123
+ this.active.delete(taskId);
124
+ if (session.sessionId) {
125
+ abortCodexSession(session.sessionId);
126
+ }
127
+ this.emitState(taskId, 'canceled');
128
+ }
129
+
130
+ private handleRuntimeFrame(
131
+ taskId: string,
132
+ frame: unknown,
133
+ session: { sessionId: string | null },
134
+ ): void {
135
+ if (!frame || typeof frame !== 'object') return;
136
+ const message = frame as Partial<NormalizedMessage>;
137
+
138
+ if (
139
+ message.kind === 'session_created' &&
140
+ typeof message.newSessionId === 'string' &&
141
+ !session.sessionId
142
+ ) {
143
+ session.sessionId = message.newSessionId;
144
+ return;
145
+ }
146
+
147
+ switch (message.kind) {
148
+ case 'text': {
149
+ const text = typeof message.content === 'string' ? message.content : null;
150
+ if (text && text.trim()) {
151
+ this.emitMessage(taskId, {
152
+ messageId: typeof message.id === 'string' ? message.id : newId('msg'),
153
+ role: message.role === 'user' ? 'user' : 'agent',
154
+ parts: [{ kind: 'text', text }],
155
+ taskId,
156
+ });
157
+ }
158
+ return;
159
+ }
160
+
161
+ case 'thinking': {
162
+ const text = typeof message.content === 'string' ? message.content : '';
163
+ this.emitArtifact(taskId, {
164
+ artifactId: typeof message.id === 'string' ? message.id : newId('art'),
165
+ type: 'data',
166
+ parts: [{ kind: 'data', data: { kind: 'thinking', text } }],
167
+ metadata: { source: 'codex-thinking' },
168
+ });
169
+ return;
170
+ }
171
+
172
+ case 'tool_use': {
173
+ this.emitArtifact(taskId, {
174
+ artifactId: typeof message.id === 'string' ? message.id : newId('art'),
175
+ type: 'command-output',
176
+ parts: [
177
+ {
178
+ kind: 'data',
179
+ data: {
180
+ toolName: message.toolName,
181
+ toolInput: message.toolInput,
182
+ toolResult: message.toolResult,
183
+ output: message.output,
184
+ exitCode: message.exitCode,
185
+ status: message.status,
186
+ },
187
+ },
188
+ ],
189
+ metadata: { source: 'codex-tool-use' },
190
+ });
191
+ return;
192
+ }
193
+
194
+ case 'tool_result': {
195
+ this.emitArtifact(taskId, {
196
+ artifactId: typeof message.id === 'string' ? message.id : newId('art'),
197
+ type: 'command-output',
198
+ parts: [
199
+ {
200
+ kind: 'data',
201
+ data: {
202
+ toolId: message.toolId,
203
+ content: message.content,
204
+ isError: message.isError,
205
+ toolUseResult: message.toolUseResult,
206
+ },
207
+ },
208
+ ],
209
+ metadata: { source: 'codex-tool-result' },
210
+ });
211
+ return;
212
+ }
213
+
214
+ case 'status':
215
+ case 'stream_delta':
216
+ case 'stream_end':
217
+ case 'complete':
218
+ case 'session_created':
219
+ return;
220
+
221
+ case 'error': {
222
+ const text =
223
+ typeof message.content === 'string' && message.content.length > 0
224
+ ? message.content
225
+ : 'Codex reported an error';
226
+ this.emitState(taskId, 'failed', {
227
+ code: 'ADAPTER_RUNTIME_ERROR',
228
+ message: text,
229
+ });
230
+ this.active.delete(taskId);
231
+ return;
232
+ }
233
+
234
+ default: {
235
+ this.emitArtifact(taskId, {
236
+ artifactId: typeof message.id === 'string' ? message.id : newId('art'),
237
+ type: 'data',
238
+ parts: [{ kind: 'data', data: message as Record<string, unknown> }],
239
+ metadata: { source: `codex-${String(message.kind ?? 'event')}` },
240
+ });
241
+ }
242
+ }
243
+ }
244
+ }
@@ -0,0 +1,249 @@
1
+ // server/modules/orchestration/a2a/adapters/cursor.adapter.ts
2
+ // Wraps the existing server/cursor-cli.js runtime, which emits
3
+ // provider-neutral NormalizedMessage frames over a writer interface.
4
+
5
+ import crypto from 'node:crypto';
6
+
7
+ // eslint-disable-next-line boundaries/no-unknown -- cursor-cli.js is a top-level CLI runtime not yet classified by eslint.config.js; cleanup deferred.
8
+ import { abortCursorSession, spawnCursor } from '@/cursor-cli.js';
9
+ import { AbstractA2AAdapter } from '@/modules/orchestration/a2a/adapters/abstract-a2a.adapter.js';
10
+ import type {
11
+ AdapterContext,
12
+ TaskHandle,
13
+ } from '@/modules/orchestration/a2a/adapters/abstract-a2a.adapter.js';
14
+ import type { AgentCard, Part, Task } from '@/modules/orchestration/a2a/types.js';
15
+ import type { NormalizedMessage } from '@/shared/types.js';
16
+
17
+ interface FakeWriter {
18
+ send(data: unknown): void;
19
+ getSessionId(): string | null;
20
+ setSessionId(sessionId: string): void;
21
+ }
22
+
23
+ function joinPartsToPrompt(parts: Part[]): string {
24
+ return parts
25
+ .map((part) => {
26
+ if (part.kind === 'text') return part.text;
27
+ if (part.kind === 'data') return JSON.stringify(part.data);
28
+ return `[file:${part.name}${part.uri ? ` uri=${part.uri}` : ''}]`;
29
+ })
30
+ .join('\n');
31
+ }
32
+
33
+ function newId(prefix: string): string {
34
+ return `${prefix}_${crypto.randomBytes(8).toString('hex')}`;
35
+ }
36
+
37
+ export class CursorA2AAdapter extends AbstractA2AAdapter {
38
+ readonly id = 'cursor';
39
+
40
+ readonly agentCard: AgentCard = {
41
+ name: 'pixcode-cursor',
42
+ description: 'Cursor CLI, accessed via Pixcode',
43
+ url: '/a2a/agents/cursor',
44
+ version: '1.0.0',
45
+ capabilities: ['streaming', 'fileEdit', 'commandExec'],
46
+ skills: [
47
+ {
48
+ id: 'rapid-prototyping',
49
+ description: 'Fast implementation for coding tasks in Cursor CLI',
50
+ },
51
+ {
52
+ id: 'reasoning-assist',
53
+ description: 'Emit reasoning and tool traces during execution',
54
+ },
55
+ {
56
+ id: 'multi-file-refactor',
57
+ description: 'Coordinate edits across multiple files',
58
+ },
59
+ ],
60
+ authentication: { type: 'bearer' },
61
+ };
62
+
63
+ private readonly active = new Map<string, { sessionId: string | null }>();
64
+
65
+ async submitTask(task: Task, ctx: AdapterContext): Promise<TaskHandle> {
66
+ const promptText = joinPartsToPrompt(
67
+ task.history[task.history.length - 1]?.parts ?? [],
68
+ );
69
+ const session = { sessionId: null as string | null };
70
+ this.active.set(task.id, session);
71
+
72
+ this.emitState(task.id, 'working');
73
+
74
+ const fakeWriter: FakeWriter = {
75
+ send: (data) => this.handleRuntimeFrame(task.id, data, session),
76
+ getSessionId: () => session.sessionId,
77
+ setSessionId: (sessionId) => {
78
+ session.sessionId = sessionId;
79
+ },
80
+ };
81
+
82
+ const finished = (async () => {
83
+ try {
84
+ await spawnCursor(
85
+ promptText,
86
+ {
87
+ cwd: ctx.cwd,
88
+ model: ctx.model,
89
+ toolsSettings: ctx.toolsSettings,
90
+ skipPermissions:
91
+ ctx.permissionMode === 'acceptEdits' || ctx.permissionMode === 'bypassPermissions',
92
+ },
93
+ fakeWriter,
94
+ );
95
+
96
+ if (this.active.has(task.id)) {
97
+ this.emitState(task.id, 'completed');
98
+ }
99
+ } catch (err) {
100
+ if (this.active.has(task.id)) {
101
+ this.emitState(task.id, 'failed', {
102
+ code: 'ADAPTER_RUNTIME_ERROR',
103
+ message: err instanceof Error ? err.message : String(err),
104
+ });
105
+ }
106
+ } finally {
107
+ this.active.delete(task.id);
108
+ }
109
+ })();
110
+
111
+ return {
112
+ cancel: () => this.cancelTask(task.id),
113
+ finished,
114
+ };
115
+ }
116
+
117
+ async cancelTask(taskId: string): Promise<void> {
118
+ const session = this.active.get(taskId);
119
+ if (!session) {
120
+ this.emitState(taskId, 'canceled');
121
+ return;
122
+ }
123
+
124
+ this.active.delete(taskId);
125
+ if (session.sessionId) {
126
+ abortCursorSession(session.sessionId);
127
+ }
128
+ this.emitState(taskId, 'canceled');
129
+ }
130
+
131
+ private handleRuntimeFrame(
132
+ taskId: string,
133
+ frame: unknown,
134
+ session: { sessionId: string | null },
135
+ ): void {
136
+ if (!frame || typeof frame !== 'object') return;
137
+ const message = frame as Partial<NormalizedMessage>;
138
+
139
+ if (
140
+ message.kind === 'session_created' &&
141
+ typeof message.newSessionId === 'string' &&
142
+ !session.sessionId
143
+ ) {
144
+ session.sessionId = message.newSessionId;
145
+ return;
146
+ }
147
+
148
+ switch (message.kind) {
149
+ case 'stream_delta':
150
+ case 'text': {
151
+ const text = typeof message.content === 'string' ? message.content : null;
152
+ if (text && text.trim()) {
153
+ this.emitMessage(taskId, {
154
+ messageId: typeof message.id === 'string' ? message.id : newId('msg'),
155
+ role: message.role === 'user' ? 'user' : 'agent',
156
+ parts: [{ kind: 'text', text }],
157
+ taskId,
158
+ });
159
+ }
160
+ return;
161
+ }
162
+
163
+ case 'thinking': {
164
+ this.emitArtifact(taskId, {
165
+ artifactId: typeof message.id === 'string' ? message.id : newId('art'),
166
+ type: 'data',
167
+ parts: [
168
+ {
169
+ kind: 'data',
170
+ data: {
171
+ kind: 'thinking',
172
+ content: message.content,
173
+ },
174
+ },
175
+ ],
176
+ metadata: { source: 'cursor-thinking' },
177
+ });
178
+ return;
179
+ }
180
+
181
+ case 'tool_use': {
182
+ this.emitArtifact(taskId, {
183
+ artifactId: typeof message.id === 'string' ? message.id : newId('art'),
184
+ type: 'command-output',
185
+ parts: [
186
+ {
187
+ kind: 'data',
188
+ data: {
189
+ toolName: message.toolName,
190
+ toolInput: message.toolInput,
191
+ toolId: message.toolId,
192
+ toolResult: message.toolResult,
193
+ },
194
+ },
195
+ ],
196
+ metadata: { source: 'cursor-tool-use' },
197
+ });
198
+ return;
199
+ }
200
+
201
+ case 'tool_result': {
202
+ this.emitArtifact(taskId, {
203
+ artifactId: typeof message.id === 'string' ? message.id : newId('art'),
204
+ type: 'command-output',
205
+ parts: [
206
+ {
207
+ kind: 'data',
208
+ data: {
209
+ toolId: message.toolId,
210
+ content: message.content,
211
+ isError: message.isError,
212
+ },
213
+ },
214
+ ],
215
+ metadata: { source: 'cursor-tool-result' },
216
+ });
217
+ return;
218
+ }
219
+
220
+ case 'status':
221
+ case 'stream_end':
222
+ case 'complete':
223
+ case 'session_created':
224
+ return;
225
+
226
+ case 'error': {
227
+ const text =
228
+ typeof message.content === 'string' && message.content.length > 0
229
+ ? message.content
230
+ : 'Cursor reported an error';
231
+ this.emitState(taskId, 'failed', {
232
+ code: 'ADAPTER_RUNTIME_ERROR',
233
+ message: text,
234
+ });
235
+ this.active.delete(taskId);
236
+ return;
237
+ }
238
+
239
+ default: {
240
+ this.emitArtifact(taskId, {
241
+ artifactId: typeof message.id === 'string' ? message.id : newId('art'),
242
+ type: 'data',
243
+ parts: [{ kind: 'data', data: message as Record<string, unknown> }],
244
+ metadata: { source: `cursor-${String(message.kind ?? 'event')}` },
245
+ });
246
+ }
247
+ }
248
+ }
249
+ }