Skip to content

feat(whoami): add whoami - #273

Merged
ferdingler merged 3 commits into
strands-agents:mainfrom
ferdingler:feat/whoami
Nov 19, 2026
Merged

ferdingler merged 3 commits into
strands-agents:mainfrom
ferdingler:feat/whoami

Conversation

@ferdingler

@ferdingler ferdingler commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

Description

There's no whoami, so an agent that checks who it's running as gets command not found.

This adds whoami. It prints the shell's own user, which is $USER (lash by default, or whatever the embedder sets), and falls back to lash if USER is unset or empty. It never looks at the real host's user. It takes no arguments, and an extra operand or unknown option is an error, like GNU. I also added it to the WASM command list and bumped the command count in the README.

Related Issues

Part of #207

Documentation PR

Type of Change

New feature

Testing

I compared the output and the error cases with GNU whoami. The new tests cover the default user, a user set in the shell or by the embedder, an unset USER, help, and the error cases. The full Rust suite passes and clippy has the same warnings as main. I didn't run the Python or Node suites because the bindings are unchanged. This is one of four small PRs adding whoami, hostname, uname, and id; each stands on its own, but they touch the same command lists, so whichever lands later will need a trivial rebase.

  • 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.

@ferdingler
ferdingler requested a review from a team as a code owner November 13, 2026 05:11
@ferdingler

Copy link
Copy Markdown
Collaborator Author

@strandly-the-agent Please review this PR

@ferdingler ferdingler mentioned this pull request Nov 13, 2026
10 tasks done

@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. whoami behaves the way the PR says, both WASM command lists are updated, and I found nothing blocking. The notes below are optional.

  • ⚪ "lash" is now hard-coded in two places, and #288 adds a third. whoami.rs:7 has const DEFAULT_USER: &str = "lash";, the same literal is at vfs_kernel.rs:291 (env.insert("USER".into(), "lash".into())), and id.rs:11 in #288 copies the constant again. A pub const LASH_USER next to LASH_UID in src/vfs.rs:14 would keep them in sync. This is cleanup, not a bug.
  • ⚪ Tests: the empty-USER branch has no test (expect!(whoami_empty_user, "USER= whoami", "lash")). The two error tests only check that stderr contains whoami, and the strands-shell: whoami: prefix always does.
What I verified
  • Head 63309f2. CI is green on every target. Locally, cargo test --test shell_integration whoami passed 7/7 and cargo test --workspace --all-targets passed 2577 with 0 failures. Clippy shows nothing new in whoami.rs. I didn't run cargo fmt (rustfmt isn't installed here) or a WASM build.
  • Behaviour through the CLI:
    • whoami → lash; USER= whoami → lash; unset USER; whoami → lash.
    • export USER=bob; whoami → bob; Shell::builder().env("USER", …) is respected; /bin/whoami works; whoami -- → lash.
    • whoami x → unexpected argument "x" (exit 1), the same as env x. whoami -x → invalid option '-x' (exit 1).
  • --help / --version: GNU whoami accepts both. Here --version is rejected (exit 1), which is consistent with the rest of the repo: no command implements --version (basename --version exits 1, pwd --version exits 2, and true --version exits 0 only because true ignores its arguments). -h is rejected, which matches GNU and the 17 other commands that only take --help (basename, cp, mv, …). About 15 commands do accept -h, so the repo is split, and this PR doesn't make that worse.
  • It never reads the host user. The env comes only from VfsKernel::new_process (vfs_kernel.rs:285-293), and nothing reads std::env.
  • Command lists: native builds register commands through inventory, so they need no change. The WASM lookup (mod.rs:109) and the WASM /bin list (vfs.rs:831) are both updated. The README count 33→34 matches the WASM lookup.

Appendix (non-blocking)

  • Pre-existing, not from this PR: the WASM /bin list (vfs.rs:829-832) is missing curl and sleep, even though both are in the WASM lookup. That's a one-line fix if someone touches that list. I didn't file an issue for it.
  • The command reference on strandsagents.com lives in a different repo and may need a whoami entry.

@strandly-the-agent strandly-the-agent mentioned this pull request Nov 13, 2026
9 of 10 tasks
@ferdingler

Copy link
Copy Markdown
Collaborator Author

Thanks. Pushed 87f1e67: there is now a test for an empty USER, and the two error tests check the actual message instead of just the command name.

On the shared "lash" constant: I kept each of the four identity PRs self-contained on purpose so they can be reviewed and merged in any order without depending on each other. Once this one and #288 are both in, I will do a small follow-up that adds a LASH_USER constant next to LASH_UID in src/vfs.rs and points new_process, whoami, and id at it. Same plan for the duplicated localhost default between #277 and #286.

The missing curl and sleep in the WASM /bin list is a good catch. It is outside this PR, so I will raise it separately.

@ferdingler

Copy link
Copy Markdown
Collaborator 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.

Still approve, now at 66d0485. Since my last review the only changes are the test commit and the merge of main; whoami.rs is byte-identical. No new findings. CI on the merge commit was still running when I posted, with no failures so far.

Previous notes:

  • Tests: fixed in 87f1e67. whoami_empty_user is a real check: when I removed the !user.is_empty() guard locally, that test failed and the other 7 passed. The two error tests now match the actual message.
  • Shared "lash" constant: still open, by agreement. #288 has merged, so the literal is now in three places (vfs_kernel.rs:282, id.rs:11, whoami.rs:7). Your follow-up plan is fine and doesn't block this.
What I verified
  • Merge resolution (66d0485, base 1e0dbfb): the WASM lookup in mod.rs:115 and the WASM /bin list in vfs.rs:848 both carry whoami next to the newly merged base64, id and uname. The README count 36→37 matches the 37 entries in the WASM lookup.
  • Tests: cargo test --workspace --all-targets passed 2687 with 0 failures; the 8 whoami tests pass. cargo fmt --check is clean and clippy reports nothing in whoami.rs. I didn't run a WASM build or the Python and Node suites.
  • Behaviour through the CLI:
    • whoami, USER= whoami and unset USER; whoami → lash; USER=agent whoami → agent, and the next whoami is back to lash.
    • whoami and the merged id -un agree for the default, a set USER and an unset USER.
    • which whoami, command -v whoami and /bin/whoami all resolve.
    • whoami x, whoami -x, whoami -h and whoami --version exit 1 with a message on stderr; whoami >&- exits 1.

Appendix (non-blocking)

  • whoami "" prints lash and exits 0 instead of failing. That's the shell dropping a literal "" before the command sees it (#299, fix in #320), not this PR; whoami '' is rejected correctly.
  • I couldn't find an issue yet for the WASM /bin list missing curl and sleep; it's still missing both on main.

@ferdingler
ferdingler merged commit c28e1fb into strands-agents:main Nov 19, 2026
33 checks passed
@ferdingler
ferdingler deleted the feat/whoami branch November 19, 2026 20:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants