dotdo 0.0.1 → 0.0.2

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 (727) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +446 -315
  3. package/dist/ai/index.js +19 -0
  4. package/dist/ai/index.js.map +1 -0
  5. package/dist/ai/template-literals.js +852 -0
  6. package/dist/ai/template-literals.js.map +1 -0
  7. package/dist/api/analytics/router.js +601 -0
  8. package/dist/api/analytics/router.js.map +1 -0
  9. package/dist/api/index.js +158 -0
  10. package/dist/api/index.js.map +1 -0
  11. package/dist/api/middleware/auth-federation.js +573 -0
  12. package/dist/api/middleware/auth-federation.js.map +1 -0
  13. package/dist/api/middleware/auth.js +544 -0
  14. package/dist/api/middleware/auth.js.map +1 -0
  15. package/dist/api/middleware/error-handling.js +176 -0
  16. package/dist/api/middleware/error-handling.js.map +1 -0
  17. package/dist/api/middleware/request-id.js +21 -0
  18. package/dist/api/middleware/request-id.js.map +1 -0
  19. package/dist/api/pages.js +1180 -0
  20. package/dist/api/pages.js.map +1 -0
  21. package/dist/api/routes/api.js +612 -0
  22. package/dist/api/routes/api.js.map +1 -0
  23. package/dist/api/routes/browsers.js +471 -0
  24. package/dist/api/routes/browsers.js.map +1 -0
  25. package/dist/api/routes/do.js +188 -0
  26. package/dist/api/routes/do.js.map +1 -0
  27. package/dist/api/routes/mcp.js +459 -0
  28. package/dist/api/routes/mcp.js.map +1 -0
  29. package/dist/api/routes/obs.js +445 -0
  30. package/dist/api/routes/obs.js.map +1 -0
  31. package/dist/api/routes/openapi.js +794 -0
  32. package/dist/api/routes/openapi.js.map +1 -0
  33. package/dist/api/routes/rpc.js +1103 -0
  34. package/dist/api/routes/rpc.js.map +1 -0
  35. package/dist/api/routes/sandboxes.js +389 -0
  36. package/dist/api/routes/sandboxes.js.map +1 -0
  37. package/dist/api/test-do.js +38 -0
  38. package/dist/api/test-do.js.map +1 -0
  39. package/dist/api/types.js +11 -0
  40. package/dist/api/types.js.map +1 -0
  41. package/dist/cli/bin.js +2 -0
  42. package/dist/cli/main.js +52342 -0
  43. package/dist/db/actions.js +212 -0
  44. package/dist/db/actions.js.map +1 -0
  45. package/dist/db/auth.js +506 -0
  46. package/dist/db/auth.js.map +1 -0
  47. package/dist/db/branches.js +65 -0
  48. package/dist/db/branches.js.map +1 -0
  49. package/dist/db/clickhouse.js +1074 -0
  50. package/dist/db/clickhouse.js.map +1 -0
  51. package/dist/db/dlq.js +39 -0
  52. package/dist/db/dlq.js.map +1 -0
  53. package/dist/db/events.js +28 -0
  54. package/dist/db/events.js.map +1 -0
  55. package/dist/db/exec.js +64 -0
  56. package/dist/db/exec.js.map +1 -0
  57. package/dist/db/files.js +85 -0
  58. package/dist/db/files.js.map +1 -0
  59. package/dist/db/flags.js +24 -0
  60. package/dist/db/flags.js.map +1 -0
  61. package/dist/db/git.js +116 -0
  62. package/dist/db/git.js.map +1 -0
  63. package/dist/db/iceberg/inverted-index.js +862 -0
  64. package/dist/db/iceberg/inverted-index.js.map +1 -0
  65. package/dist/db/iceberg/puffin.js +878 -0
  66. package/dist/db/iceberg/puffin.js.map +1 -0
  67. package/dist/db/iceberg/search-manifest.js +422 -0
  68. package/dist/db/iceberg/search-manifest.js.map +1 -0
  69. package/dist/db/iceberg/types.js +8 -0
  70. package/dist/db/iceberg/types.js.map +1 -0
  71. package/dist/db/index.js +121 -0
  72. package/dist/db/index.js.map +1 -0
  73. package/dist/db/integrations.js +368 -0
  74. package/dist/db/integrations.js.map +1 -0
  75. package/dist/db/json-indexes.js +332 -0
  76. package/dist/db/json-indexes.js.map +1 -0
  77. package/dist/db/linked-accounts.js +287 -0
  78. package/dist/db/linked-accounts.js.map +1 -0
  79. package/dist/db/nouns.js +183 -0
  80. package/dist/db/nouns.js.map +1 -0
  81. package/dist/db/objects.js +170 -0
  82. package/dist/db/objects.js.map +1 -0
  83. package/dist/db/primitives/dag-scheduler/index.js +869 -0
  84. package/dist/db/primitives/dag-scheduler/index.js.map +1 -0
  85. package/dist/db/primitives/exactly-once-context.js +237 -0
  86. package/dist/db/primitives/exactly-once-context.js.map +1 -0
  87. package/dist/db/primitives/index.js +62 -0
  88. package/dist/db/primitives/index.js.map +1 -0
  89. package/dist/db/primitives/keyed-router.js +145 -0
  90. package/dist/db/primitives/keyed-router.js.map +1 -0
  91. package/dist/db/primitives/observability.js +162 -0
  92. package/dist/db/primitives/observability.js.map +1 -0
  93. package/dist/db/primitives/schema-evolution.js +643 -0
  94. package/dist/db/primitives/schema-evolution.js.map +1 -0
  95. package/dist/db/primitives/stateful-operator/index.js +770 -0
  96. package/dist/db/primitives/stateful-operator/index.js.map +1 -0
  97. package/dist/db/primitives/temporal-store.js +306 -0
  98. package/dist/db/primitives/temporal-store.js.map +1 -0
  99. package/dist/db/primitives/typed-column-store.js +1229 -0
  100. package/dist/db/primitives/typed-column-store.js.map +1 -0
  101. package/dist/db/primitives/utils/duration.js +162 -0
  102. package/dist/db/primitives/utils/duration.js.map +1 -0
  103. package/dist/db/primitives/utils/murmur3.js +118 -0
  104. package/dist/db/primitives/utils/murmur3.js.map +1 -0
  105. package/dist/db/primitives/watermark-service.js +136 -0
  106. package/dist/db/primitives/watermark-service.js.map +1 -0
  107. package/dist/db/primitives/window-manager.js +764 -0
  108. package/dist/db/primitives/window-manager.js.map +1 -0
  109. package/dist/db/relationships.js +66 -0
  110. package/dist/db/relationships.js.map +1 -0
  111. package/dist/db/schema-minimal.js +61 -0
  112. package/dist/db/schema-minimal.js.map +1 -0
  113. package/dist/db/search.js +28 -0
  114. package/dist/db/search.js.map +1 -0
  115. package/dist/db/stores.js +1665 -0
  116. package/dist/db/stores.js.map +1 -0
  117. package/dist/db/things.js +297 -0
  118. package/dist/db/things.js.map +1 -0
  119. package/dist/db/vault.js +171 -0
  120. package/dist/db/vault.js.map +1 -0
  121. package/dist/db/verbs.js +102 -0
  122. package/dist/db/verbs.js.map +1 -0
  123. package/dist/do/base.js +48 -0
  124. package/dist/do/base.js.map +1 -0
  125. package/dist/do/bash.js +35 -0
  126. package/dist/do/bash.js.map +1 -0
  127. package/dist/do/fs.js +25 -0
  128. package/dist/do/fs.js.map +1 -0
  129. package/dist/do/full.js +61 -0
  130. package/dist/do/full.js.map +1 -0
  131. package/dist/do/git.js +28 -0
  132. package/dist/do/git.js.map +1 -0
  133. package/dist/do/index.js +52 -0
  134. package/dist/do/index.js.map +1 -0
  135. package/dist/do/tiny.js +31 -0
  136. package/dist/do/tiny.js.map +1 -0
  137. package/dist/lib/DOAuth.js +261 -0
  138. package/dist/lib/DOAuth.js.map +1 -0
  139. package/dist/lib/DODispatcher.js +72 -0
  140. package/dist/lib/DODispatcher.js.map +1 -0
  141. package/dist/lib/Modifier.js +189 -0
  142. package/dist/lib/Modifier.js.map +1 -0
  143. package/dist/lib/StateStorage.js +403 -0
  144. package/dist/lib/StateStorage.js.map +1 -0
  145. package/dist/lib/TypeRegistry.js +122 -0
  146. package/dist/lib/TypeRegistry.js.map +1 -0
  147. package/dist/lib/agent/tools/bash.js +336 -0
  148. package/dist/lib/agent/tools/bash.js.map +1 -0
  149. package/dist/lib/agent/tools/edit.js +157 -0
  150. package/dist/lib/agent/tools/edit.js.map +1 -0
  151. package/dist/lib/agent/tools/glob.js +137 -0
  152. package/dist/lib/agent/tools/glob.js.map +1 -0
  153. package/dist/lib/agent/tools/grep.js +315 -0
  154. package/dist/lib/agent/tools/grep.js.map +1 -0
  155. package/dist/lib/agent/tools/index.js +71 -0
  156. package/dist/lib/agent/tools/index.js.map +1 -0
  157. package/dist/lib/agent/tools/read.js +212 -0
  158. package/dist/lib/agent/tools/read.js.map +1 -0
  159. package/dist/lib/agent/tools/types.js +197 -0
  160. package/dist/lib/agent/tools/types.js.map +1 -0
  161. package/dist/lib/agent/tools/write.js +159 -0
  162. package/dist/lib/agent/tools/write.js.map +1 -0
  163. package/dist/lib/ai/gateway.js +247 -0
  164. package/dist/lib/ai/gateway.js.map +1 -0
  165. package/dist/lib/ai/tool-loop-agent.js +591 -0
  166. package/dist/lib/ai/tool-loop-agent.js.map +1 -0
  167. package/dist/lib/auto-wiring.js +439 -0
  168. package/dist/lib/auto-wiring.js.map +1 -0
  169. package/dist/lib/browse/browserbase.js +163 -0
  170. package/dist/lib/browse/browserbase.js.map +1 -0
  171. package/dist/lib/browse/cloudflare.js +144 -0
  172. package/dist/lib/browse/cloudflare.js.map +1 -0
  173. package/dist/lib/browse/index.js +62 -0
  174. package/dist/lib/browse/index.js.map +1 -0
  175. package/dist/lib/browse/types.js +13 -0
  176. package/dist/lib/browse/types.js.map +1 -0
  177. package/dist/lib/cache/index.js +37 -0
  178. package/dist/lib/cache/index.js.map +1 -0
  179. package/dist/lib/cache/visibility.js +638 -0
  180. package/dist/lib/cache/visibility.js.map +1 -0
  181. package/dist/lib/capabilities.js +268 -0
  182. package/dist/lib/capabilities.js.map +1 -0
  183. package/dist/lib/channels/base.js +106 -0
  184. package/dist/lib/channels/base.js.map +1 -0
  185. package/dist/lib/channels/discord.js +94 -0
  186. package/dist/lib/channels/discord.js.map +1 -0
  187. package/dist/lib/channels/email.js +204 -0
  188. package/dist/lib/channels/email.js.map +1 -0
  189. package/dist/lib/channels/index.js +90 -0
  190. package/dist/lib/channels/index.js.map +1 -0
  191. package/dist/lib/channels/mdxui-chat.js +95 -0
  192. package/dist/lib/channels/mdxui-chat.js.map +1 -0
  193. package/dist/lib/channels/slack-blockkit.js +121 -0
  194. package/dist/lib/channels/slack-blockkit.js.map +1 -0
  195. package/dist/lib/channels/types.js +7 -0
  196. package/dist/lib/channels/types.js.map +1 -0
  197. package/dist/lib/cloudflare/ai.js +654 -0
  198. package/dist/lib/cloudflare/ai.js.map +1 -0
  199. package/dist/lib/cloudflare/index.js +88 -0
  200. package/dist/lib/cloudflare/index.js.map +1 -0
  201. package/dist/lib/cloudflare/kv.js +342 -0
  202. package/dist/lib/cloudflare/kv.js.map +1 -0
  203. package/dist/lib/cloudflare/queues.js +434 -0
  204. package/dist/lib/cloudflare/queues.js.map +1 -0
  205. package/dist/lib/cloudflare/r2.js +604 -0
  206. package/dist/lib/cloudflare/r2.js.map +1 -0
  207. package/dist/lib/cloudflare/vectorize.js +494 -0
  208. package/dist/lib/cloudflare/vectorize.js.map +1 -0
  209. package/dist/lib/cloudflare/workflows.js +569 -0
  210. package/dist/lib/cloudflare/workflows.js.map +1 -0
  211. package/dist/lib/colo/caching.js +196 -0
  212. package/dist/lib/colo/caching.js.map +1 -0
  213. package/dist/lib/colo/detection.js +194 -0
  214. package/dist/lib/colo/detection.js.map +1 -0
  215. package/dist/lib/colo/external-data.js +219 -0
  216. package/dist/lib/colo/external-data.js.map +1 -0
  217. package/dist/lib/colo/globe-data.js +179 -0
  218. package/dist/lib/colo/globe-data.js.map +1 -0
  219. package/dist/lib/colo/index.js +16 -0
  220. package/dist/lib/colo/index.js.map +1 -0
  221. package/dist/lib/decorators.js +37 -0
  222. package/dist/lib/decorators.js.map +1 -0
  223. package/dist/lib/discovery.js +81 -0
  224. package/dist/lib/discovery.js.map +1 -0
  225. package/dist/lib/executors/AgenticFunctionExecutor.js +619 -0
  226. package/dist/lib/executors/AgenticFunctionExecutor.js.map +1 -0
  227. package/dist/lib/executors/BaseFunctionExecutor.js +328 -0
  228. package/dist/lib/executors/BaseFunctionExecutor.js.map +1 -0
  229. package/dist/lib/executors/CascadeExecutor.js +418 -0
  230. package/dist/lib/executors/CascadeExecutor.js.map +1 -0
  231. package/dist/lib/executors/CodeFunctionExecutor.js +904 -0
  232. package/dist/lib/executors/CodeFunctionExecutor.js.map +1 -0
  233. package/dist/lib/executors/GenerativeFunctionExecutor.js +904 -0
  234. package/dist/lib/executors/GenerativeFunctionExecutor.js.map +1 -0
  235. package/dist/lib/executors/HumanFunctionExecutor.js +884 -0
  236. package/dist/lib/executors/HumanFunctionExecutor.js.map +1 -0
  237. package/dist/lib/executors/ParallelStepExecutor.js +308 -0
  238. package/dist/lib/executors/ParallelStepExecutor.js.map +1 -0
  239. package/dist/lib/executors/types.js +12 -0
  240. package/dist/lib/executors/types.js.map +1 -0
  241. package/dist/lib/experiments.js +89 -0
  242. package/dist/lib/experiments.js.map +1 -0
  243. package/dist/lib/flags/store.js +262 -0
  244. package/dist/lib/flags/store.js.map +1 -0
  245. package/dist/lib/functions/FunctionComposition.js +467 -0
  246. package/dist/lib/functions/FunctionComposition.js.map +1 -0
  247. package/dist/lib/functions/FunctionMiddleware.js +457 -0
  248. package/dist/lib/functions/FunctionMiddleware.js.map +1 -0
  249. package/dist/lib/functions/FunctionRegistry.js +426 -0
  250. package/dist/lib/functions/FunctionRegistry.js.map +1 -0
  251. package/dist/lib/functions/createFunction.js +1048 -0
  252. package/dist/lib/functions/createFunction.js.map +1 -0
  253. package/dist/lib/humans/index.js +68 -0
  254. package/dist/lib/humans/index.js.map +1 -0
  255. package/dist/lib/humans/templates.js +117 -0
  256. package/dist/lib/humans/templates.js.map +1 -0
  257. package/dist/lib/identity.js +98 -0
  258. package/dist/lib/identity.js.map +1 -0
  259. package/dist/lib/index.js +9 -0
  260. package/dist/lib/index.js.map +1 -0
  261. package/dist/lib/logging/error-logger.js +163 -0
  262. package/dist/lib/logging/error-logger.js.map +1 -0
  263. package/dist/lib/logging/index.js +160 -0
  264. package/dist/lib/logging/index.js.map +1 -0
  265. package/dist/lib/mixins/bash.js +825 -0
  266. package/dist/lib/mixins/bash.js.map +1 -0
  267. package/dist/lib/mixins/fs.js +648 -0
  268. package/dist/lib/mixins/fs.js.map +1 -0
  269. package/dist/lib/mixins/git.js +1011 -0
  270. package/dist/lib/mixins/git.js.map +1 -0
  271. package/dist/lib/mixins/index.js +29 -0
  272. package/dist/lib/mixins/index.js.map +1 -0
  273. package/dist/lib/mixins/npm.js +662 -0
  274. package/dist/lib/mixins/npm.js.map +1 -0
  275. package/dist/lib/noun-id.js +278 -0
  276. package/dist/lib/noun-id.js.map +1 -0
  277. package/dist/lib/rate-limit/sliding-window.js +148 -0
  278. package/dist/lib/rate-limit/sliding-window.js.map +1 -0
  279. package/dist/lib/rate-limit.js +110 -0
  280. package/dist/lib/rate-limit.js.map +1 -0
  281. package/dist/lib/rpc/bindings.js +548 -0
  282. package/dist/lib/rpc/bindings.js.map +1 -0
  283. package/dist/lib/rpc/index.js +64 -0
  284. package/dist/lib/rpc/index.js.map +1 -0
  285. package/dist/lib/safe-stringify.js +223 -0
  286. package/dist/lib/safe-stringify.js.map +1 -0
  287. package/dist/lib/sandbox/miniflare-sandbox.js +1007 -0
  288. package/dist/lib/sandbox/miniflare-sandbox.js.map +1 -0
  289. package/dist/lib/sqids.js +110 -0
  290. package/dist/lib/sqids.js.map +1 -0
  291. package/dist/lib/sql/adapters/index.js +10 -0
  292. package/dist/lib/sql/adapters/index.js.map +1 -0
  293. package/dist/lib/sql/adapters/node-sql-parser.js +552 -0
  294. package/dist/lib/sql/adapters/node-sql-parser.js.map +1 -0
  295. package/dist/lib/sql/adapters/pgsql-parser.js +1189 -0
  296. package/dist/lib/sql/adapters/pgsql-parser.js.map +1 -0
  297. package/dist/lib/sql/index.js +277 -0
  298. package/dist/lib/sql/index.js.map +1 -0
  299. package/dist/lib/sql/types.js +56 -0
  300. package/dist/lib/sql/types.js.map +1 -0
  301. package/dist/lib/type-classifier.js +126 -0
  302. package/dist/lib/type-classifier.js.map +1 -0
  303. package/dist/lib/utils/html.js +47 -0
  304. package/dist/lib/utils/html.js.map +1 -0
  305. package/dist/lib/validation.js +48 -0
  306. package/dist/lib/validation.js.map +1 -0
  307. package/dist/lib/vault/store.js +411 -0
  308. package/dist/lib/vault/store.js.map +1 -0
  309. package/dist/metrics/hunch.js +739 -0
  310. package/dist/metrics/hunch.js.map +1 -0
  311. package/dist/objects/API.js +302 -0
  312. package/dist/objects/API.js.map +1 -0
  313. package/dist/objects/Agent.js +179 -0
  314. package/dist/objects/Agent.js.map +1 -0
  315. package/dist/objects/AgenticFunctionExecutor.js +8 -0
  316. package/dist/objects/AgenticFunctionExecutor.js.map +1 -0
  317. package/dist/objects/App.js +83 -0
  318. package/dist/objects/App.js.map +1 -0
  319. package/dist/objects/Browser.js +884 -0
  320. package/dist/objects/Browser.js.map +1 -0
  321. package/dist/objects/Business.js +107 -0
  322. package/dist/objects/Business.js.map +1 -0
  323. package/dist/objects/CLI.js +221 -0
  324. package/dist/objects/CLI.js.map +1 -0
  325. package/dist/objects/CodeFunctionExecutor.js +8 -0
  326. package/dist/objects/CodeFunctionExecutor.js.map +1 -0
  327. package/dist/objects/Collection.js +161 -0
  328. package/dist/objects/Collection.js.map +1 -0
  329. package/dist/objects/DO.js +41 -0
  330. package/dist/objects/DO.js.map +1 -0
  331. package/dist/objects/DOBase.js +2309 -0
  332. package/dist/objects/DOBase.js.map +1 -0
  333. package/dist/objects/DOFull.js +1676 -0
  334. package/dist/objects/DOFull.js.map +1 -0
  335. package/dist/objects/DOTiny.js +207 -0
  336. package/dist/objects/DOTiny.js.map +1 -0
  337. package/dist/objects/Directory.js +199 -0
  338. package/dist/objects/Directory.js.map +1 -0
  339. package/dist/objects/Entity.js +413 -0
  340. package/dist/objects/Entity.js.map +1 -0
  341. package/dist/objects/Function.js +116 -0
  342. package/dist/objects/Function.js.map +1 -0
  343. package/dist/objects/Human.js +231 -0
  344. package/dist/objects/Human.js.map +1 -0
  345. package/dist/objects/HumanFunctionExecutor.js +8 -0
  346. package/dist/objects/HumanFunctionExecutor.js.map +1 -0
  347. package/dist/objects/IcebergMetadataDO.js +938 -0
  348. package/dist/objects/IcebergMetadataDO.js.map +1 -0
  349. package/dist/objects/IntegrationsDO.js +1174 -0
  350. package/dist/objects/IntegrationsDO.js.map +1 -0
  351. package/dist/objects/ObservabilityBroadcaster.js +149 -0
  352. package/dist/objects/ObservabilityBroadcaster.js.map +1 -0
  353. package/dist/objects/Package.js +154 -0
  354. package/dist/objects/Package.js.map +1 -0
  355. package/dist/objects/Product.js +193 -0
  356. package/dist/objects/Product.js.map +1 -0
  357. package/dist/objects/SDK.js +152 -0
  358. package/dist/objects/SDK.js.map +1 -0
  359. package/dist/objects/SaaS.js +235 -0
  360. package/dist/objects/SaaS.js.map +1 -0
  361. package/dist/objects/SandboxDO.js +759 -0
  362. package/dist/objects/SandboxDO.js.map +1 -0
  363. package/dist/objects/Service.js +337 -0
  364. package/dist/objects/Service.js.map +1 -0
  365. package/dist/objects/Site.js +80 -0
  366. package/dist/objects/Site.js.map +1 -0
  367. package/dist/objects/Startup.js +479 -0
  368. package/dist/objects/Startup.js.map +1 -0
  369. package/dist/objects/ThingsDO.js +170 -0
  370. package/dist/objects/ThingsDO.js.map +1 -0
  371. package/dist/objects/VectorShardDO.js +648 -0
  372. package/dist/objects/VectorShardDO.js.map +1 -0
  373. package/dist/objects/Worker.js +144 -0
  374. package/dist/objects/Worker.js.map +1 -0
  375. package/dist/objects/Workflow.js +196 -0
  376. package/dist/objects/Workflow.js.map +1 -0
  377. package/dist/objects/WorkflowFactory.js +313 -0
  378. package/dist/objects/WorkflowFactory.js.map +1 -0
  379. package/dist/objects/WorkflowRuntime.js +863 -0
  380. package/dist/objects/WorkflowRuntime.js.map +1 -0
  381. package/dist/objects/circuit-breaker-bulkhead.js +178 -0
  382. package/dist/objects/circuit-breaker-bulkhead.js.map +1 -0
  383. package/dist/objects/createFunction.js +934 -0
  384. package/dist/objects/createFunction.js.map +1 -0
  385. package/dist/objects/index.js +80 -0
  386. package/dist/objects/index.js.map +1 -0
  387. package/dist/objects/lifecycle/Branch.js +275 -0
  388. package/dist/objects/lifecycle/Branch.js.map +1 -0
  389. package/dist/objects/lifecycle/Clone.js +1499 -0
  390. package/dist/objects/lifecycle/Clone.js.map +1 -0
  391. package/dist/objects/lifecycle/Compact.js +237 -0
  392. package/dist/objects/lifecycle/Compact.js.map +1 -0
  393. package/dist/objects/lifecycle/Promote.js +476 -0
  394. package/dist/objects/lifecycle/Promote.js.map +1 -0
  395. package/dist/objects/lifecycle/Shard.js +560 -0
  396. package/dist/objects/lifecycle/Shard.js.map +1 -0
  397. package/dist/objects/lifecycle/index.js +15 -0
  398. package/dist/objects/lifecycle/index.js.map +1 -0
  399. package/dist/objects/lifecycle/types.js +33 -0
  400. package/dist/objects/lifecycle/types.js.map +1 -0
  401. package/dist/objects/mixins/infrastructure.js +171 -0
  402. package/dist/objects/mixins/infrastructure.js.map +1 -0
  403. package/dist/objects/modules/StoresModule.js +153 -0
  404. package/dist/objects/modules/StoresModule.js.map +1 -0
  405. package/dist/objects/persistence/checkpoint-manager.js +606 -0
  406. package/dist/objects/persistence/checkpoint-manager.js.map +1 -0
  407. package/dist/objects/persistence/index.js +72 -0
  408. package/dist/objects/persistence/index.js.map +1 -0
  409. package/dist/objects/persistence/migration-runner.js +562 -0
  410. package/dist/objects/persistence/migration-runner.js.map +1 -0
  411. package/dist/objects/persistence/replication-manager.js +501 -0
  412. package/dist/objects/persistence/replication-manager.js.map +1 -0
  413. package/dist/objects/persistence/tiered-storage-manager.js +595 -0
  414. package/dist/objects/persistence/tiered-storage-manager.js.map +1 -0
  415. package/dist/objects/persistence/types.js +14 -0
  416. package/dist/objects/persistence/types.js.map +1 -0
  417. package/dist/objects/persistence/wal-manager.js +653 -0
  418. package/dist/objects/persistence/wal-manager.js.map +1 -0
  419. package/dist/objects/presets/index.js +20 -0
  420. package/dist/objects/presets/index.js.map +1 -0
  421. package/dist/objects/presets/primitives.js +188 -0
  422. package/dist/objects/presets/primitives.js.map +1 -0
  423. package/dist/objects/primitives/alarm-adapter.js +141 -0
  424. package/dist/objects/primitives/alarm-adapter.js.map +1 -0
  425. package/dist/objects/primitives/index.js +337 -0
  426. package/dist/objects/primitives/index.js.map +1 -0
  427. package/dist/objects/primitives/storage-adapter.js +182 -0
  428. package/dist/objects/primitives/storage-adapter.js.map +1 -0
  429. package/dist/objects/primitives/with-primitives.js +102 -0
  430. package/dist/objects/primitives/with-primitives.js.map +1 -0
  431. package/dist/objects/services/StoreManager.js +227 -0
  432. package/dist/objects/services/StoreManager.js.map +1 -0
  433. package/dist/objects/services/index.js +13 -0
  434. package/dist/objects/services/index.js.map +1 -0
  435. package/dist/objects/transport/auth-layer.js +1451 -0
  436. package/dist/objects/transport/auth-layer.js.map +1 -0
  437. package/dist/objects/transport/capnweb-target.js +355 -0
  438. package/dist/objects/transport/capnweb-target.js.map +1 -0
  439. package/dist/objects/transport/chain.js +441 -0
  440. package/dist/objects/transport/chain.js.map +1 -0
  441. package/dist/objects/transport/handler.js +58 -0
  442. package/dist/objects/transport/handler.js.map +1 -0
  443. package/dist/objects/transport/index.js +53 -0
  444. package/dist/objects/transport/index.js.map +1 -0
  445. package/dist/objects/transport/mcp-server.js +690 -0
  446. package/dist/objects/transport/mcp-server.js.map +1 -0
  447. package/dist/objects/transport/rest-autowire.js +1507 -0
  448. package/dist/objects/transport/rest-autowire.js.map +1 -0
  449. package/dist/objects/transport/rest-router.js +440 -0
  450. package/dist/objects/transport/rest-router.js.map +1 -0
  451. package/dist/objects/transport/rpc-server.js +1536 -0
  452. package/dist/objects/transport/rpc-server.js.map +1 -0
  453. package/dist/objects/transport/shared.js +575 -0
  454. package/dist/objects/transport/shared.js.map +1 -0
  455. package/dist/objects/transport/sync-engine.js +291 -0
  456. package/dist/objects/transport/sync-engine.js.map +1 -0
  457. package/dist/objects/transport/types.js +8 -0
  458. package/dist/objects/transport/types.js.map +1 -0
  459. package/dist/primitives/bashx/src/ast/analyze.js +1472 -0
  460. package/dist/primitives/bashx/src/ast/analyze.js.map +1 -0
  461. package/dist/primitives/bashx/src/ast/parser.js +1488 -0
  462. package/dist/primitives/bashx/src/ast/parser.js.map +1 -0
  463. package/dist/primitives/bashx/src/do/commands/crypto.js +1954 -0
  464. package/dist/primitives/bashx/src/do/commands/crypto.js.map +1 -0
  465. package/dist/primitives/bashx/src/do/commands/data-processing.js +1812 -0
  466. package/dist/primitives/bashx/src/do/commands/data-processing.js.map +1 -0
  467. package/dist/primitives/bashx/src/do/commands/extended-utils.js +804 -0
  468. package/dist/primitives/bashx/src/do/commands/extended-utils.js.map +1 -0
  469. package/dist/primitives/bashx/src/do/commands/math-control.js +1122 -0
  470. package/dist/primitives/bashx/src/do/commands/math-control.js.map +1 -0
  471. package/dist/primitives/bashx/src/do/commands/posix-utils.js +1015 -0
  472. package/dist/primitives/bashx/src/do/commands/posix-utils.js.map +1 -0
  473. package/dist/primitives/bashx/src/do/commands/system-utils.js +687 -0
  474. package/dist/primitives/bashx/src/do/commands/system-utils.js.map +1 -0
  475. package/dist/primitives/bashx/src/do/commands/test-command.js +523 -0
  476. package/dist/primitives/bashx/src/do/commands/test-command.js.map +1 -0
  477. package/dist/primitives/bashx/src/do/commands/text-processing.js +1550 -0
  478. package/dist/primitives/bashx/src/do/commands/text-processing.js.map +1 -0
  479. package/dist/primitives/bashx/src/do/container-executor.js +429 -0
  480. package/dist/primitives/bashx/src/do/container-executor.js.map +1 -0
  481. package/dist/primitives/bashx/src/do/index.js +668 -0
  482. package/dist/primitives/bashx/src/do/index.js.map +1 -0
  483. package/dist/primitives/bashx/src/do/tiered-executor.js +2647 -0
  484. package/dist/primitives/bashx/src/do/tiered-executor.js.map +1 -0
  485. package/dist/primitives/bashx/src/do/worker.js +352 -0
  486. package/dist/primitives/bashx/src/do/worker.js.map +1 -0
  487. package/dist/primitives/bashx/src/types.js +10 -0
  488. package/dist/primitives/bashx/src/types.js.map +1 -0
  489. package/dist/primitives/fsx/core/backend.js +480 -0
  490. package/dist/primitives/fsx/core/backend.js.map +1 -0
  491. package/dist/primitives/fsx/core/constants.js +140 -0
  492. package/dist/primitives/fsx/core/constants.js.map +1 -0
  493. package/dist/primitives/fsx/core/fsx.js +1184 -0
  494. package/dist/primitives/fsx/core/fsx.js.map +1 -0
  495. package/dist/primitives/fsx/core/glob/glob.js +438 -0
  496. package/dist/primitives/fsx/core/glob/glob.js.map +1 -0
  497. package/dist/primitives/fsx/core/glob/index.js +8 -0
  498. package/dist/primitives/fsx/core/glob/index.js.map +1 -0
  499. package/dist/primitives/fsx/core/glob/match.js +392 -0
  500. package/dist/primitives/fsx/core/glob/match.js.map +1 -0
  501. package/dist/primitives/fsx/core/types.js +307 -0
  502. package/dist/primitives/fsx/core/types.js.map +1 -0
  503. package/dist/sandbox/index.js +258 -0
  504. package/dist/sandbox/index.js.map +1 -0
  505. package/dist/sdk/capnweb-compat.js +42 -0
  506. package/dist/sdk/capnweb-compat.js.map +1 -0
  507. package/dist/sdk/client.js +20 -0
  508. package/dist/sdk/client.js.map +1 -0
  509. package/dist/sdk/index.js +17 -0
  510. package/dist/sdk/index.js.map +1 -0
  511. package/dist/snippets/artifacts-config.js +241 -0
  512. package/dist/snippets/artifacts-config.js.map +1 -0
  513. package/dist/snippets/artifacts-ingest.js +832 -0
  514. package/dist/snippets/artifacts-ingest.js.map +1 -0
  515. package/dist/snippets/artifacts-serve.js +1035 -0
  516. package/dist/snippets/artifacts-serve.js.map +1 -0
  517. package/dist/snippets/artifacts-types.js +161 -0
  518. package/dist/snippets/artifacts-types.js.map +1 -0
  519. package/dist/snippets/cache-probe.js +376 -0
  520. package/dist/snippets/cache-probe.js.map +1 -0
  521. package/dist/snippets/cache.js +10 -0
  522. package/dist/snippets/cache.js.map +1 -0
  523. package/dist/snippets/events.js +469 -0
  524. package/dist/snippets/events.js.map +1 -0
  525. package/dist/snippets/index.js +7 -0
  526. package/dist/snippets/index.js.map +1 -0
  527. package/dist/snippets/proxy.js +495 -0
  528. package/dist/snippets/proxy.js.map +1 -0
  529. package/dist/snippets/search.js +1759 -0
  530. package/dist/snippets/search.js.map +1 -0
  531. package/dist/streams/index.js +30 -0
  532. package/dist/streams/index.js.map +1 -0
  533. package/dist/streams/observability.js +68 -0
  534. package/dist/streams/observability.js.map +1 -0
  535. package/dist/types/AI.js +92 -0
  536. package/dist/types/AI.js.map +1 -0
  537. package/dist/types/AIFunction.js +171 -0
  538. package/dist/types/AIFunction.js.map +1 -0
  539. package/dist/types/BrowseVerb.js +89 -0
  540. package/dist/types/BrowseVerb.js.map +1 -0
  541. package/dist/types/Browser.js +31 -0
  542. package/dist/types/Browser.js.map +1 -0
  543. package/dist/types/Chaos.js +15 -0
  544. package/dist/types/Chaos.js.map +1 -0
  545. package/dist/types/CloudflareBindings.js +109 -0
  546. package/dist/types/CloudflareBindings.js.map +1 -0
  547. package/dist/types/Collection.js +50 -0
  548. package/dist/types/Collection.js.map +1 -0
  549. package/dist/types/DO.js +2 -0
  550. package/dist/types/DO.js.map +1 -0
  551. package/dist/types/DOLocation.js +63 -0
  552. package/dist/types/DOLocation.js.map +1 -0
  553. package/dist/types/EventHandler.js +57 -0
  554. package/dist/types/EventHandler.js.map +1 -0
  555. package/dist/types/Experiment.js +33 -0
  556. package/dist/types/Experiment.js.map +1 -0
  557. package/dist/types/Flag.js +57 -0
  558. package/dist/types/Flag.js.map +1 -0
  559. package/dist/types/Lifecycle.js +13 -0
  560. package/dist/types/Lifecycle.js.map +1 -0
  561. package/dist/types/Location.js +169 -0
  562. package/dist/types/Location.js.map +1 -0
  563. package/dist/types/Noun.js +66 -0
  564. package/dist/types/Noun.js.map +1 -0
  565. package/dist/types/SessionEvent.js +194 -0
  566. package/dist/types/SessionEvent.js.map +1 -0
  567. package/dist/types/Thing.js +55 -0
  568. package/dist/types/Thing.js.map +1 -0
  569. package/dist/types/ThingDO.js +153 -0
  570. package/dist/types/ThingDO.js.map +1 -0
  571. package/dist/types/Things.js +2 -0
  572. package/dist/types/Things.js.map +1 -0
  573. package/dist/types/Verb.js +119 -0
  574. package/dist/types/Verb.js.map +1 -0
  575. package/dist/types/WorkflowContext.js +70 -0
  576. package/dist/types/WorkflowContext.js.map +1 -0
  577. package/dist/types/analytics-api.js +13 -0
  578. package/dist/types/analytics-api.js.map +1 -0
  579. package/dist/types/capabilities.js +135 -0
  580. package/dist/types/capabilities.js.map +1 -0
  581. package/dist/types/drizzle.js +12 -0
  582. package/dist/types/drizzle.js.map +1 -0
  583. package/dist/types/event.js +201 -0
  584. package/dist/types/event.js.map +1 -0
  585. package/dist/types/fn.js +12 -0
  586. package/dist/types/fn.js.map +1 -0
  587. package/dist/types/iceberg.js +48 -0
  588. package/dist/types/iceberg.js.map +1 -0
  589. package/dist/types/ids.js +170 -0
  590. package/dist/types/ids.js.map +1 -0
  591. package/dist/types/index.js +41 -0
  592. package/dist/types/index.js.map +1 -0
  593. package/dist/types/introspect.js +54 -0
  594. package/dist/types/introspect.js.map +1 -0
  595. package/dist/types/observability.js +124 -0
  596. package/dist/types/observability.js.map +1 -0
  597. package/dist/types/sync-protocol.js +175 -0
  598. package/dist/types/sync-protocol.js.map +1 -0
  599. package/dist/types/vector.js +13 -0
  600. package/dist/types/vector.js.map +1 -0
  601. package/dist/workflows/ScheduleManager.js +473 -0
  602. package/dist/workflows/ScheduleManager.js.map +1 -0
  603. package/dist/workflows/StepDOBridge.js +149 -0
  604. package/dist/workflows/StepDOBridge.js.map +1 -0
  605. package/dist/workflows/StepResultStorage.js +232 -0
  606. package/dist/workflows/StepResultStorage.js.map +1 -0
  607. package/dist/workflows/WaitForEventManager.js +461 -0
  608. package/dist/workflows/WaitForEventManager.js.map +1 -0
  609. package/dist/workflows/analyzer.js +332 -0
  610. package/dist/workflows/analyzer.js.map +1 -0
  611. package/dist/workflows/compat/activity-router.js +484 -0
  612. package/dist/workflows/compat/activity-router.js.map +1 -0
  613. package/dist/workflows/compat/backends/cloudflare-workflows.js +431 -0
  614. package/dist/workflows/compat/backends/cloudflare-workflows.js.map +1 -0
  615. package/dist/workflows/compat/backends/index.js +14 -0
  616. package/dist/workflows/compat/backends/index.js.map +1 -0
  617. package/dist/workflows/compat/errors/index.js +375 -0
  618. package/dist/workflows/compat/errors/index.js.map +1 -0
  619. package/dist/workflows/compat/index.js +79 -0
  620. package/dist/workflows/compat/index.js.map +1 -0
  621. package/dist/workflows/compat/inngest/index.js +989 -0
  622. package/dist/workflows/compat/inngest/index.js.map +1 -0
  623. package/dist/workflows/compat/qstash/index.js +1263 -0
  624. package/dist/workflows/compat/qstash/index.js.map +1 -0
  625. package/dist/workflows/compat/temporal/activities.js +739 -0
  626. package/dist/workflows/compat/temporal/activities.js.map +1 -0
  627. package/dist/workflows/compat/temporal/child-workflows.js +154 -0
  628. package/dist/workflows/compat/temporal/child-workflows.js.map +1 -0
  629. package/dist/workflows/compat/temporal/client.js +381 -0
  630. package/dist/workflows/compat/temporal/client.js.map +1 -0
  631. package/dist/workflows/compat/temporal/context.js +309 -0
  632. package/dist/workflows/compat/temporal/context.js.map +1 -0
  633. package/dist/workflows/compat/temporal/determinism.js +216 -0
  634. package/dist/workflows/compat/temporal/determinism.js.map +1 -0
  635. package/dist/workflows/compat/temporal/errors.js +128 -0
  636. package/dist/workflows/compat/temporal/errors.js.map +1 -0
  637. package/dist/workflows/compat/temporal/index.js +2464 -0
  638. package/dist/workflows/compat/temporal/index.js.map +1 -0
  639. package/dist/workflows/compat/temporal/saga.js +504 -0
  640. package/dist/workflows/compat/temporal/saga.js.map +1 -0
  641. package/dist/workflows/compat/temporal/signals.js +364 -0
  642. package/dist/workflows/compat/temporal/signals.js.map +1 -0
  643. package/dist/workflows/compat/temporal/storage.js +271 -0
  644. package/dist/workflows/compat/temporal/storage.js.map +1 -0
  645. package/dist/workflows/compat/temporal/timers.js +347 -0
  646. package/dist/workflows/compat/temporal/timers.js.map +1 -0
  647. package/dist/workflows/compat/temporal/types.js +7 -0
  648. package/dist/workflows/compat/temporal/types.js.map +1 -0
  649. package/dist/workflows/compat/temporal/unified-primitives.js +339 -0
  650. package/dist/workflows/compat/temporal/unified-primitives.js.map +1 -0
  651. package/dist/workflows/compat/trigger/index.js +468 -0
  652. package/dist/workflows/compat/trigger/index.js.map +1 -0
  653. package/dist/workflows/compat/utils/index.js +69 -0
  654. package/dist/workflows/compat/utils/index.js.map +1 -0
  655. package/dist/workflows/context/correlation-capability.js +266 -0
  656. package/dist/workflows/context/correlation-capability.js.map +1 -0
  657. package/dist/workflows/context/correlation.js +484 -0
  658. package/dist/workflows/context/correlation.js.map +1 -0
  659. package/dist/workflows/context/experiment.js +289 -0
  660. package/dist/workflows/context/experiment.js.map +1 -0
  661. package/dist/workflows/context/flag.js +244 -0
  662. package/dist/workflows/context/flag.js.map +1 -0
  663. package/dist/workflows/context/foundation.js +648 -0
  664. package/dist/workflows/context/foundation.js.map +1 -0
  665. package/dist/workflows/context/human-base.js +106 -0
  666. package/dist/workflows/context/human-base.js.map +1 -0
  667. package/dist/workflows/context/human.js +368 -0
  668. package/dist/workflows/context/human.js.map +1 -0
  669. package/dist/workflows/context/measure.js +354 -0
  670. package/dist/workflows/context/measure.js.map +1 -0
  671. package/dist/workflows/context/rate-limit.js +358 -0
  672. package/dist/workflows/context/rate-limit.js.map +1 -0
  673. package/dist/workflows/context/user.js +117 -0
  674. package/dist/workflows/context/user.js.map +1 -0
  675. package/dist/workflows/context/vault.js +360 -0
  676. package/dist/workflows/context/vault.js.map +1 -0
  677. package/dist/workflows/data/entity-events/entity-events.js +489 -0
  678. package/dist/workflows/data/entity-events/entity-events.js.map +1 -0
  679. package/dist/workflows/data/experiment/index.js +599 -0
  680. package/dist/workflows/data/experiment/index.js.map +1 -0
  681. package/dist/workflows/data/goal/context.js +558 -0
  682. package/dist/workflows/data/goal/context.js.map +1 -0
  683. package/dist/workflows/data/goal/index.js +32 -0
  684. package/dist/workflows/data/goal/index.js.map +1 -0
  685. package/dist/workflows/data/measure/index.js +840 -0
  686. package/dist/workflows/data/measure/index.js.map +1 -0
  687. package/dist/workflows/data/stream/index.js +1215 -0
  688. package/dist/workflows/data/stream/index.js.map +1 -0
  689. package/dist/workflows/data/track/context.js +883 -0
  690. package/dist/workflows/data/track/context.js.map +1 -0
  691. package/dist/workflows/data/track/index.js +15 -0
  692. package/dist/workflows/data/track/index.js.map +1 -0
  693. package/dist/workflows/data/view/context.js +864 -0
  694. package/dist/workflows/data/view/context.js.map +1 -0
  695. package/dist/workflows/domain.js +93 -0
  696. package/dist/workflows/domain.js.map +1 -0
  697. package/dist/workflows/flag.js +176 -0
  698. package/dist/workflows/flag.js.map +1 -0
  699. package/dist/workflows/flags.js +217 -0
  700. package/dist/workflows/flags.js.map +1 -0
  701. package/dist/workflows/hash.js +209 -0
  702. package/dist/workflows/hash.js.map +1 -0
  703. package/dist/workflows/index.js +50 -0
  704. package/dist/workflows/index.js.map +1 -0
  705. package/dist/workflows/on.js +378 -0
  706. package/dist/workflows/on.js.map +1 -0
  707. package/dist/workflows/pipeline-promise.js +481 -0
  708. package/dist/workflows/pipeline-promise.js.map +1 -0
  709. package/dist/workflows/pipeline-types.js +20 -0
  710. package/dist/workflows/pipeline-types.js.map +1 -0
  711. package/dist/workflows/proxy.js +76 -0
  712. package/dist/workflows/proxy.js.map +1 -0
  713. package/dist/workflows/runtime.js +310 -0
  714. package/dist/workflows/runtime.js.map +1 -0
  715. package/dist/workflows/schedule-builder.js +327 -0
  716. package/dist/workflows/schedule-builder.js.map +1 -0
  717. package/dist/workflows/visibility/index.js +148 -0
  718. package/dist/workflows/visibility/index.js.map +1 -0
  719. package/dist/workflows/visibility/query-parser.js +150 -0
  720. package/dist/workflows/visibility/query-parser.js.map +1 -0
  721. package/dist/workflows/visibility/store.js +223 -0
  722. package/dist/workflows/visibility/store.js.map +1 -0
  723. package/dist/workflows/visibility/types.js +30 -0
  724. package/dist/workflows/visibility/types.js.map +1 -0
  725. package/dist/workflows/workflow.js +53 -0
  726. package/dist/workflows/workflow.js.map +1 -0
  727. package/package.json +279 -46
@@ -0,0 +1,1015 @@
1
+ /**
2
+ * POSIX Utilities Commands
3
+ *
4
+ * Native implementations for POSIX utility commands:
5
+ * - cut: Remove sections from lines
6
+ * - sort: Sort lines
7
+ * - tr: Translate characters
8
+ * - uniq: Report/filter repeated lines
9
+ * - wc: Word, line, byte counts
10
+ * - basename/dirname: Path operations
11
+ * - echo: Print arguments
12
+ * - printf: Formatted output
13
+ * - date: Display/format date
14
+ * - dd: Convert and copy
15
+ * - od: Octal dump
16
+ *
17
+ * @module bashx/do/commands/posix-utils
18
+ */
19
+ /**
20
+ * Parse a range specification like "1-3", "2,4,6", "-5", "3-"
21
+ *
22
+ * @param spec - Range specification string
23
+ * @param maxValue - Maximum value for open-ended ranges
24
+ * @returns Set of 1-based positions to include
25
+ */
26
+ function parseRangeSpec(spec, maxValue) {
27
+ const positions = new Set();
28
+ const parts = spec.split(',');
29
+ for (const part of parts) {
30
+ const trimmed = part.trim();
31
+ if (!trimmed)
32
+ continue;
33
+ if (trimmed.includes('-')) {
34
+ const [startStr, endStr] = trimmed.split('-');
35
+ const start = startStr ? parseInt(startStr, 10) : 1;
36
+ const end = endStr ? parseInt(endStr, 10) : maxValue;
37
+ for (let i = start; i <= end && i <= maxValue; i++) {
38
+ if (i >= 1)
39
+ positions.add(i);
40
+ }
41
+ }
42
+ else {
43
+ const pos = parseInt(trimmed, 10);
44
+ if (pos >= 1 && pos <= maxValue) {
45
+ positions.add(pos);
46
+ }
47
+ }
48
+ }
49
+ return positions;
50
+ }
51
+ /**
52
+ * Execute cut command - remove sections from each line of input
53
+ *
54
+ * @param input - Input text to process
55
+ * @param options - Cut options (bytes, chars, fields, delimiter)
56
+ * @returns Processed output string
57
+ *
58
+ * @example
59
+ * ```typescript
60
+ * // Cut first field with comma delimiter
61
+ * executeCut('a,b,c\n1,2,3', { fields: '1', delimiter: ',' })
62
+ * // => 'a\n1\n'
63
+ *
64
+ * // Cut bytes 1-3
65
+ * executeCut('hello\nworld', { bytes: '1-3' })
66
+ * // => 'hel\nwor\n'
67
+ * ```
68
+ */
69
+ export function executeCut(input, options) {
70
+ const lines = input.split('\n');
71
+ const results = [];
72
+ const delimiter = options.delimiter || '\t';
73
+ const outputDelim = options.outputDelimiter || delimiter;
74
+ for (const line of lines) {
75
+ // Skip empty lines at the end
76
+ if (line === '' && lines.indexOf(line) === lines.length - 1 && input.endsWith('\n')) {
77
+ continue;
78
+ }
79
+ if (options.bytes) {
80
+ // Cut by byte positions
81
+ const positions = parseRangeSpec(options.bytes, line.length);
82
+ let result = '';
83
+ for (let i = 1; i <= line.length; i++) {
84
+ const include = positions.has(i);
85
+ if (options.complement ? !include : include) {
86
+ result += line[i - 1];
87
+ }
88
+ }
89
+ results.push(result);
90
+ }
91
+ else if (options.chars) {
92
+ // Cut by character positions (same as bytes for ASCII)
93
+ const chars = [...line];
94
+ const positions = parseRangeSpec(options.chars, chars.length);
95
+ let result = '';
96
+ for (let i = 1; i <= chars.length; i++) {
97
+ const include = positions.has(i);
98
+ if (options.complement ? !include : include) {
99
+ result += chars[i - 1];
100
+ }
101
+ }
102
+ results.push(result);
103
+ }
104
+ else if (options.fields) {
105
+ // Cut by field positions
106
+ if (!line.includes(delimiter)) {
107
+ // Line doesn't contain delimiter
108
+ if (options.onlyDelimited) {
109
+ continue; // Skip this line
110
+ }
111
+ results.push(line);
112
+ continue;
113
+ }
114
+ const fields = line.split(delimiter);
115
+ const positions = parseRangeSpec(options.fields, fields.length);
116
+ const selectedFields = [];
117
+ for (let i = 1; i <= fields.length; i++) {
118
+ const include = positions.has(i);
119
+ if (options.complement ? !include : include) {
120
+ selectedFields.push(fields[i - 1]);
121
+ }
122
+ }
123
+ results.push(selectedFields.join(outputDelim));
124
+ }
125
+ else {
126
+ // No option specified - output line as-is
127
+ results.push(line);
128
+ }
129
+ }
130
+ return results.join('\n') + (results.length > 0 ? '\n' : '');
131
+ }
132
+ /**
133
+ * Parse human-readable size suffixes (K, M, G, T)
134
+ */
135
+ function parseHumanSize(str) {
136
+ const match = str.match(/^(\d+(?:\.\d+)?)\s*([KMGT])?/i);
137
+ if (!match)
138
+ return parseFloat(str) || 0;
139
+ const value = parseFloat(match[1]);
140
+ const suffix = (match[2] || '').toUpperCase();
141
+ const multipliers = {
142
+ K: 1024,
143
+ M: 1024 * 1024,
144
+ G: 1024 * 1024 * 1024,
145
+ T: 1024 * 1024 * 1024 * 1024,
146
+ };
147
+ return value * (multipliers[suffix] || 1);
148
+ }
149
+ /**
150
+ * Compare version strings (GNU sort -V behavior)
151
+ * Handles versions like "1.2", "1.10", "2.0-alpha", "v1.0.0"
152
+ *
153
+ * @param a - First version string
154
+ * @param b - Second version string
155
+ * @returns Negative if a < b, positive if a > b, 0 if equal
156
+ */
157
+ function compareVersions(a, b) {
158
+ // Split into segments of digits and non-digits
159
+ const splitVersion = (s) => {
160
+ const parts = [];
161
+ let current = '';
162
+ let isDigit = false;
163
+ for (const char of s) {
164
+ const charIsDigit = /\d/.test(char);
165
+ if (current === '') {
166
+ current = char;
167
+ isDigit = charIsDigit;
168
+ }
169
+ else if (charIsDigit === isDigit) {
170
+ current += char;
171
+ }
172
+ else {
173
+ parts.push(isDigit ? parseInt(current, 10) : current);
174
+ current = char;
175
+ isDigit = charIsDigit;
176
+ }
177
+ }
178
+ if (current) {
179
+ parts.push(isDigit ? parseInt(current, 10) : current);
180
+ }
181
+ return parts;
182
+ };
183
+ const partsA = splitVersion(a);
184
+ const partsB = splitVersion(b);
185
+ const maxLen = Math.max(partsA.length, partsB.length);
186
+ for (let i = 0; i < maxLen; i++) {
187
+ const partA = partsA[i];
188
+ const partB = partsB[i];
189
+ // Missing parts are treated as less than existing parts
190
+ if (partA === undefined)
191
+ return -1;
192
+ if (partB === undefined)
193
+ return 1;
194
+ // Compare numbers numerically, strings lexicographically
195
+ if (typeof partA === 'number' && typeof partB === 'number') {
196
+ if (partA !== partB)
197
+ return partA - partB;
198
+ }
199
+ else if (typeof partA === 'string' && typeof partB === 'string') {
200
+ const cmp = partA.localeCompare(partB);
201
+ if (cmp !== 0)
202
+ return cmp;
203
+ }
204
+ else {
205
+ // Mixed: numbers sort before strings
206
+ if (typeof partA === 'number')
207
+ return -1;
208
+ return 1;
209
+ }
210
+ }
211
+ return 0;
212
+ }
213
+ /**
214
+ * Execute sort command - sort lines of text
215
+ *
216
+ * @param lines - Array of lines to sort
217
+ * @param options - Sort options
218
+ * @returns Sorted array of lines
219
+ *
220
+ * @example
221
+ * ```typescript
222
+ * executeSort(['c', 'a', 'b'], {})
223
+ * // => ['a', 'b', 'c']
224
+ *
225
+ * executeSort(['10', '2', '1'], { numeric: true })
226
+ * // => ['1', '2', '10']
227
+ * ```
228
+ */
229
+ export function executeSort(lines, options = {}) {
230
+ let result = [...lines];
231
+ const separator = options.separator || /\s+/;
232
+ // Extract key for comparison
233
+ const getKey = (line) => {
234
+ if (!options.key)
235
+ return line;
236
+ const keyMatch = options.key.match(/^(\d+)(?:,(\d+))?/);
237
+ if (!keyMatch)
238
+ return line;
239
+ const startField = parseInt(keyMatch[1], 10) - 1;
240
+ const endField = keyMatch[2] ? parseInt(keyMatch[2], 10) - 1 : startField;
241
+ const fields = line.split(separator);
242
+ return fields.slice(startField, endField + 1).join(' ');
243
+ };
244
+ // Comparison function
245
+ const compare = (a, b) => {
246
+ let keyA = getKey(a);
247
+ let keyB = getKey(b);
248
+ if (options.ignoreLeadingBlanks) {
249
+ keyA = keyA.trimStart();
250
+ keyB = keyB.trimStart();
251
+ }
252
+ if (options.ignoreCase) {
253
+ keyA = keyA.toLowerCase();
254
+ keyB = keyB.toLowerCase();
255
+ }
256
+ let comparison;
257
+ if (options.versionSort) {
258
+ // GNU extension: version number sort (-V)
259
+ comparison = compareVersions(keyA, keyB);
260
+ }
261
+ else if (options.humanNumeric) {
262
+ comparison = parseHumanSize(keyA) - parseHumanSize(keyB);
263
+ }
264
+ else if (options.numeric) {
265
+ const numA = parseFloat(keyA) || 0;
266
+ const numB = parseFloat(keyB) || 0;
267
+ comparison = numA - numB;
268
+ }
269
+ else {
270
+ comparison = keyA.localeCompare(keyB);
271
+ }
272
+ return options.reverse ? -comparison : comparison;
273
+ };
274
+ // Check mode
275
+ if (options.check) {
276
+ for (let i = 1; i < result.length; i++) {
277
+ if (compare(result[i - 1], result[i]) > 0) {
278
+ throw new Error(`sort: disorder: ${result[i]}`);
279
+ }
280
+ }
281
+ return result;
282
+ }
283
+ // Sort
284
+ result.sort(compare);
285
+ // Remove duplicates if unique
286
+ if (options.unique) {
287
+ result = result.filter((line, i) => i === 0 || compare(result[i - 1], line) !== 0);
288
+ }
289
+ return result;
290
+ }
291
+ /**
292
+ * Expand character class and range specifications
293
+ * Handles [:alpha:], [:digit:], [:upper:], [:lower:], a-z ranges
294
+ */
295
+ function expandCharSet(spec) {
296
+ let result = '';
297
+ let i = 0;
298
+ while (i < spec.length) {
299
+ // Check for POSIX character classes
300
+ if (spec.slice(i).startsWith('[:alpha:]')) {
301
+ result += 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
302
+ i += 9;
303
+ }
304
+ else if (spec.slice(i).startsWith('[:digit:]')) {
305
+ result += '0123456789';
306
+ i += 9;
307
+ }
308
+ else if (spec.slice(i).startsWith('[:upper:]')) {
309
+ result += 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
310
+ i += 9;
311
+ }
312
+ else if (spec.slice(i).startsWith('[:lower:]')) {
313
+ result += 'abcdefghijklmnopqrstuvwxyz';
314
+ i += 9;
315
+ }
316
+ else if (spec.slice(i).startsWith('[:alnum:]')) {
317
+ result += 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
318
+ i += 9;
319
+ }
320
+ else if (spec.slice(i).startsWith('[:space:]')) {
321
+ result += ' \t\n\r\f\v';
322
+ i += 9;
323
+ }
324
+ else if (spec.slice(i).startsWith('[:blank:]')) {
325
+ result += ' \t';
326
+ i += 9;
327
+ }
328
+ else if (spec.slice(i).startsWith('[:punct:]')) {
329
+ result += '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~';
330
+ i += 9;
331
+ }
332
+ else if (spec.slice(i).startsWith('[:xdigit:]')) {
333
+ result += '0123456789abcdefABCDEF';
334
+ i += 10;
335
+ }
336
+ else if (spec[i] === '\\' && i + 1 < spec.length) {
337
+ // Handle escape sequences
338
+ const next = spec[i + 1];
339
+ switch (next) {
340
+ case 'n':
341
+ result += '\n';
342
+ break;
343
+ case 't':
344
+ result += '\t';
345
+ break;
346
+ case 'r':
347
+ result += '\r';
348
+ break;
349
+ case '\\':
350
+ result += '\\';
351
+ break;
352
+ default: result += next;
353
+ }
354
+ i += 2;
355
+ }
356
+ else if (i + 2 < spec.length && spec[i + 1] === '-') {
357
+ // Character range (e.g., a-z)
358
+ const start = spec.charCodeAt(i);
359
+ const end = spec.charCodeAt(i + 2);
360
+ for (let c = start; c <= end; c++) {
361
+ result += String.fromCharCode(c);
362
+ }
363
+ i += 3;
364
+ }
365
+ else {
366
+ result += spec[i];
367
+ i++;
368
+ }
369
+ }
370
+ return result;
371
+ }
372
+ /**
373
+ * Execute tr command - translate or delete characters
374
+ *
375
+ * @param input - Input string to process
376
+ * @param set1 - First character set
377
+ * @param set2 - Second character set (for translation)
378
+ * @param options - tr options
379
+ * @returns Transformed string
380
+ *
381
+ * @example
382
+ * ```typescript
383
+ * // Translate lowercase to uppercase
384
+ * executeTr('hello', '[:lower:]', '[:upper:]')
385
+ * // => 'HELLO'
386
+ *
387
+ * // Delete digits
388
+ * executeTr('abc123', '[:digit:]', undefined, { delete: true })
389
+ * // => 'abc'
390
+ *
391
+ * // Squeeze repeated spaces
392
+ * executeTr('a b', ' ', ' ', { squeeze: true })
393
+ * // => 'a b'
394
+ * ```
395
+ */
396
+ export function executeTr(input, set1, set2, options = {}) {
397
+ const expandedSet1 = expandCharSet(set1);
398
+ const expandedSet2 = set2 ? expandCharSet(set2) : '';
399
+ let charset = expandedSet1;
400
+ if (options.complement) {
401
+ // Create complement of set1 (all chars NOT in set1)
402
+ const set1Chars = new Set(expandedSet1.split(''));
403
+ charset = '';
404
+ for (let i = 0; i < 128; i++) {
405
+ const char = String.fromCharCode(i);
406
+ if (!set1Chars.has(char)) {
407
+ charset += char;
408
+ }
409
+ }
410
+ }
411
+ let result = '';
412
+ let lastChar = '';
413
+ for (const char of input) {
414
+ const pos = charset.indexOf(char);
415
+ if (options.delete) {
416
+ // Delete mode: skip characters in set1
417
+ if (pos === -1) {
418
+ if (options.squeeze && char === lastChar && expandedSet2.includes(char)) {
419
+ continue;
420
+ }
421
+ result += char;
422
+ lastChar = char;
423
+ }
424
+ }
425
+ else if (pos !== -1 && expandedSet2) {
426
+ // Translation mode: replace character
427
+ const replacement = expandedSet2[Math.min(pos, expandedSet2.length - 1)];
428
+ if (options.squeeze && replacement === lastChar) {
429
+ continue;
430
+ }
431
+ result += replacement;
432
+ lastChar = replacement;
433
+ }
434
+ else {
435
+ // No translation for this character
436
+ if (options.squeeze && char === lastChar && charset.includes(char)) {
437
+ continue;
438
+ }
439
+ result += char;
440
+ lastChar = char;
441
+ }
442
+ }
443
+ return result;
444
+ }
445
+ /**
446
+ * Execute uniq command - report or filter repeated lines
447
+ *
448
+ * @param lines - Array of lines to process
449
+ * @param options - Uniq options
450
+ * @returns Array of filtered/modified lines
451
+ *
452
+ * @example
453
+ * ```typescript
454
+ * executeUniq(['a', 'a', 'b', 'b', 'c'], {})
455
+ * // => ['a', 'b', 'c']
456
+ *
457
+ * executeUniq(['a', 'a', 'b'], { count: true })
458
+ * // => ['2 a', '1 b']
459
+ *
460
+ * executeUniq(['a', 'a', 'b'], { repeated: true })
461
+ * // => ['a']
462
+ * ```
463
+ */
464
+ export function executeUniq(lines, options = {}) {
465
+ if (lines.length === 0)
466
+ return [];
467
+ const getCompareKey = (line) => {
468
+ let key = line;
469
+ // Skip fields
470
+ if (options.skipFields) {
471
+ const fields = key.split(/\s+/);
472
+ key = fields.slice(options.skipFields).join(' ');
473
+ }
474
+ // Skip characters
475
+ if (options.skipChars) {
476
+ key = key.slice(options.skipChars);
477
+ }
478
+ // Compare only first N characters (GNU extension -w N)
479
+ if (options.compareChars !== undefined && options.compareChars > 0) {
480
+ key = key.slice(0, options.compareChars);
481
+ }
482
+ // Case insensitive
483
+ if (options.ignoreCase) {
484
+ key = key.toLowerCase();
485
+ }
486
+ return key;
487
+ };
488
+ const groups = [];
489
+ let currentGroup = null;
490
+ for (const line of lines) {
491
+ const key = getCompareKey(line);
492
+ if (currentGroup && getCompareKey(currentGroup.line) === key) {
493
+ currentGroup.count++;
494
+ }
495
+ else {
496
+ if (currentGroup) {
497
+ groups.push(currentGroup);
498
+ }
499
+ currentGroup = { line, count: 1 };
500
+ }
501
+ }
502
+ if (currentGroup) {
503
+ groups.push(currentGroup);
504
+ }
505
+ // Filter based on options
506
+ let result = groups;
507
+ if (options.repeated) {
508
+ result = result.filter(g => g.count > 1);
509
+ }
510
+ if (options.unique) {
511
+ result = result.filter(g => g.count === 1);
512
+ }
513
+ // Format output
514
+ return result.map(g => {
515
+ if (options.count) {
516
+ return `${String(g.count).padStart(7)} ${g.line}`;
517
+ }
518
+ return g.line;
519
+ });
520
+ }
521
+ /**
522
+ * Execute wc command - word, line, and byte counts
523
+ *
524
+ * @param input - Input string to count
525
+ * @param options - Which counts to include
526
+ * @returns Count results
527
+ *
528
+ * @example
529
+ * ```typescript
530
+ * executeWc('hello world\nfoo bar\n')
531
+ * // => { lines: 2, words: 4, bytes: 20, chars: 20 }
532
+ * ```
533
+ */
534
+ export function executeWc(input, _options = {}) {
535
+ // Count lines (number of newlines)
536
+ const lines = (input.match(/\n/g) || []).length;
537
+ // Count words (sequences of non-whitespace)
538
+ const words = input.split(/\s+/).filter(w => w.length > 0).length;
539
+ // Count bytes (UTF-8 encoded length)
540
+ const bytes = new TextEncoder().encode(input).length;
541
+ // Count characters
542
+ const chars = [...input].length;
543
+ return { lines, words, bytes, chars };
544
+ }
545
+ // ============================================================================
546
+ // SHELL UTILITIES
547
+ // ============================================================================
548
+ /**
549
+ * Execute basename command - strip directory and suffix from pathname
550
+ *
551
+ * @param path - The pathname to process
552
+ * @param suffix - Optional suffix to remove
553
+ * @returns Base name of the path
554
+ *
555
+ * @example
556
+ * ```typescript
557
+ * executeBasename('/usr/bin/bash')
558
+ * // => 'bash'
559
+ *
560
+ * executeBasename('/path/to/file.txt', '.txt')
561
+ * // => 'file'
562
+ * ```
563
+ */
564
+ export function executeBasename(path, suffix) {
565
+ // Remove trailing slashes
566
+ let result = path.replace(/\/+$/, '');
567
+ // Get last component
568
+ const lastSlash = result.lastIndexOf('/');
569
+ if (lastSlash !== -1) {
570
+ result = result.slice(lastSlash + 1);
571
+ }
572
+ // Remove suffix if specified and matches
573
+ if (suffix && result.endsWith(suffix) && result !== suffix) {
574
+ result = result.slice(0, -suffix.length);
575
+ }
576
+ return result || '/';
577
+ }
578
+ /**
579
+ * Execute dirname command - strip last component from pathname
580
+ *
581
+ * @param path - The pathname to process
582
+ * @returns Directory portion of the path
583
+ *
584
+ * @example
585
+ * ```typescript
586
+ * executeDirname('/usr/bin/bash')
587
+ * // => '/usr/bin'
588
+ *
589
+ * executeDirname('file.txt')
590
+ * // => '.'
591
+ * ```
592
+ */
593
+ export function executeDirname(path) {
594
+ // Remove trailing slashes (except for root)
595
+ let result = path.replace(/\/+$/, '') || '/';
596
+ // Find last slash
597
+ const lastSlash = result.lastIndexOf('/');
598
+ if (lastSlash === -1) {
599
+ // No slash - current directory
600
+ return '.';
601
+ }
602
+ if (lastSlash === 0) {
603
+ // Slash at start - root
604
+ return '/';
605
+ }
606
+ // Return everything before the last slash, then remove trailing slashes from that
607
+ const dirname = result.slice(0, lastSlash);
608
+ // Keep leading slashes, remove only internal trailing slashes
609
+ return dirname.replace(/\/+$/, '') || '/';
610
+ }
611
+ /**
612
+ * Execute echo command - display a line of text
613
+ *
614
+ * @param args - Arguments to print
615
+ * @param options - Echo options
616
+ * @returns Output string
617
+ *
618
+ * @example
619
+ * ```typescript
620
+ * executeEcho(['hello', 'world'])
621
+ * // => 'hello world\n'
622
+ *
623
+ * executeEcho(['hello\\nworld'], { interpretEscapes: true })
624
+ * // => 'hello\nworld\n'
625
+ * ```
626
+ */
627
+ export function executeEcho(args, options = {}) {
628
+ let output = args.join(' ');
629
+ if (options.interpretEscapes) {
630
+ output = output
631
+ .replace(/\\n/g, '\n')
632
+ .replace(/\\t/g, '\t')
633
+ .replace(/\\r/g, '\r')
634
+ .replace(/\\a/g, '\x07')
635
+ .replace(/\\b/g, '\b')
636
+ .replace(/\\f/g, '\f')
637
+ .replace(/\\v/g, '\v')
638
+ .replace(/\\\\/g, '\\')
639
+ .replace(/\\0([0-7]{1,3})/g, (_, oct) => String.fromCharCode(parseInt(oct, 8)))
640
+ .replace(/\\x([0-9a-fA-F]{1,2})/g, (_, hex) => String.fromCharCode(parseInt(hex, 16)))
641
+ // Handle \c - stop output
642
+ .replace(/\\c.*$/, '');
643
+ }
644
+ if (!options.noNewline && !output.endsWith('\n')) {
645
+ output += '\n';
646
+ }
647
+ return output;
648
+ }
649
+ /**
650
+ * Execute printf command - formatted output
651
+ *
652
+ * @param format - Format string
653
+ * @param args - Arguments to format
654
+ * @returns Formatted output string
655
+ *
656
+ * @example
657
+ * ```typescript
658
+ * executePrintf('Name: %s, Age: %d\n', ['Alice', '30'])
659
+ * // => 'Name: Alice, Age: 30\n'
660
+ *
661
+ * executePrintf('%x\n', ['255'])
662
+ * // => 'ff\n'
663
+ * ```
664
+ */
665
+ export function executePrintf(format, args) {
666
+ let result = '';
667
+ let argIndex = 0;
668
+ // Process escape sequences first
669
+ const processEscapes = (str) => {
670
+ return str
671
+ .replace(/\\n/g, '\n')
672
+ .replace(/\\t/g, '\t')
673
+ .replace(/\\r/g, '\r')
674
+ .replace(/\\a/g, '\x07')
675
+ .replace(/\\b/g, '\b')
676
+ .replace(/\\f/g, '\f')
677
+ .replace(/\\v/g, '\v')
678
+ .replace(/\\\\/g, '\\')
679
+ .replace(/\\0([0-7]{1,3})/g, (_, oct) => String.fromCharCode(parseInt(oct, 8)))
680
+ .replace(/\\x([0-9a-fA-F]{1,2})/g, (_, hex) => String.fromCharCode(parseInt(hex, 16)));
681
+ };
682
+ // Process format string character by character
683
+ let i = 0;
684
+ while (i < format.length) {
685
+ if (format[i] === '%' && i + 1 < format.length) {
686
+ // Check for %%
687
+ if (format[i + 1] === '%') {
688
+ result += '%';
689
+ i += 2;
690
+ continue;
691
+ }
692
+ // Parse format specifier
693
+ let j = i + 1;
694
+ let width = '';
695
+ let precision = '';
696
+ let leftAlign = false;
697
+ // Flags
698
+ while (j < format.length && '- +#0'.includes(format[j])) {
699
+ if (format[j] === '-')
700
+ leftAlign = true;
701
+ j++;
702
+ }
703
+ // Width
704
+ while (j < format.length && /\d/.test(format[j])) {
705
+ width += format[j];
706
+ j++;
707
+ }
708
+ // Precision
709
+ if (j < format.length && format[j] === '.') {
710
+ j++;
711
+ while (j < format.length && /\d/.test(format[j])) {
712
+ precision += format[j];
713
+ j++;
714
+ }
715
+ }
716
+ // Conversion specifier
717
+ const spec = format[j];
718
+ const arg = args[argIndex] || '';
719
+ argIndex++;
720
+ let formatted = '';
721
+ const widthNum = parseInt(width, 10) || 0;
722
+ const precisionNum = precision ? parseInt(precision, 10) : undefined;
723
+ switch (spec) {
724
+ case 's':
725
+ formatted = arg;
726
+ if (precisionNum !== undefined) {
727
+ formatted = formatted.slice(0, precisionNum);
728
+ }
729
+ break;
730
+ case 'd':
731
+ case 'i':
732
+ formatted = String(parseInt(arg, 10) || 0);
733
+ break;
734
+ case 'u':
735
+ formatted = String(Math.abs(parseInt(arg, 10) || 0));
736
+ break;
737
+ case 'x':
738
+ formatted = (parseInt(arg, 10) || 0).toString(16);
739
+ break;
740
+ case 'X':
741
+ formatted = (parseInt(arg, 10) || 0).toString(16).toUpperCase();
742
+ break;
743
+ case 'o':
744
+ formatted = (parseInt(arg, 10) || 0).toString(8);
745
+ break;
746
+ case 'f':
747
+ case 'F':
748
+ const floatVal = parseFloat(arg) || 0;
749
+ formatted = precisionNum !== undefined
750
+ ? floatVal.toFixed(precisionNum)
751
+ : floatVal.toFixed(6);
752
+ break;
753
+ case 'e':
754
+ formatted = (parseFloat(arg) || 0).toExponential(precisionNum ?? 6);
755
+ break;
756
+ case 'E':
757
+ formatted = (parseFloat(arg) || 0).toExponential(precisionNum ?? 6).toUpperCase();
758
+ break;
759
+ case 'c':
760
+ formatted = arg.charAt(0);
761
+ break;
762
+ case 'b':
763
+ // Interpret backslash escapes in arg
764
+ formatted = processEscapes(arg);
765
+ break;
766
+ default:
767
+ formatted = '%' + spec;
768
+ argIndex--; // Didn't consume an argument
769
+ }
770
+ // Apply width padding
771
+ if (widthNum > formatted.length) {
772
+ const padding = ' '.repeat(widthNum - formatted.length);
773
+ formatted = leftAlign ? formatted + padding : padding + formatted;
774
+ }
775
+ result += formatted;
776
+ i = j + 1;
777
+ }
778
+ else {
779
+ result += format[i];
780
+ i++;
781
+ }
782
+ }
783
+ return processEscapes(result);
784
+ }
785
+ /**
786
+ * Format specifiers for date command
787
+ */
788
+ const DATE_FORMATS = {
789
+ '%Y': (d, utc) => String(utc ? d.getUTCFullYear() : d.getFullYear()),
790
+ '%y': (d, utc) => String(utc ? d.getUTCFullYear() : d.getFullYear()).slice(-2),
791
+ '%m': (d, utc) => String(utc ? d.getUTCMonth() + 1 : d.getMonth() + 1).padStart(2, '0'),
792
+ '%d': (d, utc) => String(utc ? d.getUTCDate() : d.getDate()).padStart(2, '0'),
793
+ '%H': (d, utc) => String(utc ? d.getUTCHours() : d.getHours()).padStart(2, '0'),
794
+ '%M': (d, utc) => String(utc ? d.getUTCMinutes() : d.getMinutes()).padStart(2, '0'),
795
+ '%S': (d, utc) => String(utc ? d.getUTCSeconds() : d.getSeconds()).padStart(2, '0'),
796
+ '%N': (d) => String(d.getMilliseconds()).padStart(3, '0') + '000000',
797
+ '%s': (d) => String(Math.floor(d.getTime() / 1000)),
798
+ '%j': (d, utc) => {
799
+ const start = new Date(utc ? d.getUTCFullYear() : d.getFullYear(), 0, 0);
800
+ const diff = d.getTime() - start.getTime();
801
+ const oneDay = 1000 * 60 * 60 * 24;
802
+ return String(Math.floor(diff / oneDay)).padStart(3, '0');
803
+ },
804
+ '%u': (d, utc) => String((utc ? d.getUTCDay() : d.getDay()) || 7), // 1-7, Monday = 1
805
+ '%w': (d, utc) => String(utc ? d.getUTCDay() : d.getDay()), // 0-6, Sunday = 0
806
+ '%a': (d, utc) => ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'][utc ? d.getUTCDay() : d.getDay()],
807
+ '%A': (d, utc) => ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'][utc ? d.getUTCDay() : d.getDay()],
808
+ '%b': (d, utc) => ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'][utc ? d.getUTCMonth() : d.getMonth()],
809
+ '%B': (d, utc) => ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'][utc ? d.getUTCMonth() : d.getMonth()],
810
+ '%I': (d, utc) => {
811
+ const h = utc ? d.getUTCHours() : d.getHours();
812
+ return String(h % 12 || 12).padStart(2, '0');
813
+ },
814
+ '%p': (d, utc) => (utc ? d.getUTCHours() : d.getHours()) < 12 ? 'AM' : 'PM',
815
+ '%P': (d, utc) => (utc ? d.getUTCHours() : d.getHours()) < 12 ? 'am' : 'pm',
816
+ '%Z': (_d, utc) => utc ? 'UTC' : Intl.DateTimeFormat().resolvedOptions().timeZone,
817
+ '%z': (d, utc) => {
818
+ if (utc)
819
+ return '+0000';
820
+ const offset = d.getTimezoneOffset();
821
+ const sign = offset <= 0 ? '+' : '-';
822
+ const absOffset = Math.abs(offset);
823
+ return `${sign}${String(Math.floor(absOffset / 60)).padStart(2, '0')}${String(absOffset % 60).padStart(2, '0')}`;
824
+ },
825
+ '%n': () => '\n',
826
+ '%t': () => '\t',
827
+ '%%': () => '%',
828
+ };
829
+ /**
830
+ * Execute date command - display or format date and time
831
+ *
832
+ * @param format - Optional format string starting with +
833
+ * @param options - Date options
834
+ * @returns Formatted date string
835
+ *
836
+ * @example
837
+ * ```typescript
838
+ * executeDate('+%Y-%m-%d')
839
+ * // => '2024-01-15'
840
+ *
841
+ * executeDate('+%H:%M:%S', { utc: true })
842
+ * // => '12:34:56'
843
+ * ```
844
+ */
845
+ export function executeDate(format, options = {}) {
846
+ let date;
847
+ if (options.date) {
848
+ date = typeof options.date === 'string' ? new Date(options.date) : options.date;
849
+ }
850
+ else {
851
+ date = new Date();
852
+ }
853
+ if (isNaN(date.getTime())) {
854
+ throw new Error('date: invalid date');
855
+ }
856
+ if (!format) {
857
+ // Default format similar to Unix date
858
+ return date.toString();
859
+ }
860
+ // Remove leading + if present
861
+ const formatStr = format.startsWith('+') ? format.slice(1) : format;
862
+ // Replace format specifiers
863
+ let result = formatStr;
864
+ // Sort specifiers by length (longest first) to handle %% before %
865
+ const specifiers = Object.keys(DATE_FORMATS).sort((a, b) => b.length - a.length);
866
+ for (const spec of specifiers) {
867
+ const formatter = DATE_FORMATS[spec];
868
+ result = result.split(spec).join(formatter(date, options.utc ?? false));
869
+ }
870
+ return result;
871
+ }
872
+ /**
873
+ * Execute dd command - convert and copy a file
874
+ *
875
+ * @param input - Input data as Uint8Array
876
+ * @param options - dd options
877
+ * @returns Output data as Uint8Array
878
+ *
879
+ * @example
880
+ * ```typescript
881
+ * const data = new TextEncoder().encode('hello world')
882
+ * executeDd(data, { bs: 5, count: 1 })
883
+ * // => Uint8Array containing 'hello'
884
+ * ```
885
+ */
886
+ export function executeDd(input, options = {}) {
887
+ const bs = options.bs ?? 512;
888
+ const ibs = options.ibs ?? bs;
889
+ const obs = options.obs ?? bs;
890
+ const skip = options.skip ?? 0;
891
+ const seek = options.seek ?? 0;
892
+ // Calculate start position in input
893
+ const inputStart = skip * ibs;
894
+ if (inputStart >= input.length) {
895
+ return new Uint8Array(0);
896
+ }
897
+ // Calculate how much to read
898
+ let bytesToRead;
899
+ if (options.count !== undefined) {
900
+ bytesToRead = options.count * ibs;
901
+ }
902
+ else {
903
+ bytesToRead = input.length - inputStart;
904
+ }
905
+ // Read from input
906
+ const endPos = Math.min(inputStart + bytesToRead, input.length);
907
+ const inputSlice = input.slice(inputStart, endPos);
908
+ // Handle seek in output (pad with zeros)
909
+ const seekBytes = seek * obs;
910
+ if (seekBytes > 0) {
911
+ const output = new Uint8Array(seekBytes + inputSlice.length);
912
+ output.set(inputSlice, seekBytes);
913
+ return output;
914
+ }
915
+ return inputSlice;
916
+ }
917
+ /**
918
+ * Execute od command - dump files in various formats
919
+ *
920
+ * @param input - Input data as Uint8Array
921
+ * @param options - od options
922
+ * @returns Formatted dump string
923
+ *
924
+ * @example
925
+ * ```typescript
926
+ * const data = new TextEncoder().encode('ABC')
927
+ * executeOd(data, { format: 'x' })
928
+ * // => '0000000 41 42 43\n0000003\n'
929
+ * ```
930
+ */
931
+ export function executeOd(input, options = {}) {
932
+ const format = options.format ?? 'o';
933
+ const addressFormat = options.addressFormat ?? 'o';
934
+ const width = options.width ?? 16;
935
+ const skip = options.skip ?? 0;
936
+ const count = options.count ?? input.length - skip;
937
+ const lines = [];
938
+ const endPos = Math.min(skip + count, input.length);
939
+ const formatAddress = (addr) => {
940
+ switch (addressFormat) {
941
+ case 'x': return addr.toString(16).padStart(7, '0');
942
+ case 'd': return addr.toString(10).padStart(7, '0');
943
+ case 'n': return '';
944
+ case 'o':
945
+ default:
946
+ return addr.toString(8).padStart(7, '0');
947
+ }
948
+ };
949
+ const formatByte = (byte) => {
950
+ switch (format) {
951
+ case 'x':
952
+ return byte.toString(16).padStart(2, '0');
953
+ case 'X':
954
+ return byte.toString(16).toUpperCase().padStart(2, '0');
955
+ case 'd':
956
+ return byte.toString(10).padStart(3, ' ');
957
+ case 'u':
958
+ return byte.toString(10).padStart(3, ' ');
959
+ case 'c':
960
+ // Character representation
961
+ if (byte >= 32 && byte < 127) {
962
+ return ' ' + String.fromCharCode(byte);
963
+ }
964
+ // Special characters
965
+ const specials = {
966
+ 0: ' \\0',
967
+ 7: ' \\a',
968
+ 8: ' \\b',
969
+ 9: ' \\t',
970
+ 10: ' \\n',
971
+ 11: ' \\v',
972
+ 12: ' \\f',
973
+ 13: ' \\r',
974
+ };
975
+ return specials[byte] ?? byte.toString(8).padStart(3, '0');
976
+ case 'o':
977
+ default:
978
+ return byte.toString(8).padStart(3, '0');
979
+ }
980
+ };
981
+ for (let i = skip; i < endPos; i += width) {
982
+ const lineBytes = input.slice(i, Math.min(i + width, endPos));
983
+ const addrStr = formatAddress(i);
984
+ const bytesStr = Array.from(lineBytes).map(formatByte).join(' ');
985
+ if (addressFormat === 'n') {
986
+ lines.push(bytesStr);
987
+ }
988
+ else {
989
+ lines.push(`${addrStr} ${bytesStr}`);
990
+ }
991
+ }
992
+ // Add final address line
993
+ if (addressFormat !== 'n') {
994
+ lines.push(formatAddress(endPos));
995
+ }
996
+ return lines.join('\n') + '\n';
997
+ }
998
+ // ============================================================================
999
+ // COMMAND SET FOR TIERED EXECUTOR
1000
+ // ============================================================================
1001
+ /**
1002
+ * Set of POSIX utility commands handled by this module
1003
+ */
1004
+ export const POSIX_UTILS_COMMANDS = new Set([
1005
+ 'cut', 'sort', 'tr', 'uniq', 'wc',
1006
+ 'basename', 'dirname', 'echo', 'printf',
1007
+ 'date', 'dd', 'od',
1008
+ ]);
1009
+ /**
1010
+ * Check if a command is a POSIX utility command
1011
+ */
1012
+ export function isPosixUtilsCommand(cmd) {
1013
+ return POSIX_UTILS_COMMANDS.has(cmd);
1014
+ }
1015
+ //# sourceMappingURL=posix-utils.js.map