Skip to content

feat: add history export subcommand#54

Merged
eitsupi merged 17 commits intomainfrom
feat/history-export-import
Feb 5, 2026
Merged

feat: add history export subcommand#54
eitsupi merged 17 commits intomainfrom
feat/history-export-import

Conversation

@eitsupi
Copy link
Copy Markdown
Owner

@eitsupi eitsupi commented Feb 5, 2026

Summary

  • Add arf history export subcommand for backing up history to a unified SQLite file
  • Exports both R and shell history to a single file with customizable table names
  • Supports arf history import --from arf to restore or transfer history
  • Implements atomic write using temp file + rename for data safety

Changes

  • New arf history export <file> command with --dry-run, --r-table, --shell-table options
  • Extended arf history import --from arf to support unified export files
  • Added table name validation for custom table names
  • Documentation updates in README, configuration guide, and CHANGELOG

Test plan

  • Unit tests for export functionality
  • Test unified parser with various filename patterns
  • Manual testing: export → import round-trip

🤖 Generated with Claude Code

eitsupi and others added 10 commits February 5, 2026 13:36
- Add `arf history export` command to backup history to a unified SQLite file
  - Exports both r.db and shell.db to a single file with customizable table names
  - Use --r-table and --shell-table to specify table names (defaults: r, shell)
- Update `arf history import --from arf` to support unified export files
  - Files named r.db/shell.db use existing single-mode import
  - Other filenames trigger unified import using table names
- Split export functionality into separate history/export.rs module
- Add comprehensive tests for export and unified import

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Address review findings:
- Add validate_table_name() to prevent SQL injection via table names
- Add --unified flag to explicitly specify unified file format
- Add parent directory existence check for export output path
- Quote table names in SQL queries for safety

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Verify that parse_unified_arf_history works regardless of filename,
which validates the --unified flag behavior indirectly.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Add history export section with options
- Update history import section with unified file support
- Document --unified, --r-table, --shell-table options

Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Use temp file + rename pattern to prevent incomplete files on error
- Clean up stale temp files from previous failed attempts
- Add documentation notes about concurrent access and restore procedure

Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Mention radian/.Rhistory import in Fuzzy History Search highlight
- Add import/export support to Features list

Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Fix TOCTOU race condition in stale temp file cleanup
- Use unique .arf-export-tmp extension to avoid collisions
- Clarify documentation about atomicity guarantees

Co-Authored-By: Claude Opus 4.5 <[email protected]>
eitsupi and others added 2 commits February 5, 2026 13:42
Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Collapse nested if statements in export.rs
- Allow too_many_arguments for handle_history_import
- Use &Path instead of &PathBuf in handle_history_export

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds an experimental history export/import feature to arf console, enabling users to back up their R and shell command history to a unified SQLite file and restore it later or transfer it between machines.

Changes:

  • Added arf history export subcommand to export both R and shell history to a single SQLite file with customizable table names
  • Extended arf history import --from arf to support unified export files (auto-detected by filename or explicit --unified flag)
  • Implemented table name validation to prevent SQL injection attacks
  • Added atomic write operations using temp files for data safety during export

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
crates/arf-console/src/cli.rs Defines new Export action with --file, --r-table, and --shell-table parameters
crates/arf-console/src/main.rs Implements handlers for export and unified import functionality
crates/arf-console/src/history/mod.rs Exports new export module
crates/arf-console/src/history/export.rs Core export logic with atomic writes, table creation, and data copying
crates/arf-console/src/history/import.rs Adds unified import parser, table validation, and helper functions
docs/configuration.md Documents export/import commands with examples
README.md Updates feature descriptions and adds comprehensive export/import documentation
CHANGELOG.md Documents new features and changes
crates/arf-console/src/snapshots/*.snap Updated shell completion and help text snapshots

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

eitsupi and others added 5 commits February 5, 2026 13:53
- Add validation to reject same table names for r_table and shell_table
  in both export and import to prevent data loss/duplication
- Fix documentation to use correct CLI syntax (--file flag required)
- Remove non-existent --dry-run from export examples
- Add tests for same table name validation

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Also improve --unified flag help text with clearer auto-detection explanation.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Add timestamp to temp file name for unpredictability (security)
- Add write permission check before export starts
- Document cross-platform atomicity limitations
- Document intentional design difference between low-level export
  function and CLI handler
- Reject underscore-only table names (e.g., "_", "___")
- Add test for temp file cleanup on export failure
- Add round-trip integration test for export/import
- Update shell completion snapshots

Addresses roborev job 113 findings.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Add comment explaining intentional behavior for write permission
  check cleanup (test file may be left if removal fails)
- Add process ID to temp file name for better uniqueness
- Improve cleanup test with clearer comments explaining the flow
- Add test_export_cleans_up_temp_file_on_copy_failure to verify
  cleanup when failure occurs during data copy (not just open)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@eitsupi eitsupi merged commit 531aa2b into main Feb 5, 2026
10 checks passed
@eitsupi eitsupi deleted the feat/history-export-import branch February 5, 2026 14:17
@eitsupi eitsupi mentioned this pull request Feb 5, 2026
3 tasks
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.

2 participants