/** * Which `opencode` is OpenCode 1.x and which is OpenCode V2 (Issue #2939). * * ## Why the name is not enough * * OpenCode V2's npm package `@opencode/cli` (2.0.18) registers **both** * `opencode` and `opencode2` in its `bin`. So on a machine that has it, * `opencode` may be OpenCode 1.x (its own installer, `~/.opencode/bin`) or * OpenCode V2 (`/opt/homebrew/bin/opencode`), decided by nothing but the order * of `PATH`. Asking `which opencode` then answers "OpenCode is installed" for a * V2 binary, and the v1 launch line (`opencode --port N --hostname …`) reaches * a program that has neither flag. * * The answer here is the version each candidate prints about itself: * * - OpenCode 1.x prints a bare `1.18.33`; * - OpenCode V2 prints `opencode v2.0.18`. * * Every `opencode` / `opencode2` on `PATH` is a candidate, not just the first, * so a V2 `opencode` earlier on `PATH` no longer hides a 1.x one behind it. * * ## Probe and launch are one measurement * * The path that answered is the path the launch line runs — the rule * `./copilot-executable` set for copilot (#1907). The server resolves names on * its own `PATH`, the pane on its login shell's; typing a bare `opencode` would * let the two disagree. * * ## Cost * * `opencode --version` takes ~0.4 s and both tools probe `opencode`, so one * probe per path is shared for {@link OPENCODE_EXECUTABLE_CACHE_TTL_MS}, and a * concurrent caller gets the probe already in flight. * * @module lib/cli-tools/opencode-executable */ /** OpenCode 1.x's executable name (tool id `opencode`). */ export declare const OPENCODE_V1_BINARY_NAME = "opencode"; /** OpenCode V2's own executable name (tool id `opencode-v2`). */ export declare const OPENCODE_V2_BINARY_NAME = "opencode2"; /** Budget for one `--version`. */ export declare const OPENCODE_VERSION_PROBE_TIMEOUT_MS = 5000; /** How long one probe result is reused (same TTL as the installed-agents cache). */ export declare const OPENCODE_EXECUTABLE_CACHE_TTL_MS = 30000; /** Which OpenCode a binary is. */ export type OpencodeGeneration = 'v1' | 'v2'; /** What `--version` said, when it said something recognisable. */ export interface OpencodeVersionInfo { readonly generation: OpencodeGeneration; /** `major.minor.patch` (plus any pre-release suffix). */ readonly version: string; } /** * Classify `opencode --version` / `opencode2 --version` output. * * A line has to be a version in one of the two forms and nothing else, so a * different program that happens to print a number is not taken for either. * The major version decides: 1 is OpenCode 1.x, 2 or later is OpenCode V2. * `0.x` (the pre-1.0 `opencode`) and anything unreadable are null. * * @returns The generation and version, or null when the output is not OpenCode's */ export declare function parseOpencodeVersionOutput(output: string): OpencodeVersionInfo | null; /** One candidate and what it answered (null: no recognisable answer). */ export interface OpencodeProbe { readonly path: string; readonly info: OpencodeVersionInfo | null; } /** The binary a tool will run. */ export interface OpencodeExecutable { /** Absolute path, as found on `PATH` — the launch line runs exactly this. */ readonly path: string; readonly version: string; readonly generation: OpencodeGeneration; } /** A resolution: what was chosen, and every candidate asked on the way. */ export interface OpencodeResolution { readonly executable: OpencodeExecutable | null; readonly probed: readonly OpencodeProbe[]; } /** Forget every cached probe (tests, and a caller that knows the install changed). */ export declare function clearOpencodeExecutableCache(): void; /** ` --version`, classified; cached per path. Never rejects. */ export declare function probeOpencodeExecutable(path: string): Promise; /** * OpenCode 1.x: the first `opencode` on `PATH` that prints a 1.x version. * An `opencode` that answers `opencode v2.x` is skipped, never launched. */ export declare function resolveOpencodeV1Executable(): Promise; /** * OpenCode V2: `opencode2` first, then an `opencode` that prints * `opencode v2.x` — for an operator who has V2 only under the `opencode` name. */ export declare function resolveOpencodeV2Executable(): Promise; /** * Why OpenCode 1.x counts as not installed, when there is more to say than * "no `opencode` on PATH". * * @returns A sentence naming the `opencode` that is there and what it is, or * null when nothing called `opencode` was found at all */ export declare function describeOpencodeV1Unavailable(resolution: OpencodeResolution): string | null; //# sourceMappingURL=opencode-executable.d.ts.map