upfynai-code 3.0.4 → 3.2.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 (258) hide show
  1. package/README.md +69 -92
  2. package/bin/cli.js +191 -0
  3. package/dist/client/assets/AppContent-M14Au3SB.js +542 -0
  4. package/{client/dist/assets/BrowserPanel-0TLEl-IC.js → dist/client/assets/BrowserPanel-TFKm2NDJ.js} +2 -2
  5. package/dist/client/assets/DashboardPanel-C88HjsCh.js +1 -0
  6. package/dist/client/assets/FileTree-DvO1xnDE.js +1 -0
  7. package/{client/dist/assets/GitPanel-C_xFM-N2.js → dist/client/assets/GitPanel-D-slVlyy.js} +2 -2
  8. package/dist/client/assets/LoginModal-Chi4SYcr.js +21 -0
  9. package/{client/dist/assets/MarkdownPreview-CESjI261.js → dist/client/assets/MarkdownPreview-CuIix2u9.js} +1 -1
  10. package/dist/client/assets/MermaidBlock-Dq9uFv82.js +2 -0
  11. package/dist/client/assets/Onboarding-QYXx24dX.js +1 -0
  12. package/{client/dist/assets/PreviewPanel-CqCa92Tf.js → dist/client/assets/PreviewPanel-Dd8q-jo0.js} +1 -1
  13. package/dist/client/assets/SetupForm-CrspaUva.js +1 -0
  14. package/dist/client/assets/WorkflowsPanel-DIlYAdhB.js +1 -0
  15. package/dist/client/assets/index-CnNNzw9A.css +1 -0
  16. package/{client/dist/assets/index-HaY-3pK1.js → dist/client/assets/index-rUkK9FDP.js} +26 -26
  17. package/{client/dist/assets/vendor-codemirror-D2ALgpaX.js → dist/client/assets/vendor-codemirror-jc6nyJQg.js} +1 -1
  18. package/{client/dist/assets/vendor-diff-DNQpbhrT.js → dist/client/assets/vendor-diff-THJmAcEI.js} +1 -1
  19. package/{client/dist/assets/vendor-icons-GyYE35HP.js → dist/client/assets/vendor-icons-CfjIpdrD.js} +145 -155
  20. package/{client/dist/assets/vendor-markdown-CimbIo6Y.js → dist/client/assets/vendor-markdown-Cdm6NEGf.js} +1 -1
  21. package/dist/client/assets/vendor-mermaid-DTPaBx-U.js +2559 -0
  22. package/{client/dist/assets/vendor-react-96lCPsRK.js → dist/client/assets/vendor-react-wFkb6mSf.js} +1 -1
  23. package/{client/dist/assets/vendor-syntax-LS_Nt30I.js → dist/client/assets/vendor-syntax-C_UZR7tc.js} +1 -1
  24. package/dist/client/favicon.png +0 -0
  25. package/dist/client/icons/icon-128x128.png +0 -0
  26. package/dist/client/icons/icon-144x144.png +0 -0
  27. package/dist/client/icons/icon-152x152.png +0 -0
  28. package/dist/client/icons/icon-192x192.png +0 -0
  29. package/dist/client/icons/icon-384x384.png +0 -0
  30. package/dist/client/icons/icon-512x512.png +0 -0
  31. package/dist/client/icons/icon-72x72.png +0 -0
  32. package/dist/client/icons/icon-96x96.png +0 -0
  33. package/{client/dist → dist/client}/index.html +37 -36
  34. package/dist/client/logo-128.png +0 -0
  35. package/dist/client/logo-256.png +0 -0
  36. package/dist/client/logo-32.png +0 -0
  37. package/dist/client/logo-512.png +0 -0
  38. package/dist/client/logo-64.png +0 -0
  39. package/dist/client/logo.png +0 -0
  40. package/{client/dist → dist/client}/manifest.json +12 -12
  41. package/{client/dist → dist/client}/mcp-docs.html +1 -1
  42. package/{client/dist → dist/client}/sw.js +2 -2
  43. package/package.json +56 -105
  44. package/scripts/postinstall.js +9 -0
  45. package/scripts/prepublish.js +77 -0
  46. package/src/animation.js +228 -0
  47. package/src/auth.js +142 -0
  48. package/src/config.js +40 -0
  49. package/src/connect.js +416 -0
  50. package/src/launch.js +81 -0
  51. package/src/mcp.js +57 -0
  52. package/src/permissions.js +140 -0
  53. package/src/persistent-shell.js +261 -0
  54. package/src/server.js +54 -0
  55. package/client/dist/assets/AppContent-CwrTP6TW.js +0 -545
  56. package/client/dist/assets/CanvasFullScreen-D1GWQsGL.js +0 -1
  57. package/client/dist/assets/CanvasWorkspace-D7ORj358.js +0 -163
  58. package/client/dist/assets/DashboardPanel-BV7ybUDe.js +0 -1
  59. package/client/dist/assets/FileTree-5qfhBqdE.js +0 -1
  60. package/client/dist/assets/LoginModal-CImJHRjX.js +0 -13
  61. package/client/dist/assets/MermaidBlock-BFM21cwe.js +0 -2
  62. package/client/dist/assets/Onboarding-B3cteLu2.js +0 -1
  63. package/client/dist/assets/SetupForm-P6dsYgHO.js +0 -1
  64. package/client/dist/assets/WorkflowsPanel-CBoN80kc.js +0 -1
  65. package/client/dist/assets/index-46kkVu2i.css +0 -1
  66. package/client/dist/assets/pdf-CE_K4jFx.js +0 -12
  67. package/client/dist/assets/vendor-canvas-BZV40eAE.css +0 -1
  68. package/client/dist/assets/vendor-canvas-DvHJ_Pn2.js +0 -49
  69. package/client/dist/assets/vendor-mermaid-DucWyDEe.js +0 -2556
  70. package/client/dist/favicon.png +0 -0
  71. package/client/dist/icons/icon-128x128.png +0 -0
  72. package/client/dist/icons/icon-144x144.png +0 -0
  73. package/client/dist/icons/icon-152x152.png +0 -0
  74. package/client/dist/icons/icon-192x192.png +0 -0
  75. package/client/dist/icons/icon-384x384.png +0 -0
  76. package/client/dist/icons/icon-512x512.png +0 -0
  77. package/client/dist/icons/icon-72x72.png +0 -0
  78. package/client/dist/icons/icon-96x96.png +0 -0
  79. package/client/dist/logo-128.png +0 -0
  80. package/client/dist/logo-256.png +0 -0
  81. package/client/dist/logo-32.png +0 -0
  82. package/client/dist/logo-512.png +0 -0
  83. package/client/dist/logo-64.png +0 -0
  84. package/commands/upfynai-connect.md +0 -59
  85. package/commands/upfynai-disconnect.md +0 -31
  86. package/commands/upfynai-doctor.md +0 -99
  87. package/commands/upfynai-export.md +0 -49
  88. package/commands/upfynai-local.md +0 -82
  89. package/commands/upfynai-status.md +0 -75
  90. package/commands/upfynai-stop.md +0 -49
  91. package/commands/upfynai-uninstall.md +0 -58
  92. package/commands/upfynai.md +0 -69
  93. package/scripts/build-client.js +0 -17
  94. package/scripts/fix-node-pty.js +0 -67
  95. package/scripts/install-commands.js +0 -78
  96. package/server/agent-loop.js +0 -242
  97. package/server/auto-compact.js +0 -99
  98. package/server/browser.js +0 -131
  99. package/server/claude-sdk.js +0 -797
  100. package/server/cli-ui.js +0 -798
  101. package/server/cli.js +0 -751
  102. package/server/constants/config.js +0 -31
  103. package/server/cursor-cli.js +0 -270
  104. package/server/database/auth.db +0 -0
  105. package/server/database/db.js +0 -1547
  106. package/server/database/init.sql +0 -70
  107. package/server/index.js +0 -3813
  108. package/server/load-env.js +0 -26
  109. package/server/mcp-server.js +0 -621
  110. package/server/middleware/auth.js +0 -184
  111. package/server/middleware/relayHelpers.js +0 -44
  112. package/server/middleware/sandboxRouter.js +0 -174
  113. package/server/openai-codex.js +0 -403
  114. package/server/openrouter.js +0 -137
  115. package/server/projects.js +0 -1807
  116. package/server/provider-factory.js +0 -174
  117. package/server/relay-client.js +0 -390
  118. package/server/routes/agent.js +0 -1234
  119. package/server/routes/auth.js +0 -559
  120. package/server/routes/browser.js +0 -419
  121. package/server/routes/canvas.js +0 -53
  122. package/server/routes/cli-auth.js +0 -263
  123. package/server/routes/codex.js +0 -396
  124. package/server/routes/commands.js +0 -707
  125. package/server/routes/composio.js +0 -176
  126. package/server/routes/cursor.js +0 -770
  127. package/server/routes/dashboard.js +0 -295
  128. package/server/routes/git.js +0 -1208
  129. package/server/routes/keys.js +0 -34
  130. package/server/routes/mcp-utils.js +0 -48
  131. package/server/routes/mcp.js +0 -661
  132. package/server/routes/payments.js +0 -227
  133. package/server/routes/projects.js +0 -754
  134. package/server/routes/sessions.js +0 -146
  135. package/server/routes/settings.js +0 -261
  136. package/server/routes/taskmaster.js +0 -1928
  137. package/server/routes/user.js +0 -106
  138. package/server/routes/vapi-chat.js +0 -624
  139. package/server/routes/voice.js +0 -235
  140. package/server/routes/webhooks.js +0 -166
  141. package/server/routes/workflows.js +0 -312
  142. package/server/sandbox.js +0 -120
  143. package/server/services/browser-ai.js +0 -154
  144. package/server/services/composio.js +0 -204
  145. package/server/services/sessionRegistry.js +0 -139
  146. package/server/services/whisperService.js +0 -84
  147. package/server/services/workflowScheduler.js +0 -211
  148. package/server/tests/relay-flow.test.js +0 -570
  149. package/server/tests/sessions.test.js +0 -259
  150. package/server/utils/commandParser.js +0 -303
  151. package/server/utils/email.js +0 -66
  152. package/server/utils/gitConfig.js +0 -24
  153. package/server/utils/mcp-detector.js +0 -198
  154. package/server/utils/taskmaster-websocket.js +0 -129
  155. package/shared/integrationCatalog.d.ts +0 -12
  156. package/shared/integrationCatalog.js +0 -172
  157. package/shared/modelConstants.js +0 -96
  158. /package/{shared → dist}/agents/claude.js +0 -0
  159. /package/{shared → dist}/agents/codex.js +0 -0
  160. /package/{shared → dist}/agents/cursor.js +0 -0
  161. /package/{shared → dist}/agents/detect.js +0 -0
  162. /package/{shared → dist}/agents/exec.js +0 -0
  163. /package/{shared → dist}/agents/files.js +0 -0
  164. /package/{shared → dist}/agents/git.js +0 -0
  165. /package/{shared → dist}/agents/gitagent.js +0 -0
  166. /package/{shared → dist}/agents/index.js +0 -0
  167. /package/{shared → dist}/agents/shell.js +0 -0
  168. /package/{shared → dist}/agents/utils.js +0 -0
  169. /package/{client/dist → dist/client}/api-docs.html +0 -0
  170. /package/{client/dist → dist/client}/assets/KaTeX_AMS-Regular-BQhdFMY1.woff2 +0 -0
  171. /package/{client/dist → dist/client}/assets/KaTeX_AMS-Regular-DMm9YOAa.woff +0 -0
  172. /package/{client/dist → dist/client}/assets/KaTeX_AMS-Regular-DRggAlZN.ttf +0 -0
  173. /package/{client/dist → dist/client}/assets/KaTeX_Caligraphic-Bold-ATXxdsX0.ttf +0 -0
  174. /package/{client/dist → dist/client}/assets/KaTeX_Caligraphic-Bold-BEiXGLvX.woff +0 -0
  175. /package/{client/dist → dist/client}/assets/KaTeX_Caligraphic-Bold-Dq_IR9rO.woff2 +0 -0
  176. /package/{client/dist → dist/client}/assets/KaTeX_Caligraphic-Regular-CTRA-rTL.woff +0 -0
  177. /package/{client/dist → dist/client}/assets/KaTeX_Caligraphic-Regular-Di6jR-x-.woff2 +0 -0
  178. /package/{client/dist → dist/client}/assets/KaTeX_Caligraphic-Regular-wX97UBjC.ttf +0 -0
  179. /package/{client/dist → dist/client}/assets/KaTeX_Fraktur-Bold-BdnERNNW.ttf +0 -0
  180. /package/{client/dist → dist/client}/assets/KaTeX_Fraktur-Bold-BsDP51OF.woff +0 -0
  181. /package/{client/dist → dist/client}/assets/KaTeX_Fraktur-Bold-CL6g_b3V.woff2 +0 -0
  182. /package/{client/dist → dist/client}/assets/KaTeX_Fraktur-Regular-CB_wures.ttf +0 -0
  183. /package/{client/dist → dist/client}/assets/KaTeX_Fraktur-Regular-CTYiF6lA.woff2 +0 -0
  184. /package/{client/dist → dist/client}/assets/KaTeX_Fraktur-Regular-Dxdc4cR9.woff +0 -0
  185. /package/{client/dist → dist/client}/assets/KaTeX_Main-Bold-Cx986IdX.woff2 +0 -0
  186. /package/{client/dist → dist/client}/assets/KaTeX_Main-Bold-Jm3AIy58.woff +0 -0
  187. /package/{client/dist → dist/client}/assets/KaTeX_Main-Bold-waoOVXN0.ttf +0 -0
  188. /package/{client/dist → dist/client}/assets/KaTeX_Main-BoldItalic-DxDJ3AOS.woff2 +0 -0
  189. /package/{client/dist → dist/client}/assets/KaTeX_Main-BoldItalic-DzxPMmG6.ttf +0 -0
  190. /package/{client/dist → dist/client}/assets/KaTeX_Main-BoldItalic-SpSLRI95.woff +0 -0
  191. /package/{client/dist → dist/client}/assets/KaTeX_Main-Italic-3WenGoN9.ttf +0 -0
  192. /package/{client/dist → dist/client}/assets/KaTeX_Main-Italic-BMLOBm91.woff +0 -0
  193. /package/{client/dist → dist/client}/assets/KaTeX_Main-Italic-NWA7e6Wa.woff2 +0 -0
  194. /package/{client/dist → dist/client}/assets/KaTeX_Main-Regular-B22Nviop.woff2 +0 -0
  195. /package/{client/dist → dist/client}/assets/KaTeX_Main-Regular-Dr94JaBh.woff +0 -0
  196. /package/{client/dist → dist/client}/assets/KaTeX_Main-Regular-ypZvNtVU.ttf +0 -0
  197. /package/{client/dist → dist/client}/assets/KaTeX_Math-BoldItalic-B3XSjfu4.ttf +0 -0
  198. /package/{client/dist → dist/client}/assets/KaTeX_Math-BoldItalic-CZnvNsCZ.woff2 +0 -0
  199. /package/{client/dist → dist/client}/assets/KaTeX_Math-BoldItalic-iY-2wyZ7.woff +0 -0
  200. /package/{client/dist → dist/client}/assets/KaTeX_Math-Italic-DA0__PXp.woff +0 -0
  201. /package/{client/dist → dist/client}/assets/KaTeX_Math-Italic-flOr_0UB.ttf +0 -0
  202. /package/{client/dist → dist/client}/assets/KaTeX_Math-Italic-t53AETM-.woff2 +0 -0
  203. /package/{client/dist → dist/client}/assets/KaTeX_SansSerif-Bold-CFMepnvq.ttf +0 -0
  204. /package/{client/dist → dist/client}/assets/KaTeX_SansSerif-Bold-D1sUS0GD.woff2 +0 -0
  205. /package/{client/dist → dist/client}/assets/KaTeX_SansSerif-Bold-DbIhKOiC.woff +0 -0
  206. /package/{client/dist → dist/client}/assets/KaTeX_SansSerif-Italic-C3H0VqGB.woff2 +0 -0
  207. /package/{client/dist → dist/client}/assets/KaTeX_SansSerif-Italic-DN2j7dab.woff +0 -0
  208. /package/{client/dist → dist/client}/assets/KaTeX_SansSerif-Italic-YYjJ1zSn.ttf +0 -0
  209. /package/{client/dist → dist/client}/assets/KaTeX_SansSerif-Regular-BNo7hRIc.ttf +0 -0
  210. /package/{client/dist → dist/client}/assets/KaTeX_SansSerif-Regular-CS6fqUqJ.woff +0 -0
  211. /package/{client/dist → dist/client}/assets/KaTeX_SansSerif-Regular-DDBCnlJ7.woff2 +0 -0
  212. /package/{client/dist → dist/client}/assets/KaTeX_Script-Regular-C5JkGWo-.ttf +0 -0
  213. /package/{client/dist → dist/client}/assets/KaTeX_Script-Regular-D3wIWfF6.woff2 +0 -0
  214. /package/{client/dist → dist/client}/assets/KaTeX_Script-Regular-D5yQViql.woff +0 -0
  215. /package/{client/dist → dist/client}/assets/KaTeX_Size1-Regular-C195tn64.woff +0 -0
  216. /package/{client/dist → dist/client}/assets/KaTeX_Size1-Regular-Dbsnue_I.ttf +0 -0
  217. /package/{client/dist → dist/client}/assets/KaTeX_Size1-Regular-mCD8mA8B.woff2 +0 -0
  218. /package/{client/dist → dist/client}/assets/KaTeX_Size2-Regular-B7gKUWhC.ttf +0 -0
  219. /package/{client/dist → dist/client}/assets/KaTeX_Size2-Regular-Dy4dx90m.woff2 +0 -0
  220. /package/{client/dist → dist/client}/assets/KaTeX_Size2-Regular-oD1tc_U0.woff +0 -0
  221. /package/{client/dist → dist/client}/assets/KaTeX_Size3-Regular-CTq5MqoE.woff +0 -0
  222. /package/{client/dist → dist/client}/assets/KaTeX_Size3-Regular-DgpXs0kz.ttf +0 -0
  223. /package/{client/dist → dist/client}/assets/KaTeX_Size4-Regular-BF-4gkZK.woff +0 -0
  224. /package/{client/dist → dist/client}/assets/KaTeX_Size4-Regular-DWFBv043.ttf +0 -0
  225. /package/{client/dist → dist/client}/assets/KaTeX_Size4-Regular-Dl5lxZxV.woff2 +0 -0
  226. /package/{client/dist → dist/client}/assets/KaTeX_Typewriter-Regular-C0xS9mPB.woff +0 -0
  227. /package/{client/dist → dist/client}/assets/KaTeX_Typewriter-Regular-CO6r4hn1.woff2 +0 -0
  228. /package/{client/dist → dist/client}/assets/KaTeX_Typewriter-Regular-D3Ib7_Hf.ttf +0 -0
  229. /package/{client/dist → dist/client}/assets/vendor-i18n-DCFGyhQR.js +0 -0
  230. /package/{client/dist → dist/client}/assets/vendor-xterm-CZq1hqo1.js +0 -0
  231. /package/{client/dist → dist/client}/assets/vendor-xterm-qxJ8_QYu.css +0 -0
  232. /package/{client/dist → dist/client}/clear-cache.html +0 -0
  233. /package/{client/dist → dist/client}/convert-icons.md +0 -0
  234. /package/{client/dist → dist/client}/favicon.svg +0 -0
  235. /package/{client/dist → dist/client}/generate-icons.js +0 -0
  236. /package/{client/dist → dist/client}/icons/claude-ai-icon.svg +0 -0
  237. /package/{client/dist → dist/client}/icons/codex-white.svg +0 -0
  238. /package/{client/dist → dist/client}/icons/codex.svg +0 -0
  239. /package/{client/dist → dist/client}/icons/cursor-white.svg +0 -0
  240. /package/{client/dist → dist/client}/icons/cursor.svg +0 -0
  241. /package/{client/dist → dist/client}/icons/icon-128x128.svg +0 -0
  242. /package/{client/dist → dist/client}/icons/icon-144x144.svg +0 -0
  243. /package/{client/dist → dist/client}/icons/icon-152x152.svg +0 -0
  244. /package/{client/dist → dist/client}/icons/icon-192x192.svg +0 -0
  245. /package/{client/dist → dist/client}/icons/icon-384x384.svg +0 -0
  246. /package/{client/dist → dist/client}/icons/icon-512x512.svg +0 -0
  247. /package/{client/dist → dist/client}/icons/icon-72x72.svg +0 -0
  248. /package/{client/dist → dist/client}/icons/icon-96x96.svg +0 -0
  249. /package/{client/dist → dist/client}/icons/icon-template.svg +0 -0
  250. /package/{client/dist → dist/client}/logo.svg +0 -0
  251. /package/{client/dist → dist/client}/offline.html +0 -0
  252. /package/{client/dist → dist/client}/screenshots/cli-selection.png +0 -0
  253. /package/{client/dist → dist/client}/screenshots/desktop-main.png +0 -0
  254. /package/{client/dist → dist/client}/screenshots/mobile-chat.png +0 -0
  255. /package/{client/dist → dist/client}/screenshots/tools-modal.png +0 -0
  256. /package/{shared → dist}/gitagent/index.js +0 -0
  257. /package/{shared → dist}/gitagent/parser.js +0 -0
  258. /package/{shared → dist}/gitagent/prompt-builder.js +0 -0
@@ -1,754 +0,0 @@
1
- import express from 'express';
2
- import { promises as fs } from 'fs';
3
- import path from 'path';
4
- import { spawn } from 'child_process';
5
- import os from 'os';
6
- import { addProjectManually } from '../projects.js';
7
-
8
- const router = express.Router();
9
-
10
- function sanitizeGitError(message, token) {
11
- if (!message || !token) return message;
12
- return message.replace(new RegExp(token.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'g'), '***');
13
- }
14
-
15
- // Configure allowed workspace root.
16
- // In platform mode (Railway), file operations are proxied to user's local machine via relay,
17
- // so no server-side path restriction is needed. Only restrict in self-hosted mode if explicitly set.
18
- const IS_LOCAL = !process.env.RAILWAY_ENVIRONMENT && !process.env.VERCEL && !process.env.RENDER;
19
- const IS_PLATFORM = !!process.env.RAILWAY_ENVIRONMENT || !!process.env.VERCEL;
20
- export const WORKSPACES_ROOT = process.env.WORKSPACES_ROOT || (IS_LOCAL || IS_PLATFORM ? null : os.homedir());
21
-
22
- // System-critical paths that should never be used as workspace directories
23
- export const FORBIDDEN_PATHS = [
24
- // Unix
25
- '/',
26
- '/etc',
27
- '/bin',
28
- '/sbin',
29
- '/usr',
30
- '/dev',
31
- '/proc',
32
- '/sys',
33
- '/var',
34
- '/boot',
35
- '/root',
36
- '/lib',
37
- '/lib64',
38
- '/opt',
39
- '/tmp',
40
- '/run',
41
- // Windows
42
- 'C:\\Windows',
43
- 'C:\\Program Files',
44
- 'C:\\Program Files (x86)',
45
- 'C:\\ProgramData',
46
- 'C:\\System Volume Information',
47
- 'C:\\$Recycle.Bin'
48
- ];
49
-
50
- /**
51
- * Validates that a path is safe for workspace operations
52
- * @param {string} requestedPath - The path to validate
53
- * @returns {Promise<{valid: boolean, resolvedPath?: string, error?: string}>}
54
- */
55
- export async function validateWorkspacePath(requestedPath) {
56
- try {
57
- // Resolve to absolute path
58
- let absolutePath = path.resolve(requestedPath);
59
-
60
- // Check if path is a forbidden system directory
61
- const normalizedPath = path.normalize(absolutePath);
62
- if (FORBIDDEN_PATHS.includes(normalizedPath) || normalizedPath === '/') {
63
- return {
64
- valid: false,
65
- error: 'Cannot use system-critical directories as workspace locations'
66
- };
67
- }
68
-
69
- // Additional check for paths starting with forbidden directories
70
- for (const forbidden of FORBIDDEN_PATHS) {
71
- if (normalizedPath === forbidden ||
72
- normalizedPath.startsWith(forbidden + path.sep)) {
73
- // Exception: /var/tmp and similar user-accessible paths might be allowed
74
- // but /var itself and most /var subdirectories should be blocked
75
- if (forbidden === '/var' &&
76
- (normalizedPath.startsWith('/var/tmp') ||
77
- normalizedPath.startsWith('/var/folders'))) {
78
- continue; // Allow these specific cases
79
- }
80
-
81
- return {
82
- valid: false,
83
- error: `Cannot create workspace in system directory: ${forbidden}`
84
- };
85
- }
86
- }
87
-
88
- // Try to resolve the real path (following symlinks)
89
- let realPath;
90
- try {
91
- // Check if path exists to resolve real path
92
- await fs.access(absolutePath);
93
- realPath = await fs.realpath(absolutePath);
94
- } catch (error) {
95
- if (error.code === 'ENOENT') {
96
- // Path doesn't exist yet - check parent directory
97
- let parentPath = path.dirname(absolutePath);
98
- try {
99
- const parentRealPath = await fs.realpath(parentPath);
100
-
101
- // Reconstruct the full path with real parent
102
- realPath = path.join(parentRealPath, path.basename(absolutePath));
103
- } catch (parentError) {
104
- if (parentError.code === 'ENOENT') {
105
- // Parent doesn't exist either - use the absolute path as-is
106
- // We'll validate it's within allowed root
107
- realPath = absolutePath;
108
- } else {
109
- throw parentError;
110
- }
111
- }
112
- } else {
113
- throw error;
114
- }
115
- }
116
-
117
- // If a workspace root is configured, enforce containment
118
- if (WORKSPACES_ROOT) {
119
- const resolvedWorkspaceRoot = await fs.realpath(WORKSPACES_ROOT);
120
-
121
- if (!realPath.startsWith(resolvedWorkspaceRoot + path.sep) &&
122
- realPath !== resolvedWorkspaceRoot) {
123
- return {
124
- valid: false,
125
- error: `Workspace path must be within the allowed workspace root: ${WORKSPACES_ROOT}`
126
- };
127
- }
128
-
129
- // Additional symlink check for existing paths
130
- try {
131
- await fs.access(absolutePath);
132
- const stats = await fs.lstat(absolutePath);
133
-
134
- if (stats.isSymbolicLink()) {
135
- const linkTarget = await fs.readlink(absolutePath);
136
- const resolvedTarget = path.resolve(path.dirname(absolutePath), linkTarget);
137
- const realTarget = await fs.realpath(resolvedTarget);
138
-
139
- if (!realTarget.startsWith(resolvedWorkspaceRoot + path.sep) &&
140
- realTarget !== resolvedWorkspaceRoot) {
141
- return {
142
- valid: false,
143
- error: 'Symlink target is outside the allowed workspace root'
144
- };
145
- }
146
- }
147
- } catch (error) {
148
- if (error.code !== 'ENOENT') {
149
- throw error;
150
- }
151
- }
152
- }
153
-
154
- return {
155
- valid: true,
156
- resolvedPath: realPath
157
- };
158
-
159
- } catch (error) {
160
- return {
161
- valid: false,
162
- error: 'Path validation failed'
163
- };
164
- }
165
- }
166
-
167
- /**
168
- * Create a new workspace
169
- * POST /api/projects/create-workspace
170
- *
171
- * Body:
172
- * - workspaceType: 'existing' | 'new'
173
- * - path: string (workspace path)
174
- * - githubUrl?: string (optional, for new workspaces)
175
- * - githubTokenId?: number (optional, ID of stored token)
176
- * - newGithubToken?: string (optional, one-time token)
177
- */
178
- router.post('/create-workspace', async (req, res) => {
179
- try {
180
- const { workspaceType, path: workspacePath, githubUrl, githubTokenId, newGithubToken } = req.body;
181
-
182
- // Validate required fields
183
- if (!workspaceType || !workspacePath) {
184
- return res.status(400).json({ error: 'workspaceType and path are required' });
185
- }
186
-
187
- if (!['existing', 'new'].includes(workspaceType)) {
188
- return res.status(400).json({ error: 'workspaceType must be "existing" or "new"' });
189
- }
190
-
191
- // Handle existing workspace
192
- if (workspaceType === 'existing') {
193
- // In cloud mode (Railway/Vercel/Render), the path is on the user's local machine.
194
- // We cannot validate it server-side. Just trust the user's input and add it.
195
- const IS_CLOUD_ENV = !!(process.env.RAILWAY_ENVIRONMENT || process.env.VERCEL || process.env.RENDER);
196
- if (IS_CLOUD_ENV) {
197
- const project = await addProjectManually(workspacePath);
198
- return res.json({ success: true, project, message: 'Workspace added successfully' });
199
- }
200
-
201
- // Local/self-hosted mode: validate on server filesystem
202
- const validation = await validateWorkspacePath(workspacePath);
203
- if (!validation.valid) {
204
- return res.status(400).json({ error: 'Invalid workspace path', details: validation.error });
205
- }
206
- const absolutePath = validation.resolvedPath;
207
-
208
- try {
209
- await fs.access(absolutePath);
210
- const stats = await fs.stat(absolutePath);
211
-
212
- if (!stats.isDirectory()) {
213
- return res.status(400).json({ error: 'Path exists but is not a directory' });
214
- }
215
- } catch (error) {
216
- if (error.code === 'ENOENT') {
217
- return res.status(404).json({ error: 'Workspace path does not exist' });
218
- }
219
- throw error;
220
- }
221
-
222
- const project = await addProjectManually(absolutePath);
223
-
224
- return res.json({
225
- success: true,
226
- project,
227
- message: 'Existing workspace added successfully'
228
- });
229
- }
230
-
231
- // Handle new workspace creation
232
- if (workspaceType === 'new') {
233
- const IS_CLOUD_ENV = !!(process.env.RAILWAY_ENVIRONMENT || process.env.VERCEL || process.env.RENDER);
234
-
235
- // In cloud mode, create directory and clone via relay
236
- if (IS_CLOUD_ENV) {
237
- if (!req.hasRelay || !req.hasRelay()) {
238
- return res.status(503).json({
239
- error: 'Machine not connected',
240
- message: 'Run "uc connect" on your local machine to create new workspaces.',
241
- code: 'RELAY_NOT_CONNECTED'
242
- });
243
- }
244
-
245
- // Create directory via relay
246
- await req.sendRelay('create-folder', { folderPath: workspacePath }, 15000);
247
-
248
- if (githubUrl) {
249
- let githubToken = null;
250
- if (githubTokenId) {
251
- const token = await getGithubTokenById(githubTokenId, req.user.id);
252
- if (!token) {
253
- return res.status(404).json({ error: 'GitHub token not found' });
254
- }
255
- githubToken = token.github_token;
256
- } else if (newGithubToken) {
257
- githubToken = newGithubToken;
258
- }
259
-
260
- const normalizedUrl = githubUrl.replace(/\/+$/, '').replace(/\.git$/, '');
261
- const repoName = normalizedUrl.split('/').pop() || 'repository';
262
- // Build clone URL with token if needed
263
- let cloneUrl = githubUrl;
264
- if (githubToken) {
265
- const urlObj = new URL(githubUrl.endsWith('.git') ? githubUrl : `${githubUrl}.git`);
266
- urlObj.username = githubToken;
267
- urlObj.password = 'x-oauth-basic';
268
- cloneUrl = urlObj.toString();
269
- }
270
- const clonePath = `${workspacePath}/${repoName}`;
271
-
272
- try {
273
- await req.sendRelay('shell-command', {
274
- command: `git clone "${cloneUrl}" "${clonePath}"`,
275
- cwd: workspacePath
276
- }, 120000);
277
- } catch (error) {
278
- const sanitized = sanitizeGitError(error.message, githubToken);
279
- throw new Error(`Failed to clone repository: ${sanitized}`);
280
- }
281
-
282
- const project = await addProjectManually(clonePath);
283
- return res.json({ success: true, project, message: 'New workspace created and repository cloned successfully' });
284
- }
285
-
286
- const project = await addProjectManually(workspacePath);
287
- return res.json({ success: true, project, message: 'New workspace created successfully' });
288
- }
289
-
290
- // Local mode
291
- const validation = await validateWorkspacePath(workspacePath);
292
- const absolutePath = validation.valid ? validation.resolvedPath : path.resolve(workspacePath);
293
- await fs.mkdir(absolutePath, { recursive: true });
294
-
295
- if (githubUrl) {
296
- let githubToken = null;
297
-
298
- if (githubTokenId) {
299
- const token = await getGithubTokenById(githubTokenId, req.user.id);
300
- if (!token) {
301
- await fs.rm(absolutePath, { recursive: true, force: true });
302
- return res.status(404).json({ error: 'GitHub token not found' });
303
- }
304
- githubToken = token.github_token;
305
- } else if (newGithubToken) {
306
- githubToken = newGithubToken;
307
- }
308
-
309
- const normalizedUrl = githubUrl.replace(/\/+$/, '').replace(/\.git$/, '');
310
- const repoName = normalizedUrl.split('/').pop() || 'repository';
311
- const clonePath = path.join(absolutePath, repoName);
312
-
313
- try {
314
- await fs.access(clonePath);
315
- return res.status(409).json({
316
- error: 'Directory already exists',
317
- details: `The destination path "${clonePath}" already exists. Please choose a different location or remove the existing directory.`
318
- });
319
- } catch (err) {
320
- // Directory doesn't exist, which is what we want
321
- }
322
-
323
- try {
324
- await cloneGitHubRepository(githubUrl, clonePath, githubToken);
325
- } catch (error) {
326
- try {
327
- const stats = await fs.stat(clonePath);
328
- if (stats.isDirectory()) {
329
- await fs.rm(clonePath, { recursive: true, force: true });
330
- }
331
- } catch (cleanupError) {
332
- // ignore
333
- }
334
- throw new Error(`Failed to clone repository: ${error.message}`);
335
- }
336
-
337
- const project = await addProjectManually(clonePath);
338
- return res.json({ success: true, project, message: 'New workspace created and repository cloned successfully' });
339
- }
340
-
341
- const project = await addProjectManually(absolutePath);
342
- return res.json({ success: true, project, message: 'New workspace created successfully' });
343
- }
344
-
345
- } catch (error) {
346
- // workspace creation error
347
- res.status(500).json({
348
- error: 'Failed to create workspace',
349
- details: error.message
350
- });
351
- }
352
- });
353
-
354
- /**
355
- * Helper function to get GitHub token from database
356
- */
357
- async function getGithubTokenById(tokenId, userId) {
358
- const { getDatabase } = await import('../database/db.js');
359
- const db = await getDatabase();
360
-
361
- const credential = await db.get(
362
- 'SELECT * FROM user_credentials WHERE id = ? AND user_id = ? AND credential_type = ? AND is_active = 1',
363
- [tokenId, userId, 'github_token']
364
- );
365
-
366
- // Return in the expected format (github_token field for compatibility)
367
- if (credential) {
368
- return {
369
- ...credential,
370
- github_token: credential.credential_value
371
- };
372
- }
373
-
374
- return null;
375
- }
376
-
377
- /**
378
- * Clone repository with progress streaming (SSE)
379
- * GET /api/projects/clone-progress
380
- */
381
- router.get('/clone-progress', async (req, res) => {
382
- const { path: workspacePath, githubUrl, githubTokenId, newGithubToken } = req.query;
383
-
384
- res.setHeader('Content-Type', 'text/event-stream');
385
- res.setHeader('Cache-Control', 'no-cache');
386
- res.setHeader('Connection', 'keep-alive');
387
- res.flushHeaders();
388
-
389
- const sendEvent = (type, data) => {
390
- res.write(`data: ${JSON.stringify({ type, ...data })}\n\n`);
391
- };
392
-
393
- try {
394
- if (!workspacePath || !githubUrl) {
395
- sendEvent('error', { message: 'workspacePath and githubUrl are required' });
396
- res.end();
397
- return;
398
- }
399
-
400
- const IS_CLOUD_ENV = !!(process.env.RAILWAY_ENVIRONMENT || process.env.VERCEL || process.env.RENDER);
401
-
402
- // Cloud mode: clone via relay on user's machine, or sandbox if no relay
403
- if (IS_CLOUD_ENV) {
404
- let githubToken = null;
405
- if (githubTokenId) {
406
- const token = await getGithubTokenById(parseInt(githubTokenId), req.user.id);
407
- if (!token) {
408
- sendEvent('error', { message: 'GitHub token not found' });
409
- res.end();
410
- return;
411
- }
412
- githubToken = token.github_token;
413
- } else if (newGithubToken) {
414
- githubToken = newGithubToken;
415
- }
416
-
417
- const normalizedUrl = githubUrl.replace(/\/+$/, '').replace(/\.git$/, '');
418
- const repoName = normalizedUrl.split('/').pop() || 'repository';
419
-
420
- // Build authenticated clone URL
421
- let cloneUrl = githubUrl;
422
- if (githubToken) {
423
- try {
424
- const url = new URL(githubUrl.endsWith('.git') ? githubUrl : `${githubUrl}.git`);
425
- url.username = githubToken;
426
- url.password = 'x-oauth-basic';
427
- cloneUrl = url.toString();
428
- } catch (error) {
429
- // SSH URL or invalid - use as-is
430
- }
431
- }
432
-
433
- // Option A: Relay connected — clone on user's machine
434
- if (req.hasRelay && req.hasRelay()) {
435
- const clonePath = `${workspacePath}/${repoName}`;
436
-
437
- sendEvent('progress', { message: 'Creating directory...' });
438
- await req.sendRelay('create-folder', { folderPath: workspacePath }, 15000);
439
-
440
- sendEvent('progress', { message: `Cloning into '${repoName}'...` });
441
-
442
- try {
443
- await req.sendRelay('shell-command', {
444
- command: `git clone "${cloneUrl}" "${clonePath}"`,
445
- cwd: workspacePath
446
- }, 120000);
447
-
448
- const project = await addProjectManually(clonePath);
449
- sendEvent('complete', { project, message: 'Repository cloned successfully' });
450
- } catch (error) {
451
- const sanitized = sanitizeGitError(error.message, githubToken);
452
- sendEvent('error', { message: sanitized || 'Git clone failed' });
453
- }
454
-
455
- res.end();
456
- return;
457
- }
458
-
459
- // Option B: No relay — clone into per-user sandbox
460
- try {
461
- const { sandboxClient } = await import('../sandbox.js');
462
- const sandboxAvailable = await sandboxClient.isAvailable();
463
- if (!sandboxAvailable) {
464
- sendEvent('error', { message: 'No machine connected and sandbox unavailable. Run "uc web connect" to connect your machine.' });
465
- res.end();
466
- return;
467
- }
468
-
469
- const userId = req.user.id;
470
- sendEvent('progress', { message: 'Initializing sandbox...' });
471
- await sandboxClient.initSandbox(userId);
472
-
473
- const sandboxPath = `/workspace/${repoName}`;
474
- sendEvent('progress', { message: `Cloning into '${repoName}' (sandbox)...` });
475
-
476
- await sandboxClient.exec(userId, `git clone "${cloneUrl}" "${sandboxPath}"`, { timeout: 120000 });
477
-
478
- sendEvent('progress', { message: 'Registering project...' });
479
-
480
- // Save project with github_origin
481
- const { projectDb } = await import('../database/db.js');
482
- const project = await projectDb.upsert(userId, sandboxPath, repoName, githubUrl);
483
-
484
- sendEvent('complete', {
485
- project: { ...project, displayName: repoName, originalPath: sandboxPath, githubOrigin: githubUrl },
486
- message: 'Repository cloned into sandbox'
487
- });
488
- } catch (error) {
489
- const sanitized = sanitizeGitError(error.message, githubToken);
490
- sendEvent('error', { message: sanitized || 'Sandbox clone failed' });
491
- }
492
-
493
- res.end();
494
- return;
495
- }
496
-
497
- // Local mode
498
- const validation = await validateWorkspacePath(workspacePath);
499
- if (!validation.valid) {
500
- sendEvent('error', { message: validation.error });
501
- res.end();
502
- return;
503
- }
504
-
505
- const absolutePath = validation.resolvedPath;
506
-
507
- await fs.mkdir(absolutePath, { recursive: true });
508
-
509
- let githubToken = null;
510
- if (githubTokenId) {
511
- const token = await getGithubTokenById(parseInt(githubTokenId), req.user.id);
512
- if (!token) {
513
- await fs.rm(absolutePath, { recursive: true, force: true });
514
- sendEvent('error', { message: 'GitHub token not found' });
515
- res.end();
516
- return;
517
- }
518
- githubToken = token.github_token;
519
- } else if (newGithubToken) {
520
- githubToken = newGithubToken;
521
- }
522
-
523
- const normalizedUrl = githubUrl.replace(/\/+$/, '').replace(/\.git$/, '');
524
- const repoName = normalizedUrl.split('/').pop() || 'repository';
525
- const clonePath = path.join(absolutePath, repoName);
526
-
527
- try {
528
- await fs.access(clonePath);
529
- sendEvent('error', { message: `Directory "${repoName}" already exists. Please choose a different location or remove the existing directory.` });
530
- res.end();
531
- return;
532
- } catch (err) {
533
- // Directory doesn't exist, which is what we want
534
- }
535
-
536
- let cloneUrl = githubUrl;
537
- if (githubToken) {
538
- try {
539
- const url = new URL(githubUrl);
540
- url.username = githubToken;
541
- url.password = '';
542
- cloneUrl = url.toString();
543
- } catch (error) {
544
- // SSH URL or invalid - use as-is
545
- }
546
- }
547
-
548
- sendEvent('progress', { message: `Cloning into '${repoName}'...` });
549
-
550
- const gitProcess = spawn('git', ['clone', '--progress', cloneUrl, clonePath], {
551
- stdio: ['ignore', 'pipe', 'pipe'],
552
- env: {
553
- ...process.env,
554
- GIT_TERMINAL_PROMPT: '0'
555
- }
556
- });
557
-
558
- let lastError = '';
559
-
560
- gitProcess.stdout.on('data', (data) => {
561
- const message = data.toString().trim();
562
- if (message) {
563
- sendEvent('progress', { message });
564
- }
565
- });
566
-
567
- gitProcess.stderr.on('data', (data) => {
568
- const message = data.toString().trim();
569
- lastError = message;
570
- if (message) {
571
- sendEvent('progress', { message });
572
- }
573
- });
574
-
575
- gitProcess.on('close', async (code) => {
576
- if (code === 0) {
577
- try {
578
- const project = await addProjectManually(clonePath);
579
- sendEvent('complete', { project, message: 'Repository cloned successfully' });
580
- } catch (error) {
581
- sendEvent('error', { message: `Clone succeeded but failed to add project: ${error.message}` });
582
- }
583
- } else {
584
- const sanitizedError = sanitizeGitError(lastError, githubToken);
585
- let errorMessage = 'Git clone failed';
586
- if (lastError.includes('Authentication failed') || lastError.includes('could not read Username')) {
587
- errorMessage = 'Authentication failed. Please check your credentials.';
588
- } else if (lastError.includes('Repository not found')) {
589
- errorMessage = 'Repository not found. Please check the URL and ensure you have access.';
590
- } else if (lastError.includes('already exists')) {
591
- errorMessage = 'Directory already exists';
592
- } else if (sanitizedError) {
593
- errorMessage = sanitizedError;
594
- }
595
- try {
596
- await fs.rm(clonePath, { recursive: true, force: true });
597
- } catch (cleanupError) {
598
- // cleanup failure ignored
599
- }
600
- sendEvent('error', { message: errorMessage });
601
- }
602
- res.end();
603
- });
604
-
605
- gitProcess.on('error', (error) => {
606
- if (error.code === 'ENOENT') {
607
- sendEvent('error', { message: 'Git is not installed or not in PATH' });
608
- } else {
609
- sendEvent('error', { message: error.message });
610
- }
611
- res.end();
612
- });
613
-
614
- req.on('close', () => {
615
- gitProcess.kill();
616
- });
617
-
618
- } catch (error) {
619
- sendEvent('error', { message: error.message });
620
- res.end();
621
- }
622
- });
623
-
624
- /**
625
- * Helper function to clone a GitHub repository
626
- */
627
- function cloneGitHubRepository(githubUrl, destinationPath, githubToken = null) {
628
- return new Promise((resolve, reject) => {
629
- let cloneUrl = githubUrl;
630
-
631
- if (githubToken) {
632
- try {
633
- const url = new URL(githubUrl);
634
- url.username = githubToken;
635
- url.password = '';
636
- cloneUrl = url.toString();
637
- } catch (error) {
638
- // SSH URL - use as-is
639
- }
640
- }
641
-
642
- const gitProcess = spawn('git', ['clone', '--progress', cloneUrl, destinationPath], {
643
- stdio: ['ignore', 'pipe', 'pipe'],
644
- env: {
645
- ...process.env,
646
- GIT_TERMINAL_PROMPT: '0'
647
- }
648
- });
649
-
650
- let stdout = '';
651
- let stderr = '';
652
-
653
- gitProcess.stdout.on('data', (data) => {
654
- stdout += data.toString();
655
- });
656
-
657
- gitProcess.stderr.on('data', (data) => {
658
- stderr += data.toString();
659
- });
660
-
661
- gitProcess.on('close', (code) => {
662
- if (code === 0) {
663
- resolve({ stdout, stderr });
664
- } else {
665
- let errorMessage = 'Git clone failed';
666
-
667
- if (stderr.includes('Authentication failed') || stderr.includes('could not read Username')) {
668
- errorMessage = 'Authentication failed. Please check your GitHub token.';
669
- } else if (stderr.includes('Repository not found')) {
670
- errorMessage = 'Repository not found. Please check the URL and ensure you have access.';
671
- } else if (stderr.includes('already exists')) {
672
- errorMessage = 'Directory already exists';
673
- } else if (stderr) {
674
- errorMessage = stderr;
675
- }
676
-
677
- reject(new Error(errorMessage));
678
- }
679
- });
680
-
681
- gitProcess.on('error', (error) => {
682
- if (error.code === 'ENOENT') {
683
- reject(new Error('Git is not installed or not in PATH'));
684
- } else {
685
- reject(error);
686
- }
687
- });
688
- });
689
- }
690
-
691
- /**
692
- * Push sandbox changes back to GitHub
693
- * POST /api/projects/:projectName/push
694
- */
695
- router.post('/:projectName/push', async (req, res) => {
696
- const { branch, commitMessage } = req.body;
697
- const userId = req.user.id;
698
-
699
- try {
700
- const { projectDb } = await import('../database/db.js');
701
- const project = await projectDb.getByName(userId, req.params.projectName);
702
-
703
- if (!project) {
704
- return res.status(404).json({ error: 'Project not found' });
705
- }
706
- if (!project.github_origin) {
707
- return res.status(400).json({ error: 'Not a GitHub project — no origin to push to' });
708
- }
709
-
710
- // Get user's GitHub token
711
- const { getDatabase } = await import('../database/db.js');
712
- const db = await getDatabase();
713
- const cred = await db.execute({
714
- sql: 'SELECT credential_value FROM user_credentials WHERE user_id = ? AND credential_type = ? AND is_active = 1 LIMIT 1',
715
- args: [userId, 'github_token']
716
- });
717
-
718
- const githubToken = cred.rows[0]?.credential_value;
719
- if (!githubToken) {
720
- return res.status(400).json({ error: 'No GitHub token configured. Add one in Settings > AI Providers.' });
721
- }
722
-
723
- // Set remote URL with token for auth
724
- const originUrl = new URL(project.github_origin.endsWith('.git') ? project.github_origin : `${project.github_origin}.git`);
725
- originUrl.username = githubToken;
726
- originUrl.password = 'x-oauth-basic';
727
-
728
- const { sandboxClient } = await import('../sandbox.js');
729
- const cwd = project.original_path;
730
- const targetBranch = branch || 'main';
731
- const msg = commitMessage || 'Update from Upfyn Code';
732
-
733
- // Set remote, stage, commit, push
734
- await sandboxClient.exec(userId, `git remote set-url origin "${originUrl.toString()}"`, { cwd });
735
- await sandboxClient.exec(userId, 'git add -A', { cwd });
736
-
737
- try {
738
- await sandboxClient.exec(userId, `git commit -m "${msg.replace(/"/g, '\\"')}"`, { cwd });
739
- } catch {
740
- return res.json({ success: true, message: 'No changes to commit' });
741
- }
742
-
743
- await sandboxClient.exec(userId, `git push origin ${targetBranch}`, { cwd, timeout: 60000 });
744
-
745
- // Clean the token from the remote URL after push
746
- await sandboxClient.exec(userId, `git remote set-url origin "${project.github_origin}"`, { cwd });
747
-
748
- res.json({ success: true, message: `Pushed to ${targetBranch}` });
749
- } catch (error) {
750
- res.status(500).json({ error: error.message || 'Push failed' });
751
- }
752
- });
753
-
754
- export default router;