toolcraft 0.0.89 → 0.0.91
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.compile-check.js +16 -1
- package/dist/cli.d.ts +57 -0
- package/dist/cli.js +168 -0
- package/dist/error-report.d.ts +11 -0
- package/dist/error-report.js +12 -1
- package/package.json +2 -2
|
@@ -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, renderErrorReport, runCLI } from "./cli.js";
|
|
4
4
|
const ignoredCommand = defineCommand({
|
|
5
5
|
name: "deploy",
|
|
6
6
|
params: S.Object({
|
|
@@ -37,4 +37,19 @@ 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;
|
|
48
|
+
const ignoredRenderedReport = renderErrorReport({
|
|
49
|
+
command: ignoredCommand,
|
|
50
|
+
env: {},
|
|
51
|
+
error: new Error("fixture"),
|
|
52
|
+
version: "1.0.0",
|
|
53
|
+
});
|
|
54
|
+
void ignoredRenderedReport;
|
|
40
55
|
void ignoredServiceOptions;
|
package/dist/cli.d.ts
CHANGED
|
@@ -3,6 +3,8 @@ import { configureTheme } from "toolcraft-design";
|
|
|
3
3
|
import type { Group, LogLevel, RuntimeLoggerInput } from "./index.js";
|
|
4
4
|
import { type ErrorReportsOption } from "./error-report.js";
|
|
5
5
|
import type { HumanInLoopRuntimeOptions } from "./human-in-loop/types.js";
|
|
6
|
+
export { renderErrorReport } from "./error-report.js";
|
|
7
|
+
export type { ErrorReportRenderContext, ErrorReportRenderResult } from "./error-report.js";
|
|
6
8
|
export { configureTheme };
|
|
7
9
|
type Casing = "kebab" | "snake";
|
|
8
10
|
export interface CLIControls {
|
|
@@ -30,4 +32,59 @@ export interface RunCLIOptions<TServices extends object = Record<string, unknown
|
|
|
30
32
|
presets?: boolean;
|
|
31
33
|
errorReports?: ErrorReportsOption;
|
|
32
34
|
}
|
|
35
|
+
export interface CLICommandTreeSnapshotOption {
|
|
36
|
+
name: string;
|
|
37
|
+
flags: string[];
|
|
38
|
+
type: string;
|
|
39
|
+
required: boolean;
|
|
40
|
+
hidden: boolean;
|
|
41
|
+
description?: string;
|
|
42
|
+
default?: unknown;
|
|
43
|
+
positional?: boolean;
|
|
44
|
+
global?: boolean;
|
|
45
|
+
dynamic?: boolean;
|
|
46
|
+
}
|
|
47
|
+
export interface CLICommandTreeSnapshotCommand {
|
|
48
|
+
kind: "command";
|
|
49
|
+
name: string;
|
|
50
|
+
path: string[];
|
|
51
|
+
aliases: string[];
|
|
52
|
+
hidden: boolean;
|
|
53
|
+
default: boolean;
|
|
54
|
+
description?: string;
|
|
55
|
+
options: CLICommandTreeSnapshotOption[];
|
|
56
|
+
}
|
|
57
|
+
export interface CLICommandTreeSnapshotGroup {
|
|
58
|
+
kind: "group";
|
|
59
|
+
name: string;
|
|
60
|
+
path: string[];
|
|
61
|
+
aliases: string[];
|
|
62
|
+
hidden: false;
|
|
63
|
+
default: boolean;
|
|
64
|
+
description?: string;
|
|
65
|
+
children: CLICommandTreeSnapshotNode[];
|
|
66
|
+
}
|
|
67
|
+
export type CLICommandTreeSnapshotNode = CLICommandTreeSnapshotCommand | CLICommandTreeSnapshotGroup;
|
|
68
|
+
export interface CLICommandTreeSnapshot {
|
|
69
|
+
schemaVersion: 1;
|
|
70
|
+
globalOptions: CLICommandTreeSnapshotOption[];
|
|
71
|
+
root: CLICommandTreeSnapshotGroup;
|
|
72
|
+
}
|
|
73
|
+
export interface CLICommandTreeSnapshotOptions {
|
|
74
|
+
approvals?: boolean;
|
|
75
|
+
argv?: readonly string[];
|
|
76
|
+
casing?: Casing;
|
|
77
|
+
controls?: CLIControls;
|
|
78
|
+
presets?: boolean;
|
|
79
|
+
version?: string;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Returns the resolved CLI command surface as deterministic plain data.
|
|
83
|
+
*
|
|
84
|
+
* Schema version 1 is independent of human-facing help layout. Nodes and options retain
|
|
85
|
+
* declaration order, paths exclude the root name, non-CLI nodes are omitted, hidden commands
|
|
86
|
+
* remain present, and Toolcraft-controlled global options are reported separately. A future
|
|
87
|
+
* incompatible shape change will increment `schemaVersion`.
|
|
88
|
+
*/
|
|
89
|
+
export declare function createCLICommandTreeSnapshot<TServices extends object>(roots: Group<TServices> | Group<TServices>[], options?: CLICommandTreeSnapshotOptions): Promise<CLICommandTreeSnapshot>;
|
|
33
90
|
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
|
@@ -16,6 +16,7 @@ import { renderSourceSnippet } from "./source-snippet.js";
|
|
|
16
16
|
import { enableSourceMaps, formatDebugStack } from "./stack-trim.js";
|
|
17
17
|
import { suggest } from "./suggest.js";
|
|
18
18
|
import { throwValidationErrors } from "./validation-errors.js";
|
|
19
|
+
export { renderErrorReport } from "./error-report.js";
|
|
19
20
|
configureTheme({ brand: "blue", label: "Toolcraft" });
|
|
20
21
|
export { configureTheme };
|
|
21
22
|
const RESERVED_SERVICE_NAMES = new Set([
|
|
@@ -39,6 +40,29 @@ const optionalModulePaths = {
|
|
|
39
40
|
function importOptionalModule(specifier) {
|
|
40
41
|
return import(specifier);
|
|
41
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* Returns the resolved CLI command surface as deterministic plain data.
|
|
45
|
+
*
|
|
46
|
+
* Schema version 1 is independent of human-facing help layout. Nodes and options retain
|
|
47
|
+
* declaration order, paths exclude the root name, non-CLI nodes are omitted, hidden commands
|
|
48
|
+
* remain present, and Toolcraft-controlled global options are reported separately. A future
|
|
49
|
+
* incompatible shape change will increment `schemaVersion`.
|
|
50
|
+
*/
|
|
51
|
+
export async function createCLICommandTreeSnapshot(roots, options = {}) {
|
|
52
|
+
const argv = [...(options.argv ?? ["node", "toolcraft"])];
|
|
53
|
+
const normalizedRoot = normalizeRoots(roots, argv);
|
|
54
|
+
const root = options.approvals === true
|
|
55
|
+
? (await importOptionalModule(optionalModulePaths.approvals)).mergeApprovalsGroup(normalizedRoot)
|
|
56
|
+
: normalizedRoot;
|
|
57
|
+
const controls = resolveCLIControls(options.controls);
|
|
58
|
+
const presetsEnabled = options.presets === true;
|
|
59
|
+
const globalLongOptionFlags = getGlobalLongOptionFlags(presetsEnabled, options.version !== undefined, controls);
|
|
60
|
+
return {
|
|
61
|
+
schemaVersion: 1,
|
|
62
|
+
globalOptions: createGlobalSnapshotOptions(presetsEnabled, options.version !== undefined, controls),
|
|
63
|
+
root: createSnapshotGroup(root, options.casing ?? "kebab", globalLongOptionFlags, [], false)
|
|
64
|
+
};
|
|
65
|
+
}
|
|
42
66
|
function inferProgramName(argv) {
|
|
43
67
|
const entrypoint = argv[1];
|
|
44
68
|
if (typeof entrypoint !== "string" || entrypoint.length === 0) {
|
|
@@ -1482,6 +1506,150 @@ function getToolcraftReservedChildNames(command) {
|
|
|
1482
1506
|
function getNodeCommandNames(node) {
|
|
1483
1507
|
return [node.name, ...node.aliases].filter((name) => name.length > 0);
|
|
1484
1508
|
}
|
|
1509
|
+
function createGlobalSnapshotOptions(presetsEnabled, versionEnabled, controls) {
|
|
1510
|
+
const options = [
|
|
1511
|
+
{
|
|
1512
|
+
name: "help",
|
|
1513
|
+
flags: ["-h", "--help"],
|
|
1514
|
+
type: "boolean",
|
|
1515
|
+
required: false,
|
|
1516
|
+
hidden: false,
|
|
1517
|
+
description: "Display help for command."
|
|
1518
|
+
}
|
|
1519
|
+
];
|
|
1520
|
+
if (presetsEnabled) {
|
|
1521
|
+
options.push({
|
|
1522
|
+
name: "preset",
|
|
1523
|
+
flags: ["--preset"],
|
|
1524
|
+
type: "string",
|
|
1525
|
+
required: false,
|
|
1526
|
+
hidden: true,
|
|
1527
|
+
description: "Load parameter defaults from a JSON file."
|
|
1528
|
+
});
|
|
1529
|
+
}
|
|
1530
|
+
if (controls.yes) {
|
|
1531
|
+
options.push({
|
|
1532
|
+
name: "yes",
|
|
1533
|
+
flags: ["--yes"],
|
|
1534
|
+
type: "boolean",
|
|
1535
|
+
required: false,
|
|
1536
|
+
hidden: true,
|
|
1537
|
+
description: "Accept defaults and skip prompts."
|
|
1538
|
+
});
|
|
1539
|
+
}
|
|
1540
|
+
if (controls.output) {
|
|
1541
|
+
options.push({
|
|
1542
|
+
name: "output",
|
|
1543
|
+
flags: ["--output"],
|
|
1544
|
+
type: "enum",
|
|
1545
|
+
required: false,
|
|
1546
|
+
hidden: true,
|
|
1547
|
+
description: "Output format."
|
|
1548
|
+
});
|
|
1549
|
+
}
|
|
1550
|
+
if (controls.debug) {
|
|
1551
|
+
options.push({
|
|
1552
|
+
name: "debug",
|
|
1553
|
+
flags: ["--debug"],
|
|
1554
|
+
type: "enum",
|
|
1555
|
+
required: false,
|
|
1556
|
+
hidden: true,
|
|
1557
|
+
description: "Print stack traces for unexpected errors."
|
|
1558
|
+
});
|
|
1559
|
+
}
|
|
1560
|
+
if (controls.logLevel) {
|
|
1561
|
+
options.push({
|
|
1562
|
+
name: "logLevel",
|
|
1563
|
+
flags: ["--log-level"],
|
|
1564
|
+
type: "enum",
|
|
1565
|
+
required: false,
|
|
1566
|
+
hidden: true,
|
|
1567
|
+
description: "Set runtime diagnostic log level."
|
|
1568
|
+
});
|
|
1569
|
+
}
|
|
1570
|
+
if (controls.verbose) {
|
|
1571
|
+
options.push({
|
|
1572
|
+
name: "verbose",
|
|
1573
|
+
flags: ["-v", "--verbose"],
|
|
1574
|
+
type: "boolean",
|
|
1575
|
+
required: false,
|
|
1576
|
+
hidden: true,
|
|
1577
|
+
description: "Print detailed runtime diagnostics."
|
|
1578
|
+
});
|
|
1579
|
+
}
|
|
1580
|
+
if (versionEnabled) {
|
|
1581
|
+
options.push({
|
|
1582
|
+
name: "version",
|
|
1583
|
+
flags: ["--version"],
|
|
1584
|
+
type: "boolean",
|
|
1585
|
+
required: false,
|
|
1586
|
+
hidden: false,
|
|
1587
|
+
description: "Output the version number."
|
|
1588
|
+
});
|
|
1589
|
+
}
|
|
1590
|
+
return options;
|
|
1591
|
+
}
|
|
1592
|
+
function createSnapshotGroup(group, casing, globalLongOptionFlags, pathSegments, isDefault) {
|
|
1593
|
+
const children = group.children
|
|
1594
|
+
.filter((child) => isNodeVisibleInScope(child, "cli"))
|
|
1595
|
+
.map((child) => createSnapshotNode(child, casing, globalLongOptionFlags, [...pathSegments, child.name], group.default === child));
|
|
1596
|
+
return {
|
|
1597
|
+
kind: "group",
|
|
1598
|
+
name: group.name,
|
|
1599
|
+
path: pathSegments,
|
|
1600
|
+
aliases: [...group.aliases],
|
|
1601
|
+
hidden: false,
|
|
1602
|
+
default: isDefault,
|
|
1603
|
+
...(group.description === undefined ? {} : { description: group.description }),
|
|
1604
|
+
children
|
|
1605
|
+
};
|
|
1606
|
+
}
|
|
1607
|
+
function createSnapshotNode(node, casing, globalLongOptionFlags, pathSegments, isDefault) {
|
|
1608
|
+
if (node.kind === "group") {
|
|
1609
|
+
return createSnapshotGroup(node, casing, globalLongOptionFlags, pathSegments, isDefault);
|
|
1610
|
+
}
|
|
1611
|
+
const collected = collectFields(node.params, casing, globalLongOptionFlags);
|
|
1612
|
+
const fields = assignPositionals(collected.fields, node.positional);
|
|
1613
|
+
validateUniqueOptionFlags(fields, globalLongOptionFlags);
|
|
1614
|
+
return {
|
|
1615
|
+
kind: "command",
|
|
1616
|
+
name: node.name,
|
|
1617
|
+
path: pathSegments,
|
|
1618
|
+
aliases: [...node.aliases],
|
|
1619
|
+
hidden: node.hidden,
|
|
1620
|
+
default: isDefault,
|
|
1621
|
+
...(node.description === undefined ? {} : { description: node.description }),
|
|
1622
|
+
options: [
|
|
1623
|
+
...fields.map((field) => createFieldSnapshotOption(field, globalLongOptionFlags)),
|
|
1624
|
+
...collected.dynamicFields.flatMap((field) => createDynamicSnapshotOptions(field, casing))
|
|
1625
|
+
]
|
|
1626
|
+
};
|
|
1627
|
+
}
|
|
1628
|
+
function createFieldSnapshotOption(field, globalLongOptionFlags) {
|
|
1629
|
+
return {
|
|
1630
|
+
name: field.displayPath,
|
|
1631
|
+
flags: formatHelpFieldFlags(field, globalLongOptionFlags).split(", "),
|
|
1632
|
+
type: formatJsonHelpSchemaType(field.schema),
|
|
1633
|
+
required: field.requiredWhenActive,
|
|
1634
|
+
hidden: false,
|
|
1635
|
+
...(field.description === undefined ? {} : { description: field.description }),
|
|
1636
|
+
...(field.hasDefault ? { default: field.defaultValue } : {}),
|
|
1637
|
+
...(field.positionalIndex === undefined ? {} : { positional: true }),
|
|
1638
|
+
...(field.global === true ? { global: true } : {})
|
|
1639
|
+
};
|
|
1640
|
+
}
|
|
1641
|
+
function createDynamicSnapshotOptions(field, casing) {
|
|
1642
|
+
return formatDynamicHelpFields(field, casing).map((row) => ({
|
|
1643
|
+
name: field.displayPath,
|
|
1644
|
+
flags: [row.flags],
|
|
1645
|
+
type: describeDynamicFieldType(field),
|
|
1646
|
+
required: field.requiredWhenActive,
|
|
1647
|
+
hidden: false,
|
|
1648
|
+
...(field.description === undefined ? {} : { description: field.description }),
|
|
1649
|
+
...(field.hasDefault ? { default: field.defaultValue } : {}),
|
|
1650
|
+
dynamic: true
|
|
1651
|
+
}));
|
|
1652
|
+
}
|
|
1485
1653
|
function addGlobalOptions(command, presetsEnabled, controls) {
|
|
1486
1654
|
const options = [];
|
|
1487
1655
|
if (presetsEnabled) {
|
package/dist/error-report.d.ts
CHANGED
|
@@ -18,6 +18,11 @@ export interface ErrorReportResult {
|
|
|
18
18
|
absolutePath: string;
|
|
19
19
|
displayPath: string;
|
|
20
20
|
}
|
|
21
|
+
export type ErrorReportRenderContext = Omit<ErrorReportContext, "errorReports" | "projectRoot">;
|
|
22
|
+
export interface ErrorReportRenderResult {
|
|
23
|
+
content: string;
|
|
24
|
+
redactedKeys: string[];
|
|
25
|
+
}
|
|
21
26
|
interface HttpErrorLike {
|
|
22
27
|
name: "HttpError";
|
|
23
28
|
message: string;
|
|
@@ -35,5 +40,11 @@ interface HttpErrorLike {
|
|
|
35
40
|
};
|
|
36
41
|
}
|
|
37
42
|
declare function hasHttpContext(error: unknown): error is HttpErrorLike;
|
|
43
|
+
/**
|
|
44
|
+
* Renders the exact redacted content used by `writeErrorReport` without checking report enablement
|
|
45
|
+
* or writing to the filesystem. `redactedKeys` lists every environment variable declared by the
|
|
46
|
+
* command's secrets in declaration order, including variables that are currently unset.
|
|
47
|
+
*/
|
|
48
|
+
export declare function renderErrorReport(context: ErrorReportRenderContext): ErrorReportRenderResult;
|
|
38
49
|
export declare function writeErrorReport(context: ErrorReportContext): Promise<ErrorReportResult | undefined>;
|
|
39
50
|
export { hasHttpContext };
|
package/dist/error-report.js
CHANGED
|
@@ -410,6 +410,17 @@ function buildReport(context) {
|
|
|
410
410
|
}
|
|
411
411
|
return `${lines.join("\n")}\n`;
|
|
412
412
|
}
|
|
413
|
+
/**
|
|
414
|
+
* Renders the exact redacted content used by `writeErrorReport` without checking report enablement
|
|
415
|
+
* or writing to the filesystem. `redactedKeys` lists every environment variable declared by the
|
|
416
|
+
* command's secrets in declaration order, including variables that are currently unset.
|
|
417
|
+
*/
|
|
418
|
+
export function renderErrorReport(context) {
|
|
419
|
+
return {
|
|
420
|
+
content: buildReport(context),
|
|
421
|
+
redactedKeys: commandSecretEnvNames(context.command?.secrets)
|
|
422
|
+
};
|
|
423
|
+
}
|
|
413
424
|
export async function writeErrorReport(context) {
|
|
414
425
|
const env = context.env ?? process.env;
|
|
415
426
|
if (!reportsEnabled(context.errorReports, env) || isSkippedError(context.error)) {
|
|
@@ -423,7 +434,7 @@ export async function writeErrorReport(context) {
|
|
|
423
434
|
if (reportDirMustStayWithinProject(context.errorReports)) {
|
|
424
435
|
await assertReportDirWithinProject(projectRoot, reportDir);
|
|
425
436
|
}
|
|
426
|
-
await writeFile(absolutePath,
|
|
437
|
+
await writeFile(absolutePath, renderErrorReport(context).content);
|
|
427
438
|
return {
|
|
428
439
|
absolutePath,
|
|
429
440
|
displayPath: relativeDisplayPath(projectRoot, absolutePath)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "toolcraft",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.91",
|
|
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.
|
|
59
|
+
"toolcraft-schema": "0.0.91",
|
|
60
60
|
"commander": "^13.1.0",
|
|
61
61
|
"fast-string-width": "^3.0.2",
|
|
62
62
|
"fast-wrap-ansi": "^0.2.0",
|