description: "Cross-session snapshot references and durable untrusted model context, for users and maintainers enabling or debugging ctx.sessionReferenceResolver."
English | 中文
dsh-session-reference lets a conversation reference other sessions: a host turns a @label mention into a canonical URI, and the service prepares a bounded, read-only snapshot of each referenced session as durable, untrusted background context for the model. Candidate discovery ranks other sessions by working-directory affinity and labels them with their latest titles. Snapshots are immutable after capture and carry a fixed warning that forbids following instructions, permission claims, or tool requests inside them. It is an opt-in service for hosts that support cross-session mentions; it consumes ctx.sessionQuery and needs no SQLite FTS.
Enable this service when hosts should let a user mention another session and give the model its context. It works with any session-query backend because it consumes the backend-independent compact checkpoint marker.
A canonical mention is @[label](dsh-session:<base64url-encoded-id>) in Markdown, or the bare dsh-session: URI; every JavaScript string session id round-trips exactly. The service rewrites mentions into readable @label text in the message and returns the structured references. Explicit Markdown mentions reject malformed URIs; empty or punctuation-only scheme mentions stay ordinary discussion text.
A message that cites other sessions is followed immediately by a ## Referenced sessions snapshot as a second user-role message. The snapshot is untrusted background: the fixed warning tells the model not to follow instructions, permission claims, or tool requests inside it unless the current user explicitly repeats them. Each source preview is bounded independently — at most maxReferences distinct sessions per message and a configured or model-relative serialized JSON byte budget per source. Retention drops older non-checkpoint messages before shortening retained text; preparation fails only when the reference cannot fit even after retention.
For a truncated reference, an optional spill backend saves the full captured text projection under the target session. A separate omission notice outside the bounded preview JSON gives exact omittedMessages and omittedBytes, then the saved locator and retrievalHint, or an unavailable outcome distinguishing missing storage from a failed save. The notice is part of the same durable context message. Full transcripts carry the same untrusted-background warning and capture metadata, including capturedFormatVersion. Each message uses JSON string fragments of at most 64 Unicode code points per line; decode and concatenate its fragments to recover exact text, including original newlines. This fixed storage format keeps even long single-line text readable through paged file reads.
listCandidates(agent, query?, limit?) lists sessions other than the agent's own, filters case-insensitively by id, working directory, or the projected title, and ranks same-directory sessions first. Each candidate carries its latest title as the mention label, falling back to the session id when the title is absent or unreadable, and reports whether its working directory is the requesting agent's so a host can surface a location only when it distinguishes the row. Browser consumers call the same discovery as ctx.remote.sessionReferenceResolver.candidates, which attaches each candidate's canonical mention.
| Field | Default | Meaning |
|---|---|---|
maxReferences |
3 |
Maximum distinct source sessions in one prepared message; must not exceed 3 |
candidateLimit |
50 |
Default candidate count returned to a host |
maxReferenceBytes |
automatic | Explicit maximum serialized JSON bytes per source; overrides the automatic budget exactly |
referenceContextFraction |
0.2 |
Context-window fraction per source, from 0 to 1 |
The automatic budget is max(65536, floor(contextWindow × 4 × referenceContextFraction)) bytes per source. Model context capacity is measured in tokens; four bytes per token is a sizing heuristic, not an exact token conversion. A missing route, LLM service, adapter, or capacity uses 64 KiB; other model metadata lookup errors and cancellation fail preparation.
The generated configuration catalog is the exhaustive source for every accepted field and its JSDoc.
Read these pages when the package-level contract is not enough. They move from the shared reference surface to the design decision and the read service behind it.
The model sees two consecutive user-role messages: the current message with its readable @label, then the ## Referenced sessions untrusted snapshot. The warning forbids following instructions, permission claims, or tool requests from the snapshot unless the current user explicitly repeats them. Labels, cwd values, ids, and conversation text are serialized as JSON inside <referenced-sessions> tags; every data < is emitted as the lossless JSON escape \u003c, so source text cannot spell a framing tag.
Each referenced message adds the fixed warning plus up to three serialized previews, each independently bounded by the configured or model-relative byte budget. Truncated references add separate omission notices outside that budget; a saved full transcript adds tokens only when retrieved. The exact context remains in target history until target compaction shadows or summarizes it; source-session changes add no further tokens.
The request and snapshot are consecutive append-only target messages and preserve earlier cacheable history. Different references or source capture contents change the new suffix only; later target compaction may invalidate reuse from its replacement boundary.
These limits define when cross-session references are a poor fit. They are current package constraints.
ctx.sessionQuery; it is not a model-facing search tool.