fix: keep cli dump budget byte-only

This commit is contained in:
Codex
2026-07-01 03:35:08 +00:00
parent ccf6adb68e
commit 73fbe4d81b
5 changed files with 3 additions and 136 deletions
-17
View File
@@ -25,7 +25,6 @@ const EMERGENCY_OUTPUT_DUMP_DIR = join(tmpdir(), "unidesk-cli-output");
export interface CliOutputPolicy {
maxStdoutBytes: number;
maxPreviewLines: number;
dumpDir: string;
includePreview: boolean;
warning: string;
@@ -170,23 +169,11 @@ function renderEnvelope<T>(command: string, envelope: JsonEnvelope<T>): string {
function outputDumpTrigger(text: string, policy: CliOutputPolicy, content: "json" | "text"): Record<string, unknown> | null {
if (process.env.UNIDESK_CLI_OUTPUT_DUMP_DISABLED === "1") return null;
const bytes = Buffer.byteLength(text, "utf8");
const lines = countLines(text);
if (bytes > policy.maxStdoutBytes) {
return {
reason: `stdout-${content}-bytes-exceeded-threshold`,
thresholdBytes: policy.maxStdoutBytes,
observedBytes: bytes,
thresholdLines: policy.maxPreviewLines,
observedLines: lines,
};
}
if (lines > policy.maxPreviewLines) {
return {
reason: `stdout-${content}-lines-exceeded-threshold`,
thresholdBytes: policy.maxStdoutBytes,
observedBytes: bytes,
thresholdLines: policy.maxPreviewLines,
observedLines: lines,
};
}
return null;
@@ -225,7 +212,6 @@ function dumpLargeOutput(command: string, text: string, extension: "json" | "txt
path,
configPath: policy.configPath,
thresholdBytes: policy.maxStdoutBytes,
thresholdLines: policy.maxPreviewLines,
bytes: Buffer.byteLength(text, "utf8"),
chars: text.length,
lines: countLines(text),
@@ -318,7 +304,6 @@ function disclosurePolicy(policy: CliOutputPolicy): Record<string, unknown> {
return {
configPath: policy.configPath,
maxStdoutBytes: policy.maxStdoutBytes,
maxPreviewLines: policy.maxPreviewLines,
dumpDir: policy.dumpDir,
includePreview: policy.includePreview,
recommendation: "Prefer k8s-style concise summaries/tables by default; expose full data through explicit --full/--raw/id-specific drill-down commands instead of large stdout.",
@@ -547,7 +532,6 @@ function cliOutputPolicy(): CliOutputPolicy {
const output = objectField(root, "output", CLI_OUTPUT_CONFIG_RELATIVE_PATH);
cachedOutputPolicy = {
maxStdoutBytes: positiveIntegerField(output, "maxStdoutBytes", `${CLI_OUTPUT_CONFIG_RELATIVE_PATH}.output`),
maxPreviewLines: positiveIntegerField(output, "maxPreviewLines", `${CLI_OUTPUT_CONFIG_RELATIVE_PATH}.output`),
dumpDir: absolutePathField(output, "dumpDir", `${CLI_OUTPUT_CONFIG_RELATIVE_PATH}.output`),
includePreview: booleanField(output, "includePreview", `${CLI_OUTPUT_CONFIG_RELATIVE_PATH}.output`),
warning: stringField(output, "warning", `${CLI_OUTPUT_CONFIG_RELATIVE_PATH}.output`),
@@ -558,7 +542,6 @@ function cliOutputPolicy(): CliOutputPolicy {
const message = error instanceof Error ? error.message : String(error);
cachedOutputPolicy = {
maxStdoutBytes: EMERGENCY_OUTPUT_DUMP_THRESHOLD_BYTES,
maxPreviewLines: 240,
dumpDir: EMERGENCY_OUTPUT_DUMP_DIR,
includePreview: false,
warning: "CLI output policy YAML could not be loaded; emergency dump guard is active for one-off drill-down only. Fix config/unidesk-cli.yaml, then improve the noisy command itself to print concise tables/summaries and id-specific progressive disclosure instead of repeatedly depending on dump extraction.",