@spotpatch/vite 1.9.0 → 1.10.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.
- package/README.md +80 -16
- package/dist/cli.js +8 -1
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +38 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +39 -3
- package/dist/index.js.map +1 -1
- package/dist/runtime-client.js +34 -34
- package/dist/runtime-data-flow-panel.js +3 -3
- package/dist/runtime-data-flow-prelude.js +1 -1
- package/dist/runtime-external-handoff-panel.js +28 -0
- package/package.json +6 -5
package/README.md
CHANGED
|
@@ -90,6 +90,7 @@ spotPatch({
|
|
|
90
90
|
maxTargets: 8,
|
|
91
91
|
ai: false,
|
|
92
92
|
dataFlow: false,
|
|
93
|
+
externalAgent: false,
|
|
93
94
|
});
|
|
94
95
|
```
|
|
95
96
|
|
|
@@ -108,10 +109,41 @@ spotPatch({
|
|
|
108
109
|
| `maxTargets` | `8` | Targets allowed in one change request by default. |
|
|
109
110
|
| `ai` | disabled or a detected complete environment | Optional provider and Agent settings. |
|
|
110
111
|
| `dataFlow` | `false` | Opt-in dispatch-only component data-flow Beta. |
|
|
112
|
+
| `externalAgent` | `false` | Opt-in development-only external Agent handoff; local-validation only. |
|
|
111
113
|
| `trustedFastMode` | `false` | Exposes Review/Trusted direct and discovers TypeScript for Review. |
|
|
112
114
|
|
|
113
115
|
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.
|
|
114
116
|
|
|
117
|
+
### External Agent handoff (local validation)
|
|
118
|
+
|
|
119
|
+
Enable the development-only UI explicitly:
|
|
120
|
+
|
|
121
|
+
```ts
|
|
122
|
+
spotPatch({ externalAgent: true });
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
Run setup and active commands from the exact canonical project root that owns the running Vite development session. Setup is a dry run without `--write`:
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
pnpm exec spotpatch-vite bridge setup --client claude --scope project --mode active --write
|
|
129
|
+
MCP_PROTOCOL_NEGOTIATION=legacy claude --dangerously-load-development-channels server:spotpatch
|
|
130
|
+
|
|
131
|
+
pnpm exec spotpatch-vite connect codex --allow-workspace-write
|
|
132
|
+
|
|
133
|
+
pnpm exec spotpatch-vite bridge setup --client cursor --scope project --write
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
The active command forms support an explicit session when `bridge sessions --json` reports multiple sessions for that exact root:
|
|
137
|
+
|
|
138
|
+
```text
|
|
139
|
+
spotpatch-vite bridge channel claude [--session <opaque-id>]
|
|
140
|
+
spotpatch-vite connect codex --allow-workspace-write [--session <opaque-id>]
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
The Claude legacy environment belongs on the Claude host process. Claude Channels are a Research Preview, work only while the Channel-enabled session is running, and provide no completion acknowledgement; completion depends on Claude calling the SpotPatch result tool. Codex active mode is zero-setup: the Connector injects the project-local SpotPatch MCP entry into its App Server thread and does not create or modify `.codex/config.toml`. Codex can still load other MCP servers already enabled by the user's normal Codex configuration. The Connector accepts exactly `codex-cli 0.149.0`. `bridge setup --client codex ...` remains available only for optional Inbox use; Cursor and all generic MCP hosts remain Inbox-only.
|
|
144
|
+
|
|
145
|
+
This path is `local-validation`, not stable support. Automated fake-host and two-handoff tests exist, and a consecutive two-revision Codex flow has been manually validated on the recorded macOS/Next.js/Codex 0.149.0 environment. Real Claude Code consecutive delivery, repeatable real-host automation, and Windows process-tree cleanup remain `not-tested`; Cursor remains Inbox-only. See the [external Agent design and exact status](https://github.com/huanglvjing/spotpatch/blob/main/docs/%E6%8A%80%E6%9C%AF%E6%96%B9%E6%A1%88/%E5%A4%96%E9%83%A8Agent%E8%BF%9E%E6%8E%A5/00-%E7%B4%A2%E5%BC%95%E4%B8%8E%E5%86%B3%E7%AD%96%E6%91%98%E8%A6%81.md).
|
|
146
|
+
|
|
115
147
|
### Optional AI Agent
|
|
116
148
|
|
|
117
149
|
AI remains disabled unless every required provider value is available. The smallest setup uses a Git-ignored `.env.local` file:
|
|
@@ -256,28 +288,60 @@ spotPatch({
|
|
|
256
288
|
maxTargets: 8,
|
|
257
289
|
ai: false,
|
|
258
290
|
dataFlow: false,
|
|
291
|
+
externalAgent: false,
|
|
259
292
|
});
|
|
260
293
|
```
|
|
261
294
|
|
|
262
|
-
| 选项 | 默认值 | 说明
|
|
263
|
-
| ----------------- | ---------------------------- |
|
|
264
|
-
| `enabled` | `true` | 启用开发期插件。
|
|
265
|
-
| `include` | `src` 下 JSX/TSX | 允许注入源码标记的文件。
|
|
266
|
-
| `exclude` | 依赖、测试、Story 与生成目录 | 不进行转换的文件。
|
|
267
|
-
| `editor` | `"auto"` | 自动识别 Cursor 或 VS Code,也可显式固定。
|
|
268
|
-
| `redact` | `true` | 清洗采集上下文;强制保护的秘密类型不会因关闭而暴露。
|
|
269
|
-
| `budget` | 有界默认值 | 限制总量、DOM、CSS 和源码上下文大小。
|
|
270
|
-
| `shortcut` | `"Mod+Shift+S"` | 切换元素选择器。
|
|
271
|
-
| `allowLan` | `false` | 默认只允许 loopback Host 与 Origin。
|
|
272
|
-
| `debug` | `false` | 输出不包含凭据的开发诊断。
|
|
273
|
-
| `locale` | `"auto"` | 自动解析 `en-US` 或 `zh-CN`。
|
|
274
|
-
| `maxTargets` | `8` | 一次修改任务默认允许的目标数。
|
|
275
|
-
| `ai` | 关闭或检测到完整环境配置 | 可选 Provider 和 Agent 配置。
|
|
276
|
-
| `dataFlow` | `false` | 可选 dispatch-only 组件数据链路 Beta。
|
|
277
|
-
| `
|
|
295
|
+
| 选项 | 默认值 | 说明 |
|
|
296
|
+
| ----------------- | ---------------------------- | ---------------------------------------------------------- |
|
|
297
|
+
| `enabled` | `true` | 启用开发期插件。 |
|
|
298
|
+
| `include` | `src` 下 JSX/TSX | 允许注入源码标记的文件。 |
|
|
299
|
+
| `exclude` | 依赖、测试、Story 与生成目录 | 不进行转换的文件。 |
|
|
300
|
+
| `editor` | `"auto"` | 自动识别 Cursor 或 VS Code,也可显式固定。 |
|
|
301
|
+
| `redact` | `true` | 清洗采集上下文;强制保护的秘密类型不会因关闭而暴露。 |
|
|
302
|
+
| `budget` | 有界默认值 | 限制总量、DOM、CSS 和源码上下文大小。 |
|
|
303
|
+
| `shortcut` | `"Mod+Shift+S"` | 切换元素选择器。 |
|
|
304
|
+
| `allowLan` | `false` | 默认只允许 loopback Host 与 Origin。 |
|
|
305
|
+
| `debug` | `false` | 输出不包含凭据的开发诊断。 |
|
|
306
|
+
| `locale` | `"auto"` | 自动解析 `en-US` 或 `zh-CN`。 |
|
|
307
|
+
| `maxTargets` | `8` | 一次修改任务默认允许的目标数。 |
|
|
308
|
+
| `ai` | 关闭或检测到完整环境配置 | 可选 Provider 和 Agent 配置。 |
|
|
309
|
+
| `dataFlow` | `false` | 可选 dispatch-only 组件数据链路 Beta。 |
|
|
310
|
+
| `externalAgent` | `false` | 可选、仅开发期的外部 Agent 交接;当前仅 local-validation。 |
|
|
311
|
+
| `trustedFastMode` | `false` | 开放审阅/可信极速选择;TypeScript 检查供审阅模式使用。 |
|
|
278
312
|
|
|
279
313
|
本包导出选项类型、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)。
|
|
280
314
|
|
|
315
|
+
### 外部 Agent 交接(本地验证)
|
|
316
|
+
|
|
317
|
+
显式启用仅开发期的 UI:
|
|
318
|
+
|
|
319
|
+
```ts
|
|
320
|
+
spotPatch({ externalAgent: true });
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
必须在当前 Vite dev Session 所属的精确 canonical 项目根执行 setup 和主动命令。setup 不带 `--write` 时只是 dry-run:
|
|
324
|
+
|
|
325
|
+
```bash
|
|
326
|
+
pnpm exec spotpatch-vite bridge setup --client claude --scope project --mode active --write
|
|
327
|
+
MCP_PROTOCOL_NEGOTIATION=legacy claude --dangerously-load-development-channels server:spotpatch
|
|
328
|
+
|
|
329
|
+
pnpm exec spotpatch-vite connect codex --allow-workspace-write
|
|
330
|
+
|
|
331
|
+
pnpm exec spotpatch-vite bridge setup --client cursor --scope project --write
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
若 `bridge sessions --json` 报告该精确项目根有多个 Session,主动子命令支持显式选择:
|
|
335
|
+
|
|
336
|
+
```text
|
|
337
|
+
spotpatch-vite bridge channel claude [--session <opaque-id>]
|
|
338
|
+
spotpatch-vite connect codex --allow-workspace-write [--session <opaque-id>]
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
Claude legacy 环境变量必须设置在 Claude 宿主进程。Claude Channels 仍是 Research Preview,只在已启用 Channel 的会话运行时工作,且没有 completion ACK;完成状态依赖 Claude 调用 SpotPatch 结果 tool。Codex 主动模式为零配置:Connector 只把当前项目的 SpotPatch MCP 配置注入它拥有的 App Server thread,不创建也不修改 `.codex/config.toml`;Codex 仍可能按用户既有配置启动其他已启用 MCP server。Connector 当前只接受 `codex-cli 0.149.0`。`bridge setup --client codex ...` 仅保留为可选 Inbox 配置;Cursor 和所有普通 MCP 宿主仍为 Inbox-only。
|
|
342
|
+
|
|
343
|
+
该链路当前只是 `local-validation`,不是稳定支持。仓库有假宿主和连续两 Handoff 自动化测试,并已在记录的 macOS/Next.js/Codex 0.149.0 环境人工验证连续两个 revision。真实 Claude Code 连续投递、可重复真实宿主自动化和 Windows 进程树清理仍为 `not-tested`;Cursor 保持 Inbox-only。准确边界见[外部 Agent 方案与实现状态](https://github.com/huanglvjing/spotpatch/blob/main/docs/%E6%8A%80%E6%9C%AF%E6%96%B9%E6%A1%88/%E5%A4%96%E9%83%A8Agent%E8%BF%9E%E6%8E%A5/00-%E7%B4%A2%E5%BC%95%E4%B8%8E%E5%86%B3%E7%AD%96%E6%91%98%E8%A6%81.md)。
|
|
344
|
+
|
|
281
345
|
### 可选 AI Agent
|
|
282
346
|
|
|
283
347
|
只有全部必需 Provider 值可用时 AI 才会启用。最小配置放在 Git 忽略的 `.env.local` 中:
|
package/dist/cli.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
import { readFile as readFile2 } from "fs/promises";
|
|
5
5
|
import { createRequire } from "module";
|
|
6
6
|
import path3 from "path";
|
|
7
|
+
import { runSpotPatchBridgeCli } from "@spotpatch/bridge";
|
|
7
8
|
|
|
8
9
|
// src/initializer.ts
|
|
9
10
|
import path from "path";
|
|
@@ -579,7 +580,7 @@ async function installCurrentAdapter(packageManager, appRoot = process.cwd()) {
|
|
|
579
580
|
var VERSION_PATTERN2 = /^(\d+)\.(\d+)\.(\d+)(?:-[0-9A-Za-z.-]+)?$/u;
|
|
580
581
|
function writeUsage() {
|
|
581
582
|
process.stderr.write(
|
|
582
|
-
"Usage: spotpatch-vite <setup|init|check>\n setup Install this CLI's exact @spotpatch/vite version, then initialize it.\n init Preview and apply safe Vite integration changes.\n check Verify the Vite integration without writing files.\n"
|
|
583
|
+
"Usage: spotpatch-vite <setup|init|check|connect|bridge>\n setup Install this CLI's exact @spotpatch/vite version, then initialize it.\n init Preview and apply safe Vite integration changes.\n check Verify the Vite integration without writing files.\n connect codex Start the zero-setup Codex Agent connector.\n bridge Run the local external-Agent MCP, CLI, or setup commands.\n"
|
|
583
584
|
);
|
|
584
585
|
}
|
|
585
586
|
async function inspectViteProject(appRoot = process.cwd()) {
|
|
@@ -681,6 +682,12 @@ async function main(arguments_) {
|
|
|
681
682
|
if (command === "check") {
|
|
682
683
|
return runCheck(rest);
|
|
683
684
|
}
|
|
685
|
+
if (command === "bridge") {
|
|
686
|
+
return runSpotPatchBridgeCli(rest, { adapter: "vite" });
|
|
687
|
+
}
|
|
688
|
+
if (command === "connect") {
|
|
689
|
+
return runSpotPatchBridgeCli(arguments_, { adapter: "vite" });
|
|
690
|
+
}
|
|
684
691
|
writeUsage();
|
|
685
692
|
return 1;
|
|
686
693
|
}
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/cli.ts","../src/initializer.ts","../src/setup.ts"],"sourcesContent":["import { readFile } from \"node:fs/promises\";\nimport { createRequire } from \"node:module\";\nimport path from \"node:path\";\n\nimport {\n applyViteIntegrationPlan,\n checkViteIntegration,\n planViteIntegration,\n} from \"./initializer.js\";\nimport { detectPackageManager, installCurrentAdapter } from \"./setup.js\";\n\nconst VERSION_PATTERN = /^(\\d+)\\.(\\d+)\\.(\\d+)(?:-[0-9A-Za-z.-]+)?$/u;\n\nfunction writeUsage(): void {\n process.stderr.write(\n \"Usage: spotpatch-vite <setup|init|check>\\n\" +\n \" setup Install this CLI's exact @spotpatch/vite version, then initialize it.\\n\" +\n \" init Preview and apply safe Vite integration changes.\\n\" +\n \" check Verify the Vite integration without writing files.\\n\",\n );\n}\n\nasync function inspectViteProject(appRoot = process.cwd()): Promise<string> {\n const resolveFromApplication = createRequire(path.join(appRoot, \"package.json\"));\n let adapterEntry: string;\n let viteManifestPath: string;\n\n try {\n adapterEntry = resolveFromApplication.resolve(\"@spotpatch/vite\");\n viteManifestPath = resolveFromApplication.resolve(\"vite/package.json\");\n } catch (error: unknown) {\n throw new Error(\n \"SpotPatch could not resolve the local @spotpatch/vite and Vite packages.\",\n { cause: error },\n );\n }\n\n if (adapterEntry.length === 0) {\n throw new Error(\"SpotPatch could not resolve the Vite adapter export.\");\n }\n\n const manifest = JSON.parse(await readFile(viteManifestPath, \"utf8\")) as unknown;\n const version =\n typeof manifest === \"object\" &&\n manifest !== null &&\n \"version\" in manifest &&\n typeof manifest.version === \"string\"\n ? manifest.version\n : undefined;\n const match = version === undefined ? null : VERSION_PATTERN.exec(version);\n const major = Number(match?.[1]);\n\n if (\n version === undefined ||\n match === null ||\n !Number.isSafeInteger(major) ||\n major < 5 ||\n major >= 8\n ) {\n throw new Error(\n `SpotPatch Vite requires Vite >=5.0.0 <8.0.0; found ${version ?? \"unknown\"}.`,\n );\n }\n\n return version;\n}\n\nfunction writeTrustedModeStatus(available: boolean): void {\n process.stdout.write(\n available\n ? \"[spotpatch:vite] trusted fast mode is available in the page selector.\\n\"\n : \"[spotpatch:vite] review mode is ready; trusted fast mode needs a local TypeScript project check.\\n\",\n );\n}\n\nasync function runInit(arguments_: readonly string[]): Promise<number> {\n if (arguments_.length !== 0) {\n throw new Error(\"SpotPatch init does not accept positional arguments.\");\n }\n\n await inspectViteProject();\n const plan = await planViteIntegration();\n\n if (plan.changes.length === 0) {\n process.stdout.write(\"[spotpatch:vite] integration is already up to date.\\n\");\n writeTrustedModeStatus(plan.trustedFastModeAvailable);\n return 0;\n }\n\n process.stdout.write(\"[spotpatch:vite] integration preview (resulting files):\\n\");\n\n for (const change of plan.changes) {\n process.stdout.write(`\\n--- ${change.relativePath}\\n${change.nextContent}`);\n\n if (!change.nextContent.endsWith(\"\\n\")) {\n process.stdout.write(\"\\n\");\n }\n }\n\n await applyViteIntegrationPlan(plan);\n process.stdout.write(\n `[spotpatch:vite] updated ${String(plan.changes.length)} integration file(s).\\n`,\n );\n writeTrustedModeStatus(plan.trustedFastModeAvailable);\n\n return 0;\n}\n\nasync function runSetup(arguments_: readonly string[]): Promise<number> {\n if (arguments_.length !== 0) {\n throw new Error(\"SpotPatch setup does not accept positional arguments.\");\n }\n\n const packageManager = await detectPackageManager();\n await installCurrentAdapter(packageManager);\n return runInit([]);\n}\n\nasync function runCheck(arguments_: readonly string[]): Promise<number> {\n if (arguments_.length !== 0) {\n throw new Error(\"SpotPatch check does not accept positional arguments.\");\n }\n\n const version = await inspectViteProject();\n const result = await checkViteIntegration();\n\n if (!result.ok) {\n for (const issue of result.issues) {\n process.stderr.write(`[spotpatch:vite] ${issue}\\n`);\n }\n\n return 1;\n }\n\n const mode = result.trustedFastModeAvailable\n ? \"trusted fast mode available\"\n : \"review mode\";\n process.stdout.write(\n `[spotpatch:vite] integration verified for Vite ${version} · ${mode}.\\n`,\n );\n return 0;\n}\n\nasync function main(arguments_: readonly string[]): Promise<number> {\n const [command, ...rest] = arguments_;\n\n if (command === \"setup\") {\n return runSetup(rest);\n }\n\n if (command === \"init\") {\n return runInit(rest);\n }\n\n if (command === \"check\") {\n return runCheck(rest);\n }\n\n writeUsage();\n return 1;\n}\n\ntry {\n process.exitCode = await main(process.argv.slice(2));\n} catch (error: unknown) {\n process.stderr.write(\n `[spotpatch:vite] ${\n error instanceof Error ? error.message : \"The command failed.\"\n }\\n`,\n );\n process.exitCode = 1;\n}\n","import path from \"node:path\";\n\nimport {\n applyIntegrationPlan,\n createIntegrationFileChange,\n discoverProjectValidationCheck,\n integrationPathExists,\n readIntegrationFile,\n type IntegrationFileChange,\n} from \"@spotpatch/dev-server\";\nimport { DEFAULT_AGENT_LIMITS } from \"@spotpatch/shared\";\nimport { MagicString } from \"magic-string\";\nimport {\n parseSync,\n Visitor,\n type ArrayExpression,\n type CallExpression,\n type ExportDefaultDeclaration,\n type Expression,\n type ImportDeclaration,\n type ObjectExpression,\n type ObjectProperty,\n type Program,\n type ReturnStatement,\n} from \"oxc-parser\";\n\nconst ADAPTER_PACKAGE_NAME = \"@spotpatch/vite\";\nconst CONFIG_FILE_NAMES = Object.freeze([\n \"vite.config.ts\",\n \"vite.config.mts\",\n \"vite.config.js\",\n \"vite.config.mjs\",\n] as const);\n\nexport interface ViteIntegrationPlan {\n readonly appRoot: string;\n readonly changes: readonly IntegrationFileChange[];\n readonly trustedFastModeAvailable: boolean;\n}\n\nexport interface ViteIntegrationCheck {\n readonly appRoot: string;\n readonly issues: readonly string[];\n readonly ok: boolean;\n readonly trustedFastModeAvailable: boolean;\n}\n\ninterface ParsedModule {\n readonly program: Program;\n readonly source: string;\n}\n\nfunction isParserErrorSeverity(value: unknown): boolean {\n return value === \"Error\";\n}\n\nfunction parseModule(absolutePath: string, source: string): ParsedModule {\n const result = parseSync(absolutePath, source, {\n sourceType: \"module\",\n showSemanticErrors: true,\n });\n const error = result.errors.find((entry) => isParserErrorSeverity(entry.severity));\n\n if (error !== undefined) {\n throw new SyntaxError(\n `SpotPatch could not safely parse ${path.basename(absolutePath)} (${error.message}).`,\n );\n }\n\n return Object.freeze({ program: result.program, source });\n}\n\nfunction importsOf(program: Program): readonly ImportDeclaration[] {\n return program.body.filter(\n (statement): statement is ImportDeclaration =>\n statement.type === \"ImportDeclaration\",\n );\n}\n\nfunction importInsertionOffset(program: Program): number {\n const lastImport = importsOf(program).at(-1);\n\n if (lastImport !== undefined) {\n return lastImport.end;\n }\n\n const directives = program.body.filter(\n (statement) =>\n statement.type === \"ExpressionStatement\" &&\n typeof statement.directive === \"string\",\n );\n return directives.at(-1)?.end ?? program.hashbang?.end ?? 0;\n}\n\nfunction insertStaticImport(\n magicString: MagicString,\n program: Program,\n statement: string,\n): void {\n const offset = importInsertionOffset(program);\n\n if (offset === 0) {\n magicString.prepend(`${statement}\\n`);\n return;\n }\n\n magicString.appendRight(offset, `\\n${statement}`);\n}\n\nfunction importQuote(source: string, program: Program): '\"' | \"'\" {\n const firstImport = importsOf(program)[0];\n\n if (firstImport !== undefined) {\n const quote = source[firstImport.source.start];\n\n if (quote === '\"' || quote === \"'\") {\n return quote;\n }\n }\n\n return '\"';\n}\n\nfunction collectIdentifierNames(program: Program): ReadonlySet<string> {\n const names = new Set<string>();\n new Visitor({\n Identifier(node) {\n names.add(node.name);\n },\n }).visit(program);\n return names;\n}\n\nfunction choosePluginName(program: Program): string {\n const names = collectIdentifierNames(program);\n let suffix = 0;\n let candidate = \"spotPatch\";\n\n while (names.has(candidate)) {\n suffix += 1;\n candidate = `spotPatch${String(suffix)}`;\n }\n\n return candidate;\n}\n\nfunction importedPluginName(program: Program): string | undefined {\n const adapterImports = importsOf(program).filter(\n (statement) => statement.source.value === ADAPTER_PACKAGE_NAME,\n );\n\n if (adapterImports.length > 1) {\n throw new Error(\"SpotPatch init found duplicate @spotpatch/vite imports.\");\n }\n\n const adapterImport = adapterImports[0];\n\n if (adapterImport === undefined) {\n return undefined;\n }\n\n const plugin = adapterImport.specifiers.find(\n (specifier) =>\n specifier.type === \"ImportSpecifier\" &&\n specifier.imported.type === \"Identifier\" &&\n specifier.imported.name === \"spotPatch\" &&\n specifier.importKind !== \"type\",\n );\n\n if (plugin === undefined) {\n throw new Error(\n \"SpotPatch init cannot safely merge the existing @spotpatch/vite import.\",\n );\n }\n\n return plugin.local.name;\n}\n\nfunction unwrapExpression(expression: Expression): Expression {\n let current = expression;\n\n while (\n current.type === \"ParenthesizedExpression\" ||\n current.type === \"TSAsExpression\" ||\n current.type === \"TSSatisfiesExpression\" ||\n current.type === \"TSTypeAssertion\" ||\n current.type === \"TSNonNullExpression\"\n ) {\n current = current.expression;\n }\n\n return current;\n}\n\nfunction findDefaultExport(program: Program): ExportDefaultDeclaration {\n const exports = program.body.filter(\n (statement): statement is ExportDefaultDeclaration =>\n statement.type === \"ExportDefaultDeclaration\",\n );\n\n if (exports.length !== 1 || exports[0] === undefined) {\n throw new Error(\n \"SpotPatch init requires exactly one ESM default export in vite.config.\",\n );\n }\n\n return exports[0];\n}\n\nfunction findVariableInitializer(\n program: Program,\n name: string,\n): Expression | undefined {\n for (const statement of program.body) {\n if (statement.type !== \"VariableDeclaration\") {\n continue;\n }\n\n for (const declaration of statement.declarations) {\n if (\n declaration.id.type === \"Identifier\" &&\n declaration.id.name === name &&\n declaration.init !== null\n ) {\n return declaration.init;\n }\n }\n }\n\n return undefined;\n}\n\nfunction resolveConfigExpression(program: Program): Expression {\n const exported = findDefaultExport(program).declaration;\n\n if (\n exported.type === \"FunctionDeclaration\" ||\n exported.type === \"ClassDeclaration\" ||\n exported.type === \"TSInterfaceDeclaration\"\n ) {\n throw new Error(\n \"SpotPatch init requires vite.config to export a configuration expression.\",\n );\n }\n\n const expression = unwrapExpression(exported);\n const resolved =\n expression.type === \"Identifier\"\n ? findVariableInitializer(program, expression.name)\n : expression;\n\n if (resolved === undefined) {\n throw new Error(\"SpotPatch init could not resolve the vite.config export.\");\n }\n\n return unwrapExpression(resolved);\n}\n\nfunction resolveFactoryConfigObject(\n expression: Expression,\n): ObjectExpression | undefined {\n const factory = unwrapExpression(expression);\n\n if (\n factory.type !== \"ArrowFunctionExpression\" &&\n factory.type !== \"FunctionExpression\"\n ) {\n return undefined;\n }\n\n if (factory.body === null) {\n throw new Error(\n \"SpotPatch init cannot use a defineConfig callback without a body.\",\n );\n }\n\n if (factory.body.type !== \"BlockStatement\") {\n const returned = unwrapExpression(factory.body);\n return returned.type === \"ObjectExpression\" ? returned : undefined;\n }\n\n const returns: ReturnStatement[] = [];\n new Visitor({\n ReturnStatement(statement) {\n returns.push(statement);\n },\n }).visit({\n type: \"Program\",\n body: factory.body.body,\n sourceType: \"module\",\n hashbang: null,\n start: factory.body.start,\n end: factory.body.end,\n });\n\n const onlyReturn = returns.length === 1 ? returns[0] : undefined;\n\n if (onlyReturn?.argument == null) {\n throw new Error(\n \"SpotPatch init requires a defineConfig callback with exactly one top-level object return.\",\n );\n }\n\n const returned = unwrapExpression(onlyReturn.argument);\n\n if (returned.type !== \"ObjectExpression\") {\n throw new Error(\n \"SpotPatch init requires the defineConfig callback to return a configuration object directly.\",\n );\n }\n\n return returned;\n}\n\nfunction resolveConfigObject(program: Program): ObjectExpression {\n const expression = resolveConfigExpression(program);\n\n if (expression.type === \"ObjectExpression\") {\n return expression;\n }\n\n if (expression.type === \"CallExpression\") {\n const callee = unwrapExpression(expression.callee);\n const argument = expression.arguments[0];\n\n if (\n callee.type === \"Identifier\" &&\n callee.name === \"defineConfig\" &&\n expression.arguments.length === 1 &&\n argument !== undefined &&\n argument.type !== \"SpreadElement\"\n ) {\n const value = unwrapExpression(argument);\n\n if (value.type === \"ObjectExpression\") {\n return value;\n }\n\n const callbackObject = resolveFactoryConfigObject(value);\n\n if (callbackObject !== undefined) {\n return callbackObject;\n }\n }\n }\n\n throw new Error(\n \"SpotPatch init supports a configuration object or an object-returning callback passed to defineConfig.\",\n );\n}\n\nfunction propertyName(property: ObjectProperty): string | undefined {\n if (property.computed) {\n return undefined;\n }\n\n if (property.key.type === \"Identifier\") {\n return property.key.name;\n }\n\n if (property.key.type === \"Literal\" && typeof property.key.value === \"string\") {\n return property.key.value;\n }\n\n return undefined;\n}\n\nfunction findProperty(\n object: ObjectExpression,\n name: string,\n): ObjectProperty | undefined {\n const matches = object.properties.filter(\n (property): property is ObjectProperty =>\n property.type === \"Property\" && propertyName(property) === name,\n );\n\n if (matches.length > 1) {\n throw new Error(`SpotPatch init found duplicate ${name} properties.`);\n }\n\n return matches[0];\n}\n\nfunction lineIndentAt(source: string, offset: number): string {\n const lineStart = source.lastIndexOf(\"\\n\", Math.max(0, offset - 1)) + 1;\n return /^[\\t ]*/u.exec(source.slice(lineStart, offset))?.[0] ?? \"\";\n}\n\nfunction childIndent(source: string, object: ObjectExpression): string {\n const first = object.properties[0];\n\n if (first !== undefined) {\n return lineIndentAt(source, first.start);\n }\n\n return `${lineIndentAt(source, object.start)} `;\n}\n\nfunction initializedPluginCall(pluginName: string, trustedFastMode: boolean): string {\n const options = [\n \"dataFlow: {}\",\n ...(trustedFastMode ? [\"trustedFastMode: true\"] : []),\n ];\n return `${pluginName}({ ${options.join(\", \")} })`;\n}\n\nfunction directPluginCalls(\n plugins: ArrayExpression,\n pluginName: string,\n): readonly CallExpression[] {\n return plugins.elements.filter((element): element is CallExpression => {\n if (element?.type !== \"CallExpression\") {\n return false;\n }\n\n const callee = unwrapExpression(element.callee);\n return callee.type === \"Identifier\" && callee.name === pluginName;\n });\n}\n\nfunction enableInitializedOptions(\n magicString: MagicString,\n source: string,\n call: CallExpression,\n trustedFastMode: boolean,\n): void {\n if (call.arguments.length === 0) {\n magicString.overwrite(\n call.start,\n call.end,\n initializedPluginCall(source.slice(call.start, call.callee.end), trustedFastMode),\n );\n return;\n }\n\n const argument = call.arguments[0];\n\n if (\n call.arguments.length !== 1 ||\n argument === undefined ||\n argument.type === \"SpreadElement\"\n ) {\n throw new Error(\"SpotPatch init cannot safely update the spotPatch options.\");\n }\n\n const value = unwrapExpression(argument);\n\n if (value.type !== \"ObjectExpression\") {\n throw new Error(\"SpotPatch init requires spotPatch options to be an object.\");\n }\n\n if (value.properties.some((property) => property.type === \"SpreadElement\")) {\n throw new Error(\n \"SpotPatch init cannot prove dataFlow through spread spotPatch options.\",\n );\n }\n\n const dataFlowProperty = findProperty(value, \"dataFlow\");\n const trustedFastModeProperty = findProperty(value, \"trustedFastMode\");\n const missingProperties: string[] = [];\n\n if (dataFlowProperty === undefined) {\n missingProperties.push(\"dataFlow: {}\");\n } else {\n const dataFlowValue = unwrapExpression(dataFlowProperty.value);\n\n if (dataFlowValue.type === \"Literal\" && dataFlowValue.value === false) {\n magicString.overwrite(dataFlowValue.start, dataFlowValue.end, \"{}\");\n } else if (dataFlowValue.type !== \"ObjectExpression\") {\n throw new Error(\n \"SpotPatch init requires dataFlow to be false or an options object.\",\n );\n }\n }\n\n if (trustedFastMode && trustedFastModeProperty === undefined) {\n missingProperties.push(\"trustedFastMode: true\");\n } else if (trustedFastModeProperty !== undefined) {\n const propertyValue = unwrapExpression(trustedFastModeProperty.value);\n\n if (propertyValue.type !== \"Literal\" || typeof propertyValue.value !== \"boolean\") {\n throw new Error(\n \"SpotPatch init requires trustedFastMode to be a boolean literal.\",\n );\n }\n\n if (trustedFastMode && !propertyValue.value) {\n magicString.overwrite(propertyValue.start, propertyValue.end, \"true\");\n }\n }\n\n if (missingProperties.length === 0) return;\n\n const indent = childIndent(source, value);\n\n if (value.properties.length === 0) {\n magicString.appendLeft(value.end - 1, ` ${missingProperties.join(\", \")} `);\n } else {\n magicString.appendLeft(\n value.properties[0]?.start ?? value.end - 1,\n `${missingProperties.join(`,\\n${indent}`)},\\n${indent}`,\n );\n }\n}\n\nfunction addPluginCall(\n magicString: MagicString,\n source: string,\n config: ObjectExpression,\n pluginName: string,\n trustedFastModeAvailable: boolean,\n): void {\n const pluginsProperty = findProperty(config, \"plugins\");\n const call = initializedPluginCall(pluginName, trustedFastModeAvailable);\n\n if (pluginsProperty === undefined) {\n const indent = childIndent(source, config);\n\n if (config.properties.length === 0) {\n magicString.appendLeft(config.end - 1, `\\n${indent}plugins: [${call}],\\n`);\n } else {\n magicString.appendLeft(\n config.properties[0]?.start ?? config.end - 1,\n `plugins: [${call}],\\n${indent}`,\n );\n }\n\n return;\n }\n\n const value = unwrapExpression(pluginsProperty.value);\n\n if (value.type !== \"ArrayExpression\") {\n throw new Error(\"SpotPatch init requires vite.config plugins to be an array.\");\n }\n\n const existing = directPluginCalls(value, pluginName);\n\n if (existing.length > 1) {\n throw new Error(\"SpotPatch init found duplicate spotPatch plugins.\");\n }\n\n if (existing[0] !== undefined) {\n enableInitializedOptions(\n magicString,\n source,\n existing[0],\n trustedFastModeAvailable,\n );\n\n return;\n }\n\n const first = value.elements.find((element) => element !== null);\n\n if (first === undefined) {\n magicString.appendLeft(value.end - 1, call);\n } else if (!source.slice(value.start, first.start).includes(\"\\n\")) {\n magicString.appendLeft(first.start, `${call}, `);\n } else {\n magicString.appendLeft(\n first.start,\n `${call},\\n${lineIndentAt(source, first.start)}`,\n );\n }\n}\n\nfunction transformViteConfig(\n absolutePath: string,\n source: string,\n trustedFastModeAvailable: boolean,\n): string {\n const { program } = parseModule(absolutePath, source);\n const config = resolveConfigObject(program);\n const existingPluginName = importedPluginName(program);\n const pluginName = existingPluginName ?? choosePluginName(program);\n const magicString = new MagicString(source);\n\n if (existingPluginName === undefined) {\n const specifier =\n pluginName === \"spotPatch\" ? \"spotPatch\" : `spotPatch as ${pluginName}`;\n const quote = importQuote(source, program);\n insertStaticImport(\n magicString,\n program,\n `import { ${specifier} } from ${quote}${ADAPTER_PACKAGE_NAME}${quote};`,\n );\n }\n\n addPluginCall(magicString, source, config, pluginName, trustedFastModeAvailable);\n return magicString.toString();\n}\n\nasync function findViteConfig(appRoot: string): Promise<string> {\n const candidates = (\n await Promise.all(\n CONFIG_FILE_NAMES.map(async (name) => {\n const absolutePath = path.join(appRoot, name);\n return (await integrationPathExists(absolutePath)) ? absolutePath : undefined;\n }),\n )\n ).filter((value): value is string => value !== undefined);\n\n if (candidates.length !== 1 || candidates[0] === undefined) {\n throw new Error(\"SpotPatch init requires exactly one supported vite.config file.\");\n }\n\n return candidates[0];\n}\n\nexport async function planViteIntegration(\n directory = process.cwd(),\n): Promise<ViteIntegrationPlan> {\n const appRoot = path.resolve(directory);\n const configPath = await findViteConfig(appRoot);\n const [configSource, discoveredCheck] = await Promise.all([\n readIntegrationFile(configPath),\n discoverProjectValidationCheck({\n appRoot,\n timeoutMs: DEFAULT_AGENT_LIMITS.checkTimeoutMs,\n }),\n ]);\n const trustedFastModeAvailable = discoveredCheck !== undefined;\n const nextContent = transformViteConfig(\n configPath,\n configSource,\n trustedFastModeAvailable,\n );\n const change = createIntegrationFileChange(\n appRoot,\n configPath,\n nextContent,\n configSource,\n );\n\n return Object.freeze({\n appRoot,\n changes: Object.freeze(change === undefined ? [] : [change]),\n trustedFastModeAvailable,\n });\n}\n\nexport async function applyViteIntegrationPlan(\n plan: ViteIntegrationPlan,\n): Promise<void> {\n await applyIntegrationPlan(plan);\n}\n\nexport async function checkViteIntegration(\n directory = process.cwd(),\n): Promise<ViteIntegrationCheck> {\n try {\n const plan = await planViteIntegration(directory);\n const issues = plan.changes.map(\n (change) => `INTEGRATION_REQUIRED:${change.relativePath}`,\n );\n return Object.freeze({\n appRoot: plan.appRoot,\n issues: Object.freeze(issues),\n ok: issues.length === 0,\n trustedFastModeAvailable: plan.trustedFastModeAvailable,\n });\n } catch (error: unknown) {\n return Object.freeze({\n appRoot: path.resolve(directory),\n issues: Object.freeze([\n error instanceof Error ? error.message : \"SpotPatch integration check failed.\",\n ]),\n ok: false,\n trustedFastModeAvailable: false,\n });\n }\n}\n","import { spawn } from \"node:child_process\";\nimport { access, readFile } from \"node:fs/promises\";\nimport path from \"node:path\";\n\nexport type SupportedPackageManager = \"npm\" | \"pnpm\";\n\ninterface ApplicationManifest {\n readonly packageManager?: unknown;\n}\n\nexport interface InstallCommand {\n readonly arguments: readonly string[];\n readonly executable: string;\n}\n\nconst VERSION_PATTERN = /^\\d+\\.\\d+\\.\\d+(?:-[0-9A-Za-z.-]+)?$/u;\n\ninterface AdapterManifest {\n readonly version?: unknown;\n}\n\nasync function pathExists(absolutePath: string): Promise<boolean> {\n try {\n await access(absolutePath);\n return true;\n } catch (error: unknown) {\n if (\n error instanceof Error &&\n \"code\" in error &&\n (error.code === \"ENOENT\" || error.code === \"ENOTDIR\")\n ) {\n return false;\n }\n\n throw error;\n }\n}\n\nexport async function detectPackageManager(\n appRoot = process.cwd(),\n userAgent = process.env.npm_config_user_agent ?? \"\",\n): Promise<SupportedPackageManager> {\n const manifestPath = path.join(appRoot, \"package.json\");\n const manifest = JSON.parse(\n await readFile(manifestPath, \"utf8\"),\n ) as ApplicationManifest;\n const declared = manifest.packageManager;\n\n if (typeof declared === \"string\") {\n const name = declared.split(\"@\", 1)[0];\n\n if (name === \"pnpm\" || name === \"npm\") {\n return name;\n }\n\n throw new Error(\n `SpotPatch setup supports npm and pnpm projects; package.json declares ${declared}.`,\n );\n }\n\n const [hasPnpmLock, hasNpmLock] = await Promise.all([\n pathExists(path.join(appRoot, \"pnpm-lock.yaml\")),\n pathExists(path.join(appRoot, \"package-lock.json\")),\n ]);\n\n if (hasPnpmLock !== hasNpmLock) {\n return hasPnpmLock ? \"pnpm\" : \"npm\";\n }\n\n if (hasPnpmLock && hasNpmLock) {\n throw new Error(\n \"SpotPatch setup found both pnpm-lock.yaml and package-lock.json; remove the stale lockfile or run installation and init separately.\",\n );\n }\n\n if (userAgent.startsWith(\"pnpm/\")) {\n return \"pnpm\";\n }\n\n if (userAgent.startsWith(\"npm/\")) {\n return \"npm\";\n }\n\n throw new Error(\n \"SpotPatch setup could not determine npm or pnpm; run installation and init separately.\",\n );\n}\n\nexport function createInstallCommand(\n packageManager: SupportedPackageManager,\n version: string,\n platform = process.platform,\n): InstallCommand {\n if (!VERSION_PATTERN.test(version)) {\n throw new Error(\"SpotPatch setup could not determine its package version.\");\n }\n\n const packageSpecifier = `@spotpatch/vite@${version}`;\n\n return Object.freeze({\n executable: platform === \"win32\" ? `${packageManager}.cmd` : packageManager,\n arguments: Object.freeze(\n packageManager === \"pnpm\"\n ? [\"add\", \"-D\", packageSpecifier]\n : [\"install\", \"--save-dev\", packageSpecifier],\n ),\n });\n}\n\nexport async function readCurrentAdapterVersion(): Promise<string> {\n const manifest = JSON.parse(\n await readFile(new URL(\"../package.json\", import.meta.url), \"utf8\"),\n ) as AdapterManifest;\n const version = manifest.version;\n\n if (typeof version !== \"string\" || !VERSION_PATTERN.test(version)) {\n throw new Error(\"SpotPatch setup could not determine its package version.\");\n }\n\n return version;\n}\n\nexport async function installCurrentAdapter(\n packageManager: SupportedPackageManager,\n appRoot = process.cwd(),\n): Promise<void> {\n const version = await readCurrentAdapterVersion();\n const command = createInstallCommand(packageManager, version);\n\n process.stdout.write(\n `[spotpatch:vite] installing @spotpatch/vite@${version} with ${packageManager}...\\n`,\n );\n\n await new Promise<void>((resolve, reject) => {\n const child = spawn(command.executable, command.arguments, {\n cwd: appRoot,\n env: process.env,\n shell: false,\n stdio: \"inherit\",\n });\n\n child.once(\"error\", reject);\n child.once(\"exit\", (code, signal) => {\n if (code === 0) {\n resolve();\n return;\n }\n\n reject(\n new Error(\n `SpotPatch setup installation failed (${signal ?? `exit ${String(code)}`}).`,\n ),\n );\n });\n });\n}\n"],"mappings":";;;AAAA,SAAS,YAAAA,iBAAgB;AACzB,SAAS,qBAAqB;AAC9B,OAAOC,WAAU;;;ACFjB,OAAO,UAAU;AAEjB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,4BAA4B;AACrC,SAAS,mBAAmB;AAC5B;AAAA,EACE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AM,IAAI,MAAM,uDAAuD;AAAA,EACzE;AAEA,QAAM,UAAU,MAAM,mBAAmB;AACzC,QAAM,SAAS,MAAM,qBAAqB;AAE1C,MAAI,CAAC,OAAO,IAAI;AACd,eAAW,SAAS,OAAO,QAAQ;AACjC,cAAQ,OAAO,MAAM,oBAAoB,KAAK;AAAA,CAAI;AAAA,IACpD;AAEA,WAAO;AAAA,EACT;AAEA,QAAM,OAAO,OAAO,2BAChB,gCACA;AACJ,UAAQ,OAAO;AAAA,IACb,kDAAkD,OAAO,SAAM,IAAI;AAAA;AAAA,EACrE;AACA,SAAO;AACT;AAEA,eAAe,KAAK,YAAgD;AAClE,QAAM,CAAC,SAAS,GAAG,IAAI,IAAI;AAE3B,MAAI,YAAY,SAAS;AACvB,WAAO,SAAS,IAAI;AAAA,EACtB;AAEA,MAAI,YAAY,QAAQ;AACtB,WAAO,QAAQ,IAAI;AAAA,EACrB;AAEA,MAAI,YAAY,SAAS;AACvB,WAAO,SAAS,IAAI;AAAA,EACtB;AAEA,aAAW;AACX,SAAO;AACT;AAEA,IAAI;AACF,UAAQ,WAAW,MAAM,KAAK,QAAQ,KAAK,MAAM,CAAC,CAAC;AACrD,SAAS,OAAgB;AACvB,UAAQ,OAAO;AAAA,IACb,oBACE,iBAAiB,QAAQ,MAAM,UAAU,qBAC3C;AAAA;AAAA,EACF;AACA,UAAQ,WAAW;AACrB;","names":["readFile","path","returned","path","VERSION_PATTERN","path","readFile"]}
|
|
1
|
+
{"version":3,"sources":["../src/cli.ts","../src/initializer.ts","../src/setup.ts"],"sourcesContent":["import { readFile } from \"node:fs/promises\";\nimport { createRequire } from \"node:module\";\nimport path from \"node:path\";\n\nimport { runSpotPatchBridgeCli } from \"@spotpatch/bridge\";\n\nimport {\n applyViteIntegrationPlan,\n checkViteIntegration,\n planViteIntegration,\n} from \"./initializer.js\";\nimport { detectPackageManager, installCurrentAdapter } from \"./setup.js\";\n\nconst VERSION_PATTERN = /^(\\d+)\\.(\\d+)\\.(\\d+)(?:-[0-9A-Za-z.-]+)?$/u;\n\nfunction writeUsage(): void {\n process.stderr.write(\n \"Usage: spotpatch-vite <setup|init|check|connect|bridge>\\n\" +\n \" setup Install this CLI's exact @spotpatch/vite version, then initialize it.\\n\" +\n \" init Preview and apply safe Vite integration changes.\\n\" +\n \" check Verify the Vite integration without writing files.\\n\" +\n \" connect codex Start the zero-setup Codex Agent connector.\\n\" +\n \" bridge Run the local external-Agent MCP, CLI, or setup commands.\\n\",\n );\n}\n\nasync function inspectViteProject(appRoot = process.cwd()): Promise<string> {\n const resolveFromApplication = createRequire(path.join(appRoot, \"package.json\"));\n let adapterEntry: string;\n let viteManifestPath: string;\n\n try {\n adapterEntry = resolveFromApplication.resolve(\"@spotpatch/vite\");\n viteManifestPath = resolveFromApplication.resolve(\"vite/package.json\");\n } catch (error: unknown) {\n throw new Error(\n \"SpotPatch could not resolve the local @spotpatch/vite and Vite packages.\",\n { cause: error },\n );\n }\n\n if (adapterEntry.length === 0) {\n throw new Error(\"SpotPatch could not resolve the Vite adapter export.\");\n }\n\n const manifest = JSON.parse(await readFile(viteManifestPath, \"utf8\")) as unknown;\n const version =\n typeof manifest === \"object\" &&\n manifest !== null &&\n \"version\" in manifest &&\n typeof manifest.version === \"string\"\n ? manifest.version\n : undefined;\n const match = version === undefined ? null : VERSION_PATTERN.exec(version);\n const major = Number(match?.[1]);\n\n if (\n version === undefined ||\n match === null ||\n !Number.isSafeInteger(major) ||\n major < 5 ||\n major >= 8\n ) {\n throw new Error(\n `SpotPatch Vite requires Vite >=5.0.0 <8.0.0; found ${version ?? \"unknown\"}.`,\n );\n }\n\n return version;\n}\n\nfunction writeTrustedModeStatus(available: boolean): void {\n process.stdout.write(\n available\n ? \"[spotpatch:vite] trusted fast mode is available in the page selector.\\n\"\n : \"[spotpatch:vite] review mode is ready; trusted fast mode needs a local TypeScript project check.\\n\",\n );\n}\n\nasync function runInit(arguments_: readonly string[]): Promise<number> {\n if (arguments_.length !== 0) {\n throw new Error(\"SpotPatch init does not accept positional arguments.\");\n }\n\n await inspectViteProject();\n const plan = await planViteIntegration();\n\n if (plan.changes.length === 0) {\n process.stdout.write(\"[spotpatch:vite] integration is already up to date.\\n\");\n writeTrustedModeStatus(plan.trustedFastModeAvailable);\n return 0;\n }\n\n process.stdout.write(\"[spotpatch:vite] integration preview (resulting files):\\n\");\n\n for (const change of plan.changes) {\n process.stdout.write(`\\n--- ${change.relativePath}\\n${change.nextContent}`);\n\n if (!change.nextContent.endsWith(\"\\n\")) {\n process.stdout.write(\"\\n\");\n }\n }\n\n await applyViteIntegrationPlan(plan);\n process.stdout.write(\n `[spotpatch:vite] updated ${String(plan.changes.length)} integration file(s).\\n`,\n );\n writeTrustedModeStatus(plan.trustedFastModeAvailable);\n\n return 0;\n}\n\nasync function runSetup(arguments_: readonly string[]): Promise<number> {\n if (arguments_.length !== 0) {\n throw new Error(\"SpotPatch setup does not accept positional arguments.\");\n }\n\n const packageManager = await detectPackageManager();\n await installCurrentAdapter(packageManager);\n return runInit([]);\n}\n\nasync function runCheck(arguments_: readonly string[]): Promise<number> {\n if (arguments_.length !== 0) {\n throw new Error(\"SpotPatch check does not accept positional arguments.\");\n }\n\n const version = await inspectViteProject();\n const result = await checkViteIntegration();\n\n if (!result.ok) {\n for (const issue of result.issues) {\n process.stderr.write(`[spotpatch:vite] ${issue}\\n`);\n }\n\n return 1;\n }\n\n const mode = result.trustedFastModeAvailable\n ? \"trusted fast mode available\"\n : \"review mode\";\n process.stdout.write(\n `[spotpatch:vite] integration verified for Vite ${version} · ${mode}.\\n`,\n );\n return 0;\n}\n\nasync function main(arguments_: readonly string[]): Promise<number> {\n const [command, ...rest] = arguments_;\n\n if (command === \"setup\") {\n return runSetup(rest);\n }\n\n if (command === \"init\") {\n return runInit(rest);\n }\n\n if (command === \"check\") {\n return runCheck(rest);\n }\n\n if (command === \"bridge\") {\n return runSpotPatchBridgeCli(rest, { adapter: \"vite\" });\n }\n\n if (command === \"connect\") {\n return runSpotPatchBridgeCli(arguments_, { adapter: \"vite\" });\n }\n\n writeUsage();\n return 1;\n}\n\ntry {\n process.exitCode = await main(process.argv.slice(2));\n} catch (error: unknown) {\n process.stderr.write(\n `[spotpatch:vite] ${\n error instanceof Error ? error.message : \"The command failed.\"\n }\\n`,\n );\n process.exitCode = 1;\n}\n","import path from \"node:path\";\n\nimport {\n applyIntegrationPlan,\n createIntegrationFileChange,\n discoverProjectValidationCheck,\n integrationPathExists,\n readIntegrationFile,\n type IntegrationFileChange,\n} from \"@spotpatch/dev-server\";\nimport { DEFAULT_AGENT_LIMITS } from \"@spotpatch/shared\";\nimport { MagicString } from \"magic-string\";\nimport {\n parseSync,\n Visitor,\n type ArrayExpression,\n type CallExpression,\n type ExportDefaultDeclaration,\n type Expression,\n type ImportDeclaration,\n type ObjectExpression,\n type ObjectProperty,\n type Program,\n type ReturnStatement,\n} from \"oxc-parser\";\n\nconst ADAPTER_PACKAGE_NAME = \"@spotpatch/vite\";\nconst CONFIG_FILE_NAMES = Object.freeze([\n \"vite.config.ts\",\n \"vite.config.mts\",\n \"vite.config.js\",\n \"vite.config.mjs\",\n] as const);\n\nexport interface ViteIntegrationPlan {\n readonly appRoot: string;\n readonly changes: readonly IntegrationFileChange[];\n readonly trustedFastModeAvailable: boolean;\n}\n\nexport interface ViteIntegrationCheck {\n readonly appRoot: string;\n readonly issues: readonly string[];\n readonly ok: boolean;\n readonly trustedFastModeAvailable: boolean;\n}\n\ninterface ParsedModule {\n readonly program: Program;\n readonly source: string;\n}\n\nfunction isParserErrorSeverity(value: unknown): boolean {\n return value === \"Error\";\n}\n\nfunction parseModule(absolutePath: string, source: string): ParsedModule {\n const result = parseSync(absolutePath, source, {\n sourceType: \"module\",\n showSemanticErrors: true,\n });\n const error = result.errors.find((entry) => isParserErrorSeverity(entry.severity));\n\n if (error !== undefined) {\n throw new SyntaxError(\n `SpotPatch could not safely parse ${path.basename(absolutePath)} (${error.message}).`,\n );\n }\n\n return Object.freeze({ program: result.program, source });\n}\n\nfunction importsOf(program: Program): readonly ImportDeclaration[] {\n return program.body.filter(\n (statement): statement is ImportDeclaration =>\n statement.type === \"ImportDeclaration\",\n );\n}\n\nfunction importInsertionOffset(program: Program): number {\n const lastImport = importsOf(program).at(-1);\n\n if (lastImport !== undefined) {\n return lastImport.end;\n }\n\n const directives = program.body.filter(\n (statement) =>\n statement.type === \"ExpressionStatement\" &&\n typeof statement.directive === \"string\",\n );\n return directives.at(-1)?.end ?? program.hashbang?.end ?? 0;\n}\n\nfunction insertStaticImport(\n magicString: MagicString,\n program: Program,\n statement: string,\n): void {\n const offset = importInsertionOffset(program);\n\n if (offset === 0) {\n magicString.prepend(`${statement}\\n`);\n return;\n }\n\n magicString.appendRight(offset, `\\n${statement}`);\n}\n\nfunction importQuote(source: string, program: Program): '\"' | \"'\" {\n const firstImport = importsOf(program)[0];\n\n if (firstImport !== undefined) {\n const quote = source[firstImport.source.start];\n\n if (quote === '\"' || quote === \"'\") {\n return quote;\n }\n }\n\n return '\"';\n}\n\nfunction collectIdentifierNames(program: Program): ReadonlySet<string> {\n const names = new Set<string>();\n new Visitor({\n Identifier(node) {\n names.add(node.name);\n },\n }).visit(program);\n return names;\n}\n\nfunction choosePluginName(program: Program): string {\n const names = collectIdentifierNames(program);\n let suffix = 0;\n let candidate = \"spotPatch\";\n\n while (names.has(candidate)) {\n suffix += 1;\n candidate = `spotPatch${String(suffix)}`;\n }\n\n return candidate;\n}\n\nfunction importedPluginName(program: Program): string | undefined {\n const adapterImports = importsOf(program).filter(\n (statement) => statement.source.value === ADAPTER_PACKAGE_NAME,\n );\n\n if (adapterImports.length > 1) {\n throw new Error(\"SpotPatch init found duplicate @spotpatch/vite imports.\");\n }\n\n const adapterImport = adapterImports[0];\n\n if (adapterImport === undefined) {\n return undefined;\n }\n\n const plugin = adapterImport.specifiers.find(\n (specifier) =>\n specifier.type === \"ImportSpecifier\" &&\n specifier.imported.type === \"Identifier\" &&\n specifier.imported.name === \"spotPatch\" &&\n specifier.importKind !== \"type\",\n );\n\n if (plugin === undefined) {\n throw new Error(\n \"SpotPatch init cannot safely merge the existing @spotpatch/vite import.\",\n );\n }\n\n return plugin.local.name;\n}\n\nfunction unwrapExpression(expression: Expression): Expression {\n let current = expression;\n\n while (\n current.type === \"ParenthesizedExpression\" ||\n current.type === \"TSAsExpression\" ||\n current.type === \"TSSatisfiesExpression\" ||\n current.type === \"TSTypeAssertion\" ||\n current.type === \"TSNonNullExpression\"\n ) {\n current = current.expression;\n }\n\n return current;\n}\n\nfunction findDefaultExport(program: Program): ExportDefaultDeclaration {\n const exports = program.body.filter(\n (statement): statement is ExportDefaultDeclaration =>\n statement.type === \"ExportDefaultDeclaration\",\n );\n\n if (exports.length !== 1 || exports[0] === undefined) {\n throw new Error(\n \"SpotPatch init requires exactly one ESM default export in vite.config.\",\n );\n }\n\n return exports[0];\n}\n\nfunction findVariableInitializer(\n program: Program,\n name: string,\n): Expression | undefined {\n for (const statement of program.body) {\n if (statement.type !== \"VariableDeclaration\") {\n continue;\n }\n\n for (const declaration of statement.declarations) {\n if (\n declaration.id.type === \"Identifier\" &&\n declaration.id.name === name &&\n declaration.init !== null\n ) {\n return declaration.init;\n }\n }\n }\n\n return undefined;\n}\n\nfunction resolveConfigExpression(program: Program): Expression {\n const exported = findDefaultExport(program).declaration;\n\n if (\n exported.type === \"FunctionDeclaration\" ||\n exported.type === \"ClassDeclaration\" ||\n exported.type === \"TSInterfaceDeclaration\"\n ) {\n throw new Error(\n \"SpotPatch init requires vite.config to export a configuration expression.\",\n );\n }\n\n const expression = unwrapExpression(exported);\n const resolved =\n expression.type === \"Identifier\"\n ? findVariableInitializer(program, expression.name)\n : expression;\n\n if (resolved === undefined) {\n throw new Error(\"SpotPatch init could not resolve the vite.config export.\");\n }\n\n return unwrapExpression(resolved);\n}\n\nfunction resolveFactoryConfigObject(\n expression: Expression,\n): ObjectExpression | undefined {\n const factory = unwrapExpression(expression);\n\n if (\n factory.type !== \"ArrowFunctionExpression\" &&\n factory.type !== \"FunctionExpression\"\n ) {\n return undefined;\n }\n\n if (factory.body === null) {\n throw new Error(\n \"SpotPatch init cannot use a defineConfig callback without a body.\",\n );\n }\n\n if (factory.body.type !== \"BlockStatement\") {\n const returned = unwrapExpression(factory.body);\n return returned.type === \"ObjectExpression\" ? returned : undefined;\n }\n\n const returns: ReturnStatement[] = [];\n new Visitor({\n ReturnStatement(statement) {\n returns.push(statement);\n },\n }).visit({\n type: \"Program\",\n body: factory.body.body,\n sourceType: \"module\",\n hashbang: null,\n start: factory.body.start,\n end: factory.body.end,\n });\n\n const onlyReturn = returns.length === 1 ? returns[0] : undefined;\n\n if (onlyReturn?.argument == null) {\n throw new Error(\n \"SpotPatch init requires a defineConfig callback with exactly one top-level object return.\",\n );\n }\n\n const returned = unwrapExpression(onlyReturn.argument);\n\n if (returned.type !== \"ObjectExpression\") {\n throw new Error(\n \"SpotPatch init requires the defineConfig callback to return a configuration object directly.\",\n );\n }\n\n return returned;\n}\n\nfunction resolveConfigObject(program: Program): ObjectExpression {\n const expression = resolveConfigExpression(program);\n\n if (expression.type === \"ObjectExpression\") {\n return expression;\n }\n\n if (expression.type === \"CallExpression\") {\n const callee = unwrapExpression(expression.callee);\n const argument = expression.arguments[0];\n\n if (\n callee.type === \"Identifier\" &&\n callee.name === \"defineConfig\" &&\n expression.arguments.length === 1 &&\n argument !== undefined &&\n argument.type !== \"SpreadElement\"\n ) {\n const value = unwrapExpression(argument);\n\n if (value.type === \"ObjectExpression\") {\n return value;\n }\n\n const callbackObject = resolveFactoryConfigObject(value);\n\n if (callbackObject !== undefined) {\n return callbackObject;\n }\n }\n }\n\n throw new Error(\n \"SpotPatch init supports a configuration object or an object-returning callback passed to defineConfig.\",\n );\n}\n\nfunction propertyName(property: ObjectProperty): string | undefined {\n if (property.computed) {\n return undefined;\n }\n\n if (property.key.type === \"Identifier\") {\n return property.key.name;\n }\n\n if (property.key.type === \"Literal\" && typeof property.key.value === \"string\") {\n return property.key.value;\n }\n\n return undefined;\n}\n\nfunction findProperty(\n object: ObjectExpression,\n name: string,\n): ObjectProperty | undefined {\n const matches = object.properties.filter(\n (property): property is ObjectProperty =>\n property.type === \"Property\" && propertyName(property) === name,\n );\n\n if (matches.length > 1) {\n throw new Error(`SpotPatch init found duplicate ${name} properties.`);\n }\n\n return matches[0];\n}\n\nfunction lineIndentAt(source: string, offset: number): string {\n const lineStart = source.lastIndexOf(\"\\n\", Math.max(0, offset - 1)) + 1;\n return /^[\\t ]*/u.exec(source.slice(lineStart, offset))?.[0] ?? \"\";\n}\n\nfunction childIndent(source: string, object: ObjectExpression): string {\n const first = object.properties[0];\n\n if (first !== undefined) {\n return lineIndentAt(source, first.start);\n }\n\n return `${lineIndentAt(source, object.start)} `;\n}\n\nfunction initializedPluginCall(pluginName: string, trustedFastMode: boolean): string {\n const options = [\n \"dataFlow: {}\",\n ...(trustedFastMode ? [\"trustedFastMode: true\"] : []),\n ];\n return `${pluginName}({ ${options.join(\", \")} })`;\n}\n\nfunction directPluginCalls(\n plugins: ArrayExpression,\n pluginName: string,\n): readonly CallExpression[] {\n return plugins.elements.filter((element): element is CallExpression => {\n if (element?.type !== \"CallExpression\") {\n return false;\n }\n\n const callee = unwrapExpression(element.callee);\n return callee.type === \"Identifier\" && callee.name === pluginName;\n });\n}\n\nfunction enableInitializedOptions(\n magicString: MagicString,\n source: string,\n call: CallExpression,\n trustedFastMode: boolean,\n): void {\n if (call.arguments.length === 0) {\n magicString.overwrite(\n call.start,\n call.end,\n initializedPluginCall(source.slice(call.start, call.callee.end), trustedFastMode),\n );\n return;\n }\n\n const argument = call.arguments[0];\n\n if (\n call.arguments.length !== 1 ||\n argument === undefined ||\n argument.type === \"SpreadElement\"\n ) {\n throw new Error(\"SpotPatch init cannot safely update the spotPatch options.\");\n }\n\n const value = unwrapExpression(argument);\n\n if (value.type !== \"ObjectExpression\") {\n throw new Error(\"SpotPatch init requires spotPatch options to be an object.\");\n }\n\n if (value.properties.some((property) => property.type === \"SpreadElement\")) {\n throw new Error(\n \"SpotPatch init cannot prove dataFlow through spread spotPatch options.\",\n );\n }\n\n const dataFlowProperty = findProperty(value, \"dataFlow\");\n const trustedFastModeProperty = findProperty(value, \"trustedFastMode\");\n const missingProperties: string[] = [];\n\n if (dataFlowProperty === undefined) {\n missingProperties.push(\"dataFlow: {}\");\n } else {\n const dataFlowValue = unwrapExpression(dataFlowProperty.value);\n\n if (dataFlowValue.type === \"Literal\" && dataFlowValue.value === false) {\n magicString.overwrite(dataFlowValue.start, dataFlowValue.end, \"{}\");\n } else if (dataFlowValue.type !== \"ObjectExpression\") {\n throw new Error(\n \"SpotPatch init requires dataFlow to be false or an options object.\",\n );\n }\n }\n\n if (trustedFastMode && trustedFastModeProperty === undefined) {\n missingProperties.push(\"trustedFastMode: true\");\n } else if (trustedFastModeProperty !== undefined) {\n const propertyValue = unwrapExpression(trustedFastModeProperty.value);\n\n if (propertyValue.type !== \"Literal\" || typeof propertyValue.value !== \"boolean\") {\n throw new Error(\n \"SpotPatch init requires trustedFastMode to be a boolean literal.\",\n );\n }\n\n if (trustedFastMode && !propertyValue.value) {\n magicString.overwrite(propertyValue.start, propertyValue.end, \"true\");\n }\n }\n\n if (missingProperties.length === 0) return;\n\n const indent = childIndent(source, value);\n\n if (value.properties.length === 0) {\n magicString.appendLeft(value.end - 1, ` ${missingProperties.join(\", \")} `);\n } else {\n magicString.appendLeft(\n value.properties[0]?.start ?? value.end - 1,\n `${missingProperties.join(`,\\n${indent}`)},\\n${indent}`,\n );\n }\n}\n\nfunction addPluginCall(\n magicString: MagicString,\n source: string,\n config: ObjectExpression,\n pluginName: string,\n trustedFastModeAvailable: boolean,\n): void {\n const pluginsProperty = findProperty(config, \"plugins\");\n const call = initializedPluginCall(pluginName, trustedFastModeAvailable);\n\n if (pluginsProperty === undefined) {\n const indent = childIndent(source, config);\n\n if (config.properties.length === 0) {\n magicString.appendLeft(config.end - 1, `\\n${indent}plugins: [${call}],\\n`);\n } else {\n magicString.appendLeft(\n config.properties[0]?.start ?? config.end - 1,\n `plugins: [${call}],\\n${indent}`,\n );\n }\n\n return;\n }\n\n const value = unwrapExpression(pluginsProperty.value);\n\n if (value.type !== \"ArrayExpression\") {\n throw new Error(\"SpotPatch init requires vite.config plugins to be an array.\");\n }\n\n const existing = directPluginCalls(value, pluginName);\n\n if (existing.length > 1) {\n throw new Error(\"SpotPatch init found duplicate spotPatch plugins.\");\n }\n\n if (existing[0] !== undefined) {\n enableInitializedOptions(\n magicString,\n source,\n existing[0],\n trustedFastModeAvailable,\n );\n\n return;\n }\n\n const first = value.elements.find((element) => element !== null);\n\n if (first === undefined) {\n magicString.appendLeft(value.end - 1, call);\n } else if (!source.slice(value.start, first.start).includes(\"\\n\")) {\n magicString.appendLeft(first.start, `${call}, `);\n } else {\n magicString.appendLeft(\n first.start,\n `${call},\\n${lineIndentAt(source, first.start)}`,\n );\n }\n}\n\nfunction transformViteConfig(\n absolutePath: string,\n source: string,\n trustedFastModeAvailable: boolean,\n): string {\n const { program } = parseModule(absolutePath, source);\n const config = resolveConfigObject(program);\n const existingPluginName = importedPluginName(program);\n const pluginName = existingPluginName ?? choosePluginName(program);\n const magicString = new MagicString(source);\n\n if (existingPluginName === undefined) {\n const specifier =\n pluginName === \"spotPatch\" ? \"spotPatch\" : `spotPatch as ${pluginName}`;\n const quote = importQuote(source, program);\n insertStaticImport(\n magicString,\n program,\n `import { ${specifier} } from ${quote}${ADAPTER_PACKAGE_NAME}${quote};`,\n );\n }\n\n addPluginCall(magicString, source, config, pluginName, trustedFastModeAvailable);\n return magicString.toString();\n}\n\nasync function findViteConfig(appRoot: string): Promise<string> {\n const candidates = (\n await Promise.all(\n CONFIG_FILE_NAMES.map(async (name) => {\n const absolutePath = path.join(appRoot, name);\n return (await integrationPathExists(absolutePath)) ? absolutePath : undefined;\n }),\n )\n ).filter((value): value is string => value !== undefined);\n\n if (candidates.length !== 1 || candidates[0] === undefined) {\n throw new Error(\"SpotPatch init requires exactly one supported vite.config file.\");\n }\n\n return candidates[0];\n}\n\nexport async function planViteIntegration(\n directory = process.cwd(),\n): Promise<ViteIntegrationPlan> {\n const appRoot = path.resolve(directory);\n const configPath = await findViteConfig(appRoot);\n const [configSource, discoveredCheck] = await Promise.all([\n readIntegrationFile(configPath),\n discoverProjectValidationCheck({\n appRoot,\n timeoutMs: DEFAULT_AGENT_LIMITS.checkTimeoutMs,\n }),\n ]);\n const trustedFastModeAvailable = discoveredCheck !== undefined;\n const nextContent = transformViteConfig(\n configPath,\n configSource,\n trustedFastModeAvailable,\n );\n const change = createIntegrationFileChange(\n appRoot,\n configPath,\n nextContent,\n configSource,\n );\n\n return Object.freeze({\n appRoot,\n changes: Object.freeze(change === undefined ? [] : [change]),\n trustedFastModeAvailable,\n });\n}\n\nexport async function applyViteIntegrationPlan(\n plan: ViteIntegrationPlan,\n): Promise<void> {\n await applyIntegrationPlan(plan);\n}\n\nexport async function checkViteIntegration(\n directory = process.cwd(),\n): Promise<ViteIntegrationCheck> {\n try {\n const plan = await planViteIntegration(directory);\n const issues = plan.changes.map(\n (change) => `INTEGRATION_REQUIRED:${change.relativePath}`,\n );\n return Object.freeze({\n appRoot: plan.appRoot,\n issues: Object.freeze(issues),\n ok: issues.length === 0,\n trustedFastModeAvailable: plan.trustedFastModeAvailable,\n });\n } catch (error: unknown) {\n return Object.freeze({\n appRoot: path.resolve(directory),\n issues: Object.freeze([\n error instanceof Error ? error.message : \"SpotPatch integration check failed.\",\n ]),\n ok: false,\n trustedFastModeAvailable: false,\n });\n }\n}\n","import { spawn } from \"node:child_process\";\nimport { access, readFile } from \"node:fs/promises\";\nimport path from \"node:path\";\n\nexport type SupportedPackageManager = \"npm\" | \"pnpm\";\n\ninterface ApplicationManifest {\n readonly packageManager?: unknown;\n}\n\nexport interface InstallCommand {\n readonly arguments: readonly string[];\n readonly executable: string;\n}\n\nconst VERSION_PATTERN = /^\\d+\\.\\d+\\.\\d+(?:-[0-9A-Za-z.-]+)?$/u;\n\ninterface AdapterManifest {\n readonly version?: unknown;\n}\n\nasync function pathExists(absolutePath: string): Promise<boolean> {\n try {\n await access(absolutePath);\n return true;\n } catch (error: unknown) {\n if (\n error instanceof Error &&\n \"code\" in error &&\n (error.code === \"ENOENT\" || error.code === \"ENOTDIR\")\n ) {\n return false;\n }\n\n throw error;\n }\n}\n\nexport async function detectPackageManager(\n appRoot = process.cwd(),\n userAgent = process.env.npm_config_user_agent ?? \"\",\n): Promise<SupportedPackageManager> {\n const manifestPath = path.join(appRoot, \"package.json\");\n const manifest = JSON.parse(\n await readFile(manifestPath, \"utf8\"),\n ) as ApplicationManifest;\n const declared = manifest.packageManager;\n\n if (typeof declared === \"string\") {\n const name = declared.split(\"@\", 1)[0];\n\n if (name === \"pnpm\" || name === \"npm\") {\n return name;\n }\n\n throw new Error(\n `SpotPatch setup supports npm and pnpm projects; package.json declares ${declared}.`,\n );\n }\n\n const [hasPnpmLock, hasNpmLock] = await Promise.all([\n pathExists(path.join(appRoot, \"pnpm-lock.yaml\")),\n pathExists(path.join(appRoot, \"package-lock.json\")),\n ]);\n\n if (hasPnpmLock !== hasNpmLock) {\n return hasPnpmLock ? \"pnpm\" : \"npm\";\n }\n\n if (hasPnpmLock && hasNpmLock) {\n throw new Error(\n \"SpotPatch setup found both pnpm-lock.yaml and package-lock.json; remove the stale lockfile or run installation and init separately.\",\n );\n }\n\n if (userAgent.startsWith(\"pnpm/\")) {\n return \"pnpm\";\n }\n\n if (userAgent.startsWith(\"npm/\")) {\n return \"npm\";\n }\n\n throw new Error(\n \"SpotPatch setup could not determine npm or pnpm; run installation and init separately.\",\n );\n}\n\nexport function createInstallCommand(\n packageManager: SupportedPackageManager,\n version: string,\n platform = process.platform,\n): InstallCommand {\n if (!VERSION_PATTERN.test(version)) {\n throw new Error(\"SpotPatch setup could not determine its package version.\");\n }\n\n const packageSpecifier = `@spotpatch/vite@${version}`;\n\n return Object.freeze({\n executable: platform === \"win32\" ? `${packageManager}.cmd` : packageManager,\n arguments: Object.freeze(\n packageManager === \"pnpm\"\n ? [\"add\", \"-D\", packageSpecifier]\n : [\"install\", \"--save-dev\", packageSpecifier],\n ),\n });\n}\n\nexport async function readCurrentAdapterVersion(): Promise<string> {\n const manifest = JSON.parse(\n await readFile(new URL(\"../package.json\", import.meta.url), \"utf8\"),\n ) as AdapterManifest;\n const version = manifest.version;\n\n if (typeof version !== \"string\" || !VERSION_PATTERN.test(version)) {\n throw new Error(\"SpotPatch setup could not determine its package version.\");\n }\n\n return version;\n}\n\nexport async function installCurrentAdapter(\n packageManager: SupportedPackageManager,\n appRoot = process.cwd(),\n): Promise<void> {\n const version = await readCurrentAdapterVersion();\n const command = createInstallCommand(packageManager, version);\n\n process.stdout.write(\n `[spotpatch:vite] installing @spotpatch/vite@${version} with ${packageManager}...\\n`,\n );\n\n await new Promise<void>((resolve, reject) => {\n const child = spawn(command.executable, command.arguments, {\n cwd: appRoot,\n env: process.env,\n shell: false,\n stdio: \"inherit\",\n });\n\n child.once(\"error\", reject);\n child.once(\"exit\", (code, signal) => {\n if (code === 0) {\n resolve();\n return;\n }\n\n reject(\n new Error(\n `SpotPatch setup installation failed (${signal ?? `exit ${String(code)}`}).`,\n ),\n );\n });\n });\n}\n"],"mappings":";;;AAAA,SAAS,YAAAA,iBAAgB;AACzB,SAAS,qBAAqB;AAC9B,OAAOC,WAAU;AAEjB,SAAS,6BAA6B;;;ACJtC,OAAO,UAAU;AAEjB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,4BAA4B;AACrC,SAAS,mBAAmB;AAC5B;AAAA,EACE;AAAA,EACA;AAAA,OAUK;AAEP,IAAM,uBAAuB;AAC7B,IAAM,oBAAoB,OAAO,OAAO;AAAA,EACtC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAU;AAoBV,SAAS,sBAAsB,OAAyB;AACtD,SAAO,UAAU;AACnB;AAEA,SAAS,YAAY,cAAsB,QAA8B;AACvE,QAAM,SAAS,UAAU,cAAc,QAAQ;A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AM,OAAO,OAAO,2BAChB,gCACA;AACJ,UAAQ,OAAO;AAAA,IACb,kDAAkD,OAAO,SAAM,IAAI;AAAA;AAAA,EACrE;AACA,SAAO;AACT;AAEA,eAAe,KAAK,YAAgD;AAClE,QAAM,CAAC,SAAS,GAAG,IAAI,IAAI;AAE3B,MAAI,YAAY,SAAS;AACvB,WAAO,SAAS,IAAI;AAAA,EACtB;AAEA,MAAI,YAAY,QAAQ;AACtB,WAAO,QAAQ,IAAI;AAAA,EACrB;AAEA,MAAI,YAAY,SAAS;AACvB,WAAO,SAAS,IAAI;AAAA,EACtB;AAEA,MAAI,YAAY,UAAU;AACxB,WAAO,sBAAsB,MAAM,EAAE,SAAS,OAAO,CAAC;AAAA,EACxD;AAEA,MAAI,YAAY,WAAW;AACzB,WAAO,sBAAsB,YAAY,EAAE,SAAS,OAAO,CAAC;AAAA,EAC9D;AAEA,aAAW;AACX,SAAO;AACT;AAEA,IAAI;AACF,UAAQ,WAAW,MAAM,KAAK,QAAQ,KAAK,MAAM,CAAC,CAAC;AACrD,SAAS,OAAgB;AACvB,UAAQ,OAAO;AAAA,IACb,oBACE,iBAAiB,QAAQ,MAAM,UAAU,qBAC3C;AAAA;AAAA,EACF;AACA,UAAQ,WAAW;AACrB;","names":["readFile","path","returned","path","VERSION_PATTERN","path","readFile"]}
|
package/dist/index.cjs
CHANGED
|
@@ -51,7 +51,7 @@ var import_dev_server = require("@spotpatch/dev-server");
|
|
|
51
51
|
// package.json
|
|
52
52
|
var package_default = {
|
|
53
53
|
name: "@spotpatch/vite",
|
|
54
|
-
version: "1.
|
|
54
|
+
version: "1.10.0",
|
|
55
55
|
description: "Vite development plugin for SpotPatch.",
|
|
56
56
|
license: "MIT",
|
|
57
57
|
repository: {
|
|
@@ -97,11 +97,12 @@ var package_default = {
|
|
|
97
97
|
}
|
|
98
98
|
},
|
|
99
99
|
scripts: {
|
|
100
|
-
build: "tsup src/index.ts --format esm,cjs --dts --sourcemap --clean && tsup --config tsup.cli.config.ts && tsup --config tsup.runtime-client.config.ts && tsup --config tsup.runtime-react-adapter.config.ts && tsup --config tsup.runtime-data-flow-prelude.config.ts && tsup --config tsup.runtime-data-flow-panel.config.ts",
|
|
100
|
+
build: "tsup src/index.ts --format esm,cjs --dts --sourcemap --clean && tsup --config tsup.cli.config.ts && tsup --config tsup.runtime-client.config.ts && tsup --config tsup.runtime-react-adapter.config.ts && tsup --config tsup.runtime-data-flow-prelude.config.ts && tsup --config tsup.runtime-data-flow-panel.config.ts && tsup --config tsup.runtime-external-handoff-panel.config.ts",
|
|
101
101
|
clean: `node --input-type=module -e "import { rmSync } from 'node:fs'; rmSync('dist', { recursive: true, force: true })"`,
|
|
102
102
|
typecheck: "tsc --noEmit -p tsconfig.json"
|
|
103
103
|
},
|
|
104
104
|
dependencies: {
|
|
105
|
+
"@spotpatch/bridge": "workspace:^",
|
|
105
106
|
"@spotpatch/compiler": "workspace:^",
|
|
106
107
|
"@spotpatch/dev-server": "workspace:^",
|
|
107
108
|
"@spotpatch/react-adapter": "workspace:^",
|
|
@@ -177,6 +178,8 @@ var SPOTPATCH_DATA_FLOW_MODULE_ID = "virtual:spotpatch/data-flow-runtime";
|
|
|
177
178
|
var RESOLVED_SPOTPATCH_DATA_FLOW_MODULE_ID = `\0${SPOTPATCH_DATA_FLOW_MODULE_ID}`;
|
|
178
179
|
var SPOTPATCH_DATA_FLOW_PANEL_MODULE_ID = "virtual:spotpatch/data-flow-panel";
|
|
179
180
|
var RESOLVED_SPOTPATCH_DATA_FLOW_PANEL_MODULE_ID = `\0${SPOTPATCH_DATA_FLOW_PANEL_MODULE_ID}`;
|
|
181
|
+
var SPOTPATCH_EXTERNAL_HANDOFF_PANEL_MODULE_ID = "virtual:spotpatch/external-handoff-panel";
|
|
182
|
+
var RESOLVED_SPOTPATCH_EXTERNAL_HANDOFF_PANEL_MODULE_ID = `\0${SPOTPATCH_EXTERNAL_HANDOFF_PANEL_MODULE_ID}`;
|
|
180
183
|
function createDataFlowPreludeModule(input, bundle) {
|
|
181
184
|
return [
|
|
182
185
|
`const __SPOTPATCH_DATA_FLOW_CONFIG__ = ${JSON.stringify(input.context.getOptions().dataFlow)};`,
|
|
@@ -209,6 +212,7 @@ function createClientModule(input, clientBundle, viteVersion) {
|
|
|
209
212
|
dataFlow: (0, import_dev_server.createRuntimeDataFlowConfig)(options.dataFlow),
|
|
210
213
|
debug: options.debug,
|
|
211
214
|
editor: options.editor,
|
|
215
|
+
externalAgent: options.externalAgent,
|
|
212
216
|
framework: "vite",
|
|
213
217
|
frameworkVersion: viteVersion,
|
|
214
218
|
locale: options.locale,
|
|
@@ -221,6 +225,7 @@ function createClientModule(input, clientBundle, viteVersion) {
|
|
|
221
225
|
};
|
|
222
226
|
return [
|
|
223
227
|
...options.dataFlow.enabled ? [`import ${JSON.stringify(SPOTPATCH_DATA_FLOW_PANEL_MODULE_ID)};`] : [],
|
|
228
|
+
...options.externalAgent.enabled ? [`import ${JSON.stringify(SPOTPATCH_EXTERNAL_HANDOFF_PANEL_MODULE_ID)};`] : [],
|
|
224
229
|
`const __SPOTPATCH_BRAND_MARK_CONTENT__ = ${JSON.stringify(BRAND_MARK_CONTENT)};`,
|
|
225
230
|
`const __SPOTPATCH_RUNTIME_CONFIG__ = ${JSON.stringify(runtimeConfig)};`,
|
|
226
231
|
clientBundle
|
|
@@ -231,6 +236,7 @@ function createRuntimeInjectionPlugin(input) {
|
|
|
231
236
|
let clientBundle = input.clientBundle;
|
|
232
237
|
let dataFlowPreludeBundle = input.dataFlowPreludeBundle;
|
|
233
238
|
let dataFlowPanelBundle = input.dataFlowPanelBundle;
|
|
239
|
+
let externalHandoffPanelBundle = input.externalHandoffPanelBundle;
|
|
234
240
|
let viteVersion = import_vite.version;
|
|
235
241
|
return {
|
|
236
242
|
name: "spotpatch:runtime-injection",
|
|
@@ -253,6 +259,9 @@ function createRuntimeInjectionPlugin(input) {
|
|
|
253
259
|
if (id === SPOTPATCH_DATA_FLOW_PANEL_MODULE_ID) {
|
|
254
260
|
return RESOLVED_SPOTPATCH_DATA_FLOW_PANEL_MODULE_ID;
|
|
255
261
|
}
|
|
262
|
+
if (id === SPOTPATCH_EXTERNAL_HANDOFF_PANEL_MODULE_ID) {
|
|
263
|
+
return RESOLVED_SPOTPATCH_EXTERNAL_HANDOFF_PANEL_MODULE_ID;
|
|
264
|
+
}
|
|
256
265
|
return null;
|
|
257
266
|
},
|
|
258
267
|
load(id) {
|
|
@@ -276,6 +285,14 @@ function createRuntimeInjectionPlugin(input) {
|
|
|
276
285
|
dataFlowPanelBundle ??= readRuntimeBundle(root, "runtime-data-flow-panel.js");
|
|
277
286
|
return dataFlowPanelBundle;
|
|
278
287
|
}
|
|
288
|
+
if (id === RESOLVED_SPOTPATCH_EXTERNAL_HANDOFF_PANEL_MODULE_ID) {
|
|
289
|
+
if (!input.context.getOptions().externalAgent.enabled) return null;
|
|
290
|
+
externalHandoffPanelBundle ??= readRuntimeBundle(
|
|
291
|
+
root,
|
|
292
|
+
"runtime-external-handoff-panel.js"
|
|
293
|
+
);
|
|
294
|
+
return externalHandoffPanelBundle;
|
|
295
|
+
}
|
|
279
296
|
return null;
|
|
280
297
|
},
|
|
281
298
|
transformIndexHtml() {
|
|
@@ -310,9 +327,12 @@ var import_node_path2 = __toESM(require("path"), 1);
|
|
|
310
327
|
var import_dev_server2 = require("@spotpatch/dev-server");
|
|
311
328
|
function createServerPlugin(input) {
|
|
312
329
|
let agentManager;
|
|
330
|
+
let externalHandoffService;
|
|
313
331
|
let config;
|
|
314
332
|
const closeResources = async () => {
|
|
315
333
|
input.registry.clear();
|
|
334
|
+
await externalHandoffService?.close();
|
|
335
|
+
externalHandoffService = void 0;
|
|
316
336
|
await agentManager?.close();
|
|
317
337
|
agentManager = void 0;
|
|
318
338
|
};
|
|
@@ -323,7 +343,7 @@ function createServerPlugin(input) {
|
|
|
323
343
|
configResolved(resolvedConfig) {
|
|
324
344
|
config = resolvedConfig;
|
|
325
345
|
},
|
|
326
|
-
configureServer(server) {
|
|
346
|
+
async configureServer(server) {
|
|
327
347
|
if (config === void 0) {
|
|
328
348
|
throw new Error("SpotPatch server initialized before Vite config resolution.");
|
|
329
349
|
}
|
|
@@ -334,9 +354,24 @@ function createServerPlugin(input) {
|
|
|
334
354
|
environment: input.context.getCredentialEnvironment(),
|
|
335
355
|
root
|
|
336
356
|
});
|
|
357
|
+
externalHandoffService = options.externalAgent.enabled ? (0, import_dev_server2.createExternalHandoffService)({
|
|
358
|
+
framework: "vite",
|
|
359
|
+
root,
|
|
360
|
+
sessionId: input.session.id
|
|
361
|
+
}) : void 0;
|
|
362
|
+
if (externalHandoffService !== void 0) {
|
|
363
|
+
try {
|
|
364
|
+
await externalHandoffService.start();
|
|
365
|
+
} catch {
|
|
366
|
+
config.logger.warn(
|
|
367
|
+
"[spotpatch:vite] External Agent handoff is unavailable; core tools remain active."
|
|
368
|
+
);
|
|
369
|
+
}
|
|
370
|
+
}
|
|
337
371
|
server.middlewares.use(
|
|
338
372
|
(0, import_dev_server2.createSpotPatchMiddleware)({
|
|
339
373
|
...agentManager === void 0 ? {} : { agentManager },
|
|
374
|
+
...externalHandoffService === void 0 ? {} : { externalHandoffService },
|
|
340
375
|
options,
|
|
341
376
|
registry: input.registry,
|
|
342
377
|
root,
|