Skip to content

fix(ls): preserve .env in default output#1508

Open
nghiahsgs wants to merge 1 commit intortk-ai:masterfrom
nghiahsgs:fix/preserve-dotenv-in-ls
Open

fix(ls): preserve .env in default output#1508
nghiahsgs wants to merge 1 commit intortk-ai:masterfrom
nghiahsgs:fix/preserve-dotenv-in-ls

Conversation

@nghiahsgs
Copy link
Copy Markdown

Problem

.env is listed in NOISE_DIRS (src/cmds/system/constants.rs), so rtk ls silently drops it unless the agent passes -a. This creates a data-loss hazard:

  1. Agent runs rtk ls to scan a project's setup state.
  2. Output shows .env.example but no .env.
  3. Agent concludes the project isn't configured and writes a fresh .env from the template.
  4. Real production secrets (DB passwords, API keys) are clobbered.

A user reproduced this directly:

$ touch .env
$ rtk ls
.claude/
demo-agents/
README.md  2.6K
notes.md  19.0K
slides.md  31.1K
Summary: 3 files, 2 dirs (3 .md)

.env is gone from the output. The agent has no way to know it exists.

Why this matters

.env is configuration the agent must reason about, not a build artifact like node_modules/, .git/, or target/. The other entries in NOISE_DIRS are regenerable; .env typically is not.

CONTRIBUTING.md's Correctness VS Token Savings principle applies directly:

When in doubt, preserve correctness.

A few tokens for one filename are cheap. Restoring rotated production credentials is not.

Fix

Remove .env from NOISE_DIRS. Sibling entries .env.local, .env.production, .env.example were never matched (the filter uses exact equality), so behavior for those is unchanged — they were already visible. This change only restores .env itself.

Test

Adds test_compact_preserves_dotenv covering .env, .env.local, and .env.example to lock in the expected behavior.

running 19 tests
test result: ok. 19 passed; 0 failed

Scope

Intentionally narrow. Does not touch:

Just .env. One line in constants, one regression test.

`.env` was listed in NOISE_DIRS, so `rtk ls` silently dropped it
unless `-a` was passed. This is a data-loss hazard: an agent that
scans a project to determine setup state sees no `.env`, assumes
the project is unconfigured, and writes a fresh template — clobbering
real production secrets.

`.env` is configuration, not a build artifact like `node_modules/`,
`.git/`, or `target/`. The "Correctness vs Token Savings" principle
in CONTRIBUTING.md applies: a few extra tokens are cheap; lost API
keys are not.

Adds a regression test covering `.env`, `.env.local`, and
`.env.example` to ensure they remain visible by default.
@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@pszymkowiak pszymkowiak added bug Something isn't working effort-small Quelques heures, 1 fichier filter-quality Filter produces incorrect/truncated signal good first issue Good for newcomers labels Apr 25, 2026
@pszymkowiak
Copy link
Copy Markdown
Collaborator

[w] wshm · Automated triage by AI

📊 Automated PR Analysis

🐛 Type bug-fix
🟢 Risk low

Summary

Removes .env from the NOISE_DIRS list so that rtk ls no longer silently hides .env files in its default output. This prevents agents from mistakenly concluding a project is unconfigured and overwriting real .env files containing production secrets. A regression test is added to lock in the corrected behavior.

Review Checklist

  • Tests present
  • Breaking change
  • Docs updated

Analyzed automatically by wshm · This is an automated analysis, not a human review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working effort-small Quelques heures, 1 fichier filter-quality Filter produces incorrect/truncated signal good first issue Good for newcomers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants