Skip to content

Commit 830f084

Browse files
committed
fix(gemini): handle plan_filename rename and fix scoping bug
Gemini CLI nightly renamed plan_path to plan_filename in exit_plan_mode. Accept both field names for forward/backward compatibility. Reconstruct full plan path from transcript_path + session_id + plans/ + filename. Also hoist planFilename variable out of try block so it's accessible in the deny output path (was causing ReferenceError). For provenance purposes, this commit was AI assisted.
1 parent 369d762 commit 830f084

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

apps/hook/server/index.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -750,23 +750,29 @@ if (args[0] === "sessions") {
750750
let planContent = "";
751751
let permissionMode = "default";
752752
let isGemini = false;
753+
let planFilename = "";
753754
let event: Record<string, any>;
754755
try {
755756
event = JSON.parse(eventJson);
756757

757-
// Detect harness: Gemini sends plan_path (file on disk), Claude Code sends plan (inline)
758-
isGemini = !!event.tool_input?.plan_path;
758+
// Detect harness: Gemini sends plan_filename (file on disk), Claude Code sends plan (inline)
759+
planFilename = event.tool_input?.plan_filename || event.tool_input?.plan_path || "";
760+
isGemini = !!planFilename;
759761

760762
if (isGemini) {
761-
const planFilePath = path.resolve(event.cwd, event.tool_input.plan_path);
763+
// Reconstruct full plan path from transcript_path and session_id:
764+
// transcript_path = <projectTempDir>/chats/session-...json
765+
// plan lives at = <projectTempDir>/<session_id>/plans/<plan_filename>
766+
const projectTempDir = path.dirname(path.dirname(event.transcript_path));
767+
const planFilePath = path.join(projectTempDir, event.session_id, "plans", planFilename);
762768
planContent = await Bun.file(planFilePath).text();
763769
} else {
764770
planContent = event.tool_input?.plan || "";
765771
}
766772

767773
permissionMode = event.permission_mode || "default";
768-
} catch {
769-
console.error("Failed to parse hook event from stdin");
774+
} catch (e: any) {
775+
console.error(`Failed to parse hook event from stdin: ${e?.message || e}`);
770776
process.exit(1);
771777
}
772778

@@ -823,7 +829,7 @@ if (args[0] === "sessions") {
823829
JSON.stringify({
824830
decision: "deny",
825831
reason: planDenyFeedback(result.feedback || "", "exit_plan_mode", {
826-
planFilePath: event.tool_input.plan_path,
832+
planFilePath: planFilename,
827833
}),
828834
})
829835
);

0 commit comments

Comments
 (0)