diff --git a/.github/drivers/copilot-sdk-driver.ts b/.github/drivers/copilot-sdk-driver.ts index 39800e6..1e82228 100644 --- a/.github/drivers/copilot-sdk-driver.ts +++ b/.github/drivers/copilot-sdk-driver.ts @@ -24,6 +24,7 @@ async function main(): Promise { 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" @@ -34,7 +35,7 @@ async function main(): Promise { 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]"); @@ -90,22 +91,40 @@ async function main(): Promise { 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(); + 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 }; } @@ -125,13 +144,13 @@ async function main(): Promise { ...(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 { diff --git a/.github/workflows/monthly-pr-clusters.lock.yml b/.github/workflows/monthly-pr-clusters.lock.yml index 6d25aba..275a9d7 100644 --- a/.github/workflows/monthly-pr-clusters.lock.yml +++ b/.github/workflows/monthly-pr-clusters.lock.yml @@ -1,4 +1,4 @@ -# gh-aw-metadata: {"schema_version":"v4","frontmatter_hash":"74b87ef9dc6f789549b24408c4c2ab7fad8b3172f7951d6a3ba07345184cd632","body_hash":"f4e0fe47bbe89f2815a7bb92f9b8bdc7ecb3f6be055ff952991f8b21e5a9c2f5","compiler_version":"v1.4.0","strict":true,"agent_id":"copilot","engine_versions":{"copilot":"1.0.113","copilot-sdk":"2.0.0"}} +# gh-aw-metadata: {"schema_version":"v4","frontmatter_hash":"e5cec37b22bc8773d1514facfb538fc2ef8925aa47d4adc3af72171075db4106","body_hash":"876a50fa0763bbe03620a43a59d8f824871e774e44ac68ffa7e3fc56e504ccb2","compiler_version":"v1.4.0","strict":true,"agent_id":"copilot","engine_versions":{"copilot":"1.0.113","copilot-sdk":"2.0.0"}} # gh-aw-manifest: {"version":1,"secrets":["GH_AW_DEFAULT_OTLP_ENDPOINT","GH_AW_DEFAULT_OTLP_HEADERS","GH_AW_GITHUB_MCP_SERVER_TOKEN","GH_AW_GITHUB_TOKEN","GITHUB_TOKEN"],"actions":[{"repo":"actions/checkout","sha":"3d3c42e5aac5ba805825da76410c181273ba90b1","version":"v7.0.1"},{"repo":"actions/download-artifact","sha":"9000827ccba6bdab643e8b6fd33ac0654aef8333","version":"v8.0.2"},{"repo":"actions/github-script","sha":"3a2844b7e9c422d3c10d287c895573f7108da1b3","version":"v9.0.0"},{"repo":"actions/setup-node","sha":"949feb2413d6458794dcd2491c4babbbce0c15c1","version":"v7.1.0"},{"repo":"actions/upload-artifact","sha":"cf430e030ddbb5b0abf93d22962f4752f3646cd9","version":"v7.0.2"},{"repo":"github/gh-aw-actions/setup","sha":"b907753c079ddd7d6829a0d8c24e02e818b4b45f","version":"v1.4.0"}],"skills":["skills/rig"],"containers":[{"image":"ghcr.io/github/gh-aw-firewall/agent:0.29.20","digest":"sha256:b9cd8d7d1a9c2693e5d91db035a678fb1ea8d87ce691e08ec091b327e5e8ba75","pinned_image":"ghcr.io/github/gh-aw-firewall/agent:0.29.20@sha256:b9cd8d7d1a9c2693e5d91db035a678fb1ea8d87ce691e08ec091b327e5e8ba75"},{"image":"ghcr.io/github/gh-aw-firewall/api-proxy:0.29.20","digest":"sha256:fc6c1eff686514d26ff90ae1398e0f6e3dcad8d2e43d11b16df312c1e72c0ace","pinned_image":"ghcr.io/github/gh-aw-firewall/api-proxy:0.29.20@sha256:fc6c1eff686514d26ff90ae1398e0f6e3dcad8d2e43d11b16df312c1e72c0ace"},{"image":"ghcr.io/github/gh-aw-firewall/cli-proxy:0.29.20","digest":"sha256:743396030b149763880978f35ad679fe02b1c0be6697b01fbf6d43f4ac2ae081","pinned_image":"ghcr.io/github/gh-aw-firewall/cli-proxy:0.29.20@sha256:743396030b149763880978f35ad679fe02b1c0be6697b01fbf6d43f4ac2ae081"},{"image":"ghcr.io/github/gh-aw-firewall/squid:0.29.20","digest":"sha256:1c4a4a12fcea206a81d656cb1f73847420a2c041d02ab51235364079a1e31d71","pinned_image":"ghcr.io/github/gh-aw-firewall/squid:0.29.20@sha256:1c4a4a12fcea206a81d656cb1f73847420a2c041d02ab51235364079a1e31d71"},{"image":"ghcr.io/github/gh-aw-mcpg:v0.5.14","digest":"sha256:716b41d53a20660e945c351c08140380430d65d98d3263596e45114c29fa7a43","pinned_image":"ghcr.io/github/gh-aw-mcpg:v0.5.14@sha256:716b41d53a20660e945c351c08140380430d65d98d3263596e45114c29fa7a43"},{"image":"ghcr.io/github/gh-aw-node","digest":"sha256:a8082161d7dceda14b68f32eb39d0eaa96b825d07f5895b096afab9d9e0c7748","pinned_image":"ghcr.io/github/gh-aw-node@sha256:a8082161d7dceda14b68f32eb39d0eaa96b825d07f5895b096afab9d9e0c7748"},{"image":"ghcr.io/github/github-mcp-server:v2.2.0","digest":"sha256:040c4e99810076035eb1d9beb4b4a96fcf589c43cefed6ff51a46a553eb4e174","pinned_image":"ghcr.io/github/github-mcp-server:v2.2.0@sha256:040c4e99810076035eb1d9beb4b4a96fcf589c43cefed6ff51a46a553eb4e174"}],"mcp_servers":[{"name":"safeoutputs","tools":["create_issue","noop","report_incomplete","report_missing_data","report_missing_tool"]}],"threat_detection":{"mode":"enabled"},"admission":false,"agent_metadata":{"03cbf8931deff21d5116":{"name":"Agentic Workflows"}}} # This file was automatically generated by gh-aw (v1.4.0). DO NOT EDIT. To debug this workflow, load the skill at https://github.com/github/gh-aw/blob/main/debug.md # @@ -34,6 +34,7 @@ # Frontmatter env variables: # - NPM_CONFIG_MIN_RELEASE_AGE: (main workflow) # - NPM_CONFIG_REGISTRY: (main workflow) +# - RIG_WORKFLOW_SOURCE_TOOL: (main workflow) # # Secrets used: # - GH_AW_DEFAULT_OTLP_ENDPOINT @@ -83,6 +84,7 @@ run-name: "Monthly PR Clusters" env: NPM_CONFIG_MIN_RELEASE_AGE: "3" NPM_CONFIG_REGISTRY: https://packagefeedproxy.microsoft.io/npm/ + RIG_WORKFLOW_SOURCE_TOOL: "1" OTEL_EXPORTER_OTLP_ENDPOINT: ${{ secrets.GH_AW_DEFAULT_OTLP_ENDPOINT || vars.GH_AW_DEFAULT_OTLP_ENDPOINT }} OTEL_EXPORTER_OTLP_PROTOCOL: ${{ vars.OTEL_EXPORTER_OTLP_PROTOCOL }} GH_AW_OTEL_METRICS: ${{ vars.GH_AW_OTEL_METRICS || 'true' }} @@ -367,6 +369,7 @@ jobs: OTEL_EXPORTER_OTLP_PROTOCOL: "" OTEL_RESOURCE_ATTRIBUTES: "" OTEL_SERVICE_NAME: "" + RIG_WORKFLOW_SOURCE_TOOL: "" - name: Interpolate variables and render templates uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 with: @@ -409,6 +412,7 @@ jobs: OTEL_EXPORTER_OTLP_PROTOCOL: "" OTEL_RESOURCE_ATTRIBUTES: "" OTEL_SERVICE_NAME: "" + RIG_WORKFLOW_SOURCE_TOOL: "" - name: Substitute placeholders uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 with: @@ -464,6 +468,7 @@ jobs: OTEL_EXPORTER_OTLP_PROTOCOL: "" OTEL_RESOURCE_ATTRIBUTES: "" OTEL_SERVICE_NAME: "" + RIG_WORKFLOW_SOURCE_TOOL: "" - name: Validate prompt placeholders run: | bash "${RUNNER_TEMP}/gh-aw/actions/validate_prompt_placeholders.sh" @@ -481,6 +486,7 @@ jobs: OTEL_EXPORTER_OTLP_PROTOCOL: "" OTEL_RESOURCE_ATTRIBUTES: "" OTEL_SERVICE_NAME: "" + RIG_WORKFLOW_SOURCE_TOOL: "" - name: Print prompt run: | bash "${RUNNER_TEMP}/gh-aw/actions/print_prompt_summary.sh" @@ -498,6 +504,7 @@ jobs: OTEL_EXPORTER_OTLP_PROTOCOL: "" OTEL_RESOURCE_ATTRIBUTES: "" OTEL_SERVICE_NAME: "" + RIG_WORKFLOW_SOURCE_TOOL: "" - name: Inventory installed skills if: success() || failure() uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 diff --git a/.github/workflows/monthly-pr-clusters.md b/.github/workflows/monthly-pr-clusters.md index e35c983..9cb12e9 100644 --- a/.github/workflows/monthly-pr-clusters.md +++ b/.github/workflows/monthly-pr-clusters.md @@ -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 @@ -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 diff --git a/skills/rig/harness-tools.md b/skills/rig/harness-tools.md index d14499a..83a8a0d 100644 --- a/skills/rig/harness-tools.md +++ b/skills/rig/harness-tools.md @@ -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, diff --git a/skills/rig/launch-tool.ts b/skills/rig/launch-tool.ts index 29490fe..fac12bd 100644 --- a/skills/rig/launch-tool.ts +++ b/skills/rig/launch-tool.ts @@ -8,6 +8,7 @@ export type RigLaunchToolOptions = { cwd: string; launcherPath?: string; timeoutMs?: number; + includeStderr?: boolean; }; export function createRigLaunchTool(options: RigLaunchToolOptions): Tool<{ source: string }> & { @@ -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"); } @@ -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)); } }); }); diff --git a/src/launch-tool.test.ts b/src/launch-tool.test.ts index f6e756a..f2d1048 100644 --- a/src/launch-tool.test.ts +++ b/src/launch-tool.test.ts @@ -9,7 +9,7 @@ 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"); @@ -17,6 +17,7 @@ async function fixture(source: string, timeoutMs?: number) { return createRigLaunchTool({ uri: "http://localhost:4242", connectionToken: "pipe-test-token", cwd, launcherPath, ...(timeoutMs !== undefined ? { timeoutMs } : {}), + ...(includeStderr && { includeStderr }), }); } @@ -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", + }); +}); diff --git a/src/monthly-pr-clusters-workflow.test.ts b/src/monthly-pr-clusters-workflow.test.ts index 58802b0..eca5d0a 100644 --- a/src/monthly-pr-clusters-workflow.test.ts +++ b/src/monthly-pr-clusters-workflow.test.ts @@ -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", () => { diff --git a/src/rig-skill-workflow.test.ts b/src/rig-skill-workflow.test.ts index f845692..2c8c17e 100644 --- a/src/rig-skill-workflow.test.ts +++ b/src/rig-skill-workflow.test.ts @@ -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"); @@ -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 | && ; < >'])(