@makine/cli 0.4.8 → 0.5.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 (56) hide show
  1. package/dist/accept/command.d.ts +25 -0
  2. package/dist/accept/command.d.ts.map +1 -0
  3. package/dist/accept/command.js +114 -0
  4. package/dist/accept/command.js.map +1 -0
  5. package/dist/connections/command.js +1 -0
  6. package/dist/connections/command.js.map +1 -1
  7. package/dist/contracts/command.d.ts +5 -1
  8. package/dist/contracts/command.d.ts.map +1 -1
  9. package/dist/contracts/command.js +92 -3
  10. package/dist/contracts/command.js.map +1 -1
  11. package/dist/index.d.ts +35 -4
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.js +386 -7
  14. package/dist/index.js.map +1 -1
  15. package/dist/judge/command.js +1 -0
  16. package/dist/judge/command.js.map +1 -1
  17. package/dist/keys/command.js +1 -0
  18. package/dist/keys/command.js.map +1 -1
  19. package/dist/lab/command.d.ts +30 -19
  20. package/dist/lab/command.d.ts.map +1 -1
  21. package/dist/lab/command.js +159 -7
  22. package/dist/lab/command.js.map +1 -1
  23. package/dist/lab/gate.d.ts +58 -0
  24. package/dist/lab/gate.d.ts.map +1 -0
  25. package/dist/lab/gate.js +124 -0
  26. package/dist/lab/gate.js.map +1 -0
  27. package/dist/lab/import.d.ts +46 -0
  28. package/dist/lab/import.d.ts.map +1 -0
  29. package/dist/lab/import.js +191 -0
  30. package/dist/lab/import.js.map +1 -0
  31. package/dist/login/command.d.ts.map +1 -1
  32. package/dist/login/command.js +3 -0
  33. package/dist/login/command.js.map +1 -1
  34. package/dist/main.js +7 -3
  35. package/dist/main.js.map +1 -1
  36. package/dist/quality/command.d.ts +47 -0
  37. package/dist/quality/command.d.ts.map +1 -0
  38. package/dist/quality/command.js +85 -0
  39. package/dist/quality/command.js.map +1 -0
  40. package/dist/receipts/command.d.ts +28 -0
  41. package/dist/receipts/command.d.ts.map +1 -0
  42. package/dist/receipts/command.js +220 -0
  43. package/dist/receipts/command.js.map +1 -0
  44. package/dist/reviews/command.d.ts.map +1 -1
  45. package/dist/reviews/command.js +1 -0
  46. package/dist/reviews/command.js.map +1 -1
  47. package/dist/suggestions/command.d.ts.map +1 -1
  48. package/dist/suggestions/command.js +29 -4
  49. package/dist/suggestions/command.js.map +1 -1
  50. package/dist/use-cases/command.d.ts +31 -0
  51. package/dist/use-cases/command.d.ts.map +1 -0
  52. package/dist/use-cases/command.js +213 -0
  53. package/dist/use-cases/command.js.map +1 -0
  54. package/dist/workflows/command.js +1 -0
  55. package/dist/workflows/command.js.map +1 -1
  56. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -6,10 +6,12 @@
6
6
  */
7
7
  import { readFileSync } from "node:fs";
8
8
  import { createInterface } from "node:readline";
9
- import { MakineBaselineClient, MakineContractsClient, MakineGatewayClient, MakineGatewayError, } from "@makine/sdk";
9
+ import { MakineBaselineClient, MakineContractsClient, MakineContractsError, MakineGatewayClient, MakineGatewayError, } from "@makine/sdk";
10
10
  import { BASELINE_SUBCOMMANDS, runBaseline, } from "./baseline/command.js";
11
11
  import { CHALLENGER_ACTIONS, CONTRACT_SUBCOMMANDS, runContracts, } from "./contracts/command.js";
12
+ import { USE_CASE_SUBCOMMANDS, runUseCases, } from "./use-cases/command.js";
12
13
  import { JUDGE_SUBCOMMANDS, runJudge, } from "./judge/command.js";
14
+ import { runReceipts, RECEIPTS_SUBCOMMANDS, } from "./receipts/command.js";
13
15
  import { SUGGESTIONS_SUBCOMMANDS, runSuggestions, } from "./suggestions/command.js";
14
16
  import { KEYS_SUBCOMMANDS, runKeys, } from "./keys/command.js";
15
17
  import { CONNECTIONS_SUBCOMMANDS, runConnections, } from "./connections/command.js";
@@ -18,6 +20,8 @@ import { CORRECTIONS_SUBCOMMANDS, DATASETS_SUBCOMMANDS, EXPERIMENTS_SUBCOMMANDS,
18
20
  import { runLogin, runLogout } from "./login/command.js";
19
21
  import { REVIEWS_SUBCOMMANDS, isReviewAction, isReviewsSubcommand, runReviews, } from "./reviews/command.js";
20
22
  import { runMigrate } from "./migrate/command.js";
23
+ import { runAccept } from "./accept/command.js";
24
+ import { runQuality } from "./quality/command.js";
21
25
  import { storedSessionFor } from "./session-store.js";
22
26
  /**
23
27
  * Exit codes are the CLI's contract with scripts. `RESULT_NOT_ACCEPTED` is a verdict, not a fault:
@@ -85,16 +89,22 @@ USAGE
85
89
  makine login Sign in as yourself, by approving a code in the dashboard
86
90
  makine logout End that session and delete the stored token
87
91
  makine run [prompt...] Send one buffered chat completion and print the verdict
88
- makine models List the model aliases this workspace may call
92
+ makine accept "<input>" Judge an answer your own system produced, with it on stdin
93
+ makine quality Acceptance and failure figures, as Quality in the dashboard
94
+ makine models [--used] List the model aliases this workspace may call; --used lists only
95
+ the names your application called in the last 30 days, with counts
89
96
  makine keys <cmd> Create, list, revoke and rotate this workspace's API keys
90
97
  makine contracts <cmd> Define what a good result is, and make it live
98
+ makine use-cases <cmd> Name a job, give it an address, and point it at a model
91
99
  makine judge <cmd> Switch the semantic judge on or off for this workspace
100
+ makine receipts <cmd> Trust an issuer once, then verify the receipts it signed, offline
92
101
  makine suggestions <cmd> Suggested prompt instructions, checks, schemas and fixes
93
102
  makine connections <cmd> Connect your own model provider, and keep it until you disconnect it
94
103
  makine workflows <cmd> Define an HTTP or container step, and approve the hosts it may reach
95
104
  makine baseline <cmd> Compare your model's first answer with what Makine delivered
96
105
  makine datasets <cmd> Keep the cases you judge a prompt or a contract against
97
106
  makine experiments <cmd> Run variants over a dataset and compare what each got accepted
107
+ run --wait polls to the end and gates on the pass rate
98
108
  makine corrections <cmd> The human corrections this workspace has written
99
109
  makine reviews <cmd> Work through the runs a contract parked for a person
100
110
  makine migrate <file> Translate a Portkey or LiteLLM config into makine.env settings
@@ -231,13 +241,52 @@ CONTRACTS
231
241
  makine contracts challengers Candidate contracts judging live traffic
232
242
  makine contracts challengers register <id>@<version> --model <alias>
233
243
  makine contracts challengers retire <registration_id>
244
+ makine contracts challengers list --use-case <address>
245
+ makine contracts test-check --file <contract.json> --answer <answer.txt>
246
+
247
+ A \`custom_code\` check runs the Python in your contract against one answer, in a sandbox that
248
+ resolves no hostname — but raw-IP egress is not blocked, so your own code can still reach out.
249
+ \`test-check\` runs it once before you save, so a syntax error is not something you discover from
250
+ a failed production run. It is hosted-only, and needs \`makine login\` rather than a workspace
251
+ key: a CI job holding a bare key cannot post a contract carrying the kind.
252
+
253
+ Python 3.13, the standard library only. No pip, no pandas, no numpy — for those, define a
254
+ container workflow step instead, which takes your own image.
255
+ 30 seconds, 1 vCPU, 512 MiB, and it draws on your workspace's daily sandbox budget.
256
+ \`observed\` takes booleans and finite numbers only, at most 16 keys. No strings: that bag is
257
+ shown in the dashboard and must not be able to carry the answer.
258
+ This runs once per answer. If your code uses the clock or randomness, two runs of the same
259
+ answer can disagree.
234
260
 
235
261
  An <id> is either the canonical id a read returned or the local part; both resolve. The file
236
262
  names its checks and repair plan by their local id. A contract is submitted before anything it
237
263
  pins is registered, so a refused contract leaves nothing behind. The API is the only validator:
238
264
  refusals are printed as the route worded them. Exit 2 means the request was refused.
239
265
 
266
+ USE CASES
267
+ makine use-cases list [--include-retired] Display name, address, target and figures
268
+ makine use-cases show <address> Addresses and their traffic, contract, figures
269
+ makine use-cases create <address> [--name <display>] [--model <model>]
270
+ makine use-cases name <address> <display name> What screens show; nothing else changes
271
+ makine use-cases point <address> --model <model> Move the job to another model
272
+ makine use-cases rename <address> <new address> The old address keeps resolving
273
+ makine use-cases remove-address <address> Free an older address for someone else
274
+ makine use-cases retire <address> Stop gating; the addresses stay held
275
+ makine use-cases restore <address> Put it back, with the same contract
276
+
277
+ An <address> is the string your application sends as \`model\`. Any address a use case still
278
+ answers to names it here, so a script written against the old name keeps working. With no
279
+ --model, \`create\` makes a use case named after the model that address already names, which is
280
+ how you organise traffic a model is already taking. Removing an address is the only thing that
281
+ frees it for another use case.
282
+
240
283
  THE SEMANTIC JUDGE
284
+ makine receipts trust <name> --origin <https-origin> Anchor an issuer by fetching its key list
285
+ makine receipts trust <name> --from-file <key-set> Anchor one by a hand-over, the stronger form
286
+ makine receipts trust <name> --refresh --origin <o> Refresh a record you already hold
287
+ makine receipts verify <file> [--issuer <name>] Check a receipt. NEVER fetches
288
+ makine receipts issuers The issuers you have anchored
289
+
241
290
  makine judge show Whether it is on, which model, and the statement
242
291
  makine judge enable --model <alias> [--yes] Agree to the statement and switch it on
243
292
  makine judge disable Switch it off for this workspace
@@ -319,6 +368,8 @@ export function parseArgs(argv) {
319
368
  return { ok: true, args: { ...args, command: "version" } };
320
369
  }
321
370
  if (head === "run" ||
371
+ head === "accept" ||
372
+ head === "quality" ||
322
373
  head === "models" ||
323
374
  head === "migrate" ||
324
375
  head === "login" ||
@@ -349,6 +400,41 @@ export function parseArgs(argv) {
349
400
  }
350
401
  }
351
402
  }
403
+ else if (head === "use-cases") {
404
+ args.command = head;
405
+ const sub = argv[1] ?? "list";
406
+ if (!isUseCaseSubcommand(sub)) {
407
+ return {
408
+ ok: false,
409
+ message: `\`makine use-cases\` needs one of ${USE_CASE_SUBCOMMANDS.join(", ")}.`,
410
+ };
411
+ }
412
+ args.useCaseSubcommand = sub;
413
+ index = argv[1] === undefined ? 1 : 2;
414
+ }
415
+ else if (head === "receipts") {
416
+ args.command = head;
417
+ const sub = argv[1];
418
+ if (sub === undefined || !RECEIPTS_SUBCOMMANDS.includes(sub)) {
419
+ return {
420
+ ok: false,
421
+ message: `\`makine receipts\` needs one of ${RECEIPTS_SUBCOMMANDS.join(", ")}.`,
422
+ };
423
+ }
424
+ args.receiptsSubcommand = sub;
425
+ // `trust <name>` and `verify <file>` both take one positional after the subcommand.
426
+ const positional = argv[2];
427
+ if (positional !== undefined && !positional.startsWith("--")) {
428
+ if (sub === "verify")
429
+ args.receiptFile = positional;
430
+ else
431
+ args.issuer = positional;
432
+ index = 3;
433
+ }
434
+ else {
435
+ index = 2;
436
+ }
437
+ }
352
438
  else if (head === "judge") {
353
439
  args.command = head;
354
440
  const sub = argv[1];
@@ -560,6 +646,24 @@ export function parseArgs(argv) {
560
646
  args.model = next;
561
647
  index += 1;
562
648
  break;
649
+ case "--issuer":
650
+ if (needsValue(token, next))
651
+ args.issuer = next;
652
+ index += 1;
653
+ break;
654
+ case "--origin":
655
+ if (needsValue(token, next))
656
+ args.origin = next;
657
+ index += 1;
658
+ break;
659
+ case "--from-file":
660
+ if (needsValue(token, next))
661
+ args.fromFile = next;
662
+ index += 1;
663
+ break;
664
+ case "--refresh":
665
+ args.refresh = true;
666
+ break;
563
667
  case "--system":
564
668
  if (needsValue(token, next))
565
669
  args.system = next;
@@ -590,6 +694,17 @@ export function parseArgs(argv) {
590
694
  args.name = next;
591
695
  index += 1;
592
696
  break;
697
+ case "--use-case":
698
+ if (needsValue(token, next))
699
+ args.useCase = next;
700
+ index += 1;
701
+ break;
702
+ case "--include-retired":
703
+ args.includeRetired = true;
704
+ break;
705
+ case "--used":
706
+ args.used = true;
707
+ break;
593
708
  case "--kinds":
594
709
  if (needsValue(token, next))
595
710
  args.suggestionKinds = next.split(",").map((k) => k.trim());
@@ -605,6 +720,36 @@ export function parseArgs(argv) {
605
720
  args.variantId = next;
606
721
  index += 1;
607
722
  break;
723
+ case "--wait":
724
+ args.wait = true;
725
+ break;
726
+ case "--min-pass-rate": {
727
+ if (!needsValue(token, next))
728
+ break;
729
+ const rate = Number(next);
730
+ if (!Number.isFinite(rate) || rate < 0 || rate > 1) {
731
+ return { ok: false, message: "--min-pass-rate takes a number between 0 and 1." };
732
+ }
733
+ args.minPassRate = rate;
734
+ index += 1;
735
+ break;
736
+ }
737
+ case "--baseline-run":
738
+ if (needsValue(token, next))
739
+ args.baselineRun = next;
740
+ index += 1;
741
+ break;
742
+ case "--timeout-minutes": {
743
+ if (!needsValue(token, next))
744
+ break;
745
+ const minutes = Number(next);
746
+ if (!Number.isInteger(minutes) || minutes <= 0) {
747
+ return { ok: false, message: "--timeout-minutes takes a whole number of minutes." };
748
+ }
749
+ args.timeoutMinutes = minutes;
750
+ index += 1;
751
+ break;
752
+ }
608
753
  case "--dataset":
609
754
  if (needsValue(token, next))
610
755
  args.datasetId = next;
@@ -635,11 +780,21 @@ export function parseArgs(argv) {
635
780
  args.shape = next;
636
781
  index += 1;
637
782
  break;
783
+ case "--run-purpose":
784
+ if (needsValue(token, next))
785
+ args.runPurpose = next;
786
+ index += 1;
787
+ break;
638
788
  case "--file":
639
789
  if (needsValue(token, next))
640
790
  args.file = next;
641
791
  index += 1;
642
792
  break;
793
+ case "--answer":
794
+ if (needsValue(token, next))
795
+ args.answerFile = next;
796
+ index += 1;
797
+ break;
643
798
  case "--header":
644
799
  if (needsValue(token, next))
645
800
  args.header = next;
@@ -662,6 +817,9 @@ export function parseArgs(argv) {
662
817
  }
663
818
  class CliUsageError extends Error {
664
819
  }
820
+ function isUseCaseSubcommand(value) {
821
+ return USE_CASE_SUBCOMMANDS.includes(value);
822
+ }
665
823
  function isContractSubcommand(value) {
666
824
  return CONTRACT_SUBCOMMANDS.includes(value);
667
825
  }
@@ -720,6 +878,25 @@ function parseOptimizeFor(value) {
720
878
  return value;
721
879
  throw new CliUsageError(`--optimize-for must be cost, latency or balanced, got \`${value}\`.`);
722
880
  }
881
+ /**
882
+ * A non-accepted verdict is `RESULT_NOT_ACCEPTED`, not a fault: Makine judged the answer and it
883
+ * did not clear the gate, which is what a CI step branches on.
884
+ */
885
+ const QUALITY_EXIT = {
886
+ ok: EXIT.ACCEPTED,
887
+ usage: EXIT.USAGE,
888
+ refused: EXIT.RESULT_NOT_ACCEPTED,
889
+ auth: EXIT.AUTH,
890
+ unreachable: EXIT.UNREACHABLE,
891
+ };
892
+ const ACCEPT_EXIT = {
893
+ accepted: EXIT.ACCEPTED,
894
+ not_accepted: EXIT.RESULT_NOT_ACCEPTED,
895
+ auth: EXIT.AUTH,
896
+ gateway: EXIT.GATEWAY,
897
+ unreachable: EXIT.UNREACHABLE,
898
+ usage: EXIT.USAGE,
899
+ };
723
900
  export async function runCli(argv, io) {
724
901
  const parsed = parseArgs(argv);
725
902
  if (!parsed.ok) {
@@ -749,6 +926,26 @@ export async function runCli(argv, io) {
749
926
  });
750
927
  return ok ? EXIT.ACCEPTED : EXIT.USAGE;
751
928
  }
929
+ if (args.command === "receipts") {
930
+ // Offline: the counterparty verifying a receipt has no Makine workspace, so neither a Gateway
931
+ // address nor a key may be demanded. `trust --origin` fetches the issuer's own origin, not ours.
932
+ const outcome = await runReceipts({
933
+ subcommand: args.receiptsSubcommand,
934
+ ...(args.issuer === undefined ? {} : { name: args.issuer }),
935
+ ...(args.origin === undefined ? {} : { origin: args.origin }),
936
+ ...(args.fromFile === undefined ? {} : { fromFile: args.fromFile }),
937
+ refresh: args.refresh === true,
938
+ ...(args.receiptFile === undefined ? {} : { receiptFile: args.receiptFile }),
939
+ json: args.json,
940
+ }, {
941
+ out: io.out,
942
+ err: io.err,
943
+ storeDirectory: receiptsStoreDirectory(),
944
+ // `verify` is never given a fetcher: a verification run is offline by construction.
945
+ ...(args.receiptsSubcommand === "trust" ? { fetchKeySet: fetchReceiptKeySet(io) } : {}),
946
+ });
947
+ return RECEIPTS_EXIT[outcome];
948
+ }
752
949
  const configuredAddress = args.baseUrl ?? io.env.MAKINE_BASE_URL;
753
950
  if (configuredAddress === undefined || configuredAddress.trim().length === 0) {
754
951
  io.err("No Makine address. Set MAKINE_BASE_URL to the dashboard's origin plus /api, as Home's setup step shows it, or pass --base-url.");
@@ -776,6 +973,44 @@ export async function runCli(argv, io) {
776
973
  }
777
974
  const apiKey = credential;
778
975
  const explicitKey = (args.apiKey ?? io.env.MAKINE_API_KEY ?? "").trim().length > 0;
976
+ if (args.command === "quality") {
977
+ const connection = {
978
+ baseUrl,
979
+ apiKey,
980
+ ...(io.fetchImpl === undefined ? {} : { fetchImpl: io.fetchImpl }),
981
+ };
982
+ let useCaseId;
983
+ if (args.useCase !== undefined) {
984
+ useCaseId = await resolveUseCaseIdByAddress(args.useCase, connection);
985
+ if (useCaseId === undefined) {
986
+ io.err(`${args.useCase} reaches no use case in this workspace.`);
987
+ return EXIT.USAGE;
988
+ }
989
+ }
990
+ const outcome = await runQuality({
991
+ json: args.json,
992
+ ...(args.runPurpose === undefined ? {} : { runPurpose: args.runPurpose }),
993
+ ...(useCaseId === undefined ? {} : { useCaseId }),
994
+ ...(args.from === undefined ? {} : { from: args.from }),
995
+ ...(args.to === undefined ? {} : { to: args.to }),
996
+ }, connection, { out: io.out, err: io.err });
997
+ return QUALITY_EXIT[outcome];
998
+ }
999
+ if (args.command === "accept") {
1000
+ const outcome = await runAccept({
1001
+ input: args.prompt.join(" "),
1002
+ answer: io.stdin ?? "",
1003
+ json: args.json,
1004
+ ...(args.contract === undefined ? {} : { contract: args.contract }),
1005
+ ...(args.useCase === undefined ? {} : { useCase: args.useCase }),
1006
+ ...(args.model === undefined ? {} : { model: args.model }),
1007
+ }, {
1008
+ baseUrl,
1009
+ apiKey,
1010
+ ...(io.fetchImpl === undefined ? {} : { fetchImpl: io.fetchImpl }),
1011
+ }, { out: io.out, err: io.err });
1012
+ return ACCEPT_EXIT[outcome];
1013
+ }
779
1014
  if (args.command === "reviews") {
780
1015
  const outcome = await runReviews({
781
1016
  subcommand: args.reviewsSubcommand,
@@ -815,7 +1050,9 @@ export async function runCli(argv, io) {
815
1050
  ...(args.prompt[0] === undefined ? {} : { target: args.prompt[0] }),
816
1051
  ...(args.model === undefined ? {} : { model: args.model }),
817
1052
  ...(args.file === undefined ? {} : { file: args.file }),
1053
+ ...(args.answerFile === undefined ? {} : { answerFile: args.answerFile }),
818
1054
  ...(args.challengerAction === undefined ? {} : { action: args.challengerAction }),
1055
+ ...(args.useCase === undefined ? {} : { useCase: args.useCase }),
819
1056
  json: args.json,
820
1057
  }, contracts, {
821
1058
  out: io.out,
@@ -824,6 +1061,26 @@ export async function runCli(argv, io) {
824
1061
  });
825
1062
  return CONTRACTS_EXIT[outcome];
826
1063
  }
1064
+ if (args.command === "use-cases") {
1065
+ const contracts = new MakineContractsClient({
1066
+ baseUrl,
1067
+ apiKey,
1068
+ ...(io.fetchImpl === undefined ? {} : { fetchImpl: io.fetchImpl }),
1069
+ });
1070
+ const outcome = await runUseCases({
1071
+ subcommand: args.useCaseSubcommand,
1072
+ ...(args.prompt[0] === undefined ? {} : { target: args.prompt[0] }),
1073
+ ...(args.prompt[1] === undefined
1074
+ ? args.name === undefined
1075
+ ? {}
1076
+ : { value: args.name }
1077
+ : { value: args.prompt.slice(1).join(" ") }),
1078
+ ...(args.model === undefined ? {} : { model: args.model }),
1079
+ includeRetired: args.includeRetired === true,
1080
+ json: args.json,
1081
+ }, contracts, { out: io.out, err: io.err });
1082
+ return USE_CASES_EXIT[outcome];
1083
+ }
827
1084
  if (args.command === "judge") {
828
1085
  const outcome = await runJudge({
829
1086
  subcommand: args.judgeSubcommand,
@@ -936,6 +1193,20 @@ export async function runCli(argv, io) {
936
1193
  if (args.command === "datasets" ||
937
1194
  args.command === "experiments" ||
938
1195
  args.command === "corrections") {
1196
+ const connection = {
1197
+ baseUrl,
1198
+ apiKey,
1199
+ ...(io.fetchImpl === undefined ? {} : { fetchImpl: io.fetchImpl }),
1200
+ };
1201
+ // `--use-case` names an address; the route takes an id, so it is resolved before the call.
1202
+ let useCaseId;
1203
+ if (args.useCase !== undefined) {
1204
+ useCaseId = await resolveUseCaseIdByAddress(args.useCase, connection);
1205
+ if (useCaseId === undefined) {
1206
+ io.err(`${args.useCase} reaches no use case in this workspace.`);
1207
+ return EXIT.USAGE;
1208
+ }
1209
+ }
939
1210
  const invocation = {
940
1211
  subcommand: args.labSubcommand,
941
1212
  ...(args.prompt[0] === undefined ? {} : { target: args.prompt[0] }),
@@ -943,19 +1214,23 @@ export async function runCli(argv, io) {
943
1214
  ...(args.variantId === undefined ? {} : { variantId: args.variantId }),
944
1215
  ...(args.datasetId === undefined ? {} : { datasetId: args.datasetId }),
945
1216
  ...(args.from === undefined ? {} : { from: args.from }),
1217
+ ...(args.file === undefined ? {} : { file: args.file }),
1218
+ ...(useCaseId === undefined ? {} : { useCaseId }),
1219
+ ...(args.wait === undefined ? {} : { wait: args.wait }),
1220
+ ...(args.minPassRate === undefined ? {} : { minPassRate: args.minPassRate }),
1221
+ ...(args.baselineRun === undefined ? {} : { baselineRun: args.baselineRun }),
1222
+ ...(args.timeoutMinutes === undefined ? {} : { timeoutMinutes: args.timeoutMinutes }),
946
1223
  json: args.json,
947
1224
  };
948
- const connection = {
949
- baseUrl,
950
- apiKey,
951
- ...(io.fetchImpl === undefined ? {} : { fetchImpl: io.fetchImpl }),
952
- };
953
1225
  const labIo = {
954
1226
  out: io.out,
955
1227
  err: io.err,
956
1228
  readCases: io.readCredentialImpl === undefined
957
1229
  ? () => readCredentialFromStdin("")
958
1230
  : () => io.readCredentialImpl(""),
1231
+ readFile: io.readFileImpl ?? ((path) => readFileSync(path, "utf8")),
1232
+ ...(io.sleepImpl === undefined ? {} : { sleep: io.sleepImpl }),
1233
+ ...(io.nowMsImpl === undefined ? {} : { nowMs: io.nowMsImpl }),
959
1234
  };
960
1235
  const outcome = args.command === "datasets"
961
1236
  ? await runDatasets(invocation, connection, labIo)
@@ -976,6 +1251,13 @@ export async function runCli(argv, io) {
976
1251
  ...(io.fetchImpl === undefined ? {} : { fetchImpl: io.fetchImpl }),
977
1252
  });
978
1253
  try {
1254
+ if (args.command === "models" && args.used === true) {
1255
+ return await commandRequestedModels(new MakineContractsClient({
1256
+ baseUrl,
1257
+ apiKey,
1258
+ ...(io.fetchImpl === undefined ? {} : { fetchImpl: io.fetchImpl }),
1259
+ }), args, io);
1260
+ }
979
1261
  return args.command === "models"
980
1262
  ? await commandModels(client, args, io)
981
1263
  : await commandRun(client, args, io);
@@ -1012,6 +1294,66 @@ const CONTRACTS_EXIT = {
1012
1294
  auth: EXIT.AUTH,
1013
1295
  unavailable: EXIT.UNREACHABLE,
1014
1296
  };
1297
+ /** The id behind an address, for the flags that scope a Lab read by use case. */
1298
+ async function resolveUseCaseIdByAddress(address, connection) {
1299
+ const client = new MakineContractsClient(connection);
1300
+ const wanted = address.trim().toLowerCase();
1301
+ const body = await client.listUseCases({ includeRetired: true });
1302
+ for (const useCase of body.use_cases) {
1303
+ if (useCase.address !== null && useCase.address.trim().toLowerCase() === wanted) {
1304
+ return useCase.use_case_id;
1305
+ }
1306
+ }
1307
+ for (const useCase of body.use_cases) {
1308
+ const detail = await client.readUseCase(useCase.use_case_id);
1309
+ if (detail.addresses.some((row) => row.address.trim().toLowerCase() === wanted)) {
1310
+ return useCase.use_case_id;
1311
+ }
1312
+ }
1313
+ return undefined;
1314
+ }
1315
+ const USE_CASES_EXIT = {
1316
+ ok: EXIT.ACCEPTED,
1317
+ usage: EXIT.USAGE,
1318
+ refused: EXIT.RESULT_NOT_ACCEPTED,
1319
+ auth: EXIT.AUTH,
1320
+ unavailable: EXIT.UNREACHABLE,
1321
+ };
1322
+ /**
1323
+ * Where trusted issuer records live: the operator's own machine, beside the session store. They are
1324
+ * the verifier's objects, not Makine's, so they never leave it.
1325
+ */
1326
+ function receiptsStoreDirectory() {
1327
+ const home = process.env.HOME ?? process.env.USERPROFILE ?? ".";
1328
+ return `${home}/.makine`;
1329
+ }
1330
+ /**
1331
+ * The one Part A step that reaches the network, and only for `trust --origin`. The fetch refuses a
1332
+ * redirect to another origin: an origin anchor is exactly as strong as the certificate the web PKI
1333
+ * vouched for at fetch time, and a followed redirect would anchor a host nobody checked.
1334
+ */
1335
+ function fetchReceiptKeySet(io) {
1336
+ return async (origin) => {
1337
+ const url = new URL("/.well-known/makine-receipt-keys.json", origin);
1338
+ if (url.protocol !== "https:") {
1339
+ throw new Error("An origin anchor must be https: there is no certificate to check otherwise.");
1340
+ }
1341
+ const response = await (io.fetchImpl ?? fetch)(url, { redirect: "manual" });
1342
+ if (response.status >= 300 && response.status < 400) {
1343
+ throw new Error("The key set answered a redirect, which is never followed.");
1344
+ }
1345
+ if (!response.ok)
1346
+ throw new Error(`The key set answered ${String(response.status)}.`);
1347
+ return (await response.json());
1348
+ };
1349
+ }
1350
+ const RECEIPTS_EXIT = {
1351
+ ok: EXIT.ACCEPTED,
1352
+ usage: EXIT.USAGE,
1353
+ refused: EXIT.RESULT_NOT_ACCEPTED,
1354
+ // A receipt that did not verify is not an error in the tool; it is the answer.
1355
+ unverified: EXIT.RESULT_NOT_ACCEPTED,
1356
+ };
1015
1357
  const JUDGE_EXIT = {
1016
1358
  ok: EXIT.ACCEPTED,
1017
1359
  usage: EXIT.USAGE,
@@ -1040,11 +1382,18 @@ const REVIEWS_EXIT = {
1040
1382
  auth: EXIT.AUTH,
1041
1383
  unavailable: EXIT.UNREACHABLE,
1042
1384
  };
1385
+ /**
1386
+ * Under `--wait`, every HTTP refusal other than 401 and 403, the timeout and a `failed` run map to
1387
+ * `gateway`, so a `2` from CI means a gate failure and nothing else. The other subcommands keep
1388
+ * their mapping (ADR 0014 § D14.15).
1389
+ */
1043
1390
  const LAB_EXIT = {
1044
1391
  ok: EXIT.ACCEPTED,
1045
1392
  usage: EXIT.USAGE,
1046
1393
  refused: EXIT.RESULT_NOT_ACCEPTED,
1394
+ gate_failed: EXIT.RESULT_NOT_ACCEPTED,
1047
1395
  auth: EXIT.AUTH,
1396
+ gateway: EXIT.GATEWAY,
1048
1397
  unavailable: EXIT.UNREACHABLE,
1049
1398
  };
1050
1399
  const CONNECTIONS_EXIT = {
@@ -1111,6 +1460,36 @@ async function commandModels(client, args, io) {
1111
1460
  io.out(`${model.id}\t(${model.owned_by})`);
1112
1461
  return EXIT.ACCEPTED;
1113
1462
  }
1463
+ async function commandRequestedModels(contracts, args, io) {
1464
+ let list;
1465
+ try {
1466
+ list = await contracts.listRequestedModels();
1467
+ }
1468
+ catch (error) {
1469
+ // This route answers the acceptance envelope, not the Gateway's, so `reportError` cannot read it.
1470
+ if (!(error instanceof MakineContractsError))
1471
+ throw error;
1472
+ io.err(error.message);
1473
+ if (error.status === 401 || error.status === 403)
1474
+ return EXIT.AUTH;
1475
+ return error.status >= 500 ? EXIT.UNREACHABLE : EXIT.RESULT_NOT_ACCEPTED;
1476
+ }
1477
+ if (args.json) {
1478
+ io.out(JSON.stringify(list, null, 2));
1479
+ return EXIT.ACCEPTED;
1480
+ }
1481
+ if (list.names.length === 0) {
1482
+ io.out(`No requests in the last ${list.window_days} days.`);
1483
+ return EXIT.ACCEPTED;
1484
+ }
1485
+ for (const row of list.names) {
1486
+ io.out(`${row.name}\t${row.request_count.toLocaleString("en-US")}`);
1487
+ }
1488
+ if (list.truncated) {
1489
+ io.out(`Only the ${list.names.length.toLocaleString("en-US")} most-requested names are shown.`);
1490
+ }
1491
+ return EXIT.ACCEPTED;
1492
+ }
1114
1493
  async function commandRun(client, args, io) {
1115
1494
  const model = args.model ?? io.env.MAKINE_MODEL;
1116
1495
  if (model === undefined || model.trim().length === 0) {