@pixelbyte-software/pixcode 1.30.1 → 1.31.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (205) hide show
  1. package/LICENSE +718 -718
  2. package/README.de.md +248 -248
  3. package/README.ja.md +240 -240
  4. package/README.ko.md +240 -240
  5. package/README.md +295 -285
  6. package/README.ru.md +248 -248
  7. package/README.tr.md +250 -250
  8. package/README.zh-CN.md +240 -240
  9. package/dist/api-docs.html +879 -879
  10. package/dist/assets/index-BRRJ47XQ.css +32 -0
  11. package/dist/assets/index-EQohwyiC.js +837 -0
  12. package/dist/clear-cache.html +85 -85
  13. package/dist/convert-icons.md +52 -52
  14. package/dist/favicon.png +0 -0
  15. package/dist/favicon.svg +7 -8
  16. package/dist/generate-icons.js +48 -48
  17. package/dist/icons/codex-white.svg +3 -3
  18. package/dist/icons/codex.svg +3 -3
  19. package/dist/icons/cursor-white.svg +11 -11
  20. package/dist/icons/icon-128x128.png +0 -0
  21. package/dist/icons/icon-128x128.svg +9 -12
  22. package/dist/icons/icon-144x144.png +0 -0
  23. package/dist/icons/icon-144x144.svg +9 -12
  24. package/dist/icons/icon-152x152.png +0 -0
  25. package/dist/icons/icon-152x152.svg +9 -12
  26. package/dist/icons/icon-192x192.png +0 -0
  27. package/dist/icons/icon-192x192.svg +9 -12
  28. package/dist/icons/icon-384x384.png +0 -0
  29. package/dist/icons/icon-384x384.svg +9 -12
  30. package/dist/icons/icon-512x512.png +0 -0
  31. package/dist/icons/icon-512x512.svg +9 -12
  32. package/dist/icons/icon-72x72.png +0 -0
  33. package/dist/icons/icon-72x72.svg +9 -12
  34. package/dist/icons/icon-96x96.png +0 -0
  35. package/dist/icons/icon-96x96.svg +9 -12
  36. package/dist/icons/icon-template.svg +9 -12
  37. package/dist/icons/qwen-ai-icon.png +0 -0
  38. package/dist/index.html +59 -49
  39. package/dist/logo.png +0 -0
  40. package/dist/logo.svg +11 -16
  41. package/dist/manifest.json +60 -60
  42. package/dist/sw.js +124 -124
  43. package/dist-server/server/cli.js +100 -97
  44. package/dist-server/server/cli.js.map +1 -1
  45. package/dist-server/server/daemon/manager.js +33 -33
  46. package/dist-server/server/daemon-manager.js +62 -62
  47. package/dist-server/server/database/db.js +114 -22
  48. package/dist-server/server/database/db.js.map +1 -1
  49. package/dist-server/server/database/schema.js +122 -89
  50. package/dist-server/server/database/schema.js.map +1 -1
  51. package/dist-server/server/gemini-cli.js +6 -1
  52. package/dist-server/server/gemini-cli.js.map +1 -1
  53. package/dist-server/server/index.js +234 -65
  54. package/dist-server/server/index.js.map +1 -1
  55. package/dist-server/server/modules/providers/list/claude/claude-auth.provider.js +29 -2
  56. package/dist-server/server/modules/providers/list/claude/claude-auth.provider.js.map +1 -1
  57. package/dist-server/server/modules/providers/list/codex/codex-auth.provider.js +22 -2
  58. package/dist-server/server/modules/providers/list/codex/codex-auth.provider.js.map +1 -1
  59. package/dist-server/server/modules/providers/list/cursor/cursor-auth.provider.js +2 -2
  60. package/dist-server/server/modules/providers/list/cursor/cursor-auth.provider.js.map +1 -1
  61. package/dist-server/server/modules/providers/list/gemini/gemini-auth.provider.js +14 -2
  62. package/dist-server/server/modules/providers/list/gemini/gemini-auth.provider.js.map +1 -1
  63. package/dist-server/server/modules/providers/list/qwen/qwen-auth.provider.js +132 -0
  64. package/dist-server/server/modules/providers/list/qwen/qwen-auth.provider.js.map +1 -0
  65. package/dist-server/server/modules/providers/list/qwen/qwen-mcp.provider.js +87 -0
  66. package/dist-server/server/modules/providers/list/qwen/qwen-mcp.provider.js.map +1 -0
  67. package/dist-server/server/modules/providers/list/qwen/qwen-sessions.provider.js +201 -0
  68. package/dist-server/server/modules/providers/list/qwen/qwen-sessions.provider.js.map +1 -0
  69. package/dist-server/server/modules/providers/list/qwen/qwen.provider.js +19 -0
  70. package/dist-server/server/modules/providers/list/qwen/qwen.provider.js.map +1 -0
  71. package/dist-server/server/modules/providers/provider.registry.js +2 -0
  72. package/dist-server/server/modules/providers/provider.registry.js.map +1 -1
  73. package/dist-server/server/modules/providers/provider.routes.js +310 -1
  74. package/dist-server/server/modules/providers/provider.routes.js.map +1 -1
  75. package/dist-server/server/projects.js +197 -6
  76. package/dist-server/server/projects.js.map +1 -1
  77. package/dist-server/server/qwen-code-cli.js +350 -0
  78. package/dist-server/server/qwen-code-cli.js.map +1 -0
  79. package/dist-server/server/qwen-response-handler.js +70 -0
  80. package/dist-server/server/qwen-response-handler.js.map +1 -0
  81. package/dist-server/server/routes/commands.js +25 -25
  82. package/dist-server/server/routes/git.js +17 -17
  83. package/dist-server/server/routes/network.js +116 -0
  84. package/dist-server/server/routes/network.js.map +1 -0
  85. package/dist-server/server/routes/projects.js +43 -0
  86. package/dist-server/server/routes/projects.js.map +1 -1
  87. package/dist-server/server/routes/qwen.js +23 -0
  88. package/dist-server/server/routes/qwen.js.map +1 -0
  89. package/dist-server/server/routes/taskmaster.js +419 -419
  90. package/dist-server/server/routes/telegram.js +119 -0
  91. package/dist-server/server/routes/telegram.js.map +1 -0
  92. package/dist-server/server/services/external-access.js +228 -0
  93. package/dist-server/server/services/external-access.js.map +1 -0
  94. package/dist-server/server/services/install-jobs.js +394 -0
  95. package/dist-server/server/services/install-jobs.js.map +1 -0
  96. package/dist-server/server/services/notification-orchestrator.js +19 -5
  97. package/dist-server/server/services/notification-orchestrator.js.map +1 -1
  98. package/dist-server/server/services/provider-credentials.js +154 -0
  99. package/dist-server/server/services/provider-credentials.js.map +1 -0
  100. package/dist-server/server/services/provider-models.js +218 -0
  101. package/dist-server/server/services/provider-models.js.map +1 -0
  102. package/dist-server/server/services/telegram/bot.js +259 -0
  103. package/dist-server/server/services/telegram/bot.js.map +1 -0
  104. package/dist-server/server/services/telegram/translations.js +160 -0
  105. package/dist-server/server/services/telegram/translations.js.map +1 -0
  106. package/dist-server/server/utils/port-access.js +196 -0
  107. package/dist-server/server/utils/port-access.js.map +1 -0
  108. package/dist-server/shared/modelConstants.js +18 -0
  109. package/dist-server/shared/modelConstants.js.map +1 -1
  110. package/package.json +177 -168
  111. package/scripts/fix-node-pty.js +67 -67
  112. package/server/claude-sdk.js +834 -834
  113. package/server/cli.js +940 -937
  114. package/server/constants/config.js +4 -4
  115. package/server/cursor-cli.js +342 -342
  116. package/server/daemon/manager.js +564 -564
  117. package/server/daemon-manager.js +920 -920
  118. package/server/database/db.js +696 -593
  119. package/server/database/schema.js +138 -102
  120. package/server/gemini-cli.js +475 -469
  121. package/server/gemini-response-handler.js +79 -79
  122. package/server/index.js +2730 -2557
  123. package/server/load-env.js +34 -34
  124. package/server/middleware/auth.js +132 -132
  125. package/server/modules/providers/list/claude/claude-auth.provider.ts +145 -123
  126. package/server/modules/providers/list/claude/claude-mcp.provider.ts +135 -135
  127. package/server/modules/providers/list/claude/claude-sessions.provider.ts +306 -306
  128. package/server/modules/providers/list/claude/claude.provider.ts +15 -15
  129. package/server/modules/providers/list/codex/codex-auth.provider.ts +115 -100
  130. package/server/modules/providers/list/codex/codex-mcp.provider.ts +135 -135
  131. package/server/modules/providers/list/codex/codex-sessions.provider.ts +319 -319
  132. package/server/modules/providers/list/codex/codex.provider.ts +15 -15
  133. package/server/modules/providers/list/cursor/cursor-auth.provider.ts +143 -143
  134. package/server/modules/providers/list/cursor/cursor-mcp.provider.ts +108 -108
  135. package/server/modules/providers/list/cursor/cursor-sessions.provider.ts +421 -421
  136. package/server/modules/providers/list/cursor/cursor.provider.ts +15 -15
  137. package/server/modules/providers/list/gemini/gemini-auth.provider.ts +163 -151
  138. package/server/modules/providers/list/gemini/gemini-mcp.provider.ts +110 -110
  139. package/server/modules/providers/list/gemini/gemini-sessions.provider.ts +227 -227
  140. package/server/modules/providers/list/gemini/gemini.provider.ts +15 -15
  141. package/server/modules/providers/list/qwen/qwen-auth.provider.ts +145 -0
  142. package/server/modules/providers/list/qwen/qwen-mcp.provider.ts +114 -0
  143. package/server/modules/providers/list/qwen/qwen-sessions.provider.ts +218 -0
  144. package/server/modules/providers/list/qwen/qwen.provider.ts +21 -0
  145. package/server/modules/providers/provider.registry.ts +38 -36
  146. package/server/modules/providers/provider.routes.ts +583 -217
  147. package/server/modules/providers/services/mcp.service.ts +94 -94
  148. package/server/modules/providers/services/provider-auth.service.ts +26 -26
  149. package/server/modules/providers/services/sessions.service.ts +45 -45
  150. package/server/modules/providers/shared/base/abstract.provider.ts +20 -20
  151. package/server/modules/providers/shared/mcp/mcp.provider.ts +151 -151
  152. package/server/modules/providers/tests/mcp.test.ts +293 -293
  153. package/server/openai-codex.js +426 -426
  154. package/server/projects.js +2993 -2792
  155. package/server/qwen-code-cli.js +392 -0
  156. package/server/qwen-response-handler.js +73 -0
  157. package/server/routes/agent.js +1245 -1245
  158. package/server/routes/auth.js +134 -134
  159. package/server/routes/codex.js +19 -19
  160. package/server/routes/commands.js +554 -554
  161. package/server/routes/cursor.js +52 -52
  162. package/server/routes/gemini.js +24 -24
  163. package/server/routes/git.js +1488 -1488
  164. package/server/routes/mcp-utils.js +31 -31
  165. package/server/routes/messages.js +61 -61
  166. package/server/routes/network.js +128 -0
  167. package/server/routes/plugins.js +307 -307
  168. package/server/routes/projects.js +675 -627
  169. package/server/routes/qwen.js +27 -0
  170. package/server/routes/settings.js +286 -286
  171. package/server/routes/taskmaster.js +1471 -1471
  172. package/server/routes/telegram.js +125 -0
  173. package/server/routes/user.js +123 -123
  174. package/server/services/external-access.js +240 -0
  175. package/server/services/install-jobs.js +410 -0
  176. package/server/services/notification-orchestrator.js +242 -227
  177. package/server/services/provider-credentials.js +151 -0
  178. package/server/services/provider-models.js +225 -0
  179. package/server/services/telegram/bot.js +280 -0
  180. package/server/services/telegram/translations.js +170 -0
  181. package/server/services/vapid-keys.js +35 -35
  182. package/server/sessionManager.js +225 -225
  183. package/server/shared/interfaces.ts +54 -54
  184. package/server/shared/types.ts +172 -172
  185. package/server/shared/utils.ts +193 -193
  186. package/server/tsconfig.json +36 -36
  187. package/server/utils/colors.js +21 -21
  188. package/server/utils/commandParser.js +303 -303
  189. package/server/utils/frontmatter.js +18 -18
  190. package/server/utils/gitConfig.js +34 -34
  191. package/server/utils/mcp-detector.js +147 -147
  192. package/server/utils/plugin-loader.js +457 -457
  193. package/server/utils/plugin-process-manager.js +184 -184
  194. package/server/utils/port-access.js +209 -0
  195. package/server/utils/runtime-paths.js +37 -37
  196. package/server/utils/taskmaster-websocket.js +128 -128
  197. package/server/utils/url-detection.js +71 -71
  198. package/server/vite-daemon.js +78 -78
  199. package/shared/modelConstants.js +117 -97
  200. package/shared/networkHosts.js +22 -22
  201. package/dist/assets/index-C2c9QNwK.css +0 -32
  202. package/dist/assets/index-DyXDZED-.js +0 -1277
  203. package/dist-server/server/routes/cli-auth.js +0 -25
  204. package/dist-server/server/routes/cli-auth.js.map +0 -1
  205. package/server/routes/cli-auth.js +0 -27
@@ -1,184 +1,184 @@
1
- import { spawn } from 'child_process';
2
- import path from 'path';
3
- import { scanPlugins, getPluginsConfig, getPluginDir } from './plugin-loader.js';
4
-
5
- // Map<pluginName, { process, port }>
6
- const runningPlugins = new Map();
7
- // Map<pluginName, Promise<port>> — in-flight start operations
8
- const startingPlugins = new Map();
9
-
10
- /**
11
- * Start a plugin's server subprocess.
12
- * The plugin's server entry must print a JSON line with { ready: true, port: <number> }
13
- * to stdout within 10 seconds.
14
- */
15
- export function startPluginServer(name, pluginDir, serverEntry) {
16
- if (runningPlugins.has(name)) {
17
- return Promise.resolve(runningPlugins.get(name).port);
18
- }
19
-
20
- // Coalesce concurrent starts for the same plugin
21
- if (startingPlugins.has(name)) {
22
- return startingPlugins.get(name);
23
- }
24
-
25
- const startPromise = new Promise((resolve, reject) => {
26
-
27
- const serverPath = path.join(pluginDir, serverEntry);
28
-
29
- // Restricted env — only essentials, no host secrets
30
- const pluginProcess = spawn('node', [serverPath], {
31
- cwd: pluginDir,
32
- env: {
33
- PATH: process.env.PATH,
34
- HOME: process.env.HOME,
35
- NODE_ENV: process.env.NODE_ENV || 'production',
36
- PLUGIN_NAME: name,
37
- },
38
- stdio: ['ignore', 'pipe', 'pipe'],
39
- });
40
-
41
- let resolved = false;
42
- let stdout = '';
43
-
44
- const timeout = setTimeout(() => {
45
- if (!resolved) {
46
- resolved = true;
47
- pluginProcess.kill();
48
- reject(new Error('Plugin server did not report ready within 10 seconds'));
49
- }
50
- }, 10000);
51
-
52
- pluginProcess.stdout.on('data', (data) => {
53
- if (resolved) return;
54
- stdout += data.toString();
55
-
56
- // Look for the JSON ready line
57
- const lines = stdout.split('\n');
58
- for (const line of lines) {
59
- try {
60
- const msg = JSON.parse(line.trim());
61
- if (msg.ready && typeof msg.port === 'number') {
62
- clearTimeout(timeout);
63
- resolved = true;
64
- runningPlugins.set(name, { process: pluginProcess, port: msg.port });
65
-
66
- pluginProcess.on('exit', () => {
67
- runningPlugins.delete(name);
68
- });
69
-
70
- console.log(`[Plugins] Server started for "${name}" on port ${msg.port}`);
71
- resolve(msg.port);
72
- }
73
- } catch {
74
- // Not JSON yet, keep buffering
75
- }
76
- }
77
- });
78
-
79
- pluginProcess.stderr.on('data', (data) => {
80
- console.warn(`[Plugin:${name}] ${data.toString().trim()}`);
81
- });
82
-
83
- pluginProcess.on('error', (err) => {
84
- clearTimeout(timeout);
85
- if (!resolved) {
86
- resolved = true;
87
- reject(new Error(`Failed to start plugin server: ${err.message}`));
88
- }
89
- });
90
-
91
- pluginProcess.on('exit', (code) => {
92
- clearTimeout(timeout);
93
- runningPlugins.delete(name);
94
- if (!resolved) {
95
- resolved = true;
96
- reject(new Error(`Plugin server exited with code ${code} before reporting ready`));
97
- }
98
- });
99
- }).finally(() => {
100
- startingPlugins.delete(name);
101
- });
102
-
103
- startingPlugins.set(name, startPromise);
104
- return startPromise;
105
- }
106
-
107
- /**
108
- * Stop a plugin's server subprocess.
109
- * Returns a Promise that resolves when the process has fully exited.
110
- */
111
- export function stopPluginServer(name) {
112
- const entry = runningPlugins.get(name);
113
- if (!entry) return Promise.resolve();
114
-
115
- return new Promise((resolve) => {
116
- const cleanup = () => {
117
- clearTimeout(forceKillTimer);
118
- runningPlugins.delete(name);
119
- resolve();
120
- };
121
-
122
- entry.process.once('exit', cleanup);
123
-
124
- entry.process.kill('SIGTERM');
125
-
126
- // Force kill after 5 seconds if still running
127
- const forceKillTimer = setTimeout(() => {
128
- if (runningPlugins.has(name)) {
129
- entry.process.kill('SIGKILL');
130
- cleanup();
131
- }
132
- }, 5000);
133
-
134
- console.log(`[Plugins] Server stopped for "${name}"`);
135
- });
136
- }
137
-
138
- /**
139
- * Get the port a running plugin server is listening on.
140
- */
141
- export function getPluginPort(name) {
142
- return runningPlugins.get(name)?.port ?? null;
143
- }
144
-
145
- /**
146
- * Check if a plugin's server is running.
147
- */
148
- export function isPluginRunning(name) {
149
- return runningPlugins.has(name);
150
- }
151
-
152
- /**
153
- * Stop all running plugin servers (called on host shutdown).
154
- */
155
- export function stopAllPlugins() {
156
- const stops = [];
157
- for (const [name] of runningPlugins) {
158
- stops.push(stopPluginServer(name));
159
- }
160
- return Promise.all(stops);
161
- }
162
-
163
- /**
164
- * Start servers for all enabled plugins that have a server entry.
165
- * Called once on host server boot.
166
- */
167
- export async function startEnabledPluginServers() {
168
- const plugins = scanPlugins();
169
- const config = getPluginsConfig();
170
-
171
- for (const plugin of plugins) {
172
- if (!plugin.server) continue;
173
- if (config[plugin.name]?.enabled === false) continue;
174
-
175
- const pluginDir = getPluginDir(plugin.name);
176
- if (!pluginDir) continue;
177
-
178
- try {
179
- await startPluginServer(plugin.name, pluginDir, plugin.server);
180
- } catch (err) {
181
- console.error(`[Plugins] Failed to start server for "${plugin.name}":`, err.message);
182
- }
183
- }
184
- }
1
+ import { spawn } from 'child_process';
2
+ import path from 'path';
3
+ import { scanPlugins, getPluginsConfig, getPluginDir } from './plugin-loader.js';
4
+
5
+ // Map<pluginName, { process, port }>
6
+ const runningPlugins = new Map();
7
+ // Map<pluginName, Promise<port>> — in-flight start operations
8
+ const startingPlugins = new Map();
9
+
10
+ /**
11
+ * Start a plugin's server subprocess.
12
+ * The plugin's server entry must print a JSON line with { ready: true, port: <number> }
13
+ * to stdout within 10 seconds.
14
+ */
15
+ export function startPluginServer(name, pluginDir, serverEntry) {
16
+ if (runningPlugins.has(name)) {
17
+ return Promise.resolve(runningPlugins.get(name).port);
18
+ }
19
+
20
+ // Coalesce concurrent starts for the same plugin
21
+ if (startingPlugins.has(name)) {
22
+ return startingPlugins.get(name);
23
+ }
24
+
25
+ const startPromise = new Promise((resolve, reject) => {
26
+
27
+ const serverPath = path.join(pluginDir, serverEntry);
28
+
29
+ // Restricted env — only essentials, no host secrets
30
+ const pluginProcess = spawn('node', [serverPath], {
31
+ cwd: pluginDir,
32
+ env: {
33
+ PATH: process.env.PATH,
34
+ HOME: process.env.HOME,
35
+ NODE_ENV: process.env.NODE_ENV || 'production',
36
+ PLUGIN_NAME: name,
37
+ },
38
+ stdio: ['ignore', 'pipe', 'pipe'],
39
+ });
40
+
41
+ let resolved = false;
42
+ let stdout = '';
43
+
44
+ const timeout = setTimeout(() => {
45
+ if (!resolved) {
46
+ resolved = true;
47
+ pluginProcess.kill();
48
+ reject(new Error('Plugin server did not report ready within 10 seconds'));
49
+ }
50
+ }, 10000);
51
+
52
+ pluginProcess.stdout.on('data', (data) => {
53
+ if (resolved) return;
54
+ stdout += data.toString();
55
+
56
+ // Look for the JSON ready line
57
+ const lines = stdout.split('\n');
58
+ for (const line of lines) {
59
+ try {
60
+ const msg = JSON.parse(line.trim());
61
+ if (msg.ready && typeof msg.port === 'number') {
62
+ clearTimeout(timeout);
63
+ resolved = true;
64
+ runningPlugins.set(name, { process: pluginProcess, port: msg.port });
65
+
66
+ pluginProcess.on('exit', () => {
67
+ runningPlugins.delete(name);
68
+ });
69
+
70
+ console.log(`[Plugins] Server started for "${name}" on port ${msg.port}`);
71
+ resolve(msg.port);
72
+ }
73
+ } catch {
74
+ // Not JSON yet, keep buffering
75
+ }
76
+ }
77
+ });
78
+
79
+ pluginProcess.stderr.on('data', (data) => {
80
+ console.warn(`[Plugin:${name}] ${data.toString().trim()}`);
81
+ });
82
+
83
+ pluginProcess.on('error', (err) => {
84
+ clearTimeout(timeout);
85
+ if (!resolved) {
86
+ resolved = true;
87
+ reject(new Error(`Failed to start plugin server: ${err.message}`));
88
+ }
89
+ });
90
+
91
+ pluginProcess.on('exit', (code) => {
92
+ clearTimeout(timeout);
93
+ runningPlugins.delete(name);
94
+ if (!resolved) {
95
+ resolved = true;
96
+ reject(new Error(`Plugin server exited with code ${code} before reporting ready`));
97
+ }
98
+ });
99
+ }).finally(() => {
100
+ startingPlugins.delete(name);
101
+ });
102
+
103
+ startingPlugins.set(name, startPromise);
104
+ return startPromise;
105
+ }
106
+
107
+ /**
108
+ * Stop a plugin's server subprocess.
109
+ * Returns a Promise that resolves when the process has fully exited.
110
+ */
111
+ export function stopPluginServer(name) {
112
+ const entry = runningPlugins.get(name);
113
+ if (!entry) return Promise.resolve();
114
+
115
+ return new Promise((resolve) => {
116
+ const cleanup = () => {
117
+ clearTimeout(forceKillTimer);
118
+ runningPlugins.delete(name);
119
+ resolve();
120
+ };
121
+
122
+ entry.process.once('exit', cleanup);
123
+
124
+ entry.process.kill('SIGTERM');
125
+
126
+ // Force kill after 5 seconds if still running
127
+ const forceKillTimer = setTimeout(() => {
128
+ if (runningPlugins.has(name)) {
129
+ entry.process.kill('SIGKILL');
130
+ cleanup();
131
+ }
132
+ }, 5000);
133
+
134
+ console.log(`[Plugins] Server stopped for "${name}"`);
135
+ });
136
+ }
137
+
138
+ /**
139
+ * Get the port a running plugin server is listening on.
140
+ */
141
+ export function getPluginPort(name) {
142
+ return runningPlugins.get(name)?.port ?? null;
143
+ }
144
+
145
+ /**
146
+ * Check if a plugin's server is running.
147
+ */
148
+ export function isPluginRunning(name) {
149
+ return runningPlugins.has(name);
150
+ }
151
+
152
+ /**
153
+ * Stop all running plugin servers (called on host shutdown).
154
+ */
155
+ export function stopAllPlugins() {
156
+ const stops = [];
157
+ for (const [name] of runningPlugins) {
158
+ stops.push(stopPluginServer(name));
159
+ }
160
+ return Promise.all(stops);
161
+ }
162
+
163
+ /**
164
+ * Start servers for all enabled plugins that have a server entry.
165
+ * Called once on host server boot.
166
+ */
167
+ export async function startEnabledPluginServers() {
168
+ const plugins = scanPlugins();
169
+ const config = getPluginsConfig();
170
+
171
+ for (const plugin of plugins) {
172
+ if (!plugin.server) continue;
173
+ if (config[plugin.name]?.enabled === false) continue;
174
+
175
+ const pluginDir = getPluginDir(plugin.name);
176
+ if (!pluginDir) continue;
177
+
178
+ try {
179
+ await startPluginServer(plugin.name, pluginDir, plugin.server);
180
+ } catch (err) {
181
+ console.error(`[Plugins] Failed to start server for "${plugin.name}":`, err.message);
182
+ }
183
+ }
184
+ }
@@ -0,0 +1,209 @@
1
+ import os from 'os';
2
+ import fs from 'fs';
3
+ import path from 'path';
4
+ import readline from 'readline';
5
+ import { execSync } from 'child_process';
6
+
7
+ import { c } from './colors.js';
8
+
9
+ /**
10
+ * Tracks inbound port access decisions across runs so the server doesn't
11
+ * re-prompt the user (on Windows/macOS) every start, and can skip work on
12
+ * Linux where a rule has already been applied.
13
+ */
14
+ const STATE_FILE = path.join(os.homedir(), '.pixcode', 'port-access.json');
15
+
16
+ function loadState() {
17
+ try {
18
+ return JSON.parse(fs.readFileSync(STATE_FILE, 'utf8'));
19
+ } catch {
20
+ return {};
21
+ }
22
+ }
23
+
24
+ function saveState(state) {
25
+ try {
26
+ fs.mkdirSync(path.dirname(STATE_FILE), { recursive: true });
27
+ fs.writeFileSync(STATE_FILE, JSON.stringify(state, null, 2));
28
+ } catch {
29
+ // Persisting the decision is a nice-to-have; failure shouldn't block start.
30
+ }
31
+ }
32
+
33
+ /** Return all non-loopback IPv4 addresses assigned to this host. */
34
+ export function getLanIps() {
35
+ const ifs = os.networkInterfaces();
36
+ const ips = [];
37
+ for (const name of Object.keys(ifs)) {
38
+ for (const ni of ifs[name] || []) {
39
+ if (ni.family === 'IPv4' && !ni.internal) ips.push(ni.address);
40
+ }
41
+ }
42
+ return ips;
43
+ }
44
+
45
+ function askYN(question) {
46
+ return new Promise((resolve) => {
47
+ if (!process.stdin.isTTY || !process.stdout.isTTY) {
48
+ resolve(null); // headless / daemon context — skip
49
+ return;
50
+ }
51
+ const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
52
+ rl.question(question, (answer) => {
53
+ rl.close();
54
+ const normalized = answer.trim().toLowerCase();
55
+ resolve(['y', 'yes', 'e', 'evet'].includes(normalized));
56
+ });
57
+ });
58
+ }
59
+
60
+ // ---------------- Linux ----------------
61
+
62
+ function tryUfw(port) {
63
+ try {
64
+ execSync('command -v ufw', { stdio: 'pipe' });
65
+ const status = execSync('ufw status', { stdio: 'pipe', encoding: 'utf8' });
66
+ // UFW inactive = no rule needed; the port is already reachable.
67
+ if (!/active/i.test(status)) return 'inactive';
68
+ execSync(`sudo -n ufw allow ${port}/tcp`, { stdio: 'pipe' });
69
+ return 'applied';
70
+ } catch {
71
+ return null;
72
+ }
73
+ }
74
+
75
+ function tryFirewalld(port) {
76
+ try {
77
+ execSync('command -v firewall-cmd', { stdio: 'pipe' });
78
+ const state = execSync('firewall-cmd --state', { stdio: 'pipe', encoding: 'utf8' });
79
+ if (!/running/i.test(state)) return 'inactive';
80
+ execSync(`sudo -n firewall-cmd --add-port=${port}/tcp --permanent`, { stdio: 'pipe' });
81
+ execSync('sudo -n firewall-cmd --reload', { stdio: 'pipe' });
82
+ return 'applied';
83
+ } catch {
84
+ return null;
85
+ }
86
+ }
87
+
88
+ // ---------------- Windows ----------------
89
+
90
+ function applyWindowsRule(port) {
91
+ const ruleName = `Pixcode-${port}`;
92
+ const cmd = `netsh advfirewall firewall add rule name="${ruleName}" dir=in action=allow protocol=TCP localport=${port}`;
93
+ try {
94
+ execSync(cmd, { stdio: 'pipe' });
95
+ return { ok: true, cmd, ruleName };
96
+ } catch (error) {
97
+ return { ok: false, cmd, ruleName, error: error.message };
98
+ }
99
+ }
100
+
101
+ // ---------------- macOS ----------------
102
+
103
+ function macFirewallHint(port) {
104
+ return [
105
+ `${c.tip('[TIP]')} macOS Application Firewall is per-app, not per-port.`,
106
+ ' If other devices can\'t connect, open:',
107
+ ' System Settings > Network > Firewall > Options',
108
+ ` and add Node.js to "Allow incoming connections" (port ${port}).`,
109
+ ].join('\n');
110
+ }
111
+
112
+ // ---------------- Main entry ----------------
113
+
114
+ /**
115
+ * Make sure inbound traffic can reach `port` from the local network.
116
+ *
117
+ * - Linux: silently try ufw/firewalld with `sudo -n` (passwordless). Skips
118
+ * cleanly when no firewall is running or sudo is gated — LAN access
119
+ * already works on most desktop distros.
120
+ * - Windows/macOS: ask the user once; remember the decision in
121
+ * ~/.pixcode/port-access.json so subsequent starts stay quiet.
122
+ *
123
+ * All failure paths are non-fatal: the server is already listening when
124
+ * we get here, and LAN clients on the same subnet often can reach it
125
+ * without any firewall change.
126
+ */
127
+ export async function ensurePortOpen(port) {
128
+ const state = loadState();
129
+ const key = `port:${port}`;
130
+ const entry = state[key];
131
+
132
+ const lanIps = getLanIps();
133
+ if (lanIps.length) {
134
+ console.log(`${c.info('[INFO]')} LAN access: ${c.bright(`http://${lanIps[0]}:${port}`)}`);
135
+ if (lanIps.length > 1) {
136
+ for (const extra of lanIps.slice(1)) {
137
+ console.log(`${c.dim(' also:')} http://${extra}:${port}`);
138
+ }
139
+ }
140
+ }
141
+
142
+ if (entry && entry.decision === 'deny') {
143
+ console.log(`${c.dim('[INFO]')} Firewall prompt suppressed (previously declined). Re-enable via ~/.pixcode/port-access.json`);
144
+ return;
145
+ }
146
+
147
+ const platform = process.platform;
148
+
149
+ if (platform === 'linux') {
150
+ if (entry && entry.status === 'applied') return;
151
+ const result = tryUfw(port) || tryFirewalld(port);
152
+ if (result === 'applied') {
153
+ console.log(`${c.ok('[OK]')} Inbound firewall rule added for port ${port}.`);
154
+ saveState({ ...state, [key]: { decision: 'allow', status: 'applied', via: 'linux' } });
155
+ } else if (result === 'inactive') {
156
+ console.log(`${c.dim('[INFO]')} No active firewall detected — port ${port} should be reachable.`);
157
+ } else {
158
+ console.log(`${c.tip('[TIP]')} Couldn't auto-open port (no sudo / unsupported firewall).`);
159
+ console.log(` Manual: ${c.bright(`sudo ufw allow ${port}/tcp`)} ${c.dim('(or firewall-cmd equivalent)')}`);
160
+ }
161
+ return;
162
+ }
163
+
164
+ if (platform === 'win32') {
165
+ if (entry && entry.status === 'applied') return;
166
+ const approved = await askYN(
167
+ `${c.tip('[?]')} Open port ${port} in Windows Firewall so other devices on your network can connect? [y/N] `,
168
+ );
169
+ if (approved === null) {
170
+ // No TTY — just show the manual command and move on.
171
+ console.log(
172
+ `${c.tip('[TIP]')} To allow LAN access, run this in an elevated PowerShell:\n ${c.bright(
173
+ `netsh advfirewall firewall add rule name="Pixcode-${port}" dir=in action=allow protocol=TCP localport=${port}`,
174
+ )}`,
175
+ );
176
+ return;
177
+ }
178
+ if (!approved) {
179
+ console.log(`${c.dim('[INFO]')} Skipping firewall change.`);
180
+ saveState({ ...state, [key]: { decision: 'deny' } });
181
+ return;
182
+ }
183
+ const result = applyWindowsRule(port);
184
+ if (result.ok) {
185
+ console.log(`${c.ok('[OK]')} Firewall rule "${result.ruleName}" added.`);
186
+ saveState({ ...state, [key]: { decision: 'allow', status: 'applied', via: 'windows' } });
187
+ } else {
188
+ console.log(`${c.tip('[TIP]')} Adding the rule needs Administrator. Run this in an elevated PowerShell:`);
189
+ console.log(` ${c.bright(result.cmd)}`);
190
+ saveState({ ...state, [key]: { decision: 'allow', status: 'manual' } });
191
+ }
192
+ return;
193
+ }
194
+
195
+ if (platform === 'darwin') {
196
+ if (entry && entry.status) return;
197
+ const approved = await askYN(
198
+ `${c.tip('[?]')} Allow inbound connections on port ${port} through macOS firewall? [y/N] `,
199
+ );
200
+ if (approved === null) return;
201
+ if (!approved) {
202
+ console.log(`${c.dim('[INFO]')} Skipping firewall hint.`);
203
+ saveState({ ...state, [key]: { decision: 'deny' } });
204
+ return;
205
+ }
206
+ console.log(macFirewallHint(port));
207
+ saveState({ ...state, [key]: { decision: 'allow', status: 'manual', via: 'macos' } });
208
+ }
209
+ }
@@ -1,37 +1,37 @@
1
- import path from 'path';
2
- import { fileURLToPath } from 'url';
3
-
4
- export function getModuleDir(importMetaUrl) {
5
- return path.dirname(fileURLToPath(importMetaUrl));
6
- }
7
-
8
- export function findServerRoot(startDir) {
9
- // Source files live under /server, while compiled files live under /dist-server/server.
10
- // Walking up to the nearest "server" folder gives every backend module one stable anchor
11
- // that works in both layouts instead of relying on fragile "../.." assumptions.
12
- let currentDir = startDir;
13
-
14
- while (path.basename(currentDir) !== 'server') {
15
- const parentDir = path.dirname(currentDir);
16
-
17
- if (parentDir === currentDir) {
18
- throw new Error(`Could not resolve the backend server root from "${startDir}".`);
19
- }
20
-
21
- currentDir = parentDir;
22
- }
23
-
24
- return currentDir;
25
- }
26
-
27
- export function findAppRoot(startDir) {
28
- const serverRoot = findServerRoot(startDir);
29
- const parentOfServerRoot = path.dirname(serverRoot);
30
-
31
- // Source files live at <app>/server, while compiled files live at <app>/dist-server/server.
32
- // When the nearest server folder sits inside dist-server we need to hop one extra level up
33
- // so repo-level files still resolve from the real app root instead of the build directory.
34
- return path.basename(parentOfServerRoot) === 'dist-server'
35
- ? path.dirname(parentOfServerRoot)
36
- : parentOfServerRoot;
37
- }
1
+ import path from 'path';
2
+ import { fileURLToPath } from 'url';
3
+
4
+ export function getModuleDir(importMetaUrl) {
5
+ return path.dirname(fileURLToPath(importMetaUrl));
6
+ }
7
+
8
+ export function findServerRoot(startDir) {
9
+ // Source files live under /server, while compiled files live under /dist-server/server.
10
+ // Walking up to the nearest "server" folder gives every backend module one stable anchor
11
+ // that works in both layouts instead of relying on fragile "../.." assumptions.
12
+ let currentDir = startDir;
13
+
14
+ while (path.basename(currentDir) !== 'server') {
15
+ const parentDir = path.dirname(currentDir);
16
+
17
+ if (parentDir === currentDir) {
18
+ throw new Error(`Could not resolve the backend server root from "${startDir}".`);
19
+ }
20
+
21
+ currentDir = parentDir;
22
+ }
23
+
24
+ return currentDir;
25
+ }
26
+
27
+ export function findAppRoot(startDir) {
28
+ const serverRoot = findServerRoot(startDir);
29
+ const parentOfServerRoot = path.dirname(serverRoot);
30
+
31
+ // Source files live at <app>/server, while compiled files live at <app>/dist-server/server.
32
+ // When the nearest server folder sits inside dist-server we need to hop one extra level up
33
+ // so repo-level files still resolve from the real app root instead of the build directory.
34
+ return path.basename(parentOfServerRoot) === 'dist-server'
35
+ ? path.dirname(parentOfServerRoot)
36
+ : parentOfServerRoot;
37
+ }