@pixelbyte-software/pixcode 1.51.1 → 1.51.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.
Files changed (320) hide show
  1. package/CODE_OF_CONDUCT.md +41 -41
  2. package/CONTRIBUTING.md +155 -155
  3. package/LICENSE +718 -718
  4. package/README.de.md +169 -169
  5. package/README.ja.md +167 -167
  6. package/README.ko.md +167 -167
  7. package/README.md +419 -419
  8. package/README.ru.md +169 -169
  9. package/README.tr.md +298 -298
  10. package/README.zh-CN.md +167 -167
  11. package/SECURITY.md +46 -46
  12. package/dist/api-automation.html +110 -110
  13. package/dist/api-docs.html +548 -548
  14. package/dist/assets/{index-DARIZgoD.js → index-17CwxHSZ.js} +185 -185
  15. package/dist/assets/index-B9N-gfOQ.css +32 -0
  16. package/dist/clear-cache.html +85 -85
  17. package/dist/convert-icons.md +52 -52
  18. package/dist/docs.html +308 -308
  19. package/dist/favicon.svg +8 -8
  20. package/dist/features.html +133 -133
  21. package/dist/generate-icons.js +48 -48
  22. package/dist/humans.txt +15 -15
  23. package/dist/icons/codex-white.svg +3 -3
  24. package/dist/icons/codex.svg +3 -3
  25. package/dist/icons/cursor-white.svg +11 -11
  26. package/dist/icons/icon-128x128.svg +9 -9
  27. package/dist/icons/icon-144x144.svg +9 -9
  28. package/dist/icons/icon-152x152.svg +9 -9
  29. package/dist/icons/icon-192x192.svg +9 -9
  30. package/dist/icons/icon-384x384.svg +9 -9
  31. package/dist/icons/icon-512x512.svg +9 -9
  32. package/dist/icons/icon-72x72.svg +9 -9
  33. package/dist/icons/icon-96x96.svg +9 -9
  34. package/dist/icons/icon-template.svg +9 -9
  35. package/dist/icons/qwen-logo.svg +14 -14
  36. package/dist/index.html +59 -59
  37. package/dist/landing.html +268 -268
  38. package/dist/llms-full.txt +119 -119
  39. package/dist/llms.txt +53 -53
  40. package/dist/logo.svg +12 -12
  41. package/dist/manifest.json +60 -60
  42. package/dist/openapi.yaml +1696 -1696
  43. package/dist/orchestration.html +125 -125
  44. package/dist/robots.txt +4 -4
  45. package/dist/site.css +692 -692
  46. package/dist/sitemap.xml +51 -51
  47. package/dist/sw.js +132 -132
  48. package/dist-server/server/cli.js +96 -96
  49. package/dist-server/server/daemon/manager.js +33 -33
  50. package/dist-server/server/daemon-manager.js +64 -64
  51. package/dist-server/server/index.js +125 -4
  52. package/dist-server/server/index.js.map +1 -1
  53. package/dist-server/server/modules/orchestration/a2a/adapters/json-event.adapter.js +84 -0
  54. package/dist-server/server/modules/orchestration/a2a/adapters/json-event.adapter.js.map +1 -0
  55. package/dist-server/server/modules/orchestration/a2a/adapters/json-event.adapter.test.js +43 -0
  56. package/dist-server/server/modules/orchestration/a2a/adapters/json-event.adapter.test.js.map +1 -0
  57. package/dist-server/server/modules/orchestration/hermes/hermes.routes.js +55 -1
  58. package/dist-server/server/modules/orchestration/hermes/hermes.routes.js.map +1 -1
  59. package/dist-server/server/modules/orchestration/index.js +1 -0
  60. package/dist-server/server/modules/orchestration/index.js.map +1 -1
  61. package/dist-server/server/routes/commands.js +25 -25
  62. package/dist-server/server/routes/git.js +17 -17
  63. package/dist-server/server/routes/live-view.js +46 -46
  64. package/dist-server/server/services/hermes-gateway.js +310 -0
  65. package/dist-server/server/services/hermes-gateway.js.map +1 -1
  66. package/dist-server/server/services/public-api-manifest.js +59 -51
  67. package/dist-server/server/services/public-api-manifest.js.map +1 -1
  68. package/package.json +222 -222
  69. package/scripts/fix-node-pty.js +67 -67
  70. package/scripts/github/create-v1.38-issues.mjs +351 -351
  71. package/scripts/github/create-vscode-workbench-issues.mjs +121 -121
  72. package/scripts/hermes/configure-pixcode-mcp.mjs +165 -163
  73. package/scripts/hermes/pixcode-mcp-server.mjs +1009 -958
  74. package/scripts/smoke/changes-panel-layout.mjs +48 -48
  75. package/scripts/smoke/chat-composer-fixed-layout.mjs +55 -55
  76. package/scripts/smoke/chat-message-timeline-order.mjs +41 -41
  77. package/scripts/smoke/chat-realtime-hydration.mjs +44 -44
  78. package/scripts/smoke/chat-session-provider-pools.mjs +35 -35
  79. package/scripts/smoke/chat-session-state.mjs +19 -19
  80. package/scripts/smoke/code-editor-theme.mjs +55 -55
  81. package/scripts/smoke/code-editor-vscode-engine.mjs +91 -91
  82. package/scripts/smoke/command-center-agent-writes.mjs +79 -79
  83. package/scripts/smoke/command-center-non-git.mjs +46 -46
  84. package/scripts/smoke/context-packet.mjs +43 -43
  85. package/scripts/smoke/control-room-ux-redesign.mjs +91 -91
  86. package/scripts/smoke/daemon-entrypoint.mjs +20 -20
  87. package/scripts/smoke/default-landing-routing.mjs +33 -33
  88. package/scripts/smoke/desktop-native-notifications.mjs +30 -30
  89. package/scripts/smoke/desktop-tray-icon.mjs +33 -33
  90. package/scripts/smoke/discord-release-workflow.mjs +24 -24
  91. package/scripts/smoke/git-install-update.mjs +255 -255
  92. package/scripts/smoke/handoff-artifact-protocol.mjs +50 -50
  93. package/scripts/smoke/hermes-api-install.mjs +56 -56
  94. package/scripts/smoke/hermes-gateway-persistence.mjs +104 -104
  95. package/scripts/smoke/hermes-mcp-pixcode-roundtrip.mjs +426 -367
  96. package/scripts/smoke/hermes-rest-chat-api.mjs +162 -162
  97. package/scripts/smoke/hermes-rest-chat-live.mjs +45 -45
  98. package/scripts/smoke/hermes-rest-codex-launch.mjs +209 -209
  99. package/scripts/smoke/hermes-rest-gateway.mjs +79 -70
  100. package/scripts/smoke/hermes-rest-live.mjs +42 -42
  101. package/scripts/smoke/hermes-roundtrip.mjs +167 -167
  102. package/scripts/smoke/hermes-settings-commands.mjs +349 -346
  103. package/scripts/smoke/hermes-smoke-launcher-guard.mjs +34 -34
  104. package/scripts/smoke/live-view-diagnostics.mjs +53 -53
  105. package/scripts/smoke/live-view-environment.mjs +92 -92
  106. package/scripts/smoke/live-view-integration.mjs +450 -450
  107. package/scripts/smoke/mac-desktop-runtime.mjs +37 -37
  108. package/scripts/smoke/mobile-tunnel-guidance.mjs +29 -29
  109. package/scripts/smoke/model-registry.mjs +36 -36
  110. package/scripts/smoke/multi-project-ui.mjs +45 -45
  111. package/scripts/smoke/multi-worker-slots.mjs +42 -42
  112. package/scripts/smoke/notification-center.mjs +87 -87
  113. package/scripts/smoke/notification-inapp-preference.mjs +23 -23
  114. package/scripts/smoke/notification-taxonomy.mjs +58 -58
  115. package/scripts/smoke/orchestration-api.mjs +172 -172
  116. package/scripts/smoke/orchestration-execution-dashboard.mjs +33 -33
  117. package/scripts/smoke/orchestration-live-run.mjs +176 -176
  118. package/scripts/smoke/orchestration-mobile-scroll.mjs +29 -29
  119. package/scripts/smoke/orchestration-model-sync.mjs +30 -30
  120. package/scripts/smoke/orchestration-permission-fallback.mjs +34 -34
  121. package/scripts/smoke/orchestration-runtime-guards.mjs +48 -48
  122. package/scripts/smoke/orchestration-user-facing-output.mjs +25 -25
  123. package/scripts/smoke/permission-policy.mjs +50 -50
  124. package/scripts/smoke/pixcode-workbench-1-48.mjs +167 -164
  125. package/scripts/smoke/provider-models-opencode-live.mjs +66 -66
  126. package/scripts/smoke/provider-rest-api.mjs +124 -124
  127. package/scripts/smoke/provider-selection-status.mjs +52 -52
  128. package/scripts/smoke/run-state-refresh.mjs +52 -52
  129. package/scripts/smoke/runtime-manager.mjs +99 -99
  130. package/scripts/smoke/shell-manual-disconnect.mjs +30 -30
  131. package/scripts/smoke/side-panel-editor-layout.mjs +34 -34
  132. package/scripts/smoke/static-root-routing.mjs +21 -21
  133. package/scripts/smoke/strict-handoff-compact.mjs +60 -60
  134. package/scripts/smoke/taskmaster-config.mjs +24 -24
  135. package/scripts/smoke/taskmaster-execution-telegram.mjs +3 -3
  136. package/scripts/smoke/taskmaster-onboarding.mjs +3 -3
  137. package/scripts/smoke/taskmaster-run-graph.mjs +3 -3
  138. package/scripts/smoke/telegram-control.mjs +242 -242
  139. package/scripts/smoke/tunnel-persistence.mjs +56 -56
  140. package/scripts/smoke/update-issue-progress.mjs +69 -69
  141. package/scripts/smoke/update-ux.mjs +55 -55
  142. package/scripts/smoke/v138-completion.mjs +132 -132
  143. package/scripts/smoke/v138-desktop-release-hardening.mjs +69 -69
  144. package/scripts/smoke/v138-diagnostics.mjs +63 -63
  145. package/scripts/smoke/v138-issue-planner.mjs +33 -33
  146. package/scripts/smoke/v143-remote-control.mjs +76 -76
  147. package/scripts/smoke/v144-production-loop.mjs +47 -47
  148. package/scripts/smoke/v145-platformization.mjs +46 -46
  149. package/scripts/smoke/v146-control-room-ui.mjs +150 -150
  150. package/scripts/smoke/version-modal-autoshow.mjs +29 -29
  151. package/scripts/smoke/vscode-workbench-layout.mjs +63 -63
  152. package/scripts/smoke/vscode-workbench-polish.mjs +461 -436
  153. package/scripts/smoke/workflow-fallback-replay.mjs +56 -56
  154. package/scripts/smoke/workflow-templates.mjs +43 -43
  155. package/scripts/smoke/workflow-trace-timeline.mjs +46 -46
  156. package/scripts/update-git-install.mjs +293 -293
  157. package/server/claude-sdk.js +920 -920
  158. package/server/cli.js +1039 -1039
  159. package/server/constants/config.js +4 -4
  160. package/server/cursor-cli.js +344 -344
  161. package/server/daemon/manager.js +563 -563
  162. package/server/daemon-manager.js +964 -964
  163. package/server/database/db.js +921 -921
  164. package/server/database/json-store.js +197 -197
  165. package/server/gemini-cli.js +550 -550
  166. package/server/gemini-response-handler.js +79 -79
  167. package/server/index.js +131 -3
  168. package/server/load-env.js +35 -35
  169. package/server/middleware/auth.js +175 -175
  170. package/server/modules/orchestration/a2a/adapter-registry.ts +108 -108
  171. package/server/modules/orchestration/a2a/adapters/abstract-a2a.adapter.ts +63 -63
  172. package/server/modules/orchestration/a2a/adapters/claude-code.adapter.ts +286 -286
  173. package/server/modules/orchestration/a2a/adapters/codex.adapter.ts +244 -244
  174. package/server/modules/orchestration/a2a/adapters/cursor.adapter.ts +249 -249
  175. package/server/modules/orchestration/a2a/adapters/gemini.adapter.ts +248 -248
  176. package/server/modules/orchestration/a2a/adapters/json-event.adapter.test.ts +60 -0
  177. package/server/modules/orchestration/a2a/adapters/json-event.adapter.ts +101 -0
  178. package/server/modules/orchestration/a2a/adapters/opencode.adapter.ts +248 -248
  179. package/server/modules/orchestration/a2a/adapters/qwen.adapter.ts +248 -248
  180. package/server/modules/orchestration/a2a/agent-card.ts +55 -55
  181. package/server/modules/orchestration/a2a/routes.ts +590 -590
  182. package/server/modules/orchestration/a2a/task-store.ts +178 -178
  183. package/server/modules/orchestration/a2a/types.ts +126 -126
  184. package/server/modules/orchestration/a2a/validator.ts +113 -113
  185. package/server/modules/orchestration/hermes/hermes.routes.ts +642 -583
  186. package/server/modules/orchestration/index.ts +101 -100
  187. package/server/modules/orchestration/preview/port-watcher.ts +112 -112
  188. package/server/modules/orchestration/preview/preview-proxy.ts +60 -60
  189. package/server/modules/orchestration/preview/types.ts +19 -19
  190. package/server/modules/orchestration/security/permission-policy.ts +401 -401
  191. package/server/modules/orchestration/tasks/orchestration-task-store.ts +41 -41
  192. package/server/modules/orchestration/tasks/orchestration-task.routes.ts +64 -64
  193. package/server/modules/orchestration/tasks/orchestration-task.service.ts +209 -209
  194. package/server/modules/orchestration/tasks/orchestration-task.types.ts +40 -40
  195. package/server/modules/orchestration/tasks/task-run-graph.ts +155 -155
  196. package/server/modules/orchestration/workflows/approval-queue.ts +106 -106
  197. package/server/modules/orchestration/workflows/built-in-workflows.ts +127 -127
  198. package/server/modules/orchestration/workflows/context-packet.ts +186 -186
  199. package/server/modules/orchestration/workflows/handoff-artifact.ts +175 -175
  200. package/server/modules/orchestration/workflows/workflow-fallback-policy.ts +161 -161
  201. package/server/modules/orchestration/workflows/workflow-replay.ts +254 -254
  202. package/server/modules/orchestration/workflows/workflow-runner.ts +2070 -2070
  203. package/server/modules/orchestration/workflows/workflow-store.ts +97 -97
  204. package/server/modules/orchestration/workflows/workflow-templates.ts +272 -272
  205. package/server/modules/orchestration/workflows/workflow-trace.ts +424 -424
  206. package/server/modules/orchestration/workflows/workflow.routes.ts +586 -586
  207. package/server/modules/orchestration/workflows/workflow.types.ts +111 -111
  208. package/server/modules/orchestration/workflows/workspace-target.ts +122 -122
  209. package/server/modules/orchestration/workspace/docker-workspace.ts +136 -136
  210. package/server/modules/orchestration/workspace/path-safety.ts +55 -55
  211. package/server/modules/orchestration/workspace/types.ts +52 -52
  212. package/server/modules/orchestration/workspace/workspace-manager.ts +102 -102
  213. package/server/modules/orchestration/workspace/worktree-workspace.ts +126 -126
  214. package/server/modules/providers/index.ts +2 -2
  215. package/server/modules/providers/list/claude/claude-auth.provider.ts +146 -146
  216. package/server/modules/providers/list/claude/claude-mcp.provider.ts +135 -135
  217. package/server/modules/providers/list/claude/claude-sessions.provider.ts +306 -306
  218. package/server/modules/providers/list/claude/claude.provider.ts +15 -15
  219. package/server/modules/providers/list/codex/codex-auth.provider.ts +117 -117
  220. package/server/modules/providers/list/codex/codex-mcp.provider.ts +135 -135
  221. package/server/modules/providers/list/codex/codex-sessions.provider.ts +319 -319
  222. package/server/modules/providers/list/codex/codex.provider.ts +15 -15
  223. package/server/modules/providers/list/cursor/cursor-auth.provider.ts +147 -147
  224. package/server/modules/providers/list/cursor/cursor-mcp.provider.ts +108 -108
  225. package/server/modules/providers/list/cursor/cursor-sessions.provider.ts +421 -421
  226. package/server/modules/providers/list/cursor/cursor.provider.ts +15 -15
  227. package/server/modules/providers/list/gemini/gemini-auth.provider.ts +173 -173
  228. package/server/modules/providers/list/gemini/gemini-mcp.provider.ts +110 -110
  229. package/server/modules/providers/list/gemini/gemini-sessions.provider.ts +227 -227
  230. package/server/modules/providers/list/gemini/gemini.provider.ts +15 -15
  231. package/server/modules/providers/list/opencode/opencode-auth.provider.ts +131 -131
  232. package/server/modules/providers/list/opencode/opencode-mcp.provider.ts +126 -126
  233. package/server/modules/providers/list/opencode/opencode-sessions.provider.ts +286 -286
  234. package/server/modules/providers/list/opencode/opencode.provider.ts +29 -29
  235. package/server/modules/providers/list/qwen/qwen-auth.provider.ts +146 -146
  236. package/server/modules/providers/list/qwen/qwen-mcp.provider.ts +114 -114
  237. package/server/modules/providers/list/qwen/qwen-sessions.provider.ts +265 -265
  238. package/server/modules/providers/list/qwen/qwen.provider.ts +21 -21
  239. package/server/modules/providers/provider.registry.ts +40 -40
  240. package/server/modules/providers/provider.routes.ts +944 -944
  241. package/server/modules/providers/services/mcp.service.ts +86 -86
  242. package/server/modules/providers/services/provider-auth.service.ts +26 -26
  243. package/server/modules/providers/services/sessions.service.ts +45 -45
  244. package/server/modules/providers/shared/base/abstract.provider.ts +20 -20
  245. package/server/modules/providers/shared/mcp/mcp.provider.ts +151 -151
  246. package/server/modules/providers/shared/provider-configs.ts +142 -142
  247. package/server/modules/providers/tests/mcp.test.ts +293 -293
  248. package/server/openai-codex.js +462 -462
  249. package/server/opencode-cli.js +491 -491
  250. package/server/opencode-response-handler.js +111 -111
  251. package/server/projects.js +3008 -3008
  252. package/server/qwen-code-cli.js +410 -410
  253. package/server/qwen-response-handler.js +73 -73
  254. package/server/routes/agent.js +1435 -1435
  255. package/server/routes/auth.js +159 -159
  256. package/server/routes/codex.js +20 -20
  257. package/server/routes/commands.js +570 -570
  258. package/server/routes/cursor.js +61 -61
  259. package/server/routes/diagnostics.js +41 -41
  260. package/server/routes/gemini.js +25 -25
  261. package/server/routes/git.js +1650 -1650
  262. package/server/routes/live-view.js +411 -411
  263. package/server/routes/mcp-utils.js +13 -13
  264. package/server/routes/messages.js +62 -62
  265. package/server/routes/network.js +125 -125
  266. package/server/routes/platformization.js +212 -212
  267. package/server/routes/plugins.js +320 -320
  268. package/server/routes/production-agent-loop.js +90 -90
  269. package/server/routes/projects.js +917 -917
  270. package/server/routes/public-api.js +34 -34
  271. package/server/routes/qwen.js +27 -27
  272. package/server/routes/remote.js +55 -55
  273. package/server/routes/settings.js +321 -321
  274. package/server/routes/telegram.js +140 -140
  275. package/server/routes/user.js +125 -125
  276. package/server/routes/webhooks.js +63 -63
  277. package/server/services/control-room.js +102 -102
  278. package/server/services/diagnostics.js +165 -165
  279. package/server/services/external-access.js +375 -375
  280. package/server/services/hermes-gateway.js +1562 -1247
  281. package/server/services/hermes-install-jobs.js +729 -729
  282. package/server/services/install-jobs.js +715 -715
  283. package/server/services/live-view.js +956 -956
  284. package/server/services/managed-runtimes.js +493 -493
  285. package/server/services/model-registry.js +144 -144
  286. package/server/services/notification-orchestrator.js +365 -365
  287. package/server/services/notification-taxonomy.js +204 -204
  288. package/server/services/platformization.js +815 -815
  289. package/server/services/production-agent-loop.js +248 -248
  290. package/server/services/provider-cli-versions.js +149 -149
  291. package/server/services/provider-credentials.js +189 -189
  292. package/server/services/provider-models.js +396 -396
  293. package/server/services/public-api-manifest.js +190 -182
  294. package/server/services/remote-connection.js +127 -127
  295. package/server/services/runtime-manager.js +323 -323
  296. package/server/services/startup-update.js +234 -234
  297. package/server/services/telegram/bot.js +331 -331
  298. package/server/services/telegram/control-center.js +979 -979
  299. package/server/services/telegram/telegram-http-client.js +151 -151
  300. package/server/services/telegram/translations.js +340 -340
  301. package/server/services/vapid-keys.js +36 -36
  302. package/server/services/webhooks.js +216 -216
  303. package/server/sessionManager.js +225 -225
  304. package/server/shared/interfaces.ts +54 -54
  305. package/server/shared/types.ts +172 -172
  306. package/server/shared/utils.ts +193 -193
  307. package/server/tsconfig.json +36 -36
  308. package/server/utils/colors.js +21 -21
  309. package/server/utils/commandParser.js +305 -305
  310. package/server/utils/frontmatter.js +18 -18
  311. package/server/utils/gitConfig.js +34 -34
  312. package/server/utils/plugin-loader.js +457 -457
  313. package/server/utils/plugin-process-manager.js +185 -185
  314. package/server/utils/port-access.js +209 -209
  315. package/server/utils/runtime-paths.js +37 -37
  316. package/server/utils/url-detection.js +71 -71
  317. package/server/vite-daemon.js +79 -79
  318. package/shared/modelConstants.js +161 -161
  319. package/shared/networkHosts.js +22 -22
  320. package/dist/assets/index-DMz0zv6T.css +0 -32
@@ -1,958 +1,1009 @@
1
- #!/usr/bin/env node
2
- import path from 'node:path';
3
- import readline from 'node:readline';
4
- import { fileURLToPath } from 'node:url';
5
-
6
- const baseUrl = (process.env.PIXCODE_BASE_URL || '').replace(/\/$/, '');
7
- const apiKey = process.env.PIXCODE_API_KEY || '';
8
- const appRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..', '..');
9
- const mcpServerPath = path.join(appRoot, 'scripts', 'hermes', 'pixcode-mcp-server.mjs');
10
- const READBACK_IDLE_STABLE_MS = Math.max(
11
- 1000,
12
- Number.parseInt(process.env.PIXCODE_MCP_READBACK_IDLE_STABLE_MS || '8000', 10) || 8000,
13
- );
14
- const DEFAULT_STARTUP_WAIT_MS = 100000;
15
- const ALLOWED_PIXCODE_API_METHODS = new Set(['GET', 'POST', 'PUT', 'PATCH', 'DELETE']);
16
-
17
- const tools = [
18
- {
19
- name: 'pixcode_list_projects',
20
- description: 'List Pixcode workspaces/projects visible to this user, including display name, path, and file count when available.',
21
- inputSchema: {
22
- type: 'object',
23
- properties: {},
24
- additionalProperties: false,
25
- },
26
- },
27
- {
28
- name: 'pixcode_get_provider_status',
29
- description: 'Get install/auth/version status for one Pixcode CLI provider before launching it inside Pixcode.',
30
- inputSchema: {
31
- type: 'object',
32
- properties: {
33
- provider: {
34
- type: 'string',
35
- enum: ['claude', 'codex', 'cursor', 'gemini', 'qwen', 'opencode'],
36
- },
37
- },
38
- required: ['provider'],
39
- additionalProperties: false,
40
- },
41
- },
42
- {
43
- name: 'pixcode_open_cli_terminal',
44
- description: 'Use this instead of Hermes shell/proc/skill execution whenever the user asks to open Codex, Claude, Cursor, Gemini, Qwen, or OpenCode inside Pixcode. It asks the open Pixcode workbench to continue the existing visible provider terminal in the project and submit startup input there. Do not run a parallel Hermes codex/claude/proc command for the same request. Do not request a fresh session unless the user explicitly asks for a new session. For multi-step, piece-by-piece, or long-running work, put the full user instruction in startupInput so the provider CLI does the work visibly inside Pixcode. When startupInput is present, Pixcode waits for the terminal to become idle before returning readback by default; never treat the first working frame as final output.',
45
- inputSchema: {
46
- type: 'object',
47
- properties: {
48
- provider: {
49
- type: 'string',
50
- enum: ['claude', 'codex', 'cursor', 'gemini', 'qwen', 'opencode'],
51
- },
52
- projectPath: {
53
- type: 'string',
54
- description: 'Absolute project path. Omit to use the currently selected Pixcode project.',
55
- },
56
- prompt: {
57
- type: 'string',
58
- description: 'Optional audit/reason text for Pixcode. This is not typed into the provider CLI.',
59
- },
60
- startupInput: {
61
- type: 'string',
62
- description: 'Exact startup input typed into the provider CLI after the TUI is ready. Use this for commands like /init, hello prompts, or full multi-step task instructions the user asked to run visibly.',
63
- },
64
- forceNewSession: {
65
- type: 'boolean',
66
- description: 'Start a fresh visible provider CLI session only when the user explicitly asks for a new session. Omit or false to continue the existing visible provider terminal.',
67
- },
68
- bypassPermissions: {
69
- type: 'boolean',
70
- description: 'When true, Pixcode starts the provider CLI with its strongest no-approval/bypass flags where supported. Defaults to true for Hermes-launched visible task work.',
71
- },
72
- permissionMode: {
73
- type: 'string',
74
- enum: ['default', 'bypassPermissions', 'acceptEdits', 'yolo', 'auto_edit', 'plan'],
75
- description: 'Optional provider permission mode. Omit to use bypassPermissions when bypassPermissions is not false.',
76
- },
77
- waitForOutputMs: {
78
- type: 'number',
79
- description: 'Optional milliseconds to wait for recent terminal output. Pixcode keeps polling while terminalState is busy, so use a large value when the user asks for the final provider answer.',
80
- },
81
- waitForCompletionMs: {
82
- type: 'number',
83
- description: 'Optional explicit milliseconds to wait for the visible provider CLI to return to an idle prompt before reporting output. Overrides waitForOutputMs.',
84
- },
85
- launchId: {
86
- type: 'number',
87
- description: 'Optional Pixcode terminal launch id. Use the id returned by pixcode_open_cli_terminal when reading one specific visible terminal.',
88
- },
89
- },
90
- required: ['provider'],
91
- additionalProperties: false,
92
- },
93
- },
94
- {
95
- name: 'pixcode_read_cli_terminal',
96
- description: 'Read recent visible Pixcode provider CLI terminal output for a project. Use after pixcode_open_cli_terminal when the user asks what Codex/Claude/Gemini/Qwen/OpenCode printed.',
97
- inputSchema: {
98
- type: 'object',
99
- properties: {
100
- provider: {
101
- type: 'string',
102
- enum: ['claude', 'codex', 'cursor', 'gemini', 'qwen', 'opencode'],
103
- },
104
- projectPath: {
105
- type: 'string',
106
- description: 'Absolute project path. Omit to use the currently selected Pixcode project.',
107
- },
108
- maxChars: {
109
- type: 'number',
110
- description: 'Maximum transcript characters to return, capped by Pixcode.',
111
- },
112
- },
113
- required: ['provider'],
114
- additionalProperties: false,
115
- },
116
- },
117
- {
118
- name: 'pixcode_get_hermes_gateway_status',
119
- description: 'Read Pixcode-managed Hermes REST gateway status, including base URL, running state, and the last probe result.',
120
- inputSchema: {
121
- type: 'object',
122
- properties: {
123
- projectPath: {
124
- type: 'string',
125
- description: 'Absolute project path. Omit to inspect all managed Hermes gateways.',
126
- },
127
- },
128
- additionalProperties: false,
129
- },
130
- },
131
- {
132
- name: 'pixcode_probe_hermes_gateway',
133
- description: 'Ask Pixcode to call Hermes Agent REST endpoints and report whether health, capabilities, model discovery, and an optional real prompt respond.',
134
- inputSchema: {
135
- type: 'object',
136
- properties: {
137
- projectPath: {
138
- type: 'string',
139
- description: 'Absolute project path. Omit to probe the first running managed Hermes gateway.',
140
- },
141
- input: {
142
- type: 'string',
143
- description: 'Optional prompt to submit to Hermes /v1/runs after the lightweight REST checks pass.',
144
- },
145
- startIfNeeded: {
146
- type: 'boolean',
147
- description: 'When true, Pixcode starts the managed Hermes gateway before probing.',
148
- },
149
- },
150
- additionalProperties: false,
151
- },
152
- },
153
- {
154
- name: 'pixcode_get_hermes_diagnostics',
155
- description: 'Read Pixcode Hermes integration diagnostics: installed command, active model/provider, Hermes toolsets, Pixcode MCP tool registration, REST gateway status, cron API state, and redacted recent error signals.',
156
- inputSchema: {
157
- type: 'object',
158
- properties: {
159
- projectPath: {
160
- type: 'string',
161
- description: 'Absolute project path. Omit to diagnose the first running managed Hermes gateway and default Hermes profile.',
162
- },
163
- },
164
- additionalProperties: false,
165
- },
166
- },
167
- {
168
- name: 'pixcode_get_api_manifest',
169
- description: 'Read Pixcode public API documentation manifest. Use this to discover controllable Pixcode API groups, paths, and scopes before calling pixcode_api_request.',
170
- inputSchema: {
171
- type: 'object',
172
- properties: {},
173
- additionalProperties: false,
174
- },
175
- },
176
- {
177
- name: 'pixcode_api_request',
178
- description: 'Call the authenticated local Pixcode REST API. Use this for full Pixcode control after reading pixcode_get_api_manifest. Path must be a local /api/... path or /health; never pass an external URL.',
179
- inputSchema: {
180
- type: 'object',
181
- properties: {
182
- method: {
183
- type: 'string',
184
- enum: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE'],
185
- description: 'HTTP method to use.',
186
- },
187
- path: {
188
- type: 'string',
189
- description: 'Local Pixcode path, for example /api/projects, /api/providers/codex/auth/status?refresh=1, or /api/remote/config.',
190
- },
191
- body: {
192
- type: 'object',
193
- description: 'Optional JSON body for POST, PUT, PATCH, or DELETE requests.',
194
- additionalProperties: true,
195
- },
196
- },
197
- required: ['method', 'path'],
198
- additionalProperties: false,
199
- },
200
- },
201
- {
202
- name: 'pixcode_hermes_gateway_request',
203
- description: 'Call the Pixcode-managed Hermes REST gateway for advanced Hermes features such as /v1/runs, /v1/responses, /api/jobs cron management, /v1/capabilities, and /health. Use startIfNeeded when the gateway is not already running.',
204
- inputSchema: {
205
- type: 'object',
206
- properties: {
207
- method: {
208
- type: 'string',
209
- enum: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE'],
210
- },
211
- endpoint: {
212
- type: 'string',
213
- description: 'Hermes gateway endpoint, for example /api/jobs, /api/jobs/<id>/run, /v1/capabilities, or /v1/responses.',
214
- },
215
- body: {
216
- type: 'object',
217
- additionalProperties: true,
218
- },
219
- projectPath: {
220
- type: 'string',
221
- description: 'Absolute project path for the managed Hermes gateway.',
222
- },
223
- startIfNeeded: {
224
- type: 'boolean',
225
- description: 'Start the managed Hermes gateway first when it is not already running.',
226
- },
227
- },
228
- required: ['method', 'endpoint'],
229
- additionalProperties: false,
230
- },
231
- },
232
- {
233
- name: 'pixcode_manage_hermes_cron',
234
- description: 'Create, list, update, pause, resume, run, or delete Hermes cron jobs through the Pixcode-managed Hermes REST gateway. Cron jobs can run in a project workdir and use Hermes skills/toolsets.',
235
- inputSchema: {
236
- type: 'object',
237
- properties: {
238
- action: {
239
- type: 'string',
240
- enum: ['list', 'create', 'get', 'update', 'delete', 'pause', 'resume', 'run'],
241
- },
242
- jobId: {
243
- type: 'string',
244
- description: 'Required for get, update, delete, pause, resume, and run.',
245
- },
246
- projectPath: {
247
- type: 'string',
248
- description: 'Absolute project path for the managed Hermes gateway and default cron workdir.',
249
- },
250
- name: { type: 'string' },
251
- schedule: { type: 'string' },
252
- prompt: { type: 'string' },
253
- workdir: { type: 'string' },
254
- skills: {
255
- type: 'array',
256
- items: { type: 'string' },
257
- },
258
- delivery: { type: 'string' },
259
- startIfNeeded: { type: 'boolean' },
260
- },
261
- required: ['action'],
262
- additionalProperties: false,
263
- },
264
- },
265
- {
266
- name: 'pixcode_send_cli_input',
267
- description: 'Send text or an Enter key directly to an existing visible Pixcode provider terminal. Use this when a terminal is already open and the user asks Hermes to continue that exact visible session.',
268
- inputSchema: {
269
- type: 'object',
270
- properties: {
271
- provider: {
272
- type: 'string',
273
- enum: ['claude', 'codex', 'cursor', 'gemini', 'qwen', 'opencode'],
274
- },
275
- projectPath: {
276
- type: 'string',
277
- description: 'Absolute project path. Omit to use the newest visible terminal for the provider.',
278
- },
279
- input: {
280
- type: 'string',
281
- description: 'Text to type. May be empty when submit=true to press Enter on already typed input.',
282
- },
283
- submit: {
284
- type: 'boolean',
285
- description: 'Append Enter after input. Defaults to true.',
286
- },
287
- launchId: {
288
- type: 'number',
289
- description: 'Optional Pixcode terminal launch id to target one visible terminal.',
290
- },
291
- },
292
- required: ['provider'],
293
- additionalProperties: false,
294
- },
295
- },
296
- ];
297
-
298
- function send(payload) {
299
- process.stdout.write(`${JSON.stringify(payload)}\n`);
300
- }
301
-
302
- function textResult(text) {
303
- return {
304
- content: [
305
- {
306
- type: 'text',
307
- text,
308
- },
309
- ],
310
- };
311
- }
312
-
313
- function sleep(ms) {
314
- return new Promise((resolve) => setTimeout(resolve, ms));
315
- }
316
-
317
- async function pixcodeFetch(endpoint, options = {}) {
318
- if (!baseUrl || !apiKey) {
319
- throw new Error('Pixcode MCP is missing PIXCODE_BASE_URL or PIXCODE_API_KEY.');
320
- }
321
-
322
- const response = await fetch(`${baseUrl}${endpoint}`, {
323
- ...options,
324
- headers: {
325
- Authorization: `Bearer ${apiKey}`,
326
- 'Content-Type': 'application/json',
327
- ...(options.headers || {}),
328
- },
329
- });
330
- const text = await response.text();
331
- let body = null;
332
- try {
333
- body = text ? JSON.parse(text) : null;
334
- } catch {
335
- body = text;
336
- }
337
-
338
- if (!response.ok) {
339
- throw new Error(`Pixcode API ${endpoint} failed with HTTP ${response.status}: ${typeof body === 'string' ? body : JSON.stringify(body)}`);
340
- }
341
-
342
- return body;
343
- }
344
-
345
- function normalizeLocalPixcodePath(pathValue) {
346
- const endpoint = typeof pathValue === 'string' ? pathValue.trim() : '';
347
- if (!endpoint) {
348
- throw new Error('Pixcode API path is required.');
349
- }
350
- if (/^[a-z][a-z0-9+.-]*:\/\//iu.test(endpoint) || endpoint.startsWith('//')) {
351
- throw new Error('Pixcode API path must be local; external URLs are not allowed.');
352
- }
353
- if (endpoint !== '/health' && !endpoint.startsWith('/api/')) {
354
- throw new Error('Pixcode API path must start with /api/ or be /health.');
355
- }
356
- return endpoint;
357
- }
358
-
359
- function normalizeHermesGatewayEndpoint(endpointValue) {
360
- const endpoint = typeof endpointValue === 'string' ? endpointValue.trim() : '';
361
- if (!endpoint) {
362
- throw new Error('Hermes gateway endpoint is required.');
363
- }
364
- if (/^[a-z][a-z0-9+.-]*:\/\//iu.test(endpoint) || endpoint.startsWith('//')) {
365
- throw new Error('Hermes gateway endpoint must be local; external URLs are not allowed.');
366
- }
367
- if (!endpoint.startsWith('/')) {
368
- throw new Error('Hermes gateway endpoint must start with /.');
369
- }
370
- if (
371
- endpoint !== '/health' &&
372
- endpoint !== '/health/detailed' &&
373
- !endpoint.startsWith('/v1/') &&
374
- !endpoint.startsWith('/api/')
375
- ) {
376
- throw new Error('Hermes gateway endpoint must be /health, /v1/..., or /api/....');
377
- }
378
- return endpoint;
379
- }
380
-
381
- function normalizeHttpMethod(methodValue) {
382
- const method = String(methodValue || 'GET').trim().toUpperCase();
383
- if (!ALLOWED_PIXCODE_API_METHODS.has(method)) {
384
- throw new Error(`Unsupported HTTP method: ${method || '(empty)'}`);
385
- }
386
- return method;
387
- }
388
-
389
- async function pixcodeJsonRequest(pathValue, { method = 'GET', body } = {}) {
390
- const endpoint = normalizeLocalPixcodePath(pathValue);
391
- const normalizedMethod = normalizeHttpMethod(method);
392
- const requestOptions = { method: normalizedMethod };
393
- if (typeof body !== 'undefined' && normalizedMethod !== 'GET') {
394
- requestOptions.body = JSON.stringify(body);
395
- }
396
- return pixcodeFetch(endpoint, requestOptions);
397
- }
398
-
399
- async function sendProviderTerminalInput(provider, projectPath, input, submit = true, launchId = null) {
400
- return pixcodeFetch('/api/shell/sessions/provider-input', {
401
- method: 'POST',
402
- body: JSON.stringify({
403
- provider,
404
- projectPath: projectPath || null,
405
- input: typeof input === 'string' ? input : '',
406
- submit: submit !== false,
407
- launchId: Number(launchId || 0) || null,
408
- }),
409
- });
410
- }
411
-
412
- async function readProviderStatus(provider) {
413
- const body = await pixcodeFetch(`/api/providers/${encodeURIComponent(provider)}/auth/status?refresh=1`);
414
- return body?.data ?? body;
415
- }
416
-
417
- async function readProviderTerminalOutput(provider, projectPath, maxChars, launchId = null) {
418
- const params = new URLSearchParams({
419
- provider,
420
- maxChars: String(maxChars || 12000),
421
- });
422
- if (projectPath) params.set('projectPath', projectPath);
423
- if (launchId) params.set('launchId', String(launchId));
424
- return pixcodeFetch(`/api/shell/sessions/provider-output?${params.toString()}`);
425
- }
426
-
427
- function getLastMatchIndex(text, pattern) {
428
- let lastIndex = -1;
429
- for (const match of text.matchAll(pattern)) {
430
- lastIndex = match.index ?? lastIndex;
431
- }
432
- return lastIndex;
433
- }
434
-
435
- function inferTerminalState(provider, terminalOutput) {
436
- if (!terminalOutput) return 'unknown';
437
- if (typeof terminalOutput.terminalState === 'string') return terminalOutput.terminalState;
438
- if (typeof terminalOutput.isBusy === 'boolean') return terminalOutput.isBusy ? 'busy' : 'idle';
439
- if (terminalOutput.active === false) return terminalOutput.output ? 'idle' : 'unknown';
440
-
441
- const output = String(terminalOutput.output || '');
442
- if (!output.trim()) return 'unknown';
443
- if (/Process exited with code/iu.test(output)) return 'idle';
444
-
445
- const lastWeakBusy = getLastMatchIndex(output, /(?:^|\n)\s*[•*]\s*(?:Working|Running|Thinking)\b/giu);
446
- const lastStrongBusy = Math.max(
447
- getLastMatchIndex(output, /\bWorking\s*\([^)]*esc to interrupt[^)]*\)/giu),
448
- getLastMatchIndex(output, /\bmsg=interrupt\b/giu),
449
- );
450
- const lastBusy = Math.max(lastWeakBusy, lastStrongBusy);
451
-
452
- if (provider === 'codex') {
453
- const lastPrompt = Math.max(
454
- getLastMatchIndex(output, /(?:^|\n)\s*›(?:\s|$)/gu),
455
- getLastMatchIndex(output, /(?:^|\n)\s*❯(?:\s|$)/gu),
456
- );
457
- if (lastPrompt >= 0) return lastStrongBusy > lastPrompt ? 'busy' : 'idle';
458
- if (lastBusy >= 0) return 'busy';
459
- return 'unknown';
460
- }
461
-
462
- if (lastBusy >= 0) return 'busy';
463
- return 'unknown';
464
- }
465
-
466
- function isTerminalReadbackFinal(provider, terminalOutput) {
467
- const terminalState = inferTerminalState(provider, terminalOutput);
468
- return terminalState === 'idle' || terminalState === 'completed' || terminalState === 'exited' || terminalState === 'failed';
469
- }
470
-
471
- function isTerminalReadbackHardFinal(provider, terminalOutput) {
472
- const terminalState = inferTerminalState(provider, terminalOutput);
473
- return terminalState === 'completed' || terminalState === 'exited' || terminalState === 'failed' || Boolean(terminalOutput?.terminalFailed);
474
- }
475
-
476
- function getReadbackFingerprint(terminalOutput) {
477
- return [
478
- terminalOutput?.terminalState || '',
479
- terminalOutput?.lifecycleState || '',
480
- terminalOutput?.exitCode ?? '',
481
- terminalOutput?.exitSignal || '',
482
- String(terminalOutput?.output || '').slice(-12000),
483
- ].join('\n---pixcode-readback---\n');
484
- }
485
-
486
- function outputHasProviderPrompt(provider, output) {
487
- const text = String(output || '');
488
- if (provider === 'codex') {
489
- return /(?:^|\n)\s*[›❯]\s*$/u.test(text) || /(?:^|\n)\s*›\s+[^\n]*$/u.test(text);
490
- }
491
- return /(?:^|\n).{0,80}(?:>\s*|❯\s*)$/u.test(text);
492
- }
493
-
494
- function startupInputLooksStuckAtPrompt(provider, terminalOutput, startupInput) {
495
- if (!startupInput || !terminalOutput?.output || terminalOutput.isBusy) return false;
496
- const output = String(terminalOutput.output || '');
497
- const escapedInput = startupInput.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
498
- if (provider === 'codex') {
499
- return new RegExp(`(?:^|\\n)\\s*[›❯]\\s*${escapedInput}\\s*$`, 'u').test(output);
500
- }
501
- return output.endsWith(startupInput) || outputHasProviderPrompt(provider, output);
502
- }
503
-
504
- async function recoverStuckStartupInput(provider, projectPath, startupInput, terminalOutput, launchId = null) {
505
- if (!startupInputLooksStuckAtPrompt(provider, terminalOutput, startupInput)) {
506
- return null;
507
- }
508
-
509
- const output = String(terminalOutput?.output || '');
510
- const inputAlreadyVisible = output.includes(startupInput);
511
- return sendProviderTerminalInput(
512
- provider,
513
- projectPath,
514
- inputAlreadyVisible ? '' : startupInput,
515
- true,
516
- launchId,
517
- );
518
- }
519
-
520
- async function waitForProviderTerminalOutput(provider, projectPath, waitMs, launchId = null) {
521
- const startedAt = Date.now();
522
- let latestOutput = null;
523
- let stableFingerprint = null;
524
- let stableSince = 0;
525
- let stableFinal = false;
526
- do {
527
- const elapsed = Date.now() - startedAt;
528
- const remaining = Math.max(0, waitMs - elapsed);
529
- await sleep(Math.min(1000, Math.max(250, remaining)));
530
- latestOutput = await readProviderTerminalOutput(provider, projectPath, 12000, launchId).catch((error) => ({
531
- active: false,
532
- terminalState: 'unknown',
533
- error: error instanceof Error ? error.message : String(error),
534
- }));
535
-
536
- if (latestOutput?.output && isTerminalReadbackFinal(provider, latestOutput)) {
537
- if (isTerminalReadbackHardFinal(provider, latestOutput)) {
538
- stableFinal = true;
539
- break;
540
- }
541
-
542
- const fingerprint = getReadbackFingerprint(latestOutput);
543
- if (fingerprint !== stableFingerprint) {
544
- stableFingerprint = fingerprint;
545
- stableSince = Date.now();
546
- }
547
- if (Date.now() - stableSince >= READBACK_IDLE_STABLE_MS) {
548
- stableFinal = true;
549
- break;
550
- }
551
- } else {
552
- stableFingerprint = null;
553
- stableSince = 0;
554
- }
555
- } while (Date.now() - startedAt < waitMs);
556
-
557
- if (latestOutput && !latestOutput.terminalState) {
558
- latestOutput.terminalState = inferTerminalState(provider, latestOutput);
559
- }
560
- if (latestOutput && typeof latestOutput.isBusy !== 'boolean') {
561
- latestOutput.isBusy = latestOutput.terminalState === 'busy';
562
- }
563
- if (latestOutput) {
564
- latestOutput.readbackStable = stableFinal;
565
- latestOutput.terminalOutputFinal = stableFinal;
566
- }
567
- return latestOutput;
568
- }
569
-
570
- function isLegacyPromptLikelyStartupInput(prompt) {
571
- if (!prompt || prompt.length > 160 || prompt.includes('\n')) return false;
572
- if (/^[/:!@]/u.test(prompt)) return true;
573
- if (prompt.includes(':')) return false;
574
- 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)) {
575
- return false;
576
- }
577
- return prompt.length <= 80;
578
- }
579
-
580
- async function upsertProviderPixcodeMcp(provider, projectPath, scope) {
581
- const body = await pixcodeFetch(`/api/providers/${encodeURIComponent(provider)}/mcp/servers`, {
582
- method: 'POST',
583
- body: JSON.stringify({
584
- name: 'pixcode',
585
- transport: 'stdio',
586
- scope,
587
- workspacePath: projectPath || process.cwd(),
588
- command: process.execPath,
589
- args: [mcpServerPath],
590
- env: {
591
- PIXCODE_BASE_URL: baseUrl,
592
- PIXCODE_API_KEY: apiKey,
593
- },
594
- }),
595
- });
596
- return body?.data?.server ?? body?.server ?? body;
597
- }
598
-
599
- async function ensureProviderPixcodeMcp(provider, projectPath) {
600
- try {
601
- const server = await upsertProviderPixcodeMcp(provider, projectPath, 'project');
602
- return { scope: 'project', server, projectScopeError: null };
603
- } catch (error) {
604
- const projectScopeError = error instanceof Error ? error.message : String(error);
605
- try {
606
- const server = await upsertProviderPixcodeMcp(provider, projectPath, 'user');
607
- return { scope: 'user', server, projectScopeError };
608
- } catch (fallbackError) {
609
- const userScopeError = fallbackError instanceof Error ? fallbackError.message : String(fallbackError);
610
- throw new Error(`Pixcode MCP auto-config failed for project scope (${projectScopeError}) and user scope (${userScopeError})`);
611
- }
612
- }
613
- }
614
-
615
- async function callTool(name, args = {}) {
616
- if (name === 'pixcode_list_projects') {
617
- const projects = await pixcodeFetch('/api/projects');
618
- const normalized = (Array.isArray(projects) ? projects : []).map((project) => ({
619
- name: project.name,
620
- displayName: project.displayName,
621
- path: project.fullPath || project.path,
622
- fileCount: project.fileCount ?? null,
623
- }));
624
- return textResult(JSON.stringify(normalized, null, 2));
625
- }
626
-
627
- if (name === 'pixcode_get_provider_status') {
628
- const provider = String(args.provider || '');
629
- const status = await readProviderStatus(provider);
630
- return textResult(JSON.stringify(status, null, 2));
631
- }
632
-
633
- if (name === 'pixcode_open_cli_terminal') {
634
- const provider = String(args.provider || '');
635
- const projectPath = typeof args.projectPath === 'string' && args.projectPath.trim()
636
- ? args.projectPath.trim()
637
- : null;
638
- const status = await readProviderStatus(provider);
639
- if (status?.installed === false) {
640
- return textResult(JSON.stringify({
641
- launched: false,
642
- provider,
643
- reason: 'not_installed',
644
- message: `${provider} CLI is not installed. Install it in Pixcode before launching a terminal.`,
645
- status,
646
- }, null, 2));
647
- }
648
-
649
- let mcpConfigured = false;
650
- let mcpConfig = null;
651
- let mcpError = null;
652
- try {
653
- mcpConfig = await ensureProviderPixcodeMcp(provider, projectPath);
654
- mcpConfigured = true;
655
- } catch (error) {
656
- mcpError = error instanceof Error ? error.message : String(error);
657
- }
658
-
659
- const startupInput = typeof args.startupInput === 'string' && args.startupInput.trim()
660
- ? args.startupInput
661
- : (isLegacyPromptLikelyStartupInput(args.prompt) ? args.prompt.trim() : null);
662
- const bypassPermissions = args.bypassPermissions === false ? false : true;
663
- const forceNewSession = args.forceNewSession === true || args.newSession === true || args.freshSession === true;
664
- const permissionMode = typeof args.permissionMode === 'string' && args.permissionMode.trim()
665
- ? args.permissionMode.trim()
666
- : (bypassPermissions ? 'bypassPermissions' : null);
667
-
668
- const body = await pixcodeFetch('/api/orchestration/hermes/terminal-launches', {
669
- method: 'POST',
670
- body: JSON.stringify({
671
- provider,
672
- projectPath,
673
- prompt: args.prompt || null,
674
- startupInput,
675
- forceNewSession,
676
- bypassPermissions,
677
- skipPermissions: bypassPermissions,
678
- permissionMode,
679
- }),
680
- });
681
- const launchId = Number(body?.event?.id || body?.id || 0) || null;
682
- let terminalOutput = null;
683
- const defaultWaitMs = startupInput ? DEFAULT_STARTUP_WAIT_MS : 0;
684
- const requestedWaitMs = Number(args.waitForCompletionMs ?? args.waitForOutputMs ?? defaultWaitMs);
685
- const waitForOutputMs = Math.min(600000, Math.max(0, requestedWaitMs));
686
- if (waitForOutputMs > 0) {
687
- terminalOutput = await waitForProviderTerminalOutput(provider, projectPath, waitForOutputMs, launchId);
688
- if (startupInput && terminalOutput && !isTerminalReadbackFinal(provider, terminalOutput)) {
689
- const recovery = await recoverStuckStartupInput(provider, projectPath, startupInput, terminalOutput, launchId).catch((error) => ({
690
- error: error instanceof Error ? error.message : String(error),
691
- }));
692
- if (recovery) {
693
- const recoveredOutput = await waitForProviderTerminalOutput(provider, projectPath, Math.min(waitForOutputMs, 120000), launchId);
694
- terminalOutput = recoveredOutput || terminalOutput;
695
- if (terminalOutput) {
696
- terminalOutput.startupInputRecovery = recovery;
697
- }
698
- }
699
- }
700
- }
701
- const terminalOutputFinal = terminalOutput
702
- ? Boolean(terminalOutput.terminalOutputFinal ?? isTerminalReadbackFinal(provider, terminalOutput))
703
- : false;
704
- return textResult(JSON.stringify({
705
- launched: true,
706
- launchId,
707
- pixcodeMcpConfigured: mcpConfigured,
708
- pixcodeMcpScope: mcpConfig?.scope ?? null,
709
- pixcodeMcpProjectScopeError: mcpConfig?.projectScopeError ?? null,
710
- pixcodeMcpError: mcpError,
711
- event: body?.event ?? body,
712
- permissionBypass: bypassPermissions,
713
- status,
714
- terminalOutputFinal,
715
- terminalFailed: Boolean(terminalOutput?.terminalFailed),
716
- message: terminalOutput && !terminalOutputFinal
717
- ? 'Provider terminal is still running or not at an idle prompt yet. Do not summarize this as final output; call pixcode_read_cli_terminal with launchId later.'
718
- : terminalOutput?.terminalFailed
719
- ? 'Provider terminal exited with a failure. Do not report this as successful; tell the user the visible CLI failed and include the exit code/output.'
720
- : undefined,
721
- terminalOutput,
722
- }, null, 2));
723
- }
724
-
725
- if (name === 'pixcode_read_cli_terminal') {
726
- const provider = String(args.provider || '');
727
- const projectPath = typeof args.projectPath === 'string' && args.projectPath.trim()
728
- ? args.projectPath.trim()
729
- : null;
730
- const maxChars = Math.min(20000, Math.max(1000, Number(args.maxChars || 12000)));
731
- const launchId = Number(args.launchId || 0) || null;
732
- const body = await readProviderTerminalOutput(provider, projectPath, maxChars, launchId);
733
- if (body && !body.terminalState) {
734
- body.terminalState = inferTerminalState(provider, body);
735
- }
736
- if (body && typeof body.isBusy !== 'boolean') {
737
- body.isBusy = body.terminalState === 'busy';
738
- }
739
- body.terminalOutputFinal = isTerminalReadbackFinal(provider, body);
740
- body.terminalFailed = Boolean(body.terminalFailed);
741
- return textResult(JSON.stringify(body, null, 2));
742
- }
743
-
744
- if (name === 'pixcode_get_hermes_gateway_status') {
745
- const projectPath = typeof args.projectPath === 'string' && args.projectPath.trim()
746
- ? `?projectPath=${encodeURIComponent(args.projectPath.trim())}`
747
- : '';
748
- const body = await pixcodeFetch(`/api/orchestration/hermes/gateway/status${projectPath}`);
749
- return textResult(JSON.stringify(body, null, 2));
750
- }
751
-
752
- if (name === 'pixcode_probe_hermes_gateway') {
753
- const body = await pixcodeFetch('/api/orchestration/hermes/gateway/probe', {
754
- method: 'POST',
755
- body: JSON.stringify({
756
- projectPath: args.projectPath || null,
757
- input: args.input || null,
758
- startIfNeeded: args.startIfNeeded === true,
759
- }),
760
- });
761
- return textResult(JSON.stringify(body, null, 2));
762
- }
763
-
764
- if (name === 'pixcode_get_hermes_diagnostics') {
765
- const projectPath = typeof args.projectPath === 'string' && args.projectPath.trim()
766
- ? `?projectPath=${encodeURIComponent(args.projectPath.trim())}`
767
- : '';
768
- const body = await pixcodeFetch(`/api/orchestration/hermes/diagnostics${projectPath}`);
769
- return textResult(JSON.stringify(body, null, 2));
770
- }
771
-
772
- if (name === 'pixcode_get_api_manifest') {
773
- const body = await pixcodeJsonRequest('/api/public/manifest', { method: 'GET' });
774
- return textResult(JSON.stringify(body, null, 2));
775
- }
776
-
777
- if (name === 'pixcode_api_request') {
778
- const body = await pixcodeJsonRequest(args.path, {
779
- method: args.method || 'GET',
780
- body: args.body,
781
- });
782
- return textResult(JSON.stringify(body, null, 2));
783
- }
784
-
785
- if (name === 'pixcode_hermes_gateway_request') {
786
- const endpoint = normalizeHermesGatewayEndpoint(args.endpoint);
787
- const body = await pixcodeFetch('/api/orchestration/hermes/gateway/request', {
788
- method: 'POST',
789
- body: JSON.stringify({
790
- method: normalizeHttpMethod(args.method || 'GET'),
791
- endpoint,
792
- body: args.body || null,
793
- projectPath: args.projectPath || null,
794
- startIfNeeded: args.startIfNeeded === true,
795
- }),
796
- });
797
- return textResult(JSON.stringify(body, null, 2));
798
- }
799
-
800
- if (name === 'pixcode_manage_hermes_cron') {
801
- const action = String(args.action || '').trim();
802
- const jobId = typeof args.jobId === 'string' && args.jobId.trim() ? args.jobId.trim() : null;
803
- const jobBody = {
804
- name: args.name || undefined,
805
- schedule: args.schedule || undefined,
806
- prompt: args.prompt || undefined,
807
- workdir: args.workdir || args.projectPath || undefined,
808
- skills: Array.isArray(args.skills) ? args.skills : undefined,
809
- delivery: args.delivery || undefined,
810
- };
811
- Object.keys(jobBody).forEach((key) => {
812
- if (typeof jobBody[key] === 'undefined') delete jobBody[key];
813
- });
814
-
815
- let method = 'GET';
816
- let endpoint = '/api/jobs';
817
- let body = null;
818
- if (action === 'create') {
819
- method = 'POST';
820
- body = jobBody;
821
- } else if (action === 'list') {
822
- method = 'GET';
823
- } else {
824
- if (!jobId) throw new Error(`jobId is required for Hermes cron action "${action}".`);
825
- const encodedJobId = encodeURIComponent(jobId);
826
- if (action === 'get') {
827
- method = 'GET';
828
- endpoint = `/api/jobs/${encodedJobId}`;
829
- } else if (action === 'update') {
830
- method = 'PATCH';
831
- endpoint = `/api/jobs/${encodedJobId}`;
832
- body = jobBody;
833
- } else if (action === 'delete') {
834
- method = 'DELETE';
835
- endpoint = `/api/jobs/${encodedJobId}`;
836
- } else if (action === 'pause' || action === 'resume' || action === 'run') {
837
- method = 'POST';
838
- endpoint = `/api/jobs/${encodedJobId}/${action}`;
839
- } else {
840
- throw new Error(`Unsupported Hermes cron action: ${action || '(empty)'}`);
841
- }
842
- }
843
-
844
- const response = await pixcodeFetch('/api/orchestration/hermes/gateway/request', {
845
- method: 'POST',
846
- body: JSON.stringify({
847
- method,
848
- endpoint,
849
- body,
850
- projectPath: args.projectPath || args.workdir || null,
851
- startIfNeeded: args.startIfNeeded !== false,
852
- }),
853
- });
854
- return textResult(JSON.stringify(response, null, 2));
855
- }
856
-
857
- if (name === 'pixcode_send_cli_input') {
858
- const provider = String(args.provider || '');
859
- const projectPath = typeof args.projectPath === 'string' && args.projectPath.trim()
860
- ? args.projectPath.trim()
861
- : null;
862
- const body = await sendProviderTerminalInput(
863
- provider,
864
- projectPath,
865
- typeof args.input === 'string' ? args.input : '',
866
- args.submit !== false,
867
- Number(args.launchId || 0) || null,
868
- );
869
- return textResult(JSON.stringify(body, null, 2));
870
- }
871
-
872
- throw new Error(`Unknown Pixcode MCP tool: ${name}`);
873
- }
874
-
875
- async function handleMessage(message) {
876
- if (message.method === 'initialize') {
877
- send({
878
- jsonrpc: '2.0',
879
- id: message.id,
880
- result: {
881
- protocolVersion: message.params?.protocolVersion || '2024-11-05',
882
- capabilities: {
883
- tools: {},
884
- },
885
- serverInfo: {
886
- name: 'pixcode-mcp',
887
- version: '1.0.0',
888
- },
889
- },
890
- });
891
- return;
892
- }
893
-
894
- if (message.method === 'tools/list') {
895
- send({
896
- jsonrpc: '2.0',
897
- id: message.id,
898
- result: { tools },
899
- });
900
- return;
901
- }
902
-
903
- if (message.method === 'tools/call') {
904
- try {
905
- const result = await callTool(message.params?.name, message.params?.arguments || {});
906
- send({
907
- jsonrpc: '2.0',
908
- id: message.id,
909
- result,
910
- });
911
- } catch (error) {
912
- send({
913
- jsonrpc: '2.0',
914
- id: message.id,
915
- error: {
916
- code: -32000,
917
- message: error instanceof Error ? error.message : String(error),
918
- },
919
- });
920
- }
921
- return;
922
- }
923
-
924
- if (typeof message.id !== 'undefined') {
925
- send({
926
- jsonrpc: '2.0',
927
- id: message.id,
928
- error: {
929
- code: -32601,
930
- message: `Method not found: ${message.method}`,
931
- },
932
- });
933
- }
934
- }
935
-
936
- const rl = readline.createInterface({
937
- input: process.stdin,
938
- crlfDelay: Number.POSITIVE_INFINITY,
939
- });
940
-
941
- rl.on('line', (line) => {
942
- if (!line.trim()) return;
943
-
944
- void (async () => {
945
- try {
946
- await handleMessage(JSON.parse(line));
947
- } catch (error) {
948
- send({
949
- jsonrpc: '2.0',
950
- id: null,
951
- error: {
952
- code: -32700,
953
- message: error instanceof Error ? error.message : String(error),
954
- },
955
- });
956
- }
957
- })();
958
- });
1
+ #!/usr/bin/env node
2
+ import path from 'node:path';
3
+ import readline from 'node:readline';
4
+ import { fileURLToPath } from 'node:url';
5
+
6
+ const baseUrl = (process.env.PIXCODE_BASE_URL || '').replace(/\/$/, '');
7
+ const apiKey = process.env.PIXCODE_API_KEY || '';
8
+ const appRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..', '..');
9
+ const mcpServerPath = path.join(appRoot, 'scripts', 'hermes', 'pixcode-mcp-server.mjs');
10
+ const READBACK_IDLE_STABLE_MS = Math.max(
11
+ 1000,
12
+ Number.parseInt(process.env.PIXCODE_MCP_READBACK_IDLE_STABLE_MS || '8000', 10) || 8000,
13
+ );
14
+ const DEFAULT_STARTUP_WAIT_MS = 100000;
15
+ const ALLOWED_PIXCODE_API_METHODS = new Set(['GET', 'POST', 'PUT', 'PATCH', 'DELETE']);
16
+
17
+ const tools = [
18
+ {
19
+ name: 'pixcode_list_projects',
20
+ description: 'List Pixcode workspaces/projects visible to this user, including display name, path, and file count when available.',
21
+ inputSchema: {
22
+ type: 'object',
23
+ properties: {},
24
+ additionalProperties: false,
25
+ },
26
+ },
27
+ {
28
+ name: 'pixcode_get_provider_status',
29
+ description: 'Get install/auth/version status for one Pixcode CLI provider before launching it inside Pixcode.',
30
+ inputSchema: {
31
+ type: 'object',
32
+ properties: {
33
+ provider: {
34
+ type: 'string',
35
+ enum: ['claude', 'codex', 'cursor', 'gemini', 'qwen', 'opencode'],
36
+ },
37
+ },
38
+ required: ['provider'],
39
+ additionalProperties: false,
40
+ },
41
+ },
42
+ {
43
+ name: 'pixcode_open_cli_terminal',
44
+ description: 'Use this instead of Hermes shell/proc/skill execution whenever the user asks to open Codex, Claude, Cursor, Gemini, Qwen, or OpenCode inside Pixcode. It asks the open Pixcode workbench to continue the existing visible provider terminal in the project and submit startup input there. Do not run a parallel Hermes codex/claude/proc command for the same request. Do not request a fresh session unless the user explicitly asks for a new session. For multi-step, piece-by-piece, or long-running work, put the full user instruction in startupInput so the provider CLI does the work visibly inside Pixcode. When startupInput is present, Pixcode waits for the terminal to become idle before returning readback by default; never treat the first working frame as final output.',
45
+ inputSchema: {
46
+ type: 'object',
47
+ properties: {
48
+ provider: {
49
+ type: 'string',
50
+ enum: ['claude', 'codex', 'cursor', 'gemini', 'qwen', 'opencode'],
51
+ },
52
+ projectPath: {
53
+ type: 'string',
54
+ description: 'Absolute project path. Omit to use the currently selected Pixcode project.',
55
+ },
56
+ prompt: {
57
+ type: 'string',
58
+ description: 'Optional audit/reason text for Pixcode. This is not typed into the provider CLI.',
59
+ },
60
+ startupInput: {
61
+ type: 'string',
62
+ description: 'Exact startup input typed into the provider CLI after the TUI is ready. Use this for commands like /init, hello prompts, or full multi-step task instructions the user asked to run visibly.',
63
+ },
64
+ forceNewSession: {
65
+ type: 'boolean',
66
+ description: 'Start a fresh visible provider CLI session only when the user explicitly asks for a new session. Omit or false to continue the existing visible provider terminal.',
67
+ },
68
+ bypassPermissions: {
69
+ type: 'boolean',
70
+ description: 'When true, Pixcode starts the provider CLI with its strongest no-approval/bypass flags where supported. Defaults to true for Hermes-launched visible task work.',
71
+ },
72
+ permissionMode: {
73
+ type: 'string',
74
+ enum: ['default', 'bypassPermissions', 'acceptEdits', 'yolo', 'auto_edit', 'plan'],
75
+ description: 'Optional provider permission mode. Omit to use bypassPermissions when bypassPermissions is not false.',
76
+ },
77
+ waitForOutputMs: {
78
+ type: 'number',
79
+ description: 'Optional milliseconds to wait for recent terminal output. Pixcode keeps polling while terminalState is busy, so use a large value when the user asks for the final provider answer.',
80
+ },
81
+ waitForCompletionMs: {
82
+ type: 'number',
83
+ description: 'Optional explicit milliseconds to wait for the visible provider CLI to return to an idle prompt before reporting output. Overrides waitForOutputMs.',
84
+ },
85
+ launchId: {
86
+ type: 'number',
87
+ description: 'Optional Pixcode terminal launch id. Use the id returned by pixcode_open_cli_terminal when reading one specific visible terminal.',
88
+ },
89
+ },
90
+ required: ['provider'],
91
+ additionalProperties: false,
92
+ },
93
+ },
94
+ {
95
+ name: 'pixcode_read_cli_terminal',
96
+ description: 'Read recent visible Pixcode provider CLI terminal output for a project. Use after pixcode_open_cli_terminal when the user asks what Codex/Claude/Gemini/Qwen/OpenCode printed.',
97
+ inputSchema: {
98
+ type: 'object',
99
+ properties: {
100
+ provider: {
101
+ type: 'string',
102
+ enum: ['claude', 'codex', 'cursor', 'gemini', 'qwen', 'opencode'],
103
+ },
104
+ projectPath: {
105
+ type: 'string',
106
+ description: 'Absolute project path. Omit to use the currently selected Pixcode project.',
107
+ },
108
+ maxChars: {
109
+ type: 'number',
110
+ description: 'Maximum transcript characters to return, capped by Pixcode.',
111
+ },
112
+ },
113
+ required: ['provider'],
114
+ additionalProperties: false,
115
+ },
116
+ },
117
+ {
118
+ name: 'pixcode_get_hermes_gateway_status',
119
+ description: 'Read Pixcode-managed Hermes REST gateway status, including base URL, running state, and the last probe result.',
120
+ inputSchema: {
121
+ type: 'object',
122
+ properties: {
123
+ projectPath: {
124
+ type: 'string',
125
+ description: 'Absolute project path. Omit to inspect all managed Hermes gateways.',
126
+ },
127
+ },
128
+ additionalProperties: false,
129
+ },
130
+ },
131
+ {
132
+ name: 'pixcode_probe_hermes_gateway',
133
+ description: 'Ask Pixcode to call Hermes Agent REST endpoints and report whether health, capabilities, model discovery, and an optional real prompt respond.',
134
+ inputSchema: {
135
+ type: 'object',
136
+ properties: {
137
+ projectPath: {
138
+ type: 'string',
139
+ description: 'Absolute project path. Omit to probe the first running managed Hermes gateway.',
140
+ },
141
+ input: {
142
+ type: 'string',
143
+ description: 'Optional prompt to submit to Hermes /v1/runs after the lightweight REST checks pass.',
144
+ },
145
+ startIfNeeded: {
146
+ type: 'boolean',
147
+ description: 'When true, Pixcode starts the managed Hermes gateway before probing.',
148
+ },
149
+ },
150
+ additionalProperties: false,
151
+ },
152
+ },
153
+ {
154
+ name: 'pixcode_get_hermes_diagnostics',
155
+ description: 'Read Pixcode Hermes integration diagnostics: installed command, active model/provider, Hermes toolsets, Pixcode MCP tool registration, REST gateway status, cron API state, and redacted recent error signals.',
156
+ inputSchema: {
157
+ type: 'object',
158
+ properties: {
159
+ projectPath: {
160
+ type: 'string',
161
+ description: 'Absolute project path. Omit to diagnose the first running managed Hermes gateway and default Hermes profile.',
162
+ },
163
+ },
164
+ additionalProperties: false,
165
+ },
166
+ },
167
+ {
168
+ name: 'pixcode_get_hermes_control_plane',
169
+ description: 'Read the full Pixcode Hermes control-plane snapshot: install status, managed/source Hermes homes, workspace gateways, profiles, sessions, cron jobs, MCP readiness, capabilities, diagnostics, and recommended fixes.',
170
+ inputSchema: {
171
+ type: 'object',
172
+ properties: {
173
+ projectPath: {
174
+ type: 'string',
175
+ description: 'Absolute project path. Omit to inspect all managed Hermes gateways and the active/default Hermes profile.',
176
+ },
177
+ },
178
+ additionalProperties: false,
179
+ },
180
+ },
181
+ {
182
+ name: 'pixcode_repair_hermes_control_plane',
183
+ description: 'Ask Pixcode to repair Hermes control-plane wiring by starting or replacing the managed gateway and rewriting Pixcode MCP config for the workspace. Use forceRestart only when stale tools or an unhealthy gateway must be replaced.',
184
+ inputSchema: {
185
+ type: 'object',
186
+ properties: {
187
+ projectPath: {
188
+ type: 'string',
189
+ description: 'Absolute project path for the managed Hermes gateway.',
190
+ },
191
+ forceRestart: {
192
+ type: 'boolean',
193
+ description: 'Stop and restart the managed Hermes gateway before repairing MCP config.',
194
+ },
195
+ },
196
+ additionalProperties: false,
197
+ },
198
+ },
199
+ {
200
+ name: 'pixcode_get_api_manifest',
201
+ description: 'Read Pixcode public API documentation manifest. Use this to discover controllable Pixcode API groups, paths, and scopes before calling pixcode_api_request.',
202
+ inputSchema: {
203
+ type: 'object',
204
+ properties: {},
205
+ additionalProperties: false,
206
+ },
207
+ },
208
+ {
209
+ name: 'pixcode_api_request',
210
+ description: 'Call the authenticated local Pixcode REST API. Use this for full Pixcode control after reading pixcode_get_api_manifest. Path must be a local /api/... path or /health; never pass an external URL.',
211
+ inputSchema: {
212
+ type: 'object',
213
+ properties: {
214
+ method: {
215
+ type: 'string',
216
+ enum: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE'],
217
+ description: 'HTTP method to use.',
218
+ },
219
+ path: {
220
+ type: 'string',
221
+ description: 'Local Pixcode path, for example /api/projects, /api/providers/codex/auth/status?refresh=1, or /api/remote/config.',
222
+ },
223
+ body: {
224
+ type: 'object',
225
+ description: 'Optional JSON body for POST, PUT, PATCH, or DELETE requests.',
226
+ additionalProperties: true,
227
+ },
228
+ },
229
+ required: ['method', 'path'],
230
+ additionalProperties: false,
231
+ },
232
+ },
233
+ {
234
+ name: 'pixcode_hermes_gateway_request',
235
+ description: 'Call the Pixcode-managed Hermes REST gateway for advanced Hermes features such as /v1/runs, /v1/responses, /api/jobs cron management, /v1/capabilities, and /health. Use startIfNeeded when the gateway is not already running.',
236
+ inputSchema: {
237
+ type: 'object',
238
+ properties: {
239
+ method: {
240
+ type: 'string',
241
+ enum: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE'],
242
+ },
243
+ endpoint: {
244
+ type: 'string',
245
+ description: 'Hermes gateway endpoint, for example /api/jobs, /api/jobs/<id>/run, /v1/capabilities, or /v1/responses.',
246
+ },
247
+ body: {
248
+ type: 'object',
249
+ additionalProperties: true,
250
+ },
251
+ projectPath: {
252
+ type: 'string',
253
+ description: 'Absolute project path for the managed Hermes gateway.',
254
+ },
255
+ startIfNeeded: {
256
+ type: 'boolean',
257
+ description: 'Start the managed Hermes gateway first when it is not already running.',
258
+ },
259
+ },
260
+ required: ['method', 'endpoint'],
261
+ additionalProperties: false,
262
+ },
263
+ },
264
+ {
265
+ name: 'pixcode_manage_hermes_cron',
266
+ description: 'Create, list, update, pause, resume, run, or delete Hermes cron jobs through the Pixcode-managed Hermes REST gateway. Cron jobs can run in a project workdir and use Hermes skills/toolsets.',
267
+ inputSchema: {
268
+ type: 'object',
269
+ properties: {
270
+ action: {
271
+ type: 'string',
272
+ enum: ['list', 'create', 'get', 'update', 'delete', 'pause', 'resume', 'run'],
273
+ },
274
+ jobId: {
275
+ type: 'string',
276
+ description: 'Required for get, update, delete, pause, resume, and run.',
277
+ },
278
+ projectPath: {
279
+ type: 'string',
280
+ description: 'Absolute project path for the managed Hermes gateway and default cron workdir.',
281
+ },
282
+ name: { type: 'string' },
283
+ schedule: { type: 'string' },
284
+ prompt: { type: 'string' },
285
+ workdir: { type: 'string' },
286
+ skills: {
287
+ type: 'array',
288
+ items: { type: 'string' },
289
+ },
290
+ delivery: { type: 'string' },
291
+ startIfNeeded: { type: 'boolean' },
292
+ },
293
+ required: ['action'],
294
+ additionalProperties: false,
295
+ },
296
+ },
297
+ {
298
+ name: 'pixcode_send_cli_input',
299
+ description: 'Send text or an Enter key directly to an existing visible Pixcode provider terminal. Use this when a terminal is already open and the user asks Hermes to continue that exact visible session.',
300
+ inputSchema: {
301
+ type: 'object',
302
+ properties: {
303
+ provider: {
304
+ type: 'string',
305
+ enum: ['claude', 'codex', 'cursor', 'gemini', 'qwen', 'opencode'],
306
+ },
307
+ projectPath: {
308
+ type: 'string',
309
+ description: 'Absolute project path. Omit to use the newest visible terminal for the provider.',
310
+ },
311
+ input: {
312
+ type: 'string',
313
+ description: 'Text to type. May be empty when submit=true to press Enter on already typed input.',
314
+ },
315
+ submit: {
316
+ type: 'boolean',
317
+ description: 'Append Enter after input. Defaults to true.',
318
+ },
319
+ launchId: {
320
+ type: 'number',
321
+ description: 'Optional Pixcode terminal launch id to target one visible terminal.',
322
+ },
323
+ },
324
+ required: ['provider'],
325
+ additionalProperties: false,
326
+ },
327
+ },
328
+ ];
329
+
330
+ function send(payload) {
331
+ process.stdout.write(`${JSON.stringify(payload)}\n`);
332
+ }
333
+
334
+ function textResult(text) {
335
+ return {
336
+ content: [
337
+ {
338
+ type: 'text',
339
+ text,
340
+ },
341
+ ],
342
+ };
343
+ }
344
+
345
+ function sleep(ms) {
346
+ return new Promise((resolve) => setTimeout(resolve, ms));
347
+ }
348
+
349
+ async function pixcodeFetch(endpoint, options = {}) {
350
+ if (!baseUrl || !apiKey) {
351
+ throw new Error('Pixcode MCP is missing PIXCODE_BASE_URL or PIXCODE_API_KEY.');
352
+ }
353
+
354
+ const response = await fetch(`${baseUrl}${endpoint}`, {
355
+ ...options,
356
+ headers: {
357
+ Authorization: `Bearer ${apiKey}`,
358
+ 'Content-Type': 'application/json',
359
+ ...(options.headers || {}),
360
+ },
361
+ });
362
+ const text = await response.text();
363
+ let body = null;
364
+ try {
365
+ body = text ? JSON.parse(text) : null;
366
+ } catch {
367
+ body = text;
368
+ }
369
+
370
+ if (!response.ok) {
371
+ throw new Error(`Pixcode API ${endpoint} failed with HTTP ${response.status}: ${typeof body === 'string' ? body : JSON.stringify(body)}`);
372
+ }
373
+
374
+ return body;
375
+ }
376
+
377
+ function normalizeLocalPixcodePath(pathValue) {
378
+ const endpoint = typeof pathValue === 'string' ? pathValue.trim() : '';
379
+ if (!endpoint) {
380
+ throw new Error('Pixcode API path is required.');
381
+ }
382
+ if (/^[a-z][a-z0-9+.-]*:\/\//iu.test(endpoint) || endpoint.startsWith('//')) {
383
+ throw new Error('Pixcode API path must be local; external URLs are not allowed.');
384
+ }
385
+ if (endpoint !== '/health' && !endpoint.startsWith('/api/')) {
386
+ throw new Error('Pixcode API path must start with /api/ or be /health.');
387
+ }
388
+ return endpoint;
389
+ }
390
+
391
+ function normalizeHermesGatewayEndpoint(endpointValue) {
392
+ const endpoint = typeof endpointValue === 'string' ? endpointValue.trim() : '';
393
+ if (!endpoint) {
394
+ throw new Error('Hermes gateway endpoint is required.');
395
+ }
396
+ if (/^[a-z][a-z0-9+.-]*:\/\//iu.test(endpoint) || endpoint.startsWith('//')) {
397
+ throw new Error('Hermes gateway endpoint must be local; external URLs are not allowed.');
398
+ }
399
+ if (!endpoint.startsWith('/')) {
400
+ throw new Error('Hermes gateway endpoint must start with /.');
401
+ }
402
+ if (
403
+ endpoint !== '/health' &&
404
+ endpoint !== '/health/detailed' &&
405
+ !endpoint.startsWith('/v1/') &&
406
+ !endpoint.startsWith('/api/')
407
+ ) {
408
+ throw new Error('Hermes gateway endpoint must be /health, /v1/..., or /api/....');
409
+ }
410
+ return endpoint;
411
+ }
412
+
413
+ function normalizeHttpMethod(methodValue) {
414
+ const method = String(methodValue || 'GET').trim().toUpperCase();
415
+ if (!ALLOWED_PIXCODE_API_METHODS.has(method)) {
416
+ throw new Error(`Unsupported HTTP method: ${method || '(empty)'}`);
417
+ }
418
+ return method;
419
+ }
420
+
421
+ async function pixcodeJsonRequest(pathValue, { method = 'GET', body } = {}) {
422
+ const endpoint = normalizeLocalPixcodePath(pathValue);
423
+ const normalizedMethod = normalizeHttpMethod(method);
424
+ const requestOptions = { method: normalizedMethod };
425
+ if (typeof body !== 'undefined' && normalizedMethod !== 'GET') {
426
+ requestOptions.body = JSON.stringify(body);
427
+ }
428
+ return pixcodeFetch(endpoint, requestOptions);
429
+ }
430
+
431
+ async function sendProviderTerminalInput(provider, projectPath, input, submit = true, launchId = null) {
432
+ return pixcodeFetch('/api/shell/sessions/provider-input', {
433
+ method: 'POST',
434
+ body: JSON.stringify({
435
+ provider,
436
+ projectPath: projectPath || null,
437
+ input: typeof input === 'string' ? input : '',
438
+ submit: submit !== false,
439
+ launchId: Number(launchId || 0) || null,
440
+ }),
441
+ });
442
+ }
443
+
444
+ async function readProviderStatus(provider) {
445
+ const body = await pixcodeFetch(`/api/providers/${encodeURIComponent(provider)}/auth/status?refresh=1`);
446
+ return body?.data ?? body;
447
+ }
448
+
449
+ async function readProviderTerminalOutput(provider, projectPath, maxChars, launchId = null) {
450
+ const params = new URLSearchParams({
451
+ provider,
452
+ maxChars: String(maxChars || 12000),
453
+ });
454
+ if (projectPath) params.set('projectPath', projectPath);
455
+ if (launchId) params.set('launchId', String(launchId));
456
+ return pixcodeFetch(`/api/shell/sessions/provider-output?${params.toString()}`);
457
+ }
458
+
459
+ function getLastMatchIndex(text, pattern) {
460
+ let lastIndex = -1;
461
+ for (const match of text.matchAll(pattern)) {
462
+ lastIndex = match.index ?? lastIndex;
463
+ }
464
+ return lastIndex;
465
+ }
466
+
467
+ function inferTerminalState(provider, terminalOutput) {
468
+ if (!terminalOutput) return 'unknown';
469
+ if (typeof terminalOutput.terminalState === 'string') return terminalOutput.terminalState;
470
+ if (typeof terminalOutput.isBusy === 'boolean') return terminalOutput.isBusy ? 'busy' : 'idle';
471
+ if (terminalOutput.active === false) return terminalOutput.output ? 'idle' : 'unknown';
472
+
473
+ const output = String(terminalOutput.output || '');
474
+ if (!output.trim()) return 'unknown';
475
+ if (/Process exited with code/iu.test(output)) return 'idle';
476
+
477
+ const lastWeakBusy = getLastMatchIndex(output, /(?:^|\n)\s*[•*]\s*(?:Working|Running|Thinking)\b/giu);
478
+ const lastStrongBusy = Math.max(
479
+ getLastMatchIndex(output, /\bWorking\s*\([^)]*esc to interrupt[^)]*\)/giu),
480
+ getLastMatchIndex(output, /\bmsg=interrupt\b/giu),
481
+ );
482
+ const lastBusy = Math.max(lastWeakBusy, lastStrongBusy);
483
+
484
+ if (provider === 'codex') {
485
+ const lastPrompt = Math.max(
486
+ getLastMatchIndex(output, /(?:^|\n)\s*›(?:\s|$)/gu),
487
+ getLastMatchIndex(output, /(?:^|\n)\s*❯(?:\s|$)/gu),
488
+ );
489
+ if (lastPrompt >= 0) return lastStrongBusy > lastPrompt ? 'busy' : 'idle';
490
+ if (lastBusy >= 0) return 'busy';
491
+ return 'unknown';
492
+ }
493
+
494
+ if (lastBusy >= 0) return 'busy';
495
+ return 'unknown';
496
+ }
497
+
498
+ function isTerminalReadbackFinal(provider, terminalOutput) {
499
+ const terminalState = inferTerminalState(provider, terminalOutput);
500
+ return terminalState === 'idle' || terminalState === 'completed' || terminalState === 'exited' || terminalState === 'failed';
501
+ }
502
+
503
+ function isTerminalReadbackHardFinal(provider, terminalOutput) {
504
+ const terminalState = inferTerminalState(provider, terminalOutput);
505
+ return terminalState === 'completed' || terminalState === 'exited' || terminalState === 'failed' || Boolean(terminalOutput?.terminalFailed);
506
+ }
507
+
508
+ function getReadbackFingerprint(terminalOutput) {
509
+ return [
510
+ terminalOutput?.terminalState || '',
511
+ terminalOutput?.lifecycleState || '',
512
+ terminalOutput?.exitCode ?? '',
513
+ terminalOutput?.exitSignal || '',
514
+ String(terminalOutput?.output || '').slice(-12000),
515
+ ].join('\n---pixcode-readback---\n');
516
+ }
517
+
518
+ function outputHasProviderPrompt(provider, output) {
519
+ const text = String(output || '');
520
+ if (provider === 'codex') {
521
+ return /(?:^|\n)\s*[›❯]\s*$/u.test(text) || /(?:^|\n)\s*›\s+[^\n]*$/u.test(text);
522
+ }
523
+ return /(?:^|\n).{0,80}(?:>\s*|❯\s*)$/u.test(text);
524
+ }
525
+
526
+ function startupInputLooksStuckAtPrompt(provider, terminalOutput, startupInput) {
527
+ if (!startupInput || !terminalOutput?.output || terminalOutput.isBusy) return false;
528
+ const output = String(terminalOutput.output || '');
529
+ const escapedInput = startupInput.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
530
+ if (provider === 'codex') {
531
+ return new RegExp(`(?:^|\\n)\\s*[›❯]\\s*${escapedInput}\\s*$`, 'u').test(output);
532
+ }
533
+ return output.endsWith(startupInput) || outputHasProviderPrompt(provider, output);
534
+ }
535
+
536
+ async function recoverStuckStartupInput(provider, projectPath, startupInput, terminalOutput, launchId = null) {
537
+ if (!startupInputLooksStuckAtPrompt(provider, terminalOutput, startupInput)) {
538
+ return null;
539
+ }
540
+
541
+ const output = String(terminalOutput?.output || '');
542
+ const inputAlreadyVisible = output.includes(startupInput);
543
+ return sendProviderTerminalInput(
544
+ provider,
545
+ projectPath,
546
+ inputAlreadyVisible ? '' : startupInput,
547
+ true,
548
+ launchId,
549
+ );
550
+ }
551
+
552
+ async function waitForProviderTerminalOutput(provider, projectPath, waitMs, launchId = null) {
553
+ const startedAt = Date.now();
554
+ let latestOutput = null;
555
+ let stableFingerprint = null;
556
+ let stableSince = 0;
557
+ let stableFinal = false;
558
+ do {
559
+ const elapsed = Date.now() - startedAt;
560
+ const remaining = Math.max(0, waitMs - elapsed);
561
+ await sleep(Math.min(1000, Math.max(250, remaining)));
562
+ latestOutput = await readProviderTerminalOutput(provider, projectPath, 12000, launchId).catch((error) => ({
563
+ active: false,
564
+ terminalState: 'unknown',
565
+ error: error instanceof Error ? error.message : String(error),
566
+ }));
567
+
568
+ if (latestOutput?.output && isTerminalReadbackFinal(provider, latestOutput)) {
569
+ if (isTerminalReadbackHardFinal(provider, latestOutput)) {
570
+ stableFinal = true;
571
+ break;
572
+ }
573
+
574
+ const fingerprint = getReadbackFingerprint(latestOutput);
575
+ if (fingerprint !== stableFingerprint) {
576
+ stableFingerprint = fingerprint;
577
+ stableSince = Date.now();
578
+ }
579
+ if (Date.now() - stableSince >= READBACK_IDLE_STABLE_MS) {
580
+ stableFinal = true;
581
+ break;
582
+ }
583
+ } else {
584
+ stableFingerprint = null;
585
+ stableSince = 0;
586
+ }
587
+ } while (Date.now() - startedAt < waitMs);
588
+
589
+ if (latestOutput && !latestOutput.terminalState) {
590
+ latestOutput.terminalState = inferTerminalState(provider, latestOutput);
591
+ }
592
+ if (latestOutput && typeof latestOutput.isBusy !== 'boolean') {
593
+ latestOutput.isBusy = latestOutput.terminalState === 'busy';
594
+ }
595
+ if (latestOutput) {
596
+ latestOutput.readbackStable = stableFinal;
597
+ latestOutput.terminalOutputFinal = stableFinal;
598
+ }
599
+ return latestOutput;
600
+ }
601
+
602
+ function isLegacyPromptLikelyStartupInput(prompt) {
603
+ if (!prompt || prompt.length > 160 || prompt.includes('\n')) return false;
604
+ if (/^[/:!@]/u.test(prompt)) return true;
605
+ if (prompt.includes(':')) return false;
606
+ 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)) {
607
+ return false;
608
+ }
609
+ return prompt.length <= 80;
610
+ }
611
+
612
+ async function upsertProviderPixcodeMcp(provider, projectPath, scope) {
613
+ const body = await pixcodeFetch(`/api/providers/${encodeURIComponent(provider)}/mcp/servers`, {
614
+ method: 'POST',
615
+ body: JSON.stringify({
616
+ name: 'pixcode',
617
+ transport: 'stdio',
618
+ scope,
619
+ workspacePath: projectPath || process.cwd(),
620
+ command: process.execPath,
621
+ args: [mcpServerPath],
622
+ env: {
623
+ PIXCODE_BASE_URL: baseUrl,
624
+ PIXCODE_API_KEY: apiKey,
625
+ },
626
+ }),
627
+ });
628
+ return body?.data?.server ?? body?.server ?? body;
629
+ }
630
+
631
+ async function ensureProviderPixcodeMcp(provider, projectPath) {
632
+ try {
633
+ const server = await upsertProviderPixcodeMcp(provider, projectPath, 'project');
634
+ return { scope: 'project', server, projectScopeError: null };
635
+ } catch (error) {
636
+ const projectScopeError = error instanceof Error ? error.message : String(error);
637
+ try {
638
+ const server = await upsertProviderPixcodeMcp(provider, projectPath, 'user');
639
+ return { scope: 'user', server, projectScopeError };
640
+ } catch (fallbackError) {
641
+ const userScopeError = fallbackError instanceof Error ? fallbackError.message : String(fallbackError);
642
+ throw new Error(`Pixcode MCP auto-config failed for project scope (${projectScopeError}) and user scope (${userScopeError})`);
643
+ }
644
+ }
645
+ }
646
+
647
+ async function callTool(name, args = {}) {
648
+ if (name === 'pixcode_list_projects') {
649
+ const projects = await pixcodeFetch('/api/projects');
650
+ const normalized = (Array.isArray(projects) ? projects : []).map((project) => ({
651
+ name: project.name,
652
+ displayName: project.displayName,
653
+ path: project.fullPath || project.path,
654
+ fileCount: project.fileCount ?? null,
655
+ }));
656
+ return textResult(JSON.stringify(normalized, null, 2));
657
+ }
658
+
659
+ if (name === 'pixcode_get_provider_status') {
660
+ const provider = String(args.provider || '');
661
+ const status = await readProviderStatus(provider);
662
+ return textResult(JSON.stringify(status, null, 2));
663
+ }
664
+
665
+ if (name === 'pixcode_open_cli_terminal') {
666
+ const provider = String(args.provider || '');
667
+ const projectPath = typeof args.projectPath === 'string' && args.projectPath.trim()
668
+ ? args.projectPath.trim()
669
+ : null;
670
+ const status = await readProviderStatus(provider);
671
+ if (status?.installed === false) {
672
+ return textResult(JSON.stringify({
673
+ launched: false,
674
+ provider,
675
+ reason: 'not_installed',
676
+ message: `${provider} CLI is not installed. Install it in Pixcode before launching a terminal.`,
677
+ status,
678
+ }, null, 2));
679
+ }
680
+
681
+ let mcpConfigured = false;
682
+ let mcpConfig = null;
683
+ let mcpError = null;
684
+ try {
685
+ mcpConfig = await ensureProviderPixcodeMcp(provider, projectPath);
686
+ mcpConfigured = true;
687
+ } catch (error) {
688
+ mcpError = error instanceof Error ? error.message : String(error);
689
+ }
690
+
691
+ const startupInput = typeof args.startupInput === 'string' && args.startupInput.trim()
692
+ ? args.startupInput
693
+ : (isLegacyPromptLikelyStartupInput(args.prompt) ? args.prompt.trim() : null);
694
+ const bypassPermissions = args.bypassPermissions === false ? false : true;
695
+ const forceNewSession = args.forceNewSession === true || args.newSession === true || args.freshSession === true;
696
+ const permissionMode = typeof args.permissionMode === 'string' && args.permissionMode.trim()
697
+ ? args.permissionMode.trim()
698
+ : (bypassPermissions ? 'bypassPermissions' : null);
699
+
700
+ const body = await pixcodeFetch('/api/orchestration/hermes/terminal-launches', {
701
+ method: 'POST',
702
+ body: JSON.stringify({
703
+ provider,
704
+ projectPath,
705
+ prompt: args.prompt || null,
706
+ startupInput,
707
+ forceNewSession,
708
+ bypassPermissions,
709
+ skipPermissions: bypassPermissions,
710
+ permissionMode,
711
+ }),
712
+ });
713
+ const launchId = Number(body?.event?.id || body?.id || 0) || null;
714
+ let terminalOutput = null;
715
+ const defaultWaitMs = startupInput ? DEFAULT_STARTUP_WAIT_MS : 0;
716
+ const requestedWaitMs = Number(args.waitForCompletionMs ?? args.waitForOutputMs ?? defaultWaitMs);
717
+ const waitForOutputMs = Math.min(600000, Math.max(0, requestedWaitMs));
718
+ if (waitForOutputMs > 0) {
719
+ terminalOutput = await waitForProviderTerminalOutput(provider, projectPath, waitForOutputMs, launchId);
720
+ if (startupInput && terminalOutput && !isTerminalReadbackFinal(provider, terminalOutput)) {
721
+ const recovery = await recoverStuckStartupInput(provider, projectPath, startupInput, terminalOutput, launchId).catch((error) => ({
722
+ error: error instanceof Error ? error.message : String(error),
723
+ }));
724
+ if (recovery) {
725
+ const recoveredOutput = await waitForProviderTerminalOutput(provider, projectPath, Math.min(waitForOutputMs, 120000), launchId);
726
+ terminalOutput = recoveredOutput || terminalOutput;
727
+ if (terminalOutput) {
728
+ terminalOutput.startupInputRecovery = recovery;
729
+ }
730
+ }
731
+ }
732
+ }
733
+ const terminalOutputFinal = terminalOutput
734
+ ? Boolean(terminalOutput.terminalOutputFinal ?? isTerminalReadbackFinal(provider, terminalOutput))
735
+ : false;
736
+ return textResult(JSON.stringify({
737
+ launched: true,
738
+ launchId,
739
+ pixcodeMcpConfigured: mcpConfigured,
740
+ pixcodeMcpScope: mcpConfig?.scope ?? null,
741
+ pixcodeMcpProjectScopeError: mcpConfig?.projectScopeError ?? null,
742
+ pixcodeMcpError: mcpError,
743
+ event: body?.event ?? body,
744
+ permissionBypass: bypassPermissions,
745
+ status,
746
+ terminalOutputFinal,
747
+ terminalFailed: Boolean(terminalOutput?.terminalFailed),
748
+ message: terminalOutput && !terminalOutputFinal
749
+ ? 'Provider terminal is still running or not at an idle prompt yet. Do not summarize this as final output; call pixcode_read_cli_terminal with launchId later.'
750
+ : terminalOutput?.terminalFailed
751
+ ? 'Provider terminal exited with a failure. Do not report this as successful; tell the user the visible CLI failed and include the exit code/output.'
752
+ : undefined,
753
+ terminalOutput,
754
+ }, null, 2));
755
+ }
756
+
757
+ if (name === 'pixcode_read_cli_terminal') {
758
+ const provider = String(args.provider || '');
759
+ const projectPath = typeof args.projectPath === 'string' && args.projectPath.trim()
760
+ ? args.projectPath.trim()
761
+ : null;
762
+ const maxChars = Math.min(20000, Math.max(1000, Number(args.maxChars || 12000)));
763
+ const launchId = Number(args.launchId || 0) || null;
764
+ const body = await readProviderTerminalOutput(provider, projectPath, maxChars, launchId);
765
+ if (body && !body.terminalState) {
766
+ body.terminalState = inferTerminalState(provider, body);
767
+ }
768
+ if (body && typeof body.isBusy !== 'boolean') {
769
+ body.isBusy = body.terminalState === 'busy';
770
+ }
771
+ body.terminalOutputFinal = isTerminalReadbackFinal(provider, body);
772
+ body.terminalFailed = Boolean(body.terminalFailed);
773
+ return textResult(JSON.stringify(body, null, 2));
774
+ }
775
+
776
+ if (name === 'pixcode_get_hermes_gateway_status') {
777
+ const projectPath = typeof args.projectPath === 'string' && args.projectPath.trim()
778
+ ? `?projectPath=${encodeURIComponent(args.projectPath.trim())}`
779
+ : '';
780
+ const body = await pixcodeFetch(`/api/orchestration/hermes/gateway/status${projectPath}`);
781
+ return textResult(JSON.stringify(body, null, 2));
782
+ }
783
+
784
+ if (name === 'pixcode_probe_hermes_gateway') {
785
+ const body = await pixcodeFetch('/api/orchestration/hermes/gateway/probe', {
786
+ method: 'POST',
787
+ body: JSON.stringify({
788
+ projectPath: args.projectPath || null,
789
+ input: args.input || null,
790
+ startIfNeeded: args.startIfNeeded === true,
791
+ }),
792
+ });
793
+ return textResult(JSON.stringify(body, null, 2));
794
+ }
795
+
796
+ if (name === 'pixcode_get_hermes_diagnostics') {
797
+ const projectPath = typeof args.projectPath === 'string' && args.projectPath.trim()
798
+ ? `?projectPath=${encodeURIComponent(args.projectPath.trim())}`
799
+ : '';
800
+ const body = await pixcodeFetch(`/api/orchestration/hermes/diagnostics${projectPath}`);
801
+ return textResult(JSON.stringify(body, null, 2));
802
+ }
803
+
804
+ if (name === 'pixcode_get_hermes_control_plane') {
805
+ const projectPath = typeof args.projectPath === 'string' && args.projectPath.trim()
806
+ ? `?projectPath=${encodeURIComponent(args.projectPath.trim())}`
807
+ : '';
808
+ const body = await pixcodeFetch(`/api/orchestration/hermes/control-plane${projectPath}`);
809
+ return textResult(JSON.stringify(body, null, 2));
810
+ }
811
+
812
+ if (name === 'pixcode_repair_hermes_control_plane') {
813
+ const body = await pixcodeFetch('/api/orchestration/hermes/control-plane/repair', {
814
+ method: 'POST',
815
+ body: JSON.stringify({
816
+ projectPath: args.projectPath || null,
817
+ forceRestart: args.forceRestart === true,
818
+ }),
819
+ });
820
+ return textResult(JSON.stringify(body, null, 2));
821
+ }
822
+
823
+ if (name === 'pixcode_get_api_manifest') {
824
+ const body = await pixcodeJsonRequest('/api/public/manifest', { method: 'GET' });
825
+ return textResult(JSON.stringify(body, null, 2));
826
+ }
827
+
828
+ if (name === 'pixcode_api_request') {
829
+ const body = await pixcodeJsonRequest(args.path, {
830
+ method: args.method || 'GET',
831
+ body: args.body,
832
+ });
833
+ return textResult(JSON.stringify(body, null, 2));
834
+ }
835
+
836
+ if (name === 'pixcode_hermes_gateway_request') {
837
+ const endpoint = normalizeHermesGatewayEndpoint(args.endpoint);
838
+ const body = await pixcodeFetch('/api/orchestration/hermes/gateway/request', {
839
+ method: 'POST',
840
+ body: JSON.stringify({
841
+ method: normalizeHttpMethod(args.method || 'GET'),
842
+ endpoint,
843
+ body: args.body || null,
844
+ projectPath: args.projectPath || null,
845
+ startIfNeeded: args.startIfNeeded === true,
846
+ }),
847
+ });
848
+ return textResult(JSON.stringify(body, null, 2));
849
+ }
850
+
851
+ if (name === 'pixcode_manage_hermes_cron') {
852
+ const action = String(args.action || '').trim();
853
+ const jobId = typeof args.jobId === 'string' && args.jobId.trim() ? args.jobId.trim() : null;
854
+ const jobBody = {
855
+ name: args.name || undefined,
856
+ schedule: args.schedule || undefined,
857
+ prompt: args.prompt || undefined,
858
+ workdir: args.workdir || args.projectPath || undefined,
859
+ skills: Array.isArray(args.skills) ? args.skills : undefined,
860
+ delivery: args.delivery || undefined,
861
+ };
862
+ Object.keys(jobBody).forEach((key) => {
863
+ if (typeof jobBody[key] === 'undefined') delete jobBody[key];
864
+ });
865
+
866
+ let method = 'GET';
867
+ let endpoint = '/api/jobs';
868
+ let body = null;
869
+ if (action === 'create') {
870
+ method = 'POST';
871
+ body = jobBody;
872
+ } else if (action === 'list') {
873
+ method = 'GET';
874
+ } else {
875
+ if (!jobId) throw new Error(`jobId is required for Hermes cron action "${action}".`);
876
+ const encodedJobId = encodeURIComponent(jobId);
877
+ if (action === 'get') {
878
+ method = 'GET';
879
+ endpoint = `/api/jobs/${encodedJobId}`;
880
+ } else if (action === 'update') {
881
+ method = 'PATCH';
882
+ endpoint = `/api/jobs/${encodedJobId}`;
883
+ body = jobBody;
884
+ } else if (action === 'delete') {
885
+ method = 'DELETE';
886
+ endpoint = `/api/jobs/${encodedJobId}`;
887
+ } else if (action === 'pause' || action === 'resume' || action === 'run') {
888
+ method = 'POST';
889
+ endpoint = `/api/jobs/${encodedJobId}/${action}`;
890
+ } else {
891
+ throw new Error(`Unsupported Hermes cron action: ${action || '(empty)'}`);
892
+ }
893
+ }
894
+
895
+ const response = await pixcodeFetch('/api/orchestration/hermes/gateway/request', {
896
+ method: 'POST',
897
+ body: JSON.stringify({
898
+ method,
899
+ endpoint,
900
+ body,
901
+ projectPath: args.projectPath || args.workdir || null,
902
+ startIfNeeded: args.startIfNeeded !== false,
903
+ }),
904
+ });
905
+ return textResult(JSON.stringify(response, null, 2));
906
+ }
907
+
908
+ if (name === 'pixcode_send_cli_input') {
909
+ const provider = String(args.provider || '');
910
+ const projectPath = typeof args.projectPath === 'string' && args.projectPath.trim()
911
+ ? args.projectPath.trim()
912
+ : null;
913
+ const body = await sendProviderTerminalInput(
914
+ provider,
915
+ projectPath,
916
+ typeof args.input === 'string' ? args.input : '',
917
+ args.submit !== false,
918
+ Number(args.launchId || 0) || null,
919
+ );
920
+ return textResult(JSON.stringify(body, null, 2));
921
+ }
922
+
923
+ throw new Error(`Unknown Pixcode MCP tool: ${name}`);
924
+ }
925
+
926
+ async function handleMessage(message) {
927
+ if (message.method === 'initialize') {
928
+ send({
929
+ jsonrpc: '2.0',
930
+ id: message.id,
931
+ result: {
932
+ protocolVersion: message.params?.protocolVersion || '2024-11-05',
933
+ capabilities: {
934
+ tools: {},
935
+ },
936
+ serverInfo: {
937
+ name: 'pixcode-mcp',
938
+ version: '1.0.0',
939
+ },
940
+ },
941
+ });
942
+ return;
943
+ }
944
+
945
+ if (message.method === 'tools/list') {
946
+ send({
947
+ jsonrpc: '2.0',
948
+ id: message.id,
949
+ result: { tools },
950
+ });
951
+ return;
952
+ }
953
+
954
+ if (message.method === 'tools/call') {
955
+ try {
956
+ const result = await callTool(message.params?.name, message.params?.arguments || {});
957
+ send({
958
+ jsonrpc: '2.0',
959
+ id: message.id,
960
+ result,
961
+ });
962
+ } catch (error) {
963
+ send({
964
+ jsonrpc: '2.0',
965
+ id: message.id,
966
+ error: {
967
+ code: -32000,
968
+ message: error instanceof Error ? error.message : String(error),
969
+ },
970
+ });
971
+ }
972
+ return;
973
+ }
974
+
975
+ if (typeof message.id !== 'undefined') {
976
+ send({
977
+ jsonrpc: '2.0',
978
+ id: message.id,
979
+ error: {
980
+ code: -32601,
981
+ message: `Method not found: ${message.method}`,
982
+ },
983
+ });
984
+ }
985
+ }
986
+
987
+ const rl = readline.createInterface({
988
+ input: process.stdin,
989
+ crlfDelay: Number.POSITIVE_INFINITY,
990
+ });
991
+
992
+ rl.on('line', (line) => {
993
+ if (!line.trim()) return;
994
+
995
+ void (async () => {
996
+ try {
997
+ await handleMessage(JSON.parse(line));
998
+ } catch (error) {
999
+ send({
1000
+ jsonrpc: '2.0',
1001
+ id: null,
1002
+ error: {
1003
+ code: -32700,
1004
+ message: error instanceof Error ? error.message : String(error),
1005
+ },
1006
+ });
1007
+ }
1008
+ })();
1009
+ });