feat: /sessions export command for markdown/json session sharing (F4.4) #33
Notifications
Due Date
No due date set.
Depends on
#26 feat: redact api keys/secrets/JWTs during session import (Privacy)
terraphim/agent-tasks
Reference: terraphim/agent-tasks#33
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
The
terraphim-agent-session-search-spec.md(section F4.4 "Session Commands") mandates a/sessions exportcommand for sharing and offline use of imported coding-assistant sessions:The Phase 3 success criterion claims
[x] Timeline and export, yet a repository-wide grep confirms zeroExport/exportsymbols insidecrates/terraphim_sessions/src/orcrates/terraphim_agent/src/repl/. Users currently have no first-class way to extract a single session, a filtered subset, or the full corpus -- they must hand-roll SQL or read JSONL. This blocks downstream review workflows, reproducibility audits, and the Reporting pipeline used bycodebase-eval.Acceptance Criteria
SessionsSubcommand::Exportaccepts:--format markdown|json|jsonl(required, defaultmarkdown)--output <path>(required when targeting multiple sessions)--session-id <id>(optional; mutually exclusive with--source/--sincefilters)--source <name>(optional filter)--since <iso8601>(optional filter; reuses the parser fromsessions search --after)# Session: <title>headings, fenced code blocks perCodeSnippetwith the language tag, and a YAML front-matter block holdingsession_id,source,created_at,message_count,conceptsSessiondocument;jsonlwriter emits one session per line for streaming--outputis omitted; multi-session export requires--outputand refuses to overwrite without--forceRobotResponse<ExportSummary { sessions_written: usize, bytes_written: u64, output_path: Option<PathBuf> }>and exit code 4 (ERROR_NOT_FOUND) when no sessions match the filters--since, refusal to overwrite, format enum round-tripcargo test -p terraphim_agent --features repl-full,repl-sessionspassescargo clippy -p terraphim_agent --features repl-full,repl-sessions -- -D warningspassesProposed Approach
Affected crates:
crates/terraphim_sessions/-- addpub mod exportwithpub fn write_markdown(session: &Session, out: &mut dyn Write) -> Result<usize>, JSON / JSONL counterparts, and apub struct ExportRequest { format, filter, output }that the REPL handler builds.crates/terraphim_agent/src/repl/commands.rs-- extendSessionsSubcommandwithExport(ExportArgs)clap variant.crates/terraphim_agent/src/repl/handler.rs-- newhandle_sessions_exportbranch inhandle_sessions.Markdown layout follows the existing
terraphim-session-analyzerreporter style so the two outputs remain visually consistent. No new dependencies; reusesserde_json,serde_yaml(already in the workspace via the manifest loader).Dependencies
None. The data model (
Session,Message,CodeSnippet) and theSessionServicequery layer are already in place.Verification
Smoke test (after build):
Scope
Single PR, approximately 350 LOC: ~120 LOC formatter (markdown), ~60 LOC JSON/JSONL writers, ~80 LOC clap variant + handler, ~90 LOC tests + fixtures. Watch-mode export, S3 sinks, and HTML/PDF formats are explicitly out of scope.