mirror of
https://github.com/garrytan/gbrain.git
synced 2026-08-15 01:12:20 +00:00
Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7b8676be3e | ||
|
|
b8376f7327 |
@@ -206,7 +206,11 @@ jobs:
|
||||
needs: cache-check
|
||||
if: needs.cache-check.outputs.hit != 'true'
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 15
|
||||
# 20 (was 15): shard 4 runs ~14.5 min on master (dream.test.ts ~29s/test
|
||||
# dominates it) and hits the 15-min ceiling on slower runners, cancelling
|
||||
# mid-run with 0 test failures. Rebalancing via
|
||||
# scripts/mine-shard-weights.ts is the real fix; this stops the bleeding.
|
||||
timeout-minutes: 20
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
|
||||
@@ -56,36 +56,6 @@ export const litellmProxy: Recipe = {
|
||||
cost_per_1m_output_usd: undefined,
|
||||
price_last_verified: '2026-06-14',
|
||||
},
|
||||
// LiteLLM normalizes Cohere / Voyage / Jina / etc. rerank backends to the
|
||||
// same wire shape gbrain's gateway.rerank() already speaks (the
|
||||
// ZeroEntropy/llama.cpp contract):
|
||||
// { model, query, documents, top_n } → { results: [{ index, relevance_score }] }
|
||||
// So any rerank model the user registers in their LiteLLM config is
|
||||
// reachable via `gbrain config set search.reranker.model litellm:<model>`
|
||||
// with no request/response adapter — same as embeddings ride the proxy.
|
||||
reranker: {
|
||||
models: [], // user-provided; whatever rerank models the proxy serves
|
||||
// No canonical default — the proxy defines its own model ids. The user
|
||||
// sets search.reranker.model explicitly (mirrors the embedding
|
||||
// touchpoint's user_provided_models contract).
|
||||
default_model: '',
|
||||
// The proxied backend bills (Cohere/Voyage/…); pricing-unknown is the
|
||||
// honest state — same stance as this recipe's embedding/chat
|
||||
// touchpoints and budget-tracker's deliberate litellm exclusion from
|
||||
// the free-provider sets.
|
||||
cost_per_1m_tokens_usd: undefined,
|
||||
price_last_verified: '2026-06-27',
|
||||
max_payload_bytes: 5_000_000,
|
||||
// LEAF path only (matches llama-server-reranker's convention). LiteLLM
|
||||
// serves both `/rerank` and `/v1/rerank`, and LITELLM_BASE_URL may be
|
||||
// set with or without the `/v1` suffix (the setup_hint allows both), so
|
||||
// the leaf form yields a valid route either way:
|
||||
// http://localhost:4000 + /rerank → /rerank ✓
|
||||
// http://localhost:4000/v1 + /rerank → /v1/rerank ✓
|
||||
// Pinning '/v1/rerank' here would double to /v1/v1/rerank → 404 on
|
||||
// /v1-suffixed bases.
|
||||
path: '/rerank',
|
||||
},
|
||||
},
|
||||
setup_hint: 'Run LiteLLM (https://docs.litellm.ai) in front of any provider; set LITELLM_BASE_URL (include the /v1 suffix if your proxy serves the OpenAI route there, e.g. http://localhost:4000/v1) + pass --embedding-model litellm:<model> and --embedding-dimensions <N>. For rerank: register a rerank model in LiteLLM and set search.reranker.model litellm:<model-name>.',
|
||||
setup_hint: 'Run LiteLLM (https://docs.litellm.ai) in front of any provider; set LITELLM_BASE_URL (include the /v1 suffix if your proxy serves the OpenAI route there, e.g. http://localhost:4000/v1) + pass --embedding-model litellm:<model> and --embedding-dimensions <N>.',
|
||||
};
|
||||
|
||||
@@ -23,6 +23,15 @@
|
||||
* hold conventions and shared rule files, not skills. Files like
|
||||
* `_brain-filing-rules.md` live at the root and are not considered
|
||||
* skills by either loader.
|
||||
*
|
||||
* ClawHub-installed workspace skills (#1767): a skill dir carrying
|
||||
* `.clawhub/origin.json` is an externally-managed runtime integration
|
||||
* (e.g. an email or catalog skill), not a gbrain-routable skill. The
|
||||
* derive path SKIPS those so `gbrain doctor` resolver_health doesn't
|
||||
* hard-fail on them — UNLESS the skill's SKILL.md frontmatter declares
|
||||
* `triggers:`, which is the explicit opt-in to gbrain routing (and the
|
||||
* same surface that makes it reachable). An explicit manifest.json that
|
||||
* lists a ClawHub skill also keeps strict checking (verbatim path).
|
||||
*/
|
||||
|
||||
import { existsSync, readFileSync, readdirSync, statSync } from 'fs';
|
||||
@@ -60,9 +69,27 @@ function parseSkillName(skillMdPath: string): string | null {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Does the SKILL.md frontmatter declare a `triggers:` key? A ClawHub-
|
||||
* installed skill that ships gbrain `triggers:` has explicitly opted in
|
||||
* to gbrain routing and gets full resolver checks (#1767).
|
||||
*/
|
||||
function declaresTriggers(skillMdPath: string): boolean {
|
||||
try {
|
||||
const content = readFileSync(skillMdPath, 'utf-8');
|
||||
const fmMatch = content.match(/^---\n([\s\S]*?)\n---/);
|
||||
if (!fmMatch) return false;
|
||||
return /^triggers:/m.test(fmMatch[1]);
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Walk skillsDir, return every `<skillsDir>/<dir>/SKILL.md` as a
|
||||
* ManifestEntry. Dotfile and underscore-prefixed dirs are skipped.
|
||||
* ManifestEntry. Dotfile and underscore-prefixed dirs are skipped, as
|
||||
* are ClawHub-installed external skills that haven't opted in to gbrain
|
||||
* routing via `triggers:` frontmatter (#1767).
|
||||
*/
|
||||
function deriveManifest(skillsDir: string): ManifestEntry[] {
|
||||
const out: ManifestEntry[] = [];
|
||||
@@ -93,6 +120,12 @@ function deriveManifest(skillsDir: string): ManifestEntry[] {
|
||||
const skillMd = join(subdirAbs, 'SKILL.md');
|
||||
if (!existsSync(skillMd)) continue;
|
||||
|
||||
// ClawHub-installed external skill (#1767): skip unless it opts in
|
||||
// to gbrain routing by declaring `triggers:` in its frontmatter.
|
||||
if (existsSync(join(subdirAbs, '.clawhub', 'origin.json')) && !declaresTriggers(skillMd)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const frontmatterName = parseSkillName(skillMd);
|
||||
const name = frontmatterName && frontmatterName !== '' ? frontmatterName : entry;
|
||||
out.push({ name, path: `${entry}/SKILL.md` });
|
||||
|
||||
@@ -1,88 +0,0 @@
|
||||
/**
|
||||
* litellm-proxy reranker touchpoint smoke.
|
||||
*
|
||||
* Sibling of recipe-llama-server-reranker.test.ts. Pins the reranker
|
||||
* touchpoint on the LiteLLM proxy recipe so:
|
||||
* - the touchpoint exists with the LEAF '/rerank' path (LiteLLM serves both
|
||||
* /rerank and /v1/rerank, so the leaf form is valid whether or not the
|
||||
* user's LITELLM_BASE_URL carries the /v1 suffix the setup_hint allows)
|
||||
* - a /v1-suffixed base URL does NOT produce /v1/v1/rerank (the original
|
||||
* community PR pinned '/v1/rerank' which 404s on /v1-suffixed bases)
|
||||
* - models: [] (user-provided; proxy defines the model ids)
|
||||
* - pricing stays undefined (proxy can front a paid provider — same honest
|
||||
* pricing-unknown stance as the embedding/chat touchpoints)
|
||||
*
|
||||
* The gateway.rerank() URL tests drive the real URL builder via the stubbed
|
||||
* transport (same seam as test/ai/rerank.test.ts).
|
||||
*/
|
||||
|
||||
import { describe, expect, test, afterEach } from 'bun:test';
|
||||
import { getRecipe } from '../../src/core/ai/recipes/index.ts';
|
||||
import {
|
||||
configureGateway,
|
||||
resetGateway,
|
||||
rerank,
|
||||
__setRerankTransportForTests,
|
||||
} from '../../src/core/ai/gateway.ts';
|
||||
|
||||
afterEach(() => {
|
||||
__setRerankTransportForTests(null);
|
||||
resetGateway();
|
||||
});
|
||||
|
||||
describe('recipe: litellm reranker touchpoint', () => {
|
||||
test('declares reranker touchpoint with leaf /rerank path', () => {
|
||||
const r = getRecipe('litellm')!;
|
||||
const tp = r.touchpoints.reranker;
|
||||
expect(tp).toBeDefined();
|
||||
expect(tp!.path).toBe('/rerank');
|
||||
expect(tp!.max_payload_bytes).toBe(5_000_000);
|
||||
});
|
||||
|
||||
test('reranker touchpoint uses empty models[] for user-provided model ids', () => {
|
||||
const r = getRecipe('litellm')!;
|
||||
expect(r.touchpoints.reranker!.models).toEqual([]);
|
||||
});
|
||||
|
||||
test('pricing stays undefined — proxy can front a paid provider', () => {
|
||||
const r = getRecipe('litellm')!;
|
||||
expect(r.touchpoints.reranker!.cost_per_1m_tokens_usd).toBeUndefined();
|
||||
});
|
||||
|
||||
test('setup_hint keeps the /v1-suffix guidance AND mentions rerank', () => {
|
||||
const r = getRecipe('litellm')!;
|
||||
expect(r.setup_hint).toMatch(/\/v1 suffix/);
|
||||
expect(r.setup_hint).toMatch(/search\.reranker\.model litellm:/);
|
||||
});
|
||||
});
|
||||
|
||||
describe('gateway.rerank() URL via litellm recipe', () => {
|
||||
async function capturedRerankUrl(baseUrl?: string): Promise<string> {
|
||||
configureGateway({
|
||||
reranker_model: 'litellm:my-reranker',
|
||||
env: {},
|
||||
...(baseUrl ? { base_urls: { litellm: baseUrl } } : {}),
|
||||
});
|
||||
let capturedUrl = '';
|
||||
__setRerankTransportForTests(async (url) => {
|
||||
capturedUrl = url;
|
||||
return new Response(
|
||||
JSON.stringify({ results: [{ index: 0, relevance_score: 0.9 }] }),
|
||||
{ status: 200, headers: { 'content-type': 'application/json' } },
|
||||
);
|
||||
});
|
||||
await rerank({ query: 'q', documents: ['d'] });
|
||||
return capturedUrl;
|
||||
}
|
||||
|
||||
test('default base (no /v1 suffix) → /rerank', async () => {
|
||||
const url = await capturedRerankUrl();
|
||||
expect(url).toBe('http://localhost:4000/rerank');
|
||||
});
|
||||
|
||||
test('/v1-suffixed base → /v1/rerank, NOT /v1/v1/rerank', async () => {
|
||||
const url = await capturedRerankUrl('http://localhost:4000/v1');
|
||||
expect(url).toBe('http://localhost:4000/v1/rerank');
|
||||
expect(url).not.toContain('/v1/v1/');
|
||||
});
|
||||
});
|
||||
@@ -382,6 +382,35 @@ describe("DRY detection — checkResolvable", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("#1767 — ClawHub workspace skills are not resolver-required", () => {
|
||||
let dir: string;
|
||||
afterEachCleanup(() => dir && rmSync(dir, { recursive: true, force: true }));
|
||||
|
||||
test("ClawHub skill without gbrain metadata produces no unreachable/mece_gap", () => {
|
||||
dir = mkdtempSync(join(tmpdir(), "gbrain-clawhub-"));
|
||||
// Native gbrain skill: routable via frontmatter triggers. No manifest.json
|
||||
// (the OpenClaw derive path from the issue repro).
|
||||
mkdirSync(join(dir, "query"), { recursive: true });
|
||||
writeFileSync(
|
||||
join(dir, "query", "SKILL.md"),
|
||||
`---\nname: query\ndescription: test\ntriggers:\n - "what do we know"\n---\n\n# query\n`
|
||||
);
|
||||
// ClawHub-installed integration: no triggers, no resolver row.
|
||||
mkdirSync(join(dir, "agentmail", ".clawhub"), { recursive: true });
|
||||
writeFileSync(
|
||||
join(dir, "agentmail", ".clawhub", "origin.json"),
|
||||
JSON.stringify({ registry: "https://clawhub.ai", slug: "agentmail" })
|
||||
);
|
||||
writeFileSync(join(dir, "agentmail", "SKILL.md"), `---\nname: agentmail\ndescription: email integration\n---\n\n# agentmail\n`);
|
||||
|
||||
const report = checkResolvable(dir);
|
||||
const agentmailIssues = report.issues.filter(i => i.skill === "agentmail");
|
||||
expect(agentmailIssues).toEqual([]);
|
||||
expect(report.ok).toBe(true);
|
||||
expect(report.summary.total_skills).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe("v0.22.4 regression — actual repo skills/ has 0 errors", () => {
|
||||
test("repo skills/ pass check-resolvable cleanly (zero errors AND zero warnings)", () => {
|
||||
// The v0.22.4 (Part A) contract was zero warnings AND zero errors.
|
||||
|
||||
@@ -166,6 +166,55 @@ describe('loadOrDeriveManifest', () => {
|
||||
expect(r.skills.map(s => s.name)).toEqual(['apple', 'mango', 'zebra']);
|
||||
});
|
||||
|
||||
// #1767 — ClawHub-installed workspace skills are external integrations,
|
||||
// not gbrain-routable skills. The derive path skips them unless they
|
||||
// opt in via `triggers:` frontmatter.
|
||||
it('skips ClawHub-origin skills without triggers frontmatter (#1767)', () => {
|
||||
const dir = scratch();
|
||||
writeSkill(dir, 'query', 'query');
|
||||
writeSkill(dir, 'agentmail', 'agentmail');
|
||||
mkdirSync(join(dir, 'agentmail', '.clawhub'), { recursive: true });
|
||||
writeFileSync(
|
||||
join(dir, 'agentmail', '.clawhub', 'origin.json'),
|
||||
JSON.stringify({ registry: 'https://clawhub.ai', slug: 'agentmail' })
|
||||
);
|
||||
const r = loadOrDeriveManifest(dir);
|
||||
expect(r.derived).toBe(true);
|
||||
expect(r.skills.map(s => s.name)).toEqual(['query']);
|
||||
});
|
||||
|
||||
it('includes ClawHub-origin skills that opt in via triggers frontmatter (#1767)', () => {
|
||||
const dir = scratch();
|
||||
writeSkill(dir, 'agentmail', 'agentmail');
|
||||
mkdirSync(join(dir, 'agentmail', '.clawhub'), { recursive: true });
|
||||
writeFileSync(
|
||||
join(dir, 'agentmail', '.clawhub', 'origin.json'),
|
||||
JSON.stringify({ registry: 'https://clawhub.ai', slug: 'agentmail' })
|
||||
);
|
||||
writeFileSync(
|
||||
join(dir, 'agentmail', 'SKILL.md'),
|
||||
`---\nname: agentmail\ndescription: test\ntriggers:\n - "send email"\n---\n\n# agentmail\n`
|
||||
);
|
||||
const r = loadOrDeriveManifest(dir);
|
||||
expect(r.derived).toBe(true);
|
||||
expect(r.skills.map(s => s.name)).toEqual(['agentmail']);
|
||||
});
|
||||
|
||||
it('keeps ClawHub-origin skills listed in an explicit manifest.json (#1767)', () => {
|
||||
// Explicit manifest.json is a deliberate declaration — strict checking stays.
|
||||
const dir = scratch();
|
||||
writeSkill(dir, 'agentmail', 'agentmail');
|
||||
mkdirSync(join(dir, 'agentmail', '.clawhub'), { recursive: true });
|
||||
writeFileSync(
|
||||
join(dir, 'agentmail', '.clawhub', 'origin.json'),
|
||||
JSON.stringify({ registry: 'https://clawhub.ai', slug: 'agentmail' })
|
||||
);
|
||||
writeManifest(dir, { skills: [{ name: 'agentmail', path: 'agentmail/SKILL.md' }] });
|
||||
const r = loadOrDeriveManifest(dir);
|
||||
expect(r.derived).toBe(false);
|
||||
expect(r.skills.map(s => s.name)).toEqual(['agentmail']);
|
||||
});
|
||||
|
||||
it('treats dirs without SKILL.md as not-a-skill', () => {
|
||||
const dir = scratch();
|
||||
writeSkill(dir, 'query', 'query');
|
||||
|
||||
Reference in New Issue
Block a user