Phase 2: hosted profile (P2-8a)

- src/interp/host.zig: real console, files (scope checked before any
  host call, positional reads/writes, append from file size) and TCP
  through std.Io; monotonic clock and host CSPRNG; host errors mapped
  to the closed io_error set; open handles released at the end of the
  instance
- interpreter dispatches intrinsics to the host or the deterministic
  world; never reports blocked in the hosted profile
- CLI: --profile hosted; the program owns stdout/stderr, the run record
  goes to --result-file, otherwise a human summary on stderr
- spec 11 §8.0: host error mapping table
- tests/hosted/smoke.py (file copy, scope denial, stdin->stdout, TCP
  echo on a free port) runs in CI
- works around Zig 0.17 net.Stream.read not compiling by using
  readWithControl
This commit is contained in:
dev committed 2026-10-04 14:46:40 +03:00
1 parent 008654999e
commit 36e91be84c
10 files changed
+530 -51

No files matched your search

+19
View File
@@ -138,6 +138,25 @@ environment outcome: not_instantiated, limit_exceeded, blocked
**Result channel.** In the `hosted` profile the program owns stdout and stderr, so the run record cannot share them unambiguously. The machine-readable record goes to a separate channel: `aji run --profile hosted --result-file PATH` (a `--result-fd N` form may follow; `ajid` has its own control channel). Without `--result-file` the CLI may print a human-readable summary on stderr after the program ends; that summary is not a machine interface.
### 8.0 Host errors in the hosted profile
The `hosted` profile maps host failures to `io_error` (spec 06 §7) as follows; anything not listed is `other`, and no host error number is observable by the program:
| Host condition | `io_error` |
|---|---|
| file or path component not found, not a directory | `not_found` |
| access or permission denied, read-only file system | `permission_denied` |
| path already exists (exclusive creation) | `already_exists` |
| bad or too long path name, path is a directory | `invalid_input` |
| no space left, disk quota exceeded | `no_space` |
| broken pipe | `broken_pipe` |
| connection refused | `connection_refused` |
| connection reset by peer | `connection_reset` |
| address in use | `address_in_use` |
| address not available | `address_unavailable` |
Paths outside a capability's scope and malformed paths or addresses are rejected before any host call (`permission_denied`, `invalid_input`), exactly as in the `deterministic` profile. Host handles still open when the execution instance ends are released by the runtime; this is not observable by the program (spec 06 §6, invariant 2).
### 8.1 Deterministic random generator
The `deterministic` profile uses xoshiro256\*\* with SplitMix64 seeding. All arithmetic is on unsigned 64-bit integers, wrapping modulo 2^64; `rotl(x, k)` is `(x << k) | (x >> (64 − k))`.