Soul-driven AI agent with permission-hardened tools, token budgets, and multi-channel access. Runs 24/7 from CLI, Telegram or More.
ci: add GitHub Actions matrix CI and local pack-verify script
Salman Qureshibae83106941f
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlnew file mode 100644index 00000000..cd1ee4ce--- /dev/null+++ b/.github/workflows/ci.yml@@ -0,0 +1,141 @@+name: CI++on:+ push:+ branches: [main]+ tags: ['v*']+ pull_request:+ branches: [main]+ workflow_dispatch:++jobs:+ typecheck:+ name: Typecheck (Node ${{ matrix.node }}, ${{ matrix.os }})+ runs-on: ${{ matrix.os }}+ strategy:+ fail-fast: false+ matrix:+ os: [ubuntu-latest, windows-latest, macos-latest]+ node: [20, 22]+ steps:+ - uses: actions/checkout@v4+ - uses: actions/setup-node@v4+ with:+ node-version: ${{ matrix.node }}+ cache: npm+ - run: npm ci+ - run: npm run typecheck++ test:+ name: Test (Node ${{ matrix.node }}, ${{ matrix.os }})+ runs-on: ${{ matrix.os }}+ strategy:+ fail-fast: false+ matrix:+ os: [ubuntu-latest, windows-latest, macos-latest]+ node: [20, 22]+ steps:+ - uses: actions/checkout@v4+ - uses: actions/setup-node@v4+ with:+ node-version: ${{ matrix.node }}+ cache: npm+ - run: npm ci+ - run: npm run build+ - run: npm test++ pack-verify:+ name: Pack & Verify (Node ${{ matrix.node }}, ${{ matrix.os }})+ runs-on: ${{ matrix.os }}+ strategy:+ fail-fast: false+ matrix:+ os: [ubuntu-latest, windows-latest, macos-latest]+ node: [20, 22]+ steps:+ - uses: actions/checkout@v4+ - uses: actions/setup-node@v4+ with:+ node-version: ${{ matrix.node }}+ cache: npm+ - run: npm ci+ - run: npm run build++ - name: Pack tarball+ run: npm pack++ - name: Verify tarball contents+ shell: bash+ run: |+ TARBALL=$(ls *.tgz | head -1)+ echo "Tarball: $TARBALL"+ mkdir -p /tmp/verify-pkg+ tar -xzf "$TARBALL" -C /tmp/verify-pkg+ echo "--- Tarball contents ---"+ find /tmp/verify-pkg -type f | head -20++ - name: Install from tarball (production only)+ shell: bash+ run: |+ TARBALL=$(ls *.tgz | head -1)+ mkdir -p /tmp/verify-install+ cp "$TARBALL" /tmp/verify-install/+ cd /tmp/verify-install+ npm init -y+ npm install "$TARBALL" --omit=dev --no-save++ - name: Verify CLI entry point exists and runs+ shell: bash+ run: |+ cd /tmp/verify-install+ ENTRY=$(node -e "const p=require('./node_modules/@cosmicstack/mercury-agent/package.json'); console.log(p.main)")+ echo "Entry point: $ENTRY"+ test -f "node_modules/@cosmicstack/mercury-agent/$ENTRY" || { echo "FAIL: entry point missing"; exit 1; }+ head -1 "node_modules/@cosmicstack/mercury-agent/$ENTRY" | grep -q "node" || { echo "FAIL: shebang missing"; exit 1; }+ echo "OK: Entry point exists with shebang"++ - name: Verify package.json has no file references that won't exist+ shell: bash+ run: |+ cd /tmp/verify-install/node_modules/@cosmicstack/mercury-agent+ PKG=$(cat package.json)+ SCRIPTS=$(echo "$PKG" | node -e "const p=JSON.parse(require('fs').readFileSync('/dev/stdin','utf8')); const s=p.scripts||{}; Object.entries(s).forEach(([k,v])=>{if(v.includes('scripts/')||v.includes('bash '))console.log('WARN: script '+k+' references: '+v)})")+ if [ -n "$SCRIPTS" ]; then+ echo "$SCRIPTS"+ echo "FAIL: scripts reference files not included in package"+ exit 1+ fi+ echo "OK: No dangling script references"++ - name: Verify better-sqlite3 optional handling+ shell: bash+ run: |+ cd /tmp/verify-install/node_modules/@cosmicstack/mercury-agent+ node -e "+ const {createRequire} = require('node:module');+ const req = createRequire(require('url').pathToFileURL(require('path').resolve('package.json')));+ let ok = false;+ try { req('better-sqlite3'); ok = true; } catch { ok = false; }+ console.log('better-sqlite3 available:', ok);+ if (!ok) console.log('OK: better-sqlite3 gracefully unavailable (optional)');+ " || echo "OK: better-sqlite3 probe handled"++ publish:+ name: Publish to npm+ needs: [typecheck, test, pack-verify]+ runs-on: ubuntu-latest+ if: startsWith(github.ref, 'refs/tags/v')+ permissions:+ contents: read+ id-token: write+ steps:+ - uses: actions/checkout@v4+ - uses: actions/setup-node@v4+ with:+ node-version: 22+ registry-url: https://registry.npmjs.org+ - run: npm ci+ - run: npm run build+ - run: npm publish --access public --provenance+ env:+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}\ No newline at end of filediff --git a/scripts/publish.sh b/scripts/publish.shindex 497653b4..6db804e0 100755--- a/scripts/publish.sh+++ b/scripts/publish.sh@@ -11,21 +11,20 @@ echo "Package: ${PKG_NAME}"echo "Version: ${PKG_VERSION}"echo ""-echo "1/5 Type checking..."+echo "1/6 Type checking..."npm run typecheck-echo "2/5 Building..."-npm run build+echo "2/6 Running tests..."+npm run test-echo "3/5 Verifying package contents..."-npm pack --dry-run 2>&1 | head -20+echo "3/6 Verifying package integrity (dry-run install)..."+node scripts/verify-package.cjs-echo ""-echo "4/5 Verifying shebang..."+echo "4/6 Verifying shebang..."head -1 dist/index.jsecho ""-echo "5/5 Publishing to npm..."+echo "5/6 Publishing to npm..."npm publish --access publicecho ""diff --git a/scripts/verify-package.cjs b/scripts/verify-package.cjsnew file mode 100755index 00000000..bd196768--- /dev/null+++ b/scripts/verify-package.cjs@@ -0,0 +1,96 @@+#!/usr/bin/env node+const { execSync } = require('child_process');+const { existsSync, readFileSync, mkdirSync, rmSync, writeFileSync } = require('fs');+const { join, resolve } = require('path');+const { tmpdir } = require('os');++const ROOT = resolve(__dirname, '..');+const TMP = join(tmpdir(), `mercury-pack-verify-${process.pid}`);++let failed = false;++function check(label, fn) {+ try {+ fn();+ console.log(` \u2713 ${label}`);+ } catch (err) {+ console.log(` \u2717 ${label}: ${err.message}`);+ failed = true;+ }+}++console.log('\u263F Mercury Agent \u2014 Pack & Verify\n');+console.log('1/5 Building...');+execSync('npm run build', { cwd: ROOT, stdio: 'inherit' });++console.log('\n2/5 Packing tarball...');+if (existsSync(TMP)) rmSync(TMP, { recursive: true, force: true });+mkdirSync(TMP, { recursive: true });++const tarball = execSync('npm pack 2>/dev/null', { cwd: ROOT, encoding: 'utf-8' }).trim();+const tarballPath = join(ROOT, tarball);+console.log(` Tarball: ${tarball}`);++console.log('\n3/5 Extracting & installing...');+execSync(`tar -xzf "${tarballPath}" -C "${TMP}"`, { stdio: 'pipe' });+const pkgDir = join(TMP, 'package');++const installDir = join(TMP, 'install');+mkdirSync(installDir, { recursive: true });+writeFileSync(join(installDir, 'package.json'), '{}');+execSync(`npm install "${tarballPath}" --omit=dev --no-save`, { cwd: installDir, stdio: 'pipe' });++const modDir = join(installDir, 'node_modules', '@cosmicstack', 'mercury-agent');++console.log('\n4/5 Verifying package integrity...');++check('package.json exists', () => {+ if (!existsSync(join(modDir, 'package.json'))) throw new Error('missing package.json');+});++check('dist/index.js exists', () => {+ if (!existsSync(join(modDir, 'dist', 'index.js'))) throw new Error('missing dist/index.js');+});++check('shebang present', () => {+ const head = readFileSync(join(modDir, 'dist', 'index.js'), 'utf-8').split('\n')[0];+ if (!head.includes('node')) throw new Error('no #!/usr/bin/env node shebang');+});++check('no dangling script references', () => {+ const pkg = JSON.parse(readFileSync(join(modDir, 'package.json'), 'utf-8'));+ const scripts = pkg.scripts || {};+ for (const [key, val] of Object.entries(scripts)) {+ if (val.includes('scripts/') || val.includes('bash ')) {+ throw new Error(`script "${key}" references unpublished path: ${val}`);+ }+ }+});++check('better-sqlite3 is optional', () => {+ const pkg = JSON.parse(readFileSync(join(modDir, 'package.json'), 'utf-8'));+ if (pkg.dependencies && pkg.dependencies['better-sqlite3']) {+ throw new Error('better-sqlite3 is in dependencies, not optionalDependencies');+ }+ if (!pkg.optionalDependencies || !pkg.optionalDependencies['better-sqlite3']) {+ throw new Error('better-sqlite3 missing from optionalDependencies');+ }+});++check('engines requires >=20', () => {+ const pkg = JSON.parse(readFileSync(join(modDir, 'package.json'), 'utf-8'));+ if (!pkg.engines || !pkg.engines.node || !pkg.engines.node.includes('20')) {+ throw new Error('engines.node should require >=20.0.0');+ }+});++console.log('\n5/5 Cleaning up...');+try { rmSync(TMP, { recursive: true, force: true }); } catch {}+try { rmSync(tarballPath, { force: true }); } catch {}++if (failed) {+ console.log('\n\u2717 Verification FAILED \u2014 do not publish!\n');+ process.exit(1);+} else {+ console.log('\n\u2713 All checks passed \u2014 safe to publish.\n');+}\ No newline at end of file