fix(pi): keep checking later glob targets after malformed hook output; document Pi 0.58.4+

(cherry picked from commit d449180d75)
This commit is contained in:
Andre Brait authored and safishamsi committed 2026-10-13 10:27:02 +01:00
1 parent 3b3ad322a6
commit 6ebe27a3c9
3 files changed
+12 -3

No files matched your search

+1 -1
View File
@@ -259,7 +259,7 @@ Codex users also need `multi_agent = true` under `[features]` in `~/.codex/confi
`--platform agents` (alias `--platform skills`) targets the generic cross-framework [Agent-Skills](https://github.com/anthropics/skills) locations: the spec's user-global `~/.agents/skills/` (read by `npx skills` and spec-compliant frameworks) for a global install, and `./.agents/skills/` for a project (`--project`) install. The bare `graphify install` stays single-platform (Claude Code) by design — use the named `agents` platform when you want the skill discoverable by any framework that reads `.agents/skills`.
Pi has no `PreToolUse` hook, so `graphify pi guard install` registers a native Pi extension (via Pi's own `pi install <package directory>`) that runs the installed `graphify hook-guard` before Pi's `read`, `grep`, `find` and search-style `bash` calls. Fresh/stale graph decisions and the `GRAPHIFY_HOOK_STRICT=1` once-per-session indexed-read denial come from that same policy, so Pi matches Claude Code's hook behavior; guidance arrives as a `<system-reminder source="graphify">` message. The package ships inside the Graphify installation, so install Graphify persistently (`uv tool install graphifyy` or `pipx install graphifyy`, not `uvx`), restart Pi after installing or upgrading, and remove it with `graphify pi guard uninstall`. Only local file targets are inspected; the hook needs `graphify` on an absolute `PATH` entry outside the project, is bounded to a two-second, 256 KiB-in/64 KiB-out call, and fails open. The same package also loads in [Oh My Pi](https://github.com/can1357/oh-my-pi): `omp plugin install "$(graphify pi guard path)"`. The registered path contains the Python version and venv, so re-run `graphify pi guard install` after changing either, and remove the old entry with `pi remove <old path>`.
Pi has no `PreToolUse` hook, so `graphify pi guard install` registers a native Pi extension (via Pi's own `pi install <package directory>`) that runs the installed `graphify hook-guard` before Pi's `read`, `grep`, `find` and search-style `bash` calls. Fresh/stale graph decisions and the `GRAPHIFY_HOOK_STRICT=1` once-per-session indexed-read denial come from that same policy, so Pi matches Claude Code's hook behavior; guidance arrives as a `<system-reminder source="graphify">` steering message. It needs Pi 0.58.4 or newer: earlier versions let a steering message skip the rest of a parallel tool-call batch. The package ships inside the Graphify installation, so install Graphify persistently (`uv tool install graphifyy` or `pipx install graphifyy`, not `uvx`), restart Pi after installing or upgrading, and remove it with `graphify pi guard uninstall`. Only local file targets are inspected; the hook needs `graphify` on an absolute `PATH` entry outside the project, is bounded to a two-second, 256 KiB-in/64 KiB-out call, and fails open. The same package also loads in [Oh My Pi](https://github.com/can1357/oh-my-pi): `omp plugin install "$(graphify pi guard path)"`. The registered path contains the Python version and venv, so re-run `graphify pi guard install` after changing either, and remove the old entry with `pi remove <old path>`.
> Codex uses `$graphify` instead of `/graphify`.
+2 -1
View File
@@ -168,7 +168,8 @@ export default function graphify(api: HostAPI): void {
}), ctx.cwd, signal, timeout, OUTPUT_LIMIT);
if (signal.aborted || !trusted()) return;
if (!output) continue;
const hook = JSON.parse(output)?.hookSpecificOutput;
let hook;
try { hook = JSON.parse(output)?.hookSpecificOutput; } catch { continue; }
if (hook?.hookEventName !== "PreToolUse") continue;
if (hook.permissionDecision === "deny" && typeof hook.permissionDecisionReason === "string" && hook.permissionDecisionReason.trim()) {
return { block: true, reason: hook.permissionDecisionReason };
+9 -1
View File
@@ -68,7 +68,8 @@ else if (config.mode === "delayed") {
const counterFile = ${JSON.stringify(join(root, "count"))};
const n = existsSync(counterFile) ? Number(readFileSync(counterFile, "utf8")) || 0 : 0;
writeFileSync(counterFile, String(n + 1));
process.stdout.write(JSON.stringify({hookSpecificOutput: {hookEventName: "PreToolUse", additionalContext: "guidance " + (n + 1)}}));
if (config.invalidFirst && n === 0) process.stdout.write("not json");
else process.stdout.write(JSON.stringify({hookSpecificOutput: {hookEventName: "PreToolUse", additionalContext: "guidance " + (n + 1)}}));
} else if (config.mode === "hung") {
process.on("SIGTERM", () => {});
await Bun.sleep(60000);
@@ -135,6 +136,13 @@ test("multi-target glob calls surface every target's guidance", async () => {
expect(result?.additionalContext).toContain("guidance 2");
});
test("malformed output from one glob target does not stop later targets", async () => {
writeFileSync(control, JSON.stringify({ mode: "varying", invalidFirst: true }));
const api = harness();
const result = await api.emit("tool_call", { toolName: "glob", input: { path: "source.py;stale.py" }, toolCallId: "call-1" });
expect(result?.additionalContext).toContain("guidance 2");
});
test("URLs, internal resources, literal selector-like names and false trust do not run project hooks", async () => {
const api = harness();
for (const path of ["https://example.com/source.py", "www.example.com/source.py", "skill://graphify", "local:/source.py", "source.py; ssh://host/source.py"]) {