Skip to content

Commit 04561f0

Browse files
charley-oaicodex
andcommitted
Standardize model-visible fragments
Fold Apps, Skills, and Plugins into the model-visible fragment registry as ordered developer-envelope fragments, keep the turn-state/contextual-user framework intact, and refresh prompt layout snapshots/docs around the new shape. Co-authored-by: Codex <noreply@openai.com>
1 parent 6fd7050 commit 04561f0

File tree

94 files changed

+3295
-2069
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+3295
-2069
lines changed

AGENTS.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,23 @@ In the codex-rs folder where the rust code lives:
3636
- When extracting code from a large module, move the related tests and module/type docs toward
3737
the new implementation so the invariants stay close to the code that owns them.
3838

39+
### Model-visible context fragments
40+
41+
- Model-visible prompt context should go through the shared fragment abstractions described in `docs/model-visible-context.md`.
42+
- Every named fragment type should implement `ModelVisibleContextFragment` and set `type Role`.
43+
- Turn-state model-visible context assembly should produce exactly two envelopes (one developer message + one contextual-user message) via the shared envelope builders.
44+
- Define and register current fragment types in `codex-rs/core/src/model_visible_fragments.rs`. `REGISTERED_MODEL_VISIBLE_FRAGMENTS` is the integration point for contextual-user detection and registry-driven turn-state assembly.
45+
- If a fragment represents durable turn/session state that should be rebuilt correctly across resume/fork/compaction/backtracking, implement `ModelVisibleContextFragment::build(...)`.
46+
- If a fragment is contextual-user, it must provide stable detection: prefer `contextual_user_markers()` when fixed markers are sufficient, and override `matches_contextual_user_text()` only for genuinely custom matching (for example AGENTS.md).
47+
- Use the developer envelope for developer guidance. Custom override text (for example config/app-server `developer_instructions`) should use `CustomDeveloperInstructions`; system-generated developer context should use typed fragments plus the neutral `developer_*_text` helpers rather than reusing the custom override type.
48+
- Use contextual-user fragments for contextual user-role state. Turn-state contextual-user fragments such as custom user instructions, AGENTS instructions, JS REPL guidance, child-agent guidance, and environment context belong in the contextual-user envelope. Runtime contextual-user fragments should still use typed fragments so history parsing treats them as contextual state rather than user intent; examples include skills triggered at runtime, shell-command records, and turn-aborted notices.
49+
- Use `<environment_context>` specifically for environment facts derived from `TurnContext` that may need turn-to-turn diffs (`cwd`, `shell`, optional `current_date`, optional `timezone`, optional network allow/deny domain summaries). Do not put policy text, plugin/skill listings, or other guidance into `<environment_context>`; those should use dedicated fragments.
50+
- Runtime/session-prefix fragments that are not turn-state diffs should usually leave `ModelVisibleContextFragment::build(...)` as `None`.
51+
- Register every current fragment exactly once in `REGISTERED_MODEL_VISIBLE_FRAGMENTS`, in the rough order it should appear in model-visible context.
52+
- Prefer dedicated typed fragments over plain strings. Developer-only one-off text is acceptable only when it is truly isolated, does not need contextual-user detection, and does not participate in turn-state diff reconstruction.
53+
- Do not hand-construct model-visible `ResponseItem::Message` payloads in new turn-state code; use fragment conversion and the shared envelope builders.
54+
- Do not inject raw strings directly into the initial-context or settings-update builders, and do not call fragment wrapping helpers ad hoc from new code.
55+
3956
Run `just fmt` (in `codex-rs` directory) automatically after you have finished making Rust code changes; do not ask for approval to run it. Additionally, run the tests:
4057

4158
1. Run the test for the specific project that was changed. For example, if changes were made in `codex-rs/tui`, run `cargo test -p codex-tui`.

codex-rs/app-server-protocol/schema/json/ClientRequest.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2547,6 +2547,7 @@
25472547
]
25482548
},
25492549
"developerInstructions": {
2550+
"description": "Custom developer override for this thread session. Takes precedence over `~/.codex/config.toml` `developer_instructions`.",
25502551
"type": [
25512552
"string",
25522553
"null"
@@ -2795,7 +2796,7 @@
27952796
"type": "object"
27962797
},
27972798
"ThreadResumeParams": {
2798-
"description": "There are three ways to resume a thread: 1. By thread_id: load the thread from disk by thread_id and resume it. 2. By history: instantiate the thread from memory and resume it. 3. By path: load the thread from disk by path and resume it.\n\nThe precedence is: history > path > thread_id. If using history or path, the thread_id param will be ignored.\n\nPrefer using thread_id whenever possible.",
2799+
"description": "There are three ways to resume a thread: 1. By thread_id: load the thread from disk by thread_id and resume it. 2. By history: instantiate the thread from memory and resume it. 3. By path: load the thread from disk by path and resume it.\n\nThe precedence is: history > path > thread_id. If using history or path, the thread_id param will be ignored.\n\nPrefer using thread_id whenever possible.\n\nWhen resuming a thread that is already loaded/running, override fields are ignored and reported as mismatch warnings rather than being reapplied mid-session.",
27992800
"properties": {
28002801
"approvalPolicy": {
28012802
"anyOf": [
@@ -2838,6 +2839,7 @@
28382839
]
28392840
},
28402841
"developerInstructions": {
2842+
"description": "Custom developer override for this thread session. Takes precedence over `~/.codex/config.toml` `developer_instructions`.",
28412843
"type": [
28422844
"string",
28432845
"null"
@@ -3000,6 +3002,7 @@
30003002
]
30013003
},
30023004
"developerInstructions": {
3005+
"description": "Custom developer override for this thread session. Takes precedence over `~/.codex/config.toml` `developer_instructions`.",
30033006
"type": [
30043007
"string",
30053008
"null"

codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.schemas.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11863,6 +11863,7 @@
1186311863
]
1186411864
},
1186511865
"developerInstructions": {
11866+
"description": "Custom developer override for this thread session. Takes precedence over `~/.codex/config.toml` `developer_instructions`.",
1186611867
"type": [
1186711868
"string",
1186811869
"null"
@@ -12958,7 +12959,7 @@
1295812959
},
1295912960
"ThreadResumeParams": {
1296012961
"$schema": "http://json-schema.org/draft-07/schema#",
12961-
"description": "There are three ways to resume a thread: 1. By thread_id: load the thread from disk by thread_id and resume it. 2. By history: instantiate the thread from memory and resume it. 3. By path: load the thread from disk by path and resume it.\n\nThe precedence is: history > path > thread_id. If using history or path, the thread_id param will be ignored.\n\nPrefer using thread_id whenever possible.",
12962+
"description": "There are three ways to resume a thread: 1. By thread_id: load the thread from disk by thread_id and resume it. 2. By history: instantiate the thread from memory and resume it. 3. By path: load the thread from disk by path and resume it.\n\nThe precedence is: history > path > thread_id. If using history or path, the thread_id param will be ignored.\n\nPrefer using thread_id whenever possible.\n\nWhen resuming a thread that is already loaded/running, override fields are ignored and reported as mismatch warnings rather than being reapplied mid-session.",
1296212963
"properties": {
1296312964
"approvalPolicy": {
1296412965
"anyOf": [
@@ -13001,6 +13002,7 @@
1300113002
]
1300213003
},
1300313004
"developerInstructions": {
13005+
"description": "Custom developer override for this thread session. Takes precedence over `~/.codex/config.toml` `developer_instructions`.",
1300413006
"type": [
1300513007
"string",
1300613008
"null"
@@ -13254,6 +13256,7 @@
1325413256
]
1325513257
},
1325613258
"developerInstructions": {
13259+
"description": "Custom developer override for this thread session. Takes precedence over `~/.codex/config.toml` `developer_instructions`.",
1325713260
"type": [
1325813261
"string",
1325913262
"null"

codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.v2.schemas.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9580,6 +9580,7 @@
95809580
]
95819581
},
95829582
"developerInstructions": {
9583+
"description": "Custom developer override for this thread session. Takes precedence over `~/.codex/config.toml` `developer_instructions`.",
95839584
"type": [
95849585
"string",
95859586
"null"
@@ -10675,7 +10676,7 @@
1067510676
},
1067610677
"ThreadResumeParams": {
1067710678
"$schema": "http://json-schema.org/draft-07/schema#",
10678-
"description": "There are three ways to resume a thread: 1. By thread_id: load the thread from disk by thread_id and resume it. 2. By history: instantiate the thread from memory and resume it. 3. By path: load the thread from disk by path and resume it.\n\nThe precedence is: history > path > thread_id. If using history or path, the thread_id param will be ignored.\n\nPrefer using thread_id whenever possible.",
10679+
"description": "There are three ways to resume a thread: 1. By thread_id: load the thread from disk by thread_id and resume it. 2. By history: instantiate the thread from memory and resume it. 3. By path: load the thread from disk by path and resume it.\n\nThe precedence is: history > path > thread_id. If using history or path, the thread_id param will be ignored.\n\nPrefer using thread_id whenever possible.\n\nWhen resuming a thread that is already loaded/running, override fields are ignored and reported as mismatch warnings rather than being reapplied mid-session.",
1067910680
"properties": {
1068010681
"approvalPolicy": {
1068110682
"anyOf": [
@@ -10718,6 +10719,7 @@
1071810719
]
1071910720
},
1072010721
"developerInstructions": {
10722+
"description": "Custom developer override for this thread session. Takes precedence over `~/.codex/config.toml` `developer_instructions`.",
1072110723
"type": [
1072210724
"string",
1072310725
"null"
@@ -10971,6 +10973,7 @@
1097110973
]
1097210974
},
1097310975
"developerInstructions": {
10976+
"description": "Custom developer override for this thread session. Takes precedence over `~/.codex/config.toml` `developer_instructions`.",
1097410977
"type": [
1097510978
"string",
1097610979
"null"

codex-rs/app-server-protocol/schema/json/v2/ThreadForkParams.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@
118118
]
119119
},
120120
"developerInstructions": {
121+
"description": "Custom developer override for this thread session. Takes precedence over `~/.codex/config.toml` `developer_instructions`.",
121122
"type": [
122123
"string",
123124
"null"

codex-rs/app-server-protocol/schema/json/v2/ThreadResumeParams.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -998,7 +998,7 @@
998998
"type": "string"
999999
}
10001000
},
1001-
"description": "There are three ways to resume a thread: 1. By thread_id: load the thread from disk by thread_id and resume it. 2. By history: instantiate the thread from memory and resume it. 3. By path: load the thread from disk by path and resume it.\n\nThe precedence is: history > path > thread_id. If using history or path, the thread_id param will be ignored.\n\nPrefer using thread_id whenever possible.",
1001+
"description": "There are three ways to resume a thread: 1. By thread_id: load the thread from disk by thread_id and resume it. 2. By history: instantiate the thread from memory and resume it. 3. By path: load the thread from disk by path and resume it.\n\nThe precedence is: history > path > thread_id. If using history or path, the thread_id param will be ignored.\n\nPrefer using thread_id whenever possible.\n\nWhen resuming a thread that is already loaded/running, override fields are ignored and reported as mismatch warnings rather than being reapplied mid-session.",
10021002
"properties": {
10031003
"approvalPolicy": {
10041004
"anyOf": [
@@ -1041,6 +1041,7 @@
10411041
]
10421042
},
10431043
"developerInstructions": {
1044+
"description": "Custom developer override for this thread session. Takes precedence over `~/.codex/config.toml` `developer_instructions`.",
10441045
"type": [
10451046
"string",
10461047
"null"

codex-rs/app-server-protocol/schema/json/v2/ThreadStartParams.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@
142142
]
143143
},
144144
"developerInstructions": {
145+
"description": "Custom developer override for this thread session. Takes precedence over `~/.codex/config.toml` `developer_instructions`.",
145146
"type": [
146147
"string",
147148
"null"

codex-rs/app-server-protocol/schema/typescript/v2/ThreadForkParams.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ model?: string | null, modelProvider?: string | null, serviceTier?: ServiceTier
2727
* Override where approval requests are routed for review on this thread
2828
* and subsequent turns.
2929
*/
30-
approvalsReviewer?: ApprovalsReviewer | null, sandbox?: SandboxMode | null, config?: { [key in string]?: JsonValue } | null, baseInstructions?: string | null, developerInstructions?: string | null, ephemeral?: boolean, /**
30+
approvalsReviewer?: ApprovalsReviewer | null, sandbox?: SandboxMode | null, config?: { [key in string]?: JsonValue } | null, baseInstructions?: string | null, /**
31+
* Custom developer override for this thread session.
32+
* Takes precedence over `~/.codex/config.toml` `developer_instructions`.
33+
*/
34+
developerInstructions?: string | null, ephemeral?: boolean, /**
3135
* If true, persist additional rollout EventMsg variants required to
3236
* reconstruct a richer thread history on subsequent resume/fork/read.
3337
*/

codex-rs/app-server-protocol/schema/typescript/v2/ThreadResumeParams.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ import type { SandboxMode } from "./SandboxMode";
1919
* If using history or path, the thread_id param will be ignored.
2020
*
2121
* Prefer using thread_id whenever possible.
22+
*
23+
* When resuming a thread that is already loaded/running, override fields are
24+
* ignored and reported as mismatch warnings rather than being reapplied
25+
* mid-session.
2226
*/
2327
export type ThreadResumeParams = {threadId: string, /**
2428
* [UNSTABLE] FOR CODEX CLOUD - DO NOT USE.
@@ -36,7 +40,11 @@ model?: string | null, modelProvider?: string | null, serviceTier?: ServiceTier
3640
* Override where approval requests are routed for review on this thread
3741
* and subsequent turns.
3842
*/
39-
approvalsReviewer?: ApprovalsReviewer | null, sandbox?: SandboxMode | null, config?: { [key in string]?: JsonValue } | null, baseInstructions?: string | null, developerInstructions?: string | null, personality?: Personality | null, /**
43+
approvalsReviewer?: ApprovalsReviewer | null, sandbox?: SandboxMode | null, config?: { [key in string]?: JsonValue } | null, baseInstructions?: string | null, /**
44+
* Custom developer override for this thread session.
45+
* Takes precedence over `~/.codex/config.toml` `developer_instructions`.
46+
*/
47+
developerInstructions?: string | null, personality?: Personality | null, /**
4048
* If true, persist additional rollout EventMsg variants required to
4149
* reconstruct a richer thread history on subsequent resume/fork/read.
4250
*/

codex-rs/app-server-protocol/schema/typescript/v2/ThreadStartParams.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ export type ThreadStartParams = {model?: string | null, modelProvider?: string |
1212
* Override where approval requests are routed for review on this thread
1313
* and subsequent turns.
1414
*/
15-
approvalsReviewer?: ApprovalsReviewer | null, sandbox?: SandboxMode | null, config?: { [key in string]?: JsonValue } | null, serviceName?: string | null, baseInstructions?: string | null, developerInstructions?: string | null, personality?: Personality | null, ephemeral?: boolean | null, /**
15+
approvalsReviewer?: ApprovalsReviewer | null, sandbox?: SandboxMode | null, config?: { [key in string]?: JsonValue } | null, serviceName?: string | null, baseInstructions?: string | null, /**
16+
* Custom developer override for this thread session.
17+
* Takes precedence over `~/.codex/config.toml` `developer_instructions`.
18+
*/
19+
developerInstructions?: string | null, personality?: Personality | null, ephemeral?: boolean | null, /**
1620
* If true, opt into emitting raw Responses API items on the event stream.
1721
* This is for internal use only (e.g. Codex Cloud).
1822
*/

0 commit comments

Comments
 (0)