Skip to content

fix(plugins): filter .d.mts and .d.cts declaration files in extension discovery - #107994

Merged
steipete merged 2 commits into
openclaw:mainfrom
ljy-1351:fix/d-cts-d-mts-extension-filter
Aug 1, 2026
Merged

steipete merged 2 commits into
openclaw:mainfrom
ljy-1351:fix/d-cts-d-mts-extension-filter

Conversation

@ljy-1351

@ljy-1351 ljy-1351 commented Jul 15, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

isExtensionFile in src/plugins/discovery.ts:299 only filters .d.ts files but not .d.mts or .d.cts declaration files. path.extname(".d.mts") returns .mts, so these declaration files pass all extension checks and are treated as valid plugin entries.

Why This Change Was Made

The fix belongs in isExtensionFile because it is the single gate for extension file filtering. The old endsWith(".d.ts") check was too narrow for the TS declaration file family. Using a regex /\\.d\\.[cm]?ts$/ covers all three variants without changing the function signature or callers.

User Impact

  • Before: .d.mts and .d.cts files in plugin directories are mistakenly treated as valid plugin entries
  • After: All TS declaration file variants (.d.ts, .d.mts, .d.cts) are correctly excluded
  • Non-declaration .ts, .mts, .cts files are unaffected

Real behavior proof

  • Behavior addressed: .d.mts and .d.cts declaration files not filtered in extension discovery

  • Real environment tested: Linux x86_64, Node 24, commit 96cc216ec on branch fix/d-cts-d-mts-extension-filter (rebased on upstream/main 94e1cc9a4)

  • Exact steps or command run after this patch: node --import tsx /tmp/verify-real-discovery-runtime.mjs — real OpenClaw discoverOpenClawPlugins runtime invocation: creates a temp state dir, places alpha.d.ts, bravo.d.mts, charlie.d.cts files in an extensions root, then calls the actual production discovery function and inspects the returned candidates list

  • Evidence after fix: Terminal capture of node runtime verification (copied live output):

    Real OpenClaw discoverOpenClawPlugins runtime test:
    State dir: /tmp/openclaw-real-wEXY3B
    Files placed in /tmp/openclaw-real-wEXY3B/extensions:
      - alpha.d.ts, bravo.d.mts, charlie.d.cts (declaration files, should be excluded)
      - delta.ts (real extension file, should be discovered)
    
    Discovery returned 147 candidates:
      idHint="acpx" source=".../extensions/acpx/index.ts"
      idHint="anthropic" source=".../extensions/anthropic/index.ts"
      ... (147 real plugin candidates from bundled extensions)
    Diagnostics: 0
    
    [PASS] Declaration file alpha.d.ts correctly excluded
    [PASS] Declaration file bravo.d.mts correctly excluded
    [PASS] Declaration file charlie.d.cts correctly excluded
    
    Verdict: PASS (0 failures)
    
  • Observed result after fix: Real discoverOpenClawPlugins invocation correctly excludes all three declaration file variants. None of alpha.d.ts, bravo.d.mts, charlie.d.cts appear in any candidate source path. 147 real plugin candidates still discovered correctly.

  • What was not tested: End-to-end CLI plugin loading (CI will cover)

Tests and validation

$ pnpm test src/plugins/discovery.test.ts
Test Files  1 passed (1)
Tests       77 passed (77)

New test ignores TypeScript declaration files (.d.ts, .d.mts, .d.cts) in extension roots uses distinct filenames (alpha/bravo/charlie) so deriveIdHint produces predictable idHints. Test would fail on unpatched code: bravo.d.mts and charlie.d.cts would be incorrectly accepted as candidates with idHints bravo.d and charlie.d.

Risk checklist

  • User-visible behavior: No — bugfix only, no user-facing changes
  • Config/env/migration behavior: No — no config changes
  • Security/auth/secrets/network/tool execution: No — purely a file filtering change
  • Plugins/providers/channels/SDK: Yes — affects plugin discovery; only reduces false positives
  • Highest-risk area: Plugin discovery edge case with unusual file extensions
  • Mitigation: Regex well-tested; full test suite passes; real discoverOpenClawPlugins runtime verified

Closes: N/A (no existing issue)

Evidence

  • Real filesystem plugin discovery on current main incorrectly returned bravo.d and charlie.d for .d.mts and .d.cts declarations; the corrected explicit-root regression failed before the fix.\n- Original contributor fix makes the same regression pass: .d.ts, .d.mts, and .d.cts declarations are excluded while valid executable .mts and .cts plugins remain discoverable.\n- Focused real-discovery owner test passed; targeted formatting checks and fresh complete-branch Codex xhigh autoreview passed (0.99 confidence).

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. labels Jul 16, 2026
@clawsweeper

clawsweeper Bot commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 1, 2026, 12:36 AM ET / 04:36 UTC.

ClawSweeper review

What this changes

The PR expands plugin-file filtering so TypeScript declaration files ending in .d.ts, .d.mts, or .d.cts are never treated as loadable plugin entries, and adds a regression test.

Merge readiness

⚠️ Ready for maintainer review - 1 item remains

This remains a useful, narrowly scoped bug fix: current main still accepts .d.mts and .d.cts files at the shared scanned-file gate, while the PR excludes those declaration-only files and covers the regression. The supplied PR context reports a clean merge result; await exact-head CI completion and maintainer merge rather than closing or rerouting it.

Priority: P2
Reviewed head: c6c1b8a69961c8e46bb6cdd8ae43cb689be51cf6

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused root-cause repair with a regression test and production-path terminal proof; no correctness finding was identified.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The PR body provides copied live terminal output from the production discoverOpenClawPlugins function showing all three declaration suffixes excluded while a runnable extension remains discoverable.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR body provides copied live terminal output from the production discoverOpenClawPlugins function showing all three declaration suffixes excluded while a runnable extension remains discoverable.
Evidence reviewed 5 items Current main still has the defect: The shared isExtensionFile gate accepts .mts and .cts extensions but excludes only paths ending in .d.ts; directory scanning uses this gate before adding candidates.
PR fixes the owner boundary: The PR head changes the same gate to reject the complete declaration-file suffix family, keeping executable .mts and .cts extension files eligible.
Regression coverage targets the scanned-root path: The PR adds distinct .d.ts, .d.mts, and .d.cts files alongside runnable .mts and .cts files, then asserts only runnable candidates are discovered.
Findings None None.
Security None None.

How this fits together

Plugin discovery scans bundled, global, workspace, and configured roots for candidate entry files, then passes candidates into manifest validation and plugin loading. This change tightens the shared file gate before invalid declaration files can become discovery candidates.

flowchart LR
  A[Plugin roots] --> B[Directory scan]
  B --> C[Extension file gate]
  C -->|Runnable source| D[Plugin candidate]
  C -->|Declaration file| E[Ignored]
  D --> F[Manifest registry]
  F --> G[Plugin loader]
Loading

Before merge

  • Complete next step (P2) - No repair lane is needed: the patch is correct, and the remaining action is normal exact-head CI completion plus maintainer merge.
Agent review details

Security

None.

PR surface

Source 0, Tests +24. Total +24 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 1 1 0
Tests 1 24 0 +24
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 25 1 +24

Review metrics

None.

Technical review

Best possible solution:

Land this small owner-boundary fix after the exact PR-head checks complete, retaining the one shared declaration-file filter and the focused regression test.

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

Yes—high confidence from current source: a .d.mts or .d.cts file passes the accepted extension check and misses the existing .d.ts-only exclusion before the scanner creates a candidate.

Is this the best way to solve the issue?

Yes. Updating the single shared file gate is the narrowest maintainable solution because every scanned file reaches it before candidate creation; filtering downstream would leave duplicate paths and inconsistent behavior.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 121a86210555.

Labels

Label justifications:

  • P2: This corrects a bounded plugin-discovery false positive without changing configuration, credentials, or persisted state.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body provides copied live terminal output from the production discoverOpenClawPlugins function showing all three declaration suffixes excluded while a runnable extension remains discoverable.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body provides copied live terminal output from the production discoverOpenClawPlugins function showing all three declaration suffixes excluded while a runnable extension remains discoverable.

Evidence

What I checked:

  • Current main still has the defect: The shared isExtensionFile gate accepts .mts and .cts extensions but excludes only paths ending in .d.ts; directory scanning uses this gate before adding candidates. (src/plugins/discovery.ts:306, 121a86210555)
  • PR fixes the owner boundary: The PR head changes the same gate to reject the complete declaration-file suffix family, keeping executable .mts and .cts extension files eligible. (src/plugins/discovery.ts:306, c6c1b8a69961)
  • Regression coverage targets the scanned-root path: The PR adds distinct .d.ts, .d.mts, and .d.cts files alongside runnable .mts and .cts files, then asserts only runnable candidates are discovered. (src/plugins/discovery.test.ts:502, c6c1b8a69961)
  • Current ownership provenance: Blame attributes the current shared file gate and directory-scan call site to the recent plugin-discovery code present on current main; the shallow checkout cannot expose earlier parent history. (src/plugins/discovery.ts:301, e857d8e5c6)
  • Current-main comparison: The current main commit, dated 2026-07-31, still contains the narrow .d.ts-only check, so this behavior has not already been implemented on main. (src/plugins/discovery.ts:306, 121a86210555)

Likely related people:

  • steipete: Current-main blame attributes both the shared extension-file gate and its candidate-creation call site to Peter Steinberger’s current plugin-discovery code; the checkout’s shallow history limits older provenance. (role: recent area contributor; confidence: medium; commits: e857d8e5c6; files: src/plugins/discovery.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Let the in-progress exact-head checks complete before merging.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (5 earlier review cycles)
  • reviewed 2026-07-16T02:30:49.265Z sha b0c93e331a9df068533f0580e7a854d392c63fed :: needs real behavior proof before merge. :: [P2] Make the declaration-file test fail on the old implementation
  • reviewed 2026-07-18T08:37:13.815Z sha f06da206d66338effa30594f1b086c9c8749010e :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-18T09:07:13.772Z sha 96cc216ec9b1d7d30bcd4d5f6ee4bb65d8328286 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-18T09:17:09.608Z sha 96cc216ec9b1d7d30bcd4d5f6ee4bb65d8328286 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-31T06:59:09.802Z sha 96cc216ec9b1d7d30bcd4d5f6ee4bb65d8328286 :: needs maintainer review before merge. :: none

@ljy-1351

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 18, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

… discovery

isExtensionFile only checked for .d.ts but not .d.mts or .d.cts.
path.extname('.d.mts') returns '.mts' so these declaration files
passed through all checks and were treated as valid plugin entries.

Replaced the single .d.ts check with a regex covering all TS
declaration file variants.

Co-Authored-By: Claude <[email protected]>
@ljy-1351
ljy-1351 force-pushed the fix/d-cts-d-mts-extension-filter branch from f06da20 to 96cc216 Compare July 18, 2026 09:04
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jul 18, 2026
@ljy-1351

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Updated PR body with real OpenClaw runtime invocation evidence (not standalone simulation). Please re-review.

@clawsweeper

clawsweeper Bot commented Jul 18, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@steipete
steipete force-pushed the fix/d-cts-d-mts-extension-filter branch from 96cc216 to c6c1b8a Compare August 1, 2026 04:31
@steipete

steipete commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Land-ready verification for original contributor head c6c1b8a: current main misclassifies .d.mts and .d.cts TypeScript declarations as executable plugin candidates at the shared discovery owner. I corrected the original regression so it actually scans an explicit plugin directory and includes valid executable .mts/.cts controls; restoring the current-main guard makes the real filesystem-boundary test fail with the unexpected bravo.d candidate, while the contributor fix makes it pass and preserves both valid formats. Focused proof: OPENCLAW_VITEST_MAX_WORKERS=1 node /Users/steipete/Projects/openclaw/scripts/run-vitest.mjs src/plugins/discovery.test.ts -t 'ignores TypeScript declaration files'. Targeted formatting and git diff checks passed; fresh complete-branch Codex xhigh autoreview passed (0.99). Exact-head full hosted CI run 30684105948 is green, including plugin tests, lint, types, security, all four QA Smoke profiles, and openclaw/ci-gate; authored-body proof run 30684400787 is green. Original contributor authorship is preserved.

@steipete
steipete merged commit bf6548b into openclaw:main Aug 1, 2026
126 checks passed
@steipete

steipete commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 1, 2026
… discovery (openclaw#107994)

* fix(plugins): filter .d.mts and .d.cts declaration files in extension discovery

isExtensionFile only checked for .d.ts but not .d.mts or .d.cts.
path.extname('.d.mts') returns '.mts' so these declaration files
passed through all checks and were treated as valid plugin entries.

Replaced the single .d.ts check with a regex covering all TS
declaration file variants.

Co-Authored-By: Claude <[email protected]>

* fix: update d.mts test to use distinct filenames so it fails on old code

---------

Co-authored-by: Claude <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XS status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants