@opencode-ai/cli-linux-arm64
Advanced tools
| { | ||
| "version": 3, | ||
| "sources": ["src/commands/handlers/service/get.ts"], | ||
| "sourcesContent": [ | ||
| "import { EOL } from \"os\"\nimport { Effect, Option } from \"effect\"\nimport { Commands } from \"../../commands\"\nimport { Runtime } from \"../../../framework/runtime\"\nimport { ServiceConfig } from \"../../../services/service-config\"\n\nexport default Runtime.handler(\n Commands.commands.service.commands.get,\n Effect.fn(\"cli.service.get\")(function* (input) {\n process.stdout.write((yield* ServiceConfig.get(Option.getOrUndefined(input.key))) + EOL)\n }),\n)\n" | ||
| ], | ||
| "mappings": ";42BAAA,mBAAS,gBAMT,SAAe,SAAQ,aACrB,OAAS,cAAS,aAAQ,cAAS,SACnC,OAAO,QAAG,sBAAiB,OAAE,cAAU,MAAC,OAAO,MAC7C,aAAQ,YAAO,YAAO,WAAO,OAAc,IAAI,EAAO,eAAe,EAAM,GAAG,CAAC,GAAK,CAAG,EACxF,CACH", | ||
| "debugId": "349DC9475FF6B6FD64756E2164756E21", | ||
| "names": [] | ||
| } |
| { | ||
| "version": 3, | ||
| "sources": ["src/commands/handlers/migrate.ts"], | ||
| "sourcesContent": [ | ||
| "import { Effect } from \"effect\"\nimport { Commands } from \"../commands\"\nimport { Runtime } from \"../../framework/runtime\"\n\nexport default Runtime.handler(Commands.commands.migrate, (_input) => Effect.log(\"No migrations to run.\"))\n" | ||
| ], | ||
| "mappings": ";ivBAIA,SAAe,SAAQ,aAAQ,OAAS,cAAS,aAAS,MAAC,SAAW,OAAO,SAAI,4BAAuB,MAAC", | ||
| "debugId": "0D40E749206D7CEC64756E2164756E21", | ||
| "names": [] | ||
| } |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
| { | ||
| "version": 3, | ||
| "sources": ["src/commands/handlers/debug/agents.ts"], | ||
| "sourcesContent": [ | ||
| "import { EOL } from \"os\"\nimport { Effect } from \"effect\"\nimport { OpenCode } from \"@opencode-ai/client\"\nimport { Commands } from \"../../commands\"\nimport { Runtime } from \"../../../framework/runtime\"\nimport { Service } from \"@opencode-ai/client/effect/service\"\nimport { ServiceConfig } from \"../../../services/service-config\"\n\nexport default Runtime.handler(\n Commands.commands.debug.commands.agents,\n Effect.fn(\"cli.debug.agents\")(function* () {\n const options = yield* ServiceConfig.options()\n const found = yield* Service.discover(options)\n const endpoint = found ?? (yield* Service.ensure(options))\n const client = OpenCode.make({ baseUrl: endpoint.url, headers: Service.headers(endpoint) })\n const response = yield* Effect.promise(() => client.agent.list({ location: { directory: process.cwd() } }))\n process.stdout.write(\n JSON.stringify(\n response.data.toSorted((a, b) => a.id.localeCompare(b.id)),\n null,\n 2,\n ) + EOL,\n )\n }),\n)\n" | ||
| ], | ||
| "mappings": ";g6BAAA,mBAAS,gBAQT,SAAe,SAAQ,aACrB,OAAS,cAAS,WAAM,cAAS,YACjC,OAAO,QAAG,uBAAkB,OAAE,cAAU,OAAG,MACzC,SAAM,OAAU,WAAO,OAAc,aAAQ,OAEvC,QADQ,MAAO,EAAQ,SAAS,CAAO,KAClB,MAAO,EAAQ,OAAO,CAAO,GAClD,EAAS,EAAS,KAAK,CAAE,QAAS,EAAS,IAAK,QAAS,EAAQ,QAAQ,CAAQ,CAAE,CAAC,EACpF,EAAW,MAAO,EAAO,QAAQ,IAAM,EAAO,MAAM,KAAK,CAAE,SAAU,CAAE,UAAW,QAAQ,IAAI,CAAE,CAAE,CAAC,CAAC,EAC1G,QAAQ,OAAO,MACb,KAAK,UACH,EAAS,KAAK,SAAS,CAAC,EAAG,IAAM,EAAE,GAAG,cAAc,EAAE,EAAE,CAAC,EACzD,KACA,CACF,EAAI,CACN,EACD,CACH", | ||
| "debugId": "2607D1EC1463628564756E2164756E21", | ||
| "names": [] | ||
| } |
| { | ||
| "version": 3, | ||
| "sources": ["../simulation/src/backend/network.ts", "../simulation/src/backend/openai.ts", "../simulation/src/backend/simulated-provider.ts", "../simulation/src/backend/index.ts"], | ||
| "sourcesContent": [ | ||
| "import { Clock, Effect, Layer, Ref } from \"effect\"\nimport { HttpClient, HttpClientResponse, type HttpMethod } from \"effect/unstable/http\"\nimport { HttpClientError, TransportError } from \"effect/unstable/http/HttpClientError\"\nimport type { HttpClientRequest } from \"effect/unstable/http\"\nimport { SimulationProtocol } from \"../protocol\"\n\n/**\n * Simulated network.\n *\n * Replaces the `HttpClient.HttpClient` platform node in simulation mode. All\n * outbound HTTP resolves against an in-memory route table; unknown\n * destinations fail loudly with a transport error so no simulation run can\n * silently reach the real network. The scripted LLM is one registered route,\n * not a separate mechanism.\n *\n * Each acquired run owns its routes and request log.\n */\n\nexport interface Route {\n /** Return a response effect to claim the request, undefined to pass. */\n readonly match: (\n request: HttpClientRequest.HttpClientRequest,\n url: URL,\n ) => Effect.Effect<HttpClientResponse.HttpClientResponse, HttpClientError> | undefined\n}\n\nexport type LogEntry = SimulationProtocol.Backend.NetworkLogEntry\n\nconst LOG_LIMIT = 1000\n\n/** Static JSON route: exact method + origin/path match answered with a fixed body. */\nexport function json(method: HttpMethod.HttpMethod, url: string, body: unknown): Route {\n return {\n match: (request, requestUrl) => {\n if (request.method !== method) return undefined\n if (requestUrl.origin + requestUrl.pathname !== url) return undefined\n return Effect.sync(() =>\n HttpClientResponse.fromWeb(\n request,\n new Response(JSON.stringify(body), { status: 200, headers: { \"content-type\": \"application/json\" } }),\n ),\n )\n },\n }\n}\n\nexport interface Run {\n readonly client: HttpClient.HttpClient\n readonly log: () => Effect.Effect<readonly LogEntry[]>\n}\n\nexport const make = Effect.fn(\"SimulationNetwork.make\")(function* (routes: readonly Route[] = []) {\n const log = yield* Ref.make<readonly LogEntry[]>([])\n const client = HttpClient.make((request, url) =>\n Effect.gen(function* () {\n let matched: Effect.Effect<HttpClientResponse.HttpClientResponse, HttpClientError> | undefined\n for (const route of routes) {\n matched = route.match(request, url)\n if (matched) break\n }\n const entry = {\n time: yield* Clock.currentTimeMillis,\n method: request.method,\n url: url.toString(),\n matched: matched !== undefined,\n }\n yield* Ref.update(log, (entries) => [...entries, entry].slice(-LOG_LIMIT))\n if (matched) return yield* matched\n return yield* Effect.fail(\n new HttpClientError({\n reason: new TransportError({\n request,\n description: `Simulation denied unregistered network destination: ${request.method} ${url}`,\n }),\n }),\n )\n }),\n )\n return { client, log: () => Ref.get(log) } satisfies Run\n})\n\nexport const layer = (routes: readonly Route[] = []) =>\n Layer.effect(HttpClient.HttpClient, make(routes).pipe(Effect.map((run) => run.client)))\n\nexport * as SimulationNetwork from \"./network\"\n", | ||
| "import { Effect, Schema, Stream } from \"effect\"\nimport { HttpClientResponse } from \"effect/unstable/http\"\nimport { HttpClientError, TransportError } from \"effect/unstable/http/HttpClientError\"\nimport { OpenAIChatEvent, DEFAULT_BASE_URL, PATH } from \"@opencode-ai/ai/protocols/openai-chat\"\nimport { SimulationNetwork } from \"./network\"\nimport { SimulatedProvider } from \"./simulated-provider\"\n\n/**\n * Driver-answered OpenAI endpoint for the simulated network.\n *\n * Claims `POST {DEFAULT_BASE_URL}{PATH}` (the real openai-chat route\n * endpoint), invokes the simulated provider, and streams the driver's events back as\n * an OpenAI Chat SSE response terminated by `[DONE]`. Everything downstream\n * of the response bytes is the real pipeline: SSE framing, the OpenAIChat\n * event schema, the protocol state machine, and Lifecycle grammar.\n */\n\nconst encodeChunk = Schema.encodeUnknownSync(OpenAIChatEvent)\n\nconst encoder = new TextEncoder()\nconst decodeBody = Schema.decodeUnknownEffect(Schema.fromJsonString(Schema.Json))\n\n// The simulated model id is echoed back only in non-schema fields; the\n// protocol event schema ignores unknown fields, so id/object/model are\n// decorative wire realism.\ntype ProviderItem = Exclude<SimulatedProvider.ProviderResponseEvent, { readonly type: \"finish\" }>\ntype FinishReason = Extract<SimulatedProvider.ProviderResponseEvent, { readonly type: \"finish\" }>[\"reason\"]\n\nfunction chunkOf(item: ProviderItem): OpenAIChatEvent | unknown {\n if (item.type === \"textDelta\") return { choices: [{ delta: { content: item.text } }] }\n if (item.type === \"reasoningDelta\") return { choices: [{ delta: { reasoning_content: item.text } }] }\n if (item.type === \"toolCall\")\n return {\n choices: [\n {\n delta: {\n tool_calls: [\n {\n index: item.index,\n id: item.id,\n function: { name: item.name, arguments: JSON.stringify(item.input) },\n },\n ],\n },\n },\n ],\n }\n return item.chunk\n}\n\nconst finishReasonWire: Record<FinishReason, string> = {\n stop: \"stop\",\n \"tool-calls\": \"tool_calls\",\n length: \"length\",\n \"content-filter\": \"content_filter\",\n}\n\nfunction frame(payload: unknown): Uint8Array {\n return encoder.encode(`data: ${JSON.stringify(payload)}\\n\\n`)\n}\n\nfunction sseBody(\n events: Stream.Stream<SimulatedProvider.ProviderResponseEvent, SimulatedProvider.ProviderDisconnectedError>,\n): Stream.Stream<Uint8Array, SimulatedProvider.ProviderDisconnectedError> {\n return events.pipe(\n Stream.map((event) => {\n if (event.type === \"finish\")\n return frame(encodeChunk({ choices: [{ delta: {}, finish_reason: finishReasonWire[event.reason] }] }))\n if (event.type === \"raw\") return frame(event.chunk)\n return frame(encodeChunk(chunkOf(event)))\n }),\n Stream.concat(Stream.make(encoder.encode(\"data: [DONE]\\n\\n\"))),\n )\n}\n\nexport const route = (provider: SimulatedProvider.Interface): SimulationNetwork.Route => ({\n match: (request, url) => {\n if (request.method !== \"POST\") return undefined\n if (url.origin + url.pathname !== DEFAULT_BASE_URL + PATH) return undefined\n return Effect.gen(function* () {\n const body =\n request.body._tag === \"Uint8Array\"\n ? yield* decodeBody(new TextDecoder().decode(request.body.body)).pipe(\n Effect.mapError(\n (cause) =>\n new HttpClientError({\n reason: new TransportError({\n request,\n cause,\n description: \"Simulation received an invalid OpenAI request body\",\n }),\n }),\n ),\n )\n : {}\n return HttpClientResponse.fromWeb(\n request,\n new Response(Stream.toReadableStream(sseBody(provider.stream({ url: url.toString(), body }))), {\n status: 200,\n headers: { \"content-type\": \"text/event-stream\" },\n }),\n )\n })\n },\n})\n\nexport * as SimulationOpenAI from \"./openai\"\n", | ||
| "import { InstallationVersion } from \"@opencode-ai/core/installation/version\"\nimport { Cause, Context, Effect, Fiber, FiberSet, Layer, PubSub, Queue, Ref, Schema, Semaphore, Stream } from \"effect\"\nimport { SimulationControlServer } from \"../control-server\"\nimport { SimulationProtocol } from \"../protocol\"\n\nexport interface ProviderRequest {\n readonly url: string\n readonly body: unknown\n}\n\nexport type ProviderResponseEvent =\n | SimulationProtocol.Backend.Item\n | { readonly type: \"finish\"; readonly reason: SimulationProtocol.Backend.FinishReason }\n\nexport class ProviderDisconnectedError extends Schema.TaggedErrorClass<ProviderDisconnectedError>()(\n \"SimulatedProvider.ProviderDisconnectedError\",\n { message: Schema.String },\n) {}\n\nexport interface Interface {\n readonly stream: (request: ProviderRequest) => Stream.Stream<ProviderResponseEvent, ProviderDisconnectedError>\n}\n\nexport class Service extends Context.Service<Service, Interface>()(\"@opencode/simulation/SimulatedProvider\") {}\n\ninterface ProviderInvocation extends ProviderRequest {\n readonly id: string\n}\n\ninterface PendingInvocation extends ProviderInvocation {\n readonly responses: Queue.Queue<ProviderResponseEvent, ProviderDisconnectedError | Cause.Done>\n}\n\ninterface State {\n readonly counter: number\n readonly pending: ReadonlyMap<string, PendingInvocation>\n}\n\ninterface Driver {\n readonly requests: Stream.Stream<ProviderInvocation>\n readonly push: (\n id: string,\n items: readonly SimulationProtocol.Backend.Item[],\n ) => Effect.Effect<void, InvocationNotFoundError>\n readonly finish: (\n id: string,\n reason: SimulationProtocol.Backend.FinishReason,\n ) => Effect.Effect<void, InvocationNotFoundError>\n readonly disconnect: (id: string) => Effect.Effect<void, InvocationNotFoundError>\n readonly pending: () => Effect.Effect<readonly ProviderInvocation[]>\n}\n\nclass InvocationNotFoundError extends Schema.TaggedErrorClass<InvocationNotFoundError>()(\n \"SimulatedProvider.InvocationNotFoundError\",\n { id: Schema.String, message: Schema.String },\n) {}\n\nclass ControllerDisconnectedError extends Schema.TaggedErrorClass<ControllerDisconnectedError>()(\n \"SimulatedProvider.ControllerDisconnectedError\",\n { message: Schema.String },\n) {}\n\ntype ControlSocket = SimulationControlServer.Socket\n\nexport const layerDrive = (options: { readonly endpoint: string }) =>\n Layer.effect(\n Service,\n Effect.gen(function* () {\n const state = yield* Ref.make<State>({ counter: 0, pending: new Map() })\n const opened = yield* PubSub.unbounded<ProviderInvocation>()\n const lock = yield* Semaphore.make(1)\n\n const close = (invocation: PendingInvocation) =>\n Effect.gen(function* () {\n yield* Queue.shutdown(invocation.responses)\n yield* lock.withPermit(\n Ref.update(state, (current) =>\n current.pending.get(invocation.id) === invocation ? remove(current, invocation.id) : current,\n ),\n )\n })\n\n yield* Effect.addFinalizer(() =>\n Effect.gen(function* () {\n const current = yield* Ref.get(state)\n yield* Effect.forEach(current.pending.values(), (invocation) => Queue.shutdown(invocation.responses), {\n discard: true,\n })\n yield* PubSub.shutdown(opened)\n }),\n )\n\n const open = (request: ProviderRequest) =>\n lock.withPermit(\n Effect.gen(function* () {\n const current = yield* Ref.get(state)\n const id = `inv_${current.counter + 1}`\n const responses = yield* Queue.bounded<ProviderResponseEvent, ProviderDisconnectedError | Cause.Done>(256)\n const invocation: PendingInvocation = { id, ...request, responses }\n yield* Ref.set(state, {\n counter: current.counter + 1,\n pending: new Map(current.pending).set(id, invocation),\n })\n yield* PubSub.publish(opened, { id, ...request })\n return invocation\n }),\n )\n\n const requireInvocation = (id: string) =>\n Effect.gen(function* () {\n const current = yield* Ref.get(state)\n const invocation = current.pending.get(id)\n if (invocation) return invocation\n return yield* Effect.fail(\n new InvocationNotFoundError({\n id,\n message: `Simulated provider invocation not found or already finished: ${id}`,\n }),\n )\n })\n\n const remove = (current: State, id: string) => {\n const pending = new Map(current.pending)\n pending.delete(id)\n return { ...current, pending }\n }\n\n const driver: Driver = {\n requests: Stream.unwrap(\n lock.withPermit(\n Effect.gen(function* () {\n const subscription = yield* PubSub.subscribe(opened)\n const current = yield* Ref.get(state)\n const pending = Array.from(current.pending.values(), ({ id, url, body }) => ({ id, url, body }))\n return Stream.concat(Stream.fromIterable(pending), Stream.fromEffectRepeat(PubSub.take(subscription)))\n }),\n ),\n ),\n push: (id, items) =>\n Effect.gen(function* () {\n const invocation = yield* lock.withPermit(requireInvocation(id))\n yield* Queue.offerAll(invocation.responses, items)\n }),\n finish: (id, reason) =>\n Effect.gen(function* () {\n const invocation = yield* lock.withPermit(\n Effect.gen(function* () {\n const invocation = yield* requireInvocation(id)\n const current = yield* Ref.get(state)\n yield* Ref.set(state, remove(current, id))\n return invocation\n }),\n )\n yield* Queue.offer(invocation.responses, { type: \"finish\", reason })\n yield* Queue.end(invocation.responses)\n }),\n disconnect: (id) =>\n Effect.gen(function* () {\n const invocation = yield* lock.withPermit(\n Effect.gen(function* () {\n const invocation = yield* requireInvocation(id)\n const current = yield* Ref.get(state)\n yield* Ref.set(state, remove(current, id))\n return invocation\n }),\n )\n yield* Queue.fail(\n invocation.responses,\n new ProviderDisconnectedError({ message: \"Simulated model provider disconnected\" }),\n )\n }),\n pending: () =>\n lock.withPermit(\n Ref.get(state).pipe(\n Effect.map((current) => Array.from(current.pending.values(), ({ id, url, body }) => ({ id, url, body }))),\n ),\n ),\n }\n\n const fibers = yield* FiberSet.make<void, unknown>()\n const activeController = yield* Ref.make<Fiber.Fiber<void> | undefined>(undefined)\n const controllerLock = yield* Semaphore.make(1)\n yield* SimulationControlServer.start({\n endpoint: options.endpoint,\n label: \"opencode drive backend websocket\",\n data: () => ({}),\n decode: SimulationProtocol.Backend.decodeRequestEffect,\n handle: (socket, request) => handle(driver, fibers, activeController, controllerLock, socket, request),\n close: (socket) => releaseController(activeController, controllerLock, socket),\n })\n yield* Effect.sync(() => process.stderr.write(`opencode drive backend websocket: ${options.endpoint}\\n`))\n\n return Service.of({\n stream: (request) =>\n Stream.unwrap(\n Effect.acquireRelease(open(request), close).pipe(\n Effect.map((invocation) =>\n Stream.fromQueue(invocation.responses).pipe(Stream.takeUntil((event) => event.type === \"finish\")),\n ),\n ),\n ),\n })\n }),\n )\n\nfunction handle(\n driver: Driver,\n fibers: FiberSet.FiberSet<void, unknown>,\n activeController: Ref.Ref<Fiber.Fiber<void> | undefined>,\n controllerLock: Semaphore.Semaphore,\n socket: ControlSocket,\n request: SimulationProtocol.Backend.Request,\n) {\n switch (request.method) {\n case \"simulation.handshake\":\n return SimulationProtocol.Handshake.dispatch(\n {\n role: \"backend\",\n server: { name: \"opencode\", version: InstallationVersion },\n capabilities: SimulationProtocol.Backend.Capabilities,\n },\n request.params,\n )\n case \"llm.attach\":\n return controllerLock.withPermit(\n Effect.gen(function* () {\n if (socket.data.closed)\n return yield* Effect.fail(\n new ControllerDisconnectedError({ message: \"Drive controller disconnected before attachment\" }),\n )\n const previous = yield* Ref.get(activeController)\n if (previous) yield* Fiber.interrupt(previous)\n const attachment = yield* FiberSet.run(\n fibers,\n driver.requests.pipe(\n Stream.runForEach((invocation) =>\n Effect.sync(() => {\n socket.send(JSON.stringify({ jsonrpc: \"2.0\", method: \"llm.request\", params: invocation }))\n }),\n ),\n ),\n )\n if (socket.data.closed) {\n yield* Fiber.interrupt(attachment)\n return yield* Effect.fail(\n new ControllerDisconnectedError({ message: \"Drive controller disconnected during attachment\" }),\n )\n }\n socket.data.attachment = attachment\n yield* Ref.set(activeController, attachment)\n return { attached: true }\n }),\n )\n case \"llm.chunk\":\n return driver.push(request.params.id, request.params.items).pipe(Effect.as({ ok: true }))\n case \"llm.finish\":\n return driver.finish(request.params.id, request.params.reason).pipe(Effect.as({ ok: true }))\n case \"llm.disconnect\":\n return driver.disconnect(request.params.id).pipe(Effect.as({ ok: true }))\n case \"llm.pending\":\n return driver.pending().pipe(Effect.map((invocations) => ({ invocations })))\n }\n}\n\nfunction releaseController(\n activeController: Ref.Ref<Fiber.Fiber<void> | undefined>,\n controllerLock: Semaphore.Semaphore,\n socket: ControlSocket,\n) {\n return controllerLock.withPermit(\n Effect.gen(function* () {\n const attachment = socket.data.attachment\n if (!attachment) return\n yield* Fiber.interrupt(attachment)\n yield* Ref.update(activeController, (active) => (active === attachment ? undefined : active))\n }),\n )\n}\n\nexport * as SimulatedProvider from \"./simulated-provider\"\n", | ||
| "import { LayerNode } from \"@opencode-ai/core/effect/layer-node\"\nimport { httpClient } from \"@opencode-ai/core/effect/app-node-platform\"\nimport { Config, Effect, Layer } from \"effect\"\nimport { HttpClient } from \"effect/unstable/http\"\nimport { DriveManifest } from \"../manifest\"\nimport { SimulationNetwork } from \"./network\"\nimport { SimulationOpenAI } from \"./openai\"\nimport { SimulatedProvider } from \"./simulated-provider\"\n\n/**\n * Layer replacements applied when the server is built in simulation mode.\n *\n * The server merges these into the app node build when `OPENCODE_SIMULATE`\n * is enabled, via a dynamic import so this module is never loaded eagerly.\n *\n * - Network: all outbound HTTP resolves against the simulated route table;\n * unknown destinations are denied. The driver-answered OpenAI endpoint is\n * registered here as the first route.\n *\n */\n\nexport const simulationReplacements = Effect.fn(\"Simulation.replacements\")(function* () {\n // ModelsDev dies when its catalog fetch fails, so simulation answers it with\n // an empty catalog; providers come from seeded config instead.\n const models = SimulationNetwork.json(\"GET\", \"https://models.dev/api.json\", {})\n const drive = yield* Config.string(\"OPENCODE_DRIVE\").pipe(Config.withDefault(undefined))\n if (!drive) return [[httpClient, SimulationNetwork.layer([models])]] satisfies LayerNode.Replacements\n\n const manifest = yield* DriveManifest.resolve()\n const networkLayer = Layer.effect(\n HttpClient.HttpClient,\n Effect.gen(function* () {\n const provider = yield* SimulatedProvider.Service\n const network = yield* SimulationNetwork.make([SimulationOpenAI.route(provider), models])\n return network.client\n }),\n ).pipe(\n Layer.provide(\n SimulatedProvider.layerDrive({\n endpoint: manifest.endpoints.backend,\n }),\n ),\n )\n return [[httpClient, networkLayer]] satisfies LayerNode.Replacements\n})\n\nexport * as Simulation from \"./index\"\n" | ||
| ], | ||
| "mappings": ";svBA4BA,SAAM,QAAY,UAGX,cAAS,OAAI,MAAC,OAA+B,OAAa,OAAsB,MACrF,MAAO,CACL,MAAO,CAAC,EAAS,IAAe,CAC9B,GAAI,EAAQ,SAAW,EAAQ,OAC/B,GAAI,EAAW,OAAS,EAAW,WAAa,EAAK,OACrD,OAAO,EAAO,KAAK,IACjB,EAA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C,CAAC,EAEnE,IAAM,EAAW,MAAO,EAAc,QAAQ,EACxC,EAAe,EAAM,OACzB,EAAW,WACX,EAAO,IAAI,SAAU,EAAG,CACtB,IAAM,EAAW,MAAO,EAAkB,QAE1C,OADgB,MAAO,EAAkB,KAAK,CAAC,EAAiB,MAAM,CAAQ,EAAG,CAAM,CAAC,GACzE,OAChB,CACH,EAAE,KACA,EAAM,QACJ,EAAkB,WAAW,CAC3B,SAAU,EAAS,UAAU,OAC/B,CAAC,CACH,CACF,EACA,MAAO,CAAC,CAAC,EAAY,CAAY,CAAC,EACnC", | ||
| "debugId": "1408EFA899E4F7BD64756E2164756E21", | ||
| "names": [] | ||
| } |
| { | ||
| "version": 3, | ||
| "sources": ["src/commands/handlers/service/start.ts"], | ||
| "sourcesContent": [ | ||
| "import { EOL } from \"os\"\nimport { Effect } from \"effect\"\nimport { Service } from \"@opencode-ai/client/effect/service\"\nimport { Commands } from \"../../commands\"\nimport { Runtime } from \"../../../framework/runtime\"\nimport { ServiceConfig } from \"../../../services/service-config\"\n\nexport default Runtime.handler(\n Commands.commands.service.commands.start,\n Effect.fn(\"cli.service.start\")(function* () {\n const transport = yield* Service.ensure(yield* ServiceConfig.options())\n process.stdout.write(transport.url + EOL)\n }),\n)\n" | ||
| ], | ||
| "mappings": ";i3BAAA,mBAAS,gBAOT,SAAe,SAAQ,aACrB,OAAS,cAAS,aAAQ,cAAS,WACnC,OAAO,QAAG,wBAAmB,OAAE,cAAU,OAAG,MAC1C,SAAM,OAAY,WAAO,OAAQ,YAAO,WAAO,EAAc,QAAQ,CAAC,EACtE,QAAQ,OAAO,MAAM,EAAU,IAAM,CAAG,EACzC,CACH", | ||
| "debugId": "E5A7E2C66193AA8164756E2164756E21", | ||
| "names": [] | ||
| } |
| { | ||
| "version": 3, | ||
| "sources": ["src/commands/handlers/service/restart.ts"], | ||
| "sourcesContent": [ | ||
| "import { EOL } from \"os\"\nimport { Effect } from \"effect\"\nimport { Service } from \"@opencode-ai/client/effect/service\"\nimport { Commands } from \"../../commands\"\nimport { Runtime } from \"../../../framework/runtime\"\nimport { ServiceConfig } from \"../../../services/service-config\"\n\nexport default Runtime.handler(\n Commands.commands.service.commands.restart,\n Effect.fn(\"cli.service.restart\")(function* () {\n const options = yield* ServiceConfig.options()\n yield* Service.stop(options)\n const transport = yield* Service.ensure(options)\n process.stdout.write(transport.url + EOL)\n }),\n)\n" | ||
| ], | ||
| "mappings": ";i3BAAA,mBAAS,gBAOT,SAAe,SAAQ,aACrB,OAAS,cAAS,aAAQ,cAAS,aACnC,OAAO,QAAG,0BAAqB,OAAE,cAAU,OAAG,MAC5C,SAAM,OAAU,WAAO,OAAc,aAAQ,OAC7C,MAAO,EAAQ,KAAK,CAAO,EAC3B,IAAM,EAAY,MAAO,EAAQ,OAAO,CAAO,EAC/C,QAAQ,OAAO,MAAM,EAAU,IAAM,CAAG,EACzC,CACH", | ||
| "debugId": "30B9E9BFE75657A464756E2164756E21", | ||
| "names": [] | ||
| } |
| { | ||
| "version": 3, | ||
| "sources": ["../core/src/util/process-lock.ts", "src/server-process.ts", "src/commands/handlers/serve.ts"], | ||
| "sourcesContent": [ | ||
| "import { dlopen, read, type Pointer } from \"bun:ffi\"\nimport { closeSync, existsSync, mkdirSync, openSync } from \"node:fs\"\nimport { connect, createServer, type Server, type Socket } from \"node:net\"\nimport path from \"node:path\"\nimport { Effect, Schema } from \"effect\"\nimport { Hash } from \"./hash\"\n\nexport namespace ProcessLock {\n export class HeldError extends Schema.TaggedErrorClass<HeldError>()(\"ProcessLockHeldError\", {\n file: Schema.String,\n }) {\n override get message() {\n return `Process lock is already held: ${this.file}`\n }\n }\n\n export class SystemError extends Schema.TaggedErrorClass<SystemError>()(\"ProcessLockSystemError\", {\n file: Schema.String,\n operation: Schema.Literals([\"open\", \"acquire\"]),\n code: Schema.String,\n }) {\n override get message() {\n return `Process lock ${this.operation} failed for ${this.file}: ${this.code}`\n }\n }\n\n export type LockError = HeldError | SystemError\n\n const acquirePosix = Effect.fnUntraced(function* (file: string) {\n const fd = yield* Effect.try({\n try: () => {\n mkdirSync(path.dirname(file), { recursive: true })\n return openSync(file, \"a+\", 0o600)\n },\n catch: (cause) =>\n new SystemError({\n file,\n operation: \"open\",\n code: cause instanceof Error ? cause.message : String(cause),\n }),\n })\n const result = yield* Effect.try({\n try: () => lock(fd),\n catch: (cause) =>\n new SystemError({\n file,\n operation: \"acquire\",\n code: cause instanceof Error ? cause.message : String(cause),\n }),\n }).pipe(\n Effect.tapError(() =>\n Effect.sync(() => {\n closeSync(fd)\n }),\n ),\n )\n if (result.acquired) {\n return fd\n }\n closeSync(fd)\n return yield* result.held\n ? new HeldError({ file })\n : new SystemError({ file, operation: \"acquire\", code: String(result.code) })\n })\n\n export const acquire = Effect.fn(\"ProcessLock.acquire\")(function* (file: string) {\n if (process.platform === \"win32\") {\n yield* Effect.acquireRelease(acquireWindows(file), closeWindows)\n return\n }\n yield* Effect.acquireRelease(acquirePosix(file), (fd) =>\n Effect.sync(() => {\n closeSync(fd)\n }),\n )\n })\n}\n\ntype Result =\n | { readonly acquired: true }\n | { readonly acquired: false; readonly held: true }\n | { readonly acquired: false; readonly held: false; readonly code: number }\n\nconst LOCK_EX = 2\nconst LOCK_NB = 4\nconst DARWIN_EWOULDBLOCK = 35\nconst LINUX_EWOULDBLOCK = 11\n\nfunction lock(fd: number): Result {\n if (process.platform === \"darwin\") return lockDarwin(fd)\n if (process.platform === \"linux\") return lockLinux(fd)\n throw new Error(`Unsupported process lock platform: ${process.platform}`)\n}\n\nfunction lockDarwin(fd: number): Result {\n const library = dlopen(\"/usr/lib/libSystem.B.dylib\", {\n flock: { args: [\"i32\", \"i32\"], returns: \"i32\" },\n __error: { args: [], returns: \"ptr\" },\n })\n try {\n const result = library.symbols.flock(fd, LOCK_EX | LOCK_NB)\n const code = result === 0 ? 0 : errorCode(library.symbols.__error())\n if (result === 0) return { acquired: true }\n if (code === DARWIN_EWOULDBLOCK) return { acquired: false, held: true }\n return { acquired: false, held: false, code }\n } finally {\n library.close()\n }\n}\n\nfunction lockLinux(fd: number): Result {\n const musl = `/lib/libc.musl-${process.arch === \"arm64\" ? \"aarch64\" : \"x86_64\"}.so.1`\n const library = dlopen(existsSync(musl) ? musl : \"libc.so.6\", {\n flock: { args: [\"i32\", \"i32\"], returns: \"i32\" },\n __errno_location: { args: [], returns: \"ptr\" },\n })\n try {\n const result = library.symbols.flock(fd, LOCK_EX | LOCK_NB)\n const code = result === 0 ? 0 : errorCode(library.symbols.__errno_location())\n if (result === 0) return { acquired: true }\n if (code === LINUX_EWOULDBLOCK) return { acquired: false, held: true }\n return { acquired: false, held: false, code }\n } finally {\n library.close()\n }\n}\n\nfunction errorCode(pointer: Pointer | null) {\n if (pointer === null) throw new Error(\"Failed to read process lock error code\")\n return read.i32(pointer, 0)\n}\n\nfunction acquireWindows(file: string) {\n return Effect.callback<Server, ProcessLock.LockError>((resume) => {\n const server = createServer()\n let probe: Socket | undefined\n const pipe = `\\\\\\\\.\\\\pipe\\\\opencode-process-lock-${Hash.sha256(path.resolve(file).toLowerCase())}`\n const onError = (cause: NodeJS.ErrnoException) => {\n server.off(\"listening\", onListening)\n probe = connect(pipe)\n const onProbeError = () => {\n probe?.off(\"connect\", onConnect)\n resume(\n Effect.fail(\n new ProcessLock.SystemError({\n file,\n operation: \"acquire\",\n code: cause.code ?? cause.message,\n }),\n ),\n )\n }\n const onConnect = () => {\n probe?.off(\"error\", onProbeError)\n probe?.destroy()\n resume(Effect.fail(new ProcessLock.HeldError({ file })))\n }\n probe.once(\"connect\", onConnect)\n probe.once(\"error\", onProbeError)\n }\n const onListening = () => {\n server.off(\"error\", onError)\n resume(Effect.succeed(server))\n }\n server.once(\"error\", onError)\n server.once(\"listening\", onListening)\n server.on(\"connection\", (socket) => socket.destroy())\n server.listen(pipe)\n return Effect.sync(() => {\n probe?.destroy()\n server.close()\n })\n })\n}\n\nfunction closeWindows(server: Server) {\n return Effect.callback<void>((resume) => {\n if (!server.listening) return resume(Effect.void)\n server.close((error) => resume(error ? Effect.die(error) : Effect.void))\n })\n}\n", | ||
| "export * as ServerProcess from \"./server-process\"\n\nimport { NodeServices } from \"@effect/platform-node\"\nimport { Service } from \"@opencode-ai/client/effect/service\"\nimport { AppNodeBuilder } from \"@opencode-ai/core/effect/app-node-builder\"\nimport { LayerNode } from \"@opencode-ai/core/effect/layer-node\"\nimport { Global } from \"@opencode-ai/core/global\"\nimport { InstallationVersion } from \"@opencode-ai/core/installation/version\"\nimport { AppProcess } from \"@opencode-ai/core/process\"\nimport { ProcessLock } from \"@opencode-ai/core/util/process-lock\"\nimport { randomBytes, randomUUID } from \"node:crypto\"\nimport path from \"node:path\"\nimport { Effect, FileSystem, Logger, Option, Redacted, Schedule, Schema } from \"effect\"\nimport { HttpServer } from \"effect/unstable/http\"\nimport { Env } from \"./env\"\nimport { ServiceConfig } from \"./services/service-config\"\nimport { Updater } from \"./services/updater\"\n\nexport type Mode = \"default\" | \"service\" | \"stdio\"\n\nexport type Options = {\n readonly mode: Mode\n readonly hostname?: string\n readonly port?: number\n}\n\nexport const run = Effect.fn(\"cli.server-process.run\")((options: Options) =>\n processEffect(options).pipe(\n Effect.provide(Updater.layer),\n Effect.provide(AppNodeBuilder.build(LayerNode.group([Global.node, AppProcess.node]))),\n Effect.provide(NodeServices.layer),\n ),\n)\n\nconst processEffect = Effect.fnUntraced(function* (options: Options) {\n if (options.mode === \"service\") yield* Effect.sync(() => process.chdir(Global.Path.home))\n return yield* Effect.scoped(\n Effect.gen(function* () {\n const serviceOptions = options.mode === \"service\" ? yield* ServiceConfig.options() : undefined\n if (serviceOptions !== undefined) {\n const acquired = yield* ProcessLock.acquire(serviceOptions.file + \".lock\").pipe(\n Effect.as(true),\n Effect.catchTag(\"ProcessLockHeldError\", () => Effect.succeed(false)),\n )\n if (!acquired) return yield* Effect.void\n if ((yield* Service.discover(serviceOptions)) !== undefined) return yield* Effect.void\n }\n const { start } = yield* Effect.promise(() => import(\"@opencode-ai/server/process\"))\n const environmentPassword = yield* Env.password\n // Keep the lease credential out of the environment inherited by tools.\n if (options.mode === \"stdio\") {\n delete process.env.OPENCODE_PASSWORD\n delete process.env.OPENCODE_SERVER_PASSWORD\n }\n const config = options.mode === \"service\" ? yield* ServiceConfig.read() : {}\n const password =\n options.mode === \"service\"\n ? yield* ServiceConfig.password()\n : environmentPassword\n ? Redacted.value(environmentPassword)\n : randomBytes(32).toString(\"base64url\")\n if (!password) return yield* Effect.fail(new Error(\"Missing server password\"))\n const instanceID = randomUUID()\n const server = yield* start({\n hostname: options.hostname ?? config.hostname ?? \"127.0.0.1\",\n port: Option.fromNullishOr(options.port ?? config.port),\n password,\n instanceID,\n service:\n serviceOptions === undefined\n ? undefined\n : { onListen: (address) => register(address, password, instanceID, serviceOptions.file) },\n }).pipe(Effect.provide(Logger.layer([], { mergeWithExisting: false })))\n const url = HttpServer.formatAddress(server.address)\n console.log(options.mode === \"stdio\" ? JSON.stringify({ url }) : `server listening on ${url}`)\n if (options.mode === \"default\" && !environmentPassword) console.log(`server password ${password}`)\n const updater = yield* Updater.Service\n yield* updater.check().pipe(Effect.schedule(Schedule.spaced(\"10 minutes\")), Effect.forkScoped)\n return yield* options.mode === \"service\"\n ? server.shutdown\n : options.mode === \"stdio\"\n ? waitForStdinClose()\n : Effect.never\n }).pipe(Effect.annotateLogs({ role: \"server\" })),\n )\n})\n\nconst infoJson = Schema.fromJsonString(Service.Info)\nconst encodeInfo = Schema.encodeEffect(infoJson)\nconst decodeInfo = Schema.decodeUnknownEffect(infoJson)\n\nconst register = Effect.fnUntraced(function* (\n address: HttpServer.Address,\n password: string,\n id: string,\n file: string,\n) {\n const fs = yield* FileSystem.FileSystem\n const temp = file + \".\" + id + \".tmp\"\n yield* fs.makeDirectory(path.dirname(file), { recursive: true })\n const info = {\n id,\n version: InstallationVersion,\n url: HttpServer.formatAddress(address),\n pid: process.pid,\n password,\n }\n const encoded = yield* encodeInfo(info)\n const publish = fs.writeFileString(temp, encoded, { mode: 0o600 }).pipe(Effect.andThen(fs.rename(temp, file)))\n yield* publish\n const current = fs.readFileString(file).pipe(\n Effect.flatMap(decodeInfo),\n Effect.orElseSucceed(() => undefined),\n )\n const assertRegistration = Effect.gen(function* () {\n const found = yield* current\n if (\n found !== undefined &&\n found.id === info.id &&\n found.version === info.version &&\n found.url === info.url &&\n found.pid === info.pid &&\n found.password === info.password\n )\n return\n yield* publish\n })\n yield* Effect.addFinalizer(() =>\n current.pipe(\n Effect.flatMap((current) => (current?.id === id ? fs.remove(file) : Effect.void)),\n Effect.ignore,\n ),\n )\n yield* assertRegistration.pipe(\n Effect.catchCause((cause) => Effect.logWarning(\"failed to reassert service registration\", { cause })),\n Effect.repeat(Schedule.spaced(\"5 seconds\")),\n Effect.forkScoped,\n )\n})\n\nfunction waitForStdinClose() {\n return Effect.callback<void>((resume) => {\n const close = () => resume(Effect.void)\n process.stdin.once(\"end\", close)\n process.stdin.once(\"close\", close)\n process.stdin.resume()\n if (process.stdin.readableEnded || process.stdin.destroyed) close()\n return Effect.sync(() => {\n process.stdin.off(\"end\", close)\n process.stdin.off(\"close\", close)\n process.stdin.pause()\n })\n })\n}\n", | ||
| "import { Effect, Option } from \"effect\"\nimport { Commands } from \"../commands\"\nimport { Runtime } from \"../../framework/runtime\"\nimport { ServerProcess } from \"../../server-process\"\n\nexport default Runtime.handler(\n Commands.commands.serve,\n Effect.fn(\"cli.serve\")(function* (input) {\n if (input.service && input.stdio) return yield* Effect.fail(new Error(\"--service and --stdio cannot be combined\"))\n return yield* ServerProcess.run({\n mode: input.service ? \"service\" : input.stdio ? \"stdio\" : \"default\",\n hostname: Option.getOrUndefined(input.hostname),\n port: Option.getOrUndefined(input.port),\n })\n }),\n)\n" | ||
| ], | ||
| "mappings": ";o6CAAA,sBAAS,eAAQ,qBACjB,yBAAS,qBAAW,oBAAY,mBAAW,gBAE3C,yBAIO,SAAU,QAAV,MAAU,SAAV,MACE,WAAM,eAAkB,OAAO,sBAA4B,OAAE,4BAAwB,MAC1F,UAAM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,aAAa,IACzB,EAAQ,KACN,EAAO,QAAQ,CAAC,IAAa,GAAS,KAAO,EAAK,EAAG,OAAO,CAAI,EAAI,EAAO,IAAK,EAChF,EAAO,MACT,CACF,EACA,MAAO,EAAmB,KACxB,EAAO,WAAW,CAAC,IAAU,EAAO,WAAW,0CAA2C,CAAE,OAAM,CAAC,CAAC,EACpG,EAAO,OAAO,EAAS,OAAO,WAAW,CAAC,EAC1C,EAAO,UACT,EACD,EAED,SAAS,EAAiB,EAAG,CAC3B,OAAO,EAAO,SAAe,CAAC,IAAW,CACvC,IAAM,EAAQ,IAAM,EAAO,EAAO,IAAI,EAItC,GAHA,QAAQ,MAAM,KAAK,MAAO,CAAK,EAC/B,QAAQ,MAAM,KAAK,QAAS,CAAK,EACjC,QAAQ,MAAM,OAAO,EACjB,QAAQ,MAAM,eAAiB,QAAQ,MAAM,UAAW,EAAM,EAClE,OAAO,EAAO,KAAK,IAAM,CACvB,QAAQ,MAAM,IAAI,MAAO,CAAK,EAC9B,QAAQ,MAAM,IAAI,QAAS,CAAK,EAChC,QAAQ,MAAM,MAAM,EACrB,EACF,ECnJH,IAAe,KAAQ,QACrB,EAAS,SAAS,MAClB,EAAO,GAAG,WAAW,EAAE,SAAU,CAAC,EAAO,CACvC,GAAI,EAAM,SAAW,EAAM,MAAO,OAAO,MAAO,EAAO,KAAS,MAAM,0CAA0C,CAAC,EACjH,OAAO,MAAO,EAAc,IAAI,CAC9B,KAAM,EAAM,QAAU,UAAY,EAAM,MAAQ,QAAU,UAC1D,SAAU,EAAO,eAAe,EAAM,QAAQ,EAC9C,KAAM,EAAO,eAAe,EAAM,IAAI,CACxC,CAAC,EACF,CACH", | ||
| "debugId": "555C96E4148F5D9164756E2164756E21", | ||
| "names": [] | ||
| } |
| { | ||
| "version": 3, | ||
| "sources": ["../core/src/installation/version.ts"], | ||
| "sourcesContent": [ | ||
| "declare global {\n const OPENCODE_VERSION: string\n const OPENCODE_CHANNEL: string\n}\n\nexport const InstallationVersion = typeof OPENCODE_VERSION === \"string\" ? OPENCODE_VERSION : \"local\"\nexport const InstallationChannel = typeof OPENCODE_CHANNEL === \"string\" ? OPENCODE_CHANNEL : \"local\"\nexport const InstallationLocal = InstallationChannel === \"local\"\n" | ||
| ], | ||
| "mappings": ";AAKO,IAAM,EAA6D,mBAC7D,EAA6D,OAC7D,EAAoB", | ||
| "debugId": "98D46A96EBB6EBD864756E2164756E21", | ||
| "names": [] | ||
| } |
| { | ||
| "version": 3, | ||
| "sources": ["src/commands/handlers/mcp/add.ts"], | ||
| "sourcesContent": [ | ||
| "import { EOL } from \"node:os\"\nimport path from \"node:path\"\nimport { Effect, Option } from \"effect\"\nimport { applyEdits, modify } from \"jsonc-parser\"\nimport { Global } from \"@opencode-ai/core/global\"\nimport { Commands } from \"../../commands\"\nimport { Runtime } from \"../../../framework/runtime\"\n\nexport default Runtime.handler(\n Commands.commands.mcp.commands.add,\n Effect.fn(\"cli.mcp.add\")(function* (input) {\n const url = Option.getOrUndefined(input.url)\n const headers = Option.getOrUndefined(input.header)\n const environment = Option.getOrUndefined(input.env)\n // The CLI framework strands `--` operands on the root command, so read the local server command\n // straight from argv after `--`. This also lets the command carry its own flags (e.g. `npx -y`).\n const dash = process.argv.indexOf(\"--\")\n const command = dash === -1 ? [...input.command] : process.argv.slice(dash + 1)\n\n const hasCommand = command.length > 0\n if (url && hasCommand)\n return yield* Effect.fail(new Error(\"Provide either --url <url> or a command after --, not both\"))\n if (!url && !hasCommand) return yield* Effect.fail(new Error(\"Provide either --url <url> or a command after --\"))\n if (url && !URL.canParse(url)) return yield* Effect.fail(new Error(`Invalid URL: ${url}`))\n if (url && environment) return yield* Effect.fail(new Error(\"--env is only valid for local MCP servers\"))\n if (hasCommand && headers) return yield* Effect.fail(new Error(\"--header is only valid for remote MCP servers\"))\n\n const server = url\n ? { type: \"remote\" as const, url, ...(headers ? { headers } : {}) }\n : { type: \"local\" as const, command, ...(environment ? { environment } : {}) }\n\n const configPath = yield* Effect.promise(() => resolveConfigPath(input.global ? Global.Path.config : process.cwd()))\n yield* Effect.promise(() => write(configPath, input.name, server))\n process.stdout.write(`MCP server \"${input.name}\" added to ${configPath}` + EOL)\n }),\n)\n\nasync function resolveConfigPath(directory: string) {\n const candidates = [\n path.join(directory, \"opencode.json\"),\n path.join(directory, \"opencode.jsonc\"),\n path.join(directory, \".opencode\", \"opencode.json\"),\n path.join(directory, \".opencode\", \"opencode.jsonc\"),\n ]\n for (const candidate of candidates) {\n if (await Bun.file(candidate).exists()) return candidate\n }\n return candidates[0]\n}\n\nasync function write(configPath: string, name: string, server: unknown) {\n const file = Bun.file(configPath)\n const text = (await file.exists()) ? await file.text() : \"{}\"\n const edits = modify(text, [\"mcp\", \"servers\", name], server, {\n formattingOptions: { tabSize: 2, insertSpaces: true },\n })\n await Bun.write(configPath, applyEdits(text, edits))\n}\n" | ||
| ], | ||
| "mappings": ";2xBAAA,mBAAS,gBACT,yBAOA,SAAe,SAAQ,aACrB,OAAS,cAAS,SAAI,cAAS,SAC/B,OAAO,QAAG,kBAAa,OAAE,cAAU,MAAC,OAAO,MACzC,SAAM,EAAM,EAAO,eAAe,EAAM,GAAG,EACrC,EAAU,EAAO,eAAe,EAAM,MAAM,EAC5C,EAAc,EAAO,eAAe,EAAM,GAAG,EAG7C,EAAO,QAAQ,KAAK,QAAQ,IAAI,EAChC,EAAU,IAAS,GAAK,CAAC,GAAG,EAAM,OAAO,EAAI,QAAQ,KAAK,MAAM,EAAO,CAAC,EAExE,EAAa,EAAQ,OAAS,EACpC,GAAI,GAAO,EACT,OAAO,MAAO,EAAO,KAAS,MAAM,4DAA4D,CAAC,EACnG,GAAI,CAAC,GAAO,CAAC,EAAY,OAAO,MAAO,EAAO,KAAS,MAAM,kDAAkD,CAAC,EAChH,GAAI,GAAO,CAAC,IAAI,SAAS,CAAG,EAAG,OAAO,MAAO,EAAO,KAAS,MAAM,gBAAgB,GAAK,CAAC,EACzF,GAAI,GAAO,EAAa,OAAO,MAAO,EAAO,KAAS,MAAM,2CAA2C,CAAC,EACxG,GAAI,GAAc,EAAS,OAAO,MAAO,EAAO,KAAS,MAAM,+CAA+C,CAAC,EAE/G,IAAM,EAAS,EACX,CAAE,KAAM,SAAmB,SAAS,EAAU,CAAE,SAAQ,EAAI,CAAC,CAAG,EAChE,CAAE,KAAM,QAAkB,aAAa,EAAc,CAAE,aAAY,EAAI,CAAC,CAAG,EAEzE,EAAa,MAAO,EAAO,QAAQ,IAAM,EAAkB,EAAM,OAAS,EAAO,KAAK,OAAS,QAAQ,IAAI,CAAC,CAAC,EACnH,MAAO,EAAO,QAAQ,IAAM,EAAM,EAAY,EAAM,KAAM,CAAM,CAAC,EACjE,QAAQ,OAAO,MAAM,eAAe,EAAM,kBAAkB,IAAe,CAAG,EAC/E,CACH,EAEA,eAAe,CAAiB,CAAC,EAAmB,CAClD,IAAM,EAAa,CACjB,EAAK,KAAK,EAAW,eAAe,EACpC,EAAK,KAAK,EAAW,gBAAgB,EACrC,EAAK,KAAK,EAAW,YAAa,eAAe,EACjD,EAAK,KAAK,EAAW,YAAa,gBAAgB,CACpD,EACA,QAAW,KAAa,EACtB,GAAI,MAAM,IAAI,KAAK,CAAS,EAAE,OAAO,EAAG,OAAO,EAEjD,OAAO,EAAW,GAGpB,eAAe,CAAK,CAAC,EAAoB,EAAc,EAAiB,CACtE,IAAM,EAAO,IAAI,KAAK,CAAU,EAC1B,EAAQ,MAAM,EAAK,OAAO,EAAK,MAAM,EAAK,KAAK,EAAI,KACnD,EAAQ,EAAO,EAAM,CAAC,MAAO,UAAW,CAAI,EAAG,EAAQ,CAC3D,kBAAmB,CAAE,QAAS,EAAG,aAAc,EAAK,CACtD,CAAC,EACD,MAAM,IAAI,MAAM,EAAY,EAAW,EAAM,CAAK,CAAC", | ||
| "debugId": "0AECBEB226A9C4C164756E2164756E21", | ||
| "names": [] | ||
| } |
| { | ||
| "version": 3, | ||
| "sources": ["src/commands/handlers/mcp/auth.ts"], | ||
| "sourcesContent": [ | ||
| "import { EOL } from \"node:os\"\nimport { Effect } from \"effect\"\nimport {\n OpenCode,\n type IntegrationAttemptStatus,\n type IntegrationOAuthMethod,\n type OpenCodeClient,\n} from \"@opencode-ai/client\"\nimport { Commands } from \"../../commands\"\nimport { Runtime } from \"../../../framework/runtime\"\nimport { Service } from \"@opencode-ai/client/effect/service\"\nimport { ServiceConfig } from \"../../../services/service-config\"\nimport { resolveIntegration } from \"./resolve\"\n\nconst location = { directory: process.cwd() }\n\nexport default Runtime.handler(\n Commands.commands.mcp.commands.auth,\n Effect.fn(\"cli.mcp.auth\")(function* (input) {\n const options = yield* ServiceConfig.options()\n const found = yield* Service.discover(options)\n const endpoint = found ?? (yield* Service.ensure(options))\n const client = OpenCode.make({ baseUrl: endpoint.url, headers: Service.headers(endpoint) })\n\n const integration = yield* resolveIntegration(client, input.name, location)\n if (!integration)\n return yield* Effect.fail(new Error(`MCP server \"${input.name}\" is not an OAuth-capable remote server`))\n const method = integration.methods.find(\n (candidate): candidate is IntegrationOAuthMethod => candidate.type === \"oauth\",\n )\n if (!method)\n return yield* Effect.fail(new Error(`MCP server \"${input.name}\" is not an OAuth-capable remote server`))\n\n const started = yield* Effect.promise(() =>\n client.integration.connect.oauth({ integrationID: integration.id, methodID: method.id, inputs: {}, location }),\n )\n const attempt = started.data\n if (attempt.mode === \"code\")\n return yield* Effect.fail(new Error(\"This server requires manual code entry, which the CLI does not support\"))\n\n process.stdout.write(attempt.instructions + EOL + attempt.url + EOL)\n\n const result = yield* poll(client, attempt.attemptID)\n if (result.status === \"complete\") {\n process.stdout.write(`Authenticated with ${input.name}` + EOL)\n return\n }\n const reason = result.status === \"failed\" ? `: ${result.message}` : \"\"\n return yield* Effect.fail(new Error(`Authentication ${result.status}${reason}`))\n }),\n)\n\nconst poll = (\n client: OpenCodeClient,\n attemptID: string,\n): Effect.Effect<Exclude<IntegrationAttemptStatus, { status: \"pending\" }>> =>\n Effect.gen(function* () {\n const status = yield* Effect.promise(() => client.integration.attempt.status({ attemptID, location })).pipe(\n Effect.map((result) => result.data),\n )\n if (status.status === \"pending\") {\n yield* Effect.sleep(\"1 second\")\n return yield* poll(client, attemptID)\n }\n return status\n })\n" | ||
| ], | ||
| "mappings": ";88BAAA,mBAAS,gBAcT,SAAM,OAAW,MAAE,eAAW,aAAQ,SAAI,MAAE,OAE7B,SAAQ,aACrB,OAAS,cAAS,SAAI,cAAS,UAC/B,OAAO,QAAG,mBAAc,OAAE,cAAU,MAAC,OAAO,MAC1C,IAAM,EAAU,MAAO,EAAc,QAAQ,EAEvC,GADQ,MAAO,EAAQ,SAAS,CAAO,KAClB,MAAO,EAAQ,OAAO,CAAO,GAClD,EAAS,EAAS,KAAK,CAAE,QAAS,EAAS,IAAK,QAAS,EAAQ,QAAQ,CAAQ,CAAE,CAAC,EAEpF,EAAc,MAAO,EAAmB,EAAQ,EAAM,KAAM,CAAQ,EAC1E,GAAI,CAAC,EACH,OAAO,MAAO,EAAO,KAAS,MAAM,eAAe,EAAM,6CAA6C,CAAC,EACzG,IAAM,EAAS,EAAY,QAAQ,KACjC,CAAC,IAAmD,EAAU,OAAS,OACzE,EACA,GAAI,CAAC,EACH,OAAO,MAAO,EAAO,KAAS,MAAM,eAAe,EAAM,6CAA6C,CAAC,EAKzG,IAAM,GAHU,MAAO,EAAO,QAAQ,IACpC,EAAO,YAAY,QAAQ,MAAM,CAAE,cAAe,EAAY,GAAI,SAAU,EAAO,GAAI,OAAQ,CAAC,EAAG,UAAS,CAAC,CAC/G,GACwB,KACxB,GAAI,EAAQ,OAAS,OACnB,OAAO,MAAO,EAAO,KAAS,MAAM,wEAAwE,CAAC,EAE/G,QAAQ,OAAO,MAAM,EAAQ,aAAe,EAAM,EAAQ,IAAM,CAAG,EAEnE,IAAM,EAAS,MAAO,EAAK,EAAQ,EAAQ,SAAS,EACpD,GAAI,EAAO,SAAW,WAAY,CAChC,QAAQ,OAAO,MAAM,sBAAsB,EAAM,OAAS,CAAG,EAC7D,OAEF,IAAM,EAAS,EAAO,SAAW,SAAW,KAAK,EAAO,UAAY,GACpE,OAAO,MAAO,EAAO,KAAS,MAAM,kBAAkB,EAAO,SAAS,GAAQ,CAAC,EAChF,CACH,EAEM,EAAO,CACX,EACA,IAEA,EAAO,IAAI,SAAU,EAAG,CACtB,IAAM,EAAS,MAAO,EAAO,QAAQ,IAAM,EAAO,YAAY,QAAQ,OAAO,CAAE,YAAW,UAAS,CAAC,CAAC,EAAE,KACrG,EAAO,IAAI,CAAC,IAAW,EAAO,IAAI,CACpC,EACA,GAAI,EAAO,SAAW,UAEpB,OADA,MAAO,EAAO,MAAM,UAAU,EACvB,MAAO,EAAK,EAAQ,CAAS,EAEtC,OAAO,EACR", | ||
| "debugId": "9D05A85EFB73D90B64756E2164756E21", | ||
| "names": [] | ||
| } |
| { | ||
| "version": 3, | ||
| "sources": ["../core/src/image/photon.ts"], | ||
| "sourcesContent": [ | ||
| "// @ts-ignore Bun's static file import is embedded by `bun build --compile`; some consumers also declare *.wasm.\nimport photonWasm from \"@silvia-odwyer/photon-node/photon_rs_bg.wasm\" with { type: \"file\" }\nimport { Effect } from \"effect\"\nimport path from \"node:path\"\nimport { fileURLToPath } from \"node:url\"\nimport { FileSystem } from \"../filesystem\"\nimport { DecodeError, ResizerUnavailableError, SizeError } from \"../image\"\n\nconst JPEG_QUALITIES = [80, 85, 70, 55, 40]\n\nexport const make = Effect.gen(function* () {\n ;(globalThis as typeof globalThis & { __OPENCODE_PHOTON_WASM_PATH?: string }).__OPENCODE_PHOTON_WASM_PATH =\n path.isAbsolute(photonWasm) ? photonWasm : fileURLToPath(new URL(photonWasm, import.meta.url))\n const loadPhoton = yield* Effect.cached(\n Effect.tryPromise({\n try: () => import(\"@silvia-odwyer/photon-node\"),\n catch: () => new ResizerUnavailableError(),\n }),\n )\n return Effect.fn(\"Image.Photon.normalize\")(function* (\n resource: string,\n content: FileSystem.Content & { readonly encoding: \"base64\" },\n limits: {\n readonly autoResize: boolean\n readonly maxWidth: number\n readonly maxHeight: number\n readonly maxBase64Bytes: number\n },\n ) {\n const photon = yield* loadPhoton\n const decoded = yield* Effect.try({\n try: () => photon.PhotonImage.new_from_byteslice(Buffer.from(content.content, \"base64\")),\n catch: () => new DecodeError({ resource }),\n })\n try {\n const width = decoded.get_width()\n const height = decoded.get_height()\n const bytes = Buffer.byteLength(content.content, \"utf-8\")\n if (width <= limits.maxWidth && height <= limits.maxHeight && bytes <= limits.maxBase64Bytes) return content\n if (!limits.autoResize)\n return yield* new SizeError({\n resource,\n width,\n height,\n bytes,\n maxWidth: limits.maxWidth,\n maxHeight: limits.maxHeight,\n maxBytes: limits.maxBase64Bytes,\n })\n const scale = Math.min(1, limits.maxWidth / width, limits.maxHeight / height)\n const sizes = Array.from({ length: 32 }).reduce<Array<{ width: number; height: number }>>((acc) => {\n const previous = acc.at(-1) ?? {\n width: Math.max(1, Math.round(width * scale)),\n height: Math.max(1, Math.round(height * scale)),\n }\n const next =\n acc.length === 0\n ? previous\n : {\n width: previous.width === 1 ? 1 : Math.max(1, Math.floor(previous.width * 0.75)),\n height: previous.height === 1 ? 1 : Math.max(1, Math.floor(previous.height * 0.75)),\n }\n return acc.some((item) => item.width === next.width && item.height === next.height) ? acc : [...acc, next]\n }, [])\n for (const size of sizes) {\n const resized = photon.resize(decoded, size.width, size.height, photon.SamplingFilter.Lanczos3)\n try {\n const encoders: Array<readonly [mime: string, encode: () => Uint8Array]> = [\n [\"image/png\", () => resized.get_bytes()],\n ...JPEG_QUALITIES.map((quality) => [\"image/jpeg\", () => resized.get_bytes_jpeg(quality)] as const),\n ]\n for (const [mime, encode] of encoders) {\n const candidate = Buffer.from(encode()).toString(\"base64\")\n if (Buffer.byteLength(candidate, \"utf-8\") <= limits.maxBase64Bytes)\n return { ...content, content: candidate, encoding: \"base64\" as const, mime }\n }\n } finally {\n resized.free()\n }\n }\n return yield* new SizeError({\n resource,\n width,\n height,\n bytes,\n maxWidth: limits.maxWidth,\n maxHeight: limits.maxHeight,\n maxBytes: limits.maxBase64Bytes,\n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AK,IAAI,EAAG,KAAK,MAAM,EAAS,CAAK,CAAC,CAChD,EACM,EACJ,EAAI,SAAW,EACX,EACA,CACE,MAAO,EAAS,QAAU,EAAI,EAAI,KAAK,IAAI,EAAG,KAAK,MAAM,EAAS,MAAQ,IAAI,CAAC,EAC/E,OAAQ,EAAS,SAAW,EAAI,EAAI,KAAK,IAAI,EAAG,KAAK,MAAM,EAAS,OAAS,IAAI,CAAC,CACpF,EACN,OAAO,EAAI,KAAK,CAAC,IAAS,EAAK,QAAU,EAAK,OAAS,EAAK,SAAW,EAAK,MAAM,EAAI,EAAM,CAAC,GAAG,EAAK,CAAI,GACxG,CAAC,CAAC,EACL,QAAW,KAAQ,EAAO,CACxB,IAAM,EAAU,EAAO,OAAO,EAAS,EAAK,MAAO,EAAK,OAAQ,EAAO,eAAe,QAAQ,EAC9F,GAAI,CACF,IAAM,EAAqE,CACzE,CAAC,YAAa,IAAM,EAAQ,UAAU,CAAC,EACvC,GAAG,EAAe,IAAI,CAAC,IAAY,CAAC,aAAc,IAAM,EAAQ,eAAe,CAAO,CAAC,CAAU,CACnG,EACA,QAAY,EAAM,KAAW,EAAU,CACrC,IAAM,EAAY,OAAO,KAAK,EAAO,CAAC,EAAE,SAAS,QAAQ,EACzD,GAAI,OAAO,WAAW,EAAW,OAAO,GAAK,EAAO,eAClD,MAAO,IAAK,EAAS,QAAS,EAAW,SAAU,SAAmB,MAAK,UAE/E,CACA,EAAQ,KAAK,GAGjB,OAAO,MAAO,IAAI,EAAU,CAC1B,WACA,QACA,SACA,QACA,SAAU,EAAO,SACjB,UAAW,EAAO,UAClB,SAAU,EAAO,cACnB,CAAC,SACD,CACA,EAAQ,KAAK,GAEhB,EACF", | ||
| "debugId": "DFA4D47152A93E2864756E2164756E21", | ||
| "names": [] | ||
| } |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
| { | ||
| "version": 3, | ||
| "sources": ["src/commands/handlers/api.ts"], | ||
| "sourcesContent": [ | ||
| "import { EOL } from \"node:os\"\nimport { Effect, Option } from \"effect\"\nimport { Commands } from \"../commands\"\nimport { Runtime } from \"../../framework/runtime\"\nimport { Service, type Endpoint } from \"@opencode-ai/client/effect/service\"\nimport { ServerConnection } from \"../../services/server-connection\"\n\nconst methods = new Set([\"delete\", \"get\", \"head\", \"options\", \"patch\", \"post\", \"put\"])\n\ntype Operation = {\n operationId?: string\n}\n\ntype OpenApi = {\n paths?: Record<string, Record<string, Operation>>\n}\n\nexport default Runtime.handler(\n Commands.commands.api,\n Effect.fn(\"cli.api\")(function* (input) {\n const server = yield* ServerConnection.resolve({\n server: Option.getOrUndefined(input.server),\n standalone: input.standalone,\n mismatch: \"ignore\",\n })\n const endpoint = server.endpoint\n const params = Option.getOrElse(input.param, () => ({}))\n const request = yield* resolveRequest(endpoint, input.request, params)\n const headers = new Headers(Service.headers(endpoint))\n for (const header of input.header) {\n const index = header.indexOf(\":\")\n if (index < 1) return yield* Effect.fail(new Error(`Invalid header, expected name:value: ${header}`))\n headers.set(header.slice(0, index).trim(), header.slice(index + 1).trim())\n }\n const body = Option.getOrUndefined(input.data)\n if (body !== undefined && !headers.has(\"content-type\")) headers.set(\"content-type\", \"application/json\")\n\n const response = yield* Effect.tryPromise(() =>\n fetch(new URL(request.path, endpoint.url), {\n method: request.method,\n headers,\n body,\n }),\n )\n const output = yield* Effect.promise(() => response.text())\n if (output) process.stdout.write(output + (output.endsWith(EOL) ? \"\" : EOL))\n }),\n)\n\nexport function resolveOperation(spec: OpenApi, operationID: string, params: Record<string, string>) {\n for (const [path, operations] of Object.entries(spec.paths ?? {})) {\n for (const [method, operation] of Object.entries(operations)) {\n if (!methods.has(method) || operation.operationId !== operationID) continue\n return { method: method.toUpperCase(), path: interpolate(path, params) }\n }\n }\n throw new Error(`Operation not found: ${operationID}`)\n}\n\nexport function rawRequest(input: readonly string[]) {\n if (input.length !== 2 || !methods.has(input[0].toLowerCase()) || !input[1].startsWith(\"/\")) return\n return { method: input[0].toUpperCase(), path: input[1] }\n}\n\nfunction resolveRequest(endpoint: Endpoint, input: readonly string[], params: Record<string, string>) {\n const raw = rawRequest(input)\n if (raw) return Effect.succeed(raw)\n if (input.length !== 1) return Effect.fail(new Error(\"Expected an operation name or an HTTP method and path\"))\n return Effect.tryPromise(async () => {\n const response = await fetch(new URL(\"/openapi.json\", endpoint.url), { headers: Service.headers(endpoint) })\n if (!response.ok) throw new Error(`Failed to load OpenAPI document: HTTP ${response.status}`)\n return resolveOperation((await response.json()) as OpenApi, input[0], params)\n })\n}\n\nfunction interpolate(path: string, params: Record<string, string>) {\n const used = new Set<string>()\n const pathname = path.replaceAll(/\\{([^}]+)\\}/g, (_, name: string) => {\n const value = params[name]\n if (value === undefined) throw new Error(`Missing path parameter: ${name}`)\n used.add(name)\n return encodeURIComponent(value)\n })\n const query = new URLSearchParams(Object.entries(params).filter(([name]) => !used.has(name))).toString()\n return query ? `${pathname}?${query}` : pathname\n}\n" | ||
| ], | ||
| "mappings": ";ixCAAA,mBAAS,gBAOT,SAAM,OAAU,SAAI,SAAI,MAAC,cAAU,WAAO,YAAQ,eAAW,aAAS,YAAQ,UAAK,MAAC,OAUrE,SAAQ,aACrB,OAAS,cAAS,SAClB,OAAO,QAAG,cAAS,OAAE,cAAU,MAAC,OAAO,MAMrC,SAAM,QALS,WAAO,OAAiB,aAAQ,MAC7C,OAAQ,EAAO,eAAe,EAAM,MAAM,EAC1C,WAAY,EAAM,WAClB,SAAU,QACZ,CAAC,GACuB,SAClB,EAAS,EAAO,UAAU,EAAM,MAAO,KAAO,CAAC,EAAE,EACjD,EAAU,MAAO,EAAe,EAAU,EAAM,QAAS,CAAM,EAC/D,EAAU,IAAI,QAAQ,EAAQ,QAAQ,CAAQ,CAAC,EACrD,QAAW,KAAU,EAAM,OAAQ,CACjC,IAAM,EAAQ,EAAO,QAAQ,GAAG,EAChC,GAAI,EAAQ,EAAG,OAAO,MAAO,EAAO,KAAS,MAAM,wCAAwC,GAAQ,CAAC,E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AS,MAAM,uDAAuD,CAAC,EAC7G,OAAO,EAAO,WAAW,SAAY,CACnC,IAAM,EAAW,MAAM,MAAM,IAAI,IAAI,gBAAiB,EAAS,GAAG,EAAG,CAAE,QAAS,EAAQ,QAAQ,CAAQ,CAAE,CAAC,EAC3G,GAAI,CAAC,EAAS,GAAI,MAAU,MAAM,yCAAyC,EAAS,QAAQ,EAC5F,OAAO,EAAkB,MAAM,EAAS,KAAK,EAAe,EAAM,GAAI,CAAM,EAC7E,EAGH,SAAS,CAAW,CAAC,EAAc,EAAgC,CACjE,IAAM,EAAO,IAAI,IACX,EAAW,EAAK,WAAW,eAAgB,CAAC,EAAG,IAAiB,CACpE,IAAM,EAAQ,EAAO,GACrB,GAAI,IAAU,OAAW,MAAU,MAAM,2BAA2B,GAAM,EAE1E,OADA,EAAK,IAAI,CAAI,EACN,mBAAmB,CAAK,EAChC,EACK,EAAQ,IAAI,gBAAgB,OAAO,QAAQ,CAAM,EAAE,OAAO,EAAE,KAAU,CAAC,EAAK,IAAI,CAAI,CAAC,CAAC,EAAE,SAAS,EACvG,OAAO,EAAQ,GAAG,KAAY,IAAU", | ||
| "debugId": "2FBE91234BAAAB5964756E2164756E21", | ||
| "names": [] | ||
| } |
| { | ||
| "version": 3, | ||
| "sources": ["src/commands/handlers/service/unset.ts"], | ||
| "sourcesContent": [ | ||
| "import { Effect } from \"effect\"\nimport { Commands } from \"../../commands\"\nimport { Runtime } from \"../../../framework/runtime\"\nimport { ServiceConfig } from \"../../../services/service-config\"\n\nexport default Runtime.handler(\n Commands.commands.service.commands.unset,\n Effect.fn(\"cli.service.unset\")(function* (input) {\n yield* ServiceConfig.unset(input.key)\n }),\n)\n" | ||
| ], | ||
| "mappings": ";o2BAKA,SAAe,SAAQ,aACrB,OAAS,cAAS,aAAQ,cAAS,WACnC,OAAO,QAAG,wBAAmB,OAAE,cAAU,MAAC,OAAO,MAC/C,WAAO,OAAc,WAAM,OAAM,QAAG,OACrC,MACH", | ||
| "debugId": "8A2030DBFE3B7B8964756E2164756E21", | ||
| "names": [] | ||
| } |
| { | ||
| "version": 3, | ||
| "sources": ["src/commands/handlers/run.ts"], | ||
| "sourcesContent": [ | ||
| "import { Effect, Option } from \"effect\"\nimport { Commands } from \"../commands\"\nimport { Runtime } from \"../../framework/runtime\"\nimport { ServerConnection } from \"../../services/server-connection\"\n\nexport default Runtime.handler(Commands.commands.run, (input) =>\n Effect.gen(function* () {\n const { runNonInteractive } = yield* Effect.promise(() => import(\"../../mini\"))\n const separator = process.argv.indexOf(\"--\", 2)\n const server = yield* ServerConnection.resolve({\n server: Option.getOrUndefined(input.server),\n standalone: input.standalone,\n })\n yield* Effect.promise(() =>\n runNonInteractive({\n server,\n message: [...input.message, ...(separator === -1 ? [] : process.argv.slice(separator + 1))],\n continue: input.continue,\n session: Option.getOrUndefined(input.session),\n fork: input.fork,\n model: Option.getOrUndefined(input.model),\n agent: Option.getOrUndefined(input.agent),\n format: input.format,\n file: [...input.file],\n title: Option.getOrUndefined(input.title),\n thinking: input.thinking,\n auto: input.auto || input.yolo,\n }),\n )\n }),\n)\n" | ||
| ], | ||
| "mappings": ";ixCAKA,SAAe,SAAQ,aAAQ,OAAS,cAAS,SAAK,MAAC,SACrD,OAAO,SAAI,cAAU,OAAG,MACtB,SAAQ,0BAAsB,WAAO,OAAO,aAAQ,SAAa,wCAAa,OACxE,OAAY,aAAQ,UAAK,aAAQ,UAAM,MAAC,OACxC,OAAS,WAAO,OAAiB,aAAQ,MAC7C,YAAQ,OAAO,oBAAe,EAAM,MAAM,EAC1C,WAAY,EAAM,UACpB,CAAC,EACD,MAAO,EAAO,QAAQ,IACpB,EAAkB,CAChB,SACA,QAAS,CAAC,GAAG,EAAM,QAAS,GAAI,IAAc,GAAK,CAAC,EAAI,QAAQ,KAAK,MAAM,EAAY,CAAC,CAAE,EAC1F,SAAU,EAAM,SAChB,QAAS,EAAO,eAAe,EAAM,OAAO,EAC5C,KAAM,EAAM,KACZ,MAAO,EAAO,eAAe,EAAM,KAAK,EACxC,MAAO,EAAO,eAAe,EAAM,KAAK,EACxC,OAAQ,EAAM,OACd,KAAM,CAAC,GAAG,EAAM,IAAI,EACpB,MAAO,EAAO,eAAe,EAAM,KAAK,EACxC,SAAU,EAAM,SAChB,KAAM,EAAM,MAAQ,EAAM,IAC5B,CAAC,CACH,EACD,CACH", | ||
| "debugId": "7CDD744CD63842B364756E2164756E21", | ||
| "names": [] | ||
| } |
| { | ||
| "version": 3, | ||
| "sources": ["src/commands/handlers/pair.ts"], | ||
| "sourcesContent": [ | ||
| "import { EOL } from \"os\"\nimport { Effect } from \"effect\"\nimport { Service } from \"@opencode-ai/client/effect/service\"\nimport { OpenCode } from \"@opencode-ai/client/promise\"\nimport { renderUnicodeCompact } from \"uqr\"\nimport { Commands } from \"../commands\"\nimport { Runtime } from \"../../framework/runtime\"\nimport { ServiceConfig } from \"../../services/service-config\"\n\nexport default Runtime.handler(\n Commands.commands.pair,\n Effect.fn(\"cli.pair\")(function* () {\n const endpoint = yield* Service.ensure(yield* ServiceConfig.options())\n const password = yield* ServiceConfig.password()\n const server = yield* Effect.tryPromise(() =>\n OpenCode.make({ baseUrl: endpoint.url, headers: Service.headers(endpoint) }).server.get(),\n )\n const info = { urls: server.urls, username: \"opencode\", password }\n process.stdout.write(\n [\n \"\",\n ` URLs ${info.urls[0] ?? \"(none)\"}`,\n ...info.urls.slice(1).map((url) => ` ${url}`),\n ` Username ${info.username}`,\n ` Password ${info.password}`,\n \"\",\n \" Scan to pair\",\n \"\",\n renderUnicodeCompact(JSON.stringify(info), { border: 2 })\n .split(EOL)\n .map((line) => \" \" + line)\n .join(EOL),\n \"\",\n ].join(EOL) + EOL,\n )\n\n const hostname = new URL(endpoint.url).hostname\n if (![\"localhost\", \"127.0.0.1\", \"[::1]\"].includes(hostname)) return\n process.stderr.write(\n ` Run \\`opencode service set hostname 0.0.0.0\\` to access the service remotely.${EOL}${EOL}`,\n )\n }),\n)\n" | ||
| ], | ||
| "mappings": ";88BAAA,mBAAS,gBAST,SAAe,SAAQ,aACrB,OAAS,cAAS,UAClB,OAAO,QAAG,eAAU,OAAE,cAAU,OAAG,MACjC,SAAM,OAAW,WAAO,OAAQ,YAAO,WAAO,OAAc,aAAQ,MAAC,OAC/D,EAAW,MAAO,EAAc,SAAS,EAIzC,EAAO,CAAE,MAHA,MAAO,EAAO,WAAW,IACtC,EAAS,KAAK,CAAE,QAAS,EAAS,IAAK,QAAS,EAAQ,QAAQ,CAAQ,CAAE,CAAC,EAAE,OAAO,IAAI,CAC1F,GAC4B,KAAM,SAAU,WAAY,UAAS,EACjE,QAAQ,OAAO,MACb,CACE,GACA,eAAe,EAAK,KAAK,IAAM,WAC/B,GAAG,EAAK,KAAK,MAAM,CAAC,EAAE,IAAI,CAAC,IAAQ,eAAe,GAAK,EACvD,eAAe,EAAK,WACpB,eAAe,EAAK,WACpB,GACA,iBACA,GACA,EAAqB,KAAK,UAAU,CAAI,EAAG,CAAE,OAAQ,CAAE,CAAC,EACrD,MAAM,CAAG,EACT,IAAI,CAAC,IAAS,KAAO,CAAI,EACzB,KAAK,CAAG,EACX,EACF,EAAE,KAAK,CAAG,EAAI,CAChB,EAEA,IAAM,EAAW,IAAI,IAAI,EAAS,GAAG,EAAE,SACvC,GAAI,CAAC,CAAC,YAAa,YAAa,OAAO,EAAE,SAAS,CAAQ,EAAG,OAC7D,QAAQ,OAAO,MACb,kFAAkF,IAAM,GAC1F,EACD,CACH", | ||
| "debugId": "D7DDF03BCD730C8C64756E2164756E21", | ||
| "names": [] | ||
| } |
| { | ||
| "version": 3, | ||
| "sources": ["src/commands/handlers/service/status.ts"], | ||
| "sourcesContent": [ | ||
| "import { EOL } from \"os\"\nimport { Effect } from \"effect\"\nimport { Service } from \"@opencode-ai/client/effect/service\"\nimport { Commands } from \"../../commands\"\nimport { Runtime } from \"../../../framework/runtime\"\nimport { ServiceConfig } from \"../../../services/service-config\"\n\nexport default Runtime.handler(\n Commands.commands.service.commands.status,\n Effect.fn(\"cli.service.status\")(function* () {\n const options = yield* ServiceConfig.options()\n const found = yield* Service.discover({ ...options, version: undefined })\n process.stdout.write((found?.url ?? \"stopped\") + EOL)\n }),\n)\n" | ||
| ], | ||
| "mappings": ";i3BAAA,mBAAS,gBAOT,SAAe,SAAQ,aACrB,OAAS,cAAS,aAAQ,cAAS,YACnC,OAAO,QAAG,yBAAoB,OAAE,cAAU,OAAG,MAC3C,SAAM,OAAU,WAAO,OAAc,aAAQ,OACvC,EAAQ,MAAO,EAAQ,SAAS,IAAK,EAAS,QAAS,MAAU,CAAC,EACxE,QAAQ,OAAO,OAAO,GAAO,KAAO,WAAa,CAAG,EACrD,CACH", | ||
| "debugId": "D6EB13B53191A58B64756E2164756E21", | ||
| "names": [] | ||
| } |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
| { | ||
| "version": 3, | ||
| "sources": ["src/mini/mini.ts", "src/mini/run.ts", "src/mini/noninteractive.ts", "src/mini/ui.ts"], | ||
| "sourcesContent": [ | ||
| "import { Service } from \"@opencode-ai/client/effect/service\"\nimport { OpenCode, type OpenCodeClient } from \"@opencode-ai/client/promise\"\nimport { ServerConnection } from \"../services/server-connection\"\nimport { waitForCatalogReady } from \"./catalog.shared\"\nimport { INTERACTIVE_INPUT_ERROR, resolveInteractiveStdin } from \"./runtime.stdin\"\nimport type { RunInput, RunTuiConfig } from \"./types\"\n\nexport type MiniCommandInput = {\n server: ServerConnection.Resolved\n continue?: boolean\n session?: string\n fork?: boolean\n model?: string\n agent?: string\n prompt?: string\n replay?: boolean\n replayLimit?: number\n demo?: boolean\n tuiConfig?: RunTuiConfig | Promise<RunTuiConfig>\n}\n\ntype Session = Awaited<ReturnType<OpenCodeClient[\"session\"][\"get\"]>>\nexport async function runMini(input: MiniCommandInput) {\n validate(input)\n const initialInput = mergeInput(process.stdin.isTTY ? undefined : await Bun.stdin.text(), input.prompt)\n const runtimeTask = import(\"./runtime\")\n const directory = localDirectory()\n\n try {\n const sdk = OpenCode.make({\n baseUrl: input.server.endpoint.url,\n headers: Service.headers(input.server.endpoint),\n })\n const model = parseModel(input.model)\n let agentTask: Promise<string | undefined> | undefined\n const resolveAgent = () => {\n agentTask ??= validateAgent(sdk, directory, input.agent)\n return agentTask\n }\n const resolveSession = async () => {\n const [agent, selected] = await Promise.all([resolveAgent(), selectSession(sdk, directory, input)])\n const readyModel =\n model ?? (selected?.model ? { providerID: selected.model.providerID, modelID: selected.model.id } : undefined)\n if (readyModel) await waitForCatalogReady({ sdk, directory, model: readyModel })\n const session = selected ?? (await createSession(sdk, directory, agent, model))\n return { id: session.id, title: session.title, resume: selected !== undefined }\n }\n const create = (\n _sdk: OpenCodeClient,\n next: { agent: string | undefined; model: RunInput[\"model\"]; variant: string | undefined },\n ) => createSession(sdk, directory, next.agent, next.model, next.variant)\n const runtime = await runtimeTask\n await runtime.runInteractiveDeferredMode({\n sdk,\n directory,\n resolveAgent,\n session: resolveSession,\n createSession: create,\n agent: input.agent,\n model,\n variant: undefined,\n files: [],\n initialInput,\n thinking: true,\n replay: input.replay ?? true,\n replayLimit: input.replayLimit,\n demo: input.demo,\n tuiConfig: input.tuiConfig,\n })\n } catch (error) {\n if (error instanceof Error && error.message === INTERACTIVE_INPUT_ERROR) fail(error.message)\n throw error\n }\n}\n\nexport function validateMiniTerminal() {\n if (!process.stdout.isTTY) fail(\"opencode mini requires a TTY stdout\")\n}\n\n/** @internal Exported for testing. */\nexport function mergeInput(piped: string | undefined, prompt: string | undefined) {\n if (!prompt) return piped || undefined\n if (!piped) return prompt\n return piped + \"\\n\" + prompt\n}\n\nfunction validate(input: MiniCommandInput) {\n validateMiniTerminal()\n if (input.replayLimit !== undefined && (!Number.isInteger(input.replayLimit) || input.replayLimit <= 0)) {\n fail(\"--replay-limit must be a positive integer\")\n }\n if (input.fork && !input.continue && !input.session) fail(\"--fork requires --continue or --session\")\n resolveInteractiveStdin().cleanup?.()\n}\n\nfunction localDirectory(): string {\n const root = process.env.PWD ?? process.cwd()\n try {\n process.chdir(root)\n return process.cwd()\n } catch {\n fail(`Failed to change directory to ${root}`)\n }\n}\n\nfunction parseModel(value?: string): RunInput[\"model\"] {\n if (!value) return\n const [providerID, ...rest] = value.split(\"/\")\n const modelID = rest.join(\"/\")\n if (!providerID || !modelID) fail(\"--model must use the format provider/model\")\n return { providerID, modelID }\n}\n\nasync function validateAgent(sdk: OpenCodeClient, directory: string, name?: string) {\n if (!name) return\n const deadline = Date.now() + 5_000\n let agents: Awaited<ReturnType<OpenCodeClient[\"agent\"][\"list\"]>> | undefined\n while (Date.now() < deadline) {\n agents = await sdk.agent.list({ location: { directory } }).catch(() => undefined)\n const agent = agents?.data.find((item) => item.id === name)\n if (agent?.mode === \"subagent\") {\n warning(`agent \"${name}\" is a subagent, not a primary agent. Falling back to default agent`)\n return\n }\n if (agent) return name\n await Bun.sleep(25)\n }\n if (!agents) {\n warning(\"failed to list agents. Falling back to default agent\")\n return\n }\n warning(`agent \"${name}\" not found. Falling back to default agent`)\n}\n\nasync function selectSession(sdk: OpenCodeClient, directory: string, input: MiniCommandInput, preselected?: Session) {\n const selected =\n preselected ??\n (input.session\n ? await sdk.session.get({ sessionID: input.session }).catch(() => undefined)\n : input.continue\n ? await sdk.session\n .list({ directory, parentID: null, limit: 1, order: \"desc\" })\n .then((result) => result.data[0])\n : undefined)\n if (input.session && !selected) fail(\"Session not found\")\n if (!selected) return\n if (!input.fork) return selected\n return sdk.session.fork({ sessionID: selected.id })\n}\n\nasync function createSession(\n sdk: OpenCodeClient,\n directory: string,\n agent: string | undefined,\n model: RunInput[\"model\"],\n variant?: string,\n): Promise<Session> {\n if (model) await waitForCatalogReady({ sdk, directory, model })\n return sdk.session.create({\n agent,\n model: model ? { providerID: model.providerID, id: model.modelID, variant } : undefined,\n location: { directory },\n })\n}\n\nfunction warning(message: string) {\n process.stderr.write(`\\x1b[93m\\x1b[1m!\\x1b[0m ${message}\\n`)\n}\n\nfunction fail(message: string): never {\n process.stderr.write(`\\x1b[91m\\x1b[1mError: \\x1b[0m${message}\\n`)\n process.exit(1)\n}\n", | ||
| "import { Service, type Endpoint } from \"@opencode-ai/client/effect/service\"\nimport { OpenCode, type OpenCodeClient } from \"@opencode-ai/client/promise\"\nimport { FSUtil } from \"@opencode-ai/core/fs-util\"\nimport { Model } from \"@opencode-ai/schema/model\"\nimport { open } from \"node:fs/promises\"\nimport path from \"node:path\"\nimport { ServerConnection } from \"../services/server-connection\"\nimport { loadRunAgents, waitForCatalogReady } from \"./catalog.shared\"\nimport { runNonInteractivePrompt } from \"./noninteractive\"\nimport { toolInlineInfo } from \"./tool\"\nimport type { MiniToolPart } from \"./types\"\nimport { UI } from \"./ui\"\n\nexport type RunCommandInput = {\n server: ServerConnection.Resolved\n message: string[]\n continue?: boolean\n session?: string\n fork?: boolean\n model?: string\n agent?: string\n format: \"default\" | \"json\"\n file: string[]\n title?: string\n thinking?: boolean\n auto?: boolean\n}\n\ntype FilePart = {\n url: string\n filename: string\n mime: string\n}\n\ntype Prepared = {\n directory?: string\n message: string\n files: FilePart[]\n}\n\nconst ATTACH_FILE_MAX_BYTES = 10 * 1024 * 1024\n\nexport function runNonInteractive(input: RunCommandInput) {\n return run(input).catch((error) => reportError(input, error instanceof Error ? error.message : String(error)))\n}\n\nasync function run(input: RunCommandInput) {\n if (input.fork && !input.continue && !input.session) fail(\"--fork requires --continue or --session\")\n const root = process.env.PWD ?? process.cwd()\n const directory = localDirectory(root)\n const message = mergeInput(formatMessage(input.message), process.stdin.isTTY ? undefined : await Bun.stdin.text())\n if (!message?.trim()) fail(\"You must provide a message\")\n const files = await Promise.all(input.file.map((file) => prepareFile(file, root)))\n const prepared = { directory, message, files }\n return execute(input, prepared, input.server.endpoint)\n}\n\nasync function execute(input: RunCommandInput, prepared: Prepared, endpoint: Endpoint) {\n const client = OpenCode.make({ baseUrl: endpoint.url, headers: Service.headers(endpoint) })\n const requestedDirectory = prepared.directory ?? (await client.location.get()).directory\n if (!requestedDirectory) fail(\"Failed to resolve server directory\")\n const session = await selectSession(client, requestedDirectory, input)\n const cwd = session?.location.directory ?? requestedDirectory\n const workspace = session?.location.workspaceID\n const explicit = parseRunModel(input.model)\n const explicitModel = explicit?.model\n const variant = explicit?.variant\n const sessionModel = session?.model ? { providerID: session.model.providerID, modelID: session.model.id } : undefined\n const defaultModel =\n !explicitModel && !sessionModel\n ? await client.model\n .default({ location: { directory: cwd, workspace } })\n .then((result) => (result.data ? { providerID: result.data.providerID, modelID: result.data.id } : undefined))\n : undefined\n const model = pickRunModel(explicitModel, variant, sessionModel, defaultModel)\n if (variant && !model) return reportError(input, \"Cannot select a variant before selecting a model\", session?.id)\n if (model) {\n await waitForCatalogReady({ sdk: client, directory: cwd, workspace, model })\n const available = await client.model.list({ location: { directory: cwd, workspace } })\n if (!available.data.some((item) => item.providerID === model.providerID && item.id === model.modelID))\n return reportError(input, `Model unavailable: ${model.providerID}/${model.modelID}`, session?.id)\n }\n const agent = await validateAgent(client, cwd, input.agent)\n const selected =\n session ??\n (await client.session.create({\n agent,\n model: model ? { providerID: model.providerID, id: model.modelID, variant } : undefined,\n location: { directory: cwd },\n }))\n if (!session && input.title !== undefined) {\n await client.session.rename({\n sessionID: selected.id,\n title: input.title || prepared.message.slice(0, 50) + (prepared.message.length > 50 ? \"...\" : \"\"),\n })\n }\n\n await runNonInteractivePrompt({\n client,\n sessionID: selected.id,\n message: prepared.message,\n files: prepared.files,\n agent,\n model,\n variant,\n thinking: input.thinking ?? false,\n format: input.format,\n auto: input.auto ?? false,\n attached: true,\n renderTool,\n renderToolError,\n }).catch((error) => reportError(input, error instanceof Error ? error.message : String(error), selected.id))\n}\n\nexport function mergeInput(message: string | undefined, piped: string | undefined) {\n if (!message) return piped || undefined\n if (!piped) return message\n return message + \"\\n\" + piped\n}\n\nexport function pickRunModel(\n explicit: { providerID: string; modelID: string } | undefined,\n variant: string | undefined,\n session: { providerID: string; modelID: string } | undefined,\n fallback: { providerID: string; modelID: string } | undefined,\n) {\n if (explicit) return explicit\n if (!variant) return\n return session ?? fallback\n}\n\nfunction formatMessage(message: string[]) {\n const value = message.map((part) => (part.includes(\" \") ? `\"${part.replace(/\"/g, '\\\\\"')}\"` : part)).join(\" \")\n return value || undefined\n}\n\nfunction localDirectory(root: string) {\n try {\n process.chdir(root)\n return process.cwd()\n } catch {\n fail(`Failed to change directory to ${root}`)\n }\n}\n\nexport function parseRunModel(value?: string) {\n if (!value) return\n const ref = Model.Ref.parse(value)\n return {\n model: { providerID: ref.providerID, modelID: ref.id },\n variant: ref.variant,\n }\n}\n\nasync function validateAgent(client: OpenCodeClient, directory: string, name?: string) {\n if (!name) return\n const agents = await loadRunAgents(client, directory).catch(() => undefined)\n if (!agents) {\n warning(\"failed to list agents. Falling back to default agent\")\n return\n }\n const agent = agents.find((item) => item.id === name)\n if (!agent) {\n warning(`agent \"${name}\" not found. Falling back to default agent`)\n return\n }\n if (agent.mode === \"subagent\") {\n warning(`agent \"${name}\" is a subagent, not a primary agent. Falling back to default agent`)\n return\n }\n return name\n}\n\nasync function selectSession(client: OpenCodeClient, directory: string, input: RunCommandInput) {\n const selected = input.session\n ? await client.session.get({ sessionID: input.session }).catch(() => undefined)\n : input.continue\n ? await client.session\n .list({ directory, parentID: null, limit: 1, order: \"desc\" })\n .then((result) => result.data[0])\n : undefined\n if (input.session && !selected) fail(\"Session not found\")\n if (!selected || !input.fork) return selected\n return client.session.fork({ sessionID: selected.id })\n}\n\nasync function prepareFile(input: string, directory: string): Promise<FilePart> {\n const file = path.resolve(directory, input)\n const handle = await open(file, \"r\").catch(() => fail(`File not found: ${input}`))\n try {\n const stat = await handle.stat()\n if (!stat.isFile() || stat.size > ATTACH_FILE_MAX_BYTES)\n fail(`Cannot attach a directory, special file, or file larger than 10 MiB: ${input}`)\n const content = Buffer.alloc(Number(stat.size))\n let offset = 0\n while (offset < content.length) {\n const read = await handle.read(content, offset, content.length - offset, offset)\n if (read.bytesRead === 0) break\n offset += read.bytesRead\n }\n const bytes = content.subarray(0, offset)\n const detected = FSUtil.mimeType(file)\n const text = bytes.toString(\"utf8\")\n const mime =\n detected.startsWith(\"image/\") || detected === \"application/pdf\"\n ? detected\n : !isBinaryContent(bytes) && Buffer.from(text, \"utf8\").equals(bytes)\n ? \"text/plain\"\n : detected\n return {\n url: `data:${mime};base64,${bytes.toString(\"base64\")}`,\n filename: path.basename(file),\n mime,\n }\n } finally {\n await handle.close()\n }\n}\n\nfunction isBinaryContent(bytes: Uint8Array) {\n if (bytes.length === 0) return false\n if (bytes.includes(0)) return true\n return bytes.reduce((count, byte) => count + Number(byte < 9 || (byte > 13 && byte < 32)), 0) / bytes.length > 0.3\n}\n\nasync function renderTool(part: MiniToolPart) {\n const info = toolInlineInfo(part)\n if (info.mode === \"block\") {\n UI.empty()\n UI.println(UI.Style.TEXT_NORMAL + info.icon, UI.Style.TEXT_NORMAL + info.title)\n if (info.body?.trim()) UI.println(info.body)\n UI.empty()\n return\n }\n UI.println(\n UI.Style.TEXT_NORMAL + info.icon,\n UI.Style.TEXT_NORMAL + info.title,\n info.description ? UI.Style.TEXT_DIM + info.description + UI.Style.TEXT_NORMAL : \"\",\n )\n}\n\nasync function renderToolError(part: MiniToolPart) {\n const info = toolInlineInfo(part)\n UI.println(UI.Style.TEXT_NORMAL + \"✗\", UI.Style.TEXT_NORMAL + `${info.title} failed`)\n}\n\nfunction warning(message: string) {\n UI.println(UI.Style.TEXT_WARNING_BOLD + \"!\", UI.Style.TEXT_NORMAL, message)\n}\n\nfunction reportError(input: RunCommandInput, message: string, sessionID?: string) {\n process.exitCode = 1\n if (input.format === \"json\") {\n process.stdout.write(\n JSON.stringify({\n type: \"error\",\n timestamp: Date.now(),\n sessionID: sessionID ?? \"\",\n error: { type: \"unknown\", message },\n }) + \"\\n\",\n )\n return\n }\n UI.error(message)\n}\n\nfunction fail(message: string): never {\n throw new Error(message)\n}\n", | ||
| "import type { EventSubscribeOutput, OpenCodeClient } from \"@opencode-ai/client/promise\"\nimport { SessionMessage } from \"@opencode-ai/schema/session-message\"\nimport { EOL } from \"node:os\"\nimport { UI } from \"./ui\"\nimport type { MiniToolPart } from \"./types\"\n\ntype Model = {\n providerID: string\n modelID: string\n}\n\ntype File = {\n url: string\n filename: string\n mime: string\n}\n\ntype Input = {\n client: OpenCodeClient\n sessionID: string\n message: string\n files: File[]\n agent?: string\n model?: Model\n variant?: string\n thinking: boolean\n format: \"default\" | \"json\"\n auto: boolean\n /** True when the client is attached to a shared server rather than an exclusive in-process one. */\n attached: boolean\n renderTool: (part: MiniToolPart) => Promise<void>\n renderToolError: (part: MiniToolPart) => Promise<void>\n}\n\ntype StartedPart = {\n id: string\n timestamp: number\n}\n\ntype ToolState = StartedPart & {\n assistantMessageID: string\n tool: string\n input: Record<string, unknown>\n raw?: string\n provider?: unknown\n}\n\ntype V2Event = EventSubscribeOutput\ntype FormRequest = Extract<V2Event, { type: \"form.created\" }>[\"data\"][\"form\"]\n\n// MCP elicitations are temporarily owned by the \"global\" sentinel instead of a real\n// session. An exclusive local process may treat them as this run's blockers; an\n// attached client must not cancel input that may belong to another session.\nconst GLOBAL_FORM_SESSION_ID = \"global\"\n\nexport async function runNonInteractivePrompt(input: Input) {\n const controller = new AbortController()\n const stream = input.client.event.subscribe({ signal: controller.signal })[Symbol.asyncIterator]()\n const connected = await stream.next()\n if (connected.done) throw new Error(\"Event stream disconnected before prompt admission\")\n\n const messageID = SessionMessage.ID.create()\n const starts = new Map<string, StartedPart>()\n const tools = new Map<string, ToolState>()\n let submitted = false\n let promoted = false\n let emittedError = false\n let questionRejected = false\n let permissionRejected = false\n let formCancelled = false\n let interrupted = false\n let admission: AbortController | undefined\n\n const emit = (type: string, timestamp: number, data: Record<string, unknown>) => {\n if (input.format !== \"json\") return false\n process.stdout.write(JSON.stringify({ type, timestamp, sessionID: input.sessionID, ...data }) + EOL)\n return true\n }\n\n const writeText = (part: { text: string; [key: string]: unknown }, timestamp: number) => {\n if (emit(\"text\", timestamp, { part })) return\n const text = part.text.trim()\n if (!text) return\n if (!process.stdout.isTTY) {\n process.stdout.write(text + EOL)\n return\n }\n UI.empty()\n UI.println(text)\n UI.empty()\n }\n\n const replyPermission = async (request: { id: string; action: string; resources: ReadonlyArray<string> }) => {\n if (!input.auto) {\n permissionRejected = true\n UI.println(\n UI.Style.TEXT_WARNING_BOLD + \"!\",\n UI.Style.TEXT_NORMAL +\n `permission requested: ${request.action} (${request.resources.join(\", \")}); auto-rejecting`,\n )\n }\n await input.client.permission\n .reply({\n sessionID: input.sessionID,\n requestID: request.id,\n reply: input.auto ? \"once\" : \"reject\",\n })\n .catch(() => {})\n if (!input.auto) {\n await input.client.session.interrupt({ sessionID: input.sessionID }).catch(() => {})\n }\n }\n\n const rejectQuestion = async (request: { id: string }) => {\n questionRejected = true\n await input.client.question.reject({ sessionID: input.sessionID, requestID: request.id }).catch(() => {})\n }\n\n const cancelForm = async (request: Pick<FormRequest, \"id\" | \"sessionID\">) => {\n formCancelled = true\n await input.client.form.cancel({ sessionID: request.sessionID, formID: request.id }).catch(() => {})\n }\n\n const consume = async () => {\n while (!controller.signal.aborted) {\n const next = await stream.next().catch((error) => {\n if (!emittedError) throw error\n return { done: true as const, value: undefined }\n })\n if (next.done) {\n if (emittedError) return\n throw new Error(\"Event stream disconnected during prompt execution\")\n }\n const event = next.value\n\n if (event.type === \"permission.v2.asked\" && submitted && event.data.sessionID === input.sessionID) {\n await replyPermission(event.data)\n continue\n }\n if (event.type === \"question.v2.asked\" && submitted && event.data.sessionID === input.sessionID) {\n await rejectQuestion(event.data)\n continue\n }\n if (\n event.type === \"form.created\" &&\n submitted &&\n (event.data.form.sessionID === input.sessionID ||\n (!input.attached && event.data.form.sessionID === GLOBAL_FORM_SESSION_ID))\n ) {\n await cancelForm(event.data.form)\n continue\n }\n if (!(\"sessionID\" in event.data) || event.data.sessionID !== input.sessionID) continue\n const time = toMillis(\"created\" in event ? event.created : undefined)\n\n if (event.type === \"session.input.promoted\") {\n if (event.data.inputID === messageID) {\n promoted = true\n continue\n }\n }\n if (\n event.type === \"session.execution.interrupted\" &&\n event.data.reason === \"user\" &&\n (interrupted || permissionRejected || questionRejected || formCancelled)\n ) {\n return\n }\n if (!promoted) continue\n\n if (event.type === \"session.step.started\") {\n const part = {\n id: partID(event.id),\n sessionID: input.sessionID,\n messageID: event.data.assistantMessageID,\n type: \"step-start\",\n snapshot: event.data.snapshot,\n }\n if (!emit(\"step_start\", time, { part }) && input.format !== \"json\") {\n UI.empty()\n UI.println(`> ${event.data.agent} · ${event.data.model.id}`)\n UI.empty()\n }\n continue\n }\n\n if (event.type === \"session.text.started\") {\n starts.set(\"text\", { id: partID(event.id), timestamp: time })\n continue\n }\n if (event.type === \"session.text.ended\") {\n const started = starts.get(\"text\")\n starts.delete(\"text\")\n const part = {\n id: started?.id ?? partID(event.id),\n sessionID: input.sessionID,\n messageID: event.data.assistantMessageID,\n type: \"text\",\n text: event.data.text,\n time: { start: started?.timestamp ?? time, end: time },\n }\n writeText(part, time)\n continue\n }\n\n if (event.type === \"session.reasoning.started\") {\n starts.set(\"reasoning\", { id: partID(event.id), timestamp: time })\n continue\n }\n if (event.type === \"session.reasoning.ended\" && input.thinking) {\n const started = starts.get(\"reasoning\")\n starts.delete(\"reasoning\")\n const part = {\n id: started?.id ?? partID(event.id),\n sessionID: input.sessionID,\n messageID: event.data.assistantMessageID,\n type: \"reasoning\",\n text: event.data.text,\n metadata: event.data.state,\n time: { start: started?.timestamp ?? time, end: time },\n }\n if (emit(\"reasoning\", time, { part })) continue\n const text = part.text.trim()\n if (!text) continue\n const line = `Thinking: ${text}`\n if (!process.stdout.isTTY) {\n process.stdout.write(line + EOL)\n continue\n }\n UI.empty()\n UI.println(`${UI.Style.TEXT_DIM}\\u001b[3m${line}\\u001b[0m${UI.Style.TEXT_NORMAL}`)\n UI.empty()\n continue\n }\n\n if (event.type === \"session.tool.input.started\") {\n tools.set(event.data.callID, {\n id: partID(event.id),\n timestamp: time,\n assistantMessageID: event.data.assistantMessageID,\n tool: event.data.name,\n input: {},\n })\n continue\n }\n if (event.type === \"session.tool.input.ended\") {\n const current = tools.get(event.data.callID)\n if (current) current.raw = event.data.text\n continue\n }\n if (event.type === \"session.tool.called\") {\n const current = tools.get(event.data.callID)\n tools.set(event.data.callID, {\n id: current?.id ?? partID(event.id),\n timestamp: current?.timestamp ?? time,\n assistantMessageID: event.data.assistantMessageID,\n tool: current?.tool ?? \"tool\",\n input: event.data.input,\n raw: current?.raw,\n provider: { executed: event.data.executed, state: event.data.state },\n })\n continue\n }\n if (event.type === \"session.tool.success\") {\n const current = tools.get(event.data.callID) ?? fallbackTool(event)\n const part: MiniToolPart = {\n id: current.id,\n sessionID: input.sessionID,\n messageID: event.data.assistantMessageID,\n type: \"tool\",\n callID: event.data.callID,\n tool: current.tool,\n state: {\n status: \"completed\",\n input: current.input,\n output: event.data.content\n .filter((item) => item.type === \"text\")\n .map((item) => item.text)\n .join(\"\\n\"),\n title: current.tool,\n metadata: {\n structured: event.data.structured,\n content: event.data.content,\n result: event.data.result,\n providerCall: current.provider,\n providerResult: { executed: event.data.executed, state: event.data.resultState },\n rawInput: current.raw,\n },\n time: { start: current.timestamp, end: time },\n },\n }\n tools.delete(event.data.callID)\n if (!emit(\"tool_use\", time, { part })) await input.renderTool(part)\n continue\n }\n if (event.type === \"session.tool.failed\") {\n const current = tools.get(event.data.callID) ?? fallbackTool(event)\n const error = event.data.error.message\n const part: MiniToolPart = {\n id: current.id,\n sessionID: input.sessionID,\n messageID: event.data.assistantMessageID,\n type: \"tool\",\n callID: event.data.callID,\n tool: current.tool,\n state: {\n status: \"error\",\n input: current.input,\n error,\n metadata: {\n result: event.data.result,\n providerCall: current.provider,\n providerResult: { executed: event.data.executed, state: event.data.resultState },\n rawInput: current.raw,\n },\n time: { start: current.timestamp, end: time },\n },\n }\n tools.delete(event.data.callID)\n if (!emit(\"tool_use\", time, { part })) {\n await input.renderToolError(part)\n UI.error(error)\n }\n continue\n }\n\n if (event.type === \"session.step.ended\") {\n const part = {\n id: partID(event.id),\n sessionID: input.sessionID,\n messageID: event.data.assistantMessageID,\n type: \"step-finish\",\n reason: event.data.finish,\n snapshot: event.data.snapshot,\n cost: event.data.cost,\n tokens: event.data.tokens,\n }\n emit(\"step_finish\", time, { part })\n continue\n }\n if (event.type === \"session.step.failed\") {\n if (interrupted || permissionRejected || questionRejected || formCancelled) continue\n emittedError = true\n process.exitCode = 1\n if (!emit(\"error\", time, { error: event.data.error })) UI.error(event.data.error.message)\n continue\n }\n if (event.type === \"session.execution.failed\") {\n if (!emittedError && !questionRejected && !formCancelled) {\n emittedError = true\n process.exitCode = 1\n if (!emit(\"error\", time, { error: event.data.error })) UI.error(event.data.error.message)\n }\n return\n }\n if (event.type === \"session.execution.interrupted\") {\n if (event.data.reason === \"user\" && interrupted) process.exitCode = 130\n if (event.data.reason !== \"user\" && !emittedError) {\n emittedError = true\n process.exitCode = 1\n const error = { type: \"aborted\" as const, message: `Session interrupted: ${event.data.reason}` }\n if (!emit(\"error\", time, { error })) UI.error(error.message)\n }\n return\n }\n if (event.type === \"session.execution.succeeded\") return\n }\n }\n\n const interrupt = () => {\n if (interrupted) process.exit(130)\n interrupted = true\n process.exitCode = 130\n admission?.abort()\n void input.client.session.interrupt({ sessionID: input.sessionID }).catch(() => {})\n }\n process.on(\"SIGINT\", interrupt)\n\n let completed: Promise<void> | undefined\n try {\n if (input.agent) {\n await input.client.session.switchAgent({ sessionID: input.sessionID, agent: input.agent })\n }\n const selected = input.model\n ? { providerID: input.model.providerID, id: input.model.modelID, variant: input.variant }\n : input.variant\n ? await input.client.session\n .get({ sessionID: input.sessionID })\n .then((result) => result.model)\n .then(async (model) => {\n if (model) return { ...model, variant: input.variant }\n const result = await input.client.model.default()\n const fallback = result.data\n return fallback ? { providerID: fallback.providerID, id: fallback.id, variant: input.variant } : undefined\n })\n : undefined\n if (input.variant && !selected) throw new Error(\"Cannot select a variant before selecting a model\")\n if (selected) {\n await input.client.session.switchModel({ sessionID: input.sessionID, model: selected })\n }\n\n const prepared = await Promise.all(input.files.map(prepareFile))\n if (interrupted) return\n submitted = true\n completed = consume()\n admission = new AbortController()\n const response = await input.client.session\n .prompt(\n {\n sessionID: input.sessionID,\n id: messageID,\n text: [input.message, ...prepared.flatMap((file) => (file.text ? [file.text] : []))].join(\"\\n\\n\"),\n files: prepared.flatMap((file) => (file.attachment ? [file.attachment] : [])),\n delivery: \"steer\",\n },\n { signal: admission.signal },\n )\n .catch(async (error) => {\n if (interrupted) {\n await input.client.session.interrupt({ sessionID: input.sessionID }).catch(() => {})\n }\n controller.abort()\n await completed?.catch(() => {})\n if (interrupted || emittedError) return undefined\n throw error\n })\n admission = undefined\n if (!response) return\n if (interrupted) await input.client.session.interrupt({ sessionID: input.sessionID }).catch(() => {})\n\n const [permissions, questions, forms] = await Promise.all([\n input.client.permission.list({ sessionID: input.sessionID }).catch(() => undefined),\n input.client.question.list({ sessionID: input.sessionID }).catch(() => undefined),\n Promise.all(\n (input.attached ? [input.sessionID] : [input.sessionID, GLOBAL_FORM_SESSION_ID]).map((sessionID) =>\n input.client.form.list({ sessionID }).catch(() => undefined),\n ),\n ),\n ])\n await Promise.all([\n ...(permissions ?? []).map(replyPermission),\n ...(questions ?? []).map(rejectQuestion),\n ...forms.flatMap((response) => response ?? []).map(cancelForm),\n ])\n await completed\n } finally {\n process.off(\"SIGINT\", interrupt)\n controller.abort()\n await stream.return?.(undefined).catch(() => {})\n }\n}\n\nfunction partID(eventID: string) {\n return `prt_${eventID.replace(/^evt_/, \"\")}`\n}\n\nfunction fallbackTool(event: {\n id: string\n created: number\n data: { assistantMessageID: string; callID: string }\n}): ToolState {\n return {\n id: partID(event.id),\n timestamp: toMillis(event.created),\n assistantMessageID: event.data.assistantMessageID,\n tool: \"tool\",\n input: {},\n }\n}\n\nfunction toMillis(value: unknown) {\n if (typeof value === \"number\") return value\n if (typeof value === \"string\") return new Date(value).getTime()\n return Date.now()\n}\n\nasync function prepareFile(file: File) {\n if (file.mime !== \"text/plain\") {\n const uri = file.url.startsWith(\"data:\")\n ? file.url\n : `data:${file.mime};base64,${Buffer.from(await Bun.file(new URL(file.url)).arrayBuffer()).toString(\"base64\")}`\n return { attachment: { uri, mime: file.mime, name: file.filename } }\n }\n const content = file.url.startsWith(\"data:\")\n ? Buffer.from(file.url.slice(file.url.indexOf(\",\") + 1), \"base64\").toString(\"utf8\")\n : await Bun.file(new URL(file.url)).text()\n return { text: `<file name=\"${file.filename}\">\\n${content}\\n</file>` }\n}\n", | ||
| "import { EOL } from \"node:os\"\n\nexport const Style = {\n TEXT_DIM: \"\\x1b[90m\",\n TEXT_NORMAL: \"\\x1b[0m\",\n TEXT_WARNING_BOLD: \"\\x1b[93m\\x1b[1m\",\n TEXT_DANGER_BOLD: \"\\x1b[91m\\x1b[1m\",\n}\n\nexport function println(...message: string[]) {\n process.stderr.write(message.join(\" \") + EOL)\n}\n\nlet blank = false\n\nexport function empty() {\n if (blank) return\n println(Style.TEXT_NORMAL)\n blank = true\n}\n\nexport function error(message: string) {\n if (message.startsWith(\"Error: \")) message = message.slice(\"Error: \".length)\n println(Style.TEXT_DANGER_BOLD + \"Error: \" + Style.TEXT_NORMAL + message)\n}\n\nexport * as UI from \"./ui\"\n" | ||
| ], | ||
| "mappings": ";4uBAsBA,oBAAsB,OAAO,MAAC,OAAyB,MACrD,QAAS,MAAK,OACd,SAAM,OAAe,OAAW,aAAQ,WAAM,WAAQ,YAAY,WAAM,SAAI,MAAM,KAAK,EAAG,EAAM,MAAM,EAChG,EAAqB,yCACrB,EAAY,GAAe,EAEjC,GAAI,CACF,IAAM,EAAM,EAAS,KAAK,CACxB,QAAS,EAAM,OAAO,SAAS,IAC/B,QAAS,EAAQ,QAAQ,EAAM,OAAO,QAAQ,CAChD,CAAC,EACK,EAAQ,GAAW,EAAM,KAAK,EAChC,EACE,EAAe,IAAM,CAEzB,OADA,IAAc,GAAc,EAAK,EAAW,EAAM,KAAK,EAChD,GAEH,EAAiB,SAAY,CACjC,IAAO,EAAO,GAAY,MAAM,QAAQ,IAAI,CAAC,EAAa,EAAG,GAAc,EAA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ChC,GAAI,EAAK,OAAS,QAAS,CAGzB,GAFA,EAAG,MAAM,EACT,EAAG,QAAQ,EAAG,MAAM,YAAc,EAAK,KAAM,EAAG,MAAM,YAAc,EAAK,KAAK,EAC1E,EAAK,MAAM,KAAK,EAAG,EAAG,QAAQ,EAAK,IAAI,EAC3C,EAAG,MAAM,EACT,OAEF,EAAG,QACD,EAAG,MAAM,YAAc,EAAK,KAC5B,EAAG,MAAM,YAAc,EAAK,MAC5B,EAAK,YAAc,EAAG,MAAM,SAAW,EAAK,YAAc,EAAG,MAAM,YAAc,EACnF,EAGF,eAAe,EAAe,CAAC,EAAoB,CACjD,IAAM,EAAO,EAAe,CAAI,EAChC,EAAG,QAAQ,EAAG,MAAM,YAAc,SAAI,EAAG,MAAM,YAAc,GAAG,EAAK,cAAc,EAGrF,SAAS,CAAO,CAAC,EAAiB,CAChC,EAAG,QAAQ,EAAG,MAAM,kBAAoB,IAAK,EAAG,MAAM,YAAa,CAAO,EAG5E,SAAS,CAAW,CAAC,EAAwB,EAAiB,EAAoB,CAEhF,GADA,QAAQ,SAAW,EACf,EAAM,SAAW,OAAQ,CAC3B,QAAQ,OAAO,MACb,KAAK,UAAU,CACb,KAAM,QACN,UAAW,KAAK,IAAI,EACpB,UAAW,GAAa,GACxB,MAAO,CAAE,KAAM,UAAW,SAAQ,CACpC,CAAC,EAAI;AAAA,CACP,EACA,OAEF,EAAG,MAAM,CAAO,EAGlB,SAAS,CAAI,CAAC,EAAwB,CACpC,MAAU,MAAM,CAAO", | ||
| "debugId": "44A6376B61BED99864756E2164756E21", | ||
| "names": [] | ||
| } |
| { | ||
| "version": 3, | ||
| "sources": ["src/mini/variant.shared.ts", "src/mini/session.shared.ts", "src/mini/theme.ts"], | ||
| "sourcesContent": [ | ||
| "// Model variant resolution and persistence.\n//\n// Variants are provider-specific reasoning effort levels (e.g., \"high\", \"max\").\n// Resolution priority: CLI --variant flag > saved preference > session history.\n//\n// The saved variant persists across sessions in ~/.local/state/opencode/model.json\n// so your last-used variant sticks. Cycling (ctrl+t) updates both the active\n// variant and the persisted file.\nimport path from \"path\"\nimport { FSUtil } from \"@opencode-ai/core/fs-util\"\nimport { AppNodeBuilder } from \"@opencode-ai/core/effect/app-node-builder\"\nimport { Context, Effect, Layer } from \"effect\"\nimport { LayerNode } from \"@opencode-ai/core/effect/layer-node\"\nimport { makeGlobalNode } from \"@opencode-ai/core/effect/app-node\"\nimport { makeRuntime } from \"@opencode-ai/core/effect/runtime\"\nimport { Global } from \"@opencode-ai/core/global\"\nimport { createSession, sessionVariant, type RunSession, type SessionMessages } from \"./session.shared\"\nimport type { RunInput, RunProvider } from \"./types\"\n\nconst MODEL_FILE = path.join(Global.Path.state, \"model.json\")\n\ntype ModelState = Record<string, unknown> & {\n variant?: Record<string, string | undefined>\n}\ntype VariantService = {\n readonly resolveSavedVariant: (model: RunInput[\"model\"]) => Effect.Effect<string | undefined>\n readonly saveVariant: (model: RunInput[\"model\"], variant: string | undefined) => Effect.Effect<void>\n}\ntype VariantRuntime = {\n resolveSavedVariant(model: RunInput[\"model\"]): Promise<string | undefined>\n saveVariant(model: RunInput[\"model\"], variant: string | undefined): Promise<void>\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return !!value && typeof value === \"object\" && !Array.isArray(value)\n}\n\nclass Service extends Context.Service<Service, VariantService>()(\"@opencode/RunVariant\") {}\n\nfunction modelKey(provider: string, model: string): string {\n return `${provider}/${model}`\n}\n\nfunction variantKey(model: NonNullable<RunInput[\"model\"]>): string {\n return modelKey(model.providerID, model.modelID)\n}\n\nexport function modelInfo(providers: RunProvider[] | undefined, model: NonNullable<RunInput[\"model\"]>) {\n const provider = providers?.find((item) => item.id === model.providerID)\n return {\n provider: provider?.name ?? model.providerID,\n model: provider?.models[model.modelID]?.name ?? model.modelID,\n }\n}\n\nexport function formatModelLabel(\n model: NonNullable<RunInput[\"model\"]>,\n variant: string | undefined,\n providers?: RunProvider[],\n): string {\n const names = modelInfo(providers, model)\n const label = variant ? ` · ${variant}` : \"\"\n return `${names.model} · ${names.provider}${label}`\n}\n\nexport function cycleVariant(current: string | undefined, variants: string[]): string | undefined {\n if (variants.length === 0) {\n return undefined\n }\n\n if (!current) {\n return variants[0]\n }\n\n const idx = variants.indexOf(current)\n if (idx === -1 || idx === variants.length - 1) {\n return undefined\n }\n\n return variants[idx + 1]\n}\n\nexport function pickVariant(model: RunInput[\"model\"], input: RunSession | SessionMessages): string | undefined {\n return sessionVariant(Array.isArray(input) ? createSession(input) : input, model)\n}\n\nfunction fitVariant(value: string | undefined, variants: string[]): string | undefined {\n if (!value) {\n return undefined\n }\n\n if (variants.length === 0 || variants.includes(value)) {\n return value\n }\n\n return undefined\n}\n\n// Picks the active variant. CLI flag wins, then saved preference, then session\n// history. fitVariant() checks saved and session values against the available\n// variants list -- if the provider doesn't offer a variant, it drops.\nexport function resolveVariant(\n input: string | undefined,\n session: string | undefined,\n saved: string | undefined,\n variants: string[],\n): string | undefined {\n if (input !== undefined) {\n return input\n }\n\n const fallback = fitVariant(saved, variants)\n const current = fitVariant(session, variants)\n if (current !== undefined) {\n return current\n }\n\n return fallback\n}\n\nfunction state(value: unknown): ModelState {\n if (!isRecord(value)) {\n return {}\n }\n\n const variant = isRecord(value.variant)\n ? Object.fromEntries(\n Object.entries(value.variant).flatMap(([key, item]) => {\n if (typeof item !== \"string\") {\n return []\n }\n\n return [[key, item] as const]\n }),\n )\n : undefined\n\n return {\n ...value,\n variant,\n }\n}\n\nconst layer = Layer.fresh(\n Layer.effect(\n Service,\n Effect.gen(function* () {\n const file = yield* FSUtil.Service\n\n const read = Effect.fn(\"RunVariant.read\")(function* () {\n return yield* file.readJson(MODEL_FILE).pipe(\n Effect.map(state),\n Effect.catchCause(() => Effect.succeed(state(undefined))),\n )\n })\n\n const resolveSavedVariant = Effect.fn(\"RunVariant.resolveSavedVariant\")(function* (model: RunInput[\"model\"]) {\n if (!model) {\n return undefined\n }\n\n return (yield* read()).variant?.[variantKey(model)]\n })\n\n const saveVariant = Effect.fn(\"RunVariant.saveVariant\")(function* (\n model: RunInput[\"model\"],\n variant: string | undefined,\n ) {\n if (!model) {\n return\n }\n\n const current = yield* read()\n const next = {\n ...current.variant,\n }\n const key = variantKey(model)\n if (variant) {\n next[key] = variant\n }\n\n if (!variant) {\n delete next[key]\n }\n\n yield* file\n .writeJson(MODEL_FILE, {\n ...current,\n variant: next,\n })\n .pipe(Effect.orElseSucceed(() => undefined))\n })\n\n return Service.of({\n resolveSavedVariant,\n saveVariant,\n })\n }),\n ),\n)\n\nconst node = makeGlobalNode({ service: Service, layer, deps: [FSUtil.node] })\n\n/** @internal Exported for testing. */\nexport function createVariantRuntime(replacements?: readonly LayerNode.Replacement[]): VariantRuntime {\n const runtime = makeRuntime(Service, AppNodeBuilder.build(node, replacements))\n return {\n resolveSavedVariant: (model) => runtime.runPromise((svc) => svc.resolveSavedVariant(model)).catch(() => undefined),\n saveVariant: (model, variant) => runtime.runPromise((svc) => svc.saveVariant(model, variant)).catch(() => {}),\n }\n}\n\nconst runtime = createVariantRuntime()\n\nexport async function resolveSavedVariant(model: RunInput[\"model\"]): Promise<string | undefined> {\n return runtime.resolveSavedVariant(model)\n}\n\nexport function saveVariant(model: RunInput[\"model\"], variant: string | undefined): void {\n void runtime.saveVariant(model, variant)\n}\n", | ||
| "import type { SessionMessageInfo, SessionMessageUser } from \"@opencode-ai/client/promise\"\nimport { promptCopy, promptSame } from \"./prompt.shared\"\nimport type { RunInput, RunPrompt } from \"./types\"\n\nconst LIMIT = 200\n\nexport type SessionMessages = SessionMessageInfo[]\n\ntype Turn = {\n prompt: RunPrompt\n provider: string | undefined\n model: string | undefined\n variant: string | undefined\n}\n\nexport type RunSession = {\n first: boolean\n turns: Turn[]\n model?: NonNullable<RunInput[\"model\"]>\n variant?: string\n}\n\nfunction messagePrompt(message: SessionMessageUser): RunPrompt {\n return {\n text: message.text,\n parts: [\n ...(message.files ?? []).map((file) => ({\n type: \"file\" as const,\n url: file.source.type === \"uri\" ? file.source.uri : `data:${file.mime};base64,${file.data}`,\n mime: file.mime,\n filename: file.name,\n source: file.mention\n ? {\n type: \"file\",\n path: file.name ?? (file.source.type === \"uri\" ? file.source.uri : \"inline attachment\"),\n text: { start: file.mention.start, end: file.mention.end, value: file.mention.text },\n }\n : undefined,\n })),\n ...(message.agents ?? []).map((agent) => ({\n type: \"agent\" as const,\n name: agent.name,\n source: agent.mention\n ? { start: agent.mention.start, end: agent.mention.end, value: agent.mention.text }\n : undefined,\n })),\n ],\n }\n}\n\nexport function createSession(messages: SessionMessages): RunSession {\n return {\n first: messages.length === 0,\n turns: messages.flatMap((message) =>\n message.type === \"user\"\n ? [{ prompt: messagePrompt(message), provider: undefined, model: undefined, variant: undefined }]\n : [],\n ),\n }\n}\n\nexport async function resolveCurrentSession(\n sdk: RunInput[\"sdk\"],\n sessionID: string,\n limit = LIMIT,\n): Promise<RunSession> {\n const [response, session] = await Promise.all([\n sdk.message.list({ sessionID, limit, order: \"desc\" }),\n sdk.session.get({ sessionID }),\n ])\n const current = createSession(response.data.toReversed())\n return {\n ...current,\n turns: current.turns.map((turn) => ({\n ...turn,\n provider: session.model?.providerID,\n model: session.model?.id,\n variant: session.model?.variant,\n })),\n ...(session.model && {\n model: { providerID: session.model.providerID, modelID: session.model.id },\n variant: session.model.variant,\n }),\n }\n}\n\nexport function sessionHistory(session: RunSession, limit = LIMIT): RunPrompt[] {\n return session.turns\n .map((turn) => turn.prompt)\n .filter((prompt) => prompt.text.trim())\n .filter((prompt, index, prompts) => index === 0 || !promptSame(prompts[index - 1], prompt))\n .map(promptCopy)\n .slice(-limit)\n}\n\nexport function sessionVariant(session: RunSession, model: RunInput[\"model\"]): string | undefined {\n if (!model) return\n if (session.model?.providerID === model.providerID && session.model.modelID === model.modelID) return session.variant\n\n return session.turns.findLast((turn) => turn.provider === model.providerID && turn.model === model.modelID)?.variant\n}\n", | ||
| "// Theme resolution for direct interactive mode.\n//\n// Derives scrollback and footer colors from the terminal's actual palette.\n// resolveRunTheme() queries the renderer for the terminal's palette,\n// detects dark/light mode, builds a small system theme locally, and maps it to\n// the run footer + scrollback color model. Falls back to a hardcoded dark-mode\n// palette if detection fails.\nimport { RGBA, SyntaxStyle, type CliRenderer, type ColorInput, type TerminalColors } from \"@opentui/core\"\nimport type { TuiThemeCurrent } from \"@opencode-ai/plugin/tui\"\nimport type { EntryKind } from \"./types\"\n\ntype Tone = {\n body: ColorInput\n start?: ColorInput\n}\n\nexport type RunEntryTheme = Record<EntryKind, Tone>\n\nexport type RunSplashTheme = {\n left: ColorInput\n right: ColorInput\n leftShadow: ColorInput\n rightShadow: ColorInput\n}\n\nexport type RunFooterTheme = {\n highlight: ColorInput\n selected: ColorInput\n selectedText: ColorInput\n warning: ColorInput\n success: ColorInput\n error: ColorInput\n muted: ColorInput\n text: ColorInput\n status: ColorInput\n statusAccent: ColorInput\n shade: ColorInput\n surface: ColorInput\n pane: ColorInput\n border: ColorInput\n line: ColorInput\n}\n\nexport type RunBlockTheme = {\n highlight: ColorInput\n warning: ColorInput\n text: ColorInput\n muted: ColorInput\n syntax?: SyntaxStyle\n diffAdded: ColorInput\n diffRemoved: ColorInput\n diffAddedBg: ColorInput\n diffRemovedBg: ColorInput\n diffContextBg: ColorInput\n diffHighlightAdded: ColorInput\n diffHighlightRemoved: ColorInput\n diffLineNumber: ColorInput\n diffAddedLineNumberBg: ColorInput\n diffRemovedLineNumberBg: ColorInput\n}\n\nexport type RunTheme = {\n background: ColorInput\n footer: RunFooterTheme\n entry: RunEntryTheme\n splash: RunSplashTheme\n block: RunBlockTheme\n}\n\ntype ThemeColor = Exclude<keyof TuiThemeCurrent, \"thinkingOpacity\">\ntype HexColor = `#${string}`\ntype RefName = string\ntype Variant = {\n dark: HexColor | RefName\n light: HexColor | RefName\n}\ntype ColorValue = HexColor | RefName | Variant | RGBA | number\ntype ThemeJson = {\n defs?: Record<string, HexColor | RefName>\n theme: Omit<Record<ThemeColor, ColorValue>, \"selectedListItemText\" | \"backgroundMenu\"> & {\n selectedListItemText?: ColorValue\n backgroundMenu?: ColorValue\n thinkingOpacity?: number\n }\n}\n\ntype SharedSyntaxTheme = TuiThemeCurrent & {\n _hasSelectedListItemText: boolean\n}\n\nexport const transparent = RGBA.fromValues(0, 0, 0, 0)\n\nfunction alpha(color: RGBA, value: number): RGBA {\n return RGBA.fromValues(color.r, color.g, color.b, Math.max(0, Math.min(1, value)))\n}\n\nfunction rgba(hex: string, value?: number): RGBA {\n const color = RGBA.fromHex(hex)\n return value === undefined ? color : alpha(color, value)\n}\n\nfunction mode(bg: RGBA): \"dark\" | \"light\" {\n return luminance(bg) > 0.5 ? \"light\" : \"dark\"\n}\n\nfunction luminance(color: RGBA): number {\n return 0.299 * color.r + 0.587 * color.g + 0.114 * color.b\n}\n\nfunction fade(color: RGBA, base: RGBA, fallback: number, scale: number, limit: number): RGBA {\n if (color.a === 0) {\n return RGBA.fromValues(color.r, color.g, color.b, Math.max(0, Math.min(1, fallback)))\n }\n\n const target = Math.min(limit, color.a * scale)\n const mix = Math.min(1, target / color.a)\n\n return RGBA.fromValues(\n base.r + (color.r - base.r) * mix,\n base.g + (color.g - base.g) * mix,\n base.b + (color.b - base.b) * mix,\n color.a,\n )\n}\n\nfunction ansiToRgba(code: number): RGBA {\n if (code < 16) {\n const ansi = [\n \"#000000\",\n \"#800000\",\n \"#008000\",\n \"#808000\",\n \"#000080\",\n \"#800080\",\n \"#008080\",\n \"#c0c0c0\",\n \"#808080\",\n \"#ff0000\",\n \"#00ff00\",\n \"#ffff00\",\n \"#0000ff\",\n \"#ff00ff\",\n \"#00ffff\",\n \"#ffffff\",\n ]\n return RGBA.fromHex(ansi[code] ?? \"#000000\")\n }\n\n if (code < 232) {\n const index = code - 16\n const b = index % 6\n const g = Math.floor(index / 6) % 6\n const r = Math.floor(index / 36)\n const value = (x: number) => (x === 0 ? 0 : x * 40 + 55)\n return RGBA.fromInts(value(r), value(g), value(b))\n }\n\n if (code < 256) {\n const gray = (code - 232) * 10 + 8\n return RGBA.fromInts(gray, gray, gray)\n }\n\n return RGBA.fromInts(0, 0, 0)\n}\n\nfunction tint(base: RGBA, overlay: RGBA, value: number): RGBA {\n return RGBA.fromInts(\n Math.round((base.r + (overlay.r - base.r) * value) * 255),\n Math.round((base.g + (overlay.g - base.g) * value) * 255),\n Math.round((base.b + (overlay.b - base.b) * value) * 255),\n )\n}\n\nfunction chroma(color: RGBA) {\n return Math.max(color.r, color.g, color.b) - Math.min(color.r, color.g, color.b)\n}\n\nfunction indexedPalette(colors: TerminalColors, size: number = Math.max(colors.palette.length, 16)): RGBA[] {\n return Array.from({ length: size }, (_, index) => {\n const value = colors.palette[index]\n return RGBA.fromIndex(index, value ? RGBA.fromHex(value) : ansiToRgba(index))\n })\n}\n\nfunction srgbToLinear(value: number): number {\n if (value <= 0.04045) {\n return value / 12.92\n }\n\n return ((value + 0.055) / 1.055) ** 2.4\n}\n\nfunction oklab(color: RGBA) {\n const r = srgbToLinear(color.r)\n const g = srgbToLinear(color.g)\n const b = srgbToLinear(color.b)\n\n const l = Math.cbrt(0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b)\n const m = Math.cbrt(0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b)\n const s = Math.cbrt(0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b)\n\n return {\n l: 0.2104542553 * l + 0.793617785 * m - 0.0040720468 * s,\n a: 1.9779984951 * l - 2.428592205 * m + 0.4505937099 * s,\n b: 0.0259040371 * l + 0.7827717662 * m - 0.808675766 * s,\n }\n}\n\nfunction nearestIndexed(indexed: RGBA[], rgba: RGBA): RGBA {\n const target = oklab(rgba)\n const hit = indexed.reduce(\n (best, item) => {\n const sample = oklab(item)\n const dl = sample.l - target.l\n const da = sample.a - target.a\n const db = sample.b - target.b\n const dist = dl * dl * 2 + da * da + db * db\n if (dist >= best.dist) return best\n return {\n dist,\n item,\n }\n },\n {\n dist: Number.POSITIVE_INFINITY,\n item: indexed[0]!,\n },\n )\n\n return RGBA.clone(hit.item)\n}\n\nfunction paletteColor(colors: TerminalColors, index: number): RGBA {\n const value = colors.palette[index]\n return value ? RGBA.fromHex(value) : ansiToRgba(index)\n}\n\nfunction splashShadow(indexed: RGBA[], base: RGBA, overlay: RGBA, value: number): RGBA {\n const mixed = tint(base, overlay, value)\n return nearestIndexed(indexed, mixed)\n}\n\nexport function resolveTheme(theme: ThemeJson, pick: \"dark\" | \"light\"): TuiThemeCurrent {\n const defs = theme.defs ?? {}\n\n const resolveColor = (value: ColorValue, chain: string[] = []): RGBA => {\n if (value instanceof RGBA) return value\n\n if (typeof value === \"number\") {\n return RGBA.fromIndex(value, ansiToRgba(value))\n }\n\n if (typeof value !== \"string\") {\n return resolveColor(value[pick], chain)\n }\n\n if (value === \"transparent\" || value === \"none\") {\n return RGBA.fromInts(0, 0, 0, 0)\n }\n\n if (value.startsWith(\"#\")) {\n return RGBA.fromHex(value)\n }\n\n if (chain.includes(value)) {\n throw new Error(`Circular color reference: ${[...chain, value].join(\" -> \")}`)\n }\n\n const next = defs[value] ?? theme.theme[value as ThemeColor]\n if (next === undefined) {\n throw new Error(`Color reference \"${value}\" not found in defs or theme`)\n }\n\n return resolveColor(next, [...chain, value])\n }\n\n const resolved = Object.fromEntries(\n Object.entries(theme.theme)\n .filter(([key]) => key !== \"selectedListItemText\" && key !== \"backgroundMenu\" && key !== \"thinkingOpacity\")\n .map(([key, value]) => [key, resolveColor(value as ColorValue)]),\n ) as Partial<Record<ThemeColor, RGBA>>\n\n return {\n ...(resolved as Record<ThemeColor, RGBA>),\n selectedListItemText:\n theme.theme.selectedListItemText === undefined\n ? resolved.background!\n : resolveColor(theme.theme.selectedListItemText),\n backgroundMenu:\n theme.theme.backgroundMenu === undefined ? resolved.backgroundElement! : resolveColor(theme.theme.backgroundMenu),\n thinkingOpacity: theme.theme.thinkingOpacity ?? 0.6,\n }\n}\n\nfunction generateGrayScale(bg: RGBA, isDark: boolean, map: (rgba: RGBA) => RGBA): Record<number, RGBA> {\n const r = bg.r * 255\n const g = bg.g * 255\n const b = bg.b * 255\n const lum = 0.299 * r + 0.587 * g + 0.114 * b\n const cast = 0.25 * (1 - chroma(bg)) ** 2\n\n const gray = (level: number) => {\n const factor = level / 12\n\n if (isDark && lum < 10) {\n const value = Math.floor(factor * 0.4 * 255)\n return map(RGBA.fromInts(value, value, value))\n }\n\n if (!isDark && lum > 245) {\n const value = Math.floor(255 - factor * 0.4 * 255)\n return map(RGBA.fromInts(value, value, value))\n }\n\n const value = isDark ? lum + (255 - lum) * factor * 0.4 : lum * (1 - factor * 0.4)\n const tone = RGBA.fromInts(Math.floor(value), Math.floor(value), Math.floor(value))\n if (cast === 0) return map(tone)\n\n const ratio = lum === 0 ? 0 : value / lum\n return map(\n tint(\n tone,\n RGBA.fromInts(\n Math.floor(Math.max(0, Math.min(r * ratio, 255))),\n Math.floor(Math.max(0, Math.min(g * ratio, 255))),\n Math.floor(Math.max(0, Math.min(b * ratio, 255))),\n ),\n cast,\n ),\n )\n }\n\n return Object.fromEntries(Array.from({ length: 12 }, (_, index) => [index + 1, gray(index + 1)]))\n}\n\nfunction generateMutedTextColor(bg: RGBA, isDark: boolean, map: (rgba: RGBA) => RGBA): RGBA {\n const lum = 0.299 * bg.r * 255 + 0.587 * bg.g * 255 + 0.114 * bg.b * 255\n const gray = isDark\n ? lum < 10\n ? 180\n : Math.min(Math.floor(160 + lum * 0.3), 200)\n : lum > 245\n ? 75\n : Math.max(Math.floor(100 - (255 - lum) * 0.2), 60)\n\n return map(RGBA.fromInts(gray, gray, gray))\n}\n\nexport function generateSystem(colors: TerminalColors, pick: \"dark\" | \"light\"): ThemeJson {\n const bg_snapshot = RGBA.fromHex(colors.defaultBackground ?? colors.palette[0]!)\n const fg_snapshot = RGBA.fromHex(colors.defaultForeground ?? colors.palette[7]!)\n const bg = RGBA.defaultBackground(bg_snapshot)\n const fg = RGBA.defaultForeground(fg_snapshot)\n const isDark = pick === \"dark\"\n\n const color = (index: number) => paletteColor(colors, index)\n\n const grays = generateGrayScale(bg_snapshot, isDark, (rgba) => rgba)\n const textMuted = generateMutedTextColor(bg_snapshot, isDark, (rgba) => rgba)\n\n const ansi = {\n red: color(1),\n green: color(2),\n yellow: color(3),\n blue: color(4),\n magenta: color(5),\n cyan: color(6),\n red_bright: color(9),\n green_bright: color(10),\n }\n\n const diff_alpha = isDark ? 0.22 : 0.14\n const diff_context_bg = grays[2]\n const primary = ansi.cyan\n const secondary = ansi.magenta\n\n return {\n theme: {\n primary,\n secondary,\n accent: primary,\n error: ansi.red,\n warning: ansi.yellow,\n success: ansi.green,\n info: ansi.cyan,\n text: fg,\n textMuted,\n selectedListItemText: bg,\n background: alpha(bg, 0),\n backgroundPanel: grays[2],\n backgroundElement: grays[3],\n backgroundMenu: grays[3],\n borderSubtle: grays[6],\n border: grays[7],\n borderActive: grays[8],\n diffAdded: ansi.green,\n diffRemoved: ansi.red,\n diffContext: grays[7],\n diffHunkHeader: grays[7],\n diffHighlightAdded: ansi.green_bright,\n diffHighlightRemoved: ansi.red_bright,\n diffAddedBg: tint(bg_snapshot, ansi.green, diff_alpha),\n diffRemovedBg: tint(bg_snapshot, ansi.red, diff_alpha),\n diffContextBg: diff_context_bg,\n diffLineNumber: textMuted,\n diffAddedLineNumberBg: tint(diff_context_bg, ansi.green, diff_alpha),\n diffRemovedLineNumberBg: tint(diff_context_bg, ansi.red, diff_alpha),\n markdownText: fg,\n markdownHeading: fg,\n markdownLink: ansi.blue,\n markdownLinkText: ansi.cyan,\n markdownCode: ansi.green,\n markdownBlockQuote: ansi.yellow,\n markdownEmph: ansi.yellow,\n markdownStrong: fg,\n markdownHorizontalRule: grays[7],\n markdownListItem: ansi.blue,\n markdownListEnumeration: ansi.cyan,\n markdownImage: ansi.blue,\n markdownImageText: ansi.cyan,\n markdownCodeBlock: fg,\n syntaxComment: textMuted,\n syntaxKeyword: ansi.magenta,\n syntaxFunction: ansi.blue,\n syntaxVariable: fg,\n syntaxString: ansi.green,\n syntaxNumber: ansi.yellow,\n syntaxType: ansi.cyan,\n syntaxOperator: ansi.cyan,\n syntaxPunctuation: fg,\n },\n }\n}\n\nfunction quantizeColor(indexed: RGBA[], rgba: RGBA): RGBA {\n if (rgba.a === 0 || rgba.intent === \"default\" || rgba.intent === \"indexed\") {\n return RGBA.clone(rgba)\n }\n\n return nearestIndexed(indexed, rgba)\n}\n\nfunction quantizeTheme(theme: TuiThemeCurrent, indexed: RGBA[]): TuiThemeCurrent {\n const resolved = Object.fromEntries(\n Object.entries(theme)\n .filter(([key]) => key !== \"thinkingOpacity\")\n .map(([key, value]) => [key, quantizeColor(indexed, value as RGBA)]),\n ) as Partial<Record<ThemeColor, RGBA>>\n\n return {\n ...(resolved as Record<ThemeColor, RGBA>),\n thinkingOpacity: theme.thinkingOpacity,\n }\n}\n\nfunction splashTheme(theme: TuiThemeCurrent, indexed: RGBA[]): RunSplashTheme {\n const left = nearestIndexed(indexed, theme.textMuted)\n const right = nearestIndexed(indexed, theme.text)\n return {\n left,\n right,\n leftShadow: splashShadow(indexed, theme.background, left, 0.14),\n rightShadow: splashShadow(indexed, theme.background, right, 0.14),\n }\n}\n\nfunction map(\n footerTheme: TuiThemeCurrent,\n scrollbackTheme: TuiThemeCurrent,\n splash: RunSplashTheme,\n syntax?: SyntaxStyle,\n): RunTheme {\n const footerBackground = alpha(footerTheme.background, 1)\n const footerMode = mode(footerBackground)\n const shade = fade(footerTheme.backgroundMenu, footerTheme.background, 0.12, 0.56, 0.72)\n const surface = fade(footerTheme.backgroundMenu, footerTheme.background, 0.18, 0.76, 0.9)\n const line = fade(footerTheme.backgroundMenu, footerTheme.background, 0.24, 0.9, 0.98)\n const statusBase = tint(footerBackground, rgba(\"#000000\"), footerMode === \"dark\" ? 0.12 : 0.06)\n const statusAccentBase =\n footerMode === \"dark\" ? tint(footerBackground, rgba(\"#ffffff\"), 0.06) : tint(statusBase, rgba(\"#000000\"), 0.04)\n const collapsedStatus = footerMode === \"dark\" && luminance(statusBase) <= 0.04\n // Pure-black backgrounds need a slight lift or the row disappears into the terminal background.\n const status = collapsedStatus ? tint(statusBase, statusAccentBase, 0.7) : statusBase\n const statusAccent = collapsedStatus ? tint(status, rgba(\"#ffffff\"), 0.06) : statusAccentBase\n\n return {\n background: footerTheme.background,\n footer: {\n highlight: footerTheme.primary,\n selected: footerTheme.backgroundElement,\n selectedText: footerTheme.selectedListItemText,\n warning: footerTheme.warning,\n success: footerTheme.success,\n error: footerTheme.error,\n muted: footerTheme.textMuted,\n text: footerTheme.text,\n status,\n statusAccent,\n shade,\n surface,\n pane: footerTheme.backgroundMenu,\n border: footerTheme.border,\n line,\n },\n entry: {\n system: {\n body: scrollbackTheme.textMuted,\n },\n user: {\n body: scrollbackTheme.primary,\n },\n assistant: {\n body: scrollbackTheme.text,\n },\n reasoning: {\n body: scrollbackTheme.textMuted,\n },\n tool: {\n body: scrollbackTheme.text,\n start: scrollbackTheme.textMuted,\n },\n error: {\n body: scrollbackTheme.error,\n },\n },\n splash,\n block: {\n highlight: scrollbackTheme.primary,\n warning: scrollbackTheme.warning,\n text: scrollbackTheme.text,\n muted: scrollbackTheme.textMuted,\n syntax,\n diffAdded: scrollbackTheme.diffAdded,\n diffRemoved: scrollbackTheme.diffRemoved,\n diffAddedBg: transparent,\n diffRemovedBg: transparent,\n diffContextBg: transparent,\n diffHighlightAdded: scrollbackTheme.diffHighlightAdded,\n diffHighlightRemoved: scrollbackTheme.diffHighlightRemoved,\n diffLineNumber: scrollbackTheme.diffLineNumber,\n diffAddedLineNumberBg: scrollbackTheme.diffAddedLineNumberBg,\n diffRemovedLineNumberBg: scrollbackTheme.diffRemovedLineNumberBg,\n },\n }\n}\n\nconst seed = {\n highlight: RGBA.fromIndex(6, rgba(\"#38bdf8\")),\n muted: RGBA.fromIndex(8, rgba(\"#64748b\")),\n text: RGBA.defaultForeground(rgba(\"#f8fafc\")),\n panel: rgba(\"#0f172a\"),\n success: RGBA.fromIndex(2, rgba(\"#22c55e\")),\n warning: RGBA.fromIndex(3, rgba(\"#f59e0b\")),\n error: RGBA.fromIndex(1, rgba(\"#ef4444\")),\n}\n\nfunction tone(body: ColorInput, start?: ColorInput): Tone {\n return {\n body,\n start,\n }\n}\n\nconst fallbackSplashIndexed = Array.from({ length: 256 }, (_, index) => RGBA.fromIndex(index))\nconst fallbackSplashLeft = RGBA.fromIndex(67)\nconst fallbackSplashRight = RGBA.fromIndex(110)\n\nexport const RUN_THEME_FALLBACK: RunTheme = {\n background: RGBA.fromValues(0, 0, 0, 0),\n footer: {\n highlight: seed.highlight,\n selected: seed.text,\n selectedText: seed.panel,\n warning: seed.warning,\n success: seed.success,\n error: seed.error,\n muted: seed.muted,\n text: seed.text,\n status: tint(seed.panel, rgba(\"#000000\"), 0.12),\n statusAccent: tint(seed.panel, rgba(\"#ffffff\"), 0.06),\n shade: alpha(seed.panel, 0.68),\n surface: alpha(seed.panel, 0.86),\n pane: seed.panel,\n border: seed.muted,\n line: alpha(seed.panel, 0.96),\n },\n entry: {\n system: tone(seed.muted),\n user: tone(seed.highlight),\n assistant: tone(seed.text),\n reasoning: tone(seed.muted),\n tool: tone(seed.text, seed.muted),\n error: tone(seed.error),\n },\n splash: {\n left: fallbackSplashLeft,\n right: fallbackSplashRight,\n leftShadow: splashShadow(fallbackSplashIndexed, RGBA.fromValues(0, 0, 0, 0), fallbackSplashLeft, 0.14),\n rightShadow: splashShadow(fallbackSplashIndexed, RGBA.fromValues(0, 0, 0, 0), fallbackSplashRight, 0.14),\n },\n block: {\n highlight: seed.highlight,\n warning: seed.warning,\n text: seed.text,\n muted: seed.muted,\n diffAdded: seed.success,\n diffRemoved: seed.error,\n diffAddedBg: alpha(seed.success, 0.18),\n diffRemovedBg: alpha(seed.error, 0.18),\n diffContextBg: alpha(seed.panel, 0.72),\n diffHighlightAdded: seed.success,\n diffHighlightRemoved: seed.error,\n diffLineNumber: seed.muted,\n diffAddedLineNumberBg: alpha(seed.success, 0.12),\n diffRemovedLineNumberBg: alpha(seed.error, 0.12),\n },\n}\n\nexport async function resolveRunTheme(renderer: CliRenderer): Promise<RunTheme> {\n try {\n const colors = await renderer.getPalette({\n size: 256,\n })\n const bg = colors.defaultBackground ?? colors.palette[0]\n if (!bg) {\n return RUN_THEME_FALLBACK\n }\n\n // Palette-only terminal reloads can leave renderer.themeMode stale, but\n // ANSI slot zero is not the terminal background when OSC 11 is absent.\n const pick = colors.defaultBackground\n ? mode(RGBA.fromHex(colors.defaultBackground))\n : (renderer.themeMode ?? mode(RGBA.fromHex(bg)))\n const footerTheme = resolveTheme(generateSystem(colors, pick), pick)\n const indexed = indexedPalette(colors, 256)\n const scrollbackTheme = quantizeTheme(footerTheme, indexed)\n const shared = await import(\"@opencode-ai/tui/context/theme\")\n const syntaxTheme: SharedSyntaxTheme = {\n ...scrollbackTheme,\n _hasSelectedListItemText: true,\n }\n const syntax = shared.generateSyntax(syntaxTheme)\n return map(footerTheme, scrollbackTheme, splashTheme(scrollbackTheme, indexed), syntax)\n } catch {\n return RUN_THEME_FALLBACK\n }\n}\n" | ||
| ], | ||
| "mappings": ";mcAQA,0BCJA,SAAM,OAAQ,SAkBd,cAAS,OAAa,MAAC,OAAwC,CAC7D,MAAO,CACL,KAAM,EAAQ,KACd,MAAO,CACL,IAAI,EAAQ,OAAS,CAAC,GAAG,IAAI,CAAC,KAAU,CACtC,KAAM,OACN,IAAK,EAAK,OAAO,OAAS,MAAQ,EAAK,OAAO,IAAM,QAAQ,EAAK,eAAe,EAAK,OACrF,KAAM,EAAK,KACX,SAAU,EAAK,KACf,OAAQ,EAAK,QACT,CACE,KAAM,OACN,KAAM,EAAK,OAAS,EAAK,OAAO,OAAS,MAAQ,EAAK,OAAO,IAAM,qBACnE,KAAM,CAAE,MAAO,EAAK,QAAQ,MAAO,IAAK,EAAK,QAAQ,IAAK,MAAO,EAAK,QAAQ,IAAK,CACrF,EACA,MACN,EAAE,EACF,IAAI,EAAQ,QAAU,CAAC,GAAG,IAAI,CAAC,KAAW,CACxC,KAAM,QACN,KAAM,EAAM,KACZ,OAAQ,EAA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AW,EAAK,QAChB,YAAa,EAAK,MAClB,YAAa,EAAM,EAAK,QAAS,IAAI,EACrC,cAAe,EAAM,EAAK,MAAO,IAAI,EACrC,cAAe,EAAM,EAAK,MAAO,IAAI,EACrC,mBAAoB,EAAK,QACzB,qBAAsB,EAAK,MAC3B,eAAgB,EAAK,MACrB,sBAAuB,EAAM,EAAK,QAAS,IAAI,EAC/C,wBAAyB,EAAM,EAAK,MAAO,IAAI,CACjD,CACF,EAEA,eAAsB,EAAe,CAAC,EAA0C,CAC9E,GAAI,CACF,IAAM,EAAS,MAAM,EAAS,WAAW,CACvC,KAAM,GACR,CAAC,EACK,EAAK,EAAO,mBAAqB,EAAO,QAAQ,GACtD,GAAI,CAAC,EACH,OAAO,EAKT,IAAM,EAAO,EAAO,kBAChB,EAAK,EAAK,QAAQ,EAAO,iBAAiB,CAAC,EAC1C,EAAS,WAAa,EAAK,EAAK,QAAQ,CAAE,CAAC,EAC1C,EAAc,GAAa,GAAe,EAAQ,CAAI,EAAG,CAAI,EAC7D,EAAU,GAAe,EAAQ,GAAG,EACpC,EAAkB,GAAc,EAAa,CAAO,EACpD,EAAS,KAAa,0CACtB,EAAiC,IAClC,EACH,yBAA0B,EAC5B,EACM,EAAS,EAAO,eAAe,CAAW,EAChD,OAAO,GAAI,EAAa,EAAiB,GAAY,EAAiB,CAAO,EAAG,CAAM,EACtF,KAAM,CACN,OAAO", | ||
| "debugId": "1A5D238C3EFC64B064756E2164756E21", | ||
| "names": [] | ||
| } |
| { | ||
| "version": 3, | ||
| "sources": ["../simulation/src/frontend/actions.ts", "../simulation/src/recording.ts", "../simulation/src/frontend/renderer.ts", "../simulation/src/frontend/server.ts", "../simulation/src/frontend/simulation.ts"], | ||
| "sourcesContent": [ | ||
| "import { tmpdir } from \"node:os\"\nimport { extname, join, resolve } from \"node:path\"\nimport type { CliRenderer, Renderable } from \"@opentui/core\"\nimport { createMockKeys, createMockMouse, type MockInput, type MockMouse } from \"@opentui/core/testing\"\nimport { Config, Effect, FileSystem } from \"effect\"\nimport type { SimulationProtocol } from \"../protocol\"\nimport { SimulationRenderer } from \"./renderer\"\n\nexport type Action = SimulationProtocol.Frontend.Action\nexport type Element = SimulationProtocol.Frontend.Element\n\nexport interface Harness {\n readonly renderer: CliRenderer\n readonly mockInput: MockInput\n readonly mockMouse: MockMouse\n readonly resize: (cols: number, rows: number) => void\n readonly renderOnce: () => Promise<void>\n readonly screen: () => string\n}\n\ntype RenderBuffer = {\n readonly width: number\n readonly height: number\n getRealCharBytes(includeAnsi?: boolean): Uint8Array\n}\n\nconst decoder = new TextDecoder()\n\nfunction children(renderable: Renderable) {\n return renderable.getChildren().filter((child): child is Renderable => \"num\" in child)\n}\n\nfunction all(renderable: Renderable): Renderable[] {\n return [renderable, ...children(renderable).flatMap(all)]\n}\n\nfunction mouseListeners(renderable: Renderable) {\n const general = Reflect.get(renderable, \"_mouseListener\")\n const specific = Reflect.get(renderable, \"_mouseListeners\")\n return Boolean(general) || (specific && typeof specific === \"object\" && Object.keys(specific).length > 0)\n}\n\nfunction hit(renderer: CliRenderer, renderable: Renderable) {\n if (renderable.width <= 0 || renderable.height <= 0) return false\n const x = Math.floor(renderable.screenX + renderable.width / 2)\n const y = Math.floor(renderable.screenY + renderable.height / 2)\n return renderer.hitTest(x, y) === renderable.num\n}\n\n/**\n * Builds the harness the simulation server drives.\n *\n * When the renderer is the headless simulation renderer, its TestRendererSetup\n * provides the supported testing APIs. For the visible terminal renderer the\n * harness falls back to `requestRender` + `idle` and reading the private\n * `currentRenderBuffer`.\n */\nexport function createHarness(renderer: CliRenderer): Harness {\n const setup = SimulationRenderer.setupFor(renderer)\n return {\n renderer,\n mockInput: setup?.mockInput ?? createMockKeys(renderer),\n mockMouse: setup?.mockMouse ?? createMockMouse(renderer),\n resize: setup?.resize ?? ((cols, rows) => renderer.resize(cols, rows)),\n renderOnce:\n setup?.renderOnce ??\n (async () => {\n renderer.requestRender()\n await renderer.idle()\n }),\n // captureCharFrame follows the test renderer's output sink. Recording\n // redirects that sink to the timeline, so read the live render buffer\n // instead; it is also the source used by screenshots.\n screen: () => decoder.decode((Reflect.get(renderer, \"currentRenderBuffer\") as RenderBuffer).getRealCharBytes()),\n }\n}\n\nexport function elements(renderer: CliRenderer): Element[] {\n return all(renderer.root)\n .filter((renderable) => renderable.visible && !renderable.isDestroyed)\n .map((renderable) => {\n const clickable = mouseListeners(renderable) && hit(renderer, renderable)\n return {\n id: renderable.id,\n num: renderable.num,\n x: renderable.screenX,\n y: renderable.screenY,\n width: renderable.width,\n height: renderable.height,\n focusable: renderable.focusable,\n focused: renderable.focused,\n clickable,\n editor: renderer.currentFocusedEditor === renderable,\n } satisfies Element\n })\n .filter((element) => element.focusable || element.clickable || element.editor)\n}\n\nexport function state(harness: Harness) {\n return {\n focused: {\n renderable: harness.renderer.currentFocusedRenderable?.num,\n editor: Boolean(harness.renderer.currentFocusedEditor),\n },\n elements: elements(harness.renderer),\n }\n}\n\nexport function matches(harness: Pick<Harness, \"screen\">, text: string) {\n return harness.screen().includes(text)\n}\n\nexport const capture = Effect.fn(\"SimulationActions.capture\")(function* (harness: Harness) {\n yield* Effect.tryPromise(() => harness.renderOnce())\n const buffer = harness.renderer.currentRenderBuffer\n return {\n cols: buffer.width,\n rows: buffer.height,\n cursor: [0, 0] as const,\n lines: buffer.getSpanLines().map((line) => ({\n spans: line.spans.map((span) => ({\n text: span.text,\n fg: span.fg.toInts(),\n bg: span.bg.toInts(),\n attributes: span.attributes,\n width: span.width,\n })),\n })),\n } satisfies SimulationProtocol.Frontend.CapturedFrame\n})\n\nexport const screenshot = Effect.fn(\"SimulationActions.screenshot\")(function* (harness: Harness, name?: string) {\n const filename = name ?? `screenshot-${crypto.randomUUID()}`\n if (!filename || filename.includes(\"/\") || filename.includes(\"\\\\\") || extname(filename))\n return yield* Effect.fail(new Error(\"screenshot name must not contain a path or extension\"))\n yield* Effect.tryPromise(() => harness.renderOnce())\n const { SimulationPng } = yield* Effect.promise(() => import(\"./png\"))\n const image = SimulationPng.screenshot(harness.renderer)\n const directory = resolve(\n yield* Config.string(\"OPENCODE_DRIVE_MEDIA_DIR\").pipe(\n Config.withDefault(join(tmpdir(), \"opencode-drive\", \"output\")),\n ),\n )\n const fs = yield* FileSystem.FileSystem\n yield* fs.makeDirectory(directory, { recursive: true })\n const path = join(directory, `${filename}.png`)\n yield* fs.writeFile(path, image.data)\n return path\n})\n\nexport const execute = Effect.fn(\"SimulationActions.execute\")(function* (harness: Harness, action: Action) {\n switch (action.type) {\n case \"ui.type\":\n yield* Effect.tryPromise(() => harness.mockInput.typeText(action.text))\n break\n case \"ui.press\":\n harness.mockInput.pressKey(action.key, action.modifiers)\n break\n case \"ui.enter\":\n harness.mockInput.pressEnter()\n break\n case \"ui.arrow\":\n harness.mockInput.pressArrow(action.direction)\n break\n case \"ui.focus\":\n all(harness.renderer.root)\n .find((item) => item.num === action.target)\n ?.focus()\n break\n case \"ui.click\":\n yield* Effect.tryPromise(() => harness.mockMouse.click(action.x, action.y))\n break\n case \"ui.resize\":\n if (\n !Number.isSafeInteger(action.cols) ||\n action.cols <= 0 ||\n !Number.isSafeInteger(action.rows) ||\n action.rows <= 0\n ) {\n return yield* Effect.fail(new Error(\"resize cols and rows must be positive integers\"))\n }\n harness.resize(action.cols, action.rows)\n SimulationRenderer.recordResize(harness.renderer, action.cols, action.rows)\n break\n }\n yield* Effect.tryPromise(() => harness.renderOnce())\n return state(harness)\n})\n\nexport * as SimulationActions from \"./actions\"\n", | ||
| "import { createWriteStream, type WriteStream } from \"node:fs\"\nimport { mkdir } from \"node:fs/promises\"\nimport { dirname } from \"node:path\"\nimport { Writable } from \"node:stream\"\nimport { finished } from \"node:stream/promises\"\nimport { Schema } from \"effect\"\n\nexport const Header = Schema.Struct({\n type: Schema.Literal(\"header\"),\n version: Schema.Literal(1),\n cols: Schema.Number,\n rows: Schema.Number,\n encoding: Schema.Literal(\"base64\"),\n})\nexport interface Header extends Schema.Schema.Type<typeof Header> {}\n\nexport const Output = Schema.Struct({\n type: Schema.Literal(\"output\"),\n at_ms: Schema.Number,\n data: Schema.String,\n})\nexport interface Output extends Schema.Schema.Type<typeof Output> {}\n\nexport const Resize = Schema.Struct({\n type: Schema.Literal(\"resize\"),\n at_ms: Schema.Number,\n cols: Schema.Number,\n rows: Schema.Number,\n})\nexport interface Resize extends Schema.Schema.Type<typeof Resize> {}\n\nexport const Event = Schema.Union([Header, Output, Resize])\nexport type Event = Schema.Schema.Type<typeof Event>\n\nexport class Timeline extends Writable {\n readonly isTTY = true\n readonly path: string\n readonly columns: number\n readonly rows: number\n private readonly output: WriteStream\n private readonly started = performance.now()\n private readonly timestamps: number[] = []\n private done?: Promise<string>\n\n private constructor(path: string, cols: number, rows: number, output: WriteStream) {\n super()\n this.path = path\n this.columns = cols\n this.rows = rows\n this.output = output\n // finish() reports stream failures; keep Writable from also throwing them process-wide.\n this.on(\"error\", () => {})\n output.on(\"error\", (error) => this.destroy(error))\n }\n\n static async create(path: string, cols: number, rows: number) {\n await mkdir(dirname(path), { recursive: true })\n const output = createWriteStream(path)\n const timeline = new Timeline(path, cols, rows, output)\n await new Promise<void>((resolve, reject) => {\n output.write(\n `${JSON.stringify({ type: \"header\", version: 1, cols, rows, encoding: \"base64\" } satisfies Header)}\\n`,\n (error) => (error ? reject(error) : resolve()),\n )\n })\n return timeline\n }\n\n getColorDepth() {\n return 24\n }\n\n override write(chunk: unknown, callback?: (error?: Error | null) => void): boolean\n override write(chunk: unknown, encoding: BufferEncoding, callback?: (error?: Error | null) => void): boolean\n override write(\n chunk: unknown,\n encoding?: BufferEncoding | ((error?: Error | null) => void),\n callback?: (error?: Error | null) => void,\n ) {\n if (!this.writableEnded) {\n this.timestamps.push(this.elapsed())\n if (typeof encoding === \"function\") return super.write(chunk, encoding)\n if (encoding === undefined) return super.write(chunk, callback)\n return super.write(chunk, encoding, callback)\n }\n const done = typeof encoding === \"function\" ? encoding : callback\n queueMicrotask(() => done?.(null))\n return true\n }\n\n override _write(chunk: Buffer, _encoding: BufferEncoding, callback: (error?: Error | null) => void) {\n this.writeOutput(chunk, this.timestamps.shift() ?? this.elapsed(), callback)\n }\n\n override _final(callback: (error?: Error | null) => void) {\n this.writeOutput(Buffer.alloc(0), this.elapsed(), (error) => {\n if (error) return callback(error)\n this.output.end(callback)\n })\n }\n\n finish() {\n if (this.done) return this.done\n this.end()\n this.done = finished(this).then(() => this.path)\n return this.done\n }\n\n resize(cols: number, rows: number) {\n if (this.writableEnded) return\n const event = { type: \"resize\", at_ms: this.elapsed(), cols, rows } satisfies Resize\n this.output.write(`${JSON.stringify(event)}\\n`)\n }\n\n private elapsed() {\n return Math.max(0, Math.round(performance.now() - this.started))\n }\n\n private writeOutput(data: Buffer, at_ms: number, callback: (error?: Error | null) => void) {\n const event = {\n type: \"output\",\n at_ms,\n data: data.toString(\"base64\"),\n } satisfies Output\n this.output.write(`${JSON.stringify(event)}\\n`, callback)\n }\n}\n\nexport * as SimulationRecording from \"./recording\"\n", | ||
| "import type { CliRenderer, CliRendererConfig } from \"@opentui/core\"\nimport { createTestRenderer, type TestRendererSetup } from \"@opentui/core/testing\"\nimport { Effect } from \"effect\"\nimport { Timeline } from \"../recording\"\n\nconst setups = new WeakMap<CliRenderer, TestRendererSetup>()\nconst recordings = new WeakMap<CliRenderer, Timeline>()\n\n/**\n * Creates a headless renderer with optional recording: a real CliRenderer\n * backed by an in-memory screen buffer. The TestRendererSetup is kept\n * module-side so the harness can use supported testing APIs without app\n * code carrying it around.\n */\nexport interface Viewport {\n readonly cols: number\n readonly rows: number\n}\n\nexport const create = Effect.fn(\"SimulationRenderer.create\")(function* (\n options: CliRendererConfig,\n path?: string,\n viewport?: Viewport,\n) {\n const cols = viewport?.cols ?? 100\n const rows = viewport?.rows ?? 40\n const recording = path\n ? yield* Effect.acquireRelease(\n Effect.tryPromise(() => Timeline.create(path, cols, rows)),\n (recording) =>\n Effect.tryPromise(() => recording.finish()).pipe(\n Effect.catch((error) =>\n Effect.sync(() => process.stderr.write(`Failed to finish UI recording: ${error}\\n`)),\n ),\n ),\n )\n : undefined\n const setup = yield* Effect.acquireRelease(\n Effect.tryPromise(() =>\n createTestRenderer({\n ...options,\n width: cols,\n height: rows,\n ...(recording\n ? {\n stdout: recording as unknown as NodeJS.WriteStream,\n bufferedOutput: \"stdout\" as const,\n }\n : {}),\n }),\n ),\n (setup) =>\n Effect.sync(() => {\n if (!setup.renderer.isDestroyed) setup.renderer.destroy()\n }),\n )\n setups.set(setup.renderer, setup)\n if (recording) recordings.set(setup.renderer, recording)\n return setup.renderer\n})\n\nexport function recordResize(renderer: CliRenderer, cols: number, rows: number) {\n recordings.get(renderer)?.resize(cols, rows)\n}\n\nexport function setupFor(renderer: CliRenderer): TestRendererSetup | undefined {\n return setups.get(renderer)\n}\n\nexport function finish(renderer: CliRenderer) {\n const recording = recordings.get(renderer)\n if (!recording) return Effect.fail(new Error(\"UI recording is not available\"))\n return Effect.tryPromise(() => recording.finish())\n}\n\nexport * as SimulationRenderer from \"./renderer\"\n", | ||
| "import { InstallationVersion } from \"@opencode-ai/core/installation/version\"\nimport { Effect } from \"effect\"\nimport { SimulationControlServer } from \"../control-server\"\nimport { SimulationProtocol } from \"../protocol\"\nimport { SimulationActions, type Harness } from \"./actions\"\nimport { SimulationRenderer } from \"./renderer\"\n\nfunction handle(harness: Harness, request: SimulationProtocol.Frontend.Request) {\n switch (request.method) {\n case \"simulation.handshake\":\n return SimulationProtocol.Handshake.dispatch(\n {\n role: \"ui\",\n server: { name: \"opencode\", version: InstallationVersion },\n capabilities: SimulationProtocol.Frontend.Capabilities,\n },\n request.params,\n )\n case \"ui.capture\":\n return SimulationActions.capture(harness)\n case \"ui.screenshot\":\n return SimulationActions.screenshot(harness, request.params?.name)\n case \"ui.state\":\n return Effect.sync(() => SimulationActions.state(harness))\n case \"ui.matches\":\n return Effect.sync(() => SimulationActions.matches(harness, request.params.text))\n case \"ui.recording.finish\":\n return SimulationRenderer.finish(harness.renderer)\n case \"ui.type\":\n return SimulationActions.execute(harness, { type: \"ui.type\", text: request.params.text })\n case \"ui.enter\":\n return SimulationActions.execute(harness, { type: \"ui.enter\" })\n case \"ui.press\":\n return SimulationActions.execute(harness, {\n type: \"ui.press\",\n key: request.params.key,\n modifiers: request.params.modifiers,\n })\n case \"ui.arrow\":\n return SimulationActions.execute(harness, { type: \"ui.arrow\", direction: request.params.direction })\n case \"ui.focus\":\n return SimulationActions.execute(harness, { type: \"ui.focus\", target: request.params.target })\n case \"ui.click\":\n return SimulationActions.execute(harness, {\n type: \"ui.click\",\n target: request.params.target,\n x: request.params.x,\n y: request.params.y,\n })\n case \"ui.resize\":\n return SimulationActions.execute(harness, {\n type: \"ui.resize\",\n cols: request.params.cols,\n rows: request.params.rows,\n })\n }\n}\n\nexport const start = Effect.fn(\"SimulationServer.start\")(function* (harness: Harness, endpoint: string) {\n return yield* SimulationControlServer.start({\n endpoint,\n label: \"opencode drive ui websocket\",\n data: () => ({ drive: true as const }),\n decode: SimulationProtocol.Frontend.decodeRequestEffect,\n handle: (_socket, request) => handle(harness, request),\n })\n})\n\nexport * as SimulationServer from \"./server\"\n", | ||
| "import { createCliRenderer, type CliRendererConfig } from \"@opentui/core\"\nimport { Config, Effect } from \"effect\"\nimport { DriveManifest } from \"../manifest\"\nimport { SimulationActions } from \"./actions\"\nimport { SimulationRenderer } from \"./renderer\"\nimport { SimulationServer } from \"./server\"\n\n/** Drive-mode renderer and control-server acquisition. */\nexport const create = Effect.fn(\"Drive.create\")(function* (options: CliRendererConfig) {\n const headless = (yield* Config.string(\"OPENCODE_DRIVE_RENDERER\").pipe(Config.withDefault(\"visible\"))) === \"headless\"\n const manifest = yield* DriveManifest.resolve()\n const renderer = headless\n ? yield* SimulationRenderer.create(options, manifest.recording?.timeline, manifest.viewport)\n : yield* Effect.acquireRelease(\n Effect.tryPromise(() => createCliRenderer(options)),\n (renderer) =>\n Effect.sync(() => {\n if (!renderer.isDestroyed) renderer.destroy()\n }),\n )\n if (!headless && manifest.viewport) renderer.resize(manifest.viewport.cols, manifest.viewport.rows)\n const server = yield* SimulationServer.start(SimulationActions.createHarness(renderer), manifest.endpoints.ui)\n yield* Effect.sync(() => process.stderr.write(`opencode drive ui websocket: ${server.url}\\n`))\n return renderer\n})\n\nexport * as Drive from \"./simulation\"\n" | ||
| ], | ||
| "mappings": ";moBAAA,sBAAS,gBACT,uBAAS,eAAS,kBAAM,uHCDxB,iCAAS,gBACT,gBAAS,oBACT,kBAAS,aACT,mBAAS,eACT,mBAAS,wBAGF,IAAM,EAAS,EAAO,OAAO,CAClC,KAAM,EAAO,QAAQ,QAAQ,EAC7B,QAAS,EAAO,QAAQ,CAAC,EACzB,KAAM,EAAO,OACb,KAAM,EAAO,OACb,SAAU,EAAO,QAAQ,QAAQ,CACnC,CAAC,EAGY,EAAS,EAAO,OAAO,CAClC,KAAM,EAAO,QAAQ,QAAQ,EAC7B,MAAO,EAAO,OACd,KAAM,EAAO,MACf,CAAC,EAGY,EAAS,EAAO,OAAO,CAClC,KAAM,EAAO,QAAQ,QAAQ,EAC7B,MAAO,EAAO,OACd,KAAM,EAAO,OACb,KAAM,EAAO,MACf,CAAC,EAGY,GAAQ,EAAO,MAAM,CAAC,EAAQ,EAAQ,CAAM,CAAC,EAGnD,MAAM,UAAiB,CAAS,CAC5B,MAAQ,GACR,KACA,QACA,KACQ,OACA,QAAU,YAAY,IAAI,EAC1B,WAAuB,CAAC,EACjC,KAEA,WAAW,CAAC,EAAc,EAAc,EAAc,EAAqB,CACjF,MAAM,EACN,KAAK,KAAO,EACZ,KAAK,QAAU,EACf,KAAK,KAAO,EACZ,KAAK,OAAS,EAEd,KAAK,GAAG,QAAS,IAAM,EAAE,EACzB,EAAO,GAAG,QAAS,CAAC,IAAU,KAAK,QAAQ,CAAK,CAAC,cAGtC,OAAM,CAAC,EAAc,EAAc,EAAc,CAC5D,MAAM,EAAM,EAAQ,CAAI,EAAG,CAAE,UAAW,EAAK,CAAC,EAC9C,IAAM,EAAS,EAAkB,CAAI,EAC/B,EAAW,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| { | ||
| "version": 3, | ||
| "sources": ["src/commands/handlers/mcp/logout.ts"], | ||
| "sourcesContent": [ | ||
| "import { EOL } from \"node:os\"\nimport { Effect } from \"effect\"\nimport { OpenCode } from \"@opencode-ai/client\"\nimport { Commands } from \"../../commands\"\nimport { Runtime } from \"../../../framework/runtime\"\nimport { Service } from \"@opencode-ai/client/effect/service\"\nimport { ServiceConfig } from \"../../../services/service-config\"\nimport { resolveIntegration } from \"./resolve\"\n\nconst location = { directory: process.cwd() }\n\nexport default Runtime.handler(\n Commands.commands.mcp.commands.logout,\n Effect.fn(\"cli.mcp.logout\")(function* (input) {\n const options = yield* ServiceConfig.options()\n const found = yield* Service.discover(options)\n const endpoint = found ?? (yield* Service.ensure(options))\n const client = OpenCode.make({ baseUrl: endpoint.url, headers: Service.headers(endpoint) })\n\n const integration = yield* resolveIntegration(client, input.name, location)\n if (!integration) {\n process.stdout.write(`No stored credentials for ${input.name}` + EOL)\n return\n }\n\n const credentials = integration.connections.filter((connection) => connection.type === \"credential\")\n if (credentials.length === 0) {\n process.stdout.write(`No stored credentials for ${input.name}` + EOL)\n return\n }\n\n yield* Effect.forEach(\n credentials,\n (connection) => Effect.promise(() => client.credential.remove({ credentialID: connection.id, location })),\n { discard: true },\n )\n process.stdout.write(`Removed OAuth credentials for ${input.name}` + EOL)\n }),\n)\n" | ||
| ], | ||
| "mappings": ";88BAAA,mBAAS,gBAST,SAAM,OAAW,MAAE,eAAW,aAAQ,SAAI,MAAE,OAE7B,SAAQ,aACrB,OAAS,cAAS,SAAI,cAAS,YAC/B,OAAO,QAAG,qBAAgB,OAAE,cAAU,MAAC,OAAO,MAC5C,IAAM,EAAU,MAAO,EAAc,QAAQ,EAEvC,GADQ,MAAO,EAAQ,SAAS,CAAO,KAClB,MAAO,EAAQ,OAAO,CAAO,GAClD,EAAS,EAAS,KAAK,CAAE,QAAS,EAAS,IAAK,QAAS,EAAQ,QAAQ,CAAQ,CAAE,CAAC,EAEpF,EAAc,MAAO,EAAmB,EAAQ,EAAM,KAAM,CAAQ,EAC1E,GAAI,CAAC,EAAa,CAChB,QAAQ,OAAO,MAAM,6BAA6B,EAAM,OAAS,CAAG,EACpE,OAGF,IAAM,EAAc,EAAY,YAAY,OAAO,CAAC,IAAe,EAAW,OAAS,YAAY,EACnG,GAAI,EAAY,SAAW,EAAG,CAC5B,QAAQ,OAAO,MAAM,6BAA6B,EAAM,OAAS,CAAG,EACpE,OAGF,MAAO,EAAO,QACZ,EACA,CAAC,IAAe,EAAO,QAAQ,IAAM,EAAO,WAAW,OAAO,CAAE,aAAc,EAAW,GAAI,UAAS,CAAC,CAAC,EACxG,CAAE,QAAS,EAAK,CAClB,EACA,QAAQ,OAAO,MAAM,iCAAiC,EAAM,OAAS,CAAG,EACzE,CACH", | ||
| "debugId": "386D62EB175E6FA564756E2164756E21", | ||
| "names": [] | ||
| } |
| { | ||
| "version": 3, | ||
| "sources": ["src/commands/handlers/service/set.ts"], | ||
| "sourcesContent": [ | ||
| "import { Effect } from \"effect\"\nimport { Commands } from \"../../commands\"\nimport { Runtime } from \"../../../framework/runtime\"\nimport { ServiceConfig } from \"../../../services/service-config\"\n\nexport default Runtime.handler(\n Commands.commands.service.commands.set,\n Effect.fn(\"cli.service.set\")(function* (input) {\n yield* ServiceConfig.set(input.key, input.value)\n }),\n)\n" | ||
| ], | ||
| "mappings": ";o2BAKA,SAAe,SAAQ,aACrB,OAAS,cAAS,aAAQ,cAAS,SACnC,OAAO,QAAG,sBAAiB,OAAE,cAAU,MAAC,OAAO,MAC7C,WAAO,OAAc,SAAI,OAAM,SAAK,OAAM,UAAK,EAChD,CACH", | ||
| "debugId": "BA54982ADFF1E12A64756E2164756E21", | ||
| "names": [] | ||
| } |
| { | ||
| "version": 3, | ||
| "sources": ["src/commands/handlers/service/stop.ts"], | ||
| "sourcesContent": [ | ||
| "import { Effect } from \"effect\"\nimport { Service } from \"@opencode-ai/client/effect/service\"\nimport { Commands } from \"../../commands\"\nimport { Runtime } from \"../../../framework/runtime\"\nimport { ServiceConfig } from \"../../../services/service-config\"\n\nexport default Runtime.handler(\n Commands.commands.service.commands.stop,\n Effect.fn(\"cli.service.stop\")(function* () {\n yield* Service.stop(yield* ServiceConfig.options())\n }),\n)\n" | ||
| ], | ||
| "mappings": ";i3BAMA,SAAe,SAAQ,aACrB,OAAS,cAAS,aAAQ,cAAS,UACnC,OAAO,QAAG,uBAAkB,OAAE,cAAU,OAAG,MACzC,WAAO,OAAQ,UAAK,WAAO,OAAc,aAAQ,MAAC,OACnD,CACH", | ||
| "debugId": "A0D2AF57F7CC7F0F64756E2164756E21", | ||
| "names": [] | ||
| } |
| { | ||
| "version": 3, | ||
| "sources": ["src/services/service-config.ts"], | ||
| "sourcesContent": [ | ||
| "import { Global } from \"@opencode-ai/core/global\"\nimport { InstallationChannel, InstallationVersion } from \"@opencode-ai/core/installation/version\"\nimport { Hash } from \"@opencode-ai/core/util/hash\"\nimport { Service } from \"@opencode-ai/client/effect/service\"\nimport { Effect, FileSystem, Option, Schema } from \"effect\"\nimport { randomBytes } from \"crypto\"\nimport path from \"path\"\n\n// The CLI's service configuration file, plus the Service.EnsureOptions binding that\n// points the client package's service operations at this CLI: which\n// registration file (by channel), which version, and how to spawn opencode.\n\nexport const Info = Schema.Struct({\n hostname: Schema.optional(Schema.String),\n port: Schema.optional(Schema.Int.check(Schema.isGreaterThanOrEqualTo(1), Schema.isLessThanOrEqualTo(65_535))),\n password: Schema.optional(Schema.String),\n})\nexport type Info = typeof Info.Type\n\nconst keys = [\"hostname\", \"port\", \"password\"] as const\ntype Key = (typeof keys)[number]\n\nconst decodeInfo = Schema.decodeUnknownEffect(Schema.fromJsonString(Info))\nconst decodeRegistration = Schema.decodeUnknownEffect(Schema.fromJsonString(Service.Info))\n\nexport function filename(channel = InstallationChannel) {\n if (channel === \"latest\") return \"service.json\"\n if (channel === \"local\") return \"service-local.json\"\n return `service-${Hash.fast(channel)}.json`\n}\n\nexport function versionBelongsToChannel(\n version: string | undefined,\n channel = InstallationChannel,\n installedVersion = InstallationVersion,\n) {\n if (version === undefined) return false\n if (version === installedVersion) return true\n const prefix = `0.0.0-${channel}-`\n if (!version.startsWith(prefix)) return false\n return /^\\d+(?:\\.\\d+)?$/.test(version.slice(prefix.length))\n}\n\nexport const migrateRegistration = Effect.fnUntraced(function* (\n legacy: string,\n file: string,\n channel = InstallationChannel,\n installedVersion = InstallationVersion,\n) {\n if (channel === \"latest\" || channel === \"local\") return\n const fs = yield* FileSystem.FileSystem\n const text = yield* fs.readFileString(legacy).pipe(Effect.option)\n if (Option.isNone(text)) return\n const registration = yield* decodeRegistration(text.value).pipe(Effect.option)\n if (Option.isNone(registration)) return\n if (!versionBelongsToChannel(registration.value.version, channel, installedVersion)) return\n yield* fs.writeFileString(file, text.value, { flag: \"wx\", mode: 0o600 }).pipe(Effect.ignore)\n})\n\nfunction configKey(key: string): Key {\n if (key === \"hostname\" || key === \"port\" || key === \"password\") return key\n throw new Error(`Unknown service config key: ${key}`)\n}\n\nconst paths = Effect.gen(function* () {\n const fs = yield* FileSystem.FileSystem\n const global = yield* Global.Service\n const name = filename()\n const file = path.join(global.state, name)\n return {\n fs,\n file,\n legacyFile: path.join(global.state, \"service.json\"),\n configFile: path.join(global.config, name),\n }\n})\n\nexport const options = Effect.fnUntraced(function* () {\n const { file, legacyFile } = yield* paths\n yield* migrateRegistration(legacyFile, file)\n const compiled = path.basename(process.execPath).replace(/\\.exe$/, \"\") !== \"bun\"\n const entrypoint = compiled ? undefined : process.argv[1]\n if (!compiled && entrypoint === undefined) return yield* Effect.fail(new Error(\"Failed to resolve CLI entrypoint\"))\n return {\n file,\n version: InstallationVersion,\n command: [process.execPath, ...(entrypoint ? [entrypoint] : []), \"serve\", \"--service\"],\n }\n})\n\nexport const read = Effect.fn(\"cli.service-config.read\")(function* () {\n const { fs, configFile } = yield* paths\n return yield* fs.readFileString(configFile).pipe(\n Effect.flatMap(decodeInfo),\n Effect.catch(() => Effect.succeed({} as Info)),\n )\n})\n\nconst write = Effect.fn(\"cli.service-config.write\")(function* (value: Info) {\n const { fs, configFile } = yield* paths\n const temp = configFile + \".tmp\"\n yield* fs.makeDirectory(path.dirname(configFile), { recursive: true })\n yield* fs.writeFileString(temp, JSON.stringify(value, null, 2) + \"\\n\", { mode: 0o600 })\n yield* fs.rename(temp, configFile)\n})\n\nexport const password = Effect.fn(\"cli.service-config.password\")(function* (value?: string) {\n const existing = yield* read()\n if (value === undefined && existing.password) return existing.password\n const next = value ?? randomBytes(32).toString(\"base64url\")\n\n // Keep one private credential across server restarts so discovered clients\n // can reconnect without exposing a password flag or environment variable.\n yield* write({ ...existing, password: next })\n return next\n})\n\nexport const get = Effect.fn(\"cli.service-config.get\")(function* (key?: string) {\n if (key === undefined) {\n const { password: _password, ...safe } = yield* read()\n return JSON.stringify(safe, null, 2)\n }\n switch (configKey(key)) {\n case \"hostname\": {\n return (yield* read()).hostname ?? \"\"\n }\n case \"port\": {\n const port = (yield* read()).port\n return port === undefined ? \"\" : String(port)\n }\n case \"password\": {\n return yield* password()\n }\n }\n throw new Error(`Unknown service config key: ${key}`)\n})\n\nexport const set = Effect.fn(\"cli.service-config.set\")(function* (key: string, value: string) {\n switch (configKey(key)) {\n case \"hostname\": {\n yield* Service.stop(yield* options())\n yield* write({ ...(yield* read()), hostname: value })\n return\n }\n case \"port\": {\n const port = Number(value)\n if (!Number.isInteger(port) || port < 1 || port > 65_535) throw new Error(\"Port must be between 1 and 65535\")\n yield* Service.stop(yield* options())\n yield* write({ ...(yield* read()), port })\n return\n }\n case \"password\": {\n yield* Service.stop(yield* options())\n yield* password(value)\n return\n }\n }\n})\n\nexport const unset = Effect.fn(\"cli.service-config.unset\")(function* (key: string) {\n switch (configKey(key)) {\n case \"hostname\": {\n yield* Service.stop(yield* options())\n const { hostname: _hostname, ...next } = yield* read()\n yield* write(next)\n return\n }\n case \"port\": {\n yield* Service.stop(yield* options())\n const { port: _port, ...next } = yield* read()\n yield* write(next)\n return\n }\n case \"password\": {\n yield* Service.stop(yield* options())\n const { password: _password, ...next } = yield* read()\n yield* write(next)\n return\n }\n }\n})\n\nexport * as ServiceConfig from \"./service-config\"\n" | ||
| ], | ||
| "mappings": ";sdAKA,2BAAS,oBACT,yBAMO,SAAM,EAAO,EAAO,OAAO,CAChC,SAAU,EAAO,SAAS,EAAO,MAAM,EACvC,KAAM,EAAO,SAAS,EAAO,IAAI,MAAM,EAAO,uBAAuB,CAAC,EAAG,EAAO,oBAAoB,KAAM,CAAC,CAAC,EAC5G,SAAU,EAAO,SAAS,EAAO,MAAM,CACzC,CAAC,EAMD,IAAM,EAAa,EAAO,oBAAoB,EAAO,eAAe,CAAI,CAAC,EACnE,EAAqB,EAAO,oBAAoB,EAAO,eAAe,EAAQ,IAAI,CAAC,EAElF,SAAS,CAAQ,CAAC,EAAU,EAAqB,CACtD,GAAI,IAAY,SAAU,MAAO,eACjC,GAAI,IAAY,QAAS,MAAO,qBAChC,MAAO,WAAW,EAAK,KAAK,CAAO,SAG9B,SAAS,CAAuB,CACrC,EACA,EAAU,EACV,EAAmB,EACnB,CACA,GAAI,IAAY,OAAW,MAAO,GAClC,GAAI,IAAY,EAAkB,MAAO,GACzC,IAAM,EAAS,SAAS,KACxB,GAAI,CAAC,EAAQ,WAAW,CAAM,EAAG,MAAO,GACxC,MAAO,kBAAkB,KAAK,EAAQ,MAAM,EAAO,MAAM,CAAC,EAGrD,IAAM,EAAsB,EAAO,WAAW,SAAU,CAC7D,EACA,EACA,EAAU,EACV,EAAmB,EACnB,CACA,GAAI,IAAY,UAAY,IAAY,QAAS,OACjD,IAAM,EAAK,MAAO,EAAW,WACvB,EAAO,MAAO,EAAG,eAAe,CAAM,EAAE,KAAK,EAAO,MAAM,EAChE,GAAI,EAAO,OAAO,CAAI,EAAG,OACzB,IAAM,EAAe,MAAO,EAAmB,EAAK,KAAK,EAAE,KAAK,EAAO,MAAM,EAC7E,GAAI,EAAO,OAAO,CAAY,EAAG,OACjC,GAAI,CAAC,EAAwB,EAAa,MAAM,Q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AAK,EAAO,MAAQ,MAAU,MAAM,kCAAkC,EAC5G,MAAO,EAAQ,KAAK,MAAO,EAAQ,CAAC,EACpC,MAAO,EAAM,IAAM,MAAO,EAAK,EAAI,MAAK,CAAC,EACzC,MACF,KACK,WAAY,CACf,MAAO,EAAQ,KAAK,MAAO,EAAQ,CAAC,EACpC,MAAO,EAAS,CAAK,EACrB,MACF,GAEH,EAEY,EAAQ,EAAO,GAAG,0BAA0B,EAAE,SAAU,CAAC,EAAa,CACjF,OAAQ,EAAU,CAAG,OACd,WAAY,CACf,MAAO,EAAQ,KAAK,MAAO,EAAQ,CAAC,EACpC,IAAQ,SAAU,KAAc,GAAS,MAAO,EAAK,EACrD,MAAO,EAAM,CAAI,EACjB,MACF,KACK,OAAQ,CACX,MAAO,EAAQ,KAAK,MAAO,EAAQ,CAAC,EACpC,IAAQ,KAAM,KAAU,GAAS,MAAO,EAAK,EAC7C,MAAO,EAAM,CAAI,EACjB,MACF,KACK,WAAY,CACf,MAAO,EAAQ,KAAK,MAAO,EAAQ,CAAC,EACpC,IAAQ,SAAU,KAAc,GAAS,MAAO,EAAK,EACrD,MAAO,EAAM,CAAI,EACjB,MACF,GAEH", | ||
| "debugId": "2C4C72CBB43DA88664756E2164756E21", | ||
| "names": [] | ||
| } |
| { | ||
| "version": 3, | ||
| "sources": ["src/commands/handlers/mini.ts"], | ||
| "sourcesContent": [ | ||
| "import { Effect, Option } from \"effect\"\nimport { Commands } from \"../commands\"\nimport { Runtime } from \"../../framework/runtime\"\nimport { ServerConnection } from \"../../services/server-connection\"\n\nexport default Runtime.handler(Commands.commands.mini, (input) =>\n Effect.gen(function* () {\n const { runMini, validateMiniTerminal } = yield* Effect.promise(() => import(\"../../mini\"))\n yield* Effect.promise(async () => validateMiniTerminal())\n const serverURL = Option.getOrUndefined(input.server)\n const server = yield* ServerConnection.resolve({ server: serverURL, standalone: input.standalone })\n yield* Effect.promise(() =>\n runMini({\n server,\n continue: input.continue,\n session: Option.getOrUndefined(input.session),\n fork: input.fork,\n model: Option.getOrUndefined(input.model),\n agent: Option.getOrUndefined(input.agent),\n prompt: Option.getOrUndefined(input.prompt),\n replay: input.replay,\n replayLimit: Option.getOrUndefined(input.replayLimit),\n demo: input.demo,\n }),\n )\n }),\n)\n" | ||
| ], | ||
| "mappings": ";ixCAKA,SAAe,SAAQ,aAAQ,OAAS,cAAS,UAAM,MAAC,SACtD,OAAO,SAAI,cAAU,OAAG,MACtB,SAAQ,eAAS,6BAAyB,WAAO,OAAO,aAAQ,SAAa,wCAAa,OAC1F,WAAO,OAAO,aAAQ,cAAY,OAAqB,MAAC,OACxD,SAAM,OAAY,OAAO,oBAAe,OAAM,WAAM,OAC9C,EAAS,MAAO,EAAiB,QAAQ,CAAE,OAAQ,EAAW,WAAY,EAAM,UAAW,CAAC,EAClG,MAAO,EAAO,QAAQ,IACpB,EAAQ,CACN,SACA,SAAU,EAAM,SAChB,QAAS,EAAO,eAAe,EAAM,OAAO,EAC5C,KAAM,EAAM,KACZ,MAAO,EAAO,eAAe,EAAM,KAAK,EACxC,MAAO,EAAO,eAAe,EAAM,KAAK,EACxC,OAAQ,EAAO,eAAe,EAAM,MAAM,EAC1C,OAAQ,EAAM,OACd,YAAa,EAAO,eAAe,EAAM,WAAW,EACpD,KAAM,EAAM,IACd,CAAC,CACH,EACD,CACH", | ||
| "debugId": "54E665514D5D727464756E2164756E21", | ||
| "names": [] | ||
| } |
Sorry, the diff of this file is too big to display
| { | ||
| "version": 3, | ||
| "sources": ["src/commands/handlers/mcp/list.ts"], | ||
| "sourcesContent": [ | ||
| "import { EOL } from \"node:os\"\nimport { Effect } from \"effect\"\nimport { OpenCode, type McpServer } from \"@opencode-ai/client\"\nimport { Commands } from \"../../commands\"\nimport { Runtime } from \"../../../framework/runtime\"\nimport { Service } from \"@opencode-ai/client/effect/service\"\nimport { ServiceConfig } from \"../../../services/service-config\"\n\nexport default Runtime.handler(\n Commands.commands.mcp.commands.list,\n Effect.fn(\"cli.mcp.list\")(function* () {\n const options = yield* ServiceConfig.options()\n const found = yield* Service.discover(options)\n const endpoint = found ?? (yield* Service.ensure(options))\n const client = OpenCode.make({ baseUrl: endpoint.url, headers: Service.headers(endpoint) })\n const response = yield* Effect.promise(() => client.mcp.list({ location: { directory: process.cwd() } }))\n const servers = response.data.toSorted((a, b) => a.name.localeCompare(b.name))\n if (servers.length === 0) {\n process.stdout.write(\"No MCP servers configured\" + EOL)\n return\n }\n const width = Math.max(...servers.map((server) => server.name.length))\n const lines = servers.map(\n (server) => `${icon(server.status)} ${server.name.padEnd(width)} ${describe(server.status)}`,\n )\n process.stdout.write(lines.join(EOL) + EOL)\n }),\n)\n\nfunction icon(status: McpServer[\"status\"]) {\n switch (status.status) {\n case \"connected\":\n return \"✓\"\n case \"needs_auth\":\n return \"⚠\"\n case \"failed\":\n case \"needs_client_registration\":\n return \"✗\"\n default:\n return \"○\"\n }\n}\n\nfunction describe(status: McpServer[\"status\"]) {\n switch (status.status) {\n case \"needs_auth\":\n return \"needs authentication\"\n case \"needs_client_registration\":\n return `needs client registration: ${status.error}`\n case \"failed\":\n return `failed: ${status.error}`\n default:\n return status.status\n }\n}\n" | ||
| ], | ||
| "mappings": ";g6BAAA,mBAAS,gBAQT,SAAe,SAAQ,aACrB,OAAS,cAAS,SAAI,cAAS,UAC/B,OAAO,QAAG,mBAAc,OAAE,cAAU,OAAG,MACrC,SAAM,OAAU,WAAO,OAAc,aAAQ,OAEvC,QADQ,MAAO,EAAQ,SAAS,CAAO,KAClB,MAAO,EAAQ,OAAO,CAAO,GAClD,EAAS,EAAS,KAAK,CAAE,QAAS,EAAS,IAAK,QAAS,EAAQ,QAAQ,CAAQ,CAAE,CAAC,EAEpF,GADW,MAAO,EAAO,QAAQ,IAAM,EAAO,IAAI,KAAK,CAAE,SAAU,CAAE,UAAW,QAAQ,IAAI,CAAE,CAAE,CAAC,CAAC,GAC/E,KAAK,SAAS,CAAC,EAAG,IAAM,EAAE,KAAK,cAAc,EAAE,IAAI,CAAC,EAC7E,GAAI,EAAQ,SAAW,EAAG,CACxB,QAAQ,OAAO,MAAM,4BAA8B,CAAG,EACtD,OAEF,IAAM,EAAQ,KAAK,IAAI,GAAG,EAAQ,IAAI,CAAC,IAAW,EAAO,KAAK,MAAM,CAAC,EAC/D,EAAQ,EAAQ,IACpB,CAAC,IAAW,GAAG,EAAK,EAAO,MAAM,KAAK,EAAO,KAAK,OAAO,CAAK,MAAM,EAAS,EAAO,MAAM,GAC5F,EACA,QAAQ,OAAO,MAAM,EAAM,KAAK,CAAG,EAAI,CAAG,EAC3C,CACH,EAEA,SAAS,CAAI,CAAC,EAA6B,CACzC,OAAQ,EAAO,YACR,YACH,MAAO,aACJ,aACH,MAAO,aACJ,aACA,4BACH,MAAO,iBAEP,MAAO,UAIb,SAAS,CAAQ,CAAC,EAA6B,CAC7C,OAAQ,EAAO,YACR,aACH,MAAO,2BACJ,4BACH,MAAO,8BAA8B,EAAO,YACzC,SACH,MAAO,WAAW,EAAO,gBAEzB,OAAO,EAAO", | ||
| "debugId": "B06F961BF3AFB94664756E2164756E21", | ||
| "names": [] | ||
| } |
| { | ||
| "version": 3, | ||
| "sources": ["src/services/standalone.ts", "src/services/server-connection.ts"], | ||
| "sourcesContent": [ | ||
| "import { Service, type Endpoint } from \"@opencode-ai/client/effect/service\"\nimport { CrossSpawnSpawner } from \"@opencode-ai/core/cross-spawn-spawner\"\nimport { AppNodeBuilder } from \"@opencode-ai/core/effect/app-node-builder\"\nimport { Effect, Schema, Stream } from \"effect\"\nimport { ChildProcess, ChildProcessSpawner } from \"effect/unstable/process\"\nimport { randomBytes } from \"node:crypto\"\nimport path from \"node:path\"\n\nconst Ready = Schema.Struct({ url: Schema.String })\nconst decodeReady = Schema.decodeUnknownPromise(Schema.fromJsonString(Ready))\n\ntype Options = {\n readonly command?: ReadonlyArray<string>\n}\n\nfunction command(password: string, options: Options) {\n const compiled = path.basename(process.execPath).replace(/\\.exe$/, \"\") !== \"bun\"\n const entrypoint = compiled ? [] : process.argv[1] ? [process.argv[1]] : []\n if (!compiled && entrypoint.length === 0) throw new Error(\"Failed to resolve CLI entrypoint\")\n const [executable, ...args] = options.command ?? [process.execPath, ...entrypoint, \"serve\"]\n if (!executable) throw new Error(\"Failed to resolve standalone server command\")\n return ChildProcess.make(executable, [...args, \"--stdio\", \"--port\", \"0\"], {\n cwd: process.cwd(),\n // Explicit entry wins over anything inherited, so a user-exported\n // OPENCODE_PASSWORD cannot shadow the child's lease credential.\n env: { OPENCODE_PASSWORD: password },\n extendEnv: true,\n // The server treats EOF on this pipe as the end of its ownership lease.\n // The OS closes it even when the TUI is killed before Effect finalizers run.\n stdin: \"pipe\",\n stderr: \"ignore\",\n killSignal: \"SIGTERM\",\n forceKillAfter: \"3 seconds\",\n })\n}\n\nconst makeEndpoint = Effect.fn(\"cli.standalone.endpoint\")(\n function* (options: Options) {\n const password = randomBytes(32).toString(\"base64url\")\n const spawner = yield* ChildProcessSpawner.ChildProcessSpawner\n const proc = yield* spawner.spawn(command(password, options))\n const output = yield* proc.stdout.pipe(Stream.decodeText(), Stream.splitLines, Stream.take(1), Stream.mkString)\n if (!output) return yield* Effect.fail(new Error(\"Standalone server exited before reporting readiness\"))\n const ready = yield* Effect.tryPromise(() => decodeReady(output))\n return {\n url: ready.url,\n auth: { type: \"basic\" as const, username: \"opencode\", password },\n pid: proc.pid,\n } satisfies Endpoint & { readonly pid: number }\n },\n Effect.provide(AppNodeBuilder.build(CrossSpawnSpawner.node)),\n)\n\nexport function start(options: Options = {}) {\n return makeEndpoint(options)\n}\n\nexport * as Standalone from \"./standalone\"\n", | ||
| "import { Service, type Endpoint, type EnsureOptions } from \"@opencode-ai/client/effect/service\"\nimport { ClientError, isUnauthorizedError, OpenCode } from \"@opencode-ai/client/promise\"\nimport { InstallationVersion } from \"@opencode-ai/core/installation/version\"\nimport { Effect, Redacted } from \"effect\"\nimport { Env } from \"../env\"\nimport { ServiceConfig } from \"./service-config\"\nimport { Standalone } from \"./standalone\"\n\nexport type Args = {\n readonly server?: string\n readonly standalone?: boolean\n readonly mismatch?: \"replace\" | \"ignore\" | \"error\"\n readonly onStart?: EnsureOptions[\"onStart\"]\n}\n\nexport type Resolved = {\n readonly endpoint: Endpoint\n readonly service?: ReturnType<typeof managedService>\n}\n\nexport const resolve = Effect.fn(\"cli.server-connection.resolve\")(function* (args: Args) {\n if (args.server !== undefined && args.standalone)\n return yield* Effect.fail(new Error(\"--server and --standalone cannot be combined\"))\n if (args.server !== undefined) {\n const password = yield* Env.password\n const endpoint = {\n url: args.server,\n auth: password ? { type: \"basic\" as const, username: \"opencode\", password: Redacted.value(password) } : undefined,\n } satisfies Endpoint\n const client = OpenCode.make({ baseUrl: endpoint.url, headers: Service.headers(endpoint) })\n const health = yield* Effect.tryPromise({\n try: () => client.health.get({ signal: AbortSignal.timeout(5_000) }),\n catch: (cause) => connectError(endpoint, cause),\n })\n if (health.version !== InstallationVersion)\n process.stderr.write(\n `Warning: Server at ${endpoint.url} has version ${health.version}; this client is ${InstallationVersion}. Continuing anyway.\\n`,\n )\n return { endpoint } satisfies Resolved\n }\n if (args.standalone) {\n return { endpoint: yield* Standalone.start() } satisfies Resolved\n }\n\n const options = yield* ServiceConfig.options()\n return {\n endpoint: yield* resolveManaged({ ...options, onStart: args.onStart }, args.mismatch ?? \"replace\"),\n service: managedService(options),\n } satisfies Resolved\n})\n\nfunction managedService(options: EnsureOptions) {\n const reconnectOptions = { ...options, version: undefined }\n return {\n reconnect: () => Service.ensure(reconnectOptions),\n restart: () =>\n Effect.gen(function* () {\n yield* Service.stop(options)\n yield* Service.ensure(options)\n }),\n }\n}\n\nconst resolveManaged = Effect.fnUntraced(function* (\n options: EnsureOptions,\n mismatch: NonNullable<Args[\"mismatch\"]>,\n) {\n if (mismatch === \"replace\") return yield* Service.ensure(options)\n if (mismatch === \"ignore\") return yield* Service.ensure({ ...options, version: undefined })\n\n const compatible = yield* Service.discover(options)\n if (compatible !== undefined) return compatible\n const existing = yield* Service.discover({ ...options, version: undefined })\n if (existing !== undefined)\n return yield* Effect.fail(new Error(\"Background server version does not match this client\"))\n return yield* Service.ensure(options)\n})\n\nfunction connectError(endpoint: Endpoint, cause: unknown) {\n if (isUnauthorizedError(cause)) {\n return new Error(\n endpoint.auth === undefined\n ? `Server at ${endpoint.url} requires a password; set OPENCODE_PASSWORD`\n : `Server at ${endpoint.url} rejected the password`,\n { cause },\n )\n }\n if (cause instanceof ClientError && cause.reason === \"Transport\")\n return new Error(`Could not reach server at ${endpoint.url}`, { cause })\n return new Error(`Server at ${endpoint.url} did not provide a compatible V2 health response`, { cause })\n}\n\nexport * as ServerConnection from \"./server-connection\"\n" | ||
| ], | ||
| "mappings": ";6mBAKA,2BAAS,oBACT,yBAEA,SAAM,OAAQ,OAAO,YAAO,MAAE,SAAK,EAAO,MAAO,CAAC,EAC5C,EAAc,EAAO,qBAAqB,EAAO,eAAe,CAAK,CAAC,EAM5E,SAAS,CAAO,CAAC,EAAkB,EAAkB,CACnD,IAAM,EAAW,EAAK,SAAS,QAAQ,QAAQ,EAAE,QAAQ,SAAU,EAAE,IAAM,MACrE,EAAa,EAAW,CAAC,EAAI,QAAQ,KAAK,GAAK,CAAC,QAAQ,KAAK,EAAE,EAAI,CAAC,EAC1E,GAAI,CAAC,GAAY,EAAW,SAAW,EAAG,MAAU,MAAM,kCAAkC,EAC5F,IAAO,KAAe,GAAQ,EAAQ,SAAW,CAAC,QAAQ,SAAU,GAAG,EAAY,OAAO,EAC1F,GAAI,CAAC,EAAY,MAAU,MAAM,6CAA6C,EAC9E,OAAO,EAAa,KAAK,EAAY,CAAC,GAAG,EAAM,UAAW,SAAU,GAAG,EAAG,CACxE,IAAK,QAAQ,IAAI,EAGjB,IAAK,CAAE,kBAAmB,CAAS,EACnC,UAAW,GAGX,MAAO,OACP,OAAQ,SACR,WAAY,UACZ,eAAgB,WAClB,CAAC,EAGH,IAAM,EAAe,EAAO,GAAG,yBAAyB,EACtD,SAAU,CAAC,EAAkB,CAC3B,IAAM,EAAW,E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810D09B76D7BA764756E2164756E21", | ||
| "names": [] | ||
| } |
| { | ||
| "version": 3, | ||
| "sources": ["src/ui/timeline.tsx", "src/commands/handlers/console/login.ts"], | ||
| "sourcesContent": [ | ||
| "import { createComponent as _$createComponent } from \"@opentui/solid\";\nimport { effect as _$effect } from \"@opentui/solid\";\nimport { createTextNode as _$createTextNode } from \"@opentui/solid\";\nimport { insertNode as _$insertNode } from \"@opentui/solid\";\nimport { insert as _$insert } from \"@opentui/solid\";\nimport { setProp as _$setProp } from \"@opentui/solid\";\nimport { createElement as _$createElement } from \"@opentui/solid\";\n/** @jsxImportSource @opentui/solid */\nimport { createCliRenderer, RGBA } from \"@opentui/core\";\nimport { createScrollbackWriter, render, useKeyboard } from \"@opentui/solid\";\nimport { registerOpencodeSpinner } from \"@opencode-ai/tui/component/register-spinner\";\nimport { Show, createSignal } from \"solid-js\";\nregisterOpencodeSpinner();\nconst SPINNER_FRAMES = [\"⠋\", \"⠙\", \"⠹\", \"⠸\", \"⠼\", \"⠴\", \"⠦\", \"⠧\", \"⠇\", \"⠏\"];\nconst IDLE_TIMEOUT = 1_000;\nconst COLORS = {\n accent: RGBA.fromIndex(6),\n error: RGBA.fromIndex(1),\n foreground: RGBA.defaultForeground(),\n muted: RGBA.fromIndex(8),\n success: RGBA.fromIndex(2)\n};\nconst ROWS = {\n intro: {\n marker: \"┌\",\n color: COLORS.muted,\n connector: true\n },\n item: {\n marker: \"●\",\n color: COLORS.accent,\n connector: true\n },\n success: {\n marker: \"◇\",\n color: COLORS.success,\n connector: true\n },\n failure: {\n marker: \"■\",\n color: COLORS.error,\n connector: false\n },\n outro: {\n marker: \"└\",\n color: COLORS.muted,\n connector: false\n }\n};\nfunction row(kind, value) {\n const style = ROWS[kind];\n return createScrollbackWriter(() => (() => {\n var _el$ = _$createElement(\"box\"),\n _el$2 = _$createElement(\"box\"),\n _el$3 = _$createElement(\"text\"),\n _el$4 = _$createElement(\"text\");\n _$insertNode(_el$, _el$2);\n _$setProp(_el$, \"width\", \"100%\");\n _$setProp(_el$, \"minHeight\", 1);\n _$setProp(_el$, \"flexDirection\", \"column\");\n _$insertNode(_el$2, _el$3);\n _$insertNode(_el$2, _el$4);\n _$setProp(_el$2, \"width\", \"100%\");\n _$setProp(_el$2, \"minHeight\", 1);\n _$setProp(_el$2, \"flexDirection\", \"row\");\n _$setProp(_el$2, \"gap\", 1);\n _$setProp(_el$3, \"flexShrink\", 0);\n _$insert(_el$3, () => style.marker);\n _$setProp(_el$4, \"wrapMode\", \"word\");\n _$insert(_el$4, value);\n _$insert(_el$, _$createComponent(Show, {\n get when() {\n return style.connector;\n },\n get children() {\n var _el$5 = _$createElement(\"text\");\n _$insertNode(_el$5, _$createTextNode(`│`));\n _$effect(_$p => _$setProp(_el$5, \"fg\", COLORS.muted, _$p));\n return _el$5;\n }\n }), null);\n _$effect(_p$ => {\n var _v$ = style.color,\n _v$2 = COLORS.foreground;\n _v$ !== _p$.e && (_p$.e = _$setProp(_el$3, \"fg\", _v$, _p$.e));\n _v$2 !== _p$.t && (_p$.t = _$setProp(_el$4, \"fg\", _v$2, _p$.t));\n return _p$;\n }, {\n e: undefined,\n t: undefined\n });\n return _el$;\n })(), {\n startOnNewLine: true,\n trailingNewline: !style.connector\n });\n}\nfunction TimelineFooter(props) {\n useKeyboard(event => {\n if (event.name !== \"escape\" && !(event.ctrl && event.name === \"c\")) return;\n event.preventDefault();\n props.cancel();\n });\n return (() => {\n var _el$7 = _$createElement(\"box\");\n _$setProp(_el$7, \"width\", \"100%\");\n _$setProp(_el$7, \"height\", 1);\n _$setProp(_el$7, \"flexDirection\", \"row\");\n _$setProp(_el$7, \"gap\", 1);\n _$insert(_el$7, _$createComponent(Show, {\n get when() {\n return props.pending();\n },\n children: text => [(() => {\n var _el$8 = _$createElement(\"spinner\");\n _$setProp(_el$8, \"frames\", SPINNER_FRAMES);\n _$setProp(_el$8, \"interval\", 80);\n _$effect(_$p => _$setProp(_el$8, \"color\", COLORS.accent, _$p));\n return _el$8;\n })(), (() => {\n var _el$9 = _$createElement(\"text\");\n _$setProp(_el$9, \"wrapMode\", \"none\");\n _$setProp(_el$9, \"truncate\", true);\n _$insert(_el$9, text);\n _$effect(_$p => _$setProp(_el$9, \"fg\", COLORS.foreground, _$p));\n return _el$9;\n })()]\n }));\n return _el$7;\n })();\n}\nfunction bounded(task) {\n return new Promise(resolve => {\n const timer = setTimeout(resolve, IDLE_TIMEOUT);\n timer.unref();\n const finish = () => {\n clearTimeout(timer);\n resolve();\n };\n void task.then(finish, finish);\n });\n}\nasync function shutdown(renderer) {\n await bounded(renderer.idle());\n try {\n renderer.externalOutputMode = \"passthrough\";\n } finally {\n try {\n renderer.screenMode = \"main-screen\";\n } finally {\n if (!renderer.isDestroyed) renderer.destroy();\n }\n }\n}\nexport async function createTimelineHost() {\n const stdout = process.stdout;\n const controller = new AbortController();\n const signals = [\"SIGINT\", \"SIGHUP\", \"SIGQUIT\"];\n const cancel = () => {\n if (!controller.signal.aborted) controller.abort();\n };\n signals.forEach(signal => process.on(signal, cancel));\n if (!stdout.isTTY || !process.stdin.isTTY) {\n let closed = false;\n let writing = false;\n let active;\n let closeTask;\n const write = async (kind, text) => {\n if (closed) throw new Error(\"timeline closed\");\n if (writing) throw new Error(\"timeline write already in progress\");\n writing = true;\n try {\n const style = kind === \"pending\" ? undefined : ROWS[kind];\n const marker = kind === \"pending\" ? \".\" : ROWS[kind].marker;\n const connector = style?.connector ? \"│\\n\" : \"\";\n active = new Promise((resolve, reject) => {\n stdout.write(`${marker} ${text}\\n${connector}`, error => error ? reject(error) : resolve());\n });\n await active;\n } finally {\n writing = false;\n active = undefined;\n }\n };\n const close = () => {\n if (closeTask) return closeTask;\n closed = true;\n closeTask = (async () => {\n await active?.catch(() => {});\n signals.forEach(signal => process.off(signal, cancel));\n })();\n return closeTask;\n };\n return {\n signal: controller.signal,\n intro: text => write(\"intro\", text),\n item: text => write(\"item\", text),\n pending: text => write(\"pending\", text),\n success: text => write(\"success\", text),\n failure: text => write(\"failure\", text),\n outro: text => write(\"outro\", text),\n close\n };\n }\n let renderer;\n try {\n // Start on a fresh row so delayed SSH cursor reports cannot make\n // split-footer overwrite the shell command.\n process.stdout.write(\"\\n\");\n renderer = await createCliRenderer({\n stdin: process.stdin,\n useMouse: false,\n autoFocus: false,\n openConsoleOnError: false,\n exitOnCtrlC: false,\n exitSignals: [],\n screenMode: \"split-footer\",\n footerHeight: 1,\n externalOutputMode: \"capture-stdout\",\n consoleMode: \"disabled\",\n clearOnShutdown: false\n });\n const activeRenderer = renderer;\n const [pending, setPending] = createSignal();\n const renderTask = render(() => _$createComponent(TimelineFooter, {\n pending: pending,\n cancel: cancel\n }), activeRenderer);\n void renderTask.catch(cancel);\n await bounded(activeRenderer.idle());\n let closed = false;\n let writing = false;\n let active;\n let closeTask;\n const write = (kind, text) => {\n if (closed) return Promise.reject(new Error(\"timeline closed\"));\n if (writing) return Promise.reject(new Error(\"timeline write already in progress\"));\n writing = true;\n active = (async () => {\n if (kind === \"pending\") {\n setPending(text);\n activeRenderer.requestRender();\n } else {\n if (kind === \"success\" || kind === \"failure\" || kind === \"outro\") setPending(undefined);\n activeRenderer.writeToScrollback(row(kind, text));\n activeRenderer.requestRender();\n }\n await bounded(activeRenderer.idle());\n })().finally(() => {\n writing = false;\n active = undefined;\n });\n return active;\n };\n const close = () => {\n if (closeTask) return closeTask;\n closed = true;\n closeTask = (async () => {\n await active?.catch(() => {});\n try {\n await shutdown(activeRenderer);\n await bounded(renderTask);\n } finally {\n signals.forEach(signal => process.off(signal, cancel));\n }\n })();\n return closeTask;\n };\n return {\n signal: controller.signal,\n intro: text => write(\"intro\", text),\n item: text => write(\"item\", text),\n pending: text => write(\"pending\", text),\n success: text => write(\"success\", text),\n failure: text => write(\"failure\", text),\n outro: text => write(\"outro\", text),\n close\n };\n } catch (error) {\n try {\n if (renderer) await shutdown(renderer);\n } finally {\n signals.forEach(signal => process.off(signal, cancel));\n }\n throw error;\n }\n}", | ||
| "import { Cause, Effect, Exit, Option } from \"effect\"\nimport { Service } from \"@opencode-ai/client/effect/service\"\nimport { OpenCode, type OpenCodeClient } from \"@opencode-ai/client/promise\"\nimport { AppProcess } from \"@opencode-ai/core/process\"\nimport { Commands } from \"../../commands\"\nimport { Runtime } from \"../../../framework/runtime\"\nimport { ServiceConfig } from \"../../../services/service-config\"\nimport { createTimelineHost, type TimelineHost } from \"../../../ui/timeline\"\n\nconst integrationID = \"opencode\"\nconst location = { directory: process.cwd() }\n\nexport default Runtime.handler(\n Commands.commands.console.commands.login,\n Effect.fn(\"cli.console.login\")(function* (input) {\n const timeline = yield* Effect.acquireRelease(\n Effect.promise(() => createTimelineHost()),\n (value) => request(() => value.close()).pipe(Effect.ignore),\n )\n const exit = yield* login(timeline, Option.getOrUndefined(input.url)).pipe(\n Effect.raceFirst(AppProcess.waitForAbort(timeline.signal)),\n Effect.exit,\n )\n if (Exit.isSuccess(exit)) return\n\n const cancelled = timeline.signal.aborted\n yield* request(() => timeline.failure(cancelled ? \"Authorization cancelled\" : errorMessage(exit.cause))).pipe(\n Effect.ignore,\n )\n process.exitCode = cancelled ? 130 : 1\n }),\n)\n\nconst login = Effect.fn(\"cli.console.login.run\")(function* (timeline: TimelineHost, server?: string) {\n yield* request(() => timeline.intro(\"Log in\"))\n yield* request(() => timeline.pending(\"Connecting to OpenCode...\"))\n\n const endpoint = yield* Service.ensure(yield* ServiceConfig.options())\n const client = OpenCode.make({ baseUrl: endpoint.url, headers: Service.headers(endpoint) })\n const found = yield* request((signal) => client.integration.get({ integrationID, location }, { signal }))\n const integration = yield* required(found.data, \"OpenCode Console integration is unavailable\")\n const method = yield* required(\n integration.methods.find((candidate) => candidate.type === \"oauth\"),\n \"OpenCode Console login is unavailable\",\n )\n\n yield* request(() => timeline.pending(\"Starting authorization...\"))\n const started = yield* request((signal) =>\n client.integration.connect.oauth(\n {\n integrationID,\n methodID: method.id,\n inputs: server ? { server } : {},\n location,\n },\n { signal },\n ),\n )\n const attempt = started.data\n yield* Effect.addFinalizer(() =>\n request(() =>\n client.integration.attempt.cancel(\n { attemptID: attempt.attemptID, location },\n { signal: AbortSignal.timeout(5_000) },\n ),\n ).pipe(Effect.ignore),\n )\n if (attempt.mode !== \"auto\") yield* Effect.fail(new Error(\"OpenCode Console requires a device login\"))\n\n yield* request(() => timeline.item(`Go to: ${attempt.url}`))\n yield* request(() => timeline.item(attempt.instructions))\n yield* request(async () => {\n const { default: open } = await import(\"open\")\n await open(attempt.url)\n }).pipe(Effect.ignore)\n yield* request(() => timeline.pending(\"Waiting for authorization...\"))\n\n const status = yield* waitForConsoleLogin(client, attempt.attemptID)\n if (status.status === \"failed\") yield* Effect.fail(new Error(status.message))\n if (status.status === \"expired\") yield* Effect.fail(new Error(\"Device code expired\"))\n\n yield* request(() => timeline.success(\"Connected to OpenCode Console\"))\n yield* request(() => timeline.outro(\"Done\"))\n})\n\nconst waitForConsoleLogin = Effect.fn(\"cli.console.login.wait\")(function* (\n client: OpenCodeClient,\n attemptID: string,\n) {\n while (true) {\n const response = yield* request((signal) =>\n client.integration.attempt.status({ attemptID, location }, { signal }),\n )\n if (response.data.status !== \"pending\") return response.data\n yield* Effect.sleep(500)\n }\n})\n\nfunction request<A>(task: (signal: AbortSignal) => Promise<A>) {\n return Effect.tryPromise({\n try: task,\n catch: (cause) => cause,\n })\n}\n\nfunction required<A>(value: A | null | undefined, message: string) {\n return value === null || value === undefined ? Effect.fail(new Error(message)) : Effect.succeed(value)\n}\n\nfunction errorMessage(cause: Cause.Cause<unknown>) {\n const error = Cause.squash(cause)\n if (error instanceof Error) return error.message\n if (typeof error === \"object\" && error !== null && \"message\" in error && typeof error.message === \"string\") {\n return error.message\n }\n return String(error)\n}\n" | ||
| ], | ||
| "mappings": ";4nCAYA,OAAwB,OACxB,SAAM,OAAiB,MAAC,cAAI,cAAK,cAAK,cAAK,cAAK,cAAK,cAAK,cAAK,cAAK,aAAG,OACjE,QAAe,UACf,OAAS,MACb,YAAQ,OAAK,eAAU,MAAC,OACxB,M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AAU,MAAQ,YAAa,GAAS,OAAO,EAAM,UAAY,SAChG,OAAO,EAAM,QAEf,OAAO,OAAO,CAAK", | ||
| "debugId": "73050DE0FBEBCECE64756E2164756E21", | ||
| "names": [] | ||
| } |
+1
-1
| { | ||
| "name": "@opencode-ai/cli-linux-arm64", | ||
| "version": "0.0.0-next-15623", | ||
| "version": "0.0.0-next-15624", | ||
| "license": "MIT", | ||
@@ -5,0 +5,0 @@ "repository": { |
| { | ||
| "version": 3, | ||
| "sources": ["src/commands/handlers/api.ts"], | ||
| "sourcesContent": [ | ||
| "import { EOL } from \"node:os\"\nimport { Effect, Option } from \"effect\"\nimport { Commands } from \"../commands\"\nimport { Runtime } from \"../../framework/runtime\"\nimport { Service, type Endpoint } from \"@opencode-ai/client/effect/service\"\nimport { ServerConnection } from \"../../services/server-connection\"\n\nconst methods = new Set([\"delete\", \"get\", \"head\", \"options\", \"patch\", \"post\", \"put\"])\n\ntype Operation = {\n operationId?: string\n}\n\ntype OpenApi = {\n paths?: Record<string, Record<string, Operation>>\n}\n\nexport default Runtime.handler(\n Commands.commands.api,\n Effect.fn(\"cli.api\")(function* (input) {\n const server = yield* ServerConnection.resolve({\n server: Option.getOrUndefined(input.server),\n standalone: input.standalone,\n mismatch: \"ignore\",\n })\n const endpoint = server.endpoint\n const params = Option.getOrElse(input.param, () => ({}))\n const request = yield* resolveRequest(endpoint, input.request, params)\n const headers = new Headers(Service.headers(endpoint))\n for (const header of input.header) {\n const index = header.indexOf(\":\")\n if (index < 1) return yield* Effect.fail(new Error(`Invalid header, expected name:value: ${header}`))\n headers.set(header.slice(0, index).trim(), header.slice(index + 1).trim())\n }\n const body = Option.getOrUndefined(input.data)\n if (body !== undefined && !headers.has(\"content-type\")) headers.set(\"content-type\", \"application/json\")\n\n const response = yield* Effect.tryPromise(() =>\n fetch(new URL(request.path, endpoint.url), {\n method: request.method,\n headers,\n body,\n }),\n )\n const output = yield* Effect.promise(() => response.text())\n if (output) process.stdout.write(output + (output.endsWith(EOL) ? \"\" : EOL))\n }),\n)\n\nexport function resolveOperation(spec: OpenApi, operationID: string, params: Record<string, string>) {\n for (const [path, operations] of Object.entries(spec.paths ?? {})) {\n for (const [method, operation] of Object.entries(operations)) {\n if (!methods.has(method) || operation.operationId !== operationID) continue\n return { method: method.toUpperCase(), path: interpolate(path, params) }\n }\n }\n throw new Error(`Operation not found: ${operationID}`)\n}\n\nexport function rawRequest(input: readonly string[]) {\n if (input.length !== 2 || !methods.has(input[0].toLowerCase()) || !input[1].startsWith(\"/\")) return\n return { method: input[0].toUpperCase(), path: input[1] }\n}\n\nfunction resolveRequest(endpoint: Endpoint, input: readonly string[], params: Record<string, string>) {\n const raw = rawRequest(input)\n if (raw) return Effect.succeed(raw)\n if (input.length !== 1) return Effect.fail(new Error(\"Expected an operation name or an HTTP method and path\"))\n return Effect.tryPromise(async () => {\n const response = await fetch(new URL(\"/openapi.json\", endpoint.url), { headers: Service.headers(endpoint) })\n if (!response.ok) throw new Error(`Failed to load OpenAPI document: HTTP ${response.status}`)\n return resolveOperation((await response.json()) as OpenApi, input[0], params)\n })\n}\n\nfunction interpolate(path: string, params: Record<string, string>) {\n const used = new Set<string>()\n const pathname = path.replaceAll(/\\{([^}]+)\\}/g, (_, name: string) => {\n const value = params[name]\n if (value === undefined) throw new Error(`Missing path parameter: ${name}`)\n used.add(name)\n return encodeURIComponent(value)\n })\n const query = new URLSearchParams(Object.entries(params).filter(([name]) => !used.has(name))).toString()\n return query ? `${pathname}?${query}` : pathname\n}\n" | ||
| ], | ||
| "mappings": ";ixCAAA,mBAAS,gBAOT,SAAM,OAAU,SAAI,SAAI,MAAC,cAAU,WAAO,YAAQ,eAAW,aAAS,YAAQ,UAAK,MAAC,OAUrE,SAAQ,aACrB,OAAS,cAAS,SAClB,OAAO,QAAG,cAAS,OAAE,cAAU,MAAC,OAAO,MAMrC,SAAM,QALS,WAAO,OAAiB,aAAQ,MAC7C,OAAQ,EAAO,eAAe,EAAM,MAAM,EAC1C,WAAY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AI,EAAM,SAAW,GAAK,CAAC,EAAQ,IAAI,EAAM,GAAG,YAAY,CAAC,GAAK,CAAC,EAAM,GAAG,WAAW,GAAG,EAAG,OAC7F,MAAO,CAAE,OAAQ,EAAM,GAAG,YAAY,EAAG,KAAM,EAAM,EAAG,EAG1D,SAAS,CAAc,CAAC,EAAoB,EAA0B,EAAgC,CACpG,IAAM,EAAM,EAAW,CAAK,EAC5B,GAAI,EAAK,OAAO,EAAO,QAAQ,CAAG,EAClC,GAAI,EAAM,SAAW,EAAG,OAAO,EAAO,KAAS,MAAM,uDAAuD,CAAC,EAC7G,OAAO,EAAO,WAAW,SAAY,CACnC,IAAM,EAAW,MAAM,MAAM,IAAI,IAAI,gBAAiB,EAAS,GAAG,EAAG,CAAE,QAAS,EAAQ,QAAQ,CAAQ,CAAE,CAAC,EAC3G,GAAI,CAAC,EAAS,GAAI,MAAU,MAAM,yCAAyC,EAAS,QAAQ,EAC5F,OAAO,EAAkB,MAAM,EAAS,KAAK,EAAe,EAAM,GAAI,CAAM,EAC7E,EAGH,SAAS,CAAW,CAAC,EAAc,EAAgC,CACjE,IAAM,EAAO,IAAI,IACX,EAAW,EAAK,WAAW,eAAgB,CAAC,EAAG,IAAiB,CACpE,IAAM,EAAQ,EAAO,GACrB,GAAI,IAAU,OAAW,MAAU,MAAM,2BAA2B,GAAM,EAE1E,OADA,EAAK,IAAI,CAAI,EACN,mBAAmB,CAAK,EAChC,EACK,EAAQ,IAAI,gBAAgB,OAAO,QAAQ,CAAM,EAAE,OAAO,EAAE,KAAU,CAAC,EAAK,IAAI,CAAI,CAAC,CAAC,EAAE,SAAS,EACvG,OAAO,EAAQ,GAAG,KAAY,IAAU", | ||
| "debugId": "2FBE91234BAAAB5964756E2164756E21", | ||
| "names": [] | ||
| } |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
| { | ||
| "version": 3, | ||
| "sources": ["src/commands/handlers/pair.ts"], | ||
| "sourcesContent": [ | ||
| "import { EOL } from \"os\"\nimport { Effect } from \"effect\"\nimport { Service } from \"@opencode-ai/client/effect/service\"\nimport { OpenCode } from \"@opencode-ai/client/promise\"\nimport { renderUnicodeCompact } from \"uqr\"\nimport { Commands } from \"../commands\"\nimport { Runtime } from \"../../framework/runtime\"\nimport { ServiceConfig } from \"../../services/service-config\"\n\nexport default Runtime.handler(\n Commands.commands.pair,\n Effect.fn(\"cli.pair\")(function* () {\n const endpoint = yield* Service.ensure(yield* ServiceConfig.options())\n const password = yield* ServiceConfig.password()\n const server = yield* Effect.tryPromise(() =>\n OpenCode.make({ baseUrl: endpoint.url, headers: Service.headers(endpoint) }).server.get(),\n )\n const info = { urls: server.urls, username: \"opencode\", password }\n process.stdout.write(\n [\n \"\",\n ` URLs ${info.urls[0] ?? \"(none)\"}`,\n ...info.urls.slice(1).map((url) => ` ${url}`),\n ` Username ${info.username}`,\n ` Password ${info.password}`,\n \"\",\n \" Scan to pair\",\n \"\",\n renderUnicodeCompact(JSON.stringify(info), { border: 2 })\n .split(EOL)\n .map((line) => \" \" + line)\n .join(EOL),\n \"\",\n ].join(EOL) + EOL,\n )\n\n const hostname = new URL(endpoint.url).hostname\n if (![\"localhost\", \"127.0.0.1\", \"[::1]\"].includes(hostname)) return\n process.stderr.write(\n ` Run \\`opencode service set hostname 0.0.0.0\\` to access the service remotely.${EOL}${EOL}`,\n )\n }),\n)\n" | ||
| ], | ||
| "mappings": ";88BAAA,mBAAS,gBAST,SAAe,SAAQ,aACrB,OAAS,cAAS,UAClB,OAAO,QAAG,eAAU,OAAE,cAAU,OAAG,MACjC,SAAM,OAAW,WAAO,OAAQ,YAAO,WAAO,OAAc,aAAQ,MAAC,OAC/D,EAAW,MAAO,EAAc,SAAS,EAIzC,EAAO,CAAE,MAHA,MAAO,EAAO,WAAW,IACtC,EAAS,KAAK,CAAE,QAAS,EAAS,IAAK,QAAS,EAAQ,QAAQ,CAAQ,CAAE,CAAC,EAAE,OAAO,IAAI,CAC1F,GAC4B,KAAM,SAAU,WAAY,UAAS,EACjE,QAAQ,OAAO,MACb,CACE,GACA,eAAe,EAAK,KAAK,IAAM,WAC/B,GAAG,EAAK,KAAK,MAAM,CAAC,EAAE,IAAI,CAAC,IAAQ,eAAe,GAAK,EACvD,eAAe,EAAK,WACpB,eAAe,EAAK,WACpB,GACA,iBACA,GACA,EAAqB,KAAK,UAAU,CAAI,EAAG,CAAE,OAAQ,CAAE,CAAC,EACrD,MAAM,CAAG,EACT,IAAI,CAAC,IAAS,KAAO,CAAI,EACzB,KAAK,CAAG,EACX,EACF,EAAE,KAAK,CAAG,EAAI,CAChB,EAEA,IAAM,EAAW,IAAI,IAAI,EAAS,GAAG,EAAE,SACvC,GAAI,CAAC,CAAC,YAAa,YAAa,OAAO,EAAE,SAAS,CAAQ,EAAG,OAC7D,QAAQ,OAAO,MACb,kFAAkF,IAAM,GAC1F,EACD,CACH", | ||
| "debugId": "D7DDF03BCD730C8C64756E2164756E21", | ||
| "names": [] | ||
| } |
Sorry, the diff of this file is too big to display
| { | ||
| "version": 3, | ||
| "sources": ["src/commands/handlers/service/stop.ts"], | ||
| "sourcesContent": [ | ||
| "import { Effect } from \"effect\"\nimport { Service } from \"@opencode-ai/client/effect/service\"\nimport { Commands } from \"../../commands\"\nimport { Runtime } from \"../../../framework/runtime\"\nimport { ServiceConfig } from \"../../../services/service-config\"\n\nexport default Runtime.handler(\n Commands.commands.service.commands.stop,\n Effect.fn(\"cli.service.stop\")(function* () {\n yield* Service.stop(yield* ServiceConfig.options())\n }),\n)\n" | ||
| ], | ||
| "mappings": ";i3BAMA,SAAe,SAAQ,aACrB,OAAS,cAAS,aAAQ,cAAS,UACnC,OAAO,QAAG,uBAAkB,OAAE,cAAU,OAAG,MACzC,WAAO,OAAQ,UAAK,WAAO,OAAc,aAAQ,MAAC,OACnD,CACH", | ||
| "debugId": "A0D2AF57F7CC7F0F64756E2164756E21", | ||
| "names": [] | ||
| } |
| { | ||
| "version": 3, | ||
| "sources": ["src/mini/variant.shared.ts", "src/mini/session.shared.ts", "src/mini/theme.ts"], | ||
| "sourcesContent": [ | ||
| "// Model variant resolution and persistence.\n//\n// Variants are provider-specific reasoning effort levels (e.g., \"high\", \"max\").\n// Resolution priority: CLI --variant flag > saved preference > session history.\n//\n// The saved variant persists across sessions in ~/.local/state/opencode/model.json\n// so your last-used variant sticks. Cycling (ctrl+t) updates both the active\n// variant and the persisted file.\nimport path from \"path\"\nimport { FSUtil } from \"@opencode-ai/core/fs-util\"\nimport { AppNodeBuilder } from \"@opencode-ai/core/effect/app-node-builder\"\nimport { Context, Effect, Layer } from \"effect\"\nimport { LayerNode } from \"@opencode-ai/core/effect/layer-node\"\nimport { makeGlobalNode } from \"@opencode-ai/core/effect/app-node\"\nimport { makeRuntime } from \"@opencode-ai/core/effect/runtime\"\nimport { Global } from \"@opencode-ai/core/global\"\nimport { createSession, sessionVariant, type RunSession, type SessionMessages } from \"./session.shared\"\nimport type { RunInput, RunProvider } from \"./types\"\n\nconst MODEL_FILE = path.join(Global.Path.state, \"model.json\")\n\ntype ModelState = Record<string, unknown> & {\n variant?: Record<string, string | undefined>\n}\ntype VariantService = {\n readonly resolveSavedVariant: (model: RunInput[\"model\"]) => Effect.Effect<string | undefined>\n readonly saveVariant: (model: RunInput[\"model\"], variant: string | undefined) => Effect.Effect<void>\n}\ntype VariantRuntime = {\n resolveSavedVariant(model: RunInput[\"model\"]): Promise<string | undefined>\n saveVariant(model: RunInput[\"model\"], variant: string | undefined): Promise<void>\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return !!value && typeof value === \"object\" && !Array.isArray(value)\n}\n\nclass Service extends Context.Service<Service, VariantService>()(\"@opencode/RunVariant\") {}\n\nfunction modelKey(provider: string, model: string): string {\n return `${provider}/${model}`\n}\n\nfunction variantKey(model: NonNullable<RunInput[\"model\"]>): string {\n return modelKey(model.providerID, model.modelID)\n}\n\nexport function modelInfo(providers: RunProvider[] | undefined, model: NonNullable<RunInput[\"model\"]>) {\n const provider = providers?.find((item) => item.id === model.providerID)\n return {\n provider: provider?.name ?? model.providerID,\n model: provider?.models[model.modelID]?.name ?? model.modelID,\n }\n}\n\nexport function formatModelLabel(\n model: NonNullable<RunInput[\"model\"]>,\n variant: string | undefined,\n providers?: RunProvider[],\n): string {\n const names = modelInfo(providers, model)\n const label = variant ? ` · ${variant}` : \"\"\n return `${names.model} · ${names.provider}${label}`\n}\n\nexport function cycleVariant(current: string | undefined, variants: string[]): string | undefined {\n if (variants.length === 0) {\n return undefined\n }\n\n if (!current) {\n return variants[0]\n }\n\n const idx = variants.indexOf(current)\n if (idx === -1 || idx === variants.length - 1) {\n return undefined\n }\n\n return variants[idx + 1]\n}\n\nexport function pickVariant(model: RunInput[\"model\"], input: RunSession | SessionMessages): string | undefined {\n return sessionVariant(Array.isArray(input) ? createSession(input) : input, model)\n}\n\nfunction fitVariant(value: string | undefined, variants: string[]): string | undefined {\n if (!value) {\n return undefined\n }\n\n if (variants.length === 0 || variants.includes(value)) {\n return value\n }\n\n return undefined\n}\n\n// Picks the active variant. CLI flag wins, then saved preference, then session\n// history. fitVariant() checks saved and session values against the available\n// variants list -- if the provider doesn't offer a variant, it drops.\nexport function resolveVariant(\n input: string | undefined,\n session: string | undefined,\n saved: string | undefined,\n variants: string[],\n): string | undefined {\n if (input !== undefined) {\n return input\n }\n\n const fallback = fitVariant(saved, variants)\n const current = fitVariant(session, variants)\n if (current !== undefined) {\n return current\n }\n\n return fallback\n}\n\nfunction state(value: unknown): ModelState {\n if (!isRecord(value)) {\n return {}\n }\n\n const variant = isRecord(value.variant)\n ? Object.fromEntries(\n Object.entries(value.variant).flatMap(([key, item]) => {\n if (typeof item !== \"string\") {\n return []\n }\n\n return [[key, item] as const]\n }),\n )\n : undefined\n\n return {\n ...value,\n variant,\n }\n}\n\nconst layer = Layer.fresh(\n Layer.effect(\n Service,\n Effect.gen(function* () {\n const file = yield* FSUtil.Service\n\n const read = Effect.fn(\"RunVariant.read\")(function* () {\n return yield* file.readJson(MODEL_FILE).pipe(\n Effect.map(state),\n Effect.catchCause(() => Effect.succeed(state(undefined))),\n )\n })\n\n const resolveSavedVariant = Effect.fn(\"RunVariant.resolveSavedVariant\")(function* (model: RunInput[\"model\"]) {\n if (!model) {\n return undefined\n }\n\n return (yield* read()).variant?.[variantKey(model)]\n })\n\n const saveVariant = Effect.fn(\"RunVariant.saveVariant\")(function* (\n model: RunInput[\"model\"],\n variant: string | undefined,\n ) {\n if (!model) {\n return\n }\n\n const current = yield* read()\n const next = {\n ...current.variant,\n }\n const key = variantKey(model)\n if (variant) {\n next[key] = variant\n }\n\n if (!variant) {\n delete next[key]\n }\n\n yield* file\n .writeJson(MODEL_FILE, {\n ...current,\n variant: next,\n })\n .pipe(Effect.orElseSucceed(() => undefined))\n })\n\n return Service.of({\n resolveSavedVariant,\n saveVariant,\n })\n }),\n ),\n)\n\nconst node = makeGlobalNode({ service: Service, layer, deps: [FSUtil.node] })\n\n/** @internal Exported for testing. */\nexport function createVariantRuntime(replacements?: readonly LayerNode.Replacement[]): VariantRuntime {\n const runtime = makeRuntime(Service, AppNodeBuilder.build(node, replacements))\n return {\n resolveSavedVariant: (model) => runtime.runPromise((svc) => svc.resolveSavedVariant(model)).catch(() => undefined),\n saveVariant: (model, variant) => runtime.runPromise((svc) => svc.saveVariant(model, variant)).catch(() => {}),\n }\n}\n\nconst runtime = createVariantRuntime()\n\nexport async function resolveSavedVariant(model: RunInput[\"model\"]): Promise<string | undefined> {\n return runtime.resolveSavedVariant(model)\n}\n\nexport function saveVariant(model: RunInput[\"model\"], variant: string | undefined): void {\n void runtime.saveVariant(model, variant)\n}\n", | ||
| "import type { SessionMessageInfo, SessionMessageUser } from \"@opencode-ai/client/promise\"\nimport { promptCopy, promptSame } from \"./prompt.shared\"\nimport type { RunInput, RunPrompt } from \"./types\"\n\nconst LIMIT = 200\n\nexport type SessionMessages = SessionMessageInfo[]\n\ntype Turn = {\n prompt: RunPrompt\n provider: string | undefined\n model: string | undefined\n variant: string | undefined\n}\n\nexport type RunSession = {\n first: boolean\n turns: Turn[]\n model?: NonNullable<RunInput[\"model\"]>\n variant?: string\n}\n\nfunction messagePrompt(message: SessionMessageUser): RunPrompt {\n return {\n text: message.text,\n parts: [\n ...(message.files ?? []).map((file) => ({\n type: \"file\" as const,\n url: file.source.type === \"uri\" ? file.source.uri : `data:${file.mime};base64,${file.data}`,\n mime: file.mime,\n filename: file.name,\n source: file.mention\n ? {\n type: \"file\",\n path: file.name ?? (file.source.type === \"uri\" ? file.source.uri : \"inline attachment\"),\n text: { start: file.mention.start, end: file.mention.end, value: file.mention.text },\n }\n : undefined,\n })),\n ...(message.agents ?? []).map((agent) => ({\n type: \"agent\" as const,\n name: agent.name,\n source: agent.mention\n ? { start: agent.mention.start, end: agent.mention.end, value: agent.mention.text }\n : undefined,\n })),\n ],\n }\n}\n\nexport function createSession(messages: SessionMessages): RunSession {\n return {\n first: messages.length === 0,\n turns: messages.flatMap((message) =>\n message.type === \"user\"\n ? [{ prompt: messagePrompt(message), provider: undefined, model: undefined, variant: undefined }]\n : [],\n ),\n }\n}\n\nexport async function resolveCurrentSession(\n sdk: RunInput[\"sdk\"],\n sessionID: string,\n limit = LIMIT,\n): Promise<RunSession> {\n const [response, session] = await Promise.all([\n sdk.message.list({ sessionID, limit, order: \"desc\" }),\n sdk.session.get({ sessionID }),\n ])\n const current = createSession(response.data.toReversed())\n return {\n ...current,\n turns: current.turns.map((turn) => ({\n ...turn,\n provider: session.model?.providerID,\n model: session.model?.id,\n variant: session.model?.variant,\n })),\n ...(session.model && {\n model: { providerID: session.model.providerID, modelID: session.model.id },\n variant: session.model.variant,\n }),\n }\n}\n\nexport function sessionHistory(session: RunSession, limit = LIMIT): RunPrompt[] {\n return session.turns\n .map((turn) => turn.prompt)\n .filter((prompt) => prompt.text.trim())\n .filter((prompt, index, prompts) => index === 0 || !promptSame(prompts[index - 1], prompt))\n .map(promptCopy)\n .slice(-limit)\n}\n\nexport function sessionVariant(session: RunSession, model: RunInput[\"model\"]): string | undefined {\n if (!model) return\n if (session.model?.providerID === model.providerID && session.model.modelID === model.modelID) return session.variant\n\n return session.turns.findLast((turn) => turn.provider === model.providerID && turn.model === model.modelID)?.variant\n}\n", | ||
| "// Theme resolution for direct interactive mode.\n//\n// Derives scrollback and footer colors from the terminal's actual palette.\n// resolveRunTheme() queries the renderer for the terminal's palette,\n// detects dark/light mode, builds a small system theme locally, and maps it to\n// the run footer + scrollback color model. Falls back to a hardcoded dark-mode\n// palette if detection fails.\nimport { RGBA, SyntaxStyle, type CliRenderer, type ColorInput, type TerminalColors } from \"@opentui/core\"\nimport type { TuiThemeCurrent } from \"@opencode-ai/plugin/tui\"\nimport type { EntryKind } from \"./types\"\n\ntype Tone = {\n body: ColorInput\n start?: ColorInput\n}\n\nexport type RunEntryTheme = Record<EntryKind, Tone>\n\nexport type RunSplashTheme = {\n left: ColorInput\n right: ColorInput\n leftShadow: ColorInput\n rightShadow: ColorInput\n}\n\nexport type RunFooterTheme = {\n highlight: ColorInput\n selected: ColorInput\n selectedText: ColorInput\n warning: ColorInput\n success: ColorInput\n error: ColorInput\n muted: ColorInput\n text: ColorInput\n status: ColorInput\n statusAccent: ColorInput\n shade: ColorInput\n surface: ColorInput\n pane: ColorInput\n border: ColorInput\n line: ColorInput\n}\n\nexport type RunBlockTheme = {\n highlight: ColorInput\n warning: ColorInput\n text: ColorInput\n muted: ColorInput\n syntax?: SyntaxStyle\n diffAdded: ColorInput\n diffRemoved: ColorInput\n diffAddedBg: ColorInput\n diffRemovedBg: ColorInput\n diffContextBg: ColorInput\n diffHighlightAdded: ColorInput\n diffHighlightRemoved: ColorInput\n diffLineNumber: ColorInput\n diffAddedLineNumberBg: ColorInput\n diffRemovedLineNumberBg: ColorInput\n}\n\nexport type RunTheme = {\n background: ColorInput\n footer: RunFooterTheme\n entry: RunEntryTheme\n splash: RunSplashTheme\n block: RunBlockTheme\n}\n\ntype ThemeColor = Exclude<keyof TuiThemeCurrent, \"thinkingOpacity\">\ntype HexColor = `#${string}`\ntype RefName = string\ntype Variant = {\n dark: HexColor | RefName\n light: HexColor | RefName\n}\ntype ColorValue = HexColor | RefName | Variant | RGBA | number\ntype ThemeJson = {\n defs?: Record<string, HexColor | RefName>\n theme: Omit<Record<ThemeColor, ColorValue>, \"selectedListItemText\" | \"backgroundMenu\"> & {\n selectedListItemText?: ColorValue\n backgroundMenu?: ColorValue\n thinkingOpacity?: number\n }\n}\n\ntype SharedSyntaxTheme = TuiThemeCurrent & {\n _hasSelectedListItemText: boolean\n}\n\nexport const transparent = RGBA.fromValues(0, 0, 0, 0)\n\nfunction alpha(color: RGBA, value: number): RGBA {\n return RGBA.fromValues(color.r, color.g, color.b, Math.max(0, Math.min(1, value)))\n}\n\nfunction rgba(hex: string, value?: number): RGBA {\n const color = RGBA.fromHex(hex)\n return value === undefined ? color : alpha(color, value)\n}\n\nfunction mode(bg: RGBA): \"dark\" | \"light\" {\n return luminance(bg) > 0.5 ? \"light\" : \"dark\"\n}\n\nfunction luminance(color: RGBA): number {\n return 0.299 * color.r + 0.587 * color.g + 0.114 * color.b\n}\n\nfunction fade(color: RGBA, base: RGBA, fallback: number, scale: number, limit: number): RGBA {\n if (color.a === 0) {\n return RGBA.fromValues(color.r, color.g, color.b, Math.max(0, Math.min(1, fallback)))\n }\n\n const target = Math.min(limit, color.a * scale)\n const mix = Math.min(1, target / color.a)\n\n return RGBA.fromValues(\n base.r + (color.r - base.r) * mix,\n base.g + (color.g - base.g) * mix,\n base.b + (color.b - base.b) * mix,\n color.a,\n )\n}\n\nfunction ansiToRgba(code: number): RGBA {\n if (code < 16) {\n const ansi = [\n \"#000000\",\n \"#800000\",\n \"#008000\",\n \"#808000\",\n \"#000080\",\n \"#800080\",\n \"#008080\",\n \"#c0c0c0\",\n \"#808080\",\n \"#ff0000\",\n \"#00ff00\",\n \"#ffff00\",\n \"#0000ff\",\n \"#ff00ff\",\n \"#00ffff\",\n \"#ffffff\",\n ]\n return RGBA.fromHex(ansi[code] ?? \"#000000\")\n }\n\n if (code < 232) {\n const index = code - 16\n const b = index % 6\n const g = Math.floor(index / 6) % 6\n const r = Math.floor(index / 36)\n const value = (x: number) => (x === 0 ? 0 : x * 40 + 55)\n return RGBA.fromInts(value(r), value(g), value(b))\n }\n\n if (code < 256) {\n const gray = (code - 232) * 10 + 8\n return RGBA.fromInts(gray, gray, gray)\n }\n\n return RGBA.fromInts(0, 0, 0)\n}\n\nfunction tint(base: RGBA, overlay: RGBA, value: number): RGBA {\n return RGBA.fromInts(\n Math.round((base.r + (overlay.r - base.r) * value) * 255),\n Math.round((base.g + (overlay.g - base.g) * value) * 255),\n Math.round((base.b + (overlay.b - base.b) * value) * 255),\n )\n}\n\nfunction chroma(color: RGBA) {\n return Math.max(color.r, color.g, color.b) - Math.min(color.r, color.g, color.b)\n}\n\nfunction indexedPalette(colors: TerminalColors, size: number = Math.max(colors.palette.length, 16)): RGBA[] {\n return Array.from({ length: size }, (_, index) => {\n const value = colors.palette[index]\n return RGBA.fromIndex(index, value ? RGBA.fromHex(value) : ansiToRgba(index))\n })\n}\n\nfunction srgbToLinear(value: number): number {\n if (value <= 0.04045) {\n return value / 12.92\n }\n\n return ((value + 0.055) / 1.055) ** 2.4\n}\n\nfunction oklab(color: RGBA) {\n const r = srgbToLinear(color.r)\n const g = srgbToLinear(color.g)\n const b = srgbToLinear(color.b)\n\n const l = Math.cbrt(0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b)\n const m = Math.cbrt(0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b)\n const s = Math.cbrt(0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b)\n\n return {\n l: 0.2104542553 * l + 0.793617785 * m - 0.0040720468 * s,\n a: 1.9779984951 * l - 2.428592205 * m + 0.4505937099 * s,\n b: 0.0259040371 * l + 0.7827717662 * m - 0.808675766 * s,\n }\n}\n\nfunction nearestIndexed(indexed: RGBA[], rgba: RGBA): RGBA {\n const target = oklab(rgba)\n const hit = indexed.reduce(\n (best, item) => {\n const sample = oklab(item)\n const dl = sample.l - target.l\n const da = sample.a - target.a\n const db = sample.b - target.b\n const dist = dl * dl * 2 + da * da + db * db\n if (dist >= best.dist) return best\n return {\n dist,\n item,\n }\n },\n {\n dist: Number.POSITIVE_INFINITY,\n item: indexed[0]!,\n },\n )\n\n return RGBA.clone(hit.item)\n}\n\nfunction paletteColor(colors: TerminalColors, index: number): RGBA {\n const value = colors.palette[index]\n return value ? RGBA.fromHex(value) : ansiToRgba(index)\n}\n\nfunction splashShadow(indexed: RGBA[], base: RGBA, overlay: RGBA, value: number): RGBA {\n const mixed = tint(base, overlay, value)\n return nearestIndexed(indexed, mixed)\n}\n\nexport function resolveTheme(theme: ThemeJson, pick: \"dark\" | \"light\"): TuiThemeCurrent {\n const defs = theme.defs ?? {}\n\n const resolveColor = (value: ColorValue, chain: string[] = []): RGBA => {\n if (value instanceof RGBA) return value\n\n if (typeof value === \"number\") {\n return RGBA.fromIndex(value, ansiToRgba(value))\n }\n\n if (typeof value !== \"string\") {\n return resolveColor(value[pick], chain)\n }\n\n if (value === \"transparent\" || value === \"none\") {\n return RGBA.fromInts(0, 0, 0, 0)\n }\n\n if (value.startsWith(\"#\")) {\n return RGBA.fromHex(value)\n }\n\n if (chain.includes(value)) {\n throw new Error(`Circular color reference: ${[...chain, value].join(\" -> \")}`)\n }\n\n const next = defs[value] ?? theme.theme[value as ThemeColor]\n if (next === undefined) {\n throw new Error(`Color reference \"${value}\" not found in defs or theme`)\n }\n\n return resolveColor(next, [...chain, value])\n }\n\n const resolved = Object.fromEntries(\n Object.entries(theme.theme)\n .filter(([key]) => key !== \"selectedListItemText\" && key !== \"backgroundMenu\" && key !== \"thinkingOpacity\")\n .map(([key, value]) => [key, resolveColor(value as ColorValue)]),\n ) as Partial<Record<ThemeColor, RGBA>>\n\n return {\n ...(resolved as Record<ThemeColor, RGBA>),\n selectedListItemText:\n theme.theme.selectedListItemText === undefined\n ? resolved.background!\n : resolveColor(theme.theme.selectedListItemText),\n backgroundMenu:\n theme.theme.backgroundMenu === undefined ? resolved.backgroundElement! : resolveColor(theme.theme.backgroundMenu),\n thinkingOpacity: theme.theme.thinkingOpacity ?? 0.6,\n }\n}\n\nfunction generateGrayScale(bg: RGBA, isDark: boolean, map: (rgba: RGBA) => RGBA): Record<number, RGBA> {\n const r = bg.r * 255\n const g = bg.g * 255\n const b = bg.b * 255\n const lum = 0.299 * r + 0.587 * g + 0.114 * b\n const cast = 0.25 * (1 - chroma(bg)) ** 2\n\n const gray = (level: number) => {\n const factor = level / 12\n\n if (isDark && lum < 10) {\n const value = Math.floor(factor * 0.4 * 255)\n return map(RGBA.fromInts(value, value, value))\n }\n\n if (!isDark && lum > 245) {\n const value = Math.floor(255 - factor * 0.4 * 255)\n return map(RGBA.fromInts(value, value, value))\n }\n\n const value = isDark ? lum + (255 - lum) * factor * 0.4 : lum * (1 - factor * 0.4)\n const tone = RGBA.fromInts(Math.floor(value), Math.floor(value), Math.floor(value))\n if (cast === 0) return map(tone)\n\n const ratio = lum === 0 ? 0 : value / lum\n return map(\n tint(\n tone,\n RGBA.fromInts(\n Math.floor(Math.max(0, Math.min(r * ratio, 255))),\n Math.floor(Math.max(0, Math.min(g * ratio, 255))),\n Math.floor(Math.max(0, Math.min(b * ratio, 255))),\n ),\n cast,\n ),\n )\n }\n\n return Object.fromEntries(Array.from({ length: 12 }, (_, index) => [index + 1, gray(index + 1)]))\n}\n\nfunction generateMutedTextColor(bg: RGBA, isDark: boolean, map: (rgba: RGBA) => RGBA): RGBA {\n const lum = 0.299 * bg.r * 255 + 0.587 * bg.g * 255 + 0.114 * bg.b * 255\n const gray = isDark\n ? lum < 10\n ? 180\n : Math.min(Math.floor(160 + lum * 0.3), 200)\n : lum > 245\n ? 75\n : Math.max(Math.floor(100 - (255 - lum) * 0.2), 60)\n\n return map(RGBA.fromInts(gray, gray, gray))\n}\n\nexport function generateSystem(colors: TerminalColors, pick: \"dark\" | \"light\"): ThemeJson {\n const bg_snapshot = RGBA.fromHex(colors.defaultBackground ?? colors.palette[0]!)\n const fg_snapshot = RGBA.fromHex(colors.defaultForeground ?? colors.palette[7]!)\n const bg = RGBA.defaultBackground(bg_snapshot)\n const fg = RGBA.defaultForeground(fg_snapshot)\n const isDark = pick === \"dark\"\n\n const color = (index: number) => paletteColor(colors, index)\n\n const grays = generateGrayScale(bg_snapshot, isDark, (rgba) => rgba)\n const textMuted = generateMutedTextColor(bg_snapshot, isDark, (rgba) => rgba)\n\n const ansi = {\n red: color(1),\n green: color(2),\n yellow: color(3),\n blue: color(4),\n magenta: color(5),\n cyan: color(6),\n red_bright: color(9),\n green_bright: color(10),\n }\n\n const diff_alpha = isDark ? 0.22 : 0.14\n const diff_context_bg = grays[2]\n const primary = ansi.cyan\n const secondary = ansi.magenta\n\n return {\n theme: {\n primary,\n secondary,\n accent: primary,\n error: ansi.red,\n warning: ansi.yellow,\n success: ansi.green,\n info: ansi.cyan,\n text: fg,\n textMuted,\n selectedListItemText: bg,\n background: alpha(bg, 0),\n backgroundPanel: grays[2],\n backgroundElement: grays[3],\n backgroundMenu: grays[3],\n borderSubtle: grays[6],\n border: grays[7],\n borderActive: grays[8],\n diffAdded: ansi.green,\n diffRemoved: ansi.red,\n diffContext: grays[7],\n diffHunkHeader: grays[7],\n diffHighlightAdded: ansi.green_bright,\n diffHighlightRemoved: ansi.red_bright,\n diffAddedBg: tint(bg_snapshot, ansi.green, diff_alpha),\n diffRemovedBg: tint(bg_snapshot, ansi.red, diff_alpha),\n diffContextBg: diff_context_bg,\n diffLineNumber: textMuted,\n diffAddedLineNumberBg: tint(diff_context_bg, ansi.green, diff_alpha),\n diffRemovedLineNumberBg: tint(diff_context_bg, ansi.red, diff_alpha),\n markdownText: fg,\n markdownHeading: fg,\n markdownLink: ansi.blue,\n markdownLinkText: ansi.cyan,\n markdownCode: ansi.green,\n markdownBlockQuote: ansi.yellow,\n markdownEmph: ansi.yellow,\n markdownStrong: fg,\n markdownHorizontalRule: grays[7],\n markdownListItem: ansi.blue,\n markdownListEnumeration: ansi.cyan,\n markdownImage: ansi.blue,\n markdownImageText: ansi.cyan,\n markdownCodeBlock: fg,\n syntaxComment: textMuted,\n syntaxKeyword: ansi.magenta,\n syntaxFunction: ansi.blue,\n syntaxVariable: fg,\n syntaxString: ansi.green,\n syntaxNumber: ansi.yellow,\n syntaxType: ansi.cyan,\n syntaxOperator: ansi.cyan,\n syntaxPunctuation: fg,\n },\n }\n}\n\nfunction quantizeColor(indexed: RGBA[], rgba: RGBA): RGBA {\n if (rgba.a === 0 || rgba.intent === \"default\" || rgba.intent === \"indexed\") {\n return RGBA.clone(rgba)\n }\n\n return nearestIndexed(indexed, rgba)\n}\n\nfunction quantizeTheme(theme: TuiThemeCurrent, indexed: RGBA[]): TuiThemeCurrent {\n const resolved = Object.fromEntries(\n Object.entries(theme)\n .filter(([key]) => key !== \"thinkingOpacity\")\n .map(([key, value]) => [key, quantizeColor(indexed, value as RGBA)]),\n ) as Partial<Record<ThemeColor, RGBA>>\n\n return {\n ...(resolved as Record<ThemeColor, RGBA>),\n thinkingOpacity: theme.thinkingOpacity,\n }\n}\n\nfunction splashTheme(theme: TuiThemeCurrent, indexed: RGBA[]): RunSplashTheme {\n const left = nearestIndexed(indexed, theme.textMuted)\n const right = nearestIndexed(indexed, theme.text)\n return {\n left,\n right,\n leftShadow: splashShadow(indexed, theme.background, left, 0.14),\n rightShadow: splashShadow(indexed, theme.background, right, 0.14),\n }\n}\n\nfunction map(\n footerTheme: TuiThemeCurrent,\n scrollbackTheme: TuiThemeCurrent,\n splash: RunSplashTheme,\n syntax?: SyntaxStyle,\n): RunTheme {\n const footerBackground = alpha(footerTheme.background, 1)\n const footerMode = mode(footerBackground)\n const shade = fade(footerTheme.backgroundMenu, footerTheme.background, 0.12, 0.56, 0.72)\n const surface = fade(footerTheme.backgroundMenu, footerTheme.background, 0.18, 0.76, 0.9)\n const line = fade(footerTheme.backgroundMenu, footerTheme.background, 0.24, 0.9, 0.98)\n const statusBase = tint(footerBackground, rgba(\"#000000\"), footerMode === \"dark\" ? 0.12 : 0.06)\n const statusAccentBase =\n footerMode === \"dark\" ? tint(footerBackground, rgba(\"#ffffff\"), 0.06) : tint(statusBase, rgba(\"#000000\"), 0.04)\n const collapsedStatus = footerMode === \"dark\" && luminance(statusBase) <= 0.04\n // Pure-black backgrounds need a slight lift or the row disappears into the terminal background.\n const status = collapsedStatus ? tint(statusBase, statusAccentBase, 0.7) : statusBase\n const statusAccent = collapsedStatus ? tint(status, rgba(\"#ffffff\"), 0.06) : statusAccentBase\n\n return {\n background: footerTheme.background,\n footer: {\n highlight: footerTheme.primary,\n selected: footerTheme.backgroundElement,\n selectedText: footerTheme.selectedListItemText,\n warning: footerTheme.warning,\n success: footerTheme.success,\n error: footerTheme.error,\n muted: footerTheme.textMuted,\n text: footerTheme.text,\n status,\n statusAccent,\n shade,\n surface,\n pane: footerTheme.backgroundMenu,\n border: footerTheme.border,\n line,\n },\n entry: {\n system: {\n body: scrollbackTheme.textMuted,\n },\n user: {\n body: scrollbackTheme.primary,\n },\n assistant: {\n body: scrollbackTheme.text,\n },\n reasoning: {\n body: scrollbackTheme.textMuted,\n },\n tool: {\n body: scrollbackTheme.text,\n start: scrollbackTheme.textMuted,\n },\n error: {\n body: scrollbackTheme.error,\n },\n },\n splash,\n block: {\n highlight: scrollbackTheme.primary,\n warning: scrollbackTheme.warning,\n text: scrollbackTheme.text,\n muted: scrollbackTheme.textMuted,\n syntax,\n diffAdded: scrollbackTheme.diffAdded,\n diffRemoved: scrollbackTheme.diffRemoved,\n diffAddedBg: transparent,\n diffRemovedBg: transparent,\n diffContextBg: transparent,\n diffHighlightAdded: scrollbackTheme.diffHighlightAdded,\n diffHighlightRemoved: scrollbackTheme.diffHighlightRemoved,\n diffLineNumber: scrollbackTheme.diffLineNumber,\n diffAddedLineNumberBg: scrollbackTheme.diffAddedLineNumberBg,\n diffRemovedLineNumberBg: scrollbackTheme.diffRemovedLineNumberBg,\n },\n }\n}\n\nconst seed = {\n highlight: RGBA.fromIndex(6, rgba(\"#38bdf8\")),\n muted: RGBA.fromIndex(8, rgba(\"#64748b\")),\n text: RGBA.defaultForeground(rgba(\"#f8fafc\")),\n panel: rgba(\"#0f172a\"),\n success: RGBA.fromIndex(2, rgba(\"#22c55e\")),\n warning: RGBA.fromIndex(3, rgba(\"#f59e0b\")),\n error: RGBA.fromIndex(1, rgba(\"#ef4444\")),\n}\n\nfunction tone(body: ColorInput, start?: ColorInput): Tone {\n return {\n body,\n start,\n }\n}\n\nconst fallbackSplashIndexed = Array.from({ length: 256 }, (_, index) => RGBA.fromIndex(index))\nconst fallbackSplashLeft = RGBA.fromIndex(67)\nconst fallbackSplashRight = RGBA.fromIndex(110)\n\nexport const RUN_THEME_FALLBACK: RunTheme = {\n background: RGBA.fromValues(0, 0, 0, 0),\n footer: {\n highlight: seed.highlight,\n selected: seed.text,\n selectedText: seed.panel,\n warning: seed.warning,\n success: seed.success,\n error: seed.error,\n muted: seed.muted,\n text: seed.text,\n status: tint(seed.panel, rgba(\"#000000\"), 0.12),\n statusAccent: tint(seed.panel, rgba(\"#ffffff\"), 0.06),\n shade: alpha(seed.panel, 0.68),\n surface: alpha(seed.panel, 0.86),\n pane: seed.panel,\n border: seed.muted,\n line: alpha(seed.panel, 0.96),\n },\n entry: {\n system: tone(seed.muted),\n user: tone(seed.highlight),\n assistant: tone(seed.text),\n reasoning: tone(seed.muted),\n tool: tone(seed.text, seed.muted),\n error: tone(seed.error),\n },\n splash: {\n left: fallbackSplashLeft,\n right: fallbackSplashRight,\n leftShadow: splashShadow(fallbackSplashIndexed, RGBA.fromValues(0, 0, 0, 0), fallbackSplashLeft, 0.14),\n rightShadow: splashShadow(fallbackSplashIndexed, RGBA.fromValues(0, 0, 0, 0), fallbackSplashRight, 0.14),\n },\n block: {\n highlight: seed.highlight,\n warning: seed.warning,\n text: seed.text,\n muted: seed.muted,\n diffAdded: seed.success,\n diffRemoved: seed.error,\n diffAddedBg: alpha(seed.success, 0.18),\n diffRemovedBg: alpha(seed.error, 0.18),\n diffContextBg: alpha(seed.panel, 0.72),\n diffHighlightAdded: seed.success,\n diffHighlightRemoved: seed.error,\n diffLineNumber: seed.muted,\n diffAddedLineNumberBg: alpha(seed.success, 0.12),\n diffRemovedLineNumberBg: alpha(seed.error, 0.12),\n },\n}\n\nexport async function resolveRunTheme(renderer: CliRenderer): Promise<RunTheme> {\n try {\n const colors = await renderer.getPalette({\n size: 256,\n })\n const bg = colors.defaultBackground ?? colors.palette[0]\n if (!bg) {\n return RUN_THEME_FALLBACK\n }\n\n // Palette-only terminal reloads can leave renderer.themeMode stale, but\n // ANSI slot zero is not the terminal background when OSC 11 is absent.\n const pick = colors.defaultBackground\n ? mode(RGBA.fromHex(colors.defaultBackground))\n : (renderer.themeMode ?? mode(RGBA.fromHex(bg)))\n const footerTheme = resolveTheme(generateSystem(colors, pick), pick)\n const indexed = indexedPalette(colors, 256)\n const scrollbackTheme = quantizeTheme(footerTheme, indexed)\n const shared = await import(\"@opencode-ai/tui/context/theme\")\n const syntaxTheme: SharedSyntaxTheme = {\n ...scrollbackTheme,\n _hasSelectedListItemText: true,\n }\n const syntax = shared.generateSyntax(syntaxTheme)\n return map(footerTheme, scrollbackTheme, splashTheme(scrollbackTheme, indexed), syntax)\n } catch {\n return RUN_THEME_FALLBACK\n }\n}\n" | ||
| ], | ||
| "mappings": ";mcAQA,0BCJA,SAAM,OAAQ,SAkBd,cAAS,OAAa,MAAC,OAAwC,CAC7D,MAAO,CACL,KAAM,EAAQ,KACd,MAAO,CACL,IAAI,EAAQ,OAAS,CAAC,GAAG,IAAI,CAAC,KAAU,CACtC,KAAM,OACN,IAAK,EAAK,OAAO,OAAS,MAAQ,EAAK,OAAO,IAAM,QAAQ,EAAK,eAAe,EAAK,OACrF,KAAM,EAAK,KACX,SAAU,EAAK,KACf,OAAQ,EAAK,QACT,CACE,KAAM,OACN,KAAM,EAAK,OAAS,EAAK,OAAO,OAAS,MAAQ,EAAK,OAAO,IAAM,qBACnE,KAAM,CAAE,MAAO,EAAK,QA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B,IAAI,EACrG,YAAa,EAAa,EAAuB,EAAK,WAAW,EAAG,EAAG,EAAG,CAAC,EAAG,EAAqB,IAAI,CACzG,EACA,MAAO,CACL,UAAW,EAAK,UAChB,QAAS,EAAK,QACd,KAAM,EAAK,KACX,MAAO,EAAK,MACZ,UAAW,EAAK,QAChB,YAAa,EAAK,MAClB,YAAa,EAAM,EAAK,QAAS,IAAI,EACrC,cAAe,EAAM,EAAK,MAAO,IAAI,EACrC,cAAe,EAAM,EAAK,MAAO,IAAI,EACrC,mBAAoB,EAAK,QACzB,qBAAsB,EAAK,MAC3B,eAAgB,EAAK,MACrB,sBAAuB,EAAM,EAAK,QAAS,IAAI,EAC/C,wBAAyB,EAAM,EAAK,MAAO,IAAI,CACjD,CACF,EAEA,eAAsB,EAAe,CAAC,EAA0C,CAC9E,GAAI,CACF,IAAM,EAAS,MAAM,EAAS,WAAW,CACvC,KAAM,GACR,CAAC,EACK,EAAK,EAAO,mBAAqB,EAAO,QAAQ,GACtD,GAAI,CAAC,EACH,OAAO,EAKT,IAAM,EAAO,EAAO,kBAChB,EAAK,EAAK,QAAQ,EAAO,iBAAiB,CAAC,EAC1C,EAAS,WAAa,EAAK,EAAK,QAAQ,CAAE,CAAC,EAC1C,EAAc,GAAa,GAAe,EAAQ,CAAI,EAAG,CAAI,EAC7D,EAAU,GAAe,EAAQ,GAAG,EACpC,EAAkB,GAAc,EAAa,CAAO,EACpD,EAAS,KAAa,0CACtB,EAAiC,IAClC,EACH,yBAA0B,EAC5B,EACM,EAAS,EAAO,eAAe,CAAW,EAChD,OAAO,GAAI,EAAa,EAAiB,GAAY,EAAiB,CAAO,EAAG,CAAM,EACtF,KAAM,CACN,OAAO", | ||
| "debugId": "1A5D238C3EFC64B064756E2164756E21", | ||
| "names": [] | ||
| } |
| { | ||
| "version": 3, | ||
| "sources": ["src/services/standalone.ts", "src/services/server-connection.ts"], | ||
| "sourcesContent": [ | ||
| "import { Service, type Endpoint } from \"@opencode-ai/client/effect/service\"\nimport { CrossSpawnSpawner } from \"@opencode-ai/core/cross-spawn-spawner\"\nimport { AppNodeBuilder } from \"@opencode-ai/core/effect/app-node-builder\"\nimport { Effect, Schema, Stream } from \"effect\"\nimport { ChildProcess, ChildProcessSpawner } from \"effect/unstable/process\"\nimport { randomBytes } from \"node:crypto\"\nimport path from \"node:path\"\n\nconst Ready = Schema.Struct({ url: Schema.String })\nconst decodeReady = Schema.decodeUnknownPromise(Schema.fromJsonString(Ready))\n\ntype Options = {\n readonly command?: ReadonlyArray<string>\n}\n\nfunction command(password: string, options: Options) {\n const compiled = path.basename(process.execPath).replace(/\\.exe$/, \"\") !== \"bun\"\n const entrypoint = compiled ? [] : process.argv[1] ? [process.argv[1]] : []\n if (!compiled && entrypoint.length === 0) throw new Error(\"Failed to resolve CLI entrypoint\")\n const [executable, ...args] = options.command ?? [process.execPath, ...entrypoint, \"serve\"]\n if (!executable) throw new Error(\"Failed to resolve standalone server command\")\n return ChildProcess.make(executable, [...args, \"--stdio\", \"--port\", \"0\"], {\n cwd: process.cwd(),\n // Explicit entry wins over anything inherited, so a user-exported\n // OPENCODE_PASSWORD cannot shadow the child's lease credential.\n env: { OPENCODE_PASSWORD: password },\n extendEnv: true,\n // The server treats EOF on this pipe as the end of its ownership lease.\n // The OS closes it even when the TUI is killed before Effect finalizers run.\n stdin: \"pipe\",\n stderr: \"ignore\",\n killSignal: \"SIGTERM\",\n forceKillAfter: \"3 seconds\",\n })\n}\n\nconst makeEndpoint = Effect.fn(\"cli.standalone.endpoint\")(\n function* (options: Options) {\n const password = randomBytes(32).toString(\"base64url\")\n const spawner = yield* ChildProcessSpawner.ChildProcessSpawner\n const proc = yield* spawner.spawn(command(password, options))\n const output = yield* proc.stdout.pipe(Stream.decodeText(), Stream.splitLines, Stream.take(1), Stream.mkString)\n if (!output) return yield* Effect.fail(new Error(\"Standalone server exited before reporting readiness\"))\n const ready = yield* Effect.tryPromise(() => decodeReady(output))\n return {\n url: ready.url,\n auth: { type: \"basic\" as const, username: \"opencode\", password },\n pid: proc.pid,\n } satisfies Endpoint & { readonly pid: number }\n },\n Effect.provide(AppNodeBuilder.build(CrossSpawnSpawner.node)),\n)\n\nexport function start(options: Options = {}) {\n return makeEndpoint(options)\n}\n\nexport * as Standalone from \"./standalone\"\n", | ||
| "import { Service, type Endpoint, type EnsureOptions } from \"@opencode-ai/client/effect/service\"\nimport { ClientError, isUnauthorizedError, OpenCode } from \"@opencode-ai/client/promise\"\nimport { InstallationVersion } from \"@opencode-ai/core/installation/version\"\nimport { Effect, Redacted } from \"effect\"\nimport { Env } from \"../env\"\nimport { ServiceConfig } from \"./service-config\"\nimport { Standalone } from \"./standalone\"\n\nexport type Args = {\n readonly server?: string\n readonly standalone?: boolean\n readonly mismatch?: \"replace\" | \"ignore\" | \"error\"\n readonly onStart?: EnsureOptions[\"onStart\"]\n}\n\nexport type Resolved = {\n readonly endpoint: Endpoint\n readonly service?: ReturnType<typeof managedService>\n}\n\nexport const resolve = Effect.fn(\"cli.server-connection.resolve\")(function* (args: Args) {\n if (args.server !== undefined && args.standalone)\n return yield* Effect.fail(new Error(\"--server and --standalone cannot be combined\"))\n if (args.server !== undefined) {\n const password = yield* Env.password\n const endpoint = {\n url: args.server,\n auth: password ? { type: \"basic\" as const, username: \"opencode\", password: Redacted.value(password) } : undefined,\n } satisfies Endpoint\n const client = OpenCode.make({ baseUrl: endpoint.url, headers: Service.headers(endpoint) })\n const health = yield* Effect.tryPromise({\n try: () => client.health.get({ signal: AbortSignal.timeout(5_000) }),\n catch: (cause) => connectError(endpoint, cause),\n })\n if (health.version !== InstallationVersion)\n process.stderr.write(\n `Warning: Server at ${endpoint.url} has version ${health.version}; this client is ${InstallationVersion}. Continuing anyway.\\n`,\n )\n return { endpoint } satisfies Resolved\n }\n if (args.standalone) {\n return { endpoint: yield* Standalone.start() } satisfies Resolved\n }\n\n const options = yield* ServiceConfig.options()\n return {\n endpoint: yield* resolveManaged({ ...options, onStart: args.onStart }, args.mismatch ?? \"replace\"),\n service: managedService(options),\n } satisfies Resolved\n})\n\nfunction managedService(options: EnsureOptions) {\n const reconnectOptions = { ...options, version: undefined }\n return {\n reconnect: () => Service.ensure(reconnectOptions),\n restart: () =>\n Effect.gen(function* () {\n yield* Service.stop(options)\n yield* Service.ensure(options)\n }),\n }\n}\n\nconst resolveManaged = Effect.fnUntraced(function* (\n options: EnsureOptions,\n mismatch: NonNullable<Args[\"mismatch\"]>,\n) {\n if (mismatch === \"replace\") return yield* Service.ensure(options)\n if (mismatch === \"ignore\") return yield* Service.ensure({ ...options, version: undefined })\n\n const compatible = yield* Service.discover(options)\n if (compatible !== undefined) return compatible\n const existing = yield* Service.discover({ ...options, version: undefined })\n if (existing !== undefined)\n return yield* Effect.fail(new Error(\"Background server version does not match this client\"))\n return yield* Service.ensure(options)\n})\n\nfunction connectError(endpoint: Endpoint, cause: unknown) {\n if (isUnauthorizedError(cause)) {\n return new Error(\n endpoint.auth === undefined\n ? `Server at ${endpoint.url} requires a password; set OPENCODE_PASSWORD`\n : `Server at ${endpoint.url} rejected the password`,\n { cause },\n )\n }\n if (cause instanceof ClientError && cause.reason === \"Transport\")\n return new Error(`Could not reach server at ${endpoint.url}`, { cause })\n return new Error(`Server at ${endpoint.url} did not provide a compatible V2 health response`, { cause })\n}\n\nexport * as ServerConnection from \"./server-connection\"\n" | ||
| ], | ||
| "mappings": ";6mBAKA,2BAAS,oBACT,yBAEA,SAAM,OAAQ,OAAO,YAAO,MAAE,SAAK,EAAO,MAAO,CAAC,EAC5C,EAAc,EAAO,qBAAqB,EAAO,eAAe,CAAK,CAAC,EAM5E,SAAS,CAAO,CAAC,EAAkB,EAAkB,CACnD,IAAM,EAAW,EAAK,SAAS,QAAQ,QAAQ,EAAE,QAAQ,SAAU,EAAE,IAAM,MACrE,EAAa,EAAW,CAAC,EAAI,QAAQ,KAAK,GAAK,CAAC,QAAQ,KAAK,EAAE,EAAI,CAAC,EAC1E,GAAI,CAAC,GAAY,EAAW,SAAW,EAAG,MAAU,M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AAC,KAC1D,OACf,OAAO,MAAO,EAAO,KAAS,MAAM,sDAAsD,CAAC,EAC7F,OAAO,MAAO,EAAQ,OAAO,CAAO,EACrC,EAED,SAAS,CAAY,CAAC,EAAoB,EAAgB,CACxD,GAAI,EAAoB,CAAK,EAC3B,OAAW,MACT,EAAS,OAAS,OACd,aAAa,EAAS,iDACtB,aAAa,EAAS,4BAC1B,CAAE,OAAM,CACV,EAEF,GAAI,aAAiB,GAAe,EAAM,SAAW,YACnD,OAAW,MAAM,6BAA6B,EAAS,MAAO,CAAE,OAAM,CAAC,EACzE,OAAW,MAAM,aAAa,EAAS,sDAAuD,CAAE,OAAM,CAAC", | ||
| "debugId": "15810D09B76D7BA764756E2164756E21", | ||
| "names": [] | ||
| } |
| { | ||
| "version": 3, | ||
| "sources": ["src/commands/handlers/mcp/auth.ts"], | ||
| "sourcesContent": [ | ||
| "import { EOL } from \"node:os\"\nimport { Effect } from \"effect\"\nimport {\n OpenCode,\n type IntegrationAttemptStatus,\n type IntegrationOAuthMethod,\n type OpenCodeClient,\n} from \"@opencode-ai/client\"\nimport { Commands } from \"../../commands\"\nimport { Runtime } from \"../../../framework/runtime\"\nimport { Service } from \"@opencode-ai/client/effect/service\"\nimport { ServiceConfig } from \"../../../services/service-config\"\nimport { resolveIntegration } from \"./resolve\"\n\nconst location = { directory: process.cwd() }\n\nexport default Runtime.handler(\n Commands.commands.mcp.commands.auth,\n Effect.fn(\"cli.mcp.auth\")(function* (input) {\n const options = yield* ServiceConfig.options()\n const found = yield* Service.discover(options)\n const endpoint = found ?? (yield* Service.ensure(options))\n const client = OpenCode.make({ baseUrl: endpoint.url, headers: Service.headers(endpoint) })\n\n const integration = yield* resolveIntegration(client, input.name, location)\n if (!integration)\n return yield* Effect.fail(new Error(`MCP server \"${input.name}\" is not an OAuth-capable remote server`))\n const method = integration.methods.find(\n (candidate): candidate is IntegrationOAuthMethod => candidate.type === \"oauth\",\n )\n if (!method)\n return yield* Effect.fail(new Error(`MCP server \"${input.name}\" is not an OAuth-capable remote server`))\n\n const started = yield* Effect.promise(() =>\n client.integration.connect.oauth({ integrationID: integration.id, methodID: method.id, inputs: {}, location }),\n )\n const attempt = started.data\n if (attempt.mode === \"code\")\n return yield* Effect.fail(new Error(\"This server requires manual code entry, which the CLI does not support\"))\n\n process.stdout.write(attempt.instructions + EOL + attempt.url + EOL)\n\n const result = yield* poll(client, attempt.attemptID)\n if (result.status === \"complete\") {\n process.stdout.write(`Authenticated with ${input.name}` + EOL)\n return\n }\n const reason = result.status === \"failed\" ? `: ${result.message}` : \"\"\n return yield* Effect.fail(new Error(`Authentication ${result.status}${reason}`))\n }),\n)\n\nconst poll = (\n client: OpenCodeClient,\n attemptID: string,\n): Effect.Effect<Exclude<IntegrationAttemptStatus, { status: \"pending\" }>> =>\n Effect.gen(function* () {\n const status = yield* Effect.promise(() => client.integration.attempt.status({ attemptID, location })).pipe(\n Effect.map((result) => result.data),\n )\n if (status.status === \"pending\") {\n yield* Effect.sleep(\"1 second\")\n return yield* poll(client, attemptID)\n }\n return status\n })\n" | ||
| ], | ||
| "mappings": ";88BAAA,mBAAS,gBAcT,SAAM,OAAW,MAAE,eAAW,aAAQ,SAAI,MAAE,OAE7B,SAAQ,aACrB,OAAS,cAAS,SAAI,cAAS,UAC/B,OAAO,QAAG,mBAAc,OAAE,cAAU,MAAC,OAAO,MAC1C,IAAM,EAAU,MAAO,EAAc,QAAQ,EAEvC,GADQ,MAAO,EAAQ,SAAS,CAAO,KAClB,MAAO,EAAQ,OAAO,CAAO,GAClD,EAAS,EAAS,KAAK,CAAE,QAAS,EAAS,IAAK,QAAS,EAAQ,QAAQ,CAAQ,CAAE,CAAC,EAEpF,EAAc,MAAO,EAAmB,EAAQ,EAAM,KAAM,CAAQ,EAC1E,GAAI,CAAC,EACH,OAAO,MAAO,EAAO,KAAS,MAAM,eAAe,EAAM,6CAA6C,CAAC,EACzG,IAAM,EAAS,EAAY,QAAQ,KACjC,CAAC,IAAmD,EAAU,OAAS,OACzE,EACA,GAAI,CAAC,EACH,OAAO,MAAO,EAAO,KAAS,MAAM,eAAe,EAAM,6CAA6C,CAAC,EAKzG,IAAM,GAHU,MAAO,EAAO,QAAQ,IACpC,EAAO,YAAY,QAAQ,MAAM,CAAE,cAAe,EAAY,GAAI,SAAU,EAAO,GAAI,OAAQ,CAAC,EAAG,UAAS,CAAC,CAC/G,GACwB,KACxB,GAAI,EAAQ,OAAS,OACnB,OAAO,MAAO,EAAO,KAAS,MAAM,wEAAwE,CAAC,EAE/G,QAAQ,OAAO,MAAM,EAAQ,aAAe,EAAM,EAAQ,IAAM,CAAG,EAEnE,IAAM,EAAS,MAAO,EAAK,EAAQ,EAAQ,SAAS,EACpD,GAAI,EAAO,SAAW,WAAY,CAChC,QAAQ,OAAO,MAAM,sBAAsB,EAAM,OAAS,CAAG,EAC7D,OAEF,IAAM,EAAS,EAAO,SAAW,SAAW,KAAK,EAAO,UAAY,GACpE,OAAO,MAAO,EAAO,KAAS,MAAM,kBAAkB,EAAO,SAAS,GAAQ,CAAC,EAChF,CACH,EAEM,EAAO,CACX,EACA,IAEA,EAAO,IAAI,SAAU,EAAG,CACtB,IAAM,EAAS,MAAO,EAAO,QAAQ,IAAM,EAAO,YAAY,QAAQ,OAAO,CAAE,YAAW,UAAS,CAAC,CAAC,EAAE,KACrG,EAAO,IAAI,CAAC,IAAW,EAAO,IAAI,CACpC,EACA,GAAI,EAAO,SAAW,UAEpB,OADA,MAAO,EAAO,MAAM,UAAU,EACvB,MAAO,EAAK,EAAQ,CAAS,EAEtC,OAAO,EACR", | ||
| "debugId": "9D05A85EFB73D90B64756E2164756E21", | ||
| "names": [] | ||
| } |
| { | ||
| "version": 3, | ||
| "sources": ["../simulation/src/backend/network.ts", "../simulation/src/backend/openai.ts", "../simulation/src/backend/simulated-provider.ts", "../simulation/src/backend/index.ts"], | ||
| "sourcesContent": [ | ||
| "import { Clock, Effect, Layer, Ref } from \"effect\"\nimport { HttpClient, HttpClientResponse, type HttpMethod } from \"effect/unstable/http\"\nimport { HttpClientError, TransportError } from \"effect/unstable/http/HttpClientError\"\nimport type { HttpClientRequest } from \"effect/unstable/http\"\nimport { SimulationProtocol } from \"../protocol\"\n\n/**\n * Simulated network.\n *\n * Replaces the `HttpClient.HttpClient` platform node in simulation mode. All\n * outbound HTTP resolves against an in-memory route table; unknown\n * destinations fail loudly with a transport error so no simulation run can\n * silently reach the real network. The scripted LLM is one registered route,\n * not a separate mechanism.\n *\n * Each acquired run owns its routes and request log.\n */\n\nexport interface Route {\n /** Return a response effect to claim the request, undefined to pass. */\n readonly match: (\n request: HttpClientRequest.HttpClientRequest,\n url: URL,\n ) => Effect.Effect<HttpClientResponse.HttpClientResponse, HttpClientError> | undefined\n}\n\nexport type LogEntry = SimulationProtocol.Backend.NetworkLogEntry\n\nconst LOG_LIMIT = 1000\n\n/** Static JSON route: exact method + origin/path match answered with a fixed body. */\nexport function json(method: HttpMethod.HttpMethod, url: string, body: unknown): Route {\n return {\n match: (request, requestUrl) => {\n if (request.method !== method) return undefined\n if (requestUrl.origin + requestUrl.pathname !== url) return undefined\n return Effect.sync(() =>\n HttpClientResponse.fromWeb(\n request,\n new Response(JSON.stringify(body), { status: 200, headers: { \"content-type\": \"application/json\" } }),\n ),\n )\n },\n }\n}\n\nexport interface Run {\n readonly client: HttpClient.HttpClient\n readonly log: () => Effect.Effect<readonly LogEntry[]>\n}\n\nexport const make = Effect.fn(\"SimulationNetwork.make\")(function* (routes: readonly Route[] = []) {\n const log = yield* Ref.make<readonly LogEntry[]>([])\n const client = HttpClient.make((request, url) =>\n Effect.gen(function* () {\n let matched: Effect.Effect<HttpClientResponse.HttpClientResponse, HttpClientError> | undefined\n for (const route of routes) {\n matched = route.match(request, url)\n if (matched) break\n }\n const entry = {\n time: yield* Clock.currentTimeMillis,\n method: request.method,\n url: url.toString(),\n matched: matched !== undefined,\n }\n yield* Ref.update(log, (entries) => [...entries, entry].slice(-LOG_LIMIT))\n if (matched) return yield* matched\n return yield* Effect.fail(\n new HttpClientError({\n reason: new TransportError({\n request,\n description: `Simulation denied unregistered network destination: ${request.method} ${url}`,\n }),\n }),\n )\n }),\n )\n return { client, log: () => Ref.get(log) } satisfies Run\n})\n\nexport const layer = (routes: readonly Route[] = []) =>\n Layer.effect(HttpClient.HttpClient, make(routes).pipe(Effect.map((run) => run.client)))\n\nexport * as SimulationNetwork from \"./network\"\n", | ||
| "import { Effect, Schema, Stream } from \"effect\"\nimport { HttpClientResponse } from \"effect/unstable/http\"\nimport { HttpClientError, TransportError } from \"effect/unstable/http/HttpClientError\"\nimport { OpenAIChatEvent, DEFAULT_BASE_URL, PATH } from \"@opencode-ai/ai/protocols/openai-chat\"\nimport { SimulationNetwork } from \"./network\"\nimport { SimulatedProvider } from \"./simulated-provider\"\n\n/**\n * Driver-answered OpenAI endpoint for the simulated network.\n *\n * Claims `POST {DEFAULT_BASE_URL}{PATH}` (the real openai-chat route\n * endpoint), invokes the simulated provider, and streams the driver's events back as\n * an OpenAI Chat SSE response terminated by `[DONE]`. Everything downstream\n * of the response bytes is the real pipeline: SSE framing, the OpenAIChat\n * event schema, the protocol state machine, and Lifecycle grammar.\n */\n\nconst encodeChunk = Schema.encodeUnknownSync(OpenAIChatEvent)\n\nconst encoder = new TextEncoder()\nconst decodeBody = Schema.decodeUnknownEffect(Schema.fromJsonString(Schema.Json))\n\n// The simulated model id is echoed back only in non-schema fields; the\n// protocol event schema ignores unknown fields, so id/object/model are\n// decorative wire realism.\ntype ProviderItem = Exclude<SimulatedProvider.ProviderResponseEvent, { readonly type: \"finish\" }>\ntype FinishReason = Extract<SimulatedProvider.ProviderResponseEvent, { readonly type: \"finish\" }>[\"reason\"]\n\nfunction chunkOf(item: ProviderItem): OpenAIChatEvent | unknown {\n if (item.type === \"textDelta\") return { choices: [{ delta: { content: item.text } }] }\n if (item.type === \"reasoningDelta\") return { choices: [{ delta: { reasoning_content: item.text } }] }\n if (item.type === \"toolCall\")\n return {\n choices: [\n {\n delta: {\n tool_calls: [\n {\n index: item.index,\n id: item.id,\n function: { name: item.name, arguments: JSON.stringify(item.input) },\n },\n ],\n },\n },\n ],\n }\n return item.chunk\n}\n\nconst finishReasonWire: Record<FinishReason, string> = {\n stop: \"stop\",\n \"tool-calls\": \"tool_calls\",\n length: \"length\",\n \"content-filter\": \"content_filter\",\n}\n\nfunction frame(payload: unknown): Uint8Array {\n return encoder.encode(`data: ${JSON.stringify(payload)}\\n\\n`)\n}\n\nfunction sseBody(\n events: Stream.Stream<SimulatedProvider.ProviderResponseEvent, SimulatedProvider.ProviderDisconnectedError>,\n): Stream.Stream<Uint8Array, SimulatedProvider.ProviderDisconnectedError> {\n return events.pipe(\n Stream.map((event) => {\n if (event.type === \"finish\")\n return frame(encodeChunk({ choices: [{ delta: {}, finish_reason: finishReasonWire[event.reason] }] }))\n if (event.type === \"raw\") return frame(event.chunk)\n return frame(encodeChunk(chunkOf(event)))\n }),\n Stream.concat(Stream.make(encoder.encode(\"data: [DONE]\\n\\n\"))),\n )\n}\n\nexport const route = (provider: SimulatedProvider.Interface): SimulationNetwork.Route => ({\n match: (request, url) => {\n if (request.method !== \"POST\") return undefined\n if (url.origin + url.pathname !== DEFAULT_BASE_URL + PATH) return undefined\n return Effect.gen(function* () {\n const body =\n request.body._tag === \"Uint8Array\"\n ? yield* decodeBody(new TextDecoder().decode(request.body.body)).pipe(\n Effect.mapError(\n (cause) =>\n new HttpClientError({\n reason: new TransportError({\n request,\n cause,\n description: \"Simulation received an invalid OpenAI request body\",\n }),\n }),\n ),\n )\n : {}\n return HttpClientResponse.fromWeb(\n request,\n new Response(Stream.toReadableStream(sseBody(provider.stream({ url: url.toString(), body }))), {\n status: 200,\n headers: { \"content-type\": \"text/event-stream\" },\n }),\n )\n })\n },\n})\n\nexport * as SimulationOpenAI from \"./openai\"\n", | ||
| "import { InstallationVersion } from \"@opencode-ai/core/installation/version\"\nimport { Cause, Context, Effect, Fiber, FiberSet, Layer, PubSub, Queue, Ref, Schema, Semaphore, Stream } from \"effect\"\nimport { SimulationControlServer } from \"../control-server\"\nimport { SimulationProtocol } from \"../protocol\"\n\nexport interface ProviderRequest {\n readonly url: string\n readonly body: unknown\n}\n\nexport type ProviderResponseEvent =\n | SimulationProtocol.Backend.Item\n | { readonly type: \"finish\"; readonly reason: SimulationProtocol.Backend.FinishReason }\n\nexport class ProviderDisconnectedError extends Schema.TaggedErrorClass<ProviderDisconnectedError>()(\n \"SimulatedProvider.ProviderDisconnectedError\",\n { message: Schema.String },\n) {}\n\nexport interface Interface {\n readonly stream: (request: ProviderRequest) => Stream.Stream<ProviderResponseEvent, ProviderDisconnectedError>\n}\n\nexport class Service extends Context.Service<Service, Interface>()(\"@opencode/simulation/SimulatedProvider\") {}\n\ninterface ProviderInvocation extends ProviderRequest {\n readonly id: string\n}\n\ninterface PendingInvocation extends ProviderInvocation {\n readonly responses: Queue.Queue<ProviderResponseEvent, ProviderDisconnectedError | Cause.Done>\n}\n\ninterface State {\n readonly counter: number\n readonly pending: ReadonlyMap<string, PendingInvocation>\n}\n\ninterface Driver {\n readonly requests: Stream.Stream<ProviderInvocation>\n readonly push: (\n id: string,\n items: readonly SimulationProtocol.Backend.Item[],\n ) => Effect.Effect<void, InvocationNotFoundError>\n readonly finish: (\n id: string,\n reason: SimulationProtocol.Backend.FinishReason,\n ) => Effect.Effect<void, InvocationNotFoundError>\n readonly disconnect: (id: string) => Effect.Effect<void, InvocationNotFoundError>\n readonly pending: () => Effect.Effect<readonly ProviderInvocation[]>\n}\n\nclass InvocationNotFoundError extends Schema.TaggedErrorClass<InvocationNotFoundError>()(\n \"SimulatedProvider.InvocationNotFoundError\",\n { id: Schema.String, message: Schema.String },\n) {}\n\nclass ControllerDisconnectedError extends Schema.TaggedErrorClass<ControllerDisconnectedError>()(\n \"SimulatedProvider.ControllerDisconnectedError\",\n { message: Schema.String },\n) {}\n\ntype ControlSocket = SimulationControlServer.Socket\n\nexport const layerDrive = (options: { readonly endpoint: string }) =>\n Layer.effect(\n Service,\n Effect.gen(function* () {\n const state = yield* Ref.make<State>({ counter: 0, pending: new Map() })\n const opened = yield* PubSub.unbounded<ProviderInvocation>()\n const lock = yield* Semaphore.make(1)\n\n const close = (invocation: PendingInvocation) =>\n Effect.gen(function* () {\n yield* Queue.shutdown(invocation.responses)\n yield* lock.withPermit(\n Ref.update(state, (current) =>\n current.pending.get(invocation.id) === invocation ? remove(current, invocation.id) : current,\n ),\n )\n })\n\n yield* Effect.addFinalizer(() =>\n Effect.gen(function* () {\n const current = yield* Ref.get(state)\n yield* Effect.forEach(current.pending.values(), (invocation) => Queue.shutdown(invocation.responses), {\n discard: true,\n })\n yield* PubSub.shutdown(opened)\n }),\n )\n\n const open = (request: ProviderRequest) =>\n lock.withPermit(\n Effect.gen(function* () {\n const current = yield* Ref.get(state)\n const id = `inv_${current.counter + 1}`\n const responses = yield* Queue.bounded<ProviderResponseEvent, ProviderDisconnectedError | Cause.Done>(256)\n const invocation: PendingInvocation = { id, ...request, responses }\n yield* Ref.set(state, {\n counter: current.counter + 1,\n pending: new Map(current.pending).set(id, invocation),\n })\n yield* PubSub.publish(opened, { id, ...request })\n return invocation\n }),\n )\n\n const requireInvocation = (id: string) =>\n Effect.gen(function* () {\n const current = yield* Ref.get(state)\n const invocation = current.pending.get(id)\n if (invocation) return invocation\n return yield* Effect.fail(\n new InvocationNotFoundError({\n id,\n message: `Simulated provider invocation not found or already finished: ${id}`,\n }),\n )\n })\n\n const remove = (current: State, id: string) => {\n const pending = new Map(current.pending)\n pending.delete(id)\n return { ...current, pending }\n }\n\n const driver: Driver = {\n requests: Stream.unwrap(\n lock.withPermit(\n Effect.gen(function* () {\n const subscription = yield* PubSub.subscribe(opened)\n const current = yield* Ref.get(state)\n const pending = Array.from(current.pending.values(), ({ id, url, body }) => ({ id, url, body }))\n return Stream.concat(Stream.fromIterable(pending), Stream.fromEffectRepeat(PubSub.take(subscription)))\n }),\n ),\n ),\n push: (id, items) =>\n Effect.gen(function* () {\n const invocation = yield* lock.withPermit(requireInvocation(id))\n yield* Queue.offerAll(invocation.responses, items)\n }),\n finish: (id, reason) =>\n Effect.gen(function* () {\n const invocation = yield* lock.withPermit(\n Effect.gen(function* () {\n const invocation = yield* requireInvocation(id)\n const current = yield* Ref.get(state)\n yield* Ref.set(state, remove(current, id))\n return invocation\n }),\n )\n yield* Queue.offer(invocation.responses, { type: \"finish\", reason })\n yield* Queue.end(invocation.responses)\n }),\n disconnect: (id) =>\n Effect.gen(function* () {\n const invocation = yield* lock.withPermit(\n Effect.gen(function* () {\n const invocation = yield* requireInvocation(id)\n const current = yield* Ref.get(state)\n yield* Ref.set(state, remove(current, id))\n return invocation\n }),\n )\n yield* Queue.fail(\n invocation.responses,\n new ProviderDisconnectedError({ message: \"Simulated model provider disconnected\" }),\n )\n }),\n pending: () =>\n lock.withPermit(\n Ref.get(state).pipe(\n Effect.map((current) => Array.from(current.pending.values(), ({ id, url, body }) => ({ id, url, body }))),\n ),\n ),\n }\n\n const fibers = yield* FiberSet.make<void, unknown>()\n const activeController = yield* Ref.make<Fiber.Fiber<void> | undefined>(undefined)\n const controllerLock = yield* Semaphore.make(1)\n yield* SimulationControlServer.start({\n endpoint: options.endpoint,\n label: \"opencode drive backend websocket\",\n data: () => ({}),\n decode: SimulationProtocol.Backend.decodeRequestEffect,\n handle: (socket, request) => handle(driver, fibers, activeController, controllerLock, socket, request),\n close: (socket) => releaseController(activeController, controllerLock, socket),\n })\n yield* Effect.sync(() => process.stderr.write(`opencode drive backend websocket: ${options.endpoint}\\n`))\n\n return Service.of({\n stream: (request) =>\n Stream.unwrap(\n Effect.acquireRelease(open(request), close).pipe(\n Effect.map((invocation) =>\n Stream.fromQueue(invocation.responses).pipe(Stream.takeUntil((event) => event.type === \"finish\")),\n ),\n ),\n ),\n })\n }),\n )\n\nfunction handle(\n driver: Driver,\n fibers: FiberSet.FiberSet<void, unknown>,\n activeController: Ref.Ref<Fiber.Fiber<void> | undefined>,\n controllerLock: Semaphore.Semaphore,\n socket: ControlSocket,\n request: SimulationProtocol.Backend.Request,\n) {\n switch (request.method) {\n case \"simulation.handshake\":\n return SimulationProtocol.Handshake.dispatch(\n {\n role: \"backend\",\n server: { name: \"opencode\", version: InstallationVersion },\n capabilities: SimulationProtocol.Backend.Capabilities,\n },\n request.params,\n )\n case \"llm.attach\":\n return controllerLock.withPermit(\n Effect.gen(function* () {\n if (socket.data.closed)\n return yield* Effect.fail(\n new ControllerDisconnectedError({ message: \"Drive controller disconnected before attachment\" }),\n )\n const previous = yield* Ref.get(activeController)\n if (previous) yield* Fiber.interrupt(previous)\n const attachment = yield* FiberSet.run(\n fibers,\n driver.requests.pipe(\n Stream.runForEach((invocation) =>\n Effect.sync(() => {\n socket.send(JSON.stringify({ jsonrpc: \"2.0\", method: \"llm.request\", params: invocation }))\n }),\n ),\n ),\n )\n if (socket.data.closed) {\n yield* Fiber.interrupt(attachment)\n return yield* Effect.fail(\n new ControllerDisconnectedError({ message: \"Drive controller disconnected during attachment\" }),\n )\n }\n socket.data.attachment = attachment\n yield* Ref.set(activeController, attachment)\n return { attached: true }\n }),\n )\n case \"llm.chunk\":\n return driver.push(request.params.id, request.params.items).pipe(Effect.as({ ok: true }))\n case \"llm.finish\":\n return driver.finish(request.params.id, request.params.reason).pipe(Effect.as({ ok: true }))\n case \"llm.disconnect\":\n return driver.disconnect(request.params.id).pipe(Effect.as({ ok: true }))\n case \"llm.pending\":\n return driver.pending().pipe(Effect.map((invocations) => ({ invocations })))\n }\n}\n\nfunction releaseController(\n activeController: Ref.Ref<Fiber.Fiber<void> | undefined>,\n controllerLock: Semaphore.Semaphore,\n socket: ControlSocket,\n) {\n return controllerLock.withPermit(\n Effect.gen(function* () {\n const attachment = socket.data.attachment\n if (!attachment) return\n yield* Fiber.interrupt(attachment)\n yield* Ref.update(activeController, (active) => (active === attachment ? undefined : active))\n }),\n )\n}\n\nexport * as SimulatedProvider from \"./simulated-provider\"\n", | ||
| "import { LayerNode } from \"@opencode-ai/core/effect/layer-node\"\nimport { httpClient } from \"@opencode-ai/core/effect/app-node-platform\"\nimport { Config, Effect, Layer } from \"effect\"\nimport { HttpClient } from \"effect/unstable/http\"\nimport { DriveManifest } from \"../manifest\"\nimport { SimulationNetwork } from \"./network\"\nimport { SimulationOpenAI } from \"./openai\"\nimport { SimulatedProvider } from \"./simulated-provider\"\n\n/**\n * Layer replacements applied when the server is built in simulation mode.\n *\n * The server merges these into the app node build when `OPENCODE_SIMULATE`\n * is enabled, via a dynamic import so this module is never loaded eagerly.\n *\n * - Network: all outbound HTTP resolves against the simulated route table;\n * unknown destinations are denied. The driver-answered OpenAI endpoint is\n * registered here as the first route.\n *\n */\n\nexport const simulationReplacements = Effect.fn(\"Simulation.replacements\")(function* () {\n // ModelsDev dies when its catalog fetch fails, so simulation answers it with\n // an empty catalog; providers come from seeded config instead.\n const models = SimulationNetwork.json(\"GET\", \"https://models.dev/api.json\", {})\n const drive = yield* Config.string(\"OPENCODE_DRIVE\").pipe(Config.withDefault(undefined))\n if (!drive) return [[httpClient, SimulationNetwork.layer([models])]] satisfies LayerNode.Replacements\n\n const manifest = yield* DriveManifest.resolve()\n const networkLayer = Layer.effect(\n HttpClient.HttpClient,\n Effect.gen(function* () {\n const provider = yield* SimulatedProvider.Service\n const network = yield* SimulationNetwork.make([SimulationOpenAI.route(provider), models])\n return network.client\n }),\n ).pipe(\n Layer.provide(\n SimulatedProvider.layerDrive({\n endpoint: manifest.endpoints.backend,\n }),\n ),\n )\n return [[httpClient, networkLayer]] satisfies LayerNode.Replacements\n})\n\nexport * as Simulation from \"./index\"\n" | ||
| ], | ||
| "mappings": ";svBA4BA,SAAM,QAAY,UAGX,cAAS,OAAI,MAAC,OAA+B,OAAa,OAAsB,MACrF,MAAO,CACL,MAAO,CAAC,EAAS,IAAe,CAC9B,GAAI,EAAQ,SAAW,EAAQ,OAC/B,GAAI,EAAW,OAAS,EAAW,WAAa,EAAK,OACrD,OAAO,EAAO,KAAK,IACjB,EAAmB,QACjB,EACA,IAAI,SAAS,KAAK,UAAU,CAAI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Q,EACxC,EAAe,EAAM,OACzB,EAAW,WACX,EAAO,IAAI,SAAU,EAAG,CACtB,IAAM,EAAW,MAAO,EAAkB,QAE1C,OADgB,MAAO,EAAkB,KAAK,CAAC,EAAiB,MAAM,CAAQ,EAAG,CAAM,CAAC,GACzE,OAChB,CACH,EAAE,KACA,EAAM,QACJ,EAAkB,WAAW,CAC3B,SAAU,EAAS,UAAU,OAC/B,CAAC,CACH,CACF,EACA,MAAO,CAAC,CAAC,EAAY,CAAY,CAAC,EACnC", | ||
| "debugId": "1408EFA899E4F7BD64756E2164756E21", | ||
| "names": [] | ||
| } |
| { | ||
| "version": 3, | ||
| "sources": ["src/commands/handlers/service/unset.ts"], | ||
| "sourcesContent": [ | ||
| "import { Effect } from \"effect\"\nimport { Commands } from \"../../commands\"\nimport { Runtime } from \"../../../framework/runtime\"\nimport { ServiceConfig } from \"../../../services/service-config\"\n\nexport default Runtime.handler(\n Commands.commands.service.commands.unset,\n Effect.fn(\"cli.service.unset\")(function* (input) {\n yield* ServiceConfig.unset(input.key)\n }),\n)\n" | ||
| ], | ||
| "mappings": ";o2BAKA,SAAe,SAAQ,aACrB,OAAS,cAAS,aAAQ,cAAS,WACnC,OAAO,QAAG,wBAAmB,OAAE,cAAU,MAAC,OAAO,MAC/C,WAAO,OAAc,WAAM,OAAM,QAAG,OACrC,MACH", | ||
| "debugId": "8A2030DBFE3B7B8964756E2164756E21", | ||
| "names": [] | ||
| } |
| { | ||
| "version": 3, | ||
| "sources": ["src/commands/handlers/service/start.ts"], | ||
| "sourcesContent": [ | ||
| "import { EOL } from \"os\"\nimport { Effect } from \"effect\"\nimport { Service } from \"@opencode-ai/client/effect/service\"\nimport { Commands } from \"../../commands\"\nimport { Runtime } from \"../../../framework/runtime\"\nimport { ServiceConfig } from \"../../../services/service-config\"\n\nexport default Runtime.handler(\n Commands.commands.service.commands.start,\n Effect.fn(\"cli.service.start\")(function* () {\n const transport = yield* Service.ensure(yield* ServiceConfig.options())\n process.stdout.write(transport.url + EOL)\n }),\n)\n" | ||
| ], | ||
| "mappings": ";i3BAAA,mBAAS,gBAOT,SAAe,SAAQ,aACrB,OAAS,cAAS,aAAQ,cAAS,WACnC,OAAO,QAAG,wBAAmB,OAAE,cAAU,OAAG,MAC1C,SAAM,OAAY,WAAO,OAAQ,YAAO,WAAO,EAAc,QAAQ,CAAC,EACtE,QAAQ,OAAO,MAAM,EAAU,IAAM,CAAG,EACzC,CACH", | ||
| "debugId": "E5A7E2C66193AA8164756E2164756E21", | ||
| "names": [] | ||
| } |
| { | ||
| "version": 3, | ||
| "sources": ["../core/src/util/process-lock.ts", "src/server-process.ts", "src/commands/handlers/serve.ts"], | ||
| "sourcesContent": [ | ||
| "import { dlopen, read, type Pointer } from \"bun:ffi\"\nimport { closeSync, existsSync, mkdirSync, openSync } from \"node:fs\"\nimport { connect, createServer, type Server, type Socket } from \"node:net\"\nimport path from \"node:path\"\nimport { Effect, Schema } from \"effect\"\nimport { Hash } from \"./hash\"\n\nexport namespace ProcessLock {\n export class HeldError extends Schema.TaggedErrorClass<HeldError>()(\"ProcessLockHeldError\", {\n file: Schema.String,\n }) {\n override get message() {\n return `Process lock is already held: ${this.file}`\n }\n }\n\n export class SystemError extends Schema.TaggedErrorClass<SystemError>()(\"ProcessLockSystemError\", {\n file: Schema.String,\n operation: Schema.Literals([\"open\", \"acquire\"]),\n code: Schema.String,\n }) {\n override get message() {\n return `Process lock ${this.operation} failed for ${this.file}: ${this.code}`\n }\n }\n\n export type LockError = HeldError | SystemError\n\n const acquirePosix = Effect.fnUntraced(function* (file: string) {\n const fd = yield* Effect.try({\n try: () => {\n mkdirSync(path.dirname(file), { recursive: true })\n return openSync(file, \"a+\", 0o600)\n },\n catch: (cause) =>\n new SystemError({\n file,\n operation: \"open\",\n code: cause instanceof Error ? cause.message : String(cause),\n }),\n })\n const result = yield* Effect.try({\n try: () => lock(fd),\n catch: (cause) =>\n new SystemError({\n file,\n operation: \"acquire\",\n code: cause instanceof Error ? cause.message : String(cause),\n }),\n }).pipe(\n Effect.tapError(() =>\n Effect.sync(() => {\n closeSync(fd)\n }),\n ),\n )\n if (result.acquired) {\n return fd\n }\n closeSync(fd)\n return yield* result.held\n ? new HeldError({ file })\n : new SystemError({ file, operation: \"acquire\", code: String(result.code) })\n })\n\n export const acquire = Effect.fn(\"ProcessLock.acquire\")(function* (file: string) {\n if (process.platform === \"win32\") {\n yield* Effect.acquireRelease(acquireWindows(file), closeWindows)\n return\n }\n yield* Effect.acquireRelease(acquirePosix(file), (fd) =>\n Effect.sync(() => {\n closeSync(fd)\n }),\n )\n })\n}\n\ntype Result =\n | { readonly acquired: true }\n | { readonly acquired: false; readonly held: true }\n | { readonly acquired: false; readonly held: false; readonly code: number }\n\nconst LOCK_EX = 2\nconst LOCK_NB = 4\nconst DARWIN_EWOULDBLOCK = 35\nconst LINUX_EWOULDBLOCK = 11\n\nfunction lock(fd: number): Result {\n if (process.platform === \"darwin\") return lockDarwin(fd)\n if (process.platform === \"linux\") return lockLinux(fd)\n throw new Error(`Unsupported process lock platform: ${process.platform}`)\n}\n\nfunction lockDarwin(fd: number): Result {\n const library = dlopen(\"/usr/lib/libSystem.B.dylib\", {\n flock: { args: [\"i32\", \"i32\"], returns: \"i32\" },\n __error: { args: [], returns: \"ptr\" },\n })\n try {\n const result = library.symbols.flock(fd, LOCK_EX | LOCK_NB)\n const code = result === 0 ? 0 : errorCode(library.symbols.__error())\n if (result === 0) return { acquired: true }\n if (code === DARWIN_EWOULDBLOCK) return { acquired: false, held: true }\n return { acquired: false, held: false, code }\n } finally {\n library.close()\n }\n}\n\nfunction lockLinux(fd: number): Result {\n const musl = `/lib/libc.musl-${process.arch === \"arm64\" ? \"aarch64\" : \"x86_64\"}.so.1`\n const library = dlopen(existsSync(musl) ? musl : \"libc.so.6\", {\n flock: { args: [\"i32\", \"i32\"], returns: \"i32\" },\n __errno_location: { args: [], returns: \"ptr\" },\n })\n try {\n const result = library.symbols.flock(fd, LOCK_EX | LOCK_NB)\n const code = result === 0 ? 0 : errorCode(library.symbols.__errno_location())\n if (result === 0) return { acquired: true }\n if (code === LINUX_EWOULDBLOCK) return { acquired: false, held: true }\n return { acquired: false, held: false, code }\n } finally {\n library.close()\n }\n}\n\nfunction errorCode(pointer: Pointer | null) {\n if (pointer === null) throw new Error(\"Failed to read process lock error code\")\n return read.i32(pointer, 0)\n}\n\nfunction acquireWindows(file: string) {\n return Effect.callback<Server, ProcessLock.LockError>((resume) => {\n const server = createServer()\n let probe: Socket | undefined\n const pipe = `\\\\\\\\.\\\\pipe\\\\opencode-process-lock-${Hash.sha256(path.resolve(file).toLowerCase())}`\n const onError = (cause: NodeJS.ErrnoException) => {\n server.off(\"listening\", onListening)\n probe = connect(pipe)\n const onProbeError = () => {\n probe?.off(\"connect\", onConnect)\n resume(\n Effect.fail(\n new ProcessLock.SystemError({\n file,\n operation: \"acquire\",\n code: cause.code ?? cause.message,\n }),\n ),\n )\n }\n const onConnect = () => {\n probe?.off(\"error\", onProbeError)\n probe?.destroy()\n resume(Effect.fail(new ProcessLock.HeldError({ file })))\n }\n probe.once(\"connect\", onConnect)\n probe.once(\"error\", onProbeError)\n }\n const onListening = () => {\n server.off(\"error\", onError)\n resume(Effect.succeed(server))\n }\n server.once(\"error\", onError)\n server.once(\"listening\", onListening)\n server.on(\"connection\", (socket) => socket.destroy())\n server.listen(pipe)\n return Effect.sync(() => {\n probe?.destroy()\n server.close()\n })\n })\n}\n\nfunction closeWindows(server: Server) {\n return Effect.callback<void>((resume) => {\n if (!server.listening) return resume(Effect.void)\n server.close((error) => resume(error ? Effect.die(error) : Effect.void))\n })\n}\n", | ||
| "export * as ServerProcess from \"./server-process\"\n\nimport { NodeServices } from \"@effect/platform-node\"\nimport { Service } from \"@opencode-ai/client/effect/service\"\nimport { AppNodeBuilder } from \"@opencode-ai/core/effect/app-node-builder\"\nimport { LayerNode } from \"@opencode-ai/core/effect/layer-node\"\nimport { Global } from \"@opencode-ai/core/global\"\nimport { InstallationVersion } from \"@opencode-ai/core/installation/version\"\nimport { AppProcess } from \"@opencode-ai/core/process\"\nimport { ProcessLock } from \"@opencode-ai/core/util/process-lock\"\nimport { randomBytes, randomUUID } from \"node:crypto\"\nimport path from \"node:path\"\nimport { Effect, FileSystem, Logger, Option, Redacted, Schedule, Schema } from \"effect\"\nimport { HttpServer } from \"effect/unstable/http\"\nimport { Env } from \"./env\"\nimport { ServiceConfig } from \"./services/service-config\"\nimport { Updater } from \"./services/updater\"\n\nexport type Mode = \"default\" | \"service\" | \"stdio\"\n\nexport type Options = {\n readonly mode: Mode\n readonly hostname?: string\n readonly port?: number\n}\n\nexport const run = Effect.fn(\"cli.server-process.run\")((options: Options) =>\n processEffect(options).pipe(\n Effect.provide(Updater.layer),\n Effect.provide(AppNodeBuilder.build(LayerNode.group([Global.node, AppProcess.node]))),\n Effect.provide(NodeServices.layer),\n ),\n)\n\nconst processEffect = Effect.fnUntraced(function* (options: Options) {\n if (options.mode === \"service\") yield* Effect.sync(() => process.chdir(Global.Path.home))\n return yield* Effect.scoped(\n Effect.gen(function* () {\n const serviceOptions = options.mode === \"service\" ? yield* ServiceConfig.options() : undefined\n if (serviceOptions !== undefined) {\n const acquired = yield* ProcessLock.acquire(serviceOptions.file + \".lock\").pipe(\n Effect.as(true),\n Effect.catchTag(\"ProcessLockHeldError\", () => Effect.succeed(false)),\n )\n if (!acquired) return yield* Effect.void\n if ((yield* Service.discover(serviceOptions)) !== undefined) return yield* Effect.void\n }\n const { start } = yield* Effect.promise(() => import(\"@opencode-ai/server/process\"))\n const environmentPassword = yield* Env.password\n // Keep the lease credential out of the environment inherited by tools.\n if (options.mode === \"stdio\") {\n delete process.env.OPENCODE_PASSWORD\n delete process.env.OPENCODE_SERVER_PASSWORD\n }\n const config = options.mode === \"service\" ? yield* ServiceConfig.read() : {}\n const password =\n options.mode === \"service\"\n ? yield* ServiceConfig.password()\n : environmentPassword\n ? Redacted.value(environmentPassword)\n : randomBytes(32).toString(\"base64url\")\n if (!password) return yield* Effect.fail(new Error(\"Missing server password\"))\n const instanceID = randomUUID()\n const server = yield* start({\n hostname: options.hostname ?? config.hostname ?? \"127.0.0.1\",\n port: Option.fromNullishOr(options.port ?? config.port),\n password,\n instanceID,\n service:\n serviceOptions === undefined\n ? undefined\n : { onListen: (address) => register(address, password, instanceID, serviceOptions.file) },\n }).pipe(Effect.provide(Logger.layer([], { mergeWithExisting: false })))\n const url = HttpServer.formatAddress(server.address)\n console.log(options.mode === \"stdio\" ? JSON.stringify({ url }) : `server listening on ${url}`)\n if (options.mode === \"default\" && !environmentPassword) console.log(`server password ${password}`)\n const updater = yield* Updater.Service\n yield* updater.check().pipe(Effect.schedule(Schedule.spaced(\"10 minutes\")), Effect.forkScoped)\n return yield* options.mode === \"service\"\n ? server.shutdown\n : options.mode === \"stdio\"\n ? waitForStdinClose()\n : Effect.never\n }).pipe(Effect.annotateLogs({ role: \"server\" })),\n )\n})\n\nconst infoJson = Schema.fromJsonString(Service.Info)\nconst encodeInfo = Schema.encodeEffect(infoJson)\nconst decodeInfo = Schema.decodeUnknownEffect(infoJson)\n\nconst register = Effect.fnUntraced(function* (\n address: HttpServer.Address,\n password: string,\n id: string,\n file: string,\n) {\n const fs = yield* FileSystem.FileSystem\n const temp = file + \".\" + id + \".tmp\"\n yield* fs.makeDirectory(path.dirname(file), { recursive: true })\n const info = {\n id,\n version: InstallationVersion,\n url: HttpServer.formatAddress(address),\n pid: process.pid,\n password,\n }\n const encoded = yield* encodeInfo(info)\n const publish = fs.writeFileString(temp, encoded, { mode: 0o600 }).pipe(Effect.andThen(fs.rename(temp, file)))\n yield* publish\n const current = fs.readFileString(file).pipe(\n Effect.flatMap(decodeInfo),\n Effect.orElseSucceed(() => undefined),\n )\n const assertRegistration = Effect.gen(function* () {\n const found = yield* current\n if (\n found !== undefined &&\n found.id === info.id &&\n found.version === info.version &&\n found.url === info.url &&\n found.pid === info.pid &&\n found.password === info.password\n )\n return\n yield* publish\n })\n yield* Effect.addFinalizer(() =>\n current.pipe(\n Effect.flatMap((current) => (current?.id === id ? fs.remove(file) : Effect.void)),\n Effect.ignore,\n ),\n )\n yield* assertRegistration.pipe(\n Effect.catchCause((cause) => Effect.logWarning(\"failed to reassert service registration\", { cause })),\n Effect.repeat(Schedule.spaced(\"5 seconds\")),\n Effect.forkScoped,\n )\n})\n\nfunction waitForStdinClose() {\n return Effect.callback<void>((resume) => {\n const close = () => resume(Effect.void)\n process.stdin.once(\"end\", close)\n process.stdin.once(\"close\", close)\n process.stdin.resume()\n if (process.stdin.readableEnded || process.stdin.destroyed) close()\n return Effect.sync(() => {\n process.stdin.off(\"end\", close)\n process.stdin.off(\"close\", close)\n process.stdin.pause()\n })\n })\n}\n", | ||
| "import { Effect, Option } from \"effect\"\nimport { Commands } from \"../commands\"\nimport { Runtime } from \"../../framework/runtime\"\nimport { ServerProcess } from \"../../server-process\"\n\nexport default Runtime.handler(\n Commands.commands.serve,\n Effect.fn(\"cli.serve\")(function* (input) {\n if (input.service && input.stdio) return yield* Effect.fail(new Error(\"--service and --stdio cannot be combined\"))\n return yield* ServerProcess.run({\n mode: input.service ? \"service\" : input.stdio ? \"stdio\" : \"default\",\n hostname: Option.getOrUndefined(input.hostname),\n port: Option.getOrUndefined(input.port),\n })\n }),\n)\n" | ||
| ], | ||
| "mappings": ";o6CAAA,sBAAS,eAAQ,qBACjB,yBAAS,qBAAW,oBAAY,mBAAW,gBAE3C,yBAIO,SAAU,QAAV,MAAU,SAAV,MACE,WAAM,eAAkB,OAAO,sBAA4B,OAAE,4BAAwB,MAC1F,UAAM,OAAO,WACf,MAAC,MAAE,SACY,aAAO,OAAG,MACrB,WAAO,sCAAiC,UAAK,OAEjD,CANO,EAAM,YAQN,MAAM,UAAoB,EAAO,iBAA8B,EAAE,yBAA0B,CAChG,KAAM,EAAO,OACb,UAAW,EAAO,SAAS,CAAC,OAAQ,SAAS,CAAC,EAC9C,KAAM,EAAO,MACf,CAAC,CAAE,IACY,QAAO,EAAG,CACrB,MAAO,gBAAgB,KAAK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,EACD,EAED,SAAS,EAAiB,EAAG,CAC3B,OAAO,EAAO,SAAe,CAAC,IAAW,CACvC,IAAM,EAAQ,IAAM,EAAO,EAAO,IAAI,EAItC,GAHA,QAAQ,MAAM,KAAK,MAAO,CAAK,EAC/B,QAAQ,MAAM,KAAK,QAAS,CAAK,EACjC,QAAQ,MAAM,OAAO,EACjB,QAAQ,MAAM,eAAiB,QAAQ,MAAM,UAAW,EAAM,EAClE,OAAO,EAAO,KAAK,IAAM,CACvB,QAAQ,MAAM,IAAI,MAAO,CAAK,EAC9B,QAAQ,MAAM,IAAI,QAAS,CAAK,EAChC,QAAQ,MAAM,MAAM,EACrB,EACF,ECnJH,IAAe,KAAQ,QACrB,EAAS,SAAS,MAClB,EAAO,GAAG,WAAW,EAAE,SAAU,CAAC,EAAO,CACvC,GAAI,EAAM,SAAW,EAAM,MAAO,OAAO,MAAO,EAAO,KAAS,MAAM,0CAA0C,CAAC,EACjH,OAAO,MAAO,EAAc,IAAI,CAC9B,KAAM,EAAM,QAAU,UAAY,EAAM,MAAQ,QAAU,UAC1D,SAAU,EAAO,eAAe,EAAM,QAAQ,EAC9C,KAAM,EAAO,eAAe,EAAM,IAAI,CACxC,CAAC,EACF,CACH", | ||
| "debugId": "555C96E4148F5D9164756E2164756E21", | ||
| "names": [] | ||
| } |
Sorry, the diff of this file is too big to display
| { | ||
| "version": 3, | ||
| "sources": ["../simulation/src/frontend/actions.ts", "../simulation/src/recording.ts", "../simulation/src/frontend/renderer.ts", "../simulation/src/frontend/server.ts", "../simulation/src/frontend/simulation.ts"], | ||
| "sourcesContent": [ | ||
| "import { tmpdir } from \"node:os\"\nimport { extname, join, resolve } from \"node:path\"\nimport type { CliRenderer, Renderable } from \"@opentui/core\"\nimport { createMockKeys, createMockMouse, type MockInput, type MockMouse } from \"@opentui/core/testing\"\nimport { Config, Effect, FileSystem } from \"effect\"\nimport type { SimulationProtocol } from \"../protocol\"\nimport { SimulationRenderer } from \"./renderer\"\n\nexport type Action = SimulationProtocol.Frontend.Action\nexport type Element = SimulationProtocol.Frontend.Element\n\nexport interface Harness {\n readonly renderer: CliRenderer\n readonly mockInput: MockInput\n readonly mockMouse: MockMouse\n readonly resize: (cols: number, rows: number) => void\n readonly renderOnce: () => Promise<void>\n readonly screen: () => string\n}\n\ntype RenderBuffer = {\n readonly width: number\n readonly height: number\n getRealCharBytes(includeAnsi?: boolean): Uint8Array\n}\n\nconst decoder = new TextDecoder()\n\nfunction children(renderable: Renderable) {\n return renderable.getChildren().filter((child): child is Renderable => \"num\" in child)\n}\n\nfunction all(renderable: Renderable): Renderable[] {\n return [renderable, ...children(renderable).flatMap(all)]\n}\n\nfunction mouseListeners(renderable: Renderable) {\n const general = Reflect.get(renderable, \"_mouseListener\")\n const specific = Reflect.get(renderable, \"_mouseListeners\")\n return Boolean(general) || (specific && typeof specific === \"object\" && Object.keys(specific).length > 0)\n}\n\nfunction hit(renderer: CliRenderer, renderable: Renderable) {\n if (renderable.width <= 0 || renderable.height <= 0) return false\n const x = Math.floor(renderable.screenX + renderable.width / 2)\n const y = Math.floor(renderable.screenY + renderable.height / 2)\n return renderer.hitTest(x, y) === renderable.num\n}\n\n/**\n * Builds the harness the simulation server drives.\n *\n * When the renderer is the headless simulation renderer, its TestRendererSetup\n * provides the supported testing APIs. For the visible terminal renderer the\n * harness falls back to `requestRender` + `idle` and reading the private\n * `currentRenderBuffer`.\n */\nexport function createHarness(renderer: CliRenderer): Harness {\n const setup = SimulationRenderer.setupFor(renderer)\n return {\n renderer,\n mockInput: setup?.mockInput ?? createMockKeys(renderer),\n mockMouse: setup?.mockMouse ?? createMockMouse(renderer),\n resize: setup?.resize ?? ((cols, rows) => renderer.resize(cols, rows)),\n renderOnce:\n setup?.renderOnce ??\n (async () => {\n renderer.requestRender()\n await renderer.idle()\n }),\n // captureCharFrame follows the test renderer's output sink. Recording\n // redirects that sink to the timeline, so read the live render buffer\n // instead; it is also the source used by screenshots.\n screen: () => decoder.decode((Reflect.get(renderer, \"currentRenderBuffer\") as RenderBuffer).getRealCharBytes()),\n }\n}\n\nexport function elements(renderer: CliRenderer): Element[] {\n return all(renderer.root)\n .filter((renderable) => renderable.visible && !renderable.isDestroyed)\n .map((renderable) => {\n const clickable = mouseListeners(renderable) && hit(renderer, renderable)\n return {\n id: renderable.id,\n num: renderable.num,\n x: renderable.screenX,\n y: renderable.screenY,\n width: renderable.width,\n height: renderable.height,\n focusable: renderable.focusable,\n focused: renderable.focused,\n clickable,\n editor: renderer.currentFocusedEditor === renderable,\n } satisfies Element\n })\n .filter((element) => element.focusable || element.clickable || element.editor)\n}\n\nexport function state(harness: Harness) {\n return {\n focused: {\n renderable: harness.renderer.currentFocusedRenderable?.num,\n editor: Boolean(harness.renderer.currentFocusedEditor),\n },\n elements: elements(harness.renderer),\n }\n}\n\nexport function matches(harness: Pick<Harness, \"screen\">, text: string) {\n return harness.screen().includes(text)\n}\n\nexport const capture = Effect.fn(\"SimulationActions.capture\")(function* (harness: Harness) {\n yield* Effect.tryPromise(() => harness.renderOnce())\n const buffer = harness.renderer.currentRenderBuffer\n return {\n cols: buffer.width,\n rows: buffer.height,\n cursor: [0, 0] as const,\n lines: buffer.getSpanLines().map((line) => ({\n spans: line.spans.map((span) => ({\n text: span.text,\n fg: span.fg.toInts(),\n bg: span.bg.toInts(),\n attributes: span.attributes,\n width: span.width,\n })),\n })),\n } satisfies SimulationProtocol.Frontend.CapturedFrame\n})\n\nexport const screenshot = Effect.fn(\"SimulationActions.screenshot\")(function* (harness: Harness, name?: string) {\n const filename = name ?? `screenshot-${crypto.randomUUID()}`\n if (!filename || filename.includes(\"/\") || filename.includes(\"\\\\\") || extname(filename))\n return yield* Effect.fail(new Error(\"screenshot name must not contain a path or extension\"))\n yield* Effect.tryPromise(() => harness.renderOnce())\n const { SimulationPng } = yield* Effect.promise(() => import(\"./png\"))\n const image = SimulationPng.screenshot(harness.renderer)\n const directory = resolve(\n yield* Config.string(\"OPENCODE_DRIVE_MEDIA_DIR\").pipe(\n Config.withDefault(join(tmpdir(), \"opencode-drive\", \"output\")),\n ),\n )\n const fs = yield* FileSystem.FileSystem\n yield* fs.makeDirectory(directory, { recursive: true })\n const path = join(directory, `${filename}.png`)\n yield* fs.writeFile(path, image.data)\n return path\n})\n\nexport const execute = Effect.fn(\"SimulationActions.execute\")(function* (harness: Harness, action: Action) {\n switch (action.type) {\n case \"ui.type\":\n yield* Effect.tryPromise(() => harness.mockInput.typeText(action.text))\n break\n case \"ui.press\":\n harness.mockInput.pressKey(action.key, action.modifiers)\n break\n case \"ui.enter\":\n harness.mockInput.pressEnter()\n break\n case \"ui.arrow\":\n harness.mockInput.pressArrow(action.direction)\n break\n case \"ui.focus\":\n all(harness.renderer.root)\n .find((item) => item.num === action.target)\n ?.focus()\n break\n case \"ui.click\":\n yield* Effect.tryPromise(() => harness.mockMouse.click(action.x, action.y))\n break\n case \"ui.resize\":\n if (\n !Number.isSafeInteger(action.cols) ||\n action.cols <= 0 ||\n !Number.isSafeInteger(action.rows) ||\n action.rows <= 0\n ) {\n return yield* Effect.fail(new Error(\"resize cols and rows must be positive integers\"))\n }\n harness.resize(action.cols, action.rows)\n SimulationRenderer.recordResize(harness.renderer, action.cols, action.rows)\n break\n }\n yield* Effect.tryPromise(() => harness.renderOnce())\n return state(harness)\n})\n\nexport * as SimulationActions from \"./actions\"\n", | ||
| "import { createWriteStream, type WriteStream } from \"node:fs\"\nimport { mkdir } from \"node:fs/promises\"\nimport { dirname } from \"node:path\"\nimport { Writable } from \"node:stream\"\nimport { finished } from \"node:stream/promises\"\nimport { Schema } from \"effect\"\n\nexport const Header = Schema.Struct({\n type: Schema.Literal(\"header\"),\n version: Schema.Literal(1),\n cols: Schema.Number,\n rows: Schema.Number,\n encoding: Schema.Literal(\"base64\"),\n})\nexport interface Header extends Schema.Schema.Type<typeof Header> {}\n\nexport const Output = Schema.Struct({\n type: Schema.Literal(\"output\"),\n at_ms: Schema.Number,\n data: Schema.String,\n})\nexport interface Output extends Schema.Schema.Type<typeof Output> {}\n\nexport const Resize = Schema.Struct({\n type: Schema.Literal(\"resize\"),\n at_ms: Schema.Number,\n cols: Schema.Number,\n rows: Schema.Number,\n})\nexport interface Resize extends Schema.Schema.Type<typeof Resize> {}\n\nexport const Event = Schema.Union([Header, Output, Resize])\nexport type Event = Schema.Schema.Type<typeof Event>\n\nexport class Timeline extends Writable {\n readonly isTTY = true\n readonly path: string\n readonly columns: number\n readonly rows: number\n private readonly output: WriteStream\n private readonly started = performance.now()\n private readonly timestamps: number[] = []\n private done?: Promise<string>\n\n private constructor(path: string, cols: number, rows: number, output: WriteStream) {\n super()\n this.path = path\n this.columns = cols\n this.rows = rows\n this.output = output\n // finish() reports stream failures; keep Writable from also throwing them process-wide.\n this.on(\"error\", () => {})\n output.on(\"error\", (error) => this.destroy(error))\n }\n\n static async create(path: string, cols: number, rows: number) {\n await mkdir(dirname(path), { recursive: true })\n const output = createWriteStream(path)\n const timeline = new Timeline(path, cols, rows, output)\n await new Promise<void>((resolve, reject) => {\n output.write(\n `${JSON.stringify({ type: \"header\", version: 1, cols, rows, encoding: \"base64\" } satisfies Header)}\\n`,\n (error) => (error ? reject(error) : resolve()),\n )\n })\n return timeline\n }\n\n getColorDepth() {\n return 24\n }\n\n override write(chunk: unknown, callback?: (error?: Error | null) => void): boolean\n override write(chunk: unknown, encoding: BufferEncoding, callback?: (error?: Error | null) => void): boolean\n override write(\n chunk: unknown,\n encoding?: BufferEncoding | ((error?: Error | null) => void),\n callback?: (error?: Error | null) => void,\n ) {\n if (!this.writableEnded) {\n this.timestamps.push(this.elapsed())\n if (typeof encoding === \"function\") return super.write(chunk, encoding)\n if (encoding === undefined) return super.write(chunk, callback)\n return super.write(chunk, encoding, callback)\n }\n const done = typeof encoding === \"function\" ? encoding : callback\n queueMicrotask(() => done?.(null))\n return true\n }\n\n override _write(chunk: Buffer, _encoding: BufferEncoding, callback: (error?: Error | null) => void) {\n this.writeOutput(chunk, this.timestamps.shift() ?? this.elapsed(), callback)\n }\n\n override _final(callback: (error?: Error | null) => void) {\n this.writeOutput(Buffer.alloc(0), this.elapsed(), (error) => {\n if (error) return callback(error)\n this.output.end(callback)\n })\n }\n\n finish() {\n if (this.done) return this.done\n this.end()\n this.done = finished(this).then(() => this.path)\n return this.done\n }\n\n resize(cols: number, rows: number) {\n if (this.writableEnded) return\n const event = { type: \"resize\", at_ms: this.elapsed(), cols, rows } satisfies Resize\n this.output.write(`${JSON.stringify(event)}\\n`)\n }\n\n private elapsed() {\n return Math.max(0, Math.round(performance.now() - this.started))\n }\n\n private writeOutput(data: Buffer, at_ms: number, callback: (error?: Error | null) => void) {\n const event = {\n type: \"output\",\n at_ms,\n data: data.toString(\"base64\"),\n } satisfies Output\n this.output.write(`${JSON.stringify(event)}\\n`, callback)\n }\n}\n\nexport * as SimulationRecording from \"./recording\"\n", | ||
| "import type { CliRenderer, CliRendererConfig } from \"@opentui/core\"\nimport { createTestRenderer, type TestRendererSetup } from \"@opentui/core/testing\"\nimport { Effect } from \"effect\"\nimport { Timeline } from \"../recording\"\n\nconst setups = new WeakMap<CliRenderer, TestRendererSetup>()\nconst recordings = new WeakMap<CliRenderer, Timeline>()\n\n/**\n * Creates a headless renderer with optional recording: a real CliRenderer\n * backed by an in-memory screen buffer. The TestRendererSetup is kept\n * module-side so the harness can use supported testing APIs without app\n * code carrying it around.\n */\nexport interface Viewport {\n readonly cols: number\n readonly rows: number\n}\n\nexport const create = Effect.fn(\"SimulationRenderer.create\")(function* (\n options: CliRendererConfig,\n path?: string,\n viewport?: Viewport,\n) {\n const cols = viewport?.cols ?? 100\n const rows = viewport?.rows ?? 40\n const recording = path\n ? yield* Effect.acquireRelease(\n Effect.tryPromise(() => Timeline.create(path, cols, rows)),\n (recording) =>\n Effect.tryPromise(() => recording.finish()).pipe(\n Effect.catch((error) =>\n Effect.sync(() => process.stderr.write(`Failed to finish UI recording: ${error}\\n`)),\n ),\n ),\n )\n : undefined\n const setup = yield* Effect.acquireRelease(\n Effect.tryPromise(() =>\n createTestRenderer({\n ...options,\n width: cols,\n height: rows,\n ...(recording\n ? {\n stdout: recording as unknown as NodeJS.WriteStream,\n bufferedOutput: \"stdout\" as const,\n }\n : {}),\n }),\n ),\n (setup) =>\n Effect.sync(() => {\n if (!setup.renderer.isDestroyed) setup.renderer.destroy()\n }),\n )\n setups.set(setup.renderer, setup)\n if (recording) recordings.set(setup.renderer, recording)\n return setup.renderer\n})\n\nexport function recordResize(renderer: CliRenderer, cols: number, rows: number) {\n recordings.get(renderer)?.resize(cols, rows)\n}\n\nexport function setupFor(renderer: CliRenderer): TestRendererSetup | undefined {\n return setups.get(renderer)\n}\n\nexport function finish(renderer: CliRenderer) {\n const recording = recordings.get(renderer)\n if (!recording) return Effect.fail(new Error(\"UI recording is not available\"))\n return Effect.tryPromise(() => recording.finish())\n}\n\nexport * as SimulationRenderer from \"./renderer\"\n", | ||
| "import { InstallationVersion } from \"@opencode-ai/core/installation/version\"\nimport { Effect } from \"effect\"\nimport { SimulationControlServer } from \"../control-server\"\nimport { SimulationProtocol } from \"../protocol\"\nimport { SimulationActions, type Harness } from \"./actions\"\nimport { SimulationRenderer } from \"./renderer\"\n\nfunction handle(harness: Harness, request: SimulationProtocol.Frontend.Request) {\n switch (request.method) {\n case \"simulation.handshake\":\n return SimulationProtocol.Handshake.dispatch(\n {\n role: \"ui\",\n server: { name: \"opencode\", version: InstallationVersion },\n capabilities: SimulationProtocol.Frontend.Capabilities,\n },\n request.params,\n )\n case \"ui.capture\":\n return SimulationActions.capture(harness)\n case \"ui.screenshot\":\n return SimulationActions.screenshot(harness, request.params?.name)\n case \"ui.state\":\n return Effect.sync(() => SimulationActions.state(harness))\n case \"ui.matches\":\n return Effect.sync(() => SimulationActions.matches(harness, request.params.text))\n case \"ui.recording.finish\":\n return SimulationRenderer.finish(harness.renderer)\n case \"ui.type\":\n return SimulationActions.execute(harness, { type: \"ui.type\", text: request.params.text })\n case \"ui.enter\":\n return SimulationActions.execute(harness, { type: \"ui.enter\" })\n case \"ui.press\":\n return SimulationActions.execute(harness, {\n type: \"ui.press\",\n key: request.params.key,\n modifiers: request.params.modifiers,\n })\n case \"ui.arrow\":\n return SimulationActions.execute(harness, { type: \"ui.arrow\", direction: request.params.direction })\n case \"ui.focus\":\n return SimulationActions.execute(harness, { type: \"ui.focus\", target: request.params.target })\n case \"ui.click\":\n return SimulationActions.execute(harness, {\n type: \"ui.click\",\n target: request.params.target,\n x: request.params.x,\n y: request.params.y,\n })\n case \"ui.resize\":\n return SimulationActions.execute(harness, {\n type: \"ui.resize\",\n cols: request.params.cols,\n rows: request.params.rows,\n })\n }\n}\n\nexport const start = Effect.fn(\"SimulationServer.start\")(function* (harness: Harness, endpoint: string) {\n return yield* SimulationControlServer.start({\n endpoint,\n label: \"opencode drive ui websocket\",\n data: () => ({ drive: true as const }),\n decode: SimulationProtocol.Frontend.decodeRequestEffect,\n handle: (_socket, request) => handle(harness, request),\n })\n})\n\nexport * as SimulationServer from \"./server\"\n", | ||
| "import { createCliRenderer, type CliRendererConfig } from \"@opentui/core\"\nimport { Config, Effect } from \"effect\"\nimport { DriveManifest } from \"../manifest\"\nimport { SimulationActions } from \"./actions\"\nimport { SimulationRenderer } from \"./renderer\"\nimport { SimulationServer } from \"./server\"\n\n/** Drive-mode renderer and control-server acquisition. */\nexport const create = Effect.fn(\"Drive.create\")(function* (options: CliRendererConfig) {\n const headless = (yield* Config.string(\"OPENCODE_DRIVE_RENDERER\").pipe(Config.withDefault(\"visible\"))) === \"headless\"\n const manifest = yield* DriveManifest.resolve()\n const renderer = headless\n ? yield* SimulationRenderer.create(options, manifest.recording?.timeline, manifest.viewport)\n : yield* Effect.acquireRelease(\n Effect.tryPromise(() => createCliRenderer(options)),\n (renderer) =>\n Effect.sync(() => {\n if (!renderer.isDestroyed) renderer.destroy()\n }),\n )\n if (!headless && manifest.viewport) renderer.resize(manifest.viewport.cols, manifest.viewport.rows)\n const server = yield* SimulationServer.start(SimulationActions.createHarness(renderer), manifest.endpoints.ui)\n yield* Effect.sync(() =>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AG,EAAQ,OAAO,EAClB,EAAG,EAAQ,OAAO,CACpB,CAAC,MACE,YACH,OAAO,EAAkB,QAAQ,EAAS,CACxC,KAAM,YACN,KAAM,EAAQ,OAAO,KACrB,KAAM,EAAQ,OAAO,IACvB,CAAC,GAIA,IAAM,GAAQ,EAAO,GAAG,wBAAwB,EAAE,SAAU,CAAC,EAAkB,EAAkB,CACtG,OAAO,MAAO,EAAwB,MAAM,CAC1C,WACA,MAAO,8BACP,KAAM,KAAO,CAAE,MAAO,EAAc,GACpC,OAAQ,EAAmB,SAAS,oBACpC,OAAQ,CAAC,EAAS,IAAY,GAAO,EAAS,CAAO,CACvD,CAAC,EACF,EC1DM,IAAM,GAAS,EAAO,GAAG,cAAc,EAAE,SAAU,CAAC,EAA4B,CACrF,IAAM,GAAY,MAAO,EAAO,OAAO,yBAAyB,EAAE,KAAK,EAAO,YAAY,SAAS,CAAC,KAAO,WACrG,EAAW,MAAO,EAAc,QAAQ,EACxC,EAAW,EACb,MAAO,EAAmB,OAAO,EAAS,EAAS,WAAW,SAAU,EAAS,QAAQ,EACzF,MAAO,EAAO,eACZ,EAAO,WAAW,IAAM,EAAkB,CAAO,CAAC,EAClD,CAAC,IACC,EAAO,KAAK,IAAM,CAChB,GAAI,CAAC,EAAS,YAAa,EAAS,QAAQ,EAC7C,CACL,EACJ,GAAI,CAAC,GAAY,EAAS,SAAU,EAAS,OAAO,EAAS,SAAS,KAAM,EAAS,SAAS,IAAI,EAClG,IAAM,EAAS,MAAO,EAAiB,MAAM,EAAkB,cAAc,CAAQ,EAAG,EAAS,UAAU,EAAE,EAE7G,OADA,MAAO,EAAO,KAAK,IAAM,QAAQ,OAAO,MAAM,gCAAgC,EAAO;AAAA,CAAO,CAAC,EACtF,EACR", | ||
| "debugId": "72850C530B9185A464756E2164756E21", | ||
| "names": [] | ||
| } |
| { | ||
| "version": 3, | ||
| "sources": ["src/commands/handlers/migrate.ts"], | ||
| "sourcesContent": [ | ||
| "import { Effect } from \"effect\"\nimport { Commands } from \"../commands\"\nimport { Runtime } from \"../../framework/runtime\"\n\nexport default Runtime.handler(Commands.commands.migrate, (_input) => Effect.log(\"No migrations to run.\"))\n" | ||
| ], | ||
| "mappings": ";ivBAIA,SAAe,SAAQ,aAAQ,OAAS,cAAS,aAAS,MAAC,SAAW,OAAO,SAAI,4BAAuB,MAAC", | ||
| "debugId": "0D40E749206D7CEC64756E2164756E21", | ||
| "names": [] | ||
| } |
Sorry, the diff of this file is too big to display
| { | ||
| "version": 3, | ||
| "sources": ["src/commands/handlers/mcp/list.ts"], | ||
| "sourcesContent": [ | ||
| "import { EOL } from \"node:os\"\nimport { Effect } from \"effect\"\nimport { OpenCode, type McpServer } from \"@opencode-ai/client\"\nimport { Commands } from \"../../commands\"\nimport { Runtime } from \"../../../framework/runtime\"\nimport { Service } from \"@opencode-ai/client/effect/service\"\nimport { ServiceConfig } from \"../../../services/service-config\"\n\nexport default Runtime.handler(\n Commands.commands.mcp.commands.list,\n Effect.fn(\"cli.mcp.list\")(function* () {\n const options = yield* ServiceConfig.options()\n const found = yield* Service.discover(options)\n const endpoint = found ?? (yield* Service.ensure(options))\n const client = OpenCode.make({ baseUrl: endpoint.url, headers: Service.headers(endpoint) })\n const response = yield* Effect.promise(() => client.mcp.list({ location: { directory: process.cwd() } }))\n const servers = response.data.toSorted((a, b) => a.name.localeCompare(b.name))\n if (servers.length === 0) {\n process.stdout.write(\"No MCP servers configured\" + EOL)\n return\n }\n const width = Math.max(...servers.map((server) => server.name.length))\n const lines = servers.map(\n (server) => `${icon(server.status)} ${server.name.padEnd(width)} ${describe(server.status)}`,\n )\n process.stdout.write(lines.join(EOL) + EOL)\n }),\n)\n\nfunction icon(status: McpServer[\"status\"]) {\n switch (status.status) {\n case \"connected\":\n return \"✓\"\n case \"needs_auth\":\n return \"⚠\"\n case \"failed\":\n case \"needs_client_registration\":\n return \"✗\"\n default:\n return \"○\"\n }\n}\n\nfunction describe(status: McpServer[\"status\"]) {\n switch (status.status) {\n case \"needs_auth\":\n return \"needs authentication\"\n case \"needs_client_registration\":\n return `needs client registration: ${status.error}`\n case \"failed\":\n return `failed: ${status.error}`\n default:\n return status.status\n }\n}\n" | ||
| ], | ||
| "mappings": ";g6BAAA,mBAAS,gBAQT,SAAe,SAAQ,aACrB,OAAS,cAAS,SAAI,cAAS,UAC/B,OAAO,QAAG,mBAAc,OAAE,cAAU,OAAG,MACrC,SAAM,OAAU,WAAO,OAAc,aAAQ,OAEvC,QADQ,MAAO,EAAQ,SAAS,CAAO,KAClB,MAAO,EAAQ,OAAO,CAAO,GAClD,EAAS,EAAS,KAAK,CAAE,QAAS,EAAS,IAAK,QAAS,EAAQ,QAAQ,CAAQ,CAAE,CAAC,EAEpF,GADW,MAAO,EAAO,QAAQ,IAAM,EAAO,IAAI,KAAK,CAAE,SAAU,CAAE,UAAW,QAAQ,IAAI,CAAE,CAAE,CAAC,CAAC,GAC/E,KAAK,SAAS,CAAC,EAAG,IAAM,EAAE,KAAK,cAAc,EAAE,IAAI,CAAC,EAC7E,GAAI,EAAQ,SAAW,EAAG,CACxB,QAAQ,OAAO,MAAM,4BAA8B,CAAG,EACtD,OAEF,IAAM,EAAQ,KAAK,IAAI,GAAG,EAAQ,IAAI,CAAC,IAAW,EAAO,KAAK,MAAM,CAAC,EAC/D,EAAQ,EAAQ,IACpB,CAAC,IAAW,GAAG,EAAK,EAAO,MAAM,KAAK,EAAO,KAAK,OAAO,CAAK,MAAM,EAAS,EAAO,MAAM,GAC5F,EACA,QAAQ,OAAO,MAAM,EAAM,KAAK,CAAG,EAAI,CAAG,EAC3C,CACH,EAEA,SAAS,CAAI,CAAC,EAA6B,CACzC,OAAQ,EAAO,YACR,YACH,MAAO,aACJ,aACH,MAAO,aACJ,aACA,4BACH,MAAO,iBAEP,MAAO,UAIb,SAAS,CAAQ,CAAC,EAA6B,CAC7C,OAAQ,EAAO,YACR,aACH,MAAO,2BACJ,4BACH,MAAO,8BAA8B,EAAO,YACzC,SACH,MAAO,WAAW,EAAO,gBAEzB,OAAO,EAAO", | ||
| "debugId": "B06F961BF3AFB94664756E2164756E21", | ||
| "names": [] | ||
| } |
Sorry, the diff of this file is too big to display
| { | ||
| "version": 3, | ||
| "sources": ["src/commands/handlers/debug/agents.ts"], | ||
| "sourcesContent": [ | ||
| "import { EOL } from \"os\"\nimport { Effect } from \"effect\"\nimport { OpenCode } from \"@opencode-ai/client\"\nimport { Commands } from \"../../commands\"\nimport { Runtime } from \"../../../framework/runtime\"\nimport { Service } from \"@opencode-ai/client/effect/service\"\nimport { ServiceConfig } from \"../../../services/service-config\"\n\nexport default Runtime.handler(\n Commands.commands.debug.commands.agents,\n Effect.fn(\"cli.debug.agents\")(function* () {\n const options = yield* ServiceConfig.options()\n const found = yield* Service.discover(options)\n const endpoint = found ?? (yield* Service.ensure(options))\n const client = OpenCode.make({ baseUrl: endpoint.url, headers: Service.headers(endpoint) })\n const response = yield* Effect.promise(() => client.agent.list({ location: { directory: process.cwd() } }))\n process.stdout.write(\n JSON.stringify(\n response.data.toSorted((a, b) => a.id.localeCompare(b.id)),\n null,\n 2,\n ) + EOL,\n )\n }),\n)\n" | ||
| ], | ||
| "mappings": ";g6BAAA,mBAAS,gBAQT,SAAe,SAAQ,aACrB,OAAS,cAAS,WAAM,cAAS,YACjC,OAAO,QAAG,uBAAkB,OAAE,cAAU,OAAG,MACzC,SAAM,OAAU,WAAO,OAAc,aAAQ,OAEvC,QADQ,MAAO,EAAQ,SAAS,CAAO,KAClB,MAAO,EAAQ,OAAO,CAAO,GAClD,EAAS,EAAS,KAAK,CAAE,QAAS,EAAS,IAAK,QAAS,EAAQ,QAAQ,CAAQ,CAAE,CAAC,EACpF,EAAW,MAAO,EAAO,QAAQ,IAAM,EAAO,MAAM,KAAK,CAAE,SAAU,CAAE,UAAW,QAAQ,IAAI,CAAE,CAAE,CAAC,CAAC,EAC1G,QAAQ,OAAO,MACb,KAAK,UACH,EAAS,KAAK,SAAS,CAAC,EAAG,IAAM,EAAE,GAAG,cAAc,EAAE,EAAE,CAAC,EACzD,KACA,CACF,EAAI,CACN,EACD,CACH", | ||
| "debugId": "2607D1EC1463628564756E2164756E21", | ||
| "names": [] | ||
| } |
| { | ||
| "version": 3, | ||
| "sources": ["../core/src/image/photon.ts"], | ||
| "sourcesContent": [ | ||
| "// @ts-ignore Bun's static file import is embedded by `bun build --compile`; some consumers also declare *.wasm.\nimport photonWasm from \"@silvia-odwyer/photon-node/photon_rs_bg.wasm\" with { type: \"file\" }\nimport { Effect } from \"effect\"\nimport path from \"node:path\"\nimport { fileURLToPath } from \"node:url\"\nimport { FileSystem } from \"../filesystem\"\nimport { DecodeError, ResizerUnavailableError, SizeError } from \"../image\"\n\nconst JPEG_QUALITIES = [80, 85, 70, 55, 40]\n\nexport const make = Effect.gen(function* () {\n ;(globalThis as typeof globalThis & { __OPENCODE_PHOTON_WASM_PATH?: string }).__OPENCODE_PHOTON_WASM_PATH =\n path.isAbsolute(photonWasm) ? photonWasm : fileURLToPath(new URL(photonWasm, import.meta.url))\n const loadPhoton = yield* Effect.cached(\n Effect.tryPromise({\n try: () => import(\"@silvia-odwyer/photon-node\"),\n catch: () => new ResizerUnavailableError(),\n }),\n )\n return Effect.fn(\"Image.Photon.normalize\")(function* (\n resource: string,\n content: FileSystem.Content & { readonly encoding: \"base64\" },\n limits: {\n readonly autoResize: boolean\n readonly maxWidth: number\n readonly maxHeight: number\n readonly maxBase64Bytes: number\n },\n ) {\n const photon = yield* loadPhoton\n const decoded = yield* Effect.try({\n try: () => photon.PhotonImage.new_from_byteslice(Buffer.from(content.content, \"base64\")),\n catch: () => new DecodeError({ resource }),\n })\n try {\n const width = decoded.get_width()\n const height = decoded.get_height()\n const bytes = Buffer.byteLength(content.content, \"utf-8\")\n if (width <= limits.maxWidth && height <= limits.maxHeight && bytes <= limits.maxBase64Bytes) return content\n if (!limits.autoResize)\n return yield* new SizeError({\n resource,\n width,\n height,\n bytes,\n maxWidth: limits.maxWidth,\n maxHeight: limits.maxHeight,\n maxBytes: limits.maxBase64Bytes,\n })\n const scale = Math.min(1, limits.maxWidth / width, limits.maxHeight / height)\n const sizes = Array.from({ length: 32 }).reduce<Array<{ width: number; height: number }>>((acc) => {\n const previous = acc.at(-1) ?? {\n width: Math.max(1, Math.round(width * scale)),\n height: Math.max(1, Math.round(height * scale)),\n }\n const next =\n acc.length === 0\n ? previous\n : {\n width: previous.width === 1 ? 1 : Math.max(1, Math.floor(previous.width * 0.75)),\n height: previous.height === 1 ? 1 : Math.max(1, Math.floor(previous.height * 0.75)),\n }\n return acc.some((item) => item.width === next.width && item.height === next.height) ? acc : [...acc, next]\n }, [])\n for (const size of sizes) {\n const resized = photon.resize(decoded, size.width, size.height, photon.SamplingFilter.Lanczos3)\n try {\n const encoders: Array<readonly [mime: string, encode: () => Uint8Array]> = [\n [\"image/png\", () => resized.get_bytes()],\n ...JPEG_QUALITIES.map((quality) => [\"image/jpeg\", () => resized.get_bytes_jpeg(quality)] as const),\n ]\n for (const [mime, encode] of encoders) {\n const candidate = Buffer.from(encode()).toString(\"base64\")\n if (Buffer.byteLength(candidate, \"utf-8\") <= limits.maxBase64Bytes)\n return { ...content, content: candidate, encoding: \"base64\" as const, mime }\n }\n } finally {\n resized.free()\n }\n }\n return yield* new SizeError({\n resource,\n width,\n height,\n bytes,\n maxWidth: limits.maxWidth,\n maxHeight: limits.maxHeight,\n maxBytes: limits.maxBase64Bytes,\n })\n } finally {\n decoded.free()\n }\n })\n})\n" | ||
| ], | ||
| "mappings": ";2xBAGA,yBACA,6BAAS,iBAIT,SAAM,OAAiB,MAAC,QAAI,QAAI,QAAI,QAAI,OAAE,OAE7B,OAAO,OAAO,SAAI,cAAU,OAAG,MACxC,gBAA4E,iCAC5E,gBAAK,WAAW,CAAU,EAAI,EAAa,EAAc,IAAI,IAAI,EAAY,YAAY,GAAG,CAAC,EAC/F,IAAM,EAAa,MAAO,EAAO,OAC/B,EAAO,WAAW,CAChB,IAAK,IAAa,yCAClB,MAAO,IAAM,IAAI,CACnB,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,CAAC,GAAG,EAAK,CAAI,GACxG,CAAC,CAAC,EACL,QAAW,KAAQ,EAAO,CACxB,IAAM,EAAU,EAAO,OAAO,EAAS,EAAK,MAAO,EAAK,OAAQ,EAAO,eAAe,QAAQ,EAC9F,GAAI,CACF,IAAM,EAAqE,CACzE,CAAC,YAAa,IAAM,EAAQ,UAAU,CAAC,EACvC,GAAG,EAAe,IAAI,CAAC,IAAY,CAAC,aAAc,IAAM,EAAQ,eAAe,CAAO,CAAC,CAAU,CACnG,EACA,QAAY,EAAM,KAAW,EAAU,CACrC,IAAM,EAAY,OAAO,KAAK,EAAO,CAAC,EAAE,SAAS,QAAQ,EACzD,GAAI,OAAO,WAAW,EAAW,OAAO,GAAK,EAAO,eAClD,MAAO,IAAK,EAAS,QAAS,EAAW,SAAU,SAAmB,MAAK,UAE/E,CACA,EAAQ,KAAK,GAGjB,OAAO,MAAO,IAAI,EAAU,CAC1B,WACA,QACA,SACA,QACA,SAAU,EAAO,SACjB,UAAW,EAAO,UAClB,SAAU,EAAO,cACnB,CAAC,SACD,CACA,EAAQ,KAAK,GAEhB,EACF", | ||
| "debugId": "DFA4D47152A93E2864756E2164756E21", | ||
| "names": [] | ||
| } |
| { | ||
| "version": 3, | ||
| "sources": ["src/commands/handlers/service/set.ts"], | ||
| "sourcesContent": [ | ||
| "import { Effect } from \"effect\"\nimport { Commands } from \"../../commands\"\nimport { Runtime } from \"../../../framework/runtime\"\nimport { ServiceConfig } from \"../../../services/service-config\"\n\nexport default Runtime.handler(\n Commands.commands.service.commands.set,\n Effect.fn(\"cli.service.set\")(function* (input) {\n yield* ServiceConfig.set(input.key, input.value)\n }),\n)\n" | ||
| ], | ||
| "mappings": ";o2BAKA,SAAe,SAAQ,aACrB,OAAS,cAAS,aAAQ,cAAS,SACnC,OAAO,QAAG,sBAAiB,OAAE,cAAU,MAAC,OAAO,MAC7C,WAAO,OAAc,SAAI,OAAM,SAAK,OAAM,UAAK,EAChD,CACH", | ||
| "debugId": "BA54982ADFF1E12A64756E2164756E21", | ||
| "names": [] | ||
| } |
| { | ||
| "version": 3, | ||
| "sources": ["src/commands/handlers/service/get.ts"], | ||
| "sourcesContent": [ | ||
| "import { EOL } from \"os\"\nimport { Effect, Option } from \"effect\"\nimport { Commands } from \"../../commands\"\nimport { Runtime } from \"../../../framework/runtime\"\nimport { ServiceConfig } from \"../../../services/service-config\"\n\nexport default Runtime.handler(\n Commands.commands.service.commands.get,\n Effect.fn(\"cli.service.get\")(function* (input) {\n process.stdout.write((yield* ServiceConfig.get(Option.getOrUndefined(input.key))) + EOL)\n }),\n)\n" | ||
| ], | ||
| "mappings": ";42BAAA,mBAAS,gBAMT,SAAe,SAAQ,aACrB,OAAS,cAAS,aAAQ,cAAS,SACnC,OAAO,QAAG,sBAAiB,OAAE,cAAU,MAAC,OAAO,MAC7C,aAAQ,YAAO,YAAO,WAAO,OAAc,IAAI,EAAO,eAAe,EAAM,GAAG,CAAC,GAAK,CAAG,EACxF,CACH", | ||
| "debugId": "349DC9475FF6B6FD64756E2164756E21", | ||
| "names": [] | ||
| } |
| { | ||
| "version": 3, | ||
| "sources": ["../core/src/installation/version.ts"], | ||
| "sourcesContent": [ | ||
| "declare global {\n const OPENCODE_VERSION: string\n const OPENCODE_CHANNEL: string\n}\n\nexport const InstallationVersion = typeof OPENCODE_VERSION === \"string\" ? OPENCODE_VERSION : \"local\"\nexport const InstallationChannel = typeof OPENCODE_CHANNEL === \"string\" ? OPENCODE_CHANNEL : \"local\"\nexport const InstallationLocal = InstallationChannel === \"local\"\n" | ||
| ], | ||
| "mappings": ";AAKO,IAAM,EAA6D,mBAC7D,EAA6D,OAC7D,EAAoB", | ||
| "debugId": "C586BA1FA699790964756E2164756E21", | ||
| "names": [] | ||
| } |
Sorry, the diff of this file is too big to display
| { | ||
| "version": 3, | ||
| "sources": ["src/commands/handlers/mini.ts"], | ||
| "sourcesContent": [ | ||
| "import { Effect, Option } from \"effect\"\nimport { Commands } from \"../commands\"\nimport { Runtime } from \"../../framework/runtime\"\nimport { ServerConnection } from \"../../services/server-connection\"\n\nexport default Runtime.handler(Commands.commands.mini, (input) =>\n Effect.gen(function* () {\n const { runMini, validateMiniTerminal } = yield* Effect.promise(() => import(\"../../mini\"))\n yield* Effect.promise(async () => validateMiniTerminal())\n const serverURL = Option.getOrUndefined(input.server)\n const server = yield* ServerConnection.resolve({ server: serverURL, standalone: input.standalone })\n yield* Effect.promise(() =>\n runMini({\n server,\n continue: input.continue,\n session: Option.getOrUndefined(input.session),\n fork: input.fork,\n model: Option.getOrUndefined(input.model),\n agent: Option.getOrUndefined(input.agent),\n prompt: Option.getOrUndefined(input.prompt),\n replay: input.replay,\n replayLimit: Option.getOrUndefined(input.replayLimit),\n demo: input.demo,\n }),\n )\n }),\n)\n" | ||
| ], | ||
| "mappings": ";ixCAKA,SAAe,SAAQ,aAAQ,OAAS,cAAS,UAAM,MAAC,SACtD,OAAO,SAAI,cAAU,OAAG,MACtB,SAAQ,eAAS,6BAAyB,WAAO,OAAO,aAAQ,SAAa,wCAAa,OAC1F,WAAO,OAAO,aAAQ,cAAY,OAAqB,MAAC,OACxD,SAAM,OAAY,OAAO,oBAAe,OAAM,WAAM,OAC9C,EAAS,MAAO,EAAiB,QAAQ,CAAE,OAAQ,EAAW,WAAY,EAAM,UAAW,CAAC,EAClG,MAAO,EAAO,QAAQ,IACpB,EAAQ,CACN,SACA,SAAU,EAAM,SAChB,QAAS,EAAO,eAAe,EAAM,OAAO,EAC5C,KAAM,EAAM,KACZ,MAAO,EAAO,eAAe,EAAM,KAAK,EACxC,MAAO,EAAO,eAAe,EAAM,KAAK,EACxC,OAAQ,EAAO,eAAe,EAAM,MAAM,EAC1C,OAAQ,EAAM,OACd,YAAa,EAAO,eAAe,EAAM,WAAW,EACpD,KAAM,EAAM,IACd,CAAC,CACH,EACD,CACH", | ||
| "debugId": "54E665514D5D727464756E2164756E21", | ||
| "names": [] | ||
| } |
| { | ||
| "version": 3, | ||
| "sources": ["src/mini/mini.ts", "src/mini/run.ts", "src/mini/noninteractive.ts", "src/mini/ui.ts"], | ||
| "sourcesContent": [ | ||
| "import { Service } from \"@opencode-ai/client/effect/service\"\nimport { OpenCode, type OpenCodeClient } from \"@opencode-ai/client/promise\"\nimport { ServerConnection } from \"../services/server-connection\"\nimport { waitForCatalogReady } from \"./catalog.shared\"\nimport { INTERACTIVE_INPUT_ERROR, resolveInteractiveStdin } from \"./runtime.stdin\"\nimport type { RunInput, RunTuiConfig } from \"./types\"\n\nexport type MiniCommandInput = {\n server: ServerConnection.Resolved\n continue?: boolean\n session?: string\n fork?: boolean\n model?: string\n agent?: string\n prompt?: string\n replay?: boolean\n replayLimit?: number\n demo?: boolean\n tuiConfig?: RunTuiConfig | Promise<RunTuiConfig>\n}\n\ntype Session = Awaited<ReturnType<OpenCodeClient[\"session\"][\"get\"]>>\nexport async function runMini(input: MiniCommandInput) {\n validate(input)\n const initialInput = mergeInput(process.stdin.isTTY ? undefined : await Bun.stdin.text(), input.prompt)\n const runtimeTask = import(\"./runtime\")\n const directory = localDirectory()\n\n try {\n const sdk = OpenCode.make({\n baseUrl: input.server.endpoint.url,\n headers: Service.headers(input.server.endpoint),\n })\n const model = parseModel(input.model)\n let agentTask: Promise<string | undefined> | undefined\n const resolveAgent = () => {\n agentTask ??= validateAgent(sdk, directory, input.agent)\n return agentTask\n }\n const resolveSession = async () => {\n const [agent, selected] = await Promise.all([resolveAgent(), selectSession(sdk, directory, input)])\n const readyModel =\n model ?? (selected?.model ? { providerID: selected.model.providerID, modelID: selected.model.id } : undefined)\n if (readyModel) await waitForCatalogReady({ sdk, directory, model: readyModel })\n const session = selected ?? (await createSession(sdk, directory, agent, model))\n return { id: session.id, title: session.title, resume: selected !== undefined }\n }\n const create = (\n _sdk: OpenCodeClient,\n next: { agent: string | undefined; model: RunInput[\"model\"]; variant: string | undefined },\n ) => createSession(sdk, directory, next.agent, next.model, next.variant)\n const runtime = await runtimeTask\n await runtime.runInteractiveDeferredMode({\n sdk,\n directory,\n resolveAgent,\n session: resolveSession,\n createSession: create,\n agent: input.agent,\n model,\n variant: undefined,\n files: [],\n initialInput,\n thinking: true,\n replay: input.replay ?? true,\n replayLimit: input.replayLimit,\n demo: input.demo,\n tuiConfig: input.tuiConfig,\n })\n } catch (error) {\n if (error instanceof Error && error.message === INTERACTIVE_INPUT_ERROR) fail(error.message)\n throw error\n }\n}\n\nexport function validateMiniTerminal() {\n if (!process.stdout.isTTY) fail(\"opencode mini requires a TTY stdout\")\n}\n\n/** @internal Exported for testing. */\nexport function mergeInput(piped: string | undefined, prompt: string | undefined) {\n if (!prompt) return piped || undefined\n if (!piped) return prompt\n return piped + \"\\n\" + prompt\n}\n\nfunction validate(input: MiniCommandInput) {\n validateMiniTerminal()\n if (input.replayLimit !== undefined && (!Number.isInteger(input.replayLimit) || input.replayLimit <= 0)) {\n fail(\"--replay-limit must be a positive integer\")\n }\n if (input.fork && !input.continue && !input.session) fail(\"--fork requires --continue or --session\")\n resolveInteractiveStdin().cleanup?.()\n}\n\nfunction localDirectory(): string {\n const root = process.env.PWD ?? process.cwd()\n try {\n process.chdir(root)\n return process.cwd()\n } catch {\n fail(`Failed to change directory to ${root}`)\n }\n}\n\nfunction parseModel(value?: string): RunInput[\"model\"] {\n if (!value) return\n const [providerID, ...rest] = value.split(\"/\")\n const modelID = rest.join(\"/\")\n if (!providerID || !modelID) fail(\"--model must use the format provider/model\")\n return { providerID, modelID }\n}\n\nasync function validateAgent(sdk: OpenCodeClient, directory: string, name?: string) {\n if (!name) return\n const deadline = Date.now() + 5_000\n let agents: Awaited<ReturnType<OpenCodeClient[\"agent\"][\"list\"]>> | undefined\n while (Date.now() < deadline) {\n agents = await sdk.agent.list({ location: { directory } }).catch(() => undefined)\n const agent = agents?.data.find((item) => item.id === name)\n if (agent?.mode === \"subagent\") {\n warning(`agent \"${name}\" is a subagent, not a primary agent. Falling back to default agent`)\n return\n }\n if (agent) return name\n await Bun.sleep(25)\n }\n if (!agents) {\n warning(\"failed to list agents. Falling back to default agent\")\n return\n }\n warning(`agent \"${name}\" not found. Falling back to default agent`)\n}\n\nasync function selectSession(sdk: OpenCodeClient, directory: string, input: MiniCommandInput, preselected?: Session) {\n const selected =\n preselected ??\n (input.session\n ? await sdk.session.get({ sessionID: input.session }).catch(() => undefined)\n : input.continue\n ? await sdk.session\n .list({ directory, parentID: null, limit: 1, order: \"desc\" })\n .then((result) => result.data[0])\n : undefined)\n if (input.session && !selected) fail(\"Session not found\")\n if (!selected) return\n if (!input.fork) return selected\n return sdk.session.fork({ sessionID: selected.id })\n}\n\nasync function createSession(\n sdk: OpenCodeClient,\n directory: string,\n agent: string | undefined,\n model: RunInput[\"model\"],\n variant?: string,\n): Promise<Session> {\n if (model) await waitForCatalogReady({ sdk, directory, model })\n return sdk.session.create({\n agent,\n model: model ? { providerID: model.providerID, id: model.modelID, variant } : undefined,\n location: { directory },\n })\n}\n\nfunction warning(message: string) {\n process.stderr.write(`\\x1b[93m\\x1b[1m!\\x1b[0m ${message}\\n`)\n}\n\nfunction fail(message: string): never {\n process.stderr.write(`\\x1b[91m\\x1b[1mError: \\x1b[0m${message}\\n`)\n process.exit(1)\n}\n", | ||
| "import { Service, type Endpoint } from \"@opencode-ai/client/effect/service\"\nimport { OpenCode, type OpenCodeClient } from \"@opencode-ai/client/promise\"\nimport { FSUtil } from \"@opencode-ai/core/fs-util\"\nimport { Model } from \"@opencode-ai/schema/model\"\nimport { open } from \"node:fs/promises\"\nimport path from \"node:path\"\nimport { ServerConnection } from \"../services/server-connection\"\nimport { loadRunAgents, waitForCatalogReady } from \"./catalog.shared\"\nimport { runNonInteractivePrompt } from \"./noninteractive\"\nimport { toolInlineInfo } from \"./tool\"\nimport type { MiniToolPart } from \"./types\"\nimport { UI } from \"./ui\"\n\nexport type RunCommandInput = {\n server: ServerConnection.Resolved\n message: string[]\n continue?: boolean\n session?: string\n fork?: boolean\n model?: string\n agent?: string\n format: \"default\" | \"json\"\n file: string[]\n title?: string\n thinking?: boolean\n auto?: boolean\n}\n\ntype FilePart = {\n url: string\n filename: string\n mime: string\n}\n\ntype Prepared = {\n directory?: string\n message: string\n files: FilePart[]\n}\n\nconst ATTACH_FILE_MAX_BYTES = 10 * 1024 * 1024\n\nexport function runNonInteractive(input: RunCommandInput) {\n return run(input).catch((error) => reportError(input, error instanceof Error ? error.message : String(error)))\n}\n\nasync function run(input: RunCommandInput) {\n if (input.fork && !input.continue && !input.session) fail(\"--fork requires --continue or --session\")\n const root = process.env.PWD ?? process.cwd()\n const directory = localDirectory(root)\n const message = mergeInput(formatMessage(input.message), process.stdin.isTTY ? undefined : await Bun.stdin.text())\n if (!message?.trim()) fail(\"You must provide a message\")\n const files = await Promise.all(input.file.map((file) => prepareFile(file, root)))\n const prepared = { directory, message, files }\n return execute(input, prepared, input.server.endpoint)\n}\n\nasync function execute(input: RunCommandInput, prepared: Prepared, endpoint: Endpoint) {\n const client = OpenCode.make({ baseUrl: endpoint.url, headers: Service.headers(endpoint) })\n const requestedDirectory = prepared.directory ?? (await client.location.get()).directory\n if (!requestedDirectory) fail(\"Failed to resolve server directory\")\n const session = await selectSession(client, requestedDirectory, input)\n const cwd = session?.location.directory ?? requestedDirectory\n const workspace = session?.location.workspaceID\n const explicit = parseRunModel(input.model)\n const explicitModel = explicit?.model\n const variant = explicit?.variant\n const sessionModel = session?.model ? { providerID: session.model.providerID, modelID: session.model.id } : undefined\n const defaultModel =\n !explicitModel && !sessionModel\n ? await client.model\n .default({ location: { directory: cwd, workspace } })\n .then((result) => (result.data ? { providerID: result.data.providerID, modelID: result.data.id } : undefined))\n : undefined\n const model = pickRunModel(explicitModel, variant, sessionModel, defaultModel)\n if (variant && !model) return reportError(input, \"Cannot select a variant before selecting a model\", session?.id)\n if (model) {\n await waitForCatalogReady({ sdk: client, directory: cwd, workspace, model })\n const available = await client.model.list({ location: { directory: cwd, workspace } })\n if (!available.data.some((item) => item.providerID === model.providerID && item.id === model.modelID))\n return reportError(input, `Model unavailable: ${model.providerID}/${model.modelID}`, session?.id)\n }\n const agent = await validateAgent(client, cwd, input.agent)\n const selected =\n session ??\n (await client.session.create({\n agent,\n model: model ? { providerID: model.providerID, id: model.modelID, variant } : undefined,\n location: { directory: cwd },\n }))\n if (!session && input.title !== undefined) {\n await client.session.rename({\n sessionID: selected.id,\n title: input.title || prepared.message.slice(0, 50) + (prepared.message.length > 50 ? \"...\" : \"\"),\n })\n }\n\n await runNonInteractivePrompt({\n client,\n sessionID: selected.id,\n message: prepared.message,\n files: prepared.files,\n agent,\n model,\n variant,\n thinking: input.thinking ?? false,\n format: input.format,\n auto: input.auto ?? false,\n attached: true,\n renderTool,\n renderToolError,\n }).catch((error) => reportError(input, error instanceof Error ? error.message : String(error), selected.id))\n}\n\nexport function mergeInput(message: string | undefined, piped: string | undefined) {\n if (!message) return piped || undefined\n if (!piped) return message\n return message + \"\\n\" + piped\n}\n\nexport function pickRunModel(\n explicit: { providerID: string; modelID: string } | undefined,\n variant: string | undefined,\n session: { providerID: string; modelID: string } | undefined,\n fallback: { providerID: string; modelID: string } | undefined,\n) {\n if (explicit) return explicit\n if (!variant) return\n return session ?? fallback\n}\n\nfunction formatMessage(message: string[]) {\n const value = message.map((part) => (part.includes(\" \") ? `\"${part.replace(/\"/g, '\\\\\"')}\"` : part)).join(\" \")\n return value || undefined\n}\n\nfunction localDirectory(root: string) {\n try {\n process.chdir(root)\n return process.cwd()\n } catch {\n fail(`Failed to change directory to ${root}`)\n }\n}\n\nexport function parseRunModel(value?: string) {\n if (!value) return\n const ref = Model.Ref.parse(value)\n return {\n model: { providerID: ref.providerID, modelID: ref.id },\n variant: ref.variant,\n }\n}\n\nasync function validateAgent(client: OpenCodeClient, directory: string, name?: string) {\n if (!name) return\n const agents = await loadRunAgents(client, directory).catch(() => undefined)\n if (!agents) {\n warning(\"failed to list agents. Falling back to default agent\")\n return\n }\n const agent = agents.find((item) => item.id === name)\n if (!agent) {\n warning(`agent \"${name}\" not found. Falling back to default agent`)\n return\n }\n if (agent.mode === \"subagent\") {\n warning(`agent \"${name}\" is a subagent, not a primary agent. Falling back to default agent`)\n return\n }\n return name\n}\n\nasync function selectSession(client: OpenCodeClient, directory: string, input: RunCommandInput) {\n const selected = input.session\n ? await client.session.get({ sessionID: input.session }).catch(() => undefined)\n : input.continue\n ? await client.session\n .list({ directory, parentID: null, limit: 1, order: \"desc\" })\n .then((result) => result.data[0])\n : undefined\n if (input.session && !selected) fail(\"Session not found\")\n if (!selected || !input.fork) return selected\n return client.session.fork({ sessionID: selected.id })\n}\n\nasync function prepareFile(input: string, directory: string): Promise<FilePart> {\n const file = path.resolve(directory, input)\n const handle = await open(file, \"r\").catch(() => fail(`File not found: ${input}`))\n try {\n const stat = await handle.stat()\n if (!stat.isFile() || stat.size > ATTACH_FILE_MAX_BYTES)\n fail(`Cannot attach a directory, special file, or file larger than 10 MiB: ${input}`)\n const content = Buffer.alloc(Number(stat.size))\n let offset = 0\n while (offset < content.length) {\n const read = await handle.read(content, offset, content.length - offset, offset)\n if (read.bytesRead === 0) break\n offset += read.bytesRead\n }\n const bytes = content.subarray(0, offset)\n const detected = FSUtil.mimeType(file)\n const text = bytes.toString(\"utf8\")\n const mime =\n detected.startsWith(\"image/\") || detected === \"application/pdf\"\n ? detected\n : !isBinaryContent(bytes) && Buffer.from(text, \"utf8\").equals(bytes)\n ? \"text/plain\"\n : detected\n return {\n url: `data:${mime};base64,${bytes.toString(\"base64\")}`,\n filename: path.basename(file),\n mime,\n }\n } finally {\n await handle.close()\n }\n}\n\nfunction isBinaryContent(bytes: Uint8Array) {\n if (bytes.length === 0) return false\n if (bytes.includes(0)) return true\n return bytes.reduce((count, byte) => count + Number(byte < 9 || (byte > 13 && byte < 32)), 0) / bytes.length > 0.3\n}\n\nasync function renderTool(part: MiniToolPart) {\n const info = toolInlineInfo(part)\n if (info.mode === \"block\") {\n UI.empty()\n UI.println(UI.Style.TEXT_NORMAL + info.icon, UI.Style.TEXT_NORMAL + info.title)\n if (info.body?.trim()) UI.println(info.body)\n UI.empty()\n return\n }\n UI.println(\n UI.Style.TEXT_NORMAL + info.icon,\n UI.Style.TEXT_NORMAL + info.title,\n info.description ? UI.Style.TEXT_DIM + info.description + UI.Style.TEXT_NORMAL : \"\",\n )\n}\n\nasync function renderToolError(part: MiniToolPart) {\n const info = toolInlineInfo(part)\n UI.println(UI.Style.TEXT_NORMAL + \"✗\", UI.Style.TEXT_NORMAL + `${info.title} failed`)\n}\n\nfunction warning(message: string) {\n UI.println(UI.Style.TEXT_WARNING_BOLD + \"!\", UI.Style.TEXT_NORMAL, message)\n}\n\nfunction reportError(input: RunCommandInput, message: string, sessionID?: string) {\n process.exitCode = 1\n if (input.format === \"json\") {\n process.stdout.write(\n JSON.stringify({\n type: \"error\",\n timestamp: Date.now(),\n sessionID: sessionID ?? \"\",\n error: { type: \"unknown\", message },\n }) + \"\\n\",\n )\n return\n }\n UI.error(message)\n}\n\nfunction fail(message: string): never {\n throw new Error(message)\n}\n", | ||
| "import type { EventSubscribeOutput, OpenCodeClient } from \"@opencode-ai/client/promise\"\nimport { SessionMessage } from \"@opencode-ai/schema/session-message\"\nimport { EOL } from \"node:os\"\nimport { UI } from \"./ui\"\nimport type { MiniToolPart } from \"./types\"\n\ntype Model = {\n providerID: string\n modelID: string\n}\n\ntype File = {\n url: string\n filename: string\n mime: string\n}\n\ntype Input = {\n client: OpenCodeClient\n sessionID: string\n message: string\n files: File[]\n agent?: string\n model?: Model\n variant?: string\n thinking: boolean\n format: \"default\" | \"json\"\n auto: boolean\n /** True when the client is attached to a shared server rather than an exclusive in-process one. */\n attached: boolean\n renderTool: (part: MiniToolPart) => Promise<void>\n renderToolError: (part: MiniToolPart) => Promise<void>\n}\n\ntype StartedPart = {\n id: string\n timestamp: number\n}\n\ntype ToolState = StartedPart & {\n assistantMessageID: string\n tool: string\n input: Record<string, unknown>\n raw?: string\n provider?: unknown\n}\n\ntype V2Event = EventSubscribeOutput\ntype FormRequest = Extract<V2Event, { type: \"form.created\" }>[\"data\"][\"form\"]\n\n// MCP elicitations are temporarily owned by the \"global\" sentinel instead of a real\n// session. An exclusive local process may treat them as this run's blockers; an\n// attached client must not cancel input that may belong to another session.\nconst GLOBAL_FORM_SESSION_ID = \"global\"\n\nexport async function runNonInteractivePrompt(input: Input) {\n const controller = new AbortController()\n const stream = input.client.event.subscribe({ signal: controller.signal })[Symbol.asyncIterator]()\n const connected = await stream.next()\n if (connected.done) throw new Error(\"Event stream disconnected before prompt admission\")\n\n const messageID = SessionMessage.ID.create()\n const starts = new Map<string, StartedPart>()\n const tools = new Map<string, ToolState>()\n let submitted = false\n let promoted = false\n let emittedError = false\n let questionRejected = false\n let permissionRejected = false\n let formCancelled = false\n let interrupted = false\n let admission: AbortController | undefined\n\n const emit = (type: string, timestamp: number, data: Record<string, unknown>) => {\n if (input.format !== \"json\") return false\n process.stdout.write(JSON.stringify({ type, timestamp, sessionID: input.sessionID, ...data }) + EOL)\n return true\n }\n\n const writeText = (part: { text: string; [key: string]: unknown }, timestamp: number) => {\n if (emit(\"text\", timestamp, { part })) return\n const text = part.text.trim()\n if (!text) return\n if (!process.stdout.isTTY) {\n process.stdout.write(text + EOL)\n return\n }\n UI.empty()\n UI.println(text)\n UI.empty()\n }\n\n const replyPermission = async (request: { id: string; action: string; resources: ReadonlyArray<string> }) => {\n if (!input.auto) {\n permissionRejected = true\n UI.println(\n UI.Style.TEXT_WARNING_BOLD + \"!\",\n UI.Style.TEXT_NORMAL +\n `permission requested: ${request.action} (${request.resources.join(\", \")}); auto-rejecting`,\n )\n }\n await input.client.permission\n .reply({\n sessionID: input.sessionID,\n requestID: request.id,\n reply: input.auto ? \"once\" : \"reject\",\n })\n .catch(() => {})\n if (!input.auto) {\n await input.client.session.interrupt({ sessionID: input.sessionID }).catch(() => {})\n }\n }\n\n const rejectQuestion = async (request: { id: string }) => {\n questionRejected = true\n await input.client.question.reject({ sessionID: input.sessionID, requestID: request.id }).catch(() => {})\n }\n\n const cancelForm = async (request: Pick<FormRequest, \"id\" | \"sessionID\">) => {\n formCancelled = true\n await input.client.form.cancel({ sessionID: request.sessionID, formID: request.id }).catch(() => {})\n }\n\n const consume = async () => {\n while (!controller.signal.aborted) {\n const next = await stream.next().catch((error) => {\n if (!emittedError) throw error\n return { done: true as const, value: undefined }\n })\n if (next.done) {\n if (emittedError) return\n throw new Error(\"Event stream disconnected during prompt execution\")\n }\n const event = next.value\n\n if (event.type === \"permission.v2.asked\" && submitted && event.data.sessionID === input.sessionID) {\n await replyPermission(event.data)\n continue\n }\n if (event.type === \"question.v2.asked\" && submitted && event.data.sessionID === input.sessionID) {\n await rejectQuestion(event.data)\n continue\n }\n if (\n event.type === \"form.created\" &&\n submitted &&\n (event.data.form.sessionID === input.sessionID ||\n (!input.attached && event.data.form.sessionID === GLOBAL_FORM_SESSION_ID))\n ) {\n await cancelForm(event.data.form)\n continue\n }\n if (!(\"sessionID\" in event.data) || event.data.sessionID !== input.sessionID) continue\n const time = toMillis(\"created\" in event ? event.created : undefined)\n\n if (event.type === \"session.input.promoted\") {\n if (event.data.inputID === messageID) {\n promoted = true\n continue\n }\n }\n if (\n event.type === \"session.execution.interrupted\" &&\n event.data.reason === \"user\" &&\n (interrupted || permissionRejected || questionRejected || formCancelled)\n ) {\n return\n }\n if (!promoted) continue\n\n if (event.type === \"session.step.started\") {\n const part = {\n id: partID(event.id),\n sessionID: input.sessionID,\n messageID: event.data.assistantMessageID,\n type: \"step-start\",\n snapshot: event.data.snapshot,\n }\n if (!emit(\"step_start\", time, { part }) && input.format !== \"json\") {\n UI.empty()\n UI.println(`> ${event.data.agent} · ${event.data.model.id}`)\n UI.empty()\n }\n continue\n }\n\n if (event.type === \"session.text.started\") {\n starts.set(\"text\", { id: partID(event.id), timestamp: time })\n continue\n }\n if (event.type === \"session.text.ended\") {\n const started = starts.get(\"text\")\n starts.delete(\"text\")\n const part = {\n id: started?.id ?? partID(event.id),\n sessionID: input.sessionID,\n messageID: event.data.assistantMessageID,\n type: \"text\",\n text: event.data.text,\n time: { start: started?.timestamp ?? time, end: time },\n }\n writeText(part, time)\n continue\n }\n\n if (event.type === \"session.reasoning.started\") {\n starts.set(\"reasoning\", { id: partID(event.id), timestamp: time })\n continue\n }\n if (event.type === \"session.reasoning.ended\" && input.thinking) {\n const started = starts.get(\"reasoning\")\n starts.delete(\"reasoning\")\n const part = {\n id: started?.id ?? partID(event.id),\n sessionID: input.sessionID,\n messageID: event.data.assistantMessageID,\n type: \"reasoning\",\n text: event.data.text,\n metadata: event.data.state,\n time: { start: started?.timestamp ?? time, end: time },\n }\n if (emit(\"reasoning\", time, { part })) continue\n const text = part.text.trim()\n if (!text) continue\n const line = `Thinking: ${text}`\n if (!process.stdout.isTTY) {\n process.stdout.write(line + EOL)\n continue\n }\n UI.empty()\n UI.println(`${UI.Style.TEXT_DIM}\\u001b[3m${line}\\u001b[0m${UI.Style.TEXT_NORMAL}`)\n UI.empty()\n continue\n }\n\n if (event.type === \"session.tool.input.started\") {\n tools.set(event.data.callID, {\n id: partID(event.id),\n timestamp: time,\n assistantMessageID: event.data.assistantMessageID,\n tool: event.data.name,\n input: {},\n })\n continue\n }\n if (event.type === \"session.tool.input.ended\") {\n const current = tools.get(event.data.callID)\n if (current) current.raw = event.data.text\n continue\n }\n if (event.type === \"session.tool.called\") {\n const current = tools.get(event.data.callID)\n tools.set(event.data.callID, {\n id: current?.id ?? partID(event.id),\n timestamp: current?.timestamp ?? time,\n assistantMessageID: event.data.assistantMessageID,\n tool: current?.tool ?? \"tool\",\n input: event.data.input,\n raw: current?.raw,\n provider: { executed: event.data.executed, state: event.data.state },\n })\n continue\n }\n if (event.type === \"session.tool.success\") {\n const current = tools.get(event.data.callID) ?? fallbackTool(event)\n const part: MiniToolPart = {\n id: current.id,\n sessionID: input.sessionID,\n messageID: event.data.assistantMessageID,\n type: \"tool\",\n callID: event.data.callID,\n tool: current.tool,\n state: {\n status: \"completed\",\n input: current.input,\n output: event.data.content\n .filter((item) => item.type === \"text\")\n .map((item) => item.text)\n .join(\"\\n\"),\n title: current.tool,\n metadata: {\n structured: event.data.structured,\n content: event.data.content,\n result: event.data.result,\n providerCall: current.provider,\n providerResult: { executed: event.data.executed, state: event.data.resultState },\n rawInput: current.raw,\n },\n time: { start: current.timestamp, end: time },\n },\n }\n tools.delete(event.data.callID)\n if (!emit(\"tool_use\", time, { part })) await input.renderTool(part)\n continue\n }\n if (event.type === \"session.tool.failed\") {\n const current = tools.get(event.data.callID) ?? fallbackTool(event)\n const error = event.data.error.message\n const part: MiniToolPart = {\n id: current.id,\n sessionID: input.sessionID,\n messageID: event.data.assistantMessageID,\n type: \"tool\",\n callID: event.data.callID,\n tool: current.tool,\n state: {\n status: \"error\",\n input: current.input,\n error,\n metadata: {\n result: event.data.result,\n providerCall: current.provider,\n providerResult: { executed: event.data.executed, state: event.data.resultState },\n rawInput: current.raw,\n },\n time: { start: current.timestamp, end: time },\n },\n }\n tools.delete(event.data.callID)\n if (!emit(\"tool_use\", time, { part })) {\n await input.renderToolError(part)\n UI.error(error)\n }\n continue\n }\n\n if (event.type === \"session.step.ended\") {\n const part = {\n id: partID(event.id),\n sessionID: input.sessionID,\n messageID: event.data.assistantMessageID,\n type: \"step-finish\",\n reason: event.data.finish,\n snapshot: event.data.snapshot,\n cost: event.data.cost,\n tokens: event.data.tokens,\n }\n emit(\"step_finish\", time, { part })\n continue\n }\n if (event.type === \"session.step.failed\") {\n if (interrupted || permissionRejected || questionRejected || formCancelled) continue\n emittedError = true\n process.exitCode = 1\n if (!emit(\"error\", time, { error: event.data.error })) UI.error(event.data.error.message)\n continue\n }\n if (event.type === \"session.execution.failed\") {\n if (!emittedError && !questionRejected && !formCancelled) {\n emittedError = true\n process.exitCode = 1\n if (!emit(\"error\", time, { error: event.data.error })) UI.error(event.data.error.message)\n }\n return\n }\n if (event.type === \"session.execution.interrupted\") {\n if (event.data.reason === \"user\" && interrupted) process.exitCode = 130\n if (event.data.reason !== \"user\" && !emittedError) {\n emittedError = true\n process.exitCode = 1\n const error = { type: \"aborted\" as const, message: `Session interrupted: ${event.data.reason}` }\n if (!emit(\"error\", time, { error })) UI.error(error.message)\n }\n return\n }\n if (event.type === \"session.execution.succeeded\") return\n }\n }\n\n const interrupt = () => {\n if (interrupted) process.exit(130)\n interrupted = true\n process.exitCode = 130\n admission?.abort()\n void input.client.session.interrupt({ sessionID: input.sessionID }).catch(() => {})\n }\n process.on(\"SIGINT\", interrupt)\n\n let completed: Promise<void> | undefined\n try {\n if (input.agent) {\n await input.client.session.switchAgent({ sessionID: input.sessionID, agent: input.agent })\n }\n const selected = input.model\n ? { providerID: input.model.providerID, id: input.model.modelID, variant: input.variant }\n : input.variant\n ? await input.client.session\n .get({ sessionID: input.sessionID })\n .then((result) => result.model)\n .then(async (model) => {\n if (model) return { ...model, variant: input.variant }\n const result = await input.client.model.default()\n const fallback = result.data\n return fallback ? { providerID: fallback.providerID, id: fallback.id, variant: input.variant } : undefined\n })\n : undefined\n if (input.variant && !selected) throw new Error(\"Cannot select a variant before selecting a model\")\n if (selected) {\n await input.client.session.switchModel({ sessionID: input.sessionID, model: selected })\n }\n\n const prepared = await Promise.all(input.files.map(prepareFile))\n if (interrupted) return\n submitted = true\n completed = consume()\n admission = new AbortController()\n const response = await input.client.session\n .prompt(\n {\n sessionID: input.sessionID,\n id: messageID,\n text: [input.message, ...prepared.flatMap((file) => (file.text ? [file.text] : []))].join(\"\\n\\n\"),\n files: prepared.flatMap((file) => (file.attachment ? [file.attachment] : [])),\n delivery: \"steer\",\n },\n { signal: admission.signal },\n )\n .catch(async (error) => {\n if (interrupted) {\n await input.client.session.interrupt({ sessionID: input.sessionID }).catch(() => {})\n }\n controller.abort()\n await completed?.catch(() => {})\n if (interrupted || emittedError) return undefined\n throw error\n })\n admission = undefined\n if (!response) return\n if (interrupted) await input.client.session.interrupt({ sessionID: input.sessionID }).catch(() => {})\n\n const [permissions, questions, forms] = await Promise.all([\n input.client.permission.list({ sessionID: input.sessionID }).catch(() => undefined),\n input.client.question.list({ sessionID: input.sessionID }).catch(() => undefined),\n Promise.all(\n (input.attached ? [input.sessionID] : [input.sessionID, GLOBAL_FORM_SESSION_ID]).map((sessionID) =>\n input.client.form.list({ sessionID }).catch(() => undefined),\n ),\n ),\n ])\n await Promise.all([\n ...(permissions ?? []).map(replyPermission),\n ...(questions ?? []).map(rejectQuestion),\n ...forms.flatMap((response) => response ?? []).map(cancelForm),\n ])\n await completed\n } finally {\n process.off(\"SIGINT\", interrupt)\n controller.abort()\n await stream.return?.(undefined).catch(() => {})\n }\n}\n\nfunction partID(eventID: string) {\n return `prt_${eventID.replace(/^evt_/, \"\")}`\n}\n\nfunction fallbackTool(event: {\n id: string\n created: number\n data: { assistantMessageID: string; callID: string }\n}): ToolState {\n return {\n id: partID(event.id),\n timestamp: toMillis(event.created),\n assistantMessageID: event.data.assistantMessageID,\n tool: \"tool\",\n input: {},\n }\n}\n\nfunction toMillis(value: unknown) {\n if (typeof value === \"number\") return value\n if (typeof value === \"string\") return new Date(value).getTime()\n return Date.now()\n}\n\nasync function prepareFile(file: File) {\n if (file.mime !== \"text/plain\") {\n const uri = file.url.startsWith(\"data:\")\n ? file.url\n : `data:${file.mime};base64,${Buffer.from(await Bun.file(new URL(file.url)).arrayBuffer()).toString(\"base64\")}`\n return { attachment: { uri, mime: file.mime, name: file.filename } }\n }\n const content = file.url.startsWith(\"data:\")\n ? Buffer.from(file.url.slice(file.url.indexOf(\",\") + 1), \"base64\").toString(\"utf8\")\n : await Bun.file(new URL(file.url)).text()\n return { text: `<file name=\"${file.filename}\">\\n${content}\\n</file>` }\n}\n", | ||
| "import { EOL } from \"node:os\"\n\nexport const Style = {\n TEXT_DIM: \"\\x1b[90m\",\n TEXT_NORMAL: \"\\x1b[0m\",\n TEXT_WARNING_BOLD: \"\\x1b[93m\\x1b[1m\",\n TEXT_DANGER_BOLD: \"\\x1b[91m\\x1b[1m\",\n}\n\nexport function println(...message: string[]) {\n process.stderr.write(message.join(\" \") + EOL)\n}\n\nlet blank = false\n\nexport function empty() {\n if (blank) return\n println(Style.TEXT_NORMAL)\n blank = true\n}\n\nexport function error(message: string) {\n if (message.startsWith(\"Error: \")) message = message.slice(\"Error: \".length)\n println(Style.TEXT_DANGER_BOLD + \"Error: \" + Style.TEXT_NORMAL + message)\n}\n\nexport * as UI from \"./ui\"\n" | ||
| ], | ||
| "mappings": ";4uBAsBA,oBAAsB,OAAO,MAAC,OAAyB,MACrD,QAAS,MAAK,OACd,SAAM,OAAe,OAAW,aAAQ,WAAM,WAAQ,YAAY,WAAM,SAAI,MAAM,KAAK,EAAG,EAAM,MAAM,EAChG,EAAqB,yCACrB,EAAY,GAAe,EAEjC,GAAI,CACF,IAAM,EAAM,EAAS,KAAK,CACxB,QAAS,EAAM,OAAO,SAAS,IAC/B,QAAS,EAAQ,QAAQ,EAAM,OAAO,QAAQ,CAChD,CAAC,EACK,EAAQ,GAAW,EAAM,KAAK,EAChC,EACE,EAAe,IAAM,CAEzB,OADA,IAAc,GAAc,EAAK,EAAW,EAAM,KAAK,EAChD,GAEH,EAAiB,SAAY,CACjC,IAAO,EAAO,GAAY,MAAM,QAAQ,IAAI,CAAC,EAAa,EAAG,GAAc,EAAK,EAAW,CAAK,CAAC,CAAC,EAC5F,EACJ,IAAU,GAAU,MAAQ,CAAE,WAAY,EAAS,MAAM,WAAY,QAAS,EAAS,MAAM,EAAG,EAAI,QACtG,GAAI,EAAY,MAAM,EAAoB,CAAE,MAAK,YAAW,MAAO,CAAW,CAAC,EAC/E,IAAM,EAAU,GAAa,MAAM,EAAc,EAAK,EAAW,EAAO,CAAK,EAC7E,MAAO,CAAE,GAAI,EAAQ,GAAI,MAAO,EAAQ,MAAO,OAAQ,IAAa,MAAU,GAE1E,EAAS,CACb,EACA,IACG,EAAc,EAAK,EAAW,EAAK,MAAO,EAAK,MAAO,EAAK,OAAO,EAEvE,MADgB,MAAM,GACR,2BAA2B,CACvC,MACA,YACA,eACA,QAAS,EACT,cAAe,EACf,MAAO,EAAM,MACb,QACA,QAAS,OACT,MAAO,CAAC,EACR,eACA,SAAU,GACV,OAAQ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AG,MAAM,kBAAoB,IAAK,EAAG,MAAM,YAAa,CAAO,EAG5E,SAAS,CAAW,CAAC,EAAwB,EAAiB,EAAoB,CAEhF,GADA,QAAQ,SAAW,EACf,EAAM,SAAW,OAAQ,CAC3B,QAAQ,OAAO,MACb,KAAK,UAAU,CACb,KAAM,QACN,UAAW,KAAK,IAAI,EACpB,UAAW,GAAa,GACxB,MAAO,CAAE,KAAM,UAAW,SAAQ,CACpC,CAAC,EAAI;AAAA,CACP,EACA,OAEF,EAAG,MAAM,CAAO,EAGlB,SAAS,CAAI,CAAC,EAAwB,CACpC,MAAU,MAAM,CAAO", | ||
| "debugId": "44A6376B61BED99864756E2164756E21", | ||
| "names": [] | ||
| } |
| { | ||
| "version": 3, | ||
| "sources": ["src/services/service-config.ts"], | ||
| "sourcesContent": [ | ||
| "import { Global } from \"@opencode-ai/core/global\"\nimport { InstallationChannel, InstallationVersion } from \"@opencode-ai/core/installation/version\"\nimport { Hash } from \"@opencode-ai/core/util/hash\"\nimport { Service } from \"@opencode-ai/client/effect/service\"\nimport { Effect, FileSystem, Option, Schema } from \"effect\"\nimport { randomBytes } from \"crypto\"\nimport path from \"path\"\n\n// The CLI's service configuration file, plus the Service.EnsureOptions binding that\n// points the client package's service operations at this CLI: which\n// registration file (by channel), which version, and how to spawn opencode.\n\nexport const Info = Schema.Struct({\n hostname: Schema.optional(Schema.String),\n port: Schema.optional(Schema.Int.check(Schema.isGreaterThanOrEqualTo(1), Schema.isLessThanOrEqualTo(65_535))),\n password: Schema.optional(Schema.String),\n})\nexport type Info = typeof Info.Type\n\nconst keys = [\"hostname\", \"port\", \"password\"] as const\ntype Key = (typeof keys)[number]\n\nconst decodeInfo = Schema.decodeUnknownEffect(Schema.fromJsonString(Info))\nconst decodeRegistration = Schema.decodeUnknownEffect(Schema.fromJsonString(Service.Info))\n\nexport function filename(channel = InstallationChannel) {\n if (channel === \"latest\") return \"service.json\"\n if (channel === \"local\") return \"service-local.json\"\n return `service-${Hash.fast(channel)}.json`\n}\n\nexport function versionBelongsToChannel(\n version: string | undefined,\n channel = InstallationChannel,\n installedVersion = InstallationVersion,\n) {\n if (version === undefined) return false\n if (version === installedVersion) return true\n const prefix = `0.0.0-${channel}-`\n if (!version.startsWith(prefix)) return false\n return /^\\d+(?:\\.\\d+)?$/.test(version.slice(prefix.length))\n}\n\nexport const migrateRegistration = Effect.fnUntraced(function* (\n legacy: string,\n file: string,\n channel = InstallationChannel,\n installedVersion = InstallationVersion,\n) {\n if (channel === \"latest\" || channel === \"local\") return\n const fs = yield* FileSystem.FileSystem\n const text = yield* fs.readFileString(legacy).pipe(Effect.option)\n if (Option.isNone(text)) return\n const registration = yield* decodeRegistration(text.value).pipe(Effect.option)\n if (Option.isNone(registration)) return\n if (!versionBelongsToChannel(registration.value.version, channel, installedVersion)) return\n yield* fs.writeFileString(file, text.value, { flag: \"wx\", mode: 0o600 }).pipe(Effect.ignore)\n})\n\nfunction configKey(key: string): Key {\n if (key === \"hostname\" || key === \"port\" || key === \"password\") return key\n throw new Error(`Unknown service config key: ${key}`)\n}\n\nconst paths = Effect.gen(function* () {\n const fs = yield* FileSystem.FileSystem\n const global = yield* Global.Service\n const name = filename()\n const file = path.join(global.state, name)\n return {\n fs,\n file,\n legacyFile: path.join(global.state, \"service.json\"),\n configFile: path.join(global.config, name),\n }\n})\n\nexport const options = Effect.fnUntraced(function* () {\n const { file, legacyFile } = yield* paths\n yield* migrateRegistration(legacyFile, file)\n const compiled = path.basename(process.execPath).replace(/\\.exe$/, \"\") !== \"bun\"\n const entrypoint = compiled ? undefined : process.argv[1]\n if (!compiled && entrypoint === undefined) return yield* Effect.fail(new Error(\"Failed to resolve CLI entrypoint\"))\n return {\n file,\n version: InstallationVersion,\n command: [process.execPath, ...(entrypoint ? [entrypoint] : []), \"serve\", \"--service\"],\n }\n})\n\nexport const read = Effect.fn(\"cli.service-config.read\")(function* () {\n const { fs, configFile } = yield* paths\n return yield* fs.readFileString(configFile).pipe(\n Effect.flatMap(decodeInfo),\n Effect.catch(() => Effect.succeed({} as Info)),\n )\n})\n\nconst write = Effect.fn(\"cli.service-config.write\")(function* (value: Info) {\n const { fs, configFile } = yield* paths\n const temp = configFile + \".tmp\"\n yield* fs.makeDirectory(path.dirname(configFile), { recursive: true })\n yield* fs.writeFileString(temp, JSON.stringify(value, null, 2) + \"\\n\", { mode: 0o600 })\n yield* fs.rename(temp, configFile)\n})\n\nexport const password = Effect.fn(\"cli.service-config.password\")(function* (value?: string) {\n const existing = yield* read()\n if (value === undefined && existing.password) return existing.password\n const next = value ?? randomBytes(32).toString(\"base64url\")\n\n // Keep one private credential across server restarts so discovered clients\n // can reconnect without exposing a password flag or environment variable.\n yield* write({ ...existing, password: next })\n return next\n})\n\nexport const get = Effect.fn(\"cli.service-config.get\")(function* (key?: string) {\n if (key === undefined) {\n const { password: _password, ...safe } = yield* read()\n return JSON.stringify(safe, null, 2)\n }\n switch (configKey(key)) {\n case \"hostname\": {\n return (yield* read()).hostname ?? \"\"\n }\n case \"port\": {\n const port = (yield* read()).port\n return port === undefined ? \"\" : String(port)\n }\n case \"password\": {\n return yield* password()\n }\n }\n throw new Error(`Unknown service config key: ${key}`)\n})\n\nexport const set = Effect.fn(\"cli.service-config.set\")(function* (key: string, value: string) {\n switch (configKey(key)) {\n case \"hostname\": {\n yield* Service.stop(yield* options())\n yield* write({ ...(yield* read()), hostname: value })\n return\n }\n case \"port\": {\n const port = Number(value)\n if (!Number.isInteger(port) || port < 1 || port > 65_535) throw new Error(\"Port must be between 1 and 65535\")\n yield* Service.stop(yield* options())\n yield* write({ ...(yield* read()), port })\n return\n }\n case \"password\": {\n yield* Service.stop(yield* options())\n yield* password(value)\n return\n }\n }\n})\n\nexport const unset = Effect.fn(\"cli.service-config.unset\")(function* (key: string) {\n switch (configKey(key)) {\n case \"hostname\": {\n yield* Service.stop(yield* options())\n const { hostname: _hostname, ...next } = yield* read()\n yield* write(next)\n return\n }\n case \"port\": {\n yield* Service.stop(yield* options())\n const { port: _port, ...next } = yield* read()\n yield* write(next)\n return\n }\n case \"password\": {\n yield* Service.stop(yield* options())\n const { password: _password, ...next } = yield* read()\n yield* write(next)\n return\n }\n }\n})\n\nexport * as ServiceConfig from \"./service-config\"\n" | ||
| ], | ||
| "mappings": ";sdAKA,2BAAS,oBACT,yBAMO,SAAM,EAAO,EAAO,OAAO,CAChC,SAAU,EAAO,SAAS,EAAO,MAAM,EACvC,KAAM,EAAO,SAAS,EAAO,IAAI,MAAM,EAAO,uBAAuB,CAAC,EAAG,EAAO,oBAAoB,KAAM,CAAC,CAAC,EAC5G,SAAU,EAAO,SAAS,EAAO,MAAM,CACzC,CAAC,EAMD,IAAM,EAAa,EAAO,oBAAoB,EAAO,eAAe,CAAI,CAAC,EACnE,EAAqB,EAAO,oBAAoB,EAAO,eAAe,EAAQ,IAAI,CAAC,EAElF,SAAS,CAAQ,CAAC,EAAU,EAAqB,CACtD,GAAI,IAAY,SAAU,MAAO,eACjC,GAAI,IAAY,QAAS,MAAO,qBAChC,MAAO,WAAW,EAAK,KAAK,CAAO,SAG9B,SAAS,CAAuB,CACrC,EACA,EAAU,EACV,EAAmB,EACnB,CACA,GAAI,IAAY,OAAW,MAAO,GAClC,GAAI,IAAY,EAAkB,MAAO,GACzC,IAAM,EAAS,SAAS,KACxB,GAAI,CAAC,EAAQ,WAAW,CAAM,EAAG,MAAO,GACxC,MAAO,kBAAkB,KAAK,EAAQ,MAAM,EAAO,MAAM,CAAC,EAGrD,IAAM,EAAsB,EAAO,WAAW,SAAU,CAC7D,EACA,EACA,EAAU,EACV,EAAmB,EACnB,CACA,GAAI,IAAY,UAAY,IAAY,QAAS,OACjD,IAAM,EAAK,MAAO,EAAW,WACvB,EAAO,MAAO,EAAG,eAAe,CAAM,EAAE,KAAK,EAAO,MAAM,EAChE,GAAI,EAAO,OAAO,CAAI,EAAG,OACzB,IAAM,EAAe,MAAO,EAAmB,EAAK,KAAK,EAAE,KAAK,EAAO,MAAM,EAC7E,GAAI,EAAO,OAAO,C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EACzB,GAAI,CAAC,OAAO,UAAU,CAAI,GAAK,EAAO,GAAK,EAAO,MAAQ,MAAU,MAAM,kCAAkC,EAC5G,MAAO,EAAQ,KAAK,MAAO,EAAQ,CAAC,EACpC,MAAO,EAAM,IAAM,MAAO,EAAK,EAAI,MAAK,CAAC,EACzC,MACF,KACK,WAAY,CACf,MAAO,EAAQ,KAAK,MAAO,EAAQ,CAAC,EACpC,MAAO,EAAS,CAAK,EACrB,MACF,GAEH,EAEY,EAAQ,EAAO,GAAG,0BAA0B,EAAE,SAAU,CAAC,EAAa,CACjF,OAAQ,EAAU,CAAG,OACd,WAAY,CACf,MAAO,EAAQ,KAAK,MAAO,EAAQ,CAAC,EACpC,IAAQ,SAAU,KAAc,GAAS,MAAO,EAAK,EACrD,MAAO,EAAM,CAAI,EACjB,MACF,KACK,OAAQ,CACX,MAAO,EAAQ,KAAK,MAAO,EAAQ,CAAC,EACpC,IAAQ,KAAM,KAAU,GAAS,MAAO,EAAK,EAC7C,MAAO,EAAM,CAAI,EACjB,MACF,KACK,WAAY,CACf,MAAO,EAAQ,KAAK,MAAO,EAAQ,CAAC,EACpC,IAAQ,SAAU,KAAc,GAAS,MAAO,EAAK,EACrD,MAAO,EAAM,CAAI,EACjB,MACF,GAEH", | ||
| "debugId": "2C4C72CBB43DA88664756E2164756E21", | ||
| "names": [] | ||
| } |
| { | ||
| "version": 3, | ||
| "sources": ["src/commands/handlers/mcp/logout.ts"], | ||
| "sourcesContent": [ | ||
| "import { EOL } from \"node:os\"\nimport { Effect } from \"effect\"\nimport { OpenCode } from \"@opencode-ai/client\"\nimport { Commands } from \"../../commands\"\nimport { Runtime } from \"../../../framework/runtime\"\nimport { Service } from \"@opencode-ai/client/effect/service\"\nimport { ServiceConfig } from \"../../../services/service-config\"\nimport { resolveIntegration } from \"./resolve\"\n\nconst location = { directory: process.cwd() }\n\nexport default Runtime.handler(\n Commands.commands.mcp.commands.logout,\n Effect.fn(\"cli.mcp.logout\")(function* (input) {\n const options = yield* ServiceConfig.options()\n const found = yield* Service.discover(options)\n const endpoint = found ?? (yield* Service.ensure(options))\n const client = OpenCode.make({ baseUrl: endpoint.url, headers: Service.headers(endpoint) })\n\n const integration = yield* resolveIntegration(client, input.name, location)\n if (!integration) {\n process.stdout.write(`No stored credentials for ${input.name}` + EOL)\n return\n }\n\n const credentials = integration.connections.filter((connection) => connection.type === \"credential\")\n if (credentials.length === 0) {\n process.stdout.write(`No stored credentials for ${input.name}` + EOL)\n return\n }\n\n yield* Effect.forEach(\n credentials,\n (connection) => Effect.promise(() => client.credential.remove({ credentialID: connection.id, location })),\n { discard: true },\n )\n process.stdout.write(`Removed OAuth credentials for ${input.name}` + EOL)\n }),\n)\n" | ||
| ], | ||
| "mappings": ";88BAAA,mBAAS,gBAST,SAAM,OAAW,MAAE,eAAW,aAAQ,SAAI,MAAE,OAE7B,SAAQ,aACrB,OAAS,cAAS,SAAI,cAAS,YAC/B,OAAO,QAAG,qBAAgB,OAAE,cAAU,MAAC,OAAO,MAC5C,IAAM,EAAU,MAAO,EAAc,QAAQ,EAEvC,GADQ,MAAO,EAAQ,SAAS,CAAO,KAClB,MAAO,EAAQ,OAAO,CAAO,GAClD,EAAS,EAAS,KAAK,CAAE,QAAS,EAAS,IAAK,QAAS,EAAQ,QAAQ,CAAQ,CAAE,CAAC,EAEpF,EAAc,MAAO,EAAmB,EAAQ,EAAM,KAAM,CAAQ,EAC1E,GAAI,CAAC,EAAa,CAChB,QAAQ,OAAO,MAAM,6BAA6B,EAAM,OAAS,CAAG,EACpE,OAGF,IAAM,EAAc,EAAY,YAAY,OAAO,CAAC,IAAe,EAAW,OAAS,YAAY,EACnG,GAAI,EAAY,SAAW,EAAG,CAC5B,QAAQ,OAAO,MAAM,6BAA6B,EAAM,OAAS,CAAG,EACpE,OAGF,MAAO,EAAO,QACZ,EACA,CAAC,IAAe,EAAO,QAAQ,IAAM,EAAO,WAAW,OAAO,CAAE,aAAc,EAAW,GAAI,UAAS,CAAC,CAAC,EACxG,CAAE,QAAS,EAAK,CAClB,EACA,QAAQ,OAAO,MAAM,iCAAiC,EAAM,OAAS,CAAG,EACzE,CACH", | ||
| "debugId": "386D62EB175E6FA564756E2164756E21", | ||
| "names": [] | ||
| } |
| { | ||
| "version": 3, | ||
| "sources": ["src/commands/handlers/mcp/add.ts"], | ||
| "sourcesContent": [ | ||
| "import { EOL } from \"node:os\"\nimport path from \"node:path\"\nimport { Effect, Option } from \"effect\"\nimport { applyEdits, modify } from \"jsonc-parser\"\nimport { Global } from \"@opencode-ai/core/global\"\nimport { Commands } from \"../../commands\"\nimport { Runtime } from \"../../../framework/runtime\"\n\nexport default Runtime.handler(\n Commands.commands.mcp.commands.add,\n Effect.fn(\"cli.mcp.add\")(function* (input) {\n const url = Option.getOrUndefined(input.url)\n const headers = Option.getOrUndefined(input.header)\n const environment = Option.getOrUndefined(input.env)\n // The CLI framework strands `--` operands on the root command, so read the local server command\n // straight from argv after `--`. This also lets the command carry its own flags (e.g. `npx -y`).\n const dash = process.argv.indexOf(\"--\")\n const command = dash === -1 ? [...input.command] : process.argv.slice(dash + 1)\n\n const hasCommand = command.length > 0\n if (url && hasCommand)\n return yield* Effect.fail(new Error(\"Provide either --url <url> or a command after --, not both\"))\n if (!url && !hasCommand) return yield* Effect.fail(new Error(\"Provide either --url <url> or a command after --\"))\n if (url && !URL.canParse(url)) return yield* Effect.fail(new Error(`Invalid URL: ${url}`))\n if (url && environment) return yield* Effect.fail(new Error(\"--env is only valid for local MCP servers\"))\n if (hasCommand && headers) return yield* Effect.fail(new Error(\"--header is only valid for remote MCP servers\"))\n\n const server = url\n ? { type: \"remote\" as const, url, ...(headers ? { headers } : {}) }\n : { type: \"local\" as const, command, ...(environment ? { environment } : {}) }\n\n const configPath = yield* Effect.promise(() => resolveConfigPath(input.global ? Global.Path.config : process.cwd()))\n yield* Effect.promise(() => write(configPath, input.name, server))\n process.stdout.write(`MCP server \"${input.name}\" added to ${configPath}` + EOL)\n }),\n)\n\nasync function resolveConfigPath(directory: string) {\n const candidates = [\n path.join(directory, \"opencode.json\"),\n path.join(directory, \"opencode.jsonc\"),\n path.join(directory, \".opencode\", \"opencode.json\"),\n path.join(directory, \".opencode\", \"opencode.jsonc\"),\n ]\n for (const candidate of candidates) {\n if (await Bun.file(candidate).exists()) return candidate\n }\n return candidates[0]\n}\n\nasync function write(configPath: string, name: string, server: unknown) {\n const file = Bun.file(configPath)\n const text = (await file.exists()) ? await file.text() : \"{}\"\n const edits = modify(text, [\"mcp\", \"servers\", name], server, {\n formattingOptions: { tabSize: 2, insertSpaces: true },\n })\n await Bun.write(configPath, applyEdits(text, edits))\n}\n" | ||
| ], | ||
| "mappings": ";2xBAAA,mBAAS,gBACT,yBAOA,SAAe,SAAQ,aACrB,OAAS,cAAS,SAAI,cAAS,SAC/B,OAAO,QAAG,kBAAa,OAAE,cAAU,MAAC,OAAO,MACzC,SAAM,EAAM,EAAO,eAAe,EAAM,GAAG,EACrC,EAAU,EAAO,eAAe,EAAM,MAAM,EAC5C,EAAc,EAAO,eAAe,EAAM,GAAG,EAG7C,EAAO,QAAQ,KAAK,QAAQ,IAAI,EAChC,EAAU,IAAS,GAAK,CAAC,GAAG,EAAM,OAAO,EAAI,QAAQ,KAAK,MAAM,EAAO,CAAC,EAExE,EAAa,EAAQ,OAAS,EACpC,GAAI,GAAO,EACT,OAAO,MAAO,EAAO,KAAS,MAAM,4DAA4D,CAAC,EACnG,GAAI,CAAC,GAAO,CAAC,EAAY,OAAO,MAAO,EAAO,KAAS,MAAM,kDAAkD,CAAC,EAChH,GAAI,GAAO,CAAC,IAAI,SAAS,CAAG,EAAG,OAAO,MAAO,EAAO,KAAS,MAAM,gBAAgB,GAAK,CAAC,EACzF,GAAI,GAAO,EAAa,OAAO,MAAO,EAAO,KAAS,MAAM,2CAA2C,CAAC,EACxG,GAAI,GAAc,EAAS,OAAO,MAAO,EAAO,KAAS,MAAM,+CAA+C,CAAC,EAE/G,IAAM,EAAS,EACX,CAAE,KAAM,SAAmB,SAAS,EAAU,CAAE,SAAQ,EAAI,CAAC,CAAG,EAChE,CAAE,KAAM,QAAkB,aAAa,EAAc,CAAE,aAAY,EAAI,CAAC,CAAG,EAEzE,EAAa,MAAO,EAAO,QAAQ,IAAM,EAAkB,EAAM,OAAS,EAAO,KAAK,OAAS,QAAQ,IAAI,CAAC,CAAC,EACnH,MAAO,EAAO,QAAQ,IAAM,EAAM,EAAY,EAAM,KAAM,CAAM,CAAC,EACjE,QAAQ,OAAO,MAAM,eAAe,EAAM,kBAAkB,IAAe,CAAG,EAC/E,CACH,EAEA,eAAe,CAAiB,CAAC,EAAmB,CAClD,IAAM,EAAa,CACjB,EAAK,KAAK,EAAW,eAAe,EACpC,EAAK,KAAK,EAAW,gBAAgB,EACrC,EAAK,KAAK,EAAW,YAAa,eAAe,EACjD,EAAK,KAAK,EAAW,YAAa,gBAAgB,CACpD,EACA,QAAW,KAAa,EACtB,GAAI,MAAM,IAAI,KAAK,CAAS,EAAE,OAAO,EAAG,OAAO,EAEjD,OAAO,EAAW,GAGpB,eAAe,CAAK,CAAC,EAAoB,EAAc,EAAiB,CACtE,IAAM,EAAO,IAAI,KAAK,CAAU,EAC1B,EAAQ,MAAM,EAAK,OAAO,EAAK,MAAM,EAAK,KAAK,EAAI,KACnD,EAAQ,EAAO,EAAM,CAAC,MAAO,UAAW,CAAI,EAAG,EAAQ,CAC3D,kBAAmB,CAAE,QAAS,EAAG,aAAc,EAAK,CACtD,CAAC,EACD,MAAM,IAAI,MAAM,EAAY,EAAW,EAAM,CAAK,CAAC", | ||
| "debugId": "0AECBEB226A9C4C164756E2164756E21", | ||
| "names": [] | ||
| } |
| { | ||
| "version": 3, | ||
| "sources": ["src/commands/handlers/service/status.ts"], | ||
| "sourcesContent": [ | ||
| "import { EOL } from \"os\"\nimport { Effect } from \"effect\"\nimport { Service } from \"@opencode-ai/client/effect/service\"\nimport { Commands } from \"../../commands\"\nimport { Runtime } from \"../../../framework/runtime\"\nimport { ServiceConfig } from \"../../../services/service-config\"\n\nexport default Runtime.handler(\n Commands.commands.service.commands.status,\n Effect.fn(\"cli.service.status\")(function* () {\n const options = yield* ServiceConfig.options()\n const found = yield* Service.discover({ ...options, version: undefined })\n process.stdout.write((found?.url ?? \"stopped\") + EOL)\n }),\n)\n" | ||
| ], | ||
| "mappings": ";i3BAAA,mBAAS,gBAOT,SAAe,SAAQ,aACrB,OAAS,cAAS,aAAQ,cAAS,YACnC,OAAO,QAAG,yBAAoB,OAAE,cAAU,OAAG,MAC3C,SAAM,OAAU,WAAO,OAAc,aAAQ,OACvC,EAAQ,MAAO,EAAQ,SAAS,IAAK,EAAS,QAAS,MAAU,CAAC,EACxE,QAAQ,OAAO,OAAO,GAAO,KAAO,WAAa,CAAG,EACrD,CACH", | ||
| "debugId": "D6EB13B53191A58B64756E2164756E21", | ||
| "names": [] | ||
| } |
| { | ||
| "version": 3, | ||
| "sources": ["src/commands/handlers/service/restart.ts"], | ||
| "sourcesContent": [ | ||
| "import { EOL } from \"os\"\nimport { Effect } from \"effect\"\nimport { Service } from \"@opencode-ai/client/effect/service\"\nimport { Commands } from \"../../commands\"\nimport { Runtime } from \"../../../framework/runtime\"\nimport { ServiceConfig } from \"../../../services/service-config\"\n\nexport default Runtime.handler(\n Commands.commands.service.commands.restart,\n Effect.fn(\"cli.service.restart\")(function* () {\n const options = yield* ServiceConfig.options()\n yield* Service.stop(options)\n const transport = yield* Service.ensure(options)\n process.stdout.write(transport.url + EOL)\n }),\n)\n" | ||
| ], | ||
| "mappings": ";i3BAAA,mBAAS,gBAOT,SAAe,SAAQ,aACrB,OAAS,cAAS,aAAQ,cAAS,aACnC,OAAO,QAAG,0BAAqB,OAAE,cAAU,OAAG,MAC5C,SAAM,OAAU,WAAO,OAAc,aAAQ,OAC7C,MAAO,EAAQ,KAAK,CAAO,EAC3B,IAAM,EAAY,MAAO,EAAQ,OAAO,CAAO,EAC/C,QAAQ,OAAO,MAAM,EAAU,IAAM,CAAG,EACzC,CACH", | ||
| "debugId": "30B9E9BFE75657A464756E2164756E21", | ||
| "names": [] | ||
| } |
Sorry, the diff of this file is too big to display
| { | ||
| "version": 3, | ||
| "sources": ["src/ui/timeline.tsx", "src/commands/handlers/console/login.ts"], | ||
| "sourcesContent": [ | ||
| "import { createComponent as _$createComponent } from \"@opentui/solid\";\nimport { effect as _$effect } from \"@opentui/solid\";\nimport { createTextNode as _$createTextNode } from \"@opentui/solid\";\nimport { insertNode as _$insertNode } from \"@opentui/solid\";\nimport { insert as _$insert } from \"@opentui/solid\";\nimport { setProp as _$setProp } from \"@opentui/solid\";\nimport { createElement as _$createElement } from \"@opentui/solid\";\n/** @jsxImportSource @opentui/solid */\nimport { createCliRenderer, RGBA } from \"@opentui/core\";\nimport { createScrollbackWriter, render, useKeyboard } from \"@opentui/solid\";\nimport { registerOpencodeSpinner } from \"@opencode-ai/tui/component/register-spinner\";\nimport { Show, createSignal } from \"solid-js\";\nregisterOpencodeSpinner();\nconst SPINNER_FRAMES = [\"⠋\", \"⠙\", \"⠹\", \"⠸\", \"⠼\", \"⠴\", \"⠦\", \"⠧\", \"⠇\", \"⠏\"];\nconst IDLE_TIMEOUT = 1_000;\nconst COLORS = {\n accent: RGBA.fromIndex(6),\n error: RGBA.fromIndex(1),\n foreground: RGBA.defaultForeground(),\n muted: RGBA.fromIndex(8),\n success: RGBA.fromIndex(2)\n};\nconst ROWS = {\n intro: {\n marker: \"┌\",\n color: COLORS.muted,\n connector: true\n },\n item: {\n marker: \"●\",\n color: COLORS.accent,\n connector: true\n },\n success: {\n marker: \"◇\",\n color: COLORS.success,\n connector: true\n },\n failure: {\n marker: \"■\",\n color: COLORS.error,\n connector: false\n },\n outro: {\n marker: \"└\",\n color: COLORS.muted,\n connector: false\n }\n};\nfunction row(kind, value) {\n const style = ROWS[kind];\n return createScrollbackWriter(() => (() => {\n var _el$ = _$createElement(\"box\"),\n _el$2 = _$createElement(\"box\"),\n _el$3 = _$createElement(\"text\"),\n _el$4 = _$createElement(\"text\");\n _$insertNode(_el$, _el$2);\n _$setProp(_el$, \"width\", \"100%\");\n _$setProp(_el$, \"minHeight\", 1);\n _$setProp(_el$, \"flexDirection\", \"column\");\n _$insertNode(_el$2, _el$3);\n _$insertNode(_el$2, _el$4);\n _$setProp(_el$2, \"width\", \"100%\");\n _$setProp(_el$2, \"minHeight\", 1);\n _$setProp(_el$2, \"flexDirection\", \"row\");\n _$setProp(_el$2, \"gap\", 1);\n _$setProp(_el$3, \"flexShrink\", 0);\n _$insert(_el$3, () => style.marker);\n _$setProp(_el$4, \"wrapMode\", \"word\");\n _$insert(_el$4, value);\n _$insert(_el$, _$createComponent(Show, {\n get when() {\n return style.connector;\n },\n get children() {\n var _el$5 = _$createElement(\"text\");\n _$insertNode(_el$5, _$createTextNode(`│`));\n _$effect(_$p => _$setProp(_el$5, \"fg\", COLORS.muted, _$p));\n return _el$5;\n }\n }), null);\n _$effect(_p$ => {\n var _v$ = style.color,\n _v$2 = COLORS.foreground;\n _v$ !== _p$.e && (_p$.e = _$setProp(_el$3, \"fg\", _v$, _p$.e));\n _v$2 !== _p$.t && (_p$.t = _$setProp(_el$4, \"fg\", _v$2, _p$.t));\n return _p$;\n }, {\n e: undefined,\n t: undefined\n });\n return _el$;\n })(), {\n startOnNewLine: true,\n trailingNewline: !style.connector\n });\n}\nfunction TimelineFooter(props) {\n useKeyboard(event => {\n if (event.name !== \"escape\" && !(event.ctrl && event.name === \"c\")) return;\n event.preventDefault();\n props.cancel();\n });\n return (() => {\n var _el$7 = _$createElement(\"box\");\n _$setProp(_el$7, \"width\", \"100%\");\n _$setProp(_el$7, \"height\", 1);\n _$setProp(_el$7, \"flexDirection\", \"row\");\n _$setProp(_el$7, \"gap\", 1);\n _$insert(_el$7, _$createComponent(Show, {\n get when() {\n return props.pending();\n },\n children: text => [(() => {\n var _el$8 = _$createElement(\"spinner\");\n _$setProp(_el$8, \"frames\", SPINNER_FRAMES);\n _$setProp(_el$8, \"interval\", 80);\n _$effect(_$p => _$setProp(_el$8, \"color\", COLORS.accent, _$p));\n return _el$8;\n })(), (() => {\n var _el$9 = _$createElement(\"text\");\n _$setProp(_el$9, \"wrapMode\", \"none\");\n _$setProp(_el$9, \"truncate\", true);\n _$insert(_el$9, text);\n _$effect(_$p => _$setProp(_el$9, \"fg\", COLORS.foreground, _$p));\n return _el$9;\n })()]\n }));\n return _el$7;\n })();\n}\nfunction bounded(task) {\n return new Promise(resolve => {\n const timer = setTimeout(resolve, IDLE_TIMEOUT);\n timer.unref();\n const finish = () => {\n clearTimeout(timer);\n resolve();\n };\n void task.then(finish, finish);\n });\n}\nasync function shutdown(renderer) {\n await bounded(renderer.idle());\n try {\n renderer.externalOutputMode = \"passthrough\";\n } finally {\n try {\n renderer.screenMode = \"main-screen\";\n } finally {\n if (!renderer.isDestroyed) renderer.destroy();\n }\n }\n}\nexport async function createTimelineHost() {\n const stdout = process.stdout;\n const controller = new AbortController();\n const signals = [\"SIGINT\", \"SIGHUP\", \"SIGQUIT\"];\n const cancel = () => {\n if (!controller.signal.aborted) controller.abort();\n };\n signals.forEach(signal => process.on(signal, cancel));\n if (!stdout.isTTY || !process.stdin.isTTY) {\n let closed = false;\n let writing = false;\n let active;\n let closeTask;\n const write = async (kind, text) => {\n if (closed) throw new Error(\"timeline closed\");\n if (writing) throw new Error(\"timeline write already in progress\");\n writing = true;\n try {\n const style = kind === \"pending\" ? undefined : ROWS[kind];\n const marker = kind === \"pending\" ? \".\" : ROWS[kind].marker;\n const connector = style?.connector ? \"│\\n\" : \"\";\n active = new Promise((resolve, reject) => {\n stdout.write(`${marker} ${text}\\n${connector}`, error => error ? reject(error) : resolve());\n });\n await active;\n } finally {\n writing = false;\n active = undefined;\n }\n };\n const close = () => {\n if (closeTask) return closeTask;\n closed = true;\n closeTask = (async () => {\n await active?.catch(() => {});\n signals.forEach(signal => process.off(signal, cancel));\n })();\n return closeTask;\n };\n return {\n signal: controller.signal,\n intro: text => write(\"intro\", text),\n item: text => write(\"item\", text),\n pending: text => write(\"pending\", text),\n success: text => write(\"success\", text),\n failure: text => write(\"failure\", text),\n outro: text => write(\"outro\", text),\n close\n };\n }\n let renderer;\n try {\n // Start on a fresh row so delayed SSH cursor reports cannot make\n // split-footer overwrite the shell command.\n process.stdout.write(\"\\n\");\n renderer = await createCliRenderer({\n stdin: process.stdin,\n useMouse: false,\n autoFocus: false,\n openConsoleOnError: false,\n exitOnCtrlC: false,\n exitSignals: [],\n screenMode: \"split-footer\",\n footerHeight: 1,\n externalOutputMode: \"capture-stdout\",\n consoleMode: \"disabled\",\n clearOnShutdown: false\n });\n const activeRenderer = renderer;\n const [pending, setPending] = createSignal();\n const renderTask = render(() => _$createComponent(TimelineFooter, {\n pending: pending,\n cancel: cancel\n }), activeRenderer);\n void renderTask.catch(cancel);\n await bounded(activeRenderer.idle());\n let closed = false;\n let writing = false;\n let active;\n let closeTask;\n const write = (kind, text) => {\n if (closed) return Promise.reject(new Error(\"timeline closed\"));\n if (writing) return Promise.reject(new Error(\"timeline write already in progress\"));\n writing = true;\n active = (async () => {\n if (kind === \"pending\") {\n setPending(text);\n activeRenderer.requestRender();\n } else {\n if (kind === \"success\" || kind === \"failure\" || kind === \"outro\") setPending(undefined);\n activeRenderer.writeToScrollback(row(kind, text));\n activeRenderer.requestRender();\n }\n await bounded(activeRenderer.idle());\n })().finally(() => {\n writing = false;\n active = undefined;\n });\n return active;\n };\n const close = () => {\n if (closeTask) return closeTask;\n closed = true;\n closeTask = (async () => {\n await active?.catch(() => {});\n try {\n await shutdown(activeRenderer);\n await bounded(renderTask);\n } finally {\n signals.forEach(signal => process.off(signal, cancel));\n }\n })();\n return closeTask;\n };\n return {\n signal: controller.signal,\n intro: text => write(\"intro\", text),\n item: text => write(\"item\", text),\n pending: text => write(\"pending\", text),\n success: text => write(\"success\", text),\n failure: text => write(\"failure\", text),\n outro: text => write(\"outro\", text),\n close\n };\n } catch (error) {\n try {\n if (renderer) await shutdown(renderer);\n } finally {\n signals.forEach(signal => process.off(signal, cancel));\n }\n throw error;\n }\n}", | ||
| "import { Cause, Effect, Exit, Option } from \"effect\"\nimport { Service } from \"@opencode-ai/client/effect/service\"\nimport { OpenCode, type OpenCodeClient } from \"@opencode-ai/client/promise\"\nimport { AppProcess } from \"@opencode-ai/core/process\"\nimport { Commands } from \"../../commands\"\nimport { Runtime } from \"../../../framework/runtime\"\nimport { ServiceConfig } from \"../../../services/service-config\"\nimport { createTimelineHost, type TimelineHost } from \"../../../ui/timeline\"\n\nconst integrationID = \"opencode\"\nconst location = { directory: process.cwd() }\n\nexport default Runtime.handler(\n Commands.commands.console.commands.login,\n Effect.fn(\"cli.console.login\")(function* (input) {\n const timeline = yield* Effect.acquireRelease(\n Effect.promise(() => createTimelineHost()),\n (value) => request(() => value.close()).pipe(Effect.ignore),\n )\n const exit = yield* login(timeline, Option.getOrUndefined(input.url)).pipe(\n Effect.raceFirst(AppProcess.waitForAbort(timeline.signal)),\n Effect.exit,\n )\n if (Exit.isSuccess(exit)) return\n\n const cancelled = timeline.signal.aborted\n yield* request(() => timeline.failure(cancelled ? \"Authorization cancelled\" : errorMessage(exit.cause))).pipe(\n Effect.ignore,\n )\n process.exitCode = cancelled ? 130 : 1\n }),\n)\n\nconst login = Effect.fn(\"cli.console.login.run\")(function* (timeline: TimelineHost, server?: string) {\n yield* request(() => timeline.intro(\"Log in\"))\n yield* request(() => timeline.pending(\"Connecting to OpenCode...\"))\n\n const endpoint = yield* Service.ensure(yield* ServiceConfig.options())\n const client = OpenCode.make({ baseUrl: endpoint.url, headers: Service.headers(endpoint) })\n const found = yield* request((signal) => client.integration.get({ integrationID, location }, { signal }))\n const integration = yield* required(found.data, \"OpenCode Console integration is unavailable\")\n const method = yield* required(\n integration.methods.find((candidate) => candidate.type === \"oauth\"),\n \"OpenCode Console login is unavailable\",\n )\n\n yield* request(() => timeline.pending(\"Starting authorization...\"))\n const started = yield* request((signal) =>\n client.integration.connect.oauth(\n {\n integrationID,\n methodID: method.id,\n inputs: server ? { server } : {},\n location,\n },\n { signal },\n ),\n )\n const attempt = started.data\n yield* Effect.addFinalizer(() =>\n request(() =>\n client.integration.attempt.cancel(\n { attemptID: attempt.attemptID, location },\n { signal: AbortSignal.timeout(5_000) },\n ),\n ).pipe(Effect.ignore),\n )\n if (attempt.mode !== \"auto\") yield* Effect.fail(new Error(\"OpenCode Console requires a device login\"))\n\n yield* request(() => timeline.item(`Go to: ${attempt.url}`))\n yield* request(() => timeline.item(attempt.instructions))\n yield* request(async () => {\n const { default: open } = await import(\"open\")\n await open(attempt.url)\n }).pipe(Effect.ignore)\n yield* request(() => timeline.pending(\"Waiting for authorization...\"))\n\n const status = yield* waitForConsoleLogin(client, attempt.attemptID)\n if (status.status === \"failed\") yield* Effect.fail(new Error(status.message))\n if (status.status === \"expired\") yield* Effect.fail(new Error(\"Device code expired\"))\n\n yield* request(() => timeline.success(\"Connected to OpenCode Console\"))\n yield* request(() => timeline.outro(\"Done\"))\n})\n\nconst waitForConsoleLogin = Effect.fn(\"cli.console.login.wait\")(function* (\n client: OpenCodeClient,\n attemptID: string,\n) {\n while (true) {\n const response = yield* request((signal) =>\n client.integration.attempt.status({ attemptID, location }, { signal }),\n )\n if (response.data.status !== \"pending\") return response.data\n yield* Effect.sleep(500)\n }\n})\n\nfunction request<A>(task: (signal: AbortSignal) => Promise<A>) {\n return Effect.tryPromise({\n try: task,\n catch: (cause) => cause,\n })\n}\n\nfunction required<A>(value: A | null | undefined, message: string) {\n return value === null || value === undefined ? Effect.fail(new Error(message)) : Effect.succeed(value)\n}\n\nfunction errorMessage(cause: Cause.Cause<unknown>) {\n const error = Cause.squash(cause)\n if (error instanceof Error) return error.message\n if (typeof error === \"object\" && error !== null && \"message\" in error && typeof error.message === \"string\") {\n return error.message\n }\n return String(error)\n}\n" | ||
| ], | ||
| "mappings": ";4nCAYA,OAAwB,OACxB,SAAM,OAAiB,MAAC,cAAI,cAAK,cAAK,cAAK,cAAK,cAAK,cAAK,cAAK,cAAK,aAAG,OACjE,QAAe,UACf,OAAS,MACb,YAAQ,O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AAI,OAAO,IAAU,UAAY,IAAU,MAAQ,YAAa,GAAS,OAAO,EAAM,UAAY,SAChG,OAAO,EAAM,QAEf,OAAO,OAAO,CAAK", | ||
| "debugId": "73050DE0FBEBCECE64756E2164756E21", | ||
| "names": [] | ||
| } |
| { | ||
| "version": 3, | ||
| "sources": ["src/commands/handlers/run.ts"], | ||
| "sourcesContent": [ | ||
| "import { Effect, Option } from \"effect\"\nimport { Commands } from \"../commands\"\nimport { Runtime } from \"../../framework/runtime\"\nimport { ServerConnection } from \"../../services/server-connection\"\n\nexport default Runtime.handler(Commands.commands.run, (input) =>\n Effect.gen(function* () {\n const { runNonInteractive } = yield* Effect.promise(() => import(\"../../mini\"))\n const separator = process.argv.indexOf(\"--\", 2)\n const server = yield* ServerConnection.resolve({\n server: Option.getOrUndefined(input.server),\n standalone: input.standalone,\n })\n yield* Effect.promise(() =>\n runNonInteractive({\n server,\n message: [...input.message, ...(separator === -1 ? [] : process.argv.slice(separator + 1))],\n continue: input.continue,\n session: Option.getOrUndefined(input.session),\n fork: input.fork,\n model: Option.getOrUndefined(input.model),\n agent: Option.getOrUndefined(input.agent),\n format: input.format,\n file: [...input.file],\n title: Option.getOrUndefined(input.title),\n thinking: input.thinking,\n auto: input.auto || input.yolo,\n }),\n )\n }),\n)\n" | ||
| ], | ||
| "mappings": ";ixCAKA,SAAe,SAAQ,aAAQ,OAAS,cAAS,SAAK,MAAC,SACrD,OAAO,SAAI,cAAU,OAAG,MACtB,SAAQ,0BAAsB,WAAO,OAAO,aAAQ,SAAa,wCAAa,OACxE,OAAY,aAAQ,UAAK,aAAQ,UAAM,MAAC,OACxC,OAAS,WAAO,OAAiB,aAAQ,MAC7C,YAAQ,OAAO,oBAAe,EAAM,MAAM,EAC1C,WAAY,EAAM,UACpB,CAAC,EACD,MAAO,EAAO,QAAQ,IACpB,EAAkB,CAChB,SACA,QAAS,CAAC,GAAG,EAAM,QAAS,GAAI,IAAc,GAAK,CAAC,EAAI,QAAQ,KAAK,MAAM,EAAY,CAAC,CAAE,EAC1F,SAAU,EAAM,SAChB,QAAS,EAAO,eAAe,EAAM,OAAO,EAC5C,KAAM,EAAM,KACZ,MAAO,EAAO,eAAe,EAAM,KAAK,EACxC,MAAO,EAAO,eAAe,EAAM,KAAK,EACxC,OAAQ,EAAM,OACd,KAAM,CAAC,GAAG,EAAM,IAAI,EACpB,MAAO,EAAO,eAAe,EAAM,KAAK,EACxC,SAAU,EAAM,SAChB,KAAM,EAAM,MAAQ,EAAM,IAC5B,CAAC,CACH,EACD,CACH", | ||
| "debugId": "7CDD744CD63842B364756E2164756E21", | ||
| "names": [] | ||
| } |
Sorry, the diff of this file is not supported yet