@eyeauras/insight-cli 0.1.0 → 0.2.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 (391) hide show
  1. package/.cli-package-build.json +1 -1
  2. package/README.md +33 -2
  3. package/SKILL.md +38 -51
  4. package/dist/src/administration-results.js +1 -1
  5. package/dist/src/administration.d.ts +1 -1
  6. package/dist/src/administration.js +16 -2
  7. package/dist/src/binary.d.ts +3 -0
  8. package/dist/src/binary.js +74 -0
  9. package/dist/src/capture.d.ts +3 -0
  10. package/dist/src/capture.js +220 -0
  11. package/dist/src/cli.js +91 -14
  12. package/dist/src/contexts.d.ts +5 -0
  13. package/dist/src/contexts.js +54 -18
  14. package/dist/src/debugger-caller.d.ts +17 -0
  15. package/dist/src/debugger-caller.js +129 -0
  16. package/dist/src/debugger-launch.d.ts +2 -0
  17. package/dist/src/debugger-launch.js +17 -0
  18. package/dist/src/debugger-results.d.ts +1 -0
  19. package/dist/src/debugger-results.js +8 -0
  20. package/dist/src/debugger-supervisor.js +56 -13
  21. package/dist/src/debugger.js +16 -7
  22. package/dist/src/die.d.ts +12 -0
  23. package/dist/src/die.js +127 -0
  24. package/dist/src/dnspy-runtime.d.ts +8 -0
  25. package/dist/src/dnspy-runtime.js +46 -0
  26. package/dist/src/dnspy.d.ts +22 -0
  27. package/dist/src/dnspy.js +160 -0
  28. package/dist/src/dotnet-diagnostics.d.ts +13 -0
  29. package/dist/src/dotnet-diagnostics.js +101 -0
  30. package/dist/src/frida-worker.d.ts +1 -0
  31. package/dist/src/frida-worker.js +125 -0
  32. package/dist/src/frida.d.ts +16 -0
  33. package/dist/src/frida.js +125 -0
  34. package/dist/src/ghidra-debugger-runtime.d.ts +7 -0
  35. package/dist/src/ghidra-debugger-runtime.js +31 -0
  36. package/dist/src/ghidra-processes.d.ts +6 -0
  37. package/dist/src/ghidra-processes.js +121 -0
  38. package/dist/src/ghidra.js +6 -6
  39. package/dist/src/ilspy.d.ts +7 -0
  40. package/dist/src/ilspy.js +122 -0
  41. package/dist/src/lifecycle.d.ts +1 -1
  42. package/dist/src/lifecycle.js +8 -2
  43. package/dist/src/lldb.d.ts +10 -0
  44. package/dist/src/lldb.js +99 -0
  45. package/dist/src/llvm.d.ts +6 -0
  46. package/dist/src/llvm.js +133 -0
  47. package/dist/src/managed-heap.d.ts +4 -0
  48. package/dist/src/managed-heap.js +73 -0
  49. package/dist/src/managed-metadata.d.ts +11 -0
  50. package/dist/src/managed-metadata.js +66 -0
  51. package/dist/src/mitmproxy.d.ts +55 -0
  52. package/dist/src/mitmproxy.js +172 -0
  53. package/dist/src/native-inputs.d.ts +3 -2
  54. package/dist/src/native-inputs.js +21 -5
  55. package/dist/src/package-version.d.ts +1 -0
  56. package/dist/src/package-version.js +3 -0
  57. package/dist/src/procmon-config.d.ts +2 -0
  58. package/dist/src/procmon-config.js +15 -0
  59. package/dist/src/procmon-events.d.ts +13 -0
  60. package/dist/src/procmon-events.js +82 -0
  61. package/dist/src/procmon.d.ts +4 -0
  62. package/dist/src/procmon.js +107 -0
  63. package/dist/src/research.d.ts +11 -2
  64. package/dist/src/research.js +5 -3
  65. package/dist/src/runtime-catalog.d.ts +13 -0
  66. package/dist/src/runtime-catalog.js +26 -0
  67. package/dist/src/runtime-manager.d.ts +125 -0
  68. package/dist/src/runtime-manager.js +385 -0
  69. package/dist/src/runtime-selection.d.ts +13 -0
  70. package/dist/src/runtime-selection.js +42 -0
  71. package/dist/src/server.d.ts +15 -0
  72. package/dist/src/server.js +77 -96
  73. package/dist/src/sevenzip.d.ts +15 -0
  74. package/dist/src/sevenzip.js +119 -0
  75. package/dist/src/strace.d.ts +10 -0
  76. package/dist/src/strace.js +71 -0
  77. package/dist/src/text-window.d.ts +11 -0
  78. package/dist/src/text-window.js +6 -0
  79. package/dist/src/tool-runtime/archives.d.ts +10 -0
  80. package/dist/src/tool-runtime/archives.js +194 -0
  81. package/dist/src/tool-runtime/catalog.d.ts +3 -0
  82. package/dist/src/tool-runtime/catalog.js +13 -0
  83. package/dist/src/tool-runtime/commands.d.ts +9 -0
  84. package/dist/src/tool-runtime/commands.js +39 -0
  85. package/dist/src/tool-runtime/deadline.d.ts +11 -0
  86. package/dist/src/tool-runtime/deadline.js +32 -0
  87. package/dist/src/tool-runtime/definition.d.ts +73 -0
  88. package/dist/src/tool-runtime/definition.js +49 -0
  89. package/dist/src/tool-runtime/dotnet.d.ts +4 -0
  90. package/dist/src/tool-runtime/dotnet.js +22 -0
  91. package/dist/src/tool-runtime/identity.d.ts +6 -0
  92. package/dist/src/tool-runtime/identity.js +50 -0
  93. package/dist/src/tool-runtime/installer.d.ts +101 -0
  94. package/dist/src/tool-runtime/installer.js +180 -0
  95. package/dist/src/tool-runtime/launch-worker.d.ts +1 -0
  96. package/dist/src/tool-runtime/launch-worker.js +58 -0
  97. package/dist/src/tool-runtime/run.d.ts +51 -0
  98. package/dist/src/tool-runtime/run.js +159 -0
  99. package/dist/src/tool-runtime/store.d.ts +15 -0
  100. package/dist/src/tool-runtime/store.js +219 -0
  101. package/dist/src/tool-runtime/supervisor.d.ts +57 -0
  102. package/dist/src/tool-runtime/supervisor.js +266 -0
  103. package/dist/src/tool-runtime/windows-job.d.ts +22 -0
  104. package/dist/src/tool-runtime/windows-job.js +43 -0
  105. package/dist/src/toolbox.d.ts +84 -0
  106. package/dist/src/toolbox.js +35 -0
  107. package/dist/src/tshark.d.ts +23 -0
  108. package/dist/src/tshark.js +174 -0
  109. package/dist/src/windbg.d.ts +14 -0
  110. package/dist/src/windbg.js +119 -0
  111. package/dist/src/workspace.d.ts +1 -0
  112. package/dist/src/workspace.js +6 -0
  113. package/package.json +7 -4
  114. package/references/administration.md +2 -1
  115. package/references/agent-execution.md +36 -0
  116. package/references/agent-setup.md +61 -0
  117. package/references/artifacts.md +5 -0
  118. package/references/debugger.md +22 -0
  119. package/references/ilspy.md +33 -0
  120. package/references/managed-runtime.md +157 -0
  121. package/references/native/InsightPythonWheels.java +283 -2
  122. package/references/native/InsightRuntimeDoctor.java +33 -0
  123. package/references/native/InsightTraceState.java +28 -13
  124. package/references/setup.md +6 -3
  125. package/runtime/managed/insight-heap/Azure.Core.dll +0 -0
  126. package/runtime/managed/insight-heap/Azure.Identity.dll +0 -0
  127. package/runtime/managed/insight-heap/Insight.Heap.csproj +1 -0
  128. package/runtime/managed/insight-heap/Insight.Heap.deps.json +391 -0
  129. package/runtime/managed/insight-heap/Insight.Heap.dll +0 -0
  130. package/runtime/managed/insight-heap/Insight.Heap.runtimeconfig.json +13 -0
  131. package/runtime/managed/insight-heap/Microsoft.Bcl.AsyncInterfaces.dll +0 -0
  132. package/runtime/managed/insight-heap/Microsoft.Diagnostics.NETCore.Client.dll +0 -0
  133. package/runtime/managed/insight-heap/Microsoft.Diagnostics.Runtime.dll +0 -0
  134. package/runtime/managed/insight-heap/Microsoft.Extensions.Configuration.Abstractions.dll +0 -0
  135. package/runtime/managed/insight-heap/Microsoft.Extensions.DependencyInjection.Abstractions.dll +0 -0
  136. package/runtime/managed/insight-heap/Microsoft.Extensions.Diagnostics.Abstractions.dll +0 -0
  137. package/runtime/managed/insight-heap/Microsoft.Extensions.FileProviders.Abstractions.dll +0 -0
  138. package/runtime/managed/insight-heap/Microsoft.Extensions.Hosting.Abstractions.dll +0 -0
  139. package/runtime/managed/insight-heap/Microsoft.Extensions.Logging.Abstractions.dll +0 -0
  140. package/runtime/managed/insight-heap/Microsoft.Extensions.Options.dll +0 -0
  141. package/runtime/managed/insight-heap/Microsoft.Extensions.Primitives.dll +0 -0
  142. package/runtime/managed/insight-heap/Microsoft.Identity.Client.Extensions.Msal.dll +0 -0
  143. package/runtime/managed/insight-heap/Microsoft.Identity.Client.dll +0 -0
  144. package/runtime/managed/insight-heap/Microsoft.IdentityModel.Abstractions.dll +0 -0
  145. package/runtime/managed/insight-heap/Microsoft.Security.AntiSSRF.dll +0 -0
  146. package/runtime/managed/insight-heap/NuGet.Config +1 -0
  147. package/runtime/managed/insight-heap/Program.cs +20 -0
  148. package/runtime/managed/insight-heap/README.md +16 -0
  149. package/runtime/managed/insight-heap/System.ClientModel.dll +0 -0
  150. package/runtime/managed/insight-heap/System.Memory.Data.dll +0 -0
  151. package/runtime/managed/insight-heap/System.Security.Cryptography.ProtectedData.dll +0 -0
  152. package/runtime/managed/insight-heap/dependencies.json +436 -0
  153. package/runtime/managed/insight-heap/notices/Azure.Core-LICENSE.txt +21 -0
  154. package/runtime/managed/insight-heap/notices/Azure.Identity-LICENSE.txt +21 -0
  155. package/runtime/managed/insight-heap/notices/Microsoft.Bcl.AsyncInterfaces-LICENSE.txt +23 -0
  156. package/runtime/managed/insight-heap/notices/Microsoft.Bcl.AsyncInterfaces-THIRD-PARTY-NOTICES.TXT +1418 -0
  157. package/runtime/managed/insight-heap/notices/Microsoft.Diagnostics.NETCore.Client-LICENSE.txt +23 -0
  158. package/runtime/managed/insight-heap/notices/Microsoft.Diagnostics.Runtime-LICENSE.txt +23 -0
  159. package/runtime/managed/insight-heap/notices/Microsoft.Extensions.Configuration.Abstractions-LICENSE.txt +23 -0
  160. package/runtime/managed/insight-heap/notices/Microsoft.Extensions.Configuration.Abstractions-THIRD-PARTY-NOTICES.TXT +1418 -0
  161. package/runtime/managed/insight-heap/notices/Microsoft.Extensions.DependencyInjection.Abstractions-LICENSE.txt +23 -0
  162. package/runtime/managed/insight-heap/notices/Microsoft.Extensions.DependencyInjection.Abstractions-THIRD-PARTY-NOTICES.TXT +1418 -0
  163. package/runtime/managed/insight-heap/notices/Microsoft.Extensions.Diagnostics.Abstractions-LICENSE.txt +23 -0
  164. package/runtime/managed/insight-heap/notices/Microsoft.Extensions.Diagnostics.Abstractions-THIRD-PARTY-NOTICES.TXT +1418 -0
  165. package/runtime/managed/insight-heap/notices/Microsoft.Extensions.FileProviders.Abstractions-LICENSE.txt +23 -0
  166. package/runtime/managed/insight-heap/notices/Microsoft.Extensions.FileProviders.Abstractions-THIRD-PARTY-NOTICES.TXT +1418 -0
  167. package/runtime/managed/insight-heap/notices/Microsoft.Extensions.Hosting.Abstractions-LICENSE.txt +23 -0
  168. package/runtime/managed/insight-heap/notices/Microsoft.Extensions.Hosting.Abstractions-THIRD-PARTY-NOTICES.TXT +1418 -0
  169. package/runtime/managed/insight-heap/notices/Microsoft.Extensions.Logging.Abstractions-LICENSE.txt +23 -0
  170. package/runtime/managed/insight-heap/notices/Microsoft.Extensions.Logging.Abstractions-THIRD-PARTY-NOTICES.TXT +1418 -0
  171. package/runtime/managed/insight-heap/notices/Microsoft.Extensions.Options-LICENSE.txt +23 -0
  172. package/runtime/managed/insight-heap/notices/Microsoft.Extensions.Options-THIRD-PARTY-NOTICES.TXT +1418 -0
  173. package/runtime/managed/insight-heap/notices/Microsoft.Extensions.Primitives-LICENSE.txt +23 -0
  174. package/runtime/managed/insight-heap/notices/Microsoft.Extensions.Primitives-THIRD-PARTY-NOTICES.TXT +1418 -0
  175. package/runtime/managed/insight-heap/notices/Microsoft.Identity.Client-LICENSE.txt +21 -0
  176. package/runtime/managed/insight-heap/notices/Microsoft.Identity.Client.Extensions.Msal-LICENSE.txt +21 -0
  177. package/runtime/managed/insight-heap/notices/Microsoft.IdentityModel.Abstractions-LICENSE.txt +21 -0
  178. package/runtime/managed/insight-heap/notices/Microsoft.Security.AntiSSRF-LICENSE.txt +21 -0
  179. package/runtime/managed/insight-heap/notices/System.ClientModel-LICENSE.txt +21 -0
  180. package/runtime/managed/insight-heap/notices/System.Memory.Data-LICENSE.txt +23 -0
  181. package/runtime/managed/insight-heap/notices/System.Memory.Data-THIRD-PARTY-NOTICES.TXT +1418 -0
  182. package/runtime/managed/insight-heap/notices/System.Security.Cryptography.ProtectedData-LICENSE.TXT +23 -0
  183. package/runtime/managed/insight-heap/notices/System.Security.Cryptography.ProtectedData-THIRD-PARTY-NOTICES.TXT +309 -0
  184. package/runtime/managed/insight-heap/packages.lock.json +165 -0
  185. package/runtime/managed/insight-heap/provenance.json +146 -0
  186. package/runtime/managed/insight-heap/runtimes/win/lib/netstandard2.0/System.Security.Cryptography.ProtectedData.dll +0 -0
  187. package/runtime/managed/insight-managed/Insight.Managed.csproj +4 -0
  188. package/runtime/managed/insight-managed/Insight.Managed.deps.json +41 -0
  189. package/runtime/managed/insight-managed/Insight.Managed.dll +0 -0
  190. package/runtime/managed/insight-managed/Insight.Managed.runtimeconfig.json +13 -0
  191. package/runtime/managed/insight-managed/LICENSE.dnlib.txt +20 -0
  192. package/runtime/managed/insight-managed/NuGet.Config +1 -0
  193. package/runtime/managed/insight-managed/Program.cs +31 -0
  194. package/runtime/managed/insight-managed/README.md +16 -0
  195. package/runtime/managed/insight-managed/dnlib.dll +0 -0
  196. package/runtime/managed/insight-managed/packages.lock.json +13 -0
  197. package/runtime/managed/insight-managed/provenance.json +40 -0
  198. package/runtime/native/binary/README.md +22 -0
  199. package/runtime/native/binary/dependencies.json +166 -0
  200. package/runtime/native/binary/helper.cpp +44 -0
  201. package/runtime/native/binary/insight-binary-darwin-arm64 +0 -0
  202. package/runtime/native/binary/notices/Catch2-3.12.0--Catch2-3.12.0__LICENSE.txt +23 -0
  203. package/runtime/native/binary/notices/LIEF-LICENSE.txt +202 -0
  204. package/runtime/native/binary/notices/LIEF-attribution.txt +37 -0
  205. package/runtime/native/binary/notices/Melkor_ELF_Fuzzer-ac2495b--elf_fuzzer-master__LICENSE.txt +674 -0
  206. package/runtime/native/binary/notices/expected-1.3.1--expected-1.3.1__COPYING +121 -0
  207. package/runtime/native/binary/notices/frozen-61dce5a--frozen-61dce5ae18ca59931e27675c468e64118aba8744__AUTHORS +3 -0
  208. package/runtime/native/binary/notices/frozen-61dce5a--frozen-61dce5ae18ca59931e27675c468e64118aba8744__LICENSE +202 -0
  209. package/runtime/native/binary/notices/json-LICENSE.MIT +21 -0
  210. package/runtime/native/binary/notices/mbedtls-4.0.0.r0.gec4044008d--LICENSE +553 -0
  211. package/runtime/native/binary/notices/mbedtls-4.0.0.r0.gec4044008d--framework__LICENSE +553 -0
  212. package/runtime/native/binary/notices/mbedtls-4.0.0.r0.gec4044008d--tf-psa-crypto__LICENSE +552 -0
  213. package/runtime/native/binary/notices/mbedtls-4.0.0.r0.gec4044008d--tf-psa-crypto__framework__LICENSE +553 -0
  214. package/runtime/native/binary/notices/nanobind-2.13.0.r18.g4db9ed3f--LICENSE +26 -0
  215. package/runtime/native/binary/notices/nanobind-2.13.0.r18.g4db9ed3f--ext__robin_map__LICENSE +21 -0
  216. package/runtime/native/binary/notices/span-LICENSE_1_0.txt +23 -0
  217. package/runtime/native/binary/notices/span-attribution.txt +11 -0
  218. package/runtime/native/binary/notices/spdlog-1.17.0--spdlog-1.17.0__LICENSE +25 -0
  219. package/runtime/native/binary/notices/utfcpp-4.0.9--utfcpp-4.0.9__LICENSE +23 -0
  220. package/runtime/native/binary/provenance.json +48 -0
  221. package/runtime/native/child-deadline-linux-x64 +0 -0
  222. package/runtime/native/child-deadline-linux.c +24 -0
  223. package/runtime/native/child-deadline-linux.provenance.json +17 -0
  224. package/runtime/native/deadline-alarm-darwin-universal.dylib +0 -0
  225. package/runtime/native/deadline-alarm.c +33 -0
  226. package/runtime/native/deadline-alarm.provenance.json +22 -0
  227. package/runtime/native/deadline-exec-darwin-arm64 +0 -0
  228. package/runtime/native/deadline-exec.c +24 -0
  229. package/runtime/native/deadline-exec.provenance.json +17 -0
  230. package/runtime/native/dnspy-extension/Bridge.cs +58 -0
  231. package/runtime/native/dnspy-extension/Insight.DnSpy.csproj +13 -0
  232. package/runtime/native/dnspy-extension/Insight.DnSpy.x.dll +0 -0
  233. package/runtime/native/dnspy-extension/NuGet.Config +1 -0
  234. package/runtime/native/dnspy-extension/UNICODE-LOADER.md +26 -0
  235. package/runtime/native/dnspy-extension/packages.lock.json +6 -0
  236. package/runtime/native/dnspy-extension/provenance.json +27 -0
  237. package/runtime/native/dnspy-extension/upstream-public-build.snk +0 -0
  238. package/runtime/native/dnspy-extension/vendor-files.json +4341 -0
  239. package/runtime/native/file-version.ps1 +7 -0
  240. package/runtime/native/insight-registry-win-x64.dll +0 -0
  241. package/runtime/native/mitmproxy/bridge.py +180 -0
  242. package/runtime/native/mitmproxy/notices.json +476 -0
  243. package/runtime/native/sources/detours-LICENSE.md +23 -0
  244. package/runtime/native/sources/detours-e4bfd6b.tar.gz +0 -0
  245. package/runtime/native/sources/detours-provenance.json +10 -0
  246. package/runtime/native/tshark-layout.json +2247 -0
  247. package/runtime/native/windows-job/DirectoryAlias.cs +24 -0
  248. package/runtime/native/windows-job/Insight.WindowsJob.csproj +1 -0
  249. package/runtime/native/windows-job/Insight.WindowsJob.dll +0 -0
  250. package/runtime/native/windows-job/NuGet.Config +1 -0
  251. package/runtime/native/windows-job/OwnedJob.cs +79 -0
  252. package/runtime/native/windows-job/RegistryRedirect.cs +45 -0
  253. package/runtime/native/windows-job/packages.lock.json +21 -0
  254. package/runtime/native/windows-job/provenance.json +16 -0
  255. package/runtime/native/windows-job/windows-job.ps1 +8 -0
  256. package/runtime/native/windows-registry.c +21 -0
  257. package/runtime/native/windows-registry.def +3 -0
  258. package/runtime/native/windows-registry.provenance.json +14 -0
  259. package/runtime/notices/diagnostics-10.0.750501.txt +23 -0
  260. package/runtime/tool-catalog.json +290 -0
  261. package/runtime/toolbox.json +1401 -0
  262. package/skill-bundle/insight-artifacts/SKILL.md +30 -0
  263. package/skill-bundle/insight-artifacts/references/agent-execution.md +36 -0
  264. package/skill-bundle/insight-artifacts/references/artifacts.md +52 -0
  265. package/skill-bundle/insight-binary/SKILL.md +46 -0
  266. package/skill-bundle/insight-binary/references/agent-execution.md +36 -0
  267. package/skill-bundle/insight-capture/SKILL.md +56 -0
  268. package/skill-bundle/insight-capture/references/agent-execution.md +36 -0
  269. package/skill-bundle/insight-cli/SKILL.md +42 -0
  270. package/skill-bundle/insight-cli/references/agent-execution.md +36 -0
  271. package/skill-bundle/insight-cli/references/agent-setup.md +61 -0
  272. package/skill-bundle/insight-die/SKILL.md +49 -0
  273. package/skill-bundle/insight-die/references/agent-execution.md +36 -0
  274. package/skill-bundle/insight-dnspy/SKILL.md +65 -0
  275. package/skill-bundle/insight-dnspy/references/agent-execution.md +36 -0
  276. package/skill-bundle/insight-dotnet-dump/SKILL.md +46 -0
  277. package/skill-bundle/insight-dotnet-dump/references/agent-execution.md +36 -0
  278. package/skill-bundle/insight-dotnet-stack/SKILL.md +39 -0
  279. package/skill-bundle/insight-dotnet-stack/references/agent-execution.md +36 -0
  280. package/skill-bundle/insight-dotnet-trace/SKILL.md +45 -0
  281. package/skill-bundle/insight-dotnet-trace/references/agent-execution.md +36 -0
  282. package/skill-bundle/insight-frida/SKILL.md +67 -0
  283. package/skill-bundle/insight-frida/references/agent-execution.md +36 -0
  284. package/skill-bundle/insight-ghidra/SKILL.md +91 -0
  285. package/skill-bundle/insight-ghidra/references/administration.md +34 -0
  286. package/skill-bundle/insight-ghidra/references/agent-execution.md +36 -0
  287. package/skill-bundle/insight-ghidra/references/archive.md +32 -0
  288. package/skill-bundle/insight-ghidra/references/artifacts.md +52 -0
  289. package/skill-bundle/insight-ghidra/references/debugger.md +62 -0
  290. package/skill-bundle/insight-ghidra/references/extensions-and-sync.md +124 -0
  291. package/skill-bundle/insight-ghidra/references/managed-runtime.md +157 -0
  292. package/skill-bundle/insight-ghidra/references/native-workflows.md +112 -0
  293. package/skill-bundle/insight-ghidra/references/query-semantics.md +96 -0
  294. package/skill-bundle/insight-ghidra/references/recovery.md +53 -0
  295. package/skill-bundle/insight-ghidra/references/research.md +101 -0
  296. package/skill-bundle/insight-ghidra/references/setup.md +50 -0
  297. package/skill-bundle/insight-ilspy/SKILL.md +45 -0
  298. package/skill-bundle/insight-ilspy/references/agent-execution.md +36 -0
  299. package/skill-bundle/insight-ilspy/references/ilspy.md +33 -0
  300. package/skill-bundle/insight-interop/SKILL.md +54 -0
  301. package/skill-bundle/insight-interop/references/agent-execution.md +36 -0
  302. package/skill-bundle/insight-lldb/SKILL.md +54 -0
  303. package/skill-bundle/insight-lldb/references/agent-execution.md +36 -0
  304. package/skill-bundle/insight-llvm/SKILL.md +56 -0
  305. package/skill-bundle/insight-llvm/references/agent-execution.md +36 -0
  306. package/skill-bundle/insight-managed-heap/SKILL.md +43 -0
  307. package/skill-bundle/insight-managed-heap/references/agent-execution.md +36 -0
  308. package/skill-bundle/insight-managed-metadata/SKILL.md +52 -0
  309. package/skill-bundle/insight-managed-metadata/references/agent-execution.md +36 -0
  310. package/skill-bundle/insight-mitmproxy/SKILL.md +62 -0
  311. package/skill-bundle/insight-mitmproxy/references/agent-execution.md +36 -0
  312. package/skill-bundle/insight-overview/SKILL.md +79 -0
  313. package/skill-bundle/insight-overview/references/agent-execution.md +36 -0
  314. package/skill-bundle/insight-procmon/SKILL.md +49 -0
  315. package/skill-bundle/insight-procmon/references/agent-execution.md +36 -0
  316. package/skill-bundle/insight-re/SKILL.md +121 -0
  317. package/skill-bundle/insight-re/references/agent-execution.md +36 -0
  318. package/skill-bundle/insight-re/references/artifacts.md +52 -0
  319. package/skill-bundle/insight-re/references/recovery.md +53 -0
  320. package/skill-bundle/insight-sevenzip/SKILL.md +42 -0
  321. package/skill-bundle/insight-sevenzip/references/agent-execution.md +36 -0
  322. package/skill-bundle/insight-strace/SKILL.md +46 -0
  323. package/skill-bundle/insight-strace/references/agent-execution.md +36 -0
  324. package/skill-bundle/insight-tshark/SKILL.md +49 -0
  325. package/skill-bundle/insight-tshark/references/agent-execution.md +36 -0
  326. package/skill-bundle/insight-windbg/SKILL.md +46 -0
  327. package/skill-bundle/insight-windbg/references/agent-execution.md +36 -0
  328. package/skill-bundle/manifest.json +32 -0
  329. package/skills/insight-artifacts/SKILL.md +30 -0
  330. package/skills/insight-artifacts/references/agent-execution.md +36 -0
  331. package/skills/insight-artifacts/references/artifacts.md +52 -0
  332. package/skills/insight-binary/SKILL.md +46 -0
  333. package/skills/insight-binary/references/agent-execution.md +36 -0
  334. package/skills/insight-capture/SKILL.md +56 -0
  335. package/skills/insight-capture/references/agent-execution.md +36 -0
  336. package/skills/insight-die/SKILL.md +49 -0
  337. package/skills/insight-die/references/agent-execution.md +36 -0
  338. package/skills/insight-dnspy/SKILL.md +65 -0
  339. package/skills/insight-dnspy/references/agent-execution.md +36 -0
  340. package/skills/insight-dotnet-dump/SKILL.md +46 -0
  341. package/skills/insight-dotnet-dump/references/agent-execution.md +36 -0
  342. package/skills/insight-dotnet-stack/SKILL.md +39 -0
  343. package/skills/insight-dotnet-stack/references/agent-execution.md +36 -0
  344. package/skills/insight-dotnet-trace/SKILL.md +45 -0
  345. package/skills/insight-dotnet-trace/references/agent-execution.md +36 -0
  346. package/skills/insight-frida/SKILL.md +67 -0
  347. package/skills/insight-frida/references/agent-execution.md +36 -0
  348. package/skills/insight-ghidra/SKILL.md +91 -0
  349. package/skills/insight-ghidra/references/administration.md +34 -0
  350. package/skills/insight-ghidra/references/agent-execution.md +36 -0
  351. package/skills/insight-ghidra/references/archive.md +32 -0
  352. package/skills/insight-ghidra/references/artifacts.md +52 -0
  353. package/skills/insight-ghidra/references/debugger.md +62 -0
  354. package/skills/insight-ghidra/references/extensions-and-sync.md +124 -0
  355. package/skills/insight-ghidra/references/managed-runtime.md +157 -0
  356. package/skills/insight-ghidra/references/native-workflows.md +112 -0
  357. package/skills/insight-ghidra/references/query-semantics.md +96 -0
  358. package/skills/insight-ghidra/references/recovery.md +53 -0
  359. package/skills/insight-ghidra/references/research.md +101 -0
  360. package/skills/insight-ghidra/references/setup.md +50 -0
  361. package/skills/insight-ilspy/SKILL.md +45 -0
  362. package/skills/insight-ilspy/references/agent-execution.md +36 -0
  363. package/skills/insight-ilspy/references/ilspy.md +33 -0
  364. package/skills/insight-interop/SKILL.md +54 -0
  365. package/skills/insight-interop/references/agent-execution.md +36 -0
  366. package/skills/insight-lldb/SKILL.md +54 -0
  367. package/skills/insight-lldb/references/agent-execution.md +36 -0
  368. package/skills/insight-llvm/SKILL.md +56 -0
  369. package/skills/insight-llvm/references/agent-execution.md +36 -0
  370. package/skills/insight-managed-heap/SKILL.md +43 -0
  371. package/skills/insight-managed-heap/references/agent-execution.md +36 -0
  372. package/skills/insight-managed-metadata/SKILL.md +52 -0
  373. package/skills/insight-managed-metadata/references/agent-execution.md +36 -0
  374. package/skills/insight-mitmproxy/SKILL.md +62 -0
  375. package/skills/insight-mitmproxy/references/agent-execution.md +36 -0
  376. package/skills/insight-overview/SKILL.md +79 -0
  377. package/skills/insight-overview/references/agent-execution.md +36 -0
  378. package/skills/insight-procmon/SKILL.md +49 -0
  379. package/skills/insight-procmon/references/agent-execution.md +36 -0
  380. package/skills/insight-re/SKILL.md +22 -9
  381. package/skills/insight-re/references/agent-execution.md +36 -0
  382. package/skills/insight-re/references/artifacts.md +52 -0
  383. package/skills/insight-re/references/recovery.md +53 -0
  384. package/skills/insight-sevenzip/SKILL.md +42 -0
  385. package/skills/insight-sevenzip/references/agent-execution.md +36 -0
  386. package/skills/insight-strace/SKILL.md +46 -0
  387. package/skills/insight-strace/references/agent-execution.md +36 -0
  388. package/skills/insight-tshark/SKILL.md +49 -0
  389. package/skills/insight-tshark/references/agent-execution.md +36 -0
  390. package/skills/insight-windbg/SKILL.md +46 -0
  391. package/skills/insight-windbg/references/agent-execution.md +36 -0
@@ -0,0 +1,219 @@
1
+ import { mkdir, open, rename, rm, readFile, readdir, lstat, realpath } from 'node:fs/promises';
2
+ import { createReadStream } from 'node:fs';
3
+ import { dirname, join, resolve, relative, sep } from 'node:path';
4
+ import { randomUUID, createHash } from 'node:crypto';
5
+ import { AsyncLocalStorage } from 'node:async_hooks';
6
+ import { CliError } from '@eyeauras/cli-factory';
7
+ import { fail } from '../model.js';
8
+ export async function atomicWrite(path, value) {
9
+ await mkdir(dirname(path), { recursive: true, mode: 0o700 });
10
+ const temporary = path + '.new-' + randomUUID(), file = await open(temporary, 'wx', 0o600);
11
+ try {
12
+ await file.writeFile(JSON.stringify(value, null, 2) + '\n');
13
+ await file.sync();
14
+ }
15
+ finally {
16
+ await file.close();
17
+ }
18
+ await rename(temporary, path);
19
+ if (process.platform !== 'win32') {
20
+ const parent = await open(dirname(path), 'r');
21
+ try {
22
+ await parent.sync();
23
+ }
24
+ finally {
25
+ await parent.close();
26
+ }
27
+ }
28
+ }
29
+ export async function readJson(path) { try {
30
+ return JSON.parse(await readFile(path, 'utf8'));
31
+ }
32
+ catch (e) {
33
+ if (e.code === 'ENOENT')
34
+ return;
35
+ throw e;
36
+ } }
37
+ export function toolRoot(directory, tool) { if (!/^[a-z][a-z0-9-]*$/.test(tool))
38
+ fail('invalid', 'Invalid tool identity.'); return tool === 'ghidra' ? join(directory, 'runtime') : join(directory, 'runtime', 'tools', tool); }
39
+ const queues = new Map(), held = new AsyncLocalStorage(), uses = new Map();
40
+ const key = (directory, tool) => resolve(directory) + '\0' + tool;
41
+ /** CLI clients already share Factory's elected owner. Do not create another IPC/lease protocol. */
42
+ export async function withToolLock(directory, tool, action, signal) {
43
+ signal?.throwIfAborted();
44
+ const k = key(directory, tool);
45
+ if (held.getStore()?.has(k))
46
+ return action();
47
+ const previous = queues.get(k) ?? Promise.resolve();
48
+ let started = false;
49
+ const execution = previous.then(() => { signal?.throwIfAborted(); started = true; return held.run(new Set([...(held.getStore() ?? []), k]), action); });
50
+ const tail = execution.then(() => { }, () => { });
51
+ queues.set(k, tail);
52
+ void tail.then(() => { if (queues.get(k) === tail)
53
+ queues.delete(k); });
54
+ if (!signal)
55
+ return execution;
56
+ return new Promise((ok, bad) => {
57
+ const aborted = () => { if (!started)
58
+ bad(signal.reason); };
59
+ signal.addEventListener('abort', aborted, { once: true });
60
+ if (signal.aborted)
61
+ aborted();
62
+ execution.then(ok, bad).finally(() => signal.removeEventListener('abort', aborted));
63
+ });
64
+ }
65
+ export function toolProfileBusy(directory) { const prefix = resolve(directory) + '\0'; return [...queues.keys(), ...uses.keys()].some(k => k.startsWith(prefix)); }
66
+ export function toolUseCount(directory, tool) { return uses.get(key(directory, tool)) ?? 0; }
67
+ export async function withToolUse(directory, tool, acquire, signal) {
68
+ return withToolLock(directory, tool, async () => {
69
+ const value = await acquire();
70
+ signal?.throwIfAborted();
71
+ const k = key(directory, tool);
72
+ uses.set(k, (uses.get(k) ?? 0) + 1);
73
+ let released = false;
74
+ return { value, release() { if (released)
75
+ return; released = true; const n = (uses.get(k) ?? 1) - 1; if (n)
76
+ uses.set(k, n);
77
+ else
78
+ uses.delete(k); } };
79
+ }, signal);
80
+ }
81
+ export async function assertUnused(directory, tool) {
82
+ if (toolUseCount(directory, tool))
83
+ fail('busy', 'Tool installation is reserved by an active operation.');
84
+ let names;
85
+ const root = join(directory, 'runtime/processes');
86
+ try {
87
+ names = await readdir(root);
88
+ }
89
+ catch (e) {
90
+ if (e.code === 'ENOENT')
91
+ return;
92
+ throw e;
93
+ }
94
+ for (const name of names) {
95
+ if (!/^[a-f0-9-]{36}\.json$/.test(name))
96
+ continue;
97
+ const retained = await readJson(join(root, name));
98
+ if (!retained || retained.tool !== tool)
99
+ continue;
100
+ const { processStatus } = await import('./supervisor.js'), record = await processStatus(directory, name.slice(0, -5));
101
+ if (['exited', 'failed'].includes(record.state))
102
+ continue;
103
+ if (record.phase === 'native_children_pending' || record.phase === 'native_children_unverified')
104
+ fail('busy', 'Tool has an active or unverified native helper; inspect its retained records before changing installations.');
105
+ if (!record.pid) {
106
+ if (record.gated && record.ownerPid)
107
+ try {
108
+ process.kill(record.ownerPid, 0);
109
+ }
110
+ catch (e) {
111
+ if (e.code === 'ESRCH')
112
+ continue;
113
+ throw e;
114
+ }
115
+ fail('busy', 'Tool has an unresolved process launch; inspect its process record.');
116
+ }
117
+ try {
118
+ process.kill(record.pid, 0);
119
+ fail('busy', 'Tool has an active or unverified process; stop it before changing installations.');
120
+ }
121
+ catch (e) {
122
+ if (e.code !== 'ESRCH')
123
+ throw e;
124
+ }
125
+ }
126
+ }
127
+ export async function installationStage(root, id, prepare, verify, signal) {
128
+ if (!/^[a-f0-9]{64}$/.test(id))
129
+ fail('invalid', 'Invalid installation identity.');
130
+ signal?.throwIfAborted();
131
+ const installed = join(root, 'installations', id), receipt = await readJson(join(installed, 'ready.json'));
132
+ if (receipt) {
133
+ await verify(receipt);
134
+ return receipt;
135
+ }
136
+ const stage = join(root, 'stages', randomUUID());
137
+ await mkdir(stage, { recursive: true, mode: 0o700 });
138
+ try {
139
+ const value = await prepare(stage, installed);
140
+ signal?.throwIfAborted();
141
+ await atomicWrite(join(stage, 'ready.json'), value);
142
+ await mkdir(dirname(installed), { recursive: true, mode: 0o700 });
143
+ try {
144
+ await lstat(installed);
145
+ fail('binding', 'Incomplete installation is retained; inspect it before removing it.');
146
+ }
147
+ catch (e) {
148
+ if (e.code !== 'ENOENT')
149
+ throw e;
150
+ }
151
+ await rename(stage, installed);
152
+ if (process.platform !== 'win32') {
153
+ const p = await open(dirname(installed), 'r');
154
+ try {
155
+ await p.sync();
156
+ }
157
+ finally {
158
+ await p.close();
159
+ }
160
+ }
161
+ return value;
162
+ }
163
+ catch (error) {
164
+ const code = error instanceof CliError ? error.code : 'installation';
165
+ await atomicWrite(join(stage, 'failure.json'), { state: 'failed', code });
166
+ if (error instanceof CliError)
167
+ throw new CliError(error.message, { code: error.code, result: { ...(error.result && typeof error.result === 'object' ? error.result : {}), diagnostics: stage } });
168
+ throw new CliError('Tool installation failed; the prior selection and diagnostic stage are retained.', { code: 'tool.installation', cause: error, result: { diagnostics: stage } });
169
+ }
170
+ }
171
+ export async function removeInstallation(root, id) {
172
+ if (!/^[a-f0-9]{64}$/.test(id))
173
+ fail('binding', 'Invalid installation identity.');
174
+ const path = join(root, 'installations', id);
175
+ let actual;
176
+ try {
177
+ actual = await realpath(path);
178
+ }
179
+ catch (e) {
180
+ if (e.code === 'ENOENT')
181
+ return;
182
+ throw e;
183
+ }
184
+ if (actual !== join(await realpath(root), 'installations', id))
185
+ fail('binding', 'Owned installation path was replaced by an external link.');
186
+ await rm(path, { recursive: true, force: true });
187
+ }
188
+ export async function treeFingerprint(root) {
189
+ const hash = createHash('sha256'), canonicalRoot = await realpath(root);
190
+ let count = 0;
191
+ async function visit(path) {
192
+ for (const name of (await readdir(path)).sort()) {
193
+ if (path === root && name === 'ready.json')
194
+ continue;
195
+ const at = join(path, name), st = await lstat(at);
196
+ if (++count > 100000)
197
+ fail('limit', 'Tool installation exceeds its file bound.');
198
+ hash.update(relative(root, at).replaceAll('\\', '/') + '\0');
199
+ if (st.isDirectory())
200
+ await visit(at);
201
+ else if (st.isSymbolicLink()) {
202
+ const destination = await realpath(at);
203
+ if (!destination.startsWith(canonicalRoot + sep))
204
+ fail('binding', 'Installed component link escapes its owned directory.');
205
+ hash.update('link:' + relative(canonicalRoot, destination));
206
+ }
207
+ else if (st.isFile()) {
208
+ const leaf = createHash('sha256');
209
+ for await (const b of createReadStream(at))
210
+ leaf.update(b);
211
+ hash.update('file:' + st.size + ':' + leaf.digest('hex') + '\0');
212
+ }
213
+ else
214
+ fail('binding', 'Unsupported tool installation entry.');
215
+ }
216
+ }
217
+ await visit(root);
218
+ return hash.digest('hex');
219
+ }
@@ -0,0 +1,57 @@
1
+ import { type ChildProcess, type SpawnOptions } from 'node:child_process';
2
+ import type { ToolProcess } from './definition.js';
3
+ export interface ProcessRecord extends ToolProcess {
4
+ root: string;
5
+ ownerPid: number;
6
+ profileBinding: string;
7
+ phase?: string;
8
+ strongIdentity?: boolean;
9
+ processGroup?: number;
10
+ gated: boolean;
11
+ metadata?: Record<string, unknown>;
12
+ outcome?: string;
13
+ requestedStop?: 'stop' | 'kill';
14
+ launchError?: string;
15
+ }
16
+ export interface ProcessSpec {
17
+ tool: string;
18
+ role: string;
19
+ installation: string;
20
+ session?: string;
21
+ target?: string;
22
+ metadata?: Record<string, unknown>;
23
+ }
24
+ export interface TrackedChild extends ChildProcess {
25
+ toolProcessId: string;
26
+ toolClosed: Promise<void>;
27
+ }
28
+ export type OwnershipVerifier = (record: ProcessRecord) => Promise<boolean | undefined>;
29
+ export declare function launchProcess(directory: string, spec: ProcessSpec, executable: string, args: string[], options?: SpawnOptions, control?: {
30
+ id?: string;
31
+ finalize?: boolean;
32
+ onSpawn?: (child: TrackedChild) => void | Promise<void>;
33
+ signal?: AbortSignal;
34
+ }): Promise<TrackedChild>;
35
+ export declare function processStatus(directory: string, id: string, verify?: OwnershipVerifier): Promise<ProcessRecord>;
36
+ export declare function listProcesses(directory: string, filter?: {
37
+ tool?: string;
38
+ session?: string;
39
+ target?: string;
40
+ }, verify?: OwnershipVerifier): Promise<ProcessRecord[]>;
41
+ export declare function terminateProcess(directory: string, id: string, force: boolean, verify?: OwnershipVerifier, graceful?: (record: ProcessRecord) => Promise<void>): Promise<{
42
+ process: string;
43
+ state: string;
44
+ interrupted?: undefined;
45
+ tool?: undefined;
46
+ session?: undefined;
47
+ target?: undefined;
48
+ } | {
49
+ process: string;
50
+ state: string;
51
+ interrupted: boolean;
52
+ tool: string;
53
+ session: string | undefined;
54
+ target: string | undefined;
55
+ }>;
56
+ /** Migration/reconnection only: an adapter must authenticate a known existing tool before registration. */
57
+ export declare function registerExistingProcess(directory: string, spec: ProcessSpec, executable: string, pid: number, verify: OwnershipVerifier): Promise<string>;
@@ -0,0 +1,266 @@
1
+ import { spawn } from 'node:child_process';
2
+ import { access, mkdir, readdir } from 'node:fs/promises';
3
+ import { constants } from 'node:fs';
4
+ import { join, isAbsolute, resolve } from 'node:path';
5
+ import { fileURLToPath } from 'node:url';
6
+ import { randomUUID } from 'node:crypto';
7
+ import { setTimeout as delay } from 'node:timers/promises';
8
+ import { CliError } from '@eyeauras/cli-factory';
9
+ import { atomicWrite, readJson, toolRoot, withToolLock } from './store.js';
10
+ import { processIdentity } from './identity.js';
11
+ import { digest } from '../model.js';
12
+ const owned = new Map();
13
+ const ownedKey = (directory, id) => resolve(directory) + '\0' + id;
14
+ /** Receipts report pending lifetime only; they never authorize a signal to another PID. */
15
+ async function nativeChildren(record) {
16
+ if (record.metadata?.nativeChildDeadlines !== true)
17
+ return [];
18
+ let names;
19
+ try {
20
+ names = await readdir(join(record.root, 'native-deadlines'));
21
+ }
22
+ catch (e) {
23
+ if (e.code === 'ENOENT')
24
+ return [];
25
+ throw e;
26
+ }
27
+ if (names.length > 100)
28
+ throw new CliError('Native helper receipt count exceeds its bound.', { code: 'tool.process.unverified' });
29
+ return Promise.all(names.map(async (name) => {
30
+ const value = await readJson(join(record.root, 'native-deadlines', name));
31
+ if (!/^\d+\.json$/.test(name) || !value || value.protocol !== 1 || !Number.isSafeInteger(value.pid) || value.pid < 1 || value.pid > 2147483647 || name !== value.pid + '.json' || !Number.isSafeInteger(value.parentPid) || value.parentPid < 1 || !Number.isSafeInteger(value.birthSeconds) || value.birthSeconds < 1 || !Number.isSafeInteger(value.birthMicroseconds) || value.birthMicroseconds < 0 || value.birthMicroseconds >= 1000000 || !Number.isSafeInteger(value.deadlineUnixSeconds) || value.deadlineUnixSeconds <= 0)
32
+ throw new CliError('Native helper receipt is invalid; no cleanup was assumed.', { code: 'tool.process.unverified' });
33
+ const receiptDigest = digest(value), acknowledgment = join(record.root, 'native-deadline-exits', name), previous = await readJson(acknowledgment);
34
+ if (previous?.receiptDigest === receiptDigest)
35
+ return { ...value, state: 'exited' };
36
+ const identity = await processIdentity(value.pid), seconds = identity && process.platform === 'darwin' ? Date.parse(identity.birth + ' GMT') / 1000 : NaN;
37
+ // A different observable birth proves reuse, without granting permission to signal that PID.
38
+ const exited = !identity || Number.isFinite(seconds) && seconds !== value.birthSeconds;
39
+ if (exited)
40
+ await atomicWrite(acknowledgment, { receiptDigest, observedAt: new Date().toISOString() });
41
+ return { ...value, state: exited ? 'exited' : 'pending' };
42
+ }));
43
+ }
44
+ export async function launchProcess(directory, spec, executable, args, options = {}, control = {}) {
45
+ return withToolLock(directory, spec.tool, async () => {
46
+ control.signal?.throwIfAborted();
47
+ toolRoot(directory, spec.tool);
48
+ if (!isAbsolute(executable))
49
+ throw new CliError('Tool executable must be absolute.', { code: 'tool.configuration' });
50
+ const id = control.id ?? randomUUID();
51
+ if (!/^[a-f0-9-]{36}$/.test(id))
52
+ throw Error('Invalid process identity');
53
+ const root = join(directory, 'runtime/runs', id), path = join(directory, 'runtime/processes', id + '.json');
54
+ await mkdir(root, { recursive: true, mode: 0o700 });
55
+ const gated = process.platform !== 'win32' && typeof process.execve === 'function';
56
+ const record = { schema: 1, id, ...spec, state: 'starting', executable, root, ownerPid: process.pid, profileBinding: digest(resolve(directory)), gated, phase: 'reserved', createdAt: new Date().toISOString() };
57
+ await atomicWrite(path, record);
58
+ try {
59
+ control.signal?.throwIfAborted();
60
+ await access(executable, process.platform === 'win32' ? constants.F_OK : constants.X_OK);
61
+ }
62
+ catch (error) {
63
+ Object.assign(record, { state: 'failed', phase: 'preflight_failed' });
64
+ await atomicWrite(path, record);
65
+ throw error;
66
+ }
67
+ const environment = options.env ?? { PATH: process.env.PATH, HOME: root, TMPDIR: root };
68
+ const stdio = Array.isArray(options.stdio) ? [...options.stdio] : Array(3).fill(options.stdio ?? 'pipe'), fd = stdio.length, nonce = randomUUID();
69
+ if (gated)
70
+ stdio.push('pipe');
71
+ let child;
72
+ try {
73
+ child = spawn(gated ? process.execPath : executable, gated ? ['--no-warnings', fileURLToPath(new URL('./launch-worker.js', import.meta.url)), directory, id, String(fd)] : args, { cwd: root, ...options, stdio, windowsHide: true, env: gated ? { PATH: environment.PATH, HOME: root, TMPDIR: root } : environment });
74
+ }
75
+ catch (error) {
76
+ Object.assign(record, { state: 'failed', phase: 'spawn_failed' });
77
+ await atomicWrite(path, record);
78
+ throw error;
79
+ }
80
+ const closed = new Promise((ok, bad) => { child.on('error', error => { if (!child.pid)
81
+ bad(error); }); child.once('close', ok); });
82
+ void closed.catch(() => { });
83
+ const handle = { child, closed, record };
84
+ owned.set(ownedKey(directory, id), handle);
85
+ const finalized = control.finalize === false ? closed : closed.then(async () => {
86
+ const current = await readJson(path) ?? record;
87
+ if (current.state !== 'failed' && current.state !== 'unverified')
88
+ Object.assign(current, { state: 'exited', exitCode: child.exitCode, signal: child.signalCode, endedAt: new Date().toISOString(), outcome: current.requestedStop === 'kill' ? 'killed' : current.requestedStop === 'stop' ? 'stopped' : 'completed' });
89
+ await atomicWrite(path, current);
90
+ }, async () => { Object.assign(record, { state: 'failed', phase: 'spawn_failed' }); await atomicWrite(path, record); });
91
+ handle.closed = finalized.finally(() => { owned.delete(ownedKey(directory, id)); });
92
+ void handle.closed.catch(() => { });
93
+ Object.assign(child, { toolProcessId: id, toolClosed: handle.closed });
94
+ try {
95
+ await control.onSpawn?.(child);
96
+ if (!child.pid)
97
+ throw Error('Owned tool spawn did not obtain a PID');
98
+ if (gated) {
99
+ const channel = child.stdio[fd];
100
+ channel.on('error', () => { });
101
+ channel.end(JSON.stringify({ executable, arguments: args, environment: Object.fromEntries(Object.entries(environment).filter(([, v]) => v !== undefined)), nonce }));
102
+ let armed = false;
103
+ for (let i = 0; i < 400; i++) {
104
+ control.signal?.throwIfAborted();
105
+ const ready = await readJson(join(root, 'armed.json'));
106
+ if (ready && ready.pid === child.pid && ready.nonce === nonce) {
107
+ armed = true;
108
+ break;
109
+ }
110
+ if (child.exitCode !== null || child.signalCode !== null)
111
+ break;
112
+ await delay(25);
113
+ }
114
+ if (!armed)
115
+ throw Error('Owned launch did not become armed');
116
+ Object.assign(record, await readJson(path), { state: 'running', phase: 'exec_authorized' });
117
+ await atomicWrite(path, record);
118
+ await atomicWrite(join(root, 'go.json'), { nonce });
119
+ }
120
+ else {
121
+ if (!child.pid)
122
+ throw Error('No child process');
123
+ const identity = await processIdentity(child.pid);
124
+ Object.assign(record, { pid: child.pid, identity: identity?.birth, strongIdentity: identity?.strong, processGroup: identity?.group, state: 'running', phase: 'direct_child_only' });
125
+ await atomicWrite(path, record);
126
+ }
127
+ return child;
128
+ }
129
+ catch (error) {
130
+ if (child.exitCode === null && child.signalCode === null)
131
+ try {
132
+ child.kill('SIGKILL');
133
+ }
134
+ catch { }
135
+ await Promise.race([handle.closed.catch(() => { }), delay(2000)]);
136
+ Object.assign(record, { state: child.exitCode !== null || child.signalCode !== null ? 'failed' : 'unverified', phase: 'launch_failed' });
137
+ await atomicWrite(path, record);
138
+ throw error;
139
+ }
140
+ }, control.signal);
141
+ }
142
+ export async function processStatus(directory, id, verify) {
143
+ if (!/^[a-f0-9-]{36}$/.test(id))
144
+ throw new CliError('Invalid process identity.', { code: 'tool.process.invalid' });
145
+ const record = await readJson(join(directory, 'runtime/processes', id + '.json'));
146
+ if (!record || record.id !== id)
147
+ throw new CliError('Unknown tool process.', { code: 'tool.process.missing' });
148
+ if (record.root !== join(directory, 'runtime/runs', id) || record.profileBinding !== digest(resolve(directory)))
149
+ return { ...record, state: 'unverified', phase: 'profile_binding_changed' };
150
+ const finishing = owned.get(ownedKey(directory, id));
151
+ if (finishing && (finishing.child.exitCode !== null || finishing.child.signalCode !== null)) {
152
+ await finishing.closed;
153
+ return processStatus(directory, id, verify);
154
+ }
155
+ let children;
156
+ try {
157
+ children = await nativeChildren(record);
158
+ }
159
+ catch {
160
+ return { ...record, state: 'unverified', phase: 'native_children_unverified' };
161
+ }
162
+ const pending = children.some(c => c.state === 'pending');
163
+ const observed = { ...record, ...(children.length ? { nativeChildren: children } : {}) };
164
+ if (['exited', 'failed'].includes(record.state))
165
+ return pending ? { ...observed, state: 'unverified', phase: 'native_children_pending' } : observed;
166
+ if (!record.pid) {
167
+ try {
168
+ process.kill(record.ownerPid, 0);
169
+ return record;
170
+ }
171
+ catch {
172
+ return { ...record, state: record.gated ? 'failed' : 'unverified', phase: 'owner_lost_before_pid' };
173
+ }
174
+ }
175
+ const identity = await processIdentity(record.pid);
176
+ if (!identity)
177
+ return { ...observed, state: pending ? 'unverified' : 'exited', phase: pending ? 'native_children_pending' : 'observed_exit', outcome: 'unknown' };
178
+ if (identity.birth !== record.identity)
179
+ return { ...record, state: 'unverified', phase: 'pid_identity_changed' };
180
+ const current = owned.get(ownedKey(directory, id)), local = current?.child.pid === record.pid && current.record.identity === record.identity && current.child.exitCode === null && current.child.signalCode === null;
181
+ const proof = verify ? await verify(record) : undefined;
182
+ if (local || proof === true || proof === undefined && record.strongIdentity && identity.strong)
183
+ return { ...observed, state: 'running' };
184
+ return { ...observed, state: 'unverified', phase: 'tool_identity_required' };
185
+ }
186
+ export async function listProcesses(directory, filter = {}, verify) {
187
+ let names;
188
+ try {
189
+ names = await readdir(join(directory, 'runtime/processes'));
190
+ }
191
+ catch (e) {
192
+ if (e.code === 'ENOENT')
193
+ return [];
194
+ throw e;
195
+ }
196
+ const items = [];
197
+ for (const name of names) {
198
+ if (!/^[a-f0-9-]{36}\.json$/.test(name))
199
+ continue;
200
+ const record = await processStatus(directory, name.slice(0, -5), verify);
201
+ if (filter.tool && record.tool !== filter.tool || filter.session && record.session !== filter.session || filter.target && record.target !== filter.target)
202
+ continue;
203
+ items.push(record);
204
+ }
205
+ return items.sort((a, b) => b.createdAt.localeCompare(a.createdAt));
206
+ }
207
+ export async function terminateProcess(directory, id, force, verify, graceful) {
208
+ const path = join(directory, 'runtime/processes', id + '.json'), record = await processStatus(directory, id, verify);
209
+ if (['exited', 'failed'].includes(record.state))
210
+ return { process: id, state: 'already_exited' };
211
+ if (record.state !== 'running' || !record.pid)
212
+ throw new CliError('Process ownership is unverified; no signal was sent.', { code: 'tool.process.unverified' });
213
+ if (!force && graceful)
214
+ await graceful(record);
215
+ let current = await processStatus(directory, id, verify);
216
+ if (!['exited', 'failed'].includes(current.state)) {
217
+ if (current.state !== 'running' || current.pid !== record.pid)
218
+ throw new CliError('Process identity changed during stop.', { code: 'tool.process.unverified' });
219
+ current.requestedStop = force ? 'kill' : 'stop';
220
+ await atomicWrite(path, current);
221
+ const identity = await processIdentity(record.pid);
222
+ if (!identity || identity.birth !== record.identity)
223
+ throw new CliError('Process identity changed before signalling.', { code: 'tool.process.unverified' });
224
+ try {
225
+ if (process.platform !== 'win32' && record.processGroup === record.pid && identity.group === record.pid)
226
+ process.kill(-record.pid, force ? 'SIGKILL' : 'SIGTERM');
227
+ else
228
+ process.kill(record.pid, force ? 'SIGKILL' : 'SIGTERM');
229
+ }
230
+ catch (error) {
231
+ if (error.code !== 'ESRCH')
232
+ throw error;
233
+ }
234
+ for (let i = 0; i < 100; i++) {
235
+ if (!await processIdentity(record.pid))
236
+ break;
237
+ await delay(50);
238
+ }
239
+ if (await processIdentity(record.pid))
240
+ throw new CliError('Owned process did not stop; its record is retained.', { code: 'tool.process.busy' });
241
+ }
242
+ await owned.get(ownedKey(directory, id))?.closed;
243
+ current = { ...(await readJson(path) ?? record), state: 'exited', outcome: force ? 'killed' : 'stopped', endedAt: new Date().toISOString() };
244
+ await atomicWrite(path, current);
245
+ return { process: id, state: force ? 'killed' : 'stopped', interrupted: force, tool: record.tool, session: record.session, target: record.target };
246
+ }
247
+ /** Migration/reconnection only: an adapter must authenticate a known existing tool before registration. */
248
+ export async function registerExistingProcess(directory, spec, executable, pid, verify) {
249
+ toolRoot(directory, spec.tool);
250
+ const identity = await processIdentity(pid);
251
+ if (!identity)
252
+ throw new CliError('Existing tool process has exited.', { code: 'tool.process.missing' });
253
+ const hex = digest({ profile: resolve(directory), ...spec, pid, identity: identity.birth }).slice(0, 32), id = [hex.slice(0, 8), hex.slice(8, 12), hex.slice(12, 16), hex.slice(16, 20), hex.slice(20)].join('-');
254
+ const root = join(directory, 'runtime/runs', id), path = join(directory, 'runtime/processes', id + '.json');
255
+ const record = { schema: 1, id, ...spec, root, ownerPid: process.pid, profileBinding: digest(resolve(directory)), gated: false, state: 'running', phase: 'adopted_verified', createdAt: new Date().toISOString(), executable, pid, identity: identity.birth, strongIdentity: identity.strong, processGroup: identity.group };
256
+ if (!await verify(record))
257
+ throw new CliError('Existing process did not authenticate as the owned tool.', { code: 'tool.process.unverified' });
258
+ if ((await processIdentity(pid))?.birth !== identity.birth)
259
+ throw new CliError('Existing process identity changed during registration.', { code: 'tool.process.unverified' });
260
+ const previous = await readJson(path);
261
+ if (previous)
262
+ return id;
263
+ await mkdir(root, { recursive: true, mode: 0o700 });
264
+ await atomicWrite(path, record);
265
+ return id;
266
+ }
@@ -0,0 +1,22 @@
1
+ /** Stock Windows PowerShell loads the packaged first-party Job Object executor; no runtime compiler. */
2
+ export declare function windowsJobLaunch(root: string, nonce: string, executable: string, args: string[], cwd: string, timeoutMs: number, options?: {
3
+ observedSubject?: {
4
+ pid: number;
5
+ birth: string;
6
+ };
7
+ nativeMutex?: 'procmon';
8
+ nativeRegistry?: 'procmon';
9
+ }): Promise<{
10
+ executable: string;
11
+ arguments: string[];
12
+ }>;
13
+ export declare function windowsJobResult(root: string, nonce: string, launcherPid: number, registryExpected?: boolean): Promise<{
14
+ registryIsolated?: boolean | undefined;
15
+ schema: number;
16
+ nonce: string;
17
+ launcherPid: number;
18
+ phase: string;
19
+ childExitCode: number;
20
+ childPid: number;
21
+ childBirthTicks: string;
22
+ }>;
@@ -0,0 +1,43 @@
1
+ import { fileURLToPath } from 'node:url';
2
+ import { readFile } from 'node:fs/promises';
3
+ import { join, isAbsolute } from 'node:path';
4
+ import { CliError } from '@eyeauras/cli-factory';
5
+ import { fileSha256 } from './archives.js';
6
+ import { atomicWrite, readJson } from './store.js';
7
+ import { processIdentity } from './identity.js';
8
+ /** Stock Windows PowerShell loads the packaged first-party Job Object executor; no runtime compiler. */
9
+ export async function windowsJobLaunch(root, nonce, executable, args, cwd, timeoutMs, options = {}) {
10
+ if (process.platform !== 'win32' || !Number.isInteger(timeoutMs) || timeoutMs < 1000 || timeoutMs > 600000)
11
+ throw new CliError('Owned Windows job deadline must be 1–600 seconds.', { code: 'tool.configuration' });
12
+ const native = fileURLToPath(new URL('../../../runtime/native/windows-job/', import.meta.url));
13
+ const proof = await readJson(join(native, 'provenance.json'));
14
+ if (!proof || await fileSha256(join(native, 'Insight.WindowsJob.dll')) !== proof.sha256 || await fileSha256(join(native, 'windows-job.ps1')) !== proof.launcherSha256)
15
+ throw new CliError('Packaged Windows job differs from its reviewed build.', { code: 'tool.binding' });
16
+ const identity = await processIdentity(process.pid), system = process.env.SystemRoot ?? process.env.WINDIR;
17
+ if (!identity?.strong || !/^\d+$/.test(identity.birth) || !system || !isAbsolute(system))
18
+ throw new CliError('Windows owner birth identity or system directory is unavailable.', { code: 'tool.process.unverified' });
19
+ if (options.observedSubject && (!Number.isSafeInteger(options.observedSubject.pid) || options.observedSubject.pid < 1 || !/^\d+$/.test(options.observedSubject.birth)))
20
+ throw new CliError('Borrowed Windows subject identity is invalid.', { code: 'tool.process.unverified' });
21
+ let registry = {};
22
+ if (options.nativeRegistry) {
23
+ const registryShim = join(native, '../insight-registry-win-x64.dll'), proof = await readJson(join(native, '../windows-registry.provenance.json'));
24
+ if (!proof || await fileSha256(registryShim) !== proof.sha256)
25
+ throw new CliError('Private Windows registry helper is missing or differs from its reviewed build.', { code: 'tool.binding' });
26
+ registry = { registryShim, registryShimSha256: proof.sha256 };
27
+ }
28
+ const specification = join(root, 'job-specification.json');
29
+ await atomicWrite(specification, { schema: 1, nonce, executable, arguments: args, cwd, timeoutMs, ownerPid: process.pid, ownerBirthTicks: identity.birth, ...registry, ...(options.observedSubject ? { observedPid: options.observedSubject.pid, observedBirthTicks: options.observedSubject.birth } : {}), ...(options.nativeMutex ? { nativeMutex: 'Local\\insight-cli-procmon-capture' } : {}) });
30
+ return { executable: join(system, 'System32/WindowsPowerShell/v1.0/powershell.exe'), arguments: ['-NoProfile', '-NonInteractive', '-ExecutionPolicy', 'Bypass', '-File', join(native, 'windows-job.ps1'), '-Specification', specification] };
31
+ }
32
+ export async function windowsJobResult(root, nonce, launcherPid, registryExpected = false) {
33
+ const result = await readJson(join(root, 'job-result.json'));
34
+ const started = await readJson(join(root, 'job-started.json'));
35
+ if (!result || !started || result.schema !== 1 || started.schema !== 1 || result.nonce !== nonce || started.nonce !== nonce || result.launcherPid !== launcherPid || started.launcherPid !== launcherPid || !['completed', 'timeout', 'owner_lost'].includes(result.phase) || !Number.isSafeInteger(result.childExitCode) || result.childExitCode < 0 || result.childExitCode > 0xffffffff || !Number.isSafeInteger(result.childPid) || result.childPid < 1 || result.childPid !== started.childPid || !/^\d+$/.test(result.childBirthTicks) || result.childBirthTicks !== started.childBirthTicks || started.phase !== 'assigned_suspended')
36
+ throw new CliError('Owned Windows job result is missing or unverified; no successful outcome was assumed.', { code: 'tool.process.unverified' });
37
+ if (registryExpected) {
38
+ const proof = await readFile(join(root, 'registry-isolated.bin'));
39
+ if (proof.length !== 48 || proof.readUInt32LE(0) !== 0x49484b31 || proof.readUInt32LE(4) !== result.childPid || proof.readUInt32LE(8) !== 0 || proof.subarray(12).toString('ascii') !== nonce)
40
+ throw new CliError('Private Windows registry initialization is unverified.', { code: 'tool.process.unverified' });
41
+ }
42
+ return { ...result, ...(registryExpected ? { registryIsolated: true } : {}) };
43
+ }