@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.
- package/index.js +28 -24
- 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
|
-
|
|
162
|
-
|
|
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:
|
|
167
|
+
systemPrompt: event.systemPrompt + "\n\n" + config.orchestrator_prompt,
|
|
170
168
|
};
|
|
171
169
|
});
|
|
172
|
-
//
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
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
|
-
|
|
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
|
-
//
|
|
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
|
-
|
|
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
|
-
|
|
220
|
-
|
|
221
|
-
|
|
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
|
-
//
|
|
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