Skip to content

Document module script entries (scriptType) and the src/ tree#17

Merged
topkoa merged 2 commits into
mainfrom
docs/module-script-paradigm
Jul 9, 2026
Merged

Document module script entries (scriptType) and the src/ tree#17
topkoa merged 2 commits into
mainfrom
docs/module-script-paradigm

Conversation

@topkoa

@topkoa topkoa commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator

Summary

The stems plugin's R1 pilot (its PRs #23–#36) split its client code from one monolithic screen.js into an ES-module tree: plugin.json declares "scriptType": "module", screen.js is a one-line import './src/main.js';, and the code lives under src/ sharing state via import/export.

The current feedBack Host already supports this — it injects <script type="module"> when scriptType is "module", and serves the module tree at /api/plugins/{id}/src/{path} — but the spec did not describe it, and best-practices actively contradicted it ("screen.js runs as a classic script", "the plugin root is not a servable directory"). This PR brings the spec up to date.

Changes (purely additive — every existing manifest still validates)

  • spec/plugin-spec-v1.md — §3 anatomy shows the optional src/ tree; §4.1/§4.3 document the new scriptType and minHost keys; §6.1 notes classic-vs-module loading; new §6.8 "Splitting client code across modules."
  • schemas/plugin.schema.json — added scriptType and minHost properties.
  • spec/best-practices.md — rewrote rules 27–29 (and the checklist): an ES-module entry (scriptType: "module" + src/) is now the recommended way to split client code; the classic single-screen.js bundle / window-shared runtime split is kept as the fallback for older Hosts. Corrects text that was flatly wrong once scriptType: "module" is set.
  • CHANGELOG.md[Unreleased] entry.

Per spec §9 this is additive (a new OPTIONAL manifest key an older Host ignores), so no manifest-major bump.

Verification

  • schemas/plugin.schema.json is valid JSON; tools/validate.py passes both examples and the real stems main manifest.
  • Repo test suite: 11 passed.
  • All new cross-reference anchors match GitHub's heading-slug convention.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Added support for ES-module client entries via a scriptType manifest setting, enabling src/-based code splitting.
    • Documented minHost guidance for module-dependent plugins to prevent older hosts from loading module entries incorrectly.
  • Documentation
    • Updated the plugin specification and best-practices to clearly explain classic-script vs module entry behavior, including asset URL patterns and re-hydration/idempotency expectations.
  • Schema Updates
    • Extended the plugin manifest schema with scriptType and minHost, and clarified the script field’s meaning.

The stems plugin's R1 pilot split its client code from one monolithic
screen.js into an ES-module tree: plugin.json declares
`scriptType: "module"`, screen.js is a one-line `import './src/main.js'`,
and the code lives under src/. The current feedback Host supports this —
it injects `<script type="module">` for `scriptType:"module"` and serves
the src/ tree at /api/plugins/{id}/src/{path} — but the spec did not
describe it, and best-practices actively contradicted it ("screen.js runs
as a classic script", "the plugin root is not a servable directory").

- spec §3/§4.1/§4.3, new §6.8, schema: document the optional `scriptType`
  and `minHost` keys and the served src/ module tree. Purely additive.
- best-practices rules 27-29 rewritten: module entry is the recommended
  split; classic bundle / window-share kept as the older-Host fallback.
- CHANGELOG: Unreleased entry.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Kris Anderson <topkoa@gmail.com>
@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 392a3f12-f56c-4080-a8c0-4b0f593d8a85

📥 Commits

Reviewing files that changed from the base of the PR and between 45ffb00 and 3609087.

📒 Files selected for processing (1)
  • spec/best-practices.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • spec/best-practices.md

📝 Walkthrough

Walkthrough

This PR updates the schema, spec, best-practices guide, and changelog to define scriptType and minHost, and to document ES-module client entries alongside classic script loading and splitting.

Changes

scriptType and module splitting documentation

Layer / File(s) Summary
Schema definition for scriptType and minHost
schemas/plugin.schema.json
Adds scriptType and minHost properties and revises the script description.
Plugin spec v1 classic vs module script semantics
spec/plugin-spec-v1.md
Updates the plugin anatomy, field summary, script loading semantics, screen lifecycle text, and module-splitting section for scriptType and minHost.
Best-practices guidance for splitting client code
spec/best-practices.md
Revises split-client-code guidance for module mode, classic mode, idempotent loading, and the publishing checklist.
Changelog entry
CHANGELOG.md
Documents scriptType, minHost, and the revised client-code organization guidance.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: documenting module script entries and the optional src/ tree.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch docs/module-script-paradigm

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@spec/best-practices.md`:
- Around line 455-460: The split-runtime guidance in best-practices.md hardcodes
the plugin asset route, which conflicts with Host-assigned asset URLs. Update
the “Split at runtime” section to tell authors to use the Host-provided asset
URL/base instead of `/api/plugins/<id>/assets/…`, and keep the checklist bullet
aligned; the relevant guidance is in the split-runtime asset-loading note and
the classic-script state-sharing example.
- Around line 422-429: The fenced examples in this best-practices section are
unlabeled, which triggers MD040 and makes them harder to read. Update the code
fences in the tree example and the runtime snippet to use the appropriate
language tags, using text for the directory tree and js for the JavaScript
example. Apply the same fix to the matching fenced block referenced later in the
document so all examples use explicit labels.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 5bf35df4-9fc0-4e9d-9fb9-55b6cd24eb39

📥 Commits

Reviewing files that changed from the base of the PR and between 2995351 and 45ffb00.

📒 Files selected for processing (4)
  • CHANGELOG.md
  • schemas/plugin.schema.json
  • spec/best-practices.md
  • spec/plugin-spec-v1.md

Comment thread spec/best-practices.md Outdated
Comment thread spec/best-practices.md Outdated
- Label the src/-tree fence as `text` (MD040).
- Stop hardcoding the /api/plugins/<id>/assets route in the classic-split
  guidance and checklist; derive the asset base from the script's own
  served URL (document.currentScript) instead, per normative §6.7 which
  says asset URLs are Host-assigned.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Kris Anderson <topkoa@gmail.com>
@topkoa
topkoa merged commit 5c9d916 into main Jul 9, 2026
8 checks passed
@topkoa
topkoa deleted the docs/module-script-paradigm branch July 9, 2026 13:48
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.

1 participant