Repository navigation
Description
Problem or Motivation
A command executed in the sandbox can produce excessive output that exceeds the LLM context window or inadvertently output sensitive strings. As required by ADR 0018 (docs/adr/0018-a-sandboxed-read-only-run-tool-for-the-planner.md, #3242), output returned to the planner must be capped and sanitized.
Proposed Solution & Architectural Design
Implement output truncation and secret sanitization for the planner run tool:
- Truncate command output to a maximum of 8 KiB and 120 lines.
- When output is truncated, append an explanatory line that names the omitted byte and line count.
- Run
mask_secretsfromsrc/devops_cli/security/sanitizer.pyover all stdout and stderr streams. - Format the final sanitized and truncated output so the planner can quote it directly into the
## Feasibilitysection of the proposal.
Depends on: #3242 (ADR 0018).
Target Subsystem
AI & Agentic Review Pipeline
Existing Tool Considered
src/devops_cli/security/sanitizer.py:mask_secrets already provides audited secret scrubbing for CLI and agent output. Standard Python string slicing handles truncation. Building this formatter costs approximately 6,000 tokens and 0.25 elapsed days.
Proposed design
Problem statement
A command that the planner runs can print more text than the plan's token budget holds. It can also print a credential. ADR 0018 requires the run tool to cap the text at 8 KiB and 120 lines and to mask secrets. This item adds the cap, the trailer line that names the omitted counts, and the mask_secrets call.
Acceptance criteria
Requirement: Output cap
The run tool SHALL return at most 8192 bytes and at most 120 lines of text for one run, the trailer line included.
Scenario: Long output is cut
- WHEN A command writes 20000 bytes over 400 lines.
- THEN The returned text holds at most 8192 UTF-8 bytes and at most 120 lines.
Requirement: Trailer names the omitted counts
The returned text MUST end with one trailer line that states the omitted byte count and the omitted line count when the cut leaves text out.
Scenario: The cut leaves text out
- WHEN A command writes 20000 bytes over 400 lines.
- THEN The last line matches
^\[truncated: \d+ bytes and \d+ lines omitted\]$, and the kept body plus the omitted counts equal the input counts.
Requirement: No trailer for a short output
The run tool MUST return the text with no trailer line when the text fits within both caps.
Scenario: Short output is kept whole
- WHEN A command writes 200 bytes over 3 lines.
- THEN The returned text equals the masked input and holds no
[truncated:line.
Requirement: Secret masking
The run tool MUST pass every returned text through mask_secrets of src/devops_cli/security/sanitizer.py before the planner reads it.
Scenario: A command prints a token on stderr
- WHEN A command writes
GITHUB_TOKEN=ghp_and 36 further characters to stderr. - THEN The returned text holds
<masked-github-token>and the 36 characters after the prefix are absent.
Requirement: Masking precedes the cut
The run tool SHALL mask the text before it cuts the text.
Scenario: The cap falls inside a private key block
- WHEN A command writes a PEM private key whose end marker sits after byte 8192.
- THEN The returned text holds
<masked-private-key>and holds no line of the key body and noPRIVATE KEYmarker.
Requirement: Feasibility quote block
The run tool SHALL format the masked text as a fenced code block that holds the command line, the exit code and the text.
Scenario: The planner quotes a failed run
- WHEN The command
devops k8s get podsexits 1 and writes 3 lines. - THEN The block opens with a fence longer than any backtick run in the text, holds the command line and
exit 1, and closes with a fence of the same length.
Existing Tool Considered
No alternatives check has run. mask_secrets in src/devops_cli/security/sanitizer.py covers the masking need, and tests/security/test_secret_redaction.py tests it. It lacks a cap, because no function there truncates text. Python slicing covers the cap at no library cost. The body states a cost of about 6,000 tokens and 0.25 elapsed days to build the formatter.
Key questions
- Which module holds the output cap, the trailer and the mask call?: Add
src/devops_cli/roadmap/run_output.py. It holds the cap, the trailer and themask_secretscall, and one test module covers it. The sanitizer stays unchanged, and the stage adapter calls the new function. (best practice) [sources: docs/adr/0018-a-sandboxed-read-only-run-tool-for-the-planner.md, src/devops_cli/security/sanitizer.py, src/devops_cli/roadmap/run.py]- Chosen: New module
src/devops_cli/roadmap/run_output.py. The run tool is a roadmap feature, and one module with one test module keeps the concern in one place. - Rejected: Extend
src/devops_cli/security/sanitizer.py. The sanitizer masks text for 84 caller paths and knows no cap. - Rejected: Extend
src/devops_cli/roadmap/run.py. That module runs the stage row in the Service pod, and the cap needs no process.
- Chosen: New module
- In which order does the code mask and cut?: Mask first, then cut. The private-key pattern runs from the
BEGINline to theENDline, so a cut before theENDline leaves key material that no pattern masks. (best practice) [sources: src/devops_cli/security/sanitizer.py, docs/adr/0018-a-sandboxed-read-only-run-tool-for-the-planner.md]- Chosen: Mask, then cut. The mask sees the whole key block and replaces it before the cut.
- Rejected: Cut, then mask. A cut inside a key block defeats the pattern that needs the
ENDline.
- Does the cap count the trailer line and its bytes?: The cap covers the trailer. The returned text holds at most 8192 bytes and 120 lines in all, the trailer line included, as ADR 0018 states. (best practice) [sources: docs/adr/0018-a-sandboxed-read-only-run-tool-for-the-planner.md]
- Chosen: The cap covers the trailer line. ADR 0018 states that the text holds at most 8 KiB and 120 lines and ends with the trailer.
- Rejected: The trailer line is outside the cap. The returned text would exceed the stated cap by one line.
- How does the code measure bytes and place the cut?: Measure bytes with the UTF-8 encoding of the text and cut only at a line boundary. Keep the first lines. A cut at a line boundary never splits a character. (best practice) [sources: docs/adr/0018-a-sandboxed-read-only-run-tool-for-the-planner.md]
- Chosen: Line boundary, UTF-8 bytes. A line boundary keeps every character whole and matches the first lines that ADR 0018 keeps.
- Rejected: Byte offset. It can split a UTF-8 character and a line.
- Which syntax does the masking call use?: Call
mask_secrets(text)with the defaultsyntax="data". Command output is terminal text and not code under review, so every credential-shaped value must be masked. (best practice) [sources: src/devops_cli/security/sanitizer.py]- Chosen:
syntax="data". The code mode leaves an unquoted code expression as written, and a token can look like one. - Rejected:
syntax="code". It leaves a value such as a token read from the environment unmasked.
- Chosen:
- What does the trailer line say?: Use
[truncated: N bytes and M lines omitted]as the last line. N counts the input bytes that the body does not hold, and M counts the lines in the same way. (best practice) [sources: docs/adr/0018-a-sandboxed-read-only-run-tool-for-the-planner.md]- Chosen:
[truncated: N bytes and M lines omitted]. One ASCII line names both counts, as ADR 0018 requires. - Rejected: A prose sentence. It costs more of the cap and names no count that a test reads.
- Chosen:
- How does the quote block look under
## Feasibility?: Open the block with a fence of backticks one longer than the longest backtick run in the text, and never fewer than three. Then write$ <command line>, thenexit <code>or the signal name, then the text, then a closing fence of the same length. (best practice) [sources: docs/adr/0018-a-sandboxed-read-only-run-tool-for-the-planner.md]- Chosen: Fence longer than the longest run in the text. CommonMark closes a block at a fence of the same length or longer, so a longer fence keeps the output inside.
- Rejected: A fixed three-backtick fence. A line of three backticks in the output closes the block early.
- Which outside work does this item wait on?: None beyond docs(security): design a sandboxed read-only run tool for the planner #3242, whose ADR is on the default branch at this commit. The cap and the mask are pure text functions, so they need no run Job. [sources: docs/adr/0018-a-sandboxed-read-only-run-tool-for-the-planner.md, src/devops_cli/security/sanitizer.py]
Fit
Fits in one pull request.
Suspected block
None.
Dependencies
Alternatives check of 2026-11-09: none.
Tool: none found.
Activity
devops-cli-service commentedon Nov 7, 2026
Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.
ADR 0018 requires the change for safety, but it is a sub-task of an open design item and not a live defect.The change stops context overflow and stops secret leaks in planner output.The change reuses the audited mask_secrets function and simple string slicing, at about 0.25 days.The candidate implements the output limits that ADR 0018 requires, but the ADR only designs the run tool and adds no code.devops-cli-service commentedon Nov 8, 2026
Status set to Ready at 1f03ee3 (see proposed design in issue body).
devops-cli-service commentedon Nov 9, 2026
Alternatives check: none
Reason: Two searches found no open library that caps text by bytes and lines, appends a trailer with the omitted counts, masks secrets before the cut, and builds a fenced Feasibility block. The results were unrelated MDN pages. The repository's own
mask_secretsalready covers the masking, and Python slicing covers the cap. The newrun_output.pyglue is small and specific to this project's format.Tool: none found
Covers:
Lacks:
Searches run:
Checked on 2026-11-09. A person decides what this means for the item. The check changes no label and closes no issue.
feat(roadmap): cap and mask the output of one planner run (#4006)
test(roadmap): cover the cap edges and the stderr join (#4006)
devops-cli-service commentedon Nov 15, 2026
Released in v0.146.0: https://github.com/dan-petty/devops-cli/releases/tag/v0.146.0
devops-cli-service commentedon Nov 15, 2026
Live since 2026-11-15 00:23 UTC