@phren/cli
Version:
Knowledge layer for AI agents - CLI, MCP server, and data layer
75 lines (74 loc) • 4.53 kB
TypeScript
import { type PaneClient, type PaneServerEntry } from "./opencode-pane-server.js";
import { type Json } from "./protocol.js";
export interface OpencodeService {
url: URL;
port: number;
password: string;
pid: number;
version: string;
authorization: string;
}
/** The running service, from the state file it writes itself. Only a loopback
* http address, and only version 2 or later (1.x has no service). */
export declare function opencodeService(): Promise<OpencodeService | undefined>;
/** `--session <id>` / `-s <id>` on an `opencode` command line: the
* conversation the TUI was started on (the Hook starts its own panes so). */
export declare function commandSession(command: string): string | undefined;
/** The conversation an OpenCode 2 pane shows. Its TUI puts the session's title
* in the terminal title ("OC | <title>", cut to 37 characters and an ellipsis
* past 40), and plain "OpenCode" until a session has a title of its own. One
* session with that title in the pane's folder is the pane's; when the title
* names none or several, the session the TUI was started on (`--session`)
* decides, if it is one of them or the pane has no title yet. Otherwise the
* pane stays without a conversation. */
export declare function opencodeServiceSession(server: string, pane: Json, commands?: () => Promise<string[]>): Promise<string | undefined>;
/** The pane's entry in the shape a served 1.x pane has, when the Hook last
* saw it showing a conversation of the running service. */
export declare function servicePane(server: string, pane: string): PaneServerEntry | undefined;
export declare function servicePanes(): PaneServerEntry[];
/** For tests: forget every pane and the service. */
export declare function resetOpencodeService(): void;
/** The installed OpenCode's major version: the running service's, else what
* `opencode --version` prints (asked at most once in five minutes). */
export declare function opencodeMajor(): Promise<number | undefined>;
/** The running service, started first (`opencode service start`) when OpenCode 2 is installed and none runs. */
export declare function ensureOpencodeService(timeoutMs?: number): Promise<OpencodeService | undefined>;
export interface ServiceLaunch {
args: string[];
model?: string;
agent?: string;
variant?: string;
}
/** A 1.x launch's arguments for OpenCode 2, whose TUI takes no `--model`,
* `--agent` or `--variant`: those become the new conversation's own settings. */
export declare function serviceLaunchArgs(args: readonly string[]): ServiceLaunch;
/** A new conversation in `directory` for a pane the Hook is about to start on
* it (`opencode --session <id>`), with the launch's agent and model. */
export declare function createServiceSession(live: OpencodeService, directory: string, launch?: Omit<ServiceLaunch, "args">): Promise<string>;
/** Records that the pane the Hook just started shows `session`, before its
* terminal title can say so. */
export declare function bindServicePane(server: string, pane: string, session: string, directory: string): PaneServerEntry | undefined;
/** A `PaneClient` over the service, for one pane's folder and conversation. */
export declare function openServiceClient(entry: PaneServerEntry, fetchImpl?: typeof fetch): PaneClient;
/** When the conversation last went to work and last came to rest, as the 1.x
* plugin stamped a process's turns. */
export declare function opencodeServiceStamps(id: string): Promise<{
session: string;
at: string;
busyAt?: string;
idleAt?: string;
} | undefined>;
/** Whether the conversation is at work, from the same stamps. */
export declare function opencodeServiceStatus(id: string): Promise<"working" | "idle" | undefined>;
/** Sets the model the conversation's next turns use and returns what the service now holds. */
export declare function switchOpencodeModel(entry: PaneServerEntry, id: string, variant?: string): Promise<{
id: string;
variant?: string;
}>;
export declare function opencodeSessionsRoot(): string;
/** Brings a session's event log up to date with the service and returns the
* file, or undefined when the service does not know the session. Safe to call
* often: an idle, unchanged session costs one small request. A working
* session rereads its newest pages; a turn's end rereads it whole, so
* messages OpenCode removed (a revert, a compaction) leave the log too. */
export declare function materializeOpencodeSession(session: string): Promise<string | undefined>;