feat(core): disable ANSI and VT output in AI agent environments#899
feat(core): disable ANSI and VT output in AI agent environments#899
Conversation
Deploying rstest with
|
| Latest commit: |
80cb0e8
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://f38c122b.rstest.pages.dev |
| Branch Preview URL: | https://agent-ansi.rstest.pages.dev |
9d9c480 to
f84bac3
Compare
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f84bac3c48
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
Pull request overview
This PR aims to suppress ANSI colors and VT control sequences (e.g., spinner cursor control / clear-screen) when running under detected AI agent environments, reducing noisy output and token usage.
Changes:
- Introduces an agent-aware
isNoAnsi()gate and routescolorusage through a runtime-configuredpicocolorsinstance. - Adds local AI agent environment detection (replacing
@vercel/detect-agent) and initializes agent-related env vars. - Updates reporter/worker/CLI paths and adds e2e coverage for “no ANSI in agent env” behavior.
Reviewed changes
Copilot reviewed 26 out of 27 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| scripts/dictionary.txt | Adds “opencode” to spellcheck dictionary. |
| pnpm-lock.yaml | Removes @vercel/detect-agent, adds yn. |
| packages/core/src/utils/testFiles.ts | Switches color import to the logger-provided color instance. |
| packages/core/src/utils/logger.ts | Adds isNoAnsi(), runtime createColors() instance, and disables VT behavior when isNoAnsi(). |
| packages/core/src/utils/index.ts | Re-exports new agent utilities. |
| packages/core/src/utils/helper.ts | Stops re-exporting picocolors; pulls color from logger. |
| packages/core/src/utils/getSetupFiles.ts | Switches color import to logger instance. |
| packages/core/src/utils/error.ts | Switches color import to logger instance. |
| packages/core/src/utils/agent/index.ts | Adds agent env init helpers and re-exports determineAgent. |
| packages/core/src/utils/agent/detectAgent.ts | Adds in-repo agent detection implementation (ported from Vercel). |
| packages/core/src/runtime/worker/index.ts | Switches color import to logger instance. |
| packages/core/src/runtime/worker/globalSetupWorker.ts | Switches color import to logger instance. |
| packages/core/src/runtime/worker/console.ts | Switches color import to logger instance. |
| packages/core/src/reporter/index.ts | Disables interactive status renderer when isNoAnsi() is true. |
| packages/core/src/pool/index.ts | Forces FORCE_COLOR=0 for workers when isNoAnsi() is true. |
| packages/core/src/core/restart.ts | Avoids VT clear-screen behavior when isNoAnsi() is true. |
| packages/core/src/core/globalSetup.ts | Sets FORCE_COLOR for global setup worker based on isNoAnsi(). |
| packages/core/src/cli/prepare.ts | Initializes agent env during CLI preparation. |
| packages/core/src/cli/init/browser/create.ts | Uses internal determineAgent and shared color. |
| packages/core/src/cli/index.ts | Removes a stray blank line. |
| packages/core/src/cli/commands.ts | Consolidates imports via utils and removes dynamic picocolors import. |
| packages/core/pnpm-test.txt | Adds a captured pnpm test output artifact containing ANSI/VT sequences. |
| packages/core/package.json | Drops @vercel/detect-agent, adds yn, adjusts dependency list ordering. |
| packages/core/LICENSE.md | Removes @vercel/detect-agent license block; adds yn license block. |
| e2e/reporter/index.test.ts | Adjusts reporter e2e invocations and excludes ANSI fixture in one case. |
| e2e/reporter/fixtures/ansi/index.test.ts | Adds failing snapshot fixture used to exercise snapshot diff output. |
| e2e/reporter/ansi.test.ts | Adds e2e test intended to assert “no ANSI under agent env”. |
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
TODO: in agent, it's always not marked as TTY, we need to remove some code and only preserve the snapshot diff part. |
Summary
this PR will: force remove ANSI and VT control for all scenes (snapshot diff and reporter) for agent env.
this could heavily reduce the token cost with default reporter and a pre-step for our agent friend MD reporter.
see the difference by running
pnpm testcommand in Rstest repository, reduced 90% prompt token.Related Links
Checklist