diff --git a/PARITY_CHECKLIST.md b/PARITY_CHECKLIST.md index 284b437..0813056 100644 --- a/PARITY_CHECKLIST.md +++ b/PARITY_CHECKLIST.md @@ -707,7 +707,7 @@ Done: - [x] Basic git status snapshot - [x] Basic shell/subprocess handling - [x] Bundled small portable utilities — `utils/array.ts`, `utils/set.ts`, `utils/objectGroupBy.ts`, `utils/xml.ts`, `utils/uuid.ts` ported in `src/small_utils.py` -- [x] Session-scoped env-var registry (`utils/sessionEnvVars.ts`) ported in `src/session_env_vars.py` and merged into spawned subprocess env via `_build_subprocess_env` (mirrors `utils/shell/bashProvider.ts`) +- [x] Session-scoped env-var registry (`utils/sessionEnvVars.ts`) ported in `src/session_env_vars.py`, merged into spawned subprocess env via `_build_subprocess_env` (mirrors `utils/shell/bashProvider.ts`), and dropped on `/clear` via `clear_runtime_state` (mirrors `commands/clear/caches.ts`) - [x] Display formatters from `utils/format.ts` (`formatFileSize`, `formatSecondsShort`, `formatDuration`, `formatNumber`, `formatTokens`) ported in `src/format_utils.py` Missing major utility categories: diff --git a/src/agent_runtime.py b/src/agent_runtime.py index bad2e70..60c6ec3 100644 --- a/src/agent_runtime.py +++ b/src/agent_runtime.py @@ -67,6 +67,7 @@ from .team_runtime import TeamRuntime from .tokenizer_runtime import describe_token_counter from .workflow_runtime import WorkflowRuntime from .worktree_runtime import WorktreeRuntime +from .session_env_vars import clear_session_env_vars from .session_store import ( StoredAgentSession, load_agent_session, @@ -249,6 +250,8 @@ class LocalCodingAgent: self.resume_source_session_id = None if self.plugin_runtime is not None: self.plugin_runtime.restore_session_state({}) + # Mirror commands/clear/caches.ts: drop session-scoped env vars on /clear. + clear_session_env_vars() def build_prompt_context(self, scratchpad_directory: Path | None = None): return build_prompt_context( diff --git a/tests/test_agent_runtime.py b/tests/test_agent_runtime.py index b2a12d2..e0d953f 100644 --- a/tests/test_agent_runtime.py +++ b/tests/test_agent_runtime.py @@ -318,6 +318,27 @@ class AgentRuntimeTests(unittest.TestCase): self.assertEqual(result.tool_calls, 0) self.assertIn('# Permissions', result.final_output) + def test_clear_runtime_state_drops_session_env_vars(self) -> None: + from src.session_env_vars import ( + clear_session_env_vars, + get_session_env_vars, + set_session_env_var, + ) + + clear_session_env_vars() + try: + with tempfile.TemporaryDirectory() as tmp_dir: + agent = LocalCodingAgent( + model_config=ModelConfig(model='Qwen/Qwen3-Coder-30B-A3B-Instruct'), + runtime_config=AgentRuntimeConfig(cwd=Path(tmp_dir)), + ) + set_session_env_var('CLAW_CLEAR_TEST', 'before') + self.assertEqual(get_session_env_vars()['CLAW_CLEAR_TEST'], 'before') + agent.clear_runtime_state() + self.assertNotIn('CLAW_CLEAR_TEST', get_session_env_vars()) + finally: + clear_session_env_vars() + def test_agent_persists_session_and_can_resume(self) -> None: responses = [ {