Skip to content

armgit / cogit

Public Imported from GitHub
0

Git for the intent behind agent-written code. Records what your coding agent decided and why, and links every commit to it.

feat(plugin): install the plugin from the plugin branch

Eren2c80bceec4c7
diff --git a/.claude-plugin/marketplace.json b/.claude-plugin/marketplace.json
index b680b8d..8b0d878 100644
--- a/.claude-plugin/marketplace.json
+++ b/.claude-plugin/marketplace.json
@@ -5,7 +5,7 @@
"plugins": [
{
"name": "cogit",
- "source": { "source": "npm", "package": "@cogit/cli" },
+ "source": { "source": "github", "repo": "erensrtky/cogit", "ref": "plugin" },
"description": "Records what each session decided and why, and renders it as a static map."
}
]
diff --git a/.github/workflows/plugin-branch.yml b/.github/workflows/plugin-branch.yml
new file mode 100644
index 0000000..bc81023
--- /dev/null
+++ b/.github/workflows/plugin-branch.yml
@@ -0,0 +1,35 @@
+# The marketplace installs the plugin from the `plugin` branch (built files only), so every
+# release tag rebuilds it there. See scripts/build-plugin-branch.mjs.
+name: plugin branch
+
+on:
+ push:
+ tags: ["v*"]
+ workflow_dispatch:
+
+permissions:
+ contents: write
+
+concurrency:
+ group: plugin-branch
+ cancel-in-progress: false
+
+jobs:
+ publish:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v4
+ - uses: actions/setup-node@v4
+ with:
+ node-version: 22
+ cache: npm
+ - run: npm ci
+ - run: npm run build
+ - name: Fetch the current plugin branch
+ run: git fetch --no-tags origin +refs/heads/plugin:refs/heads/plugin || echo "no plugin branch yet"
+ - name: Commit the build onto it
+ run: |
+ git config user.name "github-actions[bot]"
+ git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
+ node scripts/build-plugin-branch.mjs
+ - run: git push origin refs/heads/plugin:refs/heads/plugin
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 80a7a42..d126f0d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased]
+### Changed
+- `/plugin install cogit` failed with `EALLOWREMOTE` for everyone on npm 12, which refuses the npm download Claude Code makes for a plugin. The plugin now installs from the repository's `plugin` branch, which a GitHub Action rebuilds on every release; the CLI still comes from npm. An existing marketplace needs `/plugin marketplace update cogit` before the install.
## [0.18.2] - 2026-10-28
### Fixed
diff --git a/docs/guide/troubleshooting.md b/docs/guide/troubleshooting.md
index 9d61477..7914d5a 100644
--- a/docs/guide/troubleshooting.md
+++ b/docs/guide/troubleshooting.md
@@ -52,6 +52,19 @@ it in that project:
cogit config hint-off
```
+## The plugin install fails with `EALLOWREMOTE`
+
+cogit 0.18 and earlier installed the plugin from npm, and npm 12 refuses the download Claude
+Code makes for that. From 0.19 the plugin comes from the repository's `plugin` branch. If you
+added the marketplace before, refresh it and install again:
+
+```text
+/plugin marketplace update cogit
+/plugin install cogit@cogit
+```
+
+The CLI is not affected: `npm install -g @cogit/cli` works with any npm.
+
## Something else
Open an issue at <https://github.com/erensrtky/cogit/issues> with the output of
diff --git a/packages/cli/test/build-plugin-branch.test.ts b/packages/cli/test/build-plugin-branch.test.ts
new file mode 100644
index 0000000..182970a
--- /dev/null
+++ b/packages/cli/test/build-plugin-branch.test.ts
@@ -0,0 +1,78 @@
+import { execFileSync } from "node:child_process";
+import { mkdir, writeFile } from "node:fs/promises";
+import { join } from "node:path";
+import { describe, expect, it } from "vitest";
+// @ts-expect-error plain ESM script without types
+import { run, stagePlugin, writePluginBranch } from "../../../scripts/build-plugin-branch.mjs";
+import { tempDir } from "./helpers.js";
+
+const git = (cwd: string, ...args: string[]) =>
+ execFileSync("git", args, { cwd, encoding: "utf8" }).trim();
+
+/** A repository shaped like this one, with a build in packages/cli/dist. */
+async function builtRepo(): Promise<string> {
+ const root = await tempDir();
+ git(root, "init", "-q", "-b", "main");
+ git(root, "config", "user.name", "Test");
+ git(root, "config", "user.email", "[email protected]");
+ // A rule like the repository's own must not keep dist/ off the branch.
+ await writeFile(join(root, ".gitignore"), "dist/\n");
+ const files: Record<string, string> = {
+ VERSION: "1.2.3\n",
+ "README.md": "readme\n",
+ LICENSE: "licence\n",
+ "packages/cli/.claude-plugin/plugin.json": '{ "name": "cogit", "version": "1.2.3" }\n',
+ "packages/cli/dist/cli.js": "built\n",
+ "packages/cli/hooks/hooks.json": "{}\n",
+ "packages/cli/skills/record/SKILL.md": "skill\n",
+ "packages/cli/src/cli.ts": "source\n",
+ };
+ for (const [rel, text] of Object.entries(files)) {
+ await mkdir(join(root, rel, ".."), { recursive: true });
+ await writeFile(join(root, rel), text);
+ }
+ git(root, "add", "-A");
+ git(root, "commit", "-q", "-m", "init");
+ return root;
+}
+
+describe("build-plugin-branch", () => {
+ it("refuses to stage a plugin that was not built", async () => {
+ const root = await tempDir();
+ expect(() => stagePlugin(root, join(root, "out"))).toThrow(/npm run build/);
+ });
+
+ it("commits only the built plugin onto its own branch, leaving main alone", async () => {
+ const root = await builtRepo();
+ const head = git(root, "rev-parse", "HEAD");
+
+ const first = writePluginBranch(root);
+ expect(first).toMatchObject({ changed: true, version: "1.2.3" });
+ expect(git(root, "ls-tree", "-r", "--name-only", "plugin").split("\n")).toEqual([
+ ".claude-plugin/plugin.json",
+ "LICENSE",
+ "README.md",
+ "dist/cli.js",
+ "hooks/hooks.json",
+ "skills/record/SKILL.md",
+ ]);
+ expect(git(root, "log", "--format=%s", "plugin")).toBe("plugin v1.2.3");
+ // An orphan branch: nothing of main's history comes along.
+ expect(git(root, "rev-list", "--count", "plugin")).toBe("1");
+ expect(git(root, "rev-parse", "HEAD")).toBe(head);
+ expect(git(root, "status", "--porcelain")).toBe("");
+
+ // The same build adds nothing; a new one adds a commit on top.
+ expect(writePluginBranch(root)).toEqual({ ...first, changed: false });
+ await writeFile(join(root, "packages/cli/dist/cli.js"), "rebuilt\n");
+ const lines: string[] = [];
+ const next = run((line: string) => lines.push(line), root);
+ expect(next.changed).toBe(true);
+ expect(git(root, "rev-parse", "plugin^")).toBe(first.commit);
+ expect(git(root, "show", "plugin:dist/cli.js")).toBe("rebuilt");
+ expect(lines).toEqual([`plugin: v1.2.3 at ${next.commit.slice(0, 7)}`]);
+
+ run((line: string) => lines.push(line), root);
+ expect(lines[1]).toBe(`plugin: v1.2.3 unchanged at ${next.commit.slice(0, 7)}`);
+ });
+});
diff --git a/packages/cli/test/plugin-manifest.test.ts b/packages/cli/test/plugin-manifest.test.ts
index 8d2235b..b2a8f25 100644
--- a/packages/cli/test/plugin-manifest.test.ts
+++ b/packages/cli/test/plugin-manifest.test.ts
@@ -16,7 +16,7 @@ describe("plugin packaging", () => {
it("keeps the plugin manifest in step with the npm package", async () => {
const pkg = await read("../package.json");
const plugin = await read("../.claude-plugin/plugin.json");
- // An npm-sourced plugin without a version resolves to "unknown" and never updates.
+ // A plugin without a version resolves to "unknown" and never updates.
expect(plugin.version).toBe(pkg.version);
// VERSION is the source; `npm run build` copies it (scripts/sync-version.mjs).
const version = (await readFile(new URL("../../../VERSION", import.meta.url), "utf8")).trim();
@@ -32,13 +32,14 @@ describe("plugin packaging", () => {
);
});
- it("lists the plugin in the marketplace under its manifest name, from npm", async () => {
+ it("lists the plugin in the marketplace under its manifest name, from the plugin branch", async () => {
const marketplace = await read("../../../.claude-plugin/marketplace.json");
- const pkg = await read("../package.json");
+ // Not the npm package: npm 12 refuses the tarball URL Claude Code fetches it by
+ // (EALLOWREMOTE). The branch holds the build; scripts/build-plugin-branch.mjs writes it.
expect(marketplace.plugins).toEqual([
expect.objectContaining({
name: "cogit",
- source: { source: "npm", package: pkg.name },
+ source: { source: "github", repo: "erensrtky/cogit", ref: "plugin" },
}),
]);
});
diff --git a/scripts/build-plugin-branch.mjs b/scripts/build-plugin-branch.mjs
new file mode 100644
index 0000000..22521c4
--- /dev/null
+++ b/scripts/build-plugin-branch.mjs
@@ -0,0 +1,74 @@
+#!/usr/bin/env node
+// The marketplace installs the plugin from the `plugin` branch: only what Claude Code loads,
+// built, with no source. main keeps dist/ out of git, so this writes the branch with git
+// plumbing (a private index, no checkout) after `npm run build`. The release Action runs it on
+// every v* tag; run it by hand to create the branch the first time.
+import { execFileSync } from "node:child_process";
+import { cpSync, existsSync, mkdtempSync, readFileSync, rmSync } from "node:fs";
+import { tmpdir } from "node:os";
+import { dirname, join } from "node:path";
+import { fileURLToPath } from "node:url";
+
+/** What the branch holds, relative to packages/cli; README and LICENSE come from the root. */
+export const PLUGIN_FILES = [".claude-plugin/plugin.json", "dist", "hooks/hooks.json", "skills"];
+export const ROOT_FILES = ["README.md", "LICENSE"];
+
+/** Copies the built plugin into `target`; throws when the build is missing. */
+export function stagePlugin(root, target) {
+ const pkg = join(root, "packages/cli");
+ if (!existsSync(join(pkg, "dist/cli.js")))
+ throw new Error("packages/cli/dist/cli.js is missing: run `npm run build` first");
+ for (const rel of PLUGIN_FILES) cpSync(join(pkg, rel), join(target, rel), { recursive: true });
+ for (const rel of ROOT_FILES) cpSync(join(root, rel), join(target, rel));
+ return [...PLUGIN_FILES, ...ROOT_FILES];
+}
+
+/**
+ * Commits the built plugin onto `branch` in the repository at `root` without touching its
+ * working tree or index. Returns the branch's commit and whether this run added one.
+ */
+export function writePluginBranch(root, { branch = "plugin" } = {}) {
+ const git = (args, env = {}) =>
+ execFileSync("git", args, { cwd: root, env: { ...process.env, ...env }, encoding: "utf8" }).trim();
+ const version = readFileSync(join(root, "VERSION"), "utf8").trim();
+ const scratch = mkdtempSync(join(tmpdir(), "cogit-plugin-"));
+ try {
+ const tree = join(scratch, "tree");
+ stagePlugin(root, tree);
+ const env = { GIT_INDEX_FILE: join(scratch, "index") };
+ // -f: a global or .git/info excludes rule must not drop dist/ from the branch.
+ git(["--work-tree", tree, "add", "-A", "-f", "."], env);
+ const treeId = git(["write-tree"], env);
+ let parent = "";
+ try {
+ parent = git(["rev-parse", "--verify", "-q", `refs/heads/${branch}`]);
+ } catch {}
+ if (parent && git(["rev-parse", `${parent}^{tree}`]) === treeId)
+ return { commit: parent, changed: false, version };
+ const commit = git([
+ "commit-tree",
+ treeId,
+ ...(parent ? ["-p", parent] : []),
+ "-m",
+ `plugin v${version}`,
+ ]);
+ // The old value guards against another writer moving the branch meanwhile.
+ git(["update-ref", `refs/heads/${branch}`, commit, ...(parent ? [parent] : [])]);
+ return { commit, changed: true, version };
+ } finally {
+ rmSync(scratch, { recursive: true, force: true });
+ }
+}
+
+/** Writes the branch of `root` (this repository by default) and prints what happened. */
+export function run(log = console.log, root = join(dirname(fileURLToPath(import.meta.url)), "..")) {
+ const result = writePluginBranch(root);
+ log(
+ result.changed
+ ? `plugin: v${result.version} at ${result.commit.slice(0, 7)}`
+ : `plugin: v${result.version} unchanged at ${result.commit.slice(0, 7)}`,
+ );
+ return result;
+}
+
+if (process.argv[1] === fileURLToPath(import.meta.url)) run();