vzcode 3.2.0 → 3.3.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 (64) hide show
  1. package/README.md +185 -40
  2. package/dist/assets/App-C9mRI7eH.js +387 -0
  3. package/dist/assets/App-CxiKy3Rs.css +1 -0
  4. package/dist/assets/bindings_wasm_bg-IWNG_AjZ.wasm +0 -0
  5. package/dist/assets/buildWorker-N5tFTOqM.js +794 -0
  6. package/dist/assets/index-COLyIkCc.js +43 -0
  7. package/dist/assets/index-CZT-v4sH.css +1 -0
  8. package/dist/assets/rolldown-runtime-COiEfhsA.js +1 -0
  9. package/dist/assets/worker-BpV7Ustv.js +223 -0
  10. package/dist/assets/worker-CLeezw6h.js +458 -0
  11. package/dist/assets/worker-DaSIYBQX.js +327 -0
  12. package/dist/cli.js +170 -99
  13. package/dist/index.html +3 -2
  14. package/dist/server/accessControl.js +104 -0
  15. package/dist/server/computeInitialDocument.js +4 -1
  16. package/dist/server/createServer.js +356 -104
  17. package/dist/server/index.js +4 -3
  18. package/dist/server/workspaceSecurity.js +115 -0
  19. package/dist/server/workspaceSync.js +141 -0
  20. package/package.json +74 -72
  21. package/src/cli.ts +203 -182
  22. package/src/client/App/index.tsx +2 -0
  23. package/src/client/App/usePending.ts +3 -1
  24. package/src/client/RunCodeWidget/index.tsx +1 -0
  25. package/src/client/VZCodeContext/types.ts +6 -0
  26. package/src/client/VZCodeContext/useVZCodeState.ts +2 -0
  27. package/src/client/VZSidebar/AIChatWrapper.tsx +2 -0
  28. package/src/client/VZSidebar/VisualEditor/CheckboxWidget.tsx +22 -30
  29. package/src/client/VZSidebar/VisualEditor/ColorWidget.tsx +198 -126
  30. package/src/client/VZSidebar/VisualEditor/DropdownWidget.tsx +25 -67
  31. package/src/client/VZSidebar/VisualEditor/PropertySection.tsx +41 -0
  32. package/src/client/VZSidebar/VisualEditor/SegmentedWidget.tsx +34 -0
  33. package/src/client/VZSidebar/VisualEditor/SliderWidget.tsx +60 -12
  34. package/src/client/VZSidebar/VisualEditor/VisualEditor.tsx +31 -393
  35. package/src/client/VZSidebar/VisualEditor/VisualEditorControls.tsx +478 -0
  36. package/src/client/VZSidebar/VisualEditor/colorUtils.ts +12 -0
  37. package/src/client/VZSidebar/VisualEditor/status.ts +47 -0
  38. package/src/client/VZSidebar/VisualEditor/updateConfig.ts +51 -24
  39. package/src/client/VZSidebar/VisualEditor/utils.ts +1 -1
  40. package/src/client/VZSidebar/styles.scss +420 -0
  41. package/src/client/WorkspaceConflictBanner.tsx +120 -0
  42. package/src/client/index.ts +2 -0
  43. package/src/client/main.jsx +54 -12
  44. package/src/llm-streaming-server/README.md +4 -16
  45. package/src/llm-streaming-ui/README.md +41 -2
  46. package/src/llm-streaming-ui/components/ChatInput.tsx +65 -13
  47. package/src/llm-streaming-ui/components/index.tsx +2 -0
  48. package/src/llm-streaming-ui/hooks/useAutoScroll.ts +1 -1
  49. package/src/llm-streaming-ui/index.ts +1 -0
  50. package/src/llm-streaming-ui/props.ts +26 -2
  51. package/src/server/accessControl.ts +151 -0
  52. package/src/server/computeInitialDocument.ts +6 -2
  53. package/src/server/createServer.ts +487 -138
  54. package/src/server/index.ts +4 -5
  55. package/src/server/workspaceSecurity.ts +160 -0
  56. package/src/server/workspaceSync.ts +203 -0
  57. package/src/types.ts +29 -27
  58. package/dist/assets/bindings_wasm_bg-9w8E-TmY.wasm +0 -0
  59. package/dist/assets/buildWorker-BZlya278.js +0 -687
  60. package/dist/assets/index-B7NRhsN6.js +0 -356
  61. package/dist/assets/index-D1V1AKed.css +0 -1
  62. package/dist/assets/worker-1oQYaz-F.js +0 -342
  63. package/dist/assets/worker-BfgPD8zR.js +0 -125
  64. package/dist/assets/worker-CoJaqtpi.js +0 -436
package/dist/cli.js CHANGED
@@ -1,111 +1,182 @@
1
1
  #!/usr/bin/env node
2
- import { spawn } from 'child_process';
3
- import path from 'path';
4
- import { fileURLToPath } from 'url';
5
- import fs from 'fs';
6
- // Get the directory of the current module
7
- const __filename = fileURLToPath(import.meta.url);
8
- const __dirname = path.dirname(__filename);
9
- // Function to find the Tauri binary
10
- function findTauriApp() {
11
- // Look for the Tauri binary in common locations
12
- const possiblePaths = [
13
- // Development location (when running from source)
14
- path.join(__dirname, '..', 'src-tauri', 'target', 'debug', 'vzcode'),
15
- path.join(__dirname, '..', 'src-tauri', 'target', 'debug', 'vzcode.exe'),
16
- // Release location (when running from built package)
17
- path.join(__dirname, '..', 'src-tauri', 'target', 'release', 'vzcode'),
18
- path.join(__dirname, '..', 'src-tauri', 'target', 'release', 'vzcode.exe'),
19
- // MacOS app bundle
20
- path.join(__dirname, '..', 'src-tauri', 'target', 'debug', 'vzcode.app', 'Contents', 'MacOS', 'vzcode'),
21
- path.join(__dirname, '..', 'src-tauri', 'target', 'release', 'vzcode.app', 'Contents', 'MacOS', 'vzcode'),
22
- ];
23
- for (const binaryPath of possiblePaths) {
24
- if (fs.existsSync(binaryPath)) {
25
- return binaryPath;
26
- }
2
+ import { spawn } from 'node:child_process';
3
+ import fs from 'node:fs';
4
+ import path from 'node:path';
5
+ import { fileURLToPath } from 'node:url';
6
+ import open from 'open';
7
+ import { createVZCodeServer } from './server/createServer.js';
8
+ const DEFAULT_PORT = 3030;
9
+ const HOST = '127.0.0.1';
10
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
11
+ const usage = [
12
+ 'VZCode - Multiplayer Code Editor',
13
+ '',
14
+ 'Usage: vzcode [directory] [options]',
15
+ '',
16
+ 'Starts the browser editor for a local workspace (defaults to ".").',
17
+ '',
18
+ 'Options:',
19
+ ' --help, -h Show this help message',
20
+ ' --browser Use the browser editor (the default)',
21
+ ' --desktop Launch a locally built Tauri application (experimental)',
22
+ ' --no-open Start the server without opening a browser',
23
+ ' --port=<port> HTTP/WebSocket port (default: 3030)',
24
+ ' --port <port> Equivalent to --port=<port>',
25
+ '',
26
+ 'Examples:',
27
+ ' vzcode .',
28
+ ' vzcode ./my-project --port=4000',
29
+ ' vzcode --no-open',
30
+ '',
31
+ 'VZCode listens on 127.0.0.1 only. Do not expose its unauthenticated',
32
+ 'workspace editing server to untrusted networks.',
33
+ ].join('\n');
34
+ function parsePort(value) {
35
+ if (!/^\d+$/.test(value)) {
36
+ throw new Error('Invalid port: ' + value);
27
37
  }
28
- return null;
29
- }
30
- // Function to launch the Tauri app
31
- function launchTauriApp(workingDirectory) {
32
- const tauriBinary = findTauriApp();
33
- if (!tauriBinary) {
34
- console.error('VZCode desktop app not found. Please build it first with: npm run tauri:build');
35
- console.error('Falling back to launching browser version...');
36
- launchBrowserVersion(workingDirectory);
37
- return;
38
+ const port = Number(value);
39
+ if (!Number.isSafeInteger(port) || port > 65535) {
40
+ throw new Error('Port must be between 0 and 65535: ' + value);
38
41
  }
39
- console.log(`Launching VZCode desktop app from: ${workingDirectory}`);
40
- // First start the server in the background
41
- startServerInBackground(workingDirectory);
42
- // Give the server a moment to start, then launch Tauri
43
- setTimeout(() => {
44
- const child = spawn(tauriBinary, [], {
45
- cwd: workingDirectory,
46
- stdio: 'inherit',
47
- detached: true,
48
- });
49
- // Allow the parent process to exit while keeping the child running
50
- child.unref();
51
- }, 2000);
42
+ return port;
52
43
  }
53
- // Function to start the server in the background
54
- function startServerInBackground(workingDirectory) {
55
- // Start the server process in the background
56
- const serverPath = path.join(__dirname, 'server', 'index.js');
57
- const serverChild = spawn('node', [serverPath], {
58
- cwd: workingDirectory,
59
- stdio: ['ignore', 'pipe', 'pipe'],
60
- detached: true,
61
- });
62
- // Don't block on the server process
63
- serverChild.unref();
64
- // Log server output for debugging
65
- if (serverChild.stdout) {
66
- serverChild.stdout.on('data', (data) => {
67
- console.log('Server:', data.toString());
68
- });
69
- }
70
- if (serverChild.stderr) {
71
- serverChild.stderr.on('data', (data) => {
72
- console.error('Server error:', data.toString());
73
- });
44
+ function parseOptions(args) {
45
+ const options = {
46
+ directory: '.',
47
+ port: DEFAULT_PORT,
48
+ openBrowser: true,
49
+ desktop: false,
50
+ help: false,
51
+ };
52
+ let hasDirectory = false;
53
+ for (let i = 0; i < args.length; i++) {
54
+ const arg = args[i];
55
+ if (arg === '--help' || arg === '-h') {
56
+ options.help = true;
57
+ continue;
58
+ }
59
+ if (arg === '--browser') {
60
+ continue;
61
+ }
62
+ if (arg === '--desktop') {
63
+ options.desktop = true;
64
+ continue;
65
+ }
66
+ if (arg === '--no-open') {
67
+ options.openBrowser = false;
68
+ continue;
69
+ }
70
+ if (arg === '--port' || arg.startsWith('--port=')) {
71
+ const value = arg === '--port'
72
+ ? args[++i]
73
+ : arg.slice('--port='.length);
74
+ if (value === undefined) {
75
+ throw new Error('Missing value for --port');
76
+ }
77
+ options.port = parsePort(value);
78
+ continue;
79
+ }
80
+ if (arg.startsWith('-')) {
81
+ throw new Error('Unknown option: ' + arg);
82
+ }
83
+ if (hasDirectory) {
84
+ throw new Error('Provide at most one workspace directory');
85
+ }
86
+ options.directory = arg;
87
+ hasDirectory = true;
74
88
  }
89
+ return options;
75
90
  }
76
- // Fallback function to launch the browser version
77
- async function launchBrowserVersion(workingDirectory) {
78
- // Note: The server/index.js will use process.cwd() automatically
79
- // and we're already in the correct working directory
80
- console.log(`Starting VZCode server from: ${workingDirectory}`);
91
+ // The npm package intentionally does not include a desktop executable.
92
+ // This path is available only after building Tauri in a source checkout.
93
+ function findDesktopApp() {
94
+ const root = path.resolve(__dirname, '..');
95
+ const candidates = [
96
+ 'src-tauri/target/debug/vzcode',
97
+ 'src-tauri/target/debug/vzcode.exe',
98
+ 'src-tauri/target/release/vzcode',
99
+ 'src-tauri/target/release/vzcode.exe',
100
+ 'src-tauri/target/debug/vzcode.app/Contents/MacOS/vzcode',
101
+ 'src-tauri/target/release/vzcode.app/Contents/MacOS/vzcode',
102
+ ];
103
+ return (candidates
104
+ .map((candidate) => path.join(root, candidate))
105
+ .find((candidate) => fs.existsSync(candidate)) ?? null);
81
106
  }
82
- // Main CLI function
83
- function main() {
84
- const workingDirectory = process.cwd();
85
- // Parse command line arguments
86
- const args = process.argv.slice(2);
87
- if (args.includes('--help') || args.includes('-h')) {
88
- console.log('VZCode - Multiplayer Code Editor');
89
- console.log('');
90
- console.log('Usage: vzcode [options]');
91
- console.log('');
92
- console.log('Options:');
93
- console.log(' --help, -h Show this help message');
94
- console.log(' --browser Force browser version instead of desktop app');
95
- console.log(' --port=<port> Specify port for server (default: 3030)');
96
- console.log('');
97
- console.log('Examples:');
98
- console.log(' vzcode # Launch desktop app in current directory');
99
- console.log(' vzcode --browser # Launch browser version');
100
- console.log(' vzcode --port=4000 # Start server on port 4000');
107
+ async function main() {
108
+ const options = parseOptions(process.argv.slice(2));
109
+ if (options.help) {
110
+ console.log(usage);
101
111
  return;
102
112
  }
103
- if (args.includes('--browser')) {
104
- launchBrowserVersion(workingDirectory);
113
+ const directory = path.resolve(options.directory);
114
+ if (!fs.existsSync(directory) ||
115
+ !fs.statSync(directory).isDirectory()) {
116
+ throw new Error('Workspace is not a directory: ' + directory);
117
+ }
118
+ const desktopBinary = options.desktop
119
+ ? findDesktopApp()
120
+ : null;
121
+ if (options.desktop && !desktopBinary) {
122
+ throw new Error('Tauri application not found. Build it with npm run tauri:build, ' +
123
+ 'or omit --desktop to use the browser editor.');
124
+ }
125
+ const server = createVZCodeServer({ cwd: directory });
126
+ await server.ready;
127
+ let actualPort;
128
+ try {
129
+ // Local-only until authenticated remote collaboration exists.
130
+ actualPort = await server.listen(options.port, HOST);
131
+ }
132
+ catch (error) {
133
+ await server.close();
134
+ throw error;
135
+ }
136
+ const url = 'http://' + HOST + ':' + actualPort;
137
+ console.log('Workspace: ' + directory);
138
+ const accessUrl = url + '/#vzcode-token=' + server.accessToken;
139
+ console.log('Editor is live at ' + accessUrl);
140
+ console.log('Keep this private link secret; it grants workspace editing access.');
141
+ console.log('Press Ctrl+C to stop VZCode.');
142
+ let closing = false;
143
+ const shutdown = async () => {
144
+ if (closing)
145
+ return;
146
+ closing = true;
147
+ try {
148
+ await server.close();
149
+ }
150
+ catch (error) {
151
+ console.error('Failed to stop VZCode:', error);
152
+ process.exitCode = 1;
153
+ }
154
+ };
155
+ process.once('SIGINT', () => void shutdown());
156
+ process.once('SIGTERM', () => void shutdown());
157
+ if (desktopBinary) {
158
+ const child = spawn(desktopBinary, [], {
159
+ cwd: directory,
160
+ stdio: 'inherit',
161
+ });
162
+ child.once('error', (error) => {
163
+ console.error('Unable to launch the desktop app:', error);
164
+ process.exitCode = 1;
165
+ void shutdown();
166
+ });
167
+ child.once('exit', () => void shutdown());
105
168
  }
106
- else {
107
- launchTauriApp(workingDirectory);
169
+ else if (options.openBrowser) {
170
+ try {
171
+ await open(accessUrl);
172
+ }
173
+ catch (error) {
174
+ console.warn('Could not open a browser automatically. Visit ' +
175
+ url, error);
176
+ }
108
177
  }
109
178
  }
110
- // Run the CLI
111
- main();
179
+ main().catch((error) => {
180
+ console.error('VZCode: ' + (error.message ?? error));
181
+ process.exitCode = 1;
182
+ });
package/dist/index.html CHANGED
@@ -20,8 +20,9 @@
20
20
  href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap"
21
21
  rel="stylesheet"
22
22
  />
23
- <script type="module" crossorigin src="/assets/index-B7NRhsN6.js"></script>
24
- <link rel="stylesheet" crossorigin href="/assets/index-D1V1AKed.css">
23
+ <script type="module" crossorigin src="/assets/index-COLyIkCc.js"></script>
24
+ <link rel="modulepreload" crossorigin href="/assets/rolldown-runtime-COiEfhsA.js">
25
+ <link rel="stylesheet" crossorigin href="/assets/index-CZT-v4sH.css">
25
26
  </head>
26
27
  <body>
27
28
  <div id="root"></div>
@@ -0,0 +1,104 @@
1
+ import { randomBytes, timingSafeEqual } from 'node:crypto';
2
+ const constantTimeEqual = (a, b) => {
3
+ const left = Buffer.from(a);
4
+ const right = Buffer.from(b);
5
+ return (left.length === right.length &&
6
+ timingSafeEqual(left, right));
7
+ };
8
+ // Deny requests originating from another web origin, including cross-site
9
+ // WebSockets carrying ambient cookies. The explicit token is still required
10
+ // to establish a session.
11
+ export const isSameOrigin = (req) => {
12
+ const origin = req.headers.origin;
13
+ if (!origin)
14
+ return true;
15
+ if (!req.headers.host || typeof origin !== 'string') {
16
+ return false;
17
+ }
18
+ try {
19
+ const parsed = new URL(origin);
20
+ return (parsed.protocol ===
21
+ (req.socket.encrypted
22
+ ? 'https:'
23
+ : 'http:') && parsed.host === req.headers.host);
24
+ }
25
+ catch {
26
+ return false;
27
+ }
28
+ };
29
+ const sessionCookie = (req, name) => {
30
+ const cookieHeader = req.headers.cookie || '';
31
+ const pair = cookieHeader
32
+ .split(';')
33
+ .map((value) => value.trim())
34
+ .find((value) => value.startsWith(name + '='));
35
+ return pair ? pair.slice(name.length + 1) : '';
36
+ };
37
+ export function createAccessControl(accessToken) {
38
+ const token = accessToken ?? randomBytes(32).toString('hex');
39
+ if (token.length < 32) {
40
+ throw new Error('Access token must have at least 32 characters');
41
+ }
42
+ // Cookies are host-scoped, not port-scoped. A random cookie name lets
43
+ // multiple local VZCode instances coexist on different ports.
44
+ const cookieName = 'vzcode_session_' + randomBytes(8).toString('hex');
45
+ const sessions = new Set();
46
+ const hasBearer = (req) => {
47
+ const authorization = req.headers.authorization || '';
48
+ return (authorization.startsWith('Bearer ') &&
49
+ constantTimeEqual(authorization.slice(7), token));
50
+ };
51
+ const authorized = (req) => {
52
+ const session = sessionCookie(req, cookieName);
53
+ return (isSameOrigin(req) &&
54
+ (hasBearer(req) ||
55
+ (session !== '' && sessions.has(session))));
56
+ };
57
+ const install = (app) => {
58
+ app.post('/auth/session', (req, res) => {
59
+ if (!isSameOrigin(req) || !hasBearer(req)) {
60
+ res.sendStatus(401);
61
+ return;
62
+ }
63
+ const session = randomBytes(32).toString('hex');
64
+ sessions.add(session);
65
+ const secure = req.secure ? '; Secure' : '';
66
+ res.setHeader('Set-Cookie', cookieName +
67
+ '=' +
68
+ session +
69
+ '; HttpOnly; SameSite=Strict; Path=/' +
70
+ secure);
71
+ res.sendStatus(204);
72
+ });
73
+ app.get('/auth/status', (req, res) => {
74
+ res.status(authorized(req) ? 200 : 401).json({
75
+ authenticated: authorized(req),
76
+ });
77
+ });
78
+ app.post('/auth/logout', (req, res) => {
79
+ const session = sessionCookie(req, cookieName);
80
+ if (!authorized(req)) {
81
+ res.sendStatus(401);
82
+ return;
83
+ }
84
+ sessions.delete(session);
85
+ res.setHeader('Set-Cookie', cookieName +
86
+ '=; Path=/; HttpOnly; SameSite=Strict; Max-Age=0');
87
+ res.sendStatus(204);
88
+ });
89
+ };
90
+ const requireAuth = (req, res, next) => {
91
+ if (!authorized(req)) {
92
+ res.sendStatus(401);
93
+ return;
94
+ }
95
+ next();
96
+ };
97
+ return {
98
+ token,
99
+ install,
100
+ authorized,
101
+ requireAuth,
102
+ close: () => sessions.clear(),
103
+ };
104
+ }
@@ -81,7 +81,10 @@ export const computeInitialDocument = ({ fullPath }) => {
81
81
  .readdirSync(currentDirectoryPath, {
82
82
  withFileTypes: true,
83
83
  })
84
- .filter((dirent) => enableDirectories ? true : dirent.isFile());
84
+ // Reject symlinks and special files during the initial scan.
85
+ // readFileSync would otherwise follow links outside the root.
86
+ .filter((dirent) => dirent.isFile() ||
87
+ (enableDirectories && dirent.isDirectory()));
85
88
  // find .ignore or .gitignore files in the current directory
86
89
  const ignoreFiles = dirEntries
87
90
  .filter((dirent) => dirent.isFile() && isIgnoreFile(dirent.name))