personal memory agent
0
fork

Configure Feed

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

Use get_journal_info() for journal path resolution; add --path flag

Replace inline load_dotenv + os.environ.get in get_status() with a call
to think.utils.get_journal_info(), which provides platform-default
fallback when JOURNAL_PATH is not set anywhere.

Add --path top-level flag that prints the resolved journal path and
exits, suitable for shell substitution: cd

Status output now shows the path source annotation (shell/dotenv/default).

+46 -20
+16 -15
sol.py
··· 138 138 139 139 def get_status() -> dict[str, Any]: 140 140 """Return current journal status information.""" 141 - from dotenv import load_dotenv 141 + from think.utils import get_journal_info 142 142 143 - load_dotenv() 143 + path, source = get_journal_info() 144 144 145 - status: dict[str, Any] = {} 146 - 147 - # Journal path 148 - journal_path = os.environ.get("JOURNAL_PATH") 149 - if journal_path: 150 - status["journal_path"] = journal_path 151 - status["journal_exists"] = os.path.isdir(journal_path) 152 - else: 153 - status["journal_path"] = "(not set)" 154 - status["journal_exists"] = False 155 - 156 - return status 145 + return { 146 + "journal_path": path, 147 + "journal_source": source, 148 + "journal_exists": os.path.isdir(path), 149 + } 157 150 158 151 159 152 def print_status() -> None: 160 153 """Print current journal status.""" 161 154 status = get_status() 162 155 163 - print(f"JOURNAL_PATH={status['journal_path']}") 156 + print(f"JOURNAL_PATH={status['journal_path']} ({status['journal_source']})") 164 157 if status["journal_exists"]: 165 158 # Count day directories 166 159 journal = status["journal_path"] ··· 289 282 # Version flag 290 283 if cmd in ("--version", "-V"): 291 284 print("sol (solstone) 0.1.0") 285 + return 286 + 287 + # Path flag 288 + if cmd == "--path": 289 + from think.utils import get_journal_info 290 + 291 + path, _source = get_journal_info() 292 + print(path) 292 293 return 293 294 294 295 # Resolve command to module path
+30 -5
tests/test_sol.py
··· 130 130 131 131 status = sol.get_status() 132 132 assert status["journal_path"] == str(tmp_path) 133 + assert status["journal_source"] == "shell" 133 134 assert status["journal_exists"] is True 134 135 135 136 def test_status_with_nonexistent_journal(self, monkeypatch, tmp_path): ··· 139 140 140 141 status = sol.get_status() 141 142 assert status["journal_path"] == str(nonexistent) 143 + assert status["journal_source"] == "shell" 142 144 assert status["journal_exists"] is False 143 145 144 146 def test_status_without_journal_path(self, monkeypatch): 145 - """Test status when JOURNAL_PATH is not set.""" 147 + """Test status when JOURNAL_PATH is not set falls back to platform default.""" 146 148 monkeypatch.delenv("JOURNAL_PATH", raising=False) 147 - # Also prevent .env from being loaded 148 - with patch("dotenv.load_dotenv"): 149 + with patch("think.utils.load_dotenv"): 149 150 status = sol.get_status() 150 - assert status["journal_path"] == "(not set)" 151 - assert status["journal_exists"] is False 151 + assert status["journal_path"] != "(not set)" 152 + assert status["journal_source"] == "default" 153 + assert isinstance(status["journal_exists"], bool) 152 154 153 155 154 156 class TestMain: ··· 193 195 194 196 captured = capsys.readouterr() 195 197 assert "sol (solstone)" in captured.out 198 + 199 + def test_main_path_flag(self, monkeypatch, capsys): 200 + """Test --path flag prints resolved journal path.""" 201 + monkeypatch.setattr(sys, "argv", ["sol", "--path"]) 202 + monkeypatch.setenv("JOURNAL_PATH", "/tmp/test-journal") 203 + 204 + sol.main() 205 + 206 + captured = capsys.readouterr() 207 + assert captured.out.strip() == "/tmp/test-journal" 208 + 209 + def test_main_path_flag_default(self, monkeypatch, capsys): 210 + """Test --path prints platform default when JOURNAL_PATH not set.""" 211 + monkeypatch.setattr(sys, "argv", ["sol", "--path"]) 212 + monkeypatch.delenv("JOURNAL_PATH", raising=False) 213 + with patch("think.utils.load_dotenv"): 214 + sol.main() 215 + 216 + captured = capsys.readouterr() 217 + path = captured.out.strip() 218 + assert path != "(not set)" 219 + assert path != "" 220 + assert "solstone" in path or "journal" in path 196 221 197 222 def test_main_unknown_command_exits(self, monkeypatch): 198 223 """Test that unknown command exits with code 1."""