Skip to content

armgit / codex

Public Imported from GitHub
0

Lightweight coding agent that runs in your terminal

Rust

Consolidate cached and fetched Codex manual handling (#55342)

Konstantine Kahadze982695cdbcce
diff --git a/codex-rs/skills/src/assets/samples/openai-docs/scripts/fetch-codex-manual.mjs b/codex-rs/skills/src/assets/samples/openai-docs/scripts/fetch-codex-manual.mjs
index d02fd2822d..d2cf628fb0 100644
--- a/codex-rs/skills/src/assets/samples/openai-docs/scripts/fetch-codex-manual.mjs
+++ b/codex-rs/skills/src/assets/samples/openai-docs/scripts/fetch-codex-manual.mjs
@@ -426,52 +426,31 @@ const fetchCodexManual = async ({
const outlinePath = outlineFilePath(resolvedCacheDir);
const checkedAt = new Date().toISOString();
- const cachedManual = await readCachedManual(resolvedCacheDir, expectedSha256);
- if (cachedManual !== null) {
- const outline = buildOutline(cachedManual);
- const outlineText = outlineMarkdown(outline);
- await writeOutline(resolvedCacheDir, outlineText);
-
- return {
- outlineText,
- status: {
- manualUrl,
- headerSha256: expectedSha256,
- fetchedManualSha256: expectedSha256,
- manualHashMatches: true,
- cacheStatus: "hit",
- cacheDir: resolvedCacheDir,
- manualPath,
- outlinePath,
- checkedAt,
- lineCount: outline.lineCount,
- headingCount: outline.headingCount,
- },
- };
- }
+ let manualText = await readCachedManual(resolvedCacheDir, expectedSha256);
+ const cacheStatus = manualText === null ? "updated" : "hit";
+ if (manualText === null) {
+ const getResponse = await requestManual(manualUrl, {
+ cacheDir: resolvedCacheDir,
+ method: "GET",
+ timeoutMs,
+ });
+ const getHeaderSha256 = readHeaderSha(getResponse);
+ if (getHeaderSha256 !== expectedSha256) {
+ throw new ManualFetchError(
+ `${HASH_HEADER} changed between HEAD and GET for ${manualUrl}.`,
+ );
+ }
- const getResponse = await requestManual(manualUrl, {
- cacheDir: resolvedCacheDir,
- method: "GET",
- timeoutMs,
- });
- const getHeaderSha256 = readHeaderSha(getResponse);
- if (getHeaderSha256 !== expectedSha256) {
- throw new ManualFetchError(
- `${HASH_HEADER} changed between HEAD and GET for ${manualUrl}.`,
- );
- }
+ manualText = await getResponse.text();
+ if (sha256(manualText) !== expectedSha256) {
+ throw new ManualFetchError(
+ `${HASH_HEADER} did not match the fetched manual body for ${manualUrl}.`,
+ );
+ }
- const manualText = await getResponse.text();
- const actualSha256 = sha256(manualText);
- const manualHashMatches = actualSha256 === expectedSha256;
- if (!manualHashMatches) {
- throw new ManualFetchError(
- `${HASH_HEADER} did not match the fetched manual body for ${manualUrl}.`,
- );
+ await writeCachedManual(resolvedCacheDir, manualText);
}
- await writeCachedManual(resolvedCacheDir, manualText);
const outline = buildOutline(manualText);
const outlineText = outlineMarkdown(outline);
await writeOutline(resolvedCacheDir, outlineText);
@@ -481,9 +460,9 @@ const fetchCodexManual = async ({
status: {
manualUrl,
headerSha256: expectedSha256,
- fetchedManualSha256: actualSha256,
- manualHashMatches,
- cacheStatus: "updated",
+ fetchedManualSha256: expectedSha256,
+ manualHashMatches: true,
+ cacheStatus,
cacheDir: resolvedCacheDir,
manualPath,
outlinePath,