Generate writing tasks from BRD structure and corpus, creating chapter/section tasks with dependencies, pre-write queries, and consistency checks
Analyze the Book Requirements Document (BRD) structure and existing corpus to generate prioritized writing tasks with full metadata, dependencies, and consistency checks.
Transform the BRD outline into executable writing tasks, each specifying required knowledge, pre-write database queries, post-write storage operations, and consistency constraints. Tasks are generated with dependencies (blockedBy relationships) to ensure proper writing order.
This command delegates the planning work to the outline-planner agent.
None. This command reads from the database:
Query the database to retrieve the Book Requirements Document:
# Query BRD from database
surreal sql --conn http://localhost:2665 \
--user root --pass root \
--ns bookstrap --db <database-name> \
--query "SELECT * FROM brd ORDER BY version DESC LIMIT 1;"
Extract structural requirements:
Check what knowledge exists to support each planned section:
-- Coverage by planned chapter/topic
SELECT chapter, count() as sources
FROM section->cites->source
GROUP BY chapter;
-- Entity availability
SELECT * FROM character;
SELECT * FROM location;
SELECT * FROM event ORDER BY sequence;
SELECT * FROM concept;
-- Resolved knowledge gaps
SELECT * FROM knowledge_gap
WHERE resolved = true;
-- Source distribution
SELECT source_type, reliability, count() as total
FROM source
GROUP BY source_type, reliability;
-- Timeline completeness
SELECT sequence, count() as events
FROM event
GROUP BY sequence
ORDER BY sequence;
For each chapter/section in the BRD, create a writing task with comprehensive metadata:
{
"taskId": "chapter-3-scene-2",
"subject": "Write Chapter 3, Scene 2: The Confrontation",
"description": "Write the confrontation scene between Anna and Erik at the safehouse, revealing the betrayal and establishing the stakes for the final act.",
"blockedBy": ["chapter-3-scene-1"],
"metadata": {
"chapter": 3,
"section": 2,
"sequence": 12,
"target_words": 2500,
"scene_type": "dialogue_heavy",
"required_knowledge": [
"character:anna.background",
"character:anna.status",
"character:erik.background",
"character:erik.relationships",
"location:safehouse.description",
"location:safehouse.introduced",
"event:discovery.details",
"event:discovery.sequence",
"concept:betrayal_theme"
],
"pre_queries": [
"SELECT * FROM section WHERE embedding <|5|> $theme_vector ORDER BY vector::similarity(embedding, $theme_vector) DESC",
"SELECT * FROM character:anna->knows->character",
"SELECT * FROM character:erik->knows->character",
"SELECT * FROM event WHERE sequence < 12 ORDER BY sequence DESC LIMIT 5",
"SELECT * FROM section WHERE chapter = 3 AND sequence < 2 ORDER BY sequence"
],
"post_writes": [
"CREATE section SET content=$content, embedding=$vec, chapter=3, sequence=12, word_count=$word_count, status='draft'",
"RELATE character:anna->confronts->character:erik SET context=$confrontation_context",
"RELATE event:confrontation->follows->event:discovery SET narrative_link=true",
"RELATE section:$section_id->cites->source:$source_ids",
"RELATE section:$section_id->appears_in<-character:anna",
"RELATE section:$section_id->appears_in<-character:erik",
"RELATE section:$section_id->located_in->location:safehouse"
],
"consistency_checks": [
"character:anna.status != 'dead'",
"character:erik.status != 'dead'",
"location:safehouse.introduced = true",
"event:discovery.sequence < 12",
"character:anna->knows->character:erik EXISTS"
],
"voice_requirements": {
"pov": "third_limited",
"tense": "past",
"tone": "tense_suspenseful",
"comparable": "tension like le Carré"
}
}
}
Establish blockedBy relationships based on:
Sequential Dependencies:
Knowledge Dependencies:
Graph Dependencies:
For each task, list the entities and facts that MUST exist in the database before writing:
"required_knowledge": [
"character:protagonist_id.name",
"character:protagonist_id.description",
"character:protagonist_id.background",
"character:protagonist_id.status",
"location:setting_id.description",
"location:setting_id.introduced",
"event:prior_event_id.sequence",
"concept:theme_id.description"
]
If any required knowledge is missing, the task should be flagged as blocked by a knowledge gap.
For each task, specify the database queries to run BEFORE writing to gather context:
Semantic Search Queries:
-- Find thematically similar passages
SELECT * FROM section
WHERE embedding <|5|> $theme_vector
ORDER BY vector::similarity(embedding, $theme_vector) DESC;
-- Find related concepts
SELECT * FROM concept
WHERE embedding <|3|> $concept_vector;
Graph Traversal Queries:
-- Character relationships
SELECT * FROM character:$char_id->knows->character;
SELECT * FROM character:$char_id<-appears_in<-section ORDER BY sequence;
-- Source support
SELECT * FROM source WHERE ->supports->concept:$concept_id;
-- Location context
SELECT * FROM location:$loc_id<-located_in<-section;
Timeline Queries:
-- Prior events
SELECT * FROM event
WHERE sequence < $current_sequence
ORDER BY sequence DESC
LIMIT 5;
-- Chronological section order
SELECT * FROM section
WHERE chapter = $chapter AND sequence < $current_sequence
ORDER BY sequence;
For each task, define the database operations to execute AFTER writing:
Content Storage:
CREATE section SET
content = $content,
embedding = $embedding_vector,
chapter = $chapter_num,
sequence = $section_num,
word_count = $word_count,
status = 'draft',
created_at = time::now();
Entity Extraction and Creation:
-- Extract and create new entities mentioned in the section
-- (Performed by writer agent using LLM entity extraction)
-- Link existing entities
RELATE section:$section_id->appears_in<-character:$char_ids;
RELATE section:$section_id->located_in->location:$loc_ids;
Relationship Creation:
-- Character interactions
RELATE character:$char1->interacts_with->character:$char2
SET context = $interaction_description;
-- Event sequencing
RELATE event:$event_id->follows->event:$prior_event_id;
Source Citations:
-- Link to supporting sources
RELATE section:$section_id->cites->source:$source_ids
SET claim = $cited_claim;
Timeline Updates:
-- Update event sequence
UPDATE event:$event_id SET sequence = $sequence_num;
For each task, specify constraints that MUST be true before writing:
Entity State Checks: