Skip to content

feat(core): disable ANSI and VT output in AI agent environments#899

Merged
fi3ework merged 1 commit intomainfrom
agent-ansi
Jan 23, 2026
Merged

feat(core): disable ANSI and VT output in AI agent environments#899
fi3ework merged 1 commit intomainfrom
agent-ansi

Conversation

@fi3ework
Copy link
Copy Markdown
Member

@fi3ework fi3ework commented Jan 23, 2026

Summary

  • tested on codex and opencode: no ANSI for test report, but still ANSI for snapshot mismatch diff.

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 test command in Rstest repository, reduced 90% prompt token.

image

Related Links

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages bot commented Jan 23, 2026

Deploying rstest with  Cloudflare Pages  Cloudflare Pages

Latest commit: 80cb0e8
Status: ✅  Deploy successful!
Preview URL: https://f38c122b.rstest.pages.dev
Branch Preview URL: https://agent-ansi.rstest.pages.dev

View logs

@fi3ework fi3ework force-pushed the agent-ansi branch 3 times, most recently from 9d9c480 to f84bac3 Compare January 23, 2026 05:24
@fi3ework
Copy link
Copy Markdown
Member Author

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

@fi3ework fi3ework marked this pull request as ready for review January 23, 2026 06:41
Copilot AI review requested due to automatic review settings January 23, 2026 06:41
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 routes color usage through a runtime-configured picocolors instance.
  • 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.

@fi3ework fi3ework enabled auto-merge (squash) January 23, 2026 08:58
@fi3ework fi3ework merged commit 5bde6b3 into main Jan 23, 2026
10 checks passed
@fi3ework fi3ework deleted the agent-ansi branch January 23, 2026 09:06
@fi3ework
Copy link
Copy Markdown
Member Author

TODO: in agent, it's always not marked as TTY, we need to remove some code and only preserve the snapshot diff part.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants