bdy 1.25.2-stage → 1.25.2

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,7 +1,7 @@
1
1
  {
2
2
  "name": "bdy",
3
3
  "preferGlobal": false,
4
- "version": "1.25.2-stage",
4
+ "version": "1.25.2",
5
5
  "type": "commonjs",
6
6
  "license": "MIT",
7
7
  "homepage": "https://buddy.works/docs/cli",
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const commander_1 = require("commander");
7
+ const output_1 = __importDefault(require("./output"));
8
+ const cliError_1 = __importDefault(require("./cliError"));
9
+ const texts_1 = require("./texts");
10
+ /** Command documentation shared by terminal help and machine discovery. */
11
+ class CliCommand extends commander_1.Command {
12
+ agentStatus;
13
+ agentInstalled;
14
+ agentId;
15
+ agentStandalone;
16
+ currentVersion;
17
+ latestVersion;
18
+ env;
19
+ hideVersionUpdate;
20
+ agentPort;
21
+ skipPre = false;
22
+ defaultErrorFormat = 'text';
23
+ metadata;
24
+ constructor(name, metadata = {}) {
25
+ super(name);
26
+ this.metadata = metadata;
27
+ }
28
+ addOption(option) {
29
+ if (option.long === '--format' && !option.argChoices) {
30
+ const choices = option.flags.match(/<([^>]+)>/)?.[1].split('|');
31
+ if (choices?.every((value) => ['text', 'json', 'jsonl'].includes(value)))
32
+ option.choices(choices);
33
+ }
34
+ return super.addOption(option);
35
+ }
36
+ parseOptions(args) {
37
+ output_1.default.errorFormat = this.defaultErrorFormat;
38
+ const formatOption = this.options.find((option) => option.long === '--format');
39
+ if (formatOption && this.defaultErrorFormat === 'text') {
40
+ // Let Commander handle option syntax without running our parsers, hooks
41
+ // or actions. Even if a required value is missing, earlier format values
42
+ // are available before the real parser reports the error.
43
+ const probe = new commander_1.Command()
44
+ .exitOverride()
45
+ .configureOutput({ writeErr: () => { } });
46
+ for (const option of this.options)
47
+ probe.option(option.flags);
48
+ try {
49
+ probe.parseOptions(args);
50
+ }
51
+ catch (err) {
52
+ if (!(err instanceof commander_1.CommanderError))
53
+ throw err;
54
+ }
55
+ const format = probe.opts().format;
56
+ if (formatOption.argChoices?.includes(format) &&
57
+ (format === 'json' || format === 'jsonl'))
58
+ output_1.default.errorFormat = format;
59
+ }
60
+ this.showSuggestionAfterError(output_1.default.errorFormat === 'text');
61
+ return super.parseOptions(args);
62
+ }
63
+ error(message, options) {
64
+ if (output_1.default.errorFormat === 'text')
65
+ return super.error(message, options);
66
+ const path = [this.name()];
67
+ for (let command = this.parent; command; command = command.parent)
68
+ path.unshift(command.name());
69
+ output_1.default.exitError(new cliError_1.default(options?.code === 'commander.unknownCommand'
70
+ ? 'unknown_command'
71
+ : 'usage_error', message.replace(/^error: /, '').trim(), (0, texts_1.TXT_CLI_USAGE_HINT)(path.join(' '))));
72
+ }
73
+ get requiredScopes() {
74
+ return this.metadata.requiredScopes ?? null;
75
+ }
76
+ get examples() {
77
+ return this.metadata.examples ?? [];
78
+ }
79
+ }
80
+ exports.default = CliCommand;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class CliError extends Error {
4
+ code;
5
+ hint;
6
+ constructor(code, message, hint = null, options) {
7
+ super(message, options);
8
+ this.code = code;
9
+ this.hint = hint;
10
+ this.name = 'CliError';
11
+ }
12
+ static details(error) {
13
+ if (error instanceof CliError) {
14
+ return { code: error.code, message: error.message, hint: error.hint };
15
+ }
16
+ const { code, syscall } = error ?? {};
17
+ const missingFile = code === 'ENOENT' &&
18
+ [
19
+ 'open',
20
+ 'stat',
21
+ 'lstat',
22
+ 'access',
23
+ 'scandir',
24
+ 'readlink',
25
+ 'realpath',
26
+ ].includes(syscall ?? '');
27
+ return {
28
+ code: missingFile ? 'file_not_found' : 'command_failed',
29
+ message: error instanceof Error ? error.message : String(error),
30
+ hint: null,
31
+ };
32
+ }
33
+ }
34
+ exports.default = CliError;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const discovery_1 = require("../discovery");
7
+ const output_1 = __importDefault(require("../output"));
8
+ const cliError_1 = __importDefault(require("../cliError"));
9
+ const texts_1 = require("../texts");
10
+ const utils_1 = require("../utils");
11
+ const commandDiscover = (0, utils_1.newCommand)('discover', texts_1.DESC_COMMAND_DISCOVER, {
12
+ requiredScopes: [],
13
+ examples: texts_1.EXAMPLE_DISCOVER,
14
+ helpText: texts_1.HELP_COMMAND_DISCOVER,
15
+ });
16
+ commandDiscover.skipPre = true;
17
+ commandDiscover.defaultErrorFormat = 'json';
18
+ commandDiscover.showSuggestionAfterError(false);
19
+ commandDiscover.argument('[command...]', texts_1.OPTION_DISCOVER_COMMAND);
20
+ commandDiscover.option('--full', texts_1.OPTION_DISCOVER_FULL);
21
+ commandDiscover.action((path, options, command) => {
22
+ const result = (0, discovery_1.discoverCommands)(command.parent, path, (0, utils_1.getVersion)(), options.full);
23
+ if (result.error) {
24
+ const { code, message, hint } = result.error;
25
+ output_1.default.writeError(new cliError_1.default(code, message, hint), 'json');
26
+ process.exitCode = 1;
27
+ }
28
+ else {
29
+ output_1.default.json(result);
30
+ }
31
+ });
32
+ exports.default = commandDiscover;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.finishExec = finishExec;
7
+ const output_1 = __importDefault(require("../../output"));
8
+ const utils_1 = require("../../utils");
9
+ const texts_1 = require("../../texts");
10
+ async function finishExec(client, workspace, sandboxId, identifier, commandId, follow, jsonl) {
11
+ const body = await client.streamSandboxCommandLogs(workspace, sandboxId, commandId, follow);
12
+ await output_1.default.streamCommandLogs(body, jsonl);
13
+ const cmdExit = await client.getSandboxCommand(workspace, sandboxId, commandId);
14
+ if (jsonl) {
15
+ output_1.default.json({
16
+ type: 'exit',
17
+ status: cmdExit.status,
18
+ exit_code: cmdExit.exit_code ?? null,
19
+ });
20
+ if ([utils_1.SANDBOX_EXEC_STATUS.SUCCESSFUL, utils_1.SANDBOX_EXEC_STATUS.INPROGRESS].includes(cmdExit.status)) {
21
+ output_1.default.exitNormal();
22
+ }
23
+ output_1.default.exitCode(1);
24
+ }
25
+ if (cmdExit.status === utils_1.SANDBOX_EXEC_STATUS.SUCCESSFUL) {
26
+ output_1.default.exitSuccess((0, texts_1.TXT_SANDBOX_EXEC_SUCCESS)(identifier, commandId));
27
+ }
28
+ else if (cmdExit.status === utils_1.SANDBOX_EXEC_STATUS.INPROGRESS) {
29
+ output_1.default.exitNormal((0, texts_1.TXT_SANDBOX_EXEC_INPROGRESS)(identifier, commandId));
30
+ }
31
+ else {
32
+ output_1.default.exitError((0, texts_1.TXT_SANDBOX_EXEC_FAILED)(identifier, commandId));
33
+ }
34
+ }
@@ -0,0 +1,119 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.discoverCommands = exports.describeCommand = void 0;
7
+ const cliCommand_1 = __importDefault(require("./cliCommand"));
8
+ const texts_1 = require("./texts");
9
+ const sortedChildren = (command) => command
10
+ .createHelp()
11
+ .visibleCommands(command)
12
+ // Commander may append a synthetic help command. Only expose registered commands.
13
+ .filter((child) => command.commands.includes(child))
14
+ .sort((a, b) => (a.name() < b.name() ? -1 : a.name() > b.name() ? 1 : 0));
15
+ const commandPath = (command) => command.parent
16
+ ? `${commandPath(command.parent)} ${command.name()}`
17
+ : command.name() || 'bdy';
18
+ const optionInfo = (option) => {
19
+ const value = option.flags.match(/[<[]([^>\]]+)[>\]]/)?.[1] ?? null;
20
+ // These are static documentation, never resolved values from opts(), env or config.
21
+ const env = option.envVar ??
22
+ option.description.match(/Can be set via variable:\s*([A-Z][A-Z0-9_]*)/)?.[1] ??
23
+ null;
24
+ const documentedDefault = option.description.match(/Default:\s*(.+)$/)?.[1] ?? null;
25
+ const choices = option.argChoices ??
26
+ (value &&
27
+ /^[A-Za-z][A-Za-z0-9_-]*(?:\|[A-Za-z][A-Za-z0-9_-]*)+$/.test(value)
28
+ ? value.split('|')
29
+ : null);
30
+ return {
31
+ flags: option.flags,
32
+ short: option.short ?? null,
33
+ long: option.long ?? null,
34
+ description: option.description,
35
+ required: option.mandatory,
36
+ value: value
37
+ ? {
38
+ name: value,
39
+ required: option.required,
40
+ variadic: !!option.variadic,
41
+ }
42
+ : null,
43
+ negated: option.negate,
44
+ choices,
45
+ default: option.defaultValue ?? null,
46
+ documented_default: documentedDefault,
47
+ env,
48
+ };
49
+ };
50
+ const describeCommand = (command) => ({
51
+ command: commandPath(command),
52
+ aliases: command.aliases(),
53
+ description: command.description(),
54
+ usage: `${commandPath(command)} ${command.usage()}`.trim(),
55
+ arguments: command.registeredArguments.map((argument) => ({
56
+ name: argument.name(),
57
+ description: argument.description,
58
+ required: argument.required,
59
+ variadic: argument.variadic,
60
+ choices: argument.argChoices ?? null,
61
+ default: argument.defaultValue ?? null,
62
+ })),
63
+ options: command
64
+ .createHelp()
65
+ .visibleOptions(command)
66
+ .filter((option) => option.long !== '--help')
67
+ .map(optionInfo),
68
+ required_scopes: command instanceof cliCommand_1.default ? command.requiredScopes : null,
69
+ examples: command instanceof cliCommand_1.default ? command.examples : [],
70
+ });
71
+ exports.describeCommand = describeCommand;
72
+ const describeTree = (command) => ({
73
+ ...(0, exports.describeCommand)(command),
74
+ subcommands: sortedChildren(command).map(describeTree),
75
+ });
76
+ const summarizeTree = (command) => [
77
+ {
78
+ command: commandPath(command),
79
+ description: command.description(),
80
+ },
81
+ ...sortedChildren(command).flatMap(summarizeTree),
82
+ ];
83
+ const discoverCommands = (program, path, version, full = false) => {
84
+ let selected = program;
85
+ const selectedPath = [];
86
+ for (const part of path) {
87
+ const child = sortedChildren(selected).find((command) => command.name() === part || command.aliases().includes(part));
88
+ if (!child)
89
+ return {
90
+ error: {
91
+ code: 'unknown_command',
92
+ message: (0, texts_1.ERR_DISCOVER_UNKNOWN_COMMAND)(part, commandPath(selected)),
93
+ hint: (0, texts_1.TXT_DISCOVER_COMMAND_HINT)(selectedPath),
94
+ },
95
+ };
96
+ selected = child;
97
+ selectedPath.push(child.name());
98
+ }
99
+ const commands = selected === program ? sortedChildren(program) : [selected];
100
+ const includeDetails = full || (selected !== program && sortedChildren(selected).length === 0);
101
+ return {
102
+ schema_version: 1,
103
+ cli_version: version,
104
+ // Root flags must precede the subcommand; keep them separate from local options.
105
+ ...(includeDetails
106
+ ? {
107
+ global_options: program
108
+ .createHelp()
109
+ .visibleOptions(program)
110
+ .map(optionInfo),
111
+ }
112
+ : {}),
113
+ commands: includeDetails
114
+ ? commands.map(describeTree)
115
+ : commands.flatMap(summarizeTree),
116
+ tips: texts_1.DISCOVERY_TIPS,
117
+ };
118
+ };
119
+ exports.discoverCommands = discoverCommands;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bdy",
3
3
  "preferGlobal": false,
4
- "version": "1.25.2-stage",
4
+ "version": "1.25.2",
5
5
  "type": "commonjs",
6
6
  "license": "MIT",
7
7
  "homepage": "https://buddy.works/docs/cli",