Skip to content

Commit 0190f36

Browse files
committed
docs: improve core API doc coverage for review confidence
- add JSDoc to storage locking/fallback transaction helpers - add JSDoc to request transformer collaboration/config helpers - clarify legacy lightweight GPT-5 alias default reasoning behavior
1 parent 49cc579 commit 0190f36

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

lib/request/request-transformer.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,9 @@ export function applyFastSessionDefaults(
263263
};
264264
}
265265

266+
/**
267+
* Resolves reasoning settings by layering transformed config with body/provider overrides.
268+
*/
266269
function resolveReasoningConfig(
267270
modelName: string,
268271
modelConfig: ConfigOptions,
@@ -283,6 +286,9 @@ function resolveReasoningConfig(
283286
return getReasoningConfig(modelName, mergedConfig);
284287
}
285288

289+
/**
290+
* Picks effective text verbosity with body/provider values taking precedence.
291+
*/
286292
function resolveTextVerbosity(
287293
modelConfig: ConfigOptions,
288294
body: RequestBody,
@@ -296,6 +302,9 @@ function resolveTextVerbosity(
296302
);
297303
}
298304

305+
/**
306+
* Resolves include fields and always preserves encrypted reasoning continuity payloads.
307+
*/
299308
function resolveInclude(modelConfig: ConfigOptions, body: RequestBody): string[] {
300309
const providerOpenAI = body.providerOptions?.openai;
301310
const base =
@@ -310,6 +319,9 @@ function resolveInclude(modelConfig: ConfigOptions, body: RequestBody): string[]
310319
return include;
311320
}
312321

322+
/**
323+
* Parses a collaboration mode token from env/config text.
324+
*/
313325
function parseCollaborationMode(value: string | undefined): CollaborationMode | undefined {
314326
if (!value) return undefined;
315327
const normalized = value.trim().toLowerCase();
@@ -318,6 +330,9 @@ function parseCollaborationMode(value: string | undefined): CollaborationMode |
318330
return undefined;
319331
}
320332

333+
/**
334+
* Extracts plain text from mixed message-content payloads.
335+
*/
321336
function extractMessageText(content: unknown): string {
322337
if (typeof content === "string") return content;
323338
if (!Array.isArray(content)) return "";
@@ -332,6 +347,9 @@ function extractMessageText(content: unknown): string {
332347
.join("\n");
333348
}
334349

350+
/**
351+
* Detects active collaboration mode using explicit env overrides first, then prompt hints.
352+
*/
335353
function detectCollaborationMode(body: RequestBody): CollaborationMode {
336354
const envMode =
337355
parseCollaborationMode(process.env.CODEX_COLLABORATION_MODE) ??
@@ -362,6 +380,9 @@ function detectCollaborationMode(body: RequestBody): CollaborationMode {
362380
return "unknown";
363381
}
364382

383+
/**
384+
* Removes tools that are only valid in plan mode when the request is not in plan mode.
385+
*/
365386
function sanitizePlanOnlyTools(tools: unknown, mode: CollaborationMode): unknown {
366387
if (!Array.isArray(tools) || mode === "plan") return tools;
367388

@@ -385,6 +406,9 @@ function sanitizePlanOnlyTools(tools: unknown, mode: CollaborationMode): unknown
385406
return filtered;
386407
}
387408

409+
/**
410+
* Collects runtime tool names from either direct tool entries or function-wrapped definitions.
411+
*/
388412
function extractRuntimeToolNames(tools: unknown): string[] {
389413
if (!Array.isArray(tools)) return [];
390414

@@ -516,6 +540,10 @@ export function getReasoningConfig(
516540
// for better coding assistance unless user explicitly requests "none".
517541
// - Canonical GPT-5 Codex defaults to high in stable Codex.
518542
// - Legacy GPT-5.3/5.2 Codex aliases default to xhigh for backward compatibility.
543+
// - Legacy lightweight aliases (gpt-5-mini / gpt-5-nano) intentionally keep a
544+
// minimal default based on the original alias, even though normalization maps
545+
// them to gpt-5.4 which supports higher efforts. Explicit xhigh requests are
546+
// still honored below via supportsRequestedXhigh.
519547
const defaultEffort: ReasoningConfig["effort"] = isCodexMini
520548
? "medium"
521549
: isGpt5Codex
@@ -557,7 +585,7 @@ export function getReasoningConfig(
557585
}
558586

559587
// Normalize "minimal" to "low" for Codex families
560-
// Codex CLI presets are low/medium/high (or xhigh for Codex Max / GPT-5.3/5.2 Codex)
588+
// Codex CLI presets are low/medium/high (or xhigh for Codex Max / GPT-5.3/5.2 Codex)
561589
if (isCodex && effort === "minimal") {
562590
effort = "low";
563591
}

lib/storage.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ export function formatStorageErrorHint(error: unknown, path: string): string {
108108

109109
let storageMutex: Promise<void> = Promise.resolve();
110110

111+
/**
112+
* Serializes storage I/O to keep account file reads/writes lock-step and avoid
113+
* cross-request races during migration/seeding flows.
114+
*/
111115
function withStorageLock<T>(fn: () => Promise<T>): Promise<T> {
112116
const previousMutex = storageMutex;
113117
let releaseLock: () => void;
@@ -669,14 +673,24 @@ export async function loadAccounts(): Promise<AccountStorageV3 | null> {
669673
return withStorageLock(async () => loadAccountsInternal(saveAccountsUnlocked));
670674
}
671675

676+
/**
677+
* Resolves the global (non-project) account storage path.
678+
*/
672679
function getGlobalAccountsStoragePath(): string {
673680
return join(getConfigDir(), ACCOUNTS_FILE_NAME);
674681
}
675682

683+
/**
684+
* Returns true when project-scoped storage is active and a global fallback is meaningful.
685+
*/
676686
function shouldUseProjectGlobalFallback(): boolean {
677687
return Boolean(currentStoragePath && currentProjectRoot);
678688
}
679689

690+
/**
691+
* Loads account data from global storage as a fallback when project storage is missing.
692+
* Returns null for missing/unusable global storage and never throws to callers.
693+
*/
680694
async function loadGlobalAccountsFallback(): Promise<AccountStorageV3 | null> {
681695
if (!shouldUseProjectGlobalFallback() || !currentStoragePath) {
682696
return null;
@@ -721,6 +735,10 @@ async function loadGlobalAccountsFallback(): Promise<AccountStorageV3 | null> {
721735
}
722736
}
723737

738+
/**
739+
* Core account-loading routine shared by normal reads and transactional storage handlers.
740+
* Handles schema normalization, legacy migration, and optional fallback seeding.
741+
*/
724742
async function loadAccountsInternal(
725743
persistMigration: ((storage: AccountStorageV3) => Promise<void>) | null,
726744
): Promise<AccountStorageV3 | null> {
@@ -797,6 +815,10 @@ async function loadAccountsInternal(
797815
}
798816
}
799817

818+
/**
819+
* Writes account storage without acquiring the outer storage mutex.
820+
* Callers must already be inside withStorageLock when using this helper directly.
821+
*/
800822
async function saveAccountsUnlocked(storage: AccountStorageV3): Promise<void> {
801823
const path = getStoragePath();
802824
const uniqueSuffix = `${Date.now()}.${Math.random().toString(36).slice(2, 8)}`;
@@ -847,6 +869,10 @@ async function saveAccountsUnlocked(storage: AccountStorageV3): Promise<void> {
847869
}
848870
}
849871

872+
/**
873+
* Executes a read-modify-write transaction under the storage lock and exposes
874+
* an unlocked persist callback so nested save operations do not deadlock.
875+
*/
850876
export async function withAccountStorageTransaction<T>(
851877
handler: (
852878
current: AccountStorageV3 | null,

0 commit comments

Comments
 (0)