diff --git a/.antigravity-plugin/plugin.json b/.antigravity-plugin/plugin.json index 083e093..9c7854b 100644 --- a/.antigravity-plugin/plugin.json +++ b/.antigravity-plugin/plugin.json @@ -1,7 +1,7 @@ { "$schema": "https://antigravity.google/schemas/v1/plugin.json", - "name": "opencode-dev-plugin", - "version": "0.1.0", + "name": "opencode-dev", + "version": "0.2.0", "description": "Skills for working with opencode v2: building plugins (@opencode/plugin, SDK, client), the CLI and TUI, the server HTTP API, and OpenCode Console administration and inference, with cached upstream docs.", "author": { "name": "rjstone", diff --git a/.claude-plugin/marketplace.json b/.claude-plugin/marketplace.json index 451b575..b2d2e54 100644 --- a/.claude-plugin/marketplace.json +++ b/.claude-plugin/marketplace.json @@ -1,12 +1,12 @@ { - "name": "opencode-dev-plugin", + "name": "opencode-dev", "owner": { "name": "rjstone" }, - "description": "Single-plugin marketplace for opencode-dev-plugin. The plugin is the repository root.", + "description": "Single-plugin marketplace for opencode-dev. The plugin is the repository root.", "plugins": [ { - "name": "opencode-dev-plugin", + "name": "opencode-dev", "source": "./", "description": "Skills for working with opencode v2: building plugins (@opencode/plugin, SDK, client), the CLI and TUI, the server HTTP API, and OpenCode Console administration and inference, with cached upstream docs." } diff --git a/.claude-plugin/plugin.json b/.claude-plugin/plugin.json index 5ee138a..b8b0cd2 100644 --- a/.claude-plugin/plugin.json +++ b/.claude-plugin/plugin.json @@ -1,6 +1,6 @@ { - "name": "opencode-dev-plugin", - "version": "0.1.0", + "name": "opencode-dev", + "version": "0.2.0", "description": "Skills for working with opencode v2: building plugins (@opencode/plugin, SDK, client), the CLI and TUI, the server HTTP API, and OpenCode Console administration and inference, with cached upstream docs.", "author": { "name": "rjstone", diff --git a/.cursor-plugin/plugin.json b/.cursor-plugin/plugin.json index b603923..4850c6c 100644 --- a/.cursor-plugin/plugin.json +++ b/.cursor-plugin/plugin.json @@ -1,6 +1,6 @@ { - "name": "opencode-dev-plugin", - "version": "0.1.0", + "name": "opencode-dev", + "version": "0.2.0", "description": "Skills for working with opencode v2: building plugins (@opencode/plugin, SDK, client), the CLI and TUI, the server HTTP API, and OpenCode Console administration and inference, with cached upstream docs.", "author": { "name": "rjstone", diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 7f2a64e..e9ba518 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -1,100 +1,11 @@ -# Generator tests and freshness, type check, and Claude Code validation (both profiles). -# On pushes to main, the "badges" job renders README badges (scripts/badges.sh) and -# force-pushes them as the single commit of the orphan branch "badges". -# Actions are pinned to commit SHAs (the version is in the comment). +# Runs this repo's checks (scripts/ci.sh), Claude Code validation and, on main, the badges. +# The steps live in rjstone/plugin-ci (reusable workflow, called at @main). name: check on: [push, pull_request] permissions: contents: read jobs: check: - runs-on: ubuntu-latest - outputs: - tests_passed: ${{ steps.counts.outputs.passed }} - tests_failed: ${{ steps.counts.outputs.failed }} - steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - with: - persist-credentials: false - - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 - with: - node-version: 22 - - name: Generator tests - shell: bash - run: npm test 2>&1 | tee "$RUNNER_TEMP/node-test.log" - - name: Skill tests (Python, stdlib only) - run: python3 -m unittest discover -s tests -v - - name: Generated files are up to date - run: node scripts/build.ts --check - - name: Type-check the generator and tests - run: npm run typecheck - - name: Validate the Claude Code plugin and marketplace - run: | - npx -y @anthropic-ai/claude-code@2.1.332 plugin validate . - npx -y @anthropic-ai/claude-code@2.1.332 plugin validate . --profile directory - - name: Count tests for the badge - id: counts - if: always() - shell: bash - run: | - log="$RUNNER_TEMP/node-test.log" - passed=0; failed=0 - if [ -f "$log" ]; then - passed=$(sed -n 's/^# pass \([0-9]*\)$/\1/p' "$log" | tail -1) - failed=$(sed -n 's/^# fail \([0-9]*\)$/\1/p' "$log" | tail -1) - fi - echo "passed=${passed:-0}" >> "$GITHUB_OUTPUT" - echo "failed=${failed:-0}" >> "$GITHUB_OUTPUT" - - badges: - needs: check - if: always() && github.event_name == 'push' && github.ref == 'refs/heads/main' - runs-on: ubuntu-latest permissions: - contents: write - concurrency: - group: badges - cancel-in-progress: true - steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - with: - persist-credentials: false - - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 - with: - node-version: 22 - - name: Render badges - env: - RESULT: ${{ needs.check.result }} - PASSED: ${{ needs.check.outputs.tests_passed }} - FAILED: ${{ needs.check.outputs.tests_failed }} - run: | - case "$RESULT" in - success) check="passing|brightgreen" ;; - failure) check="failing|red" ;; - *) check="$RESULT|lightgrey" ;; - esac - if [ "${FAILED:-0}" != 0 ]; then tests="$FAILED failed|red" - elif [ "${PASSED:-0}" != 0 ]; then tests="$PASSED passed|brightgreen" - else tests="unknown|lightgrey"; fi - version=$(node -p "require('./plugin.config.json').version") - license=$(node -p "require('./plugin.config.json').license") - { - echo "check|check|$check" - echo "tests|tests|$tests" - echo "version|version|v$version|blue" - echo "license|license|$license|blue" - } > "$RUNNER_TEMP/badges.txt" - bash scripts/badges.sh "$RUNNER_TEMP/badges.txt" "$RUNNER_TEMP/badges" - - name: Push to the badges branch - env: - GH_TOKEN: ${{ github.token }} - REPO: ${{ github.repository }} - SHA: ${{ github.sha }} - run: | - cd "$RUNNER_TEMP/badges" - git init -q -b badges - git config user.name "github-actions[bot]" - git config user.email "41898282+github-actions[bot]@users.noreply.github.com" - git add -A - git commit -q -m "badges for $SHA" - git push -q --force "https://x-access-token:$GH_TOKEN@github.com/$REPO.git" badges + contents: write # for the nested badges job; the nested check job lowers it to read + uses: rjstone/plugin-ci/.github/workflows/check.yml@main diff --git a/.github/workflows/notify-marketplace.yml b/.github/workflows/notify-marketplace.yml index ba31e2f..dd3fcdf 100644 --- a/.github/workflows/notify-marketplace.yml +++ b/.github/workflows/notify-marketplace.yml @@ -1,16 +1,7 @@ -# Starts rjstone/plugin-marketplace's update workflow so a new release is listed within minutes -# instead of at the marketplace's next daily run. Copied from that repo's -# docs/plugin-repo-release-workflow.yml, plus a manual trigger. -# -# Runs on a release tag push (vX.Y.Z or X.Y.Z), or by hand (Actions > notify-marketplace > Run -# workflow) for a tag pushed before this workflow existed. The marketplace resolves the latest -# release tag itself; the tag sent here only labels its run. -# -# Setup in THIS repo (Settings -> Secrets and variables -> Actions): -# - variable MARKETPLACE_APP_CLIENT_ID: the GitHub App's Client ID (App settings page, "Iv...") -# - secret MARKETPLACE_APP_PRIVATE_KEY: a private key (.pem) generated for that App -# The App needs only "Actions: Read and write" and is installed on the marketplace repo. -# Actions are pinned to commit SHAs (the version is in the comment). +# Starts rjstone/plugin-marketplace's update workflow when a release tag is pushed, or by hand. +# The steps live in rjstone/plugin-ci (reusable workflow, called at @main). +# Setup in this repo: variable MARKETPLACE_APP_CLIENT_ID and secret MARKETPLACE_APP_PRIVATE_KEY +# (the GitHub App needs only "Actions: Read and write" on the marketplace repo). name: notify-marketplace on: push: @@ -21,55 +12,13 @@ on: description: Release tag to report (empty = the latest vX.Y.Z tag) required: false type: string - permissions: contents: read - -env: - MARKETPLACE_OWNER: rjstone - MARKETPLACE_REPO: plugin-marketplace - jobs: notify: - runs-on: ubuntu-latest - steps: - - name: Find the tag - id: tag - env: - GH_TOKEN: ${{ github.token }} - EVENT: ${{ github.event_name }} - REF_NAME: ${{ github.ref_name }} - INPUT_TAG: ${{ inputs.tag }} - REPO: ${{ github.repository }} - run: | - if [ "$EVENT" = push ]; then - tag="$REF_NAME" - elif [ -n "$INPUT_TAG" ]; then - tag="$INPUT_TAG" - else - tag=$(gh api "repos/$REPO/tags" --paginate --jq '.[].name' \ - | grep -E '^v?[0-9]+\.[0-9]+\.[0-9]+$' | sort -V | tail -1) - fi - # Only a plain release tag goes on (no shell or output injection through a tag name). - if ! printf '%s' "$tag" | grep -Eqx 'v?[0-9]+\.[0-9]+\.[0-9]+'; then - echo "not a release tag: '$tag'"; exit 1 - fi - echo "tag=$tag" >> "$GITHUB_OUTPUT" - echo "reporting $tag" - - uses: actions/create-github-app-token@f418cff399f7aef4c2f0ad47e25ca7a6abbdd6fc # v3.4.0 - id: token - with: - client-id: ${{ vars.MARKETPLACE_APP_CLIENT_ID }} - private-key: ${{ secrets.MARKETPLACE_APP_PRIVATE_KEY }} - owner: ${{ env.MARKETPLACE_OWNER }} - repositories: ${{ env.MARKETPLACE_REPO }} - - name: Start the marketplace update workflow - env: - GH_TOKEN: ${{ steps.token.outputs.token }} - REPO: ${{ github.repository }} - TAG: ${{ steps.tag.outputs.tag }} - run: | - gh api -X POST "repos/$MARKETPLACE_OWNER/$MARKETPLACE_REPO/actions/workflows/update.yml/dispatches" \ - -f ref=main \ - -f "inputs[repo]=$REPO" \ - -f "inputs[tag]=$TAG" + uses: rjstone/plugin-ci/.github/workflows/notify-marketplace.yml@main + with: + tag: ${{ inputs.tag }} + client-id: ${{ vars.MARKETPLACE_APP_CLIENT_ID }} + secrets: + private-key: ${{ secrets.MARKETPLACE_APP_PRIVATE_KEY }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 270835f..1f6cd89 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,6 +1,5 @@ -# On a release tag (vX.Y.Z): build that release's notes with git-cliff (cliff.toml) and publish -# a GitHub Release. The tag itself is created by the maintainer (see AGENTS.md, "Releases"). -# Actions are pinned to commit SHAs (the version is in the comment). +# Publishes a GitHub Release with git-cliff notes when a vX.Y.Z tag is pushed. +# The steps live in rjstone/plugin-ci (reusable workflow, called at @main). name: release on: push: @@ -8,22 +7,6 @@ on: permissions: {} jobs: release: - runs-on: ubuntu-latest permissions: contents: write - steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - with: - fetch-depth: 0 - persist-credentials: false - - name: Release notes - uses: orhun/git-cliff-action@a9a95522b26fe6403f7bb24031f21fb573d0f5ff # v4.9.1 - with: - config: cliff.toml - args: --latest --strip header - env: - OUTPUT: RELEASE_NOTES.md - - name: Publish the release - uses: softprops/action-gh-release@8a0cd651e5b2365bd640854a3fa5dfc70e4875f3 # v3.0.4 - with: - body_path: RELEASE_NOTES.md + uses: rjstone/plugin-ci/.github/workflows/release.yml@main diff --git a/.kimi-plugin/plugin.json b/.kimi-plugin/plugin.json index bf27770..93242b3 100644 --- a/.kimi-plugin/plugin.json +++ b/.kimi-plugin/plugin.json @@ -1,6 +1,6 @@ { - "name": "opencode-dev-plugin", - "version": "0.1.0", + "name": "opencode-dev", + "version": "0.2.0", "description": "Skills for working with opencode v2: building plugins (@opencode/plugin, SDK, client), the CLI and TUI, the server HTTP API, and OpenCode Console administration and inference, with cached upstream docs.", "author": { "name": "rjstone", diff --git a/AGENTS.md b/AGENTS.md index 89ad9a7..edb2a7c 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -7,25 +7,16 @@ user must not see. ## What this repo is -A template for **one plugin that installs, from the same repository, into every major coding -harness and through `npx skills`**: Claude Code, OpenAI Codex, GitHub Copilot CLI, VS Code agent -plugins, Cursor, Google Antigravity, Gemini CLI, Qwen Code, Kiro, Factory Droid, Augment Auggie, -JetBrains Junie, Devin, Hermes, Kimi Code, Muse, opencode, Pi, Cline and Amp. +A coding-agent plugin with four opencode v2 skills, made from `rjstone/harness-plugin-template` +and shipped to every harness that template supports. -Every manifest is generated from `plugin.config.json` by `scripts/build.ts`. This file documents -the full tree and every metadata file, including parts a given plugin won't use: unused folders -are described here, not created empty. +## This plugin: opencode-dev -The layout comes from each harness's docs (read 2026-11-27) and was checked against -`obra/superpowers` v7.0.2, a long-lived plugin shipped to many harnesses. Items marked **[U]** -were not confirmed in a primary source; **[T]** items need a real install test and are tracked -in `TODO.md`. - -## This plugin: opencode-dev-plugin - -This repo was made from `rjstone/harness-plugin-template`; the template reference below still -applies. It ships four skills for opencode v2, moved here with their history from -`rjstone/agent-skills` (the user, 2026-11-28): +The plugin is named `opencode-dev`, the repo name without `-plugin` (the user, 2026-11-28); +its skills show as `opencode-dev:`. Only `gemini-extension.json` carries the repo name. +The `opencode-api` cache folder keeps the name `opencode-dev-plugin`, so existing caches still +work. The template reference below the marker applies. The plugin ships four skills for +opencode v2, moved here with their history from `rjstone/agent-skills` (the user, 2026-11-28): - `opencode-build` - opencode v2 Build docs (plugins, client, SDK) cached as Markdown in `references/`, with `scripts/refresh_references.py` to update them and `ERRATA.md` for known @@ -55,19 +46,30 @@ Rules carried over from `agent-skills`: `if not selected(""): raise unittest.SkipTest(...)` (`tests/_select.py`; `SKILLS=a,b` limits a run). Run `python3 -m unittest discover -s tests`. No network in tests. + ## Making a plugin from the template -1. Create a repo from the template. Its folder name is the plugin name (Gemini and Qwen expect - them to match). -2. Edit `plugin.config.json`: `name` (see "Name rule"), `displayName`, `description`, - `shortDescription`, `author`, URLs, `keywords`, `category`, and `harnesses` (turn off what the - plugin doesn't ship to). +1. Create a repo from the template (rjstone/harness-plugin-template) and name it + `-plugin`, where `` is the plugin's name (see "Name rule"). +2. Edit `plugin.config.json`: `name` (``; the generator refuses anything else for a + `-plugin` repo, and Gemini's manifest gets the repo name by itself), `displayName`, + `description`, `shortDescription`, `author`, URLs (`repository` decides the repo name), + `keywords`, `category`, and `harnesses` (turn off what the plugin doesn't ship to). 3. Replace `skills/example/` with real skills, and `assets/icon.png` with the plugin's icon. 4. Add optional parts (agents, hooks, MCP, code) from "Layout" below. 5. `node scripts/build.ts`, then commit everything it wrote. CI fails if a generated file is stale (`--check`). 6. Update `README.md` (install table, owner/repo, and the badge row's owner/repo) and `cliff.toml` (commit link). +7. Put the repo's own checks in `scripts/ci.sh` (see "Checks"). It starts with the template's + three; add yours below them. +8. In a repo just created from the template, delete the template's own files under + `docs/superpowers/` (its shared-CI spec and plans). A plugin's own specs and plans may live + there. +9. In the repo's Actions settings, set the variable `MARKETPLACE_APP_CLIENT_ID` and the secret + `MARKETPLACE_APP_PRIVATE_KEY`, or delete `.github/workflows/notify-marketplace.yml` if the + plugin isn't listed in `rjstone/plugin-marketplace` (the drift list marks that file optional, + so a deleted copy stays deleted). ## Rules @@ -143,10 +145,12 @@ the plugin uses it; **doc** = described here only, not in the template. ├── cline/ doc Cline plugin (package.json "cline" key) ├── amp/ doc Amp plugin module (/index.ts) ├── scripts/ core the generator (build.ts, generate.ts, types.ts, frontmatter.ts), -│ badges.sh (README badges, see "Badges") -├── tests/build.test.ts core generator tests (node:test, throwaway folders, no network) -├── .github/workflows/ -│ ├── check.yml core tests, --check, type check, claude plugin validate; badges job +│ ci.sh (the repo's own checks), template-drift.sh and +│ template-files.txt (see "Staying in step with the template") +├── tests/ core build.test.ts (generator tests) and template-drift.test.ts +│ (node:test, throwaway folders, no network) +├── .github/workflows/ three thin callers of rjstone/plugin-ci's reusable workflows +│ ├── check.yml core scripts/ci.sh, claude plugin validate, test counts; badges job │ ├── release.yml core GitHub Release from git-cliff notes on a vX.Y.Z tag │ └── notify-marketplace.yml opt start rjstone/plugin-marketplace's update job ├── AGENTS.md, CLAUDE.md core CLAUDE.md is "@AGENTS.md" plus Claude-only notes @@ -193,7 +197,7 @@ Modules: `types.ts` (config shape, `validateConfig`, `nameProblem`), `frontmatte | Field | Rules | Used by | |---|---|---| -| `name` | see "Name rule" | every manifest | +| `name` | see "Name rule"; for a repo named `-plugin` it must be `` | every manifest except Gemini's | | `displayName` | ≤ 30 characters (Codex) | Codex, Cursor, Antigravity, Kimi, Muse | | `version` | semver `X.Y.Z`; **the only place the version is written** | every manifest, `package.json` | | `description` | ≤ 1024 characters | every manifest; Codex `longDescription` | @@ -243,7 +247,9 @@ Modules: `types.ts` (config shape, `validateConfig`, `nameProblem`), `frontmatte and passes the name rule; `description` 1-1024 characters, starting "Use when"; no nested `SKILL.md`; `metadata.version` while the opencode catalog is on. - Agents: frontmatter with `name` and `description`. -- The icon exists; a warning if the repo folder name differs from `name`. +- The icon exists. +- Naming: an error if the repo name (the last segment of `repository`) ends in `-plugin` and + `name` isn't the repo name without that suffix. ## Name rule @@ -251,6 +257,16 @@ Modules: `types.ts` (config shape, `validateConfig`, `nameProblem`), `frontmatte periods (Antigravity forbids them). Not `claude`, and not starting `claude-`, `anthropic-` or `cc-plugin-` (Claude rejects these). The same rule applies to skill names. +Repo rule: the repo name is the last path segment of `repository` (a trailing `.git` or `/` +removed). If it ends in `-plugin`, `name` must be the repo name without that suffix, so the repo +`docshelf-plugin` holds the plugin `docshelf`, and the generator reports anything else as an error. +With no `repository`, or a repo name that doesn't end in `-plugin`, there is no rule. + +Gemini exception: `gemini-extension.json` carries the repo name, not `name`. Gemini's reference +says "we expect this name to match the extension directory name", and a cloned or linked +extension folder is named after the repo. Qwen converts the same file. Every other manifest +carries `name`. + ## The five format families | Family | Harnesses | What they read | @@ -324,29 +340,63 @@ never from a hard-coded path. ## Checks -`check.yml` runs on every push and pull request: `npm test`, `node scripts/build.ts --check`, -`npm run typecheck`, and `claude plugin validate .` in both profiles (`--profile directory` -adds the plugin-directory checks: README ≥ 40 words, licence, file sizes). Run the same before -committing. No validator exists for Codex, Copilot, VS Code, Cursor, Gemini, Qwen, Kiro, Droid, -Augment, Junie or Devin; `agy plugin validate` (Antigravity) and `hermes plugins validate` exist -but aren't in CI yet (`TODO.md`). +CI is `check.yml`, a thin caller of the reusable `check` workflow in +[rjstone/plugin-ci](https://github.com/rjstone/plugin-ci). On every push and pull request it runs +`bash scripts/ci.sh`, then `claude plugin validate` in both profiles (`--profile directory` adds +the plugin-directory checks: README ≥ 40 words, licence, file sizes), then the drift report +(see "Staying in step with the template"). `plugin-ci`'s README documents the inputs and the +`scripts/ci.sh` contract; this file doesn't repeat them. + +`scripts/ci.sh` holds the repo's own checks: `npm test`, `node scripts/build.ts --check` and +`npm run typecheck`, plus whatever the plugin adds. Before committing, run +`bash scripts/ci.sh`, `claude plugin validate .` and `claude plugin validate . --profile +directory`. The script works with no environment set. In CI it also gets two variables: + +- `CI_BASE_SHA`: the pull request's base commit, else the commit before the push. Use it for + checks that compare against the base, such as "a changed skill needs a version bump". It is + all zeros on the first push of a branch, and with the default shallow checkout the commit it + names is usually not in the clone. A check that compares against it must treat a missing or + all-zero base as nothing to compare. A repo that needs the history passes `fetch-depth: 0` in + its `check.yml`; the drift report then lists that file as differing, which is expected. +- `CI_BADGES`: a file the script may append extra badge lines to (see "Badges"). + +No validator exists for Codex, Copilot, VS Code, Cursor, Gemini, Qwen, Kiro, Droid, Augment, +Junie or Devin; `agy plugin validate` (Antigravity) and `hermes plugins validate` exist but aren't +in `scripts/ci.sh` yet (`TODO.md`). ### Badges README badges are SVG files on the orphan branch `badges`, linked as `https://raw.githubusercontent.com///badges/.svg`; no badge service is used -(the user, 2026-11-28). On pushes to `main`, `check.yml`'s `badges` job (after `check`, even when -it fails) writes one `name|label|message|color` line per badge and runs -`bash scripts/badges.sh SPEC OUTDIR`, which renders them offline with the pinned npm -`badge-maker` (shields.io's renderer). The job then force-pushes them as the branch's only -commit. It is the only job with `contents: write` and never runs on pull requests. Badges: -`check` (the `check` job's result), `tests` (from `npm test`'s `# pass` / `# fail` lines), -`version` and `license` (from `plugin.config.json`). A plugin with other test suites adds their -counts in the "Count tests" step. A new badge appears after the next push to `main`; GitHub's -image proxy can show an old one for a few minutes. - -Actions are pinned to commit SHAs (version in a comment), with `permissions: contents: read`; -pass event values to scripts through `env:`, never by `${{ }}` inside `run:`. +(the user, 2026-11-28). `plugin-ci` renders them on pushes to the default branch, offline, and +force-pushes them as the branch's only commit. `check` (the job's result), `tests`, `version` and +`license` (from `plugin.config.json`) come for free. `tests` adds up the summaries in the log of +`scripts/ci.sh` and the validation step: node:test, unittest and `claude plugin test`. A repo +adds a badge by appending a `name|label|message|color` line to the file named by `$CI_BADGES` in +`scripts/ci.sh`. A new badge appears after the next push to the default branch; GitHub's image +proxy can show an old one for a few minutes. + +The workflow callers reference `rjstone/plugin-ci/...@main`. A pin to a SHA would bring back the +same update in every plugin repo, and `main` has the same owner as the callers. Third-party +actions are pinned to commit SHAs inside `plugin-ci`, and nothing else is in this repo's +workflows. Pass event values to scripts through `env:`, never by `${{ }}` inside `run:`. + +## Staying in step with the template + +A plugin made from the template keeps some files identical to the template's: the generator +modules, its tests, `tsconfig.json`, the three workflow callers, `CLAUDE.md`, the drift script +and its list, and this file from the `template-reference` marker to the end. +`scripts/template-files.txt` names them (one path per line; `path :: MARKER` means from the +first line containing MARKER to the end of the file; `? path` marks a whole file optional: it +is skipped while the plugin has no copy, and compared and applied once it exists). + +- `bash scripts/template-drift.sh` fetches the template's `main` and compares each listed file. + In CI it runs after validation and prints one warning per differing file; it never + fails the run. It does nothing in the template itself. +- `bash scripts/template-drift.sh --apply` copies the template's versions over the local ones. + Review the diff and commit it. +- Fix a shared file in the template first, then apply it in each plugin repo. A fix made only in + a plugin repo is overwritten by the next `--apply`. ## Commits, versions and releases @@ -356,6 +406,8 @@ pass event values to scripts through `env:`, never by `${{ }}` inside `run:`. - Commit straight to `main` unless a change wants review on a branch. - The version lives only in `plugin.config.json`; bump it there and rebuild. - `CHANGELOG.md` is generated: `npx git-cliff@2.14.2 -o CHANGELOG.md`, never by hand. +- Merge a release branch by fast-forward or a merge commit, never squash or rebase, so the + tagged commit stays in `main`'s history. Releasing `vX.Y.Z`: @@ -363,10 +415,12 @@ Releasing `vX.Y.Z`: 2. `npx git-cliff@2.14.2 --tag vX.Y.Z -o CHANGELOG.md`; commit everything as `chore(release): vX.Y.Z` and push `main`. 3. Tag the commit `vX.Y.Z` and push the tag (cloud agent sessions can't push tags: ask the - maintainer). `release.yml` publishes a GitHub Release with git-cliff's notes. + maintainer). `release.yml` publishes a GitHub Release with git-cliff's notes, and refuses a + tag that differs from `version` in the manifest. 4. If the plugin is listed in `rjstone/plugin-marketplace`, `notify-marketplace.yml` starts its update job. It needs the variable `MARKETPLACE_APP_CLIENT_ID` and the secret - `MARKETPLACE_APP_PRIVATE_KEY` in this repo's Actions settings. Delete the workflow otherwise. + `MARKETPLACE_APP_PRIVATE_KEY` in this repo's Actions settings. Delete the workflow + otherwise; the drift check leaves a deleted copy alone. Tags must be `vX.Y.Z` (the marketplace ignores other forms). diff --git a/CHANGELOG.md b/CHANGELOG.md index 5dec807..f480a88 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,11 +3,46 @@ All notable changes to this repository. Generated by [git-cliff](https://git-cliff.org) from the commit history (see `cliff.toml`); don't edit by hand. -## [Unreleased] +## [0.2.0] - 2026-11-28 + +### Features + +- **BREAKING** Rename the plugin to opencode-dev ([5c0c686](https://github.com/rjstone/opencode-dev-plugin/commit/5c0c68685591181e37d602383e4d368586b18433)) + +### Fixes + +- **generator:** Copy the icon to .claude-plugin/ instead of an icon key ([4e2dddc](https://github.com/rjstone/opencode-dev-plugin/commit/4e2dddccc839bf4ce59e7d88adc951fde5ed35a6)) + +### Documentation + +- Align install table and dev steps with shared CI ([10eb660](https://github.com/rjstone/opencode-dev-plugin/commit/10eb660b1398742239be5bc316fe4f1dff1c009b)) + +### Maintenance + +- Sync the generator, tests, workflows and reference docs from the template ([b543e24](https://github.com/rjstone/opencode-dev-plugin/commit/b543e2465cddf688aae86306f9d2e87bf0310339)) + +## [0.1.1] - 2026-11-28 + +### Features + +- **opencode-api:** **BREAKING** Download the OpenAPI spec at run time instead of shipping it ([94b4710](https://github.com/rjstone/opencode-dev-plugin/commit/94b471055938edd66dceda0ff81d00a6f6566f1d)) + +## [0.1.0] - 2026-11-28 ### Features - Import opencode skills with history from rjstone/agent-skills ([6e34cfe](https://github.com/rjstone/opencode-dev-plugin/commit/6e34cfe31469c0e2ffb60f5c2249ef879e29856a)) +- Ship the opencode skills as opencode-dev-plugin ([7822b9f](https://github.com/rjstone/opencode-dev-plugin/commit/7822b9fea70eef0d6e3bbc32e0986fd14207e114)) + +### Documentation + +- Import opencode-build plan and SkillSpector baselines from rjstone/agent-skills ([f2e0d81](https://github.com/rjstone/opencode-dev-plugin/commit/f2e0d81b93bd4a32408e137f0cf7c1388b87b1ad)) +- TODO for SkillSpector CI, openapi.json size, first release ([86536b4](https://github.com/rjstone/opencode-dev-plugin/commit/86536b4424093669f8963fc3a58488551b2a60ef)) +- TODO items carried over from rjstone/agent-skills ([862b612](https://github.com/rjstone/opencode-dev-plugin/commit/862b612e0177a4835a6b7be6287947118fda832b)) + +### Maintenance + +- Stop tracking Python bytecode caches ([60ab0b6](https://github.com/rjstone/opencode-dev-plugin/commit/60ab0b67933516021ff4af3a35e1bd671cd71038)) ### Changes @@ -44,5 +79,8 @@ commit history (see `cliff.toml`); don't edit by hand. - Refresh references (0.1.1) (#26) ([5c43dc0](https://github.com/rjstone/opencode-dev-plugin/commit/5c43dc0793ea85f5d48b814fd80c2f392006a33d)) - Merge branch 'main' into update/opencode-api ([19637a0](https://github.com/rjstone/opencode-dev-plugin/commit/19637a0e96879d209ff75fb0f7d78f80dc433cd5)) - Add opencode-console skill (0.1.0) (#28) ([a49146c](https://github.com/rjstone/opencode-dev-plugin/commit/a49146c828c77f377ae54bc5fdb62504efcca4b6)) +- Archive the opencode-build plan; note that skills find fails on the web ([407b574](https://github.com/rjstone/opencode-dev-plugin/commit/407b57450e280058896080e73d9b5585dfb96ffb)) +- SkillSpector scan of every skill with per-skill baselines ([ad3c7e5](https://github.com/rjstone/opencode-dev-plugin/commit/ad3c7e573eacae7938e2b8b04bc7052453ea6c3c)) +- SkillSpector scan of every skill with per-skill baselines (#36) ([6d045a3](https://github.com/rjstone/opencode-dev-plugin/commit/6d045a3a54857679aa45b52b95556b9da87126d0)) diff --git a/CLAUDE.md b/CLAUDE.md index 79e0dd0..d057e36 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -2,8 +2,8 @@ # Claude Code notes -- Before committing, run `npm test`, `node scripts/build.ts --check`, `npm run typecheck`, - `claude plugin validate .` and `claude plugin validate . --profile directory`. +- Before committing, run `bash scripts/ci.sh`, `claude plugin validate .` and + `claude plugin validate . --profile directory`. - Try the plugin in a session with `claude --plugin-dir .` (skills appear as `:`). - Cloud sessions can't push tags: ask the maintainer. diff --git a/README.md b/README.md index 61e5421..6b409d3 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ -# opencode-dev-plugin +# opencode-dev [![check](https://raw.githubusercontent.com/rjstone/opencode-dev-plugin/badges/check.svg)](https://github.com/rjstone/opencode-dev-plugin/actions/workflows/check.yml) ![tests](https://raw.githubusercontent.com/rjstone/opencode-dev-plugin/badges/tests.svg) -![version](https://raw.githubusercontent.com/rjstone/opencode-dev-plugin/badges/version.svg) +[![version](https://raw.githubusercontent.com/rjstone/opencode-dev-plugin/badges/version.svg)](https://github.com/rjstone/opencode-dev-plugin/releases) ![license](https://raw.githubusercontent.com/rjstone/opencode-dev-plugin/badges/license.svg) Skills for developing with [opencode](https://opencode.ai) v2, for any coding agent. Each skill @@ -21,11 +21,11 @@ The skills moved here, with their history, from ## Installing - | Harness | Command | |---|---| -| Claude Code | `/plugin marketplace add rjstone/opencode-dev-plugin`, then `/plugin install opencode-dev-plugin@opencode-dev-plugin` | -| OpenAI Codex | `codex plugin marketplace add rjstone/opencode-dev-plugin` | +| Claude Code | `/plugin marketplace add rjstone/plugin-marketplace`, then `/plugin install opencode-dev@rjstone` | +| Claude Code, direct | `/plugin marketplace add rjstone/opencode-dev-plugin`, then `/plugin install opencode-dev@opencode-dev` | +| OpenAI Codex | `codex plugin marketplace add rjstone/plugin-marketplace` | | GitHub Copilot CLI | `copilot plugin install rjstone/opencode-dev-plugin` | | VS Code | add `"rjstone/opencode-dev-plugin"` to the `chat.plugins.marketplaces` setting | | Cursor | install from the Cursor marketplace once published | @@ -33,21 +33,28 @@ The skills moved here, with their history, from | Gemini CLI | `gemini extensions install https://github.com/rjstone/opencode-dev-plugin` | | Qwen Code | `qwen extensions install rjstone/opencode-dev-plugin` | | Kiro | Powers panel, Add Custom Power, then the repository URL | -| Factory Droid | `droid plugin marketplace add rjstone/opencode-dev-plugin`, then `droid plugin install opencode-dev-plugin@opencode-dev-plugin` | +| Factory Droid | `droid plugin marketplace add rjstone/opencode-dev-plugin`, then `droid plugin install opencode-dev@opencode-dev` | | Augment Auggie | `auggie plugin marketplace add rjstone/opencode-dev-plugin` | -| JetBrains Junie CLI | `/extensions marketplace add rjstone/opencode-dev-plugin`, then `/extensions install opencode-dev-plugin` | +| JetBrains Junie CLI | `/extensions marketplace add rjstone/opencode-dev-plugin`, then `/extensions install opencode-dev` | | Devin | `devin plugins install rjstone/opencode-dev-plugin` | | Hermes | `hermes plugins install rjstone/opencode-dev-plugin` | | opencode | add `https://raw.githubusercontent.com/rjstone/opencode-dev-plugin/main/skills/` to `skills` in `opencode.json` | -| Pi | `pi install git:github.com/rjstone/opencode-dev-plugin` | +| Pi | `pi install git:github.com/rjstone/opencode-dev-plugin@vX.Y.Z` | | Any agent, skills only | `npx skills add rjstone/opencode-dev-plugin` | Some of these are still being tested; see [`TODO.md`](TODO.md). +### Renamed in 0.2.0 + +The plugin was called `opencode-dev-plugin`. Installs under the old id +(`opencode-dev-plugin@rjstone`) get no more updates: uninstall it and install +`opencode-dev@rjstone`. Skills are now `opencode-dev:`. + ## Developing [`AGENTS.md`](AGENTS.md) documents the layout, the generator and the skill maintenance rules. -Run `npm test` and `python3 -m unittest discover -s tests` before committing. +Before committing, run `bash scripts/ci.sh`, `claude plugin validate .` and +`claude plugin validate . --profile directory`. ## Licence diff --git a/TODO.md b/TODO.md index 6a119b6..4380bd8 100644 --- a/TODO.md +++ b/TODO.md @@ -62,13 +62,11 @@ Settled by superpowers (no test needed): - [ ] Re-check every harness's docs before the first release of the template: several formats changed in 2026. -## opencode-dev-plugin +## opencode-dev - [ ] SkillSpector CI: `.skillspector/.yaml` baselines came over from `rjstone/agent-skills`, but this repo has no SkillSpector workflow yet. Port `skillspector.yml` and `scripts/skillspector_ci.py` from there, or run the scan by hand before releases. -- [ ] Tag the first release `v0.1.0` (the maintainer: cloud sessions can't push tags), then add - the plugin to `rjstone/plugin-marketplace`. - [ ] `opencode-console`: still missing upstream (checked 2026-11-08, still true 2026-11-22): a REST API for members, usage, budgets and billing. Usage is readable only through the Console MCP tools (`get_usage`, `get_member_usage`). Revisit if a REST account API appears. diff --git a/gemini-extension.json b/gemini-extension.json index 2864846..ce483b7 100644 --- a/gemini-extension.json +++ b/gemini-extension.json @@ -1,5 +1,5 @@ { "name": "opencode-dev-plugin", - "version": "0.1.0", + "version": "0.2.0", "description": "Skills for working with opencode v2: building plugins (@opencode/plugin, SDK, client), the CLI and TUI, the server HTTP API, and OpenCode Console administration and inference, with cached upstream docs." } diff --git a/package.json b/package.json index 68573a1..5d0692b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { - "name": "opencode-dev-plugin", - "version": "0.1.0", + "name": "opencode-dev", + "version": "0.2.0", "description": "Skills for working with opencode v2: building plugins (@opencode/plugin, SDK, client), the CLI and TUI, the server HTTP API, and OpenCode Console administration and inference, with cached upstream docs.", "license": "MIT", "author": "rjstone", diff --git a/plugin.config.json b/plugin.config.json index 2bd3505..8beae8e 100644 --- a/plugin.config.json +++ b/plugin.config.json @@ -1,7 +1,7 @@ { - "name": "opencode-dev-plugin", + "name": "opencode-dev", "displayName": "OpenCode Dev", - "version": "0.1.0", + "version": "0.2.0", "description": "Skills for working with opencode v2: building plugins (@opencode/plugin, SDK, client), the CLI and TUI, the server HTTP API, and OpenCode Console administration and inference, with cached upstream docs.", "shortDescription": "opencode v2 dev skills", "author": { diff --git a/plugin.json b/plugin.json index e62d623..57870d8 100644 --- a/plugin.json +++ b/plugin.json @@ -1,7 +1,7 @@ { "$schema": "https://agent-plugins.org/schemas/1.0.0/plugin.schema.json", - "name": "opencode-dev-plugin", - "version": "0.1.0", + "name": "opencode-dev", + "version": "0.2.0", "description": "Skills for working with opencode v2: building plugins (@opencode/plugin, SDK, client), the CLI and TUI, the server HTTP API, and OpenCode Console administration and inference, with cached upstream docs.", "author": { "name": "rjstone", diff --git a/scripts/badges.sh b/scripts/badges.sh deleted file mode 100755 index e401c1b..0000000 --- a/scripts/badges.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env bash -# Render README badges as SVG files, offline, with shields.io's own renderer (badge-maker). -# -# bash scripts/badges.sh SPEC OUTDIR -# -# SPEC has one badge per line: name|label|message|color (color: a badge-maker name such as -# brightgreen, red, blue, lightgrey, or #rgb / #rrggbb). Each becomes OUTDIR/.svg. -# Empty lines and lines starting with # are skipped. CI (check.yml, job "badges") writes SPEC -# and pushes OUTDIR to the orphan branch "badges". -set -euo pipefail - -BADGE_MAKER="badge-maker@6.0.0" # pinned; bump on purpose - -spec=${1:?usage: badges.sh SPEC OUTDIR} -out=${2:?usage: badges.sh SPEC OUTDIR} -mkdir -p "$out" - -while IFS='|' read -r name label message color || [ -n "${name:-}" ]; do - case "$name" in ''|'#'*) continue ;; esac - if ! [[ "$name" =~ ^[a-z0-9-]+$ ]]; then - echo "badges.sh: bad badge name: $name" >&2 - exit 1 - fi - npx -y -p "$BADGE_MAKER" badge "$label" "$message" ":$color" > "$out/$name.svg" - echo "wrote $out/$name.svg ($label: $message)" -done < "$spec" diff --git a/scripts/ci.sh b/scripts/ci.sh new file mode 100755 index 0000000..adddf1e --- /dev/null +++ b/scripts/ci.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash +# This repo's own checks. The shared check workflow (rjstone/plugin-ci) runs it in CI; run it +# by hand before committing. Claude Code validation is separate (see CLAUDE.md). +set -euo pipefail +cd "$(dirname "$0")/.." +npm test +node scripts/build.ts --check +npm run typecheck +python3 -m unittest discover -s tests -v diff --git a/scripts/generate.ts b/scripts/generate.ts index 80500d2..61da672 100644 --- a/scripts/generate.ts +++ b/scripts/generate.ts @@ -4,7 +4,7 @@ import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync } from 'node:fs'; import { basename, dirname, join, relative, sep } from 'node:path'; import { parseFrontmatter } from './frontmatter.ts'; -import { nameProblem, validateConfig } from './types.ts'; +import { nameProblem, repoNameOf, validateConfig } from './types.ts'; import type { Config, Harness, McpServer, McpSource } from './types.ts'; export const AP_PLUGIN_SCHEMA = 'https://agent-plugins.org/schemas/1.0.0/plugin.schema.json'; @@ -220,10 +220,9 @@ export function plan(root: string, configPath = join(root, 'plugin.config.json') const on = c.harnesses; const exists = (p: string) => existsSync(join(root, p)); - if (basename(root) !== c.name) { - warnings.push(`the repo folder is "${basename(root)}" but name is "${c.name}": Gemini and Qwen expect them to match`); - } - if (!exists(c.icon)) errors.push(`icon ${c.icon} does not exist`); + if (c.icon in FIXED_OUTPUTS) { + errors.push(`icon must not be a generated file (${c.icon}): keep the source icon elsewhere, such as assets/icon.png`); + } else if (!exists(c.icon)) errors.push(`icon ${c.icon} does not exist`); const skills = readSkills(root, on.opencodeCatalog, errors); if (skills.length === 0) warnings.push('skills/ holds no skills'); @@ -260,7 +259,7 @@ export function plan(root: string, configPath = join(root, 'plugin.config.json') // No `icon` key: Claude Code finds .claude-plugin/icon.png by itself, and the claude.ai // marketplace sync (Agent SDK) warns about `icon` as an unknown key and strips it. files.set('.claude-plugin/plugin.json', json(merge(common, c.claude))); - if (c.icon !== '.claude-plugin/icon.png' && exists(c.icon)) { + if (exists(c.icon)) { files.set('.claude-plugin/icon.png', readFileSync(join(root, c.icon))); } files.set('.claude-plugin/marketplace.json', json(merge({ @@ -289,8 +288,10 @@ export function plan(root: string, configPath = join(root, 'plugin.config.json') if (mcp) files.set('mcp_config.json', json({ mcpServers: mcpServers(mcp, 'antigravity', errors) })); } if (on.gemini) { + const repo = repoNameOf(c.repository); + const geminiName = repo?.endsWith('-plugin') ? repo : c.name; files.set('gemini-extension.json', json(merge(clean({ - name: c.name, version: c.version, description: c.description, + name: geminiName, version: c.version, description: c.description, contextFileName: exists('GEMINI.md') ? 'GEMINI.md' : undefined, mcpServers: mcp ? mcpServers(mcp, 'gemini', errors) : undefined, }), c.gemini))); diff --git a/scripts/template-drift.sh b/scripts/template-drift.sh new file mode 100644 index 0000000..7cf3bff --- /dev/null +++ b/scripts/template-drift.sh @@ -0,0 +1,213 @@ +#!/usr/bin/env bash +# shellcheck disable=SC2317 # the last line is a safety net: main exits by itself +# Report (or, with --apply, fix) drift between this plugin repo and the template it was made from. +# Usage: bash scripts/template-drift.sh [--apply] [TEMPLATE_DIR] (run from the plugin repo's root) +# The list of files is the template's scripts/template-files.txt. A line is "PATH" (the whole +# file) or "PATH :: MARKER" (from the first line containing MARKER to the end of the file). +# A "?" before a whole-file PATH marks it optional: skipped while the plugin has no such file. +# Report mode always exits 0, so CI can run it as a non-blocking step. +set -u + +# Everything is inside main, and the last line runs it, so bash has parsed the whole script +# before --apply can replace this file. +main() { + + TEMPLATE_REPO="rjstone/harness-plugin-template" + TEMPLATE_URL="https://github.com/$TEMPLATE_REPO" + CLONE_URL="${TEMPLATE_DRIFT_URL:-$TEMPLATE_URL}" + + apply=0 + template_dir="" + for arg in "$@"; do + case "$arg" in + --apply) apply=1 ;; + -*) echo "usage: template-drift.sh [--apply] [TEMPLATE_DIR]" >&2; exit 2 ;; + *) template_dir="$arg" ;; + esac + done + + strip_url() { + local u="${1%/}" + u="${u%.git}" + printf '%s' "${u%/}" + } + + repository="" + if [ -f plugin.config.json ]; then + repository="$(node -e 'try{const r=JSON.parse(require("fs").readFileSync("plugin.config.json","utf8")).repository;process.stdout.write(typeof r==="string"?r:"")}catch{}' 2>/dev/null)" + fi + if [ -n "$repository" ] && [ "$(strip_url "$repository")" = "$(strip_url "$TEMPLATE_URL")" ]; then + echo "template-drift: this is the template; nothing to compare" + exit 0 + fi + + if [ -z "$template_dir" ]; then + tmp="$(mktemp -d)" + trap 'rm -rf "$tmp"' EXIT + if ! git clone --depth 1 --quiet "$CLONE_URL" "$tmp/template" >/dev/null 2>&1; then + echo "template-drift: could not fetch the template" + [ "$apply" -eq 1 ] && exit 1 + exit 0 + fi + template_dir="$tmp/template" + fi + + list="$template_dir/scripts/template-files.txt" + if [ ! -f "$list" ]; then + echo "template-drift: could not fetch the template" + [ "$apply" -eq 1 ] && exit 1 + exit 0 + fi + + trim() { + local s="$1" + s="${s#"${s%%[![:space:]]*}"}" + s="${s%"${s##*[![:space:]]}"}" + printf '%s' "$s" + } + + paths=() + markers=() + optionals=() + while IFS= read -r line || [ -n "$line" ]; do + line="$(trim "$line")" + case "$line" in '' | '#'*) continue ;; esac + optional=0 + if [ "${line:0:1}" = "?" ]; then + optional=1 + line="$(trim "${line:1}")" + fi + path="$line" + marker="" + if [[ "$line" == *' :: '* ]]; then + path="$(trim "${line%% :: *}")" + marker="$(trim "${line#* :: }")" + fi + case "$path" in + /* | *..*) + echo "template-files.txt: bad path \"$path\"" >&2 + exit 1 + ;; + esac + paths+=("$path") + markers+=("$marker") + optionals+=("$optional") + done <"$list" + + total=${#paths[@]} + differ=0 + applied=0 + failed=0 + + # Print a finding: a plain line, or a GitHub Actions warning annotation. + report() { # path text + if [ "${GITHUB_ACTIONS:-}" = "true" ]; then + echo "::warning file=$1::$2 ($TEMPLATE_REPO)" + else + echo "$2" + fi + } + + # Line number of the first line of FILE containing MARKER (empty if none). + marker_line() { + grep -nF -m1 -e "$2" "$1" 2>/dev/null | head -n1 | cut -d: -f1 + } + + # Write stdin to PATH through a temporary file in the same directory, then move it into place, + # so a running script is never overwritten in place (bash reads a script as it runs). + put_file() { # path + local dir tmp + dir="$(dirname "$1")" + mkdir -p "$dir" || return 1 + [ -d "$1" ] && return 1 + tmp="$(mktemp "$dir/.drift.XXXXXX")" || return 1 + if [ -f "$1" ]; then cp -p "$1" "$tmp" 2>/dev/null; else chmod 644 "$tmp"; fi + if cat >"$tmp" && mv -f "$tmp" "$1"; then return 0; fi + rm -f "$tmp" + return 1 + } + + # Apply: write stdin to PATH and say so, or say it failed. + apply_file() { # path note + if put_file "$1"; then + applied=$((applied + 1)) + echo "updated $1$2" + else + echo "$1: could not write" >&2 + failed=1 + fi + } + + for i in "${!paths[@]}"; do + path="${paths[$i]}" + marker="${markers[$i]}" + src="$template_dir/$path" + if [ "${optionals[$i]}" = 1 ] && [ -z "$marker" ] && [ ! -f "$path" ]; then + total=$((total - 1)) + continue + fi + if [ ! -f "$src" ]; then + differ=$((differ + 1)) + report "$path" "$path: not in the template" + [ "$apply" -eq 1 ] && failed=1 + continue + fi + + if [ -z "$marker" ]; then + if [ -f "$path" ] && cmp -s "$src" "$path"; then continue; fi + differ=$((differ + 1)) + if [ "$apply" -eq 1 ]; then + apply_file "$path" "" <"$src" + elif [ -f "$path" ]; then + report "$path" "$path differs from the template" + else + report "$path" "$path is missing" + fi + continue + fi + + tn="$(marker_line "$src" "$marker")" + if [ -z "$tn" ]; then + differ=$((differ + 1)) + report "$path" "$path: marker \"$marker\" not found in the template" + [ "$apply" -eq 1 ] && failed=1 + continue + fi + if [ ! -f "$path" ]; then + differ=$((differ + 1)) + if [ "$apply" -eq 1 ]; then + apply_file "$path" "" <"$src" + else + report "$path" "$path is missing" + fi + continue + fi + ln="$(marker_line "$path" "$marker")" + if [ -z "$ln" ]; then + differ=$((differ + 1)) + if [ "$apply" -eq 1 ]; then + echo "$path: marker \"$marker\" not found" >&2 + failed=1 + else + report "$path" "$path: marker \"$marker\" not found" + fi + continue + fi + if [ "$(tail -n +"$tn" "$src")" = "$(tail -n +"$ln" "$path")" ]; then continue; fi + differ=$((differ + 1)) + if [ "$apply" -eq 1 ]; then + apply_file "$path" " (below the marker)" < <(head -n "$((ln - 1))" "$path"; tail -n +"$tn" "$src") + else + report "$path" "$path differs from the template below the marker" + fi + done + + if [ "$apply" -eq 1 ]; then + echo "template-drift: applied $applied of $total" + exit "$failed" + fi + echo "template-drift: $differ of $total differ" + exit 0 +} + +main "$@"; exit $? diff --git a/scripts/template-files.txt b/scripts/template-files.txt new file mode 100644 index 0000000..16198b7 --- /dev/null +++ b/scripts/template-files.txt @@ -0,0 +1,19 @@ +# Files a plugin made from this template keeps identical to the template's. +# "path" = the whole file; "path :: MARKER" = from the first line containing MARKER to the end. +# "? path" = an optional whole file: skipped (not reported, not created) while the plugin has none; +# once it exists it is compared and applied like any other. Not supported on "path :: MARKER" lines. +# Report: bash scripts/template-drift.sh Pull the template's versions in: add --apply +scripts/build.ts +scripts/generate.ts +scripts/types.ts +scripts/frontmatter.ts +scripts/template-drift.sh +scripts/template-files.txt +tests/build.test.ts +tests/template-drift.test.ts +tsconfig.json +.github/workflows/check.yml +.github/workflows/release.yml +? .github/workflows/notify-marketplace.yml +CLAUDE.md +AGENTS.md :: template-reference: diff --git a/scripts/types.ts b/scripts/types.ts index e381bb8..f405a74 100644 --- a/scripts/types.ts +++ b/scripts/types.ts @@ -72,7 +72,10 @@ export interface McpSource { } // The name every harness accepts: Agent Plugins allows periods, Antigravity doesn't; Claude -// reserves some prefixes; Gemini and Qwen expect it to match the folder name. +// reserves some prefixes. Naming rule: a repository named "-plugin" holds a plugin named +// "", and every manifest carries ""; only Gemini's manifest carries the repository name +// (Gemini and Qwen expect the extension name to match the repository). Any other repository +// name puts no rule on the name. export const NAME_RE = /^[a-z0-9]+(-[a-z0-9]+)*$/; const RESERVED_PREFIXES = ['claude-', 'anthropic-', 'cc-plugin-']; @@ -86,6 +89,19 @@ export function nameProblem(name: unknown): string | undefined { return undefined; } +// The last path segment of a repository URL, without a trailing "/" or ".git"; undefined if none. +export function repoNameOf(repository: unknown): string | undefined { + if (typeof repository !== 'string') return undefined; + let path: string; + try { + path = new URL(repository).pathname; + } catch { + return undefined; + } + const last = path.replace(/\/+$/, '').replace(/\.git$/, '').split('/').pop(); + return last ? last : undefined; +} + const SEMVER_RE = /^\d+\.\d+\.\d+(-[0-9A-Za-z.-]+)?$/; function isObject(v: unknown): v is Record { @@ -123,6 +139,13 @@ export function validateConfig(raw: unknown): string[] { errors.push(`${key} must be an https:// URL`); } } + const repo = repoNameOf(c.repository); + if (repo && repo.endsWith('-plugin') && repo.length > '-plugin'.length && typeof c.name === 'string') { + const short = repo.slice(0, -'-plugin'.length); + if (c.name !== short) { + errors.push(`name must be "${short}": the repository is "${repo}", and a plugin is named after its repository without "-plugin"`); + } + } if (typeof c.icon === 'string' && (c.icon.startsWith('/') || c.icon.includes('..'))) { errors.push('icon must be a path inside the repo'); } diff --git a/tests/build.test.ts b/tests/build.test.ts index d2875bd..e29cfa8 100644 --- a/tests/build.test.ts +++ b/tests/build.test.ts @@ -1,12 +1,12 @@ // Generator tests: each builds a throwaway plugin folder in the temp directory (no network). import { test } from 'node:test'; import assert from 'node:assert/strict'; -import { existsSync, mkdirSync, mkdtempSync, readFileSync, writeFileSync } from 'node:fs'; +import { existsSync, mkdirSync, mkdtempSync, readFileSync, renameSync, writeFileSync } from 'node:fs'; import { tmpdir } from 'node:os'; import { join } from 'node:path'; import { diff, merge, plan, write } from '../scripts/generate.ts'; import { parseFrontmatter } from '../scripts/frontmatter.ts'; -import { HARNESSES, nameProblem } from '../scripts/types.ts'; +import { HARNESSES, nameProblem, repoNameOf } from '../scripts/types.ts'; const NAME = 'demo-plugin'; @@ -226,3 +226,62 @@ test('name rule and helpers', () => { assert.deepEqual(fm?.data, { name: 'x', description: 'one two', metadata: { version: '1.0.0' } }); assert.equal(fm?.body, 'body'); }); + +test('repoNameOf reads the last path segment of the repository URL', () => { + assert.equal(repoNameOf('https://github.com/o/x-plugin'), 'x-plugin'); + assert.equal(repoNameOf('https://github.com/o/x-plugin.git'), 'x-plugin'); + assert.equal(repoNameOf('https://github.com/o/x-plugin/'), 'x-plugin'); + assert.equal(repoNameOf('https://github.com/'), undefined); + assert.equal(repoNameOf(undefined), undefined); +}); + +test('a repo named -plugin: every manifest says , Gemini says the repo name', () => { + const root = fixture(config({ name: 'demo', repository: 'https://github.com/someone/demo-plugin' })); + put(root, '.opencode/plugins/demo.js', 'export default {};\n'); + const p = plan(root); + assert.deepEqual(p.errors, []); + assert.deepEqual(p.warnings, []); + write(root, p); + for (const f of ['plugin.json', '.claude-plugin/plugin.json', '.cursor-plugin/plugin.json', + '.antigravity-plugin/plugin.json', '.kimi-plugin/plugin.json', '.muse-plugin/plugin.json', 'package.json']) { + assert.equal(read(root, f).name, 'demo', f); + } + const m = read(root, '.claude-plugin/marketplace.json'); + assert.equal(m.name, 'demo'); + assert.equal(m.plugins[0].name, 'demo'); + assert.equal(read(root, 'gemini-extension.json').name, 'demo-plugin'); +}); + +test('a repo named -plugin with any other name is an error', () => { + const root = fixture(config({ repository: 'https://github.com/someone/demo-plugin' })); + assert.match(plan(root).errors.join('\n'), + /name must be "demo": the repository is "demo-plugin", and a plugin is named after its repository without "-plugin"/); +}); + +test('other repository names put no rule on the name, and Gemini uses the name', () => { + const root = fixture(config({ repository: 'https://github.com/someone/demo-tools' })); + const p = plan(root); + assert.deepEqual(p.errors, []); + write(root, p); + assert.equal(read(root, 'gemini-extension.json').name, 'demo-plugin'); +}); + +test('the folder a checkout sits in does not matter', () => { + const root = fixture(); + const moved = `${root}-worktree`; + renameSync(root, moved); + const p = plan(moved); + assert.deepEqual(p.errors, []); + assert.deepEqual(p.warnings, []); + write(moved, p); + assert.deepEqual(diff(moved, plan(moved)), { stale: [], missing: [], leftover: [] }); +}); + +test('an icon that is a generated path is a config error and the file is left alone', () => { + const root = fixture(config({ icon: '.claude-plugin/icon.png' })); + put(root, '.claude-plugin/icon.png', 'mine'); + const result = plan(root); + assert.ok(result.errors.some((e) => e.includes( + 'icon must not be a generated file (.claude-plugin/icon.png): keep the source icon elsewhere, such as assets/icon.png'))); + assert.equal(readFileSync(join(root, '.claude-plugin/icon.png'), 'utf8'), 'mine'); +}); diff --git a/tests/template-drift.test.ts b/tests/template-drift.test.ts new file mode 100644 index 0000000..cc2a4b5 --- /dev/null +++ b/tests/template-drift.test.ts @@ -0,0 +1,233 @@ +// Drift script tests: throwaway template and plugin folders in the temp directory (no network). +import { test } from 'node:test'; +import assert from 'node:assert/strict'; +import { spawnSync } from 'node:child_process'; +import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'; +import { tmpdir } from 'node:os'; +import { dirname, join } from 'node:path'; + +const SCRIPT = join(import.meta.dirname, '..', 'scripts', 'template-drift.sh'); +const TEMPLATE_URL = 'https://github.com/rjstone/harness-plugin-template'; +const TEMPLATE_AGENTS = '# Template\n\nshared\n'; + +function put(root: string, path: string, content: string) { + mkdirSync(dirname(join(root, path)), { recursive: true }); + writeFileSync(join(root, path), content); +} + +const read = (root: string, p: string) => readFileSync(join(root, p), 'utf8'); + +// A template folder and a plugin folder holding identical copies, except that the plugin's +// AGENTS.md has its own first line. +function pair(repository = 'https://github.com/someone/demo-plugin') { + const base = mkdtempSync(join(tmpdir(), 'hpt-drift-')); + const template = join(base, 'template'); + const plugin = join(base, 'plugin'); + put(template, 'plugin.config.json', JSON.stringify({ repository: TEMPLATE_URL })); + put(template, 'scripts/template-files.txt', + '# comment\n\na.txt\nsub/b.txt\nAGENTS.md :: template-reference:\n'); + put(plugin, 'plugin.config.json', JSON.stringify({ repository })); + for (const root of [template, plugin]) { + put(root, 'a.txt', 'alpha\n'); + put(root, 'sub/b.txt', 'beta\n'); + } + put(template, 'AGENTS.md', TEMPLATE_AGENTS); + put(plugin, 'AGENTS.md', '# Mine\n\nshared\n'); + return { base, template, plugin }; +} + +function drift(plugin: string, args: string[], env: Record = {}) { + const r = spawnSync('bash', [SCRIPT, ...args], { + cwd: plugin, encoding: 'utf8', + env: { ...process.env, GITHUB_ACTIONS: '', ...env }, + }); + return { status: r.status, stdout: r.stdout, stderr: r.stderr }; +} + +test('identical files: nothing to report', () => { + const { base, template, plugin } = pair(); + const r = drift(plugin, [template]); + assert.equal(r.status, 0); + assert.match(r.stdout, /template-drift: 0 of 3 differ/); + rmSync(base, { recursive: true }); +}); + +test('a changed file is reported and the exit code stays 0', () => { + const { base, template, plugin } = pair(); + put(plugin, 'a.txt', 'changed\n'); + const r = drift(plugin, [template]); + assert.equal(r.status, 0); + assert.match(r.stdout, /^a\.txt differs from the template$/m); + assert.match(r.stdout, /1 of 3 differ/); + rmSync(base, { recursive: true }); +}); + +test('in CI the report is a warning annotation', () => { + const { base, template, plugin } = pair(); + put(plugin, 'a.txt', 'changed\n'); + const r = drift(plugin, [template], { GITHUB_ACTIONS: 'true' }); + assert.equal(r.status, 0); + assert.match(r.stdout, + /^::warning file=a\.txt::a\.txt differs from the template \(rjstone\/harness-plugin-template\)$/m); + rmSync(base, { recursive: true }); +}); + +test('a file the plugin lacks is reported', () => { + const { base, template, plugin } = pair(); + rmSync(join(plugin, 'sub/b.txt')); + const r = drift(plugin, [template]); + assert.equal(r.status, 0); + assert.match(r.stdout, /^sub\/b\.txt is missing$/m); + rmSync(base, { recursive: true }); +}); + +test('above the marker is the plugin\'s own', () => { + const { base, template, plugin } = pair(); + const r = drift(plugin, [template]); + assert.match(r.stdout, /0 of 3 differ/); + rmSync(base, { recursive: true }); +}); + +test('below the marker is compared', () => { + const { base, template, plugin } = pair(); + put(plugin, 'AGENTS.md', '# Mine\n\nlocal edit\n'); + const r = drift(plugin, [template]); + assert.equal(r.status, 0); + assert.match(r.stdout, /^AGENTS\.md differs from the template below the marker$/m); + rmSync(base, { recursive: true }); +}); + +test('--apply copies files and replaces only what is below the marker', () => { + const { base, template, plugin } = pair(); + put(plugin, 'a.txt', 'changed\n'); + put(plugin, 'AGENTS.md', '# Mine\n\nlocal edit\n'); + const r = drift(plugin, ['--apply', template]); + assert.equal(r.status, 0); + assert.equal(read(plugin, 'a.txt'), 'alpha\n'); + assert.equal(read(plugin, 'AGENTS.md'), '# Mine\n\nshared\n'); + const again = drift(plugin, [template]); + assert.match(again.stdout, /0 of 3 differ/); + rmSync(base, { recursive: true }); +}); + +test('--apply leaves a file without the marker alone and exits 1', () => { + const { base, template, plugin } = pair(); + const own = '# Mine\nno marker here\n'; + put(plugin, 'AGENTS.md', own); + put(plugin, 'a.txt', 'changed\n'); + const r = drift(plugin, ['--apply', template]); + assert.equal(r.status, 1); + assert.match(r.stderr, /AGENTS\.md: marker "template-reference:" not found/); + assert.equal(read(plugin, 'AGENTS.md'), own); + assert.equal(read(plugin, 'a.txt'), 'alpha\n'); + rmSync(base, { recursive: true }); +}); + +test('report mode says when the marker is missing', () => { + const { base, template, plugin } = pair(); + put(plugin, 'AGENTS.md', '# Mine\nno marker here\n'); + put(plugin, 'a.txt', 'changed\n'); + const r = drift(plugin, [template]); + assert.equal(r.status, 0); + assert.match(r.stdout, /^AGENTS\.md: marker "template-reference:" not found$/m); + rmSync(base, { recursive: true }); +}); + +test('a list entry outside the repo is refused', () => { + const { base, template, plugin } = pair(); + put(template, 'scripts/template-files.txt', 'a.txt\n../evil.txt\n'); + put(plugin, 'a.txt', 'changed\n'); + const r = drift(plugin, ['--apply', template]); + assert.equal(r.status, 1); + assert.match(r.stderr, /template-files\.txt: bad path "\.\.\/evil\.txt"/); + assert.equal(read(plugin, 'a.txt'), 'changed\n'); + rmSync(base, { recursive: true }); +}); + +test('does nothing in the template itself', () => { + const { base, template, plugin } = pair(TEMPLATE_URL + '.git'); + put(plugin, 'a.txt', 'changed\n'); + const r = drift(plugin, [template]); + assert.equal(r.status, 0); + assert.match(r.stdout, /this is the template; nothing to compare/); + rmSync(base, { recursive: true }); +}); + +test('a template that can\'t be fetched is a note, not a failure', () => { + const { base, plugin } = pair(); + const env = { TEMPLATE_DRIFT_URL: 'file:///nonexistent' }; + const r = drift(plugin, [], env); + assert.equal(r.status, 0); + assert.match(r.stdout, /could not fetch the template/); + assert.equal(drift(plugin, ['--apply'], env).status, 1); + rmSync(base, { recursive: true }); +}); + +test('--apply can replace the drift script it is running', () => { + const { base, template, plugin } = pair(); + const real = readFileSync(SCRIPT, 'utf8'); + put(plugin, 'scripts/template-drift.sh', real); + put(template, 'scripts/template-drift.sh', '# extra line 1\n# extra line 2\n# extra line 3\n' + real); + put(template, 'scripts/template-files.txt', 'scripts/template-drift.sh\n'); + const r = spawnSync('bash', [join(plugin, 'scripts/template-drift.sh'), '--apply', template], { + cwd: plugin, encoding: 'utf8', env: { ...process.env, GITHUB_ACTIONS: '' }, + }); + assert.doesNotMatch(r.stderr, /syntax error/); + assert.equal(r.status, 0); + assert.equal(read(plugin, 'scripts/template-drift.sh'), read(template, 'scripts/template-drift.sh')); + assert.match(r.stdout, /template-drift: applied 1 of 1$/m); + rmSync(base, { recursive: true }); +}); + +test('an optional entry that is missing locally is silent and not created', () => { + const { base, template, plugin } = pair(); + put(template, 'scripts/template-files.txt', 'a.txt\n? opt.txt\n'); + put(template, 'opt.txt', 'optional\n'); + const r = drift(plugin, [template]); + assert.equal(r.status, 0); + assert.doesNotMatch(r.stdout, /opt\.txt/); + assert.match(r.stdout, /0 of 1 differ/); + const a = drift(plugin, ['--apply', template]); + assert.equal(a.status, 0); + assert.equal(existsSync(join(plugin, 'opt.txt')), false); + rmSync(base, { recursive: true }); +}); + +test('an optional entry that exists and differs is reported and applied', () => { + const { base, template, plugin } = pair(); + put(template, 'scripts/template-files.txt', 'a.txt\n? opt.txt\n'); + put(template, 'opt.txt', 'optional\n'); + put(plugin, 'opt.txt', 'old\n'); + const r = drift(plugin, [template]); + assert.match(r.stdout, /^opt\.txt differs from the template$/m); + assert.match(r.stdout, /1 of 2 differ/); + drift(plugin, ['--apply', template]); + assert.equal(read(plugin, 'opt.txt'), 'optional\n'); + rmSync(base, { recursive: true }); +}); + +test('an entry missing from the template is exit 1 with --apply, exit 0 in report mode', () => { + const { base, template, plugin } = pair(); + put(template, 'scripts/template-files.txt', 'a.txt\nnot-there.txt\n'); + put(plugin, 'a.txt', 'changed\n'); + assert.equal(drift(plugin, [template]).status, 0); + const r = drift(plugin, ['--apply', template]); + assert.equal(r.status, 1); + assert.match(r.stdout, /not-there\.txt: not in the template/); + assert.match(r.stdout, /applied 1 of 2/); + rmSync(base, { recursive: true }); +}); + +test('--apply that cannot write says failed, not updated, and exits 1', () => { + const { base, template, plugin } = pair(); + put(plugin, 'a.txt', 'changed\n'); + // A directory where the file should go makes the move fail. + rmSync(join(plugin, 'sub/b.txt')); + mkdirSync(join(plugin, 'sub/b.txt')); + const r = drift(plugin, ['--apply', template]); + assert.equal(r.status, 1); + assert.doesNotMatch(r.stdout, /updated sub\/b\.txt/); + assert.match(r.stderr, /sub\/b\.txt: could not write/); + assert.equal(read(plugin, 'a.txt'), 'alpha\n'); + rmSync(base, { recursive: true }); +});