@eyeauras/insight-cli 0.8.4 → 0.9.1

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 (609) hide show
  1. package/.cli-package-build.json +1 -1
  2. package/README.md +16 -23
  3. package/SKILL.md +6 -44
  4. package/dist/src/activity-audit.d.ts +33 -46
  5. package/dist/src/activity-audit.js +120 -195
  6. package/dist/src/analysis-default.d.ts +10 -2
  7. package/dist/src/analysis-default.js +62 -47
  8. package/dist/src/analysis-storage.d.ts +13 -13
  9. package/dist/src/analysis-storage.js +127 -258
  10. package/dist/src/artifacts.d.ts +5 -1
  11. package/dist/src/artifacts.js +31 -46
  12. package/dist/src/audit-commands.d.ts +6 -1
  13. package/dist/src/audit-commands.js +9 -2
  14. package/dist/src/audit-retention.d.ts +5 -23
  15. package/dist/src/audit-retention.js +37 -150
  16. package/dist/src/binary.js +4 -13
  17. package/dist/src/budgets.d.ts +2 -2
  18. package/dist/src/budgets.js +7 -9
  19. package/dist/src/capture.js +17 -30
  20. package/dist/src/cli.d.ts +9 -4
  21. package/dist/src/cli.js +288 -473
  22. package/dist/src/code-references.d.ts +2 -13
  23. package/dist/src/code-references.js +7 -99
  24. package/dist/src/context-diagnostics.d.ts +1 -23
  25. package/dist/src/context-diagnostics.js +1 -83
  26. package/dist/src/core/coordinator.d.ts +298 -0
  27. package/dist/src/core/coordinator.js +591 -0
  28. package/dist/src/core/layout.d.ts +51 -0
  29. package/dist/src/core/layout.js +55 -0
  30. package/dist/src/core/legacy-import.d.ts +55 -0
  31. package/dist/src/core/legacy-import.js +193 -0
  32. package/dist/src/cross-results.d.ts +3 -3
  33. package/dist/src/cross-results.js +4 -42
  34. package/dist/src/cross.js +2 -3
  35. package/dist/src/debugger-results.d.ts +1 -6
  36. package/dist/src/debugger-results.js +21 -153
  37. package/dist/src/debugger.d.ts +21 -11
  38. package/dist/src/debugger.js +106 -168
  39. package/dist/src/decode-results.d.ts +2 -1
  40. package/dist/src/decode-results.js +4 -20
  41. package/dist/src/diagnostic-error.d.ts +1 -1
  42. package/dist/src/diagnostic-error.js +4 -23
  43. package/dist/src/die.js +1 -23
  44. package/dist/src/dnspy-runtime.js +5 -12
  45. package/dist/src/dnspy.js +13 -28
  46. package/dist/src/dotnet-diagnostics.js +1 -1
  47. package/dist/src/extensions.d.ts +2 -3
  48. package/dist/src/extensions.js +14 -91
  49. package/dist/src/frida-worker.js +0 -20
  50. package/dist/src/frida.js +3 -26
  51. package/dist/src/function-boundaries.d.ts +2 -2
  52. package/dist/src/function-boundaries.js +9 -61
  53. package/dist/src/function-entries.d.ts +2 -2
  54. package/dist/src/function-entries.js +6 -36
  55. package/dist/src/function-inspection.d.ts +2 -2
  56. package/dist/src/function-inspection.js +17 -33
  57. package/dist/src/function-results.d.ts +1 -3
  58. package/dist/src/function-results.js +2 -13
  59. package/dist/src/hub/admin.d.ts +101 -0
  60. package/dist/src/hub/admin.js +314 -0
  61. package/dist/src/hub/autostart.d.ts +111 -0
  62. package/dist/src/hub/autostart.js +207 -0
  63. package/dist/src/hub/bundle.d.ts +33 -0
  64. package/dist/src/hub/bundle.js +25 -0
  65. package/dist/src/hub/client.d.ts +90 -0
  66. package/dist/src/hub/client.js +256 -0
  67. package/dist/src/hub/commands.d.ts +13 -0
  68. package/dist/src/hub/commands.js +280 -0
  69. package/dist/src/hub/contract.d.ts +87 -0
  70. package/dist/src/hub/contract.js +3 -0
  71. package/dist/src/hub/extensions.d.ts +41 -0
  72. package/dist/src/hub/extensions.js +3 -0
  73. package/dist/src/hub/ghidra.d.ts +70 -0
  74. package/dist/src/hub/ghidra.js +197 -0
  75. package/dist/src/hub/index.d.ts +6 -0
  76. package/dist/src/hub/index.js +7 -0
  77. package/dist/src/{work/store.d.ts → hub/ledger-store.d.ts} +57 -94
  78. package/dist/src/hub/ledger-store.js +919 -0
  79. package/dist/src/hub/ledger.d.ts +4 -0
  80. package/dist/src/hub/ledger.js +173 -0
  81. package/dist/src/hub/lock.d.ts +7 -0
  82. package/dist/src/hub/lock.js +53 -0
  83. package/dist/src/hub/repository.d.ts +45 -0
  84. package/dist/src/hub/repository.js +130 -0
  85. package/dist/src/hub/server.d.ts +86 -0
  86. package/dist/src/hub/server.js +414 -0
  87. package/dist/src/hub/settings.d.ts +36 -0
  88. package/dist/src/hub/settings.js +112 -0
  89. package/dist/src/hub/storage.d.ts +13 -0
  90. package/dist/src/hub/storage.js +46 -0
  91. package/dist/src/hub/store.d.ts +75 -0
  92. package/dist/src/hub/store.js +188 -0
  93. package/dist/src/ilspy.js +1 -1
  94. package/dist/src/internal-timing.d.ts +2 -9
  95. package/dist/src/internal-timing.js +2 -95
  96. package/dist/src/lldb.js +3 -15
  97. package/dist/src/llvm.js +0 -9
  98. package/dist/src/managed-heap.js +3 -7
  99. package/dist/src/managed-metadata.js +2 -5
  100. package/dist/src/memory-inputs.d.ts +1 -4
  101. package/dist/src/memory-inputs.js +10 -40
  102. package/dist/src/mitmproxy.d.ts +35 -4
  103. package/dist/src/mitmproxy.js +59 -40
  104. package/dist/src/model.d.ts +0 -73
  105. package/dist/src/model.js +0 -45
  106. package/dist/src/mutations.d.ts +1 -1
  107. package/dist/src/mutations.js +5 -10
  108. package/dist/src/native/contract.d.ts +130 -0
  109. package/dist/src/native/ghidra.d.ts +58 -0
  110. package/dist/src/native/ghidra.js +77 -0
  111. package/dist/src/native/host.d.ts +71 -0
  112. package/dist/src/native/host.js +265 -0
  113. package/dist/src/native/index.d.ts +13 -0
  114. package/dist/src/native/index.js +19 -0
  115. package/dist/src/native/jvm.d.ts +54 -0
  116. package/dist/src/native/jvm.js +47 -0
  117. package/dist/src/native/worker.d.ts +70 -0
  118. package/dist/src/native/worker.js +240 -0
  119. package/dist/src/native-inputs.d.ts +9 -14
  120. package/dist/src/native-inputs.js +22 -110
  121. package/dist/src/native-merge-patches.d.ts +2 -2
  122. package/dist/src/native-merge-patches.js +14 -14
  123. package/dist/src/persistent-client.js +53 -25
  124. package/dist/src/procmon.js +17 -31
  125. package/dist/src/program-files.d.ts +42 -0
  126. package/dist/src/program-files.js +148 -0
  127. package/dist/src/queries.js +2 -15
  128. package/dist/src/query-policy.d.ts +0 -2
  129. package/dist/src/query-policy.js +1 -14
  130. package/dist/src/research.d.ts +59 -238
  131. package/dist/src/research.js +212 -906
  132. package/dist/src/runtime-identity.d.ts +8 -0
  133. package/dist/src/runtime-identity.js +26 -0
  134. package/dist/src/runtime-manager.d.ts +1 -11
  135. package/dist/src/runtime-manager.js +10 -145
  136. package/dist/src/runtime-selection.d.ts +1 -1
  137. package/dist/src/runtime-selection.js +5 -37
  138. package/dist/src/saved-materials.js +8 -51
  139. package/dist/src/scripts.d.ts +1 -1
  140. package/dist/src/scripts.js +15 -15
  141. package/dist/src/sdk-contracts.js +2 -2
  142. package/dist/src/sdk.js +8 -8
  143. package/dist/src/sevenzip.js +1 -3
  144. package/dist/src/strace.js +0 -3
  145. package/dist/src/string-anchors.d.ts +2 -3
  146. package/dist/src/string-anchors.js +8 -101
  147. package/dist/src/text-window.d.ts +5 -4
  148. package/dist/src/text-window.js +4 -4
  149. package/dist/src/tool-runtime/archives.d.ts +1 -1
  150. package/dist/src/tool-runtime/archives.js +11 -20
  151. package/dist/src/tool-runtime/catalog.js +2 -5
  152. package/dist/src/tool-runtime/commands.js +1 -3
  153. package/dist/src/tool-runtime/deadline.js +2 -7
  154. package/dist/src/tool-runtime/definition.js +1 -31
  155. package/dist/src/tool-runtime/identity.js +6 -87
  156. package/dist/src/tool-runtime/installer.d.ts +2 -6
  157. package/dist/src/tool-runtime/installer.js +14 -76
  158. package/dist/src/tool-runtime/java-arguments.js +4 -10
  159. package/dist/src/tool-runtime/launch-worker.js +2 -8
  160. package/dist/src/tool-runtime/run.d.ts +2 -0
  161. package/dist/src/tool-runtime/run.js +20 -8
  162. package/dist/src/tool-runtime/store.d.ts +3 -3
  163. package/dist/src/tool-runtime/store.js +21 -83
  164. package/dist/src/tool-runtime/supervisor.d.ts +6 -11
  165. package/dist/src/tool-runtime/supervisor.js +155 -214
  166. package/dist/src/tool-runtime/windows-helper.d.ts +5 -0
  167. package/dist/src/tool-runtime/windows-helper.js +13 -0
  168. package/dist/src/tool-runtime/windows-job.d.ts +5 -5
  169. package/dist/src/tool-runtime/windows-job.js +13 -31
  170. package/dist/src/tshark.js +14 -27
  171. package/dist/src/ui-results.d.ts +3 -2
  172. package/dist/src/ui-results.js +16 -53
  173. package/dist/src/ui.d.ts +12 -13
  174. package/dist/src/ui.js +32 -70
  175. package/dist/src/version-tracking.d.ts +25 -39
  176. package/dist/src/version-tracking.js +70 -174
  177. package/dist/src/windbg.d.ts +1 -1
  178. package/dist/src/windbg.js +2 -8
  179. package/dist/src/work/client.d.ts +63 -0
  180. package/dist/src/work/client.js +163 -0
  181. package/dist/src/work/commands.d.ts +3 -1
  182. package/dist/src/work/commands.js +158 -184
  183. package/dist/src/work/dashboard.d.ts +2 -2
  184. package/dist/src/work/dashboard.js +7 -8
  185. package/dist/src/work/legacy.d.ts +8 -0
  186. package/dist/src/work/legacy.js +70 -0
  187. package/dist/src/work/model.d.ts +0 -3
  188. package/dist/src/work/model.js +0 -10
  189. package/dist/src/work/timing.d.ts +3 -3
  190. package/dist/src/work/timing.js +21 -25
  191. package/dist/src/workspace.d.ts +4 -250
  192. package/dist/src/workspace.js +11 -699
  193. package/node_modules/@eyeauras/cli-factory/README.md +6 -0
  194. package/node_modules/@eyeauras/cli-factory/dist/src/cli.d.ts.map +1 -1
  195. package/node_modules/@eyeauras/cli-factory/dist/src/cli.js +76 -28
  196. package/node_modules/@eyeauras/cli-factory/dist/src/cli.js.map +1 -1
  197. package/node_modules/@eyeauras/cli-factory/dist/src/command.d.ts +1 -1
  198. package/node_modules/@eyeauras/cli-factory/dist/src/command.d.ts.map +1 -1
  199. package/node_modules/@eyeauras/cli-factory/dist/src/command.js +1 -0
  200. package/node_modules/@eyeauras/cli-factory/dist/src/command.js.map +1 -1
  201. package/node_modules/@eyeauras/cli-factory/dist/src/errors.d.ts +1 -1
  202. package/node_modules/@eyeauras/cli-factory/dist/src/errors.d.ts.map +1 -1
  203. package/node_modules/@eyeauras/cli-factory/dist/src/errors.js +18 -6
  204. package/node_modules/@eyeauras/cli-factory/dist/src/errors.js.map +1 -1
  205. package/node_modules/@eyeauras/cli-factory/dist/src/file-publication.d.ts +44 -0
  206. package/node_modules/@eyeauras/cli-factory/dist/src/file-publication.d.ts.map +1 -0
  207. package/node_modules/@eyeauras/cli-factory/dist/src/{profile-file.js → file-publication.js} +41 -113
  208. package/node_modules/@eyeauras/cli-factory/dist/src/file-publication.js.map +1 -0
  209. package/node_modules/@eyeauras/cli-factory/dist/src/help.d.ts +5 -0
  210. package/node_modules/@eyeauras/cli-factory/dist/src/help.d.ts.map +1 -0
  211. package/node_modules/@eyeauras/cli-factory/dist/src/help.js +17 -0
  212. package/node_modules/@eyeauras/cli-factory/dist/src/help.js.map +1 -0
  213. package/node_modules/@eyeauras/cli-factory/dist/src/index.d.ts +9 -4
  214. package/node_modules/@eyeauras/cli-factory/dist/src/index.d.ts.map +1 -1
  215. package/node_modules/@eyeauras/cli-factory/dist/src/index.js +5 -2
  216. package/node_modules/@eyeauras/cli-factory/dist/src/index.js.map +1 -1
  217. package/node_modules/@eyeauras/cli-factory/dist/src/json-rpc.d.ts.map +1 -1
  218. package/node_modules/@eyeauras/cli-factory/dist/src/json-rpc.js +11 -18
  219. package/node_modules/@eyeauras/cli-factory/dist/src/json-rpc.js.map +1 -1
  220. package/node_modules/@eyeauras/cli-factory/dist/src/output-write.d.ts +10 -0
  221. package/node_modules/@eyeauras/cli-factory/dist/src/output-write.d.ts.map +1 -0
  222. package/node_modules/@eyeauras/cli-factory/dist/src/output-write.js +69 -0
  223. package/node_modules/@eyeauras/cli-factory/dist/src/output-write.js.map +1 -0
  224. package/node_modules/@eyeauras/cli-factory/dist/src/output.d.ts +3 -1
  225. package/node_modules/@eyeauras/cli-factory/dist/src/output.d.ts.map +1 -1
  226. package/node_modules/@eyeauras/cli-factory/dist/src/output.js +74 -14
  227. package/node_modules/@eyeauras/cli-factory/dist/src/output.js.map +1 -1
  228. package/node_modules/@eyeauras/cli-factory/dist/src/pagination.d.ts +3 -0
  229. package/node_modules/@eyeauras/cli-factory/dist/src/pagination.d.ts.map +1 -0
  230. package/node_modules/@eyeauras/cli-factory/dist/src/pagination.js +9 -0
  231. package/node_modules/@eyeauras/cli-factory/dist/src/pagination.js.map +1 -0
  232. package/node_modules/@eyeauras/cli-factory/dist/src/permissions.d.ts.map +1 -1
  233. package/node_modules/@eyeauras/cli-factory/dist/src/permissions.js +3 -1
  234. package/node_modules/@eyeauras/cli-factory/dist/src/permissions.js.map +1 -1
  235. package/node_modules/@eyeauras/cli-factory/dist/src/stream-result.d.ts +16 -0
  236. package/node_modules/@eyeauras/cli-factory/dist/src/stream-result.d.ts.map +1 -0
  237. package/node_modules/@eyeauras/cli-factory/dist/src/stream-result.js +83 -0
  238. package/node_modules/@eyeauras/cli-factory/dist/src/stream-result.js.map +1 -0
  239. package/node_modules/@eyeauras/cli-factory/dist/src/types.d.ts +5 -0
  240. package/node_modules/@eyeauras/cli-factory/dist/src/types.d.ts.map +1 -1
  241. package/node_modules/@eyeauras/cli-factory/dist/src/view.d.ts +49 -7
  242. package/node_modules/@eyeauras/cli-factory/dist/src/view.d.ts.map +1 -1
  243. package/node_modules/@eyeauras/cli-factory/dist/src/view.js +83 -6
  244. package/node_modules/@eyeauras/cli-factory/dist/src/view.js.map +1 -1
  245. package/node_modules/@eyeauras/cli-factory/package.json +1 -1
  246. package/node_modules/@eyeauras/cli-factory-ipc/dist/cli-host.proto +19 -19
  247. package/node_modules/@eyeauras/cli-factory-ipc/dist/src/build.d.ts +7 -1
  248. package/node_modules/@eyeauras/cli-factory-ipc/dist/src/build.d.ts.map +1 -1
  249. package/node_modules/@eyeauras/cli-factory-ipc/dist/src/build.js +9 -4
  250. package/node_modules/@eyeauras/cli-factory-ipc/dist/src/build.js.map +1 -1
  251. package/node_modules/@eyeauras/cli-factory-ipc/dist/src/host.d.ts.map +1 -1
  252. package/node_modules/@eyeauras/cli-factory-ipc/dist/src/host.js +5 -4
  253. package/node_modules/@eyeauras/cli-factory-ipc/dist/src/host.js.map +1 -1
  254. package/node_modules/@eyeauras/cli-factory-ipc/dist/src/package-build.d.ts +11 -1
  255. package/node_modules/@eyeauras/cli-factory-ipc/dist/src/package-build.d.ts.map +1 -1
  256. package/node_modules/@eyeauras/cli-factory-ipc/dist/src/package-build.js +85 -57
  257. package/node_modules/@eyeauras/cli-factory-ipc/dist/src/package-build.js.map +1 -1
  258. package/node_modules/@eyeauras/cli-factory-ipc/package.json +2 -2
  259. package/package.json +4 -5
  260. package/references/native/InsightAnalyzerOptions.java +10 -0
  261. package/references/native/InsightAnchorScan.java +1 -11
  262. package/references/native/InsightCodeReferences.java +2 -3
  263. package/references/native/InsightCopyType.java +24 -0
  264. package/references/native/InsightFunctionBoundaries.java +0 -1
  265. package/references/native/InsightFunctionDatabases.java +20 -16
  266. package/references/native/InsightHelperCall.java +17 -0
  267. package/references/native/InsightHubServer.java +214 -0
  268. package/references/native/InsightNativeHost.java +112 -0
  269. package/references/native/InsightPlugins.java +0 -1
  270. package/references/native/InsightPythonWheels.java +3 -2
  271. package/references/native/InsightResearchQueries.java +3 -4
  272. package/references/native/InsightResearchView.java +4 -10
  273. package/references/native/InsightSdkFiles.java +7 -15
  274. package/references/native/InsightSdkScript.java +1 -4
  275. package/references/native/InsightSdkTools.java +36 -97
  276. package/references/native/InsightSdkTypes.java +13 -43
  277. package/references/native/InsightStringAnchors.java +1 -3
  278. package/references/native/InsightTraceState.java +13 -96
  279. package/references/native/InsightTraceTools.java +3 -5
  280. package/references/native/InsightVersionTracking.java +0 -6
  281. package/references/native/{HeadlessProgramMergeManager.java → InsightWcMerge.java} +17 -24
  282. package/references/native/InsightWcOps.java +449 -0
  283. package/references/native/InsightWcWorker.java +142 -0
  284. package/references/native/NATIVE-MERGE-NOTICE.txt +4 -8
  285. package/runtime/GhidraMCP-7.0.0.jar +0 -0
  286. package/runtime/managed/insight-heap/README.md +3 -3
  287. package/runtime/managed/insight-managed/README.md +3 -3
  288. package/runtime/native/binary/README.md +5 -4
  289. package/runtime/native/windows/DirectoryAlias.cs +24 -0
  290. package/runtime/native/windows/Insight.Windows.csproj +27 -0
  291. package/runtime/native/windows/Native.cs +36 -0
  292. package/runtime/native/windows/OwnedJob.cs +86 -0
  293. package/runtime/native/windows/Program.cs +50 -0
  294. package/runtime/native/windows/RegistryRedirect.cs +42 -0
  295. package/runtime/native/windows/insight-windows-x64.exe +0 -0
  296. package/runtime/native/windows/packages.lock.json +35 -0
  297. package/runtime/native/windows/provenance.json +17 -0
  298. package/runtime/research-view.provenance.json +6 -7
  299. package/runtime/toolbox.json +33 -114
  300. package/skill-bundle/insight-artifacts/SKILL.md +5 -19
  301. package/skill-bundle/insight-binary/SKILL.md +5 -35
  302. package/skill-bundle/insight-capture/SKILL.md +5 -45
  303. package/skill-bundle/insight-cli/SKILL.md +6 -44
  304. package/skill-bundle/insight-die/SKILL.md +5 -38
  305. package/skill-bundle/insight-dnspy/SKILL.md +5 -54
  306. package/skill-bundle/insight-dotnet-dump/SKILL.md +5 -35
  307. package/skill-bundle/insight-dotnet-stack/SKILL.md +5 -28
  308. package/skill-bundle/insight-dotnet-trace/SKILL.md +5 -34
  309. package/skill-bundle/insight-frida/SKILL.md +5 -56
  310. package/skill-bundle/insight-ghidra/SKILL.md +14 -113
  311. package/skill-bundle/insight-ilspy/SKILL.md +5 -34
  312. package/skill-bundle/insight-interop/SKILL.md +5 -43
  313. package/skill-bundle/insight-lldb/SKILL.md +5 -43
  314. package/skill-bundle/insight-llvm/SKILL.md +5 -45
  315. package/skill-bundle/insight-managed-heap/SKILL.md +5 -32
  316. package/skill-bundle/insight-managed-metadata/SKILL.md +5 -41
  317. package/skill-bundle/insight-mitmproxy/SKILL.md +5 -51
  318. package/skill-bundle/insight-overview/SKILL.md +5 -68
  319. package/skill-bundle/insight-procmon/SKILL.md +5 -38
  320. package/skill-bundle/insight-re/SKILL.md +10 -127
  321. package/skill-bundle/insight-sevenzip/SKILL.md +5 -31
  322. package/skill-bundle/insight-strace/SKILL.md +5 -35
  323. package/skill-bundle/insight-tshark/SKILL.md +5 -38
  324. package/skill-bundle/insight-windbg/SKILL.md +5 -35
  325. package/skill-bundle/manifest.json +1 -1
  326. package/skills/insight-artifacts/SKILL.md +5 -19
  327. package/skills/insight-binary/SKILL.md +5 -35
  328. package/skills/insight-capture/SKILL.md +5 -45
  329. package/skills/insight-die/SKILL.md +5 -38
  330. package/skills/insight-dnspy/SKILL.md +5 -54
  331. package/skills/insight-dotnet-dump/SKILL.md +5 -35
  332. package/skills/insight-dotnet-stack/SKILL.md +5 -28
  333. package/skills/insight-dotnet-trace/SKILL.md +5 -34
  334. package/skills/insight-frida/SKILL.md +5 -56
  335. package/skills/insight-ghidra/SKILL.md +14 -113
  336. package/skills/insight-ilspy/SKILL.md +5 -34
  337. package/skills/insight-interop/SKILL.md +5 -43
  338. package/skills/insight-lldb/SKILL.md +5 -43
  339. package/skills/insight-llvm/SKILL.md +5 -45
  340. package/skills/insight-managed-heap/SKILL.md +5 -32
  341. package/skills/insight-managed-metadata/SKILL.md +5 -41
  342. package/skills/insight-mitmproxy/SKILL.md +5 -51
  343. package/skills/insight-overview/SKILL.md +5 -68
  344. package/skills/insight-procmon/SKILL.md +5 -38
  345. package/skills/insight-re/SKILL.md +10 -127
  346. package/skills/insight-sevenzip/SKILL.md +5 -31
  347. package/skills/insight-strace/SKILL.md +5 -35
  348. package/skills/insight-tshark/SKILL.md +5 -38
  349. package/skills/insight-windbg/SKILL.md +5 -35
  350. package/dist/src/administration-results.d.ts +0 -1
  351. package/dist/src/administration-results.js +0 -84
  352. package/dist/src/administration.d.ts +0 -14
  353. package/dist/src/administration.js +0 -134
  354. package/dist/src/archive-contract.d.ts +0 -6
  355. package/dist/src/archive-contract.js +0 -108
  356. package/dist/src/archive.d.ts +0 -12
  357. package/dist/src/archive.js +0 -116
  358. package/dist/src/comment-effects.d.ts +0 -3
  359. package/dist/src/comment-effects.js +0 -55
  360. package/dist/src/context-credential.d.ts +0 -18
  361. package/dist/src/context-credential.js +0 -44
  362. package/dist/src/contexts.d.ts +0 -387
  363. package/dist/src/contexts.js +0 -2805
  364. package/dist/src/coordinator.d.ts +0 -41
  365. package/dist/src/coordinator.js +0 -160
  366. package/dist/src/cross-peer.d.ts +0 -20
  367. package/dist/src/cross-peer.js +0 -53
  368. package/dist/src/data-effects.d.ts +0 -3
  369. package/dist/src/data-effects.js +0 -103
  370. package/dist/src/debugger-caller.d.ts +0 -17
  371. package/dist/src/debugger-caller.js +0 -129
  372. package/dist/src/debugger-launch.d.ts +0 -2
  373. package/dist/src/debugger-launch.js +0 -17
  374. package/dist/src/debugger-supervisor.js +0 -179
  375. package/dist/src/directory-identity.d.ts +0 -6
  376. package/dist/src/directory-identity.js +0 -45
  377. package/dist/src/documentation-effects.d.ts +0 -5
  378. package/dist/src/documentation-effects.js +0 -56
  379. package/dist/src/function-effects.d.ts +0 -4
  380. package/dist/src/function-effects.js +0 -112
  381. package/dist/src/ghidra-processes.d.ts +0 -6
  382. package/dist/src/ghidra-processes.js +0 -138
  383. package/dist/src/ghidra.d.ts +0 -50
  384. package/dist/src/ghidra.js +0 -468
  385. package/dist/src/initial-model.d.ts +0 -7
  386. package/dist/src/initial-model.js +0 -115
  387. package/dist/src/initial-progress.d.ts +0 -4
  388. package/dist/src/initial-progress.js +0 -74
  389. package/dist/src/inline-script.d.ts +0 -15
  390. package/dist/src/inline-script.js +0 -61
  391. package/dist/src/legacy-migration.d.ts +0 -37
  392. package/dist/src/legacy-migration.js +0 -238
  393. package/dist/src/lifecycle.d.ts +0 -77
  394. package/dist/src/lifecycle.js +0 -315
  395. package/dist/src/merge.d.ts +0 -29
  396. package/dist/src/merge.js +0 -66
  397. package/dist/src/mutation-effects.d.ts +0 -4
  398. package/dist/src/mutation-effects.js +0 -321
  399. package/dist/src/native-queries.d.ts +0 -2
  400. package/dist/src/native-queries.js +0 -24
  401. package/dist/src/native-service.d.ts +0 -40
  402. package/dist/src/native-service.js +0 -406
  403. package/dist/src/projects.d.ts +0 -31
  404. package/dist/src/projects.js +0 -302
  405. package/dist/src/prototype-cli.d.ts +0 -8
  406. package/dist/src/prototype-cli.js +0 -155
  407. package/dist/src/query-results.d.ts +0 -2
  408. package/dist/src/query-results.js +0 -224
  409. package/dist/src/research-view.d.ts +0 -6
  410. package/dist/src/research-view.js +0 -9
  411. package/dist/src/sdk-files.d.ts +0 -29
  412. package/dist/src/sdk-files.js +0 -249
  413. package/dist/src/server.d.ts +0 -102
  414. package/dist/src/server.js +0 -663
  415. package/dist/src/storage-gc.d.ts +0 -23
  416. package/dist/src/storage-gc.js +0 -600
  417. package/dist/src/store.d.ts +0 -33
  418. package/dist/src/store.js +0 -178
  419. package/dist/src/sync-policy.d.ts +0 -22
  420. package/dist/src/sync-policy.js +0 -129
  421. package/dist/src/timed-backend.d.ts +0 -3
  422. package/dist/src/timed-backend.js +0 -24
  423. package/dist/src/timing-report.d.ts +0 -32
  424. package/dist/src/timing-report.js +0 -74
  425. package/dist/src/tool-runtime/native-process-proof.d.ts +0 -2
  426. package/dist/src/tool-runtime/native-process-proof.js +0 -26
  427. package/dist/src/transport.d.ts +0 -60
  428. package/dist/src/transport.js +0 -223
  429. package/dist/src/unresolved-guidance.d.ts +0 -46
  430. package/dist/src/unresolved-guidance.js +0 -55
  431. package/dist/src/work/backup.d.ts +0 -66
  432. package/dist/src/work/backup.js +0 -446
  433. package/dist/src/work/store.js +0 -1107
  434. package/dist/src/worker-lease.d.ts +0 -17
  435. package/dist/src/worker-lease.js +0 -50
  436. package/node_modules/@eyeauras/cli-factory/dist/src/profile-file.d.ts +0 -37
  437. package/node_modules/@eyeauras/cli-factory/dist/src/profile-file.d.ts.map +0 -1
  438. package/node_modules/@eyeauras/cli-factory/dist/src/profile-file.js.map +0 -1
  439. package/references/InsightRepositoryProbe.java +0 -55
  440. package/references/administration.md +0 -34
  441. package/references/agent-execution.md +0 -36
  442. package/references/agent-setup.md +0 -60
  443. package/references/archive.md +0 -32
  444. package/references/artifacts.md +0 -52
  445. package/references/debugger.md +0 -64
  446. package/references/extensions-and-sync.md +0 -125
  447. package/references/ilspy.md +0 -33
  448. package/references/managed-runtime.md +0 -162
  449. package/references/native/InsightArchivePayloads.java +0 -36
  450. package/references/native/InsightBlockTransfer.java +0 -57
  451. package/references/native/InsightGuiMain.java +0 -33
  452. package/references/native/InsightHeadlessMain.java +0 -18
  453. package/references/native/InsightImportProgress.java +0 -60
  454. package/references/native/InsightInitialImport.java +0 -48
  455. package/references/native/InsightInitialJournal.java +0 -57
  456. package/references/native/InsightInitialPublication.java +0 -142
  457. package/references/native/InsightInitialRecovery.java +0 -131
  458. package/references/native/InsightInlineExecutor.java +0 -143
  459. package/references/native/InsightInlineScript.java +0 -14
  460. package/references/native/InsightNativeCheckout.java +0 -487
  461. package/references/native/InsightNativeFingerprint.java +0 -80
  462. package/references/native/InsightNativeMigration.java +0 -155
  463. package/references/native/InsightNativeRead.java +0 -80
  464. package/references/native/InsightNativeReceipt.java +0 -31
  465. package/references/native/InsightNativeService.java +0 -43
  466. package/references/native/InsightNativeView.java +0 -40
  467. package/references/native/InsightOfflineAuthenticator.java +0 -20
  468. package/references/native/InsightOwnedScripts.java +0 -170
  469. package/references/native/InsightProjectFiles.java +0 -92
  470. package/references/native/InsightPublicationRecovery.java +0 -63
  471. package/references/native/InsightServerAdministration.java +0 -82
  472. package/references/native/InsightServerInit.java +0 -62
  473. package/references/native/InsightServerMain.java +0 -43
  474. package/references/native/InsightServerProbe.java +0 -29
  475. package/references/native/InsightSnapshotFields.java +0 -74
  476. package/references/native/InsightSnapshotInspect.java +0 -191
  477. package/references/native/InsightSnapshotPublisher.java +0 -123
  478. package/references/native/InsightStopDebugger.java +0 -20
  479. package/references/native/InsightTraceInspect.java +0 -24
  480. package/references/native/InsightWorkerLease.java +0 -132
  481. package/references/native-workflows.md +0 -124
  482. package/references/persistent-client.mjs +0 -147
  483. package/references/persistent.md +0 -90
  484. package/references/query-semantics.md +0 -109
  485. package/references/recovery.md +0 -235
  486. package/references/research.md +0 -296
  487. package/references/setup.md +0 -135
  488. package/references/sparse-navigation.md +0 -173
  489. package/references/storage.md +0 -139
  490. package/references/work-tracking.md +0 -261
  491. package/runtime/native/file-version.ps1 +0 -7
  492. package/runtime/native/mitmproxy/bridge.py +0 -180
  493. package/runtime/native/windows-job/DirectoryAlias.cs +0 -24
  494. package/runtime/native/windows-job/Insight.WindowsJob.csproj +0 -1
  495. package/runtime/native/windows-job/Insight.WindowsJob.dll +0 -0
  496. package/runtime/native/windows-job/OwnedJob.cs +0 -79
  497. package/runtime/native/windows-job/RegistryRedirect.cs +0 -45
  498. package/runtime/native/windows-job/packages.lock.json +0 -21
  499. package/runtime/native/windows-job/provenance.json +0 -16
  500. package/runtime/native/windows-job/windows-job.ps1 +0 -8
  501. package/skill-bundle/insight-artifacts/references/agent-execution.md +0 -36
  502. package/skill-bundle/insight-artifacts/references/artifacts.md +0 -52
  503. package/skill-bundle/insight-artifacts/references/recovery.md +0 -235
  504. package/skill-bundle/insight-artifacts/references/storage.md +0 -139
  505. package/skill-bundle/insight-binary/references/agent-execution.md +0 -36
  506. package/skill-bundle/insight-capture/references/agent-execution.md +0 -36
  507. package/skill-bundle/insight-cli/references/agent-execution.md +0 -36
  508. package/skill-bundle/insight-cli/references/agent-setup.md +0 -60
  509. package/skill-bundle/insight-cli/references/archive.md +0 -32
  510. package/skill-bundle/insight-cli/references/managed-runtime.md +0 -162
  511. package/skill-bundle/insight-cli/references/persistent-client.mjs +0 -147
  512. package/skill-bundle/insight-cli/references/persistent.md +0 -90
  513. package/skill-bundle/insight-cli/references/recovery.md +0 -235
  514. package/skill-bundle/insight-cli/references/setup.md +0 -135
  515. package/skill-bundle/insight-cli/references/storage.md +0 -139
  516. package/skill-bundle/insight-die/references/agent-execution.md +0 -36
  517. package/skill-bundle/insight-dnspy/references/agent-execution.md +0 -36
  518. package/skill-bundle/insight-dotnet-dump/references/agent-execution.md +0 -36
  519. package/skill-bundle/insight-dotnet-stack/references/agent-execution.md +0 -36
  520. package/skill-bundle/insight-dotnet-trace/references/agent-execution.md +0 -36
  521. package/skill-bundle/insight-frida/references/agent-execution.md +0 -36
  522. package/skill-bundle/insight-ghidra/references/administration.md +0 -34
  523. package/skill-bundle/insight-ghidra/references/agent-execution.md +0 -36
  524. package/skill-bundle/insight-ghidra/references/archive.md +0 -32
  525. package/skill-bundle/insight-ghidra/references/artifacts.md +0 -52
  526. package/skill-bundle/insight-ghidra/references/debugger.md +0 -64
  527. package/skill-bundle/insight-ghidra/references/extensions-and-sync.md +0 -125
  528. package/skill-bundle/insight-ghidra/references/managed-runtime.md +0 -162
  529. package/skill-bundle/insight-ghidra/references/native-workflows.md +0 -124
  530. package/skill-bundle/insight-ghidra/references/persistent-client.mjs +0 -147
  531. package/skill-bundle/insight-ghidra/references/persistent.md +0 -90
  532. package/skill-bundle/insight-ghidra/references/query-semantics.md +0 -109
  533. package/skill-bundle/insight-ghidra/references/recovery.md +0 -235
  534. package/skill-bundle/insight-ghidra/references/research.md +0 -296
  535. package/skill-bundle/insight-ghidra/references/setup.md +0 -135
  536. package/skill-bundle/insight-ghidra/references/sparse-navigation.md +0 -173
  537. package/skill-bundle/insight-ghidra/references/storage.md +0 -139
  538. package/skill-bundle/insight-ilspy/references/agent-execution.md +0 -36
  539. package/skill-bundle/insight-ilspy/references/ilspy.md +0 -33
  540. package/skill-bundle/insight-interop/references/agent-execution.md +0 -36
  541. package/skill-bundle/insight-lldb/references/agent-execution.md +0 -36
  542. package/skill-bundle/insight-llvm/references/agent-execution.md +0 -36
  543. package/skill-bundle/insight-managed-heap/references/agent-execution.md +0 -36
  544. package/skill-bundle/insight-managed-metadata/references/agent-execution.md +0 -36
  545. package/skill-bundle/insight-mitmproxy/references/agent-execution.md +0 -36
  546. package/skill-bundle/insight-overview/references/agent-execution.md +0 -36
  547. package/skill-bundle/insight-procmon/references/agent-execution.md +0 -36
  548. package/skill-bundle/insight-re/references/agent-execution.md +0 -36
  549. package/skill-bundle/insight-re/references/artifacts.md +0 -52
  550. package/skill-bundle/insight-re/references/persistent-client.mjs +0 -147
  551. package/skill-bundle/insight-re/references/persistent.md +0 -90
  552. package/skill-bundle/insight-re/references/recovery.md +0 -235
  553. package/skill-bundle/insight-re/references/storage.md +0 -139
  554. package/skill-bundle/insight-re/references/work-tracking.md +0 -261
  555. package/skill-bundle/insight-sevenzip/references/agent-execution.md +0 -36
  556. package/skill-bundle/insight-strace/references/agent-execution.md +0 -36
  557. package/skill-bundle/insight-tshark/references/agent-execution.md +0 -36
  558. package/skill-bundle/insight-windbg/references/agent-execution.md +0 -36
  559. package/skills/insight-artifacts/references/agent-execution.md +0 -36
  560. package/skills/insight-artifacts/references/artifacts.md +0 -52
  561. package/skills/insight-artifacts/references/recovery.md +0 -235
  562. package/skills/insight-artifacts/references/storage.md +0 -139
  563. package/skills/insight-binary/references/agent-execution.md +0 -36
  564. package/skills/insight-capture/references/agent-execution.md +0 -36
  565. package/skills/insight-die/references/agent-execution.md +0 -36
  566. package/skills/insight-dnspy/references/agent-execution.md +0 -36
  567. package/skills/insight-dotnet-dump/references/agent-execution.md +0 -36
  568. package/skills/insight-dotnet-stack/references/agent-execution.md +0 -36
  569. package/skills/insight-dotnet-trace/references/agent-execution.md +0 -36
  570. package/skills/insight-frida/references/agent-execution.md +0 -36
  571. package/skills/insight-ghidra/references/administration.md +0 -34
  572. package/skills/insight-ghidra/references/agent-execution.md +0 -36
  573. package/skills/insight-ghidra/references/archive.md +0 -32
  574. package/skills/insight-ghidra/references/artifacts.md +0 -52
  575. package/skills/insight-ghidra/references/debugger.md +0 -64
  576. package/skills/insight-ghidra/references/extensions-and-sync.md +0 -125
  577. package/skills/insight-ghidra/references/managed-runtime.md +0 -162
  578. package/skills/insight-ghidra/references/native-workflows.md +0 -124
  579. package/skills/insight-ghidra/references/persistent-client.mjs +0 -147
  580. package/skills/insight-ghidra/references/persistent.md +0 -90
  581. package/skills/insight-ghidra/references/query-semantics.md +0 -109
  582. package/skills/insight-ghidra/references/recovery.md +0 -235
  583. package/skills/insight-ghidra/references/research.md +0 -296
  584. package/skills/insight-ghidra/references/setup.md +0 -135
  585. package/skills/insight-ghidra/references/sparse-navigation.md +0 -173
  586. package/skills/insight-ghidra/references/storage.md +0 -139
  587. package/skills/insight-ilspy/references/agent-execution.md +0 -36
  588. package/skills/insight-ilspy/references/ilspy.md +0 -33
  589. package/skills/insight-interop/references/agent-execution.md +0 -36
  590. package/skills/insight-lldb/references/agent-execution.md +0 -36
  591. package/skills/insight-llvm/references/agent-execution.md +0 -36
  592. package/skills/insight-managed-heap/references/agent-execution.md +0 -36
  593. package/skills/insight-managed-metadata/references/agent-execution.md +0 -36
  594. package/skills/insight-mitmproxy/references/agent-execution.md +0 -36
  595. package/skills/insight-overview/references/agent-execution.md +0 -36
  596. package/skills/insight-procmon/references/agent-execution.md +0 -36
  597. package/skills/insight-re/references/agent-execution.md +0 -36
  598. package/skills/insight-re/references/artifacts.md +0 -52
  599. package/skills/insight-re/references/persistent-client.mjs +0 -147
  600. package/skills/insight-re/references/persistent.md +0 -90
  601. package/skills/insight-re/references/recovery.md +0 -235
  602. package/skills/insight-re/references/storage.md +0 -139
  603. package/skills/insight-re/references/work-tracking.md +0 -261
  604. package/skills/insight-sevenzip/references/agent-execution.md +0 -36
  605. package/skills/insight-strace/references/agent-execution.md +0 -36
  606. package/skills/insight-tshark/references/agent-execution.md +0 -36
  607. package/skills/insight-windbg/references/agent-execution.md +0 -36
  608. /package/dist/src/{debugger-supervisor.d.ts → native/contract.js} +0 -0
  609. /package/runtime/native/{windows-job → windows}/NuGet.Config +0 -0
@@ -0,0 +1,207 @@
1
+ // OS autostart registration of `hub run` (docs/HUB.md, Autostart). The OS registration is the only record:
2
+ // nothing here stores an "installed" flag, and a removed registration is never re-created implicitly.
3
+ import { execFile } from 'node:child_process';
4
+ import { mkdir, rm, stat, writeFile } from 'node:fs/promises';
5
+ import { homedir, tmpdir, userInfo } from 'node:os';
6
+ import { dirname, join } from 'node:path';
7
+ import { randomUUID } from 'node:crypto';
8
+ import { fileURLToPath } from 'node:url';
9
+ import { hubError } from './settings.js';
10
+ export const exec = (file, args) => new Promise(resolve => execFile(file, args, { windowsHide: true, timeout: 60000, maxBuffer: 1 << 22 }, (error, stdout, stderr) => resolve({ code: error ? (typeof error.code === 'number' ? error.code : 1) : 0, stdout: String(stdout), stderr: String(stderr || (error && !stdout ? error.message : '')) })));
11
+ /** Command line the registration runs: the installed CLI entry point, so an upgrade applies on the next start. */
12
+ export const hubCommandLine = () => ({ executable: process.execPath, arguments: [fileURLToPath(new URL('../bin.js', import.meta.url)), 'hub', 'run'] });
13
+ export const autostartName = (appName = 'insight-cli') => appName + '-hub';
14
+ const xml = (value) => value.replace(/[&<>"']/g, c => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&apos;' }[c]));
15
+ const windowsQuote = (value) => /[\s"]/.test(value) ? '"' + value.replace(/(\\*)"/g, '$1$1\\"').replace(/(\\+)$/, '$1$1') + '"' : value;
16
+ /** Task Scheduler definition. `logon` runs as the interactive user without admin; `boot` uses S4U and needs admin. */
17
+ export function windowsTaskXml(input) {
18
+ const trigger = input.at === 'boot' ? '<BootTrigger><Enabled>true</Enabled></BootTrigger>' : `<LogonTrigger><Enabled>true</Enabled><UserId>${xml(input.user)}</UserId></LogonTrigger>`;
19
+ // conhost --headless keeps the console hub without a visible window.
20
+ const args = ['--headless', input.executable, ...input.arguments].map(windowsQuote).join(' ');
21
+ return `<?xml version="1.0" encoding="UTF-16"?>
22
+ <Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
23
+ <RegistrationInfo><Description>insight-cli hub</Description></RegistrationInfo>
24
+ <Triggers>${trigger}</Triggers>
25
+ <Principals><Principal id="Author"><UserId>${xml(input.user)}</UserId><LogonType>${input.at === 'boot' ? 'S4U' : 'InteractiveToken'}</LogonType><RunLevel>LeastPrivilege</RunLevel></Principal></Principals>
26
+ <Settings>
27
+ <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
28
+ <DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>
29
+ <StopIfGoingOnBatteries>false</StopIfGoingOnBatteries>
30
+ <ExecutionTimeLimit>PT0S</ExecutionTimeLimit>
31
+ <AllowHardTerminate>true</AllowHardTerminate>
32
+ <StartWhenAvailable>true</StartWhenAvailable>
33
+ <IdleSettings><StopOnIdleEnd>false</StopOnIdleEnd><RestartOnIdle>false</RestartOnIdle></IdleSettings>
34
+ <Enabled>true</Enabled>
35
+ </Settings>
36
+ <Actions Context="Author"><Exec><Command>conhost.exe</Command><Arguments>${xml(args)}</Arguments></Exec></Actions>
37
+ </Task>
38
+ `;
39
+ }
40
+ export function systemdUnit(input) {
41
+ const quote = (v) => /[\s"'\\$%]/.test(v) ? '"' + v.replace(/[\\"]/g, '\\$&').replace(/\$/g, '$$$$').replace(/%/g, '%%') + '"' : v;
42
+ return `[Unit]
43
+ Description=insight-cli hub
44
+ After=network-online.target
45
+ Wants=network-online.target
46
+
47
+ [Service]
48
+ Type=simple
49
+ ExecStart=${[input.executable, ...input.arguments].map(quote).join(' ')}
50
+ Restart=on-failure
51
+ RestartSec=5
52
+
53
+ [Install]
54
+ WantedBy=default.target
55
+ `;
56
+ }
57
+ export function launchdPlist(input) {
58
+ return `<?xml version="1.0" encoding="UTF-8"?>
59
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
60
+ <plist version="1.0">
61
+ <dict>
62
+ <key>Label</key><string>${xml(input.label)}</string>
63
+ <key>ProgramArguments</key>
64
+ <array>
65
+ ${[input.executable, ...input.arguments].map(v => ` <string>${xml(v)}</string>`).join('\n')}
66
+ </array>
67
+ <key>RunAtLoad</key><true/>
68
+ <key>KeepAlive</key><false/>
69
+ <key>ProcessType</key><string>Background</string>
70
+ </dict>
71
+ </plist>
72
+ `;
73
+ }
74
+ const failed = (action, r) => hubError('hub.unavailable', `${action} failed: ${(r.stderr || r.stdout).trim().slice(0, 1000)}`);
75
+ export class WindowsAutostart {
76
+ name;
77
+ run;
78
+ command;
79
+ mechanism = 'Task Scheduler';
80
+ constructor(name, run = exec, command = hubCommandLine) {
81
+ this.name = name;
82
+ this.run = run;
83
+ this.command = command;
84
+ }
85
+ async probe() {
86
+ const r = await this.run('schtasks.exe', ['/Query', '/TN', this.name, '/XML', 'ONE']);
87
+ if (r.code !== 0)
88
+ return { installed: false, name: this.name, mechanism: this.mechanism };
89
+ return { installed: true, at: /<BootTrigger/.test(r.stdout) ? 'boot' : 'logon', name: this.name, mechanism: this.mechanism };
90
+ }
91
+ async install(at, extra = []) {
92
+ const user = (process.env.USERDOMAIN ? process.env.USERDOMAIN + '\\' : '') + userInfo().username, { executable, arguments: base } = this.command(), args = [...base, ...extra];
93
+ const file = join(tmpdir(), 'insight-hub-task-' + randomUUID() + '.xml');
94
+ await writeFile(file, Buffer.concat([Buffer.from([0xff, 0xfe]), Buffer.from(windowsTaskXml({ at, user, executable, arguments: args }), 'utf16le')]));
95
+ try {
96
+ const r = await this.run('schtasks.exe', ['/Create', '/TN', this.name, '/XML', file, '/F']);
97
+ if (r.code !== 0)
98
+ throw failed(at === 'boot' ? 'Registering the boot task (needs an elevated shell once)' : 'Registering the logon task', r);
99
+ }
100
+ finally {
101
+ await rm(file, { force: true });
102
+ }
103
+ return { installed: true, at, name: this.name, mechanism: this.mechanism };
104
+ }
105
+ async uninstall() {
106
+ const r = await this.run('schtasks.exe', ['/Delete', '/TN', this.name, '/F']);
107
+ // A failed removal of a task that does not exist is no failure: nothing was registered.
108
+ if (r.code !== 0 && (await this.probe()).installed)
109
+ throw failed('Removing the task', r);
110
+ return { installed: false, name: this.name, mechanism: this.mechanism };
111
+ }
112
+ async start() { const r = await this.run('schtasks.exe', ['/Run', '/TN', this.name]); if (r.code !== 0)
113
+ throw failed('Starting the hub task', r); }
114
+ }
115
+ export class SystemdAutostart {
116
+ name;
117
+ run;
118
+ command;
119
+ home;
120
+ mechanism = 'systemd user unit';
121
+ constructor(name, run = exec, command = hubCommandLine, home = homedir()) {
122
+ this.name = name;
123
+ this.run = run;
124
+ this.command = command;
125
+ this.home = home;
126
+ }
127
+ get unit() { return this.name + '.service'; }
128
+ get file() { return join(process.env.XDG_CONFIG_HOME || join(this.home, '.config'), 'systemd', 'user', this.unit); }
129
+ async probe() {
130
+ const enabled = await this.run('systemctl', ['--user', 'is-enabled', this.unit]);
131
+ if (enabled.code !== 0 || enabled.stdout.trim() !== 'enabled')
132
+ return { installed: false, name: this.name, mechanism: this.mechanism };
133
+ const linger = await this.run('loginctl', ['show-user', userInfo().username, '--property=Linger', '--value']);
134
+ return { installed: true, at: linger.stdout.trim() === 'yes' ? 'boot' : 'logon', name: this.name, mechanism: this.mechanism };
135
+ }
136
+ async install(at, extra = []) {
137
+ const { executable, arguments: args } = this.command();
138
+ await mkdir(dirname(this.file), { recursive: true });
139
+ await writeFile(this.file, systemdUnit({ executable, arguments: [...args, ...extra] }));
140
+ for (const args of [['--user', 'daemon-reload'], ['--user', 'enable', this.unit]]) {
141
+ const r = await this.run('systemctl', args);
142
+ if (r.code !== 0)
143
+ throw failed('systemctl ' + args.join(' '), r);
144
+ }
145
+ if (at === 'boot') {
146
+ const r = await this.run('loginctl', ['enable-linger', userInfo().username]);
147
+ if (r.code !== 0)
148
+ throw failed('loginctl enable-linger', r);
149
+ }
150
+ return { installed: true, at, name: this.name, mechanism: this.mechanism };
151
+ }
152
+ async uninstall() {
153
+ await this.run('systemctl', ['--user', 'disable', this.unit]);
154
+ await rm(this.file, { force: true });
155
+ await this.run('systemctl', ['--user', 'daemon-reload']);
156
+ return { installed: false, name: this.name, mechanism: this.mechanism };
157
+ }
158
+ async start() { const r = await this.run('systemctl', ['--user', 'start', this.unit]); if (r.code !== 0)
159
+ throw failed('Starting the hub unit', r); }
160
+ }
161
+ export class LaunchdAutostart {
162
+ name;
163
+ run;
164
+ command;
165
+ home;
166
+ uid;
167
+ mechanism = 'launchd LaunchAgent';
168
+ constructor(name, run = exec, command = hubCommandLine, home = homedir(), uid = userInfo().uid) {
169
+ this.name = name;
170
+ this.run = run;
171
+ this.command = command;
172
+ this.home = home;
173
+ this.uid = uid;
174
+ }
175
+ get label() { return 'com.insight-cli.' + this.name; }
176
+ get file() { return join(this.home, 'Library', 'LaunchAgents', this.label + '.plist'); }
177
+ async probe() {
178
+ const present = await stat(this.file).then(s => s.isFile(), () => false);
179
+ return present ? { installed: true, at: 'logon', name: this.name, mechanism: this.mechanism } : { installed: false, name: this.name, mechanism: this.mechanism };
180
+ }
181
+ async install(at, extra = []) {
182
+ if (at === 'boot')
183
+ throw hubError('hub.invalid', 'macOS supports only --at logon (a LaunchAgent).');
184
+ const { executable, arguments: args } = this.command();
185
+ await mkdir(dirname(this.file), { recursive: true });
186
+ await writeFile(this.file, launchdPlist({ label: this.label, executable, arguments: [...args, ...extra] }));
187
+ await this.run('launchctl', ['bootout', `gui/${this.uid}/${this.label}`]);
188
+ const r = await this.run('launchctl', ['bootstrap', `gui/${this.uid}`, this.file]);
189
+ if (r.code !== 0)
190
+ throw failed('launchctl bootstrap', r);
191
+ return { installed: true, at: 'logon', name: this.name, mechanism: this.mechanism };
192
+ }
193
+ async uninstall() {
194
+ await this.run('launchctl', ['bootout', `gui/${this.uid}/${this.label}`]);
195
+ await rm(this.file, { force: true });
196
+ return { installed: false, name: this.name, mechanism: this.mechanism };
197
+ }
198
+ async start() { const r = await this.run('launchctl', ['kickstart', `gui/${this.uid}/${this.label}`]); if (r.code !== 0)
199
+ throw failed('Starting the LaunchAgent', r); }
200
+ }
201
+ export function platformAutostart(name = autostartName(), platform = process.platform, run = exec) {
202
+ if (platform === 'win32')
203
+ return new WindowsAutostart(name, run);
204
+ if (platform === 'darwin')
205
+ return new LaunchdAutostart(name, run);
206
+ return new SystemdAutostart(name, run);
207
+ }
@@ -0,0 +1,33 @@
1
+ import type { HubProject, HubTarget } from './contract.js';
2
+ import type { GhidraItem } from './ghidra.js';
3
+ import type { DiskItem } from './repository.js';
4
+ export declare const BUNDLE_FILE = "bundle.json";
5
+ export interface BundleProgram {
6
+ path: string;
7
+ fileId: string;
8
+ versions: number[];
9
+ checkouts: string[];
10
+ }
11
+ export interface Bundle {
12
+ schema: 1;
13
+ format: 'insight-hub-project';
14
+ createdAt: string;
15
+ /** Where the project came from: a hub (id, address) or a legacy profile. */
16
+ source: {
17
+ hubId?: string;
18
+ address?: string;
19
+ legacyProfile?: string;
20
+ };
21
+ /** Ghidra runtime of the source hub; import requires the same one. Null for a legacy profile. */
22
+ runtimeFingerprint: string | null;
23
+ project: HubProject;
24
+ targets: HubTarget[];
25
+ programs: BundleProgram[];
26
+ blobs: {
27
+ sha256: string;
28
+ }[];
29
+ extensions: string[];
30
+ }
31
+ export declare const programOf: (item: GhidraItem | DiskItem) => BundleProgram;
32
+ /** Reads bundle.json; a bundle is written by hub export (or a legacy import), so only its kind is checked. */
33
+ export declare function readBundle(directory: string): Promise<Bundle>;
@@ -0,0 +1,25 @@
1
+ // Project bundle of `hub export` / `hub import` (docs/HUB.md, Moving between hubs). A bundle is a directory:
2
+ // bundle.json manifest (written last; its presence marks a complete bundle)
3
+ // repository/** the Ghidra Server repository directory
4
+ // blobs/<sha256> binaries of the project's targets
5
+ // extensions/<prefix>/** data of each hub extension
6
+ // Programs list version numbers and checkout ids as Ghidra holds them.
7
+ import { readFile } from 'node:fs/promises';
8
+ import { join } from 'node:path';
9
+ import { invalid } from './settings.js';
10
+ export const BUNDLE_FILE = 'bundle.json';
11
+ export const programOf = (item) => ({ path: item.path, fileId: item.fileId,
12
+ versions: item.versions.map(v => typeof v === 'number' ? v : v.version).sort((a, b) => a - b), checkouts: item.checkouts.map(c => c.id).sort() });
13
+ /** Reads bundle.json; a bundle is written by hub export (or a legacy import), so only its kind is checked. */
14
+ export async function readBundle(directory) {
15
+ let value;
16
+ try {
17
+ value = JSON.parse(await readFile(join(directory, BUNDLE_FILE), 'utf8'));
18
+ }
19
+ catch (error) {
20
+ return invalid(`${directory} is not a complete project bundle (${BUNDLE_FILE}: ${error.message}).`);
21
+ }
22
+ if (value?.schema !== 1 || value.format !== 'insight-hub-project')
23
+ invalid(`${join(directory, BUNDLE_FILE)} is not an insight hub project bundle.`);
24
+ return value;
25
+ }
@@ -0,0 +1,90 @@
1
+ import type { CommandContext } from '@eyeauras/cli-factory';
2
+ import { type HubSettings } from '../core/layout.js';
3
+ import type { GhidraEndpoint, HubClient, HubProject, HubStatus, HubTarget } from './contract.js';
4
+ import { type Autostart } from './autostart.js';
5
+ import type { HubRuntime } from './ghidra.js';
6
+ /** A value, or a function that computes it when it is first needed. */
7
+ export type Lazy<T> = T | (() => T);
8
+ /**
9
+ * `hub.unavailable` for a request that never reached the hub (nothing listens: a local hub that idled out). Such a
10
+ * request may be sent again after reconnecting, whatever it does.
11
+ */
12
+ export declare function unreachableError(url: string, error: unknown): import("@eyeauras/cli-factory").CliError;
13
+ /** True for an error of a request that did not reach the hub (see unreachableError). */
14
+ export declare const notReached: (error: unknown) => boolean;
15
+ export declare class HttpHubClient implements HubClient {
16
+ readonly url: string;
17
+ private readonly runtimeSource?;
18
+ readonly client: string;
19
+ private readonly timeoutMs;
20
+ connectedStatus?: HubStatus;
21
+ private runtimeValue?;
22
+ /** `runtime` is offered to a hub without one; a function is called only when it is needed. */
23
+ constructor(url: string, runtimeSource?: Lazy<HubRuntime | undefined>, client?: string, timeoutMs?: number);
24
+ get runtime(): HubRuntime | undefined;
25
+ private request;
26
+ private json;
27
+ status(): Promise<HubStatus>;
28
+ ensureGhidra(runtimeFingerprint: string, offer?: {
29
+ java: string;
30
+ ghidraHome: string;
31
+ }): Promise<GhidraEndpoint>;
32
+ projects(): Promise<HubProject[]>;
33
+ /**
34
+ * The project, created when absent. A new project needs Ghidra Server for its repository: a local hub without a
35
+ * runtime adopts this client's one first; without a runtime on either side the error says to install one.
36
+ */
37
+ project(name: string): Promise<HubProject>;
38
+ /** The project when it exists; never creates it, so it needs no Ghidra Server. */
39
+ existingProject(name: string): Promise<HubProject | undefined>;
40
+ targets(projectId: string): Promise<HubTarget[]>;
41
+ target(projectId: string, targetId: string): Promise<HubTarget>;
42
+ registerTarget(projectId: string, input: {
43
+ sha256: string;
44
+ name: string;
45
+ size?: number;
46
+ }): Promise<{
47
+ target: HubTarget;
48
+ created: boolean;
49
+ }>;
50
+ hasBlob(sha256: string): Promise<boolean>;
51
+ shutdown(): Promise<void>;
52
+ /** Hub administration (admin.ts): export, import, state, purge, remove-target, checkouts, release, gc. */
53
+ admin<T = Record<string, unknown>>(operation: string, body: Record<string, unknown>): Promise<T>;
54
+ putBlob(sha256: string, file: string): Promise<boolean>;
55
+ getBlob(sha256: string, destination: string): Promise<void>;
56
+ }
57
+ /** Runtime of the calling profile, passed to a hub it starts (absent when Ghidra is not installed). */
58
+ export declare function profileRuntime(c: CommandContext): HubRuntime | undefined;
59
+ /** The configured hub data root, else the default below the installation storage base. A broken storage default is an error, never a different, empty hub. */
60
+ export declare function hubDataRoot(c: Pick<CommandContext, 'appArguments'>, settings: HubSettings): string;
61
+ /** Log of a hub started detached or by the OS (stdout/stderr and the hub's own log lines). */
62
+ export declare const hubLogPath: (dataRoot: string) => string;
63
+ /** -1, 0 or 1 by semantic version precedence; undefined when either is not `major.minor.patch[-pre]`. */
64
+ export declare function compareVersions(a: string, b: string): number | undefined;
65
+ /** `hub run` arguments that pin a started hub to these settings and runtime. */
66
+ export declare function hubRunArguments(settings: HubSettings, dataRoot: string, runtime?: HubRuntime): string[];
67
+ /** `hub run` flags of an initial runtime (used only by a hub that has none recorded). */
68
+ export declare const runtimeArguments: (runtime?: HubRuntime) => string[];
69
+ /**
70
+ * A local hub is restarted for this CLI only when this CLI is newer (never back and forth between two installations)
71
+ * and nothing uses it: no Ghidra clients and no other request in progress.
72
+ */
73
+ export declare const restartForUpgrade: (s: HubStatus, version: string) => boolean;
74
+ export interface ConnectOptions {
75
+ settings: HubSettings;
76
+ /** Data root and runtime of a hub this call starts; a function is called only when a hub is started. */
77
+ dataRoot: Lazy<string>;
78
+ runtime?: Lazy<HubRuntime | undefined>;
79
+ version?: string;
80
+ autostart?: Autostart;
81
+ /** Starts a detached `hub run` with these arguments and data root; replaced in tests. */
82
+ spawnHub?: (args: string[], dataRoot: string) => void;
83
+ startTimeoutMs?: number;
84
+ }
85
+ /** Starts `hub run` detached in its data root; its stdout and stderr go to hub.log there. */
86
+ export declare function spawnDetachedHub(args: string[], dataRoot: string): void;
87
+ /** Connects per settings, starting a local hub when needed. Exported for tests; connectHub supplies the context. */
88
+ export declare function connect(o: ConnectOptions): Promise<HttpHubClient>;
89
+ /** Connects to the configured hub; the data root and the profile runtime are read only when a local hub is started. */
90
+ export declare function connectHub(c: CommandContext): Promise<HubClient>;
@@ -0,0 +1,256 @@
1
+ // HubClient over HTTP and connectHub (docs/HUB.md, On-demand start and Upgrade).
2
+ import { runtimeIdentity } from '../runtime-identity.js';
3
+ import { spawn } from 'node:child_process';
4
+ import { randomUUID } from 'node:crypto';
5
+ import { closeSync, createReadStream, createWriteStream, mkdirSync, openSync } from 'node:fs';
6
+ import { mkdir, rename, rm } from 'node:fs/promises';
7
+ import { dirname, join } from 'node:path';
8
+ import { Readable } from 'node:stream';
9
+ import { pipeline } from 'node:stream/promises';
10
+ import { HUB_API_VERSION, clientUserName, defaultHubDataRoot } from '../core/layout.js';
11
+ import { packageVersion } from '../package-version.js';
12
+ import { storageDefault } from '../analysis-default.js';
13
+ import { analysisDirectory } from '../analysis-storage.js';
14
+ import { runtimeSelection } from '../runtime-selection.js';
15
+ import { autostartName, hubCommandLine, platformAutostart } from './autostart.js';
16
+ import { hubError, hubUrl, readHubSettings } from './settings.js';
17
+ const codes = ['hub.unavailable', 'hub.incompatible', 'hub.not_found', 'hub.invalid', 'hub.runtime_mismatch', 'hub.runtime_missing', 'hub.frozen', 'hub.moved'];
18
+ const resolveLazy = (value) => typeof value === 'function' ? value() : value;
19
+ /**
20
+ * `hub.unavailable` for a request that never reached the hub (nothing listens: a local hub that idled out). Such a
21
+ * request may be sent again after reconnecting, whatever it does.
22
+ */
23
+ export function unreachableError(url, error) {
24
+ const cause = error.cause, failure = hubError('hub.unavailable', `Hub at ${url} is unavailable: ${cause instanceof Error ? cause.message : error.message}`);
25
+ if (cause?.code === 'ECONNREFUSED')
26
+ Object.defineProperty(failure, 'notReached', { value: true });
27
+ return failure;
28
+ }
29
+ /** True for an error of a request that did not reach the hub (see unreachableError). */
30
+ export const notReached = (error) => error?.notReached === true;
31
+ export class HttpHubClient {
32
+ url;
33
+ runtimeSource;
34
+ client;
35
+ timeoutMs;
36
+ connectedStatus;
37
+ runtimeValue;
38
+ /** `runtime` is offered to a hub without one; a function is called only when it is needed. */
39
+ constructor(url, runtimeSource, client = clientUserName(), timeoutMs = 300_000) {
40
+ this.url = url;
41
+ this.runtimeSource = runtimeSource;
42
+ this.client = client;
43
+ this.timeoutMs = timeoutMs;
44
+ }
45
+ get runtime() { return (this.runtimeValue ??= { value: resolveLazy(this.runtimeSource) }).value; }
46
+ async request(method, path, init = {}) {
47
+ let response;
48
+ try {
49
+ response = await fetch(this.url + path, { method, headers: { 'x-insight-client': this.client, ...(init.body !== undefined ? { 'content-type': 'application/json' } : {}), ...(init.raw ? { 'content-type': 'application/octet-stream' } : {}) },
50
+ body: init.raw ?? (init.body === undefined ? undefined : JSON.stringify(init.body)), signal: AbortSignal.timeout(init.timeoutMs ?? this.timeoutMs), ...(init.raw ? { duplex: 'half' } : {}) });
51
+ }
52
+ catch (error) {
53
+ throw unreachableError(this.url, error);
54
+ }
55
+ if (response.ok || init.missing && response.status === 404)
56
+ return response;
57
+ let code = 'hub.unavailable', message = `Hub ${method} ${path} failed with HTTP ${response.status}.`;
58
+ try {
59
+ const e = (await response.json()).error;
60
+ if (e?.code && codes.includes(e.code))
61
+ code = e.code;
62
+ if (e?.message)
63
+ message = e.message;
64
+ }
65
+ catch { }
66
+ throw hubError(code, message);
67
+ }
68
+ async json(method, path, body, timeoutMs) { return await (await this.request(method, path, { body, timeoutMs })).json(); }
69
+ status() { return this.json('GET', '/status', undefined, 30_000); }
70
+ ensureGhidra(runtimeFingerprint, offer) {
71
+ // A local hub without this runtime may adopt it; the paths are offered only when they belong to that fingerprint.
72
+ const own = offer ?? (this.runtime?.fingerprint === runtimeFingerprint ? this.runtime : undefined);
73
+ return this.json('POST', '/ghidra/ensure', { runtimeFingerprint, ...(own ? { java: own.java, ghidraHome: own.ghidraHome } : {}) }, 300_000);
74
+ }
75
+ projects() { return this.json('GET', '/projects'); }
76
+ /**
77
+ * The project, created when absent. A new project needs Ghidra Server for its repository: a local hub without a
78
+ * runtime adopts this client's one first; without a runtime on either side the error says to install one.
79
+ */
80
+ async project(name) {
81
+ try {
82
+ return await this.json('POST', '/projects', { name }, 300_000);
83
+ }
84
+ catch (error) {
85
+ const code = error.code;
86
+ // Creating a project fails on the runtime only when the hub has none (an older hub of this API calls that a mismatch).
87
+ if (code !== 'hub.runtime_missing' && code !== 'hub.runtime_mismatch')
88
+ throw error;
89
+ const runtime = this.runtime;
90
+ if (!runtime) {
91
+ throw hubError('hub.runtime_missing', `Hub project ${name} does not exist yet, and creating it needs Ghidra Server. The hub has no Ghidra runtime and this profile has none installed: run \`insight-cli ghidra install\`, then retry.`);
92
+ }
93
+ await this.ensureGhidra(runtime.fingerprint);
94
+ return this.json('POST', '/projects', { name }, 300_000);
95
+ }
96
+ }
97
+ /** The project when it exists; never creates it, so it needs no Ghidra Server. */
98
+ async existingProject(name) { return (await this.projects()).find(p => p.name === name); }
99
+ targets(projectId) { return this.json('GET', `/projects/${encodeURIComponent(projectId)}/targets`); }
100
+ target(projectId, targetId) { return this.json('GET', `/projects/${encodeURIComponent(projectId)}/targets/${encodeURIComponent(targetId)}`); }
101
+ registerTarget(projectId, input) {
102
+ return this.json('POST', `/projects/${encodeURIComponent(projectId)}/targets`, { ...input, createdBy: this.client });
103
+ }
104
+ async hasBlob(sha256) { return (await this.request('HEAD', '/blobs/' + sha256, { missing: true })).status === 200; }
105
+ async shutdown() { await this.json('POST', '/shutdown'); }
106
+ /** Hub administration (admin.ts): export, import, state, purge, remove-target, checkouts, release, gc. */
107
+ admin(operation, body) { return this.json('POST', '/admin/' + operation, body, 6 * 3_600_000); }
108
+ async putBlob(sha256, file) {
109
+ if (await this.hasBlob(sha256))
110
+ return false;
111
+ await (await this.request('PUT', '/blobs/' + sha256, { raw: Readable.toWeb(createReadStream(file)), timeoutMs: 3_600_000 })).arrayBuffer();
112
+ return true;
113
+ }
114
+ async getBlob(sha256, destination) {
115
+ const response = await this.request('GET', '/blobs/' + sha256, { timeoutMs: 3_600_000 });
116
+ await mkdir(dirname(destination), { recursive: true });
117
+ const temporary = destination + '.download-' + randomUUID();
118
+ try {
119
+ await pipeline(Readable.fromWeb(response.body), createWriteStream(temporary, { flags: 'wx' }));
120
+ await rename(temporary, destination);
121
+ }
122
+ finally {
123
+ await rm(temporary, { force: true });
124
+ }
125
+ }
126
+ }
127
+ /** Runtime of the calling profile, passed to a hub it starts (absent when Ghidra is not installed). */
128
+ export function profileRuntime(c) {
129
+ try {
130
+ const s = runtimeSelection(c.appArguments.AppDataDirectory, analysisDirectory(c));
131
+ return s && !s.uninstalledAt ? { java: s.java, ghidraHome: s.ghidraHome, fingerprint: runtimeIdentity(s.ghidraHome) } : undefined;
132
+ }
133
+ catch {
134
+ return;
135
+ }
136
+ }
137
+ /** The configured hub data root, else the default below the installation storage base. A broken storage default is an error, never a different, empty hub. */
138
+ export function hubDataRoot(c, settings) {
139
+ if (settings.dataRoot)
140
+ return settings.dataRoot;
141
+ return defaultHubDataRoot(c.appArguments.RoamingAppDataDirectory, storageDefault(c)?.base, c.appArguments.AppName);
142
+ }
143
+ /** Log of a hub started detached or by the OS (stdout/stderr and the hub's own log lines). */
144
+ export const hubLogPath = (dataRoot) => join(dataRoot, 'hub.log');
145
+ /** -1, 0 or 1 by semantic version precedence; undefined when either is not `major.minor.patch[-pre]`. */
146
+ export function compareVersions(a, b) {
147
+ const parse = (v) => /^v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+.*)?$/.exec(v.trim());
148
+ const x = parse(a), y = parse(b);
149
+ if (!x || !y)
150
+ return;
151
+ for (let i = 1; i <= 3; i++) {
152
+ const d = Number(x[i]) - Number(y[i]);
153
+ if (d)
154
+ return Math.sign(d);
155
+ }
156
+ if (!x[4] || !y[4])
157
+ return x[4] ? -1 : y[4] ? 1 : 0;
158
+ const p = x[4].split('.'), q = y[4].split('.');
159
+ for (let i = 0; i < Math.max(p.length, q.length); i++) {
160
+ if (p[i] === undefined)
161
+ return -1;
162
+ if (q[i] === undefined)
163
+ return 1;
164
+ const m = /^\d+$/.test(p[i]), n = /^\d+$/.test(q[i]);
165
+ if (m && n) {
166
+ const d = Number(p[i]) - Number(q[i]);
167
+ if (d)
168
+ return Math.sign(d);
169
+ }
170
+ else if (m !== n)
171
+ return m ? -1 : 1;
172
+ else if (p[i] !== q[i])
173
+ return p[i] < q[i] ? -1 : 1;
174
+ }
175
+ return 0;
176
+ }
177
+ /** `hub run` arguments that pin a started hub to these settings and runtime. */
178
+ export function hubRunArguments(settings, dataRoot, runtime) {
179
+ return ['--data-root', dataRoot, '--listen', settings.listen, '--port', String(settings.port), ...runtimeArguments(runtime)];
180
+ }
181
+ /** `hub run` flags of an initial runtime (used only by a hub that has none recorded). */
182
+ export const runtimeArguments = (runtime) => runtime ? ['--java', runtime.java, '--ghidra-home', runtime.ghidraHome, '--fingerprint', runtime.fingerprint] : [];
183
+ const connectedClients = (s) => s.ghidra.running ? Number(s.ghidra.clients ?? 1) : 0;
184
+ /**
185
+ * A local hub is restarted for this CLI only when this CLI is newer (never back and forth between two installations)
186
+ * and nothing uses it: no Ghidra clients and no other request in progress.
187
+ */
188
+ export const restartForUpgrade = (s, version) => compareVersions(version, s.version) === 1 && connectedClients(s) === 0 &&
189
+ Number(s.activeRequests ?? 0) === 0;
190
+ const delay = (ms) => new Promise(r => setTimeout(r, ms));
191
+ /** Starts `hub run` detached in its data root; its stdout and stderr go to hub.log there. */
192
+ export function spawnDetachedHub(args, dataRoot) {
193
+ const { executable, arguments: base } = hubCommandLine();
194
+ mkdirSync(dataRoot, { recursive: true });
195
+ const log = openSync(hubLogPath(dataRoot), 'a');
196
+ try {
197
+ const child = spawn(executable, [...base, ...args], { detached: true, cwd: dataRoot, stdio: ['ignore', log, log], windowsHide: true });
198
+ child.on('error', () => { });
199
+ child.unref();
200
+ }
201
+ finally {
202
+ closeSync(log);
203
+ }
204
+ }
205
+ async function waitFor(client, until, timeoutMs) {
206
+ const deadline = Date.now() + timeoutMs;
207
+ for (;;) {
208
+ const s = await client.status().catch(() => undefined);
209
+ if (until(s))
210
+ return { status: s };
211
+ if (Date.now() > deadline)
212
+ return;
213
+ await delay(250);
214
+ }
215
+ }
216
+ const incompatible = (url, s, version) => hubError('hub.incompatible', `Hub at ${url} runs ${s.version} (API ${s.apiVersion}); this CLI is ${version} (API ${HUB_API_VERSION}).`);
217
+ /** Connects per settings, starting a local hub when needed. Exported for tests; connectHub supplies the context. */
218
+ export async function connect(o) {
219
+ const version = o.version ?? packageVersion, client = new HttpHubClient(hubUrl(o.settings), o.runtime);
220
+ let status = await client.status().catch(() => undefined);
221
+ if (o.settings.hub === 'remote') {
222
+ if (!status)
223
+ throw hubError('hub.unavailable', `Remote hub ${o.settings.remote} is unavailable.`);
224
+ if (status.apiVersion !== HUB_API_VERSION)
225
+ throw incompatible(client.url, status, version);
226
+ client.connectedStatus = status;
227
+ return client;
228
+ }
229
+ if (status && restartForUpgrade(status, version)) {
230
+ // Restart a local hub of another version while nobody uses it; the new one runs this CLI.
231
+ await client.shutdown();
232
+ if (!await waitFor(client, s => !s, 30_000))
233
+ throw hubError('hub.unavailable', 'The local hub of version ' + status.version + ' did not stop for the upgrade.');
234
+ status = undefined;
235
+ }
236
+ if (!status) {
237
+ // Only starting a hub needs its data root and the runtime it gets.
238
+ const dataRoot = resolveLazy(o.dataRoot), autostart = o.autostart ?? platformAutostart(autostartName());
239
+ if ((await autostart.probe().catch(() => ({ installed: false }))).installed)
240
+ await autostart.start();
241
+ else
242
+ (o.spawnHub ?? spawnDetachedHub)(hubRunArguments(o.settings, dataRoot, client.runtime), dataRoot);
243
+ status = (await waitFor(client, s => !!s, o.startTimeoutMs ?? 60_000))?.status;
244
+ if (!status)
245
+ throw hubError('hub.unavailable', `The local hub did not answer on ${client.url} after it was started; see ${hubLogPath(dataRoot)}.`);
246
+ }
247
+ if (status.apiVersion !== HUB_API_VERSION)
248
+ throw incompatible(client.url, status, version);
249
+ client.connectedStatus = status;
250
+ return client;
251
+ }
252
+ /** Connects to the configured hub; the data root and the profile runtime are read only when a local hub is started. */
253
+ export async function connectHub(c) {
254
+ const settings = await readHubSettings(c.appArguments.RoamingAppDataDirectory);
255
+ return connect({ settings, dataRoot: () => hubDataRoot(c, settings), runtime: () => profileRuntime(c), autostart: platformAutostart(autostartName(c.appArguments.AppName)) });
256
+ }
@@ -0,0 +1,13 @@
1
+ import { type CommandDefinition } from '@eyeauras/cli-factory';
2
+ /**
3
+ * Appends hub log lines to `path`, keeping one previous file (`.1`) once it exceeds `limit` bytes. Echoes to stderr
4
+ * when that is a terminal (an interactive `hub run`); a detached hub's stderr already goes to the same file.
5
+ */
6
+ export declare function hubLogger(path: string, limit?: number, echo?: boolean): (message: string) => void;
7
+ /** Runs the hub in this process until it is stopped or idles out. */
8
+ export declare function runHubProcess(o: Record<string, unknown>, signal?: AbortSignal): Promise<{
9
+ stopped: boolean;
10
+ hubId: string;
11
+ dataRoot: string;
12
+ }>;
13
+ export declare function hubCommands(): CommandDefinition;