Add opt-in string_tables_only and CLI --string-tables-only to keep selected strings once in typed table facts. Preserve existing defaults and legacy replies; charge aggregate output capacity for the copies actually requested. Validate shared CLI/MCP behavior with independent XML oracles, three real APKs, 94 source tests, nine compiled boundary tests, 36 completed MCP tasks and three CLI parity tasks. Preserve full task estimates, negative timings, resource admission refusal and verification limitations in the measured report. Fixes #4982 Co-authored-by: gensokyo-dev <[email protected]> Co-authored-by: Kaoru0822 <[email protected]>
87 lines
3.5 KiB
TypeScript
87 lines
3.5 KiB
TypeScript
import { z } from "incur";
|
|
import { ApktoolResourceAnalysisService } from "../application/apktool/ApktoolResourceAnalysisService.js";
|
|
import type { ApktoolResourceAnalysisPort } from "../application/apktool/ApktoolResourceAnalysisPort.js";
|
|
import { createApktoolResourceAnalysisProvider } from "../composition/apktool.js";
|
|
import { CLI_COMMANDS } from "../cliCommandNames.js";
|
|
import { logCliCommand } from "../cliLogging.js";
|
|
import {
|
|
apktoolInputSchemas,
|
|
type ApktoolOperation,
|
|
} from "../domain/apktool/apktoolResourceAnalysis.js";
|
|
import type { Logger } from "pino";
|
|
import type { CliInstance } from "./types.js";
|
|
import { withCommandCancellation } from "./commandCancellation.js";
|
|
import { finishAnalysisCommand } from "./finishAnalysisCommand.js";
|
|
|
|
/** Expose the same explicit Apktool requests through one-shot CLI commands. */
|
|
export const registerApktoolCommands = (
|
|
cli: CliInstance,
|
|
logger: Logger,
|
|
environment: Readonly<Record<string, string | undefined>>,
|
|
provider: ApktoolResourceAnalysisPort = createApktoolResourceAnalysisProvider(
|
|
environment,
|
|
),
|
|
): void => {
|
|
const service = new ApktoolResourceAnalysisService(provider);
|
|
const execute = (name: string, operation: ApktoolOperation, input: unknown) =>
|
|
withCommandCancellation((signal) =>
|
|
logCliCommand(logger, name, () =>
|
|
finishAnalysisCommand(
|
|
() => service.execute(operation, input, { signal }),
|
|
{ close: () => provider.close() },
|
|
"apktool",
|
|
operation,
|
|
signal,
|
|
),
|
|
),
|
|
);
|
|
|
|
cli.command(CLI_COMMANDS.inspectApktoolClient, {
|
|
description:
|
|
"Inspect the caller-selected apktool launcher without decoding anything",
|
|
args: z.object({}),
|
|
run: () =>
|
|
execute(CLI_COMMANDS.inspectApktoolClient, "inspect_apktool_client", {}),
|
|
});
|
|
cli.command(CLI_COMMANDS.decodeAndroidResources, {
|
|
description:
|
|
"Decode one APK's manifest, metadata, and string resources with apktool",
|
|
args: z.object({
|
|
path: z.string().min(1).describe("Local APK file to decode"),
|
|
}),
|
|
// The locale grammar and the string-projection default belong to the
|
|
// apktool input owner. Read them from that schema rather than restating a
|
|
// narrower locale pattern, which refused the owner's own advertised
|
|
// `b+zh+Hans+CN` form at the CLI boundary.
|
|
options: z.object({
|
|
locale: apktoolInputSchemas.decode_android_resources.shape.locale,
|
|
"string-tables-only":
|
|
apktoolInputSchemas.decode_android_resources.shape.string_tables_only,
|
|
locales:
|
|
apktoolInputSchemas.decode_android_resources.shape.locales.describe(
|
|
"Repeat to project multiple localized string tables, e.g. --locales de --locales pt-BR",
|
|
),
|
|
strings: z
|
|
.boolean()
|
|
.default(
|
|
apktoolInputSchemas.decode_android_resources.shape.include_strings.parse(
|
|
undefined,
|
|
),
|
|
)
|
|
.describe(
|
|
"Include string resources; use --no-strings to skip projecting them",
|
|
),
|
|
}),
|
|
run: ({ args, options }) =>
|
|
execute(CLI_COMMANDS.decodeAndroidResources, "decode_android_resources", {
|
|
path: args.path,
|
|
include_strings: options.strings,
|
|
...(options["string-tables-only"] === undefined
|
|
? {}
|
|
: { string_tables_only: options["string-tables-only"] }),
|
|
...(options.locale === undefined ? {} : { locale: options.locale }),
|
|
...(options.locales === undefined ? {} : { locales: options.locales }),
|
|
}),
|
|
});
|
|
};
|