diff --git a/.claude-plugin/marketplace.json b/.claude-plugin/marketplace.json index 9e07b44..8cc626a 100644 --- a/.claude-plugin/marketplace.json +++ b/.claude-plugin/marketplace.json @@ -10,7 +10,7 @@ "name": "t3-pstack", "source": "./plugins/pstack", "description": "pstack for T3 Code: rigorous agent workflows whose panels and fan-outs run across model families through T3. Original pstack by Lauren Tan (poteto).", - "version": "2.2.4" + "version": "2.2.5" } ] } diff --git a/CHANGES.md b/CHANGES.md index c9f0518..5dcb82e 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,22 @@ This file is the release changelog, with one `## - ` entry per release, newest first. The Cursor-to-T3 rewrite rules live in [`tools/substitutions.json`](tools/substitutions.json), and the [sync boundary](CONTRIBUTING.md#the-sync-boundary) in `CONTRIBUTING.md` defines how a change to upstream's skill content is declared. +## 2.2.5 - The installer pins each Codex home to the release tag, so Codex's own updates no longer turn the hook off + +On Codex 0.164 and later, a plugin hook's trust covers every file in the installed plugin, as 2.2.3 described. Each time a Codex app-server starts, such as the one T3 runs, Codex's marketplace auto-upgrade moved each home's `t3-pstack` marketplace to the latest commit on `main` and reinstalled the plugin from it. So each release, and each other commit that changed the plugin's files, turned the session-start hook off with `plugin contents changed; hook approval required` until someone reran the installer. 2.2.3 left this as it was. + +`install` and `update` now pin each Codex home's `t3-pstack` marketplace to this release's tag. In that home's `config.toml`, the `[marketplaces.t3-pstack]` table gets one more line, `ref = "v2.2.5"`, and its `source` stays as it was. Codex's auto-upgrade fetches again only when the hash that `git ls-remote` reports for the configured ref differs from the commit it installed. For a lightweight tag, which every t3-pstack release tag is, the two stay equal, so it leaves the home where it is. A release reaches a Codex home only when `update` runs, and that run trusts the hook again. A home pinned to an earlier tag moves to this one. `codex plugin marketplace add --ref` refuses a marketplace that is already added, so the installer writes the ref through the Codex app-server's config writer, as it writes the hook's trust, and then runs `codex plugin marketplace upgrade t3-pstack`, which fetches the tag and reinstalls the plugin from it. When Codex cannot fetch the tag, as from a fork that never pushed it, or from `main` before the release is tagged, the installer writes the old ref back, updates the home as before, and says so. `doctor` then fails the home's pin, and each run exits 1, until the source has the tag. A marketplace from a local directory has no tag and stays unpinned. Claude Code homes do not change. + +`doctor` has a new Codex check, `marketplace pin`. It fails a home that is unpinned or pinned to another tag, as in `marketplace pin: none, expected v2.2.5`, and its fix reruns the installer with the run's `--source`. On a local directory it passes with `none, since a local directory has no tag`. + +To follow `main` again, delete the `ref` line from `[marketplaces.t3-pstack]` in that home's `config.toml`. Codex then moves the home to the latest commit on `main` at its next start. The next `install` or `update` pins it again, and `doctor` fails it until then. A ref set by hand, such as `main`, is replaced the same way. + +In throwaway homes on macOS with Codex 0.167.0, a repository in the test folder served as `https://github.com/chhoumann/t3-pstack.git` through the global Git config. With 2.2.3's installer, a home set up from the default source moved from 2.2.3 to a newer commit on `main` at 9.9.9, through `codex plugin marketplace upgrade` and through a bare app-server start within 0.8 seconds, and its hook read `modified` both times. With this release's installer, the same home read `ref = "v2.2.5"`. `codex plugin marketplace upgrade` printed `All configured Git marketplaces are already up to date.`, an app-server ran for 20 seconds without moving it, the hook stayed trusted, and `doctor` passed. A new end-to-end suite runs these checks from the default source, a GitHub `--source`, a Git URL `--source`, and a local directory, with homes that Codex's own CLI set up unpinned and pinned to an older tag, a source without the tag, and a second run that changes nothing. Against 2.2.3's `codex.mjs` all 5 of its tests fail. On macOS with Codex 0.167.0, Claude Code 2.1.319, and Bun 1.4.4, the installer's end-to-end test passes 18 of 18, and `GIT_CONFIG_GLOBAL=/dev/null bun test tests/` passes 554, skips 56, and fails 0. + +Users who do nothing keep today's behaviour. Run `npx -y github:chhoumann/t3-pstack update` to pin each Codex home. Neither hooks file changes. This is a patch release. + +Thanks to @rma1k0 for the report and its evidence ([#56](https://github.com/chhoumann/t3-pstack/issues/56)). + ## 2.2.4 - poteto-mode runs interrogate only for a contested design, as Lauren's pstack does poteto-mode no longer runs `interrogate` before every pull request. Since 1.0.1 it sent each bug fix, feature, or refactoring diff to the `interrogate reviewers` panel before Opening a PR, and 1.0.6 added a review loop to that gate: later rounds reviewed only the fix diff, a `feature, refactoring` delegate ran the real artifact after each fix round, and the loop stopped after three rounds. The gate was always the port's own addition and never Lauren's text. Through 1.0.14 it lived in the port's `t3-tools.md`, and from 2.0.0-rc.1 it was an anchored insert in `tools/substitutions.json` after Lauren's contested-design trigger. At `c742dd6` Lauren's poteto-mode runs `interrogate` only for a contested design, and the Feature playbook's step 7 says "If the design is contested, `interrogate` before shipping." So in a T3 session every bug fix, feature, and refactoring ran a multi-model adversarial panel that Lauren's pstack saves for a contested design ([#65](https://github.com/chhoumann/t3-pstack/issues/65)). diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c564b9c..fcb6ad8 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -95,7 +95,7 @@ Dependabot keeps the pinned action SHAs current. The vendored scripts' one runti Plugin auto-update installs **by version number**, not by tracking `main`. A skill fix merged without a version bump is inert on every installed copy. The bump is three steps: edit the root `VERSION` file, add a `CHANGES.md` entry under a `## <version> - <title>` heading, and run `bun tools/generate.mjs` to stamp the manifests. Forgetting any of the three fails CI. -Versions follow semantic versioning, and each sync of Lauren's pstack is its own release. A patch release (2.0.1) carries fixes and reworded text, whether Lauren's or the port's. A minor release (2.1.0) adds a skill, a capability, or a harness. A major release (3.0.0) is for a change the user must act on, such as rerunning the installer or editing the model sheet. When a release spans more than one kind, the largest wins. The `CHANGES.md` entry of a sync names the pstack version it moves to. Each release gets a `v<version>` tag and a GitHub release whose notes are its `CHANGES.md` entry. +Versions follow semantic versioning, and each sync of Lauren's pstack is its own release. A patch release (2.0.1) carries fixes and reworded text, whether Lauren's or the port's. A minor release (2.1.0) adds a skill, a capability, or a harness. A major release (3.0.0) is for a change the user must act on, such as rerunning the installer or editing the model sheet. When a release spans more than one kind, the largest wins. The `CHANGES.md` entry of a sync names the pstack version it moves to. Each release gets a `v<version>` tag and a GitHub release whose notes are its `CHANGES.md` entry. Make the tag a lightweight one, as `git tag v<version>` makes without `-a`, `-s`, or `tag.gpgSign`, and push it as soon as the release merges. The installer pins each Codex home's marketplace to it, and until it exists, `update` leaves each Codex home on the ref it had. Codex compares the hash that `git ls-remote` reports for the tag with the commit it installed, and for an annotated tag they never match, so every Codex start would clone the marketplace and reinstall the plugin again. ## Commit and PR style diff --git a/README.md b/README.md index 0e390eb..437ccc8 100644 --- a/README.md +++ b/README.md @@ -14,11 +14,11 @@ npx -y github:chhoumann/t3-pstack update npx -y github:chhoumann/t3-pstack doctor ``` -`npx -y github:chhoumann/t3-pstack` runs the installer from the latest commit on `main`. That is the rolling channel, the same one each home's marketplace auto-updates from. To run one release's installer, name its tag, as in `npx -y github:chhoumann/t3-pstack#v2.2.4 doctor`. +`npx -y github:chhoumann/t3-pstack` runs the installer from the latest commit on `main`. Each Claude Code home's marketplace auto-updates from `main` too, and each Codex home's marketplace stays on the release tag the installer pinned. To run one release's installer, name its tag, as in `npx -y github:chhoumann/t3-pstack#v2.2.5 doctor`. -`install` and `update` are the same command, and a second run changes nothing. With Node 20 or later, it installs or updates the `t3-pstack@t3-pstack` plugin in every Claude Code and Codex config home T3 can run: `~/.claude` and `~/.codex`, `$CLAUDE_CONFIG_DIR` and `$CODEX_HOME`, and the home of each `claudeAgent` and `codex` instance in T3's settings, disabled ones included. Name any other home with `--claude-home <dir>` or `--codex-home <dir>`. Each home's `t3-pstack` marketplace must come from `chhoumann/t3-pstack`, or from `--source <owner/repo|git URL|dir>` on the same run, and a home whose marketplace has another source is left as it is. A run never switches a home's source, so a home already on `chhoumann/t3-pstack` stays on it under another `--source`, and `doctor` warns and prints the commands that move it. A local directory needs a path such as `./t3-pstack`, since `owner/repo` always means GitHub. On Codex it also trusts t3-pstack's session-start hook, once its hooks file is the one this release pins. Codex runs a plugin's hook only once it is trusted, and T3's Codex sessions never ask, so without this step the hook never runs. Codex 0.164 and later tie that trust to every file in the installed plugin, so each release turns the hook off, even one Codex's own auto-update installs, until `update` runs again. Run `update` after each release. +`install` and `update` are the same command, and a second run changes nothing. With Node 20 or later, it installs or updates the `t3-pstack@t3-pstack` plugin in every Claude Code and Codex config home T3 can run: `~/.claude` and `~/.codex`, `$CLAUDE_CONFIG_DIR` and `$CODEX_HOME`, and the home of each `claudeAgent` and `codex` instance in T3's settings, disabled ones included. Name any other home with `--claude-home <dir>` or `--codex-home <dir>`. Each home's `t3-pstack` marketplace must come from `chhoumann/t3-pstack`, or from `--source <owner/repo|git URL|dir>` on the same run, and a home whose marketplace has another source is left as it is. A run never switches a home's source, so a home already on `chhoumann/t3-pstack` stays on it under another `--source`, and `doctor` warns and prints the commands that move it. A local directory needs a path such as `./t3-pstack`, since `owner/repo` always means GitHub. On Codex it also trusts t3-pstack's session-start hook, once its hooks file is the one this release pins. Codex runs a plugin's hook only once it is trusted, and T3's Codex sessions never ask, so without this step the hook never runs. Codex 0.164 and later tie that trust to every file in the installed plugin, so each release turns the hook off until the installer trusts it again. So the installer pins each Codex home's `t3-pstack` marketplace to the release's tag, such as `v2.2.5`, and Codex's own auto-upgrade leaves that tag where it is. A release reaches a Codex home only when `update` runs, and that run trusts the hook again. A local directory has no tag, so a marketplace from one stays unpinned. Run `update` after each release. -`doctor` reports on the same homes and changes nothing itself: each marketplace's source, the installed version, whether its files are all there, whether it is enabled, the Codex hook's trust, Claude Code records that pin an old version, plain copies of the plugin's skills, and the model sheet. It exits 1 on any problem and prints a fix for each. +`doctor` reports on the same homes and changes nothing itself: each marketplace's source, each Codex marketplace's pin, the installed version, whether its files are all there, whether it is enabled, the Codex hook's trust, Claude Code records that pin an old version, plain copies of the plugin's skills, and the model sheet. It exits 1 on any problem and prints a fix for each. Then run `/t3-pstack:setup-pstack` in a T3 thread on each machine. It writes the model sheet, `~/.config/t3-pstack/models.md`, with one T3 target per role (`<providerInstanceId>/<modelId>` plus that provider's options), and checks it against the machine's `orchestrator_capabilities`. Without a sheet, every role runs on the defaults in its skill's Models section. diff --git a/VERSION b/VERSION index 530cdd9..21bb5e1 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.2.4 +2.2.5 diff --git a/package.json b/package.json index f78a134..179b4c4 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "t3-pstack", "private": true, - "version": "2.2.4", + "version": "2.2.5", "description": "The installer and development tooling for t3-pstack, Lauren Tan's pstack rewritten in place for T3 Code. The plugin itself lives in plugins/pstack.", "author": { "name": "Christian Bager Bach Houmann", diff --git a/plugins/pstack/.claude-plugin/plugin.json b/plugins/pstack/.claude-plugin/plugin.json index 9f2643f..4110d10 100644 --- a/plugins/pstack/.claude-plugin/plugin.json +++ b/plugins/pstack/.claude-plugin/plugin.json @@ -1,7 +1,7 @@ { "name": "t3-pstack", "displayName": "t3-pstack (pstack for T3 Code)", - "version": "2.2.4", + "version": "2.2.5", "description": "pstack for T3 Code: Lauren Tan's pstack with its Cursor mechanics rewritten in place for T3, so subagents, panels, schedules, and PR watches dispatch through T3's orchestration and panels mix Claude, GPT, and Grok.", "author": { "name": "Christian Bager Bach Houmann", diff --git a/plugins/pstack/.codex-plugin/plugin.json b/plugins/pstack/.codex-plugin/plugin.json index ee5f9a5..d814dee 100644 --- a/plugins/pstack/.codex-plugin/plugin.json +++ b/plugins/pstack/.codex-plugin/plugin.json @@ -1,6 +1,6 @@ { "name": "t3-pstack", - "version": "2.2.4", + "version": "2.2.5", "description": "pstack for T3 Code on a Codex host: Lauren Tan's pstack with its Cursor mechanics rewritten in place for T3, so subagents, panels, schedules, and PR watches dispatch through T3's orchestration.", "author": { "name": "Christian Bager Bach Houmann", diff --git a/tests/install-e2e.test.mjs b/tests/install-e2e.test.mjs index cdcf9d5..d6db4be 100644 --- a/tests/install-e2e.test.mjs +++ b/tests/install-e2e.test.mjs @@ -24,7 +24,7 @@ import { delimiter, join, relative } from "node:path"; import { fileURLToPath } from "node:url"; import { AppServer } from "../tools/install/codex.mjs"; -import { resolveCli } from "../tools/install/common.mjs"; +import { HOME_REPO, PLUGIN_ID, resolveCli } from "../tools/install/common.mjs"; import { hookDigest } from "../tools/plugin.mjs"; const repoRoot = fileURLToPath(new URL("..", import.meta.url)); @@ -44,8 +44,8 @@ function sh(bin, args, env = {}) { } // `source` null runs with no --source, as a user does. -function installer(command, source = repoRoot) { - const r = spawnSync("node", [join(repoRoot, "tools/install.mjs"), command, ...(source ? ["--source", source] : []), "--json"], { +function installer(command, source = repoRoot, ...args) { + const r = spawnSync("node", [join(repoRoot, "tools/install.mjs"), command, ...(source ? ["--source", source] : []), ...args, "--json"], { cwd: root, env: process.env, encoding: "utf8", @@ -65,6 +65,8 @@ function pluginCopy(dir) { return dir; } const edit = (path, from, to) => writeFileSync(path, readFileSync(path, "utf8").replace(from, to)); +const MANIFESTS = [".claude-plugin/marketplace.json", "plugins/pstack/.claude-plugin/plugin.json", "plugins/pstack/.codex-plugin/plugin.json"]; +const bump = (dir, from, to) => MANIFESTS.forEach((file) => edit(join(dir, file), `"version": "${from}"`, `"version": "${to}"`)); async function until(done, ms) { for (const deadline = Date.now() + ms; Date.now() < deadline; await new Promise((r) => setTimeout(r, 200))) { @@ -368,10 +370,7 @@ describe.skipIf(!enabled)("the installer, on a release that changes the hook ent expect(installer("install", source).status).toBe(0); const next = "9.9.9"; - for (const file of [".claude-plugin/marketplace.json", "plugins/pstack/.claude-plugin/plugin.json", "plugins/pstack/.codex-plugin/plugin.json"]) { - const path = join(source, file); - writeFileSync(path, readFileSync(path, "utf8").replace(`"version": "${version}"`, `"version": "${next}"`)); - } + bump(source, version, next); const hooks = join(source, "plugins/pstack/hooks/codex-hooks.json"); edit(hooks, "startup|resume|clear|compact", "startup|resume|compact|clear"); @@ -399,6 +398,185 @@ describe.skipIf(!enabled)("the installer, on a release that changes the hook ent }, 300_000); }); +// Git marketplaces, served from repositories in the throwaway root: the global +// Git config sends each source's URL there. `claude` is off PATH, because +// Claude Code fetches a GitHub marketplace without that config and would reach +// github.com. +describe.skipIf(!enabled)("the installer, on Git marketplaces", () => { + isolate({ + codex: { driver: "codex", enabled: true, config: { binaryPath: "codex", homePath: "" } }, + codex_unpinned: { driver: "codex", enabled: true, config: { homePath: "~/.codex-unpinned" } }, + codex_old: { driver: "codex", enabled: true, config: { homePath: "~/.codex-old" } }, + }); + const path = process.env.PATH; + const tag = `v${version}`; + const PINNED = [".codex", ".codex-unpinned", ".codex-old"]; + let origin; + const git = (...args) => sh("git", ["-C", origin, "-c", "user.name=t3-pstack", "-c", "user.email=t3-pstack@example.test", ...args]); + const codex = (dir, ...args) => sh("codex", args, { CODEX_HOME: join(home, dir) }); + const marketplace = (dir) => readFileSync(join(home, dir, "config.toml"), "utf8").match(/\[marketplaces\.t3-pstack\]\n[^[]*/)?.[0].trimEnd(); + const pinned = (source) => `[marketplaces.t3-pstack]\nsource_type = "git"\nsource = "${source}"\nref = "${tag}"`; + const cached = (dir) => readdirSync(join(home, dir, "plugins/cache/t3-pstack/t3-pstack")).filter((name) => !name.startsWith(".")); + const pin = (report, dir) => row(report, dir).checks.find((c) => c.name === "marketplace pin"); + + beforeAll(() => { + const bin = join(root, "bin"); + mkdirSync(bin); + for (const tool of ["codex", "node", "git"]) symlinkSync(resolveCli(tool), join(bin, tool)); + process.env.PATH = [bin, "/usr/bin", "/bin"].join(delimiter); + + origin = pluginCopy(join(root, "origin")); + bump(origin, version, "0.0.1"); + git("init", "-q", "-b", "main"); + git("add", "-A"); + git("commit", "-qm", "0.0.1"); + git("tag", "v0.0.1"); + bump(origin, "0.0.1", version); + git("commit", "-qam", version); + git("tag", tag); + const untagged = join(root, "untagged"); + sh("git", ["clone", "-q", "--no-tags", origin, untagged]); + const urls = [ + [origin, `https://github.com/${HOME_REPO}.git`], + [origin, "https://github.com/someone/t3-pstack.git"], + [origin, "https://git.example.test/t3-pstack.git"], + [untagged, "https://github.com/someone/untagged.git"], + ]; + writeFileSync(join(root, "gitconfig"), urls.map(([dir, url]) => `[url "file://${dir}"]\n\tinsteadOf = ${url}\n`).join("")); + process.env.GIT_CONFIG_GLOBAL = join(root, "gitconfig"); + + // Homes Codex's own CLI set up: one on main, as every earlier release left + // it, and one pinned to an older tag. + for (const [dir, ...ref] of [[".codex-unpinned"], [".codex-old", "--ref", "v0.0.1"]]) { + mkdirSync(join(home, dir), { recursive: true }); + codex(dir, "plugin", "marketplace", "add", HOME_REPO, ...ref); + codex(dir, "plugin", "add", PLUGIN_ID); + } + }); + + afterAll(() => { + process.env.PATH = path; + }); + + test("doctor fails a Codex home that is not pinned to this release's tag", () => { + const { status, report } = installer("doctor", null); + expect(status).toBe(1); + expect(failing(row(report, ".codex-unpinned").checks)).toEqual([ + `marketplace pin: none, expected ${tag}`, + `session-start hook trusted: ${HOOK} untrusted`, + ]); + expect(failing(row(report, ".codex-old").checks)).toEqual([ + `marketplace pin: v0.0.1, expected ${tag}`, + `installed: 0.0.1, expected ${version}`, + `session-start hook trusted: ${HOOK} untrusted`, + ]); + expect(pin(report, ".codex-unpinned").fix).toBe("rerun `npx -y github:chhoumann/t3-pstack install`"); + }, 300_000); + + test("install pins every Codex home to the release tag, and the hook routes", async () => { + const { status, report } = installer("install", null); + console.log("pin:", JSON.stringify(report.homes.map(({ dir, steps }) => ({ dir: relative(home, dir), steps })))); + expect(failing(report.homes.flatMap((h) => h.checks))).toEqual([]); + expect(status).toBe(0); + const trustedHook = `trusted hook ${HOOK} (was untrusted)`; + expect(row(report, ".codex").steps).toEqual([ + `added the t3-pstack marketplace from ${HOME_REPO}`, + `pinned the marketplace to ${tag} (was unpinned)`, + `installed ${version}`, + trustedHook, + ]); + expect(row(report, ".codex-unpinned").steps).toEqual([`pinned the marketplace to ${tag} (was unpinned)`, trustedHook]); + expect(row(report, ".codex-old").steps).toEqual([`pinned the marketplace to ${tag} (was v0.0.1)`, `updated 0.0.1 to ${version}`, trustedHook]); + for (const dir of PINNED) expect(marketplace(dir)).toBe(pinned(`https://github.com/${HOME_REPO}.git`)); + expect(pin(report, ".codex")).toEqual({ name: "marketplace pin", ok: true, detail: tag }); + + const after = await probe(join(home, ".codex")); + expect(after.hookEvents).toEqual(["hook/started", "hook/completed"]); + expect(after.routedMessages).toBe(1); + }, 300_000); + + test("a second install changes nothing", () => { + const before = snapshot(); + const { status, report } = installer("update", null); + expect(status).toBe(0); + expect(report.homes.flatMap((h) => h.steps)).toEqual([]); + expect(snapshot()).toEqual(before); + }, 300_000); + + test("pins a GitHub or Git URL --source too, leaves a local directory unpinned, and leaves a source without the tag as it was", () => { + const run = (source, dir) => installer("install", source, "--codex-home", join(home, dir)); + for (const [source, dir, url] of [ + ["someone/t3-pstack", ".codex-fork", "https://github.com/someone/t3-pstack.git"], + ["https://git.example.test/t3-pstack.git", ".codex-url", "https://git.example.test/t3-pstack.git"], + ]) { + const { status, report } = run(source, dir); + expect(status).toBe(0); + expect(row(report, dir).steps).toEqual([ + `added the t3-pstack marketplace from ${source}`, + `pinned the marketplace to ${tag} (was unpinned)`, + `installed ${version}`, + `trusted hook ${HOOK} (was untrusted)`, + ]); + expect(marketplace(dir)).toBe(pinned(url)); + expect(row(report, ".codex").steps).toEqual([]); + } + + const local = pluginCopy(join(root, "local")); + const fromDir = run(local, ".codex-local"); + expect(fromDir.status).toBe(0); + expect(row(fromDir.report, ".codex-local").steps).toEqual([`added the t3-pstack marketplace from ${local}`, `installed ${version}`, `trusted hook ${HOOK} (was untrusted)`]); + expect(pin(fromDir.report, ".codex-local")).toEqual({ name: "marketplace pin", ok: true, detail: "none, since a local directory has no tag" }); + expect(marketplace(".codex-local")).toBe(`[marketplaces.t3-pstack]\nsource_type = "local"\nsource = "${local}"`); + + const untagged = run("someone/untagged", ".codex-untagged"); + expect(untagged.status).toBe(1); + const steps = row(untagged.report, ".codex-untagged").steps; + expect(steps[1]).toStartWith(`Codex could not fetch ${tag}, so the marketplace stays unpinned (`); + expect(steps.filter((_, i) => i !== 1)).toEqual([ + "added the t3-pstack marketplace from someone/untagged", + `installed ${version}`, + `trusted hook ${HOOK} (was untrusted)`, + ]); + expect(failing(row(untagged.report, ".codex-untagged").checks)).toEqual([`marketplace pin: none, expected ${tag}`]); + expect(marketplace(".codex-untagged")).toBe('[marketplaces.t3-pstack]\nsource_type = "git"\nsource = "https://github.com/someone/untagged.git"'); + }, 300_000); + + test("a newer commit on main reaches only a home without the pin, through Codex's own upgrade", async () => { + // As every earlier release left a home: the hook trusted, the marketplace on main. + edit(join(home, ".codex-unpinned/config.toml"), `ref = "${tag}"\n`, ""); + bump(origin, version, "9.9.9"); + git("commit", "-qam", "9.9.9"); + + for (const dir of PINNED) codex(dir, "plugin", "marketplace", "upgrade"); + for (const dir of [".codex", ".codex-old"]) { + // Each app-server start also runs Codex's background marketplace upgrade. + const after = await probe(join(home, dir)); + expect(after.hookEvents).toEqual(["hook/started", "hook/completed"]); + expect(after.routedMessages).toBe(1); + expect(cached(dir)).toEqual([version]); + } + expect(cached(".codex-unpinned")).toEqual(["9.9.9"]); + + const doctor = installer("doctor", null); + expect(doctor.status).toBe(1); + expect(failing(doctor.report.homes.flatMap((h) => h.checks))).toEqual([ + `marketplace pin: none, expected ${tag}`, + `installed: 9.9.9, expected ${version}`, + `session-start hook trusted: ${HOOK} modified`, + ]); + + const { status, report } = installer("update", null); + expect(status).toBe(0); + expect(row(report, ".codex-unpinned").steps).toEqual([ + `pinned the marketplace to ${tag} (was unpinned)`, + `updated 9.9.9 to ${version}`, + ]); + expect(row(report, ".codex").steps).toEqual([]); + const after = await probe(join(home, ".codex-unpinned")); + expect(after.routedMessages).toBe(1); + }, 300_000); +}); + describe.skipIf(!enabled)("the installer, on a Codex home that changes while it trusts the hook", () => { isolate({}); const path = process.env.PATH; diff --git a/tests/install.test.mjs b/tests/install.test.mjs index 24aeb52..c1ab719 100644 --- a/tests/install.test.mjs +++ b/tests/install.test.mjs @@ -24,7 +24,7 @@ import { join, resolve } from "node:path"; import { fileURLToPath } from "node:url"; import { doctorClaude, installClaude, syncScopedRecords } from "../tools/install/claude.mjs"; -import { AppServer } from "../tools/install/codex.mjs"; +import { AppServer, pinCheck } from "../tools/install/codex.mjs"; import { parseSource, writeAtomic } from "../tools/install/common.mjs"; import { discoverHomes } from "../tools/install/homes.mjs"; import { doctorSheet, moveSheet } from "../tools/install/sheet.mjs"; @@ -419,6 +419,27 @@ describe("codex app-server output that is not JSON-RPC", () => { }); }); +describe("doctor's check of a Codex marketplace's pin", () => { + test("passes on this release's tag, and on a local directory, which has no tag", () => { + const git = { source_type: "git", source: "https://github.com/chhoumann/t3-pstack.git" }; + const pin = (marketplace) => pinCheck(marketplace, "v2.2.5", FIX); + expect(pin({ ...git, ref: "v2.2.5" })).toEqual({ name: "marketplace pin", ok: true, detail: "v2.2.5" }); + expect(pin({ source_type: "local", source: "/src/t3-pstack" })).toEqual({ + name: "marketplace pin", + ok: true, + detail: "none, since a local directory has no tag", + }); + expect([git, { ...git, ref: "v2.2.3" }, { ...git, ref: "main" }, undefined].map(pin)).toEqual( + ["none, expected v2.2.5", "v2.2.3, expected v2.2.5", "main, expected v2.2.5", "no marketplace"].map((detail) => ({ + name: "marketplace pin", + ok: false, + detail, + fix: FIX, + })), + ); + }); +}); + describe("the model sheet", () => { const SHEET = "# budget: large (xhigh)\nbug-fix: inherit-parent\nsession hook: on\n"; diff --git a/tools/install.mjs b/tools/install.mjs index fdef3bd..a89944e 100755 --- a/tools/install.mjs +++ b/tools/install.mjs @@ -1,11 +1,12 @@ #!/usr/bin/env node // t3-pstack's installer. `install`, or `update`, the same command, brings // every Claude Code and Codex home T3 can run to this package's version of -// t3-pstack, trusts the Codex session-start hook, and moves the model sheet to -// its one path per machine. Each step converges, so a second run changes -// nothing. `doctor` checks the same homes and writes nothing itself, though -// the Codex app-server it starts refreshes a Git marketplace, as any T3 Codex -// thread does. Both exit 1 when a check fails. +// t3-pstack, pins each Codex home's marketplace to that version's tag, trusts +// the Codex session-start hook, and moves the model sheet to its one path per +// machine. Each step converges, so a second run changes nothing. `doctor` +// checks the same homes and writes nothing itself, though the Codex app-server +// it starts refreshes a Git marketplace, as any T3 Codex thread does. Both +// exit 1 when a check fails. // // Each home's t3-pstack marketplace must come from chhoumann/t3-pstack or from // this run's --source. A home whose marketplace has another source, such as a @@ -14,6 +15,13 @@ // home's source: one from chhoumann/t3-pstack stays on it under another // --source, and doctor warns with the commands that switch it. // +// The pin is the `ref` of a Codex home's Git marketplace, the tag v<version>. +// Codex's own auto-upgrade leaves a lightweight tag, as each release's is, +// where it is, so a release reaches the home only through this installer, +// which trusts the hook again. A local +// directory has no tag and stays unpinned. Claude Code homes still auto-update +// from their marketplace's default branch. +// // npx -y github:chhoumann/t3-pstack <install|update|doctor> // --source <owner/repo|git URL|dir> marketplace source, default chhoumann/t3-pstack // --claude-home <dir>, --codex-home <dir> more homes, repeatable diff --git a/tools/install/codex.mjs b/tools/install/codex.mjs index 744a45d..af07096 100644 --- a/tools/install/codex.mjs +++ b/tools/install/codex.mjs @@ -8,6 +8,11 @@ // its command runs. Codex's own trust covers the entry alone, and the script // changes with each release, so the marketplace source check is what vouches // for the script. +// +// Codex 0.164 and later also tie that trust to every file in the plugin, so a +// release that Codex's own marketplace auto-upgrade installs turns the hook +// off. So the installer pins a Git marketplace to this release's tag, and only +// the installer, which trusts the hook again, moves it. import { spawn } from "node:child_process"; import { closeSync, constants, existsSync, fstatSync, lstatSync, mkdirSync, openSync, readdirSync, readFileSync, realpathSync } from "node:fs"; import { join } from "node:path"; @@ -133,6 +138,7 @@ async function pluginState(server, dir, skills) { const plugin = marketplaces.flatMap((m) => m.plugins ?? []).find((p) => p.id === PLUGIN_ID); const versions = installedVersions(dir); return { + marketplace: config.marketplaces?.[MARKETPLACE], sources: marketplaceSources(config), installed: plugin?.installed === true, enabled: plugin?.enabled === true, @@ -214,6 +220,10 @@ export async function installCodex(home, { source, trusted, version, skills, cod } // Nothing installs from a marketplace of another source; doctor names it. if (!trustedOnly(before.sources, trusted)) return steps; + const tag = `v${version}`; + if (before.marketplace.source_type === "git" && before.marketplace.ref !== tag) { + steps.push(...(await pinMarketplace(home, trusted, tag, () => plugin("marketplace", "upgrade", MARKETPLACE)))); + } const step = codexStep(before, version); if (step) { // A local marketplace is read in place; a Git one is a snapshot to refresh. @@ -233,6 +243,41 @@ export async function installCodex(home, { source, trusted, version, skills, cod return steps; } +// Codex's auto-upgrade moves a Git marketplace only when the hash `git +// ls-remote` reports for its ref differs from the commit it installed, so a +// lightweight tag, as each release's is, holds it. The ref is written before +// `upgrade` makes Codex fetch it, so an app-server that starts in between, +// such as the installer's own, fetches the tag too. A source without the tag, such as a +// fork that never pushed it, gets its old ref back and updates as before. +async function pinMarketplace(home, trusted, tag, upgrade) { + const keyPath = `marketplaces.${MARKETPLACE}.ref`; + const pinned = await withServer(home, async (server) => { + const { config, layers } = await server.request("config/read", { includeLayers: true }); + if (!trustedOnly(marketplaceSources(config), trusted)) return null; + const user = layers.find((layer) => layer.name.type === "user"); + const written = await server.request("config/value/write", { keyPath, value: tag, mergeStrategy: "replace", expectedVersion: user.version }); + return { was: config.marketplaces[MARKETPLACE].ref ?? null, version: written.version }; + }); + if (!pinned) return []; + try { + upgrade(); + } catch (err) { + await withServer(home, (server) => + server.request("config/value/write", { keyPath, value: pinned.was, mergeStrategy: "replace", expectedVersion: pinned.version }), + ); + const stays = pinned.was ? `on ${pinned.was}` : "unpinned"; + return [`Codex could not fetch ${tag}, so the marketplace stays ${stays} (${err.message.split("\n")[0]})`]; + } + return [`pinned the marketplace to ${tag} (was ${pinned.was ?? "unpinned"})`]; +} + +// A local directory is read in place and has no tag to pin. +export function pinCheck(marketplace, tag, hint) { + if (marketplace?.source_type === "local") return check("marketplace pin", true, "none, since a local directory has no tag"); + const ref = marketplace?.ref; + return check("marketplace pin", ref === tag, !marketplace ? "no marketplace" : ref === tag ? tag : `${ref ?? "none"}, expected ${tag}`, hint); +} + // One app-server session checks the marketplace source, lists the hooks, and // writes the trust. The write names the config version the source check read, // so Codex refuses it when config.toml changed in between. A config write @@ -278,6 +323,7 @@ export async function doctorCodex(home, { source, trusted, version, skills, code const good = (h) => h.trustStatus === "trusted" && isPinned(h, codexHook); return [ marketplaceCheck(state.sources, { source, trusted }, `remove it with \`CODEX_HOME=${home.dir} codex plugin marketplace remove ${MARKETPLACE}\``), + pinCheck(state.marketplace, `v${version}`, hint), check( "installed", state.installed && installed === version && state.intact,