mirror of
https://github.com/github/awesome-copilot.git
synced 2026-02-22 11:25:13 +00:00
Add SDK features to all Ralph loop recipes
- Add WorkingDirectory/working_directory to pin sessions to project root - Add OnPermissionRequest/on_permission_request for unattended operation - Add tool execution event logging for visibility - Add See Also cross-links to error-handling and persisting-sessions - Add best practices for WorkingDirectory and permission auto-approval - Consistent across all 4 languages (Node.js, Python, .NET, Go)
This commit is contained in:
@@ -99,8 +99,21 @@ async function ralphLoop(mode: Mode, maxIterations: number = 50) {
|
||||
for (let i = 1; i <= maxIterations; i++) {
|
||||
console.log(`\n=== Iteration ${i}/${maxIterations} ===`);
|
||||
|
||||
// Fresh session — each task gets full context budget
|
||||
const session = await client.createSession({ model: "claude-sonnet-4.5" });
|
||||
const session = await client.createSession({
|
||||
model: "claude-sonnet-4.5",
|
||||
// Pin the agent to the project directory
|
||||
workingDirectory: process.cwd(),
|
||||
// Auto-approve tool calls for unattended operation
|
||||
onPermissionRequest: async () => ({ allow: true }),
|
||||
});
|
||||
|
||||
// Log tool usage for visibility
|
||||
session.on((event) => {
|
||||
if (event.type === "tool.execution_start") {
|
||||
console.log(` ⚙ ${event.data.toolName}`);
|
||||
}
|
||||
});
|
||||
|
||||
try {
|
||||
await session.sendAndWait({ prompt }, 600_000);
|
||||
} finally {
|
||||
@@ -200,6 +213,8 @@ npm run build
|
||||
6. **The plan is disposable**: If the agent goes off track, delete `IMPLEMENTATION_PLAN.md` and re-plan
|
||||
7. **Keep `AGENTS.md` brief**: It's loaded every iteration — operational info only, no progress notes
|
||||
8. **Use a sandbox**: The agent runs autonomously with full tool access — isolate it
|
||||
9. **Set `workingDirectory`**: Pin the session to your project root so tool operations resolve paths correctly
|
||||
10. **Auto-approve permissions**: Use `onPermissionRequest` to allow tool calls without interrupting the loop
|
||||
|
||||
## When to Use a Ralph Loop
|
||||
|
||||
@@ -214,3 +229,8 @@ npm run build
|
||||
- One-shot operations that don't benefit from iteration
|
||||
- Vague requirements without testable acceptance criteria
|
||||
- Exploratory prototyping where direction isn't clear
|
||||
|
||||
## See Also
|
||||
|
||||
- [Error Handling](error-handling.md) — timeout patterns and graceful shutdown for long-running sessions
|
||||
- [Persisting Sessions](persisting-sessions.md) — save and resume sessions across restarts
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
"name": "copilot-sdk-cookbook-recipes",
|
||||
"version": "1.0.0",
|
||||
"dependencies": {
|
||||
"@github/copilot-sdk": "file:../../src"
|
||||
"@github/copilot-sdk": "*"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^22.19.7",
|
||||
|
||||
@@ -39,9 +39,19 @@ async function ralphLoop(mode: Mode, maxIterations: number) {
|
||||
for (let i = 1; i <= maxIterations; i++) {
|
||||
console.log(`\n=== Iteration ${i}/${maxIterations} ===`);
|
||||
|
||||
// Fresh session — each task gets full context budget
|
||||
const session = await client.createSession({
|
||||
model: "claude-sonnet-4.5",
|
||||
// Pin the agent to the project directory
|
||||
workingDirectory: process.cwd(),
|
||||
// Auto-approve tool calls for unattended operation
|
||||
onPermissionRequest: async () => ({ allow: true }),
|
||||
});
|
||||
|
||||
// Log tool usage for visibility
|
||||
session.on((event) => {
|
||||
if (event.type === "tool.execution_start") {
|
||||
console.log(` ⚙ ${event.data.toolName}`);
|
||||
}
|
||||
});
|
||||
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user