Files
deepseek-harness/docs/cordis-api/fiber.md
T

13 KiB

Fiber

A fiber is one loaded plugin instance: its lifecycle state, validated config, and registered effects. ctx.fiber is the current fiber, and ctx.effect() delegates to it.

ctx.effect(execute, label?)

/**
 * Register a cleanup-aware effect on this fiber.
 *
 * `execute` runs immediately; the disposers it produces are collected and
 * run (in reverse order) either when the returned disposer is called or
 * when the fiber unloads, whichever comes first. Calling the disposer twice
 * is a no-op. Throws `CordisError('INACTIVE_EFFECT')` if the fiber is
 * already disposed, and `TypeError` if `execute` returns an invalid shape.
 *
 * @param execute — the effect body; see {@link Effect} for accepted shapes.
 * @param label — effect label shown in `getEffects()` diagnostics.
 * @returns a disposer that tears the effect down and settles once done.
 */
effect(execute: () => SyncEffect, label?: string): Disposable<Promise<void>>
effect(execute: () => Effect, label?: string): AsyncDisposable<Promise<void>>

Register a cleanup-aware effect on this fiber.

execute runs immediately; the disposers it produces are collected and run (in reverse order) either when the returned disposer is called or when the fiber unloads, whichever comes first. Calling the disposer twice is a no-op. Throws CordisError('INACTIVE_EFFECT') if the fiber is already disposed, and TypeError if execute returns an invalid shape.

  • execute — the effect body; see Effect for accepted shapes.
  • label — effect label shown in getEffects() diagnostics.

Returns a disposer that tears the effect down and settles once done.

Source

ctx.fiber

/** The fiber (plugin runtime instance) that owns this context. */
fiber: Fiber

The fiber (plugin runtime instance) that owns this context.

Source

The Fiber class

Runtime instance of one plugin application.

A fiber tracks dependency state, raw and effective config, lifecycle effects, and cleanup for the plugin context returned by ctx.plugin().

Source

fiber.uid

/** Unique id within the registry; 0 for the root fiber, `null` once disposed. */
public uid: number | null

Unique id within the registry; 0 for the root fiber, null once disposed.

Source

fiber.ctx

/** The context this fiber's plugin runs in (extends the parent context). */
public readonly ctx: Context

The context this fiber's plugin runs in (extends the parent context).

Source

fiber.config

/** Raw plugin input retained for the next activation. */
public config: any

Raw plugin input retained for the next activation.

Source

fiber.state

/** Current lifecycle state; transitions emit `internal/status`. */
public state

Current lifecycle state; transitions emit internal/status.

Source

fiber.dispose

/** Dispose this fiber: unload the plugin, then settle once cleanup finished. */
public readonly dispose: () => Promise<void>

Dispose this fiber: unload the plugin, then settle once cleanup finished.

Source

fiber.committed

/** Required implementations retained through dependent teardown. */
public committed: Readonly<Dict<Impl>> | undefined

Required implementations retained through dependent teardown.

Source

fiber.provisions

/** Service implementations owned by this fiber, including isolated provisions. */
public readonly provisions: Set<Impl>

Service implementations owned by this fiber, including isolated provisions.

Source

fiber.inertia

/** The in-flight load/unload transition, if one is currently running. */
public inertia: Promise<void> | undefined

The in-flight load/unload transition, if one is currently running.

Source

fiber.name

/** The plugin's display name, inherited from the nearest named ancestor, else `'root'`. */
get name()

The plugin's display name, inherited from the nearest named ancestor, else 'root'.

Source

fiber.assertActive()

/**
 * Throw if the fiber has already been disposed.
 *
 * @returns nothing when the fiber is still active.
 * @throws {CordisError} `INACTIVE_EFFECT` when the fiber's uid has been cleared.
 */
assertActive()

Throw if the fiber has already been disposed.

Returns nothing when the fiber is still active.

Source

fiber.effect(execute, label?)

/**
 * Register a cleanup-aware effect on this fiber.
 *
 * `execute` runs immediately; the disposers it produces are collected and
 * run (in reverse order) either when the returned disposer is called or
 * when the fiber unloads, whichever comes first. Calling the disposer twice
 * is a no-op. Throws `CordisError('INACTIVE_EFFECT')` if the fiber is
 * already disposed, and `TypeError` if `execute` returns an invalid shape.
 *
 * @param execute — the effect body; see {@link Effect} for accepted shapes.
 * @param label — effect label shown in `getEffects()` diagnostics.
 * @returns a disposer that tears the effect down and settles once done.
 */
effect(execute: () => SyncEffect, label?: string): Disposable<Promise<void>>
effect(execute: () => Effect, label?: string): AsyncDisposable<Promise<void>>

Register a cleanup-aware effect on this fiber.

execute runs immediately; the disposers it produces are collected and run (in reverse order) either when the returned disposer is called or when the fiber unloads, whichever comes first. Calling the disposer twice is a no-op. Throws CordisError('INACTIVE_EFFECT') if the fiber is already disposed, and TypeError if execute returns an invalid shape.

  • execute — the effect body; see Effect for accepted shapes.
  • label — effect label shown in getEffects() diagnostics.

Returns a disposer that tears the effect down and settles once done.

Source

fiber.getEffects()

/**
 * Return metadata for currently registered effects.
 *
 * @returns one {@link EffectMeta} tree per labeled live effect.
 */
getEffects()

Return metadata for currently registered effects.

Returns one EffectMeta tree per labeled live effect.

Source

fiber.rawConfig

/** Raw input retained for the next activation, without evaluating expressions or validating it. */
get rawConfig(): unknown

Raw input retained for the next activation, without evaluating expressions or validating it.

Source

fiber.effectiveConfig

/**
 * The object passed to plugin activation or the latest successful update that retained the instance.
 * Candidate resolution does not publish it; volatile updates retain its references.
 * Undefined before activation and readable after unload; callers requiring a live instance check `state`.
 */
get effectiveConfig(): unknown

The object passed to plugin activation or the latest successful update that retained the instance. Candidate resolution does not publish it; volatile updates retain its references. Undefined before activation and readable after unload; callers requiring a live instance check state.

Source

fiber.resolveConfig(config)

/**
 * Evaluate and validate a candidate using this fiber's `internal/config` hooks and runtime schema.
 * Does not publish the result, replace raw input, or commit running volatile references.
 * Required injections must be available when a hook uses them.
 * @param config Raw candidate input.
 * @returns The candidate's resolved config, retaining the schema's result identity.
 * @throws {ValidationError} when the runtime schema rejects the candidate; hook errors propagate.
 */
resolveConfig(config: unknown): unknown

Evaluate and validate a candidate using this fiber's internal/config hooks and runtime schema. Does not publish the result, replace raw input, or commit running volatile references. Required injections must be available when a hook uses them.

  • config — Raw candidate input.

Returns The candidate's resolved config, retaining the schema's result identity.

Source

fiber.await()

/**
 * Wait for current lifecycle work and rethrow startup errors.
 *
 * @returns this fiber, once it has settled into a stable state.
 * @throws the config-validation or plugin-startup error, if any.
 */
async await()

Wait for current lifecycle work and rethrow startup errors.

Returns this fiber, once it has settled into a stable state.

Source

fiber.restart()

/**
 * Dispose and immediately reload this plugin with its current config.
 *
 * @returns a promise resolving once the reload settled.
 * @throws {CordisError} `INACTIVE_EFFECT` when the fiber is already disposed.
 */
async restart()

Dispose and immediately reload this plugin with its current config.

Returns a promise resolving once the reload settled.

Source

fiber.update(config, noSave?)

/**
 * Resolve a candidate, retain its raw config and apply it through the update waterfall.
 * @param config Raw config; pending fibers defer resolution until activation.
 * @param noSave Suppress the persistence notification when true.
 * @returns The awaited update/restart result, or undefined when a synchronous listener handles it.
 * @throws {ValidationError} when an active fiber's candidate is invalid.
 */
update(config: any, noSave = false): Awaitable<void>

Resolve a candidate, retain its raw config and apply it through the update waterfall.

  • config — Raw config; pending fibers defer resolution until activation.
  • noSave — Suppress the persistence notification when true.

Returns The awaited update/restart result, or undefined when a synchronous listener handles it.

Source

Effect

Effect body result accepted by ctx.effect() and plugin startup.

Either a single disposer, a promise of one, or a (possibly async) iterable yielding several — generator effects register each yielded disposer as it is produced.

/**
 * Effect body result accepted by `ctx.effect()` and plugin startup.
 *
 * Either a single disposer, a promise of one, or a (possibly async) iterable
 * yielding several — generator effects register each yielded disposer as it
 * is produced.
 */
type Effect<T = any> =
  | SyncEffect<T>
  | AsyncEffect<T>

Source

Disposable

Function returned by an effect to release resources during disposal.

Disposers run in reverse registration order when the owning fiber unloads; they may be async, in which case unloading awaits them.

/**
 * Function returned by an effect to release resources during disposal.
 *
 * Disposers run in reverse registration order when the owning fiber unloads;
 * they may be async, in which case unloading awaits them.
 */
type Disposable<T = any> = () => T

Source

EffectMeta

Tree node used to expose nested effect labels for diagnostics.

/** Tree node used to expose nested effect labels for diagnostics. */
interface EffectMeta {
  /** Human-readable effect label, e.g. `ctx.on("event")` or `ctx.provide("name")`. */
  label: string
  /** Metadata of nested effects registered while this effect ran. */
  children: EffectMeta[]
}

Source

CordisError

Framework error with a stable machine-readable code.

/** Framework error with a stable machine-readable code. */
class CordisError extends Error {
  /**
   * @param code — the stable error code; also the default message.
   * @param message — optional human-readable override.
   */
  constructor(public code: CordisError.Code, message?: string)
}

/** Cordis error code definitions. */
namespace CordisError {
  export type Code = keyof typeof Code

  export const Code = {
    INACTIVE_EFFECT: 'cannot create effect on inactive context',
  } as const
}

Source

ValidationError

Error raised when plugin configuration fails standard-schema validation.

/** Error raised when plugin configuration fails standard-schema validation. */
class ValidationError extends TypeError {
  name = 'ValidationError'

  /**
   * Build the aggregated message from schema issues.
   *
   * @param issues — the standard-schema issues, one message line each.
   */
  constructor(issues: readonly StandardSchemaV1.Issue[])
}

Source