Files
deepseek-harness/website/zh-CN/api/harness/sessions.md
lintianle fcd9d8c391 website: fix nine review findings (generator coverage, loader facts, mode semantics)
Generator (all four structural gaps):
- harness service pages now render public properties/accessors, not just
  methods (ctx.codeRuntime.language/isolation were missing);
- the class page merges the same-named interface half, so ctx.root/baseUrl/
  events/logger/reflect/registry appear on Context (vendor root JSDoc gains
  prose alongside @experimental);
- Pick<…> heritage on a Context merge resolves to the picked class members,
  giving ctx.effect a documented signature on the Fiber page;
- {@link} tags normalize to code spans; merge sections get their own h2 so
  reflect members no longer nest under 'Static members'.

verify-website-yaml: reject the unloadable 'group:' pseudo-name (tree.import
only special-cases 'cordis:'; no builtin is registered here) and recurse into
@cordisjs/plugin-group nested entry lists instead.

Prose corrected against loader/cordis source: service.md isolation example
uses the real group plugin + group: true + the required isolate map;
config.md documents concurrent entry startup (Promise.all; order via inject)
and the real hmr defaults (root ['.'], base/ignored/debounce); events.md
fixes emit (synchronous, not parallel), bail (null/false also delegate), and
serial (stops at the first bail value).
2026-07-16 21:15:44 +08:00

5.5 KiB

ctx.sessions

SessionStore — provided by @deepseek-ai/dsh-session.

In-memory session store (ctx.sessions). Persistence is intentionally not implemented here — persistence plugins subscribe to session/event and flush on session/flush / dispose.

Source

ctx.sessions.create(id?, options?)

create(id?: SessionId, options?: CreateSessionOptions): Session

Create a session owned by the calling fiber: disposing that fiber stops event notification and removes the session from the store. options.seed populates the session with a copy of those events (replay/fork); options.meta attaches creation metadata (validated absolute cwd, parentSession lineage) as the immutable SessionHeader (the store fills version/id/createdAt). For an agent whose session must be torn down IN ORDER with its loop (so the loop's final flush is captured before onAppend detaches), do NOT use this — fold the session lifecycle into the agent's own effect via prepare + enter + announce (see dsh-agent-loop's startOwned).

  • id — the session id; omitted, the store mints session-<n>.
  • options — seed events and/or creation metadata for the header.

Returns the live session, already entered and announced.

Source

ctx.sessions.prepare(id?, options?)

prepare(id?: SessionId, options?: CreateSessionOptions): Session

Build a session WITHOUT entering it into the store — validate the id/cwd and construct the Session (with its immutable SessionHeader). Pairs with enter + announce: a caller that owns a composite ctx.effect (the agent factory) folds the session lifecycle into that ONE effect so a fiber unload tears the session + agent down as a single ORDERED chain rather than as racing sibling effects — which would detach onAppend before the loop's closing session/flush, dropping the closing events.

  • id — the session id; omitted, the store mints session-<n>.
  • options — seed events and/or creation metadata for the header.

Returns the constructed session, NOT yet in the store.

Source

ctx.sessions.enter(session)

enter(session: Session): () => void

Enter a prepared session into the store: wire onAppend → session/event and add it to the store. Returns the DETACH disposer (onAppend = undefined + store removal). Does NOT emit session/created — the caller yields this disposer inside its effect and THEN calls announce, so a throwing session/created listener rolls the attach back instead of leaking it. Re-checks the id for a duplicate: prepare and enter are public cross-package primitives and a caller may interleave arbitrary work (or another create) between them, so a stale prepared session must NOT overwrite a live store entry of the same id — its detach disposer would later delete the REAL session. The create convenience and the agent factory call the two back-to-back so they never trip this, but the public seam cannot assume that.

  • session — a prepared session not yet in the store.

Returns the detach disposer (onAppend = undefined + store removal).

Source

ctx.sessions.announce(session)

announce(session: Session): void

Emit session/created for an entered session. Separate from enter so the caller can yield the detach disposer first (rollback safety — see enter).

  • session — the entered session to announce to listeners.

Source

ctx.sessions.get(id)

get(id: SessionId): Session | undefined

Look up a live session.

  • id — the session id to look up.

Returns the session, or undefined when no live session has that id.

Source

ctx.sessions.list()

list(): Session[]

All live sessions, in creation order.

Returns a fresh array; mutating it does not affect the store.

Source

ctx.sessions.fork(source, boundary?, childSessionId?)

fork(source: SessionForkSource, boundary?: number, childSessionId?: SessionId): Session

Create a live child session from a turn-enclosed prefix of a live source. boundary is an inclusive source event seq; omitted means the source's current last event. A non-empty selected slice must end at turn/end.

  • source — Live source session object or id.
  • boundary — Inclusive source event seq to fork through; omitted means the source's current last event, and omitted on an empty source forks an empty child.
  • childSessionId — Optional child session id; omitted delegates to SessionStore's id policy.

Returns The created live child session.

Source