eva-cli 4.1.0__tar.gz → 4.2.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (170) hide show
  1. {eva_cli-4.1.0 → eva_cli-4.2.1}/.github/workflows/ci.yaml +3 -0
  2. {eva_cli-4.1.0 → eva_cli-4.2.1}/CHANGELOG.md +11 -0
  3. {eva_cli-4.1.0 → eva_cli-4.2.1}/PKG-INFO +2 -1
  4. {eva_cli-4.1.0 → eva_cli-4.2.1}/docs/README.md +1 -1
  5. {eva_cli-4.1.0 → eva_cli-4.2.1}/pyproject.toml +2 -1
  6. {eva_cli-4.1.0 → eva_cli-4.2.1}/src/eva/__init__.py +1 -1
  7. eva_cli-4.2.1/src/eva/replay/crypto.py +100 -0
  8. {eva_cli-4.1.0 → eva_cli-4.2.1}/src/eva/replay/player.py +7 -6
  9. {eva_cli-4.1.0 → eva_cli-4.2.1}/src/eva/replay/recorder.py +11 -10
  10. eva_cli-4.2.1/tests/unit/replay/test_replay.py +134 -0
  11. eva_cli-4.1.0/tests/unit/replay/test_replay.py +0 -55
  12. {eva_cli-4.1.0 → eva_cli-4.2.1}/.github/workflows/fastwalk-release.yml +0 -0
  13. {eva_cli-4.1.0 → eva_cli-4.2.1}/.github/workflows/release.yml +0 -0
  14. {eva_cli-4.1.0 → eva_cli-4.2.1}/.gitignore +0 -0
  15. {eva_cli-4.1.0 → eva_cli-4.2.1}/.pre-commit-config.yaml +0 -0
  16. {eva_cli-4.1.0 → eva_cli-4.2.1}/CONTRIBUTING.md +0 -0
  17. {eva_cli-4.1.0 → eva_cli-4.2.1}/Dockerfile +0 -0
  18. {eva_cli-4.1.0 → eva_cli-4.2.1}/LICENSE +0 -0
  19. {eva_cli-4.1.0 → eva_cli-4.2.1}/README.md +0 -0
  20. {eva_cli-4.1.0 → eva_cli-4.2.1}/SECURITY.md +0 -0
  21. {eva_cli-4.1.0 → eva_cli-4.2.1}/assets/demo.gif +0 -0
  22. {eva_cli-4.1.0 → eva_cli-4.2.1}/assets/demo2.gif +0 -0
  23. {eva_cli-4.1.0 → eva_cli-4.2.1}/assets/demo3.gif +0 -0
  24. {eva_cli-4.1.0 → eva_cli-4.2.1}/assets/demo4.gif +0 -0
  25. {eva_cli-4.1.0 → eva_cli-4.2.1}/assets/demo5.gif +0 -0
  26. {eva_cli-4.1.0 → eva_cli-4.2.1}/assets/eva.png +0 -0
  27. {eva_cli-4.1.0 → eva_cli-4.2.1}/docs/architecture.md +0 -0
  28. {eva_cli-4.1.0 → eva_cli-4.2.1}/docs/command-reference.md +0 -0
  29. {eva_cli-4.1.0 → eva_cli-4.2.1}/docs/configuration.md +0 -0
  30. {eva_cli-4.1.0 → eva_cli-4.2.1}/docs/index.md +0 -0
  31. {eva_cli-4.1.0 → eva_cli-4.2.1}/docs/plugins.md +0 -0
  32. {eva_cli-4.1.0 → eva_cli-4.2.1}/docs/provider-behavior.md +0 -0
  33. {eva_cli-4.1.0 → eva_cli-4.2.1}/docs/security-model.md +0 -0
  34. {eva_cli-4.1.0 → eva_cli-4.2.1}/examples/eva-plugin-hello/README.md +0 -0
  35. {eva_cli-4.1.0 → eva_cli-4.2.1}/examples/eva-plugin-hello/eva_plugin_hello.py +0 -0
  36. {eva_cli-4.1.0 → eva_cli-4.2.1}/examples/eva-plugin-hello/pyproject.toml +0 -0
  37. {eva_cli-4.1.0 → eva_cli-4.2.1}/install.sh +0 -0
  38. {eva_cli-4.1.0 → eva_cli-4.2.1}/rust/eva_fastwalk/Cargo.lock +0 -0
  39. {eva_cli-4.1.0 → eva_cli-4.2.1}/rust/eva_fastwalk/Cargo.toml +0 -0
  40. {eva_cli-4.1.0 → eva_cli-4.2.1}/rust/eva_fastwalk/pyproject.toml +0 -0
  41. {eva_cli-4.1.0 → eva_cli-4.2.1}/rust/eva_fastwalk/src/lib.rs +0 -0
  42. {eva_cli-4.1.0 → eva_cli-4.2.1}/src/eva/agent/__init__.py +0 -0
  43. {eva_cli-4.1.0 → eva_cli-4.2.1}/src/eva/agent/loop.py +0 -0
  44. {eva_cli-4.1.0 → eva_cli-4.2.1}/src/eva/agent/tools.py +0 -0
  45. {eva_cli-4.1.0 → eva_cli-4.2.1}/src/eva/cache/__init__.py +0 -0
  46. {eva_cli-4.1.0 → eva_cli-4.2.1}/src/eva/cache/cache.py +0 -0
  47. {eva_cli-4.1.0 → eva_cli-4.2.1}/src/eva/cli/__init__.py +0 -0
  48. {eva_cli-4.1.0 → eva_cli-4.2.1}/src/eva/cli/app.py +0 -0
  49. {eva_cli-4.1.0 → eva_cli-4.2.1}/src/eva/cli.py +0 -0
  50. {eva_cli-4.1.0 → eva_cli-4.2.1}/src/eva/config/__init__.py +0 -0
  51. {eva_cli-4.1.0 → eva_cli-4.2.1}/src/eva/config/config.py +0 -0
  52. {eva_cli-4.1.0 → eva_cli-4.2.1}/src/eva/indexing/__init__.py +0 -0
  53. {eva_cli-4.1.0 → eva_cli-4.2.1}/src/eva/indexing/finder.py +0 -0
  54. {eva_cli-4.1.0 → eva_cli-4.2.1}/src/eva/indexing/io.py +0 -0
  55. {eva_cli-4.1.0 → eva_cli-4.2.1}/src/eva/indexing/packer.py +0 -0
  56. {eva_cli-4.1.0 → eva_cli-4.2.1}/src/eva/indexing/repo_index.py +0 -0
  57. {eva_cli-4.1.0 → eva_cli-4.2.1}/src/eva/indexing/tokenizer.py +0 -0
  58. {eva_cli-4.1.0 → eva_cli-4.2.1}/src/eva/indexing/tree.py +0 -0
  59. {eva_cli-4.1.0 → eva_cli-4.2.1}/src/eva/plugins/__init__.py +0 -0
  60. {eva_cli-4.1.0 → eva_cli-4.2.1}/src/eva/plugins/loader.py +0 -0
  61. {eva_cli-4.1.0 → eva_cli-4.2.1}/src/eva/plugins/protocol.py +0 -0
  62. {eva_cli-4.1.0 → eva_cli-4.2.1}/src/eva/prompts/__init__.py +0 -0
  63. {eva_cli-4.1.0 → eva_cli-4.2.1}/src/eva/providers/__init__.py +0 -0
  64. {eva_cli-4.1.0 → eva_cli-4.2.1}/src/eva/providers/gemini_provider.py +0 -0
  65. {eva_cli-4.1.0 → eva_cli-4.2.1}/src/eva/providers/groq_provider.py +0 -0
  66. {eva_cli-4.1.0 → eva_cli-4.2.1}/src/eva/providers/llamacpp_provider.py +0 -0
  67. {eva_cli-4.1.0 → eva_cli-4.2.1}/src/eva/providers/ollama_provider.py +0 -0
  68. {eva_cli-4.1.0 → eva_cli-4.2.1}/src/eva/providers/openai_compat.py +0 -0
  69. {eva_cli-4.1.0 → eva_cli-4.2.1}/src/eva/providers/opencode_zen_provider.py +0 -0
  70. {eva_cli-4.1.0 → eva_cli-4.2.1}/src/eva/providers/openrouter_provider.py +0 -0
  71. {eva_cli-4.1.0 → eva_cli-4.2.1}/src/eva/replay/__init__.py +0 -0
  72. {eva_cli-4.1.0 → eva_cli-4.2.1}/src/eva/security/__init__.py +0 -0
  73. {eva_cli-4.1.0 → eva_cli-4.2.1}/src/eva/security/audit.py +0 -0
  74. {eva_cli-4.1.0 → eva_cli-4.2.1}/src/eva/security/redaction.py +0 -0
  75. {eva_cli-4.1.0 → eva_cli-4.2.1}/src/eva/security/sandbox.py +0 -0
  76. {eva_cli-4.1.0 → eva_cli-4.2.1}/src/eva/security/sensitive_files.py +0 -0
  77. {eva_cli-4.1.0 → eva_cli-4.2.1}/src/eva/security/work_safety.py +0 -0
  78. {eva_cli-4.1.0 → eva_cli-4.2.1}/src/eva/shell/__init__.py +0 -0
  79. {eva_cli-4.1.0 → eva_cli-4.2.1}/src/eva/shell/runner.py +0 -0
  80. {eva_cli-4.1.0 → eva_cli-4.2.1}/src/eva/telemetry/__init__.py +0 -0
  81. {eva_cli-4.1.0 → eva_cli-4.2.1}/src/eva/telemetry/diagnostics.py +0 -0
  82. {eva_cli-4.1.0 → eva_cli-4.2.1}/src/eva/telemetry/metrics.py +0 -0
  83. {eva_cli-4.1.0 → eva_cli-4.2.1}/src/eva/ui/formatter.py +0 -0
  84. {eva_cli-4.1.0 → eva_cli-4.2.1}/src/eva/ui/streaming.py +0 -0
  85. {eva_cli-4.1.0 → eva_cli-4.2.1}/src/eva/workflows/__init__.py +0 -0
  86. {eva_cli-4.1.0 → eva_cli-4.2.1}/src/eva/workflows/budget.py +0 -0
  87. {eva_cli-4.1.0 → eva_cli-4.2.1}/src/eva/workflows/builtins/dependency_audit.yaml +0 -0
  88. {eva_cli-4.1.0 → eva_cli-4.2.1}/src/eva/workflows/builtins/repo_health.yaml +0 -0
  89. {eva_cli-4.1.0 → eva_cli-4.2.1}/src/eva/workflows/builtins/security_scan.yaml +0 -0
  90. {eva_cli-4.1.0 → eva_cli-4.2.1}/src/eva/workflows/chat_session.py +0 -0
  91. {eva_cli-4.1.0 → eva_cli-4.2.1}/src/eva/workflows/engine.py +0 -0
  92. {eva_cli-4.1.0 → eva_cli-4.2.1}/src/eva/workspace/__init__.py +0 -0
  93. {eva_cli-4.1.0 → eva_cli-4.2.1}/src/eva/workspace/git_ops.py +0 -0
  94. {eva_cli-4.1.0 → eva_cli-4.2.1}/src/eva/workspace/gitignore.py +0 -0
  95. {eva_cli-4.1.0 → eva_cli-4.2.1}/src/eva/workspace/session.py +0 -0
  96. {eva_cli-4.1.0 → eva_cli-4.2.1}/tests/conftest.py +0 -0
  97. {eva_cli-4.1.0 → eva_cli-4.2.1}/tests/fixtures/golden/patches/sample1_expected.diff +0 -0
  98. {eva_cli-4.1.0 → eva_cli-4.2.1}/tests/fixtures/golden/patches/sample1_fenced.txt +0 -0
  99. {eva_cli-4.1.0 → eva_cli-4.2.1}/tests/fixtures/golden/prompts/analyze_system_prompt.txt +0 -0
  100. {eva_cli-4.1.0 → eva_cli-4.2.1}/tests/fixtures/golden/prompts/ask_system_prompt.txt +0 -0
  101. {eva_cli-4.1.0 → eva_cli-4.2.1}/tests/fixtures/golden/prompts/changes_system_prompt.txt +0 -0
  102. {eva_cli-4.1.0 → eva_cli-4.2.1}/tests/fixtures/golden/prompts/chat_system_prompt.txt +0 -0
  103. {eva_cli-4.1.0 → eva_cli-4.2.1}/tests/fixtures/golden/prompts/commit_system_prompt.txt +0 -0
  104. {eva_cli-4.1.0 → eva_cli-4.2.1}/tests/fixtures/golden/prompts/edit_system_prompt.txt +0 -0
  105. {eva_cli-4.1.0 → eva_cli-4.2.1}/tests/fixtures/golden/prompts/explain_system_prompt.txt +0 -0
  106. {eva_cli-4.1.0 → eva_cli-4.2.1}/tests/fixtures/golden/prompts/work_system_prompt.txt +0 -0
  107. {eva_cli-4.1.0 → eva_cli-4.2.1}/tests/test_basic.py +0 -0
  108. {eva_cli-4.1.0 → eva_cli-4.2.1}/tests/unit/__init__.py +0 -0
  109. {eva_cli-4.1.0 → eva_cli-4.2.1}/tests/unit/agent/test_loop.py +0 -0
  110. {eva_cli-4.1.0 → eva_cli-4.2.1}/tests/unit/agent/test_tools.py +0 -0
  111. {eva_cli-4.1.0 → eva_cli-4.2.1}/tests/unit/cache/__init__.py +0 -0
  112. {eva_cli-4.1.0 → eva_cli-4.2.1}/tests/unit/cache/test_cache.py +0 -0
  113. {eva_cli-4.1.0 → eva_cli-4.2.1}/tests/unit/cli/__init__.py +0 -0
  114. {eva_cli-4.1.0 → eva_cli-4.2.1}/tests/unit/cli/test_ask_repo.py +0 -0
  115. {eva_cli-4.1.0 → eva_cli-4.2.1}/tests/unit/cli/test_changes_command.py +0 -0
  116. {eva_cli-4.1.0 → eva_cli-4.2.1}/tests/unit/cli/test_cli.py +0 -0
  117. {eva_cli-4.1.0 → eva_cli-4.2.1}/tests/unit/cli/test_cli_commands.py +0 -0
  118. {eva_cli-4.1.0 → eva_cli-4.2.1}/tests/unit/cli/test_cli_coverage.py +0 -0
  119. {eva_cli-4.1.0 → eva_cli-4.2.1}/tests/unit/cli/test_cli_more.py +0 -0
  120. {eva_cli-4.1.0 → eva_cli-4.2.1}/tests/unit/cli/test_investigate.py +0 -0
  121. {eva_cli-4.1.0 → eva_cli-4.2.1}/tests/unit/config/__init__.py +0 -0
  122. {eva_cli-4.1.0 → eva_cli-4.2.1}/tests/unit/config/test_config.py +0 -0
  123. {eva_cli-4.1.0 → eva_cli-4.2.1}/tests/unit/config/test_config_keys.py +0 -0
  124. {eva_cli-4.1.0 → eva_cli-4.2.1}/tests/unit/golden/__init__.py +0 -0
  125. {eva_cli-4.1.0 → eva_cli-4.2.1}/tests/unit/golden/test_golden_patches.py +0 -0
  126. {eva_cli-4.1.0 → eva_cli-4.2.1}/tests/unit/golden/test_golden_prompts.py +0 -0
  127. {eva_cli-4.1.0 → eva_cli-4.2.1}/tests/unit/indexing/__init__.py +0 -0
  128. {eva_cli-4.1.0 → eva_cli-4.2.1}/tests/unit/indexing/test_indexing.py +0 -0
  129. {eva_cli-4.1.0 → eva_cli-4.2.1}/tests/unit/indexing/test_indexing_more.py +0 -0
  130. {eva_cli-4.1.0 → eva_cli-4.2.1}/tests/unit/indexing/test_packer.py +0 -0
  131. {eva_cli-4.1.0 → eva_cli-4.2.1}/tests/unit/indexing/test_repo_index.py +0 -0
  132. {eva_cli-4.1.0 → eva_cli-4.2.1}/tests/unit/indexing/test_tokenizer_offline.py +0 -0
  133. {eva_cli-4.1.0 → eva_cli-4.2.1}/tests/unit/plugins/__init__.py +0 -0
  134. {eva_cli-4.1.0 → eva_cli-4.2.1}/tests/unit/plugins/test_plugins.py +0 -0
  135. {eva_cli-4.1.0 → eva_cli-4.2.1}/tests/unit/providers/__init__.py +0 -0
  136. {eva_cli-4.1.0 → eva_cli-4.2.1}/tests/unit/providers/test_context_budget.py +0 -0
  137. {eva_cli-4.1.0 → eva_cli-4.2.1}/tests/unit/providers/test_dispatch_caching.py +0 -0
  138. {eva_cli-4.1.0 → eva_cli-4.2.1}/tests/unit/providers/test_gemini_tools.py +0 -0
  139. {eva_cli-4.1.0 → eva_cli-4.2.1}/tests/unit/providers/test_offline_providers.py +0 -0
  140. {eva_cli-4.1.0 → eva_cli-4.2.1}/tests/unit/providers/test_openai_compat_tools.py +0 -0
  141. {eva_cli-4.1.0 → eva_cli-4.2.1}/tests/unit/providers/test_provider_coverage.py +0 -0
  142. {eva_cli-4.1.0 → eva_cli-4.2.1}/tests/unit/providers/test_provider_errors.py +0 -0
  143. {eva_cli-4.1.0 → eva_cli-4.2.1}/tests/unit/providers/test_provider_tools_protocol.py +0 -0
  144. {eva_cli-4.1.0 → eva_cli-4.2.1}/tests/unit/providers/test_providers.py +0 -0
  145. {eva_cli-4.1.0 → eva_cli-4.2.1}/tests/unit/providers/test_providers_more.py +0 -0
  146. {eva_cli-4.1.0 → eva_cli-4.2.1}/tests/unit/providers/test_repo_caching.py +0 -0
  147. {eva_cli-4.1.0 → eva_cli-4.2.1}/tests/unit/security/__init__.py +0 -0
  148. {eva_cli-4.1.0 → eva_cli-4.2.1}/tests/unit/security/test_allowlist_cli.py +0 -0
  149. {eva_cli-4.1.0 → eva_cli-4.2.1}/tests/unit/security/test_audit.py +0 -0
  150. {eva_cli-4.1.0 → eva_cli-4.2.1}/tests/unit/security/test_audit_chain.py +0 -0
  151. {eva_cli-4.1.0 → eva_cli-4.2.1}/tests/unit/security/test_redaction.py +0 -0
  152. {eva_cli-4.1.0 → eva_cli-4.2.1}/tests/unit/security/test_safety_audit.py +0 -0
  153. {eva_cli-4.1.0 → eva_cli-4.2.1}/tests/unit/security/test_sandbox.py +0 -0
  154. {eva_cli-4.1.0 → eva_cli-4.2.1}/tests/unit/security/test_work_safety.py +0 -0
  155. {eva_cli-4.1.0 → eva_cli-4.2.1}/tests/unit/shell/__init__.py +0 -0
  156. {eva_cli-4.1.0 → eva_cli-4.2.1}/tests/unit/shell/test_shell.py +0 -0
  157. {eva_cli-4.1.0 → eva_cli-4.2.1}/tests/unit/telemetry/__init__.py +0 -0
  158. {eva_cli-4.1.0 → eva_cli-4.2.1}/tests/unit/telemetry/test_metrics.py +0 -0
  159. {eva_cli-4.1.0 → eva_cli-4.2.1}/tests/unit/telemetry/test_telemetry.py +0 -0
  160. {eva_cli-4.1.0 → eva_cli-4.2.1}/tests/unit/test_compatibility_imports.py +0 -0
  161. {eva_cli-4.1.0 → eva_cli-4.2.1}/tests/unit/ui/__init__.py +0 -0
  162. {eva_cli-4.1.0 → eva_cli-4.2.1}/tests/unit/ui/test_ui.py +0 -0
  163. {eva_cli-4.1.0 → eva_cli-4.2.1}/tests/unit/workflows/__init__.py +0 -0
  164. {eva_cli-4.1.0 → eva_cli-4.2.1}/tests/unit/workflows/test_chat_session.py +0 -0
  165. {eva_cli-4.1.0 → eva_cli-4.2.1}/tests/unit/workflows/test_workflow_engine.py +0 -0
  166. {eva_cli-4.1.0 → eva_cli-4.2.1}/tests/unit/workflows/test_workflows.py +0 -0
  167. {eva_cli-4.1.0 → eva_cli-4.2.1}/tests/unit/workspace/__init__.py +0 -0
  168. {eva_cli-4.1.0 → eva_cli-4.2.1}/tests/unit/workspace/test_git_ops.py +0 -0
  169. {eva_cli-4.1.0 → eva_cli-4.2.1}/tests/unit/workspace/test_session_workspace.py +0 -0
  170. {eva_cli-4.1.0 → eva_cli-4.2.1}/tests/unit/workspace/test_workspace.py +0 -0
@@ -5,6 +5,9 @@ on:
5
5
  push:
6
6
  branches: [main]
7
7
 
8
+ permissions:
9
+ contents: read
10
+
8
11
  jobs:
9
12
  test:
10
13
  runs-on: ${{ matrix.os }}
@@ -7,6 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
 
9
9
 
10
+ ## [4.2.1] - 2026-08-12
11
+
12
+ ### Security
13
+ - **Replay session data encrypted at rest (`src/eva/replay/`):**
14
+ - Fixed a high-severity finding from GitHub code scanning: `meta.json` and `events.jsonl` under a session's replay directory were written as plaintext JSON. Terminal output can contain sensitive data that `redact_secrets()` doesn't catch (PII, internal hostnames, proprietary output), so replay files are now encrypted at rest as a second, independent layer.
15
+ - Added `src/eva/replay/crypto.py`: encrypts/decrypts replay records using `Fernet` (AES-128-CBC + HMAC via the `cryptography` package).
16
+ - Key storage follows the existing API-key pattern in `eva.config.config`: the key is stored in the OS keyring by default, falling back to a mode-`0600` file in the config directory when no keyring backend is available (e.g. headless CI, containers), so replay recording never hard-fails a command.
17
+ - `record_replay_event` now encrypts each record before it's written; file permissions on `meta.json` and `events.jsonl` are additionally restricted to `0600` as defense-in-depth.
18
+ - `load_replay_session` / `list_replay_sessions` transparently decrypt records, with a fallback to plain `json.loads` on `InvalidToken` so replay data recorded before this change continues to load correctly. No migration required.
19
+ - Added `cryptography>=43.0.0,<47.0.0` as a project dependency.
20
+
10
21
  ## [4.1.0] - 2026-08-11
11
22
 
12
23
  ### Added
@@ -1,9 +1,10 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: eva-cli
3
- Version: 4.1.0
3
+ Version: 4.2.1
4
4
  Summary: Command Line Intelligence
5
5
  License-File: LICENSE
6
6
  Requires-Python: >=3.10
7
+ Requires-Dist: cryptography<47.0.0,>=43.0.0
7
8
  Requires-Dist: diskcache<6.0.0,>=5.6.0
8
9
  Requires-Dist: google-genai<2.0.0,>=0.1.0
9
10
  Requires-Dist: httpx<1.0.0,>=0.27.0
@@ -16,4 +16,4 @@ This directory contains the official documentation for Eva CLI, mirroring the co
16
16
 
17
17
  ## Version
18
18
 
19
- This documentation corresponds to **Eva CLI v4.1.0**.
19
+ This documentation corresponds to **Eva CLI v4.2.1**.
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "eva-cli"
3
- version = "4.1.0"
3
+ version = "4.2.1"
4
4
 
5
5
 
6
6
  description = "Command Line Intelligence"
@@ -12,6 +12,7 @@ dependencies = [
12
12
  "pydantic-settings>=2.0.0,<3.0.0",
13
13
  "platformdirs>=4.0.0,<5.0.0",
14
14
  "keyring>=25.0.0,<26.0.0",
15
+ "cryptography>=43.0.0,<47.0.0",
15
16
  "diskcache>=5.6.0,<6.0.0",
16
17
  "tenacity>=9.0.0,<10.0.0",
17
18
  "rich>=13.0.0,<15.0.0",
@@ -1,3 +1,3 @@
1
1
  """Eva CLI package."""
2
2
 
3
- __version__ = "4.1.0"
3
+ __version__ = "4.2.1"
@@ -0,0 +1,100 @@
1
+ """Encryption for replay session data at rest.
2
+
3
+ redact_secrets() strips known secret patterns from command/output text,
4
+ but terminal output can still carry sensitive data redaction won't
5
+ catch (PII, internal hostnames, proprietary data, secret formats we
6
+ don't recognize). Replay files are therefore encrypted at rest as a
7
+ second layer, independent of redaction.
8
+
9
+ Key storage mirrors eva.config.config's API-key handling: prefer the
10
+ OS keyring, and fall back to a mode-0600 file in the config dir when
11
+ no keyring backend is available (headless CI, some containers) so that
12
+ replay recording never hard-fails a command.
13
+ """
14
+
15
+ import json
16
+ import logging
17
+ from pathlib import Path
18
+ from typing import Any
19
+
20
+ import keyring
21
+ from cryptography.fernet import Fernet, InvalidToken
22
+ from keyring.errors import KeyringError, NoKeyringError
23
+
24
+ from eva.config import APP_NAME, get_config_dir
25
+
26
+ logger = logging.getLogger(__name__)
27
+
28
+ _KEYRING_USERNAME = "replay-encryption-key"
29
+ _FALLBACK_KEY_FILENAME = ".replay.key"
30
+
31
+ # Broad on purpose: mirrors eva.config.config.keyring_backend_available,
32
+ # since misbehaving keyring backends raise more than just KeyringError.
33
+ _KEYRING_FAILURE_MODES = (NoKeyringError, KeyringError, RuntimeError, TypeError, AttributeError, ValueError)
34
+
35
+ _cached_fernet: Fernet | None = None
36
+
37
+
38
+ def restrict_permissions(path: Path) -> None:
39
+ """Best-effort chmod 0600. Public: also used by recorder.py on data files."""
40
+ try:
41
+ path.chmod(0o600)
42
+ except OSError:
43
+ pass # not all platforms support POSIX perms (e.g. Windows)
44
+
45
+
46
+ def _fallback_key_path() -> Path:
47
+ return get_config_dir() / _FALLBACK_KEY_FILENAME
48
+
49
+
50
+ def _load_or_create_fallback_key() -> bytes:
51
+ path = _fallback_key_path()
52
+ if path.exists():
53
+ return path.read_bytes()
54
+ key = Fernet.generate_key()
55
+ path.write_bytes(key)
56
+ restrict_permissions(path)
57
+ return key
58
+
59
+
60
+ def _get_or_create_key() -> bytes:
61
+ try:
62
+ existing = keyring.get_password(APP_NAME, _KEYRING_USERNAME)
63
+ if existing:
64
+ return existing.encode("utf-8")
65
+ new_key = Fernet.generate_key()
66
+ keyring.set_password(APP_NAME, _KEYRING_USERNAME, new_key.decode("utf-8"))
67
+ return new_key
68
+ except _KEYRING_FAILURE_MODES as exc:
69
+ logger.debug("Keyring unavailable for replay encryption key, using fallback file: %s", exc)
70
+ return _load_or_create_fallback_key()
71
+
72
+
73
+ def get_fernet() -> Fernet:
74
+ """Return a cached Fernet instance, creating/loading the key on first use."""
75
+ global _cached_fernet
76
+ if _cached_fernet is None:
77
+ _cached_fernet = Fernet(_get_or_create_key())
78
+ return _cached_fernet
79
+
80
+
81
+ def reset_cached_fernet() -> None:
82
+ """Clear the cached key/Fernet instance. Mainly useful for tests."""
83
+ global _cached_fernet
84
+ _cached_fernet = None
85
+
86
+
87
+ def encrypt_json(obj: Any) -> bytes:
88
+ return get_fernet().encrypt(json.dumps(obj).encode("utf-8"))
89
+
90
+
91
+ def decrypt_json_line(raw: bytes) -> Any:
92
+ """Decrypt one encrypted JSON record.
93
+
94
+ Falls back to plain json.loads on InvalidToken so replay data
95
+ written before encryption was introduced still loads.
96
+ """
97
+ try:
98
+ return json.loads(get_fernet().decrypt(raw))
99
+ except InvalidToken:
100
+ return json.loads(raw)
@@ -1,4 +1,3 @@
1
- import json
2
1
  import logging
3
2
  from pathlib import Path
4
3
  from typing import Any
@@ -6,6 +5,7 @@ from typing import Any
6
5
  from rich.console import Console
7
6
  from rich.table import Table
8
7
 
8
+ from eva.replay.crypto import decrypt_json_line
9
9
  from eva.replay.recorder import get_replays_dir, get_session_dir
10
10
 
11
11
  logger = logging.getLogger(__name__)
@@ -26,14 +26,15 @@ def list_replay_sessions(replays_dir: Path | None = None) -> list[dict[str, Any]
26
26
  count = 0
27
27
  if meta_file.exists():
28
28
  try:
29
- meta = json.loads(meta_file.read_text(encoding="utf-8"))
29
+ meta = decrypt_json_line(meta_file.read_bytes())
30
30
  created_at = meta.get("created_at", created_at)
31
31
  except (OSError, ValueError) as exc:
32
32
  logger.debug("Failed to read replay metadata %s: %s", meta_file, exc)
33
33
  if events_file.exists():
34
34
  try:
35
- count = len([line for line in events_file.read_text(encoding="utf-8").splitlines() if line.strip()])
36
- except (OSError, ValueError) as exc:
35
+ with open(events_file, "rb") as f:
36
+ count = sum(1 for line in f if line.strip())
37
+ except OSError as exc:
37
38
  logger.debug("Failed to read replay events %s: %s", events_file, exc)
38
39
  sessions.append(
39
40
  {
@@ -54,10 +55,10 @@ def load_replay_session(session_id: str, replays_dir: Path | None = None) -> lis
54
55
  raise FileNotFoundError(f"Replay session '{session_id}' not found.")
55
56
 
56
57
  events = []
57
- with open(events_file, "r", encoding="utf-8") as f:
58
+ with open(events_file, "rb") as f:
58
59
  for line in f:
59
60
  if line.strip():
60
- events.append(json.loads(line))
61
+ events.append(decrypt_json_line(line))
61
62
  return events
62
63
 
63
64
 
@@ -1,8 +1,8 @@
1
- import json
2
1
  from datetime import datetime, timezone
3
2
  from pathlib import Path
4
3
 
5
4
  from eva.config import get_config_dir
5
+ from eva.replay.crypto import encrypt_json, restrict_permissions
6
6
  from eva.security.redaction import redact_secrets
7
7
 
8
8
 
@@ -30,23 +30,23 @@ def record_replay_event(
30
30
  ):
31
31
  """Record a terminal execution event to session replay log.
32
32
 
33
- Secrets in command, output, and cwd are redacted at write time.
33
+ Secrets in command, output, and cwd are redacted at write time,
34
+ and each record is encrypted at rest.
34
35
  """
35
36
  target_dir = (replays_dir / session_id) if replays_dir else get_session_dir(session_id)
36
37
  target_dir.mkdir(parents=True, exist_ok=True)
37
38
 
38
39
  meta_file = target_dir / "meta.json"
39
40
  if not meta_file.exists():
40
- meta_file.write_text(
41
- json.dumps(
41
+ meta_file.write_bytes(
42
+ encrypt_json(
42
43
  {
43
44
  "session_id": session_id,
44
45
  "created_at": datetime.now(timezone.utc).isoformat(),
45
- },
46
- indent=2,
47
- ),
48
- encoding="utf-8",
46
+ }
47
+ )
49
48
  )
49
+ restrict_permissions(meta_file)
50
50
 
51
51
  events_file = target_dir / "events.jsonl"
52
52
 
@@ -63,5 +63,6 @@ def record_replay_event(
63
63
  "cwd": clean_cwd,
64
64
  }
65
65
 
66
- with open(events_file, "a", encoding="utf-8") as f:
67
- f.write(json.dumps(record) + "\n")
66
+ with open(events_file, "ab") as f:
67
+ f.write(encrypt_json(record) + b"\n")
68
+ restrict_permissions(events_file)
@@ -0,0 +1,134 @@
1
+ import json
2
+
3
+ import pytest
4
+
5
+ from eva.replay import list_replay_sessions, load_replay_session, record_replay_event
6
+ from eva.replay.crypto import decrypt_json_line
7
+
8
+
9
+ def test_replay_recording_and_loading(tmp_path):
10
+ replays_dir = tmp_path / "replays"
11
+
12
+ record_replay_event(
13
+ session_id="test_session",
14
+ command="echo hello",
15
+ output="hello",
16
+ exit_code=0,
17
+ duration_s=0.12,
18
+ cwd=tmp_path,
19
+ replays_dir=replays_dir,
20
+ )
21
+
22
+ sessions = list_replay_sessions(replays_dir=replays_dir)
23
+ assert len(sessions) == 1
24
+ assert sessions[0]["session_id"] == "test_session"
25
+ assert sessions[0]["event_count"] == 1
26
+
27
+ events = load_replay_session("test_session", replays_dir=replays_dir)
28
+ assert len(events) == 1
29
+ assert events[0]["command"] == "echo hello"
30
+ assert events[0]["output"] == "hello"
31
+ assert events[0]["exit_code"] == 0
32
+
33
+
34
+ def test_replay_redacts_secrets_at_write_time(tmp_path):
35
+ replays_dir = tmp_path / "replays"
36
+
37
+ secret_key = "sk-1234567890123456789012345678901234567890"
38
+ record_replay_event(
39
+ session_id="secret_session",
40
+ command=f"export API_KEY={secret_key}",
41
+ output=f"Stored secret key {secret_key}",
42
+ exit_code=0,
43
+ duration_s=0.05,
44
+ cwd=tmp_path,
45
+ replays_dir=replays_dir,
46
+ )
47
+
48
+ events_file = replays_dir / "secret_session" / "events.jsonl"
49
+ raw = events_file.read_bytes()
50
+
51
+ # Ciphertext on disk must never contain the raw secret.
52
+ assert secret_key.encode() not in raw
53
+
54
+ # Decrypted content should show the redaction happened before encryption.
55
+ decrypted = decrypt_json_line(raw.splitlines()[0])
56
+ assert secret_key not in decrypted["command"]
57
+ assert secret_key not in decrypted["output"]
58
+ assert "REDACTED" in decrypted["command"]
59
+ assert "REDACTED" in decrypted["output"]
60
+
61
+
62
+ def test_replay_events_file_is_encrypted_at_rest(tmp_path):
63
+ """The whole point of the fix: plaintext JSON should never hit disk."""
64
+ replays_dir = tmp_path / "replays"
65
+
66
+ record_replay_event(
67
+ session_id="enc_session",
68
+ command="echo plaintext-marker",
69
+ output="plaintext-marker output",
70
+ exit_code=0,
71
+ duration_s=0.01,
72
+ cwd=tmp_path,
73
+ replays_dir=replays_dir,
74
+ )
75
+
76
+ events_file = replays_dir / "enc_session" / "events.jsonl"
77
+ meta_file = replays_dir / "enc_session" / "meta.json"
78
+
79
+ for f in (events_file, meta_file):
80
+ raw = f.read_bytes()
81
+ # Encrypted bytes are not valid/parseable JSON.
82
+ with pytest.raises((json.JSONDecodeError, UnicodeDecodeError, ValueError)):
83
+ json.loads(raw)
84
+ assert b"plaintext-marker" not in raw
85
+ assert b"enc_session" not in raw or f == events_file # session_id lives in meta, encrypted too
86
+
87
+
88
+ def test_load_replay_session_falls_back_to_legacy_plaintext(tmp_path):
89
+ """Records written before encryption was introduced must still load."""
90
+ replays_dir = tmp_path / "replays"
91
+ session_dir = replays_dir / "legacy_session"
92
+ session_dir.mkdir(parents=True)
93
+
94
+ legacy_record = {
95
+ "timestamp": "2026-01-01T00:00:00+00:00",
96
+ "command": "echo legacy",
97
+ "output": "legacy",
98
+ "exit_code": 0,
99
+ "duration_s": 0.01,
100
+ "cwd": "/tmp",
101
+ }
102
+ (session_dir / "events.jsonl").write_text(json.dumps(legacy_record) + "\n", encoding="utf-8")
103
+
104
+ events = load_replay_session("legacy_session", replays_dir=replays_dir)
105
+ assert len(events) == 1
106
+ assert events[0]["command"] == "echo legacy"
107
+
108
+
109
+ def test_replay_key_survives_process_restart(tmp_path, monkeypatch):
110
+ """A fresh Fernet instance (simulating a new process) must still
111
+ decrypt data written by a previous one, i.e. the key must persist."""
112
+ from eva.replay import crypto
113
+
114
+ replays_dir = tmp_path / "replays"
115
+ record_replay_event(
116
+ session_id="persist_session",
117
+ command="echo persisted",
118
+ output="persisted",
119
+ exit_code=0,
120
+ duration_s=0.01,
121
+ cwd=tmp_path,
122
+ replays_dir=replays_dir,
123
+ )
124
+
125
+ crypto.reset_cached_fernet() # simulate a new process picking the key back up
126
+
127
+ events = load_replay_session("persist_session", replays_dir=replays_dir)
128
+ assert events[0]["command"] == "echo persisted"
129
+
130
+
131
+ def test_load_nonexistent_session(tmp_path):
132
+ replays_dir = tmp_path / "replays"
133
+ with pytest.raises(FileNotFoundError):
134
+ load_replay_session("nonexistent_session", replays_dir=replays_dir)
@@ -1,55 +0,0 @@
1
- import pytest
2
-
3
- from eva.replay import list_replay_sessions, load_replay_session, record_replay_event
4
-
5
-
6
- def test_replay_recording_and_loading(tmp_path):
7
- replays_dir = tmp_path / "replays"
8
-
9
- record_replay_event(
10
- session_id="test_session",
11
- command="echo hello",
12
- output="hello",
13
- exit_code=0,
14
- duration_s=0.12,
15
- cwd=tmp_path,
16
- replays_dir=replays_dir,
17
- )
18
-
19
- sessions = list_replay_sessions(replays_dir=replays_dir)
20
- assert len(sessions) == 1
21
- assert sessions[0]["session_id"] == "test_session"
22
- assert sessions[0]["event_count"] == 1
23
-
24
- events = load_replay_session("test_session", replays_dir=replays_dir)
25
- assert len(events) == 1
26
- assert events[0]["command"] == "echo hello"
27
- assert events[0]["output"] == "hello"
28
- assert events[0]["exit_code"] == 0
29
-
30
-
31
- def test_replay_redacts_secrets_at_write_time(tmp_path):
32
- replays_dir = tmp_path / "replays"
33
-
34
- secret_key = "sk-1234567890123456789012345678901234567890"
35
- record_replay_event(
36
- session_id="secret_session",
37
- command=f"export API_KEY={secret_key}",
38
- output=f"Stored secret key {secret_key}",
39
- exit_code=0,
40
- duration_s=0.05,
41
- cwd=tmp_path,
42
- replays_dir=replays_dir,
43
- )
44
-
45
- events_file = replays_dir / "secret_session" / "events.jsonl"
46
- content = events_file.read_text(encoding="utf-8")
47
-
48
- assert secret_key not in content
49
- assert "REDACTED" in content
50
-
51
-
52
- def test_load_nonexistent_session(tmp_path):
53
- replays_dir = tmp_path / "replays"
54
- with pytest.raises(FileNotFoundError):
55
- load_replay_session("nonexistent_session", replays_dir=replays_dir)
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes