@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
@@ -1,16 +1,19 @@
1
+ // Research calls on a context's worker (#161). Argument validation and result shaping stay here; the working
2
+ // copy and Ghidra hold the state, so there are no request ids, journals or saved-state receipts.
1
3
  import { textWindow } from './text-window.js';
2
4
  import { functionResult, functionFailure } from './function-results.js';
3
5
  import { inspectFunctions } from './function-inspection.js';
4
- import { entryRequest } from './function-entries.js';
5
6
  import { inspectAnchors } from './string-anchors.js';
6
- import { fail, id, object, text, digest, fieldKey } from './model.js';
7
- import { failUnresolved, unresolvedGuidance, unresolvedAdvice, unknownOutcome, ownerNext, cliPrefix } from './unresolved-guidance.js';
8
- import { verifyMutation } from './mutation-effects.js';
9
- import { transferResult } from './cross-results.js';
10
- import { CliError } from '@eyeauras/cli-factory';
11
- import { timed } from './internal-timing.js';
12
- import { navigationResult } from './context-diagnostics.js';
13
7
  import { inspectCodeReferences } from './code-references.js';
8
+ import { fail, id, object, text, digest } from './model.js';
9
+ import { nativeQueries } from './query-policy.js';
10
+ import { sdkWrites } from './sdk-contracts.js';
11
+ import { scriptInventory, scriptPath } from './scripts.js';
12
+ import { logicalPrograms, transferResult } from './cross-results.js';
13
+ import { randomUUID } from 'node:crypto';
14
+ import { rm } from 'node:fs/promises';
15
+ import { helperEntry } from './native/worker.js';
16
+ import { join } from 'node:path';
14
17
  export function address(value) {
15
18
  const input = text(value, 128);
16
19
  const match = /^(?:([A-Za-z0-9_]+):)?(?:0x)?([a-fA-F0-9]+)$/.exec(input);
@@ -41,312 +44,196 @@ export function number(value, maximum, minimum = 0) {
41
44
  return result;
42
45
  }
43
46
  export function scope(options) { return { session: id(options.session, '--session'), target: id(options.target, '--target') }; }
44
- const count = (context) => context.scalars.length + context.complexChanges.length;
45
- const revision = (value) => value === undefined ? undefined : 'R' + value;
46
47
  function comments(value) {
47
48
  const result = object(value), observed = {};
48
- for (const kind of ['eol', 'pre', 'post', 'plate', 'repeatable']) {
49
- if (!Object.hasOwn(result, kind))
50
- fail('partial', 'Comment result omitted a requested field.');
51
- observed[kind] = scalarText(result[kind]);
52
- }
49
+ for (const kind of ['eol', 'pre', 'post', 'plate', 'repeatable'])
50
+ observed[kind] = typeof result[kind] === 'string' && result[kind] ? result[kind] : null;
53
51
  return observed;
54
52
  }
55
- function pageResult(value, key, limit, offset) {
53
+ function pageResult(value, key) {
56
54
  const result = object(value);
57
- if (!Array.isArray(result[key]) || result[key].length > limit || !Number.isSafeInteger(result.total) || Number(result.total) < 0 ||
58
- result.offset !== offset || result.limit !== limit || result.count !== undefined && result.count !== result[key].length)
59
- fail('partial', 'Paged result has inconsistent items, counts or selectors.');
60
55
  return { result, items: result[key], total: Number(result.total) };
61
56
  }
62
- /** A native step the coordinator proves was never sent (only Update/check-in report this). */
63
- const notSent = (error) => error instanceof CliError && error.code === 'coordinator.notSent';
64
- /** A not-sent request keeps its memory diagnosis in its saved result, not only in the first response. */
65
- export const memoryOf = (error) => {
66
- // A recorded not-sent refusal keeps what its replay needs: the phase, the cause and the memory diagnosis.
67
- const result = object(error instanceof CliError ? error.result ?? {} : {}), cause = result.cause && typeof result.cause === 'object' && !Array.isArray(result.cause) ? object(result.cause) : {};
68
- return { ...(result.phase === 'update' || result.phase === 'checkin' ? { phase: result.phase } : {}),
69
- ...(typeof cause.code === 'string' && typeof cause.message === 'string' ? { cause: { code: cause.code, message: cause.message.slice(0, 1000) } } : {}),
70
- ...(result.memory === 'exhausted' ? { memory: 'exhausted', memoryCause: result.memoryCause } : {}) };
71
- };
72
- /** One ordered working context per tuple, shared by every transport through the Factory owner. */
57
+ /** Bridge parameters that GhidraMCP expects as JSON text. */
58
+ function wire(operation, parameters) {
59
+ if (operation === '/set_variables' && typeof parameters.variables !== 'string')
60
+ return { ...parameters, variables: JSON.stringify(parameters.variables) };
61
+ if (operation === '/create_function_signature' && typeof parameters.parameters !== 'string')
62
+ return { ...parameters, parameters: JSON.stringify(parameters.parameters) };
63
+ return parameters;
64
+ }
65
+ /**
66
+ * Runs a helper of this package (references/native/<base>.java, compiled once per runtime and on the worker classpath)
67
+ * through the worker's fixed entry script, so no source is compiled per call.
68
+ */
69
+ export async function helperScript(worker, base, args) {
70
+ const raw = await worker.request('POST', '/run_ghidra_script', { ...(worker.program ? { program: worker.program } : {}), script_name: helperEntry, args: args === undefined ? base : base + ' ' + args });
71
+ return raw && typeof raw === 'object' && !Array.isArray(raw) ? raw : { console_output: String(raw) };
72
+ }
73
+ /** One facade-owned native query (`INSIGHT_QUERY:<json>`) run by its helper inside the worker. */
74
+ export async function nativeQuery(worker, operation, parameters, write = false) {
75
+ const base = operation === '/code_references' ? 'InsightCodeReferences' : operation.startsWith('/sdk/') ? 'InsightSdkScript' : operation.startsWith('/emulate_') ? 'InsightEmulation' : 'InsightResearchQueries';
76
+ const response = await helperScript(worker, base, Buffer.from(JSON.stringify({ operation, parameters, ...(write ? { write: true } : {}) }), 'utf8').toString('base64'));
77
+ if (response.success !== true || typeof response.console_output !== 'string')
78
+ fail('partial', 'Native research helper did not complete' + (typeof response.error === 'string' ? ': ' + response.error.slice(0, 500) : '.'));
79
+ const result = markedLine(response, 'INSIGHT_QUERY:');
80
+ if (result.error) {
81
+ const error = object(result.error), code = String(error.code);
82
+ fail(['invalid', 'unsupported', 'limit', ...(operation.startsWith('/sdk/') ? ['rejected'] : [])].includes(code) ? code : 'partial', typeof error.message === 'string' ? error.message.slice(0, 500) : 'Native research failed.');
83
+ }
84
+ return result.value;
85
+ }
86
+ /** The `<marker><json>` line a helper script prints. */
87
+ export function markedLine(response, marker) {
88
+ const output = typeof response.console_output === 'string' ? response.console_output : '', at = output.indexOf(marker);
89
+ if (response.success !== true || at < 0)
90
+ fail('partial', 'Native helper ' + marker.replace(/[: ]+$/, '') + ' did not complete' + (typeof response.error === 'string' ? ': ' + response.error.slice(0, 500) : '.'));
91
+ const end = output.indexOf('\n', at);
92
+ return object(JSON.parse(output.slice(at + marker.length, end < 0 ? undefined : end)));
93
+ }
94
+ /** Workers whose managed analyzer options are registered (InsightAnalyzerOptions runs once per worker). */
95
+ const analyzerOptionsRegistered = new WeakSet();
96
+ /** Imports a GZF as a temporary program next to the worker's own, runs `action` with its project path and removes it. */
97
+ export async function withPeer(worker, gzf, action) {
98
+ const name = '__insight_peer_' + randomUUID().replaceAll('-', ''), path = '/' + name;
99
+ const imported = object(await worker.request('POST', '/import_program', { gzf_path: gzf, target_folder: '/', target_name: name, overwrite: false }));
100
+ if (imported.success !== true && imported.status !== 'success')
101
+ fail('partial', 'Ghidra did not import the comparison program' + (typeof imported.error === 'string' ? ': ' + imported.error : '.'));
102
+ try {
103
+ await worker.request('POST', '/open_program', { path });
104
+ return await action(path);
105
+ }
106
+ finally {
107
+ await worker.request('POST', '/close_program', { name: path, save: false }).catch(() => { });
108
+ await worker.request('POST', '/delete_file', { filePath: path }).catch(() => { });
109
+ }
110
+ }
111
+ /** Research surface of one profile: every call goes to the selected context's worker. */
73
112
  export class Research {
74
- workspace;
75
- backend;
76
- tasks;
77
- constructor(workspace, backend, tasks = new Map()) {
78
- this.workspace = workspace;
79
- this.backend = backend;
80
- this.tasks = tasks;
113
+ core;
114
+ constructor(core) {
115
+ this.core = core;
81
116
  }
82
- retainedDisposal(selected, request, error) {
83
- if (!error || typeof error !== 'object')
84
- return;
85
- const failure = error, proof = failure.result?.retention, current = this.workspace.context(selected), outcome = this.workspace.request(request);
86
- if (failure.code === 'coordinator.conflict' && failure.result?.state === 'retained' && proof?.schema === 1 && proof.source === 'native-release-status' &&
87
- proof.request === request && proof.snapshot?.id === current.workingSnapshot?.id && outcome.context === current.id && outcome.state === 'failed' && digest(outcome.result) === digest(failure.result) &&
88
- proof.checkout && current.nativeCheckout?.state === 'active' && digest(proof.checkout) === digest(current.nativeCheckout))
89
- return failure.result;
117
+ backend(selected, worker) {
118
+ return { call: (_s, operation, parameters = {}) => this.route(selected, worker, 'GET', operation, parameters),
119
+ observation: () => this.route(selected, worker, 'GET', '/insight/research-view/v1', {}) };
90
120
  }
91
- async ordered(selected, action) {
92
- const key = this.workspace.context(selected).id, previous = this.tasks.get(key);
93
- const task = timed('facade.queue', 'research', async () => { await previous?.catch(() => { }); }).then(action);
94
- this.tasks.set(key, task);
95
- try {
96
- return await task;
121
+ /** Sends one operation to the worker; facade-owned operations run their fixed helpers there. */
122
+ async route(selected, worker, method, operation, parameters) {
123
+ parameters = wire(operation, parameters);
124
+ // The precompiled /insight/ bridge reads serve an explicitly named open program.
125
+ if (operation.startsWith('/insight/'))
126
+ return worker.request(method, operation, { ...parameters, program: worker.program ?? '/' + selected.target + '.bin' });
127
+ if (operation.startsWith('/sdk/'))
128
+ return nativeQuery(worker, operation, parameters, sdkWrites.has(operation));
129
+ if (nativeQueries.has(operation))
130
+ return nativeQuery(worker, operation, parameters);
131
+ if (operation === '/set_function_prototype' && parameters.calling_convention === 'default') {
132
+ // The bridge accepts only the compiler spec's convention names; Ghidra resolves 'default' to one.
133
+ const validation = object(await nativeQuery(worker, '/validate_function_prototype', { function: parameters.function_address, prototype: parameters.prototype, calling_convention: 'default' }));
134
+ if (validation.valid !== true)
135
+ fail('invalid', 'Prototype or default convention could not be resolved by Ghidra.');
136
+ parameters = { ...parameters, calling_convention: object(validation.signature).calling_convention };
97
137
  }
98
- finally {
99
- if (this.tasks.get(key) === task)
100
- this.tasks.delete(key);
138
+ if (operation === '/apply_function_documentation')
139
+ return helperScript(worker, 'InsightApplyDocumentation', Buffer.from(JSON.stringify(parameters.json_body), 'utf8').toString('base64'));
140
+ if (operation === '/configure_analyzer' && !analyzerOptionsRegistered.has(worker) && ((await this.native()).extensionRoots?.length ?? 0) > 0) {
141
+ // A packed program need not persist analyzer option registrations of managed extensions; register them once per worker.
142
+ const initialized = await helperScript(worker, 'InsightAnalyzerOptions');
143
+ if (initialized.success !== true || !String(initialized.console_output ?? '').includes('INSIGHT_ANALYZER_OPTIONS_READY'))
144
+ fail('partial', 'Installed analyzer option registration could not be established.');
145
+ analyzerOptionsRegistered.add(worker);
101
146
  }
102
- }
103
- async boundary(selected, action) {
104
- const key = 'command:' + this.workspace.context(selected).id, previous = this.tasks.get(key), task = timed('facade.queue', 'command', async () => { await previous?.catch(() => { }); }).then(action);
105
- this.tasks.set(key, task);
106
- try {
107
- return await task;
147
+ if (operation === '/run_ghidra_script') {
148
+ const native = await this.native(), script = String(parameters.script_name);
149
+ if (!native.ghidraHome)
150
+ fail('configuration', 'The native layer does not expose its installation.');
151
+ const path = await scriptPath(native.ghidraHome, this.core.copyRoot(selected), script, [...native.extensionRoots ?? []]);
152
+ const value = object(await worker.request(method, operation, { ...parameters, script_name: path, ...(worker.program ? { program: worker.program } : {}) }));
153
+ delete value.script_path;
154
+ value.script_name = script;
155
+ return value;
108
156
  }
109
- finally {
110
- if (this.tasks.get(key) === task)
111
- this.tasks.delete(key);
112
- }
113
- }
114
- status(selected) {
115
- const context = this.workspace.context(selected), model = this.workspace.model(selected.target), unresolved = this.workspace.unresolved(selected);
116
- const external = this.workspace.unresolvedSessionAdministration(selected.session, selected.target);
117
- return { ...selected, externalRequests: external.map(request => ({ ...(request.callerId ? { requestId: request.callerId } : {}), operation: request.operation, state: request.state })), externalRequestsTruncated: external.length === 100,
118
- ghidra: { syncPolicy: context.syncPolicy ?? { publish: 'manual', refresh: 'manual' }, state: unresolved.length ? 'needs_recovery' : context.state, baseRevision: revision(context.baseRevision),
119
- engine: context.nativeCheckout ? 'ghidra-native' : 'uninitialized-or-legacy', ...(context.nativeCheckout ? { checkout: { id: context.nativeCheckout.checkoutId, fileId: context.nativeCheckout.fileId, baseRevision: revision(context.nativeCheckout.baseVersion), state: context.nativeCheckout.state } } : {}),
120
- sharedRevision: revision(model.sharedRevision), pendingChanges: count(context),
121
- mergeState: model.state === 'unknown' ? 'unknown' : 'idle',
122
- conflicts: [...(context.nativeCheckout?.conflict ? [{ engine: 'ghidra-native', ...context.nativeCheckout.conflict }] : []), ...context.scalars.filter(change => change.conflict).map(change => ({ address: publicAddress(change.address), field: change.field,
123
- original: change.original, local: change.local, shared: change.conflict.shared }))],
124
- unresolvedRequests: unresolved.map(request => ({ id: request.id, ...(request.result ? { detail: request.result } : {}), ...(request.callerId ? { requestId: request.callerId } : {}), operation: request.operation, state: request.state })) } };
157
+ if (operation === '/clone_data_type')
158
+ return helperScript(worker, 'InsightCopyType', [parameters.source_type, parameters.new_name].map(value => Buffer.from(text(value, 512), 'utf8').toString('base64')).join(' '));
159
+ return worker.request(method, operation, parameters);
125
160
  }
126
- async abandon(selected, requestId, acknowledged) {
127
- return this.ordered(selected, async () => {
128
- if (!acknowledged)
129
- fail('invalid', 'Explicit --acknowledge-unknown-effects is required.');
130
- const context = this.workspace.context(selected), requests = this.workspace.unresolved(selected);
131
- if (context.nativeCheckout) {
132
- const guidance = unresolvedGuidance(this.workspace, selected);
133
- fail('unsupported', 'A native unknown outcome is reconciled on its original project, not abandoned. ' + unresolvedAdvice(guidance), guidance);
134
- }
135
- const request = this.workspace.scopedRequest(selected, requestId);
136
- if (request?.state === 'failed' && object(request.result ?? {}).state === 'abandoned')
137
- return request.result;
138
- if (!request || !['running', 'unknown'].includes(request.state) || requests.length !== 1 || object(request.execution ?? {}).kind !== 'program')
139
- fail('blocked', 'Abandon requires exactly one unresolved private program operation.');
140
- if (this.workspace.activePublication(selected.target) || context.debugger?.connected)
141
- fail('blocked', 'Publication or a live debugger prevents private abandonment.');
142
- const execution = object(request.execution), snapshot = context.workingSnapshot;
143
- if (!snapshot || execution.generation !== context.generation || object(execution.workingSnapshot).id !== snapshot.id)
144
- fail('binding', 'The previous saved program view no longer matches the attempt.');
145
- await this.workspace.artifacts.verify(snapshot);
146
- const backend = await this.backend();
147
- if (!backend.closed || !await backend.closed(selected))
148
- fail('busy', 'The original native worker must be stopped before abandoning its uncertain program attempt.');
149
- return this.workspace.abandonProgramRequest(selected, request.id, context.generation);
150
- });
151
- }
152
- async open(target, session, settings, callerId, mode) {
153
- // Mode belongs to the request's effective intent. It does not alter target load identity.
154
- const reserved = this.workspace.reserveOpen(target, session, settings, callerId, mode);
155
- // Older reconciliation accidentally persisted internal context fields in ready results.
156
- // Project the public envelope without rewriting an immutable historical request record.
157
- const opened = (value) => { const result = object(value); return Object.fromEntries(['session', 'target', 'state', 'baseRevision', 'sharedRevision', 'pendingChanges'].filter(key => Object.hasOwn(result, key)).map(key => [key, result[key]])); };
158
- const retained = (state) => ({ session: reserved.context.session, target, state, ...(callerId ? { requestId: callerId } : {}) });
159
- const next = [['sessions', 'status', reserved.context.session, '--target', target], ['ghidra', 'open', '--session', reserved.context.session, '--target', target]];
160
- const openingFailure = (error, state, reconciling = false) => {
161
- const detail = error instanceof CliError && error.result && typeof error.result === 'object' ? error.result : undefined;
162
- const guidance = reconciling ? unresolvedGuidance(this.workspace, { session: reserved.context.session, target }) : undefined;
163
- // An outcome owned by another session sends the agent to that owner, never back into this same refusal.
164
- const owner = guidance?.owner ?? (detail && detail.owner && typeof detail.owner === 'object' ? detail.owner : undefined), follow = owner ? ownerNext({ owner }) : next;
165
- // A plain error outside reconciliation is a setup failure (for example a missing runtime path), not an outcome.
166
- const plain = reconciling ? 'Ghidra open did not complete; the context is retained for reconciliation.' : 'Ghidra open could not set up its runtime: ' + (error instanceof Error ? error.message : String(error));
167
- return new CliError((error instanceof CliError ? error.message : plain) + (guidance ? ' ' + unresolvedAdvice(guidance, true) : ''), {
168
- code: error instanceof CliError ? error.code : reconciling ? 'coordinator.unknown' : 'coordinator.launch', result: { ...retained(state), ...(detail ? { detail } : {}), ...(guidance ? { guidance } : {}) },
169
- next: error instanceof CliError && error.code === 'coordinator.migration' ? [['ghidra', 'migrate', '--target', target, '--dry-run'], ['ghidra', 'migrate', '--target', target], ...follow] :
170
- // A refusal that names its own ways out keeps them first.
171
- error instanceof CliError && error.next?.length ? [...error.next, ...follow] : follow
172
- });
173
- };
174
- return this.ordered(reserved.context, async () => {
175
- if (this.workspace.request(reserved.request.id).state === 'applied')
176
- return opened(this.workspace.request(reserved.request.id).result);
177
- // A replayed open that failed at setup reports that recorded failure before any new setup runs.
178
- const prior = this.workspace.request(reserved.request.id), setup = object(object(prior.result ?? {}).setupFailure ?? {});
179
- if (reserved.replay && prior.state === 'failed' && typeof setup.code === 'string')
180
- throw new CliError(`This open failed before any work: ${String(setup.message)} Open again with a new request ID.`, { code: setup.code, result: retained('failed'), next });
181
- let backend, reconciling = false;
182
- try {
183
- backend = await this.backend();
184
- // Reconciliation acts only on a retained publication or this context's own unresolved requests. Without
185
- // either it has nothing to do, so the open does not wait behind another context's merge in the target lane.
186
- const selected = { session: reserved.context.session, target };
187
- const held = this.workspace.activePublication(target);
188
- if (held || this.workspace.unresolved(selected).length) {
189
- reconciling = true;
190
- await this.sharedOrder(target, () => this.reconcile(selected, backend, true));
191
- }
192
- }
193
- catch (error) {
194
- const request = this.workspace.request(reserved.request.id), failure = openingFailure(error, 'failed', reconciling);
195
- // A setup failure (before any reconciliation) is a plain failure of this request: its replay reports it as such.
196
- // Recovery guidance applies only when an unresolved outcome prompted reconciliation, not to a setup failure.
197
- if (request.state === 'accepted')
198
- this.workspace.recordRequest(request.id, 'failed', { ...retained('blocked'), ...(!reconciling ? { setupFailure: { code: failure.code, message: failure.message } } : {}) });
199
- throw openingFailure(error, this.workspace.request(request.id).state, reconciling);
200
- }
201
- const request = this.workspace.request(reserved.request.id);
202
- if (request.state === 'applied')
203
- return opened(request.result);
204
- if (reserved.replay && request.state !== 'accepted') {
205
- const guidance = unresolvedGuidance(this.workspace, reserved.context);
206
- throw new CliError('This open retains an unproved outcome; inspect the retained context before continuing.', { code: 'coordinator.unknown', result: retained(request.state), next: guidance.targetHeld ? ownerNext(guidance) : next });
207
- }
208
- const unresolved = this.workspace.unresolved(reserved.context).filter(other => other.id !== request.id);
209
- if (unresolved.length) {
210
- const result = { session: reserved.context.session, target, state: 'blocked' };
211
- this.workspace.recordRequest(request.id, 'failed', result);
212
- const close = unresolved.find(other => other.operation === 'ghidra.close'), guidance = unresolvedGuidance(this.workspace, reserved.context);
213
- // An unfinished close is finished by its own command; anything else waits for a reconciliation that can prove it.
214
- const advice = close ? `Finish it with \`${cliPrefix(this.workspace)} ghidra close --session ${reserved.context.session} --target ${target} --request-id ${close.callerId ?? close.id}\`; the saved project and its journals are retained.` : unresolvedAdvice(guidance, true);
215
- throw new CliError('This context retains an unproved effect; continuation did not start a second operation. ' + advice, {
216
- code: 'coordinator.blocked', result: { ...result, ...guidance }, next: close ? [['ghidra', 'close', '--session', reserved.context.session, '--target', target, '--request-id', close.callerId ?? close.id]] : ownerNext(guidance)
217
- });
218
- }
219
- this.workspace.startRequest(request.id);
220
- try {
221
- await backend.open(reserved.context, request.id);
222
- if (mode)
223
- await backend.mode(reserved.context, mode);
224
- const context = this.workspace.context(reserved.context);
225
- const result = { session: context.session, target: context.target, state: 'ready', baseRevision: revision(context.baseRevision),
226
- sharedRevision: revision(this.workspace.model(target).sharedRevision), pendingChanges: count(context) };
227
- this.workspace.completeSavedRequest(context, request.id, context.generation, {}, result);
228
- return result;
229
- }
230
- catch (error) {
231
- const migration = error instanceof CliError && error.code === 'coordinator.migration';
232
- const result = { ...retained(migration ? 'blocked' : 'unknown'), ...(migration ? { reason: 'explicit_native_migration_required', detail: error.message } : {}) };
233
- this.workspace.recordRequest(request.id, migration ? 'failed' : 'unknown', result);
234
- throw openingFailure(error, migration ? 'blocked' : 'unknown');
235
- }
236
- });
161
+ using(selected, action) {
162
+ return this.core.withWorker(selected, worker => action(this.backend(selected, worker), worker));
237
163
  }
164
+ async native() { return this.core.nativeLayer(); }
238
165
  async read(selected, operation, parameters) {
239
- return this.ordered(selected, async () => {
240
- const backend = await this.backend();
241
- await backend.open(selected);
242
- return backend.call(selected, operation, parameters);
243
- });
166
+ return this.using(selected, backend => backend.call(selected, operation, parameters));
244
167
  }
168
+ /** Installation, managed extension and context scripts (`ghidra_scripts` in the working copy). */
245
169
  async scripts(selected, filter, limit, offset) {
246
- return this.ordered(selected, async () => {
247
- const backend = await this.backend();
248
- await backend.open(selected);
249
- if (!backend.scripts)
250
- fail('configuration', 'Selected backend does not provide the configured script inventory.');
251
- return backend.scripts(selected, filter, limit, offset);
252
- });
170
+ const native = await this.native();
171
+ if (!native.ghidraHome)
172
+ fail('configuration', 'The native layer does not expose its installation.');
173
+ return scriptInventory(native.ghidraHome, this.core.copyRoot(selected), filter, limit, offset, [...native.extensionRoots ?? []]);
253
174
  }
254
- async paired(selected, other, action) {
255
- const scopes = [selected, other].sort((a, b) => this.workspace.context(a).id.localeCompare(this.workspace.context(b).id));
256
- if (this.workspace.context(selected).id === this.workspace.context(other).id)
257
- return this.ordered(selected, action);
258
- return this.ordered(scopes[0], () => this.ordered(scopes[1], action));
175
+ /** A GZF of `other` (another context, or this copy's base version) imported next to the selected program for one comparison. */
176
+ async peer(selected, other, action) {
177
+ if (other !== 'base' && other.session === selected.session && other.target === selected.target)
178
+ fail('invalid', 'Select two different contexts, or omit --other-target to compare with the base version.');
179
+ const directory = await this.core.copyScratch(selected), gzf = join(directory, 'peer.gzf');
180
+ try {
181
+ if (other === 'base')
182
+ await this.core.exportBase(selected, gzf);
183
+ else
184
+ await this.core.exportProgram(other, gzf);
185
+ return await this.core.withWorker(selected, worker => withPeer(worker, gzf, peer => action(worker, peer)));
186
+ }
187
+ finally {
188
+ await rm(directory, { recursive: true, force: true }).catch(() => { });
189
+ }
259
190
  }
191
+ /** Read-only comparison of two contexts, or of a context with its base version (`/sdk/changes` only). */
260
192
  async crossRead(selected, other, operation, parameters) {
261
- return this.paired(selected, other, async () => {
262
- const backend = await this.backend();
263
- await backend.open(selected);
264
- await backend.open(other);
265
- if (!backend.pair)
266
- fail('configuration', 'Selected backend does not support explicit cross-target comparisons.');
267
- return backend.pair(selected, other, await backend.saved(other), operation, parameters);
268
- });
269
- }
270
- async savedScalars(context, backend, snapshot) {
271
- if (!context.scalars.length)
272
- return context.scalars;
273
- if (!backend.fields)
274
- fail('configuration', 'Tracked scalar fields require saved-state inspection.');
275
- const fields = await backend.fields(snapshot, context.scalars);
276
- return context.scalars.flatMap(change => {
277
- const observed = fields[fieldKey(change)];
278
- if (!observed)
279
- fail('partial', 'Saved inspection omitted a tracked scalar field.');
280
- if (!observed.exists)
281
- return [{ ...change, local: null, removed: true }];
282
- const { removed, ...previous } = change;
283
- if (observed.value === previous.original && !previous.conflict)
284
- return [];
285
- return [{ ...previous, local: observed.value }];
193
+ if (other === 'base' && operation !== '/sdk/changes')
194
+ fail('invalid', 'Only changes compare can use the base version.');
195
+ return this.peer(selected, other, async (worker, peer) => {
196
+ const program = worker.program ?? '/' + selected.target + '.bin', otherScope = other === 'base' ? selected : other;
197
+ if (operation === '/sdk/changes')
198
+ return nativeQuery(worker, operation, { ...parameters, peer_program: peer });
199
+ let routing;
200
+ if (operation === '/diff_functions')
201
+ routing = { program_a: program, program_b: peer };
202
+ else if (operation === '/compare_programs_documentation')
203
+ routing = { program };
204
+ else if (['/bulk_fuzzy_match', '/find_similar_functions_fuzzy'].includes(operation))
205
+ routing = { source_program: program, target_program: peer };
206
+ else
207
+ fail('invalid', 'Unsupported cross-target comparison.');
208
+ const value = object(await worker.request('GET', operation, { ...parameters, ...routing }));
209
+ if (operation === '/compare_programs_documentation' && Array.isArray(value.programs)) {
210
+ value.programs = value.programs.map(raw => {
211
+ const row = object(raw), who = row.path === program ? selected : otherScope;
212
+ const { name: _n, path: _p, is_current: _c, ...counts } = row;
213
+ return { ...who, ...counts };
214
+ });
215
+ }
216
+ return logicalPrograms(value, new Map([[program, selected], ['program', selected], [peer, otherScope], [peer.slice(1), otherScope]]));
286
217
  });
287
218
  }
288
- async transfer(selected, source, dryRun, callerId) {
289
- if (this.workspace.context(selected).id === this.workspace.context(source).id)
290
- fail('invalid', 'Documentation source and destination contexts must differ.');
291
- const reserved = this.workspace.reserveRequest(selected, '/merge_program_documentation', { source, dryRun }, callerId);
292
- return this.paired(selected, source, async () => {
293
- const request = this.workspace.request(reserved.request.id);
294
- if (reserved.replay && request.state !== 'accepted') {
295
- if (request.state === 'applied')
296
- return request.result;
297
- fail('unknown', 'This documentation transfer retains an unproved outcome and is not repeated.', request.result);
298
- }
299
- const backend = await this.backend();
300
- await backend.open(source);
301
- const sourceView = await backend.saved(source);
302
- if (sourceView.kind === 'native' && !backend.snapshotFile)
303
- fail('configuration', 'Selected backend cannot retain an immutable documentation source.');
304
- const sourceSnapshot = sourceView.kind === 'native' ? await this.workspace.captureSnapshot(await backend.snapshotFile(sourceView)) : sourceView;
305
- await backend.open(selected);
306
- if (!backend.transfer || !backend.transferCheck)
307
- fail('configuration', 'Selected backend cannot verify documentation transfer.');
308
- const context = this.workspace.context(selected);
309
- this.workspace.startRequest(request.id, { kind: 'transfer', generation: context.generation, workingSnapshot: context.workingSnapshot, source, sourceView, sourceSnapshot, dryRun });
310
- try {
311
- const value = transferResult(await backend.transfer(selected, sourceSnapshot, dryRun), dryRun);
312
- const snapshot = await backend.saved(selected);
313
- if (!dryRun && transferResult(await backend.transferCheck(selected, sourceSnapshot, snapshot), true).total !== 0)
314
- fail('partial', 'Saved destination retains untransferred documentation.');
315
- const scalars = dryRun ? context.scalars : await this.savedScalars(context, backend, snapshot);
316
- const complexChanges = dryRun || value.total === 0 ? context.complexChanges : [...context.complexChanges, request.id];
317
- const result = { ...selected, source, state: dryRun ? 'preview' : 'applied', sharedState: 'pending',
318
- pendingChanges: scalars.length + complexChanges.length, value };
319
- this.workspace.completeSavedRequest(selected, request.id, context.generation, { workingSnapshot: snapshot, complexChanges, scalars }, result);
320
- return result;
321
- }
322
- catch (error) {
323
- let savedSnapshot;
324
- try {
325
- savedSnapshot = await backend.saved(selected);
326
- }
327
- catch { }
328
- this.workspace.recordRequest(request.id, 'unknown', { ...selected, source, state: 'unknown', sourceSnapshot, ...(savedSnapshot ? { savedSnapshot } : {}) });
329
- throw error;
330
- }
219
+ /** Copies documentation from another context into this working copy (Ghidra's merge_program_documentation). */
220
+ async transfer(selected, source, dryRun) {
221
+ const value = await this.peer(selected, source, async (worker, peer) => {
222
+ const result = transferResult(await worker.request('POST', '/merge_program_documentation', { source: peer, target: worker.program ?? '/' + selected.target + '.bin', dry_run: dryRun }), dryRun);
223
+ return result;
331
224
  });
225
+ return { ...selected, source, state: dryRun ? 'preview' : 'applied', value };
332
226
  }
333
227
  async strings(selected, contains, limit, offset) {
334
228
  const pattern = text(contains, 4096).replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
335
229
  const value = await this.read(selected, '/search_strings', { search_term: pattern, min_length: 0, offset, limit });
336
- const page = pageResult(value, 'matches', limit, offset);
337
- const items = page.items.map(item => {
338
- const row = object(item);
339
- if (typeof row.value !== 'string')
340
- fail('malformed', 'String result lacks decoded text.');
341
- return { address: publicAddress(row.address), text: row.value };
342
- });
230
+ const page = pageResult(value, 'matches');
231
+ const items = page.items.map(item => { const row = object(item); return { address: publicAddress(row.address), text: row.value }; });
343
232
  return { ...selected, items, offset, limit, total: page.total, truncated: object(value).truncated === true || offset + items.length < page.total,
344
233
  ...(object(value).scan ? { scan: object(value).scan, totalKnown: object(value).total_known !== false } : {}) };
345
234
  }
346
235
  async function(selected, at, decompile = false, page) {
347
- return this.ordered(selected, async () => {
348
- const backend = await this.backend();
349
- await backend.open(selected);
236
+ return this.using(selected, async (backend) => {
350
237
  const value = await backend.call(selected, '/get_functions', { functions: at, fields: decompile ? 'entry_point,signature,decompiled_code' : 'entry_point,signature', include_call_context: false });
351
238
  const result = functionResult(value, at);
352
239
  if (typeof result.signature !== 'string')
@@ -354,651 +241,70 @@ export class Research {
354
241
  if (decompile && typeof result.decompiled_code !== 'string')
355
242
  functionFailure(at, 'missing_decompiler_text');
356
243
  const listing = object(await backend.call(selected, '/get_comment', { address: result.entry_point }));
357
- const window = decompile ? textWindow(String(result.decompiled_code), page?.limit ?? 16000, page?.offset ?? 0, Boolean(object(result.truncation ?? {}).decompiled_code)) : undefined;
244
+ const window = decompile ? textWindow(String(result.decompiled_code), page?.limit ?? 16000, page?.offset ?? 0, Boolean(object(result.truncation ?? {}).decompiled_code), false) : undefined;
358
245
  const { content, ...paging } = window ?? { content: undefined };
359
246
  return { ...selected, address: publicAddress(result.entry_point), name: result.name, signature: result.signature, comments: comments(listing), ...(window ? { code: content, ...paging } : {}) };
360
247
  });
361
248
  }
249
+ /** The view identity reported with a result: what --expect-view or a continuation cursor names. Observed once, before the read. */
250
+ async view(selected, backend) { return digest({ ...selected, observation: await backend.observation(selected) }); }
362
251
  async inspectFunctions(selected, parameters, options) {
363
- const lookup = entryRequest(parameters, options);
364
- return this.ordered(selected, async () => {
365
- const backend = await this.backend();
366
- await backend.open(selected);
367
- const context = this.workspace.context(selected);
368
- const observe = backend.inspectObservation ? () => backend.inspectObservation(selected) : backend.observation ? () => backend.observation(selected) : undefined;
369
- if (lookup && !observe)
370
- fail('unsupported', 'Address resolution requires guarded native observations.');
371
- const observation = await observe?.();
372
- const view = { revision: revision(context.baseRevision), identity: digest({ target: selected.target, context: context.id, generation: context.generation, snapshot: context.workingSnapshot, epoch: context.viewEpoch ?? 0, observation }) };
373
- return inspectFunctions(backend, selected, parameters, options, view, observation, observe);
374
- });
252
+ return this.using(selected, async (backend) => inspectFunctions(backend, selected, parameters, options, { identity: await this.view(selected, backend) }));
375
253
  }
376
254
  async stringAnchors(selected, request) {
377
- return this.ordered(selected, async () => {
378
- const backend = await this.backend();
379
- await backend.open(selected);
380
- const observe = backend.inspectObservation ? () => backend.inspectObservation(selected) : backend.observation ? () => backend.observation(selected) : undefined;
381
- if (!observe)
382
- fail('unsupported', 'String anchors require guarded native observations.');
383
- const context = this.workspace.context(selected), observation = await observe();
384
- const view = digest({ target: selected.target, context: context.id, generation: context.generation, snapshot: context.workingSnapshot, epoch: context.viewEpoch ?? 0, observation });
385
- return inspectAnchors(backend, selected, request, view, observation, observe);
386
- });
255
+ return this.using(selected, async (backend) => inspectAnchors(backend, selected, request, await this.view(selected, backend)));
387
256
  }
388
257
  async codeReferences(selected, request) {
389
- return this.ordered(selected, async () => {
390
- const backend = await this.backend();
391
- await backend.open(selected);
392
- if (!backend.observation)
393
- fail('unsupported', 'Code-reference continuation requires native view observation.');
394
- const context = this.workspace.context(selected), observation = await backend.observation(selected);
395
- const view = digest({ target: selected.target, context: context.id, generation: context.generation, snapshot: context.workingSnapshot, epoch: context.viewEpoch ?? 0, observation });
396
- return inspectCodeReferences(backend, selected, request, view, observation);
397
- });
258
+ return this.using(selected, async (backend) => inspectCodeReferences(backend, selected, request, await this.view(selected, backend)));
398
259
  }
399
260
  async navigation(selected, maximum) {
400
- return this.ordered(selected, async () => {
401
- const backend = await this.backend();
402
- await backend.open(selected);
403
- const value = navigationResult(await backend.call(selected, '/navigation_diagnostic', { max_scan: maximum }), maximum);
404
- return { ...selected, value: { ...value, initialAnalysis: this.workspace.model(selected.target).settings.autoAnalyze ? 'requested' : 'none', priorAnalysis: 'unknown', provenance: 'Initial facade policy only; imported/saved metadata may have an unknown analysis history.' } };
405
- });
261
+ return { ...selected, value: await this.read(selected, '/navigation_diagnostic', { max_scan: maximum }) };
406
262
  }
407
263
  async xrefs(selected, at, limit, offset) {
408
- return this.ordered(selected, async () => {
409
- const backend = await this.backend();
410
- await backend.open(selected);
411
- const page = pageResult(await backend.call(selected, '/get_xrefs_to', { address: at, limit, offset }), 'references', limit, offset);
412
- const items = [];
413
- for (const item of page.items) {
414
- const row = object(item);
415
- if (typeof row.type !== 'string' || !row.type)
416
- fail('partial', 'Reference result lacks its kind.');
264
+ return this.using(selected, async (backend) => {
265
+ const page = pageResult(await backend.call(selected, '/get_xrefs_to', { address: at, limit, offset }), 'references');
266
+ const rows = page.items.map(object);
267
+ // Entry points of the containing functions: one get_functions call per 20 distinct reference sources.
268
+ const sources = [...new Set(rows.filter(row => row.from_function !== undefined && row.from_address !== 'Entry Point').map(row => address(row.from_address)))];
269
+ const entries = new Map();
270
+ for (let i = 0; i < sources.length; i += 20) {
271
+ const functions = object(object(await backend.call(selected, '/get_functions', { functions: sources.slice(i, i + 20).join(','), fields: 'entry_point', include_call_context: false })).functions);
272
+ for (const [selector, found] of Object.entries(functions))
273
+ entries.set(selector, object(found).entry_point);
274
+ }
275
+ const items = rows.map(row => {
417
276
  // Ghidra's external-entry reference is metadata, not a navigable address.
418
- if (row.from_address === 'Entry Point' && row.type === 'EXTERNAL') {
419
- items.push({ from: null, to: publicAddress(at), kind: row.type, source: 'entry-point' });
420
- continue;
421
- }
422
- const from = address(row.from_address);
423
- let containing;
424
- if (row.from_function !== undefined) {
425
- const found = functionResult(await backend.call(selected, '/get_functions', { functions: from, fields: 'entry_point', include_call_context: false }), from);
426
- if (found.name !== row.from_function)
427
- fail('binding', 'Reference function changed during ordered inspection.');
428
- containing = { address: publicAddress(found.entry_point), name: found.name };
429
- }
430
- items.push({ from: publicAddress(from), to: publicAddress(at), kind: row.type, ...(containing ? { function: containing } : {}) });
431
- }
277
+ if (row.from_address === 'Entry Point' && row.type === 'EXTERNAL')
278
+ return { from: null, to: publicAddress(at), kind: row.type, source: 'entry-point' };
279
+ const from = address(row.from_address), entry = entries.get(from);
280
+ const containing = row.from_function === undefined ? undefined : { ...(typeof entry === 'string' ? { address: publicAddress(entry) } : {}), name: row.from_function };
281
+ return { from: publicAddress(from), to: publicAddress(at), kind: row.type, ...(containing ? { function: containing } : {}) };
282
+ });
432
283
  return { ...selected, items, offset, limit, total: page.total, truncated: offset + items.length < page.total };
433
284
  });
434
285
  }
435
286
  async comment(selected, at, kind) {
436
- const result = object(await this.read(selected, '/get_comment', { address: at }));
437
- if (address(result.address) !== address(at))
438
- fail('partial', 'Comment response changed its address selector.');
439
- const values = comments(result), context = this.workspace.context(selected);
440
- const change = context.scalars.find(change => change.address === address(at) && change.field === 'comment.' + kind);
441
- return { ...selected, address: publicAddress(at), ...(kind ? { kind, text: values[kind], sharedState: change?.conflict ? 'conflict' : change ? 'pending' : 'shared' } : { comments: values }) };
287
+ const values = comments(await this.read(selected, '/get_comment', { address: at }));
288
+ return { ...selected, address: publicAddress(at), ...(kind ? { kind, text: values[kind] } : { comments: values }) };
442
289
  }
443
- async edit(selected, at, field, value, callerId, resolution) {
290
+ /** Renames a function or sets a comment; stop, merge, close and export save the working copy. */
291
+ async edit(selected, at, field, value) {
444
292
  at = address(at);
445
- const reserved = this.workspace.reserveRequest(selected, field === 'function.name' ? 'ghidra.functions.rename' : 'ghidra.comments.set', { address: at, field, value, ...(resolution ? { resolution } : {}) }, callerId);
446
- const action = async () => {
447
- const request = this.workspace.request(reserved.request.id);
448
- if (reserved.replay) {
449
- if (request.state === 'applied')
450
- return request.result;
451
- if (request.state !== 'accepted')
452
- return { ...selected, state: request.state, ...(callerId ? { requestId: callerId } : {}) };
453
- }
454
- const backend = await this.backend();
455
- // Restore before starting this mutation; other uncertain effects still block the context.
456
- await backend.open(selected);
457
- const before = this.workspace.context(selected);
458
- if (resolution && before.nativeCheckout)
459
- fail('unsupported', 'Native conflicts require Ghidra resolver decisions; the legacy scalar resolution option cannot choose a native winner.');
460
- const previous = before.scalars.find(change => change.address === at && change.field === field);
461
- let observed;
462
- if (field === 'function.name') {
463
- observed = String(functionResult(await backend.call(selected, '/get_functions', { functions: at, fields: 'entry_point', include_call_context: false }), at).name);
464
- }
465
- else
466
- observed = comments(await backend.call(selected, '/get_comment', { address: at }))[field.slice(8)];
467
- let original = previous ? previous.original : observed, dependency = previous?.dependency;
468
- if (resolution) {
469
- if (!previous?.conflict)
470
- fail('conflict', 'Explicit resolution requires an existing field conflict.');
471
- if (!backend.latest || !backend.fields)
472
- fail('configuration', 'Resolution requires verified shared-state inspection.');
473
- if (this.workspace.activePublication(selected.target) || this.workspace.model(selected.target).state === 'unknown')
474
- failUnresolved(this.workspace, selected, 'Shared publication outcome must be reconciled before resolving a field.');
475
- const shared = await backend.latest(selected.target);
476
- this.workspace.observeShared(selected.target, shared.revision, shared.snapshot);
477
- const current = (await backend.fields(shared.snapshot, [previous]))[fieldKey(previous)];
478
- if (!current || !current.exists)
479
- fail('conflict', 'The shared field dependency disappeared; transfer work onto a current context.');
480
- if (current.value !== resolution.expectedShared) {
481
- const result = { ...selected, state: 'conflict', reason: 'shared_changed', expected: resolution.expectedShared, shared: current.value, local: observed, applied: 0 };
482
- this.workspace.recordRequest(request.id, 'failed', result);
483
- fail('conflict', 'Shared value changed since the explicit decision; local work is retained.', result);
484
- }
485
- original = current.value;
486
- dependency = current.dependency;
487
- }
488
- else if (previous?.conflict)
489
- fail('conflict', 'This field has an unresolved shared conflict; use an explicit resolution.');
490
- if (dependency === undefined && backend.fields && before.workingSnapshot) {
491
- const anchor = (await backend.fields(before.workingSnapshot, [{ address: at, field }]))[at + '@' + field];
492
- if (!anchor)
493
- fail('partial', 'Saved private dependency inspection omitted the edited field.');
494
- dependency = anchor.dependency;
495
- }
496
- const scalars = before.scalars.filter(change => change.address !== at || change.field !== field);
497
- if (value !== original)
498
- scalars.push({ address: at, field, original, local: value, ...(dependency ? { dependency } : {}) });
499
- const complexChanges = [...before.complexChanges];
500
- if (previous && previous.local !== observed && !complexChanges.includes(request.id))
501
- complexChanges.push(request.id);
502
- const result = { ...selected, state: 'applied', sharedState: scalars.length || complexChanges.length ? 'pending' : 'shared',
503
- ...(resolution ? { conflict: 'resolved' } : {}), pendingChanges: scalars.length + complexChanges.length };
504
- this.workspace.startRequest(request.id, { kind: 'scalar', address: at, field, value, observed, generation: before.generation,
505
- workingSnapshot: before.workingSnapshot, scalars, complexChanges, result });
506
- try {
507
- const changed = object(await backend.call(selected, field === 'function.name' ? '/rename_function' : '/set_comment', field === 'function.name' ? { old_name: at, new_name: value, strict_mode: 'off' } : { address: at, type: field.slice(8), comment: value ?? '' }));
508
- if (changed.status !== 'success' && changed.success !== true)
509
- fail('partial', 'Editing operation was not acknowledged.');
510
- const after = field === 'function.name' ? String(functionResult(await backend.call(selected, '/get_functions', { functions: at, fields: 'entry_point', include_call_context: false }), at).name) :
511
- comments(await backend.call(selected, '/get_comment', { address: at }))[field.slice(8)];
512
- if (after !== value)
513
- fail('partial', 'Editing readback does not match the requested value.');
514
- const snapshot = await backend.saved(selected);
515
- this.workspace.completeSavedRequest(selected, request.id, before.generation, { workingSnapshot: snapshot, scalars, complexChanges }, result);
516
- return result;
517
- }
518
- catch (error) {
519
- this.workspace.recordRequest(request.id, 'unknown', { ...selected, state: 'unknown' });
520
- throw error;
521
- }
522
- };
523
- return this.ordered(selected, () => resolution ? this.sharedOrder(selected.target, action) : action());
524
- }
525
- /** A worker parked by native Update/check-in is reopened or stopped before the command ends, whatever its outcome. */
526
- async resuming(selected, action) {
527
- try {
528
- return await action();
529
- }
530
- finally {
531
- const backend = await this.backend().catch(() => undefined);
532
- await backend?.resumeParked?.(selected).catch(() => { });
533
- }
534
- }
535
- async sharedOrder(target, action) {
536
- // The wait is attributed separately: a target lane held by another context's merge is not this command's work.
537
- const key = 'shared:' + target, previous = this.tasks.get(key), task = timed('facade.queue', 'shared', async () => { await previous?.catch(() => { }); }).then(action);
538
- this.tasks.set(key, task);
539
- try {
540
- return await task;
541
- }
542
- finally {
543
- if (this.tasks.get(key) === task)
544
- this.tasks.delete(key);
545
- }
546
- }
547
- async reconcileRequests(selected, backend) {
548
- return this.sharedOrder(selected.target, () => this.reconcile(selected, backend));
549
- }
550
- async reconcile(selected, backend, reportOpenFailure = false) {
551
- const active = this.workspace.activePublication(selected.target);
552
- if (active) {
553
- if (active.state === 'preparing')
554
- this.workspace.rejectPublication(active.id, { session: active.session, target: active.target, state: 'not_published', applied: 0 });
555
- else if (backend.recover) {
556
- const observed = await backend.recover(active);
557
- if (observed.state === 'verified')
558
- this.workspace.finishPublication(active.id, observed.revision, { session: active.session, target: active.target,
559
- state: 'merged', sharedRevision: revision(observed.revision), applied: active.scalars.length + (active.complexChanges?.length ?? Number(active.complex)), pendingChanges: 0 }, observed.snapshot);
560
- if (observed.state === 'verified' && backend.dropNative)
561
- await backend.dropNative(active);
562
- if (observed.state === 'refused')
563
- this.workspace.finishRefusedPublication(active.id, observed.revision, observed.snapshot, { session: active.session, target: active.target, state: 'conflict', reason: observed.reason ?? 'shared_changed', applied: 0,
564
- pendingChanges: active.scalars.length + (active.complexChanges?.length ?? Number(active.complex)),
565
- conflicts: [{ engine: 'ghidra', message: observed.conflict }], reconciled: true });
566
- }
567
- }
568
- for (const request of this.workspace.unresolved(selected)) {
569
- if (request.operation === 'ghidra.merge') {
570
- let publication;
571
- try {
572
- publication = this.workspace.publication(request.id);
573
- }
574
- catch (error) {
575
- if (!String(error.code).endsWith('.notFound'))
576
- throw error;
577
- }
578
- if (!publication) {
579
- let empty;
580
- try {
581
- empty = await backend.recoverEmptyNative?.(selected, request.id);
582
- }
583
- catch (error) {
584
- const retained = this.retainedDisposal(selected, request.id, error);
585
- if (!retained)
586
- throw error;
587
- continue;
588
- }
589
- if (empty?.state === 'verified') {
590
- const current = this.workspace.context(selected);
591
- this.workspace.completeSavedRequest(selected, request.id, current.generation, {}, { ...selected, state: 'empty', applied: 0, pendingChanges: 0, sharedRevision: revision(empty.revision), engine: 'ghidra-native' });
592
- continue;
593
- }
594
- if (backend.nativeEngine) {
595
- const update = await backend.recoverUpdate?.(selected, request.id);
596
- if (!update || update.state === 'unknown')
597
- continue;
598
- }
599
- this.workspace.recordRequest(request.id, 'failed', { ...selected, state: 'not_published', applied: 0 });
600
- }
601
- continue;
602
- }
603
- if (request.operation === 'ghidra.refresh') {
604
- // Native Update may have changed the saved checkout. An interrupted result cannot be declared not_updated.
605
- if (backend.nativeEngine) {
606
- const update = await backend.recoverUpdate?.(selected, request.id);
607
- if (!update || update.state === 'unknown')
608
- continue;
609
- const context = this.workspace.context(selected);
610
- if (update.state === 'conflict')
611
- this.workspace.recordRequest(request.id, 'failed', { ...selected, state: 'conflict', receivedChanges: 0, preservedLocalChanges: count(context), conflicts: [{ engine: 'ghidra', message: update.conflict }] });
612
- else
613
- this.workspace.completeSavedRequest(selected, request.id, context.generation, {}, { ...selected, state: 'updated', engine: 'ghidra-native', sharedRevision: revision(update.revision), receivedChanges: update.receivedChanges, preservedLocalChanges: count(context), nativeMergeInvocations: update.nativeMergeInvocations, conflicts: [] });
614
- }
615
- else
616
- this.workspace.recordRequest(request.id, 'failed', { ...selected, state: 'not_updated', receivedChanges: 0 });
617
- continue;
618
- }
619
- if (request.operation === 'ghidra.open') {
620
- if (backend.recoverModel && !await backend.recoverModel(selected.target))
621
- continue;
622
- try {
623
- await backend.open(selected, request.id);
624
- const intent = object(request.intent);
625
- if (intent.mode)
626
- await backend.mode(selected, intent.mode);
627
- const context = this.workspace.context(selected), result = { ...selected, state: 'ready', baseRevision: revision(context.baseRevision),
628
- sharedRevision: revision(this.workspace.model(selected.target).sharedRevision), pendingChanges: count(context) };
629
- this.workspace.completeSavedRequest(selected, request.id, context.generation, {}, result);
630
- }
631
- catch (error) {
632
- if (reportOpenFailure)
633
- throw error; /* Status retains unresolved evidence without dispatching another intent. */
634
- }
635
- continue;
636
- }
637
- const execution = request.execution === undefined ? undefined : object(request.execution);
638
- if (execution?.kind === 'native-discard') {
639
- const discarded = await backend.recoverDiscardNative?.(selected, request.id, execution.checkout);
640
- if (discarded?.state === 'verified') {
641
- const current = this.workspace.context(selected);
642
- this.workspace.completeSavedRequest(selected, request.id, current.generation, {}, { ...selected, state: 'discarded', discardedChanges: Number(execution.discardedChanges), pendingChanges: 0,
643
- baseRevision: revision(discarded.baseRevision), ...(discarded.retainedKeepFile ? { retainedKeepFile: discarded.retainedKeepFile } : {}) });
644
- }
645
- continue;
646
- }
647
- if (execution?.kind === 'discard') {
648
- try {
649
- const current = this.workspace.context(selected), base = execution.baseSnapshot, discarded = execution.discardedSnapshot;
650
- if (!backend.closed || !await backend.closed(selected) || current.generation !== execution.generation || current.baseSnapshot?.id !== base.id || current.workingSnapshot?.id !== discarded.id)
651
- continue;
652
- await this.workspace.artifacts.verify(base);
653
- await this.workspace.artifacts.verify(discarded);
654
- this.workspace.completeSavedRequest(selected, request.id, current.generation, { workingSnapshot: base, state: 'stopped', viewEpoch: (current.viewEpoch ?? 0) + 1, scalars: [], complexChanges: [] }, execution.result);
655
- }
656
- catch { /* A local switch is reconstructed only from its unchanged retained snapshots. */ }
657
- continue;
658
- }
659
- if (execution?.kind === 'debugger') {
660
- try {
661
- if (backend.closed && await backend.closed(selected)) {
662
- const current = this.workspace.context(selected), outcome = object(request.result ?? {}), retained = outcome.savedDebugger;
663
- const saved = retained && current.generation === execution.generation ? retained : current.debugger;
664
- const program = outcome.metadataChanged === true && current.generation === execution.generation ? outcome.savedSnapshot : undefined;
665
- if (saved || program) {
666
- if (program)
667
- await this.workspace.artifacts.verify(program);
668
- for (const trace of saved?.traces ?? [])
669
- await this.workspace.artifacts.verify(trace.snapshot);
670
- this.workspace.saveContext(selected, current.generation, { ...(saved ? { debugger: { ...saved, connected: false, traces: saved.traces.map(trace => ({ ...trace, connected: false })) } } : {}),
671
- ...(program ? { workingSnapshot: program, complexChanges: current.complexChanges.includes(request.id) ? current.complexChanges : [...current.complexChanges, request.id] } : {}) });
672
- }
673
- this.workspace.recordRequest(request.id, 'failed', { ...selected, state: 'disconnected', outcome: 'unknown', operation: execution.operation });
674
- }
675
- }
676
- catch { /* A CPU action is not replayed or inferred from a later program counter. */ }
677
- continue;
678
- }
679
- if (execution?.kind === 'ui') {
680
- try {
681
- if (backend.closed && await backend.closed(selected)) {
682
- this.workspace.recordRequest(request.id, 'failed', { ...selected, state: 'disconnected', outcome: 'unknown', operation: execution.operation });
683
- continue;
684
- }
685
- if (execution.operation === 'goto' && backend.ui) {
686
- const p = object(object(request.intent).parameters), cursor = await backend.ui(selected, 'cursor', {}), location = object(cursor.address), current = this.workspace.context(selected);
687
- if (location.session !== selected.session || location.target !== selected.target || address(location.address) !== address(p.address) || current.generation !== execution.generation)
688
- continue;
689
- const containing = cursor.function ? object(cursor.function) : undefined, value = { address: publicAddress(location.address), ...(containing && typeof containing.function_name === 'string' ? { function: containing.function_name } : {}) };
690
- this.workspace.completeSavedRequest(selected, request.id, current.generation, {}, { ...selected, state: 'applied', value });
691
- }
692
- }
693
- catch { /* Only the live verified cursor or a verified lost process establishes continuation. */ }
694
- continue;
695
- }
696
- if (execution?.kind === 'export') {
697
- try {
698
- const snapshot = execution.snapshot;
699
- await this.workspace.artifacts.verify(snapshot);
700
- const observed = await this.workspace.artifacts.capture(text(execution.output, 4096), 'snapshot'), current = this.workspace.context(selected);
701
- if (observed.id !== snapshot.id || current.generation !== execution.generation)
702
- continue;
703
- this.workspace.completeSavedRequest(selected, request.id, current.generation, { workingSnapshot: execution.workingSnapshot ?? snapshot }, { ...selected, state: 'exported', output: execution.output, sha256: snapshot.sha256, size: snapshot.size });
704
- }
705
- catch { /* Partial or changed output cannot prove an export and is never overwritten. */ }
706
- continue;
707
- }
708
- if (execution?.kind === 'close' && backend.closed) {
709
- try {
710
- if (!await backend.closed(selected))
711
- continue;
712
- const current = this.workspace.context(selected);
713
- this.workspace.completeSavedRequest(selected, request.id, current.generation, { state: 'stopped' }, { ...selected, state: 'closed', pendingChanges: count(current) });
714
- }
715
- catch { /* A stopped metadata flag alone never proves process release. */ }
716
- continue;
717
- }
718
- if (execution?.kind === 'save') {
719
- try {
720
- const snapshot = object(request.result).savedSnapshot;
721
- if (!snapshot)
722
- continue;
723
- await this.workspace.artifacts.verify(snapshot);
724
- const current = this.workspace.context(selected);
725
- if (current.generation !== execution.generation)
726
- continue;
727
- this.workspace.completeSavedRequest(selected, request.id, current.generation, { workingSnapshot: snapshot, viewEpoch: (current.viewEpoch ?? 0) + 1 }, { ...selected, state: 'saved', pendingChanges: count(current) });
728
- }
729
- catch { /* Unproved save outcome stays retained without another save dispatch. */ }
730
- continue;
731
- }
732
- if (execution?.kind === 'transfer' && execution.dryRun === false && backend.transferCheck) {
733
- try {
734
- const sourceSnapshot = execution.sourceSnapshot, retained = request.result && object(request.result).savedSnapshot;
735
- await this.workspace.artifacts.verify(sourceSnapshot);
736
- await backend.open(selected, request.id);
737
- const snapshot = retained ? retained : await backend.saved(selected);
738
- await this.workspace.artifacts.verify(snapshot);
739
- if (transferResult(await backend.transferCheck(selected, sourceSnapshot, snapshot), true).total !== 0)
740
- continue;
741
- const current = this.workspace.context(selected);
742
- if (current.generation !== execution.generation && current.workingSnapshot?.id !== object(execution.workingSnapshot).id)
743
- continue;
744
- const scalars = await this.savedScalars(current, backend, snapshot);
745
- const complexChanges = [...current.complexChanges, request.id];
746
- this.workspace.completeSavedRequest(selected, request.id, current.generation, { workingSnapshot: snapshot, complexChanges, scalars, viewEpoch: (current.viewEpoch ?? 0) + 1 }, { ...selected, source: execution.source, state: 'applied', reconciled: true, sharedState: 'pending', pendingChanges: scalars.length + complexChanges.length });
747
- }
748
- catch { /* Saved source/candidate remain retained; never execute transfer again as recovery. */ }
749
- continue;
750
- }
751
- if (execution?.kind === 'program' && execution.savedVerification === true) {
752
- try {
753
- const retained = request.result && object(request.result).savedSnapshot;
754
- let snapshot;
755
- if (retained) {
756
- snapshot = retained;
757
- await this.workspace.artifacts.verify(snapshot);
758
- }
759
- else {
760
- await backend.open(selected, request.id);
761
- snapshot = await backend.saved(selected);
762
- }
763
- const intent = object(request.intent), parameters = object(intent.parameters);
764
- const value = await verifyMutation(backend, snapshot, request.operation, parameters, {});
765
- const current = this.workspace.context(selected);
766
- if (current.generation !== execution.generation)
767
- continue;
768
- const scalars = await this.savedScalars(current, backend, snapshot), complexChanges = [...current.complexChanges, request.id];
769
- this.workspace.completeSavedRequest(selected, request.id, current.generation, { workingSnapshot: snapshot, complexChanges, scalars, viewEpoch: (current.viewEpoch ?? 0) + 1 }, { ...selected, state: 'applied', sharedState: 'pending', pendingChanges: scalars.length + complexChanges.length, value });
770
- }
771
- catch { /* Retain both snapshots and the unresolved intent when complete effects cannot be proven. */ }
772
- continue;
773
- }
774
- if (execution?.kind === 'scalar') {
775
- try {
776
- await backend.open(selected, request.id);
777
- const field = text(execution.field), at = address(execution.address);
778
- const observed = field === 'function.name' ? String(functionResult(await backend.call(selected, '/get_functions', { functions: at, fields: 'entry_point', include_call_context: false }), at).name) : comments(await backend.call(selected, '/get_comment', { address: at }))[field.slice(8)];
779
- if (observed !== execution.value)
780
- continue;
781
- const current = this.workspace.context(selected), snapshot = await backend.saved(selected);
782
- const expected = number(execution.generation, Number.MAX_SAFE_INTEGER);
783
- if (current.generation !== expected && current.workingSnapshot?.id !== object(execution.workingSnapshot).id)
784
- continue;
785
- this.workspace.completeSavedRequest(selected, request.id, current.generation, { workingSnapshot: snapshot,
786
- scalars: execution.scalars, complexChanges: execution.complexChanges }, execution.result);
787
- }
788
- catch { /* Never replay an uncertain setter merely because its desired value was not observed. */ }
789
- }
790
- }
791
- }
792
- /**
793
- * `close` releases the working copy after publication; otherwise the context continues at the published version.
794
- * It only chooses what follows a publication, so it is not part of the request identity.
795
- */
796
- async merge(selected, callerId, close = false) {
797
- const reserved = this.workspace.reserveRequest(selected, 'ghidra.merge', {}, callerId);
798
- return this.ordered(selected, () => this.resuming(selected, () => this.sharedOrder(selected.target, async () => {
799
- let request = this.workspace.request(reserved.request.id), backend;
800
- if (reserved.replay && ['running', 'unknown'].includes(request.state)) {
801
- backend = await this.backend();
802
- await this.reconcile(selected, backend);
803
- request = this.workspace.request(request.id);
804
- }
805
- if (reserved.replay && request.state !== 'accepted') {
806
- if (request.state === 'applied')
807
- return request.result;
808
- fail(request.state === 'failed' ? 'conflict' : 'unknown', 'This merge retains its recorded outcome; it is never checked in blindly again.', request.result);
809
- }
810
- if (this.workspace.activePublication(selected.target) || this.workspace.model(selected.target).state === 'unknown')
811
- failUnresolved(this.workspace, selected, 'Shared publication is unresolved; every working copy is retained.');
812
- backend ??= await this.backend();
813
- if (backend.nativeEngine !== 'native-checkout-v1' || !backend.updateNative || !backend.publishNative || !backend.dropNative || !backend.finishEmptyNative)
814
- fail('configuration', 'The primary CLI requires native checkout/Update/check-in; scalar fallback is disabled.');
815
- await backend.open(selected);
816
- if (this.workspace.context(selected).debugger?.connected)
817
- fail('busy', 'Stop the live debugger before handing its native project to Update/check-in.');
818
- this.workspace.startRequest(request.id, { kind: 'native-merge' });
819
- let publication;
820
- try {
821
- const update = await backend.updateNative(selected, request.id), context = this.workspace.context(selected);
822
- if (update.state === 'conflict') {
823
- const result = { ...selected, state: 'conflict', applied: 0, pendingChanges: count(context), conflicts: [{ engine: 'ghidra', message: update.conflict }] };
824
- this.workspace.recordRequest(request.id, 'failed', result);
825
- fail('conflict', 'Native conflict preserves the original working copy and checkout.', result);
826
- }
827
- if (update.state === 'empty') {
828
- // Nothing to publish: a continuing context keeps its checkout exactly as Update left it.
829
- if (close || !backend.continueNative)
830
- await backend.finishEmptyNative(selected, request.id);
831
- const current = this.workspace.context(selected);
832
- const result = { ...selected, state: count(context) ? 'merged' : 'empty', applied: 0, pendingChanges: 0, sharedRevision: revision(update.revision), engine: 'ghidra-native' };
833
- this.workspace.completeSavedRequest(selected, request.id, current.generation, {}, result);
834
- return result;
835
- }
836
- if (update.revision < (this.workspace.model(selected.target).sharedRevision ?? 1)) {
837
- const result = { ...selected, state: 'conflict', reason: 'shared_changed', applied: 0, pendingChanges: count(context) };
838
- this.workspace.recordRequest(request.id, 'failed', result);
839
- fail('conflict', 'Another context observed a newer server version; retain this checkout and perform a new native Update.', result);
840
- }
841
- publication = this.workspace.beginPublication(selected, request.id, update.revision, update.snapshot);
842
- publication = this.workspace.publicationIntent(publication.id);
843
- const published = await backend.publishNative(publication);
844
- if (published.state === 'conflict') {
845
- const result = { ...selected, state: 'conflict', reason: 'shared_changed', applied: 0, pendingChanges: count(context), conflicts: [{ engine: 'ghidra', message: published.conflict ?? 'Shared head changed' }] };
846
- this.workspace.rejectPublication(publication.id, result);
847
- fail('conflict', 'Native check-in was refused; local work remains retained.', result);
848
- }
849
- const result = { ...selected, state: 'merged', sharedRevision: revision(published.revision), applied: count(context), pendingChanges: 0, engine: 'ghidra-native' };
850
- this.workspace.finishPublication(publication.id, published.revision, result, published.snapshot);
851
- // The publication is applied. Continuing is an optimization: when the kept checkout cannot be proved
852
- // unchanged at the published version it is disposed exactly as before, and the next open checks out anew.
853
- if (!close && backend.continueNative && published.observation)
854
- try {
855
- if (await backend.continueNative(selected, published.observation))
856
- return result;
857
- }
858
- catch { /* Disposal below. */ }
859
- await backend.dropNative(selected);
860
- return result;
861
- }
862
- catch (error) {
863
- const state = this.workspace.request(request.id).state;
864
- // A native Update or check-in that provably never left this process: nothing was published.
865
- if (notSent(error) && state !== 'applied' && state !== 'failed') {
866
- const result = { ...selected, state: 'not_published', applied: 0, reason: 'not_sent', engine: 'ghidra-native', ...memoryOf(error) };
867
- if (publication && ['preparing', 'commit_intent'].includes(this.workspace.publication(publication.id).state))
868
- this.workspace.rejectPublication(publication.id, result);
869
- else
870
- this.workspace.recordRequest(request.id, 'failed', result);
871
- throw error;
872
- }
873
- if (state !== 'applied' && state !== 'failed') {
874
- // Proved empty-disposal retention already committed its terminal request atomically above.
875
- // An uncertain release or any publication still follows the unknown-outcome path below.
876
- if (publication && ['commit_intent', 'unknown'].includes(this.workspace.publication(publication.id).state))
877
- this.workspace.unknownPublication(publication.id, { state: 'unknown', engine: 'ghidra-native' });
878
- this.workspace.recordRequest(request.id, 'unknown', { ...selected, state: 'unknown', engine: 'ghidra-native' });
879
- throw unknownOutcome(this.workspace, selected, error);
880
- }
881
- throw error;
882
- }
883
- })));
884
- }
885
- async refresh(selected, callerId) {
886
- const reserved = this.workspace.reserveRequest(selected, 'ghidra.refresh', {}, callerId);
887
- return this.ordered(selected, () => this.resuming(selected, () => this.sharedOrder(selected.target, async () => {
888
- const request = this.workspace.request(reserved.request.id);
889
- if (reserved.replay && request.state !== 'accepted') {
890
- if (request.state === 'applied')
891
- return request.result;
892
- fail(request.state === 'failed' ? 'conflict' : 'unknown', 'Native Update retains its recorded outcome; its saved checkout is preserved.', request.result);
893
- }
894
- if (this.workspace.activePublication(selected.target) || this.workspace.model(selected.target).state === 'unknown')
895
- failUnresolved(this.workspace, selected, 'Shared publication requires reconciliation before Update.');
896
- const backend = await this.backend();
897
- if (backend.nativeEngine !== 'native-checkout-v1' || !backend.updateNative)
898
- fail('configuration', 'Native Update is required; scalar refresh fallback is disabled.');
899
- await backend.open(selected);
900
- if (this.workspace.context(selected).debugger?.connected)
901
- fail('busy', 'Stop the live debugger before handing its native project to Update.');
902
- this.workspace.startRequest(request.id, { kind: 'native-update' });
903
- try {
904
- const update = await backend.updateNative(selected, request.id), context = this.workspace.context(selected);
905
- if (update.state === 'conflict') {
906
- const result = { ...selected, state: 'conflict', receivedChanges: 0, preservedLocalChanges: count(context), conflicts: [{ engine: 'ghidra', message: update.conflict }] };
907
- this.workspace.recordRequest(request.id, 'failed', result);
908
- fail('conflict', 'Native Update requires a decision; saved private work and ancestry are preserved.', result);
909
- }
910
- const result = { ...selected, state: 'updated', engine: 'ghidra-native', sharedRevision: revision(update.revision), receivedChanges: update.receivedChanges,
911
- preservedLocalChanges: count(context), nativeMergeInvocations: update.nativeMergeInvocations, conflicts: [] };
912
- this.workspace.completeSavedRequest(selected, request.id, context.generation, {}, result);
913
- return result;
914
- }
915
- catch (error) {
916
- if (!['applied', 'failed'].includes(this.workspace.request(request.id).state)) {
917
- this.workspace.recordRequest(request.id, notSent(error) ? 'failed' : 'unknown', notSent(error) ? { ...selected, state: 'not_updated', receivedChanges: 0, reason: 'not_sent', engine: 'ghidra-native', ...memoryOf(error) } : { ...selected, state: 'unknown', engine: 'ghidra-native' });
918
- if (!notSent(error))
919
- throw unknownOutcome(this.workspace, selected, error);
920
- }
921
- throw error;
922
- }
923
- })));
293
+ return this.using(selected, async (_backend, worker) => {
294
+ const changed = object(await worker.request('POST', field === 'function.name' ? '/rename_function' : '/set_comment', field === 'function.name' ? { old_name: at, new_name: value, strict_mode: 'off' } : { address: at, type: field.slice(8), comment: value ?? '' }));
295
+ if (changed.status !== 'success' && changed.success !== true)
296
+ fail('partial', 'Editing operation was not acknowledged' + (typeof changed.error === 'string' ? ': ' + changed.error.slice(0, 500) : '.'));
297
+ return { ...selected, address: publicAddress(at), field, value, state: 'applied', sharedState: 'pending' };
298
+ });
924
299
  }
925
- async mutate(selected, operation, parameters, verify, callerId, verifySaved) {
926
- const reserved = this.workspace.reserveRequest(selected, operation, parameters, callerId);
927
- return this.ordered(selected, async () => {
928
- const request = this.workspace.request(reserved.request.id);
929
- if (reserved.replay && request.state !== 'accepted') {
930
- if (request.state === 'applied')
931
- return request.result;
932
- if (operation === '/run_script_inline' && request.state === 'failed' && object(request.result ?? {}).reason === 'script_not_executed') {
933
- const result = object(request.result), execution = object(result.execution);
934
- fail('script.' + String(execution.stage), String(object(result.diagnostic).message), result);
935
- }
936
- if (operation.startsWith('/sdk/') && request.state === 'failed' && object(request.result ?? {}).state === 'rejected')
937
- fail('rejected', 'This SDK transaction was rolled back and is not repeated.', request.result);
938
- fail('unknown', 'This saved-state operation retains an unresolved outcome; it is not re-executed.', request.result);
939
- }
940
- const backend = await this.backend();
941
- await backend.open(selected);
942
- if (operation === '/batch_apply_documentation' && parameters.goto === true)
943
- await backend.mode(selected, 'gui');
944
- const context = this.workspace.context(selected);
945
- this.workspace.startRequest(request.id, { kind: 'program', operation, generation: context.generation, workingSnapshot: context.workingSnapshot,
946
- savedVerification: !!verifySaved });
947
- let savedSnapshot, phase = 'operation';
948
- try {
949
- let raw;
950
- if (operation === '/run_script_inline' && backend.inlineScript) {
951
- const attempt = await backend.inlineScript(selected, parameters, request.id);
952
- raw = attempt.response;
953
- if (attempt.response.success === false) {
954
- const result = { ...selected, requestId: request.callerId ?? request.id, state: attempt.safe ? 'rejected' : 'unknown',
955
- contextState: attempt.safe ? 'ready' : 'needs_recovery', reason: attempt.safe ? 'script_not_executed' : 'script_execution_not_proven_complete',
956
- execution: attempt.response.execution, diagnostic: attempt.response.diagnostic, diagnostics: attempt.response.diagnostics,
957
- diagnosticsTruncated: attempt.response.diagnosticsTruncated, compilerOutput: attempt.response.compilerOutput,
958
- output: attempt.response.console_output, outputTruncated: attempt.response.outputTruncated };
959
- if (attempt.safe)
960
- this.workspace.recordRequest(request.id, 'failed', result);
961
- fail('script.' + String(object(attempt.response.execution).stage), String(object(attempt.response.diagnostic).message), result);
962
- }
963
- }
964
- else
965
- raw = await backend.call(selected, operation, parameters);
966
- const response = raw && typeof raw === 'object' && !Array.isArray(raw) ? object(raw) : { output: raw };
967
- if (['rejected', 'partial', 'failed', 'error'].includes(String(response.status)) || response.success === false)
968
- fail('partial', 'Program operation reported a rejected or incomplete effect.');
969
- if (!verifySaved && response.success !== true && response.status !== 'success')
970
- fail('partial', 'Program operation did not acknowledge its effect.');
971
- let value = await verify(backend, response);
972
- phase = 'save';
973
- const snapshot = await backend.saved(selected);
974
- savedSnapshot = snapshot;
975
- phase = 'verification';
976
- if (verifySaved)
977
- value = await verifySaved(backend, snapshot, response);
978
- const scalars = await this.savedScalars(context, backend, snapshot), complexChanges = [...context.complexChanges, request.id], result = { ...selected, state: 'applied', sharedState: 'pending',
979
- pendingChanges: scalars.length + complexChanges.length, value };
980
- this.workspace.completeSavedRequest(selected, request.id, context.generation, { workingSnapshot: snapshot, complexChanges, scalars }, result);
981
- return result;
982
- }
983
- catch (error) {
984
- if (operation === '/run_script_inline' && this.workspace.request(request.id).state === 'failed' && object(this.workspace.request(request.id).result ?? {}).reason === 'script_not_executed')
985
- throw error;
986
- if (operation.startsWith('/sdk/') && String(error.code).endsWith('.rejected')) {
987
- this.workspace.recordRequest(request.id, 'failed', { ...selected, state: 'rejected', reason: 'native_transaction_rolled_back' });
988
- throw error;
989
- }
990
- // Retain supported structural candidates after a lost operation reply. Never
991
- // dispatch another save after a save deadline or an arbitrary script failure.
992
- if (phase === 'operation' && verifySaved && !['/run_script_inline', '/run_ghidra_script'].includes(operation)) {
993
- try {
994
- savedSnapshot = await backend.saved(selected);
995
- }
996
- catch { /* Native evidence stays retained. */ }
997
- }
998
- const detail = error instanceof CliError ? { code: error.code, ...(error.result ? { result: error.result } : {}) } : {};
999
- this.workspace.recordRequest(request.id, 'unknown', { ...selected, state: 'unknown', phase, ...detail, ...(savedSnapshot ? { savedSnapshot } : {}) });
1000
- throw error;
1001
- }
300
+ /** Runs one program change on the worker and checks its acknowledgement. */
301
+ async mutate(selected, operation, parameters) {
302
+ return this.using(selected, async (_backend, worker) => {
303
+ const raw = await this.route(selected, worker, 'POST', operation, parameters);
304
+ const response = raw && typeof raw === 'object' && !Array.isArray(raw) ? object(raw) : { output: raw };
305
+ if (['rejected', 'partial', 'failed', 'error'].includes(String(response.status)) || response.success === false)
306
+ fail(operation.startsWith('/sdk/') ? 'rejected' : 'partial', 'Program operation reported a rejected or incomplete effect.', { ...selected, response });
307
+ return { ...selected, state: 'applied', sharedState: 'pending', value: response };
1002
308
  });
1003
309
  }
1004
310
  }