@tyvm/knowhow 0.0.89 → 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.
- package/CONFIG.md +52 -0
- package/README.md +344 -29
- package/WORKER.md +169 -334
- package/autodoc/chat-guide.md +540 -0
- package/autodoc/cli-reference.md +765 -0
- package/autodoc/config-reference.md +541 -0
- package/autodoc/embeddings-guide.md +566 -0
- package/autodoc/generate-guide.md +477 -0
- package/autodoc/language-plugin-guide.md +443 -0
- package/autodoc/modules-guide.md +352 -0
- package/autodoc/plugins-guide.md +720 -0
- package/autodoc/quickstart-guide.md +129 -0
- package/autodoc/skills-guide.md +468 -0
- package/autodoc/worker-guide.md +526 -0
- package/package.json +1 -1
- package/src/ai.ts +33 -2
- package/src/config.ts +28 -4
- package/src/index.ts +22 -2
- package/src/processors/TokenCompressor.ts +2 -2
- package/src/processors/ToolResponseCache.ts +3 -3
- package/src/processors/tools/grepToolResponse.ts +9 -4
- package/src/processors/tools/jqToolResponse.ts +11 -6
- package/src/processors/tools/listStoredToolResponses.ts +1 -1
- package/src/processors/tools/tailToolResponse.ts +9 -4
- package/ts_build/package.json +1 -1
- package/ts_build/src/ai.js +18 -1
- package/ts_build/src/ai.js.map +1 -1
- package/ts_build/src/config.js +17 -2
- package/ts_build/src/config.js.map +1 -1
- package/ts_build/src/index.js +12 -2
- package/ts_build/src/index.js.map +1 -1
- package/ts_build/src/processors/TokenCompressor.js +2 -2
- package/ts_build/src/processors/TokenCompressor.js.map +1 -1
- package/ts_build/src/processors/ToolResponseCache.js +3 -3
- package/ts_build/src/processors/ToolResponseCache.js.map +1 -1
- package/ts_build/src/processors/tools/grepToolResponse.d.ts +3 -1
- package/ts_build/src/processors/tools/grepToolResponse.js +8 -2
- package/ts_build/src/processors/tools/grepToolResponse.js.map +1 -1
- package/ts_build/src/processors/tools/jqToolResponse.d.ts +3 -1
- package/ts_build/src/processors/tools/jqToolResponse.js +10 -4
- package/ts_build/src/processors/tools/jqToolResponse.js.map +1 -1
- package/ts_build/src/processors/tools/listStoredToolResponses.js +1 -1
- package/ts_build/src/processors/tools/listStoredToolResponses.js.map +1 -1
- package/ts_build/src/processors/tools/tailToolResponse.d.ts +3 -1
- package/ts_build/src/processors/tools/tailToolResponse.js +8 -2
- package/ts_build/src/processors/tools/tailToolResponse.js.map +1 -1
- package/autodoc/chat.mdx +0 -20
- package/autodoc/cli.mdx +0 -11
- package/autodoc/plugins/asana.mdx +0 -47
- package/autodoc/plugins/downloader/downloader.mdx +0 -38
- package/autodoc/plugins/downloader/plugin.mdx +0 -37
- package/autodoc/plugins/downloader/types.mdx +0 -42
- package/autodoc/plugins/embedding.mdx +0 -41
- package/autodoc/plugins/figma.mdx +0 -45
- package/autodoc/plugins/github.mdx +0 -40
- package/autodoc/plugins/jira.mdx +0 -46
- package/autodoc/plugins/language.mdx +0 -37
- package/autodoc/plugins/linear.mdx +0 -35
- package/autodoc/plugins/notion.mdx +0 -38
- package/autodoc/plugins/plugins.mdx +0 -59
- package/autodoc/plugins/types.mdx +0 -51
- package/autodoc/plugins/vim.mdx +0 -39
- package/autodoc/tools/addInternalTools.mdx +0 -1
- package/autodoc/tools/agentCall.mdx +0 -1
- package/autodoc/tools/asana/definitions.mdx +0 -10
- package/autodoc/tools/asana/index.mdx +0 -12
- package/autodoc/tools/askHuman.mdx +0 -1
- package/autodoc/tools/callPlugin.mdx +0 -1
- package/autodoc/tools/embeddingSearch.mdx +0 -1
- package/autodoc/tools/execCommand.mdx +0 -1
- package/autodoc/tools/fileSearch.mdx +0 -1
- package/autodoc/tools/finalAnswer.mdx +0 -1
- package/autodoc/tools/github/definitions.mdx +0 -6
- package/autodoc/tools/github/index.mdx +0 -8
- package/autodoc/tools/index.mdx +0 -14
- package/autodoc/tools/lintFile.mdx +0 -7
- package/autodoc/tools/list.mdx +0 -16
- package/autodoc/tools/modifyFile.mdx +0 -7
- package/autodoc/tools/patch.mdx +0 -9
- package/autodoc/tools/readBlocks.mdx +0 -1
- package/autodoc/tools/readFile.mdx +0 -1
- package/autodoc/tools/scanFile.mdx +0 -1
- package/autodoc/tools/textSearch.mdx +0 -6
- package/autodoc/tools/types/fileblock.mdx +0 -1
- package/autodoc/tools/visionTool.mdx +0 -1
- package/autodoc/tools/writeFile.mdx +0 -1
- package/test-comprehensive.ts +0 -31
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
# Knowhow Custom Modules Guide
|
|
2
|
+
|
|
3
|
+
Knowhow **modules** are the primary extension mechanism for adding new capabilities to the Knowhow CLI/runtime. A module is a dynamically loaded package (an npm package or a local file) that can register **tools**, **agents**, **plugins**, **AI clients**, and **chat commands**.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 1) What modules are
|
|
8
|
+
|
|
9
|
+
When Knowhow starts, it reads configuration and **dynamically loads** each configured module. A module can extend Knowhow by contributing any of the following:
|
|
10
|
+
|
|
11
|
+
- **Tools**: functions that Knowhow/agents can call (tool calling)
|
|
12
|
+
- **Agents**: preconfigured agent definitions (prompts, tool access, etc.)
|
|
13
|
+
- **Plugins**: plugin objects registered under a module-provided name
|
|
14
|
+
- **AI clients**: provider/client/model registrations for model routing
|
|
15
|
+
- **Commands**: additional chat commands supported by the module
|
|
16
|
+
- **Initialization hook (`init`)**: async setup work before registration
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## 2) Configuring modules (`knowhow.json`)
|
|
21
|
+
|
|
22
|
+
In your project’s `knowhow.json`, add a `modules` array.
|
|
23
|
+
|
|
24
|
+
```jsonc
|
|
25
|
+
{
|
|
26
|
+
"modules": [
|
|
27
|
+
"@acme/knowhow-module-internal-api",
|
|
28
|
+
"./modules/local-module.js"
|
|
29
|
+
]
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Supported module entries
|
|
34
|
+
Each entry supports both:
|
|
35
|
+
|
|
36
|
+
- **npm package names** (e.g. `@acme/knowhow-module-internal-api`)
|
|
37
|
+
- **local file paths** (e.g. `./modules/local-module.js`)
|
|
38
|
+
|
|
39
|
+
> Tip: Use the correct extension/format for your runtime (often compiled `.js`). If you author in TypeScript, compile to a Node-loadable format first.
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
## 3) Global vs local modules
|
|
44
|
+
|
|
45
|
+
Knowhow supports both a global and local configuration:
|
|
46
|
+
|
|
47
|
+
1. **Global config**: `~/.knowhow/knowhow.json`
|
|
48
|
+
2. **Local config**: your project’s `knowhow.json`
|
|
49
|
+
|
|
50
|
+
### Load order
|
|
51
|
+
Modules load in this order:
|
|
52
|
+
|
|
53
|
+
1. **Global modules** from `~/.knowhow/knowhow.json` load **first**
|
|
54
|
+
2. **Local modules** from `./knowhow.json` load **after**
|
|
55
|
+
|
|
56
|
+
This means local modules can add additional capabilities or change behavior depending on how Knowhow merges/handles registrations (for example, tool name conflicts).
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
## 4) The `KnowhowModule` interface
|
|
61
|
+
|
|
62
|
+
A module must export an object compatible with the `KnowhowModule` interface. At minimum, a module must provide:
|
|
63
|
+
|
|
64
|
+
### `init(params)` (async initialization)
|
|
65
|
+
```ts
|
|
66
|
+
async init(params): Promise<void>
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Knowhow calls `init` during module loading so you can perform setup such as:
|
|
70
|
+
|
|
71
|
+
- validate config
|
|
72
|
+
- read environment variables/secrets
|
|
73
|
+
- initialize API clients
|
|
74
|
+
- precompute schemas or caches
|
|
75
|
+
|
|
76
|
+
### `tools`
|
|
77
|
+
```ts
|
|
78
|
+
tools: Array<{
|
|
79
|
+
name: string;
|
|
80
|
+
handler: (...args: any[]) => any;
|
|
81
|
+
definition: any;
|
|
82
|
+
}>
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Your module provides tools as entries with:
|
|
86
|
+
- **`name`**: the tool name
|
|
87
|
+
- **`handler`**: the implementation function
|
|
88
|
+
- **`definition`**: tool metadata/schema
|
|
89
|
+
|
|
90
|
+
#### Important: tool definition shape
|
|
91
|
+
In Knowhow’s tool registration flow, tool metadata is used to register the tool, and the tool handler is bound using the tool definition’s function name. That implies your `definition` must include a function name (commonly via something like `definition.function.name`).
|
|
92
|
+
|
|
93
|
+
A typical definition looks like:
|
|
94
|
+
|
|
95
|
+
```ts
|
|
96
|
+
{
|
|
97
|
+
type: "function",
|
|
98
|
+
function: {
|
|
99
|
+
name: "my_tool",
|
|
100
|
+
description: "...",
|
|
101
|
+
parameters: { /* JSON-schema-like */ }
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### `agents`
|
|
107
|
+
```ts
|
|
108
|
+
agents: any[] // array of agent configs (shape depends on Knowhow)
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Agents are module-provided configurations. The exact schema depends on your Knowhow version, but typically includes:
|
|
112
|
+
|
|
113
|
+
- agent name
|
|
114
|
+
- instructions/system prompt
|
|
115
|
+
- allowed tools (by tool name)
|
|
116
|
+
- model/provider selection (or references to registered clients/models)
|
|
117
|
+
|
|
118
|
+
### `plugins`
|
|
119
|
+
```ts
|
|
120
|
+
plugins: Array<{
|
|
121
|
+
name: string;
|
|
122
|
+
plugin: any; // plugin instance/object
|
|
123
|
+
}>
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### `clients`
|
|
127
|
+
```ts
|
|
128
|
+
clients: Array<{
|
|
129
|
+
provider: string;
|
|
130
|
+
client: any; // AI client instance/constructor
|
|
131
|
+
models: string[]; // supported model IDs
|
|
132
|
+
}>
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### `commands`
|
|
136
|
+
```ts
|
|
137
|
+
commands: any[] // chat commands
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
Commands are additional chat-loop commands exposed by your module (exact handler signature depends on Knowhow’s command system).
|
|
141
|
+
|
|
142
|
+
---
|
|
143
|
+
|
|
144
|
+
## 5) Writing a custom module (step-by-step)
|
|
145
|
+
|
|
146
|
+
Below is a practical workflow with a concrete example at the end.
|
|
147
|
+
|
|
148
|
+
### Step 1 — Create the module file
|
|
149
|
+
Example layout:
|
|
150
|
+
|
|
151
|
+
```
|
|
152
|
+
your-project/
|
|
153
|
+
knowhow.json
|
|
154
|
+
modules/
|
|
155
|
+
hello-module.js (or hello-module.ts compiled to js)
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### Step 2 — Implement `init(params)`
|
|
159
|
+
Create an async function that performs any setup once at startup.
|
|
160
|
+
|
|
161
|
+
### Step 3 — Add a custom tool (with a definition)
|
|
162
|
+
Add a tool entry:
|
|
163
|
+
- choose a unique tool `name`
|
|
164
|
+
- implement `handler`
|
|
165
|
+
- provide `definition` with a callable-function name (commonly `definition.function.name`)
|
|
166
|
+
|
|
167
|
+
### Step 4 — Add a custom agent
|
|
168
|
+
Add an agent config referencing your tools and setting prompt/model behavior.
|
|
169
|
+
|
|
170
|
+
### Step 5 — Register the module in `knowhow.json`
|
|
171
|
+
Add your module path or npm package to the `modules` array.
|
|
172
|
+
|
|
173
|
+
---
|
|
174
|
+
|
|
175
|
+
## 6) Plugin packages (`pluginPackages`)
|
|
176
|
+
|
|
177
|
+
In addition to full **modules**, Knowhow can load **plugin-only** npm packages via a configuration map called `pluginPackages`.
|
|
178
|
+
|
|
179
|
+
Conceptually, Knowhow will iterate `pluginPackages` entries and load/instantiate them, typically expecting a default export that represents a plugin constructor/class.
|
|
180
|
+
|
|
181
|
+
Example (conceptual):
|
|
182
|
+
|
|
183
|
+
```jsonc
|
|
184
|
+
{
|
|
185
|
+
"pluginPackages": {
|
|
186
|
+
"acme-lint": "@acme/knowhow-plugin-eslint",
|
|
187
|
+
"kb": "./plugins/my-kb-plugin.js"
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
**Use `pluginPackages` when** your package is intended to register plugins only and doesn’t need to define tools/agents/clients.
|
|
193
|
+
|
|
194
|
+
---
|
|
195
|
+
|
|
196
|
+
## 7) Use cases
|
|
197
|
+
|
|
198
|
+
Modules are ideal for connecting Knowhow to your organization’s environment, for example:
|
|
199
|
+
|
|
200
|
+
1. **Connect to internal APIs**
|
|
201
|
+
- Build tools like `internal_ticket_create`, `internal_user_lookup`, `internal_doc_search`
|
|
202
|
+
- Use `init` to authenticate and construct API clients
|
|
203
|
+
|
|
204
|
+
2. **Custom tools**
|
|
205
|
+
- Wrap internal services as LLM-callable tools
|
|
206
|
+
- Provide JSON-schema-like definitions so agents can call them safely
|
|
207
|
+
|
|
208
|
+
3. **Company-specific agents**
|
|
209
|
+
- Ship agents tuned for your workflows (support triage, engineering review, compliance checks)
|
|
210
|
+
- Restrict agents to only the tools you want them to use
|
|
211
|
+
|
|
212
|
+
4. **Custom AI clients**
|
|
213
|
+
- Register model providers that point to internal gateways or custom hosting
|
|
214
|
+
- Limit allowed models to those approved by your org
|
|
215
|
+
|
|
216
|
+
---
|
|
217
|
+
|
|
218
|
+
## Complete working TypeScript example (minimal module)
|
|
219
|
+
|
|
220
|
+
> This is a minimal module that:
|
|
221
|
+
> - implements `init`
|
|
222
|
+
> - registers one tool with a `definition.function.name`
|
|
223
|
+
> - registers one agent
|
|
224
|
+
> - leaves plugins/clients empty
|
|
225
|
+
> - registers one chat command
|
|
226
|
+
>
|
|
227
|
+
> **Save as:** `modules/minimal-module.ts`
|
|
228
|
+
> **Compile to JS** (CommonJS or runtime-compatible output), then reference the compiled `.js` in `knowhow.json`.
|
|
229
|
+
|
|
230
|
+
### `modules/minimal-module.ts`
|
|
231
|
+
```ts
|
|
232
|
+
// modules/minimal-module.ts
|
|
233
|
+
|
|
234
|
+
// If you have the exact Knowhow types in your repo, replace `any` with real imports.
|
|
235
|
+
// This example is intentionally robust against type mismatches.
|
|
236
|
+
|
|
237
|
+
type ToolDefinition = {
|
|
238
|
+
type: "function";
|
|
239
|
+
function: {
|
|
240
|
+
name: string;
|
|
241
|
+
description?: string;
|
|
242
|
+
parameters?: any;
|
|
243
|
+
};
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
type KnowhowModule = {
|
|
247
|
+
init: (params: { config: any; cwd: string }) => Promise<void> | void;
|
|
248
|
+
tools: Array<{
|
|
249
|
+
name: string;
|
|
250
|
+
handler: (args: any) => Promise<any> | any;
|
|
251
|
+
definition: ToolDefinition;
|
|
252
|
+
}>;
|
|
253
|
+
agents: any[];
|
|
254
|
+
plugins: Array<{ name: string; plugin: any }>;
|
|
255
|
+
clients: Array<{ provider: string; client: any; models: string[] }>;
|
|
256
|
+
commands: any[];
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
const toolDefinition: ToolDefinition = {
|
|
260
|
+
type: "function",
|
|
261
|
+
function: {
|
|
262
|
+
name: "demo_echo",
|
|
263
|
+
description: "Echoes input back to the caller.",
|
|
264
|
+
parameters: {
|
|
265
|
+
type: "object",
|
|
266
|
+
properties: {
|
|
267
|
+
text: { type: "string", description: "Text to echo" }
|
|
268
|
+
},
|
|
269
|
+
required: ["text"],
|
|
270
|
+
additionalProperties: false
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
const module: KnowhowModule = {
|
|
276
|
+
// 1) Required async initialization hook
|
|
277
|
+
async init({ config, cwd }) {
|
|
278
|
+
// Example: validate config or prepare resources once at startup
|
|
279
|
+
// console.log("[minimal-module] init", { cwd, hasConfig: !!config });
|
|
280
|
+
void config;
|
|
281
|
+
void cwd;
|
|
282
|
+
},
|
|
283
|
+
|
|
284
|
+
// 2) Tool registrations
|
|
285
|
+
tools: [
|
|
286
|
+
{
|
|
287
|
+
name: "demo_echo",
|
|
288
|
+
definition: toolDefinition,
|
|
289
|
+
|
|
290
|
+
// Important: handler is bound to definition.function.name by Knowhow’s loader
|
|
291
|
+
handler: async (args: any) => {
|
|
292
|
+
const text = typeof args?.text === "string" ? args.text : "";
|
|
293
|
+
return { echoed: text };
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
],
|
|
297
|
+
|
|
298
|
+
// 3) Agent registrations (shape depends on Knowhow’s IAgent schema)
|
|
299
|
+
agents: [
|
|
300
|
+
{
|
|
301
|
+
name: "demo-echo-agent",
|
|
302
|
+
description: "A demo agent that can call demo_echo.",
|
|
303
|
+
// Common pattern: restrict the agent to specific tools by name
|
|
304
|
+
tools: ["demo_echo"],
|
|
305
|
+
// Provide instructions/prompt. (Field names vary by Knowhow version.)
|
|
306
|
+
systemPrompt: "You are a demo agent. When asked to echo, call demo_echo."
|
|
307
|
+
}
|
|
308
|
+
],
|
|
309
|
+
|
|
310
|
+
// 4) Plugin registrations (optional)
|
|
311
|
+
plugins: [],
|
|
312
|
+
|
|
313
|
+
// 5) AI client registrations (optional)
|
|
314
|
+
clients: [],
|
|
315
|
+
|
|
316
|
+
// 6) Chat commands (optional; exact handler signature depends on Knowhow)
|
|
317
|
+
commands: [
|
|
318
|
+
{
|
|
319
|
+
name: "/echo",
|
|
320
|
+
description: "Echo text using the demo_echo tool.",
|
|
321
|
+
handler: (ctx: any) => {
|
|
322
|
+
// This is a minimal placeholder. Depending on Knowhow’s command system,
|
|
323
|
+
// you may need to call a tool runner from ctx.
|
|
324
|
+
const raw = typeof ctx?.args === "string" ? ctx.args : ctx?.args?.text;
|
|
325
|
+
const text = typeof raw === "string" ? raw : "hello";
|
|
326
|
+
ctx?.reply?.({ text: `Echo: ${text}` });
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
]
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
// Export strategy:
|
|
333
|
+
// - If your Knowhow loader uses require(), CommonJS export can be safest.
|
|
334
|
+
// - This `export =` pattern works with CommonJS outputs.
|
|
335
|
+
export = module;
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
### Register it in `knowhow.json`
|
|
339
|
+
|
|
340
|
+
After compiling, point to the compiled JS file, for example:
|
|
341
|
+
|
|
342
|
+
```jsonc
|
|
343
|
+
{
|
|
344
|
+
"modules": [
|
|
345
|
+
"./modules/dist/minimal-module.js"
|
|
346
|
+
]
|
|
347
|
+
}
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
---
|
|
351
|
+
|
|
352
|
+
If you paste (or link) the exact `KnowhowModule`, `Tool` definition, and `IAgent` type shapes from your source tree, I can tailor the example to be **fully type-checked** (no `any`) and ensure your command handler matches the exact runtime signature.
|