contree-cli 0.2.3__tar.gz

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 (34) hide show
  1. contree_cli-0.2.3/PKG-INFO +323 -0
  2. contree_cli-0.2.3/README.md +311 -0
  3. contree_cli-0.2.3/contree_cli/__init__.py +27 -0
  4. contree_cli-0.2.3/contree_cli/__main__.py +62 -0
  5. contree_cli-0.2.3/contree_cli/arguments.py +141 -0
  6. contree_cli-0.2.3/contree_cli/cli/__init__.py +0 -0
  7. contree_cli-0.2.3/contree_cli/cli/auth.py +124 -0
  8. contree_cli-0.2.3/contree_cli/cli/cat.py +74 -0
  9. contree_cli-0.2.3/contree_cli/cli/cd.py +49 -0
  10. contree_cli-0.2.3/contree_cli/cli/cp.py +107 -0
  11. contree_cli-0.2.3/contree_cli/cli/file.py +179 -0
  12. contree_cli-0.2.3/contree_cli/cli/images.py +88 -0
  13. contree_cli-0.2.3/contree_cli/cli/kill.py +86 -0
  14. contree_cli-0.2.3/contree_cli/cli/ls.py +83 -0
  15. contree_cli-0.2.3/contree_cli/cli/ps.py +120 -0
  16. contree_cli-0.2.3/contree_cli/cli/run.py +438 -0
  17. contree_cli-0.2.3/contree_cli/cli/session.py +282 -0
  18. contree_cli-0.2.3/contree_cli/cli/show.py +97 -0
  19. contree_cli-0.2.3/contree_cli/cli/tag.py +50 -0
  20. contree_cli-0.2.3/contree_cli/cli/use.py +119 -0
  21. contree_cli-0.2.3/contree_cli/client.py +222 -0
  22. contree_cli-0.2.3/contree_cli/config.py +116 -0
  23. contree_cli-0.2.3/contree_cli/log.py +40 -0
  24. contree_cli-0.2.3/contree_cli/mapped_file.py +112 -0
  25. contree_cli-0.2.3/contree_cli/output.py +376 -0
  26. contree_cli-0.2.3/contree_cli/session.py +761 -0
  27. contree_cli-0.2.3/contree_cli/shell/__init__.py +59 -0
  28. contree_cli-0.2.3/contree_cli/shell/completer.py +465 -0
  29. contree_cli-0.2.3/contree_cli/shell/history.py +53 -0
  30. contree_cli-0.2.3/contree_cli/shell/parser.py +107 -0
  31. contree_cli-0.2.3/contree_cli/shell/repl.py +486 -0
  32. contree_cli-0.2.3/contree_cli/shell/trie.py +113 -0
  33. contree_cli-0.2.3/contree_cli/types.py +87 -0
  34. contree_cli-0.2.3/pyproject.toml +52 -0
@@ -0,0 +1,323 @@
1
+ Metadata-Version: 2.3
2
+ Name: contree-cli
3
+ Version: 0.2.3
4
+ Summary: ConTree simple CLI
5
+ Requires-Python: >=3.10
6
+ Project-URL: Homepage, https://contree.dev
7
+ Project-URL: Documentation, https://docs.contree.dev/cli/
8
+ Project-URL: Repository, https://github.com/nebius/contree-cli
9
+ Project-URL: Issues, https://github.com/nebius/contree-cli/issues
10
+ Project-URL: Changelog, https://github.com/nebius/contree-cli/releases
11
+ Description-Content-Type: text/markdown
12
+
13
+ # contree-cli
14
+
15
+ [![Python 3.10+](https://img.shields.io/badge/python-3.10%2B-blue.svg)](https://www.python.org/downloads/)
16
+ [![Zero Dependencies](https://img.shields.io/badge/dependencies-0-brightgreen.svg)](#zero-dependencies)
17
+ [![PyPI](https://img.shields.io/pypi/v/contree-cli.svg)](https://pypi.org/project/contree-cli/)
18
+
19
+ Command-line client for the [ConTree](https://contree.dev) sandboxing platform — secure, VM-isolated sandboxes with git-like branching for AI agents and developers.
20
+
21
+ ```bash
22
+ eval $(contree use tag:ubuntu:latest) # pick a base image for current session
23
+ contree run apt-get update -qq # each run snapshots the result
24
+ contree run apt-get install -y curl # builds on the previous snapshot
25
+ contree session branch experiment # branch the sandbox state
26
+ contree run -- make test # experiment freely
27
+ contree session checkout main # switch back instantly
28
+ contree session rollback 2 # or rewind two steps
29
+ ```
30
+
31
+ ## What is ConTree?
32
+
33
+ [ConTree](https://contree.dev) is a secure sandbox API that runs every command inside a VM-isolated instance and snapshots the full filesystem after each execution. These snapshots (called **images**) form a tree — branch from any checkpoint, explore paths in parallel, and roll back on failure.
34
+
35
+ **Built for AI agents that think ahead:**
36
+
37
+ - **Tree-search execution** — branch sandbox state so an agent can explore multiple solution paths in parallel and keep the best one
38
+ - **Instant rollback** — backtrack to any previous checkpoint without rebuilding from scratch
39
+ - **Safe code execution** — run untrusted or LLM-generated code inside VM-level isolation; crashes and side effects stay in the sandbox
40
+ - **Session continuity** — rewind and resume long-running agent workflows with full filesystem context preserved
41
+
42
+ `contree-cli` talks to the ConTree API. Install it, authenticate with your project token, and create sandboxes, run commands, inspect filesystems, and manage sessions — all from your terminal, shell scripts, or agent toolchains.
43
+
44
+ ## Install
45
+
46
+ ```bash
47
+ pip install contree-cli
48
+ ```
49
+
50
+ Or with [uv](https://docs.astral.sh/uv/):
51
+
52
+ ```bash
53
+ uv tool install contree-cli
54
+ ```
55
+
56
+ <details>
57
+ <summary>More options (pipx, from source)</summary>
58
+
59
+ ```bash
60
+ # pipx
61
+ pipx install contree-cli
62
+
63
+ # From source
64
+ git clone https://github.com/nebius/contree-cli.git
65
+ cd contree-cli
66
+ pip install .
67
+ ```
68
+
69
+ </details>
70
+
71
+ Verify:
72
+
73
+ ```bash
74
+ contree --help
75
+ ```
76
+
77
+ **Requirements:** Python 3.10+ and nothing else. Zero external dependencies — stdlib only.
78
+
79
+ ## Quick Start
80
+
81
+ ### 1. Authenticate
82
+
83
+ ```bash
84
+ contree auth
85
+ ```
86
+
87
+ You'll be prompted to enter your API token securely. The CLI verifies it and saves it to `~/.config/contree-cli/config.ini`.
88
+
89
+ ### 2. Start a session
90
+
91
+ ```bash
92
+ eval $(contree use tag:ubuntu:latest)
93
+ ```
94
+
95
+ This picks a base image and creates a session. The `eval` wrapper exports the session variable so subsequent commands share the same state.
96
+
97
+ ### 3. Run commands
98
+
99
+ ```bash
100
+ contree run uname -a # direct execution
101
+ contree run apt-get install -y curl # installs persist to next run
102
+ contree run -s -- 'echo $PATH' # shell mode for expansions
103
+ ```
104
+
105
+ Each non-disposable `run` produces a new image — a full filesystem checkpoint.
106
+
107
+ ### 4. Inspect without spawning
108
+
109
+ ```bash
110
+ contree ls /usr/bin # list files (no VM needed)
111
+ contree cat /etc/os-release # read files (no VM needed)
112
+ contree cp /app/output.log . # download to local machine
113
+ ```
114
+
115
+ ### 5. Branch and roll back
116
+
117
+ ```bash
118
+ contree session branch experiment # create a branch
119
+ contree run -- make test # experiment on it
120
+ contree session checkout main # switch back
121
+ contree session rollback 1 # undo last run
122
+ ```
123
+
124
+ ## Interactive Shell
125
+
126
+ `contree shell` starts a REPL where bare commands run in the sandbox automatically:
127
+
128
+ ```
129
+ $ contree shell
130
+ contree:/> apt-get update -qq
131
+ ...
132
+ contree:/> apt-get install -y curl
133
+ ...
134
+ contree:/> curl -sI https://example.com
135
+ HTTP/2 200
136
+ ...
137
+ contree:/> cd /etc
138
+ contree:/etc> cat os-release
139
+ PRETTY_NAME="Ubuntu 24.04 LTS"
140
+ ...
141
+ contree:/etc> contree session branch experiment
142
+ Created branch 'experiment'
143
+ contree:/etc> exit
144
+ ```
145
+
146
+ The shell provides tab completion for commands, paths, image tags, and operation IDs. `ls` and `cat` map to the fast API inspection commands by default. `vim`/`vi`/`nano` open `contree file edit` with your local `$EDITOR`.
147
+
148
+ ## Commands
149
+
150
+ | Command | Aliases | Description |
151
+ |---|---|---|
152
+ | `use IMAGE` | `ci` | Set or show current session image |
153
+ | `run [-- CMD]` | | Spawn a sandbox instance, execute command |
154
+ | `images [--prefix]` | `img` | List available images |
155
+ | `tag UUID TAG` | | Tag or untag an image |
156
+ | `ps` | | List operations (instances, imports) |
157
+ | `kill UUID` | | Cancel an operation (`--all` for all) |
158
+ | `show UUID` | | Show operation result |
159
+ | `ls [PATH]` | | List files in session image (no VM) |
160
+ | `cat PATH` | | Show file content from session image (no VM) |
161
+ | `cp PATH DEST` | | Download file from image to local path |
162
+ | `file edit PATH` | `e` | Edit remote file via local `$EDITOR` |
163
+ | `file cp SRC DEST` | | Upload local file into session image |
164
+ | `cd [PATH]` | | Change working directory in session |
165
+ | `session` | `s` | Show current session info |
166
+ | `session list` | `ls` | List all sessions |
167
+ | `session branch` | `br` | Create or list branches |
168
+ | `session checkout` | `co` | Switch active branch |
169
+ | `session rollback [N]` | `rb` | Revert N steps in history |
170
+ | `session show` | | Display session history DAG |
171
+ | `auth` | | Configure authentication (secure prompt) |
172
+ | `auth profiles` | | List saved profiles |
173
+ | `auth switch NAME` | | Switch active profile |
174
+ | `shell` | | Start interactive REPL |
175
+
176
+ See the full [command reference](https://docs.contree.dev/cli/commands/) for all flags and options.
177
+
178
+ ## Execution Modes
179
+
180
+ The `run` command supports four execution modes:
181
+
182
+ ```bash
183
+ # Direct — arguments are the command
184
+ contree run uname -a
185
+
186
+ # Shell — arguments joined, passed to sh -c
187
+ contree run -s -- 'echo $HOME && ls /'
188
+
189
+ # Interpreter — local script executed remotely
190
+ contree run -I ./deploy.sh
191
+
192
+ # Piped stdin — stdin forwarded to the command
193
+ echo 'SELECT 1' | contree run -- psql
194
+ ```
195
+
196
+ ### File injection
197
+
198
+ Mount local files into the sandbox:
199
+
200
+ ```bash
201
+ contree run --file ./app.py:/app/app.py -- python /app/app.py
202
+ contree run --file ./config.yaml --file ./data.csv -- ./process.sh
203
+ ```
204
+
205
+ File specs support permissions: `host_path[:remote_path][:uUID][:gGID][:mMODE]`
206
+
207
+ ### Shebang scripts
208
+
209
+ ```bash
210
+ #!/usr/bin/env -S contree run -I
211
+ apt-get update -qq
212
+ apt-get install -y curl
213
+ curl https://example.com
214
+ ```
215
+
216
+ Save as `setup.sh`, `chmod +x`, and run it directly.
217
+
218
+ ## Sessions and Branching
219
+
220
+ Sessions track your sandbox state with git-like branching and history:
221
+
222
+ ```
223
+ main: A ── B ── C ── D
224
+ \
225
+ experiment: E ── F
226
+ ```
227
+
228
+ Every `run` creates a checkpoint. Branch to explore alternatives. Roll back to any point. Switch branches instantly.
229
+
230
+ ```bash
231
+ contree session # show current state
232
+ contree session show # display history DAG
233
+ contree session branch feature # create branch from HEAD
234
+ contree session checkout feature # switch to it
235
+ contree session rollback 3 # go back 3 steps
236
+ contree session use other-session # import image from another session
237
+ ```
238
+
239
+ ## Output Formats
240
+
241
+ All commands support structured output via `-f`/`--format`:
242
+
243
+ ```bash
244
+ contree images -f json # JSON (one object per line)
245
+ contree images -f json-pretty # pretty-printed JSON array
246
+ contree ps -f csv # RFC 4180 CSV
247
+ contree ps -f tsv # tab-separated values
248
+ contree ls -f table # ASCII table
249
+ ```
250
+
251
+ Pipe JSON output into `jq`, feed CSV into spreadsheets, or parse programmatically in your agent toolchain.
252
+
253
+ ## Configuration
254
+
255
+ ### Config file
256
+
257
+ `~/.config/contree-cli/config.ini`:
258
+
259
+ ```ini
260
+ [DEFAULT]
261
+ profile = default
262
+
263
+ [profile:default]
264
+ token = eyJ...
265
+ url = https://contree.dev
266
+ ```
267
+
268
+ ### Multiple profiles
269
+
270
+ ```bash
271
+ contree auth --profile=staging # save staging token
272
+ contree auth --profile=prod # save production token
273
+ contree auth profiles # list all profiles
274
+ contree auth switch staging # switch active profile
275
+ ```
276
+
277
+ ### Environment variables
278
+
279
+ | Variable | Purpose |
280
+ |---|---|
281
+ | `CONTREE_TOKEN` | API bearer token (overrides config) |
282
+ | `CONTREE_URL` | API base URL (overrides config) |
283
+ | `CONTREE_PROFILE` | Active profile name |
284
+ | `CONTREE_SESSION` | Explicit session key (for multi-terminal workflows) |
285
+ | `CONTREE_SESSION_DB` | Path to session SQLite database |
286
+
287
+ Environment variables take precedence over the config file. `--token` and `--url` flags override everything.
288
+
289
+ ## Zero Dependencies
290
+
291
+ `contree-cli` uses only the Python standard library. No `requests`, no `click`, no `rich` — just `http.client`, `argparse`, `json`, `sqlite3`, and friends. It runs anywhere Python 3.10+ is available with nothing to install beyond the package itself.
292
+
293
+ ## Development
294
+
295
+ ```bash
296
+ git clone https://github.com/nebius/contree-cli.git
297
+ cd contree-cli
298
+ uv sync --group dev
299
+ ```
300
+
301
+ ```bash
302
+ make lint # ruff check --fix
303
+ make types # mypy strict mode
304
+ make check # lint + types
305
+ make tests # lint + types + pytest
306
+ ```
307
+
308
+ The project enforces strict mypy, ruff linting (E/F/W/I/UP/B/SIM/RUF rules), and full test coverage across 23+ test modules.
309
+
310
+ ## Documentation
311
+
312
+ Full documentation is available at **[docs.contree.dev/cli](https://docs.contree.dev/cli/)**, including:
313
+
314
+ - [Tutorial](https://docs.contree.dev/cli/tutorial/) — step-by-step from installation to automation
315
+ - [Command Reference](https://docs.contree.dev/cli/commands/) — every command, flag, and subcommand
316
+
317
+ ## Links
318
+
319
+ - [ConTree Platform](https://contree.dev)
320
+ - [Documentation](https://docs.contree.dev/cli/)
321
+ - [PyPI](https://pypi.org/project/contree-cli/)
322
+ - [Issues](https://github.com/nebius/contree-cli/issues)
323
+ - [Releases](https://github.com/nebius/contree-cli/releases)
@@ -0,0 +1,311 @@
1
+ # contree-cli
2
+
3
+ [![Python 3.10+](https://img.shields.io/badge/python-3.10%2B-blue.svg)](https://www.python.org/downloads/)
4
+ [![Zero Dependencies](https://img.shields.io/badge/dependencies-0-brightgreen.svg)](#zero-dependencies)
5
+ [![PyPI](https://img.shields.io/pypi/v/contree-cli.svg)](https://pypi.org/project/contree-cli/)
6
+
7
+ Command-line client for the [ConTree](https://contree.dev) sandboxing platform — secure, VM-isolated sandboxes with git-like branching for AI agents and developers.
8
+
9
+ ```bash
10
+ eval $(contree use tag:ubuntu:latest) # pick a base image for current session
11
+ contree run apt-get update -qq # each run snapshots the result
12
+ contree run apt-get install -y curl # builds on the previous snapshot
13
+ contree session branch experiment # branch the sandbox state
14
+ contree run -- make test # experiment freely
15
+ contree session checkout main # switch back instantly
16
+ contree session rollback 2 # or rewind two steps
17
+ ```
18
+
19
+ ## What is ConTree?
20
+
21
+ [ConTree](https://contree.dev) is a secure sandbox API that runs every command inside a VM-isolated instance and snapshots the full filesystem after each execution. These snapshots (called **images**) form a tree — branch from any checkpoint, explore paths in parallel, and roll back on failure.
22
+
23
+ **Built for AI agents that think ahead:**
24
+
25
+ - **Tree-search execution** — branch sandbox state so an agent can explore multiple solution paths in parallel and keep the best one
26
+ - **Instant rollback** — backtrack to any previous checkpoint without rebuilding from scratch
27
+ - **Safe code execution** — run untrusted or LLM-generated code inside VM-level isolation; crashes and side effects stay in the sandbox
28
+ - **Session continuity** — rewind and resume long-running agent workflows with full filesystem context preserved
29
+
30
+ `contree-cli` talks to the ConTree API. Install it, authenticate with your project token, and create sandboxes, run commands, inspect filesystems, and manage sessions — all from your terminal, shell scripts, or agent toolchains.
31
+
32
+ ## Install
33
+
34
+ ```bash
35
+ pip install contree-cli
36
+ ```
37
+
38
+ Or with [uv](https://docs.astral.sh/uv/):
39
+
40
+ ```bash
41
+ uv tool install contree-cli
42
+ ```
43
+
44
+ <details>
45
+ <summary>More options (pipx, from source)</summary>
46
+
47
+ ```bash
48
+ # pipx
49
+ pipx install contree-cli
50
+
51
+ # From source
52
+ git clone https://github.com/nebius/contree-cli.git
53
+ cd contree-cli
54
+ pip install .
55
+ ```
56
+
57
+ </details>
58
+
59
+ Verify:
60
+
61
+ ```bash
62
+ contree --help
63
+ ```
64
+
65
+ **Requirements:** Python 3.10+ and nothing else. Zero external dependencies — stdlib only.
66
+
67
+ ## Quick Start
68
+
69
+ ### 1. Authenticate
70
+
71
+ ```bash
72
+ contree auth
73
+ ```
74
+
75
+ You'll be prompted to enter your API token securely. The CLI verifies it and saves it to `~/.config/contree-cli/config.ini`.
76
+
77
+ ### 2. Start a session
78
+
79
+ ```bash
80
+ eval $(contree use tag:ubuntu:latest)
81
+ ```
82
+
83
+ This picks a base image and creates a session. The `eval` wrapper exports the session variable so subsequent commands share the same state.
84
+
85
+ ### 3. Run commands
86
+
87
+ ```bash
88
+ contree run uname -a # direct execution
89
+ contree run apt-get install -y curl # installs persist to next run
90
+ contree run -s -- 'echo $PATH' # shell mode for expansions
91
+ ```
92
+
93
+ Each non-disposable `run` produces a new image — a full filesystem checkpoint.
94
+
95
+ ### 4. Inspect without spawning
96
+
97
+ ```bash
98
+ contree ls /usr/bin # list files (no VM needed)
99
+ contree cat /etc/os-release # read files (no VM needed)
100
+ contree cp /app/output.log . # download to local machine
101
+ ```
102
+
103
+ ### 5. Branch and roll back
104
+
105
+ ```bash
106
+ contree session branch experiment # create a branch
107
+ contree run -- make test # experiment on it
108
+ contree session checkout main # switch back
109
+ contree session rollback 1 # undo last run
110
+ ```
111
+
112
+ ## Interactive Shell
113
+
114
+ `contree shell` starts a REPL where bare commands run in the sandbox automatically:
115
+
116
+ ```
117
+ $ contree shell
118
+ contree:/> apt-get update -qq
119
+ ...
120
+ contree:/> apt-get install -y curl
121
+ ...
122
+ contree:/> curl -sI https://example.com
123
+ HTTP/2 200
124
+ ...
125
+ contree:/> cd /etc
126
+ contree:/etc> cat os-release
127
+ PRETTY_NAME="Ubuntu 24.04 LTS"
128
+ ...
129
+ contree:/etc> contree session branch experiment
130
+ Created branch 'experiment'
131
+ contree:/etc> exit
132
+ ```
133
+
134
+ The shell provides tab completion for commands, paths, image tags, and operation IDs. `ls` and `cat` map to the fast API inspection commands by default. `vim`/`vi`/`nano` open `contree file edit` with your local `$EDITOR`.
135
+
136
+ ## Commands
137
+
138
+ | Command | Aliases | Description |
139
+ |---|---|---|
140
+ | `use IMAGE` | `ci` | Set or show current session image |
141
+ | `run [-- CMD]` | | Spawn a sandbox instance, execute command |
142
+ | `images [--prefix]` | `img` | List available images |
143
+ | `tag UUID TAG` | | Tag or untag an image |
144
+ | `ps` | | List operations (instances, imports) |
145
+ | `kill UUID` | | Cancel an operation (`--all` for all) |
146
+ | `show UUID` | | Show operation result |
147
+ | `ls [PATH]` | | List files in session image (no VM) |
148
+ | `cat PATH` | | Show file content from session image (no VM) |
149
+ | `cp PATH DEST` | | Download file from image to local path |
150
+ | `file edit PATH` | `e` | Edit remote file via local `$EDITOR` |
151
+ | `file cp SRC DEST` | | Upload local file into session image |
152
+ | `cd [PATH]` | | Change working directory in session |
153
+ | `session` | `s` | Show current session info |
154
+ | `session list` | `ls` | List all sessions |
155
+ | `session branch` | `br` | Create or list branches |
156
+ | `session checkout` | `co` | Switch active branch |
157
+ | `session rollback [N]` | `rb` | Revert N steps in history |
158
+ | `session show` | | Display session history DAG |
159
+ | `auth` | | Configure authentication (secure prompt) |
160
+ | `auth profiles` | | List saved profiles |
161
+ | `auth switch NAME` | | Switch active profile |
162
+ | `shell` | | Start interactive REPL |
163
+
164
+ See the full [command reference](https://docs.contree.dev/cli/commands/) for all flags and options.
165
+
166
+ ## Execution Modes
167
+
168
+ The `run` command supports four execution modes:
169
+
170
+ ```bash
171
+ # Direct — arguments are the command
172
+ contree run uname -a
173
+
174
+ # Shell — arguments joined, passed to sh -c
175
+ contree run -s -- 'echo $HOME && ls /'
176
+
177
+ # Interpreter — local script executed remotely
178
+ contree run -I ./deploy.sh
179
+
180
+ # Piped stdin — stdin forwarded to the command
181
+ echo 'SELECT 1' | contree run -- psql
182
+ ```
183
+
184
+ ### File injection
185
+
186
+ Mount local files into the sandbox:
187
+
188
+ ```bash
189
+ contree run --file ./app.py:/app/app.py -- python /app/app.py
190
+ contree run --file ./config.yaml --file ./data.csv -- ./process.sh
191
+ ```
192
+
193
+ File specs support permissions: `host_path[:remote_path][:uUID][:gGID][:mMODE]`
194
+
195
+ ### Shebang scripts
196
+
197
+ ```bash
198
+ #!/usr/bin/env -S contree run -I
199
+ apt-get update -qq
200
+ apt-get install -y curl
201
+ curl https://example.com
202
+ ```
203
+
204
+ Save as `setup.sh`, `chmod +x`, and run it directly.
205
+
206
+ ## Sessions and Branching
207
+
208
+ Sessions track your sandbox state with git-like branching and history:
209
+
210
+ ```
211
+ main: A ── B ── C ── D
212
+ \
213
+ experiment: E ── F
214
+ ```
215
+
216
+ Every `run` creates a checkpoint. Branch to explore alternatives. Roll back to any point. Switch branches instantly.
217
+
218
+ ```bash
219
+ contree session # show current state
220
+ contree session show # display history DAG
221
+ contree session branch feature # create branch from HEAD
222
+ contree session checkout feature # switch to it
223
+ contree session rollback 3 # go back 3 steps
224
+ contree session use other-session # import image from another session
225
+ ```
226
+
227
+ ## Output Formats
228
+
229
+ All commands support structured output via `-f`/`--format`:
230
+
231
+ ```bash
232
+ contree images -f json # JSON (one object per line)
233
+ contree images -f json-pretty # pretty-printed JSON array
234
+ contree ps -f csv # RFC 4180 CSV
235
+ contree ps -f tsv # tab-separated values
236
+ contree ls -f table # ASCII table
237
+ ```
238
+
239
+ Pipe JSON output into `jq`, feed CSV into spreadsheets, or parse programmatically in your agent toolchain.
240
+
241
+ ## Configuration
242
+
243
+ ### Config file
244
+
245
+ `~/.config/contree-cli/config.ini`:
246
+
247
+ ```ini
248
+ [DEFAULT]
249
+ profile = default
250
+
251
+ [profile:default]
252
+ token = eyJ...
253
+ url = https://contree.dev
254
+ ```
255
+
256
+ ### Multiple profiles
257
+
258
+ ```bash
259
+ contree auth --profile=staging # save staging token
260
+ contree auth --profile=prod # save production token
261
+ contree auth profiles # list all profiles
262
+ contree auth switch staging # switch active profile
263
+ ```
264
+
265
+ ### Environment variables
266
+
267
+ | Variable | Purpose |
268
+ |---|---|
269
+ | `CONTREE_TOKEN` | API bearer token (overrides config) |
270
+ | `CONTREE_URL` | API base URL (overrides config) |
271
+ | `CONTREE_PROFILE` | Active profile name |
272
+ | `CONTREE_SESSION` | Explicit session key (for multi-terminal workflows) |
273
+ | `CONTREE_SESSION_DB` | Path to session SQLite database |
274
+
275
+ Environment variables take precedence over the config file. `--token` and `--url` flags override everything.
276
+
277
+ ## Zero Dependencies
278
+
279
+ `contree-cli` uses only the Python standard library. No `requests`, no `click`, no `rich` — just `http.client`, `argparse`, `json`, `sqlite3`, and friends. It runs anywhere Python 3.10+ is available with nothing to install beyond the package itself.
280
+
281
+ ## Development
282
+
283
+ ```bash
284
+ git clone https://github.com/nebius/contree-cli.git
285
+ cd contree-cli
286
+ uv sync --group dev
287
+ ```
288
+
289
+ ```bash
290
+ make lint # ruff check --fix
291
+ make types # mypy strict mode
292
+ make check # lint + types
293
+ make tests # lint + types + pytest
294
+ ```
295
+
296
+ The project enforces strict mypy, ruff linting (E/F/W/I/UP/B/SIM/RUF rules), and full test coverage across 23+ test modules.
297
+
298
+ ## Documentation
299
+
300
+ Full documentation is available at **[docs.contree.dev/cli](https://docs.contree.dev/cli/)**, including:
301
+
302
+ - [Tutorial](https://docs.contree.dev/cli/tutorial/) — step-by-step from installation to automation
303
+ - [Command Reference](https://docs.contree.dev/cli/commands/) — every command, flag, and subcommand
304
+
305
+ ## Links
306
+
307
+ - [ConTree Platform](https://contree.dev)
308
+ - [Documentation](https://docs.contree.dev/cli/)
309
+ - [PyPI](https://pypi.org/project/contree-cli/)
310
+ - [Issues](https://github.com/nebius/contree-cli/issues)
311
+ - [Releases](https://github.com/nebius/contree-cli/releases)
@@ -0,0 +1,27 @@
1
+ from __future__ import annotations
2
+
3
+ import argparse
4
+ from collections.abc import Callable
5
+ from contextvars import ContextVar
6
+ from typing import TYPE_CHECKING, Protocol
7
+
8
+ if TYPE_CHECKING:
9
+ from contree_cli.client import ContreeClient
10
+ from contree_cli.config import ConfigProfile
11
+ from contree_cli.output import OutputFormatter
12
+ from contree_cli.session import SessionStore
13
+
14
+ PROFILE: ContextVar[ConfigProfile] = ContextVar("PROFILE")
15
+ CLIENT: ContextVar[ContreeClient] = ContextVar("CLIENT")
16
+ FORMATTER: ContextVar[OutputFormatter] = ContextVar("FORMATTER")
17
+ SESSION_STORE: ContextVar[SessionStore] = ContextVar("SESSION_STORE")
18
+ IN_SHELL: ContextVar[bool] = ContextVar("IN_SHELL", default=False)
19
+
20
+
21
+ class ArgumentsProtocol(Protocol):
22
+ @classmethod
23
+ def from_args(cls, ns: argparse.Namespace) -> ArgumentsProtocol: ...
24
+
25
+
26
+ Handler = Callable[..., int | None]
27
+ SetupResult = tuple[Handler, type[ArgumentsProtocol]]