Reverse engineer anything with agents, from app behavior down to native binaries.
TypeScript agent-skillsai-agentsbinary-analysisclaude-codeclicodexcordisdecompilerdeveloper-toolsdshdsh-pluginghidrahopperllmmcpmodel-context-protocolreareverse-engineeringstatic-analysistouhou
fix(sigrok): retain recording suffix for autodetection
morlutoea579ebfaee0
diff --git a/docs/signal-recordings.md b/docs/signal-recordings.mdindex 298d7be54..9fd45b738 100644--- a/docs/signal-recordings.md+++ b/docs/signal-recordings.md@@ -31,7 +31,10 @@ The corresponding MCP request is:`decoders` uses sigrok's decoder stack and option/channel syntax. Channel namesmust match the recording; REA does not guess wiring, baud rate or protocol.-Omitting `input_format` requests sigrok's autodetection. Omitting `annotations`+Omitting `input_format` requests sigrok's autodetection. REA uses an immutable+private copy whose filename retains the selected recording's final suffix, so+filename-based format detection receives that hint without exposing the+caller's directory to sigrok. Omitting `annotations`retains every annotation class. Both omitted selections are recorded as null.See the [upstream manual](https://sigrok.org/wiki/Sigrok-cli) for formats,decoder stacking and annotation selectors. No arbitrary command flags are accepted.diff --git a/src/signals/SigrokRecordingProvider.ts b/src/signals/SigrokRecordingProvider.tsindex 4d75acae6..b5e978b27 100644--- a/src/signals/SigrokRecordingProvider.ts+++ b/src/signals/SigrokRecordingProvider.ts@@ -20,7 +20,7 @@ import {import { randomUUID } from "node:crypto";import { constants } from "node:fs";import { access, realpath, writeFile } from "node:fs/promises";-import { isAbsolute, join } from "node:path";+import { extname, isAbsolute, join } from "node:path";import {createAnalysisExecution,type AnalysisExecution,@@ -177,7 +177,11 @@ export class SigrokRecordingProvider implements SignalRecordingPort {phase = "workspace";root = await this.createRuntime();this.#resources.retain(root, undefined);- const snapshotPath = join(root.path, "recording");+ // Keep the selected file's suffix as private parser metadata. sigrok's+ // autodetection receives a filename, not just the copied bytes.+ const snapshotName =+ "path" in input ? `recording${extname(input.path)}` : "recording";+ const snapshotPath = join(root.path, snapshotName);const execute = async (args: readonly string[],// Caller selectors this command loads; their refusals are input errors.@@ -327,7 +331,7 @@ export class SigrokRecordingProvider implements SignalRecordingPort {phase = "producer";const args = ["--dont-scan",- "--input-file=recording",+ `--input-file=${snapshotName}`,`--protocol-decoders=${input.decoders}`,"--protocol-decoder-samplenum",...(input.input_format === nulldiff --git a/tests/boundary/signals/recordingProvider.test.ts b/tests/boundary/signals/recordingProvider.test.tsindex 7f4fc5541..b94dfc34f 100644--- a/tests/boundary/signals/recordingProvider.test.ts+++ b/tests/boundary/signals/recordingProvider.test.ts@@ -4,7 +4,7 @@ import { projectAnalysisError } from "../../../src/domain/analysisErrorProjectioimport { OwnedCommandFailure } from "../../../src/process/OwnedCommand.js";import { it, expect, onTestFinished } from "vitest";import { writeFile, readdir, chmod, symlink } from "node:fs/promises";-import { join } from "node:path";+import { extname, join } from "node:path";import { readStableArtifact } from "../../../src/artifacts/readStableArtifact.js";import { SigrokRecordingProvider } from "../../../src/signals/SigrokRecordingProvider.js";import { SignalRecordingService } from "../../../src/application/signals/SignalRecordingService.js";@@ -26,8 +26,15 @@ import { silentLogger } from "../../../src/logger.js";// A command-boundary simulator: real process ownership/filesystem, not real sigrok coverage.const fixture = async (mode = "ok", failCleanup = false) => {const directory = await createTestTempDirectory("rea-signal-test-");- const path = join(directory, "recorded bytes.vcd");- await writeFile(path, "recording bytes");+ const path = join(+ directory,+ mode === "csv-autodetect" ? "capture.csv" : "recorded bytes.vcd",+ );+ const snapshotName = `recording${extname(path)}`;+ await writeFile(+ path,+ mode === "csv-autodetect" ? "CLK,MOSI\n0,0\n1,0\n" : "recording bytes",+ );const script = join(directory, "producer.mjs");await writeFile(script,@@ -38,15 +45,16 @@ else if (${JSON.stringify(mode)} === 'nonzero') { console.error('invalid decoderelse if (${JSON.stringify(mode)} === 'unknown-decoder') { console.error("srd: ModuleNotFoundError: Failed to load decoder nosuchdecoder: import by name failed: No module named 'nosuchdecoder'\\nFailed to load protocol decoder nosuchdecoder."); process.exitCode = 1; }else if (${JSON.stringify(mode)} === 'broken-decoder') { console.error("srd: ModuleNotFoundError: Failed to load decoder uart: import by name failed: No module named 'serial'\\nFailed to load protocol decoder uart."); process.exitCode = 1; }else if (${JSON.stringify(mode)} === 'unknown-annotation') { console.error("Annotation 'nosuchclass' not found for protocol decoder 'uart'."); process.exitCode = 1; }-else if (${JSON.stringify(mode)} === 'malformed-copy') { chmodSync('recording', 0o600); writeFileSync('recording', 'changed'); }-else if (${JSON.stringify(mode)} === 'oversized-copy') { chmodSync('recording', 0o600); truncateSync('recording', 32 * 1024 * 1024 + 1); }+else if (${JSON.stringify(mode)} === 'malformed-copy') { chmodSync(${JSON.stringify(snapshotName)}, 0o600); writeFileSync(${JSON.stringify(snapshotName)}, 'changed'); }+else if (${JSON.stringify(mode)} === 'oversized-copy') { chmodSync(${JSON.stringify(snapshotName)}, 0o600); truncateSync(${JSON.stringify(snapshotName)}, 32 * 1024 * 1024 + 1); }else if (${JSON.stringify(mode)} === 'line-budget') process.stdout.write('ID: uart' + '\\n'.repeat(65536));else if (${JSON.stringify(mode)} === 'overflow') process.stdout.write('x'.repeat(5 * 1024 * 1024));else if (${JSON.stringify(mode)} === 'wait') { console.log('ready'); setInterval(() => {}, 1000); }else if (${JSON.stringify(mode)} === 'many') process.stdout.write(Array.from({length:90},(_,i)=>'line '+(i+1)+'\\r\\n').join(''));else if (process.argv.includes('--list-supported')) { console.log('Supported hardware drivers:\\n ignored Device\\nSupported protocol decoders:\\n uart Universal Asynchronous Receiver/Transmitter\\n i2c Inter-Integrated Circuit\\n'); console.error('catalog warning'); }else if (process.argv.includes('--show')) console.log('ID: uart\\nOptions:\\n- baudrate: Baud rate (default 115200)\\n- parity: Parity');-else { if(readFileSync('recording', 'utf8') !== 'recording bytes') throw Error('wrong copy'); console.log('10-20 uart-1: 42'); console.error('producer warning'); }+else if (${JSON.stringify(mode)} === 'csv-autodetect') { if (!process.argv.includes('--input-file=recording.csv') || readFileSync(${JSON.stringify(snapshotName)}, 'utf8') !== 'CLK,MOSI\\n0,0\\n1,0\\n') throw Error('CSV suffix or copy bytes lost'); console.log('10-20 spi-1: 1'); }+else { if(readFileSync(${JSON.stringify(snapshotName)}, 'utf8') !== 'recording bytes') throw Error('wrong copy'); console.log('10-20 uart-1: 42'); console.error('producer warning'); }`,);await chmod(script, 0o700);@@ -104,7 +112,7 @@ else { if(readFileSync('recording', 'utf8') !== 'recording bytes') throw Error('await release.promise;}if (mode === "snapshot-write-failure")- await writeFile(join(root.path, "recording"), "already exists");+ await writeFile(join(root.path, snapshotName), "already exists");return {path: root.path,close: async () => {@@ -180,7 +188,7 @@ it("pages literal output without changing decoder arguments or normalizing text"expect(report.output_window.returned_lines).toBe(count);expect(report.tool.arguments).toEqual(["--dont-scan",- "--input-file=recording",+ "--input-file=recording.vcd","--protocol-decoders=uart","--protocol-decoder-samplenum",]);@@ -223,7 +231,7 @@ it("decodes an immutable copy, preserves options and warnings, and releases itsexpect(report.selection.input_format).toBeNull();expect(report.tool.arguments).toEqual(["--dont-scan",- "--input-file=recording",+ "--input-file=recording.vcd","--protocol-decoders=uart:rx=RX:baudrate=9600","--protocol-decoder-samplenum","--protocol-decoder-annotations=uart=rx-data",@@ -234,6 +242,26 @@ it("decodes an immutable copy, preserves options and warnings, and releases its]);});+it("preserves a CSV filename hint through the private autodetection copy", async () => {+ const f = await fixture("csv-autodetect");+ const result = await f.service.decode({+ path: f.path,+ decoders: "spi:clk=CLK:mosi=MOSI",+ });+ if (!result.ok) throw result.error;+ const report = signalRecordingSchema.parse(result.value.normalized_result);+ expect(report.selection).toMatchObject({+ path: f.path,+ input_format: null,+ });+ expect(report.tool.arguments).toEqual([+ "--dont-scan",+ "--input-file=recording.csv",+ "--protocol-decoders=spi:clk=CLK:mosi=MOSI",+ "--protocol-decoder-samplenum",+ ]);+});+it.each([["nonzero", "ProviderAdapterError"],["malformed-copy", "AnalysisArtifactChangedError"],@@ -590,7 +618,7 @@ it.each(["oversized-copy", "oversized-tool"])(path:mode === "oversized-tool"? join(f.directory, "producer.mjs")- : expect.stringMatching(/decoder-.*[/\\]recording$/u),+ : expect.stringMatching(/decoder-.*[/\\]recording\.vcd$/u),});expect((await readdir(f.directory)).filter((name) =>