MCPcopy Index your code
hub / github.com/anomalyco/opencode / runInteractiveRuntime

Function runInteractiveRuntime

packages/opencode/src/cli/cmd/run/runtime.ts:181–731  ·  view source on GitHub ↗
(input: RunRuntimeInput, deps: RunRuntimeDeps = {})

Source from the content-addressed store, hash-verified

179// Files only attach on the first prompt turn -- after that, includeFiles
180// flips to false so subsequent turns don't re-send attachments.
181async function runInteractiveRuntime(input: RunRuntimeInput, deps: RunRuntimeDeps = {}): Promise<void> {
182 const start = performance.now()
183 const log = trace()
184 const tuiConfigTask = resolveRunTuiConfig()
185 const ctx = await input.boot()
186 const modelTask = resolveModelInfo(ctx.sdk, ctx.directory, ctx.model)
187 const sessionTask =
188 ctx.resume === true
189 ? resolveSessionInfo(ctx.sdk, ctx.sessionID, ctx.model)
190 : Promise.resolve({
191 first: true,
192 history: [],
193 variant: undefined,
194 })
195 const savedTask = resolveSavedVariant(ctx.model)
196 const [tuiConfig, session, savedVariant] = await Promise.all([tuiConfigTask, sessionTask, savedTask])
197 const state: RuntimeState = {
198 shown: !session.first,
199 aborting: false,
200 model: ctx.model,
201 providers: [],
202 variants: [],
203 limits: {},
204 activeVariant: resolveVariant(ctx.variant, session.variant, savedVariant, []),
205 sessionID: ctx.sessionID,
206 history: [...session.history],
207 localRows: [],
208 sessionTitle: ctx.sessionTitle,
209 agent: ctx.agent,
210 }
211 const ensureSession = () => {
212 if (!input.resolveSession || state.sessionID) {
213 return Promise.resolve()
214 }
215
216 if (state.session) {
217 return state.session
218 }
219
220 state.session = input.resolveSession(ctx).then((next) => {
221 state.sessionID = next.sessionID
222 state.sessionTitle = next.sessionTitle ?? state.sessionTitle
223 state.agent = next.agent
224 })
225 return state.session
226 }
227
228 const shell = await (deps.createRuntimeLifecycle ?? createRuntimeLifecycle)({
229 directory: ctx.directory,
230 findFiles: (query) =>
231 ctx.sdk.find
232 .files({ query, directory: ctx.directory })
233 .then((x) => x.data ?? [])
234 .catch(() => []),
235 agents: [],
236 resources: [],
237 sessionID: state.sessionID,
238 sessionTitle: state.sessionTitle,

Callers 2

runInteractiveLocalModeFunction · 0.85
runInteractiveModeFunction · 0.85

Calls 15

traceFunction · 0.90
resolveRunTuiConfigFunction · 0.90
resolveModelInfoFunction · 0.90
resolveSessionInfoFunction · 0.90
resolveSavedVariantFunction · 0.90
resolveVariantFunction · 0.90
cycleVariantFunction · 0.90
saveVariantFunction · 0.90
formatModelLabelFunction · 0.90
createRunDemoFunction · 0.90
variantsForFunction · 0.85
hasSessionFunction · 0.85

Tested by

no test coverage detected