mirror of
https://github.com/garrytan/gbrain.git
synced 2026-08-17 10:22:34 +00:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
00ebc5bb61 |
+1
-18
@@ -509,12 +509,8 @@ export function extractTimelineFromContent(content: string, slug: string): Extra
|
||||
// DB-level uniqueness cannot collapse.
|
||||
const citationPattern = /\[Source:\s*([^\]]+?),\s*(\d{4}-\d{2}-\d{2})\s*\]/g;
|
||||
const bulletLinePattern = /^-\s+\*\*\d{4}-\d{2}-\d{2}\*\*\s*\|/;
|
||||
// Lines captured by Format 4 (plain bullet) are skipped for the same
|
||||
// reason: quality.md mandates a trailing [Source: ...] on those bullets,
|
||||
// and re-extracting the citation would double-count the event.
|
||||
const plainBulletLinePattern = /^-\s+\d{4}-\d{2}-\d{2}\s*[—–-]/;
|
||||
for (const line of content.split(/\r?\n/)) {
|
||||
if (bulletLinePattern.test(line) || plainBulletLinePattern.test(line)) continue;
|
||||
if (bulletLinePattern.test(line)) continue;
|
||||
const lineMatches = [...line.matchAll(citationPattern)];
|
||||
if (lineMatches.length === 0) continue;
|
||||
// Strip every citation marker from the line to leave the annotated text.
|
||||
@@ -530,19 +526,6 @@ export function extractTimelineFromContent(content: string, slug: string): Extra
|
||||
}
|
||||
}
|
||||
|
||||
// Format 4: Plain bullet — - YYYY-MM-DD — Summary
|
||||
// This is the format gbrain's own enrich skill writes (no bold, no source
|
||||
// pipe). Without it, every brain-authored timeline entry is invisible to
|
||||
// extraction and timeline_coverage stays at 0%. Anchored at line start so a
|
||||
// date inside a summary/link cannot start a spurious entry; a bold Format-1
|
||||
// line (`- **…**`) cannot match here (a `*` follows the bullet, not a
|
||||
// digit), and the citation loop above skips these lines, so a plain bullet
|
||||
// carrying its own [Source: ...] files exactly one entry.
|
||||
const plainBulletPattern = /^-\s+(\d{4}-\d{2}-\d{2})\s*[—–-]\s*(.+)$/gm;
|
||||
while ((match = plainBulletPattern.exec(content)) !== null) {
|
||||
entries.push({ slug, date: match[1], source: 'markdown', summary: match[2].trim() });
|
||||
}
|
||||
|
||||
return entries;
|
||||
}
|
||||
|
||||
|
||||
@@ -35,10 +35,11 @@
|
||||
*
|
||||
* The doctor renders both side by side.
|
||||
*
|
||||
* Drift contract: every check name that ships in doctor.ts MUST appear in
|
||||
* Drift contract: every check name that ships through doctor MUST appear in
|
||||
* exactly one set below. The drift-guard test in
|
||||
* `test/doctor-categories.test.ts` enforces this by reading doctor.ts source
|
||||
* via a tagged-string scan and asserting set membership exactly.
|
||||
* `test/doctor-categories.test.ts` enforces this by reading doctor check
|
||||
* emitter sources via a tagged-string scan and asserting set membership
|
||||
* exactly.
|
||||
*
|
||||
* If you add a new doctor check, you MUST add its name to the appropriate
|
||||
* set here. The categorize step in `src/commands/doctor.ts` falls through
|
||||
@@ -67,12 +68,15 @@ export const BRAIN_CHECK_NAMES: ReadonlySet<string> = new Set([
|
||||
'conversation_parser_probe_health',
|
||||
'cross_modal_modality_backfill',
|
||||
'cycle_freshness',
|
||||
'dangling_aliases',
|
||||
'effective_date_health',
|
||||
'embed_staleness',
|
||||
'embedding_column_registry',
|
||||
'embedding_env_override',
|
||||
'embedding_provider',
|
||||
'embedding_width_consistency',
|
||||
'embeddings',
|
||||
'entity_link_coverage',
|
||||
'eval_drift',
|
||||
'extract_atoms_backlog',
|
||||
'extract_health',
|
||||
@@ -102,7 +106,9 @@ export const BRAIN_CHECK_NAMES: ReadonlySet<string> = new Set([
|
||||
'stub_guard_24h',
|
||||
'sync_failures',
|
||||
'sync_freshness',
|
||||
'takes_count',
|
||||
'takes_weight_grid',
|
||||
'timeline_coverage',
|
||||
'unified_multimodal_coverage',
|
||||
'voice_gate_health',
|
||||
]);
|
||||
@@ -170,12 +176,14 @@ export const META_CHECK_NAMES: ReadonlySet<string> = new Set([
|
||||
'eval_capture',
|
||||
'minions_migration',
|
||||
'multi_source_drift',
|
||||
'pack_upgrade_available',
|
||||
'schema_pack_active',
|
||||
'schema_pack_consistency',
|
||||
'schema_pack_source_drift',
|
||||
'schema_version',
|
||||
'slug_fallback_audit',
|
||||
'timeline_dedup_index',
|
||||
'type_proliferation',
|
||||
'upgrade_errors',
|
||||
]);
|
||||
|
||||
|
||||
@@ -1103,11 +1103,6 @@ export interface TimelineCandidate {
|
||||
// Match: `- **YYYY-MM-DD** | summary` or `- **YYYY-MM-DD** -- summary`
|
||||
// or `- **YYYY-MM-DD** - summary` or just `**YYYY-MM-DD** | summary`.
|
||||
const TIMELINE_LINE_RE = /^\s*-?\s*\*\*(\d{4}-\d{2}-\d{2})\*\*\s*[|\-–—]+\s*(.+?)\s*$/;
|
||||
// Plain bullet: `- YYYY-MM-DD — summary` (no bold, no source pipe). Kept in
|
||||
// sync with extractTimelineFromContent's Format 4 (the fs-source path).
|
||||
// Anchored flush-left so a date inside an indented continuation line cannot
|
||||
// start a spurious entry.
|
||||
const PLAIN_TIMELINE_LINE_RE = /^-\s+(\d{4}-\d{2}-\d{2})\s*[—–-]\s*(.+?)\s*$/;
|
||||
|
||||
/**
|
||||
* Parse timeline entries from content. Looks at:
|
||||
@@ -1124,7 +1119,7 @@ export function parseTimelineEntries(content: string): TimelineCandidate[] {
|
||||
|
||||
let i = 0;
|
||||
while (i < lines.length) {
|
||||
const m = TIMELINE_LINE_RE.exec(lines[i]) ?? PLAIN_TIMELINE_LINE_RE.exec(lines[i]);
|
||||
const m = TIMELINE_LINE_RE.exec(lines[i]);
|
||||
if (!m) {
|
||||
i++;
|
||||
continue;
|
||||
@@ -1141,7 +1136,7 @@ export function parseTimelineEntries(content: string): TimelineCandidate[] {
|
||||
let j = i + 1;
|
||||
while (j < lines.length) {
|
||||
const next = lines[j];
|
||||
if (TIMELINE_LINE_RE.test(next) || PLAIN_TIMELINE_LINE_RE.test(next)) break;
|
||||
if (TIMELINE_LINE_RE.test(next)) break;
|
||||
if (/^#{1,6}\s/.test(next)) break;
|
||||
if (next.trim().length === 0 && detailLines.length === 0) {
|
||||
// skip leading blank line; if we hit a blank after detail content
|
||||
@@ -1171,7 +1166,7 @@ export function parseTimelineEntries(content: string): TimelineCandidate[] {
|
||||
// bullet pass are skipped (a bullet often carries its own citation).
|
||||
const citationRe = /\[Source:\s*([^\]]+?),\s*(\d{4}-\d{2}-\d{2})\s*\]/g;
|
||||
for (const line of lines) {
|
||||
if (TIMELINE_LINE_RE.test(line) || PLAIN_TIMELINE_LINE_RE.test(line)) continue;
|
||||
if (TIMELINE_LINE_RE.test(line)) continue;
|
||||
const matches = [...line.matchAll(citationRe)];
|
||||
if (matches.length === 0) continue;
|
||||
const summary = line
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
/**
|
||||
* Drift guard for src/core/doctor-categories.ts.
|
||||
*
|
||||
* Reads src/commands/doctor.ts source via a literal-string scan, enumerates
|
||||
* every `name: '<...>'` Check name, and asserts each appears in exactly ONE
|
||||
* category set. The union of the four sets must equal the discovered names
|
||||
* exactly — no orphans, no extras.
|
||||
* Reads doctor check emitter source via a literal-string scan, enumerates every
|
||||
* `name: '<...>'` Check name, and asserts each appears in exactly ONE category
|
||||
* set. The union of the four sets must equal the discovered names exactly —
|
||||
* no orphans, no extras.
|
||||
*
|
||||
* This is the structural failure the v0.41.19.0 plan-eng-review caught:
|
||||
* doctor.ts grows new checks regularly; without this guard, the
|
||||
@@ -25,26 +25,30 @@ import {
|
||||
} from '../src/core/doctor-categories.ts';
|
||||
|
||||
const DOCTOR_TS_PATH = join(import.meta.dir, '..', 'src', 'commands', 'doctor.ts');
|
||||
const ONBOARD_CHECKS_TS_PATH = join(import.meta.dir, '..', 'src', 'core', 'onboard', 'checks.ts');
|
||||
const CHECK_SOURCE_PATHS = [DOCTOR_TS_PATH, ONBOARD_CHECKS_TS_PATH];
|
||||
|
||||
function enumerateCheckNames(): Set<string> {
|
||||
const source = readFileSync(DOCTOR_TS_PATH, 'utf-8');
|
||||
const names = new Set<string>();
|
||||
// 1) Inline object-literal form: `{ name: 'foo', ... }`.
|
||||
for (const m of source.matchAll(/name:\s*['"]([a-z][a-z0-9_]+)['"]/g)) {
|
||||
names.add(m[1]);
|
||||
}
|
||||
// 2) Helper-function form: `const name = 'foo';` inside a check helper.
|
||||
// Catches checks like `nightly_quality_probe_health` and
|
||||
// `conversation_facts_backlog` that build the Check from a captured
|
||||
// name constant.
|
||||
for (const m of source.matchAll(/const\s+name\s*=\s*['"]([a-z][a-z0-9_]+)['"]/g)) {
|
||||
names.add(m[1]);
|
||||
for (const path of CHECK_SOURCE_PATHS) {
|
||||
const source = readFileSync(path, 'utf-8');
|
||||
// 1) Inline object-literal form: `{ name: 'foo', ... }`.
|
||||
for (const m of source.matchAll(/name:\s*['"]([a-z][a-z0-9_]+)['"]/g)) {
|
||||
names.add(m[1]);
|
||||
}
|
||||
// 2) Helper-function form: `const name = 'foo';` inside a check helper.
|
||||
// Catches checks like `nightly_quality_probe_health` and
|
||||
// `conversation_facts_backlog` that build the Check from a captured
|
||||
// name constant.
|
||||
for (const m of source.matchAll(/const\s+name\s*=\s*['"]([a-z][a-z0-9_]+)['"]/g)) {
|
||||
names.add(m[1]);
|
||||
}
|
||||
}
|
||||
return names;
|
||||
}
|
||||
|
||||
describe('doctor-categories drift guard', () => {
|
||||
test('every check name in doctor.ts source belongs to exactly one category set', () => {
|
||||
test('every doctor-emitted check name belongs to exactly one category set', () => {
|
||||
const discovered = enumerateCheckNames();
|
||||
const allCategorized = new Set<string>([
|
||||
...BRAIN_CHECK_NAMES,
|
||||
@@ -59,7 +63,7 @@ describe('doctor-categories drift guard', () => {
|
||||
}
|
||||
if (missing.length > 0) {
|
||||
throw new Error(
|
||||
`These check names appear in doctor.ts but are not categorized in ` +
|
||||
`These check names appear in doctor check emitters but are not categorized in ` +
|
||||
`src/core/doctor-categories.ts: ${missing.sort().join(', ')}. ` +
|
||||
`Add each to BRAIN/SKILL/OPS/META_CHECK_NAMES.`,
|
||||
);
|
||||
@@ -86,7 +90,7 @@ describe('doctor-categories drift guard', () => {
|
||||
expect(dupes).toEqual([]);
|
||||
});
|
||||
|
||||
test('every categorized name is currently used in doctor.ts source (no stale entries)', () => {
|
||||
test('every categorized name is currently used in doctor check emitters (no stale entries)', () => {
|
||||
const discovered = enumerateCheckNames();
|
||||
const allCategorized = new Set<string>([
|
||||
...BRAIN_CHECK_NAMES,
|
||||
@@ -124,6 +128,14 @@ describe('categorizeCheck', () => {
|
||||
expect(categorizeCheck('sync_freshness')).toBe('brain');
|
||||
});
|
||||
|
||||
test('returns the right category for onboard data-quality check names', () => {
|
||||
expect(categorizeCheck('embed_staleness')).toBe('brain');
|
||||
expect(categorizeCheck('entity_link_coverage')).toBe('brain');
|
||||
expect(categorizeCheck('timeline_coverage')).toBe('brain');
|
||||
expect(categorizeCheck('takes_count')).toBe('brain');
|
||||
expect(categorizeCheck('dangling_aliases')).toBe('brain');
|
||||
});
|
||||
|
||||
test('returns the right category for a known skill name', () => {
|
||||
expect(categorizeCheck('resolver_health')).toBe('skill');
|
||||
expect(categorizeCheck('skill_conformance')).toBe('skill');
|
||||
@@ -140,6 +152,24 @@ describe('categorizeCheck', () => {
|
||||
expect(categorizeCheck('upgrade_errors')).toBe('meta');
|
||||
});
|
||||
|
||||
test('returns the right category for onboard schema-pack check names without warning', () => {
|
||||
const originalWrite = process.stderr.write.bind(process.stderr);
|
||||
const captured: string[] = [];
|
||||
(process.stderr as { write: typeof process.stderr.write }).write = ((
|
||||
chunk: string | Uint8Array,
|
||||
) => {
|
||||
captured.push(typeof chunk === 'string' ? chunk : Buffer.from(chunk).toString());
|
||||
return true;
|
||||
}) as typeof process.stderr.write;
|
||||
try {
|
||||
expect(categorizeCheck('pack_upgrade_available')).toBe('meta');
|
||||
expect(categorizeCheck('type_proliferation')).toBe('meta');
|
||||
expect(captured.filter((c) => c.includes('[doctor-categories]'))).toEqual([]);
|
||||
} finally {
|
||||
(process.stderr as { write: typeof process.stderr.write }).write = originalWrite;
|
||||
}
|
||||
});
|
||||
|
||||
test('unknown check name falls through to meta with a stderr warn (once per process)', () => {
|
||||
const originalWrite = process.stderr.write.bind(process.stderr);
|
||||
const captured: string[] = [];
|
||||
|
||||
@@ -185,49 +185,6 @@ describe('extractTimelineFromContent', () => {
|
||||
expect(entries).toHaveLength(1);
|
||||
expect(entries[0].summary).toBe('Landed the enterprise pilot with acme-example.');
|
||||
});
|
||||
|
||||
// Format 4: the plain bullet `- YYYY-MM-DD — Summary` that gbrain's own
|
||||
// enrich skill writes. Before this was supported, every brain-authored
|
||||
// timeline entry was invisible and timeline_coverage was stuck at 0%.
|
||||
it('extracts plain bullet format (- YYYY-MM-DD — Summary)', () => {
|
||||
const content = `## Timeline\n- 2026-06-01 — Catch-up call with alice-example; intros offered.`;
|
||||
const entries = extractTimelineFromContent(content, 'people/alice-example');
|
||||
expect(entries).toHaveLength(1);
|
||||
expect(entries[0].date).toBe('2026-06-01');
|
||||
expect(entries[0].source).toBe('markdown');
|
||||
expect(entries[0].summary).toBe('Catch-up call with alice-example; intros offered.');
|
||||
});
|
||||
|
||||
it('files exactly one entry for a plain bullet that carries its own citation', () => {
|
||||
// quality.md mandates this shape; it must not double-count via the
|
||||
// citation arm (Format 3) AND the plain-bullet arm (Format 4).
|
||||
const content = `- 2026-05-31 — Confirmed full name. [Source: User, 2026-05-31]`;
|
||||
const entries = extractTimelineFromContent(content, 'people/charlie-example');
|
||||
expect(entries).toHaveLength(1);
|
||||
expect(entries[0].date).toBe('2026-05-31');
|
||||
expect(entries[0].source).toBe('markdown');
|
||||
expect(entries[0].summary).toContain('Confirmed full name.');
|
||||
});
|
||||
|
||||
it('does not double-count bold (Format 1) lines as plain bullets', () => {
|
||||
const content = `- **2025-03-18** | Meeting — Discussed partnership`;
|
||||
const entries = extractTimelineFromContent(content, 'test');
|
||||
expect(entries).toHaveLength(1);
|
||||
expect(entries[0].source).toBe('Meeting');
|
||||
});
|
||||
|
||||
it('does not start a spurious entry from a date inside a summary', () => {
|
||||
const content = `- 2026-06-01 — See [meeting](meetings/2026-06-01).`;
|
||||
const entries = extractTimelineFromContent(content, 'people/alice-example');
|
||||
expect(entries).toHaveLength(1);
|
||||
expect(entries[0].date).toBe('2026-06-01');
|
||||
});
|
||||
|
||||
it('handles en dash and hyphen separators in plain bullets', () => {
|
||||
const content = `- 2026-06-01 – First\n- 2026-06-02 - Second`;
|
||||
const entries = extractTimelineFromContent(content, 'test');
|
||||
expect(entries).toHaveLength(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe('walkMarkdownFiles', () => {
|
||||
|
||||
@@ -720,30 +720,6 @@ More prose here.
|
||||
const entries = parseTimelineEntries(content);
|
||||
expect(entries.length).toBe(2);
|
||||
});
|
||||
|
||||
// Plain bullet (extract.ts Format 4 parity — the db-source path must see
|
||||
// the same entries as the fs-source path).
|
||||
test('parses plain bullet: - YYYY-MM-DD — summary', () => {
|
||||
const entries = parseTimelineEntries('## Timeline\n- 2026-06-01 — Catch-up call with alice-example');
|
||||
expect(entries.length).toBe(1);
|
||||
expect(entries[0].date).toBe('2026-06-01');
|
||||
expect(entries[0].summary).toBe('Catch-up call with alice-example');
|
||||
});
|
||||
|
||||
test('files exactly one entry for a plain bullet carrying its own citation', () => {
|
||||
const entries = parseTimelineEntries('- 2026-05-31 — Confirmed full name. [Source: User, 2026-05-31]');
|
||||
expect(entries.length).toBe(1);
|
||||
expect(entries[0].date).toBe('2026-05-31');
|
||||
});
|
||||
|
||||
test('skips invalid dates in plain bullets', () => {
|
||||
expect(parseTimelineEntries('- 2026-13-45 — Bad date').length).toBe(0);
|
||||
});
|
||||
|
||||
test('does not double-count a bold bullet as a plain bullet', () => {
|
||||
const entries = parseTimelineEntries('- **2026-01-15** | Met with Alice');
|
||||
expect(entries.length).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
// ─── isAutoLinkEnabled ─────────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user