Skip to content

fix: Model behavior, not detecting the correct environment #688

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

PramaYudhistira
Copy link
Contributor

@PramaYudhistira PramaYudhistira commented Apr 26, 2025

Fix agent behavior, not detecting PowerShell and seeing an empty directory

What's Changed

  • This PR attempts to fix agent behavior where it is not detecting the correct environment. The agent would incorrectly detect that it is running on a Linux environment and start running Linux commands, even though it is running on Windows PowerShell. The agent would then therefore not detect the current working directory. So this change fixes this problem and also presents the correct environment on the terminal header.

Why

  • Previously, the model would not detect any directory whatsoever especially on Windows PowerShell, and incorrectly running Linux commands on PowerShell, resulting in viewing an empty directory.

  • In fact, the model thinks it is living inside a Linux environment

image

  • Particularly on issue #413 it is not detecting anything in a non-empty directory and cannot run any commands.

How

  • By adding context to the agent on which environments it is in and how to handle the different environments, it will correctly detect and run commands that work on all terminals.

Result

  • Agent now properly detects that it is in the correct environments and the environment is now displayed. Instead of seeing an "empty directory" it finally sees what is going on inside the working directory

image

image

@PramaYudhistira PramaYudhistira force-pushed the detect-shell-fix branch 4 times, most recently from 7462e86 to 0c19cd7 Compare April 26, 2025 23:32
@PramaYudhistira PramaYudhistira changed the title added environment on terminal header and fixed agent behavior to dete… fix: Agent behavior to detect environment Apr 26, 2025
@PramaYudhistira PramaYudhistira changed the title fix: Agent behavior to detect environment fix: Agent behavior, not detecting the correct environment Apr 27, 2025
@NawidT
Copy link

NawidT commented Apr 27, 2025

Thanks for working on this, was wondering why codex wasn't recognizing. Really needed someone to fix this lol.

@PramaYudhistira PramaYudhistira changed the title fix: Agent behavior, not detecting the correct environment fix: Model behavior, not detecting the correct environment Apr 27, 2025
}) => {
const envName =
Copy link
Collaborator

Choose a reason for hiding this comment

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

The change to terminal-header.tsx is unrelated to the actual core fix in this PR to have the instructions depend on the environment. Would prefer if we revert this as we don't want to clutter the header with this information preferably.

const prefix = `You are operating as and within the Codex CLI, a terminal-based agentic coding assistant built by OpenAI. It wraps OpenAI models to enable natural language interaction with a local codebase. You are expected to be precise, safe, and helpful.

All commands should be formatted for: ${shellEnv}.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please move this at the end, below the "You MUST adhere to the following criteria" section


export interface ShellDetection {
shellOption?: boolean | string;
environment: string;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please make this an enum

import { parse } from "shell-quote";

export interface ShellDetection {
shellOption?: boolean | string;
Copy link
Collaborator

Choose a reason for hiding this comment

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

As far as I can tell this is not used. Please remove

@tibo-openai
Copy link
Collaborator

Thank you for the contribution! Left some comments that I would like to see addressed before taking another look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants