Lightweight coding agent that runs in your terminal
Rust
app-server: use permission ids and runtime workspace roots (#22611)
Michael Bolin8a5306ff88b8
diff --git a/codex-rs/analytics/src/analytics_client_tests.rs b/codex-rs/analytics/src/analytics_client_tests.rsindex 5b4a72229b..7b9ab4f9d6 100644--- a/codex-rs/analytics/src/analytics_client_tests.rs+++ b/codex-rs/analytics/src/analytics_client_tests.rs@@ -201,6 +201,7 @@ fn sample_thread_start_response(model_provider: "openai".to_string(),service_tier: None,cwd: test_path_buf("/tmp").abs(),+ runtime_workspace_roots: Vec::new(),instruction_sources: Vec::new(),approval_policy: AppServerAskForApproval::OnFailure,approvals_reviewer: AppServerApprovalsReviewer::User,@@ -257,6 +258,7 @@ fn sample_thread_resume_response_with_source(model_provider: "openai".to_string(),service_tier: None,cwd: test_path_buf("/tmp").abs(),+ runtime_workspace_roots: Vec::new(),instruction_sources: Vec::new(),approval_policy: AppServerAskForApproval::OnFailure,approvals_reviewer: AppServerApprovalsReviewer::User,diff --git a/codex-rs/analytics/src/client_tests.rs b/codex-rs/analytics/src/client_tests.rsindex 71c46d808a..885875346d 100644--- a/codex-rs/analytics/src/client_tests.rs+++ b/codex-rs/analytics/src/client_tests.rs@@ -153,6 +153,7 @@ fn sample_thread_start_response() -> ClientResponsePayload {model_provider: "openai".to_string(),service_tier: None,cwd: test_path_buf("/tmp").abs(),+ runtime_workspace_roots: Vec::new(),instruction_sources: Vec::new(),approval_policy: AppServerAskForApproval::OnFailure,approvals_reviewer: AppServerApprovalsReviewer::User,@@ -170,6 +171,7 @@ fn sample_thread_resume_response() -> ClientResponsePayload {model_provider: "openai".to_string(),service_tier: None,cwd: test_path_buf("/tmp").abs(),+ runtime_workspace_roots: Vec::new(),instruction_sources: Vec::new(),approval_policy: AppServerAskForApproval::OnFailure,approvals_reviewer: AppServerApprovalsReviewer::User,@@ -187,6 +189,7 @@ fn sample_thread_fork_response() -> ClientResponsePayload {model_provider: "openai".to_string(),service_tier: None,cwd: test_path_buf("/tmp").abs(),+ runtime_workspace_roots: Vec::new(),instruction_sources: Vec::new(),approval_policy: AppServerAskForApproval::OnFailure,approvals_reviewer: AppServerApprovalsReviewer::User,diff --git a/codex-rs/app-server-protocol/schema/json/ClientRequest.json b/codex-rs/app-server-protocol/schema/json/ClientRequest.jsonindex a6fe99b35e..f40d16feb6 100644--- a/codex-rs/app-server-protocol/schema/json/ClientRequest.json+++ b/codex-rs/app-server-protocol/schema/json/ClientRequest.json@@ -1850,31 +1850,6 @@}]},- "PermissionProfileModificationParams": {- "oneOf": [- {- "description": "Additional concrete directory that should be writable.",- "properties": {- "path": {- "$ref": "#/definitions/AbsolutePathBuf"- },- "type": {- "enum": [- "additionalWritableRoot"- ],- "title": "AdditionalWritableRootPermissionProfileModificationParamsType",- "type": "string"- }- },- "required": [- "path",- "type"- ],- "title": "AdditionalWritableRootPermissionProfileModificationParams",- "type": "object"- }- ]- },"PermissionProfileNetworkPermissions": {"properties": {"enabled": {@@ -1886,40 +1861,6 @@],"type": "object"},- "PermissionProfileSelectionParams": {- "oneOf": [- {- "description": "Select a named built-in or user-defined profile and optionally apply bounded modifications that Codex knows how to validate.",- "properties": {- "id": {- "type": "string"- },- "modifications": {- "items": {- "$ref": "#/definitions/PermissionProfileModificationParams"- },- "type": [- "array",- "null"- ]- },- "type": {- "enum": [- "profile"- ],- "title": "ProfilePermissionProfileSelectionParamsType",- "type": "string"- }- },- "required": [- "id",- "type"- ],- "title": "ProfilePermissionProfileSelectionParams",- "type": "object"- }- ]- },"Personality": {"enum": ["none",diff --git a/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.schemas.json b/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.schemas.jsonindex 603b08d343..e37c26881b 100644--- a/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.schemas.json+++ b/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.schemas.json@@ -11739,31 +11739,6 @@}]},- "PermissionProfileModificationParams": {- "oneOf": [- {- "description": "Additional concrete directory that should be writable.",- "properties": {- "path": {- "$ref": "#/definitions/v2/AbsolutePathBuf"- },- "type": {- "enum": [- "additionalWritableRoot"- ],- "title": "AdditionalWritableRootPermissionProfileModificationParamsType",- "type": "string"- }- },- "required": [- "path",- "type"- ],- "title": "AdditionalWritableRootPermissionProfileModificationParams",- "type": "object"- }- ]- },"PermissionProfileNetworkPermissions": {"properties": {"enabled": {@@ -11775,40 +11750,6 @@],"type": "object"},- "PermissionProfileSelectionParams": {- "oneOf": [- {- "description": "Select a named built-in or user-defined profile and optionally apply bounded modifications that Codex knows how to validate.",- "properties": {- "id": {- "type": "string"- },- "modifications": {- "items": {- "$ref": "#/definitions/v2/PermissionProfileModificationParams"- },- "type": [- "array",- "null"- ]- },- "type": {- "enum": [- "profile"- ],- "title": "ProfilePermissionProfileSelectionParamsType",- "type": "string"- }- },- "required": [- "id",- "type"- ],- "title": "ProfilePermissionProfileSelectionParams",- "type": "object"- }- ]- },"Personality": {"enum": ["none",diff --git a/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.v2.schemas.json b/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.v2.schemas.jsonindex 187650c913..653a1a5751 100644--- a/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.v2.schemas.json+++ b/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.v2.schemas.json@@ -8288,31 +8288,6 @@}]},- "PermissionProfileModificationParams": {- "oneOf": [- {- "description": "Additional concrete directory that should be writable.",- "properties": {- "path": {- "$ref": "#/definitions/AbsolutePathBuf"- },- "type": {- "enum": [- "additionalWritableRoot"- ],- "title": "AdditionalWritableRootPermissionProfileModificationParamsType",- "type": "string"- }- },- "required": [- "path",- "type"- ],- "title": "AdditionalWritableRootPermissionProfileModificationParams",- "type": "object"- }- ]- },"PermissionProfileNetworkPermissions": {"properties": {"enabled": {@@ -8324,40 +8299,6 @@],"type": "object"},- "PermissionProfileSelectionParams": {- "oneOf": [- {- "description": "Select a named built-in or user-defined profile and optionally apply bounded modifications that Codex knows how to validate.",- "properties": {- "id": {- "type": "string"- },- "modifications": {- "items": {- "$ref": "#/definitions/PermissionProfileModificationParams"- },- "type": [- "array",- "null"- ]- },- "type": {- "enum": [- "profile"- ],- "title": "ProfilePermissionProfileSelectionParamsType",- "type": "string"- }- },- "required": [- "id",- "type"- ],- "title": "ProfilePermissionProfileSelectionParams",- "type": "object"- }- ]- },"Personality": {"enum": ["none",diff --git a/codex-rs/app-server-protocol/schema/json/v2/ThreadForkParams.json b/codex-rs/app-server-protocol/schema/json/v2/ThreadForkParams.jsonindex 29d67403cd..102cfa0299 100644--- a/codex-rs/app-server-protocol/schema/json/v2/ThreadForkParams.json+++ b/codex-rs/app-server-protocol/schema/json/v2/ThreadForkParams.json@@ -1,10 +1,6 @@{"$schema": "http://json-schema.org/draft-07/schema#","definitions": {- "AbsolutePathBuf": {- "description": "A path that is guaranteed to be absolute and normalized (though it is not guaranteed to be canonicalized or exist on the filesystem).\n\nIMPORTANT: When deserializing an `AbsolutePathBuf`, a base path must be set using [AbsolutePathBufGuard::new]. If no base path is set, the deserialization will fail unless the path being deserialized is already absolute.",- "type": "string"- },"ApprovalsReviewer": {"description": "Configures who approval requests are routed to for review. Examples include sandbox escapes, blocked network access, MCP approval prompts, and ARC escalations. Defaults to `user`. `auto_review` uses a carefully prompted subagent to gather relevant context and apply a risk-based decision framework before approving or denying the request. The legacy value `guardian_subagent` is accepted for compatibility.","enum": [@@ -64,65 +60,6 @@}]},- "PermissionProfileModificationParams": {- "oneOf": [- {- "description": "Additional concrete directory that should be writable.",- "properties": {- "path": {- "$ref": "#/definitions/AbsolutePathBuf"- },- "type": {- "enum": [- "additionalWritableRoot"- ],- "title": "AdditionalWritableRootPermissionProfileModificationParamsType",- "type": "string"- }- },- "required": [- "path",- "type"- ],- "title": "AdditionalWritableRootPermissionProfileModificationParams",- "type": "object"- }- ]- },- "PermissionProfileSelectionParams": {- "oneOf": [- {- "description": "Select a named built-in or user-defined profile and optionally apply bounded modifications that Codex knows how to validate.",- "properties": {- "id": {- "type": "string"- },- "modifications": {- "items": {- "$ref": "#/definitions/PermissionProfileModificationParams"- },- "type": [- "array",- "null"- ]- },- "type": {- "enum": [- "profile"- ],- "title": "ProfilePermissionProfileSelectionParamsType",- "type": "string"- }- },- "required": [- "id",- "type"- ],- "title": "ProfilePermissionProfileSelectionParams",- "type": "object"- }- ]- },"SandboxMode": {"enum": ["read-only",diff --git a/codex-rs/app-server-protocol/schema/json/v2/ThreadResumeParams.json b/codex-rs/app-server-protocol/schema/json/v2/ThreadResumeParams.jsonindex 5f07fe0149..27674afc7b 100644--- a/codex-rs/app-server-protocol/schema/json/v2/ThreadResumeParams.json+++ b/codex-rs/app-server-protocol/schema/json/v2/ThreadResumeParams.json@@ -1,10 +1,6 @@{"$schema": "http://json-schema.org/draft-07/schema#","definitions": {- "AbsolutePathBuf": {- "description": "A path that is guaranteed to be absolute and normalized (though it is not guaranteed to be canonicalized or exist on the filesystem).\n\nIMPORTANT: When deserializing an `AbsolutePathBuf`, a base path must be set using [AbsolutePathBufGuard::new]. If no base path is set, the deserialization will fail unless the path being deserialized is already absolute.",- "type": "string"- },"ApprovalsReviewer": {"description": "Configures who approval requests are routed to for review. Examples include sandbox escapes, blocked network access, MCP approval prompts, and ARC escalations. Defaults to `user`. `auto_review` uses a carefully prompted subagent to gather relevant context and apply a risk-based decision framework before approving or denying the request. The legacy value `guardian_subagent` is accepted for compatibility.","enum": [@@ -298,65 +294,6 @@}]},- "PermissionProfileModificationParams": {- "oneOf": [- {- "description": "Additional concrete directory that should be writable.",- "properties": {- "path": {- "$ref": "#/definitions/AbsolutePathBuf"- },- "type": {- "enum": [- "additionalWritableRoot"- ],- "title": "AdditionalWritableRootPermissionProfileModificationParamsType",- "type": "string"- }- },- "required": [- "path",- "type"- ],- "title": "AdditionalWritableRootPermissionProfileModificationParams",- "type": "object"- }- ]- },- "PermissionProfileSelectionParams": {- "oneOf": [- {- "description": "Select a named built-in or user-defined profile and optionally apply bounded modifications that Codex knows how to validate.",- "properties": {- "id": {- "type": "string"- },- "modifications": {- "items": {- "$ref": "#/definitions/PermissionProfileModificationParams"- },- "type": [- "array",- "null"- ]- },- "type": {- "enum": [- "profile"- ],- "title": "ProfilePermissionProfileSelectionParamsType",- "type": "string"- }- },- "required": [- "id",- "type"- ],- "title": "ProfilePermissionProfileSelectionParams",- "type": "object"- }- ]- },"Personality": {"enum": ["none",diff --git a/codex-rs/app-server-protocol/schema/json/v2/ThreadStartParams.json b/codex-rs/app-server-protocol/schema/json/v2/ThreadStartParams.jsonindex 9a60049a61..99b25490ab 100644--- a/codex-rs/app-server-protocol/schema/json/v2/ThreadStartParams.json+++ b/codex-rs/app-server-protocol/schema/json/v2/ThreadStartParams.json@@ -90,65 +90,6 @@],"type": "object"},- "PermissionProfileModificationParams": {- "oneOf": [- {- "description": "Additional concrete directory that should be writable.",- "properties": {- "path": {- "$ref": "#/definitions/AbsolutePathBuf"- },- "type": {- "enum": [- "additionalWritableRoot"- ],- "title": "AdditionalWritableRootPermissionProfileModificationParamsType",- "type": "string"- }- },- "required": [- "path",- "type"- ],- "title": "AdditionalWritableRootPermissionProfileModificationParams",- "type": "object"- }- ]- },- "PermissionProfileSelectionParams": {- "oneOf": [- {- "description": "Select a named built-in or user-defined profile and optionally apply bounded modifications that Codex knows how to validate.",- "properties": {- "id": {- "type": "string"- },- "modifications": {- "items": {- "$ref": "#/definitions/PermissionProfileModificationParams"- },- "type": [- "array",- "null"- ]- },- "type": {- "enum": [- "profile"- ],- "title": "ProfilePermissionProfileSelectionParamsType",- "type": "string"- }- },- "required": [- "id",- "type"- ],- "title": "ProfilePermissionProfileSelectionParams",- "type": "object"- }- ]- },"Personality": {"enum": ["none",diff --git a/codex-rs/app-server-protocol/schema/json/v2/TurnStartParams.json b/codex-rs/app-server-protocol/schema/json/v2/TurnStartParams.jsonindex 1ef33d4301..086d3c6ed1 100644--- a/codex-rs/app-server-protocol/schema/json/v2/TurnStartParams.json+++ b/codex-rs/app-server-protocol/schema/json/v2/TurnStartParams.json@@ -114,65 +114,6 @@],"type": "string"},- "PermissionProfileModificationParams": {- "oneOf": [- {- "description": "Additional concrete directory that should be writable.",- "properties": {- "path": {- "$ref": "#/definitions/AbsolutePathBuf"- },- "type": {- "enum": [- "additionalWritableRoot"- ],- "title": "AdditionalWritableRootPermissionProfileModificationParamsType",- "type": "string"- }- },- "required": [- "path",- "type"- ],- "title": "AdditionalWritableRootPermissionProfileModificationParams",- "type": "object"- }- ]- },- "PermissionProfileSelectionParams": {- "oneOf": [- {- "description": "Select a named built-in or user-defined profile and optionally apply bounded modifications that Codex knows how to validate.",- "properties": {- "id": {- "type": "string"- },- "modifications": {- "items": {- "$ref": "#/definitions/PermissionProfileModificationParams"- },- "type": [- "array",- "null"- ]- },- "type": {- "enum": [- "profile"- ],- "title": "ProfilePermissionProfileSelectionParamsType",- "type": "string"- }- },- "required": [- "id",- "type"- ],- "title": "ProfilePermissionProfileSelectionParams",- "type": "object"- }- ]- },"Personality": {"enum": ["none",diff --git a/codex-rs/app-server-protocol/schema/typescript/v2/PermissionProfileModificationParams.ts b/codex-rs/app-server-protocol/schema/typescript/v2/PermissionProfileModificationParams.tsdeleted file mode 100644index c619edcea8..0000000000--- a/codex-rs/app-server-protocol/schema/typescript/v2/PermissionProfileModificationParams.ts+++ /dev/null@@ -1,6 +0,0 @@-// GENERATED CODE! DO NOT MODIFY BY HAND!--// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.-import type { AbsolutePathBuf } from "../AbsolutePathBuf";--export type PermissionProfileModificationParams = { "type": "additionalWritableRoot", path: AbsolutePathBuf, };diff --git a/codex-rs/app-server-protocol/schema/typescript/v2/PermissionProfileSelectionParams.ts b/codex-rs/app-server-protocol/schema/typescript/v2/PermissionProfileSelectionParams.tsdeleted file mode 100644index a415bd0028..0000000000--- a/codex-rs/app-server-protocol/schema/typescript/v2/PermissionProfileSelectionParams.ts+++ /dev/null@@ -1,6 +0,0 @@-// GENERATED CODE! DO NOT MODIFY BY HAND!--// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.-import type { PermissionProfileModificationParams } from "./PermissionProfileModificationParams";--export type PermissionProfileSelectionParams = { "type": "profile", id: string, modifications?: Array<PermissionProfileModificationParams> | null, };diff --git a/codex-rs/app-server-protocol/schema/typescript/v2/index.ts b/codex-rs/app-server-protocol/schema/typescript/v2/index.tsindex 0a6d868ad0..beb1973bb9 100644--- a/codex-rs/app-server-protocol/schema/typescript/v2/index.ts+++ b/codex-rs/app-server-protocol/schema/typescript/v2/index.ts@@ -257,9 +257,7 @@ export type { PatchChangeKind } from "./PatchChangeKind";export type { PermissionGrantScope } from "./PermissionGrantScope";export type { PermissionProfile } from "./PermissionProfile";export type { PermissionProfileFileSystemPermissions } from "./PermissionProfileFileSystemPermissions";-export type { PermissionProfileModificationParams } from "./PermissionProfileModificationParams";export type { PermissionProfileNetworkPermissions } from "./PermissionProfileNetworkPermissions";-export type { PermissionProfileSelectionParams } from "./PermissionProfileSelectionParams";export type { PermissionsRequestApprovalParams } from "./PermissionsRequestApprovalParams";export type { PermissionsRequestApprovalResponse } from "./PermissionsRequestApprovalResponse";export type { PlanDeltaNotification } from "./PlanDeltaNotification";diff --git a/codex-rs/app-server-protocol/src/protocol/common.rs b/codex-rs/app-server-protocol/src/protocol/common.rsindex 89f60f979b..e0cd330fff 100644--- a/codex-rs/app-server-protocol/src/protocol/common.rs+++ b/codex-rs/app-server-protocol/src/protocol/common.rs@@ -2296,6 +2296,7 @@ mod tests {model_provider: "openai".to_string(),service_tier: None,cwd,+ runtime_workspace_roots: Vec::new(),instruction_sources: vec![absolute_path("/tmp/AGENTS.md")],approval_policy: v2::AskForApproval::OnFailure,approvals_reviewer: v2::ApprovalsReviewer::User,@@ -2340,6 +2341,7 @@ mod tests {"modelProvider": "openai","serviceTier": null,"cwd": absolute_path_string("tmp"),+ "runtimeWorkspaceRoots": [],"instructionSources": [absolute_path_string("tmp/AGENTS.md")],"approvalPolicy": "on-failure","approvalsReviewer": "user",diff --git a/codex-rs/app-server-protocol/src/protocol/v2/permissions.rs b/codex-rs/app-server-protocol/src/protocol/v2/permissions.rsindex 0796ee4e89..faf264411e 100644--- a/codex-rs/app-server-protocol/src/protocol/v2/permissions.rs+++ b/codex-rs/app-server-protocol/src/protocol/v2/permissions.rs@@ -21,7 +21,9 @@ use codex_protocol::request_permissions::RequestPermissionProfile as CoreRequestuse codex_utils_absolute_path::AbsolutePathBuf;use schemars::JsonSchema;use serde::Deserialize;+use serde::Deserializer;use serde::Serialize;+use serde::Serializer;use std::num::NonZeroUsize;use std::path::PathBuf;use ts_rs::TS;@@ -456,31 +458,100 @@ impl From<ActivePermissionProfile> for CoreActivePermissionProfile {}}-#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema, TS)]-#[serde(tag = "type", rename_all = "camelCase")]-#[ts(tag = "type")]-#[ts(export_to = "v2/")]-pub enum PermissionProfileSelectionParams {- /// Select a named built-in or user-defined profile and optionally apply- /// bounded modifications that Codex knows how to validate.- #[serde(rename_all = "camelCase")]- #[ts(rename_all = "camelCase")]- Profile {- id: String,- #[ts(optional = nullable)]- modifications: Option<Vec<PermissionProfileModificationParams>>,- },+#[derive(Debug, Clone, PartialEq, Eq)]+pub struct PermissionProfileSelectionParams {+ id: String,+ legacy_additional_writable_roots: Vec<AbsolutePathBuf>,}-#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema, TS)]-#[serde(tag = "type", rename_all = "camelCase")]-#[ts(tag = "type")]-#[ts(export_to = "v2/")]-pub enum PermissionProfileModificationParams {- /// Additional concrete directory that should be writable.- #[serde(rename_all = "camelCase")]- #[ts(rename_all = "camelCase")]- AdditionalWritableRoot { path: AbsolutePathBuf },+impl PermissionProfileSelectionParams {+ pub fn new(id: impl Into<String>) -> Self {+ Self {+ id: id.into(),+ legacy_additional_writable_roots: Vec::new(),+ }+ }++ pub fn id(&self) -> &str {+ &self.id+ }++ pub fn into_id(self) -> String {+ self.id+ }++ pub fn legacy_additional_writable_roots(&self) -> &[AbsolutePathBuf] {+ &self.legacy_additional_writable_roots+ }+}++impl From<String> for PermissionProfileSelectionParams {+ fn from(id: String) -> Self {+ Self::new(id)+ }+}++impl Serialize for PermissionProfileSelectionParams {+ fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>+ where+ S: Serializer,+ {+ serializer.serialize_str(&self.id)+ }+}++impl<'de> Deserialize<'de> for PermissionProfileSelectionParams {+ fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>+ where+ D: Deserializer<'de>,+ {+ #[derive(Deserialize)]+ #[serde(untagged)]+ enum Wire {+ Id(String),+ LegacyProfile {+ #[serde(rename = "type")]+ _type: LegacyPermissionProfileSelectionType,+ id: String,+ #[serde(default)]+ modifications: Option<Vec<LegacyPermissionProfileModificationParams>>,+ },+ }++ #[derive(Deserialize)]+ #[serde(rename_all = "camelCase")]+ enum LegacyPermissionProfileSelectionType {+ Profile,+ }++ #[derive(Deserialize)]+ #[serde(tag = "type", rename_all = "camelCase")]+ enum LegacyPermissionProfileModificationParams {+ #[serde(rename_all = "camelCase")]+ AdditionalWritableRoot { path: AbsolutePathBuf },+ }++ match Wire::deserialize(deserializer)? {+ Wire::Id(id) => Ok(Self::new(id)),+ Wire::LegacyProfile {+ id, modifications, ..+ } => {+ let legacy_additional_writable_roots = modifications+ .unwrap_or_default()+ .into_iter()+ .map(|modification| match modification {+ LegacyPermissionProfileModificationParams::AdditionalWritableRoot {+ path,+ } => path,+ })+ .collect();+ Ok(Self {+ id,+ legacy_additional_writable_roots,+ })+ }+ }+ }}#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema, TS)]diff --git a/codex-rs/app-server-protocol/src/protocol/v2/tests.rs b/codex-rs/app-server-protocol/src/protocol/v2/tests.rsindex f32c483ec7..50058cb686 100644--- a/codex-rs/app-server-protocol/src/protocol/v2/tests.rs+++ b/codex-rs/app-server-protocol/src/protocol/v2/tests.rs@@ -655,6 +655,61 @@ fn permissions_request_approval_response_accepts_strict_auto_review() {assert_eq!(response.strict_auto_review, Some(true));}+#[test]+fn permission_profile_selection_accepts_legacy_object_shape() {+ let additional_root = absolute_path("additional-root");+ let params = json!({+ "permissions": {+ "type": "profile",+ "id": ":workspace",+ "modifications": [+ {+ "type": "additionalWritableRoot",+ "path": additional_root,+ }+ ],+ },+ });++ let start: ThreadStartParams =+ serde_json::from_value(params.clone()).expect("thread/start params deserialize");+ assert_legacy_permission_profile_selection(start.permissions, &additional_root);++ let resume: ThreadResumeParams = serde_json::from_value(json!({+ "threadId": "thread-1",+ "permissions": params["permissions"].clone(),+ }))+ .expect("thread/resume params deserialize");+ assert_legacy_permission_profile_selection(resume.permissions, &additional_root);++ let fork: ThreadForkParams = serde_json::from_value(json!({+ "threadId": "thread-1",+ "permissions": params["permissions"].clone(),+ }))+ .expect("thread/fork params deserialize");+ assert_legacy_permission_profile_selection(fork.permissions, &additional_root);++ let turn: TurnStartParams = serde_json::from_value(json!({+ "threadId": "thread-1",+ "input": [],+ "permissions": params["permissions"].clone(),+ }))+ .expect("turn/start params deserialize");+ assert_legacy_permission_profile_selection(turn.permissions, &additional_root);+}++fn assert_legacy_permission_profile_selection(+ selection: Option<PermissionProfileSelectionParams>,+ additional_root: &AbsolutePathBuf,+) {+ let selection = selection.expect("permissions should be present");+ assert_eq!(selection.id(), ":workspace");+ assert_eq!(+ selection.legacy_additional_writable_roots(),+ std::slice::from_ref(additional_root)+ );+}+#[test]fn fs_get_metadata_response_round_trips_minimal_fields() {let response = FsGetMetadataResponse {@@ -3473,6 +3528,7 @@ fn turn_start_params_preserve_explicit_null_service_tier() {responsesapi_client_metadata: None,environments: None,cwd: None,+ runtime_workspace_roots: None,approval_policy: None,approvals_reviewer: None,sandbox_policy: None,diff --git a/codex-rs/app-server-protocol/src/protocol/v2/thread.rs b/codex-rs/app-server-protocol/src/protocol/v2/thread.rsindex 458722b3a2..a3321436f6 100644--- a/codex-rs/app-server-protocol/src/protocol/v2/thread.rs+++ b/codex-rs/app-server-protocol/src/protocol/v2/thread.rs@@ -107,6 +107,11 @@ pub struct ThreadStartParams {pub service_tier: Option<Option<String>>,#[ts(optional = nullable)]pub cwd: Option<String>,+ /// Replace the thread's runtime workspace roots. Relative paths are+ /// resolved against the effective cwd for the thread.+ #[experimental("thread/start.runtimeWorkspaceRoots")]+ #[ts(optional = nullable)]+ pub runtime_workspace_roots: Option<Vec<PathBuf>>,#[experimental(nested)]#[ts(optional = nullable)]pub approval_policy: Option<AskForApproval>,@@ -116,10 +121,10 @@ pub struct ThreadStartParams {pub approvals_reviewer: Option<ApprovalsReviewer>,#[ts(optional = nullable)]pub sandbox: Option<SandboxMode>,- /// Named profile selection for this thread. Cannot be combined with- /// `sandbox`. Use bounded `modifications` for supported turn/thread- /// adjustments instead of replacing the full permissions profile.+ /// Named profile id for this thread. Cannot be combined with `sandbox`.#[experimental("thread/start.permissions")]+ #[schemars(with = "Option<String>")]+ #[ts(type = "string | null")]#[ts(optional = nullable)]pub permissions: Option<PermissionProfileSelectionParams>,#[ts(optional = nullable)]@@ -195,6 +200,11 @@ pub struct ThreadStartResponse {pub model_provider: String,pub service_tier: Option<String>,pub cwd: AbsolutePathBuf,+ /// Thread-scoped runtime workspace roots used to materialize+ /// `:workspace_roots`.+ #[experimental("thread/start.runtimeWorkspaceRoots")]+ #[serde(default)]+ pub runtime_workspace_roots: Vec<AbsolutePathBuf>,/// Instruction source files currently loaded for this thread.#[serde(default)]pub instruction_sources: Vec<AbsolutePathBuf>,@@ -264,6 +274,11 @@ pub struct ThreadResumeParams {pub service_tier: Option<Option<String>>,#[ts(optional = nullable)]pub cwd: Option<String>,+ /// Replace the thread's runtime workspace roots. Relative paths are+ /// resolved against the effective cwd for the thread.+ #[experimental("thread/resume.runtimeWorkspaceRoots")]+ #[ts(optional = nullable)]+ pub runtime_workspace_roots: Option<Vec<PathBuf>>,#[experimental(nested)]#[ts(optional = nullable)]pub approval_policy: Option<AskForApproval>,@@ -273,10 +288,11 @@ pub struct ThreadResumeParams {pub approvals_reviewer: Option<ApprovalsReviewer>,#[ts(optional = nullable)]pub sandbox: Option<SandboxMode>,- /// Named profile selection for the resumed thread. Cannot be combined- /// with `sandbox`. Use bounded `modifications` for supported thread- /// adjustments instead of replacing the full permissions profile.+ /// Named profile id for the resumed thread. Cannot be combined with+ /// `sandbox`.#[experimental("thread/resume.permissions")]+ #[schemars(with = "Option<String>")]+ #[ts(type = "string | null")]#[ts(optional = nullable)]pub permissions: Option<PermissionProfileSelectionParams>,#[ts(optional = nullable)]@@ -310,6 +326,11 @@ pub struct ThreadResumeResponse {pub model_provider: String,pub service_tier: Option<String>,pub cwd: AbsolutePathBuf,+ /// Thread-scoped runtime workspace roots used to materialize+ /// `:workspace_roots`.+ #[experimental("thread/resume.runtimeWorkspaceRoots")]+ #[serde(default)]+ pub runtime_workspace_roots: Vec<AbsolutePathBuf>,/// Instruction source files currently loaded for this thread.#[serde(default)]pub instruction_sources: Vec<AbsolutePathBuf>,@@ -370,6 +391,11 @@ pub struct ThreadForkParams {pub service_tier: Option<Option<String>>,#[ts(optional = nullable)]pub cwd: Option<String>,+ /// Replace the thread's runtime workspace roots. Relative paths are+ /// resolved against the effective cwd for the thread.+ #[experimental("thread/fork.runtimeWorkspaceRoots")]+ #[ts(optional = nullable)]+ pub runtime_workspace_roots: Option<Vec<PathBuf>>,#[experimental(nested)]#[ts(optional = nullable)]pub approval_policy: Option<AskForApproval>,@@ -379,10 +405,11 @@ pub struct ThreadForkParams {pub approvals_reviewer: Option<ApprovalsReviewer>,#[ts(optional = nullable)]pub sandbox: Option<SandboxMode>,- /// Named profile selection for the forked thread. Cannot be combined with- /// `sandbox`. Use bounded `modifications` for supported thread- /// adjustments instead of replacing the full permissions profile.+ /// Named profile id for the forked thread. Cannot be combined with+ /// `sandbox`.#[experimental("thread/fork.permissions")]+ #[schemars(with = "Option<String>")]+ #[ts(type = "string | null")]#[ts(optional = nullable)]pub permissions: Option<PermissionProfileSelectionParams>,#[ts(optional = nullable)]@@ -419,6 +446,11 @@ pub struct ThreadForkResponse {pub model_provider: String,pub service_tier: Option<String>,pub cwd: AbsolutePathBuf,+ /// Thread-scoped runtime workspace roots used to materialize+ /// `:workspace_roots`.+ #[experimental("thread/fork.runtimeWorkspaceRoots")]+ #[serde(default)]+ pub runtime_workspace_roots: Vec<AbsolutePathBuf>,/// Instruction source files currently loaded for this thread.#[serde(default)]pub instruction_sources: Vec<AbsolutePathBuf>,diff --git a/codex-rs/app-server-protocol/src/protocol/v2/turn.rs b/codex-rs/app-server-protocol/src/protocol/v2/turn.rsindex 61a09bfbf5..8f4cd04e2d 100644--- a/codex-rs/app-server-protocol/src/protocol/v2/turn.rs+++ b/codex-rs/app-server-protocol/src/protocol/v2/turn.rs@@ -64,6 +64,12 @@ pub struct TurnStartParams {/// Override the working directory for this turn and subsequent turns.#[ts(optional = nullable)]pub cwd: Option<PathBuf>,+ /// Replace the thread's runtime workspace roots for this turn and+ /// subsequent turns. Relative paths are resolved against the effective+ /// cwd for the turn.+ #[experimental("turn/start.runtimeWorkspaceRoots")]+ #[ts(optional = nullable)]+ pub runtime_workspace_roots: Option<Vec<PathBuf>>,/// Override the approval policy for this turn and subsequent turns.#[experimental(nested)]#[ts(optional = nullable)]@@ -75,11 +81,11 @@ pub struct TurnStartParams {/// Override the sandbox policy for this turn and subsequent turns.#[ts(optional = nullable)]pub sandbox_policy: Option<SandboxPolicy>,- /// Select a named permissions profile for this turn and subsequent turns.- /// Cannot be combined with `sandboxPolicy`. Use bounded `modifications`- /// for supported turn adjustments instead of replacing the full- /// permissions profile.+ /// Select a named permissions profile id for this turn and subsequent+ /// turns. Cannot be combined with `sandboxPolicy`.#[experimental("turn/start.permissions")]+ #[schemars(with = "Option<String>")]+ #[ts(type = "string | null")]#[ts(optional = nullable)]pub permissions: Option<PermissionProfileSelectionParams>,/// Override the model for this turn and subsequent turns.diff --git a/codex-rs/app-server/README.md b/codex-rs/app-server/README.mdindex bd7dd186fe..09c450614f 100644--- a/codex-rs/app-server/README.md+++ b/codex-rs/app-server/README.md@@ -130,10 +130,10 @@ Example with notification opt-out:## API Overview-- `thread/start` — create a new thread; emits `thread/started` (including the current `thread.status`) and auto-subscribes you to turn/item events for that thread. When the request includes a `cwd` and the resolved sandbox is `workspace-write` or full access, app-server also marks that project as trusted in the user `config.toml`. Pass `sessionStartSource: "clear"` when starting a replacement thread after clearing the current session so `SessionStart` hooks receive `source: "clear"` instead of the default `"startup"`. For permissions, prefer experimental `permissions` profile selection; the legacy `sandbox` shorthand is still accepted but cannot be combined with `permissions`. Experimental `environments` selects the sticky execution environments for turns on the thread; omit it to use the server default, pass `[]` to disable environments, or pass explicit environment ids with per-environment `cwd`.+- `thread/start` — create a new thread; emits `thread/started` (including the current `thread.status`) and auto-subscribes you to turn/item events for that thread. When the request includes a `cwd` and the resolved sandbox is `workspace-write` or full access, app-server also marks that project as trusted in the user `config.toml`. Pass `sessionStartSource: "clear"` when starting a replacement thread after clearing the current session so `SessionStart` hooks receive `source: "clear"` instead of the default `"startup"`. Experimental `runtimeWorkspaceRoots` replaces the thread-scoped runtime workspace roots used to materialize `:workspace_roots`; relative paths resolve against the effective thread cwd. For permissions, prefer experimental `permissions` profile selection by id; the legacy `sandbox` shorthand is still accepted but cannot be combined with `permissions`. Experimental `environments` selects the sticky execution environments for turns on the thread; omit it to use the server default, pass `[]` to disable environments, or pass explicit environment ids with per-environment `cwd`.- `thread/resume` — reopen an existing thread by id so subsequent `turn/start` calls append to it. Accepts the same permission override rules as `thread/start`.- `thread/fork` — fork an existing thread into a new thread id by copying the stored history; if the source thread is currently mid-turn, the fork records the same interruption marker as `turn/interrupt` instead of inheriting an unmarked partial turn suffix. The returned `thread.forkedFromId` points at the source thread when known. Accepts `ephemeral: true` for an in-memory temporary fork, emits `thread/started` (including the current `thread.status`), and auto-subscribes you to turn/item events for the new thread. Experimental clients can pass `excludeTurns: true` when they plan to page fork history via `thread/turns/list` instead of receiving the full turn array immediately. Accepts the same permission override rules as `thread/start`.-- `thread/start`, `thread/resume`, and `thread/fork` responses include the legacy `sandbox` compatibility projection. Experimental clients can read response `permissionProfile` for the exact active runtime permissions and `activePermissionProfile` for the named or implicit built-in profile identity/provenance when known.+- `thread/start`, `thread/resume`, and `thread/fork` responses include the legacy `sandbox` compatibility projection. Experimental clients can read `runtimeWorkspaceRoots` for the thread-scoped runtime roots, `permissionProfile` for the exact active runtime permissions, and `activePermissionProfile` for the named or implicit built-in profile identity/provenance when known.- `thread/list` — page through stored rollouts; supports cursor-based pagination and optional `modelProviders`, `sourceKinds`, `archived`, `cwd`, and `searchTerm` filters. Each returned `thread` includes `status` (`ThreadStatus`), defaulting to `notLoaded` when the thread is not currently loaded.- `thread/loaded/list` — list the thread ids currently loaded in memory.- `thread/read` — read a stored thread by id without resuming it; optionally include turns via `includeTurns`. The returned `thread` includes `status` (`ThreadStatus`), defaulting to `notLoaded` when the thread is not currently loaded.@@ -156,7 +156,7 @@ Example with notification opt-out:- `thread/shellCommand` — run a user-initiated `!` shell command against a thread; this runs unsandboxed with full access rather than inheriting the thread sandbox policy. Returns `{}` immediately while progress streams through standard turn/item notifications and any active turn receives the formatted output in its message stream.- `thread/backgroundTerminals/clean` — terminate all running background terminals for a thread (experimental; requires `capabilities.experimentalApi`); returns `{}` when the cleanup request is accepted.- `thread/rollback` — drop the last N turns from the agent’s in-memory context and persist a rollback marker in the rollout so future resumes see the pruned history; returns the updated `thread` (with `turns` populated) on success.-- `turn/start` — add user input to a thread and begin Codex generation; responds with the initial `turn` object and streams `turn/started`, `item/*`, and `turn/completed` notifications. Prefer experimental `permissions` profile selection for permission overrides; the legacy `sandboxPolicy` field is still accepted but cannot be combined with `permissions`. For `collaborationMode`, `settings.developer_instructions: null` means "use built-in instructions for the selected mode".+- `turn/start` — add user input to a thread and begin Codex generation; responds with the initial `turn` object and streams `turn/started`, `item/*`, and `turn/completed` notifications. Experimental `runtimeWorkspaceRoots` replaces the thread-scoped runtime workspace roots used to materialize `:workspace_roots`; relative paths resolve against the effective turn cwd. Prefer experimental `permissions` profile selection by id for permission overrides; the legacy `sandboxPolicy` field is still accepted but cannot be combined with `permissions`. For `collaborationMode`, `settings.developer_instructions: null` means "use built-in instructions for the selected mode".- `thread/inject_items` — append raw Responses API items to a loaded thread’s model-visible history without starting a user turn; returns `{}` on success.- `turn/steer` — add user input to an already in-flight regular turn without starting a new turn; returns the active `turnId` that accepted the input. Review and manual compaction turns reject `turn/steer`.- `turn/interrupt` — request cancellation of an in-flight turn by `(thread_id, turn_id)`; success is an empty `{}` response and the turn finishes with `status: "interrupted"`.@@ -236,7 +236,9 @@ Start a fresh thread when you need a new Codex conversation."approvalPolicy": "never","sandbox": "workspaceWrite",// Prefer experimental profile selection:- // "permissions": { "type": "profile", "id": ":workspace" }+ // "permissions": ":workspace"+ // Experimental runtime roots for :workspace_roots materialization:+ // "runtimeWorkspaceRoots": ["/Users/me/project", "/Users/me/openai"],// Do not send both "sandbox" and "permissions"."personality": "friendly","serviceName": "my_app_server_client", // optional metrics tag (`service_name`)@@ -649,7 +651,9 @@ You can optionally specify config overrides on the new turn. If specified, these"networkAccess": true},// Prefer experimental profile selection:- // "permissions": { "type": "profile", "id": ":workspace" }+ // "permissions": ":workspace"+ // Experimental runtime roots for :workspace_roots materialization:+ // "runtimeWorkspaceRoots": ["/Users/me/project", "/Users/me/openai"],// Do not send both "sandboxPolicy" and "permissions"."model": "gpt-5.1-codex","effort": "medium",diff --git a/codex-rs/app-server/src/message_processor_tracing_tests.rs b/codex-rs/app-server/src/message_processor_tracing_tests.rsindex c955d06ba2..a9625d3086 100644--- a/codex-rs/app-server/src/message_processor_tracing_tests.rs+++ b/codex-rs/app-server/src/message_processor_tracing_tests.rs@@ -659,6 +659,7 @@ async fn turn_start_jsonrpc_span_parents_core_turn_spans() -> Result<()> {}],responsesapi_client_metadata: None,cwd: None,+ runtime_workspace_roots: None,approval_policy: None,sandbox_policy: None,permissions: None,diff --git a/codex-rs/app-server/src/request_processors.rs b/codex-rs/app-server/src/request_processors.rsindex 2c20c1816a..611678a713 100644--- a/codex-rs/app-server/src/request_processors.rs+++ b/codex-rs/app-server/src/request_processors.rs@@ -103,7 +103,6 @@ use codex_app_server_protocol::MockExperimentalMethodParams;use codex_app_server_protocol::MockExperimentalMethodResponse;use codex_app_server_protocol::ModelListParams;use codex_app_server_protocol::ModelListResponse;-use codex_app_server_protocol::PermissionProfileModificationParams;use codex_app_server_protocol::PermissionProfileSelectionParams;use codex_app_server_protocol::PluginDetail;use codex_app_server_protocol::PluginInstallParams;diff --git a/codex-rs/app-server/src/request_processors/thread_lifecycle.rs b/codex-rs/app-server/src/request_processors/thread_lifecycle.rsindex 7dab206d85..c64066ee93 100644--- a/codex-rs/app-server/src/request_processors/thread_lifecycle.rs+++ b/codex-rs/app-server/src/request_processors/thread_lifecycle.rs@@ -604,6 +604,7 @@ pub(super) async fn handle_pending_thread_resume_request(permission_profile,active_permission_profile,cwd,+ workspace_roots,reasoning_effort,..} = pending.config_snapshot;@@ -620,6 +621,7 @@ pub(super) async fn handle_pending_thread_resume_request(model_provider: model_provider_id,service_tier,cwd,+ runtime_workspace_roots: workspace_roots,instruction_sources,approval_policy: approval_policy.into(),approvals_reviewer: approvals_reviewer.into(),diff --git a/codex-rs/app-server/src/request_processors/thread_processor.rs b/codex-rs/app-server/src/request_processors/thread_processor.rsindex 85b2e57571..3038feeef1 100644--- a/codex-rs/app-server/src/request_processors/thread_processor.rs+++ b/codex-rs/app-server/src/request_processors/thread_processor.rs@@ -59,6 +59,25 @@ fn collect_resume_override_mismatches());}}+ if let Some(requested_runtime_workspace_roots) = request.runtime_workspace_roots.as_ref() {+ let base_cwd = request+ .cwd+ .as_deref()+ .map(|cwd| {+ AbsolutePathBuf::resolve_path_against_base(cwd, config_snapshot.cwd.as_path())+ })+ .unwrap_or_else(|| config_snapshot.cwd.clone());+ let requested_runtime_workspace_roots = requested_runtime_workspace_roots+ .iter()+ .map(|path| AbsolutePathBuf::resolve_path_against_base(path, base_cwd.as_path()))+ .collect::<Vec<_>>();+ if requested_runtime_workspace_roots != config_snapshot.workspace_roots {+ mismatch_details.push(format!(+ "runtime_workspace_roots requested={requested_runtime_workspace_roots:?} active={:?}",+ config_snapshot.workspace_roots+ ));+ }+ }if let Some(requested_approval) = request.approval_policy.as_ref() {let active_approval: AskForApproval = config_snapshot.approval_policy.into();if requested_approval != &active_approval {@@ -804,6 +823,7 @@ impl ThreadRequestProcessor {model_provider,service_tier,cwd,+ runtime_workspace_roots,approval_policy,approvals_reviewer,sandbox,@@ -837,6 +857,7 @@ impl ThreadRequestProcessor {model_provider,service_tier,cwd,+ runtime_workspace_roots,approval_policy,approvals_reviewer,sandbox,@@ -1173,6 +1194,7 @@ impl ThreadRequestProcessor {model_provider: config_snapshot.model_provider_id,service_tier: config_snapshot.service_tier,cwd: config_snapshot.cwd,+ runtime_workspace_roots: config_snapshot.workspace_roots,instruction_sources,approval_policy: config_snapshot.approval_policy.into(),approvals_reviewer: config_snapshot.approvals_reviewer.into(),@@ -1214,6 +1236,7 @@ impl ThreadRequestProcessor {model_provider: Option<String>,service_tier: Option<Option<String>>,cwd: Option<String>,+ runtime_workspace_roots: Option<Vec<PathBuf>>,approval_policy: Option<codex_app_server_protocol::AskForApproval>,approvals_reviewer: Option<codex_app_server_protocol::ApprovalsReviewer>,sandbox: Option<SandboxMode>,@@ -1227,6 +1250,7 @@ impl ThreadRequestProcessor {model_provider,service_tier,cwd: cwd.map(PathBuf::from),+ workspace_roots: runtime_workspace_roots,approval_policy: approval_policy.map(codex_app_server_protocol::AskForApproval::to_core),approvals_reviewer: approvals_reviewer@@ -2351,6 +2375,7 @@ impl ThreadRequestProcessor {model_provider,service_tier,cwd,+ runtime_workspace_roots,approval_policy,approvals_reviewer,sandbox,@@ -2386,6 +2411,7 @@ impl ThreadRequestProcessor {model_provider,service_tier,cwd,+ runtime_workspace_roots,approval_policy,approvals_reviewer,sandbox,@@ -2523,6 +2549,7 @@ impl ThreadRequestProcessor {model_provider: session_configured.model_provider_id,service_tier: session_configured.service_tier,cwd: session_configured.cwd,+ runtime_workspace_roots: config_snapshot.workspace_roots,instruction_sources,approval_policy: session_configured.approval_policy.into(),approvals_reviewer: session_configured.approvals_reviewer.into(),@@ -2987,6 +3014,7 @@ impl ThreadRequestProcessor {model_provider,service_tier,cwd,+ runtime_workspace_roots,approval_policy,approvals_reviewer,sandbox,@@ -3052,6 +3080,7 @@ impl ThreadRequestProcessor {model_provider,service_tier,cwd,+ runtime_workspace_roots,approval_policy,approvals_reviewer,sandbox,@@ -3181,6 +3210,7 @@ impl ThreadRequestProcessor {model_provider: session_configured.model_provider_id,service_tier: session_configured.service_tier,cwd: session_configured.cwd,+ runtime_workspace_roots: config_snapshot.workspace_roots,instruction_sources,approval_policy: session_configured.approval_policy.into(),approvals_reviewer: session_configured.approvals_reviewer.into(),diff --git a/codex-rs/app-server/src/request_processors/thread_processor_tests.rs b/codex-rs/app-server/src/request_processors/thread_processor_tests.rsindex f59daab2fb..c2e6b9a55e 100644--- a/codex-rs/app-server/src/request_processors/thread_processor_tests.rs+++ b/codex-rs/app-server/src/request_processors/thread_processor_tests.rs@@ -636,6 +636,7 @@ mod thread_processor_behavior_tests {model_provider: None,service_tier: Some(Some("priority".to_string())),cwd: None,+ runtime_workspace_roots: None,approval_policy: None,approvals_reviewer: None,sandbox: None,@@ -656,6 +657,8 @@ mod thread_processor_behavior_tests {permission_profile: codex_protocol::models::PermissionProfile::Disabled,active_permission_profile: None,cwd,+ workspace_roots: Vec::new(),+ profile_workspace_roots: Vec::new(),ephemeral: false,reasoning_effort: None,personality: None,diff --git a/codex-rs/app-server/src/request_processors/thread_summary.rs b/codex-rs/app-server/src/request_processors/thread_summary.rsindex 875bd3deaf..63ceeb55e2 100644--- a/codex-rs/app-server/src/request_processors/thread_summary.rs+++ b/codex-rs/app-server/src/request_processors/thread_summary.rs@@ -179,19 +179,23 @@ pub(super) fn apply_permission_profile_selection_to_config_overrides(overrides: &mut ConfigOverrides,permissions: Option<PermissionProfileSelectionParams>,) {- let Some(PermissionProfileSelectionParams::Profile { id, modifications }) = permissions else {+ let Some(selection) = permissions else {return;};- overrides.default_permissions = Some(id);- overrides- .additional_writable_roots- .extend(modifications.unwrap_or_default().into_iter().map(- |modification| match modification {- PermissionProfileModificationParams::AdditionalWritableRoot { path } => {- path.to_path_buf()- }- },- ));+ overrides.default_permissions = Some(selection.id().to_string());+ if selection.legacy_additional_writable_roots().is_empty() {+ return;+ }++ let legacy_roots = selection+ .legacy_additional_writable_roots()+ .iter()+ .map(AbsolutePathBuf::to_path_buf);+ if let Some(workspace_roots) = overrides.workspace_roots.as_mut() {+ workspace_roots.extend(legacy_roots);+ } else {+ overrides.additional_writable_roots.extend(legacy_roots);+ }}pub(super) fn thread_response_sandbox_policy(diff --git a/codex-rs/app-server/src/request_processors/thread_summary_tests.rs b/codex-rs/app-server/src/request_processors/thread_summary_tests.rsindex f8902e132d..699db34ed4 100644--- a/codex-rs/app-server/src/request_processors/thread_summary_tests.rs+++ b/codex-rs/app-server/src/request_processors/thread_summary_tests.rs@@ -66,3 +66,43 @@ fn extract_conversation_summary_prefers_plain_user_messages() -> Result<()> {assert_eq!(summary, expected);Ok(())}++#[test]+fn legacy_permission_profile_modifications_extend_runtime_roots() -> Result<()> {+ let root = if cfg!(windows) {+ AbsolutePathBuf::try_from("C:\\workspace-extra")?+ } else {+ AbsolutePathBuf::try_from("/workspace-extra")?+ };+ let selection = serde_json::from_value::<PermissionProfileSelectionParams>(json!({+ "type": "profile",+ "id": ":workspace",+ "modifications": [+ {+ "type": "additionalWritableRoot",+ "path": root,+ }+ ],+ }))?;++ let mut overrides = ConfigOverrides::default();+ apply_permission_profile_selection_to_config_overrides(&mut overrides, Some(selection.clone()));+ assert_eq!(+ overrides.default_permissions,+ Some(":workspace".to_string())+ );+ assert_eq!(+ overrides.additional_writable_roots,+ vec![root.to_path_buf()]+ );++ let mut overrides = ConfigOverrides {+ workspace_roots: Some(Vec::new()),+ ..ConfigOverrides::default()+ };+ apply_permission_profile_selection_to_config_overrides(&mut overrides, Some(selection));+ assert_eq!(overrides.additional_writable_roots, Vec::<PathBuf>::new());+ assert_eq!(overrides.workspace_roots, Some(vec![root.to_path_buf()]));++ Ok(())+}diff --git a/codex-rs/app-server/src/request_processors/turn_processor.rs b/codex-rs/app-server/src/request_processors/turn_processor.rsindex 110406cc9e..54fc0383e4 100644--- a/codex-rs/app-server/src/request_processors/turn_processor.rs+++ b/codex-rs/app-server/src/request_processors/turn_processor.rs@@ -16,6 +16,20 @@ pub(crate) struct TurnRequestProcessor {skills_watcher: Arc<SkillsWatcher>,}+fn resolve_runtime_workspace_roots(+ workspace_roots: Vec<PathBuf>,+ base_cwd: &AbsolutePathBuf,+) -> Vec<AbsolutePathBuf> {+ let mut resolved_roots = Vec::new();+ for path in workspace_roots {+ let root = AbsolutePathBuf::resolve_path_against_base(path, base_cwd.as_path());+ if !resolved_roots.iter().any(|existing| existing == &root) {+ resolved_roots.push(root);+ }+ }+ resolved_roots+}+impl TurnRequestProcessor {#[allow(clippy::too_many_arguments)]pub(crate) fn new(@@ -355,8 +369,16 @@ impl TurnRequestProcessor {.map(V2UserInput::into_core).collect();let turn_has_input = !mapped_items.is_empty();+ let runtime_workspace_roots_request = params.runtime_workspace_roots.clone();+ let snapshot = if params.permissions.is_some() || runtime_workspace_roots_request.is_some()+ {+ Some(thread.config_snapshot().await)+ } else {+ None+ };let has_any_overrides = params.cwd.is_some()+ || runtime_workspace_roots_request.is_some()|| params.approval_policy.is_some()|| params.approvals_reviewer.is_some()|| params.sandbox_policy.is_some()@@ -375,16 +397,45 @@ impl TurnRequestProcessor {}let cwd = params.cwd;+ let runtime_workspace_roots = if let Some(workspace_roots) =+ runtime_workspace_roots_request.clone()+ {+ let Some(snapshot) = snapshot.as_ref() else {+ return Err(internal_error(+ "turn/start runtime workspace roots missing thread snapshot",+ ));+ };+ let base_cwd = cwd+ .as_ref()+ .map(|cwd| AbsolutePathBuf::resolve_path_against_base(cwd, snapshot.cwd.as_path()))+ .unwrap_or_else(|| snapshot.cwd.clone());+ Some(resolve_runtime_workspace_roots(workspace_roots, &base_cwd))+ } else {+ None+ };let approval_policy = params.approval_policy.map(AskForApproval::to_core);let approvals_reviewer = params.approvals_reviewer.map(codex_app_server_protocol::ApprovalsReviewer::to_core);let sandbox_policy = params.sandbox_policy.map(|p| p.to_core());- let (permission_profile, active_permission_profile) =+ let (permission_profile, active_permission_profile, profile_workspace_roots) =if let Some(permissions) = params.permissions {- let snapshot = thread.config_snapshot().await;+ let Some(snapshot) = snapshot.as_ref() else {+ return Err(internal_error(+ "turn/start permission selection missing thread snapshot",+ ));+ };let mut overrides = ConfigOverrides {cwd: cwd.clone(),+ workspace_roots: Some(runtime_workspace_roots_request.clone().unwrap_or_else(+ || {+ snapshot+ .workspace_roots+ .iter()+ .map(AbsolutePathBuf::to_path_buf)+ .collect()+ },+ )),codex_linux_sandbox_exe: self.arg0_paths.codex_linux_sandbox_exe.clone(),main_execve_wrapper_exe: self.arg0_paths.main_execve_wrapper_exe.clone(),..Default::default()@@ -413,11 +464,12 @@ impl TurnRequestProcessor {)));}(- Some(config.permissions.effective_permission_profile()),+ Some(config.permissions.permission_profile().clone()),config.permissions.active_permission_profile(),+ Some(config.permissions.profile_workspace_roots().to_vec()),)} else {- (None, None)+ (None, None, None)};let model = params.model;let effort = params.effort.map(Some);@@ -432,11 +484,13 @@ impl TurnRequestProcessor {thread.validate_turn_context_overrides(CodexThreadTurnContextOverrides {cwd: cwd.clone(),+ workspace_roots: runtime_workspace_roots.clone(),approval_policy,approvals_reviewer,sandbox_policy: sandbox_policy.clone(),permission_profile: permission_profile.clone(),active_permission_profile: active_permission_profile.clone(),+ profile_workspace_roots: profile_workspace_roots.clone(),windows_sandbox_level: None,model: model.clone(),effort,@@ -457,6 +511,8 @@ impl TurnRequestProcessor {final_output_json_schema: params.output_schema,responsesapi_client_metadata: params.responsesapi_client_metadata,cwd,+ workspace_roots: runtime_workspace_roots,+ profile_workspace_roots,approval_policy,approvals_reviewer,sandbox_policy,diff --git a/codex-rs/app-server/tests/suite/v2/skills_list.rs b/codex-rs/app-server/tests/suite/v2/skills_list.rsindex 416b2515ad..db982bc5d0 100644--- a/codex-rs/app-server/tests/suite/v2/skills_list.rs+++ b/codex-rs/app-server/tests/suite/v2/skills_list.rs@@ -614,6 +614,7 @@ async fn skills_changed_notification_is_emitted_after_skill_change() -> Result<(model_provider: None,service_tier: None,cwd: None,+ runtime_workspace_roots: None,approval_policy: None,approvals_reviewer: None,sandbox: None,diff --git a/codex-rs/app-server/tests/suite/v2/thread_resume.rs b/codex-rs/app-server/tests/suite/v2/thread_resume.rsindex 64dfe0beb7..ff2ccec49c 100644--- a/codex-rs/app-server/tests/suite/v2/thread_resume.rs+++ b/codex-rs/app-server/tests/suite/v2/thread_resume.rs@@ -184,6 +184,79 @@ async fn thread_resume_rejects_unmaterialized_thread() -> Result<()> {Ok(())}+#[tokio::test]+async fn turn_start_updates_runtime_workspace_roots_for_loaded_thread() -> Result<()> {+ let server = create_mock_responses_server_repeating_assistant("Done").await;+ let codex_home = TempDir::new()?;+ create_config_toml(codex_home.path(), &server.uri())?;++ let extra_root_tmp = TempDir::new()?;+ let extra_root = extra_root_tmp.path().join("extra-root");+ std::fs::create_dir_all(&extra_root)?;++ let mut mcp = McpProcess::new(codex_home.path()).await?;+ timeout(DEFAULT_READ_TIMEOUT, mcp.initialize()).await??;++ let start_id = mcp+ .send_thread_start_request(ThreadStartParams {+ model: Some("gpt-5.4".to_string()),+ ..Default::default()+ })+ .await?;+ let start_resp: JSONRPCResponse = timeout(+ DEFAULT_READ_TIMEOUT,+ mcp.read_stream_until_response_message(RequestId::Integer(start_id)),+ )+ .await??;+ let ThreadStartResponse { thread, .. } = to_response::<ThreadStartResponse>(start_resp)?;++ let turn_id = mcp+ .send_turn_start_request(TurnStartParams {+ thread_id: thread.id.clone(),+ input: vec![UserInput::Text {+ text: "Hello".to_string(),+ text_elements: Vec::new(),+ }],+ runtime_workspace_roots: Some(vec![extra_root.clone(), extra_root.join(".")]),+ ..Default::default()+ })+ .await?;+ timeout(+ DEFAULT_READ_TIMEOUT,+ mcp.read_stream_until_response_message(RequestId::Integer(turn_id)),+ )+ .await??;+ timeout(+ DEFAULT_READ_TIMEOUT,+ mcp.read_stream_until_notification_message("turn/completed"),+ )+ .await??;++ let resume_id = mcp+ .send_thread_resume_request(ThreadResumeParams {+ thread_id: thread.id,+ exclude_turns: true,+ ..Default::default()+ })+ .await?;+ let resume_resp: JSONRPCResponse = timeout(+ DEFAULT_READ_TIMEOUT,+ mcp.read_stream_until_response_message(RequestId::Integer(resume_id)),+ )+ .await??;+ let ThreadResumeResponse {+ runtime_workspace_roots,+ ..+ } = to_response::<ThreadResumeResponse>(resume_resp)?;++ assert_eq!(+ runtime_workspace_roots,+ vec![AbsolutePathBuf::from_absolute_path(extra_root)?]+ );++ Ok(())+}+#[tokio::test]async fn thread_goal_get_rejects_unmaterialized_thread() -> Result<()> {let server = create_mock_responses_server_repeating_assistant("Done").await;diff --git a/codex-rs/app-server/tests/suite/v2/thread_start.rs b/codex-rs/app-server/tests/suite/v2/thread_start.rsindex 78155d8c9a..75c124e893 100644--- a/codex-rs/app-server/tests/suite/v2/thread_start.rs+++ b/codex-rs/app-server/tests/suite/v2/thread_start.rs@@ -236,6 +236,89 @@ async fn thread_start_creates_thread_and_emits_started() -> Result<()> {Ok(())}+#[tokio::test]+async fn thread_start_resolves_runtime_workspace_roots_against_cwd() -> Result<()> {+ let server = create_mock_responses_server_repeating_assistant("Done").await;+ let codex_home = TempDir::new()?;+ create_config_toml_without_approval_policy(codex_home.path(), &server.uri())?;++ let cwd_tmp = TempDir::new()?;+ let cwd = cwd_tmp.path().to_path_buf();+ let relative_root = PathBuf::from("extra-root");+ std::fs::create_dir_all(cwd.join(&relative_root))?;++ let mut mcp = McpProcess::new(codex_home.path()).await?;+ timeout(DEFAULT_READ_TIMEOUT, mcp.initialize()).await??;++ let req_id = mcp+ .send_thread_start_request(ThreadStartParams {+ cwd: Some(cwd.to_string_lossy().to_string()),+ runtime_workspace_roots: Some(vec![relative_root.clone()]),+ ..Default::default()+ })+ .await?;++ let resp: JSONRPCResponse = timeout(+ DEFAULT_READ_TIMEOUT,+ mcp.read_stream_until_response_message(RequestId::Integer(req_id)),+ )+ .await??;+ let ThreadStartResponse {+ cwd: response_cwd,+ runtime_workspace_roots,+ ..+ } = to_response::<ThreadStartResponse>(resp)?;++ assert_eq!(response_cwd, cwd.abs());+ assert_eq!(+ runtime_workspace_roots,+ vec![cwd_tmp.path().join(relative_root).abs()]+ );++ Ok(())+}++#[tokio::test]+async fn thread_start_excludes_profile_workspace_roots_from_runtime_workspace_roots() -> Result<()>+{+ let server = create_mock_responses_server_repeating_assistant("Done").await;+ let codex_home = TempDir::new()?;+ let cwd = TempDir::new()?;+ let profile_root = TempDir::new()?;+ create_config_toml_with_profile_workspace_root(+ codex_home.path(),+ &server.uri(),+ profile_root.path(),+ )?;++ let mut mcp = McpProcess::new(codex_home.path()).await?;+ timeout(DEFAULT_READ_TIMEOUT, mcp.initialize()).await??;++ let req_id = mcp+ .send_thread_start_request(ThreadStartParams {+ cwd: Some(cwd.path().to_string_lossy().to_string()),+ ..Default::default()+ })+ .await?;++ let resp: JSONRPCResponse = timeout(+ DEFAULT_READ_TIMEOUT,+ mcp.read_stream_until_response_message(RequestId::Integer(req_id)),+ )+ .await??;+ let ThreadStartResponse {+ runtime_workspace_roots,+ ..+ } = to_response::<ThreadStartResponse>(resp)?;++ assert_eq!(+ runtime_workspace_roots,+ vec![cwd.path().to_path_buf().abs()]+ );++ Ok(())+}+#[tokio::test]async fn thread_start_rejects_unknown_environment_as_invalid_request() -> Result<()> {let server = create_mock_responses_server_repeating_assistant("Done").await;@@ -980,6 +1063,42 @@ stream_max_retries = 0)}+fn create_config_toml_with_profile_workspace_root(+ codex_home: &Path,+ server_uri: &str,+ profile_root: &Path,+) -> std::io::Result<()> {+ let config_toml = codex_home.join("config.toml");+ let profile_root_key = profile_root+ .display()+ .to_string()+ .replace('\\', "\\\\")+ .replace('"', "\\\"");+ std::fs::write(+ config_toml,+ format!(+ r#"+model = "mock-model"+default_permissions = "dev"+model_provider = "mock_provider"++[model_providers.mock_provider]+name = "Mock provider for test"+base_url = "{server_uri}/v1"+wire_api = "responses"+request_max_retries = 0+stream_max_retries = 0++[permissions.dev.workspace_roots]+"{profile_root_key}" = true++[permissions.dev.filesystem.":workspace_roots"]+"." = "write"+"#,+ ),+ )+}+fn create_config_toml_with_chatgpt_base_url(codex_home: &Path,server_uri: &str,diff --git a/codex-rs/app-server/tests/suite/v2/turn_start.rs b/codex-rs/app-server/tests/suite/v2/turn_start.rsindex 314be8a6ff..afc37d73c4 100644--- a/codex-rs/app-server/tests/suite/v2/turn_start.rs+++ b/codex-rs/app-server/tests/suite/v2/turn_start.rs@@ -34,7 +34,6 @@ use codex_app_server_protocol::JSONRPCNotification;use codex_app_server_protocol::JSONRPCResponse;use codex_app_server_protocol::PatchApplyStatus;use codex_app_server_protocol::PatchChangeKind;-use codex_app_server_protocol::PermissionProfileSelectionParams;use codex_app_server_protocol::RequestId;use codex_app_server_protocol::ServerRequest;use codex_app_server_protocol::ServerRequestResolvedNotification;@@ -780,10 +779,11 @@ async fn turn_start_rejects_invalid_permission_selection_before_starting_turn()text: "Hello".to_string(),text_elements: Vec::new(),}],- permissions: Some(PermissionProfileSelectionParams::Profile {- id: BUILT_IN_PERMISSION_PROFILE_DANGER_FULL_ACCESS.to_string(),- modifications: None,- }),+ permissions: Some(+ BUILT_IN_PERMISSION_PROFILE_DANGER_FULL_ACCESS+ .to_string()+ .into(),+ ),..Default::default()}).await?;@@ -1891,6 +1891,7 @@ async fn turn_start_updates_sandbox_and_cwd_between_turns_v2() -> Result<()> {}],responsesapi_client_metadata: None,cwd: Some(first_cwd.clone()),+ runtime_workspace_roots: None,approval_policy: Some(codex_app_server_protocol::AskForApproval::Never),approvals_reviewer: None,sandbox_policy: Some(codex_app_server_protocol::SandboxPolicy::WorkspaceWrite {@@ -1932,6 +1933,7 @@ async fn turn_start_updates_sandbox_and_cwd_between_turns_v2() -> Result<()> {}],responsesapi_client_metadata: None,cwd: Some(second_cwd.clone()),+ runtime_workspace_roots: None,approval_policy: Some(codex_app_server_protocol::AskForApproval::Never),approvals_reviewer: None,sandbox_policy: Some(codex_app_server_protocol::SandboxPolicy::DangerFullAccess),@@ -1991,6 +1993,152 @@ async fn turn_start_updates_sandbox_and_cwd_between_turns_v2() -> Result<()> {Ok(())}+#[cfg(unix)]+#[tokio::test]+async fn turn_start_permission_profile_rebinds_runtime_workspace_roots_between_turns() -> Result<()>+{+ skip_if_no_network!(Ok(()));++ let tmp = TempDir::new()?;+ let codex_home = tmp.path().join("codex_home");+ std::fs::create_dir(&codex_home)?;+ let old_root = tmp.path().join("old-root");+ let new_root = tmp.path().join("new-root");+ std::fs::create_dir(&old_root)?;+ std::fs::create_dir(&new_root)?;+ let old_root_text = old_root.to_string_lossy().into_owned();+ let new_root_text = new_root.to_string_lossy().into_owned();++ let server = responses::start_mock_server().await;+ let response_mock = responses::mount_sse_sequence(+ &server,+ vec![+ responses::sse(vec![+ responses::ev_response_created("resp-1"),+ responses::ev_assistant_message("msg-1", "done first"),+ responses::ev_completed("resp-1"),+ ]),+ responses::sse(vec![+ responses::ev_response_created("resp-2"),+ responses::ev_assistant_message("msg-2", "done second"),+ responses::ev_completed("resp-2"),+ ]),+ ],+ )+ .await;+ let server_uri = server.uri();+ std::fs::write(+ codex_home.join("config.toml"),+ format!(+ r#"+model = "mock-model"+approval_policy = "never"+default_permissions = "dev"+model_provider = "mock_provider"++[model_providers.mock_provider]+name = "Mock provider for test"+base_url = "{server_uri}/v1"+wire_api = "responses"+request_max_retries = 0+stream_max_retries = 0++[permissions.dev.filesystem.":workspace_roots"]+"." = "write"+"#+ ),+ )?;++ let mut mcp = McpProcess::new(&codex_home).await?;+ timeout(DEFAULT_READ_TIMEOUT, mcp.initialize()).await??;++ let start_id = mcp+ .send_thread_start_request(ThreadStartParams {+ model: Some("mock-model".to_string()),+ ..Default::default()+ })+ .await?;+ let start_resp: JSONRPCResponse = timeout(+ DEFAULT_READ_TIMEOUT,+ mcp.read_stream_until_response_message(RequestId::Integer(start_id)),+ )+ .await??;+ let ThreadStartResponse { thread, .. } = to_response::<ThreadStartResponse>(start_resp)?;++ let first_turn_id = mcp+ .send_turn_start_request(TurnStartParams {+ thread_id: thread.id.clone(),+ input: vec![V2UserInput::Text {+ text: "select dev profile".to_string(),+ text_elements: Vec::new(),+ }],+ runtime_workspace_roots: Some(vec![old_root]),+ permissions: Some("dev".to_string().into()),+ ..Default::default()+ })+ .await?;+ timeout(+ DEFAULT_READ_TIMEOUT,+ mcp.read_stream_until_response_message(RequestId::Integer(first_turn_id)),+ )+ .await??;+ timeout(+ DEFAULT_READ_TIMEOUT,+ mcp.read_stream_until_notification_message("turn/completed"),+ )+ .await??;++ let second_turn_id = mcp+ .send_turn_start_request(TurnStartParams {+ thread_id: thread.id.clone(),+ input: vec![V2UserInput::Text {+ text: "write in new root".to_string(),+ text_elements: Vec::new(),+ }],+ runtime_workspace_roots: Some(vec![new_root]),+ ..Default::default()+ })+ .await?;+ timeout(+ DEFAULT_READ_TIMEOUT,+ mcp.read_stream_until_response_message(RequestId::Integer(second_turn_id)),+ )+ .await??;++ timeout(+ DEFAULT_READ_TIMEOUT,+ mcp.read_stream_until_notification_message("turn/completed"),+ )+ .await??;++ let requests = response_mock.requests();+ assert_eq!(requests.len(), 2, "expected two Responses API requests");+ let latest_permissions_instructions =+ |request: &core_test_support::responses::ResponsesRequest| {+ request+ .message_input_texts("developer")+ .into_iter()+ .rev()+ .find(|text| text.contains("<permissions instructions>"))+ .expect("permissions instructions")+ };+ let first_permissions = latest_permissions_instructions(&requests[0]);+ assert!(first_permissions.contains(&old_root_text));+ assert!(+ !first_permissions.contains(&new_root_text),+ "first turn should materialize the initial runtime workspace root"+ );++ let second_permissions = latest_permissions_instructions(&requests[1]);+ assert!(second_permissions.contains(&new_root_text));+ assert!(+ !second_permissions.contains(&old_root_text),+ "second turn should rebind :workspace_roots to the updated runtime workspace root"+ );++ Ok(())+}+#[tokio::test]async fn turn_start_resolves_sticky_thread_local_environment_and_turn_overrides() -> Result<()> {let tmp = TempDir::new()?;diff --git a/codex-rs/core/src/codex_thread.rs b/codex-rs/core/src/codex_thread.rsindex be5b0ccb88..1a2d5ed710 100644--- a/codex-rs/core/src/codex_thread.rs+++ b/codex-rs/core/src/codex_thread.rs@@ -59,6 +59,8 @@ pub struct ThreadConfigSnapshot {pub permission_profile: PermissionProfile,pub active_permission_profile: Option<ActivePermissionProfile>,pub cwd: AbsolutePathBuf,+ pub workspace_roots: Vec<AbsolutePathBuf>,+ pub profile_workspace_roots: Vec<AbsolutePathBuf>,pub ephemeral: bool,pub reasoning_effort: Option<ReasoningEffort>,pub personality: Option<Personality>,@@ -82,6 +84,8 @@ impl ThreadConfigSnapshot {#[derive(Clone, Default)]pub struct CodexThreadTurnContextOverrides {pub cwd: Option<PathBuf>,+ pub workspace_roots: Option<Vec<AbsolutePathBuf>>,+ pub profile_workspace_roots: Option<Vec<AbsolutePathBuf>>,pub approval_policy: Option<AskForApproval>,pub approvals_reviewer: Option<ApprovalsReviewer>,pub sandbox_policy: Option<SandboxPolicy>,@@ -258,6 +262,8 @@ impl CodexThread {) -> ConstraintResult<()> {let CodexThreadTurnContextOverrides {cwd,+ workspace_roots,+ profile_workspace_roots,approval_policy,approvals_reviewer,sandbox_policy,@@ -283,6 +289,8 @@ impl CodexThread {let updates = SessionSettingsUpdate {cwd,+ workspace_roots,+ profile_workspace_roots,approval_policy,approvals_reviewer,sandbox_policy,diff --git a/codex-rs/core/src/config/config_tests.rs b/codex-rs/core/src/config/config_tests.rsindex 6412bff01e..f197ccad71 100644--- a/codex-rs/core/src/config/config_tests.rs+++ b/codex-rs/core/src/config/config_tests.rs@@ -1905,9 +1905,28 @@ async fn workspace_profile_applies_rules_to_runtime_and_profile_workspace_roots().await?;+ let cwd_abs = cwd.abs();+ let runtime_root_abs = runtime_root.abs();let profile_root_abs = profile_root.abs();+ assert_eq!(+ config.workspace_roots,+ vec![cwd_abs.clone(), runtime_root_abs.clone()]+ );+ assert_eq!(+ config.permissions.workspace_roots(),+ &[cwd_abs.clone(), runtime_root_abs.clone()]+ );+ assert_eq!(+ config.effective_workspace_roots(),+ vec![+ cwd_abs.clone(),+ runtime_root_abs.clone(),+ profile_root_abs.clone()+ ]+ );+let policy = config.permissions.file_system_sandbox_policy();- for root in [cwd.abs(), runtime_root.abs(), profile_root_abs.clone()] {+ for root in [cwd_abs, runtime_root_abs, profile_root_abs.clone()] {assert!(policy.can_write_path_with_cwd(root.as_path(), cwd.as_path()),"expected workspace root to be writable, policy: {policy:?}"diff --git a/codex-rs/core/src/config/mod.rs b/codex-rs/core/src/config/mod.rsindex d9f744155d..527c93b3f3 100644--- a/codex-rs/core/src/config/mod.rs+++ b/codex-rs/core/src/config/mod.rs@@ -1231,6 +1231,13 @@ impl Config {Ok(())}+ pub fn effective_workspace_roots(&self) -> Vec<AbsolutePathBuf> {+ let mut workspace_roots = self.workspace_roots.clone();+ workspace_roots.extend(self.permissions.profile_workspace_roots().iter().cloned());+ dedupe_absolute_paths(&mut workspace_roots);+ workspace_roots+ }+pub fn to_models_manager_config(&self) -> ModelsManagerConfig {ModelsManagerConfig {model_context_window: self.model_context_window,@@ -2671,8 +2678,6 @@ impl Config {configured_workspace_roots.extend(sandbox_workspace_write.writable_roots.clone());}dedupe_absolute_paths(&mut configured_workspace_roots);- workspace_roots.extend(configured_workspace_roots.iter().cloned());- dedupe_absolute_paths(&mut workspace_roots);file_system_sandbox_policy = file_system_sandbox_policy.with_materialized_project_roots_for_workspace_roots(&configured_workspace_roots);let mut permission_profile = if let Some(permission_profile) =diff --git a/codex-rs/core/src/config/resolved_permission_profile.rs b/codex-rs/core/src/config/resolved_permission_profile.rsindex c7cf264dae..911d9bf2e8 100644--- a/codex-rs/core/src/config/resolved_permission_profile.rs+++ b/codex-rs/core/src/config/resolved_permission_profile.rs@@ -101,24 +101,6 @@ impl ResolvedPermissionProfile {}}- fn with_permission_profile(&self, permission_profile: PermissionProfile) -> Self {- match self {- Self::Legacy(_) => Self::legacy(permission_profile),- Self::BuiltIn(profile) => Self::BuiltIn(BuiltInPermissionProfile {- id: profile.id,- extends: profile.extends.clone(),- permission_profile,- profile_workspace_roots: profile.profile_workspace_roots.clone(),- }),- Self::Named(profile) => Self::Named(NamedPermissionProfile {- id: profile.id.clone(),- extends: profile.extends.clone(),- permission_profile,- profile_workspace_roots: profile.profile_workspace_roots.clone(),- }),- }- }-pub(crate) fn active_permission_profile(&self) -> Option<ActivePermissionProfile> {match self {Self::Legacy(_) => None,@@ -189,19 +171,6 @@ impl PermissionProfileState {self.resolved_permission_profile.get().permission_profile()}- pub(crate) fn clone_with_permission_profile(- &self,- permission_profile: PermissionProfile,- ) -> ConstraintResult<Self> {- let candidate = self- .resolved_permission_profile- .get()- .with_permission_profile(permission_profile);- let mut state = self.clone();- state.resolved_permission_profile.set(candidate)?;- Ok(state)- }-pub(crate) fn active_permission_profile(&self) -> Option<ActivePermissionProfile> {self.resolved_permission_profile.get()diff --git a/codex-rs/core/src/session/handlers.rs b/codex-rs/core/src/session/handlers.rsindex 5cb37f9828..a26b9bb3f6 100644--- a/codex-rs/core/src/session/handlers.rs+++ b/codex-rs/core/src/session/handlers.rs@@ -146,6 +146,8 @@ pub(super) async fn user_input_or_turn_inner(approval_policy: Some(approval_policy),approvals_reviewer,sandbox_policy: Some(sandbox_policy),+ workspace_roots: None,+ profile_workspace_roots: None,permission_profile,active_permission_profile: None,windows_sandbox_level: None,@@ -163,6 +165,8 @@ pub(super) async fn user_input_or_turn_inner(}Op::UserInputWithTurnContext {cwd,+ workspace_roots,+ profile_workspace_roots,approval_policy,approvals_reviewer,sandbox_policy,@@ -195,6 +199,8 @@ pub(super) async fn user_input_or_turn_inner(items,SessionSettingsUpdate {cwd,+ workspace_roots,+ profile_workspace_roots,approval_policy,approvals_reviewer,sandbox_policy,diff --git a/codex-rs/core/src/session/mod.rs b/codex-rs/core/src/session/mod.rsindex 1938ae2a81..142e39ea97 100644--- a/codex-rs/core/src/session/mod.rs+++ b/codex-rs/core/src/session/mod.rs@@ -621,6 +621,7 @@ impl Codex {permission_profile_state: session_permission_profile_state_from_config(&config)?,windows_sandbox_level: WindowsSandboxLevel::from_config(&config),cwd: config.cwd.clone(),+ workspace_roots: config.workspace_roots.clone(),codex_home: config.codex_home.clone(),thread_name: None,environments: environment_selections.to_selections(),@@ -821,15 +822,7 @@ fn get_service_tier(fn session_permission_profile_state_from_config(config: &Config,) -> CodexResult<PermissionProfileState> {- config- .permissions- .permission_profile_state()- .clone_with_permission_profile(config.permissions.effective_permission_profile())- .map_err(|err| {- CodexErr::Fatal(format!(- "failed to materialize workspace roots for session permissions: {err}"- ))- })+ Ok(config.permissions.permission_profile_state().clone())}fn is_enterprise_default_service_tier_plan(plan_type: AccountPlanType) -> bool {diff --git a/codex-rs/core/src/session/session.rs b/codex-rs/core/src/session/session.rsindex 5f140ee36d..5b57e11895 100644--- a/codex-rs/core/src/session/session.rs+++ b/codex-rs/core/src/session/session.rs@@ -63,9 +63,9 @@ pub(crate) struct SessionConfiguration {/// When to escalate for approval for executionpub(super) approval_policy: Constrained<AskForApproval>,pub(super) approvals_reviewer: ApprovalsReviewer,- /// Permission profile state for the session. Keep the constrained profile- /// and selected profile id in sync by using the methods below instead of- /// mutating the fields independently.+ /// Permission profile state for the session. Keep the constrained profile,+ /// active profile id, and profile-defined workspace roots in sync by using+ /// the methods below instead of mutating the fields independently.pub(super) permission_profile_state: PermissionProfileState,pub(super) windows_sandbox_level: WindowsSandboxLevel,@@ -74,6 +74,9 @@ pub(crate) struct SessionConfiguration {/// execution sandbox are resolved against this directory **instead** of/// the process-wide current working directory.pub(super) cwd: AbsolutePathBuf,+ /// Thread-scoped runtime workspace roots for materializing symbolic+ /// workspace permissions at session runtime.+ pub(super) workspace_roots: Vec<AbsolutePathBuf>,/// Directory containing all Codex state for this session.pub(super) codex_home: AbsolutePathBuf,/// Optional user-facing name for the thread, updated during the session.@@ -107,13 +110,20 @@ impl SessionConfiguration {}pub(super) fn permission_profile(&self) -> PermissionProfile {- self.permission_profile_state.permission_profile().clone()+ self.permission_profile_state+ .permission_profile()+ .clone()+ .materialize_project_roots_with_workspace_roots(&self.workspace_roots)}pub(super) fn active_permission_profile(&self) -> Option<ActivePermissionProfile> {self.permission_profile_state.active_permission_profile()}+ pub(super) fn profile_workspace_roots(&self) -> &[AbsolutePathBuf] {+ self.permission_profile_state.profile_workspace_roots()+ }+pub(super) fn apply_permission_profile_to_permissions(&self,permissions: &mut crate::config::Permissions,@@ -164,6 +174,8 @@ impl SessionConfiguration {permission_profile: self.permission_profile(),active_permission_profile: self.active_permission_profile(),cwd: self.cwd.clone(),+ workspace_roots: self.workspace_roots.clone(),+ profile_workspace_roots: self.profile_workspace_roots().to_vec(),ephemeral: self.original_config_do_not_use.ephemeral,reasoning_effort: self.collaboration_mode.reasoning_effort(),personality: self.personality,@@ -243,6 +255,23 @@ impl SessionConfiguration {let cwd_changed = absolute_cwd.as_path() != self.cwd.as_path();next_configuration.cwd = absolute_cwd;+ if let Some(workspace_roots) = updates.workspace_roots.clone() {+ next_configuration.workspace_roots = workspace_roots;+ } else if cwd_changed && self.workspace_roots.contains(&self.cwd) {+ let mut retargeted_workspace_roots =+ Vec::with_capacity(next_configuration.workspace_roots.len());+ for root in &self.workspace_roots {+ let root = if root == &self.cwd {+ next_configuration.cwd.clone()+ } else {+ root.clone()+ };+ if !retargeted_workspace_roots.contains(&root) {+ retargeted_workspace_roots.push(root);+ }+ }+ next_configuration.workspace_roots = retargeted_workspace_roots;+ }if let Some(permission_profile) = updates.permission_profile.clone() {let active_permission_profile =@@ -256,6 +285,7 @@ impl SessionConfiguration {next_configuration.set_permission_profile_projection(permission_profile,active_permission_profile,+ updates.profile_workspace_roots.clone().unwrap_or_default(),Some(¤t_file_system_sandbox_policy),)?;} else if let Some(sandbox_policy) = updates.sandbox_policy.clone() {@@ -311,6 +341,7 @@ impl SessionConfiguration {&mut self,permission_profile: PermissionProfile,active_permission_profile: Option<ActivePermissionProfile>,+ profile_workspace_roots: Vec<AbsolutePathBuf>,preserve_deny_reads_from: Option<&FileSystemSandboxPolicy>,) -> ConstraintResult<()> {let enforcement = permission_profile.enforcement();@@ -329,7 +360,7 @@ impl SessionConfiguration {self.permission_profile_state.set_active_permission_profile(effective_permission_profile,active_permission_profile,- Vec::new(),+ profile_workspace_roots,)}}@@ -337,6 +368,8 @@ impl SessionConfiguration {#[derive(Default, Clone)]pub(crate) struct SessionSettingsUpdate {pub(crate) cwd: Option<PathBuf>,+ pub(crate) workspace_roots: Option<Vec<AbsolutePathBuf>>,+ pub(crate) profile_workspace_roots: Option<Vec<AbsolutePathBuf>>,pub(crate) approval_policy: Option<AskForApproval>,pub(crate) approvals_reviewer: Option<ApprovalsReviewer>,pub(crate) sandbox_policy: Option<SandboxPolicy>,diff --git a/codex-rs/core/src/session/tests.rs b/codex-rs/core/src/session/tests.rsindex 81012419cb..9265072dde 100644--- a/codex-rs/core/src/session/tests.rs+++ b/codex-rs/core/src/session/tests.rs@@ -36,6 +36,7 @@ use codex_protocol::account::PlanType as AccountPlanType;use codex_protocol::config_types::ServiceTier;use codex_protocol::config_types::TrustLevel;use codex_protocol::exec_output::ExecToolCallOutput;+use codex_protocol::models::ActivePermissionProfile;use codex_protocol::models::BUILT_IN_PERMISSION_PROFILE_WORKSPACE;use codex_protocol::models::FileSystemPermissions;use codex_protocol::models::FunctionCallOutputBody;@@ -2153,29 +2154,47 @@ async fn session_configured_reports_permission_profile_for_external_sandbox() ->}#[tokio::test(flavor = "multi_thread", worker_threads = 2)]-async fn session_permission_profile_materializes_runtime_workspace_roots() -> anyhow::Result<()> {+async fn session_permission_profile_rebinds_runtime_workspace_roots() -> anyhow::Result<()> {let codex_home = tempfile::TempDir::new()?;let cwd = tempfile::TempDir::new()?;- let extra_root = tempfile::TempDir::new()?;+ let old_root = test_path_buf("/workspace/old").abs();+ let new_root = test_path_buf("/workspace/new").abs();let config = ConfigBuilder::default().codex_home(codex_home.path().to_path_buf()).harness_overrides(crate::config::ConfigOverrides {cwd: Some(cwd.path().to_path_buf()),default_permissions: Some(BUILT_IN_PERMISSION_PROFILE_WORKSPACE.to_string()),- additional_writable_roots: vec![extra_root.path().to_path_buf()],+ additional_writable_roots: vec![old_root.to_path_buf()],..Default::default()}).build().await?;+let session_permission_profile_state = session_permission_profile_state_from_config(&config)?;- let file_system_policy = session_permission_profile_state+ let stored_file_system_policy = session_permission_profile_state.permission_profile().file_system_sandbox_policy();-assert!(- file_system_policy.can_write_path_with_cwd(extra_root.path(), config.cwd.as_path()),- "session permission profile should carry materialized runtime workspace roots"+ !stored_file_system_policy+ .can_write_path_with_cwd(old_root.as_path(), config.cwd.as_path()),+ "session permission profile state should keep runtime workspace roots symbolic");++ let mut session_configuration = make_session_configuration_for_tests().await;+ session_configuration.cwd = config.cwd.clone();+ session_configuration.workspace_roots = config.workspace_roots.clone();+ session_configuration.permission_profile_state = session_permission_profile_state;++ let initial_policy = session_configuration.file_system_sandbox_policy();+ assert!(initial_policy.can_write_path_with_cwd(old_root.as_path(), config.cwd.as_path()));++ let updated = session_configuration.apply(&SessionSettingsUpdate {+ workspace_roots: Some(vec![new_root.clone()]),+ ..Default::default()+ })?;+ let updated_policy = updated.file_system_sandbox_policy();+ assert!(updated_policy.can_write_path_with_cwd(new_root.as_path(), updated.cwd.as_path()));+ assert!(!updated_policy.can_write_path_with_cwd(old_root.as_path(), updated.cwd.as_path()));Ok(())}@@ -2917,6 +2936,7 @@ async fn set_rate_limits_retains_previous_credits() {permission_profile_state: config.permissions.permission_profile_state().clone(),windows_sandbox_level: WindowsSandboxLevel::from_config(&config),cwd: config.cwd.clone(),+ workspace_roots: config.workspace_roots.clone(),codex_home: config.codex_home.clone(),thread_name: None,environments: Vec::new(),@@ -3020,6 +3040,7 @@ async fn set_rate_limits_updates_plan_type_when_present() {permission_profile_state: config.permissions.permission_profile_state().clone(),windows_sandbox_level: WindowsSandboxLevel::from_config(&config),cwd: config.cwd.clone(),+ workspace_roots: config.workspace_roots.clone(),codex_home: config.codex_home.clone(),thread_name: None,environments: Vec::new(),@@ -3492,6 +3513,7 @@ pub(crate) async fn make_session_configuration_for_tests() -> SessionConfiguratipermission_profile_state: config.permissions.permission_profile_state().clone(),windows_sandbox_level: WindowsSandboxLevel::from_config(&config),cwd: config.cwd.clone(),+ workspace_roots: config.workspace_roots.clone(),codex_home: config.codex_home.clone(),thread_name: None,environments: Vec::new(),@@ -3561,6 +3583,8 @@ async fn session_configuration_apply_preserves_profile_file_system_policy_on_cwd),).expect("set permission profile");+ let expected_file_system_sandbox_policy = file_system_sandbox_policy+ .materialize_project_roots_with_workspace_roots(&session_configuration.workspace_roots);let updated = session_configuration.apply(&SessionSettingsUpdate {@@ -3571,7 +3595,7 @@ async fn session_configuration_apply_preserves_profile_file_system_policy_on_cwdassert_eq!(updated.file_system_sandbox_policy(),- file_system_sandbox_policy+ expected_file_system_sandbox_policy);}@@ -3620,7 +3644,8 @@ async fn session_configuration_apply_permission_profile_preserves_existing_deny_}).expect("permission profile update should succeed");- let mut expected_file_system_policy = requested_file_system_policy;+ let mut expected_file_system_policy = requested_file_system_policy+ .materialize_project_roots_with_workspace_roots(&session_configuration.workspace_roots);expected_file_system_policy.glob_scan_max_depth = Some(2);expected_file_system_policy.entries.push(deny_entry);assert_eq!(@@ -3675,6 +3700,93 @@ async fn session_configuration_apply_permission_profile_accepts_direct_write_roo);}+#[tokio::test]+async fn session_configuration_apply_rebinds_symbolic_profile_to_updated_workspace_roots() {+ let mut session_configuration = make_session_configuration_for_tests().await;+ let old_root = tempfile::tempdir().expect("create old root");+ let new_root = tempfile::tempdir().expect("create new root");+ let profile_root = tempfile::tempdir().expect("create profile root");+ let old_root = old_root.path().abs();+ let new_root = new_root.path().abs();+ let profile_root = profile_root.path().abs();+ session_configuration.workspace_roots = vec![old_root.clone()];++ let file_system_sandbox_policy =+ FileSystemSandboxPolicy::restricted(vec![FileSystemSandboxEntry {+ path: FileSystemPath::Special {+ value: FileSystemSpecialPath::project_roots(/*subpath*/ None),+ },+ access: FileSystemAccessMode::Write,+ }]);+ let permission_profile = PermissionProfile::from_runtime_permissions(+ &file_system_sandbox_policy,+ NetworkSandboxPolicy::Restricted,+ );++ let updated = session_configuration+ .apply(&SessionSettingsUpdate {+ workspace_roots: Some(vec![new_root.clone()]),+ permission_profile: Some(permission_profile),+ active_permission_profile: Some(ActivePermissionProfile::new("dev")),+ profile_workspace_roots: Some(vec![profile_root.clone()]),+ ..Default::default()+ })+ .expect("permission profile update should succeed");++ let updated_policy = updated.file_system_sandbox_policy();+ assert!(updated_policy.can_write_path_with_cwd(new_root.as_path(), updated.cwd.as_path()));+ assert!(!updated_policy.can_write_path_with_cwd(old_root.as_path(), updated.cwd.as_path()));+ assert_eq!(+ updated.active_permission_profile(),+ Some(ActivePermissionProfile::new("dev"))+ );+ assert_eq!(updated.profile_workspace_roots(), &[profile_root]);+}++#[tokio::test]+async fn session_configuration_apply_retargets_implicit_workspace_root_on_cwd_update() {+ let mut session_configuration = make_session_configuration_for_tests().await;+ let old_root = tempfile::tempdir().expect("create old root");+ let new_root = tempfile::tempdir().expect("create new root");+ let extra_root = tempfile::tempdir().expect("create extra root");+ let old_root = old_root.path().abs();+ let new_root = new_root.path().abs();+ let extra_root = extra_root.path().abs();+ session_configuration.cwd = old_root.clone();+ session_configuration.workspace_roots = vec![old_root.clone(), extra_root.clone()];++ let file_system_sandbox_policy =+ FileSystemSandboxPolicy::restricted(vec![FileSystemSandboxEntry {+ path: FileSystemPath::Special {+ value: FileSystemSpecialPath::project_roots(/*subpath*/ None),+ },+ access: FileSystemAccessMode::Write,+ }]);+ let permission_profile = PermissionProfile::from_runtime_permissions(+ &file_system_sandbox_policy,+ NetworkSandboxPolicy::Restricted,+ );+ session_configuration+ .set_permission_profile_for_tests(permission_profile)+ .expect("set permission profile");++ let updated = session_configuration+ .apply(&SessionSettingsUpdate {+ cwd: Some(new_root.to_path_buf()),+ ..Default::default()+ })+ .expect("cwd-only update should succeed");++ assert_eq!(+ updated.workspace_roots,+ vec![new_root.clone(), extra_root.clone()]+ );+ let updated_policy = updated.file_system_sandbox_policy();+ assert!(updated_policy.can_write_path_with_cwd(new_root.as_path(), updated.cwd.as_path()));+ assert!(updated_policy.can_write_path_with_cwd(extra_root.as_path(), updated.cwd.as_path()));+ assert!(!updated_policy.can_write_path_with_cwd(old_root.as_path(), updated.cwd.as_path()));+}+#[cfg_attr(windows, ignore)]#[tokio::test]async fn new_default_turn_uses_config_aware_skills_for_role_overrides() {@@ -3762,12 +3874,13 @@ enabled = false}#[tokio::test]-async fn session_configuration_apply_rederives_legacy_file_system_policy_on_cwd_update() {+async fn session_configuration_apply_retargets_legacy_workspace_root_on_cwd_update() {let mut session_configuration = make_session_configuration_for_tests().await;let workspace = tempfile::tempdir().expect("create temp dir");- let project_root = workspace.path().join("project");- let original_cwd = project_root.join("subdir");- session_configuration.cwd = original_cwd.abs();+ let original_cwd = workspace.path().join("repo-a").abs();+ let project_root = workspace.path().join("repo-b").abs();+ session_configuration.cwd = original_cwd.clone();+ session_configuration.workspace_roots = vec![session_configuration.cwd.clone()];let sandbox_policy = SandboxPolicy::WorkspaceWrite {writable_roots: Vec::new(),network_access: false,@@ -3790,20 +3903,23 @@ async fn session_configuration_apply_rederives_legacy_file_system_policy_on_cwd_let updated = session_configuration.apply(&SessionSettingsUpdate {- cwd: Some(project_root.clone()),+ cwd: Some(project_root.to_path_buf()),..Default::default()}).expect("cwd-only update should succeed");- let expected_file_system_policy = FileSystemSandboxPolicy::from_legacy_sandbox_policy_for_cwd(- &updated.sandbox_policy(),- &project_root,- );+ assert_eq!(updated.workspace_roots, vec![project_root.clone()]);assert!(updated.file_system_sandbox_policy()- .is_semantically_equivalent_to(&expected_file_system_policy, &project_root),- "cwd-only update should rederive the legacy filesystem policy for the new cwd"+ .can_write_path_with_cwd(project_root.as_path(), updated.cwd.as_path()),+ "cwd-only update should keep the new cwd writable"+ );+ assert!(+ !updated+ .file_system_sandbox_policy()+ .can_write_path_with_cwd(original_cwd.as_path(), updated.cwd.as_path()),+ "cwd-only update should not keep the old implicit cwd writable");}@@ -4032,6 +4148,7 @@ async fn session_new_fails_when_zsh_fork_enabled_without_zsh_path() {permission_profile_state: config.permissions.permission_profile_state().clone(),windows_sandbox_level: WindowsSandboxLevel::from_config(&config),cwd: config.cwd.clone(),+ workspace_roots: config.workspace_roots.clone(),codex_home: config.codex_home.clone(),thread_name: None,environments: Vec::new(),@@ -4140,6 +4257,7 @@ pub(crate) async fn make_session_and_context() -> (Session, TurnContext) {permission_profile_state: config.permissions.permission_profile_state().clone(),windows_sandbox_level: WindowsSandboxLevel::from_config(&config),cwd: config.cwd.clone(),+ workspace_roots: config.workspace_roots.clone(),codex_home: config.codex_home.clone(),thread_name: None,environments: default_environments,@@ -4373,6 +4491,7 @@ async fn make_session_with_config_and_rx(permission_profile_state: config.permissions.permission_profile_state().clone(),windows_sandbox_level: WindowsSandboxLevel::from_config(&config),cwd: config.cwd.clone(),+ workspace_roots: config.workspace_roots.clone(),codex_home: config.codex_home.clone(),thread_name: None,environments: default_environments,@@ -4475,6 +4594,7 @@ async fn make_session_with_history_source_and_agent_control_and_rx(permission_profile_state: config.permissions.permission_profile_state().clone(),windows_sandbox_level: WindowsSandboxLevel::from_config(&config),cwd: config.cwd.clone(),+ workspace_roots: config.workspace_roots.clone(),codex_home: config.codex_home.clone(),thread_name: None,environments: default_environments,@@ -5124,6 +5244,8 @@ fn op_kind_distinguishes_turn_ops() {final_output_json_schema: None,responsesapi_client_metadata: None,cwd: None,+ workspace_roots: None,+ profile_workspace_roots: None,approval_policy: None,approvals_reviewer: None,sandbox_policy: None,@@ -5991,6 +6113,7 @@ wherepermission_profile_state: config.permissions.permission_profile_state().clone(),windows_sandbox_level: WindowsSandboxLevel::from_config(&config),cwd: config.cwd.clone(),+ workspace_roots: config.workspace_roots.clone(),codex_home: config.codex_home.clone(),thread_name: None,environments: default_environments,diff --git a/codex-rs/core/src/session/turn_context.rs b/codex-rs/core/src/session/turn_context.rsindex eefa6bc9da..cab18b8561 100644--- a/codex-rs/core/src/session/turn_context.rs+++ b/codex-rs/core/src/session/turn_context.rs@@ -432,6 +432,10 @@ impl Session {let config = session_configuration.original_config_do_not_use.clone();let mut per_turn_config = (*config).clone();per_turn_config.cwd = cwd;+ per_turn_config.workspace_roots = session_configuration.workspace_roots.clone();+ per_turn_config+ .permissions+ .set_workspace_roots(session_configuration.workspace_roots.clone());per_turn_config.model_reasoning_effort =session_configuration.collaboration_mode.reasoning_effort();per_turn_config.model_reasoning_summary = session_configuration.model_reasoning_summary;@@ -466,6 +470,10 @@ impl Session {Self::build_per_turn_config(session_configuration, session_configuration.cwd.clone());config.model = Some(session_configuration.collaboration_mode.model().to_string());config.permissions.approval_policy = session_configuration.approval_policy.clone();+ config.workspace_roots = session_configuration.workspace_roots.clone();+ config+ .permissions+ .set_workspace_roots(session_configuration.workspace_roots.clone());config}diff --git a/codex-rs/core/tests/suite/permissions_messages.rs b/codex-rs/core/tests/suite/permissions_messages.rsindex 05fbaad89f..c4f1bef968 100644--- a/codex-rs/core/tests/suite/permissions_messages.rs+++ b/codex-rs/core/tests/suite/permissions_messages.rs@@ -557,6 +557,7 @@ async fn permissions_message_includes_writable_roots() -> Result<()> {.set_permission_profile(permission_profile).expect("test permission profile should be allowed");let workspace_roots = vec![config.cwd.clone(), writable_root_for_config];+ config.workspace_roots = workspace_roots.clone();config.permissions.set_workspace_roots(workspace_roots);config.config_layer_stack = ConfigLayerStack::default();});@@ -578,9 +579,9 @@ async fn permissions_message_includes_writable_roots() -> Result<()> {let permissions = permissions_texts(&req.single_request());let normalize_line_endings = |s: &str| s.replace("\r\n", "\n");let exec_policy = load_exec_policy(&test.config.config_layer_stack).await?;- let sandbox_policy = test.config.legacy_sandbox_policy();- let expected = PermissionsInstructions::from_policy(- &sandbox_policy,+ let permission_profile = test.config.permissions.effective_permission_profile();+ let expected = PermissionsInstructions::from_permission_profile(+ &permission_profile,AskForApproval::OnRequest,test.config.approvals_reviewer,&exec_policy,diff --git a/codex-rs/exec/src/lib.rs b/codex-rs/exec/src/lib.rsindex a71ca5fa3f..9f7174ec68 100644--- a/codex-rs/exec/src/lib.rs+++ b/codex-rs/exec/src/lib.rs@@ -24,7 +24,6 @@ use codex_app_server_protocol::ConfigWarningNotification;use codex_app_server_protocol::JSONRPCErrorError;use codex_app_server_protocol::McpServerElicitationAction;use codex_app_server_protocol::McpServerElicitationRequestResponse;-use codex_app_server_protocol::PermissionProfileModificationParams;use codex_app_server_protocol::PermissionProfileSelectionParams;use codex_app_server_protocol::RequestId;use codex_app_server_protocol::ReviewStartParams;@@ -790,6 +789,7 @@ async fn run_exec_session(args: ExecRunArgs) -> anyhow::Result<()> {responsesapi_client_metadata: None,environments: None,cwd: Some(default_cwd),+ runtime_workspace_roots: None,approval_policy: Some(default_approval_policy.into()),approvals_reviewer: None,sandbox_policy: None,@@ -961,6 +961,13 @@ fn thread_start_params_from_config(config: &Config) -> ThreadStartParams {model: config.model.clone(),model_provider: Some(config.model_provider_id.clone()),cwd: Some(config.cwd.to_string_lossy().to_string()),+ runtime_workspace_roots: Some(+ config+ .workspace_roots+ .iter()+ .map(AbsolutePathBuf::to_path_buf)+ .collect(),+ ),approval_policy: Some(config.permissions.approval_policy.value().into()),approvals_reviewer: approvals_reviewer_override_from_config(config),sandbox: sandbox.flatten(),@@ -984,6 +991,13 @@ fn thread_resume_params_from_config(config: &Config, thread_id: String) -> Threamodel: config.model.clone(),model_provider: Some(config.model_provider_id.clone()),cwd: Some(config.cwd.to_string_lossy().to_string()),+ runtime_workspace_roots: Some(+ config+ .workspace_roots+ .iter()+ .map(AbsolutePathBuf::to_path_buf)+ .collect(),+ ),approval_policy: Some(config.permissions.approval_policy.value().into()),approvals_reviewer: approvals_reviewer_override_from_config(config),sandbox: sandbox.flatten(),@@ -997,30 +1011,13 @@ fn permissions_selection_from_config(config: &Config) -> Option<PermissionProfilconfig.permissions.active_permission_profile()- .map(|active| {- permissions_selection_from_active_profile(- active,- config.cwd.as_path(),- config.permissions.user_visible_workspace_roots(),- )- })+ .map(permissions_selection_from_active_profile)}fn permissions_selection_from_active_profile(active: ActivePermissionProfile,- cwd: &Path,- workspace_roots: &[AbsolutePathBuf],) -> PermissionProfileSelectionParams {- let modifications = workspace_roots- .iter()- .filter(|root| root.as_path() != cwd)- .cloned()- .map(|path| PermissionProfileModificationParams::AdditionalWritableRoot { path })- .collect::<Vec<_>>();- PermissionProfileSelectionParams::Profile {- id: active.id,- modifications: (!modifications.is_empty()).then_some(modifications),- }+ PermissionProfileSelectionParams::new(active.id)}fn sandbox_mode_from_permission_profile(diff --git a/codex-rs/exec/src/lib_tests.rs b/codex-rs/exec/src/lib_tests.rsindex 2aa2663435..367bba5d05 100644--- a/codex-rs/exec/src/lib_tests.rs+++ b/codex-rs/exec/src/lib_tests.rs@@ -459,24 +459,14 @@ async fn thread_start_params_include_review_policy_when_auto_review_is_enabled()}#[test]-fn active_profile_selection_includes_extra_workspace_roots_as_modifications() {- let cwd = test_path_buf("/workspace/project").abs();- let extra_root = test_path_buf("/workspace/cache").abs();-- let selection = permissions_selection_from_active_profile(- ActivePermissionProfile::new(BUILT_IN_PERMISSION_PROFILE_WORKSPACE),- cwd.as_path(),- &[cwd.clone(), extra_root.clone()],- );+fn active_profile_selection_uses_profile_id_only() {+ let selection = permissions_selection_from_active_profile(ActivePermissionProfile::new(+ BUILT_IN_PERMISSION_PROFILE_WORKSPACE,+ ));assert_eq!(selection,- PermissionProfileSelectionParams::Profile {- id: BUILT_IN_PERMISSION_PROFILE_WORKSPACE.to_string(),- modifications: Some(vec![- PermissionProfileModificationParams::AdditionalWritableRoot { path: extra_root }- ]),- }+ PermissionProfileSelectionParams::new(BUILT_IN_PERMISSION_PROFILE_WORKSPACE));}@@ -583,6 +573,7 @@ fn sample_thread_start_response() -> ThreadStartResponse {model_provider: "openai".to_string(),service_tier: None,cwd: test_path_buf("/tmp").abs(),+ runtime_workspace_roots: Vec::new(),instruction_sources: Vec::new(),approval_policy: codex_app_server_protocol::AskForApproval::OnRequest,approvals_reviewer: codex_app_server_protocol::ApprovalsReviewer::AutoReview,diff --git a/codex-rs/protocol/src/protocol.rs b/codex-rs/protocol/src/protocol.rsindex 91fd02d858..fac2616d04 100644--- a/codex-rs/protocol/src/protocol.rs+++ b/codex-rs/protocol/src/protocol.rs@@ -462,6 +462,16 @@ pub enum Op {#[serde(skip_serializing_if = "Option::is_none")]cwd: Option<PathBuf>,+ /// Updated runtime workspace roots used to materialize symbolic+ /// `:workspace_roots` filesystem permissions.+ #[serde(skip_serializing_if = "Option::is_none")]+ workspace_roots: Option<Vec<AbsolutePathBuf>>,++ /// Updated profile-defined workspace roots for status summaries and+ /// per-turn config reconstruction.+ #[serde(skip_serializing_if = "Option::is_none")]+ profile_workspace_roots: Option<Vec<AbsolutePathBuf>>,+/// Updated command approval policy.#[serde(skip_serializing_if = "Option::is_none")]approval_policy: Option<AskForApproval>,diff --git a/codex-rs/tui/src/app/config_persistence.rs b/codex-rs/tui/src/app/config_persistence.rsindex d77e3b3140..8d02e6f1e4 100644--- a/codex-rs/tui/src/app/config_persistence.rs+++ b/codex-rs/tui/src/app/config_persistence.rs@@ -661,6 +661,7 @@ mod tests {permission_profile: PermissionProfile::read_only(),active_permission_profile: None,cwd: next_cwd.clone().abs(),+ runtime_workspace_roots: Vec::new(),instruction_source_paths: Vec::new(),reasoning_effort: None,message_history: None,diff --git a/codex-rs/tui/src/app/tests.rs b/codex-rs/tui/src/app/tests.rsindex dac290e1a5..bbc1802d17 100644--- a/codex-rs/tui/src/app/tests.rs+++ b/codex-rs/tui/src/app/tests.rs@@ -2796,10 +2796,13 @@ async fn inactive_thread_started_notification_initializes_replay_session() -> ReThreadId::from_string("00000000-0000-0000-0000-000000000101").expect("valid thread");let agent_thread_id =ThreadId::from_string("00000000-0000-0000-0000-000000000202").expect("valid thread");+ let primary_cwd = test_path_buf("/tmp/main").abs();+ let shared_root = test_path_buf("/tmp/shared").abs();let primary_session = ThreadSessionState {approval_policy: AskForApproval::OnRequest,permission_profile: PermissionProfile::workspace_write(),- ..test_thread_session(main_thread_id, test_path_buf("/tmp/main"))+ runtime_workspace_roots: vec![primary_cwd.clone(), shared_root.clone()],+ ..test_thread_session(main_thread_id, primary_cwd.to_path_buf())};app.primary_thread_id = Some(main_thread_id);@@ -2871,6 +2874,10 @@ async fn inactive_thread_started_notification_initializes_replay_session() -> Reassert_eq!(session.model_provider_id, "agent-provider");assert_eq!(session.approval_policy, primary_session.approval_policy);assert_eq!(session.cwd.as_path(), test_path_buf("/tmp/agent").as_path());+ assert_eq!(+ session.runtime_workspace_roots,+ vec![test_path_buf("/tmp/agent").abs(), shared_root]+ );assert_eq!(session.rollout_path, Some(rollout_path));assert_eq!(app.agent_navigation.get(&agent_thread_id),@@ -2892,10 +2899,12 @@ async fn inactive_thread_started_notification_preserves_primary_model_when_path_ThreadId::from_string("00000000-0000-0000-0000-000000000301").expect("valid thread");let agent_thread_id =ThreadId::from_string("00000000-0000-0000-0000-000000000302").expect("valid thread");+ let primary_cwd = test_path_buf("/tmp/main").abs();let primary_session = ThreadSessionState {approval_policy: AskForApproval::OnRequest,permission_profile: PermissionProfile::workspace_write(),- ..test_thread_session(main_thread_id, test_path_buf("/tmp/main"))+ runtime_workspace_roots: vec![primary_cwd.clone()],+ ..test_thread_session(main_thread_id, primary_cwd.to_path_buf())};app.primary_thread_id = Some(main_thread_id);@@ -2962,10 +2971,12 @@ async fn thread_read_session_state_does_not_reuse_primary_permission_profile() {ThreadId::from_string("00000000-0000-0000-0000-000000000401").expect("valid thread");let read_thread_id =ThreadId::from_string("00000000-0000-0000-0000-000000000402").expect("valid thread");+ let primary_cwd = test_path_buf("/tmp/main").abs();let primary_session = ThreadSessionState {approval_policy: AskForApproval::OnRequest,permission_profile: PermissionProfile::workspace_write(),- ..test_thread_session(main_thread_id, test_path_buf("/tmp/main"))+ runtime_workspace_roots: vec![primary_cwd.clone()],+ ..test_thread_session(main_thread_id, primary_cwd.to_path_buf())};app.primary_session_configured = Some(primary_session);@@ -2997,6 +3008,10 @@ async fn thread_read_session_state_does_not_reuse_primary_permission_profile() {assert_eq!(session.thread_id, read_thread_id);assert_eq!(session.cwd.as_path(), test_path_buf("/tmp/read").as_path());+ assert_eq!(+ session.runtime_workspace_roots,+ vec![test_path_buf("/tmp/read").abs()]+ );let expected_permission_profile = app.chat_widget.config_ref()@@ -3688,6 +3703,7 @@ async fn render_clear_ui_header_after_long_transcript_for_snapshot() -> String {permission_profile: PermissionProfile::read_only(),active_permission_profile: None,cwd: test_path_buf("/tmp/project").abs(),+ runtime_workspace_roots: Vec::new(),instruction_source_paths: Vec::new(),reasoning_effort: Some(ReasoningEffortConfig::High),message_history: None,@@ -3936,6 +3952,7 @@ fn test_thread_session(thread_id: ThreadId, cwd: PathBuf) -> ThreadSessionStatepermission_profile: PermissionProfile::read_only(),active_permission_profile: None,cwd: cwd.abs(),+ runtime_workspace_roots: Vec::new(),instruction_source_paths: Vec::new(),reasoning_effort: None,message_history: None,@@ -4511,6 +4528,7 @@ async fn backtrack_selection_with_duplicate_history_targets_unique_turn() {permission_profile: PermissionProfile::read_only(),active_permission_profile: None,cwd: test_path_buf("/home/user/project").abs(),+ runtime_workspace_roots: Vec::new(),instruction_source_paths: Vec::new(),reasoning_effort: None,message_history: None,@@ -4574,6 +4592,7 @@ async fn backtrack_selection_with_duplicate_history_targets_unique_turn() {permission_profile: PermissionProfile::read_only(),active_permission_profile: None,cwd: test_path_buf("/home/user/project").abs(),+ runtime_workspace_roots: Vec::new(),instruction_source_paths: Vec::new(),reasoning_effort: None,message_history: None,@@ -4666,6 +4685,7 @@ async fn backtrack_resubmit_preserves_data_image_urls_in_user_turn() {permission_profile: PermissionProfile::read_only(),active_permission_profile: None,cwd: test_path_buf("/home/user/project").abs(),+ runtime_workspace_roots: Vec::new(),instruction_source_paths: Vec::new(),reasoning_effort: None,message_history: None,@@ -4901,6 +4921,7 @@ async fn refreshed_snapshot_session_persists_resumed_turns() {)];let resumed_session = ThreadSessionState {cwd: test_path_buf("/tmp/refreshed").abs(),+ runtime_workspace_roots: Vec::new(),instruction_source_paths: Vec::new(),..initial_session.clone()};@@ -5065,6 +5086,7 @@ async fn new_session_requests_shutdown_for_previous_conversation() {permission_profile: PermissionProfile::read_only(),active_permission_profile: None,cwd: test_path_buf("/home/user/project").abs(),+ runtime_workspace_roots: Vec::new(),instruction_source_paths: Vec::new(),reasoning_effort: None,message_history: None,@@ -5186,6 +5208,7 @@ async fn clear_only_ui_reset_preserves_chat_session_state() {permission_profile: PermissionProfile::read_only(),active_permission_profile: None,cwd: test_path_buf("/tmp/project").abs(),+ runtime_workspace_roots: Vec::new(),instruction_source_paths: Vec::new(),reasoning_effort: None,message_history: None,diff --git a/codex-rs/tui/src/app/thread_events.rs b/codex-rs/tui/src/app/thread_events.rsindex 431bf5f804..30f68dc640 100644--- a/codex-rs/tui/src/app/thread_events.rs+++ b/codex-rs/tui/src/app/thread_events.rs@@ -352,6 +352,7 @@ mod tests {permission_profile: PermissionProfile::read_only(),active_permission_profile: None,cwd: cwd.abs(),+ runtime_workspace_roots: Vec::new(),instruction_source_paths: Vec::new(),reasoning_effort: None,message_history: None,diff --git a/codex-rs/tui/src/app/thread_routing.rs b/codex-rs/tui/src/app/thread_routing.rsindex 9d6cda012d..716f2eedf0 100644--- a/codex-rs/tui/src/app/thread_routing.rs+++ b/codex-rs/tui/src/app/thread_routing.rs@@ -895,7 +895,8 @@ impl App {session.thread_id = thread_id;session.thread_name = notification.thread.name.clone();session.model_provider_id = notification.thread.model_provider.clone();- session.cwd = notification.thread.cwd.clone();+ session+ .set_cwd_retargeting_implicit_runtime_workspace_root(notification.thread.cwd.clone());let rollout_path = notification.thread.path.clone();if let Some(model) =read_session_model(self.state_db.as_deref(), thread_id, rollout_path.as_deref()).awaitdiff --git a/codex-rs/tui/src/app/thread_session_state.rs b/codex-rs/tui/src/app/thread_session_state.rsindex 6afbc2de38..a8d421563b 100644--- a/codex-rs/tui/src/app/thread_session_state.rs+++ b/codex-rs/tui/src/app/thread_session_state.rs@@ -72,6 +72,7 @@ impl App {permission_profile: permission_profile.clone(),active_permission_profile: active_permission_profile.clone(),cwd: thread.cwd.clone(),+ runtime_workspace_roots: self.config.workspace_roots.clone(),instruction_source_paths: Vec::new(),reasoning_effort: self.chat_widget.current_reasoning_effort(),message_history: None,@@ -81,7 +82,7 @@ impl App {session.thread_id = thread_id;session.thread_name = thread.name.clone();session.model_provider_id = thread.model_provider.clone();- session.cwd = thread.cwd.clone();+ session.set_cwd_retargeting_implicit_runtime_workspace_root(thread.cwd.clone());session.permission_profile = permission_profile;session.active_permission_profile = active_permission_profile;session.instruction_source_paths = Vec::new();@@ -148,6 +149,7 @@ mod tests {permission_profile: PermissionProfile::read_only(),active_permission_profile: None,cwd: cwd.abs(),+ runtime_workspace_roots: vec![cwd.abs()],instruction_source_paths: Vec::new(),reasoning_effort: None,message_history: None,diff --git a/codex-rs/tui/src/app_server_session.rs b/codex-rs/tui/src/app_server_session.rsindex 6a0af955ba..0470d24db6 100644--- a/codex-rs/tui/src/app_server_session.rs+++ b/codex-rs/tui/src/app_server_session.rs@@ -34,7 +34,6 @@ use codex_app_server_protocol::MemoryResetResponse;use codex_app_server_protocol::Model as ApiModel;use codex_app_server_protocol::ModelListParams;use codex_app_server_protocol::ModelListResponse;-use codex_app_server_protocol::PermissionProfileModificationParams;use codex_app_server_protocol::PermissionProfileSelectionParams;use codex_app_server_protocol::RateLimitSnapshot;use codex_app_server_protocol::RequestId;@@ -577,6 +576,12 @@ impl AppServerSession {responsesapi_client_metadata: None,environments: None,cwd: Some(cwd),+ runtime_workspace_roots: Some(+ workspace_roots+ .iter()+ .map(AbsolutePathBuf::to_path_buf)+ .collect(),+ ),approval_policy: Some(approval_policy),approvals_reviewer: Some(approvals_reviewer.into()),sandbox_policy,@@ -1175,34 +1180,22 @@ fn sandbox_mode_from_permission_profile(fn permissions_selection_from_active_profile(active: ActivePermissionProfile,- cwd: &std::path::Path,- workspace_roots: &[AbsolutePathBuf],) -> PermissionProfileSelectionParams {- let modifications = workspace_roots- .iter()- .filter(|root| root.as_path() != cwd)- .cloned()- .map(|path| PermissionProfileModificationParams::AdditionalWritableRoot { path })- .collect::<Vec<_>>();- PermissionProfileSelectionParams::Profile {- id: active.id,- modifications: (!modifications.is_empty()).then_some(modifications),- }+ PermissionProfileSelectionParams::new(active.id)}fn turn_permissions_overrides(permission_profile: &PermissionProfile,active_permission_profile: Option<ActivePermissionProfile>,cwd: &std::path::Path,- workspace_roots: &[AbsolutePathBuf],+ _workspace_roots: &[AbsolutePathBuf],thread_params_mode: ThreadParamsMode,) -> (Option<codex_app_server_protocol::SandboxPolicy>,Option<PermissionProfileSelectionParams>,) {let permissions = if matches!(thread_params_mode, ThreadParamsMode::Embedded) {- active_permission_profile- .map(|active| permissions_selection_from_active_profile(active, cwd, workspace_roots))+ active_permission_profile.map(permissions_selection_from_active_profile)} else {None};@@ -1231,13 +1224,7 @@ fn permissions_selection_from_config(config.permissions.active_permission_profile()- .map(|active| {- permissions_selection_from_active_profile(- active,- config.cwd.as_path(),- config.permissions.user_visible_workspace_roots(),- )- })+ .map(permissions_selection_from_active_profile)}fn thread_start_params_from_config(@@ -1261,6 +1248,13 @@ fn thread_start_params_from_config(model_provider: thread_params_mode.model_provider_from_config(config),service_tier: service_tier_override_from_config(config),cwd: thread_cwd_from_config(config, thread_params_mode, remote_cwd_override),+ runtime_workspace_roots: Some(+ config+ .workspace_roots+ .iter()+ .map(AbsolutePathBuf::to_path_buf)+ .collect(),+ ),approval_policy: Some(config.permissions.approval_policy.value().into()),approvals_reviewer: approvals_reviewer_override_from_config(config),sandbox,@@ -1296,6 +1290,13 @@ fn thread_resume_params_from_config(model_provider: thread_params_mode.model_provider_from_config(&config),service_tier: service_tier_override_from_config(&config),cwd: thread_cwd_from_config(&config, thread_params_mode, remote_cwd_override),+ runtime_workspace_roots: Some(+ config+ .workspace_roots+ .iter()+ .map(AbsolutePathBuf::to_path_buf)+ .collect(),+ ),approval_policy: Some(config.permissions.approval_policy.value().into()),approvals_reviewer: approvals_reviewer_override_from_config(&config),sandbox,@@ -1328,6 +1329,13 @@ fn thread_fork_params_from_config(model_provider: thread_params_mode.model_provider_from_config(&config),service_tier: service_tier_override_from_config(&config),cwd: thread_cwd_from_config(&config, thread_params_mode, remote_cwd_override),+ runtime_workspace_roots: Some(+ config+ .workspace_roots+ .iter()+ .map(AbsolutePathBuf::to_path_buf)+ .collect(),+ ),approval_policy: Some(config.permissions.approval_policy.value().into()),approvals_reviewer: approvals_reviewer_override_from_config(&config),sandbox,@@ -1425,6 +1433,7 @@ async fn thread_session_state_from_thread_start_response(permission_profile,response.active_permission_profile.clone().map(Into::into),response.cwd.clone(),+ response.runtime_workspace_roots.clone(),response.instruction_sources.clone(),response.reasoning_effort,config,@@ -1457,6 +1466,7 @@ async fn thread_session_state_from_thread_resume_response(permission_profile,response.active_permission_profile.clone().map(Into::into),response.cwd.clone(),+ response.runtime_workspace_roots.clone(),response.instruction_sources.clone(),response.reasoning_effort,config,@@ -1489,6 +1499,7 @@ async fn thread_session_state_from_thread_fork_response(permission_profile,response.active_permission_profile.clone().map(Into::into),response.cwd.clone(),+ response.runtime_workspace_roots.clone(),response.instruction_sources.clone(),response.reasoning_effort,config,@@ -1531,6 +1542,7 @@ async fn thread_session_state_from_thread_response(permission_profile: PermissionProfile,active_permission_profile: Option<ActivePermissionProfile>,cwd: AbsolutePathBuf,+ runtime_workspace_roots: Vec<AbsolutePathBuf>,instruction_source_paths: Vec<AbsolutePathBuf>,reasoning_effort: Option<codex_protocol::openai_models::ReasoningEffort>,config: &Config,@@ -1558,6 +1570,7 @@ async fn thread_session_state_from_thread_response(permission_profile,active_permission_profile,cwd,+ runtime_workspace_roots,instruction_source_paths,reasoning_effort,message_history: Some(MessageHistoryMetadata {@@ -1637,19 +1650,23 @@ mod tests {);assert_eq!(params.cwd, Some(config.cwd.to_string_lossy().to_string()));+ assert_eq!(+ params.runtime_workspace_roots,+ Some(+ config+ .workspace_roots+ .iter()+ .map(AbsolutePathBuf::to_path_buf)+ .collect()+ )+ );assert_eq!(params.sandbox, None);assert_eq!(params.permissions,config.permissions.active_permission_profile()- .map(|active| {- permissions_selection_from_active_profile(- active,- config.cwd.as_path(),- config.permissions.user_visible_workspace_roots(),- )- })+ .map(permissions_selection_from_active_profile));assert_eq!(params.model_provider, Some(config.model_provider_id));assert_eq!(params.thread_source, Some(ThreadSource::User));@@ -1676,11 +1693,8 @@ mod tests {let active_permission_profile =ActivePermissionProfile::new(BUILT_IN_PERMISSION_PROFILE_WORKSPACE);let workspace_roots = vec![cwd.clone()];- let expected_permissions = permissions_selection_from_active_profile(- active_permission_profile.clone(),- cwd.as_path(),- &workspace_roots,- );+ let expected_permissions =+ permissions_selection_from_active_profile(active_permission_profile.clone());let (sandbox_policy, permissions) = turn_permissions_overrides(&PermissionProfile::workspace_write(),@@ -1695,12 +1709,12 @@ mod tests {}#[test]- fn embedded_turn_permissions_include_extra_workspace_roots_as_modifications() {+ fn embedded_turn_permissions_select_profile_id_only() {let cwd = test_path_buf("/workspace/project").abs();let extra_root = test_path_buf("/workspace/cache").abs();let active_permission_profile =ActivePermissionProfile::new(BUILT_IN_PERMISSION_PROFILE_WORKSPACE);- let workspace_roots = vec![cwd.clone(), extra_root.clone()];+ let workspace_roots = vec![cwd.clone(), extra_root];let (sandbox_policy, permissions) = turn_permissions_overrides(&PermissionProfile::workspace_write(),@@ -1713,14 +1727,9 @@ mod tests {assert_eq!(sandbox_policy, None);assert_eq!(permissions,- Some(PermissionProfileSelectionParams::Profile {- id: BUILT_IN_PERMISSION_PROFILE_WORKSPACE.to_string(),- modifications: Some(vec![- PermissionProfileModificationParams::AdditionalWritableRoot {- path: extra_root- }- ]),- })+ Some(PermissionProfileSelectionParams::new(+ BUILT_IN_PERMISSION_PROFILE_WORKSPACE+ )));}@@ -1777,6 +1786,13 @@ mod tests {&config.permissions.effective_permission_profile(),config.cwd.as_path(),);+ let expected_runtime_workspace_roots = Some(+ config+ .workspace_roots+ .iter()+ .map(AbsolutePathBuf::to_path_buf)+ .collect::<Vec<_>>(),+ );let start = thread_start_params_from_config(&config,@@ -1800,6 +1816,18 @@ mod tests {assert_eq!(start.cwd, None);assert_eq!(resume.cwd, None);assert_eq!(fork.cwd, None);+ assert_eq!(+ start.runtime_workspace_roots,+ expected_runtime_workspace_roots+ );+ assert_eq!(+ resume.runtime_workspace_roots,+ expected_runtime_workspace_roots+ );+ assert_eq!(+ fork.runtime_workspace_roots,+ expected_runtime_workspace_roots+ );assert_eq!(start.model_provider, None);assert_eq!(resume.model_provider, None);assert_eq!(fork.model_provider, None);@@ -2070,6 +2098,10 @@ mod tests {model_provider: "openai".to_string(),service_tier: None,cwd: test_path_buf("/tmp/project").abs(),+ runtime_workspace_roots: vec![+ test_path_buf("/tmp/project").abs(),+ test_path_buf("/tmp/project/extra").abs(),+ ],instruction_sources: vec![test_path_buf("/tmp/project/AGENTS.md").abs()],approval_policy: codex_app_server_protocol::AskForApproval::Never,approvals_reviewer: codex_app_server_protocol::ApprovalsReviewer::User,@@ -2090,6 +2122,10 @@ mod tests {.await.expect("resume response should map");assert_eq!(started.session.forked_from_id, Some(forked_from_id));+ assert_eq!(+ started.session.runtime_workspace_roots,+ response.runtime_workspace_roots+ );assert_eq!(started.session.instruction_source_paths,response.instruction_sources@@ -2097,6 +2133,17 @@ mod tests {assert_eq!(started.session.permission_profile, read_only_profile);assert_eq!(started.turns.len(), 1);assert_eq!(started.turns[0], response.thread.turns[0]);++ let mut empty_roots_response = response;+ empty_roots_response.runtime_workspace_roots = Vec::new();+ let started = started_thread_from_resume_response(+ empty_roots_response,+ &config,+ ThreadParamsMode::Remote,+ )+ .await+ .expect("resume response should map");+ assert_eq!(started.session.runtime_workspace_roots, Vec::new());}#[tokio::test]@@ -2193,6 +2240,7 @@ mod tests {/*active_permission_profile*/ None,test_path_buf("/tmp/project").abs(),Vec::new(),+ Vec::new(),/*reasoning_effort*/ None,&config,)@@ -2227,6 +2275,7 @@ mod tests {/*active_permission_profile*/ None,test_path_buf("/tmp/project").abs(),Vec::new(),+ Vec::new(),/*reasoning_effort*/ None,&config,)diff --git a/codex-rs/tui/src/chatwidget/session_flow.rs b/codex-rs/tui/src/chatwidget/session_flow.rsindex 932263bcc1..5dfb2090f7 100644--- a/codex-rs/tui/src/chatwidget/session_flow.rs+++ b/codex-rs/tui/src/chatwidget/session_flow.rs@@ -32,26 +32,12 @@ impl ChatWidget {self.forked_from = session.forked_from_id;self.current_rollout_path = session.rollout_path.clone();self.current_cwd = Some(session.cwd.to_path_buf());- let previous_cwd = self.config.cwd.clone();- let previous_workspace_roots = self.config.workspace_roots.clone();self.config.cwd = session.cwd.clone();- if !self.config.workspace_roots_explicit {- let mut workspace_roots = vec![session.cwd.clone()];- if previous_workspace_roots- .iter()- .any(|root| root == &previous_cwd)- {- for root in previous_workspace_roots {- if root != previous_cwd- && !workspace_roots.iter().any(|existing| existing == &root)- {- workspace_roots.push(root);- }- }- }- self.config.workspace_roots = workspace_roots.clone();- self.config.permissions.set_workspace_roots(workspace_roots);- }+ let runtime_workspace_roots = session.runtime_workspace_roots.clone();+ self.config.workspace_roots = runtime_workspace_roots.clone();+ self.config+ .permissions+ .set_workspace_roots(runtime_workspace_roots);self.effective_service_tier = session.service_tier.clone();if let Err(err) = self.configdiff --git a/codex-rs/tui/src/chatwidget/tests/composer_submission.rs b/codex-rs/tui/src/chatwidget/tests/composer_submission.rsindex 95e8317e9c..96477c8d38 100644--- a/codex-rs/tui/src/chatwidget/tests/composer_submission.rs+++ b/codex-rs/tui/src/chatwidget/tests/composer_submission.rs@@ -28,6 +28,7 @@ async fn submission_preserves_text_elements_and_local_images() {permission_profile: PermissionProfile::read_only(),active_permission_profile: None,cwd: test_path_buf("/home/user/project").abs(),+ runtime_workspace_roots: Vec::new(),instruction_source_paths: Vec::new(),reasoning_effort: Some(ReasoningEffortConfig::default()),message_history: None,@@ -131,6 +132,7 @@ async fn submission_includes_configured_permission_profile() {permission_profile: expected_permission_profile.clone(),active_permission_profile: None,cwd: test_path_buf("/home/user/project").abs(),+ runtime_workspace_roots: Vec::new(),instruction_source_paths: Vec::new(),reasoning_effort: Some(ReasoningEffortConfig::default()),message_history: None,@@ -180,6 +182,7 @@ async fn submission_keeps_profile_when_legacy_projection_is_external() {permission_profile: expected_permission_profile.clone(),active_permission_profile: None,cwd: test_path_buf("/home/user/project").abs(),+ runtime_workspace_roots: Vec::new(),instruction_source_paths: Vec::new(),reasoning_effort: Some(ReasoningEffortConfig::default()),message_history: None,@@ -221,6 +224,7 @@ async fn submission_with_remote_and_local_images_keeps_local_placeholder_numberipermission_profile: PermissionProfile::read_only(),active_permission_profile: None,cwd: test_path_buf("/home/user/project").abs(),+ runtime_workspace_roots: Vec::new(),instruction_source_paths: Vec::new(),reasoning_effort: Some(ReasoningEffortConfig::default()),message_history: None,@@ -314,6 +318,7 @@ async fn enter_with_only_remote_images_submits_user_turn() {permission_profile: PermissionProfile::read_only(),active_permission_profile: None,cwd: test_path_buf("/home/user/project").abs(),+ runtime_workspace_roots: Vec::new(),instruction_source_paths: Vec::new(),reasoning_effort: Some(ReasoningEffortConfig::default()),message_history: None,@@ -377,6 +382,7 @@ async fn shift_enter_with_only_remote_images_does_not_submit_user_turn() {permission_profile: PermissionProfile::read_only(),active_permission_profile: None,cwd: test_path_buf("/home/user/project").abs(),+ runtime_workspace_roots: Vec::new(),instruction_source_paths: Vec::new(),reasoning_effort: Some(ReasoningEffortConfig::default()),message_history: None,@@ -415,6 +421,7 @@ async fn enter_with_only_remote_images_does_not_submit_when_modal_is_active() {permission_profile: PermissionProfile::read_only(),active_permission_profile: None,cwd: test_path_buf("/home/user/project").abs(),+ runtime_workspace_roots: Vec::new(),instruction_source_paths: Vec::new(),reasoning_effort: Some(ReasoningEffortConfig::default()),message_history: None,@@ -453,6 +460,7 @@ async fn enter_with_only_remote_images_does_not_submit_when_input_disabled() {permission_profile: PermissionProfile::read_only(),active_permission_profile: None,cwd: test_path_buf("/home/user/project").abs(),+ runtime_workspace_roots: Vec::new(),instruction_source_paths: Vec::new(),reasoning_effort: Some(ReasoningEffortConfig::default()),message_history: None,@@ -494,6 +502,7 @@ async fn submission_prefers_selected_duplicate_skill_path() {permission_profile: PermissionProfile::read_only(),active_permission_profile: None,cwd: test_path_buf("/home/user/project").abs(),+ runtime_workspace_roots: Vec::new(),instruction_source_paths: Vec::new(),reasoning_effort: Some(ReasoningEffortConfig::default()),message_history: None,diff --git a/codex-rs/tui/src/chatwidget/tests/exec_flow.rs b/codex-rs/tui/src/chatwidget/tests/exec_flow.rsindex 2655c8cf95..d54783615c 100644--- a/codex-rs/tui/src/chatwidget/tests/exec_flow.rs+++ b/codex-rs/tui/src/chatwidget/tests/exec_flow.rs@@ -957,6 +957,7 @@ async fn bang_shell_enter_while_task_running_submits_run_user_shell_command() {permission_profile: PermissionProfile::read_only(),active_permission_profile: None,cwd: test_path_buf("/home/user/project").abs(),+ runtime_workspace_roots: Vec::new(),instruction_source_paths: Vec::new(),reasoning_effort: Some(ReasoningEffortConfig::default()),message_history: None,diff --git a/codex-rs/tui/src/chatwidget/tests/history_replay.rs b/codex-rs/tui/src/chatwidget/tests/history_replay.rsindex 6e3ead97bb..8282430306 100644--- a/codex-rs/tui/src/chatwidget/tests/history_replay.rs+++ b/codex-rs/tui/src/chatwidget/tests/history_replay.rs@@ -29,6 +29,7 @@ async fn resumed_initial_messages_render_history() {permission_profile: PermissionProfile::read_only(),active_permission_profile: None,cwd: test_path_buf("/home/user/project").abs(),+ runtime_workspace_roots: Vec::new(),instruction_source_paths: Vec::new(),reasoning_effort: Some(ReasoningEffortConfig::default()),message_history: None,@@ -99,6 +100,7 @@ async fn replayed_user_message_preserves_text_elements_and_local_images() {permission_profile: PermissionProfile::read_only(),active_permission_profile: None,cwd: test_path_buf("/home/user/project").abs(),+ runtime_workspace_roots: Vec::new(),instruction_source_paths: Vec::new(),reasoning_effort: Some(ReasoningEffortConfig::default()),message_history: None,@@ -167,6 +169,7 @@ async fn replayed_user_message_preserves_remote_image_urls() {permission_profile: PermissionProfile::read_only(),active_permission_profile: None,cwd: test_path_buf("/home/user/project").abs(),+ runtime_workspace_roots: Vec::new(),instruction_source_paths: Vec::new(),reasoning_effort: Some(ReasoningEffortConfig::default()),message_history: None,@@ -266,6 +269,7 @@ async fn session_configured_syncs_widget_config_permissions_and_cwd() {permission_profile: expected_permission_profile,active_permission_profile: None,cwd: expected_cwd.clone(),+ runtime_workspace_roots: vec![expected_cwd.clone()],instruction_source_paths: Vec::new(),reasoning_effort: Some(ReasoningEffortConfig::default()),message_history: None,@@ -300,7 +304,7 @@ async fn session_configured_syncs_widget_config_permissions_and_cwd() {assert_eq!(chat.config_ref().permissions.effective_permission_profile(),updated_profile- .materialize_project_roots_with_workspace_roots(std::slice::from_ref(&expected_cwd)),+ .materialize_project_roots_with_workspace_roots(std::slice::from_ref(&expected_cwd,)),"effective permissions should still use the current thread runtime workspace roots");}@@ -319,9 +323,10 @@ async fn session_configured_preserves_profile_workspace_roots() {.set_workspace_roots(chat.config.workspace_roots.clone());let session_cwd = test_path_buf("/home/user/sub-agent").abs();- let session_workspace_roots = vec![session_cwd.clone(), profile_root];+ let session_runtime_workspace_roots = vec![session_cwd.clone()];+ let session_effective_workspace_roots = vec![session_cwd.clone(), profile_root];let session_permission_profile = PermissionProfile::workspace_write()- .materialize_project_roots_with_workspace_roots(&session_workspace_roots);+ .materialize_project_roots_with_workspace_roots(&session_effective_workspace_roots);let configured = crate::session_state::ThreadSessionState {thread_id: ThreadId::new(),forked_from_id: None,@@ -335,6 +340,7 @@ async fn session_configured_preserves_profile_workspace_roots() {permission_profile: session_permission_profile.clone(),active_permission_profile: None,cwd: session_cwd.clone(),+ runtime_workspace_roots: session_runtime_workspace_roots.clone(),instruction_source_paths: Vec::new(),reasoning_effort: Some(ReasoningEffortConfig::default()),message_history: None,@@ -347,7 +353,7 @@ async fn session_configured_preserves_profile_workspace_roots() {assert_eq!(&chat.config_ref().cwd, &session_cwd);assert_eq!(chat.config_ref().permissions.user_visible_workspace_roots(),- session_workspace_roots.as_slice()+ session_runtime_workspace_roots.as_slice());assert_eq!(chat.config_ref().permissions.effective_permission_profile(),@@ -380,6 +386,7 @@ async fn session_configured_external_sandbox_keeps_external_runtime_policy() {permission_profile: expected_permission_profile,active_permission_profile: None,cwd: test_path_buf("/home/user/external").abs(),+ runtime_workspace_roots: Vec::new(),instruction_source_paths: Vec::new(),reasoning_effort: Some(ReasoningEffortConfig::default()),message_history: None,@@ -420,6 +427,7 @@ async fn replayed_user_message_with_only_remote_images_renders_history_cell() {permission_profile: PermissionProfile::read_only(),active_permission_profile: None,cwd: test_path_buf("/home/user/project").abs(),+ runtime_workspace_roots: Vec::new(),instruction_source_paths: Vec::new(),reasoning_effort: Some(ReasoningEffortConfig::default()),message_history: None,@@ -474,6 +482,7 @@ async fn replayed_user_message_with_only_local_images_renders_history_cell() {permission_profile: PermissionProfile::read_only(),active_permission_profile: None,cwd: test_path_buf("/home/user/project").abs(),+ runtime_workspace_roots: Vec::new(),instruction_source_paths: Vec::new(),reasoning_effort: Some(ReasoningEffortConfig::default()),message_history: None,@@ -744,6 +753,7 @@ async fn replayed_reasoning_item_hides_raw_reasoning_when_disabled() {permission_profile: PermissionProfile::read_only(),active_permission_profile: None,cwd: test_project_path().abs(),+ runtime_workspace_roots: Vec::new(),instruction_source_paths: Vec::new(),reasoning_effort: None,message_history: None,@@ -789,6 +799,7 @@ async fn replayed_reasoning_item_shows_raw_reasoning_when_enabled() {permission_profile: PermissionProfile::read_only(),active_permission_profile: None,cwd: test_project_path().abs(),+ runtime_workspace_roots: Vec::new(),instruction_source_paths: Vec::new(),reasoning_effort: None,message_history: None,diff --git a/codex-rs/tui/src/chatwidget/tests/permissions.rs b/codex-rs/tui/src/chatwidget/tests/permissions.rsindex df3615c0fd..4c66041271 100644--- a/codex-rs/tui/src/chatwidget/tests/permissions.rs+++ b/codex-rs/tui/src/chatwidget/tests/permissions.rs@@ -584,6 +584,7 @@ async fn permissions_selection_marks_auto_review_current_after_session_configurepermission_profile: PermissionProfile::workspace_write(),active_permission_profile: None,cwd: test_project_path().abs(),+ runtime_workspace_roots: Vec::new(),instruction_source_paths: Vec::new(),reasoning_effort: None,message_history: None,@@ -631,6 +632,7 @@ async fn permissions_selection_marks_auto_review_current_with_custom_workspace_wpermission_profile,active_permission_profile: None,cwd,+ runtime_workspace_roots: Vec::new(),instruction_source_paths: Vec::new(),reasoning_effort: None,message_history: None,diff --git a/codex-rs/tui/src/chatwidget/tests/plan_mode.rs b/codex-rs/tui/src/chatwidget/tests/plan_mode.rsindex e9fdb6d987..b97695e800 100644--- a/codex-rs/tui/src/chatwidget/tests/plan_mode.rs+++ b/codex-rs/tui/src/chatwidget/tests/plan_mode.rs@@ -1217,6 +1217,7 @@ async fn submit_user_message_emits_structured_plugin_mentions_from_bindings() {permission_profile: PermissionProfile::read_only(),active_permission_profile: None,cwd: test_path_buf("/home/user/project").abs(),+ runtime_workspace_roots: Vec::new(),instruction_source_paths: Vec::new(),reasoning_effort: Some(ReasoningEffortConfig::default()),message_history: None,@@ -1403,6 +1404,7 @@ async fn plan_slash_command_with_args_submits_prompt_in_plan_mode() {permission_profile: PermissionProfile::read_only(),active_permission_profile: None,cwd: test_path_buf("/home/user/project").abs(),+ runtime_workspace_roots: Vec::new(),instruction_source_paths: Vec::new(),reasoning_effort: Some(ReasoningEffortConfig::default()),message_history: None,diff --git a/codex-rs/tui/src/chatwidget/tests/status_and_layout.rs b/codex-rs/tui/src/chatwidget/tests/status_and_layout.rsindex 53b60e0d8d..acd6b7111b 100644--- a/codex-rs/tui/src/chatwidget/tests/status_and_layout.rs+++ b/codex-rs/tui/src/chatwidget/tests/status_and_layout.rs@@ -2230,6 +2230,7 @@ async fn session_configured_clears_goal_status_footer() {permission_profile: PermissionProfile::read_only(),active_permission_profile: None,cwd: test_path_buf("/home/user/project").abs(),+ runtime_workspace_roots: Vec::new(),instruction_source_paths: Vec::new(),reasoning_effort: Some(ReasoningEffortConfig::default()),message_history: None,diff --git a/codex-rs/tui/src/history_cell/tests.rs b/codex-rs/tui/src/history_cell/tests.rsindex f8c25c9670..8ea7af5d32 100644--- a/codex-rs/tui/src/history_cell/tests.rs+++ b/codex-rs/tui/src/history_cell/tests.rs@@ -448,6 +448,7 @@ fn session_configured_event(model: &str) -> ThreadSessionState {permission_profile: PermissionProfile::read_only(),active_permission_profile: None,cwd: test_path_buf("/tmp/project").abs(),+ runtime_workspace_roots: Vec::new(),instruction_source_paths: Vec::new(),reasoning_effort: None,message_history: None,diff --git a/codex-rs/tui/src/session_state.rs b/codex-rs/tui/src/session_state.rsindex e4d2dbab96..eee682fd79 100644--- a/codex-rs/tui/src/session_state.rs+++ b/codex-rs/tui/src/session_state.rs@@ -42,9 +42,30 @@ pub(crate) struct ThreadSessionState {/// when the server knows it.pub(crate) active_permission_profile: Option<ActivePermissionProfile>,pub(crate) cwd: AbsolutePathBuf,+ pub(crate) runtime_workspace_roots: Vec<AbsolutePathBuf>,pub(crate) instruction_source_paths: Vec<AbsolutePathBuf>,pub(crate) reasoning_effort: Option<codex_protocol::openai_models::ReasoningEffort>,pub(crate) message_history: Option<MessageHistoryMetadata>,pub(crate) network_proxy: Option<SessionNetworkProxyRuntime>,pub(crate) rollout_path: Option<PathBuf>,}++impl ThreadSessionState {+ pub(crate) fn set_cwd_retargeting_implicit_runtime_workspace_root(+ &mut self,+ cwd: AbsolutePathBuf,+ ) {+ let previous_cwd = std::mem::replace(&mut self.cwd, cwd.clone());+ if !self.runtime_workspace_roots.contains(&previous_cwd) {+ return;+ }++ let previous_roots = std::mem::take(&mut self.runtime_workspace_roots);+ self.runtime_workspace_roots.push(cwd);+ for root in previous_roots {+ if root != previous_cwd && !self.runtime_workspace_roots.contains(&root) {+ self.runtime_workspace_roots.push(root);+ }+ }+ }+}