@deepdynamic/cli 0.1.4 → 0.1.5

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,16 +1,52 @@
1
- import { lstat, open, readdir, realpath, stat } from 'node:fs/promises';
1
+ import { execFile } from 'node:child_process';
2
+ import { lstat, mkdir, mkdtemp, open, readdir, realpath, rm, stat, writeFile } from 'node:fs/promises';
3
+ import { tmpdir } from 'node:os';
2
4
  import { basename, join } from 'node:path';
3
5
  import { credentialsPath } from "../../auth/credentials.js";
4
6
  const EXCLUDED_NAMES = [
5
7
  'node_modules', '.git', '.cache', '.ds_store', 'thumbs.db', '.env', '.envrc', '.dev.vars', '.wrangler', '.cloudflare', '.npmrc', '.netrc', '_netrc',
6
8
  '.yarnrc', '.yarnrc.yml', '.git-credentials', '.pypirc', '.ssh', '.aws', '.docker', '.kube', '.gnupg', '.svn', '.hg'
7
9
  ];
10
+ const IGNORE_PATTERNS = [...EXCLUDED_NAMES, '.env.*', '.dev.vars.*'];
8
11
  const sameFile = (first, second) => first.dev === second.dev && first.ino === second.ino;
9
12
  function isExcluded(name) {
10
13
  const normalized = name.toLowerCase();
11
14
  return EXCLUDED_NAMES.includes(normalized) || normalized.startsWith('.env.') || normalized.startsWith('.dev.vars.') || /^git~\d+$/.test(normalized) || /^\.git[. ]+$/.test(normalized);
12
15
  }
13
- export async function collectDeployFiles(root) {
16
+ const listGit = (args, cwd, env) => new Promise((resolve, reject) => {
17
+ execFile('git', args, { cwd, env, windowsHide: true, timeout: 180_000, maxBuffer: 64 * 1024 * 1024 }, (error, stdout) => {
18
+ if (error && 'code' in error && error.code === 'ENOENT')
19
+ return reject(new Error('Git is required to read .gitignore files. Install Git and retry.'));
20
+ resolve({ code: error ? typeof error.code === 'number' ? error.code : -1 : 0, stdout });
21
+ });
22
+ });
23
+ const gitPath = (path) => path.startsWith('\\\\?\\') && !path.startsWith('\\\\?\\UNC\\') ? path.slice(4) : path;
24
+ async function unignoredFiles(root, git) {
25
+ const work = await mkdtemp(join(tmpdir(), 'dd-files-'));
26
+ try {
27
+ const config = join(work, 'config');
28
+ const templates = join(work, 'templates');
29
+ await mkdir(templates);
30
+ await writeFile(config, '');
31
+ const env = Object.fromEntries(Object.entries(process.env).filter(([key]) => !/^(GIT_|GCM_)/i.test(key)));
32
+ Object.assign(env, { GIT_CONFIG_NOSYSTEM: '1', GIT_CONFIG_GLOBAL: config, GIT_CONFIG_SYSTEM: config, GIT_TEMPLATE_DIR: templates, GIT_TERMINAL_PROMPT: '0' });
33
+ const tree = gitPath(root);
34
+ const base = [`--git-dir=${join(work, 'git')}`, `--work-tree=${tree}`, '-c', `core.excludesFile=${config}`, '-c', 'safe.directory=*'];
35
+ const init = await git([...base, 'init', '-q'], tree, env);
36
+ const listed = init.code === 0
37
+ ? await git([...base, 'ls-files', '--others', '--exclude-standard', '-z', ...IGNORE_PATTERNS.flatMap((pattern) => ['-x', pattern])], tree, env)
38
+ : init;
39
+ if (listed.code !== 0)
40
+ throw new Error('Git could not read the .gitignore files of the directory.');
41
+ return new Set(listed.stdout.split('\0').filter(Boolean).map((path) => path.normalize('NFC')));
42
+ }
43
+ finally {
44
+ await rm(work, { recursive: true, force: true });
45
+ }
46
+ }
47
+ export async function collectDeployFiles(root, git = listGit) {
48
+ const kept = await unignoredFiles(root, git);
49
+ const folders = new Set([...kept].flatMap((path) => path.split('/').slice(0, -1).map((_, index, parts) => parts.slice(0, index + 1).join('/'))));
14
50
  const files = [];
15
51
  const paths = ['', '1'].map((development) => credentialsPath({ ...process.env, DEEPDYNAMIC_DEVELOPMENT: development }));
16
52
  const credentials = paths.map((path) => path.toLowerCase());
@@ -31,10 +67,13 @@ export async function collectDeployFiles(root) {
31
67
  const path = join(directory, entry.name);
32
68
  if (await isCredentials(path, entry.name))
33
69
  continue;
34
- if (entry.isDirectory())
35
- await walk(path, `${prefix}${entry.name}/`);
36
- else if (entry.isFile())
37
- files.push(`${prefix}${entry.name}`);
70
+ const relative = `${prefix}${entry.name}`;
71
+ if (entry.isDirectory()) {
72
+ if (folders.has(relative.normalize('NFC')))
73
+ await walk(path, `${relative}/`);
74
+ }
75
+ else if (entry.isFile() && kept.has(relative.normalize('NFC')))
76
+ files.push(relative);
38
77
  }
39
78
  };
40
79
  await walk(root, '');
@@ -55,7 +55,16 @@ export async function runDeploy(input, pretty, depth, deps = { ...defaultAuthDep
55
55
  : agentResult(1, { command, project, directory, error: { code: 'directory_not_found', message: 'The directory does not exist.' } });
56
56
  }
57
57
  const reader = await deployFileReader(directory);
58
- const files = await collectDeployFiles(directory);
58
+ let files;
59
+ try {
60
+ files = await collectDeployFiles(directory);
61
+ }
62
+ catch (error) {
63
+ const message = error instanceof Error ? error.message : String(error);
64
+ return pretty
65
+ ? prettyResult(1, depth, command, 'Could not list the files to upload.', [['Directory', directory], ['Reason', message]])
66
+ : agentResult(1, { command, project, directory, error: { code: 'file_list_failed', message } });
67
+ }
59
68
  if (files.length === 0) {
60
69
  return pretty
61
70
  ? prettyResult(1, depth, command, 'No files to upload after exclusions.', [['Directory', directory]])
@@ -7,6 +7,7 @@ import { SITE_URL } from "../../metadata.js";
7
7
  import { agentResult } from "../../output.js";
8
8
  import { prettyResult } from "../../pretty.js";
9
9
  import { openBrowser } from "../../runtime/browser.js";
10
+ import { detectAgent } from "../../runtime/card-request.js";
10
11
  import { startLoginScreen } from "../../runtime/login-screen.js";
11
12
  import { supportMessage } from "../../runtime/support.js";
12
13
  export const CLIENT_ID = 'dd-cli';
@@ -25,7 +26,7 @@ const failure = (pretty, depth, code, message) => pretty
25
26
  : agentResult(1, { command: 'login', error: { code, message } });
26
27
  const supportResult = (pretty, depth, code) => failure(pretty, depth, code, supportMessage(code));
27
28
  export const redirectUri = (port) => `http://127.0.0.1:${port}/callback`;
28
- export function authorizeUrl(siteUrl, port, challenge, state, agent = false) {
29
+ export function authorizeUrl(siteUrl, port, challenge, state, agent = null) {
29
30
  const url = new URL('/login/device', siteUrl);
30
31
  url.search = new URLSearchParams({
31
32
  response_type: 'code',
@@ -34,7 +35,7 @@ export function authorizeUrl(siteUrl, port, challenge, state, agent = false) {
34
35
  code_challenge: challenge,
35
36
  code_challenge_method: 'S256',
36
37
  state,
37
- ...(agent ? { requested_by: 'agent' } : {})
38
+ ...(agent ? { requested_by: 'agent', agent } : {})
38
39
  }).toString();
39
40
  return url.href;
40
41
  }
@@ -114,7 +115,7 @@ export async function login(deps, pretty = false, depth = 1) {
114
115
  await new Promise((resolve) => server.listen(0, '127.0.0.1', resolve));
115
116
  const { port } = server.address();
116
117
  const timer = setTimeout(() => settle(null), deps.timeoutMs);
117
- const url = authorizeUrl(deps.siteUrl, port, challenge, state, !pretty);
118
+ const url = authorizeUrl(deps.siteUrl, port, challenge, state, pretty ? null : detectAgent());
118
119
  const notice = `Finish logging in to DeepDynamic Cloud in your browser.\nIf the browser does not open, open this URL yourself.\n ${url}\n`;
119
120
  let stop;
120
121
  try {
@@ -583,11 +583,16 @@ export const details = {
583
583
  `Every deploy needs --agent with the code of the AI agent running it: ${AGENTS.map(([code, name]) => `${code} (${name})`).join(', ')}. Pass your own code. If you cannot tell which code is yours, ask the user before deploying.`,
584
584
  'The first deploy with --agent gives the project a flight number such as KR4821, shown with the agent on the projects page. Later deploys keep the flight number and record the agent of the latest deploy. A project deployed before --agent existed gets its flight number on its next deploy.',
585
585
  `Write the deploy settings in ${MANIFEST_FILE} at the root of the deployed directory. Without it the directory is served as static files exactly as uploaded, the same as {"output": "."}.`,
586
- `${MANIFEST_FILE} accepts only these fields: packageManager ("pnpm"), build ("pnpm build" or "pnpm run <script>"), output, start and port. A static site sets output (the build output folder relative to the directory, such as "dist"); packageManager and build come together or not at all. An app server sets start ("pnpm start" or "pnpm run <script>") and port (1024-65535) instead of output, needs packageManager "pnpm" and may add build, for example {"packageManager": "pnpm", "build": "pnpm build", "start": "pnpm start", "port": 3000}. Any other field, combination, command or package manager is rejected.`,
586
+ `${MANIFEST_FILE} accepts only these fields: runtime, packageManager, build, output, start and port. A static site sets output (the build output folder relative to the directory, such as "dist"). For Node.js, packageManager is "pnpm", build is "pnpm build" or "pnpm run <script>", and packageManager and build come together or not at all. An app server sets start and port (1024-65535) instead of output and may add build; with Node.js start is "pnpm start" or "pnpm run <script>" and packageManager "pnpm" is required, for example {"packageManager": "pnpm", "build": "pnpm build", "start": "pnpm start", "port": 3000}. Any other field, combination, command, runtime or package manager is rejected.`,
587
+ 'For Python, Rust or Java set runtime instead of packageManager: "python3.11", "python3.12", "python3.13", "python3.14", "python3.15", "rust", "java17", "java21" or "java25". No other runtime or version is installed. With runtime, build and start are commands followed by optional arguments separated by single spaces and made only of letters, digits and . _ : = / -. Python commands are "python -m <module>" or "python <file>.py"; they run in a virtual environment after pip installs requirements.txt, which must be committed (it may be empty). Rust commands start with the name of a binary target in Cargo.toml; the project server builds it with cargo build --release --locked on a pinned stable Rust, so Cargo.lock must be committed. A static site with runtime needs build and output, for example {"runtime": "python3.13", "build": "python -m mkdocs build", "output": "site"}; an app server needs start and port, for example {"runtime": "python3.13", "start": "python -m uvicorn main:app --host 127.0.0.1 --port 8000", "port": 8000} or {"runtime": "rust", "start": "server", "port": 8080}. Do not upload a folder named .dd; the deploy uses it.',
588
+ 'Java (such as Spring Boot) runs only as an app server, on Eclipse Temurin JDK 17, 21 or 25. build is the Gradle or Maven wrapper committed with the project, "./gradlew <tasks>" or "./mvnw <goals>", for example "./gradlew bootJar" or "./mvnw -DskipTests package"; commit gradlew with the gradle/wrapper folder, or mvnw with the .mvn/wrapper folder. start is "java -jar <file>.jar" with the path of the executable jar the build makes inside the project, for example {"runtime": "java21", "build": "./gradlew bootJar", "start": "java -jar build/libs/demo-0.0.1-SNAPSHOT.jar", "port": 8080}. SERVER_PORT is set to port as well as PORT, so Spring Boot listens on it without extra settings. Put JVM options such as -Xmx512m in JAVA_TOOL_OPTIONS with deepdynamic projects env push, not in start. buildTools is not available for Java.',
589
+ 'Add "buildTools": true (only with runtime) when a dependency compiles native code, such as Rust crates using openssl-sys or Python packages without prebuilt wheels. The project server then also installs gcc, pkg-config and libssl-dev, plus python3.X-dev for Python, before the build, so that deploy takes longer than usual: tell the user before deploying. Leave it out otherwise.',
590
+ 'The project server can open connections to the internet only on TCP 80, TCP 443, UDP 443, UDP 123 and TCP 4460, and resolves names through the project network DNS. Builds and apps cannot reach databases, mail servers, SSH or other services on other ports, so use HTTPS APIs instead.',
587
591
  'An app server must listen on 127.0.0.1 or 0.0.0.0 at the port given in the PORT environment variable, which is set to port. If it does not start answering HTTP, the previous release stays live and the deploy fails with publish_failed and the end of the app log in forAgent.publishLog.',
588
- 'Rules for the project you deploy: use pnpm only and commit pnpm-lock.yaml. Do not add npm or yarn lockfiles, and do not call npm, npx, yarn, curl or wget from package.json scripts.',
592
+ 'Rules for a Node.js project you deploy: use pnpm only and commit pnpm-lock.yaml. Do not add npm or yarn lockfiles, and do not call npm, npx, yarn, curl or wget from package.json scripts.',
589
593
  'List the packages whose install scripts the build needs, such as esbuild, in pnpm.onlyBuiltDependencies in package.json, and only those.',
590
594
  'Never put secrets such as API keys, tokens or .env values into source files or deepdynamic.json. Files named .env, .env.<anything>, .envrc, .dev.vars or .dev.vars.<anything> and credential files and folders such as .npmrc, .netrc, _netrc, .yarnrc.yml, .git-credentials, .pypirc, .ssh, .aws, .docker, .kube and .gnupg are never uploaded, but other names such as .env-local or secrets.json are uploaded like any file. Store secrets with deepdynamic projects env push <name> [<file>] instead: the build and the app server get them from the next deploy. Variables a bundler inlines into browser code (such as VITE_* or NEXT_PUBLIC_*) are public on the site anyway.',
595
+ 'Files and folders that the .gitignore files inside the deployed directory match are not uploaded. Git decides this exactly as git status would, so Git must be installed, also for --dry-run. .gitignore files above the directory, .git/info/exclude and global Git excludes are not used, and a subfolder that is itself a Git repository is skipped as Git skips it. Keep build output and environments such as target/, build/, .gradle/, .venv/ and __pycache__/ in .gitignore: one Git upload request is limited to 50 MB.',
591
596
  'For a static site the output folder must stay inside the project, and symbolic links in it are not published.',
592
597
  'Without a build, files are minified before upload. With a build, sources are uploaded unchanged.',
593
598
  'Automatically creates a progress record, reports upload stages, verifies the Git commit on the server and waits for publishing. A stopped project server is turned on first.',
@@ -618,7 +623,8 @@ export const details = {
618
623
  server_failed: SUPPORT_HELP,
619
624
  deploy_stopped: 'deepdynamic projects stop cancelled this deploy and turned the project server off. Deploy again when the user wants the site back.',
620
625
  upload_unverified: UPLOAD_UNVERIFIED,
621
- progress_unavailable: PROGRESS_UNAVAILABLE
626
+ progress_unavailable: PROGRESS_UNAVAILABLE,
627
+ file_list_failed: 'Git is missing or could not read the .gitignore files of the directory. Install Git or fix the message, then deploy again. No files were uploaded.'
622
628
  },
623
629
  options: [
624
630
  { flag: '<name>', description: 'Name of one of your projects created with deepdynamic projects create.', required: true },
package/dist/guide.js CHANGED
@@ -7,7 +7,7 @@ const SECTIONS = `## CLI projects and deploys
7
7
  - Naming a project: if the user did not give a name, first check \`deepdynamic projects\` for a project made from this source and deploy there if one exists. Otherwise read the source and look for evidence in this order: \`name\` in \`package.json\` (without \`@scope/\`) → the site \`<title>\` and first heading → the folder name, then summarize it into the shortest name that still says what the site is: one or two words of lowercase English letters, digits and hyphens, preferably 12 characters or fewer and longer only when no shorter name does. Drop filler words such as \`official\`, \`homepage\`, \`website\` or \`korea\`, build a long title around its most distinctive word such as a brand or place, use only abbreviations most people know, and join two words without a hyphen when they still read clearly (render Korean by its meaning in English or romanization, e.g. 제주 카페 → \`jejucafe\`, 서울대학교 총동문회 공식 홈페이지 → \`snu-alumni\`). Do not use names that say nothing about the content, such as \`app\`, \`site\`, \`test\`, \`my-app\` or \`vite-project\`, nor personal data or secrets. Names are globally unique, so check each candidate with \`deepdynamic projects create <name> --dry-run\` (checks only \`available\` and \`owned\` without creating), then show the user one available recommendation and two alternatives as full addresses (\`https://<name>.deepdynamic.space\`), the alternatives shortest first, each with a reason of a few words, and create it after they confirm. If a name is taken, first try another name of about the same length, such as a synonym or another key word, and only then add one short word that describes the content instead of random digits. The full rules are in the notes of \`deepdynamic projects create --help\`.
8
8
  - Renaming: for a project made with a name that says nothing about the content, such as \`demo-site\`, do not create a new one; name it from the source by the same rules and rename it with \`deepdynamic projects rename demo-site <new-name>\` (\`POST /api/v1/projects/{project}/rename\`). Check first with \`--dry-run\` that the name is available and have the user confirm one recommendation and two alternatives shown as full addresses. The issued address changes to the new name and is connected on the next deploy. The server, repository and deploy history stay, and later commands use the new name.
9
9
  - Installable app (PWA): \`deepdynamic projects pwa my-site\` (\`GET /api/v1/projects/{project}/pwa\`) returns in \`pwa\` whether the gateway advertises the site as an installable web app, and \`deepdynamic projects pwa my-site on|off\` (\`POST /api/v1/projects/{project}/pwa\`, \`{ enabled }\`) changes it. It is on by default; when on, the gateway always appends \`<link rel="manifest">\` before \`</head>\` while browsers use only the first manifest link on the page, so a manifest the site declares wins, and it serves \`/__dd/manifest.webmanifest\`, which Android Chrome uses for "Install app" and iOS Safari for "Add to Home Screen". No UI is injected into the page and the site files are not changed; when the gateway cannot be synchronized the command fails with \`unavailable\` and the setting stays as it was.
10
- - Deploy settings go in \`deepdynamic.json\` at the root of the deploy folder. The only accepted fields are \`packageManager\` (\`pnpm\` only), \`build\` (\`pnpm build\` or \`pnpm run <script>\`), \`output\` (relative path of the build output folder), \`start\` and \`port\`; without the file the uploaded files are served as they are. For an app server set \`start\` (\`pnpm start\` or \`pnpm run <script>\`) and \`port\` (1024-65535) instead of \`output\`: the project server starts it with \`PORT\` set and proxies the site to that port. Follow the notes of \`deepdynamic projects deploy --help\` for the full rules.
10
+ - Deploy settings go in \`deepdynamic.json\` at the root of the deploy folder. The only accepted fields are \`runtime\`, \`buildTools\`, \`packageManager\` (\`pnpm\` only), \`build\`, \`output\` (relative path of the build output folder), \`start\` and \`port\`; without the file the uploaded files are served as they are. For Node.js set \`packageManager\` with \`build\` (\`pnpm build\` or \`pnpm run <script>\`). For an app server set \`start\` and \`port\` (1024-65535) instead of \`output\`: the project server starts it with \`PORT\` set and proxies the site to that port; with Node.js \`start\` is \`pnpm start\` or \`pnpm run <script>\`. For Python, Rust or Java set \`runtime\` to \`python3.11\`, \`python3.12\`, \`python3.13\`, \`python3.14\`, \`python3.15\`, \`rust\`, \`java17\`, \`java21\` or \`java25\` instead of \`packageManager\`; \`build\` and \`start\` are then \`python -m <module>\` or \`python <file>.py\` (commit \`requirements.txt\`), or a Cargo binary name (commit \`Cargo.lock\`), followed by simple arguments. Java (such as Spring Boot) runs only as an app server on Eclipse Temurin: \`build\` is the committed Gradle or Maven wrapper (\`./gradlew bootJar\` or \`./mvnw -DskipTests package\`) and \`start\` is \`java -jar <file>.jar\` with the jar the build makes; \`SERVER_PORT\` is set to \`port\`, and \`buildTools\` is not available. No other runtime or version is available. Add \`"buildTools": true\` only when a dependency compiles native code (for example openssl-sys or a Python package without wheels); it installs gcc, pkg-config and libssl-dev and makes the deploy take longer than usual, so tell the user. The project server reaches the internet only on ports 80 and 443 (plus time sync), so apps must use HTTPS APIs rather than direct database or mail connections. Files matched by \`.gitignore\` files inside the deploy folder are not uploaded (Git decides, so Git must be installed); keep \`target/\`, \`build/\`, \`.gradle/\` and \`.venv/\` there, because one upload request is limited to 50 MB. Follow the notes of \`deepdynamic projects deploy --help\` for the full rules.
11
11
  - Security rules: use pnpm only and upload \`pnpm-lock.yaml\` with the source (the server installs with \`pnpm install --frozen-lockfile\`). Do not call npm, npx, yarn, curl or wget from package.json scripts, and list only the packages that really need install scripts in \`pnpm.onlyBuiltDependencies\`. Never put API keys, tokens or .env values into the source or settings. The build runs on the project server as a non-root user without deploy credentials.
12
12
  - Environment variables: \`deepdynamic projects env push my-site [.env]\` (\`GET\` and \`POST /api/v1/projects/{project}/env\`) seals the \`.env\` file on this device with the project server's public key, so the web server never sees the values. They reach the build and the app server from the next deploy or rollback and are masked as \`***\` in build and app logs. \`deepdynamic projects env list my-site\` shows only the names and \`deepdynamic projects env clear my-site --yes\` (\`POST /api/v1/projects/{project}/env/clear\`) removes them all. Values inlined into browser code such as \`VITE_*\` or \`NEXT_PUBLIC_*\` are visible on the site anyway.
13
13
  - Rollback: \`deepdynamic projects history my-site\` (\`GET /api/v1/projects/{project}/deployments\`) lists only deploys that finished publishing, the latest 20 by commit, and the first entry is the deploy published now. \`deepdynamic projects rollback my-site --yes\` rolls back to the previous deploy, and \`--to <commit>\` to the chosen one. It pushes a new commit holding exactly the files of the target commit, then builds and publishes again in the same stages as \`deepdynamic projects deploy\`; history is never erased. If the user did not name a target, show the history and have them confirm. Until \`deployed: true\` the previous site stays published.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deepdynamic/cli",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "Command-line tool for deploying and managing sites on DeepDynamic Cloud.",
5
5
  "keywords": [
6
6
  "deepdynamic",