@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,75 +1,30 @@
1
1
  import { DatabaseSync } from 'node:sqlite';
2
- import { auditEvent, bindAudit, auditHash } from './activity-audit.js';
3
- import { chmodSync, mkdirSync, readFileSync, realpathSync } from 'node:fs';
2
+ import { chmodSync, mkdirSync, realpathSync } from 'node:fs';
4
3
  import { basename, join } from 'node:path';
5
4
  import { randomUUID } from 'node:crypto';
6
5
  import { Artifacts } from './artifacts.js';
7
- import { digest, fail, id, stable, text, version, object } from './model.js';
6
+ import { digest, fail, id, stable, text } from './model.js';
8
7
  const now = () => new Date().toISOString();
9
- function loadSettings(value) {
10
- if (typeof value.autoAnalyze !== 'boolean' || Object.keys(value).some(key => !['autoAnalyze', 'language', 'compilerSpec', 'imageBase', 'loader', 'loaderOptions'].includes(key)))
11
- fail('invalid', 'Ghidra load settings are malformed.');
12
- const result = { autoAnalyze: value.autoAnalyze };
13
- if (value.language !== undefined)
14
- result.language = text(value.language, 128);
15
- if (value.compilerSpec !== undefined)
16
- result.compilerSpec = text(value.compilerSpec, 128);
17
- if (value.loader !== undefined)
18
- result.loader = text(value.loader, 512);
19
- if (value.loaderOptions !== undefined) {
20
- if (!value.loader || !value.loaderOptions || Array.isArray(value.loaderOptions) || typeof value.loaderOptions !== 'object' || Object.keys(value.loaderOptions).length > 64)
21
- fail('invalid', 'Loader options require an explicit loader and at most 64 named primitive values.');
22
- const options = {};
23
- for (const [key, item] of Object.entries(value.loaderOptions)) {
24
- text(key, 512);
25
- if (!['string', 'number', 'boolean'].includes(typeof item) || typeof item === 'number' && !Number.isSafeInteger(item))
26
- fail('invalid', 'Loader options require exact primitive values.');
27
- if (typeof item === 'string' && (item.length > 4096 || /[\u0000-\u0008\u000b\u000c\u000e-\u001f]/.test(item)))
28
- fail('invalid', 'Loader option text exceeds its bound.');
29
- options[key] = item;
30
- }
31
- result.loaderOptions = options;
32
- }
33
- if (value.imageBase !== undefined) {
34
- const address = text(value.imageBase, 128).toLowerCase().replace(/^0x/, '');
35
- if (!/^[a-f0-9]+$/.test(address))
36
- fail('invalid', 'Image base must be hexadecimal.');
37
- result.imageBase = address.replace(/^0+(?=.)/, '');
38
- }
39
- return result;
40
- }
41
8
  function bounded(value) {
42
9
  const result = stable(value);
43
10
  if (typeof result !== 'string' || Buffer.byteLength(result) > 1024 * 1024)
44
- fail('limit', 'Durable request or context exceeds 1 MiB.');
11
+ fail('limit', 'Durable request exceeds 1 MiB.');
45
12
  return result;
46
13
  }
47
14
  function page(limit, offset) {
48
15
  if (!Number.isSafeInteger(limit) || limit < 1 || limit > 100 || !Number.isSafeInteger(offset) || offset < 0)
49
16
  fail('invalid', 'Pagination requires a limit of 1–100 and a nonnegative offset.');
50
17
  }
51
- /** Profile root state, deliberately separate from the earlier coordinator.sqlite journals. */
52
- export const missingDiscardOperation = 'ghidra.changes.discard-missing';
53
- export const legacyDiscardOperation = 'ghidra.changes.discard-legacy';
18
+ /**
19
+ * The local tool workspace: immutable inputs (targets) and idempotent administration requests of the non-Ghidra
20
+ * tools. Tables of the earlier journal-era Ghidra facade may remain in older files; they are no longer read.
21
+ */
54
22
  export class Workspace {
55
23
  profile;
56
24
  directory;
57
25
  artifacts;
58
26
  db;
59
27
  namespace;
60
- auditPending;
61
- auditRequest(request) {
62
- const data = { request: request.id, state: request.state, ...(request.callerId ? { callerHash: auditHash(request.callerId) } : {}), ...(request.context ? { context: request.context } : {}), ...(['unknown', 'failed'].includes(request.state) ? { outcome: 'failure' } : request.state === 'applied' ? { outcome: 'success' } : {}) };
63
- const emit = () => { bindAudit(data); if (request.context)
64
- try {
65
- bindAudit(this.contextById(request.context));
66
- }
67
- catch { } auditEvent('request.state', data); };
68
- if (this.auditPending)
69
- this.auditPending.push(emit);
70
- else
71
- emit();
72
- }
73
28
  constructor(directory, profile) {
74
29
  this.profile = profile;
75
30
  text(profile);
@@ -80,36 +35,15 @@ export class Workspace {
80
35
  this.db = new DatabaseSync(path);
81
36
  chmodSync(path, 0o600);
82
37
  try {
83
- if (this.db.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name='metadata'").get()) {
84
- const binding = this.db.prepare('SELECT value FROM metadata WHERE key=?').get('profile');
85
- if (binding && binding.value !== profile)
86
- fail('binding', 'Workspace belongs to a different profile; restore its original profile.');
87
- }
88
- if (Number(this.db.prepare('PRAGMA user_version').get()?.user_version) > 5)
89
- fail('binding', 'Workspace schema is newer than this build; preserve it and use the matching build.');
90
38
  this.db.exec(`PRAGMA busy_timeout=5000; PRAGMA journal_mode=WAL; PRAGMA synchronous=FULL; PRAGMA foreign_keys=ON;
91
39
  CREATE TABLE IF NOT EXISTS metadata(key TEXT PRIMARY KEY, value TEXT NOT NULL);
92
40
  CREATE TABLE IF NOT EXISTS artifacts(id TEXT PRIMARY KEY, data TEXT NOT NULL);
93
41
  CREATE TABLE IF NOT EXISTS targets(id TEXT PRIMARY KEY, sha TEXT NOT NULL UNIQUE, data TEXT NOT NULL);
94
42
  CREATE TABLE IF NOT EXISTS sessions(id TEXT PRIMARY KEY, data TEXT NOT NULL);
95
- CREATE TABLE IF NOT EXISTS ghidra_models(target TEXT PRIMARY KEY REFERENCES targets(id), data TEXT NOT NULL);
96
- CREATE TABLE IF NOT EXISTS contexts(id TEXT PRIMARY KEY, session TEXT NOT NULL REFERENCES sessions(id),
97
- target TEXT NOT NULL REFERENCES ghidra_models(target), generation INTEGER NOT NULL, data TEXT NOT NULL,
98
- UNIQUE(session,target));
99
- CREATE TABLE IF NOT EXISTS requests(id TEXT PRIMARY KEY, caller_id TEXT UNIQUE, hash TEXT NOT NULL,
100
- context TEXT NOT NULL REFERENCES contexts(id), state TEXT NOT NULL, data TEXT NOT NULL);
101
- CREATE TABLE IF NOT EXISTS publications(id TEXT PRIMARY KEY, target TEXT NOT NULL REFERENCES ghidra_models(target), state TEXT NOT NULL, data TEXT NOT NULL);
102
43
  CREATE TABLE IF NOT EXISTS administration_requests(id TEXT PRIMARY KEY,caller_id TEXT UNIQUE,hash TEXT NOT NULL,state TEXT NOT NULL,data TEXT NOT NULL);
103
- CREATE UNIQUE INDEX IF NOT EXISTS active_publication ON publications(target) WHERE state IN ('preparing','commit_intent','unknown');
104
44
  PRAGMA user_version=5;`);
105
45
  this.transaction(() => {
106
- const binding = this.db.prepare('SELECT value FROM metadata WHERE key=?').get('profile');
107
- if (binding && binding.value !== profile)
108
- fail('binding', 'Workspace belongs to a different profile; restore its original profile.');
109
- if (!binding) {
110
- this.db.prepare('INSERT INTO metadata VALUES(?,?)').run('profile', profile);
111
- this.db.prepare('INSERT INTO metadata VALUES(?,?)').run('namespace', randomUUID());
112
- }
46
+ this.db.prepare('INSERT OR IGNORE INTO metadata VALUES(?,?)').run('namespace', randomUUID());
113
47
  this.namespace = String(this.db.prepare('SELECT value FROM metadata WHERE key=?').get('namespace').value);
114
48
  });
115
49
  }
@@ -121,45 +55,21 @@ export class Workspace {
121
55
  close() { this.db.close(); }
122
56
  transaction(action) {
123
57
  this.db.exec('BEGIN IMMEDIATE');
124
- const previous = this.auditPending, events = [];
125
- this.auditPending = events;
126
58
  try {
127
59
  const result = action();
128
60
  this.db.exec('COMMIT');
129
- this.auditPending = previous;
130
- for (const emit of events)
131
- emit();
132
61
  return result;
133
62
  }
134
63
  catch (error) {
135
- this.auditPending = previous;
136
64
  this.db.exec('ROLLBACK');
137
65
  throw error;
138
66
  }
139
67
  }
140
- rememberArtifact(artifact) {
141
- this.artifacts.path(artifact);
142
- const row = this.db.prepare('SELECT data FROM artifacts WHERE id=?').get(artifact.id);
143
- if (row && row.data !== stable(artifact))
144
- fail('artifact', 'Artifact identity has inconsistent metadata.');
145
- this.db.prepare('INSERT OR IGNORE INTO artifacts VALUES(?,?)').run(artifact.id, stable(artifact));
146
- }
147
- knownSnapshot(artifact) {
148
- this.artifacts.path(artifact);
149
- if (!['snapshot', 'native'].includes(artifact.kind) || this.db.prepare('SELECT data FROM artifacts WHERE id=?').get(artifact.id)?.data !== stable(artifact))
150
- fail('artifact', 'Context requires a captured immutable snapshot.');
151
- }
152
- async captureSnapshot(path) {
153
- const artifact = await this.artifacts.capture(path, 'snapshot');
154
- this.rememberArtifact(artifact);
155
- return artifact;
156
- }
157
- async captureNative(path) { const artifact = await this.artifacts.capture(path, 'native'); this.rememberArtifact(artifact); return artifact; }
158
68
  async importTarget(path) {
159
69
  const name = text(basename(path), 512);
160
70
  const input = await this.artifacts.capture(path, 'input');
161
71
  return this.transaction(() => {
162
- this.rememberArtifact(input);
72
+ this.db.prepare('INSERT OR IGNORE INTO artifacts VALUES(?,?)').run(input.id, stable(input));
163
73
  const row = this.db.prepare('SELECT id FROM targets WHERE sha=?').get(input.sha256);
164
74
  if (row)
165
75
  return this.target(String(row.id));
@@ -187,299 +97,28 @@ export class Workspace {
187
97
  fail('notFound', 'Session was not found in the selected profile.');
188
98
  return JSON.parse(String(row.data));
189
99
  }
190
- sessions(limit = 100, offset = 0) {
191
- page(limit, offset);
192
- return this.db.prepare('SELECT data FROM sessions ORDER BY rowid LIMIT ? OFFSET ?').all(limit, offset).map(row => JSON.parse(String(row.data)));
193
- }
194
- model(target) {
195
- this.target(target);
196
- const row = this.db.prepare('SELECT data FROM ghidra_models WHERE target=?').get(target);
197
- if (!row)
198
- fail('notFound', 'Target has no Ghidra model.');
199
- return JSON.parse(String(row.data));
200
- }
201
- context(scope) {
202
- this.session(scope.session);
203
- this.target(scope.target);
204
- const row = this.db.prepare('SELECT data FROM contexts WHERE session=? AND target=?').get(scope.session, scope.target);
205
- if (!row)
206
- fail('notFound', 'No Ghidra context exists for this session and target; open it first.');
207
- return JSON.parse(String(row.data));
208
- }
209
- contextById(context) {
210
- const row = this.db.prepare('SELECT data FROM contexts WHERE id=?').get(id(context));
211
- if (!row)
212
- fail('notFound', 'Tool context was not found.');
213
- return JSON.parse(String(row.data));
214
- }
215
- contexts(session, limit = 100, offset = 0) {
216
- this.session(session);
217
- page(limit, offset);
218
- return this.db.prepare('SELECT data FROM contexts WHERE session=? ORDER BY rowid LIMIT ? OFFSET ?').all(session, limit, offset).map(row => JSON.parse(String(row.data)));
219
- }
220
- existingRequest(callerId, intentHash) {
221
- if (callerId === undefined)
222
- return;
223
- // A previous build may have reserved a blocked retry under this generated ID.
224
- // The recorded identity still selects its original intent, not that newer caller ID.
225
- const recorded = this.db.prepare('SELECT id,hash FROM requests WHERE id=?').get(id(callerId));
226
- if (!recorded && this.db.prepare('SELECT id FROM administration_requests WHERE caller_id=?').get(id(callerId)))
227
- fail('idempotency', 'Request ID already identifies a profile administration operation.');
228
- const row = recorded ?? this.db.prepare('SELECT id,hash FROM requests WHERE caller_id=?').get(id(callerId));
229
- if (!row)
230
- return;
231
- if (row.hash !== intentHash)
232
- fail('idempotency', 'Request ID was already used with different effective input.');
233
- return this.request(String(row.id));
234
- }
235
- insertRequest(context, operation, intent, callerId, hash) {
236
- const request = { id: 'q_' + randomUUID(), operation: text(operation, 128), intent,
237
- context, state: 'accepted', ...(callerId === undefined ? {} : { callerId: id(callerId) }), createdAt: now(), updatedAt: now() };
238
- this.db.prepare('INSERT INTO requests VALUES(?,?,?,?,?,?)').run(request.id, callerId ?? null, hash, context, request.state, bounded(request));
239
- this.auditRequest(request);
240
- return request;
241
- }
242
- reserveOpen(target, session, settings, callerId, mode) {
243
- this.target(target);
244
- const normalized = loadSettings(settings);
245
- if (session !== 'new')
246
- this.session(session);
247
- if (mode !== undefined && !['headless', 'gui'].includes(mode))
248
- fail('invalid', 'Requested tool mode is invalid.');
249
- const intent = { operation: 'ghidra.open', target, session, settings: normalized, ...(mode ? { mode } : {}) };
250
- const hash = digest(intent);
251
- return this.transaction(() => {
252
- const previous = this.existingRequest(callerId, hash);
253
- if (previous) {
254
- const row = this.db.prepare('SELECT data FROM contexts WHERE id=?').get(previous.context);
255
- return { context: JSON.parse(String(row.data)), request: previous, replay: true };
256
- }
257
- const row = this.db.prepare('SELECT data FROM ghidra_models WHERE target=?').get(target);
258
- if (row) {
259
- if (stable(JSON.parse(String(row.data)).settings) !== stable(normalized))
260
- fail('binding', 'Target already uses different Ghidra load settings.');
261
- }
262
- else {
263
- const model = { target, settings: normalized, state: 'opening' };
264
- this.db.prepare('INSERT INTO ghidra_models VALUES(?,?)').run(target, stable(model));
265
- }
266
- if (session === 'new') {
267
- const selected = { id: 's_' + randomUUID(), createdAt: now() };
268
- this.db.prepare('INSERT INTO sessions VALUES(?,?)').run(selected.id, stable(selected));
269
- session = selected.id;
270
- }
271
- const existing = this.db.prepare('SELECT data FROM contexts WHERE session=? AND target=?').get(session, target);
272
- const context = existing ? JSON.parse(String(existing.data)) : {
273
- id: 'c_' + randomUUID(), session, target, tool: 'ghidra', state: 'opening', generation: 0, scalars: [], complexChanges: [],
274
- };
275
- if (!existing)
276
- this.db.prepare('INSERT INTO contexts VALUES(?,?,?,?,?)').run(context.id, session, target, 0, stable(context));
277
- return { context, request: this.insertRequest(context.id, 'ghidra.open', intent, callerId, hash), replay: false };
278
- });
279
- }
280
- reserveRequest(scope, operation, parameters, callerId) {
281
- const context = this.context(scope);
282
- const intent = { operation: text(operation, 128), session: scope.session, target: scope.target, parameters };
283
- bounded(intent);
284
- const hash = digest(intent);
285
- return this.transaction(() => {
286
- const previous = this.existingRequest(callerId, hash);
287
- return previous ? { request: previous, replay: true } : { request: this.insertRequest(context.id, operation, intent, callerId, hash), replay: false };
288
- });
289
- }
290
- scopedRequest(scope, identity) {
291
- const row = this.db.prepare('SELECT data FROM requests WHERE context=? AND (id=? OR caller_id=?)').get(this.context(scope).id, id(identity), id(identity));
292
- return row ? JSON.parse(String(row.data)) : undefined;
293
- }
294
- allContexts() { return this.db.prepare('SELECT data FROM contexts ORDER BY rowid').all().map(row => JSON.parse(String(row.data))); }
295
- allArtifacts() { return this.db.prepare('SELECT data FROM artifacts ORDER BY rowid').all().map(row => JSON.parse(String(row.data))); }
296
- legacyDiscarded(context) {
297
- return this.db.prepare("SELECT data FROM requests WHERE context=? AND state='applied'").all(context.id).some(row => JSON.parse(String(row.data)).operation === legacyDiscardOperation);
298
- }
299
- /** Every started or reserved intent of a context, without the display bound of unresolved(). */
300
- unfinished(scope) {
301
- return this.db.prepare("SELECT data FROM requests WHERE context=? AND state IN ('accepted','running','unknown') ORDER BY rowid").all(this.context(scope).id).map(row => JSON.parse(String(row.data)));
302
- }
303
- /**
304
- * Explicitly gives up one detached context. Every intent it had so far becomes terminal, so none can run later on
305
- * a native checkout, and exactly those non-applied rows stop owning evidence. Their own outcomes stay readable.
306
- */
307
- discardLegacy(scope, request, generation, result) {
308
- return this.giveUp(scope, request, generation, result, legacyDiscardOperation);
309
- }
310
- /** The same for a native checkout whose project is gone and whose server checkout was ended. */
311
- discardMissing(scope, request, generation, result) {
312
- return this.giveUp(scope, request, generation, result, missingDiscardOperation);
313
- }
314
- giveUp(scope, request, generation, result, operation) {
315
- return this.transaction(() => {
316
- const context = this.context(scope), intent = this.request(request), model = this.model(scope.target);
317
- const checkout = context.nativeCheckout, missing = operation === missingDiscardOperation;
318
- if (context.generation !== generation || missing !== Boolean(checkout) || checkout?.state === 'dropped' || this.activePublication(scope.target) || context.debugger?.connected || model.state !== 'ready' ||
319
- intent.context !== context.id || intent.operation !== operation || intent.state !== 'running')
320
- fail('blocked', 'Only an unchanged, stopped context can be discarded.');
321
- for (const pending of this.unfinished(scope))
322
- if (pending.id !== request)
323
- this.writeRequest(pending.id, 'failed', { ...scope, state: 'discarded', reason: missing ? 'explicit_missing_discard' : 'explicit_legacy_discard' });
324
- for (const row of this.db.prepare("SELECT id,data FROM requests WHERE context=? AND state='failed'").all(context.id))
325
- this.db.prepare('UPDATE requests SET data=? WHERE id=?').run(bounded({ ...JSON.parse(String(row.data)), dropped: true }), String(row.id));
326
- this.writeContext(scope, generation, { state: 'stopped', workingSnapshot: undefined, baseSnapshot: undefined, baseRevision: undefined,
327
- // Saved traces of a native context live outside its project.
328
- ...(missing ? {} : { debugger: undefined }),
329
- scalars: [], complexChanges: [], viewEpoch: (context.viewEpoch ?? 0) + 1,
330
- ...(checkout ? { nativeCheckout: (({ conflict, ...rest }) => ({ ...rest, state: 'dropped' }))(checkout) } : {}) });
331
- return this.writeRequest(request, 'applied', result).result;
332
- });
333
- }
334
- /** An abandoned or otherwise unknown terminal effect keeps all of its native evidence. */
335
- uncertainOutcome(scope) {
336
- return this.db.prepare("SELECT data FROM requests WHERE context=? AND state='failed'").all(this.context(scope).id).map(row => JSON.parse(String(row.data)))
337
- .some(row => !row.dropped && row.result?.outcome === 'unknown');
338
- }
339
- /**
340
- * Whether the working copy holds no private work, as Ghidra itself reported it when the copy was last saved or
341
- * observed (`modifiedSinceCheckout`). Native state is observed again before any release.
342
- */
343
- unchangedNative(context) {
344
- if (context.nativeCheckout?.state === 'verified')
345
- return true;
346
- if (context.workingSnapshot?.kind !== 'native')
347
- return false;
348
- try {
349
- const local = JSON.parse(readFileSync(this.artifacts.path(context.workingSnapshot), 'utf8'));
350
- return local.source === 'checkout' && local.modified === false;
351
- }
352
- catch {
353
- return false;
354
- }
355
- }
356
- /** Another context's unresolved operation may still need this checkout's private view. */
357
- checkoutReferenced(context, root = context.nativeCheckout?.root) {
358
- const seen = new Set();
359
- if (!root)
360
- return false;
361
- for (const row of this.db.prepare("SELECT data FROM requests WHERE context<>? AND state IN ('running','unknown','failed')").all(context.id)) {
362
- const request = JSON.parse(String(row.data));
363
- if (request.dropped || request.state === 'failed' && request.result?.outcome !== 'unknown')
364
- continue;
365
- for (const match of String(row.data).matchAll(/native:([a-f0-9]{64})/g))
366
- seen.add(match[1]);
367
- }
368
- for (const sha of seen)
369
- try {
370
- const value = JSON.parse(readFileSync(join(this.directory, 'artifacts', sha + '.json'), 'utf8'));
371
- if (value.source === 'checkout') {
372
- const referenced = value.checkout?.root;
373
- if (typeof referenced !== 'string' || referenced === root || realpathSync(referenced) === realpathSync(root))
374
- return true;
375
- }
376
- }
377
- catch {
378
- return true;
379
- }
380
- return false;
381
- }
382
- /** Applied requests keep their results; their superseded before-images are not recovery inputs. */
383
- artifactRoots() {
384
- const roots = new Set(), scan = (value) => { for (const match of value.matchAll(/(?:input|snapshot|native):[a-f0-9]{64}/g))
385
- roots.add(match[0]); };
386
- for (const table of ['targets', 'sessions', 'ghidra_models', 'contexts', 'administration_requests'])
387
- for (const row of this.db.prepare('SELECT data FROM ' + table).all())
388
- scan(String(row.data));
389
- for (const row of this.db.prepare("SELECT data FROM publications WHERE state<>'verified'").all())
390
- scan(String(row.data));
391
- for (const row of this.db.prepare('SELECT state,data FROM requests').all()) {
392
- const request = JSON.parse(String(row.data));
393
- if (!request.dropped)
394
- scan(row.state === 'applied' ? stable(request.result ?? null) : String(row.data));
395
- }
396
- return roots;
397
- }
398
- forgetArtifact(artifact) { this.db.prepare('DELETE FROM artifacts WHERE id=?').run(artifact); }
399
- /** A detached context proved equal to a server version continues from a lazy native checkout. */
400
- resetMigratedContext(scope) {
401
- const context = this.context(scope);
402
- if (context.nativeCheckout || context.scalars.length || context.complexChanges.length || context.debugger?.traces.length || context.debugger?.connected || this.unresolved(scope).length || this.uncertainOutcome(scope))
403
- fail('blocked', 'Only an unchanged detached context can be reset by migration.');
404
- this.writeContext(scope, context.generation, { state: 'stopped', workingSnapshot: undefined, baseSnapshot: undefined, baseRevision: undefined, viewEpoch: (context.viewEpoch ?? 0) + 1 });
405
- }
406
- recoverMigrationOpen(scope) {
407
- return this.transaction(() => {
408
- const context = this.context(scope), unresolved = this.unresolved(scope);
409
- if (context.nativeCheckout || context.workingSnapshot || context.scalars.length || context.complexChanges.length || context.debugger?.traces.length || unresolved.some(q => q.operation !== 'ghidra.open'))
410
- fail('blocked', 'Only a proven no-work open can be recovered by migration.');
411
- for (const request of unresolved)
412
- this.writeRequest(request.id, 'failed', { ...scope, state: 'not_opened', reason: 'explicit_native_migration_completed', previousResult: request.result ?? null });
413
- if (unresolved.length)
414
- this.writeContext(scope, context.generation, { state: 'stopped' });
415
- return unresolved.length;
416
- });
417
- }
418
- request(request) {
419
- const row = this.db.prepare('SELECT data FROM requests WHERE id=?').get(id(request));
420
- if (!row)
421
- fail('notFound', 'Request was not found in the selected profile.');
422
- return JSON.parse(String(row.data));
423
- }
424
100
  reserveAdministration(operation, parameters, callerId) {
425
101
  const intent = { operation: text(operation, 128), parameters }, hash = digest(intent);
426
102
  bounded(intent);
427
103
  return this.transaction(() => {
428
104
  if (callerId !== undefined) {
429
105
  id(callerId);
430
- if (this.db.prepare('SELECT id FROM requests WHERE caller_id=?').get(callerId))
431
- fail('idempotency', 'Request ID already identifies scoped research.');
432
- const row = this.db.prepare('SELECT id,hash FROM administration_requests WHERE caller_id=?').get(callerId);
433
- if (row) {
434
- if (row.hash !== hash)
435
- fail('idempotency', 'Request ID was already used with different effective input.');
106
+ const row = this.db.prepare('SELECT id FROM administration_requests WHERE caller_id=?').get(callerId);
107
+ if (row)
436
108
  return { request: this.administration(String(row.id)), replay: true };
437
- }
438
109
  }
439
110
  const request = { id: 'a_' + randomUUID(), operation, intent, state: 'accepted', ...(callerId ? { callerId } : {}), createdAt: now(), updatedAt: now() };
440
111
  this.db.prepare('INSERT INTO administration_requests VALUES(?,?,?,?,?)').run(request.id, callerId ?? null, hash, request.state, bounded(request));
441
- this.auditRequest(request);
442
112
  return { request, replay: false };
443
113
  });
444
114
  }
445
115
  administrationByCaller(callerId) { const row = this.db.prepare('SELECT id FROM administration_requests WHERE caller_id=?').get(id(callerId)); return row ? this.administration(String(row.id)) : undefined; }
446
- /** Synchronous metadata snapshot; consumers must not perform remote work in this callback. */
447
- withAdministrationSnapshot(prefix, read) {
448
- if (!/^[a-z]+\.$/.test(prefix))
449
- fail('invalid', 'A literal administration namespace is required.');
450
- return this.transaction(() => {
451
- const rows = this.db.prepare("SELECT data FROM administration_requests WHERE json_extract(data,'$.operation') LIKE ? ORDER BY id").iterate(prefix + '%');
452
- function* records() { for (const row of rows)
453
- yield JSON.parse(String(row.data)); }
454
- return read(records());
455
- });
456
- }
457
- requestByCaller(callerId) { const row = this.db.prepare('SELECT id FROM requests WHERE caller_id=?').get(id(callerId)); return row ? this.request(String(row.id)) : undefined; }
458
116
  administration(request) {
459
117
  const row = this.db.prepare('SELECT data FROM administration_requests WHERE id=?').get(id(request));
460
118
  if (!row)
461
119
  fail('notFound', 'Administration request was not found in this profile.');
462
120
  return JSON.parse(String(row.data));
463
121
  }
464
- unresolvedAdministration() {
465
- return this.db.prepare("SELECT data FROM administration_requests WHERE state IN ('running','unknown') ORDER BY rowid LIMIT 100")
466
- .all().map(row => JSON.parse(String(row.data)));
467
- }
468
- unresolvedSessionAdministration(session, target) {
469
- this.session(session);
470
- if (target)
471
- this.target(target);
472
- return this.db.prepare("SELECT data FROM administration_requests WHERE state IN ('running','unknown') AND json_extract(data,'$.intent.parameters.session')=? AND (? IS NULL OR json_extract(data,'$.intent.parameters.target') IS NULL OR json_extract(data,'$.intent.parameters.target')=?) ORDER BY rowid LIMIT 100")
473
- .all(session, target ?? null, target ?? null).map(row => JSON.parse(String(row.data)));
474
- }
475
- unresolvedServer() {
476
- return this.db.prepare("SELECT data FROM administration_requests WHERE state IN ('running','unknown') AND json_extract(data,'$.operation') LIKE 'server.%' ORDER BY rowid LIMIT 100")
477
- .all().map(row => JSON.parse(String(row.data)));
478
- }
479
- unresolvedProject(project) {
480
- return this.db.prepare("SELECT data FROM administration_requests WHERE state IN ('running','unknown') AND json_extract(data,'$.intent.parameters.project')=? ORDER BY rowid LIMIT 100")
481
- .all(project).map(row => JSON.parse(String(row.data)));
482
- }
483
122
  administrationState(request, state, result) {
484
123
  return this.transaction(() => {
485
124
  const previous = this.administration(request);
@@ -492,334 +131,7 @@ export class Workspace {
492
131
  fail('blocked', 'Administration operation already started; do not replay it.');
493
132
  const next = { ...previous, state, ...(result === undefined ? {} : { result }), updatedAt: now() };
494
133
  this.db.prepare('UPDATE administration_requests SET state=?,data=? WHERE id=?').run(state, bounded(next), request);
495
- this.auditRequest(next);
496
- return next;
497
- });
498
- }
499
- unresolved(scope) {
500
- const context = this.context(scope);
501
- return this.db.prepare("SELECT data FROM requests WHERE context=? AND state IN ('running','unknown') ORDER BY rowid LIMIT 100")
502
- .all(context.id).map(row => JSON.parse(String(row.data)));
503
- }
504
- startRequest(request, execution) {
505
- return this.transaction(() => {
506
- const previous = this.request(request);
507
- if (previous.state !== 'accepted')
508
- fail('blocked', 'Request already started; reconcile its recorded outcome before continuing.');
509
- const next = { ...previous, state: 'running', ...(execution === undefined ? {} : { execution }), updatedAt: now() };
510
- this.db.prepare('UPDATE requests SET state=?,data=? WHERE id=?').run(next.state, bounded(next), next.id);
511
- this.auditRequest(next);
512
- return next;
513
- });
514
- }
515
- recordRequest(request, state, result) {
516
- return this.transaction(() => this.writeRequest(request, state, result));
517
- }
518
- writeRequest(request, state, result) {
519
- const previous = this.request(request);
520
- if (previous.state === 'applied' || previous.state === 'failed') {
521
- if (state !== previous.state || stable(result) !== stable(previous.result))
522
- fail('idempotency', 'A completed request outcome is immutable.');
523
- return previous;
524
- }
525
- if (state === 'applied' && previous.state === 'accepted')
526
- fail('binding', 'Request must start before an effect can be acknowledged.');
527
- const next = { ...previous, state, result, updatedAt: now() };
528
- this.db.prepare('UPDATE requests SET state=?,data=? WHERE id=?').run(next.state, bounded(next), next.id);
529
- this.auditRequest(next);
530
- return next;
531
- }
532
- establishModel(target, revision, snapshot) {
533
- version(revision);
534
- this.knownSnapshot(snapshot);
535
- return this.transaction(() => {
536
- const model = this.model(target);
537
- if (model.state === 'ready')
538
- fail('binding', 'Ghidra model was already initialized; publication must verify its shared base.');
539
- const next = { ...model, state: 'ready', sharedRevision: revision, sharedSnapshot: snapshot };
540
- this.db.prepare('UPDATE ghidra_models SET data=? WHERE target=?').run(stable(next), target);
541
- return next;
542
- });
543
- }
544
- beginModelInitialization(target) {
545
- return this.transaction(() => {
546
- const model = this.model(target);
547
- if (model.state !== 'opening')
548
- fail('blocked', 'Shared model setup already started; reconcile its persisted outcome.');
549
- const next = { ...model, state: 'unknown' };
550
- this.db.prepare('UPDATE ghidra_models SET data=? WHERE target=?').run(stable(next), target);
551
- return next;
552
- });
553
- }
554
- observeShared(target, revision, snapshot) {
555
- version(revision);
556
- this.knownSnapshot(snapshot);
557
- return this.transaction(() => {
558
- const model = this.model(target);
559
- if (model.state !== 'ready')
560
- fail('blocked', 'Shared model outcome requires reconciliation before accepting another baseline.');
561
- if (revision < (model.sharedRevision ?? 1))
562
- fail('binding', 'Shared version history regressed.');
563
- const next = { ...model, sharedRevision: revision, sharedSnapshot: snapshot };
564
- this.db.prepare('UPDATE ghidra_models SET data=? WHERE target=?').run(stable(next), target);
565
- return next;
566
- });
567
- }
568
- publication(publication) {
569
- const row = this.db.prepare('SELECT data FROM publications WHERE id=?').get(id(publication));
570
- if (!row)
571
- fail('notFound', 'Publication was not found in this profile.');
572
- return JSON.parse(String(row.data));
573
- }
574
- activePublication(target) {
575
- this.target(target);
576
- const row = this.db.prepare("SELECT data FROM publications WHERE target=? AND state IN ('preparing','commit_intent','unknown')").get(target);
577
- return row ? JSON.parse(String(row.data)) : undefined;
578
- }
579
- beginPublication(scope, request, expectedRevision, snapshot) {
580
- version(expectedRevision);
581
- this.knownSnapshot(snapshot);
582
- return this.transaction(() => {
583
- const context = this.context(scope), intent = this.request(request), model = this.model(scope.target);
584
- if (intent.context !== context.id || intent.state !== 'running')
585
- fail('binding', 'Publication does not match its running context request.');
586
- const active = this.activePublication(scope.target);
587
- if (active || model.state !== 'ready')
588
- fail('blocked', 'Shared model has an unresolved publication; reconcile it before another merge.');
589
- const publication = { ...scope, id: request, request, state: 'preparing', expectedRevision, snapshot,
590
- generation: context.generation, scalars: context.scalars, complex: context.complexChanges.length > 0, complexChanges: context.complexChanges };
591
- this.db.prepare('INSERT INTO publications VALUES(?,?,?,?)').run(publication.id, scope.target, publication.state, bounded(publication));
592
- return publication;
593
- });
594
- }
595
- publicationIntent(publication) {
596
- return this.transaction(() => {
597
- const previous = this.publication(publication);
598
- if (previous.state !== 'preparing')
599
- fail('blocked', 'Publication intent was already issued; verify its history instead of retrying.');
600
- const next = { ...previous, state: 'commit_intent' };
601
- const model = this.model(previous.target);
602
- this.db.prepare('UPDATE ghidra_models SET data=? WHERE target=?').run(stable({ ...model, state: 'unknown' }), previous.target);
603
- this.db.prepare('UPDATE publications SET state=?,data=? WHERE id=?').run(next.state, bounded(next), next.id);
604
- return next;
605
- });
606
- }
607
- unknownPublication(publication, detail) {
608
- return this.transaction(() => {
609
- const previous = this.publication(publication);
610
- if (!['commit_intent', 'unknown'].includes(previous.state))
611
- fail('binding', 'Uncertainty must retain an actual publication intent.');
612
- const next = { ...previous, state: 'unknown', detail };
613
- this.db.prepare('UPDATE publications SET state=?,data=? WHERE id=?').run(next.state, bounded(next), next.id);
614
- return next;
615
- });
616
- }
617
- finishPublication(publication, publishedRevision, result, sharedSnapshot) {
618
- version(publishedRevision);
619
- return this.transaction(() => {
620
- const previous = this.publication(publication);
621
- if (!['commit_intent', 'unknown'].includes(previous.state) || publishedRevision !== previous.expectedRevision + 1)
622
- fail('binding', 'Verified publication has an unexpected state or version.');
623
- const context = this.context(previous), model = this.model(previous.target);
624
- if (context.generation !== previous.generation)
625
- fail('binding', 'Private context changed during publication; preserve both saved versions.');
626
- if (sharedSnapshot)
627
- this.knownSnapshot(sharedSnapshot);
628
- const saved = sharedSnapshot ?? previous.snapshot;
629
- this.writeContext(previous, previous.generation, { state: context.nativeCheckout ? 'stopped' : 'ready', baseRevision: publishedRevision, baseSnapshot: saved,
630
- workingSnapshot: saved, viewEpoch: (context.viewEpoch ?? 0) + 1, scalars: [], complexChanges: [],
631
- ...(context.nativeCheckout ? { nativeCheckout: { ...context.nativeCheckout, state: 'verified', baseVersion: publishedRevision } } : {}) });
632
- this.db.prepare('UPDATE ghidra_models SET data=? WHERE target=?').run(stable({ ...model, state: 'ready', sharedRevision: publishedRevision, sharedSnapshot: saved }), previous.target);
633
- this.writeRequest(previous.request, 'applied', result);
634
- const next = { ...previous, state: 'verified', publishedRevision };
635
- this.db.prepare('UPDATE publications SET state=?,data=? WHERE id=?').run(next.state, bounded(next), next.id);
636
- return next;
637
- });
638
- }
639
- rejectPublication(publication, result) {
640
- return this.transaction(() => {
641
- const previous = this.publication(publication);
642
- if (!['preparing', 'commit_intent'].includes(previous.state))
643
- fail('blocked', 'An uncertain publication cannot be abandoned without proof.');
644
- const model = this.model(previous.target), next = { ...previous, state: 'conflict', detail: result };
645
- this.db.prepare('UPDATE ghidra_models SET data=? WHERE target=?').run(stable({ ...model, state: 'ready' }), previous.target);
646
- this.db.prepare('UPDATE publications SET state=?,data=? WHERE id=?').run(next.state, bounded(next), next.id);
647
- this.writeRequest(previous.request, 'failed', result);
648
- return next;
649
- });
650
- }
651
- /** Exactly proved native pre-call refusal: settle all journals together, retaining the private view. */
652
- finishRefusedPublication(publication, observedRevision, sharedSnapshot, result) {
653
- version(observedRevision);
654
- this.knownSnapshot(sharedSnapshot);
655
- return this.transaction(() => {
656
- const previous = this.publication(publication), context = this.context(previous), request = this.request(previous.request), model = this.model(previous.target);
657
- // The head equals the expected version when a check-in was sent and created no version.
658
- if (!['commit_intent', 'unknown'].includes(previous.state) || observedRevision < previous.expectedRevision ||
659
- observedRevision < (model.sharedRevision ?? 1) || context.generation !== previous.generation || context.workingSnapshot?.id !== previous.snapshot.id ||
660
- context.nativeCheckout?.state !== 'active' || request.context !== context.id || request.operation !== 'ghidra.merge' ||
661
- !['running', 'unknown'].includes(request.state))
662
- fail('binding', 'Refused native publication no longer matches its retained intent.');
663
- const next = { ...previous, state: 'conflict', detail: result };
664
- this.db.prepare('UPDATE ghidra_models SET data=? WHERE target=?').run(stable({ ...model, state: 'ready', sharedRevision: observedRevision, sharedSnapshot }), previous.target);
665
- this.db.prepare('UPDATE publications SET state=?,data=? WHERE id=?').run(next.state, bounded(next), next.id);
666
- this.writeRequest(previous.request, 'failed', result);
667
134
  return next;
668
135
  });
669
136
  }
670
- publishedSince(target, revision) {
671
- this.target(target);
672
- version(revision);
673
- return this.db.prepare("SELECT data FROM publications WHERE target=? AND state='verified' ORDER BY rowid").all(target)
674
- .map(row => JSON.parse(String(row.data))).filter(item => item.publishedRevision > revision);
675
- }
676
- saveContext(scope, expectedGeneration, patch) {
677
- return this.transaction(() => this.writeContext(scope, expectedGeneration, patch));
678
- }
679
- /** Independent release readback and its no-publication request outcome become visible together. */
680
- retainNativeDisposal(scope, generation, checkout, snapshot, request) {
681
- return this.transaction(() => {
682
- const context = this.context(scope);
683
- if (checkout.state !== 'verified' || stable(context.nativeCheckout) !== stable(checkout))
684
- fail('binding', 'Native disposal ownership changed before retention.');
685
- const active = { ...checkout, state: 'active' };
686
- this.knownSnapshot(snapshot);
687
- const saved = object(JSON.parse(readFileSync(this.artifacts.path(snapshot), 'utf8')));
688
- if (snapshot.kind !== 'native' || saved.engine !== 'native-checkout-v1' || saved.source !== 'checkout' || stable(saved.checkout) !== stable(active) ||
689
- saved.fileId !== active.fileId || saved.version !== active.baseVersion || typeof saved.fingerprint !== 'string' || !/^[a-f0-9]{64}$/.test(saved.fingerprint))
690
- fail('binding', 'Retained native receipt differs from independently observed checkout ownership.');
691
- if (request) {
692
- const pending = this.request(request);
693
- if (pending.context !== context.id || pending.operation !== 'ghidra.merge' || !['running', 'unknown'].includes(pending.state) || object(pending.execution ?? {}).kind !== 'native-merge')
694
- fail('binding', 'Retained disposal does not match an unfinished native merge request.');
695
- if (this.db.prepare('SELECT id FROM publications WHERE id=? OR json_extract(data,\'$.request\')=?').get(request, request) || this.activePublication(scope.target) || this.model(scope.target).state !== 'ready')
696
- fail('blocked', 'A publication outcome cannot be replaced by retained empty disposal.');
697
- const journal = object(JSON.parse(readFileSync(join(checkout.root, 'operations', request + '-update.json'), 'utf8'))), q = object(journal.request), updated = object(journal.result), view = object(updated.saved);
698
- const owner = JSON.parse(readFileSync(join(checkout.root, 'native-owner.json'), 'utf8'));
699
- if (q.operation !== 'update' || q.request !== request || q.root !== checkout.root || q.fileId !== checkout.fileId || q.checkoutId !== checkout.checkoutId || stable(q.owner) !== stable(owner) ||
700
- updated.state !== 'updated' || updated.checkoutId !== checkout.checkoutId || updated.baseVersion !== checkout.baseVersion || view.fileId !== checkout.fileId || view.version !== checkout.baseVersion ||
701
- typeof view.fingerprint !== 'string' || !/^[a-f0-9]{64}$/.test(view.fingerprint))
702
- fail('binding', 'Retained disposal lacks its completed owned native Update.');
703
- try {
704
- readFileSync(join(checkout.root, 'operations', request + '-checkin.json'));
705
- fail('blocked', 'A native check-in intent cannot become retained empty disposal.');
706
- }
707
- catch (error) {
708
- if (error.code !== 'ENOENT')
709
- throw error;
710
- }
711
- }
712
- else if (this.unresolved(scope).some(pending => pending.operation === 'ghidra.merge'))
713
- fail('blocked', 'Retained native disposal requires its unfinished merge request identity.');
714
- const result = { session: scope.session, target: scope.target, state: 'retained', engine: 'ghidra-native', checkout: 'retained',
715
- retention: { schema: 1, source: 'native-release-status', checkout: active, snapshot, ...(request ? { request } : {}) } };
716
- this.writeContext(scope, generation, { nativeCheckout: active, workingSnapshot: snapshot, state: 'stopped' });
717
- if (request)
718
- this.writeRequest(request, 'failed', result);
719
- return result;
720
- });
721
- }
722
- /** Terminal abandonment retains the previous outcome and saved view atomically. */
723
- abandonProgramRequest(scope, request, generation) {
724
- return this.transaction(() => {
725
- const previous = this.request(request), context = this.context(scope), execution = object(previous.execution ?? {});
726
- if (previous.context !== context.id || !['running', 'unknown'].includes(previous.state) || execution.kind !== 'program' || execution.generation !== generation ||
727
- this.unresolved(scope).length !== 1 || this.activePublication(scope.target) || !context.workingSnapshot || object(execution.workingSnapshot).id !== context.workingSnapshot.id)
728
- fail('binding', 'Uncertain attempt changed before abandonment.');
729
- const result = { ...scope, state: 'abandoned', outcome: 'unknown', requestId: previous.callerId ?? previous.id, previousResult: previous.result ?? null, retainedSnapshot: context.workingSnapshot };
730
- this.writeContext(scope, generation, { state: 'stopped', viewEpoch: (context.viewEpoch ?? 0) + 1 });
731
- this.writeRequest(request, 'failed', result);
732
- return result;
733
- });
734
- }
735
- /** Snapshot and successful request acknowledgment enter the same durable transaction. */
736
- completeSavedRequest(scope, request, expectedGeneration, patch, result) {
737
- return this.transaction(() => {
738
- const previous = this.context(scope), intent = this.request(request);
739
- if (intent.context !== previous.id)
740
- fail('binding', 'Saved operation belongs to a different working context.');
741
- if (intent.state === 'applied' || intent.state === 'failed')
742
- fail('idempotency', 'Completed request cannot change its working context.');
743
- const context = this.writeContext(scope, expectedGeneration, patch);
744
- const outcome = this.writeRequest(request, 'applied', result);
745
- return { context, request: outcome };
746
- });
747
- }
748
- writeContext(scope, expectedGeneration, patch) {
749
- if (!Number.isSafeInteger(expectedGeneration) || expectedGeneration < 0)
750
- fail('invalid', 'Invalid context generation.');
751
- if (Object.keys(patch).some(key => !['state', 'baseRevision', 'baseSnapshot', 'workingSnapshot', 'viewEpoch', 'scalars', 'complexChanges', 'debugger', 'syncPolicy', 'nativeCheckout'].includes(key)) ||
752
- patch.state !== undefined && !['opening', 'ready', 'stopped', 'needs_recovery'].includes(patch.state))
753
- fail('invalid', 'Invalid context state update.');
754
- if (patch.baseRevision !== undefined)
755
- version(patch.baseRevision);
756
- if (patch.viewEpoch !== undefined && (!Number.isSafeInteger(patch.viewEpoch) || patch.viewEpoch < 0))
757
- fail('invalid', 'View epoch must be a nonnegative integer.');
758
- if (patch.baseSnapshot)
759
- this.knownSnapshot(patch.baseSnapshot);
760
- if (patch.workingSnapshot)
761
- this.knownSnapshot(patch.workingSnapshot);
762
- if (patch.nativeCheckout) {
763
- const n = patch.nativeCheckout;
764
- if (n.schema !== 1 || !['active', 'verified', 'dropped'].includes(n.state) || !Number.isSafeInteger(n.checkoutId) || n.checkoutId < 0 || !Number.isSafeInteger(n.baseVersion) || n.baseVersion < 1 ||
765
- !/^[a-f0-9]{64}$/.test(n.runtimeFingerprint) || n.context !== this.context(scope).id || !n.root || !n.fileId || !n.origin || !n.repository || n.path !== '/' + scope.target + '.bin')
766
- fail('binding', 'Native checkout receipt is malformed.');
767
- }
768
- if (patch.syncPolicy) {
769
- const p = patch.syncPolicy;
770
- if (Object.keys(p).some(k => !['publish', 'refresh'].includes(k)) || !['manual', 'after-edit', 'after-save'].includes(p.publish) || !['manual', 'before-edit'].includes(p.refresh))
771
- fail('invalid', 'Invalid synchronization policy.');
772
- }
773
- if (patch.debugger) {
774
- const state = patch.debugger;
775
- if (typeof state.connected !== 'boolean' || !Array.isArray(state.traces) || state.traces.length > 64)
776
- fail('invalid', 'Debugger trace state is malformed.');
777
- const ids = new Set();
778
- for (const trace of state.traces) {
779
- if (!/^trace_[a-f0-9-]{36}$/.test(trace.id) || ids.has(trace.id) || !/^\d+$/.test(trace.snap) || !Number.isSafeInteger(trace.modules) || trace.modules < 0 || !Number.isSafeInteger(trace.threads) || trace.threads < 0 || typeof trace.connected !== 'boolean')
780
- fail('invalid', 'Saved trace identity or counts are malformed.');
781
- text(trace.name, 512);
782
- this.knownSnapshot(trace.snapshot);
783
- ids.add(trace.id);
784
- if (trace.thread !== undefined && !/^\d+$/.test(trace.thread))
785
- fail('invalid', 'Saved debugger thread is malformed.');
786
- }
787
- if (state.active !== undefined && !ids.has(state.active))
788
- fail('invalid', 'Active trace must belong to the selected context.');
789
- }
790
- const previous = this.context(scope);
791
- if (previous.generation !== expectedGeneration)
792
- fail('binding', 'Context changed before its saved result could be recorded.');
793
- const next = { ...previous, ...patch, generation: expectedGeneration + 1 };
794
- if (next.state === 'ready' && (!next.baseRevision || !next.baseSnapshot || !next.workingSnapshot))
795
- fail('binding', 'A ready context requires durable private and base snapshots.');
796
- if (!Array.isArray(next.scalars) || !Array.isArray(next.complexChanges))
797
- fail('invalid', 'Pending changes must be arrays.');
798
- for (const request of next.complexChanges)
799
- id(request);
800
- if (new Set(next.complexChanges).size !== next.complexChanges.length)
801
- fail('invalid', 'Complex change identities must be distinct.');
802
- const fields = new Set();
803
- for (const change of next.scalars) {
804
- if (!/^(?:[A-Za-z0-9_]+:)?[a-f0-9]+$/.test(text(change.address, 128)) ||
805
- !['function.name', 'comment.eol', 'comment.pre', 'comment.post', 'comment.plate', 'comment.repeatable'].includes(change.field))
806
- fail('invalid', 'Scalar changes require a canonical address and a supported field.');
807
- for (const value of [change.original, change.local, ...(change.conflict ? [change.conflict.shared] : [])]) {
808
- if (value !== null && (typeof value !== 'string' || value.length > 16000 || value.includes('\0')))
809
- fail('invalid', 'Scalar values must be bounded strings or null.');
810
- }
811
- if (change.removed !== undefined && (change.removed !== true || change.local !== null || !next.complexChanges.length))
812
- fail('invalid', 'Removed scalar fields require retained complex program state.');
813
- if (change.field === 'function.name' && !change.removed && (change.local === null || !change.local.length || change.local.length > 512))
814
- fail('invalid', 'Function name must be a nonempty bounded string.');
815
- const field = change.address + ':' + change.field;
816
- if (change.dependency !== undefined && !/^[a-f0-9]{64}$/.test(change.dependency))
817
- fail('invalid', 'Scalar dependency fingerprint is malformed.');
818
- if (fields.has(field))
819
- fail('invalid', 'Scalar field must have one original/local comparison.');
820
- fields.add(field);
821
- }
822
- this.db.prepare('UPDATE contexts SET generation=?,data=? WHERE id=?').run(next.generation, bounded(next), next.id);
823
- return next;
824
- }
825
137
  }