@spotpatch/vite 1.4.0 → 1.4.1

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.
package/README.md CHANGED
@@ -1,22 +1,42 @@
1
- # @spotpatch/vite
1
+ <p align="center">
2
+ <a href="https://github.com/huanglvjing/spotpatch">
3
+ <img src="https://raw.githubusercontent.com/huanglvjing/spotpatch/main/docs/assets/spotpatch-logo.svg" alt="SpotPatch" width="680" />
4
+ </a>
5
+ </p>
2
6
 
3
- The public Vite entry point for SpotPatch: a development-only React element
4
- picker with source-aware context, bilingual multi-target change requests, and
5
- an optional review-gated AI code Agent.
7
+ <p align="center">
8
+ <a href="#english">English</a> · <a href="#简体中文">简体中文</a>
9
+ </p>
6
10
 
7
- ## Install
11
+ <p align="center">
12
+ <a href="https://www.npmjs.com/package/@spotpatch/vite"><img src="https://img.shields.io/npm/v/%40spotpatch%2Fvite?logo=npm" alt="npm version" /></a>
13
+ <a href="https://www.npmjs.com/package/@spotpatch/vite"><img src="https://img.shields.io/npm/dm/%40spotpatch%2Fvite?logo=npm" alt="npm downloads" /></a>
14
+ <a href="https://github.com/huanglvjing/spotpatch/actions/workflows/ci.yml"><img src="https://github.com/huanglvjing/spotpatch/actions/workflows/ci.yml/badge.svg?branch=main" alt="CI status" /></a>
15
+ <a href="https://github.com/huanglvjing/spotpatch/blob/main/LICENSE"><img src="https://img.shields.io/npm/l/%40spotpatch%2Fvite" alt="MIT license" /></a>
16
+ </p>
17
+
18
+ # `@spotpatch/vite`
19
+
20
+ ## English
21
+
22
+ The supported Vite integration for SpotPatch: select React UI, trace it to JSX/TSX source, collect bounded and sanitized context, write per-target change requests, and either copy a structured prompt or run an optional review-gated AI Agent.
23
+
24
+ SpotPatch runs only with the Vite development server. Production builds contain no SpotPatch Runtime, source markers, or local API endpoints.
25
+
26
+ ### Install
8
27
 
9
28
  ```bash
10
29
  npm install --save-dev @spotpatch/vite
11
- # or: pnpm add -D @spotpatch/vite
30
+ # or
31
+ pnpm add -D @spotpatch/vite
12
32
  ```
13
33
 
14
- ## Configure
34
+ ### Configure
15
35
 
16
- Place SpotPatch before the React plugin so source markers are available to the
17
- development runtime:
36
+ Place SpotPatch before the React plugin so its development source transform runs first.
18
37
 
19
38
  ```ts
39
+ // vite.config.ts
20
40
  import { spotPatch } from "@spotpatch/vite";
21
41
  import react from "@vitejs/plugin-react-swc";
22
42
  import { defineConfig } from "vite";
@@ -26,29 +46,211 @@ export default defineConfig({
26
46
  });
27
47
  ```
28
48
 
29
- SpotPatch injects no runtime, source markers, or local API endpoints into a
30
- production build. AI stays disabled when no AI environment exists. To enable the
31
- single-provider setup without changing `vite.config.ts`, add the three required
32
- values to a Git-ignored `.env.local`:
49
+ Start the application normally:
50
+
51
+ ```bash
52
+ pnpm dev
53
+ ```
54
+
55
+ Select **Select element** in the bottom-right corner or press `Mod+Shift+S`. SpotPatch can collect multiple targets, preserve a separate instruction for each one, open the exact source location in Cursor or VS Code, and generate a structured prompt without requiring AI configuration.
56
+
57
+ ### Compatibility
58
+
59
+ | Dependency | Supported range |
60
+ | -------------------- | ------------------------------ |
61
+ | Node.js | `>=20.19.0` |
62
+ | Vite | `^5.0.0 | | ^6.0.0 | | ^7.0.0` |
63
+ | React public support | `18.2–18.3` |
64
+ | Default source files | `src/**/*.jsx`, `src/**/*.tsx` |
65
+
66
+ React 19 is not part of the Vite v1 public support promise. Next.js projects must not use this package as a substitute for a Next adapter; see the repository's [Next.js status](https://github.com/huanglvjing/spotpatch/blob/main/docs/%E6%8A%80%E6%9C%AF%E6%96%B9%E6%A1%88/Next%E9%80%82%E9%85%8D/00-%E7%B4%A2%E5%BC%95%E4%B8%8E%E6%9E%B6%E6%9E%84%E6%91%98%E8%A6%81.md).
67
+
68
+ ### Options
69
+
70
+ ```ts
71
+ spotPatch({
72
+ enabled: true,
73
+ editor: "auto",
74
+ redact: true,
75
+ shortcut: "Mod+Shift+S",
76
+ allowLan: false,
77
+ debug: false,
78
+ locale: "auto",
79
+ maxTargets: 8,
80
+ ai: false,
81
+ });
82
+ ```
83
+
84
+ | Option | Default | Description |
85
+ | ------------ | ------------------------------------------------- | ----------------------------------------------------------------------- |
86
+ | `enabled` | `true` | Enables the development plugin. |
87
+ | `include` | JSX/TSX under `src` | Files eligible for source marker injection. |
88
+ | `exclude` | dependencies, tests, stories and generated output | Files excluded from transformation. |
89
+ | `editor` | `"auto"` | Auto-detect Cursor or VS Code; either can be fixed explicitly. |
90
+ | `redact` | `true` | Sanitizes collected context; mandatory secret classes remain protected. |
91
+ | `budget` | bounded defaults | Limits total, DOM, CSS and source context sizes. |
92
+ | `shortcut` | `"Mod+Shift+S"` | Toggles element selection. |
93
+ | `allowLan` | `false` | Keeps Host and Origin authorization loopback-only by default. |
94
+ | `debug` | `false` | Enables development diagnostics without logging credentials. |
95
+ | `locale` | `"auto"` | Resolves `en-US` or `zh-CN`. |
96
+ | `maxTargets` | `8` | Targets allowed in one change request by default. |
97
+ | `ai` | disabled or a detected complete environment | Optional provider and Agent settings. |
98
+
99
+ The package exports the option types, AI provider types, Agent limits, and immutable defaults. See the [public API specification](https://github.com/huanglvjing/spotpatch/blob/main/docs/%E6%8A%80%E6%9C%AF%E6%96%B9%E6%A1%88/03-%E5%85%AC%E5%85%B1API%E4%B8%8E%E6%95%B0%E6%8D%AE%E6%A8%A1%E5%9E%8B.md) for the complete constraints.
100
+
101
+ ### Optional AI Agent
102
+
103
+ AI remains disabled unless every required provider value is available. The smallest setup uses a Git-ignored `.env.local` file:
33
104
 
34
105
  ```dotenv
35
106
  SPOTPATCH_AI_BASE_URL=https://relay.example.com/v1
36
107
  SPOTPATCH_AI_MODEL=provider-model-name
37
108
  SPOTPATCH_AI_API_KEY=<your-key>
109
+
110
+ # Optional:
111
+ # SPOTPATCH_AI_PROTOCOL=chat-completions
112
+ # SPOTPATCH_AI_AUTHENTICATION=bearer
38
113
  ```
39
114
 
40
- `SPOTPATCH_AI_PROTOCOL` optionally selects `chat-completions` (the default) or
41
- `responses`. `SPOTPATCH_AI_AUTHENTICATION` optionally selects `bearer` (the
42
- default) or `x-api-key`. Partial environment configuration fails fast without
43
- printing credential values. API keys must never use a `VITE_` prefix.
115
+ Supported protocols are `chat-completions` and `responses`; supported authentication modes are `bearer` and `x-api-key`. Never give the API key a `VITE_` prefix: credentials must stay in the Vite Node process.
44
116
 
45
- Source actions auto-detect Cursor or VS Code and open the selected file at its
46
- exact line and column. Set `editor: "cursor"` or `editor: "vscode"` only when an
47
- explicit preference is required. The workbench also links to the
48
- [SpotPatch GitHub repository](https://github.com/huanglvjing/spotpatch) for docs,
49
- issues, and project updates.
117
+ Non-secret provider values can instead be declared in the plugin configuration:
50
118
 
51
- Non-secret URL and model values can instead use the concise API:
119
+ ```ts
120
+ spotPatch({
121
+ ai: {
122
+ baseURL: "https://relay.example.com/v1",
123
+ model: "provider-model-name",
124
+ },
125
+ });
126
+ ```
127
+
128
+ The default Agent path is review-gated: it probes provider capabilities, works in an isolated Git worktree, exposes bounded file tools rather than an arbitrary shell, runs configured checks, and shows the complete Diff before Apply. SpotPatch does not commit, push, publish, or deploy application code.
129
+
130
+ ### Security and production behavior
131
+
132
+ - Browser requests use a random session token and random file identifiers.
133
+ - Source reads are restricted to registered JSX/TSX files inside the active project root.
134
+ - Sensitive DOM data, credentials, tokens, cookies and authorization values are sanitized.
135
+ - API keys never enter the browser bundle or generated prompt.
136
+ - `allowLan: false` is the default. Enabling LAN access expands the trust boundary and should be deliberate.
137
+ - `vite build` and `vite preview` do not activate the SpotPatch development service.
138
+ - Production leakage tests assert zero Runtime, source markers, endpoints, and internal secrets.
139
+
140
+ ### Troubleshooting
141
+
142
+ - **No selection button:** confirm `spotPatch()` appears before the React plugin and that the app is running through `vite`/`vite dev`, not `vite preview`.
143
+ - **No exact source location:** confirm the component is authored in an included `.jsx` or `.tsx` file under `src`, or configure `include` explicitly.
144
+ - **AI is unavailable:** provide all three required environment values or set `ai: false`; partial environment configuration fails closed.
145
+ - **Editor does not open:** use `editor: "cursor"` or `editor: "vscode"` when terminal auto-detection cannot identify the intended editor.
146
+
147
+ ### Links
148
+
149
+ - [Repository and complete documentation](https://github.com/huanglvjing/spotpatch)
150
+ - [Security model](https://github.com/huanglvjing/spotpatch/blob/main/docs/%E6%8A%80%E6%9C%AF%E6%96%B9%E6%A1%88/09-%E6%9C%AC%E5%9C%B0%E5%8D%8F%E8%AE%AE%E4%B8%8E%E5%AE%89%E5%85%A8.md)
151
+ - [AI execution model](https://github.com/huanglvjing/spotpatch/blob/main/docs/%E6%8A%80%E6%9C%AF%E6%96%B9%E6%A1%88/16-AIAgent%E6%89%A7%E8%A1%8C%E4%B8%8E%E5%8F%98%E6%9B%B4%E5%AE%A1%E9%98%85.md)
152
+ - [Issues](https://github.com/huanglvjing/spotpatch/issues)
153
+
154
+ ---
155
+
156
+ ## 简体中文
157
+
158
+ `@spotpatch/vite` 是 SpotPatch 当前正式支持的 Vite 接入包:在 React 页面中选择元素,定位到 JSX/TSX 源码,采集经过预算约束与脱敏的上下文,为每个目标分别编写要求,然后复制结构化 Prompt,或运行默认需要审阅的可选 AI Agent。
159
+
160
+ SpotPatch 只在 Vite 开发服务器中运行。生产构建不包含 SpotPatch Runtime、源码标记或本地 API 端点。
161
+
162
+ ### 安装
163
+
164
+ ```bash
165
+ npm install --save-dev @spotpatch/vite
166
+ # 或
167
+ pnpm add -D @spotpatch/vite
168
+ ```
169
+
170
+ ### 配置
171
+
172
+ SpotPatch 必须放在 React 插件之前,让开发期源码转换先执行。
173
+
174
+ ```ts
175
+ // vite.config.ts
176
+ import { spotPatch } from "@spotpatch/vite";
177
+ import react from "@vitejs/plugin-react-swc";
178
+ import { defineConfig } from "vite";
179
+
180
+ export default defineConfig({
181
+ plugins: [spotPatch(), react()],
182
+ });
183
+ ```
184
+
185
+ 照常启动应用:
186
+
187
+ ```bash
188
+ pnpm dev
189
+ ```
190
+
191
+ 点击右下角的 **选择元素** 或按下 `Mod+Shift+S`。SpotPatch 支持一次采集多个目标、为每个目标保留独立修改要求、在 Cursor 或 VS Code 中打开精确位置,并且在完全不配置 AI 的情况下生成结构化 Prompt。
192
+
193
+ ### 兼容范围
194
+
195
+ | 依赖 | 正式支持范围 |
196
+ | -------------- | ------------------------------ |
197
+ | Node.js | `>=20.19.0` |
198
+ | Vite | `^5.0.0 | | ^6.0.0 | | ^7.0.0` |
199
+ | React 正式支持 | `18.2–18.3` |
200
+ | 默认源码文件 | `src/**/*.jsx`、`src/**/*.tsx` |
201
+
202
+ React 19 不在 Vite v1 正式承诺内。Next.js 项目不能把本包当作 Next 适配器使用;准确状态见仓库中的 [Next.js 适配说明](https://github.com/huanglvjing/spotpatch/blob/main/docs/%E6%8A%80%E6%9C%AF%E6%96%B9%E6%A1%88/Next%E9%80%82%E9%85%8D/00-%E7%B4%A2%E5%BC%95%E4%B8%8E%E6%9E%B6%E6%9E%84%E6%91%98%E8%A6%81.md)。
203
+
204
+ ### 选项
205
+
206
+ ```ts
207
+ spotPatch({
208
+ enabled: true,
209
+ editor: "auto",
210
+ redact: true,
211
+ shortcut: "Mod+Shift+S",
212
+ allowLan: false,
213
+ debug: false,
214
+ locale: "auto",
215
+ maxTargets: 8,
216
+ ai: false,
217
+ });
218
+ ```
219
+
220
+ | 选项 | 默认值 | 说明 |
221
+ | ------------ | ---------------------------- | ---------------------------------------------------- |
222
+ | `enabled` | `true` | 启用开发期插件。 |
223
+ | `include` | `src` 下 JSX/TSX | 允许注入源码标记的文件。 |
224
+ | `exclude` | 依赖、测试、Story 与生成目录 | 不进行转换的文件。 |
225
+ | `editor` | `"auto"` | 自动识别 Cursor 或 VS Code,也可显式固定。 |
226
+ | `redact` | `true` | 清洗采集上下文;强制保护的秘密类型不会因关闭而暴露。 |
227
+ | `budget` | 有界默认值 | 限制总量、DOM、CSS 和源码上下文大小。 |
228
+ | `shortcut` | `"Mod+Shift+S"` | 切换元素选择器。 |
229
+ | `allowLan` | `false` | 默认只允许 loopback Host 与 Origin。 |
230
+ | `debug` | `false` | 输出不包含凭据的开发诊断。 |
231
+ | `locale` | `"auto"` | 自动解析 `en-US` 或 `zh-CN`。 |
232
+ | `maxTargets` | `8` | 一次修改任务默认允许的目标数。 |
233
+ | `ai` | 关闭或检测到完整环境配置 | 可选 Provider 和 Agent 配置。 |
234
+
235
+ 本包导出选项类型、AI Provider 类型、Agent 限制和不可变默认值。完整约束见[公共 API 规范](https://github.com/huanglvjing/spotpatch/blob/main/docs/%E6%8A%80%E6%9C%AF%E6%96%B9%E6%A1%88/03-%E5%85%AC%E5%85%B1API%E4%B8%8E%E6%95%B0%E6%8D%AE%E6%A8%A1%E5%9E%8B.md)。
236
+
237
+ ### 可选 AI Agent
238
+
239
+ 只有全部必需 Provider 值可用时 AI 才会启用。最小配置放在 Git 忽略的 `.env.local` 中:
240
+
241
+ ```dotenv
242
+ SPOTPATCH_AI_BASE_URL=https://relay.example.com/v1
243
+ SPOTPATCH_AI_MODEL=provider-model-name
244
+ SPOTPATCH_AI_API_KEY=<your-key>
245
+
246
+ # 可选:
247
+ # SPOTPATCH_AI_PROTOCOL=chat-completions
248
+ # SPOTPATCH_AI_AUTHENTICATION=bearer
249
+ ```
250
+
251
+ 协议支持 `chat-completions` 与 `responses`,认证支持 `bearer` 与 `x-api-key`。API Key 绝不能使用 `VITE_` 前缀,凭据必须只保留在 Vite Node 进程中。
252
+
253
+ 非秘密的 Provider 信息也可以写入插件配置:
52
254
 
53
255
  ```ts
54
256
  spotPatch({
@@ -59,20 +261,32 @@ spotPatch({
59
261
  });
60
262
  ```
61
263
 
62
- The full provider map remains available for multiple providers, multiple models,
63
- custom labels, checks, and limits.
264
+ 默认 Agent 路径必须经过审阅:先探测 Provider 能力,在隔离 Git worktree 中工作,只暴露有界文件工具而不是任意 Shell,执行已配置检查,并在 Apply 前展示完整 Diff。SpotPatch 不会替业务代码执行 commit、push、发包或部署。
265
+
266
+ ### 安全与生产行为
267
+
268
+ - 浏览器请求使用随机会话令牌和随机文件标识。
269
+ - 源码读取只允许命中活动项目 root 内、当前会话登记的 JSX/TSX 文件。
270
+ - 敏感 DOM 数据、凭据、Token、Cookie 与 Authorization 会被清洗。
271
+ - API Key 不会进入浏览器 bundle 或生成的 Prompt。
272
+ - `allowLan: false` 是默认值;启用 LAN 会扩大信任边界,必须明确评估。
273
+ - `vite build` 与 `vite preview` 不会启动 SpotPatch 开发服务。
274
+ - 生产泄漏测试验证 Runtime、源码标记、端点和内部秘密零残留。
275
+
276
+ ### 常见问题
277
+
278
+ - **没有选择元素按钮:**确认 `spotPatch()` 位于 React 插件之前,并且应用通过 `vite`/`vite dev` 而不是 `vite preview` 启动。
279
+ - **没有精确源码位置:**确认组件来自 include 范围内的 `.jsx` 或 `.tsx` 文件,默认范围是 `src`。
280
+ - **AI 不可用:**提供全部三个必需环境变量,或者显式设置 `ai: false`;不完整配置会安全失败。
281
+ - **编辑器没有打开:**终端自动识别无法确定目标时,显式设置 `editor: "cursor"` 或 `editor: "vscode"`。
282
+
283
+ ### 链接
64
284
 
65
- AI runs directly when the Git workspace is clean. If staged, unstaged, or
66
- bounded regular untracked files exist, the workbench reports their counts and
67
- requires explicit consent before copying them into an isolated Agent baseline.
68
- SpotPatch never stashes, resets, commits, or changes the source index, and Apply
69
- or Revert touches only the Agent delta. Conflicts and unsupported workspace
70
- states remain blocked with an actionable reason.
285
+ - [仓库与完整文档](https://github.com/huanglvjing/spotpatch)
286
+ - [安全模型](https://github.com/huanglvjing/spotpatch/blob/main/docs/%E6%8A%80%E6%9C%AF%E6%96%B9%E6%A1%88/09-%E6%9C%AC%E5%9C%B0%E5%8D%8F%E8%AE%AE%E4%B8%8E%E5%AE%89%E5%85%A8.md)
287
+ - [AI 执行模型](https://github.com/huanglvjing/spotpatch/blob/main/docs/%E6%8A%80%E6%9C%AF%E6%96%B9%E6%A1%88/16-AIAgent%E6%89%A7%E8%A1%8C%E4%B8%8E%E5%8F%98%E6%9B%B4%E5%AE%A1%E9%98%85.md)
288
+ - [问题反馈](https://github.com/huanglvjing/spotpatch/issues)
71
289
 
72
- OpenAI-compatible relays may reuse a provider tool call ID in a later model
73
- turn. SpotPatch scopes idempotency to the model turn, while conflicting IDs in
74
- the same turn still fail without source-side effects. Invalid tool arguments
75
- and same-turn ID conflicts are reported separately.
290
+ ### License / 许可证
76
291
 
77
- See the [repository README](https://github.com/huanglvjing/spotpatch#readme) for
78
- the complete setup and security model.
292
+ [MIT](https://github.com/huanglvjing/spotpatch/blob/main/LICENSE) © SpotPatch contributors.