pi-doc-injector 0.3.1 → 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.
- package/README.md +108 -13
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -27,7 +27,23 @@ git clone https://github.com/yourname/pi-doc-injector.git .pi/extensions/doc-inj
|
|
|
27
27
|
## Quick Start
|
|
28
28
|
|
|
29
29
|
1. Create a `docs/` folder in your project root.
|
|
30
|
-
2. Add markdown files with
|
|
30
|
+
2. Add markdown files with frontmatter (`title` + `keywords`). See [Document Format](#document-format) for supported formats.
|
|
31
|
+
3. Start Pi. The extension scans `docs/` on session start.
|
|
32
|
+
4. When the user mentions a keyword, the matching doc is injected into the
|
|
33
|
+
system prompt **before the assistant responds** — no one-turn delay.
|
|
34
|
+
5. If the assistant mentions a NEW keyword mid-response, generation is
|
|
35
|
+
automatically aborted and restarted with the doc injected immediately.
|
|
36
|
+
|
|
37
|
+
## Document Format
|
|
38
|
+
|
|
39
|
+
Documents are markdown files (`.md` or `.txt`) that the extension scans for injection.
|
|
40
|
+
Each file can declare `title` and `keywords` via **frontmatter** — a metadata block at the top of the file.
|
|
41
|
+
|
|
42
|
+
### Supported Frontmatter Formats
|
|
43
|
+
|
|
44
|
+
The extension tries formats in this order and uses the first match it finds:
|
|
45
|
+
|
|
46
|
+
**1. YAML (recommended)**
|
|
31
47
|
|
|
32
48
|
```md
|
|
33
49
|
---
|
|
@@ -36,28 +52,57 @@ keywords: [test, testing, jest, vitest]
|
|
|
36
52
|
---
|
|
37
53
|
|
|
38
54
|
# Testing Workflow
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
**2. C-style block comment** — useful for `.ts`/`.js` doc files:
|
|
58
|
+
|
|
59
|
+
```md
|
|
60
|
+
/*---
|
|
61
|
+
title: "Testing Workflow"
|
|
62
|
+
keywords: [test, testing, jest, vitest]
|
|
63
|
+
---*/
|
|
39
64
|
|
|
40
|
-
|
|
65
|
+
# Testing Workflow
|
|
41
66
|
```
|
|
42
67
|
|
|
43
|
-
|
|
68
|
+
**3. HTML comment** — useful for HTML-generated docs:
|
|
44
69
|
|
|
45
70
|
```md
|
|
46
|
-
|
|
71
|
+
<!--
|
|
47
72
|
title: "Testing Workflow"
|
|
48
|
-
keywords:
|
|
73
|
+
keywords: [test, testing, jest, vitest]
|
|
74
|
+
-->
|
|
75
|
+
|
|
76
|
+
# Testing Workflow
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
**4. Slash-slash comment** — useful for `.js`/`.ts` sidecar docs:
|
|
80
|
+
|
|
81
|
+
```md
|
|
82
|
+
//---
|
|
83
|
+
title: "Testing Workflow"
|
|
84
|
+
keywords: [test, testing, jest, vitest]
|
|
85
|
+
|
|
86
|
+
# Testing Workflow
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Keyword Array Syntax
|
|
90
|
+
|
|
91
|
+
Both **flow** and **block** keyword array syntaxes are supported:
|
|
92
|
+
|
|
93
|
+
```md
|
|
94
|
+
keywords: [test, testing, jest] # flow: comma-separated in brackets
|
|
95
|
+
keywords: # block: one per line
|
|
49
96
|
- test
|
|
50
97
|
- testing
|
|
51
98
|
- jest
|
|
52
|
-
- vitest
|
|
53
|
-
---
|
|
54
99
|
```
|
|
55
100
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
101
|
+
### Auto-Keywords Fallback
|
|
102
|
+
|
|
103
|
+
If a file has **no frontmatter** and `autoKeywords` is enabled (default: `true`), the extension generates keywords heuristically from the filename and content — no metadata needed.
|
|
104
|
+
|
|
105
|
+
If `autoKeywords` is `false`, files without valid frontmatter are **skipped** with a warning.
|
|
61
106
|
|
|
62
107
|
## Configuration
|
|
63
108
|
|
|
@@ -68,7 +113,10 @@ Create `.pi/doc-injector.json` in your project root to customize behavior:
|
|
|
68
113
|
"docsPath": "./docs",
|
|
69
114
|
"matchThreshold": 1,
|
|
70
115
|
"contextThreshold": 80,
|
|
71
|
-
"recursive": true
|
|
116
|
+
"recursive": true,
|
|
117
|
+
"autoKeywords": true,
|
|
118
|
+
"llmKeywords": false,
|
|
119
|
+
"llmBatchSize": 20
|
|
72
120
|
}
|
|
73
121
|
```
|
|
74
122
|
|
|
@@ -78,6 +126,9 @@ Create `.pi/doc-injector.json` in your project root to customize behavior:
|
|
|
78
126
|
| `matchThreshold` | `1` | Minimum keyword matches required to inject a doc |
|
|
79
127
|
| `contextThreshold` | `80` | Skip injection when context usage exceeds this % (0–100) |
|
|
80
128
|
| `recursive` | `true` | Scan docs subdirectories recursively |
|
|
129
|
+
| `autoKeywords` | `true` | Generate keywords heuristically when frontmatter is missing |
|
|
130
|
+
| `llmKeywords` | `false` | Enable LLM-based keyword generation (see below) |
|
|
131
|
+
| `llmBatchSize` | `20` | Max files per LLM keyword batch |
|
|
81
132
|
|
|
82
133
|
### Keyword Matching
|
|
83
134
|
|
|
@@ -96,6 +147,50 @@ Injection is also skipped if the current context usage exceeds 80% of the token
|
|
|
96
147
|
| `/doc-inject reset` | Reset all injected flags (docs become re-injectable) |
|
|
97
148
|
| `/doc-inject status` | Show current injection status and config |
|
|
98
149
|
| `/doc-reload` | Re-scan docs folder and rebuild registry |
|
|
150
|
+
| `/doc-keywords-gen` | Generate LLM keywords for files without frontmatter (requires `llmKeywords: true` in config) |
|
|
151
|
+
|
|
152
|
+
## Keyword Generation
|
|
153
|
+
|
|
154
|
+
When a document has no frontmatter keywords, the extension handles it in two ways:
|
|
155
|
+
|
|
156
|
+
### Heuristic (Automatic)
|
|
157
|
+
|
|
158
|
+
If `autoKeywords` is `true` (default), keywords are generated automatically from:
|
|
159
|
+
|
|
160
|
+
- **Filename parts**: `"api-authentication.md"` → `[api, authentication]`
|
|
161
|
+
- **Markdown headings**: `"# Getting Started"` → `[getting, started]`
|
|
162
|
+
- **Code symbols**: `"function foo()"` → `[foo]`
|
|
163
|
+
|
|
164
|
+
All keywords are filtered through a stop-word list, lowercased, and capped at 20.
|
|
165
|
+
|
|
166
|
+
### LLM Generation (Manual)
|
|
167
|
+
|
|
168
|
+
For better keywords, enable LLM generation in config:
|
|
169
|
+
|
|
170
|
+
```json
|
|
171
|
+
{
|
|
172
|
+
"autoKeywords": true,
|
|
173
|
+
"llmKeywords": true,
|
|
174
|
+
"llmBatchSize": 20
|
|
175
|
+
}
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
Then run `/doc-keywords-gen [path]` to generate keywords via LLM. Without a path argument, it processes all keyword-less files.
|
|
179
|
+
|
|
180
|
+
The LLM reads each file's content and produces 3–10 relevant, searchable keywords per file. Results are saved to the cache and reused on subsequent scans.
|
|
181
|
+
|
|
182
|
+
### Keyword Source Tracking
|
|
183
|
+
|
|
184
|
+
The cache stores which method was used for each file's keywords:
|
|
185
|
+
|
|
186
|
+
| Source | How set |
|
|
187
|
+
| ------------ | ------------------------------------------------ |
|
|
188
|
+
| `frontmatter` | Keywords declared in file frontmatter |
|
|
189
|
+
| `cache` | Reused from previous scan (mtime match) |
|
|
190
|
+
| `heuristic` | Auto-generated from filename/content |
|
|
191
|
+
| `llm` | Generated via `/doc-keywords-gen` |
|
|
192
|
+
|
|
193
|
+
Use `/doc-inject list` to see each file's keyword source (shown as `[source]` tag).
|
|
99
194
|
|
|
100
195
|
## Injection Lifecycle
|
|
101
196
|
|