Skip to content

add the new-plugin starter command - #124

Merged
adssib merged 3 commits into
mainfrom
new-plugin
Nov 19, 2026
Merged

adssib merged 3 commits into
mainfrom
new-plugin

Conversation

@adssib

@adssib adssib commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #121 (needs its docs/plugins.json, Layer column and make plugins-json). Review/merge #121 first; this PR's diff against make-check is one commit.

Closes #116

What this changes

go run ./cmd/new-plugin --api <id> --provider <Name> --format <format> scaffolds a provider on any of the eight format plugins (openapi, retirements, migrationguide, removedmembers, changelog, feed, apichangelog, catalog), following how the existing providers are added:

Format Definition goes in Registered as
openapi adapter/<api>.go (a stub Adapter: LatestTag/Fetch to write) Plugin{Adapter: adapter.X{}}
retirements retire/<api>.go (retire.Page) + its migrate/ providers entry Plugin{Page: retire.X, Archiver: kit.Wayback{}}
migrationguide sdkguide/<api>.go (sdkguide.Guide) + its migrate/ guides entry Plugin{Guide: sdkguide.X}
removedmembers, changelog, feed, apichangelog, catalog plugins/<format>/<api>.go the format's usual Plugin{…}

For every format it also writes:

  • the plugin.Register line, added to the format's existing init (parsed with go/parser, formatted with go/format), so all registrations stay in one place;
  • plugins/<format>/<api>_test.go: Test<X>RegistersItself (kittest.Registered), Test<X>Golden (kittest.Golden over the in-memory kittest.Mem) and Test<X>DropsANonChange, over placeholder sources in testdata/, and the golden file written from them (go test -run … -update);
  • one row per saved file in that testdata/README.md (URL / date / license / quote placeholders; a "Saved sources" table when the README has none);
  • providers/<api>.md from providers/_template.md, or with --page <name> nothing new, linking the provider's existing page (the three algolia plugins share providers/algolia.md);
  • the docs/plugins.md row (status live: a plugin in the code is live), then docs/plugins.json regenerated.

Every place to fill in says TODO(new-plugin). It prints the next steps (save the page, fill in the definition, go test ./plugins/<format> -run Test<X> -update, fill in "Why this source", make check, PR). It refuses an invalid id, all, a registered id, an id with a row, an existing file or a Go name already declared in the package, and then changes nothing. File names avoid Go build-constraint suffixes (acme-linux → acme_linux_plugin.go).

Docs: docs/writing-a-plugin.md step 1 is now the starter (the rest renumbered), and CONTRIBUTING.md and AGENTS.md point to it.

Guard (from the review): make todos fails while any TODO(new-plugin) is left in plugins/, adapter/, retire/, sdkguide/, migrate/, providers/ or docs/plugins.md. It's part of make check and a step in CI_go (one cheap grep, same job). Also from the review: quotes and backslashes are refused in --provider/--watches with a clear message, and the openapi testdata table's Source/Checked columns get their hints.

Acceptance criteria (#116)

  • Running the command on a clean checkout creates all five pieces (plugin file, test, testdata + README rows, provider page, docs/plugins.md row), and go test ./... passes right after: TestScaffoldEveryFormat scaffolds one plugin of each of the eight formats into a copy of the repo, then runs go build ./..., go vet ./... and go test over plugins/, internal/ and migrate/.
  • Running it twice with the same name fails with a clear message ("docs/plugins.md already has a row for …") and changes nothing (the test hashes every file before and after).
  • docs/writing-a-plugin.md and CONTRIBUTING.md point to the command.
  • The command has its own tests (cmd/new-plugin/main_test.go: every format, refusal, shared provider page, bad input, file names).

Flag name: the ticket suggests --name; I used --api (it's the --api id users select the plugin by, and every event's api) plus --provider for the display name.

Checklist

  • docs/plugins.md: no plugin added or changed (the generator writes rows; none committed). Not applicable otherwise.
  • Every commit is signed off (DCO)
  • Golden test / testdata / drop test / provider page: not applicable, no plugin added
  • Fetches only through env.Get / kit/ (the generated openapi adapter is the only code that will fetch, in adapter/, as today)
  • make check passes locally (except the known local-gofmt mismatch on plugins/openapi/vercel_test.go, see add make check and docs/plugins.json #121)
  • Nothing private

Calls I made (please check)

  • Placeholder sources are realistic enough for each format's parser. For removedmembers, migrationguide and retirements every row the parser accepts is an event, so their placeholder golden has one event, and their drop test checks that a specific placeholder row (another table / another call / a model Keep drops) produces none, instead of "no events at all".
  • The generated row's status is live (the rule from plugins list: every plugin in the code is live #122: a plugin in the code is live). The TODOs in the generated files mark it unfinished, and make todos (CI_go) fails until they're gone, so an unfinished scaffold can't merge green.
  • The generator runs go (test -update and cmd/list-plugins) itself, so go test ./... passes immediately.
  • New retirements/migrationguide providers also need an entry in migrate/migrate.go's maps (otherwise v1 → v2 conversion rejects their events); the generator adds it. Provider slug = provider name lowercased with hyphens.

Related PRs

🤖 Generated with Claude Code

go run ./cmd/new-plugin --api <id> --provider <Name> --format <format>
scaffolds a provider on any of the eight format plugins: the definition,
its Register line, a registered/golden/drop test over placeholder
sources, testdata rows, the provider page, the docs/plugins.md row and
docs/plugins.json. It refuses a taken id and then changes nothing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: adssib <75389300+adssib@users.noreply.github.com>
@claude

claude Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Claude finished @adssib's task in 2m 32s —— View job


✅ Ready to merge (after #121): the starter adds no plugin, all checks I ran pass, I found no blocking bugs, and it meets every acceptance criterion in #116.

Rules

Rule Status Evidence
Plugin list (Rule 1) ✅ n/a No plugin is registered or removed, and docs/plugins.md / docs/plugins.json are unchanged. The generated row (tableRow) uses absolute links, sits before plugins:end, and TestScaffoldEveryFormat checks that cmd/list-plugins accepts it.
Provider page ✅ n/a No provider added. The generated page comes from providers/_template.md, with TODOs in "Why this source". With --page, the plugin shares an existing page (tested with algolia).
Golden test + quote ✅ n/a No new source. Generated tests use kittest.Golden over placeholders and add a testdata/README.md row per file (URL / date / license / quote TODOs).
Drop test ✅ n/a Each generated plugin gets one pinned drop test. For removedmembers, migrationguide and retirements it targets a specific row, which is the right call because every row those parsers accept is an event.
Fetch only via env ✅ cmd/new-plugin runs go and touches files only at scaffold time; it is not plugin code. Generated code fetches nothing except the openapi stub in adapter/, which points to fetch.Get.
Precision over recall ✅ I checked every format's placeholders: none can emit an event against a real source (see the inline comment on main.go:509).
Nothing private (Rule 2) ✅ Code, docs, commit message and PR body are clean, and the leak guard passes.

Bugs

None found that block the merge. Things I checked by reading the code:

  • Every refusal happens before anything is written: format, id, provider, layer, source, page, registry, table row, existing files and Go names in both packages.
  • Provider names with " or \ make gofmt fail before any write, so the tree is left untouched.
  • register/addMapEntry edit through go/parser + go/format.
  • fileBase avoids build-constraint suffixes.

One edge case: if the go test -update / cmd/list-plugins step at the end fails, the files stay written and a re-run is refused. The error message says so ("remove what's left of an earlier run"), so I think that's fine.

Verified

  • go build ./...: ok
  • go vet ./...: ok
  • gofmt -l .: printed nothing (the vercel_test.go mismatch from add make check and docs/plugins.json #121 doesn't show up with this CI Go)
  • go test -race -count=1 ./...: all packages ok. cmd/new-plugin took 16s, including TestScaffoldEveryFormat, which scaffolds all 8 formats into a repo copy, then builds, vets, tests, and checks that a second run changes nothing.
  • python3 scripts/leak_guard.py --all: "no banned terms (8 hashed terms checked)"
  • Not run: make check, make imports and make nethttp. The make command needs approval in this job, so the import allowlist and net/http guard were not run here; CI_go will run them.

Non-blocking (optional)

  1. A real guard against leftover TODOs (inline on main.go:509): a make check step that fails on TODO(new-plugin) outside cmd/new-plugin/, rather than relying only on the PR-template checkbox.
  2. openapi README columns (inline on main.go:485): openapi's README table heads its columns Source / Checked, so those cells get a bare TODO without the URL or date hint.
  3. fill ignores the error from template.Execute. The templates are constants, so this is harmless today, but a template.Must-style panic would catch a future typo in a template.
  4. A " in --provider currently fails with "the feed template: …". Rejecting " and \ in cellSafe (or saying "--provider can't contain quotes") would be a clearer message.

Thanks, this is a careful piece of work: the refusal-changes-nothing test that hashes the whole tree is a nice touch.

Comment thread cmd/new-plugin/main.go Outdated
Comment on lines +485 to +487
case strings.Contains(c, "url"):
cells = append(cells, "TODO(new-plugin): "+source)
case strings.Contains(c, "saved") || strings.Contains(c, "date") || strings.Contains(c, "fetched"):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking: plugins/openapi/testdata/README.md heads its table | Files | Source | Checked | License | Quote |, so neither source nor checked matches here. For --format openapi those two cells get a bare TODO(new-plugin) with no URL or date hint. Matching source with the URL and checked with the date would fix it:

Suggested change
case strings.Contains(c, "url"):
cells = append(cells, "TODO(new-plugin): "+source)
case strings.Contains(c, "saved") || strings.Contains(c, "date") || strings.Contains(c, "fetched"):
case strings.Contains(c, "url") || strings.Contains(c, "source"):
cells = append(cells, "TODO(new-plugin): "+source)
case strings.Contains(c, "saved") || strings.Contains(c, "date") || strings.Contains(c, "fetched") || strings.Contains(c, "checked"):

Comment thread cmd/new-plugin/main.go
if end < 0 {
return nil, fmt.Errorf("%s: no %s", pluginlist.Table, pluginlist.EndMarker)
}
row := fmt.Sprintf("| [`%s`](https://github.com/patch-it-dev/patch-it-plugins/blob/main/providers/%s.md) | %s | %s | %s | `%s` | [%s](%s) | live |\n",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking, but worth thinking about: this row is live, and the plugin is registered in plugins/all, so an unfinished scaffold merged by mistake would be run by patch-it's hosted ingestion service with a placeholder source. I checked every format's placeholders and none of them can emit an event: the feed reader returns nil, Keep matches only placeholder-text-*, the openapi adapter returns errors, and the GitHub sources point at TODO-owner/TODO-repo. So the risk is noise, not wrong PRs. Right now the only guard is a PR-template checkbox. A make check step (not go test, so the "passes right after" criterion still holds) that fails on TODO(new-plugin) outside cmd/new-plugin/ would make it a real guard, since AGENTS.md already asks everyone to run make check.

adssib and others added 2 commits November 19, 2026 15:21
Also: quotes and backslashes refused in --provider and --watches, the
openapi testdata table's Source and Checked columns get their hints.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: adssib <75389300+adssib@users.noreply.github.com>
Base automatically changed from make-check to main November 19, 2026 20:28
@adssib
adssib merged commit 8a1685b into main Nov 19, 2026
4 checks passed
@adssib
adssib deleted the new-plugin branch November 19, 2026 20:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

R1.3 · new-plugin starter command

1 participant