@kruntime/komputer 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (353) hide show
  1. package/README.md +368 -0
  2. package/dist/agent/approvals.d.ts +28 -0
  3. package/dist/agent/approvals.js +109 -0
  4. package/dist/agent/approvals.js.map +1 -0
  5. package/dist/agent/messages.d.ts +67 -0
  6. package/dist/agent/messages.js +213 -0
  7. package/dist/agent/messages.js.map +1 -0
  8. package/dist/agent/recovery.d.ts +13 -0
  9. package/dist/agent/recovery.js +112 -0
  10. package/dist/agent/recovery.js.map +1 -0
  11. package/dist/agent/session-utils.d.ts +17 -0
  12. package/dist/agent/session-utils.js +77 -0
  13. package/dist/agent/session-utils.js.map +1 -0
  14. package/dist/agent-session.d.ts +303 -0
  15. package/dist/agent-session.js +3031 -0
  16. package/dist/agent-session.js.map +1 -0
  17. package/dist/authority.d.ts +34 -0
  18. package/dist/authority.js +105 -0
  19. package/dist/authority.js.map +1 -0
  20. package/dist/content.d.ts +17 -0
  21. package/dist/content.js +69 -0
  22. package/dist/content.js.map +1 -0
  23. package/dist/cron.d.ts +20 -0
  24. package/dist/cron.js +25 -0
  25. package/dist/cron.js.map +1 -0
  26. package/dist/drive.d.ts +198 -0
  27. package/dist/drive.js +656 -0
  28. package/dist/drive.js.map +1 -0
  29. package/dist/events.d.ts +20 -0
  30. package/dist/events.js +149 -0
  31. package/dist/events.js.map +1 -0
  32. package/dist/fs-mode.d.ts +9 -0
  33. package/dist/fs-mode.js +98 -0
  34. package/dist/fs-mode.js.map +1 -0
  35. package/dist/index.d.ts +26 -0
  36. package/dist/index.js +15 -0
  37. package/dist/index.js.map +1 -0
  38. package/dist/komputer.d.ts +123 -0
  39. package/dist/komputer.js +733 -0
  40. package/dist/komputer.js.map +1 -0
  41. package/dist/kstate.d.ts +107 -0
  42. package/dist/kstate.js +529 -0
  43. package/dist/kstate.js.map +1 -0
  44. package/dist/model.d.ts +81 -0
  45. package/dist/model.js +824 -0
  46. package/dist/model.js.map +1 -0
  47. package/dist/node.d.ts +2 -0
  48. package/dist/node.js +3 -0
  49. package/dist/node.js.map +1 -0
  50. package/dist/path.d.ts +4 -0
  51. package/dist/path.js +38 -0
  52. package/dist/path.js.map +1 -0
  53. package/dist/pool.d.ts +56 -0
  54. package/dist/pool.js +172 -0
  55. package/dist/pool.js.map +1 -0
  56. package/dist/receipts.d.ts +44 -0
  57. package/dist/receipts.js +35 -0
  58. package/dist/receipts.js.map +1 -0
  59. package/dist/remote-node.d.ts +2 -0
  60. package/dist/remote-node.js +122 -0
  61. package/dist/remote-node.js.map +1 -0
  62. package/dist/remote.d.ts +84 -0
  63. package/dist/remote.js +11 -0
  64. package/dist/remote.js.map +1 -0
  65. package/dist/sandbox.d.ts +4 -0
  66. package/dist/sandbox.js +70 -0
  67. package/dist/sandbox.js.map +1 -0
  68. package/dist/shell/builtins/catalog.d.ts +6 -0
  69. package/dist/shell/builtins/catalog.js +12 -0
  70. package/dist/shell/builtins/catalog.js.map +1 -0
  71. package/dist/shell/builtins/commands/filesystem/basename.d.ts +2 -0
  72. package/dist/shell/builtins/commands/filesystem/basename.js +23 -0
  73. package/dist/shell/builtins/commands/filesystem/basename.js.map +1 -0
  74. package/dist/shell/builtins/commands/filesystem/cat.d.ts +2 -0
  75. package/dist/shell/builtins/commands/filesystem/cat.js +85 -0
  76. package/dist/shell/builtins/commands/filesystem/cat.js.map +1 -0
  77. package/dist/shell/builtins/commands/filesystem/cd.d.ts +2 -0
  78. package/dist/shell/builtins/commands/filesystem/cd.js +14 -0
  79. package/dist/shell/builtins/commands/filesystem/cd.js.map +1 -0
  80. package/dist/shell/builtins/commands/filesystem/chmod.d.ts +2 -0
  81. package/dist/shell/builtins/commands/filesystem/chmod.js +46 -0
  82. package/dist/shell/builtins/commands/filesystem/chmod.js.map +1 -0
  83. package/dist/shell/builtins/commands/filesystem/copy-directory.d.ts +4 -0
  84. package/dist/shell/builtins/commands/filesystem/copy-directory.js +48 -0
  85. package/dist/shell/builtins/commands/filesystem/copy-directory.js.map +1 -0
  86. package/dist/shell/builtins/commands/filesystem/cp.d.ts +2 -0
  87. package/dist/shell/builtins/commands/filesystem/cp.js +92 -0
  88. package/dist/shell/builtins/commands/filesystem/cp.js.map +1 -0
  89. package/dist/shell/builtins/commands/filesystem/dirname.d.ts +2 -0
  90. package/dist/shell/builtins/commands/filesystem/dirname.js +23 -0
  91. package/dist/shell/builtins/commands/filesystem/dirname.js.map +1 -0
  92. package/dist/shell/builtins/commands/filesystem/du.d.ts +2 -0
  93. package/dist/shell/builtins/commands/filesystem/du.js +93 -0
  94. package/dist/shell/builtins/commands/filesystem/du.js.map +1 -0
  95. package/dist/shell/builtins/commands/filesystem/find.d.ts +2 -0
  96. package/dist/shell/builtins/commands/filesystem/find.js +111 -0
  97. package/dist/shell/builtins/commands/filesystem/find.js.map +1 -0
  98. package/dist/shell/builtins/commands/filesystem/install.d.ts +2 -0
  99. package/dist/shell/builtins/commands/filesystem/install.js +89 -0
  100. package/dist/shell/builtins/commands/filesystem/install.js.map +1 -0
  101. package/dist/shell/builtins/commands/filesystem/ln.d.ts +2 -0
  102. package/dist/shell/builtins/commands/filesystem/ln.js +57 -0
  103. package/dist/shell/builtins/commands/filesystem/ln.js.map +1 -0
  104. package/dist/shell/builtins/commands/filesystem/ls.d.ts +2 -0
  105. package/dist/shell/builtins/commands/filesystem/ls.js +153 -0
  106. package/dist/shell/builtins/commands/filesystem/ls.js.map +1 -0
  107. package/dist/shell/builtins/commands/filesystem/mkdir.d.ts +2 -0
  108. package/dist/shell/builtins/commands/filesystem/mkdir.js +41 -0
  109. package/dist/shell/builtins/commands/filesystem/mkdir.js.map +1 -0
  110. package/dist/shell/builtins/commands/filesystem/mktemp.d.ts +2 -0
  111. package/dist/shell/builtins/commands/filesystem/mktemp.js +94 -0
  112. package/dist/shell/builtins/commands/filesystem/mktemp.js.map +1 -0
  113. package/dist/shell/builtins/commands/filesystem/mv.d.ts +2 -0
  114. package/dist/shell/builtins/commands/filesystem/mv.js +41 -0
  115. package/dist/shell/builtins/commands/filesystem/mv.js.map +1 -0
  116. package/dist/shell/builtins/commands/filesystem/pwd.d.ts +2 -0
  117. package/dist/shell/builtins/commands/filesystem/pwd.js +2 -0
  118. package/dist/shell/builtins/commands/filesystem/pwd.js.map +1 -0
  119. package/dist/shell/builtins/commands/filesystem/realpath.d.ts +3 -0
  120. package/dist/shell/builtins/commands/filesystem/realpath.js +61 -0
  121. package/dist/shell/builtins/commands/filesystem/realpath.js.map +1 -0
  122. package/dist/shell/builtins/commands/filesystem/rm.d.ts +2 -0
  123. package/dist/shell/builtins/commands/filesystem/rm.js +38 -0
  124. package/dist/shell/builtins/commands/filesystem/rm.js.map +1 -0
  125. package/dist/shell/builtins/commands/filesystem/stat.d.ts +2 -0
  126. package/dist/shell/builtins/commands/filesystem/stat.js +141 -0
  127. package/dist/shell/builtins/commands/filesystem/stat.js.map +1 -0
  128. package/dist/shell/builtins/commands/filesystem/touch.d.ts +2 -0
  129. package/dist/shell/builtins/commands/filesystem/touch.js +143 -0
  130. package/dist/shell/builtins/commands/filesystem/touch.js.map +1 -0
  131. package/dist/shell/builtins/commands/filesystem.d.ts +2 -0
  132. package/dist/shell/builtins/commands/filesystem.js +44 -0
  133. package/dist/shell/builtins/commands/filesystem.js.map +1 -0
  134. package/dist/shell/builtins/commands/network/curl.d.ts +2 -0
  135. package/dist/shell/builtins/commands/network/curl.js +25 -0
  136. package/dist/shell/builtins/commands/network/curl.js.map +1 -0
  137. package/dist/shell/builtins/commands/network/http.d.ts +27 -0
  138. package/dist/shell/builtins/commands/network/http.js +226 -0
  139. package/dist/shell/builtins/commands/network/http.js.map +1 -0
  140. package/dist/shell/builtins/commands/network/wget.d.ts +2 -0
  141. package/dist/shell/builtins/commands/network/wget.js +32 -0
  142. package/dist/shell/builtins/commands/network/wget.js.map +1 -0
  143. package/dist/shell/builtins/commands/network.d.ts +2 -0
  144. package/dist/shell/builtins/commands/network.js +9 -0
  145. package/dist/shell/builtins/commands/network.js.map +1 -0
  146. package/dist/shell/builtins/commands/process/bg.d.ts +2 -0
  147. package/dist/shell/builtins/commands/process/bg.js +10 -0
  148. package/dist/shell/builtins/commands/process/bg.js.map +1 -0
  149. package/dist/shell/builtins/commands/process/fg.d.ts +2 -0
  150. package/dist/shell/builtins/commands/process/fg.js +14 -0
  151. package/dist/shell/builtins/commands/process/fg.js.map +1 -0
  152. package/dist/shell/builtins/commands/process/jobs.d.ts +2 -0
  153. package/dist/shell/builtins/commands/process/jobs.js +8 -0
  154. package/dist/shell/builtins/commands/process/jobs.js.map +1 -0
  155. package/dist/shell/builtins/commands/process/jobspec.d.ts +4 -0
  156. package/dist/shell/builtins/commands/process/jobspec.js +20 -0
  157. package/dist/shell/builtins/commands/process/jobspec.js.map +1 -0
  158. package/dist/shell/builtins/commands/process/kill.d.ts +2 -0
  159. package/dist/shell/builtins/commands/process/kill.js +35 -0
  160. package/dist/shell/builtins/commands/process/kill.js.map +1 -0
  161. package/dist/shell/builtins/commands/process/ps.d.ts +2 -0
  162. package/dist/shell/builtins/commands/process/ps.js +6 -0
  163. package/dist/shell/builtins/commands/process/ps.js.map +1 -0
  164. package/dist/shell/builtins/commands/process/sleep.d.ts +2 -0
  165. package/dist/shell/builtins/commands/process/sleep.js +6 -0
  166. package/dist/shell/builtins/commands/process/sleep.js.map +1 -0
  167. package/dist/shell/builtins/commands/process/wait.d.ts +2 -0
  168. package/dist/shell/builtins/commands/process/wait.js +21 -0
  169. package/dist/shell/builtins/commands/process/wait.js.map +1 -0
  170. package/dist/shell/builtins/commands/process.d.ts +2 -0
  171. package/dist/shell/builtins/commands/process.js +19 -0
  172. package/dist/shell/builtins/commands/process.js.map +1 -0
  173. package/dist/shell/builtins/commands/system/command.d.ts +2 -0
  174. package/dist/shell/builtins/commands/system/command.js +42 -0
  175. package/dist/shell/builtins/commands/system/command.js.map +1 -0
  176. package/dist/shell/builtins/commands/system/date.d.ts +2 -0
  177. package/dist/shell/builtins/commands/system/date.js +121 -0
  178. package/dist/shell/builtins/commands/system/date.js.map +1 -0
  179. package/dist/shell/builtins/commands/system/env.d.ts +2 -0
  180. package/dist/shell/builtins/commands/system/env.js +84 -0
  181. package/dist/shell/builtins/commands/system/env.js.map +1 -0
  182. package/dist/shell/builtins/commands/system/export.d.ts +2 -0
  183. package/dist/shell/builtins/commands/system/export.js +18 -0
  184. package/dist/shell/builtins/commands/system/export.js.map +1 -0
  185. package/dist/shell/builtins/commands/system/false.d.ts +2 -0
  186. package/dist/shell/builtins/commands/system/false.js +4 -0
  187. package/dist/shell/builtins/commands/system/false.js.map +1 -0
  188. package/dist/shell/builtins/commands/system/help.d.ts +2 -0
  189. package/dist/shell/builtins/commands/system/help.js +38 -0
  190. package/dist/shell/builtins/commands/system/help.js.map +1 -0
  191. package/dist/shell/builtins/commands/system/hostname.d.ts +2 -0
  192. package/dist/shell/builtins/commands/system/hostname.js +6 -0
  193. package/dist/shell/builtins/commands/system/hostname.js.map +1 -0
  194. package/dist/shell/builtins/commands/system/id.d.ts +2 -0
  195. package/dist/shell/builtins/commands/system/id.js +55 -0
  196. package/dist/shell/builtins/commands/system/id.js.map +1 -0
  197. package/dist/shell/builtins/commands/system/printenv.d.ts +2 -0
  198. package/dist/shell/builtins/commands/system/printenv.js +22 -0
  199. package/dist/shell/builtins/commands/system/printenv.js.map +1 -0
  200. package/dist/shell/builtins/commands/system/read.d.ts +2 -0
  201. package/dist/shell/builtins/commands/system/read.js +75 -0
  202. package/dist/shell/builtins/commands/system/read.js.map +1 -0
  203. package/dist/shell/builtins/commands/system/resolve-command.d.ts +3 -0
  204. package/dist/shell/builtins/commands/system/resolve-command.js +34 -0
  205. package/dist/shell/builtins/commands/system/resolve-command.js.map +1 -0
  206. package/dist/shell/builtins/commands/system/set.d.ts +2 -0
  207. package/dist/shell/builtins/commands/system/set.js +49 -0
  208. package/dist/shell/builtins/commands/system/set.js.map +1 -0
  209. package/dist/shell/builtins/commands/system/sh.d.ts +2 -0
  210. package/dist/shell/builtins/commands/system/sh.js +55 -0
  211. package/dist/shell/builtins/commands/system/sh.js.map +1 -0
  212. package/dist/shell/builtins/commands/system/source.d.ts +2 -0
  213. package/dist/shell/builtins/commands/system/source.js +42 -0
  214. package/dist/shell/builtins/commands/system/source.js.map +1 -0
  215. package/dist/shell/builtins/commands/system/test-expression.d.ts +2 -0
  216. package/dist/shell/builtins/commands/system/test-expression.js +93 -0
  217. package/dist/shell/builtins/commands/system/test-expression.js.map +1 -0
  218. package/dist/shell/builtins/commands/system/test.d.ts +4 -0
  219. package/dist/shell/builtins/commands/system/test.js +19 -0
  220. package/dist/shell/builtins/commands/system/test.js.map +1 -0
  221. package/dist/shell/builtins/commands/system/true.d.ts +2 -0
  222. package/dist/shell/builtins/commands/system/true.js +2 -0
  223. package/dist/shell/builtins/commands/system/true.js.map +1 -0
  224. package/dist/shell/builtins/commands/system/type.d.ts +2 -0
  225. package/dist/shell/builtins/commands/system/type.js +77 -0
  226. package/dist/shell/builtins/commands/system/type.js.map +1 -0
  227. package/dist/shell/builtins/commands/system/uname.d.ts +2 -0
  228. package/dist/shell/builtins/commands/system/uname.js +39 -0
  229. package/dist/shell/builtins/commands/system/uname.js.map +1 -0
  230. package/dist/shell/builtins/commands/system/unset.d.ts +2 -0
  231. package/dist/shell/builtins/commands/system/unset.js +9 -0
  232. package/dist/shell/builtins/commands/system/unset.js.map +1 -0
  233. package/dist/shell/builtins/commands/system/which.d.ts +2 -0
  234. package/dist/shell/builtins/commands/system/which.js +38 -0
  235. package/dist/shell/builtins/commands/system/which.js.map +1 -0
  236. package/dist/shell/builtins/commands/system/whoami.d.ts +2 -0
  237. package/dist/shell/builtins/commands/system/whoami.js +6 -0
  238. package/dist/shell/builtins/commands/system/whoami.js.map +1 -0
  239. package/dist/shell/builtins/commands/system.d.ts +2 -0
  240. package/dist/shell/builtins/commands/system.js +49 -0
  241. package/dist/shell/builtins/commands/system.js.map +1 -0
  242. package/dist/shell/builtins/commands/text/awk.d.ts +2 -0
  243. package/dist/shell/builtins/commands/text/awk.js +8 -0
  244. package/dist/shell/builtins/commands/text/awk.js.map +1 -0
  245. package/dist/shell/builtins/commands/text/base64.d.ts +2 -0
  246. package/dist/shell/builtins/commands/text/base64.js +69 -0
  247. package/dist/shell/builtins/commands/text/base64.js.map +1 -0
  248. package/dist/shell/builtins/commands/text/cut.d.ts +2 -0
  249. package/dist/shell/builtins/commands/text/cut.js +35 -0
  250. package/dist/shell/builtins/commands/text/cut.js.map +1 -0
  251. package/dist/shell/builtins/commands/text/diff.d.ts +2 -0
  252. package/dist/shell/builtins/commands/text/diff.js +83 -0
  253. package/dist/shell/builtins/commands/text/diff.js.map +1 -0
  254. package/dist/shell/builtins/commands/text/echo.d.ts +2 -0
  255. package/dist/shell/builtins/commands/text/echo.js +6 -0
  256. package/dist/shell/builtins/commands/text/echo.js.map +1 -0
  257. package/dist/shell/builtins/commands/text/grep.d.ts +2 -0
  258. package/dist/shell/builtins/commands/text/grep.js +123 -0
  259. package/dist/shell/builtins/commands/text/grep.js.map +1 -0
  260. package/dist/shell/builtins/commands/text/head.d.ts +2 -0
  261. package/dist/shell/builtins/commands/text/head.js +8 -0
  262. package/dist/shell/builtins/commands/text/head.js.map +1 -0
  263. package/dist/shell/builtins/commands/text/jq.d.ts +2 -0
  264. package/dist/shell/builtins/commands/text/jq.js +239 -0
  265. package/dist/shell/builtins/commands/text/jq.js.map +1 -0
  266. package/dist/shell/builtins/commands/text/printf.d.ts +2 -0
  267. package/dist/shell/builtins/commands/text/printf.js +3 -0
  268. package/dist/shell/builtins/commands/text/printf.js.map +1 -0
  269. package/dist/shell/builtins/commands/text/sed.d.ts +2 -0
  270. package/dist/shell/builtins/commands/text/sed.js +21 -0
  271. package/dist/shell/builtins/commands/text/sed.js.map +1 -0
  272. package/dist/shell/builtins/commands/text/sha256sum.d.ts +2 -0
  273. package/dist/shell/builtins/commands/text/sha256sum.js +63 -0
  274. package/dist/shell/builtins/commands/text/sha256sum.js.map +1 -0
  275. package/dist/shell/builtins/commands/text/sort.d.ts +2 -0
  276. package/dist/shell/builtins/commands/text/sort.js +134 -0
  277. package/dist/shell/builtins/commands/text/sort.js.map +1 -0
  278. package/dist/shell/builtins/commands/text/tail.d.ts +2 -0
  279. package/dist/shell/builtins/commands/text/tail.js +10 -0
  280. package/dist/shell/builtins/commands/text/tail.js.map +1 -0
  281. package/dist/shell/builtins/commands/text/tee.d.ts +2 -0
  282. package/dist/shell/builtins/commands/text/tee.js +29 -0
  283. package/dist/shell/builtins/commands/text/tee.js.map +1 -0
  284. package/dist/shell/builtins/commands/text/tr.d.ts +2 -0
  285. package/dist/shell/builtins/commands/text/tr.js +3 -0
  286. package/dist/shell/builtins/commands/text/tr.js.map +1 -0
  287. package/dist/shell/builtins/commands/text/uniq.d.ts +2 -0
  288. package/dist/shell/builtins/commands/text/uniq.js +8 -0
  289. package/dist/shell/builtins/commands/text/uniq.js.map +1 -0
  290. package/dist/shell/builtins/commands/text/wc.d.ts +2 -0
  291. package/dist/shell/builtins/commands/text/wc.js +30 -0
  292. package/dist/shell/builtins/commands/text/wc.js.map +1 -0
  293. package/dist/shell/builtins/commands/text/xargs.d.ts +2 -0
  294. package/dist/shell/builtins/commands/text/xargs.js +138 -0
  295. package/dist/shell/builtins/commands/text/xargs.js.map +1 -0
  296. package/dist/shell/builtins/commands/text.d.ts +2 -0
  297. package/dist/shell/builtins/commands/text.js +41 -0
  298. package/dist/shell/builtins/commands/text.js.map +1 -0
  299. package/dist/shell/builtins/help-text.d.ts +69 -0
  300. package/dist/shell/builtins/help-text.js +381 -0
  301. package/dist/shell/builtins/help-text.js.map +1 -0
  302. package/dist/shell/builtins/path.d.ts +28 -0
  303. package/dist/shell/builtins/path.js +184 -0
  304. package/dist/shell/builtins/path.js.map +1 -0
  305. package/dist/shell/builtins/registry.d.ts +3 -0
  306. package/dist/shell/builtins/registry.js +75 -0
  307. package/dist/shell/builtins/registry.js.map +1 -0
  308. package/dist/shell/builtins/run.d.ts +4 -0
  309. package/dist/shell/builtins/run.js +29 -0
  310. package/dist/shell/builtins/run.js.map +1 -0
  311. package/dist/shell/builtins/runtime.d.ts +83 -0
  312. package/dist/shell/builtins/runtime.js +46 -0
  313. package/dist/shell/builtins/runtime.js.map +1 -0
  314. package/dist/shell/builtins/text.d.ts +90 -0
  315. package/dist/shell/builtins/text.js +970 -0
  316. package/dist/shell/builtins/text.js.map +1 -0
  317. package/dist/shell/control.d.ts +31 -0
  318. package/dist/shell/control.js +232 -0
  319. package/dist/shell/control.js.map +1 -0
  320. package/dist/shell/expansion.d.ts +30 -0
  321. package/dist/shell/expansion.js +514 -0
  322. package/dist/shell/expansion.js.map +1 -0
  323. package/dist/shell/functions.d.ts +10 -0
  324. package/dist/shell/functions.js +108 -0
  325. package/dist/shell/functions.js.map +1 -0
  326. package/dist/shell/runtime.d.ts +44 -0
  327. package/dist/shell/runtime.js +276 -0
  328. package/dist/shell/runtime.js.map +1 -0
  329. package/dist/shell/time.d.ts +1 -0
  330. package/dist/shell/time.js +68 -0
  331. package/dist/shell/time.js.map +1 -0
  332. package/dist/state-backend.d.ts +61 -0
  333. package/dist/state-backend.js +275 -0
  334. package/dist/state-backend.js.map +1 -0
  335. package/dist/state-node.d.ts +2 -0
  336. package/dist/state-node.js +266 -0
  337. package/dist/state-node.js.map +1 -0
  338. package/dist/types.d.ts +462 -0
  339. package/dist/types.js +2 -0
  340. package/dist/types.js.map +1 -0
  341. package/dist/utils.d.ts +5 -0
  342. package/dist/utils.js +117 -0
  343. package/dist/utils.js.map +1 -0
  344. package/dist/vbash.d.ts +40 -0
  345. package/dist/vbash.js +389 -0
  346. package/dist/vbash.js.map +1 -0
  347. package/dist/vfs.d.ts +64 -0
  348. package/dist/vfs.js +248 -0
  349. package/dist/vfs.js.map +1 -0
  350. package/dist/vprocess.d.ts +139 -0
  351. package/dist/vprocess.js +756 -0
  352. package/dist/vprocess.js.map +1 -0
  353. package/package.json +28 -0
package/dist/drive.js ADDED
@@ -0,0 +1,656 @@
1
+ import { KState, normalizeKPath } from "./kstate.js";
2
+ import { joinPath, relativePath } from "./path.js";
3
+ export const MOUNT_REGISTRY_PATH = '/meta/mounts.jsonl';
4
+ export function ro(source) {
5
+ return { kind: 'mount-binding', source, mode: 'ro' };
6
+ }
7
+ export function rw(source) {
8
+ return { kind: 'mount-binding', source, mode: 'rw' };
9
+ }
10
+ export class MountTable {
11
+ entries = new Map();
12
+ constructor(rootDrive) {
13
+ this.mount('/', rootDrive);
14
+ }
15
+ mount(path, drive, options = {}) {
16
+ const kPath = normalizeKPath(path);
17
+ if (this.entries.has(kPath))
18
+ throw new Error(`drive already mounted at ${kPath}`);
19
+ const mode = options.mode ?? 'rw';
20
+ this.entries.set(kPath, { drive, mode, mounted: false });
21
+ }
22
+ has(path) {
23
+ return this.entries.has(normalizeKPath(path));
24
+ }
25
+ async unmount(path) {
26
+ const kPath = normalizeKPath(path);
27
+ const entry = this.entries.get(kPath);
28
+ if (!entry)
29
+ return;
30
+ this.entries.delete(kPath);
31
+ if (!entry.mounted)
32
+ return;
33
+ await entry.drive.unmount?.();
34
+ entry.mounted = false;
35
+ }
36
+ async activate() {
37
+ for (const [path, entry] of this.entries.entries()) {
38
+ if (entry.mounted)
39
+ continue;
40
+ await entry.drive.mount?.({
41
+ path,
42
+ mode: entry.mode,
43
+ });
44
+ entry.mounted = true;
45
+ }
46
+ }
47
+ async unmountAll() {
48
+ const entries = [...this.entries.values()].reverse();
49
+ for (const entry of entries) {
50
+ if (!entry.mounted)
51
+ continue;
52
+ await entry.drive.unmount?.();
53
+ entry.mounted = false;
54
+ }
55
+ }
56
+ list() {
57
+ return [...this.entries.entries()]
58
+ .map(([path, entry]) => ({ path, drive: entry.drive, mode: entry.mode }))
59
+ .sort((a, b) => a.path.localeCompare(b.path));
60
+ }
61
+ childMounts(path) {
62
+ const parent = normalizeKPath(path);
63
+ return this.list().filter((entry) => {
64
+ if (entry.path === '/' || entry.path === parent)
65
+ return false;
66
+ return dirnameOf(entry.path) === parent;
67
+ });
68
+ }
69
+ hasDescendant(path) {
70
+ const parent = normalizeKPath(path);
71
+ const prefix = parent === '/' ? '/' : `${parent}/`;
72
+ return this.list().some((entry) => entry.path !== parent && entry.path.startsWith(prefix));
73
+ }
74
+ resolve(path) {
75
+ const kPath = normalizeKPath(path);
76
+ const matches = [...this.entries.entries()]
77
+ .filter(([mountPath]) => kPath === mountPath || kPath.startsWith(`${mountPath.replace(/\/$/, '')}/`) || mountPath === '/')
78
+ .sort((a, b) => b[0].length - a[0].length);
79
+ const [mountPath, entry] = matches[0] ?? [];
80
+ if (!mountPath || !entry)
81
+ throw new Error(`no drive mounted for path: ${kPath}`);
82
+ const drive = entry.drive;
83
+ const drivePath = mountPath === '/'
84
+ ? kPath
85
+ : `/${relativePath(mountPath, kPath)}`;
86
+ return { mountPath, drivePath: normalizeKPath(drivePath), drive, mode: entry.mode };
87
+ }
88
+ realPath(path) {
89
+ const resolved = this.resolve(path);
90
+ return resolved.drive.realPath?.(resolved.drivePath);
91
+ }
92
+ }
93
+ function dirnameOf(path) {
94
+ const normalized = normalizeKPath(path);
95
+ if (normalized === '/')
96
+ return '/';
97
+ const index = normalized.lastIndexOf('/');
98
+ return index <= 0 ? '/' : normalized.slice(0, index);
99
+ }
100
+ export function basenameOf(path) {
101
+ const normalized = normalizeKPath(path);
102
+ if (normalized === '/')
103
+ return '/';
104
+ return normalized.slice(normalized.lastIndexOf('/') + 1);
105
+ }
106
+ export class KStateDrive {
107
+ kind = 'drive';
108
+ name;
109
+ prefix;
110
+ kstate;
111
+ constructor(kstate, { name = 'kstate', prefix = '/' } = {}) {
112
+ this.kstate = kstate;
113
+ this.name = name;
114
+ this.prefix = normalizeKPath(prefix);
115
+ }
116
+ async readText(path) {
117
+ return this.kstate.readText(this.fullPath(path));
118
+ }
119
+ async writeText(path, text) {
120
+ await this.kstate.writeText(this.fullPath(path), text);
121
+ }
122
+ async mkdir(path) {
123
+ await this.kstate.mkdir(this.fullPath(path));
124
+ }
125
+ async rm(path, options = {}) {
126
+ await this.kstate.rm(this.fullPath(path), options);
127
+ }
128
+ async rename(from, to) {
129
+ await this.kstate.rename(this.fullPath(from), this.fullPath(to));
130
+ }
131
+ async symlink(target, path) {
132
+ await this.kstate.symlink(target, this.fullPath(path));
133
+ }
134
+ async readLink(path) {
135
+ return this.kstate.readLink(this.fullPath(path));
136
+ }
137
+ async chmod(path, mode) {
138
+ await this.kstate.chmod(this.fullPath(path), mode);
139
+ }
140
+ async utime(path, mtime) {
141
+ await this.kstate.utime(this.fullPath(path), mtime);
142
+ }
143
+ async exists(path) {
144
+ return this.kstate.exists(this.fullPath(path));
145
+ }
146
+ async readdir(path) {
147
+ return this.kstate.readdir(this.fullPath(path));
148
+ }
149
+ async stat(path) {
150
+ return this.kstate.stat(this.fullPath(path));
151
+ }
152
+ fullPath(path = '/') {
153
+ const subPath = normalizeKPath(path);
154
+ return this.prefix === '/'
155
+ ? subPath
156
+ : normalizeKPath(joinPath(this.prefix, subPath.slice(1)));
157
+ }
158
+ realPath(path = '/') {
159
+ return this.kstate.realRootPath(this.fullPath(path));
160
+ }
161
+ }
162
+ export async function recordMount(kstate, record) {
163
+ await kstate.appendJsonl(MOUNT_REGISTRY_PATH, { ...record, path: normalizeKPath(record.path) });
164
+ }
165
+ export async function readMountRegistry(kstate) {
166
+ const rows = await kstate.readJsonl(MOUNT_REGISTRY_PATH);
167
+ const latest = new Map();
168
+ for (const row of rows) {
169
+ const legacy = row;
170
+ const mode = legacy.mode === 'ro' || legacy.mode === 'rw'
171
+ ? legacy.mode
172
+ : legacy.readonly ? 'ro' : 'rw';
173
+ latest.set(normalizeKPath(row.path), { ...row, mode, path: normalizeKPath(row.path) });
174
+ }
175
+ return [...latest.values()].sort((a, b) => a.path.localeCompare(b.path));
176
+ }
177
+ export class OverlayDrive {
178
+ kind = 'drive';
179
+ name;
180
+ lower;
181
+ upper;
182
+ constructor({ name = 'overlay', lower, upper }) {
183
+ this.name = name;
184
+ this.lower = lower;
185
+ this.upper = upper;
186
+ }
187
+ async readText(path) {
188
+ if (await this.isDeleted(path))
189
+ throw new Error(`file not found: ${normalizeKPath(path)}`);
190
+ if (await this.upper.exists(path))
191
+ return this.upper.readText(path);
192
+ return this.lower.readText(path);
193
+ }
194
+ async writeText(path, text) {
195
+ await this.clearTombstone(path);
196
+ await this.upper.writeText(path, text);
197
+ }
198
+ async mkdir(path) {
199
+ await this.clearTombstone(path);
200
+ await this.upper.mkdir(path);
201
+ }
202
+ async rm(path, options = {}) {
203
+ await this.upper.rm(path, { recursive: true, force: true }).catch(() => undefined);
204
+ if (!(await this.lower.exists(path)) && !options.force)
205
+ throw new Error(`file not found: ${normalizeKPath(path)}`);
206
+ await this.upper.writeText(this.tombstonePath(path), JSON.stringify({ deletedAt: new Date().toISOString(), path: normalizeKPath(path) }));
207
+ }
208
+ async rename(from, to) {
209
+ const stat = await this.stat(from);
210
+ if (stat.type !== 'file')
211
+ throw new Error('overlay rename currently supports files; copy directory contents explicitly');
212
+ const text = await this.readText(from);
213
+ await this.writeText(to, text);
214
+ await this.rm(from, { force: true });
215
+ }
216
+ async symlink(target, path) {
217
+ await this.clearTombstone(path);
218
+ if (!this.upper.symlink)
219
+ throw new Error(`drive ${this.upper.name} does not support symlink`);
220
+ await this.upper.symlink(target, path);
221
+ }
222
+ async readLink(path) {
223
+ if (await this.isDeleted(path))
224
+ return undefined;
225
+ const upperTarget = await this.upper.readLink?.(path);
226
+ if (upperTarget !== undefined)
227
+ return upperTarget;
228
+ return this.lower.readLink?.(path);
229
+ }
230
+ async chmod(path, mode) {
231
+ await this.clearTombstone(path);
232
+ if (await this.upper.exists(path)) {
233
+ await this.upper.chmod(path, mode);
234
+ return;
235
+ }
236
+ if (!(await this.lower.exists(path)))
237
+ throw new Error(`file not found: ${normalizeKPath(path)}`);
238
+ const stat = await this.lower.stat?.(path);
239
+ if (stat?.type === 'symlink') {
240
+ const target = await this.lower.readLink?.(path);
241
+ if (target === undefined)
242
+ throw new Error(`file not found: ${normalizeKPath(path)}`);
243
+ await this.chmod(resolveRelativeDrivePath(path, target), mode);
244
+ return;
245
+ }
246
+ if (stat?.type === 'dir') {
247
+ await this.upper.mkdir(path);
248
+ await this.upper.chmod(path, mode);
249
+ return;
250
+ }
251
+ const text = await this.lower.readText(path);
252
+ await this.upper.writeText(path, text);
253
+ await this.upper.chmod(path, mode);
254
+ }
255
+ async utime(path, mtime) {
256
+ await this.clearTombstone(path);
257
+ if (await this.upper.exists(path)) {
258
+ await this.upper.utime(path, mtime);
259
+ return;
260
+ }
261
+ if (!(await this.lower.exists(path)))
262
+ throw new Error(`file not found: ${normalizeKPath(path)}`);
263
+ const stat = await this.lower.stat?.(path);
264
+ if (stat?.type === 'symlink') {
265
+ const target = await this.lower.readLink?.(path);
266
+ if (target === undefined)
267
+ throw new Error(`file not found: ${normalizeKPath(path)}`);
268
+ await this.utime(resolveRelativeDrivePath(path, target), mtime);
269
+ return;
270
+ }
271
+ if (stat?.type === 'dir') {
272
+ await this.upper.mkdir(path);
273
+ await this.upper.utime(path, mtime);
274
+ return;
275
+ }
276
+ const text = await this.lower.readText(path);
277
+ await this.upper.writeText(path, text);
278
+ await this.upper.utime(path, mtime);
279
+ }
280
+ async exists(path) {
281
+ if (await this.isDeleted(path))
282
+ return false;
283
+ return (await this.upper.exists(path)) || this.lower.exists(path);
284
+ }
285
+ async readdir(path) {
286
+ if (await this.isDeleted(path))
287
+ throw new Error(`file not found: ${normalizeKPath(path)}`);
288
+ const entries = new Map();
289
+ const lowerEntries = await this.lower.readdir(path).catch(() => []);
290
+ const upperEntries = await this.upper.readdir(path).catch(() => []);
291
+ for (const entry of lowerEntries)
292
+ entries.set(entry.name, entry.type);
293
+ for (const entry of upperEntries) {
294
+ if (entry.name === '.k-overlay')
295
+ continue;
296
+ entries.set(entry.name, entry.type);
297
+ }
298
+ for (const entry of [...entries.keys()]) {
299
+ if (await this.isDeleted(joinPath(path, entry)))
300
+ entries.delete(entry);
301
+ }
302
+ return [...entries.entries()].map(([name, type]) => ({ name, type }));
303
+ }
304
+ async stat(path) {
305
+ if (await this.isDeleted(path))
306
+ throw new Error(`file not found: ${normalizeKPath(path)}`);
307
+ if (await this.upper.exists(path))
308
+ return this.upper.stat(path);
309
+ if (!this.lower.stat) {
310
+ if (await this.lower.exists(path))
311
+ return { type: 'file' };
312
+ throw new Error(`file not found: ${normalizeKPath(path)}`);
313
+ }
314
+ return this.lower.stat(path);
315
+ }
316
+ tombstonePath(path) {
317
+ return normalizeKPath(joinPath('/.k-overlay/tombstones', encodeURIComponent(normalizeKPath(path))));
318
+ }
319
+ async clearTombstone(path) {
320
+ await this.upper.rm(this.tombstonePath(path), { force: true }).catch(() => undefined);
321
+ }
322
+ async isDeleted(path) {
323
+ let current = normalizeKPath(path);
324
+ while (current !== '/') {
325
+ if (await this.upper.exists(this.tombstonePath(current)))
326
+ return true;
327
+ current = current.split('/').slice(0, -1).join('/') || '/';
328
+ }
329
+ return false;
330
+ }
331
+ }
332
+ export class ReadonlyDrive {
333
+ kind = 'drive';
334
+ name;
335
+ inner;
336
+ constructor(inner, name = `readonly:${inner.name || 'drive'}`) {
337
+ this.inner = inner;
338
+ this.name = name;
339
+ }
340
+ mount(ctx) {
341
+ return this.inner.mount?.({ ...ctx, mode: 'ro' });
342
+ }
343
+ unmount() {
344
+ return this.inner.unmount?.();
345
+ }
346
+ readText(path) {
347
+ return this.inner.readText(path);
348
+ }
349
+ exists(path) {
350
+ return this.inner.exists(path);
351
+ }
352
+ readdir(path) {
353
+ return this.inner.readdir(path);
354
+ }
355
+ stat(path) {
356
+ if (!this.inner.stat)
357
+ return this.inner.exists(path).then((exists) => {
358
+ if (!exists)
359
+ throw new Error(`file not found: ${normalizeKPath(path)}`);
360
+ return { type: 'file' };
361
+ });
362
+ return this.inner.stat(path);
363
+ }
364
+ readLink(path) {
365
+ return this.inner.readLink ? this.inner.readLink(path) : Promise.resolve(undefined);
366
+ }
367
+ realPath(path) {
368
+ return this.inner.realPath?.(path);
369
+ }
370
+ }
371
+ export class MemoryDrive {
372
+ kind = 'drive';
373
+ name;
374
+ files = new Map();
375
+ symlinks = new Map();
376
+ modes = new Map();
377
+ mtimes = new Map();
378
+ constructor(tree = {}, { name = 'memory' } = {}) {
379
+ this.name = name;
380
+ this.loadTree('/', tree);
381
+ }
382
+ async readText(path) {
383
+ const kPath = this.resolveSymlinks(path, true);
384
+ const text = this.files.get(kPath);
385
+ if (text === undefined)
386
+ throw new Error(`file not found: ${kPath}`);
387
+ return text;
388
+ }
389
+ async writeText(path, text) {
390
+ const kPath = this.resolveSymlinks(path, true);
391
+ this.files.set(kPath, text);
392
+ if (!this.modes.has(kPath))
393
+ this.modes.set(kPath, 0o644);
394
+ this.mtimes.set(kPath, new Date().toISOString());
395
+ }
396
+ async rm(path, options = {}) {
397
+ const kPath = this.resolveSymlinks(path, false);
398
+ if (this.symlinks.delete(kPath)) {
399
+ this.modes.delete(kPath);
400
+ this.mtimes.delete(kPath);
401
+ return;
402
+ }
403
+ if (this.files.delete(kPath)) {
404
+ this.modes.delete(kPath);
405
+ this.mtimes.delete(kPath);
406
+ return;
407
+ }
408
+ const prefix = `${kPath.replace(/\/$/, '')}/`;
409
+ const matches = [...this.files.keys()].filter((file) => file.startsWith(prefix));
410
+ if (!matches.length) {
411
+ if (options.force)
412
+ return;
413
+ throw new Error(`file not found: ${kPath}`);
414
+ }
415
+ if (!options.recursive)
416
+ throw new Error(`directory not empty: ${kPath}`);
417
+ for (const file of matches) {
418
+ this.files.delete(file);
419
+ this.modes.delete(file);
420
+ this.mtimes.delete(file);
421
+ }
422
+ }
423
+ async rename(from, to) {
424
+ const source = this.resolveSymlinks(from, false);
425
+ const target = this.resolveSymlinks(to, false);
426
+ const link = this.symlinks.get(source);
427
+ if (link !== undefined) {
428
+ this.symlinks.delete(source);
429
+ this.symlinks.set(target, link);
430
+ this.moveMode(source, target);
431
+ this.moveMtime(source, target);
432
+ return;
433
+ }
434
+ if (this.files.has(source)) {
435
+ const value = this.files.get(source) ?? '';
436
+ this.files.delete(source);
437
+ this.files.set(target, value);
438
+ this.moveMode(source, target);
439
+ this.moveMtime(source, target);
440
+ return;
441
+ }
442
+ const sourcePrefix = `${source.replace(/\/$/, '')}/`;
443
+ const targetPrefix = `${target.replace(/\/$/, '')}/`;
444
+ const matches = [...this.files.entries()].filter(([file]) => file.startsWith(sourcePrefix));
445
+ if (!matches.length)
446
+ throw new Error(`file not found: ${source}`);
447
+ for (const [file, value] of matches) {
448
+ this.files.delete(file);
449
+ this.files.set(`${targetPrefix}${file.slice(sourcePrefix.length)}`, value);
450
+ this.moveMode(file, `${targetPrefix}${file.slice(sourcePrefix.length)}`);
451
+ this.moveMtime(file, `${targetPrefix}${file.slice(sourcePrefix.length)}`);
452
+ }
453
+ }
454
+ async exists(path) {
455
+ const noFollow = this.resolveSymlinks(path, false);
456
+ if (this.symlinks.has(noFollow))
457
+ return true;
458
+ const kPath = this.resolveSymlinks(path, true);
459
+ if (this.files.has(kPath))
460
+ return true;
461
+ const prefix = `${kPath.replace(/\/$/, '')}/`;
462
+ return [...this.files.keys()].some((file) => file.startsWith(prefix));
463
+ }
464
+ async readdir(path) {
465
+ const kPath = this.resolveSymlinks(path, true);
466
+ const prefix = kPath === '/' ? '/' : `${kPath.replace(/\/$/, '')}/`;
467
+ const names = new Map();
468
+ for (const file of this.files.keys()) {
469
+ if (!file.startsWith(prefix))
470
+ continue;
471
+ const rest = file.slice(prefix.length);
472
+ if (!rest)
473
+ continue;
474
+ const [name, ...tail] = rest.split('/');
475
+ if (!name)
476
+ continue;
477
+ names.set(name, tail.length ? 'dir' : 'file');
478
+ }
479
+ for (const linkPath of this.symlinks.keys()) {
480
+ if (linkPath.startsWith(prefix)) {
481
+ const rest = linkPath.slice(prefix.length);
482
+ const [name, ...tail] = rest.split('/');
483
+ if (name)
484
+ names.set(name, tail.length ? 'dir' : 'symlink');
485
+ }
486
+ }
487
+ return [...names.entries()].map(([name, type]) => ({ name, type }));
488
+ }
489
+ async stat(path) {
490
+ const noFollow = this.resolveSymlinks(path, false);
491
+ const link = this.symlinks.get(noFollow);
492
+ if (link !== undefined)
493
+ return { type: 'symlink', size: new TextEncoder().encode(link).byteLength, mode: this.modes.get(noFollow) ?? 0o777, mtime: this.mtimes.get(noFollow) };
494
+ const kPath = this.resolveSymlinks(path, true);
495
+ if (this.files.has(kPath))
496
+ return { type: 'file', size: this.files.get(kPath)?.length ?? 0, mode: this.modes.get(kPath) ?? 0o644, mtime: this.mtimes.get(kPath) };
497
+ if (await this.exists(kPath))
498
+ return { type: 'dir', mode: this.modes.get(kPath) ?? 0o755, mtime: this.mtimes.get(kPath) };
499
+ throw new Error(`file not found: ${kPath}`);
500
+ }
501
+ async chmod(path, mode) {
502
+ const noFollow = this.resolveSymlinks(path, false);
503
+ const kPath = this.symlinks.has(noFollow) ? this.resolveSymlinks(path, true) : noFollow;
504
+ if (!await this.exists(kPath))
505
+ throw new Error(`file not found: ${kPath}`);
506
+ this.modes.set(kPath, mode & 0o777);
507
+ }
508
+ async utime(path, mtime) {
509
+ const noFollow = this.resolveSymlinks(path, false);
510
+ const kPath = this.symlinks.has(noFollow) ? this.resolveSymlinks(path, true) : noFollow;
511
+ if (!await this.exists(kPath))
512
+ throw new Error(`file not found: ${kPath}`);
513
+ this.mtimes.set(kPath, mtime);
514
+ }
515
+ async symlink(target, path) {
516
+ const linkPath = this.resolveSymlinks(path, false);
517
+ if (await this.exists(linkPath))
518
+ throw new Error(`file exists: ${linkPath}`);
519
+ this.symlinks.set(linkPath, target);
520
+ this.modes.set(linkPath, 0o777);
521
+ this.mtimes.set(linkPath, new Date().toISOString());
522
+ }
523
+ async readLink(path) {
524
+ return this.symlinks.get(this.resolveSymlinks(path, false));
525
+ }
526
+ loadTree(basePath, tree) {
527
+ for (const [name, value] of Object.entries(tree)) {
528
+ const child = normalizeKPath(joinPath(basePath, name));
529
+ if (typeof value === 'string') {
530
+ this.files.set(child, value);
531
+ this.modes.set(child, 0o644);
532
+ this.mtimes.set(child, new Date().toISOString());
533
+ }
534
+ else if (value instanceof Uint8Array) {
535
+ this.files.set(child, new TextDecoder().decode(value));
536
+ this.modes.set(child, 0o644);
537
+ this.mtimes.set(child, new Date().toISOString());
538
+ }
539
+ else if (value && typeof value === 'object' && !Array.isArray(value)) {
540
+ this.modes.set(child, 0o755);
541
+ this.mtimes.set(child, new Date().toISOString());
542
+ this.loadTree(child, value);
543
+ }
544
+ else {
545
+ this.files.set(child, JSON.stringify(value, null, 2));
546
+ this.modes.set(child, 0o644);
547
+ this.mtimes.set(child, new Date().toISOString());
548
+ }
549
+ }
550
+ }
551
+ moveMode(from, to) {
552
+ const mode = this.modes.get(from);
553
+ this.modes.delete(from);
554
+ if (mode !== undefined)
555
+ this.modes.set(to, mode);
556
+ }
557
+ moveMtime(from, to) {
558
+ const mtime = this.mtimes.get(from);
559
+ this.mtimes.delete(from);
560
+ if (mtime !== undefined)
561
+ this.mtimes.set(to, mtime);
562
+ }
563
+ resolveSymlinks(path, followFinal) {
564
+ let currentPath = normalizeKPath(path);
565
+ for (let depth = 0; depth < 40; depth += 1) {
566
+ const parts = currentPath.split('/').filter(Boolean);
567
+ if (!parts.length)
568
+ return '/';
569
+ let current = '/';
570
+ let changed = false;
571
+ for (let index = 0; index < parts.length; index += 1) {
572
+ current = joinPath(current, parts[index]);
573
+ const isFinal = index === parts.length - 1;
574
+ if (isFinal && !followFinal)
575
+ break;
576
+ const target = this.symlinks.get(current);
577
+ if (target === undefined)
578
+ continue;
579
+ const base = target.startsWith('/') ? target : joinPath(current.split('/').slice(0, -1).join('/') || '/', target);
580
+ const rest = parts.slice(index + 1).join('/');
581
+ currentPath = normalizeKPath(rest ? joinPath(base, rest) : base);
582
+ changed = true;
583
+ break;
584
+ }
585
+ if (!changed)
586
+ return currentPath;
587
+ }
588
+ throw new Error(`too many symbolic link levels: ${path}`);
589
+ }
590
+ }
591
+ export function memoryDrive(tree = {}, options = {}) {
592
+ const drive = new MemoryDrive(tree, { name: options.name });
593
+ return options.readonly ? new ReadonlyDrive(drive, options.name ? `${options.name}:readonly` : undefined) : drive;
594
+ }
595
+ export function overlayMountTable(kstate, sessionId, base) {
596
+ const overlayRoot = `/var/k/overlays/${encodeURIComponent(sessionId)}`;
597
+ const rootEntry = base.resolve('/');
598
+ const table = new MountTable(new OverlayDrive({
599
+ name: `overlay:${sessionId}:/`,
600
+ lower: rootEntry.drive,
601
+ upper: new KStateDrive(kstate, { name: `upper:${sessionId}:/`, prefix: `${overlayRoot}/root` }),
602
+ }));
603
+ for (const { path, drive, mode } of base.list()) {
604
+ if (path === '/')
605
+ continue;
606
+ if (drive instanceof KStateDrive) {
607
+ table.mount(path, new OverlayDrive({
608
+ name: `overlay:${sessionId}:${path}`,
609
+ lower: drive,
610
+ upper: new KStateDrive(kstate, { name: `upper:${sessionId}:${path}`, prefix: `${overlayRoot}/mounts/${encodeURIComponent(path)}` }),
611
+ }), { mode });
612
+ }
613
+ else {
614
+ table.mount(path, drive, { mode: 'ro' });
615
+ }
616
+ }
617
+ return table;
618
+ }
619
+ export function isMountBinding(value) {
620
+ return Boolean(value && typeof value === 'object'
621
+ && value.kind === 'mount-binding'
622
+ && (value.mode === 'ro' || value.mode === 'rw')
623
+ && 'source' in value);
624
+ }
625
+ export function isDrive(value) {
626
+ return Boolean(value && typeof value === 'object'
627
+ && value.kind === 'drive'
628
+ && typeof value.readText === 'function'
629
+ && typeof value.exists === 'function'
630
+ && typeof value.readdir === 'function');
631
+ }
632
+ function resolveRelativeDrivePath(path, target) {
633
+ if (target.startsWith('/'))
634
+ return normalizeKPath(target);
635
+ const base = path.split('/').slice(0, -1).join('/') || '/';
636
+ return normalizeKPath(joinPath(base, target));
637
+ }
638
+ export async function materializeFileTree(kstate, mountPath, source) {
639
+ if (typeof source === 'string') {
640
+ await kstate.writeText(mountPath, source);
641
+ return;
642
+ }
643
+ if (source instanceof Uint8Array) {
644
+ await kstate.writeText(mountPath, new TextDecoder().decode(source));
645
+ return;
646
+ }
647
+ if (source && typeof source === 'object' && !Array.isArray(source)) {
648
+ await kstate.ensureRootDir(mountPath);
649
+ for (const [name, value] of Object.entries(source)) {
650
+ await materializeFileTree(kstate, joinPath(mountPath, name), value);
651
+ }
652
+ return;
653
+ }
654
+ await kstate.writeText(mountPath, JSON.stringify(source, null, 2));
655
+ }
656
+ //# sourceMappingURL=drive.js.map