@spotpatch/vite 1.4.0 → 1.4.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.
- package/README.md +245 -37
- package/dist/index.cjs +101 -2208
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -65
- package/dist/index.d.ts +5 -65
- package/dist/index.js +104 -2239
- package/dist/index.js.map +1 -1
- package/dist/runtime-client.js +32 -30
- package/package.json +6 -10
package/README.md
CHANGED
|
@@ -1,22 +1,36 @@
|
|
|
1
|
-
|
|
1
|
+
<h1><a href="https://github.com/huanglvjing/spotpatch"><img src="https://raw.githubusercontent.com/huanglvjing/spotpatch/main/docs/assets/spotpatch-npm-icon.png" alt="SpotPatch" width="48" height="48" align="absmiddle" /></a> <code>@spotpatch/vite</code></h1>
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
<p align="center">
|
|
4
|
+
<a href="#english">English</a> · <a href="#简体中文">简体中文</a>
|
|
5
|
+
</p>
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
<p align="center">
|
|
8
|
+
<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>
|
|
9
|
+
<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>
|
|
10
|
+
<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>
|
|
11
|
+
<a href="https://github.com/huanglvjing/spotpatch/blob/main/LICENSE"><img src="https://img.shields.io/npm/l/%40spotpatch%2Fvite" alt="MIT license" /></a>
|
|
12
|
+
</p>
|
|
13
|
+
|
|
14
|
+
## English
|
|
15
|
+
|
|
16
|
+
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.
|
|
17
|
+
|
|
18
|
+
SpotPatch runs only with the Vite development server. Production builds contain no SpotPatch Runtime, source markers, or local API endpoints.
|
|
19
|
+
|
|
20
|
+
### Install
|
|
8
21
|
|
|
9
22
|
```bash
|
|
10
23
|
npm install --save-dev @spotpatch/vite
|
|
11
|
-
# or
|
|
24
|
+
# or
|
|
25
|
+
pnpm add -D @spotpatch/vite
|
|
12
26
|
```
|
|
13
27
|
|
|
14
|
-
|
|
28
|
+
### Configure
|
|
15
29
|
|
|
16
|
-
Place SpotPatch before the React plugin so
|
|
17
|
-
development runtime:
|
|
30
|
+
Place SpotPatch before the React plugin so its development source transform runs first.
|
|
18
31
|
|
|
19
32
|
```ts
|
|
33
|
+
// vite.config.ts
|
|
20
34
|
import { spotPatch } from "@spotpatch/vite";
|
|
21
35
|
import react from "@vitejs/plugin-react-swc";
|
|
22
36
|
import { defineConfig } from "vite";
|
|
@@ -26,29 +40,211 @@ export default defineConfig({
|
|
|
26
40
|
});
|
|
27
41
|
```
|
|
28
42
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
43
|
+
Start the application normally:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
pnpm dev
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Select **Select element** in the bottom-right corner or press `Mod+Shift+S`. SpotPatch can collect multiple targets across same-project pages, preserve them through navigation and workbench close/reopen cycles, keep 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.
|
|
50
|
+
|
|
51
|
+
### Compatibility
|
|
52
|
+
|
|
53
|
+
| Dependency | Supported range |
|
|
54
|
+
| -------------------- | ------------------------------ |
|
|
55
|
+
| Node.js | `>=20.19.0` |
|
|
56
|
+
| Vite | `^5.0.0 | | ^6.0.0 | | ^7.0.0` |
|
|
57
|
+
| React public support | `18.2–18.3` |
|
|
58
|
+
| Default source files | `src/**/*.jsx`, `src/**/*.tsx` |
|
|
59
|
+
|
|
60
|
+
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).
|
|
61
|
+
|
|
62
|
+
### Options
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
spotPatch({
|
|
66
|
+
enabled: true,
|
|
67
|
+
editor: "auto",
|
|
68
|
+
redact: true,
|
|
69
|
+
shortcut: "Mod+Shift+S",
|
|
70
|
+
allowLan: false,
|
|
71
|
+
debug: false,
|
|
72
|
+
locale: "auto",
|
|
73
|
+
maxTargets: 8,
|
|
74
|
+
ai: false,
|
|
75
|
+
});
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
| Option | Default | Description |
|
|
79
|
+
| ------------ | ------------------------------------------------- | ----------------------------------------------------------------------- |
|
|
80
|
+
| `enabled` | `true` | Enables the development plugin. |
|
|
81
|
+
| `include` | JSX/TSX under `src` | Files eligible for source marker injection. |
|
|
82
|
+
| `exclude` | dependencies, tests, stories and generated output | Files excluded from transformation. |
|
|
83
|
+
| `editor` | `"auto"` | Auto-detect Cursor or VS Code; either can be fixed explicitly. |
|
|
84
|
+
| `redact` | `true` | Sanitizes collected context; mandatory secret classes remain protected. |
|
|
85
|
+
| `budget` | bounded defaults | Limits total, DOM, CSS and source context sizes. |
|
|
86
|
+
| `shortcut` | `"Mod+Shift+S"` | Toggles element selection. |
|
|
87
|
+
| `allowLan` | `false` | Keeps Host and Origin authorization loopback-only by default. |
|
|
88
|
+
| `debug` | `false` | Enables development diagnostics without logging credentials. |
|
|
89
|
+
| `locale` | `"auto"` | Resolves `en-US` or `zh-CN`. |
|
|
90
|
+
| `maxTargets` | `8` | Targets allowed in one change request by default. |
|
|
91
|
+
| `ai` | disabled or a detected complete environment | Optional provider and Agent settings. |
|
|
92
|
+
|
|
93
|
+
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.
|
|
94
|
+
|
|
95
|
+
### Optional AI Agent
|
|
96
|
+
|
|
97
|
+
AI remains disabled unless every required provider value is available. The smallest setup uses a Git-ignored `.env.local` file:
|
|
33
98
|
|
|
34
99
|
```dotenv
|
|
35
100
|
SPOTPATCH_AI_BASE_URL=https://relay.example.com/v1
|
|
36
101
|
SPOTPATCH_AI_MODEL=provider-model-name
|
|
37
102
|
SPOTPATCH_AI_API_KEY=<your-key>
|
|
103
|
+
|
|
104
|
+
# Optional:
|
|
105
|
+
# SPOTPATCH_AI_PROTOCOL=chat-completions
|
|
106
|
+
# SPOTPATCH_AI_AUTHENTICATION=bearer
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
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.
|
|
110
|
+
|
|
111
|
+
Non-secret provider values can instead be declared in the plugin configuration:
|
|
112
|
+
|
|
113
|
+
```ts
|
|
114
|
+
spotPatch({
|
|
115
|
+
ai: {
|
|
116
|
+
baseURL: "https://relay.example.com/v1",
|
|
117
|
+
model: "provider-model-name",
|
|
118
|
+
},
|
|
119
|
+
});
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
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.
|
|
123
|
+
|
|
124
|
+
### Security and production behavior
|
|
125
|
+
|
|
126
|
+
- Browser requests use a random session token and random file identifiers.
|
|
127
|
+
- Source reads are restricted to registered JSX/TSX files inside the active project root.
|
|
128
|
+
- Sensitive DOM data, credentials, tokens, cookies and authorization values are sanitized.
|
|
129
|
+
- API keys never enter the browser bundle or generated prompt.
|
|
130
|
+
- `allowLan: false` is the default. Enabling LAN access expands the trust boundary and should be deliberate.
|
|
131
|
+
- `vite build` and `vite preview` do not activate the SpotPatch development service.
|
|
132
|
+
- Production leakage tests assert zero Runtime, source markers, endpoints, and internal secrets.
|
|
133
|
+
|
|
134
|
+
### Troubleshooting
|
|
135
|
+
|
|
136
|
+
- **No selection button:** confirm `spotPatch()` appears before the React plugin and that the app is running through `vite`/`vite dev`, not `vite preview`.
|
|
137
|
+
- **No exact source location:** confirm the component is authored in an included `.jsx` or `.tsx` file under `src`, or configure `include` explicitly.
|
|
138
|
+
- **AI is unavailable:** provide all three required environment values or set `ai: false`; partial environment configuration fails closed.
|
|
139
|
+
- **Editor does not open:** use `editor: "cursor"` or `editor: "vscode"` when terminal auto-detection cannot identify the intended editor.
|
|
140
|
+
|
|
141
|
+
### Links
|
|
142
|
+
|
|
143
|
+
- [Repository and complete documentation](https://github.com/huanglvjing/spotpatch)
|
|
144
|
+
- [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)
|
|
145
|
+
- [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)
|
|
146
|
+
- [Issues](https://github.com/huanglvjing/spotpatch/issues)
|
|
147
|
+
|
|
148
|
+
---
|
|
149
|
+
|
|
150
|
+
## 简体中文
|
|
151
|
+
|
|
152
|
+
`@spotpatch/vite` 是 SpotPatch 当前正式支持的 Vite 接入包:在 React 页面中选择元素,定位到 JSX/TSX 源码,采集经过预算约束与脱敏的上下文,为每个目标分别编写要求,然后复制结构化 Prompt,或运行默认需要审阅的可选 AI Agent。
|
|
153
|
+
|
|
154
|
+
SpotPatch 只在 Vite 开发服务器中运行。生产构建不包含 SpotPatch Runtime、源码标记或本地 API 端点。
|
|
155
|
+
|
|
156
|
+
### 安装
|
|
157
|
+
|
|
158
|
+
```bash
|
|
159
|
+
npm install --save-dev @spotpatch/vite
|
|
160
|
+
# 或
|
|
161
|
+
pnpm add -D @spotpatch/vite
|
|
38
162
|
```
|
|
39
163
|
|
|
40
|
-
|
|
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.
|
|
164
|
+
### 配置
|
|
44
165
|
|
|
45
|
-
|
|
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.
|
|
166
|
+
SpotPatch 必须放在 React 插件之前,让开发期源码转换先执行。
|
|
50
167
|
|
|
51
|
-
|
|
168
|
+
```ts
|
|
169
|
+
// vite.config.ts
|
|
170
|
+
import { spotPatch } from "@spotpatch/vite";
|
|
171
|
+
import react from "@vitejs/plugin-react-swc";
|
|
172
|
+
import { defineConfig } from "vite";
|
|
173
|
+
|
|
174
|
+
export default defineConfig({
|
|
175
|
+
plugins: [spotPatch(), react()],
|
|
176
|
+
});
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
照常启动应用:
|
|
180
|
+
|
|
181
|
+
```bash
|
|
182
|
+
pnpm dev
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
点击右下角的 **选择元素** 或按下 `Mod+Shift+S`。SpotPatch 支持跨同一项目的多个页面采集目标,在页面跳转及工作台关闭/重开后保留目标与独立修改要求,在 Cursor 或 VS Code 中打开精确位置,并且在完全不配置 AI 的情况下生成结构化 Prompt。
|
|
186
|
+
|
|
187
|
+
### 兼容范围
|
|
188
|
+
|
|
189
|
+
| 依赖 | 正式支持范围 |
|
|
190
|
+
| -------------- | ------------------------------ |
|
|
191
|
+
| Node.js | `>=20.19.0` |
|
|
192
|
+
| Vite | `^5.0.0 | | ^6.0.0 | | ^7.0.0` |
|
|
193
|
+
| React 正式支持 | `18.2–18.3` |
|
|
194
|
+
| 默认源码文件 | `src/**/*.jsx`、`src/**/*.tsx` |
|
|
195
|
+
|
|
196
|
+
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)。
|
|
197
|
+
|
|
198
|
+
### 选项
|
|
199
|
+
|
|
200
|
+
```ts
|
|
201
|
+
spotPatch({
|
|
202
|
+
enabled: true,
|
|
203
|
+
editor: "auto",
|
|
204
|
+
redact: true,
|
|
205
|
+
shortcut: "Mod+Shift+S",
|
|
206
|
+
allowLan: false,
|
|
207
|
+
debug: false,
|
|
208
|
+
locale: "auto",
|
|
209
|
+
maxTargets: 8,
|
|
210
|
+
ai: false,
|
|
211
|
+
});
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
| 选项 | 默认值 | 说明 |
|
|
215
|
+
| ------------ | ---------------------------- | ---------------------------------------------------- |
|
|
216
|
+
| `enabled` | `true` | 启用开发期插件。 |
|
|
217
|
+
| `include` | `src` 下 JSX/TSX | 允许注入源码标记的文件。 |
|
|
218
|
+
| `exclude` | 依赖、测试、Story 与生成目录 | 不进行转换的文件。 |
|
|
219
|
+
| `editor` | `"auto"` | 自动识别 Cursor 或 VS Code,也可显式固定。 |
|
|
220
|
+
| `redact` | `true` | 清洗采集上下文;强制保护的秘密类型不会因关闭而暴露。 |
|
|
221
|
+
| `budget` | 有界默认值 | 限制总量、DOM、CSS 和源码上下文大小。 |
|
|
222
|
+
| `shortcut` | `"Mod+Shift+S"` | 切换元素选择器。 |
|
|
223
|
+
| `allowLan` | `false` | 默认只允许 loopback Host 与 Origin。 |
|
|
224
|
+
| `debug` | `false` | 输出不包含凭据的开发诊断。 |
|
|
225
|
+
| `locale` | `"auto"` | 自动解析 `en-US` 或 `zh-CN`。 |
|
|
226
|
+
| `maxTargets` | `8` | 一次修改任务默认允许的目标数。 |
|
|
227
|
+
| `ai` | 关闭或检测到完整环境配置 | 可选 Provider 和 Agent 配置。 |
|
|
228
|
+
|
|
229
|
+
本包导出选项类型、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)。
|
|
230
|
+
|
|
231
|
+
### 可选 AI Agent
|
|
232
|
+
|
|
233
|
+
只有全部必需 Provider 值可用时 AI 才会启用。最小配置放在 Git 忽略的 `.env.local` 中:
|
|
234
|
+
|
|
235
|
+
```dotenv
|
|
236
|
+
SPOTPATCH_AI_BASE_URL=https://relay.example.com/v1
|
|
237
|
+
SPOTPATCH_AI_MODEL=provider-model-name
|
|
238
|
+
SPOTPATCH_AI_API_KEY=<your-key>
|
|
239
|
+
|
|
240
|
+
# 可选:
|
|
241
|
+
# SPOTPATCH_AI_PROTOCOL=chat-completions
|
|
242
|
+
# SPOTPATCH_AI_AUTHENTICATION=bearer
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
协议支持 `chat-completions` 与 `responses`,认证支持 `bearer` 与 `x-api-key`。API Key 绝不能使用 `VITE_` 前缀,凭据必须只保留在 Vite Node 进程中。
|
|
246
|
+
|
|
247
|
+
非秘密的 Provider 信息也可以写入插件配置:
|
|
52
248
|
|
|
53
249
|
```ts
|
|
54
250
|
spotPatch({
|
|
@@ -59,20 +255,32 @@ spotPatch({
|
|
|
59
255
|
});
|
|
60
256
|
```
|
|
61
257
|
|
|
62
|
-
|
|
63
|
-
|
|
258
|
+
默认 Agent 路径必须经过审阅:先探测 Provider 能力,在隔离 Git worktree 中工作,只暴露有界文件工具而不是任意 Shell,执行已配置检查,并在 Apply 前展示完整 Diff。SpotPatch 不会替业务代码执行 commit、push、发包或部署。
|
|
259
|
+
|
|
260
|
+
### 安全与生产行为
|
|
261
|
+
|
|
262
|
+
- 浏览器请求使用随机会话令牌和随机文件标识。
|
|
263
|
+
- 源码读取只允许命中活动项目 root 内、当前会话登记的 JSX/TSX 文件。
|
|
264
|
+
- 敏感 DOM 数据、凭据、Token、Cookie 与 Authorization 会被清洗。
|
|
265
|
+
- API Key 不会进入浏览器 bundle 或生成的 Prompt。
|
|
266
|
+
- `allowLan: false` 是默认值;启用 LAN 会扩大信任边界,必须明确评估。
|
|
267
|
+
- `vite build` 与 `vite preview` 不会启动 SpotPatch 开发服务。
|
|
268
|
+
- 生产泄漏测试验证 Runtime、源码标记、端点和内部秘密零残留。
|
|
269
|
+
|
|
270
|
+
### 常见问题
|
|
271
|
+
|
|
272
|
+
- **没有选择元素按钮:**确认 `spotPatch()` 位于 React 插件之前,并且应用通过 `vite`/`vite dev` 而不是 `vite preview` 启动。
|
|
273
|
+
- **没有精确源码位置:**确认组件来自 include 范围内的 `.jsx` 或 `.tsx` 文件,默认范围是 `src`。
|
|
274
|
+
- **AI 不可用:**提供全部三个必需环境变量,或者显式设置 `ai: false`;不完整配置会安全失败。
|
|
275
|
+
- **编辑器没有打开:**终端自动识别无法确定目标时,显式设置 `editor: "cursor"` 或 `editor: "vscode"`。
|
|
276
|
+
|
|
277
|
+
### 链接
|
|
64
278
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
or Revert touches only the Agent delta. Conflicts and unsupported workspace
|
|
70
|
-
states remain blocked with an actionable reason.
|
|
279
|
+
- [仓库与完整文档](https://github.com/huanglvjing/spotpatch)
|
|
280
|
+
- [安全模型](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)
|
|
281
|
+
- [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)
|
|
282
|
+
- [问题反馈](https://github.com/huanglvjing/spotpatch/issues)
|
|
71
283
|
|
|
72
|
-
|
|
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.
|
|
284
|
+
### License / 许可证
|
|
76
285
|
|
|
77
|
-
|
|
78
|
-
the complete setup and security model.
|
|
286
|
+
[MIT](https://github.com/huanglvjing/spotpatch/blob/main/LICENSE) © SpotPatch contributors.
|