@pixelbyte-software/pixcode 1.52.4 → 1.53.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 (95) hide show
  1. package/README.md +9 -10
  2. package/README.tr.md +1 -1
  3. package/dist/api-automation.html +1 -1
  4. package/dist/assets/index-Cz9BCbXv.css +32 -0
  5. package/dist/assets/index-yE2qL74i.js +816 -0
  6. package/dist/docs.html +10 -10
  7. package/dist/features.html +3 -3
  8. package/dist/index.html +2 -2
  9. package/dist/landing.html +16 -16
  10. package/dist/llms-full.txt +4 -4
  11. package/dist/llms.txt +3 -3
  12. package/dist/openapi.yaml +6 -6
  13. package/dist-server/server/index.js +8 -118
  14. package/dist-server/server/index.js.map +1 -1
  15. package/dist-server/server/modules/orchestration/a2a/adapters/claude-code.adapter.js +1 -1
  16. package/dist-server/server/modules/orchestration/a2a/adapters/claude-code.adapter.js.map +1 -1
  17. package/dist-server/server/modules/orchestration/a2a/adapters/codex.adapter.js +1 -1
  18. package/dist-server/server/modules/orchestration/a2a/adapters/codex.adapter.js.map +1 -1
  19. package/dist-server/server/modules/orchestration/a2a/adapters/cursor.adapter.js +1 -1
  20. package/dist-server/server/modules/orchestration/a2a/adapters/cursor.adapter.js.map +1 -1
  21. package/dist-server/server/modules/orchestration/a2a/adapters/gemini.adapter.js +1 -1
  22. package/dist-server/server/modules/orchestration/a2a/adapters/gemini.adapter.js.map +1 -1
  23. package/dist-server/server/modules/orchestration/a2a/adapters/json-event.adapter.js +1 -1
  24. package/dist-server/server/modules/orchestration/a2a/adapters/json-event.adapter.js.map +1 -1
  25. package/dist-server/server/modules/orchestration/a2a/adapters/opencode.adapter.js +1 -1
  26. package/dist-server/server/modules/orchestration/a2a/adapters/opencode.adapter.js.map +1 -1
  27. package/dist-server/server/modules/orchestration/a2a/adapters/qwen.adapter.js +1 -1
  28. package/dist-server/server/modules/orchestration/a2a/adapters/qwen.adapter.js.map +1 -1
  29. package/dist-server/server/modules/orchestration/a2a/agent-card.js +4 -4
  30. package/dist-server/server/modules/orchestration/a2a/agent-card.js.map +1 -1
  31. package/dist-server/server/modules/orchestration/a2a/routes.js +2 -5
  32. package/dist-server/server/modules/orchestration/a2a/routes.js.map +1 -1
  33. package/dist-server/server/modules/orchestration/a2a/task-dispatcher.js +295 -0
  34. package/dist-server/server/modules/orchestration/a2a/task-dispatcher.js.map +1 -0
  35. package/dist-server/server/modules/orchestration/index.js +0 -2
  36. package/dist-server/server/modules/orchestration/index.js.map +1 -1
  37. package/dist-server/server/modules/orchestration/tasks/orchestration-task-store.js +2 -2
  38. package/dist-server/server/modules/orchestration/tasks/orchestration-task-store.js.map +1 -1
  39. package/dist-server/server/modules/orchestration/tasks/orchestration-task.routes.js +12 -0
  40. package/dist-server/server/modules/orchestration/tasks/orchestration-task.routes.js.map +1 -1
  41. package/dist-server/server/modules/orchestration/tasks/orchestration-task.service.js +19 -26
  42. package/dist-server/server/modules/orchestration/tasks/orchestration-task.service.js.map +1 -1
  43. package/dist-server/server/modules/orchestration/workflows/workflow-runner.js +47 -58
  44. package/dist-server/server/modules/orchestration/workflows/workflow-runner.js.map +1 -1
  45. package/dist-server/server/modules/orchestration/workflows/workflow-trace.js +2 -2
  46. package/dist-server/server/modules/orchestration/workflows/workflow-trace.js.map +1 -1
  47. package/dist-server/server/services/public-api-manifest.js +0 -9
  48. package/dist-server/server/services/public-api-manifest.js.map +1 -1
  49. package/package.json +1 -1
  50. package/server/index.js +7 -126
  51. package/server/modules/orchestration/a2a/adapters/claude-code.adapter.ts +1 -1
  52. package/server/modules/orchestration/a2a/adapters/codex.adapter.ts +1 -1
  53. package/server/modules/orchestration/a2a/adapters/cursor.adapter.ts +1 -1
  54. package/server/modules/orchestration/a2a/adapters/gemini.adapter.ts +1 -1
  55. package/server/modules/orchestration/a2a/adapters/json-event.adapter.ts +1 -1
  56. package/server/modules/orchestration/a2a/adapters/opencode.adapter.ts +1 -1
  57. package/server/modules/orchestration/a2a/adapters/qwen.adapter.ts +1 -1
  58. package/server/modules/orchestration/a2a/agent-card.ts +4 -4
  59. package/server/modules/orchestration/a2a/routes.ts +2 -6
  60. package/server/modules/orchestration/a2a/task-dispatcher.ts +345 -0
  61. package/server/modules/orchestration/index.ts +0 -2
  62. package/server/modules/orchestration/tasks/orchestration-task-store.ts +2 -2
  63. package/server/modules/orchestration/tasks/orchestration-task.routes.ts +17 -0
  64. package/server/modules/orchestration/tasks/orchestration-task.service.ts +19 -27
  65. package/server/modules/orchestration/tasks/orchestration-task.types.ts +2 -2
  66. package/server/modules/orchestration/tasks/task-run-graph.ts +1 -1
  67. package/server/modules/orchestration/workflows/workflow-runner.ts +52 -60
  68. package/server/modules/orchestration/workflows/workflow-trace.ts +2 -2
  69. package/server/modules/orchestration/workflows/workflow.types.ts +1 -1
  70. package/server/services/public-api-manifest.js +0 -9
  71. package/dist/assets/index-CapxXSc7.js +0 -816
  72. package/dist/assets/index-DkT6-Pja.css +0 -32
  73. package/dist/hermes-agent.png +0 -0
  74. package/dist-server/server/modules/orchestration/hermes/hermes.routes.js +0 -577
  75. package/dist-server/server/modules/orchestration/hermes/hermes.routes.js.map +0 -1
  76. package/dist-server/server/services/hermes-gateway.js +0 -1467
  77. package/dist-server/server/services/hermes-gateway.js.map +0 -1
  78. package/dist-server/server/services/hermes-install-jobs.js +0 -676
  79. package/dist-server/server/services/hermes-install-jobs.js.map +0 -1
  80. package/scripts/hermes/configure-pixcode-mcp.mjs +0 -165
  81. package/scripts/hermes/pixcode-mcp-server.mjs +0 -1009
  82. package/scripts/smoke/hermes-api-install.mjs +0 -56
  83. package/scripts/smoke/hermes-gateway-persistence.mjs +0 -104
  84. package/scripts/smoke/hermes-mcp-pixcode-roundtrip.mjs +0 -426
  85. package/scripts/smoke/hermes-rest-chat-api.mjs +0 -162
  86. package/scripts/smoke/hermes-rest-chat-live.mjs +0 -45
  87. package/scripts/smoke/hermes-rest-codex-launch.mjs +0 -209
  88. package/scripts/smoke/hermes-rest-gateway.mjs +0 -79
  89. package/scripts/smoke/hermes-rest-live.mjs +0 -42
  90. package/scripts/smoke/hermes-roundtrip.mjs +0 -167
  91. package/scripts/smoke/hermes-settings-commands.mjs +0 -349
  92. package/scripts/smoke/hermes-smoke-launcher-guard.mjs +0 -34
  93. package/server/modules/orchestration/hermes/hermes.routes.ts +0 -642
  94. package/server/services/hermes-gateway.js +0 -1562
  95. package/server/services/hermes-install-jobs.js +0 -729
@@ -1,642 +0,0 @@
1
- import os from 'node:os';
2
- import { EventEmitter } from 'node:events';
3
-
4
- import express, { type Request, type Response, type Router } from 'express';
5
-
6
- import { adapterRegistry } from '@/modules/orchestration/a2a/adapter-registry.js';
7
- import { a2aTaskStore as hermesTaskStore } from '@/modules/orchestration/a2a/task-store.js';
8
- import {
9
- cancelHermesInstallJob,
10
- createHermesInstallJob,
11
- getHermesInstallJob,
12
- readHermesInstallStatus,
13
- snapshotHermesInstallDonePayload,
14
- } from '@/services/hermes-install-jobs.js';
15
- import {
16
- ensureHermesGateway,
17
- getHermesGatewayStatus,
18
- probeHermesGateway,
19
- readHermesControlPlane,
20
- readHermesDiagnostics,
21
- repairHermesControlPlane,
22
- requestHermesGateway,
23
- runHermesGatewayPrompt,
24
- stopHermesGateway,
25
- } from '@/services/hermes-gateway.js';
26
-
27
- const HERMES_TERMINAL_LAUNCH_LIMIT = 100;
28
- const HERMES_TERMINAL_LAUNCH_PROVIDERS = new Set(['claude', 'codex', 'cursor', 'gemini', 'qwen', 'opencode']);
29
- const HERMES_TERMINAL_LAUNCH_STREAM_HEARTBEAT_MS = 25000;
30
-
31
- type HermesTerminalLaunchEvent = {
32
- id: number;
33
- provider: string;
34
- projectPath: string | null;
35
- prompt: string | null;
36
- startupInput: string | null;
37
- forceNewSession: boolean;
38
- permissionMode: string | null;
39
- skipPermissions: boolean;
40
- bypassPermissions: boolean;
41
- source: string;
42
- createdAt: string;
43
- };
44
-
45
- type HermesRouterOptions = {
46
- appRoot?: string;
47
- createHermesApiKey?: (userId: number | string | null | undefined) => string | null;
48
- resolvePublicBaseUrl?: (req: Request) => string;
49
- };
50
-
51
- type PixcodeRequest = Request & {
52
- user?: {
53
- id?: number | string;
54
- userId?: number | string;
55
- };
56
- };
57
-
58
- let nextHermesTerminalLaunchId = 1;
59
- const hermesTerminalLaunches: HermesTerminalLaunchEvent[] = [];
60
- const hermesTerminalLaunchEmitter = new EventEmitter();
61
- hermesTerminalLaunchEmitter.setMaxListeners(200);
62
-
63
- function writeSse(res: Response, event: string, payload: unknown) {
64
- res.write(`event: ${event}\n`);
65
- res.write(`data: ${JSON.stringify(payload)}\n\n`);
66
- }
67
-
68
- function readUserId(req: PixcodeRequest) {
69
- return req.user?.id ?? req.user?.userId ?? null;
70
- }
71
-
72
- function resolveHermesMcpBaseUrl() {
73
- const configured = process.env.PIXCODE_INTERNAL_BASE_URL || process.env.PIXCODE_HERMES_BASE_URL;
74
- if (configured) return configured.replace(/\/$/, '');
75
-
76
- return `http://127.0.0.1:${process.env.SERVER_PORT ?? process.env.PORT ?? '3001'}`;
77
- }
78
-
79
- function readAfterId(req: Request) {
80
- const after = Number.parseInt(typeof req.query.after === 'string' ? req.query.after : '0', 10);
81
- return Number.isFinite(after) ? after : 0;
82
- }
83
-
84
- function rememberHermesTerminalLaunch(event: HermesTerminalLaunchEvent) {
85
- hermesTerminalLaunches.push(event);
86
- if (hermesTerminalLaunches.length > HERMES_TERMINAL_LAUNCH_LIMIT) {
87
- hermesTerminalLaunches.splice(0, hermesTerminalLaunches.length - HERMES_TERMINAL_LAUNCH_LIMIT);
88
- }
89
- hermesTerminalLaunchEmitter.emit('terminal-launch', event);
90
- }
91
-
92
- function readTrimmedString(value: unknown) {
93
- return typeof value === 'string' && value.trim() ? value.trim() : null;
94
- }
95
-
96
- function readBoolean(value: unknown) {
97
- return value === true || value === 'true' || value === '1';
98
- }
99
-
100
- function isLegacyPromptLikelyStartupInput(prompt: string | null) {
101
- if (!prompt || prompt.length > 160 || prompt.includes('\n')) return false;
102
- if (/^[/:!@]/u.test(prompt)) return true;
103
- if (prompt.includes(':')) return false;
104
- if (/\b(user|request|reason|audit|task|kullanıcı|kullanicinin|istek|isteği|gorev|görev|terminal|codex|claude|qwen|gemini|cursor|opencode|open|aç|ac|başlat|baslat|send|gönder|gonder)\b/iu.test(prompt)) {
105
- return false;
106
- }
107
- return prompt.length <= 80;
108
- }
109
-
110
- export function createHermesRouter(options: HermesRouterOptions = {}): Router {
111
- const router = express.Router();
112
-
113
- router.get('/status', (_req, res) => {
114
- res.json({
115
- id: 'hermes',
116
- name: 'Hermes Agent',
117
- product: 'Pixcode',
118
- runtime: {
119
- mode: process.env.PIXCODE_MANAGED_PLATFORM === '1' ? 'managed' : 'local',
120
- host: os.hostname(),
121
- node: process.version,
122
- pid: process.pid,
123
- },
124
- capabilities: [
125
- 'project-aware CLI orchestration',
126
- 'background checks and tests',
127
- 'workspace-scoped terminal operations',
128
- 'run history and artifact review',
129
- ],
130
- });
131
- });
132
-
133
- router.get('/context', (req, res) => {
134
- const project = typeof req.query.project === 'string' ? req.query.project : null;
135
- const cwd = typeof req.query.cwd === 'string' ? req.query.cwd : process.cwd();
136
- res.json({
137
- agent: 'Hermes Agent',
138
- product: 'Pixcode',
139
- project,
140
- cwd,
141
- local: true,
142
- message: project
143
- ? `Hermes is operating inside Pixcode for ${project}.`
144
- : 'Hermes is operating inside Pixcode.',
145
- });
146
- });
147
-
148
- router.get('/install-status', (_req, res) => {
149
- res.json(readHermesInstallStatus());
150
- });
151
-
152
- router.get('/gateway/status', (req, res) => {
153
- const projectPath = typeof req.query.projectPath === 'string' ? req.query.projectPath : null;
154
- res.json(getHermesGatewayStatus(projectPath));
155
- });
156
-
157
- router.post('/gateway/start', async (req: PixcodeRequest, res) => {
158
- const apiKey = options.createHermesApiKey?.(readUserId(req)) ?? null;
159
- if (!apiKey) {
160
- res.status(500).json({
161
- error: {
162
- code: 'HERMES_API_KEY_UNAVAILABLE',
163
- message: 'Pixcode could not create a Hermes MCP API key for this user.',
164
- },
165
- });
166
- return;
167
- }
168
-
169
- const body = (req.body ?? {}) as Record<string, unknown>;
170
- try {
171
- const gateway = await ensureHermesGateway({
172
- appRoot: options.appRoot ?? process.cwd(),
173
- pixcodeApiKey: apiKey,
174
- pixcodeBaseUrl: resolveHermesMcpBaseUrl(),
175
- projectPath: typeof body.projectPath === 'string' ? body.projectPath : undefined,
176
- });
177
- res.status(202).json(gateway);
178
- } catch (error) {
179
- res.status(500).json({
180
- error: {
181
- code: 'HERMES_GATEWAY_START_FAILED',
182
- message: error instanceof Error ? error.message : String(error),
183
- },
184
- });
185
- }
186
- });
187
-
188
- router.post('/gateway/probe', async (req: PixcodeRequest, res) => {
189
- const body = (req.body ?? {}) as Record<string, unknown>;
190
- const projectPath = typeof body.projectPath === 'string' ? body.projectPath : null;
191
- const input = typeof body.input === 'string' ? body.input : undefined;
192
- const shouldStart = body.startIfNeeded === true;
193
-
194
- try {
195
- if (shouldStart) {
196
- const apiKey = options.createHermesApiKey?.(readUserId(req)) ?? null;
197
- if (!apiKey) {
198
- res.status(500).json({
199
- error: {
200
- code: 'HERMES_API_KEY_UNAVAILABLE',
201
- message: 'Pixcode could not create a Hermes MCP API key for this user.',
202
- },
203
- });
204
- return;
205
- }
206
- await ensureHermesGateway({
207
- appRoot: options.appRoot ?? process.cwd(),
208
- pixcodeApiKey: apiKey,
209
- pixcodeBaseUrl: resolveHermesMcpBaseUrl(),
210
- projectPath: projectPath ?? undefined,
211
- });
212
- }
213
-
214
- const probe = await probeHermesGateway(projectPath, { input });
215
- res.status(probe.ok ? 200 : 503).json(probe);
216
- } catch (error) {
217
- res.status(500).json({
218
- error: {
219
- code: 'HERMES_GATEWAY_PROBE_FAILED',
220
- message: error instanceof Error ? error.message : String(error),
221
- },
222
- });
223
- }
224
- });
225
-
226
- router.post('/gateway/chat', async (req: PixcodeRequest, res) => {
227
- const body = (req.body ?? {}) as Record<string, unknown>;
228
- const projectPath = typeof body.projectPath === 'string' && body.projectPath.trim()
229
- ? body.projectPath.trim()
230
- : undefined;
231
- const input = typeof body.input === 'string' ? body.input.trim() : '';
232
- const sessionId = typeof body.sessionId === 'string' && body.sessionId.trim()
233
- ? body.sessionId.trim()
234
- : undefined;
235
-
236
- if (!input) {
237
- res.status(400).json({
238
- error: {
239
- code: 'HERMES_PROMPT_REQUIRED',
240
- message: 'Hermes prompt is required.',
241
- },
242
- });
243
- return;
244
- }
245
-
246
- const apiKey = options.createHermesApiKey?.(readUserId(req)) ?? null;
247
- if (!apiKey) {
248
- res.status(500).json({
249
- error: {
250
- code: 'HERMES_API_KEY_UNAVAILABLE',
251
- message: 'Pixcode could not create a Hermes MCP API key for this user.',
252
- },
253
- });
254
- return;
255
- }
256
-
257
- try {
258
- const gateway = await ensureHermesGateway({
259
- appRoot: options.appRoot ?? process.cwd(),
260
- pixcodeApiKey: apiKey,
261
- pixcodeBaseUrl: resolveHermesMcpBaseUrl(),
262
- projectPath,
263
- probeExisting: false,
264
- });
265
- const run = await runHermesGatewayPrompt(projectPath, {
266
- input,
267
- sessionId,
268
- });
269
-
270
- res.status(run.ok ? 200 : 502).json({
271
- ok: run.ok,
272
- gateway,
273
- run,
274
- message: run.message,
275
- error: run.error ?? null,
276
- });
277
- } catch (error) {
278
- res.status(500).json({
279
- error: {
280
- code: 'HERMES_GATEWAY_CHAT_FAILED',
281
- message: error instanceof Error ? error.message : String(error),
282
- },
283
- });
284
- }
285
- });
286
-
287
- router.post('/gateway/request', async (req: PixcodeRequest, res) => {
288
- const body = (req.body ?? {}) as Record<string, unknown>;
289
- const projectPath = typeof body.projectPath === 'string' && body.projectPath.trim()
290
- ? body.projectPath.trim()
291
- : undefined;
292
- const endpoint = typeof body.endpoint === 'string' ? body.endpoint : body.path;
293
- const method = typeof body.method === 'string' ? body.method : 'GET';
294
-
295
- try {
296
- if (body.startIfNeeded === true) {
297
- const apiKey = options.createHermesApiKey?.(readUserId(req)) ?? null;
298
- if (!apiKey) {
299
- res.status(500).json({
300
- error: {
301
- code: 'HERMES_API_KEY_UNAVAILABLE',
302
- message: 'Pixcode could not create a Hermes MCP API key for this user.',
303
- },
304
- });
305
- return;
306
- }
307
- await ensureHermesGateway({
308
- appRoot: options.appRoot ?? process.cwd(),
309
- pixcodeApiKey: apiKey,
310
- pixcodeBaseUrl: resolveHermesMcpBaseUrl(),
311
- projectPath,
312
- });
313
- }
314
-
315
- const gatewayResponse = await requestHermesGateway(projectPath, {
316
- endpoint,
317
- method,
318
- body: body.body,
319
- timeoutMs: typeof body.timeoutMs === 'number' ? body.timeoutMs : undefined,
320
- });
321
- res.status(gatewayResponse.ok ? 200 : 502).json(gatewayResponse);
322
- } catch (error) {
323
- res.status(500).json({
324
- error: {
325
- code: 'HERMES_GATEWAY_REQUEST_FAILED',
326
- message: error instanceof Error ? error.message : String(error),
327
- },
328
- });
329
- }
330
- });
331
-
332
- router.get('/diagnostics', async (req, res) => {
333
- const projectPath = typeof req.query.projectPath === 'string' && req.query.projectPath.trim()
334
- ? req.query.projectPath.trim()
335
- : undefined;
336
-
337
- try {
338
- const diagnostics = await readHermesDiagnostics({
339
- appRoot: options.appRoot ?? process.cwd(),
340
- projectPath,
341
- });
342
- res.status(diagnostics.ok ? 200 : 503).json(diagnostics);
343
- } catch (error) {
344
- res.status(500).json({
345
- error: {
346
- code: 'HERMES_DIAGNOSTICS_FAILED',
347
- message: error instanceof Error ? error.message : String(error),
348
- },
349
- });
350
- }
351
- });
352
-
353
- router.get('/control-plane', async (req, res) => {
354
- const projectPath = typeof req.query.projectPath === 'string' && req.query.projectPath.trim()
355
- ? req.query.projectPath.trim()
356
- : undefined;
357
-
358
- try {
359
- const controlPlane = await readHermesControlPlane({
360
- appRoot: options.appRoot ?? process.cwd(),
361
- projectPath,
362
- });
363
- res.status(controlPlane.ok ? 200 : 503).json(controlPlane);
364
- } catch (error) {
365
- res.status(500).json({
366
- error: {
367
- code: 'HERMES_CONTROL_PLANE_FAILED',
368
- message: error instanceof Error ? error.message : String(error),
369
- },
370
- });
371
- }
372
- });
373
-
374
- router.post('/control-plane/repair', async (req: PixcodeRequest, res) => {
375
- const apiKey = options.createHermesApiKey?.(readUserId(req)) ?? null;
376
- if (!apiKey) {
377
- res.status(500).json({
378
- error: {
379
- code: 'HERMES_API_KEY_UNAVAILABLE',
380
- message: 'Pixcode could not create a Hermes MCP API key for this user.',
381
- },
382
- });
383
- return;
384
- }
385
-
386
- const body = (req.body ?? {}) as Record<string, unknown>;
387
- const projectPath = typeof body.projectPath === 'string' && body.projectPath.trim()
388
- ? body.projectPath.trim()
389
- : undefined;
390
-
391
- try {
392
- const repaired = await repairHermesControlPlane({
393
- appRoot: options.appRoot ?? process.cwd(),
394
- pixcodeApiKey: apiKey,
395
- pixcodeBaseUrl: resolveHermesMcpBaseUrl(),
396
- projectPath,
397
- forceRestart: readBoolean(body.forceRestart),
398
- });
399
- res.status(repaired.ok ? 200 : 202).json(repaired);
400
- } catch (error) {
401
- res.status(500).json({
402
- error: {
403
- code: 'HERMES_CONTROL_PLANE_REPAIR_FAILED',
404
- message: error instanceof Error ? error.message : String(error),
405
- },
406
- });
407
- }
408
- });
409
-
410
- router.post('/gateway/stop', (req, res) => {
411
- const body = (req.body ?? {}) as Record<string, unknown>;
412
- const projectPath = typeof body.projectPath === 'string' ? body.projectPath : null;
413
- res.json(stopHermesGateway(projectPath));
414
- });
415
-
416
- router.post('/install', (req: PixcodeRequest, res) => {
417
- const apiKey = options.createHermesApiKey?.(readUserId(req)) ?? null;
418
- if (!apiKey) {
419
- res.status(500).json({
420
- error: {
421
- code: 'HERMES_API_KEY_UNAVAILABLE',
422
- message: 'Pixcode could not create a Hermes MCP API key for this user.',
423
- },
424
- });
425
- return;
426
- }
427
-
428
- const body = (req.body ?? {}) as Record<string, unknown>;
429
- const job = createHermesInstallJob({
430
- appRoot: options.appRoot ?? process.cwd(),
431
- force: Boolean(body.force),
432
- pixcodeApiKey: apiKey,
433
- pixcodeBaseUrl: resolveHermesMcpBaseUrl(),
434
- skipBrowser: body.skipBrowser !== false,
435
- });
436
-
437
- res.status(202).json({
438
- jobId: job.id,
439
- provider: 'hermes',
440
- status: job.status,
441
- startedAt: job.startedAt,
442
- });
443
- });
444
-
445
- router.get('/install/:jobId/stream', (req, res) => {
446
- const job = getHermesInstallJob(req.params.jobId);
447
- if (!job) {
448
- res.status(404).json({
449
- error: {
450
- code: 'HERMES_INSTALL_JOB_NOT_FOUND',
451
- message: 'Hermes install job not found or already expired.',
452
- },
453
- });
454
- return;
455
- }
456
-
457
- res.setHeader('Content-Type', 'text/event-stream');
458
- res.setHeader('Cache-Control', 'no-cache, no-transform');
459
- res.setHeader('Connection', 'keep-alive');
460
- res.setHeader('X-Accel-Buffering', 'no');
461
- if (typeof res.flushHeaders === 'function') res.flushHeaders();
462
- try {
463
- (res.socket as NodeJS.Socket & { setNoDelay?: (on: boolean) => void })?.setNoDelay?.(true);
464
- } catch { /* noop */ }
465
-
466
- let closed = false;
467
- const safeWrite = (event: string, payload: unknown) => {
468
- if (closed) return;
469
- try { writeSse(res, event, payload); } catch { /* socket gone */ }
470
- };
471
-
472
- try { res.write(': start\n\n'); } catch { /* noop */ }
473
- const heartbeat = setInterval(() => {
474
- if (closed) return;
475
- try { res.write(': ping\n\n'); } catch { /* noop */ }
476
- }, 5000);
477
-
478
- for (const entry of job.logs) {
479
- safeWrite('log', { stream: entry.stream, chunk: entry.chunk });
480
- }
481
-
482
- const onLog = (entry: { stream: string; chunk: string }) => {
483
- safeWrite('log', { stream: entry.stream, chunk: entry.chunk });
484
- };
485
- const onDone = (payload: Record<string, unknown>) => {
486
- safeWrite('done', payload);
487
- cleanup();
488
- try { res.end(); } catch { /* noop */ }
489
- };
490
- function cleanup() {
491
- if (closed) return;
492
- closed = true;
493
- clearInterval(heartbeat);
494
- job.emitter.off('log', onLog);
495
- job.emitter.off('done', onDone);
496
- }
497
-
498
- if (job.status !== 'running') {
499
- safeWrite('done', snapshotHermesInstallDonePayload(job));
500
- cleanup();
501
- try { res.end(); } catch { /* noop */ }
502
- return;
503
- }
504
-
505
- job.emitter.on('log', onLog);
506
- job.emitter.once('done', onDone);
507
- req.on('close', cleanup);
508
- });
509
-
510
- router.delete('/install/:jobId', (req, res) => {
511
- const job = getHermesInstallJob(req.params.jobId);
512
- if (!job) {
513
- res.status(404).json({
514
- error: {
515
- code: 'HERMES_INSTALL_JOB_NOT_FOUND',
516
- message: 'Hermes install job not found.',
517
- },
518
- });
519
- return;
520
- }
521
-
522
- res.json({ cancelled: cancelHermesInstallJob(req.params.jobId) });
523
- });
524
-
525
- router.get('/agents', (_req, res) => {
526
- res.json({
527
- agent: 'hermes',
528
- agents: adapterRegistry.agentCards().map((agent) => ({
529
- ...agent,
530
- coordinator: 'hermes',
531
- })),
532
- });
533
- });
534
-
535
- router.get('/terminal-launches', (req, res) => {
536
- const afterId = readAfterId(req);
537
- res.json({
538
- events: hermesTerminalLaunches.filter((event) => event.id > afterId),
539
- });
540
- });
541
-
542
- router.get('/terminal-launches/stream', (req, res) => {
543
- const afterId = readAfterId(req);
544
-
545
- res.setHeader('Content-Type', 'text/event-stream');
546
- res.setHeader('Cache-Control', 'no-cache, no-transform');
547
- res.setHeader('Connection', 'keep-alive');
548
- res.setHeader('X-Accel-Buffering', 'no');
549
- if (typeof res.flushHeaders === 'function') res.flushHeaders();
550
- try {
551
- (res.socket as NodeJS.Socket & { setNoDelay?: (on: boolean) => void })?.setNoDelay?.(true);
552
- } catch { /* noop */ }
553
-
554
- let closed = false;
555
- const safeWrite = (event: string, payload: unknown) => {
556
- if (closed) return;
557
- try { writeSse(res, event, payload); } catch { /* socket gone */ }
558
- };
559
-
560
- try { res.write(': start\n\n'); } catch { /* noop */ }
561
- const replayed = hermesTerminalLaunches.filter((event) => event.id > afterId);
562
- for (const event of replayed) {
563
- safeWrite('terminal-launch', event);
564
- }
565
- safeWrite('ready', {
566
- latestId: hermesTerminalLaunches[hermesTerminalLaunches.length - 1]?.id ?? afterId,
567
- replayed: replayed.length,
568
- });
569
-
570
- const heartbeat = setInterval(() => {
571
- if (closed) return;
572
- try { res.write(': ping\n\n'); } catch { /* noop */ }
573
- }, HERMES_TERMINAL_LAUNCH_STREAM_HEARTBEAT_MS);
574
-
575
- const onTerminalLaunch = (event: HermesTerminalLaunchEvent) => {
576
- safeWrite('terminal-launch', event);
577
- };
578
- hermesTerminalLaunchEmitter.on('terminal-launch', onTerminalLaunch);
579
-
580
- const cleanup = () => {
581
- if (closed) return;
582
- closed = true;
583
- clearInterval(heartbeat);
584
- hermesTerminalLaunchEmitter.off('terminal-launch', onTerminalLaunch);
585
- };
586
-
587
- req.on('close', cleanup);
588
- });
589
-
590
- router.post('/terminal-launches', (req, res) => {
591
- const body = (req.body ?? {}) as Record<string, unknown>;
592
- const provider = typeof body.provider === 'string' ? body.provider.trim() : '';
593
- if (!HERMES_TERMINAL_LAUNCH_PROVIDERS.has(provider)) {
594
- res.status(400).json({ error: { code: 'INVALID_PROVIDER', message: provider || 'provider is required' } });
595
- return;
596
- }
597
-
598
- const projectPath = typeof body.projectPath === 'string' && body.projectPath.trim()
599
- ? body.projectPath.trim()
600
- : null;
601
- const prompt = readTrimmedString(body.prompt ?? body.reason);
602
- const requestedStartupInput = readTrimmedString(body.startupInput ?? body.input);
603
- const startupInput = requestedStartupInput ?? (isLegacyPromptLikelyStartupInput(prompt) ? prompt : null);
604
- const forceNewSession = readBoolean(body.forceNewSession ?? body.newSession ?? body.freshSession);
605
- const bypassPermissions = readBoolean(body.bypassPermissions);
606
- const skipPermissions = readBoolean(body.skipPermissions) || bypassPermissions;
607
- const requestedPermissionMode = readTrimmedString(body.permissionMode);
608
- const permissionMode = requestedPermissionMode ?? (skipPermissions ? 'bypassPermissions' : null);
609
-
610
- const event: HermesTerminalLaunchEvent = {
611
- id: nextHermesTerminalLaunchId,
612
- provider,
613
- projectPath,
614
- prompt,
615
- startupInput,
616
- forceNewSession,
617
- permissionMode,
618
- skipPermissions,
619
- bypassPermissions,
620
- source: 'hermes-mcp',
621
- createdAt: new Date().toISOString(),
622
- };
623
- nextHermesTerminalLaunchId += 1;
624
- rememberHermesTerminalLaunch(event);
625
-
626
- res.status(201).json({ event });
627
- });
628
-
629
- router.get('/tasks/:id', (req, res) => {
630
- const task = hermesTaskStore.get(req.params.id);
631
- if (!task) {
632
- res.status(404).json({ error: { code: 'HERMES_TASK_NOT_FOUND', message: req.params.id } });
633
- return;
634
- }
635
- res.json({
636
- ...task,
637
- hermesTaskId: task.id,
638
- });
639
- });
640
-
641
- return router;
642
- }