MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / makeOpenCodeHome

Function makeOpenCodeHome

e2e/src/clients/opencode.ts:34–103  ·  view source on GitHub ↗
(
  serverName: string,
  mcpUrl: string,
  options?: { readonly chatBrainUrl?: string },
)

Source from the content-addressed store, hash-verified

32 * scripted conversation. Tool permissions are pre-allowed so the recorded
33 * TUI session flows without approval dialogs. */
34export const makeOpenCodeHome = (
35 serverName: string,
36 mcpUrl: string,
37 options?: { readonly chatBrainUrl?: string },
38): OpenCodeHome => {
39 const root = mkdtempSync(join(tmpdir(), "e2e-opencode-"));
40 const projectDir = join(root, "project");
41 const dataDir = join(root, "data");
42 const binDir = join(root, "bin");
43 const openedUrlsFile = join(root, "opened-urls.txt");
44 for (const dir of [projectDir, dataDir, binDir]) mkdirSync(dir, { recursive: true });
45
46 writeFileSync(
47 join(projectDir, "opencode.json"),
48 JSON.stringify({
49 $schema: "https://opencode.ai/config.json",
50 mcp: { [serverName]: { type: "remote", url: mcpUrl } },
51 ...(options?.chatBrainUrl
52 ? {
53 autoupdate: false,
54 share: "disabled",
55 model: "replay/replay-model",
56 permission: { "*": "allow" },
57 provider: {
58 replay: {
59 name: "Replay",
60 npm: "@ai-sdk/openai-compatible",
61 options: { baseURL: options.chatBrainUrl, apiKey: "replay-key" },
62 models: { "replay-model": { name: "Replay Model" } },
63 },
64 },
65 }
66 : {}),
67 }),
68 );
69 // OpenCode launches the OAuth URL via the platform browser opener; the shim
70 // records it instead. macOS uses `open`; Linux uses `xdg-open` (and a few
71 // fallback names), so shim them all to the same recorder — otherwise the URL
72 // is never captured on Linux and consent never completes.
73 for (const opener of ["open", "xdg-open", "www-browser", "x-www-browser"]) {
74 writeFileSync(join(binDir, opener), `#!/bin/sh\necho "$@" >> ${openedUrlsFile}\nexit 0\n`, {
75 mode: 0o755,
76 });
77 }
78
79 return {
80 projectDir,
81 env: {
82 ...process.env,
83 PATH: `${binDir}:${process.env.PATH ?? ""}`,
84 XDG_DATA_HOME: dataDir,
85 XDG_CONFIG_HOME: join(root, "config"),
86 XDG_STATE_HOME: join(root, "state"),
87 XDG_CACHE_HOME: join(root, "cache"),
88 },
89 openedUrls: () =>
90 existsSync(openedUrlsFile)
91 ? readFileSync(openedUrlsFile, "utf8").split("\n").filter(Boolean)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected