Files
awesome-copilot/cookbook/copilot-sdk/nodejs/recipe
Anthony Shaw d8fc473383 Add RALPH-loop recipe to Copilot SDK cookbook
Add iterative RALPH-loop (Read, Act, Log, Persist, Halt) pattern
implementations for all four supported languages:

- C#/.NET: ralph-loop.cs with documentation
- Node.js/TypeScript: ralph-loop.ts with documentation
- Python: ralph_loop.py with documentation (async API)
- Go: ralph-loop.go with documentation

Each recipe demonstrates:
- Self-referential iteration where AI reviews its own output
- Completion promise detection to halt the loop
- Max iteration safety limits
- File persistence between iterations

Verified against real Copilot SDK APIs:
- Python: fully verified end-to-end with github-copilot-sdk
- Node.js: fully verified end-to-end with @github/copilot-sdk
- C#: compiles and runs successfully with GitHub.Copilot.SDK
- Go: compiles against github.com/github/copilot-sdk/go v0.1.23
2026-02-11 04:59:20 -08:00
..
2026-02-02 14:01:22 +11:00

Runnable Recipe Examples

This folder contains standalone, executable TypeScript examples for each cookbook recipe. Each file can be run directly with tsx or via npm scripts.

Prerequisites

  • Node.js 18 or later
  • Install dependencies (this links to the local SDK in the repo):
npm install

Running Examples

Each .ts file is a complete, runnable program. You can run them in two ways:

Using npm scripts:

npm run <script-name>

Using tsx directly:

npx tsx <filename>.ts

Available Recipes

Recipe npm script Direct command Description
Error Handling npm run error-handling npx tsx error-handling.ts Demonstrates error handling patterns
Multiple Sessions npm run multiple-sessions npx tsx multiple-sessions.ts Manages multiple independent conversations
Managing Local Files npm run managing-local-files npx tsx managing-local-files.ts Organizes files using AI grouping
PR Visualization npm run pr-visualization npx tsx pr-visualization.ts Generates PR age charts
Persisting Sessions npm run persisting-sessions npx tsx persisting-sessions.ts Save and resume sessions across restarts

Examples with Arguments

PR Visualization with specific repo:

npx tsx pr-visualization.ts --repo github/copilot-sdk

Managing Local Files (edit the file to change target folder):

# Edit the targetFolder variable in managing-local-files.ts first
npx tsx managing-local-files.ts

Local SDK Development

The package.json references the local Copilot SDK using "*", which resolves to the local SDK source. This means:

  • Changes to the SDK source are immediately available
  • No need to publish or install from npm
  • Perfect for testing and development

If you modify the SDK source, you may need to rebuild:

cd ../../src
npm run build

TypeScript Features

These examples use modern TypeScript/Node.js features:

  • Top-level await (requires "type": "module" in package.json)
  • ESM imports
  • Type safety with TypeScript
  • async/await patterns

Learning Resources