feat(signals): discover installed decoders and option help (#2487)

* feat(signals): discover installed decoders and selected option help

* fix(signals): bound retained discovery data and preserve resource failures

* fix(signals): complete CLI help and portable decoder patterns

* test(signals): verify case-insensitive decoder help queries

* fix(signals): retain discovery operation across cleanup retries
This commit is contained in:
Olorin
2026-10-13 15:58:19 +09:00
committed by GitHub
parent 9c34c091b3
commit 4276aaf18b
18 changed files with 945 additions and 173 deletions
+69 -26
View File
@@ -1,3 +1,4 @@
import { inspectSignalDecodersInputSchema } from "../domain/signals/signalDecoders.js";
import { z } from "incur";
import type { SignalRecordingService } from "../application/signals/SignalRecordingService.js";
import { AnalysisError } from "../domain/analysisErrorBase.js";
@@ -22,9 +23,75 @@ export const registerSignalCommands = (
environment: Readonly<NodeJS.ProcessEnv>,
service: Pick<
SignalRecordingService,
"decode" | "close"
"decode" | "inspectDecoders" | "close"
> = createSignalRecordingService(environment),
): void => {
const finish = async (
result: Awaited<ReturnType<SignalRecordingService["decode"]>>,
operation: string,
) => {
// A one-shot command must retry retained cleanup before discarding its owner.
try {
await service.close();
} catch (cause) {
const cleanup =
cause instanceof AnalysisError
? cause
: new ProviderCleanupError(
"sigrok-recording",
[],
{ reason: String(cause) },
{ cause, operation: operation },
);
if (result.ok) cleanup.retainPartialObservation(result.value);
return projectAnalysisError(
result.ok
? cleanup
: analysisErrorWithCleanupFailure(result.error, cleanup, operation),
);
}
return result.ok ? result.value : projectAnalysisError(result.error);
};
cli.command(CLI_COMMANDS.inspectSignalDecoders, {
description: "Search installed sigrok decoders or selected decoder help",
options: z
.object({
...inspectSignalDecodersInputSchema.shape,
limit: z
.number()
.int()
.positive()
.max(Number.MAX_SAFE_INTEGER)
.optional()
.describe(
"Maximum matching decoders or help lines to return; defaults to 50",
),
all: z
.boolean()
.default(false)
.describe("Return all remaining matches"),
})
.superRefine((options, context) => {
if (options.all && options.limit !== undefined)
context.addIssue({
code: "custom",
path: ["all"],
message: "all and limit are mutually exclusive",
});
}),
run: ({ options: { all, ...options } }) =>
withCommandCancellation((signal) =>
logCliCommand(logger, CLI_COMMANDS.inspectSignalDecoders, async () =>
finish(
await service.inspectDecoders(
{ ...options, ...(all ? { limit: null } : {}) },
{ signal },
),
"inspect_signal_decoders",
),
),
),
});
cli.command(CLI_COMMANDS.decodeSignalRecording, {
description:
"Decode an existing signal recording with caller-supplied sigrok",
@@ -68,31 +135,7 @@ export const registerSignalCommands = (
},
{ signal },
);
// A one-shot command must retry retained cleanup before discarding its owner.
try {
await service.close();
} catch (cause) {
const cleanup =
cause instanceof AnalysisError
? cause
: new ProviderCleanupError(
"sigrok-recording",
[],
{ reason: String(cause) },
{ cause, operation: "decode_signal_recording" },
);
if (result.ok) cleanup.retainPartialObservation(result.value);
return projectAnalysisError(
result.ok
? cleanup
: analysisErrorWithCleanupFailure(
result.error,
cleanup,
"decode_signal_recording",
),
);
}
return result.ok ? result.value : projectAnalysisError(result.error);
return finish(result, "decode_signal_recording");
}),
),
});