@jrkropp/codex-js 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (132) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/ClientNotification-B6-FhXQf.d.ts +5 -0
  3. package/dist/{DynamicToolCallResponse-D2OVpa4p.d.ts → DynamicToolCallResponse-82DFjES2.d.ts} +1 -1
  4. package/dist/DynamicToolSpec-CfnhqAYK.d.ts +29 -0
  5. package/dist/PermissionsRequestApprovalResponse-DxzPPDRb.d.ts +55 -0
  6. package/dist/ProviderStatusBanner-BlP6lzwE.d.ts +441 -0
  7. package/dist/ServerRequest-B5cKVJjr.d.ts +2181 -0
  8. package/dist/{session-BO6EZNK7.d.ts → ThreadResumeResponse-DvmE1juU.d.ts} +3 -290
  9. package/dist/ToolRequestUserInputQuestion-CeZa5X1J.d.ts +23 -0
  10. package/dist/{ToolRequestUserInputResponse-Bxjlpgho.d.ts → ToolRequestUserInputResponse-zcPLwbiK.d.ts} +1 -1
  11. package/dist/TurnSteerResponse-0kBCfplh.d.ts +209 -0
  12. package/dist/WebSearchToolConfig-D3ep0625.d.ts +18 -0
  13. package/dist/chat-runtime-B6azJyKo.d.ts +381 -0
  14. package/dist/chunk-2DZRMCI2.js +1258 -0
  15. package/dist/chunk-2DZRMCI2.js.map +1 -0
  16. package/dist/chunk-4DPLJPB5.js +396 -0
  17. package/dist/chunk-4DPLJPB5.js.map +1 -0
  18. package/dist/chunk-5JMJ6OI5.js +3 -0
  19. package/dist/chunk-5JMJ6OI5.js.map +1 -0
  20. package/dist/chunk-6ZMJ34KE.js +1153 -0
  21. package/dist/chunk-6ZMJ34KE.js.map +1 -0
  22. package/dist/chunk-CGBS37IU.js +128 -0
  23. package/dist/chunk-CGBS37IU.js.map +1 -0
  24. package/dist/chunk-DCMKA2A6.js +18 -0
  25. package/dist/chunk-DCMKA2A6.js.map +1 -0
  26. package/dist/chunk-DYLHN3HG.js +937 -0
  27. package/dist/chunk-DYLHN3HG.js.map +1 -0
  28. package/dist/chunk-ILXA6HLX.js +1973 -0
  29. package/dist/chunk-ILXA6HLX.js.map +1 -0
  30. package/dist/{chunk-TZBLUZ2X.js → chunk-LWQNX4LI.js} +7811 -12696
  31. package/dist/chunk-LWQNX4LI.js.map +1 -0
  32. package/dist/{chunk-FFASNDXU.js → chunk-NCI4MAWZ.js} +317 -1967
  33. package/dist/chunk-NCI4MAWZ.js.map +1 -0
  34. package/dist/chunk-O44XP7LH.js +214 -0
  35. package/dist/chunk-O44XP7LH.js.map +1 -0
  36. package/dist/chunk-PST3ZWX2.js +555 -0
  37. package/dist/chunk-PST3ZWX2.js.map +1 -0
  38. package/dist/chunk-SYPHCDRD.js +1133 -0
  39. package/dist/chunk-SYPHCDRD.js.map +1 -0
  40. package/dist/chunk-V4BMZWBM.js +2401 -0
  41. package/dist/chunk-V4BMZWBM.js.map +1 -0
  42. package/dist/chunk-YHVCFD2D.js +117 -0
  43. package/dist/chunk-YHVCFD2D.js.map +1 -0
  44. package/dist/chunk-Z63UPBS3.js +152 -0
  45. package/dist/chunk-Z63UPBS3.js.map +1 -0
  46. package/dist/client/index.d.ts +16 -111
  47. package/dist/client/index.js +13 -1
  48. package/dist/codex-rs/app-server/index.d.ts +161 -0
  49. package/dist/codex-rs/app-server/index.js +13 -0
  50. package/dist/codex-rs/app-server/index.js.map +1 -0
  51. package/dist/codex-rs/app-server-protocol/index.d.ts +1722 -0
  52. package/dist/codex-rs/app-server-protocol/index.js +6 -0
  53. package/dist/codex-rs/app-server-protocol/index.js.map +1 -0
  54. package/dist/codex-rs/app-server-protocol/protocol.d.ts +19 -0
  55. package/dist/codex-rs/app-server-protocol/protocol.js +4 -0
  56. package/dist/codex-rs/app-server-protocol/protocol.js.map +1 -0
  57. package/dist/codex-rs/codex-api/index.d.ts +104 -0
  58. package/dist/codex-rs/codex-api/index.js +11 -0
  59. package/dist/codex-rs/codex-api/index.js.map +1 -0
  60. package/dist/codex-rs/config/index.d.ts +88 -0
  61. package/dist/codex-rs/config/index.js +4 -0
  62. package/dist/codex-rs/config/index.js.map +1 -0
  63. package/dist/codex-rs/core/config/index.d.ts +61 -0
  64. package/dist/codex-rs/core/config/index.js +5 -0
  65. package/dist/codex-rs/core/config/index.js.map +1 -0
  66. package/dist/codex-rs/core/index.d.ts +1393 -0
  67. package/dist/codex-rs/core/index.js +11 -0
  68. package/dist/codex-rs/core/index.js.map +1 -0
  69. package/dist/codex-rs/model-provider/index.d.ts +2 -0
  70. package/dist/codex-rs/model-provider/index.js +4 -0
  71. package/dist/codex-rs/model-provider/index.js.map +1 -0
  72. package/dist/codex-rs/models-manager/index.d.ts +2 -0
  73. package/dist/codex-rs/models-manager/index.js +4 -0
  74. package/dist/codex-rs/models-manager/index.js.map +1 -0
  75. package/dist/codex-rs/parity.d.ts +26 -0
  76. package/dist/codex-rs/parity.js +3 -0
  77. package/dist/codex-rs/parity.js.map +1 -0
  78. package/dist/codex-rs/thread-store/index.d.ts +5 -0
  79. package/dist/codex-rs/thread-store/index.js +4 -0
  80. package/dist/codex-rs/thread-store/index.js.map +1 -0
  81. package/dist/codex-rs/unsupported.d.ts +15 -0
  82. package/dist/codex-rs/unsupported.js +22 -0
  83. package/dist/codex-rs/unsupported.js.map +1 -0
  84. package/dist/codex-rs/utils/output-truncation.d.ts +21 -0
  85. package/dist/codex-rs/utils/output-truncation.js +4 -0
  86. package/dist/codex-rs/utils/output-truncation.js.map +1 -0
  87. package/dist/codex-rs/utils/string.d.ts +7 -0
  88. package/dist/codex-rs/utils/string.js +3 -0
  89. package/dist/codex-rs/utils/string.js.map +1 -0
  90. package/dist/common-CTyph5x8.d.ts +40 -0
  91. package/dist/event-mapping-CbISdQ1D.d.ts +43 -0
  92. package/dist/history-CfM-4V7b.d.ts +1654 -0
  93. package/dist/index-77U_Oc-a.d.ts +63 -0
  94. package/dist/index-CoDZosq0.d.ts +261 -0
  95. package/dist/index.d.ts +18 -8
  96. package/dist/index.js +16 -2
  97. package/dist/lib-nXlaKiS-.d.ts +48 -0
  98. package/dist/live-thread-BMvlflzM.d.ts +30 -0
  99. package/dist/merge-B_AWVmnI.d.ts +24 -0
  100. package/dist/mod-DYVLSWO4.d.ts +91 -0
  101. package/dist/plan-mode-Cv6KWb_S.d.ts +14 -0
  102. package/dist/proposed-plan-DpN1ma0Y.d.ts +53 -0
  103. package/dist/protocol-mpBcYHrm.d.ts +1655 -0
  104. package/dist/react/index.d.ts +20 -53
  105. package/dist/react/index.js +16 -2
  106. package/dist/{remote-DMPfepa9.d.ts → remote-ClZbq9KN.d.ts} +3 -1
  107. package/dist/rendered-thread-AOxw3V5b.d.ts +29 -0
  108. package/dist/responses_websocket-BhxSgCzK.d.ts +183 -0
  109. package/dist/runtime-Cm6ml53h.d.ts +528 -0
  110. package/dist/server/index.d.ts +29 -1999
  111. package/dist/server/index.js +13 -1
  112. package/dist/session-BRYzi8OT.d.ts +46 -0
  113. package/dist/shadcn/index.d.ts +1 -1
  114. package/dist/{sidebar-DT2XoitN.d.ts → sidebar-DMMij22z.d.ts} +1 -1
  115. package/dist/spec_plan_types-CmsJ-Tfn.d.ts +260 -0
  116. package/dist/{store-H2cQxdpe.d.ts → store-AGRxhgQ3.d.ts} +2 -1
  117. package/dist/t3code/apps/web/components/chat.d.ts +508 -0
  118. package/dist/t3code/apps/web/components/chat.js +12 -0
  119. package/dist/t3code/apps/web/components/chat.js.map +1 -0
  120. package/dist/t3code/apps/web/index.d.ts +12 -0
  121. package/dist/t3code/apps/web/index.js +13 -0
  122. package/dist/t3code/apps/web/index.js.map +1 -0
  123. package/dist/testing/index.d.ts +9 -91
  124. package/dist/testing/index.js +13 -1
  125. package/dist/thread-history-builder-zW0zeqcS.d.ts +58 -0
  126. package/dist/thread_event_store-C0zYzukG.d.ts +77 -0
  127. package/dist/types-BTeabLYr.d.ts +126 -0
  128. package/package.json +152 -88
  129. package/dist/chat-runtime-CMli5dzJ.d.ts +0 -748
  130. package/dist/chunk-FFASNDXU.js.map +0 -1
  131. package/dist/chunk-TZBLUZ2X.js.map +0 -1
  132. package/dist/thread_event_store-BIS0qzhi.d.ts +0 -3843
@@ -0,0 +1,1133 @@
1
+ import { BaseInstructions } from './chunk-O44XP7LH.js';
2
+ import { parse, stringify } from 'smol-toml';
3
+
4
+ function parse_config_toml(contents) {
5
+ return parse(contents);
6
+ }
7
+ function parse_toml_value(contents) {
8
+ return parse(contents);
9
+ }
10
+ function serialize_config_toml(config) {
11
+ return stringify(config);
12
+ }
13
+ function empty_config_toml() {
14
+ return {};
15
+ }
16
+ function config_toml_from_unknown(value) {
17
+ if (isTomlTable(value)) {
18
+ return value;
19
+ }
20
+ return {};
21
+ }
22
+ function isTomlTable(value) {
23
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);
24
+ }
25
+
26
+ // src/upstream/codex-rs/config/src/types.ts
27
+ var CONFIG_TOML_FILE = "config.toml";
28
+ var ConfigLayerStackOrdering = {
29
+ LowestPrecedenceFirst: "LowestPrecedenceFirst",
30
+ HighestPrecedenceFirst: "HighestPrecedenceFirst"
31
+ };
32
+ function createConfigLayerStack(layers = [], startup_warnings = []) {
33
+ return { layers, startup_warnings };
34
+ }
35
+
36
+ // src/upstream/codex-rs/core/src/config/permissions.ts
37
+ var BUILT_IN_READ_ONLY_PROFILE = ":read-only";
38
+ var BUILT_IN_WORKSPACE_PROFILE = ":workspace";
39
+ var BUILT_IN_DANGER_NO_SANDBOX_PROFILE = ":danger-no-sandbox";
40
+ function defaultBuiltinPermissionProfileName(input = {}) {
41
+ return input.trusted || input.untrusted ? BUILT_IN_WORKSPACE_PROFILE : BUILT_IN_READ_ONLY_PROFILE;
42
+ }
43
+ function readOnlyPermissionProfile() {
44
+ return {
45
+ type: "managed",
46
+ file_system: {
47
+ type: "restricted",
48
+ entries: [
49
+ {
50
+ path: { type: "special", value: "root" },
51
+ access: "read"
52
+ }
53
+ ]
54
+ },
55
+ network: "restricted"
56
+ };
57
+ }
58
+ function workspaceWritePermissionProfile() {
59
+ return {
60
+ type: "managed",
61
+ file_system: {
62
+ type: "restricted",
63
+ entries: [
64
+ {
65
+ path: { type: "special", value: "project_roots" },
66
+ access: "read-write"
67
+ }
68
+ ]
69
+ },
70
+ network: "restricted"
71
+ };
72
+ }
73
+ function disabledPermissionProfile() {
74
+ return {
75
+ type: "disabled"
76
+ };
77
+ }
78
+ function builtinPermissionProfile(name) {
79
+ switch (name) {
80
+ case BUILT_IN_READ_ONLY_PROFILE:
81
+ return readOnlyPermissionProfile();
82
+ case BUILT_IN_WORKSPACE_PROFILE:
83
+ return workspaceWritePermissionProfile();
84
+ case BUILT_IN_DANGER_NO_SANDBOX_PROFILE:
85
+ return disabledPermissionProfile();
86
+ }
87
+ }
88
+ function permissionProfileFromLegacySandboxPolicy(sandboxPolicy) {
89
+ const mode = legacySandboxPolicyMode(sandboxPolicy);
90
+ switch (mode) {
91
+ case "danger-full-access":
92
+ return disabledPermissionProfile();
93
+ case "read-only":
94
+ return readOnlyPermissionProfile();
95
+ case "workspace-write":
96
+ return workspaceWritePermissionProfile();
97
+ case "external":
98
+ return {
99
+ type: "external",
100
+ network: legacySandboxPolicyNetwork(sandboxPolicy)
101
+ };
102
+ }
103
+ }
104
+ function legacySandboxPolicyFromPermissionProfile(permissionProfile, cwd = "") {
105
+ const normalizedProfile = normalizePermissionProfile(permissionProfile);
106
+ const type = permissionProfileType(normalizedProfile);
107
+ if (type === "disabled") {
108
+ return { mode: "danger-full-access" };
109
+ }
110
+ if (type === "external") {
111
+ return {
112
+ mode: "external",
113
+ network_access: permissionProfileNetwork(normalizedProfile)
114
+ };
115
+ }
116
+ if (permissionProfileFileSystemMode(normalizedProfile) === "read-only") {
117
+ return {
118
+ mode: "read-only",
119
+ network_access: permissionProfileNetwork(normalizedProfile)
120
+ };
121
+ }
122
+ return {
123
+ mode: "workspace-write",
124
+ ...cwd ? { cwd } : {},
125
+ network_access: permissionProfileNetwork(normalizedProfile)
126
+ };
127
+ }
128
+ function effectivePermissionProfile(input) {
129
+ return input.permission_profile && Object.keys(input.permission_profile).length > 0 ? normalizePermissionProfile(input.permission_profile) : permissionProfileFromLegacySandboxPolicy(input.sandbox_policy);
130
+ }
131
+ function builtinPermissionProfileNameFromProfile(permissionProfile) {
132
+ const normalizedProfile = normalizePermissionProfile(permissionProfile);
133
+ const type = permissionProfileType(normalizedProfile);
134
+ if (type === "disabled") {
135
+ return BUILT_IN_DANGER_NO_SANDBOX_PROFILE;
136
+ }
137
+ return permissionProfileFileSystemMode(normalizedProfile) === "read-only" ? BUILT_IN_READ_ONLY_PROFILE : BUILT_IN_WORKSPACE_PROFILE;
138
+ }
139
+ function activePermissionProfileForBuiltin(id) {
140
+ return {
141
+ id,
142
+ extends: null,
143
+ modifications: []
144
+ };
145
+ }
146
+ function active_permission_profile(permissionProfile) {
147
+ return activePermissionProfileForBuiltin(
148
+ builtinPermissionProfileNameFromProfile(permissionProfile)
149
+ );
150
+ }
151
+ function validatePermissionProfile(permissionProfile) {
152
+ const warnings = [];
153
+ const profileType = permissionProfileType(permissionProfile);
154
+ if (profileType.startsWith(":")) {
155
+ warnings.push(
156
+ `Permission profile names beginning with ":" are reserved for Codex built-ins: ${profileType}`
157
+ );
158
+ }
159
+ return warnings;
160
+ }
161
+ function legacySandboxPolicyMode(sandboxPolicy) {
162
+ const mode = stringField(sandboxPolicy, ["mode", "type", "kind"]);
163
+ if (mode === "danger-full-access" || mode === "danger_full_access" || mode === "disabled") {
164
+ return "danger-full-access";
165
+ }
166
+ if (mode === "read-only" || mode === "read_only" || mode === "readonly") {
167
+ return "read-only";
168
+ }
169
+ if (mode === "external" || mode === "external_sandbox") {
170
+ return "external";
171
+ }
172
+ return "workspace-write";
173
+ }
174
+ function legacySandboxPolicyNetwork(sandboxPolicy) {
175
+ const value = stringField(sandboxPolicy, ["network_access", "network"]);
176
+ return value === "restricted" || value === "disabled" ? "restricted" : "enabled";
177
+ }
178
+ function permissionProfileType(permissionProfile) {
179
+ return stringField(permissionProfile, ["type", "mode", "profile"]) ?? "managed";
180
+ }
181
+ function normalizePermissionProfile(permissionProfile) {
182
+ const type = permissionProfileType(permissionProfile);
183
+ switch (type) {
184
+ case "danger-full-access":
185
+ case "danger-no-sandbox":
186
+ case "disabled":
187
+ return disabledPermissionProfile();
188
+ case "read-only":
189
+ case "readonly":
190
+ return readOnlyPermissionProfile();
191
+ case "workspace":
192
+ case "workspace-write":
193
+ return workspaceWritePermissionProfile();
194
+ default:
195
+ return permissionProfile && Object.keys(permissionProfile).length > 0 ? permissionProfile : readOnlyPermissionProfile();
196
+ }
197
+ }
198
+ function permissionProfileFileSystemMode(permissionProfile) {
199
+ const fileSystem = recordField(permissionProfile, "file_system");
200
+ const entries = Array.isArray(fileSystem?.entries) ? fileSystem.entries : [];
201
+ if (entries.length > 0 && entries.every(
202
+ (entry) => typeof entry === "object" && entry !== null && entry.access === "read"
203
+ )) {
204
+ return "read-only";
205
+ }
206
+ return "workspace-write";
207
+ }
208
+ function permissionProfileNetwork(permissionProfile) {
209
+ const network = permissionProfile ? permissionProfile.network : null;
210
+ if (typeof network === "string") {
211
+ return network === "enabled" ? "enabled" : "restricted";
212
+ }
213
+ if (typeof network === "object" && network !== null && "enabled" in network && network.enabled === true) {
214
+ return "enabled";
215
+ }
216
+ return "restricted";
217
+ }
218
+ function recordField(value, field) {
219
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
220
+ return null;
221
+ }
222
+ const fieldValue = value[field];
223
+ return typeof fieldValue === "object" && fieldValue !== null && !Array.isArray(fieldValue) ? fieldValue : null;
224
+ }
225
+ function stringField(value, fields) {
226
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
227
+ return null;
228
+ }
229
+ for (const field of fields) {
230
+ const fieldValue = value[field];
231
+ if (typeof fieldValue === "string" && fieldValue.trim().length > 0) {
232
+ return fieldValue.trim().toLowerCase().replaceAll("_", "-");
233
+ }
234
+ }
235
+ return null;
236
+ }
237
+
238
+ // src/upstream/codex-rs/core/src/config-types.ts
239
+ var ModeKind = {
240
+ Plan: "plan",
241
+ Default: "default"
242
+ };
243
+ var TUI_VISIBLE_COLLABORATION_MODES = [
244
+ ModeKind.Default,
245
+ ModeKind.Plan
246
+ ];
247
+ function allowsRequestUserInput(mode) {
248
+ return mode === ModeKind.Plan;
249
+ }
250
+ function modeDisplayName(mode) {
251
+ switch (mode) {
252
+ case ModeKind.Plan:
253
+ return "Plan";
254
+ case ModeKind.Default:
255
+ return "Default";
256
+ }
257
+ }
258
+ function collaborationModeWithUpdates(collaborationMode, model, effort, developerInstructions) {
259
+ return {
260
+ mode: collaborationMode.mode,
261
+ settings: {
262
+ model: model ?? collaborationMode.settings.model,
263
+ reasoning_effort: effort === void 0 ? collaborationMode.settings.reasoning_effort : effort,
264
+ developer_instructions: developerInstructions === void 0 ? collaborationMode.settings.developer_instructions : developerInstructions
265
+ }
266
+ };
267
+ }
268
+ function applyCollaborationModeMask(collaborationMode, mask) {
269
+ return {
270
+ mode: mask.mode ?? collaborationMode.mode,
271
+ settings: {
272
+ model: mask.model ?? collaborationMode.settings.model,
273
+ reasoning_effort: mask.reasoning_effort === void 0 ? collaborationMode.settings.reasoning_effort : mask.reasoning_effort,
274
+ developer_instructions: mask.developer_instructions === void 0 ? collaborationMode.settings.developer_instructions : mask.developer_instructions
275
+ }
276
+ };
277
+ }
278
+ function collaborationModeForModel(model, effort, mode = ModeKind.Default, developerInstructions = null) {
279
+ return {
280
+ mode,
281
+ settings: {
282
+ model,
283
+ reasoning_effort: effort ?? null,
284
+ developer_instructions: developerInstructions
285
+ }
286
+ };
287
+ }
288
+
289
+ // src/upstream/codex-rs/core/src/plan-mode.ts
290
+ var CODEX_PLAN_MODE_INSTRUCTIONS = `# Plan Mode (Conversational)
291
+
292
+ You work in 3 phases, and you should *chat your way* to a great plan before finalizing it. A great plan is very detailed\u2014intent- and implementation-wise\u2014so that it can be handed to another engineer or agent to be implemented right away. It must be **decision complete**, where the implementer does not need to make any decisions.
293
+
294
+ ## Mode rules (strict)
295
+
296
+ You are in **Plan Mode** until a developer message explicitly ends it.
297
+
298
+ Plan Mode is not changed by user intent, tone, or imperative language. If a user asks for execution while still in Plan Mode, treat it as a request to **plan the execution**, not perform it.
299
+
300
+ ## Plan Mode vs update_plan tool
301
+
302
+ Plan Mode is a collaboration mode that can involve requesting user input and eventually issuing a \`<proposed_plan>\` block.
303
+
304
+ Separately, \`update_plan\` is a checklist/progress/TODOs tool; it does not enter or exit Plan Mode. Do not confuse it with Plan mode or try to use it while in Plan mode. If you try to use \`update_plan\` in Plan mode, it will return an error.
305
+
306
+ ## Execution vs. mutation in Plan Mode
307
+
308
+ You may explore and execute **non-mutating** actions that improve the plan. You must not perform **mutating** actions.
309
+
310
+ ### Allowed (non-mutating, plan-improving)
311
+
312
+ Actions that gather truth, reduce ambiguity, or validate feasibility without changing repo-tracked state. Examples:
313
+
314
+ * Reading or searching files, configs, schemas, types, manifests, and docs
315
+ * Static analysis, inspection, and repo exploration
316
+ * Dry-run style commands when they do not edit repo-tracked files
317
+ * Tests, builds, or checks that may write to caches or build artifacts (for example, \`target/\`, \`.cache/\`, or snapshots) so long as they do not edit repo-tracked files
318
+
319
+ ### Not allowed (mutating, plan-executing)
320
+
321
+ Actions that implement the plan or change repo-tracked state. Examples:
322
+
323
+ * Editing or writing files
324
+ * Running formatters or linters that rewrite files
325
+ * Applying patches, migrations, or codegen that updates repo-tracked files
326
+ * Side-effectful commands whose purpose is to carry out the plan rather than refine it
327
+
328
+ When in doubt: if the action would reasonably be described as "doing the work" rather than "planning the work," do not do it.
329
+
330
+ ## PHASE 1 \u2014 Ground in the environment (explore first, ask second)
331
+
332
+ Begin by grounding yourself in the actual environment. Eliminate unknowns in the prompt by discovering facts, not by asking the user. Resolve all questions that can be answered through exploration or inspection. Identify missing or ambiguous details only if they cannot be derived from the environment. Silent exploration between turns is allowed and encouraged.
333
+
334
+ Before asking the user any question, perform at least one targeted non-mutating exploration pass (for example: search relevant files, inspect likely entrypoints/configs, confirm current implementation shape), unless no local environment/repo is available.
335
+
336
+ Exception: you may ask clarifying questions about the user's prompt before exploring, ONLY if there are obvious ambiguities or contradictions in the prompt itself. However, if ambiguity might be resolved by exploring, always prefer exploring first.
337
+
338
+ Do not ask questions that can be answered from the repo or system (for example, "where is this struct?" or "which UI component should we use?" when exploration can make it clear). Only ask once you have exhausted reasonable non-mutating exploration.
339
+
340
+ ## PHASE 2 \u2014 Intent chat (what they actually want)
341
+
342
+ * Keep asking until you can clearly state: goal + success criteria, audience, in/out of scope, constraints, current state, and the key preferences/tradeoffs.
343
+ * Bias toward questions over guessing: if any high-impact ambiguity remains, do NOT plan yet\u2014ask.
344
+
345
+ ## PHASE 3 \u2014 Implementation chat (what/how we\u2019ll build)
346
+
347
+ * Once intent is stable, keep asking until the spec is decision complete: approach, interfaces (APIs/schemas/I/O), data flow, edge cases/failure modes, testing + acceptance criteria, rollout/monitoring, and any migrations/compat constraints.
348
+
349
+ ## Asking questions
350
+
351
+ Critical rules:
352
+
353
+ * Strongly prefer using the \`request_user_input\` tool to ask any questions.
354
+ * Offer only meaningful multiple\u2011choice options; don\u2019t include filler choices that are obviously wrong or irrelevant.
355
+ * In rare cases where an unavoidable, important question can\u2019t be expressed with reasonable multiple\u2011choice options (due to extreme ambiguity), you may ask it directly without the tool.
356
+
357
+ You SHOULD ask many questions, but each question must:
358
+
359
+ * materially change the spec/plan, OR
360
+ * confirm/lock an assumption, OR
361
+ * choose between meaningful tradeoffs.
362
+ * not be answerable by non-mutating commands.
363
+
364
+ Use the \`request_user_input\` tool only for decisions that materially change the plan, for confirming important assumptions, or for information that cannot be discovered via non-mutating exploration.
365
+
366
+ ## Two kinds of unknowns (treat differently)
367
+
368
+ 1. **Discoverable facts** (repo/system truth): explore first.
369
+
370
+ * Before asking, run targeted searches and check likely sources of truth (configs/manifests/entrypoints/schemas/types/constants).
371
+ * Ask only if: multiple plausible candidates; nothing found but you need a missing identifier/context; or ambiguity is actually product intent.
372
+ * If asking, present concrete candidates (paths/service names) + recommend one.
373
+ * Never ask questions you can answer from your environment (e.g., \u201Cwhere is this struct\u201D).
374
+
375
+ 2. **Preferences/tradeoffs** (not discoverable): ask early.
376
+
377
+ * These are intent or implementation preferences that cannot be derived from exploration.
378
+ * Provide 2\u20134 mutually exclusive options + a recommended default.
379
+ * If unanswered, proceed with the recommended option and record it as an assumption in the final plan.
380
+
381
+ ## Finalization rule
382
+
383
+ Only output the final plan when it is decision complete and leaves no decisions to the implementer.
384
+
385
+ When you present the official plan, wrap it in a \`<proposed_plan>\` block so the client can render it specially:
386
+
387
+ 1) The opening tag must be on its own line.
388
+ 2) Start the plan content on the next line (no text on the same line as the tag).
389
+ 3) The closing tag must be on its own line.
390
+ 4) Use Markdown inside the block.
391
+ 5) Keep the tags exactly as \`<proposed_plan>\` and \`</proposed_plan>\` (do not translate or rename them), even if the plan content is in another language.
392
+
393
+ Example:
394
+
395
+ <proposed_plan>
396
+ plan content
397
+ </proposed_plan>
398
+
399
+ plan content should be human and agent digestible. The final plan must be plan-only, concise by default, and include:
400
+
401
+ * A clear title
402
+ * A brief summary section
403
+ * Important changes or additions to public APIs/interfaces/types
404
+ * Test cases and scenarios
405
+ * Explicit assumptions and defaults chosen where needed
406
+
407
+ When possible, prefer a compact structure with 3-5 short sections, usually: Summary, Key Changes or Implementation Changes, Test Plan, and Assumptions. Do not include a separate Scope section unless scope boundaries are genuinely important to avoid mistakes.
408
+
409
+ Prefer grouped implementation bullets by subsystem or behavior over file-by-file inventories. Mention files only when needed to disambiguate a non-obvious change, and avoid naming more than 3 paths unless extra specificity is necessary to prevent mistakes. Prefer behavior-level descriptions over symbol-by-symbol removal lists. For v1 feature-addition plans, do not invent detailed schema, validation, precedence, fallback, or wire-shape policy unless the request establishes it or it is needed to prevent a concrete implementation mistake; prefer the intended capability and minimum interface/behavior changes.
410
+
411
+ Keep bullets short and avoid explanatory sub-bullets unless they are needed to prevent ambiguity. Prefer the minimum detail needed for implementation safety, not exhaustive coverage. Within each section, compress related changes into a few high-signal bullets and omit branch-by-branch logic, repeated invariants, and long lists of unaffected behavior unless they are necessary to prevent a likely implementation mistake. Avoid repeated repo facts and irrelevant edge-case or rollout detail. For straightforward refactors, keep the plan to a compact summary, key edits, tests, and assumptions. If the user asks for more detail, then expand.
412
+
413
+ Do not ask "should I proceed?" in the final output. The user can easily switch out of Plan mode and request implementation if you have included a \`<proposed_plan>\` block in your response. Alternatively, they can decide to stay in Plan mode and continue refining the plan.
414
+
415
+ Only produce at most one \`<proposed_plan>\` block per turn, and only when you are presenting a complete spec.
416
+
417
+ If the user stays in Plan mode and asks for revisions after a prior \`<proposed_plan>\`, any new \`<proposed_plan>\` must be a complete replacement.`;
418
+
419
+ // src/upstream/codex-rs/core/src/collaboration-mode-presets.ts
420
+ var DEFAULT_MODE_TEMPLATE = `# Collaboration Mode: Default
421
+
422
+ You are now in Default mode. Any previous instructions for other modes (e.g. Plan mode) are no longer active.
423
+
424
+ Your active mode changes only when new developer instructions with a different \`<collaboration_mode>...</collaboration_mode>\` change it; user requests or tool descriptions do not change mode by themselves. Known mode names are {{KNOWN_MODE_NAMES}}.
425
+
426
+ ## request_user_input availability
427
+
428
+ Use the \`request_user_input\` tool only when it is listed in the available tools for this turn.
429
+
430
+ In Default mode, strongly prefer making reasonable assumptions and executing the user's request rather than stopping to ask questions. If you absolutely must ask a question because the answer cannot be discovered from local context and a reasonable assumption would be risky, ask the user directly with a concise plain-text question. Never write a multiple choice question as a textual assistant message.`;
431
+ function builtinCollaborationModePresets() {
432
+ return [planPreset(), defaultPreset()];
433
+ }
434
+ function collaborationModePresetForMode(mode) {
435
+ return builtinCollaborationModePresets().find((preset) => preset.mode === mode) ?? null;
436
+ }
437
+ function normalizeCollaborationMode(input) {
438
+ const current = input.collaborationMode ? collaborationModeForModel(
439
+ input.collaborationMode.settings.model ?? input.model,
440
+ input.collaborationMode.settings.reasoning_effort ?? input.reasoningEffort ?? null,
441
+ input.collaborationMode.mode,
442
+ input.collaborationMode.settings.developer_instructions ?? null
443
+ ) : collaborationModeForModel(
444
+ input.model,
445
+ input.reasoningEffort ?? null,
446
+ ModeKind.Default
447
+ );
448
+ const preset = collaborationModePresetForMode(current.mode);
449
+ if (current.settings.developer_instructions === null && preset?.developer_instructions) {
450
+ return applyCollaborationModeMask(current, {
451
+ name: preset.name,
452
+ developer_instructions: preset.developer_instructions
453
+ });
454
+ }
455
+ return current;
456
+ }
457
+ function defaultModeInstructions() {
458
+ return DEFAULT_MODE_TEMPLATE.replace(
459
+ "{{KNOWN_MODE_NAMES}}",
460
+ formatModeNames(TUI_VISIBLE_COLLABORATION_MODES)
461
+ );
462
+ }
463
+ function planPreset() {
464
+ return {
465
+ name: modeDisplayName(ModeKind.Plan),
466
+ mode: ModeKind.Plan,
467
+ model: null,
468
+ reasoning_effort: "medium",
469
+ developer_instructions: CODEX_PLAN_MODE_INSTRUCTIONS
470
+ };
471
+ }
472
+ function defaultPreset() {
473
+ return {
474
+ name: modeDisplayName(ModeKind.Default),
475
+ mode: ModeKind.Default,
476
+ model: null,
477
+ reasoning_effort: void 0,
478
+ developer_instructions: defaultModeInstructions()
479
+ };
480
+ }
481
+ function formatModeNames(modes) {
482
+ const modeNames = modes.map(modeDisplayName);
483
+ if (modeNames.length === 0) {
484
+ return "none";
485
+ }
486
+ if (modeNames.length === 1) {
487
+ return modeNames[0] ?? "none";
488
+ }
489
+ if (modeNames.length === 2) {
490
+ return `${modeNames[0]} and ${modeNames[1]}`;
491
+ }
492
+ return modeNames.join(", ");
493
+ }
494
+
495
+ // src/upstream/codex-rs/core/src/tools/spec_plan_types.ts
496
+ var ToolHandlerKind = {
497
+ DynamicTool: "DynamicTool",
498
+ RequestPermissions: "RequestPermissions",
499
+ RequestUserInput: "RequestUserInput",
500
+ ToolSearch: "ToolSearch",
501
+ UnavailableTool: "UnavailableTool",
502
+ Mcp: "Mcp",
503
+ ListMcpResources: "ListMcpResources",
504
+ ListMcpResourceTemplates: "ListMcpResourceTemplates",
505
+ ReadMcpResource: "ReadMcpResource",
506
+ ExecCommand: "ExecCommand",
507
+ WriteStdin: "WriteStdin",
508
+ ApplyPatch: "ApplyPatch",
509
+ Plan: "Plan",
510
+ GetGoal: "GetGoal",
511
+ CreateGoal: "CreateGoal",
512
+ UpdateGoal: "UpdateGoal",
513
+ SpawnAgent: "SpawnAgent",
514
+ SendInput: "SendInput",
515
+ WaitAgent: "WaitAgent",
516
+ CloseAgent: "CloseAgent",
517
+ ResumeAgent: "ResumeAgent",
518
+ ListAgents: "ListAgents",
519
+ SendMessage: "SendMessage",
520
+ FollowupTask: "FollowupTask"
521
+ };
522
+ function createToolRegistryPlan() {
523
+ return {
524
+ specs: [],
525
+ handlers: []
526
+ };
527
+ }
528
+ function defaultToolsConfig(input = {}) {
529
+ return {
530
+ namespace_tools: input.namespace_tools ?? true,
531
+ request_permissions_tool_enabled: input.request_permissions_tool_enabled ?? true,
532
+ request_user_input_available_modes: input.request_user_input_available_modes ?? [],
533
+ search_tool: input.search_tool ?? true,
534
+ web_search_mode: input.web_search === false ? "disabled" : input.web_search_mode ?? "cached",
535
+ web_search_tool_type: input.web_search_tool_type ?? "text",
536
+ web_search_config: input.web_search_config ?? null,
537
+ image_gen_tool: input.image_gen_tool ?? input.image_generation ?? false,
538
+ exec_command_tool_enabled: input.exec_command_tool_enabled ?? false,
539
+ write_stdin_tool_enabled: input.write_stdin_tool_enabled ?? false,
540
+ apply_patch_tool_enabled: input.apply_patch_tool_enabled ?? false,
541
+ thread_goal_tools_enabled: input.thread_goal_tools_enabled ?? true,
542
+ mcp_tools_enabled: input.mcp_tools_enabled ?? true,
543
+ multi_agent_tools_enabled: input.multi_agent_tools_enabled ?? false
544
+ };
545
+ }
546
+
547
+ // src/upstream/codex-rs/config/src/merge.ts
548
+ var PROJECT_LOCAL_CONFIG_DENYLIST = /* @__PURE__ */ new Set([
549
+ "openai_base_url",
550
+ "chatgpt_base_url",
551
+ "model_provider",
552
+ "model_providers",
553
+ "notify",
554
+ "profile",
555
+ "profiles",
556
+ "experimental_realtime_ws_base_url"
557
+ ]);
558
+ function config_layer_source_precedence(source) {
559
+ switch (source.type) {
560
+ case "Mdm":
561
+ return 0;
562
+ case "System":
563
+ return 10;
564
+ case "User":
565
+ return 20;
566
+ case "Project":
567
+ return 25;
568
+ case "SessionFlags":
569
+ return 30;
570
+ case "LegacyManagedConfigTomlFromFile":
571
+ return 40;
572
+ case "LegacyManagedConfigTomlFromMdm":
573
+ return 50;
574
+ }
575
+ }
576
+ function ConfigLayerEntry_new(name, config) {
577
+ return {
578
+ name,
579
+ config: sanitize_config_for_layer(name, config),
580
+ raw_toml: null,
581
+ version: version_for_toml(config),
582
+ disabled_reason: null
583
+ };
584
+ }
585
+ function ConfigLayerEntry_new_with_raw_toml(name, config, raw_toml) {
586
+ const sanitized = sanitize_config_for_layer(name, config);
587
+ return {
588
+ name,
589
+ config: sanitized,
590
+ raw_toml,
591
+ version: version_for_toml(sanitized),
592
+ disabled_reason: null
593
+ };
594
+ }
595
+ function ConfigLayerEntry_new_disabled(name, config, disabled_reason) {
596
+ return {
597
+ name,
598
+ config,
599
+ raw_toml: null,
600
+ version: version_for_toml(config),
601
+ disabled_reason
602
+ };
603
+ }
604
+ function ConfigLayerEntry_is_disabled(layer) {
605
+ return Boolean(layer.disabled_reason);
606
+ }
607
+ function ConfigLayerStack_new(layers = [], startup_warnings = []) {
608
+ verify_layer_ordering(layers);
609
+ return { layers, startup_warnings };
610
+ }
611
+ function ConfigLayerStack_get_layers(stack, ordering, include_disabled = false) {
612
+ const layers = stack.layers.filter(
613
+ (layer) => include_disabled || !ConfigLayerEntry_is_disabled(layer)
614
+ );
615
+ return ordering === ConfigLayerStackOrdering.HighestPrecedenceFirst ? [...layers].reverse() : layers;
616
+ }
617
+ function ConfigLayerStack_effective_config(stack) {
618
+ const merged = {};
619
+ for (const layer of ConfigLayerStack_get_layers(
620
+ stack,
621
+ ConfigLayerStackOrdering.LowestPrecedenceFirst,
622
+ false
623
+ )) {
624
+ merge_toml_values(merged, layer.config);
625
+ }
626
+ return merged;
627
+ }
628
+ function merge_config_layers(stack, overrides = {}) {
629
+ const merged = ConfigLayerStack_effective_config(stack);
630
+ return resolve_config(merged, stack.startup_warnings, overrides);
631
+ }
632
+ function merge_toml_values(base, overlay) {
633
+ merge_toml_values_at_path(base, overlay, []);
634
+ return base;
635
+ }
636
+ function merge_toml_values_at_path(base, overlay, path) {
637
+ normalize_key_aliases(path, base);
638
+ const normalizedOverlay = { ...overlay };
639
+ normalize_key_aliases(path, normalizedOverlay);
640
+ for (const [key, value] of Object.entries(normalizedOverlay)) {
641
+ const existing = base[key];
642
+ const childPath = [...path, key];
643
+ if (isIgnoredLegacyToolsWebSearchValue(childPath, value)) {
644
+ continue;
645
+ }
646
+ if (isPlainTomlTable(existing) && isPlainTomlTable(value)) {
647
+ merge_toml_values_at_path(existing, value, childPath);
648
+ } else {
649
+ base[key] = normalized_with_key_aliases(value, childPath);
650
+ }
651
+ }
652
+ }
653
+ function resolve_config(config, startupWarnings = [], overrides = {}) {
654
+ const merged = { ...config };
655
+ const activeProfileName = overrides.profile ?? merged.profile ?? null;
656
+ const configProfile = activeProfileName && merged.profiles ? merged.profiles[activeProfileName] : null;
657
+ if (activeProfileName && !configProfile) {
658
+ startupWarnings = [
659
+ ...startupWarnings,
660
+ `config profile \`${activeProfileName}\` not found`
661
+ ];
662
+ }
663
+ if (configProfile) {
664
+ merge_toml_values(merged, configProfile);
665
+ }
666
+ merge_toml_values(merged, overrides);
667
+ const permissionProfile = resolvePermissionProfile(merged);
668
+ const permissionWarnings = validatePermissionProfile(permissionProfile);
669
+ const sandboxPolicy = merged.sandbox_policy ?? legacySandboxPolicyFromPermissionProfile(permissionProfile, merged.cwd ?? "");
670
+ const activeBuiltin = builtinPermissionProfileNameFromProfile(
671
+ permissionProfile
672
+ ) ?? defaultBuiltinPermissionProfileName();
673
+ const baseInstructions = normalizeBaseInstructions(merged);
674
+ const webSearchMode = resolve_web_search_mode(merged) ?? "cached";
675
+ const webSearchConfig = resolve_web_search_config(merged);
676
+ const tools = tools_config_from_toml(merged.tools, {
677
+ web_search_config: webSearchConfig,
678
+ web_search_mode: webSearchMode
679
+ });
680
+ return {
681
+ model: merged.model ?? "gpt-5.5",
682
+ model_provider: merged.model_provider ?? "openai",
683
+ service_tier: merged.service_tier ?? null,
684
+ reasoning_effort: merged.model_reasoning_effort ?? null,
685
+ reasoning_summary: merged.model_reasoning_summary ?? "auto",
686
+ personality: merged.personality ?? null,
687
+ approval_policy: merged.approval_policy ?? "never",
688
+ approvals_reviewer: merged.approvals_reviewer ?? null,
689
+ sandbox_policy: sandboxPolicy,
690
+ permission_profile: permissionProfile,
691
+ active_permission_profile: merged.active_permission_profile ?? activePermissionProfileForBuiltin(activeBuiltin),
692
+ windows_sandbox_level: merged.windows_sandbox_level ?? null,
693
+ cwd: merged.cwd ?? "",
694
+ base_instructions: baseInstructions.base_instructions,
695
+ base_instructions_source: baseInstructions.source,
696
+ developer_instructions: merged.developer_instructions ?? null,
697
+ user_instructions: merged.user_instructions ?? null,
698
+ collaboration_mode: normalizeCollaborationMode({
699
+ collaborationMode: merged.collaboration_mode ?? null,
700
+ model: merged.model ?? "gpt-5.5",
701
+ reasoningEffort: merged.model_reasoning_effort ?? null
702
+ }),
703
+ session_source: merged.session_source ?? "test",
704
+ environments: merged.environments ?? [],
705
+ dynamic_tools: merged.dynamic_tools ?? [],
706
+ final_output_json_schema: merged.final_output_json_schema,
707
+ truncation_policy: merged.truncation_policy ?? null,
708
+ web_search: merged.web_search ?? null,
709
+ web_search_mode: webSearchMode,
710
+ tools,
711
+ profiles: merged.profiles,
712
+ profile: merged.profile,
713
+ compact_prompt: merged.compact_prompt ?? null,
714
+ include_permissions_instructions: merged.include_permissions_instructions ?? true,
715
+ include_environment_context: merged.include_environment_context ?? true,
716
+ include_apps_instructions: merged.include_apps_instructions ?? true,
717
+ include_skill_instructions: merged.include_skill_instructions ?? true,
718
+ startup_warnings: [...startupWarnings, ...permissionWarnings],
719
+ model_reasoning_effort: merged.model_reasoning_effort,
720
+ model_reasoning_summary: merged.model_reasoning_summary
721
+ };
722
+ }
723
+ function resolve_web_search_mode(config) {
724
+ if (isWebSearchMode(config.web_search)) {
725
+ return config.web_search;
726
+ }
727
+ if (featureEnabled(config.features, "web_search_cached", "WebSearchCached")) {
728
+ return "cached";
729
+ }
730
+ if (featureEnabled(config.features, "web_search_request", "WebSearchRequest")) {
731
+ return "live";
732
+ }
733
+ return null;
734
+ }
735
+ function resolve_web_search_config(config) {
736
+ const toolConfig = normalizeWebSearchToolConfig(config.tools?.web_search);
737
+ return toolConfig ? webSearchConfigFromToolConfig(toolConfig) : null;
738
+ }
739
+ function resolve_web_search_mode_for_turn(input) {
740
+ const allowed = allowedWebSearchModes(input.allowed_modes);
741
+ const preferred = input.web_search_mode;
742
+ if (isDisabledPermissionProfile(input.permission_profile) && preferred !== "disabled") {
743
+ for (const mode of ["live", "cached", "disabled"]) {
744
+ if (allowed.has(mode)) {
745
+ return mode;
746
+ }
747
+ }
748
+ return "disabled";
749
+ }
750
+ if (allowed.has(preferred)) {
751
+ return preferred;
752
+ }
753
+ for (const mode of ["cached", "live", "disabled"]) {
754
+ if (allowed.has(mode)) {
755
+ return mode;
756
+ }
757
+ }
758
+ return "disabled";
759
+ }
760
+ function tools_config_from_toml(tools, webSearch) {
761
+ const input = { ...tools ?? {} };
762
+ delete input.web_search;
763
+ return defaultToolsConfig({
764
+ ...input,
765
+ web_search_config: webSearch.web_search_config,
766
+ web_search_mode: webSearch.web_search_mode
767
+ });
768
+ }
769
+ function normalizeWebSearchToolConfig(value) {
770
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
771
+ return null;
772
+ }
773
+ return value;
774
+ }
775
+ function webSearchConfigFromToolConfig(config) {
776
+ return {
777
+ ...Array.isArray(config.allowed_domains) ? { filters: { allowed_domains: config.allowed_domains } } : {},
778
+ ...config.location && typeof config.location === "object" ? { user_location: webSearchUserLocation(config.location) } : {},
779
+ ...config.context_size ? { search_context_size: config.context_size } : {}
780
+ };
781
+ }
782
+ function webSearchUserLocation(location) {
783
+ return {
784
+ type: "approximate",
785
+ ...location.country ? { country: location.country } : {},
786
+ ...location.region ? { region: location.region } : {},
787
+ ...location.city ? { city: location.city } : {},
788
+ ...location.timezone ? { timezone: location.timezone } : {}
789
+ };
790
+ }
791
+ function allowedWebSearchModes(modes) {
792
+ if (!modes) {
793
+ return /* @__PURE__ */ new Set(["disabled", "cached", "live"]);
794
+ }
795
+ return /* @__PURE__ */ new Set(["disabled", ...modes.filter(isWebSearchMode)]);
796
+ }
797
+ function isWebSearchMode(value) {
798
+ return value === "disabled" || value === "cached" || value === "live";
799
+ }
800
+ function isDisabledPermissionProfile(profile) {
801
+ return Boolean(profile && profile.type === "disabled");
802
+ }
803
+ function featureEnabled(features, ...keys) {
804
+ if (!features) {
805
+ return false;
806
+ }
807
+ for (const key of keys) {
808
+ const value = features[key];
809
+ if (value === true) {
810
+ return true;
811
+ }
812
+ if (value && typeof value === "object") {
813
+ const record = value;
814
+ if (record.enabled === true || record.value === true) {
815
+ return true;
816
+ }
817
+ }
818
+ }
819
+ return false;
820
+ }
821
+ function normalizeBaseInstructions(config) {
822
+ if (typeof config.instructions === "string") {
823
+ return {
824
+ base_instructions: { text: config.instructions },
825
+ source: "config"
826
+ };
827
+ }
828
+ if (typeof config.model_instructions_file_contents === "string") {
829
+ const trimmed = config.model_instructions_file_contents.trim();
830
+ if (trimmed) {
831
+ return {
832
+ base_instructions: { text: trimmed },
833
+ source: "model_instructions_file"
834
+ };
835
+ }
836
+ }
837
+ const baseInstructions = config.base_instructions;
838
+ if (typeof baseInstructions === "string") {
839
+ return {
840
+ base_instructions: { text: baseInstructions },
841
+ source: "config"
842
+ };
843
+ }
844
+ if (baseInstructions) {
845
+ return {
846
+ base_instructions: baseInstructions,
847
+ source: "config"
848
+ };
849
+ }
850
+ return {
851
+ base_instructions: BaseInstructions.default(),
852
+ source: "default"
853
+ };
854
+ }
855
+ function resolvePermissionProfile(config) {
856
+ if (config.permission_profile) {
857
+ return effectivePermissionProfile({
858
+ permission_profile: config.permission_profile,
859
+ sandbox_policy: config.sandbox_policy
860
+ });
861
+ }
862
+ if (config.sandbox_policy) {
863
+ return effectivePermissionProfile({
864
+ permission_profile: null,
865
+ sandbox_policy: config.sandbox_policy
866
+ });
867
+ }
868
+ if (config.sandbox_mode) {
869
+ return permissionProfileFromLegacySandboxPolicy({
870
+ mode: config.sandbox_mode
871
+ });
872
+ }
873
+ return effectivePermissionProfile({
874
+ permission_profile: null,
875
+ sandbox_policy: null
876
+ });
877
+ }
878
+ function sanitize_config_for_layer(source, config) {
879
+ if (source.type !== "Project") {
880
+ return config;
881
+ }
882
+ const sanitized = { ...config };
883
+ for (const denied of PROJECT_LOCAL_CONFIG_DENYLIST) {
884
+ delete sanitized[denied];
885
+ }
886
+ return sanitized;
887
+ }
888
+ function verify_layer_ordering(layers) {
889
+ for (let index = 1; index < layers.length; index += 1) {
890
+ const previous = layers[index - 1];
891
+ const current = layers[index];
892
+ if (config_layer_source_precedence(previous.name) > config_layer_source_precedence(current.name)) {
893
+ throw new Error("config layers are not in correct precedence order");
894
+ }
895
+ }
896
+ }
897
+ function version_for_toml(config) {
898
+ return stableStringify(config);
899
+ }
900
+ function stableStringify(value) {
901
+ if (Array.isArray(value)) {
902
+ return `[${value.map(stableStringify).join(",")}]`;
903
+ }
904
+ if (isPlainTomlTable(value)) {
905
+ return `{${Object.keys(value).sort().map((key) => `${JSON.stringify(key)}:${stableStringify(value[key])}`).join(",")}}`;
906
+ }
907
+ return JSON.stringify(value);
908
+ }
909
+ function isPlainTomlTable(value) {
910
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);
911
+ }
912
+ function normalize_key_aliases(path, table) {
913
+ if (path.length === 1 && path[0] === "memories" && "no_memories_if_mcp_or_web_search" in table && !("disable_on_external_context" in table)) {
914
+ table.disable_on_external_context = table.no_memories_if_mcp_or_web_search;
915
+ delete table.no_memories_if_mcp_or_web_search;
916
+ }
917
+ }
918
+ function normalized_with_key_aliases(value, path) {
919
+ if (Array.isArray(value)) {
920
+ return value.map((item) => normalized_with_key_aliases(item, path));
921
+ }
922
+ if (!isPlainTomlTable(value)) {
923
+ return value;
924
+ }
925
+ const normalized = {};
926
+ for (const [key, child] of Object.entries(value)) {
927
+ normalized[key] = normalized_with_key_aliases(child, [...path, key]);
928
+ }
929
+ normalize_key_aliases(path, normalized);
930
+ return normalized;
931
+ }
932
+ function isIgnoredLegacyToolsWebSearchValue(path, value) {
933
+ return path.length === 2 && path[0] === "tools" && path[1] === "web_search" && typeof value === "boolean";
934
+ }
935
+ function build_cli_overrides_layer(cli_overrides) {
936
+ const root = {};
937
+ for (const [path, value] of cli_overrides) {
938
+ apply_toml_override(root, path, value);
939
+ }
940
+ return root;
941
+ }
942
+ function apply_toml_override(root, path, value) {
943
+ let current = root;
944
+ const segments = path.split(".");
945
+ for (const [index, segment] of segments.entries()) {
946
+ if (index === segments.length - 1) {
947
+ current[segment] = value;
948
+ return;
949
+ }
950
+ const next = current[segment];
951
+ if (!isPlainTomlTable(next)) {
952
+ current[segment] = {};
953
+ }
954
+ current = current[segment];
955
+ }
956
+ }
957
+
958
+ // src/upstream/codex-rs/config/src/thread_config.ts
959
+ var ThreadConfigLoadError = class extends Error {
960
+ constructor(code, message, status_code = null) {
961
+ super(message);
962
+ this.code = code;
963
+ this.status_code = status_code;
964
+ this.name = "ThreadConfigLoadError";
965
+ }
966
+ code;
967
+ status_code;
968
+ };
969
+ var BaseThreadConfigLoader = class {
970
+ async load_config_layers(context) {
971
+ const sources = await this.load(context);
972
+ return sources.map(thread_config_source_to_layer).filter((layer) => Boolean(layer));
973
+ }
974
+ };
975
+ var StaticThreadConfigLoader = class extends BaseThreadConfigLoader {
976
+ constructor(sources = []) {
977
+ super();
978
+ this.sources = sources;
979
+ }
980
+ sources;
981
+ load(context) {
982
+ return this.sources;
983
+ }
984
+ };
985
+ var NoopThreadConfigLoader = class _NoopThreadConfigLoader extends BaseThreadConfigLoader {
986
+ static instance = new _NoopThreadConfigLoader();
987
+ load(context) {
988
+ return [];
989
+ }
990
+ };
991
+ function thread_config_source_to_layer(source) {
992
+ switch (source.type) {
993
+ case "Session":
994
+ return is_empty_config(source.config) ? null : ConfigLayerEntry_new({ type: "SessionFlags" }, source.config);
995
+ case "User":
996
+ return is_empty_config(source.config) ? null : ConfigLayerEntry_new(
997
+ { type: "User", file: "$CODEX_HOME/config.toml" },
998
+ source.config
999
+ );
1000
+ }
1001
+ }
1002
+ function is_empty_config(config) {
1003
+ return Object.keys(config).length === 0;
1004
+ }
1005
+
1006
+ // src/upstream/codex-rs/config/src/loader/mod.ts
1007
+ async function load_config_layers_state(params = {}) {
1008
+ const codexHome = params.codex_home ?? "";
1009
+ const readFile = params.read_file_text ?? (() => null);
1010
+ const layers = [];
1011
+ if (params.app_config) {
1012
+ layers.push(
1013
+ load_config_toml_from_text(
1014
+ { type: "System", file: params.app_config.file },
1015
+ params.app_config.contents
1016
+ )
1017
+ );
1018
+ }
1019
+ if (!params.overrides?.ignore_user_config && codexHome) {
1020
+ layers.push(
1021
+ await load_config_toml_for_required_layer(readFile, {
1022
+ type: "User",
1023
+ file: `${codexHome.replace(/\/$/, "")}/${CONFIG_TOML_FILE}`
1024
+ })
1025
+ );
1026
+ }
1027
+ const threadConfigContext = {
1028
+ thread_id: null,
1029
+ cwd: params.cwd ?? null
1030
+ };
1031
+ const threadConfigLoader = params.thread_config_loader ?? NoopThreadConfigLoader.instance;
1032
+ for (const layer of await threadConfigLoader.load_config_layers(
1033
+ threadConfigContext
1034
+ )) {
1035
+ insert_layer_by_precedence(layers, layer);
1036
+ }
1037
+ const modelInstructionsFile = merge_config_layers(
1038
+ ConfigLayerStack_new(layers, params.startup_warnings ?? [])
1039
+ ).model_instructions_file;
1040
+ if (modelInstructionsFile) {
1041
+ const contents = await readFile(modelInstructionsFile);
1042
+ if (contents != null) {
1043
+ layers.push(
1044
+ ConfigLayerEntry_new(
1045
+ { type: "SessionFlags" },
1046
+ { model_instructions_file_contents: contents }
1047
+ )
1048
+ );
1049
+ }
1050
+ }
1051
+ if (params.cli_overrides?.length) {
1052
+ layers.push(
1053
+ ConfigLayerEntry_new(
1054
+ { type: "SessionFlags" },
1055
+ build_cli_overrides_layer(params.cli_overrides)
1056
+ )
1057
+ );
1058
+ }
1059
+ return ConfigLayerStack_new(layers, params.startup_warnings ?? []);
1060
+ }
1061
+ async function load_config(stack, overrides = {}) {
1062
+ return merge_config_layers(stack, overrides);
1063
+ }
1064
+ async function load_config_toml_for_required_layer(read_file_text, name) {
1065
+ const file = config_layer_source_file(name);
1066
+ const contents = file ? await read_file_text(file) : null;
1067
+ if (contents == null) {
1068
+ return ConfigLayerEntry_new(name, {});
1069
+ }
1070
+ return load_config_toml_from_text(name, contents);
1071
+ }
1072
+ function load_config_toml_from_text(name, contents) {
1073
+ try {
1074
+ return ConfigLayerEntry_new_with_raw_toml(
1075
+ name,
1076
+ parse_config_toml(contents),
1077
+ contents
1078
+ );
1079
+ } catch (error) {
1080
+ throw new Error(
1081
+ `Error parsing config file ${config_layer_source_label(name)}: ${String(error)}`
1082
+ );
1083
+ }
1084
+ }
1085
+ function insert_layer_by_precedence(layers, layer) {
1086
+ const index = layers.findIndex(
1087
+ (existing) => config_layer_source_precedence2(existing.name) > config_layer_source_precedence2(layer.name)
1088
+ );
1089
+ if (index === -1) {
1090
+ layers.push(layer);
1091
+ } else {
1092
+ layers.splice(index, 0, layer);
1093
+ }
1094
+ }
1095
+ function config_layer_source_precedence2(source) {
1096
+ switch (source.type) {
1097
+ case "Mdm":
1098
+ return 0;
1099
+ case "System":
1100
+ return 10;
1101
+ case "User":
1102
+ return 20;
1103
+ case "Project":
1104
+ return 25;
1105
+ case "SessionFlags":
1106
+ return 30;
1107
+ case "LegacyManagedConfigTomlFromFile":
1108
+ return 40;
1109
+ case "LegacyManagedConfigTomlFromMdm":
1110
+ return 50;
1111
+ }
1112
+ }
1113
+ function config_layer_source_file(source) {
1114
+ switch (source.type) {
1115
+ case "System":
1116
+ case "User":
1117
+ case "LegacyManagedConfigTomlFromFile":
1118
+ return source.file;
1119
+ case "Project":
1120
+ return `${source.dot_codex_folder.replace(/\/$/, "")}/${CONFIG_TOML_FILE}`;
1121
+ case "Mdm":
1122
+ case "SessionFlags":
1123
+ case "LegacyManagedConfigTomlFromMdm":
1124
+ return null;
1125
+ }
1126
+ }
1127
+ function config_layer_source_label(source) {
1128
+ return config_layer_source_file(source) ?? source.type;
1129
+ }
1130
+
1131
+ export { BUILT_IN_DANGER_NO_SANDBOX_PROFILE, BUILT_IN_READ_ONLY_PROFILE, BUILT_IN_WORKSPACE_PROFILE, BaseThreadConfigLoader, CODEX_PLAN_MODE_INSTRUCTIONS, CONFIG_TOML_FILE, ConfigLayerEntry_is_disabled, ConfigLayerEntry_new, ConfigLayerEntry_new_disabled, ConfigLayerEntry_new_with_raw_toml, ConfigLayerStackOrdering, ConfigLayerStack_effective_config, ConfigLayerStack_get_layers, ConfigLayerStack_new, ModeKind, NoopThreadConfigLoader, StaticThreadConfigLoader, TUI_VISIBLE_COLLABORATION_MODES, ThreadConfigLoadError, ToolHandlerKind, activePermissionProfileForBuiltin, active_permission_profile, allowsRequestUserInput, applyCollaborationModeMask, build_cli_overrides_layer, builtinCollaborationModePresets, builtinPermissionProfile, builtinPermissionProfileNameFromProfile, collaborationModeForModel, collaborationModePresetForMode, collaborationModeWithUpdates, config_layer_source_precedence, config_toml_from_unknown, createConfigLayerStack, createToolRegistryPlan, defaultBuiltinPermissionProfileName, defaultModeInstructions, defaultToolsConfig, disabledPermissionProfile, effectivePermissionProfile, empty_config_toml, insert_layer_by_precedence, isTomlTable, legacySandboxPolicyFromPermissionProfile, load_config, load_config_layers_state, load_config_toml_for_required_layer, load_config_toml_from_text, merge_config_layers, merge_toml_values, modeDisplayName, normalizeCollaborationMode, parse_config_toml, parse_toml_value, permissionProfileFromLegacySandboxPolicy, readOnlyPermissionProfile, resolve_config, resolve_web_search_config, resolve_web_search_mode, resolve_web_search_mode_for_turn, serialize_config_toml, thread_config_source_to_layer, validatePermissionProfile, workspaceWritePermissionProfile };
1132
+ //# sourceMappingURL=chunk-SYPHCDRD.js.map
1133
+ //# sourceMappingURL=chunk-SYPHCDRD.js.map