@event4u/agent-config 1.27.0 → 1.29.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.
Files changed (34) hide show
  1. package/.agent-src/commands/research.md +142 -0
  2. package/.agent-src/contexts/contracts/frugality-charter.md +4 -3
  3. package/.agent-src/contexts/contracts/research-schema.md +117 -0
  4. package/.agent-src/rules/domain-adoption-policy.md +1 -1
  5. package/.agent-src/rules/no-roadmap-references.md +1 -1
  6. package/.agent-src/rules/no-unsolicited-rebase.md +1 -1
  7. package/.agent-src/rules/scope-control.md +6 -8
  8. package/.agent-src/skills/async-python-patterns/SKILL.md +147 -0
  9. package/.agent-src/skills/deep-reading-analyst/SKILL.md +192 -0
  10. package/.agent-src/skills/defense-in-depth/SKILL.md +152 -0
  11. package/.agent-src/skills/error-handling-patterns/SKILL.md +134 -0
  12. package/.agent-src/skills/mcp-builder/SKILL.md +108 -0
  13. package/.agent-src/skills/prompt-engineering-patterns/SKILL.md +145 -0
  14. package/.agent-src/skills/repomix/SKILL.md +135 -0
  15. package/.agent-src/skills/roadmap-writing/SKILL.md +3 -3
  16. package/.agent-src/skills/secrets-management/SKILL.md +142 -0
  17. package/.agent-src/skills/testing-anti-patterns/SKILL.md +145 -0
  18. package/.agent-src/templates/agent-settings.md +1 -1
  19. package/.claude-plugin/marketplace.json +11 -1
  20. package/CHANGELOG.md +57 -0
  21. package/README.md +3 -3
  22. package/docs/architecture.md +3 -3
  23. package/docs/catalog.md +20 -7
  24. package/docs/contracts/command-clusters.md +1 -0
  25. package/docs/contracts/file-ownership-matrix.json +1644 -165
  26. package/docs/contracts/package-self-orientation.md +1 -1
  27. package/docs/decisions/ADR-004-rule-governance-pruning.md +3 -3
  28. package/docs/getting-started.md +1 -1
  29. package/docs/guidelines/agent-infra/inversion-thinking.md +388 -0
  30. package/docs/guidelines/agent-infra/mcp-request-signing.md +11 -14
  31. package/docs/guidelines/agent-infra/mental-models.md +314 -0
  32. package/docs/guidelines/agent-infra/scqa-framework.md +526 -0
  33. package/package.json +1 -1
  34. package/scripts/schemas/skill.schema.json +15 -0
@@ -0,0 +1,192 @@
1
+ ---
2
+ name: deep-reading-analyst
3
+ description: "Deep analysis of articles/long-form via thinking frameworks (SCQA, mental models, inversion) — 'analyze article', 'deep dive', 'extract insights', URL/text wanting depth not summary."
4
+ status: active
5
+ source: package
6
+ external_source: "https://github.com/ginobefun/deep-reading-analyst-skill/tree/26cd7dc9920e025d39751e396e707399022e49ef/src/deep-reading-analyst"
7
+ refresh_trigger: "Upstream `ginobefun/deep-reading-analyst-skill` major rewrite (new framework added, dispatch table reshaped, or SHA pin invalidated by reference rename)."
8
+ sunset_criterion: "Replace with a 50-line pointer skill if (a) all referenced modules are adopted as project-local guidelines (`docs/guidelines/agent-infra/{framework}.md`) AND (b) the dispatch logic moves into a project-native router."
9
+ ---
10
+
11
+ > **Pinned upstream:** `ginobefun/deep-reading-analyst-skill` @ SHA `26cd7dc9` (MIT). Re-verify per upstream major rewrite. Reference modules below link to the same SHA.
12
+
13
+ # deep-reading-analyst
14
+
15
+ Wing-1 deep-thinking skill for articles, papers, opinion pieces, case studies, and long-form decision documents. Routes the user's content through 8 thinking frameworks at four depth levels (Quick / Standard / Deep / Research) and returns insight tied to the user's **goal**, not framework completion.
16
+
17
+ ## When to use
18
+
19
+ - User pastes an article URL, paper, or long text and wants depth ("analyze", "deep dive", "extract insights", "help me understand").
20
+ - User asks for a specific framework ("apply SCQA to this", "use inversion thinking", "give me the mental models lens").
21
+ - User is making a decision and wants pre-mortem / multi-lens analysis on a written proposal.
22
+ - User is studying or note-taking on dense material (research papers, strategy memos, books).
23
+
24
+ Do NOT use when:
25
+ - User wants a 3-bullet TL;DR — use `agent-docs-writing` or write a direct summary.
26
+ - Content is code or a diff — route to `judge-bug-hunter`, `judge-code-quality`, or `adversarial-review`.
27
+ - User wants risk analysis on a code change — route to `adversarial-review` (diff-bound) or `threat-modeling`.
28
+ - User wants debugging or incident analysis — route to `bug-analyzer` or `systematic-debugging`.
29
+
30
+ ## Framework Arsenal
31
+
32
+ | Depth | Time | Frameworks | Reference module |
33
+ |---|---|---|---|
34
+ | **L1 — Quick** | ~15 min | SCQA, 5W2H | [`scqa-framework`](../../../docs/guidelines/agent-infra/scqa-framework.md), `5w2h_analysis.md` (upstream) |
35
+ | **L2 — Standard** | ~30 min | L1 + Critical Thinking, Inversion | + [`inversion-thinking`](../../../docs/guidelines/agent-infra/inversion-thinking.md), `critical_thinking.md` (upstream) |
36
+ | **L3 — Deep** | ~60 min | L2 + Mental Models, First Principles, Systems Thinking, Six Hats | + [`mental-models`](../../../docs/guidelines/agent-infra/mental-models.md), `first_principles.md`, `systems_thinking.md`, `six_hats.md` (upstream) |
37
+ | **L4 — Research** | 120 min+ | L3 + Cross-source comparison via web search | + `comparison_matrix.md` (upstream) |
38
+
39
+ Modules tagged `(upstream)` link to SHA-pinned files at the URL in `external_source` above; project-local modules are adopted as guidelines.
40
+
41
+ ## Procedure: deep-reading-analyst
42
+
43
+ ### Step 0: Inspect
44
+
45
+ 1. **Detect content type** — article, paper, opinion piece, case study, how-to, strategy memo. Drives auto-suggested frameworks (Step 1).
46
+ 2. **Detect goal signal** — problem-solving, learning, writing reference, decision-making, curiosity. Drives Step 4 output shape.
47
+ 3. **Skip if mismatched** — see "Do NOT use when" above; route to the named skill.
48
+
49
+ ### Step 1: Initialize Analysis
50
+
51
+ Ask the user three things in **one** message (not three turns), per `ask-when-uncertain` Iron Law (one question per turn — these three are bundled into a single numbered-options block):
52
+
53
+ 1. **Goal** — problem-solving · learning · writing · decision-making · curiosity.
54
+ 2. **Depth** — L1 Quick (15 min) · L2 Standard (30 min) · L3 Deep (60 min) · L4 Research (120 min+).
55
+ 3. **Framework override** — defaults are auto-suggested by content type (table below); user may name specific frameworks.
56
+
57
+ If the user does not answer, default to L2 Standard with auto-selected frameworks.
58
+
59
+ **Auto-suggest matrix:**
60
+
61
+ | Content type | Default frameworks |
62
+ |---|---|
63
+ | Strategy / business article | SCQA + Mental Models + Inversion |
64
+ | Research paper | 5W2H + Critical Thinking + Systems Thinking |
65
+ | How-to guide | SCQA + 5W2H + First Principles |
66
+ | Opinion piece | Critical Thinking + Inversion + Six Hats |
67
+ | Case study | SCQA + Mental Models + Systems Thinking |
68
+
69
+ ### Step 2: Structural Understanding (always run)
70
+
71
+ Regardless of depth, open with two short blocks:
72
+
73
+ **2A — Basic structure.**
74
+
75
+ ```markdown
76
+ 📄 Type: [article/paper/report]
77
+ 🎯 Core thesis: [one sentence]
78
+ Structure:
79
+ ├─ Argument 1 → [key support]
80
+ ├─ Argument 2 → [key support]
81
+ └─ Argument 3 → [key support]
82
+ Key concepts: [3–5 terms with one-line definitions]
83
+ ```
84
+
85
+ **2B — SCQA breakdown.** Apply the four-element decomposition from [`scqa-framework`](../../../docs/guidelines/agent-infra/scqa-framework.md):
86
+
87
+ ```markdown
88
+ **S (Situation)**: [context the article establishes]
89
+ **C (Complication)**: [problem identified]
90
+ **Q (Question)**: [core question]
91
+ **A (Answer)**: [main solution / conclusion]
92
+ Structure quality — clarity / logic / completeness: [★★★☆☆]
93
+ ```
94
+
95
+ **2C — 5W2H gap check** (L1+). Quick scan: which of *What, Why, Who, When, Where, How, How much* are well-covered, partial, or missing? Flag the 1–2 most critical gaps.
96
+
97
+ ### Step 3: Apply Frameworks (depth-gated)
98
+
99
+ Load only the frameworks the user's depth bought. Each framework follows the same pattern: **load reference module → apply lens → produce one fixed-shape block**.
100
+
101
+ **L2 additions:**
102
+
103
+ - **Critical Thinking** (`critical_thinking.md`, upstream) — argument strength score (X/10), strengths, weaknesses, logical fallacies detected.
104
+ - **Inversion** ([`inversion-thinking`](../../../docs/guidelines/agent-infra/inversion-thinking.md)) — pre-mortem on the article's recommendation: "how would this fail?", missing risk factors, mitigations.
105
+
106
+ **L3 additions:**
107
+
108
+ - **Mental Models** ([`mental-models`](../../../docs/guidelines/agent-infra/mental-models.md)) — pick 3–5 models from different disciplines (physics, biology, psychology, economics, math), apply each lens, surface cross-model patterns.
109
+ - **First Principles** (`first_principles.md`, upstream) — strip to fundamental truths, validate each core assumption, rebuild from base.
110
+ - **Systems Thinking** (`systems_thinking.md`, upstream) — map relationships, feedback loops, leverage points.
111
+ - **Six Hats** (`six_hats.md`, upstream) — White (facts), Red (feelings), Black (cautions), Yellow (benefits), Green (creativity), Blue (process).
112
+
113
+ **L4 addition:**
114
+
115
+ - **Cross-source comparison** (`comparison_matrix.md`, upstream) — web-search 2–3 related sources, compare SCQA across sources, identify consensus vs divergence, synthesize integrated perspective.
116
+
117
+ ### Step 4: Synthesize by Goal
118
+
119
+ Output shape is **driven by Step 0 goal**, not by frameworks applied. Pick exactly one of the four blocks below.
120
+
121
+ **For problem-solving:** Applicable solutions (2–3 from content) → Application plan with timed action steps → Success metrics → Risk mitigations from Inversion.
122
+
123
+ **For learning:** Core concepts (definition + example) → Mental models gained → Connections to prior knowledge → First Principles fundamental question → 3 verification questions (understanding / application / evaluation).
124
+
125
+ **For writing reference:** Key arguments + evidence (with paragraph citations) → Quotable insights with context → Critical analysis (strengths for citing, limitations for balanced discussion) → Alternative perspectives from Mental Models → Gaps and counterfactuals.
126
+
127
+ **For decision-making:** Options presented → Multi-model evaluation (economic + risk + systems lens) → Six Hats decision analysis → Scenario analysis (best / worst / most likely) → Synthesized recommendation.
128
+
129
+ ### Step 5: Knowledge Activation (always end here)
130
+
131
+ Regardless of goal, close with three fixed blocks:
132
+
133
+ ```markdown
134
+ ## 🎯 Top 3 takeaways
135
+ 1. **[Insight]** — Why it matters: [...] · One action: [specific, time-bound]
136
+ 2. **[Insight]** — Why it matters: [...] · One action: [specific, time-bound]
137
+ 3. **[Insight]** — Why it matters: [...] · One action: [specific, time-bound]
138
+
139
+ ## 💡 Quick win — one tiny, specific action for the next 24 hours.
140
+
141
+ ## 🧭 Frameworks used
142
+ ✅ SCQA ✅ 5W2H ✅ Critical ✅ Inversion
143
+ □ Mental Models □ First Principles □ Systems □ Six Hats
144
+ ```
145
+
146
+ ### Step 6: Validate
147
+
148
+ 1. Every claim is faithful to the source — no misrepresentation, facts distinguished from opinions.
149
+ 2. Frameworks applied **purposefully**, not force-fit — drop a framework that adds no insight rather than padding the output.
150
+ 3. Output ends with concrete, actionable steps — no analysis-without-application.
151
+ 4. Specific citations (paragraph numbers, quotes) where the source supports them.
152
+
153
+ ## Output format
154
+
155
+ 1. **Structural block (Step 2)** — type / thesis / structure tree / key concepts / SCQA / 5W2H gaps.
156
+ 2. **Framework blocks (Step 3)** — one fixed-shape block per framework the depth bought.
157
+ 3. **Goal-shaped synthesis (Step 4)** — problem-solving / learning / writing / decision-making.
158
+ 4. **Knowledge activation (Step 5)** — top 3 takeaways · quick win · frameworks-used checkboxes.
159
+
160
+ ## Gotcha
161
+
162
+ - The model tends to **apply every framework** even at L1 — respect the depth budget; skip frameworks the user did not buy.
163
+ - The model tends to **summarize** instead of analyze when the user pastes long text — go deep on 1–3 points, not shallow on all of them.
164
+ - Inversion drifts into adversarial code review — this skill targets **decisions and arguments**, not diffs. Route diff stress-tests to `adversarial-review` / `judge-bug-hunter`.
165
+ - Mental Models drifts into name-dropping — pick 3–5, apply each lens *concretely* to the article's claims, drop models that yield no new insight.
166
+ - L4 cross-source comparison drifts into a literature review — keep it to 2–3 sources, focus on consensus / divergence / unique value.
167
+ - Output without action steps is a failure mode — every Step-4 synthesis must end with timed, concrete actions tied to the user's goal.
168
+
169
+ ## Do NOT
170
+
171
+ - Do NOT force-apply all frameworks at the user's chosen depth — drop ones that add no insight.
172
+ - Do NOT copy text verbatim from the source — always reword for the user's understanding.
173
+ - Do NOT use academic jargon without one-line definitions in the "key concepts" block.
174
+ - Do NOT skip Step 5 — the takeaways + quick win are the load-bearing output, not optional decoration.
175
+ - Do NOT route code reviews, diff stress-tests, or incident debugging through this skill.
176
+
177
+ ## Reference modules
178
+
179
+ Project-local guidelines (full text adopted under the Reference-Guideline Sunset Policy):
180
+
181
+ - [`scqa-framework`](../../../docs/guidelines/agent-infra/scqa-framework.md) — full 499-line authoritative-link adopt.
182
+ - [`mental-models`](../../../docs/guidelines/agent-infra/mental-models.md) — pure adopt of Munger's multi-discipline toolkit.
183
+ - [`inversion-thinking`](../../../docs/guidelines/agent-infra/inversion-thinking.md) — pre-mortem on decisions, distinct from `adversarial-review`.
184
+
185
+ Upstream modules (loaded on demand from the SHA-pinned URL in `external_source`):
186
+
187
+ - `5w2h_analysis.md` — completeness check (7 questions).
188
+ - `critical_thinking.md` — argument quality / fallacy detection.
189
+ - `first_principles.md` — fundamental-truth extraction.
190
+ - `systems_thinking.md` — feedback loops + leverage points.
191
+ - `six_hats.md` — White / Red / Black / Yellow / Green / Blue protocol.
192
+ - `comparison_matrix.md` — cross-source synthesis (L4 only).
@@ -0,0 +1,152 @@
1
+ ---
2
+ name: defense-in-depth
3
+ description: "Use when validation needs entry, business-logic, environment, and instrumentation guards so a bad value cannot reach the failure point — turns a local bug fix into a structural one."
4
+ source: package
5
+ ---
6
+
7
+ # defense-in-depth
8
+
9
+ Validate at every layer the value passes through. Fixing the bug at one layer is locally sufficient and globally fragile — the next refactor, code path, mock, or platform edge case will rediscover it. Four-layer validation makes the bug *structurally* impossible.
10
+
11
+ ## When to use
12
+
13
+ - Bug fix where invalid data caused failure several frames deep.
14
+ - New entry point that funnels external input into existing internals.
15
+ - Refactor that adds a second caller to a previously single-caller routine.
16
+ - Test setup that shortcuts production guards (mocks bypassing entry validation).
17
+
18
+ Do NOT use when:
19
+
20
+ - Pure formatting / style change — no data flow, no layers to defend.
21
+ - Boundary validation alone is correct (e.g. immutable value object with constructor invariant) — route to [`laravel-validation`](../laravel-validation/SKILL.md).
22
+ - The fix belongs at a single architectural seam — adding three more guards is over-engineering. Use the gate function below to stop early.
23
+
24
+ ## Procedure: Apply the four-layer pattern
25
+
26
+ ### Step 0: Analyze the data flow before adding guards
27
+
28
+ 1. Identify where the bad value originates (test fixture, request body, env var, config).
29
+ 2. List every function that receives the value before the failure point.
30
+ 3. Mark which functions are reachable from production paths and which only from tests.
31
+
32
+ ### Step 1: Layer 1 — Entry-point validation
33
+
34
+ Reject obviously invalid input at the API / route / command boundary. In Laravel this is FormRequest rules; in pure PHP services it is the public method on the service.
35
+
36
+ ```php
37
+ public function createProject(string $name, string $workingDirectory): Project
38
+ {
39
+ if (trim($workingDirectory) === '') {
40
+ throw new InvalidArgumentException('workingDirectory cannot be empty');
41
+ }
42
+ if (! is_dir($workingDirectory)) {
43
+ throw new InvalidArgumentException("workingDirectory does not exist: {$workingDirectory}");
44
+ }
45
+ if (! is_writable($workingDirectory)) {
46
+ throw new InvalidArgumentException("workingDirectory is not writable: {$workingDirectory}");
47
+ }
48
+ // ... proceed
49
+ }
50
+ ```
51
+
52
+ ### Step 2: Layer 2 — Business-logic validation
53
+
54
+ Verify the value still makes sense for the operation that consumes it. Different code paths can reach the same internal — re-check rather than trust the caller.
55
+
56
+ ```php
57
+ public function initializeWorkspace(string $projectDir, string $sessionId): Workspace
58
+ {
59
+ if ($projectDir === '') {
60
+ throw new RuntimeException('projectDir required for workspace initialization');
61
+ }
62
+ // ... proceed
63
+ }
64
+ ```
65
+
66
+ ### Step 3: Layer 3 — Environment guards
67
+
68
+ Refuse dangerous operations in the wrong context — most often: running a destructive command outside a test temp dir while the test suite is active.
69
+
70
+ ```php
71
+ public function gitInit(string $directory): void
72
+ {
73
+ if (app()->environment('testing')) {
74
+ $normalized = realpath($directory) ?: $directory;
75
+ $tmp = realpath(sys_get_temp_dir());
76
+
77
+ if ($tmp === false || ! str_starts_with($normalized, $tmp)) {
78
+ throw new RuntimeException("refusing git init outside tmp during tests: {$directory}");
79
+ }
80
+ }
81
+ // ... proceed
82
+ }
83
+ ```
84
+
85
+ ### Step 4: Layer 4 — Debug instrumentation
86
+
87
+ Capture context for forensics so the next failure surfaces *why*, not just *that*. Log only when the call is about to hit an irreversible side effect.
88
+
89
+ ```php
90
+ public function gitInit(string $directory): void
91
+ {
92
+ Log::debug('about to git init', [
93
+ 'directory' => $directory,
94
+ 'cwd' => getcwd(),
95
+ 'trace' => (new Exception)->getTraceAsString(),
96
+ ]);
97
+ // ... proceed
98
+ }
99
+ ```
100
+
101
+ ### Step 5: Verify each layer in isolation
102
+
103
+ Try to bypass Layer 1 (call the internal directly) and confirm Layer 2 catches it. Mock the production guard and confirm Layer 3 still refuses. The pattern only earns its name when each layer is independently provable.
104
+
105
+ ## Gate function — when to stop adding layers
106
+
107
+ ```
108
+ BEFORE adding the 5th guard:
109
+ STOP — re-check the data flow.
110
+
111
+ IF the value crosses ≤ 1 module boundary:
112
+ Use a single boundary check + a value-object invariant. Two layers max.
113
+
114
+ IF every layer would re-implement the same predicate:
115
+ Hoist the predicate into a value object / type and inject. One check is enough.
116
+
117
+ Layers are for distinct concerns: input shape vs operation invariant
118
+ vs environment risk vs forensic visibility. Same concern repeated is duplication, not depth.
119
+ ```
120
+
121
+ ## Output format
122
+
123
+ 1. The four guards (or a documented subset, with the gate-function justification).
124
+ 2. Tests that bypass each layer to prove the next layer catches the failure.
125
+ 3. One-line note on the data flow that motivated the layering.
126
+
127
+ ## Gotcha
128
+
129
+ - Layers 1 and 2 must reject with **distinct** errors — same error string makes the second guard look like a duplicate.
130
+ - Layer 3 environment checks should fail closed: unknown environment treated as production.
131
+ - Layer 4 instrumentation must not change behavior — no early returns, no mutated state.
132
+ - Test bypasses (in-process mocks) often skip Layer 1 — Layer 2 catches them; do not weaken Layer 2 to silence the test.
133
+
134
+ ## Do NOT
135
+
136
+ - Do NOT replicate Layer 1 inside private methods that only Layer 1 can reach.
137
+ - Do NOT log secrets in Layer 4 — sanitize before `Log::debug`.
138
+ - Do NOT use Layer 3 to gate business logic — environments change, business rules do not.
139
+ - Do NOT add a layer without a failing test that proves the layer was needed.
140
+
141
+ ## Auto-trigger keywords
142
+
143
+ - defense in depth
144
+ - multiple validation layers
145
+ - bug deep in execution
146
+ - structurally impossible
147
+
148
+ ## Provenance
149
+
150
+ - Adopted from: `Microck/ordinary-claude-skills@8f5c83174f7aa683b4ddc7433150471983b93131:skills_all/defense-in-depth/SKILL.md` (MIT, © 2025 Microck).
151
+ - Provenance registry: `agents/contexts/skills-provenance.yml` (entry: `defense-in-depth`).
152
+ - Iron-Law floor: `non-destructive-by-default`, `verify-before-complete`, `skill-quality`.
@@ -0,0 +1,134 @@
1
+ ---
2
+ name: error-handling-patterns
3
+ description: "Use when picking a failure-reporting strategy — exceptions vs Result types, recoverable vs not, retry / circuit-breaker / graceful degradation — decision framework only, catalogues externalized."
4
+ source: package
5
+ status: active
6
+ refresh_trigger: "≥30% of cited upstream pattern catalogues become deprecated, OR a new top-2 ecosystem (Python/JS/PHP/Go/Rust) ships a paradigm-shifting standard error model"
7
+ sunset_criterion: "When the upstream framework docs (Laravel, FastAPI, Express, Axum, Effect-TS) all carry an equivalent in-tree decision framework AND consumer projects no longer cite this skill in PR reviews for two consecutive review cycles."
8
+ ---
9
+
10
+ # error-handling-patterns
11
+
12
+ Decision framework for picking an error-handling strategy. **Catalogues of language-specific code live upstream** (links in § Provenance) — this skill is the predicate, not the pattern library. Sunset-policy compliant: large language-specific catalogues stay in authoritative upstream docs.
13
+
14
+ ## When to use
15
+
16
+ - Designing how a new feature, API, or service reports failure.
17
+ - Reviewing a diff that introduces a new exception class, `Result<T, E>`, or sentinel return.
18
+ - Debugging production noise that traces back to inconsistent error semantics.
19
+ - Choosing between retry, circuit-breaker, fallback, and fail-fast for an external dependency.
20
+
21
+ Do NOT use when:
22
+
23
+ - You only need the syntax for a `try/catch` in language X — read the upstream language guide directly.
24
+ - The failure is a single-call Laravel validation error — route to [`laravel-validation`](../laravel-validation/SKILL.md).
25
+ - The fix is a one-line null check in existing code — route to [`bug-analyzer`](../bug-analyzer/SKILL.md).
26
+
27
+ ## Decision framework
28
+
29
+ ### Step 1 — Classify the failure
30
+
31
+ ```
32
+ Failure is:
33
+ caller's fault (bad input, missing auth) → reject at boundary, structured error
34
+ expected operational (timeout, 404, rate-limit) → Result-type / typed return; retry-aware
35
+ unexpected operational (DB down, OOM, deadlock) → exception; observability + alert
36
+ programmer bug (null deref, off-by-one) → crash early; do not catch
37
+ ```
38
+
39
+ ### Step 2 — Pick the reporting mechanism
40
+
41
+ ```
42
+ IF failure is an EXPECTED, branchable outcome the caller will route on
43
+ → Result type / tagged union / typed error return.
44
+ Forces the caller to handle it; the type system is the proof.
45
+
46
+ IF failure is UNEXPECTED and most callers cannot do anything useful
47
+ → exception, propagated to a single boundary handler.
48
+ One layer (HTTP, queue, CLI) translates exceptions to user-facing errors.
49
+
50
+ IF failure is UNRECOVERABLE (invariant violated, data corruption)
51
+ → fail loud, fail fast. No catch-and-continue.
52
+ Log structured context, exit / panic / 500.
53
+
54
+ IF the language idiom forces one choice (Go: errors are values; Rust: Result;
55
+ Python/PHP/JS: exceptions)
56
+ → follow the idiom. Inventing a foreign mechanism is more cost than the
57
+ correctness it buys.
58
+ ```
59
+
60
+ ### Step 3 — Pick the resilience strategy
61
+
62
+ ```
63
+ External call?
64
+ Idempotent + transient failure mode → retry with exponential backoff + jitter, cap.
65
+ Non-idempotent → no blind retry; require an idempotency key.
66
+ Repeated failure across instances → circuit breaker; open → half-open probe → close.
67
+ Optional functionality → graceful degradation (cached / default / null result).
68
+ Required functionality → propagate; surface to user with a recovery hint.
69
+ ```
70
+
71
+ ### Step 4 — Shape the error payload
72
+
73
+ Every produced error must carry: `code` (stable string), `message` (human-readable), `cause` (chained), `context` (sanitized inputs), `correlation_id` (request / trace).
74
+
75
+ Forbidden: secrets, raw SQL, full stack traces in user-facing surfaces, internal class names leaked through API boundaries.
76
+
77
+ ### Step 5 — Define the boundary
78
+
79
+ Exactly **one** layer translates internal errors to the egress format (HTTP status + body, queue requeue policy, CLI exit code). Anywhere else doing this duplication is the bug.
80
+
81
+ ## Procedure: Apply the framework to a new feature
82
+
83
+ 1. List failure modes (each external call, each invariant, each user input class).
84
+ 2. Run Step 1 against each, write the classification next to it.
85
+ 3. Pick reporting mechanism per Step 2; reject combinations the language idiom rejects.
86
+ 4. For each external call, run Step 3 and write down the chosen resilience strategy.
87
+ 5. Sketch the error payload shape (Step 4) and the single boundary (Step 5).
88
+ 6. Hand the sketch to a reviewer **before** coding; cite this skill.
89
+
90
+ ## Output format
91
+
92
+ 1. The failure-mode table (mode · classification · mechanism · resilience strategy).
93
+ 2. The shared error payload definition (code, message, cause, context, correlation_id).
94
+ 3. The single boundary handler (file:line) where internal → egress translation happens.
95
+ 4. The retry / circuit-breaker config (attempts, base, jitter, breaker thresholds), if any.
96
+
97
+ ## Gotcha
98
+
99
+ - "Catch everything, log it, return null" silently destroys signal — every catch must either rethrow, translate, or recover with a written reason.
100
+ - Retries on non-idempotent calls are the second-most-common production incident; insist on idempotency keys before allowing retry.
101
+ - Circuit breakers without a half-open probe never close — they degrade to permanent failure.
102
+ - Mixing Result types and exceptions in the same module is worse than picking the wrong one — pick one per module and stay in it.
103
+ - Upstream pattern catalogues drift; trust the link, not memory. Refresh per `refresh_trigger` above.
104
+
105
+ ## Do NOT
106
+
107
+ - Do NOT introduce a custom error mechanism that fights the language idiom.
108
+ - Do NOT swallow exceptions — every catch has a written purpose.
109
+ - Do NOT leak stack traces, secrets, or internal class names across the boundary.
110
+ - Do NOT retry without backoff + jitter + cap.
111
+ - Do NOT inline language-specific code catalogues into this skill — externalize per Sunset Policy.
112
+
113
+ ## Auto-trigger keywords
114
+
115
+ - error handling strategy
116
+ - exceptions vs result
117
+ - retry pattern
118
+ - circuit breaker
119
+ - graceful degradation
120
+ - error payload shape
121
+
122
+ ## Provenance
123
+
124
+ - Adopted from: `Microck/ordinary-claude-skills@8f5c83174f7aa683b4ddc7433150471983b93131:skills_all/error-handling-patterns/SKILL.md` (MIT, © 2025 Microck) — **Sunset Policy applied**: 636-line source reduced to a ~150-line decision framework; language catalogues externalized to the upstream resources below.
125
+ - Externalized catalogues:
126
+ - Python: https://docs.python.org/3/tutorial/errors.html · https://docs.python.org/3/library/exceptions.html
127
+ - PHP / Laravel: https://laravel.com/docs/errors · https://www.php.net/manual/en/language.exceptions.php
128
+ - JS / TS: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Control_flow_and_error_handling · https://www.typescriptlang.org/docs/handbook/2/narrowing.html
129
+ - Go: https://go.dev/blog/error-handling-and-go · https://pkg.go.dev/errors
130
+ - Rust: https://doc.rust-lang.org/book/ch09-00-error-handling.html
131
+ - Resilience patterns: https://martinfowler.com/bliki/CircuitBreaker.html · https://aws.amazon.com/builders-library/timeouts-retries-and-backoff-with-jitter/
132
+ - Cross-linked: [`defense-in-depth`](../defense-in-depth/SKILL.md), [`laravel-validation`](../laravel-validation/SKILL.md), [`bug-analyzer`](../bug-analyzer/SKILL.md), [`api-design`](../api-design/SKILL.md).
133
+ - Provenance registry: `agents/contexts/skills-provenance.yml` (entry: `error-handling-patterns`).
134
+ - Iron-Law floor: `verify-before-complete`, `skill-quality`, `non-destructive-by-default`.
@@ -0,0 +1,108 @@
1
+ ---
2
+ name: mcp-builder
3
+ description: "Use when building an MCP server in Python (FastMCP) or Node/TypeScript (MCP SDK) — agent-centric tool design, input schemas, error handling, and the 10-question evaluation harness."
4
+ source: package
5
+ ---
6
+
7
+ # mcp-builder
8
+
9
+ Author MCP servers that LLMs can drive end-to-end. The quality bar is *can the agent finish the workflow*, not *does the endpoint return 200*. This skill is the **server-author** counterpart to the existing [`mcp`](../mcp/SKILL.md) consumer skill.
10
+
11
+ ## When to use
12
+
13
+ - Wrapping an external API or service as MCP tools for an LLM client.
14
+ - Adding tools to an existing MCP server (Python FastMCP or TypeScript SDK).
15
+ - Reviewing an MCP server before shipping — Phase 4 evaluation gate below.
16
+
17
+ Do NOT use when:
18
+
19
+ - You only need to *call* an MCP server — route to [`mcp`](../mcp/SKILL.md).
20
+ - The integration belongs in the host process — write a regular service, not an MCP server.
21
+ - The "server" wraps one endpoint with no workflow — a CLI wrapper is enough.
22
+
23
+ ## Procedure: Four phases, one tool at a time
24
+
25
+ ### Phase 1 — Research & plan
26
+
27
+ 1. **Agent-centric design**. Tools encode *workflows*, not raw endpoints. Consolidate (`schedule_event` checks availability **and** creates the event). Default to human-readable names over IDs. Errors are educational, not just diagnostic ("retry with `filter='active_only'` to reduce results").
28
+ 2. **Load the protocol**. Fetch `https://modelcontextprotocol.io/llms-full.txt` once into context — the canonical spec.
29
+ 3. **Load the SDK README** for the chosen language:
30
+ - Python: `https://raw.githubusercontent.com/modelcontextprotocol/python-sdk/main/README.md`
31
+ - TypeScript: `https://raw.githubusercontent.com/modelcontextprotocol/typescript-sdk/main/README.md`
32
+ 4. **Read the target service's API docs in full** — auth, rate limits, pagination, error codes, schemas. Skipping this produces incomplete mocks (see [`testing-anti-patterns`](../testing-anti-patterns/SKILL.md) § Anti-Pattern 4).
33
+ 5. **Write the plan**: tool list with priority, shared utilities (request helper, pagination, formatter), input/output schemas, error strategy, response-detail levels (concise vs detailed), character limits (default 25 000 tokens).
34
+
35
+ ### Phase 2 — Implement
36
+
37
+ 1. **Project layout**. Python: single `.py` or modular package; Pydantic v2 with `model_config`. TypeScript: standard `package.json` + `tsconfig.json` strict mode; Zod schemas with `.strict()`.
38
+ 2. **Shared utilities first**. API request helper with retry/timeout, error formatter, JSON-vs-Markdown response builder, pagination cursor handling, auth/token cache.
39
+ 3. **Per tool**:
40
+ - Input schema (Pydantic / Zod) with constraints, descriptions, and *examples*.
41
+ - One-line summary + detailed docstring covering purpose, parameters, return shape, when-to-use, when-NOT-to-use, error handling.
42
+ - Tool annotations: `readOnlyHint`, `destructiveHint`, `idempotentHint`, `openWorldHint`.
43
+ - Async/await for all I/O. Honor pagination. Truncate to the character limit and signal truncation in the response.
44
+
45
+ ### Phase 3 — Review & test
46
+
47
+ 1. **Code-quality pass**: DRY across tools, shared helpers extracted, consistent response shapes, all external calls have error handling, full type coverage.
48
+ 2. **Build & syntax**:
49
+ - Python: `python -m py_compile server.py`.
50
+ - TypeScript: `npm run build`; verify `dist/index.js`.
51
+ 3. **Run the server safely**. MCP servers block on stdio. Either run inside `tmux` and drive from the harness, or wrap with `timeout 5s python server.py` for a smoke check. Do NOT block your own session by running it in-process.
52
+
53
+ ### Phase 4 — Evaluations (10-question harness)
54
+
55
+ Each evaluation is a question the agent must answer using only the new tools.
56
+
57
+ Requirements per question — **independent**, **read-only**, **complex** (multiple tool calls), **realistic**, **verifiable** (string-comparable answer), **stable** (answer does not drift over time).
58
+
59
+ ```xml
60
+ <evaluation>
61
+ <qa_pair>
62
+ <question>...</question>
63
+ <answer>...</answer>
64
+ </qa_pair>
65
+ <!-- 9 more -->
66
+ </evaluation>
67
+ ```
68
+
69
+ Process: enumerate the tools, explore READ-ONLY data, draft 10 questions, **solve each yourself first** to confirm the answer is reachable and stable.
70
+
71
+ ## Output format
72
+
73
+ 1. The server source plus the 10-question evaluation XML.
74
+ 2. A README with: install, env vars, transport mode (stdio / sse / http), example tool call.
75
+ 3. A line in `agents/contexts/skills-provenance.yml` if the server was forked from an upstream, or a note that it was authored from scratch.
76
+
77
+ ## Gotcha
78
+
79
+ - "Wrap every endpoint" is the failure mode — agents cannot orchestrate 60 thin tools as well as 12 workflow tools.
80
+ - Returning the full upstream payload blows the agent's context. Default to a *concise* shape with an opt-in *detailed* mode.
81
+ - Pydantic / Zod descriptions are the *only* documentation the LLM sees at runtime — write them like usage docs, not comments.
82
+ - A server that hangs your session usually means stdio transport ran in the main process — move it under `tmux` or use a `timeout`.
83
+ - Inflated token claims are not credible without an evaluation harness — Phase 4 is the validation gate, not optional.
84
+
85
+ ## Do NOT
86
+
87
+ - Do NOT mirror REST routes 1:1.
88
+ - Do NOT use `any` (TypeScript) or untyped `dict` (Python) in tool I/O.
89
+ - Do NOT skip the 10-question evaluation — Phase 4 IS the quality bar.
90
+ - Do NOT run the MCP server in your main process during testing — it will block.
91
+ - Do NOT log tokens, API keys, or full request bodies — sanitize before logging.
92
+
93
+ ## Auto-trigger keywords
94
+
95
+ - mcp server
96
+ - model context protocol
97
+ - fastmcp
98
+ - mcp builder
99
+ - agent-centric tools
100
+
101
+ ## Provenance
102
+
103
+ - Upstream protocol: https://modelcontextprotocol.io
104
+ - Upstream SDKs: https://github.com/modelcontextprotocol/python-sdk · https://github.com/modelcontextprotocol/typescript-sdk
105
+ - Adopted from: `Microck/ordinary-claude-skills@8f5c83174f7aa683b4ddc7433150471983b93131:skills_all/mcp-builder/SKILL.md` (MIT, © 2025 Microck) — external `./reference/*.md` file links replaced with inline guidance + upstream URLs.
106
+ - Cross-linked: [`mcp`](../mcp/SKILL.md), [`testing-anti-patterns`](../testing-anti-patterns/SKILL.md), [`api-design`](../api-design/SKILL.md).
107
+ - Provenance registry: `agents/contexts/skills-provenance.yml` (entry: `mcp-builder`).
108
+ - Iron-Law floor: `verify-before-complete`, `tool-safety`, `skill-quality`.