Skip to content

Commit f01ea69

Browse files
chore: final cleanup, and updates in tests
1 parent 212a62d commit f01ea69

File tree

5 files changed

+21
-36
lines changed

5 files changed

+21
-36
lines changed

registry/coder-labs/modules/codex/README.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Run Codex CLI in your workspace to access OpenAI's models through the Codex inte
1313
```tf
1414
module "codex" {
1515
source = "registry.coder.com/coder-labs/codex/coder"
16-
version = "1.0.2"
16+
version = "1.1.0"
1717
agent_id = coder_agent.example.id
1818
openai_api_key = var.openai_api_key
1919
folder = "/home/coder/project"
@@ -33,7 +33,7 @@ module "codex" {
3333
module "codex" {
3434
count = data.coder_workspace.me.start_count
3535
source = "registry.coder.com/coder-labs/codex/coder"
36-
version = "1.0.2"
36+
version = "1.1.0"
3737
agent_id = coder_agent.example.id
3838
openai_api_key = "..."
3939
install_codex = true
@@ -62,13 +62,13 @@ module "coder-login" {
6262
}
6363
6464
module "codex" {
65-
source = "registry.coder.com/coder-labs/codex/coder"
66-
version = "1.0.2"
67-
agent_id = coder_agent.example.id
68-
openai_api_key = "..."
69-
ai_prompt = data.coder_parameter.ai_prompt.value
70-
folder = "/home/coder/project"
71-
65+
source = "registry.coder.com/coder-labs/codex/coder"
66+
version = "1.1.0"
67+
agent_id = coder_agent.example.id
68+
openai_api_key = "..."
69+
ai_prompt = data.coder_parameter.ai_prompt.value
70+
folder = "/home/coder/project"
71+
7272
# Custom configuration for full auto mode
7373
base_config_toml = <<-EOT
7474
approval_policy = "never"
@@ -103,6 +103,7 @@ writable_roots = ["$/path/to/your/folder$", "$HOME/.codex"]
103103
```
104104

105105
The default configuration allows writing to only two specific directories:
106+
106107
- Your specified `folder` (working directory)
107108
- `$HOME/.codex` (for configuration files like AGENTS.md)
108109

@@ -115,7 +116,7 @@ For custom Codex configuration, use `base_config_toml` and/or `additional_mcp_se
115116
```tf
116117
module "codex" {
117118
source = "registry.coder.com/coder-labs/codex/coder"
118-
version = "1.0.2"
119+
version = "1.1.0"
119120
# ... other variables ...
120121
121122
# Override default configuration

registry/coder-labs/modules/codex/main.test.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ describe("codex", async () => {
143143
id,
144144
"/home/coder/.codex-module/agentapi-start.log",
145145
);
146-
expect(resp).toContain("openai_api_key provided !");
146+
expect(resp).toContain("OpenAI API Key: Provided");
147147
});
148148

149149
test("pre-post-install-scripts", async () => {
@@ -271,7 +271,7 @@ describe("codex", async () => {
271271

272272
// Check default base config
273273
expect(resp).toContain("sandbox_mode = \"workspace-write\"");
274-
expect(resp).toContain("approval_policy = \"on-request\"");
274+
expect(resp).toContain("approval_policy = \"never\"");
275275
expect(resp).toContain("[sandbox_workspace_write]");
276276
expect(resp).toContain("network_access = true");
277277

@@ -305,6 +305,7 @@ describe("codex", async () => {
305305
`.trim();
306306
const pre_install_script = dedent`
307307
#!/bin/bash
308+
mkdir -p /home/coder/.codex
308309
echo -e "${prompt_3}" >> /home/coder/.codex/AGENTS.md
309310
`.trim();
310311

@@ -350,7 +351,11 @@ describe("codex", async () => {
350351
});
351352

352353
test("start-without-prompt", async () => {
353-
const { id } = await setup();
354+
const { id } = await setup({
355+
moduleVariables: {
356+
codex_system_prompt: "", // Explicitly disable system prompt
357+
},
358+
});
354359
await execModuleScript(id);
355360
const prompt = await execContainer(id, [
356361
"ls",

registry/coder-labs/modules/codex/main.tf

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,9 @@ variable "ai_prompt" {
110110
variable "codex_system_prompt" {
111111
type = string
112112
description = "System instructions written to AGENTS.md in the ~/.codex directory"
113-
default = ""
113+
default = "You are a helpful coding assistant. Start every response with `Codex says:`"
114114
}
115115

116-
117-
118116
resource "coder_env" "openai_api_key" {
119117
agent_id = var.agent_id
120118
name = "OPENAI_API_KEY"

registry/coder-labs/modules/codex/scripts/install.sh

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ source "$HOME"/.bashrc
33

44
BOLD='\033[0;1m'
55

6-
# Function to check if a command exists
76
command_exists() {
87
command -v "$1" > /dev/null 2>&1
98
}
@@ -28,7 +27,6 @@ echo "======================================"
2827
set +o nounset
2928

3029
function install_node() {
31-
# borrowed from claude-code module
3230
if ! command_exists npm; then
3331
printf "npm not found, checking for Node.js installation...\n"
3432
if ! command_exists node; then
@@ -57,24 +55,18 @@ function install_node() {
5755

5856
function install_codex() {
5957
if [ "${ARG_INSTALL}" = "true" ]; then
60-
# we need node to install and run codex-cli
6158
install_node
6259

63-
# If nvm does not exist, we will create a global npm directory (this os to prevent the possibility of EACCESS issues on npm -g)
6460
if ! command_exists nvm; then
6561
printf "which node: %s\n" "$(which node)"
6662
printf "which npm: %s\n" "$(which npm)"
6763

68-
# Create a directory for global packages
6964
mkdir -p "$HOME"/.npm-global
7065

71-
# Configure npm to use it
7266
npm config set prefix "$HOME/.npm-global"
7367

74-
# Add to PATH for current session
7568
export PATH="$HOME/.npm-global/bin:$PATH"
7669

77-
# Add to shell profile for future sessions
7870
if ! grep -q "export PATH=$HOME/.npm-global/bin:\$PATH" ~/.bashrc; then
7971
echo "export PATH=$HOME/.npm-global/bin:\$PATH" >> ~/.bashrc
8072
fi
@@ -91,7 +83,6 @@ function install_codex() {
9183
fi
9284
}
9385

94-
# Write minimal default configuration
9586
write_minimal_default_config() {
9687
local config_path="$1"
9788
cat << EOF > "$config_path"
@@ -107,7 +98,6 @@ writable_roots = ["${ARG_CODEX_START_DIRECTORY}", "$HOME/.codex"]
10798
EOF
10899
}
109100

110-
# Append MCP servers section
111101
append_mcp_servers_section() {
112102
local config_path="$1"
113103

@@ -129,12 +119,10 @@ EOF
129119
fi
130120
}
131121

132-
# Main configuration function
133122
function populate_config_toml() {
134123
CONFIG_PATH="$HOME/.codex/config.toml"
135124
mkdir -p "$(dirname "$CONFIG_PATH")"
136125

137-
# Step 1: Write base config (user-provided or minimal default)
138126
if [ -n "$ARG_BASE_CONFIG_TOML" ]; then
139127
printf "Using provided base configuration\n"
140128
echo "$ARG_BASE_CONFIG_TOML" > "$CONFIG_PATH"
@@ -143,28 +131,23 @@ function populate_config_toml() {
143131
write_minimal_default_config "$CONFIG_PATH"
144132
fi
145133

146-
# Step 2: Always append complete MCP servers section
147134
append_mcp_servers_section "$CONFIG_PATH"
148135
}
149136

150137
function add_instruction_prompt_if_exists() {
151138
if [ -n "${ARG_CODEX_INSTRUCTION_PROMPT:-}" ]; then
152-
# Create AGENTS.md in .codex directory instead of polluting the working directory
153139
AGENTS_PATH="$HOME/.codex/AGENTS.md"
154140
printf "Creating AGENTS.md in .codex directory: %s\\n" "${AGENTS_PATH}"
155141

156-
# Ensure .codex directory exists
157142
mkdir -p "$HOME/.codex"
158143

159-
# Check if AGENTS.md contains the instruction prompt already
160-
if [ -f "${AGENTS_PATH}" ] && grep -Fxq "${ARG_CODEX_INSTRUCTION_PROMPT}" "${AGENTS_PATH}"; then
144+
if [ -f "${AGENTS_PATH}" ] && grep -Fq "${ARG_CODEX_INSTRUCTION_PROMPT}" "${AGENTS_PATH}"; then
161145
printf "AGENTS.md already contains the instruction prompt. Skipping append.\n"
162146
else
163147
printf "Appending instruction prompt to AGENTS.md in .codex directory\n"
164148
echo -e "\n${ARG_CODEX_INSTRUCTION_PROMPT}" >> "${AGENTS_PATH}"
165149
fi
166150

167-
# Ensure the working directory exists for Codex to run in
168151
if [ ! -d "${ARG_CODEX_START_DIRECTORY}" ]; then
169152
printf "Creating start directory '%s'\\n" "${ARG_CODEX_START_DIRECTORY}"
170153
mkdir -p "${ARG_CODEX_START_DIRECTORY}" || {
@@ -177,7 +160,6 @@ function add_instruction_prompt_if_exists() {
177160
fi
178161
}
179162

180-
# Install Codex
181163
install_codex
182164
codex --version
183165
populate_config_toml

registry/coder-labs/modules/codex/scripts/start.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#!/bin/bash
22

3-
# Load shell environment
43
source "$HOME"/.bashrc
54
set -o errexit
65
set -o pipefail

0 commit comments

Comments
 (0)