# Remove Dead DM-History Helper Functions in `agent.c` ## Background While investigating how Didactyl maintains continuity across a DM "chat session", two functions in [`src/agent.c`](../src/agent.c) were found to be compiled-but-unreferenced, marked with `__attribute__((unused))` to suppress compiler warnings: - [`append_recent_admin_dm_history`](../src/agent.c:1065) - [`build_recent_admin_dm_history_messages`](../src/agent.c:1800) (wraps the above) These were part of an older design where the agent automatically injected the last N admin DM turns into every LLM call. The current architecture is **skill-driven**: DM history only reaches the LLM when an adopted, triggered skill explicitly pulls it in via the `{{dm_history}}` / `{{nostr_dm_history(...)}}` template variables or the `nostr_dm_history` tool (see [`tool_agent.c`](../src/tools/tool_agent.c:284) and [`tools_schema.c`](../src/tools/tools_schema.c:1606)). The dead functions are now a source of confusion for anyone reading the code to understand chat-session behavior. ## Goal Remove the dead functions and any symbols used exclusively by them, without changing runtime behavior. ## Scope Analysis (verified before planning) A repo-wide search for each symbol confirmed the following: | Symbol | Only callers | Disposition | |---|---|---| | [`append_recent_admin_dm_history`](../src/agent.c:1065) | called by `build_recent_admin_dm_history_messages` (also dead) | **delete** | | [`build_recent_admin_dm_history_messages`](../src/agent.c:1800) | no callers | **delete** | | [`AGENT_HISTORY_TURNS`](../src/agent.c:38) | referenced only inside the dead `append_recent_admin_dm_history` | **delete** | | [`AGENT_HISTORY_QUERY_LIMIT`](../src/agent.c:39) | defined but zero references repo-wide | **delete** | | [`append_simple_message`](../src/agent.c:187) | many live callers throughout `agent.c` | **keep** | | [`nostr_handler_get_dm_history_json`](../src/nostr_handler.c:4384) | live via [`tool_agent.c`](../src/tools/tool_agent.c:318) | **keep** | No non-source references (Makefile, tests, docs) depend on these symbols. ## Risks Very low. Both functions carry `__attribute__((unused))` so they are not linked into any runtime path. The only failure modes are accidental deletion of something still live, which the scope analysis above rules out. ## Verification Strategy 1. Clean build with `make` — must succeed with no new warnings. 2. Existing tests under [`tests/`](../tests/) pass (`python tests/run_tests.py` or the project's usual invocation). 3. Manual sanity check: start an agent, send a DM, confirm normal reply — no regression, since the deleted code was never on the hot path. ## Mermaid: before/after ```mermaid flowchart LR subgraph Before A1[agent.c dead funcs] -. unused attr .- B1[compiler silences warning] A1 --> C1[reader assumes auto DM history replay] C1 --> D1[confusion about session behavior] end subgraph After A2[agent.c clean] --> E2[skill-driven history only] E2 --> F2[intent matches code] end ``` ## Follow-on (out of scope for this change) The documentation in [`docs/CONTEXT.md`](../docs/CONTEXT.md) already describes the skill-driven assembly model correctly, but neither that file nor [`docs/SKILLS.md`](../docs/SKILLS.md) explicitly states "DM history is not automatic — it only appears when a skill references it." A brief clarifying paragraph could be added in a separate change.