3.4 KiB
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 were found to be compiled-but-unreferenced, marked with __attribute__((unused)) to suppress compiler warnings:
append_recent_admin_dm_historybuild_recent_admin_dm_history_messages(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 and tools_schema.c). 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 |
called by build_recent_admin_dm_history_messages (also dead) |
delete |
build_recent_admin_dm_history_messages |
no callers | delete |
AGENT_HISTORY_TURNS |
referenced only inside the dead append_recent_admin_dm_history |
delete |
AGENT_HISTORY_QUERY_LIMIT |
defined but zero references repo-wide | delete |
append_simple_message |
many live callers throughout agent.c |
keep |
nostr_handler_get_dm_history_json |
live via tool_agent.c |
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
- Clean build with
make— must succeed with no new warnings. - Existing tests under
tests/pass (python tests/run_tests.pyor the project's usual invocation). - 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
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 already describes the skill-driven assembly model correctly, but neither that file nor 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.