@softspark/ai-toolkit 2.6.1 → 2.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/AGENTS.md CHANGED
@@ -463,6 +463,7 @@ Skills are invocable commands or auto-loaded knowledge sources:
463
463
  - **clean-code**: Loaded when user asks about clean code, naming, or code quality
464
464
  - **command-creator**: Creates new Claude Code slash commands with frontmatter, workflow guidance, and validation
465
465
  - **commit**: Create Conventional Commits with pre-commit validation
466
+ - **content-moderation-patterns**: Loaded when user builds content moderation, safety filters, or policy enforcement with Claude. Covers pre-filter vs LLM-classify, category design, confidence thresholds, and human-in-the-loop.
466
467
  - **council**: 4-perspective decision evaluation for architecture choices. Use when user wants multi-angle analysis, needs to decide between alternatives, or mentions 'council', 'evaluate decision', 'pros cons'. Codex-adapted: uses native subagents and plan tracking.
467
468
  - **csharp-patterns**: Loaded when user asks about C# or .NET development patterns
468
469
  - **cve-scan**: Scan project dependencies for known CVEs using native audit tools (npm, pip, composer, cargo, go, bundler, dart)
@@ -492,12 +493,15 @@ Skills are invocable commands or auto-loaded knowledge sources:
492
493
  - **instinct-review**: Review and manage learned instincts from past sessions
493
494
  - **introspect**: Agent self-debugging and recovery. Use when stuck in loops, making repeated errors, or quality degrades. Triggers: introspect, self-debug, stuck, loop, why failing.
494
495
  - **java-patterns**: Loaded when user asks about Java development patterns
496
+ - **json-mode-patterns**: Loaded when user needs structured JSON output from Claude. Covers tool-use-as-JSON-mode, schema design, parsing, partial recovery, and validation.
495
497
  - **kotlin-patterns**: Loaded when user asks about Kotlin development patterns
496
498
  - **lint**: Lint code with auto-detected tools and fix suggestions
499
+ - **mcp-builder**: Build production-grade MCP (Model Context Protocol) servers from scratch using the 4-phase methodology: research, implement, test, evaluate. Use when creating new MCP integrations for external APIs, databases, or internal services.
497
500
  - **mcp-patterns**: Loaded when user asks about MCP servers or tool protocol design
498
501
  - **mem-search**: Search past coding sessions using natural language. Finds relevant observations, decisions, and context from previous work.
499
502
  - **migrate**: Run database migrations with backup verification
500
503
  - **migration-patterns**: Loaded when user asks about database migrations or zero-downtime deploys
504
+ - **model-routing-patterns**: Loaded when user builds multi-model pipelines (Haiku/Sonnet/Opus). Covers cost-optimized routing, escalation, sub-agent delegation, and fallback chains.
501
505
  - **night-watch**: Run autonomous maintenance and dependency updates
502
506
  - **observability-patterns**: Loaded when user asks about logging, metrics, or tracing patterns
503
507
  - **onboard**: Generate project onboarding materials
@@ -512,6 +516,7 @@ Skills are invocable commands or auto-loaded knowledge sources:
512
516
  - **prd-to-issues**: Break a PRD into independently-grabbable GitHub issues using vertical slices with HITL/AFK tagging and dependency ordering. Use when user wants to convert a PRD to issues, create tickets, or break down a PRD into work items.
513
517
  - **prd-to-plan**: Convert a PRD into a phased implementation plan using tracer-bullet vertical slices. Use when user wants to break down a PRD, create an implementation plan, plan phases from a PRD, or mentions tracer bullets. Codex-adapted: uses native subagents and plan tracking.
514
518
  - **predict**: Predict regressions and impact before changes land
519
+ - **prompt-caching-patterns**: Loaded when user builds with Anthropic API and needs to cut cost or latency via prompt caching. Covers TTL, cache breakpoints, stacking, invalidation, and measuring hit rate.
515
520
  - **qa-session**: Interactive QA session where user reports bugs conversationally and agent files GitHub issues with domain language. Explores codebase in background for context. Use when user wants to report bugs, do QA, file issues conversationally, or mentions QA session. Codex-adapted: uses native subagents and plan tracking.
516
521
  - **rag-patterns**: Loaded when user asks about RAG systems, embeddings, or vector search
517
522
  - **refactor**: Refactor code for quality and maintainability
package/CHANGELOG.md CHANGED
@@ -7,6 +7,45 @@ Versioning follows [Semantic Versioning](https://semver.org/).
7
7
 
8
8
  ---
9
9
 
10
+ ## v2.7.0 — Anthropic Ecosystem Alignment (2026-04-17)
11
+
12
+ ### Added
13
+ - **`/mcp-builder` task skill** — opinionated 4-phase MCP server build workflow (Phase 1 research & planning, Phase 2 implementation with Zod/Pydantic schemas, Phase 3 review & testing via MCP Inspector, Phase 4 eval set of 10 realistic questions). Complements the existing `mcp-patterns` knowledge skill.
14
+ - **4 knowledge skills for Claude API work**, auto-loaded by relevant agents:
15
+ - `prompt-caching-patterns` — TTL, cache breakpoints, 4-layer stacking, hit-rate measurement, anti-patterns.
16
+ - `json-mode-patterns` — tool-use forcing as idiomatic JSON mode, schema design, partial-output recovery.
17
+ - `content-moderation-patterns` — 2-stage pre-filter + Haiku classifier, category design, threshold router, HIL queue.
18
+ - `model-routing-patterns` — Haiku/Sonnet/Opus routing, confidence-based escalation, Opus-planner-with-Haiku-workers sub-agent delegation, task-specific routing table.
19
+ - **2 output styles** in `app/output-styles/`:
20
+ - `learning.md` — interactive "⟶ Your turn" prompts on meaningful decisions, ★ Insight educational blocks.
21
+ - `explanatory.md` — one-way ★ Insight blocks exposing implementation trade-offs, no user prompts.
22
+ - **`app/ARCHITECTURE.md` → Frontmatter Schema section** — documents ai-toolkit's spec-defined fields (`name`, `description`, `license`, `compatibility`, `metadata`, `allowed-tools`) and top-level extensions (`user-invocable`, `disable-model-invocation`, `effort`, `agent`, `context`, `argument-hint`, `color`). Explains the comma-separated `allowed-tools` convention enforced by `scripts/codex_skill_adapter.py:70` and `scripts/audit_skills.py:157`.
23
+ - **`kb/reference/agent-skills-spec.md` (rag-mcp KB)** — canonical mirror of `agentskills.io/specification` with ai-toolkit extension mapping, validation commands, and progressive-disclosure tiers.
24
+ - **4 fixture tests in `tests/test_review_diff_analyzer.bats`** — category ordering (docs vs security), false-positive guard for unquoted identifier assignments (e.g. `request_token = generate_token_v2_legacy()` no longer flagged), quoted + unquoted env-style detection with accurate file/line tracking, rename record parsing in `git diff --numstat -z`. Test count: 660 → 664.
25
+
26
+ ### Changed
27
+ - **`/review` diff analyzer (`app/skills/review/scripts/diff-analyzer.py`) hardened end-to-end:**
28
+ - Secret scan now tracks the actual file line number per hunk (parses `@@ -a,b +c,d @@`) and reports `{"file": path, "line": file_line, "preview": snippet}`. Previously reported `line` was the offset in the unified diff text.
29
+ - Base ref existence verified via `git rev-parse --verify` before diffing. Silent fallback to `--cached` now emits a stderr notice and a `warnings[]` entry in the JSON output, so callers see the reduced scope explicitly.
30
+ - `git diff --numstat -z` parser replaces naive tab-split; rename entries (three NUL-separated tokens) are handled correctly.
31
+ - Secret pattern list expanded: JWT (three-segment), PEM private key header (`-----BEGIN … PRIVATE KEY-----`), Google API key (`AIza…`), Slack tokens (`xox[baprs]-…`), GitHub fine-grained PAT (`github_pat_…`), unquoted env-style assignments.
32
+ - Unquoted env-style pattern tightened so `request_token = generate_token_v2_legacy()` (snake_case identifier on RHS) is not flagged while `API_KEY=abcdef1234567890` and `API_KEY=SECRET_VALUE_XYZ` are. Uses scoped `(?-i:…)` for the ALL_CAPS constant alternative.
33
+ - Category regex reordered (`docs` and `test` checked before `security`) and anchored with word boundaries and path segments (`(^|/)…` / `\b…\b`). Files like `docs/role-permissions.md`, `roles_and_responsibilities.md`, `accessor.py` are now categorised correctly; `authentication_config_loader.py` resolves to `security`; `notification_settings.py` resolves to `logic` (not `config`).
34
+ - New output fields: `scope` (`"{base}...HEAD"` or `"staged"`), `warnings[]`.
35
+ - **Doc-count sync** — README, package.json, manifest.json, `app/.claude-plugin/plugin.json`, `app/ARCHITECTURE.md`, `kb/reference/skills-catalog.md`, `AGENTS.md`, `llms-full.txt` all advance to 99 skills (32 task / 31 hybrid / 36 knowledge) and 664 tests.
36
+
37
+ ---
38
+
39
+ ## v2.6.2 — Eject Count Fix (2026-04-17)
40
+
41
+ ### Fixed
42
+ - **`ai-toolkit eject` skill count** — reported `95 skills` while `validate.py` reported `94`. Root cause: eject iterated every directory under `app/skills/`, including the shared `_lib/` helper (no `SKILL.md`). Now matches `validate.py` semantics — skips underscore-prefixed dirs and requires `SKILL.md` for the count. `_lib/` is still copied so dependent skills (`ci`, `test`, `build`, `lint`) keep working after eject.
43
+
44
+ ### Added
45
+ - **Two eject tests** in `tests/test_eject.bats` — `eject reports skill count matching validate.py (excludes _lib helpers)` and `eject still copies _lib helper directory for dependent skills`. Test count: 658 → 660.
46
+
47
+ ---
48
+
10
49
  ## v2.6.1 — HIPAA Scanner Precision (2026-04-17)
11
50
 
12
51
  ### Changed
package/README.md CHANGED
@@ -1,36 +1,22 @@
1
1
  # ai-toolkit
2
2
 
3
- > Professional-grade AI coding toolkit with multi-platform support. Machine-enforced safety, 94 skills, 44 agents, expanded lifecycle hooks, persona presets, experimental opt-in plugin packs, and benchmark tooling — works with Claude, Cursor, Windsurf, Copilot, Gemini, Cline, Roo Code, Aider, Augment, Google Antigravity, Codex CLI, and opencode, ready in 60 seconds.
3
+ > Professional-grade AI coding toolkit with multi-platform support. Machine-enforced safety, 99 skills, 44 agents, expanded lifecycle hooks, persona presets, experimental opt-in plugin packs, and benchmark tooling — works with Claude, Cursor, Windsurf, Copilot, Gemini, Cline, Roo Code, Aider, Augment, Google Antigravity, Codex CLI, and opencode, ready in 60 seconds.
4
4
 
5
5
  [![CI](https://github.com/softspark/ai-toolkit/actions/workflows/ci.yml/badge.svg)](https://github.com/softspark/ai-toolkit/actions/workflows/ci.yml)
6
6
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
7
- [![Skills](https://img.shields.io/badge/skills-94-brightgreen)](app/skills/)
7
+ [![Skills](https://img.shields.io/badge/skills-99-brightgreen)](app/skills/)
8
8
  [![Agents](https://img.shields.io/badge/agents-44-blue)](app/agents/)
9
- [![Tests](https://img.shields.io/badge/tests-658%20passing-success)](tests/)
9
+ [![Tests](https://img.shields.io/badge/tests-664%20passing-success)](tests/)
10
10
 
11
11
  ---
12
12
 
13
- ## What's New in v2.6.1
13
+ ## What's New in v2.7.0
14
14
 
15
- - **HIPAA scanner precision** — Cat 3 TLS regexes anchored (`ssl.CERT_NONE`, `[,(] ssl=False`) to eliminate false positives on feature flags and constant names
16
- - **Cross-language isolation** — new `LANG_EXTENSIONS` filter ensures Python regexes don't match `.java` files in mixed projects, and vice versa
17
- - **`SECURE_SSL_REDIRECT = False` HIGH WARN** — commonly False in dev settings; reviewer confirms prod config instead of flooding every Django project with HIGH findings
18
- - **11 new bats tests** (`tests/test_hipaa_scan.bats`) fixture-driven positive/negative cases covering the Python pattern expansion and isolation guarantee. Test count: 647 658
19
-
20
- ## What's New in v2.6.0
21
-
22
- - **opencode integration** — `ai-toolkit install --editors opencode` generates `AGENTS.md`, `.opencode/agents/`, `.opencode/commands/`, plus a JS plugin bridging our Bash hooks to opencode's lifecycle events
23
- - **opencode MCP merge** — `.mcp.json` servers are translated into `opencode.json` under the `mcp` key, preserving user-authored entries
24
- - **Global opencode configs** — `~/.config/opencode/{AGENTS.md,agents/,commands/}` managed from `state.json`, auto-refreshed on `update`
25
- - **Shared AGENTS.md** — opencode and Codex CLI both read the same `AGENTS.md` via distinct marker sections; installing both does not clobber either
26
-
27
- ## What's New in v2.5.0
28
-
29
- - **`/seo-validate`** — 9-category SEO scanner with automated `seo-scanner.py` script (community contribution)
30
- - **`/a11y-validate`** — WCAG 2.1/2.2 + EAA accessibility scanner with `a11y-scanner.py` script (community contribution)
31
- - **Design Craft** — 7-domain impeccable design vocabulary in `frontend-specialist` + `frontend-lead` persona
32
- - **GEO/AEO reference** — Answer Engine Optimization patterns for AI answer engines
33
- - **94 skills** — 31 task + 31 hybrid + 32 knowledge
15
+ - **5 new skills aligned with Anthropic ecosystem** — `/mcp-builder` (task skill: 4-phase MCP server build methodology, research → implement → test → evaluate) and 4 knowledge skills auto-loaded for Claude API work: `prompt-caching-patterns`, `json-mode-patterns`, `content-moderation-patterns`, `model-routing-patterns`. Skill count: 94 → 99.
16
+ - **2 new output styles** in `app/output-styles/` — `learning` (interactive "your turn" prompts on meaningful decisions) and `explanatory` (★ Insight blocks surfacing implementation trade-offs). Both stack with the existing `golden-rules` style.
17
+ - **`/review` secrets scanner hardened** — `diff-analyzer.py` now tracks actual file line numbers (not diff offsets) per hunk, detects renames via `git diff --numstat -z`, surfaces a `warnings[]` array when falling back from branch diff to staged, and expands secret patterns (JWT, PEM private keys, Google API, Slack tokens, GitHub fine-grained PAT, unquoted env-style). Category regex tightened with word boundaries and anchored path patterns (`docs/role-permissions.md` is no longer miscategorised as security). 4 fixture tests in `tests/test_review_diff_analyzer.bats`.
18
+ - **Frontmatter Schema reference** — new section in `app/ARCHITECTURE.md` and canonical spec mirror at `kb/reference/agent-skills-spec.md` (in rag-mcp KB). Documents ai-toolkit's extensions beyond `agentskills.io/specification` and the comma-separated `allowed-tools` convention enforced by `codex_skill_adapter.py` and `audit_skills.py`.
19
+ - **Test count:** 660 → 664.
34
20
 
35
21
  See [CHANGELOG.md](CHANGELOG.md) for full history.
36
22
 
@@ -61,7 +47,7 @@ ai-toolkit install
61
47
  npx @softspark/ai-toolkit install
62
48
  ```
63
49
 
64
- **That's it.** Claude Code picks up 94 skills, 44 agents, quality hooks, and the safety constitution automatically.
50
+ **That's it.** Claude Code picks up 99 skills, 44 agents, quality hooks, and the safety constitution automatically.
65
51
 
66
52
  ### Update
67
53
 
@@ -131,9 +117,9 @@ See [CLI Reference](kb/reference/cli-reference.md) for all commands and options.
131
117
 
132
118
  | Component | Count | Description |
133
119
  |-----------|-------|-------------|
134
- | `skills/` (task) | 31 | Slash commands: `/commit`, `/build`, `/deploy`, `/test`, `/skill-audit`, ... |
120
+ | `skills/` (task) | 32 | Slash commands: `/commit`, `/build`, `/deploy`, `/test`, `/mcp-builder`, ... |
135
121
  | `skills/` (hybrid) | 31 | Slash commands with agent knowledge base |
136
- | `skills/` (knowledge) | 32 | Domain knowledge auto-loaded by agents |
122
+ | `skills/` (knowledge) | 36 | Domain knowledge auto-loaded by agents |
137
123
  | `agents/` | 44 | Specialized agents across 10 categories |
138
124
  | `hooks/` | 21 global + 5 skill-scoped | Quality gates, path safety, prompt governance, session lifecycle |
139
125
  | `plugins/` | 11 packs | Opt-in domain bundles (security, research, frontend, enterprise, 6 language packs) |
@@ -149,7 +135,7 @@ See [CLI Reference](kb/reference/cli-reference.md) for all commands and options.
149
135
  ai-toolkit/
150
136
  ├── app/
151
137
  │ ├── agents/ # 44 agent definitions
152
- │ ├── skills/ # 94 skills (task / hybrid / knowledge)
138
+ │ ├── skills/ # 99 skills (task / hybrid / knowledge)
153
139
  │ ├── rules/ # Auto-injected into your CLAUDE.md
154
140
  │ ├── hooks/ # Hook scripts (21 entries, 12 lifecycle events)
155
141
  │ ├── plugins/ # 11 experimental plugin packs (opt-in)
@@ -158,7 +144,7 @@ ai-toolkit/
158
144
  │ └── ARCHITECTURE.md # Full system design
159
145
  ├── kb/ # Reference docs, procedures, plans
160
146
  ├── scripts/ # Validation, install, evaluation scripts
161
- ├── tests/ # Bats test suite (658 tests)
147
+ ├── tests/ # Bats test suite (664 tests)
162
148
  └── CHANGELOG.md
163
149
  ```
164
150
 
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "ai-toolkit",
3
3
  "description": "Professional-grade Claude Code toolkit with persona presets, skill security auditor, expanded lifecycle hooks, experimental opt-in plugin packs, benchmark harvesting, and multi-tool support.",
4
- "version": "2.6.1",
4
+ "version": "2.7.0",
5
5
  "author": {
6
6
  "name": "SoftSpark",
7
7
  "url": "https://github.com/softspark"
@@ -102,7 +102,7 @@ Universal multi-agent system for software development. Works across all reposito
102
102
 
103
103
  ## Skills
104
104
 
105
- ### Task Skills (29)
105
+ ### Task Skills (32)
106
106
  | Skill | Slash Command | Purpose |
107
107
  |-------|---------------|---------|
108
108
  | `commit` | `/commit` | Create well-structured git commits (Conventional Commits) |
@@ -134,6 +134,7 @@ Universal multi-agent system for software development. Works across all reposito
134
134
  | `prd-to-issues` | `/prd-to-issues` | Break PRD into GitHub issues with vertical slices and HITL/AFK tagging |
135
135
  | `skill-audit` | `/skill-audit` | Scan skills and agents for security risks, dangerous patterns, secrets |
136
136
  | `hipaa-validate` | `/hipaa-validate` | Scan codebase for HIPAA compliance: PHI exposure, missing audit logging, unencrypted transmission/storage, access control gaps, temp file exposure, missing BAA references |
137
+ | `mcp-builder` | `/mcp-builder` | Build production-grade MCP servers using 4-phase methodology (research, implement, test, evaluate) |
137
138
 
138
139
  ### Hybrid Skills (31)
139
140
  | Skill | Slash Command | Purpose |
@@ -200,11 +201,15 @@ Universal multi-agent system for software development. Works across all reposito
200
201
  | `testing-patterns` | Multi-language testing strategies |
201
202
  | `migration-patterns` | Database & API migration patterns |
202
203
 
203
- ### Knowledge Skills - AI/RAG (2)
204
+ ### Knowledge Skills - AI/RAG (6)
204
205
  | Skill | Purpose |
205
206
  |-------|---------|
206
207
  | `rag-patterns` | RAG, retrieval optimization |
207
208
  | `mcp-patterns` | MCP server patterns |
209
+ | `prompt-caching-patterns` | Anthropic prompt caching: TTL, breakpoints, hit rate |
210
+ | `json-mode-patterns` | Structured JSON output via tool-use forcing |
211
+ | `content-moderation-patterns` | Two-stage moderation: pre-filter + LLM classifier |
212
+ | `model-routing-patterns` | Haiku/Sonnet/Opus routing, escalation, fallback |
208
213
 
209
214
  ### Knowledge Skills - Process (7)
210
215
  | Skill | Purpose |
@@ -346,3 +351,43 @@ The `inject_section_cli.py` script provides a stable marker-based injection API.
346
351
  5. **Read-Only Exploration**: Explorer agent never writes
347
352
  6. **Cite Sources**: Always include `[PATH: ...]`
348
353
  7. **Multi-Language**: All tools, hooks, and skills support multiple tech stacks
354
+
355
+ ---
356
+
357
+ ## Frontmatter Schema (Agent Skills spec + ai-toolkit extensions)
358
+
359
+ Canonical spec: https://agentskills.io/specification. ai-toolkit is spec-conformant on required fields and adds extensions at the top level for Claude Code integration.
360
+
361
+ ### Spec-defined fields (agentskills.io)
362
+
363
+ | Field | Required | Constraints |
364
+ |-------|----------|-------------|
365
+ | `name` | Yes | 1-64 chars, lowercase `a-z0-9` + hyphens, no leading/trailing hyphen, no `--`, must match parent directory |
366
+ | `description` | Yes | 1-1024 chars |
367
+ | `license` | No | License name or bundled file reference |
368
+ | `compatibility` | No | Max 500 chars; environment requirements |
369
+ | `metadata` | No | String-keyed map |
370
+ | `allowed-tools` | No | Space-separated per spec; ai-toolkit uses comma-separated (see below) |
371
+
372
+ ### ai-toolkit extensions (beyond spec)
373
+
374
+ These live at the top level for convenience. If a future strict spec parser is adopted, move them under `metadata:`.
375
+
376
+ | Field | Type | Purpose |
377
+ |-------|------|---------|
378
+ | `user-invocable` | bool | Surfaces the skill as a slash command. `false` = knowledge skill. |
379
+ | `disable-model-invocation` | bool | Task skill flag; prevents auto-invocation by the model. |
380
+ | `effort` | enum | `low`/`medium`/`high`/`max` — planner and SLM compiler hint. |
381
+ | `agent` | string | Delegates the skill to a specialized agent. |
382
+ | `context` | string | `fork` runs the skill in an isolated forked context. |
383
+ | `argument-hint` | string | Argument pattern for the CLI (e.g. `[symptom]`). |
384
+ | `color` | string | Visual tag for agent cards. |
385
+
386
+ ### `allowed-tools` format note
387
+
388
+ Spec example uses space separation: `allowed-tools: Bash(git:*) Read`. Claude Code parses several formats leniently: comma-separated, JSON array, and space-separated. **ai-toolkit uses comma-separated** because `scripts/codex_skill_adapter.py:70` and `scripts/audit_skills.py:157` split on `,`. Do not mass-convert unless adapter parsers change first.
389
+
390
+ ### Validation
391
+
392
+ Internal: `python3 scripts/validate.py --strict` + `python3 scripts/audit_skills.py --ci`.
393
+ External (optional): `skills-ref validate app/skills/` from https://github.com/agentskills/agentskills.
@@ -0,0 +1,64 @@
1
+ ---
2
+ name: Explanatory
3
+ description: Surfaces educational insights about implementation choices, codebase patterns, and design trade-offs. One-way explanation mode (no prompts for user input).
4
+ keep-coding-instructions: true
5
+ ---
6
+
7
+ ## Core Principle
8
+
9
+ Explain WHY, not just WHAT. After each non-trivial change, add an insight block that exposes the reasoning — patterns, trade-offs, consequences — tied to the actual codebase.
10
+
11
+ ## Insight Block Format
12
+
13
+ ```
14
+ ★ Insight
15
+ <2-3 short lines about implementation choices, patterns, or trade-offs in THIS codebase>
16
+ ```
17
+
18
+ Use one insight block per meaningful change, not per file.
19
+
20
+ ## What Counts as an Insight
21
+
22
+ - Why a specific pattern was chosen over plausible alternatives
23
+ - Convention the user would miss without reading 20 other files
24
+ - Trade-off being cashed in (e.g. "losing type safety here to keep the public API simple")
25
+ - Interaction with a subsystem the user hasn't touched in this session
26
+ - Non-obvious consequence that bites 3 steps later if ignored
27
+
28
+ ## What Is NOT an Insight
29
+
30
+ - "This function takes X and returns Y" (the code already says that)
31
+ - "Good practice is to X" (generic — say WHY it matters here)
32
+ - "Note that async functions return Promises" (basic language feature)
33
+ - Flattery or soft openings
34
+
35
+ ## Example
36
+
37
+ Bad:
38
+ ```
39
+ ★ Insight
40
+ This function uses async/await for better readability.
41
+ ```
42
+
43
+ Good:
44
+ ```
45
+ ★ Insight
46
+ `refreshToken()` is fire-and-forget here because `getUser()` already retries on 401.
47
+ If you call `refreshToken()` awaited from a hot path, you'll double-retry and hit the
48
+ rate limit faster than the original bug we're fixing.
49
+ ```
50
+
51
+ ## Scope
52
+
53
+ - Apply to feature work, refactors, non-trivial bug fixes.
54
+ - Skip for mechanical changes (rename, move, reformat).
55
+ - Skip inside `/orchestrate`, `/workflow`, `/swarm` — delegation output styles take over.
56
+
57
+ ## Token Cost
58
+
59
+ Insights add roughly 50-150 tokens per change. Worth it for understanding, not for bulk generation. Users should enable when working in unfamiliar code, disable when grinding through known territory.
60
+
61
+ ## Compatibility
62
+
63
+ - Stacks with `golden-rules` and `learning` — the latter adds user prompts, this one adds explanations only.
64
+ - Honors `Minimal Changes` — insights document what WAS done, never scope creep.
@@ -0,0 +1,70 @@
1
+ ---
2
+ name: Learning
3
+ description: Interactive learning mode. Claude requests the user's input on meaningful decisions and surfaces educational insights about the codebase.
4
+ keep-coding-instructions: true
5
+ ---
6
+
7
+ ## Core Principle
8
+
9
+ Transform the interaction from "watch and learn" to "build and understand." Involve the user in decisions that shape the result. Complete boilerplate without interruption.
10
+
11
+ ## When to Pause and Request User Input
12
+
13
+ Ask for 5-10 lines of contribution from the user when multiple valid approaches exist:
14
+
15
+ - Business logic with meaningful trade-offs
16
+ - Error handling strategy (fail fast vs. recover vs. queue)
17
+ - Architectural decisions (inline vs. extract, sync vs. async)
18
+ - Naming of public APIs that will outlast the session
19
+ - Choice of algorithm or data structure when several fit
20
+
21
+ Format:
22
+ ```
23
+ ⟶ Your turn: <specific decision or snippet>
24
+ Choose an approach:
25
+ A) <option with trade-off>
26
+ B) <option with trade-off>
27
+ C) <option with trade-off>
28
+ ```
29
+
30
+ Wait for the user's response before continuing.
31
+
32
+ ## When NOT to Pause
33
+
34
+ - Boilerplate (imports, config, DI wiring)
35
+ - Straightforward data transformations
36
+ - Fixing trivial bugs (typos, missing imports)
37
+ - Renames and mechanical refactors
38
+ - Following an existing pattern in the codebase
39
+
40
+ ## Educational Insights
41
+
42
+ After non-trivial changes, add 2-3 insights tied to the codebase (not general theory):
43
+
44
+ ```
45
+ ★ Insight
46
+ - <pattern-specific observation about THIS codebase>
47
+ - <trade-off being made in THIS change>
48
+ - <non-obvious consequence for nearby code>
49
+ ```
50
+
51
+ Focus on:
52
+ - Project conventions the user may not know
53
+ - Trade-offs specific to the current design
54
+ - Consequences that surface only at integration points
55
+ - Patterns that repeat elsewhere in the repo
56
+
57
+ Avoid:
58
+ - Generic programming theory
59
+ - Explanations the user already knows (inferred from their messages)
60
+ - Flattery ("great question")
61
+
62
+ ## Token Cost Warning
63
+
64
+ This style produces more tokens per response. Users should enable it deliberately for learning sessions, not for bulk refactors.
65
+
66
+ ## Compatibility
67
+
68
+ - Works alongside `golden-rules` rules: apply both.
69
+ - Disable for `/workflow`, `/orchestrate`, `/swarm` (delegation modes) — those pass through output style unchanged.
70
+ - Honors `Minimal Changes` and `No Phantom Files` from `golden-rules`.
@@ -0,0 +1,141 @@
1
+ ---
2
+ name: content-moderation-patterns
3
+ description: "Loaded when user builds content moderation, safety filters, or policy enforcement with Claude. Covers pre-filter vs LLM-classify, category design, confidence thresholds, and human-in-the-loop."
4
+ effort: medium
5
+ user-invocable: false
6
+ allowed-tools: Read
7
+ ---
8
+
9
+ # Content Moderation Patterns
10
+
11
+ Two-stage pattern that balances cost, latency, and quality: cheap deterministic filters first, then LLM classification only on survivors.
12
+
13
+ ## Architecture
14
+
15
+ ```
16
+ [ input ]
17
+
18
+
19
+ [ pre-filter ] ── (regex, allow/block lists, length check) ──► reject early
20
+
21
+
22
+ [ LLM classifier ] ── (Haiku, structured output) ──► categories + confidence
23
+
24
+
25
+ [ decision router ]
26
+ ├── high confidence + policy violation → reject
27
+ ├── high confidence + clean → pass
28
+ └── low confidence or edge categories → human review queue
29
+ ```
30
+
31
+ ## Pre-filter Stage (cheap)
32
+
33
+ Catch the obvious cases before paying an LLM call:
34
+
35
+ ```python
36
+ BANNED_PATTERNS = [
37
+ re.compile(r"\b(banned_term_1|banned_term_2)\b", re.I),
38
+ re.compile(r"\bhttps?://(?!allowed-domain\.com)", re.I), # external links
39
+ ]
40
+
41
+ def pre_filter(text: str) -> tuple[bool, str]:
42
+ if len(text) > 10_000:
43
+ return False, "too_long"
44
+ for pat in BANNED_PATTERNS:
45
+ if pat.search(text):
46
+ return False, f"banned_pattern:{pat.pattern}"
47
+ return True, "pass"
48
+ ```
49
+
50
+ Roughly 40-70% of spammy input should die here. Log counts by rule so you can tune.
51
+
52
+ ## LLM Classifier Stage (Haiku)
53
+
54
+ Use the smallest capable model. Haiku is usually right for moderation.
55
+
56
+ ```python
57
+ CATEGORIES = ["harassment", "self_harm", "spam", "off_topic", "pii", "clean"]
58
+
59
+ def classify(text: str) -> dict:
60
+ response = client.messages.create(
61
+ model="claude-haiku-4-5",
62
+ max_tokens=256,
63
+ tools=[{
64
+ "name": "moderate",
65
+ "description": "Classify content against policy",
66
+ "input_schema": {
67
+ "type": "object",
68
+ "properties": {
69
+ "categories": {
70
+ "type": "array",
71
+ "items": {"type": "string", "enum": CATEGORIES}
72
+ },
73
+ "confidence": {"type": "number", "minimum": 0, "maximum": 1},
74
+ "reasoning": {"type": "string", "maxLength": 200}
75
+ },
76
+ "required": ["categories", "confidence", "reasoning"]
77
+ }
78
+ }],
79
+ tool_choice={"type": "tool", "name": "moderate"},
80
+ system=POLICY_DESCRIPTION, # cached — stable across requests
81
+ messages=[{"role": "user", "content": text}]
82
+ )
83
+ return extract_tool_result(response)
84
+ ```
85
+
86
+ **Cache the policy description** — it's the same on every call. See `prompt-caching-patterns`.
87
+
88
+ ## Category Design
89
+
90
+ - **Start with 5-8 categories**, not 50. Fewer = higher per-category accuracy.
91
+ - **One `clean` category** — easier than trying to define "not bad"
92
+ - **No overlapping categories** — `harassment` and `hate_speech` should be merged or clearly separated by specific criteria in the policy doc
93
+ - **`unclear` / `needs_review` category** — gives the model a graceful escape hatch instead of forcing a wrong label
94
+
95
+ ## Threshold Router
96
+
97
+ ```python
98
+ def route(classification: dict) -> str:
99
+ conf = classification["confidence"]
100
+ cats = set(classification["categories"])
101
+
102
+ if "clean" in cats and conf > 0.8:
103
+ return "pass"
104
+ if cats & BLOCK_CATEGORIES and conf > 0.85:
105
+ return "reject"
106
+ if cats & BLOCK_CATEGORIES:
107
+ return "human_review"
108
+ return "human_review" # default to review on ambiguity
109
+ ```
110
+
111
+ Thresholds belong in config, not code — they change as you learn.
112
+
113
+ ## Human-in-the-Loop
114
+
115
+ - All `human_review` cases go to a queue with the model's reasoning
116
+ - Human decisions flow back into a dataset used to evaluate new model versions
117
+ - Track disagreement rate between human and model — rising disagreement signals policy drift
118
+
119
+ ## Evaluation Loop
120
+
121
+ Build a golden set of ~500 examples per category with ground truth. Track:
122
+ - **Precision per category** (of what we flagged, how much was truly bad)
123
+ - **Recall per category** (of truly bad, how much we caught)
124
+ - **False-positive cost** per category — harassment FP is cheap, "clean FP" (wrongly blocking good content) is expensive
125
+
126
+ ## Anti-patterns
127
+
128
+ | Anti-pattern | Why it bites | Fix |
129
+ |--------------|--------------|-----|
130
+ | One huge prompt asking "is this okay?" | Unstable answers, no tracking | Structured categories + confidence |
131
+ | Using Opus for moderation | 10x cost, no accuracy gain for this task | Haiku is fine |
132
+ | Hiding policy in user message | Policy gets mixed with input | Policy in system prompt, cached |
133
+ | Binary block/allow only | No signal for edge cases | Add review queue |
134
+ | No audit trail | Can't improve | Log every decision with full classification |
135
+
136
+ ## Related
137
+
138
+ - `security-patterns` — input validation at system boundaries
139
+ - `prompt-caching-patterns` — cache the policy doc
140
+ - `model-routing-patterns` — when to escalate from Haiku to Sonnet
141
+ - Anthropic docs: https://docs.claude.com/en/docs/about-claude/use-case-guides/content-moderation
@@ -0,0 +1,124 @@
1
+ ---
2
+ name: json-mode-patterns
3
+ description: "Loaded when user needs structured JSON output from Claude. Covers tool-use-as-JSON-mode, schema design, parsing, partial recovery, and validation."
4
+ effort: medium
5
+ user-invocable: false
6
+ allowed-tools: Read
7
+ ---
8
+
9
+ # JSON Mode Patterns
10
+
11
+ Claude does not have a dedicated `response_format: json` parameter like some other APIs. The idiomatic way to get guaranteed JSON is **tool use with a forced function call**. This skill documents that pattern plus fallbacks.
12
+
13
+ ## Preferred Pattern: Tool-as-Schema
14
+
15
+ Define a tool whose input schema IS the JSON shape you want, then force the model to call it.
16
+
17
+ ```python
18
+ tools = [{
19
+ "name": "record_analysis",
20
+ "description": "Return the analysis as structured data",
21
+ "input_schema": {
22
+ "type": "object",
23
+ "properties": {
24
+ "sentiment": {"type": "string", "enum": ["positive", "neutral", "negative"]},
25
+ "confidence": {"type": "number", "minimum": 0, "maximum": 1},
26
+ "themes": {"type": "array", "items": {"type": "string"}}
27
+ },
28
+ "required": ["sentiment", "confidence", "themes"]
29
+ }
30
+ }]
31
+
32
+ response = client.messages.create(
33
+ model="claude-opus-4-7",
34
+ max_tokens=1024,
35
+ tools=tools,
36
+ tool_choice={"type": "tool", "name": "record_analysis"},
37
+ messages=[{"role": "user", "content": text_to_analyze}]
38
+ )
39
+
40
+ # The structured result is in response.content
41
+ for block in response.content:
42
+ if block.type == "tool_use" and block.name == "record_analysis":
43
+ result = block.input # already a Python dict, schema-validated
44
+ break
45
+ ```
46
+
47
+ Why this wins:
48
+ - Schema is enforced at the API level
49
+ - No regex or parsing from model text
50
+ - Enums, min/max, required fields actually constrain the output
51
+
52
+ ## Fallback: Prompted JSON + Strict Parse
53
+
54
+ When tool use is unavailable (some SDKs/proxies strip it):
55
+
56
+ ```python
57
+ response = client.messages.create(
58
+ model="claude-opus-4-7",
59
+ max_tokens=1024,
60
+ system="You return ONLY valid JSON. No prose, no markdown fences.",
61
+ messages=[{
62
+ "role": "user",
63
+ "content": f"Extract as JSON matching this schema: {schema_str}\n\nInput: {text}"
64
+ }]
65
+ )
66
+
67
+ import json
68
+ try:
69
+ result = json.loads(response.content[0].text)
70
+ except json.JSONDecodeError:
71
+ # Claude sometimes wraps in ```json ... ```
72
+ result = json.loads(strip_markdown_fence(response.content[0].text))
73
+ ```
74
+
75
+ Add a regex fallback that extracts the first `{...}` block if the model added a preface.
76
+
77
+ ## Schema Design Rules
78
+
79
+ - **Favor enums** over free-form strings when values are known
80
+ - **Mark required fields** aggressively — default-optional produces flaky output
81
+ - **Use arrays of objects**, not parallel arrays (`[{name, value}]` over `{names: [], values: []}`)
82
+ - **Shallow beats nested** — 2 levels of nesting max unless necessary
83
+ - **Document each field** in the tool's `description` as well as the schema
84
+
85
+ ## Partial Output Recovery
86
+
87
+ Model hits `max_tokens` mid-JSON. Strategies:
88
+
89
+ 1. **Increase `max_tokens`** if the schema is genuinely large (most common cause).
90
+ 2. **Split the schema** — generate one field per call, merge.
91
+ 3. **Use streaming** and close unclosed braces if stop reason is `max_tokens`.
92
+
93
+ ```python
94
+ if response.stop_reason == "max_tokens":
95
+ # Either retry with higher budget or gracefully degrade
96
+ raise IncompleteOutputError(...)
97
+ ```
98
+
99
+ ## Validation After Parse
100
+
101
+ Even with tool schema enforcement, business rules aren't enforced by JSON Schema. Add a Pydantic/Zod layer:
102
+
103
+ ```python
104
+ from pydantic import BaseModel, Field
105
+
106
+ class Analysis(BaseModel):
107
+ sentiment: Literal["positive", "neutral", "negative"]
108
+ confidence: float = Field(ge=0, le=1)
109
+ themes: list[str] = Field(min_length=1, max_length=10)
110
+
111
+ parsed = Analysis(**result) # raises on violation
112
+ ```
113
+
114
+ ## Gotchas
115
+
116
+ - **Tool call tokens count toward output budget** — a huge schema eats max_tokens fast
117
+ - **`stop_reason == "tool_use"`** is success, not an error
118
+ - **Streaming with tool use** requires handling `content_block_delta` events with `input_json_delta` deltas
119
+ - **Model picks a different tool** than you expected if `tool_choice` is `"auto"` — always force the specific tool for JSON mode
120
+
121
+ ## Related
122
+
123
+ - `claude-api` skill — Anthropic SDK essentials
124
+ - Anthropic docs: https://docs.claude.com/en/docs/build-with-claude/structured-outputs