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
@@ -99,7 +99,46 @@ See `AIChatProps` in `props.ts` for the full contract.
99
99
  - Add or update tests when changing behavior
100
100
  - Document new props and side effects
101
101
 
102
+ ## Host-owned microphone integration
103
+
104
+ A host can pass `renderChatVoiceInput` to `VZCodeProvider`. VZCode renders its
105
+ returned element in the chat composer footer, immediately before Send. The host
106
+ owns the microphone implementation, recording state, speech-to-text, any cleanup,
107
+ and cancellation. VZCode never starts its built-in speech-recognition engine
108
+ from the host control; `enableVoiceInput` remains a separate legacy option.
109
+
110
+ ```tsx
111
+ <VZCodeProvider
112
+ // ...other provider props
113
+ renderChatVoiceInput={({
114
+ value,
115
+ onChange,
116
+ onBusyChange,
117
+ onPreviewChange,
118
+ }) => (
119
+ <MyAppVoiceButton
120
+ value={value}
121
+ onCommitDraft={onChange}
122
+ onBusyChange={onBusyChange}
123
+ onPreviewChange={onPreviewChange}
124
+ />
125
+ )}
126
+ />
127
+ ```
128
+
129
+ The renderer must return a component rather than directly calling hooks. Its
130
+ `value` is the **complete committed draft**. Call `onChange(nextFullDraft)`
131
+ only when dictation has finished; this must never submit the chat message.
132
+ Call `onPreviewChange(fullDraftPreview)` to display optional interim text,
133
+ and `onPreviewChange(null)` to clear it. Call `onBusyChange(true)` before
134
+ starting microphone work, including permission and transcript processing; while
135
+ busy, VZCode makes its textarea read-only and blocks Send and Enter. Always
136
+ call `onBusyChange(false)` on completion, cancellation, errors, and teardown.
137
+ Without a renderer, the existing chat composer behavior is preserved.
138
+
102
139
  ## Theming
103
140
 
104
- The components currently use VZCode's theming system via SCSS variables.
105
- Future versions will provide CSS custom properties and theme presets.
141
+ The components use scoped CSS custom properties with VZCode defaults, so they
142
+ can render without a host UI framework. When embedding them, hosts can override
143
+ the `--vz-color-*` properties on the chat container. The styles do not inject
144
+ Bootstrap or VizHub UI CSS.
@@ -2,6 +2,7 @@ import {
2
2
  useRef,
3
3
  useEffect,
4
4
  useCallback,
5
+ useState,
5
6
  memo,
6
7
  } from 'react';
7
8
  import { useSpeechRecognition } from './useSpeechRecognition';
@@ -57,8 +58,42 @@ const ChatInputComponent = ({
57
58
  resetMessageHistoryNavigation,
58
59
  enableAskMode = false,
59
60
  enableVoiceInput = false,
61
+ renderChatVoiceInput,
60
62
  }: ChatInputProps) => {
61
63
  const inputRef = useRef<HTMLTextAreaElement>(null);
64
+ const [hostVoiceBusy, setHostVoiceBusy] = useState(false);
65
+ const [hostVoicePreview, setHostVoicePreview] = useState<
66
+ string | null
67
+ >(null);
68
+ const isHostVoiceBusy =
69
+ !!renderChatVoiceInput && hostVoiceBusy;
70
+ const canSend =
71
+ !isHostVoiceBusy && !!aiChatMessage.trim();
72
+ const displayValue =
73
+ isHostVoiceBusy && hostVoicePreview !== null
74
+ ? hostVoicePreview
75
+ : aiChatMessage;
76
+
77
+ const handleHostDraftChange = useCallback(
78
+ (value: string) => {
79
+ setAIChatMessage(value);
80
+ resetMessageHistoryNavigation();
81
+ },
82
+ [setAIChatMessage, resetMessageHistoryNavigation],
83
+ );
84
+ const handleHostBusyChange = useCallback(
85
+ (busy: boolean) => {
86
+ setHostVoiceBusy(busy);
87
+ if (!busy) setHostVoicePreview(null);
88
+ },
89
+ [],
90
+ );
91
+ const handleHostPreviewChange = useCallback(
92
+ (preview: string | null) => {
93
+ setHostVoicePreview(preview);
94
+ },
95
+ [],
96
+ );
62
97
 
63
98
  // Speech recognition is created lazily on first toggle, so simply
64
99
  // mounting this hook does not touch any browser media APIs.
@@ -79,7 +114,7 @@ const ChatInputComponent = ({
79
114
  (event: React.KeyboardEvent) => {
80
115
  if (event.key === 'Enter' && !event.shiftKey) {
81
116
  event.preventDefault();
82
- onSendMessage();
117
+ if (canSend) onSendMessage();
83
118
  } else if (event.key === 'Enter' && event.shiftKey) {
84
119
  // Shift+Enter should add a newline, not trigger run code
85
120
  // We prevent the event from bubbling up to the global keyboard handler
@@ -119,26 +154,33 @@ const ChatInputComponent = ({
119
154
  },
120
155
  [
121
156
  onSendMessage,
157
+ canSend,
122
158
  navigateMessageHistoryUp,
123
159
  navigateMessageHistoryDown,
124
160
  ],
125
161
  );
126
162
 
127
163
  const handleSendClick = useCallback(() => {
164
+ if (!canSend) return;
128
165
  // If speech recognition is active, stop it
129
166
  if (isSpeaking) {
130
167
  stopSpeaking();
131
168
  }
132
169
  onSendMessage();
133
- }, [onSendMessage, isSpeaking, stopSpeaking]);
170
+ }, [onSendMessage, isSpeaking, stopSpeaking, canSend]);
134
171
 
135
172
  const handleChange = useCallback(
136
173
  (event: React.ChangeEvent<HTMLTextAreaElement>) => {
174
+ if (isHostVoiceBusy) return;
137
175
  setAIChatMessage(event.target.value);
138
176
  // Reset history navigation when user starts typing
139
177
  resetMessageHistoryNavigation();
140
178
  },
141
- [setAIChatMessage, resetMessageHistoryNavigation],
179
+ [
180
+ setAIChatMessage,
181
+ resetMessageHistoryNavigation,
182
+ isHostVoiceBusy,
183
+ ],
142
184
  );
143
185
 
144
186
  return (
@@ -178,7 +220,8 @@ const ChatInputComponent = ({
178
220
  <div className="ai-chat-input-group">
179
221
  <textarea
180
222
  rows={10}
181
- value={aiChatMessage}
223
+ value={displayValue}
224
+ readOnly={isHostVoiceBusy}
182
225
  onChange={handleChange}
183
226
  onKeyDown={handleKeyDown}
184
227
  ref={inputRef}
@@ -192,20 +235,29 @@ const ChatInputComponent = ({
192
235
  />
193
236
  <div className="ai-chat-input-footer">
194
237
  <span className="ai-chat-hint">
195
- {aiChatMessage ? 'Press Enter to send' : ''}
238
+ {aiChatMessage && !isHostVoiceBusy
239
+ ? 'Press Enter to send'
240
+ : ''}
196
241
  </span>
197
242
  <div style={{ display: 'flex', gap: '8px' }}>
198
- {enableVoiceInput && (
199
- <VoiceInputButton
200
- isSpeaking={isSpeaking}
201
- onToggle={toggleSpeechRecognition}
202
- />
203
- )}
243
+ {renderChatVoiceInput
244
+ ? renderChatVoiceInput({
245
+ value: aiChatMessage,
246
+ onChange: handleHostDraftChange,
247
+ onBusyChange: handleHostBusyChange,
248
+ onPreviewChange: handleHostPreviewChange,
249
+ })
250
+ : enableVoiceInput && (
251
+ <VoiceInputButton
252
+ isSpeaking={isSpeaking}
253
+ onToggle={toggleSpeechRecognition}
254
+ />
255
+ )}
204
256
  <button
205
257
  type="button"
206
258
  onClick={handleSendClick}
207
- disabled={!aiChatMessage.trim()}
208
- className={`ai-chat-send-button vz-chat-button ${aiChatMessage.trim() ? 'vz-chat-button--primary' : 'vz-chat-button--outline-secondary'}`}
259
+ disabled={!canSend}
260
+ className={`ai-chat-send-button vz-chat-button ${canSend ? 'vz-chat-button--primary' : 'vz-chat-button--outline-secondary'}`}
209
261
  aria-label="Send message"
210
262
  title="Send message (Enter)"
211
263
  >
@@ -64,6 +64,7 @@ export const AIChat = ({
64
64
  enableDiffView = true,
65
65
  enableAskMode = false,
66
66
  enableVoiceInput = false,
67
+ renderChatVoiceInput,
67
68
  onOpenFile,
68
69
  }: AIChatProps) => {
69
70
  // Use the new simplified auto-scroll hook
@@ -376,6 +377,7 @@ export const AIChat = ({
376
377
  setAIChatMode={setAIChatMode}
377
378
  enableAskMode={enableAskMode}
378
379
  enableVoiceInput={enableVoiceInput}
380
+ renderChatVoiceInput={renderChatVoiceInput}
379
381
  navigateMessageHistoryUp={
380
382
  navigateMessageHistoryUp
381
383
  }
@@ -108,7 +108,7 @@ export const useAutoScroll = (
108
108
  useState<AutoScrollState>('AUTO_SCROLL_ON');
109
109
  const [showJumpButton, setShowJumpButton] =
110
110
  useState(false);
111
- const rafIdRef = useRef<number>();
111
+ const rafIdRef = useRef<number | undefined>(undefined);
112
112
  const isProgrammaticScrollRef = useRef(false);
113
113
 
114
114
  /**
@@ -39,6 +39,7 @@ export type {
39
39
  AIChatProps,
40
40
  AIChatMode,
41
41
  AdditionalWidgets,
42
+ ChatVoiceInputRenderer,
42
43
  ChatInputProps,
43
44
  DiffViewProps,
44
45
  HandleSendMessage,
@@ -26,6 +26,26 @@ export type AdditionalWidgets = (props: {
26
26
  handleSendMessage?: HandleSendMessage;
27
27
  }) => ReactNode;
28
28
 
29
+ /**
30
+ * Optional host-owned control rendered beside Send in the chat composer.
31
+ *
32
+ * The host owns recording, permissions, transcript cleanup, and teardown.
33
+ * VZCode only owns its draft string and submission buttons.
34
+ *
35
+ * Return a React element containing the host component; do not call React
36
+ * hooks directly from this renderer callback.
37
+ */
38
+ export type ChatVoiceInputRenderer = (props: {
39
+ /** Current committed chat draft. */
40
+ value: string;
41
+ /** Commit a new full draft (not just the dictated fragment). */
42
+ onChange: (nextValue: string) => void;
43
+ /** Set true during permission, recording, or transcript processing. */
44
+ onBusyChange: (busy: boolean) => void;
45
+ /** Optional transient transcript preview; null clears it. */
46
+ onPreviewChange: (preview: string | null) => void;
47
+ }) => ReactNode;
48
+
29
49
  /**
30
50
  * Props for the main `AIChat` component.
31
51
  *
@@ -69,8 +89,10 @@ export interface AIChatProps {
69
89
  enableDiffView?: boolean;
70
90
  /** Show the ask/edit mode toggle in the input. */
71
91
  enableAskMode?: boolean;
72
- /** Show the voice input microphone button. */
92
+ /** Show VZCode's legacy voice input button when no host renderer exists. */
73
93
  enableVoiceInput?: boolean;
94
+ /** Optional host-owned voice control; takes precedence over enableVoiceInput. */
95
+ renderChatVoiceInput?: ChatVoiceInputRenderer;
74
96
  /** Whether the minimal AI edit flow is enabled. */
75
97
  enableMinimalEditFlow?: boolean;
76
98
  }
@@ -88,8 +110,10 @@ export interface ChatInputProps {
88
110
  resetMessageHistoryNavigation: () => void;
89
111
  /** Show the ask/edit mode toggle. */
90
112
  enableAskMode?: boolean;
91
- /** Show the voice input microphone button. */
113
+ /** Show VZCode's legacy voice input button when no host renderer exists. */
92
114
  enableVoiceInput?: boolean;
115
+ /** Optional host-owned voice control; takes precedence over enableVoiceInput. */
116
+ renderChatVoiceInput?: ChatVoiceInputRenderer;
93
117
  }
94
118
 
95
119
  /** Props for the unified diff view. */
@@ -0,0 +1,151 @@
1
+ import { randomBytes, timingSafeEqual } from 'node:crypto';
2
+ import type { IncomingMessage } from 'node:http';
3
+ import type { Express, Request, Response } from 'express';
4
+
5
+ const constantTimeEqual = (
6
+ a: string,
7
+ b: string,
8
+ ): boolean => {
9
+ const left = Buffer.from(a);
10
+ const right = Buffer.from(b);
11
+ return (
12
+ left.length === right.length &&
13
+ timingSafeEqual(left, right)
14
+ );
15
+ };
16
+
17
+ // Deny requests originating from another web origin, including cross-site
18
+ // WebSockets carrying ambient cookies. The explicit token is still required
19
+ // to establish a session.
20
+ export const isSameOrigin = (req: IncomingMessage) => {
21
+ const origin = req.headers.origin;
22
+ if (!origin) return true;
23
+ if (!req.headers.host || typeof origin !== 'string') {
24
+ return false;
25
+ }
26
+ try {
27
+ const parsed = new URL(origin);
28
+ return (
29
+ parsed.protocol ===
30
+ ((req.socket as any).encrypted
31
+ ? 'https:'
32
+ : 'http:') && parsed.host === req.headers.host
33
+ );
34
+ } catch {
35
+ return false;
36
+ }
37
+ };
38
+
39
+ const sessionCookie = (
40
+ req: IncomingMessage,
41
+ name: string,
42
+ ): string => {
43
+ const cookieHeader = req.headers.cookie || '';
44
+ const pair = cookieHeader
45
+ .split(';')
46
+ .map((value) => value.trim())
47
+ .find((value) => value.startsWith(name + '='));
48
+ return pair ? pair.slice(name.length + 1) : '';
49
+ };
50
+
51
+ export function createAccessControl(accessToken?: string) {
52
+ const token =
53
+ accessToken ?? randomBytes(32).toString('hex');
54
+ if (token.length < 32) {
55
+ throw new Error(
56
+ 'Access token must have at least 32 characters',
57
+ );
58
+ }
59
+ // Cookies are host-scoped, not port-scoped. A random cookie name lets
60
+ // multiple local VZCode instances coexist on different ports.
61
+ const cookieName =
62
+ 'vzcode_session_' + randomBytes(8).toString('hex');
63
+ const sessions = new Set<string>();
64
+
65
+ const hasBearer = (req: IncomingMessage) => {
66
+ const authorization = req.headers.authorization || '';
67
+ return (
68
+ authorization.startsWith('Bearer ') &&
69
+ constantTimeEqual(authorization.slice(7), token)
70
+ );
71
+ };
72
+ const authorized = (req: IncomingMessage) => {
73
+ const session = sessionCookie(req, cookieName);
74
+ return (
75
+ isSameOrigin(req) &&
76
+ (hasBearer(req) ||
77
+ (session !== '' && sessions.has(session)))
78
+ );
79
+ };
80
+
81
+ const install = (app: Express) => {
82
+ app.post(
83
+ '/auth/session',
84
+ (req: Request, res: Response) => {
85
+ if (!isSameOrigin(req) || !hasBearer(req)) {
86
+ res.sendStatus(401);
87
+ return;
88
+ }
89
+ const session = randomBytes(32).toString('hex');
90
+ sessions.add(session);
91
+ const secure = req.secure ? '; Secure' : '';
92
+ res.setHeader(
93
+ 'Set-Cookie',
94
+ cookieName +
95
+ '=' +
96
+ session +
97
+ '; HttpOnly; SameSite=Strict; Path=/' +
98
+ secure,
99
+ );
100
+ res.sendStatus(204);
101
+ },
102
+ );
103
+
104
+ app.get(
105
+ '/auth/status',
106
+ (req: Request, res: Response) => {
107
+ res.status(authorized(req) ? 200 : 401).json({
108
+ authenticated: authorized(req),
109
+ });
110
+ },
111
+ );
112
+
113
+ app.post(
114
+ '/auth/logout',
115
+ (req: Request, res: Response) => {
116
+ const session = sessionCookie(req, cookieName);
117
+ if (!authorized(req)) {
118
+ res.sendStatus(401);
119
+ return;
120
+ }
121
+ sessions.delete(session);
122
+ res.setHeader(
123
+ 'Set-Cookie',
124
+ cookieName +
125
+ '=; Path=/; HttpOnly; SameSite=Strict; Max-Age=0',
126
+ );
127
+ res.sendStatus(204);
128
+ },
129
+ );
130
+ };
131
+
132
+ const requireAuth = (
133
+ req: Request,
134
+ res: Response,
135
+ next: () => void,
136
+ ) => {
137
+ if (!authorized(req)) {
138
+ res.sendStatus(401);
139
+ return;
140
+ }
141
+ next();
142
+ };
143
+
144
+ return {
145
+ token,
146
+ install,
147
+ authorized,
148
+ requireAuth,
149
+ close: () => sessions.clear(),
150
+ };
151
+ }
@@ -129,8 +129,12 @@ export const computeInitialDocument = ({ fullPath }) => {
129
129
  .readdirSync(currentDirectoryPath, {
130
130
  withFileTypes: true,
131
131
  })
132
- .filter((dirent) =>
133
- enableDirectories ? true : dirent.isFile(),
132
+ // Reject symlinks and special files during the initial scan.
133
+ // readFileSync would otherwise follow links outside the root.
134
+ .filter(
135
+ (dirent) =>
136
+ dirent.isFile() ||
137
+ (enableDirectories && dirent.isDirectory()),
134
138
  );
135
139
  // find .ignore or .gitignore files in the current directory
136
140
  const ignoreFiles = dirEntries