memory-literary-analysis

Analyze a complete literary work into a structured Basic Memory knowledge graph. Covers schema design, entity seeding, chapter-by-chapter processing, cross-referencing, validation, and graph exploration.

By basicmachines-co · 767 installs

npx skills add basicmachines-co/basic-memory --skill memory-literary-analysis

Source repository · Upstream listing

Memory Literary Analysis Transform a complete literary work into a structured knowledge graph. Characters, themes, chapters, locations, symbols, and literary devices become interconnected notes — searchable, validatable, and traversable. When to Use Analyzing a novel, play, poem, or non fiction book end to end Building a teaching or study resource for a literary text Creating a book club companion knowledge base Research projects requiring structured close reading Stress testing Basic Memory at scale (~200+ notes, 1000+ relations) Pipeline Overview Tools Writing always goes through write note and edit note . For reading — which is most of the work in a long analysis — prefer the POSIX read verbs where they are available ( enable posix tools for the MCP tools; the bm CLI verbs are always available): Need Use Instead of A section of a long note cat <note section Observations reading the whole note A line range of the source text cat <source .txt lines 4200 4890 pulling the whole book into context Notes matching frontmatter find meta status=active reading notes to check fields Fields across many notes find meta ... fields pov,setting one read per note Where something lives ls , tree , find name ' .md' listing everything The two rules that matter across a 100+ chapter run: Never read a note to check a field. That is what meta predicates and fields projection are for — one call answers what a read per note loop would cost. Never pull a whole file into context to reach one part of it. Sections and line ranges slice the output : the full note is still fetched, then cut down before it is returned. What they save is context, not I/O — a long chapter or a full source text costs you the tokens of the relevant part, not of the whole file. These compound. In measured runs, predicate queries replaced 28 call scans with a single call; across 138 chapters that difference is the run. Three sharp edges to know before you write a query. The first two fail quietly — a wrong answer, exit 0, no warning — so learn them here rather than from a graph you thought you had audited: meta matches case sensitively, and the stored value is always snake case. note type is an alias for the frontmatter type: key, compared with SQL = . write note normalizes note type through to snake case before writing, so a note authored as note type="Chapter" is stored as type: chapter — the casing you author with is not the casing on disk. Query the snake case form: meta 'note type=chapter' . The capitalized spelling returns zero rows and exit 0. The value a result row displays is the value to query with. find pages, and the default page is 10. Any query whose answer is "all N chapters" needs page size 200 (the maximum) — see [Coverage Checks]( coverage checks). name cannot combine with meta . The metadata search has no filename glob. Scope a meta query with the positional path instead: find /characters meta 'note type=character' . That path is matched on a directory boundary against the file path a note is indexed under — where the note actually lives, not its permalink, which stops mirroring the file path once a note pins permalink: in frontmatter or is moved. So /characters reaches everything filed under characters/ (including characters/major/ ), and never characters cut/ . If the POSIX verbs are unavailable, every step below still works with search notes , read note , and list directory — it just costs more. Phase 0: Setup Create the Project Use a kebab case slug of the work's title (e.g., great gatsby , hamlet , beloved ). Define Schemas Write 6 schema notes to schema/ . Each schema defines the entity type's fields, observation categories, and relation types. Adapt fields to fit the work — the schemas below are starting points, not rigid templates. Character Schema Add work specific fields as needed — e.g., rank for military fiction, house for family sagas, species for fantasy. Theme Schema Chapter Schema Location Schema Symbol Schema LiteraryDevice Schema Directory Structure Phase 1: Seed Entities Before processing chapters, create stub notes for major entities so [[wiki links]] resolve from the start. Characters (major) For each major character, create a stub with known metadata: Seed Checklist Identify the work's major entities before you start reading. A good starting inventory: Type Typical Count What to Include Characters (major) 8 20 Protagonist, antagonist, key supporting cast Themes 5 12 Central concerns the work explores Locations 4 10 Primary settings, symbolically significant places Symbols 4 10 Recurring objects, images, or motifs with layered meaning Stubs don't need to be complete — they give [[wiki link]] targets and will be enriched during chapter processing. Phase 2: Chapter Processing Source Text Preparation Obtain the full text and identify chapter/section boundaries. For public domain works, Project Gutenberg is a good source. For copyrighted works, work from a physical or licensed digital copy. Put the source text inside the project directory, as .txt , and index it once. bm cat resolves a note identifier , not a filesystem path — it can only reach a file the project index has observed. A one time index pass gives the raw text an entity row, after which the line range slice works against it: Two constraints that make this the right shape, both worth respecting: Keep it .txt , do not convert it to .md . Basic Memory injects frontmatter into markdown notes, which shifts every line number by the height of that block — an offset map built from the original file would then be silently wrong. A .txt is stored verbatim, so its line numbers stay 1:1 with the file on disk. Keep it inside the project. A source text elsewhere on disk is not an entity, and bm cat answers Error: Entity not found . If you must leave it outside, drop the BM verbs for the source and use plain shell ( sed n '4200,4890p' <path ) — the notes still get the BM verbs, only the raw source falls back to the shell. Then build a chapter offset map once, before processing. Scan the text for chapter headings and record the line range of each chapter, then read chapters by range rather than re reading the whole book into context: grep n here is the shell's grep on a filesystem path (this is the map building step, and it needs the file). bm cat then takes the note identifier and returns exactly that slice plus a lines 4200 4890 of N footer. Spell the identifier project qualified: <work /<work .txt . The bare moby dick.txt fails with names a project, not a note , because the prefix check drops the extension and the stem then equals the project name — which this layout guarantees ( 1458). bm head moby dick/moby dick.txt n 40 is the cheap way to eyeball the heading format before writing the grep pattern. Store the map in the project (a note or a small JSON file) so later batches — and a resumed run after context compaction — do not have to rediscover it. On a long work this is the single largest context saving in the pipeline. Batching Strategy Process ~10 chapters per batch to balance depth with progress. Group by narrative arc or thematic focus: Batch Typical Content 1 Opening: setting, character introductions, world building 2 3 Rising action: conflicts established, relationships develop 4 6 Middle: complications, turning points, thematic deepening 7 8 Climax approach: escalation, revelations, crises Final Climax, resolution, epilogue Adjust batch size based on chapter length and density. Short, action heavy chapters can be batched in larger groups; long, philosophically dense chapters may need smaller batches. Per Chapter Workflow For each chapter: 1. Read the chapter carefully. Read the chapter's line range from the offset map ( bm cat <source .txt lines <start <end ), not the whole file. Read the actual text — never work from memory or a summary; textual evidence is the entire point. 2. Create the chapter note: 3. Enrich related entities: 3b. After the first batch, check where the enrichment landed. On a 206 note graph built with this pipeline, every character's append under heading="Observations" had gone under Relations , and the prose prepends had landed above the H1, so cat <note section Observations returned the seed stub for every major character. One check catches it: Fix the heading discipline before batch two; a section read is only as good as the headings. 4. Track progress using the memory tasks skill to create a processing task that survives context compaction. What to Capture Per Chapter Category What to Look For [summary] 1 2 sentence chapter synopsis [event] Key plot events (actions, revelations, arrivals) [tone] Emotional and stylistic atmosphere [technique] Narrative innovations (POV shifts, structural experiments, genre blending) [quote] Memorable or thematically significant passages [significance] Why this chapter matters to the whole [foreshadowing] Hints at future events Entity Enrichment Per Chapter As each chapter is processed, append observations to relevant entities: Characters : [arc] moments, new [trait] revelations, [quote] attributions Themes : [manifestation] in this chapter, [evolution] shifts Symbols : [appearance] with context, new [interpretation] angles Locations : [atmosphere] as described, [significance] in scene Literary devices : [example] from this chapter Adding Prose and Interpretation After the structured observations are in place, consider adding interpretive prose to major entity notes. Prepend 2 4 paragraphs of critical essay before the Observations section using edit note(operation="prepend") . This prose should: Argue for a reading of the character, theme, or symbol — not just describe it Connect the entity to the work's larger concerns and to literary tradition Include subjective opinions clearly marked as such ("In my reading...", "I find...") Ground claims in textual evidence cited by chapter number The prose adds the interpretive texture that structured observations alone cannot capture. Phase 3: Cross Referencing After all chapters are processed: Find What Needs Enriching Do not re read every note to decide what is thin. Query for it: A field a note never set comes back as a blank cell ( null under json ), so rows with blanks are the work queue. This turns "audit the graph" from a read of every note into one call per question. Note the lowercase chapter / character — write note snake cases note type before the note is written, so that is the value on disk no matter how your Phase 0 schemas spelled it. Match it exactly; the capitalized spelling returns zero rows and exit 0. And page size 200 is not decoration: without it these return the first 10 rows and the work queue looks ten items long. Character Arcs For each major character, write a full [arc] summary observation covering their trajectory across the work. Theme Evolution For each theme, add [evolution] observations tracing how it develops from introduction to resolution. Chapter Parallels Add parallels and contrasts with relations between structurally similar chapters (e.g., mirrored scenes, repeated settings, thematic echoes). Analysis Notes Create synthesis notes in analysis/ : Recommended analysis notes: Narrative Structure — overall architecture and pacing Work Overview — synthesis of the complete work (summary, thesis, legacy) Critical Reception — hist