docs: state the Host-face rule for the browser e2e and settle the follow-ups
apps/web/tests/README.md records why these e2e type-check in the Host aggregate and why importing a Client package there pulls its project tree into the Host build graph, with mirroring as the standing answer. The Agent Note drops the directory-picker face split (assessed and declined) and the grep-level gate in favour of that README. docs: regenerate the catalogs and retarget the moved declarations The forwarded-event change moved three owner packages' cordis `Events` declarations and their branded types into client-safe `./types` modules, and the settings-scope split moves the shell spec into ui-settings-general. Point the type-equivalence manifest and the affected Agent Note at those homes, register the new `remote/*` event scope and the `ctx.settingsScope` service in the catalog partition, and re-run the generators. `$on` joins the documented `TypeRTClientRemote` surface, and the two Agent Note fences that quote a bare member signature are marked `ignore-check`: they are declaration fragments, not compilable units. refactor(client): make ui-settings the settings domain's base layer The settings-namespace transport lived in client/runtime, where every feature could value-import it because runtime is a platform module. It belongs to the settings domain, but moving it into ui-settings as a shared function fails twice: the client bundle purity gate forbids cross-plugin value imports, and ui-settings reached ui-sidebar for its shell, so any feature depending on it closed a cycle through ui-layout and ui-theme. Both halves move. `ctx.settingsScope` is now a cordis service — the collaboration shape the purity gate prescribes, and the service proxy binds `this.ctx` to the caller, so a bound scope's disposer belongs to the calling fiber. The shell ui-settings used to own (the `sidebar.settings` occupant, its navigation, and the nav-row projection) moves to ui-settings-general, which already owns the chrome and the General section. What stays in ui-settings is what carries no `ui-*` dependency: the scope service and the canonical settings slot types, `settings.general.item` included. That type was parked in the locale package precisely because the declarer was unreachable without a cycle; every registrant now depends on this base layer, so it comes home. The scope CONTRACT stays in client/runtime: a feature service accepts a scope through its own signature without depending on the surface that binds it. The forwarded settings invalidation replaces the deleted client-side `settings/changed` event, so the transport reads `ctx.remote.$on`. It reaches `$on` through the gateway's Client half plus the allowlist's type-only subpath rather than api-remotes' Client face: that face imports a Host-tsdown-generated artifact, and this package is reachable from the Host build graph through its callers. refactor(client): reach the settings transport through ctx.settingsScope Every feature that owns a preference row switches from value-importing a shared binder to the settings domain's service, and declares the two injections that binding needs: `settingsScope` for the transport and `remote` for the forwarded invalidation it subscribes to on the caller's own context. The rows stay with the features that own the preferences — Language with locale, Appearance with ui-theme, Composer Enter with ui-conversation. Only their route to the transport changes, so no settings surface moves and no feature gains a dependency on the shell. The `settings.general.item` slot type now arrives from ui-settings, the base layer every registrant already depends on, which retires the re-export outlet ui-theme kept and the parked declaration in the locale package. client/runtime drops its settings-form and schemastery dependencies with the transport that used them. test(client): bind the settings transport in the specs that boot a preference row Every bench that activates a plugin owning a preference row now supplies the two services that plugin injects: the forwarded-event port and the scope service. Specs that exercise no settings path get the minimal doubles; the ones that do drive their refresh chains through `remote/host-event`, the same signal client/runtime republishes from a forwarded frame, replacing the deleted client-side `settings/changed` event. Also fixes a publication defect the built-invariant gate catches once it runs: api-remotes' invariant companion shared the allowlist module with the package index, so rolldown hoisted it into a third chunk beside the two bundled entries — a file the mechanically derived publication list does not carry, leaving an installed companion unable to import it. The companion now reads the allowlist through this package's own published `./types` subpath, which the bundle keeps external, so each entry stays self-contained. The dynamic-subscription cast in apiproxy is gone: after the vendored cordis rescope, `on` accepts the rest-parameter handler directly, and the allowlist's shape assertion still carries the safety argument. fix(client): carry the settings-scope move across the release manifests Rebasing onto the publishable release set replaced every manifest's dependency block, so the packages this change touches restate their additions in the workspace-protocol form: the base layer's own transport dependencies, and the `ui-settings` plus `remote` edges each preference-row owner now needs. ui-settings-general takes clsx with the shell it received, and client/runtime drops the settings-form and schemastery dependencies that left with the transport. fix(api-gateway): give each $on subscription its own registration and containment Two defects in the forwarded-event subscription table, both raised in review: A set keyed on listener identity stored one entry when two callers subscribed the same function object to the same event, so the first frame reached it once instead of twice and either disposer silenced the surviving registration. Subscriptions are now records addressed by registration, which is what "the disposer belongs to the calling fiber" requires. A listener declared void may still be `async`, and the synchronous `try/catch` could not see its rejection: the promise was dropped and surfaced as an unhandled rejection outside the documented containment. Delivery now attaches a rejection handler when a listener returns a promise, so both failure modes are logged and isolated alike. Delivery also iterates a snapshot, so a listener that subscribes or disposes during a frame no longer changes who receives that frame, and production matches the TestRemote double instead of relying on live Set iteration order. Both fixes are pinned by tests that fail against the previous implementation. The double gains its own spec for the `$mount` refusal and the unsubscribed-name drop — per-file coverage reaches it — plus a note that it propagates a throwing listener where production contains one, so no spec mistakes it for the containment guarantee. Three prose corrections: `assertJsonArgs` states where its throw actually surfaces (the emitter's listener containment, not load or emit time), the browser e2e README names every standing Client import rather than claiming one exception, and two comments and a test title state the forwarded event instead of the deleted client-side one. refactor(remote): deliver forwarded frames through ctx.remote.$dispatch The carrier used to relay each decoded frame over an internal `remote/host-event` cordis event so the delivery port could stay off the Remote contract. The relay was the wrong shape twice over: it put a client-face event into a scan whose subject is the Host vocabulary, forcing a walk exemption for something that is not a Host event at all, and it made a direct handoff between two Client plugins look like a broadcast any plugin participates in. `TypeRTClientRemote` now carries both roles of one surface — consumers subscribe with `$on`, and whoever owns the Host frame sink hands frames over with `$dispatch` — so client/runtime calls the Remote service directly and the event declaration is gone. A cordis service method is the collaboration shape the client bundle purity gate prescribes, and it needs no relay to satisfy it. The trade is that the handoff is now developer-visible: any plugin holding `ctx.remote` can synthesize a forwarded event. That is the exposure the relay already had — `ctx.emit` was equally reachable — stated in the contract instead of hidden behind a private subscriber. runtime reaches `ctx.remote` through the gateway's Client face rather than api-remotes': that face imports a Host-tsdown-generated artifact, and this project sits in the Host build graph. refactor(api-remotes): keep the allowlist value out of types.ts `src/types.ts` carries only types by package convention, but it held the forwarded-event array, so the type-only subpath published runtime code. The array moves to `src/remote-events.ts` and `types.ts` derives its projection from it; both compiler faces list both files, so the Host forwarding loop and the consumer key face still read one declaration and the package's exports are unchanged. The invariant companion returns to an empty installer. Its dispatch-shape check was the only reason the companion imported the allowlist, which made the two bundled entries share a module: rolldown hoisted it into a third chunk that the mechanically derived publication list does not carry, so an installed companion could not import it. Dropping the check retires that coupling along with the subpath-import and bundle-external workarounds it needed, and the shape the check enforced at runtime is the part the Host face's `TypeRTForwardableEvent` assertion already refuses at compile time. test(ui-task): bind the locale plugin's new injections in its bench The bench boots the real locale plugin, which now injects the settings-scope service and the forwarded-event port, so it stayed pending and left `ctx.locale` undefined. Supplies both doubles like the other benches that boot a plugin owning a preference row. docs: close the documentation gates for the forwarded-event surface Regenerates the two graph catalogs and re-records every bilingual pair this branch edited. Several pairs needed real work beyond the record: - The generators write only the English side, so the Chinese sides of `event-producer-consumer` and `module-graph` had drifted: the former still listed the three deleted client-face events and pointed at declaration sites this branch moved into `types.ts` modules, and the latter carried a stale dependency graph. - `TypeRTClientRemote`'s documented declaration gains `$dispatch` on both sides. - The pairing contract requires both sides to link the same target, so the apiproxy README and the design note now link the English note from both languages, and the note's code blocks are byte-identical across the pair (a translated comment inside a fence counts as divergence). - `apps/web/tests/README.md` gains its Chinese counterpart; the browser e2e lane documents a discipline reviewers apply, so it belongs in the bilingual corpus rather than in the pairing exemption list. - Four fences in the design note are marked `ignore-check`: each quotes a member signature, a union arm, or a snippet that names symbols it does not import, so none is a compilable unit. docs(agent-note): transition the forwarded-event note to implemented The design shipped in this PR, so the pair moves into `implemented/` and takes that folder's skeleton: `## Proposal` becomes a present-tense `## Decision`, and `## Acceptance criteria` plus `## Risks` fold into `## Verification` (what pins the behavior) and `## Consequences` (what the shipped shape costs). Facts that moved after the proposal are corrected rather than preserved: the allowlist value now lives in `remote-events.ts` beside a type-only `types.ts`, the delivery port is `$dispatch` rather than an internal cordis event, and the invariant companion is an explained empty installer. `Verification` states the two `$on` defects the review found — independent registration identity and async-rejection containment — since those are now the properties tests pin. Supersession is partial, so five active notes stay active and gain a cross-link each: `web-config-plane`, `web-client-session-scope`, `config-plane-boundaries`, `versioned-gui-welcome-onboarding`, and `permission-default-for-new-sessions` each described a frame this change replaced. Only the mechanism sentence is annotated; every conclusion those notes own is untouched, and `host/models-changed` remains apiproxy's own derived frame in all of them. Also pins the disposer's idempotence: calling one `$on` disposer twice must not splice a surviving twin registration out from under its owner. fix: docs fix: test
This commit is contained in:
@@ -2,5 +2,5 @@
|
||||
# side as of the last confirmed-consistent state. Both languages carry equal authority;
|
||||
# after editing either side, bring the other along and re-record with:
|
||||
# pnpm run verify-translation-pairing --write packages/api/remotes/README.md
|
||||
README.md: 567ece0fb58d4b9c0b022dd2ce4d8ee87caccc57
|
||||
README.zh.md: 12add6f8efc5b6af3e9b74b26a1abb2bb3936e0a
|
||||
README.md: 34c78caf985c93137e7369329302ffd5feb67595
|
||||
README.zh.md: 4fff19673f10b0d173c9e3f724ca205845a0b9ed
|
||||
|
||||
@@ -16,10 +16,9 @@ export type {} from '@deepseek-ai/dsh-commands/types'
|
||||
export type {} from '@deepseek-ai/dsh-credentials/types'
|
||||
export type {} from '@deepseek-ai/dsh-settings/types'
|
||||
/**
|
||||
* The Gateway Client face's own declaration merges, type-only: the internal
|
||||
* `remote/host-event` delivery event a carrier owner emits and the Remote
|
||||
* service subscribes to. Erased at emit, so this facade still carries no
|
||||
* runtime edge to the Gateway implementation.
|
||||
* The Gateway Client face's own declaration merges, type-only: `ctx.remote` and
|
||||
* with it the `$on`/`$dispatch` surface. Erased at emit, so this facade still
|
||||
* carries no runtime edge to the Gateway implementation.
|
||||
*/
|
||||
export type {} from '@deepseek-ai/dsh-api-gateway/client'
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/** Host BFF entry and Loader shell for the Remote contribution assembly. */
|
||||
|
||||
import type { TypeRTForwardableEvent } from '@deepseek-ai/dsh-type-meta'
|
||||
import { API_REMOTE_FORWARDED_EVENTS } from './types.ts'
|
||||
import { API_REMOTE_FORWARDED_EVENTS } from './remote-events.ts'
|
||||
|
||||
// The owner packages' client-safe `./types` exports carry the cordis `Events`
|
||||
// declarations for every allowlisted event. Pulling them into this face is what
|
||||
@@ -24,7 +24,7 @@ export type {
|
||||
ApiRemoteAgentResult,
|
||||
ApiRemoteLookupError,
|
||||
} from './agent-lookup.ts'
|
||||
export { API_REMOTE_FORWARDED_EVENTS } from './types.ts'
|
||||
export { API_REMOTE_FORWARDED_EVENTS } from './remote-events.ts'
|
||||
export type { ApiRemoteForwardedEvent } from './types.ts'
|
||||
|
||||
// Shape gate over the allowlist, kept in the Host face because the Host's event
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/** Package-owned invariant companion for `@deepseek-ai/dsh-api-remotes`. */
|
||||
|
||||
/* jscpd:ignore-start */
|
||||
import type { Context } from '@deepseek-ai/cordis'
|
||||
import type { InvariantFailure, InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
import { API_REMOTE_FORWARDED_EVENTS } from './types.ts'
|
||||
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
const PACKAGE_NAME = '@deepseek-ai/dsh-api-remotes'
|
||||
|
||||
@@ -11,38 +11,8 @@ export const name = 'api-remotes-invariant'
|
||||
/** Service required before the companion can reserve package ownership. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** The allowlist as a lookup over the live dispatch stream's plain event names. */
|
||||
const FORWARDED_EVENTS: ReadonlySet<string> = new Set(API_REMOTE_FORWARDED_EVENTS)
|
||||
|
||||
/**
|
||||
* Judge one observed dispatch of an allowlisted event against what verbatim
|
||||
* forwarding can carry. The Host face's `TypeRTForwardableEvent` assertion
|
||||
* judges each name's DECLARED signature; only the dispatch stream shows how a
|
||||
* producer actually emitted it, and neither deviation below is visible to the
|
||||
* compiler. A Scope carrier would be silently dropped on the way to a consumer
|
||||
* because `ctx.remote.$on` has no scoped form, and a waterfall or bail dispatch
|
||||
* expects a return value that a one-way carrier can never deliver back.
|
||||
* @param mode - dispatch mode reported by the event bus.
|
||||
* @param event - dispatched event name.
|
||||
* @param carrier - the dispatch `this`; `null` when the event is unscoped.
|
||||
* @param fail - reporter bound to this package.
|
||||
*/
|
||||
function validateDispatch(mode: string, event: string, carrier: unknown, fail: InvariantFailure): void {
|
||||
if (!FORWARDED_EVENTS.has(event)) return
|
||||
if (carrier !== null) {
|
||||
fail(`forwarded host event "${event}" was dispatched with a Scope carrier, which consumers can never receive`)
|
||||
}
|
||||
if (mode !== 'emit') {
|
||||
fail(`forwarded host event "${event}" was dispatched as "${mode}", but forwarding to consumers is one-way`)
|
||||
}
|
||||
}
|
||||
|
||||
/** Install the forwarded-event dispatch-shape check over the live event bus. */
|
||||
const install: InvariantInstaller = (ctx, fail) => {
|
||||
ctx.on('internal/dispatch', (mode, event, _args, thisArg) => {
|
||||
validateDispatch(mode, event, thisArg, fail)
|
||||
}, { global: true })
|
||||
}
|
||||
/** No runtime invariant: TypeRT and the Agent/Session registries own the observed relationships. */
|
||||
const install: InvariantInstaller = () => {}
|
||||
|
||||
/**
|
||||
* Register this package's invariant companion.
|
||||
@@ -51,3 +21,4 @@ const install: InvariantInstaller = (ctx, fail) => {
|
||||
*/
|
||||
export const apply = (ctx: Context): Promise<() => void> =>
|
||||
Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install))
|
||||
/* jscpd:ignore-end */
|
||||
|
||||
21
packages/api/remotes/src/remote-events.ts
Normal file
21
packages/api/remotes/src/remote-events.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* The one home of this application's forwarded-Host-event allowlist. Both
|
||||
* compiler faces list this file, so the Host forwarding loop and the consumer
|
||||
* `ctx.remote.$on` key face read one declaration instead of two copies that
|
||||
* could drift; `./types.ts` derives the type projection from it and stays
|
||||
* type-only.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Host events this application forwards to consumers verbatim: no projection,
|
||||
* no redaction, no renaming. The wire name is the Host cordis event name and
|
||||
* the payload is its argument list, so this array is simultaneously the whole
|
||||
* control point over what a consumer can receive and the legal key set of
|
||||
* `ctx.remote.$on`. Forwarding one more event is an entry here and nothing
|
||||
* else.
|
||||
*/
|
||||
export const API_REMOTE_FORWARDED_EVENTS = [
|
||||
'commands/change',
|
||||
'credentials/updated',
|
||||
'settings/document-updated',
|
||||
] as const
|
||||
@@ -1,25 +1,15 @@
|
||||
/**
|
||||
* The one home of this application's forwarded-Host-event allowlist, listed in
|
||||
* `tsconfig.host.json` AND `tsconfig.client.json` so the Host forwarding loop
|
||||
* and the consumer `ctx.remote.$on` key face read the same declaration instead
|
||||
* of two copies that could drift.
|
||||
* Type face of the forwarded-Host-event allowlist: the consumer key projection
|
||||
* and the selection seat it fills. The allowlist VALUE lives in
|
||||
* `./remote-events.ts`, keeping this module type-only per the package
|
||||
* convention; both compiler faces list both files, so the Host forwarding loop
|
||||
* and the consumer `ctx.remote.$on` key face read one declaration instead of
|
||||
* two copies that could drift.
|
||||
*
|
||||
* @module @deepseek-ai/dsh-api-remotes/types
|
||||
*/
|
||||
|
||||
/**
|
||||
* Host events this application forwards to consumers verbatim: no projection,
|
||||
* no redaction, no renaming. The wire name is the Host cordis event name and
|
||||
* the payload is its argument list, so this array is simultaneously the whole
|
||||
* control point over what a consumer can receive and the legal key set of
|
||||
* `ctx.remote.$on`. Forwarding one more event is an entry here and nothing
|
||||
* else.
|
||||
*/
|
||||
export const API_REMOTE_FORWARDED_EVENTS = [
|
||||
'commands/change',
|
||||
'credentials/updated',
|
||||
'settings/document-updated',
|
||||
] as const
|
||||
import type { API_REMOTE_FORWARDED_EVENTS } from './remote-events.ts'
|
||||
|
||||
/** Type projection of the allowlist; the consumer and the Host read this one. */
|
||||
export type ApiRemoteForwardedEvent = typeof API_REMOTE_FORWARDED_EVENTS[number]
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { Context } from '@deepseek-ai/cordis'
|
||||
import { credentialRef } from '@deepseek-ai/dsh-credentials'
|
||||
import InvariantService from '@deepseek-ai/dsh-invariants'
|
||||
import { settingsNamespace } from '@deepseek-ai/dsh-settings'
|
||||
import { API_REMOTE_FORWARDED_EVENTS } from '@deepseek-ai/dsh-api-remotes'
|
||||
import type { ApiRemoteForwardedEvent } from '@deepseek-ai/dsh-api-remotes'
|
||||
import * as ApiRemotesInvariant from '@deepseek-ai/dsh-api-remotes/invariant'
|
||||
|
||||
async function setup(): Promise<Context> {
|
||||
const ctx = new Context()
|
||||
await ctx.plugin(InvariantService)
|
||||
await ctx.plugin(ApiRemotesInvariant)
|
||||
return ctx
|
||||
}
|
||||
|
||||
/**
|
||||
* One legal emission per allowlisted event. `Events` types each emit by name,
|
||||
* so the three arities (0, 2, 1) cannot share a single loop body; keying the
|
||||
* table by {@link ApiRemoteForwardedEvent} makes the compiler reject it as soon
|
||||
* as the allowlist grows, which keeps "every listed event is exercised" true
|
||||
* without a single argument-list assertion.
|
||||
*/
|
||||
const legalEmission: Record<ApiRemoteForwardedEvent, (ctx: Context) => void> = {
|
||||
'commands/change': ctx => { ctx.emit('commands/change') },
|
||||
'credentials/updated': ctx => { ctx.emit('credentials/updated', credentialRef('DEMO_TOKEN')) },
|
||||
'settings/document-updated': ctx => {
|
||||
ctx.emit('settings/document-updated', settingsNamespace('demo'), 1)
|
||||
},
|
||||
}
|
||||
|
||||
describe('forwarded host event invariants', () => {
|
||||
it('accepts an unscoped one-way dispatch of every allowlisted event', async () => {
|
||||
const ctx = await setup()
|
||||
for (const event of API_REMOTE_FORWARDED_EVENTS) {
|
||||
expect(() => { legalEmission[event](ctx) }).not.toThrow()
|
||||
}
|
||||
})
|
||||
|
||||
it('ignores an owner package event the allowlist does not select', async () => {
|
||||
const ctx = await setup()
|
||||
// `settings/updated` is the resolved-value event, deliberately left out of
|
||||
// the allowlist while its sibling `settings/document-updated` is in it, so
|
||||
// this pins that the check discriminates by name rather than by owner.
|
||||
expect(() => {
|
||||
ctx.emit('settings/updated', settingsNamespace('demo'), { a: 1 }, { a: 2 }, 'update')
|
||||
}).not.toThrow()
|
||||
// The carrier that fails an allowlisted event must pass unremarked here.
|
||||
expect(() => {
|
||||
ctx.emit({}, 'settings/updated', settingsNamespace('demo'), { a: 1 }, { a: 2 }, 'update')
|
||||
}).not.toThrow()
|
||||
})
|
||||
|
||||
it('rejects an allowlisted event dispatched with a Scope carrier', async () => {
|
||||
const ctx = await setup()
|
||||
expect(() => { ctx.emit({}, 'commands/change') })
|
||||
.toThrow(/"commands\/change" was dispatched with a Scope carrier/)
|
||||
})
|
||||
|
||||
it('rejects an allowlisted event dispatched as anything but one-way', async () => {
|
||||
const ctx = await setup()
|
||||
expect(() => { ctx.bail('commands/change') })
|
||||
.toThrow(/"commands\/change" was dispatched as "bail"/)
|
||||
})
|
||||
})
|
||||
@@ -7,6 +7,7 @@
|
||||
},
|
||||
"files": [
|
||||
"src/client/index.ts",
|
||||
"src/remote-events.ts",
|
||||
"src/types.ts"
|
||||
],
|
||||
"references": [
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
"src/agent-lookup.ts",
|
||||
"src/index.ts",
|
||||
"src/invariant.ts",
|
||||
"src/remote-events.ts",
|
||||
"src/types.ts"
|
||||
],
|
||||
"references": [
|
||||
|
||||
Reference in New Issue
Block a user