Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ Capability package downloads are constrained to the configured Backend origin. T

When a project task runs through the local executor, its task-level `CLAUDE_CONFIG_DIR` exposes both global `skills` and `plugins` directories and inherits non-sensitive plugin settings such as `enabledPlugins` and `extraKnownMarketplaces` from the local `~/.claude/settings.json`. This lets Claude Code load global Skills and Skills provided by Plugins. Sensitive model and token configuration is still injected through runtime environment variables and is not copied from global settings into the task directory.

Claude Code and Agno runtimes receive a task identity environment set. `WEGENT_TASK_ID` identifies the current Task, `AUTH_TOKEN` provides the per-turn bearer token for Backend API access, and `WEGENT_SKILL_IDENTITY_TOKEN` plus `WEGENT_SKILL_USER_NAME` identify task-scoped Skill operations. Codex uses a shared app-server process and does not receive task identity environment variables; code that needs task or turn identity should keep using Responses events, artifact metadata, or existing task/subtask protocol fields instead of environment variables. The executor does not inject `WEGENT_SUBTASK_ID` into these child runtimes.
Claude Code, Agno, and Codex task shells receive a task identity environment set. `WEGENT_TASK_ID` identifies the current Task, `AUTH_TOKEN` provides the per-turn bearer token for Backend API access, and `WEGENT_SKILL_IDENTITY_TOKEN` plus `WEGENT_SKILL_USER_NAME` identify task-scoped Skill operations. Claude Code and Agno receive the values through their child-process environments. Codex receives them through thread-scoped `shell_environment_policy.set.*` settings, so task identity never enters the shared app-server process environment and cannot leak across tasks. The executor does not inject `WEGENT_SUBTASK_ID` into these child runtimes.

When project mode calls Claude or Codex model APIs, the executor adds a `wecode-project: <project_id>` request header in the directly launched runtime context and fills source identity headers: `wecode-action: wegent`, `wecode-source: wegent-local`, and `wecode-executor: <runtime>`, where Claude Code uses `claudecode` and Codex uses `codex`. Claude Code local mode first merges existing `ANTHROPIC_CUSTOM_HEADERS` from the executor startup process environment and the runtime environment, then appends the project identity and writes the resulting header set to both `ANTHROPIC_CUSTOM_HEADERS` and `DEFAULT_HEADERS`/`default_headers`. This keeps the Claude Code child process and downstream model gateways on the same header set. Codex writes the header into provider `http_headers` for Wegent-managed provider configs, and also injects it for personal Codex config runs when the execution model explicitly names the provider.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ Plugin 上报必须包含其内部 Skill 列表。Executor 会扫描每个 Plugi

项目任务使用本地 executor 执行时,任务级 `CLAUDE_CONFIG_DIR` 会同时暴露全局 `skills` 和 `plugins` 目录,并从本机 `~/.claude/settings.json` 继承 `enabledPlugins`、`extraKnownMarketplaces` 等非敏感插件配置,使 Claude Code 能加载全局 Skill 以及 Plugin 内部提供的 Skill。模型、Token 等敏感配置仍通过运行时环境变量注入,不会从全局 settings 写入任务目录。

Claude Code 和 Agno 运行时内部会收到一组任务身份环境变量。`WEGENT_TASK_ID` 标识当前 Task,`AUTH_TOKEN` 提供本轮任务访问 Backend API 的 bearer token,`WEGENT_SKILL_IDENTITY_TOKEN` 和 `WEGENT_SKILL_USER_NAME` 用于任务内 Skill 操作的身份校验与展示。Codex 使用共享 app-server 进程,不注入任务身份环境变量;需要区分任务或轮次时,应继续使用 Responses 事件、artifact metadata 或已有 task/subtask 协议字段,而不是依赖环境变量。executor 不向这些子运行时注入 `WEGENT_SUBTASK_ID`。
Claude Code、Agno 运行时和 Codex 任务 shell 都会收到一组任务身份环境变量。`WEGENT_TASK_ID` 标识当前 Task,`AUTH_TOKEN` 提供本轮任务访问 Backend API 的 bearer token,`WEGENT_SKILL_IDENTITY_TOKEN` 和 `WEGENT_SKILL_USER_NAME` 用于任务内 Skill 操作的身份校验与展示。Claude Code 和 Agno 通过子进程环境注入;Codex 通过 thread 级 `shell_environment_policy.set.*` 注入,身份值不会进入共享 app-server 进程环境,避免跨任务泄漏。executor 不向这些子运行时注入 `WEGENT_SUBTASK_ID`。

项目模式下访问 Claude 或 Codex 模型 API 时,executor 会在直接启动的运行时上下文中加入 `wecode-project: <project_id>` 请求头,并补齐 `wecode-action: wegent`、`wecode-source: wegent-local`、`wecode-executor: <runtime>` 来源标识,其中 Claude Code 使用 `claudecode`,Codex 使用 `codex`。Claude Code 本地模式会先合并 executor 启动进程环境和运行时环境里已有的 `ANTHROPIC_CUSTOM_HEADERS`,再追加 project 标识,并同时写入 `ANTHROPIC_CUSTOM_HEADERS` 与 `DEFAULT_HEADERS`/`default_headers` 环境变量,保证直接 Claude Code 子进程和下游模型网关读取到一致的 header 集合;Codex 在 Wegent 管理 provider 配置时写入 provider 的 `http_headers`,使用个人 Codex 配置且显式指定 provider 时也会对该 provider 注入同一 project 请求头。

Expand Down
18 changes: 17 additions & 1 deletion executor/src/agents/codex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use tokio::{
};

use crate::{
agents::runtime_capabilities,
agents::{runtime_capabilities, task_identity::task_identity_env},
attachments::{process_prompt, AttachmentPromptProcessor, AttachmentRecord},
image_preprocessor::prepare_image_bytes_for_model,
logging::{log_executor_event, task_fields},
Expand Down Expand Up @@ -2004,6 +2004,9 @@ fn build_codex_launch_config(request: &ExecutionRequest) -> CodexLaunchConfig {
launch_config
.config_overrides
.push(shell_path_config_override());
launch_config
.config_overrides
.extend(task_identity_config_overrides(request));
Comment on lines +2007 to +2009

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Keep task credentials out of app-server arguments

In the regular AgentProcessEngine Codex path, run_codex_app_server_turn_with_cancel passes this launch_config to spawn_codex_app_server, which serializes every override into -c command-line arguments. Consequently, AUTH_TOKEN and WEGENT_SKILL_IDENTITY_TOKEN are exposed through process listings, /proc/*/cmdline, and process-monitoring telemetry for the lifetime of every Codex task. Keep these overrides exclusively in the thread JSON-RPC config, and filter them from the per-task process launch config as the persistent app-server path already does.

Useful? React with 👍 / 👎.

launch_config
.config_overrides
.extend(codex_runtime_default_config_overrides());
Expand Down Expand Up @@ -2127,6 +2130,19 @@ fn shell_path_config_override() -> String {
format!("shell_environment_policy.set.PATH={}", toml_value(&path))
}

fn task_identity_config_overrides(request: &ExecutionRequest) -> Vec<String> {
task_identity_env(request)
.into_iter()
.map(|(key, value)| {
format!(
"shell_environment_policy.set.{}={}",
toml_key_segment(&key),
toml_value(&value)
)
})
.collect()
}

fn codex_streaming_patch_config_overrides() -> Vec<String> {
vec![
CODEX_APPLY_PATCH_STREAMING_EVENTS_OVERRIDE.to_owned(),
Expand Down
49 changes: 36 additions & 13 deletions executor/src/agents/codex/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ fn required_loopback_hosts_are_merged_into_no_proxy() {
}

#[test]
fn codex_launch_config_does_not_forward_task_identity() {
fn codex_launch_config_forwards_task_identity_to_thread_only() {
let request = ExecutionRequest {
task_id: "task-525".to_owned(),
auth_token: Some("task-jwt".to_owned()),
Expand All @@ -810,18 +810,26 @@ fn codex_launch_config_does_not_forward_task_identity() {

assert!(!launch_config.env.contains_key("WEGENT_TASK_ID"));
assert!(!launch_config.env.contains_key("AUTH_TOKEN"));
assert!(config
.get("shell_environment_policy.set.WEGENT_TASK_ID")
.is_none());
assert!(config
.get("shell_environment_policy.set.AUTH_TOKEN")
.is_none());
assert!(config
.get("shell_environment_policy.set.WEGENT_SKILL_IDENTITY_TOKEN")
.is_none());
assert!(config
.get("shell_environment_policy.set.WEGENT_SKILL_USER_NAME")
.is_none());
assert!(!launch_config
.env
.contains_key("WEGENT_SKILL_IDENTITY_TOKEN"));
assert!(!launch_config.env.contains_key("WEGENT_SKILL_USER_NAME"));
assert_eq!(
config["shell_environment_policy.set.WEGENT_TASK_ID"],
"task-525"
);
assert_eq!(
config["shell_environment_policy.set.AUTH_TOKEN"],
"task-jwt"
);
assert_eq!(
config["shell_environment_policy.set.WEGENT_SKILL_IDENTITY_TOKEN"],
"skill-jwt"
);
assert_eq!(
config["shell_environment_policy.set.WEGENT_SKILL_USER_NAME"],
"alice"
);
}

#[test]
Expand All @@ -832,6 +840,10 @@ fn persistent_codex_app_server_launch_config_keeps_only_process_settings() {
"model_provider=wecode-openai".to_owned(),
"model_catalog_json=\"/tmp/wework-models.json\"".to_owned(),
"mcp_servers.wework.command=\"node\"".to_owned(),
"shell_environment_policy.set.WEGENT_TASK_ID=\"task-525\"".to_owned(),
"shell_environment_policy.set.AUTH_TOKEN=\"task-jwt\"".to_owned(),
"shell_environment_policy.set.WEGENT_SKILL_IDENTITY_TOKEN=\"skill-jwt\"".to_owned(),
"shell_environment_policy.set.WEGENT_SKILL_USER_NAME=\"alice\"".to_owned(),
],
model_provider: Some("wecode-openai".to_owned()),
effort: Some("high".to_owned()),
Expand All @@ -853,6 +865,17 @@ fn persistent_codex_app_server_launch_config_keeps_only_process_settings() {
.config_overrides
.iter()
.any(|value| value.starts_with("model_catalog_json=")));
for key in [
"WEGENT_TASK_ID",
"AUTH_TOKEN",
"WEGENT_SKILL_IDENTITY_TOKEN",
"WEGENT_SKILL_USER_NAME",
] {
assert!(!launch_config
.config_overrides
.iter()
.any(|value| value.starts_with(&format!("shell_environment_policy.set.{key}="))));
}
assert!(launch_config
.config_overrides
.contains(&"goals=true".to_owned()));
Expand Down
20 changes: 20 additions & 0 deletions executor/tests/codex_app_server_contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ async fn codex_app_server_engine_drives_thread_and_turn_over_json_rpc() {
let fake_codex = write_fake_codex(&log_path);
let engine = CodexAppServerEngine::new(fake_codex.display().to_string());
let request = ExecutionRequest {
task_id: "task-525".to_owned(),
auth_token: Some("task-jwt".to_owned()),
skill_identity_token: Some("skill-jwt".to_owned()),
user_name: Some("alice".to_owned()),
Comment on lines +33 to +36

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔒 Security & Privacy | 🟡 Minor | ⚡ Quick win

Avoid writing bearer-token values to the fake Codex log.

write_fake_codex appends every JSON-RPC request to log_path (Lines 863-864), so this test now persists the raw auth_token and skill_identity_token values. Keep the propagation check, but make the fake server validate or redact sensitive fields before logging.

As per coding guidelines, “never log tokens, API keys, or local authentication-file contents.”

Also applies to: 73-88

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@executor/tests/codex_app_server_contract.rs` around lines 33 - 36, Update
write_fake_codex so JSON-RPC requests are validated for the expected auth_token
and skill_identity_token values but those sensitive fields are redacted or
removed before being appended to log_path. Preserve the propagation assertions
in the test without persisting raw bearer-token values in the fake Codex log.

Source: Coding guidelines

prompt: json!("implement feature"),
bot: json!([{"shell_type": "ClaudeCode"}]),
model_config: json!({
Expand Down Expand Up @@ -66,6 +70,22 @@ async fn codex_app_server_engine_drives_thread_and_turn_over_json_rpc() {
assert_eq!(messages[2]["params"]["model"], "gpt-5");
assert_eq!(messages[2]["params"]["cwd"], "/tmp/wegent/project");
assert_eq!(messages[2]["params"]["permissions"], ":danger-full-access");
assert_eq!(
messages[2]["params"]["config"]["shell_environment_policy.set.WEGENT_TASK_ID"],
"task-525"
);
assert_eq!(
messages[2]["params"]["config"]["shell_environment_policy.set.AUTH_TOKEN"],
"task-jwt"
);
assert_eq!(
messages[2]["params"]["config"]["shell_environment_policy.set.WEGENT_SKILL_IDENTITY_TOKEN"],
"skill-jwt"
);
assert_eq!(
messages[2]["params"]["config"]["shell_environment_policy.set.WEGENT_SKILL_USER_NAME"],
"alice"
);
assert_eq!(messages[3]["method"], "turn/start");
assert_eq!(messages[3]["params"]["threadId"], "thread-1");
assert_eq!(messages[3]["params"]["model"], "gpt-5");
Expand Down
Loading