Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/evaluations/chat-intake.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
import tempfile
import urllib.request

from loopx.chat import CHAT_REVIEW_CLOSE_TAG, CHAT_REVIEW_OPEN_TAG, parse_agent_response
from loopx.chat_agent import CodexChatAgentSession, _turn_prompt
from loopx.chat import CHAT_REVIEW_CLOSE_TAG, CHAT_REVIEW_OPEN_TAG, _turn_prompt, parse_agent_response
from loopx.chat_agent import CodexChatAgentSession
from loopx.control_plane.operator_provider import operator_provider_environ


Expand Down
3 changes: 0 additions & 3 deletions loopx/canary/module_metric_baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@
"any_count": 52,
"dict_any_count": 0
},
"loopx/chat_agent.py": {
"lines": 2047
},
"loopx/chat_runtime.py": {
"any_count": 29,
"dict_any_count": 0
Expand Down
3 changes: 2 additions & 1 deletion loopx/capabilities/native_chat/antigravity_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@
CHAT_REVIEW_OPEN_TAG, CHAT_REVIEW_CLOSE_TAG,
VisibleResponseStreamFilter,
_review_openings,
_turn_prompt,
parse_agent_response,
)
from ...chat_agent import CodexChatAgentError, _turn_prompt
from ...chat_agent import CodexChatAgentError
from .antigravity_activity import AntigravityActivity
from .manager_input import manager_input_matches

Expand Down
2 changes: 1 addition & 1 deletion loopx/capabilities/native_chat/external_conversations.py
Original file line number Diff line number Diff line change
Expand Up @@ -991,7 +991,7 @@ def prepare_metadata_review_input(self, session: dict[str, Any], turn: dict[str,
continuation = self._checked_metadata_review(session, turn, observe_native=True)
if continuation is None:
return None
from ...chat_agent import COLLABORATION_INPUTS_GUIDANCE
from ...chat import COLLABORATION_INPUTS_GUIDANCE

return (
"Core admitted ONE text-only FORMAT REVIEW of an already completed original result. "
Expand Down
229 changes: 229 additions & 0 deletions loopx/chat.py

Large diffs are not rendered by default.

26 changes: 8 additions & 18 deletions loopx/chat_acp.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@
CHAT_REVIEW_CLOSE_TAG,
CHAT_REVIEW_OPEN_TAG,
VisibleResponseStreamFilter,
_turn_prompt,
parse_agent_response,
redact_local_paths,
)
from .chat_agent import (
CodexChatAgentError,
CodexChatTimeoutError,
_host_tool_gate,
_turn_prompt,
_reader,
)


Expand All @@ -33,22 +34,6 @@
ACP_SESSION_STARTUP_TIMEOUT_DEFAULT_SEC = 45.0


def _reader(stream: Any, messages: "queue.Queue[dict[str, Any] | Exception]") -> None:
try:
for line in stream:
if not line.strip():
continue
try:
payload = json.loads(line)
except Exception as exc: # pragma: no cover - defensive transport path.
messages.put(exc)
continue
if isinstance(payload, dict):
messages.put(payload)
finally:
messages.put(EOFError("ACP stdio stream closed"))


def _compact_label(value: Any, *, fallback: str) -> str:
return " ".join(str(value or "").split())[:100].strip() or fallback

Expand Down Expand Up @@ -120,7 +105,12 @@ def start(
) from exc
messages: "queue.Queue[dict[str, Any] | Exception]" = queue.Queue()
assert process.stdout is not None
threading.Thread(target=_reader, args=(process.stdout, messages), daemon=True).start()
threading.Thread(
target=_reader,
args=(process.stdout, messages),
kwargs={"eof_message": "ACP stdio stream closed"},
daemon=True,
).start()
initialize_timeout_sec = (
ACP_INITIALIZE_TIMEOUT_DEFAULT_SEC
if startup_timeout_sec is None
Expand Down
403 changes: 79 additions & 324 deletions loopx/chat_agent.py

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions loopx/chat_dsh.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
from typing import Any
import uuid

from .chat import parse_agent_response
from .chat_agent import CodexChatAgentError, CodexChatTimeoutError, _turn_prompt
from .chat import _turn_prompt, parse_agent_response
from .chat_agent import CodexChatAgentError, CodexChatTimeoutError
from .control_plane.turn_driver.host_binding import dsh_output_token_budget
from .dsh_goal_mode.turn_host_adapter import (
normalize_runner_outcome,
Expand Down
4 changes: 2 additions & 2 deletions loopx/chat_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@
load_effective_steward_executor_defaults,
normalize_manager_executor_allocation,
)
from .chat_agent import (
from .chat import (
CONVERSATION_INTENT_RESOLUTION_INSTRUCTION,
TRUSTED_OWNER_DIRECT_WORK_INSTRUCTION,
WORK_RESULT_VERIFICATION_INSTRUCTION,
CodexChatAgentError,
)
from .chat_agent import CodexChatAgentError
from .chat_store import (
CHAT_SESSION_MODE_ATTACHED,
CHAT_SESSION_MODE_MANAGED,
Expand Down
4 changes: 2 additions & 2 deletions loopx/chat_providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
from urllib import request
import uuid

from .chat import VisibleResponseStreamFilter, parse_agent_response
from .chat_agent import CodexChatAgentError, _host_tool_gate, _turn_prompt
from .chat import VisibleResponseStreamFilter, _turn_prompt, parse_agent_response
from .chat_agent import CodexChatAgentError, _host_tool_gate


EventSink = Callable[[str, dict[str, Any]], None]
Expand Down
7 changes: 4 additions & 3 deletions tests/test_chat_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from types import SimpleNamespace
from pathlib import Path

import loopx.chat as chat
import loopx.chat_agent as chat_agent
import loopx.chat_providers as chat_providers
import loopx.chat_runtime as chat_runtime
Expand Down Expand Up @@ -1463,7 +1464,7 @@ def popen(command, *args, **kwargs):
if public_reader:
assert "requested version's URL" in prompt and "truncation and read coverage" in prompt
else:
assert prompt == chat_agent._turn_prompt("Continue.", context_summary=session.context_summary,
assert prompt == chat._turn_prompt("Continue.", context_summary=session.context_summary,
runtime_profile=session.runtime_profile, project_work=grant == "workspace_write")
assert sent[0][1]["threadId"] == session.thread_id == "thread-loopx-chat"
finally:
Expand Down Expand Up @@ -2387,7 +2388,7 @@ def test_focused_edit_guidance_reaches_confirmed_execution_only(tmp_path, monkey
):
assert (competing_route in prompt) is not execution_mode
if execution_mode:
assert chat_agent.WORK_RESULT_VERIFICATION_INSTRUCTION in prompt
assert chat.WORK_RESULT_VERIFICATION_INSTRUCTION in prompt
assert "Never claim the change has been written without a verified control-plane receipt" not in prompt
assert "keep proposals=[], goal_draft=null and context_handoff=null" in prompt
assert "protected_action must be null" in prompt
Expand All @@ -2397,7 +2398,7 @@ def test_focused_edit_guidance_reaches_confirmed_execution_only(tmp_path, monkey
{}, {"runtime_profile": "trusted_owner"}, {"project_work": True}, {"execution_mode": True},
])
def test_turn_guidance_scopes_gates_without_cutting_requested_results(mode):
prompt = chat_agent._turn_prompt(
prompt = chat._turn_prompt(
"Inspect the seven requested files; publishing still needs owner authorization.", **mode
)
assert "stop only actions that depend on the missing authority or tool" in prompt
Expand Down
10 changes: 5 additions & 5 deletions tests/test_chat_intake_evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def test_accepted_report_fixture_supplies_the_content_it_claims_to_have_read():


def test_shared_intake_guidance_precedes_handoff_without_widening_runtime():
from loopx.chat_agent import CONVERSATION_INTENT_RESOLUTION_INSTRUCTION, _turn_prompt
from loopx.chat import CONVERSATION_INTENT_RESOLUTION_INSTRUCTION, _turn_prompt
from loopx.chat_manager import manager_agent_objective

prompt = _turn_prompt("Continue.")
Expand All @@ -84,7 +84,7 @@ def test_shared_intake_guidance_precedes_handoff_without_widening_runtime():


def test_capable_owner_can_complete_work_without_claiming_a_worker_launch():
from loopx.chat_agent import TRUSTED_OWNER_DIRECT_WORK_INSTRUCTION, _turn_prompt
from loopx.chat import TRUSTED_OWNER_DIRECT_WORK_INSTRUCTION, _turn_prompt
from loopx.chat_manager import manager_agent_objective

prompt = _turn_prompt("Save the supplied source using this project's rules.", runtime_profile="trusted_owner")
Expand All @@ -100,7 +100,7 @@ def test_capable_owner_can_complete_work_without_claiming_a_worker_launch():

@pytest.mark.parametrize("existing_workspace", [False, True])
def test_managed_owner_instructions_and_turn_agree_on_completion(tmp_path, existing_workspace):
from loopx.chat_agent import _turn_prompt
from loopx.chat import _turn_prompt
from loopx.chat_manager import manager_workspace

if existing_workspace:
Expand All @@ -117,7 +117,7 @@ def test_managed_owner_instructions_and_turn_agree_on_completion(tmp_path, exist

@pytest.mark.parametrize("mode", ["restricted", "project", "execution"])
def test_direct_manager_work_does_not_widen_other_conversations(mode):
from loopx.chat_agent import TRUSTED_OWNER_DIRECT_WORK_INSTRUCTION, _turn_prompt
from loopx.chat import TRUSTED_OWNER_DIRECT_WORK_INSTRUCTION, _turn_prompt
from loopx.chat_manager import manager_agent_objective

kwargs = {"runtime_profile": "restricted"}
Expand Down Expand Up @@ -292,7 +292,7 @@ def test_review_evidence_retains_brief_without_provider_payload():
def test_followthrough_refresh_reaches_existing_workspaces_without_replacing_owner_text(
tmp_path, profile, custom_owner_instructions, previous_marker
):
from loopx.chat_agent import _turn_prompt
from loopx.chat import _turn_prompt
from loopx.chat_manager import manager_workspace, MANAGED_SKILL_CURRENT_MARKER

workspace = manager_workspace(tmp_path, runtime_profile=profile)
Expand Down
3 changes: 1 addition & 2 deletions tests/test_manager_context_execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
POLICY_SCHEMA, _root, _write, deliver, register_ingress,
)
from loopx.capabilities.manager_context import execution
from loopx.chat import normalize_agent_response
from loopx.chat_agent import _turn_prompt
from loopx.chat import _turn_prompt, normalize_agent_response
from loopx.chat_store import ChatSessionStore
from loopx.capabilities.manager_context.inspection import manager_index
from test_local_delegation import brief, wait, service as delegation_service # noqa: F401
Expand Down
Loading