// Package pi is the Pi harness (connectors spec 2026-11-12, §3 and §4.1, // slice S2): the pinned Pi package tree and Node, Equipo's own Pi // extension, the isolated configuration, the RPC client and the decoder // that turns Pi's events into Equipo's kinds. package pi import ( "embed" "encoding/json" "amadan.net/oficina/equipo/internal/runner/provider" ) // The pinned Pi (connectors spec §4.1): npm's @earendil-works package // (the @mariozechner one is deprecated), with the integrity npm // published for it. The lockfile pins every package it brings. const ( PackageName = "@earendil-works/pi-coding-agent" Version = "1.5.2" Integrity = "sha512-mUWI04rqF1Vd/m1q+Ps1XeWsTXEVvRUnsmRa83I3Dzua0Tx5bYS93imeqtIfrXf7PkkaR6ERz+AuQhIJlom5yA==" // NodeVersion is the pinned Node Pi runs on (Pi needs 22.19 or // later); the Mac runner's srt runs on the same release. NodeVersion = "v22.23.4" // CLI is Pi's entry point inside the tree (package.json bin "pi"). CLI = "@earendil-works/pi-coding-agent/dist/bundle/cli.js" ) // NodeArchive is the official Node release archive for one platform: // the archive's SHA-256 as nodejs.org publishes it (SHASUMS256.txt), and // the node program's own SHA-256 inside it. type NodeArchive struct { Version, URL, SHA256, Root, BinarySHA256 string } // treeSHA256 is the committed digest of the installed node_modules tree // (TreeSHA256 after Seal), per platform. Pi 1.5.2's tree has no // platform-specific package (its native terminal modules ship every // platform's build), so linux/amd64 (the runner) and linux/arm64 (CI) // install the same tree. var treeSHA256 = map[string]string{ "amd64": "d0ce14faa1c7442ee2cc5289b350f7a56b2bddbdf7d7c1675331de37c6cbc534", "arm64": "d0ce14faa1c7442ee2cc5289b350f7a56b2bddbdf7d7c1675331de37c6cbc534", } // nodeArchives are Node v22.23.4 for Linux. var nodeArchives = map[string]NodeArchive{ "amd64": {Version: NodeVersion, URL: "https://nodejs.org/dist/v22.23.4/node-v22.23.4-linux-x64.tar.gz", SHA256: "b8492284c76a54baf58d61668dd0e41ee0fc98adabf9503d30f05d08f55b4406", Root: "node-v22.23.4-linux-x64", BinarySHA256: "94efd062ed066c1a0b332e18249859c905e920eeada5df55d24c99b919629a90"}, "arm64": {Version: NodeVersion, URL: "https://nodejs.org/dist/v22.23.4/node-v22.23.4-linux-arm64.tar.gz", SHA256: "f7a1e486dbc8b286847815b477d4fb5e9fb963ed4489c3e1588853d685f589f9", Root: "node-v22.23.4-linux-arm64", BinarySHA256: "7e48183361053f039294fbbc3ba586722fe756bf296d6cb8195356d10819cd16"}, } // Pins are the committed tree digest and the Node archive for goarch. // ok is false where Pi is not supported. func Pins(goarch string) (tree string, node NodeArchive, ok bool) { tree, ok = treeSHA256[goarch] if !ok { return "", NodeArchive{}, false } return tree, nodeArchives[goarch], true } //go:embed npm/package.json npm/package-lock.json var npmFiles embed.FS // Package is the package.json and package-lock.json an install writes // into the Pi prefix before `npm ci --ignore-scripts`. func Package() (pkg, lock []byte) { pkg, _ = npmFiles.ReadFile("npm/package.json") lock, _ = npmFiles.ReadFile("npm/package-lock.json") return pkg, lock } // Pinned reports whether the lockfile pins Pi at Version with Integrity. func Pinned() bool { _, lock := Package() var l struct { Packages map[string]struct{ Version, Integrity string } `json:"packages"` } if json.Unmarshal(lock, &l) != nil { return false } p := l.Packages["node_modules/"+PackageName] return p.Version == Version && p.Integrity == Integrity } // ErrUnpinned: the Pi tree or Node is not where the install put it, is // writable, or does not match its pin. var ErrUnpinned = provider.ErrTree // Seal makes an installed tree read-only (provider.SealTree). func Seal(dir string) error { return provider.SealTree(dir) } // TreeSHA256 names an installed tree (provider.TreeSHA256). func TreeSHA256(dir string) (string, error) { return provider.TreeSHA256(dir) }