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:
|
||||
|
||||
+1
-4
@@ -935,10 +935,7 @@ export function formatResult(opName: string, result: unknown): string {
|
||||
lines.push(`Link coverage (entities): ${(h.link_coverage * 100).toFixed(1)}%`);
|
||||
}
|
||||
if (h.timeline_coverage !== undefined) {
|
||||
lines.push(`Timeline coverage (entity pages): ${(h.timeline_coverage * 100).toFixed(1)}%`);
|
||||
}
|
||||
if (h.timeline_coverage_score !== undefined) {
|
||||
lines.push(`Timeline density (all pages): ${h.timeline_coverage_score}/15 (whole-brain brain-score component)`);
|
||||
lines.push(`Timeline coverage (entities): ${(h.timeline_coverage * 100).toFixed(1)}%`);
|
||||
}
|
||||
if (Array.isArray(h.most_connected) && h.most_connected.length > 0) {
|
||||
lines.push('Most connected entities:');
|
||||
|
||||
@@ -5868,12 +5868,12 @@ export async function buildChecks(
|
||||
message: `Only code/test fixture entity pages found (${entityCount}); graph_coverage not applicable`,
|
||||
});
|
||||
} else if (linkCoverage >= 0.5 && timelineCoverage >= 0.5) {
|
||||
checks.push({ name: 'graph_coverage', status: 'ok', message: `Entity link coverage ${linkPct}%, entity timeline coverage ${timelinePct}%` });
|
||||
checks.push({ name: 'graph_coverage', status: 'ok', message: `Entity link coverage ${linkPct}%, timeline ${timelinePct}%` });
|
||||
} else {
|
||||
checks.push({
|
||||
name: 'graph_coverage',
|
||||
status: 'warn',
|
||||
message: `Entity link coverage ${linkPct}%, entity timeline coverage ${timelinePct}% (${eligibleEntityCount} entity pages). Run: gbrain extract all`,
|
||||
message: `Entity link coverage ${linkPct}%, timeline ${timelinePct}% (${eligibleEntityCount} entity pages). Run: gbrain extract all`,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -5885,7 +5885,7 @@ export async function buildChecks(
|
||||
const parts = [
|
||||
`embed ${health.embed_coverage_score}/35`,
|
||||
`links ${health.link_density_score}/25`,
|
||||
`timeline density (all pages) ${health.timeline_coverage_score}/15`,
|
||||
`timeline ${health.timeline_coverage_score}/15`,
|
||||
`orphans ${health.no_orphans_score}/15`,
|
||||
`dead-links ${health.no_dead_links_score}/10`,
|
||||
];
|
||||
|
||||
@@ -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` });
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -1,155 +0,0 @@
|
||||
/**
|
||||
* Issue #2298 — timeline metric presentation contract.
|
||||
*
|
||||
* Authoritative upstream semantics (src/core/types.ts):
|
||||
* - Metric A `timeline_coverage` (entity-scoped, fraction 0–1):
|
||||
* eligible entity pages WITH a timeline entry / eligible entity pages
|
||||
* -> surfaced by `graph_coverage` check AND `get_health` CLI entity line.
|
||||
* - Metric B `timeline_coverage_score` (whole-brain, 0–15 brain-score component):
|
||||
* all pages WITH a timeline entry / all pages
|
||||
* -> surfaced by `brain_score` component breakdown AND (separately) CLI.
|
||||
*
|
||||
* The two have DIFFERENT numerators/denominators. This PR labels each
|
||||
* explicitly and keeps BOTH the entity CLI line and the whole-brain line.
|
||||
*
|
||||
* Tests (no private EriadorMu data, no production/home DB, no network):
|
||||
* - numeric denominator assertions (Metric A = 50%, Metric B = 4/15)
|
||||
* - doctor rendered-message assertions (exact labels, no ambiguous old label)
|
||||
* - CLI rendered-output assertions (exact lines, guard matrix)
|
||||
* - red/green: same assertions FAIL on origin/master, PASS on this branch
|
||||
*
|
||||
* Scoring formula UNCHANGED. Canonical PGLite fixture via resetPgliteState.
|
||||
*/
|
||||
|
||||
import { describe, expect, test, beforeAll, afterAll, beforeEach } from 'bun:test';
|
||||
import { PGLiteEngine } from '../src/core/pglite-engine.ts';
|
||||
import { sqlQueryForEngine } from '../src/core/sql-query.ts';
|
||||
import { resetPgliteState } from './helpers/reset-pglite.ts';
|
||||
import { buildChecks } from '../src/commands/doctor.ts';
|
||||
import { formatResult } from '../src/cli.ts';
|
||||
|
||||
let engine: PGLiteEngine;
|
||||
|
||||
async function seedFourPages(eng: PGLiteEngine): Promise<void> {
|
||||
const sql = sqlQueryForEngine(eng);
|
||||
// 2 eligible entity pages, 2 technical/non-entity pages.
|
||||
// Only ONE entity page has a timeline entry; only ONE total page does.
|
||||
await sql`
|
||||
INSERT INTO pages (slug, source_id, type, title, compiled_truth, frontmatter, content_hash, created_at, updated_at)
|
||||
VALUES
|
||||
('acme-example', 'default', 'company', 'Acme', '', '{}', 'h1', now(), now()),
|
||||
('alice-example', 'default', 'person', 'Alice', '', '{}', 'h2', now(), now()),
|
||||
('technical-a', 'default', 'note', 'Tech A', '', '{}', 'h3', now(), now()),
|
||||
('technical-b', 'default', 'note', 'Tech B', '', '{}', 'h4', now(), now())
|
||||
`;
|
||||
const companyId = (await sql`SELECT id FROM pages WHERE slug='acme-example'`)[0].id as number;
|
||||
await sql`INSERT INTO timeline_entries (page_id, date, source, summary, detail)
|
||||
VALUES (${companyId}, CURRENT_DATE, 'test', 'milestone', '{}')`;
|
||||
}
|
||||
|
||||
beforeAll(async () => {
|
||||
engine = new PGLiteEngine();
|
||||
await engine.connect({});
|
||||
await engine.initSchema();
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await engine.disconnect();
|
||||
});
|
||||
|
||||
beforeEach(async () => {
|
||||
await resetPgliteState(engine);
|
||||
});
|
||||
|
||||
describe('issue #2298 — numeric denominator semantics', () => {
|
||||
test('entity timeline coverage = 1/2 = 50% (2 eligible entities, 1 with timeline)', async () => {
|
||||
await seedFourPages(engine);
|
||||
const health = await engine.getHealth();
|
||||
expect(health.timeline_coverage).toBeDefined();
|
||||
expect(Math.round((health.timeline_coverage ?? 0) * 100)).toBe(50);
|
||||
});
|
||||
|
||||
test('whole-brain timeline density = 1/4 -> score 4/15 (4 total pages, 1 with timeline)', async () => {
|
||||
await seedFourPages(engine);
|
||||
const health = await engine.getHealth();
|
||||
expect(health.timeline_coverage_score).toBeDefined();
|
||||
expect(health.timeline_coverage_score).toBe(4);
|
||||
});
|
||||
|
||||
test('the two metrics use independent denominators', async () => {
|
||||
await seedFourPages(engine);
|
||||
const health = await engine.getHealth();
|
||||
expect(Math.round((health.timeline_coverage ?? 0) * 100)).toBe(50);
|
||||
expect(health.timeline_coverage_score ?? 0).toBe(4);
|
||||
// 50% (entity, /2) != 26.7% (whole-brain, /4). Provably distinct.
|
||||
expect(Math.round(((health.timeline_coverage_score ?? 0) / 15) * 100)).not.toBe(50);
|
||||
});
|
||||
});
|
||||
|
||||
describe('issue #2298 — doctor rendered-message contract', () => {
|
||||
test('graph_coverage renders entity-scoped label with 50%', async () => {
|
||||
await seedFourPages(engine);
|
||||
const checks = await buildChecks(engine, [], null);
|
||||
const graph = checks.find((c) => c.name === 'graph_coverage');
|
||||
expect(graph, 'graph_coverage check must be present').toBeDefined();
|
||||
expect(graph!.message).toContain('entity timeline coverage 50%');
|
||||
// ambiguous old label must NOT be present
|
||||
expect(graph!.message).not.toMatch(/timeline 50%/);
|
||||
expect(graph!.message).not.toMatch(/timeline \(entity, brain score\)/);
|
||||
});
|
||||
|
||||
test('brain_score renders whole-brain density label 4/15', async () => {
|
||||
await seedFourPages(engine);
|
||||
const checks = await buildChecks(engine, [], null);
|
||||
const brain = checks.find((c) => c.name === 'brain_score');
|
||||
expect(brain, 'brain_score check must be present').toBeDefined();
|
||||
expect(brain!.message).toContain('timeline density (all pages) 4/15');
|
||||
// wrong labels must NOT be present
|
||||
expect(brain!.message).not.toMatch(/timeline 4\/15/);
|
||||
expect(brain!.message).not.toMatch(/timeline \(entity, brain score\)/);
|
||||
// brain-score component must NOT carry the word "entity" (it is whole-brain)
|
||||
const timelinePart = brain!.message.split('timeline density (all pages) 4/15')[0] + 'timeline density (all pages) 4/15';
|
||||
expect(timelinePart).not.toMatch(/entity/);
|
||||
});
|
||||
});
|
||||
|
||||
describe('issue #2298 — CLI get_health rendered-output contract', () => {
|
||||
function fakeHealth(overrides: Record<string, unknown>): any {
|
||||
return {
|
||||
embed_coverage: 1, missing_embeddings: 0, stale_pages: 0, orphan_pages: 0,
|
||||
link_coverage: 1, timeline_coverage: 0.5, timeline_coverage_score: 4,
|
||||
most_connected: [], ...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
test('both entity and whole-brain lines render, no undefined/15', () => {
|
||||
const out = formatResult('get_health', fakeHealth({}));
|
||||
expect(out).toContain('Timeline coverage (entity pages): 50.0%');
|
||||
expect(out).toContain('Timeline density (all pages): 4/15');
|
||||
expect(out).not.toContain('undefined/15');
|
||||
expect(out).not.toContain('Timeline coverage (entities)');
|
||||
expect(out).not.toMatch(/timeline \(entity, brain score\)/);
|
||||
expect(out).not.toMatch(/bare "timeline 4\/15"/);
|
||||
});
|
||||
|
||||
test('guard matrix: entity present, whole-brain absent -> only entity line', () => {
|
||||
const out = formatResult('get_health', fakeHealth({ timeline_coverage_score: undefined }));
|
||||
expect(out).toContain('Timeline coverage (entity pages): 50.0%');
|
||||
expect(out).not.toContain('Timeline density (all pages)');
|
||||
expect(out).not.toContain('undefined/15');
|
||||
});
|
||||
|
||||
test('guard matrix: whole-brain present, entity absent -> only whole-brain line', () => {
|
||||
const out = formatResult('get_health', fakeHealth({ timeline_coverage: undefined }));
|
||||
expect(out).toContain('Timeline density (all pages): 4/15');
|
||||
expect(out).not.toContain('Timeline coverage (entity pages)');
|
||||
expect(out).not.toContain('undefined/15');
|
||||
});
|
||||
|
||||
test('guard matrix: both absent -> neither timeline line, never undefined/15', () => {
|
||||
const out = formatResult('get_health', fakeHealth({ timeline_coverage: undefined, timeline_coverage_score: undefined }));
|
||||
expect(out).not.toContain('Timeline coverage (entity pages)');
|
||||
expect(out).not.toContain('Timeline density (all pages)');
|
||||
expect(out).not.toContain('undefined/15');
|
||||
});
|
||||
});
|
||||
@@ -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