fix(cli): stream JSON results at the shared command boundary

Route ordinary CLI results through the bounded JSON writer after command registration, including managed member inspection. Remove JavaScript-specific output plumbing while preserving filters, envelopes, cancellation, and failure exits.

Measure formatted UTF-16 expansion before Incur token counting and return resource_constraint above the runtime string limit, with recovery guidance.

Validate output above the real V8 string limit by SHA-256 and exercise the compiled managed provider. Clean-worktree validation: npm run check; 76 focused tests passed, with 2 optional-provider skips; test discovery passed.

Fixes #1371.
This commit is contained in:
morluto
2026-10-10 06:23:26 +08:00
parent ecc67cab2d
commit 810107a2ad
9 changed files with 314 additions and 65 deletions
+2 -10
View File
@@ -15,7 +15,6 @@ import {
import type { CliInstance } from "./types.js";
import { runCliJavaScriptApplicationAnalysis } from "./javascriptApplicationAnalysis.js";
import { withCommandCancellation } from "./commandCancellation.js";
import type { CliResultOutput } from "./streamedJsonOutput.js";
import { javascriptApplicationOptions } from "../cliObservationOptions.js";
/** Register provider-neutral binary overview and procedure CLI commands. */
@@ -23,9 +22,8 @@ export const registerCoreBinaryCommands = (
cli: CliInstance,
logger: Logger,
runDirectAnalysis: DirectAnalysis["runDirectAnalysis"],
resultOutput?: CliResultOutput,
): void => {
registerOverviewCommands(cli, logger, runDirectAnalysis, resultOutput);
registerOverviewCommands(cli, logger, runDirectAnalysis);
registerDecompileCommand(cli, logger, runDirectAnalysis);
registerFunctionCommand(cli, logger, runDirectAnalysis);
registerInstructionsCommand(cli, logger, runDirectAnalysis);
@@ -38,7 +36,6 @@ const registerOverviewCommands = (
cli: CliInstance,
logger: Logger,
runDirectAnalysis: DirectAnalysis["runDirectAnalysis"],
resultOutput?: CliResultOutput,
): void => {
const overviewOptions = z.object({
snapshot: z
@@ -58,11 +55,7 @@ const registerOverviewCommands = (
integrityPolicy: javascriptApplicationOptions.shape.integrityPolicy,
}),
alias: { integrityPolicy: "integrity-policy" },
run: async ({ args, options, format }) => {
const output =
resultOutput === undefined
? undefined
: { output: resultOutput, command: CLI_COMMANDS.analyze, format };
run: async ({ args, options }) => {
// Route JavaScript targets exactly like analyze-javascript-application,
// including typed cancellation; cancellation wraps logging so its exit
// code is not replaced by the logged failure status.
@@ -74,7 +67,6 @@ const registerOverviewCommands = (
input_path: resolve(args.path),
integrity_policy: options.integrityPolicy,
},
output,
signal,
),
),