@try-works/dsh-model-as-tool 0.1.2 → 0.3.6

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 (267) hide show
  1. package/bin/dsh-tool-mode-credentials.mjs +20 -0
  2. package/bin/dsh-tool-mode.mjs +202 -0
  3. package/catalog/desert-ant-models.json +693 -693
  4. package/client/client.model-tools.js +592 -0
  5. package/client/index.js +1679 -0
  6. package/lib/adapters/index.d.ts.map +1 -1
  7. package/lib/adapters/index.js +4 -4
  8. package/lib/bindings.d.ts.map +1 -1
  9. package/lib/bindings.js +26 -25
  10. package/lib/capability.d.ts.map +1 -1
  11. package/lib/capability.js +17 -0
  12. package/lib/capture-path.d.ts +97 -0
  13. package/lib/capture-path.d.ts.map +1 -0
  14. package/lib/capture-path.js +152 -0
  15. package/lib/diagnostics.d.ts +166 -0
  16. package/lib/diagnostics.d.ts.map +1 -0
  17. package/lib/diagnostics.js +135 -0
  18. package/lib/extension-dependencies.d.ts +197 -0
  19. package/lib/extension-dependencies.d.ts.map +1 -0
  20. package/lib/extension-dependencies.js +369 -0
  21. package/lib/extension-dispatch.d.ts +117 -0
  22. package/lib/extension-dispatch.d.ts.map +1 -0
  23. package/lib/extension-dispatch.js +124 -0
  24. package/lib/extension-registrar.d.ts +100 -0
  25. package/lib/extension-registrar.d.ts.map +1 -0
  26. package/lib/extension-registrar.js +134 -0
  27. package/lib/extensions-api.d.ts +217 -0
  28. package/lib/extensions-api.d.ts.map +1 -0
  29. package/lib/extensions-api.js +17 -0
  30. package/lib/extensions-remote.d.ts +54 -0
  31. package/lib/extensions-remote.d.ts.map +1 -0
  32. package/lib/extensions-remote.js +66 -0
  33. package/lib/extensions-service.d.ts +334 -0
  34. package/lib/extensions-service.d.ts.map +1 -0
  35. package/lib/extensions-service.js +1351 -0
  36. package/lib/harness-llm.d.ts +138 -0
  37. package/lib/harness-llm.d.ts.map +1 -0
  38. package/lib/harness-llm.js +218 -0
  39. package/lib/harness-serving.d.ts +95 -0
  40. package/lib/harness-serving.d.ts.map +1 -0
  41. package/lib/harness-serving.js +157 -0
  42. package/lib/headless.d.ts +97 -0
  43. package/lib/headless.d.ts.map +1 -0
  44. package/lib/headless.js +349 -0
  45. package/lib/http-acquisition.d.ts +27 -0
  46. package/lib/http-acquisition.d.ts.map +1 -0
  47. package/lib/http-acquisition.js +136 -0
  48. package/lib/index.d.ts +250 -7
  49. package/lib/index.d.ts.map +1 -1
  50. package/lib/index.js +2625 -70
  51. package/lib/invocation-accounting.d.ts +169 -0
  52. package/lib/invocation-accounting.d.ts.map +1 -0
  53. package/lib/invocation-accounting.js +148 -0
  54. package/lib/legacy-migration.d.ts +95 -0
  55. package/lib/legacy-migration.d.ts.map +1 -0
  56. package/lib/legacy-migration.js +429 -0
  57. package/lib/managed-workers.d.ts +151 -0
  58. package/lib/managed-workers.d.ts.map +1 -0
  59. package/lib/managed-workers.js +249 -0
  60. package/lib/mcp/client-grant.d.ts +74 -0
  61. package/lib/mcp/client-grant.d.ts.map +1 -0
  62. package/lib/mcp/client-grant.js +60 -0
  63. package/lib/mcp/credential-cli.d.ts +38 -0
  64. package/lib/mcp/credential-cli.d.ts.map +1 -0
  65. package/lib/mcp/credential-cli.js +148 -0
  66. package/lib/mcp/credential-store.d.ts +143 -0
  67. package/lib/mcp/credential-store.d.ts.map +1 -0
  68. package/lib/mcp/credential-store.js +454 -0
  69. package/lib/mcp/host-binding.d.ts +25 -0
  70. package/lib/mcp/host-binding.d.ts.map +1 -1
  71. package/lib/mcp/host-binding.js +107 -14
  72. package/lib/mcp/http.d.ts +68 -18
  73. package/lib/mcp/http.d.ts.map +1 -1
  74. package/lib/mcp/http.js +390 -62
  75. package/lib/mcp/oauth.d.ts +149 -0
  76. package/lib/mcp/oauth.d.ts.map +1 -0
  77. package/lib/mcp/oauth.js +396 -0
  78. package/lib/mcp/protocol.d.ts +46 -7
  79. package/lib/mcp/protocol.d.ts.map +1 -1
  80. package/lib/mcp/protocol.js +63 -16
  81. package/lib/mcp/rate-limit.d.ts +68 -0
  82. package/lib/mcp/rate-limit.d.ts.map +1 -0
  83. package/lib/mcp/rate-limit.js +114 -0
  84. package/lib/mcp/sdk-v2.d.ts +17 -0
  85. package/lib/mcp/sdk-v2.d.ts.map +1 -0
  86. package/lib/mcp/sdk-v2.js +181 -0
  87. package/lib/mcp/server.d.ts +11 -1
  88. package/lib/mcp/server.d.ts.map +1 -1
  89. package/lib/mcp/server.js +80 -13
  90. package/lib/mcp/stdio.d.ts.map +1 -1
  91. package/lib/mcp/stdio.js +9 -1
  92. package/lib/mcp/subscriptions.d.ts +43 -1
  93. package/lib/mcp/subscriptions.d.ts.map +1 -1
  94. package/lib/mcp/subscriptions.js +90 -9
  95. package/lib/model-qualification.d.ts +192 -0
  96. package/lib/model-qualification.d.ts.map +1 -0
  97. package/lib/model-qualification.js +178 -0
  98. package/lib/planning.d.ts +246 -0
  99. package/lib/planning.d.ts.map +1 -0
  100. package/lib/planning.js +457 -0
  101. package/lib/prepared-assets.d.ts +178 -0
  102. package/lib/prepared-assets.d.ts.map +1 -0
  103. package/lib/prepared-assets.js +286 -0
  104. package/lib/provider-bridge.d.ts +37 -0
  105. package/lib/provider-bridge.d.ts.map +1 -1
  106. package/lib/provider-bridge.js +189 -12
  107. package/lib/ptc-authority.d.ts +140 -0
  108. package/lib/ptc-authority.d.ts.map +1 -0
  109. package/lib/ptc-authority.js +216 -0
  110. package/lib/ptc-runtime.d.ts +156 -0
  111. package/lib/ptc-runtime.d.ts.map +1 -0
  112. package/lib/ptc-runtime.js +191 -0
  113. package/lib/publication.d.ts +2 -1
  114. package/lib/publication.d.ts.map +1 -1
  115. package/lib/publication.js +13 -5
  116. package/lib/receipt.d.ts.map +1 -1
  117. package/lib/receipt.js +8 -0
  118. package/lib/title-proposal.d.ts +194 -0
  119. package/lib/title-proposal.d.ts.map +1 -0
  120. package/lib/title-proposal.js +244 -0
  121. package/lib/tool-mode-run.d.ts +235 -0
  122. package/lib/tool-mode-run.d.ts.map +1 -0
  123. package/lib/tool-mode-run.js +283 -0
  124. package/lib/types.d.ts +3 -1
  125. package/lib/types.d.ts.map +1 -1
  126. package/lib/update-surface.d.ts +79 -0
  127. package/lib/update-surface.d.ts.map +1 -0
  128. package/lib/update-surface.js +224 -0
  129. package/node_modules/@try-works/tool-mode-contracts/lib/contracts/lang-detect.d.ts +16 -0
  130. package/node_modules/@try-works/tool-mode-contracts/lib/contracts/lang-detect.d.ts.map +1 -0
  131. package/node_modules/@try-works/tool-mode-contracts/lib/contracts/lang-detect.js +85 -0
  132. package/node_modules/@try-works/tool-mode-contracts/lib/contracts/standard.d.ts +38 -0
  133. package/node_modules/@try-works/tool-mode-contracts/lib/contracts/standard.d.ts.map +1 -0
  134. package/node_modules/@try-works/tool-mode-contracts/lib/contracts/standard.js +445 -0
  135. package/node_modules/@try-works/tool-mode-contracts/lib/contracts/stt-transcribe.d.ts +20 -0
  136. package/node_modules/@try-works/tool-mode-contracts/lib/contracts/stt-transcribe.d.ts.map +1 -0
  137. package/node_modules/@try-works/tool-mode-contracts/lib/contracts/stt-transcribe.js +112 -0
  138. package/node_modules/@try-works/tool-mode-contracts/lib/contracts/text-embed.d.ts +14 -0
  139. package/node_modules/@try-works/tool-mode-contracts/lib/contracts/text-embed.d.ts.map +1 -0
  140. package/node_modules/@try-works/tool-mode-contracts/lib/contracts/text-embed.js +63 -0
  141. package/node_modules/@try-works/tool-mode-contracts/lib/contracts/text-rerank.d.ts +14 -0
  142. package/node_modules/@try-works/tool-mode-contracts/lib/contracts/text-rerank.d.ts.map +1 -0
  143. package/node_modules/@try-works/tool-mode-contracts/lib/contracts/text-rerank.js +76 -0
  144. package/node_modules/@try-works/tool-mode-contracts/lib/dsh.d.ts +82 -0
  145. package/node_modules/@try-works/tool-mode-contracts/lib/dsh.d.ts.map +1 -0
  146. package/node_modules/@try-works/tool-mode-contracts/lib/dsh.js +274 -0
  147. package/node_modules/@try-works/tool-mode-contracts/lib/index.d.ts +26 -0
  148. package/node_modules/@try-works/tool-mode-contracts/lib/index.d.ts.map +1 -0
  149. package/node_modules/@try-works/tool-mode-contracts/lib/index.js +48 -0
  150. package/node_modules/@try-works/tool-mode-contracts/lib/meta.d.ts +104 -0
  151. package/node_modules/@try-works/tool-mode-contracts/lib/meta.d.ts.map +1 -0
  152. package/node_modules/@try-works/tool-mode-contracts/lib/meta.js +55 -0
  153. package/node_modules/@try-works/tool-mode-contracts/lib/registry.d.ts +107 -0
  154. package/node_modules/@try-works/tool-mode-contracts/lib/registry.d.ts.map +1 -0
  155. package/node_modules/@try-works/tool-mode-contracts/lib/registry.js +246 -0
  156. package/node_modules/@try-works/tool-mode-contracts/package.json +34 -0
  157. package/node_modules/@try-works/tool-mode-extension-sdk/bin/dsh-tool-mode.mjs +20 -0
  158. package/node_modules/@try-works/tool-mode-extension-sdk/lib/cli.d.ts +80 -0
  159. package/node_modules/@try-works/tool-mode-extension-sdk/lib/cli.d.ts.map +1 -0
  160. package/node_modules/@try-works/tool-mode-extension-sdk/lib/cli.js +533 -0
  161. package/node_modules/@try-works/tool-mode-extension-sdk/lib/declarative-recipes.d.ts +83 -0
  162. package/node_modules/@try-works/tool-mode-extension-sdk/lib/declarative-recipes.d.ts.map +1 -0
  163. package/node_modules/@try-works/tool-mode-extension-sdk/lib/declarative-recipes.js +125 -0
  164. package/node_modules/@try-works/tool-mode-extension-sdk/lib/discovery.d.ts +70 -0
  165. package/node_modules/@try-works/tool-mode-extension-sdk/lib/discovery.d.ts.map +1 -0
  166. package/node_modules/@try-works/tool-mode-extension-sdk/lib/discovery.js +201 -0
  167. package/node_modules/@try-works/tool-mode-extension-sdk/lib/errors.d.ts +57 -0
  168. package/node_modules/@try-works/tool-mode-extension-sdk/lib/errors.d.ts.map +1 -0
  169. package/node_modules/@try-works/tool-mode-extension-sdk/lib/errors.js +83 -0
  170. package/node_modules/@try-works/tool-mode-extension-sdk/lib/index.d.ts +31 -0
  171. package/node_modules/@try-works/tool-mode-extension-sdk/lib/index.d.ts.map +1 -0
  172. package/node_modules/@try-works/tool-mode-extension-sdk/lib/index.js +31 -0
  173. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/archive.d.ts +86 -0
  174. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/archive.d.ts.map +1 -0
  175. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/archive.js +185 -0
  176. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/dependencies.d.ts +126 -0
  177. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/dependencies.d.ts.map +1 -0
  178. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/dependencies.js +297 -0
  179. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/lifecycle.d.ts +216 -0
  180. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/lifecycle.d.ts.map +1 -0
  181. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/lifecycle.js +800 -0
  182. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/migration.d.ts +210 -0
  183. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/migration.d.ts.map +1 -0
  184. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/migration.js +368 -0
  185. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/runtime-link.d.ts +63 -0
  186. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/runtime-link.d.ts.map +1 -0
  187. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/runtime-link.js +149 -0
  188. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/source-directory.d.ts +35 -0
  189. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/source-directory.d.ts.map +1 -0
  190. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/source-directory.js +179 -0
  191. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/staged.d.ts +179 -0
  192. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/staged.d.ts.map +1 -0
  193. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/staged.js +235 -0
  194. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/store.d.ts +367 -0
  195. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/store.d.ts.map +1 -0
  196. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/store.js +807 -0
  197. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/update-flow.d.ts +185 -0
  198. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/update-flow.d.ts.map +1 -0
  199. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/update-flow.js +504 -0
  200. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/zip-source.d.ts +17 -0
  201. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/zip-source.d.ts.map +1 -0
  202. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/zip-source.js +80 -0
  203. package/node_modules/@try-works/tool-mode-extension-sdk/lib/load.d.ts +52 -0
  204. package/node_modules/@try-works/tool-mode-extension-sdk/lib/load.d.ts.map +1 -0
  205. package/node_modules/@try-works/tool-mode-extension-sdk/lib/load.js +102 -0
  206. package/node_modules/@try-works/tool-mode-extension-sdk/lib/manifest.d.ts +171 -0
  207. package/node_modules/@try-works/tool-mode-extension-sdk/lib/manifest.d.ts.map +1 -0
  208. package/node_modules/@try-works/tool-mode-extension-sdk/lib/manifest.js +271 -0
  209. package/node_modules/@try-works/tool-mode-extension-sdk/lib/runtime.d.ts +242 -0
  210. package/node_modules/@try-works/tool-mode-extension-sdk/lib/runtime.d.ts.map +1 -0
  211. package/node_modules/@try-works/tool-mode-extension-sdk/lib/runtime.js +58 -0
  212. package/node_modules/@try-works/tool-mode-extension-sdk/lib/state.d.ts +118 -0
  213. package/node_modules/@try-works/tool-mode-extension-sdk/lib/state.d.ts.map +1 -0
  214. package/node_modules/@try-works/tool-mode-extension-sdk/lib/state.js +113 -0
  215. package/node_modules/@try-works/tool-mode-extension-sdk/lib/worker/worker-child.d.ts +2 -0
  216. package/node_modules/@try-works/tool-mode-extension-sdk/lib/worker/worker-child.d.ts.map +1 -0
  217. package/node_modules/@try-works/tool-mode-extension-sdk/lib/worker/worker-child.js +351 -0
  218. package/node_modules/@try-works/tool-mode-extension-sdk/lib/worker.d.ts +150 -0
  219. package/node_modules/@try-works/tool-mode-extension-sdk/lib/worker.d.ts.map +1 -0
  220. package/node_modules/@try-works/tool-mode-extension-sdk/lib/worker.js +670 -0
  221. package/node_modules/@try-works/tool-mode-extension-sdk/package.json +53 -0
  222. package/node_modules/@try-works/tool-mode-extension-sdk/schema/extension-manifest-1.1.0.schema.json +253 -0
  223. package/node_modules/@try-works/tool-mode-recipes/bin/tool-mode-recipe.mjs +15 -0
  224. package/node_modules/@try-works/tool-mode-recipes/lib/broker.d.ts +427 -0
  225. package/node_modules/@try-works/tool-mode-recipes/lib/broker.d.ts.map +1 -0
  226. package/node_modules/@try-works/tool-mode-recipes/lib/broker.js +592 -0
  227. package/node_modules/@try-works/tool-mode-recipes/lib/cli.d.ts +60 -0
  228. package/node_modules/@try-works/tool-mode-recipes/lib/cli.d.ts.map +1 -0
  229. package/node_modules/@try-works/tool-mode-recipes/lib/cli.js +936 -0
  230. package/node_modules/@try-works/tool-mode-recipes/lib/dsh-adapter.d.ts +237 -0
  231. package/node_modules/@try-works/tool-mode-recipes/lib/dsh-adapter.d.ts.map +1 -0
  232. package/node_modules/@try-works/tool-mode-recipes/lib/dsh-adapter.js +200 -0
  233. package/node_modules/@try-works/tool-mode-recipes/lib/fixture-provider.d.ts +85 -0
  234. package/node_modules/@try-works/tool-mode-recipes/lib/fixture-provider.d.ts.map +1 -0
  235. package/node_modules/@try-works/tool-mode-recipes/lib/fixture-provider.js +176 -0
  236. package/node_modules/@try-works/tool-mode-recipes/lib/images.d.ts +105 -0
  237. package/node_modules/@try-works/tool-mode-recipes/lib/images.d.ts.map +1 -0
  238. package/node_modules/@try-works/tool-mode-recipes/lib/images.js +129 -0
  239. package/node_modules/@try-works/tool-mode-recipes/lib/index.d.ts +25 -0
  240. package/node_modules/@try-works/tool-mode-recipes/lib/index.d.ts.map +1 -0
  241. package/node_modules/@try-works/tool-mode-recipes/lib/index.js +25 -0
  242. package/node_modules/@try-works/tool-mode-recipes/lib/recipe-format.d.ts +325 -0
  243. package/node_modules/@try-works/tool-mode-recipes/lib/recipe-format.d.ts.map +1 -0
  244. package/node_modules/@try-works/tool-mode-recipes/lib/recipe-format.js +1310 -0
  245. package/node_modules/@try-works/tool-mode-recipes/lib/templates.d.ts +51 -0
  246. package/node_modules/@try-works/tool-mode-recipes/lib/templates.d.ts.map +1 -0
  247. package/node_modules/@try-works/tool-mode-recipes/lib/templates.js +310 -0
  248. package/node_modules/@try-works/tool-mode-recipes/lib/titles.d.ts +227 -0
  249. package/node_modules/@try-works/tool-mode-recipes/lib/titles.d.ts.map +1 -0
  250. package/node_modules/@try-works/tool-mode-recipes/lib/titles.js +407 -0
  251. package/node_modules/@try-works/tool-mode-recipes/package.json +56 -0
  252. package/node_modules/@try-works/tool-mode-recipes/recipes/describe-image.json +38 -0
  253. package/node_modules/@try-works/tool-mode-recipes/recipes/text-title.json +45 -0
  254. package/node_modules/@try-works/tool-mode-recipes/schema/harness-model-recipe.schema.json +273 -0
  255. package/package.json +50 -17
  256. package/remote/spec.mjs +439 -0
  257. package/remote/typert.host.mjs +14 -0
  258. package/remote/typert.remote-client.mjs +16 -0
  259. package/lib/adapters/tongue.d.ts +0 -31
  260. package/lib/adapters/tongue.d.ts.map +0 -1
  261. package/lib/adapters/tongue.js +0 -93
  262. package/lib/adapters/voz.d.ts +0 -28
  263. package/lib/adapters/voz.d.ts.map +0 -1
  264. package/lib/adapters/voz.js +0 -102
  265. /package/{lib → node_modules/@try-works/tool-mode-extension-sdk/lib}/licensing.d.ts +0 -0
  266. /package/{lib → node_modules/@try-works/tool-mode-extension-sdk/lib}/licensing.d.ts.map +0 -0
  267. /package/{lib → node_modules/@try-works/tool-mode-extension-sdk/lib}/licensing.js +0 -0
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * The `dsh-tool-mode-credentials` executable (SEC-01).
4
+ *
5
+ * The HUMAN-ONLY credential surface: the model-visible `model_tools`
6
+ * management action refuses generation (a generated secret must never enter a
7
+ * model transcript), and this CLI is the operator's terminal instead. The
8
+ * stream discipline is the stdio bridge's own: STDOUT carries the credential
9
+ * (the secret exactly once) and nothing else; diagnostics and usage go to
10
+ * stderr. The secret is never logged and never recoverable.
11
+ */
12
+
13
+ import { runCredentialsCli } from '../lib/mcp/credential-cli.js'
14
+
15
+ const exit = runCredentialsCli(process.argv.slice(2), {
16
+ out: line => process.stdout.write(`${line}\n`),
17
+ err: line => process.stderr.write(`${line}\n`),
18
+ })
19
+
20
+ process.exit(exit)
@@ -0,0 +1,202 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * The `dsh-tool-mode` launcher (RUN-03/RUN-04): serve / doctor / prepare /
4
+ * mcp-stdio.
5
+ *
6
+ * - `serve` boots the headless host composition. The host package ships no
7
+ * composition entry of its own (no src/host.ts — the recorded seam): serve
8
+ * attempts to resolve the DSH composition runtime and, when it is not
9
+ * resolvable from this artifact, exits non-zero with the exact missing seam
10
+ * rather than inventing service constructors.
11
+ * - `doctor` reports configuration, package/runtime compatibility, platform
12
+ * readiness and the launcher seam WITHOUT secrets.
13
+ * - `prepare --tool <name>` resolves the installed extension that serves the
14
+ * tool and runs the digest-verified prepared-assets acquisition (a REAL
15
+ * download is opt-in: the operator runs this command deliberately).
16
+ * - `mcp-stdio` reuses the existing stdio relay (same env contract as the
17
+ * standalone binary).
18
+ *
19
+ * Every subcommand: `--json` emits structured JSON on stdout; failures exit
20
+ * non-zero; an unattended launch never hangs (P26-16).
21
+ */
22
+
23
+ import { readFileSync } from 'node:fs'
24
+ import { createHash } from 'node:crypto'
25
+ import { existsSync, mkdirSync, readdirSync, statSync } from 'node:fs'
26
+ import { dirname, join, resolve } from 'node:path'
27
+ import { createPreparedAssetRegistry, parseAssetLock, plannedAssets, lockGroups, identityFor } from '../lib/prepared-assets.js'
28
+ import { planPreparation } from '../lib/deployment-coordinator.js'
29
+ import { createHttpSource } from '../lib/http-acquisition.js'
30
+ import { createStdioBridge } from '../lib/mcp/stdio.js'
31
+ import { discoverExtension } from '@try-works/tool-mode-extension-sdk'
32
+
33
+ const args = process.argv.slice(2)
34
+ const command = args[0] ?? '--help'
35
+ const flag = name => {
36
+ const index = args.indexOf(name)
37
+ return index === -1 || index + 1 >= args.length ? undefined : args[index + 1]
38
+ }
39
+ const jsonOut = args.includes('--json')
40
+ const report = (value) => {
41
+ process.stdout.write(`${JSON.stringify(value, null, 2)}\n`)
42
+ process.exit(0)
43
+ }
44
+ const fail = (message, code = 2) => {
45
+ if (jsonOut) process.stdout.write(`${JSON.stringify({ ok: false, error: message })}\n`)
46
+ else process.stderr.write(`dsh-tool-mode: ${message}\n`)
47
+ process.exit(code)
48
+ }
49
+
50
+ /** Read the config document, tolerating its absence for the read-only commands. */
51
+ function readConfig(path) {
52
+ const target = path ?? process.env.DSH_TOOL_MODE_CONFIG ?? './tool-mode.json'
53
+ try {
54
+ return JSON.parse(readFileSync(target, 'utf8'))
55
+ } catch {
56
+ return {}
57
+ }
58
+ }
59
+
60
+ if (command === 'mcp-stdio') {
61
+ const url = process.env.DSH_TOOL_MODE_MCP_URL ?? 'http://127.0.0.1:3765/mcp'
62
+ const token = process.env.DSH_TOOL_MODE_MCP_TOKEN
63
+ if (token === undefined || token.length === 0) {
64
+ process.stderr.write('dsh-tool-mode mcp-stdio: no credential configured (DSH_TOOL_MODE_MCP_TOKEN).\n')
65
+ process.exit(2)
66
+ }
67
+ const bridge = createStdioBridge(
68
+ {
69
+ url,
70
+ token,
71
+ fetch: async (target, init) => {
72
+ const response = await fetch(target, {
73
+ method: init.method,
74
+ headers: init.headers,
75
+ body: init.body,
76
+ signal: init.signal,
77
+ })
78
+ const headers = {}
79
+ response.headers.forEach((value, key) => { headers[key] = value })
80
+ return { status: response.status, headers, body: await response.text() }
81
+ },
82
+ },
83
+ {
84
+ protocol: line => process.stdout.write(`${line}\n`),
85
+ diagnostic: line => process.stderr.write(`${line}\n`),
86
+ },
87
+ )
88
+ bridge.start()
89
+ process.on('SIGINT', () => process.exit(0))
90
+ } else if (command === 'doctor') {
91
+ const config = readConfig(flag('--config'))
92
+ const platform = `${process.platform} ${process.arch}`
93
+ const nodeVersion = process.version
94
+ const mcpPort = config.mcpV3?.port ?? config.mcp?.port ?? 3765
95
+ const extensionStore = config.extensionStore ?? config.extensions?.registry ?? 'unset'
96
+ const result = {
97
+ ok: true,
98
+ command: 'doctor',
99
+ platform: { os: process.platform, arch: process.arch, node: nodeVersion, accelerator: 'cpu' },
100
+ configuration: {
101
+ schemaVersion: config.schemaVersion ?? 'legacy (v1/v2 flat shape)',
102
+ mcp: { host: '127.0.0.1', port: mcpPort, path: config.mcpV3?.path ?? '/mcp' },
103
+ extensionStore,
104
+ fixedFalseFlags: {
105
+ automaticUpdates: false,
106
+ runInstallScripts: false,
107
+ automaticActivation: false,
108
+ allowExecutableTemplates: false,
109
+ inheritConversation: false,
110
+ allowModelToolCalls: false,
111
+ },
112
+ },
113
+ launcherSeam:
114
+ '`serve` boots the headless composition in lib/headless.js: config -> catalog -> contract bindings -> MCP host -> '
115
+ + 'HTTP with credential authentication, without the DSH CLI or a browser (RUN-03). Harness-backed program '
116
+ + 'execution (tool_mode_run) stays refused headless: it needs the DSH PtcHostContext (CODE-10).',
117
+ serverStatus: 'not running (doctor does not start the listener)',
118
+ }
119
+ report(result)
120
+ } else if (command === 'prepare') {
121
+ const tool = flag('--tool')
122
+ if (tool === undefined) fail('prepare requires --tool <toolName> (RUN-04)')
123
+ const config = readConfig(flag('--config'))
124
+ const storeDir = config.extensionStore
125
+ if (typeof storeDir !== 'string' || storeDir.length === 0) {
126
+ fail('prepare requires the extension store (config.extensionStore); the store is not configured')
127
+ }
128
+ // Resolve the installed extension whose manifest serves the requested tool.
129
+ const found = []
130
+ if (existsSync(storeDir)) {
131
+ for (const entry of readdirSync(storeDir)) {
132
+ const root = join(storeDir, entry)
133
+ if (!statSync(root).isDirectory()) continue
134
+ for (const id of readdirSync(root)) {
135
+ const scope = join(root, id)
136
+ if (!statSync(scope).isDirectory()) continue
137
+ for (const version of readdirSync(scope)) {
138
+ const installPath = join(scope, version)
139
+ if (!existsSync(join(installPath, 'tool-mode.extension.json'))) continue
140
+ try {
141
+ const discovery = discoverExtension(installPath)
142
+ const serves = discovery.manifest.tools.some(t => t.name === tool)
143
+ || discovery.manifest.implementations.some(impl => {
144
+ const owner = discovery.manifest.tools.find(t => t.contractId === impl.contractId)
145
+ return owner?.name === tool
146
+ })
147
+ if (serves) found.push({ discovery, installPath })
148
+ } catch {
149
+ // A broken package is skipped: prepare never guesses.
150
+ }
151
+ }
152
+ }
153
+ }
154
+ }
155
+ if (found.length === 0) fail(`no installed extension serves the tool ${JSON.stringify(tool)} (prepare never guesses)`)
156
+ const { discovery, installPath } = found[0]
157
+ const model = discovery.manifest.models[0]
158
+ if (model === undefined) fail(`the extension serving ${tool} declares no model deployment`)
159
+ const lockPath = join(dirname(discovery.manifestPath), model.assetLock)
160
+ const lock = parseAssetLock(readFileSync(lockPath, 'utf8'))
161
+ const groups = lockGroups(lock, model.assetSet)
162
+ const plan = planPreparation(identityFor(discovery.manifest.id, model.id, lock), plannedAssets(lock, model.assetSet), lock.license)
163
+ const statePath = config.stateFile ?? join(process.env.LOCALAPPDATA ?? process.env.TEMP ?? '.', 'dsh-model-as-tool', 'state.json')
164
+ const registry = createPreparedAssetRegistry({ cacheRoot: join(dirname(resolve(statePath)), 'asset-cache') })
165
+ const outcome = await registry.prepare(discovery.manifest.id, plan, groups, {
166
+ source: createHttpSource(),
167
+ allowExecutable: false,
168
+ signal: new AbortController().signal,
169
+ })
170
+ if (!outcome.ok) fail(`the preparation failed: ${outcome.reason}`, 1)
171
+ const transferred = outcome.groups.map(group => group.digests.map(digest => createHash('sha256').update(digest).digest('hex')))
172
+ report({
173
+ ok: true,
174
+ command: 'prepare',
175
+ tool,
176
+ extension: discovery.manifest.id,
177
+ model: model.id,
178
+ revision: lock.revision,
179
+ groups: outcome.groups.map(group => ({ groupId: group.groupId, path: group.path, digests: group.digests })),
180
+ note: `transferred digests (${transferred.length} groups) are the content hashes; sizes are per-asset in the lock`,
181
+ })
182
+ } else if (command === 'serve') {
183
+ // The REAL headless composition (RUN-03, task-74): config load, catalog
184
+ // resolution, contract bindings, the MCP HTTP listener, and a bounded
185
+ // SIGINT/SIGTERM shutdown — composed from the host's own services, no DSH
186
+ // CLI required.
187
+ const { runHeadlessServe } = await import('../lib/headless.js')
188
+ const exit = await runHeadlessServe(
189
+ { configPath: flag('--config'), json: jsonOut },
190
+ { out: line => process.stdout.write(`${line}\n`), err: line => process.stderr.write(`${line}\n`) },
191
+ )
192
+ process.exit(exit)
193
+ } else {
194
+ process.stderr.write(
195
+ 'dsh-tool-mode: usage\n'
196
+ + ' dsh-tool-mode serve [--config tool-mode.json] [--json]\n'
197
+ + ' dsh-tool-mode doctor [--config tool-mode.json] [--json]\n'
198
+ + ' dsh-tool-mode prepare --tool <toolName> [--config tool-mode.json] [--json]\n'
199
+ + ' dsh-tool-mode mcp-stdio\n',
200
+ )
201
+ process.exit(command === '--help' || command === '-h' ? 0 : 2)
202
+ }