@kodelyth/codex 2026.5.40 → 2026.6.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 (41) hide show
  1. package/dist/client-ChMX13_o.js +642 -0
  2. package/dist/client-factory-D3dIsp4Y.js +9 -0
  3. package/dist/command-formatters-BRW7_Nu7.js +519 -0
  4. package/dist/command-handlers-P2IqtXaZ.js +1462 -0
  5. package/dist/compact-baos5flR.js +329 -0
  6. package/dist/computer-use-VfLvTMaa.js +367 -0
  7. package/dist/config-CezENx_E.js +510 -0
  8. package/dist/doctor-contract-api.js +53 -0
  9. package/dist/harness.js +51 -0
  10. package/dist/index.js +1133 -0
  11. package/dist/media-understanding-provider.js +335 -0
  12. package/dist/models-B9DhrIwD.js +110 -0
  13. package/dist/node-cli-sessions-De4_DuFw.js +1216 -0
  14. package/dist/plugin-activation-BlMuJeXz.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-CHuacE27.js +24 -0
  22. package/dist/request-CTQKUxaa.js +89 -0
  23. package/dist/rolldown-runtime-DUslC3ob.js +14 -0
  24. package/dist/run-attempt-DqV2OU1R.js +5366 -0
  25. package/dist/session-binding-3PzU7ZTW.js +222 -0
  26. package/dist/shared-client-Cnyr9dyT.js +631 -0
  27. package/dist/side-question-CP5XlA0U.js +667 -0
  28. package/dist/test-api.js +45 -0
  29. package/dist/thread-lifecycle-DBJetBuV.js +1561 -0
  30. package/dist/vision-tools-Cl_5a93K.js +1379 -0
  31. package/klaw.plugin.json +24 -85
  32. package/package.json +18 -3
  33. package/doctor-contract-api.js +0 -7
  34. package/harness.js +0 -7
  35. package/index.js +0 -7
  36. package/media-understanding-provider.js +0 -7
  37. package/prompt-overlay.js +0 -7
  38. package/provider-catalog.js +0 -7
  39. package/provider-discovery.js +0 -7
  40. package/provider.js +0 -7
  41. package/test-api.js +0 -7
@@ -0,0 +1,84 @@
1
+ //#region extensions/codex/provider-catalog.ts
2
+ const CODEX_PROVIDER_ID = "codex";
3
+ const CODEX_BASE_URL = "https://chatgpt.com/backend-api";
4
+ const CODEX_APP_SERVER_AUTH_MARKER = "codex-app-server";
5
+ const DEFAULT_CONTEXT_WINDOW = 272e3;
6
+ const DEFAULT_MAX_TOKENS = 128e3;
7
+ const FALLBACK_CODEX_MODELS = [
8
+ {
9
+ id: "gpt-5.5",
10
+ model: "gpt-5.5",
11
+ displayName: "gpt-5.5",
12
+ description: "Latest frontier agentic coding model.",
13
+ isDefault: true,
14
+ inputModalities: ["text", "image"],
15
+ supportedReasoningEfforts: [
16
+ "low",
17
+ "medium",
18
+ "high",
19
+ "xhigh"
20
+ ]
21
+ },
22
+ {
23
+ id: "gpt-5.4-mini",
24
+ model: "gpt-5.4-mini",
25
+ displayName: "GPT-5.4-Mini",
26
+ description: "Smaller frontier agentic coding model.",
27
+ inputModalities: ["text", "image"],
28
+ supportedReasoningEfforts: [
29
+ "low",
30
+ "medium",
31
+ "high",
32
+ "xhigh"
33
+ ]
34
+ },
35
+ {
36
+ id: "gpt-5.2",
37
+ model: "gpt-5.2",
38
+ displayName: "gpt-5.2",
39
+ inputModalities: ["text", "image"],
40
+ supportedReasoningEfforts: [
41
+ "low",
42
+ "medium",
43
+ "high",
44
+ "xhigh"
45
+ ]
46
+ }
47
+ ];
48
+ function buildCodexModelDefinition(model) {
49
+ const id = model.id.trim() || model.model.trim();
50
+ return {
51
+ id,
52
+ name: model.displayName?.trim() || id,
53
+ api: "openai-codex-responses",
54
+ reasoning: model.supportedReasoningEfforts.length > 0 || shouldDefaultToReasoningModel(id),
55
+ input: model.inputModalities.includes("image") ? ["text", "image"] : ["text"],
56
+ cost: {
57
+ input: 0,
58
+ output: 0,
59
+ cacheRead: 0,
60
+ cacheWrite: 0
61
+ },
62
+ contextWindow: DEFAULT_CONTEXT_WINDOW,
63
+ maxTokens: DEFAULT_MAX_TOKENS,
64
+ compat: {
65
+ supportsReasoningEffort: model.supportedReasoningEfforts.length > 0,
66
+ supportsUsageInStreaming: true
67
+ }
68
+ };
69
+ }
70
+ function buildCodexProviderConfig(models) {
71
+ return {
72
+ baseUrl: CODEX_BASE_URL,
73
+ apiKey: CODEX_APP_SERVER_AUTH_MARKER,
74
+ auth: "token",
75
+ api: "openai-codex-responses",
76
+ models: models.map(buildCodexModelDefinition)
77
+ };
78
+ }
79
+ function shouldDefaultToReasoningModel(modelId) {
80
+ const lower = modelId.toLowerCase();
81
+ return lower.startsWith("gpt-5") || lower.startsWith("o1") || lower.startsWith("o3") || lower.startsWith("o4");
82
+ }
83
+ //#endregion
84
+ export { CODEX_APP_SERVER_AUTH_MARKER, CODEX_BASE_URL, CODEX_PROVIDER_ID, FALLBACK_CODEX_MODELS, buildCodexModelDefinition, buildCodexProviderConfig };
@@ -0,0 +1,33 @@
1
+ import { CODEX_APP_SERVER_AUTH_MARKER, CODEX_PROVIDER_ID, FALLBACK_CODEX_MODELS, buildCodexProviderConfig } from "./provider-catalog.js";
2
+ //#region extensions/codex/provider-discovery.ts
3
+ function resolveCodexPluginConfig(ctx) {
4
+ return (ctx.config.plugins?.entries)?.codex?.config;
5
+ }
6
+ async function runCodexCatalog(ctx) {
7
+ const { buildCodexProviderCatalog } = await import("./provider.js");
8
+ return await buildCodexProviderCatalog({
9
+ env: ctx.env,
10
+ pluginConfig: resolveCodexPluginConfig(ctx)
11
+ });
12
+ }
13
+ const codexProviderDiscovery = {
14
+ id: CODEX_PROVIDER_ID,
15
+ label: "Codex",
16
+ docsPath: "/providers/models",
17
+ auth: [],
18
+ catalog: {
19
+ order: "late",
20
+ run: runCodexCatalog
21
+ },
22
+ staticCatalog: {
23
+ order: "late",
24
+ run: async () => ({ provider: buildCodexProviderConfig(FALLBACK_CODEX_MODELS) })
25
+ },
26
+ resolveSyntheticAuth: () => ({
27
+ apiKey: CODEX_APP_SERVER_AUTH_MARKER,
28
+ source: "codex-app-server",
29
+ mode: "token"
30
+ })
31
+ };
32
+ //#endregion
33
+ export { codexProviderDiscovery, codexProviderDiscovery as default };
@@ -0,0 +1,150 @@
1
+ import { CODEX_APP_SERVER_AUTH_MARKER, CODEX_BASE_URL, CODEX_PROVIDER_ID, FALLBACK_CODEX_MODELS, buildCodexModelDefinition, buildCodexProviderConfig } from "./provider-catalog.js";
2
+ import { c as resolveCodexAppServerRuntimeOptions, s as readCodexPluginConfig } from "./config-CezENx_E.js";
3
+ import { resolveCodexSystemPromptContribution } from "./prompt-overlay.js";
4
+ import { resolvePluginConfigObject } from "klaw/plugin-sdk/plugin-config-runtime";
5
+ import { createSubsystemLogger } from "klaw/plugin-sdk/core";
6
+ import { normalizeModelCompat } from "klaw/plugin-sdk/provider-model-shared";
7
+ //#region extensions/codex/provider.ts
8
+ const DEFAULT_DISCOVERY_TIMEOUT_MS = 2500;
9
+ const LIVE_DISCOVERY_ENV = "KLAW_CODEX_DISCOVERY_LIVE";
10
+ const MODEL_DISCOVERY_PAGE_LIMIT = 100;
11
+ const CODEX_APP_SERVER_SETUP_METHOD_ID = "app-server";
12
+ const CODEX_DEFAULT_MODEL_REF = `${CODEX_PROVIDER_ID}/${FALLBACK_CODEX_MODELS[0].id}`;
13
+ const codexCatalogLog = createSubsystemLogger("codex/catalog");
14
+ function buildCodexProvider(options = {}) {
15
+ return {
16
+ id: CODEX_PROVIDER_ID,
17
+ label: "Codex",
18
+ docsPath: "/providers/models",
19
+ auth: [{
20
+ id: CODEX_APP_SERVER_SETUP_METHOD_ID,
21
+ label: "Codex app-server",
22
+ hint: "Use the Codex app-server runtime and managed model catalog.",
23
+ kind: "custom",
24
+ wizard: {
25
+ choiceId: CODEX_PROVIDER_ID,
26
+ choiceLabel: "Codex app-server",
27
+ choiceHint: "Use the Codex app-server runtime and managed model catalog.",
28
+ assistantPriority: -40,
29
+ groupId: CODEX_PROVIDER_ID,
30
+ groupLabel: "Codex",
31
+ groupHint: "Codex app-server model provider",
32
+ onboardingScopes: ["text-inference"]
33
+ },
34
+ run: async () => ({
35
+ profiles: [],
36
+ defaultModel: CODEX_DEFAULT_MODEL_REF
37
+ })
38
+ }],
39
+ catalog: {
40
+ order: "late",
41
+ run: async (ctx) => {
42
+ const pluginConfig = resolvePluginConfigObject(ctx.config, "codex") ?? (ctx.config ? void 0 : options.pluginConfig);
43
+ return await buildCodexProviderCatalog({
44
+ env: ctx.env,
45
+ pluginConfig,
46
+ listModels: options.listModels
47
+ });
48
+ }
49
+ },
50
+ staticCatalog: {
51
+ order: "late",
52
+ run: async () => ({ provider: buildCodexProviderConfig(FALLBACK_CODEX_MODELS) })
53
+ },
54
+ resolveDynamicModel: (ctx) => resolveCodexDynamicModel(ctx.modelId),
55
+ resolveSyntheticAuth: () => ({
56
+ apiKey: CODEX_APP_SERVER_AUTH_MARKER,
57
+ source: "codex-app-server",
58
+ mode: "token"
59
+ }),
60
+ resolveThinkingProfile: ({ modelId }) => ({ levels: [
61
+ { id: "off" },
62
+ { id: "minimal" },
63
+ { id: "low" },
64
+ { id: "medium" },
65
+ { id: "high" },
66
+ ...isKnownXHighCodexModel(modelId) ? [{ id: "xhigh" }] : []
67
+ ] }),
68
+ resolveSystemPromptContribution: ({ config, modelId }) => resolveCodexSystemPromptContribution({
69
+ config,
70
+ modelId
71
+ }),
72
+ isModernModelRef: ({ modelId }) => isModernCodexModel(modelId)
73
+ };
74
+ }
75
+ async function buildCodexProviderCatalog(options = {}) {
76
+ const config = readCodexPluginConfig(options.pluginConfig);
77
+ const appServer = resolveCodexAppServerRuntimeOptions({ pluginConfig: options.pluginConfig });
78
+ const timeoutMs = normalizeTimeoutMs(config.discovery?.timeoutMs);
79
+ let discovered = [];
80
+ if (config.discovery?.enabled !== false && !shouldSkipLiveDiscovery(options.env)) discovered = await listModelsBestEffort({
81
+ listModels: options.listModels ?? listCodexAppServerModelsLazy,
82
+ timeoutMs,
83
+ startOptions: appServer.start,
84
+ onDiscoveryFailure: options.onDiscoveryFailure
85
+ });
86
+ return { provider: buildCodexProviderConfig(discovered.length > 0 ? discovered : FALLBACK_CODEX_MODELS) };
87
+ }
88
+ function resolveCodexDynamicModel(modelId) {
89
+ const id = modelId.trim();
90
+ if (!id) return;
91
+ const fallbackModel = FALLBACK_CODEX_MODELS.find((model) => model.id === id);
92
+ return normalizeModelCompat({
93
+ ...buildCodexModelDefinition({
94
+ id,
95
+ model: id,
96
+ inputModalities: fallbackModel?.inputModalities ?? ["text"],
97
+ supportedReasoningEfforts: fallbackModel?.supportedReasoningEfforts ?? (shouldDefaultToReasoningModel(id) ? ["medium"] : [])
98
+ }),
99
+ provider: CODEX_PROVIDER_ID,
100
+ baseUrl: CODEX_BASE_URL
101
+ });
102
+ }
103
+ async function listModelsBestEffort(params) {
104
+ try {
105
+ const models = [];
106
+ let cursor;
107
+ do {
108
+ const result = await params.listModels({
109
+ timeoutMs: params.timeoutMs,
110
+ limit: MODEL_DISCOVERY_PAGE_LIMIT,
111
+ cursor,
112
+ startOptions: params.startOptions,
113
+ sharedClient: false
114
+ });
115
+ models.push(...result.models.filter((model) => !model.hidden));
116
+ cursor = result.nextCursor;
117
+ } while (cursor);
118
+ return models;
119
+ } catch (error) {
120
+ params.onDiscoveryFailure?.(error);
121
+ codexCatalogLog.debug("codex model discovery failed; using fallback catalog", { error: error instanceof Error ? error.message : String(error) });
122
+ return [];
123
+ }
124
+ }
125
+ async function listCodexAppServerModelsLazy(options) {
126
+ const { listCodexAppServerModels } = await import("./models-B9DhrIwD.js").then((n) => n.r);
127
+ return listCodexAppServerModels(options);
128
+ }
129
+ function normalizeTimeoutMs(value) {
130
+ return typeof value === "number" && Number.isFinite(value) && value > 0 ? value : DEFAULT_DISCOVERY_TIMEOUT_MS;
131
+ }
132
+ function shouldSkipLiveDiscovery(env = process.env) {
133
+ const override = env[LIVE_DISCOVERY_ENV]?.trim().toLowerCase();
134
+ if (override === "0" || override === "false") return true;
135
+ return Boolean(env.VITEST) && override !== "1";
136
+ }
137
+ function shouldDefaultToReasoningModel(modelId) {
138
+ const lower = modelId.toLowerCase();
139
+ return lower.startsWith("gpt-5") || lower.startsWith("o1") || lower.startsWith("o3") || lower.startsWith("o4");
140
+ }
141
+ function isKnownXHighCodexModel(modelId) {
142
+ const lower = modelId.trim().toLowerCase();
143
+ return lower.startsWith("gpt-5") || lower.startsWith("o3") || lower.startsWith("o4") || lower.includes("codex");
144
+ }
145
+ function isModernCodexModel(modelId) {
146
+ const lower = modelId.trim().toLowerCase();
147
+ return lower === "gpt-5.5" || lower === "gpt-5.4" || lower === "gpt-5.4-mini" || lower === "gpt-5.2";
148
+ }
149
+ //#endregion
150
+ export { buildCodexProvider, buildCodexProviderCatalog, isModernCodexModel };
@@ -0,0 +1,24 @@
1
+ //#region extensions/codex/src/app-server/rate-limit-cache.ts
2
+ const DEFAULT_CODEX_RATE_LIMIT_CACHE_MAX_AGE_MS = 10 * 6e4;
3
+ const CODEX_RATE_LIMIT_CACHE_STATE = Symbol.for("klaw.codexRateLimitCacheState");
4
+ function getCodexRateLimitCacheState() {
5
+ const globalState = globalThis;
6
+ globalState[CODEX_RATE_LIMIT_CACHE_STATE] ??= {};
7
+ return globalState[CODEX_RATE_LIMIT_CACHE_STATE];
8
+ }
9
+ function rememberCodexRateLimits(value, nowMs = Date.now()) {
10
+ if (value === void 0) return;
11
+ const state = getCodexRateLimitCacheState();
12
+ state.value = value;
13
+ state.updatedAtMs = nowMs;
14
+ }
15
+ function readRecentCodexRateLimits(options) {
16
+ const state = getCodexRateLimitCacheState();
17
+ if (state.value === void 0 || state.updatedAtMs === void 0) return;
18
+ const nowMs = options?.nowMs ?? Date.now();
19
+ const maxAgeMs = options?.maxAgeMs ?? DEFAULT_CODEX_RATE_LIMIT_CACHE_MAX_AGE_MS;
20
+ if (maxAgeMs >= 0 && nowMs - state.updatedAtMs > maxAgeMs) return;
21
+ return state.value;
22
+ }
23
+ //#endregion
24
+ export { rememberCodexRateLimits as n, readRecentCodexRateLimits as t };
@@ -0,0 +1,89 @@
1
+ import { n as CodexAppServerRpcError } from "./client-ChMX13_o.js";
2
+ import { f as resolveCodexAppServerHomeDir, i as getSharedCodexAppServerClient, o as withTimeout, r as createIsolatedCodexAppServerClient } from "./shared-client-Cnyr9dyT.js";
3
+ import { i as buildCodexAppInventoryCacheKey } from "./plugin-activation-BlMuJeXz.js";
4
+ import { createHash } from "node:crypto";
5
+ //#region extensions/codex/src/app-server/capabilities.ts
6
+ const CODEX_CONTROL_METHODS = {
7
+ account: "account/read",
8
+ compact: "thread/compact/start",
9
+ feedback: "feedback/upload",
10
+ listMcpServers: "mcpServerStatus/list",
11
+ listSkills: "skills/list",
12
+ listThreads: "thread/list",
13
+ rateLimits: "account/rateLimits/read",
14
+ resumeThread: "thread/resume",
15
+ review: "review/start"
16
+ };
17
+ function describeControlFailure(error) {
18
+ if (isUnsupportedControlError(error)) return "unsupported by this Codex app-server";
19
+ return error instanceof Error ? error.message : String(error);
20
+ }
21
+ function isUnsupportedControlError(error) {
22
+ return error instanceof CodexAppServerRpcError && error.code === -32601;
23
+ }
24
+ //#endregion
25
+ //#region extensions/codex/src/app-server/plugin-app-cache-key.ts
26
+ function buildCodexPluginAppCacheKey(params) {
27
+ return buildCodexAppInventoryCacheKey({
28
+ codexHome: resolveCodexPluginAppCacheCodexHome(params.appServer, params.agentDir),
29
+ endpoint: resolveCodexPluginAppCacheEndpoint(params.appServer),
30
+ authProfileId: params.authProfileId,
31
+ accountId: params.accountId,
32
+ envApiKeyFingerprint: params.envApiKeyFingerprint,
33
+ appServerVersion: params.appServerVersion
34
+ });
35
+ }
36
+ function resolveCodexPluginAppCacheEndpoint(appServer) {
37
+ return JSON.stringify({
38
+ transport: appServer.start.transport,
39
+ command: appServer.start.command,
40
+ args: appServer.start.args,
41
+ url: appServer.start.url ?? null,
42
+ credentialFingerprint: fingerprintCodexPluginAppCacheCredentials(appServer.start)
43
+ });
44
+ }
45
+ function resolveCodexPluginAppCacheCodexHome(appServer, agentDir) {
46
+ const configuredCodexHome = appServer.start.env?.CODEX_HOME?.trim();
47
+ if (configuredCodexHome) return configuredCodexHome;
48
+ return appServer.start.transport === "stdio" && agentDir ? resolveCodexAppServerHomeDir(agentDir) : void 0;
49
+ }
50
+ function fingerprintCodexPluginAppCacheCredentials(startOptions) {
51
+ const authToken = startOptions.authToken ?? "";
52
+ const headers = Object.entries(startOptions.headers).map(([key, value]) => [key.toLowerCase(), value]).toSorted(([left], [right]) => left.localeCompare(right));
53
+ if (!authToken && headers.length === 0) return null;
54
+ const hash = createHash("sha256");
55
+ hash.update("klaw:codex:plugin-app-cache-credentials:v1");
56
+ hash.update("\0");
57
+ hash.update(authToken);
58
+ for (const [key, value] of headers) {
59
+ hash.update("\0");
60
+ hash.update(key);
61
+ hash.update("\0");
62
+ hash.update(value);
63
+ }
64
+ return `sha256:${hash.digest("hex")}`;
65
+ }
66
+ //#endregion
67
+ //#region extensions/codex/src/app-server/request.ts
68
+ async function requestCodexAppServerJson(params) {
69
+ const timeoutMs = params.timeoutMs ?? 6e4;
70
+ return await withTimeout((async () => {
71
+ const client = await (params.isolated ? createIsolatedCodexAppServerClient : getSharedCodexAppServerClient)({
72
+ startOptions: params.startOptions,
73
+ timeoutMs,
74
+ authProfileId: params.authProfileId,
75
+ agentDir: params.agentDir,
76
+ config: params.config
77
+ });
78
+ try {
79
+ return await client.request(params.method, params.requestParams, { timeoutMs });
80
+ } finally {
81
+ if (params.isolated) await client.closeAndWait({
82
+ exitTimeoutMs: 2e3,
83
+ forceKillDelayMs: 250
84
+ });
85
+ }
86
+ })(), timeoutMs, `codex app-server ${params.method} timed out`);
87
+ }
88
+ //#endregion
89
+ export { describeControlFailure as i, buildCodexPluginAppCacheKey as n, CODEX_CONTROL_METHODS as r, requestCodexAppServerJson as t };
@@ -0,0 +1,14 @@
1
+ import "node:module";
2
+ //#region \0rolldown/runtime.js
3
+ var __defProp = Object.defineProperty;
4
+ var __exportAll = (all, no_symbols) => {
5
+ let target = {};
6
+ for (var name in all) __defProp(target, name, {
7
+ get: all[name],
8
+ enumerable: true
9
+ });
10
+ if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
11
+ return target;
12
+ };
13
+ //#endregion
14
+ export { __exportAll as t };