@try-works/dsh-tool-mode 0.0.0-stage → 0.5.45

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 (432) hide show
  1. package/LICENSE +205 -0
  2. package/README.md +303 -2
  3. package/bin/dsh-tool-mode-credentials.mjs +20 -0
  4. package/bin/dsh-tool-mode-mcp-stdio.mjs +80 -0
  5. package/bin/dsh-tool-mode.mjs +211 -0
  6. package/builtins.lock.json +26 -0
  7. package/catalog/desert-ant-models.json +693 -0
  8. package/catalog/playbooks.json +531 -0
  9. package/client/client.model-tools.js +1910 -0
  10. package/client/index.js +4158 -0
  11. package/cordis.patch.yml +39 -0
  12. package/lib/adapters/index.d.ts +61 -0
  13. package/lib/adapters/index.d.ts.map +1 -0
  14. package/lib/adapters/index.js +82 -0
  15. package/lib/adapters/types.d.ts +106 -0
  16. package/lib/adapters/types.d.ts.map +1 -0
  17. package/lib/adapters/types.js +85 -0
  18. package/lib/approval.d.ts +189 -0
  19. package/lib/approval.d.ts.map +1 -0
  20. package/lib/approval.js +510 -0
  21. package/lib/asset-acquisition.d.ts +149 -0
  22. package/lib/asset-acquisition.d.ts.map +1 -0
  23. package/lib/asset-acquisition.js +175 -0
  24. package/lib/authority.d.ts +185 -0
  25. package/lib/authority.d.ts.map +1 -0
  26. package/lib/authority.js +223 -0
  27. package/lib/bindings.d.ts +144 -0
  28. package/lib/bindings.d.ts.map +1 -0
  29. package/lib/bindings.js +314 -0
  30. package/lib/builtins.d.ts +27 -0
  31. package/lib/builtins.d.ts.map +1 -0
  32. package/lib/builtins.js +37 -0
  33. package/lib/capability.d.ts +58 -0
  34. package/lib/capability.d.ts.map +1 -0
  35. package/lib/capability.js +192 -0
  36. package/lib/capture-path.d.ts +97 -0
  37. package/lib/capture-path.d.ts.map +1 -0
  38. package/lib/capture-path.js +152 -0
  39. package/lib/catalog.d.ts +37 -0
  40. package/lib/catalog.d.ts.map +1 -0
  41. package/lib/catalog.js +274 -0
  42. package/lib/contract-payload.d.ts +39 -0
  43. package/lib/contract-payload.d.ts.map +1 -0
  44. package/lib/contract-payload.js +56 -0
  45. package/lib/custom-tools/compile.d.ts +25 -0
  46. package/lib/custom-tools/compile.d.ts.map +1 -0
  47. package/lib/custom-tools/compile.js +61 -0
  48. package/lib/custom-tools/composite-executor.d.ts +42 -0
  49. package/lib/custom-tools/composite-executor.d.ts.map +1 -0
  50. package/lib/custom-tools/composite-executor.js +113 -0
  51. package/lib/custom-tools/dispatch.d.ts +28 -0
  52. package/lib/custom-tools/dispatch.d.ts.map +1 -0
  53. package/lib/custom-tools/dispatch.js +34 -0
  54. package/lib/custom-tools/http-executor.d.ts +48 -0
  55. package/lib/custom-tools/http-executor.d.ts.map +1 -0
  56. package/lib/custom-tools/http-executor.js +241 -0
  57. package/lib/custom-tools/index.d.ts +12 -0
  58. package/lib/custom-tools/index.d.ts.map +1 -0
  59. package/lib/custom-tools/index.js +12 -0
  60. package/lib/custom-tools/mcp-surface.d.ts +14 -0
  61. package/lib/custom-tools/mcp-surface.d.ts.map +1 -0
  62. package/lib/custom-tools/mcp-surface.js +41 -0
  63. package/lib/custom-tools/prompt-executor.d.ts +39 -0
  64. package/lib/custom-tools/prompt-executor.d.ts.map +1 -0
  65. package/lib/custom-tools/prompt-executor.js +59 -0
  66. package/lib/custom-tools/registry.d.ts +69 -0
  67. package/lib/custom-tools/registry.d.ts.map +1 -0
  68. package/lib/custom-tools/registry.js +130 -0
  69. package/lib/custom-tools/schema.d.ts +26 -0
  70. package/lib/custom-tools/schema.d.ts.map +1 -0
  71. package/lib/custom-tools/schema.js +375 -0
  72. package/lib/custom-tools/service.d.ts +90 -0
  73. package/lib/custom-tools/service.d.ts.map +1 -0
  74. package/lib/custom-tools/service.js +203 -0
  75. package/lib/custom-tools/store.d.ts +61 -0
  76. package/lib/custom-tools/store.d.ts.map +1 -0
  77. package/lib/custom-tools/store.js +240 -0
  78. package/lib/custom-tools/types.d.ts +131 -0
  79. package/lib/custom-tools/types.d.ts.map +1 -0
  80. package/lib/custom-tools/types.js +11 -0
  81. package/lib/decision-combine.d.ts +113 -0
  82. package/lib/decision-combine.d.ts.map +1 -0
  83. package/lib/decision-combine.js +156 -0
  84. package/lib/decision-evaluate.d.ts +185 -0
  85. package/lib/decision-evaluate.d.ts.map +1 -0
  86. package/lib/decision-evaluate.js +227 -0
  87. package/lib/deployment-coordinator.d.ts +213 -0
  88. package/lib/deployment-coordinator.d.ts.map +1 -0
  89. package/lib/deployment-coordinator.js +274 -0
  90. package/lib/diagnostics.d.ts +169 -0
  91. package/lib/diagnostics.d.ts.map +1 -0
  92. package/lib/diagnostics.js +136 -0
  93. package/lib/discovery-contracts.d.ts +14 -0
  94. package/lib/discovery-contracts.d.ts.map +1 -0
  95. package/lib/discovery-contracts.js +90 -0
  96. package/lib/discovery-describe.d.ts +35 -0
  97. package/lib/discovery-describe.d.ts.map +1 -0
  98. package/lib/discovery-describe.js +99 -0
  99. package/lib/embedding-index.d.ts +55 -0
  100. package/lib/embedding-index.d.ts.map +1 -0
  101. package/lib/embedding-index.js +126 -0
  102. package/lib/extension-dependencies.d.ts +355 -0
  103. package/lib/extension-dependencies.d.ts.map +1 -0
  104. package/lib/extension-dependencies.js +987 -0
  105. package/lib/extension-dispatch.d.ts +150 -0
  106. package/lib/extension-dispatch.d.ts.map +1 -0
  107. package/lib/extension-dispatch.js +178 -0
  108. package/lib/extension-page-state.d.ts +69 -0
  109. package/lib/extension-page-state.d.ts.map +1 -0
  110. package/lib/extension-page-state.js +82 -0
  111. package/lib/extension-registrar.d.ts +116 -0
  112. package/lib/extension-registrar.d.ts.map +1 -0
  113. package/lib/extension-registrar.js +144 -0
  114. package/lib/extensions-api.d.ts +346 -0
  115. package/lib/extensions-api.d.ts.map +1 -0
  116. package/lib/extensions-api.js +17 -0
  117. package/lib/extensions-remote.d.ts +57 -0
  118. package/lib/extensions-remote.d.ts.map +1 -0
  119. package/lib/extensions-remote.js +69 -0
  120. package/lib/extensions-service.d.ts +568 -0
  121. package/lib/extensions-service.d.ts.map +1 -0
  122. package/lib/extensions-service.js +2552 -0
  123. package/lib/harness-budgets.d.ts +158 -0
  124. package/lib/harness-budgets.d.ts.map +1 -0
  125. package/lib/harness-budgets.js +152 -0
  126. package/lib/harness-llm.d.ts +138 -0
  127. package/lib/harness-llm.d.ts.map +1 -0
  128. package/lib/harness-llm.js +218 -0
  129. package/lib/harness-serving.d.ts +115 -0
  130. package/lib/harness-serving.d.ts.map +1 -0
  131. package/lib/harness-serving.js +176 -0
  132. package/lib/headless.d.ts +97 -0
  133. package/lib/headless.d.ts.map +1 -0
  134. package/lib/headless.js +407 -0
  135. package/lib/http-acquisition.d.ts +27 -0
  136. package/lib/http-acquisition.d.ts.map +1 -0
  137. package/lib/http-acquisition.js +140 -0
  138. package/lib/index.d.ts +546 -0
  139. package/lib/index.d.ts.map +1 -0
  140. package/lib/index.js +5273 -0
  141. package/lib/invocation-accounting.d.ts +169 -0
  142. package/lib/invocation-accounting.d.ts.map +1 -0
  143. package/lib/invocation-accounting.js +148 -0
  144. package/lib/jev.d.ts +218 -0
  145. package/lib/jev.d.ts.map +1 -0
  146. package/lib/jev.js +366 -0
  147. package/lib/legacy-migration.d.ts +95 -0
  148. package/lib/legacy-migration.d.ts.map +1 -0
  149. package/lib/legacy-migration.js +429 -0
  150. package/lib/license-basis.d.ts +29 -0
  151. package/lib/license-basis.d.ts.map +1 -0
  152. package/lib/license-basis.js +58 -0
  153. package/lib/managed-workers.d.ts +158 -0
  154. package/lib/managed-workers.d.ts.map +1 -0
  155. package/lib/managed-workers.js +269 -0
  156. package/lib/mcp/auth-selection.d.ts +35 -0
  157. package/lib/mcp/auth-selection.d.ts.map +1 -0
  158. package/lib/mcp/auth-selection.js +64 -0
  159. package/lib/mcp/client-grant.d.ts +89 -0
  160. package/lib/mcp/client-grant.d.ts.map +1 -0
  161. package/lib/mcp/client-grant.js +63 -0
  162. package/lib/mcp/credential-cli.d.ts +38 -0
  163. package/lib/mcp/credential-cli.d.ts.map +1 -0
  164. package/lib/mcp/credential-cli.js +148 -0
  165. package/lib/mcp/credential-store.d.ts +143 -0
  166. package/lib/mcp/credential-store.d.ts.map +1 -0
  167. package/lib/mcp/credential-store.js +461 -0
  168. package/lib/mcp/export-policy.d.ts +25 -0
  169. package/lib/mcp/export-policy.d.ts.map +1 -0
  170. package/lib/mcp/export-policy.js +31 -0
  171. package/lib/mcp/host-binding.d.ts +144 -0
  172. package/lib/mcp/host-binding.d.ts.map +1 -0
  173. package/lib/mcp/host-binding.js +280 -0
  174. package/lib/mcp/http.d.ts +180 -0
  175. package/lib/mcp/http.d.ts.map +1 -0
  176. package/lib/mcp/http.js +602 -0
  177. package/lib/mcp/oauth.d.ts +149 -0
  178. package/lib/mcp/oauth.d.ts.map +1 -0
  179. package/lib/mcp/oauth.js +396 -0
  180. package/lib/mcp/protocol.d.ts +329 -0
  181. package/lib/mcp/protocol.d.ts.map +1 -0
  182. package/lib/mcp/protocol.js +459 -0
  183. package/lib/mcp/rate-limit.d.ts +68 -0
  184. package/lib/mcp/rate-limit.d.ts.map +1 -0
  185. package/lib/mcp/rate-limit.js +114 -0
  186. package/lib/mcp/sdk-v2.d.ts +17 -0
  187. package/lib/mcp/sdk-v2.d.ts.map +1 -0
  188. package/lib/mcp/sdk-v2.js +204 -0
  189. package/lib/mcp/server.d.ts +149 -0
  190. package/lib/mcp/server.d.ts.map +1 -0
  191. package/lib/mcp/server.js +302 -0
  192. package/lib/mcp/stdio.d.ts +80 -0
  193. package/lib/mcp/stdio.d.ts.map +1 -0
  194. package/lib/mcp/stdio.js +184 -0
  195. package/lib/mcp/subscriptions.d.ts +177 -0
  196. package/lib/mcp/subscriptions.d.ts.map +1 -0
  197. package/lib/mcp/subscriptions.js +288 -0
  198. package/lib/mcp-status.d.ts +96 -0
  199. package/lib/mcp-status.d.ts.map +1 -0
  200. package/lib/mcp-status.js +70 -0
  201. package/lib/mcp-usage.d.ts +110 -0
  202. package/lib/mcp-usage.d.ts.map +1 -0
  203. package/lib/mcp-usage.js +189 -0
  204. package/lib/model-qualification.d.ts +192 -0
  205. package/lib/model-qualification.d.ts.map +1 -0
  206. package/lib/model-qualification.js +178 -0
  207. package/lib/model-runtime-lane.d.ts +69 -0
  208. package/lib/model-runtime-lane.d.ts.map +1 -0
  209. package/lib/model-runtime-lane.js +122 -0
  210. package/lib/model-runtime-recipe.d.ts +132 -0
  211. package/lib/model-runtime-recipe.d.ts.map +1 -0
  212. package/lib/model-runtime-recipe.js +291 -0
  213. package/lib/planning.d.ts +256 -0
  214. package/lib/planning.d.ts.map +1 -0
  215. package/lib/planning.js +471 -0
  216. package/lib/playbook.d.ts +42 -0
  217. package/lib/playbook.d.ts.map +1 -0
  218. package/lib/playbook.js +65 -0
  219. package/lib/prepared-assets.d.ts +269 -0
  220. package/lib/prepared-assets.d.ts.map +1 -0
  221. package/lib/prepared-assets.js +471 -0
  222. package/lib/provider-bridge.d.ts +107 -0
  223. package/lib/provider-bridge.d.ts.map +1 -0
  224. package/lib/provider-bridge.js +423 -0
  225. package/lib/ptc-authority.d.ts +154 -0
  226. package/lib/ptc-authority.d.ts.map +1 -0
  227. package/lib/ptc-authority.js +242 -0
  228. package/lib/ptc-confinement.d.ts +60 -0
  229. package/lib/ptc-confinement.d.ts.map +1 -0
  230. package/lib/ptc-confinement.js +212 -0
  231. package/lib/ptc-runtime.d.ts +166 -0
  232. package/lib/ptc-runtime.d.ts.map +1 -0
  233. package/lib/ptc-runtime.js +231 -0
  234. package/lib/publication.d.ts +161 -0
  235. package/lib/publication.d.ts.map +1 -0
  236. package/lib/publication.js +181 -0
  237. package/lib/receipt-store.d.ts +57 -0
  238. package/lib/receipt-store.d.ts.map +1 -0
  239. package/lib/receipt-store.js +143 -0
  240. package/lib/receipt.d.ts +231 -0
  241. package/lib/receipt.d.ts.map +1 -0
  242. package/lib/receipt.js +165 -0
  243. package/lib/registrar.d.ts +75 -0
  244. package/lib/registrar.d.ts.map +1 -0
  245. package/lib/registrar.js +152 -0
  246. package/lib/resource-governance.d.ts +204 -0
  247. package/lib/resource-governance.d.ts.map +1 -0
  248. package/lib/resource-governance.js +213 -0
  249. package/lib/server-lifecycle.d.ts +175 -0
  250. package/lib/server-lifecycle.d.ts.map +1 -0
  251. package/lib/server-lifecycle.js +269 -0
  252. package/lib/skills.d.ts +31 -0
  253. package/lib/skills.d.ts.map +1 -0
  254. package/lib/skills.js +170 -0
  255. package/lib/speech-bridge.d.ts +74 -0
  256. package/lib/speech-bridge.d.ts.map +1 -0
  257. package/lib/speech-bridge.js +115 -0
  258. package/lib/state.d.ts +100 -0
  259. package/lib/state.d.ts.map +1 -0
  260. package/lib/state.js +160 -0
  261. package/lib/title-proposal.d.ts +194 -0
  262. package/lib/title-proposal.d.ts.map +1 -0
  263. package/lib/title-proposal.js +244 -0
  264. package/lib/tool-inventory.d.ts +90 -0
  265. package/lib/tool-inventory.d.ts.map +1 -0
  266. package/lib/tool-inventory.js +102 -0
  267. package/lib/tool-mode-run.d.ts +310 -0
  268. package/lib/tool-mode-run.d.ts.map +1 -0
  269. package/lib/tool-mode-run.js +411 -0
  270. package/lib/tool-sources.d.ts +80 -0
  271. package/lib/tool-sources.d.ts.map +1 -0
  272. package/lib/tool-sources.js +123 -0
  273. package/lib/tool-usage-projection.d.ts +390 -0
  274. package/lib/tool-usage-projection.d.ts.map +1 -0
  275. package/lib/tool-usage-projection.js +1038 -0
  276. package/lib/tool-usage-report.d.ts +153 -0
  277. package/lib/tool-usage-report.d.ts.map +1 -0
  278. package/lib/tool-usage-report.js +274 -0
  279. package/lib/transport.d.ts +158 -0
  280. package/lib/transport.d.ts.map +1 -0
  281. package/lib/transport.js +332 -0
  282. package/lib/types.d.ts +134 -0
  283. package/lib/types.d.ts.map +1 -0
  284. package/lib/types.js +8 -0
  285. package/lib/update-surface.d.ts +79 -0
  286. package/lib/update-surface.d.ts.map +1 -0
  287. package/lib/update-surface.js +224 -0
  288. package/lib/version.d.ts +3 -0
  289. package/lib/version.d.ts.map +1 -0
  290. package/lib/version.js +27 -0
  291. package/node_modules/@try-works/tool-mode-contracts/lib/contract-metadata.d.ts +13 -0
  292. package/node_modules/@try-works/tool-mode-contracts/lib/contract-metadata.d.ts.map +1 -0
  293. package/node_modules/@try-works/tool-mode-contracts/lib/contract-metadata.js +85 -0
  294. package/node_modules/@try-works/tool-mode-contracts/lib/contracts/lang-detect.d.ts +16 -0
  295. package/node_modules/@try-works/tool-mode-contracts/lib/contracts/lang-detect.d.ts.map +1 -0
  296. package/node_modules/@try-works/tool-mode-contracts/lib/contracts/lang-detect.js +87 -0
  297. package/node_modules/@try-works/tool-mode-contracts/lib/contracts/standard.d.ts +38 -0
  298. package/node_modules/@try-works/tool-mode-contracts/lib/contracts/standard.d.ts.map +1 -0
  299. package/node_modules/@try-works/tool-mode-contracts/lib/contracts/standard.js +445 -0
  300. package/node_modules/@try-works/tool-mode-contracts/lib/contracts/stt-transcribe.d.ts +20 -0
  301. package/node_modules/@try-works/tool-mode-contracts/lib/contracts/stt-transcribe.d.ts.map +1 -0
  302. package/node_modules/@try-works/tool-mode-contracts/lib/contracts/stt-transcribe.js +112 -0
  303. package/node_modules/@try-works/tool-mode-contracts/lib/contracts/text-embed.d.ts +14 -0
  304. package/node_modules/@try-works/tool-mode-contracts/lib/contracts/text-embed.d.ts.map +1 -0
  305. package/node_modules/@try-works/tool-mode-contracts/lib/contracts/text-embed.js +63 -0
  306. package/node_modules/@try-works/tool-mode-contracts/lib/contracts/text-rerank.d.ts +14 -0
  307. package/node_modules/@try-works/tool-mode-contracts/lib/contracts/text-rerank.d.ts.map +1 -0
  308. package/node_modules/@try-works/tool-mode-contracts/lib/contracts/text-rerank.js +76 -0
  309. package/node_modules/@try-works/tool-mode-contracts/lib/dsh.d.ts +82 -0
  310. package/node_modules/@try-works/tool-mode-contracts/lib/dsh.d.ts.map +1 -0
  311. package/node_modules/@try-works/tool-mode-contracts/lib/dsh.js +274 -0
  312. package/node_modules/@try-works/tool-mode-contracts/lib/index.d.ts +26 -0
  313. package/node_modules/@try-works/tool-mode-contracts/lib/index.d.ts.map +1 -0
  314. package/node_modules/@try-works/tool-mode-contracts/lib/index.js +53 -0
  315. package/node_modules/@try-works/tool-mode-contracts/lib/meta.d.ts +133 -0
  316. package/node_modules/@try-works/tool-mode-contracts/lib/meta.d.ts.map +1 -0
  317. package/node_modules/@try-works/tool-mode-contracts/lib/meta.js +64 -0
  318. package/node_modules/@try-works/tool-mode-contracts/lib/registry.d.ts +121 -0
  319. package/node_modules/@try-works/tool-mode-contracts/lib/registry.d.ts.map +1 -0
  320. package/node_modules/@try-works/tool-mode-contracts/lib/registry.js +246 -0
  321. package/node_modules/@try-works/tool-mode-contracts/package.json +35 -0
  322. package/node_modules/@try-works/tool-mode-extension-sdk/bin/dsh-tool-mode.mjs +20 -0
  323. package/node_modules/@try-works/tool-mode-extension-sdk/lib/cli.d.ts +80 -0
  324. package/node_modules/@try-works/tool-mode-extension-sdk/lib/cli.d.ts.map +1 -0
  325. package/node_modules/@try-works/tool-mode-extension-sdk/lib/cli.js +533 -0
  326. package/node_modules/@try-works/tool-mode-extension-sdk/lib/declarative-recipes.d.ts +86 -0
  327. package/node_modules/@try-works/tool-mode-extension-sdk/lib/declarative-recipes.d.ts.map +1 -0
  328. package/node_modules/@try-works/tool-mode-extension-sdk/lib/declarative-recipes.js +145 -0
  329. package/node_modules/@try-works/tool-mode-extension-sdk/lib/discovery.d.ts +70 -0
  330. package/node_modules/@try-works/tool-mode-extension-sdk/lib/discovery.d.ts.map +1 -0
  331. package/node_modules/@try-works/tool-mode-extension-sdk/lib/discovery.js +201 -0
  332. package/node_modules/@try-works/tool-mode-extension-sdk/lib/errors.d.ts +57 -0
  333. package/node_modules/@try-works/tool-mode-extension-sdk/lib/errors.d.ts.map +1 -0
  334. package/node_modules/@try-works/tool-mode-extension-sdk/lib/errors.js +83 -0
  335. package/node_modules/@try-works/tool-mode-extension-sdk/lib/index.d.ts +33 -0
  336. package/node_modules/@try-works/tool-mode-extension-sdk/lib/index.d.ts.map +1 -0
  337. package/node_modules/@try-works/tool-mode-extension-sdk/lib/index.js +33 -0
  338. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/archive.d.ts +86 -0
  339. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/archive.d.ts.map +1 -0
  340. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/archive.js +191 -0
  341. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/dependencies.d.ts +137 -0
  342. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/dependencies.d.ts.map +1 -0
  343. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/dependencies.js +349 -0
  344. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/lifecycle.d.ts +274 -0
  345. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/lifecycle.d.ts.map +1 -0
  346. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/lifecycle.js +932 -0
  347. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/migration.d.ts +210 -0
  348. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/migration.d.ts.map +1 -0
  349. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/migration.js +368 -0
  350. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/runtime-link.d.ts +63 -0
  351. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/runtime-link.d.ts.map +1 -0
  352. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/runtime-link.js +149 -0
  353. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/source-directory.d.ts +35 -0
  354. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/source-directory.d.ts.map +1 -0
  355. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/source-directory.js +179 -0
  356. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/staged.d.ts +179 -0
  357. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/staged.d.ts.map +1 -0
  358. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/staged.js +299 -0
  359. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/store.d.ts +395 -0
  360. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/store.d.ts.map +1 -0
  361. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/store.js +839 -0
  362. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/tar-gzip-source.d.ts +44 -0
  363. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/tar-gzip-source.d.ts.map +1 -0
  364. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/tar-gzip-source.js +255 -0
  365. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/update-flow.d.ts +185 -0
  366. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/update-flow.d.ts.map +1 -0
  367. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/update-flow.js +504 -0
  368. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/zip-source.d.ts +17 -0
  369. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/zip-source.d.ts.map +1 -0
  370. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/zip-source.js +80 -0
  371. package/node_modules/@try-works/tool-mode-extension-sdk/lib/licensing.d.ts +221 -0
  372. package/node_modules/@try-works/tool-mode-extension-sdk/lib/licensing.d.ts.map +1 -0
  373. package/node_modules/@try-works/tool-mode-extension-sdk/lib/licensing.js +188 -0
  374. package/node_modules/@try-works/tool-mode-extension-sdk/lib/load.d.ts +52 -0
  375. package/node_modules/@try-works/tool-mode-extension-sdk/lib/load.d.ts.map +1 -0
  376. package/node_modules/@try-works/tool-mode-extension-sdk/lib/load.js +102 -0
  377. package/node_modules/@try-works/tool-mode-extension-sdk/lib/manifest.d.ts +171 -0
  378. package/node_modules/@try-works/tool-mode-extension-sdk/lib/manifest.d.ts.map +1 -0
  379. package/node_modules/@try-works/tool-mode-extension-sdk/lib/manifest.js +271 -0
  380. package/node_modules/@try-works/tool-mode-extension-sdk/lib/runtime.d.ts +242 -0
  381. package/node_modules/@try-works/tool-mode-extension-sdk/lib/runtime.d.ts.map +1 -0
  382. package/node_modules/@try-works/tool-mode-extension-sdk/lib/runtime.js +58 -0
  383. package/node_modules/@try-works/tool-mode-extension-sdk/lib/state.d.ts +128 -0
  384. package/node_modules/@try-works/tool-mode-extension-sdk/lib/state.d.ts.map +1 -0
  385. package/node_modules/@try-works/tool-mode-extension-sdk/lib/state.js +113 -0
  386. package/node_modules/@try-works/tool-mode-extension-sdk/lib/test-host.d.ts +41 -0
  387. package/node_modules/@try-works/tool-mode-extension-sdk/lib/test-host.d.ts.map +1 -0
  388. package/node_modules/@try-works/tool-mode-extension-sdk/lib/test-host.js +52 -0
  389. package/node_modules/@try-works/tool-mode-extension-sdk/lib/worker/worker-child.d.ts +2 -0
  390. package/node_modules/@try-works/tool-mode-extension-sdk/lib/worker/worker-child.d.ts.map +1 -0
  391. package/node_modules/@try-works/tool-mode-extension-sdk/lib/worker/worker-child.js +351 -0
  392. package/node_modules/@try-works/tool-mode-extension-sdk/lib/worker.d.ts +157 -0
  393. package/node_modules/@try-works/tool-mode-extension-sdk/lib/worker.d.ts.map +1 -0
  394. package/node_modules/@try-works/tool-mode-extension-sdk/lib/worker.js +688 -0
  395. package/node_modules/@try-works/tool-mode-extension-sdk/package.json +54 -0
  396. package/node_modules/@try-works/tool-mode-extension-sdk/schema/extension-manifest-1.1.0.schema.json +253 -0
  397. package/node_modules/@try-works/tool-mode-recipes/bin/tool-mode-recipe.mjs +15 -0
  398. package/node_modules/@try-works/tool-mode-recipes/lib/broker.d.ts +460 -0
  399. package/node_modules/@try-works/tool-mode-recipes/lib/broker.d.ts.map +1 -0
  400. package/node_modules/@try-works/tool-mode-recipes/lib/broker.js +647 -0
  401. package/node_modules/@try-works/tool-mode-recipes/lib/cli.d.ts +61 -0
  402. package/node_modules/@try-works/tool-mode-recipes/lib/cli.d.ts.map +1 -0
  403. package/node_modules/@try-works/tool-mode-recipes/lib/cli.js +1106 -0
  404. package/node_modules/@try-works/tool-mode-recipes/lib/dsh-adapter.d.ts +237 -0
  405. package/node_modules/@try-works/tool-mode-recipes/lib/dsh-adapter.d.ts.map +1 -0
  406. package/node_modules/@try-works/tool-mode-recipes/lib/dsh-adapter.js +205 -0
  407. package/node_modules/@try-works/tool-mode-recipes/lib/fixture-provider.d.ts +85 -0
  408. package/node_modules/@try-works/tool-mode-recipes/lib/fixture-provider.d.ts.map +1 -0
  409. package/node_modules/@try-works/tool-mode-recipes/lib/fixture-provider.js +176 -0
  410. package/node_modules/@try-works/tool-mode-recipes/lib/images.d.ts +119 -0
  411. package/node_modules/@try-works/tool-mode-recipes/lib/images.d.ts.map +1 -0
  412. package/node_modules/@try-works/tool-mode-recipes/lib/images.js +201 -0
  413. package/node_modules/@try-works/tool-mode-recipes/lib/index.d.ts +25 -0
  414. package/node_modules/@try-works/tool-mode-recipes/lib/index.d.ts.map +1 -0
  415. package/node_modules/@try-works/tool-mode-recipes/lib/index.js +25 -0
  416. package/node_modules/@try-works/tool-mode-recipes/lib/recipe-format.d.ts +345 -0
  417. package/node_modules/@try-works/tool-mode-recipes/lib/recipe-format.d.ts.map +1 -0
  418. package/node_modules/@try-works/tool-mode-recipes/lib/recipe-format.js +1465 -0
  419. package/node_modules/@try-works/tool-mode-recipes/lib/templates.d.ts +51 -0
  420. package/node_modules/@try-works/tool-mode-recipes/lib/templates.d.ts.map +1 -0
  421. package/node_modules/@try-works/tool-mode-recipes/lib/templates.js +310 -0
  422. package/node_modules/@try-works/tool-mode-recipes/lib/titles.d.ts +231 -0
  423. package/node_modules/@try-works/tool-mode-recipes/lib/titles.d.ts.map +1 -0
  424. package/node_modules/@try-works/tool-mode-recipes/lib/titles.js +435 -0
  425. package/node_modules/@try-works/tool-mode-recipes/package.json +56 -0
  426. package/node_modules/@try-works/tool-mode-recipes/recipes/describe-image.json +38 -0
  427. package/node_modules/@try-works/tool-mode-recipes/recipes/text-title.json +45 -0
  428. package/node_modules/@try-works/tool-mode-recipes/schema/harness-model-recipe.schema.json +273 -0
  429. package/package.json +127 -4
  430. package/remote/spec.mjs +993 -0
  431. package/remote/typert.host.mjs +14 -0
  432. package/remote/typert.remote-client.mjs +16 -0
@@ -0,0 +1,175 @@
1
+ /**
2
+ * Verified atomic asset acquisition (RES-03, RES-07).
3
+ *
4
+ * The requirement's rules are all about what must NOT be observable:
5
+ *
6
+ * - **A partial download must never be usable.** Bytes are written to a temporary
7
+ * sibling, verified against the expected digest, and only then renamed into place.
8
+ * A file at the final path is therefore either absent or complete and correct —
9
+ * which is why the temp file is a sibling rather than somewhere else: a rename
10
+ * within one directory is atomic, and one across filesystems is not.
11
+ * - **A failed or interrupted preparation cannot become ready.** A digest mismatch
12
+ * deletes the partial rather than keeping it for a retry that would resume from
13
+ * bytes already known to be wrong.
14
+ * - **Uninstall and purge are separate** (RES-03). Acquisition records ownership; it
15
+ * never deletes. Deletion is `purgeCandidates`, which refuses to remove an asset
16
+ * another owner still holds.
17
+ * - **No source changes or binary builds on the end-user machine.** This acquires
18
+ * pinned bytes; there is no compile step here to disable.
19
+ *
20
+ * Everything that touches the network or the filesystem is INJECTED, so the failure
21
+ * paths — which are the ones that matter and the ones a real download makes hard to
22
+ * reach — are exercised by test.
23
+ *
24
+ * @module @try-works/dsh-tool-mode/asset-acquisition
25
+ */
26
+ import { createHash } from 'node:crypto';
27
+ /** Where an asset lives once acquired. */
28
+ function contentPath(root, digest) {
29
+ return `${root}/${digest}`;
30
+ }
31
+ /** The temporary sibling a transfer lands in before verification. */
32
+ function partialPath(root, digest) {
33
+ // A SIBLING of the final path, so the rename is within one directory and therefore
34
+ // atomic. A temp directory elsewhere would make the final rename a copy.
35
+ return `${root}/.partial-${digest}`;
36
+ }
37
+ /** Hash bytes with the algorithm the digest length implies. */
38
+ function digestOf(bytes, expectedLength) {
39
+ // SHA-512 is 128 hex characters, SHA-256 is 64. Inferring from the expected length
40
+ // means a lock written in either is verified with the right algorithm rather than a
41
+ // mismatch that looks like corruption.
42
+ return createHash(expectedLength > 64 ? 'sha512' : 'sha256').update(bytes).digest('hex');
43
+ }
44
+ /**
45
+ * Whether two hex digests name the same content.
46
+ *
47
+ * HEX CASE IS NOT SEMANTIC. `crypto` emits lower case, while an extension lock may
48
+ * record either case (Laya's records upper case). Comparing the raw strings rejected
49
+ * a correctly seeded blob, so the acquisition fell through to the lock's prose source
50
+ * and failed with `Failed to parse URL` even though the verified bytes were on disk.
51
+ * @param left - one hex digest.
52
+ * @param right - the other hex digest.
53
+ * @returns true when they differ only in case.
54
+ */
55
+ export function sameDigest(left, right) {
56
+ return left.toLowerCase() === right.toLowerCase();
57
+ }
58
+ /**
59
+ * Acquire one asset, atomically and verified (RES-03).
60
+ *
61
+ * @param asset - the planned asset.
62
+ * @param options - the store, the source, the root and a cancellation signal.
63
+ * @returns the result, which never leaves a partial at the final path.
64
+ */
65
+ export async function acquireAsset(asset, options) {
66
+ const { store, source, root, signal } = options;
67
+ const finalPath = contentPath(root, asset.digest);
68
+ const partial = partialPath(root, asset.digest);
69
+ // Already acquired and verified by a previous run: nothing to do, and nothing to
70
+ // re-download. This is also what makes two owners share one set of bytes.
71
+ if (store.exists(finalPath) && sameDigest(digestOf(store.read(finalPath) ?? new Uint8Array(), asset.digest.length), asset.digest)) {
72
+ return { acquired: true, path: finalPath, digest: asset.digest, transferredBytes: 0, resumed: false };
73
+ }
74
+ const chunkBytes = options.chunkBytes ?? 4 * 1024 * 1024;
75
+ // Resumption is only attempted when the source can serve ranges. Assuming a partial
76
+ // is resumable against a source that cannot would append a full response to a
77
+ // partial and produce bytes that hash wrong for a reason that looks like corruption.
78
+ let offset = source.supportsRanges ? store.sizeOf(partial) : 0;
79
+ const resumed = offset > 0;
80
+ if (!source.supportsRanges && store.exists(partial))
81
+ store.remove(partial);
82
+ let transferred = 0;
83
+ try {
84
+ while (offset < asset.bytes) {
85
+ if (signal.aborted) {
86
+ // The partial is LEFT in place, because it is verifiable bytes and a later
87
+ // attempt can resume from it; it is not at the final path, so nothing can use
88
+ // it as though it were complete.
89
+ return { acquired: false, reason: 'the transfer was cancelled', retryable: true };
90
+ }
91
+ const to = Math.min(offset + chunkBytes, asset.bytes) - 1;
92
+ const chunk = await source.fetchRange(asset, offset, to, signal);
93
+ if (chunk.byteLength === 0) {
94
+ // A zero-length chunk before the declared size means the source ended early.
95
+ return {
96
+ acquired: false,
97
+ reason: `the source ended at ${offset} of ${asset.bytes} bytes`,
98
+ retryable: true,
99
+ };
100
+ }
101
+ // Appended rather than accumulated in memory: a 349 MB asset must not need a
102
+ // 349 MB buffer to be resumed.
103
+ store.write(partial, appendTo(store.read(partial), chunk));
104
+ offset += chunk.byteLength;
105
+ transferred += chunk.byteLength;
106
+ }
107
+ const completed = store.read(partial) ?? new Uint8Array();
108
+ if (completed.byteLength !== asset.bytes) {
109
+ store.remove(partial);
110
+ return {
111
+ acquired: false,
112
+ reason: `received ${completed.byteLength} bytes, expected ${asset.bytes}`,
113
+ retryable: true,
114
+ };
115
+ }
116
+ const actual = digestOf(completed, asset.digest.length);
117
+ if (!sameDigest(actual, asset.digest)) {
118
+ // RES-03: a failed preparation cannot become ready, and bytes already known to
119
+ // be wrong must not be kept for a retry that would resume from them.
120
+ store.remove(partial);
121
+ return {
122
+ acquired: false,
123
+ reason: `the asset digest is ${actual}, not the pinned ${asset.digest}`,
124
+ retryable: false,
125
+ };
126
+ }
127
+ // The whole point: verified bytes move into place in one atomic step, so the final
128
+ // path is never a partial file.
129
+ store.rename(partial, finalPath);
130
+ return { acquired: true, path: finalPath, digest: asset.digest, transferredBytes: transferred, resumed };
131
+ }
132
+ catch (error) {
133
+ // A transport failure leaves the partial for a resume and reports retryable, so a
134
+ // caller can tell a flaky network from a corrupt asset.
135
+ return {
136
+ acquired: false,
137
+ reason: error instanceof Error ? error.message : String(error),
138
+ retryable: true,
139
+ };
140
+ }
141
+ }
142
+ /** Concatenate a previous buffer with a new chunk. */
143
+ function appendTo(previous, chunk) {
144
+ if (previous === undefined)
145
+ return chunk;
146
+ const out = new Uint8Array(previous.byteLength + chunk.byteLength);
147
+ out.set(previous, 0);
148
+ out.set(chunk, previous.byteLength);
149
+ return out;
150
+ }
151
+ /**
152
+ * Describe a memory admission, without overstating what is enforced (RES-07).
153
+ * @param input - the enforced and estimated figures.
154
+ * @returns the estimate, with the scope stated.
155
+ */
156
+ export function describeMemory(input) {
157
+ return {
158
+ enforcedBytes: input.enforcedBytes,
159
+ estimatedBytes: input.estimatedBytes,
160
+ enforcedScope: input.enforcedScope,
161
+ measured: input.measured ?? false,
162
+ };
163
+ }
164
+ /**
165
+ * Whether an enforced limit actually bounds the whole process tree (RES-07).
166
+ *
167
+ * A V8 heap cap does NOT, and treating it as though it did is the specific mistake the
168
+ * requirement names.
169
+ * @param estimate - the estimate.
170
+ * @returns whether the enforcement covers the process tree.
171
+ */
172
+ export function boundsProcessTree(estimate) {
173
+ return estimate.enforcedScope === 'process-tree';
174
+ }
175
+ //# sourceMappingURL=asset-acquisition.js.map
@@ -0,0 +1,185 @@
1
+ /**
2
+ * Caller authority: the grant a tool invocation runs under (SEC-03, SEC-06).
3
+ *
4
+ * The governing rule is BASE-05: an external request cannot supply or forge these
5
+ * authorities. Everything here is constructed by the HOST from operator
6
+ * configuration, never from a request body, a `clientInfo.name`, a requested tool
7
+ * list, or a path a caller supplied. A caller's arguments are then checked
8
+ * AGAINST the grant; they never expand it.
9
+ *
10
+ * Path handling is deliberately paranoid. SEC-06 requires resolving Windows drive
11
+ * letters, separators, Unicode, junctions and symlinks safely, rejecting escapes,
12
+ * unsupported UNC/device paths and unauthorized roots, and refusing when
13
+ * authorization cannot be established. The resolver therefore returns the
14
+ * CANONICAL path for the caller to open, rather than validating a string and
15
+ * letting a later open re-resolve it — that gap is the classic check-then-open
16
+ * race, and a symlink swapped between the two steps would win it.
17
+ *
18
+ * @module @try-works/dsh-tool-mode/authority
19
+ */
20
+ /** The stable error codes a denied request reports (SPEC §4 error vocabulary). */
21
+ export type AuthorityErrorCode =
22
+ /** The path was not absolute; SEC-06 admits absolute paths only. */
23
+ 'PATH_NOT_ABSOLUTE'
24
+ /** A UNC or Windows device path, which v1 refuses outright. */
25
+ | 'PATH_UNSUPPORTED'
26
+ /** The path does not exist, so it cannot be authorized. */
27
+ | 'PATH_NOT_FOUND'
28
+ /** The path resolves outside every approved root. */
29
+ | 'PATH_OUTSIDE_GRANT'
30
+ /** The tool is not in the grant's allowed set. */
31
+ | 'TOOL_NOT_GRANTED'
32
+ /** The harness executor profile is not explicitly allowed by the grant. */
33
+ | 'PROFILE_NOT_GRANTED'
34
+ /** The model capability is not explicitly allowed by the grant. */
35
+ | 'CAPABILITY_NOT_GRANTED'
36
+ /** The grant does not exist or was revoked. */
37
+ | 'GRANT_REVOKED';
38
+ /** A refused invocation. Carries a recovery hint, not just a refusal. */
39
+ export declare class AuthorityError extends Error {
40
+ readonly name = "AuthorityError";
41
+ readonly code: AuthorityErrorCode;
42
+ /** Actionable next step for the caller or operator. */
43
+ readonly hint: string;
44
+ constructor(code: AuthorityErrorCode, message: string, hint: string);
45
+ }
46
+ /** Absolute resource limits applied to every invocation under a grant. */
47
+ export interface GrantLimits {
48
+ /** Largest admitted input, in bytes. */
49
+ readonly maxInputBytes: number;
50
+ /** Largest admitted audio duration, in seconds. */
51
+ readonly maxAudioSeconds: number;
52
+ /** Largest admitted inline result, in bytes. */
53
+ readonly maxResultBytes: number;
54
+ /** Largest number of model calls one root invocation may make. */
55
+ readonly maxModelCalls: number;
56
+ /** Largest output-token budget one root invocation may use. */
57
+ readonly maxOutputTokens: number;
58
+ /** Largest number of image inputs one invocation may bind. */
59
+ readonly maxImages: number;
60
+ /** Root wall-clock deadline for one invocation, in milliseconds. */
61
+ readonly deadlineMs: number;
62
+ }
63
+ /** What a caller is permitted to do (SEC-03). */
64
+ export interface ToolGrant {
65
+ /** Stable grant identity, recorded in receipts. */
66
+ readonly grantId: string;
67
+ /** Tool names this caller may invoke. A requested list never extends it. */
68
+ readonly allowedTools: readonly string[];
69
+ /**
70
+ * Filesystem roots the caller may read from, as absolute paths.
71
+ * Canonicalized when the grant is built, so a symlinked root cannot be declared
72
+ * one way and resolve another.
73
+ */
74
+ readonly approvedRoots: readonly string[];
75
+ /** Remote destinations this caller may reach. Empty means none. */
76
+ readonly remoteDestinations: readonly string[];
77
+ /** Operator-approved harness executor profiles this caller may select. */
78
+ readonly allowedHarnessProfiles: readonly string[];
79
+ /** Model capabilities (input/output modalities) this caller may use. */
80
+ readonly modelCapabilities: readonly string[];
81
+ /** Whether hosted code execution is permitted. */
82
+ readonly hostedCode: boolean;
83
+ /** Whether receipts may be recorded. */
84
+ readonly recordingPolicy: 'none' | 'receipts';
85
+ /** Hard resource limits. */
86
+ readonly limits: GrantLimits;
87
+ }
88
+ /** Build a grant, canonicalizing its roots. */
89
+ export interface GrantInput {
90
+ readonly grantId: string;
91
+ readonly allowedTools: readonly string[];
92
+ readonly approvedRoots: readonly string[];
93
+ readonly remoteDestinations?: readonly string[];
94
+ readonly allowedHarnessProfiles?: readonly string[];
95
+ readonly modelCapabilities?: readonly string[];
96
+ readonly hostedCode?: boolean;
97
+ readonly recordingPolicy?: 'none' | 'receipts';
98
+ readonly limits?: Partial<GrantLimits>;
99
+ }
100
+ /** Conservative defaults: a grant that declares nothing permits almost nothing. */
101
+ export declare const DEFAULT_LIMITS: GrantLimits;
102
+ /**
103
+ * Build a grant from operator configuration.
104
+ *
105
+ * This is the only constructor: a request cannot reach it, and an approved root
106
+ * that is not absolute or not resolvable is dropped rather than trusted.
107
+ * @param input - the operator's declaration.
108
+ * @returns the canonicalized grant.
109
+ */
110
+ export declare function createGrant(input: GrantInput): ToolGrant;
111
+ /**
112
+ * Authorize one caller-supplied path against a grant (SEC-06).
113
+ *
114
+ * Returns the CANONICAL path, which the caller must open. Validating the original
115
+ * string and opening it later would leave a window in which a symlink could be
116
+ * swapped; resolving once and returning the result closes it.
117
+ * @param grant - the caller's grant.
118
+ * @param candidate - the caller-supplied path.
119
+ * @returns the canonical, authorized path.
120
+ * @throws AuthorityError when the path is inadmissible, missing, or outside the grant.
121
+ */
122
+ export declare function authorizePath(grant: ToolGrant, candidate: string): string;
123
+ /**
124
+ * Authorize a tool name against a grant (SEC-03).
125
+ * @param grant - the caller's grant.
126
+ * @param toolName - the requested tool.
127
+ * @throws AuthorityError with `TOOL_NOT_GRANTED`.
128
+ */
129
+ export declare function authorizeTool(grant: ToolGrant, toolName: string): void;
130
+ /**
131
+ * Authorize an operator-bound harness executor profile (SEC-03/HLM-03).
132
+ * @param grant - the caller's grant.
133
+ * @param profile - the logical profile the recipe selected.
134
+ * @throws AuthorityError with `PROFILE_NOT_GRANTED`.
135
+ */
136
+ export declare function authorizeHarnessProfile(grant: ToolGrant, profile: string): void;
137
+ /**
138
+ * Authorize the model capabilities an executor will use (SEC-03).
139
+ * @param grant - the caller's grant.
140
+ * @param required - the input/output modalities required by the selected model.
141
+ * @throws AuthorityError with `CAPABILITY_NOT_GRANTED`.
142
+ */
143
+ export declare function authorizeModelCapabilities(grant: ToolGrant, required: readonly string[]): void;
144
+ /**
145
+ * Authorize a remote destination against a grant (SEC-10).
146
+ *
147
+ * No silent local-to-remote fallback: if a destination was not explicitly
148
+ * approved, the call is refused rather than downgraded or upgraded.
149
+ * @param grant - the caller's grant.
150
+ * @param destination - the destination origin.
151
+ * @throws AuthorityError with `TOOL_NOT_GRANTED`.
152
+ */
153
+ export declare function authorizeDestination(grant: ToolGrant, destination: string): void;
154
+ /**
155
+ * The trusted execution context handed to an implementation.
156
+ *
157
+ * An implementation receives resolved authority, never a raw path it must
158
+ * re-check, and never anything a caller could have constructed.
159
+ */
160
+ export interface InvocationAuthority {
161
+ /** Grant identity, for the receipt. */
162
+ readonly grantId: string;
163
+ /** Who is calling, as the host resolved it. */
164
+ readonly callerKind: 'interactive' | 'external' | 'system';
165
+ /** Resource limits in force. */
166
+ readonly limits: GrantLimits;
167
+ /** Whether receipts may be recorded. */
168
+ readonly recordingPolicy: 'none' | 'receipts';
169
+ /**
170
+ * Resolve a caller-supplied path to a canonical authorized path.
171
+ * @param candidate - the caller-supplied path.
172
+ * @returns the canonical path to open.
173
+ */
174
+ resolvePath(candidate: string): string;
175
+ }
176
+ /**
177
+ * Build the invocation authority for one call.
178
+ *
179
+ * The result is constructed by the host; a request body has no path to it.
180
+ * @param grant - the caller's grant.
181
+ * @param callerKind - how the host classified the caller.
182
+ * @returns the authority handed to the implementation.
183
+ */
184
+ export declare function createInvocationAuthority(grant: ToolGrant, callerKind: InvocationAuthority['callerKind']): InvocationAuthority;
185
+ //# sourceMappingURL=authority.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authority.d.ts","sourceRoot":"","sources":["../src/authority.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,223 @@
1
+ /**
2
+ * Caller authority: the grant a tool invocation runs under (SEC-03, SEC-06).
3
+ *
4
+ * The governing rule is BASE-05: an external request cannot supply or forge these
5
+ * authorities. Everything here is constructed by the HOST from operator
6
+ * configuration, never from a request body, a `clientInfo.name`, a requested tool
7
+ * list, or a path a caller supplied. A caller's arguments are then checked
8
+ * AGAINST the grant; they never expand it.
9
+ *
10
+ * Path handling is deliberately paranoid. SEC-06 requires resolving Windows drive
11
+ * letters, separators, Unicode, junctions and symlinks safely, rejecting escapes,
12
+ * unsupported UNC/device paths and unauthorized roots, and refusing when
13
+ * authorization cannot be established. The resolver therefore returns the
14
+ * CANONICAL path for the caller to open, rather than validating a string and
15
+ * letting a later open re-resolve it — that gap is the classic check-then-open
16
+ * race, and a symlink swapped between the two steps would win it.
17
+ *
18
+ * @module @try-works/dsh-tool-mode/authority
19
+ */
20
+ import { realpathSync } from 'node:fs';
21
+ import { isAbsolute, sep } from 'node:path';
22
+ /** A refused invocation. Carries a recovery hint, not just a refusal. */
23
+ export class AuthorityError extends Error {
24
+ name = 'AuthorityError';
25
+ code;
26
+ /** Actionable next step for the caller or operator. */
27
+ hint;
28
+ constructor(code, message, hint) {
29
+ super(message);
30
+ this.code = code;
31
+ this.hint = hint;
32
+ }
33
+ }
34
+ /** Conservative defaults: a grant that declares nothing permits almost nothing. */
35
+ export const DEFAULT_LIMITS = {
36
+ maxInputBytes: 64 * 1024 * 1024,
37
+ maxAudioSeconds: 3600,
38
+ maxResultBytes: 8 * 1024 * 1024,
39
+ maxModelCalls: 1,
40
+ maxOutputTokens: 1024,
41
+ maxImages: 2,
42
+ deadlineMs: 60_000,
43
+ };
44
+ /** Whether this process is on a case-insensitive filesystem. */
45
+ const CASE_INSENSITIVE = process.platform === 'win32' || process.platform === 'darwin';
46
+ /**
47
+ * Canonicalize a root for containment comparison.
48
+ *
49
+ * A root that does not exist is still admitted, because an operator may declare a
50
+ * root before creating it; it simply can never contain anything until it exists,
51
+ * which fails closed.
52
+ * @param root - the declared root.
53
+ * @returns the canonical root, or undefined when it cannot be resolved yet.
54
+ */
55
+ function canonicalizeRoot(root) {
56
+ if (!isAbsolute(root))
57
+ return undefined;
58
+ try {
59
+ return realpathSync.native(root);
60
+ }
61
+ catch {
62
+ return undefined;
63
+ }
64
+ }
65
+ /**
66
+ * Build a grant from operator configuration.
67
+ *
68
+ * This is the only constructor: a request cannot reach it, and an approved root
69
+ * that is not absolute or not resolvable is dropped rather than trusted.
70
+ * @param input - the operator's declaration.
71
+ * @returns the canonicalized grant.
72
+ */
73
+ export function createGrant(input) {
74
+ const roots = [];
75
+ for (const root of input.approvedRoots) {
76
+ const canonical = canonicalizeRoot(root);
77
+ // A root that cannot be canonicalized is dropped, not guessed at. Dropping
78
+ // fails closed; keeping an unresolved string would fail open.
79
+ if (canonical !== undefined)
80
+ roots.push(canonical);
81
+ }
82
+ return {
83
+ grantId: input.grantId,
84
+ allowedTools: [...input.allowedTools],
85
+ approvedRoots: roots,
86
+ remoteDestinations: [...(input.remoteDestinations ?? [])],
87
+ allowedHarnessProfiles: [...(input.allowedHarnessProfiles ?? [])],
88
+ modelCapabilities: [...(input.modelCapabilities ?? [])],
89
+ hostedCode: input.hostedCode ?? false,
90
+ recordingPolicy: input.recordingPolicy ?? 'none',
91
+ limits: { ...DEFAULT_LIMITS, ...input.limits },
92
+ };
93
+ }
94
+ /** Compare two paths for equality under this platform's case rules. */
95
+ function samePath(a, b) {
96
+ return CASE_INSENSITIVE ? a.toLowerCase() === b.toLowerCase() : a === b;
97
+ }
98
+ /** Whether `child` is `root` itself or lies beneath it, on a separator boundary. */
99
+ function isWithin(child, root) {
100
+ if (samePath(child, root))
101
+ return true;
102
+ const prefix = root.endsWith(sep) ? root : root + sep;
103
+ return CASE_INSENSITIVE
104
+ ? child.toLowerCase().startsWith(prefix.toLowerCase())
105
+ : child.startsWith(prefix);
106
+ }
107
+ /**
108
+ * Reject path shapes v1 does not admit, before any filesystem call.
109
+ * @param candidate - the caller-supplied path.
110
+ * @throws AuthorityError with `PATH_UNSUPPORTED` or `PATH_NOT_ABSOLUTE`.
111
+ */
112
+ function assertAdmissibleShape(candidate) {
113
+ // Windows device namespaces bypass normal path handling entirely, and a UNC
114
+ // path reaches another host that no approved root can describe.
115
+ if (candidate.startsWith('\\\\') || candidate.startsWith('//')) {
116
+ throw new AuthorityError('PATH_UNSUPPORTED', 'UNC and Windows device paths are not admitted', 'Use an absolute path on a local drive that lies under an approved root.');
117
+ }
118
+ if (candidate.includes('\0')) {
119
+ throw new AuthorityError('PATH_UNSUPPORTED', 'the path contains a NUL byte', 'Pass the path as a plain string without embedded control characters.');
120
+ }
121
+ if (!isAbsolute(candidate)) {
122
+ throw new AuthorityError('PATH_NOT_ABSOLUTE', 'relative paths are not admitted; v1 authorizes absolute paths only', 'Resolve the path to an absolute path under an approved root before calling.');
123
+ }
124
+ }
125
+ /**
126
+ * Authorize one caller-supplied path against a grant (SEC-06).
127
+ *
128
+ * Returns the CANONICAL path, which the caller must open. Validating the original
129
+ * string and opening it later would leave a window in which a symlink could be
130
+ * swapped; resolving once and returning the result closes it.
131
+ * @param grant - the caller's grant.
132
+ * @param candidate - the caller-supplied path.
133
+ * @returns the canonical, authorized path.
134
+ * @throws AuthorityError when the path is inadmissible, missing, or outside the grant.
135
+ */
136
+ export function authorizePath(grant, candidate) {
137
+ if (typeof candidate !== 'string' || candidate.length === 0) {
138
+ throw new AuthorityError('PATH_NOT_ABSOLUTE', 'a path is required', 'Supply an absolute path under an approved root.');
139
+ }
140
+ assertAdmissibleShape(candidate);
141
+ let canonical;
142
+ try {
143
+ // Resolves junctions and symlinks, so containment is checked against what the
144
+ // path actually IS rather than what it spells.
145
+ canonical = realpathSync.native(candidate);
146
+ }
147
+ catch {
148
+ throw new AuthorityError('PATH_NOT_FOUND', 'the path does not exist, so it cannot be authorized', 'Check the path, or ask the operator to add its root to the grant.');
149
+ }
150
+ for (const root of grant.approvedRoots) {
151
+ if (isWithin(canonical, root))
152
+ return canonical;
153
+ }
154
+ // The message names the grant, not the allowed roots: enumerating a caller's
155
+ // permitted directories would disclose the operator's configuration.
156
+ throw new AuthorityError('PATH_OUTSIDE_GRANT', 'the path resolves outside every root approved for this caller', 'Ask the operator to add the containing root to this grant.');
157
+ }
158
+ /**
159
+ * Authorize a tool name against a grant (SEC-03).
160
+ * @param grant - the caller's grant.
161
+ * @param toolName - the requested tool.
162
+ * @throws AuthorityError with `TOOL_NOT_GRANTED`.
163
+ */
164
+ export function authorizeTool(grant, toolName) {
165
+ if (!grant.allowedTools.includes(toolName)) {
166
+ throw new AuthorityError('TOOL_NOT_GRANTED', `tool "${toolName}" is not granted to this caller`, 'Request access from the operator; a requested tool list does not extend a grant.');
167
+ }
168
+ }
169
+ /**
170
+ * Authorize an operator-bound harness executor profile (SEC-03/HLM-03).
171
+ * @param grant - the caller's grant.
172
+ * @param profile - the logical profile the recipe selected.
173
+ * @throws AuthorityError with `PROFILE_NOT_GRANTED`.
174
+ */
175
+ export function authorizeHarnessProfile(grant, profile) {
176
+ if (!grant.allowedHarnessProfiles.includes(profile)) {
177
+ throw new AuthorityError('PROFILE_NOT_GRANTED', `harness executor profile "${profile}" is not granted to this caller`, 'The operator must authorize the profile for this client/workspace; a caller cannot select another client\'s profile.');
178
+ }
179
+ }
180
+ /**
181
+ * Authorize the model capabilities an executor will use (SEC-03).
182
+ * @param grant - the caller's grant.
183
+ * @param required - the input/output modalities required by the selected model.
184
+ * @throws AuthorityError with `CAPABILITY_NOT_GRANTED`.
185
+ */
186
+ export function authorizeModelCapabilities(grant, required) {
187
+ const missing = required.filter(capability => !grant.modelCapabilities.includes(capability));
188
+ if (missing.length > 0) {
189
+ throw new AuthorityError('CAPABILITY_NOT_GRANTED', `model capability ${missing.map(capability => JSON.stringify(capability)).join(', ')} is not granted to this caller`, 'The grant must name the model capabilities this caller may use; a request cannot widen it.');
190
+ }
191
+ }
192
+ /**
193
+ * Authorize a remote destination against a grant (SEC-10).
194
+ *
195
+ * No silent local-to-remote fallback: if a destination was not explicitly
196
+ * approved, the call is refused rather than downgraded or upgraded.
197
+ * @param grant - the caller's grant.
198
+ * @param destination - the destination origin.
199
+ * @throws AuthorityError with `TOOL_NOT_GRANTED`.
200
+ */
201
+ export function authorizeDestination(grant, destination) {
202
+ if (!grant.remoteDestinations.includes(destination)) {
203
+ throw new AuthorityError('TOOL_NOT_GRANTED', `destination "${destination}" is not authorized for this caller`, 'A remote destination requires explicit authorization; there is no silent fallback.');
204
+ }
205
+ }
206
+ /**
207
+ * Build the invocation authority for one call.
208
+ *
209
+ * The result is constructed by the host; a request body has no path to it.
210
+ * @param grant - the caller's grant.
211
+ * @param callerKind - how the host classified the caller.
212
+ * @returns the authority handed to the implementation.
213
+ */
214
+ export function createInvocationAuthority(grant, callerKind) {
215
+ return {
216
+ grantId: grant.grantId,
217
+ callerKind,
218
+ limits: grant.limits,
219
+ recordingPolicy: grant.recordingPolicy,
220
+ resolvePath: candidate => authorizePath(grant, candidate),
221
+ };
222
+ }
223
+ //# sourceMappingURL=authority.js.map