@trazum/cli 1.62.1 → 1.63.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trazum/cli",
3
- "version": "1.62.1",
3
+ "version": "1.63.0",
4
4
  "description": "Trazum CLI: find where your LLM bill goes, price every finding per month, and enforce token budgets in CI.",
5
5
  "license": "MIT",
6
6
  "author": "David Mu\u00f1oz Rey",
@@ -37,7 +37,7 @@
37
37
  "prepublishOnly": "npm run build && npm test"
38
38
  },
39
39
  "dependencies": {
40
- "@trazum/core": "1.62.1"
40
+ "@trazum/core": "1.63.0"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@types/node": "^26.2.0",
package/src/i18n/en.ts CHANGED
@@ -405,6 +405,10 @@ ${bold('OPTIONS FOR optimize')}
405
405
  --diff Show the line-by-line diff.
406
406
  --json Dump the full report as JSON.
407
407
  --locale <${d.locales.join('|')}> Language of the report. Default: the system language.
408
+ --max-input <chars> Raise (or lower) the prompt-input ceiling, per run.
409
+ Above it a prompt door refuses with the size and
410
+ the limit named rather than grinding. Logs and
411
+ documents are never held to it.
408
412
  -o, --out <file> Write the optimised prompt to a file.
409
413
  -h, --help This help.
410
414
  --clear-suggestion-cache Empty the --cache-suggestions cache and say how much
@@ -881,6 +885,9 @@ ${bold('EXAMPLES')}
881
885
  optionNeedsValue: (name) => `Option --${name} needs a value.`,
882
886
  mustBeNonNegative: (name, raw) =>
883
887
  `--${name} must be a non-negative number (received: "${raw}").`,
888
+ inputTooLarge: (source, size, limit) =>
889
+ `${source} is ${count(size)} characters, past the ${count(limit)}-character ceiling for a prompt. Raise it deliberately with --max-input <chars> if this input really is one.`,
890
+ badMaxInput: (raw) => `--max-input must be a positive number of characters (received: "${raw}").`,
884
891
  fractionFlag: (name, raw) =>
885
892
  `--${name} is a fraction between 0 and 1 (received: ${raw}). The config refuses the same value the same way.`,
886
893
  badLevel: (received) => `--level must be "safe" or "aggressive" (received: "${received}").`,
package/src/i18n/es.ts CHANGED
@@ -404,6 +404,10 @@ ${bold('OPCIONES DE optimize')}
404
404
  --diff Muestra el diff línea a línea.
405
405
  --json Vuelca el informe completo en JSON.
406
406
  --locale <${d.locales.join('|')}> Idioma del informe. Por defecto: el del sistema.
407
+ --max-input <caracteres> Sube (o baja) el techo de entrada de prompts, por
408
+ ejecución. Por encima, una puerta de prompt rechaza
409
+ nombrando el tamaño y el límite en vez de arrastrarse.
410
+ Los logs y documentos nunca se sujetan a él.
407
411
  -o, --out <fichero> Escribe el prompt optimizado a un fichero.
408
412
  -h, --help Esta ayuda.
409
413
  --clear-suggestion-cache Vacía la caché de --cache-suggestions y dice cuánto
@@ -907,6 +911,9 @@ ${bold('EJEMPLOS')}
907
911
  optionNeedsValue: (name) => `La opción --${name} necesita un valor.`,
908
912
  mustBeNonNegative: (name, raw) =>
909
913
  `--${name} debe ser un número no negativo (recibido: "${raw}").`,
914
+ inputTooLarge: (source, size, limit) =>
915
+ `${source} tiene ${count(size)} caracteres, por encima del techo de ${count(limit)} para un prompt. Súbelo deliberadamente con --max-input <caracteres> si esta entrada de verdad lo es.`,
916
+ badMaxInput: (raw) => `--max-input debe ser un número positivo de caracteres (recibido: "${raw}").`,
910
917
  fractionFlag: (name, raw) =>
911
918
  `--${name} es una fracción entre 0 y 1 (recibido: ${raw}). La configuración rechaza el mismo valor de la misma forma.`,
912
919
  badLevel: (received) => `--level debe ser "safe" o "aggressive" (recibido: "${received}").`,
package/src/i18n/types.ts CHANGED
@@ -84,6 +84,9 @@ export interface CliMessages {
84
84
  livePricingFailed: (url: string, detail: string) => string;
85
85
  optionNeedsValue(name: string): string;
86
86
  mustBeNonNegative(name: string, raw: string): string;
87
+ /** The refusal ceiling: an input past the limit is named, never ground through. */
88
+ inputTooLarge(source: string, size: number, limit: number): string;
89
+ badMaxInput(raw: string): string;
87
90
  /** A flag that is a fraction of a whole: over 1 is refused, like the config. */
88
91
  fractionFlag(name: string, raw: string): string;
89
92
  badLevel(received: string): string;
package/src/index.ts CHANGED
@@ -91,6 +91,7 @@ import {
91
91
  listModels,
92
92
  LOCALES,
93
93
  MAX_BASELINE_BYTES,
94
+ MAX_INPUT_CHARS,
94
95
  moneyIsComparable,
95
96
  mostSpecificMatch,
96
97
  assemble,
@@ -317,6 +318,7 @@ const VALUE_FLAGS = new Set([
317
318
  'workload',
318
319
  'record',
319
320
  'max-ratio',
321
+ 'max-input',
320
322
  'max-day-usd',
321
323
  'max-session-usd',
322
324
  'csv-out',
@@ -605,7 +607,7 @@ function disabledRules(args: Args, config: TrazumConfig): RuleId[] | undefined {
605
607
  * a threshold is set — `--max-growh 5` would have been ignored and the build
606
608
  * gone green. Silence is the wrong answer for a typo.
607
609
  */
608
- const GLOBAL_FLAGS = ['help', 'h', 'version', 'v', 'locale', 'json', 'config', 'pricing', 'pricing-live'];
610
+ const GLOBAL_FLAGS = ['help', 'h', 'version', 'v', 'locale', 'json', 'config', 'pricing', 'pricing-live', 'max-input'];
609
611
  const COMMAND_FLAGS: Record<string, string[]> = {
610
612
  optimize: [
611
613
  'level', 'model', 'calls', 'output-tokens', 'cache-hit-rate', 'batch',
@@ -2060,7 +2062,8 @@ async function commandConform(args: Args, t: CliMessages): Promise<void> {
2060
2062
  throw new Error(t.conform.badContract(named, CONTRACT_NAMES.join(', ')));
2061
2063
  }
2062
2064
 
2063
- const text = target === '-' ? await readInput('-', t) : await readUsageLog(target, t);
2065
+ // A document or a log, not a prompt: deliberately uncapped (limit null).
2066
+ const text = target === '-' ? await readInput('-', t, null) : await readUsageLog(target, t);
2064
2067
  const report = conform(text, named === undefined ? {} : { contract: named });
2065
2068
 
2066
2069
  if (boolFlag(args, 'json')) {
@@ -3618,7 +3621,7 @@ async function commandSemantic(
3618
3621
  pricing: PricingCatalogue,
3619
3622
  t: CliMessages,
3620
3623
  ): Promise<void> {
3621
- const prompt = await readInput(args.positional[0], t);
3624
+ const prompt = await readInput(args.positional[0], t, maxInputFlag(args, t));
3622
3625
  const modelId = stringFlag(args, 'model') ?? config.usage?.model ?? DEFAULT_USAGE.model;
3623
3626
  const model = pricing.byId.get(modelId) ?? getModel(DEFAULT_USAGE.model);
3624
3627
  const rates = { inputPerMTok: model.inputPerMTok, outputPerMTok: model.outputPerMTok };
@@ -4279,7 +4282,7 @@ async function commandRulesMeasure(
4279
4282
  // `walkPrompts` returns names relative to the root it was given, so the
4280
4283
  // root has to go back on. Reading them bare only worked from a run whose
4281
4284
  // cwd happened to be the root, which is the one case a first probe uses.
4282
- const raw = await readFile(join(root, file), 'utf8');
4285
+ const raw = capInput(await readFile(join(root, file), 'utf8'), file, maxInputFlag(args, t), t);
4283
4286
  // A marked source file contributes its marked prompts; anything else
4284
4287
  // contributes itself. The same rule `check` and `doctor` already follow,
4285
4288
  // so the three commands measure the same text.
@@ -4331,16 +4334,57 @@ async function commandRulesMeasure(
4331
4334
  console.log();
4332
4335
  }
4333
4336
 
4334
- async function readInput(source: string | undefined, t: CliMessages): Promise<string> {
4337
+ /**
4338
+ * The refusal ceiling for a prompt door: the flag, or the number written once
4339
+ * in `@trazum/core`.
4340
+ *
4341
+ * Raising it is deliberate — a flag typed by the person paying the wall time —
4342
+ * and nothing raises it by accident. Lowering it is equally legitimate: a CI
4343
+ * job that knows its prompts are small can make anything bigger a red build.
4344
+ */
4345
+ function maxInputFlag(args: Args, t: CliMessages): number {
4346
+ const raw = args.flags.get('max-input');
4347
+ if (raw === undefined || typeof raw === 'boolean') return MAX_INPUT_CHARS;
4348
+ const value = Number(raw);
4349
+ if (!Number.isFinite(value) || value <= 0) {
4350
+ throw new Error(t.errors.badMaxInput(String(raw)));
4351
+ }
4352
+ return Math.floor(value);
4353
+ }
4354
+
4355
+ /** Refuses a prompt past the ceiling — the size and the limit named, never a grind. */
4356
+ function capInput(text: string, source: string, limit: number, t: CliMessages): string {
4357
+ if (text.length > limit) {
4358
+ throw new Error(t.errors.inputTooLarge(source, text.length, limit));
4359
+ }
4360
+ return text;
4361
+ }
4362
+
4363
+ /**
4364
+ * Reads a prompt-sized input, held to the ceiling.
4365
+ *
4366
+ * `limit: null` is for the callers whose input is a *document or a log* — a
4367
+ * 200,000-line export is ordinary and its size is the product's subject, so
4368
+ * holding it to a prompt's ceiling would refuse the exact input `profile`
4369
+ * exists to read. The null is written at the call site, so a reader of the
4370
+ * caller sees the decision.
4371
+ */
4372
+ async function readInput(
4373
+ source: string | undefined,
4374
+ t: CliMessages,
4375
+ limit: number | null = null,
4376
+ ): Promise<string> {
4335
4377
  if (!source) {
4336
4378
  throw new Error(t.errors.missingInputFile());
4337
4379
  }
4338
4380
  if (source === '-') {
4339
4381
  const chunks: Buffer[] = [];
4340
4382
  for await (const chunk of process.stdin) chunks.push(Buffer.from(chunk));
4341
- return Buffer.concat(chunks).toString('utf8');
4383
+ const text = Buffer.concat(chunks).toString('utf8');
4384
+ return limit === null ? text : capInput(text, 'stdin', limit, t);
4342
4385
  }
4343
- return readFile(source, 'utf8');
4386
+ const text = await readFile(source, 'utf8');
4387
+ return limit === null ? text : capInput(text, source, limit, t);
4344
4388
  }
4345
4389
 
4346
4390
  async function commandOptimize(
@@ -4392,6 +4436,7 @@ async function commandOptimize(
4392
4436
  unreadable.push({ label, path: promptPath });
4393
4437
  continue;
4394
4438
  }
4439
+ text = capInput(text, promptPath, maxInputFlag(args, t), t);
4395
4440
  const r = optimize(text, { level, usage: m.profile, locale, pricing });
4396
4441
  rows.push({
4397
4442
  label,
@@ -4442,7 +4487,7 @@ async function commandOptimize(
4442
4487
  }
4443
4488
 
4444
4489
  const target = args.positional[0];
4445
- const raw = await readInput(target, t);
4490
+ const raw = await readInput(target, t, maxInputFlag(args, t));
4446
4491
  const level = levelFlag(args, config, t);
4447
4492
 
4448
4493
  // A source file is not a prompt.
@@ -4850,7 +4895,7 @@ async function commandCheck(
4850
4895
  return;
4851
4896
  }
4852
4897
 
4853
- const prompt = await readInput(target, t);
4898
+ const prompt = await readInput(target, t, maxInputFlag(args, t));
4854
4899
  const n = (value: number): string => value.toLocaleString(t.numberLocale);
4855
4900
 
4856
4901
  // A single file falls back to the config budget for its own path, so
@@ -8862,7 +8907,7 @@ async function commandRoute(args: Args, pricing: PricingCatalogue, t: CliMessage
8862
8907
  return;
8863
8908
  }
8864
8909
 
8865
- const prompt = await readFile(promptPath, 'utf8');
8910
+ const prompt = capInput(await readFile(promptPath, 'utf8'), promptPath, maxInputFlag(args, t), t);
8866
8911
  const inputs = parseCases(await readFile(casesPath, 'utf8'));
8867
8912
  if (inputs.length === 0) throw new Error(t.errors.evalNoCases(casesPath));
8868
8913
 
@@ -9155,7 +9200,12 @@ async function scanPrompts(
9155
9200
  const declined: Array<{ path: string; line: number; detail: string }> = [];
9156
9201
 
9157
9202
  for (const relativePath of files) {
9158
- const text = await readFile(join(root, relativePath), 'utf8');
9203
+ const text = capInput(
9204
+ await readFile(join(root, relativePath), 'utf8'),
9205
+ relativePath,
9206
+ maxInputFlag(args, t),
9207
+ t,
9208
+ );
9159
9209
  // Budgets are keyed on paths as written in the repository, so a pattern like
9160
9210
  // `prompts/**` has to be matched against the path including the root the
9161
9211
  // user passed — not against the name relative to it.
@@ -9452,7 +9502,7 @@ function joinPosix(root: string, relativePath: string): string {
9452
9502
  * never "delete this", and nothing here edits the prompt.
9453
9503
  */
9454
9504
  async function commandPrune(args: Args, t: CliMessages): Promise<void> {
9455
- const prompt = await readInput(args.positional[0], t);
9505
+ const prompt = await readInput(args.positional[0], t, maxInputFlag(args, t));
9456
9506
 
9457
9507
  const casesPath = stringFlag(args, 'cases');
9458
9508
  if (!casesPath) throw new Error(t.errors.evalNeedsCases());
@@ -9540,7 +9590,7 @@ async function commandEval(
9540
9590
  t: CliMessages,
9541
9591
  locale: Locale,
9542
9592
  ): Promise<void> {
9543
- const prompt = await readInput(args.positional[0], t);
9593
+ const prompt = await readInput(args.positional[0], t, maxInputFlag(args, t));
9544
9594
  const level = levelFlag(args, config, t);
9545
9595
 
9546
9596
  const casesPath = stringFlag(args, 'cases');
@@ -9727,8 +9777,8 @@ async function commandDiff(
9727
9777
  }
9728
9778
 
9729
9779
  const [before, after] = await Promise.all([
9730
- readInput(beforePath, t),
9731
- readInput(afterPath, t),
9780
+ readInput(beforePath, t, maxInputFlag(args, t)),
9781
+ readInput(afterPath, t, maxInputFlag(args, t)),
9732
9782
  ]);
9733
9783
 
9734
9784
  const comparison = comparePrompts(before, after, {
@@ -10203,7 +10253,7 @@ async function commandRank(
10203
10253
  let skipped = 0;
10204
10254
 
10205
10255
  for (const file of files) {
10206
- const raw = await readFile(join(root, file), 'utf8');
10256
+ const raw = capInput(await readFile(join(root, file), 'utf8'), file, maxInputFlag(args, t), t);
10207
10257
 
10208
10258
  // A source file contributes its marked prompt, or nothing. Ranking
10209
10259
  // `src/prompts.ts` by the size of its imports would put the wrong file at
@@ -10684,7 +10734,7 @@ async function commandDoctor(
10684
10734
  let skipped = 0;
10685
10735
 
10686
10736
  for (const file of files) {
10687
- const raw = await readFile(join(root, file), 'utf8');
10737
+ const raw = capInput(await readFile(join(root, file), 'utf8'), file, maxInputFlag(args, t), t);
10688
10738
 
10689
10739
  // Same contract as `rank`: a source file contributes its marked prompt or
10690
10740
  // nothing, and an unmarked one is counted rather than allowed to abort a
@@ -10986,7 +11036,7 @@ async function diffDirectories(
10986
11036
 
10987
11037
  /** The prompt at a path, or null when the file holds no marked prompt. */
10988
11038
  const textAt = async (root: string, file: string): Promise<string | null> => {
10989
- const raw = await readFile(join(root, file), 'utf8');
11039
+ const raw = capInput(await readFile(join(root, file), 'utf8'), file, maxInputFlag(args, t), t);
10990
11040
  let source: { text: string; model?: string } | null;
10991
11041
  try {
10992
11042
  source = sourceFileOf(file, raw, pricing, stringFlag(args, 'prompt'));