diff --git a/AGENTS.md b/AGENTS.md index efb32ed..c190f36 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -13,7 +13,8 @@ better-sidebar and file a note in `docs/`. - **Language**: TypeScript (strict, `noUncheckedIndexedAccess`, ESM, `.ts` extension imports) - **Build**: `tsdown` (rolldown). Dual output — `lib/index.js` + `lib/invariant.js` - (host, ESM) and `lib/client.js` (client, CJS closure factory) + (host, ESM) and `lib/client.js` (client, self-contained bundle with a named + `apply` export) - **Type check**: `tsc --noEmit -p tsconfig.json` - **Unit tests**: `vitest` (node environment, no DOM) - **Package manager**: `pnpm` (Node ≥ 22.13 required — `node:sqlite` + pnpm 11) @@ -40,7 +41,7 @@ src/ invariant.ts # invariant surface (assert, semver, peer guard) — dep-free context-types.ts # service face contracts (ApesContext = CordisContext & {...}) client/ - index.tsx # CLIENT entry: closure factory registering apes:* tabs + index.tsx # CLIENT entry: named `apply(ctx)` registering apes:* tabs locales.ts # i18n (zh default, en fallback) + useApesLocale hook tests/ smoke.spec.ts # host plugin shape + apply + invariant surface @@ -60,9 +61,13 @@ cordis.patch.yml # plugin registration into the DSH profile 2. **Host / client split is load-bearing.** - The **host** half (`lib/index.js`) runs in Node. It may use Node builtins. - - The **client** half (`lib/client.js`) runs in the DSH browser shell. It is - a **CJS closure factory** — `module.exports = (hostApi) => {...}`. React is - external (host-provided). Never `import` a Node builtin into `src/client/**`. + - The **client** half (`lib/client.js`) runs in the DSH browser shell. Its + entry is a **named `export function apply(ctx: ApesClientContext)`** (not a + default export); tsdown bundles it to a self-contained module whose export + face is `{ apply, ... }`. The host wires it via `ctx.betterSidebar` / + `ctx.effect` (read from `ctx`, not a separately-injected `hostApi`). + React is external (host-provided). Never `import` a Node builtin into + `src/client/**`. - `src/invariant.ts` is reachable from BOTH halves — it must stay dependency-free (no Node builtins, no @deepseek-ai imports). @@ -120,6 +125,14 @@ cordis.patch.yml # plugin registration into the DSH profile pnpm store. A fresh `pnpm install` on a clean checkout will re-prompt. - The workspace path contains spaces and Chinese characters (`文稿 - figmarLite的MacBook Pro/...`) — always quote it in shell commands. +- **`lib/client.js` is a DSH browser `__ModuleLoader__` bundle, NOT plain + CJS/ESM.** Line 1 is `window.__ModuleLoader__.load({...})` — it is consumed + by the DSH browser shell's module loader and **cannot be `require()`d in + Node** (top-level `window` reference throws `window is not defined`). This is + why the cordis scratch mount smoke cannot run in the unit gate: the client + artifact is browser-only by construction, not just because the `dsh` CLI is + absent. Unit specs test the **source** `src/client/index.tsx` (`apply` + contract), never the built bundle. ## Phase status