Files
frameledger/src/FrameLedger.CaptureHost/Capture/NgxDriverProbe.cs
T
poli0981andClaude Fable 5.1 97fc9d9707 refactor(capture): promote the capture path into Application and Infrastructure -- CaptureSession over ports, the CaptureHost a thin shell (P2 PR-C) (#147)
A pure move. CaptureLoop -- every hooked session's driver since 2026-08-06
-- is now Application.Capture.CaptureSession, over ports instead of
delegates so the Agent's composition root can supply the adapters:
IRingAttacher, ITargetLivenessSource, ITargetResolver, IProcessLauncher,
IRuntimeModuleSnapshot, INgxDriverProbe, IExecutableMarkerScan. ICaptureSink,
CaptureOptions, CaptureOutcome (was CaptureResult), SessionEndReason,
SessionEndClassifier, FocusTally, RuntimeModuleSet/Info, CensusNames,
SlTagCensusNames, ExecutableMarkers/Marker, NgxDriverState/NgxOverrideFlags/
NgxProbeOutcome move beside it.

Infrastructure.Capture holds the OS adapters: ShmRingAttacher + ShmCaptureSink
over ShmRingReader (no interface, no second consumer), HeldProcessLivenessSource
+ ProcessTargetLiveness (§S29(e)), TargetResolver (path only, never a pid; its
one report line through a callback, not the host's console) + ChromiumGpuProcess,
ProcessLauncher (an instance over the Vulkan layer's environment; the duplicated
enable-variable constant is gone), RuntimeModuleSnapshot, ExecutableMarkerScan.
DrainResult moves to Shared so Application can read it.

Report text stays with the report (NgxDriverStateText, ExecutableMarkersText);
NgxDriverProbe stays in the host until PR-E2 puts it in-process. The loop's
tests move with it -- CaptureSessionTests / CaptureSessionLaunchTests in
Application.Tests, driven through the real SQLite consent adapter (a test
project on Domain's InternalsVisibleTo would be a second mint) -- and the
report fixtures are byte-identical. Two new pins: HookRequestSoleProducerTests
(no public constructor, no setter, exactly one factory) and
NoSecondRingReaderTests (nothing but ShmRingReader opens the ring).

04_CAPTURE §Frame source abstraction now describes what exists (IFrameSource
never did) and gains §Threading model; §S27 restated a second time (the loop
ships; the entry point is PR-F's); CLAUDE.md §Solution layout. Hook-path
overhead: none (managed only).

Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-09 19:02:43 +00:00

70 lines
2.7 KiB
C#

using System.ComponentModel;
using System.Diagnostics;
using FrameLedger.Application.Capture;
namespace FrameLedger.CaptureHost.Capture;
/// <summary>
/// Runs <c>fl-probe-nvapi --ngx-state &lt;pid&gt;</c> beside this host and parses its machine line.
/// </summary>
/// <remarks>
/// <para>
/// <b>Out of process, on purpose.</b> The probe links <c>nvapi64.lib</c> (MIT, vendored) and asks the driver about
/// a pid; nothing is injected, nothing in the target is touched, no consent is involved. Spawning the tool this
/// repo already builds keeps the native layer reachable only through what is already there (CLAUDE.md: no
/// P/Invoke outside <c>Infrastructure</c>) — the day the shipped Agent wants this fact, it goes through
/// <c>Infrastructure</c> as a native call, not through a child process.
/// </para>
/// <para>
/// The probe is staged beside the host by the project file the way the Overlay payload is; a missing binary is
/// an outcome the report prints, never an exception the loop sees.
/// </para>
/// </remarks>
internal sealed class NgxDriverProbe : INgxDriverProbe
{
private const string _probeFileName = "fl-probe-nvapi.exe";
private static readonly TimeSpan _budget = TimeSpan.FromSeconds(5);
public static string ProbePath => Path.Combine(AppContext.BaseDirectory, _probeFileName);
/// <inheritdoc />
NgxDriverState INgxDriverProbe.Run(int pid) => Run(pid);
public static NgxDriverState Run(int pid) => Run(pid, ProbePath);
public static NgxDriverState Run(int pid, string probePath)
{
if (!File.Exists(probePath))
{
return NgxDriverState.Of(NgxProbeOutcome.ProbeMissing, probePath);
}
try
{
using var probe = new Process();
probe.StartInfo = new ProcessStartInfo(probePath)
{
UseShellExecute = false,
RedirectStandardOutput = true,
CreateNoWindow = true,
};
probe.StartInfo.ArgumentList.Add("--ngx-state");
probe.StartInfo.ArgumentList.Add(pid.ToString(System.Globalization.CultureInfo.InvariantCulture));
probe.Start();
string output = probe.StandardOutput.ReadToEnd();
if (!probe.WaitForExit((int)_budget.TotalMilliseconds))
{
probe.Kill();
return NgxDriverState.Of(NgxProbeOutcome.ProbeFailed, "the probe did not exit within " + _budget.TotalSeconds + " s");
}
return NgxDriverState.Parse(output);
}
catch (Exception e) when (e is Win32Exception or InvalidOperationException or IOException)
{
return NgxDriverState.Of(NgxProbeOutcome.ProbeFailed, e.Message);
}
}
}