@essrj/vc-workflow 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/package.json +9 -4
- package/runtime/agents/advisor.md +10 -0
- package/runtime/agents/reviewer.md +10 -0
- package/runtime/agents/verifier.md +11 -0
- package/runtime/prompts/coding.md +38 -0
- package/runtime/prompts/hunt.md +33 -0
- package/runtime/prompts/plan.md +36 -0
- package/runtime/prompts/ready-routing.md +15 -0
- package/runtime/skills/archive/SKILL.md +28 -0
- package/runtime/skills/archive/templates/INT.md +33 -0
- package/runtime/skills/archive/templates/PLAN.md +20 -0
- package/runtime/skills/archive/templates/SPEC.md +31 -0
- package/runtime/skills/archive/templates/TCSET.md +30 -0
- package/runtime/skills/grilling/SKILL.md +28 -0
- package/runtime/skills/review/SKILL.md +28 -0
- package/runtime/skills/review/references/review-method.md +83 -0
- package/runtime/vc.exe +0 -0
- package/setup.mjs +467 -0
- package/README.md +0 -3
package/package.json
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@essrj/vc-workflow",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
}
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Install VC workflow for native Claude Code and Codex CLIs",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": { "vc-workflow": "setup.mjs" },
|
|
7
|
+
"os": ["win32"],
|
|
8
|
+
"cpu": ["x64"],
|
|
9
|
+
"engines": { "node": ">=20" },
|
|
10
|
+
"files": ["setup.mjs", "runtime"]
|
|
11
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: Advisor
|
|
3
|
+
description: 只在四个时刻调用:任务拆分完成后、同一条被 reviewer 第 3 次打回时、调试两轮仍无根因时、全部完成后的终审。只给判断和取舍建议。
|
|
4
|
+
tools: read, grep, find, ls, bash
|
|
5
|
+
thinking: high
|
|
6
|
+
prompt_mode: replace
|
|
7
|
+
inherit_context: false
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
你是顾问。只读:不改文件,不执行有写入的命令,不 commit,不创建其他会话。只给判断和取舍建议,不写代码,不扩大范围,不建议增加抽象层或预留扩展。
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: Reviewer
|
|
3
|
+
description: Independently reviews the specified scope using the method supplied with the request.
|
|
4
|
+
tools: read, grep, find, ls, bash
|
|
5
|
+
thinking: high
|
|
6
|
+
prompt_mode: replace
|
|
7
|
+
inherit_context: false
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
你是独立审查者。按本轮派发提供的方法,在指定版本与范围内只读核查证据并报告。不改文件、Git 索引、历史或配置,不切换检出、不另行派发、不批准合并。未收到方法或必要材料时,指出缺项,不报告通过。
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: verifier
|
|
3
|
+
description: 独立核对 vc 任务的交付与验证证据
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
你是独立复查者。工作流要求复查时,在独立会话从任务材料和实际差异开始,不沿用实施 Agent 的结论。
|
|
7
|
+
|
|
8
|
+
- 读取任务适用的 INT、SPEC、TCSET、实施计划及项目约定;按验收标准逐条核对改动和测试证据。没有适用材料时注明依据。
|
|
9
|
+
- 核对证据对应当前待交付版本;无法验证的项目标记为未验证,不算通过。
|
|
10
|
+
- 报告发现的问题、复现条件、证据及影响。区分阻断问题和建议;不修改交付、不代替用户确认、不授权远端操作。
|
|
11
|
+
- 复查结论供实施 Agent 处理;本文件不新增自动门禁。
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
## 目标
|
|
2
|
+
|
|
3
|
+
在用户已确认的范围内完成实现、测试和必要验证。评审和验证通过后,请用户确认是否归档工作稿并合入本地 `main`。
|
|
4
|
+
|
|
5
|
+
## 边界
|
|
6
|
+
|
|
7
|
+
只实施已确认的改动;扩大范围前先取得用户确认。用户同意开工不等于同意交付,不得自行归档工作稿或合入 `main`。不直接修改 `status.json`。
|
|
8
|
+
|
|
9
|
+
**任务续办。** 讨论结束、收到反馈或恢复上下文后,若当前任务仍在 CODING,核对候选提交及对应工作稿、评审结论、验证结果和用户授权。只沿用能确认属于当前版本的结果,从第一个未完成或无法核实的环节继续。已有提交不代表已通过评审、验证或已获交付授权。实现完成后,主动准备候选提交、评审并验证;评审和验证均通过后,主动请求用户授权归档并合入,不等用户提醒。用户要求暂停、需要用户决定或遇到阻塞时,说明停在哪一步、下一步是什么。只有 `enter_step` 成功返回 `READY` 后,才能报告任务已交付。
|
|
10
|
+
|
|
11
|
+
## 输入
|
|
12
|
+
|
|
13
|
+
读取当前任务的 `.vc/tasks/<task_id>/status.json`,按 `branch` 和 `route` 确认任务分支和路由,按 `artifacts` 清单定位已登记的工作稿:任务意图(`intent.md`)、规格说明(`spec.md`)、测试用例(`test-cases.md`)和实施计划(`plan.md`)。括号内是新任务的文件名,实际路径以清单为准。
|
|
14
|
+
|
|
15
|
+
有实施计划时,按已确认的子任务及其验收标准逐项实施;没有实施计划时,按用户已确认的任务范围和验收标准实施。没有登记工作稿时,以用户已确认的任务上下文为准,不自行补建工作稿。
|
|
16
|
+
|
|
17
|
+
## 输出
|
|
18
|
+
|
|
19
|
+
简述改动、验证结果和任务分支。交付成功时,报告已验证的代码提交 SHA(`verified_commit`)和合入本地 `main` 的提交 SHA(`delivered_commit`)。未合入时说明当前状态;无改动时说明原因。
|
|
20
|
+
|
|
21
|
+
## 必要步骤
|
|
22
|
+
|
|
23
|
+
1. **选择工作区。** 若需要并行写入,或当前工作区有与本任务无关的未提交改动,在原任务工作区调用 `vc` MCP 服务的 `ensure_worktree` 工具,参数为 `{}`,在返回的 `worktree` 路径中开发。否则沿用当前任务工作区。
|
|
24
|
+
2. **实施与测试。** 按已确认的测试用例复用或编写测试;没有测试用例工作稿时,以已确认的验收标准为准。按改动性质选择验证方式:
|
|
25
|
+
- 修复缺陷:先用回归测试复现原缺陷,确认测试因该缺陷失败并单独提交测试;修复后重跑同一测试,确认通过。
|
|
26
|
+
- 新增或调整行为:按新预期编写或更新测试,验证改动前后的行为差异。
|
|
27
|
+
- 不改变行为:纯重构在改动前后运行相同的相关测试,确认行为一致;文档、格式等改动按验收标准检查,不要求先产生失败。
|
|
28
|
+
3. **准备候选提交。** 将本任务的成果整合到任务分支,补齐已登记的工作稿和适用的实施记录。若验证结果须随工作稿归档,先对整合后的版本执行相应检查,将实际结果和证据写入工作稿,再固定候选版本。在任务工作区暂存本任务的实施改动,不纳入无关改动。调用 `vc` MCP 服务的 `prepare_delivery` 工具,参数为 `{}`,取得 `candidate_commit`。后续评审和验证均以该提交及对应的工作稿为准。
|
|
29
|
+
4. **评审。** 调用 `review` skill 评审候选提交中的全部任务改动。阻塞性问题必须解决;直接相关、低风险的非阻塞性建议可一并处理。超出此范围或风险较高的建议由用户决定;未采纳的建议说明原因。
|
|
30
|
+
5. **验证。** 按验收标准核验同一候选提交;能确认已有验证证据适用于该版本时可沿用,否则补做相应检查。将最终核验结果与候选 SHA 一并列入交付摘要,不为重复记录通过结果而改写已固定的工作稿。
|
|
31
|
+
|
|
32
|
+
代码、测试或工作稿有变更时,返回第 3 步,重新准备候选提交,再评审和验证。评审和验证经过 3 轮仍有未解决的问题,或发现实施方向已偏离目标时,留在 CODING,记录未完成事项、问题详情和失败证据,向用户汇报并等待决定。
|
|
33
|
+
|
|
34
|
+
## 确认
|
|
35
|
+
|
|
36
|
+
- 评审和验证通过后,简述背景、改动及理由、验证结果和候选提交 SHA,询问:「是否将本任务工作稿归档到 `docs/sdlc/` 并合入本地 `main`?」用户要求修改时,完成修改后重新准备、评审、验证并请求确认。
|
|
37
|
+
- 用户明确同意交付当前候选版本后,在原任务工作区调用 `archive` 技能,传入任务 ID 和已确认的候选提交 SHA;没有工作稿时跳过。归档成功后,调用 `vc` MCP 服务的 `enter_step` 工具。传入三个参数:`step` 固定为 `READY`;`route` 取当前任务 `status.json` 中的 `route` 原值(`R2`、`R3` 或 `R4`);`verified_commit` 取已通过评审和验证、且用户同意交付的 `candidate_commit` SHA。
|
|
38
|
+
- 工具返回成功后,按「输出」报告结果。返回失败时,不报交付完成;说明工具返回的原因,处理后再重试。候选代码、测试或工作稿有变更时,重新准备、评审、验证并取得用户确认后再重试。
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
## 目标
|
|
2
|
+
|
|
3
|
+
查清用户遇到的问题,给出有证据支撑的根因、修复方向和回归验收标准。证据不足时,说明还需要查清什么。
|
|
4
|
+
|
|
5
|
+
## 边界
|
|
6
|
+
|
|
7
|
+
进入 HUNT 后,不创建任务,不新建或切换 Git 分支。HUNT 只调查,不实施修复;仅在成功进入 CODING 后开始修复。
|
|
8
|
+
|
|
9
|
+
## 权限
|
|
10
|
+
|
|
11
|
+
调查期间,仓库内只更新当前任务的任务意图工作稿,不直接修改 `status.json`。可读取代码、配置、日志、指标和测试,运行不会修改仓库的已有检查。若取证需要修改仓库,只记录所需证据和原因,不执行该修改。
|
|
12
|
+
|
|
13
|
+
## 输出
|
|
14
|
+
|
|
15
|
+
按 `.vc/tasks/<task_id>/status.json` 的 `artifacts` 清单定位并更新任务意图工作稿。新任务的工作稿为 `.vc/tasks/<task_id>/artifacts/intent.md`,实际路径以清单为准。将问题、影响范围和成功标准写入对应章节;在「调查结论」中记录关键证据的位置、因果解释、未确认项、建议的下一步及理由。
|
|
16
|
+
|
|
17
|
+
## 必要步骤
|
|
18
|
+
|
|
19
|
+
1. **明确问题。** 结合用户提供的信息和代码现状,在任务意图工作稿中写清实际现象、期望结果和可验证的成功标准。
|
|
20
|
+
2. **调查原因。** 根据线索取证,复用已有证据,逐一解释用户报告的症状。若现有证据不足以支持制定方案或修复,留在 HUNT,在工作稿中说明未确认的问题、缺少的证据和取得方式。能自行取证就继续;需要用户提供日志或复现条件时,只请求所缺信息,不请求切换步骤。
|
|
21
|
+
3. **建议下一步。** 证据足以支持下一阶段时,在工作稿中记录建议及依据。仅复用[项目分流规则](ready-routing.md)中 R2、R3、R4 的判据,推荐当前任务进入 PLAN 或 CODING,不执行新建任务流程。
|
|
22
|
+
|
|
23
|
+
## 确认
|
|
24
|
+
|
|
25
|
+
- **给出摘要。** 推荐切换时,根据最新工作稿简述问题、范围、成功标准、调查结论和关键依据,附上工作稿的绝对路径。只询问本次推荐的动作:推荐 PLAN 时问「是否按上述目标和范围开始制定方案?」;推荐 CODING 时问「是否按上述范围开始修复?」
|
|
26
|
+
- **切换步骤。** 仅认可分析不算授权;用户提出质疑或意图仍不清楚时,留在 HUNT,按需澄清。用户明确同意按当前摘要执行推荐动作后,将任务意图工作稿的「确认记录」正文写为 `已确认`,调用 `vc` MCP 服务的 `enter_step` 工具,按已确认的路由传入对应参数:
|
|
27
|
+
- R4:`{"step":"PLAN","route":"R4"}`
|
|
28
|
+
- R2:`{"step":"CODING","route":"R2"}`
|
|
29
|
+
- R3:`{"step":"CODING","route":"R3"}`
|
|
30
|
+
|
|
31
|
+
仅在工具返回成功后开始下一步。失败时留在 HUNT,按工具返回的原因处理;已确认内容未变可直接重试。
|
|
32
|
+
- **重新确认。** 提交确认后,若任务意图、范围、成功标准、调查结论或推荐动作有变,更新同一份工作稿,将「确认记录」改回 `待确认`,简述改动及影响,重新请求授权。
|
|
33
|
+
- **暂存。** 用户明确选择暂存时,调用 `vc` MCP 服务的 `reset` 工具,参数为 `{}`。成功后,在同一轮按工具返回的路径写入 `handoff.md`,记录当前结论、证据位置、未确认事项和接手后的第一步。工具失败时留在 HUNT 并说明原因;若已回到 READY 但交接写入失败,报告「已回到 READY,交接未写入」。
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
## 目标
|
|
2
|
+
|
|
3
|
+
完成调研与设计,明确做什么、怎么做、怎么验收,产出一份有充分依据、可执行的计划,并请用户确认是否开工。
|
|
4
|
+
|
|
5
|
+
## 边界
|
|
6
|
+
|
|
7
|
+
进入 PLAN 后,不再创建任务,不新建或切换 Git 分支。
|
|
8
|
+
|
|
9
|
+
## 权限
|
|
10
|
+
- 计划文档: 可按需修改 .vc/tasks/<task_id>/ 下的内容,但不直接修改 status.json。
|
|
11
|
+
- 临时文件:可在仓库根目录的 `tmp/` 下创建或编辑文件。编辑仓库外的文件时,不得超出本次任务范围和宿主授权范围。
|
|
12
|
+
- 产品文件:成功进入 CODING 前,不得修改业务代码或依赖,即使用户已同意开工。修改仓库内的其他产品文件前,须说明
|
|
13
|
+
拟修改的内容并取得用户确认。
|
|
14
|
+
- Shell:命令按宿主权限运行;使用 Shell 时同样遵守上述限制。
|
|
15
|
+
|
|
16
|
+
## 输出
|
|
17
|
+
|
|
18
|
+
按 `.vc/tasks/<task_id>/status.json` 的 `artifacts` 清单定位并更新四份工作稿:任务意图(`intent.md`)、规格说明(`spec.md`)、测试用例(`test-cases.md`)和实施计划(`plan.md`)。括号内为新任务的文件名,实际路径以清单为准。沿用实施计划工作稿中的章节标题,填写或更新各节内容。需要设计稿时,一并提供。
|
|
19
|
+
|
|
20
|
+
## 必要步骤
|
|
21
|
+
|
|
22
|
+
1. 理解用户意图,调查代码库。
|
|
23
|
+
2. 制定计划前,必须调用 `grilling` skill 与用户对齐需求。复用已有调查结论和用户已确认的信息,不重复提问;需要外部依据时,可定向开展网络调研。完成对齐后再制定计划。
|
|
24
|
+
3. 将已确定的决策写入任务意图和规格说明。
|
|
25
|
+
|
|
26
|
+
4. 根据规格说明编写测试用例,在追溯矩阵中核对每项验收标准至少有一个对应用例。已有用例能够验证时优先复用,同一用例可以覆盖多项标准。同类场景选取代表性用例,按本次改动的影响和风险补充必要的边界、异常与回归场景。用例内容按测试用例模板填写。
|
|
27
|
+
|
|
28
|
+
5. 根据规格说明和测试用例制定实施计划,尽量将任务拆分为可独立开发和验证的工作。
|
|
29
|
+
|
|
30
|
+
**遇到关键分歧时,可请独立代理核对事实和方案取舍。仍需决定范围、方案或验收标准时,将可选方案及其影响交用户决定,再更新计划。**
|
|
31
|
+
|
|
32
|
+
## 确认
|
|
33
|
+
|
|
34
|
+
- 根据「输出」中的工作稿,写一份简短的开工摘要,简述目标、范围、主要步骤和完成标准,并带上工作稿的绝对路径。最后问:「是否同意按上述目标、范围和计划开始编码?」
|
|
35
|
+
- 材料提交确认后如有内容变更,更新相关材料,将任务意图、规格说明中受影响的「确认记录」重置为 待确认;测试用例变更时,须重置规格说明的记录。简述改动及影响,重新请求开工授权。
|
|
36
|
+
- 仅确认理解正确不算授权,仍留在 PLAN。用户明确同意按当前摘要开工后,将任务意图和规格说明的「确认记录」正文均写为 已确认,再调用 vc MCP 服务的 enter_step 工具,参数为{"step":"CODING","route":"R4"}。仅在工具返回成功后开始编码。
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
**仅在当前会话处于 `READY` 时生效。** 以 Runtime 最近一次成功提交的状态为准,不以规则文本的出现顺序为准。进入 `HUNT`、`PLAN` 或 `CODING` 后,本规则不再约束当前任务。
|
|
2
|
+
|
|
3
|
+
每条新的用户输入都先判断意图。简单只读请求(如解释、查阅或只读评审)直接处理,保持 `READY`:不分配路由(包括 R2),不调用 `create_task`,不创建任务分支或产物。确需调查的问题走 R1,不把问题调查当作简单只读请求。既有任务恢复按 Runtime 提供的任务和步骤继续,不作为新任务再创建。意图或执行范围不清时先澄清,不擅自开始修改。
|
|
4
|
+
|
|
5
|
+
仅对新任务,按 `R1 → R4 → R2 → R3` 的顺序判断:
|
|
6
|
+
|
|
7
|
+
| 路由 | 判定 | 初始步骤 |
|
|
8
|
+
| --- | --- | --- |
|
|
9
|
+
| R1 — INVESTIGATE | 已有问题或事件的原因、范围、影响、证据或复现条件未知;先调查,不修改代码。 | `HUNT` |
|
|
10
|
+
| R4 — PLANNED_ENGINEERING | 新功能、性能优化、重构、架构变更、认证、安全、授权、API 或契约变更、数据变更或迁移、生产变更、跨模块变更、基础设施变更。即使范围明确或改动很小也不降级。 | `PLAN` |
|
|
11
|
+
| R2 — TRIVIAL | 同时满足:文件和改法明确,改动小且可回退;仅涉及本地或开发配置、文档、注释、格式、固定的非敏感日志或纯视觉样式;不改变业务行为,不影响 API、数据、认证、安全、性能或生产。环境或影响不清楚时不用 R2。 | `CODING` |
|
|
12
|
+
| R3 — KNOWN_CHANGE | 已知问题修复或既有行为调整,范围、验收标准和实现边界明确,且不属于 R4 或 R2。 | `CODING` |
|
|
13
|
+
|
|
14
|
+
根据任务意图拟一个简短的英文名称,小写、连字符分词,例如 remember-login;
|
|
15
|
+
确定路由后,从本地 `main` 调用 `create_task(route, slug)`,新任务只调用一次。若当前不在 `main`,先正常切回本地 `main`;缺少 `main` 或 Git 拒绝切换时停止并说明原因,不自动创建、拉取或强切。Agent 判断路由并提供 `slug`;Runtime 创建并切换任务分支、初始化 `status.json`,再进入初始步骤。不要自行建任务分支、准备正式产物或写任务状态;以 Runtime 返回的结果为准。
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: archive
|
|
3
|
+
description: 在任务收尾时生成或迁移研发文档,并更新 docs/sdlc/README.md。
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
在项目根目录运行本技能随附的 `archive.mjs`。
|
|
7
|
+
|
|
8
|
+
## 非 VC 任务
|
|
9
|
+
|
|
10
|
+
首次建档时,选定简短的英文 `slug` 和本次需要的文档类型(`INT` 需求意图、`SPEC` 规格说明、`TCSET` 测试用例、`PLAN` 实施计划),例如:
|
|
11
|
+
|
|
12
|
+
```text
|
|
13
|
+
node "<技能目录>/archive.mjs" init login-timeout INT SPEC PLAN
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
脚本用同一个随机编号和随附模板创建文档,返回文件路径。打开这些文件,根据本次任务的用户意图、已确认的决定、实际改动和验证结果填写模板。已有正式文档则直接更新,不再建档。
|
|
17
|
+
|
|
18
|
+
更新 `docs/sdlc/README.md`(没有就创建):按编号更新或新增条目,链接实际保存的文档和验证记录,保留其他条目。
|
|
19
|
+
|
|
20
|
+
## VC 任务
|
|
21
|
+
|
|
22
|
+
用户确认交付后,在原任务工作区传入任务 ID 和已确认的候选提交 SHA:
|
|
23
|
+
|
|
24
|
+
```text
|
|
25
|
+
node "<技能目录>/archive.mjs" move <task_id> <candidate_commit>
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
脚本读取任务 `status.json` 的 `artifacts` 清单,把已有工作稿归档到 `docs/sdlc/` 对应目录并更新总览。不重新填写正文。脚本成功后回到交付流程完成合入;工作稿在合入成功后移除,失败时可用同一个候选提交重试。
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: INT-{{id}}
|
|
3
|
+
title: null
|
|
4
|
+
owner: null
|
|
5
|
+
status: draft
|
|
6
|
+
created: {{date}}
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
# Intent: {{key}}
|
|
10
|
+
|
|
11
|
+
## 问题,受影响的用户与系统
|
|
12
|
+
|
|
13
|
+
<!-- 描述问题、触发场景和受影响的用户、环境、接口或模块。 -->
|
|
14
|
+
|
|
15
|
+
## 期望结果
|
|
16
|
+
|
|
17
|
+
<!-- 描述期望看到的行为。 -->
|
|
18
|
+
|
|
19
|
+
## 约束
|
|
20
|
+
|
|
21
|
+
<!-- 记录已知约束和不在范围内的事项。 -->
|
|
22
|
+
|
|
23
|
+
## 成功标准
|
|
24
|
+
|
|
25
|
+
<!-- 写明可观察、可验证的标准。 -->
|
|
26
|
+
|
|
27
|
+
## 调查结论
|
|
28
|
+
|
|
29
|
+
<!-- 记录根因、证据、未决问题和处理决定。 -->
|
|
30
|
+
|
|
31
|
+
## 确认记录
|
|
32
|
+
|
|
33
|
+
待确认
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: PLAN-{{id}}
|
|
3
|
+
spec: SPEC-{{id}}
|
|
4
|
+
test_cases: TCSET-{{id}}
|
|
5
|
+
status: draft
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Plan: {{key}}
|
|
9
|
+
|
|
10
|
+
## 目标和范围
|
|
11
|
+
|
|
12
|
+
<!-- 说明本次实施目标、覆盖范围和不在范围内的事项。 -->
|
|
13
|
+
|
|
14
|
+
## 实施方案
|
|
15
|
+
|
|
16
|
+
<!-- 写明工作顺序、主要风险和回退办法;按需记录偏离和原因。 -->
|
|
17
|
+
|
|
18
|
+
## 验收标准
|
|
19
|
+
|
|
20
|
+
<!-- 关联规格和测试用例,说明必测场景、验证方式及完成条件。 -->
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: SPEC-{{id}}
|
|
3
|
+
intent: INT-{{id}}
|
|
4
|
+
status: draft
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Spec: {{key}}
|
|
8
|
+
|
|
9
|
+
## 目标
|
|
10
|
+
|
|
11
|
+
<!-- 引用来源意图,明确本次目标和范围。 -->
|
|
12
|
+
|
|
13
|
+
## 功能需求
|
|
14
|
+
|
|
15
|
+
<!-- 为需求编号,说明使用者、前置条件、正常与异常流程。 -->
|
|
16
|
+
|
|
17
|
+
## 非功能需求
|
|
18
|
+
|
|
19
|
+
<!-- 为适用的性能、安全、兼容性及可观测性要求给出可验证指标。 -->
|
|
20
|
+
|
|
21
|
+
## 设计
|
|
22
|
+
|
|
23
|
+
<!-- 说明接口契约、数据模型和关键决策,可引用设计稿。 -->
|
|
24
|
+
|
|
25
|
+
## 验收标准
|
|
26
|
+
|
|
27
|
+
<!-- 为验收标准编号,关联需求与验证方式。 -->
|
|
28
|
+
|
|
29
|
+
## 确认记录
|
|
30
|
+
|
|
31
|
+
待确认
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: TCSET-{{id}}
|
|
3
|
+
intent: INT-{{id}}
|
|
4
|
+
spec: SPEC-{{id}}
|
|
5
|
+
status: draft
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# 测试用例:{{key}}
|
|
9
|
+
|
|
10
|
+
## 范围、环境与数据
|
|
11
|
+
|
|
12
|
+
<!-- 记录关联规格版本、测试环境与数据、必测清单和回归范围。 -->
|
|
13
|
+
|
|
14
|
+
## 测试用例
|
|
15
|
+
|
|
16
|
+
### TC-001
|
|
17
|
+
|
|
18
|
+
<!-- 步骤与预期结果可用普通列表,正文允许冒号。其他字段请另起一行写「字段名:」,或在列表中明确加粗标签(例如「- **备注**:…」)。普通列表正文不用于识别自定义字段。 -->
|
|
19
|
+
|
|
20
|
+
关联需求及验收标准:
|
|
21
|
+
|
|
22
|
+
前置条件与测试数据:
|
|
23
|
+
|
|
24
|
+
步骤:
|
|
25
|
+
|
|
26
|
+
预期结果:
|
|
27
|
+
|
|
28
|
+
## 追溯矩阵
|
|
29
|
+
|
|
30
|
+
<!-- 关联需求、验收标准、用例与计划验证方式;执行后再补结果及证据。 -->
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: grilling
|
|
3
|
+
description: Use when requirements or decisions are unclear and need clarification from the user.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
Interview the user relentlessly until you reach a shared understanding. Map this as a **design tree**: every decision branches into the decisions that hang off it.
|
|
7
|
+
|
|
8
|
+
Work the tree in **rounds**. The **frontier** is every decision whose prerequisites are already settled: the questions you can ask _now_ without guessing at answers you haven't heard yet. Ask the whole frontier in one round: number each question and give your recommended answer. Then wait for the user's answers before the next round.
|
|
9
|
+
|
|
10
|
+
For example, structure a round like this in the questionnaire—not as plain-chat text:
|
|
11
|
+
```
|
|
12
|
+
❓ **Q1** - **<question title>**
|
|
13
|
+
<question body, might be multiple paragraphs, including multiple choices>
|
|
14
|
+
|
|
15
|
+
💡 <your recommended answer>
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
❓ **Q2** - **<question title>**
|
|
20
|
+
<question body, might be multiple paragraphs, including multiple choices>
|
|
21
|
+
|
|
22
|
+
💡 <your recommended answer>
|
|
23
|
+
```
|
|
24
|
+
Each round the user answers reshapes the tree: settled decisions push the frontier outward and unblock questions that depended on them. Recompute the frontier and ask the next round. A question whose answer depends on another question still open in this round belongs to a _later_ round, not this one.
|
|
25
|
+
|
|
26
|
+
Finding _facts_ is your job, never the user's. When a frontier question needs a fact from the environment (filesystem, tools, etc.), dispatch a sub-agent to find it; don't ask the user for anything you could look up yourself. Don't block on it: a running exploration is an unsettled prerequisite, so only the questions downstream of it wait for the sub-agent to report; ask the rest of the frontier now. The _decisions_ are the user's: put each to them and wait.
|
|
27
|
+
|
|
28
|
+
The session is done when the frontier is empty: every branch of the design tree visited, nothing left silently assumed. Do not act on it until the user confirms you have reached a shared understanding.
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: review
|
|
3
|
+
description: Use when work needs an independent review — a completed change, a confirmed fix (re-review), or a design.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
组装评审目标和材料,确定评审范围,将评审委派给后台的 `reviewer` 子代理(Claude Code 使用 Agent 工具,Codex 使用 `spawn_agent`)。派发后先做不依赖评审结论的工作;判断评审是否通过前,必须取得该子代理的报告。
|
|
7
|
+
子代理返回后:结论、问题和版本必须保持在本轮评审的边界内(自动忽略边界之外的任何内容);评审未完成不算通过;忠实转达问题和未评审项——绝不自行授权修复。
|
|
8
|
+
|
|
9
|
+
## 组装提示词
|
|
10
|
+
|
|
11
|
+
按以下模板组装,替换每个 `<...>`;保持目标清晰、上下文完整、边界明确(否则子代理会过度评审并浪费精力)。
|
|
12
|
+
只陈述事实和材料,绝不包含主代理的叙述性结论;材料条目指向实际 diff 和文档本身——变更摘要不能替代实际变更。
|
|
13
|
+
只有实际运行并通过的内容才记录为已验证;配置和计划不算验证。
|
|
14
|
+
复评只移交上轮已确认的问题、对应修复和直接影响。派发前读取与当前 `SKILL.md` 同目录下的 `references/review-method.md`,将完整正文填入「方法」段,不只传路径。无法读取方法或无法调用 `reviewer` 时,报告评审未完成,不自行代评。
|
|
15
|
+
|
|
16
|
+
```markdown
|
|
17
|
+
## 目标
|
|
18
|
+
<本轮的目标和验收标准;必须保留的约束。>
|
|
19
|
+
|
|
20
|
+
## 上下文
|
|
21
|
+
<评审对象及其确切版本;材料条目(diff、需求文档、相关代码路径);哪些已验证、哪些未验证。>
|
|
22
|
+
|
|
23
|
+
## 边界
|
|
24
|
+
<包含和排除的范围;本轮特定的限制。>
|
|
25
|
+
|
|
26
|
+
## 方法
|
|
27
|
+
<当前 skill 的 references/review-method.md 完整正文>
|
|
28
|
+
```
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# 评审方法
|
|
2
|
+
|
|
3
|
+
## 执行
|
|
4
|
+
|
|
5
|
+
1. 对照已确认的需求、验收标准和设计,审查本次变更及其直接影响。初评走查五个维度中的适用项;评审设计稿时,不把尚未进入实现阶段的代码或测试当作缺失。
|
|
6
|
+
2. 报告前逐条反证:**触发条件成立吗?现有机制已经处理了吗?这是不是预期行为?** 有具体依据和影响才报告;静态证据充分时不要求动态复现,未运行的检查不写成已验证。
|
|
7
|
+
3. 五个维度是找问题的视角,不是五栏报告。同一问题只报一次,不凑条数,不顺带报告与本次变更无关的遗留问题。
|
|
8
|
+
|
|
9
|
+
## 初评:五个维度
|
|
10
|
+
|
|
11
|
+
### 实现完整性
|
|
12
|
+
|
|
13
|
+
从需求和验收标准追到实现,不从子任务清单反推需求已覆盖。
|
|
14
|
+
|
|
15
|
+
- **漏拆**:有没有哪项已确认的需求没有对应实现,即使子任务都标了完成?
|
|
16
|
+
- **部分实现**:入口或主要场景已经实现,但某个明确要求的分支、条件或结果仍缺失吗?
|
|
17
|
+
|
|
18
|
+
报告遗漏时,指出对应的需求或验收标准,以及缺在哪一步。
|
|
19
|
+
|
|
20
|
+
### 逻辑闭环性
|
|
21
|
+
|
|
22
|
+
沿受影响的路径检查:**入口 → 状态变化或副作用 → 返回结果**。
|
|
23
|
+
|
|
24
|
+
- **正常路径**:输入经过各环节后,状态和结果是否符合验收标准?
|
|
25
|
+
- **异常路径**:在本次改动实际可达的失败条件下,是否会卡在中间状态、重复执行,或把失败报成成功?需要重试或恢复时,检查再次进入是否安全。
|
|
26
|
+
- **测试保护**:相关测试能否识别上述错误?原有测试或断言是否被删除、跳过或弱化?
|
|
27
|
+
|
|
28
|
+
不因改动缺少重试、回滚或监控就判为缺陷;先说明哪条实际路径需要它。
|
|
29
|
+
|
|
30
|
+
### 实现是否克制
|
|
31
|
+
|
|
32
|
+
先确认现有契约、运行约束和风险,再判断新增的行为、分支或抽象是否必要。
|
|
33
|
+
|
|
34
|
+
| 检查 | 判定问题 |
|
|
35
|
+
|---|---|
|
|
36
|
+
| 超出设计意图 | 是否引入了未要求、且不是达成已确认目标所必需的行为、接口或配置? |
|
|
37
|
+
| 过度防御 | 新增的回退或兼容分支是否处理了在当前约束下不可达、或已由其他层完整处理的情况? |
|
|
38
|
+
| 不必要的复杂度 | 是否有更直接的做法,能在保留行为、契约和必要保护的前提下减少分支、状态或依赖? |
|
|
39
|
+
|
|
40
|
+
报告时说明为什么在当前约束下可以简化、简化后仍满足哪些要求。仅凭“设计没写”“过去没出过问题”或“测试全绿”,不能判定保护多余。材料不足时,不下过度设计的结论。
|
|
41
|
+
|
|
42
|
+
### 安全性
|
|
43
|
+
|
|
44
|
+
检查本次变更及其直接影响是否引入或扩大安全风险,不扩展为全仓审计。
|
|
45
|
+
|
|
46
|
+
- **输入与访问**:外部输入是否被误当作指令处理?本应受保护的入口或资源是否缺少认证、授权检查?
|
|
47
|
+
- **敏感信息**:日志、错误或输出是否泄露敏感信息?是否新增了硬编码密钥?
|
|
48
|
+
|
|
49
|
+
### 代码清晰与可维护性
|
|
50
|
+
|
|
51
|
+
以书面项目规范和具体维护影响为准,不按个人喜好评判。
|
|
52
|
+
|
|
53
|
+
- **规范偏离**:违反了哪条适用的项目约定?
|
|
54
|
+
- **维护隐患**:业务规则是否散落在必须同步修改的多个位置?命名是否误导调用方?不明显的副作用是否容易让后续修改出错?
|
|
55
|
+
|
|
56
|
+
指出具体影响,不报告个人风格偏好或 CI 已覆盖的格式问题。
|
|
57
|
+
|
|
58
|
+
## 复评
|
|
59
|
+
|
|
60
|
+
只检查上轮已确认的问题、对应修复及其直接影响,不重新走查五个维度。逐项标明**已关闭 / 仍存在 / 待确认**;修复引入的直接回归按严重度报告。原问题全部关闭且未发现直接回归时,输出 `通过(复评范围)`。
|
|
61
|
+
|
|
62
|
+
## 结论与报告
|
|
63
|
+
|
|
64
|
+
- **通过**:本轮范围已评完,没有成立的问题。静态评审通过不等于运行验证通过或批准合并。
|
|
65
|
+
- **P0–P3**:有成立的问题时,总体取最高严重度;只有 P3 也不写通过。
|
|
66
|
+
- **评审未完成**:材料不足或范围未评完,且没有已成立的问题。已有发现时照常报告严重度,另列未评审项,不把没查到当作通过。
|
|
67
|
+
|
|
68
|
+
按实际影响分级:
|
|
69
|
+
**P0** 阻断(如数据损坏、严重安全风险或核心功能不可用);
|
|
70
|
+
**P1** 严重(如核心流程错误或外部契约破坏);
|
|
71
|
+
**P2** 局部但确实影响预期行为;
|
|
72
|
+
**P3** 有明确依据的项目规范或可维护性问题。
|
|
73
|
+
|
|
74
|
+
```markdown
|
|
75
|
+
结论:<通过 / 通过(复评范围) / P0–P3 中的最高级别 / 评审未完成>
|
|
76
|
+
|
|
77
|
+
- [P级] <文件:行号>:<问题>;依据:<触发条件或材料>;影响:<实际后果>;建议:<有明确改法时填写>
|
|
78
|
+
|
|
79
|
+
未评审:<缺少的材料或未覆盖的范围>
|
|
80
|
+
复评:<原问题 ID> <已关闭 / 仍存在 / 待确认>
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
无发现时不列问题;没有未评审项或不是复评时,省略对应行。
|
package/runtime/vc.exe
ADDED
|
Binary file
|
package/setup.mjs
ADDED
|
@@ -0,0 +1,467 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { spawn, spawnSync } from 'node:child_process';
|
|
3
|
+
import { randomUUID } from 'node:crypto';
|
|
4
|
+
import fs from 'node:fs/promises';
|
|
5
|
+
import { homedir } from 'node:os';
|
|
6
|
+
import path from 'node:path';
|
|
7
|
+
import process from 'node:process';
|
|
8
|
+
import { emitKeypressEvents } from 'node:readline';
|
|
9
|
+
import { createInterface } from 'node:readline/promises';
|
|
10
|
+
import { isDeepStrictEqual } from 'node:util';
|
|
11
|
+
import { pathToFileURL, fileURLToPath } from 'node:url';
|
|
12
|
+
|
|
13
|
+
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
14
|
+
const supported = ['claude-code', 'codex'];
|
|
15
|
+
const stages = {
|
|
16
|
+
hunt: '调查问题、核实根因并提出下一步建议',
|
|
17
|
+
plan: '澄清需求、拆解功能并制定实施计划',
|
|
18
|
+
coding: '按任务范围实施改动、验证并完成本地交付',
|
|
19
|
+
};
|
|
20
|
+
const payload = ['vc.exe', ...['ready-routing', ...Object.keys(stages)].map(x => `prompts/${x}.md`)];
|
|
21
|
+
const matcher = '.*'; // PLAN inspects ordinary host tools as well as VC calls.
|
|
22
|
+
const events = ['UserPromptSubmit', 'PreToolUse'];
|
|
23
|
+
// Only fixed labels and sanitized version numbers cross this boundary. The
|
|
24
|
+
// installer never waits for its diagnostic helper to write or exit.
|
|
25
|
+
function writeSetupLog({ version, events }) {
|
|
26
|
+
if (process.platform !== 'win32' || !path.isAbsolute(process.env.LOCALAPPDATA ?? '')) return;
|
|
27
|
+
try {
|
|
28
|
+
const child = spawn(path.join(here, 'runtime', 'vc.exe'), ['setup-log', JSON.stringify({ version, events })], {
|
|
29
|
+
detached: true, windowsHide: true, stdio: 'ignore',
|
|
30
|
+
});
|
|
31
|
+
child.on('error', () => {});
|
|
32
|
+
child.unref();
|
|
33
|
+
} catch {
|
|
34
|
+
// Diagnostics never change the installer result.
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function fail(message) { throw new Error(message); }
|
|
39
|
+
function samePath(a, b) { return typeof a === 'string' && path.normalize(a).toLowerCase() === path.normalize(b).toLowerCase(); }
|
|
40
|
+
function object(value, label) {
|
|
41
|
+
if (!value || Array.isArray(value) || typeof value !== 'object') fail(`${label} must be a JSON object`);
|
|
42
|
+
return value;
|
|
43
|
+
}
|
|
44
|
+
async function optional(file) {
|
|
45
|
+
try { return await fs.readFile(file); } catch (error) { if (error.code !== 'ENOENT') throw error; return null; }
|
|
46
|
+
}
|
|
47
|
+
function jsonEdit(file, before, data) {
|
|
48
|
+
const after = Buffer.from(`${JSON.stringify(data, null, 2)}\n`);
|
|
49
|
+
return { file, before, after };
|
|
50
|
+
}
|
|
51
|
+
async function jsonFile(file) {
|
|
52
|
+
const before = await optional(file);
|
|
53
|
+
return { before, data: object(before === null ? {} : JSON.parse(before.toString('utf8').replace(/^\uFEFF/, '')), file) };
|
|
54
|
+
}
|
|
55
|
+
export async function apply({ file, before, after, retire }) {
|
|
56
|
+
if (retire) {
|
|
57
|
+
if (!(await optional(file))?.equals(before)) fail(`Entry changed during setup: ${file}`);
|
|
58
|
+
// Keep a recoverable copy, with a name neither host discovers as an entry.
|
|
59
|
+
const backup = `${file}.vc-backup-${randomUUID()}`;
|
|
60
|
+
await fs.rename(file, backup);
|
|
61
|
+
console.log(`Backed up replaced entry: ${backup}`);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
await fs.mkdir(path.dirname(file), { recursive: true });
|
|
65
|
+
const temp = `${file}.vc-${randomUUID()}.tmp`;
|
|
66
|
+
try {
|
|
67
|
+
await fs.writeFile(temp, after, { flag: 'wx' });
|
|
68
|
+
const current = await optional(file);
|
|
69
|
+
if (before === null ? current !== null : !current?.equals(before)) fail(`Configuration changed during setup: ${file}`);
|
|
70
|
+
if (before === null) await fs.link(temp, file); // Do not replace a concurrently created user file.
|
|
71
|
+
else await fs.rename(temp, file);
|
|
72
|
+
} finally { await fs.rm(temp, { force: true }); }
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Use the existing host CLI to update TOML. Pass arguments as a JSON array in
|
|
76
|
+
// the child environment, not as PowerShell/cmd source and not via shell:true.
|
|
77
|
+
function hostCommand(host, args, cwd) {
|
|
78
|
+
const script = `$ErrorActionPreference = 'Stop'; $command = Get-Command -Name '${host}.exe','${host}.cmd' -CommandType Application -ErrorAction SilentlyContinue | Select-Object -First 1; if (!$command) { exit 127 }; $a = @(ConvertFrom-Json $env:VC_SETUP_HOST_ARGS); & $command.Source @a; exit $LASTEXITCODE`;
|
|
79
|
+
const child = spawnSync('powershell.exe', ['-NoProfile', '-NonInteractive', '-EncodedCommand', Buffer.from(script, 'utf16le').toString('base64')], {
|
|
80
|
+
cwd, env: { ...process.env, VC_SETUP_HOST_ARGS: JSON.stringify(args) }, encoding: 'utf8', windowsHide: true, timeout: 20000,
|
|
81
|
+
});
|
|
82
|
+
if (child.error) throw child.error;
|
|
83
|
+
return { result: child.status, out: child.stdout.trim(), error: child.stderr.trim() };
|
|
84
|
+
}
|
|
85
|
+
function cliVersion(host, installDir, progress) {
|
|
86
|
+
const result = hostCommand(host === 'claude-code' ? 'claude' : 'codex', ['--version'], installDir);
|
|
87
|
+
if (result.result !== 0) {
|
|
88
|
+
progress.events.push({ event: 'host_version', outcome: 'failed', host, reason: 'cli_unavailable' });
|
|
89
|
+
fail(`${host} CLI not found or could not run. Install it separately, then repeat setup.`);
|
|
90
|
+
}
|
|
91
|
+
const version = result.out.match(/\b\d{1,6}\.\d{1,6}\.\d{1,6}\b/)?.[0];
|
|
92
|
+
const tested = host === 'claude-code' ? '2.1.332' : '0.172.0';
|
|
93
|
+
if (version !== tested) {
|
|
94
|
+
progress.events.push({ event: 'host_version', outcome: 'failed', host, hostVersion: version, reason: 'unsupported_version' });
|
|
95
|
+
fail(`${host} ${version ?? '(unknown version)'} is not verified with this installer; expected ${tested}.`);
|
|
96
|
+
}
|
|
97
|
+
progress.events.push({ event: 'host_version', outcome: 'ok', host, hostVersion: version });
|
|
98
|
+
}
|
|
99
|
+
function psQuote(s) { return `'${s.replaceAll("'", "''")}'`; }
|
|
100
|
+
export function hookGroup(host, exe, event) {
|
|
101
|
+
const args = ['native-hook', host, event];
|
|
102
|
+
const command = `& ${[exe, ...args].map(psQuote).join(' ')}`;
|
|
103
|
+
const handler = host === 'claude-code'
|
|
104
|
+
? { type: 'command', command: exe, args, timeout: 8, ...(event === 'PreToolUse' ? { onFailure: 'block' } : {}) }
|
|
105
|
+
: { type: 'command', command, commandWindows: command, timeout: 8 };
|
|
106
|
+
return { ...(event === 'PreToolUse' ? { matcher } : {}), hooks: [handler] };
|
|
107
|
+
}
|
|
108
|
+
function mergeHooks(data, host, exe, file) {
|
|
109
|
+
data.hooks ??= {};
|
|
110
|
+
object(data.hooks, `${file}: hooks`);
|
|
111
|
+
let changed = false;
|
|
112
|
+
for (const event of events) {
|
|
113
|
+
const groups = data.hooks[event] ?? [];
|
|
114
|
+
if (!Array.isArray(groups)) fail(`${file}: hooks.${event} must be an array`);
|
|
115
|
+
const group = hookGroup(host, exe, event);
|
|
116
|
+
if (groups.some(x => isDeepStrictEqual(x, group))) continue;
|
|
117
|
+
if (groups.some(x => x?.hooks?.some?.(h => h?.args?.[0] === 'native-hook' || /\bnative-hook\b/.test(h?.command ?? '')))) {
|
|
118
|
+
fail(`${file}: existing VC hook differs; remove or reconcile it before reinstalling`);
|
|
119
|
+
}
|
|
120
|
+
data.hooks[event] = [...groups, group];
|
|
121
|
+
changed = true;
|
|
122
|
+
}
|
|
123
|
+
return changed;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
async function installRuntime(target, source) {
|
|
127
|
+
const files = await Promise.all(payload.map(async name => [name, await fs.readFile(path.join(source, name))]));
|
|
128
|
+
const [name, binary] = files[0];
|
|
129
|
+
if (binary.subarray(0, 2).toString() !== 'MZ' || files.some(([, data]) => !data.length)) fail(`Invalid bundled runtime: ${name}`);
|
|
130
|
+
await fs.mkdir(path.dirname(target), { recursive: true });
|
|
131
|
+
const verify = async () => {
|
|
132
|
+
for (const [file, bytes] of files) {
|
|
133
|
+
if (!(await optional(path.join(target, file)))?.equals(bytes)) fail(`Runtime conflict at ${target}; do not publish different builds under the same version.`);
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
try { await fs.stat(target); return await verify(); } catch (error) { if (error.code !== 'ENOENT') throw error; }
|
|
137
|
+
const temp = await fs.mkdtemp(path.join(path.dirname(target), '.setup-'));
|
|
138
|
+
try {
|
|
139
|
+
await fs.mkdir(path.join(temp, 'prompts'));
|
|
140
|
+
for (const [file, data] of files) await fs.writeFile(path.join(temp, file), data, { flag: 'wx' });
|
|
141
|
+
try { await fs.rename(temp, target); } catch (error) {
|
|
142
|
+
if (!['EEXIST', 'ENOTEMPTY', 'EPERM'].includes(error.code)) throw error;
|
|
143
|
+
await verify();
|
|
144
|
+
}
|
|
145
|
+
} finally { await fs.rm(temp, { recursive: true, force: true }); }
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
async function setup(harnesses, progress) {
|
|
149
|
+
if (process.platform !== 'win32' || process.arch !== 'x64') fail('This release supports Windows x64 only.');
|
|
150
|
+
if (!process.env.LOCALAPPDATA || !path.isAbsolute(process.env.LOCALAPPDATA)) fail('LOCALAPPDATA is not an absolute path.');
|
|
151
|
+
const pkg = JSON.parse(await fs.readFile(path.join(here, 'package.json'), 'utf8'));
|
|
152
|
+
if (/^\d{1,6}\.\d{1,6}\.\d{1,6}$/.test(pkg.version)) progress.version = pkg.version;
|
|
153
|
+
for (const host of harnesses) progress.events.push({ event: 'host_selected', outcome: 'ok', host });
|
|
154
|
+
for (const [host, variable] of [['claude-code', 'CLAUDE_CONFIG_DIR'], ['codex', 'CODEX_HOME']]) {
|
|
155
|
+
if (harnesses.includes(host) && process.env[variable] && !path.isAbsolute(process.env[variable])) fail(`${variable} must be an absolute path.`);
|
|
156
|
+
}
|
|
157
|
+
const base = path.join(process.env.LOCALAPPDATA, 'vc');
|
|
158
|
+
const target = path.join(base, 'versions', pkg.version);
|
|
159
|
+
const exe = path.join(target, 'vc.exe');
|
|
160
|
+
const home = homedir();
|
|
161
|
+
await fs.mkdir(base, { recursive: true });
|
|
162
|
+
const lockPath = path.join(base, 'setup.lock');
|
|
163
|
+
let lock;
|
|
164
|
+
progress.stage = 'setup_lock';
|
|
165
|
+
try { lock = await fs.open(lockPath, 'wx'); } catch (err) {
|
|
166
|
+
if (err.code === 'EEXIST') fail(`Another VC setup is running or left a lock: ${lockPath}`);
|
|
167
|
+
throw err;
|
|
168
|
+
}
|
|
169
|
+
try {
|
|
170
|
+
// Run the host config commands outside the caller's repository.
|
|
171
|
+
const cwd = await fs.mkdtemp(path.join(process.env.LOCALAPPDATA, 'vc-setup-'));
|
|
172
|
+
try {
|
|
173
|
+
await configure({ harnesses, target, exe, home, cwd, edits: [], registrations: [], progress });
|
|
174
|
+
} finally {
|
|
175
|
+
await fs.rm(cwd, { recursive: true, force: true });
|
|
176
|
+
}
|
|
177
|
+
} finally {
|
|
178
|
+
await lock.close();
|
|
179
|
+
await fs.unlink(lockPath);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
async function planStageEntries(host, hostDir, edits) {
|
|
184
|
+
for (const [stage, description] of Object.entries(stages)) {
|
|
185
|
+
const name = `vc-${stage}`;
|
|
186
|
+
const body = await fs.readFile(path.join(here, 'runtime', 'prompts', `${stage}.md`));
|
|
187
|
+
const claude = host === 'claude-code';
|
|
188
|
+
const file = claude ? path.join(hostDir, 'commands', `${name}.md`) : path.join(hostDir, 'skills', name, 'SKILL.md');
|
|
189
|
+
const after = claude ? body : Buffer.concat([Buffer.from(`---\nname: ${name}\ndescription: ${description}\n---\n\n`), body]);
|
|
190
|
+
const before = await optional(file);
|
|
191
|
+
edits.push({ name, file, before, after, host, stage: 'stage_entry_install' });
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
async function planResource(file, after, host, stage, edits) {
|
|
196
|
+
const before = await optional(file);
|
|
197
|
+
if (before?.equals(after)) return;
|
|
198
|
+
if (before !== null) fail(`Existing VC resource differs at ${file}; reconcile it before reinstalling.`);
|
|
199
|
+
edits.push({ file, before, after, host, stage });
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
async function planControls(host, hostDir, home, exe, edits) {
|
|
203
|
+
const claude = host === 'claude-code';
|
|
204
|
+
for (const [name, description] of Object.entries({
|
|
205
|
+
'vc-pause': 'Show how to manually disable VC for this user.',
|
|
206
|
+
'vc-resume': 'Show how to manually enable VC for this user.',
|
|
207
|
+
})) {
|
|
208
|
+
const file = claude ? path.join(hostDir, 'commands', `${name}.md`) : path.join(home, '.agents', 'skills', name, 'SKILL.md');
|
|
209
|
+
const command = `& ${psQuote(exe)} ${name.slice(3)}`;
|
|
210
|
+
const body = `请只向用户展示以下命令,由用户在宿主外的 PowerShell 中手动运行。不要执行命令、调用工具或声称开关已经改变。\n\n\`\`\`powershell\n${command}\n\`\`\`\n`;
|
|
211
|
+
const header = claude ? `---\ndescription: ${description}\n---\n\n` : `---\nname: ${name}\ndescription: ${description} Use only when explicitly invoked by the user.\n---\n\n`;
|
|
212
|
+
edits.push({ name, file, before: await optional(file), after: Buffer.from(header + body), host, stage: claude ? 'stage_entry_install' : 'skill_install' });
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
async function planSkills(host, hostDir, home, exe, edits) {
|
|
217
|
+
const source = path.join(here, 'runtime', 'skills');
|
|
218
|
+
const target = path.join(hostDir, 'skills');
|
|
219
|
+
for (const relative of ['archive/SKILL.md', ...['INT', 'SPEC', 'TCSET', 'PLAN'].map(kind => `archive/templates/${kind}.md`), 'archive/archive.mjs', 'grilling/SKILL.md', 'review/SKILL.md', 'review/references/review-method.md']) {
|
|
220
|
+
const after = relative === 'archive/archive.mjs'
|
|
221
|
+
? Buffer.from(`import { spawnSync } from 'node:child_process';\nconst result = spawnSync(${JSON.stringify(exe)}, ['archive', ...process.argv.slice(2)], { stdio: 'inherit' });\nif (result.error) console.error(result.error.message);\nprocess.exitCode = result.status ?? 1;\n`)
|
|
222
|
+
: await fs.readFile(path.join(source, relative));
|
|
223
|
+
const file = path.join(target, relative);
|
|
224
|
+
edits.push({ name: relative.split('/')[0], file, before: await optional(file), after, host, stage: 'skill_install' });
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
async function listDirectory(dir) {
|
|
229
|
+
try { return await fs.readdir(dir, { withFileTypes: true }); }
|
|
230
|
+
catch (err) { if (err.code === 'ENOENT') return []; throw err; }
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
async function discoverEntries(host, hostDir, home) {
|
|
234
|
+
const found = [];
|
|
235
|
+
if (host === 'claude-code') {
|
|
236
|
+
const dir = path.join(hostDir, 'commands');
|
|
237
|
+
for (const item of await listDirectory(dir)) {
|
|
238
|
+
if (!item.isDirectory() && /\.md$/i.test(item.name)) found.push({ name: item.name.slice(0, -3).toLowerCase(), file: path.join(dir, item.name) });
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
const roots = [path.join(hostDir, 'skills')];
|
|
242
|
+
if (host === 'codex') roots.push(path.join(home, '.agents', 'skills'));
|
|
243
|
+
for (const root of roots) {
|
|
244
|
+
for (const item of await listDirectory(root)) {
|
|
245
|
+
if (!item.isDirectory() && !item.isSymbolicLink()) continue;
|
|
246
|
+
const file = path.join(root, item.name, 'SKILL.md');
|
|
247
|
+
const body = await optional(file);
|
|
248
|
+
if (!body) continue;
|
|
249
|
+
const header = /^\uFEFF?---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/.exec(body.toString('utf8'))?.[1];
|
|
250
|
+
const alias = /^name:\s*["']?([\w-]+)["']?\s*$/m.exec(header ?? '')?.[1];
|
|
251
|
+
for (const name of new Set([item.name.toLowerCase(), alias?.toLowerCase()].filter(Boolean))) found.push({ name, file });
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
return found;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
async function chooseOverwrite(host, name, files) {
|
|
258
|
+
console.error(`[${host}] ${name} — conflicting entry files:\n${files.map(file => ` ${file}`).join('\n')}`);
|
|
259
|
+
if (!process.stdin.isTTY || !process.stdout.isTTY) return false;
|
|
260
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
261
|
+
try { return /^(?:o|overwrite)$/i.test((await rl.question('Overwrite these entries or skip? [o/S] ')).trim()); }
|
|
262
|
+
finally { rl.close(); }
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
// Decide for a whole skill at once, before any files or registrations are changed.
|
|
266
|
+
export async function resolveEntries(host, hostDir, home, entries, choose = chooseOverwrite) {
|
|
267
|
+
const existing = await discoverEntries(host, hostDir, home);
|
|
268
|
+
const result = [];
|
|
269
|
+
for (const name of new Set(entries.map(e => e.name))) {
|
|
270
|
+
const group = entries.filter(e => e.name === name);
|
|
271
|
+
const changed = group.filter(e => !e.before?.equals(e.after));
|
|
272
|
+
const alternate = [...new Set(existing.filter(e => e.name === name && !group.some(g => samePath(g.file, e.file))).map(e => e.file))];
|
|
273
|
+
// Reuse a single identical skill in an alternative discovery root, including
|
|
274
|
+
// its resources. Do not create a duplicate at the canonical target.
|
|
275
|
+
const entry = group.find(e => path.basename(e.file) === 'SKILL.md');
|
|
276
|
+
if (entry && group.every(e => e.before === null) && alternate.length === 1 && path.basename(alternate[0]) === 'SKILL.md') {
|
|
277
|
+
const dir = path.dirname(alternate[0]);
|
|
278
|
+
const matches = await Promise.all(group.map(async e => (await optional(path.join(dir, path.relative(path.dirname(entry.file), e.file))))?.equals(e.after)));
|
|
279
|
+
if (matches.every(Boolean)) continue;
|
|
280
|
+
}
|
|
281
|
+
const conflicts = [...changed.filter(e => e.before !== null).map(e => e.file), ...alternate];
|
|
282
|
+
if (conflicts.length && !await choose(host, name, conflicts)) {
|
|
283
|
+
console.log(`Skipped [${host}] ${name}; existing entry retained.`);
|
|
284
|
+
continue;
|
|
285
|
+
}
|
|
286
|
+
result.push(...changed);
|
|
287
|
+
for (const file of alternate) {
|
|
288
|
+
if (entries.some(e => samePath(e.file, file)) || result.some(e => e.retire && samePath(e.file, file))) fail(`Ambiguous entry name at ${file}; reconcile it before overwriting.`);
|
|
289
|
+
result.push({ file, before: await fs.readFile(file), retire: true, host, stage: group[0].stage });
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
return result;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
async function planAgents(host, hostDir, edits) {
|
|
296
|
+
const claude = host === 'claude-code';
|
|
297
|
+
const folder = path.join(hostDir, 'agents');
|
|
298
|
+
const extension = claude ? '.md' : '.toml';
|
|
299
|
+
const installed = await fs.readdir(folder).catch(error => { if (error.code === 'ENOENT') return []; throw error; });
|
|
300
|
+
for (const name of ['advisor', 'reviewer', 'verifier']) {
|
|
301
|
+
const text = await fs.readFile(path.join(here, 'runtime', 'agents', `${name}.md`), 'utf8');
|
|
302
|
+
const parsed = /^---\r?\n([\s\S]*?)\r?\n---\r?\n([\s\S]+)$/.exec(text);
|
|
303
|
+
const description = parsed?.[1].match(/^description: (.+)$/m)?.[1].trim();
|
|
304
|
+
const declared = parsed?.[1].match(/^name: (.+)$/m)?.[1].trim();
|
|
305
|
+
if (!description || declared?.toLowerCase() !== name || !parsed[2].trim()) fail(`Invalid bundled agent: ${name}`);
|
|
306
|
+
const body = parsed[2].trim();
|
|
307
|
+
for (const entry of installed) {
|
|
308
|
+
if (entry.toLowerCase() === `${name}${extension}` || !entry.endsWith(extension)) continue;
|
|
309
|
+
const other = await fs.readFile(path.join(folder, entry), 'utf8');
|
|
310
|
+
const header = claude ? /^\uFEFF?---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/.exec(other)?.[1] ?? '' : other.split(/^\s*\[/m, 1)[0];
|
|
311
|
+
const match = (claude ? /^\s*name\s*:\s*["']?([\w-]+)/m : /^\s*name\s*=\s*["']([\w-]+)/m).exec(header);
|
|
312
|
+
if (match?.[1].toLowerCase() === name) fail(`Existing agent named ${name} at ${path.join(folder, entry)}; reconcile it before setup.`);
|
|
313
|
+
}
|
|
314
|
+
const after = claude
|
|
315
|
+
? `---\nname: ${name}\ndescription: ${JSON.stringify(description)}\ntools: Read, Grep, Glob\n---\n\n${body}\n`
|
|
316
|
+
: `name = ${JSON.stringify(name)}\ndescription = ${JSON.stringify(description)}\nsandbox_mode = "read-only"\ndeveloper_instructions = ${JSON.stringify(body)}\n`;
|
|
317
|
+
await planResource(path.join(folder, `${name}${extension}`), Buffer.from(after), host, 'agent_install', edits);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
async function configure({ harnesses, target, exe, home, cwd, edits, registrations, progress }) {
|
|
322
|
+
for (const host of harnesses) {
|
|
323
|
+
progress.host = host;
|
|
324
|
+
progress.stage = 'host_version_check';
|
|
325
|
+
cliVersion(host, cwd, progress);
|
|
326
|
+
const claudeOverride = process.env.CLAUDE_CONFIG_DIR;
|
|
327
|
+
const hostDir = host === 'claude-code'
|
|
328
|
+
? path.resolve(claudeOverride || path.join(home, '.claude'))
|
|
329
|
+
: path.resolve(process.env.CODEX_HOME || path.join(home, '.codex'));
|
|
330
|
+
progress.stage = 'stage_entry_check';
|
|
331
|
+
const entries = [];
|
|
332
|
+
await planStageEntries(host, hostDir, entries);
|
|
333
|
+
progress.stage = 'skill_check';
|
|
334
|
+
await planSkills(host, hostDir, home, exe, entries);
|
|
335
|
+
await planControls(host, hostDir, home, exe, entries);
|
|
336
|
+
edits.push(...await resolveEntries(host, hostDir, home, entries));
|
|
337
|
+
progress.stage = 'agent_check';
|
|
338
|
+
await planAgents(host, hostDir, edits);
|
|
339
|
+
progress.stage = 'hook_config_check';
|
|
340
|
+
const hooksPath = path.join(hostDir, host === 'claude-code' ? 'settings.json' : 'hooks.json');
|
|
341
|
+
const config = await jsonFile(hooksPath);
|
|
342
|
+
if (mergeHooks(config.data, host, exe, hooksPath)) edits.push({ ...jsonEdit(hooksPath, config.before, config.data), host, stage: 'hook_registration' });
|
|
343
|
+
progress.stage = 'mcp_config_check';
|
|
344
|
+
const trustFile = host === 'claude-code' ? path.join(claudeOverride ? hostDir : home, '.claude.json') : path.join(hostDir, 'config.toml');
|
|
345
|
+
const args = ['mcp', '--stdio', '--harness', host, '--installed', trustFile];
|
|
346
|
+
if (host === 'claude-code') {
|
|
347
|
+
const mcpPath = trustFile;
|
|
348
|
+
const mcp = await jsonFile(mcpPath);
|
|
349
|
+
mcp.data.mcpServers ??= {};
|
|
350
|
+
object(mcp.data.mcpServers, `${mcpPath}: mcpServers`);
|
|
351
|
+
const old = mcp.data.mcpServers.vc;
|
|
352
|
+
if (Object.hasOwn(mcp.data.mcpServers, 'vc')) {
|
|
353
|
+
if (!samePath(old?.command, exe) || JSON.stringify(old?.args) !== JSON.stringify(args) || old?.type !== 'stdio') fail(`${mcpPath}: a different MCP named vc is already registered`);
|
|
354
|
+
} else {
|
|
355
|
+
mcp.data.mcpServers.vc = { type: 'stdio', command: exe, args };
|
|
356
|
+
edits.push({ ...jsonEdit(mcpPath, mcp.before, mcp.data), host, stage: 'mcp_registration' });
|
|
357
|
+
}
|
|
358
|
+
} else {
|
|
359
|
+
const configPath = trustFile;
|
|
360
|
+
// Codex requires its configured home directory to exist before `mcp get`.
|
|
361
|
+
await fs.mkdir(hostDir, { recursive: true });
|
|
362
|
+
const before = await optional(configPath);
|
|
363
|
+
const get = hostCommand('codex', ['mcp', 'get', '--json', 'vc'], cwd);
|
|
364
|
+
if (get.result === 0) {
|
|
365
|
+
const server = JSON.parse(get.out);
|
|
366
|
+
if (!samePath(server.transport?.command, exe) || JSON.stringify(server.transport?.args) !== JSON.stringify(args) || !server.enabled) fail('A different or disabled Codex MCP named vc is already registered');
|
|
367
|
+
} else {
|
|
368
|
+
if (!/No MCP server named 'vc' found\./.test(get.error)) fail(`Cannot inspect Codex MCP configuration: ${get.error}`);
|
|
369
|
+
registrations.push(() => registerCodex(cwd, configPath, before, exe, args));
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
progress.host = undefined;
|
|
374
|
+
progress.stage = 'runtime_copy';
|
|
375
|
+
await installRuntime(target, path.join(here, 'runtime'));
|
|
376
|
+
// No host configuration mutation until all selected configs have been checked.
|
|
377
|
+
for (const edit of edits) {
|
|
378
|
+
progress.host = edit.host;
|
|
379
|
+
progress.stage = edit.stage;
|
|
380
|
+
await apply(edit);
|
|
381
|
+
progress.events.push({ event: edit.stage, outcome: 'ok', host: edit.host });
|
|
382
|
+
}
|
|
383
|
+
for (const register of registrations) {
|
|
384
|
+
progress.host = 'codex';
|
|
385
|
+
progress.stage = 'mcp_registration';
|
|
386
|
+
await register();
|
|
387
|
+
progress.events.push({ event: 'mcp_registration', outcome: 'ok', host: 'codex' });
|
|
388
|
+
}
|
|
389
|
+
progress.host = undefined;
|
|
390
|
+
progress.stage = 'cleanup';
|
|
391
|
+
console.log(`Installed ${harnesses.join(', ')} for this user. Runtime: ${target}`);
|
|
392
|
+
console.log('Start claude or codex normally in a trusted Git project. Confirm any host trust or tool approval prompts yourself.');
|
|
393
|
+
if (harnesses.includes('codex')) console.log('Codex: review the added hooks with /hooks.');
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
async function registerCodex(cwd, configPath, before, exe, args) {
|
|
397
|
+
const current = await optional(configPath);
|
|
398
|
+
if (before === null ? current !== null : !current?.equals(before)) fail(`Configuration changed during setup: ${configPath}`);
|
|
399
|
+
const added = hostCommand('codex', ['mcp', 'add', 'vc', '--', exe, ...args], cwd);
|
|
400
|
+
if (added.result !== 0) fail(`Codex MCP registration failed: ${added.error}`);
|
|
401
|
+
const checked = hostCommand('codex', ['mcp', 'get', '--json', 'vc'], cwd);
|
|
402
|
+
const actual = checked.result === 0 && JSON.parse(checked.out);
|
|
403
|
+
if (!samePath(actual?.transport?.command, exe) || JSON.stringify(actual.transport?.args) !== JSON.stringify(args)) fail('Codex registered an unexpected MCP command; inspect codex mcp get vc before use.');
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
export async function main(argv) {
|
|
407
|
+
if (argv[0] === '--help' || argv[0] === '-h') {
|
|
408
|
+
console.log('Usage: npx @essrj/vc-workflow setup [--harness claude-code,codex]');
|
|
409
|
+
return;
|
|
410
|
+
}
|
|
411
|
+
if (argv[0] !== 'setup' || (argv.length !== 1 && (argv.length !== 3 || argv[1] !== '--harness'))) fail('Usage: vc-workflow setup [--harness claude-code,codex]');
|
|
412
|
+
let selected = argv[2]?.split(',').map(x => x.trim());
|
|
413
|
+
if (!selected) selected = await chooseHarnesses();
|
|
414
|
+
if (selected.length === 0) return;
|
|
415
|
+
if (selected.some(x => !supported.includes(x))) fail(`Select one or more of: ${supported.join(', ')}`);
|
|
416
|
+
const progress = { stage: 'preflight', events: [] };
|
|
417
|
+
try {
|
|
418
|
+
await setup([...new Set(selected)], progress);
|
|
419
|
+
progress.events.push({ event: 'setup_finish', outcome: 'ok' });
|
|
420
|
+
} catch (err) {
|
|
421
|
+
progress.events.push({ event: 'setup_finish', outcome: 'failed', host: progress.host, reason: progress.stage });
|
|
422
|
+
throw err;
|
|
423
|
+
} finally {
|
|
424
|
+
writeSetupLog(progress);
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
function chooseHarnesses() {
|
|
429
|
+
const { stdin, stdout } = process;
|
|
430
|
+
if (!stdin.isTTY || !stdout.isTTY) fail('Use --harness claude-code,codex for noninteractive setup.');
|
|
431
|
+
const labels = ['Claude Code', 'Codex'];
|
|
432
|
+
const selected = new Set();
|
|
433
|
+
let cursor = 0;
|
|
434
|
+
const draw = () => labels.forEach((label, i) => stdout.write(`${i === cursor ? '>' : ' '} [${selected.has(i) ? 'x' : ' '}] ${label}\n`));
|
|
435
|
+
stdout.write('Enable VC for this user (arrows to move, Space to select, Enter to install, Esc to cancel):\n');
|
|
436
|
+
draw();
|
|
437
|
+
emitKeypressEvents(stdin);
|
|
438
|
+
const wasRaw = stdin.isRaw;
|
|
439
|
+
stdin.setRawMode(true);
|
|
440
|
+
stdin.resume();
|
|
441
|
+
return new Promise(resolve => {
|
|
442
|
+
const finish = (result) => {
|
|
443
|
+
stdin.off('keypress', onKey);
|
|
444
|
+
stdin.setRawMode(wasRaw);
|
|
445
|
+
stdin.pause();
|
|
446
|
+
resolve(result);
|
|
447
|
+
};
|
|
448
|
+
const onKey = (_, key) => {
|
|
449
|
+
if (!key) return;
|
|
450
|
+
if (key.name === 'escape' || (key.ctrl && key.name === 'c')) return finish([]);
|
|
451
|
+
if (key.name === 'return' && selected.size) return finish(supported.filter((_, i) => selected.has(i)));
|
|
452
|
+
if (key.name === 'up') cursor = (cursor + labels.length - 1) % labels.length;
|
|
453
|
+
else if (key.name === 'down') cursor = (cursor + 1) % labels.length;
|
|
454
|
+
else if (key.name === 'space') selected.has(cursor) ? selected.delete(cursor) : selected.add(cursor);
|
|
455
|
+
else return;
|
|
456
|
+
stdout.moveCursor(0, -labels.length);
|
|
457
|
+
stdout.cursorTo(0);
|
|
458
|
+
stdout.clearScreenDown();
|
|
459
|
+
draw();
|
|
460
|
+
};
|
|
461
|
+
stdin.on('keypress', onKey);
|
|
462
|
+
});
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
|
|
466
|
+
main(process.argv.slice(2)).catch(error => { console.error(`vc setup: ${error.message}`); process.exitCode = 1; });
|
|
467
|
+
}
|
package/README.md
DELETED