knowz-mcp 0.4.0

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.
@@ -0,0 +1,877 @@
1
+ ---
2
+ name: knowz
3
+ description: "Search, save, query, and manage knowledge in Knowz vaults. Use when the user wants to find knowledge, save an insight, ask a question, browse vaults, configure vault connections, register for an account, or interact with the Knowz knowledge base in any way."
4
+ user-invocable: true
5
+ allowed-tools: Read, Write, Bash, Glob, Grep, AskUserQuestion
6
+ argument-hint: "ask|save|search|browse|setup|status|register|flush [query or content]"
7
+ ---
8
+
9
+ # Knowz — Frictionless Knowledge Management
10
+
11
+ You are the **Knowz skill**. You provide frictionless interaction with the Knowz MCP server, routing all operations through a vault configuration file (`knowz-vaults.md`) when available.
12
+
13
+ ## Enterprise Configuration
14
+
15
+ Before using any endpoints or brand names below, check for an `enterprise.json` file in the plugin root directory (the directory containing `.claude-plugin/plugin.json`). Read it once at the start of any action.
16
+
17
+ If the file exists, use its values:
18
+ - `brand` → replaces "Knowz" in all user-facing messages (e.g., "Welcome to {brand}", "{brand} MCP server")
19
+ - `mcp_endpoint` → replaces `https://mcp.knowz.io/mcp` in all MCP commands and references
20
+ - `api_endpoint` → replaces `https://api.knowz.io/api/v1` in all API calls (e.g., registration: `{api_endpoint}/auth/register`)
21
+
22
+ If the file is absent or a field is missing, use the defaults:
23
+ - brand: `Knowz`
24
+ - mcp_endpoint: `https://mcp.knowz.io/mcp`
25
+ - api_endpoint: `https://api.knowz.io/api/v1`
26
+
27
+ When `enterprise.json` is present, ignore the `--dev` flag for endpoint selection — the enterprise config provides the canonical endpoints.
28
+
29
+ ## Command Syntax
30
+
31
+ ```bash
32
+ /knowz ask "question" # AI-powered Q&A against vaults
33
+ /knowz save "insight" # Capture knowledge to a vault
34
+ /knowz search "query" # Semantic search across vaults
35
+ /knowz browse [vault-name] # Browse vault contents and topics
36
+ /knowz setup [api-key] [--oauth] # Configure MCP + create/update knowz-vaults.md
37
+ /knowz status # Check MCP connection and vault health
38
+ /knowz register [--dev] # Create account + configure MCP + set up vault
39
+ /knowz flush # Process pending captures queue
40
+ /knowz "bare question or insight" # Auto-detect intent
41
+ ```
42
+
43
+ ## Intent Detection from `$ARGUMENTS`
44
+
45
+ Parse the first word of `$ARGUMENTS` to determine the action:
46
+
47
+ | Prefix / Signal | Action | Primary MCP Tool |
48
+ |---|---|---|
49
+ | `ask "question"` | AI-powered Q&A | `mcp__knowz__ask_question` |
50
+ | `save "insight"` / `learn "insight"` | Capture knowledge | `mcp__knowz__create_knowledge` |
51
+ | `search "query"` / `find "query"` | Semantic search | `mcp__knowz__search_knowledge` |
52
+ | `browse` / `list` | Browse vault contents | `mcp__knowz__list_vault_contents`, `mcp__knowz__list_topics` |
53
+ | `setup` / `configure` / `config` | Configure MCP + vault file | `mcp__knowz__list_vaults` |
54
+ | `status` / `health` / `check` | Check connection and vault health | `mcp__knowz__list_vaults` |
55
+ | `register` / `signup` | Create account + configure | HTTP API |
56
+ | `flush` / `sync` | Process pending captures | `mcp__knowz__create_knowledge` |
57
+ | (bare question — contains `?`) | Auto-detect → ask | `mcp__knowz__ask_question` |
58
+ | (bare statement — no `?`, no prefix) | Auto-detect → save | `mcp__knowz__create_knowledge` |
59
+
60
+ ---
61
+
62
+ ## Step 0: Vault File Integration (ALWAYS runs first)
63
+
64
+ Before every action, regardless of intent:
65
+
66
+ 1. Look for `knowz-vaults.md` in the project root (the working directory)
67
+ 2. **If found** → parse the vault entries. Extract:
68
+ - Each vault's **name**, **ID**, **description**
69
+ - Each vault's **when to query** rules
70
+ - Each vault's **when to save** rules
71
+ - Each vault's **content template**
72
+ - The **default vault** from the `## Defaults` section
73
+ 3. **If not found** → zero-config mode:
74
+ - All MCP operations work but without vault scoping (no `vaultId` parameter)
75
+ - After completing the action, suggest: `"Tip: Run /knowz setup to create a knowz-vaults.md file for vault-aware routing."`
76
+
77
+ ---
78
+
79
+ ## Step 1: MCP Connectivity Check
80
+
81
+ Before any MCP operation, verify the Knowz MCP tools are available:
82
+
83
+ 1. Check that `mcp__knowz__list_vaults` exists in your available tools
84
+
85
+ 2. **If NOT available** → run `CLAUDECODE= claude mcp get knowz` to distinguish:
86
+
87
+ **a) Configured but not active** (command succeeds — MCP entry exists):
88
+ The server was configured in this session but Claude Code hasn't loaded it yet.
89
+ ```
90
+ ┌─────────────────────────────────────────────────────┐
91
+ │ RESTART REQUIRED │
92
+ │ │
93
+ │ Knowz MCP server is configured but not yet active. │
94
+ │ │
95
+ │ Claude Code only loads MCP servers at startup — │
96
+ │ this is a platform limitation, not a bug. │
97
+ │ │
98
+ │ → Close and reopen Claude Code │
99
+ │ → Then run: /knowz status │
100
+ └─────────────────────────────────────────────────────┘
101
+ ```
102
+ STOP here — do not attempt any MCP operations.
103
+
104
+ **b) Not configured** (command fails — no MCP entry found):
105
+ ```
106
+ Knowz MCP server is not connected.
107
+
108
+ To set it up:
109
+ /knowz register — create an account and configure automatically
110
+ /knowz setup — configure with an existing API key or OAuth
111
+
112
+ Or configure manually:
113
+ claude mcp add --transport http --scope local knowz https://mcp.knowz.io/mcp \
114
+ --header "Authorization: Bearer <your-api-key>"
115
+
116
+ Then restart Claude Code and run /knowz status to verify.
117
+ ```
118
+ STOP here — do not attempt any MCP operations.
119
+
120
+ 3. **If available:** Call `mcp__knowz__list_vaults()` as a connectivity smoke test
121
+ - If it succeeds → MCP is connected, proceed to the action
122
+ - If it fails with **401/unauthorized or OAuth error** → authentication issue:
123
+ ```
124
+ ┌─────────────────────────────────────────────────────┐
125
+ │ AUTHENTICATION FAILED │
126
+ │ │
127
+ │ The Knowz MCP server returned an auth error. │
128
+ │ │
129
+ │ If using OAuth: │
130
+ │ → Restart Claude Code — browser will open for │
131
+ │ login on the next MCP call │
132
+ │ → If this keeps happening, switch to API Key: │
133
+ │ /knowz setup <your-api-key> │
134
+ │ (no browser login or token refresh needed) │
135
+ │ │
136
+ │ If using API Key: │
137
+ │ → Your key may be invalid or expired │
138
+ │ → Get a new key at: https://knowz.io/api-keys │
139
+ │ → Reconfigure: /knowz setup <new-key> │
140
+ └─────────────────────────────────────────────────────┘
141
+ ```
142
+ - If it fails with **other error** → report with troubleshooting:
143
+ ```
144
+ Knowz MCP server is configured but returned an error:
145
+ {error message}
146
+
147
+ This usually means:
148
+ - The Knowz server is temporarily unreachable
149
+ - There's a network connectivity issue
150
+
151
+ Try:
152
+ - Verify network connectivity to the Knowz server
153
+ - Run "claude mcp list" to inspect server status
154
+ - If using OAuth and errors persist, consider switching to API Key
155
+ for more resilient connections: /knowz setup <api-key>
156
+ ```
157
+
158
+ ---
159
+
160
+ ## Action: `register`
161
+
162
+ Create a new Knowz account and automatically configure MCP + vault.
163
+
164
+ **Reference:** Read [references/registration.md](references/registration.md) for API endpoints, error codes, and response format.
165
+
166
+ ### Parameters
167
+
168
+ - `--scope <local|project|user>` — Configuration scope (default: `local`)
169
+ - `--dev` — Use development environment instead of production
170
+
171
+ ### Steps
172
+
173
+ #### Step R0: Smart Discovery
174
+
175
+ Before starting registration, check if user already has an API key:
176
+
177
+ 1. Check `KNOWZ_API_KEY` environment variable
178
+ 2. Check cross-platform configs: `.gemini/settings.json`, `.vscode/mcp.json`, `.mcp.json`
179
+ - Extract Bearer token from Authorization headers if found
180
+
181
+ If existing API key found:
182
+ ```
183
+ You already have a Knowz API key configured (ending ...{last4}) from {source}.
184
+
185
+ Options:
186
+ 1. Use existing key — run /knowz setup to configure this platform
187
+ 2. Register a new account anyway
188
+ 3. Cancel
189
+ ```
190
+
191
+ If user chooses option 1: advise running `/knowz setup` with discovered key.
192
+ If user chooses option 2: proceed with registration normally.
193
+ If user chooses option 3: stop.
194
+
195
+ #### Step R1: Check Existing MCP Configuration
196
+
197
+ 1. Run: `CLAUDECODE= claude mcp get knowz`
198
+ 2. If already configured:
199
+ ```
200
+ Knowz MCP server is already configured.
201
+
202
+ Options:
203
+ 1. Keep existing configuration (abort registration)
204
+ 2. Remove existing and register new account
205
+ ```
206
+ Use AskUserQuestion. If they keep existing, STOP.
207
+ If they continue, run `CLAUDECODE= claude mcp remove knowz` first.
208
+
209
+ #### Step R2: Welcome + Collect Information (one question at a time)
210
+
211
+ **CRITICAL: Interactive Flow — ask ONE question, then WAIT for response.**
212
+
213
+ Display welcome:
214
+ ```
215
+ KNOWZ REGISTRATION
216
+
217
+ Welcome! Let's set up your Knowz account.
218
+
219
+ This will:
220
+ 1. Create your Knowz account
221
+ 2. Generate an API key
222
+ 3. Configure the MCP server automatically
223
+
224
+ All data transmitted securely over HTTPS.
225
+ Privacy policy: https://knowz.io/privacy
226
+ ```
227
+
228
+ Then use AskUserQuestion to collect (one at a time, validating each):
229
+
230
+ 1. **Name** — "What name would you like for your account?"
231
+ - Validation: non-empty, 2-100 characters
232
+ 2. **Email** — "What is your email address?"
233
+ - Validation: contains `@` and domain
234
+ 3. **Password** — "Create a password (minimum 8 characters)"
235
+ - Note: "Your password will be sent securely over HTTPS. It will NOT be stored locally."
236
+ - Validation: minimum 8 characters
237
+
238
+ #### Step R3: Confirm Details
239
+
240
+ ```
241
+ CONFIRM REGISTRATION
242
+
243
+ Name: {name}
244
+ Email: {email}
245
+ Password: ********
246
+
247
+ Is this correct?
248
+ ```
249
+
250
+ Use AskUserQuestion with options: Yes / No / Edit.
251
+ - If "Edit": go back to Step R2
252
+ - If "No": cancel and STOP
253
+ - If "Yes": proceed
254
+
255
+ #### Step R4: Call Registration API
256
+
257
+ Determine endpoint based on `--dev` flag (see [references/registration.md](references/registration.md)).
258
+
259
+ ```bash
260
+ curl -X POST https://api.knowz.io/api/v1/auth/register \
261
+ -H "Content-Type: application/json" \
262
+ -d '{"name": "{name}", "email": "{email}", "password": "{password}"}'
263
+ ```
264
+
265
+ Handle response codes per [references/registration.md](references/registration.md).
266
+
267
+ Extract from response: API key (`apiKey`/`api_key`/`token`), vault ID (`vault_id`/`vaultId`), vault name.
268
+
269
+ #### Step R5: Configure MCP Server
270
+
271
+ Parse scope from arguments (default: `local`). If `project` scope, warn about `.mcp.json` git visibility.
272
+
273
+ Ask auth method:
274
+ ```
275
+ How would you like to authenticate with the MCP server?
276
+
277
+ OAuth (recommended) — authenticate via browser, tokens auto-managed
278
+ API Key — use the key from registration, no browser step needed
279
+ ```
280
+
281
+ Configure per [references/mcp-setup.md](references/mcp-setup.md).
282
+
283
+ Verify: `CLAUDECODE= claude mcp get knowz`
284
+
285
+ #### Step R6: Generate Vault Configuration
286
+
287
+ 1. Generate `knowz-vaults.md` with the registered vault using the format from `knowz-vaults.example.md`
288
+ 2. Pre-populate routing rules based on the vault name/description
289
+ 3. **KC interop:** If `knowzcode/knowzcode_vaults.md` exists, update the vault IDs there too (see KC Vault File Interop section)
290
+
291
+ #### Step R7: Success Message
292
+
293
+ ```
294
+ REGISTRATION COMPLETE
295
+
296
+ Account:
297
+ Email: {email}
298
+ Auth: {OAuth OR API Key: masked_key}
299
+
300
+ MCP Configuration:
301
+ Scope: {scope}
302
+ Endpoint: {endpoint}
303
+ Status: Configured
304
+
305
+ Vault:
306
+ Name: {vault_name}
307
+ ID: {vault_id prefix...}
308
+ File: knowz-vaults.md
309
+ ```
310
+
311
+ Then display the restart box:
312
+ ```
313
+ ┌─────────────────────────────────────────────────────┐
314
+ │ RESTART REQUIRED │
315
+ │ │
316
+ │ Claude Code must be restarted to load the new │
317
+ │ MCP server — this is a platform limitation. │
318
+ │ │
319
+ │ → Close and reopen Claude Code │
320
+ │ → Then run: /knowz status │
321
+ │ │
322
+ │ {If OAuth: "Your browser will open for login on │
323
+ │ the first MCP call after restart."} │
324
+ └─────────────────────────────────────────────────────┘
325
+
326
+ After restart:
327
+ 1. Verify connection: /knowz status
328
+ 2. Try: /knowz ask "your first question"
329
+ 3. Save knowledge: /knowz save "your first insight"
330
+ ```
331
+
332
+ ---
333
+
334
+ ## Action: `setup`
335
+
336
+ Configure MCP server connection (if needed) and generate/update the `knowz-vaults.md` vault configuration file.
337
+
338
+ **Reference:** Read [references/mcp-setup.md](references/mcp-setup.md) for MCP configuration details.
339
+
340
+ ### Parameters (from `$ARGUMENTS` after `setup`)
341
+
342
+ - `<api-key>` — optional API key (positional)
343
+ - `--oauth` — use OAuth dynamic discovery
344
+ - `--endpoint <url>` — custom MCP endpoint
345
+ - `--scope <local|project|user>` — configuration scope (default: `local`)
346
+ - `--dev` — use development environment
347
+
348
+ ### Steps
349
+
350
+ #### Step S1: Check MCP Status
351
+
352
+ Check if `mcp__knowz__list_vaults` exists in available tools.
353
+
354
+ **If MCP IS available** → skip to Step S4 (vault file creation).
355
+
356
+ **If MCP is NOT available** → proceed with MCP configuration (Steps S2-S3).
357
+
358
+ #### Step S2: Smart Config Discovery
359
+
360
+ Before prompting for credentials, check known sources per [references/mcp-setup.md](references/mcp-setup.md):
361
+
362
+ 1. Check `KNOWZ_API_KEY` environment variable
363
+ 2. Check cross-platform configs (`.gemini/settings.json`, `.vscode/mcp.json`, `.mcp.json`)
364
+ 3. Parse API key or `--oauth` from `$ARGUMENTS`
365
+
366
+ If no auth found from any source:
367
+ ```
368
+ No API key found. How would you like to authenticate?
369
+
370
+ OAuth (recommended) — authenticate via browser, tokens auto-managed
371
+ API Key — enter a Knowz API key, no browser step needed
372
+ Register — create a new account (/knowz register)
373
+ ```
374
+
375
+ If user chooses "Register" → advise running `/knowz register` and STOP.
376
+
377
+ #### Step S3: Configure MCP Server
378
+
379
+ 1. Check for existing config: `CLAUDECODE= claude mcp get knowz`
380
+ - If exists, ask to reconfigure or keep
381
+ 2. Parse scope (default: `local`); warn on `project` scope
382
+ 3. Determine endpoint (`https://mcp.knowz.io/mcp` or `--dev` / `--endpoint`)
383
+ 4. Run `claude mcp add` per [references/mcp-setup.md](references/mcp-setup.md)
384
+ 5. Verify: `CLAUDECODE= claude mcp get knowz`
385
+ 6. **If Gemini CLI detected** (`.gemini/` directory exists): configure Gemini too
386
+ 7. Report:
387
+ ```
388
+ MCP server configured!
389
+ Scope: {scope}
390
+ Endpoint: {endpoint}
391
+
392
+ ┌─────────────────────────────────────────────────────┐
393
+ │ RESTART REQUIRED │
394
+ │ │
395
+ │ Claude Code must be restarted to load the new │
396
+ │ MCP server — this is a platform limitation. │
397
+ │ MCP servers only connect at session startup. │
398
+ │ │
399
+ │ → Close and reopen Claude Code │
400
+ │ → Then run: /knowz setup │
401
+ │ (to create your vault configuration file) │
402
+ └─────────────────────────────────────────────────────┘
403
+ ```
404
+ STOP here — restart required before vault discovery.
405
+
406
+ #### Step S4: Vault File Creation/Update (existing flow, MCP available)
407
+
408
+ 1. Call `mcp__knowz__list_vaults(includeStats: true)` to discover vaults
409
+ 2. **If `knowz-vaults.md` already exists:**
410
+ - Read the existing file
411
+ - Compare configured vaults against server vaults
412
+ - Show what's configured vs available:
413
+ ```
414
+ Current vault configuration:
415
+
416
+ Configured:
417
+ - Engineering Knowledge (abc-123) — 42 items
418
+ - Company Wiki (def-456) — 18 items
419
+
420
+ Available on server but not configured:
421
+ - Personal Notes (ghi-789) — 7 items
422
+
423
+ Would you like to:
424
+ 1. Add missing vaults to your configuration
425
+ 2. Reconfigure from scratch
426
+ 3. Keep current configuration
427
+ ```
428
+ - Use AskUserQuestion to get their choice
429
+ - Update the file accordingly
430
+
431
+ 3. **If `knowz-vaults.md` does not exist:**
432
+ - **If server has vaults:** Present discovered vaults to the user:
433
+ ```
434
+ Found {N} vault(s) on the Knowz server:
435
+
436
+ 1. {Vault Name} — {item count} items
437
+ "{vault description}"
438
+
439
+ 2. {Vault Name} — {item count} items
440
+ "{vault description}"
441
+
442
+ Which vaults would you like to connect to this project?
443
+ (Enter numbers, "all", or "none")
444
+ ```
445
+ - Use AskUserQuestion to get their selection
446
+ - For each selected vault, ask (or infer from the vault description):
447
+ - Brief description of what this vault contains
448
+ - When to query it (plain English rules)
449
+ - When to save to it (plain English rules)
450
+ - Generate `knowz-vaults.md` using the format from `knowz-vaults.example.md`
451
+ - Write the file to the project root
452
+
453
+ - **If server has NO vaults:** Offer to create one:
454
+ ```
455
+ No vaults found on the Knowz server.
456
+
457
+ Would you like to create a vault for this project?
458
+ I can set up a general-purpose knowledge vault to get you started.
459
+
460
+ Suggested vault:
461
+ Name: "{project-name} Knowledge"
462
+ Description: "Architecture decisions, code patterns, conventions, and technical learnings for {project-name}"
463
+ ```
464
+ - Use AskUserQuestion for confirmation and to let user customize the name/description
465
+ - If confirmed → call `mcp__knowz__create_vault(name, description)` to create it
466
+ - Then generate `knowz-vaults.md` with the newly created vault
467
+ - Pre-populate sensible "when to query" and "when to save" rules based on the vault description
468
+
469
+ 4. **Smart defaults for routing rules:**
470
+ When generating rules for a vault, infer from the vault's name and description:
471
+ - A vault named "Engineering Knowledge" or with "decisions" in description →
472
+ - When to query: architecture decisions, conventions, "why did we...", best practices
473
+ - When to save: decisions about approach, new conventions, workarounds
474
+ - A vault named "Company Wiki" or with "processes" in description →
475
+ - When to query: team processes, onboarding, "how do we...", policies
476
+ - When to save: new processes, policy changes, team structure updates
477
+ - A vault with "patterns" or "code" in description →
478
+ - When to query: code patterns, "how did we build...", implementation examples
479
+ - When to save: reusable patterns, workarounds, performance insights
480
+ - For vaults that don't match any heuristic → use generic rules and ask the user to customize
481
+
482
+ 5. **KC Vault File Interop:** If `knowzcode/knowzcode_vaults.md` exists, update vault IDs there too (see KC Vault File Interop section).
483
+
484
+ 6. Report success:
485
+ ```
486
+ Vault configuration saved to knowz-vaults.md
487
+
488
+ Connected vaults:
489
+ - {Vault Name} (query + save)
490
+ - {Vault Name} (query only)
491
+
492
+ You can now use:
493
+ /knowz ask "question" — query your vaults
494
+ /knowz save "insight" — save to your vaults
495
+ /knowz search "term" — search across vaults
496
+ ```
497
+
498
+ ---
499
+
500
+ ## Action: `status`
501
+
502
+ Check MCP connection health and vault configuration.
503
+
504
+ ### Steps
505
+
506
+ 1. **Check MCP tool availability:**
507
+ - If `mcp__knowz__list_vaults` is NOT in available tools → report "MCP not connected" with setup instructions:
508
+ ```
509
+ Knowz MCP not connected. Run /knowz setup or /knowz register to configure.
510
+ ```
511
+ - If available → proceed
512
+
513
+ 2. **Test MCP connectivity:**
514
+ - Call `mcp__knowz__list_vaults(includeStats: true)`
515
+ - If fails → report error with troubleshooting
516
+
517
+ 3. **Check vault file:**
518
+ - Look for `knowz-vaults.md` in project root
519
+ - If found → parse and validate vault IDs against server
520
+
521
+ 4. **Report status:**
522
+ ```
523
+ Knowz Status
524
+
525
+ MCP Connection: Connected
526
+ Server vaults: {N} vault(s) available
527
+ - {Vault Name} — {item count} items
528
+ - {Vault Name} — {item count} items
529
+
530
+ Vault Configuration: {Configured / Not configured}
531
+ {If configured:}
532
+ File: knowz-vaults.md
533
+ Connected vaults: {N}
534
+ - {Vault Name} ({vault ID prefix}) — matched on server
535
+ - {Vault Name} ({vault ID prefix}) — NOT FOUND on server (stale config?)
536
+ Default vault: {name}
537
+
538
+ {If not configured:}
539
+ No knowz-vaults.md found. Run /knowz setup to create one.
540
+
541
+ Pending captures: {N items in knowz-pending.md, or "None"}
542
+
543
+ Auto-trigger: {Active (vault file found) / Inactive (no vault file)}
544
+ ```
545
+
546
+ 5. **Surface actionable issues:**
547
+ - Vault IDs in the file that don't match any server vault → "Stale vault config? Run `/knowz setup` to refresh."
548
+ - No vaults on server → "No vaults found. Create one on the Knowz platform, then run `/knowz setup`."
549
+ - Vault file missing → "Run `/knowz setup` for vault-aware routing and auto-trigger behavior."
550
+ - Pending captures exist → "Run `/knowz flush` to sync pending captures to vaults."
551
+
552
+ ---
553
+
554
+ ## Action: `flush`
555
+
556
+ Process the pending captures queue — drain `knowz-pending.md` to vaults.
557
+
558
+ ### Steps
559
+
560
+ 1. **Read pending captures file:**
561
+ - Read `knowz-pending.md` from the project root
562
+ - If the file doesn't exist or contains no `---`-delimited capture blocks:
563
+ ```
564
+ 0 pending captures — nothing to flush.
565
+ ```
566
+ STOP.
567
+
568
+ 2. **Verify MCP connectivity:**
569
+ - Check that `mcp__knowz__create_knowledge` is available
570
+ - If NOT available:
571
+ ```
572
+ Cannot flush — MCP not connected. Run /knowz setup first.
573
+ ```
574
+ STOP.
575
+ - Read `knowz-vaults.md` to resolve vault IDs
576
+
577
+ 3. **Parse capture blocks:**
578
+ - Split file content by `---` delimiters
579
+ - Each block contains: timestamp, title (after `###`), Category, Target Vault, Source, Content
580
+ - Count total blocks
581
+
582
+ 4. **Flush each capture to MCP:**
583
+ For each parsed block:
584
+ a. Resolve target vault ID from `knowz-vaults.md` matching the Target Vault name. If only one vault configured, use it for all.
585
+ b. Build `mcp__knowz__create_knowledge` payload:
586
+ - `title`: from the `###` header (after timestamp and ` -- `)
587
+ - `content`: the Content field value
588
+ - `knowledgeType`: `"Note"`
589
+ - `vaultId`: resolved vault ID
590
+ - `tags`: extract from `[TAGS]` section in content if present, otherwise derive from Category
591
+ - `source`: the Source field value
592
+ c. Call `mcp__knowz__create_knowledge` with the payload
593
+ d. On **success**: mark the block for removal
594
+ e. On **failure**: leave the block in place, log the error
595
+
596
+ 5. **Update the pending captures file:**
597
+ - Remove all successfully flushed blocks
598
+ - Keep the file header (`# Knowz Pending Captures` and description line)
599
+ - If all blocks flushed: file should contain only the header
600
+
601
+ 6. **Report results:**
602
+ ```
603
+ Flushed {success}/{total} pending captures to vault.
604
+
605
+ Captured:
606
+ - {title1} → {vault name}
607
+ - {title2} → {vault name}
608
+
609
+ {If any failed:}
610
+ Failed:
611
+ - {title3} — {error reason}
612
+ Run /knowz flush again when MCP is available.
613
+
614
+ {If all succeeded:}
615
+ All captures synced. Pending file cleared.
616
+ ```
617
+
618
+ ---
619
+
620
+ ## Action: `ask`
621
+
622
+ AI-powered Q&A against configured vaults.
623
+
624
+ ### Steps
625
+
626
+ 1. Parse the question from `$ARGUMENTS` (everything after `ask`)
627
+ 2. **Vault routing:** Match the question against each vault's "when to query" rules
628
+ - If one vault matches → scope to that vault
629
+ - If multiple vaults match → query all matching vaults
630
+ - If no vaults match → use the default vault from `## Defaults`
631
+ - If no vault file → no vault scoping
632
+ 3. Call `mcp__knowz__ask_question` with:
633
+ - `question`: the user's question
634
+ - `vaultId`: the matched vault ID (if vault file exists)
635
+ - `researchMode`: `true` for complex questions (multi-part, "how", "why", "compare"), `false` for simple lookups
636
+ 4. Present the answer naturally, citing the vault source:
637
+ ```
638
+ From {Vault Name}:
639
+
640
+ {answer content}
641
+ ```
642
+
643
+ ---
644
+
645
+ ## Action: `save`
646
+
647
+ Capture an insight or piece of knowledge to a vault.
648
+
649
+ ### Steps
650
+
651
+ 1. Parse the content from `$ARGUMENTS` (everything after `save` or `learn`)
652
+ 2. **If content is empty**, ask the user what they want to save using AskUserQuestion
653
+ 3. **Category detection** — scan the content for signal words:
654
+ | Signal Words | Category |
655
+ |---|---|
656
+ | pattern, reusable, utility, helper | Pattern |
657
+ | chose, decided, opted, because, trade-off | Decision |
658
+ | workaround, limitation, instead, temporary | Workaround |
659
+ | faster, optimized, reduced, cache, performance | Performance |
660
+ | security, vulnerability, sanitize, auth, encrypt | Security |
661
+ | always, never, standard, rule, convention | Convention |
662
+ | *(no clear match)* | Note |
663
+
664
+ 4. **Vault routing:** Match content against each vault's "when to save" rules
665
+ - If one vault matches → target that vault
666
+ - If multiple vaults match → ask the user which one using AskUserQuestion
667
+ - If no vaults match → use the default vault
668
+ - If no vault file → no vault scoping (use first available vault)
669
+
670
+ 5. **Content formatting:** Apply the target vault's content template. Expand terse user input into detailed, self-contained content:
671
+ - **Content Detail Principle:** Every saved item must be detailed enough to be useful when retrieved via semantic search months later. Include reasoning, technology names, code examples, and file paths.
672
+ - If the vault has a content template, fill each field
673
+ - If no template, use the default format:
674
+ ```
675
+ [CONTEXT] {Where/why this arose — component, technology, problem}
676
+ [INSIGHT] {The knowledge — detailed, self-contained, actionable}
677
+ [RATIONALE] {Why this approach, alternatives considered}
678
+ [TAGS] {category, technology, domain keywords}
679
+ ```
680
+
681
+ 6. **Generate title:** `{Category}: {Descriptive summary with key technology names}`
682
+
683
+ 7. **Dedup check:** Call `mcp__knowz__search_knowledge` with:
684
+ - `query`: the generated title
685
+ - `vaultId`: the target vault ID
686
+ - `limit`: 3
687
+ - If a substantially similar item exists, present it and ask:
688
+ ```
689
+ Similar knowledge already exists:
690
+
691
+ "{existing title}"
692
+ {brief snippet}
693
+
694
+ Options:
695
+ 1. Create anyway (new entry)
696
+ 2. Skip (don't save)
697
+ 3. Update existing item
698
+ ```
699
+ - Use AskUserQuestion for their choice
700
+ - If "Update existing" → call `mcp__knowz__update_knowledge` instead of create
701
+
702
+ 8. **Create:** Call `mcp__knowz__create_knowledge` with:
703
+ - `content`: the formatted content
704
+ - `title`: the generated title
705
+ - `knowledgeType`: `"Note"`
706
+ - `vaultId`: target vault ID
707
+ - `tags`: `[category, extracted-keywords]`
708
+ - `source`: `"knowz-skill"`
709
+
710
+ 9. **Report success:**
711
+ ```
712
+ Knowledge captured!
713
+
714
+ Title: {title}
715
+ Vault: {vault name}
716
+ Tags: {tag list}
717
+ ```
718
+
719
+ ---
720
+
721
+ ## Action: `search`
722
+
723
+ Semantic search across configured vaults.
724
+
725
+ ### Steps
726
+
727
+ 1. Parse the search query from `$ARGUMENTS` (everything after `search` or `find`)
728
+ 2. **Vault routing:** Match query against "when to query" rules
729
+ - If matches found → search those vaults
730
+ - If no match → search all configured vaults (or no scoping in zero-config mode)
731
+ 3. For each target vault, call `mcp__knowz__search_knowledge` with:
732
+ - `query`: the search query
733
+ - `vaultId`: the vault ID
734
+ - `limit`: 10
735
+ 4. Present results grouped by vault:
736
+ ```
737
+ Results from {Vault Name}:
738
+
739
+ 1. {title} — {snippet}
740
+ 2. {title} — {snippet}
741
+ 3. {title} — {snippet}
742
+
743
+ Results from {Other Vault}:
744
+
745
+ 1. {title} — {snippet}
746
+ ```
747
+ 5. If no results across any vault:
748
+ ```
749
+ No results found for "{query}" across configured vaults.
750
+
751
+ Try:
752
+ - Broader search terms
753
+ - /knowz browse to see what's in your vaults
754
+ - /knowz ask "{query}" for AI-powered Q&A
755
+ ```
756
+
757
+ ---
758
+
759
+ ## Action: `browse`
760
+
761
+ Browse vault contents and topics.
762
+
763
+ ### Steps
764
+
765
+ 1. Parse optional vault name from `$ARGUMENTS` (everything after `browse` or `list`)
766
+ 2. **If vault name provided** → browse that specific vault
767
+ 3. **If no vault name** → browse all configured vaults (or all available vaults in zero-config mode)
768
+ 4. For each vault:
769
+ - Call `mcp__knowz__list_topics(vaultId)` to get topic overview
770
+ - Call `mcp__knowz__list_vault_contents(vaultId, limit: 20)` for recent items
771
+ 5. Present a browsable overview:
772
+ ```
773
+ {Vault Name} ({item count} items)
774
+
775
+ Topics:
776
+ - {topic 1} ({count} items)
777
+ - {topic 2} ({count} items)
778
+
779
+ Recent items:
780
+ - {title 1}
781
+ - {title 2}
782
+ - {title 3}
783
+ ```
784
+ 6. If a specific topic interests the user, they can follow up with `/knowz search "topic name"`
785
+
786
+ ---
787
+
788
+ ## KC Vault File Interop
789
+
790
+ When the knowz plugin creates or updates vault configurations and a KnowzCode project exists alongside, keep both vault files in sync.
791
+
792
+ **When to apply:** During `setup` and `register` actions, after writing `knowz-vaults.md`.
793
+
794
+ ### Steps
795
+
796
+ 1. Check if `knowzcode/knowzcode_vaults.md` exists in the project
797
+ 2. **If it exists:**
798
+ - Read the file and find vault entries in the `## Connected Vaults` section
799
+ - For each vault that was just configured in `knowz-vaults.md`:
800
+ - Find a matching vault entry in `knowzcode_vaults.md` (match by vault name or vault ID)
801
+ - If matched: update the **ID** field if it was empty or different
802
+ - If not matched: leave `knowzcode_vaults.md` as-is (don't add knowz-plugin vaults to KC config)
803
+ - Write the updated file
804
+ - Report: `"Also updated vault IDs in knowzcode/knowzcode_vaults.md for KnowzCode compatibility."`
805
+ 3. **If it doesn't exist:** do nothing — no KC project present
806
+
807
+ **Reverse direction:** This interop is one-way from knowz → KC. KC's agents update their own vault file independently.
808
+
809
+ ---
810
+
811
+ ## Error Handling
812
+
813
+ | Condition | Response |
814
+ |---|---|
815
+ | MCP tools not available | "Knowz MCP not connected. Run `/knowz setup` or `/knowz register`." |
816
+ | Vault file not found | Zero-config mode — proceed without vault scoping, suggest `/knowz setup` |
817
+ | MCP call fails | Report error clearly: "Knowz MCP returned an error: {error}. Check your connection." |
818
+ | Dedup match found | Present existing item, ask: create anyway / skip / update existing |
819
+ | Multiple vaults match | Ask user which one using AskUserQuestion |
820
+ | No vaults match routing rules | Use default vault from `## Defaults` section, or first vault listed |
821
+ | Empty arguments | Show usage help with examples |
822
+
823
+ ---
824
+
825
+ ## Dispatching the Knowledge Worker Agent
826
+
827
+ For complex, multi-step research tasks, dispatch the `knowledge-worker` agent instead of handling inline:
828
+
829
+ **Dispatch when:**
830
+ - User asks for comprehensive research across multiple vaults
831
+ - Query requires synthesizing findings from many items
832
+ - Task involves batch capture of multiple insights
833
+
834
+ **How to dispatch:**
835
+ ```
836
+ Use the Agent tool with subagent_type "knowledge-worker" — pass the user's query
837
+ and let the agent handle multi-step vault operations.
838
+ ```
839
+
840
+ For simple single-query/single-save operations, handle directly in this skill — don't dispatch an agent for simple tasks.
841
+
842
+ ---
843
+
844
+ ## Usage Examples
845
+
846
+ ```bash
847
+ # Account setup
848
+ /knowz register # create account + auto-configure
849
+ /knowz setup # configure MCP + create vault file
850
+ /knowz setup kz_live_abc123 # configure with specific API key
851
+ /knowz setup --oauth # configure with OAuth
852
+
853
+ # Ask a question
854
+ /knowz ask "What's our convention for error handling in APIs?"
855
+
856
+ # Save an insight
857
+ /knowz save "We chose Redis over Memcached because we need pub/sub for real-time notifications"
858
+
859
+ # Search for knowledge
860
+ /knowz search "authentication patterns"
861
+
862
+ # Browse vaults
863
+ /knowz browse
864
+ /knowz browse "Engineering Knowledge"
865
+
866
+ # Check connection and health
867
+ /knowz status
868
+
869
+ # Process pending captures
870
+ /knowz flush
871
+
872
+ # Auto-detected intent (bare input)
873
+ /knowz "Why did we use PostgreSQL?" # → detected as ask
874
+ /knowz "Always use UTC for timestamps" # → detected as save
875
+ ```
876
+
877
+ Execute the detected action now.