← Back to Pull requests

Add tee builtin #623

Closed
unknown closed this pull request without merging on Sep 30, 2026 16:25 UTC
View on GitHub
unknown unknown commented on Sep 22, 2026 12:07 UTC
Author

Summary

Adds tee as a remediation-only builtin, alongside truncate/logrotate/rm/systemctl, since it mutates file content.

Supported flags: -a/--append, -h/--help. -i/--ignore-interrupts and -p/--output-error are intentionally out of scope (rshell builtins don't receive process signals, and every FIFO write target is already rejected by the sandbox) and are rejected as unknown flags.

Design notes

  • Streams stdin to stdout and every FILE operand in fixed 32 KiB chunks — no buffering proportional to input size.

  • Every FILE write routes through callCtx.OpenFile, inheriting the AllowedPaths :rw sandbox gate, hard-link write-target rejection, and the RemediationOnly dispatch gate that truncate/logrotate already rely on.

  • Found and worked around a real gap while implementing this: unlike Sandbox.Truncate/Sandbox.TruncateToZeroIfAtLeast, Sandbox.Open (the primitive behind callCtx.OpenFile) does not add O_NONBLOCK to a caller-supplied write flag. An O_WRONLY open of a readerless FIFO through callCtx.OpenFile therefore blocks the shell indefinitely — I hit this early on with tee pipe hanging. tee works around it with a pre-open StatFile check (rejectNonRegularTarget), mirroring the interpreter's own rejectNonRegularRedirectTarget used by >/>>. Documented in AGENTS.md for future write-capable builtins, since tee is the first builtin to call callCtx.OpenFile with a write flag directly.

  • - as a FILE operand writes to standard output again (matching GNU tee), not a literal file named -.

  • A failing destination (sandbox denial, hard link, non-regular target) is reported once and dropped; output continues to standard output and every remaining FILE, matching GNU tee's continue-on-failure semantics.
  • Testing

  • builtins/tests/tee: unit/integration tests covering append/overwrite, multi-file, -/passthrough, remediation-mode gating, sandbox containment, hard-link rejection, FIFO rejection.

  • interp/builtin_tee_pentest__test.go: pentest suite — remediation-mode gating (including the "no FILE operands" edge case), sandbox escape (path traversal, symlink, absolute path), hard-link and FIFO write-target rejection with and without an attached reader (mirroring the existing truncate FIFO pentest's determinism check), resource limits (200 file operands, duplicate operand, streamed large input, broken downstream pipe), flag/argument injection.

  • builtins/tests/tee/tee_fuzz_test.go: FuzzTeeStdinContent, FuzzTeeFlags.

  • tests/scenarios/cmd/tee/: YAML scenarios, compared against real bash/GNU tee via the existing Docker-based harness where behavior is expected to match; skip_assert_against_bash only on the two flags we intentionally reject that GNU tee accepts (-i, -p).

  • Full suite (go build ./..., gofmt -l ., go vet ./..., go test ./...) is green, including the analysis/ symbol-allowlist and structural (OpenFile-must-close) checks.
  • Note: RSHELL_BASH_TEST=1 go test ./tests/... -run TestShellScenariosAgainstBash fails locally on this machine with a pre-existing Docker-Desktop-on-macOS bind-mount issue (bash: /work/runner.sh: No such file or directory) — reproduces identically on unmodified main, unrelated to this change.

    Docs

  • SHELL_FEATURES.md: new tee entry, RemediationMode builtin list updated.

  • AGENTS.md: new note on the O_NONBLOCK write-open gap this surfaced.

  • .github/workflows/fuzz.yml: new matrix entry for builtins/tests/tee.
  • Diff: 442 lines (+331 / -111) across 5 files Reviewer: san-jos Review duration: 11778m
    All Vouch review confidence checks passed
    Residual risk 0.18 = Change Risk (0.45) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.45 · 442 lines diff across 5 files
    0.45
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.365
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #623"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 45.3% (MEDIUM) · Higher = larger blast radius
    45.3%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 17.9% · Safe to merge
    17.9%
    Repository