MCPcopy Create free account
hub / github.com/github/gh-aw / main

Function main

actions/setup/js/apply_samples.cjs:542–647  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

540}
541
542async function main() {
543 const samples = loadSamples();
544 const workspace = process.env.GITHUB_WORKSPACE || process.cwd();
545 const logPath = process.env.GH_AW_AGENT_STDIO_LOG || "";
546
547 // Pre-stage branches/patches.
548 for (let i = 0; i < samples.length; i++) {
549 const sample = samples[i];
550 if (PATCH_SIDECAR_TOOLS.has(sample.tool)) {
551 await preStagePatch(sample, i, workspace);
552 }
553 }
554
555 if (samples.length === 0) {
556 core.info("apply_samples: nothing to replay; exiting cleanly.");
557 writeSyntheticStdioLog(logPath, 0);
558 return;
559 }
560
561 const serverPath = resolveMcpServerPath();
562 core.info(`apply_samples: spawning MCP server ${serverPath}`);
563 const child = spawn(process.execPath, [serverPath], {
564 stdio: ["pipe", "pipe", "inherit"],
565 env: process.env,
566 });
567
568 const stdoutIter = lineIterator(child.stdout);
569 let nextId = 1;
570 const failures = [];
571
572 try {
573 // Initialize handshake.
574 const initRsp = await sendJsonRpc(
575 child,
576 child.stdin,
577 {
578 jsonrpc: "2.0",
579 id: nextId++,
580 method: "initialize",
581 params: {
582 protocolVersion: "2025-06-18",
583 capabilities: {},
584 clientInfo: { name: "apply_samples", version: "1.0.0" },
585 },
586 },
587 stdoutIter
588 );
589 if (initRsp.error) {
590 throw new Error(`${ERR_API}: MCP initialize failed: ${JSON.stringify(initRsp.error)}`);
591 }
592
593 // Send one tools/call per sample.
594 for (const [i, sample] of samples.entries()) {
595 const callRsp = await sendJsonRpc(
596 child,
597 child.stdin,
598 {
599 jsonrpc: "2.0",

Callers 1

apply_samples.cjsFile · 0.70

Calls 7

loadSamplesFunction · 0.85
preStagePatchFunction · 0.85
writeSyntheticStdioLogFunction · 0.85
resolveMcpServerPathFunction · 0.85
lineIteratorFunction · 0.85
sendJsonRpcFunction · 0.85
sampleResultIsErrorFunction · 0.85

Tested by

no test coverage detected