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 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": 2,
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` | `2` | Minimum keyword matches required to inject a doc |
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
- bun test
124
+ npm test
111
125
 
112
126
  # Run tests in watch mode
113
- bun test --watch
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: [bun, package manager, runtime, install, test, build]
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 **Bun** as its JavaScript runtime and package manager.
8
+ This project uses **Node.js** as its JavaScript runtime and **npm** as its package manager.
9
9
 
10
- ## Why Bun?
10
+ ## Why npm?
11
11
 
12
- - Fast native TypeScript support (no separate tsc step needed)
13
- - All-in-one runtime, bundler, and test runner
14
- - Drop-in replacement for Node.js and npm/yarn/pnpm
15
- - Significantly faster installs and test executions
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
- bun install
21
+ npm install
22
22
 
23
23
  # Run tests
24
- bun test
24
+ npm test
25
25
 
26
- # Run tests in watch mode (recommended for development)
27
- bun test --watch
26
+ # Run tests in watch mode
27
+ npm run test:watch
28
28
  ```
29
29
 
30
30
  ## Version
31
31
 
32
- This project requires Bun >= 1.3.0. The lockfile (`bun.lock`) ensures reproducible installs.
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, bun, oidc, trusted publisher]
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 `bun install --frozen-lockfile`
57
+ - Runs `npm ci`
58
58
  - Verifies tag matches `package.json` version
59
- - Runs `bun test`
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",
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": "bun test",
17
- "test:watch": "bun 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/bun": "^1.3.13"
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": "bun@1.3.11"
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
- // Build relative path from the directory tree
148
- const parentPath = (dirent as Dirent & { path?: string }).path ?? "";
149
- const relPath = parentPath
150
- ? relative(dir, join(parentPath, dirent.name))
151
- : dirent.name;
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: dirent.name,
168
+ fileName,
157
169
  });
158
170
  }
159
171
 
package/types.ts CHANGED
@@ -38,7 +38,7 @@ export interface DocInjectorConfig {
38
38
  /** Default configuration values. */
39
39
  export const DEFAULT_CONFIG: DocInjectorConfig = {
40
40
  docsPath: "./docs",
41
- matchThreshold: 2,
41
+ matchThreshold: 1,
42
42
  contextThreshold: 80,
43
43
  recursive: true,
44
44
  };