mirror of
https://github.com/github/awesome-copilot.git
synced 2026-03-23 17:45:12 +00:00
* Apply permission handler requirements across Copilot SDK docs Co-authored-by: jamesmontemagno <1676321+jamesmontemagno@users.noreply.github.com> Agent-Logs-Url: https://github.com/jamesmontemagno/awesome-copilot/sessions/adf27a88-92f8-4ca6-b3fe-1204e3bb9963 * Polish permission update formatting in SDK examples Co-authored-by: jamesmontemagno <1676321+jamesmontemagno@users.noreply.github.com> Agent-Logs-Url: https://github.com/jamesmontemagno/awesome-copilot/sessions/adf27a88-92f8-4ca6-b3fe-1204e3bb9963 * Fix review comments on SDK permission handling PR Address 5 review comments from PR #1103: 1. Fix invalid object literal syntax (stray comma) in resumeSession example in copilot-sdk-nodejs.instructions.md 2. Replace unused PermissionHandler import with actual usage in cookbook/copilot-sdk/python/recipe/ralph_loop.py (was using inline lambda instead) 3. Replace unused approveAll import with actual usage in cookbook/copilot-sdk/nodejs/recipe/ralph-loop.ts (was using inline handler instead) 4. Add missing PermissionHandler import to 4 Python code snippets in skills/copilot-sdk/SKILL.md that reference it without importing 5. Add missing approveAll import to 3 TypeScript code snippets in skills/copilot-sdk/SKILL.md that reference it without importing * Refactor session creation to improve code formatting and consistency across SDK examples * Fix formatting: split multi-property lines and put closing braces on own lines Address review comments on PR #1107: - Split OnPermissionRequest + Model onto separate lines in Go, C#, TypeScript - Put closing }); on its own line consistently across all examples - Fix indentation in SKILL.md Quick Start, CLI URL, Error Handling sections - Fix cookbook Go multiple-sessions and error-handling formatting - Fix ralph-loop.md TypeScript indentation --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: jamesmontemagno <1676321+jamesmontemagno@users.noreply.github.com>
79 lines
2.6 KiB
TypeScript
79 lines
2.6 KiB
TypeScript
import { readFile } from "fs/promises";
|
|
import { CopilotClient, approveAll } from "@github/copilot-sdk";
|
|
|
|
/**
|
|
* Ralph loop: autonomous AI task loop with fresh context per iteration.
|
|
*
|
|
* Two modes:
|
|
* - "plan": reads PROMPT_plan.md, generates/updates IMPLEMENTATION_PLAN.md
|
|
* - "build": reads PROMPT_build.md, implements tasks, runs tests, commits
|
|
*
|
|
* Each iteration creates a fresh session so the agent always operates in
|
|
* the "smart zone" of its context window. State is shared between
|
|
* iterations via files on disk (IMPLEMENTATION_PLAN.md, AGENTS.md, specs/*).
|
|
*
|
|
* Usage:
|
|
* npx tsx ralph-loop.ts # build mode, 50 iterations
|
|
* npx tsx ralph-loop.ts plan # planning mode
|
|
* npx tsx ralph-loop.ts 20 # build mode, 20 iterations
|
|
* npx tsx ralph-loop.ts plan 5 # planning mode, 5 iterations
|
|
*/
|
|
|
|
type Mode = "plan" | "build";
|
|
|
|
async function ralphLoop(mode: Mode, maxIterations: number) {
|
|
const promptFile = mode === "plan" ? "PROMPT_plan.md" : "PROMPT_build.md";
|
|
|
|
const client = new CopilotClient();
|
|
await client.start();
|
|
|
|
console.log("━".repeat(40));
|
|
console.log(`Mode: ${mode}`);
|
|
console.log(`Prompt: ${promptFile}`);
|
|
console.log(`Max: ${maxIterations} iterations`);
|
|
console.log("━".repeat(40));
|
|
|
|
try {
|
|
const prompt = await readFile(promptFile, "utf-8");
|
|
|
|
for (let i = 1; i <= maxIterations; i++) {
|
|
console.log(`\n=== Iteration ${i}/${maxIterations} ===`);
|
|
|
|
const session = await client.createSession({
|
|
model: "gpt-5.1-codex-mini",
|
|
// Pin the agent to the project directory
|
|
workingDirectory: process.cwd(),
|
|
// Auto-approve tool calls for unattended operation
|
|
onPermissionRequest: approveAll,
|
|
});
|
|
|
|
// 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 {
|
|
await session.destroy();
|
|
}
|
|
|
|
console.log(`\nIteration ${i} complete.`);
|
|
}
|
|
|
|
console.log(`\nReached max iterations: ${maxIterations}`);
|
|
} finally {
|
|
await client.stop();
|
|
}
|
|
}
|
|
|
|
// Parse CLI args
|
|
const args = process.argv.slice(2);
|
|
const mode: Mode = args.includes("plan") ? "plan" : "build";
|
|
const maxArg = args.find((a) => /^\d+$/.test(a));
|
|
const maxIterations = maxArg ? parseInt(maxArg) : 50;
|
|
|
|
ralphLoop(mode, maxIterations).catch(console.error);
|