@minato-aqukin/autodl-cli 0.1.1 → 0.2.0

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/README.md CHANGED
@@ -49,10 +49,10 @@ being saved, and you land on the dashboard. Once configured, `autodl` goes strai
49
49
 
50
50
  A live table of your instances: status, GPU, region, **how long each has been powered on
51
51
  and roughly what that has cost**, and how much TTL is left. Keys: `↑↓` move, `Enter`
52
- detail, `s` start, `x` stop, `c` copy the SSH command to the clipboard, `ctrl+d` release, `g` GPU stock,
53
- `n` new instance, `r` refresh, `ctrl+l` log out, `q` quit. The two that change or destroy
54
- something take ctrl rather than a bare key; shift makes no difference to either, and the
55
- hints are printed all-lowercase so they do not read as bindings you hold shift for.
52
+ detail, `s` start, `x` stop, `ctrl+d` release, `g` stock,
53
+ `r` refresh, `ctrl+l` log out, `?` help, `q` quit. Release and logout require confirmation.
54
+ The detail screen (`Enter`) owns the per-instance keys: `h` automatically authenticated
55
+ SSH, `f` files, `t` transfers, `c` copy the SSH command, `n` new instance.
56
56
 
57
57
  `ctrl+d` release wipes the instance permanently, which is why it is not a bare `d`.
58
58
 
@@ -61,6 +61,10 @@ it says so when `AUTODL_TOKEN` or `--token` will outrank whatever you save next.
61
61
  API rejects the token while the dashboard is open — expired, reset, verification lapsed —
62
62
  polling stops and the same login screen is one keystroke away, rather than leaving a
63
63
  frozen table above an endless stream of 401s.
64
+ Re-login keeps the same token precedence: `--token` › `AUTODL_TOKEN` › saved token.
65
+ Saving a different token does not switch accounts while an override is active. If that
66
+ override is invalid, remove or update it and restart the TUI; it will not silently fall
67
+ back to the saved account. Authentication failures from GPU stock queries also end the session.
64
68
 
65
69
  It fills the terminal and shows your account id and balance in the header. Copying with
66
70
  `c` puts only the SSH command on the clipboard — never the root password, which any
@@ -78,11 +82,69 @@ Two deliberate honesty constraints. A rate is only knowable from a **running** i
78
82
  snapshot, so a stopped instance shows elapsed time and no money — inventing a number
79
83
  would be worse than showing none. And while a rate is still loading the total says so
80
84
  rather than quietly under-reporting.
85
+ Account runway stays pending until every running instance's rate is known; an unknown
86
+ rate is never treated as free compute. On short terminals, including 80×24, the resource
87
+ and billing panels are hidden when their stacked layout would obscure the instance list
88
+ or keyboard hints.
81
89
 
82
90
  The TUI never runs in a pipe, in CI, or under `--json`: it exits with code 2 and an
83
91
  explanation instead of taking over a terminal that isn't there. A bare `autodl` outside
84
92
  an interactive terminal still prints help exactly as before.
85
93
 
94
+ ### SSH and file management
95
+
96
+ Open the detail screen (`Enter`) and press `h`: it hands the entire terminal to a
97
+ password-authenticated SSH session and restores the dashboard on exit or disconnect;
98
+ this is not an embedded terminal. Credentials are
99
+ fetched live and never placed in command arguments, logs, or transfer records.
100
+ The CLI equivalent is `autodl ssh <id> --auto-auth`. This mode uses ssh2, not OpenSSH
101
+ configuration. Keep using ordinary `autodl ssh <id>` for `~/.ssh/config`, agents and
102
+ forwarding such as `-L`. The implementation uses cross-platform Node.js terminal and
103
+ filesystem interfaces for Linux, macOS and native Windows; sshpass is not required.
104
+
105
+ On the detail screen, `f` opens local/remote panes; narrow terminals show the active pane. `Tab` switches
106
+ sides, arrows and Enter navigate, Space selects multiple entries, and `a` selects all.
107
+ `g` accepts a directory path; `p` accepts source/destination paths directly.
108
+ `u` transfers the selection to the opposite pane after confirming direction.
109
+ `m` creates directories, `r` renames or moves within one side, and `x` permanently
110
+ deletes after confirmation. `Q` opens the queue; Esc returns.
111
+
112
+ Relative paths resolve against their corresponding pane. Selected source basenames
113
+ are preserved: copying `project` into `/root/work` produces `/root/work/project`.
114
+ The browser transfers explicitly selected directory contents, without the legacy
115
+ `push` command's ignore rules. Symlinks and special files are skipped; queue details
116
+ offer `v` to browse every skipped entry.
117
+
118
+ Ordinary conflicts pause for `o` overwrite, `s` skip, or `b` keep both; `a` applies the
119
+ choice to remaining conflicts in this task. Toggle `s` in the browser to synchronize
120
+ one way: skip unchanged files, replace changed files in full, and **never delete
121
+ destination-only files**. Size/mtime comparison is the default; `c` enables SHA-256
122
+ comparison. Checksumming reads both files; remote contents are streamed over SFTP,
123
+ so strict checking can cost as much bandwidth as downloading the files.
124
+
125
+ The session queue is serial, with byte progress, speed, cancellation (`c`), details
126
+ (Enter), and manual resume (`r`). Recoverable transport failures have bounded retries;
127
+ authentication failures and powered-off instances pause instead. Starting a stopped
128
+ instance to open SSH/files or resume a task always requires a billing confirmation.
129
+ Automatic reconnect never powers an instance on.
130
+ The file view holds one browsing connection for list/mkdir/rename/remove; directory
131
+ contents are always read live, a dead connection reconnects on the next operation,
132
+ and leaving the view releases it.
133
+ The CLI `files` and `queue` commands share the same queue records: a task added via
134
+ `queue add` can be confirmed and resumed from the dashboard, and vice versa.
135
+
136
+ Transfers write same-directory `.autodl-*.part` files and commit only after completion,
137
+ preserving existing destinations on interruption. Resume validates the source version
138
+ and partial prefix, restarting changed/corrupt files. Remote replacement requires the
139
+ OpenSSH atomic-rename extension; unsupported servers fail without deleting the old file.
140
+ Credential-free records live under the config directory's `transfers/`, scoped by
141
+ account and API endpoint. Exit/logout pauses unfinished work. Restored tasks require
142
+ manual resume: **nothing runs in the background after exit**. Only one process may
143
+ mutate an account's queue; dead-process ownership claims are recoverable.
144
+ Cancelled tasks retain partial data; remove their `.part` files and local checkpoints
145
+ only when you no longer need to resume them.
146
+
147
+
86
148
  ## Setup
87
149
 
88
150
  The official API needs a developer token from an **identity-verified** account
@@ -258,6 +320,9 @@ Stable across minor versions. Breaking changes require a major.
258
320
 
259
321
  **stdout in `--json` mode is pure JSON.** Progress, prompts and warnings all go to
260
322
  stderr, so `autodl ... --json | jq` is always safe.
323
+ Unknown commands, unknown options and missing arguments use exit code 2 with a `USAGE`
324
+ error, including a JSON error object when `--json` is enabled. `tui --json` follows the
325
+ same error contract; explicit help and version requests still print their normal text.
261
326
 
262
327
  ```jsonc
263
328
  // success
@@ -292,9 +357,10 @@ stderr, so `autodl ... --json | jq` is always safe.
292
357
  | `info <id> [--show-password]` | Details, live SSH info, resource usage |
293
358
  | `create --gpu <spec>` | Create a pay-as-you-go Pro instance |
294
359
  | `start` / `stop` / `rm <id>` | Power on / off / release |
295
- | `ssh <id>` | Interactive login (extra flags pass through to `ssh`) |
360
+ | `ssh <id> [--auto-auth]` | System OpenSSH with extra flags, or automatic instance-password authentication |
296
361
  | `exec <id> <cmd…>` | Run a command, stream output, propagate exit code |
297
- | `push` / `pull <id>` | SFTP transfer, recursive, respects ignore files |
362
+ | `files ls/mkdir/mv/rm <id>` | Browse and manage instance files (SFTP, reused connection) |
363
+ | `queue add/ls/resume/cancel/resolve` | Serial transfer queue, shared with the dashboard |
298
364
  | `run <cmd…>` | Create → sync → run → fetch → power off |
299
365
  | `deploy <repo>` | Create → clone → install deps → start → **stop, keeping data** |
300
366
  | `stock [--gpu] [--region]` | Live GPU stock per region |
package/README.zh-CN.md CHANGED
@@ -43,9 +43,10 @@ autodl tui # 交互式终端里直接敲 autodl 也进
43
43
  粘贴 Token 后会先向 API 验证再保存,然后直接进看板。已经配置过的,敲 `autodl` 直接进。
44
44
 
45
45
  一张会自己刷新的实例表:状态、GPU、地区、**已开机多久、大概花了多少钱**、TTL 还剩多少。
46
- 快捷键:`↑↓` 移动、`Enter` 详情、`s` 开机、`x` 关机、`c` 复制 SSH 命令到剪贴板、`ctrl+d` 释放、
47
- `g` 看 GPU 库存、`n` 新建、`r` 刷新、`ctrl+l` 退出登录、`q` 退出。会改变或销毁东西的两个
48
- 都带 ctrl 而不是单键;按不按 shift 都认,提示也统一小写显示,免得看起来像要按 shift。
46
+ 快捷键:`↑↓` 移动、`Enter` 详情、`s` 开机、`x` 关机、`ctrl+d` 释放、`g` 库存、
47
+ `r` 刷新、`ctrl+l` 退出登录、`?` 帮助、`q` 退出。释放和退出登录需要确认。
48
+ 详情页(`Enter` 进入)里还有实例级操作:`h` 自动认证 SSH、`f` 文件管理、
49
+ `t` 传输队列、`c` 复制 SSH 命令、`n` 新建实例。
49
50
 
50
51
  `ctrl+d` 释放会永久清空实例,所以它不是单个 `d`。
51
52
 
@@ -53,6 +54,9 @@ autodl tui # 交互式终端里直接敲 autodl 也进
53
54
  或 `--token`,确认框会直说它的优先级高于接下来保存的 Token。看板开着时 Token 失效了
54
55
  (过期、被重置、实名状态变化),刷新会立刻停下,并给出一个回登录页的入口——
55
56
  而不是让你对着一张不再更新的表和刷不完的 401。
57
+ 重新登录也遵守 `--token` › `AUTODL_TOKEN` › 本地 Token 的优先级。有覆盖项时,
58
+ 保存另一个 Token 不会切换账号;覆盖项失效时需要修改或移除它并重启 TUI,不会悄悄
59
+ 改用刚保存的账号。库存查询遇到认证失败时也会结束当前会话。
56
60
 
57
61
  界面占满终端,头部显示账号 ID 与余额。`c` 只把 **SSH 命令**写进剪贴板,**不含 root 密码**
58
62
  ——剪贴板任何进程都能读。没有剪贴板工具的环境(SSH 会话、容器)会退回 OSC 52 并如实说明,
@@ -67,10 +71,61 @@ autodl tui # 交互式终端里直接敲 autodl 也进
67
71
  有两处刻意的诚实约束。单价只能从**运行中**实例的 snapshot 拿到,所以已关机的实例
68
72
  只显示时长、不显示金额——编一个看起来合理的数字比留空更糟。单价还没拉到时,
69
73
  汇总栏会明说"总额偏低",而不是安静地少报。
74
+ 账号续航会等所有运行实例的单价齐全后才给出时长,不会把未知单价当成免费。
75
+ 终端高度不足时(包括 80×24),资源和计费面板会让位给实例列表和按键提示;
76
+ 窄屏上下堆叠所占的高度也会计入判断。
70
77
 
71
78
  TUI 不会在管道、CI 或 `--json` 下启动:它会以退出码 2 退出并说明原因,
72
79
  而不是去接管一个并不存在的终端。非交互环境下裸 `autodl` 仍然和以前一样打印帮助。
73
80
 
81
+ ### SSH 和文件管理
82
+
83
+ 先 `Enter` 进详情页再按 `h`,它会临时交出整个终端,用实时实例密码建立 SSH 会话;
84
+ 退出或断线后返回看板,不是看板内嵌入终端。
85
+ 也可运行 `autodl ssh <id> --auto-auth`。自动认证模式使用 ssh2,不读取 OpenSSH 配置;
86
+ 需要 `~/.ssh/config`、agent 或 `-L` 转发时,继续使用普通 `autodl ssh <id>`。
87
+ 实现使用 Node.js 的跨平台终端和文件接口,无需安装 sshpass;支持 Linux、macOS 和原生 Windows。
88
+
89
+ 详情页按 `f` 打开本地/远端双栏,窄屏显示活动侧,`Tab` 切换。文件操作:
90
+
91
+ | 按键 | 操作 |
92
+ |---|---|
93
+ | `↑↓`、`Enter`、`←` | 选择、进入目录、返回父目录 |
94
+ | `Space` / `a` | 多选 / 全选或清空 |
95
+ | `g` / `p` | 跳转路径 / 直接输入传输来源和目标目录 |
96
+ | `u` | 把选中项传到对侧目录,确认方向后加入队列 |
97
+ | `s` / `c` | 切换单向增量同步 / 内容校验 |
98
+ | `m` / `r` / `x` | 新建目录 / 改名或同端移动 / 确认后永久删除 |
99
+ | `Q` / `Esc` | 查看队列 / 返回 |
100
+
101
+ 相对路径以对应侧当前目录为基准。每个选中来源的文件名或目录名保留在目标目录下:
102
+ 例如把本地 `project` 传到远端 `/root/work`,结果是 `/root/work/project`。
103
+ 文件管理器传输明确选中的目录内容,不套用旧 `push` 命令的忽略规则;
104
+ 符号链接及特殊文件跳过,队列详情按 `v` 可逐项查看全部跳过记录。
105
+
106
+ 普通传输遇到同名文件会暂停询问:`o` 覆盖、`s` 跳过、`b` 保留两份,
107
+ `a` 切换对本任务其余冲突应用同一选择。同步则以所选方向的来源为准:
108
+ 跳过未变化文件,整份替换变化文件,**不删除目标端独有文件**。
109
+ 默认比较大小和修改时间;可开启 SHA-256 内容校验,但需要读取两端文件内容,
110
+ 远端校验会通过 SFTP 读取数据,因此严格校验可能消耗与下载相当的带宽。
111
+
112
+ 队列按顺序执行,显示字节进度、速度和状态。可返回看板继续操作;
113
+ 在队列按 `Enter` 看详情、`c` 取消、`r` 恢复已暂停或已取消任务。
114
+ 网络中断有界重试;实例关机或认证失败会暂停,不自动开机。
115
+ 文件页打开后只建立一条浏览连接,切目录、建目录、改名、删除都复用它;
116
+ 目录内容每次实时读取,连接断了下次操作自动重连,离开文件页即释放。
117
+ CLI 的 `files` 和 `queue` 命令与看板共用同一队列记录:
118
+ `queue add` 进去的任务能在看板 `t` 里确认冲突和恢复,反之亦然。
119
+
120
+ 未完成文件写入目标目录里的 `.autodl-*.part`,完成后才替换目标,取消不会截断原文件。
121
+ 续传会验证来源版本及已传前缀;来源变化或临时文件损坏时重新传输。
122
+ 覆盖远端文件需要服务器的 OpenSSH 原子重命名扩展;不支持时保留原文件并报错。
123
+ 任务记录位于配置目录的 `transfers/`,按账号和 API 地址隔离,不保存凭证。
124
+ 退出/退出登录会暂停任务;下次进入队列后手动恢复,**退出后不后台传输**。
125
+ 同一账号队列只允许一个进程写入,崩溃遗留的所有权记录可自动回收。
126
+ 取消会保留续传文件;确定不再恢复时可删除对应任务的 `.part` 和本地续传记录。
127
+
128
+
74
129
  ## 配置
75
130
 
76
131
  官方 API 需要**已完成实名认证**(个人或企业)账号的开发者 Token。
@@ -237,6 +292,9 @@ autodl guard idle pro-xxx --threshold 5 --samples 6 --interval 1m
237
292
 
238
293
  **`--json` 模式下 stdout 是纯 JSON。** 进度、提示、警告一律走 stderr,
239
294
  所以 `autodl ... --json | jq` 永远安全。
295
+ 未知命令、未知选项和缺少参数统一返回退出码 2、`USAGE` 错误;启用 `--json` 时
296
+ 也会输出一个 JSON 错误对象。`tui --json` 同样遵守错误输出契约;显式请求帮助或
297
+ 版本号仍输出原来的文本。
240
298
 
241
299
  ```jsonc
242
300
  // 成功
@@ -271,9 +329,10 @@ autodl guard idle pro-xxx --threshold 5 --samples 6 --interval 1m
271
329
  | `info <id> [--show-password]` | 详情、实时 SSH 信息、资源占用 |
272
330
  | `create --gpu <spec>` | 创建按量计费 Pro 实例 |
273
331
  | `start` / `stop` / `rm <id>` | 开机 / 关机 / 释放 |
274
- | `ssh <id>` | 交互式登录(多余参数原样透传给 `ssh`) |
332
+ | `ssh <id> [--auto-auth]` | 系统 SSH 登录,或使用实例密码自动认证;系统模式支持额外 OpenSSH 参数 |
275
333
  | `exec <id> <cmd…>` | 远程执行,流式输出,透传退出码 |
276
- | `push` / `pull <id>` | SFTP 传输,支持递归目录与忽略规则 |
334
+ | `files ls/mkdir/mv/rm <id>` | 实例文件浏览与管理(SFTP,连接复用) |
335
+ | `queue add/ls/resume/cancel/resolve` | 串行传输队列,与看板共用同一队列 |
277
336
  | `run <cmd…>` | 建实例 → 同步 → 执行 → 回传 → 关机 |
278
337
  | `deploy <仓库>` | 建实例 → 拉代码 → 装依赖 → 启动 → **关机保留数据** |
279
338
  | `stock [--gpu] [--region]` | 各地区 GPU 实时库存 |