* refactor(session): move Session log validation into a module Move header, seed-event envelope, and inherited-cut validation out of the Session constructor into validation.ts without changing check order or error text. Export needsInheritedSeedMarker for the fork marker rule the constructor applies. * feat(session): validate a Session log without constructing a Session validateSessionLog composes the header, seed-event, surface, and inherited-cut checks of Session construction in the same order. Omitting eventState matches Session.create; an event state matches Session.fromRestore. * refactor: validate stored Session logs with validateSessionLog The chat importer, session-query readSession, the format catalog, and JSONL generation verification constructed a discarded Session only to validate a log. They now call validateSessionLog with the same mode, inherited count, and message interpreters. * refactor(session): extract buildSessionHeader Move new-Session header construction out of SessionStore.prepare into the exported buildSessionHeader and name its input SessionHeaderMeta. Automatic ids and duplicate checks stay in prepare. * refactor(session): move header and fork error helpers out of the session index Move buildSessionHeader into validation.ts and SessionForkError with SessionForkErrorCode into fork.ts so later modules can import them without importing index.ts. index.ts re-exports both under the same names. Complete the JSDoc of the exported validation helpers. * refactor(session): extract checkSessionLog from the Session constructor Move header validation, seed acceptance with surface admission, and the inherited-cut check into checkSessionLog in validation.ts, keeping the constructor's order and errors. The Session constructor and validateSessionLog call it. * test(session): cover Session log validation and construction helpers Cover validateSessionLog against Session.create and Session.fromRestore in every event state, buildSessionHeader, needsInheritedSeedMarker, Session.readEvents range semantics, and the fork subpath export of SessionForkError. * docs(session): document Session log validation Document validateSessionLog, buildSessionHeader, needsInheritedSeedMarker, Session.readEvents, and the SessionForkError subpath export in the package README. Align the Session and CreateSessionOptions type blocks, add SessionHeaderMeta, regenerate the Cordis, event graph, and persistence catalogs, and update the plugin entry, unknown-cast, and package dependency registries. --------- Co-authored-by: imccyu <[email protected]>
description, kind
| description | kind |
|---|---|
| Build-static first-party Session format codec and adjacent migration assembly for persistence readers. | package-library |
@deepseek-ai/dsh-session-format-catalog
English | 中文
Summary
dsh-session-format-catalog gives persistence one deterministic Session format reader without consulting mounted plugins. It assembles codecs and adjacent edges from the earliest supported format through the current writer format, checks the complete gap-free chain at module initialization, and exposes physical dispatch, header-only classification, single-pass row restoration, and current record encoding through sessionFormatCatalog.
Table of Contents
- Use this package
- Understand the implementation
- Further Exploration
- Model Experience
- Known Limitations and Deferred Work
- Dev Note
Use this package
When to use it
Import this library from persistence and test-support readers that need the complete first-party released-format inventory before any feature plugin mounts. Feature compositions do not register or reorder its entries.
Entry point
const descriptor = sessionFormatCatalog.readHeader(physicalHeader)
const catalog = createSessionFormatCatalogWithChildren(childFacts)
const restore = catalog.createRestore(physicalHeader, { recovery: 'recoverable', validation: 'transformed' })
for (const row of physicalRows) restore.decodeRow(row)
const current = restore.finish()
const headerRecord = sessionFormatCatalog.encodeCurrentHeader(current.header, current.inheritedEventCount)
const eventRecords = current.events.map(sessionFormatCatalog.encodeCurrentEvent)
Import sessionFormatCatalog from the package root. JSONL and fixture readers create one restore, push each parsed physical row through decodeRow(), and call finish() once. Writers serialize the returned current artifact through encodeCurrentHeader() and encodeCurrentEvent(). Listing calls readHeader() and never opens event bodies.
Production historical reads select { recovery: 'recoverable', validation: 'transformed' }. Worker and fixture verification select { recovery: 'strict', validation: 'current' }. Transformed validation runs the released-current rules after migration but deliberately skips installed semantic validation for input that is already current.
The catalog contains all supported historical readers directly. A profile cannot add, remove, or reorder an edge by mounting a feature plugin. Its peer dependency on dsh-session supplies the installed current event vocabulary and current restoration rules, while historical edge validators remain frozen. The browser-safe ./message-projections export assembles current plugin-owned interpreters for detached constructors and surface folds; it does not mount recovery listeners.
createSessionFormatCatalogWithChildren(childFacts) binds explicit child evidence to V3→V4 during assembly; see the catalog-completion specification. historicalSessionFormatCatalog restores V0–V3 using the fixed released-V3 event vocabulary to collect child prerequisites without recursively completing their catalogs. An ignorable V3 extension remains opaque even when the installed writer knows its name. Isolated transcript replay explicitly supplies an empty array; persistence must collect the complete available direct-child set. Keep the supplied evidence unchanged for the catalog’s lifetime. Each restore owns independent stage state. The static sessionFormatCatalog supports header and native current-format reads; historical body reads require the child-bound catalog.
Understand the implementation
Implementation internals — click to expand
src/generated.ts is the static owner of codec and edge ordering. src/current.ts delegates final header, envelope, message, surface, seed, and current request-header validation to the installed Session semantics. The low-level constructor rejects duplicate codecs, duplicate edges, gaps, and entries beyond the current version before any Session read can begin.
Further Exploration
- Migration machinery — catalog construction and dispatch behavior.
- Released v0 to v1 edge — codec and validator ownership.
- Released v1 to v2 edge — Assistant stream embedding and cardinality-changing reference remapping.
- Released V2 to V3 specification — transformations, preservation, and refusal.
- V3 to V4 specification — conversion, reference remapping, and delivery-generation validation.
- JSONL persistence — immutable generation naming and exclusive publication.
Model Experience
Catalog dispatch
What the model sees
Nothing directly. The catalog only restores the SessionEvent history consumed by request reconstruction.
Token effect
Zero direct tokens.
KV Cache effect
No direct effect; restored history determines cache identity in its consumer.
Known Limitations and Deferred Work
- First-party build inventory only — external migration ownership and distribution are not supported.
- Generated ordering is closed — runtime plugin registration cannot supply a missing historical edge.
Dev Note
Working context for maintainers — click to expand
None.