2026-07-16 18:13:34 +08:00
<!-- Generated by scripts/gen-website-api.ts — do not edit by hand. Run `pnpm run gen-website-api` to regenerate. -->
2026-07-09 16:07:58 +08:00
# Context
2026-07-16 18:13:34 +08:00
The context is the core cordis object: every service, event, and lifecycle API is reached through `ctx` . Event methods (`ctx.on` , `ctx.emit` , …) are documented on [Events ](./events.md ); `ctx.effect` and `ctx.fiber` on [Fiber ](./fiber.md ); `ctx.plugin` and `ctx.inject` on [Registry ](./registry.md ).
Root and child dependency containers for Cordis plugins.
A context is a proxy: normal property reads go through the service resolver, while `extend()` , `isolate()` , and `intercept()` create scoped child contexts without mutating their parent.
[Source ](https://github.com/deepseek-harness/deepseek-harness/blob/master/vendor/cordis/src/context.ts#L42 )
2026-07-09 16:07:58 +08:00
2026-07-16 18:13:34 +08:00
### ctx.extend(meta?)
2026-07-09 16:07:58 +08:00
2026-07-16 18:13:34 +08:00
```ts website-api
2026-07-19 14:14:02 +08:00
/**
* Create a child context with extra metadata on top of the current scope.
*
* The child prototypally inherits every property of this context; own
* properties of ` meta` shadow the inherited ones. The parent is not mutated.
*
* @param meta — own properties (including symbol keys) to define on the child.
* @returns a child context inheriting from this one.
*/
2026-07-16 18:13:34 +08:00
extend(meta = {}): this
` ``
2026-07-09 16:07:58 +08:00
2026-07-16 18:13:34 +08:00
Create a child context with extra metadata on top of the current scope.
The child prototypally inherits every property of this context; own properties of ` meta` shadow the inherited ones. The parent is not mutated.
2026-07-09 16:07:58 +08:00
2026-07-16 18:13:34 +08:00
- ` meta` — own properties (including symbol keys) to define on the child.
2026-07-09 16:07:58 +08:00
2026-07-16 18:13:34 +08:00
**Returns** a child context inheriting from this one.
2026-07-09 16:07:58 +08:00
2026-07-16 18:13:34 +08:00
[Source](https://github.com/deepseek-harness/deepseek-harness/blob/master/vendor/cordis/src/context.ts#L99)
2026-07-09 16:07:58 +08:00
2026-07-16 18:13:34 +08:00
### ctx.isolate(name, label?)
` ``ts website-api
2026-07-19 14:14:02 +08:00
/**
* Create a child context with an independent service scope for ` name`.
*
* Below the returned context, reads and writes of the service ` name`
* resolve against the new label instead of the parent's, so a different
* implementation can be provided without affecting the parent scope.
* Passing the same ` label` to two ` isolate()` calls joins their scopes.
*
* @param name — the service name to isolate.
* @param label — scope label to join; defaults to a fresh unique symbol.
* @returns a child context whose ` name` service resolves in the new scope.
*/
2026-07-16 18:13:34 +08:00
isolate(name: string, label?: symbol)
` ``
2026-07-09 16:07:58 +08:00
2026-07-16 18:13:34 +08:00
Create a child context with an independent service scope for ` name`.
Below the returned context, reads and writes of the service ` name` resolve against the new label instead of the parent's, so a different implementation can be provided without affecting the parent scope. Passing the same ` label` to two ` isolate()` calls joins their scopes.
2026-07-09 16:07:58 +08:00
2026-07-16 18:13:34 +08:00
- ` name` — the service name to isolate.
- ` label` — scope label to join; defaults to a fresh unique symbol.
2026-07-09 16:07:58 +08:00
2026-07-16 18:13:34 +08:00
**Returns** a child context whose ` name` service resolves in the new scope.
2026-07-09 16:07:58 +08:00
2026-07-16 18:13:34 +08:00
[Source](https://github.com/deepseek-harness/deepseek-harness/blob/master/vendor/cordis/src/context.ts#L121)
2026-07-09 16:07:58 +08:00
### ctx.intercept(name, config)
2026-07-16 18:13:34 +08:00
` ``ts website-api
2026-07-19 14:14:02 +08:00
/**
* Add service-specific intercept config for plugins started below this
* context.
*
* Plugins loaded under the returned context see ` config` merged into the
* service's resolved config (ancestor entries first; see
* ` Service[symbols.resolveConfig]`). The parent context is not affected.
*
* @param name — the service name whose config to intercept.
* @param config — the intercept config to merge for that service.
* @returns a child context carrying the additional intercept entry.
*/
2026-07-16 18:13:34 +08:00
intercept<K extends InjectKey>(name: K, config: Context[K] extends { [symbols.config]: infer T } ? T : never): this
intercept(name: string, config: any): this
` ``
2026-07-09 16:07:58 +08:00
2026-07-16 18:13:34 +08:00
Add service-specific intercept config for plugins started below this context.
Plugins loaded under the returned context see ` config` merged into the service's resolved config (ancestor entries first; see ` Service[symbols.resolveConfig]`). The parent context is not affected.
2026-07-09 16:07:58 +08:00
2026-07-16 18:13:34 +08:00
- ` name` — the service name whose config to intercept.
- ` config` — the intercept config to merge for that service.
**Returns** a child context carrying the additional intercept entry.
[Source](https://github.com/deepseek-harness/deepseek-harness/blob/master/vendor/cordis/src/context.ts#L139)
2026-07-16 21:15:44 +08:00
### ctx.root
` ``ts website-api
2026-07-19 14:14:02 +08:00
/** The root context of the application (every child context shares it). @experimental */
2026-07-16 21:15:44 +08:00
root: this
` ``
The root context of the application (every child context shares it). @experimental
[Source](https://github.com/deepseek-harness/deepseek-harness/blob/master/vendor/cordis/src/context.ts#L22)
### ctx.baseUrl
` ``ts website-api
2026-07-19 14:14:02 +08:00
/** Base URL used to resolve relative plugin/module specifiers, if the runtime sets one. */
2026-07-16 21:15:44 +08:00
baseUrl?: string
` ``
Base URL used to resolve relative plugin/module specifiers, if the runtime sets one.
[Source](https://github.com/deepseek-harness/deepseek-harness/blob/master/vendor/cordis/src/context.ts#L24)
### ctx.events
` ``ts website-api
2026-07-19 14:14:02 +08:00
/** The event bus. Its methods are also mixed onto ` ctx` (` ctx.on`, ` ctx.emit`, ...). */
2026-07-16 21:15:44 +08:00
events: EventsService
` ``
The event bus. Its methods are also mixed onto ` ctx` (` ctx.on`, ` ctx.emit`, ...).
[Source](https://github.com/deepseek-harness/deepseek-harness/blob/master/vendor/cordis/src/context.ts#L26)
### ctx.logger
` ``ts website-api
2026-07-19 14:14:02 +08:00
/** The logging service. Call ` ctx.logger(name)` for a named logger. */
2026-07-16 21:15:44 +08:00
logger: LoggerService
` ``
The logging service. Call ` ctx.logger(name)` for a named logger.
[Source](https://github.com/deepseek-harness/deepseek-harness/blob/master/vendor/cordis/src/context.ts#L28)
### ctx.reflect
` ``ts website-api
2026-07-19 14:14:02 +08:00
/** The reflection layer backing the context proxy (` ctx.get`, ` ctx.provide`, ...). */
2026-07-16 21:15:44 +08:00
reflect: ReflectService
` ``
The reflection layer backing the context proxy (` ctx.get`, ` ctx.provide`, ...).
[Source](https://github.com/deepseek-harness/deepseek-harness/blob/master/vendor/cordis/src/context.ts#L30)
### ctx.registry
` ``ts website-api
2026-07-19 14:14:02 +08:00
/** The plugin registry. Its methods are mixed onto ` ctx` (` ctx.plugin`, ` ctx.inject`). */
2026-07-16 21:15:44 +08:00
registry: RegistryService
` ``
The plugin registry. Its methods are mixed onto ` ctx` (` ctx.plugin`, ` ctx.inject`).
[Source](https://github.com/deepseek-harness/deepseek-harness/blob/master/vendor/cordis/src/context.ts#L32)
2026-07-16 18:13:34 +08:00
## Static members
### Context.effect
` ``ts website-api
2026-07-19 14:14:02 +08:00
/** Symbol key under which a disposer exposes its {@link EffectMeta} diagnostics tree. */
2026-07-16 18:13:34 +08:00
static readonly effect: unique symbol
` ``
Symbol key under which a disposer exposes its EffectMeta diagnostics tree.
[Source](https://github.com/deepseek-harness/deepseek-harness/blob/master/vendor/cordis/src/context.ts#L44)
### Context.filter
` ``ts website-api
2026-07-19 14:14:02 +08:00
/** Symbol key for a context's listener filter, consulted on every event dispatch. */
2026-07-16 18:13:34 +08:00
static readonly filter: unique symbol
` ``
Symbol key for a context's listener filter, consulted on every event dispatch.
[Source](https://github.com/deepseek-harness/deepseek-harness/blob/master/vendor/cordis/src/context.ts#L46)
### Context.isolate
` ``ts website-api
2026-07-19 14:14:02 +08:00
/** Symbol key of the isolation map (see the ` Context[symbols.isolate]` property). */
2026-07-16 18:13:34 +08:00
static readonly isolate: unique symbol
` ``
Symbol key of the isolation map (see the ` Context[symbols.isolate]` property).
[Source](https://github.com/deepseek-harness/deepseek-harness/blob/master/vendor/cordis/src/context.ts#L48)
2026-07-09 16:07:58 +08:00
2026-07-16 18:13:34 +08:00
### Context.intercept
2026-07-09 16:07:58 +08:00
2026-07-16 18:13:34 +08:00
` ``ts website-api
2026-07-19 14:14:02 +08:00
/** Symbol key of the intercept map (see the ` Context[symbols.intercept]` property). */
2026-07-16 18:13:34 +08:00
static readonly intercept: unique symbol
` ``
2026-07-09 16:07:58 +08:00
2026-07-16 18:13:34 +08:00
Symbol key of the intercept map (see the ` Context[symbols.intercept]` property).
2026-07-09 16:07:58 +08:00
2026-07-16 18:13:34 +08:00
[Source](https://github.com/deepseek-harness/deepseek-harness/blob/master/vendor/cordis/src/context.ts#L50)
2026-07-09 16:07:58 +08:00
2026-07-16 18:13:34 +08:00
### Context.is(value)
` ``ts website-api
2026-07-19 14:14:02 +08:00
/**
* Returns true for Cordis context proxies and context prototypes.
*
* Works across realms and across multiple copies of cordis, because the
* brand is keyed by a global symbol rather than by ` instanceof`.
*
* @param value — the value to test.
* @returns ` true` if ` value` is a Cordis context, narrowing its type.
*/
2026-07-16 18:13:34 +08:00
static is(value: any): value is Context
` ``
Returns true for Cordis context proxies and context prototypes.
Works across realms and across multiple copies of cordis, because the brand is keyed by a global symbol rather than by ` instanceof`.
- ` value` — the value to test.
**Returns** ` true` if ` value` is a Cordis context, narrowing its type.
[Source](https://github.com/deepseek-harness/deepseek-harness/blob/master/vendor/cordis/src/context.ts#L61)
2026-07-16 21:15:44 +08:00
## Service store and mixins
2026-07-16 18:13:34 +08:00
### ctx.get(name, strict?)
` ``ts website-api
2026-07-19 14:14:02 +08:00
/**
* Read a service from the store without the inject requirement.
*
* @param name — the service name.
* @param strict — when ` true` (default), only return implementations
* whose providing fiber is currently active.
* @returns the service value, or ` undefined` when not (yet) provided.
*/
2026-07-16 18:13:34 +08:00
get<K extends string & keyof this>(name: K, strict?: boolean): undefined | this[K]
get(name: string, strict?: boolean): any
` ``
Read a service from the store without the inject requirement.
- ` name` — the service name.
- ` strict` — when ` true` (default), only return implementations whose providing fiber is currently active.
**Returns** the service value, or ` undefined` when not (yet) provided.
[Source](https://github.com/deepseek-harness/deepseek-harness/blob/master/vendor/cordis/src/reflect.ts#L16)
2026-07-09 16:07:58 +08:00
### ctx.set(name, value)
2026-07-16 18:13:34 +08:00
` ``ts website-api
2026-07-19 14:14:02 +08:00
/**
* Overwrite a provided service's value.
*
* Only the fiber that provided the service may set it; setting an
* unprovided name throws.
*
* @param name — the service name.
* @param value — the new service value.
*/
2026-07-16 18:13:34 +08:00
set<K extends string & keyof this>(name: K, value: undefined | this[K]): void
set(name: string, value: any): void
` ``
Overwrite a provided service's value.
Only the fiber that provided the service may set it; setting an unprovided name throws.
- ` name` — the service name.
- ` value` — the new service value.
[Source](https://github.com/deepseek-harness/deepseek-harness/blob/master/vendor/cordis/src/reflect.ts#L28)
### ctx.provide(name, value)
` ``ts website-api
2026-07-19 14:14:02 +08:00
/**
* Register a service implementation owned by the current fiber.
*
* The service becomes visible to dependents in the same isolation scope
* once the fiber is active; it is unregistered (waking dependents) when
* the returned disposer runs or the fiber unloads. Throws if the name is
* already provided in this scope or declared as an accessor.
*
* @param name — the service name.
* @param value — the service value.
* @returns a disposer that unregisters the service.
*/
2026-07-16 18:13:34 +08:00
provide<K extends string & keyof this>(name: K, value: undefined | this[K]): () => void
provide(name: string, value?: any): () => void
` ``
Register a service implementation owned by the current fiber.
The service becomes visible to dependents in the same isolation scope once the fiber is active; it is unregistered (waking dependents) when the returned disposer runs or the fiber unloads. Throws if the name is already provided in this scope or declared as an accessor.
- ` name` — the service name.
- ` value` — the service value.
**Returns** a disposer that unregisters the service.
[Source](https://github.com/deepseek-harness/deepseek-harness/blob/master/vendor/cordis/src/reflect.ts#L43)
### ctx.accessor(name, options)
2026-07-09 16:07:58 +08:00
2026-07-16 18:13:34 +08:00
` ``ts website-api
2026-07-19 14:14:02 +08:00
/**
* Define a computed context property backed by get/set hooks.
*
* The accessor is removed when the current fiber unloads. Throws if the
* name is already declared.
*
* @param name — the context property name.
* @param options — the ` get` hook and optional ` set` hook.
*/
2026-07-16 18:13:34 +08:00
accessor(name: string, options: Omit<Property.Accessor, 'type'>): void
` ``
2026-07-09 16:07:58 +08:00
2026-07-16 18:13:34 +08:00
Define a computed context property backed by get/set hooks.
The accessor is removed when the current fiber unloads. Throws if the name is already declared.
2026-07-09 16:07:58 +08:00
2026-07-16 18:13:34 +08:00
- ` name` — the context property name.
- ` options` — the ` get` hook and optional ` set` hook.
2026-07-09 16:07:58 +08:00
2026-07-16 18:13:34 +08:00
[Source](https://github.com/deepseek-harness/deepseek-harness/blob/master/vendor/cordis/src/reflect.ts#L55)
2026-07-09 16:07:58 +08:00
2026-07-16 18:13:34 +08:00
### ctx.mixin(name, mixins)
2026-07-09 16:07:58 +08:00
2026-07-16 18:13:34 +08:00
` ``ts website-api
2026-07-19 14:14:02 +08:00
/**
* Expose selected members of a service directly on ` ctx`.
*
* Each mixed-in key becomes an accessor that forwards to the service
* (binding methods to it), so e.g. ` ctx.on` forwards to ` ctx.events.on`.
* Mixins are removed when the current fiber unloads.
*
* @param name — the context property holding the source service.
* @param mixins — keys to forward, or a source-key → ctx-key map.
*/
2026-07-16 18:13:34 +08:00
mixin<K extends string & keyof this>(name: K, mixins: (keyof this & keyof this[K])[] | Dict<string>): void
mixin<T extends {}>(source: T, mixins: (keyof this & keyof T)[] | Dict<string>): void
` ``
2026-07-09 16:07:58 +08:00
2026-07-16 18:13:34 +08:00
Expose selected members of a service directly on ` ctx`.
Each mixed-in key becomes an accessor that forwards to the service (binding methods to it), so e.g. ` ctx.on` forwards to ` ctx.events.on`. Mixins are removed when the current fiber unloads.
2026-07-09 16:07:58 +08:00
2026-07-16 18:13:34 +08:00
- ` name` — the context property holding the source service.
- ` mixins` — keys to forward, or a source-key → ctx-key map.
2026-07-09 16:07:58 +08:00
2026-07-16 18:13:34 +08:00
[Source ](https://github.com/deepseek-harness/deepseek-harness/blob/master/vendor/cordis/src/reflect.ts#L66 )