prizmkit 1.0.13 → 1.0.14

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 (77) hide show
  1. package/bin/create-prizmkit.js +4 -1
  2. package/bundled/VERSION.json +3 -3
  3. package/bundled/adapters/claude/command-adapter.js +35 -4
  4. package/bundled/adapters/claude/rules-adapter.js +6 -58
  5. package/bundled/adapters/claude/team-adapter.js +2 -2
  6. package/bundled/adapters/codebuddy/agent-adapter.js +0 -1
  7. package/bundled/adapters/codebuddy/rules-adapter.js +30 -0
  8. package/bundled/adapters/shared/frontmatter.js +3 -1
  9. package/bundled/dev-pipeline/README.md +13 -3
  10. package/bundled/dev-pipeline/launch-bugfix-daemon.sh +10 -0
  11. package/bundled/dev-pipeline/launch-daemon.sh +18 -4
  12. package/bundled/dev-pipeline/lib/common.sh +105 -0
  13. package/bundled/dev-pipeline/run-bugfix.sh +57 -57
  14. package/bundled/dev-pipeline/run.sh +75 -59
  15. package/bundled/dev-pipeline/scripts/check-session-status.py +47 -2
  16. package/bundled/dev-pipeline/scripts/cleanup-logs.py +192 -0
  17. package/bundled/dev-pipeline/scripts/detect-stuck.py +15 -3
  18. package/bundled/dev-pipeline/scripts/generate-bootstrap-prompt.py +32 -27
  19. package/bundled/dev-pipeline/scripts/generate-bugfix-prompt.py +23 -23
  20. package/bundled/dev-pipeline/scripts/update-feature-status.py +50 -2
  21. package/bundled/dev-pipeline/scripts/utils.py +22 -0
  22. package/bundled/dev-pipeline/templates/bootstrap-tier1.md +18 -1
  23. package/bundled/dev-pipeline/templates/bootstrap-tier2.md +19 -1
  24. package/bundled/dev-pipeline/templates/bootstrap-tier3.md +18 -2
  25. package/bundled/dev-pipeline/templates/session-status-schema.json +7 -1
  26. package/bundled/dev-pipeline/tests/__init__.py +0 -0
  27. package/bundled/dev-pipeline/tests/conftest.py +133 -0
  28. package/bundled/dev-pipeline/tests/test_check_session.py +127 -0
  29. package/bundled/dev-pipeline/tests/test_cleanup_logs.py +119 -0
  30. package/bundled/dev-pipeline/tests/test_detect_stuck.py +207 -0
  31. package/bundled/dev-pipeline/tests/test_generate_bugfix_prompt.py +181 -0
  32. package/bundled/dev-pipeline/tests/test_generate_prompt.py +190 -0
  33. package/bundled/dev-pipeline/tests/test_init_bugfix_pipeline.py +153 -0
  34. package/bundled/dev-pipeline/tests/test_init_pipeline.py +241 -0
  35. package/bundled/dev-pipeline/tests/test_update_bug_status.py +142 -0
  36. package/bundled/dev-pipeline/tests/test_update_feature_status.py +277 -0
  37. package/bundled/dev-pipeline/tests/test_utils.py +141 -0
  38. package/bundled/rules/USAGE.md +153 -0
  39. package/bundled/rules/_rules-metadata.json +43 -0
  40. package/bundled/rules/general/prefer-linux-commands.md +9 -0
  41. package/bundled/rules/prizm/prizm-commit-workflow.md +10 -0
  42. package/bundled/rules/prizm/prizm-documentation.md +19 -0
  43. package/bundled/rules/prizm/prizm-progressive-loading.md +11 -0
  44. package/bundled/skills/_metadata.json +130 -67
  45. package/bundled/skills/app-planner/SKILL.md +252 -499
  46. package/bundled/skills/app-planner/assets/evaluation-guide.md +44 -0
  47. package/bundled/skills/app-planner/scripts/validate-and-generate.py +143 -4
  48. package/bundled/skills/bug-planner/SKILL.md +58 -13
  49. package/bundled/skills/bugfix-pipeline-launcher/SKILL.md +5 -7
  50. package/bundled/skills/dev-pipeline-launcher/SKILL.md +16 -7
  51. package/bundled/skills/feature-workflow/SKILL.md +175 -234
  52. package/bundled/skills/prizm-kit/SKILL.md +17 -31
  53. package/bundled/skills/{prizmkit-adr-manager → prizmkit-tool-adr-manager}/SKILL.md +6 -7
  54. package/bundled/skills/{prizmkit-api-doc-generator → prizmkit-tool-api-doc-generator}/SKILL.md +4 -5
  55. package/bundled/skills/{prizmkit-bug-reproducer → prizmkit-tool-bug-reproducer}/SKILL.md +4 -5
  56. package/bundled/skills/{prizmkit-ci-cd-generator → prizmkit-tool-ci-cd-generator}/SKILL.md +4 -5
  57. package/bundled/skills/{prizmkit-db-migration → prizmkit-tool-db-migration}/SKILL.md +4 -5
  58. package/bundled/skills/{prizmkit-dependency-health → prizmkit-tool-dependency-health}/SKILL.md +3 -4
  59. package/bundled/skills/{prizmkit-deployment-strategy → prizmkit-tool-deployment-strategy}/SKILL.md +4 -5
  60. package/bundled/skills/{prizmkit-error-triage → prizmkit-tool-error-triage}/SKILL.md +4 -5
  61. package/bundled/skills/{prizmkit-log-analyzer → prizmkit-tool-log-analyzer}/SKILL.md +4 -5
  62. package/bundled/skills/{prizmkit-monitoring-setup → prizmkit-tool-monitoring-setup}/SKILL.md +4 -5
  63. package/bundled/skills/{prizmkit-onboarding-generator → prizmkit-tool-onboarding-generator}/SKILL.md +4 -5
  64. package/bundled/skills/{prizmkit-perf-profiler → prizmkit-tool-perf-profiler}/SKILL.md +4 -5
  65. package/bundled/skills/{prizmkit-security-audit → prizmkit-tool-security-audit}/SKILL.md +3 -4
  66. package/bundled/skills/{prizmkit-tech-debt-tracker → prizmkit-tool-tech-debt-tracker}/SKILL.md +3 -4
  67. package/bundled/skills/refactor-skill/SKILL.md +371 -0
  68. package/bundled/skills/refactor-workflow/SKILL.md +17 -119
  69. package/package.json +1 -1
  70. package/src/external-skills.js +71 -0
  71. package/src/index.js +62 -4
  72. package/src/metadata.js +36 -0
  73. package/src/scaffold.js +136 -32
  74. package/bundled/skills/prizmkit-bug-fix-workflow/SKILL.md +0 -356
  75. package/bundled/templates/claude-md-template.md +0 -38
  76. package/bundled/templates/codebuddy-md-template.md +0 -35
  77. /package/bundled/skills/{prizmkit-adr-manager → prizmkit-tool-adr-manager}/assets/adr-template.md +0 -0
@@ -1,12 +1,16 @@
1
1
  ---
2
2
  name: "refactor-workflow"
3
3
  tier: 1
4
- description: "[Tier 1] End-to-end refactor workflow: analyze → plan → tasks → implement → review → commit. 6-phase behavior-preserving pipeline with scope guard and mandatory test gates. (project)"
4
+ description: "[Tier 1] End-to-end refactor workflow: analyze → plan → tasks → implement → review → commit. 6-phase behavior-preserving pipeline with mandatory test gates. (project)"
5
+ ---
6
+
7
+ refactor-workflow-SKILL.md
8
+ refactor-workflow/SKILL.md
5
9
  ---
6
10
 
7
11
  # PrizmKit Refactor Workflow
8
12
 
9
- End-to-end orchestration skill for code refactoring and optimization. Chains existing PrizmKit skills (tech-debt-tracker, plan, tasks, implement, code-review, committer) into a 6-phase behavior-preserving pipeline with scope guard enforcement.
13
+ End-to-end orchestration skill for code refactoring and optimization. Chains existing PrizmKit skills (tech-debt-tracker, plan, tasks, implement, code-review, committer) into a 6-phase behavior-preserving pipeline with mandatory test gates after each task.
10
14
 
11
15
  ## Overview
12
16
 
@@ -32,148 +36,99 @@ prizmkit.refactor <目标模块或描述>
32
36
  | 6 | Commit | `prizmkit.committer` | git commit |
33
37
 
34
38
  ### Key Principles
35
-
36
- - **Behavior preservation**: Refactoring MUST NOT change observable behavior
37
- - **Acceptance criteria** = "behavior unchanged + structure improved"
38
- - **No REGISTRY entry**: Refactoring does not go into REGISTRY.md
39
- - **No spec.md**: Refactoring has no user stories
40
- - **Mandatory test gates**: Full test suite after every task, not just checkpoints
41
- - **Scope guard**: New behavior detected → STOP and suggest feature-workflow
39
+ | Principle | Description |
40
+ |-----------|-------------|
41
+ | **Behavior preservation** | Refactoring MUST NOT change observable behavior. Acceptance criteria = "behavior unchanged + structure improved". |
42
+ | **Test gates** | Full test suite MUST run after EVERY task** — not just at checkpoints. |
43
+ | **No REGISTRY entry** | Refactoring does not go into REGISTRY.md (no user stories, no feature registration). |
44
+ | **Incremental safety** | Each task preserves all tests; if tests fail → STOP and revert. |
42
45
 
43
46
  ### Artifacts
44
-
45
47
  Refactor artifacts stored at `.prizmkit/refactor/<refactor-slug>/`:
46
48
  - **`refactor-analysis.md`** — Code analysis (Phase 1)
47
49
  - **`plan.md`** — Refactoring plan (Phase 2)
48
50
  - **`tasks.md`** — Task breakdown (Phase 3)
49
51
 
50
52
  ## Commands
51
-
52
53
  ### prizmkit.refactor \<目标模块或描述\>
53
-
54
54
  Execute the full refactor pipeline for a module or code area.
55
-
56
55
  **INPUT**: Target description. Can be:
57
56
  - Module or file path (e.g., "src/auth/")
58
57
  - Natural language description (e.g., "重构认证模块,提取公共逻辑")
59
58
  - Specific refactoring goal (e.g., "extract payment processing into separate service")
60
-
61
59
  ---
62
60
 
63
61
  ## Phase 1: Analyze — 代码分析
64
-
65
62
  **Goal**: Assess current code state, identify refactoring targets, establish baseline.
66
-
67
63
  **STEPS:**
68
-
69
64
  1. **Read target code**: Thoroughly read and understand the target module/files:
70
65
  - Code structure and architecture
71
66
  - Dependencies (incoming and outgoing)
72
67
  - Current test coverage
73
68
  - Known tech debt (from `.prizm-docs/` TRAPS)
74
-
75
69
  2. **Invoke `prizmkit.tech-debt-tracker`** on target area:
76
70
  - Receive: debt items, complexity metrics, code smell patterns
77
71
  - Identify highest-impact refactoring opportunities
78
-
79
72
  3. **Establish baseline**:
80
73
  - Run full test suite — record pass/fail counts
81
74
  - Note any pre-existing test failures (isolate from refactor impact)
82
75
  - Document current behavior contracts (public API, interfaces)
83
-
84
76
  4. **Generate `refactor-analysis.md`** at `.prizmkit/refactor/<refactor-slug>/refactor-analysis.md`:
85
-
86
77
  Required sections:
87
78
  - **Current State**: module overview, file inventory, dependency graph, complexity metrics
88
79
  - **Refactoring Goals**: what structural improvements are targeted, why (debt items, complexity, maintainability)
89
80
  - **Risk Assessment**: what could break, cross-module impact, data migration needs
90
81
  - **Baseline Tests**: test suite status (total, passing, failing), coverage estimate, behavior contracts to preserve
91
82
  - **Scope Boundary**: what IS in scope, what is explicitly OUT of scope
92
-
93
83
  **CHECKPOINT CP-RW-1**: `refactor-analysis.md` exists with baseline test results.
94
-
95
84
  ---
96
-
97
85
  ## Phase 2: Plan — 重构方案
98
-
99
86
  **Goal**: Generate technical refactoring plan that preserves behavior.
100
-
101
87
  **STEPS:**
102
-
103
88
  1. **Read context**: refactor-analysis.md, `.prizm-docs/` (PATTERNS, RULES, TRAPS)
104
-
105
89
  2. **Invoke `prizmkit.plan`** with refactor-analysis.md as input (in place of spec.md):
106
90
  - Plan MUST specify: what changes, what stays the same, how behavior is preserved
107
91
  - Artifact path: `.prizmkit/refactor/<refactor-slug>/plan.md`
108
-
109
92
  3. **Verify plan constraints**:
110
- - No new user-facing behavior (scope guard)
111
93
  - All public API contracts preserved
112
94
  - Test strategy: how to verify behavior unchanged at each step
113
95
  - Rollback strategy: how to revert if behavior breaks
114
-
115
96
  **CHECKPOINT CP-RW-2**: `plan.md` exists with behavior preservation strategy.
116
-
117
97
  ---
118
-
119
98
  ## Phase 3: Tasks — 任务拆解
120
-
121
99
  **Goal**: Break refactoring plan into safe, atomic, testable tasks.
122
-
123
100
  **STEPS:**
124
-
125
101
  1. **Invoke `prizmkit.tasks`** with plan.md:
126
102
  - Each task MUST be independently testable
127
103
  - Each task MUST preserve all tests (green → green)
128
104
  - Artifact path: `.prizmkit/refactor/<refactor-slug>/tasks.md`
129
-
130
105
  2. **Verify task safety**:
131
106
  - Every task ends with "run full test suite"
132
107
  - No task introduces temporary test failures
133
108
  - Tasks are ordered to minimize risk (safe renames first, structural changes later)
134
-
135
109
  **CHECKPOINT CP-RW-3**: `tasks.md` exists with test gates on every task.
136
-
137
110
  ---
138
-
139
111
  ## Phase 4: Implement — 实现
140
-
141
112
  **Goal**: Execute refactoring tasks with mandatory test verification after each task.
142
-
143
113
  **STEPS:**
144
-
145
114
  1. **For EACH task in tasks.md**:
146
115
  a. Implement the refactoring change
147
116
  b. **Run FULL test suite** (not just affected tests)
148
117
  c. Verify: all previously-passing tests still pass
149
118
  d. If any test fails → STOP, revert task, investigate
150
-
151
- 2. **Scope Guard** (checked after each task):
152
- - If implementation reveals need for new behavior → **STOP**
153
- - Output: "Scope guard triggered: <description of new behavior needed>"
154
- - Recommend: "Switch to `prizmkit.feature` for this change"
155
- - Do NOT proceed with behavior changes in refactor pipeline
156
-
157
- 3. **Progress tracking**:
119
+ 2. **Progress tracking**:
158
120
  - Mark tasks complete in tasks.md as they finish
159
121
  - Record test results after each task
160
-
161
122
  **CHECKPOINT CP-RW-4**: All tasks complete, full test suite green.
162
-
163
123
  **KEY RULES:**
164
124
  - NEVER skip the test gate between tasks
165
125
  - NEVER allow temporary test failures ("we'll fix it in the next task")
166
126
  - If a task cannot be completed without breaking tests → split it into smaller tasks
167
127
  - Max 3 attempts per task before escalating to user
168
-
169
128
  ---
170
-
171
129
  ## Phase 5: Code Review — 代码审查
172
-
173
130
  **Goal**: Verify refactoring quality and behavior preservation.
174
-
175
131
  **STEPS:**
176
-
177
132
  1. **Invoke `prizmkit.code-review`** (scoped to changed files):
178
133
  - Review dimensions for refactoring:
179
134
  - **Behavior preservation**: Does observable behavior remain identical?
@@ -181,69 +136,47 @@ Execute the full refactor pipeline for a module or code area.
181
136
  - **Test integrity**: Are all tests still meaningful and passing?
182
137
  - **Code quality**: Does refactored code follow project conventions?
183
138
  - Verdict: PASS / PASS_WITH_WARNINGS / NEEDS_FIXES
184
-
185
139
  2. **Run full test suite one final time**: All tests MUST pass
186
-
187
140
  3. **Handle review results**:
188
141
  - **PASS / PASS_WITH_WARNINGS**: Proceed to Phase 6
189
142
  - **NEEDS_FIXES**: Return to Phase 4 (max 2 review rounds)
190
-
191
143
  **CHECKPOINT CP-RW-5**: Code review passes, all tests green.
192
-
193
144
  ---
194
-
195
145
  ## Phase 6: Commit — 提交
196
-
197
146
  **Goal**: Commit with refactor convention.
198
-
199
147
  **STEPS:**
200
-
201
148
  1. **Invoke `prizmkit.committer`**:
202
149
  - Commit message: `refactor(<scope>): <description>`
203
150
  - Include all refactored code + any test updates
204
151
  - Do NOT push
205
152
  - Do NOT invoke `prizmkit.summarize` (no REGISTRY entry for refactoring)
206
-
207
153
  2. **Update `.prizm-docs/`** if needed:
208
154
  - Updated module structure documentation
209
155
  - New PATTERNS discovered
210
156
  - Resolved TRAPS (remove if debt is paid)
211
-
212
157
  **CHECKPOINT CP-RW-6**: Commit recorded with `refactor()` prefix.
213
-
214
158
  ---
215
-
216
159
  ## Fast Path — 快速路径
217
-
218
160
  For single-file refactoring (rename, extract method, <30 lines changed):
219
-
220
161
  ```
221
162
  Phase 1 (Analyze) → Phase 4 (Implement) → Phase 5 (Review) → Phase 6 (Commit)
222
163
  ```
223
-
224
164
  Skip Phase 2 (Plan) and Phase 3 (Tasks).
225
-
226
165
  **CRITERIA** (ALL must be true):
227
166
  - Single file change
228
167
  - Estimated change < 30 lines
229
168
  - Well-known refactoring pattern (rename, extract method/class, inline, move)
230
169
  - No cross-module impact
231
170
  - No dependency changes
232
-
233
171
  **Fast Path still requires:**
234
172
  - refactor-analysis.md (lightweight version with baseline)
235
173
  - Full test suite run after implementation
236
174
  - Code review
237
175
  - `refactor(<scope>):` commit convention
238
-
239
176
  ---
240
-
241
177
  ## Resume — 中断恢复
242
-
243
178
  The pipeline supports resuming from the last completed phase by detecting existing artifacts.
244
-
245
179
  **Detection logic**: Check `.prizmkit/refactor/<slug>/` for:
246
-
247
180
  | Artifact Found | Resume From |
248
181
  |---------------|------------|
249
182
  | (nothing) | Phase 1: Analyze |
@@ -252,70 +185,39 @@ The pipeline supports resuming from the last completed phase by detecting existi
252
185
  | All 3 docs | Phase 4: Implement |
253
186
  | All 3 docs + code changes exist | Phase 5: Review |
254
187
  | All 3 docs + review passed | Phase 6: Commit |
255
-
256
188
  **Resume command**: `prizmkit.refactor <slug>` — if `<slug>` matches an existing `.prizmkit/refactor/<slug>/` directory, resume instead of starting fresh.
257
-
258
189
  ---
259
-
260
- ## Scope Guard — 范围守卫
261
-
262
- The scope guard is a critical safety mechanism that prevents behavior changes from sneaking into refactoring.
263
-
264
- **Triggers:**
265
- - New public API method or endpoint added
266
- - New user-facing feature or UI element
267
- - Changed return values or response formats
268
- - New configuration options
269
- - Modified business logic (not just restructured)
270
-
271
- **When triggered:**
272
- 1. STOP current task immediately
273
- 2. Output clear message: "⚠️ Scope Guard: This change introduces new behavior"
274
- 3. Describe what new behavior was detected
275
- 4. Recommend: "Create a feature request and use `prizmkit.feature` instead"
276
- 5. Offer to continue refactoring WITHOUT the behavior change
277
-
278
- ---
279
-
280
190
  ## Error Handling
281
-
282
191
  | Scenario | Action |
283
192
  |----------|--------|
284
193
  | Cannot identify target module | Ask user for clarification |
285
194
  | No tests exist for target module | WARN user, recommend writing tests first |
286
195
  | Baseline tests already failing | Isolate failures, document, proceed with caution |
287
196
  | Test fails after a refactoring task | Revert task, investigate, retry or split |
288
- | Scope guard triggered | STOP, recommend feature-workflow |
289
197
  | Implementation fails after 3 rounds | Escalate to user with analysis |
290
198
  | Review fails after 2 rounds | Escalate with review findings |
291
199
  | Refactoring creates circular dependency | STOP, revise plan |
292
200
  | Performance regression detected | STOP, investigate, revise approach |
293
-
294
201
  ---
295
-
296
202
  ## Relationship to Other Skills
297
-
298
203
  | Skill | Role in Refactor Workflow |
299
204
  |-------|--------------------------|
300
- | `prizmkit-tech-debt-tracker` | Phase 1: identify debt and complexity |
205
+ | `prizmkit-tool-tech-debt-tracker` | Phase 1: identify debt and complexity |
301
206
  | `prizmkit-plan` | Phase 2: refactoring plan generation |
302
207
  | `prizmkit-tasks` | Phase 3: task breakdown |
303
208
  | `prizmkit-implement` | Phase 4: execute refactoring tasks |
304
209
  | `prizmkit-code-review` | Phase 5: review quality and behavior preservation |
305
210
  | `prizmkit-committer` | Phase 6: commit with `refactor()` convention |
306
- | `feature-workflow` | Handoff target when scope guard triggers |
211
+ | `feature-workflow` | Handoff target when new behavior is needed |
307
212
  | `prizmkit-specify` | NOT used (no user stories for refactoring) |
308
213
  | `prizmkit-analyze` | NOT used (no spec ↔ plan consistency needed) |
309
214
  | `prizmkit-summarize` | NOT used (no REGISTRY entry for refactoring) |
310
215
  | `prizmkit-retrospective` | Optional: post-refactor lessons learned |
311
-
312
216
  ---
313
-
314
217
  ## Comparison with Feature and Bug Fix Pipelines
315
-
316
218
  | Dimension | Feature Workflow | Refactor Workflow | Bug Fix Pipeline |
317
- |-----------|-----------------|-------------------|-----------------|
318
- | Input | Requirement description | Module/code target | Bug description |
219
+ |-----------|-----------------|-------------------|------------------|
220
+ | Input | Natural language requirement | Module/code target | Bug description |
319
221
  | Pipeline Phases | 7 (Fast: 5) | 6 (Fast: 4) | 5 (Fast: 3) |
320
222
  | Phase 1 | Specify (spec.md) | Analyze (refactor-analysis.md) | Triage (fix-plan.md) |
321
223
  | Artifact Path | `.prizmkit/specs/<slug>/` | `.prizmkit/refactor/<slug>/` | `.prizmkit/bugfix/<id>/` |
@@ -324,13 +226,9 @@ The scope guard is a critical safety mechanism that prevents behavior changes fr
324
226
  | Test Strategy | TDD per task | Full suite after EVERY task | Reproduction test |
325
227
  | Scope Guard | N/A | ✅ (enforced) | N/A |
326
228
  | Behavior Change | ✅ Expected | ❌ Forbidden | ✅ Fix behavior |
327
-
328
229
  ## Path References
329
-
330
230
  All internal asset paths MUST use `${SKILL_DIR}` placeholder for cross-IDE compatibility.
331
-
332
231
  ## Output
333
-
334
232
  - `refactor-analysis.md` (Phase 1 artifact)
335
233
  - `plan.md` (Phase 2 artifact)
336
234
  - `tasks.md` (Phase 3 artifact)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prizmkit",
3
- "version": "1.0.13",
3
+ "version": "1.0.14",
4
4
  "description": "Create a new PrizmKit-powered project with clean initialization — no framework dev files, just what you need.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -0,0 +1,71 @@
1
+ /**
2
+ * External Skills Installer
3
+ * Fetches and installs third-party skills from remote URLs.
4
+ */
5
+
6
+ import https from 'node:https';
7
+ import http from 'node:http';
8
+ import path from 'path';
9
+ import fs from 'fs-extra';
10
+
11
+ /**
12
+ * Fetch content from a remote URL (supports http and https)
13
+ * @param {string} url - Remote URL to fetch
14
+ * @returns {Promise<string>} - Content string
15
+ */
16
+ export function fetchRemoteSkill(skill) {
17
+ return new Promise((resolve, reject) => {
18
+ const url = skill.source;
19
+ const protocol = url.startsWith('https://') ? https : http;
20
+
21
+ const request = protocol.get(url, (res) => {
22
+ if (res.statusCode === 301 || res.statusCode === 302) {
23
+ // Follow redirect
24
+ const redirectSkill = { ...skill, source: res.headers.location };
25
+ resolve(fetchRemoteSkill(redirectSkill));
26
+ return;
27
+ }
28
+
29
+ if (res.statusCode !== 200) {
30
+ reject(new Error(`HTTP ${res.statusCode}: ${url}`));
31
+ return;
32
+ }
33
+
34
+ const chunks = [];
35
+ res.on('data', chunk => chunks.push(chunk));
36
+ res.on('end', () => resolve(Buffer.concat(chunks).toString('utf8')));
37
+ res.on('error', reject);
38
+ });
39
+
40
+ request.on('error', reject);
41
+ request.setTimeout(15000, () => {
42
+ request.destroy();
43
+ reject(new Error(`Timeout fetching ${url}`));
44
+ });
45
+ });
46
+ }
47
+
48
+ /**
49
+ * Install an external skill to the target platform directory.
50
+ * @param {Object} skill - Skill definition from external_skills.known
51
+ * @param {string} platform - 'codebuddy' | 'claude'
52
+ * @param {string} projectRoot - Target project root
53
+ * @param {boolean} dryRun - If true, don't write files
54
+ */
55
+ export async function installExternalSkill(skill, platform, projectRoot, dryRun) {
56
+ const content = await fetchRemoteSkill(skill);
57
+
58
+ if (dryRun) {
59
+ return;
60
+ }
61
+
62
+ if (platform === 'codebuddy') {
63
+ const targetDir = path.join(projectRoot, '.codebuddy', 'skills', skill.name);
64
+ await fs.ensureDir(targetDir);
65
+ await fs.writeFile(path.join(targetDir, 'SKILL.md'), content);
66
+ } else if (platform === 'claude') {
67
+ const targetDir = path.join(projectRoot, '.claude', 'commands');
68
+ await fs.ensureDir(targetDir);
69
+ await fs.writeFile(path.join(targetDir, `${skill.name}.md`), content);
70
+ }
71
+ }
package/src/index.js CHANGED
@@ -5,10 +5,9 @@
5
5
  * 然后调用 scaffold.js 执行纯净安装。
6
6
  */
7
7
 
8
- import { select, confirm } from '@inquirer/prompts';
8
+ import { select, confirm, input } from '@inquirer/prompts';
9
9
  import chalk from 'chalk';
10
10
  import path from 'path';
11
- import fs from 'fs-extra';
12
11
  import { detectPlatform } from './detect-platform.js';
13
12
  import { scaffold } from './scaffold.js';
14
13
  import { loadMetadata } from './metadata.js';
@@ -54,6 +53,9 @@ export async function runScaffold(directory, options) {
54
53
  skills: options.skills || 'full',
55
54
  team: options.team !== false,
56
55
  pipeline: options.pipeline !== false,
56
+ rules: options.rules || 'recommended',
57
+ aiCli: options.aiCli || '',
58
+ externalSkills: options.externalSkills ? options.externalSkills.split(',').map(s => s.trim()).filter(Boolean) : [],
57
59
  projectRoot,
58
60
  dryRun: options.dryRun || false,
59
61
  };
@@ -82,8 +84,15 @@ export async function runScaffold(directory, options) {
82
84
  default: detected.suggested,
83
85
  });
84
86
 
87
+ // 1.5. AI CLI 命令配置
88
+ const defaultCli = detected.cbc ? 'cbc' : detected.claude ? 'claude' : '';
89
+ const aiCli = await input({
90
+ message: '底层 AI CLI 可执行命令 (留空自动检测):',
91
+ default: defaultCli,
92
+ });
93
+
85
94
  // 2. 选择技能套件
86
- const skillSuite = await select({
95
+ const skillSuiteChoice = await select({
87
96
  message: '选择技能套件:',
88
97
  choices: [
89
98
  {
@@ -98,10 +107,41 @@ export async function runScaffold(directory, options) {
98
107
  name: `Minimal — 最小可用 (${metadata.suites.minimal.skills.length} 个技能)`,
99
108
  value: 'minimal',
100
109
  },
110
+ {
111
+ name: 'Recommended — 按项目类型推荐 ▸',
112
+ value: 'recommended',
113
+ },
101
114
  ],
102
115
  default: 'full',
103
116
  });
104
117
 
118
+ let skillSuite = skillSuiteChoice;
119
+ if (skillSuiteChoice === 'recommended') {
120
+ const projectType = await select({
121
+ message: '选择项目类型:',
122
+ choices: Object.entries(metadata.recommendations || {}).map(([key, val]) => ({
123
+ name: val.label,
124
+ value: `recommended:${key}`,
125
+ })),
126
+ });
127
+ skillSuite = projectType;
128
+ }
129
+
130
+ // 2.5. 外部 Skill 选择(可选)
131
+ let selectedExternalSkills = [];
132
+ const knownExternalSkills = metadata.external_skills?.known || [];
133
+ if (knownExternalSkills.length > 0) {
134
+ const { checkbox } = await import('@inquirer/prompts');
135
+ selectedExternalSkills = await checkbox({
136
+ message: '选择要安装的第三方 Skills(可选,需要网络):',
137
+ choices: knownExternalSkills.map(s => ({
138
+ name: `${s.name} — ${s.description}`,
139
+ value: s.name,
140
+ checked: false,
141
+ })),
142
+ });
143
+ }
144
+
105
145
  // 3. 团队模式
106
146
  const team = await confirm({
107
147
  message: '启用多 Agent 团队模式 (prizm-dev-team)?',
@@ -114,12 +154,24 @@ export async function runScaffold(directory, options) {
114
154
  default: true,
115
155
  });
116
156
 
157
+ // 5. Rules 预设
158
+ const rulesPreset = await select({
159
+ message: '安装 AI 行为规则 (rules):',
160
+ choices: [
161
+ { name: 'Recommended — 全部规则 (推荐)', value: 'recommended' },
162
+ { name: 'Minimal — 仅渐进式加载 + 通用规则', value: 'minimal' },
163
+ { name: 'None — 不安装规则', value: 'none' },
164
+ ],
165
+ default: 'recommended',
166
+ });
167
+
117
168
  // 显示安装摘要
118
169
  const platformLabel = platform === 'both' ? 'CodeBuddy + Claude Code'
119
170
  : platform === 'codebuddy' ? 'CodeBuddy' : 'Claude Code';
120
171
  const suiteLabel = skillSuite === 'full' ? `Full (${totalSkills} 个)`
121
172
  : skillSuite === 'core' ? `Core (${metadata.suites.core.skills.length} 个)`
122
- : `Minimal (${metadata.suites.minimal.skills.length} 个)`;
173
+ : skillSuite === 'minimal' ? `Minimal (${metadata.suites.minimal.skills.length} 个)`
174
+ : `Recommended (${skillSuite})`;
123
175
 
124
176
  console.log('');
125
177
  console.log(chalk.bold(' 安装摘要:'));
@@ -127,6 +179,9 @@ export async function runScaffold(directory, options) {
127
179
  console.log(` 技能: ${chalk.cyan(suiteLabel)}`);
128
180
  console.log(` 团队模式: ${team ? chalk.green('启用') : chalk.gray('禁用')}`);
129
181
  console.log(` 流水线: ${pipeline ? chalk.green('启用') : chalk.gray('禁用')}`);
182
+ console.log(` 规则: ${chalk.cyan(rulesPreset)}`);
183
+ if (aiCli) console.log(` AI CLI: ${chalk.cyan(aiCli)}`);
184
+ if (selectedExternalSkills.length > 0) console.log(` 外部技能: ${chalk.cyan(selectedExternalSkills.join(', '))}`);
130
185
  console.log(` 目标目录: ${projectRoot}`);
131
186
  console.log('');
132
187
 
@@ -146,6 +201,9 @@ export async function runScaffold(directory, options) {
146
201
  skills: skillSuite,
147
202
  team,
148
203
  pipeline,
204
+ rules: rulesPreset,
205
+ aiCli: aiCli || '',
206
+ externalSkills: selectedExternalSkills,
149
207
  projectRoot,
150
208
  dryRun: options.dryRun || false,
151
209
  };
package/src/metadata.js CHANGED
@@ -51,6 +51,7 @@ export async function loadMetadata() {
51
51
 
52
52
  throw new Error(
53
53
  '无法找到 Skill 元数据文件。\n' +
54
+ `尝试路径:\n 1. ${bundledPath}\n 2. ${corePath}\n` +
54
55
  '请确保在 PrizmKit 框架目录中运行,或已执行 `npm run bundle` 打包资源。'
55
56
  );
56
57
  }
@@ -131,4 +132,39 @@ export function getAdaptersDir() {
131
132
  if (fs.pathExistsSync(coreDir)) return coreDir;
132
133
 
133
134
  throw new Error('无法找到 Adapters 目录。');
135
+ }
136
+
137
+ /**
138
+ * 获取 core rules 目录路径
139
+ */
140
+ export function getRulesDir() {
141
+ const bundledDir = path.join(getBundledRoot(), 'rules');
142
+ const coreDir = path.join(getFrameworkRoot(), 'core', 'rules');
143
+
144
+ if (fs.pathExistsSync(bundledDir)) return bundledDir;
145
+ if (fs.pathExistsSync(coreDir)) return coreDir;
146
+
147
+ throw new Error('无法找到 Rules 目录。');
148
+ }
149
+
150
+ /**
151
+ * 加载 Rules 元数据
152
+ * @returns {Promise<Object>} metadata 对象(包含 rules 和 presets)
153
+ */
154
+ export async function loadRulesMetadata() {
155
+ const bundledPath = path.join(getBundledRoot(), 'rules', '_rules-metadata.json');
156
+ const corePath = path.join(getFrameworkRoot(), 'core', 'rules', '_rules-metadata.json');
157
+
158
+ if (await fs.pathExists(bundledPath)) {
159
+ return fs.readJSON(bundledPath);
160
+ }
161
+
162
+ if (await fs.pathExists(corePath)) {
163
+ return fs.readJSON(corePath);
164
+ }
165
+
166
+ throw new Error(
167
+ '无法找到 Rules 元数据文件。\n' +
168
+ `尝试路径:\n 1. ${bundledPath}\n 2. ${corePath}`
169
+ );
134
170
  }