@gakr-gakr/codex 0.1.0 → 0.1.1

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 (115) hide show
  1. package/dist/client-DNN2uyJW.js +642 -0
  2. package/dist/client-factory-Bu9OClHJ.js +9 -0
  3. package/dist/command-formatters-BpPOTePl.js +520 -0
  4. package/dist/command-handlers-BBs7Vws9.js +1533 -0
  5. package/dist/compact-CDboBy7o.js +329 -0
  6. package/dist/computer-use-DCZB46Sw.js +367 -0
  7. package/dist/config-CLMSw0p2.js +510 -0
  8. package/dist/doctor-contract-api.js +53 -0
  9. package/dist/harness.js +51 -0
  10. package/dist/index.js +1171 -0
  11. package/dist/media-understanding-provider.js +335 -0
  12. package/dist/models-jLA2SIvd.js +110 -0
  13. package/dist/node-cli-sessions-BLRDs_US.js +1216 -0
  14. package/dist/plugin-activation-CEy_oYpx.js +452 -0
  15. package/dist/prompt-overlay.js +12 -0
  16. package/dist/protocol-C9UWI98H.js +9 -0
  17. package/dist/protocol-validators-BGBspNmF.js +5988 -0
  18. package/dist/provider-catalog.js +84 -0
  19. package/dist/provider-discovery.js +33 -0
  20. package/dist/provider.js +150 -0
  21. package/dist/rate-limit-cache-9LxQdE0K.js +24 -0
  22. package/dist/request-DbSPeTcV.js +89 -0
  23. package/dist/rolldown-runtime-DUslC3ob.js +14 -0
  24. package/dist/run-attempt-BoEwzQCv.js +5463 -0
  25. package/dist/session-binding-e2GFp9VH.js +222 -0
  26. package/dist/shared-client-D7Vy0glq.js +631 -0
  27. package/dist/side-question-BDLuEzFP.js +668 -0
  28. package/dist/test-api.js +49 -0
  29. package/dist/thread-lifecycle-Clo0EHMk.js +1565 -0
  30. package/dist/vision-tools-Cofrv35p.js +1379 -0
  31. package/package.json +16 -1
  32. package/doctor-contract-api.ts +0 -68
  33. package/harness.ts +0 -72
  34. package/index.ts +0 -124
  35. package/media-understanding-provider.ts +0 -521
  36. package/prompt-overlay.ts +0 -21
  37. package/provider-catalog.ts +0 -83
  38. package/provider-discovery.ts +0 -45
  39. package/provider.ts +0 -243
  40. package/src/app-server/app-inventory-cache.ts +0 -324
  41. package/src/app-server/approval-bridge.ts +0 -1211
  42. package/src/app-server/auth-bridge.ts +0 -614
  43. package/src/app-server/capabilities.ts +0 -27
  44. package/src/app-server/client-factory.ts +0 -24
  45. package/src/app-server/client.ts +0 -715
  46. package/src/app-server/compact.ts +0 -512
  47. package/src/app-server/computer-use.ts +0 -683
  48. package/src/app-server/config.ts +0 -1038
  49. package/src/app-server/context-engine-projection.ts +0 -403
  50. package/src/app-server/dynamic-tool-diagnostics.ts +0 -73
  51. package/src/app-server/dynamic-tool-profile.ts +0 -70
  52. package/src/app-server/dynamic-tools.ts +0 -623
  53. package/src/app-server/elicitation-bridge.ts +0 -783
  54. package/src/app-server/event-projector.ts +0 -2065
  55. package/src/app-server/image-payload-sanitizer.ts +0 -167
  56. package/src/app-server/local-runtime-attribution.ts +0 -39
  57. package/src/app-server/managed-binary.ts +0 -193
  58. package/src/app-server/models.ts +0 -172
  59. package/src/app-server/native-hook-relay.ts +0 -150
  60. package/src/app-server/native-subagent-task-mirror.ts +0 -497
  61. package/src/app-server/plugin-activation.ts +0 -283
  62. package/src/app-server/plugin-app-cache-key.ts +0 -74
  63. package/src/app-server/plugin-approval-roundtrip.ts +0 -122
  64. package/src/app-server/plugin-inventory.ts +0 -357
  65. package/src/app-server/plugin-thread-config.ts +0 -455
  66. package/src/app-server/protocol-generated/json/DynamicToolCallParams.json +0 -33
  67. package/src/app-server/protocol-generated/json/v2/ErrorNotification.json +0 -199
  68. package/src/app-server/protocol-generated/json/v2/GetAccountResponse.json +0 -102
  69. package/src/app-server/protocol-generated/json/v2/ModelListResponse.json +0 -227
  70. package/src/app-server/protocol-generated/json/v2/ThreadResumeResponse.json +0 -2630
  71. package/src/app-server/protocol-generated/json/v2/ThreadStartResponse.json +0 -2630
  72. package/src/app-server/protocol-generated/json/v2/TurnCompletedNotification.json +0 -1659
  73. package/src/app-server/protocol-generated/json/v2/TurnStartResponse.json +0 -1655
  74. package/src/app-server/protocol-validators.ts +0 -203
  75. package/src/app-server/protocol.ts +0 -520
  76. package/src/app-server/rate-limit-cache.ts +0 -48
  77. package/src/app-server/rate-limits.ts +0 -583
  78. package/src/app-server/request.ts +0 -73
  79. package/src/app-server/run-attempt.ts +0 -4862
  80. package/src/app-server/session-binding.ts +0 -398
  81. package/src/app-server/session-history.ts +0 -44
  82. package/src/app-server/shared-client.ts +0 -289
  83. package/src/app-server/side-question.ts +0 -1009
  84. package/src/app-server/test-support.ts +0 -48
  85. package/src/app-server/thread-lifecycle.ts +0 -959
  86. package/src/app-server/timeout.ts +0 -9
  87. package/src/app-server/tool-progress-normalization.ts +0 -77
  88. package/src/app-server/trajectory.ts +0 -368
  89. package/src/app-server/transcript-mirror.ts +0 -208
  90. package/src/app-server/transport-stdio.ts +0 -107
  91. package/src/app-server/transport-websocket.ts +0 -90
  92. package/src/app-server/transport.ts +0 -117
  93. package/src/app-server/user-input-bridge.ts +0 -316
  94. package/src/app-server/version.ts +0 -4
  95. package/src/app-server/vision-tools.ts +0 -12
  96. package/src/command-account.ts +0 -544
  97. package/src/command-formatters.ts +0 -426
  98. package/src/command-handlers.ts +0 -2021
  99. package/src/command-plugins-management.ts +0 -137
  100. package/src/command-rpc.ts +0 -142
  101. package/src/commands.ts +0 -65
  102. package/src/conversation-binding-data.ts +0 -124
  103. package/src/conversation-binding.ts +0 -561
  104. package/src/conversation-control.ts +0 -303
  105. package/src/conversation-turn-collector.ts +0 -186
  106. package/src/conversation-turn-input.ts +0 -106
  107. package/src/migration/apply.ts +0 -501
  108. package/src/migration/helpers.ts +0 -55
  109. package/src/migration/plan.ts +0 -461
  110. package/src/migration/provider.ts +0 -41
  111. package/src/migration/source.ts +0 -643
  112. package/src/migration/targets.ts +0 -25
  113. package/src/node-cli-sessions.ts +0 -711
  114. package/test-api.ts +0 -95
  115. package/tsconfig.json +0 -16
@@ -0,0 +1,510 @@
1
+ import { createHmac, randomBytes } from "node:crypto";
2
+ import { readFileSync } from "node:fs";
3
+ import { hostname } from "node:os";
4
+ import { z } from "zod";
5
+ //#region extensions/codex/src/app-server/config.ts
6
+ const START_OPTIONS_KEY_SECRET_SYMBOL = Symbol.for("autobot.codexAppServerStartOptionsKeySecret");
7
+ const START_OPTIONS_KEY_SECRET = getStartOptionsKeySecret();
8
+ const UNIX_CODEX_REQUIREMENTS_PATH = "/etc/codex/requirements.toml";
9
+ const WINDOWS_CODEX_REQUIREMENTS_SUFFIX = "\\OpenAI\\Codex\\requirements.toml";
10
+ const CODEX_PLUGINS_MARKETPLACE_NAME = "openai-curated";
11
+ const DEFAULT_CODEX_COMPUTER_USE_PLUGIN_NAME = "computer-use";
12
+ const DEFAULT_CODEX_COMPUTER_USE_MCP_SERVER_NAME = "computer-use";
13
+ const DEFAULT_CODEX_COMPUTER_USE_MARKETPLACE_DISCOVERY_TIMEOUT_MS = 6e4;
14
+ const codexAppServerTransportSchema = z.enum(["stdio", "websocket"]);
15
+ const codexAppServerPolicyModeSchema = z.enum(["yolo", "guardian"]);
16
+ const codexAppServerApprovalPolicySchema = z.enum([
17
+ "never",
18
+ "on-request",
19
+ "on-failure",
20
+ "untrusted"
21
+ ]);
22
+ const codexAppServerSandboxSchema = z.enum([
23
+ "read-only",
24
+ "workspace-write",
25
+ "danger-full-access"
26
+ ]);
27
+ const codexAppServerApprovalsReviewerSchema = z.enum([
28
+ "user",
29
+ "auto_review",
30
+ "guardian_subagent"
31
+ ]);
32
+ const codexDynamicToolsLoadingSchema = z.enum(["searchable", "direct"]);
33
+ const codexAppServerServiceTierSchema = z.preprocess((value) => value === null ? null : normalizeCodexServiceTier(value), z.string().trim().min(1).nullable().optional()).optional();
34
+ const codexPluginEntryConfigSchema = z.object({
35
+ enabled: z.boolean().optional(),
36
+ marketplaceName: z.literal(CODEX_PLUGINS_MARKETPLACE_NAME).optional(),
37
+ pluginName: z.string().trim().min(1).optional(),
38
+ allow_destructive_actions: z.boolean().optional()
39
+ }).strict();
40
+ const codexPluginsConfigSchema = z.object({
41
+ enabled: z.boolean().optional(),
42
+ allow_destructive_actions: z.boolean().optional(),
43
+ plugins: z.record(z.string(), codexPluginEntryConfigSchema).optional()
44
+ }).strict();
45
+ const codexPluginConfigSchema = z.object({
46
+ codexDynamicToolsLoading: codexDynamicToolsLoadingSchema.optional(),
47
+ codexDynamicToolsExclude: z.array(z.string()).optional(),
48
+ discovery: z.object({
49
+ enabled: z.boolean().optional(),
50
+ timeoutMs: z.number().positive().optional()
51
+ }).strict().optional(),
52
+ computerUse: z.object({
53
+ enabled: z.boolean().optional(),
54
+ autoInstall: z.boolean().optional(),
55
+ marketplaceDiscoveryTimeoutMs: z.number().positive().optional(),
56
+ marketplaceSource: z.string().optional(),
57
+ marketplacePath: z.string().optional(),
58
+ marketplaceName: z.string().optional(),
59
+ pluginName: z.string().optional(),
60
+ mcpServerName: z.string().optional()
61
+ }).strict().optional(),
62
+ codexPlugins: z.unknown().optional(),
63
+ appServer: z.object({
64
+ mode: codexAppServerPolicyModeSchema.optional(),
65
+ transport: codexAppServerTransportSchema.optional(),
66
+ command: z.string().optional(),
67
+ args: z.union([z.array(z.string()), z.string()]).optional(),
68
+ url: z.string().optional(),
69
+ authToken: z.string().optional(),
70
+ headers: z.record(z.string(), z.string()).optional(),
71
+ clearEnv: z.array(z.string()).optional(),
72
+ codeModeOnly: z.boolean().optional(),
73
+ requestTimeoutMs: z.number().positive().optional(),
74
+ turnCompletionIdleTimeoutMs: z.number().positive().optional(),
75
+ approvalPolicy: codexAppServerApprovalPolicySchema.optional(),
76
+ sandbox: codexAppServerSandboxSchema.optional(),
77
+ approvalsReviewer: codexAppServerApprovalsReviewerSchema.optional(),
78
+ serviceTier: codexAppServerServiceTierSchema,
79
+ defaultWorkspaceDir: z.string().optional()
80
+ }).strict().optional()
81
+ }).strict();
82
+ function readCodexPluginConfig(value) {
83
+ const parsed = codexPluginConfigSchema.safeParse(value);
84
+ if (!parsed.success) return {};
85
+ const { codexPlugins: rawCodexPlugins, ...config } = parsed.data;
86
+ const plugins = codexPluginsConfigSchema.safeParse(rawCodexPlugins);
87
+ if (!plugins.success) return config;
88
+ return {
89
+ ...config,
90
+ ...plugins.data ? { codexPlugins: plugins.data } : {}
91
+ };
92
+ }
93
+ function resolveCodexPluginsPolicy(pluginConfig) {
94
+ const config = readCodexPluginConfig(pluginConfig).codexPlugins;
95
+ const configured = config !== void 0;
96
+ const enabled = config?.enabled === true;
97
+ const allowDestructiveActions = config?.allow_destructive_actions ?? true;
98
+ return {
99
+ configured,
100
+ enabled,
101
+ allowDestructiveActions,
102
+ pluginPolicies: Object.entries(config?.plugins ?? {}).flatMap(([configKey, entry]) => {
103
+ if (entry.marketplaceName !== "openai-curated" || !entry.pluginName) return [];
104
+ return [{
105
+ configKey,
106
+ marketplaceName: CODEX_PLUGINS_MARKETPLACE_NAME,
107
+ pluginName: entry.pluginName,
108
+ enabled: enabled && entry.enabled !== false,
109
+ allowDestructiveActions: entry.allow_destructive_actions ?? allowDestructiveActions
110
+ }];
111
+ }).toSorted((left, right) => left.configKey.localeCompare(right.configKey))
112
+ };
113
+ }
114
+ function resolveCodexAppServerRuntimeOptions(params = {}) {
115
+ const env = params.env ?? process.env;
116
+ const config = readCodexPluginConfig(params.pluginConfig).appServer ?? {};
117
+ const transport = resolveTransport(config.transport);
118
+ const configCommand = readNonEmptyString(config.command);
119
+ const envCommand = readNonEmptyString(env.AUTOBOT_CODEX_APP_SERVER_BIN);
120
+ const command = configCommand ?? envCommand ?? "codex";
121
+ const commandSource = configCommand ? "config" : envCommand ? "env" : "managed";
122
+ const args = resolveArgs(config.args, env.AUTOBOT_CODEX_APP_SERVER_ARGS);
123
+ const headers = normalizeHeaders(config.headers);
124
+ const clearEnv = normalizeStringList(config.clearEnv);
125
+ const authToken = readNonEmptyString(config.authToken);
126
+ const url = readNonEmptyString(config.url);
127
+ const explicitPolicyMode = resolvePolicyMode(config.mode) ?? resolvePolicyMode(env.AUTOBOT_CODEX_APP_SERVER_MODE);
128
+ const defaultPolicy = explicitPolicyMode ? void 0 : resolveDefaultCodexAppServerPolicy({
129
+ transport,
130
+ env,
131
+ requirementsToml: params.requirementsToml,
132
+ requirementsPath: params.requirementsPath,
133
+ readRequirementsFile: params.readRequirementsFile,
134
+ platform: params.platform,
135
+ hostName: params.hostName
136
+ });
137
+ const policyMode = explicitPolicyMode ?? defaultPolicy?.mode ?? "yolo";
138
+ const serviceTier = normalizeCodexServiceTier(config.serviceTier);
139
+ if (transport === "websocket" && !url) throw new Error("plugins.entries.codex.config.appServer.url is required when appServer.transport is websocket");
140
+ return {
141
+ start: {
142
+ transport,
143
+ command,
144
+ commandSource,
145
+ args: args.length > 0 ? args : [
146
+ "app-server",
147
+ "--listen",
148
+ "stdio://"
149
+ ],
150
+ ...url ? { url } : {},
151
+ ...authToken ? { authToken } : {},
152
+ headers,
153
+ ...transport === "stdio" && clearEnv.length > 0 ? { clearEnv } : {}
154
+ },
155
+ codeModeOnly: config.codeModeOnly === true,
156
+ requestTimeoutMs: normalizePositiveNumber(config.requestTimeoutMs, 6e4),
157
+ turnCompletionIdleTimeoutMs: normalizePositiveNumber(config.turnCompletionIdleTimeoutMs, 6e4),
158
+ approvalPolicy: resolveApprovalPolicy(config.approvalPolicy) ?? resolveApprovalPolicy(env.AUTOBOT_CODEX_APP_SERVER_APPROVAL_POLICY) ?? defaultPolicy?.approvalPolicy ?? (policyMode === "guardian" ? "on-request" : "never"),
159
+ sandbox: resolveSandbox(config.sandbox) ?? resolveSandbox(env.AUTOBOT_CODEX_APP_SERVER_SANDBOX) ?? defaultPolicy?.sandbox ?? (policyMode === "guardian" ? "workspace-write" : "danger-full-access"),
160
+ approvalsReviewer: resolveApprovalsReviewer(config.approvalsReviewer) ?? defaultPolicy?.approvalsReviewer ?? (policyMode === "guardian" ? "auto_review" : "user"),
161
+ ...serviceTier ? { serviceTier } : {}
162
+ };
163
+ }
164
+ function isCodexAppServerApprovalPolicyAllowedByRequirements(policy, params = {}) {
165
+ const content = readCodexRequirementsToml(params);
166
+ if (content === void 0) return true;
167
+ const allowedApprovalPolicies = parseAllowedApprovalPoliciesFromCodexRequirements(content);
168
+ return allowedApprovalPolicies === void 0 || allowedApprovalPolicies.has(policy);
169
+ }
170
+ function resolveCodexComputerUseConfig(params = {}) {
171
+ const env = params.env ?? process.env;
172
+ const config = readCodexPluginConfig(params.pluginConfig).computerUse ?? {};
173
+ const marketplaceSource = readNonEmptyString(params.overrides?.marketplaceSource) ?? readNonEmptyString(config.marketplaceSource) ?? readNonEmptyString(env.AUTOBOT_CODEX_COMPUTER_USE_MARKETPLACE_SOURCE);
174
+ const marketplacePath = readNonEmptyString(params.overrides?.marketplacePath) ?? readNonEmptyString(config.marketplacePath) ?? readNonEmptyString(env.AUTOBOT_CODEX_COMPUTER_USE_MARKETPLACE_PATH);
175
+ const marketplaceName = readNonEmptyString(params.overrides?.marketplaceName) ?? readNonEmptyString(config.marketplaceName) ?? readNonEmptyString(env.AUTOBOT_CODEX_COMPUTER_USE_MARKETPLACE_NAME);
176
+ const autoInstall = params.overrides?.autoInstall ?? config.autoInstall ?? readBooleanEnv(env.AUTOBOT_CODEX_COMPUTER_USE_AUTO_INSTALL) ?? false;
177
+ const marketplaceDiscoveryTimeoutMs = normalizePositiveNumber(params.overrides?.marketplaceDiscoveryTimeoutMs ?? config.marketplaceDiscoveryTimeoutMs ?? readNumberEnv(env.AUTOBOT_CODEX_COMPUTER_USE_MARKETPLACE_DISCOVERY_TIMEOUT_MS), DEFAULT_CODEX_COMPUTER_USE_MARKETPLACE_DISCOVERY_TIMEOUT_MS);
178
+ return {
179
+ enabled: params.overrides?.enabled ?? config.enabled ?? readBooleanEnv(env.AUTOBOT_CODEX_COMPUTER_USE) ?? Boolean(autoInstall || marketplaceSource || marketplacePath || marketplaceName),
180
+ autoInstall,
181
+ marketplaceDiscoveryTimeoutMs,
182
+ pluginName: readNonEmptyString(params.overrides?.pluginName) ?? readNonEmptyString(config.pluginName) ?? readNonEmptyString(env.AUTOBOT_CODEX_COMPUTER_USE_PLUGIN_NAME) ?? DEFAULT_CODEX_COMPUTER_USE_PLUGIN_NAME,
183
+ mcpServerName: readNonEmptyString(params.overrides?.mcpServerName) ?? readNonEmptyString(config.mcpServerName) ?? readNonEmptyString(env.AUTOBOT_CODEX_COMPUTER_USE_MCP_SERVER_NAME) ?? DEFAULT_CODEX_COMPUTER_USE_MCP_SERVER_NAME,
184
+ ...marketplaceSource ? { marketplaceSource } : {},
185
+ ...marketplacePath ? { marketplacePath } : {},
186
+ ...marketplaceName ? { marketplaceName } : {}
187
+ };
188
+ }
189
+ function codexAppServerStartOptionsKey(options, params = {}) {
190
+ return JSON.stringify({
191
+ transport: options.transport,
192
+ command: options.command,
193
+ commandSource: options.commandSource ?? null,
194
+ args: options.args,
195
+ url: options.url ?? null,
196
+ authToken: hashSecretForKey(options.authToken, "authToken"),
197
+ headers: Object.entries(options.headers).toSorted(([left], [right]) => left.localeCompare(right)),
198
+ env: Object.entries(options.env ?? {}).toSorted(([left], [right]) => left.localeCompare(right)).map(([key, value]) => [key, hashSecretForKey(value, `env:${key}`)]),
199
+ clearEnv: [...options.clearEnv ?? []].toSorted(),
200
+ authProfileId: params.authProfileId ?? null,
201
+ agentDir: params.agentDir ?? null
202
+ });
203
+ }
204
+ function codexSandboxPolicyForTurn(mode, cwd) {
205
+ if (mode === "danger-full-access") return { type: "dangerFullAccess" };
206
+ if (mode === "read-only") return {
207
+ type: "readOnly",
208
+ networkAccess: false
209
+ };
210
+ return {
211
+ type: "workspaceWrite",
212
+ writableRoots: [cwd],
213
+ networkAccess: false,
214
+ excludeTmpdirEnvVar: false,
215
+ excludeSlashTmp: false
216
+ };
217
+ }
218
+ function withMcpElicitationsApprovalPolicy(policy) {
219
+ if (typeof policy !== "string") return { granular: {
220
+ ...policy.granular,
221
+ mcp_elicitations: true
222
+ } };
223
+ if (policy === "never") return { granular: {
224
+ mcp_elicitations: true,
225
+ rules: false,
226
+ sandbox_approval: false
227
+ } };
228
+ return { granular: {
229
+ mcp_elicitations: true,
230
+ rules: true,
231
+ sandbox_approval: true
232
+ } };
233
+ }
234
+ function resolveTransport(value) {
235
+ return value === "websocket" ? "websocket" : "stdio";
236
+ }
237
+ function resolvePolicyMode(value) {
238
+ return value === "guardian" || value === "yolo" ? value : void 0;
239
+ }
240
+ function resolveDefaultCodexAppServerPolicy(params) {
241
+ if (params.transport !== "stdio") return { mode: "yolo" };
242
+ const content = readCodexRequirementsToml(params);
243
+ if (content === void 0) return { mode: "yolo" };
244
+ const allowedSandboxModes = parseAllowedSandboxModesFromCodexRequirements(content, readNonEmptyString(params.hostName) ?? hostname());
245
+ const allowedApprovalPolicies = parseAllowedApprovalPoliciesFromCodexRequirements(content);
246
+ const allowedApprovalsReviewers = parseAllowedApprovalsReviewersFromCodexRequirements(content);
247
+ const yoloSandboxAllowed = allowedSandboxModes === void 0 || allowedSandboxModes.has("danger-full-access");
248
+ const yoloApprovalAllowed = allowedApprovalPolicies === void 0 || allowedApprovalPolicies.has("never");
249
+ const yoloReviewerAllowed = allowedApprovalsReviewers === void 0 || allowedApprovalsReviewers.has("user");
250
+ if (yoloSandboxAllowed && yoloApprovalAllowed && yoloReviewerAllowed) return { mode: "yolo" };
251
+ return {
252
+ mode: "guardian",
253
+ approvalPolicy: selectGuardianApprovalPolicy(allowedApprovalPolicies),
254
+ approvalsReviewer: selectGuardianApprovalsReviewer(allowedApprovalsReviewers),
255
+ sandbox: selectGuardianSandbox(allowedSandboxModes)
256
+ };
257
+ }
258
+ function readCodexRequirementsToml(params) {
259
+ if (params.requirementsToml !== void 0) return params.requirementsToml ?? void 0;
260
+ const path = readNonEmptyString(params.requirementsPath) ?? resolveCodexRequirementsPath(params.env ?? process.env, params.platform ?? process.platform);
261
+ try {
262
+ if (params.readRequirementsFile) return params.readRequirementsFile(path);
263
+ return readFileSync(path, "utf8");
264
+ } catch {
265
+ return;
266
+ }
267
+ }
268
+ function resolveCodexRequirementsPath(env, platform) {
269
+ if (platform === "win32") return `${(readNonEmptyString(env.ProgramData) ?? "C:\\ProgramData").replace(/[\\/]+$/, "")}${WINDOWS_CODEX_REQUIREMENTS_SUFFIX}`;
270
+ return UNIX_CODEX_REQUIREMENTS_PATH;
271
+ }
272
+ function parseAllowedSandboxModesFromCodexRequirements(content, hostName) {
273
+ const remoteSandboxModes = parseMatchingRemoteSandboxModesFromCodexRequirements(content, hostName);
274
+ if (remoteSandboxModes !== void 0) return remoteSandboxModes;
275
+ return parseRequirementsSandboxModes(parseTopLevelRequirementsStringArray(content, "allowed_sandbox_modes"));
276
+ }
277
+ function parseAllowedApprovalPoliciesFromCodexRequirements(content) {
278
+ const values = parseTopLevelRequirementsStringArray(content, "allowed_approval_policies");
279
+ if (values === void 0) return;
280
+ const normalizedPolicies = values.map((entry) => normalizeRequirementsApprovalPolicy(entry)).filter((entry) => entry !== void 0);
281
+ return normalizedPolicies.length > 0 ? new Set(normalizedPolicies) : void 0;
282
+ }
283
+ function parseAllowedApprovalsReviewersFromCodexRequirements(content) {
284
+ const values = parseTopLevelRequirementsStringArray(content, "allowed_approvals_reviewers");
285
+ if (values === void 0) return;
286
+ const normalizedReviewers = values.map((entry) => normalizeRequirementsApprovalsReviewer(entry)).filter((entry) => entry !== void 0);
287
+ return normalizedReviewers.length > 0 ? new Set(normalizedReviewers) : void 0;
288
+ }
289
+ function parseMatchingRemoteSandboxModesFromCodexRequirements(content, hostName) {
290
+ const normalizedHostName = normalizeRequirementsHostName(hostName);
291
+ if (normalizedHostName === void 0) return;
292
+ for (const section of parseTomlArrayTableSections(content, "remote_sandbox_config")) {
293
+ const patterns = parseRequirementsStringArray(section, "hostname_patterns");
294
+ if (!patterns || !requirementsHostNameMatchesAnyPattern(normalizedHostName, patterns)) continue;
295
+ return parseRequirementsSandboxModes(parseRequirementsStringArray(section, "allowed_sandbox_modes"));
296
+ }
297
+ }
298
+ function parseRequirementsSandboxModes(values) {
299
+ if (values === void 0) return;
300
+ const normalizedModes = values.map((entry) => normalizeRequirementsSandboxMode(entry)).filter((entry) => entry !== void 0);
301
+ return normalizedModes.length > 0 ? new Set(normalizedModes) : void 0;
302
+ }
303
+ function parseTopLevelRequirementsStringArray(content, key) {
304
+ return parseRequirementsStringArray(stripTomlLineComments(content).slice(0, firstTomlTableOffset(content)), key);
305
+ }
306
+ function parseRequirementsStringArray(content, key) {
307
+ const match = content.match(new RegExp(`(?:^|\\n)\\s*${key}\\s*=\\s*\\[([\\s\\S]*?)\\]`));
308
+ if (!match) return;
309
+ const arrayBody = match[1] ?? "";
310
+ const stringMatches = [...arrayBody.matchAll(/"([^"\\]*(?:\\.[^"\\]*)*)"|'([^']*)'/g)];
311
+ if (stringMatches.length === 0 && arrayBody.trim().length > 0) return;
312
+ return stringMatches.map((entry) => entry[1] ?? entry[2] ?? "");
313
+ }
314
+ function parseTomlArrayTableSections(content, table) {
315
+ const strippedContent = stripTomlLineComments(content);
316
+ const escapedTable = table.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
317
+ const headerPattern = new RegExp(`^\\s*\\[\\[\\s*${escapedTable}\\s*\\]\\]\\s*$`, "gm");
318
+ const sections = [];
319
+ for (let match = headerPattern.exec(strippedContent); match; match = headerPattern.exec(strippedContent)) {
320
+ const sectionStart = headerPattern.lastIndex;
321
+ const rest = strippedContent.slice(sectionStart);
322
+ const nextTableOffset = rest.search(/^\s*\[/m);
323
+ sections.push(nextTableOffset === -1 ? rest : rest.slice(0, nextTableOffset));
324
+ }
325
+ return sections;
326
+ }
327
+ function firstTomlTableOffset(content) {
328
+ return content.match(/^\s*\[[^\]\n]/m)?.index ?? content.length;
329
+ }
330
+ function stripTomlLineComments(value) {
331
+ let output = "";
332
+ let quote;
333
+ let escaped = false;
334
+ for (let index = 0; index < value.length; index += 1) {
335
+ const char = value[index] ?? "";
336
+ if (quote) {
337
+ output += char;
338
+ if (quote === "\"" && escaped) {
339
+ escaped = false;
340
+ continue;
341
+ }
342
+ if (quote === "\"" && char === "\\") {
343
+ escaped = true;
344
+ continue;
345
+ }
346
+ if (char === quote) quote = void 0;
347
+ continue;
348
+ }
349
+ if (char === "\"" || char === "'") {
350
+ quote = char;
351
+ output += char;
352
+ continue;
353
+ }
354
+ if (char === "#") {
355
+ while (index < value.length && value[index] !== "\n") index += 1;
356
+ if (value[index] === "\n") output += "\n";
357
+ continue;
358
+ }
359
+ output += char;
360
+ }
361
+ return output;
362
+ }
363
+ function normalizeRequirementsSandboxMode(value) {
364
+ const compact = value.replace(/[\s_-]/g, "").toLowerCase();
365
+ if (compact === "readonly") return "read-only";
366
+ if (compact === "workspacewrite") return "workspace-write";
367
+ if (compact === "dangerfullaccess") return "danger-full-access";
368
+ }
369
+ function normalizeRequirementsHostName(value) {
370
+ const normalized = value.trim().replace(/\.+$/g, "").toLowerCase();
371
+ return normalized.length > 0 ? normalized : void 0;
372
+ }
373
+ function requirementsHostNameMatchesAnyPattern(hostName, patterns) {
374
+ return patterns.some((pattern) => {
375
+ const normalizedPattern = normalizeRequirementsHostName(pattern);
376
+ return normalizedPattern !== void 0 && globPatternMatches(hostName, normalizedPattern);
377
+ });
378
+ }
379
+ function globPatternMatches(value, pattern) {
380
+ let regex = "^";
381
+ for (const char of pattern) if (char === "*") regex += ".*";
382
+ else if (char === "?") regex += ".";
383
+ else regex += char.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
384
+ regex += "$";
385
+ return new RegExp(regex).test(value);
386
+ }
387
+ function normalizeRequirementsApprovalPolicy(value) {
388
+ return resolveApprovalPolicy(value.trim().toLowerCase());
389
+ }
390
+ function normalizeRequirementsApprovalsReviewer(value) {
391
+ return resolveApprovalsReviewer(value.trim().toLowerCase());
392
+ }
393
+ function selectGuardianApprovalPolicy(allowedApprovalPolicies) {
394
+ if (allowedApprovalPolicies === void 0 || allowedApprovalPolicies.has("on-request")) return "on-request";
395
+ if (allowedApprovalPolicies.has("on-failure")) return "on-failure";
396
+ if (allowedApprovalPolicies.has("untrusted")) return "untrusted";
397
+ if (allowedApprovalPolicies.has("never")) return "never";
398
+ return "on-request";
399
+ }
400
+ function selectGuardianApprovalsReviewer(allowedApprovalsReviewers) {
401
+ if (allowedApprovalsReviewers === void 0 || allowedApprovalsReviewers.has("auto_review")) return "auto_review";
402
+ if (allowedApprovalsReviewers.has("guardian_subagent")) return "guardian_subagent";
403
+ if (allowedApprovalsReviewers.has("user")) return "user";
404
+ return "auto_review";
405
+ }
406
+ function selectGuardianSandbox(allowedSandboxModes) {
407
+ if (allowedSandboxModes === void 0 || allowedSandboxModes.has("workspace-write")) return "workspace-write";
408
+ if (allowedSandboxModes.has("read-only")) return "read-only";
409
+ if (allowedSandboxModes.has("danger-full-access")) return "danger-full-access";
410
+ return "workspace-write";
411
+ }
412
+ function resolveApprovalPolicy(value) {
413
+ return value === "on-request" || value === "on-failure" || value === "untrusted" || value === "never" ? value : void 0;
414
+ }
415
+ function resolveSandbox(value) {
416
+ return value === "read-only" || value === "workspace-write" || value === "danger-full-access" ? value : void 0;
417
+ }
418
+ function resolveApprovalsReviewer(value) {
419
+ return value === "auto_review" || value === "guardian_subagent" || value === "user" ? value : void 0;
420
+ }
421
+ function normalizeCodexServiceTier(value) {
422
+ if (typeof value !== "string") return;
423
+ const trimmed = value.trim();
424
+ if (!trimmed) return;
425
+ const normalized = trimmed.toLowerCase();
426
+ if (normalized === "fast" || normalized === "priority") return "priority";
427
+ if (normalized === "flex") return "flex";
428
+ return trimmed;
429
+ }
430
+ function isCodexFastServiceTier(value) {
431
+ return normalizeCodexServiceTier(value) === "priority";
432
+ }
433
+ function normalizePositiveNumber(value, fallback) {
434
+ return typeof value === "number" && Number.isFinite(value) && value > 0 ? value : fallback;
435
+ }
436
+ function normalizeHeaders(value) {
437
+ if (!value || typeof value !== "object" || Array.isArray(value)) return {};
438
+ return Object.fromEntries(Object.entries(value).map(([key, child]) => [key.trim(), readNonEmptyString(child)]).filter((entry) => Boolean(entry[0] && entry[1])));
439
+ }
440
+ function normalizeStringList(value) {
441
+ if (!Array.isArray(value)) return [];
442
+ return value.map((entry) => readNonEmptyString(entry)).filter((entry) => entry !== void 0);
443
+ }
444
+ function readBooleanEnv(value) {
445
+ if (value === void 0) return;
446
+ const normalized = value.trim().toLowerCase();
447
+ if ([
448
+ "1",
449
+ "true",
450
+ "yes",
451
+ "on"
452
+ ].includes(normalized)) return true;
453
+ if ([
454
+ "0",
455
+ "false",
456
+ "no",
457
+ "off"
458
+ ].includes(normalized)) return false;
459
+ }
460
+ function readNumberEnv(value) {
461
+ if (value === void 0) return;
462
+ const parsed = Number(value);
463
+ return Number.isFinite(parsed) ? parsed : void 0;
464
+ }
465
+ function resolveArgs(configArgs, envArgs) {
466
+ if (Array.isArray(configArgs)) return configArgs.map((entry) => readNonEmptyString(entry)).filter((entry) => entry !== void 0);
467
+ if (typeof configArgs === "string") return splitShellWords(configArgs);
468
+ return splitShellWords(envArgs ?? "");
469
+ }
470
+ function readNonEmptyString(value) {
471
+ if (typeof value !== "string") return;
472
+ return value.trim() || void 0;
473
+ }
474
+ function hashSecretForKey(value, label) {
475
+ if (!value) return null;
476
+ return createHmac("sha256", START_OPTIONS_KEY_SECRET).update(label).update("\0").update(value).digest("hex");
477
+ }
478
+ function getStartOptionsKeySecret() {
479
+ const globalState = globalThis;
480
+ globalState[START_OPTIONS_KEY_SECRET_SYMBOL] ??= randomBytes(32);
481
+ return globalState[START_OPTIONS_KEY_SECRET_SYMBOL];
482
+ }
483
+ function splitShellWords(value) {
484
+ const words = [];
485
+ let current = "";
486
+ let quote = null;
487
+ for (const char of value) {
488
+ if (quote) {
489
+ if (char === quote) quote = null;
490
+ else current += char;
491
+ continue;
492
+ }
493
+ if (char === "\"" || char === "'") {
494
+ quote = char;
495
+ continue;
496
+ }
497
+ if (/\s/.test(char)) {
498
+ if (current) {
499
+ words.push(current);
500
+ current = "";
501
+ }
502
+ continue;
503
+ }
504
+ current += char;
505
+ }
506
+ if (current) words.push(current);
507
+ return words;
508
+ }
509
+ //#endregion
510
+ export { isCodexFastServiceTier as a, resolveCodexAppServerRuntimeOptions as c, withMcpElicitationsApprovalPolicy as d, isCodexAppServerApprovalPolicyAllowedByRequirements as i, resolveCodexComputerUseConfig as l, codexAppServerStartOptionsKey as n, normalizeCodexServiceTier as o, codexSandboxPolicyForTurn as r, readCodexPluginConfig as s, CODEX_PLUGINS_MARKETPLACE_NAME as t, resolveCodexPluginsPolicy as u };
@@ -0,0 +1,53 @@
1
+ //#region extensions/codex/doctor-contract-api.ts
2
+ function asRecord(value) {
3
+ return value && typeof value === "object" && !Array.isArray(value) ? value : null;
4
+ }
5
+ function hasRetiredDynamicToolsProfile(value) {
6
+ return Object.prototype.hasOwnProperty.call(asRecord(value) ?? {}, "codexDynamicToolsProfile");
7
+ }
8
+ const legacyConfigRules = [{
9
+ path: [
10
+ "plugins",
11
+ "entries",
12
+ "codex",
13
+ "config"
14
+ ],
15
+ message: "plugins.entries.codex.config.codexDynamicToolsProfile is retired; Codex app-server always keeps Codex-native workspace tools native. Run \"autobot doctor --fix\".",
16
+ match: hasRetiredDynamicToolsProfile
17
+ }];
18
+ function normalizeCompatibilityConfig({ cfg }) {
19
+ const rawPluginConfig = asRecord(asRecord(cfg.plugins?.entries?.codex)?.config);
20
+ if (!rawPluginConfig || !hasRetiredDynamicToolsProfile(rawPluginConfig)) return {
21
+ config: cfg,
22
+ changes: []
23
+ };
24
+ const nextConfig = structuredClone(cfg);
25
+ const nextPluginConfig = asRecord(asRecord(asRecord(asRecord(nextConfig.plugins)?.entries)?.codex)?.config);
26
+ if (!nextPluginConfig) return {
27
+ config: cfg,
28
+ changes: []
29
+ };
30
+ delete nextPluginConfig.codexDynamicToolsProfile;
31
+ return {
32
+ config: nextConfig,
33
+ changes: ["Removed retired plugins.entries.codex.config.codexDynamicToolsProfile; Codex app-server always keeps Codex-native workspace tools native."]
34
+ };
35
+ }
36
+ const sessionRouteStateOwners = [{
37
+ id: "codex",
38
+ label: "Codex",
39
+ providerIds: [
40
+ "codex",
41
+ "codex-cli",
42
+ "openai-codex"
43
+ ],
44
+ runtimeIds: ["codex", "codex-cli"],
45
+ cliSessionKeys: ["codex-cli"],
46
+ authProfilePrefixes: [
47
+ "codex:",
48
+ "codex-cli:",
49
+ "openai-codex:"
50
+ ]
51
+ }];
52
+ //#endregion
53
+ export { legacyConfigRules, normalizeCompatibilityConfig, sessionRouteStateOwners };
@@ -0,0 +1,51 @@
1
+ //#region extensions/codex/harness.ts
2
+ const DEFAULT_CODEX_HARNESS_PROVIDER_IDS = new Set(["codex"]);
3
+ function createCodexAppServerAgentHarness(options) {
4
+ const providerIds = new Set([...options?.providerIds ?? DEFAULT_CODEX_HARNESS_PROVIDER_IDS].map((id) => id.trim().toLowerCase()));
5
+ return {
6
+ id: options?.id ?? "codex",
7
+ label: options?.label ?? "Codex agent harness",
8
+ deliveryDefaults: { sourceVisibleReplies: "message_tool" },
9
+ supports: (ctx) => {
10
+ const provider = ctx.provider.trim().toLowerCase();
11
+ if (providerIds.has(provider)) return {
12
+ supported: true,
13
+ priority: 100
14
+ };
15
+ return {
16
+ supported: false,
17
+ reason: `provider is not one of: ${[...providerIds].toSorted().join(", ")}`
18
+ };
19
+ },
20
+ runAttempt: async (params) => {
21
+ const { runCodexAppServerAttempt } = await import("./run-attempt-BoEwzQCv.js");
22
+ return runCodexAppServerAttempt(params, {
23
+ pluginConfig: options?.resolvePluginConfig?.() ?? options?.pluginConfig,
24
+ nativeHookRelay: { enabled: true }
25
+ });
26
+ },
27
+ runSideQuestion: async (params) => {
28
+ const { runCodexAppServerSideQuestion } = await import("./side-question-BDLuEzFP.js");
29
+ return runCodexAppServerSideQuestion(params, {
30
+ pluginConfig: options?.resolvePluginConfig?.() ?? options?.pluginConfig,
31
+ nativeHookRelay: { enabled: true }
32
+ });
33
+ },
34
+ compact: async (params) => {
35
+ const { maybeCompactCodexAppServerSession } = await import("./compact-CDboBy7o.js");
36
+ return maybeCompactCodexAppServerSession(params, { pluginConfig: options?.resolvePluginConfig?.() ?? options?.pluginConfig });
37
+ },
38
+ reset: async (params) => {
39
+ if (params.sessionFile) {
40
+ const { clearCodexAppServerBinding } = await import("./session-binding-e2GFp9VH.js").then((n) => n.a);
41
+ await clearCodexAppServerBinding(params.sessionFile);
42
+ }
43
+ },
44
+ dispose: async () => {
45
+ const { clearSharedCodexAppServerClientAndWait } = await import("./shared-client-D7Vy0glq.js").then((n) => n.a);
46
+ await clearSharedCodexAppServerClientAndWait();
47
+ }
48
+ };
49
+ }
50
+ //#endregion
51
+ export { createCodexAppServerAgentHarness };