hostlet 0.0.0-stage → 0.1.0-alpha.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 (512) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +233 -2
  3. package/bin/hostlet.js +61 -0
  4. package/console/app/api.js +1223 -0
  5. package/console/app/boot.js +165 -0
  6. package/console/app/cards.js +222 -0
  7. package/console/app/compose-quote.js +127 -0
  8. package/console/app/config-form.js +727 -0
  9. package/console/app/document-drafts.js +62 -0
  10. package/console/app/document-tools.mjs +67 -0
  11. package/console/app/documents.js +106 -0
  12. package/console/app/pages.js +6483 -0
  13. package/console/app/plugins.js +509 -0
  14. package/console/app/preview-tools.js +172 -0
  15. package/console/app/reference-labels.js +118 -0
  16. package/console/app/selection.js +372 -0
  17. package/console/app/store.js +57 -0
  18. package/console/app/text-anchor.js +26 -0
  19. package/console/app/topic-local.js +322 -0
  20. package/console/app/topic-nav.js +414 -0
  21. package/console/app/topic-status.js +109 -0
  22. package/console/app/views.js +43 -0
  23. package/console/apple-touch-icon.png +0 -0
  24. package/console/avatars/agy.svg +34 -0
  25. package/console/avatars/alhena.svg +36 -0
  26. package/console/avatars/castor.svg +38 -0
  27. package/console/avatars/claude.svg +34 -0
  28. package/console/avatars/codex.svg +34 -0
  29. package/console/avatars/devin.svg +34 -0
  30. package/console/avatars/echo.svg +34 -0
  31. package/console/avatars/kimi.svg +33 -0
  32. package/console/avatars/opencode.svg +33 -0
  33. package/console/avatars/pinion.svg +34 -0
  34. package/console/avatars/sprocket.svg +34 -0
  35. package/console/avatars/vela.svg +44 -0
  36. package/console/avatars/wasat.svg +38 -0
  37. package/console/clients/agy.svg +1 -0
  38. package/console/clients/claude.svg +1 -0
  39. package/console/clients/codex.svg +1 -0
  40. package/console/clients/devin.svg +1 -0
  41. package/console/clients/kimi.svg +1 -0
  42. package/console/clients/opencode.svg +1 -0
  43. package/console/favicon.ico +0 -0
  44. package/console/favicon.svg +16 -0
  45. package/console/index.html +99 -0
  46. package/console/pdl/engine/README.md +13 -0
  47. package/console/pdl/engine/anchor.js +195 -0
  48. package/console/pdl/engine/core.js +1340 -0
  49. package/console/pdl/engine/frame.js +1252 -0
  50. package/console/pdl/engine/i18n.js +67 -0
  51. package/console/pdl/engine/pdl-check.js +102 -0
  52. package/console/pdl/engine/pdl-doc.js +353 -0
  53. package/console/pdl/engine/pdl-view.js +280 -0
  54. package/console/pdl/engine/pdl.js +1064 -0
  55. package/console/pdl/engine/platform.js +18 -0
  56. package/console/pdl/engine/proj.js +279 -0
  57. package/console/pdl/engine/theme.js +176 -0
  58. package/console/pdl/engine/tree.js +171 -0
  59. package/console/pdl/engine/units.js +546 -0
  60. package/console/pdl/library/README.md +28 -0
  61. package/console/pdl/library/blocks.js +1512 -0
  62. package/console/pdl/library/buttons.js +86 -0
  63. package/console/pdl/library/capsules.js +130 -0
  64. package/console/pdl/library/charts.js +287 -0
  65. package/console/pdl/library/code.js +98 -0
  66. package/console/pdl/library/css/base.css +12 -0
  67. package/console/pdl/library/css/blocks.css +98 -0
  68. package/console/pdl/library/css/capsules.css +42 -0
  69. package/console/pdl/library/css/catalog-page.css +24 -0
  70. package/console/pdl/library/css/chat.css +100 -0
  71. package/console/pdl/library/css/composer-top.css +145 -0
  72. package/console/pdl/library/css/controls.css +195 -0
  73. package/console/pdl/library/css/drag.css +29 -0
  74. package/console/pdl/library/css/edit-layout.css +93 -0
  75. package/console/pdl/library/css/floating-window.css +30 -0
  76. package/console/pdl/library/css/hover.css +50 -0
  77. package/console/pdl/library/css/label-search.css +37 -0
  78. package/console/pdl/library/css/layers.css +43 -0
  79. package/console/pdl/library/css/library-parts.css +33 -0
  80. package/console/pdl/library/css/library.css +117 -0
  81. package/console/pdl/library/css/member-select.css +34 -0
  82. package/console/pdl/library/css/message.css +72 -0
  83. package/console/pdl/library/css/page.css +104 -0
  84. package/console/pdl/library/css/parts.css +338 -0
  85. package/console/pdl/library/css/responsive.css +40 -0
  86. package/console/pdl/library/css/roles.css +28 -0
  87. package/console/pdl/library/css/rows.css +231 -0
  88. package/console/pdl/library/css/settings-rows.css +37 -0
  89. package/console/pdl/library/css/shell.css +59 -0
  90. package/console/pdl/library/css/stream.css +296 -0
  91. package/console/pdl/library/css/theme-calculator.css +18 -0
  92. package/console/pdl/library/css/thumb-choice.css +69 -0
  93. package/console/pdl/library/css/tweaks.css +16 -0
  94. package/console/pdl/library/css/widgets.css +211 -0
  95. package/console/pdl/library/css/workbench.css +59 -0
  96. package/console/pdl/library/feedback.js +83 -0
  97. package/console/pdl/library/floating-window.mjs +100 -0
  98. package/console/pdl/library/fold.js +238 -0
  99. package/console/pdl/library/format.js +53 -0
  100. package/console/pdl/library/frames.js +123 -0
  101. package/console/pdl/library/icons.js +165 -0
  102. package/console/pdl/library/identity.js +149 -0
  103. package/console/pdl/library/inputs.js +801 -0
  104. package/console/pdl/library/label-search.js +214 -0
  105. package/console/pdl/library/markdown-text.js +115 -0
  106. package/console/pdl/library/markdown.js +150 -0
  107. package/console/pdl/library/media-viewer.js +293 -0
  108. package/console/pdl/library/member-select.mjs +32 -0
  109. package/console/pdl/library/message.js +105 -0
  110. package/console/pdl/library/motion.js +56 -0
  111. package/console/pdl/library/overlays.js +165 -0
  112. package/console/pdl/library/page.js +142 -0
  113. package/console/pdl/library/plugin-form.js +154 -0
  114. package/console/pdl/library/registry.js +198 -0
  115. package/console/pdl/library/rows.js +523 -0
  116. package/console/pdl/library/shell.js +151 -0
  117. package/console/pdl/library/stream.js +58 -0
  118. package/console/pdl/library/tabs.js +259 -0
  119. package/console/pdl/library/theme-calculator.js +300 -0
  120. package/console/pdl/library/widgets.js +114 -0
  121. package/console/pdl/load-order.json +74 -0
  122. package/console/pdl/platform/README.md +3 -0
  123. package/console/pdl/platform/rich-markdown.mjs +17 -0
  124. package/console/pdl/platform/web-links.js +26 -0
  125. package/console/pdl/platform/web.js +80 -0
  126. package/console/sdk-browser/mentions.d.mts +16 -0
  127. package/console/sdk-browser/mentions.mjs +84 -0
  128. package/console/theme/assets.js +21 -0
  129. package/console/theme/theme.json +9417 -0
  130. package/console/theme/tokens.json +444 -0
  131. package/dist/core/a2a.d.ts +288 -0
  132. package/dist/core/a2a.js +2197 -0
  133. package/dist/core/address.d.ts +34 -0
  134. package/dist/core/address.js +33 -0
  135. package/dist/core/approval-inputs.d.ts +17 -0
  136. package/dist/core/approval-inputs.js +70 -0
  137. package/dist/core/archive.d.ts +19 -0
  138. package/dist/core/archive.js +135 -0
  139. package/dist/core/attachments.d.ts +17 -0
  140. package/dist/core/attachments.js +143 -0
  141. package/dist/core/blocked-handoffs.d.ts +132 -0
  142. package/dist/core/blocked-handoffs.js +349 -0
  143. package/dist/core/config-schema.d.ts +124 -0
  144. package/dist/core/config-schema.js +192 -0
  145. package/dist/core/config.d.ts +117 -0
  146. package/dist/core/config.js +638 -0
  147. package/dist/core/disk-usage.d.ts +26 -0
  148. package/dist/core/disk-usage.js +83 -0
  149. package/dist/core/documents.d.ts +9 -0
  150. package/dist/core/documents.js +48 -0
  151. package/dist/core/entry.d.ts +316 -0
  152. package/dist/core/entry.js +711 -0
  153. package/dist/core/home.d.ts +76 -0
  154. package/dist/core/home.js +449 -0
  155. package/dist/core/i18n.d.ts +36 -0
  156. package/dist/core/i18n.js +458 -0
  157. package/dist/core/instances.d.ts +224 -0
  158. package/dist/core/instances.js +1272 -0
  159. package/dist/core/members.d.ts +190 -0
  160. package/dist/core/members.js +358 -0
  161. package/dist/core/mentions.d.ts +12 -0
  162. package/dist/core/mentions.js +49 -0
  163. package/dist/core/messages.d.ts +876 -0
  164. package/dist/core/messages.js +916 -0
  165. package/dist/core/notices.d.ts +88 -0
  166. package/dist/core/notices.js +54 -0
  167. package/dist/core/ops.d.ts +117 -0
  168. package/dist/core/ops.js +146 -0
  169. package/dist/core/package.d.ts +2 -0
  170. package/dist/core/package.js +14 -0
  171. package/dist/core/parts.d.ts +25 -0
  172. package/dist/core/parts.js +119 -0
  173. package/dist/core/plugins/catalog.d.ts +14 -0
  174. package/dist/core/plugins/catalog.js +54 -0
  175. package/dist/core/plugins/external.d.ts +7 -0
  176. package/dist/core/plugins/external.js +921 -0
  177. package/dist/core/plugins/index.d.ts +5 -0
  178. package/dist/core/plugins/index.js +51 -0
  179. package/dist/core/plugins/npm.d.ts +12 -0
  180. package/dist/core/plugins/npm.js +99 -0
  181. package/dist/core/plugins/plugin-manifest.d.ts +12 -0
  182. package/dist/core/plugins/plugin-manifest.js +231 -0
  183. package/dist/core/push.d.ts +22 -0
  184. package/dist/core/push.js +63 -0
  185. package/dist/core/resource.d.ts +77 -0
  186. package/dist/core/resource.js +48 -0
  187. package/dist/core/spawn.d.ts +12 -0
  188. package/dist/core/spawn.js +30 -0
  189. package/dist/core/storage-inventory.d.ts +118 -0
  190. package/dist/core/storage-inventory.js +279 -0
  191. package/dist/core/storage.d.ts +45 -0
  192. package/dist/core/storage.js +602 -0
  193. package/dist/core/store.d.ts +15 -0
  194. package/dist/core/store.js +33 -0
  195. package/dist/core/topic-index.d.ts +19 -0
  196. package/dist/core/topic-index.js +70 -0
  197. package/dist/core/topic-ops.d.ts +139 -0
  198. package/dist/core/topic-ops.js +507 -0
  199. package/dist/core/topic-status.d.ts +32 -0
  200. package/dist/core/topic-status.js +105 -0
  201. package/dist/core/topics.d.ts +327 -0
  202. package/dist/core/topics.js +786 -0
  203. package/dist/core/turn-clients.d.ts +1 -0
  204. package/dist/core/turn-clients.js +5 -0
  205. package/dist/core/types.d.ts +2866 -0
  206. package/dist/core/types.js +166 -0
  207. package/dist/core/util.d.ts +10 -0
  208. package/dist/core/util.js +47 -0
  209. package/dist/main.d.ts +12 -0
  210. package/dist/main.js +82 -0
  211. package/dist/plugins/adapter-acp/index.d.ts +3 -0
  212. package/dist/plugins/adapter-acp/index.js +57 -0
  213. package/dist/plugins/adapter-acp/plugin.yaml +100 -0
  214. package/dist/plugins/adapter-agy/command.d.ts +9 -0
  215. package/dist/plugins/adapter-agy/command.js +34 -0
  216. package/dist/plugins/adapter-agy/index.d.ts +5 -0
  217. package/dist/plugins/adapter-agy/index.js +65 -0
  218. package/dist/plugins/adapter-agy/quota.d.ts +2 -0
  219. package/dist/plugins/adapter-agy/quota.js +155 -0
  220. package/dist/plugins/adapter-agy/terminal.d.ts +6 -0
  221. package/dist/plugins/adapter-agy/terminal.js +132 -0
  222. package/dist/plugins/adapter-agy/version.d.ts +9 -0
  223. package/dist/plugins/adapter-agy/version.js +17 -0
  224. package/dist/plugins/adapter-claude/index.d.ts +43 -0
  225. package/dist/plugins/adapter-claude/index.js +412 -0
  226. package/dist/plugins/adapter-claude/quota.d.ts +14 -0
  227. package/dist/plugins/adapter-claude/quota.js +103 -0
  228. package/dist/plugins/adapter-codex/index.d.ts +4 -0
  229. package/dist/plugins/adapter-codex/index.js +688 -0
  230. package/dist/plugins/adapter-codex/responses-model.d.ts +9 -0
  231. package/dist/plugins/adapter-codex/responses-model.js +82 -0
  232. package/dist/plugins/adapter-kimi/index.d.ts +4 -0
  233. package/dist/plugins/adapter-kimi/index.js +51 -0
  234. package/dist/plugins/adapter-kimi/quota.d.ts +3 -0
  235. package/dist/plugins/adapter-kimi/quota.js +171 -0
  236. package/dist/plugins/adapter-opencode/index.d.ts +12 -0
  237. package/dist/plugins/adapter-opencode/index.js +64 -0
  238. package/dist/plugins/annotations/console/cards.css +189 -0
  239. package/dist/plugins/annotations/console/cards.mjs +439 -0
  240. package/dist/plugins/annotations/console/pdl.json +52 -0
  241. package/dist/plugins/annotations/console/view.mjs +241 -0
  242. package/dist/plugins/annotations/console/window.mjs +219 -0
  243. package/dist/plugins/annotations/followups.d.ts +51 -0
  244. package/dist/plugins/annotations/followups.js +112 -0
  245. package/dist/plugins/annotations/index.d.ts +3 -0
  246. package/dist/plugins/annotations/index.js +298 -0
  247. package/dist/plugins/annotations/plugin.yaml +3 -0
  248. package/dist/plugins/ask-choice/index.d.ts +9 -0
  249. package/dist/plugins/ask-choice/index.js +24 -0
  250. package/dist/plugins/ask-choice/plugin.yaml +2 -0
  251. package/dist/plugins/background/index.d.ts +2 -0
  252. package/dist/plugins/background/index.js +398 -0
  253. package/dist/plugins/background/plugin.yaml +7 -0
  254. package/dist/plugins/builtin.json +37 -0
  255. package/dist/plugins/cards/console/pdl.json +516 -0
  256. package/dist/plugins/cards/console/view.mjs +67 -0
  257. package/dist/plugins/cards/index.d.ts +8 -0
  258. package/dist/plugins/cards/index.js +627 -0
  259. package/dist/plugins/cards/plugin.yaml +3 -0
  260. package/dist/plugins/console/browser.d.ts +2 -0
  261. package/dist/plugins/console/browser.js +115 -0
  262. package/dist/plugins/console/console/pdl.json +38 -0
  263. package/dist/plugins/console/console/view.mjs +26 -0
  264. package/dist/plugins/console/index.d.ts +4 -0
  265. package/dist/plugins/console/index.js +94 -0
  266. package/dist/plugins/console/picker.d.ts +2 -0
  267. package/dist/plugins/console/picker.js +48 -0
  268. package/dist/plugins/console/plugin.yaml +3 -0
  269. package/dist/plugins/console/topic-view.d.ts +3 -0
  270. package/dist/plugins/console/topic-view.js +388 -0
  271. package/dist/plugins/handoff/index.d.ts +2 -0
  272. package/dist/plugins/handoff/index.js +147 -0
  273. package/dist/plugins/handoff/plugin.yaml +8 -0
  274. package/dist/plugins/host-api/index.d.ts +7 -0
  275. package/dist/plugins/host-api/index.js +310 -0
  276. package/dist/plugins/host-api/plugin.yaml +2 -0
  277. package/dist/plugins/host-api/signing.d.ts +63 -0
  278. package/dist/plugins/host-api/signing.js +427 -0
  279. package/dist/plugins/host-api/skills/host-ops/SKILL.md +28 -0
  280. package/dist/plugins/host-api/skills/hostlet-plugin-dev/SKILL.md +38 -0
  281. package/dist/plugins/inbox/index.d.ts +15 -0
  282. package/dist/plugins/inbox/index.js +161 -0
  283. package/dist/plugins/inbox/plugin.yaml +2 -0
  284. package/dist/plugins/keys/account-directories.d.ts +18 -0
  285. package/dist/plugins/keys/account-directories.js +86 -0
  286. package/dist/plugins/keys/account-storage.d.ts +18 -0
  287. package/dist/plugins/keys/account-storage.js +112 -0
  288. package/dist/plugins/keys/console/pdl.json +710 -0
  289. package/dist/plugins/keys/console/view.mjs +619 -0
  290. package/dist/plugins/keys/index.d.ts +7 -0
  291. package/dist/plugins/keys/index.js +842 -0
  292. package/dist/plugins/keys/login-link.d.ts +2 -0
  293. package/dist/plugins/keys/login-link.js +15 -0
  294. package/dist/plugins/keys/plugin.yaml +3 -0
  295. package/dist/plugins/keys/quota-history.d.ts +91 -0
  296. package/dist/plugins/keys/quota-history.js +420 -0
  297. package/dist/plugins/mcp/console/pdl.json +412 -0
  298. package/dist/plugins/mcp/console/view.mjs +207 -0
  299. package/dist/plugins/mcp/index.d.ts +7 -0
  300. package/dist/plugins/mcp/index.js +494 -0
  301. package/dist/plugins/mcp/plugin.yaml +3 -0
  302. package/dist/plugins/member-health/index.d.ts +2 -0
  303. package/dist/plugins/member-health/index.js +478 -0
  304. package/dist/plugins/member-health/plugin.yaml +2 -0
  305. package/dist/plugins/memory/capabilities.d.ts +10 -0
  306. package/dist/plugins/memory/capabilities.js +70 -0
  307. package/dist/plugins/memory/console/pdl.json +459 -0
  308. package/dist/plugins/memory/console/view.mjs +254 -0
  309. package/dist/plugins/memory/corpus.d.ts +60 -0
  310. package/dist/plugins/memory/corpus.js +521 -0
  311. package/dist/plugins/memory/engines/fts-tree-diversity.d.ts +8 -0
  312. package/dist/plugins/memory/engines/fts-tree-diversity.js +49 -0
  313. package/dist/plugins/memory/engines/fts-tree-text.d.ts +12 -0
  314. package/dist/plugins/memory/engines/fts-tree-text.js +93 -0
  315. package/dist/plugins/memory/engines/fts-tree.d.ts +4 -0
  316. package/dist/plugins/memory/engines/fts-tree.js +387 -0
  317. package/dist/plugins/memory/engines/search.d.ts +9 -0
  318. package/dist/plugins/memory/engines/search.js +35 -0
  319. package/dist/plugins/memory/index.d.ts +3 -0
  320. package/dist/plugins/memory/index.js +465 -0
  321. package/dist/plugins/memory/notes.d.ts +22 -0
  322. package/dist/plugins/memory/notes.js +140 -0
  323. package/dist/plugins/memory/plugin.yaml +23 -0
  324. package/dist/plugins/model-profiles/index.d.ts +2 -0
  325. package/dist/plugins/model-profiles/index.js +916 -0
  326. package/dist/plugins/model-profiles/plugin.yaml +13 -0
  327. package/dist/plugins/model-profiles/review-source.d.ts +11 -0
  328. package/dist/plugins/model-profiles/review-source.js +640 -0
  329. package/dist/plugins/model-profiles/rules.d.ts +130 -0
  330. package/dist/plugins/model-profiles/rules.js +729 -0
  331. package/dist/plugins/model-profiles/skills/model-profile/SKILL.md +59 -0
  332. package/dist/plugins/model-profiles/sources.d.ts +61 -0
  333. package/dist/plugins/model-profiles/sources.js +375 -0
  334. package/dist/plugins/model-profiles/storage.d.ts +84 -0
  335. package/dist/plugins/model-profiles/storage.js +315 -0
  336. package/dist/plugins/model-profiles/types.d.ts +179 -0
  337. package/dist/plugins/model-profiles/types.js +12 -0
  338. package/dist/plugins/model-profiles/wakeup.d.ts +29 -0
  339. package/dist/plugins/model-profiles/wakeup.js +390 -0
  340. package/dist/plugins/models/index.d.ts +2 -0
  341. package/dist/plugins/models/index.js +63 -0
  342. package/dist/plugins/models/plugin.yaml +8 -0
  343. package/dist/plugins/ops/collector.d.ts +22 -0
  344. package/dist/plugins/ops/collector.js +48 -0
  345. package/dist/plugins/ops/config.d.ts +11 -0
  346. package/dist/plugins/ops/config.js +13 -0
  347. package/dist/plugins/ops/console/pdl.json +676 -0
  348. package/dist/plugins/ops/console/view.mjs +700 -0
  349. package/dist/plugins/ops/index.d.ts +3 -0
  350. package/dist/plugins/ops/index.js +20 -0
  351. package/dist/plugins/ops/journal.d.ts +7 -0
  352. package/dist/plugins/ops/journal.js +109 -0
  353. package/dist/plugins/ops/metrics.d.ts +3 -0
  354. package/dist/plugins/ops/metrics.js +81 -0
  355. package/dist/plugins/ops/plugin.yaml +63 -0
  356. package/dist/plugins/ops/samples.d.ts +54 -0
  357. package/dist/plugins/ops/samples.js +100 -0
  358. package/dist/plugins/ops/trace.d.ts +3 -0
  359. package/dist/plugins/ops/trace.js +104 -0
  360. package/dist/plugins/ops/usage.d.ts +2 -0
  361. package/dist/plugins/ops/usage.js +152 -0
  362. package/dist/plugins/plans/acceptance.d.ts +284 -0
  363. package/dist/plugins/plans/acceptance.js +247 -0
  364. package/dist/plugins/plans/blocked.d.ts +25 -0
  365. package/dist/plugins/plans/blocked.js +66 -0
  366. package/dist/plugins/plans/console/pdl.json +639 -0
  367. package/dist/plugins/plans/console/view.d.mts +2 -0
  368. package/dist/plugins/plans/console/view.mjs +855 -0
  369. package/dist/plugins/plans/dependencies.d.ts +5 -0
  370. package/dist/plugins/plans/dependencies.js +21 -0
  371. package/dist/plugins/plans/index.d.ts +72 -0
  372. package/dist/plugins/plans/index.js +2057 -0
  373. package/dist/plugins/plans/plugin.yaml +44 -0
  374. package/dist/plugins/plans/progress.d.ts +82 -0
  375. package/dist/plugins/plans/progress.js +516 -0
  376. package/dist/plugins/prompt/index.d.ts +8 -0
  377. package/dist/plugins/prompt/index.js +361 -0
  378. package/dist/plugins/prompt/plugin.yaml +2 -0
  379. package/dist/plugins/recovery/console/pdl.json +50 -0
  380. package/dist/plugins/recovery/console/view.mjs +46 -0
  381. package/dist/plugins/recovery/index.d.ts +9 -0
  382. package/dist/plugins/recovery/index.js +454 -0
  383. package/dist/plugins/recovery/plugin.yaml +9 -0
  384. package/dist/plugins/recovery/probe.d.ts +11 -0
  385. package/dist/plugins/recovery/probe.js +128 -0
  386. package/dist/plugins/restart/console/pdl.json +112 -0
  387. package/dist/plugins/restart/console/view.mjs +85 -0
  388. package/dist/plugins/restart/index.d.ts +10 -0
  389. package/dist/plugins/restart/index.js +669 -0
  390. package/dist/plugins/restart/plugin.yaml +9 -0
  391. package/dist/plugins/restart/scope.d.ts +6 -0
  392. package/dist/plugins/restart/scope.js +44 -0
  393. package/dist/plugins/schedule/console/pdl.json +696 -0
  394. package/dist/plugins/schedule/console/view.mjs +398 -0
  395. package/dist/plugins/schedule/events.d.ts +76 -0
  396. package/dist/plugins/schedule/events.js +158 -0
  397. package/dist/plugins/schedule/index.d.ts +32 -0
  398. package/dist/plugins/schedule/index.js +1199 -0
  399. package/dist/plugins/schedule/plugin.yaml +26 -0
  400. package/dist/plugins/schedule/when.d.ts +14 -0
  401. package/dist/plugins/schedule/when.js +83 -0
  402. package/dist/plugins/sessions/console/pdl.json +259 -0
  403. package/dist/plugins/sessions/console/view.mjs +355 -0
  404. package/dist/plugins/sessions/index.d.ts +3 -0
  405. package/dist/plugins/sessions/index.js +126 -0
  406. package/dist/plugins/sessions/participants.d.ts +28 -0
  407. package/dist/plugins/sessions/participants.js +83 -0
  408. package/dist/plugins/sessions/plugin.yaml +3 -0
  409. package/dist/plugins/signals/console/pdl.json +802 -0
  410. package/dist/plugins/signals/console/view.mjs +284 -0
  411. package/dist/plugins/signals/content.d.ts +31 -0
  412. package/dist/plugins/signals/content.js +151 -0
  413. package/dist/plugins/signals/index.d.ts +2 -0
  414. package/dist/plugins/signals/index.js +601 -0
  415. package/dist/plugins/signals/plugin.yaml +32 -0
  416. package/dist/plugins/signals/skills/signal-sources/SKILL.md +27 -0
  417. package/dist/plugins/skills/console/pdl.json +254 -0
  418. package/dist/plugins/skills/console/view.mjs +204 -0
  419. package/dist/plugins/skills/index.d.ts +11 -0
  420. package/dist/plugins/skills/index.js +567 -0
  421. package/dist/plugins/skills/install.d.ts +69 -0
  422. package/dist/plugins/skills/install.js +265 -0
  423. package/dist/plugins/skills/plugin.yaml +24 -0
  424. package/dist/plugins/skills/safety-scan.d.ts +17 -0
  425. package/dist/plugins/skills/safety-scan.js +78 -0
  426. package/dist/plugins/skills/skills/skill-ops/SKILL.md +29 -0
  427. package/dist/plugins/terminal/console/pdl.json +115 -0
  428. package/dist/plugins/terminal/console/view.mjs +178 -0
  429. package/dist/plugins/terminal/index.d.ts +3 -0
  430. package/dist/plugins/terminal/index.js +204 -0
  431. package/dist/plugins/terminal/plugin.yaml +2 -0
  432. package/dist/plugins/tools/index.d.ts +3 -0
  433. package/dist/plugins/tools/index.js +455 -0
  434. package/dist/plugins/tools/plugin.yaml +2 -0
  435. package/dist/plugins/tools/token.d.ts +61 -0
  436. package/dist/plugins/tools/token.js +179 -0
  437. package/dist/plugins/topic-tools/index.d.ts +9 -0
  438. package/dist/plugins/topic-tools/index.js +29 -0
  439. package/dist/plugins/topic-tools/plugin.yaml +2 -0
  440. package/dist/plugins/topic-tools/skills/topic-tidy/SKILL.md +108 -0
  441. package/dist/plugins/works/console/pdl.json +120 -0
  442. package/dist/plugins/works/console/view.mjs +91 -0
  443. package/dist/plugins/works/document-words.d.ts +50 -0
  444. package/dist/plugins/works/document-words.js +27 -0
  445. package/dist/plugins/works/editors.d.ts +3 -0
  446. package/dist/plugins/works/editors.js +162 -0
  447. package/dist/plugins/works/events.d.ts +58 -0
  448. package/dist/plugins/works/events.js +82 -0
  449. package/dist/plugins/works/files.d.ts +23 -0
  450. package/dist/plugins/works/files.js +53 -0
  451. package/dist/plugins/works/index.d.ts +9 -0
  452. package/dist/plugins/works/index.js +1088 -0
  453. package/dist/plugins/works/plugin.yaml +9 -0
  454. package/dist/plugins/works/preview.d.ts +10 -0
  455. package/dist/plugins/works/preview.js +30 -0
  456. package/dist/plugins/works/project.d.ts +3 -0
  457. package/dist/plugins/works/project.js +245 -0
  458. package/dist/plugins/works/resource.d.ts +28 -0
  459. package/dist/plugins/works/resource.js +71 -0
  460. package/dist/plugins/works/retention.d.ts +36 -0
  461. package/dist/plugins/works/retention.js +295 -0
  462. package/dist/plugins/works/skills/works-ops/SKILL.md +14 -0
  463. package/dist/plugins/works/viewers.d.ts +13 -0
  464. package/dist/plugins/works/viewers.js +87 -0
  465. package/dist/plugins/works/web/anchors.js +94 -0
  466. package/dist/plugins/works/web/document-edit.js +245 -0
  467. package/dist/plugins/works/web/preview-bridge.js +142 -0
  468. package/dist/plugins/works/web/reading-position.js +74 -0
  469. package/dist/plugins/works/web/view.html +1118 -0
  470. package/dist/runtime/runtime.d.ts +210 -0
  471. package/dist/runtime/runtime.js +338 -0
  472. package/dist/sdk/adapter-kit.d.ts +1 -0
  473. package/dist/sdk/adapter-kit.js +1 -0
  474. package/dist/sdk/client.d.ts +163 -0
  475. package/dist/sdk/client.js +43 -0
  476. package/dist/sdk/contracts.d.ts +1263 -0
  477. package/dist/sdk/contracts.js +1 -0
  478. package/dist/sdk/index.d.ts +57 -0
  479. package/dist/sdk/index.js +27 -0
  480. package/dist/sdk/source-choice.d.ts +40 -0
  481. package/dist/sdk/source-choice.js +217 -0
  482. package/dist/sdk/topic-text.d.ts +5 -0
  483. package/dist/sdk/topic-text.js +26 -0
  484. package/dist/sdk/transport.d.ts +12 -0
  485. package/dist/sdk/transport.js +34 -0
  486. package/node_modules/@hostlet/adapter-kit/dist/acp.d.ts +88 -0
  487. package/node_modules/@hostlet/adapter-kit/dist/acp.js +674 -0
  488. package/node_modules/@hostlet/adapter-kit/dist/command.d.ts +18 -0
  489. package/node_modules/@hostlet/adapter-kit/dist/command.js +39 -0
  490. package/node_modules/@hostlet/adapter-kit/dist/index.d.ts +8 -0
  491. package/node_modules/@hostlet/adapter-kit/dist/index.js +6 -0
  492. package/node_modules/@hostlet/adapter-kit/dist/models.d.ts +29 -0
  493. package/node_modules/@hostlet/adapter-kit/dist/models.js +108 -0
  494. package/node_modules/@hostlet/adapter-kit/dist/quota.d.ts +3 -0
  495. package/node_modules/@hostlet/adapter-kit/dist/quota.js +4 -0
  496. package/node_modules/@hostlet/adapter-kit/dist/rpc.d.ts +29 -0
  497. package/node_modules/@hostlet/adapter-kit/dist/rpc.js +84 -0
  498. package/node_modules/@hostlet/adapter-kit/dist/upstream-failure.d.ts +5 -0
  499. package/node_modules/@hostlet/adapter-kit/dist/upstream-failure.js +37 -0
  500. package/node_modules/@hostlet/adapter-kit/package.json +16 -0
  501. package/node_modules/@hostlet/platform/dist/desktop.d.ts +16 -0
  502. package/node_modules/@hostlet/platform/dist/desktop.js +270 -0
  503. package/node_modules/@hostlet/platform/dist/files.d.ts +24 -0
  504. package/node_modules/@hostlet/platform/dist/files.js +113 -0
  505. package/node_modules/@hostlet/platform/dist/index.d.ts +6 -0
  506. package/node_modules/@hostlet/platform/dist/index.js +4 -0
  507. package/node_modules/@hostlet/platform/dist/paths.d.ts +4 -0
  508. package/node_modules/@hostlet/platform/dist/paths.js +9 -0
  509. package/node_modules/@hostlet/platform/dist/process.d.ts +45 -0
  510. package/node_modules/@hostlet/platform/dist/process.js +297 -0
  511. package/node_modules/@hostlet/platform/package.json +14 -0
  512. package/package.json +60 -4
@@ -0,0 +1,688 @@
1
+ import { realpathSync } from 'node:fs';
2
+ import { tmpdir } from 'node:os';
3
+ import { join } from 'node:path';
4
+ import { commandLine, detectCommand, catalogOutput, configuredContextWindow, contextWindowOption, keyedModel, keyedOptions, modelWindowFill, windowTokens, RpcFailure, startRpc, stopRpc, classifiedError, upstreamCode, upstreamStatus, } from '@hostlet/adapter-kit';
5
+ import { errorText, firstLine, onPath, SessionGoneError, startChild, TurnFailureError } from 'hostlet/sdk';
6
+ import { ResponsesModels, responsesTracing } from "./responses-model.js";
7
+ /** Clears inherited Codex/OpenAI auth variables for spawned child processes without touching host or system config. */
8
+ const CODEX_CLEAN_AUTH_ENV = {
9
+ OPENAI_API_KEY: undefined,
10
+ CODEX_API_KEY: undefined,
11
+ };
12
+ const CODEX_FILE_STORE_ARGS = ['-c', 'cli_auth_credentials_store="file"'];
13
+ // Codex rebuilds a fresh TLS client per analytics event, causing connection storms across managed app-server instances.
14
+ const CODEX_DISABLE_ANALYTICS_ARGS = ['-c', 'analytics.enabled=false'];
15
+ // The owner's Codex config can load desktop-control servers from the ChatGPT app (Computer Use, the CUA/node REPL)
16
+ // and a turn-ended hook that wakes them. They drive the owner's own browser and apps without Hostlet's approval cards,
17
+ // so managed instances turn them off and leave members the host's headless browser and approved computer-use tools.
18
+ const CODEX_DESKTOP_SERVERS = ['computer-use', 'cua_repl', 'node_repl', 'codex_app'];
19
+ const CODEX_DESKTOP_FEATURES = ['computer_use', 'browser_use', 'browser_use_external', 'in_app_browser'];
20
+ const CODEX_NO_DESKTOP_ARGS = [...CODEX_DESKTOP_FEATURES.flatMap((name) => ['-c', `features.${name}=false`]), '-c', 'notify=[]'];
21
+ /**
22
+ * Thread settings that keep the desktop-control servers from starting. Plugin toggles are ignored by app-server 0.172,
23
+ * so the servers are turned off by name, against the configuration this app-server actually loaded: a server it
24
+ * already has keeps its own transport; one only a plugin adds needs a placeholder transport to parse, and is never run.
25
+ * Without a readable configuration every server gets the placeholder, which only an HTTP server of the same name rejects.
26
+ */
27
+ async function desktopOff(peer, cwd) {
28
+ const loaded = await peer.request('config/read', { cwd }, 30_000)
29
+ .then(({ config }) => config?.mcp_servers ?? {}, () => ({}));
30
+ return Object.fromEntries(CODEX_DESKTOP_SERVERS.flatMap((name) => [
31
+ ...(Object.hasOwn(loaded, name) ? [] : [[`mcp_servers.${name}.command`, 'false']]),
32
+ [`mcp_servers.${name}.enabled`, false],
33
+ ]));
34
+ }
35
+ /**
36
+ * Codex through `codex app-server`: one long-lived process per instance, one Codex thread per session.
37
+ * Adding input to a running turn is `turn/steer`; stopping one is `turn/interrupt`.
38
+ */
39
+ const CLIENT = { name: 'hostlet', title: 'hostlet', version: '0.1.0' };
40
+ const APPROVAL_METHODS = ['item/commandExecution/requestApproval', 'item/fileChange/requestApproval', 'execCommandApproval', 'applyPatchApproval'];
41
+ const APPROVAL_OPTIONS = [
42
+ { id: 'accept', label: '允许这一次', kind: 'allow_once' },
43
+ { id: 'acceptForSession', label: '本次会话都允许', kind: 'allow_always' },
44
+ { id: 'decline', label: '拒绝', kind: 'reject_once' },
45
+ ];
46
+ const text = (value) => [{ type: 'text', text: value, text_elements: [] }];
47
+ const COMMAND = 'codex app-server';
48
+ const RESUME_INSTRUCTIONS_METHOD = 'thread/inject_items';
49
+ const STANDARD_TIER = 'default';
50
+ // Responses diagnostics may be delivered after the completion on the independent protocol pipe.
51
+ const MODEL_EVIDENCE_GRACE_MS = 200;
52
+ const FOLLOW_DEFAULT = { value: '', label: '跟随默认' };
53
+ const SESSION_LIMIT = 200;
54
+ function codexFailure(info) {
55
+ switch (info) {
56
+ case 'usageLimitExceeded':
57
+ case 'apiKeySpendLimitExceeded':
58
+ case 'projectSpendLimitExceeded':
59
+ case 'organizationSpendLimitExceeded':
60
+ case 'unauthorized':
61
+ return 'account';
62
+ case 'serverOverloaded':
63
+ case 'internalServerError':
64
+ case 'modelNotFound':
65
+ case 'flexUnavailable':
66
+ return 'provider';
67
+ }
68
+ if (!info || typeof info !== 'object')
69
+ return;
70
+ const variants = info;
71
+ for (const name of ['httpConnectionFailed', 'responseStreamConnectionFailed', 'responseStreamDisconnected']) {
72
+ const detail = variants[name];
73
+ if (detail && typeof detail === 'object') {
74
+ return upstreamStatus(detail.httpStatusCode) ?? (detail.httpStatusCode == null ? 'network' : undefined);
75
+ }
76
+ }
77
+ return upstreamStatus(variants.responseTooManyFailedAttempts?.httpStatusCode);
78
+ }
79
+ function rpcFailure(error) {
80
+ if (error instanceof RpcFailure) {
81
+ return codexFailure(error.data?.codexErrorInfo) ?? upstreamCode(error.data?.code) ?? upstreamStatus(error.data?.httpStatusCode);
82
+ }
83
+ }
84
+ async function connect(cwd, options, mcpServers = [], key, contextWindow, [command, ...before] = commandLine(undefined, COMMAND), env, memberEnv) {
85
+ // Codex takes MCP servers as configuration; each instance has its own process, so per-instance overrides fit.
86
+ // The host's own tools are approved as a group: a member told not to ask could otherwise never call them.
87
+ const table = (pairs = {}) => `{${Object.entries(pairs).map(([k, v]) => `${JSON.stringify(k)}=${JSON.stringify(v)}`).join(',')}}`;
88
+ const overrides = mcpServers.flatMap((server) => [
89
+ ...(server.url
90
+ ? ['-c', `mcp_servers.${server.name}.url=${JSON.stringify(server.url)}`, ...(Object.keys(server.headers ?? {}).length ? ['-c', `mcp_servers.${server.name}.http_headers=${table(server.headers)}`] : [])]
91
+ : ['-c', `mcp_servers.${server.name}.command=${JSON.stringify(server.command ?? '')}`, '-c', `mcp_servers.${server.name}.args=${JSON.stringify(server.args ?? [])}`, '-c', `mcp_servers.${server.name}.env=${table(server.env)}`]),
92
+ '-c', `mcp_servers.${server.name}.default_tools_approval_mode="approve"`,
93
+ ]);
94
+ // With an API key Codex is pointed at a model provider of its own: the address, and the variable the key is read from.
95
+ const provider = key ? ['-c', 'model_provider="hostlet"', '-c', 'model_providers.hostlet.name="hostlet"', '-c', `model_providers.hostlet.base_url=${JSON.stringify((key.endpoint ?? 'https://api.openai.com/v1').replace(/\/+$/, ''))}`, '-c', 'model_providers.hostlet.wire_api="responses"', '-c', 'model_providers.hostlet.env_key="OPENAI_API_KEY"', '-c', 'model_providers.hostlet.requires_openai_auth=false'] : [];
96
+ const store = env && !key ? [...CODEX_FILE_STORE_ARGS] : [];
97
+ const window = contextWindow === undefined ? [] : ['-c', `model_context_window=${contextWindow}`];
98
+ const authEnv = key ? { ...CODEX_CLEAN_AUTH_ENV, OPENAI_API_KEY: key.apiKey } : env;
99
+ const baseEnv = { ...memberEnv, ...authEnv };
100
+ const childEnv = options.onStderrLine ? { ...baseEnv, RUST_LOG: responsesTracing(baseEnv) } : baseEnv;
101
+ const peer = startRpc(command, [...before, ...CODEX_DISABLE_ANALYTICS_ARGS, ...CODEX_NO_DESKTOP_ARGS, ...overrides, ...provider, ...store, ...window], { cwd, tagged: false, startChild, env: childEnv, ...options });
102
+ try {
103
+ await peer.request('initialize', { clientInfo: CLIENT, capabilities: { experimentalApi: true, requestAttestation: false } }, 30_000);
104
+ }
105
+ catch (error) {
106
+ await stopRpc(peer, true);
107
+ throw error;
108
+ }
109
+ peer.notify('initialized');
110
+ return peer;
111
+ }
112
+ /** A short-lived server for queries that need no loaded thread. */
113
+ async function query(read, { command, key, env, memberEnv }) {
114
+ const peer = await connect(tmpdir(), { onNotification() { }, onRequest: (id) => peer.reject(id, 'not available') }, [], key, undefined, command, env, memberEnv);
115
+ try {
116
+ return await read(peer);
117
+ }
118
+ finally {
119
+ await stopRpc(peer, true);
120
+ }
121
+ }
122
+ function messageType(phase) {
123
+ if (phase === 'commentary')
124
+ return 'thinking';
125
+ if (phase === 'partial_answer' || phase === 'final_answer')
126
+ return 'text';
127
+ }
128
+ function agentMessage(turn, id) {
129
+ let message = turn.messages.get(id);
130
+ if (!message)
131
+ turn.messages.set(id, message = { pending: '', emitted: 0 });
132
+ return message;
133
+ }
134
+ function open(ctx) {
135
+ let peer;
136
+ let threadId = '';
137
+ let configuredModel;
138
+ let alias;
139
+ const observed = new ResponsesModels();
140
+ let windowOverride;
141
+ let turnSettings = {};
142
+ let stopping = false;
143
+ let turn;
144
+ let checkModelEvidence;
145
+ const asks = new Map();
146
+ const emitMessage = (current, id, message, delta) => {
147
+ if (!delta)
148
+ return;
149
+ message.emitted += delta.length;
150
+ if (message.type === 'thinking')
151
+ ctx.emit({ type: 'thinking', turn: current.id, delta });
152
+ else
153
+ ctx.emit({ type: 'text', turn: current.id, delta, message: id });
154
+ };
155
+ const flushMessages = (current) => {
156
+ for (const [id, message] of current.messages)
157
+ emitMessage(current, id, message, message.pending);
158
+ };
159
+ const reportModel = (current, model, expected) => ctx.emit({ type: 'model', turn: current.id, model, ...(expected ? { configuredModel: expected } : {}) });
160
+ const modelOf = (current) => current.reroutedModel ?? observed.modelFor(threadId, current.startedAt, current.replyItems);
161
+ const waitForModel = (current) => {
162
+ const item = [...current.replyItems].at(-1);
163
+ const lastReply = item ? new Set([item]) : undefined;
164
+ const ready = () => current.reroutedModel ?? (lastReply
165
+ ? observed.modelFor(threadId, current.startedAt, lastReply, false)
166
+ : modelOf(current));
167
+ const known = ready();
168
+ if (known || !current.codexId)
169
+ return Promise.resolve(known);
170
+ return new Promise((resolve) => {
171
+ const finish = (model) => {
172
+ clearTimeout(deadline);
173
+ checkModelEvidence = undefined;
174
+ resolve(model);
175
+ };
176
+ // A thread-wide observation can describe a preceding tool step. Prefer the final reply if its trace is still arriving.
177
+ const deadline = setTimeout(() => finish(modelOf(current)), MODEL_EVIDENCE_GRACE_MS);
178
+ checkModelEvidence = () => {
179
+ const reported = ready();
180
+ if (reported)
181
+ finish(reported);
182
+ };
183
+ });
184
+ };
185
+ const resolveAlias = (model) => {
186
+ const requested = configuredModel;
187
+ if (!requested || requested === model)
188
+ return;
189
+ if (requested.toLowerCase() === model.toLowerCase())
190
+ return model;
191
+ // Resolve an alias against the client's own catalog, independently of what the reply reported.
192
+ return alias ??= peer.request('model/list', { includeHidden: true }, 1000)
193
+ .then(({ data }) => data?.find(({ id }) => id === requested)?.model)
194
+ .catch(() => undefined);
195
+ };
196
+ const end = async (outcome, error, failure) => {
197
+ const current = turn;
198
+ if (!current || current.afterEnd)
199
+ return;
200
+ current.afterEnd = [];
201
+ const model = await waitForModel(current);
202
+ if (turn !== current)
203
+ return;
204
+ if (model) {
205
+ const expected = await resolveAlias(model);
206
+ if (turn !== current)
207
+ return;
208
+ reportModel(current, model, expected);
209
+ }
210
+ turn = undefined;
211
+ asks.clear();
212
+ flushMessages(current);
213
+ ctx.emit({ type: 'turn_end', turn: current.id, outcome, ...(error ? { error } : {}), ...(failure ? { failure } : {}) });
214
+ for (const [method, params, receivedAt] of current.afterEnd)
215
+ onNotification(method, params, receivedAt);
216
+ };
217
+ const toolOf = (item) => {
218
+ switch (item.type) {
219
+ case 'commandExecution':
220
+ return { name: 'shell', input: String(item.command ?? ''), output: item.aggregatedOutput ?? undefined, failed: item.status === 'failed' || (item.exitCode ?? 0) !== 0 };
221
+ case 'fileChange':
222
+ return { name: 'edit', input: (item.changes ?? []).map((c) => c.path).join('\n'), failed: item.status === 'failed' };
223
+ case 'mcpToolCall':
224
+ return { name: `${item.server}.${item.tool}`, input: JSON.stringify(item.arguments ?? {}), failed: item.status === 'failed' };
225
+ case 'webSearch':
226
+ return { name: 'web search', input: String(item.query ?? '') };
227
+ case 'collabToolCall':
228
+ case 'collabAgentToolCall':
229
+ return { name: String(item.tool ?? 'agent'), agent: true, input: String(item.prompt ?? ''), failed: item.status === 'failed' };
230
+ default:
231
+ return undefined;
232
+ }
233
+ };
234
+ const identifyTurn = (current, codexId) => {
235
+ if (current.codexId)
236
+ return;
237
+ current.codexId = codexId;
238
+ current.reroutedModel = current.reroutes?.get(codexId);
239
+ delete current.reroutes;
240
+ };
241
+ const onNotification = (method, params, receivedAt = Date.now()) => {
242
+ if (turn?.afterEnd && !(method === 'model/rerouted' && params.turnId === turn.codexId)) {
243
+ turn.afterEnd.push([method, params, receivedAt]);
244
+ return;
245
+ }
246
+ if (method === 'turn/started') {
247
+ const codexId = params.turn?.id;
248
+ if (!threadId || params.threadId !== threadId || typeof codexId !== 'string')
249
+ return;
250
+ if (turn) {
251
+ if (!turn.codexId)
252
+ identifyTurn(turn, codexId);
253
+ }
254
+ else {
255
+ turn = { id: `codex:${codexId}`, codexId, startedAt: receivedAt, replyItems: new Set(), messages: new Map() };
256
+ ctx.emit({ type: 'turn_start', turn: turn.id, origin: 'self' });
257
+ }
258
+ return;
259
+ }
260
+ if (method === 'model/rerouted') {
261
+ const { turnId, toModel } = params;
262
+ if (!turn || params.threadId !== threadId || typeof turnId !== 'string' || typeof toModel !== 'string' || !toModel.trim())
263
+ return;
264
+ if (turnId === turn.codexId) {
265
+ turn.reroutedModel = toModel.trim();
266
+ checkModelEvidence?.();
267
+ }
268
+ // Notifications can be read before the turn/start response has been handled.
269
+ else if (!turn.codexId)
270
+ (turn.reroutes ??= new Map()).set(turnId, toModel.trim());
271
+ return;
272
+ }
273
+ if (method === 'thread/tokenUsage/updated') {
274
+ const last = params.tokenUsage?.last ?? {};
275
+ const reportedWindow = windowTokens(params.tokenUsage?.modelContextWindow);
276
+ if (turn && reportedWindow !== undefined)
277
+ turn.reportedWindow = reportedWindow;
278
+ const usage = {
279
+ inputTokens: last.inputTokens, outputTokens: last.outputTokens, cachedReadTokens: last.cachedInputTokens,
280
+ totalTokens: params.tokenUsage?.total?.totalTokens,
281
+ contextSize: reportedWindow ?? turn?.reportedWindow ?? windowOverride, contextUsed: last.totalTokens,
282
+ };
283
+ ctx.emit({ type: 'usage', ...(turn ? { turn: turn.id } : {}), usage });
284
+ return;
285
+ }
286
+ if (!turn)
287
+ return;
288
+ const current = turn;
289
+ const item = params.item;
290
+ switch (method) {
291
+ case 'item/agentMessage/delta': {
292
+ const message = agentMessage(current, params.itemId);
293
+ // Older clients may omit phase; newer clients can first report it in the completed snapshot.
294
+ if (message.type)
295
+ emitMessage(current, params.itemId, message, params.delta);
296
+ else
297
+ message.pending += params.delta;
298
+ return;
299
+ }
300
+ case 'item/reasoning/summaryTextDelta':
301
+ case 'item/reasoning/textDelta':
302
+ ctx.emit({ type: 'thinking', turn: current.id, delta: params.delta });
303
+ return;
304
+ case 'item/started': {
305
+ if (item.type === 'agentMessage') {
306
+ const message = agentMessage(current, item.id);
307
+ message.type = messageType(item.phase);
308
+ if (message.type) {
309
+ emitMessage(current, item.id, message, message.pending);
310
+ message.pending = '';
311
+ }
312
+ return;
313
+ }
314
+ const tool = toolOf(item);
315
+ if (tool)
316
+ ctx.emit({ type: 'tool', turn: current.id, id: item.id, phase: 'start', name: tool.name, ...(tool.input ? { input: tool.input } : {}), ...(tool.agent ? { agent: true } : {}) });
317
+ return;
318
+ }
319
+ case 'item/completed': {
320
+ if (item.type === 'agentMessage') {
321
+ const message = agentMessage(current, item.id);
322
+ message.type ??= messageType(item.phase);
323
+ if (message.type !== 'thinking' && params.threadId === threadId && params.turnId === current.codexId
324
+ && typeof item.id === 'string')
325
+ current.replyItems.add(item.id);
326
+ const snapshot = item.text || message.pending;
327
+ if (item.text === '' && !snapshot && !message.emitted && message.type !== 'thinking') {
328
+ ctx.emit({ type: 'text', turn: current.id, delta: '', message: item.id });
329
+ }
330
+ else {
331
+ emitMessage(current, item.id, message, snapshot.slice(message.emitted));
332
+ }
333
+ current.messages.delete(item.id);
334
+ return;
335
+ }
336
+ const tool = toolOf(item);
337
+ if (tool)
338
+ ctx.emit({ type: 'tool', turn: current.id, id: item.id, phase: 'end', ...(tool.output ? { output: tool.output.slice(-4000) } : {}), ...(tool.failed ? { failed: true } : {}) });
339
+ return;
340
+ }
341
+ case 'turn/completed': {
342
+ const status = params.turn?.status;
343
+ if ((params.threadId && params.threadId !== threadId)
344
+ || (current.codexId && params.turn?.id && params.turn.id !== current.codexId))
345
+ return;
346
+ const error = params.turn?.error;
347
+ void end(status === 'completed' ? 'completed' : status === 'interrupted' ? 'canceled' : 'failed', error?.message, status === 'failed' ? codexFailure(error?.codexErrorInfo) : undefined);
348
+ return;
349
+ }
350
+ default:
351
+ return;
352
+ }
353
+ };
354
+ const onRequest = (id, method, params) => {
355
+ if (!turn || !APPROVAL_METHODS.includes(method))
356
+ return peer?.reject(id, 'hostlet does not handle this request');
357
+ const askId = String(id);
358
+ asks.set(askId, id);
359
+ const shell = method === 'item/commandExecution/requestApproval' || method === 'execCommandApproval';
360
+ const changes = method === 'applyPatchApproval' ? params.fileChanges : undefined;
361
+ const target = shell ? params.cwd : changes ? Object.keys(changes).join('、') : params.grantRoot;
362
+ const fields = [
363
+ ...(target ? [{ label: shell ? '工作目录' : '目标', value: target }] : []),
364
+ ...(params.reason ? [{ label: '理由', value: params.reason }] : []),
365
+ ];
366
+ const command = Array.isArray(params.command) ? params.command.map((arg) => JSON.stringify(arg)).join(' ') : params.command;
367
+ const code = command ? { label: '命令', text: command }
368
+ : changes ? { label: '修改内容', text: JSON.stringify(changes, null, 2) } : undefined;
369
+ ctx.emit({
370
+ type: 'ask', turn: turn.id, askId, title: shell ? '执行命令' : '修改文件', options: APPROVAL_OPTIONS,
371
+ details: { fields, ...(code ? { code } : {}) },
372
+ });
373
+ };
374
+ return {
375
+ get pid() {
376
+ return peer?.child.pid;
377
+ },
378
+ async start(input) {
379
+ const { options } = input;
380
+ const model = input.key ? keyedModel(options, ctx.member.name) : typeof options.model === 'string' ? options.model.trim() : undefined;
381
+ windowOverride = configuredContextWindow(options);
382
+ const { effort, serviceTier } = options;
383
+ turnSettings = {
384
+ ...(typeof effort === 'string' && effort ? { effort } : {}),
385
+ ...(typeof serviceTier === 'string' && serviceTier ? { serviceTier } : {}),
386
+ };
387
+ const classify = (error) => { throw classifiedError(error, rpcFailure(error), TurnFailureError); };
388
+ const started = await connect(input.cwd, {
389
+ onNotification, onRequest, member: ctx.member,
390
+ onStderrLine(line) {
391
+ const consumed = observed.read(line);
392
+ if (consumed)
393
+ checkModelEvidence?.();
394
+ return consumed;
395
+ },
396
+ }, input.mcpServers, input.key, windowOverride, commandLine(options.command, COMMAND), input.env, input.memberEnv).catch(classify);
397
+ peer = started;
398
+ void started.child.exited.then(({ code, stderr }) => {
399
+ if (stopping)
400
+ return;
401
+ if (turn) {
402
+ const current = turn;
403
+ turn = undefined;
404
+ const model = modelOf(current);
405
+ if (model)
406
+ reportModel(current, model);
407
+ flushMessages(current);
408
+ }
409
+ ctx.emit({ type: 'exit', reason: `codex app-server 退出(code ${code})${stderr ? ` ${stderr.trim().split('\n').at(-1)}` : ''}` });
410
+ });
411
+ const params = {
412
+ cwd: input.cwd,
413
+ approvalPolicy: options.approvalPolicy ?? 'never',
414
+ sandbox: options.sandbox ?? 'workspace-write',
415
+ ...(model ? { model } : {}),
416
+ config: { ...await desktopOff(started, input.cwd), ...(turnSettings.effort ? { model_reasoning_effort: turnSettings.effort } : {}) },
417
+ ...(turnSettings.serviceTier ? { serviceTier: turnSettings.serviceTier } : {}),
418
+ ...(input.systemPrompt ? { developerInstructions: input.systemPrompt } : {}),
419
+ };
420
+ const result = await (input.sessionId
421
+ ? started.request('thread/resume', { threadId: input.sessionId, ...params }, 60_000).catch((error) => {
422
+ if (error instanceof RpcFailure && !rpcFailure(error)
423
+ && /\b(?:thread|session|rollout)\b.*\bnot found\b|\bno rollout found\b/i.test(error.message)) {
424
+ throw new SessionGoneError(error.message, { cause: error });
425
+ }
426
+ throw error;
427
+ })
428
+ : started.request('thread/start', params, 60_000)).catch(classify);
429
+ threadId = result.thread.id;
430
+ if (input.sessionId && (input.opening || input.changed?.includes('prompt'))) {
431
+ // A resumed Codex thread replays its original developer message. Install the current
432
+ // Hostlet instructions in model-visible history before the next turn can start.
433
+ const instructions = input.systemPrompt
434
+ ? `以下是 Hostlet 当前的完整说明,取代此前由 Hostlet 提供的说明。\n\n${input.systemPrompt}`
435
+ : 'Hostlet 已撤回此前提供的说明,当前没有新的 Hostlet 说明。';
436
+ await started.request(RESUME_INSTRUCTIONS_METHOD, {
437
+ threadId, items: [{ type: 'message', role: 'developer', content: [{ type: 'input_text', text: instructions }] }],
438
+ }, 60_000).catch(classify);
439
+ }
440
+ configuredModel = params.model;
441
+ return threadId;
442
+ },
443
+ send(input) {
444
+ const current = { id: input.turnId, startedAt: Date.now(), replyItems: new Set(), messages: new Map() };
445
+ turn = current;
446
+ peer.request('turn/start', {
447
+ threadId, input: text(input.text), ...turnSettings,
448
+ }).then((result) => {
449
+ if (turn === current && typeof result.turn?.id === 'string')
450
+ identifyTurn(current, result.turn.id);
451
+ }, (error) => {
452
+ if (turn === current)
453
+ void end('failed', errorText(error), rpcFailure(error));
454
+ });
455
+ },
456
+ async append(input) {
457
+ if (!turn?.codexId)
458
+ throw new Error('这一轮还没开始,不能追加');
459
+ await peer.request('turn/steer', { threadId, expectedTurnId: turn.codexId, input: text(input.text) }, 15_000);
460
+ },
461
+ async interrupt() {
462
+ if (!turn)
463
+ return;
464
+ for (const id of asks.values())
465
+ peer.respond(id, { decision: 'cancel' });
466
+ asks.clear();
467
+ if (turn.codexId)
468
+ await peer.request('turn/interrupt', { threadId, turnId: turn.codexId }, 15_000);
469
+ else
470
+ end('canceled');
471
+ },
472
+ answer(askId, optionId) {
473
+ const id = asks.get(askId);
474
+ if (id === undefined)
475
+ return;
476
+ asks.delete(askId);
477
+ peer.respond(id, { decision: optionId });
478
+ },
479
+ async stop({ force }) {
480
+ stopping = true;
481
+ if (peer)
482
+ await stopRpc(peer, force);
483
+ end('canceled', '实例被停止');
484
+ },
485
+ };
486
+ }
487
+ async function modelCatalog(_fresh, key, env) {
488
+ const catalogPromise = query(async (peer) => {
489
+ const models = [];
490
+ let cursor;
491
+ do {
492
+ const page = await peer.request('model/list', { includeHidden: true, cursor }, 30_000);
493
+ models.push(...page.data);
494
+ cursor = page.nextCursor;
495
+ } while (cursor);
496
+ const config = key ? undefined : await peer.request('config/read', {}, 30_000)
497
+ .then((result) => result.config)
498
+ .catch(() => undefined);
499
+ return { models, configuredModel: config?.model, configuredWindow: windowTokens(config?.model_context_window) };
500
+ }, { key, env });
501
+ const windowsPromise = key ? Promise.resolve(undefined) : catalogOutput('codex', [...(env ? CODEX_FILE_STORE_ARGS : []), 'debug', 'models'], env)
502
+ .then((stdout) => {
503
+ const raw = JSON.parse(stdout);
504
+ return { windows: new Map(raw.models.map(({ slug, context_window }) => [slug, windowTokens(context_window)])) };
505
+ })
506
+ .catch(() => ({ windowError: 'Codex 暂时无法读取模型窗口目录' }));
507
+ const [catalog, extra] = await Promise.all([catalogPromise, windowsPromise]);
508
+ if (extra)
509
+ Object.assign(catalog, extra);
510
+ return catalog;
511
+ }
512
+ function modelControls(models, catalogError) {
513
+ const efforts = new Set(catalogError ? ['low', 'medium', 'high', 'xhigh'] : []);
514
+ const tiers = new Map([[STANDARD_TIER, '标准']]);
515
+ const allowed = new Map();
516
+ for (const model of models) {
517
+ const modelEfforts = model.supportedReasoningEfforts.map((option) => option.reasoningEffort);
518
+ for (const effort of modelEfforts)
519
+ efforts.add(effort);
520
+ const modelTiers = new Set([STANDARD_TIER]);
521
+ for (const tier of model.serviceTiers ?? []) {
522
+ modelTiers.add(tier.id);
523
+ if (tier.id !== STANDARD_TIER)
524
+ tiers.set(tier.id, tier.name);
525
+ }
526
+ if (model.defaultServiceTier) {
527
+ modelTiers.add(model.defaultServiceTier);
528
+ if (!tiers.has(model.defaultServiceTier))
529
+ tiers.set(model.defaultServiceTier, model.defaultServiceTier);
530
+ }
531
+ allowed.set(model.id, { effort: ['', ...modelEfforts], serviceTier: ['', ...modelTiers] });
532
+ }
533
+ const fields = [
534
+ { key: 'effort', label: '思考强度', kind: 'select', default: '', options: [FOLLOW_DEFAULT, ...Array.from(efforts, (value) => ({ value, label: value }))] },
535
+ { key: 'serviceTier', label: '速度', kind: 'select', default: '', options: [FOLLOW_DEFAULT, ...Array.from(tiers, ([value, label]) => ({ value, label }))] },
536
+ ];
537
+ return { fields, allowed };
538
+ }
539
+ const quotaInFlight = new Map();
540
+ async function readQuota(command, env, memberEnv) {
541
+ const result = await query((peer) => peer.request('account/rateLimits/read', {}, 30_000), { command, env, memberEnv }).catch((error) => {
542
+ // Raw app-server errors can include details of the client's own login.
543
+ throw new Error('Codex 暂时无法读取账号额度', { cause: error });
544
+ });
545
+ return ['primary', 'secondary'].flatMap((name) => {
546
+ const window = result?.rateLimits?.[name];
547
+ if (!window)
548
+ return [];
549
+ const { windowDurationMins: minutes, usedPercent } = window;
550
+ const resetsAt = typeof window.resetsAt === 'number' ? window.resetsAt * 1000 : 0;
551
+ const duration = typeof minutes === 'number' && minutes > 0 && Number.isFinite(minutes) ? minutes : undefined;
552
+ const label = duration !== undefined
553
+ ? (duration >= 1440 ? `${Math.round(duration / 1440)} 天窗口` : `${Math.round(duration / 60)} 小时窗口`)
554
+ : name;
555
+ return [{
556
+ duration,
557
+ window: {
558
+ label,
559
+ ...(typeof usedPercent === 'number' && usedPercent >= 0 && usedPercent <= 100 ? { usedPercent } : {}),
560
+ ...(Number.isFinite(resetsAt) && resetsAt > 0 ? { resetsAt } : {}),
561
+ },
562
+ }];
563
+ }).sort((a, b) => (b.duration ?? -1) - (a.duration ?? -1)).map(({ window }) => window);
564
+ }
565
+ export const codexAdapter = {
566
+ title: 'Codex',
567
+ memberTemplate: { name: 'Dex', color: { primary: '#123C34' }, avatarPath: '/avatars/codex.svg', options: { handoffAt: 0.85 } },
568
+ icon: '/clients/codex.svg',
569
+ detect: () => detectCommand('codex', { firstLine, onPath }),
570
+ command: COMMAND,
571
+ quotaAccountEnv: ['CODEX_HOME', 'HOME', 'USERPROFILE', ...Object.keys(CODEX_CLEAN_AUTH_ENV)],
572
+ skillsDir: '.codex/skills',
573
+ append: true,
574
+ // Codex speaks only the responses API to a provider of its own (it refuses `wire_api = "chat"`).
575
+ protocols: ['openai-responses'],
576
+ account: {
577
+ env: (dir) => ({ ...CODEX_CLEAN_AUTH_ENV, CODEX_HOME: dir }),
578
+ credentialFile: (dir) => join(dir, 'auth.json'),
579
+ login: ['codex', ...CODEX_FILE_STORE_ARGS, 'login'],
580
+ logout: ['codex', ...CODEX_FILE_STORE_ARGS, 'logout'],
581
+ loginBrowser: { endpoint: 'https://auth.openai.com/oauth/authorize', env: { BROWSER: 'none' } },
582
+ },
583
+ async sessions(cwd, options, env) {
584
+ const real = realpathSync(cwd);
585
+ const directory = cwd === real ? cwd : [cwd, real];
586
+ return query(async (peer) => {
587
+ const sessions = [];
588
+ let cursor;
589
+ do {
590
+ const page = await peer.request('thread/list', {
591
+ cwd: directory,
592
+ // The default list omits threads opened with codex exec.
593
+ sourceKinds: ['cli', 'vscode', 'exec', 'appServer'],
594
+ sortKey: 'updated_at',
595
+ limit: Math.min(50, SESSION_LIMIT - sessions.length),
596
+ cursor,
597
+ }, 30_000);
598
+ for (const thread of page.data) {
599
+ sessions.push({
600
+ id: thread.id,
601
+ ...(thread.name ? { title: thread.name } : {}),
602
+ cwd: thread.cwd,
603
+ updatedAt: thread.updatedAt * 1000,
604
+ });
605
+ }
606
+ cursor = page.nextCursor;
607
+ } while (cursor && sessions.length < SESSION_LIMIT);
608
+ return sessions;
609
+ }, { command: commandLine(options.command, COMMAND), env });
610
+ },
611
+ async options(fresh, key, env) {
612
+ const [catalog, keyFields] = await Promise.all([
613
+ modelCatalog(fresh, key, env).catch(() => ({
614
+ models: [], configuredModel: undefined, error: 'Codex 暂时无法读取模型列表',
615
+ })),
616
+ key ? keyedOptions(key, contextWindowOption(true)) : [],
617
+ ]);
618
+ const { models, configuredModel } = catalog;
619
+ let defaultModel;
620
+ if (configuredModel === null)
621
+ defaultModel = models.find((model) => model.isDefault);
622
+ else if (configuredModel)
623
+ defaultModel = models.find((model) => model.id === configuredModel || model.model === configuredModel);
624
+ const visible = models.filter((model) => !model.hidden);
625
+ const catalogError = catalog.error !== undefined;
626
+ const { fields, allowed } = modelControls(key ? models : models.filter((model) => !model.hidden || model === defaultModel), catalogError);
627
+ const restrict = (choice, modelId = choice.value) => {
628
+ const allowedValues = allowed.get(modelId);
629
+ return allowedValues ? { ...choice, allowedValues } : choice;
630
+ };
631
+ const defaultName = defaultModel?.displayName ?? configuredModel;
632
+ const modelWindow = (id) => id ? catalog.windows?.get(id) : undefined;
633
+ const localWindow = contextWindowOption(true, catalog.configuredWindow);
634
+ if (catalog.windowError)
635
+ localWindow.error = catalog.windowError;
636
+ const localModel = {
637
+ key: 'model', label: '模型', kind: 'string', default: '',
638
+ suggestions: [
639
+ restrict({
640
+ value: '', label: `跟随 Codex 的默认${defaultName ? `(${defaultName})` : ''}`,
641
+ fill: modelWindowFill(catalog.configuredWindow ?? modelWindow(defaultModel?.model ?? configuredModel ?? undefined)),
642
+ }, defaultModel?.id),
643
+ ...visible.map(({ id, model, displayName }) => restrict({
644
+ value: id, label: displayName, fill: modelWindowFill(modelWindow(model) ?? modelWindow(id)),
645
+ })),
646
+ ],
647
+ ...(catalogError ? { error: catalog.error } : {}),
648
+ };
649
+ // The key's endpoint supplies IDs and windows. Codex can restrict settings for the IDs it knows.
650
+ const modelFields = key ? keyFields.map((field) => field.key === 'model'
651
+ ? { ...field, kind: 'string', suggestions: field.suggestions?.map((choice) => restrict(choice)) }
652
+ : field) : [localModel, localWindow];
653
+ return [
654
+ ...modelFields, ...fields,
655
+ { key: 'approvalPolicy', label: '什么时候问我', kind: 'select', default: 'never', options: [{ value: 'never', label: '不问(在沙箱里直接做)' }, { value: 'on-request', label: '它觉得需要时问' }, { value: 'untrusted', label: '不认识的命令都问' }] },
656
+ { key: 'sandbox', label: '沙箱', kind: 'select', default: 'workspace-write', options: [{ value: 'read-only', label: '只读' }, { value: 'workspace-write', label: '可写项目目录' }, { value: 'danger-full-access', label: '不限制' }] },
657
+ ];
658
+ },
659
+ async quota(ctx) {
660
+ if (ctx?.key)
661
+ return [];
662
+ const command = commandLine(ctx?.options?.command, COMMAND);
663
+ const id = JSON.stringify([command, ctx?.env && Object.entries(ctx.env).sort(), Object.entries(ctx?.memberEnv ?? {}).sort()]);
664
+ const running = quotaInFlight.get(id);
665
+ if (running)
666
+ return running;
667
+ const probe = readQuota(command, ctx?.env, ctx?.memberEnv).finally(() => quotaInFlight.delete(id));
668
+ quotaInFlight.set(id, probe);
669
+ return probe;
670
+ },
671
+ applies: { tools: 'restart', prompt: 'restart', model: 'restart', options: 'restart' },
672
+ open,
673
+ };
674
+ export const codexAdapterPlugin = {
675
+ name: 'adapter-codex',
676
+ title: 'Codex',
677
+ about: '通过 codex app-server 接 Codex:流式、追加、打断、模型列表、额度。',
678
+ group: '客户端',
679
+ caution: '关掉后,用它的成员正在跑的回合会跑完再结束实例,空闲实例立即结束;这些成员也收不到新消息了。',
680
+ needs: ['instances'],
681
+ start(ctx) {
682
+ ctx.effect(ctx.get('instances').registerAdapter('codex', codexAdapter));
683
+ // An older adapter may have fingerprinted the current text without ever delivering it on resume.
684
+ ctx.note('session.input', { title: 'Codex 续接时写入宿主说明的方式', when: '投递方式变化时,在原会话补发当前说明' });
685
+ ctx.hook('session.input', ({ member }) => member.adapter === 'codex' ? { prompt: RESUME_INSTRUCTIONS_METHOD } : undefined);
686
+ },
687
+ };
688
+ export default codexAdapterPlugin;