vc-extras 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (249) hide show
  1. package/README.md +128 -71
  2. package/agent-install.mjs +159 -0
  3. package/agents/tester.md +23 -23
  4. package/install-extras.mjs +41 -109
  5. package/install-menu.mjs +22 -43
  6. package/install-skills.mjs +112 -112
  7. package/package.json +72 -28
  8. package/plugin-registry.mjs +73 -0
  9. package/plugins/config-ui/index.ts +159 -159
  10. package/plugins/config-ui/lib/arguments.mjs +24 -24
  11. package/plugins/config-ui/lib/documents.mjs +67 -67
  12. package/plugins/config-ui/lib/frontmatter.mjs +91 -91
  13. package/plugins/config-ui/lib/open.mjs +16 -16
  14. package/plugins/config-ui/lib/ownership.mjs +99 -99
  15. package/plugins/config-ui/lib/page.mjs +11 -11
  16. package/plugins/config-ui/lib/patch.mjs +35 -35
  17. package/plugins/config-ui/lib/paths.mjs +14 -14
  18. package/plugins/config-ui/lib/plugin-fields.mjs +86 -86
  19. package/plugins/config-ui/lib/plugin-validation.mjs +28 -28
  20. package/plugins/config-ui/lib/redaction.mjs +8 -8
  21. package/plugins/config-ui/lib/registry.mjs +282 -282
  22. package/plugins/config-ui/lib/secrets.mjs +44 -44
  23. package/plugins/config-ui/lib/server.mjs +250 -250
  24. package/plugins/config-ui/lib/sources.mjs +96 -96
  25. package/plugins/config-ui/lib/state.mjs +156 -156
  26. package/plugins/config-ui/lib/themes.mjs +113 -113
  27. package/plugins/config-ui/lib/writer.mjs +690 -690
  28. package/plugins/config-ui/project-local-owner.ts +106 -106
  29. package/plugins/config-ui/vc-extras.plugin.json +13 -0
  30. package/plugins/config-ui/web/app.mjs +997 -997
  31. package/plugins/config-ui/web/index.html +342 -342
  32. package/plugins/pi-blackhole/vc-extras.plugin.json +12 -0
  33. package/plugins/pi-btw/vc-extras.plugin.json +12 -0
  34. package/plugins/pi-claude-code/vc-extras.plugin.json +12 -0
  35. package/plugins/pi-fff/vc-extras.plugin.json +12 -0
  36. package/plugins/pi-jev-auto-mode/vc-extras.plugin.json +12 -0
  37. package/plugins/pi-mcp-adapter/vc-extras.plugin.json +12 -0
  38. package/plugins/pi-web-access/vc-extras.plugin.json +12 -0
  39. package/plugins/vc-ask/claude-hook.mjs +37 -0
  40. package/plugins/vc-ask/codex-native.mjs +28 -0
  41. package/plugins/vc-ask/host-channel.mjs +75 -0
  42. package/plugins/vc-ask/index.ts +57 -0
  43. package/plugins/vc-ask/native-questions.mjs +33 -0
  44. package/plugins/vc-ask/package.json +10 -0
  45. package/plugins/vc-ask/payload.ts +170 -0
  46. package/plugins/vc-ask/questionnaire/LICENSE.ask-user-question +21 -0
  47. package/plugins/vc-ask/questionnaire/UPSTREAM.md +104 -0
  48. package/plugins/vc-ask/questionnaire/answer-channel.ts +135 -0
  49. package/plugins/vc-ask/questionnaire/config.ts +180 -0
  50. package/plugins/vc-ask/questionnaire/events.ts +154 -0
  51. package/plugins/vc-ask/questionnaire/execute.ts +688 -0
  52. package/plugins/vc-ask/questionnaire/i18n.ts +73 -0
  53. package/plugins/vc-ask/questionnaire/inline-entry.ts +312 -0
  54. package/plugins/vc-ask/questionnaire/locales/de.json +43 -0
  55. package/plugins/vc-ask/questionnaire/locales/en.json +42 -0
  56. package/plugins/vc-ask/questionnaire/locales/es.json +43 -0
  57. package/plugins/vc-ask/questionnaire/locales/fr.json +43 -0
  58. package/plugins/vc-ask/questionnaire/locales/pt-BR.json +43 -0
  59. package/plugins/vc-ask/questionnaire/locales/pt.json +43 -0
  60. package/plugins/vc-ask/questionnaire/locales/ru.json +43 -0
  61. package/plugins/vc-ask/questionnaire/locales/uk.json +43 -0
  62. package/plugins/vc-ask/questionnaire/locales/zh.json +46 -0
  63. package/plugins/vc-ask/questionnaire/presentation.ts +11 -0
  64. package/plugins/vc-ask/questionnaire/question-preview.ts +6 -0
  65. package/plugins/vc-ask/questionnaire/rpc.ts +221 -0
  66. package/plugins/vc-ask/questionnaire/session-timeout.ts +67 -0
  67. package/plugins/vc-ask/questionnaire/state/build-questionnaire.ts +144 -0
  68. package/plugins/vc-ask/questionnaire/state/external-editor.ts +62 -0
  69. package/plugins/vc-ask/questionnaire/state/geometry.ts +131 -0
  70. package/plugins/vc-ask/questionnaire/state/key-router.ts +382 -0
  71. package/plugins/vc-ask/questionnaire/state/panel-router.ts +32 -0
  72. package/plugins/vc-ask/questionnaire/state/questionnaire-session.ts +642 -0
  73. package/plugins/vc-ask/questionnaire/state/row-intent.ts +143 -0
  74. package/plugins/vc-ask/questionnaire/state/selectors/contract.ts +24 -0
  75. package/plugins/vc-ask/questionnaire/state/selectors/derivations.ts +40 -0
  76. package/plugins/vc-ask/questionnaire/state/selectors/focus.ts +17 -0
  77. package/plugins/vc-ask/questionnaire/state/selectors/projections.ts +99 -0
  78. package/plugins/vc-ask/questionnaire/state/state-reducer.ts +455 -0
  79. package/plugins/vc-ask/questionnaire/state/state.ts +90 -0
  80. package/plugins/vc-ask/questionnaire/state/vertical.ts +158 -0
  81. package/plugins/vc-ask/questionnaire/timeout.ts +59 -0
  82. package/plugins/vc-ask/questionnaire/tool/external-answer.ts +103 -0
  83. package/plugins/vc-ask/questionnaire/tool/format-answer.ts +24 -0
  84. package/plugins/vc-ask/questionnaire/tool/normalize-params.ts +37 -0
  85. package/plugins/vc-ask/questionnaire/tool/response-envelope.ts +75 -0
  86. package/plugins/vc-ask/questionnaire/tool/types.ts +74 -0
  87. package/plugins/vc-ask/questionnaire/tool/validate-questionnaire.ts +75 -0
  88. package/plugins/vc-ask/questionnaire/view/card-theme.ts +245 -0
  89. package/plugins/vc-ask/questionnaire/view/components/inline-input.ts +66 -0
  90. package/plugins/vc-ask/questionnaire/view/components/multi-select-view.ts +177 -0
  91. package/plugins/vc-ask/questionnaire/view/components/option-list-view.ts +65 -0
  92. package/plugins/vc-ask/questionnaire/view/components/preview/markdown-content-cache.ts +101 -0
  93. package/plugins/vc-ask/questionnaire/view/components/preview/preview-block-renderer.ts +130 -0
  94. package/plugins/vc-ask/questionnaire/view/components/preview/preview-box-renderer.ts +86 -0
  95. package/plugins/vc-ask/questionnaire/view/components/preview/preview-layout-decider.ts +204 -0
  96. package/plugins/vc-ask/questionnaire/view/components/preview/preview-pane.ts +257 -0
  97. package/plugins/vc-ask/questionnaire/view/components/submit-picker.ts +65 -0
  98. package/plugins/vc-ask/questionnaire/view/components/tab-bar.ts +57 -0
  99. package/plugins/vc-ask/questionnaire/view/components/wrapping-select.ts +269 -0
  100. package/plugins/vc-ask/questionnaire/view/dialog-builder.ts +319 -0
  101. package/plugins/vc-ask/questionnaire/view/document-theme.ts +53 -0
  102. package/plugins/vc-ask/questionnaire/view/document-view.ts +306 -0
  103. package/plugins/vc-ask/questionnaire/view/panel-chrome.ts +133 -0
  104. package/plugins/vc-ask/questionnaire/view/props-adapter.ts +77 -0
  105. package/plugins/vc-ask/questionnaire/view/stateful-view.ts +24 -0
  106. package/plugins/vc-ask/questionnaire/view/tab-components.ts +16 -0
  107. package/plugins/vc-ask/questionnaire/view/tab-content-strategy.ts +280 -0
  108. package/plugins/vc-ask/questionnaire/view/vertical-view.ts +218 -0
  109. package/plugins/vc-ask/user-input-events.ts +34 -0
  110. package/plugins/vc-ask/vc-extras.plugin.json +18 -0
  111. package/plugins/vc-footer/agents/claude-code/adapter.mjs +29 -0
  112. package/plugins/vc-footer/agents/claude-code/cli.mjs +23 -0
  113. package/plugins/vc-footer/agents/claude-code/renderer.mjs +1 -0
  114. package/plugins/vc-footer/agents/claude-code/types.d.ts +38 -0
  115. package/plugins/vc-footer/agents/codex/adapter.mjs +13 -0
  116. package/plugins/vc-footer/agents/codex/mcp.mjs +45 -0
  117. package/plugins/vc-footer/agents/codex/native.mjs +19 -0
  118. package/plugins/vc-footer/agents/codex/renderer.mjs +2 -0
  119. package/plugins/vc-footer/agents/pi/adapter.mjs +23 -0
  120. package/plugins/vc-footer/agents/pi/index.js +84 -0
  121. package/plugins/vc-footer/agents/pi/project-local-owner.mjs +97 -0
  122. package/plugins/vc-footer/agents/pi/renderer.mjs +5 -0
  123. package/plugins/vc-footer/core/data.mjs +218 -0
  124. package/plugins/vc-footer/core/render.mjs +291 -0
  125. package/plugins/vc-footer/core/types.d.ts +29 -0
  126. package/plugins/vc-footer/package.json +22 -0
  127. package/plugins/vc-footer/vc-extras.plugin.json +32 -0
  128. package/skills/animate/LICENSE +21 -21
  129. package/skills/animate/RECIPES.md +324 -324
  130. package/skills/animate/SKILL.md +208 -208
  131. package/skills/animate/UPSTREAM.md +19 -19
  132. package/skills/animation-performance/LICENSE +21 -21
  133. package/skills/animation-performance/SKILL.md +223 -223
  134. package/skills/animation-performance/UPSTREAM.md +19 -19
  135. package/skills/answer-me-with-html/SKILL.md +174 -174
  136. package/skills/answer-me-with-html/scripts/am.mjs +12896 -12896
  137. package/skills/apple-design/LICENSE +21 -21
  138. package/skills/apple-design/SKILL.md +291 -291
  139. package/skills/apple-design/UPSTREAM.md +19 -19
  140. package/skills/bad-smell/SKILL.md +44 -44
  141. package/skills/commit/SKILL.md +90 -90
  142. package/skills/emil-design-eng/LICENSE +21 -21
  143. package/skills/emil-design-eng/SKILL.md +677 -677
  144. package/skills/emil-design-eng/UPSTREAM.md +19 -19
  145. package/skills/find-the-truth/SKILL.md +38 -38
  146. package/skills/find-the-truth/references/trace-method.md +48 -48
  147. package/skills/find-the-truth/references/truth-method.md +39 -39
  148. package/skills/gestures/LICENSE +21 -21
  149. package/skills/gestures/SKILL.md +107 -107
  150. package/skills/gestures/UPSTREAM.md +19 -19
  151. package/skills/humanizer-zh/LICENSE +21 -21
  152. package/skills/humanizer-zh/SKILL.md +409 -409
  153. package/skills/humanizer-zh/UPSTREAM.md +7 -7
  154. package/skills/impeccable/LICENSE +191 -191
  155. package/skills/impeccable/NOTICE.md +11 -11
  156. package/skills/impeccable/SKILL.md +89 -89
  157. package/skills/impeccable/licenses/modern-screenshot-MIT.txt +8 -8
  158. package/skills/impeccable/licenses/platform-design-skills-MIT.txt +21 -21
  159. package/skills/impeccable/reference/adapt.md +318 -318
  160. package/skills/impeccable/reference/adapt.native.md +58 -58
  161. package/skills/impeccable/reference/android.md +46 -46
  162. package/skills/impeccable/reference/animate.md +89 -89
  163. package/skills/impeccable/reference/audit.md +139 -139
  164. package/skills/impeccable/reference/audit.native.md +139 -139
  165. package/skills/impeccable/reference/bolder.md +33 -33
  166. package/skills/impeccable/reference/clarify.md +94 -94
  167. package/skills/impeccable/reference/colorize.md +86 -86
  168. package/skills/impeccable/reference/component-review.md +63 -63
  169. package/skills/impeccable/reference/craft-floor.md +44 -44
  170. package/skills/impeccable/reference/craft.md +5 -5
  171. package/skills/impeccable/reference/critique.md +819 -819
  172. package/skills/impeccable/reference/degraded/asset-producer.md +41 -41
  173. package/skills/impeccable/reference/degraded/documenter.md +23 -23
  174. package/skills/impeccable/reference/degraded/finish-reviewer.md +37 -37
  175. package/skills/impeccable/reference/degraded/manual-edit-applier.md +92 -92
  176. package/skills/impeccable/reference/delight.md +70 -70
  177. package/skills/impeccable/reference/distill.md +111 -111
  178. package/skills/impeccable/reference/doctor.md +54 -54
  179. package/skills/impeccable/reference/document.md +416 -416
  180. package/skills/impeccable/reference/extract.md +69 -69
  181. package/skills/impeccable/reference/generate.md +101 -101
  182. package/skills/impeccable/reference/harden.md +362 -362
  183. package/skills/impeccable/reference/hooks.md +114 -114
  184. package/skills/impeccable/reference/init.md +131 -131
  185. package/skills/impeccable/reference/ios.md +51 -51
  186. package/skills/impeccable/reference/layout.md +84 -84
  187. package/skills/impeccable/reference/live-setup.md +104 -104
  188. package/skills/impeccable/reference/live.md +327 -327
  189. package/skills/impeccable/reference/mode-operate.md +21 -21
  190. package/skills/impeccable/reference/mode-persuade.md +19 -19
  191. package/skills/impeccable/reference/mode-read.md +21 -21
  192. package/skills/impeccable/reference/new-work.md +152 -152
  193. package/skills/impeccable/reference/onboard.md +234 -234
  194. package/skills/impeccable/reference/operate.md +61 -61
  195. package/skills/impeccable/reference/optimize.md +257 -257
  196. package/skills/impeccable/reference/overdrive.md +127 -127
  197. package/skills/impeccable/reference/polish.md +105 -105
  198. package/skills/impeccable/reference/quieter.md +99 -99
  199. package/skills/impeccable/reference/region-map.md +26 -26
  200. package/skills/impeccable/reference/routing.md +24 -24
  201. package/skills/impeccable/reference/shape.md +59 -59
  202. package/skills/impeccable/reference/typeset.md +90 -90
  203. package/skills/impeccable/reference/visualize.md +47 -47
  204. package/skills/impeccable/scripts/VERSION +1 -1
  205. package/skills/impeccable/scripts/command-metadata.json +98 -98
  206. package/skills/impeccable/scripts/data/font-index-failures.json +120 -120
  207. package/skills/impeccable/scripts/engine-checksums.txt +9 -9
  208. package/skills/impeccable/scripts/impeccable +249 -249
  209. package/skills/impeccable/scripts/impeccable.cmd +278 -278
  210. package/skills/impeccable/scripts/live-browser-dom.js +320 -320
  211. package/skills/impeccable/scripts/live-browser-ignores.js +246 -246
  212. package/skills/impeccable/scripts/live-browser-session.js +183 -183
  213. package/skills/impeccable/scripts/live-browser.js +13862 -13862
  214. package/skills/impeccable/scripts/modern-screenshot.umd.js +14 -14
  215. package/skills/improve-animations/AUDIT.md +115 -115
  216. package/skills/improve-animations/LICENSE +21 -21
  217. package/skills/improve-animations/PLAN-TEMPLATE.md +73 -73
  218. package/skills/improve-animations/SKILL.md +110 -110
  219. package/skills/improve-animations/UPSTREAM.md +19 -19
  220. package/skills/pick-ui-library/LICENSE +21 -21
  221. package/skills/pick-ui-library/SKILL.md +85 -85
  222. package/skills/pick-ui-library/UPSTREAM.md +19 -19
  223. package/skills/review-animations/LICENSE +21 -21
  224. package/skills/review-animations/SKILL.md +120 -120
  225. package/skills/review-animations/STANDARDS.md +187 -187
  226. package/skills/review-animations/UPSTREAM.md +19 -19
  227. package/skills/test/SKILL.md +29 -29
  228. package/skills/test/references/test-method.md +60 -60
  229. package/skills/write-doc/SKILL.md +115 -115
  230. package/skills/write-doc/examples/result-report.md +53 -53
  231. package/skills/write-doc/examples/task-summary.md +45 -45
  232. package/skills/write-doc/references/terminology.md +147 -147
  233. package/specs/ask-host-protocol-v1.md +58 -0
  234. package/specs/design-demo.md +1102 -1102
  235. package/specs/frontend-immersive.md +28 -28
  236. package/specs/plugin-install-v2.md +123 -0
  237. package/specs/plugin-install.md +38 -0
  238. package/specs/web-modes/explore.md +31 -31
  239. package/specs/web-modes/risk.md +15 -15
  240. package/specs/web-modes/verify.md +16 -16
  241. package/vc-extras.mjs +46 -62
  242. package/plugins/essrj/context.ts +0 -47
  243. package/plugins/essrj/data.ts +0 -190
  244. package/plugins/essrj/index.ts +0 -139
  245. package/plugins/essrj/package.json +0 -12
  246. package/plugins/essrj/project-local-owner.ts +0 -106
  247. package/plugins/essrj/render.ts +0 -217
  248. package/plugins/essrj/types.ts +0 -40
  249. package/plugins.json +0 -38
package/install-menu.mjs CHANGED
@@ -1,63 +1,42 @@
1
1
  import { emitKeypressEvents } from 'node:readline';
2
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 } = {}) {
3
+ export function chooseAgents(agents, options = {}) {
4
+ return chooseList('选择要安装到哪些 Agent:', agents.map(id => ({ id, label: id })), { ...options, preview: false });
5
+ }
6
+
7
+ export function chooseTargets(targets, options = {}) {
8
+ return chooseList('选择要安装的插件:', targets, options);
9
+ }
10
+
11
+ function chooseList(title, items, { input = process.stdin, terminal = process.stdout, preview = true, describe = item => item.label } = {}) {
5
12
  if (!input.isTTY || !terminal.isTTY || typeof input.setRawMode !== 'function') {
6
13
  throw new Error('交互安装需要终端。可用 --help 查看非交互命令。');
7
14
  }
8
15
  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 退出',
16
+ let position = 0, confirming = false, lines = 0;
17
+ const selected = new Set(), wasRaw = input.isRaw, wasPaused = input.isPaused();
18
+ const render = rows => { if (lines) terminal.write(`\x1b[${lines}F\x1b[J`); terminal.write(rows.join('\n') + '\n'); lines = rows.length; };
19
+ const draw = () => render(confirming ? ['确认安装:', ...items.filter(item => selected.has(item.id)).map(item => ` ${describe(item)}`), 'Enter 安装 · Backspace 返回 · Esc 取消'] : [
20
+ `${title} ↑/↓ 移动 · 空格勾选 · Enter ${preview ? '预览' : '下一步'} · Esc 退出`,
26
21
  ...items.map(({ id, label }, i) => `${i === position ? '>' : ' '} [${selected.has(id) ? 'x' : ' '}] ${label}`),
27
22
  ]);
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
- };
23
+ const done = result => { input.off('keypress', onKey); input.off('end', cancel); input.setRawMode(Boolean(wasRaw)); if (wasPaused || !wasRaw) input.pause(); resolve(result); };
35
24
  const cancel = () => done(null);
36
25
  const onKey = (_, key = {}) => {
37
26
  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
- }
27
+ if (confirming) { if (key.name === 'return' || key.name === 'enter') return done(items.filter(item => selected.has(item.id)).map(item => item.id)); if (key.name === 'backspace') { confirming = false; draw(); } return; }
43
28
  switch (key.name) {
44
29
  case 'up': position = (position + items.length - 1) % items.length; break;
45
30
  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;
31
+ case 'space': { const id = items[position].id; if (selected.has(id)) selected.delete(id); else selected.add(id); break; }
32
+ case 'return': case 'enter': if (selected.size) { if (!preview) return done(items.filter(item => selected.has(item.id)).map(item => item.id)); confirming = true; } break;
52
33
  default: return;
53
34
  }
54
35
  draw();
55
36
  };
56
- emitKeypressEvents(input);
57
- input.setRawMode(true);
58
- input.on('keypress', onKey);
59
- input.once('end', cancel);
60
- input.resume();
61
- draw();
37
+ emitKeypressEvents(input); input.setRawMode(true); input.on('keypress', onKey); input.once('end', cancel); input.resume(); draw();
62
38
  });
63
39
  }
40
+
41
+ // Compatibility entry point for callers that already supply one flat list.
42
+ export function choose(items, options) { return chooseTargets(items, options); }
@@ -1,112 +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
- }
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,28 +1,72 @@
1
- {
2
- "name": "vc-extras",
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
- }
1
+ {
2
+ "name": "vc-extras",
3
+ "version": "0.1.1",
4
+ "description": "Optional skills and companion plugins for the vc Pi workflow",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "keywords": [
8
+ "pi-package",
9
+ "agent-skills"
10
+ ],
11
+ "engines": {
12
+ "node": ">=22.19.0"
13
+ },
14
+ "bin": {
15
+ "vc-extras": "./vc-extras.mjs"
16
+ },
17
+ "scripts": {
18
+ "test": "node --test"
19
+ },
20
+ "dependencies": {
21
+ "smol-toml": "1.9.1"
22
+ },
23
+ "devDependencies": {
24
+ "@earendil-works/pi-tui": "1.2.0",
25
+ "tsx": "^4.23.15"
26
+ },
27
+ "files": [
28
+ "skills/",
29
+ "agents/",
30
+ "specs/*.md",
31
+ "specs/web-modes/",
32
+ "vc-extras.mjs",
33
+ "install-skills.mjs",
34
+ "install-extras.mjs",
35
+ "install-menu.mjs",
36
+ "plugin-registry.mjs",
37
+ "agent-install.mjs",
38
+ "plugins/*/vc-extras.plugin.json",
39
+ "plugins/vc-footer/",
40
+ "plugins/vc-ask/",
41
+ "plugins/config-ui/vc-extras.plugin.json",
42
+ "plugins/config-ui/*.ts",
43
+ "plugins/config-ui/package.json",
44
+ "plugins/config-ui/lib/",
45
+ "plugins/config-ui/web/"
46
+ ],
47
+ "pi": {
48
+ "skills": [
49
+ "./skills/animate",
50
+ "./skills/animation-performance",
51
+ "./skills/answer-me-with-html",
52
+ "./skills/apple-design",
53
+ "./skills/bad-smell",
54
+ "./skills/commit",
55
+ "./skills/emil-design-eng",
56
+ "./skills/find-the-truth",
57
+ "./skills/gestures",
58
+ "./skills/humanizer-zh",
59
+ "./skills/impeccable",
60
+ "./skills/improve-animations",
61
+ "./skills/pick-ui-library",
62
+ "./skills/review-animations",
63
+ "./skills/test",
64
+ "./skills/write-doc"
65
+ ],
66
+ "subagents": {
67
+ "agents": [
68
+ "./agents"
69
+ ]
70
+ }
71
+ }
72
+ }
@@ -0,0 +1,73 @@
1
+ import { readdirSync, readFileSync, realpathSync, lstatSync } from 'node:fs';
2
+ import { resolve, relative, isAbsolute, sep } from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
4
+
5
+ export const AGENTS = ['pi', 'claude-code', 'codex'];
6
+ const kinds = { pi: ['pi-package'], 'claude-code': ['claude-statusline', 'claude-ask-hook'], codex: ['codex-statusline-mcp'] };
7
+ const defaultRoot = fileURLToPath(new URL('./plugins/', import.meta.url));
8
+ export function ownedPath(root, name) {
9
+ if (typeof name !== 'string' || !name || isAbsolute(name)) throw new Error('Invalid local path');
10
+ const target = resolve(root, name), rel = relative(root, target);
11
+ if (!rel || rel === '..' || rel.startsWith(`..${sep}`) || isAbsolute(rel)) throw new Error(`Path escapes plugin: ${name}`);
12
+ const real = realpathSync(target), realRel = relative(realpathSync(root), real);
13
+ if (realRel === '..' || realRel.startsWith(`..${sep}`) || isAbsolute(realRel)) throw new Error(`Linked path escapes plugin: ${name}`);
14
+ return target;
15
+ }
16
+ export function localFiles(root, agent, target) {
17
+ const entry = ownedPath(root, target.entry);
18
+ if (!lstatSync(entry).isFile()) throw new Error(`Invalid entry: ${target.entry}`);
19
+ const pkg = agent === 'pi' ? JSON.parse(readFileSync(ownedPath(root, 'package.json'), 'utf8')) : null;
20
+ if (agent === 'pi' && (!Array.isArray(pkg?.pi?.extensions) || !pkg.pi.extensions.includes(target.entry))) {
21
+ throw new Error(`Pi 包未声明该入口:${target.entry}`);
22
+ }
23
+ const files = target.files === undefined ? pkg?.files : target.files;
24
+ if (!Array.isArray(files) || !files.length) throw new Error(`Missing or invalid runtime files: ${target.entry}`);
25
+ const entries = new Set();
26
+ let includesEntry = false;
27
+ for (const file of [...(agent === 'pi' ? ['package.json'] : []), ...files]) {
28
+ const path = ownedPath(root, file), info = lstatSync(path);
29
+ if (!info.isFile() && !info.isDirectory()) throw new Error(`Invalid runtime file: ${file}`);
30
+ entries.add(relative(root, path));
31
+ const rel = relative(path, entry);
32
+ if (!rel || (info.isDirectory() && rel !== '..' && !rel.startsWith(`..${sep}`) && !isAbsolute(rel))) includesEntry = true;
33
+ }
34
+ if (!includesEntry) throw new Error(`安装文件未包含入口:${target.entry}`);
35
+ return [...entries];
36
+ }
37
+ export function discoverPlugins(root = defaultRoot) {
38
+ const plugins = [], ids = new Set();
39
+ for (const dir of readdirSync(root, { withFileTypes: true }).sort((a,b) => a.name.localeCompare(b.name))) {
40
+ if (!dir.isDirectory()) continue;
41
+ const folder = resolve(root, dir.name), file = resolve(folder, 'vc-extras.plugin.json');
42
+ if (!lstatSync(file, { throwIfNoEntry: false })) continue;
43
+ if (!lstatSync(file).isFile()) throw new Error(`Invalid manifest: ${file}`);
44
+ const m = JSON.parse(readFileSync(file, 'utf8'));
45
+ if (m.protocol !== 'vc-extras/plugin' || m.protocolVersion !== 1) throw new Error(`Unsupported plugin protocol: ${file}`);
46
+ if (typeof m.id !== 'string' || !/^[a-z0-9][a-z0-9-]*$/.test(m.id) || ids.has(m.id)) throw new Error(`Invalid or duplicate plugin id: ${m.id}`);
47
+ if (!m.targets || typeof m.targets !== 'object' || Array.isArray(m.targets) || !Object.keys(m.targets).length) throw new Error(`Missing targets: ${m.id}`);
48
+ for (const [agent, target] of Object.entries(m.targets)) {
49
+ if (!AGENTS.includes(agent) || !target || !kinds[agent].includes(target.kind)) throw new Error(`Unsupported target: ${m.id}/${agent}`);
50
+ if (target.dependencies !== undefined && (agent !== 'pi' || typeof target.dependencies !== 'boolean')) throw new Error(`Invalid dependencies flag: ${m.id}`);
51
+ if (target.source !== undefined) {
52
+ if (agent !== 'pi' || typeof target.source !== 'string' || !/^npm:(?:@[a-z0-9._-]+\/)?[a-z0-9._-]+(?:@[a-zA-Z0-9.*^~+-]+)?$/.test(target.source)) throw new Error(`Invalid package source: ${m.id}`);
53
+ } else localFiles(folder, agent, target);
54
+ }
55
+ ids.add(m.id); plugins.push({ ...m, root: folder });
56
+ }
57
+ return plugins;
58
+ }
59
+ export function targetChoices(agents, plugins = discoverPlugins()) {
60
+ if (!agents.every(a => AGENTS.includes(a))) throw new Error('Unknown agent');
61
+ return [...new Set(agents)].flatMap(agent => plugins.filter(p => p.targets[agent]).map(p => ({
62
+ id: `${p.id}:${agent}`, label: `${agent} · ${p.label || p.id}`, plugin: p.id, agent,
63
+ })));
64
+ }
65
+ export function createPlan(keys, plugins = discoverPlugins()) {
66
+ return [...new Set(keys)].map(key => {
67
+ const [id, agent, extra] = key.split(':');
68
+ const plugin = plugins.find(p => p.id === id);
69
+ if (extra !== undefined || !AGENTS.includes(agent) || !plugin || !Object.hasOwn(plugin.targets, agent)) throw new Error(`Unknown installation target: ${key}`);
70
+ const { kind, source, entry, files, dependencies } = plugin.targets[agent];
71
+ return { key, id, agent, root: plugin.root, label: plugin.label || id, kind, source, entry, files, dependencies };
72
+ });
73
+ }