mirror of
https://github.com/garrytan/gbrain.git
synced 2026-07-29 19:01:39 +00:00
Replaces the T9-shipped stub modules with working LLM-driven phase
bodies. v0.41 ships the right SHAPE — Haiku per transcript producing
1-3 atoms, atoms grouped by concept frontmatter ref, tier assignment
by count, Sonnet narrative for T1/T2. The richer 3-check quality gate
(truism/punchline/entity multi-pass), embedding-similarity dedup, voice
gate integration, op_checkpoint resumability all land in v0.41.1+ —
filed as inline TODOs and plan follow-ups.
T5 extract_atoms (src/core/cycle/extract-atoms.ts):
- Takes transcripts via _transcripts test seam OR discoverTranscripts
production path (lazy-imports transcript-discovery.ts to avoid
circular module loads through cycle.ts).
- Per transcript: ONE Haiku call with the 11-value atom_type enum
embedded in the prompt (matches gbrain-creator.yaml declaration;
v0.42 reads from active pack manifest at runtime per D11).
- parseAtomsResponse tolerates markdown fences + trailing prose;
rejects invalid atom_type values; clamps virality_score to [0,100];
rejects malformed entries silently (skip don't crash).
- Per atom: putPage atom-typed page under atoms/{YYYY-MM-DD}/
{slug-from-title}. Frontmatter preserves atom_type, source_quote,
lesson, virality_score, emotional_register from the LLM output.
- Budget cap $0.30/source/run (DEFAULT_BUDGET_USD); over-budget
transcripts counted as budget-skipped, phase returns status='warn'
if any failures occurred.
- Source-scoped: opts.sourceId routes corpus dir + write target.
- dry-run: counts but doesn't writePages.
- Failures tracked per-transcript without halting the run.
T6 synthesize_concepts (src/core/cycle/synthesize-concepts.ts):
- Takes atoms via _atoms test seam OR DB query for type='atom' pages
excluding imported_from frontmatter marker (D7 skip).
- Groups atoms by frontmatter `concepts:` array ref.
- Tier by count: T1 >=10, T2 >=5, T3 >=2, T4 deferred (no <2 groups).
- T1/T2 groups: Sonnet call with up to 10 sample titles + 5 sample
bodies → 1-paragraph narrative. Budget cap $1.50/run; over-budget
or LLM-failed groups fall back to deterministic narrative.
- T3 groups: deterministic narrative (no LLM call).
- Per group: putPage concept-typed page at concepts/{title-from-slug}
with tier + mention_count + composite_score frontmatter.
- dry-run + yieldDuringPhase honored.
Tests (test/cycle/extract-atoms-synthesize-concepts.test.ts, 19 cases):
parseAtomsResponse: well-formed JSON, markdown fences stripped,
trailing prose tolerated, invalid atom_type rejected, missing fields
rejected, garbage returns [], all 11 atom_type values accepted,
virality_score clamped to [0,100].
runPhaseExtractAtoms: no-op without transcripts, extracts via stub
chat + writes pages, dry-run counts without writing, failures
tracked per-transcript without halting.
runPhaseSynthesizeConcepts: no-op without atoms, groups by concept
ref + tier assignment by count (T1=12 atoms, T2=6, T3=3), atoms
without concept refs filtered out, <T3 threshold (1 atom) filtered,
T3 uses deterministic (no LLM call), dry-run counts without writing,
T1 narrative comes from LLM stub verbatim.
All 19 pass; typecheck clean.
Plan: ~/.claude/plans/system-instruction-you-are-working-toasty-milner.md
Tasks T5 + T6 of 13. v0.41.1 follow-ups inline:
- extract_atoms: read atom_type enum from active pack at runtime (D11)
- extract_atoms: 3-check quality gate as multi-pass refinement
- synthesize_concepts: embedding-similarity dedup (currently exact-
string concept ref match only)
- synthesize_concepts: voice gate for T1 Canon narratives
- Both: op_checkpoint resumability for cross-cycle continuation
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>