stitchkit 0.124.4 → 0.125.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 (59) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/dist/entrypoints/agent-runtime/coding-tools.js +3 -3
  3. package/dist/entrypoints/agent-runtime/harness.js +4 -4
  4. package/dist/entrypoints/agent-runtime/sandbox.js +3 -3
  5. package/dist/entrypoints/agent-runtime/sqlite/bun.js +5 -5
  6. package/dist/entrypoints/agent-runtime/sqlite/node.js +5 -5
  7. package/dist/entrypoints/agent-runtime/testing.js +5 -5
  8. package/dist/entrypoints/agent-runtime.js +11 -11
  9. package/dist/entrypoints/cli.js +8 -7
  10. package/dist/entrypoints/testing.js +1 -1
  11. package/dist/entrypoints/tools/agent.js +6 -6
  12. package/dist/entrypoints/tools/connections.js +2 -2
  13. package/dist/entrypoints/tools/invoker.js +4 -4
  14. package/dist/entrypoints/tools/mcp.js +6 -6
  15. package/dist/entrypoints/tools/toolkit.js +8 -8
  16. package/dist/entrypoints/tools.js +7 -7
  17. package/dist/{index-afc3mtah.js → index-0sg3wnzr.js} +1 -1
  18. package/dist/{index-cm07qz01.js → index-1v3k5zgx.js} +1 -1
  19. package/dist/{index-x68eyh6y.js → index-7cn66qdk.js} +2 -2
  20. package/dist/{index-6fmg17bg.js → index-8wzhmgpa.js} +1 -1
  21. package/dist/{index-xaem29dc.js → index-a3z56mtn.js} +1 -1
  22. package/dist/{index-en2xqhty.js → index-cj5f0x4y.js} +1 -1
  23. package/dist/{index-z2z67tnv.js → index-cvjddnvd.js} +3 -3
  24. package/dist/{index-3n8k175r.js → index-fgzbc06j.js} +4 -4
  25. package/dist/{index-q7s1yr9g.js → index-kxff9e9w.js} +3 -3
  26. package/dist/{index-r7v5xz0g.js → index-m0wsfmrc.js} +1 -1
  27. package/dist/{index-2ds89z96.js → index-n6hvd1r2.js} +4 -4
  28. package/dist/{index-p9saezh1.js → index-r8swbw1x.js} +1 -1
  29. package/dist/{index-a3ekss9t.js → index-v7rbjatr.js} +230 -201
  30. package/dist/{index-rk7m4j7r.js → index-x2d51zay.js} +9 -10
  31. package/dist/{index-1wz4y15d.js → index-x2rvpbtj.js} +1 -1
  32. package/dist/tools/cli/args-route.d.ts +11 -0
  33. package/dist/tools/cli/args-route.d.ts.map +1 -1
  34. package/dist/tools/cli/args.d.ts.map +1 -1
  35. package/dist/tools/cli/command-shape.d.ts +4 -0
  36. package/dist/tools/cli/command-shape.d.ts.map +1 -1
  37. package/dist/tools/cli/create-cli.d.ts.map +1 -1
  38. package/dist/tools/cli/managed-surface.d.ts.map +1 -1
  39. package/dist/tools/cli/notices.d.ts +5 -0
  40. package/dist/tools/cli/notices.d.ts.map +1 -0
  41. package/dist/tools/cli/profile.d.ts +1 -1
  42. package/dist/tools/cli/profile.d.ts.map +1 -1
  43. package/dist/tools/cli/run-managed.d.ts.map +1 -1
  44. package/dist/tools/cli/session.d.ts +2 -1
  45. package/dist/tools/cli/session.d.ts.map +1 -1
  46. package/dist/tools/cli/stream-surface.d.ts +6 -1
  47. package/dist/tools/cli/stream-surface.d.ts.map +1 -1
  48. package/dist/tools/cli/unavailable.d.ts +0 -6
  49. package/dist/tools/cli/unavailable.d.ts.map +1 -1
  50. package/dist/tools/internal/surface-projector.d.ts +2 -0
  51. package/dist/tools/internal/surface-projector.d.ts.map +1 -1
  52. package/llms/cli.2.txt +1 -1
  53. package/llms/cli.txt +32 -4
  54. package/llms/stitchkit.txt +3 -3
  55. package/llms/{upgrading-0.106.0-0.124.0.txt → upgrading-0.106.0-0.125.0.txt} +26 -3
  56. package/llms/upgrading.txt +1 -1
  57. package/llms-full.txt +59 -8
  58. package/llms.txt +2 -2
  59. package/package.json +1 -1
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  projectRuntimeTool
3
- } from "./index-rk7m4j7r.js";
3
+ } from "./index-x2d51zay.js";
4
4
  import {
5
5
  isRecord
6
6
  } from "./index-hkxgennw.js";
@@ -2,11 +2,11 @@ import {
2
2
  toolResultFromError,
3
3
  toolCauseFromResult,
4
4
  isToolExecutionControlError2
5
- } from "./index-1wz4y15d.js";
5
+ } from "./index-x2rvpbtj.js";
6
6
  import {
7
7
  createToolRunner,
8
8
  formatToolError
9
- } from "./index-x68eyh6y.js";
9
+ } from "./index-7cn66qdk.js";
10
10
  import {
11
11
  resolveRuntimeToolCall
12
12
  } from "./index-eh71zr32.js";
@@ -15,10 +15,10 @@ import {
15
15
  } from "./index-1psbyyhj.js";
16
16
  import {
17
17
  collectToolSurface
18
- } from "./index-q7s1yr9g.js";
18
+ } from "./index-kxff9e9w.js";
19
19
  import {
20
20
  agentPresenterOf
21
- } from "./index-r7v5xz0g.js";
21
+ } from "./index-m0wsfmrc.js";
22
22
  import {
23
23
  isRecord
24
24
  } from "./index-hkxgennw.js";
@@ -17,7 +17,7 @@ import {
17
17
  replaceMessage,
18
18
  ArchiveSpillSchema,
19
19
  createAgentRuntimeStore2
20
- } from "./index-afc3mtah.js";
20
+ } from "./index-0sg3wnzr.js";
21
21
 
22
22
  // src/agent-runtime/store-memory.ts
23
23
  import { z as z2 } from "zod";
@@ -18,16 +18,17 @@ import {
18
18
  mergeSchemas,
19
19
  toToolName,
20
20
  assertUniqueToolName,
21
- buildToolPresentationSchema
22
- } from "./index-rk7m4j7r.js";
21
+ buildToolPresentationSchema,
22
+ projectedContractToolName
23
+ } from "./index-x2d51zay.js";
23
24
  import {
24
25
  toolResultFromError,
25
26
  toolErrorFromResult
26
- } from "./index-1wz4y15d.js";
27
+ } from "./index-x2rvpbtj.js";
27
28
  import {
28
29
  createToolRunner,
29
30
  formatToolError
30
- } from "./index-x68eyh6y.js";
31
+ } from "./index-7cn66qdk.js";
31
32
  import {
32
33
  isRepeatableRead
33
34
  } from "./index-332d0m9g.js";
@@ -54,7 +55,7 @@ import {
54
55
  } from "./index-9cxxfkhb.js";
55
56
  import {
56
57
  collectToolSurface
57
- } from "./index-q7s1yr9g.js";
58
+ } from "./index-kxff9e9w.js";
58
59
  import {
59
60
  fetchGuarded,
60
61
  readCapped
@@ -646,15 +647,21 @@ function assertCliPoliciesResolved(commands, config) {
646
647
  }
647
648
 
648
649
  // src/tools/cli/stream-surface.ts
650
+ function cliStreamIdentity(serviceName, methodName, method) {
651
+ if (!method.stream || !method.expose?.includes("CLI"))
652
+ return;
653
+ return { name: toToolName(serviceName, methodName), descriptor: method.stream };
654
+ }
649
655
  function collectCliStreams(services) {
650
656
  const streams = new Map;
651
657
  for (const service of services) {
652
658
  for (const [methodName, method] of Object.entries(service.methods)) {
653
- if (method.stream === undefined || !method.expose?.includes("CLI"))
659
+ const identity = cliStreamIdentity(service.name, methodName, method);
660
+ if (identity === undefined)
654
661
  continue;
655
- const name = toToolName(service.name, methodName);
662
+ const { name, descriptor } = identity;
656
663
  streams.set(name, {
657
- descriptor: method.stream,
664
+ descriptor,
658
665
  tool: {
659
666
  method,
660
667
  name,
@@ -943,6 +950,180 @@ function createCliIo(config) {
943
950
  return { stdout, stdoutWhileOpen, stderr, exit, readStdin };
944
951
  }
945
952
 
953
+ // src/tools/cli/notices.ts
954
+ import { AsyncLocalStorage } from "node:async_hooks";
955
+
956
+ // src/tools/cli/args-route.ts
957
+ function isOptionToken(token) {
958
+ return token.startsWith("--") || /^-[A-Za-z](?:=|$)/.test(token);
959
+ }
960
+ function looksLikeOption(token) {
961
+ return token.startsWith("--") || /^-[A-Za-z]/.test(token);
962
+ }
963
+ var BOOL_OPTIONS = new Set([
964
+ "json",
965
+ "wait",
966
+ "quiet",
967
+ "dry-run",
968
+ "help",
969
+ "schema",
970
+ "ascending"
971
+ ]);
972
+ var VIEW_OPTIONS = new Set(["count-by", "sum", "by", "top", "table", "sort"]);
973
+ var VALUE_OPTIONS = new Set(["wait-timeout", "output-dir", ...VIEW_OPTIONS]);
974
+ var RESERVED_CLI_OPTIONS = new Set([...BOOL_OPTIONS, ...VALUE_OPTIONS]);
975
+ function classifyLongOptionToken(token) {
976
+ if (!token.startsWith("--") || token === "--")
977
+ return;
978
+ const equals = token.indexOf("=");
979
+ const name = equals >= 0 ? token.slice(2, equals) : token.slice(2);
980
+ return {
981
+ name,
982
+ value: equals >= 0 ? token.slice(equals + 1) : undefined,
983
+ inline: equals >= 0,
984
+ globalKind: BOOL_OPTIONS.has(name) ? "boolean" : VALUE_OPTIONS.has(name) ? "value" : undefined
985
+ };
986
+ }
987
+ function readCliBooleanFlag(argv, name) {
988
+ const request = name === "help" || name === "schema";
989
+ for (const [index, token] of argv.entries()) {
990
+ if (token === "--")
991
+ break;
992
+ if (token === undefined)
993
+ continue;
994
+ if (name === "help" && token === "-h")
995
+ return true;
996
+ const option = classifyLongOptionToken(token);
997
+ if (option?.name !== name || option.globalKind !== "boolean")
998
+ continue;
999
+ const enabled = option.value === undefined ? separateBoolValue(argv[index + 1]) ?? true : isReservedBoolWord(option.value) && parseReservedBool(name, option.value);
1000
+ if (enabled || !request)
1001
+ return enabled;
1002
+ }
1003
+ return false;
1004
+ }
1005
+ function preserveCliBooleanBoundary(prefix, next) {
1006
+ if (separateBoolValue(next) === undefined)
1007
+ return;
1008
+ const last = prefix.at(-1);
1009
+ const option = last === undefined ? undefined : classifyLongOptionToken(last);
1010
+ if (option?.globalKind === "boolean" && !option.inline) {
1011
+ prefix[prefix.length - 1] = last === "--help" ? "-h" : `${last}=true`;
1012
+ }
1013
+ }
1014
+ var HELP_TOKENS = new Set(["--help", "-h", "help"]);
1015
+ function isCliVersionToken(token) {
1016
+ return token === "--version" || token === "version";
1017
+ }
1018
+ function isReservedCliCommandName(name) {
1019
+ return name === "--" || HELP_TOKENS.has(name) || isCliVersionToken(name) || classifyLongOptionToken(name)?.globalKind !== undefined;
1020
+ }
1021
+ function helpFilterFrom(token, rest) {
1022
+ if (token?.startsWith("--help=")) {
1023
+ const value = token.slice("--help=".length).trim();
1024
+ if (value.length === 0 || isReservedBoolWord(value))
1025
+ return;
1026
+ return value;
1027
+ }
1028
+ if (token === undefined || !HELP_TOKENS.has(token))
1029
+ return;
1030
+ const next = rest[0];
1031
+ return next !== undefined && !next.startsWith("-") ? next : undefined;
1032
+ }
1033
+ function isTopHelpOption(token) {
1034
+ return token === "--help" || token === "-h" || token.startsWith("--help=") && !isReservedBoolWord(token.slice("--help=".length));
1035
+ }
1036
+ function leadingGlobalCount(argv, hasDefault) {
1037
+ let index = 0;
1038
+ while (index < argv.length) {
1039
+ const token = argv[index];
1040
+ if (token === undefined || isTopHelpOption(token))
1041
+ break;
1042
+ const option = classifyLongOptionToken(token);
1043
+ if (!option?.globalKind)
1044
+ break;
1045
+ index++;
1046
+ if (option.inline)
1047
+ continue;
1048
+ const value = argv[index];
1049
+ if (value === undefined)
1050
+ break;
1051
+ if (option.globalKind === "boolean") {
1052
+ if (separateBoolValue(value) !== undefined)
1053
+ index++;
1054
+ } else {
1055
+ if (value === "--" || value === "--help" || value === "-h" || value === "--version" || hasDefault && value === "version") {
1056
+ break;
1057
+ }
1058
+ if (hasDefault || !classifyLongOptionToken(value)?.globalKind)
1059
+ index++;
1060
+ }
1061
+ }
1062
+ return index;
1063
+ }
1064
+ function routeCliArgv2(argv, defaultCommand) {
1065
+ const index = leadingGlobalCount(argv, defaultCommand !== undefined);
1066
+ const token = argv[index];
1067
+ if (token === "--" && (index > 0 || defaultCommand !== undefined)) {
1068
+ return {
1069
+ commandArgv: [],
1070
+ topLevelHelp: false,
1071
+ version: false,
1072
+ error: 'A command is required before "--"'
1073
+ };
1074
+ }
1075
+ if (defaultCommand !== undefined) {
1076
+ if (token !== undefined && isTopHelpOption(token)) {
1077
+ const helpFilter = helpFilterFrom(token, argv.slice(index + 1));
1078
+ return {
1079
+ commandArgv: [],
1080
+ topLevelHelp: true,
1081
+ version: false,
1082
+ ...helpFilter !== undefined && { helpFilter }
1083
+ };
1084
+ }
1085
+ if (isCliVersionToken(token)) {
1086
+ return { commandArgv: [], topLevelHelp: false, version: true };
1087
+ }
1088
+ if (token === undefined || token.startsWith("-") && token !== "-") {
1089
+ return {
1090
+ command: defaultCommand,
1091
+ commandArgv: argv.slice(),
1092
+ topLevelHelp: false,
1093
+ version: false
1094
+ };
1095
+ }
1096
+ }
1097
+ const commandIndex = token === undefined ? 0 : index;
1098
+ const command = argv[commandIndex];
1099
+ const rest = argv.slice(commandIndex + 1);
1100
+ const prefix = argv.slice(0, commandIndex);
1101
+ preserveCliBooleanBoundary(prefix, rest[0]);
1102
+ const helpFilter = commandIndex > 0 || defaultCommand === undefined ? helpFilterFrom(command, rest) : undefined;
1103
+ return {
1104
+ command,
1105
+ commandArgv: prefix.concat(rest),
1106
+ topLevelHelp: false,
1107
+ version: false,
1108
+ ...helpFilter !== undefined && { helpFilter }
1109
+ };
1110
+ }
1111
+
1112
+ // src/tools/cli/notices.ts
1113
+ var invocationNotices = new AsyncLocalStorage;
1114
+ function withCliNotices(quiet, stderr, run) {
1115
+ return invocationNotices.run({ quiet, stderr }, run);
1116
+ }
1117
+ function writeCliNotice(text) {
1118
+ const invocation = invocationNotices.getStore();
1119
+ if (invocation !== undefined) {
1120
+ if (!invocation.quiet)
1121
+ invocation.stderr(text);
1122
+ } else if (!readCliBooleanFlag(process.argv.slice(2), "quiet")) {
1123
+ process.stderr.write(text);
1124
+ }
1125
+ }
1126
+
946
1127
  // src/tools/cli/download.ts
947
1128
  import { createHash } from "node:crypto";
948
1129
  import { basename as basename2, resolve } from "node:path";
@@ -1350,169 +1531,28 @@ function renderCommandHelp(name, command, descriptor, applicationOptions = []) {
1350
1531
  `;
1351
1532
  }
1352
1533
 
1353
- // src/tools/cli/args-route.ts
1354
- function isOptionToken(token) {
1355
- return token.startsWith("--") || /^-[A-Za-z](?:=|$)/.test(token);
1356
- }
1357
- function looksLikeOption(token) {
1358
- return token.startsWith("--") || /^-[A-Za-z]/.test(token);
1359
- }
1360
- var BOOL_OPTIONS = new Set([
1361
- "json",
1362
- "wait",
1363
- "quiet",
1364
- "dry-run",
1365
- "help",
1366
- "schema",
1367
- "ascending"
1368
- ]);
1369
- var VIEW_OPTIONS = new Set(["count-by", "sum", "by", "top", "table", "sort"]);
1370
- var VALUE_OPTIONS = new Set(["wait-timeout", "output-dir", ...VIEW_OPTIONS]);
1371
- var RESERVED_CLI_OPTIONS = new Set([...BOOL_OPTIONS, ...VALUE_OPTIONS]);
1372
- function classifyLongOptionToken(token) {
1373
- if (!token.startsWith("--") || token === "--")
1374
- return;
1375
- const equals = token.indexOf("=");
1376
- const name = equals >= 0 ? token.slice(2, equals) : token.slice(2);
1377
- return {
1378
- name,
1379
- value: equals >= 0 ? token.slice(equals + 1) : undefined,
1380
- inline: equals >= 0,
1381
- globalKind: BOOL_OPTIONS.has(name) ? "boolean" : VALUE_OPTIONS.has(name) ? "value" : undefined
1382
- };
1383
- }
1384
- var HELP_TOKENS = new Set(["--help", "-h", "help"]);
1385
- function helpFilterFrom(token, rest) {
1386
- if (token?.startsWith("--help=")) {
1387
- const value = token.slice("--help=".length).trim();
1388
- if (value.length === 0 || isReservedBoolWord(value))
1389
- return;
1390
- return value;
1534
+ // src/tools/cli/command-shape.ts
1535
+ function assertCliCommandName(name) {
1536
+ if (isReservedCliCommandName(name)) {
1537
+ throw new Error(`[stitchkit] CLI command "${name}" is reserved. Rename the command to a word outside the framework option syntax.`);
1391
1538
  }
1392
- if (token === undefined || !HELP_TOKENS.has(token))
1393
- return;
1394
- const next = rest[0];
1395
- return next !== undefined && !next.startsWith("-") ? next : undefined;
1396
1539
  }
1397
- function routeCliArgv2(argv, defaultCommand) {
1398
- if (defaultCommand === undefined) {
1399
- const [command, ...commandArgv] = argv;
1400
- const helpFilter = helpFilterFrom(command, commandArgv);
1401
- return {
1402
- command,
1403
- commandArgv,
1404
- topLevelHelp: false,
1405
- version: false,
1406
- ...helpFilter !== undefined && { helpFilter }
1407
- };
1540
+ function assertStaticCliCommandNames(services, runtimeTools) {
1541
+ for (const tool of runtimeTools) {
1542
+ if (tool.transports?.includes("CLI"))
1543
+ assertCliCommandName(tool.name);
1408
1544
  }
1409
- const globals = [];
1410
- let index = 0;
1411
- while (index < argv.length) {
1412
- const token = argv[index];
1413
- if (token === undefined)
1414
- break;
1415
- if (token === "--") {
1416
- return {
1417
- commandArgv: [],
1418
- topLevelHelp: false,
1419
- version: false,
1420
- error: 'A command is required before "--"'
1421
- };
1422
- }
1423
- const inlineHelpFilter = token.startsWith("--help=") && !isReservedBoolWord(token.slice("--help=".length));
1424
- if (token === "--help" || token === "-h" || inlineHelpFilter) {
1425
- const helpFilter = helpFilterFrom(token, argv.slice(index + 1));
1426
- return {
1427
- commandArgv: [],
1428
- topLevelHelp: true,
1429
- version: false,
1430
- ...helpFilter !== undefined && { helpFilter }
1431
- };
1432
- }
1433
- if (token === "--version" || token === "version") {
1434
- return { commandArgv: [], topLevelHelp: false, version: true };
1435
- }
1436
- if (!token.startsWith("-") || token === "-") {
1437
- return {
1438
- command: token,
1439
- commandArgv: [...globals, ...argv.slice(index + 1)],
1440
- topLevelHelp: false,
1441
- version: false
1442
- };
1443
- }
1444
- if (!token.startsWith("--")) {
1445
- return {
1446
- command: defaultCommand,
1447
- commandArgv: [...globals, ...argv.slice(index)],
1448
- topLevelHelp: false,
1449
- version: false
1450
- };
1451
- }
1452
- const option = classifyLongOptionToken(token);
1453
- if (!option) {
1454
- return {
1455
- command: defaultCommand,
1456
- commandArgv: [...globals, ...argv.slice(index)],
1457
- topLevelHelp: false,
1458
- version: false
1459
- };
1460
- }
1461
- if (option.globalKind === "boolean") {
1462
- globals.push(token);
1463
- index += 1;
1464
- const next = argv[index];
1465
- if (option.value === undefined && next !== undefined && separateBoolValue(next) !== undefined) {
1466
- globals.push(next);
1467
- index += 1;
1468
- }
1469
- continue;
1470
- }
1471
- if (option.globalKind === "value") {
1472
- globals.push(token);
1473
- if (!option.inline) {
1474
- const value = argv[index + 1];
1475
- if (value === "--help" || value === "-h") {
1476
- const helpFilter = helpFilterFrom(value, argv.slice(index + 2));
1477
- return {
1478
- commandArgv: [],
1479
- topLevelHelp: true,
1480
- version: false,
1481
- ...helpFilter !== undefined && { helpFilter }
1482
- };
1483
- }
1484
- if (value === "--version" || value === "version") {
1485
- return { commandArgv: [], topLevelHelp: false, version: true };
1486
- }
1487
- if (value !== undefined)
1488
- globals.push(value);
1489
- index += value === undefined ? 1 : 2;
1490
- } else {
1491
- index += 1;
1492
- }
1493
- continue;
1545
+ for (const service of services) {
1546
+ for (const [key, method] of Object.entries(service.methods)) {
1547
+ const name = projectedContractToolName(service.name, key, method, "CLI") ?? cliStreamIdentity(service.name, key, method)?.name;
1548
+ if (name !== undefined)
1549
+ assertCliCommandName(name);
1494
1550
  }
1495
- return {
1496
- command: defaultCommand,
1497
- commandArgv: [...globals, ...argv.slice(index)],
1498
- topLevelHelp: false,
1499
- version: false
1500
- };
1501
1551
  }
1502
- return {
1503
- command: defaultCommand,
1504
- commandArgv: globals,
1505
- topLevelHelp: false,
1506
- version: false
1507
- };
1508
1552
  }
1509
-
1510
- // src/tools/cli/command-shape.ts
1511
1553
  function commandShapeIssue(name, descriptor, exists, passthroughField, applicationGlobals = new Set) {
1512
1554
  assertUniqueToolName(name, exists, "CLI command");
1513
- if (name === "help" || name === "version") {
1514
- throw new Error(`[stitchkit] CLI command "${name}" is reserved`);
1515
- }
1555
+ assertCliCommandName(name);
1516
1556
  if (passthroughField !== undefined && descriptor.aliases.has(passthroughField)) {
1517
1557
  throw new Error(`[stitchkit] CLI command "${name}" cannot alias passthrough field "${passthroughField}"`);
1518
1558
  }
@@ -1535,9 +1575,8 @@ async function buildManagedSurface(session, typedGlobals, forExecution) {
1535
1575
  authPromise ??= (async () => config.resolveAuth ? await config.resolveAuth(typedGlobals) : await config.auth)();
1536
1576
  return authPromise;
1537
1577
  };
1538
- const dynamicSurface = typeof config.services === "function" || typeof config.runtimeTools === "function";
1539
1578
  let auth;
1540
- if (dynamicSurface || forExecution) {
1579
+ if (session.hasManagedFactory || forExecution) {
1541
1580
  try {
1542
1581
  auth = await resolveIdentity();
1543
1582
  } catch (error) {
@@ -1955,6 +1994,7 @@ function extractCliGlobalOptions2(argv, schema) {
1955
1994
  }
1956
1995
  }
1957
1996
  appendCliFieldValue(raw, jsonFields, field.name, value, info, field.json);
1997
+ preserveCliBooleanBoundary(rest, argv[i + 1]);
1958
1998
  }
1959
1999
  const args = {};
1960
2000
  for (const [name, values] of raw) {
@@ -2073,6 +2113,7 @@ function createCliSession(config, io) {
2073
2113
  }
2074
2114
  const nativeCommands = new Map;
2075
2115
  const nativeHelp = new Map;
2116
+ assertStaticCliCommandNames(typeof config.services === "function" ? [] : config.services ?? [], typeof config.runtimeTools === "function" ? [] : config.runtimeTools ?? []);
2076
2117
  for (const definition of config.commands ?? []) {
2077
2118
  const descriptor = applyCliPresentationPolicy(definition.name, nativeDescriptor(definition), config);
2078
2119
  const issue = commandShapeIssue(definition.name, descriptor, nativeCommands.has(definition.name), config.passthrough?.[definition.name], applicationGlobalNames);
@@ -2087,7 +2128,8 @@ function createCliSession(config, io) {
2087
2128
  applicationOptions,
2088
2129
  applicationGlobalNames,
2089
2130
  nativeCommands,
2090
- nativeHelp
2131
+ nativeHelp,
2132
+ hasManagedFactory: typeof config.services === "function" || typeof config.runtimeTools === "function"
2091
2133
  };
2092
2134
  }
2093
2135
  function resolveCliRoute(session, argv) {
@@ -2116,28 +2158,27 @@ function resolveCliRoute(session, argv) {
2116
2158
  return;
2117
2159
  }
2118
2160
  const { command, commandArgv } = route;
2119
- if (route.version || command === "--version" || command === "version") {
2161
+ if (config.defaultCommand === undefined && session.hasManagedFactory && command !== undefined && command !== routableArgv[0] && session.nativeCommands.has(command)) {
2162
+ stderr(`Managed command names are unknown before native dispatch. Put "${config.name} ${command}" first and keep options with their values. ` + `If moving a bare boolean flag next to positional true or false, spell the flag explicitly (for example, --dry-run=true).
2163
+ `);
2164
+ exit(2);
2165
+ return;
2166
+ }
2167
+ if (route.version || isCliVersionToken(command)) {
2120
2168
  stdout(`${config.name} ${config.version}
2121
2169
  `);
2122
2170
  exit(0);
2123
2171
  return;
2124
2172
  }
2125
- const beforeSeparator = commandArgv.indexOf("--") === -1 ? commandArgv : commandArgv.slice(0, commandArgv.indexOf("--"));
2126
- const asked = (name) => beforeSeparator.some((token) => {
2127
- if (token === `--${name}` || name === "help" && token === "-h")
2128
- return true;
2129
- const option = classifyLongOptionToken(token);
2130
- return option?.name === name && option.value !== undefined && isReservedBoolWord(option.value) && parseReservedBool(name, option.value);
2131
- });
2132
- const helpRequested = asked("help");
2133
- const schemaRequested = !helpRequested && asked("schema");
2173
+ const helpRequested = readCliBooleanFlag(commandArgv, "help");
2174
+ const schemaRequested = !helpRequested && readCliBooleanFlag(commandArgv, "schema");
2134
2175
  return {
2135
2176
  globals,
2136
2177
  typedGlobals,
2137
2178
  route,
2138
2179
  command,
2139
2180
  commandArgv,
2140
- beforeSeparator,
2181
+ quiet: readCliBooleanFlag(route.topLevelHelp ? routableArgv : commandArgv, "quiet"),
2141
2182
  helpRequested,
2142
2183
  schemaRequested
2143
2184
  };
@@ -2269,20 +2310,6 @@ function unavailableCommand(reason) {
2269
2310
  retryable: false
2270
2311
  }));
2271
2312
  }
2272
- function unavailableCommandJson(argv) {
2273
- for (let i = 0;i < argv.length; i++) {
2274
- const token = argv[i];
2275
- if (token === "--")
2276
- break;
2277
- if (token === undefined)
2278
- continue;
2279
- const option = classifyLongOptionToken(token);
2280
- if (option?.name !== "json")
2281
- continue;
2282
- return option.value === undefined ? separateBoolValue(argv[i + 1]) ?? true : isReservedBoolWord(option.value) && parseReservedBool("json", option.value);
2283
- }
2284
- return false;
2285
- }
2286
2313
 
2287
2314
  // src/tools/cli/view.ts
2288
2315
  var ABSENT = "(absent)";
@@ -2525,13 +2552,13 @@ async function pollUntilDone2(params) {
2525
2552
  async function runManagedInvocation(session, route) {
2526
2553
  const { config } = session;
2527
2554
  const { stdout, stderr, exit } = session.io;
2528
- const { command, helpRequested, schemaRequested, beforeSeparator } = route;
2555
+ const { command, helpRequested, schemaRequested } = route;
2529
2556
  const topLevelHelp = route.route.topLevelHelp || command === undefined || command === "help" || command === "--help" || command === "-h" || command.startsWith("--help=") && !isReservedBoolWord(command.slice("--help=".length));
2530
2557
  const managed = await buildManagedSurface(session, route.typedGlobals, !topLevelHelp && !helpRequested && !schemaRequested);
2531
2558
  if (topLevelHelp)
2532
2559
  return respondTopLevelHelp(session, route, managed);
2533
2560
  if (!managed.resolved) {
2534
- return exit(emitResult2(managed.failure, { stdout, stderr }, emitOptionsFor(config, beforeSeparator.includes("--json"), command ?? config.name)));
2561
+ return exit(emitResult2(managed.failure, { stdout, stderr }, emitOptionsFor(config, readCliBooleanFlag(route.commandArgv, "json"), command ?? config.name)));
2535
2562
  }
2536
2563
  return runManagedCommand(session, route, command, managed);
2537
2564
  }
@@ -2578,7 +2605,7 @@ async function runManagedCommand(session, route, command, managed) {
2578
2605
  return exit(0);
2579
2606
  }
2580
2607
  if (descriptor.unavailableReason !== undefined) {
2581
- return exit(emitResult2(unavailableCommand(descriptor.unavailableReason), { stdout, stderr }, emitOptionsFor(config, unavailableCommandJson(route.commandArgv), command)));
2608
+ return exit(emitResult2(unavailableCommand(descriptor.unavailableReason), { stdout, stderr }, emitOptionsFor(config, readCliBooleanFlag(route.commandArgv, "json"), command)));
2582
2609
  }
2583
2610
  const stream = managed.streams.get(command);
2584
2611
  const tool = managed.tools.get(command);
@@ -2779,12 +2806,14 @@ async function createCli2(config) {
2779
2806
  const route = resolveCliRoute(session, argv);
2780
2807
  if (route === undefined)
2781
2808
  return;
2782
- const { command } = route;
2783
- const native = command === undefined ? undefined : session.nativeCommands.get(command);
2784
- if (native && command !== undefined) {
2785
- return runNativeCommand2(session, route, command, native);
2786
- }
2787
- return runManagedInvocation(session, route);
2809
+ return withCliNotices(route.quiet, io.stderr, () => {
2810
+ const { command } = route;
2811
+ const native = command === undefined ? undefined : session.nativeCommands.get(command);
2812
+ if (native && command !== undefined) {
2813
+ return runNativeCommand2(session, route, command, native);
2814
+ }
2815
+ return runManagedInvocation(session, route);
2816
+ });
2788
2817
  }
2789
2818
 
2790
- export { DEFAULT_EXIT_CODES2, cliExitCode2, emitResult2, defineCliResult2, defineCliCommand2, CliArgumentError2, cliInvocationResult2, createCliInvoker2, routeCliArgv2, parseCliArgs2, extractCliGlobalOptions2, renderCliView2, pollUntilDone2, createCli2 };
2819
+ export { DEFAULT_EXIT_CODES2, cliExitCode2, emitResult2, defineCliResult2, defineCliCommand2, CliArgumentError2, cliInvocationResult2, createCliInvoker2, routeCliArgv2, writeCliNotice, parseCliArgs2, extractCliGlobalOptions2, renderCliView2, pollUntilDone2, createCli2 };
@@ -1039,6 +1039,12 @@ function assertProjectedName(name, serviceName, action, transport, derived) {
1039
1039
  }
1040
1040
  assertToolName(name, serviceName, action);
1041
1041
  }
1042
+ function projectedContractToolName(serviceName, methodName, method, transport) {
1043
+ const exposed = method.expose?.includes(transport) ?? transport !== "CLI";
1044
+ if (!exposed || isHttpOnlyEndpoint(method))
1045
+ return;
1046
+ return method.toolName ?? toToolName(serviceName, methodName);
1047
+ }
1042
1048
  function projectToolSurface(surface, transport, config = {}) {
1043
1049
  const projected = [];
1044
1050
  const names = new Set;
@@ -1058,16 +1064,9 @@ function projectToolSurface(surface, transport, config = {}) {
1058
1064
  };
1059
1065
  for (const service of surface.services ?? []) {
1060
1066
  for (const [methodName, method] of Object.entries(service.methods)) {
1061
- if (transport === "CLI") {
1062
- if (!method.expose?.includes("CLI"))
1063
- continue;
1064
- } else if (method.expose && !method.expose.includes(transport)) {
1067
+ const name = projectedContractToolName(service.name, methodName, method, transport);
1068
+ if (name === undefined)
1065
1069
  continue;
1066
- }
1067
- if (isHttpOnlyEndpoint(method)) {
1068
- continue;
1069
- }
1070
- const name = method.toolName ?? toToolName(service.name, methodName);
1071
1070
  if (config.assertNames ?? true) {
1072
1071
  assertProjectedName(name, service.name, methodName, transport, !method.toolName);
1073
1072
  }
@@ -1216,4 +1215,4 @@ function prepareProjectedMcpTools(tools, config = {}) {
1216
1215
  return prepared;
1217
1216
  }
1218
1217
 
1219
- export { toolSurfaceOutputSchema, applyToolViewDefaults, projectToolView, objectShapeKeys, rebuildObject, mergeSchemas, staticInputRounds, validateMcpRoundPolicy, validateResolvedInputRounds, assertToolName, toToolName, assertUniqueToolName, PORTABLE_JSON_SCHEMA_FORMATS2, findNonPortableFormats2, flattenToolJsonSchema2, buildToolPresentationSchema, presentationMetadata, findUntypedProperties2, assertToolExtensionCompatible, projectRuntimeTool, projectToolSurface, mcpProjectionCandidate, prepareProjectedMcpTools };
1218
+ export { toolSurfaceOutputSchema, applyToolViewDefaults, projectToolView, objectShapeKeys, rebuildObject, mergeSchemas, staticInputRounds, validateMcpRoundPolicy, validateResolvedInputRounds, assertToolName, toToolName, assertUniqueToolName, PORTABLE_JSON_SCHEMA_FORMATS2, findNonPortableFormats2, flattenToolJsonSchema2, buildToolPresentationSchema, presentationMetadata, findUntypedProperties2, assertToolExtensionCompatible, projectRuntimeTool, projectedContractToolName, projectToolSurface, mcpProjectionCandidate, prepareProjectedMcpTools };
@@ -12,7 +12,7 @@ import {
12
12
  applyToolViewDefaults,
13
13
  projectToolView,
14
14
  objectShapeKeys
15
- } from "./index-rk7m4j7r.js";
15
+ } from "./index-x2d51zay.js";
16
16
  import {
17
17
  runWithRequestContext2,
18
18
  getRequestContext2
@@ -29,6 +29,10 @@ export interface CliLongOptionToken {
29
29
  }
30
30
  /** One source of truth for long-option token shape and framework-global ownership. */
31
31
  export declare function classifyLongOptionToken(token: string): CliLongOptionToken | undefined;
32
+ /** Read a setting before validation. Any enabled help or schema request takes precedence. */
33
+ export declare function readCliBooleanFlag(argv: readonly string[], name: string): boolean;
34
+ /** Removing an intervening token cannot make a positional true/false a flag's value. */
35
+ export declare function preserveCliBooleanBoundary(prefix: string[], next: string | undefined): void;
32
36
  export interface CliArgvRoute {
33
37
  command?: string;
34
38
  commandArgv: string[];
@@ -38,5 +42,12 @@ export interface CliArgvRoute {
38
42
  helpFilter?: string;
39
43
  error?: string;
40
44
  }
45
+ export declare function isCliVersionToken(token: string | undefined): boolean;
46
+ /** Exact shell tokens owned by the framework, including inline option values. */
47
+ export declare function isReservedCliCommandName(name: string): boolean;
48
+ /**
49
+ * Route recognised leading globals to the explicit command. A CLI with a default
50
+ * also routes a global-only invocation and command-local leading flags to that default.
51
+ */
41
52
  export declare function routeCliArgv(argv: string[], defaultCommand?: string): CliArgvRoute;
42
53
  //# sourceMappingURL=args-route.d.ts.map