@@ -347,6 +347,29 @@ def _record_author(uid: str, author: str | None) -> None:
347347
348348
349349# ── Setup (human picks a direction, then autonomous) ─────────────────────────
350+ def _base_run_state (uid , abstract , * , intake , author , max_revisions , autonomous , humanize ,
351+ settings ) -> dict :
352+ """Run-state keys shared by every project (book + article). Callers spread this and add
353+ the mode-specific keys (the id, phase, unit counter, and any per-mode quality flags)."""
354+ return {
355+ "uid" : uid , "abstract" : abstract ,
356+ "intake" : intake or "" , "author" : author or "" ,
357+ "max_revisions" : max_revisions , "committed" : 0 , "pending_review" : False ,
358+ "use_researcher" : settings .use_researcher ,
359+ "deep_research" : settings .deep_research ,
360+ "autonomous" : autonomous ,
361+ "humanize" : settings .humanize if humanize is None else humanize ,
362+ "use_images" : settings .use_images ,
363+ "diagram_engine" : settings .diagram_engine ,
364+ "use_embeddings" : settings .use_embeddings ,
365+ "divergent_drafts" : settings .divergent_drafts ,
366+ "tournament_judge" : settings .tournament_judge ,
367+ "min_insight" : settings .min_insight ,
368+ # Autonomous runs never pause on low confidence.
369+ "escalate_below_confidence" : 0.0 if autonomous else settings .escalate_below_confidence ,
370+ }
371+
372+
350373def start_book (
351374 cfg : ModelConfig , settings : Settings , uid : str , abstract : str ,
352375 chosen : S .Direction , book_id_override : str | None ,
@@ -369,23 +392,14 @@ def start_book(
369392 brain .write_text (paths .toc , render .render_toc_md (toc ))
370393
371394 state = {
372- "uid" : uid , "book_id" : book_id , "abstract" : abstract ,
373- "intake" : intake or "" , "author" : author or "" ,
395+ ** _base_run_state (uid , abstract , intake = intake , author = author ,
396+ max_revisions = max_revisions , autonomous = autonomous ,
397+ humanize = humanize , settings = settings ),
398+ "book_id" : book_id ,
374399 "phase" : "chapters" , "num_chapters" : len (toc .chapters ),
375- "max_revisions" : max_revisions , "consolidate_every" : settings .consolidate_every ,
376- "current_chapter" : 1 , "committed" : 0 , "pending_review" : False ,
377- "use_researcher" : settings .use_researcher ,
378- "deep_research" : settings .deep_research ,
379- "autonomous" : autonomous ,
380- "humanize" : settings .humanize if humanize is None else humanize ,
381- "use_images" : settings .use_images ,
382- "diagram_engine" : settings .diagram_engine ,
383- "use_embeddings" : settings .use_embeddings ,
384- "divergent_drafts" : settings .divergent_drafts ,
385- "tournament_judge" : settings .tournament_judge ,
386- "min_insight" : settings .min_insight ,
387- # Autonomous runs never pause: no confidence/contradiction escalation.
388- "escalate_below_confidence" : 0.0 if autonomous else settings .escalate_below_confidence ,
400+ "consolidate_every" : settings .consolidate_every ,
401+ "current_chapter" : 1 ,
402+ # Autonomous runs never pause on contradictions either.
389403 "escalate_on_contradiction" : False if autonomous else settings .escalate_on_contradiction ,
390404 }
391405 brain .write_json (paths .run_state , state )
@@ -1593,30 +1607,19 @@ def start_article(
15931607 brain .write_text (paths .root / "thesis.md" , nodes .render_thesis (thesis ))
15941608
15951609 state = {
1596- "uid" : uid , "article_id" : article_id , "abstract" : abstract ,
1597- "intake" : intake or "" , "author" : author or "" ,
1598- "mode" : "article" ,
1610+ ** _base_run_state (uid , abstract , intake = intake , author = author ,
1611+ max_revisions = max_revisions , autonomous = autonomous ,
1612+ humanize = humanize , settings = settings ),
1613+ "article_id" : article_id , "mode" : "article" ,
15991614 "phase" : "sections" , "num_sections" : len (outline .sections ),
1600- "max_revisions" : max_revisions , "current_section" : 1 ,
1601- "committed" : 0 , "pending_review" : False ,
1602- "use_researcher" : settings .use_researcher ,
1603- "deep_research" : settings .deep_research ,
1604- "autonomous" : autonomous ,
1605- "humanize" : settings .humanize if humanize is None else humanize ,
1606- "use_images" : settings .use_images ,
1607- "diagram_engine" : settings .diagram_engine ,
1608- "use_embeddings" : settings .use_embeddings ,
1615+ "current_section" : 1 ,
16091616 "article_cohesion" : settings .article_cohesion ,
16101617 "strip_inline_citations" : settings .strip_inline_citations ,
16111618 "rank_references" : settings .rank_references ,
16121619 "table_read" : settings .table_read ,
16131620 "table_read_revise" : settings .table_read_revise ,
1614- "divergent_drafts" : settings .divergent_drafts ,
16151621 "divergent_skeletons" : settings .divergent_skeletons ,
1616- "tournament_judge" : settings .tournament_judge ,
16171622 "verify_claims" : settings .verify_claims ,
1618- "min_insight" : settings .min_insight ,
1619- "escalate_below_confidence" : 0.0 if autonomous else settings .escalate_below_confidence ,
16201623 "escalate_on_contradiction" : False ,
16211624 }
16221625 brain .write_json (paths .run_state , state )
0 commit comments