@tellagen/mcp-server 0.6.0 → 0.8.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.
Files changed (99) hide show
  1. package/README.md +29 -4
  2. package/SKILL.md +106 -19
  3. package/contracts/mcp-protocol.json +52 -3
  4. package/contracts/runbooks/manifest.json +10 -10
  5. package/contracts/runbooks/v2/client-protocol.json +6 -0
  6. package/contracts/runbooks/v2/fixtures/filesystem-pressure.json +22 -31
  7. package/contracts/runbooks/v2/result-summary.guidance.json +53 -5
  8. package/contracts/runbooks/v2/timeline-event-blocks.schema.json +4 -2
  9. package/contracts/tellagen-runbook-contracts.json +3 -3
  10. package/dist/active-run.d.ts +6 -0
  11. package/dist/active-run.js +14 -0
  12. package/dist/active-run.js.map +1 -1
  13. package/dist/cli/doctor.d.ts +2 -2
  14. package/dist/cli/doctor.js +2 -35
  15. package/dist/cli/doctor.js.map +1 -1
  16. package/dist/cli/kubernetes.d.ts +47 -0
  17. package/dist/cli/kubernetes.js +369 -0
  18. package/dist/cli/kubernetes.js.map +1 -0
  19. package/dist/cli/main.js +5 -0
  20. package/dist/cli/main.js.map +1 -1
  21. package/dist/diagnosis-structure.d.ts +277 -24
  22. package/dist/diagnosis-structure.js +273 -8
  23. package/dist/diagnosis-structure.js.map +1 -1
  24. package/dist/doctor/checks.js +8 -2
  25. package/dist/doctor/checks.js.map +1 -1
  26. package/dist/doctor/k8s-read-only.d.ts +16 -0
  27. package/dist/doctor/k8s-read-only.js +89 -0
  28. package/dist/doctor/k8s-read-only.js.map +1 -0
  29. package/dist/doctor/real-fs.d.ts +3 -0
  30. package/dist/doctor/real-fs.js +36 -0
  31. package/dist/doctor/real-fs.js.map +1 -0
  32. package/dist/figures.d.ts +121 -26
  33. package/dist/figures.js +44 -2
  34. package/dist/figures.js.map +1 -1
  35. package/dist/heartbeat.d.ts +3 -0
  36. package/dist/heartbeat.js +32 -1
  37. package/dist/heartbeat.js.map +1 -1
  38. package/dist/index.js +1 -1
  39. package/dist/index.js.map +1 -1
  40. package/dist/k8s-safety.d.ts +2 -2
  41. package/dist/k8s-safety.js +2 -2
  42. package/dist/k8s-safety.js.map +1 -1
  43. package/dist/listen-config.d.ts +5 -5
  44. package/dist/listen-probe.d.ts +14 -1
  45. package/dist/listen-probe.js +83 -5
  46. package/dist/listen-probe.js.map +1 -1
  47. package/dist/listen-settings.d.ts +8 -0
  48. package/dist/listen-settings.js +29 -0
  49. package/dist/listen-settings.js.map +1 -1
  50. package/dist/listener.d.ts +23 -0
  51. package/dist/listener.js +122 -19
  52. package/dist/listener.js.map +1 -1
  53. package/dist/run-events.js +13 -1
  54. package/dist/run-events.js.map +1 -1
  55. package/dist/run-requests.d.ts +16 -0
  56. package/dist/run-requests.js +56 -0
  57. package/dist/run-requests.js.map +1 -0
  58. package/dist/server.d.ts +1 -1
  59. package/dist/server.js +10 -8
  60. package/dist/server.js.map +1 -1
  61. package/dist/session.d.ts +37 -0
  62. package/dist/session.js +59 -0
  63. package/dist/session.js.map +1 -1
  64. package/dist/tools/amendments.d.ts +13 -0
  65. package/dist/tools/amendments.js +206 -0
  66. package/dist/tools/amendments.js.map +1 -0
  67. package/dist/tools/catalog.js +3 -0
  68. package/dist/tools/catalog.js.map +1 -1
  69. package/dist/tools/diagnostics.js +57 -12
  70. package/dist/tools/diagnostics.js.map +1 -1
  71. package/dist/tools/figures.d.ts +1 -1
  72. package/dist/tools/figures.js +12 -6
  73. package/dist/tools/figures.js.map +1 -1
  74. package/dist/tools/findings.d.ts +128 -0
  75. package/dist/tools/findings.js +6 -6
  76. package/dist/tools/findings.js.map +1 -1
  77. package/dist/tools/index.js +4 -0
  78. package/dist/tools/index.js.map +1 -1
  79. package/dist/tools/investigations.d.ts +3223 -5
  80. package/dist/tools/investigations.js +191 -69
  81. package/dist/tools/investigations.js.map +1 -1
  82. package/dist/tools/next.d.ts +16 -0
  83. package/dist/tools/next.js +49 -1
  84. package/dist/tools/next.js.map +1 -1
  85. package/dist/tools/requests.d.ts +3 -0
  86. package/dist/tools/requests.js +62 -0
  87. package/dist/tools/requests.js.map +1 -0
  88. package/dist/tools/resume.js +14 -1
  89. package/dist/tools/resume.js.map +1 -1
  90. package/dist/tools/timeline.js +13 -2
  91. package/dist/tools/timeline.js.map +1 -1
  92. package/dist/unattended.d.ts +10 -0
  93. package/dist/unattended.js +13 -0
  94. package/dist/unattended.js.map +1 -0
  95. package/dist/version.d.ts +4 -2
  96. package/dist/version.js +4 -1
  97. package/dist/version.js.map +1 -1
  98. package/package.json +1 -1
  99. package/server.json +1 -1
@@ -0,0 +1,89 @@
1
+ import { isAbsolute, join } from "node:path";
2
+ import { toolOfEntry } from "./checks.js";
3
+ import { DOCTOR_CLIENTS, scanClient } from "./config-files.js";
4
+ import { parseToml } from "./toml.js";
5
+ /** Replaces a leading `~` and the `$HOME` forms that a config line may use. */
6
+ function expandHome(path, fs) {
7
+ return path
8
+ .replace(/^~(?=$|[\\/])/, fs.home)
9
+ .replace(/^\$\{?HOME\}?(?=$|[\\/])/, fs.home)
10
+ .replace(/^%USERPROFILE%(?=$|[\\/])/i, fs.home);
11
+ }
12
+ function flagValue(args, name) {
13
+ for (let i = 0; i < args.length; i++) {
14
+ const arg = args[i];
15
+ if (arg === name) {
16
+ const next = args[i + 1];
17
+ return next !== undefined && !next.startsWith("-") ? next : true;
18
+ }
19
+ if (arg.startsWith(`${name}=`))
20
+ return arg.slice(name.length + 1);
21
+ }
22
+ return undefined;
23
+ }
24
+ function truthy(value) {
25
+ if (value === true)
26
+ return true;
27
+ const v = value.trim().toLowerCase();
28
+ if (v === "true" || v === "1" || v === "yes")
29
+ return true;
30
+ if (v === "false" || v === "0" || v === "no")
31
+ return false;
32
+ return undefined;
33
+ }
34
+ /**
35
+ * Whether one Kubernetes server entry runs read-only: the `read_only` setting
36
+ * of its `--config` TOML file, or a `--read-only` flag. `true` when it does,
37
+ * `false` when the entry clearly does not, `undefined` when it cannot be
38
+ * known (a config file that cannot be read, or an entry that is a remote
39
+ * address). Only this one fact is read; no path, value or file text leaves.
40
+ */
41
+ export function kubernetesEntryReadOnly(entry, fs) {
42
+ if (entry.url && !entry.command)
43
+ return undefined;
44
+ const flag = flagValue(entry.args, "--read-only");
45
+ if (flag !== undefined)
46
+ return truthy(flag);
47
+ const config = flagValue(entry.args, "--config");
48
+ if (typeof config === "string") {
49
+ const expanded = expandHome(config, fs);
50
+ const path = isAbsolute(expanded) ? expanded : join(fs.cwd, expanded);
51
+ const text = fs.readText(path);
52
+ if (text === undefined)
53
+ return undefined;
54
+ try {
55
+ const root = parseToml(text);
56
+ const value = root.read_only;
57
+ return value === true;
58
+ }
59
+ catch {
60
+ return undefined;
61
+ }
62
+ }
63
+ return false;
64
+ }
65
+ /**
66
+ * The read-only flag of the Kubernetes server of a client, read from its
67
+ * config files. With several Kubernetes servers it is true only when every
68
+ * one is read-only. `undefined` when the client has no Kubernetes server in a
69
+ * file the doctor reads, or the answer cannot be known.
70
+ */
71
+ export function kubernetesReadOnlyOfClient(client, fs) {
72
+ const clients = DOCTOR_CLIENTS.includes(client ?? "")
73
+ ? [client]
74
+ : DOCTOR_CLIENTS;
75
+ const answers = [];
76
+ for (const name of clients) {
77
+ for (const entry of scanClient(name, fs).entries) {
78
+ if (toolOfEntry(entry) !== "kubernetes")
79
+ continue;
80
+ const answer = kubernetesEntryReadOnly(entry, fs);
81
+ if (answer !== undefined)
82
+ answers.push(answer);
83
+ }
84
+ }
85
+ if (answers.length === 0)
86
+ return undefined;
87
+ return answers.every(Boolean);
88
+ }
89
+ //# sourceMappingURL=k8s-read-only.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"k8s-read-only.js","sourceRoot":"","sources":["../../src/doctor/k8s-read-only.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,UAAU,EA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AAE,EAAY;IACjF,MAAM,OAAO,GAA6B,cAAoC,CAAC,QAAQ,CAAC,MAAM,IAAI,EAAE,CAAC;QACnG,CAAC,CAAC,CAAC,MAAsB,CAAC;QAC1B,CAAC,CAAC,cAAc,CAAC;IACnB,MAAM,OAAO,GAAc,EAAE,CAAC;IAC9B,KAAK,MAAM,IAAI,IAAI,OAAO,EAAE,CAAC;QAC3B,KAAK,MAAM,KAAK,IAAI,UAAU,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC;YACjD,IAAI,WAAW,CAAC,KAAK,CAAC,KAAK,YAAY;gBAAE,SAAS;YAClD,MAAM,MAAM,GAAG,uBAAuB,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;YAClD,IAAI,MAAM,KAAK,SAAS;gBAAE,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACjD,CAAC;IACH,CAAC;IACD,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,SAAS,CAAC;IAC3C,OAAO,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;AAChC,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { DoctorFs } from "./config-files.js";
2
+ /** The computer this process runs on. */
3
+ export declare function realDoctorFs(): DoctorFs;
@@ -0,0 +1,36 @@
1
+ import { accessSync, constants, readFileSync, statSync } from "node:fs";
2
+ import { homedir } from "node:os";
3
+ const MAX_CONFIG_BYTES = 4 << 20;
4
+ /** The computer this process runs on. */
5
+ export function realDoctorFs() {
6
+ return {
7
+ platform: process.platform,
8
+ home: homedir(),
9
+ cwd: process.cwd(),
10
+ appData: process.env.APPDATA ?? "",
11
+ xdgConfig: process.env.XDG_CONFIG_HOME ?? "",
12
+ readText(path) {
13
+ try {
14
+ if (statSync(path).size > MAX_CONFIG_BYTES)
15
+ return undefined;
16
+ return readFileSync(path, "utf8");
17
+ }
18
+ catch {
19
+ return undefined;
20
+ }
21
+ },
22
+ isExecutable(path) {
23
+ try {
24
+ if (!statSync(path).isFile())
25
+ return false;
26
+ if (process.platform !== "win32")
27
+ accessSync(path, constants.X_OK);
28
+ return true;
29
+ }
30
+ catch {
31
+ return false;
32
+ }
33
+ },
34
+ };
35
+ }
36
+ //# sourceMappingURL=real-fs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"real-fs.js","sourceRoot":"","sources":["../../src/doctor/real-fs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACxE,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAGlC,MAAM,gBAAgB,GAAG,CAAC,IAAI,EAAE,CAAC;AAEjC,yCAAyC;AACzC,MAAM,UAAU,YAAY;IAC1B,OAAO;QACL,QAAQ,EAAE,OAAO,CAAC,QAAQ;QAC1B,IAAI,EAAE,OAAO,EAAE;QACf,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE;QAClB,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,OAAO,IAAI,EAAE;QAClC,SAAS,EAAE,OAAO,CAAC,GAAG,CAAC,eAAe,IAAI,EAAE;QAC5C,QAAQ,CAAC,IAAI;YACX,IAAI,CAAC;gBACH,IAAI,QAAQ,CAAC,IAAI,CAAC,CAAC,IAAI,GAAG,gBAAgB;oBAAE,OAAO,SAAS,CAAC;gBAC7D,OAAO,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;YACpC,CAAC;YAAC,MAAM,CAAC;gBACP,OAAO,SAAS,CAAC;YACnB,CAAC;QACH,CAAC;QACD,YAAY,CAAC,IAAI;YACf,IAAI,CAAC;gBACH,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE;oBAAE,OAAO,KAAK,CAAC;gBAC3C,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO;oBAAE,UAAU,CAAC,IAAI,EAAE,SAAS,CAAC,IAAI,CAAC,CAAC;gBACnE,OAAO,IAAI,CAAC;YACd,CAAC;YAAC,MAAM,CAAC;gBACP,OAAO,KAAK,CAAC;YACf,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC"}
package/dist/figures.d.ts CHANGED
@@ -33,6 +33,8 @@ export declare const MAX_STATS_ITEMS = 8;
33
33
  export declare const MAX_STATS_TILES = 4;
34
34
  /** The server takes a stats title, more than 4 stats and runs_not_shown. */
35
35
  export declare const FIGURE_EXTRAS_CAPABILITY = "figure_extras_v1";
36
+ /** The server takes a `limit` on a compare row (the row is then "after against limit"). */
37
+ export declare const FIGURE_LIMITS_CAPABILITY = "figure_limits_v1";
36
38
  /** The server takes a log_lines figure. */
37
39
  export declare const LOG_LINES_CAPABILITY = "log_lines_v1";
38
40
  export declare const RUN_RESULTS: readonly ["success", "failure", "cancelled", "pending"];
@@ -407,14 +409,14 @@ export declare const logLinesBlockSchema: z.ZodObject<{
407
409
  note: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
408
410
  }, "strict", z.ZodTypeAny, {
409
411
  text: string;
410
- level: "other" | "error" | "warn" | "info" | "debug";
412
+ level: "other" | "info" | "error" | "warn" | "debug";
411
413
  time: string;
412
414
  fields?: Record<string, string> | undefined;
413
415
  relation?: "context" | "matches_event" | "unrelated" | undefined;
414
416
  note?: string | undefined;
415
417
  }, {
416
418
  text: string;
417
- level: "other" | "error" | "warn" | "info" | "debug";
419
+ level: "other" | "info" | "error" | "warn" | "debug";
418
420
  time: string;
419
421
  fields?: Record<string, string> | undefined;
420
422
  relation?: "context" | "matches_event" | "unrelated" | undefined;
@@ -434,7 +436,7 @@ export declare const logLinesBlockSchema: z.ZodObject<{
434
436
  } | undefined;
435
437
  lines?: {
436
438
  text: string;
437
- level: "other" | "error" | "warn" | "info" | "debug";
439
+ level: "other" | "info" | "error" | "warn" | "debug";
438
440
  time: string;
439
441
  fields?: Record<string, string> | undefined;
440
442
  relation?: "context" | "matches_event" | "unrelated" | undefined;
@@ -456,7 +458,7 @@ export declare const logLinesBlockSchema: z.ZodObject<{
456
458
  } | undefined;
457
459
  lines?: {
458
460
  text: string;
459
- level: "other" | "error" | "warn" | "info" | "debug";
461
+ level: "other" | "info" | "error" | "warn" | "debug";
460
462
  time: string;
461
463
  fields?: Record<string, string> | undefined;
462
464
  relation?: "context" | "matches_event" | "unrelated" | undefined;
@@ -547,11 +549,12 @@ export declare const timelineBlockSchema: z.ZodDiscriminatedUnion<"type", [z.Zod
547
549
  value: number;
548
550
  label?: string | undefined;
549
551
  }>>;
550
- rows: z.ZodArray<z.ZodObject<{
552
+ rows: z.ZodArray<z.ZodEffects<z.ZodObject<{
551
553
  label: z.ZodString;
552
554
  mono: z.ZodOptional<z.ZodBoolean>;
553
- before: z.ZodNumber;
555
+ before: z.ZodOptional<z.ZodNumber>;
554
556
  after: z.ZodNumber;
557
+ limit: z.ZodOptional<z.ZodNumber>;
555
558
  details: z.ZodOptional<z.ZodArray<z.ZodObject<{
556
559
  label: z.ZodString;
557
560
  before: z.ZodString;
@@ -567,7 +570,6 @@ export declare const timelineBlockSchema: z.ZodDiscriminatedUnion<"type", [z.Zod
567
570
  }>, "many">>;
568
571
  }, "strict", z.ZodTypeAny, {
569
572
  label: string;
570
- before: number;
571
573
  after: number;
572
574
  details?: {
573
575
  label: string;
@@ -575,9 +577,10 @@ export declare const timelineBlockSchema: z.ZodDiscriminatedUnion<"type", [z.Zod
575
577
  after: string;
576
578
  }[] | undefined;
577
579
  mono?: boolean | undefined;
580
+ before?: number | undefined;
581
+ limit?: number | undefined;
578
582
  }, {
579
583
  label: string;
580
- before: number;
581
584
  after: number;
582
585
  details?: {
583
586
  label: string;
@@ -585,6 +588,30 @@ export declare const timelineBlockSchema: z.ZodDiscriminatedUnion<"type", [z.Zod
585
588
  after: string;
586
589
  }[] | undefined;
587
590
  mono?: boolean | undefined;
591
+ before?: number | undefined;
592
+ limit?: number | undefined;
593
+ }>, {
594
+ label: string;
595
+ after: number;
596
+ details?: {
597
+ label: string;
598
+ before: string;
599
+ after: string;
600
+ }[] | undefined;
601
+ mono?: boolean | undefined;
602
+ before?: number | undefined;
603
+ limit?: number | undefined;
604
+ }, {
605
+ label: string;
606
+ after: number;
607
+ details?: {
608
+ label: string;
609
+ before: string;
610
+ after: string;
611
+ }[] | undefined;
612
+ mono?: boolean | undefined;
613
+ before?: number | undefined;
614
+ limit?: number | undefined;
588
615
  }>, "many">;
589
616
  } & {
590
617
  slot: z.ZodOptional<z.ZodLiteral<"summary">>;
@@ -594,7 +621,6 @@ export declare const timelineBlockSchema: z.ZodDiscriminatedUnion<"type", [z.Zod
594
621
  type: "compare";
595
622
  rows: {
596
623
  label: string;
597
- before: number;
598
624
  after: number;
599
625
  details?: {
600
626
  label: string;
@@ -602,6 +628,8 @@ export declare const timelineBlockSchema: z.ZodDiscriminatedUnion<"type", [z.Zod
602
628
  after: string;
603
629
  }[] | undefined;
604
630
  mono?: boolean | undefined;
631
+ before?: number | undefined;
632
+ limit?: number | undefined;
605
633
  }[];
606
634
  title?: string | undefined;
607
635
  anchor?: string | undefined;
@@ -620,7 +648,6 @@ export declare const timelineBlockSchema: z.ZodDiscriminatedUnion<"type", [z.Zod
620
648
  type: "compare";
621
649
  rows: {
622
650
  label: string;
623
- before: number;
624
651
  after: number;
625
652
  details?: {
626
653
  label: string;
@@ -628,6 +655,8 @@ export declare const timelineBlockSchema: z.ZodDiscriminatedUnion<"type", [z.Zod
628
655
  after: string;
629
656
  }[] | undefined;
630
657
  mono?: boolean | undefined;
658
+ before?: number | undefined;
659
+ limit?: number | undefined;
631
660
  }[];
632
661
  title?: string | undefined;
633
662
  anchor?: string | undefined;
@@ -1261,14 +1290,14 @@ export declare const timelineBlockSchema: z.ZodDiscriminatedUnion<"type", [z.Zod
1261
1290
  note: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
1262
1291
  }, "strict", z.ZodTypeAny, {
1263
1292
  text: string;
1264
- level: "other" | "error" | "warn" | "info" | "debug";
1293
+ level: "other" | "info" | "error" | "warn" | "debug";
1265
1294
  time: string;
1266
1295
  fields?: Record<string, string> | undefined;
1267
1296
  relation?: "context" | "matches_event" | "unrelated" | undefined;
1268
1297
  note?: string | undefined;
1269
1298
  }, {
1270
1299
  text: string;
1271
- level: "other" | "error" | "warn" | "info" | "debug";
1300
+ level: "other" | "info" | "error" | "warn" | "debug";
1272
1301
  time: string;
1273
1302
  fields?: Record<string, string> | undefined;
1274
1303
  relation?: "context" | "matches_event" | "unrelated" | undefined;
@@ -1294,7 +1323,7 @@ export declare const timelineBlockSchema: z.ZodDiscriminatedUnion<"type", [z.Zod
1294
1323
  postmortem?: boolean | undefined;
1295
1324
  lines?: {
1296
1325
  text: string;
1297
- level: "other" | "error" | "warn" | "info" | "debug";
1326
+ level: "other" | "info" | "error" | "warn" | "debug";
1298
1327
  time: string;
1299
1328
  fields?: Record<string, string> | undefined;
1300
1329
  relation?: "context" | "matches_event" | "unrelated" | undefined;
@@ -1319,7 +1348,7 @@ export declare const timelineBlockSchema: z.ZodDiscriminatedUnion<"type", [z.Zod
1319
1348
  postmortem?: boolean | undefined;
1320
1349
  lines?: {
1321
1350
  text: string;
1322
- level: "other" | "error" | "warn" | "info" | "debug";
1351
+ level: "other" | "info" | "error" | "warn" | "debug";
1323
1352
  time: string;
1324
1353
  fields?: Record<string, string> | undefined;
1325
1354
  relation?: "context" | "matches_event" | "unrelated" | undefined;
@@ -1399,11 +1428,12 @@ export declare const figureInputSchema: z.ZodDiscriminatedUnion<"type", [z.ZodOb
1399
1428
  value: number;
1400
1429
  label?: string | undefined;
1401
1430
  }>>;
1402
- rows: z.ZodArray<z.ZodObject<{
1431
+ rows: z.ZodArray<z.ZodEffects<z.ZodObject<{
1403
1432
  label: z.ZodString;
1404
1433
  mono: z.ZodOptional<z.ZodBoolean>;
1405
- before: z.ZodNumber;
1434
+ before: z.ZodOptional<z.ZodNumber>;
1406
1435
  after: z.ZodNumber;
1436
+ limit: z.ZodOptional<z.ZodNumber>;
1407
1437
  details: z.ZodOptional<z.ZodArray<z.ZodObject<{
1408
1438
  label: z.ZodString;
1409
1439
  before: z.ZodString;
@@ -1419,7 +1449,6 @@ export declare const figureInputSchema: z.ZodDiscriminatedUnion<"type", [z.ZodOb
1419
1449
  }>, "many">>;
1420
1450
  }, "strict", z.ZodTypeAny, {
1421
1451
  label: string;
1422
- before: number;
1423
1452
  after: number;
1424
1453
  details?: {
1425
1454
  label: string;
@@ -1427,9 +1456,32 @@ export declare const figureInputSchema: z.ZodDiscriminatedUnion<"type", [z.ZodOb
1427
1456
  after: string;
1428
1457
  }[] | undefined;
1429
1458
  mono?: boolean | undefined;
1459
+ before?: number | undefined;
1460
+ limit?: number | undefined;
1461
+ }, {
1462
+ label: string;
1463
+ after: number;
1464
+ details?: {
1465
+ label: string;
1466
+ before: string;
1467
+ after: string;
1468
+ }[] | undefined;
1469
+ mono?: boolean | undefined;
1470
+ before?: number | undefined;
1471
+ limit?: number | undefined;
1472
+ }>, {
1473
+ label: string;
1474
+ after: number;
1475
+ details?: {
1476
+ label: string;
1477
+ before: string;
1478
+ after: string;
1479
+ }[] | undefined;
1480
+ mono?: boolean | undefined;
1481
+ before?: number | undefined;
1482
+ limit?: number | undefined;
1430
1483
  }, {
1431
1484
  label: string;
1432
- before: number;
1433
1485
  after: number;
1434
1486
  details?: {
1435
1487
  label: string;
@@ -1437,12 +1489,13 @@ export declare const figureInputSchema: z.ZodDiscriminatedUnion<"type", [z.ZodOb
1437
1489
  after: string;
1438
1490
  }[] | undefined;
1439
1491
  mono?: boolean | undefined;
1492
+ before?: number | undefined;
1493
+ limit?: number | undefined;
1440
1494
  }>, "many">;
1441
1495
  }, "strict", z.ZodTypeAny, {
1442
1496
  type: "compare";
1443
1497
  rows: {
1444
1498
  label: string;
1445
- before: number;
1446
1499
  after: number;
1447
1500
  details?: {
1448
1501
  label: string;
@@ -1450,6 +1503,8 @@ export declare const figureInputSchema: z.ZodDiscriminatedUnion<"type", [z.ZodOb
1450
1503
  after: string;
1451
1504
  }[] | undefined;
1452
1505
  mono?: boolean | undefined;
1506
+ before?: number | undefined;
1507
+ limit?: number | undefined;
1453
1508
  }[];
1454
1509
  title?: string | undefined;
1455
1510
  metric?: string | undefined;
@@ -1465,7 +1520,6 @@ export declare const figureInputSchema: z.ZodDiscriminatedUnion<"type", [z.ZodOb
1465
1520
  type: "compare";
1466
1521
  rows: {
1467
1522
  label: string;
1468
- before: number;
1469
1523
  after: number;
1470
1524
  details?: {
1471
1525
  label: string;
@@ -1473,6 +1527,8 @@ export declare const figureInputSchema: z.ZodDiscriminatedUnion<"type", [z.ZodOb
1473
1527
  after: string;
1474
1528
  }[] | undefined;
1475
1529
  mono?: boolean | undefined;
1530
+ before?: number | undefined;
1531
+ limit?: number | undefined;
1476
1532
  }[];
1477
1533
  title?: string | undefined;
1478
1534
  metric?: string | undefined;
@@ -2332,11 +2388,12 @@ export declare const figureToolInputSchema: z.ZodDiscriminatedUnion<"type", [z.Z
2332
2388
  value: number;
2333
2389
  label?: string | undefined;
2334
2390
  }>>;
2335
- rows: z.ZodArray<z.ZodObject<{
2391
+ rows: z.ZodArray<z.ZodEffects<z.ZodObject<{
2336
2392
  label: z.ZodString;
2337
2393
  mono: z.ZodOptional<z.ZodBoolean>;
2338
- before: z.ZodNumber;
2394
+ before: z.ZodOptional<z.ZodNumber>;
2339
2395
  after: z.ZodNumber;
2396
+ limit: z.ZodOptional<z.ZodNumber>;
2340
2397
  details: z.ZodOptional<z.ZodArray<z.ZodObject<{
2341
2398
  label: z.ZodString;
2342
2399
  before: z.ZodString;
@@ -2352,7 +2409,6 @@ export declare const figureToolInputSchema: z.ZodDiscriminatedUnion<"type", [z.Z
2352
2409
  }>, "many">>;
2353
2410
  }, "strict", z.ZodTypeAny, {
2354
2411
  label: string;
2355
- before: number;
2356
2412
  after: number;
2357
2413
  details?: {
2358
2414
  label: string;
@@ -2360,9 +2416,10 @@ export declare const figureToolInputSchema: z.ZodDiscriminatedUnion<"type", [z.Z
2360
2416
  after: string;
2361
2417
  }[] | undefined;
2362
2418
  mono?: boolean | undefined;
2419
+ before?: number | undefined;
2420
+ limit?: number | undefined;
2363
2421
  }, {
2364
2422
  label: string;
2365
- before: number;
2366
2423
  after: number;
2367
2424
  details?: {
2368
2425
  label: string;
@@ -2370,12 +2427,35 @@ export declare const figureToolInputSchema: z.ZodDiscriminatedUnion<"type", [z.Z
2370
2427
  after: string;
2371
2428
  }[] | undefined;
2372
2429
  mono?: boolean | undefined;
2430
+ before?: number | undefined;
2431
+ limit?: number | undefined;
2432
+ }>, {
2433
+ label: string;
2434
+ after: number;
2435
+ details?: {
2436
+ label: string;
2437
+ before: string;
2438
+ after: string;
2439
+ }[] | undefined;
2440
+ mono?: boolean | undefined;
2441
+ before?: number | undefined;
2442
+ limit?: number | undefined;
2443
+ }, {
2444
+ label: string;
2445
+ after: number;
2446
+ details?: {
2447
+ label: string;
2448
+ before: string;
2449
+ after: string;
2450
+ }[] | undefined;
2451
+ mono?: boolean | undefined;
2452
+ before?: number | undefined;
2453
+ limit?: number | undefined;
2373
2454
  }>, "many">;
2374
2455
  }, "strict", z.ZodTypeAny, {
2375
2456
  type: "compare";
2376
2457
  rows: {
2377
2458
  label: string;
2378
- before: number;
2379
2459
  after: number;
2380
2460
  details?: {
2381
2461
  label: string;
@@ -2383,6 +2463,8 @@ export declare const figureToolInputSchema: z.ZodDiscriminatedUnion<"type", [z.Z
2383
2463
  after: string;
2384
2464
  }[] | undefined;
2385
2465
  mono?: boolean | undefined;
2466
+ before?: number | undefined;
2467
+ limit?: number | undefined;
2386
2468
  }[];
2387
2469
  title?: string | undefined;
2388
2470
  metric?: string | undefined;
@@ -2398,7 +2480,6 @@ export declare const figureToolInputSchema: z.ZodDiscriminatedUnion<"type", [z.Z
2398
2480
  type: "compare";
2399
2481
  rows: {
2400
2482
  label: string;
2401
- before: number;
2402
2483
  after: number;
2403
2484
  details?: {
2404
2485
  label: string;
@@ -2406,6 +2487,8 @@ export declare const figureToolInputSchema: z.ZodDiscriminatedUnion<"type", [z.Z
2406
2487
  after: string;
2407
2488
  }[] | undefined;
2408
2489
  mono?: boolean | undefined;
2490
+ before?: number | undefined;
2491
+ limit?: number | undefined;
2409
2492
  }[];
2410
2493
  title?: string | undefined;
2411
2494
  metric?: string | undefined;
@@ -2704,6 +2787,8 @@ export declare function validateBlock(block: unknown): string[];
2704
2787
  export type FigureOptions = {
2705
2788
  /** The server lists figure_extras_v1: a stats title, more than 4 stats and runs_not_shown. */
2706
2789
  figureExtras?: boolean;
2790
+ /** The server lists figure_limits_v1: a compare row may carry a limit. */
2791
+ figureLimits?: boolean;
2707
2792
  /** The server lists diff_lines_v1: a diff may carry unchanged lines and line numbers. */
2708
2793
  diffLines?: boolean;
2709
2794
  /** The server lists log_lines_v1: it takes a log_lines figure. */
@@ -2730,6 +2815,16 @@ export declare function withoutFigureExtrasInBlock(block: unknown): {
2730
2815
  block: unknown;
2731
2816
  what: string[];
2732
2817
  };
2818
+ /**
2819
+ * A compare block as a server without figure_limits_v1 takes it: no `limit`
2820
+ * on a row. A row that had only a limit has no before then, so `unusable` is
2821
+ * true and the figure cannot be sent. Any other block is returned as it is.
2822
+ */
2823
+ export declare function withoutFigureLimitsInBlock(block: unknown): {
2824
+ block: unknown;
2825
+ what: string[];
2826
+ unusable: boolean;
2827
+ };
2733
2828
  /** Whether a block is a log_lines figure. */
2734
2829
  export declare function isLogLinesBlock(block: unknown): boolean;
2735
2830
  /**
package/dist/figures.js CHANGED
@@ -62,6 +62,8 @@ export const MAX_STATS_TILES = 4;
62
62
  const MAX_RUNS_NOT_SHOWN = 1_000_000;
63
63
  /** The server takes a stats title, more than 4 stats and runs_not_shown. */
64
64
  export const FIGURE_EXTRAS_CAPABILITY = "figure_extras_v1";
65
+ /** The server takes a `limit` on a compare row (the row is then "after against limit"). */
66
+ export const FIGURE_LIMITS_CAPABILITY = "figure_limits_v1";
65
67
  /** The server takes a log_lines figure. */
66
68
  export const LOG_LINES_CAPABILITY = "log_lines_v1";
67
69
  const number = z.number().finite().min(-MAX_ABS).max(MAX_ABS);
@@ -109,8 +111,11 @@ const compareBase = z
109
111
  .object({
110
112
  label: text(1, 80).describe("One host, route, query or job"),
111
113
  mono: z.boolean().optional().describe("Draw the label in a monospace face"),
112
- before: number,
114
+ before: number.optional().describe("The value before the change. Left out only on a row with a limit. Never put a limit or a budget here."),
113
115
  after: number,
116
+ limit: number
117
+ .optional()
118
+ .describe("A limit or budget the after value is measured against, in the figure's unit. Only when the server lists figure_limits_v1; the row then needs no before."),
114
119
  details: z
115
120
  .array(z
116
121
  .object({ label: text(1, 32), before: text(1, 32), after: text(1, 32) })
@@ -118,7 +123,8 @@ const compareBase = z
118
123
  .max(3)
119
124
  .optional(),
120
125
  })
121
- .strict())
126
+ .strict()
127
+ .refine((row) => row.before !== undefined || row.limit !== undefined, { message: "send before, or a limit to measure after against" }))
122
128
  .min(1)
123
129
  .max(8)
124
130
  .describe("One row per host, route, query or job, biggest movers first"),
@@ -1546,6 +1552,29 @@ export function withoutFigureExtrasInBlock(block) {
1546
1552
  }
1547
1553
  return what.length > 0 ? { block: record, what } : { block, what };
1548
1554
  }
1555
+ /**
1556
+ * A compare block as a server without figure_limits_v1 takes it: no `limit`
1557
+ * on a row. A row that had only a limit has no before then, so `unusable` is
1558
+ * true and the figure cannot be sent. Any other block is returned as it is.
1559
+ */
1560
+ export function withoutFigureLimitsInBlock(block) {
1561
+ if (typeof block !== "object" || block === null || Array.isArray(block))
1562
+ return { block, what: [], unusable: false };
1563
+ const record = block;
1564
+ if (record.type !== "compare" || !Array.isArray(record.rows) || !record.rows.some((row) => typeof row === "object" && row !== null && "limit" in row)) {
1565
+ return { block, what: [], unusable: false };
1566
+ }
1567
+ let unusable = false;
1568
+ const rows = record.rows.map((row) => {
1569
+ if (typeof row !== "object" || row === null)
1570
+ return row;
1571
+ const { limit: _limit, ...rest } = row;
1572
+ if (rest.before === undefined)
1573
+ unusable = true;
1574
+ return rest;
1575
+ });
1576
+ return { block: { ...record, rows }, what: ["the row limits"], unusable };
1577
+ }
1549
1578
  /** Whether a block is a log_lines figure. */
1550
1579
  export function isLogLinesBlock(block) {
1551
1580
  return typeof block === "object" && block !== null && block.type === "log_lines";
@@ -1686,6 +1715,19 @@ export function buildFigure(input, options = {}) {
1686
1715
  notes.push(`Left out ${stripped.what.join(" and ")}: this Tellagen does not list ${FIGURE_EXTRAS_CAPABILITY} in server_capabilities.`);
1687
1716
  }
1688
1717
  }
1718
+ if (options.figureLimits !== true) {
1719
+ const stripped = withoutFigureLimitsInBlock(block);
1720
+ if (stripped.what.length > 0) {
1721
+ if (stripped.unusable) {
1722
+ return {
1723
+ ok: false,
1724
+ issues: [`rows: this Tellagen does not list ${FIGURE_LIMITS_CAPABILITY} in server_capabilities, so a row needs before. Send the value before the change, or leave the limit out of the figure and say it in the caption.`],
1725
+ };
1726
+ }
1727
+ block = stripped.block;
1728
+ notes.push(`Left out ${stripped.what.join(" and ")}: this Tellagen does not list ${FIGURE_LIMITS_CAPABILITY} in server_capabilities.`);
1729
+ }
1730
+ }
1689
1731
  if (input.placement === "timeline_block") {
1690
1732
  if (input.slot)
1691
1733
  block.slot = input.slot;