@tyvm/knowhow 0.0.109 → 0.0.110

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 (94) hide show
  1. package/autodoc/README.md +324 -0
  2. package/autodoc/chat-guide.md +268 -365
  3. package/autodoc/cli-reference.md +399 -473
  4. package/autodoc/config-reference.md +431 -330
  5. package/autodoc/embeddings-guide.md +223 -322
  6. package/autodoc/generate-guide.md +261 -301
  7. package/autodoc/language-plugin-guide.md +221 -247
  8. package/autodoc/modules-guide.md +242 -215
  9. package/autodoc/plugins-guide.md +470 -469
  10. package/autodoc/quickstart-guide.md +67 -70
  11. package/autodoc/skills-guide.md +455 -339
  12. package/autodoc/worker-guide.md +301 -308
  13. package/package.json +1 -1
  14. package/scripts/build-for-node.sh +10 -24
  15. package/src/agents/tools/list.ts +2 -2
  16. package/src/ai.ts +81 -37
  17. package/src/chat/CliChatService.ts +1 -1
  18. package/src/chat/modules/AgentModule.ts +7 -2
  19. package/src/chat/modules/SessionsModule.ts +40 -1
  20. package/src/chat/modules/SystemModule.ts +2 -2
  21. package/src/clients/anthropic.ts +1 -1
  22. package/src/clients/index.ts +25 -6
  23. package/src/clients/openai.ts +8 -5
  24. package/src/clients/types.ts +29 -6
  25. package/src/clients/withRetry.ts +89 -0
  26. package/src/commands/agent.ts +30 -0
  27. package/src/commands/modules.ts +417 -47
  28. package/src/config.ts +1 -1
  29. package/src/fileSync.ts +20 -12
  30. package/src/hashes.ts +43 -22
  31. package/src/index.ts +4 -2
  32. package/src/processors/Base64ImageDetector.ts +73 -0
  33. package/src/services/MediaProcessorService.ts +79 -10
  34. package/src/services/modules/index.ts +47 -18
  35. package/tests/processors/Base64ImageDetector.test.ts +160 -0
  36. package/tests/unit/clients/AIClient.test.ts +446 -0
  37. package/tests/unit/clients/withRetry.test.ts +319 -0
  38. package/tests/unit/commands/github-credentials.test.ts +1 -2
  39. package/ts_build/package.json +1 -1
  40. package/ts_build/src/agents/tools/list.js +2 -2
  41. package/ts_build/src/agents/tools/list.js.map +1 -1
  42. package/ts_build/src/ai.d.ts +3 -3
  43. package/ts_build/src/ai.js +51 -23
  44. package/ts_build/src/ai.js.map +1 -1
  45. package/ts_build/src/chat/CliChatService.js +1 -1
  46. package/ts_build/src/chat/CliChatService.js.map +1 -1
  47. package/ts_build/src/chat/modules/AgentModule.js +5 -2
  48. package/ts_build/src/chat/modules/AgentModule.js.map +1 -1
  49. package/ts_build/src/chat/modules/SessionsModule.js +30 -1
  50. package/ts_build/src/chat/modules/SessionsModule.js.map +1 -1
  51. package/ts_build/src/chat/modules/SystemModule.js +2 -2
  52. package/ts_build/src/chat/modules/SystemModule.js.map +1 -1
  53. package/ts_build/src/clients/anthropic.js +1 -1
  54. package/ts_build/src/clients/anthropic.js.map +1 -1
  55. package/ts_build/src/clients/index.js +7 -6
  56. package/ts_build/src/clients/index.js.map +1 -1
  57. package/ts_build/src/clients/openai.js +4 -4
  58. package/ts_build/src/clients/openai.js.map +1 -1
  59. package/ts_build/src/clients/types.d.ts +12 -6
  60. package/ts_build/src/clients/withRetry.d.ts +2 -0
  61. package/ts_build/src/clients/withRetry.js +60 -0
  62. package/ts_build/src/clients/withRetry.js.map +1 -0
  63. package/ts_build/src/commands/agent.js +25 -0
  64. package/ts_build/src/commands/agent.js.map +1 -1
  65. package/ts_build/src/commands/modules.js +359 -32
  66. package/ts_build/src/commands/modules.js.map +1 -1
  67. package/ts_build/src/config.js +1 -1
  68. package/ts_build/src/config.js.map +1 -1
  69. package/ts_build/src/fileSync.d.ts +2 -2
  70. package/ts_build/src/fileSync.js +13 -11
  71. package/ts_build/src/fileSync.js.map +1 -1
  72. package/ts_build/src/hashes.d.ts +2 -2
  73. package/ts_build/src/hashes.js +40 -16
  74. package/ts_build/src/hashes.js.map +1 -1
  75. package/ts_build/src/index.js +1 -1
  76. package/ts_build/src/index.js.map +1 -1
  77. package/ts_build/src/processors/Base64ImageDetector.d.ts +3 -0
  78. package/ts_build/src/processors/Base64ImageDetector.js +42 -0
  79. package/ts_build/src/processors/Base64ImageDetector.js.map +1 -1
  80. package/ts_build/src/services/MediaProcessorService.d.ts +5 -4
  81. package/ts_build/src/services/MediaProcessorService.js +53 -8
  82. package/ts_build/src/services/MediaProcessorService.js.map +1 -1
  83. package/ts_build/src/services/modules/index.js +35 -12
  84. package/ts_build/src/services/modules/index.js.map +1 -1
  85. package/ts_build/tests/processors/Base64ImageDetector.test.js +111 -0
  86. package/ts_build/tests/processors/Base64ImageDetector.test.js.map +1 -1
  87. package/ts_build/tests/unit/clients/AIClient.test.d.ts +1 -0
  88. package/ts_build/tests/unit/clients/AIClient.test.js +339 -0
  89. package/ts_build/tests/unit/clients/AIClient.test.js.map +1 -0
  90. package/ts_build/tests/unit/clients/withRetry.test.d.ts +1 -0
  91. package/ts_build/tests/unit/clients/withRetry.test.js +225 -0
  92. package/ts_build/tests/unit/clients/withRetry.test.js.map +1 -0
  93. package/ts_build/tests/unit/commands/github-credentials.test.js +1 -2
  94. package/ts_build/tests/unit/commands/github-credentials.test.js.map +1 -1
@@ -1,468 +1,584 @@
1
- ```md
2
1
  # Skills Guide (Knowhow CLI)
3
2
 
4
3
  ## 1) What skills are
5
4
 
6
- **Skills** are reusable instruction sets stored in files named **`SKILL.md`**.
5
+ **Skills** are reusable instruction bundles stored in files named **`SKILL.md`**.
6
+ When a user asks for something that matches a skill’s **name**, Knowhow automatically loads that skill’s full markdown content and provides it as context to the agent.
7
+
8
+ A skill file is ordinary markdown, but it includes **frontmatter metadata** at the top:
7
9
 
8
- When a user’s request mentions the *skill name*, Knowhow loads the matching **full `SKILL.md` content** and injects it into the agent context, so the agent follows your standardized procedure (checklists, commands, rollback plans, etc.).
10
+ - `name` the skill trigger name (must match what users say)
11
+ - `description` — a short summary shown during “skill discovery”
12
+ - **Body** — the complete instructions the agent should follow
9
13
 
10
- Each `SKILL.md` file must include **frontmatter metadata** at the top so Knowhow can identify and match the skill.
14
+ **File naming rule:** the plugin scans for files literally named **`SKILL.md`** (case-sensitive on most systems).
11
15
 
12
16
  ---
13
17
 
14
- ## 2) How skills work (SkillsPlugin behavior)
15
-
16
- Knowhow’s **Skills Plugin** (`src/plugins/SkillsPlugin.ts`) works as follows:
17
-
18
- 1. **Reads configuration** via `getConfig()`.
19
- 2. Loads the configured **skills directories** from `knowhow.json` under a `skills` array.
20
- 3. **Recursively scans** each directory:
21
- - Searches for any file named **exactly** `SKILL.md`
22
- - Uses recursive directory traversal (`readdir` + recursion)
23
- 4. **Parses frontmatter** from each `SKILL.md`:
24
- - Frontmatter must start with:
25
- ```md
26
- ---
27
- ...
28
- ---
18
+ ## 2) How skills work
19
+
20
+ ### What the SkillsPlugin does
21
+ Knowhow’s **Skills Plugin** (`src/plugins/SkillsPlugin.ts`) performs three steps:
22
+
23
+ 1. **Load config**
24
+ - Reads `.knowhow/knowhow.json` via `getConfig()`
25
+ - Looks for a `skills` array:
26
+ ```json
27
+ {
28
+ "skills": ["some/directory", "..."]
29
+ }
29
30
  ```
30
- - Each frontmatter line is parsed by splitting on the first `:` to extract fields like:
31
- - `name: ...`
32
- - `description: ...`
33
- 5. **Matches skills to the user prompt** using substring logic:
34
- ```ts
35
- userPrompt.toLowerCase().includes(skill.name.toLowerCase())
36
- ```
37
- **Important implication:** matching is **not exact**—it uses `includes()`.
38
- - If your skill `name` is `deploy`, it may trigger on: “deploy”, “redeploy”, “deployment”, “deploying”.
39
-
40
- 6. **If one or more skills match**:
41
- - The plugin reads each matched `SKILL.md` file
42
- - It injects content into the agent context in a wrapper:
43
- - Prepends:
44
- - `## Skill: <name>`
45
- - `File: <filePath>`
46
- - Then includes the **entire `SKILL.md` file content**.
47
-
48
- 7. **If no skill name matches**:
49
- - The plugin returns a **skills discovery summary** listing each discovered skill:
50
- - skill name
51
- - file path
52
- - description
53
- - This summary is injected as context so the user can reference the correct skill name.
54
31
 
55
- ---
32
+ 2. **Scan skill directories**
33
+ - For each directory in `skills`, it:
34
+ - Expands `~` to `process.env.HOME`
35
+ - Recursively searches all subdirectories
36
+ - Finds files named `SKILL.md`
37
+ - Reads each file and extracts frontmatter `name` + `description`
38
+ - Each skill is indexed as:
39
+ - `name`
40
+ - `description`
41
+ - `filePath`
42
+
43
+ 3. **Match user input to skills**
44
+ - If the user prompt contains a skill name **as a substring** (case-insensitive), e.g.:
45
+ - user: “Please do a **database migration**”
46
+ - skill name: “database migration”
47
+ - Then the plugin loads the **entire SKILL.md content** for every matched skill.
48
+
49
+ ### What gets injected into the agent
50
+ For each matched skill, the plugin returns a block like:
56
51
 
57
- ## 3) `SKILL.md` format
52
+ ```md
53
+ ## Skill: <skill.name>
54
+ File: <skill.filePath>
58
55
 
59
- A `SKILL.md` file must contain:
56
+ <full SKILL.md content>
57
+ ```
60
58
 
61
- ### Required frontmatter fields
62
- - `name` — the skill name (must match what users are likely to say; see substring matching)
63
- - `description` — a short description shown during discovery
59
+ If multiple skills match, the plugin provides multiple blocks.
64
60
 
65
- ### Body content
66
- Everything after frontmatter is the full instruction set. The plugin injects the **entire file** into context when the skill matches.
61
+ ### Skill discovery behavior (no matches)
62
+ If **no** skill name is found in the user prompt, the plugin returns a **summary**:
67
63
 
68
- ### Full template
69
- ```md
70
- ---
71
- name: <skill name>
72
- description: <short description>
73
- ---
64
+ - “Available skills:”
65
+ - Each skill listed as:
66
+ - `- <name> (<filePath>): <description>`
67
+ - Plus a reminder:
68
+ - “To use a skill, reference its name in your request and I will load the full instructions.”
74
69
 
75
- # <Section title>
70
+ So users can learn what skills exist by asking something that doesn’t match any skill name.
76
71
 
77
- Step-by-step instructions...
72
+ ---
78
73
 
79
- ## Examples
80
- ...
74
+ ## 3) `SKILL.md` format
81
75
 
82
- ## Edge cases / gotchas
83
- ...
84
- ```
76
+ A skill file must follow this structure:
85
77
 
86
- ### Frontmatter example
87
78
  ```md
88
79
  ---
89
- name: deploy
90
- description: Deploy an application safely with verification and rollback steps.
80
+ name: <skill name>
81
+ description: <short description>
91
82
  ---
83
+
84
+ <instructions and examples here>
92
85
  ```
93
86
 
87
+ ### Frontmatter rules (important)
88
+ From the plugin’s `parseFrontmatter()` implementation:
89
+
90
+ - It expects frontmatter to begin at the **start** of the file with:
91
+ - `---` then newline
92
+ - It captures content until the next `---`
93
+ - Each frontmatter line is parsed as:
94
+ - `key: <value>`
95
+ - If a value contains `:` characters, they are preserved because the parser:
96
+ - splits on the first `:`
97
+ - rejoins the rest
98
+
99
+ ### Body content
100
+ Everything after the closing `---` is treated as the **full skill instructions** and gets injected into the agent context.
101
+
94
102
  ---
95
103
 
96
104
  ## 4) Configuring skills
97
105
 
98
- Add your skill directories to `knowhow.json` using a `skills` array.
106
+ Add a `skills` array in your `knowhow.json`:
99
107
 
100
- Example:
108
+ ### Example: local project config
109
+ `.knowhow/knowhow.json`
101
110
  ```json
102
111
  {
103
- "plugins": {
104
- "skills": true
105
- },
106
112
  "skills": [
107
- "./skills",
108
- "~/.knowhow/skills"
113
+ ".knowhow/skills",
114
+ "skills"
109
115
  ]
110
116
  }
111
117
  ```
112
118
 
113
- Notes:
114
- - Paths may be relative or absolute.
115
- - `~` is expanded using the user’s home directory (`process.env.HOME`).
116
- - The plugin scans **recursively**, so `./skills/<any-folders>/SKILL.md` is fine.
119
+ **Notes**
120
+ - Directories are scanned **recursively**
121
+ - Every `SKILL.md` found contributes a skill
122
+ - Unreadable/missing directories are ignored
123
+
124
+ ### Path shorthand
125
+ The plugin supports `~`:
126
+ - `~/some/path` → resolved using `process.env.HOME`
117
127
 
118
128
  ---
119
129
 
120
- ## 5) Skill discovery (when no skill matches)
130
+ ## 5) Skill discovery
121
131
 
122
- If the user request does **not** contain any skill name, Knowhow injects a context item like:
132
+ If a user’s request does **not** include any configured skill names (as substring matches), the agent will receive the plugin’s “Available skills” summary.
123
133
 
124
- - **`Available skills:`**
125
- - `- <name> (<filePath>): <description>`
134
+ To get a skill loaded, the user must:
135
+ - mention the skill name **in the request text**
136
+ - in any casing (the match is case-insensitive)
126
137
 
127
- …and then suggests the user reference a skill by name.
128
-
129
- **Author takeaway:** choose `name` values that users will naturally include in their requests.
138
+ **Tip:** choose `name` strings that users will naturally include verbatim (e.g., “code review”, “deploy”, “database migration”).
130
139
 
131
140
  ---
132
141
 
133
142
  ## 6) Writing effective skills (best practices)
134
143
 
135
- ### A) Use clear, natural `name` values
136
- Because matching is substring-based (`includes()`), avoid names that are likely to match unintentionally.
144
+ ### A) Use a clear, human-friendly `name`
145
+ - Pick wording users are likely to type.
146
+ - Keep it consistent and not overly broad.
147
+ - Avoid punctuation-heavy names; they are harder to match reliably.
148
+
149
+ ### B) Put the most important instructions early
150
+ Agents work better when:
151
+ - prerequisites and scope are near the top
152
+ - steps are structured and scannable
153
+
154
+ ### C) Use step-by-step structure
155
+ Prefer numbered lists, short sections, and checklists.
137
156
 
138
- - Good: `deploy`, `code review`, `database migration`
139
- - ⚠️ Risky: `run`, `update`, `manage`, `test` (may trigger on many unrelated phrases)
157
+ ### D) Include code examples and templates
158
+ If the skill involves commands, configs, queries, or scripts:
159
+ - provide copy/paste examples
160
+ - show placeholders clearly (e.g., `<SERVICE>`, `<ENV>`)
140
161
 
141
- ### B) Write step-by-step instructions
142
- Use numbered/structured steps with decision points, e.g.:
143
- - “If you have X, do A; otherwise do B.”
162
+ ### E) Handle edge cases explicitly
163
+ Include a section like:
164
+ - “Edge cases / when to stop”
165
+ - “Common pitfalls”
166
+ - “If you lack access/inputs, ask these questions”
144
167
 
145
- ### C) Include copy/paste-ready code examples
146
- Provide exact commands/snippets with clear placeholders:
147
- - `APP_NAME`, `NAMESPACE`, `RELEASE_TAG`, `MIGRATION_NAME`, etc.
168
+ ### F) Match the plugin’s matching behavior
169
+ Because the plugin triggers when:
170
+ - `userPrompt.toLowerCase().includes(skill.name.toLowerCase())`
148
171
 
149
- ### D) Cover edge cases and failure modes
150
- Add sections such as:
151
- - Common failures
152
- - Rollback plan
153
- - Verification steps
154
- - What to do if an environment variable is missing
155
- - What to do if a deployment health check fails
172
+ …avoid names that require exact formatting users won’t reproduce.
156
173
 
157
- ### E) Make the “success criteria” explicit
158
- Tell the agent what “done” means:
159
- - expected outputs
160
- - checklist completion
161
- - verification queries/commands that must pass
174
+ **Example:** If you name a skill `DB migrate`, users may type `database migration` instead and won’t match. Prefer a common phrase.
162
175
 
163
176
  ---
164
177
 
165
178
  ## 7) Example skills (complete `SKILL.md` files)
166
179
 
167
- Below are complete, copyable examples. Save each as **`SKILL.md`** inside a directory included by your `skills` config.
180
+ Below are **complete** examples you can place in directories scanned by your `skills` config.
168
181
 
169
- ---
170
-
171
- ### Example 1: `deploy` skill
182
+ ### Example A: `deploy` skill
172
183
 
173
- **File:** `./skills/deploy/SKILL.md`
184
+ **File:** `.knowhow/skills/deploy/SKILL.md` (path arbitrary; filename must be `SKILL.md`)
174
185
  ```md
175
186
  ---
176
187
  name: deploy
177
- description: Deploy an application safely with verification and rollback steps.
188
+ description: Deploy an application safely using a repeatable, checklist-driven process (plan, validate, release, verify, rollback).
178
189
  ---
179
190
 
180
191
  # Deploy Skill
181
192
 
182
- Use this checklist to deploy an application reliably. Tailor steps to your stack (Node/Python/Go/etc.), but keep the flow the same.
183
-
184
- ## 1) Pre-deploy verification
185
- 1. Confirm the target environment:
186
- - `dev`, `staging`, or `production`
187
- 2. Confirm the artifact/version to deploy:
188
- - Commit SHA or release tag
189
- 3. Confirm required secrets/config exist:
190
- - API keys
191
- - database connection strings
192
- - environment variables required by the app
193
-
194
- ## 2) Readiness checks
195
- 1. Check current health:
196
- - Ensure the service is reachable
197
- 2. Check recent errors:
198
- - Look for failing pods/services/jobs
199
- 3. Estimate downtime expectations:
200
- - Can deployments be zero-downtime?
201
-
202
- ## 3) Deploy procedure (generic)
203
- 1. Backup/ensure rollback readiness
204
- - If using containers: ensure you can redeploy the previous image tag
205
- 2. Deploy the new artifact
206
- - Update deployment manifest / pipeline configuration
207
- 3. Apply changes
208
- - Run CI/CD or execute deployment commands (examples below)
209
-
210
- ### Example: Kubernetes rollout
193
+ Use this skill to guide a safe deployment for a typical web/service app. Adapt steps to your stack (Kubernetes, systemd, Heroku, Docker Compose, etc.).
194
+
195
+ ## Inputs to request (if missing)
196
+ If the user did not provide these, ask:
197
+ 1. Deployment target (e.g., `staging`, `production`, a specific environment name)
198
+ 2. Release artifact (e.g., docker image tag, build number, commit SHA)
199
+ 3. Deployment method/tooling (e.g., Helm, kubectl, Terraform, SSH scripts, GitHub Actions)
200
+ 4. Any required approvals or maintenance windows
201
+ 5. Current rollback strategy
202
+
203
+ ## Step-by-step deployment process
204
+
205
+ ### 1) Plan & confirm scope
206
+ - Identify what will change:
207
+ - code changes
208
+ - config changes
209
+ - infrastructure changes
210
+ - Confirm:
211
+ - target environment
212
+ - expected downtime (if any)
213
+ - dependencies (databases, queues, caches)
214
+
215
+ ### 2) Pre-deploy validation
216
+ - Verify health of the current environment:
217
+ - uptime/error rates
218
+ - logs for obvious incidents
219
+ - Confirm required secrets/configs exist for the target environment.
220
+ - If migrations are involved, identify:
221
+ - migration ordering and whether they are backward-compatible
222
+
223
+ ### 3) Choose a release strategy
224
+ Pick one:
225
+ - **Blue/Green** (preferred for minimal disruption)
226
+ - **Rolling** (common for Kubernetes/stateful services)
227
+ - **Canary** (gradual traffic shift)
228
+ - **Restart-based** (simpler but higher risk)
229
+
230
+ State which one you will use and why.
231
+
232
+ ### 4) Execute deployment
233
+ Provide the exact commands/steps for the user’s stack.
234
+
235
+ #### Kubernetes/Helm template
211
236
  ```bash
212
- kubectl config use-context <context>
213
- kubectl set image deployment/<app> <container>=<image>:<tag> -n <namespace>
214
- kubectl rollout status deployment/<app> -n <namespace> --timeout=5m
237
+ # Example variables:
238
+ # RELEASE=<release-name>
239
+ # NAMESPACE=<namespace>
240
+ # CHART=<chart-dir-or-name>
241
+ # IMAGE_TAG=<tag>
242
+
243
+ helm upgrade --install "$RELEASE" "$CHART" \
244
+ --namespace "$NAMESPACE" \
245
+ --set image.tag="$IMAGE_TAG"
215
246
  ```
216
247
 
217
- ### Example: Docker Compose
248
+ #### Docker Compose template
218
249
  ```bash
219
- export IMAGE_TAG="<tag>"
250
+ # Example:
251
+ # IMAGE_TAG=<tag>
252
+ export IMAGE_TAG="$IMAGE_TAG"
253
+
220
254
  docker compose pull
221
- docker compose up -d
222
- docker compose ps
255
+ docker compose up -d --no-deps
223
256
  ```
224
257
 
225
- ## 4) Post-deploy verification
226
- 1. Health endpoints
227
- - Verify `/health` or equivalent returns 200
228
- 2. Smoke tests
229
- - Login flow (if applicable)
230
- - Minimal read/write operation
231
- 3. Check logs for startup errors
232
- - Look for crashes, migrations failing, missing env vars
233
-
234
- ## 5) Rollback plan (define before you need it)
235
- If verification fails:
236
- 1. Identify the previous version/image
237
- 2. Roll back
238
- - Kubernetes:
239
- ```bash
240
- kubectl rollout undo deployment/<app> -n <namespace>
241
- kubectl rollout status deployment/<app> -n <namespace> --timeout=5m
242
- ```
243
- - Compose/Docker:
244
- ```bash
245
- export IMAGE_TAG="<previous-tag>"
246
- docker compose up -d
247
- ```
248
-
249
- ## 6) Report the outcome
250
- Provide:
251
- - Environment name
252
- - Version/artifact deployed
253
- - Verification results (what succeeded)
254
- - Any follow-up tasks or incidents
258
+ ### 5) Post-deploy verification (must-do)
259
+ After the deploy completes:
260
+ - Check application health endpoints
261
+ - Confirm critical workflows:
262
+ - login/session
263
+ - primary read/write operations
264
+ - queue consumers / background jobs (if applicable)
265
+ - Monitor logs for errors for at least **10–15 minutes** (or the team’s standard)
266
+
267
+ ### 6) Communicate & close out
268
+ Report:
269
+ - what changed
270
+ - verification results
271
+ - link(s) to release notes/build artifacts
272
+ - next steps (if any)
273
+
274
+ ## Rollback plan (include before executing)
275
+ Before the deployment, define rollback triggers:
276
+ - error budget exceeded
277
+ - health checks failing
278
+ - latency spike
279
+ - incident detected
280
+
281
+ Provide concrete rollback actions, e.g.:
282
+ - Helm rollback to previous revision:
283
+ ```bash
284
+ helm rollback "$RELEASE" <revision-number> --namespace "$NAMESPACE"
285
+ ```
286
+ - Or redeploy prior image tag.
287
+
288
+ ## Edge cases / stop conditions
289
+ - Stop and ask questions if:
290
+ - you don’t know the release artifact
291
+ - there are pending schema changes without a migration plan
292
+ - rollback strategy is unclear
293
+ - If migrations exist, consider ordering:
294
+ 1) deploy backward-compatible code
295
+ 2) apply migrations
296
+ 3) deploy forward code
297
+
298
+ ## Output format (what to respond with)
299
+ When executing, respond with:
300
+ 1. Deployment plan summary
301
+ 2. Exact steps/commands
302
+ 3. Verification checklist
303
+ 4. Rollback instructions and triggers
255
304
  ```
256
305
 
257
306
  ---
258
307
 
259
- ### Example 2: `code review` skill (checklist)
308
+ ### Example B: `code review` skill
260
309
 
261
- **File:** `./skills/code-review/SKILL.md`
310
+ **File:** `.knowhow/skills/code-review/SKILL.md`
262
311
  ```md
263
312
  ---
264
313
  name: code review
265
- description: Perform a structured code review with correctness, security, and style checks.
314
+ description: Perform a structured code review with a checklist, risk assessment, and actionable feedback.
266
315
  ---
267
316
 
268
317
  # Code Review Skill
269
318
 
270
- Use this checklist for reviewing PRs or patches. If you lack context (language/framework/test coverage), ask targeted questions.
271
-
272
- ## 0) First pass (understand)
273
- 1. What is the change trying to accomplish?
274
- 2. Does the change align with the existing codebase patterns?
275
- 3. Are there any new dependencies or risky integrations?
276
-
277
- ## 1) Correctness & behavior
278
- - [ ] All intended behaviors are implemented
279
- - [ ] Edge cases are handled (empty input, nulls, timeouts, boundaries)
280
- - [ ] Error handling is consistent and actionable
281
- - [ ] Tests exist and cover the changed logic
282
- - [ ] Performance implications are understood (e.g., new loops, DB queries)
283
-
284
- ## 2) Security review
285
- - [ ] Input validation is present where needed
286
- - [ ] Secrets are not logged or exposed
287
- - [ ] AuthZ/AuthN is enforced (no missing permission checks)
288
- - [ ] Injection risks are mitigated (SQL/command/template)
289
- - [ ] File/path handling is safe (no traversal)
290
-
291
- ## 3) API / interface correctness
292
- - [ ] Contracts are updated consistently (types, docs, callers)
293
- - [ ] Backwards compatibility is preserved if required
294
- - [ ] Status codes / error shapes are stable
295
-
296
- ## 4) Code quality & maintainability
297
- - [ ] Naming is clear and consistent
298
- - [ ] Complexity is reasonable; no deeply nested logic
299
- - [ ] Duplicated logic is refactored when appropriate
300
- - [ ] Comments explain “why”, not “what”
301
-
302
- ## 5) Tests
303
- - [ ] Unit tests cover core logic
304
- - [ ] Integration tests cover boundaries (DB/network/interfaces)
305
- - [ ] Test data is minimal and deterministic
306
- - [ ] Flaky tests are avoided
307
-
308
- ## 6) Documentation
309
- - [ ] README or inline docs updated if user-facing behavior changed
310
- - [ ] Migration notes added when needed
311
- - [ ] Examples updated
312
-
313
- ## 7) Final response format
314
- Return the review as:
315
-
316
- 1. Summary of key changes
317
- 2. Must-fix issues (severity: critical/high)
318
- 3. Should-fix issues (medium/low)
319
- 4. Nice-to-have improvements
320
- 5. Suggested diffs (if possible) or questions for the author
319
+ Use this skill to review a code change (PR/diff). Provide feedback that is:
320
+ - specific
321
+ - actionable
322
+ - prioritized by risk/impact
323
+
324
+ ## Inputs to request (if missing)
325
+ Ask for:
326
+ 1. Language/framework
327
+ 2. Repo context (where relevant)
328
+ 3. The diff/patch (or key files)
329
+ 4. Purpose of change (bug fix? feature?)
330
+ 5. Constraints (performance/security/compliance)
331
+
332
+ ## Review workflow
333
+
334
+ ### 1) High-level summary
335
+ - What does the change aim to do?
336
+ - What files/components are most impacted?
337
+
338
+ ### 2) Checklist review (use this order)
339
+
340
+ #### Correctness
341
+ - Does the code match the intended behavior?
342
+ - Are there off-by-one / null / boundary cases?
343
+ - Are errors handled and surfaced appropriately?
344
+
345
+ #### Security
346
+ - Input validation and sanitization
347
+ - Authz/authn checks
348
+ - Secrets handling (no secrets in logs)
349
+ - Injection risks (SQL/command/template)
350
+ - CSRF/XSS risks (web)
351
+
352
+ #### Performance
353
+ - Hot paths and unnecessary allocations
354
+ - N+1 queries / repeated work
355
+ - Unbounded loops or expensive operations
356
+
357
+ #### Maintainability
358
+ - Naming clarity
359
+ - DRY vs duplication
360
+ - Testability (pure functions, seams for mocks)
361
+ - Code structure and separation of concerns
362
+
363
+ #### Observability
364
+ - Useful logs (without leaking sensitive data)
365
+ - Metrics/events where appropriate
366
+ - Error logs include sufficient context
367
+
368
+ #### Testing
369
+ - Unit tests for logic
370
+ - Integration tests for boundaries
371
+ - Regression tests for bug fixes
372
+ - Edge cases covered
373
+
374
+ ### 3) Risk assessment (must include)
375
+ Create a short risk table:
376
+
377
+ | Area | Risk level (Low/Med/High) | Why | Suggestion |
378
+ |------|------------------------------|-----|------------|
379
+
380
+ ### 4) Actionable feedback
381
+ For each issue:
382
+ - Explain why it’s a problem
383
+ - Provide a suggested change (or example)
384
+ - Label severity: **Must-fix / Should-fix / Nice-to-have**
385
+
386
+ ### 5) Questions for the author (if needed)
387
+ Ask clarifying questions only when assumptions would otherwise be unsafe.
388
+
389
+ ## Example response structure
390
+ Return your output using:
391
+
392
+ 1. Summary
393
+ 2. Review (grouped by Correctness/Security/Performance/etc.)
394
+ 3. Risk table
395
+ 4. Must-fix / Should-fix items (with suggestions)
396
+ 5. Tests recommendations
397
+ 6. Questions (if any)
398
+
399
+ ## Edge cases / constraints
400
+ - If the diff is incomplete, ask for the missing portions instead of guessing.
401
+ - If you cannot assess security due to missing auth context, explicitly state that limitation and request needed info.
321
402
  ```
322
403
 
323
404
  ---
324
405
 
325
- ### Example 3: `database migration` skill
406
+ ### Example C: `database migration` skill
326
407
 
327
- **File:** `./skills/db-migration/SKILL.md`
408
+ **File:** `.knowhow/skills/database-migration/SKILL.md`
328
409
  ```md
329
410
  ---
330
411
  name: database migration
331
- description: Plan and execute a safe database migration with validation and rollback.
412
+ description: Plan and execute database migrations with safety (backward compatibility, ordering, verification, rollback).
332
413
  ---
333
414
 
334
415
  # Database Migration Skill
335
416
 
336
- Use this playbook to design and run a database migration safely in real environments.
337
-
338
- ## 1) Clarify migration intent
339
- Answer:
340
- 1. What schema change is required? (add/rename/remove column/table, indexes, constraints)
341
- 2. Does it require data backfill?
342
- 3. Is it online/zero-downtime or will it incur downtime?
343
-
344
- ## 2) Safety prerequisites
345
- - Ensure you have:
346
- - A backup strategy (automated snapshot or external backup)
347
- - A way to rollback (or a forward-fix plan if rollback is unsafe)
348
- - Confirm:
349
- - Migration tool (e.g., Alembic, Flyway, Liquibase, Rails)
350
- - Database engine (Postgres/MySQL/etc.)
351
- - Staging validation environment mirrors production settings
352
-
353
- ## 3) Use a safe migration pattern
354
- Common safe approach for risky changes:
355
- 1. Additive first
356
- - Add new columns/constraints as nullable or non-enforcing
357
- 2. Backfill
358
- - Populate existing rows with a controlled job
359
- 3. Validate
360
- - Confirm data correctness (counts, null rates, invariants)
361
- 4. Switch reads/writes
362
- - Update application code to use the new schema
363
- 5. Finalize
364
- - Tighten constraints (NOT NULL, FK constraints, unique indexes)
365
- 6. Clean up
366
- - Remove old columns after a safe window
367
-
368
- ## 4) Concrete checklist
369
-
370
- ### Schema change checklist
371
- - [ ] Avoid dropping columns/constraints in the first pass if downtime is not acceptable
372
- - [ ] Prefer “expand/contract” patterns when possible
373
- - [ ] Index changes are planned to avoid locking storms
374
-
375
- ### Backfill checklist
376
- - [ ] Batch updates (avoid locking large tables)
377
- - [ ] Add progress logging
378
- - [ ] Validate after backfill (row counts, distribution checks)
379
-
380
- ### Verification checklist
381
- - [ ] Run migration in staging first
382
- - [ ] Confirm application health (no errors on startup)
383
- - [ ] Verify critical queries
384
-
385
- ### Rollback checklist
386
- Choose one:
387
- - [ ] True rollback supported by the migration tool
388
- - [ ] Or forward-only correction plan (recommended if true rollback is unsafe)
389
-
390
- ## 5) Example SQL patterns (Postgres)
391
-
392
- ### Add nullable column + backfill + enforce NOT NULL
417
+ Use this skill to guide migrations for relational databases (Postgres/MySQL/etc.) with production-safety principles.
418
+
419
+ ## Inputs to request (if missing)
420
+ Ask:
421
+ 1. Database type/version (e.g., Postgres 14)
422
+ 2. Migration type:
423
+ - schema change
424
+ - data backfill
425
+ - index changes
426
+ - constraints
427
+ 3. Migration tool (e.g., Flyway, Liquibase, Alembic, Prisma Migrate, custom scripts)
428
+ 4. Environment (staging vs production)
429
+ 5. Constraints:
430
+ - availability requirements
431
+ - expected load window
432
+ - maximum acceptable migration duration
433
+ 6. Whether the app code will be deployed concurrently
434
+
435
+ ## Safety principles (follow in order)
436
+ 1. **Backward compatible first**
437
+ 2. Prefer **expand migrate contract**
438
+ 3. Keep transactions short when possible
439
+ 4. Avoid long locks (reindex/alter carefully)
440
+ 5. Validate before/after with queries
441
+
442
+ ## Migration plan template
443
+
444
+ ### Step 1) Understand current state
445
+ - Identify current schema
446
+ - Identify dependencies:
447
+ - foreign keys
448
+ - views
449
+ - triggers
450
+ - application queries
451
+
452
+ ### Step 2) Define the target
453
+ - What new columns/tables/indexes/constraints are desired?
454
+ - What data transformations are needed?
455
+
456
+ ### Step 3) Plan expand/migrate/contract (example)
457
+ #### Expand (backward compatible)
458
+ - Add new nullable column(s)
459
+ - Add new tables
460
+ - Add indexes concurrently (if supported)
461
+ - Do **not** add NOT NULL or strict constraints yet
462
+
463
+ #### Migrate (populate data)
464
+ - Backfill in batches
465
+ - Ensure idempotency
466
+ - Rate limit if needed
467
+
468
+ #### Contract (enforce invariants)
469
+ - Set NOT NULL after backfill completion
470
+ - Add constraints
471
+ - Drop old columns only after code is updated and verified
472
+
473
+ ### Step 4) Order of deployments
474
+ If app code changes too, use:
475
+ 1. Deploy backward-compatible code
476
+ 2. Run expand migration
477
+ 3. Deploy code that writes new format (optional)
478
+ 4. Run data backfill
479
+ 5. Deploy forward code
480
+ 6. Run contract migration
481
+
482
+ ## Concrete examples
483
+
484
+ ### Example: Backfill a new column in batches (SQL pseudocode)
393
485
  ```sql
394
- -- 1) Expand: add column as nullable
395
- ALTER TABLE users ADD COLUMN email_normalized text;
486
+ -- Add column first (expand)
487
+ ALTER TABLE users ADD COLUMN display_name TEXT;
396
488
 
397
- -- 2) Backfill in a controlled way (example)
489
+ -- Backfill in batches (migrate)
490
+ -- Repeat until affected_rows = 0
398
491
  UPDATE users
399
- SET email_normalized = lower(email)
400
- WHERE email_normalized IS NULL;
401
-
402
- -- 3) Validate before enforcing (example checks)
403
- SELECT count(*) FROM users WHERE email_normalized IS NULL;
404
-
405
- -- 4) Contract: enforce constraint
406
- ALTER TABLE users ALTER COLUMN email_normalized SET NOT NULL;
492
+ SET display_name = username
493
+ WHERE display_name IS NULL
494
+ LIMIT 10000;
407
495
  ```
408
496
 
409
- ### Create index with lower blocking risk (conceptual)
497
+ > If your DB doesn’t support `LIMIT` on UPDATE, use a CTE or batch-selection strategy.
498
+
499
+ ### Example: Index creation carefully (Postgres-style)
500
+ - Create index concurrently to reduce locking:
410
501
  ```sql
411
- -- If supported, use CONCURRENTLY to reduce blocking
412
- CREATE INDEX CONCURRENTLY idx_users_email_normalized
413
- ON users(email_normalized);
502
+ CREATE INDEX CONCURRENTLY users_display_name_idx
503
+ ON users (display_name);
414
504
  ```
415
505
 
416
- ## 6) What to output as the agent response
417
- Provide:
418
- - Migration plan (phases)
419
- - Estimated risk level and why
420
- - Exact commands (tool-specific)
421
- - Validation queries/tests
422
- - Rollback or forward-fix plan
423
- - Execution order and required application deploy timing
506
+ ## Verification checklist (before and after)
507
+ ### Before
508
+ - Confirm migration has a dry run plan
509
+ - Confirm rollback method exists
510
+ - Record:
511
+ - row counts
512
+ - min/max timestamps
513
+ - key aggregates
514
+
515
+ ### After
516
+ - Re-run invariants:
517
+ - null counts for new required columns
518
+ - foreign key validity checks
519
+ - Check application health
520
+ - Monitor errors/latency for the migration window
521
+
522
+ ## Rollback strategy
523
+ Define one of:
524
+ - **Down migration** (if safe/possible)
525
+ - **Reverse via feature flag**
526
+ - **Recreate old schema** (last resort)
527
+ - **Data rollback** (restore from snapshot/backups)
528
+
529
+ State rollback triggers explicitly (e.g., health checks failing, lock contention too high).
530
+
531
+ ## Edge cases
532
+ - If adding NOT NULL column without default to a large table:
533
+ - do it via expand/migrate/contract
534
+ - If updating huge datasets:
535
+ - batch and monitor impact
536
+ - If migrations aren’t idempotent:
537
+ - redesign to be re-runnable safely
424
538
  ```
425
539
 
426
540
  ---
427
541
 
428
542
  ## 8) Global skills
429
543
 
430
- To reuse skills across multiple projects, store them in:
544
+ If you want skills to be available **across projects**, store them in:
431
545
 
432
546
  **`~/.knowhow/skills/`**
433
547
 
434
- Then ensure your `knowhow.json` includes that directory in the `skills` array, for example:
435
- ```json
436
- {
437
- "skills": [
438
- "~/.knowhow/skills"
439
- ]
440
- }
441
- ```
548
+ Then include that directory in your `skills` configuration (either in global config or project config, depending on how your setup uses `knowhow.json`).
442
549
 
443
- Recommended structure (nested organization is fine because scanning is recursive):
550
+ ### Recommended structure
444
551
  ```text
445
552
  ~/.knowhow/skills/
446
553
  deploy/
447
554
  SKILL.md
448
555
  code-review/
449
556
  SKILL.md
450
- db-migration/
557
+ database-migration/
451
558
  SKILL.md
452
559
  ```
453
560
 
454
- The plugin does not require the folder name to match the skill name—only the `SKILL.md` frontmatter `name` matters.
561
+ ### Example `knowhow.json` (point to global + local)
562
+ ```json
563
+ {
564
+ "skills": [
565
+ "~/.knowhow/skills",
566
+ ".knowhow/skills"
567
+ ]
568
+ }
569
+ ```
455
570
 
456
571
  ---
457
572
 
458
- ## Summary checklist (quick reference)
459
-
460
- - Name skill file: **`SKILL.md`**
461
- - Add frontmatter at the top:
462
- - `name: ...`
463
- - `description: ...`
464
- - Write clear step-by-step instructions + examples
465
- - Include edge cases / rollback / verification
466
- - Configure directories in `knowhow.json` under `skills`
467
- - For global reuse, use `~/.knowhow/skills/`
468
- ```
573
+ ## Quick checklist for creating a new skill
574
+
575
+ 1. Create a folder (any name) and place a file named **`SKILL.md`**
576
+ 2. Add frontmatter at the top:
577
+ - `name: ...`
578
+ - `description: ...`
579
+ 3. Write clear, step-by-step instructions in the body
580
+ 4. Include examples and edge cases
581
+ 5. Add the directory to the `skills` array in `.knowhow/knowhow.json`
582
+ 6. Test by prompting the agent using the exact skill name phrase (case-insensitive substring match)
583
+
584
+ If you want, tell me your workflow (tools/stack) and I can generate a tailored set of `SKILL.md` templates for your team.