Skip to content

Commit 7df93ff

Browse files
Copilotpelikhan
andauthored
Prefer Copilot env before default engine override
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
1 parent 1de3d63 commit 7df93ff

4 files changed

Lines changed: 36 additions & 5 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ configureAgent(codexEngine());
296296
configureAgent(geminiEngine());
297297
```
298298

299-
If you do not call `configureAgent(...)`, Rig now auto-selects a default engine from environment variables: `ANTHROPIC_API_KEY``anthropicEngine()`, `OPENAI_API_KEY``codexEngine()`, `GEMINI_API_KEY`/`GOOGLE_API_KEY``geminiEngine()`, otherwise `copilotEngine()`. Set `RIG_ENGINE` to `copilot`, `anthropic`, `codex`, or `gemini` to force one explicitly.
299+
If you do not call `configureAgent(...)`, Rig now auto-selects a default engine from environment variables: `COPILOT_SDK_URI``copilotEngine()`, then `RIG_ENGINE` (`copilot` | `anthropic` | `codex` | `gemini`) if set, then `ANTHROPIC_API_KEY``anthropicEngine()`, `OPENAI_API_KEY``codexEngine()`, `GEMINI_API_KEY`/`GOOGLE_API_KEY``geminiEngine()`, otherwise `copilotEngine()`.
300300

301301
`piEngine()` uses the maintained `@earendil-works/pi-agent-core` package and requires the provider for model lookup. `anthropicEngine()` uses `@anthropic-ai/sdk`. Both adapters preserve conversation state across repair turns and map Rig tools to their SDK tool runners.
302302

skills/rig/references/runtime.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,12 @@ configureAgent(geminiEngine());
8686
```
8787

8888
- If you do not call `configureAgent(...)`, Rig auto-selects an engine from env vars:
89+
- `COPILOT_SDK_URI``copilotEngine()`
90+
- `RIG_ENGINE` (`copilot` | `anthropic` | `codex` | `gemini`) to force a specific default when Copilot URI is not set.
8991
- `ANTHROPIC_API_KEY``anthropicEngine()`
9092
- `OPENAI_API_KEY``codexEngine()`
9193
- `GEMINI_API_KEY` or `GOOGLE_API_KEY``geminiEngine()`
9294
- otherwise → `copilotEngine()`
93-
- set `RIG_ENGINE` (`copilot` | `anthropic` | `codex` | `gemini`) to force a specific default.
9495
- `copilotEngine()` uses the Copilot SDK HTTP transport by default; launcher `--server` selects stdio.
9596
- `piEngine({ provider })` uses `@earendil-works/pi-agent-core` and requires a provider for model lookup.
9697
- `anthropicEngine()` uses `@anthropic-ai/sdk` and reads `ANTHROPIC_API_KEY`.

skills/rig/rig.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -457,13 +457,13 @@ function resolveDefaultEngineKind(options: DefaultEngineOptions = {}): DefaultEn
457457
if (options.startServer) {
458458
return "copilot";
459459
}
460+
if (hasNonEmptyEnv("COPILOT_SDK_URI")) {
461+
return "copilot";
462+
}
460463
const configuredEngine = process.env["RIG_ENGINE"]?.trim().toLowerCase();
461464
if (configuredEngine === "copilot" || configuredEngine === "anthropic" || configuredEngine === "codex" || configuredEngine === "gemini") {
462465
return configuredEngine;
463466
}
464-
if (hasNonEmptyEnv("COPILOT_SDK_URI")) {
465-
return "copilot";
466-
}
467467
if (hasNonEmptyEnv("ANTHROPIC_API_KEY")) {
468468
return "anthropic";
469469
}

src/launcher-default-engine.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,11 @@ beforeEach(() => {
7575
mocks.codexRun.mockClear();
7676
mocks.codexStartThread.mockClear();
7777
delete process.env["COPILOT_SDK_URI"];
78+
delete process.env["RIG_ENGINE"];
7879
delete process.env["ANTHROPIC_API_KEY"];
7980
delete process.env["OPENAI_API_KEY"];
81+
delete process.env["GEMINI_API_KEY"];
82+
delete process.env["GOOGLE_API_KEY"];
8083
});
8184

8285
it("uses the launcher cwd when mounting the default copilot engine", async () => {
@@ -126,6 +129,33 @@ it("uses COPILOT_SDK_URI when mounting the default copilot engine", async () =>
126129
}
127130
});
128131

132+
it("prefers COPILOT_SDK_URI over RIG_ENGINE when mounting the default engine", async () => {
133+
const sendAndWait = vi.fn().mockResolvedValue(JSON.stringify("copilot-preferred"));
134+
mocks.createSession.mockResolvedValue({ sendAndWait });
135+
process.env["COPILOT_SDK_URI"] = "http://127.0.0.1:4242";
136+
process.env["RIG_ENGINE"] = "anthropic";
137+
process.env["ANTHROPIC_API_KEY"] = "test-key";
138+
mocks.forUri.mockImplementation(((url: string) => ({ kind: "uri", url })) as any);
139+
140+
const fixturePath = resolve(dirname(fileURLToPath(import.meta.url)), "./launcher.fixture.ts");
141+
142+
try {
143+
await launchRigProgram(fixturePath);
144+
145+
const call = agent({
146+
name: "launcher-default-engine-copilot-preferred-test",
147+
input: s.object({}),
148+
});
149+
const result = await call({});
150+
expect(result).toBe("copilot-preferred");
151+
expect(mocks.forUri).toHaveBeenCalledWith("http://127.0.0.1:4242");
152+
expect(mocks.copilotClientCtor).toHaveBeenCalled();
153+
expect(mocks.anthropicConstructor).not.toHaveBeenCalled();
154+
} finally {
155+
mocks.forUri.mockImplementation(mocks.defaultForUri);
156+
}
157+
});
158+
129159
it("automatically mounts anthropicEngine when ANTHROPIC_API_KEY is set", async () => {
130160
process.env["ANTHROPIC_API_KEY"] = "test-key";
131161
const fixturePath = resolve(dirname(fileURLToPath(import.meta.url)), "./launcher.fixture.ts");

0 commit comments

Comments
 (0)