[PR #7869] [MERGED] feat(packages): agent packages use the Engine's own stores and libraries #7977

Closed
opened 2026-10-24 04:09:20 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/7869
Author: @SpicyMarinara
Created: 10/20/2026
Status: ✅ Merged
Merged: 10/20/2026
Merged by: @SpicyMarinara

Base: staging ← Head: fix/ready-engine-ui-store-guard


📝 Commits (8)

  • db92312 fix(ui): repair UI settings an old package's bundled store drops
  • 36091d2 Merge remote-tracking branch 'origin/staging' into fix/ready-engine-ui-store-guard
  • 617a4b2 Merge remote-tracking branch 'origin/staging' into fix/ready-engine-ui-store-guard
  • 5450b07 fix(ui): load the Engine's own UI save over an older package's blob
  • cda64c6 Merge remote-tracking branch 'origin/staging' into fix/ready-engine-ui-store-guard
  • ef17849 Merge remote-tracking branch 'origin/staging' into fix/ready-engine-ui-store-guard
  • 851d165 feat(packages): agent packages use the Engine's own stores and libraries
  • 3916996 Merge remote-tracking branch 'origin/staging' into fix/ready-engine-ui-store-guard

📊 Changes

22 files changed (+1479 additions, -25 deletions)

View changed files

📝 docs/development/optional-agent-packages.md (+101 -0)
📝 e2e/assigned-chat-sweep.e2e.ts (+2 -0)
➕ e2e/host-package-fixture.ts (+116 -0)
➕ e2e/marinara-host-namespace.e2e.ts (+383 -0)
➕ e2e/ui-store-foreign-write.e2e.ts (+293 -0)
📝 packages/client/.instructions.md (+2 -2)
📝 packages/client/package.json (+1 -0)
📝 packages/client/src/App.tsx (+2 -0)
📝 packages/client/src/components/ui/AppDialogRenderer.tsx (+2 -0)
📝 packages/client/src/components/ui/Modal.tsx (+4 -1)
📝 packages/client/src/hooks/use-capability-packages.ts (+5 -1)
📝 packages/client/src/hooks/use-dialog-focus-scope.ts (+3 -3)
➕ packages/client/src/lib/marinara-host-contract.ts (+202 -0)
➕ packages/client/src/lib/marinara-host.ts (+116 -0)
➕ packages/client/src/lib/query-client.ts (+12 -0)
📝 packages/client/src/lib/ui-persistence.ts (+27 -0)
📝 packages/client/src/main.tsx (+2 -11)
📝 packages/client/src/stores/ui.store.ts (+24 -3)
📝 packages/client/src/styles/mari.css (+4 -3)
📝 pnpm-lock.yaml (+3 -0)

...and 2 more files

📄 Description

Important

Contributions target staging. Only SpicyMarinara may promote this repository's staging branch or a same-repository hotfix/* branch to main.
Outside and first-time contributors also require an approving review from SpicyMarinara.

Linked issue

Closes #7858

Part of #7858. This is the client part (E-client) of the de-duplication work: the first of three Engine PRs. The Agents side is Pasta-Devs/Marinara-Agents#1487, and it also closes Pasta-Devs/Marinara-Agents#1478.

Merge order: merge this first, before the E-server PR, which bumps the capability API to 1.341. Every Engine PR of this work merges to staging before the Agents PR.

Why this change

The user problem. Agent package clients bundle copies of Engine client code, and some of those copies keep state of their own:

  • UI settings (Pasta-Devs/Marinara-Agents#1478). Reproduced in a browser: on every page load, 9 package clients each save an old (v74) copy of the UI settings over the Engine's. Each write drops 85 settings. Server sync restores 79 of them, and 6 browser-only settings are lost for good.
  • Chat store, also 9 copies. Each copy remembers the chat that was open when the page loaded:
    • Calls' connection switcher, and the sticker and emoji settings in Calls, Noodle and Slurp, change that chat instead of the current one.
    • Game boards never lock while the character is replying.
  • Smaller ones. Calls' [youtube] command does nothing, and Calls' sticker dialogs hang (no dialog renderer). There are 12 separate React Query caches, and Escape can close two modals at once.

How big the duplication is. The audit unzipped and hashed all 41 catalog packages. 16 code packages ship 26.25 MB of code, and about 16.2 MB of it (≈62%) copies something the Engine already has:

  • libraries: 9.3 MB (React ×12, the Claude Agent SDK ×3, zod, React Query, sonner, …)
  • the Engine's shared package: 2.0 MB
  • Engine client code: 1.36 MB
  • Engine server code: 1.48 MB
  • the Engine's own stylesheet: ≈1.9 MB

What this PR does about it. It gives package clients one place to take the Engine's live stores, services and libraries from, globalThis.__MARINARA_HOST__. The Agents PR then rebuilds the packages to use it instead of carrying copies.

Lead decisions (binding; made by the lead while the maintainer was away):

  • D1: All of the audit plan ships in this release: this-release lanes 1–4, next-release phases 1–4, disk cleanup and every guardrail. Nothing is deferred unless proven impossible.
  • D2: One namespace: globalThis.__MARINARA_HOST__ = { version: 1, ... }. There is no __MARINARA_HOST_UI_STORE__ alias, because it was never published. The in-flight bridge is renamed here.
  • D3: Rebuilt packages are gated on the host's capability API (bumped in the Engine), not on engine.min. Engines without the members never install them and keep their installed version working. The ui and chat store adapters keep a read-only fallback that never writes. A package never falls back to a bundled copy of a stateful Engine service; it reports the feature unavailable instead.
  • D4: Packages use the host's React and the other listed client libraries. A host React major upgrade requires a capability API major. This is documented for package authors and enforced by a regression.
  • D5: During a call, Calls' connection switcher and emoji settings use the call's chat (session.chatId). Noodle and Slurp hide the chat-scoped emoji-selection settings. (Agents side.)
  • D6: Bugs only reasoned from code (the ChatGPT refresh race, two haptics clients, the logger shutdown hang, a cleared spatial transition coming back) are fixed by moving to the host code, without a separate reproduction.
  • D7: Unchanged: uninstall keeps package data, and launcher update backups keep copying versions/.
  • D8: Every Engine PR of this work merges to staging before the Agents PR.
  • D9: Test what this Mac can test. The rest is listed for Mari below.
  • D10: Never delete user data. (This PR touches no data on disk.)

Contract decisions this PR relies on:

  • C1: This PR does not bump the capability API. E-server bumps it to 1.341 and merges after this, so an Engine never reports 1.341 without the namespace.
  • C8: One QueryClient and one toast stack for the Engine and its packages.
  • C9: Packages keep their own i18next instance and never use initReactI18next, setI18n or setDefaults (documented).
  • C10: App dialogs render on the topmost layer.
  • C12: Closes #7858, because the PR template check needs a closing keyword and merges into staging do not close issues.
  • C14: New tests go in new files.

Choices made in this PR (conservative; please check):

  • One import() for the whole namespace. lib/marinara-host.ts imports its members statically, and the package loader loads that module with one import() before the first package client. The in-flight draft used one import() per member instead. Both keep every member out of startup, but per-member import() made Vite warn that ui.store.ts and Modal.tsx "will not move into another chunk". An Engine with no package clients never loads the module.
  • First-load JavaScript grows by about 30 KB gzip (+84 KB raw: 3,109,261 → 3,193,380 bytes; gzip 867,426 → 897,975), measured against an origin/staging build:
    • Why: modules has to be the whole library namespace, so the build can no longer drop the unused exports of framer-motion, React Query, zod, zustand/middleware and tailwind-merge. vite.config.ts puts all node_modules code in the vendor chunks, and those load at startup.
    • Why it stays: the contract expected that first paint would not grow. That cannot be done for growth inside library modules that are already in those chunks, so I left the chunking alone.
    • A smaller first load would need its own chunking change (a lazy host-library chunk), with care for the startup cycles that vite.config.ts warns about.
  • One zod copy, proven. packages/client now depends on zod directly (^3.25.76, the same range packages/shared uses), and pnpm resolves both to zod@3.25.76. The production build still has exactly one copy: grep -c ZodError matches 1 line in 1 file, and there is one name="ZodError" class, the same as staging.
  • Regression compile settings. The members regression is compiled by tsconfig.client-lanes.json, which now sets "jsx": "react-jsx" because the contract type refers to Modal. That pulled use-dialog-focus-scope.ts into a noUncheckedIndexedAccess compile. I rewrote its empty-list check to test first and last directly, which behaves the same.
  • openCharacter is not pinned among the UI store fields: Noodle reads it from its own capability props, not from the Engine's UI store.
  • Branch name. I kept the in-flight branch name (fix/ready-engine-ui-store-guard), as the lead's task asked, rather than the contract's suggested fix/7858-host-namespace.

What changed

  • App dialogs now open above every other layer, including the command bar.
  • Before the Engine imports the first agent package client, it defines globalThis.__MARINARA_HOST__ (version 1). The property is not writable or configurable, and the namespace is frozen. It contains:
    • the live ui, chat, agent, sidecar, dialog, gallery, encounter, gameState and backfill stores
    • services.tts and services.dialogs
    • the 14 library modules (React, React DOM, React Query, zustand, sonner, zod, i18next, react-i18next, framer-motion, tailwind-merge, clsx and their listed subpaths)
    • the app's one queryClient
    • components.Modal, data.emojiCatalog and api
  • If the namespace cannot load (for example a stale chunk after an update), each package shows its existing load error.
  • packages/client/src/lib/marinara-host-contract.ts is the exported contract for package authors. It holds:
    • the MarinaraHostV1 type
    • the store, module and Engine-owned storage lists
    • the library majors
    • MARINARA_HOST_STORE_FIELDS, which pins with Pick<> every store field published packages read, so dropping one fails the build
  • The QueryClient moves from main.tsx to lib/query-client.ts. It is still one instance, and its defaults are unchanged.
  • The UI settings guard from the in-flight work ships unchanged in substance:
    • The Engine also saves its UI settings to a host-only marinara-engine-ui:host copy.
    • When it loads, it ignores an older blob that a pre-namespace package saved over the key.
    • Resetting the local UI state clears that copy.
  • docs/development/optional-agent-packages.md replaces "Host UI settings store" with "Host client namespace". It covers:
    • the members, feature detection and the read-only fallbacks
    • the host module rules (no own <Toaster> or QueryClient, the i18n rule, the D4 major rule)
    • the store fields packages read
    • Engine-owned browser storage, which packages may read but never write
    • the dialog layer, and older package builds
  • Tests:
    • new regression scripts/regressions/marinara-host-namespace.regression.ts
    • new e2e e2e/marinara-host-namespace.e2e.ts
    • e2e/ui-store-foreign-write.e2e.ts reads the namespace and gets write-origin checks
    • a shared e2e/host-package-fixture.ts

Validation

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

What the agent ran (the boxes above are left for a human):

  • Install and checks.
    • pnpm install --frozen-lockfile --prefer-offline: the lockfile is unchanged apart from the zod importer line.
    • pnpm check: passes. One lint warning remains, and it was already there (HomeProfessorMariChat.tsx).
    • pnpm localization:check: passes. There is no new UI copy.
  • The new regression. node scripts/run-regressions.mjs --filter scripts/regressions/marinara-host-namespace.regression.ts passes. Its two negative controls fail as they should:
    • Renaming a pinned store field fails tsc with TS2344.
    • Changing zod's major in the contract fails with "A host module major change requires a capability API major bump (docs/development/optional-agent-packages.md#host-client-namespace)".
  • Related regressions. 17 regressions that read the changed files pass, including command-center (the omnibar layer), capability-package-lifecycle, setup-escape-overlay-guard and tts-safari-play-guard.
  • The new specs (--project=desktop-chromium --workers=2, against my own dev server pair with its own data folder): all 8 tests pass, 3 in e2e/marinara-host-namespace.e2e.ts and 5 in e2e/ui-store-foreign-write.e2e.ts.
    • The namespace exists when a fixture package is imported. Every store is the same object as the app's /src/stores/*.ts module, and queryClient is the app's instance. All 14 libraries give their sample exports. The property cannot be overwritten, and the namespace is frozen.
    • A package reading stores.chat follows the chat the user opens. It sees the user open another chat from the sidebar. It also sees isStreaming and streamingChatId while a stub OpenAI-compatible server holds the reply open.
    • A confirm dialog a package opens over a z-index: 10020 overlay is visible, focused and topmost, and it can be clicked.
    • No package write. A recorder wraps Storage.prototype.setItem and removeItem and keeps the calling frame of every write. No write to marinara-engine-ui, marinara-active-chat-id, marinara-input-drafts or another Engine-owned key came from the package's code. The Engine's own store and chat store did make the expected writes.
    • The recorder can see package writes. As a negative control, the same recorder catches the old v74 client writing marinara-engine-ui itself.
    • The existing guard tests still pass: the v74 foreign write across two reloads, and the v2.4.4 and v2.5.0 migrations.
  • Negative controls for the new specs. The specs catch the bugs they are meant to:
    • Without topLayer, the dialog test fails because the overlay is on top.
    • Without awaiting the namespace before importing a package client, the namespace and chat tests fail.
  • Broader e2e (desktop-chromium): assigned-chat-sweep, capability-permissions, game-experience-setup, game-experience-startup, agent-apps-category, command-palette and conversation-video-gallery load fixture package clients through the new path. 48 tests passed, and 3 mobile-only ones were skipped.
  • The production build (pnpm build, then the production server):
    • A fixture package rendered a component with the host's React hooks through the host react-dom/client. It used a host zustand store and the host React Query, and its query landed in the Engine's cache.
    • Its sonner toast showed in the Engine's only Toaster ([data-sonner-toaster] count 1).
    • __MARINARA_HOST__.modules.react.useState is a function, and there were no page errors.

Manual verification notes

  • Manually verify on staging that the agents you have installed today (Noodle, Slurp, Calls, World Maps, Long-Term Memory, Memory Nag and the games) still open. This PR changes when their code loads: it now loads after the namespace.
  • Manually verify that a browser-only setting (for example Reduced paint effects in Roleplay) survives two reloads with your agents installed, including old builds such as the games at 1.0.5.
  • Manually verify that a confirmation opened from inside an agent screen (for example a delete in Slurp, or a World Maps prompt) shows on top and takes focus.
  • Manually verify that the command bar (Ctrl/⌘K) still opens on top of an open app confirmation (both now share the command bar's layer, so the one opened last is on top), and that a confirmation opened from the command bar or Professor Mari shows on top of it.
  • Manually verify that the first load feels the same on a phone. First-load JavaScript grew by about 30 KB gzip (see "Choices made in this PR").
  • Not tested here: mobile-chromium and WebKit for the new specs. They are desktop-only by design, as the existing UI store spec is, and WebKit is off on this shared Mac. The Calls, Noodle, Slurp and games behaviour comes with the Agents PR, and its manual list covers it.

Claim boundary (compatibility path):

  • Core claim: package clients find the complete, read-only namespace before they run, and nothing in it writes Engine storage on a package's behalf.
  • Risk type: client compatibility with installed package builds, and browser-stored settings.
  • Entrypoints touched: useCapabilityClientModules, main.tsx, AppDialogRenderer/Modal, and the UI store's persist storage.
  • Current paths tested: a namespace fixture package in dev and in the production build.
  • Legacy paths tested:
    • the old v74 package client (the guard, across two reloads)
    • the v2.4.4 and v2.5.0 settings migrations
    • fixture package clients in seven existing specs
    • globalThis.React and ReactDOM, which are kept
  • Negative controls: the three listed above.
  • Not tested here: the real published packages on this branch (Agents PR) and a real phone.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README) as needed
  • Translated docs on the docs-i18n branch updated to match, or a [docs-i18n] follow-up issue opened (see CONTRIBUTING.md § Translated documentation)
  • Version/release files updated (only if this PR includes a version bump)

Docs:

  • docs/development/optional-agent-packages.md: the "Host client namespace" section.
  • packages/client/.instructions.md: the QueryClient is now in lib/query-client.ts.

No CHANGELOG.md entry and no version bump. The held release translation PR covers the translated docs, so no [docs-i18n] issue was opened.

UI evidence (if applicable)

There is no visual change, except that app dialogs now sit on the top layer. e2e/marinara-host-namespace.e2e.ts checks a confirm dialog over a package overlay.

Summary by CodeRabbit

  • New Features

    • Optional package clients can access shared Engine services, stores, modules, components, data, and query functionality through a stable host interface.
    • Package clients can observe live application state, including chat changes and streaming activity.
    • Application dialogs now appear above package screens and overlays.
  • Bug Fixes

    • Improved recovery of UI preferences when older package versions overwrite saved settings.
    • Preserved newer settings during storage migrations and recovery.
    • Improved focus handling for dialogs with no focusable elements.
  • Documentation

    • Added guidance for package compatibility, shared resources, storage rules, and fallback behavior.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/7869 **Author:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Created:** 10/20/2026 **Status:** ✅ Merged **Merged:** 10/20/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `fix/ready-engine-ui-store-guard` --- ### 📝 Commits (8) - [`db92312`](https://github.com/Pasta-Devs/Marinara-Engine/commit/db92312bc11fc551fa29a3446bda950eba5362ac) fix(ui): repair UI settings an old package's bundled store drops - [`36091d2`](https://github.com/Pasta-Devs/Marinara-Engine/commit/36091d23b84ca74c8798aaf79f8c4496c87476ca) Merge remote-tracking branch 'origin/staging' into fix/ready-engine-ui-store-guard - [`617a4b2`](https://github.com/Pasta-Devs/Marinara-Engine/commit/617a4b24dbaa5f894b441aa9c3e1df1abfa222c4) Merge remote-tracking branch 'origin/staging' into fix/ready-engine-ui-store-guard - [`5450b07`](https://github.com/Pasta-Devs/Marinara-Engine/commit/5450b07bd5c413b5cae9b398edfa686590ebbc0f) fix(ui): load the Engine's own UI save over an older package's blob - [`cda64c6`](https://github.com/Pasta-Devs/Marinara-Engine/commit/cda64c69c32f9d081dd77b387382601b24c99c71) Merge remote-tracking branch 'origin/staging' into fix/ready-engine-ui-store-guard - [`ef17849`](https://github.com/Pasta-Devs/Marinara-Engine/commit/ef178491326e63fc6f85213fe055b3ad5ebcc74e) Merge remote-tracking branch 'origin/staging' into fix/ready-engine-ui-store-guard - [`851d165`](https://github.com/Pasta-Devs/Marinara-Engine/commit/851d1654a97a10fcf79c5df11bcd404d3824d2a7) feat(packages): agent packages use the Engine's own stores and libraries - [`3916996`](https://github.com/Pasta-Devs/Marinara-Engine/commit/3916996d4ffef62a2980777b482fe1b8af6417e1) Merge remote-tracking branch 'origin/staging' into fix/ready-engine-ui-store-guard ### 📊 Changes **22 files changed** (+1479 additions, -25 deletions) <details> <summary>View changed files</summary> 📝 `docs/development/optional-agent-packages.md` (+101 -0) 📝 `e2e/assigned-chat-sweep.e2e.ts` (+2 -0) ➕ `e2e/host-package-fixture.ts` (+116 -0) ➕ `e2e/marinara-host-namespace.e2e.ts` (+383 -0) ➕ `e2e/ui-store-foreign-write.e2e.ts` (+293 -0) 📝 `packages/client/.instructions.md` (+2 -2) 📝 `packages/client/package.json` (+1 -0) 📝 `packages/client/src/App.tsx` (+2 -0) 📝 `packages/client/src/components/ui/AppDialogRenderer.tsx` (+2 -0) 📝 `packages/client/src/components/ui/Modal.tsx` (+4 -1) 📝 `packages/client/src/hooks/use-capability-packages.ts` (+5 -1) 📝 `packages/client/src/hooks/use-dialog-focus-scope.ts` (+3 -3) ➕ `packages/client/src/lib/marinara-host-contract.ts` (+202 -0) ➕ `packages/client/src/lib/marinara-host.ts` (+116 -0) ➕ `packages/client/src/lib/query-client.ts` (+12 -0) 📝 `packages/client/src/lib/ui-persistence.ts` (+27 -0) 📝 `packages/client/src/main.tsx` (+2 -11) 📝 `packages/client/src/stores/ui.store.ts` (+24 -3) 📝 `packages/client/src/styles/mari.css` (+4 -3) 📝 `pnpm-lock.yaml` (+3 -0) _...and 2 more files_ </details> ### 📄 Description > [!IMPORTANT] > Contributions target `staging`. Only `SpicyMarinara` may promote this repository's `staging` branch or a same-repository `hotfix/*` branch to `main`. > Outside and first-time contributors also require an approving review from `SpicyMarinara`. <!-- See CONTRIBUTING.md § Branches. --> ## Linked issue Closes #7858 Part of #7858. This is the client part (E-client) of the de-duplication work: the first of three Engine PRs. The Agents side is Pasta-Devs/Marinara-Agents#1487, and it also closes Pasta-Devs/Marinara-Agents#1478. **Merge order:** merge this first, before the E-server PR, which bumps the capability API to 1.341. Every Engine PR of this work merges to `staging` before the Agents PR. ## Why this change **The user problem.** Agent package clients bundle copies of Engine client code, and some of those copies keep state of their own: - **UI settings (Pasta-Devs/Marinara-Agents#1478).** Reproduced in a browser: on every page load, 9 package clients each save an old (v74) copy of the UI settings over the Engine's. Each write drops 85 settings. Server sync restores 79 of them, and 6 browser-only settings are lost for good. - **Chat store, also 9 copies.** Each copy remembers the chat that was open when the page loaded: - Calls' connection switcher, and the sticker and emoji settings in Calls, Noodle and Slurp, change that chat instead of the current one. - Game boards never lock while the character is replying. - **Smaller ones.** Calls' `[youtube]` command does nothing, and Calls' sticker dialogs hang (no dialog renderer). There are 12 separate React Query caches, and Escape can close two modals at once. **How big the duplication is.** The audit unzipped and hashed all 41 catalog packages. 16 code packages ship 26.25 MB of code, and about 16.2 MB of it (≈62%) copies something the Engine already has: - libraries: 9.3 MB (React ×12, the Claude Agent SDK ×3, zod, React Query, sonner, …) - the Engine's shared package: 2.0 MB - Engine client code: 1.36 MB - Engine server code: 1.48 MB - the Engine's own stylesheet: ≈1.9 MB **What this PR does about it.** It gives package clients one place to take the Engine's live stores, services and libraries from, `globalThis.__MARINARA_HOST__`. The Agents PR then rebuilds the packages to use it instead of carrying copies. **Lead decisions (binding; made by the lead while the maintainer was away):** - **D1:** All of the audit plan ships in this release: this-release lanes 1–4, next-release phases 1–4, disk cleanup and every guardrail. Nothing is deferred unless proven impossible. - **D2:** One namespace: `globalThis.__MARINARA_HOST__ = { version: 1, ... }`. There is no `__MARINARA_HOST_UI_STORE__` alias, because it was never published. The in-flight bridge is renamed here. - **D3:** Rebuilt packages are gated on the host's capability API (bumped in the Engine), not on `engine.min`. Engines without the members never install them and keep their installed version working. The `ui` and `chat` store adapters keep a read-only fallback that never writes. A package never falls back to a bundled copy of a stateful Engine service; it reports the feature unavailable instead. - **D4:** Packages use the host's React and the other listed client libraries. A host React major upgrade requires a capability API major. This is documented for package authors and enforced by a regression. - **D5:** During a call, Calls' connection switcher and emoji settings use the call's chat (`session.chatId`). Noodle and Slurp hide the chat-scoped emoji-selection settings. (Agents side.) - **D6:** Bugs only reasoned from code (the ChatGPT refresh race, two haptics clients, the logger shutdown hang, a cleared spatial transition coming back) are fixed by moving to the host code, without a separate reproduction. - **D7:** Unchanged: uninstall keeps package data, and launcher update backups keep copying `versions/`. - **D8:** Every Engine PR of this work merges to `staging` before the Agents PR. - **D9:** Test what this Mac can test. The rest is listed for Mari below. - **D10:** Never delete user data. (This PR touches no data on disk.) **Contract decisions this PR relies on:** - **C1:** This PR does not bump the capability API. E-server bumps it to 1.341 and merges after this, so an Engine never reports 1.341 without the namespace. - **C8:** One QueryClient and one toast stack for the Engine and its packages. - **C9:** Packages keep their own i18next instance and never use `initReactI18next`, `setI18n` or `setDefaults` (documented). - **C10:** App dialogs render on the topmost layer. - **C12:** `Closes #7858`, because the PR template check needs a closing keyword and merges into `staging` do not close issues. - **C14:** New tests go in new files. **Choices made in this PR (conservative; please check):** - **One `import()` for the whole namespace.** `lib/marinara-host.ts` imports its members statically, and the package loader loads that module with one `import()` before the first package client. The in-flight draft used one `import()` per member instead. Both keep every member out of startup, but per-member `import()` made Vite warn that `ui.store.ts` and `Modal.tsx` "will not move into another chunk". An Engine with no package clients never loads the module. - **First-load JavaScript grows by about 30 KB gzip** (+84 KB raw: 3,109,261 → 3,193,380 bytes; gzip 867,426 → 897,975), measured against an `origin/staging` build: - Why: `modules` has to be the whole library namespace, so the build can no longer drop the unused exports of framer-motion, React Query, zod, `zustand/middleware` and tailwind-merge. `vite.config.ts` puts all `node_modules` code in the vendor chunks, and those load at startup. - Why it stays: the contract expected that first paint would not grow. That cannot be done for growth inside library modules that are already in those chunks, so I left the chunking alone. - A smaller first load would need its own chunking change (a lazy host-library chunk), with care for the startup cycles that `vite.config.ts` warns about. - **One zod copy, proven.** `packages/client` now depends on `zod` directly (`^3.25.76`, the same range `packages/shared` uses), and pnpm resolves both to `zod@3.25.76`. The production build still has exactly one copy: `grep -c ZodError` matches 1 line in 1 file, and there is one `name="ZodError"` class, the same as `staging`. - **Regression compile settings.** The members regression is compiled by `tsconfig.client-lanes.json`, which now sets `"jsx": "react-jsx"` because the contract type refers to `Modal`. That pulled `use-dialog-focus-scope.ts` into a `noUncheckedIndexedAccess` compile. I rewrote its empty-list check to test `first` and `last` directly, which behaves the same. - **`openCharacter` is not pinned** among the UI store fields: Noodle reads it from its own capability props, not from the Engine's UI store. - **Branch name.** I kept the in-flight branch name (`fix/ready-engine-ui-store-guard`), as the lead's task asked, rather than the contract's suggested `fix/7858-host-namespace`. ## What changed - App dialogs now open above every other layer, including the command bar. - Before the Engine imports the first agent package client, it defines `globalThis.__MARINARA_HOST__` (version 1). The property is not writable or configurable, and the namespace is frozen. It contains: - the live `ui`, `chat`, `agent`, `sidecar`, `dialog`, `gallery`, `encounter`, `gameState` and `backfill` stores - `services.tts` and `services.dialogs` - the 14 library `modules` (React, React DOM, React Query, zustand, sonner, zod, i18next, react-i18next, framer-motion, tailwind-merge, clsx and their listed subpaths) - the app's one `queryClient` - `components.Modal`, `data.emojiCatalog` and `api` - If the namespace cannot load (for example a stale chunk after an update), each package shows its existing load error. - `packages/client/src/lib/marinara-host-contract.ts` is the exported contract for package authors. It holds: - the `MarinaraHostV1` type - the store, module and Engine-owned storage lists - the library majors - `MARINARA_HOST_STORE_FIELDS`, which pins with `Pick<>` every store field published packages read, so dropping one fails the build - The QueryClient moves from `main.tsx` to `lib/query-client.ts`. It is still one instance, and its defaults are unchanged. - The UI settings guard from the in-flight work ships unchanged in substance: - The Engine also saves its UI settings to a host-only `marinara-engine-ui:host` copy. - When it loads, it ignores an older blob that a pre-namespace package saved over the key. - Resetting the local UI state clears that copy. - `docs/development/optional-agent-packages.md` replaces "Host UI settings store" with **"Host client namespace"**. It covers: - the members, feature detection and the read-only fallbacks - the host module rules (no own `<Toaster>` or `QueryClient`, the i18n rule, the D4 major rule) - the store fields packages read - Engine-owned browser storage, which packages may read but never write - the dialog layer, and older package builds - Tests: - new regression `scripts/regressions/marinara-host-namespace.regression.ts` - new e2e `e2e/marinara-host-namespace.e2e.ts` - `e2e/ui-store-foreign-write.e2e.ts` reads the namespace and gets write-origin checks - a shared `e2e/host-package-fixture.ts` ## Validation - [ ] `pnpm check` passes locally - [ ] Container (Docker / Podman) built and ran without issue - [ ] Ran the app, clicked through the changes manually - [ ] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [ ] Above manual verification completed (describe below) - [ ] Read and followed `CONTRIBUTING.md` What the agent ran (the boxes above are left for a human): - **Install and checks.** - `pnpm install --frozen-lockfile --prefer-offline`: the lockfile is unchanged apart from the `zod` importer line. - `pnpm check`: passes. One lint warning remains, and it was already there (`HomeProfessorMariChat.tsx`). - `pnpm localization:check`: passes. There is no new UI copy. - **The new regression.** `node scripts/run-regressions.mjs --filter scripts/regressions/marinara-host-namespace.regression.ts` passes. Its two negative controls fail as they should: - Renaming a pinned store field fails `tsc` with TS2344. - Changing zod's major in the contract fails with "A host module major change requires a capability API major bump (docs/development/optional-agent-packages.md#host-client-namespace)". - **Related regressions.** 17 regressions that read the changed files pass, including `command-center` (the omnibar layer), `capability-package-lifecycle`, `setup-escape-overlay-guard` and `tts-safari-play-guard`. - **The new specs** (`--project=desktop-chromium --workers=2`, against my own dev server pair with its own data folder): all 8 tests pass, 3 in `e2e/marinara-host-namespace.e2e.ts` and 5 in `e2e/ui-store-foreign-write.e2e.ts`. - **The namespace exists when a fixture package is imported.** Every store is the same object as the app's `/src/stores/*.ts` module, and `queryClient` is the app's instance. All 14 libraries give their sample exports. The property cannot be overwritten, and the namespace is frozen. - **A package reading `stores.chat` follows the chat the user opens.** It sees the user open another chat from the sidebar. It also sees `isStreaming` and `streamingChatId` while a stub OpenAI-compatible server holds the reply open. - **A confirm dialog a package opens over a `z-index: 10020` overlay** is visible, focused and topmost, and it can be clicked. - **No package write.** A recorder wraps `Storage.prototype.setItem` and `removeItem` and keeps the calling frame of every write. No write to `marinara-engine-ui`, `marinara-active-chat-id`, `marinara-input-drafts` or another Engine-owned key came from the package's code. The Engine's own store and chat store did make the expected writes. - **The recorder can see package writes.** As a negative control, the same recorder catches the old v74 client writing `marinara-engine-ui` itself. - **The existing guard tests still pass:** the v74 foreign write across two reloads, and the v2.4.4 and v2.5.0 migrations. - **Negative controls for the new specs.** The specs catch the bugs they are meant to: - Without `topLayer`, the dialog test fails because the overlay is on top. - Without awaiting the namespace before importing a package client, the namespace and chat tests fail. - **Broader e2e** (desktop-chromium): `assigned-chat-sweep`, `capability-permissions`, `game-experience-setup`, `game-experience-startup`, `agent-apps-category`, `command-palette` and `conversation-video-gallery` load fixture package clients through the new path. 48 tests passed, and 3 mobile-only ones were skipped. - **The production build** (`pnpm build`, then the production server): - A fixture package rendered a component with the host's React hooks through the host `react-dom/client`. It used a host zustand store and the host React Query, and its query landed in the Engine's cache. - Its `sonner` toast showed in the Engine's only Toaster (`[data-sonner-toaster]` count 1). - `__MARINARA_HOST__.modules.react.useState` is a function, and there were no page errors. ### Manual verification notes - Manually verify on staging that the agents you have installed today (Noodle, Slurp, Calls, World Maps, Long-Term Memory, Memory Nag and the games) still open. This PR changes when their code loads: it now loads after the namespace. - Manually verify that a browser-only setting (for example Reduced paint effects in Roleplay) survives two reloads with your agents installed, including old builds such as the games at 1.0.5. - Manually verify that a confirmation opened from inside an agent screen (for example a delete in Slurp, or a World Maps prompt) shows on top and takes focus. - Manually verify that the command bar (Ctrl/⌘K) still opens on top of an open app confirmation (both now share the command bar's layer, so the one opened last is on top), and that a confirmation opened from the command bar or Professor Mari shows on top of it. - Manually verify that the first load feels the same on a phone. First-load JavaScript grew by about 30 KB gzip (see "Choices made in this PR"). - Not tested here: mobile-chromium and WebKit for the new specs. They are desktop-only by design, as the existing UI store spec is, and WebKit is off on this shared Mac. The Calls, Noodle, Slurp and games behaviour comes with the Agents PR, and its manual list covers it. **Claim boundary (compatibility path):** - **Core claim:** package clients find the complete, read-only namespace before they run, and nothing in it writes Engine storage on a package's behalf. - **Risk type:** client compatibility with installed package builds, and browser-stored settings. - **Entrypoints touched:** `useCapabilityClientModules`, `main.tsx`, `AppDialogRenderer`/`Modal`, and the UI store's persist storage. - **Current paths tested:** a namespace fixture package in dev and in the production build. - **Legacy paths tested:** - the old v74 package client (the guard, across two reloads) - the v2.4.4 and v2.5.0 settings migrations - fixture package clients in seven existing specs - `globalThis.React` and `ReactDOM`, which are kept - **Negative controls:** the three listed above. - **Not tested here:** the real published packages on this branch (Agents PR) and a real phone. ## Docs and release impact - [ ] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README) as needed - [ ] Translated docs on the `docs-i18n` branch updated to match, or a `[docs-i18n]` follow-up issue opened (see CONTRIBUTING.md § Translated documentation) - [ ] Version/release files updated (only if this PR includes a version bump) Docs: - `docs/development/optional-agent-packages.md`: the "Host client namespace" section. - `packages/client/.instructions.md`: the QueryClient is now in `lib/query-client.ts`. No `CHANGELOG.md` entry and no version bump. The held release translation PR covers the translated docs, so no `[docs-i18n]` issue was opened. ## UI evidence (if applicable) There is no visual change, except that app dialogs now sit on the top layer. `e2e/marinara-host-namespace.e2e.ts` checks a confirm dialog over a package overlay. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Optional package clients can access shared Engine services, stores, modules, components, data, and query functionality through a stable host interface. - Package clients can observe live application state, including chat changes and streaming activity. - Application dialogs now appear above package screens and overlays. - **Bug Fixes** - Improved recovery of UI preferences when older package versions overwrite saved settings. - Preserved newer settings during storage migrations and recovery. - Improved focus handling for dialogs with no focusable elements. - **Documentation** - Added guidance for package compatibility, shared resources, storage rules, and fallback behavior. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-24 04:09:20 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#7977
No description provided.