dsh-zen-remote 1.1.16 → 2.0.1

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 (261) hide show
  1. package/AGENTS.md +54 -9
  2. package/README.md +249 -190
  3. package/README.zh-CN.md +247 -201
  4. package/assets/home.png +0 -0
  5. package/assets/info.png +0 -0
  6. package/assets/pairing.png +0 -0
  7. package/assets/session.png +0 -0
  8. package/assets/sheet.png +0 -0
  9. package/cordis.patch.yml +12 -11
  10. package/cordis.patch.yml.example +24 -9
  11. package/docs/interface.md +57 -2
  12. package/docs/remote-access.en.md +99 -58
  13. package/docs/remote-access.md +99 -42
  14. package/dsh-push.mjs +67 -54
  15. package/lan-gate.mjs +88 -20
  16. package/lib/activity.js +168 -0
  17. package/lib/activity.js.map +1 -0
  18. package/lib/admin-routes.js +526 -0
  19. package/lib/admin-routes.js.map +1 -0
  20. package/lib/client-pairing.js +224 -0
  21. package/lib/client-pairing.js.map +1 -0
  22. package/lib/client-routes.js +674 -0
  23. package/lib/client-routes.js.map +1 -0
  24. package/lib/client.js +11498 -5990
  25. package/lib/config.js +346 -0
  26. package/lib/config.js.map +1 -0
  27. package/lib/fetch-route-intercept.js +418 -0
  28. package/lib/fetch-route-intercept.js.map +1 -0
  29. package/lib/fingerprint.js +365 -0
  30. package/lib/fingerprint.js.map +1 -0
  31. package/lib/http.js +69 -0
  32. package/lib/http.js.map +1 -0
  33. package/lib/index.js +675 -54
  34. package/lib/index.js.map +1 -1
  35. package/lib/intercept-shape.js +81 -0
  36. package/lib/intercept-shape.js.map +1 -0
  37. package/lib/intercept.js +3181 -0
  38. package/lib/intercept.js.map +1 -0
  39. package/lib/lan-gate-server.cjs +532 -121
  40. package/lib/merge-streams.js +1172 -0
  41. package/lib/merge-streams.js.map +1 -0
  42. package/lib/relay-access.js +496 -0
  43. package/lib/relay-access.js.map +1 -0
  44. package/lib/relay-client.js +1303 -0
  45. package/lib/relay-client.js.map +1 -0
  46. package/lib/relay-filter.js +282 -0
  47. package/lib/relay-filter.js.map +1 -0
  48. package/lib/relay-server.js +1813 -0
  49. package/lib/relay-server.js.map +1 -0
  50. package/lib/restart-fields.js +34 -0
  51. package/lib/restart-fields.js.map +1 -0
  52. package/lib/restart-watcher.js +106 -0
  53. package/lib/restart-watcher.js.map +1 -0
  54. package/lib/session-reference.js +157 -0
  55. package/lib/session-reference.js.map +1 -0
  56. package/lib/share-export.js +16 -1
  57. package/lib/share-export.js.map +1 -1
  58. package/lib/share-ops.js +86 -0
  59. package/lib/share-ops.js.map +1 -0
  60. package/lib/share-store.js +294 -0
  61. package/lib/share-store.js.map +1 -0
  62. package/lib/types/activity.d.ts +99 -0
  63. package/lib/types/activity.d.ts.map +1 -0
  64. package/lib/types/admin-routes.d.ts +129 -0
  65. package/lib/types/admin-routes.d.ts.map +1 -0
  66. package/lib/types/client/MobileDrawerFooter.d.ts.map +1 -1
  67. package/lib/types/client/MobileHome.d.ts +1 -1
  68. package/lib/types/client/MobileHome.d.ts.map +1 -1
  69. package/lib/types/client/MobileHomeChips.d.ts +1 -1
  70. package/lib/types/client/MobileHomeChips.d.ts.map +1 -1
  71. package/lib/types/client/MobileSessionHeader.d.ts +13 -2
  72. package/lib/types/client/MobileSessionHeader.d.ts.map +1 -1
  73. package/lib/types/client/MobileSessionInfo.d.ts +20 -3
  74. package/lib/types/client/MobileSessionInfo.d.ts.map +1 -1
  75. package/lib/types/client/RemoteComposerBanner.d.ts +42 -0
  76. package/lib/types/client/RemoteComposerBanner.d.ts.map +1 -0
  77. package/lib/types/client/RemoteHeaderIcon.d.ts +37 -0
  78. package/lib/types/client/RemoteHeaderIcon.d.ts.map +1 -0
  79. package/lib/types/client/RemoteShareMenu.d.ts +28 -0
  80. package/lib/types/client/RemoteShareMenu.d.ts.map +1 -0
  81. package/lib/types/client/RemoteStatusIcon.d.ts +36 -0
  82. package/lib/types/client/RemoteStatusIcon.d.ts.map +1 -0
  83. package/lib/types/client/compat/desktop.d.ts +21 -0
  84. package/lib/types/client/compat/desktop.d.ts.map +1 -0
  85. package/lib/types/client/compat/types.d.ts +57 -0
  86. package/lib/types/client/compat/types.d.ts.map +1 -1
  87. package/lib/types/client/current-session-report.d.ts +37 -0
  88. package/lib/types/client/current-session-report.d.ts.map +1 -0
  89. package/lib/types/client/effects/header-status.d.ts.map +1 -1
  90. package/lib/types/client/effects/keyboard-guard.d.ts.map +1 -1
  91. package/lib/types/client/effects/model-group-side.d.ts +13 -0
  92. package/lib/types/client/effects/model-group-side.d.ts.map +1 -0
  93. package/lib/types/client/effects/permission-sheet.d.ts +39 -0
  94. package/lib/types/client/effects/permission-sheet.d.ts.map +1 -0
  95. package/lib/types/client/effects/remote-session.d.ts +25 -0
  96. package/lib/types/client/effects/remote-session.d.ts.map +1 -0
  97. package/lib/types/client/effects/turn-fold.d.ts +9 -0
  98. package/lib/types/client/effects/turn-fold.d.ts.map +1 -1
  99. package/lib/types/client/index.d.ts.map +1 -1
  100. package/lib/types/client/locales.d.ts +187 -2
  101. package/lib/types/client/locales.d.ts.map +1 -1
  102. package/lib/types/client/remote-fetch.d.ts +51 -0
  103. package/lib/types/client/remote-fetch.d.ts.map +1 -0
  104. package/lib/types/client/remote-group-expansion.d.ts +41 -0
  105. package/lib/types/client/remote-group-expansion.d.ts.map +1 -0
  106. package/lib/types/client/remote-share-css.d.ts +19 -0
  107. package/lib/types/client/remote-share-css.d.ts.map +1 -0
  108. package/lib/types/client/remote-share-register.d.ts +113 -0
  109. package/lib/types/client/remote-share-register.d.ts.map +1 -0
  110. package/lib/types/client/remote-status-css.d.ts +15 -0
  111. package/lib/types/client/remote-status-css.d.ts.map +1 -0
  112. package/lib/types/client/remote-status-register.d.ts +46 -0
  113. package/lib/types/client/remote-status-register.d.ts.map +1 -0
  114. package/lib/types/client/settings/SettingsSection.d.ts +46 -0
  115. package/lib/types/client/settings/SettingsSection.d.ts.map +1 -0
  116. package/lib/types/client/settings/register-settings.d.ts +58 -0
  117. package/lib/types/client/settings/register-settings.d.ts.map +1 -0
  118. package/lib/types/client/settings/settings-css.d.ts +10 -0
  119. package/lib/types/client/settings/settings-css.d.ts.map +1 -0
  120. package/lib/types/client/share/share-preview.d.ts.map +1 -1
  121. package/lib/types/client/styles/composer.css.d.ts +1 -1
  122. package/lib/types/client/styles/composer.css.d.ts.map +1 -1
  123. package/lib/types/client/styles/header.css.d.ts +1 -1
  124. package/lib/types/client/styles/header.css.d.ts.map +1 -1
  125. package/lib/types/client/styles/info.css.d.ts +1 -1
  126. package/lib/types/client/styles/info.css.d.ts.map +1 -1
  127. package/lib/types/client/styles/remote-session.css.d.ts +2 -0
  128. package/lib/types/client/styles/remote-session.css.d.ts.map +1 -0
  129. package/lib/types/client-data/current-session.d.ts +41 -0
  130. package/lib/types/client-data/current-session.d.ts.map +1 -0
  131. package/lib/types/client-data/model-group-side.d.ts +44 -0
  132. package/lib/types/client-data/model-group-side.d.ts.map +1 -0
  133. package/lib/types/client-data/remote-group-expansion.d.ts +76 -0
  134. package/lib/types/client-data/remote-group-expansion.d.ts.map +1 -0
  135. package/lib/types/client-data/remote-status.d.ts +148 -0
  136. package/lib/types/client-data/remote-status.d.ts.map +1 -0
  137. package/lib/types/client-data/settings-form.d.ts +774 -0
  138. package/lib/types/client-data/settings-form.d.ts.map +1 -0
  139. package/lib/types/client-data/shares.d.ts +211 -0
  140. package/lib/types/client-data/shares.d.ts.map +1 -0
  141. package/lib/types/client-pairing.d.ts +114 -0
  142. package/lib/types/client-pairing.d.ts.map +1 -0
  143. package/lib/types/client-routes.d.ts +112 -0
  144. package/lib/types/client-routes.d.ts.map +1 -0
  145. package/lib/types/config.d.ts +200 -0
  146. package/lib/types/config.d.ts.map +1 -0
  147. package/lib/types/fetch-route-intercept.d.ts +156 -0
  148. package/lib/types/fetch-route-intercept.d.ts.map +1 -0
  149. package/lib/types/fingerprint.d.ts +166 -0
  150. package/lib/types/fingerprint.d.ts.map +1 -0
  151. package/lib/types/http.d.ts +41 -0
  152. package/lib/types/http.d.ts.map +1 -0
  153. package/lib/types/index.d.ts +56 -24
  154. package/lib/types/index.d.ts.map +1 -1
  155. package/lib/types/intercept-shape.d.ts +32 -0
  156. package/lib/types/intercept-shape.d.ts.map +1 -0
  157. package/lib/types/intercept.d.ts +442 -0
  158. package/lib/types/intercept.d.ts.map +1 -0
  159. package/lib/types/merge-streams.d.ts +398 -0
  160. package/lib/types/merge-streams.d.ts.map +1 -0
  161. package/lib/types/relay-access.d.ts +310 -0
  162. package/lib/types/relay-access.d.ts.map +1 -0
  163. package/lib/types/relay-client.d.ts +274 -0
  164. package/lib/types/relay-client.d.ts.map +1 -0
  165. package/lib/types/relay-filter.d.ts +103 -0
  166. package/lib/types/relay-filter.d.ts.map +1 -0
  167. package/lib/types/relay-server.d.ts +208 -0
  168. package/lib/types/relay-server.d.ts.map +1 -0
  169. package/lib/types/restart-fields.d.ts +22 -0
  170. package/lib/types/restart-fields.d.ts.map +1 -0
  171. package/lib/types/restart-watcher.d.ts +83 -0
  172. package/lib/types/restart-watcher.d.ts.map +1 -0
  173. package/lib/types/session-reference.d.ts +66 -0
  174. package/lib/types/session-reference.d.ts.map +1 -0
  175. package/lib/types/share-export.d.ts +14 -1
  176. package/lib/types/share-export.d.ts.map +1 -1
  177. package/lib/types/share-ops.d.ts +79 -0
  178. package/lib/types/share-ops.d.ts.map +1 -0
  179. package/lib/types/share-store.d.ts +87 -0
  180. package/lib/types/share-store.d.ts.map +1 -0
  181. package/lib/types/virtual-id.d.ts +52 -0
  182. package/lib/types/virtual-id.d.ts.map +1 -0
  183. package/lib/virtual-id.js +66 -0
  184. package/lib/virtual-id.js.map +1 -0
  185. package/llms.txt +17 -14
  186. package/package.json +60 -50
  187. package/scripts/build-client.mjs +5 -3
  188. package/scripts/check-host-shadow.mjs +19 -2
  189. package/scripts/check-settings-form.mjs +933 -0
  190. package/scripts/check-shares.mjs +397 -0
  191. package/scripts/check-upload-endpoint.mjs +59 -3
  192. package/scripts/sync-doc-version.mjs +8 -15
  193. package/scripts/verify-fingerprint-live.mjs +111 -0
  194. package/src/activity.ts +218 -0
  195. package/src/admin-routes.ts +627 -0
  196. package/src/client/MobileAttachButton.tsx +2 -2
  197. package/src/client/MobileAttachChips.tsx +3 -3
  198. package/src/client/MobileDrawerFooter.tsx +7 -4
  199. package/src/client/MobileHome.tsx +20 -16
  200. package/src/client/MobileHomeChips.tsx +16 -16
  201. package/src/client/MobileNavOverlay.tsx +2 -2
  202. package/src/client/MobileNavToggle.tsx +3 -3
  203. package/src/client/MobileSessionHeader.tsx +63 -42
  204. package/src/client/MobileSessionInfo.tsx +118 -17
  205. package/src/client/RemoteComposerBanner.tsx +76 -0
  206. package/src/client/RemoteHeaderIcon.tsx +103 -0
  207. package/src/client/RemoteShareMenu.tsx +57 -0
  208. package/src/client/RemoteStatusIcon.tsx +91 -0
  209. package/src/client/compat/desktop.ts +22 -0
  210. package/src/client/compat/types.ts +62 -0
  211. package/src/client/current-session-report.ts +164 -0
  212. package/src/client/effects/header-status.ts +21 -17
  213. package/src/client/effects/keyboard-guard.ts +65 -1
  214. package/src/client/effects/model-group-side.ts +132 -0
  215. package/src/client/effects/permission-sheet.ts +149 -0
  216. package/src/client/effects/remote-session.ts +68 -0
  217. package/src/client/effects/turn-fold.ts +52 -0
  218. package/src/client/index.tsx +158 -36
  219. package/src/client/locales.ts +396 -2
  220. package/src/client/remote-fetch.ts +125 -0
  221. package/src/client/remote-group-expansion.ts +190 -0
  222. package/src/client/remote-share-css.ts +54 -0
  223. package/src/client/remote-share-register.ts +244 -0
  224. package/src/client/remote-status-css.ts +64 -0
  225. package/src/client/remote-status-register.ts +107 -0
  226. package/src/client/settings/SettingsSection.tsx +1229 -0
  227. package/src/client/settings/register-settings.ts +116 -0
  228. package/src/client/settings/settings-css.ts +236 -0
  229. package/src/client/share/share-preview.tsx +6 -3
  230. package/src/client/share/share-sheet.tsx +3 -3
  231. package/src/client/styles/composer.css.ts +119 -26
  232. package/src/client/styles/header.css.ts +7 -7
  233. package/src/client/styles/info.css.ts +74 -0
  234. package/src/client/styles/remote-session.css.ts +274 -0
  235. package/src/client-data/current-session.ts +57 -0
  236. package/src/client-data/model-group-side.ts +65 -0
  237. package/src/client-data/remote-group-expansion.ts +145 -0
  238. package/src/client-data/remote-status.ts +374 -0
  239. package/src/client-data/settings-form.ts +1371 -0
  240. package/src/client-data/shares.ts +467 -0
  241. package/src/client-pairing.ts +244 -0
  242. package/src/client-routes.ts +732 -0
  243. package/src/config.ts +447 -0
  244. package/src/fetch-route-intercept.ts +510 -0
  245. package/src/fingerprint.ts +410 -0
  246. package/src/http.ts +68 -0
  247. package/src/index.ts +719 -62
  248. package/src/intercept-shape.ts +87 -0
  249. package/src/intercept.ts +3510 -0
  250. package/src/merge-streams.ts +1279 -0
  251. package/src/relay-access.ts +672 -0
  252. package/src/relay-client.ts +1514 -0
  253. package/src/relay-filter.ts +291 -0
  254. package/src/relay-server.ts +2063 -0
  255. package/src/restart-fields.ts +36 -0
  256. package/src/restart-watcher.ts +140 -0
  257. package/src/session-reference.ts +156 -0
  258. package/src/share-export.ts +26 -1
  259. package/src/share-ops.ts +114 -0
  260. package/src/share-store.ts +373 -0
  261. package/src/virtual-id.ts +74 -0
@@ -0,0 +1,103 @@
1
+ /**
2
+ * Pure wire-frame filters for the relay's streaming subscriptions (T22b).
3
+ *
4
+ * Two of DSH's subscriptions are GLOBAL — `workspace/follow` and
5
+ * `session/control` carry every workspace and every session of the server,
6
+ * while a paired desktop client may only see shared ones. Frames are filtered
7
+ * HERE, one frame at a time, right before they are written to the client; the
8
+ * upstream subscription stays unfiltered, which is what lets a later
9
+ * share/unshare re-filter already-known state without re-reading anything.
10
+ *
11
+ * Frame shapes mirror the generated codecs in the 0.2.0
12
+ * `lib/typert.remote-client.js` of `@deepseek-ai/dsh-api-workspace-controller`
13
+ * / `-session-controller` / `-job-controller` (verified against the local
14
+ * copies, docs/spike-relay.md §3): `baseline` is the only frame that nests its
15
+ * payload under `value`; every increment frame carries its fields at the TOP
16
+ * level (`{type:'upsert', workspace}`, `{type:'archived',
17
+ * archivedSessionIds}`, …). A frame that does not match a known type is
18
+ * dropped (null) rather than forwarded — an unrecognized frame is either a
19
+ * future protocol or a hostile inject, and neither may reach the client.
20
+ *
21
+ * All functions are pure: the input is never mutated, filtered frames come
22
+ * back as new objects, passthrough frames (`remove` / `order`, accessible
23
+ * `projection`) come back unchanged.
24
+ */
25
+ /** The accessibility oracle: true when a session may travel to this client. */
26
+ export type Accessibility = (sessionId: string) => boolean;
27
+ /**
28
+ * Filter one `workspace/follow` frame. `baseline` and `upsert` keep every
29
+ * workspace but narrow each `sessionIds`; `archived` / `pinned` narrow their
30
+ * lists; `remove` / `order` carry no session ids and pass through unchanged;
31
+ * anything else is dropped.
32
+ */
33
+ export declare function filterWorkspaceFrame(frame: unknown, isAccessible: Accessibility): Record<string, unknown> | null;
34
+ /**
35
+ * Filter one `session/control` frame. Exactly two frame types exist:
36
+ * `baseline{value:{projections: Record<sessionId, {asOfSeq, values}>}}` — the
37
+ * per-session map keeps only accessible keys — and `projection{sessionId, key,
38
+ * value, seq}` — kept whole or dropped by its session id. Anything else is
39
+ * dropped.
40
+ *
41
+ * The baseline record is rebuilt with `defineProperty` because a session id of
42
+ * `__proto__` must become an own data property of the new record, not fire the
43
+ * prototype setter (the same trap share-store.ts documents for its file keys).
44
+ */
45
+ export declare function filterControlFrame(frame: unknown, isAccessible: Accessibility): Record<string, unknown> | null;
46
+ /**
47
+ * Filter one `session/list` result (the invoke route forwards it as the
48
+ * enveloped value): `items` keeps only entries whose `sessionId` is
49
+ * accessible, every other field of the result (and of each kept item) passes
50
+ * through as-is — except a `parentSessionId` naming a session the share table
51
+ * cannot reach (CP4): that field is dropped while the row stays, so the id of
52
+ * a hidden session never travels, not even as a dangling parent link. The
53
+ * result arrives from the same JSON boundary as the frames but it is a
54
+ * RESULT, not a frame — there is no unknown-shape refusal here; a result
55
+ * without an `items` array simply has nothing to filter.
56
+ */
57
+ export declare function filterSessionListResult(result: unknown, isAccessible: Accessibility): unknown;
58
+ /**
59
+ * Scrub one `session/modelCatalog` result (T52-fix): the `failures` array is
60
+ * emptied in place-shaped fashion — the whole result otherwise passes through
61
+ * — because a provider group's failure text is the HOST's own error for that
62
+ * group (adapter names, endpoint URLs, credential states; RT
63
+ * dsh-api-session-controller `lib/index.js` builds `failures` from each
64
+ * adapter's load error). The sub-client discards `failures` anyway
65
+ * (intercept.ts mergeModelCatalogs keeps the LOCAL failures only), so
66
+ * forwarding the server's texts would spend real detail for nothing a client
67
+ * can show. The result arrives from the same JSON boundary as the frames; a
68
+ * result without a recognizable shape passes untouched (the merge on the far
69
+ * side re-guards it).
70
+ */
71
+ export declare function filterModelCatalogResult(value: unknown): unknown;
72
+ /**
73
+ * Filter one `job/list` frame (`{type:'rows', jobs:[…]}` — the only frame type
74
+ * the stream emits). DSH opens every OWNERLESS job to all sessions, so the
75
+ * unfiltered stream would leak server-wide jobs through any shared session;
76
+ * the relay keeps only jobs whose `owner` is exactly the session the client
77
+ * claimed in `request.sessionId`. Ownerless jobs (`owner` absent) are
78
+ * therefore invisible remotely — including for `job/follow` / `job/kill`,
79
+ * which the relay refuses separately (relay-server.ts).
80
+ */
81
+ export declare function filterJobListFrame(frame: unknown, ownerSessionId: string): Record<string, unknown> | null;
82
+ /**
83
+ * The unfiltered latest workspace state behind ONE `workspace/follow` relay
84
+ * stream, maintained from the raw upstream frames so a share/unshare can
85
+ * synthesize the frames the client missed (relay-server.ts writes them as if
86
+ * the workspace had just been upserted).
87
+ */
88
+ export interface WorkspaceFollowState {
89
+ /** Feed one raw upstream frame (baseline / upsert / remove / order /
90
+ * archived / pinned); unknown frames are ignored. */
91
+ apply(frame: unknown): void;
92
+ /**
93
+ * Frames to write after `sessionId` was shared or unshared: one re-filtered
94
+ * `upsert` per workspace currently containing it, plus one `archived` /
95
+ * `pinned` frame when the session sits in those lists. Running the
96
+ * synthesized frames back through {@link filterWorkspaceFrame} keeps their
97
+ * shape identical to real upstream frames — and naturally drops the session
98
+ * after an unshare.
99
+ */
100
+ onShareChange(sessionId: string, isAccessible: Accessibility): Record<string, unknown>[];
101
+ }
102
+ export declare function createWorkspaceFollowState(): WorkspaceFollowState;
103
+ //# sourceMappingURL=relay-filter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"relay-filter.d.ts","sourceRoot":"","sources":["../../src/relay-filter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,+EAA+E;AAC/E,MAAM,MAAM,aAAa,GAAG,CAAC,SAAS,EAAE,MAAM,KAAK,OAAO,CAAA;AAwB1D;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CA6BhH;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAsB9G;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE,aAAa,GAAG,OAAO,CAgB7F;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAGhE;AAED;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAOzG;AAED;;;;;GAKG;AACH,MAAM,WAAW,oBAAoB;IACnC;yDACqD;IACrD,KAAK,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,CAAA;IAC3B;;;;;;;OAOG;IACH,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,YAAY,EAAE,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAA;CACzF;AAED,wBAAgB,0BAA0B,IAAI,oBAAoB,CAkFjE"}
@@ -0,0 +1,208 @@
1
+ /**
2
+ * Server-side relay routes for the desktop client (T22a routes, T22b
3
+ * streaming, T32 event forwarding, T41b plain-HTTP passthrough):
4
+ * authentication, ping, handshake, the single invoke passthrough, the
5
+ * `relay/v1/http` GET dispatch through the host's shared `/api` fetch
6
+ * handler, the NDJSON stream subscription route with share-change
7
+ * synchronization, and the forwarded-event half — the
8
+ * `$zr/events` subscription over the gateway's `$events` wire stream plus
9
+ * the `relay/v1/event-result` answer route. Activity stats remain a later
10
+ * task.
11
+ *
12
+ * Why the secret: the desktop client is a Node process on another machine —
13
+ * it has no DSH login cookie, so the gateway authenticates it with a Bearer
14
+ * pairing token and marks the forwarded request with `x-zen-remote-*` headers.
15
+ * But DSH only listens on 127.0.0.1, where any local process could bypass the
16
+ * gateway and forge those headers. The plugin therefore mints a per-apply
17
+ * secret, hands it to the gateway child through `LAN_GATE_RELAY_SECRET`, the
18
+ * gateway stamps every device-authenticated forward with it, and these routes
19
+ * re-verify it on every request with `timingSafeEqual`.
20
+ *
21
+ * Path dispatch never decodes the request path. The gateway only admits relay
22
+ * paths whose raw and URL-normalized forms are byte-identical, which lets
23
+ * `/_dsh/zen-remote/relay/..%2f..%2fapi` through — decoding it here before
24
+ * matching would reopen the traversal the gateway just closed. Every route is
25
+ * an exact comparison on `new URL(req.url).pathname` as-is; anything else is
26
+ * a 404.
27
+ */
28
+ import type { IncomingMessage, ServerResponse } from 'node:http';
29
+ import type { ShareStore } from './share-store.js';
30
+ /**
31
+ * Registration prefix on the host webServer. Deliberately WITHOUT the
32
+ * trailing slash: the webserver matches a prefix route as `pathname === p ||
33
+ * pathname.startsWith(p + '/')`, so a trailing slash here would match only
34
+ * `…/relay//…` shapes and never `…/relay/ping`.
35
+ */
36
+ export declare const RELAY_PREFIX = "/_dsh/zen-remote/relay";
37
+ /**
38
+ * Body ceiling for the binary upload channel alone (T51): a shared session's
39
+ * non-image file attachments. DSH's own upload route has NO byte cap — the
40
+ * host stores the stream verbatim (`saveFileStreamVerbatim` →
41
+ * `publishImmutableObjectStream`, RT dsh-attachment-local lib/index.js
42
+ * ~699-716; the 20 MiB `maxImageBytes` there covers INLINE images only), so
43
+ * there is no host number to mirror and this relay picks its own: 100 MiB
44
+ * per upload, checked first against `Content-Length` (refused before a byte
45
+ * moves) and then counted while the stream is pumped (a chunked body has no
46
+ * length header — the sub-client's undici forbids hand-set length headers,
47
+ * so the streaming count is the path its uploads normally take). Past the
48
+ * cap the forward is aborted, the rest of the request is drained and the
49
+ * answer is 413 `payload-too-large`.
50
+ *
51
+ * SLOW-LINK BOUND (T51-fix, for the docs): a single legitimate upload is
52
+ * also bounded in TIME — the host's HTTP server keeps its default 300 s
53
+ * request deadline, and the sub-client's own round-trip budget caps at the
54
+ * same 300 s (relay-client.ts, the T31-fix rule) — so a 100 MiB body needs
55
+ * roughly 2.8 Mbps sustained end to end; slower links fail the call (the
56
+ * client-side refusal keeps the connection state) rather than hanging.
57
+ */
58
+ export declare const MAX_UPLOAD_BYTES: number;
59
+ /** The `/api` route the upload channel dispatches into, verbatim from the
60
+ * host's own registration (RT dsh-client-file-upload lib/index.js:73). */
61
+ export declare const UPLOAD_HTTP_PATH = "/api/session/uploadFileBinary";
62
+ /** Shape of the `typertGateway` service this route needs (measured live,
63
+ * docs/spike-relay.md §2.1: invoke returns the unwrapped business value and
64
+ * throws errors carrying a string `code`; stream opens one `mode: 'stream'`
65
+ * method and resolves to an async iterable of its frames). Declared
66
+ * structurally instead of augmenting `Context`: the providing package is not
67
+ * a devDependency here, and a local augmentation could collide with its own
68
+ * once that changes.
69
+ *
70
+ * T32 adds the two event surfaces, both OPTIONAL: only `$zr/events` and
71
+ * `relay/v1/event-result` touch them, so a composition (or test fake) without
72
+ * them keeps every other route working and the event routes answer
73
+ * `gateway/service-unavailable`.
74
+ *
75
+ * - `wireStream.open('$events', …)` is the ONLY way to the forwarded-event
76
+ * stream — `gw.stream({namespace:'$events'})` refuses with
77
+ * `gateway/invocation-unavailable` (docs/spike-relay.md §2.1 坑 1). It
78
+ * resolves to an async iterable whose first frame is the `ready` frame.
79
+ * - `dispatchRpc('$events/result', payload, signal, peer)` is the only way to
80
+ * answer a forwarded waterfall — the gateway special-cases the endpoint
81
+ * before its typert dispatch — and returns the `{ok,…}` envelope itself.
82
+ */
83
+ export interface RelayGateway {
84
+ invoke(call: {
85
+ namespace: string;
86
+ method: string;
87
+ args: unknown;
88
+ signal?: AbortSignal;
89
+ }): Promise<unknown>;
90
+ stream(call: {
91
+ namespace: string;
92
+ method: string;
93
+ args: unknown;
94
+ signal?: AbortSignal;
95
+ }): Promise<AsyncIterable<unknown>>;
96
+ /** The host's wire adapter, shared by the WebSocket mux and the local
97
+ * transports. `open` is the async 0.2.0 method. */
98
+ wireStream?: {
99
+ open(endpoint: string, payload: unknown, uplink: unknown, peer: unknown, signal: AbortSignal | undefined): unknown;
100
+ };
101
+ /** The host's `/api` dispatch, owning the `$events/result` special case. */
102
+ dispatchRpc?(endpoint: string, payload: unknown, signal: AbortSignal | undefined, peer: unknown): Promise<unknown>;
103
+ }
104
+ /** What the handshake reports about this server. `serverName` is a CALLBACK
105
+ * on purpose: the row value is a volatile (`{ get() }` wrapped) setting that
106
+ * can change without restarting the plugin row, so it must be recomputed at
107
+ * handshake time, not snapshotted at registration. `fingerprints` is a
108
+ * callback too (T42), awaited per handshake so a just-restarted server never
109
+ * serves a stale map; a THROWN compute degrades to the empty map here so a
110
+ * broken fingerprint source can never fail the handshake itself — the
111
+ * client's comparison judges every group `unavailable`, never `different`. */
112
+ export interface RelayServerInfo {
113
+ serverId: string;
114
+ serverName: () => string;
115
+ dshVersion: string;
116
+ fingerprints?: () => Record<string, string> | Promise<Record<string, string>>;
117
+ }
118
+ export interface RelayHandlerOptions {
119
+ /** The per-apply shared secret; an empty one refuses every request. */
120
+ secret: string;
121
+ /** The shared-session table deciding reachability. */
122
+ store: ShareStore;
123
+ /** The host gateway service invokes and streams go through. */
124
+ gateway: RelayGateway;
125
+ /** Handshake facts. */
126
+ serverInfo: RelayServerInfo;
127
+ /** Ancestor lookup for subagent reachability; defaults to "no parent". */
128
+ parentOf?: (id: string) => string | undefined;
129
+ /** The host's `/api` shared-fetch dispatcher (T41b), probed lazily per
130
+ * request: `undefined` — no connection service, or no shared handler —
131
+ * answers 501 `unsupported` instead of touching the network. The wiring
132
+ * builds it from `connection.createSharedFetchHandler('/api').fetch`
133
+ * (dsh-client-connection), the in-process entry that dispatches a
134
+ * synthetic Request to the same exact-fetch route table the browser's
135
+ * `/api` transport uses — no loopback HTTP, no login state. */
136
+ getApiFetch?: () => ((request: Request) => Promise<Response>) | undefined;
137
+ /** Stream heartbeat interval in ms (a `{"type":"ping"}` line that keeps
138
+ * reverse proxies from timing the idle stream away); defaults to 15000.
139
+ * Tests inject a small value. */
140
+ heartbeatMs?: number;
141
+ /** How long a stream's finish may wait for a backed-up write buffer to
142
+ * drain before the response is destroyed (T43-A: a client that stopped
143
+ * reading must not pin the viewer count and the device budget forever);
144
+ * defaults to 5000. Tests inject a small value. */
145
+ endDrainTimeoutMs?: number;
146
+ /** The binary upload channel's byte cap (T51); defaults to
147
+ * {@link MAX_UPLOAD_BYTES} (100 MiB). Tests inject a small value so the
148
+ * Content-Length and streaming-count refusals stay cheap to drive. */
149
+ uploadCapBytes?: number;
150
+ /** How long an upload refusal's tail drain may run before the socket is
151
+ * destroyed (the {@link DRAIN_DEADLINE_MS} bound); defaults to 10000.
152
+ * Tests inject a small value so the deadline path stays cheap to drive. */
153
+ drainDeadlineMs?: number;
154
+ }
155
+ /**
156
+ * The relay route handler plus its introspection surface. A function WITH
157
+ * properties on purpose: the webServer registration wants exactly a request
158
+ * handler, and the "who is looking" badge (a later UI task) wants the
159
+ * per-session viewer counts — while the row-reload path (T22b-fix) needs to
160
+ * tear every open stream down with the handler that owns it.
161
+ */
162
+ export interface RelayHandler {
163
+ (req: IncomingMessage, res: ServerResponse): Promise<void>;
164
+ /** How many session-scoped relay streams currently reference the session
165
+ * (across all devices). */
166
+ viewerCount(sessionId: string): number;
167
+ /** End every currently open stream: each client gets one
168
+ * `error{code:'server-restart'}` line, then the response ends (a client
169
+ * that stopped reading is destroyed after {@link RelayHandlerOptions.endDrainTimeoutMs}),
170
+ * the upstream subscription aborts and every counter/listener cleans up —
171
+ * including the handler's own share-table subscriptions, so a table change
172
+ * after the close never reaches this handler again (T43-B). A plugin row
173
+ * reload builds a new handler and share table; without this the streams of
174
+ * the OLD handler would keep pushing, unreachable by any unshare. */
175
+ closeAll(reason: string): void;
176
+ }
177
+ /**
178
+ * Read the persisted server id, creating (and persisting) one on first use.
179
+ * A missing file is the normal first run; an unreadable or damaged file must
180
+ * never take the host down, so every failure degrades to a fresh per-process
181
+ * id that simply is not remembered across restarts.
182
+ */
183
+ export declare function loadServerId(home: string): string;
184
+ /**
185
+ * The DSH version reported in the handshake: `DSH_CLIENT_VERSION` when the
186
+ * host sets it, else the version of the `@deepseek-ai/dsh` package resolved
187
+ * from here (compositions without that package installed — tests, Electron —
188
+ * report `'unknown'`). Never throws.
189
+ */
190
+ export declare function resolveDshVersion(): string;
191
+ /**
192
+ * Build the relay route handler mounted under {@link RELAY_PREFIX}. Exported
193
+ * as a factory so the route tests can drive it against a plain node:http
194
+ * server with a fake gateway and a real share store — no harness required.
195
+ *
196
+ * Every request passes the same gate first: gateway secret, then the two
197
+ * marking headers. Failures answer a uniform 401 that does not say WHICH
198
+ * check failed — the difference would only help someone probing the wall.
199
+ * After the gate, `x-zen-remote-device` is the caller's device id (the
200
+ * per-device stream budget hangs off it).
201
+ *
202
+ * @param options - secret, share store, gateway service and server facts.
203
+ * @returns the handler owning the full response lifecycle of one request,
204
+ * with `viewerCount` alongside for the "who is looking" surface.
205
+ */
206
+ export declare function createRelayHandler(options: RelayHandlerOptions): RelayHandler;
207
+ export { SESSION_REFERENCE_URI, collectReferenceTexts, decodeSessionReferenceUri, encodeSessionReferenceUri, mapReferenceTexts, } from './session-reference.js';
208
+ //# sourceMappingURL=relay-server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"relay-server.d.ts","sourceRoot":"","sources":["../../src/relay-server.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * The plugin row fields whose changed value must reload the row to take
3
+ * effect (T17): `role` chooses which halves load; `port` / `host` /
4
+ * `targetPort` / `rateLimit` / `trustedProxies` become the gateway child's
5
+ * runtime shape; `vapidSubject` / `lang` / `pushEvents` / `pushDebounceMs` /
6
+ * `pushSummary` / `pushTurnEnd` / `pushTool` are the push leg's startup
7
+ * values. Everything else (serverName, idleHours, autoShareNewSessions,
8
+ * serverUrl, deviceToken, and the interface-half knobs) is read live per use
9
+ * and needs no reload.
10
+ *
11
+ * Single source shared by both halves: the host's restart watcher
12
+ * (src/restart-watcher.ts) fingerprints exactly these fields, and the
13
+ * settings page (src/client-data/settings-form.ts) shows the "saving reloads
14
+ * the plugin" note while one of them has a staged change. Deliberately
15
+ * dependency-free — the client bundler inlines every reachable module, so
16
+ * this file must never import node builtins or schemastery, which is why the
17
+ * list does not live in src/config.ts (T17b).
18
+ */
19
+ export declare const RESTART_FIELDS: readonly ["role", "port", "host", "targetPort", "rateLimit", "trustedProxies", "vapidSubject", "lang", "pushEvents", "pushDebounceMs", "pushSummary", "pushTurnEnd", "pushTool"];
20
+ /** One field of {@link RESTART_FIELDS}. */
21
+ export type RestartField = (typeof RESTART_FIELDS)[number];
22
+ //# sourceMappingURL=restart-fields.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"restart-fields.d.ts","sourceRoot":"","sources":["../../src/restart-fields.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,cAAc,kLAcjB,CAAA;AAEV,2CAA2C;AAC3C,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,cAAc,CAAC,CAAC,MAAM,CAAC,CAAA"}
@@ -0,0 +1,83 @@
1
+ /**
2
+ * Auto-reload of the plugin row when a "needs restart" config field changes
3
+ * (T17). Every Config field is volatile (src/config.ts — DSH's settings
4
+ * service only surfaces volatile fields), so "this value only takes effect
5
+ * after the row re-runs apply()" can no longer ride the volatility flag.
6
+ * Instead the host half re-resolves the effective config and compares a
7
+ * fingerprint over exactly the restart-required fields; a changed fingerprint
8
+ * reloads the row via cordis, which re-runs `apply()` and with it the gateway
9
+ * child and the push half. The comparison runs on two triggers (T17b): the
10
+ * loader's `loader/volatile-update` event (a settings save that only moves
11
+ * volatile fields commits without a restart and announces itself — the
12
+ * immediate path) and a 2s poll (the fallback for lan-gate.config.json and
13
+ * environment changes, which no loader event ever covers).
14
+ *
15
+ * Pure logic — no imports beyond src/restart-fields.ts and src/config.ts
16
+ * types, and timers only through injectable functions
17
+ * (test/restart-watcher.test.cjs drives every tick from a fake clock, same
18
+ * shape as startSweeper in src/activity.ts).
19
+ */
20
+ import type { ZenRemoteConfig } from './config.js';
21
+ export { RESTART_FIELDS } from './restart-fields.js';
22
+ export type { RestartField } from './restart-fields.js';
23
+ /**
24
+ * The restart fingerprint of one resolved config: the restart-required
25
+ * fields' values, JSON-stringified under a stable (sorted) key order, so a
26
+ * deep-equal config always yields the same string regardless of key order or
27
+ * the values of every other field. Takes a loose record (the resolved values
28
+ * type satisfies it structurally) because tests feed partial objects; a
29
+ * missing field and an undefined one are the same "not set".
30
+ */
31
+ export declare function restartKey(values: {
32
+ [K in keyof ZenRemoteConfig]?: unknown;
33
+ }): string;
34
+ /** Duck-typed timer halves, exactly like src/activity.ts's sweeper: Node's
35
+ * setInterval/clearInterval at runtime, fakes in tests. */
36
+ type StartInterval = (callback: () => void, ms: number) => unknown;
37
+ type ClearInterval = (handle: unknown) => void;
38
+ export interface RestartWatcherOptions {
39
+ /** Resolve the CURRENT effective config values; called once immediately
40
+ * (the baseline) and once per trigger. A throw is swallowed and retried on
41
+ * the next trigger — the watcher must survive a transient resolution
42
+ * failure. */
43
+ getValues: () => ZenRemoteConfig;
44
+ /** Called at most once, when the fingerprint diverges from the baseline.
45
+ * After the call the watcher is done: it clears its own timer, so a slow
46
+ * or failing reload can never trigger a second one (the reload itself
47
+ * re-runs apply(), which starts a fresh watcher). */
48
+ onChange: () => void;
49
+ /** Poll cadence in ms. Default 2000. */
50
+ intervalMs?: number;
51
+ /** Injectable timer halves (tests drive ticks by hand). */
52
+ setIntervalImpl?: StartInterval;
53
+ clearIntervalImpl?: ClearInterval;
54
+ }
55
+ /** The two handles {@link startRestartWatcher} gives back: the poll's stop
56
+ * function (the host half hands it to ctx.effect as the disposer) and the
57
+ * immediate check the `loader/volatile-update` listener calls (T17b). */
58
+ export interface RestartWatcher {
59
+ stop(): void;
60
+ /** One fingerprint comparison right now, bypassing the poll cadence.
61
+ * Identical semantics to a poll tick that sees a change: fires
62
+ * {@link RestartWatcherOptions.onChange} at most once, then disarms
63
+ * itself. */
64
+ checkNow(): void;
65
+ }
66
+ /**
67
+ * Watch the restart-required fields and call `onChange` (once) when their
68
+ * resolved values diverge from the values {@link startRestartWatcher} was
69
+ * started with. Two triggers share the one fire-at-most-once guard: the
70
+ * returned `checkNow()` (the loader's `loader/volatile-update` event — a
71
+ * volatile-only settings save commits without a restart and announces itself
72
+ * on the row context, so the fingerprint is re-checked immediately instead
73
+ * of at the next tick, T17b) and the 2s poll, which remains the safety net
74
+ * for the layers no loader event ever covers — `lan-gate.config.json` and
75
+ * `LAN_GATE_*` / `DSH_PUSH_*` environment changes are picked up by the same
76
+ * comparison (getValues re-resolves every layer), which is the desired
77
+ * behavior: those layers below the row are just as invisible to a live read
78
+ * as a restart-required row field. `stop` is the disposer (the host half
79
+ * hands it to ctx.effect); the underlying timer is unref()ed so the poll
80
+ * alone never keeps the DSH process alive.
81
+ */
82
+ export declare function startRestartWatcher(options: RestartWatcherOptions): RestartWatcher;
83
+ //# sourceMappingURL=restart-watcher.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"restart-watcher.d.ts","sourceRoot":"","sources":["../../src/restart-watcher.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAGlD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AACpD,YAAY,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAEvD;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE;KAAG,CAAC,IAAI,MAAM,eAAe,CAAC,CAAC,EAAE,OAAO;CAAE,GAAG,MAAM,CAIrF;AAED;2DAC2D;AAC3D,KAAK,aAAa,GAAG,CAAC,QAAQ,EAAE,MAAM,IAAI,EAAE,EAAE,EAAE,MAAM,KAAK,OAAO,CAAA;AAClE,KAAK,aAAa,GAAG,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,CAAA;AAE9C,MAAM,WAAW,qBAAqB;IACpC;;;kBAGc;IACd,SAAS,EAAE,MAAM,eAAe,CAAA;IAChC;;;yDAGqD;IACrD,QAAQ,EAAE,MAAM,IAAI,CAAA;IACpB,wCAAwC;IACxC,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,2DAA2D;IAC3D,eAAe,CAAC,EAAE,aAAa,CAAA;IAC/B,iBAAiB,CAAC,EAAE,aAAa,CAAA;CAClC;AAED;;yEAEyE;AACzE,MAAM,WAAW,cAAc;IAC7B,IAAI,IAAI,IAAI,CAAA;IACZ;;;iBAGa;IACb,QAAQ,IAAI,IAAI,CAAA;CACjB;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,qBAAqB,GAAG,cAAc,CAgDlF"}
@@ -0,0 +1,66 @@
1
+ /**
2
+ * The `dsh-session:` reference discipline BOTH ends share (T41a-fix2):
3
+ *
4
+ * - the CODEC — the canonical reference addresses the host's own parser
5
+ * accepts (dsh-session-reference lib/index.js: a Markdown mention
6
+ * `@[label](URI)` or a bare URI; the payload is
7
+ * base64url(JSON.stringify(sessionId)) and the decode is CANONICAL —
8
+ * re-encoding must reproduce the URI byte for byte);
9
+ * - the SCAN RULE — which texts of one relayed call DSH would inject
10
+ * through. `prepareDirectMessages` parses the text blocks of EVERY
11
+ * user-sourced message wherever the message came from, and three wire
12
+ * paths put remote text into such a message: the prompt content
13
+ * (`session/prompt`, `subagents/prompt`), a queue edit — the edit
14
+ * REPLACES the queued user message's content verbatim (RT
15
+ * dsh-api-session-controller updateQueue) — and a slash command's raw
16
+ * input, which handlers steer in as a fresh user message (`/plan <text>`
17
+ * does exactly that, RT dsh-plan-mode). So the rule reads:
18
+ *
19
+ * `session/prompt` / `subagents/prompt` → the text blocks of
20
+ * `request.content`;
21
+ * `session/updateQueue` → when `request.action.kind === 'edit'`, the
22
+ * text blocks of `request.action.content` (steer/remove carry no
23
+ * content the host would inject);
24
+ * `commands/execute` → EVERY string in the arguments, recursively —
25
+ * the injection surface is whatever the command's handler does with
26
+ * the line, so the scan does not depend on the argument field name.
27
+ *
28
+ * Everything else contributes nothing. The relay server decodes every
29
+ * reference found in these texts and refuses the call when one names a
30
+ * session off its share table (relay-server.ts); the sub-client restores
31
+ * THIS server's virtual ids inside them and refuses references naming
32
+ * anything else (intercept.ts). One module serves both so the ends
33
+ * cannot drift — the previous two private copies are gone.
34
+ *
35
+ * Pure functions, no I/O; safe for both the host bundle and the tests.
36
+ */
37
+ /** The canonical reference shape, as {@link decodeSessionReferenceUri}
38
+ * consumes it. Match group 1 is a mention's URI, group 2 a bare URI. */
39
+ export declare const SESSION_REFERENCE_URI: RegExp;
40
+ /** Encode one session id into the canonical reference URI (matching the
41
+ * host's encoder, the mirror of {@link decodeSessionReferenceUri}). */
42
+ export declare function encodeSessionReferenceUri(sessionId: string): string;
43
+ /**
44
+ * Decode one `dsh-session:` URI the way the host does, or `undefined` when
45
+ * it is not canonical. The host parser THROWS on non-canonical addresses —
46
+ * those become gateway business errors — so an address this decoder rejects
47
+ * can never inject anything and needs no guarding.
48
+ */
49
+ export declare function decodeSessionReferenceUri(uri: string): string | undefined;
50
+ /**
51
+ * Apply `visit` to EVERY text of one call the host would inject through —
52
+ * the scan rule above, in one place. The args are mutated IN PLACE where
53
+ * the rule reaches (content blocks) and rebuilt clone-on-write where it
54
+ * walks recursively (commands/execute); the returned args are what should
55
+ * travel (identical to the input when `visit` was the identity on every
56
+ * text). Both ends call THIS to decide what to scan — the server to check,
57
+ * the client to rewrite — so the two cannot disagree on where references
58
+ * hide.
59
+ */
60
+ export declare function mapReferenceTexts(namespace: string, method: string, args: unknown, visit: (text: string) => string): unknown;
61
+ /**
62
+ * The texts of one call the host would inject through, read-only — the
63
+ * server-side face of {@link mapReferenceTexts}.
64
+ */
65
+ export declare function collectReferenceTexts(namespace: string, method: string, args: unknown): string[];
66
+ //# sourceMappingURL=session-reference.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session-reference.d.ts","sourceRoot":"","sources":["../../src/session-reference.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAEH;wEACwE;AACxE,eAAO,MAAM,qBAAqB,QAAkF,CAAA;AAEpH;uEACuE;AACvE,wBAAgB,yBAAyB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAEnE;AAED;;;;;GAKG;AACH,wBAAgB,yBAAyB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAWzE;AAkDD;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,GAAG,OAAO,CAkB5H;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,MAAM,EAAE,CAOhG"}
@@ -27,6 +27,14 @@ export declare const SHARE_EXPORT_ROUTE = "/_dsh/mobile-nav/share-export";
27
27
  * already more wall of text than any share card wants, and the cap keeps a
28
28
  * careless `turns=99999999` from quietly meaning "the whole log". */
29
29
  export declare const MAX_SHARE_TURNS = 500;
30
+ /** What `connection.admit` answers: the operator peer, or the refusal status.
31
+ * Declared locally (same union as admin-routes.ts's AdminAdmission) so this
32
+ * module stays import-free of the entry file. */
33
+ export type ShareExportAdmission = {
34
+ readonly peer: unknown;
35
+ } | {
36
+ readonly rejection: 401 | 403;
37
+ };
30
38
  /** One exportable content block of a transcript row. */
31
39
  export type ShareBlock = {
32
40
  kind: 'text';
@@ -61,6 +69,11 @@ export interface ShareExportBody {
61
69
  * @param ctx - host context carrying the sessionQuery service and logger.
62
70
  * @param req - inbound request; no body is read.
63
71
  * @param res - the response this call owns end to end.
72
+ * @param admit - DSH's connection-service admission, passed by the apply()
73
+ * wiring (T17): webServer routes skip DSH's /api authentication, so every
74
+ * request must ask the connection service itself, its refusal relayed
75
+ * verbatim — same first wall as the admin and client routes. Optional only
76
+ * for the direct-drive tests; production always passes it.
64
77
  */
65
- export declare function handleShareExport(ctx: Context, req: IncomingMessage, res: ServerResponse): Promise<void>;
78
+ export declare function handleShareExport(ctx: Context, req: IncomingMessage, res: ServerResponse, admit?: (req: IncomingMessage) => ShareExportAdmission): Promise<void>;
66
79
  //# sourceMappingURL=share-export.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"share-export.d.ts","sourceRoot":"","sources":["../../src/share-export.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAChE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAWlD,sEAAsE;AACtE,eAAO,MAAM,kBAAkB,kCAAkC,CAAA;AAEjE;;qEAEqE;AACrE,eAAO,MAAM,eAAe,MAAM,CAAA;AAElC,wDAAwD;AACxD,MAAM,MAAM,UAAU,GAClB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAC9B;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE,CAAA;AAErB;;uDAEuD;AACvD,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,GAAG,WAAW,CAAA;IAC1B,GAAG,EAAE,MAAM,CAAA;IACX,MAAM,EAAE,UAAU,EAAE,CAAA;CACrB;AAaD,+DAA+D;AAC/D,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,IAAI,CAAA;IACR,sEAAsE;IACtE,SAAS,EAAE,MAAM,CAAA;IACjB,KAAK,EAAE,SAAS,EAAE,CAAA;IAClB;oDACgD;IAChD,SAAS,EAAE,KAAK,CAAA;CACjB;AAoTD;;;;;;;;;GASG;AACH,wBAAsB,iBAAiB,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,eAAe,EAAE,GAAG,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAoC9G"}
1
+ {"version":3,"file":"share-export.d.ts","sourceRoot":"","sources":["../../src/share-export.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAChE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAWlD,sEAAsE;AACtE,eAAO,MAAM,kBAAkB,kCAAkC,CAAA;AAEjE;;qEAEqE;AACrE,eAAO,MAAM,eAAe,MAAM,CAAA;AAElC;;iDAEiD;AACjD,MAAM,MAAM,oBAAoB,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAA;CAAE,GAAG;IAAE,QAAQ,CAAC,SAAS,EAAE,GAAG,GAAG,GAAG,CAAA;CAAE,CAAA;AAEjG,wDAAwD;AACxD,MAAM,MAAM,UAAU,GAClB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAC9B;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE,CAAA;AAErB;;uDAEuD;AACvD,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,GAAG,WAAW,CAAA;IAC1B,GAAG,EAAE,MAAM,CAAA;IACX,MAAM,EAAE,UAAU,EAAE,CAAA;CACrB;AAaD,+DAA+D;AAC/D,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,IAAI,CAAA;IACR,sEAAsE;IACtE,SAAS,EAAE,MAAM,CAAA;IACjB,KAAK,EAAE,SAAS,EAAE,CAAA;IAClB;oDACgD;IAChD,SAAS,EAAE,KAAK,CAAA;CACjB;AAoTD;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,iBAAiB,CACrC,GAAG,EAAE,OAAO,EACZ,GAAG,EAAE,eAAe,EACpB,GAAG,EAAE,cAAc,EACnB,KAAK,CAAC,EAAE,CAAC,GAAG,EAAE,eAAe,KAAK,oBAAoB,GACrD,OAAO,CAAC,IAAI,CAAC,CA8Cf"}
@@ -0,0 +1,79 @@
1
+ /**
2
+ * Pure share-table operations driven by host-side observations (T33a): the
3
+ * busy restore after a restart, and the share decision for a freshly created
4
+ * session. No DSH imports, no I/O, no clock — the table and every host fact
5
+ * come in as arguments, so the tests can drive them with plain objects.
6
+ *
7
+ * Field semantics verified against the DSH 0.2.0 sources (and spot-checked
8
+ * against the 0.1.7 line this package still supports):
9
+ *
10
+ * - `agents.list()` returns live agents whose `id` IS the session id (the
11
+ * agent registry is keyed by it, its typert wire type is
12
+ * `dsh-session/types#SessionId`, and `hasDesktopActiveTasks` in
13
+ * dsh-desktop-host feeds `agent.id` straight into `workspace/session-activity`'s
14
+ * `sessionId`). `status` is a getter answering `'idle'` or `'running'`;
15
+ * `'running'` means a turn is in flight (including waiting on approval).
16
+ * - a session header's `origin` is only ever `'subagent'` (subagent child,
17
+ * with `parentSession` naming its delegating parent); a FORK carries
18
+ * `parentSession` (its source) and `isSeeded: true` with NO origin — per
19
+ * `session/fork`'s `meta` in dsh-api-session-controller and
20
+ * `validateSessionHeader` in dsh-session.
21
+ */
22
+ import type { ShareStore } from './share-store.js';
23
+ /** The slice of a live agent the busy restore reads. Declared structurally
24
+ * so this module never imports DSH types and the tests can feed plain
25
+ * objects — the same discipline as activity.ts's ObservableSession. */
26
+ export interface AgentStatusLike {
27
+ id?: unknown;
28
+ status?: unknown;
29
+ }
30
+ /** The slice of a DSH session header the share decision reads. Field names
31
+ * per `validateSessionHeader`: `id` (matches the session id), `origin`
32
+ * (only legal value `'subagent'`), `parentSession` (a string when set). */
33
+ export interface CreatedSessionHeaderLike {
34
+ id?: unknown;
35
+ origin?: unknown;
36
+ parentSession?: unknown;
37
+ }
38
+ /**
39
+ * Re-mark the busy flags a restart wiped. `busy` is deliberately never
40
+ * persisted, so after a plugin-row restart every shared session resumes as
41
+ * idle — and an idle session whose agent is actually mid-turn would idle out
42
+ * from under it. For every shared session whose agent currently reports
43
+ * `status === 'running'`, set busy; everything else keeps the post-restart
44
+ * idle default (setting busy FALSE here would re-stamp lastActivityAt and
45
+ * silently restart idle clocks for sessions nobody touched). The running
46
+ * flags then live their normal life: T22c's activity tracker clears them on
47
+ * `turn/end`.
48
+ *
49
+ * A throwing `listAgents` means "no information", not "nothing runs" — the
50
+ * restore degrades to a no-op instead of failing its caller (a route, or
51
+ * plugin startup).
52
+ */
53
+ export declare function restoreBusy(store: ShareStore, listAgents: () => readonly AgentStatusLike[]): void;
54
+ export interface OnSessionCreatedOptions {
55
+ /** The shared-session table the decision writes into. */
56
+ store: ShareStore;
57
+ /** The volatile `autoShareNewSessions` knob, resolved by the caller AT
58
+ * EVENT TIME — never snapshotted at apply. */
59
+ autoShare: boolean;
60
+ /** Ancestor lookup for fork-source reachability (the same index the
61
+ * activity tracker and relay use). */
62
+ parentOf: (id: string) => string | undefined;
63
+ }
64
+ /**
65
+ * The share decision for one freshly created session (the `agent/created`
66
+ * `source: 'startup'` payload's session header). Returns whether the session
67
+ * entered the table.
68
+ *
69
+ * Three shapes, judged off the header alone:
70
+ * - subagent child (`origin === 'subagent'`): never enters the table — it
71
+ * borrows reachability from its ancestor chain.
72
+ * - fork (`parentSession` set, origin absent): an ORDINARY user-created
73
+ * session (its header has no subagent marker), so the auto-share knob
74
+ * applies to it exactly as to a top-level one, with the fork source as an
75
+ * extra path: shared when its source is accessible OR the knob is on.
76
+ * - top-level: shared only when the auto-share knob is on right now.
77
+ */
78
+ export declare function onSessionCreated(header: CreatedSessionHeaderLike | undefined | null, options: OnSessionCreatedOptions): boolean;
79
+ //# sourceMappingURL=share-ops.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"share-ops.d.ts","sourceRoot":"","sources":["../../src/share-ops.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAElD;;uEAEuE;AACvE,MAAM,WAAW,eAAe;IAC9B,EAAE,CAAC,EAAE,OAAO,CAAA;IACZ,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB;AAED;;2EAE2E;AAC3E,MAAM,WAAW,wBAAwB;IACvC,EAAE,CAAC,EAAE,OAAO,CAAA;IACZ,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,aAAa,CAAC,EAAE,OAAO,CAAA;CACxB;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,SAAS,eAAe,EAAE,GAAG,IAAI,CAiBjG;AAED,MAAM,WAAW,uBAAuB;IACtC,yDAAyD;IACzD,KAAK,EAAE,UAAU,CAAA;IACjB;kDAC8C;IAC9C,SAAS,EAAE,OAAO,CAAA;IAClB;0CACsC;IACtC,QAAQ,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAA;CAC7C;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,wBAAwB,GAAG,SAAS,GAAG,IAAI,EACnD,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAUT"}