feat: CodeSnippet extraction and Message.snippets in session model (F4.2) #39
Notifications
Due Date
No due date set.
Blocks
#5 feat: Implement Tantivy-based session index for full-text search
terraphim/agent-tasks
Reference: terraphim/agent-tasks#39
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem Statement
Spec section F4.2 Session Data Model defines a first-class
CodeSnippettype alongsideMessage.snippets: Vec<CodeSnippet>:This shape is what F4.3 relies on: the Tantivy
code_contentfield (separate fromcontent) needs canonical code blocks, and the spec's edge-n-gram tokenizer for code patterns is meaningless without them. Issue #5 ("Tantivy session index") therefore depends on this data being present.Today,
crates/terraphim_sessions/src/model.rslacks aCodeSnippetstruct entirely.Messagecarriesblocks: Vec<ContentBlock>whereText { text }blends prose and fenced code, andToolUse/ToolResultlose code structure. Connectors (Aider markdown, Claude JSONL, Cursor SQLite, Cline JSON) all parse code fences, throw the language tag away, and append the raw text intocontent. Downstream concept enrichment (SessionEnricher) sees no language signal, and the plannedcode_contentindex has nothing to consume.Acceptance Criteria
pub struct CodeSnippetincrates/terraphim_sessions/src/model.rswith the four fields above plusSerialize/Deserialize/Debug/CloneMessage.snippets: Vec<CodeSnippet>(default empty via#[serde(default)]) without removingblocksMessage::extract_snippets_from_blocks(&self) -> Vec<CodeSnippet>that pulls fenced code fromTextblocks (use existingterraphim_markdown_parserfor fence parsing)NativeClaudeConnector,AiderConnector, andClineConnectorto populatesnippetsafter parsing each messagecode_blocks: boolinSessionMetadata(already present ashas_codein spec) becomesmetadata.has_code = !snippets.is_empty()in the connectors that didn't set itcargo test -p terraphim_sessions model::tests::code_snippet*passes (fence parsing, language detection forrust/python/none)cargo test -p terraphim_sessionspassescargo clippy -p terraphim_sessions -- -D warningspassesProposed Approach
Crates affected:
crates/terraphim_sessionsonly. No public API breakage outside the workspace because the field is additive with#[serde(default)].Files to add/modify:
crates/terraphim_sessions/src/model.rs-- addCodeSnippet, extendMessage, add extraction helpercrates/terraphim_sessions/src/connector/native.rs-- populate snippets when parsing Claude JSONLtextcontentcrates/terraphim_sessions/src/connector/aider.rs-- already callsterraphim_markdown_parser; capture fenced blocks intoCodeSnippetcrates/terraphim_sessions/src/connector/cline.rs-- detect code fences in message content (Cline messages are markdown)Key extraction logic: Use a regex like
(?s)```(\w*)\n(.*?)```` to split fenced blocks; first capture is the language tag (empty ->None), second is the content.file_pathandline_rangestayNone` for now -- they require connector-specific tool-use parsing which is a follow-up.Dependencies
None. Blocks #5 (Tantivy index) -- when this lands, #5 can index
code_contentfromMessage.snippets[].contentjoined per session.After merge, run
gitea-robot add-dep --owner terraphim --repo agent-tasks --issue 5 --blocks <THIS>to record the edge.Verification
Manual smoke test:
Scope
Single PR, ~300-400 lines including tests and connector wiring. Do not change the Tantivy index, do not add
file_path/line_rangeconnector parsing -- both are explicit follow-ups to keep this PR reviewable.