@dsh-edge/dsh-edge-agent 0.0.0-stage → 0.1.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 (238) hide show
  1. package/CHANGELOG.md +142 -0
  2. package/LICENSE +21 -0
  3. package/README.md +372 -2
  4. package/config/edge.example.json +179 -0
  5. package/config/privacy-policy.json +202 -0
  6. package/cordis.desktop-safe.patch.yml +129 -0
  7. package/cordis.patch.yml +382 -0
  8. package/cordis.yml +374 -0
  9. package/lib/attestation.d.ts +2 -0
  10. package/lib/attestation.d.ts.map +1 -0
  11. package/lib/attestation.js +2 -0
  12. package/lib/audit-log.d.ts +2 -0
  13. package/lib/audit-log.d.ts.map +1 -0
  14. package/lib/audit-log.js +2 -0
  15. package/lib/client.js +87 -0
  16. package/lib/cloud-llm-adapter.d.ts +2 -0
  17. package/lib/cloud-llm-adapter.d.ts.map +1 -0
  18. package/lib/cloud-llm-adapter.js +2 -0
  19. package/lib/dsh-adapter/attestation.d.ts +42 -0
  20. package/lib/dsh-adapter/attestation.d.ts.map +1 -0
  21. package/lib/dsh-adapter/attestation.js +40 -0
  22. package/lib/dsh-adapter/audit-log.d.ts +139 -0
  23. package/lib/dsh-adapter/audit-log.d.ts.map +1 -0
  24. package/lib/dsh-adapter/audit-log.js +376 -0
  25. package/lib/dsh-adapter/cloud-egress.d.ts +181 -0
  26. package/lib/dsh-adapter/cloud-egress.d.ts.map +1 -0
  27. package/lib/dsh-adapter/cloud-egress.js +257 -0
  28. package/lib/dsh-adapter/cloud-llm-adapter.d.ts +416 -0
  29. package/lib/dsh-adapter/cloud-llm-adapter.d.ts.map +1 -0
  30. package/lib/dsh-adapter/cloud-llm-adapter.js +1472 -0
  31. package/lib/dsh-adapter/contract.d.ts +80 -0
  32. package/lib/dsh-adapter/contract.d.ts.map +1 -0
  33. package/lib/dsh-adapter/contract.js +194 -0
  34. package/lib/dsh-adapter/desktop-cookie-janitor.d.ts +214 -0
  35. package/lib/dsh-adapter/desktop-cookie-janitor.d.ts.map +1 -0
  36. package/lib/dsh-adapter/desktop-cookie-janitor.js +409 -0
  37. package/lib/dsh-adapter/dsh-edge-agent.d.ts +48 -0
  38. package/lib/dsh-adapter/dsh-edge-agent.d.ts.map +1 -0
  39. package/lib/dsh-adapter/dsh-edge-agent.js +64 -0
  40. package/lib/dsh-adapter/edge-config.d.ts +484 -0
  41. package/lib/dsh-adapter/edge-config.d.ts.map +1 -0
  42. package/lib/dsh-adapter/edge-config.js +898 -0
  43. package/lib/dsh-adapter/edge-context-view.d.ts +184 -0
  44. package/lib/dsh-adapter/edge-context-view.d.ts.map +1 -0
  45. package/lib/dsh-adapter/edge-context-view.js +483 -0
  46. package/lib/dsh-adapter/effective-model.d.ts +85 -0
  47. package/lib/dsh-adapter/effective-model.d.ts.map +1 -0
  48. package/lib/dsh-adapter/effective-model.js +171 -0
  49. package/lib/dsh-adapter/etscli-shell-guard.d.ts +244 -0
  50. package/lib/dsh-adapter/etscli-shell-guard.d.ts.map +1 -0
  51. package/lib/dsh-adapter/etscli-shell-guard.js +420 -0
  52. package/lib/dsh-adapter/etscli-tools.d.ts +112 -0
  53. package/lib/dsh-adapter/etscli-tools.d.ts.map +1 -0
  54. package/lib/dsh-adapter/etscli-tools.js +393 -0
  55. package/lib/dsh-adapter/file-logger.d.ts +294 -0
  56. package/lib/dsh-adapter/file-logger.d.ts.map +1 -0
  57. package/lib/dsh-adapter/file-logger.js +564 -0
  58. package/lib/dsh-adapter/function-call-external.d.ts +357 -0
  59. package/lib/dsh-adapter/function-call-external.d.ts.map +1 -0
  60. package/lib/dsh-adapter/function-call-external.js +1005 -0
  61. package/lib/dsh-adapter/host-egress-guard.d.ts +161 -0
  62. package/lib/dsh-adapter/host-egress-guard.d.ts.map +1 -0
  63. package/lib/dsh-adapter/host-egress-guard.js +213 -0
  64. package/lib/dsh-adapter/host-llm-trace.d.ts +198 -0
  65. package/lib/dsh-adapter/host-llm-trace.d.ts.map +1 -0
  66. package/lib/dsh-adapter/host-llm-trace.js +344 -0
  67. package/lib/dsh-adapter/http-api-routes.d.ts +61 -0
  68. package/lib/dsh-adapter/http-api-routes.d.ts.map +1 -0
  69. package/lib/dsh-adapter/http-api-routes.js +79 -0
  70. package/lib/dsh-adapter/http-api-sessions.d.ts +105 -0
  71. package/lib/dsh-adapter/http-api-sessions.d.ts.map +1 -0
  72. package/lib/dsh-adapter/http-api-sessions.js +173 -0
  73. package/lib/dsh-adapter/http-api.d.ts +221 -0
  74. package/lib/dsh-adapter/http-api.d.ts.map +1 -0
  75. package/lib/dsh-adapter/http-api.js +1811 -0
  76. package/lib/dsh-adapter/index.d.ts +62 -0
  77. package/lib/dsh-adapter/index.d.ts.map +1 -0
  78. package/lib/dsh-adapter/index.js +97 -0
  79. package/lib/dsh-adapter/input-guard-messages.d.ts +56 -0
  80. package/lib/dsh-adapter/input-guard-messages.d.ts.map +1 -0
  81. package/lib/dsh-adapter/input-guard-messages.js +136 -0
  82. package/lib/dsh-adapter/input-guard.d.ts +508 -0
  83. package/lib/dsh-adapter/input-guard.d.ts.map +1 -0
  84. package/lib/dsh-adapter/input-guard.js +2174 -0
  85. package/lib/dsh-adapter/intent-prompts.d.ts +77 -0
  86. package/lib/dsh-adapter/intent-prompts.d.ts.map +1 -0
  87. package/lib/dsh-adapter/intent-prompts.js +97 -0
  88. package/lib/dsh-adapter/intent-router.d.ts +710 -0
  89. package/lib/dsh-adapter/intent-router.d.ts.map +1 -0
  90. package/lib/dsh-adapter/intent-router.js +2802 -0
  91. package/lib/dsh-adapter/intent-signals.d.ts +208 -0
  92. package/lib/dsh-adapter/intent-signals.d.ts.map +1 -0
  93. package/lib/dsh-adapter/intent-signals.js +391 -0
  94. package/lib/dsh-adapter/invariant-install.d.ts +16 -0
  95. package/lib/dsh-adapter/invariant-install.d.ts.map +1 -0
  96. package/lib/dsh-adapter/invariant-install.js +15 -0
  97. package/lib/dsh-adapter/invariant.d.ts +16 -0
  98. package/lib/dsh-adapter/invariant.d.ts.map +1 -0
  99. package/lib/dsh-adapter/invariant.js +22 -0
  100. package/lib/dsh-adapter/llm-adapters.d.ts +19 -0
  101. package/lib/dsh-adapter/llm-adapters.d.ts.map +1 -0
  102. package/lib/dsh-adapter/llm-adapters.js +16 -0
  103. package/lib/dsh-adapter/llm-internal-caller.d.ts +92 -0
  104. package/lib/dsh-adapter/llm-internal-caller.d.ts.map +1 -0
  105. package/lib/dsh-adapter/llm-internal-caller.js +100 -0
  106. package/lib/dsh-adapter/llm-max-turns.d.ts +55 -0
  107. package/lib/dsh-adapter/llm-max-turns.d.ts.map +1 -0
  108. package/lib/dsh-adapter/llm-max-turns.js +127 -0
  109. package/lib/dsh-adapter/llm-trace-store.d.ts +131 -0
  110. package/lib/dsh-adapter/llm-trace-store.d.ts.map +1 -0
  111. package/lib/dsh-adapter/llm-trace-store.js +205 -0
  112. package/lib/dsh-adapter/llm-trace.d.ts +450 -0
  113. package/lib/dsh-adapter/llm-trace.d.ts.map +1 -0
  114. package/lib/dsh-adapter/llm-trace.js +463 -0
  115. package/lib/dsh-adapter/local-llm-adapter.d.ts +141 -0
  116. package/lib/dsh-adapter/local-llm-adapter.d.ts.map +1 -0
  117. package/lib/dsh-adapter/local-llm-adapter.js +787 -0
  118. package/lib/dsh-adapter/local-storage.d.ts +96 -0
  119. package/lib/dsh-adapter/local-storage.d.ts.map +1 -0
  120. package/lib/dsh-adapter/local-storage.js +198 -0
  121. package/lib/dsh-adapter/model-router.d.ts +79 -0
  122. package/lib/dsh-adapter/model-router.d.ts.map +1 -0
  123. package/lib/dsh-adapter/model-router.js +107 -0
  124. package/lib/dsh-adapter/ohttp-gateway.d.ts +49 -0
  125. package/lib/dsh-adapter/ohttp-gateway.d.ts.map +1 -0
  126. package/lib/dsh-adapter/ohttp-gateway.js +32 -0
  127. package/lib/dsh-adapter/openai-sse.d.ts +85 -0
  128. package/lib/dsh-adapter/openai-sse.d.ts.map +1 -0
  129. package/lib/dsh-adapter/openai-sse.js +462 -0
  130. package/lib/dsh-adapter/pii-utils.d.ts +96 -0
  131. package/lib/dsh-adapter/pii-utils.d.ts.map +1 -0
  132. package/lib/dsh-adapter/pii-utils.js +324 -0
  133. package/lib/dsh-adapter/plugin-host.d.ts +38 -0
  134. package/lib/dsh-adapter/plugin-host.d.ts.map +1 -0
  135. package/lib/dsh-adapter/plugin-host.js +38 -0
  136. package/lib/dsh-adapter/plugin.d.ts +46 -0
  137. package/lib/dsh-adapter/plugin.d.ts.map +1 -0
  138. package/lib/dsh-adapter/plugin.js +100 -0
  139. package/lib/dsh-adapter/privacy-policy.d.ts +237 -0
  140. package/lib/dsh-adapter/privacy-policy.d.ts.map +1 -0
  141. package/lib/dsh-adapter/privacy-policy.js +391 -0
  142. package/lib/dsh-adapter/prompt-guard.d.ts +152 -0
  143. package/lib/dsh-adapter/prompt-guard.d.ts.map +1 -0
  144. package/lib/dsh-adapter/prompt-guard.js +872 -0
  145. package/lib/dsh-adapter/realm-skill-bridge.d.ts +365 -0
  146. package/lib/dsh-adapter/realm-skill-bridge.d.ts.map +1 -0
  147. package/lib/dsh-adapter/realm-skill-bridge.js +1180 -0
  148. package/lib/dsh-adapter/sanitizer-pipeline.d.ts +140 -0
  149. package/lib/dsh-adapter/sanitizer-pipeline.d.ts.map +1 -0
  150. package/lib/dsh-adapter/sanitizer-pipeline.js +431 -0
  151. package/lib/dsh-adapter/secure-bridge.d.ts +47 -0
  152. package/lib/dsh-adapter/secure-bridge.d.ts.map +1 -0
  153. package/lib/dsh-adapter/secure-bridge.js +35 -0
  154. package/lib/dsh-adapter/session-attribution.d.ts +70 -0
  155. package/lib/dsh-adapter/session-attribution.d.ts.map +1 -0
  156. package/lib/dsh-adapter/session-attribution.js +76 -0
  157. package/lib/dsh-adapter/sessions.d.ts +86 -0
  158. package/lib/dsh-adapter/sessions.d.ts.map +1 -0
  159. package/lib/dsh-adapter/sessions.js +179 -0
  160. package/lib/dsh-adapter/tcm.d.ts +55 -0
  161. package/lib/dsh-adapter/tcm.d.ts.map +1 -0
  162. package/lib/dsh-adapter/tcm.js +94 -0
  163. package/lib/dsh-adapter/td-bus.d.ts +87 -0
  164. package/lib/dsh-adapter/td-bus.d.ts.map +1 -0
  165. package/lib/dsh-adapter/td-bus.js +196 -0
  166. package/lib/dsh-adapter/tool-runner.d.ts +185 -0
  167. package/lib/dsh-adapter/tool-runner.d.ts.map +1 -0
  168. package/lib/dsh-adapter/tool-runner.js +271 -0
  169. package/lib/dsh-adapter/tools.d.ts +118 -0
  170. package/lib/dsh-adapter/tools.d.ts.map +1 -0
  171. package/lib/dsh-adapter/tools.js +292 -0
  172. package/lib/dsh-adapter/types.d.ts +23 -0
  173. package/lib/dsh-adapter/types.d.ts.map +1 -0
  174. package/lib/dsh-adapter/types.js +16 -0
  175. package/lib/dsh-adapter/voice-input.d.ts +30 -0
  176. package/lib/dsh-adapter/voice-input.d.ts.map +1 -0
  177. package/lib/dsh-adapter/voice-input.js +34 -0
  178. package/lib/dsh-adapter/web-search-tavily-bocha.d.ts +152 -0
  179. package/lib/dsh-adapter/web-search-tavily-bocha.d.ts.map +1 -0
  180. package/lib/dsh-adapter/web-search-tavily-bocha.js +289 -0
  181. package/lib/http-api.d.ts +2 -0
  182. package/lib/http-api.d.ts.map +1 -0
  183. package/lib/http-api.js +2 -0
  184. package/lib/index.d.ts +48 -0
  185. package/lib/index.d.ts.map +1 -0
  186. package/lib/index.js +49 -0
  187. package/lib/intent-router.d.ts +2 -0
  188. package/lib/intent-router.d.ts.map +1 -0
  189. package/lib/intent-router.js +2 -0
  190. package/lib/llm-adapters.d.ts +2 -0
  191. package/lib/llm-adapters.d.ts.map +1 -0
  192. package/lib/llm-adapters.js +2 -0
  193. package/lib/local-llm-adapter.d.ts +2 -0
  194. package/lib/local-llm-adapter.d.ts.map +1 -0
  195. package/lib/local-llm-adapter.js +2 -0
  196. package/lib/local-storage.d.ts +2 -0
  197. package/lib/local-storage.d.ts.map +1 -0
  198. package/lib/local-storage.js +2 -0
  199. package/lib/model-router.d.ts +2 -0
  200. package/lib/model-router.d.ts.map +1 -0
  201. package/lib/model-router.js +2 -0
  202. package/lib/ohttp-gateway.d.ts +2 -0
  203. package/lib/ohttp-gateway.d.ts.map +1 -0
  204. package/lib/ohttp-gateway.js +2 -0
  205. package/lib/plugin-host.d.ts +2 -0
  206. package/lib/plugin-host.d.ts.map +1 -0
  207. package/lib/plugin-host.js +2 -0
  208. package/lib/privacy-policy.d.ts +2 -0
  209. package/lib/privacy-policy.d.ts.map +1 -0
  210. package/lib/privacy-policy.js +2 -0
  211. package/lib/prompt-guard.d.ts +2 -0
  212. package/lib/prompt-guard.d.ts.map +1 -0
  213. package/lib/prompt-guard.js +2 -0
  214. package/lib/sanitizer-pipeline.d.ts +2 -0
  215. package/lib/sanitizer-pipeline.d.ts.map +1 -0
  216. package/lib/sanitizer-pipeline.js +2 -0
  217. package/lib/secure-bridge.d.ts +2 -0
  218. package/lib/secure-bridge.d.ts.map +1 -0
  219. package/lib/secure-bridge.js +2 -0
  220. package/lib/sessions.d.ts +2 -0
  221. package/lib/sessions.d.ts.map +1 -0
  222. package/lib/sessions.js +2 -0
  223. package/lib/tcm.d.ts +2 -0
  224. package/lib/tcm.d.ts.map +1 -0
  225. package/lib/tcm.js +2 -0
  226. package/lib/td-bus.d.ts +2 -0
  227. package/lib/td-bus.d.ts.map +1 -0
  228. package/lib/td-bus.js +2 -0
  229. package/lib/tools.d.ts +2 -0
  230. package/lib/tools.d.ts.map +1 -0
  231. package/lib/tools.js +2 -0
  232. package/lib/voice-input.d.ts +2 -0
  233. package/lib/voice-input.d.ts.map +1 -0
  234. package/lib/voice-input.js +2 -0
  235. package/package.json +341 -3
  236. package/presets/agent-preset-edge.json +50 -0
  237. package/presets/edge.desktop-safe.patch.yml +503 -0
  238. package/presets/edge.patch.yml +557 -0
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Main plugin entry — wires the dsh-edge-agent package together as a single
3
+ * Cordis plugin that mounts the privacy stack into a host context.
4
+ *
5
+ * Plugin surface (consumer of `@deepseek-ai/*`):
6
+ * - name: 'dsh-edge-agent'
7
+ * - inject: NONE — this entry is only the bundle's host half bootstrap.
8
+ * apply() does NOT depend on `agents`/`llm`/`tools`/`sessions`/`invariants`
9
+ * at the bundle top level. Each subordinate plugin declares its own
10
+ * inject in its own file (e.g. `audit-log`, `intent-router`, ...).
11
+ * Declaring deps here used to force cordis 0.2.1-rc.2 to hang pending
12
+ * `invariants` (which the desktop webui profile does not provide) —
13
+ * documented in docs/dev-notes/cordis-rc021-patch-loader.md.
14
+ * - Config: full schemastery schema (matches cordis.yml row)
15
+ * - apply: bootstraps the privacy stack and exposes sub-plugin
16
+ * re-exports so the package root can be loaded as a single Cordis
17
+ * plugin that mounts every sub-plugin via its own cordis.yml row.
18
+ */
19
+ import type { Context } from '@deepseek-ai/cordis';
20
+ import Schema from '@deepseek-ai/schemastery';
21
+ export declare const name = "dsh-edge-agent";
22
+ export declare const inject: readonly [];
23
+ export interface Config {
24
+ /** TEE backend preference. Platform-dependent; auto-detected when omitted. */
25
+ teeType?: 'simulated' | 'trustzone' | 'keystone' | 'sgx';
26
+ /** Path to the encrypted storage root. */
27
+ storageRoot?: string;
28
+ /** Privacy policy file path. Hot-reloaded on change. */
29
+ policyPath?: string;
30
+ /** Default privacy posture when the policy engine cannot classify. */
31
+ defaultDataLevel?: 'public' | 'sanitized' | 'internal';
32
+ /** Allow outbound OHTTP requests even when the relay is unreachable. */
33
+ allowFallbackTls?: boolean;
34
+ /** Number of recent turns to keep in the conversation slice. */
35
+ sessionWindowSize?: number;
36
+ }
37
+ export declare const Config: Schema<Config>;
38
+ export declare function apply(ctx: Context, config: Config): Promise<() => Promise<void>>;
39
+ export * from './tcm.js';
40
+ export * from './local-storage.js';
41
+ export * from './sessions.js';
42
+ export * from './audit-log.js';
43
+ export * from './privacy-policy.js';
44
+ export * from './tools.js';
45
+ export * from './realm-skill-bridge.js';
46
+ export * from './prompt-guard.js';
47
+ export * from './intent-router.js';
48
+ export * from './model-router.js';
49
+ export * from './local-llm-adapter.js';
50
+ export * from './cloud-llm-adapter.js';
51
+ export * from './sanitizer-pipeline.js';
52
+ export * from './ohttp-gateway.js';
53
+ export * from './secure-bridge.js';
54
+ export * from './attestation.js';
55
+ export * from './td-bus.js';
56
+ export * from './voice-input.js';
57
+ export * from './plugin-host.js';
58
+ export { name as httpApiName, inject as httpApiInject, Config as HttpApiConfig, HttpApiServiceImpl, apply as httpApiApply } from './http-api.js';
59
+ export type { HttpApiService } from './http-api.js';
60
+ export * from './llm-adapters.js';
61
+ export * from './edge-context-view.js';
62
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/dsh-adapter/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,MAAM,MAAM,0BAA0B,CAAA;AAE7C,eAAO,MAAM,IAAI,mBAAmB,CAAA;AAOpC,eAAO,MAAM,MAAM,aAAc,CAAA;AAEjC,MAAM,WAAW,MAAM;IACrB,8EAA8E;IAC9E,OAAO,CAAC,EAAE,WAAW,GAAG,WAAW,GAAG,UAAU,GAAG,KAAK,CAAA;IACxD,0CAA0C;IAC1C,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,wDAAwD;IACxD,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,sEAAsE;IACtE,gBAAgB,CAAC,EAAE,QAAQ,GAAG,WAAW,GAAG,UAAU,CAAA;IACtD,wEAAwE;IACxE,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B,gEAAgE;IAChE,iBAAiB,CAAC,EAAE,MAAM,CAAA;CAC3B;AAED,eAAO,MAAM,MAAM,EAAE,MAAM,CAAC,MAAM,CAahC,CAAA;AAEF,wBAAsB,KAAK,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,CAyBtF;AAKD,cAAc,UAAU,CAAA;AACxB,cAAc,oBAAoB,CAAA;AAClC,cAAc,eAAe,CAAA;AAC7B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,qBAAqB,CAAA;AACnC,cAAc,YAAY,CAAA;AAC1B,cAAc,yBAAyB,CAAA;AACvC,cAAc,mBAAmB,CAAA;AACjC,cAAc,oBAAoB,CAAA;AAClC,cAAc,mBAAmB,CAAA;AACjC,cAAc,wBAAwB,CAAA;AACtC,cAAc,wBAAwB,CAAA;AACtC,cAAc,yBAAyB,CAAA;AACvC,cAAc,oBAAoB,CAAA;AAClC,cAAc,oBAAoB,CAAA;AAClC,cAAc,kBAAkB,CAAA;AAChC,cAAc,aAAa,CAAA;AAC3B,cAAc,kBAAkB,CAAA;AAChC,cAAc,kBAAkB,CAAA;AAIhC,OAAO,EAAE,IAAI,IAAI,WAAW,EAAE,MAAM,IAAI,aAAa,EAAE,MAAM,IAAI,aAAa,EAAE,kBAAkB,EAAE,KAAK,IAAI,YAAY,EAAE,MAAM,eAAe,CAAA;AAIhJ,YAAY,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AACnD,cAAc,mBAAmB,CAAA;AAMjC,cAAc,wBAAwB,CAAA"}
@@ -0,0 +1,97 @@
1
+ /**
2
+ * Main plugin entry — wires the dsh-edge-agent package together as a single
3
+ * Cordis plugin that mounts the privacy stack into a host context.
4
+ *
5
+ * Plugin surface (consumer of `@deepseek-ai/*`):
6
+ * - name: 'dsh-edge-agent'
7
+ * - inject: NONE — this entry is only the bundle's host half bootstrap.
8
+ * apply() does NOT depend on `agents`/`llm`/`tools`/`sessions`/`invariants`
9
+ * at the bundle top level. Each subordinate plugin declares its own
10
+ * inject in its own file (e.g. `audit-log`, `intent-router`, ...).
11
+ * Declaring deps here used to force cordis 0.2.1-rc.2 to hang pending
12
+ * `invariants` (which the desktop webui profile does not provide) —
13
+ * documented in docs/dev-notes/cordis-rc021-patch-loader.md.
14
+ * - Config: full schemastery schema (matches cordis.yml row)
15
+ * - apply: bootstraps the privacy stack and exposes sub-plugin
16
+ * re-exports so the package root can be loaded as a single Cordis
17
+ * plugin that mounts every sub-plugin via its own cordis.yml row.
18
+ */
19
+ import Schema from '@deepseek-ai/schemastery';
20
+ export const name = 'dsh-edge-agent';
21
+ // Empty inject — see above. Subordinate plugins each declare their own
22
+ // deps in their own .ts files; the bundle's host-half bootstrap does
23
+ // not need any service to start. Mirrors dsh-context's pattern (its
24
+ // inject is `['sessionProjections']` because it does need a projection
25
+ // store; ours does not because we install our own ring buffer).
26
+ export const inject = [];
27
+ export const Config = Schema.object({
28
+ teeType: Schema.union([
29
+ 'simulated',
30
+ 'trustzone',
31
+ 'keystone',
32
+ 'sgx',
33
+ ]).description('TEE backend preference; auto-detected when omitted.'),
34
+ storageRoot: Schema.string().description('Path to the encrypted storage root (resolved at runtime).'),
35
+ policyPath: Schema.string().description('Privacy policy file path. Hot-reloaded on change.'),
36
+ defaultDataLevel: Schema.union(['public', 'sanitized', 'internal'])
37
+ .description('Default privacy posture when the policy engine cannot classify.'),
38
+ allowFallbackTls: Schema.boolean().description('Allow outbound OHTTP requests even when the relay is unreachable.'),
39
+ sessionWindowSize: Schema.natural().description('Number of recent turns to keep in the conversation slice.'),
40
+ });
41
+ export async function apply(ctx, config) {
42
+ // 0. Install the file-logger exporter (see ./file-logger.ts).
43
+ //
44
+ // All dsh-edge-agent plugins log through `ctx.logger.*`; without an
45
+ // external exporter those calls only land in Cordis's 1000-entry
46
+ // in-memory ring buffer and are lost on exit. We register a file
47
+ // exporter here, BEFORE any other plugin can call `ctx.logger.*` so
48
+ // the drift warning (next step) and every boot diagnostic land on
49
+ // disk. See `./file-logger.ts` for the persistence + rotation logic.
50
+ //
51
+ // - Gated by DSH_EDGE_LOG_FILE !== 'false' (default ON; tests opt out).
52
+ // - "First-wins" guard: if the DSH host already registered its own
53
+ // file exporter, ours would double-write — skip instead.
54
+ const { installFileLogger } = await import('./file-logger.js');
55
+ installFileLogger(ctx);
56
+ // 1. Drift check — warn at boot when upstream DSH has moved.
57
+ const { upstreamDrift } = await import('./contract.js');
58
+ for (const entry of await upstreamDrift()) {
59
+ ctx.logger?.warn?.(`[dsh-edge-agent] upstream drift: ${entry.pkg} has ${entry.installed} (expected ${entry.expected})`);
60
+ }
61
+ // 2. Delegate to the real implementation under plugin.ts.
62
+ const { apply: bootstrap } = await import('./plugin.js');
63
+ return bootstrap(ctx, config);
64
+ }
65
+ // Convenience: re-export the canonical subpath plugins so that consumers
66
+ // who `import '@dsh-edge/dsh-edge-agent'` can also
67
+ // pull individual cordis rows out of the same module.
68
+ export * from './tcm.js';
69
+ export * from './local-storage.js';
70
+ export * from './sessions.js';
71
+ export * from './audit-log.js';
72
+ export * from './privacy-policy.js';
73
+ export * from './tools.js';
74
+ export * from './realm-skill-bridge.js';
75
+ export * from './prompt-guard.js';
76
+ export * from './intent-router.js';
77
+ export * from './model-router.js';
78
+ export * from './local-llm-adapter.js';
79
+ export * from './cloud-llm-adapter.js';
80
+ export * from './sanitizer-pipeline.js';
81
+ export * from './ohttp-gateway.js';
82
+ export * from './secure-bridge.js';
83
+ export * from './attestation.js';
84
+ export * from './td-bus.js';
85
+ export * from './voice-input.js';
86
+ export * from './plugin-host.js';
87
+ // http-api re-exports: skip `resolveRoute` — it collides with the canonical
88
+ // `resolveRoute` from model-router.js (TS2308). http-api's local copy is only
89
+ // exported for unit tests; consumers should use model-router's version.
90
+ export { name as httpApiName, inject as httpApiInject, Config as HttpApiConfig, HttpApiServiceImpl, apply as httpApiApply } from './http-api.js';
91
+ export * from './llm-adapters.js';
92
+ // §7.101 v5: re-export edge-context-view so it is reachable from the package
93
+ // root (`@dsh-edge/dsh-edge-agent`). The cordis patch row
94
+ // in cordis.desktop-safe.patch.yml points at this name (bare package name,
95
+ // matching dsh-context's pattern); without this re-export the package root
96
+ // has no apply() for the host plugin and Edge tab remains invisible.
97
+ export * from './edge-context-view.js';
@@ -0,0 +1,56 @@
1
+ /**
2
+ * input-guard-messages — message-array helpers for the input guard.
3
+ *
4
+ * §7.123 (2026-10-27): these helpers lived at the bottom of
5
+ * `input-guard.ts` (2086 lines) inside the same file as the hook logic.
6
+ * They are pure functions over the agent's `messages` array — the part of
7
+ * the module that most benefits from being readable (and unit-testable) on
8
+ * its own, because the agent loop's message shape is the thing that keeps
9
+ * changing upstream.
10
+ *
11
+ * The contract they encode:
12
+ * - `payload.messages` holds the REAL user turns;
13
+ * - `decision.messages` may carry EXTRA synthetic user-role runtime
14
+ * context appended by dsh-agent-instructions — that is NOT user
15
+ * content and must never be rewritten;
16
+ * - so rewriting is driven by indices collected from `payload.messages`.
17
+ *
18
+ * @module dsh-edge-agent/input-guard-messages
19
+ */
20
+ /** Find the last user message with non-empty text content. */
21
+ export declare function findLastUserText(messages: ReadonlyArray<Record<string, unknown>>): {
22
+ text: string;
23
+ index: number;
24
+ } | undefined;
25
+ /** Replace the last user message's text (immutable — returns a new array). */
26
+ export declare function replaceLastUserText(messages: ReadonlyArray<Record<string, unknown>>, newText: string): Array<Record<string, unknown>>;
27
+ /**
28
+ * Replace the text of the message at `index` (immutable — returns a new array).
29
+ *
30
+ * Used when dsh-agent-instructions appends content at the end of
31
+ * `decision.messages` and we still want to rewrite the ORIGINAL user
32
+ * message (whose index came from `payload.messages`).
33
+ */
34
+ export declare function replaceAtUserIndex(messages: ReadonlyArray<Record<string, unknown>>, index: number, newText: string): Array<Record<string, unknown>>;
35
+ /**
36
+ * Collect EVERY user message in the ORIGINAL payload.
37
+ *
38
+ * §7.123 (2026-10-27): the previous code only ever sanitized the LAST user
39
+ * message. That is a data-egress hole: the agent loop sends the whole
40
+ * conversation to the model, so a phone number the user typed in turn 1 rode
41
+ * along in `messages` history on every later cloud turn — unredacted. The
42
+ * sanitizer is session-scoped, so the same value across turns maps to the
43
+ * same placeholder; the leak was purely "we only rewrote index N".
44
+ *
45
+ * Only messages from `payload.messages` are considered — NOT
46
+ * `decision.messages`, because dsh-agent-instructions appends synthetic
47
+ * user-role runtime context there (a system-injected run context, not user
48
+ * content).
49
+ */
50
+ export declare function findUserTexts(messages: ReadonlyArray<Record<string, unknown>>): Array<{
51
+ text: string;
52
+ index: number;
53
+ }>;
54
+ /** Apply a per-index text replacement map to a messages array (immutable). */
55
+ export declare function replaceUserTextsAt(messages: ReadonlyArray<Record<string, unknown>>, replacements: ReadonlyMap<number, string>): Array<Record<string, unknown>>;
56
+ //# sourceMappingURL=input-guard-messages.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"input-guard-messages.d.ts","sourceRoot":"","sources":["../../src/dsh-adapter/input-guard-messages.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,8DAA8D;AAC9D,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,aAAa,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAC/C;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CAoB7C;AAED,8EAA8E;AAC9E,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,aAAa,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EAChD,OAAO,EAAE,MAAM,GACd,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAIhC;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,aAAa,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EAChD,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,MAAM,GACd,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CA0BhC;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,aAAa,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAC/C,KAAK,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC,CAsBxC;AAED,8EAA8E;AAC9E,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,aAAa,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EAChD,YAAY,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,GACxC,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAMhC"}
@@ -0,0 +1,136 @@
1
+ /**
2
+ * input-guard-messages — message-array helpers for the input guard.
3
+ *
4
+ * §7.123 (2026-10-27): these helpers lived at the bottom of
5
+ * `input-guard.ts` (2086 lines) inside the same file as the hook logic.
6
+ * They are pure functions over the agent's `messages` array — the part of
7
+ * the module that most benefits from being readable (and unit-testable) on
8
+ * its own, because the agent loop's message shape is the thing that keeps
9
+ * changing upstream.
10
+ *
11
+ * The contract they encode:
12
+ * - `payload.messages` holds the REAL user turns;
13
+ * - `decision.messages` may carry EXTRA synthetic user-role runtime
14
+ * context appended by dsh-agent-instructions — that is NOT user
15
+ * content and must never be rewritten;
16
+ * - so rewriting is driven by indices collected from `payload.messages`.
17
+ *
18
+ * @module dsh-edge-agent/input-guard-messages
19
+ */
20
+ /** Find the last user message with non-empty text content. */
21
+ export function findLastUserText(messages) {
22
+ for (let i = messages.length - 1; i >= 0; i--) {
23
+ const m = messages[i];
24
+ if (m?.role !== 'user')
25
+ continue;
26
+ const content = m.content;
27
+ if (typeof content === 'string' && content.length > 0) {
28
+ return { text: content, index: i };
29
+ }
30
+ if (Array.isArray(content)) {
31
+ const texts = [];
32
+ for (const block of content) {
33
+ if (block && typeof block === 'object' && block.type === 'text' && typeof block.text === 'string') {
34
+ texts.push(block.text);
35
+ }
36
+ }
37
+ const joined = texts.join('');
38
+ if (joined.length > 0)
39
+ return { text: joined, index: i };
40
+ }
41
+ }
42
+ return undefined;
43
+ }
44
+ /** Replace the last user message's text (immutable — returns a new array). */
45
+ export function replaceLastUserText(messages, newText) {
46
+ const found = findLastUserText(messages);
47
+ if (!found)
48
+ return [...messages];
49
+ return replaceAtUserIndex(messages, found.index, newText);
50
+ }
51
+ /**
52
+ * Replace the text of the message at `index` (immutable — returns a new array).
53
+ *
54
+ * Used when dsh-agent-instructions appends content at the end of
55
+ * `decision.messages` and we still want to rewrite the ORIGINAL user
56
+ * message (whose index came from `payload.messages`).
57
+ */
58
+ export function replaceAtUserIndex(messages, index, newText) {
59
+ if (index < 0 || index >= messages.length)
60
+ return [...messages];
61
+ const result = [...messages];
62
+ const original = result[index];
63
+ const originalContent = original.content;
64
+ if (typeof originalContent === 'string') {
65
+ result[index] = { ...original, content: newText };
66
+ }
67
+ else if (Array.isArray(originalContent)) {
68
+ // 替换所有 text block 为单个合并的 text block
69
+ const newContent = [];
70
+ let replaced = false;
71
+ for (const block of originalContent) {
72
+ if (block && typeof block === 'object' && block.type === 'text') {
73
+ if (!replaced) {
74
+ newContent.push({ type: 'text', text: newText });
75
+ replaced = true;
76
+ }
77
+ // 后续 text block 丢弃(已合并到 newText)
78
+ }
79
+ else {
80
+ newContent.push(block);
81
+ }
82
+ }
83
+ if (!replaced)
84
+ newContent.unshift({ type: 'text', text: newText });
85
+ result[index] = { ...original, content: newContent };
86
+ }
87
+ return result;
88
+ }
89
+ /**
90
+ * Collect EVERY user message in the ORIGINAL payload.
91
+ *
92
+ * §7.123 (2026-10-27): the previous code only ever sanitized the LAST user
93
+ * message. That is a data-egress hole: the agent loop sends the whole
94
+ * conversation to the model, so a phone number the user typed in turn 1 rode
95
+ * along in `messages` history on every later cloud turn — unredacted. The
96
+ * sanitizer is session-scoped, so the same value across turns maps to the
97
+ * same placeholder; the leak was purely "we only rewrote index N".
98
+ *
99
+ * Only messages from `payload.messages` are considered — NOT
100
+ * `decision.messages`, because dsh-agent-instructions appends synthetic
101
+ * user-role runtime context there (a system-injected run context, not user
102
+ * content).
103
+ */
104
+ export function findUserTexts(messages) {
105
+ const out = [];
106
+ for (let i = 0; i < messages.length; i++) {
107
+ const m = messages[i];
108
+ if (m?.role !== 'user')
109
+ continue;
110
+ const content = m.content;
111
+ if (typeof content === 'string' && content.length > 0) {
112
+ out.push({ text: content, index: i });
113
+ continue;
114
+ }
115
+ if (Array.isArray(content)) {
116
+ const texts = [];
117
+ for (const block of content) {
118
+ if (block && typeof block === 'object' && block.type === 'text' && typeof block.text === 'string') {
119
+ texts.push(block.text);
120
+ }
121
+ }
122
+ const joined = texts.join('');
123
+ if (joined.length > 0)
124
+ out.push({ text: joined, index: i });
125
+ }
126
+ }
127
+ return out;
128
+ }
129
+ /** Apply a per-index text replacement map to a messages array (immutable). */
130
+ export function replaceUserTextsAt(messages, replacements) {
131
+ let result;
132
+ for (const [index, text] of replacements) {
133
+ result = replaceAtUserIndex(result ?? messages, index, text);
134
+ }
135
+ return result ?? [...messages];
136
+ }