cli: add caller-buffer lexical path APIs

Add pure std.path queries and failure-preserving normalization/join using
safe reverse measurement/emission and caller-provided output storage.
Component queries return explicit Copy ranges; filesystem authority is
checked independently. Complete the STD-7 implementation gate.

Validation: 1079 conformance cases, 18 path cases with per-step collection
and 12-seed schedule stress, independent 132-path/49-join capacity oracle,
68 CLI checks, fourteen previous source/std CLI suites, unit/Quick Reference,
formatting, hosted smoke, 117/117 source coverage and reference budgets.
This commit is contained in:
dev committed 2026-10-07 13:41:45 +03:00
1 parent 8d8bef8f3e
commit 8edec5b831
35 files changed
+1189 -8

No files matched your search

+23
View File
@@ -425,3 +425,26 @@ Any failed external write preserves pending bytes/used and records its first io_
The visible representations are Reader{file,storage,begin,end}, 0≤begin≤end≤N, and Writer{file,storage,used,failed}, 0≤used≤N. Both buffers have initialized length=capacity=N. Caller field access/construction must preserve spec 16 §2.18's complete data/cursor/first-error invariant and must not independently consume/use the internal file/storage. Existing ownership, alias/task-loan, effects and Send/Share checks apply. Adapters can transfer to workers but cannot be shared immutably across tasks because files are non-Share. No unsafe/trusted boundary or new runtime/verifier state is needed.
The [copy example](../../examples/std/buffered_io.aji) uses two three-byte buffers (heap=mem.alloc:6), explicitly handles constructor/finish failure and returns the copied byte count, or zero after normal error cleanup. Conformance fixtures include capacities zero/full, unread finish/discard, exact EOF, allocation failure/refunds, worker transfer and rejected ownership/effect/alias cases. Hosted tests exercise read errors and real partial external writes; Linux raises the child file quota after failure to detect forbidden retry.
## Lexical paths
Import `std.path`. Six pure operations use byte `/` separators in every profile. They never allocate heap, retain/return a borrow, inspect the filesystem/current directory or grant authority. Backslash, colon and non-UTF-8 bytes are ordinary component bytes; there is no drive/UNC or symlink resolution. Range{start:usize,end:usize} is Copy; callers explicitly borrow ref path[range.start..range.end]. A range is data, and bounds are still checked if it is reused for a different path.
| Function arguments | Result |
|---|---|
| is_absolute(path: slice<u8>) | bool: first byte is `/` |
| basename(path: slice<u8>) | Range of final nonempty raw component, ignoring trailing separators; 0..0 for empty/root-only |
| parent(path: slice<u8>) | Range of raw prefix before basename, trimming the separator run before it; rooted input retains first `/`; 0..0 for empty/relative leaf |
| extension(path: slice<u8>) | Range after basename's last dot, excluding dot; empty at basename.end for absent/leading-only/trailing dot or `.`/`..` |
| normalize(destination: slice_mut<u8>, path: slice<u8>) | WriteResult: ok(usize), invalid_input, size_overflow, short_output |
| join(destination: slice_mut<u8>, base: slice<u8>, child: slice<u8>) | WriteResult |
Queries accept arbitrary bytes, including NUL, and return offsets into the original input, without normalizing it. For a//b///, basename selects b and parent selects a; parent(a/../b) selects `a/..`. Root-only parent selects the first slash; root-only basename is empty. Extension(.profile) is empty, extension(.profile.json) selects json, extension(a..b) selects b, extension(a.) is empty. Empty extension deliberately makes no distinction between no dot and empty suffix.
Normalize collapses separator runs and leading slashes, removes `.` and trailing slashes, and cancels each ordinary component followed by `..`. Relative unmatched parents remain leading `..`; parents above root are dropped. Empty/reduced-empty relative input becomes `.`; empty rooted output becomes `/`. Examples: a//b/../c/ → a/c; a/../../b → ../b; /../../a → /a; a/.. → . . Normalization is idempotent. Exactly two leading slashes have no special meaning.
Join normalizes absolute child alone, replacing base. Otherwise it normalizes base followed by child as components separated by a slash; an empty base does not introduce a root. Empty child normalizes base, both empty become `.`, and child parents can cancel base components. Examples: /data/a + ../b → /data/b; a + /b → /b; empty + a → a. These transformations give no capability-containment proof. Filesystem primitives still reject normalized relative paths and enforce their granted scopes on absolute ones.
Both writers first validate all input bytes: NUL yields invalid_input, including in base when an absolute child replaces it. Invalid input precedes size_overflow, which precedes short_output. Every returned error leaves the entire destination unchanged. Success writes exactly the reported prefix, preserves the suffix and writes no NUL terminator. Only final normalized size must fit: a long component followed by `..` can normalize into one byte of output. Reverse measurement/emission needs fixed frame state and no intermediate buffer or allocation. Work is linear in supplied input/output bytes.
Input borrows can overlap each other; destination must be disjoint. Explicit split_at permits source/output in one allocation. Existing type/borrow/task-loan/Send/Share checks apply, including no-op/short-output paths. No unsafe boundary, new language/AIR semantics or hidden effects are needed. Borrow-return source support (Q-034) remains separate. The [pure example](../../examples/std/path.aji) joins into a caller buffer and borrows basename/parent/extension from the returned prefix. The independent Python forward-stack oracle covers normalization/join/query/capacity/idempotence; hosted fixtures confirm filesystem authority remains independent.