A local-first multi-agent app development platform, built on PenguinHarness
fix(core,ci): a workspace checkout loads plugins from plugins/, and a plugin change must bump its version (#725)
Yaowei Zhengb205c6147cfe
diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.mdindex 543262eb..f98cdcf5 100644--- a/.github/CONTRIBUTING.md+++ b/.github/CONTRIBUTING.md@@ -59,6 +59,14 @@ that only re-sync when the package's `build` script runs via pnpmcache — on the old build; if a running dev web app still serves stale core after a manualrebuild, delete `packages/web/node_modules/.vite` and restart.+Plugins are the exception to the snapshot rule: in a workspace checkout core's loader reads+the repo's `plugins/<name>/` directories directly, not pnpm's injected copies (plugins have+no `build` script, so those copies would never re-sync), so an edit under `plugins/` — a new+skill, a changed SKILL.md, a bumped `plugin.json` — is live in `pnpm dev` and in the test+suites at once. Any content change under a plugin must bump its `plugin.json` date version+(`YYYY.MM.DD.N`): that version is how installed copies learn they are behind, and CI fails a+pull request whose plugin files changed without it (`scripts/check-plugin-versions.mjs`).+Dev entry points that touch data default to separate data roots, kept apart from theinstalled CLI/server's `~/.penguin/data` — hacking on the repo never mixes state withyour real agents. `pnpm dev`, `pnpm dev:server` and `pnpm desktop` sharediff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex 24cf0e4a..57d2343d 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -54,6 +54,19 @@ jobs:# workflows this change does not touch are a separate conversation../actionlint -shellcheck=+ # A plugin's files changed without its plugin.json version moving: installed copies would+ # never learn about the change (the update flag reads the version). Compared against the+ # pull request's base; a push has no base and the script passes on an empty one.+ plugin-versions:+ name: plugin versions+ runs-on: ubuntu-latest+ steps:+ - uses: actions/checkout@v5+ with:+ fetch-depth: 0+ - name: Changed plugins carry a new version+ run: node scripts/check-plugin-versions.mjs '${{ github.event.pull_request.base.sha }}'+# tsc over every package, so this one does need the whole build. Results are# platform-independent, which is why neither macOS nor Windows repeats it.typecheck:@@ -318,7 +331,17 @@ jobs:ci:if: always()needs:- [style, typecheck, test, installer-e2e, test-macos, test-windows, installer-windows, runtime]+ [+ style,+ plugin-versions,+ typecheck,+ test,+ installer-e2e,+ test-macos,+ test-windows,+ installer-windows,+ runtime,+ ]runs-on: ubuntu-lateststeps:- name: Every gate passeddiff --git a/changelog/unreleased/2026-09-14-plugins-from-workspace.md b/changelog/unreleased/2026-09-14-plugins-from-workspace.mdnew file mode 100644index 00000000..be3e3c2f--- /dev/null+++ b/changelog/unreleased/2026-09-14-plugins-from-workspace.md@@ -0,0 +1,13 @@+# A checkout loads plugins from the repo's plugins/ directory, and CI requires a version bump++- **Date:** 2026-09-14+- **Type:** fix+- **Scope:** `core`, `ci`+- **PR:** [#725](https://github.com/Prism-Shadow/penguin-harness/pull/725)++[中文版](2026-09-14-plugins-from-workspace.zh.md)++## What changed++- In a workspace checkout, core's plugin loader reads each plugin from the repo's `plugins/<name>/` directory instead of the copy pnpm injects under `node_modules`. That copy is a snapshot taken at install time and refreshed only after the package's `build` script runs — which plugins have none of — so a skill added or a `plugin.json` version bumped after the last install never reached a running `pnpm dev`, nor the server's own tests: the plugin library kept showing the old version and installed agents never saw an update to take. The redirect applies only under a `pnpm-workspace.yaml`; an npm install and the packed desktop app keep resolving their own copy.+- CI gains a `plugin versions` job: a pull request that changes files under `plugins/<name>/` must also change that plugin's `plugin.json` version (`YYYY.MM.DD.N`), because that version is what tells an installed copy it is behind the library. `scripts/check-plugin-versions.mjs` does the comparison against the base commit and passes when there is nothing to compare.diff --git a/changelog/unreleased/2026-09-14-plugins-from-workspace.zh.md b/changelog/unreleased/2026-09-14-plugins-from-workspace.zh.mdnew file mode 100644index 00000000..e5bf4145--- /dev/null+++ b/changelog/unreleased/2026-09-14-plugins-from-workspace.zh.md@@ -0,0 +1,13 @@+# 工作区检出直接从仓库的 plugins/ 目录加载插件,CI 要求版本号随内容变化++- **Date:** 2026-09-14+- **Type:** fix+- **Scope:** `core`, `ci`+- **PR:** [#725](https://github.com/Prism-Shadow/penguin-harness/pull/725)++[English](2026-09-14-plugins-from-workspace.md)++## 变更内容++- 在工作区检出里,core 的插件 loader 改为直接读取仓库的 `plugins/<name>/` 目录,而不是 pnpm 注入到 `node_modules` 下的副本。那份副本是安装时的快照,只在包的 `build` 脚本跑过之后才会重新同步——插件没有 build 脚本——因此上次安装之后新增的技能、改过的 `plugin.json` 版本号都到不了正在运行的 `pnpm dev`,也到不了服务端自己的测试:插件库一直显示旧版本,已安装的 Agent 也永远看不到可更新。这条重定向只在 `pnpm-workspace.yaml` 之下生效;npm 安装与打包的桌面应用仍解析自己的副本。+- CI 新增「plugin versions」任务:改动了 `plugins/<name>/` 下文件的 PR 必须同时改动该插件 `plugin.json` 的版本号(`YYYY.MM.DD.N`),因为已安装副本正是靠这个版本号得知自己落后于插件库。`scripts/check-plugin-versions.mjs` 与 base 提交比对,无可比对时直接通过。diff --git a/packages/core/src/plugins/index.ts b/packages/core/src/plugins/index.tsindex 57119817..178eef8b 100644--- a/packages/core/src/plugins/index.ts+++ b/packages/core/src/plugins/index.ts@@ -220,15 +220,62 @@ const PKG_ROOT = packageRoot();/** npm-name prefix of the per-plugin packages (the host package's dependencies name them). */const PLUGIN_PKG_PREFIX = "@penguinharness/";+/**+ * The pnpm workspace root above `from`, or null outside a workspace checkout: the directory+ * holding `pnpm-workspace.yaml`. An npm install and the packed desktop app have none above+ * them, which is what keeps the workspace preference below out of their way.+ */+function workspaceRootAbove(from: string): string | null {+ let dir = from;+ for (;;) {+ if (fs.existsSync(path.join(dir, "pnpm-workspace.yaml"))) return dir;+ const parent = path.dirname(dir);+ if (parent === dir) return null;+ dir = parent;+ }+}++/**+ * The directory a plugin is read from, given where Node resolved its package: in a workspace+ * checkout, the repo's own `plugins/<name>/` whenever it holds that package; the resolved+ * directory otherwise.+ *+ * The workspace installs every `workspace:*` package as an injected copy (a snapshot pnpm+ * takes at install time and refreshes only after the package's `build` script runs — which+ * plugins have none of), so `require.resolve` lands on a copy that misses every file added+ * since the last install, and an edited `plugin.json` version stays invisible to a running+ * `pnpm dev`. The plugin directory itself is the source of truth in a checkout, so that is+ * what a checkout reads; nothing changes for an npm install or the packed desktop app,+ * which have no workspace file above them and keep resolving their own copy.+ */+export function workspacePluginRoot(+ name: string,+ resolvedDir: string,+ packageRoot: string = PKG_ROOT,+): string {+ const workspace = workspaceRootAbove(packageRoot);+ if (workspace === null) return resolvedDir;+ const candidate = path.join(workspace, "plugins", name);+ try {+ const manifest = JSON.parse(fs.readFileSync(path.join(candidate, "package.json"), "utf8")) as {+ name?: unknown;+ };+ return manifest.name === `${PLUGIN_PKG_PREFIX}${name}` ? candidate : resolvedDir;+ } catch {+ return resolvedDir;+ }+}+/*** Where the plugin directories live, name → absolute root. Each plugin is its own npm package* (`@penguinharness/<name>`, `plugins/<name>/` in the repo): the host package's `dependencies`* name them (core, the CLI, and the desktop app — whose packaged manifest keeps that field* and nothing else, so `devDependencies` would not survive into an installer), and each is* resolved through Node from this module's own location, so the lookup walks the same- * `node_modules` chain a `require` from here would: the workspace, an npm install and the- * packed desktop app (electron-builder collects the declared packages into its node_modules)- * all land on their own copy. Read fresh on every call, like the plugin files themselves.+ * `node_modules` chain a `require` from here would: an npm install and the packed desktop+ * app (electron-builder collects the declared packages into its node_modules) each land on+ * their own copy, and a workspace checkout is redirected to its `plugins/<name>/` directory+ * (see workspacePluginRoot). Read fresh on every call, like the plugin files themselves.*/function pluginRoots(): Map<string, string> {const roots = new Map<string, string>();@@ -248,7 +295,8 @@ function pluginRoots(): Map<string, string> {`Plugin package ${dep} is declared in ${PKG_ROOT}/package.json but cannot be resolved: ${err instanceof Error ? err.message : String(err)}`,);}- roots.set(dep.slice(PLUGIN_PKG_PREFIX.length), path.dirname(manifest));+ const name = dep.slice(PLUGIN_PKG_PREFIX.length);+ roots.set(name, workspacePluginRoot(name, path.dirname(manifest)));}return roots;}diff --git a/packages/core/test/plugins.test.ts b/packages/core/test/plugins.test.tsindex 90b2fc94..f2e8e61d 100644--- a/packages/core/test/plugins.test.ts+++ b/packages/core/test/plugins.test.ts@@ -4,7 +4,9 @@* category grouping, the preinstall filter, the name lookups, the doc conventions every* shipped skill follows, and the README tables that repeat the library for human readers.*/+import { existsSync } from "node:fs";import fs from "node:fs/promises";+import os from "node:os";import path from "node:path";import { describe, expect, it } from "vitest";import {@@ -18,6 +20,7 @@ import {loadPluginGroups,loadPreinstalledPlugins,parseSkillFrontmatter,+ workspacePluginRoot,type LibraryPlugin,type PluginCategory,} from "../src/plugins/index.js";@@ -294,3 +297,64 @@ describe("README category tables", () => {});}});++describe("workspacePluginRoot (a checkout reads plugins from the repo's plugins/ directory)", () => {+ /** A workspace checkout as pnpm lays it out: the repo root, its plugins/, and an injected copy of a plugin under .pnpm. */+ async function checkout(opts: { workspaceFile: boolean; packageName: string }) {+ const root = await fs.mkdtemp(path.join(os.tmpdir(), "penguin-plugin-root-"));+ if (opts.workspaceFile)+ await fs.writeFile(path.join(root, "pnpm-workspace.yaml"), "packages:\n");+ const source = path.join(root, "plugins", "sample");+ await fs.mkdir(source, { recursive: true });+ await fs.writeFile(+ path.join(source, "package.json"),+ JSON.stringify({ name: opts.packageName }),+ );+ const injected = path.join(+ root,+ "node_modules/.pnpm/@penguinharness+sample@file+plugins+sample/node_modules/@penguinharness/sample",+ );+ await fs.mkdir(injected, { recursive: true });+ // Where core itself sits in that checkout: its own injected copy, deep under .pnpm.+ const core = path.join(+ root,+ "node_modules/.pnpm/@prismshadow+penguin-core@file+packages+core/node_modules/@prismshadow/penguin-core",+ );+ await fs.mkdir(core, { recursive: true });+ return { root, source, injected, core };+ }++ it("prefers the repo's plugins/<name>/ over pnpm's injected copy inside a workspace checkout", async () => {+ const c = await checkout({ workspaceFile: true, packageName: "@penguinharness/sample" });+ try {+ expect(workspacePluginRoot("sample", c.injected, c.core)).toBe(c.source);+ } finally {+ await fs.rm(c.root, { recursive: true, force: true });+ }+ });++ it("keeps the resolved copy outside a workspace: an npm install and the packed app have no workspace file", async () => {+ const c = await checkout({ workspaceFile: false, packageName: "@penguinharness/sample" });+ try {+ expect(workspacePluginRoot("sample", c.injected, c.core)).toBe(c.injected);+ } finally {+ await fs.rm(c.root, { recursive: true, force: true });+ }+ });++ it("keeps the resolved copy when the workspace directory is not that package", async () => {+ const c = await checkout({ workspaceFile: true, packageName: "@penguinharness/other" });+ try {+ expect(workspacePluginRoot("sample", c.injected, c.core)).toBe(c.injected);+ } finally {+ await fs.rm(c.root, { recursive: true, force: true });+ }+ });++ it("the live loader reads this checkout's plugins/ directories, not copies under node_modules", () => {+ // The whole point, on the real tree: every library plugin's files come from the repo.+ for (const plugin of loadLibraryPlugins()) {+ expect(existsSync(path.join(pluginsRoot, plugin.name, "plugin.json"))).toBe(true);+ }+ });+});diff --git a/scripts/check-plugin-versions.mjs b/scripts/check-plugin-versions.mjsnew file mode 100644index 00000000..a24205f2--- /dev/null+++ b/scripts/check-plugin-versions.mjs@@ -0,0 +1,65 @@+#!/usr/bin/env node+/**+ * Every plugin whose files changed since the base commit must carry a new `plugin.json`+ * version. The version is what tells an installed copy it is behind the library (the Agents+ * page's update flag and the plugin library's cards read it), so a content change shipped+ * under the old version is invisible to every user until the next unrelated bump.+ *+ * Usage: node scripts/check-plugin-versions.mjs <base-commit>+ * An empty or missing base (a push event, a local run with nothing to compare) passes.+ */+import { execFileSync } from "node:child_process";+import { readFileSync } from "node:fs";++const base = process.argv[2] ?? "";+if (base.trim() === "") {+ console.log("plugin versions: no base commit given, nothing to compare");+ process.exit(0);+}++const git = (...args) => execFileSync("git", args, { encoding: "utf8" });++const changed = git("diff", "--name-only", `${base}...HEAD`, "--", "plugins/")+ .split("\n")+ .map((line) => line.trim())+ .filter((line) => line.startsWith("plugins/"));+const plugins = [...new Set(changed.map((file) => file.split("/")[1]).filter(Boolean))].sort();+if (plugins.length === 0) {+ console.log("plugin versions: no plugin files changed");+ process.exit(0);+}++const versionOf = (json) => {+ try {+ return JSON.parse(json).version ?? null;+ } catch {+ return null;+ }+};+const stale = [];+for (const name of plugins) {+ const manifest = `plugins/${name}/plugin.json`;+ let before;+ try {+ before = versionOf(git("show", `${base}:${manifest}`));+ } catch {+ // A plugin that did not exist at the base commit is new: any version is a new version.+ continue;+ }+ let after;+ try {+ after = versionOf(readFileSync(manifest, "utf8"));+ } catch {+ // Removed plugin: nothing to version.+ continue;+ }+ if (before !== null && before === after) stale.push(`${name} (still ${after})`);+}+if (stale.length > 0) {+ console.error(+ `plugin versions: files changed under plugins/ without a plugin.json version bump — ${stale.join(", ")}. ` ++ "Bump the date version (YYYY.MM.DD.N) so installed copies see the update.",+ );+ process.exit(1);+}+console.log(`plugin versions: ${plugins.join(", ")} changed and carry new versions`);