Skip to content

feat: add simple tool plugin authoring - #83006

Merged
steipete merged 7 commits into
mainfrom
feat/tool-plugin-dx
May 17, 2026
Merged

steipete merged 7 commits into
mainfrom
feat/tool-plugin-dx

Conversation

@steipete

@steipete steipete commented May 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Add defineToolPlugin as a typed SDK helper for simple tool-only plugins, including optional tool metadata and context-backed factories.
  • Add openclaw plugins init, build, and validate so generated openclaw.plugin.json and package.json extension entries stay in sync with the plugin entry.
  • Dogfood the helper in the bundled llm-task plugin and document the npm/package authoring workflow in docs/plugins/tool-plugins.md plus the CLI/plugin SDK reference pages.

Verification

  • node scripts/run-vitest.mjs src/plugin-sdk/tool-plugin.test.ts src/cli/plugins-authoring-command.test.ts (16 tests passed; rerun by Codex review)
  • node scripts/run-vitest.mjs src/plugin-sdk/tool-plugin.test.ts src/cli/plugins-authoring-command.test.ts extensions/llm-task/src/llm-task-tool.test.ts -- --reporter=verbose (31 tests passed before final source-loader fix)
  • pnpm check:changed (Testbox tbx_01krtr5zy3aabxe6pejqha1bev, Actions run https://github.com/openclaw/openclaw/actions/runs/25988511278, passed)
  • pnpm openclaw plugins build --root extensions/llm-task --check && pnpm openclaw plugins validate --root extensions/llm-task (Plugin metadata is up to date. and Plugin llm-task is valid.)
  • pnpm check:docs
  • pnpm plugin-sdk:api:check
  • node scripts/check-plugin-sdk-subpath-exports.mjs
  • git diff --check
  • Codex review: clean after fixing the accepted source-entry loader finding

Real behavior proof

Behavior addressed: simple tool-only plugin authoring through defineToolPlugin, generated plugin metadata, optional tool declarations, and source or dist entry validation.

Real environment tested: local OpenClaw checkout using the OpenClaw CLI against the bundled extensions/llm-task plugin, plus Blacksmith Testbox changed gate for the full touched surface.

Exact steps or command run after this patch: pnpm openclaw plugins build --root extensions/llm-task --check && pnpm openclaw plugins validate --root extensions/llm-task

Evidence after fix: the command loaded the package source entry ./index.ts, resolved openclaw/plugin-sdk/tool-plugin through the plugin SDK alias loader, checked generated metadata, then validated the manifest/package/entry agreement.

Observed result after fix: Plugin metadata is up to date. followed by Plugin llm-task is valid. Testbox tbx_01krtr5zy3aabxe6pejqha1bev also passed pnpm check:changed for head 9ec68e3eda390aaea9a4eeba7712ea97e2f7af6a.

What was not tested: publishing a third-party npm package to the public registry; the scaffold and docs cover npm packaging, but no package was published from this PR.

@github-actions github-actions Bot added the dependencies-changed PR changes dependency-related files label May 17, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Dependency Changes Detected

This PR changes dependency-related files. Maintainers should confirm these changes are intentional.

Changed files:

  • package.json

Maintainer follow-up:

  • Review whether the dependency changes are intentional.
  • Inspect resolved package deltas when lockfile or workspace dependency policy changes are present.
  • Run pnpm deps:changes:report -- --base-ref origin/main --markdown /tmp/dependency-changes.md --json /tmp/dependency-changes.json locally for detailed release-style evidence.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation cli CLI command changes scripts Repository scripts size: L maintainer Maintainer-authored PR and removed dependencies-changed PR changes dependency-related files labels May 17, 2026
@clawsweeper

clawsweeper Bot commented May 17, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

Summary
The PR adds a defineToolPlugin SDK subpath, tool-plugin authoring CLI commands, docs, tests, package exports, and an llm-task migration to the helper.

Reproducibility: Do we have a high-confidence way to reproduce the issue? Not applicable as a current-main bug, but yes for the review blockers: the latest PR head shows the failing source paths, and the Windows path guard issue is reproduced with a read-only path.win32.relative probe.

Real behavior proof
Needs real behavior proof before merge: The PR body provides tests, static checks, and summarized results, but not after-fix real CLI output or artifacts from an actual openclaw plugins init/build/validate run. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, ask a maintainer to comment @clawsweeper re-review.

Next step before merge
The PR needs contributor/maintainer follow-up for real behavior proof and P2 repairs; ClawSweeper should not request repair markers while the proof gate is mock-only.

Security
Needs attention: The patch introduces authoring-time runtime imports and package metadata generation, with concrete path-boundary and stale-entry concerns.

Review findings

  • [P2] Reject cross-drive entries outside the plugin root — src/cli/plugins-authoring-command.ts:49-56
  • [P2] Parse plugin manifests with the JSON5-compatible loader — src/cli/plugins-authoring-command.ts:37-38
  • [P2] Generate publishable names for scoped plugin ids — src/cli/plugins-authoring-command.ts:330-332
Review details

Best possible solution:

Land a repaired version that keeps manifest-first discovery, hardens authoring path boundaries, validates exact generated package metadata, scaffolds publishable package names, and includes redacted real CLI authoring proof.

Do we have a high-confidence way to reproduce the issue?

Do we have a high-confidence way to reproduce the issue? Not applicable as a current-main bug, but yes for the review blockers: the latest PR head shows the failing source paths, and the Windows path guard issue is reproduced with a read-only path.win32.relative probe.

Is this the best way to solve the issue?

Is this the best way to solve the issue? No, not as currently written. The SDK/CLI direction is plausible, but the command should share the existing manifest parser contract, harden root-boundary checks, validate the single generated runtime entry, and generate publishable scaffold metadata.

Full review comments:

  • [P2] Reject cross-drive entries outside the plugin root — src/cli/plugins-authoring-command.ts:49-56
    normalizeRelativePath only rejects .. escapes. On Windows, an entry on another drive normalizes to a drive-qualified relative path like D:/outside/index.js, passes this guard, and can then be imported and persisted as if it lived under the plugin root.
    Confidence: 0.9
  • [P2] Parse plugin manifests with the JSON5-compatible loader — src/cli/plugins-authoring-command.ts:37-38
    readJsonFile uses strict JSON.parse for openclaw.plugin.json in build/check/validate paths, but the normal manifest loader accepts JSON5 features such as comments and trailing commas. Supported manifests will fail this new authoring path.
    Confidence: 0.9
  • [P2] Generate publishable names for scoped plugin ids — src/cli/plugins-authoring-command.ts:330-332
    plugins init interpolates the raw plugin id into package.json.name, so a supported scoped id such as @acme/quotes becomes openclaw-plugin-@acme/quotes, which is not a valid npm package name for publishing.
    Confidence: 0.86
  • [P2] Reject stale extra runtime entries during validation — src/cli/plugins-authoring-command.ts:236-238
    validateToolPluginProject only checks whether openclaw.extensions includes the selected entry. A package with ['./dist/index.js', './dist/old.js'] passes validation even though build would rewrite it to the selected single runtime entry, allowing unintended stale runtime entrypoints to ship.
    Confidence: 0.88

Overall correctness: patch is incorrect
Overall confidence: 0.9

Security concerns:

  • [low] Harden authoring entry root checks — src/cli/plugins-authoring-command.ts:49
    Because plugins build/validate imports the selected entry and writes it into package metadata, cross-drive paths that bypass the intended root guard can create an out-of-package runtime reference on Windows.
    Confidence: 0.82
  • [low] Reject stale package runtime entries — src/cli/plugins-authoring-command.ts:236
    Validation can pass while extra openclaw.extensions entries remain, so a package can ship unintended plugin runtime entrypoints even though the generated metadata contract says there is one selected entry.
    Confidence: 0.78

What I checked:

Likely related people:

  • steipete: Local current-main blame in the shallow checkout attributes the central plugin CLI, manifest, and SDK entry files to Peter Steinberger, and the PR branch commits introduce the proposed authoring feature. (role: recent area contributor; confidence: medium; commits: 1f6ababb635b, a4748dfd242c, 8538a8dd2f9c; files: src/cli/plugins-cli.ts, src/plugins/manifest.ts, src/plugin-sdk/plugin-entry.ts)
  • joshavant: Current main commit f29bcff4 recently refactored plugin metadata snapshot and model/plugin registry surfaces adjacent to manifest-first discovery. (role: recent adjacent contributor; confidence: medium; commits: f29bcff4dad0; files: src/plugins/current-plugin-metadata-snapshot.ts, src/plugins/plugin-registry-snapshot.ts, src/plugins/plugin-registry-contributions.ts)

Remaining risk / open question:

  • No after-fix real CLI transcript, log, screenshot, recording, or linked artifact is present, so real behavior proof remains a merge blocker.

Codex review notes: model gpt-5.5, reasoning high; reviewed against f29bcff4dad0.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6046730732

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +52 to +55
if (relative === ".." || relative.startsWith("../")) {
throw new Error(`entry must stay inside plugin root: ${targetPath}`);
}
return relative.startsWith(".") ? relative : `./${relative}`;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Badge Reject cross-drive entry paths outside plugin root

normalizeRelativePath only rejects entries when the relative string starts with ../, but on Windows path.relative() returns a drive-qualified path (for example D:\...) when --entry is on a different drive. After separator normalization this becomes D:/..., passes the guard, and gets rewritten as ./D:/..., so plugins build/validate can import and persist an entry outside the plugin root instead of failing with the intended boundary error.

Useful? React with 👍 / 👎.

Comment on lines +36 to +37
function readJsonFile(filePath: string): JsonObject {
return JSON.parse(fs.readFileSync(filePath, "utf8")) as JsonObject;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Badge Parse plugin manifests with JSON5-compatible loader

readJsonFile uses JSON.parse, but this command path also operates on openclaw.plugin.json, which is accepted by loadPluginManifest via JSON5 fallback. A manifest containing valid JSON5 syntax (comments/trailing commas) will pass loadPluginManifest and then crash when re-read here, causing plugins validate and plugins build --check to fail on otherwise supported manifests.

Useful? React with 👍 / 👎.

@github-actions github-actions Bot added the dependencies-changed PR changes dependency-related files label May 17, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. impact:security Security boundary, credential, authz, sandbox, or sensitive-data risk. labels May 17, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 56b0d4a212

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

fs.mkdirSync(path.join(rootDir, "src"), { recursive: true });

const packageManifest = {
name: `openclaw-plugin-${id}`,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Badge Validate plugin id before deriving scaffold package name

plugins init interpolates the raw <id> into package.json.name, so a valid scoped plugin id like @acme/quotes produces openclaw-plugin-@acme/quotes, which npm rejects as an invalid package name at publish time. This makes the generated scaffold unusable for normal distribution unless users manually repair metadata, so the command should validate/normalize ids (or generate a publishable package name scheme) before writing package.json.

Useful? React with 👍 / 👎.

@openclaw-barnacle openclaw-barnacle Bot added extensions: llm-task Extension: llm-task size: XL and removed size: L labels May 17, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3eb47d1700

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +236 to +237
} else if (!extensionResolution.entries.includes(params.entry)) {
errors.push(`package.json openclaw.extensions must include ${params.entry}`);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Badge Require a single openclaw.extensions runtime entry

validateToolPluginProject only checks whether openclaw.extensions includes the selected entry, so validation passes when extra stale entries are still present (for example ['./dist/index.js', './dist/old.js']). In that state plugins build would rewrite package.json, but plugins validate incorrectly reports success, allowing projects to ship unintended additional runtime entrypoints that can be loaded by OpenClaw.

Useful? React with 👍 / 👎.

@steipete
steipete force-pushed the feat/tool-plugin-dx branch from 3eb47d1 to 8538a8d Compare May 17, 2026 09:50
@steipete
steipete force-pushed the feat/tool-plugin-dx branch from 2d2d550 to 9ec68e3 Compare May 17, 2026 10:39
@steipete
steipete merged commit 156e86a into main May 17, 2026
120 checks passed
@steipete
steipete deleted the feat/tool-plugin-dx branch May 17, 2026 10:45
@steipete

Copy link
Copy Markdown
Contributor Author

Landed via rebase merge.

Proof:

Source head: 9ec68e3
Landed commit: 156e86a

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes dependencies-changed PR changes dependency-related files docs Improvements or additions to documentation extensions: llm-task Extension: llm-task impact:security Security boundary, credential, authz, sandbox, or sensitive-data risk. maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. scripts Repository scripts size: XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant