pi-doc-injector 0.1.3 → 0.1.4
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 +18 -4
- package/docs/bun.md +12 -12
- package/docs/publish.md +3 -3
- package/index.ts +23 -0
- package/package.json +7 -5
- package/registry.ts +18 -6
- package/types.ts +1 -1
package/README.md
CHANGED
|
@@ -63,7 +63,7 @@ Create `.pi/doc-injector.json` in your project root to customize behavior:
|
|
|
63
63
|
```json
|
|
64
64
|
{
|
|
65
65
|
"docsPath": "./docs",
|
|
66
|
-
"matchThreshold":
|
|
66
|
+
"matchThreshold": 1,
|
|
67
67
|
"contextThreshold": 80,
|
|
68
68
|
"recursive": true
|
|
69
69
|
}
|
|
@@ -72,7 +72,7 @@ Create `.pi/doc-injector.json` in your project root to customize behavior:
|
|
|
72
72
|
| Option | Default | Description |
|
|
73
73
|
| ------------------ | ---------- | -------------------------------------------------------- |
|
|
74
74
|
| `docsPath` | `"./docs"` | Path to docs folder (relative to project root) |
|
|
75
|
-
| `matchThreshold` | `
|
|
75
|
+
| `matchThreshold` | `1` | Minimum keyword matches required to inject a doc |
|
|
76
76
|
| `contextThreshold` | `80` | Skip injection when context usage exceeds this % (0–100) |
|
|
77
77
|
| `recursive` | `true` | Scan docs subdirectories recursively |
|
|
78
78
|
|
|
@@ -103,14 +103,28 @@ The extension uses a per-session injection model:
|
|
|
103
103
|
- Use `/doc-inject reset` to manually reset all flags and allow docs to be injected again.
|
|
104
104
|
- Use `/doc-inject list` to see which docs have been injected (✅) and which are pending (⬜).
|
|
105
105
|
|
|
106
|
+
### System Prompt Lifecycle
|
|
107
|
+
|
|
108
|
+
Pi **reconstructs the system prompt from source files each turn** (verified against pi v0.70.6).
|
|
109
|
+
|
|
110
|
+
When `before_agent_start` fires, the `systemPrompt` passed to the extension is a freshly rebuilt prompt from `AGENTS.md`, `SYSTEM.md`, skills, and tool snippets. It is **not** accumulated from previous turns.
|
|
111
|
+
|
|
112
|
+
This means:
|
|
113
|
+
|
|
114
|
+
- Injections apply to the **current turn only** and do not persist in subsequent turns.
|
|
115
|
+
- There is no risk of duplicate injection sections stacking up over time.
|
|
116
|
+
- The `injected` flag alone is sufficient to prevent re-injection — no additional deduplication or marker-based stripping is needed.
|
|
117
|
+
|
|
118
|
+
For the full source-level verification, see the JSDoc block in `index.ts`.
|
|
119
|
+
|
|
106
120
|
## Development
|
|
107
121
|
|
|
108
122
|
```bash
|
|
109
123
|
# Run tests
|
|
110
|
-
|
|
124
|
+
npm test
|
|
111
125
|
|
|
112
126
|
# Run tests in watch mode
|
|
113
|
-
|
|
127
|
+
npm run test:watch
|
|
114
128
|
```
|
|
115
129
|
|
|
116
130
|
## License
|
package/docs/bun.md
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
1
|
---
|
|
2
2
|
title: "JavaScript Runtime & Package Manager"
|
|
3
|
-
keywords: [
|
|
3
|
+
keywords: [npm, node, package manager, runtime, install, test, build]
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# JavaScript Runtime & Package Manager
|
|
7
7
|
|
|
8
|
-
This project uses **
|
|
8
|
+
This project uses **Node.js** as its JavaScript runtime and **npm** as its package manager.
|
|
9
9
|
|
|
10
|
-
## Why
|
|
10
|
+
## Why npm?
|
|
11
11
|
|
|
12
|
-
-
|
|
13
|
-
-
|
|
14
|
-
-
|
|
15
|
-
-
|
|
12
|
+
- The default package manager that ships with Node.js
|
|
13
|
+
- Widely supported across all CI/CD platforms
|
|
14
|
+
- Deterministic installs via `package-lock.json`
|
|
15
|
+
- No additional runtime or tooling required
|
|
16
16
|
|
|
17
17
|
## Common Commands
|
|
18
18
|
|
|
19
19
|
```bash
|
|
20
20
|
# Install dependencies
|
|
21
|
-
|
|
21
|
+
npm install
|
|
22
22
|
|
|
23
23
|
# Run tests
|
|
24
|
-
|
|
24
|
+
npm test
|
|
25
25
|
|
|
26
|
-
# Run tests in watch mode
|
|
27
|
-
|
|
26
|
+
# Run tests in watch mode
|
|
27
|
+
npm run test:watch
|
|
28
28
|
```
|
|
29
29
|
|
|
30
30
|
## Version
|
|
31
31
|
|
|
32
|
-
This project requires
|
|
32
|
+
This project requires Node.js >= 18.0.0. The lockfile (`package-lock.json`) ensures reproducible installs.
|
package/docs/publish.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
title: "Publishing Workflow"
|
|
3
|
-
keywords: [publish, release, npm, version, tag,
|
|
3
|
+
keywords: [publish, release, npm, version, tag, node, oidc, trusted publisher]
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# Publishing Workflow
|
|
@@ -54,9 +54,9 @@ git push origin master --follow-tags
|
|
|
54
54
|
## CI/CD
|
|
55
55
|
|
|
56
56
|
The `Publish` workflow triggers on `v*` tags and:
|
|
57
|
-
- Runs `
|
|
57
|
+
- Runs `npm ci`
|
|
58
58
|
- Verifies tag matches `package.json` version
|
|
59
|
-
- Runs `
|
|
59
|
+
- Runs `npm test`
|
|
60
60
|
- Publishes to npm with provenance via OIDC
|
|
61
61
|
|
|
62
62
|
Monitor: https://github.com/lmn451/pi-docs/actions
|
package/index.ts
CHANGED
|
@@ -22,6 +22,29 @@
|
|
|
22
22
|
* session, once a doc is injected, it won't be re-injected unless the user
|
|
23
23
|
* manually runs `/doc-inject reset`.
|
|
24
24
|
*
|
|
25
|
+
* ## System Prompt Lifecycle (verified against pi v0.70.6)
|
|
26
|
+
*
|
|
27
|
+
* Pi **reconstructs the system prompt from source files each turn**. Here is
|
|
28
|
+
* the exact flow, verified via source-code review of dist/core/agent-session.js
|
|
29
|
+
* and dist/core/extensions/runner.js (v0.70.6):
|
|
30
|
+
*
|
|
31
|
+
* 1. Before each agent turn, pi calls `this._rebuildSystemPrompt(toolNames)`.
|
|
32
|
+
* This builds the prompt from `AGENTS.md`, `SYSTEM.md`, skills, enabled
|
|
33
|
+
* tool snippets — never from a previously modified (injected) prompt.
|
|
34
|
+
* 2. The rebuilt prompt is stored in `this._baseSystemPrompt`.
|
|
35
|
+
* 3. `emitBeforeAgentStart(..., this._baseSystemPrompt, ...)` passes this
|
|
36
|
+
* *fresh* base prompt to every extension handler.
|
|
37
|
+
* 4. Extension handlers can return a modified `systemPrompt` for the current
|
|
38
|
+
* turn. Pi uses the modified prompt **only for this turn**.
|
|
39
|
+
* 5. When no extension modifies the prompt, pi explicitly resets to
|
|
40
|
+
* `this._baseSystemPrompt` (comment in source: "Ensure we're using the
|
|
41
|
+
* base prompt (in case previous turn had modifications)").
|
|
42
|
+
*
|
|
43
|
+
* **Therefore**: Previous injections from `before_agent_start` do NOT persist
|
|
44
|
+
* across turns. Duplicate sections cannot accumulate in the system prompt.
|
|
45
|
+
* The `injected` flag alone is sufficient to prevent re-injection — no
|
|
46
|
+
* marker-based stripping or deduplication is needed.
|
|
47
|
+
*
|
|
25
48
|
* ## Race Condition Note
|
|
26
49
|
*
|
|
27
50
|
* If `resources_discover` (rebuild) fires while `before_agent_start` is running,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-doc-injector",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "Auto-inject relevant project documentation into Pi's LLM context based on keyword matching",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./index.ts",
|
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
"README.md"
|
|
14
14
|
],
|
|
15
15
|
"scripts": {
|
|
16
|
-
"test": "
|
|
17
|
-
"test:watch": "
|
|
16
|
+
"test": "vitest run",
|
|
17
|
+
"test:watch": "vitest"
|
|
18
18
|
},
|
|
19
19
|
"keywords": [
|
|
20
20
|
"pi-package",
|
|
@@ -37,10 +37,12 @@
|
|
|
37
37
|
"@mariozechner/pi-coding-agent": "*"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@types/
|
|
40
|
+
"@types/node": "^22.0.0",
|
|
41
|
+
"typescript": "^5.7.0",
|
|
42
|
+
"vitest": "^3.0.0"
|
|
41
43
|
},
|
|
42
44
|
"publishConfig": {
|
|
43
45
|
"access": "public"
|
|
44
46
|
},
|
|
45
|
-
"packageManager": "
|
|
47
|
+
"packageManager": "npm@11.5.2"
|
|
46
48
|
}
|
package/registry.ts
CHANGED
|
@@ -144,16 +144,28 @@ export class DocRegistry {
|
|
|
144
144
|
for (const dirent of dirents) {
|
|
145
145
|
if (!dirent.isFile() || !dirent.name.endsWith(".md")) continue;
|
|
146
146
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
147
|
+
const fileName = basename(dirent.name);
|
|
148
|
+
|
|
149
|
+
// Cross-runtime: when dirent.name is just the filename, resolve the
|
|
150
|
+
// relative path from the parent directory. Use parentPath (Node 18+)
|
|
151
|
+
// with fallback to .path (Bun) for older runtimes.
|
|
152
|
+
let relPath: string;
|
|
153
|
+
if (dirent.name === fileName) {
|
|
154
|
+
const parentPath = (dirent as Dirent & { parentPath?: string; path?: string }).parentPath
|
|
155
|
+
?? (dirent as Dirent & { path?: string }).path
|
|
156
|
+
?? "";
|
|
157
|
+
relPath = parentPath
|
|
158
|
+
? relative(dir, join(parentPath, dirent.name))
|
|
159
|
+
: dirent.name;
|
|
160
|
+
} else {
|
|
161
|
+
// Node-style: dirent.name already contains the relative path from dir
|
|
162
|
+
relPath = dirent.name;
|
|
163
|
+
}
|
|
152
164
|
|
|
153
165
|
results.push({
|
|
154
166
|
filePath: join(dir, relPath),
|
|
155
167
|
relativePath: relPath,
|
|
156
|
-
fileName
|
|
168
|
+
fileName,
|
|
157
169
|
});
|
|
158
170
|
}
|
|
159
171
|
|
package/types.ts
CHANGED