@deepdynamic/cli 0.0.0-stage → 0.1.1

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 (84) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +32 -2
  3. package/THIRD_PARTY_NOTICES.txt +102 -0
  4. package/dist/agents/content.js +12 -0
  5. package/dist/agents/edit.js +140 -0
  6. package/dist/agents/install.js +190 -0
  7. package/dist/agents/refresh.js +20 -0
  8. package/dist/agents/setup.js +29 -0
  9. package/dist/agents/targets.js +91 -0
  10. package/dist/auth/credentials.js +63 -0
  11. package/dist/auth/session.js +49 -0
  12. package/dist/cli.js +198 -0
  13. package/dist/commands/account.js +96 -0
  14. package/dist/commands/activity.js +80 -0
  15. package/dist/commands/blocked.js +89 -0
  16. package/dist/commands/deploy/agents.js +11 -0
  17. package/dist/commands/deploy/files.js +62 -0
  18. package/dist/commands/deploy/index.js +95 -0
  19. package/dist/commands/deploy/manifest.js +24 -0
  20. package/dist/commands/deploy/minify.js +27 -0
  21. package/dist/commands/deploy/progress.js +85 -0
  22. package/dist/commands/deploy/ship.js +117 -0
  23. package/dist/commands/deploy/upload.js +125 -0
  24. package/dist/commands/deployments.js +60 -0
  25. package/dist/commands/dns.js +777 -0
  26. package/dist/commands/domains.js +639 -0
  27. package/dist/commands/emails.js +74 -0
  28. package/dist/commands/env.js +194 -0
  29. package/dist/commands/help.js +148 -0
  30. package/dist/commands/keys.js +263 -0
  31. package/dist/commands/login/flow.js +155 -0
  32. package/dist/commands/login/index.js +26 -0
  33. package/dist/commands/logout.js +71 -0
  34. package/dist/commands/mail.js +241 -0
  35. package/dist/commands/notifications.js +133 -0
  36. package/dist/commands/plan.js +355 -0
  37. package/dist/commands/projects.js +838 -0
  38. package/dist/commands/reference.js +2187 -0
  39. package/dist/commands/search.js +86 -0
  40. package/dist/commands/server.js +301 -0
  41. package/dist/commands/sessions.js +114 -0
  42. package/dist/commands/sites.js +102 -0
  43. package/dist/commands/sms.js +65 -0
  44. package/dist/commands/status.js +87 -0
  45. package/dist/commands/support.js +115 -0
  46. package/dist/commands/update.js +100 -0
  47. package/dist/commands/usage.js +51 -0
  48. package/dist/commands/verify.js +149 -0
  49. package/dist/commands/version.js +6 -0
  50. package/dist/guide.js +37 -0
  51. package/dist/http/call.js +6 -0
  52. package/dist/http/request.js +54 -0
  53. package/dist/index.js +11 -0
  54. package/dist/metadata.js +4 -0
  55. package/dist/output.js +9 -0
  56. package/dist/pretty.js +70 -0
  57. package/dist/refresh-skills.js +5 -0
  58. package/dist/registry.js +688 -0
  59. package/dist/runtime/browser.js +15 -0
  60. package/dist/runtime/card-request.js +55 -0
  61. package/dist/runtime/confirm.js +21 -0
  62. package/dist/runtime/development.js +13 -0
  63. package/dist/runtime/domain-name.js +5 -0
  64. package/dist/runtime/dry-run.js +28 -0
  65. package/dist/runtime/env-file.js +55 -0
  66. package/dist/runtime/error-hints.js +26 -0
  67. package/dist/runtime/flags.js +48 -0
  68. package/dist/runtime/login-screen.js +78 -0
  69. package/dist/runtime/page.js +18 -0
  70. package/dist/runtime/project-name.js +1 -0
  71. package/dist/runtime/run-mode.js +7 -0
  72. package/dist/runtime/server-options.js +28 -0
  73. package/dist/runtime/spinner.js +17 -0
  74. package/dist/runtime/suggest.js +22 -0
  75. package/dist/runtime/support.js +13 -0
  76. package/dist/runtime/text-file.js +20 -0
  77. package/dist/runtime/timeout.js +22 -0
  78. package/dist/runtime/update-check.js +158 -0
  79. package/dist/runtime/update-install.js +80 -0
  80. package/dist/runtime/usage-error.js +9 -0
  81. package/dist/setup-agents.js +15 -0
  82. package/dist/site.js +1 -0
  83. package/dist/update-refresh.js +5 -0
  84. package/package.json +46 -3
@@ -0,0 +1,74 @@
1
+ import { authorized, defaultAuthDeps } from "../auth/session.js";
2
+ import { LOGIN_EXPIRED, accepted, httpFailure, postJson, sendFailureError } from "../http/request.js";
3
+ import { agentResult } from "../output.js";
4
+ import { prettyResult } from "../pretty.js";
5
+ import { spec } from "../registry.js";
6
+ import { splitDryRun } from "../runtime/dry-run.js";
7
+ import { parseFlags } from "../runtime/flags.js";
8
+ import { readText } from "../runtime/text-file.js";
9
+ export const EMAILS_PATH = '/api/v1/emails';
10
+ const { name: command, usage } = spec('emails send');
11
+ const FLAGS = ['--to', '--title', '--body', '--body-file'];
12
+ const BODY_ESCAPE_RE = /\\(\\|r\\n|n|t)/g;
13
+ function unescapeBody(body) {
14
+ return body.replace(BODY_ESCAPE_RE, (_, escape) => (escape === '\\' ? '\\' : escape === 't' ? '\t' : '\n'));
15
+ }
16
+ async function parseSendArgs(args) {
17
+ const parsed = parseFlags(args, FLAGS);
18
+ if ('error' in parsed)
19
+ return parsed;
20
+ const values = Object.fromEntries(parsed.entries);
21
+ const { '--to': to, '--title': title, '--body': body, '--body-file': bodyFile } = values;
22
+ if (to === undefined || title === undefined) {
23
+ const missing = to === undefined ? '--to' : '--title';
24
+ return { error: `${missing} is required.` };
25
+ }
26
+ const content = await readText('--body', body === undefined ? undefined : unescapeBody(body), bodyFile);
27
+ return 'error' in content ? content : { to, title, body: content.text };
28
+ }
29
+ export async function runEmailSend(args, pretty, depth, deps = defaultAuthDeps(pretty, depth)) {
30
+ const { args: rest, dryRun } = splitDryRun(args);
31
+ const parsed = await parseSendArgs(rest);
32
+ if ('error' in parsed) {
33
+ return pretty
34
+ ? prettyResult(2, depth, command, parsed.error, [['Usage', usage]])
35
+ : agentResult(2, { command, error: { code: 'invalid_arguments', message: parsed.error }, usage });
36
+ }
37
+ const sent = await authorized(deps, ({ siteUrl, token }) => postJson(new URL(EMAILS_PATH, siteUrl).href, token, dryRun ? { ...parsed, dryRun } : parsed, deps, pretty ? (dryRun ? 'Validating the email.' : 'Sending the email.') : null));
38
+ if ('login' in sent)
39
+ return sent.login;
40
+ const { session: { siteUrl }, result } = sent;
41
+ let failure = null;
42
+ let rejected = false;
43
+ if ('failure' in result) {
44
+ failure = result.failure;
45
+ }
46
+ else if (result.status === 401) {
47
+ failure = LOGIN_EXPIRED;
48
+ }
49
+ else if (!accepted(result)) {
50
+ rejected = result.status === 400 && result.body?.rejected === true;
51
+ failure = rejected
52
+ ? { code: 'spam_rejected', message: 'The server rejected the email as advertising or spam. The account may be blocked if this continues.', display: 'The server rejected the email as advertising or spam. The account may be blocked if this continues.' }
53
+ : result.status === 429
54
+ ? { code: 'rate_limited', message: 'Too many emails. Try again later.', display: 'Too many emails. Try again later.' }
55
+ : result.status === 400
56
+ ? { code: 'rejected', message: 'The server rejected the email. Check the recipient, title and body.', display: 'The server rejected the email. Check the recipient, title and body.' }
57
+ : httpFailure(result.status);
58
+ }
59
+ if (failure) {
60
+ return pretty
61
+ ? prettyResult(1, depth, command, rejected ? 'The email was rejected.' : dryRun ? 'Could not validate the email.' : 'Could not send the email.', [['Server', siteUrl], ['Reason', failure.display]])
62
+ : agentResult(1, { command, siteUrl, delivered: false, ...(rejected ? { rejected } : {}), error: sendFailureError(result, failure) });
63
+ }
64
+ const { dryRun: checked, delivered, id, from, to, replyTo, bcc } = result.body;
65
+ if (!pretty) {
66
+ return agentResult(0, { command, siteUrl, ...(checked === true ? { dryRun: true } : {}), delivered, rejected, id, from, to, replyTo, bcc });
67
+ }
68
+ return prettyResult(0, depth, command, checked === true ? 'Validated the email. Nothing was sent.' : 'Sent the email.', [
69
+ ['Server', siteUrl],
70
+ ['From', from],
71
+ ['To', to],
72
+ ['Reply-To', replyTo]
73
+ ]);
74
+ }
@@ -0,0 +1,194 @@
1
+ import { readFile } from 'node:fs/promises';
2
+ import { resolve } from 'node:path';
3
+ import { authorized, defaultAuthDeps, signedIn } from "../auth/session.js";
4
+ import { LOGIN_EXPIRED, UNEXPECTED, failureError, httpFailure, postJson, request } from "../http/request.js";
5
+ import { agentResult } from "../output.js";
6
+ import { prettyResult } from "../pretty.js";
7
+ import { confirmationRequired, splitYes } from "../runtime/confirm.js";
8
+ import { plannedChange, plannedRequest, splitDryRun } from "../runtime/dry-run.js";
9
+ import { readEnv, sealEnv, validSeal } from "../runtime/env-file.js";
10
+ import { parseCommand } from "../runtime/flags.js";
11
+ import { PROJECT } from "../runtime/project-name.js";
12
+ import { supportFailure, supportMessage } from "../runtime/support.js";
13
+ import { usageError } from "../runtime/usage-error.js";
14
+ export const ENV_FILE = '.env';
15
+ const NEXT_DEPLOY = 'Changes apply to builds and the app server from the next deploy or rollback.';
16
+ const NAME_ERROR = 'The project name must be 1-63 lowercase letters, digits or hyphens that start and end with a letter or digit.';
17
+ const NOT_FOUND_MESSAGE = 'You have no project with that name. Check the name with deepdynamic projects.';
18
+ const SEAL_KEY_MESSAGE = 'The variables could not be saved. Run the same command again.';
19
+ const variableCount = (count) => `${count.toLocaleString('en-US')} environment variable${count === 1 ? '' : 's'}`;
20
+ const PROJECT_NOT_FOUND = { code: 'project_not_found', message: NOT_FOUND_MESSAGE, display: NOT_FOUND_MESSAGE };
21
+ const ENV_UNAVAILABLE = supportFailure('env_unavailable', { note: 'Nothing was sent.' });
22
+ const SEAL_KEY_CHANGED = { code: 'seal_key_changed', message: SEAL_KEY_MESSAGE, display: SEAL_KEY_MESSAGE };
23
+ const envUrl = (siteUrl, project, action = '') => new URL(`/api/v1/projects/${project}/env${action}`, siteUrl).href;
24
+ function envState(body, project) {
25
+ const value = body;
26
+ if (value?.ok !== true || value.project !== project || !Array.isArray(value.names) || !value.names.every((name) => typeof name === 'string')
27
+ || (value.updatedAt !== null && typeof value.updatedAt !== 'string') || (value.seal !== undefined && value.seal !== null && !validSeal(value.seal)))
28
+ return null;
29
+ return { names: value.names, updatedAt: value.updatedAt, seal: (value.seal ?? null) };
30
+ }
31
+ function failureOf(result) {
32
+ if ('failure' in result)
33
+ return result.failure;
34
+ if (result.status === 401)
35
+ return LOGIN_EXPIRED;
36
+ if (result.status === 404)
37
+ return PROJECT_NOT_FOUND;
38
+ if (result.status === 409)
39
+ return SEAL_KEY_CHANGED;
40
+ if (result.status !== 200)
41
+ return httpFailure(result.status);
42
+ return null;
43
+ }
44
+ function failed(command, pretty, depth, siteUrl, project, message, failure) {
45
+ return pretty
46
+ ? prettyResult(1, depth, command, message, [['Server', siteUrl], ['Project', project], ['Reason', failure.display]])
47
+ : agentResult(1, { command, siteUrl, project, error: failureError(failure) });
48
+ }
49
+ function parseProject(command, names, max, pretty, depth) {
50
+ if (names.length < 1 || names.length > max) {
51
+ return usageError(command, max === 1
52
+ ? 'Specify exactly one project name.'
53
+ : 'Specify the project name and at most one env file.', pretty, depth);
54
+ }
55
+ return PROJECT.test(names[0]) ? names[0] : usageError(command, NAME_ERROR, pretty, depth);
56
+ }
57
+ const getEnv = (session, project, deps, spinner) => request(envUrl(session.siteUrl, project), { method: 'GET', headers: { authorization: `Bearer ${session.token}` } }, deps, spinner);
58
+ async function readVars(command, path, pretty, depth) {
59
+ let text;
60
+ try {
61
+ text = await readFile(path, 'utf8');
62
+ }
63
+ catch (error) {
64
+ const reason = error.code ?? String(error);
65
+ return {
66
+ result: pretty
67
+ ? prettyResult(1, depth, command, 'Could not read the env file.', [['File', path], ['Reason', reason]])
68
+ : agentResult(1, { command, file: path, error: { code: 'env_file_unreadable', message: `Cannot read the env file (${reason}).` } })
69
+ };
70
+ }
71
+ const read = readEnv(text);
72
+ if ('vars' in read)
73
+ return read;
74
+ return {
75
+ result: pretty
76
+ ? prettyResult(1, depth, command, 'Check the env file.', [['File', path], ['Reason', read.error]])
77
+ : agentResult(1, { command, file: path, error: { code: 'invalid_env', message: read.error } })
78
+ };
79
+ }
80
+ export async function runEnvPush(args, pretty, depth, deps = defaultAuthDeps(pretty, depth)) {
81
+ const command = 'projects env push';
82
+ const { args: rest, dryRun } = splitDryRun(args);
83
+ const parsed = parseCommand(rest, []);
84
+ if ('error' in parsed)
85
+ return usageError(command, parsed.error, pretty, depth);
86
+ const project = parseProject(command, parsed.names, 2, pretty, depth);
87
+ if (typeof project !== 'string')
88
+ return project;
89
+ const file = resolve(parsed.names[1] ?? ENV_FILE);
90
+ const read = await readVars(command, file, pretty, depth);
91
+ if ('result' in read)
92
+ return read.result;
93
+ const names = Object.keys(read.vars).sort();
94
+ if (dryRun) {
95
+ const session = await signedIn(deps);
96
+ if ('login' in session)
97
+ return session.login;
98
+ return plannedChange(command, pretty, depth, session.siteUrl, { url: envUrl(session.siteUrl, project), body: { names } }, `Checked ${variableCount(names.length)}. Nothing was sealed or sent.`, [['Project', project], ['File', file], ['Variables', names.join(', ')]], { project, file, names });
99
+ }
100
+ const sent = await authorized(deps, (session) => getEnv(session, project, deps, pretty ? 'Preparing to save the environment variables.' : null));
101
+ if ('login' in sent)
102
+ return sent.login;
103
+ const { session } = sent;
104
+ const current = failureOf(sent.result) ? null : envState(sent.result.body, project);
105
+ const keyFailure = failureOf(sent.result) ?? (current ? current.seal ? null : ENV_UNAVAILABLE : UNEXPECTED);
106
+ if (keyFailure)
107
+ return failed(command, pretty, depth, session.siteUrl, project, 'Could not save the environment variables.', keyFailure);
108
+ let sealed;
109
+ try {
110
+ sealed = sealEnv(read.vars, current.seal);
111
+ }
112
+ catch {
113
+ return failed(command, pretty, depth, session.siteUrl, project, 'Could not save the environment variables.', UNEXPECTED);
114
+ }
115
+ const saved = await postJson(envUrl(session.siteUrl, project), session.token, { sealed, names }, deps, pretty ? 'Sealing and sending the environment variables.' : null);
116
+ const state = failureOf(saved) ? null : envState(saved.body, project);
117
+ const saveFailure = failureOf(saved) ?? (state ? null : UNEXPECTED);
118
+ if (saveFailure)
119
+ return failed(command, pretty, depth, session.siteUrl, project, 'Could not save the environment variables.', saveFailure);
120
+ if (!pretty)
121
+ return agentResult(0, { command, siteUrl: session.siteUrl, project, file, names: state.names, updatedAt: state.updatedAt, appliesFrom: 'next_deploy' });
122
+ return prettyResult(0, depth, command, `Sealed and saved ${variableCount(state.names.length)}. ${NEXT_DEPLOY}`, [
123
+ ['Server', session.siteUrl], ['Project', project], ['File', file], ['Variables', state.names.join(', ')]
124
+ ]);
125
+ }
126
+ export async function runEnvList(args, pretty, depth, deps = defaultAuthDeps(pretty, depth)) {
127
+ const command = 'projects env list';
128
+ const { args: rest, dryRun } = splitDryRun(args);
129
+ const parsed = parseCommand(rest, []);
130
+ if ('error' in parsed)
131
+ return usageError(command, parsed.error, pretty, depth);
132
+ const project = parseProject(command, parsed.names, 1, pretty, depth);
133
+ if (typeof project !== 'string')
134
+ return project;
135
+ if (dryRun) {
136
+ const session = await signedIn(deps);
137
+ if ('login' in session)
138
+ return session.login;
139
+ return plannedRequest(command, pretty, depth, session.siteUrl, envUrl(session.siteUrl, project));
140
+ }
141
+ const sent = await authorized(deps, (session) => getEnv(session, project, deps, pretty ? 'Loading the environment variables.' : null));
142
+ if ('login' in sent)
143
+ return sent.login;
144
+ const { session, result } = sent;
145
+ const state = failureOf(result) ? null : envState(result.body, project);
146
+ const failure = failureOf(result) ?? (state ? null : UNEXPECTED);
147
+ if (failure)
148
+ return failed(command, pretty, depth, session.siteUrl, project, 'Could not load the environment variables.', failure);
149
+ const { names, updatedAt, seal } = state;
150
+ if (!pretty)
151
+ return agentResult(0, { command, siteUrl: session.siteUrl, project, names, updatedAt, enabled: seal !== null });
152
+ return prettyResult(0, depth, command, names.length ? `Found ${variableCount(names.length)}. Only names are shown because not even the server can read the values.` : 'No environment variables are saved.', [
153
+ ['Server', session.siteUrl], ['Project', project],
154
+ ...(names.length ? [['Variables', names.join(', ')], ['Saved at', updatedAt ?? '']] : []),
155
+ ...(seal ? [] : [['Notice', supportMessage('env_unavailable')]])
156
+ ]);
157
+ }
158
+ export async function runEnvClear(args, pretty, depth, deps = defaultAuthDeps(pretty, depth)) {
159
+ const command = 'projects env clear';
160
+ const { args: plain, dryRun } = splitDryRun(args);
161
+ const { args: rest, yes } = splitYes(plain);
162
+ const parsed = parseCommand(rest, []);
163
+ if ('error' in parsed)
164
+ return usageError(command, parsed.error, pretty, depth);
165
+ const project = parseProject(command, parsed.names, 1, pretty, depth);
166
+ if (typeof project !== 'string')
167
+ return project;
168
+ if (dryRun) {
169
+ const session = await signedIn(deps);
170
+ if ('login' in session)
171
+ return session.login;
172
+ return plannedChange(command, pretty, depth, session.siteUrl, { url: envUrl(session.siteUrl, project, '/clear') }, 'Checked clearing the environment variables. Nothing was cleared.', [['Project', project]], { project });
173
+ }
174
+ if (!yes) {
175
+ return confirmationRequired(command, plain, pretty, depth, {
176
+ message: 'Clearing removes every stored environment variable of the project; the next deploy builds and runs without them.',
177
+ display: 'Clearing removes every saved environment variable; the next deploy builds and runs without them. Confirm with the user, then run the command with --yes.'
178
+ }, { project });
179
+ }
180
+ const sent = await authorized(deps, (session) => request(envUrl(session.siteUrl, project, '/clear'), {
181
+ method: 'POST', headers: { authorization: `Bearer ${session.token}` }
182
+ }, deps, pretty ? 'Clearing the environment variables.' : null));
183
+ if ('login' in sent)
184
+ return sent.login;
185
+ const { session, result } = sent;
186
+ const value = failureOf(result) ? null : result.body;
187
+ const failure = failureOf(result) ?? (value?.ok === true && value.project === project && typeof value.cleared === 'boolean' ? null : UNEXPECTED);
188
+ if (failure)
189
+ return failed(command, pretty, depth, session.siteUrl, project, 'Could not clear the environment variables.', failure);
190
+ const cleared = value.cleared;
191
+ if (!pretty)
192
+ return agentResult(0, { command, siteUrl: session.siteUrl, project, cleared, appliesFrom: 'next_deploy' });
193
+ return prettyResult(0, depth, command, cleared ? `Cleared all saved environment variables. ${NEXT_DEPLOY}` : 'There were no environment variables to clear.', [['Server', session.siteUrl], ['Project', project]]);
194
+ }
@@ -0,0 +1,148 @@
1
+ import { SITE_URL } from "../metadata.js";
2
+ import { agentResult } from "../output.js";
3
+ import { displayWidth, pad, paint, prettyResult } from "../pretty.js";
4
+ import { commands, requiredUsage } from "../registry.js";
5
+ import { unknownArgument } from "../runtime/flags.js";
6
+ import { LOGIN_TIMEOUT_OPTION } from "../runtime/timeout.js";
7
+ import { usageError } from "../runtime/usage-error.js";
8
+ import { LOGIN_TIMEOUT_MS } from "./login/flow.js";
9
+ import { HELP_USAGE, details } from "./reference.js";
10
+ export const CLI_USAGE = 'deepdynamic [--pretty] [--login-timeout <seconds>] <command> [options]';
11
+ const options = [
12
+ ['-h, --help', 'Show help'],
13
+ ['-v, --version', 'Show the CLI version'],
14
+ [' --pretty', 'Show human-readable output instead of JSON'],
15
+ [' --login-timeout', `Seconds to wait for the login window, 1-${LOGIN_TIMEOUT_MS / 1000} (default ${LOGIN_TIMEOUT_MS / 1000})`]
16
+ ];
17
+ const docs = [
18
+ ['Agents', `${SITE_URL}/llms.txt`],
19
+ ['Developers', `${SITE_URL}/docs/dev`],
20
+ ['CLI', `${SITE_URL}/cli.md`]
21
+ ];
22
+ export function runHelp(args, version, depth, pretty) {
23
+ const rest = args.filter((arg) => arg !== '--all');
24
+ if (rest.length) {
25
+ return usageError('help', unknownArgument(rest[0]), pretty, depth);
26
+ }
27
+ if (args.length)
28
+ return runCommands([], version, depth, pretty);
29
+ return pretty ? { code: 0, stdout: renderHome(depth), stderr: '' } : agentResult(0, agentHome(version));
30
+ }
31
+ function fields({ name, usage, description, effect, requiresLogin, requiresBrowser, dryRun, confirm }) {
32
+ return {
33
+ name,
34
+ usage,
35
+ description,
36
+ effect,
37
+ requiresLogin,
38
+ ...(requiresBrowser ? { requiresBrowser } : {}),
39
+ ...(dryRun ? { dryRun } : {}),
40
+ ...(confirm ? { confirm } : {})
41
+ };
42
+ }
43
+ export function commandTree() {
44
+ const tree = [];
45
+ for (const entry of commands) {
46
+ const head = entry.name.split(' ')[0];
47
+ let node = tree.find(({ name }) => name === head);
48
+ if (!node) {
49
+ node = { name: head };
50
+ tree.push(node);
51
+ }
52
+ if (entry.name === head)
53
+ Object.assign(node, fields(entry));
54
+ else
55
+ (node.commands ??= []).push(fields(entry));
56
+ }
57
+ return tree;
58
+ }
59
+ export function runCommands(args, version, depth, pretty) {
60
+ const command = 'commands';
61
+ if (args.length)
62
+ return usageError(command, unknownArgument(args[0]), pretty, depth);
63
+ if (!pretty)
64
+ return agentResult(0, { command, version, commands: commandTree() });
65
+ return prettyResult(0, depth, command, 'Listed all commands.', commands.map(({ name, summary }) => [`deepdynamic ${name}`, summary]));
66
+ }
67
+ export function runCommandHelp(args, pretty, depth) {
68
+ const length = args.findIndex((arg) => arg === '-h' || arg === '--help');
69
+ if (length < 1)
70
+ return null;
71
+ const topic = args.slice(0, length).join(' ');
72
+ const entries = commands.filter(({ name }) => name === topic || name.startsWith(`${topic} `));
73
+ if (!entries.length)
74
+ return null;
75
+ if (!pretty) {
76
+ return agentResult(0, {
77
+ command: 'help',
78
+ topic,
79
+ commands: entries.map((entry) => {
80
+ const { prettyOptions: _, ...detail } = details[entry.name];
81
+ return entry.name === topic ? { ...fields(entry), ...detail } : {
82
+ name: entry.name,
83
+ usage: entry.usage,
84
+ description: entry.description,
85
+ options: detail.options?.map(({ flag }) => flag) ?? [],
86
+ help: `deepdynamic ${entry.name} --help`
87
+ };
88
+ })
89
+ });
90
+ }
91
+ const stdout = entries
92
+ .map((entry) => prettyResult(0, depth, entry.name, 'Showed the help.', [['Usage', entry.usage], ...details[entry.name].prettyOptions]).stdout)
93
+ .join('');
94
+ return { code: 0, stdout, stderr: '' };
95
+ }
96
+ export function agentHome(version) {
97
+ return {
98
+ command: 'help',
99
+ name: 'DeepDynamic Cloud CLI',
100
+ version,
101
+ description: 'Deploy static and dynamic sites to DeepDynamic Cloud.',
102
+ usage: CLI_USAGE,
103
+ start: { command: 'deepdynamic account get', reason: 'Returns the signed-in account and the guide for talking to this user. Run it first.' },
104
+ commands: commands.map(({ name, usage, description, requiresBrowser, requiresLogin }) => ({
105
+ name,
106
+ usage,
107
+ description,
108
+ ...(requiresBrowser ? { requiresBrowser } : {}),
109
+ ...(requiresLogin ? { requiresLogin } : {})
110
+ })),
111
+ help: HELP_USAGE,
112
+ tree: 'deepdynamic commands',
113
+ options: [
114
+ { flags: ['-h', '--help'], description: 'Show help.' },
115
+ { flags: ['-v', '--version'], description: 'Show the CLI version.' },
116
+ { flags: ['--pretty'], description: 'Use the human-readable interface instead of JSON.' },
117
+ {
118
+ flags: [LOGIN_TIMEOUT_OPTION],
119
+ description: `Seconds to wait for the browser sign-in window, 1-${LOGIN_TIMEOUT_MS / 1000} (default ${LOGIN_TIMEOUT_MS / 1000}). The window still opens. When the seconds run out the command fails with login_timeout and that window can no longer sign in. Set it below the time limit of your shell.`
120
+ }
121
+ ],
122
+ docs: { agents: `${SITE_URL}/llms.txt`, developers: `${SITE_URL}/docs/dev`, cli: `${SITE_URL}/cli.md` },
123
+ exitCodes: { 0: 'Success', 1: 'Command failed', 2: 'Invalid command or arguments', 3: 'Confirmation required: nothing was sent. Ask the user, then run error.next' }
124
+ };
125
+ }
126
+ export function renderHome(depth) {
127
+ const { bold } = paint(depth);
128
+ const lines = commands.map(({ usage, summary }) => [requiredUsage(usage), summary]);
129
+ const labels = [...lines.map(([label]) => label), ...[...options, ...docs].map(([label]) => label)];
130
+ const labelWidth = Math.max(...labels.map(displayWidth));
131
+ const item = (label, text) => ` ${pad(label, labelWidth)} ${text}`;
132
+ return [
133
+ 'The official CLI for deploying static and dynamic sites to DeepDynamic Cloud.',
134
+ '',
135
+ bold('Usage'),
136
+ ' deepdynamic <command> [options]',
137
+ '',
138
+ bold('Commands'),
139
+ ...lines.map(([label, summary]) => item(label, summary)),
140
+ '',
141
+ bold('Options'),
142
+ ...options.map(([label, text]) => item(label, text)),
143
+ '',
144
+ bold('Docs'),
145
+ ...docs.map(([label, url]) => item(label, url)),
146
+ ''
147
+ ].join('\n');
148
+ }