From 088acb5f8898042bfd59679e224c411794db7af1 Mon Sep 17 00:00:00 2001 From: John Taylor Date: Thu, 13 Aug 2026 00:11:39 -0400 Subject: [PATCH 1/6] =?UTF-8?q?docs:=20plan=20=E2=80=94=20unified=20inspir?= =?UTF-8?q?ation=20catalog=20(PR=203)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Fable 5 --- .../plans/2026-08-13-inspiration-catalog.md | 502 ++++++++++++++++++ 1 file changed, 502 insertions(+) create mode 100644 docs/superpowers/plans/2026-08-13-inspiration-catalog.md diff --git a/docs/superpowers/plans/2026-08-13-inspiration-catalog.md b/docs/superpowers/plans/2026-08-13-inspiration-catalog.md new file mode 100644 index 0000000..c4d6334 --- /dev/null +++ b/docs/superpowers/plans/2026-08-13-inspiration-catalog.md @@ -0,0 +1,502 @@ +# Unified Inspiration Catalog (PR 3 of streamline epic) Implementation Plan + +> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking. + +**Goal:** One browsable inspiration catalog: the 24 flavor generators, the bundled starter tables, and My Tables all appear — searchable and category-grouped — on Ask → Tables and in the GenerateSheet, with the starter-pack import step gone. + +**Architecture:** A pure `buildCatalog` merges three sources into `CatalogEntry` rows (generators read-only, starters read-only shipped as data via a new `starterTablesProvider`, user tables editable). The two surfaces render the same catalog with their existing visual idioms (expansion tiles / chips). All rolls keep the existing `addResult` pipeline and provenance tags. The oracle-data built-in table groups on the Tables tab already render grouped + searchable and are untouched. + +**Tech Stack:** Flutter + flutter_riverpod. Package name `loreseer`. + +**Spec:** `docs/superpowers/specs/2026-08-12-streamline-library-exclusive-capabilities-design.md` (Part 3) + +## Global Constraints + +- Provenance unchanged: generator rolls log `sourceTool: sourceToolFor(section)` (`gen-*`), table rolls (starter or user) log `sourceTool: 'custom-table'`. `PayloadCard` rendering and Inspire must keep working (`showLoggedSnackBar` after instant logs — only from hosts that stay mounted). +- Starters are read-only entries with STABLE ids (`starter-` by file order) — no editor, no delete. The one-tap "Add starter tables" import tile dies. Legacy users who already imported the pack must NOT see duplicates: a bundled starter is hidden when a user table with the same name AND `source == kStarterTableSource` exists. +- Bundled-asset load stays STRICT (repo doctrine): `starterTablesProvider` may throw on a malformed asset; only USER-persisted reads are tolerant. +- Widget tests: never hit rootBundle — override `starterTablesProvider` with a fixture list; pump `TablesScreen`/`GenerateSheet` the way their existing tests do (copy that scaffolding). +- Format only files you edit. + +--- + +### Task 1: Engine catalog + starter provider + +**Files:** +- Create: `lib/engine/inspiration_catalog.dart` +- Modify: `lib/state/providers.dart` (add `starterTablesProvider` near the other asset FutureProviders, e.g. after `dungeonDataProvider` ~line 79) +- Test: `test/inspiration_catalog_test.dart` + +**Interfaces:** +- Consumes: `GeneratorDef`/`GenSection`/`flavorGenerators` (`lib/engine/generator_registry.dart`), `CustomTable`/`decodeTablePack`/`kStarterTableSource`/`matchesTableQuery`/`kUncategorized` (`lib/engine/custom_table.dart`). +- Produces (used by Tasks 2–3): + - `enum CatalogKind { generator, table }` + - `class CatalogEntry { String id; String name; CatalogKind kind; String category; String genre; String source; bool editable; GeneratorDef? gen; CustomTable? table; }` + - `List buildCatalog({required List generators, required List starters, required List userTables})` + - `bool matchesCatalogQuery(CatalogEntry e, String q)` (lowercased q; name/genre/category/source) + - `List<(String, List)> groupCatalogByCategory(List entries)` (category-sorted, insertion order within) + - `final starterTablesProvider = FutureProvider>(...)` — loads `assets/starter_tables.json` via `decodeTablePack`, re-ids rows to stable `starter-`. + +- [ ] **Step 1: Write the failing test** + +```dart +// test/inspiration_catalog_test.dart +import 'package:flutter_test/flutter_test.dart'; +import 'package:loreseer/engine/custom_table.dart'; +import 'package:loreseer/engine/generator_registry.dart'; +import 'package:loreseer/engine/inspiration_catalog.dart'; + +CustomTable t(String id, String name, + {String cat = '', String genre = '', String src = ''}) => + CustomTable( + id: id, name: name, rows: const [], category: cat, genre: genre, + source: src); + +void main() { + test('buildCatalog merges three sources with right kinds/flags', () { + final cat = buildCatalog( + generators: flavorGenerators, + starters: [t('starter-0', 'Rumors', cat: 'Hooks', + src: kStarterTableSource)], + userTables: [t('u1', 'My monsters', cat: 'Foes')], + ); + expect(cat.where((e) => e.kind == CatalogKind.generator).length, + flavorGenerators.length); + final starter = cat.singleWhere((e) => e.id == 'starter-0'); + expect(starter.editable, isFalse); + expect(starter.kind, CatalogKind.table); + final mine = cat.singleWhere((e) => e.id == 'u1'); + expect(mine.editable, isTrue); + // Generators carry their section label as category. + expect(cat.firstWhere((e) => e.name == 'Word Oracle').category, + GenSection.story.label); + }); + + test('a bundled starter hides when the user already imported it', () { + final cat = buildCatalog( + generators: const [], + starters: [t('starter-0', 'Rumors', src: kStarterTableSource)], + userTables: [t('u9', 'Rumors', src: kStarterTableSource)], + ); + expect(cat.where((e) => e.name == 'Rumors').length, 1); + expect(cat.single.id, 'u9'); + }); + + test('matchesCatalogQuery spans name/genre/category/source', () { + final e = buildCatalog( + generators: const [], + starters: const [], + userTables: [t('u1', 'Wild beasts', cat: 'Foes', genre: 'fantasy', + src: 'homebrew')], + ).single; + for (final q in ['beast', 'foes', 'fantasy', 'homebrew']) { + expect(matchesCatalogQuery(e, q), isTrue, reason: q); + } + expect(matchesCatalogQuery(e, 'sci-fi'), isFalse); + }); + + test('groupCatalogByCategory sorts categories, keeps insertion order', () { + final groups = groupCatalogByCategory(buildCatalog( + generators: const [], + starters: const [], + userTables: [t('a', 'A', cat: 'Zed'), t('b', 'B', cat: 'Alpha'), + t('c', 'C', cat: 'Zed')], + )); + expect(groups.map((g) => g.$1).toList(), ['Alpha', 'Zed']); + expect(groups.last.$2.map((e) => e.name).toList(), ['A', 'C']); + }); +} +``` + +Note: verify `CustomTable`'s actual constructor (named params, `category`/`genre`/`source` field names) in `lib/engine/custom_table.dart` before running; adjust the `t` helper to match reality. If category default is `kUncategorized`, adjust the empty-category expectations accordingly. + +- [ ] **Step 2: Run to verify it fails** + +Run: `flutter test test/inspiration_catalog_test.dart` +Expected: FAIL — file missing. + +- [ ] **Step 3: Implement** + +```dart +// lib/engine/inspiration_catalog.dart +// +// One inspiration catalog over three sources: the flavor generators, the +// bundled read-only starter tables, and the user's My Tables. Both rolling +// surfaces (Ask → Tables, GenerateSheet) render this list, so a table or +// generator added in one place appears in both. Pure — no Flutter. +import 'custom_table.dart'; +import 'generator_registry.dart'; + +enum CatalogKind { generator, table } + +class CatalogEntry { + const CatalogEntry({ + required this.id, + required this.name, + required this.kind, + required this.category, + this.genre = '', + this.source = '', + this.editable = false, + this.gen, + this.table, + }); + final String id; + final String name; + final CatalogKind kind; + final String category; + final String genre; + final String source; + + /// True only for the user's own tables — the editor opens on these. + final bool editable; + final GeneratorDef? gen; // set when kind == generator + final CustomTable? table; // set when kind == table +} + +/// Merges the three sources. A bundled starter is dropped when the user +/// library already holds a table with the same name and starter source — +/// legacy libraries imported the pack via the old one-tap button, and the +/// user's (possibly edited) copy wins. +List buildCatalog({ + required List generators, + required List starters, + required List userTables, +}) { + final imported = { + for (final t in userTables) + if (t.source == kStarterTableSource) t.name, + }; + return [ + for (final g in generators) + CatalogEntry( + id: 'gen-${g.label.toLowerCase().replaceAll(' ', '-')}', + name: g.label, + kind: CatalogKind.generator, + category: g.section.label, + source: 'Built-in', + gen: g, + ), + for (final t in starters) + if (!imported.contains(t.name)) + CatalogEntry( + id: t.id, + name: t.name, + kind: CatalogKind.table, + category: t.category, + genre: t.genre, + source: t.source, + table: t, + ), + for (final t in userTables) + CatalogEntry( + id: t.id, + name: t.name, + kind: CatalogKind.table, + category: t.category, + genre: t.genre, + source: t.source, + editable: true, + table: t, + ), + ]; +} + +/// Library search across the whole catalog (name/genre/category/source), +/// mirroring [matchesTableQuery]'s fields. [q] arrives lowercased. +bool matchesCatalogQuery(CatalogEntry e, String q) => [ + e.name, + e.genre, + e.category, + e.source, + ].any((f) => f.toLowerCase().contains(q)); + +/// Category-sorted grouping; entries keep their catalog order inside each +/// group (generators first, then starters, then user tables). +List<(String, List)> groupCatalogByCategory( + List entries) { + final byCat = >{}; + for (final e in entries) { + byCat.putIfAbsent(e.category, () => []).add(e); + } + final cats = byCat.keys.toList()..sort(); + return [for (final c in cats) (c, byCat[c]!)]; +} +``` + +`lib/state/providers.dart` — near the other asset loaders (after `dungeonDataProvider`): + +```dart +/// Loads the bundled starter tables as read-only catalog entries. STRICT on +/// purpose (bundled asset, build-verified); rows get stable `starter-` +/// ids so widget keys and dedup survive reloads. Replaces the old one-tap +/// import — starters now appear in the catalog directly. +final starterTablesProvider = FutureProvider>((ref) async { + final raw = await rootBundle.loadString('assets/starter_tables.json'); + final tables = decodeTablePack(raw); + return [ + for (final (i, t) in tables.indexed) t.copyWith(id: 'starter-$i'), + ]; +}); +``` + +Note: check `CustomTable.copyWith` exists and accepts `id`; if it doesn't take `id`, rebuild via `CustomTable.fromJson({...t.toJson(), 'id': 'starter-$i'})` or the constructor — match whatever the class offers. Add the import of `inspiration_catalog.dart` only where used (Tasks 2–3); providers.dart needs only `custom_table.dart` (already imported). + +- [ ] **Step 4: Run to verify it passes** + +Run: `flutter test test/inspiration_catalog_test.dart` +Expected: PASS. + +- [ ] **Step 5: Commit** + +```bash +git add lib/engine/inspiration_catalog.dart lib/state/providers.dart test/inspiration_catalog_test.dart +git commit -m "feat(catalog): unified inspiration catalog engine + bundled starters provider" +``` + +--- + +### Task 2: Tables tab renders the catalog + +**Files:** +- Modify: `lib/features/tables_screen.dart` +- Test: `test/tables_catalog_test.dart` (new) + update the existing starter-pack test (find: `grep -rln "tables-starter-pack" test/`) + +**Interfaces:** +- Consumes: Task 1 symbols; existing `_rollCustomTable` (extend for read-only starters), `journalProvider.addResult`, `showLoggedSnackBar`, `sourceToolFor`, `widget.oracle`. +- Produces: keys `tables-generators` (ExpansionTile), `gen-roll-` rows, `tables-starters` (ExpansionTile), `starter-roll-` rows. The `tables-starter-pack` import tile and `_importStarterPack` are REMOVED. + +- [ ] **Step 1: Write the failing test** + +Copy the pump scaffolding from the existing Tables-tab test (find: `grep -rln "tables-my-tables\|tables-search" test/ | head`; it overrides the oracle-data provider with a fixture). Override `starterTablesProvider` with `[CustomTable(id: 'starter-0', name: 'Rumors', ...one row...)]`. Scenarios (write real tests): + +```dart +// 1. A 'Generators' section lists flavor generators; tapping the +// 'Word Oracle' row (key gen-roll-gen-word-oracle) logs a journal entry +// with sourceTool 'gen-story' (assert via journalProvider state). +// 2. A 'Starter tables' section lists the fixture starter; tapping +// starter-roll-starter-0 logs a 'custom-table' entry. No edit affordance +// on the row (no my-table-edit-* key). +// 3. Searching 'rumor' keeps the starter row and drops non-matching +// generators; searching 'word' keeps the Word Oracle generator row. +// 4. tables-starter-pack is GONE even with an empty user library. +// 5. With a user table named 'Rumors' sourced kStarterTableSource, the +// starter section hides its bundled duplicate. +``` + +- [ ] **Step 2: Run to verify it fails** + +Run: `flutter test test/tables_catalog_test.dart` +Expected: FAIL. + +- [ ] **Step 3: Implement** + +In `_TablesScreenState.build`, watch the catalog inputs and build entries once: + +```dart + final starters = + ref.watch(starterTablesProvider).valueOrNull ?? const []; + final catalog = buildCatalog( + generators: flavorGenerators, + starters: starters, + userTables: customTables); + final gens = [ + for (final e in catalog) + if (e.kind == CatalogKind.generator && + (q.isEmpty || matchesCatalogQuery(e, q))) + e, + ]; + final starterEntries = [ + for (final e in catalog) + if (e.kind == CatalogKind.table && !e.editable && + (q.isEmpty || matchesCatalogQuery(e, q))) + e, + ]; +``` + +Render, between the My Tables section and the built-in oracle groups: + +```dart + if (starterEntries.isNotEmpty) + ExpansionTile( + key: q.isEmpty + ? const PageStorageKey('tables-starters') + : const ValueKey('tables-starters-search'), + initiallyExpanded: q.isNotEmpty, + title: Text('Starter tables', + style: theme.textTheme.titleMedium), + subtitle: const Text( + 'A general-play core set: NPCs, places, hooks, rumors…'), + childrenPadding: const EdgeInsets.only(bottom: 4), + children: [ + for (final e in starterEntries) + Card( + child: ListTile( + key: Key('starter-roll-${e.id}'), + title: Text(e.name), + subtitle: switch ([ + if (e.genre.trim().isNotEmpty) e.genre.trim(), + if (e.category.trim().isNotEmpty) + e.category.trim(), + ].join(' · ')) { + '' => null, + final meta => Text(meta), + }, + trailing: const Icon(Icons.casino_outlined), + onTap: () => _rollCustomTable(e.table!), + ), + ), + ], + ), + if (gens.isNotEmpty) + ExpansionTile( + key: q.isEmpty + ? const PageStorageKey('tables-generators') + : const ValueKey('tables-generators-search'), + initiallyExpanded: q.isNotEmpty, + title: + Text('Generators', style: theme.textTheme.titleMedium), + subtitle: + const Text('One-tap story, NPC, and detail rolls'), + childrenPadding: const EdgeInsets.only(bottom: 4), + children: [ + for (final e in gens) + Card( + child: ListTile( + key: Key('gen-roll-${e.id}'), + title: Text(e.name), + subtitle: Text(e.category), + trailing: const Icon(Icons.casino_outlined), + onTap: () => _rollGenerator(e), + ), + ), + ], + ), +``` + +Add the handler beside `_rollCustomTable` (same log-then-snackbar shape): + +```dart + /// Roll a catalog generator and log it under its section's gen-* tag — + /// identical provenance to the same generator rolled from the composer's + /// GenerateSheet. + Future _rollGenerator(CatalogEntry e) async { + final g = e.gen!; + final r = g.run(widget.oracle); + final id = await ref.read(journalProvider.notifier).addResult( + r.title, r.asText, + sourceTool: sourceToolFor(g.section), payload: r.toPayload()); + if (!mounted) return; + showLoggedSnackBar(context, ref, id); + } +``` + +Delete the `tables-starter-pack` tile and `_importStarterPack` (its `rootBundle` import too, if now unused). Update `_myTablesSection`'s caller comment if it referenced the import. Fix/remove the existing starter-pack import test (it now asserts the tile is gone — fold into scenario 4 or keep in place, whichever file fits). + +Imports to add: `../engine/generator_registry.dart`, `../engine/inspiration_catalog.dart`. + +- [ ] **Step 4: Run tests** + +Run: `flutter test test/tables_catalog_test.dart $(grep -rln "tables-my-tables\|tables-starter-pack\|tables-search" test/ | tr '\n' ' ')` +Expected: PASS. + +- [ ] **Step 5: Format + commit** + +```bash +dart format lib/features/tables_screen.dart +git add lib/features/tables_screen.dart test/ +git commit -m "feat(catalog): Tables tab lists generators + bundled starters; import tile retired" +``` + +--- + +### Task 3: GenerateSheet renders the starters + +**Files:** +- Modify: `lib/features/generate_sheet.dart` (a "Starter Tables" section beside the existing "My Tables" section ~line 216) +- Test: extend `test/generate_sheet_test.dart` + +**Interfaces:** +- Consumes: `starterTablesProvider`, `buildCatalog`/`CatalogKind` (or just the starters list + the same name-dedup rule — use `buildCatalog` so the dedup logic isn't duplicated), existing `table-roll` handler shape (`rollCustomTable` + `addResult` sourceTool `'custom-table'`). +- Produces: `starter-chip-` ActionChips. + +- [ ] **Step 1: Write the failing test** + +In `test/generate_sheet_test.dart` (existing scaffolding), override `starterTablesProvider` with one fixture table. Scenarios: + +```dart +// 1. A 'Starter Tables' section shows starter-chip-starter-0; tapping it +// logs a 'custom-table' journal entry (sheet stays open or closes — +// match the existing My-Tables chip behavior exactly). +// 2. With a user table named identically (source kStarterTableSource), the +// starter chip is hidden (dedup via buildCatalog). +``` + +- [ ] **Step 2: Run to verify it fails** + +Run: `flutter test test/generate_sheet_test.dart` +Expected: new cases FAIL. + +- [ ] **Step 3: Implement** + +Mirror the existing "My Tables" section block (~line 216): watch `starterTablesProvider` + `customTablesProvider`, compute + +```dart + final starterEntries = buildCatalog( + generators: const [], + starters: starters, + userTables: customTables, + ).where((e) => e.kind == CatalogKind.table && !e.editable).toList(); +``` + +and render a `'Starter Tables'` label + Wrap of ActionChips keyed `starter-chip-`, whose onPressed does exactly what the `table-roll-` chip does (roll via `rollCustomTable(e.table!, ...)`, log `sourceTool: 'custom-table'`, same open/close behavior). Imports: `../engine/inspiration_catalog.dart`. + +- [ ] **Step 4: Run tests** + +Run: `flutter test test/generate_sheet_test.dart` +Expected: PASS. + +- [ ] **Step 5: Format + commit** + +```bash +dart format lib/features/generate_sheet.dart +git add lib/features/generate_sheet.dart test/generate_sheet_test.dart +git commit -m "feat(catalog): GenerateSheet offers the bundled starter tables" +``` + +--- + +### Task 4: Full verify + docs + +**Files:** +- Modify: `CLAUDE.md` + +- [ ] **Step 1: Analyze + full suite** + +Run: `flutter analyze && flutter test` +Expected: clean + green. Attribute failures ONLY from the final "Failing tests:" block. + +- [ ] **Step 2: CLAUDE.md note** + +```markdown +- **Unified inspiration catalog (2026-08-13, PR 3 of the streamline epic)** — + one browsable catalog over three sources: flavor generators + bundled + starter tables + My Tables. Pure `lib/engine/inspiration_catalog.dart` + (`CatalogEntry`/`CatalogKind`, `buildCatalog` — dedups a bundled starter + when the user library holds a same-name `kStarterTableSource` copy, + `matchesCatalogQuery`, `groupCatalogByCategory`) + + `starterTablesProvider` (STRICT asset load, stable `starter-` ids). + Ask → Tables gained 'Starter tables' (`starter-roll-`) + 'Generators' + (`gen-roll-`) sections with unified search; the one-tap + `tables-starter-pack` import tile is RETIRED (starters render directly). + GenerateSheet gained `starter-chip-` chips. Provenance unchanged: + generators log `gen-*`, tables log `'custom-table'`. See + `docs/superpowers/specs/2026-08-12-streamline-library-exclusive-capabilities-design.md`. +``` + +- [ ] **Step 3: Commit** + +```bash +git add CLAUDE.md +git commit -m "docs: unified inspiration catalog project note" +``` From fc062c31410b14ed1d61c9c02dfd579d2b4f4760 Mon Sep 17 00:00:00 2001 From: John Taylor Date: Thu, 13 Aug 2026 00:13:25 -0400 Subject: [PATCH 2/6] feat(catalog): unified inspiration catalog engine + bundled starters provider --- lib/engine/inspiration_catalog.dart | 104 ++++++++++++++++++++++++++++ lib/state/providers.dart | 13 ++++ test/inspiration_catalog_test.dart | 74 ++++++++++++++++++++ 3 files changed, 191 insertions(+) create mode 100644 lib/engine/inspiration_catalog.dart create mode 100644 test/inspiration_catalog_test.dart diff --git a/lib/engine/inspiration_catalog.dart b/lib/engine/inspiration_catalog.dart new file mode 100644 index 0000000..d93e35b --- /dev/null +++ b/lib/engine/inspiration_catalog.dart @@ -0,0 +1,104 @@ +/// One inspiration catalog over three sources: the flavor generators, the +/// bundled read-only starter tables, and the user's My Tables. Both rolling +/// surfaces (Ask → Tables, GenerateSheet) render this list, so a table or +/// generator added in one place appears in both. Pure — no Flutter. +library; + +import 'custom_table.dart'; +import 'generator_registry.dart'; + +enum CatalogKind { generator, table } + +class CatalogEntry { + const CatalogEntry({ + required this.id, + required this.name, + required this.kind, + required this.category, + this.genre = '', + this.source = '', + this.editable = false, + this.gen, + this.table, + }); + final String id; + final String name; + final CatalogKind kind; + final String category; + final String genre; + final String source; + + /// True only for the user's own tables — the editor opens on these. + final bool editable; + final GeneratorDef? gen; // set when kind == generator + final CustomTable? table; // set when kind == table +} + +/// Merges the three sources. A bundled starter is dropped when the user +/// library already holds a table with the same name and starter source — +/// legacy libraries imported the pack via the old one-tap button, and the +/// user's (possibly edited) copy wins. +List buildCatalog({ + required List generators, + required List starters, + required List userTables, +}) { + final imported = { + for (final t in userTables) + if (t.source == kStarterTableSource) t.name, + }; + return [ + for (final g in generators) + CatalogEntry( + id: 'gen-${g.label.toLowerCase().replaceAll(' ', '-')}', + name: g.label, + kind: CatalogKind.generator, + category: g.section.label, + source: 'Built-in', + gen: g, + ), + for (final t in starters) + if (!imported.contains(t.name)) + CatalogEntry( + id: t.id, + name: t.name, + kind: CatalogKind.table, + category: t.category, + genre: t.genre, + source: t.source, + table: t, + ), + for (final t in userTables) + CatalogEntry( + id: t.id, + name: t.name, + kind: CatalogKind.table, + category: t.category, + genre: t.genre, + source: t.source, + editable: true, + table: t, + ), + ]; +} + +/// Library search across the whole catalog (name/genre/category/source), +/// mirroring [matchesTableQuery]'s fields. [q] arrives lowercased. +bool matchesCatalogQuery(CatalogEntry e, String q) => [ + e.name, + e.genre, + e.category, + e.source, + ].any((f) => f.toLowerCase().contains(q)); + +/// Category-sorted grouping; entries keep their catalog order inside each +/// group (generators first, then starters, then user tables). +List<(String, List)> groupCatalogByCategory( + List entries) { + final byCat = >{}; + for (final e in entries) { + byCat.putIfAbsent(e.category, () => []).add(e); + } + final cats = byCat.keys.toList()..sort(); + return [for (final c in cats) (c, byCat[c]!)]; +} diff --git a/lib/state/providers.dart b/lib/state/providers.dart index 3d1ae6b..70bf6b7 100644 --- a/lib/state/providers.dart +++ b/lib/state/providers.dart @@ -79,6 +79,19 @@ final dungeonDataProvider = FutureProvider((ref) async { return DungeonTables.fromJson(jsonDecode(raw) as Map); }); +/// Loads the bundled starter tables as read-only catalog entries. STRICT on +/// purpose (bundled asset, build-verified); rows get stable `starter-` +/// ids so widget keys and dedup survive reloads. Replaces the old one-tap +/// import — starters now appear in the catalog directly. +final starterTablesProvider = FutureProvider>((ref) async { + final raw = await rootBundle.loadString('assets/starter_tables.json'); + final tables = decodeTablePack(raw); + return [ + for (final (i, t) in tables.indexed) + CustomTable.fromJson({...t.toJson(), 'id': 'starter-$i'}), + ]; +}); + String _newId() => DateTime.now().microsecondsSinceEpoch.toString(); /// Tolerant decode for USER-persisted JSON (never bundled assets): corrupt diff --git a/test/inspiration_catalog_test.dart b/test/inspiration_catalog_test.dart new file mode 100644 index 0000000..678fd29 --- /dev/null +++ b/test/inspiration_catalog_test.dart @@ -0,0 +1,74 @@ +import 'package:flutter_test/flutter_test.dart'; +import 'package:loreseer/engine/custom_table.dart'; +import 'package:loreseer/engine/generator_registry.dart'; +import 'package:loreseer/engine/inspiration_catalog.dart'; + +CustomTable t(String id, String name, + {String cat = '', String genre = '', String src = ''}) => + CustomTable( + id: id, + name: name, + rows: const [], + category: cat, + genre: genre, + source: src); + +void main() { + test('buildCatalog merges three sources with right kinds/flags', () { + final cat = buildCatalog( + generators: flavorGenerators, + starters: [ + t('starter-0', 'Rumors', cat: 'Hooks', src: kStarterTableSource) + ], + userTables: [t('u1', 'My monsters', cat: 'Foes')], + ); + expect(cat.where((e) => e.kind == CatalogKind.generator).length, + flavorGenerators.length); + final starter = cat.singleWhere((e) => e.id == 'starter-0'); + expect(starter.editable, isFalse); + expect(starter.kind, CatalogKind.table); + final mine = cat.singleWhere((e) => e.id == 'u1'); + expect(mine.editable, isTrue); + // Generators carry their section label as category. + expect(cat.firstWhere((e) => e.name == 'Word Oracle').category, + GenSection.story.label); + }); + + test('a bundled starter hides when the user already imported it', () { + final cat = buildCatalog( + generators: const [], + starters: [t('starter-0', 'Rumors', src: kStarterTableSource)], + userTables: [t('u9', 'Rumors', src: kStarterTableSource)], + ); + expect(cat.where((e) => e.name == 'Rumors').length, 1); + expect(cat.single.id, 'u9'); + }); + + test('matchesCatalogQuery spans name/genre/category/source', () { + final e = buildCatalog( + generators: const [], + starters: const [], + userTables: [ + t('u1', 'Wild beasts', cat: 'Foes', genre: 'fantasy', src: 'homebrew') + ], + ).single; + for (final q in ['beast', 'foes', 'fantasy', 'homebrew']) { + expect(matchesCatalogQuery(e, q), isTrue, reason: q); + } + expect(matchesCatalogQuery(e, 'sci-fi'), isFalse); + }); + + test('groupCatalogByCategory sorts categories, keeps insertion order', () { + final groups = groupCatalogByCategory(buildCatalog( + generators: const [], + starters: const [], + userTables: [ + t('a', 'A', cat: 'Zed'), + t('b', 'B', cat: 'Alpha'), + t('c', 'C', cat: 'Zed') + ], + )); + expect(groups.map((g) => g.$1).toList(), ['Alpha', 'Zed']); + expect(groups.last.$2.map((e) => e.name).toList(), ['A', 'C']); + }); +} From 6c02761915eeb65451166a8c15176beeaafa3111 Mon Sep 17 00:00:00 2001 From: John Taylor Date: Thu, 13 Aug 2026 00:22:35 -0400 Subject: [PATCH 3/6] feat(catalog): Tables tab lists generators + bundled starters; import tile retired --- lib/features/tables_screen.dart | 110 +++++++++++++++++++++------ test/tables_catalog_test.dart | 130 ++++++++++++++++++++++++++++++++ test/tables_screen_test.dart | 32 +++----- 3 files changed, 227 insertions(+), 45 deletions(-) create mode 100644 test/tables_catalog_test.dart diff --git a/lib/features/tables_screen.dart b/lib/features/tables_screen.dart index 80d3e09..04f0da1 100644 --- a/lib/features/tables_screen.dart +++ b/lib/features/tables_screen.dart @@ -1,9 +1,10 @@ import 'package:flutter/material.dart'; -import 'package:flutter/services.dart' show rootBundle; import 'package:flutter_riverpod/flutter_riverpod.dart'; import '../engine/custom_table.dart'; import '../engine/dice.dart'; +import '../engine/generator_registry.dart'; +import '../engine/inspiration_catalog.dart'; import '../engine/models.dart'; import '../engine/oracle.dart'; import '../engine/table_groups.dart'; @@ -45,6 +46,25 @@ class _TablesScreenState extends ConsumerState { final q = _query.trim().toLowerCase(); final customTables = ref.watch(customTablesProvider).valueOrNull ?? const []; + final starters = + ref.watch(starterTablesProvider).valueOrNull ?? const []; + final catalog = buildCatalog( + generators: flavorGenerators, + starters: starters, + userTables: customTables); + final gens = [ + for (final e in catalog) + if (e.kind == CatalogKind.generator && + (q.isEmpty || matchesCatalogQuery(e, q))) + e, + ]; + final starterEntries = [ + for (final e in catalog) + if (e.kind == CatalogKind.table && + !e.editable && + (q.isEmpty || matchesCatalogQuery(e, q))) + e, + ]; return Column( children: [ Padding( @@ -105,6 +125,58 @@ class _TablesScreenState extends ConsumerState { if (_visibleMyTables(customTables, q) case final mine when q.isEmpty || mine.isNotEmpty) _myTablesSection(customTables, mine), + if (starterEntries.isNotEmpty) + ExpansionTile( + key: q.isEmpty + ? const PageStorageKey('tables-starters') + : const ValueKey('tables-starters-search'), + initiallyExpanded: q.isNotEmpty, + title: Text('Starter tables', + style: theme.textTheme.titleMedium), + subtitle: const Text( + 'A general-play core set: NPCs, places, hooks, rumors…'), + childrenPadding: const EdgeInsets.only(bottom: 4), + children: [ + for (final e in starterEntries) + Card( + child: ListTile( + key: Key('starter-roll-${e.id}'), + title: Text(e.name), + subtitle: switch ([ + if (e.genre.trim().isNotEmpty) e.genre.trim(), + if (e.category.trim().isNotEmpty) e.category.trim(), + ].join(' · ')) { + '' => null, + final meta => Text(meta), + }, + trailing: const Icon(Icons.casino_outlined), + onTap: () => _rollCustomTable(e.table!), + ), + ), + ], + ), + if (gens.isNotEmpty) + ExpansionTile( + key: q.isEmpty + ? const PageStorageKey('tables-generators') + : const ValueKey('tables-generators-search'), + initiallyExpanded: q.isNotEmpty, + title: Text('Generators', style: theme.textTheme.titleMedium), + subtitle: const Text('One-tap story, NPC, and detail rolls'), + childrenPadding: const EdgeInsets.only(bottom: 4), + children: [ + for (final e in gens) + Card( + child: ListTile( + key: Key('gen-roll-${e.id}'), + title: Text(e.name), + subtitle: Text(e.category), + trailing: const Icon(Icons.casino_outlined), + onTap: () => _rollGenerator(e), + ), + ), + ], + ), for (final group in groups) if (_matching(group, q) case final matches when matches.isNotEmpty) @@ -140,6 +212,19 @@ class _TablesScreenState extends ConsumerState { showLoggedSnackBar(context, ref, id); } + /// Roll a catalog generator and log it under its section's gen-* tag — + /// identical provenance to the same generator rolled from the composer's + /// GenerateSheet. + Future _rollGenerator(CatalogEntry e) async { + final g = e.gen!; + final r = g.run(widget.oracle); + final id = await ref.read(journalProvider.notifier).addResult( + r.title, r.asText, + sourceTool: sourceToolFor(g.section), payload: r.toPayload()); + if (!mounted) return; + showLoggedSnackBar(context, ref, id); + } + /// The user tables visible under the current genre filter + search query. List _visibleMyTables(List all, String q) => [ for (final t in all) @@ -234,33 +319,10 @@ class _TablesScreenState extends ConsumerState { onTap: () => showCustomTableDialog(context, ref, null), ), ), - // One-tap import of the bundled starter set (original authored - // tables); hidden once any starter-sourced table is in the library. - if (!all.any((t) => t.source == kStarterTableSource)) - Card( - child: ListTile( - key: const Key('tables-starter-pack'), - leading: const Icon(Icons.auto_awesome_outlined), - title: const Text('Add starter tables'), - subtitle: const Text( - 'A general-play core set: NPCs, places, hooks, rumors…'), - onTap: _importStarterPack, - ), - ), ], ); } - Future _importStarterPack() async { - final raw = await rootBundle.loadString('assets/starter_tables.json'); - final tables = decodeTablePack(raw); - await ref.read(customTablesProvider.notifier).addAll(tables); - if (!mounted) return; - ScaffoldMessenger.of(context).showSnackBar( - SnackBar(content: Text('Added ${tables.length} starter tables')), - ); - } - /// Keys in [group] whose display title matches the lowercased query [q] /// (all of them when [q] is empty). List _matching(TableGroup group, String q) => q.isEmpty diff --git a/test/tables_catalog_test.dart b/test/tables_catalog_test.dart new file mode 100644 index 0000000..e454777 --- /dev/null +++ b/test/tables_catalog_test.dart @@ -0,0 +1,130 @@ +import 'dart:convert'; +import 'dart:io'; + +import 'package:flutter/material.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:loreseer/engine/custom_table.dart'; +import 'package:loreseer/engine/oracle.dart'; +import 'package:loreseer/engine/oracle_data.dart'; +import 'package:loreseer/features/tables_screen.dart'; +import 'package:loreseer/shared/theme.dart'; +import 'package:loreseer/state/providers.dart'; +import 'package:shared_preferences/shared_preferences.dart'; + +final _oracle = Oracle(OracleData( + jsonDecode(File('assets/oracle_data.json').readAsStringSync()) + as Map)); + +const _starterFixture = [ + CustomTable( + id: 'starter-0', + name: 'Rumors', + category: 'Hooks & Rumors', + rows: [CustomRow('A stranger asks after you by name')], + ), +]; + +/// Pump under an [UncontrolledProviderScope] so the test can read +/// [journalProvider] to assert what a roll logged. +Future pumpWithContainer( + WidgetTester tester, { + String? customTablesJson, + List starters = _starterFixture, +}) async { + SharedPreferences.setMockInitialValues({ + 'loreseer.sessions.v1': + '{"active":"default","sessions":[{"id":"default","name":"C1"}]}', + 'loreseer.journal.v2.default': '[]', + if (customTablesJson != null) 'loreseer.custom_tables.v1': customTablesJson, + }); + tester.view.physicalSize = const Size(900, 3000); + tester.view.devicePixelRatio = 1.0; + addTearDown(tester.view.resetPhysicalSize); + addTearDown(tester.view.resetDevicePixelRatio); + final c = ProviderContainer(overrides: [ + starterTablesProvider.overrideWith((ref) async => starters), + ]); + addTearDown(c.dispose); + await c.read(sessionsProvider.future); + await tester.pumpWidget(UncontrolledProviderScope( + container: c, + child: MaterialApp( + theme: AppTheme.light(), + home: Scaffold(body: TablesScreen(oracle: _oracle)), + ), + )); + await tester.pumpAndSettle(); + return c; +} + +void main() { + testWidgets( + 'Generators section lists flavor generators; tapping Word Oracle logs ' + 'a gen-story entry', (tester) async { + final c = await pumpWithContainer(tester); + // The header's PageStorageKey isn't a plain ValueKey, so tap it by text + // (mirrors how the built-in oracle table groups are expanded in tests). + await tester.tap(find.text('Generators')); + await tester.pumpAndSettle(); + final row = find.byKey(const Key('gen-roll-gen-word-oracle')); + expect(row, findsOneWidget); + await tester.tap(row); + await tester.pumpAndSettle(); + final entries = await c.read(journalProvider.future); + expect(entries.length, 1); + expect(entries.first.sourceTool, 'gen-story'); + }); + + testWidgets( + 'Starter tables section lists the fixture starter with no edit ' + 'affordance; tapping it logs a custom-table entry', (tester) async { + final c = await pumpWithContainer(tester); + expect(find.text('Starter tables'), findsOneWidget); + await tester.tap(find.text('Starter tables')); + await tester.pumpAndSettle(); + final row = find.byKey(const Key('starter-roll-starter-0')); + expect(row, findsOneWidget); + expect(find.byKey(const Key('my-table-edit-starter-0')), findsNothing); + await tester.tap(row); + await tester.pumpAndSettle(); + final entries = await c.read(journalProvider.future); + expect(entries.length, 1); + expect(entries.first.sourceTool, 'custom-table'); + }); + + testWidgets( + "searching 'rumor' keeps the starter row and drops non-matching " + 'generators', (tester) async { + await pumpWithContainer(tester); + await tester.enterText(find.byKey(const Key('tables-search')), 'rumor'); + await tester.pumpAndSettle(); + expect(find.byKey(const Key('starter-roll-starter-0')), findsOneWidget); + expect(find.byKey(const Key('gen-roll-gen-word-oracle')), findsNothing); + }); + + testWidgets("searching 'word' keeps the Word Oracle generator row", + (tester) async { + await pumpWithContainer(tester); + await tester.enterText(find.byKey(const Key('tables-search')), 'word'); + await tester.pumpAndSettle(); + expect(find.byKey(const Key('gen-roll-gen-word-oracle')), findsOneWidget); + expect(find.byKey(const Key('starter-roll-starter-0')), findsNothing); + }); + + testWidgets('tables-starter-pack is gone even with an empty user library', + (tester) async { + await pumpWithContainer(tester); + expect(find.byKey(const Key('tables-starter-pack')), findsNothing); + }); + + testWidgets( + 'a user table sourced from the starter pack hides the bundled ' + 'duplicate', (tester) async { + const seed = '[{"id":"t1","name":"Rumors","rows":["x"],' + '"src":"Starter set"}]'; + await pumpWithContainer(tester, customTablesJson: seed); + expect(find.byKey(const Key('starter-roll-starter-0')), findsNothing); + expect(find.byKey(const Key('my-table-t1')), findsOneWidget); + }); +} diff --git a/test/tables_screen_test.dart b/test/tables_screen_test.dart index 706529b..e73e02d 100644 --- a/test/tables_screen_test.dart +++ b/test/tables_screen_test.dart @@ -71,7 +71,7 @@ void main() { // Top-of-list groups are built; 'General' (pinned last) is off-screen and // lazily unbuilt — its placement is covered by table_groups_test. // ('Quest' and later groups sit below the lazy-list fold now that the - // My Tables section carries the starter-pack card.) + // My Tables / Starter tables / Generators sections lead the list.) expect(find.text('Challenge'), findsOneWidget); expect(find.text('NPC'), findsOneWidget); }); @@ -82,7 +82,9 @@ void main() { await tester.enterText( find.byKey(const Key('tables-search')), 'settlement'); await tester.pumpAndSettle(); - expect(find.text('Settlement'), findsOneWidget); // header still there + // Header + the catalog's own "Settlement" generator row (search now + // surfaces matching generators too). + expect(find.text('Settlement'), findsNWidgets(2)); expect(find.text('Settlement Name'), findsOneWidget); // a matching tile expect(find.text('Quest'), findsNothing); // non-matching group gone expect(find.text('NPC Need'), findsNothing); // non-matching tile gone @@ -180,8 +182,8 @@ void main() { await pumpWithContainer(tester, customTablesJson: seed); // Two categories → headers show, in taxonomy order. - expect(find.byKey(const Key('tables-cat-Characters & NPCs')), - findsOneWidget); + expect( + find.byKey(const Key('tables-cat-Characters & NPCs')), findsOneWidget); expect(find.byKey(const Key('tables-cat-Locations & Settings')), findsOneWidget); // Row subtitle carries the genre. @@ -197,18 +199,6 @@ void main() { expect(find.byKey(const Key('my-table-t1')), findsOneWidget); }); - testWidgets( - 'starter-pack import chip shows for a fresh library and hides once a ' - 'starter-sourced table exists', (tester) async { - await pumpWithContainer(tester); - expect(find.byKey(const Key('tables-starter-pack')), findsOneWidget); - - const seeded = '[{"id":"t1","name":"Rumors","rows":["x"],' - '"src":"Starter set"}]'; - await pumpWithContainer(tester, customTablesJson: seeded); - expect(find.byKey(const Key('tables-starter-pack')), findsNothing); - }); - testWidgets('editor saves genre/category/source onto the table', (tester) async { final c = await pumpWithContainer(tester); @@ -227,8 +217,7 @@ void main() { await tester.tap(find.byKey(const Key('table-save'))); await tester.pumpAndSettle(); - final saved = - (await c.read(customTablesProvider.future)).single; + final saved = (await c.read(customTablesProvider.future)).single; expect(saved.name, 'Patrons'); expect(saved.genre, 'Fantasy'); expect(saved.category, 'Characters & NPCs'); @@ -245,7 +234,8 @@ void main() { await tester.tap(find.text('Quest Objective')); await tester.pumpAndSettle(); expect(find.byTooltip('Add to journal'), findsOneWidget); // rolled - expect(find.byKey(const Key('table-inspire-quest_objective')), findsNothing); + expect( + find.byKey(const Key('table-inspire-quest_objective')), findsNothing); }); testWidgets( @@ -315,8 +305,8 @@ void main() { await tester.tap(find.text('Quest Objective')); await tester.pumpAndSettle(); // Three trailing icon buttons (inspire + log + roll) must fit the row. - expect(find.byKey(const Key('table-inspire-quest_objective')), - findsOneWidget); + expect( + find.byKey(const Key('table-inspire-quest_objective')), findsOneWidget); expect(tester.takeException(), isNull); }); } From 5f3615361d7c787a7680a2c429ae24abe41019ab Mon Sep 17 00:00:00 2001 From: John Taylor Date: Thu, 13 Aug 2026 00:26:20 -0400 Subject: [PATCH 4/6] feat(catalog): GenerateSheet offers the bundled starter tables --- lib/features/generate_sheet.dart | 36 +++++++++++++++ test/generate_sheet_test.dart | 75 +++++++++++++++++++++++++++++++- 2 files changed, 109 insertions(+), 2 deletions(-) diff --git a/lib/features/generate_sheet.dart b/lib/features/generate_sheet.dart index 7a4082a..29df240 100644 --- a/lib/features/generate_sheet.dart +++ b/lib/features/generate_sheet.dart @@ -4,6 +4,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart'; import '../engine/custom_table.dart'; import '../engine/dice.dart'; import '../engine/generator_registry.dart'; +import '../engine/inspiration_catalog.dart'; import '../engine/models.dart'; import '../engine/oracle.dart'; import '../engine/oracle_data.dart'; @@ -127,6 +128,13 @@ class _GenerateSheetState extends ConsumerState { final theme = Theme.of(context); final tables = ref.watch(customTablesProvider).valueOrNull ?? const []; + final starters = + ref.watch(starterTablesProvider).valueOrNull ?? const []; + final starterEntries = buildCatalog( + generators: const [], + starters: starters, + userTables: tables, + ).where((e) => e.kind == CatalogKind.table && !e.editable).toList(); final bySection = >{}; for (final g in flavorGenerators) { bySection.putIfAbsent(g.section, () => []).add(g); @@ -248,6 +256,34 @@ class _GenerateSheetState extends ConsumerState { ), ], ), + if (starterEntries.isNotEmpty) ...[ + Padding( + padding: const EdgeInsets.only(top: 8, bottom: 6), + child: + Text('Starter Tables', style: theme.textTheme.labelMedium), + ), + Wrap( + spacing: 8, + runSpacing: 8, + children: [ + for (final e in starterEntries) + ActionChip( + key: Key('starter-chip-${e.id}'), + label: Text(e.name), + onPressed: () async { + final r = rollCustomTable(e.table!, Dice()); + final id = await ref + .read(journalProvider.notifier) + .addResult(r.title, r.asText, + sourceTool: 'custom-table', + payload: r.toPayload()); + if (!context.mounted) return; + Navigator.of(context).pop(id); + }, + ), + ], + ), + ], Padding( padding: const EdgeInsets.only(top: 8, bottom: 6), child: diff --git a/test/generate_sheet_test.dart b/test/generate_sheet_test.dart index b11f076..8e708fb 100644 --- a/test/generate_sheet_test.dart +++ b/test/generate_sheet_test.dart @@ -26,10 +26,15 @@ const _basePrefs = { 'loreseer.journal.v2.default': '[]', }; +// Every container below overrides starterTablesProvider to an empty list +// (unless a test is specifically exercising Starter Tables) — the real +// bundled asset holds ~20 tables, and rendering them inline would push +// lower chips (e.g. gen-New Quest) out of the test viewport. Future _makeContainer() async { SharedPreferences.setMockInitialValues({..._basePrefs}); final c = ProviderContainer(overrides: [ oracleProvider.overrideWith((ref) async => _oracle()), + starterTablesProvider.overrideWith((ref) async => const []), ]); addTearDown(c.dispose); await c.read(oracleProvider.future); @@ -71,13 +76,15 @@ Future _pumpHost(WidgetTester tester, ProviderContainer c) async { } void main() { - testWidgets('a flavor chip logs, pops the sheet, and offers Inspire on the ' + testWidgets( + 'a flavor chip logs, pops the sheet, and offers Inspire on the ' 'entry it just wrote', (tester) async { SharedPreferences.setMockInitialValues({..._basePrefs}); final fake = FakeInterpreterService( initial: const InterpreterStatus(InterpreterPhase.ready)); final c = ProviderContainer(overrides: [ oracleProvider.overrideWith((ref) async => _oracle()), + starterTablesProvider.overrideWith((ref) async => const []), interpretReadyProvider.overrideWithValue(true), interpreterServiceProvider.overrideWithValue(fake), ]); @@ -110,7 +117,8 @@ void main() { // Still ONE entry — the reading folded into the roll it came from. final journal = c.read(journalProvider).valueOrNull ?? const []; expect(journal, hasLength(1)); - expect(journal.single.body, contains('— Oracle reading (literal): fallback')); + expect( + journal.single.body, contains('— Oracle reading (literal): fallback')); }); testWidgets('no Inspire action on the snackbar when interpret is not ready', @@ -118,6 +126,7 @@ void main() { SharedPreferences.setMockInitialValues({..._basePrefs}); final c = ProviderContainer(overrides: [ oracleProvider.overrideWith((ref) async => _oracle()), + starterTablesProvider.overrideWith((ref) async => const []), interpretReadyProvider.overrideWithValue(false), ]); addTearDown(c.dispose); @@ -278,6 +287,7 @@ void main() { }); final c = ProviderContainer(overrides: [ oracleProvider.overrideWith((ref) async => _oracle()), + starterTablesProvider.overrideWith((ref) async => const []), ]); addTearDown(c.dispose); await c.read(oracleProvider.future); @@ -350,4 +360,65 @@ void main() { final entries = await c.read(journalProvider.future); expect(entries.single.sourceTool, 'custom-table'); }); + + // --- Starter Tables (bundled read-only tables) ---------------------------- + + testWidgets( + 'Starter Tables section shows a starter chip; tapping it logs a ' + 'custom-table entry', (tester) async { + SharedPreferences.setMockInitialValues({..._basePrefs}); + final c = ProviderContainer(overrides: [ + oracleProvider.overrideWith((ref) async => _oracle()), + starterTablesProvider.overrideWith((ref) async => const [ + CustomTable( + id: 'starter-0', + name: 'Rumors', + rows: [CustomRow('A stranger asks after you by name')], + ), + ]), + ]); + addTearDown(c.dispose); + await c.read(oracleProvider.future); + await c.read(sessionsProvider.future); + await _pumpSheet(tester, c); + + expect(find.text('Starter Tables'), findsOneWidget); + final chip = find.byKey(const Key('starter-chip-starter-0')); + expect(chip, findsOneWidget); + await tester.tap(chip); + await tester.pumpAndSettle(); + + final entries = await c.read(journalProvider.future); + expect(entries.length, 1); + expect(entries.first.sourceTool, 'custom-table'); + expect(entries.first.title, 'Rumors'); + }); + + testWidgets( + 'a user table sourced from the starter pack hides the bundled ' + 'duplicate chip', (tester) async { + SharedPreferences.setMockInitialValues({ + ..._basePrefs, + 'loreseer.custom_tables.v1': + '[{"id":"t1","name":"Rumors","rows":["x"],"src":"Starter set"}]', + }); + final c = ProviderContainer(overrides: [ + oracleProvider.overrideWith((ref) async => _oracle()), + starterTablesProvider.overrideWith((ref) async => const [ + CustomTable( + id: 'starter-0', + name: 'Rumors', + rows: [CustomRow('A stranger asks after you by name')], + ), + ]), + ]); + addTearDown(c.dispose); + await c.read(oracleProvider.future); + await c.read(sessionsProvider.future); + await c.read(customTablesProvider.future); + await _pumpSheet(tester, c); + + expect(find.byKey(const Key('starter-chip-starter-0')), findsNothing); + expect(find.byKey(const Key('table-roll-t1')), findsOneWidget); + }); } From bf4e84daad99053913155d66f32666c095b258a1 Mon Sep 17 00:00:00 2001 From: John Taylor Date: Thu, 13 Aug 2026 00:32:42 -0400 Subject: [PATCH 5/6] docs: unified inspiration catalog project note --- CLAUDE.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/CLAUDE.md b/CLAUDE.md index 73137cd..c016d75 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -19,6 +19,19 @@ Working rules for this repo: ## Project notes +- **Unified inspiration catalog (2026-08-13, PR 3 of the streamline epic)** — + one browsable catalog over three sources: flavor generators + bundled + starter tables + My Tables. Pure `lib/engine/inspiration_catalog.dart` + (`CatalogEntry`/`CatalogKind`, `buildCatalog` — dedups a bundled starter + when the user library holds a same-name `kStarterTableSource` copy, + `matchesCatalogQuery`, `groupCatalogByCategory`) + + `starterTablesProvider` (STRICT asset load, stable `starter-` ids). + Ask → Tables gained 'Starter tables' (`starter-roll-`) + 'Generators' + (`gen-roll-`) sections with unified search; the one-tap + `tables-starter-pack` import tile is RETIRED (starters render directly). + GenerateSheet gained `starter-chip-` chips. Provenance unchanged: + generators log `gen-*`, tables log `'custom-table'`. See + `docs/superpowers/specs/2026-08-12-streamline-library-exclusive-capabilities-design.md`. - **Single-select capabilities (2026-08-12, PR 2 of the streamline epic)** — overlapping tools are radio choices, not stacking toggles. Pure `kExclusiveGroups` (`{'hex-flavor': [verdant, hexcrawl]}`) + From adbf1adf80ecdc2e9fb4dc8508f85b7d1f35d16f Mon Sep 17 00:00:00 2001 From: John Taylor Date: Thu, 13 Aug 2026 00:41:57 -0400 Subject: [PATCH 6/6] fix(catalog): final-review fixes for the inspiration catalog PR MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Drop the starterTablesProvider index re-id (assets/starter_tables.json already ships stable, unique starter-* ids — reindexing on load was strictly less stable). Fix CLAUDE.md's stale custom-tables paragraph that still described the retired import tile, and note the legacy rename/delete dedup edge case. Harden test/tables_screen_test.dart's pump helpers against loading the real starter-tables asset, tighten a loose findsNWidgets(2) assertion, and correct a comment claiming PageStorageKey isn't key-findable (it extends ValueKey). --- CLAUDE.md | 12 +++++++++--- lib/state/providers.dart | 14 ++++++-------- test/generate_sheet_test.dart | 8 ++++---- test/inspiration_catalog_test.dart | 6 +++--- test/tables_catalog_test.dart | 17 ++++++++--------- test/tables_screen_test.dart | 13 +++++++++++-- 6 files changed, 41 insertions(+), 29 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index c016d75..8a8ec11 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -25,13 +25,18 @@ Working rules for this repo: (`CatalogEntry`/`CatalogKind`, `buildCatalog` — dedups a bundled starter when the user library holds a same-name `kStarterTableSource` copy, `matchesCatalogQuery`, `groupCatalogByCategory`) + - `starterTablesProvider` (STRICT asset load, stable `starter-` ids). + `starterTablesProvider` (STRICT asset load; the asset owns its own stable, + unique `starter-*` ids — no provider-side re-id). Ask → Tables gained 'Starter tables' (`starter-roll-`) + 'Generators' (`gen-roll-`) sections with unified search; the one-tap `tables-starter-pack` import tile is RETIRED (starters render directly). GenerateSheet gained `starter-chip-` chips. Provenance unchanged: generators log `gen-*`, tables log `'custom-table'`. See `docs/superpowers/specs/2026-08-12-streamline-library-exclusive-capabilities-design.md`. + A legacy user who had imported a starter table then renamed or deleted it + sees the pristine bundled original reappear read-only in the catalog (dedup + is by name + `kStarterTableSource`, so once that match breaks the bundled + entry is no longer hidden) — accepted behavior, not a bug. - **Single-select capabilities (2026-08-12, PR 2 of the streamline epic)** — overlapping tools are radio choices, not stacking toggles. Pure `kExclusiveGroups` (`{'hex-flavor': [verdant, hexcrawl]}`) + @@ -943,8 +948,9 @@ Working rules for this repo: content — the user authors every row. A bundled **starter pack** (`assets/starter_tables.json`, generated by `build_starter_tables.py` — same script-is-source-of-truth rail; 22 ORIGINAL-authored general-play tables - stamped `src: kStarterTableSource`) imports one-tap via `tables-starter-pack` - in My Tables (hidden once any starter-sourced table exists). Community + stamped `src: kStarterTableSource`) is surfaced read-only through the + unified inspiration catalog (see the 2026-08-13 bullet) rather than + imported. Community collections (r/BehindTheTables via autorolltables) were evaluated and NOT vendored — no reuse license on the content; only their topic coverage informed the set. **Library taxonomy (community binder diff --git a/lib/state/providers.dart b/lib/state/providers.dart index 70bf6b7..056a4dd 100644 --- a/lib/state/providers.dart +++ b/lib/state/providers.dart @@ -80,16 +80,14 @@ final dungeonDataProvider = FutureProvider((ref) async { }); /// Loads the bundled starter tables as read-only catalog entries. STRICT on -/// purpose (bundled asset, build-verified); rows get stable `starter-` -/// ids so widget keys and dedup survive reloads. Replaces the old one-tap -/// import — starters now appear in the catalog directly. +/// purpose (bundled asset, build-verified). The asset itself owns stable, +/// unique `starter-*` semantic ids (verified by test/starter_tables_test.dart) +/// — no re-id here, since an index-based id renumbers every entry below an +/// insertion. Replaces the old one-tap import — starters now appear in the +/// catalog directly. final starterTablesProvider = FutureProvider>((ref) async { final raw = await rootBundle.loadString('assets/starter_tables.json'); - final tables = decodeTablePack(raw); - return [ - for (final (i, t) in tables.indexed) - CustomTable.fromJson({...t.toJson(), 'id': 'starter-$i'}), - ]; + return decodeTablePack(raw); }); String _newId() => DateTime.now().microsecondsSinceEpoch.toString(); diff --git a/test/generate_sheet_test.dart b/test/generate_sheet_test.dart index 8e708fb..3f497e7 100644 --- a/test/generate_sheet_test.dart +++ b/test/generate_sheet_test.dart @@ -371,7 +371,7 @@ void main() { oracleProvider.overrideWith((ref) async => _oracle()), starterTablesProvider.overrideWith((ref) async => const [ CustomTable( - id: 'starter-0', + id: 'starter-rumor', name: 'Rumors', rows: [CustomRow('A stranger asks after you by name')], ), @@ -383,7 +383,7 @@ void main() { await _pumpSheet(tester, c); expect(find.text('Starter Tables'), findsOneWidget); - final chip = find.byKey(const Key('starter-chip-starter-0')); + final chip = find.byKey(const Key('starter-chip-starter-rumor')); expect(chip, findsOneWidget); await tester.tap(chip); await tester.pumpAndSettle(); @@ -406,7 +406,7 @@ void main() { oracleProvider.overrideWith((ref) async => _oracle()), starterTablesProvider.overrideWith((ref) async => const [ CustomTable( - id: 'starter-0', + id: 'starter-rumor', name: 'Rumors', rows: [CustomRow('A stranger asks after you by name')], ), @@ -418,7 +418,7 @@ void main() { await c.read(customTablesProvider.future); await _pumpSheet(tester, c); - expect(find.byKey(const Key('starter-chip-starter-0')), findsNothing); + expect(find.byKey(const Key('starter-chip-starter-rumor')), findsNothing); expect(find.byKey(const Key('table-roll-t1')), findsOneWidget); }); } diff --git a/test/inspiration_catalog_test.dart b/test/inspiration_catalog_test.dart index 678fd29..b61a6fc 100644 --- a/test/inspiration_catalog_test.dart +++ b/test/inspiration_catalog_test.dart @@ -18,13 +18,13 @@ void main() { final cat = buildCatalog( generators: flavorGenerators, starters: [ - t('starter-0', 'Rumors', cat: 'Hooks', src: kStarterTableSource) + t('starter-rumor', 'Rumors', cat: 'Hooks', src: kStarterTableSource) ], userTables: [t('u1', 'My monsters', cat: 'Foes')], ); expect(cat.where((e) => e.kind == CatalogKind.generator).length, flavorGenerators.length); - final starter = cat.singleWhere((e) => e.id == 'starter-0'); + final starter = cat.singleWhere((e) => e.id == 'starter-rumor'); expect(starter.editable, isFalse); expect(starter.kind, CatalogKind.table); final mine = cat.singleWhere((e) => e.id == 'u1'); @@ -37,7 +37,7 @@ void main() { test('a bundled starter hides when the user already imported it', () { final cat = buildCatalog( generators: const [], - starters: [t('starter-0', 'Rumors', src: kStarterTableSource)], + starters: [t('starter-rumor', 'Rumors', src: kStarterTableSource)], userTables: [t('u9', 'Rumors', src: kStarterTableSource)], ); expect(cat.where((e) => e.name == 'Rumors').length, 1); diff --git a/test/tables_catalog_test.dart b/test/tables_catalog_test.dart index e454777..3b04093 100644 --- a/test/tables_catalog_test.dart +++ b/test/tables_catalog_test.dart @@ -18,7 +18,7 @@ final _oracle = Oracle(OracleData( const _starterFixture = [ CustomTable( - id: 'starter-0', + id: 'starter-rumor', name: 'Rumors', category: 'Hooks & Rumors', rows: [CustomRow('A stranger asks after you by name')], @@ -63,9 +63,8 @@ void main() { 'Generators section lists flavor generators; tapping Word Oracle logs ' 'a gen-story entry', (tester) async { final c = await pumpWithContainer(tester); - // The header's PageStorageKey isn't a plain ValueKey, so tap it by text - // (mirrors how the built-in oracle table groups are expanded in tests). - await tester.tap(find.text('Generators')); + // PageStorageKey extends ValueKey, so it's findable by key like any other. + await tester.tap(find.byKey(const PageStorageKey('tables-generators'))); await tester.pumpAndSettle(); final row = find.byKey(const Key('gen-roll-gen-word-oracle')); expect(row, findsOneWidget); @@ -83,9 +82,9 @@ void main() { expect(find.text('Starter tables'), findsOneWidget); await tester.tap(find.text('Starter tables')); await tester.pumpAndSettle(); - final row = find.byKey(const Key('starter-roll-starter-0')); + final row = find.byKey(const Key('starter-roll-starter-rumor')); expect(row, findsOneWidget); - expect(find.byKey(const Key('my-table-edit-starter-0')), findsNothing); + expect(find.byKey(const Key('my-table-edit-starter-rumor')), findsNothing); await tester.tap(row); await tester.pumpAndSettle(); final entries = await c.read(journalProvider.future); @@ -99,7 +98,7 @@ void main() { await pumpWithContainer(tester); await tester.enterText(find.byKey(const Key('tables-search')), 'rumor'); await tester.pumpAndSettle(); - expect(find.byKey(const Key('starter-roll-starter-0')), findsOneWidget); + expect(find.byKey(const Key('starter-roll-starter-rumor')), findsOneWidget); expect(find.byKey(const Key('gen-roll-gen-word-oracle')), findsNothing); }); @@ -109,7 +108,7 @@ void main() { await tester.enterText(find.byKey(const Key('tables-search')), 'word'); await tester.pumpAndSettle(); expect(find.byKey(const Key('gen-roll-gen-word-oracle')), findsOneWidget); - expect(find.byKey(const Key('starter-roll-starter-0')), findsNothing); + expect(find.byKey(const Key('starter-roll-starter-rumor')), findsNothing); }); testWidgets('tables-starter-pack is gone even with an empty user library', @@ -124,7 +123,7 @@ void main() { const seed = '[{"id":"t1","name":"Rumors","rows":["x"],' '"src":"Starter set"}]'; await pumpWithContainer(tester, customTablesJson: seed); - expect(find.byKey(const Key('starter-roll-starter-0')), findsNothing); + expect(find.byKey(const Key('starter-roll-starter-rumor')), findsNothing); expect(find.byKey(const Key('my-table-t1')), findsOneWidget); }); } diff --git a/test/tables_screen_test.dart b/test/tables_screen_test.dart index e73e02d..f03bc3c 100644 --- a/test/tables_screen_test.dart +++ b/test/tables_screen_test.dart @@ -4,6 +4,7 @@ import 'dart:io'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_test/flutter_test.dart'; +import 'package:loreseer/engine/custom_table.dart'; import 'package:loreseer/engine/oracle.dart'; import 'package:loreseer/engine/oracle_data.dart'; import 'package:loreseer/features/tables_screen.dart'; @@ -29,6 +30,9 @@ Future pump(WidgetTester tester, {String? customTablesJson}) async { addTearDown(tester.view.resetPhysicalSize); addTearDown(tester.view.resetDevicePixelRatio); await tester.pumpWidget(ProviderScope( + overrides: [ + starterTablesProvider.overrideWith((ref) async => const []), + ], child: MaterialApp( theme: AppTheme.light(), home: Scaffold(body: TablesScreen(oracle: _oracle)), @@ -51,7 +55,10 @@ Future pumpWithContainer(WidgetTester tester, tester.view.devicePixelRatio = 1.0; addTearDown(tester.view.resetPhysicalSize); addTearDown(tester.view.resetDevicePixelRatio); - final c = ProviderContainer(overrides: overrides); + final c = ProviderContainer(overrides: [ + starterTablesProvider.overrideWith((ref) async => const []), + ...overrides, + ]); addTearDown(c.dispose); await c.read(sessionsProvider.future); await tester.pumpWidget(UncontrolledProviderScope( @@ -84,7 +91,9 @@ void main() { await tester.pumpAndSettle(); // Header + the catalog's own "Settlement" generator row (search now // surfaces matching generators too). - expect(find.text('Settlement'), findsNWidgets(2)); + expect(find.byKey(const Key('gen-roll-gen-settlement')), findsOneWidget); + expect(find.byKey(const ValueKey('tables-group-search-Settlement')), + findsOneWidget); expect(find.text('Settlement Name'), findsOneWidget); // a matching tile expect(find.text('Quest'), findsNothing); // non-matching group gone expect(find.text('NPC Need'), findsNothing); // non-matching tile gone