toolcraft 0.0.89 → 0.0.90

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.
@@ -1,6 +1,6 @@
1
1
  import { S } from "toolcraft-schema";
2
2
  import { defineCommand, defineGroup } from "./index.js";
3
- import { runCLI } from "./cli.js";
3
+ import { createCLICommandTreeSnapshot, runCLI } from "./cli.js";
4
4
  const ignoredCommand = defineCommand({
5
5
  name: "deploy",
6
6
  params: S.Object({
@@ -37,4 +37,12 @@ const ignoredServiceOptions = {
37
37
  };
38
38
  void runCLI(ignoredRoot, ignoredOptions);
39
39
  void runCLI([ignoredRoot], ignoredOptions);
40
+ const ignoredSnapshot = createCLICommandTreeSnapshot(ignoredRoot, {
41
+ approvals: true,
42
+ casing: "kebab",
43
+ controls: ignoredOptions.controls,
44
+ presets: true,
45
+ version: ignoredOptions.version,
46
+ });
47
+ void ignoredSnapshot;
40
48
  void ignoredServiceOptions;
package/dist/cli.d.ts CHANGED
@@ -30,4 +30,59 @@ export interface RunCLIOptions<TServices extends object = Record<string, unknown
30
30
  presets?: boolean;
31
31
  errorReports?: ErrorReportsOption;
32
32
  }
33
+ export interface CLICommandTreeSnapshotOption {
34
+ name: string;
35
+ flags: string[];
36
+ type: string;
37
+ required: boolean;
38
+ hidden: boolean;
39
+ description?: string;
40
+ default?: unknown;
41
+ positional?: boolean;
42
+ global?: boolean;
43
+ dynamic?: boolean;
44
+ }
45
+ export interface CLICommandTreeSnapshotCommand {
46
+ kind: "command";
47
+ name: string;
48
+ path: string[];
49
+ aliases: string[];
50
+ hidden: boolean;
51
+ default: boolean;
52
+ description?: string;
53
+ options: CLICommandTreeSnapshotOption[];
54
+ }
55
+ export interface CLICommandTreeSnapshotGroup {
56
+ kind: "group";
57
+ name: string;
58
+ path: string[];
59
+ aliases: string[];
60
+ hidden: false;
61
+ default: boolean;
62
+ description?: string;
63
+ children: CLICommandTreeSnapshotNode[];
64
+ }
65
+ export type CLICommandTreeSnapshotNode = CLICommandTreeSnapshotCommand | CLICommandTreeSnapshotGroup;
66
+ export interface CLICommandTreeSnapshot {
67
+ schemaVersion: 1;
68
+ globalOptions: CLICommandTreeSnapshotOption[];
69
+ root: CLICommandTreeSnapshotGroup;
70
+ }
71
+ export interface CLICommandTreeSnapshotOptions {
72
+ approvals?: boolean;
73
+ argv?: readonly string[];
74
+ casing?: Casing;
75
+ controls?: CLIControls;
76
+ presets?: boolean;
77
+ version?: string;
78
+ }
79
+ /**
80
+ * Returns the resolved CLI command surface as deterministic plain data.
81
+ *
82
+ * Schema version 1 is independent of human-facing help layout. Nodes and options retain
83
+ * declaration order, paths exclude the root name, non-CLI nodes are omitted, hidden commands
84
+ * remain present, and Toolcraft-controlled global options are reported separately. A future
85
+ * incompatible shape change will increment `schemaVersion`.
86
+ */
87
+ export declare function createCLICommandTreeSnapshot<TServices extends object>(roots: Group<TServices> | Group<TServices>[], options?: CLICommandTreeSnapshotOptions): Promise<CLICommandTreeSnapshot>;
33
88
  export declare function runCLI<TServices extends object = Record<string, unknown>>(roots: Group<TServices> | Group<TServices>[], options?: RunCLIOptions<TServices>): Promise<void>;
package/dist/cli.js CHANGED
@@ -39,6 +39,29 @@ const optionalModulePaths = {
39
39
  function importOptionalModule(specifier) {
40
40
  return import(specifier);
41
41
  }
42
+ /**
43
+ * Returns the resolved CLI command surface as deterministic plain data.
44
+ *
45
+ * Schema version 1 is independent of human-facing help layout. Nodes and options retain
46
+ * declaration order, paths exclude the root name, non-CLI nodes are omitted, hidden commands
47
+ * remain present, and Toolcraft-controlled global options are reported separately. A future
48
+ * incompatible shape change will increment `schemaVersion`.
49
+ */
50
+ export async function createCLICommandTreeSnapshot(roots, options = {}) {
51
+ const argv = [...(options.argv ?? ["node", "toolcraft"])];
52
+ const normalizedRoot = normalizeRoots(roots, argv);
53
+ const root = options.approvals === true
54
+ ? (await importOptionalModule(optionalModulePaths.approvals)).mergeApprovalsGroup(normalizedRoot)
55
+ : normalizedRoot;
56
+ const controls = resolveCLIControls(options.controls);
57
+ const presetsEnabled = options.presets === true;
58
+ const globalLongOptionFlags = getGlobalLongOptionFlags(presetsEnabled, options.version !== undefined, controls);
59
+ return {
60
+ schemaVersion: 1,
61
+ globalOptions: createGlobalSnapshotOptions(presetsEnabled, options.version !== undefined, controls),
62
+ root: createSnapshotGroup(root, options.casing ?? "kebab", globalLongOptionFlags, [], false)
63
+ };
64
+ }
42
65
  function inferProgramName(argv) {
43
66
  const entrypoint = argv[1];
44
67
  if (typeof entrypoint !== "string" || entrypoint.length === 0) {
@@ -1482,6 +1505,150 @@ function getToolcraftReservedChildNames(command) {
1482
1505
  function getNodeCommandNames(node) {
1483
1506
  return [node.name, ...node.aliases].filter((name) => name.length > 0);
1484
1507
  }
1508
+ function createGlobalSnapshotOptions(presetsEnabled, versionEnabled, controls) {
1509
+ const options = [
1510
+ {
1511
+ name: "help",
1512
+ flags: ["-h", "--help"],
1513
+ type: "boolean",
1514
+ required: false,
1515
+ hidden: false,
1516
+ description: "Display help for command."
1517
+ }
1518
+ ];
1519
+ if (presetsEnabled) {
1520
+ options.push({
1521
+ name: "preset",
1522
+ flags: ["--preset"],
1523
+ type: "string",
1524
+ required: false,
1525
+ hidden: true,
1526
+ description: "Load parameter defaults from a JSON file."
1527
+ });
1528
+ }
1529
+ if (controls.yes) {
1530
+ options.push({
1531
+ name: "yes",
1532
+ flags: ["--yes"],
1533
+ type: "boolean",
1534
+ required: false,
1535
+ hidden: true,
1536
+ description: "Accept defaults and skip prompts."
1537
+ });
1538
+ }
1539
+ if (controls.output) {
1540
+ options.push({
1541
+ name: "output",
1542
+ flags: ["--output"],
1543
+ type: "enum",
1544
+ required: false,
1545
+ hidden: true,
1546
+ description: "Output format."
1547
+ });
1548
+ }
1549
+ if (controls.debug) {
1550
+ options.push({
1551
+ name: "debug",
1552
+ flags: ["--debug"],
1553
+ type: "enum",
1554
+ required: false,
1555
+ hidden: true,
1556
+ description: "Print stack traces for unexpected errors."
1557
+ });
1558
+ }
1559
+ if (controls.logLevel) {
1560
+ options.push({
1561
+ name: "logLevel",
1562
+ flags: ["--log-level"],
1563
+ type: "enum",
1564
+ required: false,
1565
+ hidden: true,
1566
+ description: "Set runtime diagnostic log level."
1567
+ });
1568
+ }
1569
+ if (controls.verbose) {
1570
+ options.push({
1571
+ name: "verbose",
1572
+ flags: ["-v", "--verbose"],
1573
+ type: "boolean",
1574
+ required: false,
1575
+ hidden: true,
1576
+ description: "Print detailed runtime diagnostics."
1577
+ });
1578
+ }
1579
+ if (versionEnabled) {
1580
+ options.push({
1581
+ name: "version",
1582
+ flags: ["--version"],
1583
+ type: "boolean",
1584
+ required: false,
1585
+ hidden: false,
1586
+ description: "Output the version number."
1587
+ });
1588
+ }
1589
+ return options;
1590
+ }
1591
+ function createSnapshotGroup(group, casing, globalLongOptionFlags, pathSegments, isDefault) {
1592
+ const children = group.children
1593
+ .filter((child) => isNodeVisibleInScope(child, "cli"))
1594
+ .map((child) => createSnapshotNode(child, casing, globalLongOptionFlags, [...pathSegments, child.name], group.default === child));
1595
+ return {
1596
+ kind: "group",
1597
+ name: group.name,
1598
+ path: pathSegments,
1599
+ aliases: [...group.aliases],
1600
+ hidden: false,
1601
+ default: isDefault,
1602
+ ...(group.description === undefined ? {} : { description: group.description }),
1603
+ children
1604
+ };
1605
+ }
1606
+ function createSnapshotNode(node, casing, globalLongOptionFlags, pathSegments, isDefault) {
1607
+ if (node.kind === "group") {
1608
+ return createSnapshotGroup(node, casing, globalLongOptionFlags, pathSegments, isDefault);
1609
+ }
1610
+ const collected = collectFields(node.params, casing, globalLongOptionFlags);
1611
+ const fields = assignPositionals(collected.fields, node.positional);
1612
+ validateUniqueOptionFlags(fields, globalLongOptionFlags);
1613
+ return {
1614
+ kind: "command",
1615
+ name: node.name,
1616
+ path: pathSegments,
1617
+ aliases: [...node.aliases],
1618
+ hidden: node.hidden,
1619
+ default: isDefault,
1620
+ ...(node.description === undefined ? {} : { description: node.description }),
1621
+ options: [
1622
+ ...fields.map((field) => createFieldSnapshotOption(field, globalLongOptionFlags)),
1623
+ ...collected.dynamicFields.flatMap((field) => createDynamicSnapshotOptions(field, casing))
1624
+ ]
1625
+ };
1626
+ }
1627
+ function createFieldSnapshotOption(field, globalLongOptionFlags) {
1628
+ return {
1629
+ name: field.displayPath,
1630
+ flags: formatHelpFieldFlags(field, globalLongOptionFlags).split(", "),
1631
+ type: formatJsonHelpSchemaType(field.schema),
1632
+ required: field.requiredWhenActive,
1633
+ hidden: false,
1634
+ ...(field.description === undefined ? {} : { description: field.description }),
1635
+ ...(field.hasDefault ? { default: field.defaultValue } : {}),
1636
+ ...(field.positionalIndex === undefined ? {} : { positional: true }),
1637
+ ...(field.global === true ? { global: true } : {})
1638
+ };
1639
+ }
1640
+ function createDynamicSnapshotOptions(field, casing) {
1641
+ return formatDynamicHelpFields(field, casing).map((row) => ({
1642
+ name: field.displayPath,
1643
+ flags: [row.flags],
1644
+ type: describeDynamicFieldType(field),
1645
+ required: field.requiredWhenActive,
1646
+ hidden: false,
1647
+ ...(field.description === undefined ? {} : { description: field.description }),
1648
+ ...(field.hasDefault ? { default: field.defaultValue } : {}),
1649
+ dynamic: true
1650
+ }));
1651
+ }
1485
1652
  function addGlobalOptions(command, presetsEnabled, controls) {
1486
1653
  const options = [];
1487
1654
  if (presetsEnabled) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "toolcraft",
3
- "version": "0.0.89",
3
+ "version": "0.0.90",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -56,7 +56,7 @@
56
56
  "postpack": "node ../../scripts/manage-bundled-workspace-deps.mjs cleanup . toolcraft-design @poe-code/frontmatter @poe-code/agent-mcp-config @poe-code/agent-human-in-loop @poe-code/task-list @poe-code/agent-defs @poe-code/config-mutations @poe-code/process-runner tiny-mcp-client mcp-oauth auth-store"
57
57
  },
58
58
  "dependencies": {
59
- "toolcraft-schema": "0.0.89",
59
+ "toolcraft-schema": "0.0.90",
60
60
  "commander": "^13.1.0",
61
61
  "fast-string-width": "^3.0.2",
62
62
  "fast-wrap-ansi": "^0.2.0",