-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Get cloudflare skills from middlecache #28658
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0297510
Get cloudflare skills from middlecache
mvvmm d90dbb7
typo
mvvmm 5aa15d4
verbage
mvvmm 1170527
Update AGENTS.md
mvvmm 955c5cb
re-use downloadToDotTempIfNotPresent
mvvmm ab5c695
add cloudflare-skills manifest to .tmp directory as well
mvvmm 5f7795d
stream files from middlecache
mvvmm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| #!/usr/bin/env tsx | ||
|
|
||
| import { spawn } from "child_process"; | ||
| import fs from "fs"; | ||
|
|
||
| const SKILLS_URL = | ||
| "https://middlecache.ced.cloudflare.com/v1/cloudflare-skills/skills.tar.gz"; | ||
| const SKILLS_DIR = "./skills"; | ||
|
|
||
| // --soft: warn and continue on failure instead of exiting non-zero. | ||
| // Used by the predev hook so a network failure doesn't block local development. | ||
| // --force: re-fetch even if skills/ already exists. | ||
| const soft = process.argv.includes("--soft"); | ||
| const force = process.argv.includes("--force"); | ||
|
|
||
| const fail = (message: string): never => { | ||
| if (soft) { | ||
| const hasExisting = fs.existsSync(SKILLS_DIR); | ||
| console.warn( | ||
| hasExisting | ||
| ? `Warning: ${message} — continuing with existing Cloudflare Skills` | ||
| : `Warning: ${message} — skills/ does not exist, /.well-known/skills/ will not work`, | ||
| ); | ||
| process.exit(0); | ||
| } | ||
| console.error(`Error: ${message}`); | ||
| process.exit(1); | ||
| }; | ||
|
|
||
| if (fs.existsSync(SKILLS_DIR) && !force) { | ||
| console.log( | ||
| "/skills directory already exists, skipping fetch. (run `npx tsx bin/fetch-skills.ts --force` to re-fetch)", | ||
| ); | ||
| process.exit(0); | ||
| } | ||
|
|
||
| console.log("Fetching Cloudflare Skills from middlecache"); | ||
|
|
||
| let res!: Response; | ||
| try { | ||
| res = await fetch(SKILLS_URL); | ||
| } catch (err) { | ||
| fail(`fetch failed: ${err}`); | ||
| } | ||
|
|
||
| if (!res.ok) { | ||
| fail(`fetch failed: ${res.status} ${res.statusText}`); | ||
| } | ||
|
|
||
| // Remove existing skills/ directory so stale Cloudflare Skills don't accumulate | ||
| fs.rmSync(SKILLS_DIR, { recursive: true, force: true }); | ||
| fs.mkdirSync(SKILLS_DIR, { recursive: true }); | ||
|
|
||
| // Pipe the response body directly into tar, extracting the skills/ subdirectory. | ||
| // The archive contains skills/<skill-name>/... so we strip the leading "skills/" | ||
| // component and extract into SKILLS_DIR. | ||
| const tar = spawn("tar", ["--strip-components=1", "-xz", "-C", SKILLS_DIR], { | ||
| stdio: ["pipe", "inherit", "inherit"], | ||
| }); | ||
|
|
||
| const reader = res.body!.getReader(); | ||
|
|
||
| const pump = async (): Promise<void> => { | ||
| while (true) { | ||
| const { done, value } = await reader.read(); | ||
| if (done) break; | ||
| tar.stdin!.write(value); | ||
| } | ||
| tar.stdin!.end(); | ||
| }; | ||
|
|
||
| await pump(); | ||
|
|
||
| const exitCode = await new Promise<number | null>((resolve) => | ||
| tar.on("close", resolve), | ||
| ); | ||
|
|
||
| if (exitCode !== 0) { | ||
| fail(`tar exited with code ${exitCode}`); | ||
| } | ||
|
|
||
| const cloudflareSkills = fs | ||
| .readdirSync(SKILLS_DIR) | ||
| .filter((entry) => fs.statSync(`${SKILLS_DIR}/${entry}`).isDirectory()); | ||
|
|
||
| console.log( | ||
| `Fetched ${cloudflareSkills.length} Cloudflare Skills: ${cloudflareSkills.join(", ")}`, | ||
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.