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,259 +0,0 @@
1
- /**
2
- * End-to-end tests for Session Management & Sandbox Integration
3
- *
4
- * These tests verify the new session management REST API, session registry,
5
- * sandbox command routing, and multi-tab session support.
6
- *
7
- * Run: node --test backend/server/tests/sessions.test.js
8
- */
9
-
10
- import { describe, it, before, after, mock } from 'node:test';
11
- import assert from 'node:assert/strict';
12
-
13
- // ── Test 1: Session Registry — getAllActiveSessions returns unified list ──
14
-
15
- describe('Session Registry', () => {
16
- it('getAllActiveSessions merges sessions from all providers', async () => {
17
- // Mock the provider modules before importing sessionRegistry
18
- const mockClaudeSessions = ['session-claude-1', 'session-claude-2'];
19
- const mockCursorSessions = ['session-cursor-1'];
20
- const mockCodexSessions = [{ id: 'session-codex-1', status: 'running', startedAt: new Date().toISOString() }];
21
-
22
- // Direct test of the registry logic
23
- const sessions = [];
24
-
25
- // Simulate Claude sessions
26
- for (const id of mockClaudeSessions) {
27
- sessions.push({ sessionId: id, provider: 'claude', status: 'active' });
28
- }
29
- // Simulate Cursor sessions
30
- for (const id of mockCursorSessions) {
31
- sessions.push({ sessionId: id, provider: 'cursor', status: 'active' });
32
- }
33
- // Simulate Codex sessions
34
- for (const s of mockCodexSessions) {
35
- sessions.push({ sessionId: s.id, provider: 'codex', status: 'active', startedAt: s.startedAt });
36
- }
37
-
38
- assert.equal(sessions.length, 4, 'Should have 4 total sessions across providers');
39
- assert.equal(sessions.filter(s => s.provider === 'claude').length, 2);
40
- assert.equal(sessions.filter(s => s.provider === 'cursor').length, 1);
41
- assert.equal(sessions.filter(s => s.provider === 'codex').length, 1);
42
-
43
- // Verify all have required fields
44
- for (const s of sessions) {
45
- assert.ok(s.sessionId, 'Each session must have sessionId');
46
- assert.ok(s.provider, 'Each session must have provider');
47
- assert.ok(s.status, 'Each session must have status');
48
- }
49
- });
50
-
51
- it('abortSession routes to correct provider', async () => {
52
- const abortLog = [];
53
-
54
- // Simulate abort routing
55
- const abortByProvider = (sessionId, provider) => {
56
- abortLog.push({ sessionId, provider });
57
- return true;
58
- };
59
-
60
- const result1 = abortByProvider('s1', 'claude');
61
- const result2 = abortByProvider('s2', 'cursor');
62
- const result3 = abortByProvider('s3', 'codex');
63
-
64
- assert.equal(result1, true);
65
- assert.equal(result2, true);
66
- assert.equal(result3, true);
67
- assert.deepEqual(abortLog, [
68
- { sessionId: 's1', provider: 'claude' },
69
- { sessionId: 's2', provider: 'cursor' },
70
- { sessionId: 's3', provider: 'codex' },
71
- ]);
72
- });
73
- });
74
-
75
- // ── Test 2: Sessions REST API route structure ──
76
-
77
- describe('Sessions REST API', () => {
78
- it('route file exports a valid Express router', async () => {
79
- const sessionRoutes = await import('../routes/sessions.js');
80
- assert.ok(sessionRoutes.default, 'Should export a default router');
81
- assert.equal(typeof sessionRoutes.default, 'function', 'Router should be a function');
82
-
83
- // Check the router has registered routes
84
- const routes = sessionRoutes.default.stack || [];
85
- const paths = routes
86
- .filter(r => r.route)
87
- .map(r => `${Object.keys(r.route.methods)[0].toUpperCase()} ${r.route.path}`);
88
-
89
- assert.ok(paths.includes('GET /'), 'Should have GET / route');
90
- assert.ok(paths.includes('GET /stats'), 'Should have GET /stats route');
91
- assert.ok(paths.some(p => p.includes('GET /:sessionId')), 'Should have GET /:sessionId route');
92
- assert.ok(paths.some(p => p.includes('POST') && p.includes('abort')), 'Should have POST abort route');
93
- assert.ok(paths.includes('POST /abort-all'), 'Should have POST /abort-all route');
94
- });
95
- });
96
-
97
- // ── Test 3: Sandbox command router — action routing ──
98
-
99
- describe('Sandbox Command Router', () => {
100
- it('handleSandboxWebSocketCommand returns false when sandbox unavailable', async () => {
101
- // Import the module
102
- const { handleSandboxWebSocketCommand } = await import('../middleware/sandboxRouter.js');
103
-
104
- // Override sandboxClient.isAvailable to return false
105
- // Since we can't easily mock ES modules, we test the contract:
106
- // When sandbox service is not running, it should return false
107
- const mockWriter = {
108
- messages: [],
109
- send(msg) { this.messages.push(msg); }
110
- };
111
-
112
- // This will fail to connect to sandbox service (not running locally)
113
- // and should return false gracefully
114
- const result = await handleSandboxWebSocketCommand('test-user', 'claude-command', {}, mockWriter);
115
- assert.equal(result, false, 'Should return false when sandbox service is unavailable');
116
- });
117
-
118
- it('sandboxCommandRouter middleware calls next() when relay is active', async () => {
119
- const { sandboxCommandRouter } = await import('../middleware/sandboxRouter.js');
120
-
121
- let nextCalled = false;
122
- const req = { hasRelay: () => true, body: {} };
123
- const res = {};
124
- const next = () => { nextCalled = true; };
125
-
126
- sandboxCommandRouter(req, res, next);
127
- assert.equal(nextCalled, true, 'Should call next() when relay is active');
128
- });
129
- });
130
-
131
- // ── Test 4: Session lock and subscriber functions ──
132
-
133
- describe('Multi-tab Session Support', () => {
134
- it('session subscriber management works correctly', () => {
135
- // Simulate the subscriber maps
136
- const sessionSubscribers = new Map();
137
-
138
- function subscribeToSession(sessionId, ws) {
139
- if (!sessionSubscribers.has(sessionId)) {
140
- sessionSubscribers.set(sessionId, new Set());
141
- }
142
- sessionSubscribers.get(sessionId).add(ws);
143
- }
144
-
145
- function unsubscribeFromSession(sessionId, ws) {
146
- const subs = sessionSubscribers.get(sessionId);
147
- if (subs) {
148
- subs.delete(ws);
149
- if (subs.size === 0) sessionSubscribers.delete(sessionId);
150
- }
151
- }
152
-
153
- function unsubscribeAllForWs(ws) {
154
- for (const [sessionId, subs] of sessionSubscribers.entries()) {
155
- subs.delete(ws);
156
- if (subs.size === 0) sessionSubscribers.delete(sessionId);
157
- }
158
- }
159
-
160
- const ws1 = { id: 'tab1' };
161
- const ws2 = { id: 'tab2' };
162
- const ws3 = { id: 'tab3' };
163
-
164
- // Tab 1 and Tab 2 subscribe to same session
165
- subscribeToSession('session-A', ws1);
166
- subscribeToSession('session-A', ws2);
167
- assert.equal(sessionSubscribers.get('session-A').size, 2, 'Two subscribers for session-A');
168
-
169
- // Tab 3 subscribes to different session
170
- subscribeToSession('session-B', ws3);
171
- assert.equal(sessionSubscribers.size, 2, 'Two sessions with subscribers');
172
-
173
- // Unsubscribe Tab 1 from session-A
174
- unsubscribeFromSession('session-A', ws1);
175
- assert.equal(sessionSubscribers.get('session-A').size, 1, 'One subscriber remaining');
176
-
177
- // Disconnect Tab 2 (cleanup all)
178
- unsubscribeAllForWs(ws2);
179
- assert.equal(sessionSubscribers.has('session-A'), false, 'Session-A cleaned up after last sub');
180
- assert.equal(sessionSubscribers.has('session-B'), true, 'Session-B still has subscriber');
181
-
182
- // Disconnect Tab 3
183
- unsubscribeAllForWs(ws3);
184
- assert.equal(sessionSubscribers.size, 0, 'All subscribers cleaned up');
185
- });
186
-
187
- it('session lock allows owner but blocks other tabs', () => {
188
- const sessionLocks = new Map();
189
-
190
- function acquireSessionLock(sessionId, ws) {
191
- if (!sessionId) return true;
192
- const existingWs = sessionLocks.get(sessionId);
193
- if (existingWs && existingWs !== ws && existingWs.readyState === 1) {
194
- return false;
195
- }
196
- sessionLocks.set(sessionId, ws);
197
- return true;
198
- }
199
-
200
- const ws1 = { id: 'tab1', readyState: 1 };
201
- const ws2 = { id: 'tab2', readyState: 1 };
202
-
203
- // Tab 1 acquires lock
204
- assert.equal(acquireSessionLock('session-X', ws1), true, 'Tab 1 should acquire lock');
205
-
206
- // Tab 2 tries to lock same session — should fail
207
- assert.equal(acquireSessionLock('session-X', ws2), false, 'Tab 2 should be blocked');
208
-
209
- // Tab 1 can re-acquire its own lock
210
- assert.equal(acquireSessionLock('session-X', ws1), true, 'Tab 1 can re-acquire');
211
- });
212
- });
213
-
214
- // ── Test 5: Workspace and integration verification ──
215
-
216
- describe('Integration Checks', () => {
217
- it('root package.json includes sandbox-service in workspaces', async () => {
218
- const fs = await import('fs');
219
- const path = await import('path');
220
- const { fileURLToPath } = await import('url');
221
- const __dirname = path.dirname(fileURLToPath(import.meta.url));
222
- const rootPkg = JSON.parse(fs.readFileSync(path.join(__dirname, '..', '..', '..', 'package.json'), 'utf8'));
223
-
224
- assert.ok(
225
- rootPkg.workspaces.includes('sandbox-service'),
226
- 'sandbox-service should be in workspaces'
227
- );
228
- });
229
-
230
- it('session routes are importable and have correct structure', async () => {
231
- const registry = await import('../services/sessionRegistry.js');
232
-
233
- // Verify all exported functions exist
234
- assert.equal(typeof registry.getAllActiveSessions, 'function');
235
- assert.equal(typeof registry.checkSessionStatus, 'function');
236
- assert.equal(typeof registry.abortSession, 'function');
237
- assert.equal(typeof registry.abortAllSessions, 'function');
238
- assert.equal(typeof registry.getSessionStats, 'function');
239
- });
240
-
241
- it('sandbox router exports both middleware and WS handler', async () => {
242
- const router = await import('../middleware/sandboxRouter.js');
243
-
244
- assert.equal(typeof router.sandboxCommandRouter, 'function');
245
- assert.equal(typeof router.handleSandboxWebSocketCommand, 'function');
246
- });
247
-
248
- it('session stats returns correct shape', async () => {
249
- const { getSessionStats } = await import('../services/sessionRegistry.js');
250
- const stats = getSessionStats();
251
-
252
- assert.equal(typeof stats.total, 'number');
253
- assert.equal(typeof stats.active, 'number');
254
- assert.ok(stats.byProvider, 'Should have byProvider');
255
- assert.equal(typeof stats.byProvider.claude, 'number');
256
- assert.equal(typeof stats.byProvider.cursor, 'number');
257
- assert.equal(typeof stats.byProvider.codex, 'number');
258
- });
259
- });
@@ -1,303 +0,0 @@
1
- import matter from 'gray-matter';
2
- import { promises as fs } from 'fs';
3
- import path from 'path';
4
- import { execFile } from 'child_process';
5
- import { promisify } from 'util';
6
- import { parse as parseShellCommand } from 'shell-quote';
7
-
8
- const execFileAsync = promisify(execFile);
9
-
10
- // Configuration
11
- const MAX_INCLUDE_DEPTH = 3;
12
- const BASH_TIMEOUT = 30000; // 30 seconds
13
- const BASH_COMMAND_ALLOWLIST = [
14
- 'echo',
15
- 'ls',
16
- 'pwd',
17
- 'date',
18
- 'whoami',
19
- 'git',
20
- 'npm',
21
- 'node',
22
- 'cat',
23
- 'grep',
24
- 'find',
25
- 'task-master'
26
- ];
27
-
28
- /**
29
- * Parse a markdown command file and extract frontmatter and content
30
- * @param {string} content - Raw markdown content
31
- * @returns {object} Parsed command with data (frontmatter) and content
32
- */
33
- export function parseCommand(content) {
34
- try {
35
- const parsed = matter(content);
36
- return {
37
- data: parsed.data || {},
38
- content: parsed.content || '',
39
- raw: content
40
- };
41
- } catch (error) {
42
- throw new Error(`Failed to parse command: ${error.message}`);
43
- }
44
- }
45
-
46
- /**
47
- * Replace argument placeholders in content
48
- * @param {string} content - Content with placeholders
49
- * @param {string|array} args - Arguments to replace (string or array)
50
- * @returns {string} Content with replaced arguments
51
- */
52
- export function replaceArguments(content, args) {
53
- if (!content) return content;
54
-
55
- let result = content;
56
-
57
- // Convert args to array if it's a string
58
- const argsArray = Array.isArray(args) ? args : (args ? [args] : []);
59
-
60
- // Replace $ARGUMENTS with all arguments joined by space
61
- const allArgs = argsArray.join(' ');
62
- result = result.replace(/\$ARGUMENTS/g, allArgs);
63
-
64
- // Replace positional arguments $1-$9
65
- for (let i = 1; i <= 9; i++) {
66
- const regex = new RegExp(`\\$${i}`, 'g');
67
- const value = argsArray[i - 1] || '';
68
- result = result.replace(regex, value);
69
- }
70
-
71
- return result;
72
- }
73
-
74
- /**
75
- * Validate file path to prevent directory traversal
76
- * @param {string} filePath - Path to validate
77
- * @param {string} basePath - Base directory path
78
- * @returns {boolean} True if path is safe
79
- */
80
- export function isPathSafe(filePath, basePath) {
81
- const resolvedPath = path.resolve(basePath, filePath);
82
- const resolvedBase = path.resolve(basePath);
83
- const relative = path.relative(resolvedBase, resolvedPath);
84
- return (
85
- relative !== '' &&
86
- !relative.startsWith('..') &&
87
- !path.isAbsolute(relative)
88
- );
89
- }
90
-
91
- /**
92
- * Process file includes in content (@filename syntax)
93
- * @param {string} content - Content with @filename includes
94
- * @param {string} basePath - Base directory for resolving file paths
95
- * @param {number} depth - Current recursion depth
96
- * @returns {Promise<string>} Content with includes resolved
97
- */
98
- export async function processFileIncludes(content, basePath, depth = 0) {
99
- if (!content) return content;
100
-
101
- // Prevent infinite recursion
102
- if (depth >= MAX_INCLUDE_DEPTH) {
103
- throw new Error(`Maximum include depth (${MAX_INCLUDE_DEPTH}) exceeded`);
104
- }
105
-
106
- // Match @filename patterns (at start of line or after whitespace)
107
- const includePattern = /(?:^|\s)@([^\s]+)/gm;
108
- const matches = [...content.matchAll(includePattern)];
109
-
110
- if (matches.length === 0) {
111
- return content;
112
- }
113
-
114
- let result = content;
115
-
116
- for (const match of matches) {
117
- const fullMatch = match[0];
118
- const filename = match[1];
119
-
120
- // Security: prevent directory traversal
121
- if (!isPathSafe(filename, basePath)) {
122
- throw new Error(`Invalid file path (directory traversal detected): ${filename}`);
123
- }
124
-
125
- try {
126
- const filePath = path.resolve(basePath, filename);
127
- const fileContent = await fs.readFile(filePath, 'utf-8');
128
-
129
- // Recursively process includes in the included file
130
- const processedContent = await processFileIncludes(fileContent, basePath, depth + 1);
131
-
132
- // Replace the @filename with the file content
133
- result = result.replace(fullMatch, fullMatch.startsWith(' ') ? ' ' + processedContent : processedContent);
134
- } catch (error) {
135
- if (error.code === 'ENOENT') {
136
- throw new Error(`File not found: ${filename}`);
137
- }
138
- throw error;
139
- }
140
- }
141
-
142
- return result;
143
- }
144
-
145
- /**
146
- * Validate that a command and its arguments are safe
147
- * @param {string} commandString - Command string to validate
148
- * @returns {{ allowed: boolean, command: string, args: string[], error?: string }} Validation result
149
- */
150
- export function validateCommand(commandString) {
151
- const trimmedCommand = commandString.trim();
152
- if (!trimmedCommand) {
153
- return { allowed: false, command: '', args: [], error: 'Empty command' };
154
- }
155
-
156
- // Parse the command using shell-quote to handle quotes properly
157
- const parsed = parseShellCommand(trimmedCommand);
158
-
159
- // Check for shell operators or control structures
160
- const hasOperators = parsed.some(token =>
161
- typeof token === 'object' && token.op
162
- );
163
-
164
- if (hasOperators) {
165
- return {
166
- allowed: false,
167
- command: '',
168
- args: [],
169
- error: 'Shell operators (&&, ||, |, ;, etc.) are not allowed'
170
- };
171
- }
172
-
173
- // Extract command and args (all should be strings after validation)
174
- const tokens = parsed.filter(token => typeof token === 'string');
175
-
176
- if (tokens.length === 0) {
177
- return { allowed: false, command: '', args: [], error: 'No valid command found' };
178
- }
179
-
180
- const [command, ...args] = tokens;
181
-
182
- // Extract just the command name (remove path if present)
183
- const commandName = path.basename(command);
184
-
185
- // Check if command exactly matches allowlist (no prefix matching)
186
- const isAllowed = BASH_COMMAND_ALLOWLIST.includes(commandName);
187
-
188
- if (!isAllowed) {
189
- return {
190
- allowed: false,
191
- command: commandName,
192
- args,
193
- error: `Command '${commandName}' is not in the allowlist`
194
- };
195
- }
196
-
197
- // Validate arguments don't contain dangerous metacharacters
198
- const dangerousPattern = /[;&|`$()<>{}[\]\\]/;
199
- for (const arg of args) {
200
- if (dangerousPattern.test(arg)) {
201
- return {
202
- allowed: false,
203
- command: commandName,
204
- args,
205
- error: `Argument contains dangerous characters: ${arg}`
206
- };
207
- }
208
- }
209
-
210
- return { allowed: true, command: commandName, args };
211
- }
212
-
213
- /**
214
- * Backward compatibility: Check if command is allowed (deprecated)
215
- * @deprecated Use validateCommand() instead for better security
216
- * @param {string} command - Command to validate
217
- * @returns {boolean} True if command is allowed
218
- */
219
- export function isBashCommandAllowed(command) {
220
- const result = validateCommand(command);
221
- return result.allowed;
222
- }
223
-
224
- /**
225
- * Sanitize bash command output
226
- * @param {string} output - Raw command output
227
- * @returns {string} Sanitized output
228
- */
229
- export function sanitizeOutput(output) {
230
- if (!output) return '';
231
-
232
- // Remove control characters except \t, \n, \r
233
- return [...output]
234
- .filter(ch => {
235
- const code = ch.charCodeAt(0);
236
- return code === 9 // \t
237
- || code === 10 // \n
238
- || code === 13 // \r
239
- || (code >= 32 && code !== 127);
240
- })
241
- .join('');
242
- }
243
-
244
- /**
245
- * Process bash commands in content (!command syntax)
246
- * @param {string} content - Content with !command syntax
247
- * @param {object} options - Options for bash execution
248
- * @returns {Promise<string>} Content with bash commands executed and replaced
249
- */
250
- export async function processBashCommands(content, options = {}) {
251
- if (!content) return content;
252
-
253
- const { cwd = process.cwd(), timeout = BASH_TIMEOUT } = options;
254
-
255
- // Match !command patterns (at start of line or after whitespace)
256
- const commandPattern = /(?:^|\n)!(.+?)(?=\n|$)/g;
257
- const matches = [...content.matchAll(commandPattern)];
258
-
259
- if (matches.length === 0) {
260
- return content;
261
- }
262
-
263
- let result = content;
264
-
265
- for (const match of matches) {
266
- const fullMatch = match[0];
267
- const commandString = match[1].trim();
268
-
269
- // Security: validate command and parse args
270
- const validation = validateCommand(commandString);
271
-
272
- if (!validation.allowed) {
273
- throw new Error(`Command not allowed: ${commandString} - ${validation.error}`);
274
- }
275
-
276
- try {
277
- // Execute without shell using execFile with parsed args
278
- const { stdout, stderr } = await execFileAsync(
279
- validation.command,
280
- validation.args,
281
- {
282
- cwd,
283
- timeout,
284
- maxBuffer: 1024 * 1024, // 1MB max output
285
- shell: false, // IMPORTANT: No shell interpretation
286
- env: { ...process.env, PATH: process.env.PATH } // Inherit PATH for finding commands
287
- }
288
- );
289
-
290
- const output = sanitizeOutput(stdout || stderr || '');
291
-
292
- // Replace the !command with the output
293
- result = result.replace(fullMatch, fullMatch.startsWith('\n') ? '\n' + output : output);
294
- } catch (error) {
295
- if (error.killed) {
296
- throw new Error(`Command timeout: ${commandString}`);
297
- }
298
- throw new Error(`Command failed: ${commandString} - ${error.message}`);
299
- }
300
- }
301
-
302
- return result;
303
- }
@@ -1,66 +0,0 @@
1
- let Resend;
2
- try {
3
- Resend = (await import('resend')).Resend;
4
- } catch {
5
- // resend not available — email features will be disabled
6
- }
7
-
8
- const resend = (process.env.RESEND_API_KEY && Resend) ? new Resend(process.env.RESEND_API_KEY) : null;
9
-
10
- const FROM_EMAIL = process.env.FROM_EMAIL || 'Upfyn Code <noreply@upfyn.com>';
11
- const APP_URL = process.env.APP_URL || 'https://cli.upfyn.com';
12
-
13
- export async function sendPasswordResetEmail(toEmail, resetToken) {
14
- if (!resend) {
15
- console.warn('[Email] RESEND_API_KEY not set — cannot send password reset email');
16
- return { success: false, error: 'Email service not configured' };
17
- }
18
-
19
- const resetUrl = `${APP_URL}/reset-password?token=${resetToken}`;
20
-
21
- try {
22
- const { data, error } = await resend.emails.send({
23
- from: FROM_EMAIL,
24
- to: toEmail,
25
- subject: 'Reset your Upfyn Code password',
26
- html: `
27
- <!DOCTYPE html>
28
- <html>
29
- <head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"></head>
30
- <body style="margin:0;padding:0;background:#0f172a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif;">
31
- <table width="100%" cellpadding="0" cellspacing="0" style="background:#0f172a;padding:40px 20px;">
32
- <tr><td align="center">
33
- <table width="480" cellpadding="0" cellspacing="0" style="background:#1e293b;border-radius:12px;border:1px solid #334155;overflow:hidden;">
34
- <tr><td style="padding:32px 32px 24px;text-align:center;">
35
- <h1 style="margin:0 0 8px;color:#f8fafc;font-size:22px;font-weight:600;">Password Reset</h1>
36
- <p style="margin:0;color:#94a3b8;font-size:14px;">You requested a password reset for your Upfyn Code account.</p>
37
- </td></tr>
38
- <tr><td style="padding:0 32px 24px;text-align:center;">
39
- <a href="${resetUrl}" style="display:inline-block;padding:12px 32px;background:#3b82f6;color:#fff;text-decoration:none;border-radius:8px;font-size:15px;font-weight:500;">
40
- Reset Password
41
- </a>
42
- </td></tr>
43
- <tr><td style="padding:0 32px 24px;text-align:center;">
44
- <p style="margin:0;color:#64748b;font-size:12px;">This link expires in 1 hour. If you didn't request this, you can safely ignore this email.</p>
45
- </td></tr>
46
- <tr><td style="padding:16px 32px;background:#0f172a;border-top:1px solid #334155;text-align:center;">
47
- <p style="margin:0;color:#475569;font-size:11px;">Upfyn Code &mdash; cli.upfyn.com</p>
48
- </td></tr>
49
- </table>
50
- </td></tr>
51
- </table>
52
- </body>
53
- </html>`,
54
- });
55
-
56
- if (error) {
57
- console.error('[Email] Resend error:', error);
58
- return { success: false, error: error.message };
59
- }
60
-
61
- return { success: true, id: data?.id };
62
- } catch (err) {
63
- console.error('[Email] Send failed:', err.message);
64
- return { success: false, error: err.message };
65
- }
66
- }
@@ -1,24 +0,0 @@
1
- import { exec } from 'child_process';
2
- import { promisify } from 'util';
3
-
4
- const execAsync = promisify(exec);
5
-
6
- /**
7
- * Read git configuration from system's global git config
8
- * @returns {Promise<{git_name: string|null, git_email: string|null}>}
9
- */
10
- export async function getSystemGitConfig() {
11
- try {
12
- const [nameResult, emailResult] = await Promise.all([
13
- execAsync('git config --global user.name').catch(() => ({ stdout: '' })),
14
- execAsync('git config --global user.email').catch(() => ({ stdout: '' }))
15
- ]);
16
-
17
- return {
18
- git_name: nameResult.stdout.trim() || null,
19
- git_email: emailResult.stdout.trim() || null
20
- };
21
- } catch (error) {
22
- return { git_name: null, git_email: null };
23
- }
24
- }