Skip to content

A desktop coding agent with free access to frontier models.

TypeScript
2.4 KB
Raw Blame
import constants from "../../../constants.json" with { type: "json" };

/**
 * Which engine and harness produced an upload. The same field names and
 * values as the CLI's uploads, so every delivery can say what ran a session:
 * `environment.engine_version` ("opencode/1.18.32-r2"), `environment.harness`
 * and `environment.app_version`.
 */
export type HarnessName = "opencode" | "pi";
export type HarnessEngine = "omnirush-opencode" | "omnirush-core";

export type Harness = {
  name: HarnessName;
  engine: HarnessEngine;
  /** The engine build's version, with its release suffix ("1.18.32-r2"). */
  version: string;
  /** The engine release it came from ("engine-1.18.32-r2"). */
  build_tag: string;
  /** A 2.x engine: its uploads hold its own message shape, unrenamed (the CLI sends the same). */
  engine_schema?: "opencode-v2";
};

const RELEASE_TAG_PREFIX = "engine-";

/** "engine-1.18.32-r2" -> "1.18.32-r2"; a bare version without the tag. */
export function engineBuildVersion(buildTag: string, fallbackVersion: string): string {
  const tag = buildTag.trim();
  if (tag.startsWith(RELEASE_TAG_PREFIX) && tag.length > RELEASE_TAG_PREFIX.length) return tag.slice(RELEASE_TAG_PREFIX.length);
  return fallbackVersion.trim().replace(/^v/, "");
}

/** The desktop's engine: OmniRush.ai's opencode build (apps/desktop/scripts/engine-v2-release.json). */
export function opencodeHarness(buildTag: string, fallbackVersion: string): Harness {
  const version = engineBuildVersion(buildTag, fallbackVersion) || "unknown";
  return {
    name: "opencode",
    engine: "omnirush-opencode",
    version,
    build_tag: buildTag.trim() || `${RELEASE_TAG_PREFIX}${version}`,
    ...(Number(version.split(".")[0]) >= 2 ? { engine_schema: "opencode-v2" as const } : {}),
  };
}

/** `engine_version` for a harness: "<name>/<version>". */
export function engineVersionOf(harness: Harness): string {
  return `${harness.name}/${harness.version}`;
}

const bundled = constants as { opencodeV2Version?: string; engineV2ReleaseTag?: string };

/** The engine every chat runs on: the bundled 2.x engine (apps/desktop/scripts/engine-v2-release.json). */
export const BUNDLED_HARNESS: Harness = Object.freeze(
  opencodeHarness(bundled.engineV2ReleaseTag ?? "", bundled.opencodeV2Version ?? ""),
) as Harness;

/** `engine_version` of the bundled engine ("opencode/1.18.32-r2"). */
export const BUNDLED_ENGINE_VERSION = engineVersionOf(BUNDLED_HARNESS);