Skip to content

Commit 13ed67c

Browse files
authored
feat: introduce TurnContext (#2343)
This PR introduces `TurnContext`, which is designed to hold a set of fields that should be constant for a turn of a conversation. Note that the fields of `TurnContext` were previously governed by `Session`. Ultimately, we want to enable users to change these values between turns (changing model, approval policy, etc.), though in the current implementation, the `TurnContext` is constant for the entire conversation. --- [//]: # (BEGIN SAPLING FOOTER) Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/openai/codex/pull/2345). * #2345 * #2329 * __->__ #2343 * #2340 * #2338
1 parent 45d6c74 commit 13ed67c

File tree

3 files changed

+175
-104
lines changed

3 files changed

+175
-104
lines changed

codex-rs/core/src/apply_patch.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::codex::Session;
2+
use crate::codex::TurnContext;
23
use crate::models::FunctionCallOutputPayload;
34
use crate::models::ResponseInputItem;
45
use crate::protocol::FileChange;
@@ -40,15 +41,16 @@ impl From<ResponseInputItem> for InternalApplyPatchInvocation {
4041

4142
pub(crate) async fn apply_patch(
4243
sess: &Session,
44+
turn_context: &TurnContext,
4345
sub_id: &str,
4446
call_id: &str,
4547
action: ApplyPatchAction,
4648
) -> InternalApplyPatchInvocation {
4749
match assess_patch_safety(
4850
&action,
49-
sess.get_approval_policy(),
50-
sess.get_sandbox_policy(),
51-
sess.get_cwd(),
51+
turn_context.approval_policy,
52+
&turn_context.sandbox_policy,
53+
&turn_context.cwd,
5254
) {
5355
SafetyCheck::AutoApprove { .. } => {
5456
InternalApplyPatchInvocation::DelegateToExec(ApplyPatchExec {

codex-rs/core/src/client.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ struct Error {
5656
message: Option<String>,
5757
}
5858

59-
#[derive(Clone)]
59+
#[derive(Debug, Clone)]
6060
pub struct ModelClient {
6161
config: Arc<Config>,
6262
auth: Option<CodexAuth>,

0 commit comments

Comments
 (0)