@tyvm/knowhow 0.0.109-dev.e88af1e → 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 (82) 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/src/agents/tools/list.ts +2 -2
  15. package/src/ai.ts +81 -37
  16. package/src/chat/CliChatService.ts +1 -1
  17. package/src/chat/modules/SystemModule.ts +2 -2
  18. package/src/clients/anthropic.ts +1 -1
  19. package/src/clients/index.ts +25 -6
  20. package/src/clients/openai.ts +8 -5
  21. package/src/clients/types.ts +29 -6
  22. package/src/clients/withRetry.ts +89 -0
  23. package/src/commands/agent.ts +30 -0
  24. package/src/commands/modules.ts +365 -30
  25. package/src/config.ts +1 -1
  26. package/src/hashes.ts +8 -9
  27. package/src/index.ts +4 -2
  28. package/src/processors/Base64ImageDetector.ts +73 -0
  29. package/src/services/MediaProcessorService.ts +79 -10
  30. package/src/services/modules/index.ts +24 -19
  31. package/tests/processors/Base64ImageDetector.test.ts +160 -0
  32. package/tests/unit/clients/AIClient.test.ts +446 -0
  33. package/tests/unit/clients/withRetry.test.ts +319 -0
  34. package/tests/unit/commands/github-credentials.test.ts +1 -2
  35. package/ts_build/package.json +1 -1
  36. package/ts_build/src/agents/tools/list.js +2 -2
  37. package/ts_build/src/agents/tools/list.js.map +1 -1
  38. package/ts_build/src/ai.d.ts +3 -3
  39. package/ts_build/src/ai.js +51 -23
  40. package/ts_build/src/ai.js.map +1 -1
  41. package/ts_build/src/chat/CliChatService.js +1 -1
  42. package/ts_build/src/chat/CliChatService.js.map +1 -1
  43. package/ts_build/src/chat/modules/SystemModule.js +2 -2
  44. package/ts_build/src/chat/modules/SystemModule.js.map +1 -1
  45. package/ts_build/src/clients/anthropic.js +1 -1
  46. package/ts_build/src/clients/anthropic.js.map +1 -1
  47. package/ts_build/src/clients/index.js +7 -6
  48. package/ts_build/src/clients/index.js.map +1 -1
  49. package/ts_build/src/clients/openai.js +4 -4
  50. package/ts_build/src/clients/openai.js.map +1 -1
  51. package/ts_build/src/clients/types.d.ts +12 -6
  52. package/ts_build/src/clients/withRetry.d.ts +2 -0
  53. package/ts_build/src/clients/withRetry.js +60 -0
  54. package/ts_build/src/clients/withRetry.js.map +1 -0
  55. package/ts_build/src/commands/agent.js +25 -0
  56. package/ts_build/src/commands/agent.js.map +1 -1
  57. package/ts_build/src/commands/modules.js +297 -17
  58. package/ts_build/src/commands/modules.js.map +1 -1
  59. package/ts_build/src/config.js +1 -1
  60. package/ts_build/src/config.js.map +1 -1
  61. package/ts_build/src/hashes.js +5 -7
  62. package/ts_build/src/hashes.js.map +1 -1
  63. package/ts_build/src/index.js +1 -1
  64. package/ts_build/src/index.js.map +1 -1
  65. package/ts_build/src/processors/Base64ImageDetector.d.ts +3 -0
  66. package/ts_build/src/processors/Base64ImageDetector.js +42 -0
  67. package/ts_build/src/processors/Base64ImageDetector.js.map +1 -1
  68. package/ts_build/src/services/MediaProcessorService.d.ts +5 -4
  69. package/ts_build/src/services/MediaProcessorService.js +53 -8
  70. package/ts_build/src/services/MediaProcessorService.js.map +1 -1
  71. package/ts_build/src/services/modules/index.js +17 -13
  72. package/ts_build/src/services/modules/index.js.map +1 -1
  73. package/ts_build/tests/processors/Base64ImageDetector.test.js +111 -0
  74. package/ts_build/tests/processors/Base64ImageDetector.test.js.map +1 -1
  75. package/ts_build/tests/unit/clients/AIClient.test.d.ts +1 -0
  76. package/ts_build/tests/unit/clients/AIClient.test.js +339 -0
  77. package/ts_build/tests/unit/clients/AIClient.test.js.map +1 -0
  78. package/ts_build/tests/unit/clients/withRetry.test.d.ts +1 -0
  79. package/ts_build/tests/unit/clients/withRetry.test.js +225 -0
  80. package/ts_build/tests/unit/clients/withRetry.test.js.map +1 -0
  81. package/ts_build/tests/unit/commands/github-credentials.test.js +1 -2
  82. package/ts_build/tests/unit/commands/github-credentials.test.js.map +1 -1
@@ -1,477 +1,437 @@
1
1
  # `knowhow generate` Guide
2
2
 
3
- `knowhow generate` is the Knowhow CLI command that turns your input files into generated documentation (and other artifacts) by running an AI prompt over the selected sources and writing the results to your configured outputs.
4
-
5
- It is driven entirely by your local **`.knowhow/knowhow.json`** config—specifically the **`sources`** array.
3
+ `knowhow generate` is Knowhow’s “code-to-documents” generator. It reads your `sources` from `.knowhow/knowhow.json`, resolves prompts, runs AI summarization (or plugin handlers), and writes output files (or sets of files) to your configured `output` paths.
6
4
 
7
5
  ---
8
6
 
9
- ## What `knowhow generate` does
10
-
11
- When you run:
12
-
13
- ```bash
14
- knowhow generate
15
- ```
16
-
17
- the CLI:
7
+ ## 1) What `knowhow generate` does
18
8
 
19
- 1. Loads your Knowhow config from **`.knowhow/knowhow.json`**
20
- 2. For each entry in **`config.sources`**:
21
- - Expands `source.input` into a list of matching files
22
- - Resolves `source.prompt` into an MDX prompt template or prompt string
23
- - Uses the selected `model`/`agent` to summarize/generate content
24
- - Writes output to either:
25
- - a single output file, or
26
- - multiple output files inside an output directory
27
- 3. Skips work when inputs and prompt haven’t changed (hash-based caching)
9
+ At a high level, for each entry in `config.sources`, it:
28
10
 
29
- ---
11
+ 1. **Finds input files** using `source.input` (glob / comma list / brace expansion).
12
+ 2. **Loads the prompt** via `source.prompt`.
13
+ 3. **Chooses output mode** based on `source.output`:
14
+ - If `source.output` ends with `/` → **multi-output mode** (one output per input file).
15
+ - Otherwise → **single-output mode** (one combined output file).
16
+ 4. **Skips work using caching** (`.knowhow/.hashes.json`):
17
+ - It computes an **MD5 hash of the prompt** and an **MD5 hash of each input file’s converted text**.
18
+ - If the prompt+file hashes match what was last generated, the output is skipped.
19
+ 5. **Writes generated documents** to disk.
30
20
 
31
- ## `sources` configuration structure
21
+ ### Output mode behavior (from the code)
32
22
 
33
- `sources` is an array of objects in `.knowhow/knowhow.json`.
23
+ #### A) Multi-output mode (directory output)
24
+ If `source.output` ends with `/`:
34
25
 
35
- At runtime, each source object may be handled in one of two ways:
26
+ - For each matched input file:
27
+ - Compute an output folder that preserves subpaths **under the base prefix before `**`**.
28
+ - Example: with `input: "src/**/*.ts"`, the base prefix is `"src/"`.
29
+ - A file like `src/cli/index.ts` becomes an output at:
30
+ - `<output>/<nestedFolder>/<outputName>.<outputExt>`
31
+ - Default `outputExt` is `"mdx"` unless overridden by `outputExt`.
36
32
 
37
- - **File generation mode** (default): when `kind` is `"file"` or missing/empty
38
- - **Plugin/“special kind” mode**: when `kind` is set and is not `"file"` (see `kind` below)
33
+ #### B) Single-output mode (single file output)
34
+ If `source.output` does **not** end with `/`:
39
35
 
40
- ### Common fields
36
+ - It writes **one** `source.output` file that contains combined results for **all** matched inputs.
41
37
 
42
- ```jsonc
43
- {
44
- "input": "src/**/*.ts",
45
- "output": ".knowhow/docs/",
46
- "prompt": "MyPrompt",
47
- "kind": "file",
48
- "agent": "Developer",
49
- "model": "gpt-4o-mini",
50
- "outputExt": "mdx",
51
- "outputName": "README"
52
- }
53
- ```
38
+ ---
54
39
 
55
- All fields described below are part of `GenerationSource` usage in the generator.
40
+ ## 2) `sources` configuration structure
56
41
 
57
- ---
42
+ Your `sources` array lives in `.knowhow/knowhow.json` under `sources`.
58
43
 
59
- ## Field reference
44
+ Each source entry is a `GenerationSource` with these commonly used fields:
60
45
 
61
- ### `input` (required)
62
- Defines which files to read. Supported formats are:
46
+ ### `input`
47
+ Controls which files are processed. Supported formats (as implemented):
63
48
 
64
49
  - **Single file**
65
50
  ```json
66
- { "input": "src/index.ts" }
51
+ "input": "src/index.ts"
67
52
  ```
68
53
  - **Glob**
69
54
  ```json
70
- { "input": "src/**/*.ts" }
55
+ "input": "src/**/*.ts"
71
56
  ```
72
57
  - **Comma-separated list**
73
58
  ```json
74
- { "input": "src/a.ts,src/b.ts,src/c.ts" }
59
+ "input": "src/a.ts,src/b.ts,src/c.ts"
75
60
  ```
76
- Comma-separated values are auto-normalized into brace expansion internally.
61
+ Comma lists are normalized into brace expansion internally.
77
62
  - **Brace expansion**
78
63
  ```json
79
- { "input": "{src/a.ts,src/b.ts}" }
64
+ "input": "{src/a.ts,src/b.ts}"
80
65
  ```
81
66
 
82
- **Normalization behavior (important):**
83
- - If `input` contains `{`, `*`, or `?`, it is used as-is.
84
- - If `input` contains commas and no glob/braces, commas are converted into `{a,b,c}`.
85
- - Otherwise, it’s treated as a glob/pattern directly.
67
+ > Implementation note: Knowhow normalizes comma-separated lists into `{a,b,c}` form (so it can pass it to the glob library).
86
68
 
87
69
  ---
88
70
 
89
- ### `output` (required)
90
- Defines where generated content is written.
91
-
92
- Two output modes exist:
93
-
94
- #### 1) Directory mode (multi-output)
95
- If `output` **ends with `/`**, each input file becomes its own output file:
96
-
97
- ```json
98
- {
99
- "input": "src/**/*.ts",
100
- "output": ".knowhow/docs/",
101
- "outputExt": "mdx"
102
- }
103
- ```
104
-
105
- - Output file name defaults to the input file’s base name
106
- - You can override the output name (see `outputName`)
107
- - You can override the output extension (see `outputExt`)
71
+ ### `output`
72
+ Controls where results are written:
108
73
 
109
- #### 2) Single file mode (single-output)
110
- If `output` **does not end with `/`**, all matched input files are combined into **one** output file.
74
+ - **Directory output** (multi-output mode)
75
+ - Must end with `/`:
76
+ ```json
77
+ "output": ".knowhow/docs/"
78
+ ```
79
+ - **Single file output** (single-output mode)
80
+ ```json
81
+ "output": ".knowhow/docs/README.mdx"
82
+ ```
111
83
 
112
- ```json
113
- {
114
- "input": "src/**/*.ts",
115
- "output": ".knowhow/docs/ALL.md"
116
- }
117
- ```
84
+ Knowhow creates directories automatically in multi-output mode.
118
85
 
119
86
  ---
120
87
 
121
- ### `prompt` (required or optional depending on your desired behavior)
122
- Controls the AI instruction template.
88
+ ### `prompt`
89
+ Controls the prompt to use for AI generation.
123
90
 
124
- You can supply `prompt` in any of these ways:
91
+ Knowhow resolves `prompt` in this order:
125
92
 
126
- 1. **Prompt name** (looked up in `promptsDir`)
127
- ```json
128
- { "prompt": "BasicCodeDocumenter" }
129
- ```
130
- The generator looks for:
131
- - `<promptsDir>/<promptName>.mdx`
132
- - Default `promptsDir` is: **`.knowhow/prompts`**
93
+ 1. **Prompt name in `promptsDir`**
94
+ If `prompt` is a name like `"BasicCodeDocumenter"`, it will try:
95
+ - `<promptsDir>/<prompt>.mdx`
96
+ Example: `.knowhow/prompts/BasicCodeDocumenter.mdx`
133
97
 
134
98
  2. **Direct prompt file path**
135
- ```json
136
- { "prompt": "prompts/MyPrompt.mdx" }
137
- ```
138
- If that file exists, it is read as prompt content.
99
+ - If `prompt` points to an existing file, it reads that file.
139
100
 
140
101
  3. **Inline prompt string**
141
- ```json
142
- { "prompt": "Summarize the following file as a short doc for newcomers.\n\n{text}" }
143
- ```
144
-
145
- #### `{text}` placeholder requirement
146
- If the prompt template does **not** include `{text}`, Knowhow automatically appends:
147
-
148
- ```mdx
149
- {text}
150
- ```
102
+ - If neither a known prompt file nor a direct path exists, Knowhow treats the `prompt` value itself as the prompt text.
151
103
 
152
- so the input is included when rendering.
104
+ > Also: Knowhow ensures your prompt contains a `{text}` placeholder. If it’s missing, it automatically appends:
105
+ > `\n\n{text}`
153
106
 
154
107
  ---
155
108
 
156
- ### `kind` (optional)
157
- Controls whether generation is treated as “file generation” or a “special processing kind”.
109
+ ### `kind`
110
+ Special processing kind.
111
+
112
+ From the code:
158
113
 
159
- - If `kind` is `"file"` **or missing**, Knowhow performs the normal file summarization flow.
160
- - Otherwise, Knowhow checks whether `kind` matches a registered plugin:
161
- - If it is a plugin, the plugin is executed and its returned data is written to `output` (and directory output is rejected for plugin-only output).
162
- - Then Knowhow still proceeds with file generation for that same source.
114
+ - If `kind` is `"file"` **or missing** **standard file summarization** pipeline runs.
115
+ - Otherwise Knowhow attempts a **plugin-based handler**:
116
+ - It checks `Plugins.isPlugin(kind)`.
117
+ - If it is a plugin:
118
+ - It runs `Plugins.call(kind, input)` and writes the result to `source.output` (but **plugin output must be a single file**; directory outputs are rejected for plugins).
119
+ - After the plugin step (or if the kind is not a plugin), Knowhow still proceeds to the normal file summarization generation for that source.
163
120
 
164
- > In other words: non-`file` kinds can run a plugin and then also run the file-based generation pipeline.
121
+ **Practical takeaway:**
122
+ Use `kind` for plugin integrations; otherwise default file generation happens.
165
123
 
166
124
  ---
167
125
 
168
- ### `agent` (optional)
169
- Selects which agent to use.
126
+ ### `agent`
127
+ Selects which agent to use when calling the AI summarizer.
170
128
 
171
- - Default agent (as noted in your config requirements): **`Developer`**
172
- - This value is passed through to summarization functions.
129
+ - If omitted, a default is used (the docs mention default agent: **Developer**).
173
130
 
174
131
  ---
175
132
 
176
- ### `model` (optional)
177
- Overrides the AI model for this source.
133
+ ### `model`
134
+ Overrides the model for this source.
135
+
136
+ - The value is passed to `summarizeFile(...)` / `summarizeFiles(...)`.
178
137
 
179
- - If omitted, the summarization functions will use Knowhow’s configured default model/provider logic (outside the code shown here).
180
- - If provided, the source-specific `model` is used when calling `summarizeFile` / `summarizeFiles`.
138
+ > If you don’t set `model`, Knowhow will use whatever default model the summarization layer chooses (not shown in the provided code).
181
139
 
182
140
  ---
183
141
 
184
- ### `outputExt` (optional; multi-output mode only)
185
- Overrides the extension used for generated files when `output` ends with `/`.
142
+ ### `outputExt`
143
+ Overrides the extension used for multi-output mode outputs.
186
144
 
187
- Default: **`"mdx"`**
145
+ - Default in multi-output handler: `"mdx"`
146
+ - Only applied when `output` ends with `/` (directory mode).
188
147
 
189
- Example:
148
+ ---
190
149
 
191
- ```json
192
- {
193
- "input": "src/**/*.ts",
194
- "output": ".knowhow/docs/",
195
- "outputExt": "md"
196
- }
197
- ```
150
+ ### `outputName`
151
+ Overrides the filename portion used for multi-output mode.
152
+
153
+ - Only applied when `output` ends with `/`.
154
+ - For each input file, output filename becomes:
155
+ - `<outputFolder>/<outputName>.<outputExt>` (instead of using the input’s basename)
198
156
 
199
157
  ---
200
158
 
201
- ### `outputName` (optional; multi-output mode only)
202
- Overrides the generated output file’s base name (instead of using the input file’s name).
159
+ ## 3) Prompt resolution (where your prompt comes from)
203
160
 
204
- Example:
161
+ Knowhow loads prompts with `loadPrompt(promptName)` and supports:
205
162
 
163
+ ### A) Prompt file in `promptsDir`
164
+ - Default `promptsDir`: `.knowhow/prompts`
165
+ - Example prompt file:
166
+ - `.knowhow/prompts/MyPrompt.mdx`
167
+
168
+ Config:
206
169
  ```json
207
- {
208
- "input": "src/**/*.ts",
209
- "output": ".knowhow/docs/",
210
- "outputName": "REFERENCE",
211
- "outputExt": "mdx"
212
- }
170
+ "prompt": "MyPrompt"
213
171
  ```
214
172
 
215
- Each file would still map into the directory (including nested folders), but each output filename would be `REFERENCE.<outputExt>`.
216
-
217
- ---
173
+ Knowhow reads:
174
+ - `.knowhow/prompts/MyPrompt.mdx`
218
175
 
219
- ## Prompt resolution (how Knowhow finds your prompt)
220
-
221
- Knowhow resolves `source.prompt` using the following order (from `loadPrompt()`):
176
+ ### B) Direct prompt file path
177
+ Config:
178
+ ```json
179
+ "prompt": "./prompts/MyPrompt.mdx"
180
+ ```
222
181
 
223
- 1. **Look in `promptsDir`**
224
- - Default `promptsDir`: **`.knowhow/prompts`**
225
- - It checks for:
226
- `path.join(promptsDir, promptName + ".mdx")`
182
+ Knowhow reads that file if it exists.
227
183
 
228
- 2. **Try `prompt` as a direct file path**
229
- - If `fs.existsSync(promptName)` succeeds, it reads that file.
184
+ ### C) Inline prompt string
185
+ Config:
186
+ ```json
187
+ "prompt": "Summarize the following code and output markdown with sections..."
188
+ ```
230
189
 
231
- 3. **Treat `prompt` itself as the prompt content**
232
- - If neither file exists, the value is used as an inline prompt string.
190
+ ### `{text}` placeholder requirement
191
+ Knowhow requires/ensures the prompt contains `{text}`.
233
192
 
234
- Finally, it ensures `{text}` exists (appends it if missing).
193
+ - If your prompt doesn’t include it, Knowhow appends it automatically.
194
+ - `{text}` is where Knowhow inserts the content it’s summarizing (the code/text extracted from each input file).
235
195
 
236
196
  ---
237
197
 
238
- ## Input output mapping (output modes)
198
+ ## 4) Input patterns: examples
239
199
 
240
- ### A) Directory output (`output` ends with `/`)
241
- For each input file:
242
-
243
- - Knowhow computes a nested output folder based on the prefix before `**`.
200
+ ### Single file
201
+ ```json
202
+ {
203
+ "input": "src/index.ts",
204
+ "output": ".knowhow/out/index.mdx",
205
+ "prompt": "BasicCodeDocumenter"
206
+ }
207
+ ```
244
208
 
245
- Given:
209
+ ### Glob (multiple files → combined single output)
210
+ ```json
211
+ {
212
+ "input": "src/**/*.ts",
213
+ "output": ".knowhow/docs/SDK.md",
214
+ "prompt": "BasicCodeDocumenter"
215
+ }
216
+ ```
246
217
 
218
+ ### Glob (multiple files → one output per file)
247
219
  ```json
248
- "input": "src/**/*.ts",
249
- "output": ".knowhow/docs/"
220
+ {
221
+ "input": "src/**/*.ts",
222
+ "output": ".knowhow/docs/",
223
+ "prompt": "BasicCodeDocumenter",
224
+ "outputExt": "mdx"
225
+ }
250
226
  ```
251
227
 
252
- - `inputPath` becomes `"src/"` (everything before the `**`)
253
- - Each input file’s directory is transformed into an equivalent subfolder under the output directory
228
+ ### Comma-separated inputs (combined single output)
229
+ ```json
230
+ {
231
+ "input": "src/a.ts,src/b.ts,src/c.ts",
232
+ "output": ".knowhow/docs/selected.md",
233
+ "prompt": "BasicCodeDocumenter"
234
+ }
235
+ ```
254
236
 
255
- Then each file is written as:
237
+ ### Brace expansion
238
+ ```json
239
+ {
240
+ "input": "{src/a.ts,src/b.ts}",
241
+ "output": ".knowhow/docs/selected.md",
242
+ "prompt": "BasicCodeDocumenter"
243
+ }
244
+ ```
256
245
 
257
- - `output/<nestedFolder>/<outputFileName>.<outputExt>`
246
+ ---
258
247
 
259
- Where:
260
- - `outputFileName` = `outputName` if provided, otherwise the input file’s base name
261
- - `outputExt` defaults to `mdx` unless overridden
248
+ ## 5) Output modes: directory vs single file
262
249
 
263
- ---
250
+ ### Directory output (`output` ends with `/`)
251
+ Produces **N output files** (one per input file matched).
264
252
 
265
- ### B) Single file output (`output` does NOT end with `/`)
266
- All matched files are combined and written into the one `output` path.
253
+ Each output file is placed under your output directory while preserving nested folders relative to the prefix before `**`.
267
254
 
268
255
  ---
269
256
 
270
- ## Hashing / caching behavior (skips unchanged files)
257
+ ### Single-file output (`output` is a file path)
258
+ Produces **one output file** that combines all matched inputs into a single document.
271
259
 
272
- Knowhow uses a persistent hash file:
260
+ ---
273
261
 
274
- - **`.knowhow/.hashes.json`**
262
+ ## 6) Hashing / caching: when outputs are skipped
275
263
 
276
- For each generation operation, it computes:
264
+ Knowhow uses `.knowhow/.hashes.json` and stores hashes keyed by the input file path (and the prompt hash).
277
265
 
278
- - `promptHash` = `md5(promptString)`
279
- - `fileHash` = `md5(convertToText(file))` (input content)
280
- - For directory mode, it checks both:
281
- - the input file, and
282
- - the output file
266
+ In both output modes:
283
267
 
284
- If `checkNoFilesChanged()` decides nothing has changed, Knowhow prints a “Skipping…” message and does not regenerate.
268
+ - It computes:
269
+ - `promptHash = md5(prompt)`
270
+ - `fileHash = md5(convertToText(file))`
271
+ - It calls `checkNoFilesChanged(...)` for the “to check” set:
272
+ - **Multi-output mode** checks: `[file, outputFile]`
273
+ - **Single-output mode** checks: `[outputFile, ...files]`
274
+ - If nothing changed, Knowhow logs a skip and moves on.
285
275
 
286
- This means:
287
- - Changing the prompt will invalidate cache for those files
288
- - Changing input file content will invalidate cache for those files
276
+ **Important:** If the input or output file is missing on disk, regeneration will happen.
289
277
 
290
278
  ---
291
279
 
292
- ## Writing good prompt templates (`.mdx`)
280
+ ## 7) Writing good `.mdx` prompt files
293
281
 
294
- Prompt files are typically stored under:
282
+ Knowhow expects prompt files to be **MDX** templates (e.g. `.knowhow/prompts/MyPrompt.mdx`).
295
283
 
296
- - **`.knowhow/prompts/YourPromptName.mdx`**
284
+ ### Minimum requirement
285
+ Your prompt must include a `{text}` placeholder (Knowhow will add it if you forget).
297
286
 
298
- ### Minimum guidance
287
+ ### Recommended structure
288
+ A solid prompt usually asks for:
299
289
 
300
- - Include a **`{text}`** placeholder somewhere in the prompt.
301
- - If you forget it, Knowhow will append it automatically at the end—but you should still place it where it makes sense.
290
+ - Clear sections (e.g. Overview / API / Usage / Notes)
291
+ - Output format (markdown headings, lists)
292
+ - Constraints (brevity, accuracy)
293
+ - Interpretation rules (assume code is partial, etc.)
302
294
 
303
- #### Example: basic prompt file
295
+ ### Example prompt file: `.knowhow/prompts/BasicCodeDocumenter.mdx`
304
296
 
305
- **`.knowhow/prompts/BasicCodeDocumenter.mdx`**
306
297
  ```mdx
307
- # Document this file
298
+ # File documentation
299
+
300
+ You are a technical writer.
308
301
 
309
- Write a clear developer-focused documentation page.
302
+ Given this code, produce documentation with:
303
+ 1. **Purpose** (1-3 sentences)
304
+ 2. **Key exported items** (functions/classes/types)
305
+ 3. **How it works** (step-by-step at a high level)
306
+ 4. **Important caveats** (edge cases, assumptions)
307
+ 5. **Examples** (if obvious)
310
308
 
311
- Requirements:
312
- - 1–2 paragraph summary
313
- - list of key exported functions/classes
314
- - notable pitfalls or usage notes
309
+ Return valid Markdown.
315
310
 
316
- Input:
311
+ Source content:
312
+ ```text
317
313
  {text}
318
314
  ```
319
-
320
- Then reference it in `knowhow.json`:
321
-
322
- ```json
323
- {
324
- "input": "src/**/*.ts",
325
- "output": ".knowhow/docs/",
326
- "prompt": "BasicCodeDocumenter"
327
- }
328
315
  ```
329
316
 
317
+ ### About “file: src/cli.ts”
318
+ Many Knowhow prompt templates also include a filename header (often formatted like `file: src/cli.ts`) above the `{text}` block. In your own prompts, follow the same pattern you see in the built-in prompts under `.knowhow/prompts/`.
319
+
330
320
  ---
331
321
 
332
- ## Practical examples
322
+ ## 8) Pipeline examples (transcribe → summarize → embed)
333
323
 
334
- ### 1) Generate docs for every source file (directory mode)
324
+ `knowhow generate` performs “summarize / document from inputs” steps. Embeddings are handled by a separate command (`knowhow embed`), but you can model a pipeline with multiple config sections.
335
325
 
336
- ```json
337
- {
338
- "sources": [
339
- {
340
- "input": "src/**/*.ts",
341
- "output": ".knowhow/docs/",
342
- "prompt": "BasicCodeDocumenter",
343
- "outputExt": "mdx",
344
- "agent": "Developer"
345
- }
346
- ]
347
- }
348
- ```
326
+ ### Example: Transcribe audio → generate summaries → embed them
349
327
 
350
- Result:
351
- - `.knowhow/docs/<same-folder-structure-as-src>/<filename>.mdx`
328
+ 1. **Transcribe step**
329
+ Use `sources` with an appropriate `kind` if you have a transcription plugin installed (or you can generate from already-transcribed text).
352
330
 
353
- ---
331
+ 2. **Summarize step**
332
+ Use `knowhow generate` to turn transcripts into markdown documents.
333
+
334
+ 3. **Embed step**
335
+ Use `embedSources` for chunking and embedding.
354
336
 
355
- ### 2) Generate one “project overview” doc from many inputs (single file mode)
337
+ Example config outline:
356
338
 
357
339
  ```json
358
340
  {
359
341
  "sources": [
360
342
  {
361
- "input": "src/**/*.ts",
362
- "output": ".knowhow/docs/OVERVIEW.mdx",
363
- "prompt": "BasicProjectDocumenter"
343
+ "input": "audio/**/*.txt",
344
+ "output": ".knowhow/transcripts/",
345
+ "prompt": "TranscriptSummarizer",
346
+ "outputExt": "mdx"
347
+ },
348
+ {
349
+ "input": ".knowhow/transcripts/**/*.mdx",
350
+ "output": ".knowhow/docs/AllSummaries.mdx",
351
+ "prompt": "ProjectSummary"
352
+ }
353
+ ],
354
+ "embedSources": [
355
+ {
356
+ "input": ".knowhow/docs/**/*.mdx",
357
+ "output": ".knowhow/embeddings/docs.json",
358
+ "prompt": "BasicEmbeddingExplainer",
359
+ "chunkSize": 2000
364
360
  }
365
361
  ]
366
362
  }
367
363
  ```
368
364
 
369
- Result:
370
- - One file: `.knowhow/docs/OVERVIEW.mdx`
365
+ Run sequence:
366
+ - `knowhow generate`
367
+ - `knowhow embed`
371
368
 
372
369
  ---
373
370
 
374
- ### 3) Use comma-separated input (combined behavior)
371
+ ## 9) Running for specific sources
375
372
 
376
- Comma-separated inputs are treated as brace-expanded patterns, but functionally they still match multiple files.
373
+ From the provided code, `generate()` loops through **all** entries in `config.sources`:
377
374
 
378
- ```json
379
- {
380
- "sources": [
381
- {
382
- "input": "src/a.ts,src/b.ts,src/c.ts",
383
- "output": ".knowhow/docs/SUBSET.mdx",
384
- "prompt": "BasicCodeDocumenter"
385
- }
386
- ]
375
+ ```ts
376
+ for (const source of config.sources) {
377
+ ...
387
378
  }
388
379
  ```
389
380
 
390
- Because `output` does not end with `/`, all matched inputs are combined into **one** output.
381
+ So, there isn’t an obvious built-in “select by name” mechanism shown here.
382
+
383
+ ### Practical approaches
384
+ - **Temporarily edit** `.knowhow/knowhow.json` to include only the sources you want to regenerate.
385
+ - Split sources into multiple config files/directories and swap configs (if your workflow supports it).
386
+ - Rely on caching: if your inputs and prompts haven’t changed, Knowhow will skip work automatically.
391
387
 
392
388
  ---
393
389
 
394
- ### 4) Use brace expansion directly
390
+ ## 10) Practical `sources` config examples
395
391
 
392
+ ### Example A: Generate one file per component (directory output)
396
393
  ```json
397
394
  {
398
395
  "sources": [
399
396
  {
400
- "input": "{src/controllers/*.ts,src/services/*.ts}",
401
- "output": ".knowhow/docs/",
402
- "prompt": "BasicCodeDocumenter"
397
+ "kind": "file",
398
+ "input": "src/components/**/*.ts",
399
+ "output": ".knowhow/docs/components/",
400
+ "prompt": "BasicCodeDocumenter",
401
+ "outputExt": "mdx",
402
+ "agent": "Developer",
403
+ "model": "gpt-5.4-nano"
403
404
  }
404
405
  ]
405
406
  }
406
407
  ```
407
408
 
408
- Directory mode: each input file becomes its own output file.
409
-
410
- ---
411
-
412
- ### 5) Inline prompt (no prompt file)
413
-
409
+ ### Example B: Generate a single README from multiple files (single-file output)
414
410
  ```json
415
411
  {
416
412
  "sources": [
417
413
  {
418
- "input": "src/index.ts",
419
- "output": ".knowhow/docs/index.mdx",
420
- "prompt": "Explain what this module does in plain English.\n\n{text}"
414
+ "input": "src/**/*.ts",
415
+ "output": ".knowhow/docs/README.mdx",
416
+ "prompt": "BasicProjectDocumenter"
421
417
  }
422
418
  ]
423
419
  }
424
420
  ```
425
421
 
426
- ---
427
-
428
- ## Pipeline example: generate → embed
429
-
430
- A common workflow is:
431
-
432
- 1. **Generate documentation files**
433
- 2. **Embed the generated docs** for search/RAG
434
-
435
- Your config already supports embedding in a separate `embedSources` array. A typical setup:
436
-
437
- ```jsonc
422
+ ### Example C: Combine a custom set of files using comma-separated input
423
+ ```json
438
424
  {
439
425
  "sources": [
440
426
  {
441
- "input": "src/**/*.ts",
442
- "output": ".knowhow/docs/",
427
+ "input": "src/cli.ts,src/config.ts,src/index.ts",
428
+ "output": ".knowhow/docs/CLI-Notes.mdx",
443
429
  "prompt": "BasicCodeDocumenter"
444
430
  }
445
- ],
446
- "embedSources": [
447
- {
448
- "input": ".knowhow/docs/**/*.mdx",
449
- "output": ".knowhow/embeddings/docs.json",
450
- "prompt": "BasicEmbeddingExplainer",
451
- "chunkSize": 2000
452
- }
453
431
  ]
454
432
  }
455
433
  ```
456
434
 
457
- Then run:
458
-
459
- ```bash
460
- knowhow generate
461
- knowhow embed
462
- ```
463
-
464
- ---
465
-
466
- ## Running for specific sources
467
-
468
- There is **no built-in CLI flag** in the shown `knowhow generate` command to select only one `sources[]` entry.
469
-
470
- To target a specific source you typically have two options:
471
-
472
- - **Temporarily edit** `.knowhow/knowhow.json` to comment out other `sources`
473
- - **Create a separate config** and adjust your workflow (the current CLI wiring shown does not expose a `--config` argument for `generate`)
474
-
475
435
  ---
476
436
 
477
- If you want, paste your current `.knowhow/knowhow.json` `sources` array and tell me whether you want **single-file** or **directory-per-input** outputs—I can help you rewrite it for the behavior you want.
437
+ If you want, paste your current `.knowhow/knowhow.json` `sources` section and the prompt(s) you’re using, and I’ll help you validate the config (including output folder structure expectations and caching behavior).