checkpoint: Working on getting gemini cli to actually have parity with gemini api.
This commit is contained in:
@@ -1,16 +1,5 @@
|
||||
# session_logger.py
|
||||
"""
|
||||
Note(Gemini):
|
||||
Opens timestamped log/script files at startup and keeps them open for the
|
||||
lifetime of the process.
|
||||
|
||||
File layout:
|
||||
logs/comms_<ts>.log - every comms entry (direction/kind/payload) as JSON-L
|
||||
logs/toolcalls_<ts>.log - sequential record of every tool invocation
|
||||
scripts/generated/<ts>_<seq:04d>.ps1 - each PowerShell script the AI generated
|
||||
"""
|
||||
# session_logger.py
|
||||
"""
|
||||
Opens timestamped log/script files at startup and keeps them open for the
|
||||
lifetime of the process. The next run of the GUI creates new files; the
|
||||
previous run's files are simply closed when the process exits.
|
||||
@@ -20,6 +9,7 @@ File layout
|
||||
logs/
|
||||
comms_<ts>.log - every comms entry (direction/kind/payload) as JSON-L
|
||||
toolcalls_<ts>.log - sequential record of every tool invocation
|
||||
clicalls_<ts>.log - sequential record of every CLI subprocess call
|
||||
scripts/generated/
|
||||
<ts>_<seq:04d>.ps1 - each PowerShell script the AI generated, in order
|
||||
|
||||
@@ -42,6 +32,7 @@ _seq_lock = threading.Lock()
|
||||
_comms_fh = None # file handle: logs/comms_<ts>.log
|
||||
_tool_fh = None # file handle: logs/toolcalls_<ts>.log
|
||||
_api_fh = None # file handle: logs/apihooks_<ts>.log - API hook calls
|
||||
_cli_fh = None # file handle: logs/clicalls_<ts>.log - CLI subprocess calls
|
||||
|
||||
|
||||
def _now_ts() -> str:
|
||||
@@ -54,7 +45,7 @@ def open_session():
|
||||
opens the two log files for this session. Idempotent - a second call is
|
||||
ignored.
|
||||
"""
|
||||
global _ts, _comms_fh, _tool_fh, _api_fh, _seq
|
||||
global _ts, _comms_fh, _tool_fh, _api_fh, _cli_fh, _seq
|
||||
|
||||
if _comms_fh is not None:
|
||||
return # already open
|
||||
@@ -68,16 +59,19 @@ def open_session():
|
||||
_comms_fh = open(_LOG_DIR / f"comms_{_ts}.log", "w", encoding="utf-8", buffering=1)
|
||||
_tool_fh = open(_LOG_DIR / f"toolcalls_{_ts}.log", "w", encoding="utf-8", buffering=1)
|
||||
_api_fh = open(_LOG_DIR / f"apihooks_{_ts}.log", "w", encoding="utf-8", buffering=1)
|
||||
_cli_fh = open(_LOG_DIR / f"clicalls_{_ts}.log", "w", encoding="utf-8", buffering=1) # New log file handle
|
||||
|
||||
_tool_fh.write(f"# Tool-call log — session {_ts}\n\n")
|
||||
_tool_fh.flush()
|
||||
_cli_fh.write(f"# CLI Subprocess Call Log — session {_ts}\n\n") # Header for new log file
|
||||
_cli_fh.flush()
|
||||
|
||||
atexit.register(close_session)
|
||||
|
||||
|
||||
def close_session():
|
||||
"""Flush and close both log files. Called on clean exit (optional)."""
|
||||
global _comms_fh, _tool_fh, _api_fh
|
||||
"""Flush and close all log files. Called on clean exit (optional)."""
|
||||
global _comms_fh, _tool_fh, _api_fh, _cli_fh
|
||||
if _comms_fh:
|
||||
_comms_fh.close()
|
||||
_comms_fh = None
|
||||
@@ -87,6 +81,9 @@ def close_session():
|
||||
if _api_fh:
|
||||
_api_fh.close()
|
||||
_api_fh = None
|
||||
if _cli_fh: # Close the new log file handle
|
||||
_cli_fh.close()
|
||||
_cli_fh = None
|
||||
|
||||
|
||||
def log_api_hook(method: str, path: str, payload: str):
|
||||
@@ -155,3 +152,26 @@ def log_tool_call(script: str, result: str, script_path: str | None):
|
||||
pass
|
||||
|
||||
return str(ps1_path) if ps1_path else None
|
||||
|
||||
|
||||
def log_cli_call(command: str, stdin_content: str | None, stdout_content: str | None, stderr_content: str | None, latency: float):
|
||||
"""
|
||||
Log details of a CLI subprocess execution.
|
||||
"""
|
||||
if _cli_fh is None:
|
||||
return
|
||||
|
||||
ts_entry = datetime.datetime.now().strftime("%H:%M:%S")
|
||||
try:
|
||||
log_data = {
|
||||
"timestamp": ts_entry,
|
||||
"command": command,
|
||||
"stdin": stdin_content,
|
||||
"stdout": stdout_content,
|
||||
"stderr": stderr_content,
|
||||
"latency_sec": latency
|
||||
}
|
||||
_cli_fh.write(json.dumps(log_data, ensure_ascii=False, default=str) + "\n")
|
||||
_cli_fh.flush()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user