prizmkit 1.0.13 → 1.0.15

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 (84) 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/retry-bug.sh +20 -2
  14. package/bundled/dev-pipeline/retry-feature.sh +20 -2
  15. package/bundled/dev-pipeline/run-bugfix.sh +57 -57
  16. package/bundled/dev-pipeline/run.sh +75 -59
  17. package/bundled/dev-pipeline/scripts/check-session-status.py +47 -2
  18. package/bundled/dev-pipeline/scripts/cleanup-logs.py +192 -0
  19. package/bundled/dev-pipeline/scripts/detect-stuck.py +15 -3
  20. package/bundled/dev-pipeline/scripts/generate-bootstrap-prompt.py +32 -27
  21. package/bundled/dev-pipeline/scripts/generate-bugfix-prompt.py +23 -23
  22. package/bundled/dev-pipeline/scripts/update-feature-status.py +50 -2
  23. package/bundled/dev-pipeline/scripts/utils.py +22 -0
  24. package/bundled/dev-pipeline/templates/bootstrap-tier1.md +18 -1
  25. package/bundled/dev-pipeline/templates/bootstrap-tier2.md +19 -1
  26. package/bundled/dev-pipeline/templates/bootstrap-tier3.md +18 -2
  27. package/bundled/dev-pipeline/templates/session-status-schema.json +7 -1
  28. package/bundled/dev-pipeline/tests/__init__.py +0 -0
  29. package/bundled/dev-pipeline/tests/conftest.py +133 -0
  30. package/bundled/dev-pipeline/tests/test_check_session.py +127 -0
  31. package/bundled/dev-pipeline/tests/test_cleanup_logs.py +119 -0
  32. package/bundled/dev-pipeline/tests/test_detect_stuck.py +207 -0
  33. package/bundled/dev-pipeline/tests/test_generate_bugfix_prompt.py +181 -0
  34. package/bundled/dev-pipeline/tests/test_generate_prompt.py +190 -0
  35. package/bundled/dev-pipeline/tests/test_init_bugfix_pipeline.py +153 -0
  36. package/bundled/dev-pipeline/tests/test_init_pipeline.py +241 -0
  37. package/bundled/dev-pipeline/tests/test_update_bug_status.py +142 -0
  38. package/bundled/dev-pipeline/tests/test_update_feature_status.py +277 -0
  39. package/bundled/dev-pipeline/tests/test_utils.py +141 -0
  40. package/bundled/rules/USAGE.md +153 -0
  41. package/bundled/rules/_rules-metadata.json +43 -0
  42. package/bundled/rules/general/prefer-linux-commands.md +9 -0
  43. package/bundled/rules/prizm/prizm-commit-workflow.md +10 -0
  44. package/bundled/rules/prizm/prizm-documentation.md +80 -0
  45. package/bundled/rules/prizm/prizm-progressive-loading.md +11 -0
  46. package/bundled/skills/_metadata.json +162 -67
  47. package/bundled/skills/app-planner/SKILL.md +252 -499
  48. package/bundled/skills/app-planner/assets/evaluation-guide.md +44 -0
  49. package/bundled/skills/app-planner/scripts/validate-and-generate.py +143 -4
  50. package/bundled/skills/bug-planner/SKILL.md +58 -13
  51. package/bundled/skills/bugfix-pipeline-launcher/SKILL.md +5 -7
  52. package/bundled/skills/dev-pipeline-launcher/SKILL.md +16 -7
  53. package/bundled/skills/feature-workflow/SKILL.md +175 -234
  54. package/bundled/skills/prizm-kit/SKILL.md +17 -31
  55. package/bundled/skills/{prizmkit-adr-manager → prizmkit-tool-adr-manager}/SKILL.md +6 -7
  56. package/bundled/skills/{prizmkit-api-doc-generator → prizmkit-tool-api-doc-generator}/SKILL.md +4 -5
  57. package/bundled/skills/{prizmkit-bug-reproducer → prizmkit-tool-bug-reproducer}/SKILL.md +4 -5
  58. package/bundled/skills/{prizmkit-ci-cd-generator → prizmkit-tool-ci-cd-generator}/SKILL.md +4 -5
  59. package/bundled/skills/{prizmkit-db-migration → prizmkit-tool-db-migration}/SKILL.md +4 -5
  60. package/bundled/skills/{prizmkit-dependency-health → prizmkit-tool-dependency-health}/SKILL.md +3 -4
  61. package/bundled/skills/{prizmkit-deployment-strategy → prizmkit-tool-deployment-strategy}/SKILL.md +4 -5
  62. package/bundled/skills/{prizmkit-error-triage → prizmkit-tool-error-triage}/SKILL.md +4 -5
  63. package/bundled/skills/{prizmkit-log-analyzer → prizmkit-tool-log-analyzer}/SKILL.md +4 -5
  64. package/bundled/skills/{prizmkit-monitoring-setup → prizmkit-tool-monitoring-setup}/SKILL.md +4 -5
  65. package/bundled/skills/{prizmkit-onboarding-generator → prizmkit-tool-onboarding-generator}/SKILL.md +4 -5
  66. package/bundled/skills/{prizmkit-perf-profiler → prizmkit-tool-perf-profiler}/SKILL.md +4 -5
  67. package/bundled/skills/{prizmkit-security-audit → prizmkit-tool-security-audit}/SKILL.md +3 -4
  68. package/bundled/skills/{prizmkit-tech-debt-tracker → prizmkit-tool-tech-debt-tracker}/SKILL.md +3 -4
  69. package/bundled/skills/refactor-skill/SKILL.md +371 -0
  70. package/bundled/skills/refactor-workflow/SKILL.md +17 -119
  71. package/bundled/templates/hooks/commit-intent-claude.json +1 -1
  72. package/bundled/templates/hooks/commit-intent-codebuddy.json +1 -1
  73. package/bundled/templates/hooks/prizm-pre-commit.sh +58 -0
  74. package/bundled/templates/hooks/validate-prizm-docs.sh +84 -0
  75. package/package.json +1 -1
  76. package/src/detect-platform.js +20 -8
  77. package/src/external-skills.js +71 -0
  78. package/src/index.js +66 -8
  79. package/src/metadata.js +36 -0
  80. package/src/scaffold.js +200 -31
  81. package/bundled/skills/prizmkit-bug-fix-workflow/SKILL.md +0 -356
  82. package/bundled/templates/claude-md-template.md +0 -38
  83. package/bundled/templates/codebuddy-md-template.md +0 -35
  84. /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)
@@ -6,7 +6,7 @@
6
6
  "hooks": [
7
7
  {
8
8
  "type": "command",
9
- "command": "echo 'PRIZMKIT_DOC_UPDATE_REQUIRED: Before committing, you MUST update .prizm-docs/ per Prizm auto-update protocol. Steps: 1) Run git diff --cached --name-status. 2) Map changed files to modules via root.prizm MODULE_INDEX. 3) Read and update affected .prizm files (only changed sections). 4) Append to changelog.prizm. 5) Stage .prizm files with git add .prizm-docs/. 6) Then proceed with commit using prizmkit-committer workflow. RULES: Never rewrite entire .prizm files. Never add prose. Only update affected sections.'"
9
+ "command": "SRC=$(git diff --cached --name-only 2>/dev/null | grep -cE '\\.(ts|tsx|js|jsx|py|go|rs|java)$'); if [ \"$SRC\" -gt 0 ]; then PRIZM=$(git diff --cached --name-only 2>/dev/null | grep -c '^\\.prizm-docs/'); if [ \"$PRIZM\" -gt 0 ]; then echo \"PRIZMKIT_DOC_STATUS: $SRC source file(s) staged | .prizm-docs/ updated ($PRIZM file(s))\"; else echo \"PRIZMKIT_DOC_STATUS: $SRC source file(s) staged | .prizm-docs/ NOT UPDATED update if this is a feature change\"; fi; fi"
10
10
  }
11
11
  ]
12
12
  }
@@ -6,7 +6,7 @@
6
6
  "hooks": [
7
7
  {
8
8
  "type": "command",
9
- "command": "echo 'PRIZMKIT_DOC_UPDATE_REQUIRED: Before committing, you MUST update .prizm-docs/ per Prizm auto-update protocol. Steps: 1) Run git diff --cached --name-status. 2) Map changed files to modules via root.prizm MODULE_INDEX. 3) Read and update affected .prizm files (only changed sections). 4) Append to changelog.prizm. 5) Stage .prizm files with git add .prizm-docs/. 6) Then proceed with commit using prizmkit-committer workflow. RULES: Never rewrite entire .prizm files. Never add prose. Only update affected sections.'"
9
+ "command": "SRC=$(git diff --cached --name-only 2>/dev/null | grep -cE '\\.(ts|tsx|js|jsx|py|go|rs|java)$'); if [ \"$SRC\" -gt 0 ]; then PRIZM=$(git diff --cached --name-only 2>/dev/null | grep -c '^\\.prizm-docs/'); if [ \"$PRIZM\" -gt 0 ]; then echo \"PRIZMKIT_DOC_STATUS: $SRC source file(s) staged | .prizm-docs/ updated ($PRIZM file(s))\"; else echo \"PRIZMKIT_DOC_STATUS: $SRC source file(s) staged | .prizm-docs/ NOT UPDATED update if this is a feature change\"; fi; fi"
10
10
  }
11
11
  ]
12
12
  }
@@ -0,0 +1,58 @@
1
+ #!/bin/sh
2
+ # prizm-pre-commit.sh — git pre-commit hook for .prizm-docs validation
3
+
4
+ PROJECT_ROOT=$(git rev-parse --show-toplevel 2>/dev/null) || exit 0
5
+
6
+ # Only run in prizm projects
7
+ [ -f "$PROJECT_ROOT/.prizm-docs/root.prizm" ] || exit 0
8
+
9
+ VALIDATE_SCRIPT="$PROJECT_ROOT/dev-pipeline/scripts/validate-prizm-docs.sh"
10
+
11
+ if [ -f "$VALIDATE_SCRIPT" ]; then
12
+ sh "$VALIDATE_SCRIPT" --staged
13
+ exit $?
14
+ fi
15
+
16
+ # Inline fallback: core checks for staged .prizm files
17
+ FILES=$(git diff --cached --name-only 2>/dev/null | grep '\.prizm$')
18
+ [ -z "$FILES" ] && exit 0
19
+
20
+ ERRORS=0
21
+ for FILE in $FILES; do
22
+ [ -f "$FILE" ] || continue
23
+
24
+ if grep -qE '^#{1,6} ' "$FILE"; then
25
+ echo "ERROR: $FILE contains markdown headers (##). Use KEY: value format." >&2
26
+ ERRORS=$((ERRORS + 1))
27
+ fi
28
+
29
+ if grep -q '^```' "$FILE"; then
30
+ echo "ERROR: $FILE contains code blocks. Use file_path:line_number reference." >&2
31
+ ERRORS=$((ERRORS + 1))
32
+ fi
33
+
34
+ SIZE=$(wc -c < "$FILE" | tr -d ' ')
35
+ case "$FILE" in
36
+ *root.prizm) LIMIT=4096 ;;
37
+ *)
38
+ DIR=$(dirname "$FILE")
39
+ if [ "$DIR" = ".prizm-docs" ]; then
40
+ LIMIT=3072
41
+ else
42
+ LIMIT=5120
43
+ fi
44
+ ;;
45
+ esac
46
+
47
+ if [ "$SIZE" -gt "$LIMIT" ]; then
48
+ echo "ERROR: $FILE exceeds size limit (${SIZE}B > ${LIMIT}B)." >&2
49
+ ERRORS=$((ERRORS + 1))
50
+ fi
51
+ done
52
+
53
+ if [ "$ERRORS" -gt 0 ]; then
54
+ echo "PrizmKit: $ERRORS format error(s) in .prizm files. Fix before committing." >&2
55
+ exit 1
56
+ fi
57
+
58
+ exit 0
@@ -0,0 +1,84 @@
1
+ #!/bin/sh
2
+ # validate-prizm-docs.sh — validate .prizm file format and size limits
3
+ # Usage: validate-prizm-docs.sh [--all | --staged]
4
+
5
+ MODE="${1:---staged}"
6
+ ERRORS=0
7
+
8
+ # Not a prizm project — exit silently
9
+ [ -f ".prizm-docs/root.prizm" ] || exit 0
10
+
11
+ # Collect files to check
12
+ if [ "$MODE" = "--all" ]; then
13
+ FILES=$(find .prizm-docs -name '*.prizm' 2>/dev/null)
14
+ elif [ "$MODE" = "--staged" ]; then
15
+ FILES=$(git diff --cached --name-only 2>/dev/null | grep '\.prizm$')
16
+ else
17
+ echo "Usage: validate-prizm-docs.sh [--all | --staged]" >&2
18
+ exit 1
19
+ fi
20
+
21
+ # Nothing to check — exit silently
22
+ [ -z "$FILES" ] && exit 0
23
+
24
+ for FILE in $FILES; do
25
+ [ -f "$FILE" ] || continue
26
+
27
+ # Check markdown headers
28
+ if grep -qE '^#{1,6} ' "$FILE"; then
29
+ echo "ERROR: $FILE contains markdown headers (##). Use KEY: value format." >&2
30
+ ERRORS=$((ERRORS + 1))
31
+ fi
32
+
33
+ # Check code blocks
34
+ if grep -q '^```' "$FILE"; then
35
+ echo "ERROR: $FILE contains code blocks. Use file_path:line_number reference." >&2
36
+ ERRORS=$((ERRORS + 1))
37
+ fi
38
+
39
+ # Size limits — determine level by path depth
40
+ SIZE=$(wc -c < "$FILE" | tr -d ' ')
41
+ case "$FILE" in
42
+ *root.prizm)
43
+ LIMIT=4096; LEVEL="L0"
44
+ HINT="Consolidate MODULE_INDEX, keep top-5 RULES."
45
+ ;;
46
+ *)
47
+ # L1 = direct child of .prizm-docs/, L2 = nested deeper
48
+ DIR=$(dirname "$FILE")
49
+ if [ "$DIR" = ".prizm-docs" ]; then
50
+ LIMIT=3072; LEVEL="L1"
51
+ HINT="Move implementation details to L2."
52
+ else
53
+ LIMIT=5120; LEVEL="L2"
54
+ HINT="Archive CHANGELOG entries older than 90 days."
55
+ fi
56
+ ;;
57
+ esac
58
+
59
+ if [ "$SIZE" -gt "$LIMIT" ]; then
60
+ echo "ERROR: $FILE exceeds $LEVEL limit (${SIZE}B > ${LIMIT}B). $HINT" >&2
61
+ ERRORS=$((ERRORS + 1))
62
+ fi
63
+
64
+ # Required fields in root.prizm
65
+ case "$FILE" in
66
+ *root.prizm)
67
+ if ! grep -q 'PRIZM_VERSION:' "$FILE"; then
68
+ echo "ERROR: $FILE missing required field PRIZM_VERSION:" >&2
69
+ ERRORS=$((ERRORS + 1))
70
+ fi
71
+ if ! grep -q 'MODULE_INDEX:' "$FILE"; then
72
+ echo "ERROR: $FILE missing required field MODULE_INDEX:" >&2
73
+ ERRORS=$((ERRORS + 1))
74
+ fi
75
+ ;;
76
+ esac
77
+ done
78
+
79
+ if [ "$ERRORS" -gt 0 ]; then
80
+ echo "PrizmKit: $ERRORS format error(s) in .prizm files. Fix before committing." >&2
81
+ exit 1
82
+ fi
83
+
84
+ exit 0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prizmkit",
3
- "version": "1.0.13",
3
+ "version": "1.0.15",
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": {
@@ -6,9 +6,9 @@
6
6
  import { execFileSync } from 'child_process';
7
7
 
8
8
  /**
9
- * 允许检测的命令白名单
9
+ * 允许检测的命令白名单(仅用于 which 检测)
10
10
  */
11
- const ALLOWED_COMMANDS = ['cbc', 'claude'];
11
+ const ALLOWED_COMMANDS = ['cbc', 'claude', 'claude-internal'];
12
12
 
13
13
  /**
14
14
  * 检查命令是否存在于 PATH 中
@@ -26,21 +26,33 @@ function commandExists(cmd) {
26
26
  }
27
27
 
28
28
  /**
29
- * 检测已安装的 AI CLI 工具,并返回推荐的默认平台。
30
- * @returns {{ cbc: boolean, claude: boolean, suggested: string }}
29
+ * 检测已安装的 AI CLI 工具,并返回推荐的默认平台和 CLI 命令。
30
+ *
31
+ * 注意:platform 控制目录结构(.codebuddy/ 或 .claude/),
32
+ * suggestedCli 是实际运行的可执行命令,二者相互独立。
33
+ *
34
+ * @returns {{ cbc: boolean, claude: boolean, claudeInternal: boolean, suggested: string, suggestedCli: string }}
31
35
  */
32
36
  export function detectPlatform() {
33
37
  const cbc = commandExists('cbc');
34
38
  const claude = commandExists('claude');
39
+ const claudeInternal = commandExists('claude-internal');
35
40
 
41
+ // platform 建议:基于目录结构,优先 both
36
42
  let suggested = 'codebuddy';
37
- if (cbc && claude) {
43
+ if ((cbc) && (claude || claudeInternal)) {
38
44
  suggested = 'both';
39
- } else if (claude && !cbc) {
45
+ } else if ((claude || claudeInternal) && !cbc) {
40
46
  suggested = 'claude';
41
- } else if (cbc && !claude) {
47
+ } else if (cbc && !claude && !claudeInternal) {
42
48
  suggested = 'codebuddy';
43
49
  }
44
50
 
45
- return { cbc, claude, suggested };
51
+ // CLI 命令建议:优先 cbc,其次 claude-internal,再次 claude
52
+ let suggestedCli = '';
53
+ if (cbc) suggestedCli = 'cbc';
54
+ else if (claudeInternal) suggestedCli = 'claude-internal';
55
+ else if (claude) suggestedCli = 'claude';
56
+
57
+ return { cbc, claude, claudeInternal, suggested, suggestedCli };
46
58
  }
@@ -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
+ }