@stfade/pi-read-delegator 1.0.8 → 1.0.10

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stfade/pi-read-delegator",
3
- "version": "1.0.8",
3
+ "version": "1.0.10",
4
4
  "description": "Pi extension that delegates all read operations to a Reader subagent, blocking read tools from the main model",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -21,18 +21,9 @@ export declare class ReaderError extends Error {
21
21
  readonly originalError?: unknown | undefined;
22
22
  constructor(message: string, originalError?: unknown | undefined);
23
23
  }
24
- /**
25
- * Verify that pi-subagents is installed as a Pi extension.
26
- *
27
- * - Uses `require.resolve('pi-subagents')` to check installation.
28
- * - If not installed, prompts the user to install via `pi install pi-subagents`.
29
- * - If the user declines or installation fails, returns false (caller disables the extension).
30
- *
31
- * @returns true if installed or successfully installed; false otherwise
32
- */
33
24
  export declare function checkDependencies(prompt: (message: string) => Promise<string>): Promise<boolean>;
34
25
  /**
35
- * Quick synchronous check: can we resolve pi-subagents?
26
+ * Quick synchronous check: does pi-subagents exist on disk?
36
27
  */
37
28
  export declare function isSubagentsInstalled(): boolean;
38
29
  /**
package/reader-manager.js CHANGED
@@ -77,21 +77,24 @@ const READER_TEMPLATE_PATH = expandTilde("~/.pi/agent/agents/reader.md");
77
77
  /**
78
78
  * Verify that pi-subagents is installed as a Pi extension.
79
79
  *
80
- * - Uses `require.resolve('pi-subagents')` to check installation.
81
- * - If not installed, prompts the user to install via `pi install pi-subagents`.
80
+ * - Checks fs.existsSync for the pi-subagents directory (bypasses require.resolve
81
+ * caching issues after npm install within the same process).
82
+ * - If not installed, prompts the user to install via `npm install --prefix`.
82
83
  * - If the user declines or installation fails, returns false (caller disables the extension).
83
84
  *
84
85
  * @returns true if installed or successfully installed; false otherwise
85
86
  */
87
+ function piSubagentsDir() {
88
+ return path.join(os.homedir(), ".pi", "agent", "npm", "node_modules", "pi-subagents");
89
+ }
90
+ function piSubagentsPackageJson() {
91
+ return path.join(piSubagentsDir(), "package.json");
92
+ }
86
93
  async function checkDependencies(prompt) {
87
94
  // Already installed — nothing to do
88
- try {
89
- require.resolve("pi-subagents");
95
+ if (fs.existsSync(piSubagentsPackageJson())) {
90
96
  return true;
91
97
  }
92
- catch {
93
- // MODULE_NOT_FOUND — prompt the user
94
- }
95
98
  console.warn("[pi-read-delegator] ⚠️ pi-subagents is not installed.");
96
99
  const answer = await prompt("pi-subagents is not installed. Install it now? [Y/n]");
97
100
  const normalized = answer.trim().toLowerCase();
@@ -100,51 +103,35 @@ async function checkDependencies(prompt) {
100
103
  return false;
101
104
  }
102
105
  // Attempt installation
103
- console.log("[pi-read-delegator] 📦 Installing pi-subagents…");
106
+ const piNpmDir = path.join(os.homedir(), ".pi", "agent", "npm");
107
+ console.log("[pi-read-delegator] 📦 Installing pi-subagents to " + piNpmDir + "…");
104
108
  try {
105
- (0, child_process_1.execSync)("pi install npm:pi-subagents", {
109
+ (0, child_process_1.execSync)(`npm install --prefix "${piNpmDir}" pi-subagents`, {
106
110
  stdio: "pipe",
107
111
  timeout: 60_000,
108
112
  encoding: "utf-8",
109
113
  });
110
- console.log("[pi-read-delegator] ✅ pi-subagents installed via 'pi install npm:pi-subagents'.");
114
+ console.log("[pi-read-delegator] ✅ pi-subagents installed via npm.");
111
115
  }
112
116
  catch (firstErr) {
113
- // Fallback to global npm install
114
- try {
115
- (0, child_process_1.execSync)("npm install -g pi-subagents", {
116
- stdio: "pipe",
117
- timeout: 60_000,
118
- encoding: "utf-8",
119
- });
120
- console.log("[pi-read-delegator] ✅ pi-subagents installed via npm.");
121
- }
122
- catch (secondErr) {
123
- console.error("[pi-read-delegator] ❌ Cannot proceed without pi-subagents. Extension disabled.");
124
- return false;
125
- }
117
+ console.error("[pi-read-delegator] ⚠️ npm install failed:", firstErr instanceof Error ? firstErr.message : String(firstErr));
118
+ console.error("[pi-read-delegator] ❌ Cannot proceed without pi-subagents. Extension disabled.");
119
+ return false;
126
120
  }
127
121
  // Verify installation took effect
128
- try {
129
- require.resolve("pi-subagents");
122
+ if (fs.existsSync(piSubagentsPackageJson())) {
130
123
  return true;
131
124
  }
132
- catch {
133
- console.error("[pi-read-delegator] ❌ pi-subagents installed but cannot be found. Restart Pi and try again.");
134
- return false;
135
- }
125
+ console.error("[pi-read-delegator] ❌ pi-subagents installed but cannot be found at " +
126
+ piSubagentsDir() +
127
+ ". Restart Pi and try again.");
128
+ return false;
136
129
  }
137
130
  /**
138
- * Quick synchronous check: can we resolve pi-subagents?
131
+ * Quick synchronous check: does pi-subagents exist on disk?
139
132
  */
140
133
  function isSubagentsInstalled() {
141
- try {
142
- require.resolve("pi-subagents");
143
- return true;
144
- }
145
- catch {
146
- return false;
147
- }
134
+ return fs.existsSync(piSubagentsPackageJson());
148
135
  }
149
136
  // ---------------------------------------------------------------------------
150
137
  // 2. Reader template