Skip to content

The fastest browser for AI agents to run browser automation, built for sharing your logged-in browser state with your AI agents, like Codex or Claude Code, without disturbing you. Zero cost, zero config.

feat(plugins): sync the plugin's Skill copy in the commit hook

0x03f2c43a741d0
diff --git a/AGENTS.md b/AGENTS.md
index 334cb5c..a167709 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -43,7 +43,7 @@ Task spaces are isolated browsing contexts with an ownership model (`agent` / `u
- `package/ego-browser/src/**/*.test.mjs` — tests are colocated with the code (there is no separate `test/` directory).
- `package/ego-browser/scripts/` — `build.mjs` (esbuild per-file → `dist/src`, rollup bundle → `dist/out/index.js`, renders `skill-body/SKILL.md` via `render-guide.mjs` → `dist/out/ego-browser/SKILL.md` plus `SKILL.macos.md` / `SKILL.windows.md`, selecting `<!-- platform: ... -->` blocks and adding version and end markers, copies the entry Skill and its learnings → `dist/out/agent-skills/ego-browser`), `validate-site-skills.ts`, and the real-browser E2E runner.
- `package/ego-browser/skill-body/SKILL.md` — canonical agent-facing usage guide, printed by `ego-browser skill`.
-- `skills/ego-browser/` — thin entry Skill published to skill markets and plugins: `SKILL.md`, `references/install.md` (plus `install-macos.md` / `install-windows.md`), `references/clearing-state.md`, `scripts/install.sh`, and the site `learnings/`. See `docs/ego-browser-skill-command.md` for the browser-side contract. `plugins/ego/skills/ego-browser/` is a copy of it for hosts that install the plugin from Git; after editing the entry Skill or its learnings, run `npm --prefix plugins/ego run sync-skills`.
+- `skills/ego-browser/` — thin entry Skill published to skill markets and plugins: `SKILL.md`, `references/install.md` (plus `install-macos.md` / `install-windows.md`), `references/clearing-state.md`, `scripts/install.sh`, and the site `learnings/`. See `docs/ego-browser-skill-command.md` for the browser-side contract. `plugins/ego/skills/ego-browser/` is a copy of it for hosts that install the plugin from Git: edit only `skills/ego-browser/`, and the commit hook syncs and stages the copy (without the hook, run `npm --prefix plugins/ego run sync-skills`).
- `skills/ego-browser/learnings/` — reusable per-site experience packs (`manifest.json` + `notes/` + `tools/` + `browser-tools/`).
## Development Commands
diff --git a/lefthook.yml b/lefthook.yml
index b99db24..0fa0543 100644
--- a/lefthook.yml
+++ b/lefthook.yml
@@ -38,6 +38,12 @@ pre-commit:
run: |
git diff --cached --name-only --diff-filter=ACMR | grep -Eq '^(package/ego-browser/(src/learning/|scripts/validate-site-skills\.ts)|skills/ego-browser/learnings/)' || exit 0
cd package/ego-browser && npm run validate:site-skills
+ plugin-skill-sync:
+ # Lefthook runs commands in name order, so this refreshes the plugin's
+ # copy of the entry Skill before plugin-tests checks it.
+ run: |
+ git diff --cached --name-only | grep -q '^skills/ego-browser/' || exit 0
+ node plugins/scripts/sync-skills.mjs ego --staged
plugin-tests:
run: |
git diff --cached --name-only --diff-filter=ACMR | grep -Eq '^(plugins/|skills/ego-browser/|package/ego-browser/skill-body/|\.agents/plugins/|\.claude-plugin/|\.cursor-plugin/)' || exit 0
diff --git a/plugins/ego/README.md b/plugins/ego/README.md
index 2e155de..75b5d99 100644
--- a/plugins/ego/README.md
+++ b/plugins/ego/README.md
@@ -326,14 +326,18 @@ EOF
`skills/ego-browser` here is a copy of the canonical `skills/ego-browser` at the
repository root, the thin entry Skill. The usage guide it points to lives in
-`package/ego-browser/skill-body/SKILL.md` and ships with ego lite. Edit the
-canonical Skill, then refresh the copy:
+`package/ego-browser/skill-body/SKILL.md` and ships with ego lite. Edit only
+the canonical Skill. When a commit stages changes under `skills/ego-browser/`,
+the commit hook refreshes the copy from the staged Skill and stages it too, so
+unstaged edits and untracked drafts never reach the copy. Without the hook,
+refresh the copy yourself:
```bash
npm --prefix plugins/ego run sync-skills
```
-The plugin tests fail while the copy differs from the canonical Skill. The
+The plugin tests compare the copy with the canonical Skill in the Git index and
+fail while they differ, so CI catches a commit that skipped the hook. The
packager builds every artifact from the canonical Skill, and unexpected or
broken links fail packaging.
diff --git a/plugins/ego/tests/claude-plugin-mode-isolation.test.mjs b/plugins/ego/tests/claude-plugin-mode-isolation.test.mjs
index 16aad77..b288b80 100644
--- a/plugins/ego/tests/claude-plugin-mode-isolation.test.mjs
+++ b/plugins/ego/tests/claude-plugin-mode-isolation.test.mjs
@@ -1,6 +1,6 @@
import assert from "node:assert/strict";
-import { existsSync, lstatSync, readFileSync, readdirSync } from "node:fs";
-import { basename } from "node:path";
+import { execFileSync } from "node:child_process";
+import { existsSync, readFileSync } from "node:fs";
import test from "node:test";
const repoFile = (path) => new URL(`../../../${path}`, import.meta.url);
@@ -173,27 +173,26 @@ test("versioned guide restores v2 Pages across script rounds", () => {
test("source plugin carries an exact copy of the canonical Skill", () => {
const canonicalRoot = "skills/ego-browser";
const copyRoot = `${claudePluginRoot}/skills/ego-browser`;
- const sync = "run `npm --prefix plugins/ego run sync-skills`";
// Hosts that install the plugin straight from Git drop links that leave
- // the plugin root, so the copy must be real files.
- assert.equal(lstatSync(repoFile(copyRoot)).isSymbolicLink(), false);
- const files = (root) =>
- readdirSync(repoFile(root), { recursive: true })
- .filter(
- (path) =>
- basename(path) !== ".DS_Store" &&
- lstatSync(repoFile(`${root}/${path}`)).isFile(),
- )
- .sort();
- const canonicalFiles = files(canonicalRoot);
- assert.deepEqual(files(copyRoot), canonicalFiles, `${copyRoot}: ${sync}`);
- for (const path of canonicalFiles) {
- assert.deepEqual(
- readFileSync(repoFile(`${copyRoot}/${path}`)),
- readFileSync(repoFile(`${canonicalRoot}/${path}`)),
- `${copyRoot}/${path} differs from the canonical Skill: ${sync}`,
- );
- }
+ // the plugin root, so the copy must be real files. Compare the Git index,
+ // which is what a commit ships, so untracked drafts do not count.
+ const entries = (root) =>
+ execFileSync("git", ["ls-files", "--stage", "--", root], {
+ cwd: repoFile(""),
+ encoding: "utf8",
+ })
+ .trim()
+ .split("\n")
+ .map((line) => {
+ const [meta, path] = line.split("\t");
+ const [mode, blob] = meta.split(" ");
+ return `${mode} ${blob} ${path.slice(root.length + 1)}`;
+ });
+ assert.deepEqual(
+ entries(copyRoot),
+ entries(canonicalRoot),
+ `${copyRoot} differs from the canonical Skill: run \`npm --prefix plugins/ego run sync-skills\``,
+ );
});
test("versioned guide preserves TaskSpace safety policy", () => {
diff --git a/plugins/ego/tests/sync-skills.test.mjs b/plugins/ego/tests/sync-skills.test.mjs
new file mode 100644
index 0000000..b27ed9b
--- /dev/null
+++ b/plugins/ego/tests/sync-skills.test.mjs
@@ -0,0 +1,70 @@
+import assert from "node:assert/strict";
+import { execFileSync } from "node:child_process";
+import {
+ copyFileSync,
+ mkdirSync,
+ mkdtempSync,
+ readFileSync,
+ rmSync,
+ writeFileSync,
+} from "node:fs";
+import { tmpdir } from "node:os";
+import { dirname, join } from "node:path";
+import { fileURLToPath } from "node:url";
+import test from "node:test";
+
+const script = fileURLToPath(
+ new URL("../../scripts/sync-skills.mjs", import.meta.url),
+);
+
+function write(root, path, value) {
+ mkdirSync(dirname(join(root, path)), { recursive: true });
+ writeFileSync(join(root, path), value);
+}
+
+test("--staged copies only what the commit stages and stages the copy", () => {
+ const root = mkdtempSync(join(tmpdir(), "ego-skill-sync-"));
+ const git = (...args) =>
+ execFileSync("git", args, { cwd: root, encoding: "utf8" });
+ try {
+ mkdirSync(join(root, "plugins", "scripts"), { recursive: true });
+ copyFileSync(script, join(root, "plugins", "scripts", "sync-skills.mjs"));
+ for (const base of ["skills/demo", "plugins/p/skills/demo"]) {
+ write(root, `${base}/SKILL.md`, "v1\n");
+ write(root, `${base}/old.md`, "old\n");
+ }
+ git("init", "-q");
+ git("add", "-A");
+ git("-c", "user.name=t", "-c", "user.email=t@t", "commit", "-qm", "init");
+
+ write(root, "skills/demo/SKILL.md", "v2 staged\n");
+ git("add", "skills/demo/SKILL.md");
+ git("rm", "-q", "skills/demo/old.md");
+ write(root, "skills/demo/SKILL.md", "v3 unstaged\n");
+ write(root, "skills/demo/draft.md", "untracked\n");
+
+ execFileSync(process.execPath, [
+ join(root, "plugins", "scripts", "sync-skills.mjs"),
+ "p",
+ "--staged",
+ ]);
+
+ assert.equal(git("show", ":plugins/p/skills/demo/SKILL.md"), "v2 staged\n");
+ assert.equal(
+ readFileSync(join(root, "plugins/p/skills/demo/SKILL.md"), "utf8"),
+ "v2 staged\n",
+ );
+ assert.deepEqual(
+ git("ls-files", "plugins/p/skills").trim().split("\n"),
+ ["plugins/p/skills/demo/SKILL.md"],
+ "the staged deletion propagates and the untracked draft stays out",
+ );
+ assert.equal(
+ readFileSync(join(root, "skills/demo/SKILL.md"), "utf8"),
+ "v3 unstaged\n",
+ "the canonical working tree is left alone",
+ );
+ } finally {
+ rmSync(root, { recursive: true, force: true });
+ }
+});
diff --git a/plugins/scripts/sync-skills.mjs b/plugins/scripts/sync-skills.mjs
index 0d7305e..48dd116 100755
--- a/plugins/scripts/sync-skills.mjs
+++ b/plugins/scripts/sync-skills.mjs
@@ -2,22 +2,51 @@
// Hosts that install a plugin straight from Git drop links that leave the
// plugin root, so each plugin keeps a copy of the canonical Skills it ships.
-import { cp, readdir, rm } from "node:fs/promises";
+//
+// --staged copies the Skills as staged in the Git index and stages the copy,
+// so a commit hook never picks up unstaged edits or untracked drafts.
+import { execFileSync } from "node:child_process";
+import { cp, mkdtemp, readdir, rm } from "node:fs/promises";
+import { tmpdir } from "node:os";
import { join } from "node:path";
import { fileURLToPath } from "node:url";
const repositoryRoot = fileURLToPath(new URL("../..", import.meta.url));
-const [name] = process.argv.slice(2);
-if (!name) {
- console.error("Usage: node plugins/scripts/sync-skills.mjs <plugin>");
+const [name, mode] = process.argv.slice(2);
+if (!name || (mode && mode !== "--staged")) {
+ console.error(
+ "Usage: node plugins/scripts/sync-skills.mjs <plugin> [--staged]",
+ );
process.exit(1);
}
+const staged = mode === "--staged";
-const skillsRoot = join(repositoryRoot, "plugins", name, "skills");
-for (const skill of await readdir(skillsRoot)) {
- if (skill.startsWith(".")) continue;
- const copy = join(skillsRoot, skill);
- await rm(copy, { recursive: true, force: true });
- await cp(join(repositoryRoot, "skills", skill), copy, { recursive: true });
- console.log(`Synced skills/${skill} -> plugins/${name}/skills/${skill}`);
+function git(args, input) {
+ return execFileSync("git", args, { cwd: repositoryRoot, input });
+}
+
+const exportRoot = staged
+ ? await mkdtemp(join(tmpdir(), "ego-skill-sync-"))
+ : undefined;
+try {
+ const skillsRoot = join(repositoryRoot, "plugins", name, "skills");
+ for (const skill of await readdir(skillsRoot)) {
+ if (skill.startsWith(".")) continue;
+ const canonical = `skills/${skill}`;
+ if (staged) {
+ git(
+ ["checkout-index", `--prefix=${exportRoot}/`, "-z", "--stdin"],
+ git(["ls-files", "-z", "--", canonical]),
+ );
+ }
+ const copy = join(skillsRoot, skill);
+ await rm(copy, { recursive: true, force: true });
+ await cp(join(staged ? exportRoot : repositoryRoot, canonical), copy, {
+ recursive: true,
+ });
+ if (staged) git(["add", "-A", "--", copy]);
+ console.log(`Synced ${canonical} -> plugins/${name}/skills/${skill}`);
+ }
+} finally {
+ if (exportRoot) await rm(exportRoot, { recursive: true, force: true });
}