upfynai-code 2.9.0 → 2.9.2

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 (229) hide show
  1. package/README.md +91 -66
  2. package/client/dist/api-docs.html +838 -0
  3. package/client/dist/assets/AppContent-BXZDeSIC.js +545 -0
  4. package/client/dist/assets/CanvasFullScreen-mnpCnLZ9.js +1 -0
  5. package/client/dist/assets/CanvasWorkspace-4CqmjAVQ.js +163 -0
  6. package/client/dist/assets/DashboardPanel-zFIFlw56.js +1 -0
  7. package/client/dist/assets/FileTree-B0c_GaB3.js +1 -0
  8. package/client/dist/assets/GitPanel-DUP4zVU4.js +2 -0
  9. package/client/dist/assets/KaTeX_AMS-Regular-BQhdFMY1.woff2 +0 -0
  10. package/client/dist/assets/KaTeX_AMS-Regular-DMm9YOAa.woff +0 -0
  11. package/client/dist/assets/KaTeX_AMS-Regular-DRggAlZN.ttf +0 -0
  12. package/client/dist/assets/KaTeX_Caligraphic-Bold-ATXxdsX0.ttf +0 -0
  13. package/client/dist/assets/KaTeX_Caligraphic-Bold-BEiXGLvX.woff +0 -0
  14. package/client/dist/assets/KaTeX_Caligraphic-Bold-Dq_IR9rO.woff2 +0 -0
  15. package/client/dist/assets/KaTeX_Caligraphic-Regular-CTRA-rTL.woff +0 -0
  16. package/client/dist/assets/KaTeX_Caligraphic-Regular-Di6jR-x-.woff2 +0 -0
  17. package/client/dist/assets/KaTeX_Caligraphic-Regular-wX97UBjC.ttf +0 -0
  18. package/client/dist/assets/KaTeX_Fraktur-Bold-BdnERNNW.ttf +0 -0
  19. package/client/dist/assets/KaTeX_Fraktur-Bold-BsDP51OF.woff +0 -0
  20. package/client/dist/assets/KaTeX_Fraktur-Bold-CL6g_b3V.woff2 +0 -0
  21. package/client/dist/assets/KaTeX_Fraktur-Regular-CB_wures.ttf +0 -0
  22. package/client/dist/assets/KaTeX_Fraktur-Regular-CTYiF6lA.woff2 +0 -0
  23. package/client/dist/assets/KaTeX_Fraktur-Regular-Dxdc4cR9.woff +0 -0
  24. package/client/dist/assets/KaTeX_Main-Bold-Cx986IdX.woff2 +0 -0
  25. package/client/dist/assets/KaTeX_Main-Bold-Jm3AIy58.woff +0 -0
  26. package/client/dist/assets/KaTeX_Main-Bold-waoOVXN0.ttf +0 -0
  27. package/client/dist/assets/KaTeX_Main-BoldItalic-DxDJ3AOS.woff2 +0 -0
  28. package/client/dist/assets/KaTeX_Main-BoldItalic-DzxPMmG6.ttf +0 -0
  29. package/client/dist/assets/KaTeX_Main-BoldItalic-SpSLRI95.woff +0 -0
  30. package/client/dist/assets/KaTeX_Main-Italic-3WenGoN9.ttf +0 -0
  31. package/client/dist/assets/KaTeX_Main-Italic-BMLOBm91.woff +0 -0
  32. package/client/dist/assets/KaTeX_Main-Italic-NWA7e6Wa.woff2 +0 -0
  33. package/client/dist/assets/KaTeX_Main-Regular-B22Nviop.woff2 +0 -0
  34. package/client/dist/assets/KaTeX_Main-Regular-Dr94JaBh.woff +0 -0
  35. package/client/dist/assets/KaTeX_Main-Regular-ypZvNtVU.ttf +0 -0
  36. package/client/dist/assets/KaTeX_Math-BoldItalic-B3XSjfu4.ttf +0 -0
  37. package/client/dist/assets/KaTeX_Math-BoldItalic-CZnvNsCZ.woff2 +0 -0
  38. package/client/dist/assets/KaTeX_Math-BoldItalic-iY-2wyZ7.woff +0 -0
  39. package/client/dist/assets/KaTeX_Math-Italic-DA0__PXp.woff +0 -0
  40. package/client/dist/assets/KaTeX_Math-Italic-flOr_0UB.ttf +0 -0
  41. package/client/dist/assets/KaTeX_Math-Italic-t53AETM-.woff2 +0 -0
  42. package/client/dist/assets/KaTeX_SansSerif-Bold-CFMepnvq.ttf +0 -0
  43. package/client/dist/assets/KaTeX_SansSerif-Bold-D1sUS0GD.woff2 +0 -0
  44. package/client/dist/assets/KaTeX_SansSerif-Bold-DbIhKOiC.woff +0 -0
  45. package/client/dist/assets/KaTeX_SansSerif-Italic-C3H0VqGB.woff2 +0 -0
  46. package/client/dist/assets/KaTeX_SansSerif-Italic-DN2j7dab.woff +0 -0
  47. package/client/dist/assets/KaTeX_SansSerif-Italic-YYjJ1zSn.ttf +0 -0
  48. package/client/dist/assets/KaTeX_SansSerif-Regular-BNo7hRIc.ttf +0 -0
  49. package/client/dist/assets/KaTeX_SansSerif-Regular-CS6fqUqJ.woff +0 -0
  50. package/client/dist/assets/KaTeX_SansSerif-Regular-DDBCnlJ7.woff2 +0 -0
  51. package/client/dist/assets/KaTeX_Script-Regular-C5JkGWo-.ttf +0 -0
  52. package/client/dist/assets/KaTeX_Script-Regular-D3wIWfF6.woff2 +0 -0
  53. package/client/dist/assets/KaTeX_Script-Regular-D5yQViql.woff +0 -0
  54. package/client/dist/assets/KaTeX_Size1-Regular-C195tn64.woff +0 -0
  55. package/client/dist/assets/KaTeX_Size1-Regular-Dbsnue_I.ttf +0 -0
  56. package/client/dist/assets/KaTeX_Size1-Regular-mCD8mA8B.woff2 +0 -0
  57. package/client/dist/assets/KaTeX_Size2-Regular-B7gKUWhC.ttf +0 -0
  58. package/client/dist/assets/KaTeX_Size2-Regular-Dy4dx90m.woff2 +0 -0
  59. package/client/dist/assets/KaTeX_Size2-Regular-oD1tc_U0.woff +0 -0
  60. package/client/dist/assets/KaTeX_Size3-Regular-CTq5MqoE.woff +0 -0
  61. package/client/dist/assets/KaTeX_Size3-Regular-DgpXs0kz.ttf +0 -0
  62. package/client/dist/assets/KaTeX_Size4-Regular-BF-4gkZK.woff +0 -0
  63. package/client/dist/assets/KaTeX_Size4-Regular-DWFBv043.ttf +0 -0
  64. package/client/dist/assets/KaTeX_Size4-Regular-Dl5lxZxV.woff2 +0 -0
  65. package/client/dist/assets/KaTeX_Typewriter-Regular-C0xS9mPB.woff +0 -0
  66. package/client/dist/assets/KaTeX_Typewriter-Regular-CO6r4hn1.woff2 +0 -0
  67. package/client/dist/assets/KaTeX_Typewriter-Regular-D3Ib7_Hf.ttf +0 -0
  68. package/client/dist/assets/LoginModal-BRycfsyD.js +13 -0
  69. package/client/dist/assets/MarkdownPreview-DHmk3qzu.js +1 -0
  70. package/client/dist/assets/MermaidBlock-BuBc_G-F.js +2 -0
  71. package/client/dist/assets/Onboarding-BcnaZZ0o.js +1 -0
  72. package/client/dist/assets/PreviewPanel-CqCa92Tf.js +32 -0
  73. package/client/dist/assets/SetupForm-S0g6u5yT.js +1 -0
  74. package/client/dist/assets/WorkflowsPanel-CouH9JDO.js +1 -0
  75. package/client/dist/assets/index-BFuqS0tY.css +1 -0
  76. package/client/dist/assets/index-CNDcVl2g.js +68 -0
  77. package/client/dist/assets/pdf-CE_K4jFx.js +12 -0
  78. package/client/dist/assets/vendor-canvas-BZV40eAE.css +1 -0
  79. package/client/dist/assets/vendor-canvas-D39yWul6.js +49 -0
  80. package/client/dist/assets/vendor-codemirror-CbtmxxaB.js +35 -0
  81. package/client/dist/assets/vendor-diff-DNQpbhrT.js +69 -0
  82. package/client/dist/assets/vendor-i18n-DCFGyhQR.js +1 -0
  83. package/client/dist/assets/vendor-icons-BaD0x9SL.js +711 -0
  84. package/client/dist/assets/vendor-markdown-CimbIo6Y.js +296 -0
  85. package/client/dist/assets/vendor-mermaid-CH7SGc99.js +2556 -0
  86. package/client/dist/assets/vendor-react-96lCPsRK.js +67 -0
  87. package/client/dist/assets/vendor-syntax-DuHI9Ok6.js +16 -0
  88. package/client/dist/assets/vendor-xterm-CZq1hqo1.js +66 -0
  89. package/client/dist/assets/vendor-xterm-qxJ8_QYu.css +32 -0
  90. package/client/dist/clear-cache.html +85 -0
  91. package/client/dist/convert-icons.md +53 -0
  92. package/client/dist/favicon.png +0 -0
  93. package/client/dist/favicon.svg +5 -0
  94. package/client/dist/generate-icons.js +49 -0
  95. package/client/dist/icons/claude-ai-icon.svg +1 -0
  96. package/client/dist/icons/codex-white.svg +3 -0
  97. package/client/dist/icons/codex.svg +3 -0
  98. package/client/dist/icons/cursor-white.svg +12 -0
  99. package/client/dist/icons/cursor.svg +1 -0
  100. package/client/dist/icons/icon-128x128.png +0 -0
  101. package/client/dist/icons/icon-128x128.svg +5 -0
  102. package/client/dist/icons/icon-144x144.png +0 -0
  103. package/client/dist/icons/icon-144x144.svg +5 -0
  104. package/client/dist/icons/icon-152x152.png +0 -0
  105. package/client/dist/icons/icon-152x152.svg +5 -0
  106. package/client/dist/icons/icon-192x192.png +0 -0
  107. package/client/dist/icons/icon-192x192.svg +5 -0
  108. package/client/dist/icons/icon-384x384.png +0 -0
  109. package/client/dist/icons/icon-384x384.svg +5 -0
  110. package/client/dist/icons/icon-512x512.png +0 -0
  111. package/client/dist/icons/icon-512x512.svg +5 -0
  112. package/client/dist/icons/icon-72x72.png +0 -0
  113. package/client/dist/icons/icon-72x72.svg +5 -0
  114. package/client/dist/icons/icon-96x96.png +0 -0
  115. package/client/dist/icons/icon-96x96.svg +5 -0
  116. package/client/dist/icons/icon-template.svg +5 -0
  117. package/client/dist/index.html +119 -0
  118. package/client/dist/logo-128.png +0 -0
  119. package/client/dist/logo-256.png +0 -0
  120. package/client/dist/logo-32.png +0 -0
  121. package/client/dist/logo-512.png +0 -0
  122. package/client/dist/logo-64.png +0 -0
  123. package/client/dist/logo.svg +14 -0
  124. package/client/dist/manifest.json +61 -0
  125. package/client/dist/mcp-docs.html +108 -0
  126. package/client/dist/offline.html +84 -0
  127. package/client/dist/screenshots/cli-selection.png +0 -0
  128. package/client/dist/screenshots/desktop-main.png +0 -0
  129. package/client/dist/screenshots/mobile-chat.png +0 -0
  130. package/client/dist/screenshots/tools-modal.png +0 -0
  131. package/client/dist/sw.js +82 -0
  132. package/commands/upfynai-connect.md +59 -0
  133. package/commands/upfynai-disconnect.md +31 -0
  134. package/commands/upfynai-doctor.md +99 -0
  135. package/commands/upfynai-export.md +49 -0
  136. package/commands/upfynai-local.md +82 -0
  137. package/commands/upfynai-status.md +75 -0
  138. package/commands/upfynai-stop.md +49 -0
  139. package/commands/upfynai-uninstall.md +58 -0
  140. package/commands/upfynai.md +69 -0
  141. package/package.json +143 -82
  142. package/scripts/build-client.js +17 -0
  143. package/scripts/fix-node-pty.js +67 -0
  144. package/scripts/install-commands.js +78 -0
  145. package/server/agent-loop.js +242 -0
  146. package/server/auto-compact.js +99 -0
  147. package/server/claude-sdk.js +797 -0
  148. package/server/cli-ui.js +785 -0
  149. package/server/cli.js +596 -0
  150. package/server/constants/config.js +31 -0
  151. package/server/cursor-cli.js +270 -0
  152. package/server/database/auth.db +0 -0
  153. package/server/database/db.js +1391 -0
  154. package/server/database/init.sql +70 -0
  155. package/server/index.js +3799 -0
  156. package/server/load-env.js +26 -0
  157. package/server/mcp-server.js +621 -0
  158. package/server/middleware/auth.js +176 -0
  159. package/server/middleware/relayHelpers.js +44 -0
  160. package/server/middleware/sandboxRouter.js +174 -0
  161. package/server/openai-codex.js +403 -0
  162. package/server/openrouter.js +137 -0
  163. package/server/projects.js +1807 -0
  164. package/server/provider-factory.js +174 -0
  165. package/server/relay-client.js +379 -0
  166. package/server/routes/agent.js +1226 -0
  167. package/server/routes/auth.js +554 -0
  168. package/server/routes/canvas.js +53 -0
  169. package/server/routes/cli-auth.js +263 -0
  170. package/server/routes/codex.js +396 -0
  171. package/server/routes/commands.js +707 -0
  172. package/server/routes/composio.js +176 -0
  173. package/server/routes/cursor.js +770 -0
  174. package/server/routes/dashboard.js +295 -0
  175. package/server/routes/git.js +1208 -0
  176. package/server/routes/keys.js +34 -0
  177. package/server/routes/mcp-utils.js +48 -0
  178. package/server/routes/mcp.js +661 -0
  179. package/server/routes/payments.js +227 -0
  180. package/server/routes/projects.js +655 -0
  181. package/server/routes/sessions.js +146 -0
  182. package/server/routes/settings.js +261 -0
  183. package/server/routes/taskmaster.js +1928 -0
  184. package/server/routes/user.js +106 -0
  185. package/server/routes/vapi-chat.js +624 -0
  186. package/server/routes/voice.js +235 -0
  187. package/server/routes/webhooks.js +166 -0
  188. package/server/routes/workflows.js +312 -0
  189. package/server/sandbox.js +120 -0
  190. package/server/services/composio.js +204 -0
  191. package/server/services/sessionRegistry.js +139 -0
  192. package/server/services/whisperService.js +84 -0
  193. package/server/services/workflowScheduler.js +206 -0
  194. package/server/tests/relay-flow.test.js +570 -0
  195. package/server/tests/sessions.test.js +259 -0
  196. package/server/utils/commandParser.js +303 -0
  197. package/server/utils/email.js +61 -0
  198. package/server/utils/gitConfig.js +24 -0
  199. package/server/utils/mcp-detector.js +198 -0
  200. package/server/utils/taskmaster-websocket.js +129 -0
  201. package/shared/integrationCatalog.d.ts +12 -0
  202. package/shared/integrationCatalog.js +172 -0
  203. package/shared/modelConstants.js +96 -0
  204. package/bin/cli.js +0 -97
  205. package/dist/agents/claude.js +0 -229
  206. package/dist/agents/codex.js +0 -48
  207. package/dist/agents/cursor.js +0 -48
  208. package/dist/agents/detect.js +0 -51
  209. package/dist/agents/exec.js +0 -31
  210. package/dist/agents/files.js +0 -105
  211. package/dist/agents/git.js +0 -18
  212. package/dist/agents/gitagent.js +0 -67
  213. package/dist/agents/index.js +0 -88
  214. package/dist/agents/shell.js +0 -38
  215. package/dist/agents/utils.js +0 -136
  216. package/scripts/postinstall.js +0 -9
  217. package/scripts/prepublish.js +0 -58
  218. package/src/animation.js +0 -228
  219. package/src/auth.js +0 -122
  220. package/src/config.js +0 -40
  221. package/src/connect.js +0 -416
  222. package/src/launch.js +0 -78
  223. package/src/mcp.js +0 -57
  224. package/src/permissions.js +0 -140
  225. package/src/persistent-shell.js +0 -261
  226. package/src/server.js +0 -54
  227. /package/{dist → shared}/gitagent/index.js +0 -0
  228. /package/{dist → shared}/gitagent/parser.js +0 -0
  229. /package/{dist → shared}/gitagent/prompt-builder.js +0 -0
package/server/cli.js ADDED
@@ -0,0 +1,596 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Upfyn-Code CLI
4
+ * by Thinqmesh Technologies
5
+ *
6
+ * Visual AI coding interface with Upfyn-Canvas for AI coding assistants
7
+ *
8
+ * Commands:
9
+ * (no args) - Launch Claude Code with Upfyn branding (default)
10
+ * start - Start the server
11
+ * connect - Connect to hosted server (relay bridge)
12
+ * config - View/set configuration (API key, server, etc.)
13
+ * status - Show configuration and data locations
14
+ * help - Show help information
15
+ * version - Show version information
16
+ */
17
+
18
+ import fs from 'fs';
19
+ import path from 'path';
20
+ import os from 'os';
21
+ import { fileURLToPath } from 'url';
22
+ import { dirname } from 'path';
23
+ import { execSync, spawn } from 'child_process';
24
+ import {
25
+ c,
26
+ showStyledHelp,
27
+ showStyledStatus,
28
+ showServerBanner,
29
+ showConnectStartup,
30
+ showConnectionBanner,
31
+ showLaunchScreen,
32
+ showConfig,
33
+ logRelayEvent,
34
+ createSpinner,
35
+ playRocketAnimation,
36
+ clearScreen,
37
+ } from './cli-ui.js';
38
+
39
+ const __filename = fileURLToPath(import.meta.url);
40
+ const __dirname = dirname(__filename);
41
+
42
+ // Load package.json for version info
43
+ const packageJsonPath = path.join(__dirname, '../package.json');
44
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
45
+
46
+ const CONFIG_DIR = path.join(os.homedir(), '.upfynai');
47
+ const CONFIG_FILE = path.join(CONFIG_DIR, 'config.json');
48
+
49
+ // Load environment variables from .env file if it exists
50
+ function loadEnvFile() {
51
+ try {
52
+ const envPath = path.join(__dirname, '../.env');
53
+ const envFile = fs.readFileSync(envPath, 'utf8');
54
+ envFile.split('\n').forEach(line => {
55
+ const trimmedLine = line.trim();
56
+ if (trimmedLine && !trimmedLine.startsWith('#')) {
57
+ const [key, ...valueParts] = trimmedLine.split('=');
58
+ if (key && valueParts.length > 0 && !process.env[key]) {
59
+ process.env[key] = valueParts.join('=').trim();
60
+ }
61
+ }
62
+ });
63
+ } catch (e) {
64
+ // .env file is optional
65
+ }
66
+ }
67
+
68
+ // Load saved config from ~/.upfynai/config.json
69
+ function loadConfig() {
70
+ try {
71
+ if (fs.existsSync(CONFIG_FILE)) {
72
+ return JSON.parse(fs.readFileSync(CONFIG_FILE, 'utf8'));
73
+ }
74
+ } catch (e) { /* ignore */ }
75
+ return {};
76
+ }
77
+
78
+ // Save config to ~/.upfynai/config.json
79
+ function saveConfig(config) {
80
+ if (!fs.existsSync(CONFIG_DIR)) {
81
+ fs.mkdirSync(CONFIG_DIR, { recursive: true });
82
+ }
83
+ // Don't save internal keys
84
+ const { _path, ...rest } = config;
85
+ fs.writeFileSync(CONFIG_FILE, JSON.stringify(rest, null, 2));
86
+ }
87
+
88
+ // Get the database path (same logic as db.js)
89
+ function getDatabasePath() {
90
+ loadEnvFile();
91
+ return process.env.DATABASE_PATH || path.join(__dirname, 'database', 'auth.db');
92
+ }
93
+
94
+ // Get the installation directory
95
+ function getInstallDir() {
96
+ return path.join(__dirname, '..');
97
+ }
98
+
99
+ // --- OS Detection + Claude Binary Discovery ---
100
+
101
+ function findClaudeBinary() {
102
+ const isWindows = process.platform === 'win32';
103
+ const candidates = isWindows
104
+ ? ['claude.exe', 'claude.cmd', 'claude']
105
+ : ['claude'];
106
+
107
+ for (const cmd of candidates) {
108
+ try {
109
+ const whichCmd = isWindows ? 'where' : 'which';
110
+ const result = execSync(`${whichCmd} ${cmd}`, { stdio: 'pipe', encoding: 'utf8' }).trim();
111
+ if (result) return cmd;
112
+ } catch {
113
+ // not found, try next
114
+ }
115
+ }
116
+ return null;
117
+ }
118
+
119
+ // --- Show status command ---
120
+ function showStatus() {
121
+ const config = loadConfig();
122
+ const installDir = getInstallDir();
123
+ const dbPath = getDatabasePath();
124
+ const dbExists = fs.existsSync(dbPath);
125
+ let dbSize = '';
126
+ if (dbExists) {
127
+ const stats = fs.statSync(dbPath);
128
+ dbSize = (stats.size / 1024).toFixed(2) + ' KB';
129
+ }
130
+
131
+ showStyledStatus({
132
+ version: packageJson.version,
133
+ installDir,
134
+ dbPath,
135
+ dbExists,
136
+ dbSize,
137
+ port: process.env.PORT || '3001',
138
+ portDefault: !process.env.PORT,
139
+ claudeCli: findClaudeBinary() || null,
140
+ apiKey: config.anthropicApiKey || null,
141
+ });
142
+ }
143
+
144
+ // Show help
145
+ function showHelp() {
146
+ showStyledHelp(packageJson.version);
147
+ }
148
+
149
+ // Show version
150
+ function showVersion() {
151
+ console.log(`${packageJson.version}`);
152
+ }
153
+
154
+ // Compare semver versions, returns true if v1 > v2
155
+ function isNewerVersion(v1, v2) {
156
+ const parts1 = v1.split('.').map(Number);
157
+ const parts2 = v2.split('.').map(Number);
158
+ for (let i = 0; i < 3; i++) {
159
+ if (parts1[i] > parts2[i]) return true;
160
+ if (parts1[i] < parts2[i]) return false;
161
+ }
162
+ return false;
163
+ }
164
+
165
+ // Check for updates
166
+ async function checkForUpdates(silent = false) {
167
+ try {
168
+ const latestVersion = execSync('npm show upfynai-code version', { encoding: 'utf8' }).trim();
169
+ const currentVersion = packageJson.version;
170
+
171
+ if (isNewerVersion(latestVersion, currentVersion)) {
172
+ if (!silent) {
173
+ console.log(`\n ${c.yellow('!')} New version available: ${c.bBright(latestVersion)} ${c.dim(`(current: ${currentVersion})`)}`);
174
+ console.log(` Run ${c.bright('uc update')} to update\n`);
175
+ }
176
+ return { hasUpdate: true, latestVersion, currentVersion };
177
+ } else if (!silent) {
178
+ console.log(` ${c.green('OK')} You are on the latest version (${currentVersion})`);
179
+ }
180
+ return { hasUpdate: false, latestVersion, currentVersion };
181
+ } catch (e) {
182
+ if (!silent) {
183
+ console.log(` ${c.yellow('!')} Could not check for updates`);
184
+ }
185
+ return { hasUpdate: false, error: e.message };
186
+ }
187
+ }
188
+
189
+ // Update the package
190
+ async function updatePackage() {
191
+ try {
192
+ const spinner = createSpinner('Checking for updates...');
193
+ spinner.start();
194
+
195
+ const { hasUpdate, latestVersion, currentVersion } = await checkForUpdates(true);
196
+ if (!hasUpdate) {
197
+ spinner.stop(`Already on the latest version (${currentVersion})`);
198
+ return;
199
+ }
200
+ spinner.stop(`Update available: ${currentVersion} -> ${latestVersion}`);
201
+
202
+ const installSpinner = createSpinner(`Updating to v${latestVersion}...`);
203
+ installSpinner.start();
204
+ execSync('npm update -g upfynai-code', { stdio: 'pipe' });
205
+ installSpinner.stop(`Updated to v${latestVersion}! Restart uc to use the new version.`);
206
+ } catch (e) {
207
+ console.log(` ${c.red('FAIL')} Update failed: ${e.message}`);
208
+ console.log(` ${c.dim('Try running manually:')} ${c.bright('npm update -g upfynai-code')}`);
209
+ }
210
+ }
211
+
212
+ // Install slash commands to ~/.claude/commands/
213
+ async function installCommands(silent = false) {
214
+ const commandsSource = path.join(__dirname, '..', 'commands');
215
+ const commandsDest = path.join(os.homedir(), '.claude', 'commands');
216
+
217
+ if (!fs.existsSync(commandsDest)) {
218
+ fs.mkdirSync(commandsDest, { recursive: true });
219
+ }
220
+
221
+ if (!fs.existsSync(commandsSource)) {
222
+ if (!silent) console.log(` ${c.red('FAIL')} Commands directory not found`);
223
+ return 0;
224
+ }
225
+
226
+ const files = fs.readdirSync(commandsSource).filter(f => f.endsWith('.md'));
227
+ let count = 0;
228
+
229
+ for (const file of files) {
230
+ fs.copyFileSync(
231
+ path.join(commandsSource, file),
232
+ path.join(commandsDest, file)
233
+ );
234
+ if (!silent) {
235
+ console.log(` ${c.green('OK')} Installed ${c.violet('/' + file.replace('.md', ''))}`);
236
+ }
237
+ count++;
238
+ }
239
+
240
+ if (!silent) {
241
+ console.log(`\n ${c.bBright(`${count} slash commands installed!`)}`);
242
+ console.log(` ${c.dim('Available in your AI CLI as /upfynai-*')}\n`);
243
+ }
244
+ return count;
245
+ }
246
+
247
+ // Remove slash commands from ~/.claude/commands/
248
+ async function uninstallCommands() {
249
+ const commandsDest = path.join(os.homedir(), '.claude', 'commands');
250
+ const files = fs.existsSync(commandsDest)
251
+ ? fs.readdirSync(commandsDest).filter(f => f.startsWith('upfynai'))
252
+ : [];
253
+
254
+ if (files.length === 0) {
255
+ console.log(` ${c.yellow('!')} No Upfyn-Code commands found to remove`);
256
+ return;
257
+ }
258
+
259
+ for (const file of files) {
260
+ fs.unlinkSync(path.join(commandsDest, file));
261
+ console.log(` ${c.green('OK')} Removed ${c.violet('/' + file.replace('.md', ''))}`);
262
+ }
263
+
264
+ console.log(`\n ${c.bBright(`${files.length} slash commands removed.`)}\n`);
265
+ }
266
+
267
+ // --- Config command ---
268
+ function handleConfig(options) {
269
+ const config = loadConfig();
270
+
271
+ if (options.apiKey) {
272
+ // Set API key
273
+ config.anthropicApiKey = options.apiKey;
274
+ saveConfig(config);
275
+ console.log(`\n ${c.green('OK')} ${c.white('Anthropic API key saved')}`);
276
+ console.log(` ${c.dim('Key:')} sk-ant-...${options.apiKey.slice(-4)}`);
277
+ console.log(` ${c.dim('Stored in:')} ${CONFIG_FILE}\n`);
278
+ return;
279
+ }
280
+
281
+ if (options.clearApiKey) {
282
+ delete config.anthropicApiKey;
283
+ saveConfig(config);
284
+ console.log(`\n ${c.green('OK')} ${c.white('Anthropic API key removed')}\n`);
285
+ return;
286
+ }
287
+
288
+ // Show current config
289
+ showConfig({ ...config, _path: CONFIG_FILE });
290
+ }
291
+
292
+ // --- First-run detection ---
293
+ function isFirstRun() {
294
+ return !fs.existsSync(CONFIG_FILE);
295
+ }
296
+
297
+ function showFirstRunWelcome() {
298
+ const W = 58;
299
+ const lines = [];
300
+ lines.push('');
301
+ lines.push(` ${c.bBright('Welcome to Upfyn-Code!')} ${c.dim('v' + packageJson.version)}`);
302
+ lines.push(` ${c.dark('='.repeat(W))}`);
303
+ lines.push('');
304
+ lines.push(` ${c.white('Upfyn-Code gives you a visual AI coding interface')}`);
305
+ lines.push(` ${c.white('for Claude Code, Cursor, and Codex — all in one place.')}`);
306
+ lines.push('');
307
+ lines.push(` ${c.bCyan('Quick start:')}`);
308
+ lines.push(` ${c.bright('1.')} ${c.gray('Run')} ${c.cyan('uc')} ${c.gray('to launch with Claude Code')}`);
309
+ lines.push(` ${c.bright('2.')} ${c.gray('Run')} ${c.cyan('uc start')} ${c.gray('for just the web UI')}`);
310
+ lines.push(` ${c.bright('3.')} ${c.gray('Run')} ${c.cyan('uc connect --key <token>')} ${c.gray('to bridge to cli.upfyn.com')}`);
311
+ lines.push('');
312
+ lines.push(` ${c.bCyan('Optional setup:')}`);
313
+ lines.push(` ${c.dim('$')} ${c.bright('uc config --api-key sk-ant-xxx')} ${c.dim('# Save your API key')}`);
314
+ lines.push(` ${c.dim('$')} ${c.bright('uc install-commands')} ${c.dim('# Add slash commands')}`);
315
+ lines.push('');
316
+ lines.push(` ${c.dim('Run')} ${c.bright('uc help')} ${c.dim('for all commands.')}`);
317
+ lines.push(` ${c.dark('='.repeat(W))}`);
318
+ lines.push('');
319
+ process.stdout.write(lines.join('\n') + '\n');
320
+
321
+ // Create config dir so first-run only shows once
322
+ if (!fs.existsSync(CONFIG_DIR)) {
323
+ fs.mkdirSync(CONFIG_DIR, { recursive: true });
324
+ }
325
+ saveConfig({});
326
+ }
327
+
328
+ // --- Launch Interactive (default command) ---
329
+ async function launchInteractive() {
330
+ // 0. Show first-run welcome if needed
331
+ const firstRun = isFirstRun();
332
+
333
+ // 1. Play rocket animation
334
+ await playRocketAnimation();
335
+ clearScreen();
336
+
337
+ // 1.5 Show first-run tips (only once)
338
+ if (firstRun) {
339
+ showFirstRunWelcome();
340
+ }
341
+
342
+ // 2. Ensure slash commands are installed (silent)
343
+ await installCommands(true);
344
+
345
+ // 3. Find Claude Code binary
346
+ const claudeBin = findClaudeBinary();
347
+
348
+ // 4. Load config for relay + API key
349
+ const config = loadConfig();
350
+
351
+ // 5. Show launch screen
352
+ showLaunchScreen(packageJson.version, claudeBin, {
353
+ relayStatus: config.relayKey && config.server
354
+ ? `Auto-connecting to ${config.server}`
355
+ : null,
356
+ apiKey: config.anthropicApiKey || null,
357
+ });
358
+
359
+ // 6. If Claude Code not found, fall back to server mode
360
+ if (!claudeBin) {
361
+ console.log(` ${c.dim('Falling back to server mode...')}\n`);
362
+ await startServer();
363
+ return;
364
+ }
365
+
366
+ // 7. Build environment for Claude Code
367
+ const childEnv = { ...process.env };
368
+ if (config.anthropicApiKey) {
369
+ childEnv.ANTHROPIC_API_KEY = config.anthropicApiKey;
370
+ }
371
+
372
+ // 8. Start the local web UI server in the background
373
+ const port = process.env.PORT || '3001';
374
+ process.env.VITE_IS_PLATFORM = 'true'; // local mode
375
+ startBackgroundServer(port);
376
+
377
+ // 9. Start background relay if config exists (for cloud mode)
378
+ if (config.relayKey && config.server) {
379
+ startBackgroundRelay(config);
380
+ }
381
+
382
+ // 10. Spawn Claude Code interactively
383
+ const child = spawn(claudeBin, [], {
384
+ stdio: 'inherit',
385
+ cwd: process.cwd(),
386
+ shell: true,
387
+ env: childEnv,
388
+ });
389
+
390
+ child.on('exit', (code) => {
391
+ process.exit(code || 0);
392
+ });
393
+
394
+ child.on('error', (err) => {
395
+ console.log(`\n ${c.red('FAIL')} Failed to launch Claude Code: ${err.message}`);
396
+ console.log(` ${c.dim('Make sure Claude Code is installed:')}`);
397
+ console.log(` ${c.bright('npm install -g @anthropic-ai/claude-code')}\n`);
398
+ process.exit(1);
399
+ });
400
+ }
401
+
402
+ // --- Background server for local mode ---
403
+ function startBackgroundServer(port) {
404
+ // Start the server in the background so the web UI is available
405
+ import('./index.js').then(() => {
406
+ // Server started successfully in background
407
+ }).catch(() => {
408
+ // Server failed to start — user still has Claude Code CLI
409
+ });
410
+
411
+ // Open browser after a short delay
412
+ setTimeout(() => {
413
+ const url = `http://localhost:${port}`;
414
+ try {
415
+ const openCmd = process.platform === 'win32' ? 'start'
416
+ : process.platform === 'darwin' ? 'open'
417
+ : 'xdg-open';
418
+ execSync(`${openCmd} ${url}`, { stdio: 'ignore' });
419
+ } catch {
420
+ // Browser open failed — not critical
421
+ }
422
+ }, 2000);
423
+ }
424
+
425
+ // --- Background relay connection ---
426
+ function startBackgroundRelay(config) {
427
+ // Import and start relay in background (non-blocking)
428
+ import('./relay-client.js').then(({ connectToServerBackground }) => {
429
+ if (typeof connectToServerBackground === 'function') {
430
+ connectToServerBackground({
431
+ server: config.server,
432
+ key: config.relayKey,
433
+ silent: true,
434
+ });
435
+ }
436
+ }).catch(() => {
437
+ // Relay module not available or no background connect — that's ok
438
+ });
439
+ }
440
+
441
+ // Start the server (self-hosted local mode)
442
+ async function startServer() {
443
+ // Check for updates silently on startup
444
+ checkForUpdates(true);
445
+
446
+ const port = process.env.PORT || '3001';
447
+
448
+ // Auto-detect local mode — set IS_PLATFORM flag
449
+ if (!process.env.RAILWAY_ENVIRONMENT && !process.env.VERCEL && !process.env.FORCE_HOSTED_MODE) {
450
+ process.env.VITE_IS_PLATFORM = 'true';
451
+ }
452
+
453
+ // Show server banner
454
+ showServerBanner(port, packageJson.version);
455
+
456
+ // Detect local agents
457
+ const claudeBin = findClaudeBinary();
458
+ if (claudeBin) {
459
+ console.log(` ${c.green('OK')} Claude Code detected: ${c.bright(claudeBin)}`);
460
+ } else {
461
+ console.log(` ${c.yellow('!')} Claude Code not found. Install: ${c.bright('npm i -g @anthropic-ai/claude-code')}`);
462
+ }
463
+ console.log('');
464
+
465
+ // Import and run the server
466
+ await import('./index.js');
467
+
468
+ // Auto-open browser after server starts (local mode only)
469
+ if (!process.env.RAILWAY_ENVIRONMENT && !process.env.VERCEL) {
470
+ const url = `http://localhost:${port}`;
471
+ setTimeout(() => {
472
+ try {
473
+ const openCmd = process.platform === 'win32' ? 'start'
474
+ : process.platform === 'darwin' ? 'open'
475
+ : 'xdg-open';
476
+ execSync(`${openCmd} ${url}`, { stdio: 'ignore' });
477
+ console.log(` ${c.green('OK')} Opened ${c.cyan(url)} in browser\n`);
478
+ } catch {
479
+ console.log(` ${c.dim('Open in browser:')} ${c.cyan(url)}\n`);
480
+ }
481
+ }, 1500);
482
+ }
483
+ }
484
+
485
+ // Parse CLI arguments
486
+ function parseArgs(args) {
487
+ const parsed = { command: null, options: {} };
488
+
489
+ for (let i = 0; i < args.length; i++) {
490
+ const arg = args[i];
491
+
492
+ if (arg === '--port' || arg === '-p') {
493
+ parsed.options.port = args[++i];
494
+ } else if (arg.startsWith('--port=')) {
495
+ parsed.options.port = arg.split('=')[1];
496
+ } else if (arg === '--database-path') {
497
+ parsed.options.databasePath = args[++i];
498
+ } else if (arg.startsWith('--database-path=')) {
499
+ parsed.options.databasePath = arg.split('=')[1];
500
+ } else if (arg === '--server') {
501
+ parsed.options.server = args[++i];
502
+ } else if (arg.startsWith('--server=')) {
503
+ parsed.options.server = arg.split('=')[1];
504
+ } else if (arg === '--key') {
505
+ parsed.options.key = args[++i];
506
+ } else if (arg.startsWith('--key=')) {
507
+ parsed.options.key = arg.split('=')[1];
508
+ } else if (arg === '--api-key') {
509
+ parsed.options.apiKey = args[++i];
510
+ } else if (arg.startsWith('--api-key=')) {
511
+ parsed.options.apiKey = arg.split('=')[1];
512
+ } else if (arg === '--clear-api-key') {
513
+ parsed.options.clearApiKey = true;
514
+ } else if (arg === '--help' || arg === '-h') {
515
+ parsed.command = 'help';
516
+ } else if (arg === '--version' || arg === '-v') {
517
+ parsed.command = 'version';
518
+ } else if (!arg.startsWith('-') && !parsed.command) {
519
+ parsed.command = arg;
520
+ }
521
+ }
522
+
523
+ // Default command: launch interactive
524
+ if (!parsed.command) {
525
+ parsed.command = 'launch';
526
+ }
527
+
528
+ return parsed;
529
+ }
530
+
531
+ // Main CLI handler
532
+ async function main() {
533
+ const args = process.argv.slice(2);
534
+ const { command, options } = parseArgs(args);
535
+
536
+ // Apply CLI options to environment variables
537
+ if (options.port) {
538
+ process.env.PORT = options.port;
539
+ }
540
+ if (options.databasePath) {
541
+ process.env.DATABASE_PATH = options.databasePath;
542
+ }
543
+
544
+ switch (command) {
545
+ case 'launch':
546
+ await launchInteractive();
547
+ break;
548
+ case 'start':
549
+ await startServer();
550
+ break;
551
+ case 'status':
552
+ case 'info':
553
+ showStatus();
554
+ break;
555
+ case 'help':
556
+ case '-h':
557
+ case '--help':
558
+ showHelp();
559
+ break;
560
+ case 'version':
561
+ case '-v':
562
+ case '--version':
563
+ showVersion();
564
+ break;
565
+ case 'update':
566
+ await updatePackage();
567
+ break;
568
+ case 'config':
569
+ handleConfig(options);
570
+ break;
571
+ case 'install-commands':
572
+ await installCommands();
573
+ break;
574
+ case 'uninstall-commands':
575
+ await uninstallCommands();
576
+ break;
577
+ case 'connect': {
578
+ const { connectToServer } = await import('./relay-client.js');
579
+ await connectToServer({
580
+ server: options.server || args[1],
581
+ key: options.key || args[2],
582
+ });
583
+ break;
584
+ }
585
+ default:
586
+ console.error(`\n ${c.red('FAIL')} Unknown command: ${command}`);
587
+ console.log(` Run ${c.bright('"uc help"')} for usage information.\n`);
588
+ process.exit(1);
589
+ }
590
+ }
591
+
592
+ // Run the CLI
593
+ main().catch(error => {
594
+ console.error(`\n ${c.red('FAIL')} Error: ${error.message}`);
595
+ process.exit(1);
596
+ });
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Environment Flag: Is Platform (Self-Hosted / Local Mode)
3
+ *
4
+ * When true, the app runs in single-user local mode:
5
+ * - Skips JWT authentication (uses first DB user)
6
+ * - Claude Code SDK runs directly on the machine
7
+ * - No relay connection needed
8
+ *
9
+ * Auto-detected when:
10
+ * - VITE_IS_PLATFORM=true is set, OR
11
+ * - Running locally (not on Railway/Vercel/cloud)
12
+ */
13
+ const isCloudEnv = !!(
14
+ process.env.RAILWAY_ENVIRONMENT ||
15
+ process.env.VERCEL ||
16
+ process.env.RENDER ||
17
+ process.env.FLY_APP_NAME ||
18
+ process.env.HEROKU_APP_NAME
19
+ );
20
+
21
+ export const IS_PLATFORM = process.env.VITE_IS_PLATFORM === 'true' || (!isCloudEnv && !process.env.FORCE_HOSTED_MODE);
22
+
23
+ /**
24
+ * True when running on a cloud provider (Railway, Vercel, etc.)
25
+ */
26
+ export const IS_CLOUD = isCloudEnv;
27
+
28
+ /**
29
+ * True when running locally (self-hosted mode)
30
+ */
31
+ export const IS_LOCAL = IS_PLATFORM && !isCloudEnv;