MCPcopy Create free account
hub / github.com/Noumena-Network/code / setup

Function setup

src/setup.ts:58–481  ·  view source on GitHub ↗
(
  cwd: string,
  permissionMode: PermissionMode,
  allowDangerouslySkipPermissions: boolean,
  worktreeEnabled: boolean,
  worktreeName: string | undefined,
  tmuxEnabled: boolean,
  customSessionId?: string | null,
  worktreePRNumber?: number,
  messagingSocketPath?: string,
)

Source from the content-addressed store, hash-verified

56} from './utils/worktree.js'
57
58export async function setup(
59 cwd: string,
60 permissionMode: PermissionMode,
61 allowDangerouslySkipPermissions: boolean,
62 worktreeEnabled: boolean,
63 worktreeName: string | undefined,
64 tmuxEnabled: boolean,
65 customSessionId?: string | null,
66 worktreePRNumber?: number,
67 messagingSocketPath?: string,
68): Promise<void> {
69 logForDiagnosticsNoPII('info', 'setup_started')
70
71 // Check for Node.js version < 18
72 const nodeVersion = process.version.match(/^v(\d+)\./)?.[1]
73 if (!nodeVersion || parseInt(nodeVersion) < 18) {
74 // biome-ignore lint/suspicious/noConsole:: intentional console output
75 console.error(
76 chalk.bold.red(
77 'Error: Code requires Node.js version 18 or higher.',
78 ),
79 )
80 process.exit(1)
81 }
82
83 // Set custom session ID if provided
84 if (customSessionId) {
85 switchSession(asSessionId(customSessionId))
86 }
87
88 // --bare / SIMPLE: skip UDS messaging server and teammate snapshot.
89 // Scripted calls don't receive injected messages and don't use swarm teammates.
90 // Explicit --messaging-socket-path is the escape hatch (per #23222 gate pattern).
91 if (!isBareMode() || messagingSocketPath !== undefined) {
92 // Start UDS messaging server (Mac/Linux only).
93 // Enabled by default for ants — creates a socket in tmpdir if no
94 // --messaging-socket-path is passed. Awaited so the server is bound
95 // and $CLAUDE_CODE_MESSAGING_SOCKET is exported before any hook
96 // (SessionStart in particular) can spawn and snapshot process.env.
97 if (feature('UDS_INBOX')) {
98 const m = await import('./utils/udsMessaging.js')
99 await m.startUdsMessaging(
100 messagingSocketPath ?? m.getDefaultUdsSocketPath(),
101 { isExplicit: messagingSocketPath !== undefined },
102 )
103 }
104 }
105
106 // Teammate snapshot — SIMPLE-only gate (no escape hatch, swarm not used in bare)
107 if (!isBareMode() && isAgentSwarmsEnabled()) {
108 const { captureTeammateModeSnapshot } = await import(
109 './utils/swarm/backends/teammateModeSnapshot.js'
110 )
111 captureTeammateModeSnapshot()
112 }
113
114 // Terminal backup restoration — interactive only. Print mode doesn't
115 // interact with terminal settings; the next interactive session will

Callers 5

runFunction · 0.70
installHandlerFunction · 0.50
mcpServeHandlerFunction · 0.50
mainFunction · 0.50
mainFunction · 0.50

Calls 15

isEnvTruthyFunction · 0.90
logForDiagnosticsNoPIIFunction · 0.85
switchSessionFunction · 0.85
asSessionIdFunction · 0.85
isBareModeFunction · 0.85
isAgentSwarmsEnabledFunction · 0.85

Tested by

no test coverage detected