homegraph 1.1.2 → 1.2.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 (361) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +268 -243
  3. package/dist/arkts/ohos-api-index.d.ts +15 -0
  4. package/dist/arkts/ohos-api-index.d.ts.map +1 -0
  5. package/dist/arkts/ohos-api-index.js +190 -0
  6. package/dist/arkts/ohos-api-index.js.map +1 -0
  7. package/dist/arkts/ohos-sdk-input.d.ts +36 -0
  8. package/dist/arkts/ohos-sdk-input.d.ts.map +1 -0
  9. package/dist/arkts/ohos-sdk-input.js +214 -0
  10. package/dist/arkts/ohos-sdk-input.js.map +1 -0
  11. package/dist/bin/command-supervision.d.ts +12 -0
  12. package/dist/bin/command-supervision.d.ts.map +1 -0
  13. package/dist/bin/command-supervision.js +86 -0
  14. package/dist/bin/command-supervision.js.map +1 -0
  15. package/dist/bin/homegraph.d.ts +1 -1
  16. package/dist/bin/homegraph.js +971 -71
  17. package/dist/bin/homegraph.js.map +1 -1
  18. package/dist/db/index.d.ts +20 -0
  19. package/dist/db/index.d.ts.map +1 -1
  20. package/dist/db/index.js +39 -0
  21. package/dist/db/index.js.map +1 -1
  22. package/dist/db/migrations.d.ts +1 -1
  23. package/dist/db/migrations.d.ts.map +1 -1
  24. package/dist/db/migrations.js +58 -19
  25. package/dist/db/migrations.js.map +1 -1
  26. package/dist/db/queries.d.ts +14 -0
  27. package/dist/db/queries.d.ts.map +1 -1
  28. package/dist/db/queries.js +314 -143
  29. package/dist/db/queries.js.map +1 -1
  30. package/dist/db/schema.sql +172 -152
  31. package/dist/directory.d.ts +32 -0
  32. package/dist/directory.d.ts.map +1 -1
  33. package/dist/directory.js +88 -5
  34. package/dist/directory.js.map +1 -1
  35. package/dist/extraction/arkts-batch-worker.d.ts +2 -0
  36. package/dist/extraction/arkts-batch-worker.d.ts.map +1 -0
  37. package/dist/extraction/arkts-batch-worker.js +28 -0
  38. package/dist/extraction/arkts-batch-worker.js.map +1 -0
  39. package/dist/extraction/context.d.ts +11 -0
  40. package/dist/extraction/context.d.ts.map +1 -1
  41. package/dist/extraction/context.js +20 -0
  42. package/dist/extraction/context.js.map +1 -1
  43. package/dist/extraction/index.d.ts +16 -2
  44. package/dist/extraction/index.d.ts.map +1 -1
  45. package/dist/extraction/index.js +619 -380
  46. package/dist/extraction/index.js.map +1 -1
  47. package/dist/extraction/languages/arkts-state-decorators.d.ts +13 -0
  48. package/dist/extraction/languages/arkts-state-decorators.d.ts.map +1 -0
  49. package/dist/extraction/languages/arkts-state-decorators.js +26 -0
  50. package/dist/extraction/languages/arkts-state-decorators.js.map +1 -0
  51. package/dist/extraction/languages/arkts-viewtree.d.ts +4 -2
  52. package/dist/extraction/languages/arkts-viewtree.d.ts.map +1 -1
  53. package/dist/extraction/languages/arkts-viewtree.js +21 -6
  54. package/dist/extraction/languages/arkts-viewtree.js.map +1 -1
  55. package/dist/extraction/languages/arkts.d.ts +98 -2
  56. package/dist/extraction/languages/arkts.d.ts.map +1 -1
  57. package/dist/extraction/languages/arkts.js +1290 -61
  58. package/dist/extraction/languages/arkts.js.map +1 -1
  59. package/dist/extraction/languages/c-cpp.d.ts +56 -0
  60. package/dist/extraction/languages/c-cpp.d.ts.map +1 -1
  61. package/dist/extraction/languages/c-cpp.js +198 -1
  62. package/dist/extraction/languages/c-cpp.js.map +1 -1
  63. package/dist/extraction/languages/ohos-api-consumer.d.ts +34 -0
  64. package/dist/extraction/languages/ohos-api-consumer.d.ts.map +1 -0
  65. package/dist/extraction/languages/ohos-api-consumer.js +283 -0
  66. package/dist/extraction/languages/ohos-api-consumer.js.map +1 -0
  67. package/dist/extraction/parse-pool.d.ts +126 -0
  68. package/dist/extraction/parse-pool.d.ts.map +1 -0
  69. package/dist/extraction/parse-pool.js +319 -0
  70. package/dist/extraction/parse-pool.js.map +1 -0
  71. package/dist/extraction/tree-sitter-types.d.ts +17 -0
  72. package/dist/extraction/tree-sitter-types.d.ts.map +1 -1
  73. package/dist/extraction/tree-sitter.d.ts +21 -0
  74. package/dist/extraction/tree-sitter.d.ts.map +1 -1
  75. package/dist/extraction/tree-sitter.js +198 -27
  76. package/dist/extraction/tree-sitter.js.map +1 -1
  77. package/dist/extraction/wasm/tree-sitter-c_sharp.wasm +0 -0
  78. package/dist/extraction/wasm/tree-sitter-pascal.wasm +0 -0
  79. package/dist/graph/traversal.d.ts.map +1 -1
  80. package/dist/graph/traversal.js +76 -17
  81. package/dist/graph/traversal.js.map +1 -1
  82. package/dist/index.d.ts +25 -0
  83. package/dist/index.d.ts.map +1 -1
  84. package/dist/index.js +78 -4
  85. package/dist/index.js.map +1 -1
  86. package/dist/installer/instructions-template.js +9 -9
  87. package/dist/installer/targets/shared.d.ts +5 -6
  88. package/dist/installer/targets/shared.d.ts.map +1 -1
  89. package/dist/installer/targets/shared.js +5 -6
  90. package/dist/installer/targets/shared.js.map +1 -1
  91. package/dist/mcp/daemon-paths.d.ts +30 -3
  92. package/dist/mcp/daemon-paths.d.ts.map +1 -1
  93. package/dist/mcp/daemon-paths.js +50 -10
  94. package/dist/mcp/daemon-paths.js.map +1 -1
  95. package/dist/mcp/daemon-registry.d.ts.map +1 -1
  96. package/dist/mcp/daemon-registry.js +7 -3
  97. package/dist/mcp/daemon-registry.js.map +1 -1
  98. package/dist/mcp/daemon.d.ts +48 -0
  99. package/dist/mcp/daemon.d.ts.map +1 -1
  100. package/dist/mcp/daemon.js +196 -32
  101. package/dist/mcp/daemon.js.map +1 -1
  102. package/dist/mcp/engine.d.ts +17 -0
  103. package/dist/mcp/engine.d.ts.map +1 -1
  104. package/dist/mcp/engine.js +73 -1
  105. package/dist/mcp/engine.js.map +1 -1
  106. package/dist/mcp/index.d.ts.map +1 -1
  107. package/dist/mcp/index.js +25 -43
  108. package/dist/mcp/index.js.map +1 -1
  109. package/dist/mcp/liveness-watchdog.js +16 -16
  110. package/dist/mcp/ppid-watchdog.d.ts +18 -0
  111. package/dist/mcp/ppid-watchdog.d.ts.map +1 -1
  112. package/dist/mcp/ppid-watchdog.js +37 -0
  113. package/dist/mcp/ppid-watchdog.js.map +1 -1
  114. package/dist/mcp/query-cache.d.ts +25 -0
  115. package/dist/mcp/query-cache.d.ts.map +1 -0
  116. package/dist/mcp/query-cache.js +191 -0
  117. package/dist/mcp/query-cache.js.map +1 -0
  118. package/dist/mcp/query-pool.d.ts +94 -0
  119. package/dist/mcp/query-pool.d.ts.map +1 -0
  120. package/dist/mcp/query-pool.js +297 -0
  121. package/dist/mcp/query-pool.js.map +1 -0
  122. package/dist/mcp/query-worker.d.ts +24 -0
  123. package/dist/mcp/query-worker.d.ts.map +1 -0
  124. package/dist/mcp/query-worker.js +87 -0
  125. package/dist/mcp/query-worker.js.map +1 -0
  126. package/dist/mcp/server-instructions.d.ts +5 -7
  127. package/dist/mcp/server-instructions.d.ts.map +1 -1
  128. package/dist/mcp/server-instructions.js +72 -74
  129. package/dist/mcp/server-instructions.js.map +1 -1
  130. package/dist/mcp/tools.d.ts +94 -4
  131. package/dist/mcp/tools.d.ts.map +1 -1
  132. package/dist/mcp/tools.js +877 -71
  133. package/dist/mcp/tools.js.map +1 -1
  134. package/dist/project-config.d.ts +20 -0
  135. package/dist/project-config.d.ts.map +1 -1
  136. package/dist/project-config.js +42 -2
  137. package/dist/project-config.js.map +1 -1
  138. package/dist/reasoning/login.js +1 -1
  139. package/dist/reasoning/login.js.map +1 -1
  140. package/dist/reasoning/reasoner.js +32 -32
  141. package/dist/resolution/c-fnptr-synthesizer.d.ts +0 -28
  142. package/dist/resolution/c-fnptr-synthesizer.d.ts.map +1 -1
  143. package/dist/resolution/c-fnptr-synthesizer.js +765 -79
  144. package/dist/resolution/c-fnptr-synthesizer.js.map +1 -1
  145. package/dist/resolution/callback-synthesizer.d.ts +1 -1
  146. package/dist/resolution/callback-synthesizer.d.ts.map +1 -1
  147. package/dist/resolution/callback-synthesizer.js +72 -11
  148. package/dist/resolution/callback-synthesizer.js.map +1 -1
  149. package/dist/resolution/cooperative-yield.d.ts +32 -0
  150. package/dist/resolution/cooperative-yield.d.ts.map +1 -0
  151. package/dist/resolution/cooperative-yield.js +42 -0
  152. package/dist/resolution/cooperative-yield.js.map +1 -0
  153. package/dist/resolution/index.d.ts +11 -2
  154. package/dist/resolution/index.d.ts.map +1 -1
  155. package/dist/resolution/index.js +72 -4
  156. package/dist/resolution/index.js.map +1 -1
  157. package/dist/resolution/name-matcher.d.ts +22 -0
  158. package/dist/resolution/name-matcher.d.ts.map +1 -1
  159. package/dist/resolution/name-matcher.js +317 -20
  160. package/dist/resolution/name-matcher.js.map +1 -1
  161. package/dist/spec/config.d.ts +39 -0
  162. package/dist/spec/config.d.ts.map +1 -0
  163. package/dist/spec/config.js +304 -0
  164. package/dist/spec/config.js.map +1 -0
  165. package/dist/spec/db/commit-node.d.ts +23 -0
  166. package/dist/spec/db/commit-node.d.ts.map +1 -0
  167. package/dist/spec/db/commit-node.js +62 -0
  168. package/dist/spec/db/commit-node.js.map +1 -0
  169. package/dist/spec/db/fragment-node.d.ts +24 -0
  170. package/dist/spec/db/fragment-node.d.ts.map +1 -0
  171. package/dist/spec/db/fragment-node.js +128 -0
  172. package/dist/spec/db/fragment-node.js.map +1 -0
  173. package/dist/spec/db/fts.d.ts +74 -0
  174. package/dist/spec/db/fts.d.ts.map +1 -0
  175. package/dist/spec/db/fts.js +324 -0
  176. package/dist/spec/db/fts.js.map +1 -0
  177. package/dist/spec/db/index.d.ts +13 -0
  178. package/dist/spec/db/index.d.ts.map +1 -0
  179. package/dist/spec/db/index.js +50 -0
  180. package/dist/spec/db/index.js.map +1 -0
  181. package/dist/spec/db/relations.d.ts +55 -0
  182. package/dist/spec/db/relations.d.ts.map +1 -0
  183. package/dist/spec/db/relations.js +158 -0
  184. package/dist/spec/db/relations.js.map +1 -0
  185. package/dist/spec/db/schema.d.ts +33 -0
  186. package/dist/spec/db/schema.d.ts.map +1 -0
  187. package/dist/spec/db/schema.js +119 -0
  188. package/dist/spec/db/schema.js.map +1 -0
  189. package/dist/spec/db/schema.sql +117 -0
  190. package/dist/spec/db/spec-node.d.ts +41 -0
  191. package/dist/spec/db/spec-node.d.ts.map +1 -0
  192. package/dist/spec/db/spec-node.js +114 -0
  193. package/dist/spec/db/spec-node.js.map +1 -0
  194. package/dist/spec/evolve/impact-locator.d.ts +13 -0
  195. package/dist/spec/evolve/impact-locator.d.ts.map +1 -0
  196. package/dist/spec/evolve/impact-locator.js +25 -0
  197. package/dist/spec/evolve/impact-locator.js.map +1 -0
  198. package/dist/spec/evolve/llm-client.d.ts +50 -0
  199. package/dist/spec/evolve/llm-client.d.ts.map +1 -0
  200. package/dist/spec/evolve/llm-client.js +176 -0
  201. package/dist/spec/evolve/llm-client.js.map +1 -0
  202. package/dist/spec/evolve/logic-checker.d.ts +12 -0
  203. package/dist/spec/evolve/logic-checker.d.ts.map +1 -0
  204. package/dist/spec/evolve/logic-checker.js +24 -0
  205. package/dist/spec/evolve/logic-checker.js.map +1 -0
  206. package/dist/spec/evolve/pipeline.d.ts +42 -0
  207. package/dist/spec/evolve/pipeline.d.ts.map +1 -0
  208. package/dist/spec/evolve/pipeline.js +567 -0
  209. package/dist/spec/evolve/pipeline.js.map +1 -0
  210. package/dist/spec/evolve/spec-rewriter.d.ts +42 -0
  211. package/dist/spec/evolve/spec-rewriter.d.ts.map +1 -0
  212. package/dist/spec/evolve/spec-rewriter.js +230 -0
  213. package/dist/spec/evolve/spec-rewriter.js.map +1 -0
  214. package/dist/spec/graph/queries.d.ts +155 -0
  215. package/dist/spec/graph/queries.d.ts.map +1 -0
  216. package/dist/spec/graph/queries.js +440 -0
  217. package/dist/spec/graph/queries.js.map +1 -0
  218. package/dist/spec/llm/client.d.ts +29 -0
  219. package/dist/spec/llm/client.d.ts.map +1 -0
  220. package/dist/spec/llm/client.js +123 -0
  221. package/dist/spec/llm/client.js.map +1 -0
  222. package/dist/spec/llm/index.d.ts +3 -0
  223. package/dist/spec/llm/index.d.ts.map +1 -0
  224. package/dist/spec/llm/index.js +11 -0
  225. package/dist/spec/llm/index.js.map +1 -0
  226. package/dist/spec/llm/prompts.d.ts +13 -0
  227. package/dist/spec/llm/prompts.d.ts.map +1 -0
  228. package/dist/spec/llm/prompts.js +75 -0
  229. package/dist/spec/llm/prompts.js.map +1 -0
  230. package/dist/spec/mining/diff-parser.d.ts +33 -0
  231. package/dist/spec/mining/diff-parser.d.ts.map +1 -0
  232. package/dist/spec/mining/diff-parser.js +166 -0
  233. package/dist/spec/mining/diff-parser.js.map +1 -0
  234. package/dist/spec/mining/git-scanner.d.ts +103 -0
  235. package/dist/spec/mining/git-scanner.d.ts.map +1 -0
  236. package/dist/spec/mining/git-scanner.js +307 -0
  237. package/dist/spec/mining/git-scanner.js.map +1 -0
  238. package/dist/spec/mining/pipeline.d.ts +53 -0
  239. package/dist/spec/mining/pipeline.d.ts.map +1 -0
  240. package/dist/spec/mining/pipeline.js +178 -0
  241. package/dist/spec/mining/pipeline.js.map +1 -0
  242. package/dist/spec/mining/scope-resolver.d.ts +45 -0
  243. package/dist/spec/mining/scope-resolver.d.ts.map +1 -0
  244. package/dist/spec/mining/scope-resolver.js +103 -0
  245. package/dist/spec/mining/scope-resolver.js.map +1 -0
  246. package/dist/spec/mining/spec-extractor.d.ts +69 -0
  247. package/dist/spec/mining/spec-extractor.d.ts.map +1 -0
  248. package/dist/spec/mining/spec-extractor.js +369 -0
  249. package/dist/spec/mining/spec-extractor.js.map +1 -0
  250. package/dist/spec/types.d.ts +149 -0
  251. package/dist/spec/types.d.ts.map +1 -0
  252. package/dist/spec/types.js +15 -0
  253. package/dist/spec/types.js.map +1 -0
  254. package/dist/spec/utils.d.ts +167 -0
  255. package/dist/spec/utils.d.ts.map +1 -0
  256. package/dist/spec/utils.js +463 -0
  257. package/dist/spec/utils.js.map +1 -0
  258. package/dist/sync/worktree.d.ts +9 -0
  259. package/dist/sync/worktree.d.ts.map +1 -1
  260. package/dist/sync/worktree.js +40 -0
  261. package/dist/sync/worktree.js.map +1 -1
  262. package/dist/types.d.ts +6 -1
  263. package/dist/types.d.ts.map +1 -1
  264. package/dist/ui/shimmer-progress.d.ts +2 -0
  265. package/dist/ui/shimmer-progress.d.ts.map +1 -1
  266. package/dist/ui/shimmer-progress.js +19 -2
  267. package/dist/ui/shimmer-progress.js.map +1 -1
  268. package/dist/upgrade/index.js +1 -1
  269. package/dist/upgrade/index.js.map +1 -1
  270. package/package.json +58 -57
  271. package/scripts/add-lang/bench.sh +60 -60
  272. package/scripts/add-lang/check-grammar.mjs +75 -75
  273. package/scripts/add-lang/dump-ast.mjs +103 -103
  274. package/scripts/add-lang/verify-extraction.mjs +70 -70
  275. package/scripts/agent-eval/ab-adoption.sh +91 -91
  276. package/scripts/agent-eval/ab-hook.sh +86 -86
  277. package/scripts/agent-eval/ab-impl.sh +78 -78
  278. package/scripts/agent-eval/ab-new-vs-baseline.sh +102 -102
  279. package/scripts/agent-eval/ab-sufficiency.sh +78 -78
  280. package/scripts/agent-eval/arms-F.sh +21 -21
  281. package/scripts/agent-eval/arms-matrix.sh +37 -37
  282. package/scripts/agent-eval/audit.sh +68 -68
  283. package/scripts/agent-eval/bench-readme.sh +28 -28
  284. package/scripts/agent-eval/bench-why-repo.sh +22 -22
  285. package/scripts/agent-eval/block-read-hook.sh +19 -19
  286. package/scripts/agent-eval/hook-settings.json +15 -15
  287. package/scripts/agent-eval/itrun.sh +120 -120
  288. package/scripts/agent-eval/offload-eval-3arm.sh +72 -72
  289. package/scripts/agent-eval/offload-eval-cost.mjs +133 -133
  290. package/scripts/agent-eval/offload-eval-effort.mjs +108 -108
  291. package/scripts/agent-eval/offload-eval-frontload-matrix.sh +25 -25
  292. package/scripts/agent-eval/offload-eval-frontload.sh +47 -47
  293. package/scripts/agent-eval/offload-eval-ground-truth.json +18 -18
  294. package/scripts/agent-eval/offload-eval-hook.mjs +84 -84
  295. package/scripts/agent-eval/offload-eval-judge.mjs +103 -103
  296. package/scripts/agent-eval/offload-eval-matrix.sh +20 -20
  297. package/scripts/agent-eval/offload-eval-metrics.mjs +94 -94
  298. package/scripts/agent-eval/offload-eval-refs1.sh +50 -50
  299. package/scripts/agent-eval/offload-eval-setup.sh +24 -24
  300. package/scripts/agent-eval/offload-eval-styles.sh +71 -71
  301. package/scripts/agent-eval/offload-eval-summarize.mjs +68 -68
  302. package/scripts/agent-eval/offload-eval.md +76 -76
  303. package/scripts/agent-eval/parse-arms.mjs +116 -116
  304. package/scripts/agent-eval/parse-bench-readme.mjs +84 -84
  305. package/scripts/agent-eval/parse-run.mjs +45 -45
  306. package/scripts/agent-eval/parse-session.mjs +93 -93
  307. package/scripts/agent-eval/probe-context.mjs +21 -21
  308. package/scripts/agent-eval/probe-explore.mjs +40 -40
  309. package/scripts/agent-eval/probe-node.mjs +20 -20
  310. package/scripts/agent-eval/probe-sweep.mjs +119 -119
  311. package/scripts/agent-eval/probe-trace.mjs +20 -20
  312. package/scripts/agent-eval/redirect-read-hook.sh +38 -38
  313. package/scripts/agent-eval/repro-concurrent-explore.mjs +119 -0
  314. package/scripts/agent-eval/repro-daemon-clients.mjs +125 -0
  315. package/scripts/agent-eval/run-agent.sh +34 -34
  316. package/scripts/agent-eval/run-all.sh +69 -69
  317. package/scripts/agent-eval/run-arms.sh +56 -56
  318. package/scripts/agent-eval/seq-matrix.mjs +137 -137
  319. package/scripts/build-bundle.sh +118 -118
  320. package/scripts/exp_boundary_eval/README.md +247 -0
  321. package/scripts/exp_boundary_eval/__pycache__/_utils.cpython-310.pyc +0 -0
  322. package/scripts/exp_boundary_eval/__pycache__/analyze.cpython-310.pyc +0 -0
  323. package/scripts/exp_boundary_eval/__pycache__/deveco_arm.cpython-310.pyc +0 -0
  324. package/scripts/exp_boundary_eval/__pycache__/run_one.cpython-310.pyc +0 -0
  325. package/scripts/exp_boundary_eval/__pycache__/run_session.cpython-310.pyc +0 -0
  326. package/scripts/exp_boundary_eval/__pycache__/setup.cpython-310.pyc +0 -0
  327. package/scripts/exp_boundary_eval/_test_mcp_chain.py +78 -0
  328. package/scripts/exp_boundary_eval/_test_stdin.py +8 -0
  329. package/scripts/exp_boundary_eval/_utils.py +1116 -0
  330. package/scripts/exp_boundary_eval/analyze.py +1313 -0
  331. package/scripts/exp_boundary_eval/data/agents.json +109 -0
  332. package/scripts/exp_boundary_eval/data/experiments.json +140 -0
  333. package/scripts/exp_boundary_eval/deveco_arm.py +519 -0
  334. package/scripts/exp_boundary_eval/run_all.py +378 -0
  335. package/scripts/exp_boundary_eval/run_one.py +165 -0
  336. package/scripts/exp_boundary_eval/run_session.py +158 -0
  337. package/scripts/exp_boundary_eval/setup.py +120 -0
  338. package/scripts/exp_boundary_eval/win_mcp_launcher.py +73 -0
  339. package/scripts/exp_boundary_eval/win_mcp_stdio_wrap.js +36 -0
  340. package/scripts/exp_boundary_eval/win_node_launcher.py +24 -0
  341. package/scripts/extract-release-notes.mjs +130 -130
  342. package/scripts/local-install.sh +41 -41
  343. package/scripts/npm-sdk.js +75 -75
  344. package/scripts/npm-shim.js +268 -246
  345. package/scripts/ohos-sdk-publish.mjs +133 -0
  346. package/scripts/pack-npm.sh +119 -119
  347. package/scripts/prepare-release.mjs +270 -270
  348. package/scripts/qa_eval/README.md +407 -404
  349. package/scripts/qa_eval/_test_deveco_probe.py +41 -41
  350. package/scripts/qa_eval/agent_runner.py +526 -526
  351. package/scripts/qa_eval/data/.gitignore +4 -4
  352. package/scripts/qa_eval/data/test-set.jsonl +2 -22
  353. package/scripts/qa_eval/eval_metrics.py +274 -233
  354. package/scripts/qa_eval/external_agent.py +976 -671
  355. package/scripts/qa_eval/llm_config.py +92 -92
  356. package/scripts/qa_eval/memory_monitor.py +132 -132
  357. package/scripts/qa_eval/my_answer_accuracy.py +187 -187
  358. package/scripts/qa_eval/requirements.txt +2 -2
  359. package/scripts/qa_eval/run_pipeline.py +804 -711
  360. package/scripts/qa_eval/stats_efficiency.py +279 -279
  361. package/scripts/qa_eval/stats_scores.py +207 -207
@@ -1,246 +1,268 @@
1
- #!/usr/bin/env node
2
- 'use strict';
3
- //
4
- // npm thin-installer launcher for HomeGraph.
5
- //
6
- // The heavy artifact (a vendored Node runtime + the app) ships as a per-platform
7
- // optionalDependency: homegraph-<platform>-<arch>. npm installs
8
- // only the one matching the host, via each package's `os`/`cpu` fields (the
9
- // esbuild pattern). This shim — run by the user's OWN Node — locates that bundle
10
- // and execs its launcher, so the real work always runs on the bundled Node 24
11
- // (with node:sqlite), regardless of the user's Node version. The user's Node is
12
- // only ever a launcher; even an ancient version can run this file.
13
- //
14
- // Self-heal (issue #303): some registries — notably the npmmirror/cnpm mirrors,
15
- // and some corporate proxies — don't reliably mirror the per-platform
16
- // optionalDependencies. npm treats an unfetchable optional dep as success and
17
- // silently skips it, so the bundle goes missing and every command fails. When
18
- // the installed bundle can't be resolved, this shim falls back to downloading
19
- // the matching bundle straight from GitHub Releases — the very archive
20
- // install.sh uses — into a cache dir, then runs that. Knobs:
21
- // HOMEGRAPH_NO_DOWNLOAD=1 disable the network fallback (print guidance)
22
- // HOMEGRAPH_INSTALL_DIR=DIR cache location (default: ~/.homegraph)
23
- // HOMEGRAPH_DOWNLOAD_BASE=URL release-download base (for mirrors/air-gapped)
24
- //
25
- // Wired up at release time as the main package's `bin`:
26
- // "bin": { "homegraph": "npm-shim.js" }
27
- // with the platform packages listed in `optionalDependencies`.
28
-
29
- var childProcess = require('child_process');
30
- var fs = require('fs');
31
- var os = require('os');
32
- var path = require('path');
33
-
34
- var target = process.platform + '-' + process.arch; // e.g. darwin-arm64, linux-x64
35
- var pkg = 'homegraph-' + target;
36
- var isWindows = process.platform === 'win32';
37
- var REPO = 'homegraph/homegraph';
38
-
39
- main().catch(function (e) {
40
- process.stderr.write('homegraph: ' + (e && e.message ? e.message : String(e)) + '\n');
41
- process.exit(1);
42
- });
43
-
44
- async function main() {
45
- // Happy path: the npm-installed optional dependency. Fall back to a download
46
- // when the registry didn't deliver it.
47
- var resolved = resolveInstalledBundle() || (await selfHealBundle());
48
- var res = childProcess.spawnSync(resolved.command, resolved.args, { stdio: 'inherit' });
49
- if (res.error) {
50
- process.stderr.write('homegraph: ' + res.error.message + '\n');
51
- process.exit(1);
52
- }
53
- process.exit(res.status === null ? 1 : res.status);
54
- }
55
-
56
- // Resolve the launcher from the installed per-platform optionalDependency.
57
- // Returns {command, args} or null if the package isn't installed.
58
- function resolveInstalledBundle() {
59
- try {
60
- if (isWindows) {
61
- // Modern Node refuses to spawn the bundle's .cmd directly (EINVAL, the
62
- // CVE-2024-27980 hardening on Node 24), so invoke the bundled node.exe
63
- // against the app entry point and pass --liftoff-only here.
64
- var nodeExe = require.resolve(pkg + '/node.exe');
65
- var entry = require.resolve(pkg + '/lib/dist/bin/homegraph.js');
66
- return { command: nodeExe, args: liftoff(entry) };
67
- }
68
- return { command: require.resolve(pkg + '/bin/homegraph'), args: process.argv.slice(2) };
69
- } catch (e) {
70
- return null;
71
- }
72
- }
73
-
74
- // Locate the launcher inside an extracted GitHub bundle directory (same
75
- // node/lib/bin layout as the npm platform package). Returns {command, args} or
76
- // null when the directory doesn't hold a usable bundle yet.
77
- function launcherIn(dir) {
78
- if (isWindows) {
79
- var nodeExe = path.join(dir, 'node.exe');
80
- var entry = path.join(dir, 'lib', 'dist', 'bin', 'homegraph.js');
81
- if (fs.existsSync(nodeExe) && fs.existsSync(entry)) {
82
- return { command: nodeExe, args: liftoff(entry) };
83
- }
84
- } else {
85
- var launcher = path.join(dir, 'bin', 'homegraph');
86
- if (fs.existsSync(launcher)) return { command: launcher, args: process.argv.slice(2) };
87
- }
88
- return null;
89
- }
90
-
91
- // --liftoff-only keeps tree-sitter's WASM grammars off V8's turboshaft tier to
92
- // avoid the Zone OOM on Node >= 22 (issues #293/#298). The unix bin/homegraph
93
- // launcher already passes it; on Windows we invoke node.exe directly so add it.
94
- function liftoff(entry) {
95
- return ['--liftoff-only', entry].concat(process.argv.slice(2));
96
- }
97
-
98
- // Download + cache the platform bundle from GitHub Releases. Returns
99
- // {command, args}; exits the process with guidance if it can't.
100
- async function selfHealBundle() {
101
- var version = readVersion();
102
- var bundlesDir = path.join(process.env.HOMEGRAPH_INSTALL_DIR || path.join(os.homedir(), '.homegraph'), 'bundles');
103
- var dest = path.join(bundlesDir, target + '-' + version);
104
-
105
- // Already downloaded by a previous run? Use it even when downloads are
106
- // disabled — HOMEGRAPH_NO_DOWNLOAD blocks fetching, not a cached bundle.
107
- var cached = launcherIn(dest);
108
- if (cached) return cached;
109
-
110
- if (process.env.HOMEGRAPH_NO_DOWNLOAD) {
111
- fail('the network fallback is disabled (HOMEGRAPH_NO_DOWNLOAD is set).');
112
- }
113
-
114
- var asset = 'homegraph-' + target + (isWindows ? '.zip' : '.tar.gz');
115
- var base = process.env.HOMEGRAPH_DOWNLOAD_BASE || ('https://github.com/' + REPO + '/releases/download');
116
- var url = base + '/v' + version + '/' + asset;
117
-
118
- process.stderr.write(
119
- 'homegraph: platform bundle missing (registry did not provide ' + pkg + ').\n' +
120
- 'homegraph: downloading ' + asset + ' from GitHub Releases (' + version + ')...\n'
121
- );
122
-
123
- // Stage inside bundlesDir so the final rename is on the same filesystem (atomic,
124
- // no EXDEV across tmpfs). Strip the archive's top-level homegraph-<target>/ dir.
125
- fs.mkdirSync(bundlesDir, { recursive: true });
126
- var stage = fs.mkdtempSync(path.join(bundlesDir, '.dl-'));
127
- try {
128
- var archivePath = path.join(stage, asset);
129
- await download(url, archivePath, 6);
130
- await verifyChecksum(archivePath, asset, base, version);
131
- var extracted = path.join(stage, 'bundle');
132
- fs.mkdirSync(extracted);
133
- extract(archivePath, extracted);
134
-
135
- var raced = launcherIn(dest); // another process may have finished meanwhile
136
- if (raced) { rmrf(stage); return raced; }
137
- try {
138
- fs.renameSync(extracted, dest);
139
- } catch (e) {
140
- var other = launcherIn(dest); // lost the race but theirs is valid
141
- if (other) { rmrf(stage); return other; }
142
- throw e;
143
- }
144
- } catch (e) {
145
- rmrf(stage);
146
- fail('download failed (' + e.message + ').\n URL: ' + url);
147
- }
148
- rmrf(stage);
149
-
150
- var ready = launcherIn(dest);
151
- if (!ready) fail('downloaded bundle is missing its launcher under ' + dest + '.');
152
- process.stderr.write('homegraph: bundle ready.\n');
153
- return ready;
154
- }
155
-
156
- function readVersion() {
157
- try {
158
- return require(path.join(__dirname, 'package.json')).version;
159
- } catch (e) {
160
- fail('could not read this package\'s version to locate a matching release.');
161
- }
162
- }
163
-
164
- // GET with manual redirect following (GitHub release URLs redirect to a CDN).
165
- function download(url, dest, redirectsLeft) {
166
- return new Promise(function (resolve, reject) {
167
- var https = require('https');
168
- // timeout is an idle/inactivity timeout — it won't kill a slow-but-progressing
169
- // download, only a stalled connection (so a blocked mirror fails fast with
170
- // guidance instead of hanging the user's command forever).
171
- var req = https.get(url, { headers: { 'User-Agent': 'homegraph-npm-shim' }, timeout: 30000 }, function (res) {
172
- var status = res.statusCode;
173
- if (status >= 300 && status < 400 && res.headers.location) {
174
- res.resume();
175
- if (redirectsLeft <= 0) { reject(new Error('too many redirects')); return; }
176
- download(new URL(res.headers.location, url).toString(), dest, redirectsLeft - 1).then(resolve, reject);
177
- return;
178
- }
179
- if (status !== 200) { res.resume(); reject(new Error('HTTP ' + status)); return; }
180
- var file = fs.createWriteStream(dest);
181
- res.on('error', reject);
182
- res.pipe(file);
183
- file.on('error', reject);
184
- file.on('finish', function () { file.close(function () { resolve(); }); });
185
- });
186
- req.on('timeout', function () { req.destroy(new Error('connection timed out')); });
187
- req.on('error', reject);
188
- });
189
- }
190
-
191
- // Best-effort integrity check. When the release publishes a SHA256SUMS file, the
192
- // downloaded archive MUST match its listed hash or we abort. When that file is
193
- // absent (older releases) or simply unreachable, we proceed the archive still
194
- // arrived from GitHub over TLS. So tampering/corruption is caught, while a
195
- // missing checksum never breaks an install.
196
- async function verifyChecksum(archivePath, asset, base, version) {
197
- var sumsPath = archivePath + '.SHA256SUMS';
198
- try {
199
- await download(base + '/v' + version + '/SHA256SUMS', sumsPath, 6);
200
- } catch (e) {
201
- return; // not published / unreachable → skip
202
- }
203
- var expected = null;
204
- var lines = fs.readFileSync(sumsPath, 'utf8').split('\n');
205
- for (var i = 0; i < lines.length; i++) {
206
- var m = lines[i].trim().match(/^([0-9a-fA-F]{64})\s+\*?(.+)$/);
207
- if (m && path.basename(m[2].trim()) === asset) { expected = m[1].toLowerCase(); break; }
208
- }
209
- if (!expected) return; // asset not listed → nothing to check
210
- var actual = require('crypto').createHash('sha256').update(fs.readFileSync(archivePath)).digest('hex');
211
- if (actual !== expected) {
212
- throw new Error('checksum mismatch for ' + asset +
213
- ' (expected ' + expected.slice(0, 12) + '…, got ' + actual.slice(0, 12) + '…)');
214
- }
215
- process.stderr.write('homegraph: checksum verified.\n');
216
- }
217
-
218
- // Extract via the system tar — present on macOS, Linux, and Windows 10+
219
- // (bsdtar reads .zip too). No third-party dependency in the shim.
220
- function extract(archive, destDir) {
221
- var args = isWindows
222
- ? ['-xf', archive, '-C', destDir, '--strip-components=1']
223
- : ['-xzf', archive, '-C', destDir, '--strip-components=1'];
224
- var res = childProcess.spawnSync('tar', args, { stdio: 'ignore' });
225
- if (res.error) throw new Error('tar unavailable: ' + res.error.message);
226
- if (res.status !== 0) throw new Error('tar exited ' + res.status);
227
- }
228
-
229
- function rmrf(p) {
230
- try { fs.rmSync(p, { recursive: true, force: true }); } catch (e) { /* best effort */ }
231
- }
232
-
233
- function fail(reason) {
234
- process.stderr.write(
235
- 'homegraph: no prebuilt bundle for ' + target + '.\n' +
236
- (reason ? 'homegraph: ' + reason + '\n' : '') +
237
- 'Expected the optional package ' + pkg + ' to be installed.\n' +
238
- 'A registry mirror (e.g. npmmirror/cnpm) that did not mirror the per-platform\n' +
239
- 'package is the usual cause. Fixes:\n' +
240
- ' - install from the official registry:\n' +
241
- ' npm i -g homegraph --registry=https://registry.npmjs.org\n' +
242
- ' - or use the standalone installer (no Node required):\n' +
243
- ' curl -fsSL https://raw.githubusercontent.com/' + REPO + '/main/install.sh | sh\n'
244
- );
245
- process.exit(1);
246
- }
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+ //
4
+ // npm thin-installer launcher for HomeGraph.
5
+ //
6
+ // The heavy artifact (a vendored Node runtime + the app) ships as a per-platform
7
+ // optionalDependency: homegraph-<platform>-<arch>. npm installs
8
+ // only the one matching the host, via each package's `os`/`cpu` fields (the
9
+ // esbuild pattern). This shim — run by the user's OWN Node — locates that bundle
10
+ // and execs its launcher, so the real work always runs on the bundled Node 24
11
+ // (with node:sqlite), regardless of the user's Node version. The user's Node is
12
+ // only ever a launcher; even an ancient version can run this file.
13
+ //
14
+ // Self-heal (issue #303): some registries — notably the npmmirror/cnpm mirrors,
15
+ // and some corporate proxies — don't reliably mirror the per-platform
16
+ // optionalDependencies. npm treats an unfetchable optional dep as success and
17
+ // silently skips it, so the bundle goes missing and every command fails. When
18
+ // the installed bundle can't be resolved, this shim falls back to downloading
19
+ // the matching bundle straight from GitHub Releases — the very archive
20
+ // install.sh uses — into a cache dir, then runs that. Knobs:
21
+ // HOMEGRAPH_NO_DOWNLOAD=1 disable the network fallback (print guidance)
22
+ // HOMEGRAPH_INSTALL_DIR=DIR cache location (default: ~/.homegraph)
23
+ // HOMEGRAPH_DOWNLOAD_BASE=URL release-download base (for mirrors/air-gapped)
24
+ //
25
+ // Wired up at release time as the main package's `bin`:
26
+ // "bin": { "homegraph": "npm-shim.js" }
27
+ // with the platform packages listed in `optionalDependencies`.
28
+
29
+ var childProcess = require('child_process');
30
+ var fs = require('fs');
31
+ var os = require('os');
32
+ var path = require('path');
33
+
34
+ var target = process.platform + '-' + process.arch; // e.g. darwin-arm64, linux-x64
35
+ var pkg = 'homegraph-' + target;
36
+ var isWindows = process.platform === 'win32';
37
+ var REPO = 'homegraph/homegraph';
38
+
39
+ main().catch(function (e) {
40
+ process.stderr.write('homegraph: ' + (e && e.message ? e.message : String(e)) + '\n');
41
+ process.exit(1);
42
+ });
43
+
44
+ async function main() {
45
+ // Happy path: the npm-installed optional dependency. Fall back to a download
46
+ // when the registry didn't deliver it.
47
+ var resolved = resolveInstalledBundle() || (await selfHealBundle());
48
+ var res = childProcess.spawnSync(resolved.command, resolved.args, { stdio: 'inherit', windowsHide: true });
49
+ if (res.error) {
50
+ process.stderr.write('homegraph: ' + res.error.message + '\n');
51
+ process.exit(1);
52
+ }
53
+ process.exit(res.status === null ? 1 : res.status);
54
+ }
55
+
56
+ // Resolve the launcher from the installed per-platform optionalDependency.
57
+ // Returns {command, args} or null if the package isn't installed.
58
+ function resolveInstalledBundle() {
59
+ try {
60
+ if (isWindows) {
61
+ // Modern Node refuses to spawn the bundle's .cmd directly (EINVAL, the
62
+ // CVE-2024-27980 hardening on Node 24), so invoke the bundled node.exe
63
+ // against the app entry point and pass --liftoff-only here.
64
+ var nodeExe = require.resolve(pkg + '/node.exe');
65
+ var entry = require.resolve(pkg + '/lib/dist/bin/homegraph.js');
66
+ return { command: nodeExe, args: liftoff(entry) };
67
+ }
68
+ return { command: require.resolve(pkg + '/bin/homegraph'), args: process.argv.slice(2) };
69
+ } catch (e) {
70
+ return null;
71
+ }
72
+ }
73
+
74
+ // Locate the launcher inside an extracted GitHub bundle directory (same
75
+ // node/lib/bin layout as the npm platform package). Returns {command, args} or
76
+ // null when the directory doesn't hold a usable bundle yet.
77
+ function launcherIn(dir) {
78
+ if (isWindows) {
79
+ var nodeExe = path.join(dir, 'node.exe');
80
+ var entry = path.join(dir, 'lib', 'dist', 'bin', 'homegraph.js');
81
+ if (fs.existsSync(nodeExe) && fs.existsSync(entry)) {
82
+ return { command: nodeExe, args: liftoff(entry) };
83
+ }
84
+ } else {
85
+ var launcher = path.join(dir, 'bin', 'homegraph');
86
+ if (fs.existsSync(launcher)) return { command: launcher, args: process.argv.slice(2) };
87
+ }
88
+ return null;
89
+ }
90
+
91
+ // --liftoff-only keeps tree-sitter's WASM grammars off V8's turboshaft tier to
92
+ // avoid the Zone OOM on Node >= 22 (issues #293/#298). The unix bin/homegraph
93
+ // launcher already passes it; on Windows we invoke node.exe directly so add it.
94
+ function liftoff(entry) {
95
+ return ['--liftoff-only', entry].concat(process.argv.slice(2));
96
+ }
97
+
98
+ // Download + cache the platform bundle from GitHub Releases. Returns
99
+ // {command, args}; exits the process with guidance if it can't.
100
+ async function selfHealBundle() {
101
+ var version = readVersion();
102
+ var bundlesDir = path.join(process.env.HOMEGRAPH_INSTALL_DIR || path.join(os.homedir(), '.homegraph'), 'bundles');
103
+ var dest = path.join(bundlesDir, target + '-' + version);
104
+
105
+ // Already downloaded by a previous run? Use it even when downloads are
106
+ // disabled — HOMEGRAPH_NO_DOWNLOAD blocks fetching, not a cached bundle.
107
+ var cached = launcherIn(dest);
108
+ if (cached) { pruneOldBundles(bundlesDir, dest); return cached; }
109
+
110
+ if (process.env.HOMEGRAPH_NO_DOWNLOAD) {
111
+ fail('the network fallback is disabled (HOMEGRAPH_NO_DOWNLOAD is set).');
112
+ }
113
+
114
+ var asset = 'homegraph-' + target + (isWindows ? '.zip' : '.tar.gz');
115
+ var base = process.env.HOMEGRAPH_DOWNLOAD_BASE || ('https://github.com/' + REPO + '/releases/download');
116
+ var url = base + '/v' + version + '/' + asset;
117
+
118
+ process.stderr.write(
119
+ 'homegraph: platform bundle missing (registry did not provide ' + pkg + ').\n' +
120
+ 'homegraph: downloading ' + asset + ' from GitHub Releases (' + version + ')...\n'
121
+ );
122
+
123
+ // Stage inside bundlesDir so the final rename is on the same filesystem (atomic,
124
+ // no EXDEV across tmpfs). Strip the archive's top-level homegraph-<target>/ dir.
125
+ fs.mkdirSync(bundlesDir, { recursive: true });
126
+ var stage = fs.mkdtempSync(path.join(bundlesDir, '.dl-'));
127
+ try {
128
+ var archivePath = path.join(stage, asset);
129
+ await download(url, archivePath, 6);
130
+ await verifyChecksum(archivePath, asset, base, version);
131
+ var extracted = path.join(stage, 'bundle');
132
+ fs.mkdirSync(extracted);
133
+ extract(archivePath, extracted);
134
+
135
+ var raced = launcherIn(dest); // another process may have finished meanwhile
136
+ if (raced) { rmrf(stage); return raced; }
137
+ try {
138
+ fs.renameSync(extracted, dest);
139
+ } catch (e) {
140
+ var other = launcherIn(dest); // lost the race but theirs is valid
141
+ if (other) { rmrf(stage); return other; }
142
+ throw e;
143
+ }
144
+ } catch (e) {
145
+ rmrf(stage);
146
+ fail('download failed (' + e.message + ').\n URL: ' + url);
147
+ }
148
+ rmrf(stage);
149
+
150
+ var ready = launcherIn(dest);
151
+ if (!ready) fail('downloaded bundle is missing its launcher under ' + dest + '.');
152
+ pruneOldBundles(bundlesDir, dest);
153
+ process.stderr.write('homegraph: bundle ready.\n');
154
+ return ready;
155
+ }
156
+
157
+ function readVersion() {
158
+ try {
159
+ return require(path.join(__dirname, 'package.json')).version;
160
+ } catch (e) {
161
+ fail('could not read this package\'s version to locate a matching release.');
162
+ }
163
+ }
164
+
165
+ // GET with manual redirect following (GitHub release URLs redirect to a CDN).
166
+ function download(url, dest, redirectsLeft) {
167
+ return new Promise(function (resolve, reject) {
168
+ var https = require('https');
169
+ // timeout is an idle/inactivity timeout it won't kill a slow-but-progressing
170
+ // download, only a stalled connection (so a blocked mirror fails fast with
171
+ // guidance instead of hanging the user's command forever).
172
+ var req = https.get(url, { headers: { 'User-Agent': 'homegraph-npm-shim' }, timeout: 30000 }, function (res) {
173
+ var status = res.statusCode;
174
+ if (status >= 300 && status < 400 && res.headers.location) {
175
+ res.resume();
176
+ if (redirectsLeft <= 0) { reject(new Error('too many redirects')); return; }
177
+ download(new URL(res.headers.location, url).toString(), dest, redirectsLeft - 1).then(resolve, reject);
178
+ return;
179
+ }
180
+ if (status !== 200) { res.resume(); reject(new Error('HTTP ' + status)); return; }
181
+ var file = fs.createWriteStream(dest);
182
+ res.on('error', reject);
183
+ res.pipe(file);
184
+ file.on('error', reject);
185
+ file.on('finish', function () { file.close(function () { resolve(); }); });
186
+ });
187
+ req.on('timeout', function () { req.destroy(new Error('connection timed out')); });
188
+ req.on('error', reject);
189
+ });
190
+ }
191
+
192
+ // Best-effort integrity check. When the release publishes a SHA256SUMS file, the
193
+ // downloaded archive MUST match its listed hash or we abort. When that file is
194
+ // absent (older releases) or simply unreachable, we proceed the archive still
195
+ // arrived from GitHub over TLS. So tampering/corruption is caught, while a
196
+ // missing checksum never breaks an install.
197
+ async function verifyChecksum(archivePath, asset, base, version) {
198
+ var sumsPath = archivePath + '.SHA256SUMS';
199
+ try {
200
+ await download(base + '/v' + version + '/SHA256SUMS', sumsPath, 6);
201
+ } catch (e) {
202
+ return; // not published / unreachable → skip
203
+ }
204
+ var expected = null;
205
+ var lines = fs.readFileSync(sumsPath, 'utf8').split('\n');
206
+ for (var i = 0; i < lines.length; i++) {
207
+ var m = lines[i].trim().match(/^([0-9a-fA-F]{64})\s+\*?(.+)$/);
208
+ if (m && path.basename(m[2].trim()) === asset) { expected = m[1].toLowerCase(); break; }
209
+ }
210
+ if (!expected) return; // asset not listed → nothing to check
211
+ var actual = require('crypto').createHash('sha256').update(fs.readFileSync(archivePath)).digest('hex');
212
+ if (actual !== expected) {
213
+ throw new Error('checksum mismatch for ' + asset +
214
+ ' (expected ' + expected.slice(0, 12) + '…, got ' + actual.slice(0, 12) + '…)');
215
+ }
216
+ process.stderr.write('homegraph: checksum verified.\n');
217
+ }
218
+
219
+ // Extract via the system tar present on macOS, Linux, and Windows 10+
220
+ // (bsdtar reads .zip too). No third-party dependency in the shim.
221
+ function extract(archive, destDir) {
222
+ var args = isWindows
223
+ ? ['-xf', archive, '-C', destDir, '--strip-components=1']
224
+ : ['-xzf', archive, '-C', destDir, '--strip-components=1'];
225
+ var res = childProcess.spawnSync('tar', args, { stdio: 'ignore', windowsHide: true });
226
+ if (res.error) throw new Error('tar unavailable: ' + res.error.message);
227
+ if (res.status !== 0) throw new Error('tar exited ' + res.status);
228
+ }
229
+
230
+ function rmrf(p) {
231
+ try { fs.rmSync(p, { recursive: true, force: true }); } catch (e) { /* best effort */ }
232
+ }
233
+
234
+ // Drop sibling bundles for OTHER versions of this same platform target, keeping
235
+ // only keepDir. The self-heal cache otherwise accumulates a full ~50 MB bundle
236
+ // per version forever (issue #1074). Best-effort: a locked/busy dir (a
237
+ // concurrent run still mapping an older node.exe on Windows) just stays — rmrf
238
+ // already swallows its own errors, and the readdir is guarded — so cleanup can
239
+ // never break a working command. Only this target's "<target>-<version>" dirs
240
+ // are touched; other platforms' bundles and the ".dl-*" staging dirs are left
241
+ // alone.
242
+ function pruneOldBundles(bundlesDir, keepDir) {
243
+ var keep = path.basename(keepDir);
244
+ try {
245
+ var names = fs.readdirSync(bundlesDir);
246
+ for (var i = 0; i < names.length; i++) {
247
+ var name = names[i];
248
+ if (name === keep) continue;
249
+ if (name.indexOf(target + '-') !== 0) continue;
250
+ rmrf(path.join(bundlesDir, name));
251
+ }
252
+ } catch (e) { /* best effort — never break a working run over cleanup */ }
253
+ }
254
+
255
+ function fail(reason) {
256
+ process.stderr.write(
257
+ 'homegraph: no prebuilt bundle for ' + target + '.\n' +
258
+ (reason ? 'homegraph: ' + reason + '\n' : '') +
259
+ 'Expected the optional package ' + pkg + ' to be installed.\n' +
260
+ 'A registry mirror (e.g. npmmirror/cnpm) that did not mirror the per-platform\n' +
261
+ 'package is the usual cause. Fixes:\n' +
262
+ ' - install from the official registry:\n' +
263
+ ' npm i -g homegraph --registry=https://registry.npmjs.org\n' +
264
+ ' - or use the standalone installer (no Node required):\n' +
265
+ ' curl -fsSL https://raw.githubusercontent.com/' + REPO + '/main/install.sh | sh\n'
266
+ );
267
+ process.exit(1);
268
+ }