personal memory agent
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Clean up stale code after get_journal() refactor

Remove dead code paths that became unreachable after get_journal() was
updated to auto-create the journal directory with platform-specific
defaults instead of raising RuntimeError.

- Remove unused load_dotenv imports from 4 files
- Remove 8 dead except RuntimeError handlers across tools/routes
- Remove stale test_entity_add_aka_runtime_error test
- Update docstrings that referenced old JOURNAL_PATH behavior
- Update AGENTS.md to recommend get_journal() over load_dotenv()

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

+5 -63
+1 -1
AGENTS.md
··· 176 176 ### Environment Management 177 177 * **JOURNAL_PATH**: The live journal path is stored in `.env`. To access it: 178 178 - **Shell/CLI**: Run `grep JOURNAL_PATH .env` to get the path, then use it directly 179 - - **Python CLI tools**: Call `setup_cli()` first, or manually use `load_dotenv()` 179 + - **Python**: Use `get_journal()` from `think.utils` - it handles `.env` loading and auto-creates a platform-specific default if unset 180 180 * **API Keys**: Store in `.env` file, never commit to repository 181 181 * **Entry Points**: Use command names (e.g., `think-indexer`) NOT `python -m ...` 182 182
-25
apps/entities/tools.py
··· 70 70 "count": len(entities), 71 71 "entities": entities, 72 72 } 73 - except RuntimeError as exc: 74 - return { 75 - "error": str(exc), 76 - "suggestion": "ensure JOURNAL_PATH environment variable is set", 77 - } 78 73 except Exception as exc: 79 74 return { 80 75 "error": f"Failed to list entities: {exc}", ··· 151 146 "day": day, 152 147 "message": f"Entity '{name}' detected successfully", 153 148 "entity": {"type": type, "name": name, "description": description}, 154 - } 155 - except RuntimeError as exc: 156 - return { 157 - "error": str(exc), 158 - "suggestion": "ensure JOURNAL_PATH environment variable is set", 159 149 } 160 150 except Exception as exc: 161 151 return { ··· 266 256 "message": f"Entity '{name}' attached successfully", 267 257 "entity": {"type": type, "name": name, "description": description}, 268 258 } 269 - except RuntimeError as exc: 270 - return { 271 - "error": str(exc), 272 - "suggestion": "ensure JOURNAL_PATH environment variable is set", 273 - } 274 259 except Exception as exc: 275 260 return { 276 261 "error": f"Failed to attach entity: {exc}", ··· 357 342 return { 358 343 "error": error_msg, 359 344 "suggestion": "verify the entity exists and try again", 360 - } 361 - except RuntimeError as exc: 362 - return { 363 - "error": str(exc), 364 - "suggestion": "ensure JOURNAL_PATH environment variable is set", 365 345 } 366 346 except Exception as exc: 367 347 return { ··· 470 450 "suggestion": "verify the entity exists in the facet (only attached entities supported, not detected)", 471 451 } 472 452 473 - except RuntimeError as exc: 474 - return { 475 - "error": str(exc), 476 - "suggestion": "ensure JOURNAL_PATH environment variable is set", 477 - } 478 453 except Exception as exc: 479 454 return { 480 455 "error": f"Failed to add aka: {exc}",
-4
apps/settings/routes.py
··· 27 27 try: 28 28 config = get_journal_config() 29 29 return jsonify(config) 30 - except RuntimeError as e: 31 - return jsonify({"error": str(e)}), 500 32 30 except Exception as e: 33 31 return jsonify({"error": str(e)}), 500 34 32 ··· 76 74 ) 77 75 78 76 return jsonify({"success": True, "config": config}) 79 - except RuntimeError as e: 80 - return jsonify({"error": str(e)}), 500 81 77 except Exception as e: 82 78 return jsonify({"error": str(e)}), 500 83 79
+1 -1
convey/utils.py
··· 103 103 agent_id string (timestamp-based) 104 104 105 105 Raises: 106 - ValueError: If JOURNAL_PATH not set or config invalid 106 + ValueError: If config is invalid 107 107 Exception: On agent spawn failure 108 108 """ 109 109 from muse.cortex_client import cortex_request
-1
muse/claude.py
··· 31 31 UserMessage, 32 32 query, 33 33 ) 34 - from dotenv import load_dotenv 35 34 36 35 from think.models import CLAUDE_SONNET_4 37 36 from think.utils import get_journal
-5
muse/tools/facets.py
··· 120 120 "message": f"No news recorded for {day} in facet '{facet}'", 121 121 } 122 122 123 - except RuntimeError as exc: 124 - return { 125 - "error": str(exc), 126 - "suggestion": "ensure JOURNAL_PATH environment variable is set", 127 - } 128 123 except Exception as exc: 129 124 return { 130 125 "error": f"Failed to process facet news: {exc}",
-15
tests/test_mcp_tools.py
··· 136 136 assert "suggestion" in result 137 137 138 138 139 - def test_entity_add_aka_runtime_error(): 140 - """Test entity_add_aka when JOURNAL_PATH not set.""" 141 - with ( 142 - patch("apps.entities.tools.load_entities") as mock_load, 143 - patch("apps.entities.tools.is_valid_entity_type") as mock_validate, 144 - ): 145 - mock_validate.return_value = True 146 - mock_load.side_effect = RuntimeError("JOURNAL_PATH not set") 147 - result = entity_tools.entity_add_aka("work", "Tool", "PostgreSQL", "PG") 148 - 149 - assert "error" in result 150 - assert "JOURNAL_PATH not set" in result["error"] 151 - assert "suggestion" in result 152 - 153 - 154 139 def test_entity_add_aka_skip_first_word(): 155 140 """Test that adding first word of entity name as aka is silently skipped.""" 156 141 mock_entities = [
+1 -1
tests/test_think_utils.py
··· 169 169 # Ensure JOURNAL_PATH is not set 170 170 monkeypatch.delenv("JOURNAL_PATH", raising=False) 171 171 # Mock load_dotenv to prevent it from loading a .env file 172 - monkeypatch.setattr("think.entities.load_dotenv", lambda: None) 172 + monkeypatch.setattr("think.utils.load_dotenv", lambda: None) 173 173 174 174 # With get_journal() fallback, this will use the platform default path 175 175 # The result depends on whether entities exist there
-1
think/entities.py
··· 13 13 from pathlib import Path 14 14 from typing import Any, Optional 15 15 16 - from dotenv import load_dotenv 17 16 from slugify import slugify 18 17 19 18 from think.utils import get_journal
-2
think/events.py
··· 16 16 from pathlib import Path 17 17 from typing import Any 18 18 19 - from dotenv import load_dotenv 20 - 21 19 from think.utils import get_journal 22 20 23 21
-1
think/facets.py
··· 11 11 from pathlib import Path 12 12 from typing import Any, Optional 13 13 14 - from dotenv import load_dotenv 15 14 from fastmcp import Context 16 15 from fastmcp.server.dependencies import get_http_headers 17 16
+1 -1
think/runner.py
··· 34 34 35 35 36 36 def _get_journal_path() -> Path: 37 - """Get JOURNAL_PATH from environment.""" 37 + """Return the journal path (auto-creates if needed).""" 38 38 return Path(get_journal()) 39 39 40 40
+1 -5
think/supervisor.py
··· 1227 1227 def main() -> None: 1228 1228 parser = parse_args() 1229 1229 args = setup_cli(parser) 1230 - try: 1231 - journal_path = _get_journal_path() 1232 - except RuntimeError: 1233 - parser.error("JOURNAL_PATH not set") 1234 - return 1230 + journal_path = _get_journal_path() 1235 1231 1236 1232 log_level = logging.DEBUG if args.debug else logging.INFO 1237 1233 log_path = journal_path / "health" / "supervisor.log"