compact-agent 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (324) hide show
  1. package/README.md +394 -0
  2. package/bin/anycode.js +2 -0
  3. package/bin/crowcoder.js +19 -0
  4. package/bin/ecc-hooks.cjs +138 -0
  5. package/dist/agents.d.ts +17 -0
  6. package/dist/agents.js +1603 -0
  7. package/dist/agents.js.map +1 -0
  8. package/dist/api.d.ts +16 -0
  9. package/dist/api.js +115 -0
  10. package/dist/api.js.map +1 -0
  11. package/dist/autonomous-loops.d.ts +108 -0
  12. package/dist/autonomous-loops.js +526 -0
  13. package/dist/autonomous-loops.js.map +1 -0
  14. package/dist/codemaps.d.ts +53 -0
  15. package/dist/codemaps.js +325 -0
  16. package/dist/codemaps.js.map +1 -0
  17. package/dist/compaction.d.ts +30 -0
  18. package/dist/compaction.js +125 -0
  19. package/dist/compaction.js.map +1 -0
  20. package/dist/config.d.ts +5 -0
  21. package/dist/config.js +79 -0
  22. package/dist/config.js.map +1 -0
  23. package/dist/content-engine.d.ts +97 -0
  24. package/dist/content-engine.js +721 -0
  25. package/dist/content-engine.js.map +1 -0
  26. package/dist/cost-tracker.d.ts +49 -0
  27. package/dist/cost-tracker.js +150 -0
  28. package/dist/cost-tracker.js.map +1 -0
  29. package/dist/counter-button.d.ts +35 -0
  30. package/dist/counter-button.js +48 -0
  31. package/dist/counter-button.js.map +1 -0
  32. package/dist/counter.d.ts +21 -0
  33. package/dist/counter.js +31 -0
  34. package/dist/counter.js.map +1 -0
  35. package/dist/coverage.d.ts +23 -0
  36. package/dist/coverage.js +215 -0
  37. package/dist/coverage.js.map +1 -0
  38. package/dist/docs-sync.d.ts +23 -0
  39. package/dist/docs-sync.js +266 -0
  40. package/dist/docs-sync.js.map +1 -0
  41. package/dist/ecc.d.ts +41 -0
  42. package/dist/ecc.js +644 -0
  43. package/dist/ecc.js.map +1 -0
  44. package/dist/evaluation.d.ts +24 -0
  45. package/dist/evaluation.js +412 -0
  46. package/dist/evaluation.js.map +1 -0
  47. package/dist/export.d.ts +22 -0
  48. package/dist/export.js +109 -0
  49. package/dist/export.js.map +1 -0
  50. package/dist/git-workflow.d.ts +22 -0
  51. package/dist/git-workflow.js +197 -0
  52. package/dist/git-workflow.js.map +1 -0
  53. package/dist/hook-controls.d.ts +34 -0
  54. package/dist/hook-controls.js +90 -0
  55. package/dist/hook-controls.js.map +1 -0
  56. package/dist/hooks.d.ts +30 -0
  57. package/dist/hooks.js +130 -0
  58. package/dist/hooks.js.map +1 -0
  59. package/dist/html-parser.d.ts +18 -0
  60. package/dist/html-parser.js +101 -0
  61. package/dist/html-parser.js.map +1 -0
  62. package/dist/index.d.ts +12 -0
  63. package/dist/index.js +1230 -0
  64. package/dist/index.js.map +1 -0
  65. package/dist/learning.d.ts +35 -0
  66. package/dist/learning.js +238 -0
  67. package/dist/learning.js.map +1 -0
  68. package/dist/login.d.ts +37 -0
  69. package/dist/login.js +191 -0
  70. package/dist/login.js.map +1 -0
  71. package/dist/memory.d.ts +39 -0
  72. package/dist/memory.js +183 -0
  73. package/dist/memory.js.map +1 -0
  74. package/dist/model-router.d.ts +23 -0
  75. package/dist/model-router.js +145 -0
  76. package/dist/model-router.js.map +1 -0
  77. package/dist/modes.d.ts +17 -0
  78. package/dist/modes.js +217 -0
  79. package/dist/modes.js.map +1 -0
  80. package/dist/orchestration.d.ts +37 -0
  81. package/dist/orchestration.js +139 -0
  82. package/dist/orchestration.js.map +1 -0
  83. package/dist/package-detect.d.ts +36 -0
  84. package/dist/package-detect.js +529 -0
  85. package/dist/package-detect.js.map +1 -0
  86. package/dist/permissions.d.ts +25 -0
  87. package/dist/permissions.js +50 -0
  88. package/dist/permissions.js.map +1 -0
  89. package/dist/pm2-manager.d.ts +40 -0
  90. package/dist/pm2-manager.js +127 -0
  91. package/dist/pm2-manager.js.map +1 -0
  92. package/dist/query.d.ts +15 -0
  93. package/dist/query.js +278 -0
  94. package/dist/query.js.map +1 -0
  95. package/dist/refactor.d.ts +22 -0
  96. package/dist/refactor.js +226 -0
  97. package/dist/refactor.js.map +1 -0
  98. package/dist/retry.d.ts +20 -0
  99. package/dist/retry.js +88 -0
  100. package/dist/retry.js.map +1 -0
  101. package/dist/rules.d.ts +34 -0
  102. package/dist/rules.js +942 -0
  103. package/dist/rules.js.map +1 -0
  104. package/dist/schema.d.ts +23 -0
  105. package/dist/schema.js +12 -0
  106. package/dist/schema.js.map +1 -0
  107. package/dist/search-first.d.ts +17 -0
  108. package/dist/search-first.js +301 -0
  109. package/dist/search-first.js.map +1 -0
  110. package/dist/security.d.ts +10 -0
  111. package/dist/security.js +145 -0
  112. package/dist/security.js.map +1 -0
  113. package/dist/sessions.d.ts +21 -0
  114. package/dist/sessions.js +112 -0
  115. package/dist/sessions.js.map +1 -0
  116. package/dist/skill-create.d.ts +38 -0
  117. package/dist/skill-create.js +389 -0
  118. package/dist/skill-create.js.map +1 -0
  119. package/dist/skills.d.ts +34 -0
  120. package/dist/skills.js +161 -0
  121. package/dist/skills.js.map +1 -0
  122. package/dist/strategic-compaction.d.ts +24 -0
  123. package/dist/strategic-compaction.js +144 -0
  124. package/dist/strategic-compaction.js.map +1 -0
  125. package/dist/system-prompt.d.ts +3 -0
  126. package/dist/system-prompt.js +101 -0
  127. package/dist/system-prompt.js.map +1 -0
  128. package/dist/theme.d.ts +60 -0
  129. package/dist/theme.js +220 -0
  130. package/dist/theme.js.map +1 -0
  131. package/dist/tools/bash.d.ts +2 -0
  132. package/dist/tools/bash.js +49 -0
  133. package/dist/tools/bash.js.map +1 -0
  134. package/dist/tools/edit.d.ts +2 -0
  135. package/dist/tools/edit.js +76 -0
  136. package/dist/tools/edit.js.map +1 -0
  137. package/dist/tools/glob.d.ts +2 -0
  138. package/dist/tools/glob.js +54 -0
  139. package/dist/tools/glob.js.map +1 -0
  140. package/dist/tools/grep.d.ts +2 -0
  141. package/dist/tools/grep.js +64 -0
  142. package/dist/tools/grep.js.map +1 -0
  143. package/dist/tools/index.d.ts +5 -0
  144. package/dist/tools/index.js +27 -0
  145. package/dist/tools/index.js.map +1 -0
  146. package/dist/tools/list-dir.d.ts +2 -0
  147. package/dist/tools/list-dir.js +51 -0
  148. package/dist/tools/list-dir.js.map +1 -0
  149. package/dist/tools/read.d.ts +2 -0
  150. package/dist/tools/read.js +56 -0
  151. package/dist/tools/read.js.map +1 -0
  152. package/dist/tools/types.d.ts +45 -0
  153. package/dist/tools/types.js +2 -0
  154. package/dist/tools/types.js.map +1 -0
  155. package/dist/tools/web-fetch.d.ts +2 -0
  156. package/dist/tools/web-fetch.js +41 -0
  157. package/dist/tools/web-fetch.js.map +1 -0
  158. package/dist/tools/web-search.d.ts +27 -0
  159. package/dist/tools/web-search.js +139 -0
  160. package/dist/tools/web-search.js.map +1 -0
  161. package/dist/tools/write.d.ts +2 -0
  162. package/dist/tools/write.js +36 -0
  163. package/dist/tools/write.js.map +1 -0
  164. package/dist/types.d.ts +28 -0
  165. package/dist/types.js +57 -0
  166. package/dist/types.js.map +1 -0
  167. package/dist/users.d.ts +51 -0
  168. package/dist/users.js +193 -0
  169. package/dist/users.js.map +1 -0
  170. package/dist/verification.d.ts +73 -0
  171. package/dist/verification.js +269 -0
  172. package/dist/verification.js.map +1 -0
  173. package/dist/walkthrough.d.ts +10 -0
  174. package/dist/walkthrough.js +121 -0
  175. package/dist/walkthrough.js.map +1 -0
  176. package/package.json +58 -0
  177. package/resources/ecc/agents/architect.json +16 -0
  178. package/resources/ecc/agents/architect.md +212 -0
  179. package/resources/ecc/agents/build-error-resolver.json +17 -0
  180. package/resources/ecc/agents/build-error-resolver.md +116 -0
  181. package/resources/ecc/agents/chief-of-staff.json +17 -0
  182. package/resources/ecc/agents/chief-of-staff.md +153 -0
  183. package/resources/ecc/agents/code-reviewer.json +16 -0
  184. package/resources/ecc/agents/code-reviewer.md +238 -0
  185. package/resources/ecc/agents/database-reviewer.json +16 -0
  186. package/resources/ecc/agents/database-reviewer.md +92 -0
  187. package/resources/ecc/agents/doc-updater.json +16 -0
  188. package/resources/ecc/agents/doc-updater.md +108 -0
  189. package/resources/ecc/agents/e2e-runner.json +17 -0
  190. package/resources/ecc/agents/e2e-runner.md +109 -0
  191. package/resources/ecc/agents/go-build-resolver.json +17 -0
  192. package/resources/ecc/agents/go-build-resolver.md +96 -0
  193. package/resources/ecc/agents/go-reviewer.json +16 -0
  194. package/resources/ecc/agents/go-reviewer.md +77 -0
  195. package/resources/ecc/agents/harness-optimizer.json +15 -0
  196. package/resources/ecc/agents/harness-optimizer.md +34 -0
  197. package/resources/ecc/agents/loop-operator.json +16 -0
  198. package/resources/ecc/agents/loop-operator.md +36 -0
  199. package/resources/ecc/agents/planner.json +15 -0
  200. package/resources/ecc/agents/planner.md +212 -0
  201. package/resources/ecc/agents/python-reviewer.json +16 -0
  202. package/resources/ecc/agents/python-reviewer.md +99 -0
  203. package/resources/ecc/agents/refactor-cleaner.json +17 -0
  204. package/resources/ecc/agents/refactor-cleaner.md +87 -0
  205. package/resources/ecc/agents/security-reviewer.json +16 -0
  206. package/resources/ecc/agents/security-reviewer.md +109 -0
  207. package/resources/ecc/agents/tdd-guide.json +17 -0
  208. package/resources/ecc/agents/tdd-guide.md +93 -0
  209. package/resources/ecc/commands/add-language-rules.md +39 -0
  210. package/resources/ecc/commands/database-migration.md +36 -0
  211. package/resources/ecc/commands/feature-development.md +38 -0
  212. package/resources/ecc/prompts/build-fix.prompt.md +47 -0
  213. package/resources/ecc/prompts/code-review.prompt.md +56 -0
  214. package/resources/ecc/prompts/plan.prompt.md +52 -0
  215. package/resources/ecc/prompts/refactor.prompt.md +50 -0
  216. package/resources/ecc/prompts/security-review.prompt.md +70 -0
  217. package/resources/ecc/prompts/tdd.prompt.md +47 -0
  218. package/resources/ecc/rules/common-agents.md +53 -0
  219. package/resources/ecc/rules/common-coding-style.md +52 -0
  220. package/resources/ecc/rules/common-development-workflow.md +33 -0
  221. package/resources/ecc/rules/common-git-workflow.md +28 -0
  222. package/resources/ecc/rules/common-hooks.md +34 -0
  223. package/resources/ecc/rules/common-patterns.md +35 -0
  224. package/resources/ecc/rules/common-performance.md +59 -0
  225. package/resources/ecc/rules/common-security.md +33 -0
  226. package/resources/ecc/rules/common-testing.md +33 -0
  227. package/resources/ecc/rules/golang-coding-style.md +31 -0
  228. package/resources/ecc/rules/golang-hooks.md +16 -0
  229. package/resources/ecc/rules/golang-patterns.md +44 -0
  230. package/resources/ecc/rules/golang-security.md +33 -0
  231. package/resources/ecc/rules/golang-testing.md +30 -0
  232. package/resources/ecc/rules/kotlin-coding-style.md +39 -0
  233. package/resources/ecc/rules/kotlin-hooks.md +16 -0
  234. package/resources/ecc/rules/kotlin-patterns.md +50 -0
  235. package/resources/ecc/rules/kotlin-security.md +58 -0
  236. package/resources/ecc/rules/kotlin-testing.md +38 -0
  237. package/resources/ecc/rules/php-coding-style.md +25 -0
  238. package/resources/ecc/rules/php-hooks.md +21 -0
  239. package/resources/ecc/rules/php-patterns.md +23 -0
  240. package/resources/ecc/rules/php-security.md +24 -0
  241. package/resources/ecc/rules/php-testing.md +26 -0
  242. package/resources/ecc/rules/python-coding-style.md +42 -0
  243. package/resources/ecc/rules/python-hooks.md +19 -0
  244. package/resources/ecc/rules/python-patterns.md +39 -0
  245. package/resources/ecc/rules/python-security.md +30 -0
  246. package/resources/ecc/rules/python-testing.md +38 -0
  247. package/resources/ecc/rules/swift-coding-style.md +47 -0
  248. package/resources/ecc/rules/swift-hooks.md +20 -0
  249. package/resources/ecc/rules/swift-patterns.md +66 -0
  250. package/resources/ecc/rules/swift-security.md +33 -0
  251. package/resources/ecc/rules/swift-testing.md +45 -0
  252. package/resources/ecc/rules/typescript-coding-style.md +63 -0
  253. package/resources/ecc/rules/typescript-hooks.md +20 -0
  254. package/resources/ecc/rules/typescript-patterns.md +50 -0
  255. package/resources/ecc/rules/typescript-security.md +26 -0
  256. package/resources/ecc/rules/typescript-testing.md +16 -0
  257. package/resources/ecc/skills/agent-introspection-debugging/SKILL.md +152 -0
  258. package/resources/ecc/skills/agent-introspection-debugging/agents/openai.yaml +7 -0
  259. package/resources/ecc/skills/agent-sort/SKILL.md +214 -0
  260. package/resources/ecc/skills/agent-sort/agents/openai.yaml +7 -0
  261. package/resources/ecc/skills/api-design/SKILL.md +522 -0
  262. package/resources/ecc/skills/api-design/agents/openai.yaml +7 -0
  263. package/resources/ecc/skills/article-writing/SKILL.md +78 -0
  264. package/resources/ecc/skills/article-writing/agents/openai.yaml +7 -0
  265. package/resources/ecc/skills/backend-patterns/SKILL.md +597 -0
  266. package/resources/ecc/skills/backend-patterns/agents/openai.yaml +7 -0
  267. package/resources/ecc/skills/brand-voice/SKILL.md +96 -0
  268. package/resources/ecc/skills/brand-voice/agents/openai.yaml +7 -0
  269. package/resources/ecc/skills/brand-voice/references/voice-profile-schema.md +55 -0
  270. package/resources/ecc/skills/bun-runtime/SKILL.md +83 -0
  271. package/resources/ecc/skills/bun-runtime/agents/openai.yaml +7 -0
  272. package/resources/ecc/skills/coding-standards/SKILL.md +548 -0
  273. package/resources/ecc/skills/coding-standards/agents/openai.yaml +7 -0
  274. package/resources/ecc/skills/content-engine/SKILL.md +130 -0
  275. package/resources/ecc/skills/content-engine/agents/openai.yaml +7 -0
  276. package/resources/ecc/skills/crosspost/SKILL.md +110 -0
  277. package/resources/ecc/skills/crosspost/agents/openai.yaml +7 -0
  278. package/resources/ecc/skills/deep-research/SKILL.md +154 -0
  279. package/resources/ecc/skills/deep-research/agents/openai.yaml +7 -0
  280. package/resources/ecc/skills/dmux-workflows/SKILL.md +143 -0
  281. package/resources/ecc/skills/dmux-workflows/agents/openai.yaml +7 -0
  282. package/resources/ecc/skills/documentation-lookup/SKILL.md +89 -0
  283. package/resources/ecc/skills/documentation-lookup/agents/openai.yaml +7 -0
  284. package/resources/ecc/skills/e2e-testing/SKILL.md +325 -0
  285. package/resources/ecc/skills/e2e-testing/agents/openai.yaml +7 -0
  286. package/resources/ecc/skills/eval-harness/SKILL.md +235 -0
  287. package/resources/ecc/skills/eval-harness/agents/openai.yaml +7 -0
  288. package/resources/ecc/skills/everything-claude-code/SKILL.md +442 -0
  289. package/resources/ecc/skills/everything-claude-code/agents/openai.yaml +7 -0
  290. package/resources/ecc/skills/exa-search/SKILL.md +169 -0
  291. package/resources/ecc/skills/exa-search/agents/openai.yaml +7 -0
  292. package/resources/ecc/skills/fal-ai-media/SKILL.md +276 -0
  293. package/resources/ecc/skills/fal-ai-media/agents/openai.yaml +7 -0
  294. package/resources/ecc/skills/frontend-patterns/SKILL.md +647 -0
  295. package/resources/ecc/skills/frontend-patterns/agents/openai.yaml +7 -0
  296. package/resources/ecc/skills/frontend-slides/SKILL.md +183 -0
  297. package/resources/ecc/skills/frontend-slides/STYLE_PRESETS.md +330 -0
  298. package/resources/ecc/skills/frontend-slides/agents/openai.yaml +7 -0
  299. package/resources/ecc/skills/investor-materials/SKILL.md +95 -0
  300. package/resources/ecc/skills/investor-materials/agents/openai.yaml +7 -0
  301. package/resources/ecc/skills/investor-outreach/SKILL.md +90 -0
  302. package/resources/ecc/skills/investor-outreach/agents/openai.yaml +7 -0
  303. package/resources/ecc/skills/market-research/SKILL.md +74 -0
  304. package/resources/ecc/skills/market-research/agents/openai.yaml +7 -0
  305. package/resources/ecc/skills/mcp-server-patterns/SKILL.md +66 -0
  306. package/resources/ecc/skills/mcp-server-patterns/agents/openai.yaml +7 -0
  307. package/resources/ecc/skills/mle-workflow/SKILL.md +346 -0
  308. package/resources/ecc/skills/mle-workflow/agents/openai.yaml +7 -0
  309. package/resources/ecc/skills/nextjs-turbopack/SKILL.md +43 -0
  310. package/resources/ecc/skills/nextjs-turbopack/agents/openai.yaml +7 -0
  311. package/resources/ecc/skills/product-capability/SKILL.md +140 -0
  312. package/resources/ecc/skills/product-capability/agents/openai.yaml +7 -0
  313. package/resources/ecc/skills/security-review/SKILL.md +494 -0
  314. package/resources/ecc/skills/security-review/agents/openai.yaml +7 -0
  315. package/resources/ecc/skills/strategic-compact/SKILL.md +102 -0
  316. package/resources/ecc/skills/strategic-compact/agents/openai.yaml +7 -0
  317. package/resources/ecc/skills/tdd-workflow/SKILL.md +409 -0
  318. package/resources/ecc/skills/tdd-workflow/agents/openai.yaml +7 -0
  319. package/resources/ecc/skills/verification-loop/SKILL.md +125 -0
  320. package/resources/ecc/skills/verification-loop/agents/openai.yaml +7 -0
  321. package/resources/ecc/skills/video-editing/SKILL.md +307 -0
  322. package/resources/ecc/skills/video-editing/agents/openai.yaml +7 -0
  323. package/resources/ecc/skills/x-api/SKILL.md +229 -0
  324. package/resources/ecc/skills/x-api/agents/openai.yaml +7 -0
@@ -0,0 +1,102 @@
1
+ ---
2
+ name: strategic-compact
3
+ description: Suggests manual context compaction at logical intervals to preserve context through task phases rather than arbitrary auto-compaction.
4
+ ---
5
+
6
+ # Strategic Compact Skill
7
+
8
+ Suggests manual `/compact` at strategic points in your workflow rather than relying on arbitrary auto-compaction.
9
+
10
+ ## When to Activate
11
+
12
+ - Running long sessions that approach context limits (200K+ tokens)
13
+ - Working on multi-phase tasks (research → plan → implement → test)
14
+ - Switching between unrelated tasks within the same session
15
+ - After completing a major milestone and starting new work
16
+ - When responses slow down or become less coherent (context pressure)
17
+
18
+ ## Why Strategic Compaction?
19
+
20
+ Auto-compaction triggers at arbitrary points:
21
+ - Often mid-task, losing important context
22
+ - No awareness of logical task boundaries
23
+ - Can interrupt complex multi-step operations
24
+
25
+ Strategic compaction at logical boundaries:
26
+ - **After exploration, before execution** — Compact research context, keep implementation plan
27
+ - **After completing a milestone** — Fresh start for next phase
28
+ - **Before major context shifts** — Clear exploration context before different task
29
+
30
+ ## How It Works
31
+
32
+ The `suggest-compact.js` script runs on PreToolUse (Edit/Write) and:
33
+
34
+ 1. **Tracks tool calls** — Counts tool invocations in session
35
+ 2. **Threshold detection** — Suggests at configurable threshold (default: 50 calls)
36
+ 3. **Periodic reminders** — Reminds every 25 calls after threshold
37
+
38
+ ## Hook Setup
39
+
40
+ Add to your `~/.claude/settings.json`:
41
+
42
+ ```json
43
+ {
44
+ "hooks": {
45
+ "PreToolUse": [
46
+ {
47
+ "matcher": "Edit",
48
+ "hooks": [{ "type": "command", "command": "node ~/.claude/skills/strategic-compact/suggest-compact.js" }]
49
+ },
50
+ {
51
+ "matcher": "Write",
52
+ "hooks": [{ "type": "command", "command": "node ~/.claude/skills/strategic-compact/suggest-compact.js" }]
53
+ }
54
+ ]
55
+ }
56
+ }
57
+ ```
58
+
59
+ ## Configuration
60
+
61
+ Environment variables:
62
+ - `COMPACT_THRESHOLD` — Tool calls before first suggestion (default: 50)
63
+
64
+ ## Compaction Decision Guide
65
+
66
+ Use this table to decide when to compact:
67
+
68
+ | Phase Transition | Compact? | Why |
69
+ |-----------------|----------|-----|
70
+ | Research → Planning | Yes | Research context is bulky; plan is the distilled output |
71
+ | Planning → Implementation | Yes | Plan is in TodoWrite or a file; free up context for code |
72
+ | Implementation → Testing | Maybe | Keep if tests reference recent code; compact if switching focus |
73
+ | Debugging → Next feature | Yes | Debug traces pollute context for unrelated work |
74
+ | Mid-implementation | No | Losing variable names, file paths, and partial state is costly |
75
+ | After a failed approach | Yes | Clear the dead-end reasoning before trying a new approach |
76
+
77
+ ## What Survives Compaction
78
+
79
+ Understanding what persists helps you compact with confidence:
80
+
81
+ | Persists | Lost |
82
+ |----------|------|
83
+ | CLAUDE.md instructions | Intermediate reasoning and analysis |
84
+ | TodoWrite task list | File contents you previously read |
85
+ | Memory files (`~/.claude/memory/`) | Multi-step conversation context |
86
+ | Git state (commits, branches) | Tool call history and counts |
87
+ | Files on disk | Nuanced user preferences stated verbally |
88
+
89
+ ## Best Practices
90
+
91
+ 1. **Compact after planning** — Once plan is finalized in TodoWrite, compact to start fresh
92
+ 2. **Compact after debugging** — Clear error-resolution context before continuing
93
+ 3. **Don't compact mid-implementation** — Preserve context for related changes
94
+ 4. **Read the suggestion** — The hook tells you *when*, you decide *if*
95
+ 5. **Write before compacting** — Save important context to files or memory before compacting
96
+ 6. **Use `/compact` with a summary** — Add a custom message: `/compact Focus on implementing auth middleware next`
97
+
98
+ ## Related
99
+
100
+ - [The Longform Guide](https://x.com/affaanmustafa/status/2014040193557471352) — Token optimization section
101
+ - Memory persistence hooks — For state that survives compaction
102
+ - `continuous-learning` skill — Extracts patterns before session ends
@@ -0,0 +1,7 @@
1
+ interface:
2
+ display_name: "Strategic Compact"
3
+ short_description: "Context management via strategic compaction"
4
+ brand_color: "#14B8A6"
5
+ default_prompt: "Use $strategic-compact to choose a useful context compaction boundary."
6
+ policy:
7
+ allow_implicit_invocation: true
@@ -0,0 +1,409 @@
1
+ ---
2
+ name: tdd-workflow
3
+ description: Use this skill when writing new features, fixing bugs, or refactoring code. Enforces test-driven development with 80%+ coverage including unit, integration, and E2E tests.
4
+ ---
5
+
6
+ # Test-Driven Development Workflow
7
+
8
+ This skill ensures all code development follows TDD principles with comprehensive test coverage.
9
+
10
+ ## When to Activate
11
+
12
+ - Writing new features or functionality
13
+ - Fixing bugs or issues
14
+ - Refactoring existing code
15
+ - Adding API endpoints
16
+ - Creating new components
17
+
18
+ ## Core Principles
19
+
20
+ ### 1. Tests BEFORE Code
21
+ ALWAYS write tests first, then implement code to make tests pass.
22
+
23
+ ### 2. Coverage Requirements
24
+ - Minimum 80% coverage (unit + integration + E2E)
25
+ - All edge cases covered
26
+ - Error scenarios tested
27
+ - Boundary conditions verified
28
+
29
+ ### 3. Test Types
30
+
31
+ #### Unit Tests
32
+ - Individual functions and utilities
33
+ - Component logic
34
+ - Pure functions
35
+ - Helpers and utilities
36
+
37
+ #### Integration Tests
38
+ - API endpoints
39
+ - Database operations
40
+ - Service interactions
41
+ - External API calls
42
+
43
+ #### E2E Tests (Playwright)
44
+ - Critical user flows
45
+ - Complete workflows
46
+ - Browser automation
47
+ - UI interactions
48
+
49
+ ## TDD Workflow Steps
50
+
51
+ ### Step 1: Write User Journeys
52
+ ```
53
+ As a [role], I want to [action], so that [benefit]
54
+
55
+ Example:
56
+ As a user, I want to search for markets semantically,
57
+ so that I can find relevant markets even without exact keywords.
58
+ ```
59
+
60
+ ### Step 2: Generate Test Cases
61
+ For each user journey, create comprehensive test cases:
62
+
63
+ ```typescript
64
+ describe('Semantic Search', () => {
65
+ it('returns relevant markets for query', async () => {
66
+ // Test implementation
67
+ })
68
+
69
+ it('handles empty query gracefully', async () => {
70
+ // Test edge case
71
+ })
72
+
73
+ it('falls back to substring search when Redis unavailable', async () => {
74
+ // Test fallback behavior
75
+ })
76
+
77
+ it('sorts results by similarity score', async () => {
78
+ // Test sorting logic
79
+ })
80
+ })
81
+ ```
82
+
83
+ ### Step 3: Run Tests (They Should Fail)
84
+ ```bash
85
+ npm test
86
+ # Tests should fail - we haven't implemented yet
87
+ ```
88
+
89
+ ### Step 4: Implement Code
90
+ Write minimal code to make tests pass:
91
+
92
+ ```typescript
93
+ // Implementation guided by tests
94
+ export async function searchMarkets(query: string) {
95
+ // Implementation here
96
+ }
97
+ ```
98
+
99
+ ### Step 5: Run Tests Again
100
+ ```bash
101
+ npm test
102
+ # Tests should now pass
103
+ ```
104
+
105
+ ### Step 6: Refactor
106
+ Improve code quality while keeping tests green:
107
+ - Remove duplication
108
+ - Improve naming
109
+ - Optimize performance
110
+ - Enhance readability
111
+
112
+ ### Step 7: Verify Coverage
113
+ ```bash
114
+ npm run test:coverage
115
+ # Verify 80%+ coverage achieved
116
+ ```
117
+
118
+ ## Testing Patterns
119
+
120
+ ### Unit Test Pattern (Jest/Vitest)
121
+ ```typescript
122
+ import { render, screen, fireEvent } from '@testing-library/react'
123
+ import { Button } from './Button'
124
+
125
+ describe('Button Component', () => {
126
+ it('renders with correct text', () => {
127
+ render(<Button>Click me</Button>)
128
+ expect(screen.getByText('Click me')).toBeInTheDocument()
129
+ })
130
+
131
+ it('calls onClick when clicked', () => {
132
+ const handleClick = jest.fn()
133
+ render(<Button onClick={handleClick}>Click</Button>)
134
+
135
+ fireEvent.click(screen.getByRole('button'))
136
+
137
+ expect(handleClick).toHaveBeenCalledTimes(1)
138
+ })
139
+
140
+ it('is disabled when disabled prop is true', () => {
141
+ render(<Button disabled>Click</Button>)
142
+ expect(screen.getByRole('button')).toBeDisabled()
143
+ })
144
+ })
145
+ ```
146
+
147
+ ### API Integration Test Pattern
148
+ ```typescript
149
+ import { NextRequest } from 'next/server'
150
+ import { GET } from './route'
151
+
152
+ describe('GET /api/markets', () => {
153
+ it('returns markets successfully', async () => {
154
+ const request = new NextRequest('http://localhost/api/markets')
155
+ const response = await GET(request)
156
+ const data = await response.json()
157
+
158
+ expect(response.status).toBe(200)
159
+ expect(data.success).toBe(true)
160
+ expect(Array.isArray(data.data)).toBe(true)
161
+ })
162
+
163
+ it('validates query parameters', async () => {
164
+ const request = new NextRequest('http://localhost/api/markets?limit=invalid')
165
+ const response = await GET(request)
166
+
167
+ expect(response.status).toBe(400)
168
+ })
169
+
170
+ it('handles database errors gracefully', async () => {
171
+ // Mock database failure
172
+ const request = new NextRequest('http://localhost/api/markets')
173
+ // Test error handling
174
+ })
175
+ })
176
+ ```
177
+
178
+ ### E2E Test Pattern (Playwright)
179
+ ```typescript
180
+ import { test, expect } from '@playwright/test'
181
+
182
+ test('user can search and filter markets', async ({ page }) => {
183
+ // Navigate to markets page
184
+ await page.goto('/')
185
+ await page.click('a[href="/markets"]')
186
+
187
+ // Verify page loaded
188
+ await expect(page.locator('h1')).toContainText('Markets')
189
+
190
+ // Search for markets
191
+ await page.fill('input[placeholder="Search markets"]', 'election')
192
+
193
+ // Wait for debounce and results
194
+ await page.waitForTimeout(600)
195
+
196
+ // Verify search results displayed
197
+ const results = page.locator('[data-testid="market-card"]')
198
+ await expect(results).toHaveCount(5, { timeout: 5000 })
199
+
200
+ // Verify results contain search term
201
+ const firstResult = results.first()
202
+ await expect(firstResult).toContainText('election', { ignoreCase: true })
203
+
204
+ // Filter by status
205
+ await page.click('button:has-text("Active")')
206
+
207
+ // Verify filtered results
208
+ await expect(results).toHaveCount(3)
209
+ })
210
+
211
+ test('user can create a new market', async ({ page }) => {
212
+ // Login first
213
+ await page.goto('/creator-dashboard')
214
+
215
+ // Fill market creation form
216
+ await page.fill('input[name="name"]', 'Test Market')
217
+ await page.fill('textarea[name="description"]', 'Test description')
218
+ await page.fill('input[name="endDate"]', '2025-12-31')
219
+
220
+ // Submit form
221
+ await page.click('button[type="submit"]')
222
+
223
+ // Verify success message
224
+ await expect(page.locator('text=Market created successfully')).toBeVisible()
225
+
226
+ // Verify redirect to market page
227
+ await expect(page).toHaveURL(/\/markets\/test-market/)
228
+ })
229
+ ```
230
+
231
+ ## Test File Organization
232
+
233
+ ```
234
+ src/
235
+ ├── components/
236
+ │ ├── Button/
237
+ │ │ ├── Button.tsx
238
+ │ │ ├── Button.test.tsx # Unit tests
239
+ │ │ └── Button.stories.tsx # Storybook
240
+ │ └── MarketCard/
241
+ │ ├── MarketCard.tsx
242
+ │ └── MarketCard.test.tsx
243
+ ├── app/
244
+ │ └── api/
245
+ │ └── markets/
246
+ │ ├── route.ts
247
+ │ └── route.test.ts # Integration tests
248
+ └── e2e/
249
+ ├── markets.spec.ts # E2E tests
250
+ ├── trading.spec.ts
251
+ └── auth.spec.ts
252
+ ```
253
+
254
+ ## Mocking External Services
255
+
256
+ ### Supabase Mock
257
+ ```typescript
258
+ jest.mock('@/lib/supabase', () => ({
259
+ supabase: {
260
+ from: jest.fn(() => ({
261
+ select: jest.fn(() => ({
262
+ eq: jest.fn(() => Promise.resolve({
263
+ data: [{ id: 1, name: 'Test Market' }],
264
+ error: null
265
+ }))
266
+ }))
267
+ }))
268
+ }
269
+ }))
270
+ ```
271
+
272
+ ### Redis Mock
273
+ ```typescript
274
+ jest.mock('@/lib/redis', () => ({
275
+ searchMarketsByVector: jest.fn(() => Promise.resolve([
276
+ { slug: 'test-market', similarity_score: 0.95 }
277
+ ])),
278
+ checkRedisHealth: jest.fn(() => Promise.resolve({ connected: true }))
279
+ }))
280
+ ```
281
+
282
+ ### OpenAI Mock
283
+ ```typescript
284
+ jest.mock('@/lib/openai', () => ({
285
+ generateEmbedding: jest.fn(() => Promise.resolve(
286
+ new Array(1536).fill(0.1) // Mock 1536-dim embedding
287
+ ))
288
+ }))
289
+ ```
290
+
291
+ ## Test Coverage Verification
292
+
293
+ ### Run Coverage Report
294
+ ```bash
295
+ npm run test:coverage
296
+ ```
297
+
298
+ ### Coverage Thresholds
299
+ ```json
300
+ {
301
+ "jest": {
302
+ "coverageThresholds": {
303
+ "global": {
304
+ "branches": 80,
305
+ "functions": 80,
306
+ "lines": 80,
307
+ "statements": 80
308
+ }
309
+ }
310
+ }
311
+ }
312
+ ```
313
+
314
+ ## Common Testing Mistakes to Avoid
315
+
316
+ ### FAIL: WRONG: Testing Implementation Details
317
+ ```typescript
318
+ // Don't test internal state
319
+ expect(component.state.count).toBe(5)
320
+ ```
321
+
322
+ ### PASS: CORRECT: Test User-Visible Behavior
323
+ ```typescript
324
+ // Test what users see
325
+ expect(screen.getByText('Count: 5')).toBeInTheDocument()
326
+ ```
327
+
328
+ ### FAIL: WRONG: Brittle Selectors
329
+ ```typescript
330
+ // Breaks easily
331
+ await page.click('.css-class-xyz')
332
+ ```
333
+
334
+ ### PASS: CORRECT: Semantic Selectors
335
+ ```typescript
336
+ // Resilient to changes
337
+ await page.click('button:has-text("Submit")')
338
+ await page.click('[data-testid="submit-button"]')
339
+ ```
340
+
341
+ ### FAIL: WRONG: No Test Isolation
342
+ ```typescript
343
+ // Tests depend on each other
344
+ test('creates user', () => { /* ... */ })
345
+ test('updates same user', () => { /* depends on previous test */ })
346
+ ```
347
+
348
+ ### PASS: CORRECT: Independent Tests
349
+ ```typescript
350
+ // Each test sets up its own data
351
+ test('creates user', () => {
352
+ const user = createTestUser()
353
+ // Test logic
354
+ })
355
+
356
+ test('updates user', () => {
357
+ const user = createTestUser()
358
+ // Update logic
359
+ })
360
+ ```
361
+
362
+ ## Continuous Testing
363
+
364
+ ### Watch Mode During Development
365
+ ```bash
366
+ npm test -- --watch
367
+ # Tests run automatically on file changes
368
+ ```
369
+
370
+ ### Pre-Commit Hook
371
+ ```bash
372
+ # Runs before every commit
373
+ npm test && npm run lint
374
+ ```
375
+
376
+ ### CI/CD Integration
377
+ ```yaml
378
+ # GitHub Actions
379
+ - name: Run Tests
380
+ run: npm test -- --coverage
381
+ - name: Upload Coverage
382
+ uses: codecov/codecov-action@v3
383
+ ```
384
+
385
+ ## Best Practices
386
+
387
+ 1. **Write Tests First** - Always TDD
388
+ 2. **One Assert Per Test** - Focus on single behavior
389
+ 3. **Descriptive Test Names** - Explain what's tested
390
+ 4. **Arrange-Act-Assert** - Clear test structure
391
+ 5. **Mock External Dependencies** - Isolate unit tests
392
+ 6. **Test Edge Cases** - Null, undefined, empty, large
393
+ 7. **Test Error Paths** - Not just happy paths
394
+ 8. **Keep Tests Fast** - Unit tests < 50ms each
395
+ 9. **Clean Up After Tests** - No side effects
396
+ 10. **Review Coverage Reports** - Identify gaps
397
+
398
+ ## Success Metrics
399
+
400
+ - 80%+ code coverage achieved
401
+ - All tests passing (green)
402
+ - No skipped or disabled tests
403
+ - Fast test execution (< 30s for unit tests)
404
+ - E2E tests cover critical user flows
405
+ - Tests catch bugs before production
406
+
407
+ ---
408
+
409
+ **Remember**: Tests are not optional. They are the safety net that enables confident refactoring, rapid development, and production reliability.
@@ -0,0 +1,7 @@
1
+ interface:
2
+ display_name: "TDD Workflow"
3
+ short_description: "Test-driven development with coverage gates"
4
+ brand_color: "#22C55E"
5
+ default_prompt: "Use $tdd-workflow to drive the change with tests before implementation."
6
+ policy:
7
+ allow_implicit_invocation: true
@@ -0,0 +1,125 @@
1
+ ---
2
+ name: verification-loop
3
+ description: "A comprehensive verification system for Claude Code sessions."
4
+ ---
5
+
6
+ # Verification Loop Skill
7
+
8
+ A comprehensive verification system for Claude Code sessions.
9
+
10
+ ## When to Use
11
+
12
+ Invoke this skill:
13
+ - After completing a feature or significant code change
14
+ - Before creating a PR
15
+ - When you want to ensure quality gates pass
16
+ - After refactoring
17
+
18
+ ## Verification Phases
19
+
20
+ ### Phase 1: Build Verification
21
+ ```bash
22
+ # Check if project builds
23
+ npm run build 2>&1 | tail -20
24
+ # OR
25
+ pnpm build 2>&1 | tail -20
26
+ ```
27
+
28
+ If build fails, STOP and fix before continuing.
29
+
30
+ ### Phase 2: Type Check
31
+ ```bash
32
+ # TypeScript projects
33
+ npx tsc --noEmit 2>&1 | head -30
34
+
35
+ # Python projects
36
+ pyright . 2>&1 | head -30
37
+ ```
38
+
39
+ Report all type errors. Fix critical ones before continuing.
40
+
41
+ ### Phase 3: Lint Check
42
+ ```bash
43
+ # JavaScript/TypeScript
44
+ npm run lint 2>&1 | head -30
45
+
46
+ # Python
47
+ ruff check . 2>&1 | head -30
48
+ ```
49
+
50
+ ### Phase 4: Test Suite
51
+ ```bash
52
+ # Run tests with coverage
53
+ npm run test -- --coverage 2>&1 | tail -50
54
+
55
+ # Check coverage threshold
56
+ # Target: 80% minimum
57
+ ```
58
+
59
+ Report:
60
+ - Total tests: X
61
+ - Passed: X
62
+ - Failed: X
63
+ - Coverage: X%
64
+
65
+ ### Phase 5: Security Scan
66
+ ```bash
67
+ # Check for secrets
68
+ grep -rn "sk-" --include="*.ts" --include="*.js" . 2>/dev/null | head -10
69
+ grep -rn "api_key" --include="*.ts" --include="*.js" . 2>/dev/null | head -10
70
+
71
+ # Check for console.log
72
+ grep -rn "console.log" --include="*.ts" --include="*.tsx" src/ 2>/dev/null | head -10
73
+ ```
74
+
75
+ ### Phase 6: Diff Review
76
+ ```bash
77
+ # Show what changed
78
+ git diff --stat
79
+ git diff HEAD~1 --name-only
80
+ ```
81
+
82
+ Review each changed file for:
83
+ - Unintended changes
84
+ - Missing error handling
85
+ - Potential edge cases
86
+
87
+ ## Output Format
88
+
89
+ After running all phases, produce a verification report:
90
+
91
+ ```
92
+ VERIFICATION REPORT
93
+ ==================
94
+
95
+ Build: [PASS/FAIL]
96
+ Types: [PASS/FAIL] (X errors)
97
+ Lint: [PASS/FAIL] (X warnings)
98
+ Tests: [PASS/FAIL] (X/Y passed, Z% coverage)
99
+ Security: [PASS/FAIL] (X issues)
100
+ Diff: [X files changed]
101
+
102
+ Overall: [READY/NOT READY] for PR
103
+
104
+ Issues to Fix:
105
+ 1. ...
106
+ 2. ...
107
+ ```
108
+
109
+ ## Continuous Mode
110
+
111
+ For long sessions, run verification every 15 minutes or after major changes:
112
+
113
+ ```markdown
114
+ Set a mental checkpoint:
115
+ - After completing each function
116
+ - After finishing a component
117
+ - Before moving to next task
118
+
119
+ Run: /verify
120
+ ```
121
+
122
+ ## Integration with Hooks
123
+
124
+ This skill complements PostToolUse hooks but provides deeper verification.
125
+ Hooks catch issues immediately; this skill provides comprehensive review.
@@ -0,0 +1,7 @@
1
+ interface:
2
+ display_name: "Verification Loop"
3
+ short_description: "Build, test, lint, and typecheck verification"
4
+ brand_color: "#10B981"
5
+ default_prompt: "Use $verification-loop to run build, test, lint, and typecheck verification."
6
+ policy:
7
+ allow_implicit_invocation: true