Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
| 1 | #!/usr/bin/env node |
| 2 | |
| 3 | import { execFileSync } from 'node:child_process'; |
| 4 | import fs from 'node:fs'; |
| 5 | import os from 'node:os'; |
| 6 | import path from 'node:path'; |
| 7 | import { fileURLToPath } from 'node:url'; |
| 8 | |
| 9 | const scriptDir = path.dirname(fileURLToPath(import.meta.url)); |
| 10 | const skillDir = path.resolve(scriptDir, '..'); |
| 11 | const versions = JSON.parse(fs.readFileSync(path.join(skillDir, 'versions.json'), 'utf8')); |
| 12 | const effectPackageNames = ['effect', '@effect/platform-bun', '@effect/vitest']; |
| 13 | const exactVersion = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/; |
| 14 | |
| 15 | for (const [packageName, version] of Object.entries(versions)) { |
| 16 | if (typeof version !== 'string' || !exactVersion.test(version)) { |
| 17 | throw new Error(`${packageName} must use an exact semantic version, received ${version}`); |
| 18 | } |
| 19 | } |
| 20 | |
| 21 | const effectVersion = versions.effect; |
| 22 | if ( |
| 23 | !/^4\.\d+\.\d+(?:-(?:beta|rc)\.\d+)?$/.test(effectVersion) || |
| 24 | effectPackageNames.some(packageName => versions[packageName] !== effectVersion) |
| 25 | ) { |
| 26 | throw new Error(`Effect packages must share one exact v4 version, received ${effectVersion}`); |
| 27 | } |
| 28 | |
| 29 | const dependencySpecs = [ |
| 30 | `effect@${versions.effect}`, |
| 31 | `@effect/platform-bun@${versions['@effect/platform-bun']}`, |
| 32 | `@effect/vitest@${versions['@effect/vitest']}`, |
| 33 | `@types/node@${versions['@types/node']}`, |
| 34 | `typescript@${versions.typescript}`, |
| 35 | `vitest@${versions.vitest}`, |
| 36 | ]; |
| 37 | const packageJson = JSON.stringify( |
| 38 | { |
| 39 | name: 'composio-effect-v4-skill-check', |
| 40 | private: true, |
| 41 | type: 'module', |
| 42 | }, |
| 43 | null, |
| 44 | 2 |
| 45 | ); |
| 46 | const pnpmWorkspace = 'allowBuilds:\n msgpackr-extract: false\n'; |
| 47 | const tsconfigBase = JSON.stringify( |
| 48 | { |
| 49 | compilerOptions: { |
| 50 | strict: true, |
| 51 | noEmit: true, |
| 52 | target: 'ES2022', |
| 53 | module: 'NodeNext', |
| 54 | moduleResolution: 'NodeNext', |
| 55 | lib: ['ES2023', 'DOM', 'DOM.Iterable'], |
| 56 | types: ['node'], |
| 57 | skipLibCheck: true, |
| 58 | exactOptionalPropertyTypes: true, |
| 59 | noUncheckedIndexedAccess: true, |
| 60 | allowImportingTsExtensions: true, |
| 61 | }, |
| 62 | }, |
| 63 | null, |
| 64 | 2 |
| 65 | ); |
| 66 | const bootstrapSpec = JSON.stringify({ |
| 67 | dependencySpecs, |
| 68 | packageJson, |
| 69 | pnpmWorkspace, |
| 70 | tsconfigBase, |
| 71 | }); |
| 72 | const cacheDigest = await globalThis.crypto.subtle.digest( |
| 73 | 'SHA-256', |
| 74 | new TextEncoder().encode(bootstrapSpec) |
| 75 | ); |
| 76 | const cachePart = Array.from(new Uint8Array(cacheDigest), byte => |
| 77 | byte.toString(16).padStart(2, '0') |
| 78 | ).join(''); |
| 79 | const scratch = path.join(os.tmpdir(), `composio-effect-v4-skill-${cachePart}`); |
| 80 | |
| 81 | const bootstrap = () => { |
| 82 | const marker = path.join(scratch, '.ready'); |
| 83 | if (fs.existsSync(marker)) return; |
| 84 | |
| 85 | fs.rmSync(scratch, { recursive: true, force: true }); |
| 86 | fs.mkdirSync(scratch, { recursive: true }); |
| 87 | fs.writeFileSync(path.join(scratch, 'package.json'), packageJson); |
| 88 | fs.writeFileSync(path.join(scratch, 'pnpm-workspace.yaml'), pnpmWorkspace); |
| 89 | execFileSync('pnpm', ['add', '--save-exact', ...dependencySpecs], { |
| 90 | cwd: scratch, |
| 91 | stdio: 'inherit', |
| 92 | }); |
| 93 | fs.writeFileSync(path.join(scratch, 'tsconfig.base.json'), tsconfigBase); |
| 94 | fs.writeFileSync(marker, `${bootstrapSpec}\n`); |
| 95 | }; |
| 96 | |
| 97 | const readBlocks = markdown => { |
| 98 | const lines = markdown.split('\n'); |
| 99 | const blocks = []; |
| 100 | let current; |
| 101 | |
| 102 | for (let index = 0; index < lines.length; index += 1) { |
| 103 | const line = lines[index]; |
| 104 | const fence = line.match(/^```(\S*)\s*(.*)$/); |
| 105 | if (fence && current === undefined) { |
| 106 | current = { lang: fence[1], info: fence[2] ?? '', startLine: index + 1, code: [] }; |
| 107 | } else if (line.startsWith('```') && current !== undefined) { |
| 108 | blocks.push({ ...current, code: current.code.join('\n') }); |
| 109 | current = undefined; |
| 110 | } else if (current !== undefined) { |
| 111 | current.code.push(line); |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | return blocks.filter( |
| 116 | block => |
| 117 | (block.lang === 'ts' || block.lang === 'typescript') && !block.info.includes('no-check') |
| 118 | ); |
| 119 | }; |
| 120 | |
| 121 | const checkFile = (markdownFile, blocks) => { |
| 122 | const slug = path.basename(markdownFile).replace(/[^A-Za-z0-9_-]/g, '_'); |
| 123 | const outDir = path.join(scratch, 'blocks', slug); |
| 124 | fs.rmSync(outDir, { recursive: true, force: true }); |
| 125 | fs.mkdirSync(outDir, { recursive: true }); |
| 126 | |
| 127 | const sourceMap = new Map(); |
| 128 | blocks.forEach((block, index) => { |
| 129 | const filename = `block-${String(index + 1).padStart(3, '0')}.ts`; |
| 130 | sourceMap.set(filename, block); |
| 131 | fs.writeFileSync(path.join(outDir, filename), block.code); |
| 132 | }); |
| 133 | fs.writeFileSync( |
| 134 | path.join(outDir, 'tsconfig.json'), |
| 135 | JSON.stringify({ extends: '../../tsconfig.base.json', include: ['*.ts'] }, null, 2) |
| 136 | ); |
| 137 | |
| 138 | try { |
| 139 | execFileSync( |
| 140 | path.join(scratch, 'node_modules', '.bin', 'tsc'), |
| 141 | ['-p', path.join(outDir, 'tsconfig.json'), '--pretty', 'false'], |
| 142 | { cwd: scratch, encoding: 'utf8' } |
| 143 | ); |
| 144 | console.log(`OK: ${blocks.length} TypeScript block(s) compile in ${markdownFile}`); |
| 145 | return true; |
| 146 | } catch (error) { |
| 147 | const output = `${error.stdout ?? ''}${error.stderr ?? ''}`; |
| 148 | console.error(`FAIL: ${markdownFile}`); |
| 149 | for (const line of output.split('\n').filter(value => value.includes('error TS'))) { |
| 150 | const match = line.match(/blocks\/[^/]+\/(block-\d+\.ts)[(:](\d+)/); |
| 151 | const block = match ? sourceMap.get(match[1]) : undefined; |
| 152 | const markdownLine = block && match ? block.startLine + Number(match[2]) : '?'; |
| 153 | console.error(` markdown line ~${markdownLine}: ${line.replace(/^.*error TS/, 'error TS')}`); |
| 154 | } |
| 155 | return false; |
| 156 | } |
| 157 | }; |
| 158 | |
| 159 | const args = process.argv.slice(2); |
| 160 | const testingReference = path.resolve( |
| 161 | skillDir, |
| 162 | '..', |
| 163 | 'typescript-testing', |
| 164 | 'references', |
| 165 | 'effect-v4-cli.md' |
| 166 | ); |
| 167 | const minimumBlockCounts = new Map([ |
| 168 | [path.join(skillDir, 'references', 'cli-surface.md'), 1], |
| 169 | [path.join(skillDir, 'references', 'core-patterns.md'), 1], |
| 170 | [testingReference, 1], |
| 171 | ]); |
| 172 | const defaultMarkdownFiles = [ |
| 173 | path.join(skillDir, 'SKILL.md'), |
| 174 | ...fs |
| 175 | .readdirSync(path.join(skillDir, 'references')) |
| 176 | .filter(filename => filename.endsWith('.md')) |
| 177 | .sort() |
| 178 | .map(filename => path.join(skillDir, 'references', filename)), |
| 179 | testingReference, |
| 180 | ]; |
| 181 | const defaultTargets = defaultMarkdownFiles.map(markdownFile => ({ |
| 182 | markdownFile, |
| 183 | minimumBlockCount: minimumBlockCounts.get(markdownFile) ?? 0, |
| 184 | })); |
| 185 | const targets = |
| 186 | args.length > 0 |
| 187 | ? args.map(value => ({ markdownFile: path.resolve(value), minimumBlockCount: 1 })) |
| 188 | : defaultTargets; |
| 189 | |
| 190 | const preparedTargets = targets.map(({ markdownFile, minimumBlockCount }) => ({ |
| 191 | markdownFile, |
| 192 | minimumBlockCount, |
| 193 | blocks: readBlocks(fs.readFileSync(markdownFile, 'utf8')), |
| 194 | })); |
| 195 | const missingBlocks = preparedTargets.filter( |
| 196 | target => target.blocks.length < target.minimumBlockCount |
| 197 | ); |
| 198 | for (const target of missingBlocks) { |
| 199 | console.error(`FAIL: ${target.markdownFile}`); |
| 200 | console.error( |
| 201 | ` expected at least ${target.minimumBlockCount} checked TypeScript block(s), found ${target.blocks.length}` |
| 202 | ); |
| 203 | } |
| 204 | for (const target of preparedTargets.filter( |
| 205 | value => value.minimumBlockCount === 0 && value.blocks.length === 0 |
| 206 | )) { |
| 207 | console.log(`OK: no checked TypeScript blocks in ${target.markdownFile}`); |
| 208 | } |
| 209 | |
| 210 | const checkedTargets = preparedTargets.filter(value => value.blocks.length > 0); |
| 211 | if (checkedTargets.length > 0) bootstrap(); |
| 212 | const checkedOk = checkedTargets |
| 213 | .map(target => checkFile(target.markdownFile, target.blocks)) |
| 214 | .every(Boolean); |
| 215 | const ok = missingBlocks.length === 0 && checkedOk; |
| 216 | process.exit(ok ? 0 : 1); |