codex-configurator 0.1.0

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.
@@ -0,0 +1,252 @@
1
+ import {
2
+ getConfigFeatureDefinition,
3
+ getConfigFeatureDefinitionOrFallback,
4
+ } from './configFeatures.js';
5
+ import { getReferenceOptionForPath } from './configReference.js';
6
+
7
+ const CONFIG_VALUE_OPTIONS = {
8
+ model: [
9
+ 'gpt-5.3-codex',
10
+ 'gpt-5.3-codex-spark',
11
+ 'gpt-5.2-codex',
12
+ 'gpt-5.1-codex-max',
13
+ 'gpt-5.2',
14
+ 'gpt-5.1-codex-mini',
15
+ ],
16
+ };
17
+
18
+ const CONFIG_PATH_EXPLANATIONS = [
19
+ {
20
+ path: ['tools', 'web_search'],
21
+ short: 'Deprecated legacy web search flag.',
22
+ usage: 'Use the top-level web_search setting instead.',
23
+ deprecation: 'tools.web_search is deprecated; use the top-level web_search setting instead.',
24
+ },
25
+ {
26
+ path: ['projects', '*', 'trust_level'],
27
+ short: 'Controls how much trust this project gets for command execution.',
28
+ usage: 'Use trusted for known folders, untrusted for extra prompts.',
29
+ },
30
+ ];
31
+
32
+ const CONFIG_PATH_OPTIONS = [
33
+ {
34
+ path: ['projects', '*', 'trust_level'],
35
+ values: ['trusted', 'untrusted'],
36
+ explanations: {
37
+ trusted: 'Runs with normal trust for this path.',
38
+ untrusted: 'Limits risky actions and prompts more often.',
39
+ },
40
+ },
41
+ ];
42
+
43
+ const CONFIG_OPTION_EXPLANATIONS = {
44
+ model: {
45
+ 'gpt-5.3-codex': 'Latest frontier agentic coding model.',
46
+ 'gpt-5.3-codex-spark': 'Ultra-fast coding model.',
47
+ 'gpt-5.2-codex': 'Frontier agentic coding model.',
48
+ 'gpt-5.1-codex-max': 'Codex-optimized flagship for deep and fast reasoning.',
49
+ 'gpt-5.2': 'Latest frontier model with improvements across knowledge, reasoning and coding.',
50
+ 'gpt-5.1-codex-mini': 'Optimized for codex. Cheaper, faster, but less capable.',
51
+ },
52
+ trust_level: {
53
+ trusted: 'Runs with normal trust for this path.',
54
+ untrusted: 'Limits risky actions and prompts more often.',
55
+ },
56
+ };
57
+
58
+ const makePathSegments = (segments, key) => {
59
+ const normalizedSegments = Array.isArray(segments)
60
+ ? segments.map((segment) => String(segment))
61
+ : [];
62
+
63
+ if (normalizedSegments[normalizedSegments.length - 1] === String(key)) {
64
+ return normalizedSegments;
65
+ }
66
+
67
+ return [...normalizedSegments, String(key)];
68
+ };
69
+
70
+ const pathMatches = (actualPath, patternPath) =>
71
+ actualPath.length === patternPath.length &&
72
+ actualPath.every((segment, index) => patternPath[index] === '*' || patternPath[index] === segment);
73
+
74
+ const getContextEntry = (segments, key, candidates) => {
75
+ const fullPath = makePathSegments(segments, key);
76
+ return candidates.find((entry) => pathMatches(fullPath, entry.path)) || null;
77
+ };
78
+
79
+ const getReferenceEntry = (segments, key) => getReferenceOptionForPath(makePathSegments(segments, key));
80
+
81
+ const getReferenceUsage = (entry) => {
82
+ if (entry.deprecated) {
83
+ return 'This option is deprecated in the official configuration reference.';
84
+ }
85
+
86
+ if (entry.enumValues.length > 0) {
87
+ return null;
88
+ }
89
+
90
+ if (entry.type === 'boolean') {
91
+ return null;
92
+ }
93
+
94
+ if (entry.type === 'table') {
95
+ return 'This section groups related settings.';
96
+ }
97
+
98
+ if (entry.type.startsWith('array<')) {
99
+ return 'This setting accepts a list value.';
100
+ }
101
+
102
+ if (entry.type.startsWith('map<')) {
103
+ return 'This setting accepts key/value pairs.';
104
+ }
105
+
106
+ return null;
107
+ };
108
+
109
+ const buildReferenceHelp = (entry) => {
110
+ if (!entry) {
111
+ return null;
112
+ }
113
+
114
+ return {
115
+ short: entry.description || 'Official configuration option.',
116
+ usage: getReferenceUsage(entry),
117
+ deprecation: entry.deprecated ? entry.description : undefined,
118
+ };
119
+ };
120
+
121
+ export const getConfigHelp = (segments, key) => {
122
+ const contextHelp = getContextEntry(segments, key, CONFIG_PATH_EXPLANATIONS);
123
+ if (contextHelp) {
124
+ return contextHelp;
125
+ }
126
+
127
+ const referenceEntry = getReferenceEntry(segments, key);
128
+ const referenceHelp = buildReferenceHelp(referenceEntry);
129
+
130
+ if (segments?.[segments.length - 1] === 'features') {
131
+ const featureDefinition = getConfigFeatureDefinition(String(key));
132
+ if (referenceHelp) {
133
+ return {
134
+ ...referenceHelp,
135
+ usage: featureDefinition?.deprecation || referenceHelp.usage || featureDefinition?.usage || null,
136
+ deprecation: featureDefinition?.deprecation || referenceHelp.deprecation,
137
+ };
138
+ }
139
+
140
+ return getConfigFeatureDefinitionOrFallback(key);
141
+ }
142
+
143
+ if (referenceHelp) {
144
+ return referenceHelp;
145
+ }
146
+
147
+ return null;
148
+ };
149
+
150
+ export const getConfigOptions = (segments, key, value, kind) => {
151
+ if (kind !== 'value') {
152
+ return null;
153
+ }
154
+
155
+ const referenceEntry = getReferenceEntry(segments, key);
156
+
157
+ if (typeof value === 'boolean') {
158
+ return [false, true];
159
+ }
160
+
161
+ if (referenceEntry?.type === 'boolean') {
162
+ return [false, true];
163
+ }
164
+
165
+ const context = getContextEntry(segments, key, CONFIG_PATH_OPTIONS);
166
+ if (context) {
167
+ return context.values;
168
+ }
169
+
170
+ if (referenceEntry?.enumValues?.length > 0) {
171
+ return referenceEntry.enumValues;
172
+ }
173
+
174
+ if (Object.prototype.hasOwnProperty.call(CONFIG_VALUE_OPTIONS, key)) {
175
+ return CONFIG_VALUE_OPTIONS[key];
176
+ }
177
+
178
+ return null;
179
+ };
180
+
181
+ export const getConfigOptionExplanation = (segments, key, option) => {
182
+ const context = getContextEntry(segments, key, CONFIG_PATH_OPTIONS);
183
+ if (context?.explanations) {
184
+ return context.explanations[String(option)] || null;
185
+ }
186
+
187
+ return CONFIG_OPTION_EXPLANATIONS[key]?.[String(option)] || null;
188
+ };
189
+
190
+ export const getConfigDefaultOption = (segments, key, kind, options) => {
191
+ if (kind !== 'value' || !Array.isArray(options) || options.length === 0) {
192
+ return null;
193
+ }
194
+
195
+ const fullPath = makePathSegments(segments, key);
196
+ const pathKey = fullPath.join('.');
197
+ const parentPath = fullPath.slice(0, -1);
198
+ const explicitDefaults = {
199
+ approval_policy: 'on-request',
200
+ cli_auth_credentials_store: 'file',
201
+ file_opener: 'vscode',
202
+ 'history.persistence': 'save-all',
203
+ mcp_oauth_credentials_store: 'auto',
204
+ model_reasoning_summary: 'auto',
205
+ model_verbosity: 'medium',
206
+ personality: 'pragmatic',
207
+ sandbox_mode: 'read-only',
208
+ 'shell_environment_policy.inherit': 'all',
209
+ 'tui.alternate_screen': 'auto',
210
+ 'tui.notification_method': 'auto',
211
+ };
212
+
213
+ if (parentPath[parentPath.length - 1] === 'features') {
214
+ const definition = getConfigFeatureDefinition(String(key));
215
+ const featureDefault = definition?.defaultValue;
216
+
217
+ if (typeof featureDefault === 'boolean') {
218
+ return options.some((option) => Object.is(option, featureDefault))
219
+ ? featureDefault
220
+ : null;
221
+ }
222
+ }
223
+
224
+ if (
225
+ fullPath.length >= 3 &&
226
+ fullPath[0] === 'projects' &&
227
+ fullPath[fullPath.length - 1] === 'trust_level'
228
+ ) {
229
+ return options.some((option) => option === 'untrusted') ? 'untrusted' : null;
230
+ }
231
+
232
+ if (pathKey === 'web_search') {
233
+ return options.some((option) => option === 'cached') ? 'cached' : null;
234
+ }
235
+
236
+ if (
237
+ fullPath.length >= 3 &&
238
+ fullPath[0] === 'profiles' &&
239
+ fullPath[fullPath.length - 1] === 'web_search'
240
+ ) {
241
+ return options.some((option) => option === 'cached') ? 'cached' : null;
242
+ }
243
+
244
+ if (Object.prototype.hasOwnProperty.call(explicitDefaults, pathKey)) {
245
+ const explicitDefault = explicitDefaults[pathKey];
246
+ return options.some((option) => Object.is(option, explicitDefault))
247
+ ? explicitDefault
248
+ : null;
249
+ }
250
+
251
+ return null;
252
+ };