@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,14 @@
1
- import { AsyncLocalStorage } from 'node:async_hooks';
2
1
  import { randomUUID, createHash } from 'node:crypto';
3
2
  import { DatabaseSync } from 'node:sqlite';
4
- import { mkdirSync, lstatSync, chmodSync } from 'node:fs';
3
+ import { mkdirSync, statSync, existsSync } from 'node:fs';
5
4
  import { join } from 'node:path';
6
5
  import { performance } from 'node:perf_hooks';
7
6
  import { CliError } from '@eyeauras/cli-factory';
8
7
  import { diagnosticFailure } from './diagnostic-error.js';
9
- import { auditLimits, auditPolicy, auditUnavailable, initializeRetention, retentionState, auditStorageMode, requireAuditStorageMode, collectAudit, acquireAuditWriter, auditAdmissionMs } from './audit-retention.js';
8
+ import { auditLimits, auditPolicy, auditUnavailable, collectAudit, metadataNumber } from './audit-retention.js';
10
9
  export { auditLimits } from './audit-retention.js';
11
10
  const applicationId = 0x49534155;
12
11
  const uuid = /^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/i;
13
- const kinds = new Set(['audit.gc', 'command.started', 'command.succeeded', 'command.failed', 'transport.failed', 'request.state', 'gc.started', 'gc.finished', 'gc.failed', 'gc.category', 'gc.retained', 'gc.remove.started', 'gc.remove.succeeded', 'gc.remove.failed', 'gc.remove.planned', 'gc.release.started', 'gc.release.succeeded', 'gc.release.failed']);
14
12
  const categories = new Set(['native-checkouts', 'duplicate-exports', 'temporary-caches', 'detached-projects', 'unreferenced-snapshots']);
15
13
  const reasons = new Set(['live-or-uncertain', 'ownership-unproved', 'referenced', 'private-work', 'capture-unproved', 'link-or-special', 'removal-failed', 'other']);
16
14
  const resourceTypes = new Set(['snapshot', 'native-view', 'project', 'export', 'cache', 'other']);
@@ -73,248 +71,175 @@ function details(raw) {
73
71
  out.failure = diagnosticFailure(error) ?? { code: auditErrorCode(error) };
74
72
  return out;
75
73
  }
74
+ /** A stored event as append() wrote it. */
76
75
  function readRecord(row) {
77
- const text = String(row.data);
78
- if (Buffer.byteLength(text) > auditLimits.eventBytes)
79
- unavailable();
80
- const raw = JSON.parse(text), operationId = field(raw, 'operationId'), command = field(raw, 'command'), event = field(raw, 'event'), at = field(raw, 'at'), sequence = Number(row.seq);
81
- if (field(raw, 'schema') !== 1 || typeof operationId !== 'string' || !uuid.test(operationId) || operationId !== row.operation_id || typeof command !== 'string' || !/^[a-z0-9][a-z0-9 -]{0,159}$/.test(command) || command !== row.command || typeof event !== 'string' || !kinds.has(event) || event !== row.event || typeof at !== 'string' || !/^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d\.\d{3}Z$/.test(at) || !Number.isSafeInteger(sequence) || sequence < 1)
82
- unavailable();
83
- const result = { schema: 1, sequence, operationId, command, event, at, ...details(raw) }, failure = field(raw, 'failure');
84
- if (failure !== undefined) {
85
- const code = field(failure, 'code');
86
- result.failure = typeof code === 'string' ? (diagnosticFailure(new CliError('Recorded failure', { code, result: { transport: field(failure, 'transport') } })) ?? { code: fsCodes.has(code) ? code : 'unavailable' }) : { code: 'unavailable' };
87
- }
88
- return result;
76
+ return { ...JSON.parse(String(row.data)), sequence: Number(row.seq) };
89
77
  }
90
78
  function unavailable() { return auditUnavailable(); }
91
- function stat(path) { try {
92
- return lstatSync(path);
93
- }
94
- catch (error) {
95
- if (field(error, 'code') === 'ENOENT')
96
- return;
97
- throw error;
98
- } }
99
- /** Independent operational history, never recovery authority. No argument/result serialization. */
79
+ const schema = `
80
+ CREATE TABLE IF NOT EXISTS metadata(key TEXT PRIMARY KEY,value TEXT NOT NULL);
81
+ CREATE TABLE IF NOT EXISTS events(seq INTEGER PRIMARY KEY AUTOINCREMENT,at_ms INTEGER NOT NULL,operation_id TEXT NOT NULL,event TEXT NOT NULL,command TEXT NOT NULL,session TEXT,target TEXT,request TEXT,caller_hash TEXT,outcome TEXT,data TEXT NOT NULL CHECK(length(data)<=4096));
82
+ CREATE INDEX IF NOT EXISTS events_operation ON events(operation_id,seq);
83
+ CREATE INDEX IF NOT EXISTS events_session ON events(session,operation_id);
84
+ CREATE INDEX IF NOT EXISTS events_target ON events(target,operation_id);
85
+ CREATE INDEX IF NOT EXISTS events_request ON events(request,caller_hash);
86
+ CREATE INDEX IF NOT EXISTS events_at ON events(at_ms);
87
+ DROP TRIGGER IF EXISTS audit_writer_v2;`;
88
+ /**
89
+ * Independent operational history, never recovery authority. No argument/result serialization.
90
+ * One connection serves the owner's lifetime: the schema is created and retention runs once, when it opens.
91
+ */
100
92
  export class AuditStore {
101
93
  directory;
102
94
  path;
103
- initialPolicy;
104
- admissionMs;
105
- /**
106
- * `admissionMs` bounds the wait of a write for the shared writer lock (default three seconds). Its opening reads
107
- * and its commit each wait for the database that long as well, and never less than three seconds; the waits add up.
108
- */
109
- constructor(directory, limits = auditLimits, options = {}) {
95
+ policy;
96
+ db;
97
+ constructor(directory, limits = auditLimits) {
110
98
  this.directory = directory;
111
99
  this.path = join(directory, 'activity.sqlite');
112
- this.initialPolicy = auditPolicy(limits);
113
- this.admissionMs = options.admissionMs ?? auditAdmissionMs;
114
- if (!Number.isSafeInteger(this.admissionMs) || this.admissionMs < 1 || this.admissionMs > 60000)
115
- throw new Error('Invalid audit admission wait.');
100
+ this.policy = auditPolicy(limits);
116
101
  }
117
- open(write) {
118
- const existing = stat(this.directory);
119
- if (!existing && !write)
120
- return;
121
- if (!existing)
122
- mkdirSync(this.directory, { recursive: true, mode: 0o700 });
123
- const dir = stat(this.directory), file = stat(this.path);
124
- if (!dir?.isDirectory() || dir.isSymbolicLink() || file && (!file.isFile() || file.isSymbolicLink() || file.nlink !== 1))
125
- unavailable();
126
- if (!file && !write)
127
- return;
128
- let db;
102
+ open() {
103
+ if (this.db)
104
+ return this.db;
105
+ mkdirSync(this.directory, { recursive: true, mode: 0o700 });
106
+ const db = new DatabaseSync(this.path);
129
107
  try {
130
- // A writer's reads before admission wait as long as its admission does: another writer's durable commit can
131
- // hold the database for longer than SQLite's short default under disk load.
132
- db = new DatabaseSync(this.path, { readOnly: !write });
133
- db.exec('PRAGMA busy_timeout=' + (write ? Math.max(3000, this.admissionMs) : 3000) + ';');
134
- db.exec('BEGIN');
135
- const version = Number(db.prepare('PRAGMA user_version').get()?.user_version), app = Number(db.prepare('PRAGMA application_id').get()?.application_id), foreign = version === 0 && app === 0 && Boolean(db.prepare("SELECT name FROM sqlite_master WHERE type='table'").get());
136
- db.exec('END');
137
- if (foreign)
138
- unavailable();
139
- if (write && version === 0 && app === 0) {
140
- db.exec('PRAGMA auto_vacuum=FULL; PRAGMA synchronous=FULL; BEGIN IMMEDIATE;');
141
- const currentVersion = Number(db.prepare('PRAGMA user_version').get()?.user_version);
142
- if (currentVersion === 0) {
143
- if (db.prepare("SELECT name FROM sqlite_master WHERE type='table'").get())
144
- unavailable();
145
- db.exec(`
146
- CREATE TABLE IF NOT EXISTS metadata(key TEXT PRIMARY KEY,value TEXT NOT NULL);
147
- CREATE TABLE IF NOT EXISTS events(seq INTEGER PRIMARY KEY AUTOINCREMENT,at_ms INTEGER NOT NULL,operation_id TEXT NOT NULL,event TEXT NOT NULL,command TEXT NOT NULL,session TEXT,target TEXT,request TEXT,caller_hash TEXT,outcome TEXT,data TEXT NOT NULL CHECK(length(data)<=4096));
148
- CREATE INDEX IF NOT EXISTS events_operation ON events(operation_id,seq);
149
- CREATE INDEX IF NOT EXISTS events_session ON events(session,operation_id);
150
- CREATE INDEX IF NOT EXISTS events_target ON events(target,operation_id);
151
- CREATE INDEX IF NOT EXISTS events_request ON events(request,caller_hash);
152
- CREATE INDEX IF NOT EXISTS events_at ON events(at_ms);
153
- PRAGMA application_id=${applicationId}; PRAGMA user_version=1;`);
154
- db.prepare('INSERT OR IGNORE INTO metadata VALUES(?,?)').run('storeId', randomUUID());
155
- db.prepare('INSERT OR IGNORE INTO metadata VALUES(?,?)').run('prunedEvents', '0');
156
- initializeRetention(db, this.initialPolicy, Date.now());
108
+ db.exec('PRAGMA busy_timeout=5000; PRAGMA synchronous=NORMAL;');
109
+ // WAL is a property of the file. Switching to it does not wait for other connections, so processes that create the
110
+ // store at the same moment retry while another one holds it; an existing store is already WAL.
111
+ for (let attempt = 0; String(db.prepare('PRAGMA journal_mode').get()?.journal_mode) !== 'wal'; attempt++) {
112
+ try {
113
+ db.exec('PRAGMA journal_mode=WAL');
114
+ }
115
+ catch (error) {
116
+ if (attempt >= 400 || error.errcode !== 5)
117
+ throw error;
118
+ Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 25);
157
119
  }
158
- else if (![1, 2].includes(currentVersion) || Number(db.prepare('PRAGMA application_id').get()?.application_id) !== applicationId)
159
- unavailable();
120
+ }
121
+ db.exec('BEGIN IMMEDIATE');
122
+ try {
123
+ db.exec(schema);
124
+ const now = Date.now();
125
+ for (const [key, value] of Object.entries({ storeId: randomUUID(), prunedEvents: '0', lastSweepMs: String(now), gcRuns: '0', lastGcRemoved: '0' }))
126
+ db.prepare('INSERT OR IGNORE INTO metadata VALUES(?,?)').run(key, value);
127
+ if (Number(db.prepare('PRAGMA user_version').get()?.user_version) !== 3)
128
+ db.exec(`PRAGMA application_id=${applicationId}; PRAGMA user_version=3;`);
160
129
  db.exec('COMMIT');
161
130
  }
162
- else if (![1, 2].includes(version) || app !== applicationId)
163
- unavailable();
164
- this.metadata(db);
165
- if (write) {
166
- requireAuditStorageMode(db);
167
- if (Number(db.prepare('PRAGMA user_version').get()?.user_version) === 2)
168
- retentionState(db);
169
- chmodSync(this.path, 0o600);
170
- db.exec('PRAGMA synchronous=FULL;');
131
+ catch (error) {
132
+ db.exec('ROLLBACK');
133
+ throw error;
171
134
  }
172
- else if (Number(db.prepare('PRAGMA user_version').get()?.user_version) === 2)
173
- retentionState(db);
174
- return db;
135
+ collectAudit(db, this.policy, Date.now());
175
136
  }
176
137
  catch (error) {
177
- db?.close();
138
+ db.close();
178
139
  throw error;
179
140
  }
141
+ return this.db = db;
180
142
  }
181
- insert(db, operationId, command, event, raw, scope, at) {
182
- const data = { schema: 1, operationId, command, event, at: new Date(at).toISOString(), ...details(scope), ...details(raw), pid: process.pid }, text = JSON.stringify(data);
183
- if (Buffer.byteLength(text) > auditLimits.eventBytes)
184
- throw new Error('Internal audit event exceeds its bound.');
185
- const value = (key) => typeof data[key] === 'string' ? data[key] : null;
186
- return Number(db.prepare('INSERT INTO events(at_ms,operation_id,event,command,session,target,request,caller_hash,outcome,data,writer_version) VALUES(?,?,?,?,?,?,?,?,?,?,2)').run(at, operationId, event, command, value('session'), value('target'), value('request'), value('callerHash'), value('outcome'), text).lastInsertRowid);
187
- }
143
+ /** Readers do not create history: without a file there is nothing to read. */
144
+ reader() { return this.db ?? (existsSync(this.path) ? this.open() : undefined); }
145
+ close() { this.db?.close(); this.db = undefined; }
188
146
  append(operationId, command, event, raw = {}, scope = {}) {
189
- if (!uuid.test(operationId) || !kinds.has(event) || !/^[a-z0-9][a-z0-9 -]{0,159}$/.test(command))
190
- throw new Error('Invalid internal audit event.');
191
- const db = this.open(true);
192
- try {
193
- acquireAuditWriter(db, this.directory, this.admissionMs);
194
- const metadata = this.metadata(db), version = Number(db.prepare('PRAGMA user_version').get()?.user_version);
195
- requireAuditStorageMode(db);
196
- if (version === 1)
197
- initializeRetention(db, this.initialPolicy, 0);
198
- else if (version !== 2)
199
- unavailable();
200
- const state = retentionState(db);
201
- const at = Date.now(), sequence = this.insert(db, operationId, command, event, raw, scope, at);
202
- collectAudit(db, at, sequence, metadata.prunedEvents, state, data => this.insert(db, operationId, command, 'audit.gc', data, scope, at));
203
- db.exec('COMMIT');
204
- }
205
- finally {
206
- db.close();
207
- }
208
- }
209
- metadata(db) {
210
- const storeId = db.prepare("SELECT value FROM metadata WHERE key='storeId'").get()?.value, rawPruned = db.prepare("SELECT value FROM metadata WHERE key='prunedEvents'").get()?.value;
211
- if (typeof storeId !== 'string' || !uuid.test(storeId) || typeof rawPruned !== 'string' || !/^\d+(?:\.0+)?$/.test(rawPruned) || !Number.isSafeInteger(Number(rawPruned)))
212
- unavailable();
213
- return { storeId, prunedEvents: Number(rawPruned) };
147
+ const at = Date.now(), data = { schema: 1, operationId, command, event, at: new Date(at).toISOString(), ...details(scope), ...details(raw), pid: process.pid }, text = JSON.stringify(data);
148
+ const value = (key) => typeof data[key] === 'string' ? data[key] : null;
149
+ this.open().prepare('INSERT INTO events(at_ms,operation_id,event,command,session,target,request,caller_hash,outcome,data) VALUES(?,?,?,?,?,?,?,?,?,?)').run(at, operationId, event, command, value('session'), value('target'), value('request'), value('callerHash'), value('outcome'), text);
214
150
  }
215
151
  snapshot(db) {
216
- const range = db.prepare('SELECT count(*) count,min(seq) oldestSequence,max(seq) newestSequence FROM events').get();
217
- return { ...this.metadata(db), count: Number(range.count), oldestSequence: range.oldestSequence === null ? null : Number(range.oldestSequence), newestSequence: range.newestSequence === null ? null : Number(range.newestSequence) };
152
+ const range = db.prepare('SELECT count(*) count,min(seq) oldestSequence,max(seq) newestSequence FROM events').get(), storeId = db.prepare("SELECT value FROM metadata WHERE key='storeId'").get()?.value;
153
+ return { storeId: typeof storeId === 'string' ? storeId : null, prunedEvents: metadataNumber(db, 'prunedEvents'), count: Number(range.count), oldestSequence: range.oldestSequence === null ? null : Number(range.oldestSequence), newestSequence: range.newestSequence === null ? null : Number(range.newestSequence) };
218
154
  }
219
155
  list(filter = {}) {
220
156
  const limit = filter.limit ?? 50;
221
157
  if (!Number.isSafeInteger(limit) || limit < 1 || limit > 10000)
222
158
  throw new CliError('Audit limit must be 1–10000.', { code: 'audit.invalid' });
223
- let db;
224
159
  try {
225
- db = this.open(false);
160
+ const db = this.reader();
226
161
  if (!db)
227
162
  return { schema: 1, storeId: null, count: 0, oldestSequence: null, newestSequence: null, prunedEvents: 0, items: [], hasMore: false, nextBefore: null };
228
163
  db.exec('BEGIN');
229
- const snapshot = this.snapshot(db), clauses = [], values = [];
230
- const add = (sql, value) => { if (value !== undefined) {
231
- clauses.push(sql);
232
- values.push(value);
233
- } };
234
- add('seq<?', filter.before);
235
- add('operation_id=?', filter.operationId);
236
- add('command=?', filter.command);
237
- add('event=?', filter.event);
238
- add('at_ms>=?', filter.since);
239
- add('at_ms<=?', filter.until);
240
- for (const key of ['session', 'target'])
241
- add(`operation_id IN (SELECT operation_id FROM events WHERE ${key}=?)`, filter[key]);
242
- if (filter.request !== undefined) {
243
- clauses.push('operation_id IN (SELECT operation_id FROM events WHERE request=? OR caller_hash=?)');
244
- values.push(filter.request, auditHash(filter.request));
164
+ try {
165
+ const snapshot = this.snapshot(db), clauses = [], values = [];
166
+ const add = (sql, value) => { if (value !== undefined) {
167
+ clauses.push(sql);
168
+ values.push(value);
169
+ } };
170
+ add('seq<?', filter.before);
171
+ add('operation_id=?', filter.operationId);
172
+ add('command=?', filter.command);
173
+ add('event=?', filter.event);
174
+ add('at_ms>=?', filter.since);
175
+ add('at_ms<=?', filter.until);
176
+ for (const key of ['session', 'target'])
177
+ add(`operation_id IN (SELECT operation_id FROM events WHERE ${key}=?)`, filter[key]);
178
+ if (filter.request !== undefined) {
179
+ clauses.push('operation_id IN (SELECT operation_id FROM events WHERE request=? OR caller_hash=?)');
180
+ values.push(filter.request, auditHash(filter.request));
181
+ }
182
+ add("operation_id IN (SELECT operation_id FROM events WHERE json_extract(data,'$.traceId')=?)", filter.traceId);
183
+ if (filter.failures)
184
+ clauses.push("outcome='failure'");
185
+ const rows = db.prepare(`SELECT seq,operation_id,event,command,data FROM events ${clauses.length ? 'WHERE ' + clauses.join(' AND ') : ''} ORDER BY seq DESC LIMIT ?`).all(...values, limit + 1), hasMore = rows.length > limit;
186
+ const items = rows.slice(0, limit).map(row => readRecord(row));
187
+ return { schema: 1, ...snapshot, items, hasMore, nextBefore: hasMore ? items.at(-1).sequence : null };
188
+ }
189
+ finally {
190
+ db.exec('COMMIT');
245
191
  }
246
- add("operation_id IN (SELECT operation_id FROM events WHERE json_extract(data,'$.traceId')=?)", filter.traceId);
247
- if (filter.failures)
248
- clauses.push("outcome='failure'");
249
- const rows = db.prepare(`SELECT seq,operation_id,event,command,data FROM events ${clauses.length ? 'WHERE ' + clauses.join(' AND ') : ''} ORDER BY seq DESC LIMIT ?`).all(...values, limit + 1), hasMore = rows.length > limit;
250
- const items = rows.slice(0, limit).map(row => readRecord(row));
251
- db.exec('COMMIT');
252
- return { schema: 1, ...snapshot, items, hasMore, nextBefore: hasMore ? items.at(-1).sequence : null };
253
192
  }
254
193
  catch {
255
194
  return unavailable();
256
195
  }
257
- finally {
258
- db?.close();
259
- }
260
196
  }
261
197
  status() {
262
- let db;
198
+ const retention = { ...auditLimits, ...this.policy }, meaning = 'No terminal record retained; this does not prove an operation is still running.';
263
199
  try {
264
- db = this.open(false);
200
+ const db = this.reader();
265
201
  if (!db)
266
- return { initialized: false, storeId: null, count: 0, oldestSequence: null, newestSequence: null, prunedEvents: 0, retention: { ...auditLimits, ...this.initialPolicy }, maintenance: { schemaVersion: 2, runs: 0, lastSweepMs: 0, lastRemoved: 0, sharedByProfile: true }, unfinished: [], unfinishedMeaning: 'No terminal record retained; this does not prove an operation is still running.' };
202
+ return { initialized: false, storeId: null, count: 0, oldestSequence: null, newestSequence: null, prunedEvents: 0, retention, maintenance: { schemaVersion: 3, runs: 0, lastSweepMs: 0, lastRemoved: 0, sharedByProfile: true }, unfinished: [], unfinishedMeaning: meaning };
267
203
  db.exec('BEGIN');
268
- const check = db.prepare('PRAGMA quick_check(1)').get();
269
- if (!check || Object.values(check)[0] !== 'ok')
270
- unavailable();
271
- const unfinished = db.prepare("SELECT s.seq,s.operation_id,s.command,s.event,s.data FROM events s WHERE event='command.started' AND NOT EXISTS(SELECT 1 FROM events e WHERE e.operation_id=s.operation_id AND e.event IN ('command.succeeded','command.failed')) ORDER BY seq DESC LIMIT 20").all().map(row => { const record = readRecord(row); return { operationId: record.operationId, command: record.command, startedAtMs: Date.parse(record.at), pid: record.pid }; });
272
- const result = { initialized: true, ...this.snapshot(db), bytes: stat(this.path)?.size, retention: { ...auditLimits, ...(Number(db.prepare('PRAGMA user_version').get()?.user_version) === 2 ? retentionState(db).policy : this.initialPolicy) }, maintenance: { schemaVersion: Number(db.prepare('PRAGMA user_version').get()?.user_version), ...(Number(db.prepare('PRAGMA user_version').get()?.user_version) === 2 ? retentionState(db) : { runs: 0, lastSweepMs: 0, lastRemoved: 0 }), sharedByProfile: true, ...auditStorageMode(db) }, unfinished, unfinishedMeaning: 'No terminal record retained; this does not prove an operation is still running.' };
273
- db.exec('COMMIT');
274
- return result;
204
+ try {
205
+ // Histories written before one-row-per-command kept a separate start record.
206
+ const unfinished = db.prepare("SELECT s.seq,s.operation_id,s.command,s.event,s.data FROM events s WHERE event='command.started' AND NOT EXISTS(SELECT 1 FROM events e WHERE e.operation_id=s.operation_id AND e.event IN ('command.succeeded','command.failed')) ORDER BY seq DESC LIMIT 20").all().map(row => { const record = readRecord(row); return { operationId: record.operationId, command: record.command, startedAtMs: Date.parse(record.at), pid: record.pid }; });
207
+ return { initialized: true, ...this.snapshot(db), bytes: statSync(this.path).size, retention,
208
+ maintenance: { schemaVersion: Number(db.prepare('PRAGMA user_version').get()?.user_version), runs: metadataNumber(db, 'gcRuns'), lastSweepMs: metadataNumber(db, 'lastSweepMs'), lastRemoved: metadataNumber(db, 'lastGcRemoved'), sharedByProfile: true, journalMode: String(db.prepare('PRAGMA journal_mode').get()?.journal_mode) },
209
+ unfinished, unfinishedMeaning: meaning };
210
+ }
211
+ finally {
212
+ db.exec('COMMIT');
213
+ }
275
214
  }
276
215
  catch {
277
216
  return unavailable();
278
217
  }
279
- finally {
280
- db?.close();
281
- }
282
- }
283
- }
284
- const active = new AsyncLocalStorage();
285
- export function bindAudit(raw) { const context = active.getStore(); if (context)
286
- Object.assign(context.scope, correlation(raw)); }
287
- export function auditEvent(event, raw = {}) {
288
- const context = active.getStore();
289
- if (!context || context.disabled)
290
- return;
291
- try {
292
- context.store.append(context.operationId, context.command, event, raw, context.scope);
293
- }
294
- catch (error) {
295
- context.disabled = true;
296
- try {
297
- context.warn(auditErrorCode(error));
298
- }
299
- catch { }
300
218
  }
301
219
  }
220
+ /** One row per command: its terminal outcome with its duration. Audit failure never changes the command outcome. */
302
221
  export async function auditCommand(store, command, options, action, warn = () => { }) {
303
222
  const operationId = randomUUID(), started = performance.now(), scope = commandCorrelation(options), request = field(options, 'requestId');
304
223
  if (typeof request === 'string' && request.length <= 4096)
305
224
  scope.callerHash = auditHash(request);
306
- return active.run({ store, operationId, command, scope, warn, disabled: false }, async () => {
307
- auditEvent('command.started');
225
+ const record = (event, raw) => { try {
226
+ store.append(operationId, command, event, raw, scope);
227
+ }
228
+ catch (error) {
308
229
  try {
309
- const value = await action();
310
- Object.assign(scope, commandCorrelation(value));
311
- auditEvent('command.succeeded', { durationMs: performance.now() - started, outcome: 'success', state: field(value, 'state'), bytes: field(value, 'bytes'), retainedCount: field(value, 'retainedCount') });
312
- return value;
313
- }
314
- catch (error) {
315
- Object.assign(scope, commandCorrelation(field(error, 'result')));
316
- auditEvent('command.failed', { durationMs: performance.now() - started, outcome: 'failure', error });
317
- throw error;
230
+ warn(auditErrorCode(error));
318
231
  }
319
- });
232
+ catch { }
233
+ } };
234
+ try {
235
+ const value = await action();
236
+ Object.assign(scope, commandCorrelation(value));
237
+ record('command.succeeded', { durationMs: performance.now() - started, outcome: 'success', state: field(value, 'state'), bytes: field(value, 'bytes'), retainedCount: field(value, 'retainedCount') });
238
+ return value;
239
+ }
240
+ catch (error) {
241
+ Object.assign(scope, commandCorrelation(field(error, 'result')));
242
+ record('command.failed', { durationMs: performance.now() - started, outcome: 'failure', error });
243
+ throw error;
244
+ }
320
245
  }
@@ -5,18 +5,26 @@ export interface StorageDefault {
5
5
  schema: 1;
6
6
  base: string;
7
7
  application: string;
8
- binding: string;
9
8
  id: string;
10
- baseInode: string;
11
9
  revision: string;
12
10
  }
11
+ type Marker = Omit<StorageDefault, 'revision'>;
12
+ /**
13
+ * Directory of the installation-wide `.cache` (binaries downloaded from the hub): next to the profiles on the storage
14
+ * default base when one is set (an external disk stays the only data disk), else the installation's roaming directory.
15
+ */
16
+ export declare function cacheBase(c: Context): string;
13
17
  /** Storage control metadata, independent of Factory's profile/settings document. */
14
18
  export declare function storageDefault(c: Context): StorageDefault | undefined;
15
19
  export declare function validateStorageDefault(c: Context, value: StorageDefault): void;
20
+ /** This application's marker on a base, or undefined when the base carries none (for example, an unmounted volume). */
21
+ export declare function storageBaseMarker(c: Context, base: string): Marker | undefined;
16
22
  /** Preserve pre-existing local analysis until it is explicitly migrated. */
17
23
  export declare function legacyAnalysis(c: Context): boolean;
18
24
  export declare function inheritedStorage(c: Context): StorageDefault | undefined;
19
25
  export declare function checkStorageDefaultBase(c: Context, base: string): Promise<void>;
26
+ /** Claim an existing base directory for this application, or return its existing claim. */
27
+ export declare function claimStorageBase(c: Context, base: string): Promise<Marker>;
20
28
  export declare function writeStorageDefault(c: Context, base: string, revision?: string, expected?: string | null): Promise<{
21
29
  state: 'configured' | 'superseded';
22
30
  base: string | null;
@@ -1,9 +1,8 @@
1
1
  import { CliError } from '@eyeauras/cli-factory';
2
- import { lstatSync, readFileSync, realpathSync } from 'node:fs';
2
+ import { lstatSync, readFileSync } from 'node:fs';
3
3
  import { link, lstat, open, realpath, unlink } from 'node:fs/promises';
4
4
  import { isAbsolute, join, resolve } from 'node:path';
5
5
  import { randomUUID } from 'node:crypto';
6
- import { digest } from './model.js';
7
6
  import { atomicWrite, withToolLock } from './tool-runtime/store.js';
8
7
  export const analysisTrees = ['workspace', 'materials', 'temp', 'runtime'];
9
8
  const uuid = (value) => typeof value === 'string' && /^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/.test(value);
@@ -11,19 +10,26 @@ const absent = (error) => error.code === 'ENOENT';
11
10
  function fail(code, message) { throw new CliError(message, { code: 'storage.' + code }); }
12
11
  const policyPath = (c) => join(c.appArguments.RoamingAppDataDirectory, '.analysis-storage-default.json');
13
12
  const markerPath = (base) => join(base, '.insight-storage-root.json');
14
- const binding = (c) => digest(realpathSync.native(c.appArguments.RoamingAppDataDirectory));
15
13
  function readOwnedJson(path) {
16
14
  if (!lstatSync(path).isFile())
17
15
  fail('configuration', 'Storage default metadata must be an ordinary file.');
18
16
  return JSON.parse(readFileSync(path, 'utf8'));
19
17
  }
18
+ /** A base marker names its application and id: that is how a foreign or unmounted base is recognized. */
20
19
  function valid(c, value) {
21
20
  if (!value || typeof value !== 'object' || Array.isArray(value))
22
21
  return false;
23
22
  const v = value;
24
- return v.schema === 1 && v.application === c.appArguments.AppName && v.binding === binding(c) && uuid(v.id) &&
25
- typeof v.base === 'string' && isAbsolute(v.base) && v.base === resolve(v.base) && !/[\0\r\n]/.test(v.base) &&
26
- typeof v.baseInode === 'string' && /^\d+$/.test(v.baseInode);
23
+ return v.schema === 1 && v.application === c.appArguments.AppName && uuid(v.id) &&
24
+ typeof v.base === 'string' && isAbsolute(v.base) && v.base === resolve(v.base) && !/[\0\r\n]/.test(v.base);
25
+ }
26
+ /**
27
+ * Directory of the installation-wide `.cache` (binaries downloaded from the hub): next to the profiles on the storage
28
+ * default base when one is set (an external disk stays the only data disk), else the installation's roaming directory.
29
+ */
30
+ export function cacheBase(c) {
31
+ const configured = storageDefault(c);
32
+ return configured ? join(configured.base, c.appArguments.AppName) : c.appArguments.RoamingAppDataDirectory;
27
33
  }
28
34
  /** Storage control metadata, independent of Factory's profile/settings document. */
29
35
  export function storageDefault(c) {
@@ -44,15 +50,24 @@ export function validateStorageDefault(c, value) {
44
50
  try {
45
51
  if (!valid(c, value) || !uuid(value.revision))
46
52
  throw Error('binding');
47
- const st = lstatSync(value.base, { bigint: true }), marker = readOwnedJson(markerPath(value.base));
48
- if (!st.isDirectory() || realpathSync.native(value.base) !== value.base || String(st.ino) !== value.baseInode ||
49
- !valid(c, marker) || marker.id !== value.id || marker.base !== value.base || marker.baseInode !== value.baseInode)
53
+ const st = lstatSync(value.base), marker = readOwnedJson(markerPath(value.base));
54
+ if (!st.isDirectory() || !valid(c, marker) || marker.id !== value.id || marker.base !== value.base)
50
55
  throw Error('binding');
51
56
  }
52
57
  catch {
53
58
  fail('unavailable', 'Installation analysis storage is missing or changed; mount its original volume. No fallback was created.');
54
59
  }
55
60
  }
61
+ /** This application's marker on a base, or undefined when the base carries none (for example, an unmounted volume). */
62
+ export function storageBaseMarker(c, base) {
63
+ try {
64
+ const marker = readOwnedJson(markerPath(base));
65
+ return valid(c, marker) && marker.base === base ? marker : undefined;
66
+ }
67
+ catch {
68
+ return;
69
+ }
70
+ }
56
71
  /** Preserve pre-existing local analysis until it is explicitly migrated. */
57
72
  export function legacyAnalysis(c) {
58
73
  return analysisTrees.some(tree => { try {
@@ -81,9 +96,42 @@ export async function checkStorageDefaultBase(c, base) {
81
96
  }
82
97
  if (!valid(c, marker) || marker.base !== base)
83
98
  fail('binding', 'Storage base belongs to another application/control root; no data was adopted.');
84
- const st = await lstat(base, { bigint: true });
85
- if (!st.isDirectory() || await realpath(base) !== base || String(st.ino) !== marker.baseInode)
86
- fail('binding', 'Storage base directory was replaced.');
99
+ }
100
+ /** Claim an existing base directory for this application, or return its existing claim. */
101
+ export async function claimStorageBase(c, base) {
102
+ await checkStorageDefaultBase(c, base);
103
+ try {
104
+ return readOwnedJson(markerPath(base));
105
+ }
106
+ catch (error) {
107
+ if (!absent(error))
108
+ throw error;
109
+ const marker = { schema: 1, base, application: c.appArguments.AppName, id: randomUUID() };
110
+ const temporary = markerPath(base) + '.new-' + randomUUID(), file = await open(temporary, 'wx', 0o600);
111
+ try {
112
+ try {
113
+ await file.writeFile(JSON.stringify(marker) + '\n');
114
+ await file.sync();
115
+ }
116
+ finally {
117
+ await file.close();
118
+ }
119
+ try {
120
+ await link(temporary, markerPath(base));
121
+ return marker;
122
+ }
123
+ catch (e) {
124
+ if (e.code !== 'EEXIST')
125
+ throw e;
126
+ }
127
+ }
128
+ finally {
129
+ await unlink(temporary);
130
+ }
131
+ // Another process claimed the base first: its marker is the claim.
132
+ await checkStorageDefaultBase(c, base);
133
+ return readOwnedJson(markerPath(base));
134
+ }
87
135
  }
88
136
  export async function writeStorageDefault(c, base, revision = randomUUID(), expected) {
89
137
  return withToolLock(c.appArguments.RoamingAppDataDirectory, 'analysis-storage-default', async () => {
@@ -91,49 +139,16 @@ export async function writeStorageDefault(c, base, revision = randomUUID(), expe
91
139
  if (current?.revision === revision) {
92
140
  if (current.base !== base)
93
141
  fail('binding', 'Storage default intent changed.');
94
- validateStorageDefault(c, current);
95
142
  return { state: 'configured', base, revision, binding: current };
96
143
  }
97
144
  // A resumed migration must never overwrite a later user's default selection.
98
145
  if (expected !== undefined && (current?.revision ?? null) !== expected)
99
146
  return { state: 'superseded', base: current?.base ?? null, revision: current?.revision ?? null };
100
- const st = await lstat(base, { bigint: true });
147
+ const st = await lstat(base);
101
148
  if (!st.isDirectory() || await realpath(base) !== base)
102
149
  fail('path', 'Choose an existing ordinary storage base directory.');
103
- await checkStorageDefaultBase(c, base);
104
- let marker;
105
- try {
106
- marker = readOwnedJson(markerPath(base));
107
- }
108
- catch (error) {
109
- if (!absent(error))
110
- throw error;
111
- marker = { schema: 1, base, application: c.appArguments.AppName, binding: binding(c), id: randomUUID(), baseInode: String(st.ino) };
112
- const temporary = markerPath(base) + '.new-' + randomUUID(), file = await open(temporary, 'wx', 0o600);
113
- try {
114
- try {
115
- await file.writeFile(JSON.stringify(marker) + '\n');
116
- await file.sync();
117
- }
118
- finally {
119
- await file.close();
120
- }
121
- try {
122
- await link(temporary, markerPath(base));
123
- }
124
- catch (e) {
125
- if (e.code !== 'EEXIST')
126
- throw e;
127
- }
128
- }
129
- finally {
130
- await unlink(temporary);
131
- }
132
- await checkStorageDefaultBase(c, base);
133
- marker = readOwnedJson(markerPath(base));
134
- }
150
+ const marker = await claimStorageBase(c, base);
135
151
  const next = { ...marker, revision };
136
- validateStorageDefault(c, next);
137
152
  if (process.platform !== 'win32') {
138
153
  const dir = await open(base, 'r');
139
154
  try {