Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 30 additions & 11 deletions .github/drivers/copilot-sdk-driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ async function main(): Promise<void> {
const { resolveModelWithFallback } = actionRequire("./model_fallback.cjs");
const { resolveRoutingReasoningEffort } = actionRequire("./copilot_routing_effort.cjs");
const fixture = process.env["RIG_WORKFLOW_FIXTURE"] === "1";
const sourceTool = process.env["RIG_WORKFLOW_SOURCE_TOOL"] === "1";
const provider = parseMultiProviderJson(requiredEnv("GH_AW_COPILOT_SDK_MULTI_PROVIDER_JSON"));
if (!provider) throw new Error("Invalid SDK provider configuration");
const requestedModel = process.env["GH_AW_MODEL_ROUTING"] === "1"
Expand All @@ -34,7 +35,7 @@ async function main(): Promise<void> {
const prompt = await readFile(requiredEnv("GH_AW_PROMPT"), "utf8");
const source = fixture ? prompt.match(/```rig\n([\s\S]*?)\n```/)?.[1] : undefined;
if (fixture && !source) throw new Error("Expected the prevalidated Rig fixture in the workflow prompt");
const cwd = fixture ? requiredEnv("GITHUB_WORKSPACE") : resolveCopilotSDKWorkingDirectory();
const cwd = fixture || sourceTool ? requiredEnv("GITHUB_WORKSPACE") : resolveCopilotSDKWorkingDirectory();
const uri = requiredEnv("COPILOT_SDK_URI");
const connectionToken = requiredEnv("COPILOT_CONNECTION_TOKEN");
const redact = (text: string) => text.replaceAll(connectionToken, "[redacted]");
Expand Down Expand Up @@ -90,22 +91,40 @@ async function main(): Promise<void> {
process.exitCode = COPILOT_MODEL_VERIFICATION_EXIT_CODE;
failSession(new Error(message));
}
const launchTool = createRigLaunchTool({ uri, connectionToken, cwd });
const launchTool = createRigLaunchTool({
uri,
connectionToken,
cwd,
...(sourceTool && { timeoutMs: 8 * 60 * 1000, includeStderr: true }),
});
let launched = false;
const sourceVersions = new Set<string>();
let sourceLaunches = 0;
let launchError: unknown;
let result: string | undefined;
const launch: typeof launchTool.handler = async (args, invocation) => {
try {
if (launched) throw new Error("The integration fixture may only be launched once");
launched = true;
if (!source || args.source.trim() !== source.trim()) throw new Error("The integration fixture must be copied unchanged");
if (fixture) {
if (launched) throw new Error("The integration fixture may only be launched once");
launched = true;
if (!source || args.source.trim() !== source.trim()) throw new Error("The integration fixture must be copied unchanged");
} else if (sourceTool) {
if (++sourceLaunches > 2) throw new Error("Rig source launch limit exceeded (2)");
if (Buffer.byteLength(args.source, "utf8") > 16 * 1024) throw new Error("Rig source exceeds 16 KiB");
sourceVersions.add(args.source);
if (sourceVersions.size > 2) throw new Error("Rig source attempt limit exceeded (2)");
} else {
throw new Error("Rig source launch tool is not enabled for this workflow");
}
const output = await launchTool.handler(args, invocation);
if (typeof output !== "string") throw new Error("Expected Rig launcher stdout");
result = output;
await writeFile("/tmp/gh-aw/agent/rig-skill-integration.json", output, "utf8");
if (fixture) {
result = output;
await writeFile("/tmp/gh-aw/agent/rig-skill-integration.json", output, "utf8");
}
return output;
} catch (error) {
launchError = error;
if (fixture) launchError = error;
const message = redact(error instanceof Error ? error.message : String(error));
return { resultType: "failure", textResultForLlm: message, error: message };
}
Expand All @@ -125,13 +144,13 @@ async function main(): Promise<void> {
...(servers && { mcp: { servers } }),
...(toolBudget && { hooks: { handlers: { onPreToolUse: toolBudget.onPreToolUse } } }),
permissions: {
onRequest: (request, invocation) => fixture && request.kind === "custom-tool" && request.toolName === "run_rig"
onRequest: (request, invocation) => (fixture || sourceTool) && request.kind === "custom-tool" && request.toolName === "run_rig"
? sdk.approveAll(request, invocation)
: permissions(request, invocation),
},
tools: {
availableTools: fixture ? sessionTools.availableTools.addCustom("run_rig") : sessionTools.availableTools,
definitions: fixture ? [...sessionTools.definitions, { ...launchTool, handler: launch }] : sessionTools.definitions,
availableTools: fixture || sourceTool ? sessionTools.availableTools.addCustom("run_rig") : sessionTools.availableTools,
definitions: fixture || sourceTool ? [...sessionTools.definitions, { ...launchTool, handler: launch }] : sessionTools.definitions,
},
});
try {
Expand Down
9 changes: 8 additions & 1 deletion .github/workflows/monthly-pr-clusters.lock.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 9 additions & 6 deletions .github/workflows/monthly-pr-clusters.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ strict: true
env:
NPM_CONFIG_MIN_RELEASE_AGE: "3"
NPM_CONFIG_REGISTRY: "https://packagefeedproxy.microsoft.io/npm/"
RIG_WORKFLOW_SOURCE_TOOL: "1"
timeout-minutes: 40
concurrency:
group: monthly-pr-clusters
Expand Down Expand Up @@ -172,12 +173,14 @@ exactly three total clusters; if fewer than three meaningful clusters exist,
report only those and explain why. Do not fabricate filler clusters.

Keep the complete source under 16 KiB. Save it in `/tmp/gh-aw/agent/`, lint and
typecheck it using the installed skill, and fix failures before execution.
Follow the shared Rig launch instructions: use a literal printf pipeline into
the installed skill's `run.ts`, inherit the SDK connection unchanged, and do not
start a server or inspect credentials. Capture actual stdout and stderr. Save
the parsed result to `/tmp/gh-aw/agent/pr-clusters-result.json` and independently
check its partition, counts, ranking, and window against the corpus.
typecheck it using the installed skill, and fix failures before execution. Run
the program with the harness-owned `run_rig` tool, passing the complete source.
The tool supplies the SDK connection and allows at most two source versions and
two executions; do not use Bash to launch the program, start a server, or inspect
credentials. Its JSON response contains the actual `stdout` and `stderr`; parse
the program result from `stdout`. Save it to
`/tmp/gh-aw/agent/pr-clusters-result.json` and independently check its partition,
counts, ranking, and window against the corpus.

Allow at most two source attempts and two executions total, within the same
20-minute execution budget. A repair must address a captured error without
Expand Down
3 changes: 2 additions & 1 deletion skills/rig/harness-tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ It starts the current Node executable with `run.ts --connection-fd=3`, sends
source over stdin, and sends `{ uri, connectionToken }` through descriptor 3.
The child environment explicitly excludes `COPILOT_SDK_URI` and
`COPILOT_CONNECTION_TOKEN`. Existing provider configuration and other parent
environment values remain inherited.
environment values remain inherited. Set `includeStderr` to return successful
stdout and stderr together as JSON; by default the tool returns stdout only.

Launch errors include stderr and a nonzero exit status; the tool throws
instead of returning success-shaped output. It kills a timed-out subprocess,
Expand Down
4 changes: 3 additions & 1 deletion skills/rig/launch-tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export type RigLaunchToolOptions = {
cwd: string;
launcherPath?: string;
timeoutMs?: number;
includeStderr?: boolean;
};

export function createRigLaunchTool(options: RigLaunchToolOptions): Tool<{ source: string }> & {
Expand All @@ -17,6 +18,7 @@ export function createRigLaunchTool(options: RigLaunchToolOptions): Tool<{ sourc
throw new TypeError("Rig launch tool requires a nonempty URI and connection token");
}
const timeoutMs = options.timeoutMs ?? 180_000;
const includeStderr = options.includeStderr ?? false;
if (!Number.isFinite(timeoutMs) || timeoutMs <= 0) {
throw new TypeError("Rig launch tool timeoutMs must be positive");
}
Expand Down Expand Up @@ -83,7 +85,7 @@ export function createRigLaunchTool(options: RigLaunchToolOptions): Tool<{ sourc
} else if (code !== 0) {
reject(new Error(redact(`Rig launch failed (${signal ?? code}): ${stderr}`)));
} else {
resolve(redact(stdout));
resolve(redact(includeStderr ? JSON.stringify({ stdout, stderr }) : stdout));
}
});
});
Expand Down
18 changes: 17 additions & 1 deletion src/launch-tool.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ afterEach(async () => {
await Promise.all(temporaryDirs.splice(0).map((path: string) => rm(path, { recursive: true, force: true })));
});

async function fixture(source: string, timeoutMs?: number) {
async function fixture(source: string, timeoutMs?: number, includeStderr = false) {
const cwd = await mkdtemp(join(tmpdir(), "rig-launch-tool-test-"));
temporaryDirs.push(cwd);
const launcherPath = join(cwd, "launcher.mjs");
await writeFile(launcherPath, source);
return createRigLaunchTool({
uri: "http://localhost:4242", connectionToken: "pipe-test-token", cwd, launcherPath,
...(timeoutMs !== undefined ? { timeoutMs } : {}),
...(includeStderr && { includeStderr }),
});
}

Expand Down Expand Up @@ -92,3 +93,18 @@ process.stdout.write(connectionToken);
`);
await expect(invoke(tool, "test")).resolves.toBe("[redacted]");
});

it("can return successful stdout and stderr together", async () => {
const tool = await fixture(`
process.stdin.resume();
process.stdin.on("end", () => {
process.stdout.write("program output");
process.stderr.write("diagnostic output");
});
`, undefined, true);
const result = await invoke(tool, "test");
expect(JSON.parse(String(result))).toEqual({
stdout: "program output",
stderr: "diagnostic output",
});
});
4 changes: 4 additions & 0 deletions src/monthly-pr-clusters-workflow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ describe("Monthly PR clusters workflow", () => {
expect(markdown).toContain(" - skills/rig");
expect(markdown).toContain(" - shared/rig.md");
expect(markdown).toContain("run: npm ci");
expect(markdown).toContain('RIG_WORKFLOW_SOURCE_TOOL: "1"');
expect(prompt).toContain("harness-owned `run_rig` tool");
expect(prompt).toContain("at most two source versions and\ntwo executions");
expect(prompt).not.toContain("literal printf pipeline");
});

it("preserves experiments in dedicated repo-memory and publishes only through safe outputs", () => {
Expand Down
8 changes: 6 additions & 2 deletions src/rig-skill-workflow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,11 @@ describe("Rig skill agentic workflow", () => {
expect(markdown).not.toContain("| node .github/skills/rig/run.ts >");
const driver = readFileSync(new URL("../.github/drivers/copilot-sdk-driver.ts", import.meta.url), "utf8");
expect(driver).toContain('from "../../skills/rig/launch-tool.ts"');
expect(driver).toContain("createRigLaunchTool({ uri, connectionToken, cwd })");
expect(driver).toContain("definitions: fixture ? [...sessionTools.definitions,");
expect(driver).toContain("createRigLaunchTool({");
expect(driver).toContain("timeoutMs: 8 * 60 * 1000");
expect(driver).toContain("definitions: fixture || sourceTool ? [...sessionTools.definitions,");
expect(driver).toContain("Rig source launch limit exceeded (2)");
expect(driver).toContain("Rig source attempt limit exceeded (2)");
expect(driver).not.toContain("sessionTools.tools");
expect(driver).not.toContain("launcherPath:");
const shared = readFileSync(new URL("../.github/workflows/shared/rig.md", import.meta.url), "utf8");
Expand All @@ -102,6 +105,7 @@ describe("Rig skill agentic workflow", () => {
expect(execution).toBeGreaterThan(restore);
expect(lock.slice(execution)).toContain(".github/drivers/copilot-sdk-driver.ts");
expect(/^ RIG_WORKFLOW_FIXTURE: "1"$/m.test(lock)).toBe(workflow === "rig-skill-integration");
expect(/^ RIG_WORKFLOW_SOURCE_TOOL: "1"$/m.test(lock)).toBe(workflow === "monthly-pr-clusters");
});

it.each([program, 'const value = "don\'t expand $HOME, $(exit 42), `exit 42`, %s, \\\\n";\n\n// literal | && ; < >'])(
Expand Down