windows-development-sandbox 1.0.5 → 1.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 (368) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +22 -6
  3. package/config.example.json +17 -0
  4. package/dist/api.js +2 -1
  5. package/dist/cli/args.d.ts +20 -0
  6. package/dist/cli/args.js +35 -3
  7. package/dist/cli/colors.d.ts +24 -0
  8. package/dist/cli/colors.js +42 -0
  9. package/dist/cli/commands/agent-commands.d.ts +6 -0
  10. package/dist/cli/commands/agent-commands.js +61 -0
  11. package/dist/cli/commands/context.d.ts +2 -0
  12. package/dist/cli/commands/context.js +3 -0
  13. package/dist/cli/commands/data/clean.d.ts +15 -0
  14. package/dist/cli/commands/data/clean.js +101 -0
  15. package/dist/cli/commands/data/collect.d.ts +11 -0
  16. package/dist/cli/commands/data/collect.js +54 -0
  17. package/dist/cli/commands/data/index.d.ts +4 -0
  18. package/dist/cli/commands/data/index.js +45 -0
  19. package/dist/cli/commands/data/remove.d.ts +2 -0
  20. package/dist/cli/commands/data/remove.js +30 -0
  21. package/dist/cli/commands/index.d.ts +5 -3
  22. package/dist/cli/commands/index.js +5 -3
  23. package/dist/cli/commands/launch.d.ts +26 -2
  24. package/dist/cli/commands/launch.js +220 -39
  25. package/dist/cli/commands/maintenance.js +33 -4
  26. package/dist/cli/commands/project.d.ts +29 -0
  27. package/dist/cli/commands/project.js +63 -0
  28. package/dist/cli/commands/projects.d.ts +14 -0
  29. package/dist/cli/commands/projects.js +146 -0
  30. package/dist/cli/commands/repair/checks.d.ts +2 -0
  31. package/dist/cli/commands/{repair.js → repair/checks.js} +19 -181
  32. package/dist/cli/commands/{repair.d.ts → repair/finders.d.ts} +0 -29
  33. package/dist/cli/commands/repair/finders.js +108 -0
  34. package/dist/cli/commands/repair/index.d.ts +12 -0
  35. package/dist/cli/commands/repair/index.js +61 -0
  36. package/dist/cli/commands/repair/types.d.ts +26 -0
  37. package/dist/cli/commands/repair/types.js +3 -0
  38. package/dist/cli/commands/restart.d.ts +6 -0
  39. package/dist/cli/commands/restart.js +85 -0
  40. package/dist/cli/commands/sessions.d.ts +2 -1
  41. package/dist/cli/commands/sessions.js +189 -45
  42. package/dist/cli/commands/setup/checks.d.ts +13 -0
  43. package/dist/cli/commands/setup/checks.js +71 -0
  44. package/dist/cli/commands/{setup.d.ts → setup/facts.d.ts} +1 -15
  45. package/dist/cli/commands/setup/facts.js +60 -0
  46. package/dist/cli/commands/setup/index.d.ts +2 -0
  47. package/dist/cli/commands/setup/index.js +43 -0
  48. package/dist/cli/commands/user-config.d.ts +8 -0
  49. package/dist/cli/commands/user-config.js +41 -0
  50. package/dist/cli/history.d.ts +11 -0
  51. package/dist/cli/history.js +21 -0
  52. package/dist/cli/index.d.ts +7 -1
  53. package/dist/cli/index.js +38 -13
  54. package/dist/cli/manifest.d.ts +8 -0
  55. package/dist/cli/manifest.js +35 -15
  56. package/dist/cli/menu-multi.d.ts +12 -0
  57. package/dist/cli/menu-multi.js +82 -0
  58. package/dist/cli/menu.d.ts +5 -13
  59. package/dist/cli/menu.js +149 -46
  60. package/dist/cli/progress.d.ts +9 -0
  61. package/dist/cli/progress.js +49 -0
  62. package/dist/cli/settings/edit.d.ts +13 -0
  63. package/dist/cli/settings/edit.js +19 -0
  64. package/dist/cli/settings/index.d.ts +8 -0
  65. package/dist/cli/settings/index.js +131 -0
  66. package/dist/cli/settings/prompts.d.ts +7 -0
  67. package/dist/cli/settings/prompts.js +48 -0
  68. package/dist/cli/settings/schema.d.ts +33 -0
  69. package/dist/cli/settings/schema.js +29 -0
  70. package/dist/cli/validate.d.ts +17 -0
  71. package/dist/cli/validate.js +89 -0
  72. package/dist/core/config.js +4 -1
  73. package/dist/core/disk.d.ts +16 -0
  74. package/dist/core/disk.js +55 -0
  75. package/dist/core/local-config.d.ts +8 -0
  76. package/dist/core/local-config.js +18 -5
  77. package/dist/core/project-policy.d.ts +15 -0
  78. package/dist/core/project-policy.js +35 -0
  79. package/dist/core/prompt.d.ts +4 -0
  80. package/dist/core/prompt.js +15 -0
  81. package/dist/core/safe-paths.d.ts +4 -0
  82. package/dist/core/safe-paths.js +37 -0
  83. package/dist/core/schema/common.d.ts +17 -0
  84. package/dist/core/schema/common.js +15 -0
  85. package/dist/core/schema/config.d.ts +594 -0
  86. package/dist/core/schema/config.js +63 -0
  87. package/dist/core/schema/databases.d.ts +33 -0
  88. package/dist/core/schema/databases.js +35 -0
  89. package/dist/core/schema/harness.d.ts +12 -0
  90. package/dist/core/schema/harness.js +17 -0
  91. package/dist/core/schema/json-schema.d.ts +5 -0
  92. package/dist/core/schema/json-schema.js +25 -0
  93. package/dist/core/schema/profile.d.ts +27 -0
  94. package/dist/core/schema/profile.js +29 -0
  95. package/dist/core/schema/projects.d.ts +9 -0
  96. package/dist/core/schema/projects.js +11 -0
  97. package/dist/core/schema/sandbox.d.ts +50 -0
  98. package/dist/core/schema/sandbox.js +36 -0
  99. package/dist/core/schema/toolchains.d.ts +93 -0
  100. package/dist/core/schema/toolchains.js +83 -0
  101. package/dist/core/schema.d.ts +6 -604
  102. package/dist/core/schema.js +8 -264
  103. package/dist/core/types.d.ts +29 -1
  104. package/dist/core/util.d.ts +7 -0
  105. package/dist/core/util.js +12 -3
  106. package/dist/core/workspace.d.ts +0 -5
  107. package/dist/core/workspace.js +12 -46
  108. package/dist/guest/boot-env.d.ts +4 -0
  109. package/dist/guest/boot-env.js +25 -0
  110. package/dist/guest/cmdline.d.ts +12 -0
  111. package/dist/guest/cmdline.js +23 -0
  112. package/dist/guest/daemon/exec.d.ts +5 -0
  113. package/dist/guest/daemon/exec.js +32 -0
  114. package/dist/guest/daemon/project.d.ts +14 -0
  115. package/dist/guest/daemon/project.js +132 -0
  116. package/dist/guest/daemon/session.d.ts +13 -0
  117. package/dist/guest/daemon/session.js +139 -0
  118. package/dist/guest/daemon/shutdown.d.ts +1 -0
  119. package/dist/guest/daemon/shutdown.js +21 -0
  120. package/dist/guest/daemon/state.d.ts +17 -0
  121. package/dist/guest/daemon/state.js +31 -0
  122. package/dist/guest/daemon.js +8 -141
  123. package/dist/guest/db.js +18 -3
  124. package/dist/guest/env.d.ts +2 -0
  125. package/dist/guest/env.js +4 -2
  126. package/dist/guest/guide.d.ts +6 -2
  127. package/dist/guest/guide.js +5 -4
  128. package/dist/guest/helpers.d.ts +3 -0
  129. package/dist/guest/helpers.js +26 -0
  130. package/dist/guest/main.js +17 -7
  131. package/dist/guest/ports.d.ts +6 -0
  132. package/dist/guest/ports.js +22 -0
  133. package/dist/guest/project-context.d.ts +7 -0
  134. package/dist/guest/project-context.js +10 -0
  135. package/dist/guest/project-env.d.ts +20 -0
  136. package/dist/guest/project-env.js +20 -0
  137. package/dist/guest/project-status.d.ts +5 -0
  138. package/dist/guest/project-status.js +17 -0
  139. package/dist/guest/ptyhost.d.ts +0 -18
  140. package/dist/guest/ptyhost.js +5 -63
  141. package/dist/guest/setup/agents.d.ts +5 -2
  142. package/dist/guest/setup/agents.js +22 -8
  143. package/dist/guest/setup/claude.js +11 -3
  144. package/dist/guest/setup/environment.d.ts +13 -3
  145. package/dist/guest/setup/environment.js +14 -10
  146. package/dist/guest/setup/hooks.d.ts +9 -1
  147. package/dist/guest/setup/hooks.js +28 -14
  148. package/dist/guest/toolchains/catalogue.d.ts +4 -0
  149. package/dist/guest/toolchains/catalogue.js +2 -2
  150. package/dist/guest/toolchains/cli.js +25 -17
  151. package/dist/guest/toolchains/common.d.ts +18 -1
  152. package/dist/guest/toolchains/common.js +34 -11
  153. package/dist/guest/toolchains/databases/dynamodb.d.ts +8 -0
  154. package/dist/guest/toolchains/databases/dynamodb.js +52 -0
  155. package/dist/guest/toolchains/{databases.d.ts → databases/index.d.ts} +2 -3
  156. package/dist/guest/toolchains/databases/index.js +62 -0
  157. package/dist/guest/toolchains/databases/mongodb.d.ts +3 -0
  158. package/dist/guest/toolchains/databases/mongodb.js +31 -0
  159. package/dist/guest/toolchains/databases/mysql.d.ts +3 -0
  160. package/dist/guest/toolchains/databases/mysql.js +38 -0
  161. package/dist/guest/toolchains/databases/postgres.d.ts +5 -0
  162. package/dist/guest/toolchains/databases/postgres.js +38 -0
  163. package/dist/guest/toolchains/databases/redis.d.ts +3 -0
  164. package/dist/guest/toolchains/databases/redis.js +16 -0
  165. package/dist/guest/toolchains/databases/server.d.ts +14 -0
  166. package/dist/guest/toolchains/databases/server.js +52 -0
  167. package/dist/guest/toolchains/git.js +25 -16
  168. package/dist/guest/toolchains/go.js +1 -1
  169. package/dist/guest/toolchains/index.d.ts +13 -9
  170. package/dist/guest/toolchains/index.js +40 -82
  171. package/dist/guest/toolchains/java.js +5 -5
  172. package/dist/guest/toolchains/leftovers.d.ts +2 -0
  173. package/dist/guest/toolchains/leftovers.js +26 -0
  174. package/dist/guest/toolchains/managers.js +12 -10
  175. package/dist/guest/toolchains/{binstall.js → native/binstall.js} +6 -9
  176. package/dist/guest/toolchains/native/cpp.d.ts +4 -0
  177. package/dist/guest/toolchains/native/cpp.js +38 -0
  178. package/dist/guest/toolchains/native/dotnet.d.ts +4 -0
  179. package/dist/guest/toolchains/native/dotnet.js +103 -0
  180. package/dist/guest/toolchains/native/mesa.d.ts +7 -0
  181. package/dist/guest/toolchains/native/mesa.js +46 -0
  182. package/dist/guest/toolchains/native/msvc/environment.d.ts +16 -0
  183. package/dist/guest/toolchains/native/msvc/environment.js +57 -0
  184. package/dist/guest/toolchains/native/msvc/index.d.ts +6 -0
  185. package/dist/guest/toolchains/native/msvc/index.js +48 -0
  186. package/dist/guest/toolchains/native/msvc/packages.d.ts +6 -0
  187. package/dist/guest/toolchains/native/msvc/packages.js +156 -0
  188. package/dist/guest/toolchains/native/msvc/tree.d.ts +15 -0
  189. package/dist/guest/toolchains/native/msvc/tree.js +21 -0
  190. package/dist/guest/toolchains/native/rust.d.ts +3 -0
  191. package/dist/guest/toolchains/native/rust.js +45 -0
  192. package/dist/guest/toolchains/node.js +26 -6
  193. package/dist/guest/toolchains/plan.d.ts +22 -0
  194. package/dist/guest/toolchains/plan.js +96 -0
  195. package/dist/guest/toolchains/pwsh.js +1 -1
  196. package/dist/guest/toolchains/python.js +17 -10
  197. package/dist/guest/toolchains/runtimes.d.ts +2 -0
  198. package/dist/guest/toolchains/runtimes.js +6 -8
  199. package/dist/guest/toolchains/scripting/php.d.ts +3 -0
  200. package/dist/guest/toolchains/scripting/php.js +71 -0
  201. package/dist/guest/toolchains/scripting/ruby.d.ts +3 -0
  202. package/dist/guest/toolchains/scripting/ruby.js +47 -0
  203. package/dist/guest/toolchains/scripting/vcruntime.d.ts +7 -0
  204. package/dist/guest/toolchains/scripting/vcruntime.js +45 -0
  205. package/dist/guest/view.js +21 -1
  206. package/dist/host/accounts.js +14 -5
  207. package/dist/host/agent-commands.d.ts +25 -0
  208. package/dist/host/agent-commands.js +145 -0
  209. package/dist/host/attach.d.ts +17 -0
  210. package/dist/host/attach.js +69 -0
  211. package/dist/host/channel.d.ts +23 -22
  212. package/dist/host/channel.js +66 -84
  213. package/dist/host/claude-profile.js +7 -3
  214. package/dist/host/cleanup.js +2 -11
  215. package/dist/host/database-plan.d.ts +12 -0
  216. package/dist/host/database-plan.js +52 -0
  217. package/dist/host/generate.d.ts +4 -12
  218. package/dist/host/generate.js +48 -135
  219. package/dist/host/join.d.ts +28 -0
  220. package/dist/host/join.js +76 -0
  221. package/dist/host/launch/mappings.d.ts +3 -0
  222. package/dist/host/launch/mappings.js +50 -0
  223. package/dist/host/launch/projects.d.ts +15 -0
  224. package/dist/host/launch/projects.js +56 -0
  225. package/dist/host/launch/stage.d.ts +11 -0
  226. package/dist/host/launch/stage.js +66 -0
  227. package/dist/host/launch/wsb.d.ts +10 -0
  228. package/dist/host/launch/wsb.js +34 -0
  229. package/dist/host/pc-scan.d.ts +6 -0
  230. package/dist/host/pc-scan.js +37 -0
  231. package/dist/host/platform.d.ts +2 -0
  232. package/dist/host/platform.js +13 -1
  233. package/dist/host/project-scan.d.ts +1 -17
  234. package/dist/host/project-scan.js +2 -86
  235. package/dist/host/projects.d.ts +100 -0
  236. package/dist/host/projects.js +147 -0
  237. package/dist/host/repo-guard.d.ts +15 -2
  238. package/dist/host/repo-guard.js +103 -12
  239. package/dist/host/terminal.js +3 -0
  240. package/dist/host/test-guard.d.ts +6 -0
  241. package/dist/host/test-guard.js +15 -0
  242. package/dist/host/window.js +7 -3
  243. package/dist/host/wsb.d.ts +37 -0
  244. package/dist/host/wsb.js +101 -0
  245. package/dist/runtime/daemon.js +10997 -2794
  246. package/dist/runtime/db.js +6428 -464
  247. package/dist/runtime/main.js +7359 -1135
  248. package/dist/runtime/view.js +5922 -47
  249. package/dist/selftest/accounts.test.d.ts +2 -0
  250. package/dist/selftest/accounts.test.js +44 -0
  251. package/dist/selftest/agent-commands.test.d.ts +2 -0
  252. package/dist/selftest/agent-commands.test.js +47 -0
  253. package/dist/selftest/channel.test.d.ts +2 -0
  254. package/dist/selftest/channel.test.js +37 -0
  255. package/dist/selftest/cli.test.d.ts +2 -2
  256. package/dist/selftest/cli.test.js +115 -27
  257. package/dist/selftest/cmdline.test.d.ts +2 -0
  258. package/dist/selftest/cmdline.test.js +45 -0
  259. package/dist/selftest/config.test.d.ts +2 -3
  260. package/dist/selftest/config.test.js +36 -72
  261. package/dist/selftest/data.test.d.ts +2 -2
  262. package/dist/selftest/data.test.js +77 -70
  263. package/dist/selftest/detect.test.d.ts +2 -2
  264. package/dist/selftest/detect.test.js +54 -38
  265. package/dist/selftest/fixtures.d.ts +44 -4
  266. package/dist/selftest/fixtures.js +40 -23
  267. package/dist/selftest/generate.test.d.ts +2 -0
  268. package/dist/selftest/generate.test.js +63 -0
  269. package/dist/selftest/git-access.test.d.ts +2 -0
  270. package/dist/selftest/git-access.test.js +26 -0
  271. package/dist/selftest/guest-boot.test.d.ts +2 -0
  272. package/dist/selftest/guest-boot.test.js +76 -0
  273. package/dist/selftest/harness.d.ts +44 -7
  274. package/dist/selftest/harness.js +62 -21
  275. package/dist/selftest/host-sim.test.d.ts +2 -0
  276. package/dist/selftest/host-sim.test.js +93 -0
  277. package/dist/selftest/hostile-input.test.d.ts +2 -0
  278. package/dist/selftest/hostile-input.test.js +54 -0
  279. package/dist/selftest/index.d.ts +8 -1
  280. package/dist/selftest/index.js +134 -35
  281. package/dist/selftest/links.test.d.ts +2 -0
  282. package/dist/selftest/links.test.js +50 -0
  283. package/dist/selftest/live-daemon.test.d.ts +2 -0
  284. package/dist/selftest/live-daemon.test.js +91 -0
  285. package/dist/selftest/live-git.test.d.ts +2 -0
  286. package/dist/selftest/live-git.test.js +60 -0
  287. package/dist/selftest/live-projects.test.d.ts +2 -0
  288. package/dist/selftest/live-projects.test.js +127 -0
  289. package/dist/selftest/live.d.ts +65 -0
  290. package/dist/selftest/live.js +109 -0
  291. package/dist/selftest/local-config.test.d.ts +2 -0
  292. package/dist/selftest/local-config.test.js +107 -0
  293. package/dist/selftest/mirror.test.d.ts +2 -3
  294. package/dist/selftest/mirror.test.js +92 -65
  295. package/dist/selftest/network.test.d.ts +2 -0
  296. package/dist/selftest/network.test.js +28 -0
  297. package/dist/selftest/personalization.test.d.ts +2 -0
  298. package/dist/selftest/personalization.test.js +53 -0
  299. package/dist/selftest/projects.test.d.ts +2 -0
  300. package/dist/selftest/projects.test.js +254 -0
  301. package/dist/selftest/repair.test.d.ts +2 -0
  302. package/dist/selftest/repair.test.js +42 -0
  303. package/dist/selftest/repo-guard.test.d.ts +2 -0
  304. package/dist/selftest/repo-guard.test.js +63 -0
  305. package/dist/selftest/secrets.test.d.ts +2 -0
  306. package/dist/selftest/secrets.test.js +71 -0
  307. package/dist/selftest/setup.test.d.ts +2 -2
  308. package/dist/selftest/setup.test.js +45 -22
  309. package/dist/selftest/suite.d.ts +13 -0
  310. package/dist/selftest/suite.js +1 -0
  311. package/dist/selftest/sync.test.d.ts +2 -3
  312. package/dist/selftest/sync.test.js +90 -78
  313. package/dist/selftest/test-guard.test.d.ts +2 -0
  314. package/dist/selftest/test-guard.test.js +49 -0
  315. package/dist/selftest/toolchains.test.d.ts +2 -0
  316. package/dist/selftest/toolchains.test.js +103 -0
  317. package/dist/selftest/workspace.test.d.ts +2 -0
  318. package/dist/selftest/workspace.test.js +53 -0
  319. package/dist/shared/download.d.ts +3 -1
  320. package/dist/shared/download.js +19 -4
  321. package/dist/shared/paths.d.ts +5 -0
  322. package/dist/shared/paths.js +6 -0
  323. package/dist/shared/projects.d.ts +53 -0
  324. package/dist/shared/projects.js +67 -0
  325. package/dist/shared/rundir.d.ts +10 -1
  326. package/dist/shared/rundir.js +12 -4
  327. package/dist/shared/safe-remove.js +11 -0
  328. package/dist/shared/schema.d.ts +443 -0
  329. package/dist/shared/schema.js +41 -2
  330. package/dist/shared/test-guard.d.ts +4 -0
  331. package/dist/shared/test-guard.js +37 -0
  332. package/dist/sync/claude-mem.js +3 -1
  333. package/dist/sync/history.d.ts +23 -12
  334. package/dist/sync/history.js +52 -20
  335. package/dist/sync/watcher.d.ts +8 -0
  336. package/dist/sync/watcher.js +23 -4
  337. package/package.json +6 -6
  338. package/sandbox/bootstrap.ps1 +258 -258
  339. package/sandbox/cpucap.ps1 +51 -0
  340. package/sandbox/logon.cmd +18 -16
  341. package/sandbox/openssl.cs +42 -0
  342. package/sandbox/ptyhost.cs +15 -4
  343. package/sandbox/trust.cmd +35 -35
  344. package/schemas/config.schema.json +100 -1
  345. package/schemas/sandbox-config.schema.json +17 -1
  346. package/dist/cli/commands/data.d.ts +0 -46
  347. package/dist/cli/commands/data.js +0 -249
  348. package/dist/cli/commands/setup.js +0 -152
  349. package/dist/cli/settings.d.ts +0 -11
  350. package/dist/cli/settings.js +0 -156
  351. package/dist/guest/toolchains/databases.js +0 -226
  352. package/dist/guest/toolchains/msvc.d.ts +0 -10
  353. package/dist/guest/toolchains/msvc.js +0 -216
  354. package/dist/guest/toolchains/native.d.ts +0 -12
  355. package/dist/guest/toolchains/native.js +0 -220
  356. package/dist/guest/toolchains/scripting.d.ts +0 -10
  357. package/dist/guest/toolchains/scripting.js +0 -137
  358. package/dist/selftest/guest.test.d.ts +0 -3
  359. package/dist/selftest/guest.test.js +0 -61
  360. package/dist/selftest/helpers.test.d.ts +0 -2
  361. package/dist/selftest/helpers.test.js +0 -125
  362. package/dist/selftest/host.test.d.ts +0 -2
  363. package/dist/selftest/host.test.js +0 -71
  364. package/dist/selftest/live.test.d.ts +0 -7
  365. package/dist/selftest/live.test.js +0 -127
  366. package/dist/selftest/security.test.d.ts +0 -3
  367. package/dist/selftest/security.test.js +0 -143
  368. /package/dist/guest/toolchains/{binstall.d.ts → native/binstall.d.ts} +0 -0
@@ -1,152 +0,0 @@
1
- // `sandbox setup`: checks this PC can run Windows Sandbox and offers to turn the feature on.
2
- import fs from 'node:fs';
3
- import os from 'node:os';
4
- import path from 'node:path';
5
- import { spawnSync } from 'node:child_process';
6
- import _ from 'lodash';
7
- import { z } from 'zod';
8
- import { askYesNo } from '../../core/workspace.js';
9
- import { fail, fileExists, isWin } from '../../core/util.js';
10
- import { SYSTEM, system32 } from '../../shared/system.js';
11
- import { table } from './context.js';
12
- const FEATURE = 'Containers-DisposableClientVM';
13
- export const ENABLE_COMMAND = 'Enable-WindowsOptionalFeature -Online -FeatureName ' + FEATURE + ' -All -NoRestart';
14
- const GB = 1024 ** 3;
15
- /** `reg query <key>` output to { valueName: data }. */
16
- export const parseRegQuery = (text) => Object.fromEntries(_.compact(text.split(/\r?\n/).map((line) => /^\s+(\S+)\s+REG_\w+\s+(.*)$/.exec(line)?.slice(1, 3))));
17
- /** Windows Sandbox needs Pro, Enterprise or Education (build 18305+); Home ("Core*") and Server cannot run it. */
18
- export const editionSupport = (edition) => {
19
- if (!edition)
20
- return 'unknown';
21
- if (/^Core/i.test(edition))
22
- return 'home';
23
- if (/^Server/i.test(edition))
24
- return 'unsupported';
25
- return /^(Professional|Enterprise|Education|IoTEnterprise)/i.test(edition) ? 'supported' : 'unknown';
26
- };
27
- /** The "State : ..." line of `Dism /Get-FeatureInfo` (English output only; anything else is unknown). */
28
- export const parseDismState = (text) => {
29
- const state = /^State\s*:\s*(.+?)\s*$/im.exec(text)?.[1].toLowerCase() ?? '';
30
- if (state === 'enabled')
31
- return 'enabled';
32
- if (state.includes('pending'))
33
- return 'pending';
34
- return state.startsWith('disabled') ? 'disabled' : 'unknown';
35
- };
36
- /** Win32_OptionalFeature.InstallState: 1 enabled, 2 disabled, 3 absent. */
37
- export const featureFromInstallState = (state) => state === 1 ? 'enabled' : state === 2 || state === 3 ? 'disabled' : 'unknown';
38
- export const nodeMajor = (version) => Number(/^v?(\d+)/.exec(version.trim())?.[1] ?? 0);
39
- /** Offer to enable the feature only when it is off and this edition can have it. */
40
- export const canEnableFeature = (f) => f.feature !== 'enabled' && f.feature !== 'pending' && !f.sandboxExe && ['supported', 'unknown'].includes(editionSupport(f.edition));
41
- const formatGb = (bytes) => (bytes / GB).toFixed(1) + ' GB';
42
- /** Turns what we learnt about the PC into the checklist (pure, so it can be tested). */
43
- export const buildChecks = (f) => {
44
- const support = editionSupport(f.edition);
45
- const edition = (f.edition ?? 'unknown edition') + (f.build ? ', build ' + f.build : '');
46
- const virt = f.hypervisorPresent || f.virtualizationFirmware;
47
- const featureReady = f.feature === 'enabled' && f.sandboxExe;
48
- return [
49
- support === 'supported' && (f.build ?? 18305) >= 18305 ? { name: 'Windows edition', status: 'ok', detail: edition }
50
- : support === 'home' ? { name: 'Windows edition', status: 'action', detail: edition + ': Windows Home cannot run Windows Sandbox. Upgrade to Pro (Settings > System > Activation).' }
51
- : support === 'unsupported' ? { name: 'Windows edition', status: 'action', detail: edition + ': Windows Sandbox needs Windows 10/11 Pro, Enterprise or Education.' }
52
- : support === 'supported' ? { name: 'Windows edition', status: 'action', detail: edition + ': too old; Windows Sandbox needs Windows 10 version 1903 or newer.' }
53
- : { name: 'Windows edition', status: 'warn', detail: edition + ': not sure this edition has Windows Sandbox (it needs Pro, Enterprise or Education).' },
54
- virt ? { name: 'CPU virtualization', status: 'ok', detail: f.hypervisorPresent ? 'on (hypervisor running)' : 'on' }
55
- : virt === false ? { name: 'CPU virtualization', status: 'action', detail: 'off. Turn on Intel VT-x / AMD-V (SVM) in your PC\'s BIOS/UEFI settings, then run this again.' }
56
- : { name: 'CPU virtualization', status: 'warn', detail: 'could not tell; if Windows Sandbox will not start, turn on VT-x / AMD-V in the BIOS/UEFI.' },
57
- featureReady ? { name: 'Windows Sandbox feature', status: 'ok', detail: 'enabled' }
58
- : f.feature === 'pending' || (f.feature === 'enabled' && !f.sandboxExe) ? { name: 'Windows Sandbox feature', status: 'action', detail: 'enabled, but Windows needs a restart to finish.' }
59
- : f.sandboxExe ? { name: 'Windows Sandbox feature', status: 'ok', detail: 'installed' }
60
- : { name: 'Windows Sandbox feature', status: 'action', detail: 'not enabled. In an admin PowerShell: ' + ENABLE_COMMAND + ', then restart.' },
61
- { name: 'Memory', status: f.totalRamBytes < 4 * GB ? 'action' : f.totalRamBytes < 8 * GB ? 'warn' : 'ok', detail: formatGb(f.totalRamBytes) + (f.totalRamBytes < 4 * GB ? ': Windows Sandbox needs at least 4 GB.' : f.totalRamBytes < 8 * GB ? ': works, but 8 GB or more is recommended.' : '') },
62
- f.freeDiskBytes === null ? { name: 'Free disk', status: 'warn', detail: 'could not check the drive of ' + f.storageRoot }
63
- : { name: 'Free disk', status: f.freeDiskBytes < 5 * GB ? 'action' : f.freeDiskBytes < 20 * GB ? 'warn' : 'ok', detail: formatGb(f.freeDiskBytes) + ' free for ' + f.storageRoot + (f.freeDiskBytes < 5 * GB ? ': free up space (toolchains need several GB).' : f.freeDiskBytes < 20 * GB ? ': getting low; toolchains and caches can use several GB.' : '') },
64
- nodeMajor(f.nodeVersion) >= 20 ? { name: 'Node.js', status: 'ok', detail: f.nodeVersion } : { name: 'Node.js', status: 'action', detail: f.nodeVersion + ': needs 20 or newer (winget install OpenJS.NodeJS.LTS).' },
65
- ];
66
- };
67
- // Fixed script (no outside data): CPU/hypervisor facts and the feature state, readable without admin rights.
68
- const PROBE = [
69
- '$ErrorActionPreference = "SilentlyContinue"',
70
- '$cpu = @(Get-CimInstance Win32_Processor)',
71
- '$cs = Get-CimInstance Win32_ComputerSystem',
72
- '$f = Get-CimInstance Win32_OptionalFeature -Filter "Name=\'' + FEATURE + '\'"',
73
- '$v = $null; if ($cpu.Count) { $v = [bool]($cpu | Where-Object { $_.VirtualizationFirmwareEnabled }) }',
74
- '$h = $null; if ($cs) { $h = [bool]$cs.HypervisorPresent }',
75
- '$s = $null; if ($f) { $s = [int]$f.InstallState }',
76
- '@{ virtualizationFirmware = $v; hypervisorPresent = $h; installState = $s } | ConvertTo-Json -Compress',
77
- ].join('; ');
78
- const Probe = z.object({ virtualizationFirmware: z.boolean().nullable(), hypervisorPresent: z.boolean().nullable(), installState: z.number().nullable() }).partial();
79
- export const parseProbe = (text) => {
80
- try {
81
- return Probe.parse(JSON.parse(_.last(text.trim().split(/\r?\n/)) ?? ''));
82
- }
83
- catch {
84
- return {};
85
- }
86
- };
87
- const run = (exe, args) => {
88
- const r = spawnSync(exe, args, { encoding: 'utf8', windowsHide: true, timeout: 60000 });
89
- return r.status === 0 ? r.stdout : '';
90
- };
91
- const freeDisk = (dir) => {
92
- let at = path.resolve(dir);
93
- while (!fs.existsSync(at) && path.dirname(at) !== at)
94
- at = path.dirname(at);
95
- try {
96
- const s = fs.statfsSync(at);
97
- return s.bavail * s.bsize;
98
- }
99
- catch {
100
- return null;
101
- }
102
- };
103
- const gatherFacts = (storageRoot) => {
104
- const reg = parseRegQuery(run(SYSTEM.reg(), ['query', 'HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion']));
105
- const probe = parseProbe(run(SYSTEM.powershell(), ['-NoProfile', '-NonInteractive', '-Command', PROBE]));
106
- // DISM knows about a pending restart but needs admin rights; the CIM state works for everyone.
107
- const dism = parseDismState(run(SYSTEM.dism(), ['/English', '/Online', '/Get-FeatureInfo', '/FeatureName:' + FEATURE]));
108
- return {
109
- edition: reg.EditionID ?? null,
110
- build: Number(reg.CurrentBuildNumber ?? reg.CurrentBuild) || null,
111
- feature: dism === 'unknown' ? featureFromInstallState(probe.installState) : dism,
112
- sandboxExe: fileExists(system32('WindowsSandbox.exe')),
113
- virtualizationFirmware: probe.virtualizationFirmware ?? null,
114
- hypervisorPresent: probe.hypervisorPresent ?? null,
115
- totalRamBytes: os.totalmem(),
116
- freeDiskBytes: freeDisk(storageRoot),
117
- storageRoot,
118
- nodeVersion: process.version,
119
- };
120
- };
121
- const LABEL = { ok: '\x1b[32mOK\x1b[0m', warn: '\x1b[33mWARNING\x1b[0m', action: '\x1b[31mACTION NEEDED\x1b[0m' };
122
- const print = (checks) => table(checks.map((c) => [LABEL[c.status], c.name, c.detail]));
123
- /** Runs the enable command in an elevated PowerShell (Windows asks for permission); true if it worked. */
124
- const enableFeature = () => {
125
- const inner = "'-NoProfile','-Command','" + ENABLE_COMMAND + " | Out-Null'";
126
- const outer = "try { $p = Start-Process -FilePath '" + SYSTEM.powershell() + "' -Verb RunAs -Wait -PassThru -WindowStyle Hidden -ArgumentList " + inner + '; exit $p.ExitCode } catch { exit 1 }';
127
- return spawnSync(SYSTEM.powershell(), ['-NoProfile', '-NonInteractive', '-Command', outer], { stdio: 'inherit' }).status === 0;
128
- };
129
- export const setup = async (ctx) => {
130
- if (!isWin)
131
- fail('Windows Sandbox only runs on Windows.', 'Run sandbox setup on a Windows 10/11 Pro, Enterprise or Education PC.');
132
- console.log('Checking this PC for Windows Sandbox...\n');
133
- const facts = gatherFacts(ctx.storageRoot);
134
- let checks = buildChecks(facts);
135
- print(checks);
136
- if (canEnableFeature(facts)) {
137
- console.log('');
138
- if (await askYesNo('Turn on Windows Sandbox now? Windows will ask for admin permission.')) {
139
- console.log('Enabling Windows Sandbox (this can take a minute)...');
140
- if (!enableFeature())
141
- fail('Windows Sandbox could not be enabled (or the admin prompt was declined).', 'In an admin PowerShell run: ' + ENABLE_COMMAND + ', then restart Windows.');
142
- console.log('Done. Restart Windows to finish, then run sandbox setup again.\n');
143
- checks = buildChecks(gatherFacts(ctx.storageRoot));
144
- print(checks);
145
- }
146
- else
147
- console.log('To do it yourself, in an admin PowerShell run:\n ' + ENABLE_COMMAND + '\nthen restart Windows.');
148
- }
149
- const todo = checks.filter((c) => c.status === 'action').length;
150
- console.log('\n' + (todo ? todo + ' thing(s) to fix before the sandbox can start (see ACTION NEEDED above).' : 'This PC is ready. cd into a project and run sandbox claude (or sandbox for no agent).'));
151
- return todo ? 1 : 0;
152
- };
@@ -1,11 +0,0 @@
1
- /**
2
- * Applies one change (undefined = back to the default) to the config text and returns the new text, or the problems
3
- * that make the result invalid. Pure: the caller writes the file.
4
- */
5
- export declare const editConfigText: (text: string, key: string[], value: unknown) => {
6
- text: string;
7
- } | {
8
- problems: string[];
9
- };
10
- /** The settings screen. Changes are saved to the user config file (created when missing). */
11
- export declare const settingsMenu: (configPath: string | null) => Promise<void>;
@@ -1,156 +0,0 @@
1
- // The settings screen in the menu: every setting, generated from the zod schema (so nothing needs to be listed by
2
- // hand), shown with its current value and description, edited with a fitting prompt and saved to the user config
3
- // file. Edits go through jsonc-parser, so comments and formatting in the file are kept, and nothing is written unless
4
- // the whole config is still valid.
5
- import fs from 'node:fs';
6
- import path from 'node:path';
7
- import { input, select, Separator } from '@inquirer/prompts';
8
- import { applyEdits, modify, parse } from 'jsonc-parser';
9
- import _ from 'lodash';
10
- import { DEFAULTS, loadConfig, mergeConfig, userConfigPath } from '../core/config.js';
11
- import { Config as ConfigSchema, describeIssues } from '../core/schema.js';
12
- const c = { dim: (s) => '\x1b[2m' + s + '\x1b[0m', cyan: (s) => '\x1b[36m' + s + '\x1b[0m', green: (s) => '\x1b[32m' + s + '\x1b[0m', yellow: (s) => '\x1b[33m' + s + '\x1b[0m', red: (s) => '\x1b[31m' + s + '\x1b[0m' };
13
- /** optional()/default() wrappers hide the real type. */
14
- const unwrap = (s) => (['optional', 'default', 'nullable'].includes(s._zod.def.type) && s._zod.def.innerType ? unwrap(s._zod.def.innerType) : s);
15
- const kind = (s) => unwrap(s)._zod.def.type;
16
- const isSection = (s) => kind(s) === 'object' && Boolean(unwrap(s).shape);
17
- /** Settings not worth editing here (the schema link) or better edited in the file (agent definitions). */
18
- const HIDDEN = new Set(['$schema']);
19
- /** A value in one short line: maps as their keys, long lists shortened. */
20
- const show = (value) => {
21
- if (value === undefined)
22
- return c.dim('(not set)');
23
- if (typeof value === 'string')
24
- return value;
25
- if (value && typeof value === 'object' && !Array.isArray(value)) {
26
- const keys = Object.keys(value);
27
- return keys.length ? '{ ' + _.truncate(keys.join(', '), { length: 60 }) + ' }' : '{}';
28
- }
29
- return _.truncate(JSON.stringify(value), { length: 70 });
30
- };
31
- /** What the value is in the file the user owns (undefined when it comes from the built-in defaults). */
32
- const fileValue = (text, key) => _.get(parse(text) ?? {}, key);
33
- /**
34
- * Applies one change (undefined = back to the default) to the config text and returns the new text, or the problems
35
- * that make the result invalid. Pure: the caller writes the file.
36
- */
37
- export const editConfigText = (text, key, value) => {
38
- const edits = modify(text || '{}', key, value, { formattingOptions: { insertSpaces: true, tabSize: 2, eol: '\n' } });
39
- const next = applyEdits(text || '{}', edits);
40
- const parsed = ConfigSchema.safeParse(mergeConfig(DEFAULTS, parse(next) ?? {}));
41
- return parsed.success ? { text: next.endsWith('\n') ? next : next + '\n' } : { problems: describeIssues(parsed.error) };
42
- };
43
- /** A prompt that fits the setting's type; returns the new value, or undefined to change nothing. */
44
- const askValue = async (schema, label, current, config) => {
45
- const s = unwrap(schema);
46
- // The default agent is one of the configured ones: a list, not free text.
47
- if (label === 'defaultHarness' && config) {
48
- const v = await select({ message: label, choices: [...Object.keys(config.harnesses).map((h) => ({ name: h, value: h })), { name: c.dim('< cancel'), value: '@cancel' }], default: current });
49
- return v === '@cancel' ? undefined : { value: v };
50
- }
51
- const t = s._zod.def.type;
52
- const back = { name: c.dim('< cancel'), value: '@cancel' };
53
- const pick = async (choices) => {
54
- const v = await select({ message: label, choices: [...choices, back], default: current });
55
- return v === '@cancel' ? undefined : { value: v };
56
- };
57
- if (t === 'boolean')
58
- return pick([{ name: 'true', value: true }, { name: 'false', value: false }]);
59
- if (t === 'enum')
60
- return pick(Object.values(s._zod.def.entries ?? {}).map((v) => ({ name: String(v), value: v })));
61
- if (t === 'union') {
62
- const options = s._zod.def.options ?? [];
63
- const literals = options.filter((o) => kind(o) === 'literal').flatMap((o) => unwrap(o)._zod.def.values ?? []);
64
- const hasBool = options.some((o) => kind(o) === 'boolean');
65
- const other = options.find((o) => !['literal', 'boolean'].includes(kind(o)));
66
- const choices = [...(hasBool ? [{ name: 'true', value: true }, { name: 'false', value: false }] : []), ...literals.map((v) => ({ name: String(v), value: v }))];
67
- if (!other)
68
- return pick(choices);
69
- const chosen = await pick([...choices, { name: 'a ' + kind(other) + ' ...', value: '@other' }]);
70
- return chosen?.value === '@other' ? askValue(other, label, current) : chosen;
71
- }
72
- const typed = async (validate, convert) => {
73
- const answer = await input({ message: label + c.dim(' (empty = cancel)'), default: current === undefined ? '' : typeof current === 'string' ? current : JSON.stringify(current), validate: (v) => (v === '' ? true : validate(v)) });
74
- return answer === '' ? undefined : { value: convert(answer) };
75
- };
76
- if (t === 'number')
77
- return typed((v) => (Number.isFinite(Number(v)) ? true : 'a number'), Number);
78
- if (t === 'string')
79
- return typed(() => true, (v) => v);
80
- if (t === 'array' && kind(s._zod.def.element) === 'string') {
81
- return typed(() => true, (v) => (v.trim() === '[]' ? [] : v.split(',').map((x) => x.trim()).filter(Boolean)));
82
- }
83
- // Lists of objects and maps (mappings, harnesses, environment): edited as JSON.
84
- return typed((v) => { try {
85
- JSON.parse(v);
86
- return true;
87
- }
88
- catch {
89
- return 'valid JSON';
90
- } }, (v) => JSON.parse(v));
91
- };
92
- /** Edits one setting: shows it, asks, saves (or resets it to the default). */
93
- const editSetting = async (schema, key, config, file) => {
94
- const text = fs.existsSync(file) ? fs.readFileSync(file, 'utf8') : '';
95
- const inFile = fileValue(text, key);
96
- console.log('\n' + c.cyan(key.join('.')) + (schema.description ? '\n' + c.dim(schema.description) : ''));
97
- console.log('Now: ' + show(_.get(config, key)) + (inFile === undefined ? c.dim(' (built-in default)') : c.dim(' (set in ' + file + ')')));
98
- const action = inFile === undefined ? 'change' : await select({ message: 'What now?', choices: [{ name: 'Change it', value: 'change' }, { name: 'Reset to the default (' + show(_.get(DEFAULTS, key)) + ')', value: 'reset' }, { name: c.dim('< back'), value: 'back' }] });
99
- if (action === 'back')
100
- return;
101
- const answer = action === 'reset' ? { value: undefined } : await askValue(schema, key.join('.'), _.get(config, key), config);
102
- if (!answer)
103
- return;
104
- // The default needs no line in the file; an unchanged value needs no save.
105
- const value = _.isEqual(answer.value, _.get(DEFAULTS, key)) ? undefined : answer.value;
106
- if (value === inFile && _.isEqual(answer.value, _.get(config, key))) {
107
- console.log(c.dim('Unchanged.'));
108
- return;
109
- }
110
- const result = editConfigText(text, key, value);
111
- if ('problems' in result) {
112
- console.log(c.red('Not saved: ') + result.problems.join('; '));
113
- return;
114
- }
115
- fs.mkdirSync(path.dirname(file), { recursive: true });
116
- fs.writeFileSync(file, result.text, 'utf8');
117
- console.log(c.green('Saved') + c.dim(' to ' + file + '. New sandboxes use it.'));
118
- };
119
- const SECTION_TITLES = {
120
- toolchains: 'Languages and tools', databases: 'Databases', sandbox: 'The sandbox machine (memory, window, GPU, network)', attach: 'Attaching (auto attach, auto hide)',
121
- provisioning: 'Provisioning and git', secrets: 'Secrets', claudeProfile: 'Your Claude settings and history', storage: 'Storage', network: 'Network', hooks: 'Hooks', personalization: 'Desktop look',
122
- };
123
- /** Browses one level of settings; sections open, leaves are edited. */
124
- const browse = async (schema, key, file) => {
125
- for (;;) {
126
- const config = loadConfig().config;
127
- const entries = Object.entries(unwrap(schema).shape ?? {}).filter(([name]) => !HIDDEN.has(name));
128
- const text = fs.existsSync(file) ? fs.readFileSync(file, 'utf8') : '';
129
- const pickName = await select({
130
- message: key.length ? key.join('.') : 'Settings ' + c.dim('(saved to ' + file + ')'),
131
- pageSize: 18,
132
- choices: [
133
- ...entries.map(([name, s]) => {
134
- const full = [...key, name];
135
- const changed = fileValue(text, full) !== undefined;
136
- const label = isSection(s) ? (key.length ? name : SECTION_TITLES[name] ?? name) + c.dim(' ...') : name.padEnd(18) + ' ' + (changed ? c.yellow(show(_.get(config, full))) : show(_.get(config, full)));
137
- return { name: label, value: name, description: s.description };
138
- }),
139
- new Separator(),
140
- { name: c.dim('< back'), value: '@back' },
141
- ],
142
- });
143
- if (pickName === '@back')
144
- return;
145
- const child = unwrap(schema).shape[pickName];
146
- if (isSection(child))
147
- await browse(child, [...key, pickName], file);
148
- else
149
- await editSetting(child, [...key, pickName], config, file);
150
- }
151
- };
152
- /** The settings screen. Changes are saved to the user config file (created when missing). */
153
- export const settingsMenu = async (configPath) => {
154
- const file = configPath ?? userConfigPath();
155
- await browse(ConfigSchema, [], file);
156
- };
@@ -1,226 +0,0 @@
1
- // Databases inside the sandbox: PostgreSQL, MariaDB (MySQL-compatible), MongoDB and Redis. Binaries live in
2
- // C:\AgentData\tools, data in C:\AgentData\databases (both persist), and every server listens on localhost only.
3
- // Which ones run was decided on the host (session.databases): only what the project needs.
4
- import fs from 'node:fs';
5
- import net from 'node:net';
6
- import path from 'node:path';
7
- import { spawn, spawnSync } from 'node:child_process';
8
- import { fetchJson, fetchText, githubAsset, installArchive } from '../../shared/download.js';
9
- import { SYSTEM } from '../../shared/system.js';
10
- import { ensureJdk } from './java.js';
11
- import { dataDir, dryRun, execAsync, exists, log, logsDir, mkdirp } from '../env.js';
12
- import { resolveCached, tool } from './common.js';
13
- const dataFor = (name) => path.join(dataDir, 'databases', name);
14
- export const portOpen = (port) => new Promise((resolve) => {
15
- const socket = net.connect({ host: '127.0.0.1', port }, () => { socket.destroy(); resolve(true); });
16
- socket.once('error', () => resolve(false));
17
- });
18
- const waitForPort = async (port, seconds) => {
19
- for (const end = Date.now() + seconds * 1000; Date.now() < end;) {
20
- if (await portOpen(port))
21
- return true;
22
- await new Promise((r) => setTimeout(r, 300));
23
- }
24
- return false;
25
- };
26
- /** Starts a server detached (it outlives the boot script) with its output in logs\<name>.log, and waits for its port. */
27
- const startServer = async (name, exe, args, port) => {
28
- if (await portOpen(port))
29
- throw new Error('port ' + port + ' is already in use (change databases.' + name + '.port)');
30
- const logFile = path.join(logsDir, name + '.log');
31
- const out = fs.openSync(logFile, 'a');
32
- spawn(exe, args, { detached: true, stdio: ['ignore', out, out], windowsHide: true }).unref();
33
- fs.closeSync(out);
34
- if (!(await waitForPort(port, 60)))
35
- throw new Error(name + ' did not start listening on port ' + port + '; see ' + logFile);
36
- };
37
- /** Lock files a sandbox that was closed without shutting the server down leaves behind (this VM never ran it). */
38
- const clearStaleLocks = (dir, files) => { for (const f of files)
39
- fs.rmSync(path.join(dir, f), { force: true }); };
40
- const setupPostgres = async (env, plan) => {
41
- const exact = await resolveCached('postgres:' + plan.version, async () => {
42
- const versions = (await fetchJson('https://www.postgresql.org/versions.json')).filter((v) => v.supported);
43
- const hit = plan.version === 'latest' ? versions.find((v) => v.current) ?? versions[versions.length - 1] : versions.find((v) => v.major === plan.version.split('.')[0]);
44
- return hit ? hit.major + '.' + hit.latestMinor : Promise.reject(new Error('No supported PostgreSQL ' + plan.version));
45
- });
46
- const home = tool('postgres', exact);
47
- const bin = path.join(home, 'bin');
48
- if (!exists(path.join(bin, 'pg_ctl.exe'))) {
49
- log('Downloading PostgreSQL ' + exact + ' (~330 MB once) ...');
50
- // EDB publishes no checksums; the download is HTTPS from EnterpriseDB, PostgreSQL's official Windows packager.
51
- await installArchive('https://get.enterprisedb.com/postgresql/postgresql-' + exact + '-1-windows-x64-binaries.zip', home, { locate: 'pg_ctl.exe', up: 1, fileName: 'postgresql-' + exact + '.zip', members: ['pgsql/bin', 'pgsql/lib', 'pgsql/share', 'pgsql/include'] });
52
- }
53
- const data = dataFor('postgres-' + exact.split('.')[0]);
54
- if (!exists(path.join(data, 'PG_VERSION'))) {
55
- log('Creating the PostgreSQL database cluster ...');
56
- mkdirp(path.dirname(data));
57
- await execAsync(path.join(bin, 'initdb.exe'), ['-D', data, '-U', 'postgres', '-A', 'trust', '-E', 'UTF8', '--locale=C'], { stdio: 'ignore' });
58
- }
59
- clearStaleLocks(data, ['postmaster.pid']);
60
- // postgres.exe refuses to run as an administrator (the sandbox user is one); pg_ctl drops the rights first.
61
- if (await portOpen(plan.port))
62
- throw new Error('port ' + plan.port + ' is already in use (change databases.postgres.port)');
63
- await execAsync(path.join(bin, 'pg_ctl.exe'), ['start', '-D', data, '-w', '-t', '60', '-l', path.join(logsDir, 'postgres.log'), '-o', '-p ' + plan.port + ' -c listen_addresses=localhost'], { stdio: 'ignore' });
64
- Object.assign(env.vars, { PGHOST: 'localhost', PGPORT: String(plan.port), PGUSER: 'postgres' });
65
- env.prepend.push(bin);
66
- env.summary.push('postgres ' + exact + ': localhost:' + plan.port + ', user postgres, no password (postgres://postgres@localhost:' + plan.port + '/postgres)');
67
- };
68
- const MARIA = 'https://downloads.mariadb.org/rest-api/mariadb/';
69
- const setupMysql = async (env, plan) => {
70
- const series = await resolveCached('mariadb:' + plan.version, async () => {
71
- if (plan.version !== 'lts')
72
- return plan.version;
73
- const { major_releases: all } = await fetchJson(MARIA);
74
- return all.find((r) => r.release_status === 'Stable' && r.release_support_type === 'Long Term Support')?.release_id ?? Promise.reject(new Error('No MariaDB LTS release found'));
75
- });
76
- const latest = async () => {
77
- const { releases } = await fetchJson(MARIA + series + '/latest/');
78
- const [version, release] = Object.entries(releases)[0] ?? [];
79
- const zip = release?.files.find((f) => /-winx64\.zip$/.test(f.file_name));
80
- return zip ? { version, zip } : Promise.reject(new Error('No MariaDB ' + series + ' zip for Windows'));
81
- };
82
- const version = await resolveCached('mariadb-version:' + series, async () => (await latest()).version);
83
- const home = tool('mariadb', version);
84
- const bin = path.join(home, 'bin');
85
- if (!exists(path.join(bin, 'mariadbd.exe'))) {
86
- const { zip } = await latest();
87
- log('Downloading MariaDB ' + version + ' ...');
88
- await installArchive(zip.file_download_url.replace(/^http:/, 'https:'), home, { sha256: zip.checksum?.sha256sum ?? null, locate: 'mariadbd.exe', up: 1, fileName: zip.file_name });
89
- }
90
- const data = dataFor('mariadb');
91
- if (!exists(path.join(data, 'mysql'))) {
92
- log('Creating the MariaDB data folder ...');
93
- mkdirp(path.dirname(data));
94
- await execAsync(path.join(bin, 'mariadb-install-db.exe'), ['--datadir=' + data, '--port=' + plan.port], { stdio: 'ignore' });
95
- }
96
- await startServer('mysql', path.join(bin, 'mariadbd.exe'), ['--datadir=' + data, '--port=' + plan.port, '--bind-address=127.0.0.1', '--console'], plan.port);
97
- Object.assign(env.vars, { MYSQL_HOST: '127.0.0.1', MYSQL_TCP_PORT: String(plan.port) });
98
- env.prepend.push(bin);
99
- env.summary.push('mysql (MariaDB ' + version + '): 127.0.0.1:' + plan.port + ', user root, no password (mysql://root@127.0.0.1:' + plan.port + ')');
100
- };
101
- const setupMongo = async (env, plan) => {
102
- const find = async () => {
103
- const { versions } = await fetchJson('https://downloads.mongodb.org/full.json');
104
- const prod = versions.filter((v) => v.production_release);
105
- const hit = plan.version === 'latest' ? prod[0] : prod.find((v) => v.version === plan.version || v.version.startsWith(plan.version + '.'));
106
- const archive = hit?.downloads.find((d) => d.target === 'windows' && d.arch === 'x86_64' && d.edition === 'base')?.archive;
107
- return hit && archive ? { version: hit.version, archive } : Promise.reject(new Error('No MongoDB ' + plan.version + ' for Windows'));
108
- };
109
- const version = await resolveCached('mongodb:' + plan.version, async () => (await find()).version);
110
- const home = tool('mongodb', version);
111
- if (!exists(path.join(home, 'bin', 'mongod.exe'))) {
112
- const { archive } = await find();
113
- log('Downloading MongoDB ' + version + ' ...');
114
- await installArchive(archive.url, home, { sha256: archive.sha256, locate: 'mongod.exe', up: 1 });
115
- }
116
- const shell = tool('mongosh');
117
- if (!exists(path.join(shell, 'mongosh.exe'))) {
118
- const asset = await githubAsset('mongodb-js/mongosh', /^mongosh-[\d.]+-win32-x64\.zip$/);
119
- log('Downloading mongosh ...');
120
- await installArchive(asset.url, shell, { sha256: asset.sha256, locate: 'mongosh.exe', fileName: asset.name });
121
- }
122
- const data = mkdirp(dataFor('mongodb'));
123
- clearStaleLocks(data, ['mongod.lock']);
124
- await startServer('mongodb', path.join(home, 'bin', 'mongod.exe'), ['--dbpath', data, '--bind_ip', '127.0.0.1', '--port', String(plan.port)], plan.port);
125
- env.prepend.push(path.join(home, 'bin'), shell);
126
- env.summary.push('mongodb ' + version + ': mongodb://127.0.0.1:' + plan.port + ' (mongosh on PATH)');
127
- };
128
- // ---- Redis -------------------------------------------------------------------------------------------------------
129
- const setupRedis = async (env, plan) => {
130
- const home = tool('redis');
131
- if (!exists(path.join(home, 'redis-server.exe'))) {
132
- // Redis has no official Windows build; this is the maintained community build of upstream Redis (MSYS2).
133
- const asset = await githubAsset('redis-windows/redis-windows', /^Redis-[\d.]+-Windows-x64-msys2\.zip$/);
134
- log('Downloading ' + asset.name + ' ...');
135
- await installArchive(asset.url, home, { sha256: asset.sha256, locate: 'redis-server.exe', fileName: asset.name });
136
- }
137
- const data = mkdirp(dataFor('redis'));
138
- await startServer('redis', path.join(home, 'redis-server.exe'), ['--port', String(plan.port), '--bind', '127.0.0.1', '--dir', data.replace(/\\/g, '/'), '--appendonly', 'yes'], plan.port);
139
- env.prepend.push(home);
140
- env.summary.push('redis: redis://127.0.0.1:' + plan.port + ' (redis-cli on PATH)');
141
- };
142
- // ---- DynamoDB Local + dynamodb-admin -------------------------------------------------------------------------------
143
- const DYNAMO_ZIP = 'https://d1ni2b6xgvw0s0.cloudfront.net/v2.x/dynamodb_local_latest.zip';
144
- /**
145
- * Amazon's DynamoDB Local (a Java program; the Java toolchain step runs first, else this installs the LTS JDK) and
146
- * dynamodb-admin, the web UI to browse and edit tables, installed with the runner's own npm. Every AWS SDK picks the
147
- * local endpoint up from AWS_ENDPOINT_URL_DYNAMODB, with dummy credentials (real ones never reach the sandbox).
148
- */
149
- const setupDynamo = async (env, plan) => {
150
- const java = path.join(await ensureJdk(), 'bin', 'java.exe');
151
- const home = tool('dynamodb-local');
152
- if (!exists(path.join(home, 'DynamoDBLocal.jar'))) {
153
- log('Downloading DynamoDB Local ...');
154
- const sha256 = (await fetchText(DYNAMO_ZIP + '.sha256')).trim().split(/\s+/)[0];
155
- await installArchive(DYNAMO_ZIP, home, { sha256, locate: 'DynamoDBLocal.jar', fileName: 'dynamodb_local.zip' });
156
- }
157
- const data = mkdirp(dataFor('dynamodb'));
158
- // -sharedDb: one database whatever region/credentials a client uses, so the admin UI and the app see the same tables.
159
- await startServer('dynamodb', java, ['-Djava.library.path=' + path.join(home, 'DynamoDBLocal_lib'), '-jar', path.join(home, 'DynamoDBLocal.jar'), '-sharedDb', '-dbPath', data, '-port', String(plan.port)], plan.port);
160
- const endpoint = 'http://localhost:' + plan.port;
161
- const aws = { AWS_ENDPOINT_URL_DYNAMODB: endpoint, DYNAMO_ENDPOINT: endpoint, AWS_ACCESS_KEY_ID: 'local', AWS_SECRET_ACCESS_KEY: 'local', AWS_REGION: 'us-east-1', AWS_DEFAULT_REGION: 'us-east-1' };
162
- Object.assign(env.vars, aws);
163
- env.summary.push('dynamodb (DynamoDB Local): ' + endpoint + ' (AWS SDKs use it automatically via AWS_ENDPOINT_URL_DYNAMODB; dummy credentials)');
164
- if (!plan.adminPort)
165
- return;
166
- const prefix = tool('dynamodb-admin');
167
- const script = path.join(prefix, 'node_modules', 'dynamodb-admin', 'dist', 'dynamodb-admin.js');
168
- if (!exists(script)) {
169
- log('Installing dynamodb-admin (web UI for DynamoDB) ...');
170
- const npmCli = path.join(path.dirname(process.execPath), 'node_modules', 'npm', 'bin', 'npm-cli.js');
171
- await execAsync(process.execPath, [npmCli, 'install', '--global', '--prefix', prefix, 'dynamodb-admin', '--no-fund', '--no-audit'], { stdio: 'ignore' });
172
- }
173
- const admin = { ...process.env, ...aws, DYNAMO_ENDPOINT: endpoint };
174
- // The database matters more than its UI: a taken port is reported, not fatal.
175
- if (await portOpen(plan.adminPort)) {
176
- env.summary.push('dynamodb-admin: NOT started, port ' + plan.adminPort + ' is in use (change databases.dynamodb.adminPort)');
177
- return;
178
- }
179
- const out = fs.openSync(path.join(logsDir, 'dynamodb-admin.log'), 'a');
180
- spawn(process.execPath, [script, '--port', String(plan.adminPort), '--dynamo-endpoint', endpoint, '--skip-default-credentials'], { detached: true, stdio: ['ignore', out, out], windowsHide: true, env: admin }).unref();
181
- fs.closeSync(out);
182
- if (!(await waitForPort(plan.adminPort, 30)))
183
- throw new Error('dynamodb-admin did not start; see ' + path.join(logsDir, 'dynamodb-admin.log'));
184
- env.summary.push('dynamodb-admin: http://localhost:' + plan.adminPort + ' (browse and edit tables in the sandbox\'s browser)');
185
- };
186
- const SETUP = { postgres: setupPostgres, mysql: setupMysql, mongodb: setupMongo, redis: setupRedis, dynamodb: setupDynamo };
187
- export const DATABASE_NAMES = { postgres: 'PostgreSQL', mysql: 'MySQL (MariaDB)', mongodb: 'MongoDB', redis: 'Redis', dynamodb: 'DynamoDB Local', sqlserver: 'SQL Server' };
188
- /** The process listening on a local TCP port (netstat: no PowerShell start-up cost), or null. */
189
- const listenerPid = (port) => {
190
- const out = spawnSync(SYSTEM.netstat(), ['-ano', '-p', 'TCP'], { encoding: 'utf8', windowsHide: true }).stdout ?? '';
191
- const hit = out.split(/\r?\n/).map((l) => /^\s*TCP\s+\S+:(\d+)\s+\S+\s+LISTENING\s+(\d+)/.exec(l)).find((m) => m && Number(m[1]) === port);
192
- return hit ? Number(hit[2]) : null;
193
- };
194
- /** Stops a database (and DynamoDB's admin UI). PostgreSQL shuts down cleanly through pg_ctl; the others are ended. */
195
- export const stopDatabase = async (plan) => {
196
- if (!(await portOpen(plan.port)))
197
- return false;
198
- if (plan.database === 'postgres' && exists(tool('postgres'))) {
199
- for (const version of fs.readdirSync(tool('postgres'))) {
200
- const data = dataFor('postgres-' + version.split('.')[0]);
201
- const pgCtl = path.join(tool('postgres', version), 'bin', 'pg_ctl.exe');
202
- if (exists(path.join(data, 'postmaster.pid')) && exists(pgCtl))
203
- await execAsync(pgCtl, ['stop', '-D', data, '-m', 'fast', '-w'], { stdio: 'ignore' });
204
- }
205
- }
206
- for (const port of [plan.port, plan.adminPort ?? 0]) {
207
- const pid = port && listenerPid(port);
208
- if (pid)
209
- try {
210
- process.kill(pid);
211
- }
212
- catch { /* already gone */ }
213
- }
214
- return true;
215
- };
216
- export const setupDatabase = async (env, plan) => {
217
- if (plan.database === 'sqlserver') {
218
- env.summary.push('sqlserver: NOT available (SQL Server cannot start inside Windows Sandbox). Use the one on the PC via hostAccess.forwards, or switch the project to Postgres/SQLite for local work');
219
- return;
220
- }
221
- if (dryRun) {
222
- log('(dry run) would run ' + DATABASE_NAMES[plan.database] + ' on port ' + plan.port + ' (' + plan.reasons.join('; ') + ')');
223
- return;
224
- }
225
- await SETUP[plan.database](env, plan);
226
- };
@@ -1,10 +0,0 @@
1
- import type { Toolchains } from '../../core/types.js';
2
- import { type ToolEnv } from './common.js';
3
- /** Variables vcvars64.bat would set for this tree (host x64, target x64). */
4
- export declare const vcvars: (root: string, msvc: string, sdk: string) => {
5
- vars: Record<string, string>;
6
- path: string[];
7
- };
8
- /** The vcvars environment of an installed tree (for steps that run before the agent's environment exists). */
9
- export declare const installedMsvcEnv: () => ReturnType<typeof vcvars> | null;
10
- export declare const setupMsvc: (env: ToolEnv, config: Toolchains["msvc"]) => Promise<void>;