Skip to content

feat(id): add id - #288

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

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

Conversation

@ferdingler

@ferdingler ferdingler commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

Description

There's no id, so a script that checks whether it's running as root with [ "$(id -u)" -eq 0 ] gets command not found.

This adds id with its default output plus -u, -g, and -n (so -un and -gn work). It reports the shell's own user, never the host's: the uid and gid are the same 1000 the virtual filesystem already uses for file ownership, and the name is $USER (lash by default), the same name whoami prints. The group shares the user's name. -n on its own and asking for both -u and -g are errors with GNU's messages. I left out -G, -r, -z, and looking up another user by name to keep this small; those are still errors. 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 format and the error cases with GNU id. The new tests cover the default output, each flag and combination, the user name variable, 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. Once whoami (#273) and this one are both in, the shared default user name could move to one place.

  • 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:20
@ferdingler

Copy link
Copy Markdown
Collaborator Author

@strandly-the-agent Please review this PR

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

@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. id matches GNU id on every flag combination and error I tried, it reports the same uid/gid (1000) the VFS already uses, and CI is green on every target. I found nothing blocking. There are three optional nits below the fold and one design question.

Question (non-blocking): USER=root id prints uid=1000(root) gid=1000(root) groups=1000(root) while id -u still prints 1000. GNU id derives the name from the uid and ignores $USER. Following $USER keeps id -un and whoami (#273) in agreement, which seems like the right trade, but the name and the number can now disagree. Is that intended?

✅ What I verified
  • Head ac10f8d. cargo test --test shell_integration id_ ran 30 tests, 30 passed (that filter also matches some non-id tests). The reviewer pass ran the full shell_integration suite: 1977 passed, 0 failed. Clippy shows nothing in id.rs. I didn't run cargo fmt --check because rustfmt isn't installed here.
  • CI: every Rust/Python/Node target, the security audit, and the CI Gate are green on ac10f8d.
  • Against GNU id (coreutils 9.1), using the built strands-shell -c:
    • id → uid=1000(lash) gid=1000(lash) groups=1000(lash), the same layout as GNU.
    • id -un, id -nu, id -gn and id -u -u behave the same as GNU.
    • id -n → id: cannot print only names or real IDs in default format, exit 1. Same as GNU.
    • id -u -g → id: cannot print "only" of more than one choice, exit 1. Same as GNU.
    • [ "$(id -u)" -eq 0 ] is false, which is the use case in the PR description.
    • USER= id -un and unset USER; id -un both print lash.
    • id -z and id lash exit 1. These options and operands are deliberately unsupported, as the description says.
  • Identity consistency: LASH_UID/LASH_GID (src/vfs.rs:14-15) are the ids the kernel uses for every permission check and new file. ls -l doesn't print owners and there is no stat, so nothing else in the shell shows a name that could disagree. $UID and $EUID aren't set.
  • Command lists: both WASM lists are updated (src/commands/mod.rs lookup and the src/vfs.rs:830 /bin list). Native builds register commands through inventory. The README bump 33→34 matches.
Passes run

I ran a correctness/tests/docs reviewer pass (fresh context) plus my own build and GNU comparison. I didn't run an API bar-raiser pass because no public Rust/Python/Node API changed; the new surface is a shell command whose GNU behaviour I checked directly. I didn't run an adversarial pass because the only risky logic is a small lexopt loop, and the edge cases (--, --user=x, repeated flags, combined shorts) are covered in the verification above.

Appendix — non-blocking (3)
  1. ⚪ No test for the empty-$USER fallback. src/commands/id.rs:46: Some(user) if !user.is_empty() =>. Deleting the if !user.is_empty() guard still passes every id_ test. One line after id_unset_user (tests/shell_integration.rs:13633) would cover it:
    expect!(id_empty_user, "USER= id -un", "lash");
  2. ⚪ id_matches_whoami_user passes by construction. tests/shell_integration.rs:13634-13638: [ "$(id -un)" = "$USER" ]. id reads $USER itself, so this adds nothing beyond id_un and id_follows_user, and whoami isn't on main yet. Either drop it, or after #273 lands, make it a real cross-check:
    expect!(id_matches_whoami, "[ \"$(id -un)\" = \"$(whoami)\" ] && echo same", "same");
  3. ⚪ A third "lash" literal. src/commands/id.rs:11: const DEFAULT_USER: &str = "lash"; duplicates src/vfs_kernel.rs:291 (env.insert("USER".into(), "lash".into())), and #273 adds the same constant in whoami.rs. The PR description already plans this follow-up. A pub const LASH_USER: &str = "lash"; next to LASH_UID in src/vfs.rs:14 would let all three share it.

Not from this PR:

  • #273 and the hostname/uname PRs edit the same README count line and the same WASM /bin list, so whichever merges later needs its count re-bumped. The description already flags this.
  • The command reference on strandsagents.com is in another repo and doesn't list id; it will need a separate docs PR.
  • Pre-existing: the WASM /bin list (src/vfs.rs:829-832) is missing curl and sleep. This was noted on #273, and I'm not filing it separately.

@ferdingler

Copy link
Copy Markdown
Collaborator Author

Thanks. Pushed 70d7c3b: added the empty USER test, dropped the comparison test that passed no matter what (I will add a real id -un vs whoami check once #273 lands), and the error tests now check the actual messages.

On USER=root id showing uid=1000(root): yes, that is intended. The sandbox has no user database. $USER is the only place a name comes from, and it is how an embedder sets the identity. So id -un and whoami follow it and always agree. The uid stays 1000 because that is what the filesystem uses for ownership and permission checks, so id -u tells the truth about access: [ "$(id -u)" -eq 0 ] is never true just because someone set USER=root.

The shared "lash" constant is the planned follow-up once #273 and this one are both in.

@ferdingler
ferdingler merged commit 62a62d1 into strands-agents:main Nov 19, 2026
31 checks passed
@ferdingler
ferdingler deleted the feat/id branch November 19, 2026 01:00
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