Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

skills: ship the resolver library as gbrain/skill-resolver and a Node bundle

garrytan26a9ae676816
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 37887a8b61..3e1aa50d1c 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -2,7 +2,8 @@ name: Release
# Publishes a GitHub release for every VERSION bump that lands on master:
# tag + title `v<VERSION>`, notes from that version's CHANGELOG.md entry,
-# compiled binaries attached (#3521).
+# compiled binaries attached (#3521), plus the skill resolver library bundle
+# for Node adapters (gbrain-skill-resolver.mjs, GBRA-377).
#
# Why every bump: `gbrain check-update` resolves the latest version from the
# VERSION file on master, but binary self-update
@@ -62,7 +63,7 @@ jobs:
# can repair it.
assets="$(gh release view "v$version" --repo "$GITHUB_REPOSITORY" \
--json assets --jq '[.assets[].name] | sort | join(",")' 2>/dev/null || true)"
- if [ "$assets" = "gbrain-darwin-arm64,gbrain-linux-x64" ]; then
+ if [ "$assets" = "gbrain-darwin-arm64,gbrain-linux-x64,gbrain-skill-resolver.mjs" ]; then
echo "exists=true" >> "$GITHUB_OUTPUT"
echo "Release v$version already published with all assets — nothing to do."
else
@@ -176,8 +177,35 @@ jobs:
name: ${{ matrix.artifact }}
path: bin/${{ matrix.artifact }}
+ skill-resolver-bundle:
+ # GBRA-377: the skill resolver library as one dependency-free ES module for
+ # Node adapters (docs/guides/skill-resolver.md#library). Built from the gated
+ # SHA and smoke-tested under Node before it is attached.
+ needs: [version, ci-gate]
+ if: needs.version.outputs.exists == 'false' && needs.ci-gate.outputs.publish == 'true'
+ runs-on: ubuntu-latest
+ timeout-minutes: 15
+ permissions:
+ contents: read
+ steps:
+ - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
+ with:
+ ref: ${{ needs.ci-gate.outputs.sha }}
+ - uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2
+ with:
+ bun-version: 1.4.4
+ - name: Install dependencies (bounded, retried once)
+ timeout-minutes: 8
+ run: bun scripts/ci-bun-install.ts --frozen-lockfile --ignore-scripts
+ - name: Build and smoke-test the bundle under Node
+ run: bun scripts/build-skill-resolver-bundle.ts --out bundle/gbrain-skill-resolver.mjs --smoke
+ - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
+ with:
+ name: gbrain-skill-resolver.mjs
+ path: bundle/gbrain-skill-resolver.mjs
+
release:
- needs: [version, ci-gate, build]
+ needs: [version, ci-gate, build, skill-resolver-bundle]
if: needs.version.outputs.exists == 'false' && needs.ci-gate.outputs.publish == 'true'
runs-on: ubuntu-latest
timeout-minutes: 15
@@ -212,6 +240,7 @@ jobs:
files: |
artifacts/gbrain-darwin-arm64/gbrain-darwin-arm64
artifacts/gbrain-linux-x64/gbrain-linux-x64
+ artifacts/gbrain-skill-resolver.mjs/gbrain-skill-resolver.mjs
# [C1 = D6-A] `latest-stable` is the alpha channel's ref: the alpha
# update check follows it, and so does anyone who pins it by hand. The
# install surfaces (the README paste block, the BOOTSTRAP_FOR_AGENTS.md
diff --git a/package.json b/package.json
index c091098d11..965d010452 100644
--- a/package.json
+++ b/package.json
@@ -42,6 +42,7 @@
"./ingestion/test-harness": "./src/core/ingestion/test-harness.ts",
"./core/guardrails": "./src/core/guardrails.ts",
"./core/skillopt": "./src/core/skillopt/index.ts",
+ "./skill-resolver": "./src/core/skills/resolver/index.ts",
"./pglite-lock": "./src/core/pglite-lock.ts",
"./version": "./src/version.ts"
},
diff --git a/scripts/build-skill-resolver-bundle.ts b/scripts/build-skill-resolver-bundle.ts
new file mode 100644
index 0000000000..8ec5d80e36
--- /dev/null
+++ b/scripts/build-skill-resolver-bundle.ts
@@ -0,0 +1,42 @@
+#!/usr/bin/env bun
+/**
+ * Build the skill resolver library (src/core/skills/resolver/index.ts) as
+ * one dependency-free ES module for Node adapters: the release asset
+ * gbrain-skill-resolver.mjs (docs/guides/skill-resolver.md#library).
+ *
+ * Usage: bun scripts/build-skill-resolver-bundle.ts --out <file.mjs> [--smoke]
+ * --smoke imports the bundle with node, builds a catalog from JSON and the
+ * bundled catalog in a scratch home, resolves one turn, and exits 1 on any
+ * failure.
+ */
+import { mkdtempSync, rmSync, writeFileSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import { basename, dirname, join, resolve } from 'node:path';
+
+const args = process.argv.slice(2);
+const at = args.indexOf('--out');
+if (at < 0 || !args[at + 1]) { console.error('Usage: bun scripts/build-skill-resolver-bundle.ts --out <file.mjs> [--smoke]'); process.exit(2); }
+const out = resolve(args[at + 1]!);
+const result = await Bun.build({ entrypoints: [join(import.meta.dir, '..', 'src/core/skills/resolver/index.ts')], target: 'node', format: 'esm', outdir: dirname(out), naming: basename(out) });
+if (!result.success) { for (const l of result.logs) console.error(l); process.exit(1); }
+console.log(`built ${out}`);
+if (args.includes('--smoke')) {
+ const home = mkdtempSync(join(tmpdir(), 'skres-bundle-'));
+ try {
+ const probe = join(home, 'probe.mjs');
+ writeFileSync(probe, [
+ `const m = await import(${JSON.stringify(out)});`,
+ `const home = ${JSON.stringify(join(home, 'home'))};`,
+ "await m.buildSkillIndex({ catalog: 'c', fromJson: JSON.stringify([{ id: 'x:deploy', name: 'deploy', description: 'Ship a service to production' }]), fromJsonStdin: true }, { home });",
+ "const b = await m.buildSkillIndex({ catalog: 'gb', bundled: true }, { home });",
+ "const t = await m.resolveSkills({ message: 'deploy the service' }, { home, catalogs: ['c'] });",
+ "if (t.output.suggestions[0]?.id !== 'x:deploy' || b.catalog.skill_count < 1) { console.error(JSON.stringify(t.output)); process.exit(1); }",
+ "console.log(JSON.stringify({ node: process.version, bundled_skills: b.catalog.skill_count, top: t.output.suggestions[0].id }));",
+ ].join('\n'));
+ const run = Bun.spawnSync(['node', probe], { stdout: 'pipe', stderr: 'pipe', cwd: home });
+ process.stdout.write(run.stdout.toString());
+ if (run.exitCode !== 0) { console.error(run.stderr.toString()); process.exit(1); }
+ } finally {
+ rmSync(home, { recursive: true, force: true });
+ }
+}
diff --git a/test/skill-resolver-packaging.test.ts b/test/skill-resolver-packaging.test.ts
new file mode 100644
index 0000000000..cddeeac577
--- /dev/null
+++ b/test/skill-resolver-packaging.test.ts
@@ -0,0 +1,40 @@
+/**
+ * GBRA-377 PR A: the skill resolver library's two published forms.
+ *
+ * 1. Protects: `gbrain/skill-resolver` (the package export Bun consumers
+ * import) and the dependency-free Node bundle the release attaches
+ * (scripts/build-skill-resolver-bundle.ts, gbrain-skill-resolver.mjs),
+ * which must import and resolve under Node with no node_modules.
+ * 2. Fails when: the export path moves, or the bundle stops building or
+ * running under Node (a Bun-only API, an unbundled dependency).
+ */
+import { describe, expect, test } from 'bun:test';
+import { mkdtempSync, rmSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import { join, resolve } from 'node:path';
+
+const ROOT = resolve(import.meta.dir, '..');
+
+describe('skill resolver packaging', () => {
+ test('the package export names the library entry point', async () => {
+ const pkg = await Bun.file(join(ROOT, 'package.json')).json() as { exports: Record<string, string> };
+ expect(pkg.exports['./skill-resolver']).toBe('./src/core/skills/resolver/index.ts');
+ const viaExport = await import('gbrain/skill-resolver');
+ const direct = await import('../src/core/skills/resolver/index.ts');
+ expect(viaExport.resolveSkills).toBe(direct.resolveSkills);
+ });
+
+ test.skipIf(!Bun.which('node'))('the Node bundle builds, imports under node from an empty directory and resolves', () => {
+ const dir = mkdtempSync(join(tmpdir(), 'skres-node-'));
+ try {
+ const out = join(dir, 'gbrain-skill-resolver.mjs');
+ const run = Bun.spawnSync([process.execPath, 'scripts/build-skill-resolver-bundle.ts', '--out', out, '--smoke'], { cwd: ROOT, stdout: 'pipe', stderr: 'pipe' });
+ expect(run.exitCode, run.stderr.toString()).toBe(0);
+ const smoke = JSON.parse(run.stdout.toString().trim().split('\n').at(-1)!) as { node: string; bundled_skills: number; top: string };
+ expect(smoke.top).toBe('x:deploy');
+ expect(smoke.bundled_skills).toBeGreaterThan(20);
+ } finally {
+ rmSync(dir, { recursive: true, force: true });
+ }
+ }, 120_000);
+});