foundation capa

foundation-bounded-io

Bounded I/O: UTF-8-safe truncation, bounded subprocess runner, line-framed JSON stream reader

Bounded I/O: UTF-8-safe truncation, bounded subprocess runner, line-framed JSON stream reader

Tierfoundation
Roleunclassified (baselined)
Pathcrates/foundation/bounded-io
Edition2021
Targetsfoundation_bounded_io
Public items20 across 2 modules
Tests47

What it is for

Bounded I/O sub-primitives (sprint 1.0.1 T-1.0.1a-0; HARVEST-BACKLOG rows 25/26/28).

Three fail-loud building blocks, each previously hand-rolled per site:

(lifted from infrastructure-ai/src/claude_cli.rs).

and per-stream byte caps; PROCESS §17 invariants in one place.

cap, read timeout, and a typed malformed-line error.

Capabilities

BoundedCommand

Bounded subprocess runner (HARVEST-BACKLOG row 25).

Item
pub struct BoundedCommand
BoundedCommand :: fn new(bin : impl Into <PathBuf>, limits : ExecLimits) -> Self
BoundedCommand :: fn arg(mut self, a : impl Into <String>) -> Self
BoundedCommand :: fn stdin_bytes(mut self, b : Vec <u8>) -> Self
BoundedCommand :: fn current_dir(mut self, dir : impl Into <PathBuf>) -> Self
BoundedCommand :: fn env_clear(mut self) -> Self
BoundedCommand :: fn env(mut self, key : impl Into <String>, value : impl Into <String>) -> Self
BoundedCommand :: fn uid(mut self, uid : u32) -> Self
BoundedCommand :: fn gid(mut self, gid : u32) -> Self
BoundedCommand :: fn run_sync(self) -> Result <ExecOutput, ExecError>
BoundedCommand :: async fn run(self) -> Result <ExecOutput, ExecError>

ExecError

Bounded subprocess runner (HARVEST-BACKLOG row 25).

Item
pub enum ExecError

ExecLimits

Bounded subprocess runner (HARVEST-BACKLOG row 25).

Item
pub struct ExecLimits

ExecOutput

Bounded subprocess runner (HARVEST-BACKLOG row 25).

Item
pub struct ExecOutput

JsonLines

Line-framed JSON stream reader (HARVEST-BACKLOG row 28).

Item
pub struct JsonLines<R>

JsonLines<R>

Line-framed JSON stream reader (HARVEST-BACKLOG row 28).

Item
JsonLines<R> :: fn new(reader : R, max_line_bytes : usize, read_timeout : Duration) -> Self
JsonLines<R> :: fn line_index(& self) -> usize
JsonLines<R> :: async fn next_line(& mut self) -> Result <Option <Vec <u8>>, JsonlError>
JsonLines<R> :: async fn next_value(& mut self) -> Result <Option <serde_json::Value>, JsonlError>

JsonlError

Line-framed JSON stream reader (HARVEST-BACKLOG row 28).

Item
pub enum JsonlError

How to use it

No examples/ target and no doctest in this crate's rustdoc. The tests listed under Verification are the closest executable usage.

Module structure

foundation_bounded_io

flowchart TD
  n_foundation_bounded_io["foundation_bounded_io"]
  n_foundation_bounded_io --> n_exec["exec"]
  n_foundation_bounded_io --> n_jsonl["jsonl"]

Public surface

`exec`

ItemWhat it is
pub struct ExecLimitsLimits applied to a single run
pub struct ExecOutputCaptured result of a bounded run that exited zero within its limits.
pub enum ExecErrorEvery way a bounded run fails
pub struct BoundedCommandA bounded subprocess invocation: explicit binary, argument vector, limits.
BoundedCommand :: fn new(bin : impl Into <PathBuf>, limits : ExecLimits) -> Self
BoundedCommand :: fn arg(mut self, a : impl Into <String>) -> Self
BoundedCommand :: fn stdin_bytes(mut self, b : Vec <u8>) -> SelfBytes written to the child's stdin before reading output
BoundedCommand :: fn current_dir(mut self, dir : impl Into <PathBuf>) -> SelfWorking directory for the child
BoundedCommand :: fn env_clear(mut self) -> SelfDrop the caller's own environment before applying .env() calls, so the child sees exactly what was configured — never an implicit inheritance a caller didn't ask for
BoundedCommand :: fn env(mut self, key : impl Into <String>, value : impl Into <String>) -> Self
BoundedCommand :: fn uid(mut self, uid : u32) -> SelfRun the child as this uid (std::os::unix::process::CommandExt — no unsafe code needed)
BoundedCommand :: fn gid(mut self, gid : u32) -> Self
BoundedCommand :: fn run_sync(self) -> Result <ExecOutput, ExecError>run without a runtime: std threads drain the two pipes under the cap while the caller's thread polls the child against the wall clock
BoundedCommand :: async fn run(self) -> Result <ExecOutput, ExecError>Run to completion within the limits

`jsonl`

ItemWhat it is
pub enum JsonlError
pub struct JsonLines<R>Bounded reader over newline-delimited JSON.
JsonLines<R> :: fn new(reader : R, max_line_bytes : usize, read_timeout : Duration) -> Self
JsonLines<R> :: fn line_index(& self) -> usizePhysical 0-based line number of the line most recently returned by Self::next_line/Self::next_value or reported in an error
JsonLines<R> :: async fn next_line(& mut self) -> Result <Option <Vec <u8>>, JsonlError>Next raw line as ORIGINAL bytes (terminator trimmed), bounded by the same content cap and timeout as Self::next_value
JsonLines<R> :: async fn next_value(& mut self) -> Result <Option <serde_json::Value>, JsonlError>Next parsed line: Ok(Some(value)), Ok(None) at clean EOF, or a typed error.

Re-exports. Exported here, defined elsewhere.

ExportDefined in
truncate_utf8_boundedtruncate::truncate_utf8_bounded
{PathError,PathGuard,PathGuardSet}pathguard::{PathError,PathGuard,PathGuardSet}

Boundary

Depends on no other workspace tier.

Shares tier foundation with 27 other crates: foundation-audit-log, foundation-basemodels, foundation-conversation-closure, foundation-crypto-sign, foundation-decisioning, foundation-encounter-vocabulary, foundation-fs-metadata, foundation-i18n, … (27 total).

_What this crate deliberately does NOT own is a judgment. No committed registry records one for it, so none is stated here._

Where it sits

Tier (ontology)foundation
Architectural role (taxonomy)unclassified (baselined)
Locationcrates/foundation/bounded-io
Vocabulary in force (lexicon)current

Dependencies

Runtime, from outside the workspace.

CrateRequirementFeaturesOptionalOnly on
serde_json^1yesalways
thiserror^2noalways
tokio^1process, io-util, time, rt, macrosyesalways

Development, from outside the workspace.

CrateRequirementFeaturesOptionalOnly on
serde_json^1noalways
tokio^1fullnoalways

Build. None.

Depended on by. 24 workspace crates.

Signal flow — what reaches this crate, and what it reaches.

flowchart LR
  n_application_wiki["application-wiki"] -->|uses| SELF
  n_infrastructure_agent["infrastructure-agent"] -->|uses| SELF
  n_infrastructure_ai["infrastructure-ai"] -->|uses| SELF
  n_infrastructure_doc_ingest["infrastructure-doc-ingest"] -->|uses| SELF
  n_infrastructure_firmware_forensics["infrastructure-firmware-forensics"] -->|uses| SELF
  n_infrastructure_memory_forensics["infrastructure-memory-forensics"] -->|uses| SELF
  n_infrastructure_registry_forensics["infrastructure-registry-forensics"] -->|uses| SELF
  n_infrastructure_write_blocker["infrastructure-write-blocker"] -->|uses| SELF
  n_operations_block_imaging["operations-block-imaging"] -->|uses| SELF
  n_operations_boot_media["operations-boot-media"] -->|uses| SELF
  n_operations_control_plane["operations-control-plane"] -->|uses| SELF
  n_operations_net_scan["operations-net-scan"] -->|uses| SELF
  n_operations_net_trace["operations-net-trace"] -->|uses| SELF
  n_platform_disclosure_lab["platform-disclosure-lab"] -->|uses| SELF
  n_tools_book_report["tools-book-report"] -->|uses| SELF
  n_tools_corpus["tools-corpus"] -->|uses| SELF
  n_tools_fleet_reconnect["tools-fleet-reconnect"] -->|uses| SELF
  n_tools_githooks["tools-githooks"] -->|uses| SELF
  n_tools_imp["tools-imp"] -->|uses| SELF
  n_tools_local_model_import["tools-local-model-import"] -->|uses| SELF
  n_tools_manual["tools-manual"] -->|uses| SELF
  n_tools_prompt_shaper["tools-prompt-shaper"] -->|uses| SELF
  n_tools_research_sweep["tools-research-sweep"] -->|uses| SELF
  n_tools_target_sweep["tools-target-sweep"] -->|uses| SELF
  SELF["foundation-bounded-io"]
  classDef self fill:#1f883d,stroke:#1f883d,color:#fff;
  class SELF self;

Feature flags

FeatureEnablesOn by default
defaultyes
execdep:tokiono
exec-syncno
jsonldep:tokio, dep:serde_jsonno
flowchart LR
  n_default["default"]
  n_exec["exec"] --> n_dep_tokio["dep:tokio"]
  n_exec_sync["exec-sync"]
  n_jsonl["jsonl"] --> n_dep_tokio["dep:tokio"]
  n_jsonl["jsonl"] --> n_dep_serde_json["dep:serde_json"]

Targets

KindNameSource
libfoundation_bounded_io`src/lib.rs`

Error model

Error typeNamed by
ExecErrordeclared, no public signature returns it
JsonlErrordeclared, no public signature returns it

Operational characteristics

PropertyEvidence
async public surfaceyes
async runtimeyes
database accessnone detected
network I/Onone detected
unsafe codeyes
environment variablesnone detected

Unsafe code.

SiteSource
unsafe blocksrc/exec.rs
unsafe fn libc_getuidsrc/exec.rs

Configuration

No environment variable is read with a literal name anywhere in this crate. A variable whose key is computed at run time cannot be listed here, and is not claimed to be absent.

24 workspace crates depend on this one: application-wiki, infrastructure-agent, infrastructure-ai, infrastructure-doc-ingest, infrastructure-firmware-forensics, infrastructure-memory-forensics, infrastructure-registry-forensics, infrastructure-write-blocker, operations-block-imaging, operations-boot-media, operations-control-plane, operations-net-scan, … (24 total).

Verification

KindCount
Unit tests47
Integration tests0
Examples0
Doctests0

Evidence by module. How often each public module is named by something executable.

ModuleTestsExamplesConsumers
exec4045
jsonl204

What the tests establish, by name:

Documentation coverage

MeasureDocumentedTotal
Public items with rustdoc1420
Public modules with a //! block22
pie showData
    title Public items with rustdoc
    "Documented" : 14
    "No rustdoc detected" : 6

Metrics

MetricValue
Rust source files5
Source lines1425
Code lines1138
Public API items20
Public modules2
Tests47
Examples0
Cargo features4
Direct runtime dependencies3
Workspace reverse dependencies24
pie showData
    title Public API by kind
    "enum" : 2
    "method" : 14
    "struct" : 4
pie showData
    title Rust source composition
    "Code" : 1138
    "Blank or comment" : 287

Generation

Rendered by tools-corpus corpus readme from repository evidence alone, renderer schema 2, lexicon current. No model, network service or database was consulted. Regenerate with tools-corpus corpus readme --write; verify with --check.

Todas las foundation · Manual