@softspark/ai-toolkit 2.6.2 → 2.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +5 -0
- package/CHANGELOG.md +39 -0
- package/README.md +11 -11
- package/app/.claude-plugin/plugin.json +1 -1
- package/app/ARCHITECTURE.md +47 -2
- package/app/output-styles/explanatory.md +64 -0
- package/app/output-styles/learning.md +70 -0
- package/app/skills/content-moderation-patterns/SKILL.md +141 -0
- package/app/skills/json-mode-patterns/SKILL.md +124 -0
- package/app/skills/mcp-builder/SKILL.md +139 -0
- package/app/skills/model-routing-patterns/SKILL.md +124 -0
- package/app/skills/prompt-caching-patterns/SKILL.md +114 -0
- package/app/skills/review/scripts/diff-analyzer.py +184 -46
- package/kb/reference/architecture-overview.md +2 -2
- package/kb/reference/skills-catalog.md +7 -2
- package/llms-full.txt +14 -4
- package/manifest.json +1 -1
- package/package.json +2 -2
- package/scripts/eject.py +17 -1
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.1 — Eject Output-Styles Fix (2026-04-17)
|
|
11
|
+
|
|
12
|
+
### Fixed
|
|
13
|
+
- **`ai-toolkit eject` now exports `app/output-styles/*.md`** — pre-existing gap dating back to when output-styles were introduced. `scripts/eject.py` copied agents, skills, rules, constitution, and ARCHITECTURE, but silently skipped the `output-styles/` directory. Standalone `.claude/` produced by eject had no system-prompt styles (no `golden-rules`, and after v2.7.0 no `learning`/`explanatory`). Now eject writes `.claude/output-styles/` with all source `.md` files and includes the count in the summary line: `Ejected: N agents, N skills, N rules, N output style(s)`.
|
|
14
|
+
|
|
15
|
+
### Added
|
|
16
|
+
- **2 `tests/test_eject.bats` cases** — `eject copies output-styles directory with all source styles` (also asserts `golden-rules.md` baseline) and `eject reports output-style count in summary line`. Test count: 664 → 666.
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## v2.7.0 — Anthropic Ecosystem Alignment (2026-04-17)
|
|
21
|
+
|
|
22
|
+
### Added
|
|
23
|
+
- **`/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.
|
|
24
|
+
- **4 knowledge skills for Claude API work**, auto-loaded by relevant agents:
|
|
25
|
+
- `prompt-caching-patterns` — TTL, cache breakpoints, 4-layer stacking, hit-rate measurement, anti-patterns.
|
|
26
|
+
- `json-mode-patterns` — tool-use forcing as idiomatic JSON mode, schema design, partial-output recovery.
|
|
27
|
+
- `content-moderation-patterns` — 2-stage pre-filter + Haiku classifier, category design, threshold router, HIL queue.
|
|
28
|
+
- `model-routing-patterns` — Haiku/Sonnet/Opus routing, confidence-based escalation, Opus-planner-with-Haiku-workers sub-agent delegation, task-specific routing table.
|
|
29
|
+
- **2 output styles** in `app/output-styles/`:
|
|
30
|
+
- `learning.md` — interactive "⟶ Your turn" prompts on meaningful decisions, ★ Insight educational blocks.
|
|
31
|
+
- `explanatory.md` — one-way ★ Insight blocks exposing implementation trade-offs, no user prompts.
|
|
32
|
+
- **`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`.
|
|
33
|
+
- **`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.
|
|
34
|
+
- **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.
|
|
35
|
+
|
|
36
|
+
### Changed
|
|
37
|
+
- **`/review` diff analyzer (`app/skills/review/scripts/diff-analyzer.py`) hardened end-to-end:**
|
|
38
|
+
- 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.
|
|
39
|
+
- 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.
|
|
40
|
+
- `git diff --numstat -z` parser replaces naive tab-split; rename entries (three NUL-separated tokens) are handled correctly.
|
|
41
|
+
- 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.
|
|
42
|
+
- 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.
|
|
43
|
+
- 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`).
|
|
44
|
+
- New output fields: `scope` (`"{base}...HEAD"` or `"staged"`), `warnings[]`.
|
|
45
|
+
- **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.
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
10
49
|
## v2.6.2 — Eject Count Fix (2026-04-17)
|
|
11
50
|
|
|
12
51
|
### Fixed
|
package/README.md
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
# ai-toolkit
|
|
2
2
|
|
|
3
|
-
> Professional-grade AI coding toolkit with multi-platform support. Machine-enforced safety,
|
|
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
|
[](https://github.com/softspark/ai-toolkit/actions/workflows/ci.yml)
|
|
6
6
|
[](LICENSE)
|
|
7
|
-
[](app/skills/)
|
|
8
8
|
[](app/agents/)
|
|
9
|
-
[](tests/)
|
|
10
10
|
|
|
11
11
|
---
|
|
12
12
|
|
|
13
|
-
## What's New in v2.
|
|
13
|
+
## What's New in v2.7.1
|
|
14
14
|
|
|
15
|
-
- **`ai-toolkit eject`
|
|
16
|
-
- **
|
|
15
|
+
- **`ai-toolkit eject` now copies `app/output-styles/*.md`** — pre-existing gap since output-styles were introduced: eject produced a standalone `.claude/` without any system-prompt styles, so `golden-rules`, `learning`, and `explanatory` silently dropped out after ejecting. Now eject writes `.claude/output-styles/` with all source `.md` files and reports the count in the summary line: `Ejected: N agents, N skills, N rules, N output style(s)`.
|
|
16
|
+
- **2 new `tests/test_eject.bats` cases** covering output-styles: directory created + file count matches source + `golden-rules.md` baseline, and summary line reports correct count. Test count: 664 → 666.
|
|
17
17
|
|
|
18
18
|
See [CHANGELOG.md](CHANGELOG.md) for full history.
|
|
19
19
|
|
|
@@ -44,7 +44,7 @@ ai-toolkit install
|
|
|
44
44
|
npx @softspark/ai-toolkit install
|
|
45
45
|
```
|
|
46
46
|
|
|
47
|
-
**That's it.** Claude Code picks up
|
|
47
|
+
**That's it.** Claude Code picks up 99 skills, 44 agents, quality hooks, and the safety constitution automatically.
|
|
48
48
|
|
|
49
49
|
### Update
|
|
50
50
|
|
|
@@ -114,9 +114,9 @@ See [CLI Reference](kb/reference/cli-reference.md) for all commands and options.
|
|
|
114
114
|
|
|
115
115
|
| Component | Count | Description |
|
|
116
116
|
|-----------|-------|-------------|
|
|
117
|
-
| `skills/` (task) |
|
|
117
|
+
| `skills/` (task) | 32 | Slash commands: `/commit`, `/build`, `/deploy`, `/test`, `/mcp-builder`, ... |
|
|
118
118
|
| `skills/` (hybrid) | 31 | Slash commands with agent knowledge base |
|
|
119
|
-
| `skills/` (knowledge) |
|
|
119
|
+
| `skills/` (knowledge) | 36 | Domain knowledge auto-loaded by agents |
|
|
120
120
|
| `agents/` | 44 | Specialized agents across 10 categories |
|
|
121
121
|
| `hooks/` | 21 global + 5 skill-scoped | Quality gates, path safety, prompt governance, session lifecycle |
|
|
122
122
|
| `plugins/` | 11 packs | Opt-in domain bundles (security, research, frontend, enterprise, 6 language packs) |
|
|
@@ -132,7 +132,7 @@ See [CLI Reference](kb/reference/cli-reference.md) for all commands and options.
|
|
|
132
132
|
ai-toolkit/
|
|
133
133
|
├── app/
|
|
134
134
|
│ ├── agents/ # 44 agent definitions
|
|
135
|
-
│ ├── skills/ #
|
|
135
|
+
│ ├── skills/ # 99 skills (task / hybrid / knowledge)
|
|
136
136
|
│ ├── rules/ # Auto-injected into your CLAUDE.md
|
|
137
137
|
│ ├── hooks/ # Hook scripts (21 entries, 12 lifecycle events)
|
|
138
138
|
│ ├── plugins/ # 11 experimental plugin packs (opt-in)
|
|
@@ -141,7 +141,7 @@ ai-toolkit/
|
|
|
141
141
|
│ └── ARCHITECTURE.md # Full system design
|
|
142
142
|
├── kb/ # Reference docs, procedures, plans
|
|
143
143
|
├── scripts/ # Validation, install, evaluation scripts
|
|
144
|
-
├── tests/ # Bats test suite (
|
|
144
|
+
├── tests/ # Bats test suite (666 tests)
|
|
145
145
|
└── CHANGELOG.md
|
|
146
146
|
```
|
|
147
147
|
|
|
@@ -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.
|
|
4
|
+
"version": "2.7.1",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "SoftSpark",
|
|
7
7
|
"url": "https://github.com/softspark"
|
package/app/ARCHITECTURE.md
CHANGED
|
@@ -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 (
|
|
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 (
|
|
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
|