mirror of
https://github.com/morluto/rea.git
synced 2026-11-16 11:43:20 +00:00
refactor(cli)!: name a failure's per-call control flag at the CLI boundary (#11413)
* refactor(cli)!: name a failure's per-call control flag at the CLI boundary Services name the contract field a deadline failure reports in details.limit.parameter; a contract command's output projection adds details.limit.cli_flag from the command's own field-to-flag binding. BREAKING CHANGE: MCP failures no longer carry details.limit.cli_flag, and native deadline remediation text no longer names the CLI flag. CLI output still reports cli_flag for the command that ran. * fix(cli): key nested flattened members by their dotted path; restore the test's exit status * refactor(reverse): bind command_timeout_ms as the per-call control of an objdump or Rizin deadline (#11442) * refactor(reverse): bind command_timeout_ms as the per-call control of an objdump or Rizin deadline The deadline failure now comes from nativeDeadlineRecovery: it names command_timeout_ms and carries limit {control_kind: "parameter"}, so the CLI projection adds --command-timeout-ms and MCP output names the field only. The service no longer writes CLI flag text. * refactor(wasm): bind max_artifact_paths as the per-call control of an auxiliary path admission refusal (#11444)
This commit is contained in:
1 parent
23eee86bd5
commit
49d4991a18
18 files changed
+321
-45
No files matched your search
@@ -686,11 +686,14 @@ export interface ContractCliDescription {
|
||||
readonly evidenceTargets: ContractCliEvidenceTargets | undefined;
|
||||
/**
|
||||
* Contract fields the CLI spells differently, so input issues reported
|
||||
* after argv parsing can name the CLI key.
|
||||
* after argv parsing can name the CLI key, and the flag of each contract
|
||||
* field (or `field.member`) the command takes as an option, so a failure
|
||||
* that names a per-call control can name the flag that sets it.
|
||||
*/
|
||||
readonly inputBinding: {
|
||||
readonly operation: string;
|
||||
readonly fields: Readonly<Record<string, string>>;
|
||||
readonly flags: Readonly<Record<string, string>>;
|
||||
};
|
||||
/** The command adds `--detail` and `--evidence_output`. */
|
||||
readonly evidenceDelivery: boolean;
|
||||
@@ -2406,6 +2409,18 @@ export const describeContractCommand = <
|
||||
...(evidenceTargets?.targets ?? []),
|
||||
].flatMap(({ field, key }) => (key === field ? [] : [[field, key]])),
|
||||
),
|
||||
flags: Object.fromEntries(
|
||||
parameters.flatMap(({ field, key, member, positional, delivery }) =>
|
||||
positional || delivery
|
||||
? []
|
||||
: [
|
||||
[
|
||||
member === undefined ? field : [field, ...member].join("."),
|
||||
`--${kebabCase(key)}`,
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
},
|
||||
evidenceDelivery,
|
||||
admit: (values) => {
|
||||
|
||||
@@ -384,7 +384,11 @@ export const runOnEvidenceTargets =
|
||||
error: "Analysis failed",
|
||||
...projectAnalysisError(retainSources(source.error), "invocation"),
|
||||
},
|
||||
{ operation: evidenceTargets.source, fields: { path: key } },
|
||||
{
|
||||
operation: evidenceTargets.source,
|
||||
fields: { path: key },
|
||||
flags: {},
|
||||
},
|
||||
);
|
||||
sources[field] = source.value;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ import type { Result } from "../domain/result.js";
|
||||
interface CliInputFieldBinding {
|
||||
readonly operation: string;
|
||||
readonly fields: Readonly<Record<string, string>>;
|
||||
/** Each contract field, or `field.member`, the command takes as a flag. */
|
||||
readonly flags: Readonly<Record<string, string>>;
|
||||
}
|
||||
|
||||
/** Flatten a finalized outcome only when returning the command's JSON output. */
|
||||
@@ -17,19 +19,39 @@ export const isObject = (
|
||||
value !== null && typeof value === "object" && !Array.isArray(value);
|
||||
|
||||
/**
|
||||
* Rename only the actionable parameter paths owned by this operation binding
|
||||
* in a contract command's output: a direct failure, a delivered failure or a
|
||||
* refused publication. Any other output is returned unchanged.
|
||||
* Name a contract command's input fields by their CLI spelling in its
|
||||
* output: a direct failure, a delivered failure or a refused publication.
|
||||
* Issue paths owned by this operation take the CLI key, and a per-call
|
||||
* control a failure reports (`details.limit.parameter`, which services name
|
||||
* by contract field) gains `cli_flag`, the option that sets it on this
|
||||
* command. Any other output is returned unchanged.
|
||||
*/
|
||||
export const projectCliInputFields = <Output>(
|
||||
output: Output,
|
||||
binding: CliInputFieldBinding,
|
||||
): Output => {
|
||||
const error = output as JsonValue;
|
||||
if (!isObject(error)) return output;
|
||||
const details = error.details;
|
||||
if (!isObject(error) || !isObject(error.details)) return output;
|
||||
const issues = renamedIssues(error, error.details, binding);
|
||||
const limit = flaggedLimit(error.details.limit, binding);
|
||||
if (issues === undefined && limit === undefined) return output;
|
||||
return {
|
||||
...error,
|
||||
details: {
|
||||
...error.details,
|
||||
...(issues === undefined ? {} : { issues }),
|
||||
...(limit === undefined ? {} : { limit }),
|
||||
},
|
||||
} as Output;
|
||||
};
|
||||
|
||||
/** Issue paths renamed to CLI keys, or undefined when none changes. */
|
||||
const renamedIssues = (
|
||||
error: Record<string, JsonValue>,
|
||||
details: Record<string, JsonValue>,
|
||||
binding: CliInputFieldBinding,
|
||||
): JsonValue[] | undefined => {
|
||||
if (
|
||||
!isObject(details) ||
|
||||
details.operation !== binding.operation ||
|
||||
!Array.isArray(details.issues) ||
|
||||
(error.code !== "invalid_request" &&
|
||||
@@ -38,8 +60,7 @@ export const projectCliInputFields = <Output>(
|
||||
details.execution_failure === "invalid_request"
|
||||
))
|
||||
)
|
||||
return output;
|
||||
|
||||
return undefined;
|
||||
let changed = false;
|
||||
const issues = details.issues.map((issue) => {
|
||||
if (!isObject(issue) || !Array.isArray(issue.path)) return issue;
|
||||
@@ -53,7 +74,29 @@ export const projectCliInputFields = <Output>(
|
||||
});
|
||||
// Keep retained output, partial Evidence and cleanup history by reference;
|
||||
// their source fields are not CLI parameter names.
|
||||
return changed
|
||||
? ({ ...error, details: { ...details, issues } } as Output)
|
||||
: output;
|
||||
return changed ? issues : undefined;
|
||||
};
|
||||
|
||||
/**
|
||||
* The reported per-call control with the flag that sets it, or undefined
|
||||
* when the command takes no flag for it. The longest bound prefix of the
|
||||
* parameter path names the flag: a flattened member option, else the option
|
||||
* of the whole field (such as `--producer-limits` JSON).
|
||||
*/
|
||||
const flaggedLimit = (
|
||||
limit: JsonValue | undefined,
|
||||
binding: CliInputFieldBinding,
|
||||
): Record<string, JsonValue> | undefined => {
|
||||
if (
|
||||
!isObject(limit) ||
|
||||
limit.control_kind !== "parameter" ||
|
||||
typeof limit.parameter !== "string"
|
||||
)
|
||||
return undefined;
|
||||
const segments = limit.parameter.split(".");
|
||||
for (let length = segments.length; length > 0; length -= 1) {
|
||||
const flag = binding.flags[segments.slice(0, length).join(".")];
|
||||
if (flag !== undefined) return { ...limit, cli_flag: flag };
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
Reference in new issue
Block a user