mirror of
https://github.com/morluto/rea.git
synced 2026-12-07 01:14:28 +08:00
* feat(windows): add read-only process sampling probe to Windows native addon Add process_sample_snapshot to the bundled Windows x64 addon and advertise inspection.processSample. Verifies live MEM_IMAGE backing-file identity and process creation time before reading GetProcessMemoryInfo, GetProcessTimes, GetProcessHandleCount, GetGuiResources, Toolhelp thread snapshots with GetThreadTimes/GetThreadDescription, and EnumProcessModulesEx metadata. Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com> * feat(native): add sample_windows_process tool and native-windows provider Expose read-only sample_windows_process bound to the active PE target via a dedicated native-windows auxiliary provider, with interval sampling, memory and thread-pool settle summaries, per-thread CPU deltas keyed by TID and creation time, system vs third-party module classification and load/unload diffs, and partial observation preservation on cancellation or process exit. Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com> * test(native): add Windows process sampling tests, schema summary, and docs Add unit, MCP boundary, provider lifecycle, and CLI/MCP Evidence parity coverage for sample_windows_process, update the advertised schema summary, and document Windows read-only process sampling in the native investigation guide. Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com> * fix(native-windows): run process sampling in owned worker and harden probes Address all round-1 review findings for sample_windows_process: - Verify GetProcessIdOfThread(handle) == pid after OpenThread before reading thread times or descriptions. - Run process_sample_snapshot probes inside a reusable Job-Object-owned NDJSON worker process so caller cancellation terminates even stalled backing-file reads, with pending cleanup retention and retry on NativeWindowsProvider. - Collect trailing module inventories via a separate finalModuleObservation probe without overwriting collected interval samples, and apply full error/cancellation handling on that probe. - Keep initial/final counter and CPU summaries strict to sample 0 and the last sample (null when an endpoint reading is missing). - Grow K32GetModuleFileNameExW up to 32768 chars, keep module path/size nullable on failure with explicit gaps, verify ERROR_NO_MORE_FILES on Toolhelp thread enumeration, and emit structured process_exited state. - Deduplicate native/windows/src/ui.cc onto process_identity.hpp, move addon wire schemas into the adapter, and report output-budget refusals via parseLimitConstraint + fixedNativeAllowance. Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com> * fix(native-windows): close worker on error, keep cleanup cancellation, and bound module diffs Address Greptile round-2 review findings: - Close readline/stdin and exit with code 1 on fatal worker errors so sampling never hangs on open stdin; constrain pid input schema to valid Windows DWORD range (1..4294967295). - Check caller AbortSignal after awaited runtime cleanup in both NativeWindowsProvider and direct sampleWindowsProcess so late cancellation remains observable with retained partialObservation. - Anchor duration_ms after the initial observation completes and mark single-sample positive-duration runs as partial. - Omit loaded_during_sampling when initial module inventory is truncated or has unreadable paths, omit unloaded_during_sampling when final module inventory is truncated or has unreadable paths, and mark modulesTruncated when unreadable modules are skipped. Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com> --------- Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
44 lines
1.2 KiB
JavaScript
44 lines
1.2 KiB
JavaScript
import { createRequire } from "node:module";
|
|
import { createInterface } from "node:readline";
|
|
|
|
const require = createRequire(import.meta.url);
|
|
let loadedPath;
|
|
let addon;
|
|
|
|
const run = async () => {
|
|
const lines = createInterface({
|
|
input: process.stdin,
|
|
crlfDelay: Infinity,
|
|
});
|
|
try {
|
|
for await (const line of lines) {
|
|
if (line.length === 0) continue;
|
|
const payload = JSON.parse(line);
|
|
const { addonPath, request } = payload;
|
|
if (addon === undefined) {
|
|
addon = require(addonPath);
|
|
loadedPath = addonPath;
|
|
} else if (loadedPath !== addonPath) {
|
|
throw new Error("Worker received a mismatched native addon path");
|
|
}
|
|
const result = await addon.call("process_sample_snapshot", [request]);
|
|
await new Promise((resolve, reject) => {
|
|
process.stdout.write(`${JSON.stringify(result)}\n`, (err) => {
|
|
if (err) reject(err);
|
|
else resolve();
|
|
});
|
|
});
|
|
}
|
|
} finally {
|
|
lines.close();
|
|
process.stdin.destroy();
|
|
}
|
|
};
|
|
|
|
run().catch((cause) => {
|
|
const message = cause instanceof Error ? cause.message : String(cause);
|
|
process.stderr.write(`${message}\n`, () => {
|
|
process.exit(1);
|
|
});
|
|
});
|