


















@@ -441,13 +441,23 @@ function invalidCliArgument(message: string): Error & { code: string; exitCode:
441441}
442442443443function parseWikiConfidenceOption(value: string): number {
444-const confidence = Number(value);
444+const trimmed = value.trim();
445+const confidence = /^[+-]?(?:\d+(?:\.\d+)?|\.\d+)$/.test(trimmed) ? Number(trimmed) : Number.NaN;
445446if (!Number.isFinite(confidence) || confidence < 0 || confidence > 1) {
446447throw invalidCliArgument("--confidence must be a number between 0 and 1.");
447448}
448449return confidence;
449450}
450451452+function parseWikiPositiveIntegerOption(value: string, flag: string): number {
453+const trimmed = value.trim();
454+const parsed = /^\d+$/.test(trimmed) ? Number(trimmed) : Number.NaN;
455+if (!Number.isSafeInteger(parsed) || parsed < 1) {
456+throw invalidCliArgument(`${flag} must be a positive integer.`);
457+}
458+return parsed;
459+}
460+451461function addWikiApplyMutationOptions<T extends Command>(command: T): T {
452462return command
453463.option("--source-id <id>", "Source id", collectCliValues)
@@ -959,7 +969,9 @@ export function registerWikiCli(
959969.command("search")
960970.description("Search wiki pages and, when configured, the active memory corpus")
961971.argument("<query>", "Search query")
962-.option("--max-results <n>", "Maximum results", (value: string) => Number(value))
972+.option("--max-results <n>", "Maximum results", (value: string) =>
973+parseWikiPositiveIntegerOption(value, "--max-results"),
974+)
963975.option("--mode <mode>", `Search mode (${WIKI_SEARCH_MODES.join(", ")})`),
964976)
965977.option("--json", "Print JSON")
@@ -981,8 +993,12 @@ export function registerWikiCli(
981993.command("get")
982994.description("Read a wiki page by id or relative path, with optional active-memory fallback")
983995.argument("<lookup>", "Relative path or page id")
984-.option("--from <n>", "Start line", (value: string) => Number(value))
985-.option("--lines <n>", "Number of lines", (value: string) => Number(value)),
996+.option("--from <n>", "Start line", (value: string) =>
997+parseWikiPositiveIntegerOption(value, "--from"),
998+)
999+.option("--lines <n>", "Number of lines", (value: string) =>
1000+parseWikiPositiveIntegerOption(value, "--lines"),
1001+),
9861002)
9871003.option("--json", "Print JSON")
9881004.action(async (lookup: string, opts: WikiGetCommandOptions) => {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。