MCPcopy
hub / github.com/openai/codex-plugin-cc / withAppServer

Function withAppServer

plugins/codex/scripts/lib/codex.mjs:613–642  ·  view source on GitHub ↗
(cwd, fn)

Source from the content-addressed store, hash-verified

611}
612
613async function withAppServer(cwd, fn) {
614 let client = null;
615 try {
616 client = await CodexAppServerClient.connect(cwd);
617 const result = await fn(client);
618 await client.close();
619 return result;
620 } catch (error) {
621 const brokerRequested = client?.transport === "broker" || Boolean(process.env[BROKER_ENDPOINT_ENV]);
622 const shouldRetryDirect =
623 (client?.transport === "broker" && error?.rpcCode === BROKER_BUSY_RPC_CODE) ||
624 (brokerRequested && (error?.code === "ENOENT" || error?.code === "ECONNREFUSED"));
625
626 if (client) {
627 await client.close().catch(() => {});
628 client = null;
629 }
630
631 if (!shouldRetryDirect) {
632 throw error;
633 }
634
635 const directClient = await CodexAppServerClient.connect(cwd, { disableBroker: true });
636 try {
637 return await fn(directClient);
638 } finally {
639 await directClient.close();
640 }
641 }
642}
643
644async function withDirectAppServer(cwd, fn) {
645 const client = await CodexAppServerClient.connect(cwd, { disableBroker: true });

Callers 3

runAppServerReviewFunction · 0.85
runAppServerTurnFunction · 0.85
findLatestTaskThreadFunction · 0.85

Calls 2

connectMethod · 0.80
closeMethod · 0.45

Tested by

no test coverage detected