@stfade/pi-read-delegator 1.0.5 → 1.0.6

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.
Files changed (2) hide show
  1. package/index.js +28 -24
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -158,22 +158,26 @@ function computeActiveTools(pi, blocked) {
158
158
  // ---------------------------------------------------------------------------
159
159
  async function default_1(pi) {
160
160
  const config = loadConfig();
161
- if (!config.enabled)
162
- return;
163
- // --- 1. Block read tools ------------------------------------------------
164
- const active = computeActiveTools(pi, config.blocked_tools);
165
- pi.setActiveTools(active);
166
- // --- 2. Inject orchestrator system prompt -------------------------------
161
+ // --- ALL actions go inside events. Factory body is registration-only. ---
162
+ // Inject orchestrator system prompt
167
163
  pi.on("before_agent_start", async (event, _ctx) => {
164
+ if (!config.enabled)
165
+ return;
168
166
  return {
169
- systemPrompt: `${event.systemPrompt}\n\n${config.orchestrator_prompt}`,
167
+ systemPrompt: event.systemPrompt + "\n\n" + config.orchestrator_prompt,
170
168
  };
171
169
  });
172
- // --- 3. Intercept bash read commands ------------------------------------
173
- //
174
- // When the LLM tries `cat some-file` or similar, we block the call and
175
- // tell it to route through the reader subagent instead.
170
+ // Block tools and set status bar AFTER runtime is ready
171
+ pi.on("session_start", async (_event, ctx) => {
172
+ if (config.enabled) {
173
+ pi.setActiveTools(computeActiveTools(pi, config.blocked_tools));
174
+ }
175
+ ctx.ui.setStatus("read-delegator", config.enabled ? "● reader: " + config.reader_subagent_name : undefined);
176
+ });
177
+ // Intercept bash read commands
176
178
  pi.on("tool_call", async (event, _ctx) => {
179
+ if (!config.enabled)
180
+ return;
177
181
  if (event.toolName === "bash" || event.toolName === "shell") {
178
182
  const command = String(event.input?.command ?? "");
179
183
  const firstWord = command.trim().split(/\s+/)[0]?.toLowerCase() ?? "";
@@ -181,14 +185,18 @@ async function default_1(pi) {
181
185
  return {
182
186
  block: true,
183
187
  reason: [
184
- `Use subagent(agent: "reader", task: "Execute and summarize: ${command}")`,
188
+ 'Use subagent(agent: "' +
189
+ config.reader_subagent_name +
190
+ '", task: "Execute and summarize: ' +
191
+ command +
192
+ '")',
185
193
  "instead of running file-reading commands directly.",
186
194
  ].join(" "),
187
195
  };
188
196
  }
189
197
  }
190
198
  });
191
- // --- 4. Register /read-delegator command --------------------------------
199
+ // Register /read-delegator command
192
200
  pi.registerCommand("read-delegator", {
193
201
  description: "Manage read delegation (on|off|status)",
194
202
  handler: async (args, ctx) => {
@@ -198,16 +206,15 @@ async function default_1(pi) {
198
206
  case "enable": {
199
207
  config.enabled = true;
200
208
  saveConfig(config);
201
- const active2 = computeActiveTools(pi, config.blocked_tools);
202
- pi.setActiveTools(active2);
209
+ pi.setActiveTools(computeActiveTools(pi, config.blocked_tools));
203
210
  ctx.ui.notify("🟢 Read delegation enabled", "info");
211
+ ctx.ui.setStatus("read-delegator", "● reader: " + config.reader_subagent_name);
204
212
  return;
205
213
  }
206
214
  case "off":
207
215
  case "disable": {
208
216
  config.enabled = false;
209
217
  saveConfig(config);
210
- // Restore all tools
211
218
  pi.setActiveTools(pi.getAllTools().map((t) => t.name));
212
219
  ctx.ui.notify("🔴 Read delegation disabled", "info");
213
220
  ctx.ui.setStatus("read-delegator", undefined);
@@ -216,9 +223,10 @@ async function default_1(pi) {
216
223
  case "status":
217
224
  default: {
218
225
  const lines = [
219
- `Read delegation: ${config.enabled ? "🟢 enabled" : "🔴 disabled"}`,
220
- `Blocked tools: ${config.blocked_tools.join(", ")}`,
221
- `Reader subagent: ${config.reader_subagent_name}`,
226
+ "Read delegation: " +
227
+ (config.enabled ? "🟢 enabled" : "🔴 disabled"),
228
+ "Blocked tools: " + config.blocked_tools.join(", "),
229
+ "Reader subagent: " + config.reader_subagent_name,
222
230
  ];
223
231
  ctx.ui.notify(lines.join("\n"), "info");
224
232
  return;
@@ -226,11 +234,7 @@ async function default_1(pi) {
226
234
  }
227
235
  },
228
236
  });
229
- // --- 5. Ensure reader.md template ---------------------------------------
237
+ // Ensure reader.md template (independent I/O — no Pi API call)
230
238
  await ensureReaderTemplate();
231
- // --- 6. Status bar ------------------------------------------------------
232
- pi.on("session_start", async (_event, ctx) => {
233
- ctx.ui.setStatus("read-delegator", `● reader: ${config.reader_subagent_name}`);
234
- });
235
239
  }
236
240
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stfade/pi-read-delegator",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
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",