Skip to main content

Module tool_lifecycle

Module tool_lifecycle 

Source
Expand description

Shared tool lifecycle — ensures CLI and MCP paths have identical side effects.

The MCP server dispatcher handles session, ledger, heatmap, intent detection, and knowledge consolidation inline (via in-memory state). When the daemon is unavailable, CLI commands call functions here to achieve the same coverage by loading/saving state from disk.

NOTE: When the daemon IS running, CLI routes through daemon_client which calls the MCP server — these functions are NOT called in that path.

Functions§

flush_all
Flush every buffered telemetry sink to disk.
flush_all_at_exit
flush_all for a process that is about to exit: first commits the provisional bounces still waiting for their edit window, so a bounce detected just before shutdown reaches the ledger and the path memory that flush_all then persists. Not part of flush_all itself, which also runs after single tool executions where committing early would book a read-before-edit as a bounce.
ir_excerpt
First 200 chars of text on a UTF-8 boundary — the exact excerpt bound the MCP dispatcher applies before handing content to the IR store (server/call_tool.rs), kept identical so CLI- and MCP-recorded IR items are byte-compatible. ContextIrV1::record redacts and further caps it.
record_file_read
Record a file-read operation with full Context OS side effects.
record_file_read_accounting
Compatibility accounting without IR persistence or an independent flush. The CLI lifecycle calls this once in its accounting stage.
record_file_read_projection
record_search_accounting
Existing search bookkeeping, separated from the IR writer for stage ownership.
record_tree
Record a tree/ls operation with full Context OS side effects.