Skip to content

Commit 5d98e93

Browse files
committed
Fix ralph loop write permission and deprecated destroy() call
Replace PermissionHandler.approve_all / approveAll with explicit permission handlers that return {"kind": "approved", "rules": []} / { allow: true }, enabling file-write tool calls needed to create IMPLEMENTATION_PLAN.md. Also replace deprecated session.destroy() with session.disconnect() in both Python and TypeScript recipes.
1 parent 0c3c5bb commit 5d98e93

2 files changed

Lines changed: 8 additions & 8 deletions

File tree

cookbook/copilot-sdk/nodejs/recipe/ralph-loop.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { readFile } from "fs/promises";
2-
import { CopilotClient, approveAll } from "@github/copilot-sdk";
2+
import { CopilotClient } from "@github/copilot-sdk";
33

44
/**
55
* Ralph loop: autonomous AI task loop with fresh context per iteration.
@@ -43,8 +43,8 @@ async function ralphLoop(mode: Mode, maxIterations: number) {
4343
model: "gpt-5.1-codex-mini",
4444
// Pin the agent to the project directory
4545
workingDirectory: process.cwd(),
46-
// Auto-approve tool calls for unattended operation
47-
onPermissionRequest: approveAll,
46+
// Auto-approve all tool calls (including file writes) for unattended operation
47+
onPermissionRequest: async () => ({ allow: true }),
4848
});
4949

5050
// Log tool usage for visibility
@@ -57,7 +57,7 @@ async function ralphLoop(mode: Mode, maxIterations: number) {
5757
try {
5858
await session.sendAndWait({ prompt }, 600_000);
5959
} finally {
60-
await session.destroy();
60+
await session.disconnect();
6161
}
6262

6363
console.log(`\nIteration ${i} complete.`);

cookbook/copilot-sdk/python/recipe/ralph_loop.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import sys
2323
from pathlib import Path
2424

25-
from copilot import CopilotClient, MessageOptions, SessionConfig, PermissionHandler
25+
from copilot import CopilotClient, MessageOptions, SessionConfig
2626

2727

2828
async def ralph_loop(mode: str = "build", max_iterations: int = 50):
@@ -47,8 +47,8 @@ async def ralph_loop(mode: str = "build", max_iterations: int = 50):
4747
model="gpt-5.1-codex-mini",
4848
# Pin the agent to the project directory
4949
working_directory=str(Path.cwd()),
50-
# Auto-approve tool calls for unattended operation
51-
on_permission_request=PermissionHandler.approve_all,
50+
# Auto-approve all tool calls (including file writes) for unattended operation
51+
on_permission_request=lambda _req, _ctx: {"kind": "approved", "rules": []},
5252
))
5353

5454
# Log tool usage for visibility
@@ -62,7 +62,7 @@ def log_tool_event(event):
6262
MessageOptions(prompt=prompt), timeout=600
6363
)
6464
finally:
65-
await session.destroy()
65+
await session.disconnect()
6666

6767
print(f"\nIteration {i} complete.")
6868

0 commit comments

Comments
 (0)