From 6fdf1560bb80eb953a037a22975d06e05b3add45 Mon Sep 17 00:00:00 2001 From: mcocdaa <2021137961@qq.com> Date: Sat, 7 Nov 2026 09:07:05 +0100 Subject: [PATCH] feat(release): prepare v2.0.0-rc.1 with Steam feedback fixes and BBCode About.xml feat(storyteller): restore vanilla trade, caravan and quest ecosystem Add vanilla storyteller comps to RimMindDirector so orbital traders, faction caravans, visitor groups, traveler groups, ship chunk drops, and random quests (Royalty-aware) continue to fire alongside AI-directed narrative events. Fix faction hint resolution to accept non-hostile factions for non-threat incidents (e.g. TraderCaravanArrival, RaidFriendly) while still requiring hostile factions for ThreatBig/ThreatSmall, and reject defeated factions. Introduce IncidentSelectionPolicy. RequiresHostileFaction to centralize this rule. Expand About.xml description with v2.0 feature overview, sub-mod dependency table, director pipeline, and FAQ. Exclude dev config files from release packaging and add contract tests covering the director def comps and faction hint policy. --- .github/workflows/release.yml | 3 + About/About.xml | 61 +++++++++- Defs/StorytellerDefs/RimMindDirector.xml | 114 ++++++++++++++++++ Source/Storyteller/IncidentSelectionPolicy.cs | 7 ++ Source/Storyteller/RimMindIncidentSelector.cs | 7 +- .../StorytellerIncidentPolicyContracts.cs | 108 +++++++++++++++-- Tests/VerseStubs.cs | 6 +- 7 files changed, 293 insertions(+), 13 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ec3bc51..3f67fe0 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -171,6 +171,9 @@ jobs: --exclude='docs/' \ --exclude='*.csproj' \ --exclude='*.sln' \ + --exclude='.coderabbit.yaml' \ + --exclude='.pre-commit-config.yaml' \ + --exclude='INTRODUCTION.txt' \ --exclude='.gitignore' \ --exclude='.gitattributes' \ --exclude='*.md' \ diff --git a/About/About.xml b/About/About.xml index 6381850..99d25d1 100644 --- a/About/About.xml +++ b/About/About.xml @@ -8,7 +8,66 @@
  • 1.6
  • 1.7
  • - AI-powered storyteller that creates coherent narratives based on colony history and current situation. Requires RimMind Core. [v2.0 BREAKING CHANGES] + [h1]RimMind - Storyteller (v2.0)[/h1] +AI Story Director, dramatic tension curve engine, and causal narrative incident selector for RimWorld. Instead of rolling arbitrary raid dice based solely on wealth graphs, the AI Storyteller observes your colony's real history, emotional pacing, and unresolved conflicts to orchestrate multi-chapter sagas, bespoke lore letters, and interactive Storyteller Altar dialogues. + +[b]v2.0 Clean Architecture & RimWorld 1.6 / 1.7 Dual-Version Support:[/b] +[list] +[*][b]RimWorld 1.6 & 1.7 (Waylith / .NET 10) Ready[/b]: Native multi-target compilation supporting both RimWorld 1.6 (.NET Framework 4.8) and RimWorld 1.7 (.NET 10 / Harmony 2.x & 3.x). +[*][b]v2.0 Resilient Director Pipeline[/b]: Non-blocking request lifecycle coordination ([code]StorytellerRequestCoordinator[/code]) with 15,000-tick timeout protection, 2,500-tick failure backoff, and automatic truncated JSON repair. Note: v1.x saves are not compatible with v2.0. +[*][b]Full Vanilla Trader / Caravan / Quest Ecosystem Preserved[/b]: Combines AI narrative direction with vanilla RimWorld's complete orbital trader, faction caravan, visitor, and quest generation schedule so your colony economy and diplomacy thrive naturally. +[/list] + +[h2]What Is RimMind[/h2] +RimMind is an enterprise-grade, AI-powered RimWorld mod suite. Integrated with Large Language Models (LLM), it transforms colonists into self-reflecting agents with distinct personalities, three-tier memories, natural spoken dialogues, autonomous mechanisms, and dynamic storytelling. + +[h2]Sub-mod List & Dependency Relationships[/h2] +[table] +[tr][th]Mod[/th][th]Responsibility[/th][th]Dependencies[/th][th]GitHub[/th][/tr] +[tr][td]RimMind-Core[/td][td]LLM runtime, 4-Zone context engine, async queue, ToolCall registry & F8 Hub[/td][td]Harmony[/td][td][url=https://github.com/RimWorld-RimMind-Mod/RimWorld-RimMind-Mod-Core]Link[/url][/td][/tr] +[tr][td]RimMind-Actions[/td][td]Composite ToolCall mechanisms, battlefield triage & autonomous construction[/td][td]Core[/td][td][url=https://github.com/RimWorld-RimMind-Mod/RimWorld-RimMind-Mod-Actions]Link[/url][/td][/tr] +[tr][td]RimMind-Advisor[/td][td]Colonist self-reflective advice cards, 5-domain autonomy & player approval[/td][td]Core, Actions[/td][td][url=https://github.com/RimWorld-RimMind-Mod/RimWorld-RimMind-Mod-Advisor]Link[/url][/td][/tr] +[tr][td]RimMind-Dialogue[/td][td]Contextual spoken dialogue via express_dialogue ToolCall & speech bubbles[/td][td]Core[/td][td][url=https://github.com/RimWorld-RimMind-Mod/RimWorld-RimMind-Mod-Dialogue]Link[/url][/td][/tr] +[tr][td]RimMind-Memory[/td][td]3-Tier cognitive memory hierarchy, work aggregation & temporal decay[/td][td]Core[/td][td][url=https://github.com/RimWorld-RimMind-Mod/RimWorld-RimMind-Mod-Memory]Link[/url][/td][/tr] +[tr][td]RimMind-Personality[/td][td]Big-Five psychological profiles, dawn monologues & dynamic mood thoughts[/td][td]Core[/td][td][url=https://github.com/RimWorld-RimMind-Mod/RimWorld-RimMind-Mod-Personality]Link[/url][/td][/tr] +[tr][td][b]RimMind-Storyteller[/b][/td][td]AI Story Director, dramatic tension curve, chained arcs & Storyteller Altar[/td][td]Core, Memory[/td][td][url=https://github.com/RimWorld-RimMind-Mod/RimWorld-RimMind-Mod-Storyteller]Link[/url][/td][/tr] +[tr][td]RimMind-Extension-ModelService[/td][td]Multi-provider routing, Anthropic KV cache, local gateways & load balancing[/td][td]Core[/td][td][url=https://github.com/RimWorld-RimMind-Mod/RimWorld-RimMind-Mod-Extension-ModelService]Link[/url][/td][/tr] +[tr][td]RimMind-Bridge-RimChat[/td][td]RimChat compatibility bridge: dialogue/action mutual exclusion & context sync[/td][td]Core, RimChat[/td][td][url=https://github.com/RimWorld-RimMind-Mod/RimWorld-RimMind-Mod-Bridge-RimChat]Link[/url][/td][/tr] +[tr][td]RimMind-Bridge-RimTalk[/td][td]RimTalk compatibility bridge: bubble harmonization & bidirectional context[/td][td]Core, RimTalk[/td][td][url=https://github.com/RimWorld-RimMind-Mod/RimWorld-RimMind-Mod-Bridge-RimTalk]Link[/url][/td][/tr] +[/table] +[code]Core ──┬── Actions ── Advisor + ├── Dialogue + ├── Memory ── Storyteller + ├── Personality + ├── Extension-ModelService + ├── Bridge-RimChat + └── Bridge-RimTalk[/code] + +[h2]Core Features[/h2] +[list] +[*][b]AI Event Selection & Causal Lore Letters[/b] - Evaluates valid in-game [code]IncidentDef[/code] candidates ([code]CanFireNow[/code]) against your colony's recent history from [code]RimMind-Memory[/code], crafting custom incident letters that directly reference your colonists' past deeds. +[*][b]Dramatic Tension Curve ([code]StorytellerMemory[/code] & [code]TensionMath[/code])[/b] - Continuously tracks colony hardship, casualties, mood equilibrium, and daily tension decay to balance intense climaxes with earned recovery periods. +[*][b]Multi-Chapter Narrative Event Chains[/b] - Links incidents across multi-step story arcs ([code]chain_id[/code], [code]chain_step[/code], [code]chain_total[/code], [code]next_hint[/code]) with bounded threat-point multipliers and faction/raid strategy hints. +[*][b]Storyteller Altar & Agent Console[/b] - Build the in-game [b]Storyteller Altar[/b] to converse directly with the AI Story Director ([code]Window_StorytellerDialogue[/code]), negotiate your colony's fate, or inspect/steer narrative pacing via [code]Window_StorytellerAgentControl[/code]. +[*][b]Full Vanilla Trader / Caravan / Quest Ecosystem[/b] - Retains full vanilla storyteller [code]StorytellerComp[/code] schedules for orbital traders, allied trade caravans, hospitality visitors, and quests alongside AI-directed dramatic arcs. +[*][b]Intelligent Fallback Mode[/b] - If your LLM API is offline, rate-limited, or unconfigured, seamlessly falls back to balanced tension-aware incident selection so gameplay never stalls. +[/list] + +[h2]Storyteller Director Pipeline[/h2] +[table] +[tr][th]Stage[/th][th]Component[/th][th]Function[/th][/tr] +[tr][td]1. Memory & Tension[/td][td]StorytellerMemory / TensionMath[/td][td]Aggregates high-importance colony memories and computes current dramatic tension (0 to 100)[/td][/tr] +[tr][td]2. Candidate Filtering[/td][td]RimMindIncidentSelector[/td][td]Pre-filters valid IncidentDefs via CanFireNow and groups threats, blessings, and neutral events[/td][/tr] +[tr][td]3. Async LLM Direction[/td][td]StorytellerRequestCoordinator[/td][td]Dispatches non-blocking AI request with timeout & backoff guards[/td][/tr] +[tr][td]4. Parse & Fire[/td][td]StorytellerResponseParserPure[/td][td]Validates incident choice, clamps threat points, fires custom letter & records chain step[/td][/tr] +[/table] + +[h2]Frequently Asked Questions[/h2] +[b]Q: Will I still get regular trade caravans, orbital traders, and quests?[/b] +A: Yes! The AI Storyteller preserves the full vanilla trader, caravan, and quest generation ecosystem while directing narrative events and story chains on top. + +[b]Q: What happens if an AI request times out or my API key runs out?[/b] +A: [code]StorytellerRequestCoordinator[/code] automatically recovers from timeouts after 15,000 ticks and uses tension-balanced fallback selection so your campaign continues smoothly.
  • brrainz.harmony diff --git a/Defs/StorytellerDefs/RimMindDirector.xml b/Defs/StorytellerDefs/RimMindDirector.xml index 563f3b4..1dc404f 100644 --- a/Defs/StorytellerDefs/RimMindDirector.xml +++ b/Defs/StorytellerDefs/RimMindDirector.xml @@ -30,6 +30,120 @@ 5 6
  • +
  • + +
  • + RaidFriendly + 15 + 0.4 + true + High +
  • +
  • + TraderCaravanArrival + 5 + 5 + 6 + +
  • Map_PlayerHome
  • + + +
  • + VisitorGroup + 3 + 4 + 5 + +
  • Map_PlayerHome
  • + + +
  • + TravelerGroup + 1 + 6 + 1 + +
  • Map_PlayerHome
  • + + + +
  • + Misc + +
  • Caravan
  • +
  • Map_TempIncident
  • + + +
  • + ThreatSmall + true + +
  • Caravan
  • +
  • Map_TempIncident
  • + + +
  • + ThreatBig + true + +
  • Caravan
  • +
  • Map_TempIncident
  • + + + +
  • + GiveQuest + +
  • World
  • + + 10 + 1 + + +
  • (8, 0)
  • +
  • (15, 1)
  • +
    +
    + 3 + +
  • Ludeon.RimWorld.Royalty
  • +
    + + +
  • + GiveQuest + +
  • World
  • + + 12 + 2 + + +
  • (8, 0)
  • +
  • (15, 1)
  • +
    +
    + 3 + +
  • Ludeon.RimWorld.Royalty
  • +
    + + +
  • + Misc + +
  • World
  • + + 15 + 15 + + +
  • + OrbitalTraderArrival + 7 + 8 + 1 +
  • StrangerInBlackJoin diff --git a/Source/Storyteller/IncidentSelectionPolicy.cs b/Source/Storyteller/IncidentSelectionPolicy.cs index b6d55df..89bd18b 100644 --- a/Source/Storyteller/IncidentSelectionPolicy.cs +++ b/Source/Storyteller/IncidentSelectionPolicy.cs @@ -20,5 +20,12 @@ public static bool ShouldNotify( => notificationsEnabled && (kind == StorytellerIncidentKind.ThreatBig || kind == StorytellerIncidentKind.ThreatSmall); + + public static bool RequiresHostileFaction( + string? incidentDefName, + string? categoryDefName) + => (string.Equals(categoryDefName, "ThreatBig", StringComparison.Ordinal) + || string.Equals(categoryDefName, "ThreatSmall", StringComparison.Ordinal)) + && !string.Equals(incidentDefName, "RaidFriendly", StringComparison.Ordinal); } } diff --git a/Source/Storyteller/RimMindIncidentSelector.cs b/Source/Storyteller/RimMindIncidentSelector.cs index 8a07c8f..61fd691 100644 --- a/Source/Storyteller/RimMindIncidentSelector.cs +++ b/Source/Storyteller/RimMindIncidentSelector.cs @@ -39,9 +39,14 @@ public static (FiringIncident? incident, IncidentResponse? response) ParseRespon if (!string.IsNullOrEmpty(result.@params.faction_hint)) { + bool requiresHostile = IncidentSelectionPolicy.RequiresHostileFaction( + incidentDef.defName, + incidentDef.category?.defName); var faction = Find.FactionManager.AllFactions .FirstOrDefault(f => f.def.defName == result.@params.faction_hint - && f.HostileTo(Faction.OfPlayer)); + && (requiresHostile + ? f.HostileTo(Faction.OfPlayer) + : !f.IsPlayer && !f.HostileTo(Faction.OfPlayer) && !f.defeated)); if (faction != null) parms.faction = faction; } diff --git a/Tests/Contracts/StorytellerIncidentPolicyContracts.cs b/Tests/Contracts/StorytellerIncidentPolicyContracts.cs index 99c8492..f5237c9 100644 --- a/Tests/Contracts/StorytellerIncidentPolicyContracts.cs +++ b/Tests/Contracts/StorytellerIncidentPolicyContracts.cs @@ -1,6 +1,8 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; +using System.Xml.Linq; using RimMind.Storyteller.Extensions; using RimMind.Storyteller.Memory; using RimMind.Testing; @@ -20,7 +22,8 @@ public void Stable_incident_policy_boundaries() ("truncated and trailing comma responses are repaired", RecoverableResponsesAreRepaired), ("empty malformed and missing def names become no incident", InvalidResponsesBecomeNoIncident), ("pawn lookup rejects invalid ids before world then map lookup", PawnLookupOrderRemainsStable), - ("only threat categories notify the player", NotificationPolicyRemainsNarrow)); + ("only threat categories notify the player", NotificationPolicyRemainsNarrow), + ("director xml includes vanilla trade visitors and random quest comps", DirectorDefIncludesVanillaEcosystemComps)); } private static void ValidResponsesRetainMetadata() @@ -141,19 +144,64 @@ public void Incident_parameters_are_bounded_before_worker_validation(float multi [Fact] public void Nonhostile_faction_and_unknown_strategy_hints_do_not_override_defaults() { - var definition = new IncidentDef { defName = "RaidEnemy" }; + var raidDef = new IncidentDef { defName = "RaidEnemy" }; + raidDef.category.defName = "ThreatBig"; + var caravanDef = new IncidentDef { defName = "TraderCaravanArrival" }; + caravanDef.category.defName = "FactionArrival"; + var friendlyRaidDef = new IncidentDef { defName = "RaidFriendly" }; + friendlyRaidDef.category.defName = "ThreatBig"; + var ally = new Faction { IsHostile = false }; - ally.def.defName = "Ally"; - DefDatabase.Definitions[definition.defName] = definition; + ally.def.defName = "OutlanderCivil"; + var defeatedAlly = new Faction { IsHostile = false, defeated = true }; + defeatedAlly.def.defName = "DefeatedCivil"; + var pirate = new Faction { IsHostile = true }; + pirate.def.defName = "Pirate"; + + DefDatabase.Definitions[raidDef.defName] = raidDef; + DefDatabase.Definitions[caravanDef.defName] = caravanDef; + DefDatabase.Definitions[friendlyRaidDef.defName] = friendlyRaidDef; Find.FactionManager.AllFactions.Add(ally); + Find.FactionManager.AllFactions.Add(defeatedAlly); + Find.FactionManager.AllFactions.Add(pirate); try { - var (incident, _) = RimMindIncidentSelector.ParseResponse( - "{\"defName\":\"RaidEnemy\",\"params\":{\"faction_hint\":\"Ally\",\"raid_strategy_hint\":\"Unknown\"}}", + Assert.True(IncidentSelectionPolicy.RequiresHostileFaction("RaidEnemy", "ThreatBig")); + Assert.True(IncidentSelectionPolicy.RequiresHostileFaction("ManhunterPack", "ThreatSmall")); + Assert.False(IncidentSelectionPolicy.RequiresHostileFaction("RaidFriendly", "ThreatBig")); + Assert.False(IncidentSelectionPolicy.RequiresHostileFaction("TraderCaravanArrival", "FactionArrival")); + Assert.False(IncidentSelectionPolicy.RequiresHostileFaction("OrbitalTraderArrival", "OrbitalVisitor")); + + var (raidIncident, _) = RimMindIncidentSelector.ParseResponse( + "{\"defName\":\"RaidEnemy\",\"params\":{\"faction_hint\":\"OutlanderCivil\",\"raid_strategy_hint\":\"Unknown\"}}", new Map(), new StorytellerComp()); - Assert.NotNull(incident); - Assert.Null(incident!.parms.faction); - Assert.Null(incident.parms.raidStrategy); + Assert.NotNull(raidIncident); + Assert.Null(raidIncident!.parms.faction); + Assert.Null(raidIncident.parms.raidStrategy); + + var (caravanIncident, _) = RimMindIncidentSelector.ParseResponse( + "{\"defName\":\"TraderCaravanArrival\",\"params\":{\"faction_hint\":\"OutlanderCivil\"}}", + new Map(), new StorytellerComp()); + Assert.NotNull(caravanIncident); + Assert.Same(ally, caravanIncident!.parms.faction); + + var (hostileCaravanIncident, _) = RimMindIncidentSelector.ParseResponse( + "{\"defName\":\"TraderCaravanArrival\",\"params\":{\"faction_hint\":\"Pirate\"}}", + new Map(), new StorytellerComp()); + Assert.NotNull(hostileCaravanIncident); + Assert.Null(hostileCaravanIncident!.parms.faction); + + var (defeatedCaravanIncident, _) = RimMindIncidentSelector.ParseResponse( + "{\"defName\":\"TraderCaravanArrival\",\"params\":{\"faction_hint\":\"DefeatedCivil\"}}", + new Map(), new StorytellerComp()); + Assert.NotNull(defeatedCaravanIncident); + Assert.Null(defeatedCaravanIncident!.parms.faction); + + var (friendlyRaidIncident, _) = RimMindIncidentSelector.ParseResponse( + "{\"defName\":\"RaidFriendly\",\"params\":{\"faction_hint\":\"OutlanderCivil\"}}", + new Map(), new StorytellerComp()); + Assert.NotNull(friendlyRaidIncident); + Assert.Same(ally, friendlyRaidIncident!.parms.faction); } finally { @@ -240,6 +288,48 @@ private static void NotificationPolicyRemainsNarrow() false, StorytellerIncidentKind.ThreatBig)); } + private static void DirectorDefIncludesVanillaEcosystemComps() + { + var dir = new DirectoryInfo(AppContext.BaseDirectory); + while (dir != null && !File.Exists(Path.Combine(dir.FullName, "Defs", "StorytellerDefs", "RimMindDirector.xml"))) + { + string candidate = Path.Combine(dir.FullName, "RimMind-Storyteller", "Defs", "StorytellerDefs", "RimMindDirector.xml"); + if (File.Exists(candidate)) + { + dir = new DirectoryInfo(Path.Combine(dir.FullName, "RimMind-Storyteller")); + break; + } + dir = dir.Parent; + } + + Assert.NotNull(dir); + string xmlPath = Path.Combine(dir!.FullName, "Defs", "StorytellerDefs", "RimMindDirector.xml"); + XDocument doc = XDocument.Load(xmlPath); + var comps = doc.Root! + .Elements("StorytellerDef") + .Single(e => e.Element("defName")?.Value == "RimMindDirector") + .Element("comps")! + .Elements("li") + .ToList(); + + var incidents = comps + .Select(c => c.Element("incident")?.Value) + .Where(v => !string.IsNullOrEmpty(v)) + .ToHashSet(StringComparer.Ordinal); + var classes = comps + .Select(c => c.Attribute("Class")?.Value) + .Where(v => !string.IsNullOrEmpty(v)) + .ToHashSet(StringComparer.Ordinal); + + Assert.Contains("TraderCaravanArrival", incidents); + Assert.Contains("VisitorGroup", incidents); + Assert.Contains("TravelerGroup", incidents); + Assert.Contains("RaidFriendly", incidents); + Assert.Contains("OrbitalTraderArrival", incidents); + Assert.Contains("StorytellerCompProperties_RandomQuest", classes); + Assert.Contains("StorytellerCompProperties_ShipChunkDrop", classes); + } + private sealed class TestPawn { public TestPawn(int id, string source) diff --git a/Tests/VerseStubs.cs b/Tests/VerseStubs.cs index 6bb277c..ce63e64 100644 --- a/Tests/VerseStubs.cs +++ b/Tests/VerseStubs.cs @@ -85,7 +85,7 @@ public sealed class Difficulty public bool allowViolentQuests = true; } public sealed class Storyteller { public Difficulty difficulty { get; } = new(); } - public sealed class IncidentCategoryDef { } + public sealed class IncidentCategoryDef { public string defName = "ThreatBig"; } public sealed class IncidentDef { public string defName = ""; @@ -111,9 +111,11 @@ public sealed class IncidentParms public sealed class FactionDef { public string defName = ""; } public sealed class Faction { - public static Faction OfPlayer { get; } = new(); + public static Faction OfPlayer { get; } = new() { IsPlayer = true }; public FactionDef def { get; } = new(); + public bool IsPlayer; public bool IsHostile; + public bool defeated; public bool HostileTo(Faction other) => IsHostile; } public sealed class FactionManager { public List AllFactions { get; } = new(); }