Skip to content

session history, dice tool, and inventory fix Plus Todo Resolves#5

Open
sjgold wants to merge 61 commits into
Sstobo:mainfrom
sjgold:main
Open

session history, dice tool, and inventory fix Plus Todo Resolves#5
sjgold wants to merge 61 commits into
Sstobo:mainfrom
sjgold:main

Conversation

@sjgold

@sjgold sjgold commented Apr 14, 2026

Copy link
Copy Markdown

Description:
Four improvements to the DM system + Todo's relolved

  1. Session History Summary System (lib/session_manager.py)

    • Saves structured session summary on dm-session.sh end
    • Displays previous session recap on dm-session.sh start
    • Tracks session number, location, character, key events
  2. Dice Rolling Tool (tools/dm-dice.sh - NEW)

    • CLI wrapper for lib/dice.py
    • Usage: dm-dice.sh roll 1d20+5, dm-dice.sh roll 2d20kh1
    • Supports advantage/disadvantage notation
  3. Inventory Bug Fix (tools/dm-player.sh)

    • Fixed multi-word item names failing (e.g., "Adamantine Armor")
    • Changed $3 to ${@:3} to capture all arguments
  4. Verbose Session History (lib/session_manager.py)

    • Auto-generates detailed markdown file on session end
    • Includes: character stats, equipment, inventory
    • World state: NPCs, locations, facts counts
    • Session logs with synopsis and key events
    • Legendary moments table tracking achievements

    Two new systems for D&D Game Master:

  • Module Management: Enable/disable modules per campaign with dependency validation
  • Quest System: Create quests interactively, track objectives, display to players

Resolves module TODOs and quest system features."

…vigation, and map rendering

Custom Stats & Time Effects:
- Custom character stats (hunger, thirst, radiation, etc.) with auto-change over time
- Time effects engine with stat consequences at thresholds
- Precise time tracking (HH:MM) with auto-elapsed calculation
- Timed consequences with --hours parameter for auto-triggering
- Auto-detect active character (name optional in commands)

Encounter System v6.0:
- D&D-based random encounter checks during travel
- Distance-based path segmentation with DC scaling
- Waypoint creation for stopping encounters
- DM-controlled encounter types (combat/social/hazard/loot/flavor)

Coordinate Navigation & Maps:
- Coordinate system with bearing/distance calculation
- A* pathfinding with blocked direction support
- Path preference caching for route decisions
- ASCII map rendering with fog of war
- Tkinter GUI map viewer with terrain visualization
- Path intersection detection and automatic splitting

Auto-Movement Time:
- Travel auto-calculates elapsed time from distance and speed
- Time effects applied automatically during movement

All features are opt-in and backward-compatible with standard D&D campaigns.
Includes 27 tests (all passing) and full documentation.
…ization, refresh button

- Terrain colors loaded from campaign-overview.json instead of hardcoded
- Auto-scale terrain surface to max 2000px (fixes 30s+ load on large maps)
- Viewport-crop rendering eliminates lag at high zoom levels
- Add map.sh launcher and clickable Refresh button
- Add CHANGELOG.md with version tracking
…cates

Connections between locations now stored in ONE place (alphabetically-first
location). All modules read edges through connection_utils helpers which
reconstruct reverse direction on the fly. Move without existing path is
rejected with actionable error message. Map renderers draw each line once.
Also: ensure_ascii=False across all json.dumps calls for proper Cyrillic.
Time effects engine now simulates hour-by-hour instead of batch multiplication,
re-evaluating rule conditions each tick. Added --sleeping flag for rest periods,
condition field for gating effects (e.g. "hp < max"), and auto-split paths when
adding locations on existing routes.
Added unified inventory manager with atomic transactions, stackable/unique item system, and auto-migration. Added automated firearms combat resolver with detailed roll breakdowns and PEN vs PROT mechanics. Includes modern campaign template and enhanced plot/consequence managers.
Modular architecture for community expansion packs - modules can be toggled during campaign creation (firearms, survival, coordinates, etc). Enables Mix & Match mechanics and backward compatibility.
Added unified inventory manager, automated firearms combat resolver, modern campaign template, enhanced time effects with conditionals, canonical connections, and module system roadmap to both English and Russian READMEs.
Module system architecture: CORE lib/ has zero module imports.
4 modules extracted: coordinate-navigation, encounter-system,
firearms-combat, survival-stats. Each module is self-contained
with own lib/, tools/, tests/, rules. CORE tools delegate to
module wrappers. 73 module tests passing.
Phase A: Revert CORE lib/ files to upstream
- session_manager: remove connection_utils, speed_multiplier, travel calc
- location_manager: remove terrain/distance params, canonical storage
- time_manager: remove elapsed_hours, precise_time, tick logic
- player_manager: remove custom_stat methods (CRUD + CLI)
- consequence_manager: remove trigger_hours, hours_elapsed
- plot_manager: remove add_plot method
- search.py, world_stats.py: remove connection_utils import

Phase B: Delete from lib/
- Delete lib/connection_utils.py (lives in coordinate-navigation module)
- Delete lib/inventory_manager.py (moved to inventory-system module)

Phase C: Modules absorb extracted features
- coordinate-navigation: add move + connect actions with metadata
- survival-stats: add custom-stat CRUD + time advance with effects
- NEW inventory-system: atomic transactions, stackable/unique items
- NEW quest-system: plot creation with full metadata

Phase D: Bash wrappers delegation
- dm-session.sh move → coordinate-navigation module (fallback: CORE)
- dm-time.sh --elapsed/--precise-time/--sleeping → survival-stats module
- dm-location.sh connect --terrain/--distance → coordinate-navigation module
- dm-player.sh custom-stat/custom-stats-list → survival-stats module
- dm-inventory.sh → inventory-system module (full delegation)
- dm-plot.sh add → quest-system module

Verification: zero grep hits for custom code in lib/*.py
…ule imports

- Copy connection_utils.py from lib/ history into coordinate-navigation/lib/
- Update all imports: lib.connection_utils → connection_utils (local module)
- encounter-system: import connection_utils via sys.path from nav module
- survival_engine: remove calls to player_mgr.modify_custom_stat (deleted from CORE)
  Replace with direct json_ops read/write on character.json

All 73 module tests pass.
- Add dm-navigation.sh path check/route/analyze actions (was broken dm-path.sh in tools/)
- Add dm-navigation.sh migrate action (wraps migrate-connections.py)
- Move migrate-connections.py from tools/ → coordinate-navigation/tools/
- Rewrite tools/dm-path.sh as thin delegator → dm-navigation.sh path
- Remove tools/migrate-connections.py (now lives in module)

tools/ rule: zero logic, only thin module delegators
…a dispatch_middleware

- Add dispatch_middleware() to common.sh: loops modules/*/middleware/<tool>.sh
- Rewrite CORE tools to use middleware chain instead of inline module checks
- Add 7 middleware files across 4 modules (survival-stats, coord-nav, inventory, quest)
- Remove delegator tools: dm-combat, dm-encounter, dm-map, dm-path (modules self-document)
- Delete .claude/rules/custom-campaigns.md (content lives in module rules.md)
- Move modern-firearms template into firearms-combat module
- Delete historical docs/custom-stats-time-effects-plan.md
- Fix JsonOps → JsonOperations bug in dm-consequence middleware
… modules

- Add dispatch_middleware_help() to common.sh: collects help lines from modules
- Fix glob bug: PROJECT_ROOT/.claude/modules/*/middleware/<tool> (was adding .sh.sh)
- Add --help handler to all middleware: each module self-documents its own actions
- CORE help text stripped of all module-specific flags/actions/examples
- Module actions (--elapsed, --from, --bearing, decide, routes, custom-stat, etc.)
  now appear in help only when the module is installed
- Delete tools/dm-inventory.sh (never in upstream, pure delegator)
- dm-plot.sh: remove add case from CORE (not in upstream), dispatch_middleware intercepts
- dm-session.sh: remove --speed-multiplier from help (coord-nav module flag, not CORE)
- Add dispatch_middleware_help to dm-plot.sh and dm-session.sh help output
- Game rules moved to .claude/rules/dm-rules.md
- CLAUDE.md reset to minimal dev-only rules
- /dm skill injects dm-rules.md + all module rules.md at startup
- DM scans modules dynamically at campaign creation, presents mod menu
- Module rules auto-injected into context — DM knows all mechanics from turn one
- Delete test_encounter.py — EncounterManager moved to encounter-system module
- Rewrite test_time_effects.py to match actual TimeManager API:
  - TimeManager only has update_time() and get_time() — no add_time_hours()
  - No require_active_campaign kwarg on TimeManager
  - Survival stat changes belong to survival-stats module (has own tests)
  - Add make_world_state() helper to build CampaignManager-compatible structure
  - Tests now cover update_time, get_time, precise_time field, config validation
Modules:
- merge coordinate-navigation + encounter-system → world-travel
- rename survival-stats → custom-stats (generic, no hardcoded hunger/thirst)
- remove quest-system module, move add_plot() into CORE plot_manager.py
- add README.md to all 4 modules (CORE vs module tables, examples, config)

Module system:
- module_loader.py rewritten: campaign-overview.json["modules"] as single source of truth
- dm-module.sh: add activate/deactivate commands with dependency checks
- common.sh: add _module_enabled(), dispatch_middleware_post() (post-hook pattern)
- campaign_manager.py: init modules from defaults on campaign creation
- module.json: standardized fields (genre_tags, middleware, post_middleware, adds_to_core)

CORE additions:
- time_manager.py: --elapsed <hours>, stores total_hours_elapsed, auto-ticks consequences
- consequence_manager.py: add --hours <N> for timed triggers, tick <hours> command
- dm-time.sh: --elapsed flag, calls dispatch_middleware_post after CORE
- dm-consequence.sh: tick command, --hours flag
- plot_manager.py + dm-plot.sh: add command (moved from quest-system)
- save_character.py: normalize stat aliases (constitution→con etc.)
- dm-player.sh: save-json via stdin (fix quoting)

custom-stats:
- replace dm-time.sh middleware with dm-time.sh.post (post-hook)
- reads --elapsed from args after CORE runs, no more CORE re-entry

Tests: 166/166 passing
DrSeedon and others added 21 commits February 21, 2026 13:22
…ation-rules

- Fix hierarchy_manager BFS to use connection_utils.get_connections()
  (canonical connections stored one-way, BFS needs both directions)
- Fix dm-hierarchy.sh --via → --entry-point translation
- Add Part 4 (Hierarchical Locations) to world-travel/rules.md
- Update creation-rules.md Step 7: compounds replace vehicles flow
- Migrate FTL campaign to hierarchy format (not committed — gitignored)
…solve

- Pre-generate all compound layouts at startup, instant switching
- Smart refresh: hash-based, only regenerate changed compounds
- Vehicle move: stopping distance (sum of radii), no overlap
- Vehicle connections: wipe and rebuild by proximity on every move
- Player auto-resolve: compound → entry point on session start
- GUI: player highlighted on global map, double-click to enter compound
- Enter button for compounds, description in info panel
- Rewrite rules.md and creation-rules.md — cleaner, no bloat
…ompts user to pull

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
…allation

Reorder Python detection to prefer 'python' (real installation) over 'python3'
(Microsoft Store stub) to avoid unnecessary Store prompts during tool execution.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
…ove flag

- Add DM_AUTO_APPROVE environment variable support
- Add prompt_yes_no helper function that checks for auto-approve mode
- Add is_auto_approve_enabled utility function
- Usage: /dm --auto-approve to enable for session

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
- Pass DM_AUTO_APPROVE environment variable through to Python scripts
- Suppress confirmation prompts in extraction workflow when enabled
- Update agent_extractor to check auto-approve flag on initialization

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
…gation fixes

- Add campaign-rules templates and dm-campaign-rules.sh tool
- Improve survival engine with rest/sleep mechanics
- Fix firearms resolver edge cases
- Enhance world-travel GUI caching and navigation
- Add hierarchical location support to CORE
- Update dm-continue and new-game command rules
- Update TODO with pending tasks
feat: Modular expansion system with 4 modules + middleware architecture
CORE (lib/, tools/) reverted to pre-merge 9b6660c state with only
sanctioned changes: ensure_ascii=False throughout, require_active_campaign
+ Optional[str] annotations in entity_manager/player_manager.

Advanced infrastructure moved from tools/ and lib/ into .claude/modules/:
- lib/module_loader.py              → .claude/modules/module_loader.py
- tools/dm-module.sh                → .claude/modules/infrastructure/tools/
- tools/dm-active-modules-*.sh      → .claude/modules/infrastructure/
- tools/dm-campaign-rules.sh        → .claude/modules/infrastructure/
- tools/dm-narrator.sh              → .claude/modules/infrastructure/
- .claude/dm/slots/                 → .claude/modules/dm-slots/
- .claude/campaign-rules-templates/ → .claude/modules/campaign-rules-templates/
- .claude/narrator-styles/          → .claude/modules/narrator-styles/
- new: .claude/modules/infrastructure/common-advanced.sh

Commands updated:
- dm.md: restored to monolithic vanilla version; delegates to /dm-continue
  when campaign-overview.json has "advanced_mode": true
- new-game.md: restored to vanilla + Phase 1.1 game mode choice (Classic/
  Advanced); Advanced phases reference .claude/modules/infrastructure/
- dm-continue.md: paths updated to .claude/modules/infrastructure/

Tests: test_time_effects.py moved to .claude/modules/custom-stats/tests/.
79 tests pass.

README rewritten to document both modes clearly, with accurate tool paths
and correct Getting Started instructions.

Thanks to DrSeedon for the PR that introduced the advanced module system —
those features are now fully accessible via Advanced mode at /new-game.
- On session end, saves structured summary to session-history.json
- On session start, displays previous session recap with:
  - Session number, timestamp, location, character
  - Summary of what happened
  - Key events extracted from summary
- Keeps last 20 sessions in history
- Fixed unicode encoding issues for Windows

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Adds _generate_markdown_history() method to session_manager.py
- Auto-creates session-history.md on session end
- Markdown format is human-readable with headers and bullet points
- Includes campaign overview and all sessions (newest first)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Comprehensive session history with:
- Full character stats, equipment, inventory
- World state (NPCs, locations, facts counts)
- Active party member details
- Detailed session log with synopsis and key events
- Legendary moments table tracking major achievements
- 83+ lines of detailed markdown per session

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add dm-module.sh for enable/disable/list/status commands
- Per-campaign module enable/disable tracking
- Dependency validation: block enable if dependencies not met
- Dependency graph: prevent disable if other modules depend on it
- List shows enabled status and dependency information
- Status shows module metadata and compatibility info

Resolves TODOs:
- [x] tools/dm-module.sh enable/disable — toggle modules for active campaign
- [x] Module dependency validation on enable (if module A requires module B)

Co-Authored-By: Seth Goldberg <sethjaygoldberg@gmail.com>
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Complete implementation of three quest system TODOs:

1. dm-plot.sh add <title> — Create quests interactively
   - Prompts for: description, type, objective, stakes, NPCs, locations, rewards
   - Automatically initializes objective array with main objective
   - Sets status to 'active' by default

2. dm-plot.sh objectives <name> [add|complete <text>]
   - Show: Display plot with formatted objectives (checked/unchecked)
   - Add: Create new sub-objectives for a quest
   - Complete: Mark individual objectives as done with [x] markers
   - Supports dict-based objective tracking with complete flag

3. Player-facing quest display (format_quests_for_player)
   - Method in PlotManager for displaying active quests to players
   - Shows up to 5 active quests with current objective
   - Ready for integration into /dm quests command
   - ASCII-safe formatting without Unicode characters

Extended plot_manager.py:
- add_plot() — Create new plot with validation and defaults
- add_objective() — Add or complete quest sub-objectives
- format_quests_for_player() — Player-appropriate quest display
- Fixed objective formatting to handle dict-based objectives

Updated dm-plot.sh:
- Added 'add' action with interactive prompts
- Added 'objectives' action with sub-commands
- Updated help text with all commands

Resolves TODOs:
- [x] dm-plot.sh add — create quests via CLI (currently manual JSON only)
- [x] dm-plot.sh objectives — mark quest objectives as complete
- [x] /dm quests — display active quests to player (display method ready)

Co-Authored-By: Seth Goldberg <sethjaygoldberg@gmail.com>
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
@sjgold sjgold changed the title session history, dice tool, and inventory fix session history, dice tool, and inventory fix Plus Todo Resolves Apr 25, 2026
DM Claude and others added 6 commits April 26, 2026 21:53
- Fixed save_character.py to write UTF-8 instead of system-default encoding
  preventing UnicodeDecodeError on Windows when reading saved characters

Co-Authored-By: Seth Goldberg <sethjaygoldberg@gmail.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Added spells field to save_character.py output so cantrips
  and level 1 spells are preserved in character.json

Co-Authored-By: Seth Goldberg <sethjaygoldberg@gmail.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Every dm-session.sh save now writes a narrative-summary.md
  with character, NPCs, locations, active threads, and recent
  session log — ready for DM handoff

Co-Authored-By: Seth Goldberg <sethjaygoldberg@gmail.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…handoff

- _generate_narrative_summary() now includes thematic spell flavor annotations,
  roleplay anchors (traits/ideals/bonds/flaws), key abilities, and auto-detected
  loose ends from session log content
- start_session() displays the narrative summary as "CAMPAIGN CONTEXT" when a
  game loads, giving new DMs full handoff context
- get_full_context() (dm-session.sh context) includes narrative summary sections
  so the DM context command carries the same information
- _get_spell_flavor() helper provides fire-themed annotations for Grom's spells
  (e.g., "Magic Missile erupts as flaming bolts")

Co-Authored-By: Seth Goldberg <sethjaygoldberg@gmail.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- _generate_markdown_history(): use campaign name from overview instead
  of hardcoded "Dungeon Crawler Carl Campaign"
- Loose end extraction: parse "Loose ends:" lines from session log content
  instead of hardcoded Nemedian/Khemet strings, with ticking clock detection
  via regex for any campaign
- Strip markdown formatting artifacts from extracted text

Co-Authored-By: Seth Goldberg <sethjaygoldberg@gmail.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Two related pieces of work bundled:

1. Module dispatch infrastructure (npc-agent contribution):
   - Fix module_loader.py project_root resolution (off-by-one .parent
     traversal was silently breaking ALL module discovery)
   - Fix _module_enabled cygpath conversion so MSYS2 paths reach
     Windows Python correctly
   - Fix lib/session_manager.py:193 use-before-assignment in
     _generate_markdown_history
   - Wire dispatch_middleware into tools/dm-npc.sh and tools/dm-session.sh
   - Add .claude/modules/npc-enhancements module: bidirectional
     NPC relationships, faction tagging/listing, auto-extraction
     post-hook on session end/save

2. DM rules-loading enforcement (this session):
   - CLAUDE.md gets a 'DM Behavioral Directives' section requiring
     rules to be assembled and read once at session start, then held
     in working memory (no per-turn re-reads)
   - AGENTS.md (new) mirrors the directives for non-Claude harnesses
     (Cursor, Aider, Ollama-hosted models, DeepSeek, Kimi, etc.)
   - /dm command adds Step 0: Load DM Rules, before context loading
   - dm-session.sh start prints a runtime reminder block as a
     model-agnostic safety net for cold-start agents
   - Fix CLAUDE.md drift (the .claude/rules/dm-rules.md path it
     referenced does not exist; rules are assembled at runtime)

Closes the cold-start gap that was causing agents to skip the 3-5
[Letter]option block at end of turns, and provides a deterministic
substrate for future modules that need to intercept state-mutating
tools.

Also: .gitignore adds sjg_dm_docs/ for personal planning docs.

Co-Authored-By: Seth Goldberg <sethjaygoldberg@gmail.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

@aoysgelt aoysgelt left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like there are a lot of files here that are related to someone's extraction of a game. This should be cleaned up because it's a red flag that this pull request has issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants