// Package opencode is the OpenCode harness (connectors spec 2026-11-12, // §3 and §4.2, slice S5): the pinned OpenCode v2 package and its // platform binary, the isolated configuration, the Agent Client Protocol // client that drives `opencode acp` over the namespace's stdio, and the // decoder that turns its updates into Equipo's kinds. package opencode import ( "embed" "encoding/json" "amadan.net/oficina/equipo/internal/runner/provider" ) // The pinned OpenCode (connectors spec §4.2): npm's @opencode/cli v2 with // the integrity npm published for it. Its binary ships in a per-platform // package (an optional dependency its postinstall script would copy into // place); the installer fetches this platform's package itself, checked // against the committed lockfile's integrity, and runs no script. const ( PackageName = "@opencode/cli" Version = "2.2.7" Integrity = "sha512-qsSExDfpUCqhGXBqZ8xhjg2OG9DxnsnfWl1/7vGINRWw7sxZvK9cXeW6MI8j9e+GItaYtg94zH3Eo2ng86VLCg==" ) // Platform is one supported platform's binary package: its name in the // lockfile and the SHA-256 of its bin/opencode. type Platform struct { Package, BinarySHA256 string } // platforms are the glibc builds for Linux (the runner is amd64, CI's // boxes arm64). The x64 build needs AVX2; the baseline and musl builds // are not supported. var platforms = map[string]Platform{ "amd64": {Package: "@opencode/cli-linux-x64", BinarySHA256: "589253d36810f21217edd51545cd435b328cdc3cf4f451fbe0cce6f88afcf5e1"}, "arm64": {Package: "@opencode/cli-linux-arm64", BinarySHA256: "c577783eacf7d1e66661fc7fd904b7646761497b687ff8f8f82ebe4f2f3ea425"}, } // treeSHA256 is the committed digest of the installed node_modules tree // (provider.TreeSHA256 after the seal), per platform: @opencode/cli and // this platform's binary package, nothing else. var treeSHA256 = map[string]string{ "amd64": "0a36384b35ce78bda86ee1cf5e5e8d67e46639a2dc610d316648bf0fc6f5ba08", "arm64": "921289af48f7e6a5b6764a20ae35d6a3d42a39a70c2bd0755089088b6bbc1c03", } // Pins are the committed tree digest and the binary package for goarch. // ok is false where OpenCode is not supported. func Pins(goarch string) (tree string, platform Platform, ok bool) { platform, ok = platforms[goarch] if !ok || treeSHA256[goarch] == "" { return "", Platform{}, false } return treeSHA256[goarch], platform, true } //go:embed npm/package.json npm/package-lock.json var npmFiles embed.FS // Package is the committed package.json and package-lock.json. func Package() (pkg, lock []byte) { pkg, _ = npmFiles.ReadFile("npm/package.json") lock, _ = npmFiles.ReadFile("npm/package-lock.json") return pkg, lock } // Locked is one lockfile entry: where npm resolved it and its integrity. type Locked struct { Version, Resolved, Integrity string } // lockfile reads the committed lockfile's packages. func lockfile() map[string]Locked { _, lock := Package() var l struct { Packages map[string]Locked `json:"packages"` } if json.Unmarshal(lock, &l) != nil { return nil } return l.Packages } // Lock is a package's entry in the committed lockfile. func Lock(name string) (Locked, bool) { p, ok := lockfile()["node_modules/"+name] return p, ok && p.Version == Version && p.Resolved != "" && len(p.Integrity) > len("sha512-") } // Pinned reports whether the lockfile pins OpenCode at Version with // Integrity. func Pinned() bool { p, ok := Lock(PackageName) return ok && p.Integrity == Integrity } // ErrUnpinned: the tree or the binary is not where the install put it, // is writable, or does not match its pin. var ErrUnpinned = provider.ErrTree