@tyvm/knowhow 0.0.88 → 0.0.90

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 (90) hide show
  1. package/CONFIG.md +52 -0
  2. package/README.md +344 -29
  3. package/WORKER.md +169 -334
  4. package/autodoc/chat-guide.md +540 -0
  5. package/autodoc/cli-reference.md +765 -0
  6. package/autodoc/config-reference.md +541 -0
  7. package/autodoc/embeddings-guide.md +566 -0
  8. package/autodoc/generate-guide.md +477 -0
  9. package/autodoc/language-plugin-guide.md +443 -0
  10. package/autodoc/modules-guide.md +352 -0
  11. package/autodoc/plugins-guide.md +720 -0
  12. package/autodoc/quickstart-guide.md +129 -0
  13. package/autodoc/skills-guide.md +468 -0
  14. package/autodoc/worker-guide.md +526 -0
  15. package/package.json +2 -2
  16. package/src/ai.ts +33 -2
  17. package/src/config.ts +28 -4
  18. package/src/index.ts +22 -2
  19. package/src/processors/TokenCompressor.ts +2 -2
  20. package/src/processors/ToolResponseCache.ts +3 -3
  21. package/src/processors/tools/grepToolResponse.ts +9 -4
  22. package/src/processors/tools/jqToolResponse.ts +11 -6
  23. package/src/processors/tools/listStoredToolResponses.ts +1 -1
  24. package/src/processors/tools/tailToolResponse.ts +9 -4
  25. package/src/worker.ts +9 -7
  26. package/ts_build/package.json +2 -2
  27. package/ts_build/src/ai.js +18 -1
  28. package/ts_build/src/ai.js.map +1 -1
  29. package/ts_build/src/config.js +17 -2
  30. package/ts_build/src/config.js.map +1 -1
  31. package/ts_build/src/index.js +12 -2
  32. package/ts_build/src/index.js.map +1 -1
  33. package/ts_build/src/processors/TokenCompressor.js +2 -2
  34. package/ts_build/src/processors/TokenCompressor.js.map +1 -1
  35. package/ts_build/src/processors/ToolResponseCache.js +3 -3
  36. package/ts_build/src/processors/ToolResponseCache.js.map +1 -1
  37. package/ts_build/src/processors/tools/grepToolResponse.d.ts +3 -1
  38. package/ts_build/src/processors/tools/grepToolResponse.js +8 -2
  39. package/ts_build/src/processors/tools/grepToolResponse.js.map +1 -1
  40. package/ts_build/src/processors/tools/jqToolResponse.d.ts +3 -1
  41. package/ts_build/src/processors/tools/jqToolResponse.js +10 -4
  42. package/ts_build/src/processors/tools/jqToolResponse.js.map +1 -1
  43. package/ts_build/src/processors/tools/listStoredToolResponses.js +1 -1
  44. package/ts_build/src/processors/tools/listStoredToolResponses.js.map +1 -1
  45. package/ts_build/src/processors/tools/tailToolResponse.d.ts +3 -1
  46. package/ts_build/src/processors/tools/tailToolResponse.js +8 -2
  47. package/ts_build/src/processors/tools/tailToolResponse.js.map +1 -1
  48. package/ts_build/src/worker.js +5 -3
  49. package/ts_build/src/worker.js.map +1 -1
  50. package/autodoc/chat.mdx +0 -20
  51. package/autodoc/cli.mdx +0 -11
  52. package/autodoc/plugins/asana.mdx +0 -47
  53. package/autodoc/plugins/downloader/downloader.mdx +0 -38
  54. package/autodoc/plugins/downloader/plugin.mdx +0 -37
  55. package/autodoc/plugins/downloader/types.mdx +0 -42
  56. package/autodoc/plugins/embedding.mdx +0 -41
  57. package/autodoc/plugins/figma.mdx +0 -45
  58. package/autodoc/plugins/github.mdx +0 -40
  59. package/autodoc/plugins/jira.mdx +0 -46
  60. package/autodoc/plugins/language.mdx +0 -37
  61. package/autodoc/plugins/linear.mdx +0 -35
  62. package/autodoc/plugins/notion.mdx +0 -38
  63. package/autodoc/plugins/plugins.mdx +0 -59
  64. package/autodoc/plugins/types.mdx +0 -51
  65. package/autodoc/plugins/vim.mdx +0 -39
  66. package/autodoc/tools/addInternalTools.mdx +0 -1
  67. package/autodoc/tools/agentCall.mdx +0 -1
  68. package/autodoc/tools/asana/definitions.mdx +0 -10
  69. package/autodoc/tools/asana/index.mdx +0 -12
  70. package/autodoc/tools/askHuman.mdx +0 -1
  71. package/autodoc/tools/callPlugin.mdx +0 -1
  72. package/autodoc/tools/embeddingSearch.mdx +0 -1
  73. package/autodoc/tools/execCommand.mdx +0 -1
  74. package/autodoc/tools/fileSearch.mdx +0 -1
  75. package/autodoc/tools/finalAnswer.mdx +0 -1
  76. package/autodoc/tools/github/definitions.mdx +0 -6
  77. package/autodoc/tools/github/index.mdx +0 -8
  78. package/autodoc/tools/index.mdx +0 -14
  79. package/autodoc/tools/lintFile.mdx +0 -7
  80. package/autodoc/tools/list.mdx +0 -16
  81. package/autodoc/tools/modifyFile.mdx +0 -7
  82. package/autodoc/tools/patch.mdx +0 -9
  83. package/autodoc/tools/readBlocks.mdx +0 -1
  84. package/autodoc/tools/readFile.mdx +0 -1
  85. package/autodoc/tools/scanFile.mdx +0 -1
  86. package/autodoc/tools/textSearch.mdx +0 -6
  87. package/autodoc/tools/types/fileblock.mdx +0 -1
  88. package/autodoc/tools/visionTool.mdx +0 -1
  89. package/autodoc/tools/writeFile.mdx +0 -1
  90. package/test-comprehensive.ts +0 -31
@@ -0,0 +1,443 @@
1
+ # Language Plugin Guide (Knowhow CLI)
2
+
3
+ The **Language Plugin** is one of the most powerful features of Knowhow. It lets you define custom **hotwords / terms** (like `frontend`, `backend`, `my PR`, `API`, `prod`) that automatically **inject context** into your chat sessions whenever you use those terms—pulling in **files, inline text, GitHub content, and URLs**.
4
+
5
+ ---
6
+
7
+ ## 1) What the Language Plugin does
8
+
9
+ When you send a message (or when certain file events occur), the Language Plugin:
10
+
11
+ 1. Loads your term configuration from **`.knowhow/language.json`**
12
+ 2. Finds which configured **term keys/patterns** match your input
13
+ 3. Expands each matching term into one or more **sources**:
14
+ - file contents from disk
15
+ - raw inline text
16
+ - GitHub PR/issue/file content
17
+ - content fetched from a URL
18
+ 4. Injects the loaded context into the session so your agent can answer using your real project/docs.
19
+
20
+ **In short:** typing a term like `API` can automatically attach your local API docs/specs—no copy/paste required.
21
+
22
+ ---
23
+
24
+ ## 2) Configuration file: `.knowhow/language.json`
25
+
26
+ Create or edit this file in your project:
27
+
28
+ ```text
29
+ ./.knowhow/language.json
30
+ ```
31
+
32
+ ### Example structure
33
+
34
+ ```jsonc
35
+ {
36
+ "term-or-pattern-key": {
37
+ "sources": [
38
+ { "kind": "file", "data": ["glob-or-path-1", "glob-or-path-2"] },
39
+ { "kind": "text", "data": "Inline raw text to inject" },
40
+ { "kind": "github","data": ["github input payload(s)"] },
41
+ { "kind": "url", "data": ["https://example.com/..."] }
42
+ ],
43
+ "events": ["file:open", "file:save"]
44
+ }
45
+ }
46
+ ```
47
+
48
+ ### Required fields
49
+ - **`sources`**: an array of source entries, each with:
50
+ - **`kind`**: one of `file`, `text`, `github`, `url`
51
+ - **`data`**: varies by kind (see section 4)
52
+
53
+ ### Optional fields
54
+ - **`events`**: an array of event names (commonly file events).
55
+ When present, the term is considered for **event-driven triggers** based on the file operation type.
56
+
57
+ ---
58
+
59
+ ## 3) Term matching (comma-separated keys + glob/wildcard matching)
60
+
61
+ ### Comma-separated keys = multiple match patterns
62
+
63
+ A single top-level JSON key can represent multiple patterns:
64
+
65
+ ```jsonc
66
+ {
67
+ "frontend, ui, web": {
68
+ "sources": [ /* ... */ ]
69
+ }
70
+ }
71
+ ```
72
+
73
+ This means any of these can trigger the same term expansion:
74
+ - `frontend`
75
+ - `ui`
76
+ - `web`
77
+
78
+ ### Matching behavior for generic prompt text
79
+
80
+ For normal chat input matching:
81
+
82
+ - If a pattern contains `*`, Knowhow treats it as a **glob/wildcard pattern**
83
+ - matching is performed with glob logic (e.g., via `minimatch`)
84
+ - Otherwise, Knowhow performs **case-insensitive substring** matching:
85
+ - `userPrompt.toLowerCase().includes(pattern.toLowerCase())`
86
+
87
+ **Implication:**
88
+ - Use `*` for families like `api*`, `payment*`, `spec-*`
89
+ - Use plain words for hotphrases like `API`, `prod`, `staging`
90
+
91
+ ### Matching behavior for file open/save events
92
+
93
+ For event-driven matching (file open/save), Knowhow checks patterns against the file:
94
+
95
+ - It only considers terms whose config includes the event type in **`events`**
96
+ - For each pattern in the comma-separated key:
97
+ - Match if `minimatch(filePath, pattern)` succeeds **(path glob match)**
98
+ **OR**
99
+ - Match if the file contents contain the pattern (case-insensitive substring match)
100
+
101
+ **Implication:**
102
+ - You can target files by **path globs** (recommended)
103
+ - Or by **content markers** when the path is unpredictable
104
+
105
+ ---
106
+
107
+ ## 4) Source kinds supported
108
+
109
+ A matching term expands into one or more sources. Knowhow supports these kinds:
110
+
111
+ ### `file` — load file contents (supports glob patterns)
112
+
113
+ Loads matching files from your repo/workspace.
114
+
115
+ - `data` is treated as a list of glob/path strings
116
+ - Each file is:
117
+ - checked to exist
118
+ - verified not to be a directory
119
+ - read as UTF-8
120
+
121
+ **Example:**
122
+
123
+ ```jsonc
124
+ {
125
+ "API, apis": {
126
+ "sources": [
127
+ { "kind": "file", "data": ["docs/api/**/*.md", "specs/openapi*.{json,yaml}"] }
128
+ ]
129
+ }
130
+ }
131
+ ```
132
+
133
+ > Tip: keep paths tight to avoid injecting huge irrelevant bundles.
134
+
135
+ ---
136
+
137
+ ### `text` — inline raw text
138
+
139
+ Injects literal text directly.
140
+
141
+ **Example:**
142
+
143
+ ```jsonc
144
+ {
145
+ "review rubric": {
146
+ "sources": [
147
+ {
148
+ "kind": "text",
149
+ "data": "Review checklist:\n- correctness\n- edge cases\n- performance\n- tests\n- migration plan\n"
150
+ }
151
+ ]
152
+ }
153
+ }
154
+ ```
155
+
156
+ ---
157
+
158
+ ### `github` — loads GitHub PR/issue/file content
159
+
160
+ This is resolved through the **GitHub plugin** mechanism. In the language config, you specify what you want loaded via `data`.
161
+
162
+ **Example (conceptual locator payloads):**
163
+
164
+ ```jsonc
165
+ {
166
+ "my PR, current PR": {
167
+ "sources": [
168
+ { "kind": "github", "data": ["CURRENT_PR"] }
169
+ ]
170
+ }
171
+ }
172
+ ```
173
+
174
+ > The exact `github` payload format depends on your GitHub plugin configuration, but the language plugin will delegate fetching/injection to that plugin.
175
+
176
+ ---
177
+
178
+ ### `url` — fetches a web URL
179
+
180
+ Resolved via the **URL plugin**. You provide the URL(s) in `data`.
181
+
182
+ **Example:**
183
+
184
+ ```jsonc
185
+ {
186
+ "k8s docs": {
187
+ "sources": [
188
+ { "kind": "url", "data": ["https://kubernetes.io/docs/home/"] }
189
+ ]
190
+ }
191
+ }
192
+ ```
193
+
194
+ ---
195
+
196
+ ## 5) Event-driven triggers (`events` field)
197
+
198
+ If you want terms to expand based on file activity (open/save), include an **`events`** array on the term.
199
+
200
+ Typical usage:
201
+
202
+ ```jsonc
203
+ {
204
+ "OpenAPI, swagger": {
205
+ "events": ["file:open", "file:save"],
206
+ "sources": [
207
+ { "kind": "file", "data": ["specs/openapi*.yaml", "specs/openapi*.json"] }
208
+ ]
209
+ }
210
+ }
211
+ ```
212
+
213
+ ### How it behaves
214
+ - Knowhow collects all event types referenced in `events`
215
+ - When those events occur, it:
216
+ - filters terms to those that include the active event
217
+ - runs matching against file path and (optionally) file contents
218
+ - injects the configured sources
219
+
220
+ ---
221
+
222
+ ## 6) Practical examples (full config snippets)
223
+
224
+ Below are copy/paste-friendly examples you can adapt.
225
+
226
+ > Put these entries into `./.knowhow/language.json`.
227
+
228
+ ---
229
+
230
+ ### Example A — Load frontend/backend architecture docs when you say “frontend” or “backend”
231
+
232
+ ```jsonc
233
+ {
234
+ "frontend, ui, web": {
235
+ "sources": [
236
+ { "kind": "file", "data": ["docs/architecture/frontend/**/*.md", "docs/architecture/web-frontend.md"] },
237
+ {
238
+ "kind": "text",
239
+ "data": "Frontend conventions:\n- Prefer feature-based folder structure\n- Keep API calls in data layer\n- Use typed DTOs\n"
240
+ }
241
+ ]
242
+ },
243
+
244
+ "backend, api, service": {
245
+ "sources": [
246
+ { "kind": "file", "data": ["docs/architecture/backend/**/*.md", "docs/architecture/services/**/*.md"] },
247
+ {
248
+ "kind": "text",
249
+ "data": "Backend conventions:\n- Validate at boundaries\n- Prefer idempotent endpoints when possible\n- Log correlation IDs\n"
250
+ }
251
+ ]
252
+ }
253
+ }
254
+ ```
255
+
256
+ **Workflow payoff**
257
+ - Ask: “How does auth work in the frontend?” → Knowhow injects frontend architecture docs automatically.
258
+ - Ask: “Where should we implement input validation in backend?” → Knowhow injects backend guidance.
259
+
260
+ ---
261
+
262
+ ### Example B — Load your current PR when you say “my PR”
263
+
264
+ ```jsonc
265
+ {
266
+ "my PR, current PR, pr": {
267
+ "sources": [
268
+ { "kind": "github", "data": ["CURRENT_PR"] },
269
+ {
270
+ "kind": "text",
271
+ "data": "Review approach:\n- Summarize intent\n- Identify risks (correctness, security, perf)\n- Suggest tests and rollback strategy\n"
272
+ }
273
+ ]
274
+ }
275
+ }
276
+ ```
277
+
278
+ **Workflow payoff**
279
+ - “Review my PR for concurrency issues and test coverage.”
280
+ - “Summarize changes + highlight any breaking behavior.”
281
+
282
+ ---
283
+
284
+ ### Example C — Load a spec file when you mention a feature name (wildcards)
285
+
286
+ Assume specs are organized like:
287
+
288
+ ```text
289
+ specs/features/<feature>.md
290
+ specs/features/<feature>/openapi*.yaml
291
+ ```
292
+
293
+ ```jsonc
294
+ {
295
+ "feature search, search feature": {
296
+ "sources": [
297
+ { "kind": "file", "data": ["specs/features/search.md", "specs/features/search/**/*.md"] }
298
+ ]
299
+ },
300
+
301
+ "payments*, payment*": {
302
+ "sources": [
303
+ { "kind": "file", "data": ["specs/features/payments*.md", "specs/features/payments/**/openapi*.{yaml,json}"] },
304
+ { "kind": "text", "data": "Focus for payments:\n- retries & idempotency\n- refund/reconciliation flows\n- edge cases\n" }
305
+ ]
306
+ }
307
+ }
308
+ ```
309
+
310
+ **How it works**
311
+ - `payments*` includes `*`, so it matches using wildcard/glob logic.
312
+ - `feature search` is a plain substring hotphrase.
313
+
314
+ **Workflow payoff**
315
+ - “Explain the payments retry strategy.” → injects payments specs automatically.
316
+
317
+ ---
318
+
319
+ ### Example D — Load API docs when you say “API”
320
+
321
+ ```jsonc
322
+ {
323
+ "API, apis, api documentation": {
324
+ "sources": [
325
+ { "kind": "file", "data": ["docs/api/**/*.md", "docs/api/**/*.mdx"] },
326
+ { "kind": "file", "data": ["specs/openapi*.json", "specs/openapi*.yaml"] },
327
+ {
328
+ "kind": "text",
329
+ "data": "API answering guidelines:\n- Prefer documented behavior\n- Include request/response schema notes\n- Call out auth and error codes\n- Mention rate limits and pagination\n"
330
+ }
331
+ ]
332
+ }
333
+ }
334
+ ```
335
+
336
+ **Workflow payoff**
337
+ - “What’s the contract for POST /sessions and what errors can it return?”
338
+ - “How do I authenticate for the payments endpoints?”
339
+
340
+ ---
341
+
342
+ ### Example E — Load environment info when you say “prod” or “staging”
343
+
344
+ ```jsonc
345
+ {
346
+ "prod, production, live": {
347
+ "sources": [
348
+ { "kind": "file", "data": ["ops/runbooks/prod/**/*.md"] },
349
+ { "kind": "file", "data": ["ops/env/prod.env.example", "ops/env/prod.*.example"] },
350
+ { "kind": "url", "data": ["https://status.yourcompany.com/"] }
351
+ ]
352
+ },
353
+
354
+ "staging, stage, preprod": {
355
+ "sources": [
356
+ { "kind": "file", "data": ["ops/runbooks/staging/**/*.md"] },
357
+ { "kind": "file", "data": ["ops/env/staging.env.example"] }
358
+ ]
359
+ }
360
+ }
361
+ ```
362
+
363
+ **Workflow payoff**
364
+ - “How do we roll out this change to prod safely?”
365
+ - “What’s the rollback procedure for staging failures?”
366
+
367
+ ---
368
+
369
+ ## 7) Dynamic language terms (runtime): `addLanguageTerm` tool
370
+
371
+ Static `.knowhow/language.json` is great, but sometimes you want **temporary terms** created at runtime—for example:
372
+ - “incident-123” should load the incident doc
373
+ - “release candidate 1.2.3” should load the right notes
374
+ - “my PR” should load the PR for the current branch/selection
375
+
376
+ Knowhow provides an `addLanguageTerm` capability to add language terms during execution.
377
+
378
+ ### Typical pattern (conceptual)
379
+ 1. Call `addLanguageTerm` with:
380
+ - the term key
381
+ - its sources (kind/data)
382
+ - optional `events`
383
+ 2. The new term becomes matchable immediately
384
+ 3. Next user message can trigger it
385
+
386
+ **Example (conceptual)**
387
+ ```ts
388
+ addLanguageTerm({
389
+ key: "incident-123",
390
+ sources: [
391
+ { kind: "file", data: ["ops/incidents/incident-123.md"] }
392
+ ]
393
+ });
394
+ ```
395
+
396
+ **Workflow payoff**
397
+ - During an incident response flow, you can dynamically register terms so the agent always references the correct incident/runbook material.
398
+
399
+ > Exact tool argument shapes vary by environment, but the core idea is: **runtime registration of term → sources**.
400
+
401
+ ---
402
+
403
+ ## 8) Global vs local language config
404
+
405
+ ### Local (project) config
406
+ - Active config for term matching:
407
+ - `./.knowhow/language.json`
408
+
409
+ ### Global config
410
+ - Your Knowhow installation may create a template at:
411
+ - `~/.knowhow/language.json`
412
+ - Whether it is merged automatically depends on your Knowhow version/config behavior.
413
+
414
+ ### Recommended practice
415
+ - Put **project/team-specific** rules in `./.knowhow/language.json`
416
+ - architecture docs
417
+ - feature specs
418
+ - environment runbooks
419
+ - repo-specific review rubrics
420
+ - If you maintain global defaults, keep them **broad and non-conflicting**
421
+ - e.g., standard “review rubric”, “testing strategy”, “security checklist”
422
+
423
+ **Tip:** avoid overly broad patterns like `"api"` if other teams/tools use the same word differently—prefer `"API,"` or `"api docs"`.
424
+
425
+ ---
426
+
427
+ ## Best practices (real-world)
428
+
429
+ - **Target sources tightly**
430
+ - A “frontend” term that injects *every* frontend file can overwhelm answers.
431
+ - **Use globs intentionally**
432
+ - Great: `payments*`, `openapi*`, `docs/api/**/*.md`
433
+ - Risky: `*` or extremely short substrings that match too often
434
+ - **Use `events` for file-driven workflows**
435
+ - Example: expand API spec context only when editing OpenAPI files.
436
+ - **Layer sources**
437
+ - Combine `file` (authoritative docs) + `text` (answering rules)
438
+ - **Prefer human hotphrases**
439
+ - `my PR`, `release notes`, `prod rollback`, `incident <id>`
440
+
441
+ ---
442
+
443
+ If you paste your current directory structure (or a redacted `.knowhow/language.json`), I can propose an optimized set of term keys + globs tailored to your repo and workflows.