@tyvm/knowhow 0.0.109 → 0.0.111
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/autodoc/README.md +324 -0
- package/autodoc/chat-guide.md +268 -365
- package/autodoc/cli-reference.md +399 -473
- package/autodoc/config-reference.md +431 -330
- package/autodoc/embeddings-guide.md +223 -322
- package/autodoc/generate-guide.md +261 -301
- package/autodoc/language-plugin-guide.md +221 -247
- package/autodoc/modules-guide.md +242 -215
- package/autodoc/plugins-guide.md +470 -469
- package/autodoc/quickstart-guide.md +67 -70
- package/autodoc/skills-guide.md +455 -339
- package/autodoc/worker-guide.md +301 -308
- package/package.json +1 -1
- package/scripts/build-for-node.sh +10 -24
- package/src/agents/tools/list.ts +2 -2
- package/src/ai.ts +81 -37
- package/src/auth/browserLogin.ts +129 -3
- package/src/chat/CliChatService.ts +1 -1
- package/src/chat/modules/AgentModule.ts +7 -2
- package/src/chat/modules/SessionsModule.ts +40 -1
- package/src/chat/modules/SystemModule.ts +2 -2
- package/src/clients/anthropic.ts +1 -1
- package/src/clients/index.ts +25 -6
- package/src/clients/openai.ts +8 -5
- package/src/clients/types.ts +29 -6
- package/src/clients/withRetry.ts +89 -0
- package/src/commands/agent.ts +30 -0
- package/src/commands/modules.ts +417 -47
- package/src/config.ts +1 -1
- package/src/fileSync.ts +20 -12
- package/src/hashes.ts +43 -22
- package/src/index.ts +4 -2
- package/src/login.ts +3 -2
- package/src/processors/Base64ImageDetector.ts +73 -0
- package/src/services/Mcp.ts +14 -1
- package/src/services/MediaProcessorService.ts +79 -10
- package/src/services/modules/index.ts +47 -18
- package/src/utils/http.ts +9 -2
- package/tests/processors/Base64ImageDetector.test.ts +160 -0
- package/tests/unit/clients/AIClient.test.ts +446 -0
- package/tests/unit/clients/withRetry.test.ts +319 -0
- package/tests/unit/commands/github-credentials.test.ts +1 -2
- package/ts_build/package.json +1 -1
- package/ts_build/src/agents/tools/list.js +2 -2
- package/ts_build/src/agents/tools/list.js.map +1 -1
- package/ts_build/src/ai.d.ts +3 -3
- package/ts_build/src/ai.js +51 -23
- package/ts_build/src/ai.js.map +1 -1
- package/ts_build/src/auth/browserLogin.d.ts +2 -0
- package/ts_build/src/auth/browserLogin.js +91 -3
- package/ts_build/src/auth/browserLogin.js.map +1 -1
- package/ts_build/src/chat/CliChatService.js +1 -1
- package/ts_build/src/chat/CliChatService.js.map +1 -1
- package/ts_build/src/chat/modules/AgentModule.js +5 -2
- package/ts_build/src/chat/modules/AgentModule.js.map +1 -1
- package/ts_build/src/chat/modules/SessionsModule.js +30 -1
- package/ts_build/src/chat/modules/SessionsModule.js.map +1 -1
- package/ts_build/src/chat/modules/SystemModule.js +2 -2
- package/ts_build/src/chat/modules/SystemModule.js.map +1 -1
- package/ts_build/src/clients/anthropic.js +1 -1
- package/ts_build/src/clients/anthropic.js.map +1 -1
- package/ts_build/src/clients/index.js +7 -6
- package/ts_build/src/clients/index.js.map +1 -1
- package/ts_build/src/clients/openai.js +4 -4
- package/ts_build/src/clients/openai.js.map +1 -1
- package/ts_build/src/clients/types.d.ts +12 -6
- package/ts_build/src/clients/withRetry.d.ts +2 -0
- package/ts_build/src/clients/withRetry.js +60 -0
- package/ts_build/src/clients/withRetry.js.map +1 -0
- package/ts_build/src/commands/agent.js +25 -0
- package/ts_build/src/commands/agent.js.map +1 -1
- package/ts_build/src/commands/modules.js +359 -32
- package/ts_build/src/commands/modules.js.map +1 -1
- package/ts_build/src/config.js +1 -1
- package/ts_build/src/config.js.map +1 -1
- package/ts_build/src/fileSync.d.ts +2 -2
- package/ts_build/src/fileSync.js +13 -11
- package/ts_build/src/fileSync.js.map +1 -1
- package/ts_build/src/hashes.d.ts +2 -2
- package/ts_build/src/hashes.js +40 -16
- package/ts_build/src/hashes.js.map +1 -1
- package/ts_build/src/index.js +1 -1
- package/ts_build/src/index.js.map +1 -1
- package/ts_build/src/login.js +2 -2
- package/ts_build/src/login.js.map +1 -1
- package/ts_build/src/processors/Base64ImageDetector.d.ts +3 -0
- package/ts_build/src/processors/Base64ImageDetector.js +42 -0
- package/ts_build/src/processors/Base64ImageDetector.js.map +1 -1
- package/ts_build/src/services/Mcp.js +9 -1
- package/ts_build/src/services/Mcp.js.map +1 -1
- package/ts_build/src/services/MediaProcessorService.d.ts +5 -4
- package/ts_build/src/services/MediaProcessorService.js +53 -8
- package/ts_build/src/services/MediaProcessorService.js.map +1 -1
- package/ts_build/src/services/modules/index.js +35 -12
- package/ts_build/src/services/modules/index.js.map +1 -1
- package/ts_build/src/utils/http.d.ts +2 -1
- package/ts_build/src/utils/http.js +11 -2
- package/ts_build/src/utils/http.js.map +1 -1
- package/ts_build/tests/processors/Base64ImageDetector.test.js +111 -0
- package/ts_build/tests/processors/Base64ImageDetector.test.js.map +1 -1
- package/ts_build/tests/unit/clients/AIClient.test.d.ts +1 -0
- package/ts_build/tests/unit/clients/AIClient.test.js +339 -0
- package/ts_build/tests/unit/clients/AIClient.test.js.map +1 -0
- package/ts_build/tests/unit/clients/withRetry.test.d.ts +1 -0
- package/ts_build/tests/unit/clients/withRetry.test.js +225 -0
- package/ts_build/tests/unit/clients/withRetry.test.js.map +1 -0
- package/ts_build/tests/unit/commands/github-credentials.test.js +1 -2
- 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
|
|
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
|
-
|
|
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
|
-
|
|
21
|
+
### Output mode behavior (from the code)
|
|
32
22
|
|
|
33
|
-
|
|
23
|
+
#### A) Multi-output mode (directory output)
|
|
24
|
+
If `source.output` ends with `/`:
|
|
34
25
|
|
|
35
|
-
|
|
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
|
-
|
|
38
|
-
|
|
33
|
+
#### B) Single-output mode (single file output)
|
|
34
|
+
If `source.output` does **not** end with `/`:
|
|
39
35
|
|
|
40
|
-
|
|
36
|
+
- It writes **one** `source.output` file that contains combined results for **all** matched inputs.
|
|
41
37
|
|
|
42
|
-
|
|
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
|
-
|
|
40
|
+
## 2) `sources` configuration structure
|
|
56
41
|
|
|
57
|
-
|
|
42
|
+
Your `sources` array lives in `.knowhow/knowhow.json` under `sources`.
|
|
58
43
|
|
|
59
|
-
|
|
44
|
+
Each source entry is a `GenerationSource` with these commonly used fields:
|
|
60
45
|
|
|
61
|
-
### `input`
|
|
62
|
-
|
|
46
|
+
### `input`
|
|
47
|
+
Controls which files are processed. Supported formats (as implemented):
|
|
63
48
|
|
|
64
49
|
- **Single file**
|
|
65
50
|
```json
|
|
66
|
-
|
|
51
|
+
"input": "src/index.ts"
|
|
67
52
|
```
|
|
68
53
|
- **Glob**
|
|
69
54
|
```json
|
|
70
|
-
|
|
55
|
+
"input": "src/**/*.ts"
|
|
71
56
|
```
|
|
72
57
|
- **Comma-separated list**
|
|
73
58
|
```json
|
|
74
|
-
|
|
59
|
+
"input": "src/a.ts,src/b.ts,src/c.ts"
|
|
75
60
|
```
|
|
76
|
-
Comma
|
|
61
|
+
Comma lists are normalized into brace expansion internally.
|
|
77
62
|
- **Brace expansion**
|
|
78
63
|
```json
|
|
79
|
-
|
|
64
|
+
"input": "{src/a.ts,src/b.ts}"
|
|
80
65
|
```
|
|
81
66
|
|
|
82
|
-
|
|
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`
|
|
90
|
-
|
|
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
|
-
|
|
110
|
-
|
|
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
|
-
|
|
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`
|
|
122
|
-
Controls the AI
|
|
88
|
+
### `prompt`
|
|
89
|
+
Controls the prompt to use for AI generation.
|
|
123
90
|
|
|
124
|
-
|
|
91
|
+
Knowhow resolves `prompt` in this order:
|
|
125
92
|
|
|
126
|
-
1. **Prompt name
|
|
127
|
-
|
|
128
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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`
|
|
157
|
-
|
|
109
|
+
### `kind`
|
|
110
|
+
Special processing kind.
|
|
111
|
+
|
|
112
|
+
From the code:
|
|
158
113
|
|
|
159
|
-
- If `kind` is `"file"` **or missing
|
|
160
|
-
- Otherwise
|
|
161
|
-
-
|
|
162
|
-
-
|
|
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
|
-
|
|
121
|
+
**Practical takeaway:**
|
|
122
|
+
Use `kind` for plugin integrations; otherwise default file generation happens.
|
|
165
123
|
|
|
166
124
|
---
|
|
167
125
|
|
|
168
|
-
### `agent`
|
|
169
|
-
Selects which agent to use.
|
|
126
|
+
### `agent`
|
|
127
|
+
Selects which agent to use when calling the AI summarizer.
|
|
170
128
|
|
|
171
|
-
-
|
|
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`
|
|
177
|
-
Overrides the
|
|
133
|
+
### `model`
|
|
134
|
+
Overrides the model for this source.
|
|
135
|
+
|
|
136
|
+
- The value is passed to `summarizeFile(...)` / `summarizeFiles(...)`.
|
|
178
137
|
|
|
179
|
-
|
|
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`
|
|
185
|
-
Overrides the extension used for
|
|
142
|
+
### `outputExt`
|
|
143
|
+
Overrides the extension used for multi-output mode outputs.
|
|
186
144
|
|
|
187
|
-
Default:
|
|
145
|
+
- Default in multi-output handler: `"mdx"`
|
|
146
|
+
- Only applied when `output` ends with `/` (directory mode).
|
|
188
147
|
|
|
189
|
-
|
|
148
|
+
---
|
|
190
149
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
216
|
-
|
|
217
|
-
---
|
|
173
|
+
Knowhow reads:
|
|
174
|
+
- `.knowhow/prompts/MyPrompt.mdx`
|
|
218
175
|
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
176
|
+
### B) Direct prompt file path
|
|
177
|
+
Config:
|
|
178
|
+
```json
|
|
179
|
+
"prompt": "./prompts/MyPrompt.mdx"
|
|
180
|
+
```
|
|
222
181
|
|
|
223
|
-
|
|
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
|
-
|
|
229
|
-
|
|
184
|
+
### C) Inline prompt string
|
|
185
|
+
Config:
|
|
186
|
+
```json
|
|
187
|
+
"prompt": "Summarize the following code and output markdown with sections..."
|
|
188
|
+
```
|
|
230
189
|
|
|
231
|
-
|
|
232
|
-
|
|
190
|
+
### `{text}` placeholder requirement
|
|
191
|
+
Knowhow requires/ensures the prompt contains `{text}`.
|
|
233
192
|
|
|
234
|
-
|
|
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
|
|
198
|
+
## 4) Input patterns: examples
|
|
239
199
|
|
|
240
|
-
###
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
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
|
-
|
|
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
|
-
|
|
249
|
-
"
|
|
220
|
+
{
|
|
221
|
+
"input": "src/**/*.ts",
|
|
222
|
+
"output": ".knowhow/docs/",
|
|
223
|
+
"prompt": "BasicCodeDocumenter",
|
|
224
|
+
"outputExt": "mdx"
|
|
225
|
+
}
|
|
250
226
|
```
|
|
251
227
|
|
|
252
|
-
-
|
|
253
|
-
|
|
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
|
-
|
|
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
|
-
|
|
246
|
+
---
|
|
258
247
|
|
|
259
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
260
|
+
---
|
|
273
261
|
|
|
274
|
-
|
|
262
|
+
## 6) Hashing / caching: when outputs are skipped
|
|
275
263
|
|
|
276
|
-
|
|
264
|
+
Knowhow uses `.knowhow/.hashes.json` and stores hashes keyed by the input file path (and the prompt hash).
|
|
277
265
|
|
|
278
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
280
|
+
## 7) Writing good `.mdx` prompt files
|
|
293
281
|
|
|
294
|
-
|
|
282
|
+
Knowhow expects prompt files to be **MDX** templates (e.g. `.knowhow/prompts/MyPrompt.mdx`).
|
|
295
283
|
|
|
296
|
-
|
|
284
|
+
### Minimum requirement
|
|
285
|
+
Your prompt must include a `{text}` placeholder (Knowhow will add it if you forget).
|
|
297
286
|
|
|
298
|
-
###
|
|
287
|
+
### Recommended structure
|
|
288
|
+
A solid prompt usually asks for:
|
|
299
289
|
|
|
300
|
-
-
|
|
301
|
-
-
|
|
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
|
-
|
|
295
|
+
### Example prompt file: `.knowhow/prompts/BasicCodeDocumenter.mdx`
|
|
304
296
|
|
|
305
|
-
**`.knowhow/prompts/BasicCodeDocumenter.mdx`**
|
|
306
297
|
```mdx
|
|
307
|
-
#
|
|
298
|
+
# File documentation
|
|
299
|
+
|
|
300
|
+
You are a technical writer.
|
|
308
301
|
|
|
309
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
##
|
|
322
|
+
## 8) Pipeline examples (transcribe → summarize → embed)
|
|
333
323
|
|
|
334
|
-
|
|
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
|
-
|
|
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
|
-
|
|
351
|
-
-
|
|
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
|
-
|
|
337
|
+
Example config outline:
|
|
356
338
|
|
|
357
339
|
```json
|
|
358
340
|
{
|
|
359
341
|
"sources": [
|
|
360
342
|
{
|
|
361
|
-
"input": "
|
|
362
|
-
"output": ".knowhow/
|
|
363
|
-
"prompt": "
|
|
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
|
-
|
|
370
|
-
-
|
|
365
|
+
Run sequence:
|
|
366
|
+
- `knowhow generate`
|
|
367
|
+
- `knowhow embed`
|
|
371
368
|
|
|
372
369
|
---
|
|
373
370
|
|
|
374
|
-
|
|
371
|
+
## 9) Running for specific sources
|
|
375
372
|
|
|
376
|
-
|
|
373
|
+
From the provided code, `generate()` loops through **all** entries in `config.sources`:
|
|
377
374
|
|
|
378
|
-
```
|
|
379
|
-
{
|
|
380
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
"
|
|
401
|
-
"
|
|
402
|
-
"
|
|
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
|
-
|
|
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
|
|
419
|
-
"output": ".knowhow/docs/
|
|
420
|
-
"prompt": "
|
|
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
|
|
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`
|
|
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).
|