vzcode 3.1.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 (74) 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/CodeEditor/style.scss +18 -11
  25. package/src/client/RunCodeWidget/index.tsx +1 -0
  26. package/src/client/TabList/Tab.tsx +13 -5
  27. package/src/client/TabList/style.scss +32 -5
  28. package/src/client/VZCodeContext/types.ts +6 -0
  29. package/src/client/VZCodeContext/useVZCodeState.ts +2 -0
  30. package/src/client/VZResizer/styles.scss +1 -1
  31. package/src/client/VZSidebar/AIChatWrapper.tsx +2 -0
  32. package/src/client/VZSidebar/DeleteConfirmationModal.tsx +1 -1
  33. package/src/client/VZSidebar/Item.tsx +8 -4
  34. package/src/client/VZSidebar/VisualEditor/CheckboxWidget.tsx +22 -30
  35. package/src/client/VZSidebar/VisualEditor/ColorWidget.tsx +198 -126
  36. package/src/client/VZSidebar/VisualEditor/DropdownWidget.tsx +25 -67
  37. package/src/client/VZSidebar/VisualEditor/PropertySection.tsx +41 -0
  38. package/src/client/VZSidebar/VisualEditor/SegmentedWidget.tsx +34 -0
  39. package/src/client/VZSidebar/VisualEditor/SliderWidget.tsx +60 -12
  40. package/src/client/VZSidebar/VisualEditor/VisualEditor.tsx +31 -393
  41. package/src/client/VZSidebar/VisualEditor/VisualEditorControls.tsx +478 -0
  42. package/src/client/VZSidebar/VisualEditor/colorUtils.ts +12 -0
  43. package/src/client/VZSidebar/VisualEditor/status.ts +47 -0
  44. package/src/client/VZSidebar/VisualEditor/updateConfig.ts +51 -24
  45. package/src/client/VZSidebar/VisualEditor/utils.ts +1 -1
  46. package/src/client/VZSidebar/index.tsx +55 -23
  47. package/src/client/VZSidebar/styles.scss +426 -6
  48. package/src/client/WorkspaceConflictBanner.tsx +120 -0
  49. package/src/client/index.ts +2 -0
  50. package/src/client/main.jsx +54 -12
  51. package/src/client/ui.scss +156 -4
  52. package/src/client/ui.tsx +1 -1
  53. package/src/llm-streaming-server/README.md +4 -16
  54. package/src/llm-streaming-ui/README.md +41 -2
  55. package/src/llm-streaming-ui/components/ChatInput.tsx +65 -13
  56. package/src/llm-streaming-ui/components/index.tsx +2 -0
  57. package/src/llm-streaming-ui/components/styles.scss +46 -0
  58. package/src/llm-streaming-ui/hooks/useAutoScroll.ts +1 -1
  59. package/src/llm-streaming-ui/index.ts +1 -0
  60. package/src/llm-streaming-ui/props.ts +26 -2
  61. package/src/server/accessControl.ts +151 -0
  62. package/src/server/computeInitialDocument.ts +6 -2
  63. package/src/server/createServer.ts +487 -138
  64. package/src/server/index.ts +4 -5
  65. package/src/server/workspaceSecurity.ts +160 -0
  66. package/src/server/workspaceSync.ts +203 -0
  67. package/src/types.ts +29 -27
  68. package/dist/assets/bindings_wasm_bg-9w8E-TmY.wasm +0 -0
  69. package/dist/assets/buildWorker-BZlya278.js +0 -687
  70. package/dist/assets/index-5qf102c2.css +0 -1
  71. package/dist/assets/index-dSJDl5x9.js +0 -356
  72. package/dist/assets/worker-1oQYaz-F.js +0 -342
  73. package/dist/assets/worker-BfgPD8zR.js +0 -125
  74. package/dist/assets/worker-CoJaqtpi.js +0 -436
@@ -891,3 +891,49 @@
891
891
  outline-offset: 2px;
892
892
  }
893
893
  }
894
+
895
+ /* Match AI Studio action/focus treatments without changing the dark chat surface. */
896
+ .ai-chat-mode-toggle .vz-chat-button-group .vz-chat-button,
897
+ .ai-chat-input-group .ai-chat-send-button {
898
+ border-radius: 6px;
899
+ transition:
900
+ background-color 0.15s ease,
901
+ border-color 0.15s ease,
902
+ color 0.15s ease;
903
+ }
904
+ .ai-chat-mode-toggle
905
+ .vz-chat-button-group
906
+ .vz-chat-button:focus-visible,
907
+ .ai-chat-input-group .ai-chat-send-button:focus-visible,
908
+ .jump-to-latest-button:focus-visible {
909
+ outline: 2px solid var(--vz-color-primary-01);
910
+ outline-offset: 2px;
911
+ }
912
+ .ai-chat-mode-toggle
913
+ .vz-chat-button-group
914
+ .vz-chat-button:disabled,
915
+ .ai-chat-input-group .ai-chat-send-button:disabled {
916
+ opacity: 0.5;
917
+ }
918
+ .ai-chat-input-group textarea:focus {
919
+ border-color: var(--vz-color-primary-01) !important;
920
+ box-shadow: 0 0 0 2px rgba(3, 102, 214, 0.3) !important;
921
+ }
922
+ .jump-to-latest-button {
923
+ transition:
924
+ background-color 0.15s ease,
925
+ box-shadow 0.15s ease;
926
+ }
927
+ .jump-to-latest-button:hover,
928
+ .jump-to-latest-button:active {
929
+ transform: translateX(-50%);
930
+ }
931
+ @media (prefers-reduced-motion: reduce) {
932
+ .ai-chat-mode-toggle
933
+ .vz-chat-button-group
934
+ .vz-chat-button,
935
+ .ai-chat-input-group .ai-chat-send-button,
936
+ .jump-to-latest-button {
937
+ transition: none;
938
+ }
939
+ }
@@ -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