Skip to content

Commit 80a9fe1

Browse files
committed
chore(agent): update logging
1 parent 8a06f69 commit 80a9fe1

3 files changed

Lines changed: 41 additions & 20 deletions

File tree

agent/entrypoint.py

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import asyncio
1818
import glob
19+
import hashlib
1920
import json
2021
import os
2122
import re
@@ -222,8 +223,17 @@ def slugify(text: str, max_len: int = 40) -> str:
222223

223224
def redact_secrets(text: str) -> str:
224225
"""Redact tokens and secrets from log output."""
226+
# GitHub and generic token-like values.
225227
text = re.sub(r"(ghp_|github_pat_|gho_|ghs_|ghr_)[A-Za-z0-9_]+", r"\1***", text)
226228
text = re.sub(r"(x-access-token:)[^\s@]+", r"\1***", text)
229+
text = re.sub(r"(authorization:\s*(?:bearer|token)\s+)[^\s]+", r"\1***", text, flags=re.I)
230+
text = re.sub(
231+
r"([?&](?:token|access_token|api_key|apikey|password)=)[^&\s]+",
232+
r"\1***",
233+
text,
234+
flags=re.I,
235+
)
236+
text = re.sub(r"(gh[opusr]_[A-Za-z0-9_]+)", "***", text)
227237
return text
228238

229239

@@ -1057,7 +1067,8 @@ def print_metrics(metrics: dict):
10571067
print("METRICS REPORT")
10581068
print("=" * 60)
10591069
for key, value in metrics.items():
1060-
print(f" {key:30s}: {value}")
1070+
safe_value = redact_secrets(str(value))
1071+
print(f" {key:30s}: {safe_value}")
10611072
print("=" * 60)
10621073

10631074

@@ -1069,7 +1080,7 @@ def print_metrics(metrics: dict):
10691080
def log(prefix: str, text: str):
10701081
"""Print a timestamped log line."""
10711082
ts = time.strftime("%H:%M:%S")
1072-
print(f"[{ts}] {prefix} {text}", flush=True)
1083+
print(f"[{ts}] {prefix} {redact_secrets(str(text))}", flush=True)
10731084

10741085

10751086
def truncate(text: str, max_len: int = 200) -> str:
@@ -1876,11 +1887,8 @@ def run_task(
18761887
def main():
18771888
config = get_config()
18781889

1879-
print(f"Task ID: {config['task_id']}")
1880-
print(f"Repository: {config['repo_url']}")
1881-
print(f"Issue: {config['issue_number'] or '(none)'}")
1882-
print(f"Model: {config['anthropic_model']}")
1883-
print(f"Dry run: {config['dry_run']}")
1890+
print("Task configuration loaded.", flush=True)
1891+
print(f"Dry run: {config['dry_run']}", flush=True)
18841892
print()
18851893

18861894
if config["dry_run"]:
@@ -1900,10 +1908,25 @@ def main():
19001908
overrides = config.get("system_prompt_overrides", "")
19011909
if overrides:
19021910
system_prompt += f"\n\n## Additional instructions\n\n{overrides}"
1903-
print("\n--- SYSTEM PROMPT ---")
1904-
print(system_prompt)
1905-
print("\n--- USER PROMPT ---")
1906-
print(prompt)
1911+
system_prompt_hash = hashlib.sha256(system_prompt.encode("utf-8")).hexdigest()[:12]
1912+
prompt_hash = hashlib.sha256(prompt.encode("utf-8")).hexdigest()[:12]
1913+
print("\n--- SYSTEM PROMPT (REDACTED) ---")
1914+
print(
1915+
f"length={len(system_prompt)} chars sha256={system_prompt_hash} "
1916+
"(set DEBUG_DRY_RUN_PROMPTS=1 to print full text)",
1917+
flush=True,
1918+
)
1919+
print("\n--- USER PROMPT (REDACTED) ---")
1920+
print(
1921+
f"length={len(prompt)} chars sha256={prompt_hash} "
1922+
"(set DEBUG_DRY_RUN_PROMPTS=1 to print full text)",
1923+
flush=True,
1924+
)
1925+
if os.environ.get("DEBUG_DRY_RUN_PROMPTS") == "1":
1926+
print("\n--- SYSTEM PROMPT (DEBUG) ---")
1927+
print(redact_secrets(system_prompt), flush=True)
1928+
print("\n--- USER PROMPT (DEBUG) ---")
1929+
print(redact_secrets(prompt), flush=True)
19071930
print("\n--- DRY RUN COMPLETE ---")
19081931
return
19091932

agent/memory.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,7 @@ def _log_error(func_name: str, err: Exception, memory_id: str, task_id: str) ->
5050
level = "ERROR" if is_programming_error else "WARN"
5151
label = "unexpected error" if is_programming_error else "infra failure"
5252
print(
53-
f"[memory] [{level}] {func_name} {label}: "
54-
f"{type(err).__name__}: {err} "
55-
f"[memory_id={memory_id}, task_id={task_id}]",
53+
f"[memory] [{level}] {func_name} {label}: {type(err).__name__}",
5654
flush=True,
5755
)
5856

@@ -121,7 +119,7 @@ def write_task_episode(
121119
metadata=metadata,
122120
)
123121

124-
print(f"[memory] Task episode written for {task_id} [memory_id={memory_id}]", flush=True)
122+
print("[memory] Task episode written", flush=True)
125123
return True
126124
except Exception as e:
127125
_log_error("write_task_episode", e, memory_id, task_id)
@@ -170,7 +168,7 @@ def write_repo_learnings(
170168
},
171169
)
172170

173-
print(f"[memory] Repo learnings written for {task_id} [memory_id={memory_id}]", flush=True)
171+
print("[memory] Repo learnings written", flush=True)
174172
return True
175173
except Exception as e:
176174
_log_error("write_repo_learnings", e, memory_id, task_id)

agent/task_state.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,9 @@ def write_running(task_id: str) -> None:
106106
isinstance(e, ClientError)
107107
and e.response.get("Error", {}).get("Code") == "ConditionalCheckFailedException"
108108
):
109-
print(f"[task_state] write_running skipped for {task_id}: status precondition not met")
109+
print("[task_state] write_running skipped: status precondition not met")
110110
return
111-
print(f"[task_state] write_running failed (best-effort): {e}")
111+
print(f"[task_state] write_running failed (best-effort): {type(e).__name__}")
112112

113113

114114
def write_terminal(task_id: str, status: str, result: dict | None = None) -> None:
@@ -165,11 +165,11 @@ def write_terminal(task_id: str, status: str, result: dict | None = None) -> Non
165165
and e.response.get("Error", {}).get("Code") == "ConditionalCheckFailedException"
166166
):
167167
print(
168-
f"[task_state] write_terminal skipped for {task_id}: "
168+
"[task_state] write_terminal skipped: "
169169
"status precondition not met (task may have been cancelled)"
170170
)
171171
return
172-
print(f"[task_state] write_terminal failed (best-effort): {e}")
172+
print(f"[task_state] write_terminal failed (best-effort): {type(e).__name__}")
173173

174174

175175
def get_task(task_id: str) -> dict | None:

0 commit comments

Comments
 (0)