opencode-agent-orchestration-kit 1.0.27

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 (236) hide show
  1. package/.github/CODEOWNERS +1 -0
  2. package/.github/ISSUE_TEMPLATE/bug_report.yml +65 -0
  3. package/.github/ISSUE_TEMPLATE/config.yml +11 -0
  4. package/.github/ISSUE_TEMPLATE/documentation.yml +22 -0
  5. package/.github/ISSUE_TEMPLATE/feature_request.yml +43 -0
  6. package/.github/PULL_REQUEST_TEMPLATE.md +25 -0
  7. package/.github/workflows/check.yml +47 -0
  8. package/CODE_OF_CONDUCT.md +24 -0
  9. package/CONTRIBUTING.md +52 -0
  10. package/LICENSE +201 -0
  11. package/NOTICE.md +23 -0
  12. package/README.md +806 -0
  13. package/SECURITY.md +17 -0
  14. package/docker/open-design/.env.example +6 -0
  15. package/docker/open-design/Dockerfile +50 -0
  16. package/docker/open-design/docker-compose.yml +18 -0
  17. package/docker/open-design/opencode-od/agents/od-worker.md +22 -0
  18. package/docker/open-design/opencode-od/opencode.json +24 -0
  19. package/docs/agents.md +21 -0
  20. package/docs/commands.md +16 -0
  21. package/docs/configuration.md +30 -0
  22. package/docs/docker-open-design.md +42 -0
  23. package/docs/impeccable.md +18 -0
  24. package/docs/installation.md +176 -0
  25. package/docs/models.md +17 -0
  26. package/docs/open-design.md +25 -0
  27. package/docs/quickstart.md +74 -0
  28. package/docs/releases/v1.0.10.md +46 -0
  29. package/docs/releases/v1.0.14.md +39 -0
  30. package/docs/releases/v1.0.27.md +66 -0
  31. package/docs/security.md +8 -0
  32. package/docs/superpowers/plans/2026-07-20-safe-installation-lifecycle.md +779 -0
  33. package/docs/superpowers/plans/2026-07-20-version-identity-and-releases.md +590 -0
  34. package/docs/superpowers/specs/2026-07-20-safe-installation-lifecycle-design.md +1350 -0
  35. package/docs/superpowers/specs/2026-07-20-version-identity-and-releases-design.md +557 -0
  36. package/docs/superpowers.md +34 -0
  37. package/docs/synology.md +30 -0
  38. package/docs/troubleshooting.md +54 -0
  39. package/docs/workflows.md +44 -0
  40. package/doctor.sh +5 -0
  41. package/env.example +15 -0
  42. package/install.sh +5 -0
  43. package/opencode/AGENTS.md +104 -0
  44. package/opencode/agents/debugger.md +41 -0
  45. package/opencode/agents/designer.md +93 -0
  46. package/opencode/agents/developer.md +180 -0
  47. package/opencode/agents/evaluator.md +35 -0
  48. package/opencode/agents/evolver.md +31 -0
  49. package/opencode/agents/lead.md +251 -0
  50. package/opencode/agents/researcher.md +76 -0
  51. package/opencode/agents/review_api.md +34 -0
  52. package/opencode/agents/review_coordinator.md +111 -0
  53. package/opencode/agents/review_quality.md +35 -0
  54. package/opencode/agents/review_security.md +35 -0
  55. package/opencode/agents/review_tests.md +37 -0
  56. package/opencode/agents/reviewer.md +116 -0
  57. package/opencode/agents/scoper.md +75 -0
  58. package/opencode/agents/specifier.md +116 -0
  59. package/opencode/commands/code-simplify.md +36 -0
  60. package/opencode/commands/design.md +27 -0
  61. package/opencode/commands/evolve.md +165 -0
  62. package/opencode/commands/feature.md +67 -0
  63. package/opencode/commands/implement.md +11 -0
  64. package/opencode/commands/init.md +34 -0
  65. package/opencode/commands/loop.md +145 -0
  66. package/opencode/commands/mvp-spec.md +20 -0
  67. package/opencode/commands/plan.md +74 -0
  68. package/opencode/commands/research.md +12 -0
  69. package/opencode/commands/review-orchestrated.md +47 -0
  70. package/opencode/commands/review-preflight.md +26 -0
  71. package/opencode/commands/review.md +18 -0
  72. package/opencode/commands/scope.md +36 -0
  73. package/opencode/commands/spec.md +12 -0
  74. package/opencode/commands/test.md +40 -0
  75. package/opencode/docs/ai/evolution/README.md +135 -0
  76. package/opencode/docs/ai/evolution/benchmarks/manual-scenarios.md +123 -0
  77. package/opencode/docs/ai/evolution/benchmarks/router-scenarios.jsonl +8 -0
  78. package/opencode/docs/ai/evolution/evolution_history.md +83 -0
  79. package/opencode/docs/ai/evolution/mechanisms.jsonl +7 -0
  80. package/opencode/docs/ai/evolution/rejected_mechanisms.jsonl +2 -0
  81. package/opencode/docs/ai/evolution/runs/README.md +15 -0
  82. package/opencode/docs/ai/evolution/runs/iteration-001-sidecar/analysis/overview.md +12 -0
  83. package/opencode/docs/ai/evolution/runs/iteration-001-sidecar/change_evaluation.json +108 -0
  84. package/opencode/docs/ai/evolution/runs/iteration-001-sidecar/change_manifest.json +52 -0
  85. package/opencode/docs/ai/evolution/runs/iteration-001-sidecar/evaluation.md +19 -0
  86. package/opencode/docs/ai/evolution/runs/iteration-001-sidecar/post_evaluation.md +12 -0
  87. package/opencode/docs/ai/evolution/runs/iteration-002-feature-flow-fix/analysis/overview.md +7 -0
  88. package/opencode/docs/ai/evolution/runs/iteration-002-feature-flow-fix/change_evaluation.json +31 -0
  89. package/opencode/docs/ai/evolution/runs/iteration-002-feature-flow-fix/evaluation.md +19 -0
  90. package/opencode/docs/ai/evolution/runs/iteration-003-agent-readable-harness/analysis/overview.md +13 -0
  91. package/opencode/docs/ai/evolution/runs/iteration-003-agent-readable-harness/change_evaluation.json +66 -0
  92. package/opencode/docs/ai/evolution/runs/iteration-003-agent-readable-harness/change_manifest.json +82 -0
  93. package/opencode/docs/ai/evolution/runs/iteration-003-agent-readable-harness/evaluation.md +20 -0
  94. package/opencode/docs/ai/evolution/runs/iteration-004-orchestration-audit/analysis/detail/ahe-run-lifecycle-validator.md +40 -0
  95. package/opencode/docs/ai/evolution/runs/iteration-004-orchestration-audit/analysis/detail/evolve-evaluation-only-contract.md +15 -0
  96. package/opencode/docs/ai/evolution/runs/iteration-004-orchestration-audit/analysis/detail/open-design-tool-contract.md +14 -0
  97. package/opencode/docs/ai/evolution/runs/iteration-004-orchestration-audit/analysis/detail/slash-command-contract-coverage.md +40 -0
  98. package/opencode/docs/ai/evolution/runs/iteration-004-orchestration-audit/analysis/overview.md +17 -0
  99. package/opencode/docs/ai/evolution/runs/iteration-004-orchestration-audit/analysis/pre_apply_approval.md +15 -0
  100. package/opencode/docs/ai/evolution/runs/iteration-004-orchestration-audit/change_evaluation.json +252 -0
  101. package/opencode/docs/ai/evolution/runs/iteration-004-orchestration-audit/change_manifest.json +210 -0
  102. package/opencode/docs/ai/evolution/runs/iteration-004-orchestration-audit/evaluation.md +25 -0
  103. package/opencode/docs/ai/evolution/runs/iteration-004-orchestration-audit/post_apply_evaluation.md +15 -0
  104. package/opencode/docs/ai/evolution/runs/iteration-004-orchestration-audit/post_manifest_evaluation.md +14 -0
  105. package/opencode/docs/ai/evolution/runs/iteration-004-orchestration-audit/pre_apply_evaluation.md +15 -0
  106. package/opencode/docs/ai/evolution/runs/iteration-005-harness-orchestration-audit/analysis/overview.md +13 -0
  107. package/opencode/docs/ai/evolution/runs/iteration-005-harness-orchestration-audit/change_evaluation.json +14 -0
  108. package/opencode/docs/ai/evolution/runs/iteration-005-harness-orchestration-audit/change_manifest.json +30 -0
  109. package/opencode/docs/ai/evolution/runs/iteration-005-harness-orchestration-audit/evaluation.md +25 -0
  110. package/opencode/docs/ai/evolution/runs/iteration-006-lead-delegation-audit/analysis/overview.md +13 -0
  111. package/opencode/docs/ai/evolution/runs/iteration-006-lead-delegation-audit/change_evaluation.json +14 -0
  112. package/opencode/docs/ai/evolution/runs/iteration-006-lead-delegation-audit/change_manifest.json +29 -0
  113. package/opencode/docs/ai/evolution/runs/iteration-006-lead-delegation-audit/evaluation.md +18 -0
  114. package/opencode/docs/ai/evolution/runs/iteration-007-agent-skills-integration/analysis/overview.md +13 -0
  115. package/opencode/docs/ai/evolution/runs/iteration-007-agent-skills-integration/change_evaluation.json +14 -0
  116. package/opencode/docs/ai/evolution/runs/iteration-007-agent-skills-integration/change_manifest.json +34 -0
  117. package/opencode/docs/ai/evolution/runs/iteration-007-agent-skills-integration/evaluation.md +17 -0
  118. package/opencode/docs/ai/evolution/runs/iteration-008-lead-readonly-shell-permissions/analysis/overview.md +13 -0
  119. package/opencode/docs/ai/evolution/runs/iteration-008-lead-readonly-shell-permissions/change_evaluation.json +12 -0
  120. package/opencode/docs/ai/evolution/runs/iteration-008-lead-readonly-shell-permissions/change_manifest.json +28 -0
  121. package/opencode/docs/ai/evolution/runs/iteration-008-lead-readonly-shell-permissions/evaluation.md +17 -0
  122. package/opencode/docs/ai/evolution/runs/iteration-009-lead-developer-ownership-loop/analysis/overview.md +9 -0
  123. package/opencode/docs/ai/evolution/runs/iteration-009-lead-developer-ownership-loop/change_evaluation.json +14 -0
  124. package/opencode/docs/ai/evolution/runs/iteration-009-lead-developer-ownership-loop/change_manifest.json +31 -0
  125. package/opencode/docs/ai/evolution/runs/iteration-009-lead-developer-ownership-loop/evaluation.md +18 -0
  126. package/opencode/docs/ai/evolution/runs/iteration-010-token-plugin-sidebar-content/analysis/overview.md +12 -0
  127. package/opencode/docs/ai/evolution/runs/iteration-010-token-plugin-sidebar-content/change_evaluation.json +14 -0
  128. package/opencode/docs/ai/evolution/runs/iteration-010-token-plugin-sidebar-content/change_manifest.json +31 -0
  129. package/opencode/docs/ai/evolution/runs/iteration-010-token-plugin-sidebar-content/evaluation.md +17 -0
  130. package/opencode/docs/ai/evolution/runs/iteration-011-lead-cd-which-permissions/analysis/overview.md +10 -0
  131. package/opencode/docs/ai/evolution/runs/iteration-011-lead-cd-which-permissions/change_evaluation.json +14 -0
  132. package/opencode/docs/ai/evolution/runs/iteration-011-lead-cd-which-permissions/change_manifest.json +30 -0
  133. package/opencode/docs/ai/evolution/runs/iteration-011-lead-cd-which-permissions/evaluation.md +17 -0
  134. package/opencode/docs/ai/evolution/runs/iteration-012-lead-shell-allowlist-boundaries/analysis/overview.md +25 -0
  135. package/opencode/docs/ai/evolution/runs/iteration-012-lead-shell-allowlist-boundaries/change_evaluation.json +28 -0
  136. package/opencode/docs/ai/evolution/runs/iteration-012-lead-shell-allowlist-boundaries/change_manifest.json +31 -0
  137. package/opencode/docs/ai/evolution/runs/iteration-012-lead-shell-allowlist-boundaries/evaluation.md +22 -0
  138. package/opencode/docs/ai/evolution/runs/iteration-013-doc-gardening-mechanical-checks/analysis/overview.md +27 -0
  139. package/opencode/docs/ai/evolution/runs/iteration-013-doc-gardening-mechanical-checks/change_evaluation.json +32 -0
  140. package/opencode/docs/ai/evolution/runs/iteration-013-doc-gardening-mechanical-checks/change_manifest.json +49 -0
  141. package/opencode/docs/ai/evolution/runs/iteration-013-doc-gardening-mechanical-checks/evaluation.md +92 -0
  142. package/opencode/docs/ai/evolution/runs/iteration-014-harness-baseline/analysis/detail/token-vs-semantic.md +31 -0
  143. package/opencode/docs/ai/evolution/runs/iteration-014-harness-baseline/analysis/overview.md +14 -0
  144. package/opencode/docs/ai/evolution/runs/iteration-014-harness-baseline/evaluation.md +36 -0
  145. package/opencode/docs/ai/evolution/runs/iteration-015-semantic-checker/analysis/overview.md +13 -0
  146. package/opencode/docs/ai/evolution/runs/iteration-015-semantic-checker/change_evaluation.json +31 -0
  147. package/opencode/docs/ai/evolution/runs/iteration-015-semantic-checker/change_manifest.json +47 -0
  148. package/opencode/docs/ai/evolution/runs/iteration-015-semantic-checker/evaluation.md +27 -0
  149. package/opencode/docs/ai/evolution/runs/iteration-016-contract-prompt-alignment/analysis/overview.md +32 -0
  150. package/opencode/docs/ai/evolution/runs/iteration-016-contract-prompt-alignment/change_evaluation.json +31 -0
  151. package/opencode/docs/ai/evolution/runs/iteration-016-contract-prompt-alignment/change_manifest.json +35 -0
  152. package/opencode/docs/ai/evolution/runs/iteration-016-contract-prompt-alignment/evaluation.md +31 -0
  153. package/opencode/docs/ai/evolution/runs/iteration-017-ahe-cycle/analysis/detail/pattern-1-feature-sidecar-false-positive.md +51 -0
  154. package/opencode/docs/ai/evolution/runs/iteration-017-ahe-cycle/analysis/detail/pattern-2-checker-time-budget.md +52 -0
  155. package/opencode/docs/ai/evolution/runs/iteration-017-ahe-cycle/analysis/overview.md +99 -0
  156. package/opencode/docs/ai/evolution/runs/iteration-017-ahe-cycle/change_evaluation.json +61 -0
  157. package/opencode/docs/ai/evolution/runs/iteration-017-ahe-cycle/change_manifest.json +61 -0
  158. package/opencode/docs/ai/evolution/runs/iteration-017-ahe-cycle/evaluation.md +448 -0
  159. package/opencode/docs/ai/evolution/runs/iteration-018-free-message-routing-audit/analysis/detail/intake-gray-zone.md +65 -0
  160. package/opencode/docs/ai/evolution/runs/iteration-018-free-message-routing-audit/analysis/overview.md +172 -0
  161. package/opencode/docs/ai/evolution/runs/iteration-018-free-message-routing-audit/evaluation.md +226 -0
  162. package/opencode/docs/ai/evolution/runs/iteration-019-handoff-routing-audit/analysis/detail/plan-only-gray-zone.md +62 -0
  163. package/opencode/docs/ai/evolution/runs/iteration-019-handoff-routing-audit/analysis/overview.md +167 -0
  164. package/opencode/docs/ai/evolution/runs/iteration-019-handoff-routing-audit/evaluation.md +163 -0
  165. package/opencode/docs/ai/evolution/runs/iteration-020-loop-engineering-command/analysis/overview.md +42 -0
  166. package/opencode/docs/ai/evolution/runs/iteration-020-loop-engineering-command/change_evaluation.json +46 -0
  167. package/opencode/docs/ai/evolution/runs/iteration-020-loop-engineering-command/change_manifest.json +57 -0
  168. package/opencode/docs/ai/evolution/runs/iteration-020-loop-engineering-command/evaluation.md +48 -0
  169. package/opencode/docs/ai/evolution/runs/iteration-021/analysis/detail/contract-vs-runtime-gap.md +163 -0
  170. package/opencode/docs/ai/evolution/runs/iteration-021/analysis/detail/evidence-collection-blocker.md +134 -0
  171. package/opencode/docs/ai/evolution/runs/iteration-021/analysis/overview.md +111 -0
  172. package/opencode/docs/ai/evolution/runs/iteration-021/change_evaluation.json +52 -0
  173. package/opencode/docs/ai/evolution/runs/iteration-021/change_manifest.json +50 -0
  174. package/opencode/docs/ai/evolution/runs/iteration-021/evaluation.md +46 -0
  175. package/opencode/docs/ai/evolution/runs/iteration-021/manifest-justification.md +48 -0
  176. package/opencode/docs/ai/evolution/session-sources.md +91 -0
  177. package/opencode/docs/ai/harness/README.md +32 -0
  178. package/opencode/docs/ai/harness/agents.md +148 -0
  179. package/opencode/docs/ai/harness/checks.md +119 -0
  180. package/opencode/docs/ai/harness/commands.md +391 -0
  181. package/opencode/docs/ai/harness/evidence.md +85 -0
  182. package/opencode/docs/ai/harness/init-detection-rules.md +160 -0
  183. package/opencode/docs/ai/harness/orchestrated-review.md +131 -0
  184. package/opencode/docs/ai/harness/skill-metadata-schema.md +198 -0
  185. package/opencode/docs/ai/harness/skill-resolution.md +202 -0
  186. package/opencode/docs/ai/harness/skill_registry.json +443 -0
  187. package/opencode/docs/ai/harness/skill_registry.md +43 -0
  188. package/opencode/docs/ai/project-context-template.md +53 -0
  189. package/opencode/opencode.json +38 -0
  190. package/opencode/package-lock.json +1717 -0
  191. package/opencode/package.json +11 -0
  192. package/opencode/plugins/token-tree-usage.tsx +206 -0
  193. package/opencode/references/performance-checklist.md +153 -0
  194. package/opencode/references/security-checklist.md +134 -0
  195. package/opencode/references/testing-patterns.md +236 -0
  196. package/opencode/scripts/check-harness.mjs +1572 -0
  197. package/opencode/scripts/check-harness.test.mjs +820 -0
  198. package/opencode/scripts/collect-session-evidence.mjs +612 -0
  199. package/opencode/scripts/collect-session-evidence.test.mjs +443 -0
  200. package/opencode/scripts/preflight-audit.mjs +497 -0
  201. package/opencode/scripts/preflight-audit.test.mjs +363 -0
  202. package/opencode/scripts/project-capability-snapshot.mjs +407 -0
  203. package/opencode/scripts/project-capability-snapshot.test.mjs +382 -0
  204. package/opencode/scripts/review-orchestrated-prepare.mjs +547 -0
  205. package/opencode/scripts/review-orchestrated-prepare.test.mjs +516 -0
  206. package/opencode/scripts/skill-resolver.mjs +585 -0
  207. package/opencode/scripts/skill-resolver.test.mjs +781 -0
  208. package/opencode/scripts/update-skill-registry.mjs +380 -0
  209. package/opencode/skills/api-and-interface-design/SKILL.md +315 -0
  210. package/opencode/skills/autonomous-loops/SKILL.md +312 -0
  211. package/opencode/skills/code-review-and-quality/SKILL.md +365 -0
  212. package/opencode/skills/code-simplification/SKILL.md +345 -0
  213. package/opencode/skills/context-engineering/SKILL.md +252 -0
  214. package/opencode/skills/debugging-and-error-recovery/SKILL.md +316 -0
  215. package/opencode/skills/documentation-and-adrs/SKILL.md +298 -0
  216. package/opencode/skills/doubt-driven-development/SKILL.md +168 -0
  217. package/opencode/skills/iterative-retrieval/SKILL.md +232 -0
  218. package/opencode/skills/open-design/SKILL.md +123 -0
  219. package/opencode/skills/performance-optimization/SKILL.md +365 -0
  220. package/opencode/skills/security-and-hardening/SKILL.md +369 -0
  221. package/opencode/skills/source-driven-development/SKILL.md +210 -0
  222. package/opencode/skills/test-driven-development/SKILL.md +406 -0
  223. package/opencode/skills/using-agent-skills/SKILL.md +194 -0
  224. package/opencode/skills/verification-loop/SKILL.md +162 -0
  225. package/opencode/tools/open_design.ts +361 -0
  226. package/opencode/tui.json +5 -0
  227. package/package.json +20 -0
  228. package/rollback.sh +5 -0
  229. package/scripts/check.sh +184 -0
  230. package/scripts/install-smoke.sh +111 -0
  231. package/scripts/manage-installation.mjs +1498 -0
  232. package/scripts/manage-installation.test.mjs +1936 -0
  233. package/scripts/version.mjs +197 -0
  234. package/scripts/version.test.mjs +195 -0
  235. package/uninstall.sh +5 -0
  236. package/upgrade.sh +5 -0
@@ -0,0 +1,369 @@
1
+ ---
2
+ name: security-and-hardening
3
+ description: Hardens code against vulnerabilities. Use when handling user input, authentication, data storage, or external integrations. Use when building any feature that accepts untrusted data, manages user sessions, or interacts with third-party services.
4
+ phase: build
5
+ domains:
6
+ - security
7
+ stacks:
8
+ - any
9
+ allowed_agents:
10
+ - developer
11
+ - researcher
12
+ - designer
13
+ - specifier
14
+ - reviewer
15
+ - scoper
16
+ - lead
17
+ surfaces:
18
+ - input-validation
19
+ - auth
20
+ - secrets-management
21
+ skill_source: built-in
22
+ origin: null
23
+ status: active
24
+ ---
25
+
26
+ # Security and Hardening
27
+
28
+ ## Overview
29
+
30
+ Security-first development practices for web applications. Treat every external input as hostile, every secret as sacred, and every authorization check as mandatory. Security isn't a phase — it's a constraint on every line of code that touches user data, authentication, or external systems.
31
+
32
+ ## When to Use
33
+
34
+ - Building anything that accepts user input
35
+ - Implementing authentication or authorization
36
+ - Storing or transmitting sensitive data
37
+ - Integrating with external APIs or services
38
+ - Adding file uploads, webhooks, or callbacks
39
+ - Handling payment or PII data
40
+
41
+ ## The Three-Tier Boundary System
42
+
43
+ ### Always Do (No Exceptions)
44
+
45
+ - **Validate all external input** at the system boundary (API routes, form handlers)
46
+ - **Parameterize all database queries** — never concatenate user input into SQL
47
+ - **Encode output** to prevent XSS (use framework auto-escaping, don't bypass it)
48
+ - **Use HTTPS** for all external communication
49
+ - **Hash passwords** with bcrypt/scrypt/argon2 (never store plaintext)
50
+ - **Set security headers** (CSP, HSTS, X-Frame-Options, X-Content-Type-Options)
51
+ - **Use httpOnly, secure, sameSite cookies** for sessions
52
+ - **Run `npm audit`** (or equivalent) before every release
53
+
54
+ ### Ask First (Requires Human Approval)
55
+
56
+ - Adding new authentication flows or changing auth logic
57
+ - Storing new categories of sensitive data (PII, payment info)
58
+ - Adding new external service integrations
59
+ - Changing CORS configuration
60
+ - Adding file upload handlers
61
+ - Modifying rate limiting or throttling
62
+ - Granting elevated permissions or roles
63
+
64
+ ### Never Do
65
+
66
+ - **Never commit secrets** to version control (API keys, passwords, tokens)
67
+ - **Never log sensitive data** (passwords, tokens, full credit card numbers)
68
+ - **Never trust client-side validation** as a security boundary
69
+ - **Never disable security headers** for convenience
70
+ - **Never use `eval()` or `innerHTML`** with user-provided data
71
+ - **Never store sessions in client-accessible storage** (localStorage for auth tokens)
72
+ - **Never expose stack traces** or internal error details to users
73
+
74
+ ## OWASP Top 10 Prevention
75
+
76
+ ### 1. Injection (SQL, NoSQL, OS Command)
77
+
78
+ ```typescript
79
+ // BAD: SQL injection via string concatenation
80
+ const query = `SELECT * FROM users WHERE id = '${userId}'`;
81
+
82
+ // GOOD: Parameterized query
83
+ const user = await db.query('SELECT * FROM users WHERE id = $1', [userId]);
84
+
85
+ // GOOD: ORM with parameterized input
86
+ const user = await prisma.user.findUnique({ where: { id: userId } });
87
+ ```
88
+
89
+ ### 2. Broken Authentication
90
+
91
+ ```typescript
92
+ // Password hashing
93
+ import { hash, compare } from 'bcrypt';
94
+
95
+ const SALT_ROUNDS = 12;
96
+ const hashedPassword = await hash(plaintext, SALT_ROUNDS);
97
+ const isValid = await compare(plaintext, hashedPassword);
98
+
99
+ // Session management
100
+ app.use(session({
101
+ secret: process.env.SESSION_SECRET, // From environment, not code
102
+ resave: false,
103
+ saveUninitialized: false,
104
+ cookie: {
105
+ httpOnly: true, // Not accessible via JavaScript
106
+ secure: true, // HTTPS only
107
+ sameSite: 'lax', // CSRF protection
108
+ maxAge: 24 * 60 * 60 * 1000, // 24 hours
109
+ },
110
+ }));
111
+ ```
112
+
113
+ ### 3. Cross-Site Scripting (XSS)
114
+
115
+ ```typescript
116
+ // BAD: Rendering user input as HTML
117
+ element.innerHTML = userInput;
118
+
119
+ // GOOD: Use framework auto-escaping (React does this by default)
120
+ return <div>{userInput}</div>;
121
+
122
+ // If you MUST render HTML, sanitize first
123
+ import DOMPurify from 'dompurify';
124
+ const clean = DOMPurify.sanitize(userInput);
125
+ ```
126
+
127
+ ### 4. Broken Access Control
128
+
129
+ ```typescript
130
+ // Always check authorization, not just authentication
131
+ app.patch('/api/tasks/:id', authenticate, async (req, res) => {
132
+ const task = await taskService.findById(req.params.id);
133
+
134
+ // Check that the authenticated user owns this resource
135
+ if (task.ownerId !== req.user.id) {
136
+ return res.status(403).json({
137
+ error: { code: 'FORBIDDEN', message: 'Not authorized to modify this task' }
138
+ });
139
+ }
140
+
141
+ // Proceed with update
142
+ const updated = await taskService.update(req.params.id, req.body);
143
+ return res.json(updated);
144
+ });
145
+ ```
146
+
147
+ ### 5. Security Misconfiguration
148
+
149
+ ```typescript
150
+ // Security headers (use helmet for Express)
151
+ import helmet from 'helmet';
152
+ app.use(helmet());
153
+
154
+ // Content Security Policy
155
+ app.use(helmet.contentSecurityPolicy({
156
+ directives: {
157
+ defaultSrc: ["'self'"],
158
+ scriptSrc: ["'self'"],
159
+ styleSrc: ["'self'", "'unsafe-inline'"], // Tighten if possible
160
+ imgSrc: ["'self'", 'data:', 'https:'],
161
+ connectSrc: ["'self'"],
162
+ },
163
+ }));
164
+
165
+ // CORS — restrict to known origins
166
+ app.use(cors({
167
+ origin: process.env.ALLOWED_ORIGINS?.split(',') || 'http://localhost:3000',
168
+ credentials: true,
169
+ }));
170
+ ```
171
+
172
+ ### 6. Sensitive Data Exposure
173
+
174
+ ```typescript
175
+ // Never return sensitive fields in API responses
176
+ function sanitizeUser(user: UserRecord): PublicUser {
177
+ const { passwordHash, resetToken, ...publicFields } = user;
178
+ return publicFields;
179
+ }
180
+
181
+ // Use environment variables for secrets
182
+ const API_KEY = process.env.STRIPE_API_KEY;
183
+ if (!API_KEY) throw new Error('STRIPE_API_KEY not configured');
184
+ ```
185
+
186
+ ## Input Validation Patterns
187
+
188
+ ### Schema Validation at Boundaries
189
+
190
+ ```typescript
191
+ import { z } from 'zod';
192
+
193
+ const CreateTaskSchema = z.object({
194
+ title: z.string().min(1).max(200).trim(),
195
+ description: z.string().max(2000).optional(),
196
+ priority: z.enum(['low', 'medium', 'high']).default('medium'),
197
+ dueDate: z.string().datetime().optional(),
198
+ });
199
+
200
+ // Validate at the route handler
201
+ app.post('/api/tasks', async (req, res) => {
202
+ const result = CreateTaskSchema.safeParse(req.body);
203
+ if (!result.success) {
204
+ return res.status(422).json({
205
+ error: {
206
+ code: 'VALIDATION_ERROR',
207
+ message: 'Invalid input',
208
+ details: result.error.flatten(),
209
+ },
210
+ });
211
+ }
212
+ // result.data is now typed and validated
213
+ const task = await taskService.create(result.data);
214
+ return res.status(201).json(task);
215
+ });
216
+ ```
217
+
218
+ ### File Upload Safety
219
+
220
+ ```typescript
221
+ // Restrict file types and sizes
222
+ const ALLOWED_TYPES = ['image/jpeg', 'image/png', 'image/webp'];
223
+ const MAX_SIZE = 5 * 1024 * 1024; // 5MB
224
+
225
+ function validateUpload(file: UploadedFile) {
226
+ if (!ALLOWED_TYPES.includes(file.mimetype)) {
227
+ throw new ValidationError('File type not allowed');
228
+ }
229
+ if (file.size > MAX_SIZE) {
230
+ throw new ValidationError('File too large (max 5MB)');
231
+ }
232
+ // Don't trust the file extension — check magic bytes if critical
233
+ }
234
+ ```
235
+
236
+ ## Triaging npm audit Results
237
+
238
+ Not all audit findings require immediate action. Use this decision tree:
239
+
240
+ ```
241
+ npm audit reports a vulnerability
242
+ ├── Severity: critical or high
243
+ │ ├── Is the vulnerable code reachable in your app?
244
+ │ │ ├── YES --> Fix immediately (update, patch, or replace the dependency)
245
+ │ │ └── NO (dev-only dep, unused code path) --> Fix soon, but not a blocker
246
+ │ └── Is a fix available?
247
+ │ ├── YES --> Update to the patched version
248
+ │ └── NO --> Check for workarounds, consider replacing the dependency, or add to allowlist with a review date
249
+ ├── Severity: moderate
250
+ │ ├── Reachable in production? --> Fix in the next release cycle
251
+ │ └── Dev-only? --> Fix when convenient, track in backlog
252
+ └── Severity: low
253
+ └── Track and fix during regular dependency updates
254
+ ```
255
+
256
+ **Key questions:**
257
+ - Is the vulnerable function actually called in your code path?
258
+ - Is the dependency a runtime dependency or dev-only?
259
+ - Is the vulnerability exploitable given your deployment context (e.g., a server-side vulnerability in a client-only app)?
260
+
261
+ When you defer a fix, document the reason and set a review date.
262
+
263
+ ## Rate Limiting
264
+
265
+ ```typescript
266
+ import rateLimit from 'express-rate-limit';
267
+
268
+ // General API rate limit
269
+ app.use('/api/', rateLimit({
270
+ windowMs: 15 * 60 * 1000, // 15 minutes
271
+ max: 100, // 100 requests per window
272
+ standardHeaders: true,
273
+ legacyHeaders: false,
274
+ }));
275
+
276
+ // Stricter limit for auth endpoints
277
+ app.use('/api/auth/', rateLimit({
278
+ windowMs: 15 * 60 * 1000,
279
+ max: 10, // 10 attempts per 15 minutes
280
+ }));
281
+ ```
282
+
283
+ ## Secrets Management
284
+
285
+ ```
286
+ .env files:
287
+ ├── .env.example → Committed (template with placeholder values)
288
+ ├── .env → NOT committed (contains real secrets)
289
+ └── .env.local → NOT committed (local overrides)
290
+
291
+ .gitignore must include:
292
+ .env
293
+ .env.local
294
+ .env.*.local
295
+ *.pem
296
+ *.key
297
+ ```
298
+
299
+ **Always check before committing:**
300
+ ```bash
301
+ # Check for accidentally staged secrets
302
+ git diff --cached | grep -i "password\|secret\|api_key\|token"
303
+ ```
304
+
305
+ ## Security Review Checklist
306
+
307
+ ```markdown
308
+ ### Authentication
309
+ - [ ] Passwords hashed with bcrypt/scrypt/argon2 (salt rounds ≥ 12)
310
+ - [ ] Session tokens are httpOnly, secure, sameSite
311
+ - [ ] Login has rate limiting
312
+ - [ ] Password reset tokens expire
313
+
314
+ ### Authorization
315
+ - [ ] Every endpoint checks user permissions
316
+ - [ ] Users can only access their own resources
317
+ - [ ] Admin actions require admin role verification
318
+
319
+ ### Input
320
+ - [ ] All user input validated at the boundary
321
+ - [ ] SQL queries are parameterized
322
+ - [ ] HTML output is encoded/escaped
323
+
324
+ ### Data
325
+ - [ ] No secrets in code or version control
326
+ - [ ] Sensitive fields excluded from API responses
327
+ - [ ] PII encrypted at rest (if applicable)
328
+
329
+ ### Infrastructure
330
+ - [ ] Security headers configured (CSP, HSTS, etc.)
331
+ - [ ] CORS restricted to known origins
332
+ - [ ] Dependencies audited for vulnerabilities
333
+ - [ ] Error messages don't expose internals
334
+ ```
335
+ ## See Also
336
+
337
+ For detailed security checklists and pre-commit verification steps, see `references/security-checklist.md`.
338
+
339
+ ## Common Rationalizations
340
+
341
+ | Rationalization | Reality |
342
+ |---|---|
343
+ | "This is an internal tool, security doesn't matter" | Internal tools get compromised. Attackers target the weakest link. |
344
+ | "We'll add security later" | Security retrofitting is 10x harder than building it in. Add it now. |
345
+ | "No one would try to exploit this" | Automated scanners will find it. Security by obscurity is not security. |
346
+ | "The framework handles security" | Frameworks provide tools, not guarantees. You still need to use them correctly. |
347
+ | "It's just a prototype" | Prototypes become production. Security habits from day one. |
348
+
349
+ ## Red Flags
350
+
351
+ - User input passed directly to database queries, shell commands, or HTML rendering
352
+ - Secrets in source code or commit history
353
+ - API endpoints without authentication or authorization checks
354
+ - Missing CORS configuration or wildcard (`*`) origins
355
+ - No rate limiting on authentication endpoints
356
+ - Stack traces or internal errors exposed to users
357
+ - Dependencies with known critical vulnerabilities
358
+
359
+ ## Verification
360
+
361
+ After implementing security-relevant code:
362
+
363
+ - [ ] `npm audit` shows no critical or high vulnerabilities
364
+ - [ ] No secrets in source code or git history
365
+ - [ ] All user input validated at system boundaries
366
+ - [ ] Authentication and authorization checked on every protected endpoint
367
+ - [ ] Security headers present in response (check with browser DevTools)
368
+ - [ ] Error responses don't expose internal details
369
+ - [ ] Rate limiting active on auth endpoints
@@ -0,0 +1,210 @@
1
+ ---
2
+ name: source-driven-development
3
+ description: Grounds every implementation decision in official documentation. Use when you want authoritative, source-cited code free from outdated patterns. Use when building with any framework or library where correctness matters.
4
+ phase: build
5
+ domains:
6
+ - research
7
+ - specification
8
+ stacks:
9
+ - any
10
+ allowed_agents:
11
+ - developer
12
+ - lead
13
+ - researcher
14
+ surfaces:
15
+ - framework-integration
16
+ - doc-verification
17
+ skill_source: built-in
18
+ origin: null
19
+ status: active
20
+ ---
21
+
22
+ # Source-Driven Development
23
+
24
+ ## Overview
25
+
26
+ Every framework-specific code decision must be backed by official documentation. Don't implement from memory — verify, cite, and let the user see your sources. Training data goes stale, APIs get deprecated, best practices evolve. This skill ensures the user gets code they can trust because every pattern traces back to an authoritative source they can check.
27
+
28
+ ## When to Use
29
+
30
+ - The user wants code that follows current best practices for a given framework
31
+ - Building boilerplate, starter code, or patterns that will be copied across a project
32
+ - The user explicitly asks for documented, verified, or "correct" implementation
33
+ - Implementing features where the framework's recommended approach matters (forms, routing, data fetching, state management, auth)
34
+ - Reviewing or improving code that uses framework-specific patterns
35
+ - Any time you are about to write framework-specific code from memory
36
+
37
+ **When NOT to use:**
38
+
39
+ - Correctness does not depend on a specific version (renaming variables, fixing typos, moving files)
40
+ - Pure logic that works the same across all versions (loops, conditionals, data structures)
41
+ - The user explicitly wants speed over verification ("just do it quickly")
42
+
43
+ ## The Process
44
+
45
+ ```
46
+ DETECT ──→ FETCH ──→ IMPLEMENT ──→ CITE
47
+ │ │ │ │
48
+ ▼ ▼ ▼ ▼
49
+ What Get the Follow the Show your
50
+ stack? relevant documented sources
51
+ docs patterns
52
+ ```
53
+
54
+ ### Step 1: Detect Stack and Versions
55
+
56
+ Read the project's dependency file to identify exact versions:
57
+
58
+ ```
59
+ package.json → Node/React/Vue/Angular/Svelte
60
+ composer.json → PHP/Symfony/Laravel
61
+ requirements.txt / pyproject.toml → Python/Django/Flask
62
+ go.mod → Go
63
+ Cargo.toml → Rust
64
+ Gemfile → Ruby/Rails
65
+ ```
66
+
67
+ State what you found explicitly:
68
+
69
+ ```
70
+ STACK DETECTED:
71
+ - React 19.1.0 (from package.json)
72
+ - Vite 6.2.0
73
+ - Tailwind CSS 4.0.3
74
+ → Fetching official docs for the relevant patterns.
75
+ ```
76
+
77
+ If versions are missing or ambiguous, **ask the user**. Don't guess — the version determines which patterns are correct.
78
+
79
+ ### Step 2: Fetch Official Documentation
80
+
81
+ Fetch the specific documentation page for the feature you're implementing. Not the homepage, not the full docs — the relevant page.
82
+
83
+ **Source hierarchy (in order of authority):**
84
+
85
+ | Priority | Source | Example |
86
+ |----------|--------|---------|
87
+ | 1 | Official documentation | react.dev, docs.djangoproject.com, symfony.com/doc |
88
+ | 2 | Official blog / changelog | react.dev/blog, nextjs.org/blog |
89
+ | 3 | Web standards references | MDN, web.dev, html.spec.whatwg.org |
90
+ | 4 | Browser/runtime compatibility | caniuse.com, node.green |
91
+
92
+ **Not authoritative — never cite as primary sources:**
93
+
94
+ - Stack Overflow answers
95
+ - Blog posts or tutorials (even popular ones)
96
+ - AI-generated documentation or summaries
97
+ - Your own training data (that is the whole point — verify it)
98
+
99
+ **Be precise with what you fetch:**
100
+
101
+ ```
102
+ BAD: Fetch the React homepage
103
+ GOOD: Fetch react.dev/reference/react/useActionState
104
+
105
+ BAD: Search "django authentication best practices"
106
+ GOOD: Fetch docs.djangoproject.com/en/6.0/topics/auth/
107
+ ```
108
+
109
+ After fetching, extract the key patterns and note any deprecation warnings or migration guidance.
110
+
111
+ When official sources conflict with each other (e.g. a migration guide contradicts the API reference), surface the discrepancy to the user and verify which pattern actually works against the detected version.
112
+
113
+ ### Step 3: Implement Following Documented Patterns
114
+
115
+ Write code that matches what the documentation shows:
116
+
117
+ - Use the API signatures from the docs, not from memory
118
+ - If the docs show a new way to do something, use the new way
119
+ - If the docs deprecate a pattern, don't use the deprecated version
120
+ - If the docs don't cover something, flag it as unverified
121
+
122
+ **When docs conflict with existing project code:**
123
+
124
+ ```
125
+ CONFLICT DETECTED:
126
+ The existing codebase uses useState for form loading state,
127
+ but React 19 docs recommend useActionState for this pattern.
128
+ (Source: react.dev/reference/react/useActionState)
129
+
130
+ Options:
131
+ A) Use the modern pattern (useActionState) — consistent with current docs
132
+ B) Match existing code (useState) — consistent with codebase
133
+ → Which approach do you prefer?
134
+ ```
135
+
136
+ Surface the conflict. Don't silently pick one.
137
+
138
+ ### Step 4: Cite Your Sources
139
+
140
+ Every framework-specific pattern gets a citation. The user must be able to verify every decision.
141
+
142
+ **In code comments:**
143
+
144
+ ```typescript
145
+ // React 19 form handling with useActionState
146
+ // Source: https://react.dev/reference/react/useActionState#usage
147
+ const [state, formAction, isPending] = useActionState(submitOrder, initialState);
148
+ ```
149
+
150
+ **In conversation:**
151
+
152
+ ```
153
+ I'm using useActionState instead of manual useState for the
154
+ form submission state. React 19 replaced the manual
155
+ isPending/setIsPending pattern with this hook.
156
+
157
+ Source: https://react.dev/blog/2024/12/05/react-19#actions
158
+ "useTransition now supports async functions [...] to handle
159
+ pending states automatically"
160
+ ```
161
+
162
+ **Citation rules:**
163
+
164
+ - Full URLs, not shortened
165
+ - Prefer deep links with anchors where possible (e.g. `/useActionState#usage` over `/useActionState`) — anchors survive doc restructuring better than top-level pages
166
+ - Quote the relevant passage when it supports a non-obvious decision
167
+ - Include browser/runtime support data when recommending platform features
168
+ - If you cannot find documentation for a pattern, say so explicitly:
169
+
170
+ ```
171
+ UNVERIFIED: I could not find official documentation for this
172
+ pattern. This is based on training data and may be outdated.
173
+ Verify before using in production.
174
+ ```
175
+
176
+ Honesty about what you couldn't verify is more valuable than false confidence.
177
+
178
+ ## Common Rationalizations
179
+
180
+ | Rationalization | Reality |
181
+ |---|---|
182
+ | "I'm confident about this API" | Confidence is not evidence. Training data contains outdated patterns that look correct but break against current versions. Verify. |
183
+ | "Fetching docs wastes tokens" | Hallucinating an API wastes more. The user debugs for an hour, then discovers the function signature changed. One fetch prevents hours of rework. |
184
+ | "The docs won't have what I need" | If the docs don't cover it, that's valuable information — the pattern may not be officially recommended. |
185
+ | "I'll just mention it might be outdated" | A disclaimer doesn't help. Either verify and cite, or clearly flag it as unverified. Hedging is the worst option. |
186
+ | "This is a simple task, no need to check" | Simple tasks with wrong patterns become templates. The user copies your deprecated form handler into ten components before discovering the modern approach exists. |
187
+
188
+ ## Red Flags
189
+
190
+ - Writing framework-specific code without checking the docs for that version
191
+ - Using "I believe" or "I think" about an API instead of citing the source
192
+ - Implementing a pattern without knowing which version it applies to
193
+ - Citing Stack Overflow or blog posts instead of official documentation
194
+ - Using deprecated APIs because they appear in training data
195
+ - Not reading `package.json` / dependency files before implementing
196
+ - Delivering code without source citations for framework-specific decisions
197
+ - Fetching an entire docs site when only one page is relevant
198
+
199
+ ## Verification
200
+
201
+ After implementing with source-driven development:
202
+
203
+ - [ ] Framework and library versions were identified from the dependency file
204
+ - [ ] Official documentation was fetched for framework-specific patterns
205
+ - [ ] All sources are official documentation, not blog posts or training data
206
+ - [ ] Code follows the patterns shown in the current version's documentation
207
+ - [ ] Non-trivial decisions include source citations with full URLs
208
+ - [ ] No deprecated APIs are used (checked against migration guides)
209
+ - [ ] Conflicts between docs and existing code were surfaced to the user
210
+ - [ ] Anything that could not be verified is explicitly flagged as unverified