@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
package/dist/src/cli.js CHANGED
@@ -4,7 +4,6 @@ import { captureCommands } from './capture.js';
4
4
  import { binaryCommands } from './binary.js';
5
5
  import { skillCommand, toolboxCommands } from './toolbox.js';
6
6
  import { listProcesses } from './tool-runtime/supervisor.js';
7
- import { migrationProcessBlockers } from './legacy-migration.js';
8
7
  import { diagnosticsCommands } from './dotnet-diagnostics.js';
9
8
  import { fridaCommands } from './frida.js';
10
9
  import { mitmproxyCommands } from './mitmproxy.js';
@@ -19,237 +18,129 @@ import { llvmCommands } from './llvm.js';
19
18
  import { sevenzipCommands } from './sevenzip.js';
20
19
  import { ilspyCommands } from './ilspy.js';
21
20
  import { toolProcessCommands } from './tool-runtime/commands.js';
22
- import { ghidraProcessHooks } from './ghidra-processes.js';
23
21
  import { withToolLock, toolProfileBusy } from './tool-runtime/store.js';
24
- import { command, createCli, Permission, CliError, ProfileStore } from '@eyeauras/cli-factory';
22
+ import { command, createCli, Permission, ProfileStore } from '@eyeauras/cli-factory';
25
23
  import { join, resolve } from 'node:path';
26
- import { readFile, readdir } from 'node:fs/promises';
27
- import { existsSync } from 'node:fs';
28
24
  import { Workspace } from './workspace.js';
29
- import { GhidraContexts } from './contexts.js';
30
- import { nativeInputs } from './native-inputs.js';
31
25
  import { Research, scope, address, commentKind, scalarText, number } from './research.js';
32
- import { fail, id, text, digest, object } from './model.js';
26
+ import { fail, id, text, object } from './model.js';
33
27
  import { queryCommands, extendQueries } from './queries.js';
34
28
  import { decodedInstructions } from './decode-results.js';
35
29
  import { mutationCommands } from './mutations.js';
36
30
  import { crossCommands } from './cross.js';
37
- import { Administration, administrationCommands } from './administration.js';
38
- import { Lifecycle, lifecycleCommands } from './lifecycle.js';
39
31
  import { utilityCommands } from './utility.js';
40
- import { Projects, projectCommands } from './projects.js';
41
- import { UserInterface, uiCommands, pluginCommands } from './ui.js';
42
- import { Debugger, debuggerCommands } from './debugger.js';
43
- import { Archive, archiveCommands } from './archive.js';
44
32
  import { blockContent } from './memory-inputs.js';
45
- import { verifyMutation } from './mutation-effects.js';
46
33
  import { sdkCommands } from './sdk.js';
47
- import { SdkFiles, sdkFileCommands } from './sdk-files.js';
48
- import { parseDomainJson } from './json.js';
49
- import { VersionTracking, trackingCommands } from './version-tracking.js';
50
- import { Extensions, extensionCommands, extensionState, extensionInventoryCommands, managedExtensions } from './extensions.js';
51
- import { Synchronization, synchronizationCommands } from './sync-policy.js';
34
+ import { Extensions, extensionCommands } from './extensions.js';
52
35
  import { artifactsCommands } from './saved-materials.js';
53
- import { RuntimeManager, runtimeCommands, runtimeProcesses } from './runtime-manager.js';
36
+ import { RuntimeManager, runtimeCommands } from './runtime-manager.js';
54
37
  import { packageVersion } from './package-version.js';
55
- import { runtimeSelection } from './runtime-selection.js';
56
38
  import { AnalysisStorage, analysisDirectory } from './analysis-storage.js';
39
+ import { cacheBase } from './analysis-default.js';
57
40
  import { codeReferenceCommands } from './code-references.js';
58
41
  import { stringAnchorCommands } from './string-anchors.js';
59
42
  import { contextDiagnosticCommands } from './context-diagnostics.js';
60
- import { traceCommand } from './internal-timing.js';
61
- import { withWorkerLeases } from './worker-lease.js';
62
43
  import { ActivityAudit } from './audit-commands.js';
63
- import { timedBackend } from './timed-backend.js';
64
- import { readInitialProgress } from './initial-progress.js';
65
- const bindingFields = ['java', 'ghidraHome', 'mcpJar', 'mcpJarSha256', 'server', 'repository', 'readerUser', 'publisherUser', 'maxContexts', 'debuggerPython', 'windbgDir', 'archiveUrl'];
44
+ import { Coordinator } from './core/coordinator.js';
45
+ import { connectHub, hubCommands } from './hub/index.js';
46
+ import { createNativeGhidra } from './native/index.js';
47
+ import { OPERATION_MINUTES } from './native/host.js';
48
+ import { Debugger, debuggerCommands } from './debugger.js';
49
+ import { ProgramFiles, programFileCommands } from './program-files.js';
50
+ import { UserInterface, uiCommands } from './ui.js';
51
+ import { VersionTracking, trackingCommands } from './version-tracking.js';
52
+ import { parseDomainJson } from './json.js';
66
53
  class Owner {
67
54
  options;
68
55
  storage;
69
56
  profiles = new Map();
70
- runtimeChanging = new Set();
71
- openSequence = 0;
72
- async runtime(c, action, quiescent = true) {
73
- const directory = c.appArguments.AppDataDirectory;
74
- if (this.runtimeChanging.has(directory))
75
- fail('busy', 'Another runtime operation is in progress.');
76
- const current = this.profiles.get(directory);
77
- if (quiescent && current?.tasks.size)
78
- fail('busy', 'Research operations are in progress; finish them before managing the runtime.');
79
- this.runtimeChanging.add(directory);
80
- try {
81
- if (!quiescent)
82
- return await action();
83
- if (current)
84
- await (await current.backend)?.quiesce?.();
85
- const processes = await runtimeProcesses(directory);
86
- if (processes.length)
87
- fail('busy', 'Close Ghidra contexts and stop the owned server before changing or checking the runtime.', { processes });
88
- if (current) {
89
- await (await current.backend)?.dispose();
90
- current.workspace.close();
91
- this.profiles.delete(directory);
92
- }
93
- return await withToolLock(directory, 'ghidra', action, c.signal);
94
- }
95
- finally {
96
- this.runtimeChanging.delete(directory);
97
- }
98
- }
99
57
  constructor(options) {
100
58
  this.options = options;
101
59
  }
102
- selected(c) {
60
+ /** One coordinator per profile; it keeps the profile's context workers for the life of the IPC owner. */
61
+ profile(c) {
103
62
  const directory = c.appArguments.AppDataDirectory;
104
- if (this.runtimeChanging.has(directory))
105
- fail('busy', 'Runtime preparation is in progress.');
106
- const root = analysisDirectory(c);
107
- const configuration = digest({ analysisDirectory: root, runtime: runtimeSelection(directory, root), profile: Object.fromEntries(bindingFields.map(key => [key, c.profile.values[key]])), extensions: extensionState(join(root, 'workspace')).modules.filter(m => m.enabled).map(m => [m.name, m.sha256]) });
108
63
  let profile = this.profiles.get(directory);
109
64
  if (!profile) {
110
- profile = { workspace: new Workspace(join(root, 'workspace'), c.profile.name), tasks: new Map(), configuration };
65
+ const holder = {};
66
+ const native = () => holder.native ??= (this.options.native ?? createNativeGhidra)(holder.context).catch(error => { holder.native = undefined; throw error; });
67
+ const core = new Coordinator({ hub: () => (this.options.hub ?? connectHub)(holder.context), native, analysis: analysisDirectory(c), cacheBase: cacheBase(c),
68
+ project: typeof c.profile.values.project === 'string' && c.profile.values.project ? c.profile.values.project : c.profile.name,
69
+ idleMinutes: c.profile.values.contextIdleMinutes === undefined ? 15 : number(c.profile.values.contextIdleMinutes, 1440, 1) });
70
+ profile = Object.assign(holder, { core, research: new Research(core), context: c });
111
71
  this.profiles.set(directory, profile);
112
72
  }
113
- if (profile.configuration !== configuration)
114
- fail('binding', 'Runtime profile changed; stop the IPC owner before reopening its saved workspace.');
115
- const selected = profile;
116
- const backend = async () => {
117
- if (!selected.backend)
118
- selected.backend = Promise.resolve(this.options.backend ?
119
- this.options.backend(selected.workspace, c) : nativeInputs(c.profile.values, selected.workspace.directory, c).then(inputs => new GhidraContexts(selected.workspace, inputs, c)))
120
- .catch(error => { selected.backend = undefined; throw error; });
121
- const result = await selected.backend;
122
- if (result instanceof GhidraContexts)
123
- await managedExtensions(selected.workspace.directory);
124
- return timedBackend(result instanceof GhidraContexts ? result.fork(c) : result);
125
- };
126
- const research = new Research(profile.workspace, backend, profile.tasks);
127
- return { workspace: profile.workspace, research, synchronization: new Synchronization(profile.workspace, research, async () => {
128
- const store = this.options.runtime?.profileStore ?? new ProfileStore({ applicationId: c.appArguments.AppName, appArguments: c.appArguments });
129
- if (!(await store.getPermissions(c.profile.name))?.includes(Permission.Update))
130
- throw new CliError('Automatic synchronization requires the current Factory Update permission.', { code: 'permission.denied', next: [['permissions', 'grant', 'Update']] });
131
- }), administration: new Administration(profile.workspace, backend, profile.tasks), lifecycle: new Lifecycle(profile.workspace, research, backend), projects: new Projects(profile.workspace, backend, research, profile.tasks), sdkFiles: new SdkFiles(profile.workspace, research, backend), tracking: new VersionTracking(profile.workspace, research, backend, profile.tasks), ui: new UserInterface(profile.workspace, research, backend), debugger: new Debugger(profile.workspace, research, backend), archive: new Archive(profile.workspace, research, backend, c), backend };
132
- }
133
- async openCommand(c, action) {
134
- const selected = this.selected(c), tasks = this.profiles.get(c.appArguments.AppDataDirectory).tasks;
135
- // Register before the first await, including import before a context/task exists.
136
- const key = 'open-command:' + ++this.openSequence, task = Promise.resolve().then(() => action(selected));
137
- tasks.set(key, task);
138
- try {
139
- return await task;
140
- }
141
- finally {
142
- tasks.delete(key);
143
- }
144
- }
145
- migrate(c, target, dryRun) {
146
- return this.maintain(c, 'migration', dryRun, async (backend) => {
147
- if (!backend.migrate)
148
- fail('unsupported', 'The selected backend cannot migrate native Ghidra models.');
149
- return backend.migrate(target, dryRun);
150
- });
73
+ profile.context = c;
74
+ return profile;
151
75
  }
152
- collect(c, dryRun) {
153
- return this.maintain(c, 'garbage collection', dryRun, async (backend) => {
154
- if (!backend.collect)
155
- fail('unsupported', 'The selected backend cannot collect retained storage.');
156
- return backend.collect(dryRun);
157
- });
158
- }
159
- /** Exclusive maintenance: no research task, native worker or uncertain helper may overlap it. */
160
- async maintain(c, name, dryRun, action) {
161
- if (!dryRun) {
162
- const store = this.options.runtime?.profileStore ?? new ProfileStore({ applicationId: c.appArguments.AppName, appArguments: c.appArguments });
163
- if (!(await store.getPermissions(c.profile.name))?.includes('Destructive'))
164
- throw new CliError('Explicit Ghidra ' + name + ' requires Destructive permission.', { code: 'permission.denied', next: [['permissions', 'grant', 'Destructive']] });
165
- }
166
- const selected = this.selected(c), profile = this.profiles.get(c.appArguments.AppDataDirectory);
167
- if (profile.tasks.size)
168
- fail('busy', 'Finish research operations before ' + name + '.');
169
- this.runtimeChanging.add(c.appArguments.AppDataDirectory);
170
- try {
171
- // Idle services and idle warm workers hold saved work only; held ones keep the refusal below.
172
- await (await selected.backend()).quiesce?.();
173
- // A missing private-worker receipt does not prove an interrupted native helper stopped.
174
- const helpers = await migrationProcessBlockers(c.appArguments.AppDataDirectory);
175
- const workers = (await runtimeProcesses(analysisDirectory(c), c.appArguments.AppDataDirectory)).filter(p => p.kind !== 'server');
176
- if (helpers.length || workers.length)
177
- fail('busy', 'Stop or reconcile retained Ghidra workers and native helpers before ' + name + '; no takeover is performed.', { helpers, workers });
178
- return await action(await selected.backend());
179
- }
180
- finally {
181
- this.runtimeChanging.delete(c.appArguments.AppDataDirectory);
76
+ core(c) { return this.profile(c).core; }
77
+ research(c) { return this.profile(c).research; }
78
+ files(c) { return new ProgramFiles(this.core(c)); }
79
+ ui(c) { return new UserInterface(this.core(c)); }
80
+ tracking(c) { return new VersionTracking(this.core(c)); }
81
+ debugger(c) { return new Debugger(this.core(c), c.profile.values); }
82
+ /** Local target and artifact store of the non-Ghidra tools and the Work ledger. */
83
+ workspace(c) { const profile = this.profile(c); return profile.workspace ??= new Workspace(join(analysisDirectory(c), 'workspace'), c.profile.name); }
84
+ async runtime(c, action, quiescent = true) {
85
+ if (quiescent) {
86
+ const open = (await this.core(c).contexts()).filter(r => r.worker === 'running');
87
+ if (open.length)
88
+ fail('busy', 'Close running Ghidra contexts before changing the runtime.', { contexts: open.map(r => ({ session: r.session, target: r.target })) });
182
89
  }
90
+ const profile = this.profiles.get(c.appArguments.AppDataDirectory);
91
+ if (profile)
92
+ await this.closeNative(profile);
93
+ return withToolLock(c.appArguments.AppDataDirectory, 'ghidra', action, c.signal);
183
94
  }
184
95
  async invalidateProfile(app) {
185
96
  const directory = app.AppDataDirectory, profile = this.profiles.get(directory);
186
97
  if (this.storage?.busy(directory))
187
98
  fail('busy', 'Storage migration is in progress.');
188
- if (this.runtimeChanging.has(directory))
189
- fail('busy', 'Runtime preparation is in progress; finish it before changing or deleting the profile.');
190
- // Idle services and idle warm workers of this owner hold no work; held ones keep the refusals below.
191
- if (profile && !profile.tasks.size)
192
- await (await profile.backend)?.quiesce?.();
193
99
  if (toolProfileBusy(directory))
194
100
  fail('busy', 'A tool operation is active.');
195
- if ((await listProcesses(directory)).some(r => !['exited', 'failed'].includes(r.state)))
101
+ if ((await listProcesses(directory, { active: true })).length)
196
102
  fail('busy', 'The profile has active or unverified tool processes.');
197
- const materials = await readdir(join(directory, 'materials')).catch(error => { if (error.code === 'ENOENT')
198
- return []; throw error; });
199
- if (existsSync(join(directory, 'storage', 'migration.json')) || existsSync(join(directory, 'workspace', 'workspace.sqlite')) || materials.length)
200
- fail('blocked', 'Profile has retained research data; preserve its workspace and materials before deleting or reconfiguring it.');
201
103
  if (profile) {
202
- await (await profile.backend)?.dispose();
203
- profile.workspace.close();
104
+ await profile.core.dispose();
105
+ await this.closeNative(profile);
106
+ profile.workspace?.close();
204
107
  this.profiles.delete(directory);
205
108
  }
206
109
  }
207
- /** Idle services and idle warm workers of an otherwise idle profile owner hold no work and may stop. */
208
- async quiesceProfile(c) { const profile = this.profiles.get(c.appArguments.AppDataDirectory); if (profile && !profile.tasks.size)
209
- await (await profile.backend)?.quiesce?.(); }
210
110
  async releaseStorage(c) {
211
- const directory = c.appArguments.AppDataDirectory, profile = this.profiles.get(directory);
111
+ const profile = this.profiles.get(c.appArguments.AppDataDirectory);
212
112
  if (!profile)
213
113
  return;
214
- if (profile.tasks.size)
215
- fail('busy', 'Research commands are active.');
216
- await (await profile.backend)?.dispose();
217
- profile.workspace.close();
218
- this.profiles.delete(directory);
114
+ await profile.core.dispose();
115
+ await this.closeNative(profile);
116
+ profile.workspace?.close();
117
+ this.profiles.delete(c.appArguments.AppDataDirectory);
118
+ }
119
+ /** Ends the profile's native host (its running operations finish first); the next native call starts a new one. */
120
+ async closeNative(profile) {
121
+ const pending = profile.native;
122
+ profile.native = undefined;
123
+ if (pending)
124
+ await pending.then(n => n.native.close?.(), () => { });
219
125
  }
220
126
  async dispose() {
221
127
  for (const profile of this.profiles.values()) {
222
- await Promise.allSettled([...profile.tasks.values()]);
223
128
  try {
224
- await (await profile.backend)?.dispose();
129
+ await profile.core.dispose();
130
+ await this.closeNative(profile);
225
131
  }
226
132
  finally {
227
- profile.workspace.close();
133
+ profile.workspace?.close();
228
134
  }
229
135
  }
230
136
  this.profiles.clear();
231
137
  }
232
138
  }
233
139
  const scoped = [
234
- { flags: '--session <id>', description: 'Select the durable research session', required: true },
235
- { flags: '--target <id>', description: 'Select the immutable input target', required: true },
140
+ { flags: '--session <id>', description: 'Select the research session', required: true },
141
+ { flags: '--target <id>', description: 'Select the hub target', required: true },
236
142
  ];
237
143
  const at = { flags: '--address <address>', description: 'Explicit hexadecimal address or space:address', required: true };
238
- const request = { flags: '--request-id <id>', description: 'Retrieve the same changing intent after a lost response' };
239
- const resolveOptions = [{ flags: '--resolve-conflict', description: 'Legacy scalar resolution only; native conflicts require Ghidra decisions' },
240
- { flags: '--expect-shared <value>', description: 'Shared value used for this resolution' },
241
- { flags: '--expect-shared-null', description: 'Expect the shared comment to be absent' }];
242
- function resolution(options) {
243
- const expected = options.expectShared !== undefined, absent = Boolean(options.expectSharedNull);
244
- if (!options.resolveConflict) {
245
- if (expected || absent)
246
- fail('invalid', 'Shared expectation requires --resolve-conflict.');
247
- return;
248
- }
249
- if (expected === absent)
250
- fail('invalid', 'Resolution needs exactly one --expect-shared or --expect-shared-null.');
251
- return { expectedShared: absent ? null : scalarText(options.expectShared) };
252
- }
253
144
  function structureFields(value) {
254
145
  const source = text(value, 65536);
255
146
  let parsed;
@@ -273,22 +164,26 @@ const paged = [
273
164
  { flags: '--offset <count>', description: 'Skip items before this page', defaultValue: 0, parse: (value) => number(value, 2147483647) },
274
165
  ];
275
166
  const fields = [
167
+ ['project', '--project <name>', 'Project on the hub (default: the profile name)'],
276
168
  ['java', '--java <path>', 'Java 21 JDK executable'],
277
169
  ['ghidraHome', '--ghidra-home <path>', 'Ghidra 12.1.2 installation'],
278
170
  ['mcpJar', '--mcp-jar <path>', 'Optional override of the packaged verified GhidraMCP runtime'],
279
- ['mcpJarSha256', '--mcp-jar-sha256 <sha>', 'Expected runtime artifact digest'],
280
- ['server', '--server <origin>', 'External Ghidra Server origin (omit for local startup)'],
281
- ['repository', '--repository <name>', 'Repository on the external server'],
282
- ['readerUser', '--reader-user <name>', 'Read-only external account'],
283
- ['publisherUser', '--publisher-user <name>', 'External publication account'],
284
171
  ['initialImportSeconds', '--initial-import-seconds <seconds>', 'Initial import/analysis budget (default 3600, range 1–86400 seconds)'],
285
- ['saveSeconds', '--save-seconds <seconds>', 'Native save/export budget (default 120, range 1–3600 seconds)'],
286
- ['maxContexts', '--max-contexts <count>', 'Concurrent contexts (default 4, maximum 16)'],
287
- ['contextIdleMinutes', '--context-idle-minutes <minutes>', 'Idle minutes after the last command before a context worker stops itself (default 15, range 1–1440)'],
172
+ ['operationMinutes', '--operation-minutes <minutes>', 'Time limit of one native Ghidra operation or helper (default 30, range 1–10080 minutes)'],
173
+ ['nativeHosts', '--native-hosts <count>', 'Native Ghidra host JVMs per profile; requests go to the least busy (default 2, range 1–64)'],
174
+ ['workerHeap', '--worker-heap <size>', 'Maximum heap of a context worker JVM (default 2g; e.g. 3072m or 8g)'],
175
+ ['hostHeap', '--host-heap <size>', 'Maximum heap of a native host JVM (default 4g)'],
176
+ ['contextIdleMinutes', '--context-idle-minutes <minutes>', 'Idle minutes after the last command before a context worker stops (default 15, range 1–1440)'],
288
177
  ['debuggerPython', '--debugger-python <path>', 'Optional Python executable for a configured debugger offer'],
289
178
  ['windbgDir', '--windbg-dir <path>', 'Optional Windows debugger runtime directory'],
290
- ['archiveUrl', '--archive-url <url>', 'Explicit archive service base URL (disabled by default)'],
291
179
  ];
180
+ /** Maximum of each numeric profile setting (minimum 1). */
181
+ const numericFields = { initialImportSeconds: 86400, operationMinutes: 10080, nativeHosts: 64, contextIdleMinutes: 1440 };
182
+ /** A JVM heap size as `-Xmx` takes it. */
183
+ const heapSize = (value) => { const size = text(value, 16).toLowerCase(); if (!/^\d+[mg]$/.test(size))
184
+ fail('invalid', 'A heap size is a number with m or g, e.g. 4g.'); return size; };
185
+ const budgetsView = (profile, values) => ({ profile, initialImportSeconds: ghidraBudget(values) / 1000,
186
+ operationMinutes: values.operationMinutes === undefined ? OPERATION_MINUTES : number(values.operationMinutes, 10080, 1) });
292
187
  const mode = (value) => {
293
188
  if (value === undefined)
294
189
  return;
@@ -296,316 +191,236 @@ const mode = (value) => {
296
191
  fail('invalid', 'Mode must be headless or gui.');
297
192
  return value;
298
193
  };
194
+ /** Explicit loader choices for the first import (`formats loaders` lists what a file supports). */
195
+ function loaderInputs(o) {
196
+ const l = {};
197
+ if (o.language !== undefined)
198
+ l.language = text(o.language, 256);
199
+ if (o.compilerSpec !== undefined) {
200
+ if (o.language === undefined)
201
+ fail('invalid', '--compiler-spec needs --language.');
202
+ l.compilerSpec = text(o.compilerSpec, 256);
203
+ }
204
+ if (o.imageBase !== undefined) {
205
+ const base = text(o.imageBase, 32).replace(/^0x/i, '');
206
+ if (!/^[a-f0-9]{1,16}$/i.test(base))
207
+ fail('invalid', '--image-base must be a hexadecimal address.');
208
+ l.imageBase = base.toLowerCase();
209
+ }
210
+ if (o.loader !== undefined)
211
+ l.loader = text(o.loader, 512);
212
+ if (o.loaderOptions !== undefined) {
213
+ if (o.loader === undefined)
214
+ fail('invalid', '--loader-options needs --loader.');
215
+ let value;
216
+ try {
217
+ value = parseDomainJson(text(o.loaderOptions, 16000));
218
+ }
219
+ catch {
220
+ fail('invalid', '--loader-options must be a JSON object.');
221
+ }
222
+ const options = object(value);
223
+ for (const [name, item] of Object.entries(options))
224
+ if (!['string', 'number', 'boolean'].includes(typeof item))
225
+ fail('invalid', 'Loader option ' + name + ' must be a string, number or boolean.');
226
+ l.loaderOptions = options;
227
+ }
228
+ return Object.keys(l).length ? l : undefined;
229
+ }
299
230
  const targetView = (target) => ({ target: target.id, name: target.name, binarySha256: target.binarySha256, size: target.size, createdAt: target.createdAt });
300
- function scopedFailures(entry, owner, parents = []) {
301
- const path = [...parents, entry.name.split(' ')[0]], name = path.join(' ');
302
- const run = entry.run;
303
- return { ...entry, ...(entry.children ? { children: entry.children.map(child => scopedFailures(child, owner, path)) } : {}), ...(run ? { run: async (input, c) => {
304
- const execute = async () => {
305
- try {
306
- let selected;
307
- try {
308
- selected = scope(input.options);
309
- if (selected.session === 'new')
310
- selected = undefined;
311
- }
312
- catch { }
313
- if (!selected)
314
- return await run(input, c);
315
- // Progress reads an atomic observation; it must remain available while open
316
- // holds this context's research boundary for a long native import.
317
- if (path[1] === 'progress')
318
- return await run(input, c);
319
- const services = owner.selected(c);
320
- // First open of an already known target reserves its context inside Research.open.
321
- // Existing contexts still use the command boundary to order automatic sync phases.
322
- if (path[1] === 'open')
323
- try {
324
- services.workspace.context(selected);
325
- }
326
- catch (error) {
327
- if (error instanceof CliError && error.code === 'coordinator.notFound')
328
- return await run(input, c);
329
- throw error;
330
- }
331
- return await services.research.boundary(selected, async () => {
332
- const excluded = ['open', 'merge', 'refresh', 'sync-policy', 'close', 'changes', 'debugger', 'ui', 'version-tracking', 'archive', 'projects', 'repository', 'server', 'formats', 'libraries', 'plugins'];
333
- const eligible = entry.permission !== Permission.ReadOnly && entry.permission !== undefined && !excluded.includes(path[1]) && !['ghidra types archive-export', 'ghidra documentation transfer'].includes(name);
334
- return eligible ? services.synchronization.execute(selected, name, { ...input.options, commandArguments: input.args }, async (requestId) => run({ ...input, options: { ...input.options, ...(requestId ? { requestId } : {}) } }, c)) : run(input, c);
335
- });
336
- }
337
- catch (error) {
338
- let selected;
339
- try {
340
- selected = scope(input.options);
341
- }
342
- catch {
343
- throw error;
344
- }
345
- if (selected.session === 'new')
346
- throw error;
347
- if (!(error instanceof CliError))
348
- throw error;
349
- const result = error.result && typeof error.result === 'object' && !Array.isArray(error.result) ? error.result : {};
350
- throw new CliError(error.message, { code: error.code, exitCode: error.exitCode, next: error.next, result: { ...result, ...selected } });
351
- }
231
+ /** Core context commands: open, publish, refresh, discard, close and collection on the hub. */
232
+ function coreCommands(owner, options) {
233
+ const core = (c) => owner.core(c);
234
+ return [
235
+ command('targets', 'Targets registered in this profile\'s hub project', [
236
+ command('list', 'List the project\'s targets', async (_input, c) => ({ items: (await core(c).targets()).map(t => ({ target: t.id, name: t.name, sha256: t.sha256, size: t.size, createdAt: t.createdAt, createdBy: t.createdBy })) }), { permission: Permission.ReadOnly }),
237
+ command('file', 'Download the original input of a target into the local cache (hash verified)', async ({ options: o }, c) => ({ target: id(o.target, '--target'), path: await core(c).targetFile(id(o.target, '--target')) }), { permission: Permission.Update, options: [{ flags: '--target <id>', description: 'Hub target', required: true }] }),
238
+ ]),
239
+ command('open [input]', 'Open a file or a hub target in a session; the first machine imports and publishes version 1', async ({ args, options: o }, c) => {
240
+ if (Boolean(args.input) === Boolean(o.target))
241
+ fail('invalid', 'Supply exactly one input path or --target.');
242
+ const session = text(o.session), loader = loaderInputs(o);
243
+ return core(c).open({ ...(args.input ? { file: resolve(c.cwd, text(args.input, 4096)) } : { target: id(o.target, '--target') }), session: session === 'new' ? session : id(session, '--session'),
244
+ analysis: o.analysis === true, ...(mode(o.mode) ? { mode: mode(o.mode) } : {}), timeoutSeconds: ghidraBudget(c.profile.values) / 1000, ...(loader ? { loader } : {}) });
245
+ }, { permission: Permission.Update, options: [{ flags: '--session <id>', description: 'Use new for independent work, or an existing session', required: true },
246
+ { flags: '--target <id>', description: 'Open a registered target instead of supplying a file' },
247
+ { flags: '--mode <mode>', description: 'headless (default) or gui' },
248
+ { flags: '--analysis', description: 'Run full automatic analysis when this machine imports the target first' },
249
+ { flags: '--no-analysis', description: 'Skip initial automatic analysis (the default)' },
250
+ { flags: '--language <id>', description: 'Loader language when this machine imports the target first (e.g. x86:LE:32:default)' },
251
+ { flags: '--compiler-spec <id>', description: 'Compiler spec for --language' },
252
+ { flags: '--image-base <address>', description: 'Image base applied at the first import' },
253
+ { flags: '--loader <name>', description: 'Installed loader name or class from formats loaders' },
254
+ { flags: '--loader-options <json>', description: 'Named primitive loader options; requires --loader' }] }),
255
+ command('status', 'Without selectors: Ghidra runtime readiness. With --session/--target: checkout version, latest version, modified flag and worker', ({ options: o }, c) => {
256
+ if (o.session === undefined && o.target === undefined)
257
+ return new RuntimeManager(c).status();
258
+ if (o.session === undefined || o.target === undefined)
259
+ fail('invalid', 'Supply both --session and --target, or neither for runtime status.');
260
+ return core(c).status(scope(o));
261
+ }, { permission: Permission.ReadOnly, options: scoped.map(({ required: _, ...option }) => option) }),
262
+ command('save', 'Save the worker\'s program into the working copy', ({ options: o }, c) => core(c).saveWorkingCopy(scope(o)), { permission: Permission.Update, options: scoped }),
263
+ command('save-all', 'Save every running context of a session into its working copy', ({ options: o }, c) => core(c).saveAll(id(o.session, '--session')), { permission: Permission.Update, options: [{ flags: '--session <id>', description: 'Session whose contexts are saved', required: true }] }),
264
+ command('diagnostics', 'Hub, native runtime and worker state', [
265
+ command('lifecycle', 'Hub availability, native runtime and the contexts and workers of this machine', ({ options: o }, c) => {
266
+ if ((o.session === undefined) !== (o.target === undefined) && o.target !== undefined)
267
+ fail('invalid', '--target needs --session.');
268
+ return core(c).diagnostics(o.session === undefined ? undefined : { session: id(o.session, '--session'), target: o.target === undefined ? '' : id(o.target, '--target') });
269
+ }, { permission: Permission.ReadOnly, options: scoped.map(({ required: _, ...option }) => option) }),
270
+ ]),
271
+ command('merge', 'Publish the working copy with Ghidra\'s merge; an unmodified copy returns unchanged', ({ options: o }, c) => core(c).merge(scope(o), { ...(o.comment === undefined ? {} : { comment: text(o.comment, 4096) }), close: Boolean(o.close) }), { permission: Permission.Update, options: [...scoped, { flags: '--comment <text>', description: 'Check-in comment' }, { flags: '--close', description: 'Release the working copy after publishing' }] }),
272
+ command('refresh', 'Merge newer published versions into the working copy', ({ options: o }, c) => core(c).refresh(scope(o)), { permission: Permission.Update, options: scoped }),
273
+ command('changes', 'Local changes of a working copy', [
274
+ command('discard', 'Drop local changes and check out the latest version again', ({ options: o }, c) => core(c).discard(scope(o)), { permission: 'Destructive', options: scoped }),
275
+ ]),
276
+ command('close', 'Stop the context worker; --release also ends the checkout and deletes the copy', ({ options: o }, c) => core(c).close(scope(o), { release: Boolean(o.release), force: Boolean(o.force) }), { permission: Permission.Update, options: [...scoped, { flags: '--release', description: 'End the checkout and delete the working copy' }, { flags: '--force', description: 'With --release, discard unpublished changes' }] }),
277
+ command('gc', 'Release unmodified copies of closed contexts and cached binaries no open context uses', ({ options: o }, c) => core(c).gc({ dryRun: Boolean(o.dryRun) }), { permission: Permission.Update, options: [{ flags: '--dry-run', description: 'Report what would be removed' }] }),
278
+ command('budgets', 'Inspect or configure native execution budgets', [
279
+ command('show', 'Read effective per-request native budgets', (_invocation, c) => budgetsView(c.profile.name, c.profile.values), { permission: Permission.ReadOnly }),
280
+ command('set', 'Configure subsequent native requests', async ({ options: o }, c) => {
281
+ if (o.initialImportSeconds === undefined && o.operationMinutes === undefined)
282
+ fail('invalid', 'Supply at least one native budget.');
283
+ const store = options.runtime?.profileStore ?? new ProfileStore({ applicationId: c.appArguments.AppName, appArguments: c.appArguments });
284
+ const patch = {
285
+ ...(o.initialImportSeconds === undefined ? {} : { initialImportSeconds: number(o.initialImportSeconds, 86400, 1) }),
286
+ ...(o.operationMinutes === undefined ? {} : { operationMinutes: number(o.operationMinutes, 10080, 1) })
352
287
  };
353
- // Context workers used by this command keep their idle lease until it ends.
354
- const leased = () => withWorkerLeases(execute);
355
- return path[1] === 'open' || input.options.session && input.options.target ? traceCommand(join(analysisDirectory(c), 'workspace'), name, leased, { session: input.options.session, target: input.options.target }) : leased();
356
- } } : {}) };
288
+ const { values } = await store.set(c.profile.name, patch);
289
+ return { ...budgetsView(c.profile.name, values), state: 'configured', appliesTo: 'subsequent-requests' };
290
+ }, { permission: Permission.Update, options: [{ flags: '--initial-import-seconds <seconds>', description: 'Initial import/analysis: 1–86400 seconds' },
291
+ { flags: '--operation-minutes <minutes>', description: 'One native operation or helper: 1–10080 minutes' }] })
292
+ ]),
293
+ ];
357
294
  }
295
+ /** Hand-written research leaves; the pinned query/mutation catalogs add the rest. */
296
+ function researchCommands(owner) {
297
+ const research = (c) => owner.research(c);
298
+ return [
299
+ command('strings', 'Read defined strings', [
300
+ command('search', 'Find literal text in defined string data; undefined literals: analysis search-byte-patterns', ({ options: o }, c) => research(c).strings(scope(o), text(o.contains, 4096), number(o.limit, 100, 1), number(o.offset, 2147483647)), { permission: Permission.ReadOnly, options: [...scoped, { flags: '--contains <text>', description: 'Literal case-insensitive substring', required: true }, ...paged] }),
301
+ ]),
302
+ command('xrefs', 'Follow cross references', [
303
+ command('to', 'Find incoming references and their functions', ({ options: o }, c) => research(c).xrefs(scope(o), address(o.address), number(o.limit, 100, 1), number(o.offset, 2147483647)), { permission: Permission.ReadOnly, options: [...scoped, at, ...paged] }),
304
+ ]),
305
+ command('types', 'Read and edit data types', [
306
+ command('struct-layout', 'Read a structure layout', ({ options: o }, c) => research(c).read(scope(o), '/get_struct_layout', { struct_name: text(o.name, 512) })
307
+ .then(value => ({ ...scope(o), value })), { permission: Permission.ReadOnly, options: [...scoped, { flags: '--name <name>', description: 'Structure name', required: true }] }),
308
+ command('create-struct', 'Create a structure in the working copy', ({ options: o }, c) => {
309
+ const who = scope(o), name = text(o.name, 512), fields = structureFields(o.fields);
310
+ if (o.replacePlaceholder)
311
+ return research(c).mutate(who, '/sdk/type-structure', { path: name.startsWith('/') ? name : '/' + name, fields, packing: -1, alignment: 0, replace_placeholder: true });
312
+ return research(c).mutate(who, '/create_struct', { name, fields });
313
+ }, { permission: Permission.Update, options: [...scoped, { flags: '--name <name>', description: 'New structure name', required: true },
314
+ { flags: '--fields <json>', description: 'Array of {name,type,offset?}', required: true }, { flags: '--replace-placeholder', description: 'Replace only an existing empty structure' }] }),
315
+ ]),
316
+ command('memory', 'Read or edit memory blocks', [
317
+ command('list', 'Read bounded memory blocks', ({ options: o }, c) => research(c).read(scope(o), '/list_program_items', { kind: 'segments', limit: number(o.limit, 100, 1), offset: number(o.offset, 2147483647) })
318
+ .then(value => ({ ...scope(o), value })), { permission: Permission.ReadOnly, options: [...scoped, ...paged] }),
319
+ command('create-block', 'Create an initialized/uninitialized or overlay block', ({ options: o }, c) => {
320
+ const parameters = { name: text(o.name, 512), address: address(o.address),
321
+ ...(o.size === undefined ? {} : { size: number(o.size, 16777216, 1) }), read: o.read !== false, write: o.write !== false, execute: Boolean(o.execute),
322
+ initialized: o.initialized !== false, overlay: Boolean(o.overlay), volatile: Boolean(o.volatile), comment: o.comment === undefined ? '' : text(o.comment, 16000),
323
+ fill_byte: o.fillByte === undefined ? 0 : number(o.fillByte, 255), ...(o.bytesHex === undefined ? {} : { bytes_hex: o.bytesHex }), ...(o.bytesBase64 === undefined ? {} : { bytes_base64: o.bytesBase64 }) };
324
+ parameters.size = blockContent(parameters).size;
325
+ return research(c).mutate(scope(o), '/create_memory_block', parameters);
326
+ }, { permission: Permission.Update, options: [...scoped, at, { flags: '--name <name>', description: 'Memory block name', required: true },
327
+ { flags: '--size <bytes>', description: 'Positive size up to 16 MiB; defaults to content length' },
328
+ { flags: '--bytes-hex <hex>', description: 'Initial bytes in hexadecimal; remainder uses fill-byte' },
329
+ { flags: '--bytes-base64 <base64>', description: 'Initial bytes as canonical padded base64' },
330
+ { flags: '--fill-byte <byte>', description: 'Fill byte from 0 to 255', defaultValue: 0 },
331
+ { flags: '--initialized <boolean>', description: 'false creates uninitialized memory', defaultValue: true, parse: (v) => { if (v !== 'true' && v !== 'false')
332
+ fail('invalid', 'initialized must be true or false.'); return v === 'true'; } },
333
+ { flags: '--overlay', description: 'Create a distinct overlay address space' },
334
+ { flags: '--volatile', description: 'Mark memory volatile' }, { flags: '--comment <text>', description: 'Block comment' },
335
+ { flags: '--no-read', description: 'Disable read permission' }, { flags: '--no-write', description: 'Disable write permission' },
336
+ { flags: '--execute', description: 'Enable execution permission' }] }),
337
+ ]),
338
+ command('functions', 'Read or name functions', [
339
+ command('decode', 'Decode executable bytes without defining instructions or functions', async ({ options: o }, c) => {
340
+ const who = scope(o), at = address(o.address), maxBytes = number(o.maxBytes ?? 64, 4096, 1), maxInstructions = number(o.maxInstructions ?? 16, 256, 1);
341
+ return { ...who, value: decodedInstructions(await research(c).read(who, '/decode_instructions', { address: at, max_bytes: maxBytes, max_instructions: maxInstructions }), at, maxBytes, maxInstructions) };
342
+ }, { permission: Permission.ReadOnly, options: [...scoped, at, { flags: '--max-bytes <count>', description: 'Read 1–4096 executable bytes', defaultValue: 64 }, { flags: '--max-instructions <count>', description: 'Decode at most 1–256 instructions', defaultValue: 16 }] }),
343
+ command('set-function-prototype', 'Set a C prototype and optional explicit compiler-supported calling convention', ({ options: o }, c) => research(c).mutate(scope(o), '/set_function_prototype', { function_address: address(o.address), prototype: text(o.prototype, 16000),
344
+ ...(o.callingConvention === undefined ? {} : { calling_convention: text(o.callingConvention, 512) }) }), { permission: Permission.Update, options: [...scoped, at, { flags: '--prototype <signature>', description: 'Complete C prototype', required: true },
345
+ { flags: '--calling-convention <name>', description: 'Explicit convention supported by the selected compiler specification' }] }),
346
+ command('get', 'Read a function and entry comments', ({ options: o }, c) => research(c).function(scope(o), address(o.address)), { permission: Permission.ReadOnly, options: [...scoped, at] }),
347
+ command('decompile', 'Read a bounded Unicode window of one decompiled function', ({ options: o }, c) => research(c).function(scope(o), address(o.address), true, { limit: number(o.limitChars ?? 16000, 32768, 1), offset: number(o.offsetChars ?? 0, 4 * 1024 ** 2) }), { permission: Permission.ReadOnly, options: [...scoped, at, { flags: '--limit-chars <count>', description: 'Return 1–32768 Unicode characters', defaultValue: 16000 }, { flags: '--offset-chars <count>', description: 'Skip Unicode characters in the returned native text', defaultValue: 0 }] }),
348
+ command('rename', 'Rename a function in the working copy', ({ options: o }, c) => {
349
+ const name = text(o.name, 512);
350
+ if (name !== name.trim())
351
+ fail('invalid', 'Function name may not have leading or trailing whitespace.');
352
+ return research(c).edit(scope(o), address(o.address), 'function.name', name);
353
+ }, { permission: Permission.Update, options: [...scoped, at, { flags: '--name <name>', description: 'Desired function name', required: true }] }),
354
+ ]),
355
+ command('comments', 'Read or edit listing comments', [
356
+ command('get', 'Read one kind or all five fields', ({ options: o }, c) => research(c).comment(scope(o), address(o.address), o.kind === undefined ? undefined : commentKind(o.kind)), { permission: Permission.ReadOnly, options: [...scoped, at, { flags: '--kind <kind>', description: 'eol, pre, post, plate or repeatable' }] }),
357
+ command('set', 'Set a comment in the working copy or clear it', ({ options: o }, c) => {
358
+ if (Boolean(o.clear) === (o.text !== undefined))
359
+ fail('invalid', 'Supply exactly one --text or --clear.');
360
+ return research(c).edit(scope(o), address(o.address), `comment.${commentKind(o.kind)}`, o.clear ? null : scalarText(o.text));
361
+ }, { permission: Permission.Update, options: [...scoped, at, { flags: '--kind <kind>', description: 'eol, pre, post, plate or repeatable', required: true },
362
+ { flags: '--text <text>', description: 'Desired text; empty text clears to null' }, { flags: '--clear', description: 'Clear this comment to null' }] }),
363
+ ]),
364
+ ];
365
+ }
366
+ /** The hub command tree. Until the hub module lands its stub throws; the rest of the CLI stays usable. */
358
367
  export function createDefinition(options = {}) {
359
- const owner = new Owner(options);
360
- const storage = new AnalysisStorage(options.runtime?.profileStore, c => owner.releaseStorage(c), undefined, c => owner.quiesceProfile(c));
368
+ const owner = new Owner(options), audit = new ActivityAudit();
369
+ const storage = new AnalysisStorage(options.runtime?.profileStore, c => owner.releaseStorage(c));
361
370
  owner.storage = storage;
371
+ const research = (c) => owner.research(c), workspace = (c) => owner.workspace(c);
372
+ const ghidra = extendQueries(extendQueries(extendQueries([...coreCommands(owner, options), ...researchCommands(owner)], queryCommands(research)), mutationCommands(research)), [...codeReferenceCommands(research), ...stringAnchorCommands(research), ...contextDiagnosticCommands(research), ...sdkCommands(research), ...crossCommands(research),
373
+ ...extensionCommands(c => new Extensions(join(analysisDirectory(c), 'workspace'))), ...programFileCommands(c => owner.files(c)), ...uiCommands(c => owner.ui(c)), ...trackingCommands(c => owner.tracking(c)), ...debuggerCommands(c => owner.debugger(c)), ...utilityCommands(), ...runtimeCommands((c, action, quiescent) => owner.runtime(c, action, quiescent))]);
362
374
  const definition = {
363
- name: 'insight-cli', applicationId: 'insight-cli', version: packageVersion, description: 'Isolated research contexts and coordinated Ghidra analysis',
364
- resources: [owner], permissions: { categories: [{ name: 'Destructive', description: 'Explicit deletion or replacement of retained research data', enabledByDefault: false }] }, ...(options.runtime ? { runtime: options.runtime } : {}),
375
+ name: 'insight-cli', applicationId: 'insight-cli', version: packageVersion, description: 'Reverse-engineering toolbox with shared Ghidra analysis through a hub',
376
+ resources: [owner, audit], permissions: { categories: [{ name: 'Destructive', description: 'Explicit deletion or replacement of retained research data', enabledByDefault: false }] }, ...(options.runtime ? { runtime: options.runtime } : {}),
365
377
  profile: { fields: fields.map(([name, flags, description]) => ({ name: name, flags: flags, description: description,
366
- ...(['maxContexts', 'initialImportSeconds', 'saveSeconds', 'contextIdleMinutes'].includes(name) ? { normalize: (value) => number(value, name === 'maxContexts' ? 16 : name === 'saveSeconds' ? 3600 : name === 'contextIdleMinutes' ? 1440 : 86400, 1) } : {}) })) },
367
- auth: {
368
- loginOptions: [{ flags: '--role <role>', description: 'External reader, publisher or archive role', defaultValue: 'reader' },
369
- { flags: '--password-stdin', description: 'Read the password from stdin' }],
370
- async login(c, o) {
371
- const role = text(o.role);
372
- if (!['reader', 'publisher', 'archive'].includes(role))
373
- fail('invalid', 'Role must be reader, publisher or archive.');
374
- if (role !== 'archive' && !c.profile.values.server)
375
- fail('configuration', 'Local server credentials are managed automatically.');
376
- if (role === 'archive' && !c.profile.values.archiveUrl)
377
- fail('configuration', 'Configure an archive URL before storing its token.');
378
- if (!o.passwordStdin || !c.stdinAvailable)
379
- fail('credentials', 'Supply --password-stdin for this role.');
380
- let candidate = '';
381
- for await (const chunk of c.io.input) {
382
- candidate += chunk.toString();
383
- if (candidate.length > 4096)
384
- fail('limit', 'Password input exceeds 4096 characters.');
385
- }
386
- candidate = candidate.replace(/\r?\n$/, '');
387
- if (!candidate || /[\r\n\0]/.test(candidate))
388
- fail('credentials', 'Password must be one nonempty line.');
389
- await c.secrets.set(role === 'archive' ? 'archiveToken' : role + 'Password', candidate);
390
- return { authenticated: true, identity: { role, ...(role === 'archive' ? {} : { user: c.profile.values[role + 'User'] }), validation: 'stored; authority verified at connection' } };
391
- },
392
- async status(c) {
393
- let reader = 'readerPassword', publisher = 'publisherPassword';
394
- const external = Boolean(c.profile.values.server);
395
- if (!external) {
396
- try {
397
- const local = JSON.parse(await readFile(join(c.appArguments.AppDataDirectory, 'workspace/server/local.json'), 'utf8'));
398
- reader = local.readerSecret;
399
- publisher = local.publisherSecret;
400
- }
401
- catch (error) {
402
- if (error.code !== 'ENOENT')
403
- throw error;
404
- return { authenticated: false, identity: { mode: 'local', validation: 'managed on first open' } };
405
- }
406
- }
407
- const readerStored = Boolean(await c.secrets.get(reader)), publisherStored = Boolean(await c.secrets.get(publisher));
408
- return { authenticated: readerStored && publisherStored, identity: { mode: external ? 'external' : 'local', readerStored, publisherStored } };
409
- },
410
- async logout(c) {
411
- await c.secrets.delete('archiveToken');
412
- if (!c.profile.values.server)
413
- return;
414
- await c.secrets.delete('readerPassword');
415
- await c.secrets.delete('publisherPassword');
416
- },
417
- },
378
+ ...(name in numericFields ? { normalize: (value) => number(value, numericFields[name], 1) } : {}),
379
+ ...(name === 'workerHeap' || name === 'hostHeap' ? { normalize: heapSize } : {}) })) },
418
380
  builtins: [skillCommand()],
419
381
  commands: [
420
- ...workCommands((c, action) => owner.openCommand(c, ({ workspace }) => action(workspace))),
382
+ ...workCommands((c, action) => action(workspace(c)), c => (options.hub ?? connectHub)(c)),
421
383
  ...artifactsCommands(),
422
- ...diagnosticsCommands(c => owner.selected(c).workspace),
423
- ...llvmCommands(c => owner.selected(c).workspace),
424
- ...dieCommands(c => owner.selected(c).workspace),
425
- ...lldbCommands(c => owner.selected(c).workspace),
426
- ...windbgCommands(c => owner.selected(c).workspace),
384
+ ...diagnosticsCommands(workspace),
385
+ ...llvmCommands(workspace),
386
+ ...dieCommands(workspace),
387
+ ...lldbCommands(workspace),
388
+ ...windbgCommands(workspace),
427
389
  ...procmonCommands(),
428
- ...dnspyCommands(c => owner.selected(c).workspace),
429
- ...tsharkCommands(c => owner.selected(c).workspace),
430
- ...mitmproxyCommands(c => owner.selected(c).workspace),
431
- ...straceCommands(c => owner.selected(c).workspace),
432
- ...fridaCommands(c => owner.selected(c).workspace),
433
- ...sevenzipCommands(c => owner.selected(c).workspace),
434
- ...ilspyCommands(c => owner.selected(c).workspace),
435
- ...binaryCommands(c => owner.selected(c).workspace),
436
- ...captureCommands(c => owner.selected(c).workspace),
437
- ...toolProcessCommands({ ghidra: ghidraProcessHooks(c => owner.selected(c).workspace, (scope, c) => owner.selected(c).lifecycle.change(scope, 'close')) }, toolboxCommands()),
438
- command('targets', 'Inspect immutable inputs', [
439
- command('add <input>', 'Consume input without starting a tool', async ({ args }, c) => targetView(await owner.selected(c).workspace.importTarget(resolve(c.cwd, text(args.input, 4096)))), { permission: Permission.Update }),
390
+ ...dnspyCommands(workspace),
391
+ ...tsharkCommands(workspace),
392
+ ...mitmproxyCommands(workspace),
393
+ ...straceCommands(workspace),
394
+ ...fridaCommands(workspace),
395
+ ...sevenzipCommands(workspace),
396
+ ...ilspyCommands(workspace),
397
+ ...binaryCommands(workspace),
398
+ ...captureCommands(workspace),
399
+ ...toolProcessCommands({}, toolboxCommands()),
400
+ command('targets', 'Inspect local tool inputs', [
401
+ command('add <input>', 'Consume input without starting a tool', async ({ args }, c) => targetView(await workspace(c).importTarget(resolve(c.cwd, text(args.input, 4096)))), { permission: Permission.Update }),
440
402
  command('list', 'List known inputs', ({ options: o }, c) => {
441
- const items = owner.selected(c).workspace.targets(number(o.limit, 100, 1), number(o.offset, 2147483647));
403
+ const items = workspace(c).targets(number(o.limit, 100, 1), number(o.offset, 2147483647));
442
404
  return { items: items.map(targetView), offset: o.offset, limit: o.limit, truncated: items.length === o.limit };
443
405
  }, { permission: Permission.ReadOnly, options: paged }),
444
- command('show <target>', 'Show an input identity', ({ args }, c) => targetView(owner.selected(c).workspace.target(id(args.target, 'target'))), { permission: Permission.ReadOnly }),
445
- ]),
446
- command('sessions', 'Inspect durable sessions', [
447
- command('list', 'List independent sessions', ({ options: o }, c) => { const items = owner.selected(c).workspace.sessions(number(o.limit, 100, 1), number(o.offset, 2147483647)); return { items, offset: o.offset, limit: o.limit, truncated: items.length === Number(o.limit) }; }, { permission: Permission.ReadOnly, options: paged }),
448
- command('status <session>', 'Inspect saved work and unresolved outcomes', ({ args, options: o }, c) => {
449
- const selected = owner.selected(c), session = id(args.session, 'session');
450
- selected.workspace.session(session);
451
- if (o.target)
452
- return selected.research.status({ session, target: id(o.target, '--target') });
453
- const limit = number(o.limit, 100, 1), offset = number(o.offset, 2147483647), contexts = selected.workspace.contexts(session, limit, offset);
454
- return { session, contexts: contexts.map(context => selected.research.status(context)), limit, offset, truncated: contexts.length === limit };
455
- }, { permission: Permission.ReadOnly, options: [{ flags: '--target <id>', description: 'Inspect one target context' }, ...paged] }),
406
+ command('show <target>', 'Show an input identity', ({ args }, c) => targetView(workspace(c).target(id(args.target, 'target'))), { permission: Permission.ReadOnly }),
456
407
  ]),
457
- command('ghidra', 'Research through an isolated saved context', [
458
- command('migrate', 'Explicitly migrate retained legacy models; repeat to resume', ({ options: o }, c) => {
459
- if (Boolean(o.target) === Boolean(o.all))
460
- fail('invalid', 'Select exactly one --target or --all.');
461
- return owner.migrate(c, o.target === undefined ? undefined : id(o.target, '--target'), Boolean(o.dryRun));
462
- }, { permission: Permission.ReadOnly, options: [{ flags: '--target <id>', description: 'Migrate one immutable target' }, { flags: '--all', description: 'Inspect or migrate every Ghidra target in this profile' }, { flags: '--dry-run', description: 'Inspect without checkout, check-in or context changes' }] }),
463
- command('gc', 'Reclaim redundant copies: unreferenced snapshots, duplicate exports, stopped detached projects and unchanged checkouts', ({ options: o }, c) => owner.collect(c, Boolean(o.dryRun)), { permission: Permission.ReadOnly, options: [{ flags: '--dry-run', description: 'Report reclaimable and retained storage without changing it' }] }),
464
- command('progress', 'Read initial-model import/publication progress without starting Ghidra', async ({ options: o }, c) => {
465
- const selected = owner.selected(c), who = scope(o);
466
- selected.workspace.context(who);
467
- return { ...who, progress: await readInitialProgress(selected.workspace.directory, who.target) };
468
- }, { permission: Permission.ReadOnly, options: scoped }),
469
- command('budgets', 'Inspect or configure native execution budgets', [
470
- command('show', 'Read effective per-request native budgets', (_invocation, c) => ({ profile: c.profile.name, initialImportSeconds: ghidraBudget(c.profile.values, 'import') / 1000, saveSeconds: ghidraBudget(c.profile.values, 'save') / 1000 }), { permission: Permission.ReadOnly }),
471
- command('set', 'Configure subsequent native requests without invalidating retained research', async ({ options: o }, c) => {
472
- if (o.initialImportSeconds === undefined && o.saveSeconds === undefined)
473
- fail('invalid', 'Supply at least one native budget.');
474
- const store = options.runtime?.profileStore ?? new ProfileStore({ applicationId: c.appArguments.AppName, appArguments: c.appArguments });
475
- const patch = {
476
- ...(o.initialImportSeconds === undefined ? {} : { initialImportSeconds: number(o.initialImportSeconds, 86400, 1) }),
477
- ...(o.saveSeconds === undefined ? {} : { saveSeconds: number(o.saveSeconds, 3600, 1) })
478
- };
479
- const { values } = await store.set(c.profile.name, patch);
480
- return { profile: c.profile.name, state: 'configured', initialImportSeconds: ghidraBudget(values, 'import') / 1000, saveSeconds: ghidraBudget(values, 'save') / 1000, appliesTo: 'subsequent-requests' };
481
- }, { permission: Permission.Update, options: [{ flags: '--initial-import-seconds <seconds>', description: 'Initial import/analysis: 1–86400 seconds' },
482
- { flags: '--save-seconds <seconds>', description: 'Native save/export: 1–3600 seconds' }] })
483
- ]),
484
- command('abandon', 'Retain an uncertain legacy detached program attempt and resume its previous saved view', ({ options: o }, c) => owner.selected(c).research.abandon(scope(o), id(o.requestId, '--request-id'), Boolean(o.acknowledgeUnknownEffects)), { permission: 'Destructive', options: [...scoped, { flags: '--request-id <id>', description: 'Original unresolved request ID from `insight-cli sessions status <session> --target <target>`', required: true }, { flags: '--acknowledge-unknown-effects', description: 'Acknowledge that the abandoned effect remains unknown; no script is replayed' }] }),
485
- command('refresh', 'Receive safe shared changes while retaining local conflicts', ({ options: o }, c) => owner.selected(c).research.refresh(scope(o), o.requestId === undefined ? undefined : id(o.requestId, '--request-id')), { permission: Permission.Update, options: [...scoped, request] }),
486
- command('merge', 'Publish the complete selected context or retain every conflict; the context stays open at the published version', ({ options: o }, c) => owner.selected(c).research.merge(scope(o), o.requestId === undefined ? undefined : id(o.requestId, '--request-id'), Boolean(o.close)), { permission: Permission.Update, options: [...scoped, request, { flags: '--close', description: 'Release the working copy after publishing instead of continuing in it' }] }),
487
- command('open [input]', 'Start independent work or continue a context', async ({ args, options: o }, c) => {
488
- if (Boolean(args.input) === Boolean(o.target))
489
- fail('invalid', 'Supply exactly one input path or --target.');
490
- return owner.openCommand(c, async (selected) => {
491
- const target = args.input ? (await selected.workspace.importTarget(resolve(c.cwd, text(args.input, 4096)))).id : id(o.target, '--target');
492
- let previous;
493
- try {
494
- previous = selected.workspace.model(target).settings;
495
- }
496
- catch (error) {
497
- if (!String(error.code).endsWith('.notFound'))
498
- throw error;
499
- }
500
- const settings = { ...previous, autoAnalyze: typeof o.analysis === 'boolean' ? o.analysis : previous?.autoAnalyze ?? false,
501
- ...(o.language ? { language: text(o.language) } : {}), ...(o.compilerSpec ? { compilerSpec: text(o.compilerSpec) } : {}),
502
- ...(o.imageBase ? { imageBase: text(o.imageBase) } : {}), ...(o.loader ? { loader: text(o.loader, 512) } : {}),
503
- ...(o.loaderOptions !== undefined ? { loaderOptions: object(parseDomainJson(text(o.loaderOptions, 16000))) } : {}) };
504
- const session = text(o.session);
505
- return selected.research.open(target, session === 'new' ? session : id(session, '--session'), settings, o.requestId === undefined ? undefined : id(o.requestId, '--request-id'), mode(o.mode));
506
- });
507
- }, { permission: Permission.Update, options: [{ flags: '--session <id>', description: 'Use new for independent work, or an existing session', required: true },
508
- { flags: '--target <id>', description: 'Continue existing input instead of supplying a file' }, request,
509
- { flags: '--mode <mode>', description: 'Request headless or gui; continuation preserves current mode' },
510
- { flags: '--analysis', description: 'Opt in to full initial automatic analysis (new targets only)' },
511
- { flags: '--no-analysis', description: 'Skip initial automatic analysis (the default for new targets)' },
512
- { flags: '--language <id>', description: 'Explicit initial loader language' },
513
- { flags: '--compiler-spec <id>', description: 'Explicit initial compiler specification' },
514
- { flags: '--image-base <address>', description: 'Initial image base' },
515
- { flags: '--loader <name>', description: 'Explicit installed loader name/ID from formats loaders' },
516
- { flags: '--loader-options <json>', description: 'Named primitive SDK loader options, requiring --loader' }] }),
517
- command('strings', 'Read defined strings', [
518
- command('search', 'Find literal text in defined string data; undefined literals: analysis search-byte-patterns', ({ options: o }, c) => owner.selected(c).research.strings(scope(o), text(o.contains, 4096), number(o.limit, 100, 1), number(o.offset, 2147483647)), { permission: Permission.ReadOnly, options: [...scoped, { flags: '--contains <text>', description: 'Literal case-insensitive substring', required: true }, ...paged] }),
519
- ]),
520
- command('xrefs', 'Follow cross references', [
521
- command('to', 'Find incoming references and their functions', ({ options: o }, c) => owner.selected(c).research.xrefs(scope(o), address(o.address), number(o.limit, 100, 1), number(o.offset, 2147483647)), { permission: Permission.ReadOnly, options: [...scoped, at, ...paged] }),
522
- ]),
523
- command('types', 'Read and edit data types', [
524
- command('struct-layout', 'Read a structure layout', ({ options: o }, c) => owner.selected(c).research.read(scope(o), '/get_struct_layout', { struct_name: text(o.name, 512) })
525
- .then(value => ({ ...scope(o), value })), { permission: Permission.ReadOnly, options: [...scoped, { flags: '--name <name>', description: 'Structure name', required: true }] }),
526
- command('create-struct', 'Create and save a private structure', ({ options: o }, c) => {
527
- const selected = owner.selected(c), who = scope(o), name = text(o.name, 512), fields = structureFields(o.fields);
528
- if (o.replacePlaceholder) {
529
- const parameters = { path: name.startsWith('/') ? name : '/' + name, fields, packing: -1, alignment: 0, replace_placeholder: true };
530
- return selected.research.mutate(who, '/sdk/type-structure', parameters, async () => ({}), o.requestId === undefined ? undefined : id(o.requestId, '--request-id'), (backend, snapshot, response) => verifyMutation(backend, snapshot, '/sdk/type-structure', parameters, response));
531
- }
532
- return selected.research.mutate(who, '/create_struct', { name, fields }, async (backend) => {
533
- const result = object(await backend.call(who, '/get_struct_layout', { struct_name: name }));
534
- if (result.name !== name || !Array.isArray(result.fields) || result.fields.length !== fields.length)
535
- fail('partial', 'Structure readback omitted fields or changed its name.');
536
- for (let i = 0; i < fields.length; i++)
537
- if (object(result.fields[i]).name !== fields[i].name)
538
- fail('partial', 'Structure readback changed a field name.');
539
- return result;
540
- }, o.requestId === undefined ? undefined : id(o.requestId, '--request-id'));
541
- }, { permission: Permission.Update, options: [...scoped, { flags: '--name <name>', description: 'New structure name', required: true },
542
- { flags: '--fields <json>', description: 'Array of {name,type,offset?}', required: true }, { flags: '--replace-placeholder', description: 'Replace only an existing empty structure, with independently verified saved layout' }, request] }),
543
- ]),
544
- command('memory', 'Read or edit memory blocks', [
545
- command('list', 'Read bounded memory blocks', ({ options: o }, c) => owner.selected(c).research.read(scope(o), '/list_program_items', { kind: 'segments', limit: number(o.limit, 100, 1), offset: number(o.offset, 2147483647) })
546
- .then(value => ({ ...scope(o), value })), { permission: Permission.ReadOnly, options: [...scoped, ...paged] }),
547
- command('create-block', 'Create a saved initialized/uninitialized or overlay block with verified content', ({ options: o }, c) => {
548
- const selected = owner.selected(c), who = scope(o), parameters = { name: text(o.name, 512), address: address(o.address),
549
- ...(o.size === undefined ? {} : { size: number(o.size, 16777216, 1) }), read: o.read !== false, write: o.write !== false, execute: Boolean(o.execute),
550
- initialized: o.initialized !== false, overlay: Boolean(o.overlay), volatile: Boolean(o.volatile), comment: o.comment === undefined ? '' : text(o.comment, 16000),
551
- fill_byte: o.fillByte === undefined ? 0 : number(o.fillByte, 255), ...(o.bytesHex === undefined ? {} : { bytes_hex: o.bytesHex }), ...(o.bytesBase64 === undefined ? {} : { bytes_base64: o.bytesBase64 }) };
552
- const expected = blockContent(parameters);
553
- parameters.size = expected.size;
554
- return selected.research.mutate(who, '/create_memory_block', parameters, async () => ({}), o.requestId === undefined ? undefined : id(o.requestId, '--request-id'), (backend, snapshot, response) => verifyMutation(backend, snapshot, '/create_memory_block', parameters, response));
555
- }, { permission: Permission.Update, options: [...scoped, at, { flags: '--name <name>', description: 'Memory block name', required: true },
556
- { flags: '--size <bytes>', description: 'Positive size up to 16 MiB; defaults to content length' },
557
- { flags: '--bytes-hex <hex>', description: 'Initial bytes in hexadecimal; remainder uses fill-byte' },
558
- { flags: '--bytes-base64 <base64>', description: 'Initial bytes as canonical padded base64' },
559
- { flags: '--fill-byte <byte>', description: 'Fill byte from 0 to 255', defaultValue: 0 },
560
- { flags: '--initialized <boolean>', description: 'false creates uninitialized memory', defaultValue: true, parse: (v) => { if (v !== 'true' && v !== 'false')
561
- fail('invalid', 'initialized must be true or false.'); return v === 'true'; } },
562
- { flags: '--overlay', description: 'Create a distinct overlay address space' },
563
- { flags: '--volatile', description: 'Mark memory volatile' }, { flags: '--comment <text>', description: 'Block comment' },
564
- { flags: '--no-read', description: 'Disable read permission' }, { flags: '--no-write', description: 'Disable write permission' },
565
- { flags: '--execute', description: 'Enable execution permission' }, request] }),
566
- ]),
567
- command('functions', 'Read or name functions', [
568
- command('decode', 'Decode executable bytes without defining instructions or functions', async ({ options: o }, c) => {
569
- const selected = owner.selected(c), who = scope(o), at = address(o.address), maxBytes = number(o.maxBytes ?? 64, 4096, 1), maxInstructions = number(o.maxInstructions ?? 16, 256, 1);
570
- const value = decodedInstructions(await selected.research.read(who, '/decode_instructions', { address: at, max_bytes: maxBytes, max_instructions: maxInstructions }), at, maxBytes, maxInstructions);
571
- const context = selected.workspace.context(who);
572
- return { ...who, value: { ...value, view: { revision: context.baseRevision, identity: digest({ context: context.id, generation: context.generation, snapshot: context.workingSnapshot, nativeModification: object(value.read_only).modification }) } } };
573
- }, { permission: Permission.ReadOnly, options: [...scoped, at, { flags: '--max-bytes <count>', description: 'Read 1–4096 executable bytes', defaultValue: 64 }, { flags: '--max-instructions <count>', description: 'Decode at most 1–256 instructions', defaultValue: 16 }] }),
574
- command('set-function-prototype', 'Set a C prototype and optional explicit compiler-supported calling convention', ({ options: o }, c) => {
575
- const selected = owner.selected(c), who = scope(o), parameters = { function_address: address(o.address), prototype: text(o.prototype, 16000),
576
- ...(o.callingConvention === undefined ? {} : { calling_convention: text(o.callingConvention, 512) }) };
577
- return selected.research.mutate(who, '/set_function_prototype', parameters, async () => ({}), o.requestId === undefined ? undefined : id(o.requestId, '--request-id'), (backend, snapshot, response) => verifyMutation(backend, snapshot, '/set_function_prototype', parameters, response));
578
- }, { permission: Permission.Update, options: [...scoped, at, { flags: '--prototype <signature>', description: 'Complete C prototype', required: true },
579
- { flags: '--calling-convention <name>', description: 'Explicit convention supported by the selected compiler specification' }, request] }),
580
- command('get', 'Read a function and entry comments', ({ options: o }, c) => owner.selected(c).research.function(scope(o), address(o.address)), { permission: Permission.ReadOnly, options: [...scoped, at] }),
581
- command('decompile', 'Read a bounded Unicode window of one decompiled function', ({ options: o }, c) => owner.selected(c).research.function(scope(o), address(o.address), true, { limit: number(o.limitChars ?? 16000, 32768, 1), offset: number(o.offsetChars ?? 0, 4 * 1024 ** 2) }), { permission: Permission.ReadOnly, options: [...scoped, at, { flags: '--limit-chars <count>', description: 'Return 1–32768 Unicode characters', defaultValue: 16000 }, { flags: '--offset-chars <count>', description: 'Skip Unicode characters in the returned native text', defaultValue: 0 }] }),
582
- command('rename', 'Record a saved private name', ({ options: o }, c) => {
583
- const name = text(o.name, 512);
584
- if (name !== name.trim())
585
- fail('invalid', 'Function name may not have leading or trailing whitespace.');
586
- return owner.selected(c).research.edit(scope(o), address(o.address), 'function.name', name, o.requestId === undefined ? undefined : id(o.requestId, '--request-id'), resolution(o));
587
- }, { permission: Permission.Update, options: [...scoped, at, { flags: '--name <name>', description: 'Desired function name', required: true }, request, ...resolveOptions] }),
588
- ]),
589
- command('comments', 'Read or edit listing comments', [
590
- command('get', 'Read one kind or all five fields', ({ options: o }, c) => owner.selected(c).research.comment(scope(o), address(o.address), o.kind === undefined ? undefined : commentKind(o.kind)), { permission: Permission.ReadOnly, options: [...scoped, at, { flags: '--kind <kind>', description: 'eol, pre, post, plate or repeatable' }] }),
591
- command('set', 'Record a saved private comment or clear it', ({ options: o }, c) => {
592
- if (Boolean(o.clear) === (o.text !== undefined))
593
- fail('invalid', 'Supply exactly one --text or --clear.');
594
- return owner.selected(c).research.edit(scope(o), address(o.address), 'comment.' + commentKind(o.kind), o.clear ? null : scalarText(o.text), o.requestId === undefined ? undefined : id(o.requestId, '--request-id'), resolution(o));
595
- }, { permission: Permission.Update, options: [...scoped, at, { flags: '--kind <kind>', description: 'eol, pre, post, plate or repeatable', required: true },
596
- { flags: '--text <text>', description: 'Desired text; empty text clears to null' }, { flags: '--clear', description: 'Clear this comment to null' }, request, ...resolveOptions] }),
597
- ]),
408
+ command('sessions', 'Ghidra sessions on this machine', [
409
+ command('list', 'List sessions and their contexts', async (_input, c) => {
410
+ const sessions = new Map();
411
+ for (const r of await owner.core(c).contexts())
412
+ sessions.set(r.session, [...sessions.get(r.session) ?? [], r.target]);
413
+ return { items: [...sessions].map(([session, targets]) => ({ session, targets })) };
414
+ }, { permission: Permission.ReadOnly }),
415
+ command('status <session>', 'List the contexts of one session', async ({ args }, c) => {
416
+ const session = id(args.session, 'session'), contexts = await owner.core(c).contexts(session);
417
+ return { session, contexts: contexts.map(r => ({ target: r.target, name: r.name, sha256: r.sha256, mode: r.mode, state: r.closedAt ? 'closed' : 'open', worker: r.worker })) };
418
+ }, { permission: Permission.ReadOnly }),
598
419
  ]),
420
+ hubCommands(),
421
+ command('ghidra', 'Shared Ghidra analysis: one working copy per session and target', ghidra),
599
422
  ],
600
423
  };
601
- const commands = definition.commands?.map(entry => entry.name === 'ghidra' ?
602
- scopedFailures({ ...entry, children: extendQueries(extendQueries(extendQueries(entry.children ?? [], queryCommands(c => owner.selected(c).research)), mutationCommands(c => owner.selected(c).research)), [...codeReferenceCommands(c => owner.selected(c).research), ...stringAnchorCommands(c => owner.selected(c).research), ...contextDiagnosticCommands(c => owner.selected(c).research, c => owner.selected(c).workspace), ...sdkCommands(c => owner.selected(c).research), ...sdkFileCommands(c => owner.selected(c).sdkFiles), ...trackingCommands(c => owner.selected(c).tracking), ...crossCommands(c => owner.selected(c).research), ...administrationCommands(c => owner.selected(c).administration, options.backend ? undefined : async (c) => { const status = await new RuntimeManager(c).status(); return status.state === 'not_ready' ? { ...status.server, connected: false, state: 'runtime_not_ready', missing: status.missing } : undefined; }),
603
- ...extensionCommands(c => new Extensions(join(analysisDirectory(c), 'workspace'))), ...extensionInventoryCommands(c => owner.selected(c).backend), ...pluginCommands(c => owner.selected(c).ui), ...synchronizationCommands(c => owner.selected(c).synchronization), ...utilityCommands(), ...runtimeCommands((c, action, quiescent) => owner.runtime(c, action, quiescent)), ...lifecycleCommands(c => owner.selected(c).lifecycle, c => new RuntimeManager(c).status()), ...projectCommands(c => owner.selected(c).projects), ...uiCommands(c => owner.selected(c).ui), ...debuggerCommands(c => owner.selected(c).debugger), ...archiveCommands(c => owner.selected(c).archive)]) }, owner) : entry);
604
- const audit = new ActivityAudit(), auth = definition.auth;
605
- return { ...definition, auth: { ...auth,
606
- login: (c, o) => audit.run(c, 'auth login', { args: {}, options: {} }, () => auth.login(c, o)),
607
- status: c => audit.run(c, 'auth status', { args: {}, options: {} }, () => auth.status(c)),
608
- logout: c => audit.run(c, 'auth logout', { args: {}, options: {} }, () => auth.logout(c)),
609
- }, commands: [...[...(commands ?? []).map(e => storage.wrap(e)), storage.commands()].map(e => audit.wrap(e)), audit.commands()] };
424
+ return { ...definition, commands: [...[...(definition.commands ?? []).map(e => storage.wrap(e)), storage.commands()].map(e => audit.wrap(e)), audit.commands()] };
610
425
  }
611
426
  export const createInsightCli = (options = {}) => createCli(createDefinition(options));