Skip to content

Commit ac794f5

Browse files
committed
feat: add session persistence and /status command
1 parent 94f0e7d commit ac794f5

3 files changed

Lines changed: 56 additions & 9 deletions

File tree

iclaw/completer.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"/model",
99
"/search_provider",
1010
"/copy",
11+
"/status",
1112
"/help",
1213
".exit",
1314
]

iclaw/config.py

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,38 @@
77
TOKEN_REFRESH_INTERVAL = 24 * 60 # seconds
88

99

10-
def load_github_token():
10+
def _load_config() -> dict:
1111
if not CONFIG_PATH.exists():
12-
return None
12+
return {}
1313
try:
14-
config = json.loads(CONFIG_PATH.read_text())
15-
return config.get("github_token")
14+
return json.loads(CONFIG_PATH.read_text())
1615
except json.JSONDecodeError:
17-
return None
16+
return {}
17+
18+
19+
def _save_config(config: dict) -> None:
20+
CONFIG_PATH.parent.mkdir(parents=True, exist_ok=True)
21+
CONFIG_PATH.write_text(json.dumps(config, indent=2))
22+
23+
24+
def load_github_token():
25+
return _load_config().get("github_token")
26+
27+
28+
def load_session_settings() -> dict:
29+
config = _load_config()
30+
return {
31+
"model_provider": config.get("model_provider", "copilot"),
32+
"current_model": config.get("current_model", "gpt-5.2"),
33+
"search_provider": config.get("search_provider", "duckduckgo"),
34+
}
35+
36+
37+
def save_session_settings(
38+
model_provider: str, current_model: str, search_provider: str
39+
) -> None:
40+
config = _load_config()
41+
config["model_provider"] = model_provider
42+
config["current_model"] = current_model
43+
config["search_provider"] = search_provider
44+
_save_config(config)

iclaw/main.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env python3
22
import json
3+
import os
34
import sys
45
import time
56

@@ -10,7 +11,13 @@
1011
from iclaw.commands.search_provider import handle_search_provider_command
1112
from iclaw.commands.utils import handle_copy_command
1213
from iclaw.completer import IclawCompleter
13-
from iclaw.config import CONFIG_PATH, TOKEN_REFRESH_INTERVAL, load_github_token
14+
from iclaw.config import (
15+
CONFIG_PATH,
16+
TOKEN_REFRESH_INTERVAL,
17+
load_github_token,
18+
load_session_settings,
19+
save_session_settings,
20+
)
1421
from iclaw.exec_tool import exec_command as exec
1522
from iclaw.github_api import chat, get_copilot_token
1623
from iclaw.tools.defs import TOOLS
@@ -22,6 +29,7 @@
2229
("/model", "Select specific model from your provider"),
2330
("/search_provider", "Select the web search provider"),
2431
("/copy", "Copy last Copilot response to clipboard"),
32+
("/status", "Show current settings"),
2533
("/help", "Show available commands"),
2634
(".exit", "Quit"),
2735
]
@@ -32,9 +40,10 @@ def main():
3240
copilot_token = None
3341
token_expiry = 0
3442
last_reply = None
35-
search_provider = "duckduckgo"
36-
model_provider = "copilot"
37-
current_model = "gpt-5.2"
43+
settings = load_session_settings()
44+
model_provider = settings["model_provider"]
45+
current_model = settings["current_model"]
46+
search_provider = settings["search_provider"]
3847

3948
if github_token:
4049
print("Connecting to GitHub Copilot...")
@@ -82,12 +91,22 @@ def main():
8291
copilot_token = t
8392
github_token = load_github_token()
8493
token_expiry = time.monotonic() + TOKEN_REFRESH_INTERVAL
94+
save_session_settings(model_provider, current_model, search_provider)
8595
continue
8696
if user_input == "/model":
8797
current_model = handle_model_command(copilot_token, current_model)
98+
save_session_settings(model_provider, current_model, search_provider)
8899
continue
89100
if user_input == "/search_provider":
90101
search_provider = handle_search_provider_command(search_provider)
102+
save_session_settings(model_provider, current_model, search_provider)
103+
continue
104+
if user_input == "/status":
105+
print(f" model_provider: {model_provider}")
106+
print(f" model: {current_model}")
107+
print(f" search_provider: {search_provider}")
108+
print(f" cwd: {os.getcwd()}")
109+
print()
91110
continue
92111

93112
if not copilot_token:

0 commit comments

Comments
 (0)