@agentorg/cli 0.0.5 → 0.0.7

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 (260) hide show
  1. package/README.md +23 -104
  2. package/dist/node_modules/@agentorg/computer/LICENSE +201 -0
  3. package/dist/node_modules/@agentorg/computer/NOTICE +2 -0
  4. package/dist/node_modules/@agentorg/computer/dist/THIRD_PARTY_LICENSES.txt +1321 -0
  5. package/dist/node_modules/@agentorg/computer/dist/sdk.js +24909 -0
  6. package/dist/node_modules/@agentorg/computer/dist/types/generated/schema.d.ts +860 -0
  7. package/dist/node_modules/@agentorg/computer/dist/types/sdk.d.ts +242 -0
  8. package/dist/node_modules/@agentorg/computer/package.json +12 -0
  9. package/dist/node_modules/@agentorg/computer-connector/dist/src/index.d.ts +1 -0
  10. package/dist/node_modules/@agentorg/computer-connector/dist/src/index.js +1 -0
  11. package/dist/node_modules/@agentorg/computer-connector/dist/src/provider.d.ts +24 -0
  12. package/dist/node_modules/@agentorg/computer-connector/dist/src/provider.js +482 -0
  13. package/dist/node_modules/@agentorg/computer-connector/dist/src/unit.d.ts +19 -0
  14. package/dist/node_modules/@agentorg/computer-connector/dist/src/unit.js +149 -0
  15. package/dist/node_modules/@agentorg/computer-connector/package.json +33 -0
  16. package/dist/node_modules/@agentorg/computer-connector/skills/browser/SKILL.md +31 -0
  17. package/dist/node_modules/@agentorg/computer-connector/skills/computer/SKILL.md +30 -0
  18. package/dist/node_modules/@agentorg/computer-connector/skills/files/SKILL.md +28 -0
  19. package/dist/node_modules/@agentorg/computer-connector/skills/terminal/SKILL.md +39 -0
  20. package/dist/node_modules/@agentorg/computer-connector/skills/web-research/SKILL.md +29 -0
  21. package/dist/node_modules/@agentorg/hub/dist/src/hub-actor.d.ts +2 -7
  22. package/dist/node_modules/@agentorg/hub/dist/src/hub-actor.js +4 -144
  23. package/dist/node_modules/@agentorg/hub/dist/src/index.d.ts +1 -3
  24. package/dist/node_modules/@agentorg/hub/dist/src/index.js +1 -3
  25. package/dist/node_modules/@agentorg/hub/dist/src/router.d.ts +9 -58
  26. package/dist/node_modules/@agentorg/hub/dist/src/router.js +41 -414
  27. package/dist/node_modules/@agentorg/hub/dist/src/state.d.ts +17 -317
  28. package/dist/node_modules/@agentorg/hub/dist/src/state.js +42 -536
  29. package/dist/node_modules/@agentorg/hub/dist/src/validate.d.ts +1 -3
  30. package/dist/node_modules/@agentorg/hub/dist/src/validate.js +19 -17
  31. package/dist/node_modules/@agentorg/hub/package.json +0 -3
  32. package/dist/node_modules/@agentorg/interfaces/dist/src/agent-provider.d.ts +119 -0
  33. package/dist/node_modules/@agentorg/interfaces/dist/src/agent-provider.js +96 -0
  34. package/dist/node_modules/@agentorg/interfaces/dist/src/agent-settings.d.ts +42 -0
  35. package/dist/node_modules/@agentorg/interfaces/dist/src/agent-settings.js +53 -0
  36. package/dist/node_modules/@agentorg/interfaces/dist/src/chat.d.ts +93 -38
  37. package/dist/node_modules/@agentorg/interfaces/dist/src/chat.js +71 -22
  38. package/dist/node_modules/@agentorg/interfaces/dist/src/connection.d.ts +36 -0
  39. package/dist/node_modules/@agentorg/interfaces/dist/src/connection.js +31 -0
  40. package/dist/node_modules/@agentorg/interfaces/dist/src/folders.d.ts +19 -0
  41. package/dist/node_modules/@agentorg/interfaces/dist/src/folders.js +25 -0
  42. package/dist/node_modules/@agentorg/interfaces/dist/src/hub.d.ts +16 -286
  43. package/dist/node_modules/@agentorg/interfaces/dist/src/hub.js +17 -159
  44. package/dist/node_modules/@agentorg/interfaces/dist/src/index.d.ts +9 -9
  45. package/dist/node_modules/@agentorg/interfaces/dist/src/index.js +9 -9
  46. package/dist/node_modules/@agentorg/interfaces/dist/src/kv.d.ts +2 -2
  47. package/dist/node_modules/@agentorg/interfaces/dist/src/kv.js +2 -2
  48. package/dist/node_modules/@agentorg/interfaces/dist/src/llm-session.d.ts +2 -0
  49. package/dist/node_modules/@agentorg/interfaces/dist/src/llm-session.js +2 -1
  50. package/dist/node_modules/@agentorg/interfaces/dist/src/manager.d.ts +626 -0
  51. package/dist/node_modules/@agentorg/interfaces/dist/src/manager.js +349 -0
  52. package/dist/node_modules/@agentorg/interfaces/dist/src/tools.d.ts +39 -0
  53. package/dist/node_modules/@agentorg/interfaces/dist/src/tools.js +43 -0
  54. package/dist/node_modules/@agentorg/interfaces/dist/src/units.d.ts +460 -0
  55. package/dist/node_modules/@agentorg/interfaces/dist/src/units.js +204 -0
  56. package/dist/node_modules/@agentorg/looper/dist/src/index.d.ts +5 -0
  57. package/dist/node_modules/@agentorg/looper/dist/src/index.js +5 -0
  58. package/dist/node_modules/@agentorg/looper/dist/src/loop.d.ts +75 -0
  59. package/dist/node_modules/@agentorg/looper/dist/src/loop.js +332 -0
  60. package/dist/node_modules/@agentorg/looper/dist/src/looper.d.ts +71 -0
  61. package/dist/node_modules/@agentorg/looper/dist/src/looper.js +282 -0
  62. package/dist/node_modules/@agentorg/looper/dist/src/record.d.ts +99 -0
  63. package/dist/node_modules/@agentorg/looper/dist/src/record.js +278 -0
  64. package/dist/node_modules/@agentorg/looper/dist/src/tools.d.ts +11 -0
  65. package/dist/node_modules/@agentorg/looper/dist/src/tools.js +42 -0
  66. package/dist/node_modules/@agentorg/looper/dist/src/types.d.ts +147 -0
  67. package/dist/node_modules/@agentorg/looper/dist/src/types.js +32 -0
  68. package/dist/node_modules/@agentorg/looper/package.json +24 -0
  69. package/dist/node_modules/@agentorg/manager/dist/src/activity.d.ts +18 -0
  70. package/dist/node_modules/@agentorg/manager/dist/src/activity.js +65 -0
  71. package/dist/node_modules/@agentorg/manager/dist/src/control.d.ts +134 -0
  72. package/dist/node_modules/@agentorg/manager/dist/src/control.js +1115 -0
  73. package/dist/node_modules/@agentorg/manager/dist/src/form.d.ts +40 -0
  74. package/dist/node_modules/@agentorg/manager/dist/src/form.js +191 -0
  75. package/dist/node_modules/@agentorg/manager/dist/src/index.d.ts +1 -0
  76. package/dist/node_modules/@agentorg/manager/dist/src/index.js +1 -0
  77. package/dist/node_modules/@agentorg/manager/dist/src/manager.d.ts +25 -0
  78. package/dist/node_modules/@agentorg/manager/dist/src/manager.js +680 -0
  79. package/dist/node_modules/@agentorg/manager/dist/src/skills.d.ts +27 -0
  80. package/dist/node_modules/@agentorg/manager/dist/src/skills.js +152 -0
  81. package/dist/node_modules/@agentorg/manager/dist/src/stack.d.ts +454 -0
  82. package/dist/node_modules/@agentorg/manager/dist/src/stack.js +917 -0
  83. package/dist/node_modules/@agentorg/manager/package.json +30 -0
  84. package/dist/node_modules/@agentorg/mcp/dist/src/connection.d.ts +34 -0
  85. package/dist/node_modules/@agentorg/mcp/dist/src/connection.js +296 -0
  86. package/dist/node_modules/@agentorg/mcp/dist/src/index.d.ts +4 -0
  87. package/dist/node_modules/@agentorg/mcp/dist/src/index.js +4 -0
  88. package/dist/node_modules/@agentorg/mcp/dist/src/kinds.d.ts +158 -0
  89. package/dist/node_modules/@agentorg/mcp/dist/src/kinds.js +164 -0
  90. package/dist/node_modules/@agentorg/mcp/dist/src/provider.d.ts +22 -0
  91. package/dist/node_modules/@agentorg/mcp/dist/src/provider.js +197 -0
  92. package/dist/node_modules/@agentorg/mcp/dist/src/public.d.ts +6 -0
  93. package/dist/node_modules/@agentorg/mcp/dist/src/public.js +72 -0
  94. package/dist/node_modules/@agentorg/mcp/package.json +31 -0
  95. package/dist/node_modules/@agentorg/sdk/dist/src/cli.js +3 -23
  96. package/dist/node_modules/@agentorg/sdk/dist/src/client.d.ts +4 -25
  97. package/dist/node_modules/@agentorg/sdk/dist/src/client.js +5 -55
  98. package/dist/node_modules/@agentorg/sdk/dist/src/errors.d.ts +1 -1
  99. package/dist/node_modules/@agentorg/sdk/dist/src/errors.js +3 -3
  100. package/dist/node_modules/@agentorg/sdk/dist/src/filled.d.ts +21 -0
  101. package/dist/node_modules/@agentorg/sdk/dist/src/filled.js +24 -0
  102. package/dist/node_modules/@agentorg/sdk/dist/src/index.d.ts +3 -2
  103. package/dist/node_modules/@agentorg/sdk/dist/src/index.js +2 -1
  104. package/dist/node_modules/@agentorg/sdk/dist/src/interface.d.ts +6 -34
  105. package/dist/node_modules/@agentorg/sdk/dist/src/interface.js +3 -24
  106. package/dist/node_modules/@agentorg/sdk/dist/src/module-host.d.ts +8 -17
  107. package/dist/node_modules/@agentorg/sdk/dist/src/module-host.js +15 -87
  108. package/dist/node_modules/@agentorg/sdk/dist/src/module.d.ts +10 -76
  109. package/dist/node_modules/@agentorg/sdk/dist/src/module.js +3 -23
  110. package/dist/node_modules/@agentorg/sdk/dist/src/person-commands.js +0 -5
  111. package/dist/node_modules/@agentorg/sdk/dist/src/runtime.d.ts +3 -27
  112. package/dist/node_modules/@agentorg/sdk/dist/src/runtime.js +5 -100
  113. package/dist/node_modules/@agentorg/sdk/dist/src/testing.d.ts +7 -8
  114. package/dist/node_modules/@agentorg/sdk/dist/src/testing.js +12 -24
  115. package/dist/node_modules/@agentorg/sdk/package.json +4 -37
  116. package/dist/node_modules/@agentorg/shell/dist/app.css +4624 -739
  117. package/dist/node_modules/@agentorg/shell/dist/app.js +245 -202
  118. package/dist/node_modules/@agentorg/shell/package.json +23 -10
  119. package/dist/node_modules/@agentorg/wire/dist/src/frames.d.ts +2 -3
  120. package/dist/node_modules/@agentorg/wire/dist/src/frames.js +2 -3
  121. package/dist/node_modules/@agentorg/wire/dist/src/ops.d.ts +5 -34
  122. package/dist/node_modules/@agentorg/wire/dist/src/ops.js +2 -17
  123. package/dist/node_modules/assistant/dist/src/chats.d.ts +92 -0
  124. package/dist/node_modules/assistant/dist/src/chats.js +357 -0
  125. package/dist/node_modules/assistant/dist/src/engine.d.ts +42 -0
  126. package/dist/node_modules/assistant/dist/src/engine.js +160 -0
  127. package/dist/node_modules/assistant/dist/src/local-store.d.ts +3 -0
  128. package/dist/node_modules/assistant/dist/src/local-store.js +58 -0
  129. package/dist/node_modules/assistant/dist/src/provider.d.ts +21 -0
  130. package/dist/node_modules/assistant/dist/src/provider.js +259 -0
  131. package/dist/node_modules/assistant/dist/src/settings.d.ts +17 -0
  132. package/dist/node_modules/assistant/dist/src/settings.js +43 -0
  133. package/dist/node_modules/assistant/dist/src/tools.d.ts +57 -0
  134. package/dist/node_modules/assistant/dist/src/tools.js +102 -0
  135. package/dist/node_modules/assistant/package.json +30 -0
  136. package/dist/node_modules/chatgpt/dist/src/account.d.ts +52 -0
  137. package/dist/node_modules/chatgpt/dist/src/account.js +270 -0
  138. package/dist/node_modules/chatgpt/dist/src/encoding.d.ts +7 -0
  139. package/dist/node_modules/chatgpt/dist/src/encoding.js +20 -0
  140. package/dist/node_modules/chatgpt/dist/src/file-store.d.ts +9 -0
  141. package/dist/node_modules/chatgpt/dist/src/file-store.js +68 -0
  142. package/dist/node_modules/chatgpt/dist/src/index.d.ts +1 -0
  143. package/dist/node_modules/chatgpt/dist/src/index.js +1 -0
  144. package/dist/node_modules/chatgpt/dist/src/jwt.d.ts +15 -0
  145. package/dist/node_modules/chatgpt/dist/src/jwt.js +37 -0
  146. package/dist/node_modules/chatgpt/dist/src/oauth.d.ts +43 -0
  147. package/dist/node_modules/chatgpt/dist/src/oauth.js +104 -0
  148. package/dist/node_modules/chatgpt/dist/src/program.d.ts +23 -0
  149. package/dist/node_modules/chatgpt/dist/src/program.js +41 -0
  150. package/dist/node_modules/chatgpt/dist/src/responses.d.ts +54 -0
  151. package/dist/node_modules/chatgpt/dist/src/responses.js +300 -0
  152. package/dist/node_modules/chatgpt/dist/src/serve.d.ts +65 -0
  153. package/dist/node_modules/chatgpt/dist/src/serve.js +46 -0
  154. package/dist/node_modules/chatgpt/package.json +33 -0
  155. package/dist/src/api.d.ts +5 -34
  156. package/dist/src/api.js +10 -68
  157. package/dist/src/cli.js +3 -7
  158. package/dist/src/folders.d.ts +2 -0
  159. package/dist/src/folders.js +45 -0
  160. package/dist/src/gateway.d.ts +13 -8
  161. package/dist/src/gateway.js +119 -296
  162. package/dist/src/index.d.ts +4 -5
  163. package/dist/src/index.js +3 -4
  164. package/dist/src/live.d.ts +17 -0
  165. package/dist/src/live.js +109 -0
  166. package/dist/src/notes.d.ts +11 -0
  167. package/dist/src/notes.js +64 -0
  168. package/dist/src/oauth.d.ts +16 -0
  169. package/dist/src/oauth.js +46 -0
  170. package/dist/src/programs.d.ts +36 -0
  171. package/dist/src/programs.js +198 -0
  172. package/dist/src/signin.d.ts +12 -3
  173. package/dist/src/signin.js +30 -6
  174. package/package.json +4 -11
  175. package/dist/bundled/index.json +0 -6
  176. package/dist/bundled/sha256-0e91cc3d0e9762b81abc2427b5496b20f383abcd6fb97d928a8d50e956b54d1f.agentorg +0 -0
  177. package/dist/bundled/sha256-1f64ca62a0209d767d6aa6c4feb50b0653d60f10bebbc301f79bd3a37e0153c1.agentorg +0 -0
  178. package/dist/bundled/sha256-4055f8fddf6b90f3d356543f554b2a9e9a2c4a8827a8774f8f87952dc1692331.agentorg +0 -0
  179. package/dist/bundled/sha256-e356ea3c1899138a8494baf521556831006f38534fa9e92ae873e7e6956c3a46.agentorg +0 -0
  180. package/dist/node_modules/@agentorg/hub/dist/src/build.d.ts +0 -17
  181. package/dist/node_modules/@agentorg/hub/dist/src/build.js +0 -120
  182. package/dist/node_modules/@agentorg/hub/dist/src/logs.d.ts +0 -33
  183. package/dist/node_modules/@agentorg/hub/dist/src/logs.js +0 -162
  184. package/dist/node_modules/@agentorg/hub/dist/src/net.d.ts +0 -41
  185. package/dist/node_modules/@agentorg/hub/dist/src/net.js +0 -265
  186. package/dist/node_modules/@agentorg/hub/dist/src/processes.d.ts +0 -78
  187. package/dist/node_modules/@agentorg/hub/dist/src/processes.js +0 -485
  188. package/dist/node_modules/@agentorg/hub/dist/src/storage.d.ts +0 -38
  189. package/dist/node_modules/@agentorg/hub/dist/src/storage.js +0 -194
  190. package/dist/node_modules/@agentorg/interfaces/dist/src/http-egress.d.ts +0 -6
  191. package/dist/node_modules/@agentorg/interfaces/dist/src/http-egress.js +0 -7
  192. package/dist/node_modules/@agentorg/interfaces/dist/src/installer.d.ts +0 -191
  193. package/dist/node_modules/@agentorg/interfaces/dist/src/installer.js +0 -136
  194. package/dist/node_modules/@agentorg/interfaces/dist/src/layout.d.ts +0 -47
  195. package/dist/node_modules/@agentorg/interfaces/dist/src/layout.js +0 -52
  196. package/dist/node_modules/@agentorg/interfaces/dist/src/rules.d.ts +0 -35
  197. package/dist/node_modules/@agentorg/interfaces/dist/src/rules.js +0 -37
  198. package/dist/node_modules/@agentorg/interfaces/dist/src/storage-admin.d.ts +0 -23
  199. package/dist/node_modules/@agentorg/interfaces/dist/src/storage-admin.js +0 -31
  200. package/dist/node_modules/@agentorg/interfaces/dist/src/ui-shell.d.ts +0 -14
  201. package/dist/node_modules/@agentorg/interfaces/dist/src/ui-shell.js +0 -26
  202. package/dist/node_modules/@agentorg/interfaces/dist/src/ui-view.d.ts +0 -27
  203. package/dist/node_modules/@agentorg/interfaces/dist/src/ui-view.js +0 -26
  204. package/dist/node_modules/@agentorg/kit/dist/src/chat.d.ts +0 -37
  205. package/dist/node_modules/@agentorg/kit/dist/src/chat.js +0 -131
  206. package/dist/node_modules/@agentorg/kit/dist/src/components.d.ts +0 -94
  207. package/dist/node_modules/@agentorg/kit/dist/src/components.js +0 -66
  208. package/dist/node_modules/@agentorg/kit/dist/src/icons.d.ts +0 -17
  209. package/dist/node_modules/@agentorg/kit/dist/src/icons.js +0 -30
  210. package/dist/node_modules/@agentorg/kit/dist/src/index.d.ts +0 -6
  211. package/dist/node_modules/@agentorg/kit/dist/src/index.js +0 -10
  212. package/dist/node_modules/@agentorg/kit/dist/src/markdown.d.ts +0 -9
  213. package/dist/node_modules/@agentorg/kit/dist/src/markdown.js +0 -14
  214. package/dist/node_modules/@agentorg/kit/dist/src/resizable.d.ts +0 -5
  215. package/dist/node_modules/@agentorg/kit/dist/src/resizable.js +0 -8
  216. package/dist/node_modules/@agentorg/kit/dist/src/styles.d.ts +0 -11
  217. package/dist/node_modules/@agentorg/kit/dist/src/styles.js +0 -166
  218. package/dist/node_modules/@agentorg/kit/package.json +0 -44
  219. package/dist/node_modules/@agentorg/sdk/dist/frame/runtime.js +0 -753
  220. package/dist/node_modules/@agentorg/sdk/dist/host/runner.js +0 -21963
  221. package/dist/node_modules/@agentorg/sdk/dist/src/build.d.ts +0 -2
  222. package/dist/node_modules/@agentorg/sdk/dist/src/build.js +0 -2
  223. package/dist/node_modules/@agentorg/sdk/dist/src/client-http.d.ts +0 -24
  224. package/dist/node_modules/@agentorg/sdk/dist/src/client-http.js +0 -247
  225. package/dist/node_modules/@agentorg/sdk/dist/src/describe.d.ts +0 -13
  226. package/dist/node_modules/@agentorg/sdk/dist/src/describe.js +0 -16
  227. package/dist/node_modules/@agentorg/sdk/dist/src/frame-base.d.ts +0 -8
  228. package/dist/node_modules/@agentorg/sdk/dist/src/frame-base.js +0 -64
  229. package/dist/node_modules/@agentorg/sdk/dist/src/frame-entry.d.ts +0 -1
  230. package/dist/node_modules/@agentorg/sdk/dist/src/frame-entry.js +0 -35
  231. package/dist/node_modules/@agentorg/sdk/dist/src/frame-host.d.ts +0 -57
  232. package/dist/node_modules/@agentorg/sdk/dist/src/frame-host.js +0 -293
  233. package/dist/node_modules/@agentorg/sdk/dist/src/frame-protocol.d.ts +0 -124
  234. package/dist/node_modules/@agentorg/sdk/dist/src/frame-protocol.js +0 -16
  235. package/dist/node_modules/@agentorg/sdk/dist/src/frame.d.ts +0 -25
  236. package/dist/node_modules/@agentorg/sdk/dist/src/frame.js +0 -248
  237. package/dist/node_modules/@agentorg/sdk/dist/src/host-main.d.ts +0 -1
  238. package/dist/node_modules/@agentorg/sdk/dist/src/host-main.js +0 -60
  239. package/dist/node_modules/@agentorg/sdk/dist/src/host.d.ts +0 -25
  240. package/dist/node_modules/@agentorg/sdk/dist/src/host.js +0 -92
  241. package/dist/node_modules/@agentorg/sdk/dist/src/manifest-api.d.ts +0 -2
  242. package/dist/node_modules/@agentorg/sdk/dist/src/manifest-api.js +0 -2
  243. package/dist/node_modules/@agentorg/sdk/dist/src/manifest.d.ts +0 -56
  244. package/dist/node_modules/@agentorg/sdk/dist/src/manifest.js +0 -165
  245. package/dist/node_modules/@agentorg/sdk/dist/src/package.d.ts +0 -60
  246. package/dist/node_modules/@agentorg/sdk/dist/src/package.js +0 -538
  247. package/dist/node_modules/@agentorg/sdk/dist/src/tar.d.ts +0 -7
  248. package/dist/node_modules/@agentorg/sdk/dist/src/tar.js +0 -71
  249. package/dist/node_modules/@agentorg/shell/dist/agent-bindings.js +0 -59
  250. package/dist/node_modules/@agentorg/shell/src/agent-bindings.ts +0 -107
  251. package/dist/src/frames.d.ts +0 -23
  252. package/dist/src/frames.js +0 -78
  253. package/dist/src/layout.d.ts +0 -44
  254. package/dist/src/layout.js +0 -90
  255. package/dist/src/model.d.ts +0 -54
  256. package/dist/src/model.js +0 -299
  257. package/dist/src/rules.d.ts +0 -71
  258. package/dist/src/rules.js +0 -157
  259. package/dist/src/transfer.d.ts +0 -30
  260. package/dist/src/transfer.js +0 -110
@@ -1,60 +0,0 @@
1
- import { type Manifest, type Verified } from "./manifest.js";
2
- export interface Built {
3
- manifest: Manifest;
4
- /** SHA-256 over the canonical file tree: what a composition pins and grants follow. */
5
- hash: string;
6
- /** The tree, exactly what is hashed: `agentorg.json` and `dist/`. */
7
- dir: string;
8
- /** The `.agentorg` archive of the tree, named by the hash, beside it. */
9
- file: string;
10
- }
11
- export interface BuildOptions {
12
- /** Where the build goes, replaced each time: `package/` holds the tree, beside its archive. */
13
- out?: string;
14
- /** How long reading one module's definition may take. */
15
- describeTimeoutMs?: number;
16
- /**
17
- * What the package's own files may import by name: only these packages (and their subpaths),
18
- * found from `from`, and nothing outside the package's folder by path. The libraries resolve
19
- * their own imports as usual. Without it, imports resolve from the package's folder as Node's do.
20
- */
21
- packages?: {
22
- allowed: string[];
23
- from: string;
24
- };
25
- /**
26
- * At most this many modules and bytes of output; each bundling cancelled past `bundleMs`, and
27
- * the whole build refused past `totalMs`.
28
- */
29
- limits?: {
30
- modules: number;
31
- bytes: number;
32
- bundleMs: number;
33
- totalMs: number;
34
- };
35
- /**
36
- * How a module's describer runs. `sandbox` gives the OS sandbox command put before `node …`
37
- * for a process that may read `paths`: the Hub runs untrusted source there, as it runs host
38
- * processes. `preload: false` drops the in-process closing of built-ins and network globals;
39
- * it is only for testing that the sandbox holds without it.
40
- */
41
- describer?: {
42
- sandbox?: (paths: string[]) => string[];
43
- preload?: boolean;
44
- };
45
- }
46
- /** A build that can't go on: the message says what to fix. */
47
- export declare class BuildError extends Error {
48
- readonly name = "BuildError";
49
- }
50
- /**
51
- * Build a package: bundle each module with every library into one ESM file, read each module's
52
- * definition from its code, write `agentorg.json`, hash the tree, and archive it as
53
- * `<hash>.agentorg`. The output folder (default `<dir>/agentorg-build`) is replaced.
54
- */
55
- export declare function buildPackage(dir: string, options?: BuildOptions): Promise<Built>;
56
- /**
57
- * Check a `.agentorg` file against its expected hash, by default the one in its file name. See
58
- * `verifyArchive` (`@agentorg/sdk/manifest`) for the same check on bytes.
59
- */
60
- export declare function verifyPackage(file: string, expected?: string): Promise<Verified>;
@@ -1,538 +0,0 @@
1
- import { execFile, spawn } from "node:child_process";
2
- import { readFileSync } from "node:fs";
3
- import { mkdir, mkdtemp, readFile, realpath, rm, writeFile } from "node:fs/promises";
4
- import { tmpdir } from "node:os";
5
- import { dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
6
- import { pathToFileURL } from "node:url";
7
- import { context as esbuildContext, } from "esbuild";
8
- import { compareInterfaces } from "./interface.js";
9
- import { checkManifest, FORMAT, treeHash, verifyArchive, } from "./manifest.js";
10
- import { writeTar } from "./tar.js";
11
- const NAME = /^[a-z][A-Za-z0-9_]*$/;
12
- /** A build that can't go on: the message says what to fix. */
13
- export class BuildError extends Error {
14
- name = "BuildError";
15
- }
16
- /** Whether `inner` is `outer` or inside it. */
17
- const within = (inner, outer) => {
18
- const path = relative(outer, inner);
19
- return path === "" || (!path.startsWith("..") && !isAbsolute(path));
20
- };
21
- /**
22
- * Build a package: bundle each module with every library into one ESM file, read each module's
23
- * definition from its code, write `agentorg.json`, hash the tree, and archive it as
24
- * `<hash>.agentorg`. The output folder (default `<dir>/agentorg-build`) is replaced.
25
- */
26
- export async function buildPackage(dir, options = {}) {
27
- const root = resolve(dir);
28
- const out = resolve(options.out ?? join(root, "agentorg-build"));
29
- if (within(root, out))
30
- throw new BuildError(`The output folder ${out} holds the package itself; choose another.`);
31
- const pkg = JSON.parse(await readFile(join(root, "package.json"), "utf8"));
32
- const config = pkg.agentorg;
33
- if (!pkg.name || !pkg.version)
34
- throw new BuildError("package.json needs a name and a version.");
35
- if (!config || typeof config.modules !== "object" || !Object.keys(config.modules).length)
36
- throw new BuildError(`package.json needs "agentorg": { "modules": { "<name>": "<entry>" } }.`);
37
- for (const name of Object.keys(config.modules))
38
- if (!NAME.test(name))
39
- throw new BuildError(`${JSON.stringify(name)} isn't a valid module name.`);
40
- // A limited build's modules are its own files too.
41
- if (options.packages)
42
- for (const [name, entry] of Object.entries(config.modules))
43
- if (!within(resolve(root, entry), root))
44
- throw new BuildError(`Module ${name}'s entry ${entry} is outside the package's folder.`);
45
- const limits = options.limits;
46
- if (limits && Object.keys(config.modules).length > limits.modules)
47
- throw new BuildError(`A package has at most ${limits.modules} modules.`);
48
- let bytes = 0;
49
- const deadline = limits ? Date.now() + limits.totalMs : Number.POSITIVE_INFINITY;
50
- /** The time a step may take: its own limit, within what's left of the build's. */
51
- const inTime = (ms) => {
52
- const left = deadline - Date.now();
53
- if (left <= 0)
54
- throw new BuildError(`A build takes at most ${(limits?.totalMs ?? 0) / 1000} s.`);
55
- return Math.min(ms, left);
56
- };
57
- const bundleMs = limits?.bundleMs ?? 30_000;
58
- const limited = () => options.packages && { ...options.packages, bundleMs: inTime(bundleMs) };
59
- const files = new Map();
60
- const described = {};
61
- const scratch = await realpath(await mkdtemp(join(tmpdir(), "agentorg-build-")));
62
- try {
63
- for (const [name, entry] of Object.entries(config.modules)) {
64
- const code = await bundle(root, { entryPoints: [join(root, entry)] }, limited());
65
- bytes += code.byteLength;
66
- if (limits && bytes > limits.bytes)
67
- throw new BuildError(`A package's modules are at most ${limits.bytes / 1024 / 1024} MiB built.`);
68
- files.set(`dist/${name}.js`, code);
69
- // The definition is read by running the module's code, so the describer is bundled with it
70
- // and shares its SDK and zod.
71
- const describer = await bundle(root, {
72
- stdin: {
73
- contents: [
74
- `import definition from ${JSON.stringify(join(root, entry))};`,
75
- `import { describeModule } from "@agentorg/sdk/describe";`,
76
- "export default describeModule(definition);",
77
- ].join("\n"),
78
- resolveDir: root,
79
- sourcefile: `describe-${name}.js`,
80
- },
81
- }, limited());
82
- described[name] = await describeInChild(scratch, name, describer, inTime(options.describeTimeoutMs ?? 30_000), options.describer ?? {});
83
- }
84
- }
85
- finally {
86
- await rm(scratch, { recursive: true, force: true });
87
- }
88
- const interfaces = {};
89
- const record = (where, iface) => {
90
- const { id, ...entry } = iface;
91
- const known = interfaces[id];
92
- if (known && compareInterfaces({ id, hash: known.hash }, iface) === "conflict")
93
- throw new BuildError(`${where} uses ${id} with other schemas than another module does: one package has one definition of each interface.`);
94
- interfaces[id] = entry;
95
- return id;
96
- };
97
- const modules = {};
98
- for (const [name, d] of Object.entries(described))
99
- modules[name] = {
100
- placement: d.placement,
101
- entry: `dist/${name}.js`,
102
- slots: Object.fromEntries(Object.entries(d.slots).map(([slot, i]) => [slot, record(`${name}.${slot}`, i)])),
103
- exports: Object.fromEntries(Object.entries(d.exports).map(([exp, i]) => [exp, record(`${name}.${exp}`, i)])),
104
- };
105
- const manifest = {
106
- format: FORMAT,
107
- name: pkg.name,
108
- version: pkg.version,
109
- ...(pkg.description ? { description: pkg.description } : {}),
110
- modules,
111
- interfaces: Object.fromEntries(Object.entries(interfaces).sort(([a], [b]) => (a < b ? -1 : 1))),
112
- connections: config.connections ?? [],
113
- seed: config.seed ?? null,
114
- };
115
- const problems = checkManifest(manifest);
116
- if (problems.length)
117
- throw new BuildError(problems.join("\n"));
118
- files.set("agentorg.json", new TextEncoder().encode(`${JSON.stringify(manifest, null, 2)}\n`));
119
- const hash = treeHash(files);
120
- const tree = join(out, "package");
121
- await rm(out, { recursive: true, force: true });
122
- await mkdir(join(tree, "dist"), { recursive: true });
123
- for (const [path, data] of files)
124
- await writeFile(join(tree, path), data);
125
- const file = join(out, `${hash}.agentorg`);
126
- await writeFile(file, writeTar(files));
127
- return { manifest, hash, dir: tree, file };
128
- }
129
- /**
130
- * One ESM file holding the entry and every library it uses: no runtime imports and no Node
131
- * built-ins. Whitespace and comments are dropped, since esbuild's comments name each file's path
132
- * and would make the hash depend on where the package sits.
133
- */
134
- async function bundle(root, input, packages) {
135
- const loadable = new Set();
136
- let ctx;
137
- let timer;
138
- try {
139
- ctx = await esbuildContext({
140
- ...input,
141
- // A limited build reads no tsconfig or jsconfig (one could name any file to read), and
142
- // loads only what its plugin resolved.
143
- ...(packages ? { plugins: [limitImports(root, packages, loadable)], tsconfigRaw: "{}" } : {}),
144
- // Its inputs, by the names the bundle gives them: a library's are renamed after.
145
- metafile: true,
146
- absWorkingDir: root,
147
- bundle: true,
148
- format: "esm",
149
- platform: "neutral",
150
- mainFields: ["module", "main"],
151
- conditions: ["import", "module", "default"],
152
- target: "es2023",
153
- // A view may be written in JSX with React (the kit's components): the automatic runtime,
154
- // so no file needs React in scope, and React's production build, since a frame has no
155
- // `process` for React to read its mode from.
156
- jsx: "automatic",
157
- define: { "process.env.NODE_ENV": '"production"' },
158
- minifyWhitespace: true,
159
- legalComments: "none",
160
- write: false,
161
- logLevel: "silent",
162
- });
163
- const running = ctx.rebuild();
164
- const result = packages
165
- ? await Promise.race([
166
- running,
167
- new Promise((_, reject) => {
168
- timer = setTimeout(() => {
169
- void ctx?.cancel();
170
- reject(new BuildError(`Bundling a module takes at most ${packages.bundleMs / 1000} s.`));
171
- }, packages.bundleMs);
172
- }),
173
- ])
174
- : await running;
175
- // Everything in the bundle was resolved by the plugin, or is the describer's stdin.
176
- const input_ = input;
177
- if (packages)
178
- for (const input of Object.keys(result.metafile?.inputs ?? {}))
179
- if (input !== (input_.stdin?.sourcefile ?? "<stdin>") &&
180
- !loadable.has(resolve(root, input)))
181
- throw new BuildError("The bundle reached a file the package didn't import.");
182
- const code = (result.outputFiles ?? [])[0]?.contents ?? new Uint8Array();
183
- return nameLibraries(code, Object.keys(result.metafile?.inputs ?? {}), root);
184
- }
185
- catch (error) {
186
- if (error instanceof BuildError)
187
- throw error;
188
- const errors = error.errors;
189
- /** A place in the package by its relative path; anywhere else isn't told. */
190
- const place = (file) => !packages || (!file.startsWith("..") && !isAbsolute(file)) ? file : "<outside>";
191
- throw new BuildError(errors?.length
192
- ? errors
193
- .map((e) => `${e.location ? `${place(e.location.file)}:${e.location.line}: ` : ""}${packages ? e.text.replaceAll(`${root}/`, "") : e.text}`)
194
- .join("\n")
195
- : String(error));
196
- }
197
- finally {
198
- clearTimeout(timer);
199
- await ctx?.dispose();
200
- }
201
- }
202
- /** The package a bare import names: `zod`, `@agentorg/sdk` (from `@agentorg/sdk/describe`). */
203
- const packageOf = (specifier) => specifier
204
- .split("/")
205
- .slice(0, specifier.startsWith("@") ? 2 : 1)
206
- .join("/");
207
- /** Whether `path` is inside the installed package `name`: a folder above it is that package's. */
208
- function inPackage(path, name) {
209
- for (let dir = dirname(path);; dir = dirname(dir)) {
210
- try {
211
- if (JSON.parse(readFileSync(join(dir, "package.json"), "utf8")).name === name)
212
- return true;
213
- }
214
- catch {
215
- // No package.json here, or not one to read.
216
- }
217
- if (dirname(dir) === dir)
218
- return false;
219
- }
220
- }
221
- /** The name a library's file is given in the bundle, after this prefix. */
222
- const LIBRARY = "agentorg-library:";
223
- /**
224
- * A library's file as the bundle names it: its package's name and version and its path in that
225
- * package, never where it is installed. Undefined for a file in no named, versioned package.
226
- */
227
- function libraryName(path, packageOfFolder) {
228
- const seen = [];
229
- let found = null;
230
- for (let dir = dirname(path); dirname(dir) !== dir; dir = dirname(dir)) {
231
- const known = packageOfFolder.get(dir);
232
- if (known !== undefined) {
233
- found = known;
234
- break;
235
- }
236
- seen.push(dir);
237
- let manifest;
238
- try {
239
- manifest = JSON.parse(readFileSync(join(dir, "package.json"), "utf8"));
240
- }
241
- catch {
242
- // No package.json here, or not one to read.
243
- }
244
- if (typeof manifest?.name === "string" && typeof manifest.version === "string") {
245
- found = { name: manifest.name, version: manifest.version, dir };
246
- break;
247
- }
248
- }
249
- for (const dir of seen)
250
- packageOfFolder.set(dir, found);
251
- return found
252
- ? `${found.name}@${found.version}/${relative(found.dir, path).split(sep).join("/")}`
253
- : undefined;
254
- }
255
- /**
256
- * The bundle with each wrapped library module named by its library, not by where it sits.
257
- * esbuild names each CommonJS (and lazily run ESM) module it wraps by its path from the build's
258
- * folder, which for an installed library spells out the machine's folders and changes with them:
259
- * React's, for one, would carry the builder's home into every package built with it. Only those
260
- * names change, and only for a library's files: in a named, versioned package, outside the
261
- * package's folder or in a node_modules within it.
262
- */
263
- function nameLibraries(code, inputs, root) {
264
- const names = new Map();
265
- const packages = new Map();
266
- for (const input of inputs) {
267
- const path = resolve(root, input);
268
- // The package's own files keep their paths; a library is named, even one installed inside.
269
- if (within(path, root) && !path.slice(root.length).split(sep).includes("node_modules"))
270
- continue;
271
- const name = libraryName(path, packages);
272
- if (name)
273
- names.set(input, `${LIBRARY}${name}`);
274
- }
275
- if (!names.size)
276
- return code;
277
- const text = new TextDecoder().decode(code);
278
- // A wrapper's key: the method name after `__commonJS({` or `__esm({` (`async` before it for a
279
- // module with top-level await), in either quote, followed by its parameter list.
280
- const named = text.replace(/(\b__(?:commonJS|esm)\d*\(\{(?:async\s*)?)("(?:[^"\\\n]|\\.)*"|'(?:[^'\\\n]|\\.)*')(?=\()/g, (whole, call, literal) => {
281
- const name = names.get(stringOf(literal));
282
- return name ? `${call}${JSON.stringify(name)}` : whole;
283
- });
284
- return new TextEncoder().encode(named);
285
- }
286
- /** A JavaScript string literal's value, as esbuild prints one: its escapes read, never thrown. */
287
- function stringOf(literal) {
288
- return literal
289
- .slice(1, -1)
290
- .replace(/\\(u\{([0-9a-fA-F]+)\}|u([0-9a-fA-F]{4})|x([0-9a-fA-F]{2})|([0-7]{1,3})|\r\n|[\s\S])/g, (_, sequence, point, unit, byte, octal) => {
291
- const code = point ?? unit ?? byte;
292
- if (code !== undefined)
293
- return String.fromCodePoint(Number.parseInt(code, 16));
294
- if (octal !== undefined)
295
- return String.fromCharCode(Number.parseInt(octal, 8));
296
- const simple = {
297
- n: "\n",
298
- r: "\r",
299
- t: "\t",
300
- b: "\b",
301
- f: "\f",
302
- v: "\v",
303
- };
304
- // A line continuation is nothing; any other escaped character is itself.
305
- return sequence === "\n" || sequence === "\r\n" || sequence === "\r"
306
- ? ""
307
- : (simple[sequence] ?? sequence);
308
- });
309
- }
310
- /**
311
- * Imports from the package's own files (and its module entries): by name, only an allowed
312
- * package, found from `from`, and only a file inside it; by relative path, only inside the
313
- * package's folder, checked as text before anything is looked up; never by absolute path. A
314
- * library's own imports are its business.
315
- */
316
- function limitImports(root, packages, loadable) {
317
- const allowed = new Set(packages.allowed);
318
- const SKIP = Symbol("resolving");
319
- const refuse = (text) => ({ errors: [{ text }] });
320
- return {
321
- name: "agentorg-limit-imports",
322
- setup(build) {
323
- build.onResolve({ filter: /.*/ }, async (args) => {
324
- if (args.pluginData?.[SKIP])
325
- return undefined;
326
- const entry = args.kind === "entry-point";
327
- // The describer's stdin and the package's own files; not the libraries'.
328
- const ours = entry ||
329
- args.importer === "" ||
330
- args.importer.startsWith("<stdin>") ||
331
- within(args.importer, root);
332
- const relativePath = args.path.startsWith(".");
333
- const bare = !entry && !relativePath && !isAbsolute(args.path);
334
- if (ours) {
335
- // An absolute path (a module's entry, the describer's import of it) only into the
336
- // folder, checked as text, so nothing outside is ever looked up.
337
- if ((entry || isAbsolute(args.path)) && !within(args.path, root))
338
- return refuse(entry
339
- ? "A module's entry is outside the package's folder."
340
- : `${args.path}: an import leaves the package's folder.`);
341
- if (bare && !allowed.has(packageOf(args.path)))
342
- return refuse(`${args.path}: a package built by the Hub imports only ${[...allowed].join(", ")}.`);
343
- if (relativePath && !within(resolve(args.resolveDir, args.path), root))
344
- return refuse(`${args.path}: an import leaves the package's folder.`);
345
- }
346
- const found = await build.resolve(args.path, {
347
- kind: args.kind,
348
- resolveDir: ours && bare ? packages.from : args.resolveDir,
349
- importer: args.importer,
350
- pluginData: { [SKIP]: true },
351
- });
352
- if (found.errors.length)
353
- return { errors: found.errors };
354
- if (ours &&
355
- (bare ? !inPackage(found.path, packageOf(args.path)) : !within(found.path, root)))
356
- return refuse(`${args.path}: an import leaves ${bare ? "its package" : "the package's folder"}.`);
357
- // A library's own import is its business, but only what was resolved here is loaded.
358
- if (found.namespace === "file")
359
- loadable.add(found.path);
360
- // A library's own import is resolved again by esbuild itself, to the same file, so it
361
- // keeps what only esbuild's resolution carries: the module type ("type": "module").
362
- if (!ours)
363
- return undefined;
364
- // As resolved, with what tree-shaking reads.
365
- return {
366
- path: found.path,
367
- namespace: found.namespace,
368
- external: found.external,
369
- sideEffects: found.sideEffects,
370
- };
371
- });
372
- // A file esbuild found any other way (a pattern in a template-string import or require
373
- // matches files without resolving them) is never read.
374
- build.onLoad({ filter: /.*/ }, (args) => args.namespace !== "file" || loadable.has(args.path)
375
- ? undefined
376
- : refuse("A pattern import (a template string in import() or require()) isn't built: import each file by its own path."));
377
- },
378
- };
379
- }
380
- const MARK = "agentorg-describe:";
381
- /**
382
- * What a process and the processes it started hold resident, in bytes: under a sandbox, the
383
- * describer's node is a child of the sandbox's process. 0 where it can't be told (Windows).
384
- */
385
- async function residentBytes(pid) {
386
- if (process.platform === "linux") {
387
- let total = 0;
388
- const visit = (id) => {
389
- try {
390
- total += Number(readFileSync(`/proc/${id}/statm`, "utf8").split(" ")[1]) * 4096;
391
- for (const child of readFileSync(`/proc/${id}/task/${id}/children`, "utf8").split(" "))
392
- if (child.trim())
393
- visit(Number(child));
394
- }
395
- catch {
396
- // Gone, or not to be read.
397
- }
398
- };
399
- visit(pid);
400
- return total;
401
- }
402
- if (process.platform === "win32")
403
- return 0;
404
- // macOS: sandbox-exec becomes the node it runs, so the process is the describer.
405
- return new Promise((resolve) => execFile("ps", ["-o", "rss=", "-p", String(pid)], (error, out) => resolve(error ? 0 : Number(out.trim()) * 1024)));
406
- }
407
- /**
408
- * What a module's describer may hold resident, all of it. A describer only defines, so it needs
409
- * little; macOS compresses idle pages, so what it really holds can be about twice this.
410
- */
411
- const MAX_DESCRIBER_MEMORY = 512 * 1024 * 1024;
412
- /**
413
- * Run before the module in the describer's process. No Node built-in can be imported, the ways
414
- * around that are gone, and so are the network globals. Node's permission model already stops
415
- * reads outside the scratch folder, writes, processes and workers, but it has no network control.
416
- */
417
- const PRELOAD = `import { isBuiltin, registerHooks } from "node:module";
418
- registerHooks({
419
- resolve(specifier, context, next) {
420
- if (isBuiltin(specifier)) throw new Error(specifier + " is not available at a module's top level");
421
- return next(specifier, context);
422
- },
423
- });
424
- for (const [owner, names] of [
425
- [globalThis, ["fetch", "WebSocket", "EventSource", "XMLHttpRequest"]],
426
- // And what describes the host: its paths, its command line, its report.
427
- [process, ["getBuiltinModule", "binding", "_linkedBinding", "dlopen", "report", "execPath", "argv", "execArgv", "title"]],
428
- ])
429
- for (const name of names)
430
- Object.defineProperty(owner, name, {
431
- configurable: false,
432
- get() {
433
- throw new Error(name + " is not available at a module's top level");
434
- },
435
- });
436
- `;
437
- const RUNNER = `let result;
438
- try {
439
- result = { described: (await import("./module.mjs")).default };
440
- } catch (error) {
441
- result = { error: String(error && error.stack ? error.name + ": " + error.message : error) };
442
- }
443
- process.stdout.write("\\n${MARK}" + JSON.stringify(result) + "\\n", () => process.exit(0));
444
- `;
445
- /**
446
- * Run a module's describer in a child Node process under the permission model: it reads only the
447
- * scratch folder, writes nothing, starts no processes or workers, and can reach no network. A top
448
- * level that does I/O or touches DOM globals fails there, and the build says why.
449
- */
450
- async function describeInChild(scratch, name, describer, timeoutMs, how) {
451
- const files = { preload: join(scratch, "preload.mjs"), runner: join(scratch, "runner.mjs") };
452
- await writeFile(files.preload, PRELOAD);
453
- await writeFile(files.runner, RUNNER);
454
- // The module is beside the runner by a fixed name: the runner can't read its own argv.
455
- const target = join(scratch, "module.mjs");
456
- await writeFile(target, describer);
457
- let timedOut = false;
458
- let tooBig = false;
459
- const { code, stdout, stderr } = await new Promise((done, fail) => {
460
- const node = [
461
- process.execPath,
462
- "--permission",
463
- "--max-old-space-size=256",
464
- `--allow-fs-read=${scratch}`,
465
- ...(how.preload === false ? [] : ["--import", pathToFileURL(files.preload).href]),
466
- files.runner,
467
- ];
468
- const [command, ...args] = [...(how.sandbox?.([scratch]) ?? []), ...node];
469
- const child = spawn(command, args, {
470
- cwd: scratch,
471
- stdio: ["ignore", "pipe", "pipe"],
472
- env: process.env.SYSTEMROOT ? { SYSTEMROOT: process.env.SYSTEMROOT } : {},
473
- });
474
- let stdout = "";
475
- let stderr = "";
476
- child.stdout.on("data", (chunk) => {
477
- stdout += chunk;
478
- });
479
- child.stderr.on("data", (chunk) => {
480
- stderr += chunk;
481
- });
482
- // SIGKILL, since a module's top level can ignore SIGTERM.
483
- const timer = setTimeout(() => {
484
- timedOut = true;
485
- child.kill("SIGKILL");
486
- }, timeoutMs);
487
- // Its heap is capped by V8, but not what it allocates outside it (ArrayBuffers): its memory
488
- // is watched, and past the cap it is stopped.
489
- const watch = setInterval(() => {
490
- if (child.pid === undefined)
491
- return;
492
- void residentBytes(child.pid).then((bytes) => {
493
- if (bytes > MAX_DESCRIBER_MEMORY) {
494
- tooBig = true;
495
- child.kill("SIGKILL");
496
- }
497
- });
498
- }, 200);
499
- child.on("error", fail);
500
- child.on("close", (code) => {
501
- clearTimeout(timer);
502
- clearInterval(watch);
503
- done({ code, stdout, stderr });
504
- });
505
- });
506
- if (tooBig)
507
- throw new BuildError(`Module ${name}: reading its definition took over ${MAX_DESCRIBER_MEMORY / 1024 / 1024} MiB of memory. A module's top level must only define; do work in start().`);
508
- if (timedOut)
509
- throw new BuildError(`Module ${name}: reading its definition took over ${timeoutMs} ms. A module's top level must only define; do work in start().`);
510
- // A module's own output may come first. JSON holds no raw newline, so the result is the text
511
- // after the last newline-led marker.
512
- const at = stdout.lastIndexOf(`\n${MARK}`);
513
- let result;
514
- try {
515
- result = at < 0 ? undefined : JSON.parse(stdout.slice(at + MARK.length + 1));
516
- }
517
- catch {
518
- result = undefined;
519
- }
520
- if (!result)
521
- throw new BuildError(`Module ${name}: its definition couldn't be read (exit ${code}). ${stderr.trim().split("\n").slice(-3).join(" ").replaceAll(scratch, "<describer>")}`);
522
- if (result.error || !result.described)
523
- throw new BuildError(`Module ${name}: its top level failed while its definition was read: ${String(result.error).replaceAll(scratch, "<describer>")}. A module's top level must not do I/O or touch DOM globals; do that work in start().`);
524
- return result.described;
525
- }
526
- /**
527
- * Check a `.agentorg` file against its expected hash, by default the one in its file name. See
528
- * `verifyArchive` (`@agentorg/sdk/manifest`) for the same check on bytes.
529
- */
530
- export async function verifyPackage(file, expected) {
531
- const want = expected ?? /(sha256-[0-9a-f]{64})\.agentorg$/.exec(file)?.[1];
532
- if (!want)
533
- return {
534
- ok: false,
535
- problems: ["No expected hash: pass one, or keep the file named by its hash."],
536
- };
537
- return verifyArchive(new Uint8Array(await readFile(file)), want);
538
- }
@@ -1,7 +0,0 @@
1
- /**
2
- * A deterministic ustar archive of regular files: entries in path order, mode 0644, uid and gid 0,
3
- * mtime 0 and no owner names, so equal trees give equal bytes.
4
- */
5
- export declare function writeTar(files: Map<string, Uint8Array>): Uint8Array;
6
- /** The regular files of a ustar archive, refusing anything else and any checksum mismatch. */
7
- export declare function readTar(archive: Uint8Array): Map<string, Uint8Array>;
@@ -1,71 +0,0 @@
1
- /**
2
- * A deterministic ustar archive of regular files: entries in path order, mode 0644, uid and gid 0,
3
- * mtime 0 and no owner names, so equal trees give equal bytes.
4
- */
5
- export function writeTar(files) {
6
- const blocks = [];
7
- for (const path of [...files.keys()].sort()) {
8
- const data = files.get(path);
9
- const name = new TextEncoder().encode(path);
10
- if (name.length > 100)
11
- throw new RangeError(`${path} is longer than a tar name allows.`);
12
- const header = new Uint8Array(512);
13
- header.set(name, 0);
14
- const field = (offset, length, value) => header.set(new TextEncoder().encode(`${value.toString(8).padStart(length - 1, "0")}\0`), offset);
15
- field(100, 8, 0o644);
16
- field(108, 8, 0);
17
- field(116, 8, 0);
18
- field(124, 12, data.length);
19
- field(136, 12, 0);
20
- header.set(new TextEncoder().encode(" "), 148);
21
- header[156] = "0".charCodeAt(0);
22
- header.set(new TextEncoder().encode("ustar\u000000"), 257);
23
- const sum = header.reduce((total, byte) => total + byte, 0);
24
- header.set(new TextEncoder().encode(`${sum.toString(8).padStart(6, "0")}\0 `), 148);
25
- blocks.push(header, data, new Uint8Array((512 - (data.length % 512)) % 512));
26
- }
27
- blocks.push(new Uint8Array(1024));
28
- const out = new Uint8Array(blocks.reduce((total, block) => total + block.length, 0));
29
- let offset = 0;
30
- for (const block of blocks) {
31
- out.set(block, offset);
32
- offset += block.length;
33
- }
34
- return out;
35
- }
36
- /** A plain relative path: `/`-separated, with no empty, `.` or `..` segments or backslashes. */
37
- function safePath(path) {
38
- return (path.length > 0 &&
39
- !path.includes("\\") &&
40
- !/^[A-Za-z]:/.test(path) &&
41
- path.split("/").every((segment) => segment !== "" && segment !== "." && segment !== ".."));
42
- }
43
- /** The regular files of a ustar archive, refusing anything else and any checksum mismatch. */
44
- export function readTar(archive) {
45
- const files = new Map();
46
- const text = (from, length) => new TextDecoder().decode(archive.subarray(from, from + length)).replace(/\0.*$/s, "");
47
- let offset = 0;
48
- while (offset + 512 <= archive.length) {
49
- const header = archive.subarray(offset, offset + 512);
50
- if (header.every((byte) => byte === 0))
51
- return files;
52
- const sum = header.reduce((total, byte, i) => total + (i >= 148 && i < 156 ? 32 : byte), 0);
53
- if (Number.parseInt(text(offset + 148, 8).trim(), 8) !== sum)
54
- throw new Error(`Corrupt tar header at byte ${offset}.`);
55
- if (text(offset + 156, 1) !== "0")
56
- throw new Error(`Only regular files are allowed in a package.`);
57
- const path = text(offset, 100);
58
- const size = Number.parseInt(text(offset + 124, 12).trim(), 8);
59
- if (text(offset + 345, 155))
60
- throw new Error("A package's tar uses no name prefix.");
61
- if (!safePath(path))
62
- throw new Error(`Unsafe path ${JSON.stringify(path)} in a package.`);
63
- if (!Number.isInteger(size) || size < 0 || offset + 512 + size > archive.length)
64
- throw new Error(`${path}'s size runs past the end of the archive.`);
65
- if (files.has(path))
66
- throw new Error(`${path} appears twice in a package.`);
67
- files.set(path, archive.slice(offset + 512, offset + 512 + size));
68
- offset += 512 + Math.ceil(size / 512) * 512;
69
- }
70
- throw new Error("The tar archive ends without its end marker.");
71
- }