@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,158 @@
1
+ import { spawn } from 'node:child_process';
2
+ import { randomUUID } from 'node:crypto';
3
+ import { mkdir, readFile, rm, stat, writeFile } from 'node:fs/promises';
4
+ import { dirname, join } from 'node:path';
5
+ import { fileURLToPath } from 'node:url';
6
+ import { credentialsPath } from "../auth/credentials.js";
7
+ import { call } from "../http/call.js";
8
+ import { jsonLine } from "../output.js";
9
+ import { developmentRun } from "./run-mode.js";
10
+ export const PACKAGE_NAME = '@deepdynamic/cli';
11
+ export const REGISTRY_URL = 'https://registry.npmjs.org/-/package/@deepdynamic/cli/dist-tags';
12
+ export const CHECK_INTERVAL_MS = 24 * 60 * 60 * 1000;
13
+ export const REFRESH_TIMEOUT_MS = 10_000;
14
+ export const LOCK_STALE_MS = 30 * 60 * 1000;
15
+ export const UPDATE_NEXT = 'deepdynamic update --yes';
16
+ export const REFRESH_ENTRY = fileURLToPath(new URL('../update-refresh.js', import.meta.url));
17
+ export const SKILL_REFRESH_ENTRY = fileURLToPath(new URL('../refresh-skills.js', import.meta.url));
18
+ const VERSION = /^(\d+)\.(\d+)\.(\d+)(-[0-9A-Za-z.-]+)?$/;
19
+ export const isVersion = (value) => typeof value === 'string' && VERSION.test(value);
20
+ export function latestOf(body) {
21
+ const latest = body?.latest;
22
+ return isVersion(latest) ? latest : null;
23
+ }
24
+ export function isNewer(latest, current) {
25
+ const next = VERSION.exec(latest);
26
+ const now = VERSION.exec(current);
27
+ if (!next || !now)
28
+ return false;
29
+ for (const index of [1, 2, 3]) {
30
+ const [a, b] = [Number(next[index]), Number(now[index])];
31
+ if (a !== b)
32
+ return a > b;
33
+ }
34
+ return !next[4] && !!now[4];
35
+ }
36
+ const isSet = (value) => !!value && value !== '0' && value !== 'false';
37
+ export const updateCheckEnabled = (env) => !isSet(env.DEEPDYNAMIC_NO_UPDATE_CHECK) && !isSet(env.CI);
38
+ export const updateCachePath = (env = process.env) => join(dirname(credentialsPath(env)), 'update-check.json');
39
+ export const updateLockPath = (cachePath) => join(dirname(cachePath), 'update.lock');
40
+ export async function readUpdateCache(path) {
41
+ try {
42
+ const { checkedAt, latest, installed } = JSON.parse(await readFile(path, 'utf8'));
43
+ if (!Number.isFinite(checkedAt) || !(latest === null || isVersion(latest)))
44
+ return null;
45
+ return isVersion(installed?.previous) && isVersion(installed?.version)
46
+ ? { checkedAt, latest, installed: { previous: installed.previous, version: installed.version } }
47
+ : { checkedAt, latest };
48
+ }
49
+ catch {
50
+ return null;
51
+ }
52
+ }
53
+ export async function saveUpdateCache(path, cache) {
54
+ await mkdir(dirname(path), { recursive: true, mode: 0o700 });
55
+ await writeFile(path, `${JSON.stringify(cache)}\n`);
56
+ }
57
+ const createLock = (path, token) => writeFile(path, token, { flag: 'wx' }).then(() => true, () => false);
58
+ const lockAge = (path, now) => stat(path).then(({ mtimeMs }) => now() - mtimeMs, () => null);
59
+ async function claimLock(path, token, now) {
60
+ try {
61
+ await mkdir(dirname(path), { recursive: true, mode: 0o700 });
62
+ }
63
+ catch {
64
+ return false;
65
+ }
66
+ if (await createLock(path, token))
67
+ return true;
68
+ const age = await lockAge(path, now);
69
+ if (age === null || age < LOCK_STALE_MS)
70
+ return false;
71
+ const takeover = `${path}.takeover`;
72
+ if (((await lockAge(takeover, now)) ?? 0) >= LOCK_STALE_MS)
73
+ await rm(takeover, { force: true });
74
+ if (!(await createLock(takeover, token)))
75
+ return false;
76
+ try {
77
+ if (((await lockAge(path, now)) ?? LOCK_STALE_MS) < LOCK_STALE_MS)
78
+ return false;
79
+ await rm(path, { force: true });
80
+ return await createLock(path, token);
81
+ }
82
+ finally {
83
+ await rm(takeover, { force: true });
84
+ }
85
+ }
86
+ export async function withUpdateLock(path, task, now = Date.now) {
87
+ const token = `${process.pid} ${randomUUID()}\n`;
88
+ if (!(await claimLock(path, token, now)))
89
+ return null;
90
+ try {
91
+ return await task();
92
+ }
93
+ finally {
94
+ if (await readFile(path, 'utf8').catch(() => null) === token)
95
+ await rm(path, { force: true });
96
+ }
97
+ }
98
+ export async function refreshUpdateCache(path, current, install, fetcher = fetch, now = Date.now) {
99
+ try {
100
+ const response = await call(REGISTRY_URL, { method: 'GET', redirect: 'manual', signal: AbortSignal.timeout(REFRESH_TIMEOUT_MS) }, fetcher);
101
+ const latest = response.status === 200 ? latestOf(await response.json()) : null;
102
+ if (!latest)
103
+ return;
104
+ const installed = install !== null && isNewer(latest, current) && await install(latest).catch(() => false);
105
+ await saveUpdateCache(path, { checkedAt: now(), latest, ...(installed ? { installed: { previous: current, version: latest } } : {}) });
106
+ }
107
+ catch {
108
+ return;
109
+ }
110
+ }
111
+ export const refreshArgs = () => [REFRESH_ENTRY, developmentRun() ? 'check' : 'install'];
112
+ function startDetached(args) {
113
+ const child = spawn(process.execPath, args, { detached: true, stdio: 'ignore', windowsHide: true });
114
+ child.on('error', () => { });
115
+ child.unref();
116
+ }
117
+ export function startRefresh() {
118
+ startDetached(refreshArgs());
119
+ }
120
+ export function startSkillRefresh() {
121
+ startDetached([SKILL_REFRESH_ENTRY]);
122
+ }
123
+ export const defaultUpdateDeps = () => ({ path: updateCachePath(), env: process.env, now: Date.now, startRefresh, startSkillRefresh });
124
+ export async function pendingUpdate(current, deps = defaultUpdateDeps()) {
125
+ if (!updateCheckEnabled(deps.env))
126
+ return null;
127
+ const cache = await readUpdateCache(deps.path);
128
+ const now = deps.now();
129
+ const stale = !cache || now - cache.checkedAt >= CHECK_INTERVAL_MS || cache.checkedAt > now;
130
+ const updated = cache?.installed?.version === current ? cache.installed : null;
131
+ if (stale || updated) {
132
+ const kept = cache?.installed && !updated ? { installed: cache.installed } : {};
133
+ await saveUpdateCache(deps.path, { checkedAt: stale ? now : cache.checkedAt, latest: cache?.latest ?? null, ...kept })
134
+ .then(() => {
135
+ if (stale)
136
+ deps.startRefresh();
137
+ if (updated)
138
+ deps.startSkillRefresh();
139
+ }, () => { });
140
+ }
141
+ if (updated)
142
+ return { event: 'updated', previous: updated.previous };
143
+ return cache?.latest && isNewer(cache.latest, current) ? { event: 'update_available', latest: cache.latest } : null;
144
+ }
145
+ export const updateLine = (current, notice) => jsonLine(notice.event === 'updated'
146
+ ? {
147
+ event: 'updated',
148
+ previous: notice.previous,
149
+ current,
150
+ message: `DeepDynamic CLI was updated in the background from ${notice.previous} to ${current}. This run uses ${current}.`
151
+ }
152
+ : {
153
+ event: 'update_available',
154
+ current,
155
+ latest: notice.latest,
156
+ next: UPDATE_NEXT,
157
+ message: `DeepDynamic CLI ${notice.latest} is available (current ${current}) and was not installed automatically. Confirm with the user, then run: ${UPDATE_NEXT}`
158
+ });
@@ -0,0 +1,80 @@
1
+ import { spawn } from 'node:child_process';
2
+ import { realpath } from 'node:fs/promises';
3
+ import { homedir } from 'node:os';
4
+ import { join, win32 } from 'node:path';
5
+ import { fileURLToPath } from 'node:url';
6
+ import { PACKAGE_NAME } from "./update-check.js";
7
+ export const INSTALL_TIMEOUT_MS = 10 * 60 * 1000;
8
+ const TASKKILL = win32.join(process.env.SystemRoot || 'C:\\Windows', 'System32', 'taskkill.exe');
9
+ export const PACKAGE_DIR = fileURLToPath(new URL('../..', import.meta.url));
10
+ export const packageManagerOf = (path) => (/[\\/]\.pnpm[\\/]/.test(path) ? 'pnpm' : 'npm');
11
+ export const installArgs = (manager, version) => [manager === 'pnpm' ? 'add' : 'install', '--global', `${PACKAGE_NAME}@${version}`];
12
+ function stopProgram(child, platform) {
13
+ if (platform !== 'win32' || child.pid === undefined) {
14
+ child.kill();
15
+ return;
16
+ }
17
+ const fallback = () => child.kill();
18
+ const killer = spawn(TASKKILL, ['/pid', String(child.pid), '/t', '/f'], { stdio: 'ignore', windowsHide: true });
19
+ killer.on('error', fallback);
20
+ killer.on('close', fallback);
21
+ }
22
+ export function runProgram(path, args, platform = process.platform, timeoutMs = INSTALL_TIMEOUT_MS) {
23
+ const options = { stdio: ['ignore', 'pipe', 'pipe'], windowsHide: true };
24
+ const child = platform === 'win32' && /\.(cmd|bat)$/i.test(path)
25
+ ? spawn(`"${path}" ${args.join(' ')}`, { ...options, shell: true })
26
+ : spawn(path, args, options);
27
+ let stdout = '';
28
+ let output = '';
29
+ child.stdout?.on('data', (chunk) => {
30
+ stdout = `${stdout}${chunk.toString('utf8')}`.slice(-4000);
31
+ output = `${output}${chunk.toString('utf8')}`.slice(-4000);
32
+ });
33
+ child.stderr?.on('data', (chunk) => {
34
+ output = `${output}${chunk.toString('utf8')}`.slice(-4000);
35
+ });
36
+ return new Promise((resolve) => {
37
+ let timedOut = false;
38
+ let settled = false;
39
+ const settle = (result) => {
40
+ if (settled)
41
+ return;
42
+ settled = true;
43
+ clearTimeout(timer);
44
+ resolve(result);
45
+ };
46
+ const timer = setTimeout(() => {
47
+ timedOut = true;
48
+ stopProgram(child, platform);
49
+ }, timeoutMs);
50
+ const expired = () => ({ status: null, stdout, output: `Timed out after ${timeoutMs / 60_000} minutes. ${output.trim()}`.trim().slice(-500) });
51
+ child.on('error', (error) => settle({ status: null, stdout: '', output: error.message }));
52
+ child.on('exit', () => {
53
+ if (timedOut)
54
+ settle(expired());
55
+ });
56
+ child.on('close', (status) => settle(timedOut ? expired() : { status, stdout, output: output.trim().slice(-500) }));
57
+ });
58
+ }
59
+ export const findPackageManager = async (name) => (await import("../agents/install.js")).systemCommands({ home: homedir(), platform: process.platform, vars: process.env }).find(name);
60
+ export const defaultAutoInstallDeps = () => ({ packageDir: PACKAGE_DIR, platform: process.platform, find: findPackageManager, run: runProgram });
61
+ export async function isGlobalInstall(path, { packageDir, platform, run }) {
62
+ const { status, stdout } = await run(path, ['root', '--global']);
63
+ const root = status === 0 ? stdout.trim().split(/\r?\n/).pop() : undefined;
64
+ if (!root)
65
+ return false;
66
+ const [global, own] = await Promise.all([
67
+ realpath(join(root, ...PACKAGE_NAME.split('/'))).catch(() => null),
68
+ realpath(packageDir).catch(() => null)
69
+ ]);
70
+ if (!global || !own)
71
+ return false;
72
+ return platform === 'win32' ? global.toLowerCase() === own.toLowerCase() : global === own;
73
+ }
74
+ export async function autoInstall(latest, deps = defaultAutoInstallDeps()) {
75
+ const manager = packageManagerOf(deps.packageDir);
76
+ const path = await deps.find(manager);
77
+ if (!path || !(await isGlobalInstall(path, deps)))
78
+ return false;
79
+ return (await deps.run(path, installArgs(manager, latest))).status === 0;
80
+ }
@@ -0,0 +1,9 @@
1
+ import { agentResult } from "../output.js";
2
+ import { prettyResult } from "../pretty.js";
3
+ import { spec } from "../registry.js";
4
+ export function usageError(command, message, pretty, depth) {
5
+ const { usage } = spec(command);
6
+ return pretty
7
+ ? prettyResult(2, depth, command, message, [['Usage', usage]])
8
+ : agentResult(2, { command, error: { code: 'invalid_arguments', message }, usage });
9
+ }
@@ -0,0 +1,15 @@
1
+ import { homedir } from 'node:os';
2
+ import { systemCommands } from "./agents/install.js";
3
+ import { runAgentSetup } from "./agents/setup.js";
4
+ import { startSpinner } from "./runtime/spinner.js";
5
+ const env = { home: homedir(), platform: process.platform, vars: process.env };
6
+ let step = '';
7
+ const stop = startSpinner(() => `Installing skills${step}`, process.stderr);
8
+ const result = await runAgentSetup(env, systemCommands(env), process.getuid?.() ?? null, (agent, item) => {
9
+ step = ` · ${agent} ${item}`;
10
+ });
11
+ stop();
12
+ if (!process.stdout.isTTY)
13
+ process.stdout.write(result.stdout);
14
+ process.stderr.write(result.stderr);
15
+ process.exitCode = result.code;
package/dist/site.js ADDED
@@ -0,0 +1 @@
1
+ export const SITE_URL = 'https://cloud.deepdynamic.net';
@@ -0,0 +1,5 @@
1
+ import { version } from "./metadata.js";
2
+ import { refreshUpdateCache, updateCachePath, updateLockPath, withUpdateLock } from "./runtime/update-check.js";
3
+ import { autoInstall } from "./runtime/update-install.js";
4
+ const path = updateCachePath();
5
+ await withUpdateLock(updateLockPath(path), () => refreshUpdateCache(path, version, process.argv[2] === 'install' ? autoInstall : null)).catch(() => null);
package/package.json CHANGED
@@ -1,6 +1,49 @@
1
1
  {
2
2
  "name": "@deepdynamic/cli",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.1",
4
+ "description": "Command-line tool for deploying and managing sites on DeepDynamic Cloud.",
5
+ "keywords": [
6
+ "deepdynamic",
7
+ "cli",
8
+ "deploy",
9
+ "hosting",
10
+ "static-site",
11
+ "mcp",
12
+ "ai-agent"
13
+ ],
14
+ "homepage": "https://cloud.deepdynamic.net",
15
+ "license": "Apache-2.0",
16
+ "author": "DeepDynamic <mail@deepdynamic.net>",
17
+ "bugs": {
18
+ "email": "mail@deepdynamic.net"
19
+ },
20
+ "type": "module",
21
+ "bin": {
22
+ "deepdynamic": "dist/index.js"
23
+ },
24
+ "files": [
25
+ "dist",
26
+ "!dist/dev.js",
27
+ "THIRD_PARTY_NOTICES.txt"
28
+ ],
29
+ "engines": {
30
+ "node": ">=22.12.0"
31
+ },
32
+ "devDependencies": {
33
+ "@types/html-minifier-terser": "^7.0.2",
34
+ "@types/node": "^22.12.0",
35
+ "typescript": "^6.0.3"
36
+ },
37
+ "dependencies": {
38
+ "esbuild": "0.28.2",
39
+ "html-minifier-terser": "7.2.0",
40
+ "jsonc-parser": "3.3.1",
41
+ "yaml": "2.9.1"
42
+ },
43
+ "scripts": {
44
+ "dev": "pnpm build && node dist/dev.js",
45
+ "build": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\" && tsc -p tsconfig.json",
46
+ "start": "node dist/index.js",
47
+ "check": "tsc -p tsconfig.json --noEmit"
48
+ }
6
49
  }