mirror of
https://github.com/garrytan/gbrain.git
synced 2026-07-28 14:59:47 +00:00
fix(extract): recognize plain-bullet timeline format as Format 4 (takeover of #1896)
Rebase of #1896 onto master: since it was opened, #2524 landed an inline-citation arm as Format 3 at the same insertion point, so the plain-bullet arm now lands as Format 4 and the citation loop's skip is extended to plain-bullet lines — a plain bullet carrying its own [Source: ...] citation (the shape quality.md mandates) files exactly one entry instead of double-counting. Co-authored-by: ElliotDrel <ElliotDrel@users.noreply.github.com> Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
ElliotDrel
Claude Fable 5
parent
0612b0daa8
commit
9efe229eee
+18
-1
@@ -509,8 +509,12 @@ 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)) continue;
|
||||
if (bulletLinePattern.test(line) || plainBulletLinePattern.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.
|
||||
@@ -526,6 +530,19 @@ 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;
|
||||
}
|
||||
|
||||
|
||||
@@ -185,6 +185,49 @@ 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', () => {
|
||||
|
||||
Reference in New Issue
Block a user