dsh-plugin-dev-kb 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (234) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +56 -0
  3. package/cordis.patch.yml +12 -0
  4. package/kb/INDEX.md +210 -0
  5. package/kb/README.md +69 -0
  6. package/kb/extra/AGENTS.md +75 -0
  7. package/kb/extra/api-gateway.md +164 -0
  8. package/kb/extra/api-gateway.zh.md +164 -0
  9. package/kb/extra/cookbook/adding-a-vendored-package.md +59 -0
  10. package/kb/extra/cookbook/adding-a-vendored-package.zh.md +59 -0
  11. package/kb/extra/cookbook/maintaining-dsh-code-review.md +64 -0
  12. package/kb/extra/cookbook/maintaining-dsh-code-review.zh.md +64 -0
  13. package/kb/extra/cookbook/responding-to-pr-review-on-a-stack.md +32 -0
  14. package/kb/extra/cookbook/responding-to-pr-review-on-a-stack.zh.md +32 -0
  15. package/kb/extra/defensive-patterns.md +33 -0
  16. package/kb/extra/defensive-patterns.zh.md +33 -0
  17. package/kb/extra/development.md +171 -0
  18. package/kb/extra/development.zh.md +171 -0
  19. package/kb/extra/event-producer-consumer.md +76 -0
  20. package/kb/extra/event-producer-consumer.zh.md +78 -0
  21. package/kb/extra/glossary.md +45 -0
  22. package/kb/extra/glossary.zh.md +45 -0
  23. package/kb/extra/graph-atlas.md +24 -0
  24. package/kb/extra/graph-atlas.zh.md +26 -0
  25. package/kb/extra/i18n/README.md +60 -0
  26. package/kb/extra/i18n/README.zh.md +60 -0
  27. package/kb/extra/i18n/style-samples.md +87 -0
  28. package/kb/extra/i18n/terminology.md +214 -0
  29. package/kb/extra/i18n/translation-prompt.md +263 -0
  30. package/kb/extra/i18n/translation-rules.md +69 -0
  31. package/kb/extra/i18n/translation-rules.zh.md +69 -0
  32. package/kb/extra/module-graph.md +1641 -0
  33. package/kb/extra/module-graph.zh.md +1643 -0
  34. package/kb/extra/postmortem/0001-acp-default-export-drops-inject.md +113 -0
  35. package/kb/extra/postmortem/0001-acp-default-export-drops-inject.zh.md +113 -0
  36. package/kb/extra/postmortem/0002-js-expression-disabled-filesystem-tools.md +47 -0
  37. package/kb/extra/postmortem/0002-js-expression-disabled-filesystem-tools.zh.md +47 -0
  38. package/kb/extra/postmortem/0003-web-agent-gui-feedback-loop.md +53 -0
  39. package/kb/extra/postmortem/0003-web-agent-gui-feedback-loop.zh.md +53 -0
  40. package/kb/extra/postmortem/0004-landlock-partial-notice-misclassified-child-failures.md +55 -0
  41. package/kb/extra/postmortem/0004-landlock-partial-notice-misclassified-child-failures.zh.md +55 -0
  42. package/kb/extra/postmortem/README.md +18 -0
  43. package/kb/extra/postmortem/README.zh.md +18 -0
  44. package/kb/extra/rescope.md +53 -0
  45. package/kb/extra/rescope.zh.md +53 -0
  46. package/kb/extra/subsystems/attachment.md +125 -0
  47. package/kb/extra/subsystems/attachment.zh.md +125 -0
  48. package/kb/extra/subsystems/extensions.md +364 -0
  49. package/kb/extra/subsystems/extensions.zh.md +364 -0
  50. package/kb/extra/subsystems/feedback.md +266 -0
  51. package/kb/extra/subsystems/feedback.zh.md +266 -0
  52. package/kb/extra/testing.md +49 -0
  53. package/kb/extra/testing.zh.md +49 -0
  54. package/kb/extra/web-styling.md +25 -0
  55. package/kb/extra/web-styling.zh.md +25 -0
  56. package/kb/meta/search-index.json +1328 -0
  57. package/kb/meta/site-pages.txt +168 -0
  58. package/kb/meta/source.json +13 -0
  59. package/kb/meta/topics.md +75 -0
  60. package/kb/site/develop/basic/config.md +108 -0
  61. package/kb/site/develop/basic/index.md +146 -0
  62. package/kb/site/develop/basic/publish.md +185 -0
  63. package/kb/site/develop/basic/tool.md +54 -0
  64. package/kb/site/develop/cordis-tutorial/01-first-plugin.md +95 -0
  65. package/kb/site/develop/cordis-tutorial/02-lifecycle-and-effects.md +98 -0
  66. package/kb/site/develop/cordis-tutorial/03-services.md +98 -0
  67. package/kb/site/develop/cordis-tutorial/04-events.md +144 -0
  68. package/kb/site/develop/cordis-tutorial/05-config.md +84 -0
  69. package/kb/site/develop/cordis-tutorial/06-composition-and-hmr.md +113 -0
  70. package/kb/site/develop/cordis-tutorial/07-into-the-harness.md +107 -0
  71. package/kb/site/develop/cordis-tutorial/index.md +62 -0
  72. package/kb/site/develop/framework/events.md +145 -0
  73. package/kb/site/develop/framework/index.md +139 -0
  74. package/kb/site/develop/framework/service.md +152 -0
  75. package/kb/site/develop/practice/index.md +157 -0
  76. package/kb/site/develop/practice/llm-adapter.md +190 -0
  77. package/kb/site/en/develop/basic/config.md +108 -0
  78. package/kb/site/en/develop/basic/index.md +146 -0
  79. package/kb/site/en/develop/basic/publish.md +185 -0
  80. package/kb/site/en/develop/basic/tool.md +54 -0
  81. package/kb/site/en/develop/cordis-tutorial/01-first-plugin.md +95 -0
  82. package/kb/site/en/develop/cordis-tutorial/02-lifecycle-and-effects.md +98 -0
  83. package/kb/site/en/develop/cordis-tutorial/03-services.md +98 -0
  84. package/kb/site/en/develop/cordis-tutorial/04-events.md +144 -0
  85. package/kb/site/en/develop/cordis-tutorial/05-config.md +84 -0
  86. package/kb/site/en/develop/cordis-tutorial/06-composition-and-hmr.md +113 -0
  87. package/kb/site/en/develop/cordis-tutorial/07-into-the-harness.md +107 -0
  88. package/kb/site/en/develop/cordis-tutorial/index.md +60 -0
  89. package/kb/site/en/develop/framework/events.md +145 -0
  90. package/kb/site/en/develop/framework/index.md +139 -0
  91. package/kb/site/en/develop/framework/service.md +150 -0
  92. package/kb/site/en/develop/practice/index.md +157 -0
  93. package/kb/site/en/develop/practice/llm-adapter.md +190 -0
  94. package/kb/site/en/guide/providers-custom-form.png +0 -0
  95. package/kb/site/en/guide/providers-models-page.png +0 -0
  96. package/kb/site/en/guide/providers.md +100 -0
  97. package/kb/site/en/guide/python-sdk.md +106 -0
  98. package/kb/site/en/guide/quickstart.md +32 -0
  99. package/kb/site/en/index.md +8 -0
  100. package/kb/site/en/reference/agent-lifecycle.md +86 -0
  101. package/kb/site/en/reference/capability-seams.md +475 -0
  102. package/kb/site/en/reference/config-catalog.md +3155 -0
  103. package/kb/site/en/reference/cookbook/adding-a-conversation-node.md +235 -0
  104. package/kb/site/en/reference/cookbook/adding-a-package.md +120 -0
  105. package/kb/site/en/reference/cookbook/adding-a-settings-card.md +102 -0
  106. package/kb/site/en/reference/cookbook/adding-a-tool.md +96 -0
  107. package/kb/site/en/reference/cookbook/adding-an-llm-adapter.md +45 -0
  108. package/kb/site/en/reference/cookbook/extension-cookbook.md +131 -0
  109. package/kb/site/en/reference/cordis-api/context.md +368 -0
  110. package/kb/site/en/reference/cordis-api/events.md +211 -0
  111. package/kb/site/en/reference/cordis-api/fiber.md +379 -0
  112. package/kb/site/en/reference/cordis-api/inherited.md +43 -0
  113. package/kb/site/en/reference/cordis-api/registry.md +156 -0
  114. package/kb/site/en/reference/cordis-api/service.md +106 -0
  115. package/kb/site/en/reference/cordis-primer.md +46 -0
  116. package/kb/site/en/reference/index.md +131 -0
  117. package/kb/site/en/reference/persistence-catalog.md +949 -0
  118. package/kb/site/en/reference/subsystems/approval.md +173 -0
  119. package/kb/site/en/reference/subsystems/client-modules.md +121 -0
  120. package/kb/site/en/reference/subsystems/code-runtime.md +194 -0
  121. package/kb/site/en/reference/subsystems/commands.md +190 -0
  122. package/kb/site/en/reference/subsystems/compaction.md +241 -0
  123. package/kb/site/en/reference/subsystems/core.md +1073 -0
  124. package/kb/site/en/reference/subsystems/credentials.md +136 -0
  125. package/kb/site/en/reference/subsystems/filesystem.md +498 -0
  126. package/kb/site/en/reference/subsystems/goal.md +280 -0
  127. package/kb/site/en/reference/subsystems/index.md +58 -0
  128. package/kb/site/en/reference/subsystems/invariants.md +91 -0
  129. package/kb/site/en/reference/subsystems/jobs.md +293 -0
  130. package/kb/site/en/reference/subsystems/llm-streaming.md +920 -0
  131. package/kb/site/en/reference/subsystems/lsp.md +205 -0
  132. package/kb/site/en/reference/subsystems/permission-presets.md +134 -0
  133. package/kb/site/en/reference/subsystems/persistence.md +388 -0
  134. package/kb/site/en/reference/subsystems/plan.md +90 -0
  135. package/kb/site/en/reference/subsystems/sandbox.md +221 -0
  136. package/kb/site/en/reference/subsystems/schedule.md +189 -0
  137. package/kb/site/en/reference/subsystems/scope.md +62 -0
  138. package/kb/site/en/reference/subsystems/session-projection.md +265 -0
  139. package/kb/site/en/reference/subsystems/session-query.md +498 -0
  140. package/kb/site/en/reference/subsystems/session-reference.md +111 -0
  141. package/kb/site/en/reference/subsystems/session-telemetry.md +197 -0
  142. package/kb/site/en/reference/subsystems/session-title.md +207 -0
  143. package/kb/site/en/reference/subsystems/session.md +852 -0
  144. package/kb/site/en/reference/subsystems/settings.md +313 -0
  145. package/kb/site/en/reference/subsystems/shell.md +306 -0
  146. package/kb/site/en/reference/subsystems/skills.md +334 -0
  147. package/kb/site/en/reference/subsystems/spill.md +120 -0
  148. package/kb/site/en/reference/subsystems/storage.md +232 -0
  149. package/kb/site/en/reference/subsystems/subagent.md +737 -0
  150. package/kb/site/en/reference/subsystems/subprocess.md +327 -0
  151. package/kb/site/en/reference/subsystems/system-prompt.md +210 -0
  152. package/kb/site/en/reference/subsystems/terminal.md +187 -0
  153. package/kb/site/en/reference/subsystems/token-meter.md +93 -0
  154. package/kb/site/en/reference/subsystems/tools.md +723 -0
  155. package/kb/site/en/reference/subsystems/typert.md +339 -0
  156. package/kb/site/en/reference/subsystems/user-questions.md +181 -0
  157. package/kb/site/en/reference/subsystems/web-server.md +111 -0
  158. package/kb/site/en/reference/subsystems/web.md +202 -0
  159. package/kb/site/en/reference/subsystems/workflow.md +281 -0
  160. package/kb/site/en/reference/subsystems/workspace.md +231 -0
  161. package/kb/site/en/reference/tool-catalog.md +1877 -0
  162. package/kb/site/en/reference/tool-execution-pipeline.md +66 -0
  163. package/kb/site/guide/providers-custom-form.zh.png +0 -0
  164. package/kb/site/guide/providers-models-page.zh.png +0 -0
  165. package/kb/site/guide/providers.md +100 -0
  166. package/kb/site/guide/python-sdk.md +106 -0
  167. package/kb/site/guide/quickstart.md +32 -0
  168. package/kb/site/index.md +8 -0
  169. package/kb/site/reference/agent-lifecycle.md +86 -0
  170. package/kb/site/reference/capability-seams.md +475 -0
  171. package/kb/site/reference/config-catalog.md +3154 -0
  172. package/kb/site/reference/cookbook/adding-a-conversation-node.md +235 -0
  173. package/kb/site/reference/cookbook/adding-a-package.md +120 -0
  174. package/kb/site/reference/cookbook/adding-a-settings-card.md +102 -0
  175. package/kb/site/reference/cookbook/adding-a-tool.md +98 -0
  176. package/kb/site/reference/cookbook/adding-an-llm-adapter.md +45 -0
  177. package/kb/site/reference/cookbook/extension-cookbook.md +133 -0
  178. package/kb/site/reference/cordis-api/context.md +368 -0
  179. package/kb/site/reference/cordis-api/events.md +211 -0
  180. package/kb/site/reference/cordis-api/fiber.md +379 -0
  181. package/kb/site/reference/cordis-api/inherited.md +43 -0
  182. package/kb/site/reference/cordis-api/registry.md +156 -0
  183. package/kb/site/reference/cordis-api/service.md +106 -0
  184. package/kb/site/reference/cordis-primer.md +52 -0
  185. package/kb/site/reference/index.md +135 -0
  186. package/kb/site/reference/persistence-catalog.md +949 -0
  187. package/kb/site/reference/subsystems/approval.md +173 -0
  188. package/kb/site/reference/subsystems/client-modules.md +121 -0
  189. package/kb/site/reference/subsystems/code-runtime.md +194 -0
  190. package/kb/site/reference/subsystems/commands.md +190 -0
  191. package/kb/site/reference/subsystems/compaction.md +241 -0
  192. package/kb/site/reference/subsystems/core.md +1081 -0
  193. package/kb/site/reference/subsystems/credentials.md +136 -0
  194. package/kb/site/reference/subsystems/filesystem.md +498 -0
  195. package/kb/site/reference/subsystems/goal.md +280 -0
  196. package/kb/site/reference/subsystems/index.md +58 -0
  197. package/kb/site/reference/subsystems/invariants.md +91 -0
  198. package/kb/site/reference/subsystems/jobs.md +293 -0
  199. package/kb/site/reference/subsystems/llm-streaming.md +926 -0
  200. package/kb/site/reference/subsystems/lsp.md +205 -0
  201. package/kb/site/reference/subsystems/permission-presets.md +134 -0
  202. package/kb/site/reference/subsystems/persistence.md +388 -0
  203. package/kb/site/reference/subsystems/plan.md +90 -0
  204. package/kb/site/reference/subsystems/sandbox.md +221 -0
  205. package/kb/site/reference/subsystems/schedule.md +189 -0
  206. package/kb/site/reference/subsystems/scope.md +62 -0
  207. package/kb/site/reference/subsystems/session-projection.md +265 -0
  208. package/kb/site/reference/subsystems/session-query.md +498 -0
  209. package/kb/site/reference/subsystems/session-reference.md +111 -0
  210. package/kb/site/reference/subsystems/session-telemetry.md +197 -0
  211. package/kb/site/reference/subsystems/session-title.md +207 -0
  212. package/kb/site/reference/subsystems/session.md +854 -0
  213. package/kb/site/reference/subsystems/settings.md +313 -0
  214. package/kb/site/reference/subsystems/shell.md +306 -0
  215. package/kb/site/reference/subsystems/skills.md +334 -0
  216. package/kb/site/reference/subsystems/spill.md +120 -0
  217. package/kb/site/reference/subsystems/storage.md +232 -0
  218. package/kb/site/reference/subsystems/subagent.md +739 -0
  219. package/kb/site/reference/subsystems/subprocess.md +327 -0
  220. package/kb/site/reference/subsystems/system-prompt.md +210 -0
  221. package/kb/site/reference/subsystems/terminal.md +187 -0
  222. package/kb/site/reference/subsystems/token-meter.md +93 -0
  223. package/kb/site/reference/subsystems/tools.md +723 -0
  224. package/kb/site/reference/subsystems/typert.md +339 -0
  225. package/kb/site/reference/subsystems/user-questions.md +181 -0
  226. package/kb/site/reference/subsystems/web-server.md +111 -0
  227. package/kb/site/reference/subsystems/web.md +202 -0
  228. package/kb/site/reference/subsystems/workflow.md +281 -0
  229. package/kb/site/reference/subsystems/workspace.md +231 -0
  230. package/kb/site/reference/tool-catalog.md +1880 -0
  231. package/kb/site/reference/tool-execution-pipeline.md +66 -0
  232. package/package.json +40 -0
  233. package/scripts/rebuild-index.mjs +88 -0
  234. package/skills/dsh-plugin-dev-kb.md +66 -0
@@ -0,0 +1,498 @@
1
+ ---
2
+ editSource: "docs/subsystems/session-query.md"
3
+ outline: [2,3]
4
+ ---
5
+
6
+ # Session Query
7
+
8
+ Query vocabulary over the live-preferred logical session corpus. The [Service Definition package](https://github.com/deepseek-ai/deepseek-harness/tree/master/packages/session-query/session-query) owns exact reads, source precedence, relationship tracing, semantic extraction, and provider-independent filters, while the [SQLite provider](https://github.com/deepseek-ai/deepseek-harness/tree/master/packages/session-query/session-query-sqlite) owns the concrete full-text index lifecycle.
9
+
10
+ Source: [`packages/session-query/session-query/src/types.ts`](https://github.com/deepseek-ai/deepseek-harness/blob/master/packages/session-query/session-query/src/types.ts)
11
+
12
+ ## Logical records
13
+
14
+ `SessionRecord` is returned by the cross-corpus list. It exposes source availability independently from the cloned live-preferred header. `SessionEventRecord` is a lightweight raw-log projection; classification uses the same `foldSurface()` transitions as model-history derivation.
15
+
16
+ ```ts type-equiv
17
+ /** Whether an event is current model context, replaced context, or raw-log-only. */
18
+ type SessionEventSurface = 'current' | 'shadowed' | 'log-only'
19
+ ```
20
+
21
+ ```ts type-equiv
22
+ /** Lightweight identity and source availability for one logical session. */
23
+ interface SessionRecord {
24
+ /** Cloned session header selected from the live-preferred corpus. */
25
+ header: SessionHeader
26
+ /** Whether the id currently exists in `ctx.sessions`. */
27
+ live: boolean
28
+ /** Whether the active persistence backend currently materializes the id. */
29
+ persisted: boolean
30
+ }
31
+ ```
32
+
33
+ `SessionLogSnapshot` is the complete detached, replay-validated raw log used by resume preflight. `SessionSurfaceSnapshot` is one exact-read surface observation rather than a retained subscription.
34
+
35
+ ```ts type-equiv
36
+ /** One validated detached observation of a logical session's complete raw log. */
37
+ interface SessionLogSnapshot {
38
+ /** Cloned session header selected from the same observation as `events`. */
39
+ session: SessionHeader
40
+ /** Cloned contiguous raw events after persistence repair and replay validation. */
41
+ events: SessionEvent[]
42
+ }
43
+ ```
44
+
45
+ ```ts type-equiv
46
+ /** One atomic live-preferred observation of a session's current model surface. */
47
+ interface SessionSurfaceSnapshot {
48
+ /** Cloned session header selected from the same corpus observation as `events`. */
49
+ session: SessionHeader
50
+ /** Highest raw-log seq included in the observation, or `null` for an empty log. */
51
+ capturedThroughSeq: number | null
52
+ /** Cloned current surface events in model-history order. */
53
+ events: SurfaceEvent[]
54
+ }
55
+ ```
56
+
57
+ `SessionTitleObservation` applies the same atomic-observation rule to title folding, so an authorization consumer can validate the source header that supplied the title. Batch reads return one ordered `SessionTitleObservationResult` per unique requested id: operational failures remain local to that id, while cancellation rejects the complete operation.
58
+
59
+ ```ts type-equiv
60
+ /** Latest folded title bound to the same session-header observation. */
61
+ interface SessionTitleObservation {
62
+ /** Cloned header selected with the event log used for the title fold. */
63
+ session: SessionHeader
64
+ /** Latest title snapshot, absent when the observed log has no title. */
65
+ title?: SessionTitleSnapshot
66
+ }
67
+ ```
68
+
69
+ ```ts type-equiv
70
+ /** One ordered result from a batch title observation. */
71
+ type SessionTitleObservationResult =
72
+ | {
73
+ /** Requested session id. */
74
+ sessionId: SessionId
75
+ /** Successful atomic header/title observation. */
76
+ status: 'fulfilled'
77
+ /** Header and optional latest title from one logical source. */
78
+ value: SessionTitleObservation
79
+ }
80
+ | {
81
+ /** Requested session id. */
82
+ sessionId: SessionId
83
+ /** Operational failure isolated to this session. */
84
+ status: 'rejected'
85
+ /** Original failure from logical-source resolution or title folding. */
86
+ reason: unknown
87
+ }
88
+ ```
89
+
90
+ ```ts type-equiv
91
+ /** Lightweight metadata for one event within a logical session. */
92
+ interface SessionEventRecord {
93
+ /** Session that owns the event. */
94
+ sessionId: SessionId
95
+ /** Monotonic event seq within the session. */
96
+ seq: number
97
+ /** Discriminant of the session event. */
98
+ type: SessionEventType
99
+ /** Event timestamp in Unix epoch milliseconds. */
100
+ time: number
101
+ /** Event placement in the folded session surface. */
102
+ surface: SessionEventSurface
103
+ }
104
+ ```
105
+
106
+ ## Provider-independent filters and documents
107
+
108
+ Session and event filter arrays are ANDed; values inside one list clause are ORed. Ranges are inclusive. The event `text` clause is a literal Unicode case-insensitive, whitespace-flexible regular-expression scan over extracted semantic text, independent of full-text providers.
109
+
110
+ ```ts type-equiv
111
+ /**
112
+ * One logical-session predicate. A filter array is ANDed; `values` within a
113
+ * clause are ORed.
114
+ */
115
+ type SessionResultFilter =
116
+ | { kind: 'id'; values: readonly SessionId[] }
117
+ | { kind: 'cwd'; values: readonly (string | null)[] }
118
+ | ({ kind: 'created-at' } & SessionResultRange)
119
+ | { kind: 'parent'; values: readonly (SessionId | null)[] }
120
+ | { kind: 'availability'; values: readonly SessionAvailability[] }
121
+ ```
122
+
123
+ ```ts type-equiv
124
+ /**
125
+ * One event predicate. A filter array is ANDed; list-valued clauses are ORed.
126
+ * Text is a literal, case-insensitive, whitespace-flexible semantic-text scan.
127
+ */
128
+ type SessionEventResultFilter =
129
+ | ({ kind: 'seq' } & SessionResultRange)
130
+ | ({ kind: 'time' } & SessionResultRange)
131
+ | { kind: 'type'; values: readonly SessionEventType[] }
132
+ | { kind: 'surface'; values: readonly SessionEventSurface[] }
133
+ | { kind: 'text'; text: string }
134
+ ```
135
+
136
+ ```ts type-equiv
137
+ /** Searchable semantic document derived from one session event. */
138
+ interface SessionEventSearchDocument extends SessionEventRecord {
139
+ /** First-party semantic text used by scan filters and full-text indexes. */
140
+ text: string
141
+ }
142
+ ```
143
+
144
+ `ctx.sessionQuery.filterSessions(filters)` applies `SessionResultFilter` to the complete logical corpus; `ctx.sessionQuery.filterEvents(sessionId, filters)` returns matching documents in ascending seq order. Messages, reasoning, tool calls/results, blocked prompts, todos, and failure/status detail contribute semantic text; structural events and stream chunks do not.
145
+
146
+ ## Full-text search pages
147
+
148
+ The combined `ctx.sessionQuery` seam has two full-text scopes. `searchSessions()` groups the corpus by strongest matching event; `searchEvents()` searches one session. Requests bind an opaque cursor to the normalized query, metadata filters, and limit. The event text scan is intentionally absent from provider metadata filters.
149
+
150
+ ```ts type-equiv
151
+ /** Provider-owned opaque continuation token returned by session search. */
152
+ type SessionSearchCursor = Branded<'SessionSearchCursor'>
153
+ ```
154
+
155
+ ```ts type-equiv
156
+ /** Cross-session full-text search request. */
157
+ interface SessionSearchRequest {
158
+ /** Full-text query interpreted as data, never executable FTS syntax. */
159
+ query: string
160
+ /** Logical-session predicates applied before event ranking. */
161
+ sessionFilters?: readonly SessionResultFilter[]
162
+ /** Event predicates applied before event ranking. */
163
+ eventFilters?: readonly SessionEventMetadataFilter[]
164
+ /** Maximum sessions in this page. */
165
+ limit?: number
166
+ /** Opaque cursor returned for the identical normalized request. */
167
+ cursor?: SessionSearchCursor
168
+ }
169
+ ```
170
+
171
+ ```ts type-equiv
172
+ /** Within-session full-text search request. */
173
+ interface SessionEventSearchRequest {
174
+ /** Session whose live-preferred logical log is searched. */
175
+ sessionId: SessionId
176
+ /** Full-text query interpreted as data, never executable FTS syntax. */
177
+ query: string
178
+ /** Event predicates applied before ranking. */
179
+ filters?: readonly SessionEventMetadataFilter[]
180
+ /** Maximum events in this page. */
181
+ limit?: number
182
+ /** Opaque cursor returned for the identical normalized request. */
183
+ cursor?: SessionSearchCursor
184
+ }
185
+ ```
186
+
187
+ ```ts type-equiv
188
+ /** One cursor-paginated result page. */
189
+ interface SessionSearchPage<T> {
190
+ /** Results for this page in contract-defined order. */
191
+ items: readonly T[]
192
+ /** Opaque continuation cursor, absent on the final page. */
193
+ nextCursor?: SessionSearchCursor
194
+ }
195
+ ```
196
+
197
+ Unlike grouped cross-session hits, a within-session search must also expose its observed target header even when the page contains no hits.
198
+
199
+ ```ts type-equiv
200
+ /** Event-search results bound to the indexed target-session observation. */
201
+ interface SessionEventSearchPage extends SessionSearchPage<SessionEventSearchHit> {
202
+ /** Cloned target header from the same indexed generation as `items`. */
203
+ session: SessionHeader
204
+ }
205
+ ```
206
+
207
+ ```ts type-equiv
208
+ /** One event full-text search hit with a bounded plain-text excerpt. */
209
+ interface SessionEventSearchHit extends SessionEventRecord {
210
+ /** Plain text excerpt selected around the match. */
211
+ snippet: string
212
+ }
213
+ ```
214
+
215
+ ```ts type-equiv
216
+ /** One grouped cross-session hit, ranked by its strongest matching event. */
217
+ interface SessionSearchHit extends SessionRecord {
218
+ /** Strongest matching event for this session. */
219
+ bestMatch: SessionEventSearchHit
220
+ }
221
+ ```
222
+
223
+ ## Session lineage
224
+
225
+ `SessionLineageTrace` carries known parents in immediate-to-outward order and a forest of recursively nested direct descendants. The completeness discriminant makes a known root and a missing parent mutually exclusive.
226
+
227
+ ```ts type-equiv
228
+ /** Recursive descendant node in a session-lineage trace. */
229
+ interface SessionLineageNode {
230
+ /** Detached logical-corpus record for this descendant. */
231
+ session: SessionRecord
232
+ /** Direct children, each carrying its own recursive descendants. */
233
+ descendants: SessionLineageNode[]
234
+ }
235
+ ```
236
+
237
+ ```ts type-equiv
238
+ /** Known ancestry and descendants for one logical session. */
239
+ type SessionLineageTrace = {
240
+ /** Detached record for the session that was traced. */
241
+ target: SessionRecord
242
+ /** Known parents from the immediate parent outward. */
243
+ ancestors: SessionRecord[]
244
+ /** Complete known descendant trees rooted at the target's direct children. */
245
+ descendants: SessionLineageNode[]
246
+ } & (
247
+ | {
248
+ /** The complete parent chain is present in the logical corpus. */
249
+ complete: true
250
+ /** Detached record at the top of the complete lineage. */
251
+ root: SessionRecord
252
+ }
253
+ | {
254
+ /** The parent chain leaves the visible logical corpus. */
255
+ complete: false
256
+ /** First parent id that is not present in the logical corpus. */
257
+ unresolvedParentId: SessionId
258
+ }
259
+ )
260
+ ```
261
+
262
+ ## Bounded event reads
263
+
264
+ The request addresses one raw seq and optional neighboring counts. The result carries a `SessionHeader` rather than availability flags so a known live target can remain independent of persistence health.
265
+
266
+ ```ts type-equiv
267
+ /** Request for one event plus raw neighboring log context. */
268
+ interface SessionEventReadRequest {
269
+ /** Session that owns the target event. */
270
+ sessionId: SessionId
271
+ /** Target event seq. */
272
+ seq: number
273
+ /** Number of preceding raw events to include. */
274
+ before?: number
275
+ /** Number of following raw events to include. */
276
+ after?: number
277
+ }
278
+ ```
279
+
280
+ ```ts type-equiv
281
+ /** Full target event and a bounded raw-log window. */
282
+ interface SessionEventWindow {
283
+ /** Cloned header for the live-preferred source read. */
284
+ session: SessionHeader
285
+ /** Full cloned target event. */
286
+ target: SessionEvent
287
+ /** Full cloned events from `startSeq` through `endSeq`. */
288
+ events: SessionEvent[]
289
+ /** First seq included in `events`. */
290
+ startSeq: number
291
+ /** Last seq included in `events`. */
292
+ endSeq: number
293
+ }
294
+ ```
295
+
296
+ ## Event relationships
297
+
298
+ Event traces distinguish positional surface replacement from events cited as sources. Every seq list contains direct links except `replacementChain`, which follows immediate replacers from the target to the final positional replacement.
299
+
300
+ ```ts type-equiv
301
+ /** Request for direct surface replacements and relationships to cited source events around one event. */
302
+ interface SessionEventTraceRequest {
303
+ /** Session that owns the target event. */
304
+ sessionId: SessionId
305
+ /** Target event seq. */
306
+ seq: number
307
+ }
308
+ ```
309
+
310
+ ```ts type-equiv
311
+ /** Direct surface replacements and relationships to cited source events for one event. */
312
+ interface SessionEventTrace {
313
+ /** Lightweight target record. */
314
+ target: SessionEventRecord
315
+ /** Immediate positional replacement event, when the target was shadowed. */
316
+ replacedBy?: number
317
+ /** Positional replacers from the immediate replacement to the final replacement. */
318
+ replacementChain: number[]
319
+ /** Surface nodes directly removed when the target itself performed a replacement. */
320
+ replacedEventSeqs: number[]
321
+ /** Earlier events cited directly as sources, in their recorded order. */
322
+ sourceEventSeqs: number[]
323
+ /** Later events that directly cite the target as a source, in log order. */
324
+ derivedEventSeqs: number[]
325
+ }
326
+ ```
327
+
328
+ ```ts type-equiv
329
+ /** Event relationships bound to the same session-header observation. */
330
+ interface SessionEventTraceObservation extends SessionEventTrace {
331
+ /** Cloned header selected with the event log used for the trace. */
332
+ session: SessionHeader
333
+ }
334
+ ```
335
+
336
+ ## Errors
337
+
338
+ The closed code union distinguishes request validation, missing targets, malformed surface logs, optional-backend failure, deployment-disabled search, and contradictory source metadata.
339
+
340
+ ```ts type-equiv
341
+ /** Stable machine-routable failure taxonomy for session reads, traces, and search. */
342
+ type SessionQueryErrorCode =
343
+ | 'SESSION_QUERY_ABORTED'
344
+ | 'SESSION_QUERY_CORRUPT_SESSION'
345
+ | 'SESSION_QUERY_EVENT_NOT_FOUND'
346
+ | 'SESSION_QUERY_INDEX_FAILED'
347
+ | 'SESSION_QUERY_INVALID_CONFIG'
348
+ | 'SESSION_QUERY_INVALID_CURSOR'
349
+ | 'SESSION_QUERY_INVALID_FILTER'
350
+ | 'SESSION_QUERY_INVALID_LIMIT'
351
+ | 'SESSION_QUERY_INVALID_QUERY'
352
+ | 'SESSION_QUERY_INVALID_LINEAGE'
353
+ | 'SESSION_QUERY_INVALID_SURFACE'
354
+ | 'SESSION_QUERY_INVALID_WINDOW'
355
+ | 'SESSION_QUERY_PERSISTENCE_FAILED'
356
+ | 'SESSION_QUERY_SEARCH_DISABLED'
357
+ | 'SESSION_QUERY_SESSION_NOT_FOUND'
358
+ | 'SESSION_QUERY_STALE_CURSOR'
359
+ | 'SESSION_QUERY_SOURCE_CONFLICT'
360
+ ```
361
+
362
+ <!-- BEGIN GENERATED cordis-surface (gen-cordis-catalog.ts) — do not edit between markers -->
363
+
364
+ <a id="cordis-surface"></a>
365
+
366
+ ## Cordis API
367
+
368
+ Generated from source by `scripts/gen-cordis-catalog.ts` (verified fresh by `pnpm run verify-cordis-catalog` in doc-sync; regenerate with `pnpm run gen-cordis-catalog`) — this section is byte-identical in both language sides of the page. Signature blocks use a `ts cordis-catalog` fence and keep the original source JSDoc; dispatch modes are defined in the [primer](../cordis-primer.md#dispatch-modes), and the framework-inherited `ctx` API lives in [cordis-api/inherited.md](../cordis-api/inherited.md).
369
+
370
+ <a id="ctxsessionquery--sessionqueryengine-abstract-seam"></a>
371
+
372
+ ### `ctx.sessionQuery` — `SessionQueryEngine` (abstract seam)
373
+
374
+ Unified live-preferred session query service.
375
+
376
+ Exact reads, filters, and traces are backend-independent concrete behavior. A backend implements full-text observation, reconciliation, ranking, cursor generations, and query execution on the same `ctx.sessionQuery` service.
377
+
378
+ ```ts cordis-catalog
379
+ /**
380
+ * Search the live-preferred logical corpus and group by session.
381
+ * @param request - query text, metadata filters, page size, and cursor.
382
+ * @param exec - optional cancellation control.
383
+ * @returns session hits ranked by their strongest matching event.
384
+ */
385
+ abstract searchSessions( request: SessionSearchRequest, exec?: SessionSearchExecContext, ): Promise<SessionSearchPage<SessionSearchHit>>
386
+
387
+ /**
388
+ * Search events within one live-preferred logical session.
389
+ * @param request - target session, query text, filters, page size, and cursor.
390
+ * @param exec - optional cancellation control.
391
+ * @returns matching event hits and their target header from one indexed generation.
392
+ */
393
+ abstract searchEvents( request: SessionEventSearchRequest, exec?: SessionSearchExecContext, ): Promise<SessionEventSearchPage>
394
+
395
+ /**
396
+ * List the complete logical corpus using live-preferred records.
397
+ * @param signal - optional cancellation for persistence listing.
398
+ * @returns deterministic newest-first cloned session records.
399
+ */
400
+ listSessions(signal?: AbortSignal): Promise<SessionRecord[]>
401
+
402
+ /**
403
+ * Read and replay-validate one complete logical session log without making it live.
404
+ * @param sessionId - live or persisted session id to read.
405
+ * @returns cloned header and complete raw event log from one observation.
406
+ * @throws when persistence, header compatibility, or replay validation fails.
407
+ */
408
+ async readSession(sessionId: SessionId): Promise<SessionLogSnapshot>
409
+
410
+ /**
411
+ * Filter the complete logical corpus with provider-independent predicates.
412
+ * @param filters - ANDed session metadata and availability clauses.
413
+ * @param signal - optional cancellation for persistence listing.
414
+ * @returns matching cloned records in deterministic newest-first order.
415
+ */
416
+ async filterSessions( filters: readonly SessionResultFilter[], signal?: AbortSignal, ): Promise<SessionRecord[]>
417
+
418
+ /**
419
+ * Fold the latest log-backed title from one live-preferred logical session.
420
+ * @param sessionId - live or persisted session id to read.
421
+ * @param signal - optional cancellation for source resolution and title folding.
422
+ * @returns latest title snapshot, or `undefined` when the log has no title event.
423
+ */
424
+ async readTitle( sessionId: SessionId, signal?: AbortSignal, ): Promise<SessionTitleSnapshot | undefined>
425
+
426
+ /**
427
+ * Fold the latest title and return its source header from one corpus observation.
428
+ * @param sessionId - live or persisted session id to read.
429
+ * @param signal - optional cancellation for source resolution and title folding.
430
+ * @returns cloned source header and optional latest title snapshot.
431
+ */
432
+ async readTitleSnapshot( sessionId: SessionId, signal?: AbortSignal, ): Promise<SessionTitleObservation>
433
+
434
+ /**
435
+ * Fold titles for unique sessions from one cancellable corpus observation.
436
+ *
437
+ * Results preserve first-occurrence input order. Operational failures stay
438
+ * isolated per session, while cancellation rejects the complete operation.
439
+ * @param sessionIds - live or persisted session ids to observe.
440
+ * @param signal - optional cancellation shared by all source reads.
441
+ * @returns one fulfilled or rejected result per unique requested id.
442
+ */
443
+ async readTitleSnapshots( sessionIds: readonly SessionId[], signal?: AbortSignal, ): Promise<SessionTitleObservationResult[]>
444
+
445
+ /**
446
+ * List lightweight raw-log event records for one logical session.
447
+ * @param sessionId - live-preferred session id to read.
448
+ * @returns event records in ascending seq order.
449
+ */
450
+ async listEvents(sessionId: SessionId): Promise<SessionEventRecord[]>
451
+
452
+ /**
453
+ * Scan first-party semantic event documents with provider-independent filters.
454
+ * @param sessionId - live-preferred session id to scan.
455
+ * @param filters - ANDed metadata and literal-text predicates.
456
+ * @returns matching semantic documents in ascending seq order.
457
+ */
458
+ async filterEvents( sessionId: SessionId, filters: readonly SessionEventResultFilter[], ): Promise<SessionEventSearchDocument[]>
459
+
460
+ /**
461
+ * Read one session's complete current model surface from one corpus observation.
462
+ * @param sessionId - live-preferred session id to read.
463
+ * @returns cloned header, current surface, and the last sequence number included in the raw-log capture.
464
+ * @throws when source resolution fails or the session surface is invalid.
465
+ */
466
+ async readSurface(sessionId: SessionId): Promise<SessionSurfaceSnapshot>
467
+
468
+ /**
469
+ * Trace known ancestry and descendants from one corpus observation.
470
+ * @param sessionId - logical session id to trace.
471
+ * @param signal - optional cancellation for persistence listing.
472
+ * @returns a complete lineage or the first parent that could not be resolved.
473
+ * @throws when corpus resolution fails, the target is absent, or its known ancestry cycles.
474
+ */
475
+ async traceSession(sessionId: SessionId, signal?: AbortSignal): Promise<SessionLineageTrace>
476
+
477
+ /**
478
+ * Trace one event's direct positional replacements and cited source events.
479
+ * @param request - target session id and event seq.
480
+ * @param signal - optional cancellation for persisted source resolution.
481
+ * @returns source header, direct links, and the target's positional replacement chain.
482
+ * @throws when source resolution fails, the target is absent, or surface/source-event validation fails.
483
+ */
484
+ async traceEvent(request: SessionEventTraceRequest, signal?: AbortSignal): Promise<SessionEventTraceObservation>
485
+
486
+ /**
487
+ * Read one full event plus a bounded raw-log context window.
488
+ * @param request - target session/seq and context sizes.
489
+ * @param signal - optional cancellation for persisted source resolution.
490
+ * @returns cloned target and neighboring events.
491
+ */
492
+ async readEvent(request: SessionEventReadRequest, signal?: AbortSignal): Promise<SessionEventWindow>
493
+ ```
494
+
495
+ Types: [SessionId](./core.md) · [SessionTitleSnapshot](./session-title.md)
496
+
497
+ Source: [`packages/session-query/session-query/src/index.ts:81`](https://github.com/deepseek-ai/deepseek-harness/blob/master/packages/session-query/session-query/src/index.ts)
498
+ <!-- END GENERATED cordis-surface -->
@@ -0,0 +1,111 @@
1
+ ---
2
+ editSource: "docs/subsystems/session-reference.md"
3
+ outline: [2,3]
4
+ ---
5
+
6
+ # Session References
7
+
8
+ Structured cross-session reference requests and prepared message contexts. The [package contract](https://github.com/deepseek-ai/deepseek-harness/tree/master/packages/context/session-reference) defines canonical URIs, current-surface projection, tag-safe JSON and byte retention, stable errors, and the untrusted model prompt. Host adapters use these types instead of passing their UI mention syntax into the agent core.
9
+
10
+ Source: [`packages/context/session-reference/src/types.ts`](https://github.com/deepseek-ai/deepseek-harness/blob/master/packages/context/session-reference/src/types.ts)
11
+
12
+ ## Inputs and candidates
13
+
14
+ `SessionReferenceInput` is the host-independent selection. The id is authoritative; the label is display metadata carried into the snapshot.
15
+
16
+ ```ts type-equiv
17
+ /** One source session selected by a host. */
18
+ interface SessionReferenceInput {
19
+ /** Opaque source session identity. */
20
+ sessionId: SessionId
21
+ /** Optional user-facing mention label. */
22
+ label?: string
23
+ }
24
+ ```
25
+
26
+ `SessionReferenceCandidate` is host-facing discovery output. Its label uses the latest session title when present, while filtering still searches only session id and cwd and never transcript text.
27
+
28
+ ```ts type-equiv
29
+ /** One host-facing candidate from exact session metadata. */
30
+ interface SessionReferenceCandidate {
31
+ /** Opaque source session identity. */
32
+ sessionId: SessionId
33
+ /** Latest log-backed title, falling back to the opaque session id. */
34
+ label: string
35
+ /** Source session working directory, when recorded. */
36
+ cwd?: string
37
+ /** Source session creation time in Unix epoch milliseconds. */
38
+ createdAt: number
39
+ }
40
+ ```
41
+
42
+ ## Prepared messages
43
+
44
+ Preparation preserves readable current-message content and returns at most one aggregated context.
45
+
46
+ ```ts type-equiv
47
+ /** Direct message content and optional referenced-session context. */
48
+ interface PreparedReferencedMessage {
49
+ /** Readable message content after host mention tokens are removed. */
50
+ content: ContentBlock[]
51
+ /** Aggregated untrusted snapshot, absent when the message has no references. */
52
+ additionalContext?: UserMessage
53
+ }
54
+ ```
55
+
56
+ ## Errors
57
+
58
+ `SessionReferenceError.code` separates invalid configuration or input, self-reference, count limits, source-read failure, budget failure, and cancellation. Host protocols map these codes to their own error envelopes without inspecting prompt bytes.
59
+
60
+ ```ts type-equiv
61
+ /** Stable failure codes exposed to host adapters. */
62
+ type SessionReferenceErrorCode =
63
+ | 'SESSION_REFERENCE_INVALID_CONFIG'
64
+ | 'SESSION_REFERENCE_INVALID_REFERENCE'
65
+ | 'SESSION_REFERENCE_SELF_REFERENCE'
66
+ | 'SESSION_REFERENCE_TOO_MANY'
67
+ | 'SESSION_REFERENCE_READ_FAILED'
68
+ | 'SESSION_REFERENCE_BUDGET_EXCEEDED'
69
+ | 'SESSION_REFERENCE_CANCELLED'
70
+ ```
71
+
72
+ <!-- BEGIN GENERATED cordis-surface (gen-cordis-catalog.ts) — do not edit between markers -->
73
+
74
+ <a id="cordis-surface"></a>
75
+
76
+ ## Cordis API
77
+
78
+ Generated from source by `scripts/gen-cordis-catalog.ts` (verified fresh by `pnpm run verify-cordis-catalog` in doc-sync; regenerate with `pnpm run gen-cordis-catalog`) — this section is byte-identical in both language sides of the page. Signature blocks use a `ts cordis-catalog` fence and keep the original source JSDoc; dispatch modes are defined in the [primer](../cordis-primer.md#dispatch-modes), and the framework-inherited `ctx` API lives in [cordis-api/inherited.md](../cordis-api/inherited.md).
79
+
80
+ <a id="ctxsessionreferenceresolver--sessionreferenceresolver"></a>
81
+
82
+ ### `ctx.sessionReferenceResolver` — `SessionReferenceResolver`
83
+
84
+ Exact-read consumer that prepares immutable cross-session message context.
85
+
86
+ ```ts cordis-catalog
87
+ /**
88
+ * List reference candidates, ranked by working-directory affinity.
89
+ * @param agent - target agent; self is excluded and its cwd drives ranking.
90
+ * @param query - optional case-insensitive session-id/cwd/title substring.
91
+ * @param limit - optional positive result cap.
92
+ * @param signal - optional cancellation boundary for host autocomplete teardown.
93
+ * @returns candidates labeled by latest title or, when absent, session id.
94
+ */
95
+ async listCandidates( agent: Agent, query: string = '', limit: number = this.config.candidateLimit, signal?: AbortSignal, ): Promise<SessionReferenceCandidate[]>
96
+
97
+ /**
98
+ * Snapshot all references before enqueue and return one aggregated durable context.
99
+ * @param agent - target agent; references to it are rejected.
100
+ * @param content - already host-normalized readable message content.
101
+ * @param references - structured source sessions in mention order.
102
+ * @param signal - optional cancellation boundary for host request teardown.
103
+ * @returns detached content and optional referenced-session context.
104
+ */
105
+ async prepare( agent: Agent, content: ContentBlock[], references: SessionReferenceInput[], signal?: AbortSignal, ): Promise<PreparedReferencedMessage>
106
+ ```
107
+
108
+ Types: [Agent](./core.md) · [ContentBlock](./llm-streaming.md)
109
+
110
+ Source: [`packages/context/session-reference/src/index.ts:70`](https://github.com/deepseek-ai/deepseek-harness/blob/master/packages/context/session-reference/src/index.ts)
111
+ <!-- END GENERATED cordis-surface -->