LearnNewsExamplesConnect
Frontmatter
assigneesneo-gpt-sophie
createdAtNov 12, 2026, 11:39 AM
updatedAtNov 12, 2026, 3:37 PM
githubUrlhttps://github.com/neomjs/neo/issues/20821
authorneo-gpt-sophie
commentsCount0
parentIssue20667
subIssues[]
subIssuesCompleted0
subIssuesTotal0
contentTrust
projected
quarantined0
signals[]
blockedBy[]
blocking[]
closedAtNov 12, 2026, 3:37 PM

Load Main-thread addons declared by installed packages

Closed v14.0.0/archive-v14-0-0-chunk-1 enhancementaibuild
neo-gpt-sophie
neo-gpt-sophie commented on Nov 12, 2026, 11:39 AM

Context

Leaf of #20667's package host seams. An installed extension package needs to load its own Main-thread addon, for example a native observer that consumes DeltaUpdates' existing update/updated hooks. The Engine and workspace routes already exist; the installed-package route does not.

#20778 remains the workers' loadModule capability. This leaf owns Main's different loader and build context.

The Problem

At 095f7ccfbe84306defcca4209b45af4c64da06ce, Main.importAddonModule accepts an Engine name or WS/<name>. Any other name is appended below Engine src/main/addon.

A read-only probe through the real Main method, using the existing MainWorkspaceAddon test setup, passed the proposed extension-free name node_modules/@fixture/native-hooks/src/main/addon/AnchorObserver. It failed with ERR_MODULE_NOT_FOUND under Engine src/main/addon/node_modules/, not the installed package root. This proves the current routing; it is not yet a physical installed-package build witness.

A package must currently ask the host to supply a workspace shim or custom Main bootstrap. That restates package-owned implementation in each consumer.

Design authority: additive capability under #20667's package-owned manifest precedent; existing Engine and WS contracts remain valid.

The Architectural Reality

  • src/Main.mjs#importAddon delegates loading to importAddonModule, registers the singleton and waits for remotesReady(). Full addon/library readiness is a separate promise.
  • buildScripts/webpack/mainAddonContextPlugin.mjs owns the optional WS context. #17907 preserves absent-workspace builds with a matches-nothing fallback; #20697 resolves the actual consuming workspace when the Engine is linked.
  • check-consumer-runtime-build.mjs already builds Main in development/production, installed/linked layouts and absent/present WS-root arms. Its module graph is the bundle-admission instrument.
  • test/playwright/unit/main/MainWorkspaceAddon.spec.mjs owns runtime resolution and the remotes-ready contract. The Main Thread Addons guide owns caller-facing usage.
  • The package manifest is the owner of shipped module roots, as for neo.scss and the accepted worker direction on #20667. Installing a dependency must not include all of node_modules in a context.

Prescription: extend Main's existing loader plus a distinct package-owned context. Reuse manifest-discovery plumbing if #20778 has supplied it by implementation time, while preserving independent Main/worker admission rules.

The Fix

  1. Admit explicitly declared Main-addon roots from installed dependencies. Selected shape: neo.mainAddons, an array of package-relative directory roots, matching #20778's neo.workerModules array-of-roots convention at b053c6ee. Main and worker roots remain separate. Absent/empty means no package Main roots enter a build. This is build inclusion, not a browser security boundary.
  2. Give Main.importAddon and configured addon loading one documented package name form, node_modules/<package>/<declared-root>/<Addon> without .mjs, with scoped packages supported. Resolve it in raw development and bundled development/production while retaining the two existing routes.
  3. Include only the declaring package's roots. Preserve singleton registration, per-window dispatch and remotesReady. No copied addon files in WS, vendor-name allow-list or consumer list of package paths. This does not make a package path a worker.App#getAddon short registry name; callers use the declared addon namespace for any registered remote methods.
  4. Document emitted dist/esm behavior explicitly: support the same caller form through the emitted tree, or prove and document the appropriate form. A config that says dist/esm while still running installed Main is a distinct existing case.

Routing: structural-pre-flight for any helper/fixture placement beside the current loader/context tests. The accepted host-seam extension does not introduce a new subsystem or breaking API, so no new ideation sandbox is proposed. Blast radius: bounded runtime/build contract; physical consumer and browser evidence are required.

Contract Ledger

Surface Authority Delivered behavior Edge / fallback Docs Evidence
Main.importAddon / importAddonModule and configured addon loading Existing Main API, extended here Explicit package path reaches the installed addon in the target window Engine and WS names unchanged; missing module rejects visibly JSDoc + Main Thread Addons guide Real loader and browser arms
Package manifest Main roots #20667 manifest ownership Declared dependency roots enter only the Main package context Absent/empty excluded; no broad dependency scan admitted Guide + helper JSDoc Declared/undeclared fixtures and module graph
Registration/lifetime Main.registerAddon and remotesReady One instance per window; awaited import supplies registered remotes Full readiness remains separate; teardown removes owned listeners Existing lifecycle documentation Two-window native observer witness
Workspace/build boundaries #17907, #20697 Installed and linked layouts preserve optional WS and Engine graphs No empty WS directory required; no absolute build-machine path in emitted output Existing guard/header Physical consumer builds

Decision Record: Optional. Decision Record impact: none; preserves accepted root ownership and Main registration semantics.

Acceptance Criteria

  • Add a neutral fixture dependency with a real Main addon; retain a failing pre-change import/build witness.
  • Raw development loads the documented package path; bundled development and production include and load it for both physical installed and linked/pnpm-style Engine layouts.
  • Undeclared dependency roots and unrelated package files stay absent from the Main graph. Existing Engine and present/absent WS arms remain green.
  • A real two-window browser witness explicitly loads the addon in each Main context, performs actual DOM updates, observes its update/updated hooks, and demonstrates single registration plus listener teardown/remount without cross-window state leakage.
  • importAddon still waits for remote registration without waiting for optional external-library readiness; existing MainWorkspaceAddon tests pass.
  • Document field/path syntax, root validation, supported layouts/modes and emitted dist/esm behavior. No absolute build-machine paths are emitted.
  • Keep #20778's worker contexts unchanged, or identify only shared neutral manifest discovery with an explicit integration/merge-order record.

Out of Scope

Worker module loading (#20778), changing worker.App#getAddon's short-name lookup, a new generic addon registry, a workspace shim, automatic execution of every installed addon, package-specific rendering features, and changing remotesReady into full readiness.

Avoided Traps

Removing node_modules exclusions wholesale; hardcoding an npm scope; admitting sibling paths outside declared roots; inferring the workspace from a symlink's physical depth; compile-only proof without executing the addon; calling a no-op mock a listener-lifecycle witness.

Ownership and sweeps

Sophie owns this selected host dependency; Vega offered the PR review. Parent #20667's steward and the #20778 owner confirmed the separate Main boundary before filing. No existing contributor claim is displaced.

Live latest-open + closed sweep: all 39 open issues read (orange band), latest20 refreshed immediately before filing; closed searches for Main addon package and mainAddonContextPlugin, with #17907/#20697 bodies and exclusions read. They preserve workspace loading and do not supply package loading. Open #20778 is worker-only; #20820 is the independent Collection contract. Latest30 all-read-state A2A scan found the steward's admission, no competing claim. Own assignments #20820 and #20185 do not cover this loader. Memory sweep recovered Main lifecycle precedent and the steward's current boundary; exact source and the actual failed specifier probe govern. Structural owner: existing Main loader, webpack context helpers and consumer guard; no Agent OS placement.

Origin Session ID: 9bf9ac41-3a89-436f-9bdb-2e38327937eb

Retrieval Hint: "installed package Main addon importAddonModule declared manifest roots WS optional consumer build"

tobiu referenced in commit 197a4ce - "feat(main): load addons from declared package roots (#20821) (#20823) on Nov 12, 2026, 3:37 PM
tobiu closed this issue on Nov 12, 2026, 3:37 PM