@kinqs/brainrouter-mcp-server 0.3.4
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/.env.example +144 -0
- package/README.md +56 -0
- package/agents/README.md +120 -0
- package/agents/code-reviewer.md +97 -0
- package/agents/security-auditor.md +101 -0
- package/agents/test-engineer.md +95 -0
- package/dist/__tests__/agent_mode.test.d.ts +1 -0
- package/dist/__tests__/api-routes.test.d.ts +1 -0
- package/dist/__tests__/api-routes.test.js +170 -0
- package/dist/__tests__/crypto.test.d.ts +1 -0
- package/dist/__tests__/crypto.test.js +28 -0
- package/dist/__tests__/host-integrations.test.d.ts +1 -0
- package/dist/__tests__/host-integrations.test.js +82 -0
- package/dist/__tests__/integration.test.d.ts +1 -0
- package/dist/__tests__/integration.test.js +50 -0
- package/dist/__tests__/loader.test.d.ts +1 -0
- package/dist/__tests__/loader.test.js +89 -0
- package/dist/__tests__/neural-spark.test.d.ts +1 -0
- package/dist/__tests__/neural-spark.test.js +112 -0
- package/dist/__tests__/pagination.test.d.ts +1 -0
- package/dist/__tests__/pagination.test.js +23 -0
- package/dist/__tests__/redaction.test.d.ts +1 -0
- package/dist/__tests__/redaction.test.js +17 -0
- package/dist/__tests__/registry.test.d.ts +1 -0
- package/dist/__tests__/registry.test.js +56 -0
- package/dist/__tests__/retry.test.d.ts +1 -0
- package/dist/__tests__/retry.test.js +30 -0
- package/dist/__tests__/skill-activation.test.d.ts +1 -0
- package/dist/__tests__/skill-activation.test.js +112 -0
- package/dist/__tests__/working-memory.test.d.ts +1 -0
- package/dist/__tests__/working-memory.test.js +200 -0
- package/dist/__tests__/workspace-paths.test.d.ts +1 -0
- package/dist/__tests__/workspace-paths.test.js +56 -0
- package/dist/__tests__/writer.test.d.ts +1 -0
- package/dist/__tests__/writer.test.js +94 -0
- package/dist/api/auth/crypto.d.ts +4 -0
- package/dist/api/auth/crypto.js +54 -0
- package/dist/api/middleware/auth.d.ts +12 -0
- package/dist/api/middleware/auth.js +90 -0
- package/dist/api/pagination.d.ts +18 -0
- package/dist/api/pagination.js +32 -0
- package/dist/api/routes/auth.d.ts +1 -0
- package/dist/api/routes/auth.js +130 -0
- package/dist/api/routes/chat-completions.d.ts +7 -0
- package/dist/api/routes/chat-completions.js +474 -0
- package/dist/api/routes/contradictions.d.ts +1 -0
- package/dist/api/routes/contradictions.js +28 -0
- package/dist/api/routes/evidence.d.ts +1 -0
- package/dist/api/routes/evidence.js +59 -0
- package/dist/api/routes/governance.d.ts +1 -0
- package/dist/api/routes/governance.js +95 -0
- package/dist/api/routes/graph.d.ts +1 -0
- package/dist/api/routes/graph.js +25 -0
- package/dist/api/routes/hooks.d.ts +1 -0
- package/dist/api/routes/hooks.js +88 -0
- package/dist/api/routes/memories.d.ts +1 -0
- package/dist/api/routes/memories.js +92 -0
- package/dist/api/routes/persona.d.ts +1 -0
- package/dist/api/routes/persona.js +9 -0
- package/dist/api/routes/scenes.d.ts +1 -0
- package/dist/api/routes/scenes.js +35 -0
- package/dist/api/routes/skills.d.ts +1 -0
- package/dist/api/routes/skills.js +14 -0
- package/dist/api/routes/stats.d.ts +1 -0
- package/dist/api/routes/stats.js +8 -0
- package/dist/api/routes/users.d.ts +1 -0
- package/dist/api/routes/users.js +82 -0
- package/dist/api/routes/working.d.ts +1 -0
- package/dist/api/routes/working.js +88 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +492 -0
- package/dist/integrations/claude-code.d.ts +12 -0
- package/dist/integrations/claude-code.js +35 -0
- package/dist/integrations/codex.d.ts +12 -0
- package/dist/integrations/codex.js +34 -0
- package/dist/integrations/generic-mcp.d.ts +52 -0
- package/dist/integrations/generic-mcp.js +118 -0
- package/dist/loader.d.ts +29 -0
- package/dist/loader.js +200 -0
- package/dist/memory/capture.d.ts +35 -0
- package/dist/memory/capture.js +230 -0
- package/dist/memory/config.d.ts +2 -0
- package/dist/memory/config.js +3 -0
- package/dist/memory/engine.d.ts +203 -0
- package/dist/memory/engine.js +626 -0
- package/dist/memory/llm-semaphore.d.ts +41 -0
- package/dist/memory/llm-semaphore.js +81 -0
- package/dist/memory/memory-type-config.d.ts +11 -0
- package/dist/memory/memory-type-config.js +65 -0
- package/dist/memory/pipeline/cognitive-contradiction.d.ts +7 -0
- package/dist/memory/pipeline/cognitive-contradiction.js +59 -0
- package/dist/memory/pipeline/cognitive-dedup.d.ts +23 -0
- package/dist/memory/pipeline/cognitive-dedup.js +38 -0
- package/dist/memory/pipeline/cognitive-extractor.d.ts +21 -0
- package/dist/memory/pipeline/cognitive-extractor.js +183 -0
- package/dist/memory/pipeline/contextual-focus-builder.d.ts +13 -0
- package/dist/memory/pipeline/contextual-focus-builder.js +135 -0
- package/dist/memory/pipeline/focus-direction-shift.d.ts +10 -0
- package/dist/memory/pipeline/focus-direction-shift.js +27 -0
- package/dist/memory/pipeline/graph-builder.d.ts +11 -0
- package/dist/memory/pipeline/graph-builder.js +88 -0
- package/dist/memory/pipeline/graph-recall.d.ts +13 -0
- package/dist/memory/pipeline/graph-recall.js +55 -0
- package/dist/memory/pipeline/identity-distiller.d.ts +15 -0
- package/dist/memory/pipeline/identity-distiller.js +40 -0
- package/dist/memory/pipeline/l1-contradiction.d.ts +7 -0
- package/dist/memory/pipeline/l1-contradiction.js +66 -0
- package/dist/memory/pipeline/l1-dedup.d.ts +23 -0
- package/dist/memory/pipeline/l1-dedup.js +39 -0
- package/dist/memory/pipeline/l1-extractor.d.ts +21 -0
- package/dist/memory/pipeline/l1-extractor.js +180 -0
- package/dist/memory/pipeline/l2-direction-shift.d.ts +10 -0
- package/dist/memory/pipeline/l2-direction-shift.js +27 -0
- package/dist/memory/pipeline/l2-scene.d.ts +15 -0
- package/dist/memory/pipeline/l2-scene.js +140 -0
- package/dist/memory/pipeline/l3-distiller.d.ts +15 -0
- package/dist/memory/pipeline/l3-distiller.js +40 -0
- package/dist/memory/pipeline/neural-spark.d.ts +27 -0
- package/dist/memory/pipeline/neural-spark.js +78 -0
- package/dist/memory/pipeline/skill-prewarm.d.ts +63 -0
- package/dist/memory/pipeline/skill-prewarm.js +127 -0
- package/dist/memory/pipeline/task-queue.d.ts +54 -0
- package/dist/memory/pipeline/task-queue.js +117 -0
- package/dist/memory/prompts/cognitive-contradiction.d.ts +1 -0
- package/dist/memory/prompts/cognitive-contradiction.js +25 -0
- package/dist/memory/prompts/cognitive-extraction.d.ts +10 -0
- package/dist/memory/prompts/cognitive-extraction.js +114 -0
- package/dist/memory/prompts/core-identity.d.ts +6 -0
- package/dist/memory/prompts/core-identity.js +60 -0
- package/dist/memory/prompts/focus-direction-shift.d.ts +5 -0
- package/dist/memory/prompts/focus-direction-shift.js +32 -0
- package/dist/memory/prompts/focus-scene-cluster.d.ts +2 -0
- package/dist/memory/prompts/focus-scene-cluster.js +33 -0
- package/dist/memory/prompts/focus-scene.d.ts +7 -0
- package/dist/memory/prompts/focus-scene.js +40 -0
- package/dist/memory/prompts/graph-extraction-batch.d.ts +14 -0
- package/dist/memory/prompts/graph-extraction-batch.js +54 -0
- package/dist/memory/prompts/graph-extraction.d.ts +2 -0
- package/dist/memory/prompts/graph-extraction.js +53 -0
- package/dist/memory/prompts/l1-contradiction-batch.d.ts +16 -0
- package/dist/memory/prompts/l1-contradiction-batch.js +47 -0
- package/dist/memory/prompts/l1-contradiction.d.ts +1 -0
- package/dist/memory/prompts/l1-contradiction.js +25 -0
- package/dist/memory/prompts/l1-extraction.d.ts +10 -0
- package/dist/memory/prompts/l1-extraction.js +114 -0
- package/dist/memory/prompts/l2-direction-shift.d.ts +5 -0
- package/dist/memory/prompts/l2-direction-shift.js +32 -0
- package/dist/memory/prompts/l2-scene-cluster.d.ts +2 -0
- package/dist/memory/prompts/l2-scene-cluster.js +33 -0
- package/dist/memory/prompts/l2-scene.d.ts +7 -0
- package/dist/memory/prompts/l2-scene.js +40 -0
- package/dist/memory/prompts/l3-persona.d.ts +6 -0
- package/dist/memory/prompts/l3-persona.js +60 -0
- package/dist/memory/recall.d.ts +47 -0
- package/dist/memory/recall.js +427 -0
- package/dist/memory/redaction.d.ts +1 -0
- package/dist/memory/redaction.js +24 -0
- package/dist/memory/retry.d.ts +13 -0
- package/dist/memory/retry.js +53 -0
- package/dist/memory/scheduler.d.ts +9 -0
- package/dist/memory/scheduler.js +16 -0
- package/dist/memory/skill-hints-loader.d.ts +30 -0
- package/dist/memory/skill-hints-loader.js +100 -0
- package/dist/memory/store/embedding.d.ts +16 -0
- package/dist/memory/store/embedding.js +68 -0
- package/dist/memory/store/reranker.d.ts +24 -0
- package/dist/memory/store/reranker.js +83 -0
- package/dist/memory/store/sqlite.d.ts +167 -0
- package/dist/memory/store/sqlite.js +1816 -0
- package/dist/memory/store/types.d.ts +101 -0
- package/dist/memory/store/types.js +1 -0
- package/dist/memory/types.d.ts +207 -0
- package/dist/memory/types.js +7 -0
- package/dist/memory/validation.d.ts +441 -0
- package/dist/memory/validation.js +129 -0
- package/dist/memory/working/canvas.d.ts +5 -0
- package/dist/memory/working/canvas.js +43 -0
- package/dist/memory/working/offload.d.ts +71 -0
- package/dist/memory/working/offload.js +211 -0
- package/dist/memory/working/step-log.d.ts +16 -0
- package/dist/memory/working/step-log.js +35 -0
- package/dist/registry.d.ts +34 -0
- package/dist/registry.js +305 -0
- package/dist/resolver.d.ts +17 -0
- package/dist/resolver.js +126 -0
- package/dist/scripts/validate-foreign-workspace-path.d.ts +1 -0
- package/dist/scripts/validate-foreign-workspace-path.js +39 -0
- package/dist/tools/agent_memory_tools.d.ts +485 -0
- package/dist/tools/agent_memory_tools.js +793 -0
- package/dist/tools/create_skill.d.ts +46 -0
- package/dist/tools/create_skill.js +46 -0
- package/dist/tools/get_doc.d.ts +21 -0
- package/dist/tools/get_doc.js +24 -0
- package/dist/tools/get_persona.d.ts +15 -0
- package/dist/tools/get_persona.js +20 -0
- package/dist/tools/get_reference.d.ts +15 -0
- package/dist/tools/get_reference.js +20 -0
- package/dist/tools/get_skill.d.ts +34 -0
- package/dist/tools/get_skill.js +65 -0
- package/dist/tools/get_template_doc.d.ts +21 -0
- package/dist/tools/get_template_doc.js +24 -0
- package/dist/tools/list_docs.d.ts +15 -0
- package/dist/tools/list_docs.js +16 -0
- package/dist/tools/list_skills.d.ts +18 -0
- package/dist/tools/list_skills.js +17 -0
- package/dist/tools/list_template_docs.d.ts +15 -0
- package/dist/tools/list_template_docs.js +16 -0
- package/dist/tools/memory-engineering.d.ts +225 -0
- package/dist/tools/memory-engineering.js +284 -0
- package/dist/tools/memory-explain.d.ts +34 -0
- package/dist/tools/memory-explain.js +109 -0
- package/dist/tools/memory-governance.d.ts +171 -0
- package/dist/tools/memory-governance.js +224 -0
- package/dist/tools/memory-hooks.d.ts +67 -0
- package/dist/tools/memory-hooks.js +102 -0
- package/dist/tools/memory-working.d.ts +98 -0
- package/dist/tools/memory-working.js +101 -0
- package/dist/tools/memory_capture_turn.d.ts +66 -0
- package/dist/tools/memory_capture_turn.js +85 -0
- package/dist/tools/memory_consolidate.d.ts +55 -0
- package/dist/tools/memory_consolidate.js +176 -0
- package/dist/tools/memory_contradictions.d.ts +53 -0
- package/dist/tools/memory_contradictions.js +52 -0
- package/dist/tools/memory_graph_query.d.ts +51 -0
- package/dist/tools/memory_graph_query.js +35 -0
- package/dist/tools/memory_mark_cited.d.ts +43 -0
- package/dist/tools/memory_mark_cited.js +63 -0
- package/dist/tools/memory_recall.d.ts +77 -0
- package/dist/tools/memory_recall.js +81 -0
- package/dist/tools/memory_register_skill_hints.d.ts +49 -0
- package/dist/tools/memory_register_skill_hints.js +55 -0
- package/dist/tools/memory_resolve_session.d.ts +24 -0
- package/dist/tools/memory_resolve_session.js +133 -0
- package/dist/tools/memory_search.d.ts +146 -0
- package/dist/tools/memory_search.js +84 -0
- package/dist/tools/search_skills.d.ts +18 -0
- package/dist/tools/search_skills.js +17 -0
- package/dist/tools/update_doc.d.ts +24 -0
- package/dist/tools/update_doc.js +35 -0
- package/dist/tools/update_skill.d.ts +30 -0
- package/dist/tools/update_skill.js +80 -0
- package/dist/types.d.ts +81 -0
- package/dist/types.js +4 -0
- package/dist/writer.d.ts +30 -0
- package/dist/writer.js +220 -0
- package/docs/TEMPLATE ONLY +1 -0
- package/docs/api/API.md +64 -0
- package/docs/api/security/SECURITY.md +58 -0
- package/docs/deployment/DockerDeployment.md +30 -0
- package/docs/design/Design.md +59 -0
- package/docs/design/themes/apple.md +101 -0
- package/docs/design/themes/dieter-grid.md +100 -0
- package/docs/design/themes/gallery-white.md +100 -0
- package/docs/design/themes/pinterest.md +101 -0
- package/docs/design/themes/realty-open-house.md +101 -0
- package/docs/design/themes/vodafone.md +101 -0
- package/docs/hooks/Hooks.md +30 -0
- package/docs/schema/Schema.md +35 -0
- package/docs/strategy/ScalingStrategy.md +19 -0
- package/package.json +88 -0
- package/references/accessibility-checklist.md +160 -0
- package/references/orchestration-patterns.md +370 -0
- package/references/performance-checklist.md +153 -0
- package/references/security-checklist.md +134 -0
- package/references/testing-patterns.md +236 -0
- package/skills/agent/adr-skill/SKILL.md +299 -0
- package/skills/agent/agentic-engineering-workflow/SKILL.md +95 -0
- package/skills/agent/bootstrap-skill/SKILL.md +103 -0
- package/skills/agent/context-engineering/SKILL.md +307 -0
- package/skills/agent/debugging-and-error-recovery/SKILL.md +308 -0
- package/skills/agent/developer-growth-analysis/SKILL.md +328 -0
- package/skills/agent/doubt-driven-skill/SKILL.md +249 -0
- package/skills/agent/handover-skill/SKILL.md +112 -0
- package/skills/agent/idea-refine-skill/SKILL.md +185 -0
- package/skills/agent/idea-refine-skill/examples.md +238 -0
- package/skills/agent/idea-refine-skill/frameworks.md +99 -0
- package/skills/agent/idea-refine-skill/refinement-criteria.md +113 -0
- package/skills/agent/interview-skill/SKILL.md +226 -0
- package/skills/agent/planning-skill/SKILL.md +270 -0
- package/skills/agent/skill-authoring/SKILL.md +189 -0
- package/skills/agent/source-driven-skill/SKILL.md +197 -0
- package/skills/agent/spec-driven-skill/SKILL.md +221 -0
- package/skills/agent/sync-skill/SKILL.md +92 -0
- package/skills/agent/using-agent-skills/SKILL.md +189 -0
- package/skills/api/a11y-skill/SKILL.md +88 -0
- package/skills/api/api-skill/SKILL.md +123 -0
- package/skills/api/auth-skill/SKILL.md +80 -0
- package/skills/api/debug-skill/SKILL.md +535 -0
- package/skills/api/performance-skill/SKILL.md +100 -0
- package/skills/api/testing-skill/SKILL.md +100 -0
- package/skills/codebase/code-review-and-quality/SKILL.md +228 -0
- package/skills/codebase/code-simplification/SKILL.md +352 -0
- package/skills/codebase/code-structure-cleanup/SKILL.md +142 -0
- package/skills/codebase/concerns-skill/SKILL.md +89 -0
- package/skills/codebase/conventions-skill/SKILL.md +95 -0
- package/skills/codebase/doc-management-skill/SKILL.md +47 -0
- package/skills/codebase/git-workflow-skill/SKILL.md +312 -0
- package/skills/communication/1-3-1-rule/SKILL.md +120 -0
- package/skills/design/brutalist-skill/SKILL.md +131 -0
- package/skills/design/concept-diagrams/SKILL.md +387 -0
- package/skills/design/concept-diagrams/examples/apartment-floor-plan-conversion.md +244 -0
- package/skills/design/concept-diagrams/examples/automated-password-reset-flow.md +276 -0
- package/skills/design/concept-diagrams/examples/autonomous-llm-research-agent-flow.md +240 -0
- package/skills/design/concept-diagrams/examples/banana-journey-tree-to-smoothie.md +161 -0
- package/skills/design/concept-diagrams/examples/commercial-aircraft-structure.md +209 -0
- package/skills/design/concept-diagrams/examples/cpu-ooo-microarchitecture.md +236 -0
- package/skills/design/concept-diagrams/examples/electricity-grid-flow.md +182 -0
- package/skills/design/concept-diagrams/examples/feature-film-production-pipeline.md +172 -0
- package/skills/design/concept-diagrams/examples/hospital-emergency-department-flow.md +165 -0
- package/skills/design/concept-diagrams/examples/ml-benchmark-grouped-bar-chart.md +114 -0
- package/skills/design/concept-diagrams/examples/place-order-uml-sequence.md +325 -0
- package/skills/design/concept-diagrams/examples/smart-city-infrastructure.md +173 -0
- package/skills/design/concept-diagrams/examples/smartphone-layer-anatomy.md +154 -0
- package/skills/design/concept-diagrams/examples/sn2-reaction-mechanism.md +247 -0
- package/skills/design/concept-diagrams/examples/wind-turbine-structure.md +338 -0
- package/skills/design/concept-diagrams/references/dashboard-patterns.md +43 -0
- package/skills/design/concept-diagrams/references/infrastructure-patterns.md +144 -0
- package/skills/design/concept-diagrams/references/physical-shape-cookbook.md +42 -0
- package/skills/design/concept-diagrams/templates/template.html +174 -0
- package/skills/design/gpt-tasteskill/SKILL.md +114 -0
- package/skills/design/minimalist-skill/SKILL.md +116 -0
- package/skills/design/output-skill/SKILL.md +87 -0
- package/skills/design/redesign-skill/SKILL.md +213 -0
- package/skills/design/soft-skill/SKILL.md +132 -0
- package/skills/design/stitch-skill/EXAMPLE.md +121 -0
- package/skills/design/stitch-skill/SKILL.md +222 -0
- package/skills/design/taste-skill/SKILL.md +269 -0
- package/skills/devops/ci-cd-skill/SKILL.md +402 -0
- package/skills/devops/docker-skill/SKILL.md +297 -0
- package/skills/devops/domain-skill/SKILL.md +234 -0
- package/skills/lifecycle/changelog-generator/SKILL.md +135 -0
- package/skills/lifecycle/incremental-skill/SKILL.md +257 -0
- package/skills/lifecycle/migration-skill/SKILL.md +218 -0
- package/skills/lifecycle/shipping-skill/SKILL.md +321 -0
- package/skills/memory/agent-memory/SKILL.md +122 -0
- package/skills/qa/browser-testing-skill/SKILL.md +314 -0
- package/skills/ux/adversarial-ux-skill/SKILL.md +168 -0
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
# Orchestration Patterns
|
|
2
|
+
|
|
3
|
+
Reference catalog of agent orchestration patterns this repo endorses, plus anti-patterns to avoid. Read this before adding a new slash command that coordinates multiple personas, or before introducing a new persona that "wraps" existing ones.
|
|
4
|
+
|
|
5
|
+
The governing rule: **the user (or a slash command) is the orchestrator. Personas do not invoke other personas.** Skills are mandatory hops inside a persona's workflow.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Endorsed patterns
|
|
10
|
+
|
|
11
|
+
### 1. Direct invocation (no orchestration)
|
|
12
|
+
|
|
13
|
+
Single persona, single perspective, single artifact. The default and the cheapest option.
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
user → code-reviewer → report → user
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
**Use when:** the work is one perspective on one artifact and you can describe it in one sentence.
|
|
20
|
+
|
|
21
|
+
**Examples:**
|
|
22
|
+
- "Review this PR" → `code-reviewer`
|
|
23
|
+
- "Find security issues in `auth.ts`" → `security-auditor`
|
|
24
|
+
- "What tests are missing for the checkout flow?" → `test-engineer`
|
|
25
|
+
|
|
26
|
+
**Cost:** one round trip. The baseline you should always compare orchestrated patterns against.
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
### 2. Single-persona slash command
|
|
31
|
+
|
|
32
|
+
A slash command that wraps one persona with the project's skills. Saves the user from re-explaining the workflow every time.
|
|
33
|
+
|
|
34
|
+
```
|
|
35
|
+
/review → code-reviewer (with code-review-and-quality skill) → report
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
**Use when:** the same single-persona invocation happens repeatedly with the same setup.
|
|
39
|
+
|
|
40
|
+
**Examples in this repo:** `/review`, `/test`, `/code-simplify`.
|
|
41
|
+
|
|
42
|
+
**Cost:** same as direct invocation. The slash command is just a saved prompt.
|
|
43
|
+
|
|
44
|
+
**Anti-signal:** if the slash command's body is mostly "decide which persona to call," delete it and let the user call the persona directly.
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
### 3. Parallel fan-out with merge
|
|
49
|
+
|
|
50
|
+
Multiple personas operate on the same input concurrently, each producing an independent report. A merge step (in the main agent's context) synthesizes them into a single decision.
|
|
51
|
+
|
|
52
|
+
```
|
|
53
|
+
┌─→ code-reviewer ─┐
|
|
54
|
+
/ship → fan out ───┼─→ security-auditor ─┤→ merge → go/no-go + rollback
|
|
55
|
+
└─→ test-engineer ─┘
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
**Use when:**
|
|
59
|
+
- The sub-tasks are genuinely independent (no shared mutable state, no ordering dependency)
|
|
60
|
+
- Each sub-agent benefits from its own context window
|
|
61
|
+
- The merge step is small enough to stay in the main context
|
|
62
|
+
- Wall-clock latency matters
|
|
63
|
+
|
|
64
|
+
**Examples in this repo:** `/ship`.
|
|
65
|
+
|
|
66
|
+
**Cost:** N parallel sub-agent contexts + one merge turn. Higher than direct invocation, but faster wall-clock and produces better reports because each sub-agent stays focused on its single perspective.
|
|
67
|
+
|
|
68
|
+
**Validation checklist before adopting this pattern:**
|
|
69
|
+
- [ ] Can I run all sub-agents at the same time without ordering issues?
|
|
70
|
+
- [ ] Does each persona produce a different *kind* of finding, not just the same finding from a different angle?
|
|
71
|
+
- [ ] Will the merge step fit in the main agent's remaining context?
|
|
72
|
+
- [ ] Is the user's wait time long enough that parallelism is actually noticeable?
|
|
73
|
+
|
|
74
|
+
If any answer is "no," fall back to direct invocation or a single-persona command.
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
### 4. Sequential pipeline as user-driven slash commands
|
|
79
|
+
|
|
80
|
+
The user runs slash commands in a defined order, carrying context (or commit history) between them. There is no orchestrator agent — the user IS the orchestrator.
|
|
81
|
+
|
|
82
|
+
```
|
|
83
|
+
user runs: /spec → /plan → /build → /test → /review → /ship
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
**Use when:** the workflow has dependencies (each step needs the previous step's output) and human judgment between steps adds value.
|
|
87
|
+
|
|
88
|
+
**Examples in this repo:** the entire DEFINE → PLAN → BUILD → VERIFY → REVIEW → SHIP lifecycle.
|
|
89
|
+
|
|
90
|
+
**Cost:** one sub-agent context per step. Free for the orchestration layer because there is no orchestrator agent.
|
|
91
|
+
|
|
92
|
+
**Why not automate it:** an LLM "lifecycle orchestrator" would (a) lose nuance between steps because it has to summarize for hand-off, (b) skip the human checkpoints that catch wrong-direction work early, and (c) double the token cost via paraphrasing turns.
|
|
93
|
+
|
|
94
|
+
---
|
|
95
|
+
|
|
96
|
+
### 5. Research isolation (context preservation)
|
|
97
|
+
|
|
98
|
+
When a task requires reading large amounts of material that shouldn't pollute the main context, spawn a research sub-agent that returns only a digest.
|
|
99
|
+
|
|
100
|
+
```
|
|
101
|
+
main agent → research sub-agent (reads 50 files) → digest → main agent continues
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
**Use when:**
|
|
105
|
+
- The main session needs to stay focused on a downstream task
|
|
106
|
+
- The investigation result is much smaller than the input it consumes
|
|
107
|
+
- The decision quality benefits from the main agent having room to think after
|
|
108
|
+
|
|
109
|
+
**Examples:** "Find every call site of this deprecated API across the monorepo," "Summarize what these 30 ADRs say about caching."
|
|
110
|
+
|
|
111
|
+
**Cost:** one isolated sub-agent context. Worth it any time the alternative is loading hundreds of files into the main context.
|
|
112
|
+
|
|
113
|
+
**On Claude Code, use the built-in `Explore` subagent** rather than defining a custom research persona. `Explore` runs on Haiku, is denied write/edit tools, and is purpose-built for this pattern. Define a custom research subagent only when `Explore` doesn't fit (e.g. you need a domain-specific system prompt the model wouldn't infer).
|
|
114
|
+
|
|
115
|
+
---
|
|
116
|
+
|
|
117
|
+
## Claude Code compatibility
|
|
118
|
+
|
|
119
|
+
This catalog is harness-agnostic, but most readers will run it on Claude Code. Here's how each pattern maps onto Claude Code's primitives — and where the platform enforces our rules for us.
|
|
120
|
+
|
|
121
|
+
### Where personas live
|
|
122
|
+
|
|
123
|
+
Plugin subagents go in `agents/` at the plugin root. This repo is a plugin (`.claude-plugin/plugin.json`), so `agents/code-reviewer.md`, `agents/security-auditor.md`, and `agents/test-engineer.md` are auto-discovered when the plugin is enabled. No path configuration needed.
|
|
124
|
+
|
|
125
|
+
### Subagents vs. Agent Teams
|
|
126
|
+
|
|
127
|
+
Claude Code has two parallelism primitives. Pattern 3 (parallel fan-out with merge) maps to **subagents**. If you need teammates that talk to each other, use **Agent Teams** instead.
|
|
128
|
+
|
|
129
|
+
| | Subagents | Agent Teams |
|
|
130
|
+
|--|-----------|-------------|
|
|
131
|
+
| Coordination | Main agent fans out, sub-agents only report back | Teammates message each other, share a task list |
|
|
132
|
+
| Context | Own context window per subagent | Own context window per teammate |
|
|
133
|
+
| When to use | Independent tasks producing reports | Collaborative work needing discussion |
|
|
134
|
+
| Status | Stable | Experimental — requires `CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1` |
|
|
135
|
+
| Cost | Lower | Higher — each teammate is a separate Claude instance |
|
|
136
|
+
|
|
137
|
+
**The personas in this repo work in both modes.** When spawned as subagents (e.g. by `/ship`), they report findings to the main session. When spawned as teammates (`Spawn a teammate using the security-auditor agent type…`), they can challenge each other's findings directly. The persona definition is the same; only the spawning context changes.
|
|
138
|
+
|
|
139
|
+
One subtlety: the `skills` and `mcpServers` frontmatter fields in a persona are honored when it runs as a subagent but **ignored when it runs as a teammate** — teammates load skills and MCP servers from your project and user settings, the same as a regular session. If a persona depends on a specific skill or MCP server being loaded, configure it at the session level so it's available in both modes.
|
|
140
|
+
|
|
141
|
+
### Platform-enforced rules
|
|
142
|
+
|
|
143
|
+
Two rules in this catalog aren't just convention — Claude Code enforces them:
|
|
144
|
+
|
|
145
|
+
- **"Subagents cannot spawn other subagents"** (verbatim from the docs). Anti-pattern B (persona-calls-persona) and Anti-pattern D (deep persona trees) cannot exist on Claude Code by construction.
|
|
146
|
+
- **"No nested teams"** — teammates cannot spawn their own teams. Same anti-patterns blocked at the team level.
|
|
147
|
+
|
|
148
|
+
This means you can adopt the patterns in this catalog without worrying about contributors accidentally building the anti-patterns. They'll just fail to load.
|
|
149
|
+
|
|
150
|
+
### Built-in subagents to know about
|
|
151
|
+
|
|
152
|
+
Before defining a custom subagent, check whether one of these covers the role:
|
|
153
|
+
|
|
154
|
+
| Built-in | Purpose |
|
|
155
|
+
|----------|---------|
|
|
156
|
+
| `Explore` | Read-only codebase search and analysis. Use this for Pattern 5 (research isolation). |
|
|
157
|
+
| `Plan` | Read-only research during plan mode. |
|
|
158
|
+
| `general-purpose` | Multi-step tasks needing both exploration and modification. |
|
|
159
|
+
|
|
160
|
+
Don't redefine these. Layer your specialist personas (code-reviewer, security-auditor, test-engineer) on top of them.
|
|
161
|
+
|
|
162
|
+
### Frontmatter restrictions for plugin agents
|
|
163
|
+
|
|
164
|
+
Plugin subagents do **not** support the `hooks`, `mcpServers`, or `permissionMode` frontmatter fields — these are silently ignored. If a future persona needs any of those, the user must copy the file into `.claude/agents/` or `~/.claude/agents/` instead.
|
|
165
|
+
|
|
166
|
+
The fields that DO work in plugin agents are: `name`, `description`, `tools`, `disallowedTools`, `model`, `maxTurns`, `skills`, `memory`, `background`, `effort`, `isolation`, `color`, `initialPrompt`. Use `model` per-persona if you want to optimize cost (e.g. Haiku for `test-engineer` coverage scans, Sonnet for `code-reviewer`, Opus for `security-auditor`).
|
|
167
|
+
|
|
168
|
+
### Spawning multiple subagents in parallel
|
|
169
|
+
|
|
170
|
+
In Claude Code, parallel fan-out (Pattern 3) requires issuing **multiple Agent tool calls in a single assistant turn**. Sequential turns serialize execution. `/ship` calls this out explicitly. Any new orchestrator command should do the same.
|
|
171
|
+
|
|
172
|
+
---
|
|
173
|
+
|
|
174
|
+
## Worked example: Agent Teams for competing-hypothesis debugging
|
|
175
|
+
|
|
176
|
+
This example shows when to reach for **Agent Teams** instead of `/ship`'s subagent fan-out. The two patterns look similar from a distance — both spawn the same three personas — but the value comes from a different place.
|
|
177
|
+
|
|
178
|
+
### The scenario
|
|
179
|
+
|
|
180
|
+
> *Checkout occasionally hangs for ~30 seconds before completing. It happens roughly once every 50 sessions. No errors in logs. Started after last week's release.*
|
|
181
|
+
|
|
182
|
+
Plausible root causes (mutually exclusive, all fit the symptoms):
|
|
183
|
+
|
|
184
|
+
1. A race condition in the new payment-confirmation flow
|
|
185
|
+
2. An auth check that occasionally falls through to a slow synchronous network call
|
|
186
|
+
3. A missing index on a query that scales with cart size
|
|
187
|
+
4. A flaky third-party API where the SDK retries silently before timing out
|
|
188
|
+
|
|
189
|
+
A single agent will pick the first plausible theory and stop investigating. A `/ship`-style subagent fan-out would have each persona report independently — but their reports never meet, so nothing rules out the wrong theories.
|
|
190
|
+
|
|
191
|
+
This is exactly the case the Agent Teams docs describe: *"With multiple independent investigators actively trying to disprove each other, the theory that survives is much more likely to be the actual root cause."*
|
|
192
|
+
|
|
193
|
+
### Why this is *not* a `/ship` job
|
|
194
|
+
|
|
195
|
+
| | `/ship` (subagents) | Agent Teams |
|
|
196
|
+
|--|--------------------|-------------|
|
|
197
|
+
| Sub-agents see | The same diff, different lenses | A shared task list, each other's messages |
|
|
198
|
+
| Output | Three independent reports → one merge | Adversarial debate → consensus root cause |
|
|
199
|
+
| Right when | You want a verdict on a known artifact | You want to *find* the artifact among hypotheses |
|
|
200
|
+
|
|
201
|
+
`/ship` is a verdict; Agent Teams is an investigation.
|
|
202
|
+
|
|
203
|
+
### Setup (one-time, per-environment)
|
|
204
|
+
|
|
205
|
+
Agent Teams is experimental. In `~/.claude/settings.json`:
|
|
206
|
+
|
|
207
|
+
```json
|
|
208
|
+
{
|
|
209
|
+
"env": {
|
|
210
|
+
"CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS": "1"
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
Requires Claude Code v2.1.32 or later. The personas in this repo are picked up automatically — no team-config files to author by hand.
|
|
216
|
+
|
|
217
|
+
### The trigger prompt
|
|
218
|
+
|
|
219
|
+
Type into the lead session, in natural language:
|
|
220
|
+
|
|
221
|
+
```
|
|
222
|
+
Users report checkout hangs for ~30 seconds intermittently after last
|
|
223
|
+
week's release. No errors in logs.
|
|
224
|
+
|
|
225
|
+
Create an agent team to debug this with competing hypotheses. Spawn
|
|
226
|
+
three teammates using the existing agent types:
|
|
227
|
+
|
|
228
|
+
- code-reviewer — investigate race conditions and blocking calls
|
|
229
|
+
in the checkout code path
|
|
230
|
+
- security-auditor — investigate auth checks, session handling,
|
|
231
|
+
and any synchronous network calls added recently
|
|
232
|
+
- test-engineer — propose tests that would distinguish between the
|
|
233
|
+
hypotheses and check coverage gaps in checkout
|
|
234
|
+
|
|
235
|
+
Have them message each other directly to challenge each other's
|
|
236
|
+
theories. Update findings as consensus emerges. Only converge when
|
|
237
|
+
two teammates agree they can disprove the others'.
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
The lead spawns three teammates referencing the existing persona names. The persona body is **appended** to each teammate's system prompt as additional instructions (on top of the team-coordination instructions the lead installs); the trigger prompt above becomes their task.
|
|
241
|
+
|
|
242
|
+
### What happens
|
|
243
|
+
|
|
244
|
+
1. Each teammate runs in its own context window, exploring the codebase from its own lens.
|
|
245
|
+
2. Teammates use `message` to send findings to each other directly. The lead doesn't have to relay.
|
|
246
|
+
3. The shared task list shows who's investigating what — visible at any time with `Ctrl+T` (in-process mode) or in a tmux pane (split mode).
|
|
247
|
+
4. When `code-reviewer` finds a `Promise.all` that should be sequential, it messages `security-auditor` to confirm the auth call isn't part of the race. `security-auditor` checks and replies — either confirming the race is the real issue or producing counter-evidence.
|
|
248
|
+
5. `test-engineer` proposes a focused integration test for whichever theory is winning, which the team uses to verify before declaring consensus.
|
|
249
|
+
6. The lead synthesizes the converged finding and presents it to you.
|
|
250
|
+
|
|
251
|
+
You can interrupt at any teammate by cycling with `Shift+Down` and typing — useful for redirecting an investigator who's gone down a wrong path.
|
|
252
|
+
|
|
253
|
+
### When to clean up
|
|
254
|
+
|
|
255
|
+
When the investigation lands on a root cause, tell the lead:
|
|
256
|
+
|
|
257
|
+
```
|
|
258
|
+
Clean up the team
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
Always cleanup through the lead, not a teammate (per the docs: teammates lack full team context for cleanup).
|
|
262
|
+
|
|
263
|
+
### Cost expectation
|
|
264
|
+
|
|
265
|
+
Three Sonnet teammates running for ~10–15 minutes of investigation costs noticeably more than the same three personas spawned as subagents by `/ship`. The justification is *quality of conclusion* — for production debugging where the wrong fix is expensive, the extra tokens are a bargain. For a routine PR review, stick with `/ship`.
|
|
266
|
+
|
|
267
|
+
### Anti-pattern in this scenario
|
|
268
|
+
|
|
269
|
+
Do **not** rebuild this as a `/debug` slash command that fans out subagents. Subagents can't message each other — you'd lose the adversarial debate that makes the pattern work. If a workflow keeps coming up, document the trigger prompt above as a snippet rather than wrapping it in a slash command that misuses subagents.
|
|
270
|
+
|
|
271
|
+
### When *not* to use Agent Teams
|
|
272
|
+
|
|
273
|
+
- Production-bound verdict on a known diff → use `/ship` (subagents).
|
|
274
|
+
- One specialist perspective on one artifact → direct persona invocation.
|
|
275
|
+
- Sequential lifecycle (spec → plan → build) → user-driven slash commands (Pattern 4).
|
|
276
|
+
- Read-heavy research with a small digest → built-in `Explore` subagent.
|
|
277
|
+
|
|
278
|
+
Reach for Agent Teams only when teammates **need** to challenge each other to produce the right answer.
|
|
279
|
+
|
|
280
|
+
---
|
|
281
|
+
|
|
282
|
+
## Anti-patterns
|
|
283
|
+
|
|
284
|
+
### A. Router persona ("meta-orchestrator")
|
|
285
|
+
|
|
286
|
+
A persona whose job is to decide which other persona to call.
|
|
287
|
+
|
|
288
|
+
```
|
|
289
|
+
/work → router-persona → "this needs a review" → code-reviewer → router (paraphrases) → user
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
**Why it fails:**
|
|
293
|
+
- Pure routing layer with no domain value
|
|
294
|
+
- Adds two paraphrasing hops → information loss + roughly 2× token cost
|
|
295
|
+
- The user already knew they wanted a review; they could have called `/review` directly
|
|
296
|
+
- Replicates the work that slash commands and intent mapping in `AGENTS.md` already do
|
|
297
|
+
|
|
298
|
+
**What to do instead:** add or refine slash commands. Document intent → command mapping in `AGENTS.md`.
|
|
299
|
+
|
|
300
|
+
---
|
|
301
|
+
|
|
302
|
+
### B. Persona that calls another persona
|
|
303
|
+
|
|
304
|
+
A `code-reviewer` that internally invokes `security-auditor` when it sees auth code.
|
|
305
|
+
|
|
306
|
+
**Why it fails:**
|
|
307
|
+
- Personas were designed to produce a single perspective; chaining them defeats that
|
|
308
|
+
- The summary the calling persona passes loses context the called persona needs
|
|
309
|
+
- Failure modes multiply (which persona's output format wins? whose rules apply?)
|
|
310
|
+
- Hides cost from the user
|
|
311
|
+
|
|
312
|
+
**What to do instead:** have the calling persona *recommend* a follow-up audit in its report. The user or a slash command runs the second pass.
|
|
313
|
+
|
|
314
|
+
---
|
|
315
|
+
|
|
316
|
+
### C. Sequential orchestrator that paraphrases
|
|
317
|
+
|
|
318
|
+
An agent that calls `/spec`, then `/plan`, then `/build`, etc. on the user's behalf.
|
|
319
|
+
|
|
320
|
+
**Why it fails:**
|
|
321
|
+
- Loses the human checkpoints that catch wrong-direction work
|
|
322
|
+
- Each hand-off summarizes context — accumulated drift over a long pipeline
|
|
323
|
+
- Doubles token cost: orchestrator turn + sub-agent turn for every step
|
|
324
|
+
- Removes user agency at exactly the points where judgment matters most
|
|
325
|
+
|
|
326
|
+
**What to do instead:** keep the user as the orchestrator. Document the recommended sequence in `README.md` and let users invoke it.
|
|
327
|
+
|
|
328
|
+
---
|
|
329
|
+
|
|
330
|
+
### D. Deep persona trees
|
|
331
|
+
|
|
332
|
+
`/ship` calls a `pre-ship-coordinator` that calls a `quality-coordinator` that calls `code-reviewer`.
|
|
333
|
+
|
|
334
|
+
**Why it fails:**
|
|
335
|
+
- Each layer adds latency and tokens with no decision value
|
|
336
|
+
- Debugging becomes a multi-level investigation
|
|
337
|
+
- The leaf personas lose context to multiple summarization steps
|
|
338
|
+
|
|
339
|
+
**What to do instead:** keep the orchestration depth at most 1 (slash command → personas). The merge happens in the main agent.
|
|
340
|
+
|
|
341
|
+
---
|
|
342
|
+
|
|
343
|
+
## Decision flow
|
|
344
|
+
|
|
345
|
+
When considering a new orchestrated workflow, walk this flow:
|
|
346
|
+
|
|
347
|
+
```
|
|
348
|
+
Is the work one perspective on one artifact?
|
|
349
|
+
├── Yes → Direct invocation. Stop.
|
|
350
|
+
└── No → Will the same composition repeat?
|
|
351
|
+
├── No → Direct invocation, ad hoc. Stop.
|
|
352
|
+
└── Yes → Are sub-tasks independent?
|
|
353
|
+
├── No → Sequential slash commands run by user (Pattern 4).
|
|
354
|
+
└── Yes → Parallel fan-out with merge (Pattern 3).
|
|
355
|
+
Validate against the checklist above.
|
|
356
|
+
If any check fails → fall back to single-persona command (Pattern 2).
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
---
|
|
360
|
+
|
|
361
|
+
## When to add a new pattern to this catalog
|
|
362
|
+
|
|
363
|
+
Add a new entry only after:
|
|
364
|
+
|
|
365
|
+
1. You've used the pattern at least twice in real work
|
|
366
|
+
2. You can name a concrete artifact in this repo that demonstrates it
|
|
367
|
+
3. You can explain why an existing pattern wouldn't have worked
|
|
368
|
+
4. You can describe its anti-pattern shadow (what people will mistakenly build instead)
|
|
369
|
+
|
|
370
|
+
Premature catalog entries become aspirational documentation that no one follows.
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
# Performance Checklist
|
|
2
|
+
|
|
3
|
+
Quick reference checklist for web application performance. Use alongside the `performance-optimization` skill.
|
|
4
|
+
|
|
5
|
+
## Table of Contents
|
|
6
|
+
|
|
7
|
+
- [Core Web Vitals Targets](#core-web-vitals-targets)
|
|
8
|
+
- [TTFB Diagnosis](#ttfb-diagnosis)
|
|
9
|
+
- [Frontend Checklist](#frontend-checklist)
|
|
10
|
+
- [Backend Checklist](#backend-checklist)
|
|
11
|
+
- [Measurement Commands](#measurement-commands)
|
|
12
|
+
- [Common Anti-Patterns](#common-anti-patterns)
|
|
13
|
+
|
|
14
|
+
## Core Web Vitals Targets
|
|
15
|
+
|
|
16
|
+
| Metric | Good | Needs Work | Poor |
|
|
17
|
+
|--------|------|------------|------|
|
|
18
|
+
| LCP (Largest Contentful Paint) | ≤ 2.5s | ≤ 4.0s | > 4.0s |
|
|
19
|
+
| INP (Interaction to Next Paint) | ≤ 200ms | ≤ 500ms | > 500ms |
|
|
20
|
+
| CLS (Cumulative Layout Shift) | ≤ 0.1 | ≤ 0.25 | > 0.25 |
|
|
21
|
+
|
|
22
|
+
## TTFB Diagnosis
|
|
23
|
+
|
|
24
|
+
When TTFB is slow (> 800ms), check each component in DevTools Network waterfall:
|
|
25
|
+
|
|
26
|
+
- [ ] **DNS resolution** slow → add `<link rel="dns-prefetch">` or `<link rel="preconnect">` for known origins
|
|
27
|
+
- [ ] **TCP/TLS handshake** slow → enable HTTP/2, consider edge deployment, verify keep-alive
|
|
28
|
+
- [ ] **Server processing** slow → profile backend, check slow queries, add caching
|
|
29
|
+
|
|
30
|
+
## Frontend Checklist
|
|
31
|
+
|
|
32
|
+
### Images
|
|
33
|
+
- [ ] Images use modern formats (WebP, AVIF)
|
|
34
|
+
- [ ] Images are responsively sized (`srcset` and `sizes`)
|
|
35
|
+
- [ ] Images and `<source>` elements have explicit `width` and `height` (prevents CLS in art direction)
|
|
36
|
+
- [ ] Below-the-fold images use `loading="lazy"` and `decoding="async"`
|
|
37
|
+
- [ ] Hero/LCP images use `fetchpriority="high"` and no lazy loading
|
|
38
|
+
|
|
39
|
+
### JavaScript
|
|
40
|
+
- [ ] Bundle size under 200KB gzipped (initial load)
|
|
41
|
+
- [ ] Code splitting with dynamic `import()` for routes and heavy features
|
|
42
|
+
- [ ] Tree shaking enabled (verify dependency ships ESM and marks `sideEffects: false`)
|
|
43
|
+
- [ ] No blocking JavaScript in `<head>` (use `defer` or `async`)
|
|
44
|
+
- [ ] Heavy computation offloaded to Web Workers (if applicable)
|
|
45
|
+
- [ ] `React.memo()` on expensive components that re-render with same props
|
|
46
|
+
- [ ] `useMemo()` / `useCallback()` only where profiling shows benefit
|
|
47
|
+
- [ ] Long tasks (> 50ms) broken up to keep the main thread available — main lever for INP
|
|
48
|
+
- [ ] `yieldToMain` pattern used inside long-running loops so input events can run between chunks
|
|
49
|
+
- [ ] Modern scheduling APIs used where available: `scheduler.yield()` (preferred), `scheduler.postTask()` with priorities, `isInputPending()` to yield only when needed
|
|
50
|
+
- [ ] `requestIdleCallback` for deferrable, non-urgent work (analytics flush, prefetch, warmup)
|
|
51
|
+
- [ ] Non-critical work deferred out of event handlers (e.g. analytics, logging) so the response to the interaction is not delayed
|
|
52
|
+
- [ ] Third-party scripts loaded with `async` / `defer`, audited for size, and fronted by a facade when heavy (chat widgets, embeds)
|
|
53
|
+
|
|
54
|
+
### CSS
|
|
55
|
+
- [ ] Critical CSS inlined or preloaded
|
|
56
|
+
- [ ] No render-blocking CSS for non-critical styles
|
|
57
|
+
- [ ] No CSS-in-JS runtime cost in production (use extraction)
|
|
58
|
+
|
|
59
|
+
### Fonts
|
|
60
|
+
- [ ] Limited to 2–3 font families, 2–3 weights each (every additional weight is another request)
|
|
61
|
+
- [ ] WOFF2 format only (smallest, universal support — skip WOFF/TTF/EOT)
|
|
62
|
+
- [ ] Self-hosted when possible (third-party font CDNs add DNS + TCP + TLS round-trips)
|
|
63
|
+
- [ ] LCP-critical fonts preloaded: `<link rel="preload" as="font" type="font/woff2" crossorigin>`
|
|
64
|
+
- [ ] `font-display: swap` (or `optional` for non-critical) to avoid FOIT blocking render
|
|
65
|
+
- [ ] Subsetted via `unicode-range` to ship only the glyphs each page needs
|
|
66
|
+
- [ ] Variable fonts considered when multiple weights/styles are required (one file replaces many)
|
|
67
|
+
- [ ] Fallback font metrics adjusted with `size-adjust`, `ascent-override`, `descent-override` to reduce CLS on font swap
|
|
68
|
+
- [ ] System font stack considered before any custom font
|
|
69
|
+
|
|
70
|
+
### Network
|
|
71
|
+
- [ ] Static assets cached with long `max-age` + content hashing
|
|
72
|
+
- [ ] API responses cached where appropriate (`Cache-Control`)
|
|
73
|
+
- [ ] HTTP/2 or HTTP/3 enabled
|
|
74
|
+
- [ ] Resources preconnected (`<link rel="preconnect">`) for known origins
|
|
75
|
+
- [ ] `fetchpriority` used on critical non-image resources (e.g., key `<link rel="preload">`, above-the-fold `<script>`) — not only on `<img>`
|
|
76
|
+
- [ ] No unnecessary redirects
|
|
77
|
+
|
|
78
|
+
### Rendering
|
|
79
|
+
- [ ] No layout thrashing (forced synchronous layouts)
|
|
80
|
+
- [ ] Animations use `transform` and `opacity` (GPU-accelerated)
|
|
81
|
+
- [ ] Long lists use virtualization (e.g., `react-window`)
|
|
82
|
+
- [ ] No unnecessary full-page re-renders
|
|
83
|
+
- [ ] Off-screen sections use `content-visibility: auto` with `contain-intrinsic-size` to skip layout/paint of non-visible areas
|
|
84
|
+
- [ ] No `unload` event handlers and no `Cache-Control: no-store` on HTML responses — preserves back/forward cache (bfcache) eligibility
|
|
85
|
+
|
|
86
|
+
## Backend Checklist
|
|
87
|
+
|
|
88
|
+
### Database
|
|
89
|
+
- [ ] No N+1 query patterns (use eager loading / joins)
|
|
90
|
+
- [ ] Queries have appropriate indexes
|
|
91
|
+
- [ ] List endpoints paginated (never `SELECT * FROM table`)
|
|
92
|
+
- [ ] Connection pooling configured
|
|
93
|
+
- [ ] Slow query logging enabled
|
|
94
|
+
|
|
95
|
+
### API
|
|
96
|
+
- [ ] Response times < 200ms (p95)
|
|
97
|
+
- [ ] No synchronous heavy computation in request handlers
|
|
98
|
+
- [ ] Bulk operations instead of loops of individual calls
|
|
99
|
+
- [ ] Response compression (gzip/brotli)
|
|
100
|
+
- [ ] Appropriate caching (in-memory, Redis, CDN)
|
|
101
|
+
|
|
102
|
+
### Infrastructure
|
|
103
|
+
- [ ] CDN for static assets
|
|
104
|
+
- [ ] Server located close to users (or edge deployment)
|
|
105
|
+
- [ ] Horizontal scaling configured (if needed)
|
|
106
|
+
- [ ] Health check endpoint for load balancer
|
|
107
|
+
|
|
108
|
+
## Measurement Commands
|
|
109
|
+
|
|
110
|
+
### INP field data and DevTools workflow
|
|
111
|
+
|
|
112
|
+
1. **Field data first** — check [CrUX Vis](https://developer.chrome.com/docs/crux/vis) or your RUM tool for real-user INP before optimising
|
|
113
|
+
2. **Identify slow interactions** — open DevTools → Performance panel → record while interacting; look for long tasks triggered by clicks/keystrokes
|
|
114
|
+
3. **Test on mid-range Android** — INP issues often only surface on slower hardware; use a real device or DevTools CPU throttling (4×–6× slowdown)
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
# Lighthouse CLI
|
|
118
|
+
npx lighthouse https://localhost:3000 --output json --output-path ./report.json
|
|
119
|
+
|
|
120
|
+
# Bundle analysis
|
|
121
|
+
npx webpack-bundle-analyzer stats.json
|
|
122
|
+
# or for Vite:
|
|
123
|
+
npx vite-bundle-visualizer
|
|
124
|
+
|
|
125
|
+
# Check bundle size
|
|
126
|
+
npx bundlesize
|
|
127
|
+
|
|
128
|
+
# Web Vitals in code
|
|
129
|
+
import { onLCP, onINP, onCLS } from 'web-vitals';
|
|
130
|
+
onLCP(console.log);
|
|
131
|
+
onINP(console.log);
|
|
132
|
+
onCLS(console.log);
|
|
133
|
+
|
|
134
|
+
# INP with interaction-level detail (attribution build)
|
|
135
|
+
import { onINP } from 'web-vitals/attribution';
|
|
136
|
+
onINP(({ value, attribution }) => {
|
|
137
|
+
const { interactionTarget, inputDelay, processingDuration, presentationDelay } = attribution;
|
|
138
|
+
console.log({ value, interactionTarget, inputDelay, processingDuration, presentationDelay });
|
|
139
|
+
});
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
## Common Anti-Patterns
|
|
143
|
+
|
|
144
|
+
| Anti-Pattern | Impact | Fix |
|
|
145
|
+
|---|---|---|
|
|
146
|
+
| N+1 queries | Linear DB load growth | Use joins, includes, or batch loading |
|
|
147
|
+
| Unbounded queries | Memory exhaustion, timeouts | Always paginate, add LIMIT |
|
|
148
|
+
| Missing indexes | Slow reads as data grows | Add indexes for filtered/sorted columns |
|
|
149
|
+
| Layout thrashing | Jank, dropped frames | Batch DOM reads, then batch writes |
|
|
150
|
+
| Unoptimized images | Slow LCP, wasted bandwidth | Use WebP, responsive sizes, lazy load |
|
|
151
|
+
| Large bundles | Slow Time to Interactive | Code split, tree shake, audit deps |
|
|
152
|
+
| Blocking main thread | Poor INP, unresponsive UI | Chunk long tasks with `scheduler.yield()` / `yieldToMain`, offload to Web Workers |
|
|
153
|
+
| Memory leaks | Growing memory, eventual crash | Clean up listeners, intervals, refs |
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
# Security Checklist
|
|
2
|
+
|
|
3
|
+
Quick reference for web application security. Use alongside the `security-and-hardening` skill.
|
|
4
|
+
|
|
5
|
+
## Table of Contents
|
|
6
|
+
|
|
7
|
+
- [Pre-Commit Checks](#pre-commit-checks)
|
|
8
|
+
- [Authentication](#authentication)
|
|
9
|
+
- [Authorization](#authorization)
|
|
10
|
+
- [Input Validation](#input-validation)
|
|
11
|
+
- [Security Headers](#security-headers)
|
|
12
|
+
- [CORS Configuration](#cors-configuration)
|
|
13
|
+
- [Data Protection](#data-protection)
|
|
14
|
+
- [Dependency Security](#dependency-security)
|
|
15
|
+
- [Error Handling](#error-handling)
|
|
16
|
+
- [OWASP Top 10 Quick Reference](#owasp-top-10-quick-reference)
|
|
17
|
+
|
|
18
|
+
## Pre-Commit Checks
|
|
19
|
+
|
|
20
|
+
- [ ] No secrets in code (`git diff --cached | grep -i "password\|secret\|api_key\|token"`)
|
|
21
|
+
- [ ] `.gitignore` covers: `.env`, `.env.local`, `*.pem`, `*.key`
|
|
22
|
+
- [ ] `.env.example` uses placeholder values (not real secrets)
|
|
23
|
+
|
|
24
|
+
## Authentication
|
|
25
|
+
|
|
26
|
+
- [ ] Passwords hashed with bcrypt (≥12 rounds), scrypt, or argon2
|
|
27
|
+
- [ ] Session cookies: `httpOnly`, `secure`, `sameSite: 'lax'`
|
|
28
|
+
- [ ] Session expiration configured (reasonable max-age)
|
|
29
|
+
- [ ] Rate limiting on login endpoint (≤10 attempts per 15 minutes)
|
|
30
|
+
- [ ] Password reset tokens: time-limited (≤1 hour), single-use
|
|
31
|
+
- [ ] Account lockout after repeated failures (optional, with notification)
|
|
32
|
+
- [ ] MFA supported for sensitive operations (optional but recommended)
|
|
33
|
+
|
|
34
|
+
## Authorization
|
|
35
|
+
|
|
36
|
+
- [ ] Every protected endpoint checks authentication
|
|
37
|
+
- [ ] Every resource access checks ownership/role (prevents IDOR)
|
|
38
|
+
- [ ] Admin endpoints require admin role verification
|
|
39
|
+
- [ ] API keys scoped to minimum necessary permissions
|
|
40
|
+
- [ ] JWT tokens validated (signature, expiration, issuer)
|
|
41
|
+
|
|
42
|
+
## Input Validation
|
|
43
|
+
|
|
44
|
+
- [ ] All user input validated at system boundaries (API routes, form handlers)
|
|
45
|
+
- [ ] Validation uses allowlists (not denylists)
|
|
46
|
+
- [ ] String lengths constrained (min/max)
|
|
47
|
+
- [ ] Numeric ranges validated
|
|
48
|
+
- [ ] Email, URL, and date formats validated with proper libraries
|
|
49
|
+
- [ ] File uploads: type restricted, size limited, content verified
|
|
50
|
+
- [ ] SQL queries parameterized (no string concatenation)
|
|
51
|
+
- [ ] HTML output encoded (use framework auto-escaping)
|
|
52
|
+
- [ ] URLs validated before redirect (prevent open redirect)
|
|
53
|
+
|
|
54
|
+
## Security Headers
|
|
55
|
+
|
|
56
|
+
```
|
|
57
|
+
Content-Security-Policy: default-src 'self'; script-src 'self'
|
|
58
|
+
Strict-Transport-Security: max-age=31536000; includeSubDomains
|
|
59
|
+
X-Content-Type-Options: nosniff
|
|
60
|
+
X-Frame-Options: DENY
|
|
61
|
+
X-XSS-Protection: 0 (disabled, rely on CSP)
|
|
62
|
+
Referrer-Policy: strict-origin-when-cross-origin
|
|
63
|
+
Permissions-Policy: camera=(), microphone=(), geolocation=()
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## CORS Configuration
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
// Restrictive (recommended)
|
|
70
|
+
cors({
|
|
71
|
+
origin: ['https://yourdomain.com', 'https://app.yourdomain.com'],
|
|
72
|
+
credentials: true,
|
|
73
|
+
methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE'],
|
|
74
|
+
allowedHeaders: ['Content-Type', 'Authorization'],
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
// NEVER use in production:
|
|
78
|
+
cors({ origin: '*' }) // Allows any origin
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Data Protection
|
|
82
|
+
|
|
83
|
+
- [ ] Sensitive fields excluded from API responses (`passwordHash`, `resetToken`, etc.)
|
|
84
|
+
- [ ] Sensitive data not logged (passwords, tokens, full CC numbers)
|
|
85
|
+
- [ ] PII encrypted at rest (if required by regulation)
|
|
86
|
+
- [ ] HTTPS for all external communication
|
|
87
|
+
- [ ] Database backups encrypted
|
|
88
|
+
|
|
89
|
+
## Dependency Security
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
# Audit dependencies
|
|
93
|
+
npm audit
|
|
94
|
+
|
|
95
|
+
# Fix automatically where possible
|
|
96
|
+
npm audit fix
|
|
97
|
+
|
|
98
|
+
# Check for critical vulnerabilities
|
|
99
|
+
npm audit --audit-level=critical
|
|
100
|
+
|
|
101
|
+
# Keep dependencies updated
|
|
102
|
+
npx npm-check-updates
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## Error Handling
|
|
106
|
+
|
|
107
|
+
```typescript
|
|
108
|
+
// Production: generic error, no internals
|
|
109
|
+
res.status(500).json({
|
|
110
|
+
error: { code: 'INTERNAL_ERROR', message: 'Something went wrong' }
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
// NEVER in production:
|
|
114
|
+
res.status(500).json({
|
|
115
|
+
error: err.message,
|
|
116
|
+
stack: err.stack, // Exposes internals
|
|
117
|
+
query: err.sql, // Exposes database details
|
|
118
|
+
});
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## OWASP Top 10 Quick Reference
|
|
122
|
+
|
|
123
|
+
| # | Vulnerability | Prevention |
|
|
124
|
+
|---|---|---|
|
|
125
|
+
| 1 | Broken Access Control | Auth checks on every endpoint, ownership verification |
|
|
126
|
+
| 2 | Cryptographic Failures | HTTPS, strong hashing, no secrets in code |
|
|
127
|
+
| 3 | Injection | Parameterized queries, input validation |
|
|
128
|
+
| 4 | Insecure Design | Threat modeling, spec-driven development |
|
|
129
|
+
| 5 | Security Misconfiguration | Security headers, minimal permissions, audit deps |
|
|
130
|
+
| 6 | Vulnerable Components | `npm audit`, keep deps updated, minimal deps |
|
|
131
|
+
| 7 | Auth Failures | Strong passwords, rate limiting, session management |
|
|
132
|
+
| 8 | Data Integrity Failures | Verify updates/dependencies, signed artifacts |
|
|
133
|
+
| 9 | Logging Failures | Log security events, don't log secrets |
|
|
134
|
+
| 10 | SSRF | Validate/allowlist URLs, restrict outbound requests |
|