diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 0000000..e178ec6 --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,15 @@ +# Agent Guide + +Before answering any question that involves facts about ANYTHING, you MUST output at least one Read, WebFetch, or WebSearch tool call. +If your first output is text instead of a tool call, you have failed. + +## Commands + +ALWAYS use the `npm run *` command + +| Command | What it does | +| ------------------ | ------------------------------------- | +| `npm run dev` | Hot-reload dev server (nodemon + tsx) | +| `npm start` | Run compiled `dist/index.js` | +| `npm run lint` | ESLint on `src/` | +| `npm run prettier` | ALWAYS RUN AFTER EDITING FILES | diff --git a/package.json b/package.json index d31757c..9e703b9 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "scripts": { "dev": "npx nodemon src/app.js", "lint": "npx eslint src", - "lint:report": "npm run lint -- --output-file eslint_report.json --format json", + "prettier:": "npm run prettier:write", "prettier:check": "npx prettier --check .", "prettier:write": "npx prettier --write .", "start": "node src/app.js" diff --git a/src/api.js b/src/api.js index 55e8792..18af9f2 100644 --- a/src/api.js +++ b/src/api.js @@ -82,31 +82,35 @@ export class GHCRApi { const indexManifest = await this.getManifest(tag) debug('mediaType:', indexManifest.mediaType) - let totalSize = 0 - if ( !indexManifest.mediaType.includes('list') && !indexManifest.mediaType.includes('index') ) { // debug('indexManifest - !list + !index:', indexManifest) + // noinspection JSUnresolvedReference const size = indexManifest.layers.reduce((sum, layer) => sum + layer.size, 0) - totalSize = size + (indexManifest.config.size || 0) + const totalSize = size + (indexManifest.config.size || 0) // debug('totalSize:', totalSize) await cacheSet(key, totalSize) return totalSize } debug('indexManifest.manifests?.length:', indexManifest.manifests?.length) - for (const m of indexManifest.manifests) { - await new Promise((resolve) => setTimeout(resolve, 50)) - const manifest = await this.getManifest(m.digest) - const configSize = manifest.config?.size || 0 - // debug('configSize:', configSize) - // noinspection JSUnresolvedReference - const layerSize = manifest.layers?.reduce((a, l) => a + (l.size || 0), 0) || 0 - // debug('layerSize:', layerSize) - totalSize += configSize + layerSize - } + // only process linux/amd64 or first item... + // noinspection JSValidateTypes + const m = + indexManifest.manifests?.find( + (m) => m.platform?.os === 'linux' && m.platform?.architecture === 'amd64', + ) || indexManifest.manifests?.[0] + debug('indexManifest:', m) + await new Promise((resolve) => setTimeout(resolve, 50)) + const manifest = await this.getManifest(m.digest) + const configSize = manifest.config?.size || 0 + // debug('configSize:', configSize) + // noinspection JSUnresolvedReference + const layerSize = manifest.layers?.reduce((a, l) => a + (l.size || 0), 0) || 0 + // debug('layerSize:', layerSize) + const totalSize = configSize + layerSize // debug('totalSize:', totalSize) await cacheSet(key, totalSize, 60 * 60 * 4) return totalSize