Skip to content

feat(os): let the kernel describe the system uname reports - #331

Merged
pgrayy merged 3 commits into
strands-agents:mainfrom
pgrayy:feature/pgrayy/kernel-system
Nov 19, 2026
Merged

pgrayy merged 3 commits into
strands-agents:mainfrom
pgrayy:feature/pgrayy/kernel-system

Conversation

@pgrayy

@pgrayy pgrayy commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

Description

Problem

uname always describes a virtual Linux system. That fits Shell on its own, where the files, the user and the home directory are virtual too.

It doesn't fit an embedder that runs Shell over a real host. Box is one: its Shell acts on host files and runs host programs. On macOS, uname there says Linux, so an agent can pick commands the host doesn't have. The embedder can't route uname to the host program either, because a command Shell implements answers its own name first.

Solution

The kernel says which system uname describes, the same way date, ls, touch and find ask Kernel::now for the time.

  • os::SystemInfo holds the fields uname takes from the system. They're named after its long options: kernel_name, node_name, kernel_release, kernel_version, machine and operating_system.
  • SystemInfo::default() is today's virtual system.
  • Kernel::uname returns that default, and uname reads it instead of its constants.

Shell on its own doesn't change. VfsKernel keeps the default, so uname still never shows the host. uname -n still prefers $HOSTNAME, as hostname does, and falls back to the kernel's node name.

Usage

A kernel that serves a real host reports it:

impl Kernel for HostKernel {
    fn uname(&self) -> SystemInfo {
        SystemInfo {
            kernel_name: "Darwin".into(),
            node_name: "studio".into(),
            kernel_release: "24.6.0".into(),
            kernel_version: "Darwin Kernel Version 24.6.0".into(),
            machine: "arm64".into(),
            operating_system: "Darwin".into(),
        }
    }
    // ...
}
$ uname -a
Darwin studio 24.6.0 Darwin Kernel Version 24.6.0 arm64 Darwin

Related Issues

Follows #286. Box will answer Kernel::uname from the host's uname(2) in a follow-up PR once this merges.

Documentation PR

None.

Type of Change

New feature

Testing

  • cargo test --lib: 86 passed

  • cargo test --test shell_integration: 2017 passed. The 16 existing uname tests pass unchanged.

  • cargo test --test custom_kernel: 15 passed, including a new test where the kernel reports its own system and uname -a prints every field.

  • cargo test --test date_fixed_clock: 5 passed

  • Box's kernel crate (cargo test -p strands-box-shell), built against this branch, with Kernel::uname answered from the host's uname(2): 146 passed. Its test checks uname -snrm against the host's own uname.

  • I ran the relevant test suites for the bindings I touched (cargo test --workspace --all-targets, pytest tests/python, npm test)

  • If I touched Rust, I ran cargo fmt and cargo clippy

Checklist

  • I have read the CONTRIBUTING document
  • I have reviewed and understand every line of code in this PR, including any generated by AI tools, and I can explain why it works
  • My change is focused and reasonably small; I have split unrelated work into separate PRs
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • I have added an appropriate example to the documentation to outline the feature, or no new docs are needed
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

uname printed fixed values for a virtual Linux system. An embedder that runs
Shell over a real host, as Box does, has no way to report that host. Add
Kernel::system, whose default is the same virtual system, and have uname
read it.
@github-actions github-actions Bot added the enhancement New feature or request label Nov 19, 2026
@pgrayy

pgrayy commented Nov 19, 2026

Copy link
Copy Markdown
Member Author

@strandly-the-agent Please review this PR

@strandly-the-agent strandly-the-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve at 548b268. Kernel::system is a small, opt-in hook in the right place, and standalone uname prints exactly what it did on base. Two inline comments, neither blocking:

  • 🟡 tests/custom_kernel.rs:323: the fixture uses Darwin for both -s and -o, so the test passes with the two fields swapped.
  • ❓ src/os.rs:92: how SystemInfo gains a field later.
What I verified, questions, appendix

Verified (Linux aarch64, rustc 1.100.0, head 548b268, base 1e0dbfb)

  • cargo test --workspace --all-targets: 2680 passed, 0 failed, 0 ignored across 20 test binaries.
  • cargo fmt --check and cargo clippy --workspace --all-targets exit 0; clippy warnings are the same on base and head, none in the changed files. RUSTDOCFLAGS="-D warnings" cargo doc --workspace --no-deps exits 0.
  • Base and head binaries compared over 42 uname invocations (every short and long flag, combinations, HOSTNAME variants, --help, bad options): stdout, stderr and exit code are identical.
  • Mutations of uname.rs that the new test catches: release and version swapped, machine read from the host ARCH, os.system() ignored, -o hard-coded. The one it misses is the inline 🟡.
  • No other source of system identity in src/ disagrees with uname under a custom kernel (no arch/hostname command, no OSTYPE/MACHTYPE), and VfsKernel is the only impl Kernel in src/, so nothing drops an override. The bindings don't expose Kernel.

Not run: pytest tests/python, npm test, a WASM build, anything on macOS.

Questions (non-blocking)

  1. Name: every command receives the kernel as os, so the call is os.system(), which reads as "run a command" (C system(3), Python os.system) in a shell crate. Would uname() or system_info() be clearer? It's free to rename now.
  2. For the Box follow-up: reporting Darwin steers the model toward BSD flags, and Shell's own built-ins reject them. At this head sed -i '' 's/a/X/' f fails with sed: no such file or directory: /home/lash/s/a/X and date -v+1d fails with invalid option '-v'. Worth checking that Darwin is a net win before Box turns it on.

Appendix (2)

  • src/os.rs:90 says "The system that uname describes", but -n comes from $HOSTNAME and -p/-i are fixed. One line saying so would explain to an embedder why uname -a still says localhost.
  • The PR checklist box "I have reviewed and understand every line of code in this PR" is unchecked.

Comment thread tests/custom_kernel.rs Resolved
Comment thread src/os.rs Resolved
zastrowm
zastrowm previously approved these changes Nov 19, 2026
os.system() read like running a command, so the method takes the name of
the POSIX call it mirrors, as stat() does. SystemInfo gains node_name, so
a kernel over a real host can report its name; uname -n still prefers
$HOSTNAME. The test fixture now gives -s and -o different values, so a
swap of the two fields fails it.
@pgrayy

pgrayy commented Nov 19, 2026

Copy link
Copy Markdown
Member Author

Thanks for the review. Addressed in 7cc894a:

  1. Name: renamed to Kernel::uname. The trait uses the POSIX call name when std has none, and uname() returning SystemInfo pairs with stat() returning FileStat.
  2. Doc: SystemInfo and Kernel::uname now say they hold "the uname fields that a kernel reports", so they no longer claim all of uname. -p and -i aren't fields, and the node_name field doc says $HOSTNAME takes precedence.
  3. Darwin in Box: Box on macOS already reports Darwin today, through the host's uname, so this keeps current behavior. Darwin is the right answer for what agents use it for, picking downloads and install steps that run on the host. The GNU-style built-ins are better handled by telling the agent in Box's agent context than by changing uname.

--lib 86, shell_integration 2017, custom_kernel 15 and date_fixed_clock 5 pass, and fmt, clippy and cargo doc -D warnings are clean.

@pgrayy
pgrayy enabled auto-merge (squash) November 19, 2026 17:03
@pgrayy
pgrayy merged commit 674212e into strands-agents:main Nov 19, 2026
34 of 36 checks passed
@pgrayy
pgrayy deleted the feature/pgrayy/kernel-system branch November 19, 2026 17:15
@strandly-the-agent strandly-the-agent mentioned this pull request Nov 19, 2026
9 of 10 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants