Skip to content

feat: add /export slash command for session Markdown - #45

Merged
aakashrajput merged 2 commits into
KlaatAI:mainfrom
Ayush7614:feat/export-session-markdown
Jul 21, 2026
Merged

feat: add /export slash command for session Markdown#45
aakashrajput merged 2 commits into
KlaatAI:mainfrom
Ayush7614:feat/export-session-markdown

Conversation

@Ayush7614

@Ayush7614 Ayush7614 commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Adds /export [path] to render the current session to clean Markdown (closes Add /export — render session to Markdown #32).
  • Tool calls use <details> summaries; edit diffs become fenced diff blocks; cost/request footer included.
  • Default path: ./klaatai-session-<id>.md. /share is kept as an alias.
  • Pure renderer in src/screens/export-session.ts with unit tests.

Test plan

  • bun run typecheck
  • bun test (186 pass on this branch)
  • bun run bench:selfcheck
  • bun run build
  • In TUI: run a short turn with a tool call, /export, open the written .md and confirm tool/diff formatting

Render the current session to clean Markdown with collapsed tool
output, fenced diffs, and a cost footer. Default path is
./klaatai-session-<id>.md; /share remains as an alias.
@Ayush7614

Copy link
Copy Markdown
Contributor Author

cc: @aakashrajput

@github-actions

Copy link
Copy Markdown
Contributor

🤖 KlaatAI Review Bot (powered by Klaatu, advisory only — a maintainer makes the real call)

Issue match
Fully addresses #32. Implements /export [path], renders tools and diffs legibly without raw JSON, includes the cost footer, updates slash autocomplete/help, and retains /share as an alias.

Test coverage
src/screens/export-session.test.ts thoroughly covers the pure renderer (path resolution, system filtering, tool collapsing, diff fencing, error headings). However, it lacks an integration test verifying that repl.ts correctly parses the [path] argument and writes the file via writeFileSync.

Correctness concerns
In src/screens/export-session.ts, renderToolBlock wraps tool output in triple backticks without escaping any backticks present in msg.content. If a tool outputs markdown code blocks, the generated export will have broken fencing. Consider dynamically adjusting the fence length (e.g., using ````) or escaping inner backticks.

Verdict
Needs a specific fix first: handle nested backticks in tool output to prevent broken markdown fencing in the exported file.

This is an automated review to help triage faster, not a gate. Nothing here blocks merging.

Export tool/diff bodies with a fence longer than any backtick run
inside the content so nested code blocks cannot break the markdown.
@Ayush7614

Copy link
Copy Markdown
Contributor Author

Addressed the review-bot note in a follow-up commit:

  • Tool/diff bodies now use a fence longer than any backtick run inside the content (fenceFor), so nested markdown code blocks can’t break the export

@github-actions

Copy link
Copy Markdown
Contributor

🤖 KlaatAI Review Bot (powered by Klaatu, advisory only — a maintainer makes the real call)

Issue match
Fully addresses #32. Implements /export [path] with the requested default path, collapsed tool <details>, fenced diff blocks, and cost footer. The --html bonus was correctly deferred. /share is preserved as an alias.

Test coverage
export-session.test.ts thoroughly covers the pure renderer: path resolution, nested backtick fence escaping, turn rendering, tool details, diff blocks, and error states. Missing coverage is the REPL integration (e.g., verifying /export triggers the file write and prints the path, or that the autocomplete menu includes the new command), though the core logic is well-tested.

Correctness concerns
In export-session.ts, resolveExportPath returns the trimmed argument directly without path.resolve(). While writeFileSync resolves relative paths against process.cwd(), this makes path resolution implicit and diverges from the comment's intent. Additionally, the default export location changed from homedir() (old /share) to cwd (new /export); this matches #32 but is a silent behavior change for existing /share users.

Verdict
Ready to merge as-is.

This is an automated review to help triage faster, not a gate. Nothing here blocks merging.

@aakashrajput
aakashrajput merged commit 630143a into KlaatAI:main Jul 21, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add /export — render session to Markdown

2 participants