Files
deepseek-harness/packages/session/session-format-v1-to-v2
Turtle 38c7a9fbf4 feat(release): publish package source, declaration maps, and documentation (#5884)
* feat(release): publish package source, declaration maps, and documentation

Every release member publishes its TypeScript source and the declaration
maps that resolve into it, and @deepseek-ai/dsh publishes the repository
Markdown documentation staged from docs/ at prepack time.

The ./src/* export most members already declared now resolves for an
installed consumer, and a consumer editor follows a declaration to the
implementation. Bundled JavaScript maps stay unpublished; the vendored
family and the Desktop runtime file policy are unchanged.

Rationale: .agents/notes/implemented/process/2026-10-08-published-source-and-docs.md

* feat(release): publish JavaScript maps and compress bundles

Every emitted JavaScript map ships beside the bundle it describes, and the
workspace build and the client preset compress bundles without mangling
identifiers.

The documentation payload now mirrors the website publication manifest and
is removed again by `postpack`; Desktop and the Python executable exclude
the published source, documentation, and maps; `clean` removes a staged
copy. Typert's publication contract gains the Remote declaration map.

* fix(release): keep node bundles readable for the worker image

The browser worker image lowers `yield*` only as a whole statement and
rewrites `for await` loops by their source layout, so compressed node-side
entries either fail that lowering or lower to unparseable code. Only the
browser bundles keep compression, which removes about a third of their text.

The bundle-purity assertion now matches the module-loader call regardless of
the quote style compression picks, and the release-pack fixture exercises
the installed package's new documentation requirement.

* feat(release): publish the whole documentation tree

`@deepseek-ai/dsh` copies `docs/` in full instead of the website's page
set: the maintainer documents, the generated migration records, the
translation guidelines, and the `*.i18n.yaml` consistency records ship
with the installed package, so the documentation's own links resolve
without a checkout.

* feat(release): publish the upgrade guides with the documentation

The staged documentation keeps the website's page set and adds every
`docs/upgrade-guide/` document, which is what an installed reader consults
when a released change breaks something. The rest of the maintainer tree
stays out.

* test(release): expect source and maps in master's new payload cases

* feat(release): keep installed docs and source readable in Desktop

Desktop keeps the published src/ and docs/ trees inside app.asar, and
every model shell call receives DSH_INSTALL_DIR and DSH_NODE_EXECUTABLE
so an agent can read them through Electron's Node mode. Staging also
generates docs/upgrade-guide/README.md, an index of the upgrade guides
grouped by the release they upgrade from.

Minified client bundles print string literals with backticks: the
worker image packer now recognizes those chunk requests, client license
banners are prepended after minification so their text survives, and
the affected artifact tests accept either quote.

* test(desktop): read archived docs through the Windows PowerShell form

Regenerate the config catalog for the shifted shell-env source line.

* test(desktop): wait for the GUI-subsystem Electron process from PowerShell

* build(release): publish source and maps from the message-quotes package

* build(release): publish source and maps from packages new on master

* build(release): publish source and maps from the tool-office package
2026-11-05 00:22:36 +08:00
..

description, kind
description kind
Frozen released-v1 Session reader and cardinality-changing migration that embeds Assistant streams in released v2 events. package-reference

@deepseek-ai/dsh-session-format-v1-to-v2

English | 中文

Summary

dsh-session-format-v1-to-v2 converts a released-v1 Session into the released-v2 event model through one stateful event stage. It consumes top-level assistant/chunk events, embeds their exact timed stream in the matching assistant/message, and records an assistant/attempt when a failed, retried, cancelled, or stream-error attempt reached settlement without a surface message. The edge densely remaps surviving events and every declared same-Session sequence reference, while the v2 codec stores one event per row and derives the inherited cut from a tagged session/end-seed marker.

Table of Contents


Use this package

When to use it

Persistence obtains this edge through dsh-session-format-catalog; feature compositions do not mount it. Import it directly only when assembling or testing the static released-format catalog or inspecting the exact v1-to-v2 transformation.

Entry point

const decoder = releasedV1SessionFormatCodec.createDecoder(physicalHeader, 'strict')
for (const row of physicalRows) decoder.decodeRow(row, migrationContext)
const stage = sessionFormatV1ToV2.createStage(stageInput)
stage.transformEvent(event, migrationContext)
const targetInheritedEventCount = stage.finish(migrationContext)
const headerRecord = releasedV2SessionFormatCodec.encodeHeader(currentHeader, targetInheritedEventCount)
const eventRecord = releasedV2SessionFormatCodec.encodeEvent(currentEvent)

releasedV1SessionFormatCodec reads the frozen v1 physical language one row at a time. sessionFormatV1ToV2 creates the cardinality-changing Stage that the static catalog connects to that decoder without retaining a v1 event array. The catalog remaps declared references and validates the released-v2 envelope, inherited cut, event admission, and relationships. Persistence applies full installed-current validation in its Worker before publication. releasedV2SessionFormatCodec creates a released-v2 row decoder and encodes v2 headers and events one record at a time.

A successful v1 assistant/message must cite its complete ordered attempt. The migration removes the cited top-level chunks and obsolete message chunk references, compacts the chunks without joining token boundaries, and stores the stream on that message. An unclaimed attempt becomes one log-only assistant/attempt at its final chunk position. Unrelated interleaved events keep their relative order.

The edge also closes the bounded legacy restart pattern in which a non-empty next-turn inbox insertion is followed by the next turn/start without the prior turn/end. It records that prior turn as interrupted. A legacy round-zero goal mutation becomes a goal/change followed by the original model-visible message with ordinary plugin attribution, so both durable goal state and historical model input survive.

The migration refuses a reference to a consumed chunk instead of redirecting it to a different semantic event. It remaps declared source-event references, surface replacements, command source events, compaction ranges and lists, and title message lists. The already model-visible session/title-llm-request.messages text remains byte-identical after source validation, so target validation does not reinterpret the old sequence numbers embedded in that prompt. A seeded source also refuses an inherited cut that splits an Assistant attempt; the target marks the exact cut with session/end-seed { inherited: true }.

The v2 physical header requires isSeeded and does not store a numeric cut. The codec derives the cut from the last inherited end-seed marker, writes one event per row, range-encodes only sourceEventSeqs, and remains neutral to ordinary event vocabulary and payload growth. Released-current restoration admits event types known to the installed Session package plus unknown events carrying ignorable: true, and validates event members and relationships. Ordinary Session restoration checks runtime-required settlement fields without replaying embedded streams; persistence publication and the frozen writer-image fixture validator retain full stream verification.


Understand the implementation

Implementation internals — click to expand

The incremental edge retains one unsettled Assistant attempt, events whose output position depends on that attempt, and the dense old-to-new sequence map. It emits settled survivors in source order and rewrites only reference fields declared by the frozen event inventory. Released-current validation rejects any relationship the transformation cannot preserve.

File Role
src/migration.ts Attempt grouping, settlement substitution, dense sequence mapping, and reference rewriting
src/codec.ts Released-v2 header, one-event-per-row encoding, source-event ranges, and recoverable prefix decoding
src/validation.ts Physical v2 envelope/cut validation and released-current event admission and relationships
src/dispositions.ts Frozen released-v2 event and payload-member inventory

Further Exploration


Model Experience

Historical restoration

What the model sees

Successful Assistant messages retain the content, provider, model, usage, and replay state assembled from the same v1 stream. Failed or abandoned attempts remain durable diagnostics through assistant/attempt but do not enter deriveMessages().

Token effect

The migration adds no model-visible content. It preserves the derived message history and removes only top-level chunk envelopes from the current logical event sequence.

KV Cache effect

The restored model-message sequence stays unchanged, so the migration alone does not alter request-prefix cache identity.

Known Limitations and Deferred Work

  • Closed first-party source inventory — an unknown v1 event refuses migration, including an event marked ignorable: true.
  • Linear remap state — streaming retains no complete v1 event array, but the final v2 event array and old-to-new sequence map remain O(event count).
  • No publication or compatibility fallback — persistence owns exclusive successor publication, and retained v1 generations are not automatic downgrade or restore inputs.

Dev Note

Working context for maintainers — click to expand

None.