@pixelbyte-software/pixcode 1.51.7 → 1.51.9

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 (307) 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-BvQgSoyC.js → index-Gs7C4hZT.js} +70 -70
  15. package/dist/clear-cache.html +85 -85
  16. package/dist/convert-icons.md +52 -52
  17. package/dist/docs.html +308 -308
  18. package/dist/favicon.svg +8 -8
  19. package/dist/features.html +133 -133
  20. package/dist/generate-icons.js +48 -48
  21. package/dist/humans.txt +15 -15
  22. package/dist/icons/codex-white.svg +3 -3
  23. package/dist/icons/codex.svg +3 -3
  24. package/dist/icons/cursor-white.svg +11 -11
  25. package/dist/icons/icon-128x128.svg +9 -9
  26. package/dist/icons/icon-144x144.svg +9 -9
  27. package/dist/icons/icon-152x152.svg +9 -9
  28. package/dist/icons/icon-192x192.svg +9 -9
  29. package/dist/icons/icon-384x384.svg +9 -9
  30. package/dist/icons/icon-512x512.svg +9 -9
  31. package/dist/icons/icon-72x72.svg +9 -9
  32. package/dist/icons/icon-96x96.svg +9 -9
  33. package/dist/icons/icon-template.svg +9 -9
  34. package/dist/icons/qwen-logo.svg +14 -14
  35. package/dist/index.html +58 -58
  36. package/dist/landing.html +268 -268
  37. package/dist/llms-full.txt +119 -119
  38. package/dist/llms.txt +53 -53
  39. package/dist/logo.svg +12 -12
  40. package/dist/manifest.json +60 -60
  41. package/dist/openapi.yaml +1696 -1696
  42. package/dist/orchestration.html +125 -125
  43. package/dist/robots.txt +4 -4
  44. package/dist/site.css +692 -692
  45. package/dist/sitemap.xml +51 -51
  46. package/dist/sw.js +132 -132
  47. package/dist-server/server/cli.js +96 -96
  48. package/dist-server/server/daemon/manager.js +33 -33
  49. package/dist-server/server/daemon-manager.js +64 -64
  50. package/dist-server/server/index.js +91 -65
  51. package/dist-server/server/index.js.map +1 -1
  52. package/dist-server/server/routes/commands.js +25 -25
  53. package/dist-server/server/routes/git.js +17 -17
  54. package/dist-server/server/routes/live-view.js +46 -46
  55. package/dist-server/server/services/hermes-gateway.js +5 -5
  56. package/dist-server/server/services/public-api-manifest.js +51 -51
  57. package/package.json +222 -222
  58. package/scripts/fix-node-pty.js +67 -67
  59. package/scripts/github/create-v1.38-issues.mjs +351 -351
  60. package/scripts/github/create-vscode-workbench-issues.mjs +121 -121
  61. package/scripts/hermes/configure-pixcode-mcp.mjs +165 -165
  62. package/scripts/hermes/pixcode-mcp-server.mjs +1009 -1009
  63. package/scripts/smoke/changes-panel-layout.mjs +48 -48
  64. package/scripts/smoke/chat-composer-fixed-layout.mjs +55 -55
  65. package/scripts/smoke/chat-message-timeline-order.mjs +41 -41
  66. package/scripts/smoke/chat-realtime-hydration.mjs +44 -44
  67. package/scripts/smoke/chat-session-provider-pools.mjs +35 -35
  68. package/scripts/smoke/chat-session-state.mjs +19 -19
  69. package/scripts/smoke/code-editor-theme.mjs +55 -55
  70. package/scripts/smoke/code-editor-vscode-engine.mjs +91 -91
  71. package/scripts/smoke/command-center-agent-writes.mjs +79 -79
  72. package/scripts/smoke/command-center-non-git.mjs +46 -46
  73. package/scripts/smoke/context-packet.mjs +43 -43
  74. package/scripts/smoke/control-room-ux-redesign.mjs +91 -91
  75. package/scripts/smoke/daemon-entrypoint.mjs +20 -20
  76. package/scripts/smoke/default-landing-routing.mjs +33 -33
  77. package/scripts/smoke/desktop-native-notifications.mjs +30 -30
  78. package/scripts/smoke/desktop-tray-icon.mjs +33 -33
  79. package/scripts/smoke/discord-release-workflow.mjs +24 -24
  80. package/scripts/smoke/git-install-update.mjs +255 -255
  81. package/scripts/smoke/handoff-artifact-protocol.mjs +50 -50
  82. package/scripts/smoke/hermes-api-install.mjs +56 -56
  83. package/scripts/smoke/hermes-gateway-persistence.mjs +104 -104
  84. package/scripts/smoke/hermes-mcp-pixcode-roundtrip.mjs +426 -426
  85. package/scripts/smoke/hermes-rest-chat-api.mjs +162 -162
  86. package/scripts/smoke/hermes-rest-chat-live.mjs +45 -45
  87. package/scripts/smoke/hermes-rest-codex-launch.mjs +209 -209
  88. package/scripts/smoke/hermes-rest-gateway.mjs +79 -79
  89. package/scripts/smoke/hermes-rest-live.mjs +42 -42
  90. package/scripts/smoke/hermes-roundtrip.mjs +167 -167
  91. package/scripts/smoke/hermes-settings-commands.mjs +349 -349
  92. package/scripts/smoke/hermes-smoke-launcher-guard.mjs +34 -34
  93. package/scripts/smoke/live-view-diagnostics.mjs +53 -53
  94. package/scripts/smoke/live-view-environment.mjs +92 -92
  95. package/scripts/smoke/live-view-integration.mjs +450 -450
  96. package/scripts/smoke/mac-desktop-runtime.mjs +37 -37
  97. package/scripts/smoke/mobile-tunnel-guidance.mjs +29 -29
  98. package/scripts/smoke/model-registry.mjs +36 -36
  99. package/scripts/smoke/multi-project-ui.mjs +45 -45
  100. package/scripts/smoke/multi-worker-slots.mjs +42 -42
  101. package/scripts/smoke/notification-center.mjs +87 -87
  102. package/scripts/smoke/notification-inapp-preference.mjs +23 -23
  103. package/scripts/smoke/notification-taxonomy.mjs +58 -58
  104. package/scripts/smoke/orchestration-api.mjs +172 -172
  105. package/scripts/smoke/orchestration-execution-dashboard.mjs +33 -33
  106. package/scripts/smoke/orchestration-live-run.mjs +176 -176
  107. package/scripts/smoke/orchestration-mobile-scroll.mjs +29 -29
  108. package/scripts/smoke/orchestration-model-sync.mjs +30 -30
  109. package/scripts/smoke/orchestration-permission-fallback.mjs +34 -34
  110. package/scripts/smoke/orchestration-runtime-guards.mjs +48 -48
  111. package/scripts/smoke/orchestration-user-facing-output.mjs +25 -25
  112. package/scripts/smoke/permission-policy.mjs +50 -50
  113. package/scripts/smoke/pixcode-workbench-1-48.mjs +167 -167
  114. package/scripts/smoke/provider-models-opencode-live.mjs +66 -66
  115. package/scripts/smoke/provider-rest-api.mjs +124 -124
  116. package/scripts/smoke/provider-selection-status.mjs +52 -52
  117. package/scripts/smoke/run-state-refresh.mjs +52 -52
  118. package/scripts/smoke/runtime-manager.mjs +99 -99
  119. package/scripts/smoke/shell-manual-disconnect.mjs +30 -30
  120. package/scripts/smoke/side-panel-editor-layout.mjs +34 -34
  121. package/scripts/smoke/static-root-routing.mjs +21 -21
  122. package/scripts/smoke/strict-handoff-compact.mjs +60 -60
  123. package/scripts/smoke/taskmaster-config.mjs +24 -24
  124. package/scripts/smoke/taskmaster-execution-telegram.mjs +3 -3
  125. package/scripts/smoke/taskmaster-onboarding.mjs +3 -3
  126. package/scripts/smoke/taskmaster-run-graph.mjs +3 -3
  127. package/scripts/smoke/telegram-control.mjs +242 -242
  128. package/scripts/smoke/tunnel-persistence.mjs +56 -56
  129. package/scripts/smoke/update-issue-progress.mjs +69 -69
  130. package/scripts/smoke/update-ux.mjs +55 -55
  131. package/scripts/smoke/v138-completion.mjs +132 -132
  132. package/scripts/smoke/v138-desktop-release-hardening.mjs +69 -69
  133. package/scripts/smoke/v138-diagnostics.mjs +63 -63
  134. package/scripts/smoke/v138-issue-planner.mjs +33 -33
  135. package/scripts/smoke/v143-remote-control.mjs +76 -76
  136. package/scripts/smoke/v144-production-loop.mjs +47 -47
  137. package/scripts/smoke/v145-platformization.mjs +46 -46
  138. package/scripts/smoke/v146-control-room-ui.mjs +150 -150
  139. package/scripts/smoke/version-modal-autoshow.mjs +29 -29
  140. package/scripts/smoke/vscode-workbench-layout.mjs +63 -63
  141. package/scripts/smoke/vscode-workbench-polish.mjs +461 -461
  142. package/scripts/smoke/workflow-fallback-replay.mjs +56 -56
  143. package/scripts/smoke/workflow-templates.mjs +43 -43
  144. package/scripts/smoke/workflow-trace-timeline.mjs +46 -46
  145. package/scripts/update-git-install.mjs +283 -283
  146. package/server/claude-sdk.js +920 -920
  147. package/server/cli.js +1035 -1035
  148. package/server/constants/config.js +4 -4
  149. package/server/cursor-cli.js +344 -344
  150. package/server/daemon/manager.js +563 -563
  151. package/server/daemon-manager.js +964 -964
  152. package/server/database/db.js +895 -895
  153. package/server/database/json-store.js +197 -197
  154. package/server/gemini-cli.js +550 -550
  155. package/server/gemini-response-handler.js +79 -79
  156. package/server/index.js +111 -81
  157. package/server/load-env.js +35 -35
  158. package/server/middleware/auth.js +155 -155
  159. package/server/modules/orchestration/a2a/adapter-registry.ts +108 -108
  160. package/server/modules/orchestration/a2a/adapters/abstract-a2a.adapter.ts +63 -63
  161. package/server/modules/orchestration/a2a/adapters/claude-code.adapter.ts +286 -286
  162. package/server/modules/orchestration/a2a/adapters/codex.adapter.ts +244 -244
  163. package/server/modules/orchestration/a2a/adapters/cursor.adapter.ts +249 -249
  164. package/server/modules/orchestration/a2a/adapters/gemini.adapter.ts +248 -248
  165. package/server/modules/orchestration/a2a/adapters/json-event.adapter.ts +100 -100
  166. package/server/modules/orchestration/a2a/adapters/opencode.adapter.ts +248 -248
  167. package/server/modules/orchestration/a2a/adapters/qwen.adapter.ts +248 -248
  168. package/server/modules/orchestration/a2a/agent-card.ts +55 -55
  169. package/server/modules/orchestration/a2a/routes.ts +590 -590
  170. package/server/modules/orchestration/a2a/task-store.ts +178 -178
  171. package/server/modules/orchestration/a2a/types.ts +126 -126
  172. package/server/modules/orchestration/a2a/validator.ts +113 -113
  173. package/server/modules/orchestration/hermes/hermes.routes.ts +642 -642
  174. package/server/modules/orchestration/index.ts +101 -101
  175. package/server/modules/orchestration/preview/port-watcher.ts +112 -112
  176. package/server/modules/orchestration/preview/preview-proxy.ts +60 -60
  177. package/server/modules/orchestration/preview/types.ts +19 -19
  178. package/server/modules/orchestration/security/permission-policy.ts +401 -401
  179. package/server/modules/orchestration/tasks/orchestration-task-store.ts +41 -41
  180. package/server/modules/orchestration/tasks/orchestration-task.routes.ts +64 -64
  181. package/server/modules/orchestration/tasks/orchestration-task.service.ts +209 -209
  182. package/server/modules/orchestration/tasks/orchestration-task.types.ts +40 -40
  183. package/server/modules/orchestration/tasks/task-run-graph.ts +155 -155
  184. package/server/modules/orchestration/workflows/approval-queue.ts +106 -106
  185. package/server/modules/orchestration/workflows/built-in-workflows.ts +127 -127
  186. package/server/modules/orchestration/workflows/context-packet.ts +186 -186
  187. package/server/modules/orchestration/workflows/handoff-artifact.ts +175 -175
  188. package/server/modules/orchestration/workflows/workflow-fallback-policy.ts +161 -161
  189. package/server/modules/orchestration/workflows/workflow-replay.ts +254 -254
  190. package/server/modules/orchestration/workflows/workflow-runner.ts +2070 -2070
  191. package/server/modules/orchestration/workflows/workflow-store.ts +97 -97
  192. package/server/modules/orchestration/workflows/workflow-templates.ts +272 -272
  193. package/server/modules/orchestration/workflows/workflow-trace.ts +424 -424
  194. package/server/modules/orchestration/workflows/workflow.routes.ts +586 -586
  195. package/server/modules/orchestration/workflows/workflow.types.ts +111 -111
  196. package/server/modules/orchestration/workflows/workspace-target.ts +122 -122
  197. package/server/modules/orchestration/workspace/docker-workspace.ts +136 -136
  198. package/server/modules/orchestration/workspace/path-safety.ts +55 -55
  199. package/server/modules/orchestration/workspace/types.ts +52 -52
  200. package/server/modules/orchestration/workspace/workspace-manager.ts +102 -102
  201. package/server/modules/orchestration/workspace/worktree-workspace.ts +126 -126
  202. package/server/modules/providers/index.ts +2 -2
  203. package/server/modules/providers/list/claude/claude-auth.provider.ts +146 -146
  204. package/server/modules/providers/list/claude/claude-mcp.provider.ts +135 -135
  205. package/server/modules/providers/list/claude/claude-sessions.provider.ts +306 -306
  206. package/server/modules/providers/list/claude/claude.provider.ts +15 -15
  207. package/server/modules/providers/list/codex/codex-auth.provider.ts +117 -117
  208. package/server/modules/providers/list/codex/codex-mcp.provider.ts +135 -135
  209. package/server/modules/providers/list/codex/codex-sessions.provider.ts +319 -319
  210. package/server/modules/providers/list/codex/codex.provider.ts +15 -15
  211. package/server/modules/providers/list/cursor/cursor-auth.provider.ts +147 -147
  212. package/server/modules/providers/list/cursor/cursor-mcp.provider.ts +108 -108
  213. package/server/modules/providers/list/cursor/cursor-sessions.provider.ts +421 -421
  214. package/server/modules/providers/list/cursor/cursor.provider.ts +15 -15
  215. package/server/modules/providers/list/gemini/gemini-auth.provider.ts +173 -173
  216. package/server/modules/providers/list/gemini/gemini-mcp.provider.ts +110 -110
  217. package/server/modules/providers/list/gemini/gemini-sessions.provider.ts +227 -227
  218. package/server/modules/providers/list/gemini/gemini.provider.ts +15 -15
  219. package/server/modules/providers/list/opencode/opencode-auth.provider.ts +131 -131
  220. package/server/modules/providers/list/opencode/opencode-mcp.provider.ts +126 -126
  221. package/server/modules/providers/list/opencode/opencode-sessions.provider.ts +286 -286
  222. package/server/modules/providers/list/opencode/opencode.provider.ts +29 -29
  223. package/server/modules/providers/list/qwen/qwen-auth.provider.ts +146 -146
  224. package/server/modules/providers/list/qwen/qwen-mcp.provider.ts +114 -114
  225. package/server/modules/providers/list/qwen/qwen-sessions.provider.ts +265 -265
  226. package/server/modules/providers/list/qwen/qwen.provider.ts +21 -21
  227. package/server/modules/providers/provider.registry.ts +40 -40
  228. package/server/modules/providers/provider.routes.ts +891 -891
  229. package/server/modules/providers/services/mcp.service.ts +86 -86
  230. package/server/modules/providers/services/provider-auth.service.ts +26 -26
  231. package/server/modules/providers/services/sessions.service.ts +45 -45
  232. package/server/modules/providers/shared/base/abstract.provider.ts +20 -20
  233. package/server/modules/providers/shared/mcp/mcp.provider.ts +151 -151
  234. package/server/modules/providers/shared/provider-configs.ts +142 -142
  235. package/server/modules/providers/tests/mcp.test.ts +293 -293
  236. package/server/openai-codex.js +462 -462
  237. package/server/opencode-cli.js +491 -491
  238. package/server/opencode-response-handler.js +111 -111
  239. package/server/projects.js +3008 -3008
  240. package/server/qwen-code-cli.js +410 -410
  241. package/server/qwen-response-handler.js +73 -73
  242. package/server/routes/agent.js +1435 -1435
  243. package/server/routes/auth.js +142 -142
  244. package/server/routes/codex.js +20 -20
  245. package/server/routes/commands.js +538 -538
  246. package/server/routes/cursor.js +61 -61
  247. package/server/routes/diagnostics.js +41 -41
  248. package/server/routes/gemini.js +25 -25
  249. package/server/routes/git.js +1641 -1641
  250. package/server/routes/live-view.js +387 -387
  251. package/server/routes/mcp-utils.js +13 -13
  252. package/server/routes/messages.js +50 -50
  253. package/server/routes/network.js +117 -117
  254. package/server/routes/platformization.js +182 -182
  255. package/server/routes/plugins.js +320 -320
  256. package/server/routes/production-agent-loop.js +90 -90
  257. package/server/routes/projects.js +911 -911
  258. package/server/routes/public-api.js +34 -34
  259. package/server/routes/qwen.js +27 -27
  260. package/server/routes/remote.js +50 -50
  261. package/server/routes/settings.js +321 -321
  262. package/server/routes/telegram.js +140 -140
  263. package/server/routes/user.js +125 -125
  264. package/server/routes/webhooks.js +63 -63
  265. package/server/services/control-room.js +102 -102
  266. package/server/services/diagnostics.js +165 -165
  267. package/server/services/external-access.js +375 -375
  268. package/server/services/hermes-gateway.js +1562 -1562
  269. package/server/services/hermes-install-jobs.js +729 -729
  270. package/server/services/install-jobs.js +715 -715
  271. package/server/services/live-view.js +956 -956
  272. package/server/services/managed-runtimes.js +493 -493
  273. package/server/services/model-registry.js +144 -144
  274. package/server/services/notification-orchestrator.js +365 -365
  275. package/server/services/notification-taxonomy.js +204 -204
  276. package/server/services/platformization.js +773 -773
  277. package/server/services/production-agent-loop.js +248 -248
  278. package/server/services/provider-cli-versions.js +149 -149
  279. package/server/services/provider-credentials.js +189 -189
  280. package/server/services/provider-models.js +396 -396
  281. package/server/services/public-api-manifest.js +190 -190
  282. package/server/services/remote-connection.js +127 -127
  283. package/server/services/runtime-manager.js +323 -323
  284. package/server/services/startup-update.js +234 -234
  285. package/server/services/telegram/bot.js +331 -331
  286. package/server/services/telegram/control-center.js +979 -979
  287. package/server/services/telegram/telegram-http-client.js +151 -151
  288. package/server/services/telegram/translations.js +340 -340
  289. package/server/services/vapid-keys.js +36 -36
  290. package/server/services/webhooks.js +216 -216
  291. package/server/sessionManager.js +225 -225
  292. package/server/shared/interfaces.ts +54 -54
  293. package/server/shared/types.ts +172 -172
  294. package/server/shared/utils.ts +193 -193
  295. package/server/tsconfig.json +36 -36
  296. package/server/utils/colors.js +21 -21
  297. package/server/utils/commandParser.js +305 -305
  298. package/server/utils/frontmatter.js +18 -18
  299. package/server/utils/gitConfig.js +34 -34
  300. package/server/utils/plugin-loader.js +457 -457
  301. package/server/utils/plugin-process-manager.js +185 -185
  302. package/server/utils/port-access.js +209 -209
  303. package/server/utils/runtime-paths.js +37 -37
  304. package/server/utils/url-detection.js +71 -71
  305. package/server/vite-daemon.js +79 -79
  306. package/shared/modelConstants.js +161 -161
  307. package/shared/networkHosts.js +22 -22
@@ -1,1009 +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_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
- });
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
+ });