Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
519ebaa
feat(diagnostics): report a byte entropy profile for one local file
mvanhorn Oct 12, 2026
b82e190
fix(diagnostics): flag zero-size files as not shown empty
mvanhorn Oct 13, 2026
b87f511
fix(diagnostics): merge main and preserve entropy boundary failures
morluto Oct 13, 2026
7a67707
fix(mcp): reject unsupported diagnostic summaries before inspection
morluto Oct 13, 2026
eccc741
Merge remote-tracking branch 'origin/main' into fix/byte-entropy-profile
morluto Oct 13, 2026
a156b1d
fix(ci): repair integrated checks and Hopper test baseline
morluto Oct 13, 2026
a2f6136
test(entropy): use shared MCP schema verification after merge
morluto Oct 13, 2026
4df3682
chore: merge current main into PR #2331
morluto Oct 13, 2026
f54b2ae
Merge branch 'main' into fix/byte-entropy-profile
morluto Oct 13, 2026
3a794e9
Merge branch 'main' into fix/byte-entropy-profile
mvanhorn Oct 14, 2026
27c6fd9
fix(catalog): list inspect_byte_entropy under its own provider
mvanhorn Oct 15, 2026
f7367fc
fix(cli): resolve the byte-entropy path with absoluteCallerPath
mvanhorn Oct 19, 2026
4e6600d
Merge remote-tracking branch 'upstream/main' into fix/byte-entropy-pr…
mvanhorn Oct 19, 2026
e3e5891
Merge origin/main into fix/byte-entropy-profile
kaoru0822-kitauji Oct 21, 2026
1eef8d6
fix(diagnostics): retain entropy read cleanup ownership
morluto Oct 21, 2026
da99090
docs(diagnostics): explain entropy output capacity
morluto Oct 21, 2026
9be3d92
fix(diagnostics): preserve entropy cancellation outcomes
morluto Oct 21, 2026
cc585b5
fix(diagnostics): close the entropy input and warn on large reports
cursoragent Oct 21, 2026
2489602
fix(diagnostics): keep byte-entropy registration mergeable with main
cursoragent Oct 22, 2026
9d37354
fix(diagnostics): register byte entropy with the shared tool options
cursoragent Oct 22, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix(diagnostics): merge main and preserve entropy boundary failures
  • Loading branch information
morluto committed Oct 13, 2026
commit b87f51184c6898e00552ca5c61ad1007e58d0020
54 changes: 50 additions & 4 deletions src/application/binaryDiagnostics/ByteEntropyService.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createHash } from "node:crypto";
import { writeFile } from "node:fs/promises";
import { open, stat, rename, writeFile } from "node:fs/promises";
import { join } from "node:path";
import { expect, it } from "vitest";
import { expect, it, vi } from "vitest";
import { createTestTempDirectory } from "../../../tests/fixtures/temporaryDirectory.js";
import { byteEntropySchema } from "../../domain/native/byteEntropy.js";
import { ByteEntropyService } from "./ByteEntropyService.js";
Expand Down Expand Up @@ -102,13 +102,59 @@ it("honors cancellation before and during streaming", async () => {
await service.inspect({ path }, { signal: AbortSignal.abort() }),
).toMatchObject({ ok: false, error: { _tag: "AnalysisCancelledError" } });
const controller = new AbortController();
const pending = service.inspect(
let reads = 0;
const streaming = new ByteEntropyService({
stat,
open: async (...args) => {
const file = await open(...args);
const read = file.read.bind(file);
vi.spyOn(file, "read").mockImplementation(async (...readArgs) => {
const result = await read(...readArgs);
reads += 1;
controller.abort();
return result;
});
return file;
},
});
const pending = streaming.inspect(
{ path, block_size: 256 },
{ signal: controller.signal },
);
setTimeout(() => controller.abort(), 5);
expect(await pending).toMatchObject({
ok: false,
error: { _tag: "AnalysisCancelledError" },
});
expect(reads).toBe(1);
});

it("reports a changed artifact when its parent directory moves during streaming", async () => {
const root = await createTestTempDirectory("rea-entropy-moved-");
const path = join(root, "bytes");
await writeFile(path, Buffer.alloc(512));
let moved = false;
const service = new ByteEntropyService({
stat,
open: async (...args) => {
const file = await open(...args);
const read = file.read.bind(file);
vi.spyOn(file, "read").mockImplementation(async (...readArgs) => {
const result = await read(...readArgs);
if (!moved) {
moved = true;
await rename(root, `${root}-moved`);
}
return result;
});
return file;
},
});
try {
expect(await service.inspect({ path, block_size: 256 })).toMatchObject({
ok: false,
error: { _tag: "AnalysisArtifactChangedError" },
});
} finally {
if (moved) await rename(`${root}-moved`, root);
}
});
Comment thread
morluto marked this conversation as resolved.
Resolved
26 changes: 22 additions & 4 deletions src/application/binaryDiagnostics/ByteEntropyService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ const invalid = (field: string, message: string) =>

/** Offline byte observations shared by CLI and MCP, with one file-wide read. */
export class ByteEntropyService {
constructor(
private readonly files: Pick<
typeof import("node:fs/promises"),
"open" | "stat"
> = { open, stat },
) {}

async inspect(
rawInput: unknown,
options?: ExecutionOptions,
Expand All @@ -52,10 +59,12 @@ export class ByteEntropyService {
return err(
invalid("path", "Expected an absolute filesystem path on this host."),
);
let admitted = false;
try {
const before = await stat(input.path, { bigint: true });
const before = await this.files.stat(input.path, { bigint: true });
if (!before.isFile()) throw invalid("path", "Expected a regular file.");
const file = await open(
admitted = true;
const file = await this.files.open(
input.path,
constants.O_RDONLY | constants.O_NONBLOCK,
);
Expand Down Expand Up @@ -125,7 +134,7 @@ export class ByteEntropyService {
}
if (
!same(await file.stat({ bigint: true })) ||
!same(await stat(input.path, { bigint: true }))
!same(await this.files.stat(input.path, { bigint: true }))
)
throw changed();
options?.signal?.throwIfAborted();
Expand Down Expand Up @@ -186,7 +195,16 @@ export class ByteEntropyService {
}),
);
if (cause.code === "ENOENT" || cause.code === "ENOTDIR")
return err(invalid("path", "Selected file could not be found."));
return err(
admitted
? new AnalysisArtifactChangedError(
OPERATION,
input.path,
"Selected file path changed during entropy inspection.",
{ cause },
)
: invalid("path", "Selected file could not be found."),
);
}
return err(
new AnalysisOutputError(
Expand Down
1 change: 0 additions & 1 deletion src/cli/binaryDiagnosticsCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ export const registerBinaryDiagnosticsCommands = (
}),
),
});
const pe = createPeResourcesService();
cli.command(CLI_COMMANDS.inspectPeResources, {
description:
"Inspect PE resource identities, payload ranges, hashes and icon-group relationships",
Expand Down
3 changes: 2 additions & 1 deletion src/server/registerBinaryDiagnosticsTools.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { output } from "zod";
import type { ByteEntropyService } from "../application/binaryDiagnostics/ByteEntropyService.js";
import type { EvidenceMcpServer } from "./EvidenceMcpServer.js";

Expand Down Expand Up @@ -30,7 +31,7 @@ export const registerBinaryDiagnosticsTools = (
{
detail,
...request
}: { detail: "complete" | "summary"; [key: string]: unknown },
}: output<typeof layout.inputSchema> | output<typeof entropy.inputSchema>,
signal: AbortSignal,
) =>
runAdmittedToolOperation(
Expand Down
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.