@poe-platform/safe-js 0.1.0

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 (326) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +206 -0
  3. package/dist/agent-defs/agents/claude-code.d.ts +2 -0
  4. package/dist/agent-defs/agents/claude-desktop.d.ts +2 -0
  5. package/dist/agent-defs/agents/codex.d.ts +2 -0
  6. package/dist/agent-defs/agents/cursor.d.ts +2 -0
  7. package/dist/agent-defs/agents/gemini-cli.d.ts +2 -0
  8. package/dist/agent-defs/agents/goose.d.ts +2 -0
  9. package/dist/agent-defs/agents/index.d.ts +10 -0
  10. package/dist/agent-defs/agents/kimi.d.ts +2 -0
  11. package/dist/agent-defs/agents/opencode.d.ts +2 -0
  12. package/dist/agent-defs/agents/pi.d.ts +2 -0
  13. package/dist/agent-defs/agents/poe-agent.d.ts +2 -0
  14. package/dist/agent-defs/capabilities.d.ts +14 -0
  15. package/dist/agent-defs/index.d.ts +6 -0
  16. package/dist/agent-defs/registry.d.ts +3 -0
  17. package/dist/agent-defs/specifier.d.ts +7 -0
  18. package/dist/agent-defs/types.d.ts +35 -0
  19. package/dist/agent-harness-tools/binary-exists.d.ts +10 -0
  20. package/dist/agent-harness-tools/execution-env.d.ts +108 -0
  21. package/dist/agent-harness-tools/hooks.d.ts +30 -0
  22. package/dist/agent-harness-tools/index.d.ts +18 -0
  23. package/dist/agent-harness-tools/log-stream.d.ts +28 -0
  24. package/dist/agent-harness-tools/participant.d.ts +10 -0
  25. package/dist/agent-harness-tools/paths.d.ts +14 -0
  26. package/dist/agent-harness-tools/plan-readiness.d.ts +7 -0
  27. package/dist/agent-harness-tools/plans.d.ts +35 -0
  28. package/dist/agent-harness-tools/poe-command-execution.d.ts +37 -0
  29. package/dist/agent-harness-tools/run-logs.d.ts +17 -0
  30. package/dist/agent-harness-tools/run-poe-command.d.ts +33 -0
  31. package/dist/agent-harness-tools/runner.d.ts +33 -0
  32. package/dist/agent-harness-tools/select-agent.d.ts +18 -0
  33. package/dist/agent-harness-tools/sequence.d.ts +7 -0
  34. package/dist/agent-harness-tools/skill-config.d.ts +1 -0
  35. package/dist/agent-harness-tools/stage.d.ts +22 -0
  36. package/dist/agent-harness-tools/workspace-transfer.d.ts +3 -0
  37. package/dist/agent-spawn/acp/middleware.d.ts +38 -0
  38. package/dist/agent-spawn/acp/types.d.ts +180 -0
  39. package/dist/agent-spawn/adapters/claude.d.ts +3 -0
  40. package/dist/agent-spawn/adapters/codex.d.ts +2 -0
  41. package/dist/agent-spawn/adapters/cursor.d.ts +2 -0
  42. package/dist/agent-spawn/adapters/index.d.ts +12 -0
  43. package/dist/agent-spawn/adapters/kimi.d.ts +2 -0
  44. package/dist/agent-spawn/adapters/native.d.ts +5 -0
  45. package/dist/agent-spawn/adapters/opencode.d.ts +2 -0
  46. package/dist/agent-spawn/adapters/pi.d.ts +2 -0
  47. package/dist/agent-spawn/environment.d.ts +2 -0
  48. package/dist/agent-spawn/parallel.d.ts +30 -0
  49. package/dist/agent-spawn/retry.d.ts +26 -0
  50. package/dist/agent-spawn/types.d.ts +272 -0
  51. package/dist/auth-store/create-secret-store.d.ts +2 -0
  52. package/dist/auth-store/encrypted-file-store.d.ts +47 -0
  53. package/dist/auth-store/index.d.ts +7 -0
  54. package/dist/auth-store/keychain-store.d.ts +25 -0
  55. package/dist/auth-store/provider-store.d.ts +14 -0
  56. package/dist/auth-store/types.d.ts +22 -0
  57. package/dist/config-mutations/execution/run-mutations.d.ts +7 -0
  58. package/dist/config-mutations/fs-utils.d.ts +18 -0
  59. package/dist/config-mutations/index.d.ts +8 -0
  60. package/dist/config-mutations/mutations/config-mutation.d.ts +47 -0
  61. package/dist/config-mutations/mutations/file-mutation.d.ts +62 -0
  62. package/dist/config-mutations/mutations/template-mutation.d.ts +40 -0
  63. package/dist/config-mutations/template/render.d.ts +6 -0
  64. package/dist/config-mutations/types.d.ts +168 -0
  65. package/dist/poe-code-config/compile/schema-compiler.d.ts +11 -0
  66. package/dist/poe-code-config/config.d.ts +2 -0
  67. package/dist/poe-code-config/configured-services.d.ts +29 -0
  68. package/dist/poe-code-config/index.d.ts +16 -0
  69. package/dist/poe-code-config/inspect.d.ts +13 -0
  70. package/dist/poe-code-config/memory.d.ts +14 -0
  71. package/dist/poe-code-config/merge-callbacks.d.ts +38 -0
  72. package/dist/poe-code-config/merge.d.ts +2 -0
  73. package/dist/poe-code-config/plan-scope.d.ts +8 -0
  74. package/dist/poe-code-config/provider-config.d.ts +16 -0
  75. package/dist/poe-code-config/resolve.d.ts +2 -0
  76. package/dist/poe-code-config/runtime.d.ts +114 -0
  77. package/dist/poe-code-config/schema.d.ts +14 -0
  78. package/dist/poe-code-config/state/fs.d.ts +24 -0
  79. package/dist/poe-code-config/state/index.d.ts +12 -0
  80. package/dist/poe-code-config/state/jobs.d.ts +34 -0
  81. package/dist/poe-code-config/state/templates.d.ts +18 -0
  82. package/dist/poe-code-config/store.d.ts +12 -0
  83. package/dist/poe-code-config/types.d.ts +88 -0
  84. package/dist/process-runner/docker/build-context.d.ts +5 -0
  85. package/dist/process-runner/docker/context.d.ts +3 -0
  86. package/dist/process-runner/docker/docker-execution-env.d.ts +28 -0
  87. package/dist/process-runner/docker/docker-runner.d.ts +2 -0
  88. package/dist/process-runner/docker/engine.d.ts +3 -0
  89. package/dist/process-runner/host/host-execution-env.d.ts +2 -0
  90. package/dist/process-runner/host/host-runner.d.ts +3 -0
  91. package/dist/process-runner/index.d.ts +10 -0
  92. package/dist/process-runner/testing/index.d.ts +2 -0
  93. package/dist/process-runner/testing/mock-runner.d.ts +3 -0
  94. package/dist/process-runner/types.d.ts +191 -0
  95. package/dist/process-runner/workspace-transfer.d.ts +61 -0
  96. package/dist/providers/auth/api-key.d.ts +5 -0
  97. package/dist/providers/auth/types.d.ts +14 -0
  98. package/dist/providers/compatibility.d.ts +4 -0
  99. package/dist/providers/index.d.ts +8 -0
  100. package/dist/providers/providers/anthropic.d.ts +1 -0
  101. package/dist/providers/providers/cloudflare.d.ts +1 -0
  102. package/dist/providers/providers/generated.d.ts +5 -0
  103. package/dist/providers/providers/openai.d.ts +1 -0
  104. package/dist/providers/providers/poe.d.ts +2 -0
  105. package/dist/providers/registry.d.ts +44 -0
  106. package/dist/providers/types.d.ts +54 -0
  107. package/dist/safe-fs/bridge/filesystem.d.ts +88 -0
  108. package/dist/safe-fs/bridge/index.d.ts +6 -0
  109. package/dist/safe-fs/bridge/types.d.ts +75 -0
  110. package/dist/safe-fs/config.d.ts +15 -0
  111. package/dist/safe-fs/config.node.d.ts +2 -0
  112. package/dist/safe-fs/contracts/errors.d.ts +50 -0
  113. package/dist/safe-fs/contracts/filesystem.d.ts +96 -0
  114. package/dist/safe-fs/contracts/index.d.ts +4 -0
  115. package/dist/safe-fs/contracts/io.d.ts +8 -0
  116. package/dist/safe-fs/contracts/path.d.ts +8 -0
  117. package/dist/safe-fs/contracts/portable-path.d.ts +13 -0
  118. package/dist/safe-fs/contracts/virtual-path.d.ts +7 -0
  119. package/dist/safe-fs/core.d.ts +12 -0
  120. package/dist/safe-fs/fs/memory/index.d.ts +58 -0
  121. package/dist/safe-fs/fs/mount/comparison.d.ts +19 -0
  122. package/dist/safe-fs/fs/mount/index.d.ts +44 -0
  123. package/dist/safe-fs/fs/overlay/index.d.ts +73 -0
  124. package/dist/safe-fs/fs/readonly/index.d.ts +31 -0
  125. package/dist/safe-fs/fs/real/index.d.ts +76 -0
  126. package/dist/safe-fs/fs/s3/filesystem.d.ts +93 -0
  127. package/dist/safe-fs/fs/s3/http/index.d.ts +2 -0
  128. package/dist/safe-fs/fs/s3/http/transport.d.ts +3 -0
  129. package/dist/safe-fs/fs/s3/http/types.d.ts +30 -0
  130. package/dist/safe-fs/fs/s3/index.d.ts +6 -0
  131. package/dist/safe-fs/fs/s3/mock.d.ts +48 -0
  132. package/dist/safe-fs/fs/s3/transport.d.ts +103 -0
  133. package/dist/safe-fs/fs/webdav/index.d.ts +2 -0
  134. package/dist/safe-fs/fs/webdav/webdav.d.ts +101 -0
  135. package/dist/safe-fs/index.d.ts +14 -0
  136. package/dist/safe-fs/node/filesystem.d.ts +11 -0
  137. package/dist/safe-fs/node/index.d.ts +2 -0
  138. package/dist/safe-fs/node-host.d.ts +1 -0
  139. package/dist/safe-fs/node-unavailable.d.ts +1 -0
  140. package/dist/safe-fs/platform/browser.d.ts +12 -0
  141. package/dist/safe-fs/platform/node.d.ts +13 -0
  142. package/dist/safe-js/browser/chunks/chunk-QGN6DKT5.js +4335 -0
  143. package/dist/safe-js/browser/chunks/chunk-QGN6DKT5.js.map +7 -0
  144. package/dist/safe-js/browser/safe-fs-core.js +67 -0
  145. package/dist/safe-js/browser/safe-fs-core.js.map +7 -0
  146. package/dist/safe-js/browser/safe-fs.js +67 -0
  147. package/dist/safe-js/browser/safe-fs.js.map +7 -0
  148. package/dist/safe-js/chunks/chunk-2QRYPKQQ.js +4315 -0
  149. package/dist/safe-js/chunks/chunk-2QRYPKQQ.js.map +7 -0
  150. package/dist/safe-js/chunks/chunk-4YIDX44G.js +40 -0
  151. package/dist/safe-js/chunks/chunk-4YIDX44G.js.map +7 -0
  152. package/dist/safe-js/chunks/chunk-7M2SJPSZ.js +2613 -0
  153. package/dist/safe-js/chunks/chunk-7M2SJPSZ.js.map +7 -0
  154. package/dist/safe-js/chunks/chunk-DC5B3GYM.js +8248 -0
  155. package/dist/safe-js/chunks/chunk-DC5B3GYM.js.map +7 -0
  156. package/dist/safe-js/chunks/chunk-Z3D76J4U.js +30732 -0
  157. package/dist/safe-js/chunks/chunk-Z3D76J4U.js.map +7 -0
  158. package/dist/safe-js/cli.d.ts +36 -0
  159. package/dist/safe-js/cli.js +724 -0
  160. package/dist/safe-js/cli.js.map +7 -0
  161. package/dist/safe-js/core.d.ts +6 -0
  162. package/dist/safe-js/core.js +14 -0
  163. package/dist/safe-js/core.js.map +7 -0
  164. package/dist/safe-js/dump.d.ts +2 -0
  165. package/dist/safe-js/error/format.d.ts +15 -0
  166. package/dist/safe-js/error/shape.d.ts +28 -0
  167. package/dist/safe-js/index.d.ts +56 -0
  168. package/dist/safe-js/index.js +454 -0
  169. package/dist/safe-js/index.js.map +7 -0
  170. package/dist/safe-js/interp/arguments.d.ts +10 -0
  171. package/dist/safe-js/interp/async.d.ts +56 -0
  172. package/dist/safe-js/interp/budget.d.ts +95 -0
  173. package/dist/safe-js/interp/exceptions.d.ts +45 -0
  174. package/dist/safe-js/interp/generator.d.ts +16 -0
  175. package/dist/safe-js/interp/globals/console-json.d.ts +14 -0
  176. package/dist/safe-js/interp/host-bridge.d.ts +29 -0
  177. package/dist/safe-js/interp/host-call.d.ts +130 -0
  178. package/dist/safe-js/interp/interpreter.d.ts +63 -0
  179. package/dist/safe-js/interp/promise-replay.d.ts +70 -0
  180. package/dist/safe-js/interp/regex/compile-guard.d.ts +33 -0
  181. package/dist/safe-js/interp/regex/parse.d.ts +62 -0
  182. package/dist/safe-js/interp/scope.d.ts +43 -0
  183. package/dist/safe-js/interp/values.d.ts +136 -0
  184. package/dist/safe-js/lint/index.d.ts +38 -0
  185. package/dist/safe-js/lint/rules/AS-export-import-meta.d.ts +21 -0
  186. package/dist/safe-js/lint/rules/module-registry.d.ts +33 -0
  187. package/dist/safe-js/lint.d.ts +1 -0
  188. package/dist/safe-js/loader/extract-block.d.ts +10 -0
  189. package/dist/safe-js/loader/find-exported.d.ts +2 -0
  190. package/dist/safe-js/loader/frontmatter.d.ts +5 -0
  191. package/dist/safe-js/migrate.d.ts +33 -0
  192. package/dist/safe-js/migration-file.d.ts +55 -0
  193. package/dist/safe-js/modules/agent.d.ts +132 -0
  194. package/dist/safe-js/modules/env.d.ts +14 -0
  195. package/dist/safe-js/modules/fail.d.ts +6 -0
  196. package/dist/safe-js/modules/fs-config.d.ts +12 -0
  197. package/dist/safe-js/modules/fs.d.ts +82 -0
  198. package/dist/safe-js/modules/harness.d.ts +19 -0
  199. package/dist/safe-js/modules/log.d.ts +16 -0
  200. package/dist/safe-js/modules/mcp-transport.d.ts +26 -0
  201. package/dist/safe-js/modules/mcp.d.ts +63 -0
  202. package/dist/safe-js/modules/metric.d.ts +4 -0
  203. package/dist/safe-js/modules/registry.d.ts +16 -0
  204. package/dist/safe-js/modules/time.d.ts +12 -0
  205. package/dist/safe-js/observability/otel.d.ts +21 -0
  206. package/dist/safe-js/output-stream.d.ts +12 -0
  207. package/dist/safe-js/parse/parse-export.d.ts +36 -0
  208. package/dist/safe-js/parse/parser.d.ts +356 -0
  209. package/dist/safe-js/parse/tokenizer.d.ts +26 -0
  210. package/dist/safe-js/parse.d.ts +4 -0
  211. package/dist/safe-js/random.d.ts +9 -0
  212. package/dist/safe-js/restore.d.ts +26 -0
  213. package/dist/safe-js/run.d.ts +74 -0
  214. package/dist/safe-js/runner/run-harness.d.ts +32 -0
  215. package/dist/safe-js/safe-fs-core.js +130 -0
  216. package/dist/safe-js/safe-fs-core.js.map +7 -0
  217. package/dist/safe-js/safe-fs-node.js +94 -0
  218. package/dist/safe-js/safe-fs-node.js.map +7 -0
  219. package/dist/safe-js/safe-fs.js +94 -0
  220. package/dist/safe-js/safe-fs.js.map +7 -0
  221. package/dist/safe-js/snapshot/arguments.d.ts +17 -0
  222. package/dist/safe-js/snapshot/backend.d.ts +19 -0
  223. package/dist/safe-js/snapshot/dump-format.d.ts +7 -0
  224. package/dist/safe-js/snapshot/dump.d.ts +23 -0
  225. package/dist/safe-js/snapshot/float32array.d.ts +12 -0
  226. package/dist/safe-js/snapshot/migration.d.ts +35 -0
  227. package/dist/safe-js/snapshot/policy.d.ts +49 -0
  228. package/dist/safe-js/snapshot/replay-data.d.ts +71 -0
  229. package/dist/safe-js/snapshot/validation.d.ts +15 -0
  230. package/dist/task-list/backends/gh-issues-client.d.ts +19 -0
  231. package/dist/task-list/backends/gh-issues-sync.d.ts +46 -0
  232. package/dist/task-list/backends/gh-issues.d.ts +21 -0
  233. package/dist/task-list/index.d.ts +9 -0
  234. package/dist/task-list/move.d.ts +2 -0
  235. package/dist/task-list/open.d.ts +5 -0
  236. package/dist/task-list/state-machine.d.ts +16 -0
  237. package/dist/task-list/state.d.ts +29 -0
  238. package/dist/task-list/types.d.ts +206 -0
  239. package/dist/tiny-mcp-client/index.d.ts +662 -0
  240. package/dist/tiny-stdio-mcp-server/content/audio.d.ts +15 -0
  241. package/dist/tiny-stdio-mcp-server/content/convert.d.ts +16 -0
  242. package/dist/tiny-stdio-mcp-server/content/file-type.d.ts +11 -0
  243. package/dist/tiny-stdio-mcp-server/content/file.d.ts +28 -0
  244. package/dist/tiny-stdio-mcp-server/content/image.d.ts +15 -0
  245. package/dist/tiny-stdio-mcp-server/content/index.d.ts +7 -0
  246. package/dist/tiny-stdio-mcp-server/content/mime.d.ts +7 -0
  247. package/dist/tiny-stdio-mcp-server/content/remote.d.ts +5 -0
  248. package/dist/tiny-stdio-mcp-server/index.d.ts +9 -0
  249. package/dist/tiny-stdio-mcp-server/schema.d.ts +20 -0
  250. package/dist/tiny-stdio-mcp-server/server.d.ts +35 -0
  251. package/dist/tiny-stdio-mcp-server/types.d.ts +247 -0
  252. package/dist/toolcraft-design/acp/components.d.ts +19 -0
  253. package/dist/toolcraft-design/acp/index.d.ts +4 -0
  254. package/dist/toolcraft-design/acp/writer.d.ts +13 -0
  255. package/dist/toolcraft-design/components/browser.d.ts +15 -0
  256. package/dist/toolcraft-design/components/catalog.d.ts +26 -0
  257. package/dist/toolcraft-design/components/color.d.ts +31 -0
  258. package/dist/toolcraft-design/components/command-errors.d.ts +18 -0
  259. package/dist/toolcraft-design/components/detail-card.d.ts +22 -0
  260. package/dist/toolcraft-design/components/file-changes.d.ts +16 -0
  261. package/dist/toolcraft-design/components/help-formatter-plain.d.ts +5 -0
  262. package/dist/toolcraft-design/components/help-formatter.d.ts +50 -0
  263. package/dist/toolcraft-design/components/inspector-card.d.ts +21 -0
  264. package/dist/toolcraft-design/components/logger.d.ts +11 -0
  265. package/dist/toolcraft-design/components/resource-browser.d.ts +21 -0
  266. package/dist/toolcraft-design/components/symbols.d.ts +12 -0
  267. package/dist/toolcraft-design/components/table.d.ts +16 -0
  268. package/dist/toolcraft-design/components/template.d.ts +19 -0
  269. package/dist/toolcraft-design/components/text.d.ts +16 -0
  270. package/dist/toolcraft-design/dashboard/buffer.d.ts +25 -0
  271. package/dist/toolcraft-design/dashboard/components/footer.d.ts +8 -0
  272. package/dist/toolcraft-design/dashboard/dashboard.d.ts +20 -0
  273. package/dist/toolcraft-design/dashboard/index.d.ts +8 -0
  274. package/dist/toolcraft-design/dashboard/should-use-dashboard.d.ts +10 -0
  275. package/dist/toolcraft-design/dashboard/snapshot.d.ts +10 -0
  276. package/dist/toolcraft-design/dashboard/terminal.d.ts +37 -0
  277. package/dist/toolcraft-design/dashboard/types.d.ts +38 -0
  278. package/dist/toolcraft-design/explorer/events.d.ts +77 -0
  279. package/dist/toolcraft-design/explorer/index.d.ts +8 -0
  280. package/dist/toolcraft-design/explorer/keymap.d.ts +31 -0
  281. package/dist/toolcraft-design/explorer/runtime.d.ts +2 -0
  282. package/dist/toolcraft-design/explorer/state.d.ts +224 -0
  283. package/dist/toolcraft-design/index.d.ts +62 -0
  284. package/dist/toolcraft-design/internal/output-format.d.ts +6 -0
  285. package/dist/toolcraft-design/internal/strip-ansi.d.ts +1 -0
  286. package/dist/toolcraft-design/internal/theme-detect.d.ts +12 -0
  287. package/dist/toolcraft-design/internal/theme-state.d.ts +12 -0
  288. package/dist/toolcraft-design/prompts/index.d.ts +91 -0
  289. package/dist/toolcraft-design/prompts/interactive/cancel-symbol.d.ts +2 -0
  290. package/dist/toolcraft-design/prompts/interactive/select.d.ts +18 -0
  291. package/dist/toolcraft-design/prompts/primitives/cancel.d.ts +2 -0
  292. package/dist/toolcraft-design/prompts/primitives/intro.d.ts +1 -0
  293. package/dist/toolcraft-design/prompts/primitives/log.d.ts +18 -0
  294. package/dist/toolcraft-design/prompts/primitives/note.d.ts +1 -0
  295. package/dist/toolcraft-design/prompts/primitives/outro.d.ts +1 -0
  296. package/dist/toolcraft-design/prompts/primitives/spinner.d.ts +6 -0
  297. package/dist/toolcraft-design/prompts/theme.d.ts +11 -0
  298. package/dist/toolcraft-design/screen/screen.d.ts +40 -0
  299. package/dist/toolcraft-design/screen/style.d.ts +16 -0
  300. package/dist/toolcraft-design/static/index.d.ts +4 -0
  301. package/dist/toolcraft-design/static/menu.d.ts +11 -0
  302. package/dist/toolcraft-design/static/spinner.d.ts +14 -0
  303. package/dist/toolcraft-design/terminal/driver.d.ts +34 -0
  304. package/dist/toolcraft-design/terminal/input.d.ts +25 -0
  305. package/dist/toolcraft-design/terminal-markdown/ast.d.ts +98 -0
  306. package/dist/toolcraft-design/terminal-markdown/html-renderer.d.ts +7 -0
  307. package/dist/toolcraft-design/terminal-markdown/index.d.ts +12 -0
  308. package/dist/toolcraft-design/terminal-markdown/parser.d.ts +5 -0
  309. package/dist/toolcraft-design/terminal-markdown/plaintext-renderer.d.ts +11 -0
  310. package/dist/toolcraft-design/terminal-markdown/renderer.d.ts +7 -0
  311. package/dist/toolcraft-design/tokens/brand.d.ts +5 -0
  312. package/dist/toolcraft-design/tokens/colors.d.ts +37 -0
  313. package/dist/toolcraft-design/tokens/index.d.ts +6 -0
  314. package/dist/toolcraft-design/tokens/spacing.d.ts +6 -0
  315. package/dist/toolcraft-design/tokens/typography.d.ts +7 -0
  316. package/dist/toolcraft-design/tokens/widths.d.ts +5 -0
  317. package/dist/toolcraft-schema/index.d.ts +184 -0
  318. package/dist/toolcraft-schema/json-schema/index.d.ts +5 -0
  319. package/dist/toolcraft-schema/json-schema/types.d.ts +33 -0
  320. package/dist/toolcraft-schema/json-schema-document.d.ts +14 -0
  321. package/dist/toolcraft-schema/json.d.ts +10 -0
  322. package/dist/toolcraft-schema/oneof.d.ts +15 -0
  323. package/dist/toolcraft-schema/record.d.ts +5 -0
  324. package/dist/toolcraft-schema/union.d.ts +8 -0
  325. package/dist/toolcraft-schema/validate.d.ts +17 -0
  326. package/package.json +89 -0
@@ -0,0 +1,724 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ countLineBreaks,
4
+ createBrokenPipeState,
5
+ createLintModulesFromRuntimeRegistry,
6
+ createSafeOutputStream,
7
+ extractBlock,
8
+ formatInterpreterError,
9
+ makeAgentModule,
10
+ makeEnvModule,
11
+ makeFailModule,
12
+ makeFsModule,
13
+ makeHarnessModule,
14
+ makeLogModule,
15
+ makeMcpModule,
16
+ makeMetricModule,
17
+ maskSource,
18
+ migrateSnapshotFile,
19
+ parseEnvConfig,
20
+ parseFsConfig,
21
+ parseMcpConfig,
22
+ resolveFsConfig,
23
+ splitFrontmatter,
24
+ withBrokenPipeGuard
25
+ } from "./chunks/chunk-DC5B3GYM.js";
26
+ import {
27
+ Budget,
28
+ SandboxError,
29
+ dump,
30
+ dumpCurrent,
31
+ hasOwnErrorCode,
32
+ lint,
33
+ parseModule,
34
+ replaceErrorStack,
35
+ restore,
36
+ run
37
+ } from "./chunks/chunk-Z3D76J4U.js";
38
+ import "./chunks/chunk-7M2SJPSZ.js";
39
+ import "./chunks/chunk-2QRYPKQQ.js";
40
+ import "./chunks/chunk-4YIDX44G.js";
41
+
42
+ // packages/safe-js/src/cli.ts
43
+ import { mkdir, readFile, realpath, stat, writeFile } from "node:fs/promises";
44
+ import path, { dirname, extname } from "node:path";
45
+ import { formatWithOptions } from "node:util";
46
+ import { fileURLToPath } from "node:url";
47
+ var EXIT_RUNTIME = 1;
48
+ var EXIT_PARSE = 2;
49
+ var EXIT_BUDGET = 3;
50
+ var EXIT_SIGINT = 130;
51
+ async function runCli(argv, options = {}) {
52
+ const brokenPipe = createBrokenPipeState();
53
+ const stdout = createSafeOutputStream(options.stdout ?? process.stdout, brokenPipe);
54
+ const stderr = createSafeOutputStream(options.stderr ?? process.stderr, brokenPipe);
55
+ return withBrokenPipeGuard(
56
+ [options.stdout ?? process.stdout, options.stderr ?? process.stderr],
57
+ brokenPipe,
58
+ async () => {
59
+ try {
60
+ if (argv.includes("--help") || argv.includes("-h")) {
61
+ stdout.write(`${createUsage()}
62
+ `);
63
+ return 0;
64
+ }
65
+ if (argv[0] === "migrate") {
66
+ const result = await migrateSnapshotFile({
67
+ ...parseMigrationArgs(argv.slice(1)),
68
+ cwd: options.cwd ?? readCurrentWorkingDirectory()
69
+ });
70
+ stdout.write(`${JSON.stringify(result, null, 2)}
71
+ `);
72
+ return 0;
73
+ }
74
+ const parsed = parseArgs(argv);
75
+ if (parsed.filepath === void 0) {
76
+ stderr.write(`${createUsage()}
77
+ `);
78
+ return brokenPipe.closed ? 0 : EXIT_RUNTIME;
79
+ }
80
+ const cwd = options.cwd ?? readCurrentWorkingDirectory();
81
+ const filepath = path.resolve(cwd, parsed.filepath);
82
+ const configuredFs = parsed.fsConfig === void 0 ? void 0 : await resolveFsConfig(
83
+ parseFsConfig(
84
+ await (options.readFile ?? readFile)(path.resolve(cwd, parsed.fsConfig), "utf8")
85
+ )
86
+ );
87
+ await assertHarnessFile({
88
+ displayPath: parsed.filepath,
89
+ filepath,
90
+ statFile: options.stat ?? stat
91
+ });
92
+ return await runScriptFile(filepath, parsed, {
93
+ cwd,
94
+ configuredFs,
95
+ env: options.env,
96
+ mcp: options.mcp,
97
+ modulesFor: options.modulesFor,
98
+ process: options.process ?? process,
99
+ readFile: options.readFile ?? readFile,
100
+ brokenPipe,
101
+ stderr,
102
+ stdout,
103
+ writeFile: options.writeFile ?? writeFile
104
+ });
105
+ } catch (error) {
106
+ if (brokenPipe.closed) {
107
+ return 0;
108
+ }
109
+ stderr.write(`${readErrorMessage(error)}
110
+ `);
111
+ return brokenPipe.closed ? 0 : error instanceof CliExitError ? error.exitCode : exitCodeForError(error);
112
+ }
113
+ }
114
+ );
115
+ }
116
+ function readCurrentWorkingDirectory() {
117
+ try {
118
+ return process.cwd();
119
+ } catch (error) {
120
+ throw new Error(`Unable to resolve current working directory: ${readErrorMessage(error)}`);
121
+ }
122
+ }
123
+ function parseMigrationArgs(argv) {
124
+ const result = { snapshotPath: "", sourcePath: "" };
125
+ const paths = /* @__PURE__ */ new Map([
126
+ ["--from", "sourcePath"],
127
+ ["--to", "targetSourcePath"],
128
+ ["--plan", "planPath"],
129
+ ["--output", "outputPath"]
130
+ ]);
131
+ const seen = /* @__PURE__ */ new Set();
132
+ for (let index = 0; index < argv.length; index += 1) {
133
+ const argument = argv[index];
134
+ if (!argument.startsWith("-")) {
135
+ if (result.snapshotPath.length > 0)
136
+ throw new TypeError("Migration accepts exactly one snapshot path.");
137
+ result.snapshotPath = argument;
138
+ continue;
139
+ }
140
+ if (seen.has(argument)) throw new TypeError(`Duplicate migration option: ${argument}`);
141
+ seen.add(argument);
142
+ if (argument === "--inspect") {
143
+ result.inspect = true;
144
+ continue;
145
+ }
146
+ if (argument === "--dry-run") {
147
+ result.dryRun = true;
148
+ continue;
149
+ }
150
+ const key = paths.get(argument);
151
+ if (key === void 0) throw new TypeError(`Unknown migration option: ${argument}`);
152
+ const value = argv[++index];
153
+ if (value === void 0 || value.startsWith("--"))
154
+ throw new TypeError(`${argument} requires a path.`);
155
+ result[key] = value;
156
+ }
157
+ return result;
158
+ }
159
+ function parseArgs(argv) {
160
+ const parsed = {
161
+ fix: false,
162
+ fs: false
163
+ };
164
+ for (let index = 0; index < argv.length; index += 1) {
165
+ const arg = argv[index];
166
+ if (arg === "--fix") {
167
+ parsed.fix = true;
168
+ continue;
169
+ }
170
+ if (arg === "--fs") {
171
+ parsed.fs = true;
172
+ continue;
173
+ }
174
+ if (arg === "--fs-root") {
175
+ parsed.fsRoot = readFlagValue(argv, index, arg);
176
+ index += 1;
177
+ continue;
178
+ }
179
+ if (arg === "--fs-config") {
180
+ if (parsed.fsConfig !== void 0) {
181
+ throw new CliExitError("--fs-config may be specified only once.", EXIT_RUNTIME);
182
+ }
183
+ const value = readFlagValue(argv, index, arg);
184
+ if (value.trim().length === 0 || value.startsWith("--")) {
185
+ throw new CliExitError("--fs-config needs a JSON file path.", EXIT_RUNTIME);
186
+ }
187
+ parsed.fsConfig = value;
188
+ index += 1;
189
+ continue;
190
+ }
191
+ if (arg === "--mcp-config") {
192
+ parsed.mcpConfig = readFlagValue(argv, index, arg);
193
+ index += 1;
194
+ continue;
195
+ }
196
+ if (arg === "--env-config") {
197
+ parsed.envConfig = readFlagValue(argv, index, arg);
198
+ index += 1;
199
+ continue;
200
+ }
201
+ if (arg === "--snapshot") {
202
+ parsed.snapshotPath = readFlagValue(argv, index, arg);
203
+ index += 1;
204
+ continue;
205
+ }
206
+ if (arg === "--restore") {
207
+ parsed.restorePath = readFlagValue(argv, index, arg);
208
+ index += 1;
209
+ continue;
210
+ }
211
+ if (arg === "--max-steps") {
212
+ parsed.maxSteps = readPositiveInteger(readFlagValue(argv, index, arg), arg);
213
+ index += 1;
214
+ continue;
215
+ }
216
+ if (arg === "--data-size") {
217
+ parsed.dataSize = readPositiveInteger(readFlagValue(argv, index, arg), arg);
218
+ index += 1;
219
+ continue;
220
+ }
221
+ if (arg.startsWith("-")) {
222
+ throw new CliExitError(`Unknown flag: ${arg}`, EXIT_RUNTIME);
223
+ }
224
+ if (parsed.filepath !== void 0) {
225
+ throw new CliExitError(`Unexpected argument: ${arg}`, EXIT_RUNTIME);
226
+ }
227
+ parsed.filepath = arg;
228
+ }
229
+ if (parsed.fsConfig !== void 0 && (parsed.fs || parsed.fsRoot !== void 0)) {
230
+ throw new CliExitError("--fs-config cannot be combined with --fs or --fs-root.", EXIT_RUNTIME);
231
+ }
232
+ if (!parsed.fs && parsed.fsRoot !== void 0) {
233
+ throw new CliExitError(
234
+ "--fs-root requires --fs. Pass --fs to give the script a filesystem confined to that root, or drop --fs-root.",
235
+ EXIT_RUNTIME
236
+ );
237
+ }
238
+ return parsed;
239
+ }
240
+ function readFlagValue(argv, index, flag) {
241
+ const value = argv[index + 1];
242
+ if (value === void 0 || value.length === 0) {
243
+ throw new CliExitError(`Missing value for ${flag}`, EXIT_RUNTIME);
244
+ }
245
+ return value;
246
+ }
247
+ function readPositiveInteger(value, flag) {
248
+ const parsed = Number(value);
249
+ if (!Number.isInteger(parsed) || parsed <= 0) {
250
+ throw new CliExitError(`${flag} must be a positive integer`, EXIT_RUNTIME);
251
+ }
252
+ return parsed;
253
+ }
254
+ async function assertHarnessFile(input) {
255
+ let stats;
256
+ try {
257
+ stats = await input.statFile(input.filepath);
258
+ } catch (error) {
259
+ if (hasErrorCode(error, "ENOENT")) {
260
+ throw new CliExitError(`File not found: ${input.displayPath}`, EXIT_RUNTIME);
261
+ }
262
+ throw error;
263
+ }
264
+ if (!stats.isFile()) {
265
+ throw new CliExitError(`Harness path must point to a file: ${input.displayPath}`, EXIT_RUNTIME);
266
+ }
267
+ }
268
+ async function runScriptFile(filepath, parsed, options) {
269
+ const loaded = loadExecutableSource(filepath, await options.readFile(filepath, "utf8"));
270
+ const meta = {
271
+ filepath,
272
+ kind: loaded.frontmatter.kind,
273
+ version: loaded.frontmatter.version
274
+ };
275
+ const runtime = createRuntime(loaded.frontmatter, meta, {
276
+ fs: parsed.fs ? { root: path.resolve(options.cwd, parsed.fsRoot ?? dirname(filepath)) } : void 0,
277
+ modulesFor: options.modulesFor,
278
+ stderr: options.stderr,
279
+ stdout: options.stdout
280
+ });
281
+ if (options.configuredFs !== void 0) {
282
+ const registry = new Map(
283
+ runtime.registry instanceof Map ? runtime.registry : Object.entries(runtime.registry)
284
+ );
285
+ if (registry.has("fs")) throw new TypeError("fs is already registered by modulesFor.");
286
+ registry.set("fs", toModuleExports(makeFsModule(options.configuredFs)));
287
+ runtime.registry = registry;
288
+ }
289
+ let env = options.env;
290
+ if (parsed.envConfig !== void 0) {
291
+ if (env !== void 0)
292
+ throw new TypeError("Pass environment options or --env-config, not both.");
293
+ const configPath = path.resolve(options.cwd, parsed.envConfig);
294
+ env = parseEnvConfig(await options.readFile(configPath, "utf8"));
295
+ }
296
+ if (env !== void 0) {
297
+ const registry = new Map(
298
+ runtime.registry instanceof Map ? runtime.registry : Object.entries(runtime.registry)
299
+ );
300
+ if (registry.has("env"))
301
+ throw new TypeError("Environment is already registered by modulesFor.");
302
+ registry.set("env", makeEnvModule(env));
303
+ runtime.registry = registry;
304
+ }
305
+ let mcp = options.mcp;
306
+ if (parsed.mcpConfig !== void 0) {
307
+ if (mcp !== void 0) throw new TypeError("Pass MCP options or --mcp-config, not both.");
308
+ const configPath = path.resolve(options.cwd, parsed.mcpConfig);
309
+ mcp = parseMcpConfig(await options.readFile(configPath, "utf8"), dirname(configPath));
310
+ }
311
+ if (mcp !== void 0) {
312
+ const registry = new Map(
313
+ runtime.registry instanceof Map ? runtime.registry : Object.entries(runtime.registry)
314
+ );
315
+ if (registry.has("mcp")) throw new TypeError("MCP is already registered by modulesFor.");
316
+ registry.set("mcp", makeMcpModule(mcp));
317
+ runtime.registry = registry;
318
+ }
319
+ const modules = excludeHarnessModule(runtime.registry, loaded.isRawScript);
320
+ let executableSource = loaded.executableSource;
321
+ const lintResult = parsed.fix ? lint(executableSource, {
322
+ allowedExportNames: ["schema"],
323
+ filename: filepath,
324
+ fix: true,
325
+ fixRanges: loaded.fixRanges,
326
+ frontmatterFields: Object.keys(loaded.frontmatter),
327
+ modules: createLintModulesFromRuntimeRegistry(modules)
328
+ }) : lint(executableSource, {
329
+ allowedExportNames: ["schema"],
330
+ filename: filepath,
331
+ frontmatterFields: Object.keys(loaded.frontmatter),
332
+ modules: createLintModulesFromRuntimeRegistry(modules)
333
+ });
334
+ const diagnostics = Array.isArray(lintResult) ? lintResult : lintResult.diagnostics;
335
+ if (!Array.isArray(lintResult)) {
336
+ executableSource = lintResult.fixed;
337
+ if (lintResult.fixed !== loaded.executableSource) {
338
+ await options.writeFile(
339
+ filepath,
340
+ replaceExecutableSource(loaded.rawSource, loaded, lintResult.fixes),
341
+ {
342
+ encoding: "utf8"
343
+ }
344
+ );
345
+ }
346
+ }
347
+ const lintErrors = diagnostics.filter((diagnostic) => diagnostic.severity === "error");
348
+ if (lintErrors.length > 0) {
349
+ options.stderr.write(`Lint failed:
350
+ ${formatDiagnostics(lintErrors)}
351
+ `);
352
+ if (options.brokenPipe.closed) {
353
+ return 0;
354
+ }
355
+ return lintErrors.some((diagnostic) => diagnostic.code === "AS001") ? EXIT_PARSE : EXIT_RUNTIME;
356
+ }
357
+ const lintWarnings = diagnostics.filter((diagnostic) => diagnostic.severity === "warning");
358
+ if (lintWarnings.length > 0) {
359
+ options.stderr.write(`Lint warnings:
360
+ ${formatDiagnostics(lintWarnings)}
361
+ `);
362
+ if (options.brokenPipe.closed) {
363
+ return 0;
364
+ }
365
+ }
366
+ const snapshot = await readRestoreSnapshot(parsed.restorePath, options);
367
+ if (snapshot !== void 0) {
368
+ restore(snapshot, { source: executableSource });
369
+ }
370
+ const abortController = new AbortController();
371
+ let interrupted = false;
372
+ let runPromise;
373
+ let signalSnapshotWrite;
374
+ const onSigint = () => {
375
+ interrupted = true;
376
+ abortController.abort(createAbortError());
377
+ options.stderr.write("Interrupted by SIGINT\n");
378
+ if (parsed.snapshotPath !== void 0 && runPromise !== void 0) {
379
+ signalSnapshotWrite = writeCurrentSnapshot(runPromise, parsed.snapshotPath, options);
380
+ }
381
+ };
382
+ options.process.on("SIGINT", onSigint);
383
+ try {
384
+ runPromise = run(executableSource, {
385
+ budget: parsed.maxSteps === void 0 && parsed.dataSize === void 0 ? void 0 : new Budget({ dataSize: parsed.dataSize, maxSteps: parsed.maxSteps }),
386
+ entryPointArgs: hasDefaultExport(executableSource, filepath) ? [] : void 0,
387
+ filename: filepath,
388
+ modules,
389
+ signal: abortController.signal,
390
+ sink: createConsoleSink(options.stdout, options.stderr),
391
+ snapshot
392
+ });
393
+ const result = await runPromise;
394
+ await signalSnapshotWrite;
395
+ if (options.brokenPipe.closed) {
396
+ return 0;
397
+ }
398
+ if (parsed.snapshotPath !== void 0) {
399
+ await writeSnapshot(parsed.snapshotPath, await dump(result), options);
400
+ }
401
+ if (!result.ok) {
402
+ options.stderr.write(
403
+ `${formatInterpreterError(result.error, {
404
+ filename: filepath,
405
+ source: executableSource
406
+ })}
407
+ `
408
+ );
409
+ if (options.brokenPipe.closed) {
410
+ return 0;
411
+ }
412
+ return interrupted ? EXIT_SIGINT : exitCodeForError(result.error);
413
+ }
414
+ options.stdout.write(`${JSON.stringify({ ok: true, returnValue: result.returnValue })}
415
+ `);
416
+ return options.brokenPipe.closed ? 0 : interrupted ? EXIT_SIGINT : 0;
417
+ } catch (error) {
418
+ await signalSnapshotWrite;
419
+ if (parsed.snapshotPath !== void 0 && runPromise !== void 0) {
420
+ try {
421
+ await writeSnapshot(
422
+ parsed.snapshotPath,
423
+ await dump(runPromise, { onFailure: "checkpoint" }),
424
+ options
425
+ );
426
+ } catch (snapshotError) {
427
+ options.stderr.write(
428
+ `Failed to write recovery snapshot at ${parsed.snapshotPath}: ${readErrorMessage(snapshotError)}. Any existing snapshot may be stale.
429
+ `
430
+ );
431
+ }
432
+ }
433
+ if (options.brokenPipe.closed) {
434
+ return 0;
435
+ }
436
+ options.stderr.write(
437
+ `${formatInterpreterError(error, {
438
+ filename: filepath,
439
+ source: executableSource
440
+ })}
441
+ `
442
+ );
443
+ return options.brokenPipe.closed ? 0 : interrupted ? EXIT_SIGINT : exitCodeForError(error);
444
+ } finally {
445
+ options.process.off("SIGINT", onSigint);
446
+ }
447
+ }
448
+ function loadExecutableSource(filepath, rawSource) {
449
+ const source = stripByteOrderMark(rawSource);
450
+ const byteOrderMarkLength = rawSource.length - source.length;
451
+ if (isRawScriptExtension(extname(filepath))) {
452
+ return {
453
+ sourceOffset: byteOrderMarkLength,
454
+ executableSource: source,
455
+ frontmatter: {},
456
+ isRawScript: true,
457
+ rawSource
458
+ };
459
+ }
460
+ const { frontmatter, body } = splitFrontmatter(source);
461
+ const bodyStartOffset = rawSource.length - body.length;
462
+ const executableBlock = extractBlock(body, countLineBreaks(rawSource, 0, bodyStartOffset) + 1);
463
+ return {
464
+ sourceOffset: 0,
465
+ fixRanges: executableBlock.ranges.map(([start, end]) => [
466
+ bodyStartOffset + start,
467
+ bodyStartOffset + end
468
+ ]),
469
+ executableSource: maskSource(rawSource.slice(0, bodyStartOffset + executableBlock.startOffset)) + executableBlock.source,
470
+ frontmatter,
471
+ isRawScript: false,
472
+ rawSource
473
+ };
474
+ }
475
+ function isRawScriptExtension(extension) {
476
+ return extension === ".safejs" || extension === ".ajs";
477
+ }
478
+ function replaceExecutableSource(source, loaded, fixes) {
479
+ return fixes.reduce(
480
+ (result, fix) => `${result.slice(0, loaded.sourceOffset + fix.range[0])}${fix.replacement}${result.slice(loaded.sourceOffset + fix.range[1])}`,
481
+ source
482
+ );
483
+ }
484
+ function createRuntime(frontmatter, meta, options) {
485
+ if (options.modulesFor !== void 0) {
486
+ return {
487
+ registry: options.modulesFor(frontmatter, meta, {
488
+ stderr: options.stderr,
489
+ stdout: options.stdout
490
+ })
491
+ };
492
+ }
493
+ const state = {
494
+ metricCalls: /* @__PURE__ */ new Map(),
495
+ spawnCount: 0
496
+ };
497
+ const harness = makeHarnessModule(frontmatter, meta);
498
+ const agent = makeAgentModule(async (input) => {
499
+ state.spawnCount += 1;
500
+ return {
501
+ exitCode: 0,
502
+ stdout: "",
503
+ stderr: "",
504
+ summary: `${input.agent} handled ${summarizePrompt(input.prompt)}`,
505
+ durationMs: 25 * state.spawnCount
506
+ };
507
+ });
508
+ const log = makeLogModule((entry) => {
509
+ const normalized = normalizeLogEntry(entry);
510
+ const stream = normalized.type === "error" ? options.stderr : options.stdout;
511
+ stream.write(`${JSON.stringify(normalized)}
512
+ `);
513
+ });
514
+ const metric = makeMetricModule(async (scriptName) => `${readMetricScore(scriptName, state)}
515
+ `);
516
+ return {
517
+ registry: {
518
+ agent: toModuleExports(agent),
519
+ fail: toModuleExports(/* @__PURE__ */ new Map([["default", makeFailModule().default]])),
520
+ // The one module here that is not a stub, so it is registered only when asked for.
521
+ ...options.fs === void 0 ? {} : { fs: toModuleExports(makeFsModule(options.fs)) },
522
+ harness: toModuleExports(harness),
523
+ log: toModuleExports(log),
524
+ metric: toModuleExports(metric)
525
+ }
526
+ };
527
+ }
528
+ async function readRestoreSnapshot(restorePath, options) {
529
+ if (restorePath === void 0) {
530
+ return void 0;
531
+ }
532
+ const snapshotPath = path.resolve(options.cwd, restorePath);
533
+ let rawSnapshot;
534
+ try {
535
+ rawSnapshot = await options.readFile(snapshotPath, "utf8");
536
+ } catch (error) {
537
+ if (hasErrorCode(error, "ENOENT")) {
538
+ throw new CliExitError(`Snapshot not found: ${restorePath}`, EXIT_RUNTIME);
539
+ }
540
+ throw error;
541
+ }
542
+ try {
543
+ return JSON.parse(rawSnapshot);
544
+ } catch (error) {
545
+ throw new Error(`Failed to parse snapshot at ${restorePath}: ${readErrorMessage(error)}`);
546
+ }
547
+ }
548
+ async function writeCurrentSnapshot(result, snapshotPath, options) {
549
+ try {
550
+ await writeSnapshot(snapshotPath, await dumpCurrent(result), options);
551
+ } catch (error) {
552
+ options.stderr.write(
553
+ `Failed to write snapshot at ${snapshotPath}: ${readErrorMessage(error)}
554
+ `
555
+ );
556
+ }
557
+ }
558
+ async function writeSnapshot(snapshotPath, content, options) {
559
+ const resolvedPath = path.resolve(options.cwd, snapshotPath);
560
+ await mkdir(dirname(resolvedPath), { recursive: true });
561
+ await options.writeFile(resolvedPath, content, { encoding: "utf8" });
562
+ }
563
+ function createConsoleSink(stdout, stderr) {
564
+ return {
565
+ error(...args) {
566
+ stderr.write(`${formatConsoleArgs(args)}
567
+ `);
568
+ },
569
+ log(...args) {
570
+ stdout.write(`${formatConsoleArgs(args)}
571
+ `);
572
+ }
573
+ };
574
+ }
575
+ function formatConsoleArgs(args) {
576
+ return formatWithOptions({ colors: false, depth: 4 }, ...args);
577
+ }
578
+ function createUsage() {
579
+ return [
580
+ "Usage: poe-safe-js [options] <script.md|script.safejs|script.ajs>",
581
+ " poe-safe-js migrate <checkpoint.json> --from <original.ajs> --inspect",
582
+ " poe-safe-js migrate <checkpoint.json> --from <original.ajs> --to <continuation.ajs>",
583
+ " --plan <migration.json> --output <new-checkpoint.json> [--dry-run]",
584
+ "",
585
+ "Compatibility alias: poe-safejs",
586
+ "",
587
+ "Options:",
588
+ " --fix apply lint fixes before running",
589
+ " --fs register the fs module: a real filesystem, unlike the agent",
590
+ " and metric stubs this runner bundles",
591
+ " --fs-root <path> directory --fs confines the script to (default: the script's",
592
+ " directory)",
593
+ " --fs-config <path> configure shared filesystem access from JSON (Node only)",
594
+ " --mcp-config <path> register named MCP servers from an explicit JSON config",
595
+ " --env-config <path> grant environment reads from an explicit JSON config",
596
+ " --snapshot <path> write success/failure state; best-effort snapshot on SIGINT",
597
+ " --restore <path> restore from a snapshot before running",
598
+ " --max-steps <n> cap interpreter step budget",
599
+ " --data-size <n> cap retained sandbox data units",
600
+ " -h, --help print this help",
601
+ "",
602
+ "Exit codes:",
603
+ " 0 success",
604
+ " 1 runtime, usage, file, or restore error",
605
+ " 2 parse error",
606
+ " 3 budget exceeded",
607
+ " 130 interrupted by SIGINT"
608
+ ].join("\n");
609
+ }
610
+ function formatDiagnostics(diagnostics) {
611
+ return diagnostics.map(
612
+ (diagnostic) => `${diagnostic.filename}:${diagnostic.line}:${diagnostic.column} ${diagnostic.code} ${diagnostic.message}`
613
+ ).join("\n");
614
+ }
615
+ function exitCodeForError(error) {
616
+ if (error instanceof SandboxError && error.code === "budgetExceeded") {
617
+ return EXIT_BUDGET;
618
+ }
619
+ if (isParseError(error)) {
620
+ return EXIT_PARSE;
621
+ }
622
+ return EXIT_RUNTIME;
623
+ }
624
+ function isParseError(error) {
625
+ return error instanceof Error && error.name === "ParseError";
626
+ }
627
+ function hasDefaultExport(source, filename) {
628
+ return parseModule(source, filename).body.some(
629
+ (statement) => statement.type === "ExportDefaultDeclaration"
630
+ );
631
+ }
632
+ function excludeHarnessModule(modules, isRawScript) {
633
+ if (!isRawScript) {
634
+ return modules;
635
+ }
636
+ if (modules instanceof Map) {
637
+ const rawModules2 = new Map(modules);
638
+ rawModules2.delete("harness");
639
+ return rawModules2;
640
+ }
641
+ const rawModules = /* @__PURE__ */ Object.create(null);
642
+ for (const [moduleName, moduleExports] of Object.entries(modules)) {
643
+ if (moduleName !== "harness") {
644
+ rawModules[moduleName] = moduleExports;
645
+ }
646
+ }
647
+ return rawModules;
648
+ }
649
+ function stripByteOrderMark(source) {
650
+ return source.startsWith("\uFEFF") ? source.slice(1) : source;
651
+ }
652
+ function normalizeLogEntry(entry) {
653
+ return {
654
+ ...entry,
655
+ ts: "2026-04-29T00:00:00.000Z"
656
+ };
657
+ }
658
+ function summarizePrompt(prompt) {
659
+ const normalizedPrompt = prompt.trim().replaceAll("\n", " ");
660
+ return normalizedPrompt.length <= 48 ? normalizedPrompt : `${normalizedPrompt.slice(0, 45)}...`;
661
+ }
662
+ function readMetricScore(scriptName, state) {
663
+ const callCount = (state.metricCalls.get(scriptName) ?? 0) + 1;
664
+ state.metricCalls.set(scriptName, callCount);
665
+ if (scriptName === "tests" && callCount === 1) {
666
+ return 10;
667
+ }
668
+ if (scriptName === "tests" && callCount === 2) {
669
+ return 9;
670
+ }
671
+ return 9 + callCount;
672
+ }
673
+ function toModuleExports(value) {
674
+ return value;
675
+ }
676
+ function createAbortError() {
677
+ if (typeof DOMException === "function") {
678
+ const error2 = new DOMException("This operation was aborted", "AbortError");
679
+ replaceErrorStack(error2);
680
+ return error2;
681
+ }
682
+ const error = new Error("This operation was aborted");
683
+ error.name = "AbortError";
684
+ replaceErrorStack(error);
685
+ return error;
686
+ }
687
+ function hasErrorCode(error, code) {
688
+ return hasOwnErrorCode(error, code);
689
+ }
690
+ function readErrorMessage(error) {
691
+ if (error instanceof Error) {
692
+ return error.message;
693
+ }
694
+ return String(error);
695
+ }
696
+ var CliExitError = class extends Error {
697
+ exitCode;
698
+ constructor(message, exitCode) {
699
+ super(message);
700
+ this.name = "CliExitError";
701
+ this.exitCode = exitCode;
702
+ }
703
+ };
704
+ async function isDirectExecution(entryPoint) {
705
+ if (typeof entryPoint !== "string" || entryPoint.length === 0) {
706
+ return false;
707
+ }
708
+ try {
709
+ const [resolvedEntryPoint, resolvedModule] = await Promise.all([
710
+ realpath(path.resolve(entryPoint)),
711
+ realpath(fileURLToPath(import.meta.url))
712
+ ]);
713
+ return resolvedEntryPoint === resolvedModule;
714
+ } catch {
715
+ return false;
716
+ }
717
+ }
718
+ if (await isDirectExecution(process.argv[1])) {
719
+ process.exitCode = await runCli(process.argv.slice(2));
720
+ }
721
+ export {
722
+ runCli
723
+ };
724
+ //# sourceMappingURL=cli.js.map