vc-extras 0.0.0-stage → 0.1.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 +70 -2
- package/agents/tester.md +23 -0
- package/install-extras.mjs +134 -0
- package/install-menu.mjs +63 -0
- package/install-skills.mjs +112 -0
- package/package.json +26 -4
- package/plugins/config-ui/index.ts +160 -0
- package/plugins/config-ui/lib/arguments.mjs +24 -0
- package/plugins/config-ui/lib/documents.mjs +67 -0
- package/plugins/config-ui/lib/frontmatter.mjs +91 -0
- package/plugins/config-ui/lib/open.mjs +17 -0
- package/plugins/config-ui/lib/ownership.mjs +99 -0
- package/plugins/config-ui/lib/page.mjs +11 -0
- package/plugins/config-ui/lib/patch.mjs +36 -0
- package/plugins/config-ui/lib/paths.mjs +14 -0
- package/plugins/config-ui/lib/plugin-fields.mjs +86 -0
- package/plugins/config-ui/lib/plugin-validation.mjs +28 -0
- package/plugins/config-ui/lib/redaction.mjs +8 -0
- package/plugins/config-ui/lib/registry.mjs +282 -0
- package/plugins/config-ui/lib/secrets.mjs +45 -0
- package/plugins/config-ui/lib/server.mjs +251 -0
- package/plugins/config-ui/lib/sources.mjs +96 -0
- package/plugins/config-ui/lib/state.mjs +157 -0
- package/plugins/config-ui/lib/themes.mjs +113 -0
- package/plugins/config-ui/lib/writer.mjs +691 -0
- package/plugins/config-ui/package.json +12 -0
- package/plugins/config-ui/project-local-owner.ts +106 -0
- package/plugins/config-ui/web/app.mjs +997 -0
- package/plugins/config-ui/web/index.html +342 -0
- package/plugins/essrj/context.ts +47 -0
- package/plugins/essrj/data.ts +190 -0
- package/plugins/essrj/index.ts +139 -0
- package/plugins/essrj/package.json +12 -0
- package/plugins/essrj/project-local-owner.ts +106 -0
- package/plugins/essrj/render.ts +217 -0
- package/plugins/essrj/types.ts +40 -0
- package/plugins.json +38 -0
- package/skills/animate/LICENSE +21 -0
- package/skills/animate/RECIPES.md +324 -0
- package/skills/animate/SKILL.md +208 -0
- package/skills/animate/UPSTREAM.md +19 -0
- package/skills/animation-performance/LICENSE +21 -0
- package/skills/animation-performance/SKILL.md +223 -0
- package/skills/animation-performance/UPSTREAM.md +19 -0
- package/skills/answer-me-with-html/SKILL.md +174 -0
- package/skills/answer-me-with-html/scripts/am.mjs +12896 -0
- package/skills/apple-design/LICENSE +21 -0
- package/skills/apple-design/SKILL.md +291 -0
- package/skills/apple-design/UPSTREAM.md +19 -0
- package/skills/bad-smell/SKILL.md +44 -0
- package/skills/commit/SKILL.md +90 -0
- package/skills/emil-design-eng/LICENSE +21 -0
- package/skills/emil-design-eng/SKILL.md +677 -0
- package/skills/emil-design-eng/UPSTREAM.md +19 -0
- package/skills/find-the-truth/SKILL.md +38 -0
- package/skills/find-the-truth/references/trace-method.md +48 -0
- package/skills/find-the-truth/references/truth-method.md +39 -0
- package/skills/gestures/LICENSE +21 -0
- package/skills/gestures/SKILL.md +107 -0
- package/skills/gestures/UPSTREAM.md +19 -0
- package/skills/humanizer-zh/LICENSE +21 -0
- package/skills/humanizer-zh/SKILL.md +409 -0
- package/skills/humanizer-zh/UPSTREAM.md +7 -0
- package/skills/impeccable/LICENSE +191 -0
- package/skills/impeccable/NOTICE.md +11 -0
- package/skills/impeccable/SKILL.md +90 -0
- package/skills/impeccable/licenses/modern-screenshot-MIT.txt +9 -0
- package/skills/impeccable/licenses/platform-design-skills-MIT.txt +21 -0
- package/skills/impeccable/reference/adapt.md +318 -0
- package/skills/impeccable/reference/adapt.native.md +58 -0
- package/skills/impeccable/reference/android.md +46 -0
- package/skills/impeccable/reference/animate.md +89 -0
- package/skills/impeccable/reference/audit.md +139 -0
- package/skills/impeccable/reference/audit.native.md +139 -0
- package/skills/impeccable/reference/bolder.md +33 -0
- package/skills/impeccable/reference/clarify.md +94 -0
- package/skills/impeccable/reference/colorize.md +86 -0
- package/skills/impeccable/reference/component-review.md +63 -0
- package/skills/impeccable/reference/craft-floor.md +44 -0
- package/skills/impeccable/reference/craft.md +5 -0
- package/skills/impeccable/reference/critique.md +819 -0
- package/skills/impeccable/reference/degraded/asset-producer.md +42 -0
- package/skills/impeccable/reference/degraded/documenter.md +24 -0
- package/skills/impeccable/reference/degraded/finish-reviewer.md +38 -0
- package/skills/impeccable/reference/degraded/manual-edit-applier.md +93 -0
- package/skills/impeccable/reference/delight.md +70 -0
- package/skills/impeccable/reference/distill.md +111 -0
- package/skills/impeccable/reference/doctor.md +54 -0
- package/skills/impeccable/reference/document.md +416 -0
- package/skills/impeccable/reference/extract.md +69 -0
- package/skills/impeccable/reference/generate.md +101 -0
- package/skills/impeccable/reference/harden.md +362 -0
- package/skills/impeccable/reference/hooks.md +114 -0
- package/skills/impeccable/reference/init.md +131 -0
- package/skills/impeccable/reference/ios.md +51 -0
- package/skills/impeccable/reference/layout.md +84 -0
- package/skills/impeccable/reference/live-setup.md +104 -0
- package/skills/impeccable/reference/live.md +327 -0
- package/skills/impeccable/reference/mode-operate.md +21 -0
- package/skills/impeccable/reference/mode-persuade.md +19 -0
- package/skills/impeccable/reference/mode-read.md +21 -0
- package/skills/impeccable/reference/new-work.md +152 -0
- package/skills/impeccable/reference/onboard.md +234 -0
- package/skills/impeccable/reference/operate.md +61 -0
- package/skills/impeccable/reference/optimize.md +257 -0
- package/skills/impeccable/reference/overdrive.md +127 -0
- package/skills/impeccable/reference/polish.md +105 -0
- package/skills/impeccable/reference/quieter.md +99 -0
- package/skills/impeccable/reference/region-map.md +26 -0
- package/skills/impeccable/reference/routing.md +24 -0
- package/skills/impeccable/reference/shape.md +59 -0
- package/skills/impeccable/reference/typeset.md +90 -0
- package/skills/impeccable/reference/visualize.md +47 -0
- package/skills/impeccable/scripts/VERSION +1 -0
- package/skills/impeccable/scripts/command-metadata.json +98 -0
- package/skills/impeccable/scripts/data/font-index-failures.json +121 -0
- package/skills/impeccable/scripts/data/font-index.json +1 -0
- package/skills/impeccable/scripts/engine-checksums.txt +9 -0
- package/skills/impeccable/scripts/impeccable +249 -0
- package/skills/impeccable/scripts/impeccable.cmd +278 -0
- package/skills/impeccable/scripts/live-browser-dom.js +320 -0
- package/skills/impeccable/scripts/live-browser-ignores.js +246 -0
- package/skills/impeccable/scripts/live-browser-session.js +183 -0
- package/skills/impeccable/scripts/live-browser.js +13862 -0
- package/skills/impeccable/scripts/modern-screenshot.umd.js +14 -0
- package/skills/improve-animations/AUDIT.md +115 -0
- package/skills/improve-animations/LICENSE +21 -0
- package/skills/improve-animations/PLAN-TEMPLATE.md +73 -0
- package/skills/improve-animations/SKILL.md +110 -0
- package/skills/improve-animations/UPSTREAM.md +19 -0
- package/skills/pick-ui-library/LICENSE +21 -0
- package/skills/pick-ui-library/SKILL.md +85 -0
- package/skills/pick-ui-library/UPSTREAM.md +19 -0
- package/skills/review-animations/LICENSE +21 -0
- package/skills/review-animations/SKILL.md +120 -0
- package/skills/review-animations/STANDARDS.md +187 -0
- package/skills/review-animations/UPSTREAM.md +19 -0
- package/skills/test/SKILL.md +29 -0
- package/skills/test/references/test-method.md +60 -0
- package/skills/write-doc/SKILL.md +115 -0
- package/skills/write-doc/examples/result-report.md +53 -0
- package/skills/write-doc/examples/task-summary.md +45 -0
- package/skills/write-doc/references/terminology.md +147 -0
- package/specs/design-demo.md +1102 -0
- package/specs/frontend-immersive.md +28 -0
- package/specs/web-modes/explore.md +31 -0
- package/specs/web-modes/risk.md +15 -0
- package/specs/web-modes/verify.md +16 -0
- package/vc-extras.mjs +78 -0
package/README.md
CHANGED
|
@@ -1,3 +1,71 @@
|
|
|
1
|
-
#
|
|
1
|
+
# vc-extras
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
`vc` 的可选增强。工作流、阶段审批和任务状态仍由 `vc` 管理。三个 Pi 包可各自注册,安装其中一个不会自动安装其余包或任何第三方插件。
|
|
4
|
+
|
|
5
|
+
## 交互安装
|
|
6
|
+
|
|
7
|
+
发布到 npm 后,在终端运行 `npx vc-extras`。当前未发布,可在本仓库根目录用 `npx --offline --yes --package . -- vc-extras` 体验同一个入口(`--offline` 只用于取得本地安装器;勾选第三方插件或 Config UI 后,安装步骤仍可能访问 npm)。也可直接运行 `node ./vc-extras.mjs`。
|
|
8
|
+
|
|
9
|
+
用 **↑/↓** 移动、**空格** 勾选,按 **Enter** 预览,再按一次 **Enter** 安装。默认不勾选任何项目,**Esc** 或 **Ctrl+C** 可在确认前取消。清单统一列出 8 个 Pi 插件(包括 ESSRJ 和 Config UI),另有可单独勾选的用户级 Skills。选插件需要 PATH 上有 `pi`,选 Config UI 还需要 `npm`。如果已有自定义状态栏,请先决定保留哪一套;使用 `vc` 时通常不需要重复选 Jev。
|
|
10
|
+
|
|
11
|
+
- 自带插件复制到 `~/.agents/vc-extras-plugins/<插件名>/`,再由 Pi 注册到用户级配置,不引用 npx 缓存。相同版本内容可重新注册;遇到不同内容不会覆盖,需先注销旧路径并移走旧目录。用 `pi list` 核对实际注册路径。
|
|
12
|
+
- 第三方插件由 `pi install npm:...` 安装到 Pi 管理的位置;只执行勾选的项。若中途失败,已完成的项目保留,未开始的项目不执行。
|
|
13
|
+
- 勾选 Skills 会复制到 `~/.agents/skills/`,默认保留同名目录。希望覆盖时,用 `npx vc-extras install --overwrite` 再勾选 Skills;未发布时对应 `node ./vc-extras.mjs install --overwrite`。两种用户级位置都优先取 `HOME`,否则用系统用户主目录。
|
|
14
|
+
|
|
15
|
+
## 单独安装用户级技能
|
|
16
|
+
|
|
17
|
+
在本仓库根目录执行(Node.js 22.19+):
|
|
18
|
+
|
|
19
|
+
```powershell
|
|
20
|
+
node ./vc-extras.mjs install-skills # 安装缺少的技能,同名目录保留
|
|
21
|
+
node ./vc-extras.mjs install-skills --overwrite # 备份并覆盖同名技能目录
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
命令把清单中的 16 个技能连同各自的参考资料复制到 `~/.agents/skills/`(`~` 优先取 `HOME`,否则取系统用户主目录,与 `vc` 一致)。安装后不依赖当前 checkout。覆盖是**整目录替换,不是合并**:旧目录移到命令输出的 `~/.agents/vc-extras-skill-backups/<批次>/`,包括用户添加的文件。要恢复某个技能,先移走该同名的新目录,再把备份里的原目录移回 `~/.agents/skills/`。不会替换 `vc` 所有权记录中的技能,也不会碰其他技能目录、Pi 设置或项目文件。运行中的 Pi 需重启或 `/reload` 才会重新发现技能。
|
|
25
|
+
|
|
26
|
+
## 注册 Pi 包(按需)
|
|
27
|
+
|
|
28
|
+
在本仓库根目录执行,不必全部注册。插件需要 npm 和 Pi。
|
|
29
|
+
|
|
30
|
+
```powershell
|
|
31
|
+
pi install .
|
|
32
|
+
pi install ./plugins/essrj
|
|
33
|
+
npm --prefix ./plugins/config-ui install --omit=dev --omit=peer
|
|
34
|
+
pi install ./plugins/config-ui
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
- 根包 `vc-extras`:通过 Pi 加载当前 checkout 里的技能和 `Tester` 角色,而不是复制用户级技能;只用用户级技能时不必注册根包。`test` 仍需要用支持包角色发现的 `@tintinweb/pi-subagents` 加载 `Tester`,并按测试环境准备 MCP 工具;`find-the-truth` 需要 `vc` 提供的 `Explorer` 和子代理工具。两份规范及 `web-modes` 提示词是按需读取的素材,不写入项目 `.emma/specs/`。`trace-rationale` 原资料不完整,未注册或分发。
|
|
38
|
+
- `vibe-essrj`:Pi 状态栏,可选读取 `vc` 的工作流状态。不与另一套自定义 footer 同时启用。
|
|
39
|
+
- `vibe-config-ui`:在 Pi 里使用 `/config`。已有同名注册时,先在 Pi 中核对来源,避免两个版本同时加载。保存会影响当前 Pi 用户配置,修改前先看预览。
|
|
40
|
+
|
|
41
|
+
### 升级、移除与旧安装
|
|
42
|
+
|
|
43
|
+
- **升级**:更新当初注册的同一个 checkout;`pi update` 不会更新本地路径。若装了 Config UI,在该 checkout 重跑 `npm --prefix ./plugins/config-ui install --omit=dev --omit=peer`,然后重启 Pi 或运行 `/reload`。
|
|
44
|
+
- **移除**:用 `pi list` 确认注册来源,再用 `pi remove <相同来源>` 注销对应的 Pi 包。它不会移除 `install-skills` 复制的用户级技能;要停用这些技能,可将对应目录移出 `~/.agents/skills/`。重启或重载 Pi 后生效。
|
|
45
|
+
- **同名技能**:如果旧 Emma 的技能在 `~/.agents/skills/`,可以用 `install-skills --overwrite` 替换。该命令不改项目级技能或其他目录里的副本;如仍有冲突,查看 Pi 的 `name … collision` 提示,核对实际加载路径。
|
|
46
|
+
|
|
47
|
+
配置页离线模式 `/config --no-server` 会下载补丁。先在 Pi 里运行 `/config apply "<下载文件的完整路径>" --dry-run` 检查,再去掉 `--dry-run` 应用。重载或关闭会话后,旧在线页面不能继续保存。
|
|
48
|
+
|
|
49
|
+
## 查看插件安装计划
|
|
50
|
+
|
|
51
|
+
```powershell
|
|
52
|
+
node ./vc-extras.mjs plan
|
|
53
|
+
node ./vc-extras.mjs plan essrj config-ui pi-mcp-adapter
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
`plan` 与交互菜单共用 `plugins.json`,只打印命令,不安装、不修改设置。手动执行本地插件的命令时,须从本仓库根目录运行;Config UI 要先安装依赖。手动选择要运行的命令。`pi-claude-code` 与 `pi-cc-extensions` 是不同的 npm 包,不自动迁移两者配置或注销旧包。MCP 服务、Blackhole 压缩策略以及第三方插件权限分别由对应上游配置。
|
|
57
|
+
|
|
58
|
+
`pi-jev-auto-mode` 可以单独安装;如果已使用 `vc`,继续由 `vc` 保持原有默认安装和审查策略,不重复迁移或重写其配置。Jev 的审查不是 `vc` 内建阶段守卫的同义替代。
|
|
59
|
+
|
|
60
|
+
## 开发验证
|
|
61
|
+
|
|
62
|
+
```powershell
|
|
63
|
+
npm install
|
|
64
|
+
npm --prefix ./plugins/config-ui install --omit=dev --omit=peer
|
|
65
|
+
npm test
|
|
66
|
+
npm pack --dry-run
|
|
67
|
+
npm pack ./plugins/essrj --dry-run
|
|
68
|
+
npm pack ./plugins/config-ui --dry-run
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
技能各自保留其附带的 `LICENSE`、`NOTICE` 和参考资料。
|
package/agents/tester.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: Tester
|
|
3
|
+
description: End-to-end testing sub-agent. Executes end-to-end tests (functional and experience-related) for specified features/fixes and outputs a test report containing test items, conclusions, and evidence.
|
|
4
|
+
tools: read, grep, find, ls, bash, write, edit, ext:pi-mcp-adapter/mcp
|
|
5
|
+
thinking: medium
|
|
6
|
+
run_in_background: true
|
|
7
|
+
prompt_mode: replace
|
|
8
|
+
inherit_context: false
|
|
9
|
+
isolation: off
|
|
10
|
+
extensions: [pi-mcp-adapter, pi-jev-auto-mode]
|
|
11
|
+
skills: false
|
|
12
|
+
---
|
|
13
|
+
You are the E2E testing sub-agent: verify the specified feature/fix end-to-end and deliver a test report with conclusions and evidence.
|
|
14
|
+
|
|
15
|
+
## Hard constraints
|
|
16
|
+
|
|
17
|
+
- Two item regimes: functional items get 「Pass / Fail / Blocked」; experience items only record observations, suggestions, and issues — never a pass/fail verdict.
|
|
18
|
+
- Every result must carry evidence (screenshot, actual output, or log) — a screenshot path alone is not evidence.
|
|
19
|
+
- No guessing, no fabrication: mark items that cannot be verified as 「Blocked」 and state what is missing.
|
|
20
|
+
- This verification only: do not solidify regression cases, do not execute Git write operations, do not modify product code or long-lived test cases; temp scripts, logs, and screenshots go to the task artifact directory.
|
|
21
|
+
- Use the test's own process, terminal, browser, or device — never the environment the user is operating; background does not mean non-intrusive. Tests needing mouse, keyboard, or window focus run in an isolated test environment.
|
|
22
|
+
- Real payments, outbound sending, irreversible data operations: obtain explicit authorization first.
|
|
23
|
+
- Testing method and tools are your call; project-level docs override when they specify.
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import * as fs from 'node:fs';
|
|
2
|
+
import { spawnSync } from 'node:child_process';
|
|
3
|
+
import { createHash } from 'node:crypto';
|
|
4
|
+
import { homedir } from 'node:os';
|
|
5
|
+
import { isAbsolute, join } from 'node:path';
|
|
6
|
+
import { fileURLToPath } from 'node:url';
|
|
7
|
+
import { installSkills } from './install-skills.mjs';
|
|
8
|
+
|
|
9
|
+
const catalogue = JSON.parse(fs.readFileSync(new URL('./plugins.json', import.meta.url), 'utf8'));
|
|
10
|
+
export function planPlugins(ids) {
|
|
11
|
+
return (ids.length ? [...new Set(ids)] : Object.keys(catalogue)).map(id => {
|
|
12
|
+
if (!Object.hasOwn(catalogue, id)) throw new Error(`Unknown plugin: ${id}`);
|
|
13
|
+
const { source, note } = catalogue[id];
|
|
14
|
+
return { id, source, note };
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const skills = 'skills';
|
|
19
|
+
export const choices = [
|
|
20
|
+
{ id: skills, label: '用户级 Skills(16 个;保留已有同名技能)' },
|
|
21
|
+
...Object.entries(catalogue).map(([id, { label = id }]) => ({ id, label })),
|
|
22
|
+
];
|
|
23
|
+
|
|
24
|
+
export function installerCommand(name, args, platform = process.platform, env = process.env) {
|
|
25
|
+
if (platform !== 'win32') return { file: name, args };
|
|
26
|
+
// Pi and npm may only expose .cmd shims. Deliberately reject cmd metacharacters,
|
|
27
|
+
// rather than interpolating an arbitrary directory name into a shell command.
|
|
28
|
+
if (![name, ...args].every(arg => !/[\x00-\x1f"%!?&|<>^()]/.test(arg))) {
|
|
29
|
+
throw new Error('无法安全地向 Windows 命令包装器传递该路径或参数');
|
|
30
|
+
}
|
|
31
|
+
const command = `"${name}.cmd ${args.map(arg => `"${arg}"`).join(' ')}"`;
|
|
32
|
+
return { file: env.ComSpec || 'cmd.exe', args: ['/d', '/s', '/v:off', '/c', command], windowsVerbatimArguments: true };
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function run(name, args, cwd) {
|
|
36
|
+
const command = installerCommand(name, args);
|
|
37
|
+
const result = spawnSync(command.file, command.args, { cwd, stdio: 'inherit', windowsVerbatimArguments: command.windowsVerbatimArguments });
|
|
38
|
+
if (result.error) throw result.error;
|
|
39
|
+
if (result.status !== 0) throw new Error(`${name} 执行失败(${result.signal ?? `退出码 ${result.status}`})`);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const stat = path => fs.lstatSync(path, { throwIfNoEntry: false });
|
|
43
|
+
function ensureDirectory(path) {
|
|
44
|
+
try { fs.mkdirSync(path, { mode: 0o700 }); }
|
|
45
|
+
catch (err) { if (err.code !== 'EEXIST') throw err; }
|
|
46
|
+
if (!stat(path)?.isDirectory()) throw new Error(`不是普通目录:${path}`);
|
|
47
|
+
return path;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function readPayload(root, entries) {
|
|
51
|
+
const hash = createHash('sha256');
|
|
52
|
+
const files = [];
|
|
53
|
+
function visit(relative) {
|
|
54
|
+
const path = join(root, relative);
|
|
55
|
+
const info = stat(path);
|
|
56
|
+
if (info?.isDirectory()) {
|
|
57
|
+
for (const entry of fs.readdirSync(path).sort()) visit(`${relative}/${entry}`);
|
|
58
|
+
} else if (info?.isFile()) {
|
|
59
|
+
const bytes = fs.readFileSync(path);
|
|
60
|
+
hash.update(JSON.stringify([relative, bytes.length])).update(bytes);
|
|
61
|
+
files.push({ relative, bytes, mode: info.mode });
|
|
62
|
+
} else throw new Error(`插件文件不存在或不是普通文件:${path}`);
|
|
63
|
+
}
|
|
64
|
+
for (const entry of entries) visit(entry);
|
|
65
|
+
return { files, digest: hash.digest('hex') };
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function prepareLocal({ id, source: location, dependencies }, { home, execute }) {
|
|
69
|
+
const source = fileURLToPath(new URL(`${location}/`, import.meta.url));
|
|
70
|
+
const manifest = JSON.parse(fs.readFileSync(join(source, 'package.json'), 'utf8'));
|
|
71
|
+
// Use exactly what the standalone package ships, never a checkout's node_modules.
|
|
72
|
+
const entries = ['package.json', ...manifest.files.map(entry => entry.replace(/\/$/, ''))];
|
|
73
|
+
if (entries.some(entry => !/^[a-z0-9][a-z0-9._-]*$/i.test(entry))) throw new Error(`无效的插件文件声明:${id}`);
|
|
74
|
+
const payload = readPayload(source, entries);
|
|
75
|
+
const root = ensureDirectory(join(ensureDirectory(join(home, '.agents')), 'vc-extras-plugins'));
|
|
76
|
+
const target = join(root, id);
|
|
77
|
+
const piArgs = ['install', target];
|
|
78
|
+
installerCommand('pi', piArgs); // Validate before copying the payload on Windows.
|
|
79
|
+
if (stat(target)) {
|
|
80
|
+
if (!stat(target)?.isDirectory() || readPayload(target, entries).digest !== payload.digest) {
|
|
81
|
+
throw new Error(`已有不同内容的插件目录,未覆盖:${target}。升级时请先用 pi remove 注销旧路径并移走旧目录,再重装。`);
|
|
82
|
+
}
|
|
83
|
+
} else {
|
|
84
|
+
const stage = fs.mkdtempSync(join(root, '.stage-'));
|
|
85
|
+
try {
|
|
86
|
+
for (const { relative, bytes, mode } of payload.files) {
|
|
87
|
+
const path = join(stage, relative);
|
|
88
|
+
fs.mkdirSync(join(path, '..'), { recursive: true });
|
|
89
|
+
fs.writeFileSync(path, bytes, { flag: 'wx', mode });
|
|
90
|
+
}
|
|
91
|
+
if (dependencies) {
|
|
92
|
+
execute('npm', ['install', '--omit=dev', '--omit=peer', '--ignore-scripts'], stage);
|
|
93
|
+
}
|
|
94
|
+
if (stat(target)) throw new Error(`插件目录已被其他操作创建,未覆盖:${target}`);
|
|
95
|
+
fs.renameSync(stage, target);
|
|
96
|
+
} finally {
|
|
97
|
+
fs.rmSync(stage, { recursive: true, force: true });
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return target;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export function installSelected(ids, {
|
|
104
|
+
home = process.env.HOME || homedir(), execute = run, overwrite = false, output = console.log,
|
|
105
|
+
} = {}) {
|
|
106
|
+
if (!isAbsolute(home)) throw new Error('用户主目录必须是绝对路径');
|
|
107
|
+
home = fs.realpathSync(home);
|
|
108
|
+
const valid = new Set(choices.map(({ id }) => id));
|
|
109
|
+
const selection = [...new Set(ids)];
|
|
110
|
+
for (const id of selection) if (!valid.has(id)) throw new Error(`未知安装项:${id}`);
|
|
111
|
+
if (selection.includes('essrj') && selection.includes('pi-claude-code')) {
|
|
112
|
+
throw new Error('请分开安装 ESSRJ 和 pi-claude-code,并确保只启用一个自定义状态栏。');
|
|
113
|
+
}
|
|
114
|
+
if (selection.some(id => id !== skills)) execute('pi', ['--version'], home);
|
|
115
|
+
const done = [];
|
|
116
|
+
for (const id of selection) {
|
|
117
|
+
try {
|
|
118
|
+
if (id === skills) {
|
|
119
|
+
const result = installSkills({ home, overwrite });
|
|
120
|
+
output(`用户级技能 → ${result.target}(新增 ${result.installed.length}、覆盖 ${result.replaced.length}、跳过 ${result.skipped.length})`);
|
|
121
|
+
if (result.backup) output(`原目录备份:${result.backup}`);
|
|
122
|
+
} else {
|
|
123
|
+
const plugin = { id, ...catalogue[id] };
|
|
124
|
+
const source = plugin.source.startsWith('./') ? prepareLocal(plugin, { home, execute }) : plugin.source;
|
|
125
|
+
execute('pi', ['install', source], home);
|
|
126
|
+
output(`已安装 ${id} → ${source}`);
|
|
127
|
+
}
|
|
128
|
+
done.push(id);
|
|
129
|
+
} catch (err) {
|
|
130
|
+
throw new Error(`安装 ${id} 失败:${err.message}${done.length ? `\n已完成:${done.join(', ')}` : ''}。后续项目未执行。`, { cause: err });
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return done;
|
|
134
|
+
}
|
package/install-menu.mjs
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { emitKeypressEvents } from 'node:readline';
|
|
2
|
+
|
|
3
|
+
// No package is preselected. Ctrl+C, Esc and EOF never commit the selection.
|
|
4
|
+
export function choose(items, { input = process.stdin, terminal = process.stdout } = {}) {
|
|
5
|
+
if (!input.isTTY || !terminal.isTTY || typeof input.setRawMode !== 'function') {
|
|
6
|
+
throw new Error('交互安装需要终端。可用 --help 查看非交互命令。');
|
|
7
|
+
}
|
|
8
|
+
return new Promise(resolve => {
|
|
9
|
+
let position = 0;
|
|
10
|
+
let confirming = false;
|
|
11
|
+
let lines = 0;
|
|
12
|
+
const selected = new Set();
|
|
13
|
+
const wasRaw = input.isRaw;
|
|
14
|
+
const wasPaused = input.isPaused();
|
|
15
|
+
const render = rows => {
|
|
16
|
+
if (lines) terminal.write(`\x1b[${lines}F\x1b[J`);
|
|
17
|
+
terminal.write(rows.join('\n') + '\n');
|
|
18
|
+
lines = rows.length;
|
|
19
|
+
};
|
|
20
|
+
const draw = () => render(confirming ? [
|
|
21
|
+
'确认安装:',
|
|
22
|
+
...items.filter(item => selected.has(item.id)).map(item => ` ${item.label}`),
|
|
23
|
+
'Enter 安装 · Backspace 返回 · Esc 取消',
|
|
24
|
+
] : [
|
|
25
|
+
'选要安装的项目:↑/↓ 移动 · 空格勾选 · Enter 预览 · Esc 退出',
|
|
26
|
+
...items.map(({ id, label }, i) => `${i === position ? '>' : ' '} [${selected.has(id) ? 'x' : ' '}] ${label}`),
|
|
27
|
+
]);
|
|
28
|
+
const done = result => {
|
|
29
|
+
input.off('keypress', onKey);
|
|
30
|
+
input.off('end', cancel);
|
|
31
|
+
input.setRawMode(Boolean(wasRaw));
|
|
32
|
+
if (wasPaused || !wasRaw) input.pause();
|
|
33
|
+
resolve(result);
|
|
34
|
+
};
|
|
35
|
+
const cancel = () => done(null);
|
|
36
|
+
const onKey = (_, key = {}) => {
|
|
37
|
+
if (key.name === 'escape' || (key.ctrl && ['c', 'd'].includes(key.name))) return cancel();
|
|
38
|
+
if (confirming) {
|
|
39
|
+
if (key.name === 'return' || key.name === 'enter') return done(items.filter(item => selected.has(item.id)).map(item => item.id));
|
|
40
|
+
if (key.name === 'backspace') { confirming = false; draw(); }
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
switch (key.name) {
|
|
44
|
+
case 'up': position = (position + items.length - 1) % items.length; break;
|
|
45
|
+
case 'down': position = (position + 1) % items.length; break;
|
|
46
|
+
case 'space': {
|
|
47
|
+
const id = items[position].id;
|
|
48
|
+
if (selected.has(id)) selected.delete(id); else selected.add(id);
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
case 'return': case 'enter': if (selected.size) confirming = true; break;
|
|
52
|
+
default: return;
|
|
53
|
+
}
|
|
54
|
+
draw();
|
|
55
|
+
};
|
|
56
|
+
emitKeypressEvents(input);
|
|
57
|
+
input.setRawMode(true);
|
|
58
|
+
input.on('keypress', onKey);
|
|
59
|
+
input.once('end', cancel);
|
|
60
|
+
input.resume();
|
|
61
|
+
draw();
|
|
62
|
+
});
|
|
63
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import * as fs from 'node:fs';
|
|
2
|
+
import { homedir } from 'node:os';
|
|
3
|
+
import { isAbsolute, join } from 'node:path';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
|
|
6
|
+
const { pi: { skills } } = JSON.parse(fs.readFileSync(new URL('./package.json', import.meta.url), 'utf8'));
|
|
7
|
+
const sourceRoot = fileURLToPath(new URL('./skills/', import.meta.url));
|
|
8
|
+
const stat = path => fs.lstatSync(path, { throwIfNoEntry: false, bigint: true });
|
|
9
|
+
|
|
10
|
+
function directory(path, { create = false } = {}) {
|
|
11
|
+
if (create) {
|
|
12
|
+
try { fs.mkdirSync(path, { mode: 0o700 }); }
|
|
13
|
+
catch (error) { if (error.code !== 'EEXIST') throw error; }
|
|
14
|
+
}
|
|
15
|
+
if (!stat(path)?.isDirectory()) throw new Error(`不是普通目录(不跟随符号链接或目录联接):${path}`);
|
|
16
|
+
return path;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function protectedVcSkills(target) {
|
|
20
|
+
const path = join(target, '.vc-skills.json');
|
|
21
|
+
const info = stat(path);
|
|
22
|
+
if (!info) return new Set();
|
|
23
|
+
if (!info.isFile()) throw new Error(`无法安全读取 vc 技能的所有权记录:${path}`);
|
|
24
|
+
const { files } = JSON.parse(fs.readFileSync(path, 'utf8'));
|
|
25
|
+
if (!files || typeof files !== 'object' || Array.isArray(files)) {
|
|
26
|
+
throw new Error(`无效的 vc 技能所有权记录:${path}`);
|
|
27
|
+
}
|
|
28
|
+
const key = name => process.platform === 'win32' ? name.toLowerCase() : name;
|
|
29
|
+
return new Set(Object.keys(files).map(path => key(path.split('/')[0])));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function installSkills({ overwrite = false, home = process.env.HOME || homedir() } = {}) {
|
|
33
|
+
if (!isAbsolute(home)) throw new Error('用户主目录必须是绝对路径');
|
|
34
|
+
const names = skills.map(dir => {
|
|
35
|
+
const match = /^\.\/skills\/([a-z0-9]+(?:-[a-z0-9]+)*)$/.exec(dir);
|
|
36
|
+
if (!match) throw new Error(`无效的技能声明:${dir}`);
|
|
37
|
+
return match[1];
|
|
38
|
+
});
|
|
39
|
+
if (new Set(names).size !== names.length) throw new Error('存在重复的技能声明');
|
|
40
|
+
|
|
41
|
+
directory(sourceRoot);
|
|
42
|
+
const agents = directory(join(fs.realpathSync(home), '.agents'), { create: true });
|
|
43
|
+
const target = directory(join(agents, 'skills'), { create: true });
|
|
44
|
+
const protectedNames = protectedVcSkills(target);
|
|
45
|
+
const result = { target, backup: null, installed: [], replaced: [], skipped: [] };
|
|
46
|
+
const pending = [];
|
|
47
|
+
for (const name of names) {
|
|
48
|
+
const destination = join(target, name);
|
|
49
|
+
const before = stat(destination);
|
|
50
|
+
if (protectedNames.has(name) || (before && !overwrite)) {
|
|
51
|
+
result.skipped.push({ name, reason: protectedNames.has(name) ? '由 vc 管理' : '已存在' });
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
if (before && !before.isDirectory()) throw new Error(`拒绝覆盖非普通目录:${destination}`);
|
|
55
|
+
pending.push({ name, destination, before });
|
|
56
|
+
}
|
|
57
|
+
if (pending.length === 0) return result;
|
|
58
|
+
|
|
59
|
+
// Copy and validate the complete payload before moving any user files.
|
|
60
|
+
const stage = fs.mkdtempSync(join(agents, '.vc-extras-stage-'));
|
|
61
|
+
try {
|
|
62
|
+
for (const { name } of pending) {
|
|
63
|
+
const source = directory(join(sourceRoot, name));
|
|
64
|
+
if (!stat(join(source, 'SKILL.md'))?.isFile()) throw new Error(`缺少普通 SKILL.md 文件:${source}`);
|
|
65
|
+
fs.cpSync(source, join(stage, name), {
|
|
66
|
+
recursive: true, force: false, errorOnExist: true,
|
|
67
|
+
filter(path) {
|
|
68
|
+
const info = stat(path);
|
|
69
|
+
if (!info || (!info.isDirectory() && !info.isFile())) {
|
|
70
|
+
throw new Error(`技能源只能包含普通文件和目录:${path}`);
|
|
71
|
+
}
|
|
72
|
+
return true;
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
if (pending.some(({ before }) => before)) {
|
|
77
|
+
const root = directory(join(agents, 'vc-extras-skill-backups'), { create: true });
|
|
78
|
+
result.backup = fs.mkdtempSync(join(root, `${new Date().toISOString().replace(/[:.]/g, '-')}-`));
|
|
79
|
+
}
|
|
80
|
+
for (const { name, destination, before } of pending) {
|
|
81
|
+
directory(agents);
|
|
82
|
+
directory(target);
|
|
83
|
+
const current = stat(destination);
|
|
84
|
+
if (before ? (!current?.isDirectory() || current.dev !== before.dev ||
|
|
85
|
+
current.ino !== before.ino || current.ctimeNs !== before.ctimeNs) : current) {
|
|
86
|
+
throw new Error(`安装期间目标发生变化,未替换:${destination}`);
|
|
87
|
+
}
|
|
88
|
+
const saved = before ? join(result.backup, name) : null;
|
|
89
|
+
if (saved) {
|
|
90
|
+
directory(result.backup);
|
|
91
|
+
fs.renameSync(destination, saved);
|
|
92
|
+
}
|
|
93
|
+
try {
|
|
94
|
+
if (stat(destination)) throw new Error(`目标已被其他操作创建,未替换:${destination}`);
|
|
95
|
+
fs.renameSync(join(stage, name), destination);
|
|
96
|
+
} catch (error) {
|
|
97
|
+
if (saved && !stat(destination)) {
|
|
98
|
+
try { fs.renameSync(saved, destination); }
|
|
99
|
+
catch (restoreError) { throw new Error(`${error.message};恢复原目录失败:${restoreError.message}`, { cause: error }); }
|
|
100
|
+
}
|
|
101
|
+
throw error;
|
|
102
|
+
}
|
|
103
|
+
(saved ? result.replaced : result.installed).push(name);
|
|
104
|
+
}
|
|
105
|
+
return result;
|
|
106
|
+
} catch (error) {
|
|
107
|
+
const done = [...result.installed, ...result.replaced];
|
|
108
|
+
throw new Error(`${error.message}${done.length ? `\n已安装或覆盖:${done.join(', ')}` : ''}${result.backup ? `\n备份目录:${result.backup}` : ''}`, { cause: error });
|
|
109
|
+
} finally {
|
|
110
|
+
fs.rmSync(stage, { recursive: true, force: true });
|
|
111
|
+
}
|
|
112
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vc-extras",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Optional skills and companion plugins for the vc Pi workflow",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"keywords": ["pi-package", "agent-skills"],
|
|
8
|
+
"engines": { "node": ">=22.19.0" },
|
|
9
|
+
"bin": { "vc-extras": "./vc-extras.mjs" },
|
|
10
|
+
"scripts": { "test": "node --test" },
|
|
11
|
+
"devDependencies": { "@earendil-works/pi-tui": "1.2.0" },
|
|
12
|
+
"files": [
|
|
13
|
+
"skills/", "agents/", "specs/*.md", "specs/web-modes/", "vc-extras.mjs",
|
|
14
|
+
"install-skills.mjs", "install-extras.mjs", "install-menu.mjs", "plugins.json",
|
|
15
|
+
"plugins/essrj/*.ts", "plugins/essrj/package.json",
|
|
16
|
+
"plugins/config-ui/*.ts", "plugins/config-ui/package.json", "plugins/config-ui/lib/", "plugins/config-ui/web/"
|
|
17
|
+
],
|
|
18
|
+
"pi": {
|
|
19
|
+
"skills": [
|
|
20
|
+
"./skills/animate", "./skills/animation-performance", "./skills/answer-me-with-html",
|
|
21
|
+
"./skills/apple-design", "./skills/bad-smell", "./skills/commit", "./skills/emil-design-eng",
|
|
22
|
+
"./skills/find-the-truth", "./skills/gestures", "./skills/humanizer-zh", "./skills/impeccable",
|
|
23
|
+
"./skills/improve-animations", "./skills/pick-ui-library", "./skills/review-animations",
|
|
24
|
+
"./skills/test", "./skills/write-doc"
|
|
25
|
+
],
|
|
26
|
+
"subagents": { "agents": ["./agents"] }
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
// `/config` — the browser configuration page for Emma's files.
|
|
2
|
+
//
|
|
3
|
+
// Two paths, one writer:
|
|
4
|
+
// /config starts a loopback service, opens the page, and writes on
|
|
5
|
+
// save; the service exits after a save or ten idle minutes.
|
|
6
|
+
// /config --no-server writes the page under <agentDir>/emma-config, nothing else:
|
|
7
|
+
// saving downloads a patch file.
|
|
8
|
+
// /config apply <patch> applies such a patch from the terminal, with --dry-run.
|
|
9
|
+
import * as fs from "node:fs";
|
|
10
|
+
import * as os from "node:os";
|
|
11
|
+
import * as path from "node:path";
|
|
12
|
+
import { fileURLToPath } from "node:url";
|
|
13
|
+
import { shouldYieldToProject } from "./project-local-owner.ts";
|
|
14
|
+
import { resolveAgentDir } from "./lib/paths.mjs";
|
|
15
|
+
import { prepareSources } from "./lib/sources.mjs";
|
|
16
|
+
import { readPatch, applyPatch } from "./lib/patch.mjs";
|
|
17
|
+
import { openBrowser } from "./lib/open.mjs";
|
|
18
|
+
import { startConfigServer, inject } from "./lib/server.mjs";
|
|
19
|
+
import { inlinePage } from "./lib/page.mjs";
|
|
20
|
+
import { readState } from "./lib/state.mjs";
|
|
21
|
+
import { discoverThemes, themeWritten } from "./lib/themes.mjs";
|
|
22
|
+
import { listBackups, restoreBackups } from "./lib/writer.mjs";
|
|
23
|
+
import { parseArguments } from "./lib/arguments.mjs";
|
|
24
|
+
|
|
25
|
+
const PAGE_DIR = path.join(path.dirname(fileURLToPath(import.meta.url)), "web");
|
|
26
|
+
|
|
27
|
+
// Both offline artifacts live under the agent directory, never in the project: a patch
|
|
28
|
+
// can carry a key the user just typed, and a project file is one `git add -A` away from
|
|
29
|
+
// being committed.
|
|
30
|
+
const exportDir = (configContext) => path.join(configContext.agentDir, "emma-config");
|
|
31
|
+
|
|
32
|
+
export default function configUi(pi) {
|
|
33
|
+
let lifetime = new AbortController();
|
|
34
|
+
const servers = new Set();
|
|
35
|
+
pi.on("session_shutdown", () => {
|
|
36
|
+
lifetime.abort();
|
|
37
|
+
for (const server of servers) server.close();
|
|
38
|
+
servers.clear();
|
|
39
|
+
});
|
|
40
|
+
// Pi has determined the trust state by session_start. On current Pi, the
|
|
41
|
+
// registered commands are collected after this event completes.
|
|
42
|
+
pi.on("session_start", (_event, context) => {
|
|
43
|
+
if (lifetime.signal.aborted) lifetime = new AbortController();
|
|
44
|
+
if (shouldYieldToProject(import.meta.url, "./runtime/config-ui/index.ts", context.cwd ?? process.cwd(), context.isProjectTrusted?.() === true)) return;
|
|
45
|
+
pi.registerCommand("config", command);
|
|
46
|
+
});
|
|
47
|
+
const command = {
|
|
48
|
+
description: "在浏览器中编辑 Emma 的配置文件(/config --no-server 仅导出补丁;/config apply <补丁> 应用补丁;/config restore <stamp> 从备份回滚)",
|
|
49
|
+
handler: async (args, context) => {
|
|
50
|
+
const { signal } = lifetime;
|
|
51
|
+
if (signal.aborted) return;
|
|
52
|
+
let argv;
|
|
53
|
+
try { argv = parseArguments(args); }
|
|
54
|
+
catch (error) { context.ui.notify(error.message, "error"); return; }
|
|
55
|
+
const cwd = context.cwd ?? process.cwd();
|
|
56
|
+
// Project-level writes only happen in a trusted project: the files are loaded by
|
|
57
|
+
// the next Pi session with the user's own permissions. A context that cannot
|
|
58
|
+
// answer is treated as untrusted — the guard fails closed.
|
|
59
|
+
const trusted = typeof context.isProjectTrusted === "function" ? context.isProjectTrusted() === true : false;
|
|
60
|
+
const configContext = await prepareSources({ agentDir: resolveAgentDir(), projectRoot: cwd, homeDir: os.homedir(), trusted, modelRegistry: context.modelRegistry });
|
|
61
|
+
// Pi owns theme resolution, so its own list is what the page offers and what a
|
|
62
|
+
// save is checked against — a name built from the directories could differ.
|
|
63
|
+
configContext.knownThemes = context.ui.getAllThemes?.() ?? [];
|
|
64
|
+
if (signal.aborted) return;
|
|
65
|
+
|
|
66
|
+
if (argv[0] === "apply") return applyFromTerminal(argv.slice(1), configContext, context);
|
|
67
|
+
if (argv[0] === "restore") return restoreFromTerminal(argv.slice(1), configContext, context);
|
|
68
|
+
if (argv.includes("--no-server")) return exportOnly(configContext, context);
|
|
69
|
+
|
|
70
|
+
let server;
|
|
71
|
+
try {
|
|
72
|
+
server = await startConfigServer({
|
|
73
|
+
context: configContext,
|
|
74
|
+
pageDir: PAGE_DIR,
|
|
75
|
+
signal,
|
|
76
|
+
onApplied: ({ values, results }) => {
|
|
77
|
+
if (!signal.aborted && themeWritten(results)) applyThemeLive(values?.piTheme, context);
|
|
78
|
+
},
|
|
79
|
+
onClose: () => {
|
|
80
|
+
if (server) servers.delete(server);
|
|
81
|
+
if (!signal.aborted) context.ui.notify("配置页服务已退出", "info");
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
} catch (error) {
|
|
85
|
+
if (signal.aborted) return;
|
|
86
|
+
throw error;
|
|
87
|
+
}
|
|
88
|
+
if (signal.aborted) { server.close(); return; }
|
|
89
|
+
servers.add(server);
|
|
90
|
+
context.ui.notify(`配置页已就绪:${server.url}(保存即写入;空闲 10 分钟或保存 30 秒后自动退出)`, "info");
|
|
91
|
+
await openBrowser(server.url);
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
async function exportOnly(configContext, context) {
|
|
97
|
+
const state = readState({ context: configContext });
|
|
98
|
+
const page = inlinePage(
|
|
99
|
+
fs.readFileSync(path.join(PAGE_DIR, "index.html"), "utf8"),
|
|
100
|
+
fs.readFileSync(path.join(PAGE_DIR, "app.mjs"), "utf8"),
|
|
101
|
+
);
|
|
102
|
+
const file = path.join(exportDir(configContext), "emma-config.html");
|
|
103
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
104
|
+
fs.writeFileSync(file, inject(page, { token: "", origin: "", state, themes: discoverThemes(configContext) }));
|
|
105
|
+
context.ui.notify(`已生成配置页:${file}。导出补丁后,运行 /config apply "<下载文件的完整路径>" --dry-run 检查。`, "info");
|
|
106
|
+
await openBrowser(`file:///${file.replace(/\\/g, "/")}`);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
async function applyFromTerminal(argv, configContext, context) {
|
|
110
|
+
const dryRun = argv.includes("--dry-run");
|
|
111
|
+
const file = argv.filter((item) => !item.startsWith("--"))[0] ?? path.join(exportDir(configContext), "emma-config-patch.json");
|
|
112
|
+
const patch = readPatch(file);
|
|
113
|
+
const applied = applyPatch({ patch, context: configContext, dryRun });
|
|
114
|
+
const lines = applied.results.map((result) => `${result.status} · ${result.path}`).join("\n") || "没有需要写入的变更";
|
|
115
|
+
const skipped = applied.skipped?.length ? `\n跳过(只读):${applied.skipped.map((entry) => entry.label).join(", ")}` : "";
|
|
116
|
+
// A rejected value must say why: otherwise an invalid patch just reports "nothing to write".
|
|
117
|
+
const problems = applied.plan.problems.length
|
|
118
|
+
? `\n被拒:${applied.plan.problems.map((problem) => `${problem.label ?? problem.id}(${problem.reason})`).join("; ")}`
|
|
119
|
+
: "";
|
|
120
|
+
const failure = describeFailure(applied.failure);
|
|
121
|
+
context.ui.notify(`${dryRun ? "[dry-run] " : ""}${lines}${problems}${skipped}${applied.unknown.length ? `\n忽略未知字段:${applied.unknown.join(", ")}` : ""}${failure}`, failure || problems || applied.results.some(result => result.status === "conflict") ? "warning" : "info");
|
|
122
|
+
// A patch applied from the terminal changes settings.json just as a save does.
|
|
123
|
+
if (!dryRun && themeWritten(applied.results)) applyThemeLive(patch.values.piTheme, context);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// Pi keeps its own in-memory theme; writing settings.json alone would leave the running
|
|
127
|
+
// session on the old colors until restart, so the change is pushed through the UI API.
|
|
128
|
+
function applyThemeLive(theme, context) {
|
|
129
|
+
if (!theme) return;
|
|
130
|
+
const result = context.ui.setTheme(theme);
|
|
131
|
+
if (result?.success === false) {
|
|
132
|
+
context.ui.notify(`主题已写入配置,但当前会话未能切换:${result.error ?? "未知原因"}`, "warning");
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
context.ui.notify(`主题已切换:${theme}`, "info");
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// `/config restore` rolls a registry file back to a backup taken before a save. The
|
|
139
|
+
// stamp addresses a directory, never a path: a backup cannot redirect a write.
|
|
140
|
+
async function restoreFromTerminal(argv, configContext, context) {
|
|
141
|
+
const dryRun = argv.includes("--dry-run");
|
|
142
|
+
const stamp = argv.filter((item) => !item.startsWith("--"))[0];
|
|
143
|
+
if (!stamp) {
|
|
144
|
+
const backups = listBackups(configContext);
|
|
145
|
+
const lines = backups.slice(0, 10).map((entry) => `${entry.stamp} · ${entry.files.length} 个文件`).join("\n");
|
|
146
|
+
context.ui.notify(backups.length ? `可回滚的备份:\n${lines}\n用法:/config restore <stamp> [--dry-run]` : "没有可回滚的备份", "info");
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
const restored = restoreBackups({ context: configContext, stamp, dryRun });
|
|
150
|
+
const lines = restored.results.map((result) => `${result.status} · ${result.path}`).join("\n") || `备份 ${stamp} 与当前文件一致,无需回滚`;
|
|
151
|
+
const failure = describeFailure(restored.failure);
|
|
152
|
+
const incomplete = restored.results.some(result => !["planned", "restored"].includes(result.status));
|
|
153
|
+
context.ui.notify(`${dryRun ? "[dry-run] " : ""}${lines}${failure}`, failure || incomplete ? "warning" : "info");
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function describeFailure(failure) {
|
|
157
|
+
if (!failure) return "";
|
|
158
|
+
const recovery = failure.stamp ? `\n恢复记录: ${failure.stamp}` : "";
|
|
159
|
+
return `\n未完成(${failure.phase}): ${failure.message}${recovery}`;
|
|
160
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// Parse command arguments without treating Windows path backslashes as escapes.
|
|
2
|
+
export function parseArguments(input) {
|
|
3
|
+
const args = [];
|
|
4
|
+
let value = "";
|
|
5
|
+
let quote = null;
|
|
6
|
+
let started = false;
|
|
7
|
+
for (const char of String(input ?? "")) {
|
|
8
|
+
if (quote) {
|
|
9
|
+
if (char === quote) quote = null;
|
|
10
|
+
else value += char;
|
|
11
|
+
} else if (char === '"' || char === "'") {
|
|
12
|
+
quote = char;
|
|
13
|
+
started = true;
|
|
14
|
+
} else if (/\s/.test(char)) {
|
|
15
|
+
if (started) { args.push(value); value = ""; started = false; }
|
|
16
|
+
} else {
|
|
17
|
+
value += char;
|
|
18
|
+
started = true;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
if (quote) throw new Error("路径引号未闭合。用法:/config apply \"完整路径\" [--dry-run]");
|
|
22
|
+
if (started) args.push(value);
|
|
23
|
+
return args;
|
|
24
|
+
}
|