mikrojs 0.0.0 → 0.0.8

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 (497) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +76 -0
  3. package/bin/mikrojs.js +3 -0
  4. package/dist/_exports/ble.d.ts +3 -0
  5. package/dist/_exports/ble.d.ts.map +1 -0
  6. package/dist/_exports/ble.js +2 -0
  7. package/dist/_exports/ble.js.map +1 -0
  8. package/dist/_exports/cbor.d.ts +3 -0
  9. package/dist/_exports/cbor.d.ts.map +1 -0
  10. package/dist/_exports/cbor.js +2 -0
  11. package/dist/_exports/cbor.js.map +1 -0
  12. package/dist/_exports/console.d.ts +2 -0
  13. package/dist/_exports/console.d.ts.map +1 -0
  14. package/dist/_exports/console.js +2 -0
  15. package/dist/_exports/console.js.map +1 -0
  16. package/dist/_exports/env.d.ts +2 -0
  17. package/dist/_exports/env.d.ts.map +1 -0
  18. package/dist/_exports/env.js +2 -0
  19. package/dist/_exports/env.js.map +1 -0
  20. package/dist/_exports/format.d.ts +2 -0
  21. package/dist/_exports/format.d.ts.map +1 -0
  22. package/dist/_exports/format.js +2 -0
  23. package/dist/_exports/format.js.map +1 -0
  24. package/dist/_exports/fs.d.ts +2 -0
  25. package/dist/_exports/fs.d.ts.map +1 -0
  26. package/dist/_exports/fs.js +2 -0
  27. package/dist/_exports/fs.js.map +1 -0
  28. package/dist/_exports/http/helpers.d.ts +3 -0
  29. package/dist/_exports/http/helpers.d.ts.map +1 -0
  30. package/dist/_exports/http/helpers.js +5 -0
  31. package/dist/_exports/http/helpers.js.map +1 -0
  32. package/dist/_exports/http/request.d.ts +4 -0
  33. package/dist/_exports/http/request.d.ts.map +1 -0
  34. package/dist/_exports/http/request.js +10 -0
  35. package/dist/_exports/http/request.js.map +1 -0
  36. package/dist/_exports/i2c.d.ts +2 -0
  37. package/dist/_exports/i2c.d.ts.map +1 -0
  38. package/dist/_exports/i2c.js +2 -0
  39. package/dist/_exports/i2c.js.map +1 -0
  40. package/dist/_exports/index.d.ts +61 -0
  41. package/dist/_exports/index.d.ts.map +1 -0
  42. package/dist/_exports/index.js +4 -0
  43. package/dist/_exports/index.js.map +1 -0
  44. package/dist/_exports/inspect.d.ts +2 -0
  45. package/dist/_exports/inspect.d.ts.map +1 -0
  46. package/dist/_exports/inspect.js +2 -0
  47. package/dist/_exports/inspect.js.map +1 -0
  48. package/dist/_exports/kv/nvs.d.ts +3 -0
  49. package/dist/_exports/kv/nvs.d.ts.map +1 -0
  50. package/dist/_exports/kv/nvs.js +2 -0
  51. package/dist/_exports/kv/nvs.js.map +1 -0
  52. package/dist/_exports/kv/rtc.d.ts +3 -0
  53. package/dist/_exports/kv/rtc.d.ts.map +1 -0
  54. package/dist/_exports/kv/rtc.js +2 -0
  55. package/dist/_exports/kv/rtc.js.map +1 -0
  56. package/dist/_exports/neopixel.d.ts +2 -0
  57. package/dist/_exports/neopixel.d.ts.map +1 -0
  58. package/dist/_exports/neopixel.js +2 -0
  59. package/dist/_exports/neopixel.js.map +1 -0
  60. package/dist/_exports/pin.d.ts +2 -0
  61. package/dist/_exports/pin.d.ts.map +1 -0
  62. package/dist/_exports/pin.js +2 -0
  63. package/dist/_exports/pin.js.map +1 -0
  64. package/dist/_exports/pwm.d.ts +2 -0
  65. package/dist/_exports/pwm.d.ts.map +1 -0
  66. package/dist/_exports/pwm.js +2 -0
  67. package/dist/_exports/pwm.js.map +1 -0
  68. package/dist/_exports/reader.d.ts +2 -0
  69. package/dist/_exports/reader.d.ts.map +1 -0
  70. package/dist/_exports/reader.js +2 -0
  71. package/dist/_exports/reader.js.map +1 -0
  72. package/dist/_exports/result.d.ts +2 -0
  73. package/dist/_exports/result.d.ts.map +1 -0
  74. package/dist/_exports/result.js +2 -0
  75. package/dist/_exports/result.js.map +1 -0
  76. package/dist/_exports/schema.d.ts +2 -0
  77. package/dist/_exports/schema.d.ts.map +1 -0
  78. package/dist/_exports/schema.js +2 -0
  79. package/dist/_exports/schema.js.map +1 -0
  80. package/dist/_exports/sim.d.ts +199 -0
  81. package/dist/_exports/sim.d.ts.map +1 -0
  82. package/dist/_exports/sim.js +8 -0
  83. package/dist/_exports/sim.js.map +1 -0
  84. package/dist/_exports/sleep.d.ts +2 -0
  85. package/dist/_exports/sleep.d.ts.map +1 -0
  86. package/dist/_exports/sleep.js +2 -0
  87. package/dist/_exports/sleep.js.map +1 -0
  88. package/dist/_exports/sntp.d.ts +3 -0
  89. package/dist/_exports/sntp.d.ts.map +1 -0
  90. package/dist/_exports/sntp.js +2 -0
  91. package/dist/_exports/sntp.js.map +1 -0
  92. package/dist/_exports/spi.d.ts +2 -0
  93. package/dist/_exports/spi.d.ts.map +1 -0
  94. package/dist/_exports/spi.js +2 -0
  95. package/dist/_exports/spi.js.map +1 -0
  96. package/dist/_exports/stdio.d.ts +2 -0
  97. package/dist/_exports/stdio.d.ts.map +1 -0
  98. package/dist/_exports/stdio.js +2 -0
  99. package/dist/_exports/stdio.js.map +1 -0
  100. package/dist/_exports/stream.d.ts +2 -0
  101. package/dist/_exports/stream.d.ts.map +1 -0
  102. package/dist/_exports/stream.js +2 -0
  103. package/dist/_exports/stream.js.map +1 -0
  104. package/dist/_exports/sys.d.ts +2 -0
  105. package/dist/_exports/sys.d.ts.map +1 -0
  106. package/dist/_exports/sys.js +2 -0
  107. package/dist/_exports/sys.js.map +1 -0
  108. package/dist/_exports/test.d.ts +2 -0
  109. package/dist/_exports/test.d.ts.map +1 -0
  110. package/dist/_exports/test.js +2 -0
  111. package/dist/_exports/test.js.map +1 -0
  112. package/dist/_exports/uart.d.ts +2 -0
  113. package/dist/_exports/uart.d.ts.map +1 -0
  114. package/dist/_exports/uart.js +2 -0
  115. package/dist/_exports/uart.js.map +1 -0
  116. package/dist/_exports/wifi.d.ts +3 -0
  117. package/dist/_exports/wifi.d.ts.map +1 -0
  118. package/dist/_exports/wifi.js +2 -0
  119. package/dist/_exports/wifi.js.map +1 -0
  120. package/dist/cli/cli.d.ts +3 -0
  121. package/dist/cli/cli.d.ts.map +1 -0
  122. package/dist/cli/cli.js +215 -0
  123. package/dist/cli/cli.js.map +1 -0
  124. package/dist/cli/cliWrapper.d.ts +3 -0
  125. package/dist/cli/cliWrapper.d.ts.map +1 -0
  126. package/dist/cli/cliWrapper.js +40 -0
  127. package/dist/cli/cliWrapper.js.map +1 -0
  128. package/dist/cli/commands/build-runtime.d.ts +14 -0
  129. package/dist/cli/commands/build-runtime.d.ts.map +1 -0
  130. package/dist/cli/commands/build-runtime.js +122 -0
  131. package/dist/cli/commands/build-runtime.js.map +1 -0
  132. package/dist/cli/commands/build.d.ts +31 -0
  133. package/dist/cli/commands/build.d.ts.map +1 -0
  134. package/dist/cli/commands/build.js +145 -0
  135. package/dist/cli/commands/build.js.map +1 -0
  136. package/dist/cli/commands/clean.d.ts +16 -0
  137. package/dist/cli/commands/clean.d.ts.map +1 -0
  138. package/dist/cli/commands/clean.js +148 -0
  139. package/dist/cli/commands/clean.js.map +1 -0
  140. package/dist/cli/commands/console.d.ts +19 -0
  141. package/dist/cli/commands/console.d.ts.map +1 -0
  142. package/dist/cli/commands/console.js +32 -0
  143. package/dist/cli/commands/console.js.map +1 -0
  144. package/dist/cli/commands/deploy.d.ts +63 -0
  145. package/dist/cli/commands/deploy.d.ts.map +1 -0
  146. package/dist/cli/commands/deploy.js +242 -0
  147. package/dist/cli/commands/deploy.js.map +1 -0
  148. package/dist/cli/commands/dev.d.ts +41 -0
  149. package/dist/cli/commands/dev.d.ts.map +1 -0
  150. package/dist/cli/commands/dev.js +170 -0
  151. package/dist/cli/commands/dev.js.map +1 -0
  152. package/dist/cli/commands/docs.d.ts +7 -0
  153. package/dist/cli/commands/docs.d.ts.map +1 -0
  154. package/dist/cli/commands/docs.js +20 -0
  155. package/dist/cli/commands/docs.js.map +1 -0
  156. package/dist/cli/commands/env.d.ts +59 -0
  157. package/dist/cli/commands/env.d.ts.map +1 -0
  158. package/dist/cli/commands/env.js +257 -0
  159. package/dist/cli/commands/env.js.map +1 -0
  160. package/dist/cli/commands/erase.d.ts +18 -0
  161. package/dist/cli/commands/erase.d.ts.map +1 -0
  162. package/dist/cli/commands/erase.js +90 -0
  163. package/dist/cli/commands/erase.js.map +1 -0
  164. package/dist/cli/commands/flash.d.ts +30 -0
  165. package/dist/cli/commands/flash.d.ts.map +1 -0
  166. package/dist/cli/commands/flash.js +243 -0
  167. package/dist/cli/commands/flash.js.map +1 -0
  168. package/dist/cli/commands/home.d.ts +7 -0
  169. package/dist/cli/commands/home.d.ts.map +1 -0
  170. package/dist/cli/commands/home.js +20 -0
  171. package/dist/cli/commands/home.js.map +1 -0
  172. package/dist/cli/commands/ls.d.ts +17 -0
  173. package/dist/cli/commands/ls.d.ts.map +1 -0
  174. package/dist/cli/commands/ls.js +62 -0
  175. package/dist/cli/commands/ls.js.map +1 -0
  176. package/dist/cli/commands/sim/clean.d.ts +7 -0
  177. package/dist/cli/commands/sim/clean.d.ts.map +1 -0
  178. package/dist/cli/commands/sim/clean.js +34 -0
  179. package/dist/cli/commands/sim/clean.js.map +1 -0
  180. package/dist/cli/commands/sim/deploy.d.ts +46 -0
  181. package/dist/cli/commands/sim/deploy.d.ts.map +1 -0
  182. package/dist/cli/commands/sim/deploy.js +127 -0
  183. package/dist/cli/commands/sim/deploy.js.map +1 -0
  184. package/dist/cli/commands/sim/dev.d.ts +52 -0
  185. package/dist/cli/commands/sim/dev.d.ts.map +1 -0
  186. package/dist/cli/commands/sim/dev.js +380 -0
  187. package/dist/cli/commands/sim/dev.js.map +1 -0
  188. package/dist/cli/commands/sim/env.d.ts +56 -0
  189. package/dist/cli/commands/sim/env.d.ts.map +1 -0
  190. package/dist/cli/commands/sim/env.js +204 -0
  191. package/dist/cli/commands/sim/env.js.map +1 -0
  192. package/dist/cli/commands/sim/profile.d.ts +67 -0
  193. package/dist/cli/commands/sim/profile.d.ts.map +1 -0
  194. package/dist/cli/commands/sim/profile.js +356 -0
  195. package/dist/cli/commands/sim/profile.js.map +1 -0
  196. package/dist/cli/commands/sim/repl.d.ts +16 -0
  197. package/dist/cli/commands/sim/repl.d.ts.map +1 -0
  198. package/dist/cli/commands/sim/repl.js +119 -0
  199. package/dist/cli/commands/sim/repl.js.map +1 -0
  200. package/dist/cli/commands/sim/reset.d.ts +11 -0
  201. package/dist/cli/commands/sim/reset.d.ts.map +1 -0
  202. package/dist/cli/commands/sim/reset.js +59 -0
  203. package/dist/cli/commands/sim/reset.js.map +1 -0
  204. package/dist/cli/commands/sim/scaffold.d.ts +11 -0
  205. package/dist/cli/commands/sim/scaffold.d.ts.map +1 -0
  206. package/dist/cli/commands/sim/scaffold.js +41 -0
  207. package/dist/cli/commands/sim/scaffold.js.map +1 -0
  208. package/dist/cli/commands/sim/test.d.ts +49 -0
  209. package/dist/cli/commands/sim/test.d.ts.map +1 -0
  210. package/dist/cli/commands/sim/test.js +364 -0
  211. package/dist/cli/commands/sim/test.js.map +1 -0
  212. package/dist/cli/commands/sim.d.ts +228 -0
  213. package/dist/cli/commands/sim.d.ts.map +1 -0
  214. package/dist/cli/commands/sim.js +69 -0
  215. package/dist/cli/commands/sim.js.map +1 -0
  216. package/dist/cli/commands/tail.d.ts +14 -0
  217. package/dist/cli/commands/tail.d.ts.map +1 -0
  218. package/dist/cli/commands/tail.js +50 -0
  219. package/dist/cli/commands/tail.js.map +1 -0
  220. package/dist/cli/commands/test.d.ts +39 -0
  221. package/dist/cli/commands/test.d.ts.map +1 -0
  222. package/dist/cli/commands/test.js +432 -0
  223. package/dist/cli/commands/test.js.map +1 -0
  224. package/dist/cli/components/DevicePicker.d.ts +9 -0
  225. package/dist/cli/components/DevicePicker.d.ts.map +1 -0
  226. package/dist/cli/components/DevicePicker.js +71 -0
  227. package/dist/cli/components/DevicePicker.js.map +1 -0
  228. package/dist/cli/components/EnvEditor.d.ts +12 -0
  229. package/dist/cli/components/EnvEditor.d.ts.map +1 -0
  230. package/dist/cli/components/EnvEditor.js +201 -0
  231. package/dist/cli/components/EnvEditor.js.map +1 -0
  232. package/dist/cli/components/TextInput.d.ts +28 -0
  233. package/dist/cli/components/TextInput.d.ts.map +1 -0
  234. package/dist/cli/components/TextInput.js +73 -0
  235. package/dist/cli/components/TextInput.js.map +1 -0
  236. package/dist/cli/components/TitledBox.d.ts +27 -0
  237. package/dist/cli/components/TitledBox.d.ts.map +1 -0
  238. package/dist/cli/components/TitledBox.js +111 -0
  239. package/dist/cli/components/TitledBox.js.map +1 -0
  240. package/dist/cli/hooks/useDevices.d.ts +23 -0
  241. package/dist/cli/hooks/useDevices.d.ts.map +1 -0
  242. package/dist/cli/hooks/useDevices.js +19 -0
  243. package/dist/cli/hooks/useDevices.js.map +1 -0
  244. package/dist/cli/lib/RenderAndExit.d.ts +6 -0
  245. package/dist/cli/lib/RenderAndExit.d.ts.map +1 -0
  246. package/dist/cli/lib/RenderAndExit.js +8 -0
  247. package/dist/cli/lib/RenderAndExit.js.map +1 -0
  248. package/dist/cli/lib/Spinner.d.ts +11 -0
  249. package/dist/cli/lib/Spinner.d.ts.map +1 -0
  250. package/dist/cli/lib/Spinner.js +22 -0
  251. package/dist/cli/lib/Spinner.js.map +1 -0
  252. package/dist/cli/lib/agent.d.ts +38 -0
  253. package/dist/cli/lib/agent.d.ts.map +1 -0
  254. package/dist/cli/lib/agent.js +87 -0
  255. package/dist/cli/lib/agent.js.map +1 -0
  256. package/dist/cli/lib/boards.d.ts +23 -0
  257. package/dist/cli/lib/boards.d.ts.map +1 -0
  258. package/dist/cli/lib/boards.js +67 -0
  259. package/dist/cli/lib/boards.js.map +1 -0
  260. package/dist/cli/lib/build.d.ts +47 -0
  261. package/dist/cli/lib/build.d.ts.map +1 -0
  262. package/dist/cli/lib/build.js +533 -0
  263. package/dist/cli/lib/build.js.map +1 -0
  264. package/dist/cli/lib/connectSim.d.ts +21 -0
  265. package/dist/cli/lib/connectSim.d.ts.map +1 -0
  266. package/dist/cli/lib/connectSim.js +20 -0
  267. package/dist/cli/lib/connectSim.js.map +1 -0
  268. package/dist/cli/lib/deploy.d.ts +42 -0
  269. package/dist/cli/lib/deploy.d.ts.map +1 -0
  270. package/dist/cli/lib/deploy.js +121 -0
  271. package/dist/cli/lib/deploy.js.map +1 -0
  272. package/dist/cli/lib/deployProgress.d.ts +8 -0
  273. package/dist/cli/lib/deployProgress.d.ts.map +1 -0
  274. package/dist/cli/lib/deployProgress.js +32 -0
  275. package/dist/cli/lib/deployProgress.js.map +1 -0
  276. package/dist/cli/lib/dotenv.d.ts +16 -0
  277. package/dist/cli/lib/dotenv.d.ts.map +1 -0
  278. package/dist/cli/lib/dotenv.js +33 -0
  279. package/dist/cli/lib/dotenv.js.map +1 -0
  280. package/dist/cli/lib/esbuild.d.ts +7 -0
  281. package/dist/cli/lib/esbuild.d.ts.map +1 -0
  282. package/dist/cli/lib/esbuild.js +15 -0
  283. package/dist/cli/lib/esbuild.js.map +1 -0
  284. package/dist/cli/lib/esptool.d.ts +41 -0
  285. package/dist/cli/lib/esptool.d.ts.map +1 -0
  286. package/dist/cli/lib/esptool.js +43 -0
  287. package/dist/cli/lib/esptool.js.map +1 -0
  288. package/dist/cli/lib/firmware.d.ts +24 -0
  289. package/dist/cli/lib/firmware.d.ts.map +1 -0
  290. package/dist/cli/lib/firmware.js +406 -0
  291. package/dist/cli/lib/firmware.js.map +1 -0
  292. package/dist/cli/lib/firmwareCompat.d.ts +19 -0
  293. package/dist/cli/lib/firmwareCompat.d.ts.map +1 -0
  294. package/dist/cli/lib/firmwareCompat.js +31 -0
  295. package/dist/cli/lib/firmwareCompat.js.map +1 -0
  296. package/dist/cli/lib/heapBaseline.d.ts +15 -0
  297. package/dist/cli/lib/heapBaseline.d.ts.map +1 -0
  298. package/dist/cli/lib/heapBaseline.js +39 -0
  299. package/dist/cli/lib/heapBaseline.js.map +1 -0
  300. package/dist/cli/lib/ink-table/index.d.ts +88 -0
  301. package/dist/cli/lib/ink-table/index.d.ts.map +1 -0
  302. package/dist/cli/lib/ink-table/index.js +217 -0
  303. package/dist/cli/lib/ink-table/index.js.map +1 -0
  304. package/dist/cli/lib/loadMikroConfig.d.ts +7 -0
  305. package/dist/cli/lib/loadMikroConfig.d.ts.map +1 -0
  306. package/dist/cli/lib/loadMikroConfig.js +26 -0
  307. package/dist/cli/lib/loadMikroConfig.js.map +1 -0
  308. package/dist/cli/lib/minify.d.ts +3 -0
  309. package/dist/cli/lib/minify.d.ts.map +1 -0
  310. package/dist/cli/lib/minify.js +89 -0
  311. package/dist/cli/lib/minify.js.map +1 -0
  312. package/dist/cli/lib/openSim.d.ts +29 -0
  313. package/dist/cli/lib/openSim.d.ts.map +1 -0
  314. package/dist/cli/lib/openSim.js +32 -0
  315. package/dist/cli/lib/openSim.js.map +1 -0
  316. package/dist/cli/lib/ospawn.d.ts +34 -0
  317. package/dist/cli/lib/ospawn.d.ts.map +1 -0
  318. package/dist/cli/lib/ospawn.js +90 -0
  319. package/dist/cli/lib/ospawn.js.map +1 -0
  320. package/dist/cli/lib/parseMinifier.d.ts +10 -0
  321. package/dist/cli/lib/parseMinifier.d.ts.map +1 -0
  322. package/dist/cli/lib/parseMinifier.js +49 -0
  323. package/dist/cli/lib/parseMinifier.js.map +1 -0
  324. package/dist/cli/lib/parseSize.d.ts +6 -0
  325. package/dist/cli/lib/parseSize.d.ts.map +1 -0
  326. package/dist/cli/lib/parseSize.js +25 -0
  327. package/dist/cli/lib/parseSize.js.map +1 -0
  328. package/dist/cli/lib/projectRoot.d.ts +11 -0
  329. package/dist/cli/lib/projectRoot.d.ts.map +1 -0
  330. package/dist/cli/lib/projectRoot.js +28 -0
  331. package/dist/cli/lib/projectRoot.js.map +1 -0
  332. package/dist/cli/lib/protocol.d.ts +144 -0
  333. package/dist/cli/lib/protocol.d.ts.map +1 -0
  334. package/dist/cli/lib/protocol.js +385 -0
  335. package/dist/cli/lib/protocol.js.map +1 -0
  336. package/dist/cli/lib/recover.d.ts +25 -0
  337. package/dist/cli/lib/recover.d.ts.map +1 -0
  338. package/dist/cli/lib/recover.js +144 -0
  339. package/dist/cli/lib/recover.js.map +1 -0
  340. package/dist/cli/lib/resolveEntry.d.ts +7 -0
  341. package/dist/cli/lib/resolveEntry.d.ts.map +1 -0
  342. package/dist/cli/lib/resolveEntry.js +30 -0
  343. package/dist/cli/lib/resolveEntry.js.map +1 -0
  344. package/dist/cli/lib/runHooks.d.ts +34 -0
  345. package/dist/cli/lib/runHooks.d.ts.map +1 -0
  346. package/dist/cli/lib/runHooks.js +90 -0
  347. package/dist/cli/lib/runHooks.js.map +1 -0
  348. package/dist/cli/lib/serial/InkReplConsole.d.ts +27 -0
  349. package/dist/cli/lib/serial/InkReplConsole.d.ts.map +1 -0
  350. package/dist/cli/lib/serial/InkReplConsole.js +24 -0
  351. package/dist/cli/lib/serial/InkReplConsole.js.map +1 -0
  352. package/dist/cli/lib/serial/InkReplMode.d.ts +38 -0
  353. package/dist/cli/lib/serial/InkReplMode.d.ts.map +1 -0
  354. package/dist/cli/lib/serial/InkReplMode.js +90 -0
  355. package/dist/cli/lib/serial/InkReplMode.js.map +1 -0
  356. package/dist/cli/lib/serial/ReplConsole.d.ts +21 -0
  357. package/dist/cli/lib/serial/ReplConsole.d.ts.map +1 -0
  358. package/dist/cli/lib/serial/ReplConsole.js +249 -0
  359. package/dist/cli/lib/serial/ReplConsole.js.map +1 -0
  360. package/dist/cli/lib/serial/devSession.d.ts +57 -0
  361. package/dist/cli/lib/serial/devSession.d.ts.map +1 -0
  362. package/dist/cli/lib/serial/devSession.js +160 -0
  363. package/dist/cli/lib/serial/devSession.js.map +1 -0
  364. package/dist/cli/lib/serial/dispatchReplCommand.d.ts +25 -0
  365. package/dist/cli/lib/serial/dispatchReplCommand.d.ts.map +1 -0
  366. package/dist/cli/lib/serial/dispatchReplCommand.js +27 -0
  367. package/dist/cli/lib/serial/dispatchReplCommand.js.map +1 -0
  368. package/dist/cli/lib/serial/openSession.d.ts +28 -0
  369. package/dist/cli/lib/serial/openSession.d.ts.map +1 -0
  370. package/dist/cli/lib/serial/openSession.js +48 -0
  371. package/dist/cli/lib/serial/openSession.js.map +1 -0
  372. package/dist/cli/lib/serial/replStateMachine.d.ts +169 -0
  373. package/dist/cli/lib/serial/replStateMachine.d.ts.map +1 -0
  374. package/dist/cli/lib/serial/replStateMachine.js +657 -0
  375. package/dist/cli/lib/serial/replStateMachine.js.map +1 -0
  376. package/dist/cli/lib/serial/runAgentRepl.d.ts +33 -0
  377. package/dist/cli/lib/serial/runAgentRepl.d.ts.map +1 -0
  378. package/dist/cli/lib/serial/runAgentRepl.js +80 -0
  379. package/dist/cli/lib/serial/runAgentRepl.js.map +1 -0
  380. package/dist/cli/lib/session.d.ts +163 -0
  381. package/dist/cli/lib/session.d.ts.map +1 -0
  382. package/dist/cli/lib/session.js +490 -0
  383. package/dist/cli/lib/session.js.map +1 -0
  384. package/dist/cli/lib/simConfig.d.ts +15 -0
  385. package/dist/cli/lib/simConfig.d.ts.map +1 -0
  386. package/dist/cli/lib/simConfig.js +25 -0
  387. package/dist/cli/lib/simConfig.js.map +1 -0
  388. package/dist/cli/lib/simPid.d.ts +30 -0
  389. package/dist/cli/lib/simPid.d.ts.map +1 -0
  390. package/dist/cli/lib/simPid.js +120 -0
  391. package/dist/cli/lib/simPid.js.map +1 -0
  392. package/dist/cli/lib/simTransport.d.ts +17 -0
  393. package/dist/cli/lib/simTransport.d.ts.map +1 -0
  394. package/dist/cli/lib/simTransport.js +80 -0
  395. package/dist/cli/lib/simTransport.js.map +1 -0
  396. package/dist/cli/lib/testRunner.d.ts +86 -0
  397. package/dist/cli/lib/testRunner.d.ts.map +1 -0
  398. package/dist/cli/lib/testRunner.js +469 -0
  399. package/dist/cli/lib/testRunner.js.map +1 -0
  400. package/dist/cli/lib/transport.d.ts +34 -0
  401. package/dist/cli/lib/transport.d.ts.map +1 -0
  402. package/dist/cli/lib/transport.js +117 -0
  403. package/dist/cli/lib/transport.js.map +1 -0
  404. package/dist/cli/lib/useObservable.d.ts +4 -0
  405. package/dist/cli/lib/useObservable.d.ts.map +1 -0
  406. package/dist/cli/lib/useObservable.js +22 -0
  407. package/dist/cli/lib/useObservable.js.map +1 -0
  408. package/dist/cli/lib/watcher.d.ts +10 -0
  409. package/dist/cli/lib/watcher.d.ts.map +1 -0
  410. package/dist/cli/lib/watcher.js +34 -0
  411. package/dist/cli/lib/watcher.js.map +1 -0
  412. package/dist/constants.d.ts +13 -0
  413. package/dist/constants.d.ts.map +1 -0
  414. package/dist/constants.js +27 -0
  415. package/dist/constants.js.map +1 -0
  416. package/dist/simulator/builtins/ble.d.ts +3 -0
  417. package/dist/simulator/builtins/ble.d.ts.map +1 -0
  418. package/dist/simulator/builtins/ble.js +46 -0
  419. package/dist/simulator/builtins/ble.js.map +1 -0
  420. package/dist/simulator/builtins/console.d.ts +8 -0
  421. package/dist/simulator/builtins/console.d.ts.map +1 -0
  422. package/dist/simulator/builtins/console.js +24 -0
  423. package/dist/simulator/builtins/console.js.map +1 -0
  424. package/dist/simulator/builtins/http.d.ts +3 -0
  425. package/dist/simulator/builtins/http.d.ts.map +1 -0
  426. package/dist/simulator/builtins/http.js +90 -0
  427. package/dist/simulator/builtins/http.js.map +1 -0
  428. package/dist/simulator/builtins/i2c.d.ts +3 -0
  429. package/dist/simulator/builtins/i2c.d.ts.map +1 -0
  430. package/dist/simulator/builtins/i2c.js +17 -0
  431. package/dist/simulator/builtins/i2c.js.map +1 -0
  432. package/dist/simulator/builtins/index.d.ts +7 -0
  433. package/dist/simulator/builtins/index.d.ts.map +1 -0
  434. package/dist/simulator/builtins/index.js +49 -0
  435. package/dist/simulator/builtins/index.js.map +1 -0
  436. package/dist/simulator/builtins/kv.d.ts +3 -0
  437. package/dist/simulator/builtins/kv.d.ts.map +1 -0
  438. package/dist/simulator/builtins/kv.js +39 -0
  439. package/dist/simulator/builtins/kv.js.map +1 -0
  440. package/dist/simulator/builtins/neopixel.d.ts +3 -0
  441. package/dist/simulator/builtins/neopixel.d.ts.map +1 -0
  442. package/dist/simulator/builtins/neopixel.js +15 -0
  443. package/dist/simulator/builtins/neopixel.js.map +1 -0
  444. package/dist/simulator/builtins/nvs-kv.d.ts +3 -0
  445. package/dist/simulator/builtins/nvs-kv.d.ts.map +1 -0
  446. package/dist/simulator/builtins/nvs-kv.js +69 -0
  447. package/dist/simulator/builtins/nvs-kv.js.map +1 -0
  448. package/dist/simulator/builtins/pin.d.ts +3 -0
  449. package/dist/simulator/builtins/pin.d.ts.map +1 -0
  450. package/dist/simulator/builtins/pin.js +32 -0
  451. package/dist/simulator/builtins/pin.js.map +1 -0
  452. package/dist/simulator/builtins/pwm.d.ts +3 -0
  453. package/dist/simulator/builtins/pwm.d.ts.map +1 -0
  454. package/dist/simulator/builtins/pwm.js +31 -0
  455. package/dist/simulator/builtins/pwm.js.map +1 -0
  456. package/dist/simulator/builtins/sleep.d.ts +3 -0
  457. package/dist/simulator/builtins/sleep.d.ts.map +1 -0
  458. package/dist/simulator/builtins/sleep.js +33 -0
  459. package/dist/simulator/builtins/sleep.js.map +1 -0
  460. package/dist/simulator/builtins/sntp.d.ts +3 -0
  461. package/dist/simulator/builtins/sntp.d.ts.map +1 -0
  462. package/dist/simulator/builtins/sntp.js +14 -0
  463. package/dist/simulator/builtins/sntp.js.map +1 -0
  464. package/dist/simulator/builtins/spi.d.ts +3 -0
  465. package/dist/simulator/builtins/spi.d.ts.map +1 -0
  466. package/dist/simulator/builtins/spi.js +16 -0
  467. package/dist/simulator/builtins/spi.js.map +1 -0
  468. package/dist/simulator/builtins/types.d.ts +24 -0
  469. package/dist/simulator/builtins/types.d.ts.map +1 -0
  470. package/dist/simulator/builtins/types.js +2 -0
  471. package/dist/simulator/builtins/types.js.map +1 -0
  472. package/dist/simulator/builtins/uart.d.ts +3 -0
  473. package/dist/simulator/builtins/uart.d.ts.map +1 -0
  474. package/dist/simulator/builtins/uart.js +22 -0
  475. package/dist/simulator/builtins/uart.js.map +1 -0
  476. package/dist/simulator/builtins/wifi.d.ts +3 -0
  477. package/dist/simulator/builtins/wifi.d.ts.map +1 -0
  478. package/dist/simulator/builtins/wifi.js +55 -0
  479. package/dist/simulator/builtins/wifi.js.map +1 -0
  480. package/dist/simulator/devRunner.d.ts +41 -0
  481. package/dist/simulator/devRunner.d.ts.map +1 -0
  482. package/dist/simulator/devRunner.js +201 -0
  483. package/dist/simulator/devRunner.js.map +1 -0
  484. package/dist/simulator/loadSimStubs.d.ts +15 -0
  485. package/dist/simulator/loadSimStubs.d.ts.map +1 -0
  486. package/dist/simulator/loadSimStubs.js +54 -0
  487. package/dist/simulator/loadSimStubs.js.map +1 -0
  488. package/dist/simulator/simProcess.d.ts +11 -0
  489. package/dist/simulator/simProcess.d.ts.map +1 -0
  490. package/dist/simulator/simProcess.js +957 -0
  491. package/dist/simulator/simProcess.js.map +1 -0
  492. package/dist/simulator/simTemplates.d.ts +6 -0
  493. package/dist/simulator/simTemplates.d.ts.map +1 -0
  494. package/dist/simulator/simTemplates.js +21 -0
  495. package/dist/simulator/simTemplates.js.map +1 -0
  496. package/package.json +123 -2
  497. package/runtime.d.ts +95 -0
@@ -0,0 +1,657 @@
1
+ import { appendFileSync, readFileSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+ import { EMPTY, merge, Subject, timer } from 'rxjs';
4
+ import { catchError, filter, first, ignoreElements, map, scan, shareReplay, startWith, switchMap, takeUntil, } from 'rxjs/operators';
5
+ import { getMikroDir } from '../projectRoot.js';
6
+ import { isIncomplete } from '../protocol.js';
7
+ // ── Constants ──────────────────────────────────────────────
8
+ /** All available slash commands */
9
+ const SLASH_COMMANDS = [
10
+ '/help',
11
+ '/env',
12
+ '/mem',
13
+ '/info',
14
+ '/gc',
15
+ '/pause',
16
+ '/resume',
17
+ '/time',
18
+ '/depth',
19
+ '/hidden',
20
+ '/ls',
21
+ '/cat',
22
+ '/rm',
23
+ '/df',
24
+ '/du',
25
+ '/exit',
26
+ ];
27
+ /** Context hints matched against the current input. First match wins. */
28
+ const CONTEXT_HINTS = [
29
+ { pattern: /^console\.\s*$/, hint: 'console.log() console.warn() console.error()' },
30
+ {
31
+ pattern: /^import\s/,
32
+ hint: 'import {x} from "mikrojs/module" — built-in modules: fs, sys, stdio',
33
+ },
34
+ ];
35
+ export const WELCOME_HINT = 'Enter to submit | Ctrl+D to exit | Ctrl+C to clear | /help for commands';
36
+ export const MULTILINE_HINT = 'Ctrl+Enter to submit | Enter to add line';
37
+ function historyFile() {
38
+ return join(getMikroDir(), 'history.txt');
39
+ }
40
+ const HISTORY_MAX = 200;
41
+ // ── Pure helpers ───────────────────────────────────────────
42
+ /** Find the line index and column for a cursor position in text */
43
+ export function cursorLocation(text, cursor) {
44
+ const lines = text.split('\n');
45
+ let pos = 0;
46
+ for (let i = 0; i < lines.length; i++) {
47
+ const lineLen = lines[i].length;
48
+ if (cursor <= pos + lineLen) {
49
+ return { line: i, col: cursor - pos, lineCount: lines.length };
50
+ }
51
+ pos += lineLen + 1;
52
+ }
53
+ return { line: lines.length - 1, col: 0, lineCount: lines.length };
54
+ }
55
+ /** Get the start offset of a given line index */
56
+ export function lineStartOffset(text, lineIdx) {
57
+ let pos = 0;
58
+ const lines = text.split('\n');
59
+ for (let i = 0; i < lineIdx && i < lines.length; i++) {
60
+ pos += lines[i].length + 1;
61
+ }
62
+ return pos;
63
+ }
64
+ function resolveContextHint(input) {
65
+ // Slash command autocomplete: filter matching commands as you type
66
+ if (input.startsWith('/') && !input.includes(' ') && !input.includes('\n')) {
67
+ const matches = SLASH_COMMANDS.filter((cmd) => cmd.startsWith(input));
68
+ if (matches.length > 0)
69
+ return matches.join(' ');
70
+ return null;
71
+ }
72
+ return CONTEXT_HINTS.find((h) => h.pattern.test(input))?.hint ?? null;
73
+ }
74
+ // ── History persistence ────────────────────────────────────
75
+ export function loadHistory() {
76
+ try {
77
+ return readFileSync(historyFile(), 'utf-8')
78
+ .split('\n')
79
+ .filter(Boolean)
80
+ .map((line) => line.replace(/\\n/g, '\n').replace(/\\\\/g, '\\'))
81
+ .slice(-HISTORY_MAX);
82
+ }
83
+ catch {
84
+ return [];
85
+ }
86
+ }
87
+ export function appendHistory(entry) {
88
+ try {
89
+ const escaped = entry.replace(/\\/g, '\\\\').replace(/\n/g, '\\n');
90
+ appendFileSync(historyFile(), escaped + '\n');
91
+ }
92
+ catch {
93
+ // ignore write errors
94
+ }
95
+ }
96
+ // ── Initial state ──────────────────────────────────────────
97
+ export function createInitialState(port, history = []) {
98
+ return {
99
+ connection: { type: 'connecting' },
100
+ port,
101
+ input: '',
102
+ cursor: 0,
103
+ history,
104
+ historyIdx: -1,
105
+ historyDraft: null,
106
+ showWelcome: true,
107
+ evaluating: false,
108
+ paused: false,
109
+ showTroubleshooting: false,
110
+ ctrlCPending: false,
111
+ returnPending: false,
112
+ disabled: false,
113
+ deployStatus: null,
114
+ footerError: null,
115
+ overrideHint: null,
116
+ contextHint: null,
117
+ pendingInput: null,
118
+ pendingTiming: null,
119
+ overlay: null,
120
+ events: [{ type: 'connecting', port }],
121
+ };
122
+ }
123
+ // ── Reducer ────────────────────────────────────────────────
124
+ export function reduce(state, action) {
125
+ switch (action.type) {
126
+ case 'deviceEvent':
127
+ return reduceSessionEvent(state, action.event);
128
+ case 'key':
129
+ return reduceKey(state, action.ch, action.key);
130
+ case 'setDisabled':
131
+ return [
132
+ {
133
+ ...state,
134
+ disabled: action.disabled,
135
+ deployStatus: action.disabled ? state.deployStatus : null,
136
+ // A new cycle starts fresh — clear any sticky footer error
137
+ // from the previous cycle.
138
+ footerError: action.disabled ? null : state.footerError,
139
+ },
140
+ [],
141
+ ];
142
+ case 'setDeployStatus':
143
+ return [{ ...state, deployStatus: action.message }, []];
144
+ case 'setFooterError':
145
+ return [{ ...state, footerError: action.message }, []];
146
+ case 'setError': {
147
+ const connection = { type: 'error', message: action.message };
148
+ const errorEvent = { type: 'error', text: action.message };
149
+ return [
150
+ { ...state, connection, showTroubleshooting: true, events: [...state.events, errorEvent] },
151
+ [],
152
+ ];
153
+ }
154
+ case 'showTroubleshooting':
155
+ if (state.connection.type === 'ready')
156
+ return [state, []];
157
+ return [{ ...state, showTroubleshooting: true }, []];
158
+ case 'ctrlCTimeout':
159
+ if (!state.ctrlCPending)
160
+ return [state, []];
161
+ return [{ ...state, ctrlCPending: false, overrideHint: null }, []];
162
+ case 'returnResolve':
163
+ return reduceReturnResolve(state, action);
164
+ case 'closeOverlay':
165
+ return [{ ...state, overlay: null }, []];
166
+ }
167
+ }
168
+ // ── Session event handling ─────────────────────────────────
169
+ function reduceSessionEvent(state, event) {
170
+ switch (event.type) {
171
+ case 'ready': {
172
+ if (state.connection.type === 'ready')
173
+ return [state, []];
174
+ const connection = {
175
+ type: 'ready',
176
+ chip: event.chip,
177
+ deviceId: event.id,
178
+ firmwareVersion: event.version,
179
+ };
180
+ return [
181
+ { ...state, connection, showTroubleshooting: false, events: [...state.events, event] },
182
+ [],
183
+ ];
184
+ }
185
+ case 'log':
186
+ case 'warn':
187
+ case 'error':
188
+ case 'info':
189
+ case 'debug':
190
+ return [{ ...state, events: [...state.events, event] }, []];
191
+ case 'eval_error':
192
+ return [{ ...state, evaluating: false, events: [...state.events, event] }, []];
193
+ case 'result': {
194
+ if (event.text.length > 0) {
195
+ return [{ ...state, evaluating: false, events: [...state.events, event] }, []];
196
+ }
197
+ return [{ ...state, evaluating: false }, []];
198
+ }
199
+ case 'completions': {
200
+ const result = event.result;
201
+ if (!result || result.items.length === 0)
202
+ return [state, []];
203
+ if (result.items.length === 1) {
204
+ const input = result.items[0];
205
+ return [{ ...state, input, cursor: input.length }, []];
206
+ }
207
+ return [{ ...state, events: [...state.events, event] }, []];
208
+ }
209
+ case 'prompt': {
210
+ // Flush pending input now that we have timing info from the prompt
211
+ const next = flushPendingInput({ ...state, pendingTiming: event.timing }, event);
212
+ return [next, []];
213
+ }
214
+ case 'raw':
215
+ case 'test':
216
+ return [{ ...state, events: [...state.events, event] }, []];
217
+ case 'disconnect': {
218
+ if (event.error) {
219
+ const connection = { type: 'error', message: event.error };
220
+ return [{ ...state, connection, events: [...state.events, event] }, []];
221
+ }
222
+ return [state, [{ type: 'end' }]];
223
+ }
224
+ default:
225
+ return [state, []];
226
+ }
227
+ }
228
+ function flushPendingInput(state, _trigger) {
229
+ if (!state.pendingInput)
230
+ return state;
231
+ const inputEvent = {
232
+ type: 'input',
233
+ code: state.pendingInput,
234
+ timing: state.pendingTiming ?? undefined,
235
+ };
236
+ return {
237
+ ...state,
238
+ pendingInput: null,
239
+ pendingTiming: null,
240
+ events: [...state.events, inputEvent],
241
+ };
242
+ }
243
+ // ── Key handling ───────────────────────────────────────────
244
+ function reduceKey(state, ch, key) {
245
+ // Overlay active: input goes to the overlay component, not the REPL
246
+ if (state.overlay)
247
+ return [state, []];
248
+ // Before ready: only allow exit
249
+ if (state.connection.type !== 'ready') {
250
+ if (key.ctrl && (ch === 'q' || ch === 'd'))
251
+ return [state, [{ type: 'end' }]];
252
+ return [state, []];
253
+ }
254
+ // ── Control sequences ──────────────────────────────────
255
+ if (key.ctrl && ch === 'q')
256
+ return [state, [{ type: 'exit' }, { type: 'end' }]];
257
+ if (key.ctrl && ch === 'r') {
258
+ const connection = { type: 'connecting', message: 'Restarting…' };
259
+ const event = { type: 'restarting' };
260
+ return [{ ...state, connection, events: [...state.events, event] }, [{ type: 'restart' }]];
261
+ }
262
+ if (key.ctrl && ch === 'd' && state.input === '') {
263
+ return [state, [{ type: 'exit' }, { type: 'end' }]];
264
+ }
265
+ if (key.ctrl && ch === 'c') {
266
+ return reduceCtrlC(state);
267
+ }
268
+ if (state.disabled)
269
+ return [state, []];
270
+ if (key.tab) {
271
+ const input = state.input.slice(0, state.cursor) + ' ' + state.input.slice(state.cursor);
272
+ return [{ ...state, input, cursor: state.cursor + 2, showWelcome: false }, []];
273
+ }
274
+ // ── Newline (Shift+Enter or Alt+Enter) ─────────────────
275
+ if (key.return && (key.shift || key.meta)) {
276
+ const input = state.input.slice(0, state.cursor) + '\n' + state.input.slice(state.cursor);
277
+ return [{ ...state, input, cursor: state.cursor + 1, showWelcome: false }, []];
278
+ }
279
+ // ── Submit (Ctrl+Enter) ────────────────────────────────
280
+ if (key.return && key.ctrl) {
281
+ return reduceSubmit(state);
282
+ }
283
+ // ── Enter (deferred for paste detection) ───────────────
284
+ if (key.return && !key.ctrl) {
285
+ const multiline = state.input.includes('\n');
286
+ return [{ ...state, returnPending: true }, [{ type: 'scheduleReturnResolve', multiline }]];
287
+ }
288
+ // ── Home / Ctrl+A ──────────────────────────────────────
289
+ if (key.home || (key.ctrl && ch === 'a')) {
290
+ const lineStart = state.input.lastIndexOf('\n', state.cursor - 1) + 1;
291
+ return [{ ...state, cursor: lineStart }, []];
292
+ }
293
+ // ── End / Ctrl+E ───────────────────────────────────────
294
+ if (key.end || (key.ctrl && ch === 'e')) {
295
+ let lineEnd = state.input.indexOf('\n', state.cursor);
296
+ if (lineEnd === -1)
297
+ lineEnd = state.input.length;
298
+ return [{ ...state, cursor: lineEnd }, []];
299
+ }
300
+ // ── Alt+Left / ESC b ──────────────────────────────────
301
+ if ((key.leftArrow && key.meta) || (key.meta && ch === 'b')) {
302
+ let i = state.cursor - 1;
303
+ while (i > 0 && /\W/.test(state.input[i - 1]))
304
+ i--;
305
+ while (i > 0 && /\w/.test(state.input[i - 1]))
306
+ i--;
307
+ return [{ ...state, cursor: Math.max(0, i) }, []];
308
+ }
309
+ // ── Alt+Right / ESC f ─────────────────────────────────
310
+ if ((key.rightArrow && key.meta) || (key.meta && ch === 'f')) {
311
+ let i = state.cursor;
312
+ while (i < state.input.length && /\W/.test(state.input[i]))
313
+ i++;
314
+ while (i < state.input.length && /\w/.test(state.input[i]))
315
+ i++;
316
+ return [{ ...state, cursor: i }, []];
317
+ }
318
+ // ── Arrow keys ─────────────────────────────────────────
319
+ if (key.leftArrow)
320
+ return [{ ...state, cursor: Math.max(0, state.cursor - 1) }, []];
321
+ if (key.rightArrow)
322
+ return [{ ...state, cursor: Math.min(state.input.length, state.cursor + 1) }, []];
323
+ if (key.upArrow)
324
+ return [reduceUpArrow(state), []];
325
+ if (key.downArrow)
326
+ return [reduceDownArrow(state), []];
327
+ // ── Ctrl+S — trigger deploy (Ctrl+Shift+S forces full redeploy) ─
328
+ if (key.ctrl && ch === 's') {
329
+ return [state, [{ type: 'deploy', force: key.shift }]];
330
+ }
331
+ // ── Alt+Backspace — delete previous word ───────────────
332
+ if (key.backspace && key.meta) {
333
+ let i = state.cursor - 1;
334
+ while (i > 0 && /\W/.test(state.input[i - 1]))
335
+ i--;
336
+ while (i > 0 && /\w/.test(state.input[i - 1]))
337
+ i--;
338
+ const wordStart = Math.max(0, i);
339
+ if (wordStart < state.cursor) {
340
+ const input = state.input.slice(0, wordStart) + state.input.slice(state.cursor);
341
+ return [
342
+ {
343
+ ...state,
344
+ input,
345
+ cursor: wordStart,
346
+ overrideHint: null,
347
+ contextHint: resolveContextHint(input),
348
+ },
349
+ [],
350
+ ];
351
+ }
352
+ return [state, []];
353
+ }
354
+ // ── Backspace ───────────────────────────────────────────
355
+ if (key.backspace) {
356
+ if (state.cursor > 0) {
357
+ const input = state.input.slice(0, state.cursor - 1) + state.input.slice(state.cursor);
358
+ return [
359
+ {
360
+ ...state,
361
+ input,
362
+ cursor: state.cursor - 1,
363
+ overrideHint: null,
364
+ contextHint: resolveContextHint(input),
365
+ },
366
+ [],
367
+ ];
368
+ }
369
+ return [state, []];
370
+ }
371
+ // ── Delete (forward) ───────────────────────────────────
372
+ if (key.delete) {
373
+ if (state.cursor < state.input.length) {
374
+ const input = state.input.slice(0, state.cursor) + state.input.slice(state.cursor + 1);
375
+ return [
376
+ {
377
+ ...state,
378
+ input,
379
+ overrideHint: null,
380
+ contextHint: resolveContextHint(input),
381
+ },
382
+ [],
383
+ ];
384
+ }
385
+ return [state, []];
386
+ }
387
+ // ── Regular character input ────────────────────────────
388
+ if (ch && !key.ctrl && !key.meta) {
389
+ return reduceCharInput(state, ch);
390
+ }
391
+ return [state, []];
392
+ }
393
+ function reduceCtrlC(state) {
394
+ if (state.input.length > 0) {
395
+ return [
396
+ { ...state, input: '', cursor: 0, ctrlCPending: false, overrideHint: null, contextHint: null },
397
+ [],
398
+ ];
399
+ }
400
+ if (state.ctrlCPending) {
401
+ return [state, [{ type: 'exit' }, { type: 'end' }]];
402
+ }
403
+ return [
404
+ { ...state, ctrlCPending: true, overrideHint: 'Press Ctrl+C again to exit, or Ctrl+D' },
405
+ [{ type: 'scheduleCtrlCTimeout' }],
406
+ ];
407
+ }
408
+ function reduceCharInput(state, ch) {
409
+ let { input, cursor } = state;
410
+ // If Return is pending, it was a paste newline — insert \n instead of submitting
411
+ if (state.returnPending) {
412
+ input = input.slice(0, cursor) + '\n' + input.slice(cursor);
413
+ cursor++;
414
+ }
415
+ // Normalize line endings and expand tabs
416
+ const text = ch.replace(/\r\n?/g, '\n').replace(/\t/g, ' ');
417
+ input = input.slice(0, cursor) + text + input.slice(cursor);
418
+ cursor += text.length;
419
+ return [
420
+ {
421
+ ...state,
422
+ input,
423
+ cursor,
424
+ returnPending: false,
425
+ historyIdx: -1,
426
+ ctrlCPending: false,
427
+ showWelcome: false,
428
+ overrideHint: null,
429
+ contextHint: resolveContextHint(input),
430
+ },
431
+ [],
432
+ ];
433
+ }
434
+ function reduceUpArrow(state) {
435
+ const loc = cursorLocation(state.input, state.cursor);
436
+ if (loc.line > 0) {
437
+ const targetStart = lineStartOffset(state.input, loc.line - 1);
438
+ const targetLineLen = (state.input.split('\n')[loc.line - 1] ?? '').length;
439
+ return { ...state, cursor: targetStart + Math.min(loc.col, targetLineLen) };
440
+ }
441
+ if (state.cursor === 0 && state.history.length > 0) {
442
+ const historyDraft = state.historyIdx < 0 ? state.input : state.historyDraft;
443
+ const idx = state.historyIdx < 0 ? state.history.length - 1 : Math.max(0, state.historyIdx - 1);
444
+ return { ...state, historyIdx: idx, historyDraft, input: state.history[idx], cursor: 0 };
445
+ }
446
+ if (loc.line === 0 && state.cursor > 0) {
447
+ return { ...state, cursor: 0 };
448
+ }
449
+ return state;
450
+ }
451
+ function reduceDownArrow(state) {
452
+ const loc = cursorLocation(state.input, state.cursor);
453
+ if (loc.line < loc.lineCount - 1) {
454
+ const targetStart = lineStartOffset(state.input, loc.line + 1);
455
+ const targetLineLen = (state.input.split('\n')[loc.line + 1] ?? '').length;
456
+ return { ...state, cursor: targetStart + Math.min(loc.col, targetLineLen) };
457
+ }
458
+ if (loc.line === loc.lineCount - 1 && state.cursor < state.input.length) {
459
+ return { ...state, cursor: state.input.length };
460
+ }
461
+ if (state.cursor === state.input.length && state.historyIdx >= 0) {
462
+ const idx = state.historyIdx + 1;
463
+ if (idx >= state.history.length) {
464
+ return {
465
+ ...state,
466
+ historyIdx: -1,
467
+ input: state.historyDraft ?? '',
468
+ historyDraft: null,
469
+ cursor: (state.historyDraft ?? '').length,
470
+ };
471
+ }
472
+ return {
473
+ ...state,
474
+ historyIdx: idx,
475
+ input: state.history[idx],
476
+ cursor: state.history[idx].length,
477
+ };
478
+ }
479
+ return state;
480
+ }
481
+ // ── Submit ─────────────────────────────────────────────────
482
+ function reduceSubmit(state) {
483
+ if (state.disabled)
484
+ return [state, []];
485
+ const value = state.input;
486
+ // Auto-continue if expression is incomplete
487
+ if (isIncomplete(value)) {
488
+ const input = `${value}\n`;
489
+ return [{ ...state, input, cursor: input.length }, []];
490
+ }
491
+ const code = value.trim();
492
+ if (!code)
493
+ return [state, []];
494
+ const effects = [{ type: 'appendHistory', entry: code }];
495
+ const resetState = {
496
+ ...state,
497
+ history: [...state.history, code].slice(-HISTORY_MAX),
498
+ historyIdx: -1,
499
+ input: '',
500
+ cursor: 0,
501
+ };
502
+ if (code === '/env') {
503
+ return [{ ...resetState, overlay: 'env' }, effects];
504
+ }
505
+ if (code === '/exit') {
506
+ return [resetState, [...effects, { type: 'exit' }, { type: 'end' }]];
507
+ }
508
+ if (!code.includes('\n') && /^\/[a-z]+(\s|$)/i.test(code)) {
509
+ const inputEvent = { type: 'input', code };
510
+ const next = { ...resetState, events: [...resetState.events, inputEvent] };
511
+ if (code === '/pause')
512
+ return [{ ...next, paused: true }, [...effects, { type: 'directive', code }]];
513
+ if (code === '/resume')
514
+ return [{ ...next, paused: false }, [...effects, { type: 'directive', code }]];
515
+ return [next, [...effects, { type: 'directive', code }]];
516
+ }
517
+ // Eval: defer input echo until result arrives
518
+ return [
519
+ {
520
+ ...resetState,
521
+ pendingInput: code,
522
+ pendingTiming: null,
523
+ evaluating: true,
524
+ },
525
+ [...effects, { type: 'eval', code }],
526
+ ];
527
+ }
528
+ // ── Return resolve (paste detection) ───────────────────────
529
+ function reduceReturnResolve(state, _action) {
530
+ if (!state.returnPending)
531
+ return [state, []];
532
+ const next = { ...state, returnPending: false };
533
+ // Single-line: submit
534
+ if (!state.input.includes('\n')) {
535
+ return reduceSubmit(next);
536
+ }
537
+ // Multi-line: insert newline
538
+ const input = state.input.slice(0, state.cursor) + '\n' + state.input.slice(state.cursor);
539
+ return [{ ...next, input, cursor: state.cursor + 1 }, []];
540
+ }
541
+ const CONNECTION_TIMEOUT_MS = 15_000;
542
+ export function createRepl(options) {
543
+ const { session, port, onEnd, deployEnabled = true } = options;
544
+ const timeoutMs = options.timeout ?? CONNECTION_TIMEOUT_MS;
545
+ const loadHistoryFn = options.loadHistory ?? loadHistory;
546
+ const saveHistoryFn = options.saveHistory ?? appendHistory;
547
+ const actions$ = new Subject();
548
+ const deploys$ = new Subject();
549
+ const restarts$ = new Subject();
550
+ const initial = createInitialState(port, loadHistoryFn());
551
+ const sessionActions$ = session.messages$.pipe(map((event) => ({ type: 'deviceEvent', event })));
552
+ // Connection timers: restart device after 2s (in case MSG_READY was sent
553
+ // before the CLI connected), show troubleshooting after 5s, hard error
554
+ // after full timeout.
555
+ const ready$ = sessionActions$.pipe(filter((a) => a.type === 'deviceEvent' && a.event.type === 'ready'), first());
556
+ const troubleshootingTimer$ = timer(5_000).pipe(takeUntil(ready$), map(() => ({ type: 'showTroubleshooting' })));
557
+ const connectionTimeout$ = timer(timeoutMs).pipe(takeUntil(ready$), map(() => ({
558
+ type: 'setError',
559
+ message: `Connection timed out after ${timeoutMs / 1000}s`,
560
+ })));
561
+ // The device only sends MSG_READY in reply to CMD_HELLO. awaitReady$
562
+ // polls HELLO until a fresh ready arrives; we merge it as a side-effect
563
+ // (no actions emitted) so the existing 'ready' deviceEvent flow drives
564
+ // the state machine. catchError swallows the timeout because
565
+ // connectionTimeout$ above already surfaces it as a 'setError' action.
566
+ const handshakeDriver$ = session.awaitReady$(timeoutMs).pipe(catchError(() => EMPTY), ignoreElements());
567
+ // After a user-triggered restart (Ctrl+R) the device reboots and stops
568
+ // emitting MSG_READY until something polls CMD_HELLO again. Re-subscribe
569
+ // to awaitReady$ on each restart so the handshake resumes; without this
570
+ // the connection state stays in 'Restarting…' forever.
571
+ const restartHandshakeDriver$ = restarts$.pipe(switchMap(() => session.awaitReady$(timeoutMs).pipe(catchError(() => EMPTY))), ignoreElements());
572
+ const state$ = merge(sessionActions$, actions$, troubleshootingTimer$, connectionTimeout$, handshakeDriver$, restartHandshakeDriver$).pipe(scan((state, action) => {
573
+ const [nextState, effects] = reduce(state, action);
574
+ for (const effect of effects) {
575
+ handleEffect(effect);
576
+ }
577
+ return nextState;
578
+ }, initial), startWith(initial), shareReplay({ bufferSize: 1, refCount: true }));
579
+ function handleEffect(effect) {
580
+ switch (effect.type) {
581
+ case 'eval':
582
+ session.eval(effect.code);
583
+ break;
584
+ case 'directive':
585
+ session.directive(effect.code);
586
+ break;
587
+ case 'exit':
588
+ session.exit();
589
+ break;
590
+ case 'restart':
591
+ session.restart();
592
+ restarts$.next();
593
+ break;
594
+ case 'end':
595
+ onEnd();
596
+ break;
597
+ case 'deploy':
598
+ // When `deployEnabled` is false (e.g. `mikro console`), the Ctrl+S
599
+ // keybind is a no-op so it doesn't feed a Subject that nothing
600
+ // subscribes to.
601
+ if (deployEnabled)
602
+ deploys$.next({ force: effect.force });
603
+ break;
604
+ case 'appendHistory':
605
+ saveHistoryFn(effect.entry);
606
+ break;
607
+ case 'scheduleCtrlCTimeout':
608
+ setTimeout(() => actions$.next({ type: 'ctrlCTimeout' }), 3000);
609
+ break;
610
+ case 'scheduleReturnResolve':
611
+ queueMicrotask(() => actions$.next({ type: 'returnResolve' }));
612
+ break;
613
+ }
614
+ }
615
+ return {
616
+ state$,
617
+ deploys$: deploys$.asObservable(),
618
+ keyInput(ch, key) {
619
+ actions$.next({ type: 'key', ch, key });
620
+ },
621
+ setDisabled(disabled) {
622
+ actions$.next({ type: 'setDisabled', disabled });
623
+ },
624
+ setDeployStatus(message) {
625
+ actions$.next({ type: 'setDeployStatus', message });
626
+ },
627
+ setError(message) {
628
+ actions$.next({ type: 'setError', message });
629
+ },
630
+ setFooterError(message) {
631
+ actions$.next({ type: 'setFooterError', message });
632
+ },
633
+ logEvent(event) {
634
+ // For non-ReplEvent log entries (e.g. `{type: 'restarting'}`) we
635
+ // could add a dedicated action, but every caller today emits a
636
+ // ReplEvent, so routing through deviceEvent keeps the surface
637
+ // minimal. The reducer treats it the same as a real device event.
638
+ if (isReplEvent(event)) {
639
+ actions$.next({ type: 'deviceEvent', event });
640
+ }
641
+ },
642
+ closeOverlay() {
643
+ actions$.next({ type: 'closeOverlay' });
644
+ },
645
+ };
646
+ }
647
+ function isReplEvent(event) {
648
+ switch (event.type) {
649
+ case 'connecting':
650
+ case 'restarting':
651
+ case 'input':
652
+ return false;
653
+ default:
654
+ return true;
655
+ }
656
+ }
657
+ //# sourceMappingURL=replStateMachine.js.map