Repository navigation
feat(menu): describe skills with title, description and tags #447
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 all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d8169a2
feat(menu): describe skills with title, description and tags; freeze …
edwinyjlim 495f1c5
ci(agents): let an urgent prompt fix through with the agents-freeze-o…
edwinyjlim 65d57c1
ci(agents): pass the base ref to the freeze check through env
edwinyjlim 619cf5f
ci(agents): drop the agent prompt freeze check
edwinyjlim 9e19fb1
Merge remote-tracking branch 'origin/main' into dag/c1-menu-metadata
edwinyjlim 689f06d
test(menu): regenerate the old-wizard snapshot on current main
edwinyjlim 3a45165
test(menu): cover planner prompts and a bundle's config tags
edwinyjlim 164c545
fix(menu): drop a bundle entry's borrowed title and tighten the checks
edwinyjlim File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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
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,130 @@ | ||
| #!/usr/bin/env node | ||
|
|
||
| /** | ||
| * Fail when a build's file contents or executable bits differ from a baseline build in anything but the skill-menu's title/description/tags. | ||
| * Permissions inside a zip are not compared. | ||
| * Both builds must read the same inputs: a doc edited on posthog.com, or a generated file under example-apps/, shows as a difference. | ||
| * Build this checkout first, with `git clean -Xn example-apps` listing nothing but `.env` files, then the baseline from a copy of its docs cache: | ||
| * `npm run build && git worktree add /tmp/cm-main main && cp -R .docs-cache /tmp/cm-main/ && (cd /tmp/cm-main && npm install && npm run build)`, | ||
| * then `npm run check:bundle-diff -- /tmp/cm-main/dist [dist]`. | ||
| */ | ||
|
|
||
| import crypto from 'crypto'; | ||
| import fs from 'fs'; | ||
| import path from 'path'; | ||
| import zlib from 'zlib'; | ||
|
|
||
| const MENU_METADATA = ['title', 'description', 'tags']; | ||
|
|
||
| const sha = buf => crypto.createHash('sha256').update(buf).digest('hex'); | ||
|
|
||
| /** Entry name -> content buffer for a zip, read from its central directory (zip mtimes are ignored). */ | ||
| function readZip(buf) { | ||
| let eocd = buf.length - 22; | ||
| while (eocd >= 0 && buf.readUInt32LE(eocd) !== 0x06054b50) eocd--; | ||
| if (eocd < 0) throw new Error('not a zip archive'); | ||
| const count = buf.readUInt16LE(eocd + 10); | ||
| let offset = buf.readUInt32LE(eocd + 16); | ||
| const entries = {}; | ||
| for (let i = 0; i < count; i++) { | ||
| const method = buf.readUInt16LE(offset + 10); | ||
| const compressedSize = buf.readUInt32LE(offset + 20); | ||
| const nameLength = buf.readUInt16LE(offset + 28); | ||
| const extraLength = buf.readUInt16LE(offset + 30); | ||
| const commentLength = buf.readUInt16LE(offset + 32); | ||
| const localOffset = buf.readUInt32LE(offset + 42); | ||
| const name = buf.toString('utf8', offset + 46, offset + 46 + nameLength); | ||
| offset += 46 + nameLength + extraLength + commentLength; | ||
| if (name.endsWith('/')) continue; | ||
| const dataStart = localOffset + 30 + buf.readUInt16LE(localOffset + 26) + buf.readUInt16LE(localOffset + 28); | ||
| const data = buf.subarray(dataStart, dataStart + compressedSize); | ||
| entries[name] = method === 8 ? zlib.inflateRawSync(data) : Buffer.from(data); | ||
| } | ||
| return entries; | ||
| } | ||
|
|
||
| function stripMenuMetadata(node) { | ||
| if (Array.isArray(node)) return node.map(stripMenuMetadata); | ||
| if (!node || typeof node !== 'object') return node; | ||
| return Object.fromEntries( | ||
| Object.entries(node).filter(([k]) => !MENU_METADATA.includes(k)).map(([k, v]) => [k, stripMenuMetadata(v)]), | ||
| ); | ||
| } | ||
|
|
||
| /** Comparable digest of one file: zips by their entries, manifests without the build timestamp, the menu without its metadata fields. */ | ||
| function digest(name, buf) { | ||
| const base = path.basename(name); | ||
| if (base.endsWith('.zip')) { | ||
| const entries = readZip(buf); | ||
| return Object.fromEntries(Object.keys(entries).sort().map(n => [n, digest(n, entries[n])])); | ||
| } | ||
| if (base === 'manifest.json') { | ||
| const { buildTimestamp: _ts, ...rest } = JSON.parse(buf.toString('utf8')); | ||
| return sha(JSON.stringify(rest)); | ||
| } | ||
| if (base === 'skill-menu.json') { | ||
| const menu = JSON.parse(buf.toString('utf8')); | ||
| menu.categories = stripMenuMetadata(menu.categories); | ||
| return sha(JSON.stringify(menu)); | ||
| } | ||
| return sha(buf); | ||
| } | ||
|
|
||
| function listFiles(root) { | ||
| return fs.readdirSync(root, { recursive: true }) | ||
| .filter(rel => fs.statSync(path.join(root, rel)).isFile()) | ||
| .map(rel => rel.split(path.sep).join('/')) | ||
| .sort(); | ||
| } | ||
|
|
||
| function diff(a, b, at, out) { | ||
| if (typeof a === 'string' || typeof b === 'string') { | ||
| if (a !== b) out.push(at); | ||
| return; | ||
| } | ||
| for (const key of new Set([...Object.keys(a), ...Object.keys(b)])) { | ||
| if (!(key in a)) out.push(`${at}!${key} (added)`); | ||
| else if (!(key in b)) out.push(`${at}!${key} (removed)`); | ||
| else diff(a[key], b[key], `${at}!${key}`, out); | ||
| } | ||
| } | ||
|
|
||
| const [baselineDir, candidateDir = 'dist'] = process.argv.slice(2); | ||
| if (!baselineDir) { | ||
| console.error('Usage: node scripts/check-bundle-diff.js <baseline-dist> [candidate-dist]'); | ||
| process.exit(2); | ||
| } | ||
|
|
||
| for (const dir of [baselineDir, candidateDir]) { | ||
| if (!fs.existsSync(dir)) { | ||
| console.error(`No build output at ${dir}`); | ||
| console.error('Usage: node scripts/check-bundle-diff.js <baseline-dist> [candidate-dist]'); | ||
| process.exit(2); | ||
| } | ||
| } | ||
|
|
||
| const isExecutable = file => (fs.statSync(file).mode & 0o111) !== 0; | ||
|
|
||
| const baseline = listFiles(baselineDir); | ||
| const candidate = listFiles(candidateDir); | ||
| const changes = []; | ||
| for (const rel of new Set([...baseline, ...candidate])) { | ||
| if (!baseline.includes(rel)) { changes.push(`${rel} (added)`); continue; } | ||
| if (!candidate.includes(rel)) { changes.push(`${rel} (removed)`); continue; } | ||
| if (isExecutable(path.join(baselineDir, rel)) !== isExecutable(path.join(candidateDir, rel))) { | ||
| changes.push(`${rel} (executable bit)`); | ||
| } | ||
| diff( | ||
| digest(rel, fs.readFileSync(path.join(baselineDir, rel))), | ||
| digest(rel, fs.readFileSync(path.join(candidateDir, rel))), | ||
| rel, | ||
| changes, | ||
| ); | ||
| } | ||
|
|
||
| if (changes.length > 0) { | ||
| console.error(`Build output differs from ${baselineDir} beyond the skill-menu metadata fields:`); | ||
| for (const change of changes) console.error(` - ${change}`); | ||
| process.exit(1); | ||
| } | ||
| console.log(`No differences beyond skill-menu ${MENU_METADATA.join('/')} (${candidate.length} files compared).`); | ||
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
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.