Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

refactor(codex): 拆出 app-server 版本门控函数

RickyYiic5ba349727d0
diff --git a/packages/maker-core/src/agents/codex/index.ts b/packages/maker-core/src/agents/codex/index.ts
index f879abf74e..41da493503 100644
--- a/packages/maker-core/src/agents/codex/index.ts
+++ b/packages/maker-core/src/agents/codex/index.ts
@@ -160,6 +160,16 @@ import {
import { scanCodexCustomizations } from './customization-scanner.js';
import { commandExecutionDisplayInput } from './command-display.js';
import { asyncUserInputQuestions } from './async-user-input.js';
+import {
+ codexUserAgentAtLeast,
+ supportsCodexThreadRollback,
+ supportsCodexApprovalsReviewerProtocol,
+ supportsCodexReadonlyReferenceDirs,
+ supportsCodexCapabilityRoutingProtocol,
+ supportsCodexResumeExcludeTurns,
+ supportsCodexForkExcludeTurns,
+ supportsCodexNativeTurnFork,
+} from './version-gates.js';
import {
dedupeCells,
extractAliveYieldCellsFromCodexItem,
@@ -402,15 +412,6 @@ export function isCodexRollbackUnavailableError(error: unknown): boolean {
return isCodexPaginatedRollbackUnsupportedError(error) || isCodexRollbackMethodRemovedError(error);
}
-/**
- * thread/rollback 在 Codex 0.156.0 被移除(openai/codex#44915)。按 initialize userAgent
- * 门控:≥ 0.156.0 的 daemon 不再尝试该方法,直接走 fork;版本未知或更老的远端 daemon
- * 仍先试 rollback,由 isCodexRollbackUnavailableError 兜住实际拒绝。
- */
-function supportsCodexThreadRollback(userAgent: string | undefined): boolean {
- return !codexUserAgentAtLeast(userAgent, [0, 156, 0]);
-}
-
function normalizeNativeForkTurnId(value: string | undefined): string | undefined {
const normalized = value?.trim();
return normalized ? normalized : undefined;
@@ -630,74 +631,6 @@ function mapPermissionToCodex(
}
}
-function codexUserAgentAtLeast(
- userAgent: string | undefined,
- minimum: readonly [number, number, number],
-): boolean {
- const match = /\/(\d+)\.(\d+)\.(\d+)(?:[-+ )]|$)/.exec(userAgent ?? '');
- if (!match) return false;
- const version = [Number(match[1]), Number(match[2]), Number(match[3])] as const;
- for (let i = 0; i < minimum.length; i += 1) {
- if (version[i]! > minimum[i]!) return true;
- if (version[i]! < minimum[i]!) return false;
- }
- return true;
-}
-
-/**
- * `approvalsReviewer` is verified against the app-server bundled with Codex 0.144.6.
- * Remote hosts may keep an older standalone binary across desktop upgrades, so parse the
- * initialize userAgent and conservatively omit the field unless that verified floor is met.
- */
-function supportsCodexApprovalsReviewerProtocol(userAgent: string | undefined): boolean {
- return codexUserAgentAtLeast(userAgent, [0, 144, 6]);
-}
-
-/**
- * Runtime workspace roots and named permission profiles were verified against
- * the app-server bundled with Codex 0.144.6. Keep older remote daemons
- * fail-closed: without profiles, legacy workspace-write would make every
- * runtime root writable.
- */
-function supportsCodexReadonlyReferenceDirs(userAgent: string | undefined): boolean {
- return supportsCodexApprovalsReviewerProtocol(userAgent);
-}
-
-/**
- * Per-thread plugin config for capability arbitration was verified against
- * Codex 0.145.0. If the host policy needs those overrides, an older daemon must
- * be rejected rather than silently starting with the downstream plugins active.
- */
-function supportsCodexCapabilityRoutingProtocol(userAgent: string | undefined): boolean {
- return codexUserAgentAtLeast(userAgent, [0, 145, 0]);
-}
-
-/**
- * `excludeTurns` was introduced in Codex 0.125.0 and later marked experimental.
- * Older remote daemons can outlive desktop upgrades, so omit the unknown field
- * and preserve their legacy full-history resume behavior.
- */
-function supportsCodexResumeExcludeTurns(userAgent: string | undefined): boolean {
- return codexUserAgentAtLeast(userAgent, [0, 125, 0]);
-}
-
-/**
- * `thread/fork.excludeTurns` was verified against the app-server bundled with
- * Codex 0.145.0. Without it, the fork response inlines the entire source-thread
- * history in one NDJSON line — a 47MB rollout produced a 31MiB single line that
- * exceeded the client's 16MiB maxLineBytes guard and killed the whole
- * connection (2026-08-08 field incident). Older daemons keep the legacy
- * full-history fork response.
- */
-function supportsCodexForkExcludeTurns(userAgent: string | undefined): boolean {
- return codexUserAgentAtLeast(userAgent, [0, 145, 0]);
-}
-
-/** Direct lastTurnId fork is used only together with the bounded response contract. */
-function supportsCodexNativeTurnFork(userAgent: string | undefined): boolean {
- return supportsCodexForkExcludeTurns(userAgent);
-}
-
const READONLY_REFERENCES_PERMISSION_PROFILE = 'cindy-readonly-references';
const REVIEW_PERMISSION_PROFILE = 'cindy-review-readonly';
const REVIEW_CREDENTIAL_GLOB_DENIES: Record<string, 'deny'> = Object.fromEntries(
diff --git a/packages/maker-core/src/agents/codex/version-gates.ts b/packages/maker-core/src/agents/codex/version-gates.ts
new file mode 100644
index 0000000000..57a241d86f
--- /dev/null
+++ b/packages/maker-core/src/agents/codex/version-gates.ts
@@ -0,0 +1,76 @@
+export function codexUserAgentAtLeast(
+ userAgent: string | undefined,
+ minimum: readonly [number, number, number],
+): boolean {
+ const match = /\/(\d+)\.(\d+)\.(\d+)(?:[-+ )]|$)/.exec(userAgent ?? '');
+ if (!match) return false;
+ const version = [Number(match[1]), Number(match[2]), Number(match[3])] as const;
+ for (let i = 0; i < minimum.length; i += 1) {
+ if (version[i]! > minimum[i]!) return true;
+ if (version[i]! < minimum[i]!) return false;
+ }
+ return true;
+}
+
+/**
+ * thread/rollback 在 Codex 0.156.0 被移除(openai/codex#44915)。按 initialize userAgent
+ * 门控:≥ 0.156.0 的 daemon 不再尝试该方法,直接走 fork;版本未知或更老的远端 daemon
+ * 仍先试 rollback,由 isCodexRollbackUnavailableError 兜住实际拒绝。
+ */
+export function supportsCodexThreadRollback(userAgent: string | undefined): boolean {
+ return !codexUserAgentAtLeast(userAgent, [0, 156, 0]);
+}
+
+/**
+ * `approvalsReviewer` is verified against the app-server bundled with Codex 0.144.6.
+ * Remote hosts may keep an older standalone binary across desktop upgrades, so parse the
+ * initialize userAgent and conservatively omit the field unless that verified floor is met.
+ */
+export function supportsCodexApprovalsReviewerProtocol(userAgent: string | undefined): boolean {
+ return codexUserAgentAtLeast(userAgent, [0, 144, 6]);
+}
+
+/**
+ * Runtime workspace roots and named permission profiles were verified against
+ * the app-server bundled with Codex 0.144.6. Keep older remote daemons
+ * fail-closed: without profiles, legacy workspace-write would make every
+ * runtime root writable.
+ */
+export function supportsCodexReadonlyReferenceDirs(userAgent: string | undefined): boolean {
+ return supportsCodexApprovalsReviewerProtocol(userAgent);
+}
+
+/**
+ * Per-thread plugin config for capability arbitration was verified against
+ * Codex 0.145.0. If the host policy needs those overrides, an older daemon must
+ * be rejected rather than silently starting with the downstream plugins active.
+ */
+export function supportsCodexCapabilityRoutingProtocol(userAgent: string | undefined): boolean {
+ return codexUserAgentAtLeast(userAgent, [0, 145, 0]);
+}
+
+/**
+ * `excludeTurns` was introduced in Codex 0.125.0 and later marked experimental.
+ * Older remote daemons can outlive desktop upgrades, so omit the unknown field
+ * and preserve their legacy full-history resume behavior.
+ */
+export function supportsCodexResumeExcludeTurns(userAgent: string | undefined): boolean {
+ return codexUserAgentAtLeast(userAgent, [0, 125, 0]);
+}
+
+/**
+ * `thread/fork.excludeTurns` was verified against the app-server bundled with
+ * Codex 0.145.0. Without it, the fork response inlines the entire source-thread
+ * history in one NDJSON line — a 47MB rollout produced a 31MiB single line that
+ * exceeded the client's 16MiB maxLineBytes guard and killed the whole
+ * connection (2026-08-08 field incident). Older daemons keep the legacy
+ * full-history fork response.
+ */
+export function supportsCodexForkExcludeTurns(userAgent: string | undefined): boolean {
+ return codexUserAgentAtLeast(userAgent, [0, 145, 0]);
+}
+
+/** Direct lastTurnId fork is used only together with the bounded response contract. */
+export function supportsCodexNativeTurnFork(userAgent: string | undefined): boolean {
+ return supportsCodexForkExcludeTurns(userAgent);
+}