Official
opencode-v2
OpenCode 2 agent provider: runs opencode serve (2.x) and talks to its /api over HTTP and server-sent events.
The app opens the listing; nothing installs until an agent in your Plugins workspace has read the files and you enable the plugin. In a terminal: dvg install divergence/opencode-v2@0.1.5
Permissions in 0.1.5
Files
maintenance.ts1.8 KB
// Whether the OpenCode 2 binary is out of date, and how to update it.
//
// OpenCode 2 updates itself: `opencode upgrade` finds the method it was
// installed with (its install script, npm, Homebrew and others) and uses
// it, so the plugin never has to prove the owner. The newest version is the
// npm package's, which every method ships.
import * as Effect from "effect/Effect";
import type { AgentMaintenance } from "divergence/protocol";
import { runProcess } from "../sdk/effect.ts";
import { isNewer, latestNpmEffect, LOOKUP_TIMEOUT } from "../sdk/maintenance.ts";
/// The npm package that ships OpenCode 2.
export const NPM_PACKAGE = "@opencode/cli";
/// `2.1.1` out of `opencode v2.1.1`, `null` when the line has no version.
export function versionIn(line: string): string | null {
return /\d+\.\d+\.\d+[^\s]*/.exec(line)?.[0] ?? null;
}
/// The maintenance block of `AgentInfo` for the binary `program`.
export const describe = Effect.fn("OpenCodeV2.describe")(function* (program: string) {
const ran = yield* runProcess(program, ["--version"], { timeout: LOOKUP_TIMEOUT }).pipe(
Effect.scoped,
Effect.catch(() => Effect.succeed(null)),
);
const installed = ran ? versionIn(ran.stdout) : null;
const out: AgentMaintenance = { manager: "native", canUpdate: true };
if (!installed) return out;
out.installedVersion = installed;
const latest = yield* latestNpmEffect(NPM_PACKAGE, null);
if (latest && isNewer(installed, latest)) out.latestVersion = latest;
return out;
});
/// Runs `program upgrade`.
export const upgrade = Effect.fn("OpenCodeV2.upgrade")(function* (program: string) {
const result = yield* runProcess(program, ["upgrade"]).pipe(Effect.scoped);
if (result.code !== 0)
return yield* Effect.fail(
new Error(`${program} upgrade failed: ${(result.stderr || result.stdout).trim() || result.code}`),
);
});
No comments yet.