Implemented the next missing parity slice around clearing session env vars on /clear.

Wires clear_session_env_vars() into LocalCodingAgent.clear_runtime_state so the
/clear slash command now drops session-scoped env vars alongside the rest of the
ephemeral runtime state, matching commands/clear/caches.ts:127.
This commit is contained in:
Abdelrahman Abdallah
2026-04-20 00:52:28 +02:00
parent 72e6fffb34
commit cfd3bb9ca7
3 changed files with 25 additions and 1 deletions
+1 -1
View File
@@ -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:
+3
View File
@@ -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(
+21
View File
@@ -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 = [
{