xtrm-tools 2.4.1 → 2.4.2

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 (125) hide show
  1. package/README.md +15 -6
  2. package/cli/dist/index.cjs +738 -239
  3. package/cli/dist/index.cjs.map +1 -1
  4. package/cli/package.json +1 -1
  5. package/config/hooks.json +10 -0
  6. package/config/pi/extensions/core/adapter.ts +2 -14
  7. package/config/pi/extensions/core/guard-rules.ts +70 -0
  8. package/config/pi/extensions/core/session-state.ts +59 -0
  9. package/config/pi/extensions/main-guard.ts +10 -14
  10. package/config/pi/extensions/plan-mode/README.md +65 -0
  11. package/config/pi/extensions/plan-mode/index.ts +340 -0
  12. package/config/pi/extensions/plan-mode/utils.ts +168 -0
  13. package/config/pi/extensions/service-skills.ts +51 -7
  14. package/config/pi/extensions/session-flow.ts +117 -0
  15. package/hooks/beads-claim-sync.mjs +123 -2
  16. package/hooks/beads-compact-restore.mjs +41 -9
  17. package/hooks/beads-compact-save.mjs +36 -5
  18. package/hooks/beads-gate-messages.mjs +27 -1
  19. package/hooks/beads-stop-gate.mjs +58 -8
  20. package/hooks/guard-rules.mjs +86 -0
  21. package/hooks/hooks.json +28 -18
  22. package/hooks/main-guard.mjs +3 -21
  23. package/hooks/quality-check.cjs +1286 -0
  24. package/hooks/quality-check.py +345 -0
  25. package/hooks/session-state.mjs +138 -0
  26. package/package.json +2 -1
  27. package/project-skills/quality-gates/.claude/settings.json +1 -24
  28. package/skills/creating-service-skills/SKILL.md +433 -0
  29. package/skills/creating-service-skills/references/script_quality_standards.md +425 -0
  30. package/skills/creating-service-skills/references/service_skill_system_guide.md +278 -0
  31. package/skills/creating-service-skills/scripts/bootstrap.py +326 -0
  32. package/skills/creating-service-skills/scripts/deep_dive.py +304 -0
  33. package/skills/creating-service-skills/scripts/scaffolder.py +482 -0
  34. package/skills/scoping-service-skills/SKILL.md +231 -0
  35. package/skills/scoping-service-skills/scripts/scope.py +74 -0
  36. package/skills/sync-docs/SKILL.md +235 -0
  37. package/skills/sync-docs/evals/evals.json +89 -0
  38. package/skills/sync-docs/references/doc-structure.md +104 -0
  39. package/skills/sync-docs/references/schema.md +103 -0
  40. package/skills/sync-docs/scripts/context_gatherer.py +246 -0
  41. package/skills/sync-docs/scripts/doc_structure_analyzer.py +495 -0
  42. package/skills/sync-docs/scripts/validate_doc.py +365 -0
  43. package/skills/sync-docs-workspace/iteration-1/benchmark.json +293 -0
  44. package/skills/sync-docs-workspace/iteration-1/benchmark.md +13 -0
  45. package/skills/sync-docs-workspace/iteration-1/eval-doc-audit/eval_metadata.json +27 -0
  46. package/skills/sync-docs-workspace/iteration-1/eval-doc-audit/with_skill/outputs/result.md +210 -0
  47. package/skills/sync-docs-workspace/iteration-1/eval-doc-audit/with_skill/run-1/grading.json +28 -0
  48. package/skills/sync-docs-workspace/iteration-1/eval-doc-audit/with_skill/run-1/timing.json +1 -0
  49. package/skills/sync-docs-workspace/iteration-1/eval-doc-audit/without_skill/outputs/result.md +101 -0
  50. package/skills/sync-docs-workspace/iteration-1/eval-doc-audit/without_skill/run-1/grading.json +28 -0
  51. package/skills/sync-docs-workspace/iteration-1/eval-doc-audit/without_skill/run-1/timing.json +5 -0
  52. package/skills/sync-docs-workspace/iteration-1/eval-doc-audit/without_skill/timing.json +5 -0
  53. package/skills/sync-docs-workspace/iteration-1/eval-fix-mode/eval_metadata.json +27 -0
  54. package/skills/sync-docs-workspace/iteration-1/eval-fix-mode/with_skill/outputs/result.md +198 -0
  55. package/skills/sync-docs-workspace/iteration-1/eval-fix-mode/with_skill/run-1/grading.json +28 -0
  56. package/skills/sync-docs-workspace/iteration-1/eval-fix-mode/with_skill/run-1/timing.json +1 -0
  57. package/skills/sync-docs-workspace/iteration-1/eval-fix-mode/without_skill/outputs/result.md +94 -0
  58. package/skills/sync-docs-workspace/iteration-1/eval-fix-mode/without_skill/run-1/grading.json +28 -0
  59. package/skills/sync-docs-workspace/iteration-1/eval-fix-mode/without_skill/run-1/timing.json +1 -0
  60. package/skills/sync-docs-workspace/iteration-1/eval-sprint-closeout/eval_metadata.json +27 -0
  61. package/skills/sync-docs-workspace/iteration-1/eval-sprint-closeout/with_skill/outputs/result.md +237 -0
  62. package/skills/sync-docs-workspace/iteration-1/eval-sprint-closeout/with_skill/run-1/grading.json +28 -0
  63. package/skills/sync-docs-workspace/iteration-1/eval-sprint-closeout/with_skill/run-1/timing.json +1 -0
  64. package/skills/sync-docs-workspace/iteration-1/eval-sprint-closeout/without_skill/outputs/result.md +134 -0
  65. package/skills/sync-docs-workspace/iteration-1/eval-sprint-closeout/without_skill/run-1/grading.json +28 -0
  66. package/skills/sync-docs-workspace/iteration-1/eval-sprint-closeout/without_skill/run-1/timing.json +1 -0
  67. package/skills/sync-docs-workspace/iteration-2/benchmark.json +297 -0
  68. package/skills/sync-docs-workspace/iteration-2/benchmark.md +13 -0
  69. package/skills/sync-docs-workspace/iteration-2/eval-doc-audit/eval_metadata.json +27 -0
  70. package/skills/sync-docs-workspace/iteration-2/eval-doc-audit/with_skill/outputs/result.md +137 -0
  71. package/skills/sync-docs-workspace/iteration-2/eval-doc-audit/with_skill/run-1/grading.json +92 -0
  72. package/skills/sync-docs-workspace/iteration-2/eval-doc-audit/with_skill/run-1/timing.json +1 -0
  73. package/skills/sync-docs-workspace/iteration-2/eval-doc-audit/without_skill/outputs/result.md +134 -0
  74. package/skills/sync-docs-workspace/iteration-2/eval-doc-audit/without_skill/run-1/grading.json +86 -0
  75. package/skills/sync-docs-workspace/iteration-2/eval-doc-audit/without_skill/run-1/timing.json +1 -0
  76. package/skills/sync-docs-workspace/iteration-2/eval-fix-mode/eval_metadata.json +27 -0
  77. package/skills/sync-docs-workspace/iteration-2/eval-fix-mode/with_skill/outputs/result.md +193 -0
  78. package/skills/sync-docs-workspace/iteration-2/eval-fix-mode/with_skill/run-1/grading.json +72 -0
  79. package/skills/sync-docs-workspace/iteration-2/eval-fix-mode/with_skill/run-1/timing.json +1 -0
  80. package/skills/sync-docs-workspace/iteration-2/eval-fix-mode/without_skill/outputs/result.md +211 -0
  81. package/skills/sync-docs-workspace/iteration-2/eval-fix-mode/without_skill/run-1/grading.json +91 -0
  82. package/skills/sync-docs-workspace/iteration-2/eval-fix-mode/without_skill/run-1/timing.json +5 -0
  83. package/skills/sync-docs-workspace/iteration-2/eval-sprint-closeout/eval_metadata.json +27 -0
  84. package/skills/sync-docs-workspace/iteration-2/eval-sprint-closeout/with_skill/outputs/result.md +182 -0
  85. package/skills/sync-docs-workspace/iteration-2/eval-sprint-closeout/with_skill/run-1/grading.json +95 -0
  86. package/skills/sync-docs-workspace/iteration-2/eval-sprint-closeout/with_skill/run-1/timing.json +1 -0
  87. package/skills/sync-docs-workspace/iteration-2/eval-sprint-closeout/without_skill/outputs/result.md +222 -0
  88. package/skills/sync-docs-workspace/iteration-2/eval-sprint-closeout/without_skill/run-1/grading.json +88 -0
  89. package/skills/sync-docs-workspace/iteration-2/eval-sprint-closeout/without_skill/run-1/timing.json +5 -0
  90. package/skills/sync-docs-workspace/iteration-3/benchmark.json +298 -0
  91. package/skills/sync-docs-workspace/iteration-3/benchmark.md +13 -0
  92. package/skills/sync-docs-workspace/iteration-3/eval-doc-audit/eval_metadata.json +27 -0
  93. package/skills/sync-docs-workspace/iteration-3/eval-doc-audit/with_skill/outputs/result.md +125 -0
  94. package/skills/sync-docs-workspace/iteration-3/eval-doc-audit/with_skill/run-1/grading.json +97 -0
  95. package/skills/sync-docs-workspace/iteration-3/eval-doc-audit/with_skill/run-1/timing.json +5 -0
  96. package/skills/sync-docs-workspace/iteration-3/eval-doc-audit/without_skill/outputs/result.md +144 -0
  97. package/skills/sync-docs-workspace/iteration-3/eval-doc-audit/without_skill/run-1/grading.json +78 -0
  98. package/skills/sync-docs-workspace/iteration-3/eval-doc-audit/without_skill/run-1/timing.json +5 -0
  99. package/skills/sync-docs-workspace/iteration-3/eval-fix-mode/eval_metadata.json +27 -0
  100. package/skills/sync-docs-workspace/iteration-3/eval-fix-mode/with_skill/outputs/result.md +104 -0
  101. package/skills/sync-docs-workspace/iteration-3/eval-fix-mode/with_skill/run-1/grading.json +91 -0
  102. package/skills/sync-docs-workspace/iteration-3/eval-fix-mode/with_skill/run-1/timing.json +5 -0
  103. package/skills/sync-docs-workspace/iteration-3/eval-fix-mode/without_skill/outputs/result.md +79 -0
  104. package/skills/sync-docs-workspace/iteration-3/eval-fix-mode/without_skill/run-1/grading.json +82 -0
  105. package/skills/sync-docs-workspace/iteration-3/eval-fix-mode/without_skill/run-1/timing.json +5 -0
  106. package/skills/sync-docs-workspace/iteration-3/eval-sprint-closeout/eval_metadata.json +27 -0
  107. package/skills/sync-docs-workspace/iteration-3/eval-sprint-closeout/with_skill/outputs/phase1_context.json +302 -0
  108. package/skills/sync-docs-workspace/iteration-3/eval-sprint-closeout/with_skill/outputs/phase2_drift.txt +33 -0
  109. package/skills/sync-docs-workspace/iteration-3/eval-sprint-closeout/with_skill/outputs/phase3_analysis.json +114 -0
  110. package/skills/sync-docs-workspace/iteration-3/eval-sprint-closeout/with_skill/outputs/phase4_fix.txt +118 -0
  111. package/skills/sync-docs-workspace/iteration-3/eval-sprint-closeout/with_skill/outputs/phase5_validate.txt +38 -0
  112. package/skills/sync-docs-workspace/iteration-3/eval-sprint-closeout/with_skill/outputs/result.md +158 -0
  113. package/skills/sync-docs-workspace/iteration-3/eval-sprint-closeout/with_skill/run-1/grading.json +95 -0
  114. package/skills/sync-docs-workspace/iteration-3/eval-sprint-closeout/with_skill/run-1/timing.json +5 -0
  115. package/skills/sync-docs-workspace/iteration-3/eval-sprint-closeout/without_skill/outputs/result.md +71 -0
  116. package/skills/sync-docs-workspace/iteration-3/eval-sprint-closeout/without_skill/run-1/grading.json +90 -0
  117. package/skills/sync-docs-workspace/iteration-3/eval-sprint-closeout/without_skill/run-1/timing.json +5 -0
  118. package/skills/updating-service-skills/SKILL.md +136 -0
  119. package/skills/updating-service-skills/scripts/drift_detector.py +222 -0
  120. package/skills/using-quality-gates/SKILL.md +254 -0
  121. package/skills/using-service-skills/SKILL.md +108 -0
  122. package/skills/using-service-skills/scripts/cataloger.py +74 -0
  123. package/skills/using-service-skills/scripts/skill_activator.py +152 -0
  124. package/skills/using-service-skills/scripts/test_skill_activator.py +58 -0
  125. package/skills/using-xtrm/SKILL.md +34 -38
@@ -0,0 +1,254 @@
1
+ ---
2
+ name: using-quality-gates
3
+ description: 'Quality Gates workflow for Claude Code. Use when editing code in projects with quality enforcement. Covers the full cycle: TDD guard (write failing test first) → implement → auto-lint/typecheck. Activates on code edits, quality issues, or when user asks about testing/linting workflow.'
4
+ ---
5
+
6
+ # Using Quality Gates
7
+
8
+ **Quality Gates** provides automated code quality enforcement through PostToolUse hooks:
9
+
10
+ 1. **TypeScript Quality Gate** — Runs after TS/JS edits: TypeScript + ESLint + Prettier
11
+ 2. **Python Quality Gate** — Runs after Python edits: Ruff + Mypy
12
+
13
+ **Separate Installation Required for TDD:**
14
+ - **TDD Guard** is a separate tool (not included) — See "TDD Guard Setup" below
15
+
16
+ ## Architecture Overview
17
+
18
+ ```
19
+ ┌─────────────────────────────────────────────────────────────────┐
20
+ │ QUALITY GATES (this skill) │
21
+ │ ───────────────────────────── │
22
+ │ PostToolUse Hooks (installed by this skill): │
23
+ │ • .claude/hooks/quality-check.cjs → TS/JS files │
24
+ │ • .claude/hooks/quality-check.py → Python files │
25
+ │ • .claude/settings.json → Hook registration │
26
+ └─────────────────────────────────────────────────────────────────┘
27
+
28
+ ┌─────────────────────────────────────────────────────────────────┐
29
+ │ TDD GUARD (separate installation) │
30
+ │ ─────────────────────────────────── │
31
+ │ PreToolUse Hook (requires xtrm install project tdd-guard): │
32
+ │ • Global CLI: npm install -g tdd-guard │
33
+ │ • Test reporter: tdd-guard-vitest / tdd-guard-pytest / etc. │
34
+ │ • Hook: .claude/hooks/tdd-guard-pretool-bridge.cjs │
35
+ └─────────────────────────────────────────────────────────────────┘
36
+ ```
37
+
38
+ ## Installation
39
+
40
+ ### Step 1: Install This Skill
41
+
42
+ ```bash
43
+ xtrm install project quality-gates
44
+ ```
45
+
46
+ This installs:
47
+ - `.claude/hooks/quality-check.cjs` — TypeScript/JavaScript checks
48
+ - `.claude/hooks/quality-check.py` — Python checks
49
+ - `.claude/settings.json` — PostToolUse hook registration
50
+ - `.claude/skills/using-quality-gates/` — This documentation
51
+
52
+ ### Step 2: Install Language Dependencies
53
+
54
+ **TypeScript Projects:**
55
+ ```bash
56
+ npm install --save-dev typescript eslint prettier
57
+ ```
58
+
59
+ **Python Projects:**
60
+ ```bash
61
+ pip install ruff mypy
62
+ ```
63
+
64
+ ### Step 3: (Optional) Install TDD Guard
65
+
66
+ For test-first enforcement, install TDD Guard separately:
67
+
68
+ ```bash
69
+ # 1. Install global CLI
70
+ npm install -g tdd-guard
71
+
72
+ # 2. Install project-skill for hook wiring
73
+ xtrm install project tdd-guard
74
+
75
+ # 3. Install test reporter (choose one)
76
+ npm install --save-dev tdd-guard-vitest # Vitest
77
+ npm install --save-dev tdd-guard-jest # Jest
78
+ pip install tdd-guard-pytest # pytest
79
+ ```
80
+
81
+ **Configure test reporter** (see https://github.com/nizos/tdd-guard):
82
+
83
+ **Vitest:**
84
+ ```typescript
85
+ // vitest.config.ts
86
+ import { defineConfig } from 'vitest/config'
87
+ import { VitestReporter } from 'tdd-guard-vitest'
88
+
89
+ export default defineConfig({
90
+ test: {
91
+ reporters: ['default', new VitestReporter('/path/to/project')],
92
+ },
93
+ })
94
+ ```
95
+
96
+ **pytest:**
97
+ ```toml
98
+ # pyproject.toml
99
+ [tool.pytest.ini_options]
100
+ tdd_guard_project_root = "/path/to/project"
101
+ ```
102
+
103
+ ## How Quality Gates Work
104
+
105
+ ### TypeScript Quality Gate (PostToolUse)
106
+
107
+ **Runs after:** Every `.ts`, `.tsx`, `.js`, `.jsx` file edit
108
+
109
+ **Checks:**
110
+ 1. TypeScript compilation (type errors)
111
+ 2. ESLint validation (style, best practices)
112
+ 3. Prettier formatting (consistency)
113
+
114
+ **Configuration** (`.claude/hooks/hook-config.json`):
115
+ ```json
116
+ {
117
+ "typescript": { "enabled": true, "showDependencyErrors": false },
118
+ "eslint": { "enabled": true, "autofix": true },
119
+ "prettier": { "enabled": true, "autofix": true },
120
+ "general": { "autofixSilent": true }
121
+ }
122
+ ```
123
+
124
+ ### Python Quality Gate (PostToolUse)
125
+
126
+ **Runs after:** Every `.py` file edit
127
+
128
+ **Checks:**
129
+ 1. Ruff linting (errors, style, best practices)
130
+ 2. Ruff formatting (Black-compatible)
131
+ 3. Mypy type checking (static types)
132
+
133
+ **Configuration** (environment variables):
134
+ ```bash
135
+ CLAUDE_HOOKS_RUFF_ENABLED=true
136
+ CLAUDE_HOOKS_MYPY_ENABLED=true
137
+ CLAUDE_HOOKS_AUTOFIX=true
138
+ ```
139
+
140
+ ## Exit Codes
141
+
142
+ | Code | Meaning | Action |
143
+ |------|---------|--------|
144
+ | 0 | All checks passed | Continue |
145
+ | 1 | Fatal error (missing deps) | Install missing tool |
146
+ | 2 | Blocking errors | Claude must fix |
147
+
148
+ ## Handling Quality Gate Errors
149
+
150
+ When blocked with exit code 2:
151
+
152
+ 1. **Read the error output** — Specific issues listed
153
+ 2. **Auto-fix applies automatically** — ESLint/Prettier/Ruff fix what they can
154
+ 3. **Fix remaining issues manually** — Type errors, complex violations
155
+ 4. **Gate re-runs on next edit** — No manual trigger needed
156
+
157
+ **Example:**
158
+ ```
159
+ [ERROR] TypeScript compilation failed:
160
+ src/auth.ts:42:5 - error TS2322: Type 'string' is not assignable to type 'number'
161
+
162
+ [WARN] Auto-fix applied: 2 issues fixed
163
+ [BLOCK] 1 issue remains - fix before continuing
164
+ ```
165
+
166
+ ## TDD Guard Integration
167
+
168
+ When TDD Guard is installed alongside Quality Gates:
169
+
170
+ ```
171
+ User Request: "Add feature X"
172
+
173
+ ┌───────────────────────────────────┐
174
+ │ TDD Guard (PreToolUse) │
175
+ │ Checks: Failing test exists? │
176
+ │ • NO → BLOCK: "Write test first" │
177
+ │ • YES → Allow implementation │
178
+ └───────────────────────────────────┘
179
+
180
+ Implementation (Write/Edit)
181
+
182
+ ┌───────────────────────────────────┐
183
+ │ Quality Gates (PostToolUse) │
184
+ │ Runs: Lint + Typecheck + Format │
185
+ │ • Errors → BLOCK, fix issues │
186
+ │ • Pass → Continue │
187
+ └───────────────────────────────────┘
188
+
189
+ Tests pass → Commit
190
+ ```
191
+
192
+ ## Troubleshooting
193
+
194
+ **"ESLint not found" / "Prettier not found"**
195
+ ```bash
196
+ npm install --save-dev eslint prettier
197
+ ```
198
+
199
+ **"Ruff not found" / "Mypy not found"**
200
+ ```bash
201
+ pip install ruff mypy
202
+ ```
203
+
204
+ **"tdd-guard: command not found"**
205
+ ```bash
206
+ npm install -g tdd-guard
207
+ ```
208
+
209
+ **"TDD Guard: No failing test found"**
210
+ - Write a failing test first
211
+ - Ensure test reporter is configured
212
+ - Run tests to generate reporter JSON
213
+
214
+ **Hook not running**
215
+ - Verify `.claude/settings.json` exists
216
+ - Check hook script paths are correct
217
+ - Ensure file extension matches (`.ts`/`.py`)
218
+
219
+ ## When This Skill Activates
220
+
221
+ **Triggers:**
222
+ - Quality gate reports errors
223
+ - User asks about linting, type checking, or quality workflow
224
+ - Session starts in a project with quality gates installed
225
+
226
+ **Response Modes:**
227
+
228
+ **Full Workflow Mode** (user mentions quality/testing, blocked by gate errors):
229
+ - Explain complete quality pipeline
230
+ - Provide troubleshooting guidance
231
+
232
+ **Minimal Mode** (general coding tasks without quality context):
233
+ - Complete the task directly
234
+ - Brief note: "Consider adding tests. If TDD Guard is installed, write failing test first."
235
+
236
+ ## Files Installed
237
+
238
+ ```
239
+ .claude/
240
+ ├── settings.json # PostToolUse hook registration
241
+ ├── hooks/
242
+ │ ├── quality-check.cjs # TypeScript/JavaScript checks
243
+ │ ├── quality-check.py # Python checks
244
+ │ └── hook-config.json # TS hook configuration
245
+ ├── skills/
246
+ │ └── using-quality-gates/ # This skill
247
+ └── docs/
248
+ └── quality-gates-readme.md
249
+ ```
250
+
251
+ ## Related
252
+
253
+ - **TDD Guard**: https://github.com/nizos/tdd-guard
254
+ - **xtrm install project tdd-guard**: Install TDD Guard hooks
@@ -0,0 +1,108 @@
1
+ ---
2
+ name: using-service-skills
3
+ description: >-
4
+ Service catalog discovery and expert persona activation.
5
+ At session start, a catalog of registered expert personas is injected
6
+ automatically. Use this skill to discover, understand, and activate
7
+ the right expert for any task.
8
+ allowed-tools: Read, Glob
9
+ ---
10
+
11
+ # Using Service Skills
12
+
13
+ ## Role: The Concierge
14
+
15
+ You are the **Service Skills Concierge**. Your job is to help users discover and
16
+ activate expert personas registered in `.claude/skills/service-registry.json`.
17
+
18
+ ---
19
+
20
+ ## How the Catalog Works
21
+
22
+ At session start, the `SessionStart` hook (configured in `.claude/settings.json`)
23
+ runs `cataloger.py` and injects a lightweight XML block into your context:
24
+
25
+ ```xml
26
+ <project_service_catalog>
27
+ Available expert personas:
28
+ - db-expert: SQL & schema optimization (Path: .claude/skills/db-expert/SKILL.md)
29
+ - auth-service: JWT authentication expert (Path: .claude/skills/auth-service/SKILL.md)
30
+ </project_service_catalog>
31
+ <instruction>To activate an expert, read its SKILL.md from the provided path.</instruction>
32
+ ```
33
+
34
+ This costs ~150 tokens per session regardless of how many experts are registered
35
+ (Progressive Disclosure: full skill bodies are loaded only when needed).
36
+
37
+ ---
38
+
39
+ ## Workflow
40
+
41
+ ### 1. Check the Injected Catalog
42
+
43
+ When a user asks about a service or starts a related task, check whether a
44
+ `<project_service_catalog>` block is present in your context.
45
+
46
+ If no catalog was injected (e.g. first run, no services registered), generate one:
47
+
48
+ ```bash
49
+ python3 "$CLAUDE_PROJECT_DIR/.claude/skills/using-service-skills/scripts/cataloger.py"
50
+ ```
51
+
52
+ ### 2. Activate an Expert Persona
53
+
54
+ When a task matches an expert's domain, read that skill's SKILL.md:
55
+
56
+ ```
57
+ Read: .claude/skills/<service-id>/SKILL.md
58
+ ```
59
+
60
+ Then adopt the expert's persona, constraints, and knowledge for the duration
61
+ of the task.
62
+
63
+ **Example:**
64
+ ```
65
+ User: "Optimize this database query"
66
+ You: [Catalog shows db-expert matches]
67
+ [Read .claude/skills/db-expert/SKILL.md]
68
+ [Apply Senior Database Engineer persona and expertise]
69
+ ```
70
+
71
+ ### 3. Handle Missing Experts
72
+
73
+ If no registered expert covers the user's need:
74
+ 1. Inform the user no expert exists for this domain
75
+ 2. Offer to create one: "I can create a service skill using `/creating-service-skills`"
76
+
77
+ ---
78
+
79
+ ## Session Start Hook
80
+
81
+ The catalog injection is not handled by skill frontmatter hooks. Configure it in
82
+ `.claude/settings.json` using `SessionStart`:
83
+
84
+ ```json
85
+ {
86
+ "hooks": {
87
+ "SessionStart": [{
88
+ "hooks": [{
89
+ "type": "command",
90
+ "command": "python3 \"$CLAUDE_PROJECT_DIR/.claude/skills/using-service-skills/scripts/cataloger.py\""
91
+ }]
92
+ }]
93
+ }
94
+ }
95
+ ```
96
+
97
+ ---
98
+
99
+ ## Tool Restrictions
100
+
101
+ Read-only — no write access:
102
+ - ✅ `Read` — read SKILL.md files to activate expert personas
103
+ - ✅ `Glob` — browse `.claude/skills/` directory
104
+
105
+ ## Related Skills
106
+
107
+ - `/creating-service-skills` — Scaffold new expert personas
108
+ - `/updating-service-skills` — Sync skills when implementation drifts
@@ -0,0 +1,74 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ Cataloger — SessionStart hook for using-service-skills.
4
+
5
+ Reads .claude/skills/service-registry.json and prints a lightweight XML
6
+ service catalog block (~150 tokens) to stdout. The SessionStart hook
7
+ injects this as additional context so Claude knows which expert personas
8
+ are available without loading full skill bodies (Progressive Disclosure).
9
+
10
+ Configured in .claude/settings.json:
11
+ "SessionStart": [{"hooks": [{"type": "command",
12
+ "command": "python3 \\"$CLAUDE_PROJECT_DIR/.claude/skills/using-service-skills/scripts/cataloger.py\\""}]}]
13
+
14
+ Output format:
15
+ <project_service_catalog>
16
+ Available expert personas:
17
+ - db-expert: SQL & schema expert (Path: .claude/skills/db-expert/SKILL.md)
18
+ </project_service_catalog>
19
+ <instruction>To activate an expert, read its SKILL.md from the provided path.</instruction>
20
+ """
21
+
22
+ import sys
23
+ from pathlib import Path
24
+
25
+ # Bootstrap lives in creating-service-skills — shared utility
26
+ BOOTSTRAP_DIR = Path(__file__).parent.parent.parent / "creating-service-skills" / "scripts"
27
+ sys.path.insert(0, str(BOOTSTRAP_DIR))
28
+
29
+ from bootstrap import RootResolutionError, list_services # noqa: E402
30
+
31
+
32
+ def generate_catalog() -> str:
33
+ """
34
+ Generate the service catalog XML block.
35
+
36
+ Returns empty string if no services are registered or project root
37
+ cannot be determined (fails gracefully — never breaks session start).
38
+ """
39
+ try:
40
+ services = list_services()
41
+ except (RootResolutionError, Exception):
42
+ return ""
43
+
44
+ if not services:
45
+ return ""
46
+
47
+ lines = [
48
+ "<project_service_catalog>",
49
+ "Available expert personas:",
50
+ ]
51
+
52
+ for service_id, data in sorted(services.items()):
53
+ description = data.get("description", data.get("name", service_id))
54
+ skill_path = data.get("skill_path", f".claude/skills/{service_id}/SKILL.md")
55
+ lines.append(f"- {service_id}: {description} (Path: {skill_path})")
56
+
57
+ lines.append("</project_service_catalog>")
58
+ lines.append(
59
+ "<instruction>To activate an expert, read its SKILL.md from the provided path.</instruction>"
60
+ )
61
+
62
+ return "\n".join(lines)
63
+
64
+
65
+ def main() -> None:
66
+ """Print catalog to stdout — injected as SessionStart additional context."""
67
+ catalog = generate_catalog()
68
+ if catalog:
69
+ print(catalog)
70
+ # Silent if no services registered — don't break session start
71
+
72
+
73
+ if __name__ == "__main__":
74
+ main()
@@ -0,0 +1,152 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ PreToolUse hook: skill activator.
4
+
5
+ Fires before Read, Write, Edit, Glob, Grep, or Bash operations.
6
+ Checks whether the operation touches a registered service territory.
7
+ If it does, injects additionalContext telling Claude to load the skill
8
+ before proceeding — ensuring expert knowledge is always applied.
9
+
10
+ Configured in .claude/settings.json PreToolUse hook.
11
+ Must be fast: pure file I/O + string matching, no subprocess.
12
+ """
13
+
14
+ import fnmatch
15
+ import json
16
+ import sys
17
+ from pathlib import Path
18
+
19
+ BOOTSTRAP_DIR = Path(__file__).parent.parent.parent / "creating-service-skills" / "scripts"
20
+ sys.path.insert(0, str(BOOTSTRAP_DIR))
21
+
22
+ from bootstrap import RootResolutionError, get_project_root, load_registry # noqa: E402 # type: ignore[import-not-found]
23
+
24
+
25
+ def match_territory(file_path: str, territory: list[str], project_root: Path) -> bool:
26
+ """Check if a file path matches any territory glob pattern."""
27
+ # Normalize to relative path
28
+ fp = Path(file_path)
29
+ if fp.is_absolute():
30
+ try:
31
+ fp = fp.relative_to(project_root)
32
+ except ValueError:
33
+ return False
34
+ rel = str(fp)
35
+
36
+ for pattern in territory:
37
+ # fnmatch handles * and ?, but not ** — handle ** manually
38
+ if "**" in pattern:
39
+ # Split on **/ and check prefix + suffix
40
+ parts = pattern.split("**/")
41
+ if len(parts) == 2:
42
+ prefix, suffix = parts
43
+ rel_check = rel[len(prefix) :] if rel.startswith(prefix) else rel
44
+ if fnmatch.fnmatch(rel_check, suffix) or fnmatch.fnmatch(
45
+ rel, f"{prefix}*/{suffix}"
46
+ ):
47
+ return True
48
+ # Also check if file is anywhere under the prefix dir
49
+ if prefix and rel.startswith(prefix.rstrip("/")):
50
+ return True
51
+ else:
52
+ if fnmatch.fnmatch(rel, pattern):
53
+ return True
54
+ # Direct prefix match for broad patterns
55
+ base = pattern.split("/*")[0].split("/**")[0]
56
+ if base and (rel.startswith(base + "/") or rel == base):
57
+ return True
58
+
59
+ return False
60
+
61
+
62
+ def find_service_for_file(
63
+ file_path: str, services: dict, project_root: Path
64
+ ) -> tuple[str, dict] | None:
65
+ """Return (service_id, service_data) if file is in any territory, else None."""
66
+ for service_id, data in services.items():
67
+ if match_territory(file_path, data.get("territory", []), project_root):
68
+ return service_id, data
69
+ return None
70
+
71
+
72
+ def find_service_for_command(command: str, services: dict) -> tuple[str, dict] | None:
73
+ """Return (service_id, service_data) if command mentions a service name."""
74
+ cmd_lower = command.lower()
75
+ for service_id, data in services.items():
76
+ # Match service_id directly or as a container name in docker commands
77
+ if service_id in cmd_lower:
78
+ return service_id, data
79
+ # Match the container name pattern (service name with dashes/underscores)
80
+ if data.get("name") and data.get("name", "").lower().replace(" ", "-") in cmd_lower:
81
+ return service_id, data
82
+ return None
83
+
84
+
85
+ def build_context(service_id: str, data: dict) -> str:
86
+ skill_path = data.get("skill_path", f".claude/skills/{service_id}/SKILL.md")
87
+ desc = data.get("description", "")
88
+ desc_line = f"\n What it covers: {desc}" if desc else ""
89
+
90
+ return (
91
+ f"[Service Skill] You are about to work with the '{service_id}' service territory."
92
+ f"{desc_line}\n"
93
+ f" Load the expert skill before proceeding: Read {skill_path}\n"
94
+ f" The skill contains: operational knowledge, failure modes, diagnostic scripts, "
95
+ f"and the correct methods for managing this service.\n"
96
+ f" Do not use ad-hoc approaches (raw SQL, improvised docker commands) "
97
+ f"when the skill defines the correct method."
98
+ )
99
+
100
+
101
+ def main() -> None:
102
+ try:
103
+ data = json.load(sys.stdin)
104
+ except (json.JSONDecodeError, EOFError):
105
+ sys.exit(0)
106
+
107
+ tool_name = data.get("tool_name", "")
108
+ tool_input = data.get("tool_input", {})
109
+
110
+ try:
111
+ project_root = Path(get_project_root())
112
+ services = load_registry().get("services", {})
113
+ except (RootResolutionError, Exception):
114
+ sys.exit(0)
115
+
116
+ if not services:
117
+ sys.exit(0)
118
+
119
+ match = None
120
+
121
+ # File-based tools: check file_path against territory
122
+ if tool_name in ("Read", "Write", "Edit", "Glob", "Grep", "NotebookRead", "NotebookEdit"):
123
+ file_path = (
124
+ tool_input.get("file_path")
125
+ or tool_input.get("path")
126
+ or tool_input.get("notebook_path")
127
+ or ""
128
+ )
129
+ if file_path:
130
+ match = find_service_for_file(file_path, services, project_root)
131
+
132
+ # Bash: check command string for service names
133
+ elif tool_name == "Bash":
134
+ command = tool_input.get("command", "")
135
+ if command:
136
+ match = find_service_for_command(command, services)
137
+
138
+ if match:
139
+ service_id, service_data = match
140
+ output = {
141
+ "hookSpecificOutput": {
142
+ "hookEventName": "PreToolUse",
143
+ "additionalContext": build_context(service_id, service_data),
144
+ }
145
+ }
146
+ print(json.dumps(output))
147
+
148
+ sys.exit(0)
149
+
150
+
151
+ if __name__ == "__main__":
152
+ main()
@@ -0,0 +1,58 @@
1
+ """Tests for skill_activator.py — load_registry integration."""
2
+ import io
3
+ import json
4
+ import sys
5
+ import unittest
6
+ from pathlib import Path
7
+ from unittest.mock import patch
8
+
9
+ scripts_dir = Path(__file__).parent
10
+ sys.path.insert(0, str(scripts_dir))
11
+ sys.path.insert(0, str(scripts_dir.parent.parent / "creating-service-skills" / "scripts"))
12
+
13
+ import skill_activator
14
+
15
+
16
+ REGISTRY_WITH_VERSION = {
17
+ "version": "1.0",
18
+ "services": {
19
+ "my-service": {
20
+ "territory": ["src/my-service/**"],
21
+ "name": "My Service",
22
+ "skill_path": ".claude/skills/my-service/SKILL.md",
23
+ }
24
+ },
25
+ }
26
+
27
+ HOOK_INPUT = json.dumps({
28
+ "tool_name": "Write",
29
+ "tool_input": {"file_path": "src/my-service/foo.py"},
30
+ "hook_event_name": "PreToolUse",
31
+ "session_id": "test",
32
+ "cwd": "/fake/project",
33
+ })
34
+
35
+
36
+ class TestMainWithVersionedRegistry(unittest.TestCase):
37
+ def test_main_does_not_crash_when_registry_has_version_key(self):
38
+ """main() must not crash with AttributeError when load_registry returns
39
+ {"version": ..., "services": {...}} — the full registry dict.
40
+ It should output valid JSON context for the matched service.
41
+ """
42
+ with patch("skill_activator.load_registry", return_value=REGISTRY_WITH_VERSION), \
43
+ patch("skill_activator.get_project_root", return_value="/fake/project"), \
44
+ patch("sys.stdin", io.StringIO(HOOK_INPUT)), \
45
+ patch("sys.stdout", new_callable=io.StringIO) as mock_stdout:
46
+ try:
47
+ skill_activator.main()
48
+ except SystemExit:
49
+ pass
50
+ output = mock_stdout.getvalue()
51
+
52
+ self.assertTrue(output, "Expected JSON output but got nothing")
53
+ result = json.loads(output)
54
+ self.assertIn("hookSpecificOutput", result)
55
+
56
+
57
+ if __name__ == "__main__":
58
+ unittest.main()