1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
# Tortia

`tortia` packages and runs applications in an isolated, non-virtualized execution environment.

It creates a single `.tortia` archive (7z format) that contains:
- your project files
- requested runtimes (for example Node, Rust, Python)
- optional package manager setup
- a run manifest

Then `tortia run` extracts and executes the archive with an isolated `PATH`.

## Features

- `init`, `build`, `run`, `clean` commands
- Colorful logs (`STEP`, `INFO`, `OK`, `ERROR`)
- Runtime auto-install during build
- Package manager integration and optional auto dependency install
- Host system package manager integration (`brew`, `apt`, `pacman`)
- User extensions (plugin-style event scripts)
- Runtime/command blocking via shims when not requested
- Download cache reuse for runtime installers and archives
- No VM/container runtime required

## Requirements

- macOS or Linux
- `7z`
- `curl`
- `tar`
- POSIX `sh`

Notes:
- Runtime downloads require network access at build time.
- Runtime installation support is currently implemented for macOS/Linux on `x86_64`/`aarch64`.

## Install / Build

```bash
cargo build --release
# binary: target/release/tortia
```

## CLI

```bash
tortia init [dir] [--force]
tortia build [dir] [-o|--output <path>]
tortia run <archive.tortia>
tortia clean [dir] [--temp] [--cache] [--tools] [--all] [--dry-run]
```

## Cleanup

`tortia clean` removes leftovers from failed/interrupted runs and build caches.

Examples:

```bash
# default: clean stale temp dirs (tortia-build-*, tortia-run-*)
tortia clean

# preview only
tortia clean --all --dry-run

# remove global download cache only
tortia clean --cache

# remove project-local tools dir only
tortia clean . --tools
```

Flags:
- `--temp`: remove stale temp dirs from the OS temp directory
- `--cache`: remove global Tortia cache (`TORTIA_CACHE_DIR` or default cache root)
- `--tools`: remove project-local tools directory (`<project>/.tortia-tools` by default)
- `--all`: enable `--temp`, `--cache`, and `--tools`
- `--dry-run`: print targets without deleting them

## Quick Start

```bash
# 1) Create template config
tortia init .

# 2) Edit RecipeFile

# 3) Build archive

tortia build .

# 4) Run archive
tortia run ./my-app.tortia
```

## Minimal Examples

Each example is intentionally minimal and runnable with only `tortia`.

### Node.js

`index.js`

```js
console.log("hello from node in tortia");
```

`RecipeFile`

```toml
[project]
name = "node-min"

[runtimes]
items = ["node@22.14.0"]

[package_managers]
items = ["npm"]
auto_install = false

[deps]
command = ""

[build]
command = ""

[run]
command = "node index.js"

[bundle]
include = ["index.js"]
exclude = []
```

Build and run:

```bash
tortia build .
tortia run ./node-min.tortia
```

### Python

`main.py`

```python
print("hello from python in tortia")
```

`RecipeFile`

```toml
[project]
name = "python-min"

[runtimes]
items = ["python@3.12"]

[package_managers]
items = ["pip"]
auto_install = false

[deps]
command = ""

[build]
command = ""

[run]
command = "python main.py"

[bundle]
include = ["main.py"]
exclude = []
```

Build and run:

```bash
tortia build .
tortia run ./python-min.tortia
```

### Rust

`Cargo.toml`

```toml
[package]
name = "rust-min"
version = "0.1.0"
edition = "2021"
```

`src/main.rs`

```rust
fn main() {
    println!("hello from rust in tortia");
}
```

`RecipeFile`

```toml
[project]
name = "rust-min"

[runtimes]
items = ["rust@stable"]

[package_managers]
items = ["cargo"]
auto_install = false

[deps]
command = ""

[build]
command = "cargo build --release"

[run]
command = "./target/release/rust-min"

[bundle]
include = ["Cargo.toml", "src"]
exclude = []
```

Build and run:

```bash
tortia build .
tortia run ./rust-min.tortia
```

## RecipeFile

`tortia` reads configuration from `RecipeFile` in the project root.

```toml
[project]
name = "my-app"

[runtimes]
items = ["node@22.14.0", "rust@stable", "python@3.12", "go@1.22.12", "deno@2.2.5", "bun@1.2.5"]

[package_managers]
items = ["npm", "pnpm", "pip", "uv", "cargo", "go", "deno", "bun"]
auto_install = true

[system_packages]
items = ["brew:wget"] # also supports apt:<pkg>, pacman:<pkg>
auto_install = false
use_sudo = false
update = false
missing_only = true

[extensions]
dirs = ["extensions"]
before_deps = []
after_deps = []
before_build = []
after_build = []
before_run = []
after_run = []

[deps]
command = ""

[build]
command = ""

[run]
command = "node app/index.js"

[bundle]
include = ["."]
exclude = [".git", "target"]
```

## Runtime Support

Supported runtimes in `[runtimes].items`:
- `node@<version>` (default: `22.14.0`)
- `rust@<toolchain>` (default: `stable`)
- `python@<version>` or `python`/`python@latest`
- `go@<version>` (default: `1.22.12`)
- `deno@<version>` or `deno`/`deno@latest`
- `bun@<version>` or `bun`/`bun@latest`

## Package Manager Integration

Supported package managers in `[package_managers].items`:
- `npm`, `pnpm`, `yarn`
- `pip`, `uv`
- `cargo`, `go`, `deno`, `bun`

Behavior:
- Required runtimes are auto-added if missing.
  - Example: `package_managers = ["npm"]` auto-adds Node runtime.
- `pnpm`/`yarn` are prepared via `corepack`.
- `pip` and `uv` wrappers are provided inside the isolated environment.

### Auto Dependency Install

If `auto_install = true`, `tortia build` attempts dependency install automatically:

- `npm`: `npm ci` (if `package-lock.json`), else `npm install`
- `pnpm`: `pnpm install --frozen-lockfile` (if lockfile), else `pnpm install`
- `yarn`: `yarn install --immutable || yarn install --frozen-lockfile || yarn install` (if lockfile), else `yarn install`
- `bun`: `bun install` (if `package.json`)
- `uv`: `uv sync` (if `pyproject.toml`) or `uv pip install -r requirements.txt`
- `pip`: `pip install -r requirements.txt` or `pip install .` (if `pyproject.toml`)
- `cargo`: `cargo fetch` (if `Cargo.toml`)
- `go`: `go mod download` (if `go.mod`)
- `deno`: currently only prepares runtime/manager; use explicit `[deps].command` for custom prefetch

## Host System Packages

`tortia` can optionally install host-level system packages during `build`.

Configuration:

```toml
[system_packages]
items = ["brew:cmake", "apt:libssl-dev", "pacman:openssl"]
auto_install = true
use_sudo = true
update = true
missing_only = true
```

Behavior:
- Supported managers: `brew`, `apt`, `pacman`
- Entry format: `<manager>:<package>`
- Install runs on the host (not inside archive)
- `missing_only = true` skips packages already installed
- `use_sudo = true` runs install/update commands with `sudo`

Notes:
- `apt` uses `apt-get`
- `pacman` uses non-interactive flags (`--noconfirm`)
- If a manager is not installed on the host, build fails with an explicit error

## Extensions (Plugins)

`tortia` supports user-defined extension scripts triggered at lifecycle events.

Configuration:

```toml
[extensions]
dirs = [".tortia/extensions", "extensions"]
before_deps = ["prepare-env"]
after_deps = []
before_build = ["gen-assets.sh"]
after_build = []
before_run = ["preflight"]
after_run = ["cleanup"]
```

Resolution rules:
- `dirs` are searched in order
- Script references are relative paths
- If no extension is provided in a reference, `.sh` is also tried

Events:
- `before_deps`, `after_deps`
- `before_build`, `after_build`
- `before_run`, `after_run`

Runtime behavior:
- Build events search scripts from your project root
- Run events search scripts from extracted archive contents
- Scripts execute with:
  - `TORTIA_EVENT`
  - `TORTIA_PROJECT_ROOT`
  - `TORTIA_STAGE_ROOT`

## Isolation Model

`tortia` runs hooks (`[deps]`, `[build]`) and `[run].command` in an isolated environment:

- `PATH` is rebuilt from archive-internal tool paths + system base path
- non-requested runtime commands are blocked by shim executables
- host user-level runtime paths are not used by default

This means a runtime not declared in `RecipeFile` should not be available inside `tortia run`.

## Archive Contents

A `.tortia` archive includes:
- bundled project files from `[bundle].include`
- tool directories (for installed runtimes/package managers)
- `.tortia-manifest.toml` with run metadata

## Paths and Overrides

Tool directory inside build/run payload:
- default: `.tortia-tools`
- override: set `TORTIA_TOOLS_DIR` to a relative directory name/path

Global cache directory:
- override: `TORTIA_CACHE_DIR`
- defaults:
  - Linux/macOS: `$XDG_CACHE_HOME/tortia` or `$HOME/.cache/tortia`
  - Windows: `%LOCALAPPDATA%\\tortia\\cache`
  - fallback: OS temp directory (`.../tortia-cache`)

Runtime download cache path:
- `<cache-root>/downloads`

## Troubleshooting

- `could not resolve host ...`
  - Build needs network to download runtimes/tools.
- `command ... is blocked in this isolated environment`
  - Add corresponding runtime in `[runtimes].items`.
- Large archive size
  - Python (Miniconda) can significantly increase archive size.
- Slow repeated builds
  - Tortia now reuses runtime download cache in `<cache-root>/downloads`.
  - Use `tortia clean --cache` to fully reset cached downloads.

## Security Note

`[deps].command`, `[build].command`, and `[run].command` execute shell commands. Treat `RecipeFile` as code.