add claw-code-agent/src/plan_runtime.py and claw-code-agent/src/background_runtime.py. The agent now has a real
persistent plan runtime with update_plan, plan_get, and plan_clear, plus plan-to-task sync wired through claw-code-agent/src/ agent_tools.py, claw-code-agent/src/agent_runtime.py, claw-code-agent/src/agent_context.py, claw-code-agent/src/agent_prompting.py, and claw-code-agent/src/ agent_slash_commands.py. New local plan slash commands are /plan and /planner.
This commit is contained in:
@@ -5,13 +5,16 @@ import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
from unittest.mock import patch
|
||||
|
||||
from src.agent_context import (
|
||||
build_context_snapshot,
|
||||
clear_context_caches,
|
||||
set_system_prompt_injection,
|
||||
)
|
||||
from src.plan_runtime import PlanRuntime
|
||||
from src.agent_types import AgentRuntimeConfig
|
||||
from src.task_runtime import TaskRuntime
|
||||
|
||||
|
||||
class AgentContextTests(unittest.TestCase):
|
||||
@@ -57,6 +60,76 @@ class AgentContextTests(unittest.TestCase):
|
||||
self.assertIn('demo-plugin', snapshot.user_context['pluginCache'])
|
||||
self.assertIn('1.2.3', snapshot.user_context['pluginCache'])
|
||||
|
||||
def test_user_context_loads_hook_policy_manifest(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||
workspace = Path(tmp_dir) / 'repo'
|
||||
workspace.mkdir(parents=True)
|
||||
(workspace / '.claw-policy.json').write_text(
|
||||
(
|
||||
'{"trusted": false, '
|
||||
'"managedSettings": {"reviewMode": "strict"}, '
|
||||
'"safeEnv": ["HOOK_SAFE_TOKEN"], '
|
||||
'"hooks": {"beforePrompt": ["Respect workspace policy."]}}'
|
||||
),
|
||||
encoding='utf-8',
|
||||
)
|
||||
with patch.dict('os.environ', {'HOOK_SAFE_TOKEN': 'demo-secret'}, clear=False):
|
||||
snapshot = build_context_snapshot(AgentRuntimeConfig(cwd=workspace))
|
||||
|
||||
self.assertIn('hookPolicy', snapshot.user_context)
|
||||
self.assertIn('managedSettings', snapshot.user_context)
|
||||
self.assertIn('safeEnv', snapshot.user_context)
|
||||
self.assertIn('trustMode', snapshot.user_context)
|
||||
self.assertIn('reviewMode=strict', snapshot.user_context['managedSettings'])
|
||||
self.assertIn('HOOK_SAFE_TOKEN=demo-secret', snapshot.user_context['safeEnv'])
|
||||
self.assertIn('untrusted', snapshot.user_context['trustMode'])
|
||||
|
||||
def test_user_context_loads_mcp_runtime_summary(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||
workspace = Path(tmp_dir) / 'repo'
|
||||
workspace.mkdir(parents=True)
|
||||
(workspace / 'notes.txt').write_text('mcp notes\n', encoding='utf-8')
|
||||
(workspace / '.claw-mcp.json').write_text(
|
||||
(
|
||||
'{"servers":[{"name":"workspace","resources":['
|
||||
'{"uri":"mcp://workspace/notes","name":"Notes","path":"notes.txt"}'
|
||||
']}]}'
|
||||
),
|
||||
encoding='utf-8',
|
||||
)
|
||||
|
||||
snapshot = build_context_snapshot(AgentRuntimeConfig(cwd=workspace))
|
||||
|
||||
self.assertIn('mcpRuntime', snapshot.user_context)
|
||||
self.assertIn('Local MCP resources: 1', snapshot.user_context['mcpRuntime'])
|
||||
|
||||
def test_user_context_loads_task_runtime_summary(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||
workspace = Path(tmp_dir) / 'repo'
|
||||
workspace.mkdir(parents=True)
|
||||
runtime = TaskRuntime.from_workspace(workspace)
|
||||
runtime.create_task(title='Review task runtime')
|
||||
|
||||
snapshot = build_context_snapshot(AgentRuntimeConfig(cwd=workspace))
|
||||
|
||||
self.assertIn('taskRuntime', snapshot.user_context)
|
||||
self.assertIn('Total tasks: 1', snapshot.user_context['taskRuntime'])
|
||||
|
||||
def test_user_context_loads_plan_runtime_summary(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||
workspace = Path(tmp_dir) / 'repo'
|
||||
workspace.mkdir(parents=True)
|
||||
plan_runtime = PlanRuntime.from_workspace(workspace)
|
||||
plan_runtime.update_plan(
|
||||
[{'step': 'Inspect the runtime', 'status': 'in_progress'}],
|
||||
explanation='Use a stored plan.',
|
||||
)
|
||||
|
||||
snapshot = build_context_snapshot(AgentRuntimeConfig(cwd=workspace))
|
||||
|
||||
self.assertIn('planRuntime', snapshot.user_context)
|
||||
self.assertIn('Total plan steps: 1', snapshot.user_context['planRuntime'])
|
||||
|
||||
@unittest.skipIf(shutil.which('git') is None, 'git is required for git context tests')
|
||||
def test_git_status_snapshot_contains_branch_and_status(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||
|
||||
Reference in New Issue
Block a user