Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

3 changes: 3 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
name: Unit Tests

on:
workflow_dispatch:
push:
branches: [main, master]
paths:
- 'Source/**'
- 'Tests/**'
- 'IntegrationTests/**'
- 'ArchTests/**'
- '.github/workflows/test.yml'
pull_request:
branches: [main, master]
paths:
- 'Source/**'
- 'Tests/**'
- 'IntegrationTests/**'
- 'ArchTests/**'
- '.github/workflows/test.yml'

Expand Down
24 changes: 13 additions & 11 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,50 +8,51 @@ AI对话系统,拦截游戏事件生成上下文对话,注入Thought,支

## 项目定位

通过Harmony Patch监听Chitchat/Hediff/技能升级/心情变化 → `RimMindDialogueService.HandleTrigger` → `DialogueRequestCoordinator`(挂载 `DialogueToolDefinitions.ExpressDialogue` 原生工具定义) → `RimMindAPI.Request.Send` → `NpcResponseHandler.Handle`(调用 `DialogueToolParser.Parse` 与 `DialogueTextSanitizer` 防污染清洗解析 `reply`/`thought`/`relation_delta`) → `ThoughtInjector` 注入独白/关系Thought。请求、活动状态、日志和响应副作用各有单一入口。
通过Harmony Patch监听Chitchat/Hediff/技能升级/心情变化 → `RimMindDialogueService.HandleTrigger` → `DialogueRequestCoordinator`(挂载 `DialogueToolDefinitions.ExpressDialogueTool` 原生工具定义,自动触发附带 `CoalesceKey`、`MaxQueueWaitTicks=5000` 与 `RequireAliveColonist=true`) → `RimMindAPI.Request.Send` → `NpcResponseHandler.Handle`(调用 `DialogueToolParser.TryParse` 与 `DialogueTextSanitizer` 防污染清洗解析 `speech`/`thought_tag`/`thought_desc`/`relation_delta`) → `ThoughtInjector` 注入独白/关系Thought。请求、活动状态、触发元数据、日志和响应副作用各有单一入口。

依赖: Core(编译期)。可选 Memory 集成使用 Core 公共 `RimMindAPI.Memory`,不引用 Memory 实现程序集。

## 构建

| 项 | 值 |
|----|-----|
| Target | net48, C#9.0, Nullable enable |
| Output | `../1.6/Assemblies/` |
| Target | `net48` (1.6) / `net10.0` (1.7), C#9.0, Nullable enable |
| Output | `../$(GameVersion)/Assemblies/` |
| Assembly | RimMindDialogue, RootNS: RimMind.Dialogue |
| Harmony ID | mcocdaa.RimMindDialogueStandalone |
| 依赖 | RimMindCore.dll, Krafs.Rimworld.Ref, Lib.Harmony.Ref, Newtonsoft.Json |
| 依赖 | 0_RimMindDomain.dll, 1_RimMindApplication.dll, 2_RimMindCore.dll (`Private=false`), Krafs.Rimworld.Ref, Lib.Harmony.Ref, Newtonsoft.Json |

## 源码结构

```
Source/
├── RimMindDialogueMod.cs 组合入口、Harmony与Core扩展注册
├── RimMindDialogueMod.cs 组合入口、Harmony与Core扩展注册(含 DialogueRequestTraceSummarizer)
├── Core/
│ ├── DialogueContextProviderRegistrar.cs 四个Core上下文Provider的唯一注册入口(经 MainThreadSnapshot 主线程读取)
│ ├── DialogueTriggerRegistry.cs TriggerType元数据单一事实来源(TriggerKind/Label/Prompt/LogColor + 自定义标签)
│ ├── README.md 对话生命周期入口地图
│ ├── RimMindDialogueService.cs 公共兼容门面与轻量事件边界
│ ├── DialogueRequestCoordinator.cs 请求门控、派发与完成清理
│ ├── DialogueActivityState.cs 冷却、配额、接收者与Pawn查询(委托 RimMindPawnLookup)
│ ├── DialogueActivityState.cs 冷却(KeyedCooldownGate)、配额、接收者与Pawn查询(委托 RimMindPawnLookup)
│ ├── DialogueLogStore.cs 按时间与序列号有序的有界日志(List + _sync锁, 上限500)与 Revision 版本号
│ ├── DialogueService.cs 玩家兼容入口,直接进入同一请求协调器
│ ├── DialogueToolDefinitions.cs express_dialogue 原生 ToolCall 定义
│ ├── DialogueToolParser.cs 双模式工具调用解析器(优先 ToolCalls,回退结构化内容)
│ ├── DialogueTextSanitizer.cs 多级防污染文本清洗管线(剥离 <think>/代码围栏/裸JSON)
│ ├── NpcResponseHandler.cs 统一响应处理(自动+玩家对话共用,含感知发布与存活/倒地校验)
├── Comps/CompRimMindDialogue.cs ThingComp(RimMindPawnLookup.IsEligibleColonist + Awake 过滤, 1000tick检查)
├── Comps/CompRimMindDialogue.cs ThingComp(RimMindPawnLookup.IsEligibleColonist + Awake 过滤, 250tick采样)
├── Extensions/ Core扩展适配器(SkipCheck/ModCooldown/SettingsTab/OverlayToggle/TriggerAdapter/RequestTraceSummarizer)
├── UI/Window_Dialogue.cs / Window_DialogueLog.cs / DialogueOverlay.cs
├── Thoughts/ThoughtInjector.cs + Thought_RimMindDialogue.cs + Thought_RelationDialogue.cs
├── Patches/ 7个Patch(Bubble/Hediff/SkillLearn/Thought/FloatMenu/GameLoad/AddComp)
├── Debug/DialogueDebugActions.cs 调试操作(Force触发/状态查看/冷却清除)
└── Settings/
├── RimMindDialogueSettings.cs 设置模型与持久化
└── DialogueSettingsDrawer.cs 设置页UI绘制(全Tooltip提示)
└── RimMindDialogueSettings.cs 设置模型、持久化与设置页UI绘制(委托 SettingsUIDrawer)
```

## 统一请求生命周期

自动触发通过 `RimMindDialogueService.HandleTrigger`,玩家输入通过 `DialogueService.RequestReply`,两者直接进入同一个 `DialogueRequestCoordinator`:总开关(玩家另查玩家开关)→ 参与者有效性(`RimMindPawnLookup.IsEligibleColonist` 且 `!Downed`)→ API配置 → IsReady → Pawn pending → ShouldSkipDialogue → 自动冷却/配额策略 → 原子 Pawn/Pair/全局容量预约 → 唯一 `RimMindAPI.Request.Send`(携带 `DialogueToolDefinitions.ExpressDialogue`)。
自动触发通过 `RimMindDialogueService.HandleTrigger`,玩家输入通过 `DialogueService.RequestReply`,两者直接进入同一个 `DialogueRequestCoordinator`:总开关(玩家另查玩家开关)→ 参与者有效性(`RimMindPawnLookup.IsActiveSpawnedColonist` 且 `!Downed`)→ API配置 → IsReady → Pawn pending → ShouldSkipDialogue → 自动冷却/配额策略 → 原子 Pawn/Pair/全局容量预约 → 唯一 `RimMindAPI.Request.Send`(携带 `DialogueToolDefinitions.ExpressDialogueTool`)。

玩家多轮输入不消耗自动每日配额或独白冷却;自动 A-B 回复仍连续进行,由独立 pair reply limiter 限制。

Expand All @@ -67,13 +68,14 @@ Source/
| CONNECTED | +2 | RimMind.Dialogue.Thought.CONNECTED | 感到亲近 |
| STRESSED | -2 | RimMind.Dialogue.Thought.STRESSED | 感到压力 |
| IRRITATED | -1 | RimMind.Dialogue.Thought.IRRITATED | 感到烦躁 |
| INSPIRED | +2 | RimMind.Dialogue.Thought.INSPIRED | 深受鼓舞 |

外部mod可通过 `ThoughtInjector.RegisterThoughtTag(tag, moodOffset, labelKey)` 注册自定义标签。

## 上下文注入

- `dialogue_state` / `dialogue_relation`: ContextKeyRegistry(L3_State),通过 `RimMindAPI.MainThreadSnapshot.GetAsync` 在主线程读取思绪与社交关系
- `dialogue_task`: ContextKeyRegistry(L0_Static, 仅 `ScenarioIds.Dialogue`, `SpeakerName` 为空时通过主线程快照构建 TaskInstruction)
- `dialogue_task`: ContextKeyRegistry(L0_Static, 覆盖 `ScenarioIds.Dialogue` 与 `ScenarioIds.CrisisDialogue`,按 `IsMonologue`/`SpeakerName` 动态组装 TaskInstruction)
- `dialogue_history`: ContextKeyRegistry(L4_History),通过主线程快照读取最近相关对话历史

> 注:原 `player_dialogue_task` provider 已于 2026-07-08 审查删除——Core 的 `ContextOrchestrator` 在所有 `BuildContext` 构造路径中将 `SpeakerName` 硬编码为 null,该 provider 触发条件(SpeakerName 非空)永不满足,属不可达死代码。归档于 `Refs/backup/RimMind-Dialogue/RimMindDialogueMod.player_dialogue_task.cs`。
Expand Down
8 changes: 4 additions & 4 deletions About/About.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Contextual social dialogue, native spoken ToolCalls, and overhead speech bubble
[b]v2.0 Clean Architecture &amp; RimWorld 1.6 / 1.7 Dual-Version Support:[/b]
[list]
[*][b]RimWorld 1.6 &amp; 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 &amp; 3.x).
[*][b]v2.0 Native [code]express_dialogue[/code] ToolCall Pipeline[/b]: Transmits spoken lines ([code]reply[/code]), inner psychological subtext ([code]thought[/code]), and relationship delta ([code]relation_delta[/code]) as structured tool calls. Note: v1.x saves are not compatible with v2.0.
[*][b]v2.0 Native [code]express_dialogue[/code] ToolCall Pipeline[/b]: Transmits spoken lines ([code]speech[/code]), inner psychological subtext ([code]thought_tag[/code] / [code]thought_desc[/code]), and relationship delta ([code]relation_delta[/code]) as structured tool calls. Note: v1.x saves are not compatible with v2.0.
[*][b]Multi-Stage Anti-Pollution Sanitizer[/b]: [code]DialogueTextSanitizer[/code] strips [code]think[/code] reasoning blocks, code fences, and raw JSON fragments so overhead speech bubbles remain 100% clean and immersive.
[/list]

Expand All @@ -29,7 +29,7 @@ RimMind is an enterprise-grade, AI-powered RimWorld mod suite. Integrated with L
[tr][td]RimMind-Advisor[/td][td]Colonist self-reflective advice cards, 5-domain autonomy &amp; 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][b]RimMind-Dialogue[/b][/td][td]Contextual spoken dialogue via express_dialogue ToolCall &amp; 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 &amp; 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 &amp; 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]RimMind-Personality[/td][td]LLM psychological profiles, state-transition reflections &amp; 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]RimMind-Storyteller[/td][td]AI Story Director, dramatic tension curve, chained arcs &amp; 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 &amp; 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 &amp; context sync[/td][td]Core, RimChat[/td][td][url=https://github.com/RimWorld-RimMind-Mod/RimWorld-RimMind-Mod-Bridge-RimChat]Link[/url][/td][/tr]
Expand All @@ -47,7 +47,7 @@ RimMind is an enterprise-grade, AI-powered RimWorld mod suite. Integrated with L
[list]
[*][b]Event-Responsive &amp; Proximity Banter[/b] - Replaces vanilla Chitchat and DeepTalk with context-aware AI conversations when awake colonists are within 6.9 tiles during dining, crafting, or relaxation, plus monologues on injuries, skill milestones, and mood swings.
[*][b]Player-Initiated Multi-Turn Chat[/b] - Start direct conversations via pawn Gizmo buttons or right-click menus with persistent session memory.
[*][b]Dynamic Relationship &amp; Thought Injection[/b] - Conversations apply real-time social opinion modifiers (-5 to +5) and inject emotional Thoughts ([i]ENCOURAGED, VALUED, CONNECTED, HURT, STRESSED, IRRITATED[/i]) that affect colonist mood and notify [code]RimMind-Advisor[/code].
[*][b]Dynamic Relationship &amp; Thought Injection[/b] - Conversations apply real-time social opinion modifiers (-5 to +5) and inject emotional Thoughts ([i]ENCOURAGED, VALUED, CONNECTED, INSPIRED, HURT, STRESSED, IRRITATED[/i]) that affect colonist mood and notify [code]RimMind-Advisor[/code].
[*][b]Strict Liveness &amp; Consciousness Gating[/b] - Guarded by [code]RimMindPawnLookup[/code] so sleeping, downed, dead, imprisoned, or off-map pawns never emit ghost dialogues.
[*][b]Draggable Floating Chat HUD &amp; History Log[/b] - Real-time corner dialogue overlay with adjustable opacity, plus a categorized dual-panel conversation log window.
[/list]
Expand All @@ -65,7 +65,7 @@ RimMind is an enterprise-grade, AI-powered RimWorld mod suite. Integrated with L
[h2]Thought Tags &amp; Mood Impacts[/h2]
[table]
[tr][th]Tag[/th][th]Mood Offset[/th][th]Description[/th][/tr]
[tr][td]VALUED / CONNECTED[/td][td]+2[/td][td]Feeling appreciated and emotionally close to companions[/td][/tr]
[tr][td]VALUED / CONNECTED / INSPIRED[/td][td]+2[/td][td]Feeling appreciated, emotionally close, or deeply inspired[/td][/tr]
[tr][td]ENCOURAGED[/td][td]+1[/td][td]Reassured by supportive words[/td][/tr]
[tr][td]HURT / IRRITATED[/td][td]-1[/td][td]Stung or annoyed by friction in conversation[/td][/tr]
[tr][td]STRESSED[/td][td]-2[/td][td]Weighed down by tense exchanges[/td][/tr]
Expand Down
90 changes: 0 additions & 90 deletions INTRODUCTION.txt

This file was deleted.

Loading