diff --git a/backend/app/main.py b/backend/app/main.py index 7dbb7ef..8612615 100644 --- a/backend/app/main.py +++ b/backend/app/main.py @@ -267,15 +267,14 @@ def runs(): # model-oriented for internal scheduling callers and enrich only this API # representation. values = [] - for run in store.runs(): - item = run.model_dump(mode="json") + for item in store.run_summaries(): responses = [ record.get("response") - for record in run.supervisor_results + for record in item.get("supervisor_results", []) if isinstance(record, dict) and isinstance(record.get("response"), dict) ] - if not responses and isinstance(run.supervisor_response, dict): - responses = [run.supervisor_response] + if not responses and isinstance(item.get("supervisor_response"), dict): + responses = [item["supervisor_response"]] improvements = [ improvement for response in responses @@ -574,6 +573,8 @@ class BuildCreate(BaseModel): candidates_per_iteration: int = Field(default=2, ge=2, le=8) approval_score: int = Field(ge=0, le=10) require_human_approval_before_apply: bool = False + agent_apply_policy: Literal["review_required", "auto_commit_branch"] = "review_required" + agent_auto_commit_allowed_paths: list[str] = Field(default_factory=list, max_length=32) executor_type: str = Field( default="local", pattern=r"^(local|remote-http)$" ) # Legacy fallback; selected execution environment is authoritative. diff --git a/backend/app/store.py b/backend/app/store.py index ed36625..fb8654c 100644 --- a/backend/app/store.py +++ b/backend/app/store.py @@ -1456,6 +1456,8 @@ def builds(self) -> list[dict[str, Any]]: # Existing builds predate this optional policy, so leave it off # unless an operator explicitly enabled it. build.setdefault("require_human_approval_before_apply", False) + build.setdefault("agent_apply_policy", "review_required") + build.setdefault("agent_auto_commit_allowed_paths", []) build.setdefault("starred", False) self._hydrate_build_environment(build) build.update(self._repository_metadata(str(build.get("repository", "")))) @@ -2283,6 +2285,8 @@ def create_build(self, values: dict[str, Any]) -> dict[str, Any]: "require_human_approval_before_apply": bool( values.get("require_human_approval_before_apply", False) ), + "agent_apply_policy": values.get("agent_apply_policy", "review_required"), + "agent_auto_commit_allowed_paths": list(values.get("agent_auto_commit_allowed_paths", [])), "executor": executor, } builds = self.builds() @@ -2377,6 +2381,8 @@ def update_build(self, build_id: str, values: dict[str, Any]) -> dict[str, Any]: "require_human_approval_before_apply": bool( values.get("require_human_approval_before_apply", False) ), + "agent_apply_policy": values.get("agent_apply_policy", "review_required"), + "agent_auto_commit_allowed_paths": list(values.get("agent_auto_commit_allowed_paths", [])), "executor": executor, } builds[index] = build @@ -3765,6 +3771,55 @@ def runs(self) -> list[Run]: entries = [Run.model_validate_json(path.read_text(encoding="utf-8")) for path in RUNS.glob("*.json")] return sorted(entries, key=lambda run: run.created_at, reverse=True) + def run_summaries(self) -> list[dict[str, Any]]: + """Return the run-history fields without repeatedly loading full evidence. + + The control room polls this collection. Browser snapshots, command + output, and saved artifacts belong to the detail endpoint; loading + every one of them for every poll can starve the local API and leave the + UI in its loading state. + """ + summaries: list[dict[str, Any]] = [] + step_keys = { + "step_id", + "phase", + "loop_index", + "candidate_id", + "name", + "started_at", + "ended_at", + "in_progress", + "exit_code", + "error", + } + for path in RUNS.glob("*.json"): + try: + payload = json.loads(path.read_text(encoding="utf-8")) + except (OSError, ValueError): + continue + if not isinstance(payload, dict): + continue + steps = payload.get("step_results", []) + compact_steps = [] + for step in steps if isinstance(steps, list) else []: + if not isinstance(step, dict): + continue + compact = {key: value for key, value in step.items() if key in step_keys} + result = step.get("result") + simulator = result.get("insighta_persona_simulator") if isinstance(result, dict) else None + active = simulator.get("active_personas") if isinstance(simulator, dict) else None + if isinstance(active, list): + compact["result"] = {"insighta_persona_simulator": {"active_personas": active}} + compact_steps.append(compact) + payload["step_results"] = compact_steps + payload.pop("prompt_snapshot", None) + payload.pop("workflow_graph", None) + for record in payload.get("supervisor_results", []): + if isinstance(record, dict): + record.pop("prompt", None) + summaries.append(payload) + return sorted(summaries, key=lambda run: str(run.get("created_at") or ""), reverse=True) + def delete_run(self, run_id: str) -> None: run = self._load(run_id) if run.status in {"queued", "running", "awaiting_approval"}: diff --git a/backend/orbit_sdk/__init__.py b/backend/orbit_sdk/__init__.py index e54ae6a..608d273 100644 --- a/backend/orbit_sdk/__init__.py +++ b/backend/orbit_sdk/__init__.py @@ -8,7 +8,12 @@ import sys from types import ModuleType -from .browser import NetworkSettleOptions, install_selenium_network_tracker, wait_for_selenium_page_settlement +from .browser import ( + NetworkSettleOptions, + install_selenium_network_tracker, + selenium_http_failures, + wait_for_selenium_page_settlement, +) from .core import context as _context from .core.context import ( ORBIT_APP_DATA, @@ -49,6 +54,7 @@ def __setattr__(self, name: str, value: object) -> None: "canonical_phase", "graph", "install_selenium_network_tracker", + "selenium_http_failures", "runner", "wait_for_selenium_page_settlement", ] diff --git a/backend/orbit_sdk/browser.py b/backend/orbit_sdk/browser.py index 9b3cadb..1833344 100644 --- a/backend/orbit_sdk/browser.py +++ b/backend/orbit_sdk/browser.py @@ -10,6 +10,7 @@ import time from dataclasses import asdict, dataclass from typing import Any, Iterable +from urllib.parse import urlsplit, urlunsplit DEFAULT_IGNORED_URL_PATTERNS = ( r"analytics", @@ -86,6 +87,45 @@ def install_selenium_network_tracker( driver.execute_script(script) +def selenium_http_failures(driver: Any, *, limit: int = 20) -> list[dict[str, Any]]: + """Return newly emitted failed HTTP responses from Chrome performance logs. + + Query strings and fragments are deliberately removed: browser evidence must + identify a failing asset without persisting credentials or user data. + Callers enable Chrome's ``performance`` log independently; unsupported + drivers simply return no diagnostic entries. + """ + try: + entries = driver.get_log("performance") + except Exception: + return [] + + failures: list[dict[str, Any]] = [] + for entry in entries if isinstance(entries, list) else []: + try: + message = json.loads(entry.get("message", "{}")).get("message", {}) + if message.get("method") != "Network.responseReceived": + continue + params = message.get("params", {}) + response = params.get("response", {}) + status = int(response.get("status", 0)) + url = str(response.get("url", "")) + if status < 400 or not url: + continue + parsed = urlsplit(url) + failures.append( + { + "status": status, + "url": urlunsplit((parsed.scheme, parsed.netloc, parsed.path, "", "")), + "mime_type": str(response.get("mimeType", "")), + "request_type": str(params.get("type", "")), + } + ) + except (TypeError, ValueError, json.JSONDecodeError): + continue + return failures[-limit:] + + def wait_for_selenium_page_settlement( driver: Any, *, diff --git a/backend/orbit_sdk/core/context.py b/backend/orbit_sdk/core/context.py index 710cc29..c227a77 100644 --- a/backend/orbit_sdk/core/context.py +++ b/backend/orbit_sdk/core/context.py @@ -7,6 +7,7 @@ from __future__ import annotations import base64 +import fnmatch import hashlib import json import os @@ -29,6 +30,18 @@ PROJECT_ROOT = Path(os.environ.get("ORBIT_TARGET_REPOSITORY", Path.cwd())).resolve() ORBIT_APP_DATA = Path(os.environ.get("ORBIT_APP_DATA", Path.home() / ".local" / "share" / "orbit")).resolve() +# These paths are never eligible for unattended agent commits, even when an +# operator accidentally includes them in an allow-list. They alter deployment, +# credentials, or persistent data and must remain review-only. +_AUTO_COMMIT_BLOCKED_PATHS = ( + ".github/**", + "infra/**", + "migrations/**", + "**/migrations/**", + "*.pem", + "*.key", +) + def ORBIT_PROJECT_PATH(*parts: str) -> Path: """Resolve a safe path relative to the evaluation target repository. @@ -1701,6 +1714,41 @@ def register_evaluation( self.emit_result({"evaluation_request": request}) return request + def _auto_commit_policy_result(self, changed_files: list[str], feedback: str) -> dict[str, object]: + """Return whether this isolated proposal may receive an unattended commit. + + This is deliberately an allow-list gate rather than a convenience + switch: the policy does not push or merge and sensitive repository + paths cannot be opted in. + """ + build = self.build + if str(build.get("agent_apply_policy", "review_required")) != "auto_commit_branch": + return {"status": "not_requested"} + if not feedback or not changed_files: + return {"status": "skipped", "reason": "proposal_has_no_feedback_or_changes"} + allowed = [ + str(pattern).strip() + for pattern in build.get("agent_auto_commit_allowed_paths", []) + if str(pattern).strip() + ] + if not allowed: + return {"status": "skipped", "reason": "allow_list_is_empty"} + blocked = [ + path + for path in changed_files + if any(fnmatch.fnmatchcase(path, pattern) for pattern in _AUTO_COMMIT_BLOCKED_PATHS) + ] + if blocked: + return {"status": "skipped", "reason": "blocked_path", "paths": blocked} + outside_allow_list = [ + path + for path in changed_files + if not any(fnmatch.fnmatchcase(path, pattern) for pattern in allowed) + ] + if outside_allow_list: + return {"status": "skipped", "reason": "path_not_allow_listed", "paths": outside_allow_list} + return {"status": "eligible"} + def run_ai_agent( self, prompt: str, @@ -1714,6 +1762,11 @@ def run_ai_agent( The agent must print ``ORBIT_AGENT_FEEDBACK: `` as its final feedback line to opt its work into evaluation. This keeps a silent or no-op agent run from creating a score for the iteration. + + When the Build's ``agent_apply_policy`` is ``auto_commit_branch``, a + proposal that stays within its explicit allow-list is committed only to + its isolated proposal branch. It is never pushed, merged, or applied to + the evaluated repository. """ normalized_prompt = prompt.strip() if not normalized_prompt: @@ -1738,6 +1791,8 @@ def run_ai_agent( output = "" changed_files: list[str] = [] patch = "" + feedback = "" + auto_commit: dict[str, object] = {"status": "not_requested"} keep_worktree = False try: output = self.exec( @@ -1746,6 +1801,9 @@ def run_ai_agent( timeout=timeout, target_log_source="ai-agent", ) + agent_head = self.exec(["git", "rev-parse", "HEAD"], cwd=worktree).strip() + if agent_head and agent_head != base_revision: + raise RuntimeError("AI agent proposals must not create commits") # Include newly-created files in the review patch without creating # a commit. Intent-to-add is local to this disposable proposal # worktree and is finalized only after Issue approval. @@ -1765,6 +1823,20 @@ def run_ai_agent( ), "", ) + auto_commit = self._auto_commit_policy_result(changed_files, feedback) + if auto_commit["status"] == "eligible": + self.exec(["git", "add", "--all"], cwd=worktree) + self.exec( + ["git", "commit", "-m", f"orbit: autonomous proposal for {run_id}"], + cwd=worktree, + target_log_source="ai-agent", + ) + auto_commit = { + "status": "committed", + "commit": self.exec(["git", "rev-parse", "HEAD"], cwd=worktree).strip(), + "branch": branch, + "allowed_paths": list(self.build.get("agent_auto_commit_allowed_paths", [])), + } keep_worktree = bool(feedback and patch) finally: if not keep_worktree: @@ -1802,6 +1874,7 @@ def run_ai_agent( "diff": patch, "fingerprint": _sha256(patch.encode("utf-8")) if patch else "", "diff_artifact": artifact, + "auto_commit": auto_commit, }, } self.emit_result({"agent_run": result}) diff --git a/backend/orbit_sdk/visual/canonical/runner-templates/autonomous-persona-journey/runner.py b/backend/orbit_sdk/visual/canonical/runner-templates/autonomous-persona-journey/runner.py index ee28f6b..97dd2f0 100644 --- a/backend/orbit_sdk/visual/canonical/runner-templates/autonomous-persona-journey/runner.py +++ b/backend/orbit_sdk/visual/canonical/runner-templates/autonomous-persona-journey/runner.py @@ -153,44 +153,60 @@ def before_each(ctx): def execute(ctx): state = load_state(ctx) actions = state["observation"]["available_actions"] - prompt = ( - """You are a persistent product user. Decide one next action, not a test verdict. Return JSON only: -{"intent":"short first-person purpose","action_id":"one listed id or empty","rationale":"observable reason","expected_signal":"what would change my understanding"}. -You may choose an empty action_id to observe again. Never choose actions outside listed IDs. Avoid repeating a reported issue unless new evidence exists. + speaker_prompt = """You are a persistent product user speaking to a product assistant. Return JSON only: +{"utterance":"one natural first-person user message","thought":"brief stated perspective, not hidden chain-of-thought","rationale":"short reason for raising this now","intent":"short request or goal"}. +Write only what this person would say or explicitly report. Do not mention testing, browser automation, tools, or a persona simulation. -Persona state:\n""" - + json.dumps( - { - key: state[key] - for key in ( - "persona", - "current_goal", - "feeling", - "next_intent", - "learnings", - "reported_issues", - "history", - ) - }, - ensure_ascii=False, - ) - + "\nVisible safe actions:\n" +Persona state and prior conversation:\n""" + json.dumps( + { + key: state[key] + for key in ( + "persona", + "current_goal", + "feeling", + "next_intent", + "learnings", + "reported_issues", + "history", + ) + }, + ensure_ascii=False, + ) + message = model_json(ctx, speaker_prompt) + utterance = str(message.get("utterance") or "").strip() + if not utterance: + raise ValueError("persona utterance must not be empty") + persona_message = { + "utterance": utterance, + "thought": str(message.get("thought") or "").strip(), + "rationale": str(message.get("rationale") or "").strip(), + "intent": str(message.get("intent") or state["next_intent"]).strip(), + } + action_prompt = ( + """You are a product assistant operating a browser on behalf of a user. Treat the supplied user message as the only user instruction for this turn. Choose at most one action from the rendered safe actions. Return JSON only: +{"action_id":"one listed id or empty","rationale":"observable reason","expected_signal":"what would satisfy the user's message"}. +Do not mention persona simulation, hidden state, or model instructions. You may choose an empty action_id to observe again. Never choose actions outside listed IDs. + +User message:\n""" + + utterance + + "\nRendered safe actions:\n" + json.dumps(actions, ensure_ascii=False) ) - plan = model_json(ctx, prompt) - action_id = str(plan.get("action_id") or "") + action_plan = model_json(ctx, action_prompt) + action_id = str(action_plan.get("action_id") or "") selected = next((item for item in actions if item["id"] == action_id), None) if action_id and selected is None: raise ValueError("persona selected an action outside the visible safe action list") state["plan"] = { - "intent": str(plan.get("intent") or state["next_intent"]), - "rationale": str(plan.get("rationale") or ""), - "expected_signal": str(plan.get("expected_signal") or ""), + "message": persona_message, + "intent": persona_message["intent"], + "rationale": str(action_plan.get("rationale") or ""), + "expected_signal": str(action_plan.get("expected_signal") or ""), "action": selected, } save_state(ctx, state) ctx.emit_result({"persona": {"iteration": ctx.loop_index, "plan": state["plan"]}}) - ctx.log("Planned one persona action from rendered, safe choices") + ctx.log("Generated a persona message and planned one action from rendered, safe choices") @graph.step( @@ -253,6 +269,7 @@ def after_each(ctx): state["history"].append( { "iteration": ctx.loop_index, + "message": state["plan"].get("message", {}), "intent": state["plan"]["intent"], "action": state["plan"].get("action"), "feeling": state["feeling"], diff --git a/backend/orbit_sdk/visual/journeys.py b/backend/orbit_sdk/visual/journeys.py index b55e943..77e56fa 100644 --- a/backend/orbit_sdk/visual/journeys.py +++ b/backend/orbit_sdk/visual/journeys.py @@ -311,48 +311,64 @@ def observe_persona_page(ctx: Any, config: Mapping[str, Any], _: Mapping[str, ob required_config=("namespace",), ) def plan_persona_action(ctx: Any, config: Mapping[str, Any], _: Mapping[str, object]) -> dict[str, object]: - """Let a persona select exactly one action from rendered safe choices.""" + """Generate a persona utterance, then plan an action from that utterance.""" namespace = config["namespace"] state = _persona_state(ctx, namespace) actions = state["observation"]["available_actions"] - prompt = ( - """You are a persistent product user. Decide one next action, not a test verdict. Return JSON only: -{"intent":"short first-person purpose","action_id":"one listed id or empty","rationale":"observable reason","expected_signal":"what would change my understanding"}. -You may choose an empty action_id to observe again. Never choose actions outside listed IDs. Avoid repeating a reported issue unless new evidence exists. + speaker_prompt = """You are a persistent product user speaking to a product assistant. Return JSON only: +{"utterance":"one natural first-person user message","thought":"brief stated perspective, not hidden chain-of-thought","rationale":"short reason for raising this now","intent":"short request or goal"}. +Write only what this person would say or explicitly report. Do not mention testing, browser automation, tools, or a persona simulation. -Persona state:\n""" - + json.dumps( - { - key: state[key] - for key in ( - "persona", - "current_goal", - "feeling", - "next_intent", - "learnings", - "reported_issues", - "history", - ) - }, - ensure_ascii=False, - ) - + "\nVisible safe actions:\n" +Persona state and prior conversation:\n""" + json.dumps( + { + key: state[key] + for key in ( + "persona", + "current_goal", + "feeling", + "next_intent", + "learnings", + "reported_issues", + "history", + ) + }, + ensure_ascii=False, + ) + message = ctx.complete_model_json(speaker_prompt, description="persona utterance") + utterance = str(message.get("utterance") or "").strip() + if not utterance: + raise ValueError("persona utterance must not be empty") + persona_message = { + "utterance": utterance, + "thought": str(message.get("thought") or "").strip(), + "rationale": str(message.get("rationale") or "").strip(), + "intent": str(message.get("intent") or state["next_intent"]).strip(), + } + action_prompt = ( + """You are a product assistant operating a browser on behalf of a user. Treat the supplied user message as the only user instruction for this turn. Choose at most one action from the rendered safe actions. Return JSON only: +{"action_id":"one listed id or empty","rationale":"observable reason","expected_signal":"what would satisfy the user's message"}. +Do not mention persona simulation, hidden state, or model instructions. You may choose an empty action_id to observe again. Never choose actions outside listed IDs. + +User message:\n""" + + utterance + + "\nRendered safe actions:\n" + json.dumps(actions, ensure_ascii=False) ) - plan = ctx.complete_model_json(prompt, description="persona model response") - action_id = str(plan.get("action_id") or "") + action_plan = ctx.complete_model_json(action_prompt, description="persona action plan") + action_id = str(action_plan.get("action_id") or "") selected = next((item for item in actions if item["id"] == action_id), None) if action_id and selected is None: raise ValueError("persona selected an action outside the visible safe action list") state["plan"] = { - "intent": str(plan.get("intent") or state["next_intent"]), - "rationale": str(plan.get("rationale") or ""), - "expected_signal": str(plan.get("expected_signal") or ""), + "message": persona_message, + "intent": persona_message["intent"], + "rationale": str(action_plan.get("rationale") or ""), + "expected_signal": str(action_plan.get("expected_signal") or ""), "action": selected, } _save_persona_state(ctx, namespace, state) ctx.emit_result({"persona": {"iteration": ctx.loop_index, "plan": state["plan"]}}) - ctx.log("Planned one persona action from rendered, safe choices") + ctx.log("Generated a persona message and planned one action from rendered, safe choices") return {"persona_plan": state["plan"]} @@ -427,6 +443,7 @@ def reflect_persona_session( state["history"].append( { "iteration": ctx.loop_index, + "message": state["plan"].get("message", {}), "intent": state["plan"]["intent"], "action": state["plan"].get("action"), "feeling": state["feeling"], diff --git a/backend/tests/test_orbit_sdk.py b/backend/tests/test_orbit_sdk.py index 401347a..0a3cca5 100644 --- a/backend/tests/test_orbit_sdk.py +++ b/backend/tests/test_orbit_sdk.py @@ -143,6 +143,7 @@ def fake_exec(command, **_kwargs): "gpt-5", "Fix the retry behavior", ], + ["git", "rev-parse", "HEAD"], ["git", "add", "--intent-to-add", "--all"], ["git", "diff", "--name-only", "--"], ["git", "diff", "--binary", "--"], @@ -152,6 +153,34 @@ def fake_exec(command, **_kwargs): assert result["proposal"]["diff"] == "diff --git a/src/retry.py b/src/retry.py\n" assert result["proposal"]["base_revision"] assert result["proposal"]["branch"].startswith("orbit/agent-proposal/run-123/") + assert result["proposal"]["auto_commit"] == {"status": "not_requested"} + + +def test_auto_commit_policy_requires_an_allow_list_and_blocks_sensitive_paths(tmp_path): + resources = b64encode( + json.dumps( + { + "build": { + "agent_apply_policy": "auto_commit_branch", + "agent_auto_commit_allowed_paths": ["backend/**", ".github/**"], + } + } + ).encode() + ).decode() + ctx = sdk.RunnerContext( + phase="execute", + target_repository=tmp_path, + mode="run", + loop_index=1, + environment={"ORBIT_RUNNER_RESOURCES": resources}, + ) + + assert ctx._auto_commit_policy_result(["backend/app/agent.py"], "done") == {"status": "eligible"} + assert ctx._auto_commit_policy_result([".github/workflows/release.yml"], "done") == { + "status": "skipped", + "reason": "blocked_path", + "paths": [".github/workflows/release.yml"], + } def test_graph_step_automatically_traces_its_execution(tmp_path, capsys): @@ -246,6 +275,56 @@ def execute_script(self, script): assert evidence["label"] == "capture" +def test_selenium_http_failures_records_safe_response_details(): + class Driver: + def get_log(self, name): + assert name == "performance" + return [ + { + "message": json.dumps( + { + "message": { + "method": "Network.responseReceived", + "params": { + "type": "Script", + "response": { + "status": 401, + "url": "https://dev-console.insighta.cloud/_next/app.js?token=secret#part", + "mimeType": "application/javascript", + }, + }, + } + } + ) + }, + { + "message": json.dumps( + { + "message": { + "method": "Network.responseReceived", + "params": { + "type": "Document", + "response": { + "status": 200, + "url": "https://dev-console.insighta.cloud/ja/library", + }, + }, + } + } + ) + }, + ] + + assert sdk.selenium_http_failures(Driver()) == [ + { + "status": 401, + "url": "https://dev-console.insighta.cloud/_next/app.js", + "mime_type": "application/javascript", + "request_type": "Script", + } + ] + + def test_update_file_retains_previous_contents_and_metadata(tmp_path, monkeypatch): project = tmp_path / "project" project.mkdir() diff --git a/backend/tests/test_persona_journeys.py b/backend/tests/test_persona_journeys.py new file mode 100644 index 0000000..44e61e2 --- /dev/null +++ b/backend/tests/test_persona_journeys.py @@ -0,0 +1,83 @@ +from __future__ import annotations + +from orbit_sdk.visual.journeys import plan_persona_action, reflect_persona_session + + +class PersonaContext: + loop_index = 3 + + def __init__(self): + self.state = { + "persona": "A careful buyer", + "current_goal": "Check an order status", + "feeling": "concerned", + "next_intent": "Find my order details.", + "learnings": [], + "reported_issues": [], + "history": [{"iteration": 2, "message": {"utterance": "Where is my order?"}}], + "observation": { + "available_actions": [ + {"id": "link-0", "href": "https://example.test/orders", "label": "Orders"} + ], + "before_url": "https://example.test/", + }, + "evidence": {"url": "https://example.test/orders"}, + } + self.prompts: list[str] = [] + self.events: list[dict] = [] + self.responses = [ + { + "utterance": "결제한 주문이 아직 보이지 않아요. 주문 상태를 확인해 주세요.", + "thought": "결제 반영이 늦는지 걱정된다.", + "rationale": "주문 내역을 찾을 수 없다.", + "intent": "주문 상태 확인", + }, + { + "action_id": "link-0", + "rationale": "주문 목록에서 상태를 확인할 수 있다.", + "expected_signal": "주문 상태", + }, + { + "feeling": "안심했다", + "learning": "주문 목록에서 상태를 확인할 수 있었다.", + "issue": {"title": "", "evidence": "", "severity": "low"}, + "next_intent": "주문 상태를 다시 확인한다.", + }, + ] + + def load_state(self, _namespace, _default): + return self.state + + def save_state(self, _namespace, value): + self.state = value + + def complete_model_json(self, prompt, *, description): + self.prompts.append(prompt) + return self.responses.pop(0) + + def emit_result(self, value): + self.events.append(value) + + def log(self, _message): + pass + + def save_data_file(self, *_args, **_kwargs): + return {"relative_path": "autonomous-persona/iteration-3.json"} + + +def test_persona_message_is_generated_before_the_action_agent_and_retained_in_history(): + ctx = PersonaContext() + + plan = plan_persona_action(ctx, {"namespace": "persona"}, {})["persona_plan"] + + assert plan["message"]["utterance"].startswith("결제한 주문") + assert plan["action"]["id"] == "link-0" + assert "A careful buyer" not in ctx.prompts[1] + assert "Where is my order?" not in ctx.prompts[1] + assert plan["message"]["thought"] not in ctx.prompts[1] + assert plan["message"]["rationale"] not in ctx.prompts[1] + assert plan["message"]["utterance"] in ctx.prompts[1] + + reflect_persona_session(ctx, {"namespace": "persona"}, {}) + + assert ctx.state["history"][-1]["message"] == plan["message"] diff --git a/frontend/src/domain/models.ts b/frontend/src/domain/models.ts index 6940e31..6e3b103 100644 --- a/frontend/src/domain/models.ts +++ b/frontend/src/domain/models.ts @@ -4,7 +4,7 @@ export type TargetTestCaseSet = { id:string; name:string; description:string; ca export type ExecutionEnvironment = {id:string;name:string;executor:{type:'local'|'remote-http';endpoint?:string;method?:'GET'|'POST'|'PUT';timeout_seconds?:number;headers?:Record};browser_executable_path?:string;browser_library_path?:string;environment_variables?:Record;created_at?:string} export type TargetEnvironment = {id:string;name:string;repository:string;browser_base_url?:string;managed_prompt_path?:string;created_at?:string} export type Persona = {id:string;name:string;locale:string;timezone:string;activity_windows:{days?:string[];start?:string;end?:string}[];definition:string;context:Record;created_at?:string} -export type Build = { id:string; name:string; enabled:boolean; starred?:boolean; runner_id:string;runner_version?:number|null;persona_ids?:string[]; execution_environment_id?:string;target_environment_id?:string; repository:string; repository_name?:string; repository_is_git?:boolean; repository_error?:string; purpose:string;manager_template_id?:string;model_profile_name?:string;test_case_set_id?:string;test_cases?:TestCase[];browser_base_url?:string;browser_executable_path?:string;browser_library_path?:string;timezone:string;repeat_interval_minutes:number;run_limit:number;cadence_mode?:'after_completion'|'fixed';overrun_policy?:'wait'|'interrupt_eval';schedule_enabled?:boolean;schedule_weekdays?:number[];schedule_start_time?:string;schedule_end_time?:string;iteration_strategy?:'linear'|'score_select';candidates_per_iteration?:number;approval_score:number;require_human_approval_before_apply?:boolean;created_at?:string;last_run_at?:string;run_count?:number;executor?:{type?:'local'|'remote-http';endpoint?:string;method?:'GET'|'POST'|'PUT';timeout_seconds?:number;headers?:Record} } +export type Build = { id:string; name:string; enabled:boolean; starred?:boolean; runner_id:string;runner_version?:number|null;persona_ids?:string[]; execution_environment_id?:string;target_environment_id?:string; repository:string; repository_name?:string; repository_is_git?:boolean; repository_error?:string; purpose:string;manager_template_id?:string;model_profile_name?:string;test_case_set_id?:string;test_cases?:TestCase[];browser_base_url?:string;browser_executable_path?:string;browser_library_path?:string;timezone:string;repeat_interval_minutes:number;run_limit:number;cadence_mode?:'after_completion'|'fixed';overrun_policy?:'wait'|'interrupt_eval';schedule_enabled?:boolean;schedule_weekdays?:number[];schedule_start_time?:string;schedule_end_time?:string;iteration_strategy?:'linear'|'score_select';candidates_per_iteration?:number;approval_score:number;require_human_approval_before_apply?:boolean;agent_apply_policy?:'review_required'|'auto_commit_branch';agent_auto_commit_allowed_paths?:string[];created_at?:string;last_run_at?:string;run_count?:number;executor?:{type?:'local'|'remote-http';endpoint?:string;method?:'GET'|'POST'|'PUT';timeout_seconds?:number;headers?:Record} } export type RunnerState = { name:string; scope:'build'|'runner'; runner_id?:string; updated_at?:string; run_id?:string; iteration?:number; value:unknown } export type PromptTemplate = { id:string; name:string; version:number; content:string; versions?:{version:number;content:string}[];created_at?:string } export type SavedDataFile = { label?:string; filename:string; path:string; relative_path?:string; sha256?:string; size?:number; content_type?:string } diff --git a/frontend/src/features/builds/page.tsx b/frontend/src/features/builds/page.tsx index 6e7a964..7514196 100644 --- a/frontend/src/features/builds/page.tsx +++ b/frontend/src/features/builds/page.tsx @@ -65,6 +65,8 @@ type Draft = { candidates_per_iteration: number; approval_score: number; require_human_approval_before_apply: boolean; + agent_apply_policy: "review_required" | "auto_commit_branch"; + agent_auto_commit_allowed_paths: string[]; enabled: boolean; }; @@ -111,6 +113,10 @@ type BuildWizardCopy = { approvalScore: LabelCopy; humanApproval: LabelCopy; humanApprovalEnable: string; + agentApplyPolicy: LabelCopy; + agentApplyReview: string; + agentApplyCommit: string; + agentAllowedPaths: LabelCopy; name: string; next: string; }; @@ -147,6 +153,8 @@ const empty: Draft = { candidates_per_iteration: 2, approval_score: 8, require_human_approval_before_apply: false, + agent_apply_policy: "review_required", + agent_auto_commit_allowed_paths: [], enabled: true, }; const testIsActive = (status: string) => @@ -178,6 +186,8 @@ const draftOf = (b: Build, copy = false): Draft => ({ approval_score: b.approval_score, require_human_approval_before_apply: b.require_human_approval_before_apply ?? false, + agent_apply_policy: b.agent_apply_policy ?? "review_required", + agent_auto_commit_allowed_paths: b.agent_auto_commit_allowed_paths ?? [], enabled: b.enabled, }); const Field = ({ @@ -598,6 +608,15 @@ function Direct({ {copy.humanApprovalEnable} + + + + {d.agent_apply_policy === "auto_commit_branch" && + setD({ ...d, agent_auto_commit_allowed_paths: e.target.value.split(",").map((value) => value.trim()).filter(Boolean) })} /> + } )} {step === 5 && ( diff --git a/frontend/src/features/evaluations/page.tsx b/frontend/src/features/evaluations/page.tsx index 1a48b58..405b6a2 100644 --- a/frontend/src/features/evaluations/page.tsx +++ b/frontend/src/features/evaluations/page.tsx @@ -33,6 +33,7 @@ import { } from "./run-detail-log-panels"; import { SupervisorPanel } from "./run-detail-supervisor-panel"; import { EvaluationResultPanel } from "./run-detail-result-panel"; +import { RunDetailConversationPanel } from "./run-detail-conversation-panel"; const phases = [ "before_all", @@ -134,6 +135,7 @@ export function EvaluationsPage({ l = copy[locale], ui = locales[locale].runUi; const [selectedInternal, setSelected] = useState(null), + [selectedDetail, setSelectedDetail] = useState(null), [tab, setTab] = useState("result"), [iterationTab, setIterationTab] = useState(1), [candidateTab, setCandidateTab] = useState(null), @@ -198,9 +200,18 @@ export function EvaluationsPage({ [retryingRun, setRetryingRun] = useState(null); const retryCopy = locale === "ko" ? { title: "실행 재시도", warning: "재시도는 작업 디렉터리 또는 외부 대상의 중간 결과를 변경할 수 있습니다.", restart: "1부터 다시 시작", resume: "마지막 이터레이션부터 재시도" } : locale === "ja" ? { title: "実行を再試行", warning: "再試行により作業ディレクトリまたは外部ターゲットの中間結果が変わる可能性があります。", restart: "反復 1 から再開", resume: "最後の反復から再試行" } : { title: "Retry run", warning: "Retrying can change intermediate results in the working directory or external target.", restart: "Restart from iteration 1", resume: "Retry from the last iteration" }; const selectedSource = initialSelectedRun ?? selectedInternal; + const selectedRunId = selectedSource?.id; const selected = selectedSource - ? runs.find((run) => run.id === selectedSource.id) ?? selectedSource + ? (selectedDetail?.id === selectedSource.id ? selectedDetail : runs.find((run) => run.id === selectedSource.id) ?? selectedSource) : null; + useEffect(() => { + if (!selectedRunId) return; + let active = true; + api(`/api/runs/${encodeURIComponent(selectedRunId)}`) + .then((run) => { if (active) setSelectedDetail(run); }) + .catch(() => { if (active) setSelectedDetail(null); }); + return () => { active = false; }; + }, [selectedRunId]); const supervisorTranslationIds = useMemo( () => (selected?.supervisor_results ?? []) @@ -972,6 +983,7 @@ export function EvaluationsPage({ title={l.detail} onClose={() => { setSelected(null); + setSelectedDetail(null); onSelectedRunClose?.(); }} className="modal--run-detail" @@ -1043,6 +1055,7 @@ export function EvaluationsPage({ { id: "result", label: l.result }, { id: "commits", label: l.worktrees }, { id: "supervisor", label: l.supervisor }, + { id: "conversation", label: l.conversation }, { id: "logs", label: l.logs }, ]} /> @@ -1110,6 +1123,11 @@ export function EvaluationsPage({ /> )} + {tab === "conversation" && ( + + + + )} {tab === "result" && (
diff --git a/frontend/src/features/evaluations/run-detail-conversation-panel.tsx b/frontend/src/features/evaluations/run-detail-conversation-panel.tsx new file mode 100644 index 0000000..8b92877 --- /dev/null +++ b/frontend/src/features/evaluations/run-detail-conversation-panel.tsx @@ -0,0 +1,94 @@ +import { useMemo, useState } from "react"; +import type { RunStepResult } from "../../domain/models"; +import { EvidenceViewer, visualEvidenceArtifacts } from "../../components/ui/evidence-viewer"; +import { intlLocales, type Locale } from "../../locales"; + +type RecordItem = Record; +type DialogueMessage = { role: "persona" | "assistant" | "tool"; content: string; recordedAt?: string }; +type Session = { persona: string; personaName: string; dialogue: DialogueMessage[]; iteration: number; recordedAt?: string; artifacts: ReturnType }; +type Copy = Record; + +const record = (value: unknown): RecordItem | null => value && typeof value === "object" && !Array.isArray(value) ? value as RecordItem : null; + +function dialogue(value: unknown): DialogueMessage[] { + if (!Array.isArray(value)) return []; + return value.flatMap((message) => { + const item = record(message); + const role = item?.role; + const content = item?.content; + const recordedAt = typeof item?.recorded_at === "string" ? item.recorded_at : undefined; + return (role === "persona" || role === "assistant" || role === "tool") && typeof content === "string" + ? [{ role, content, recordedAt }] + : []; + }); +} + +// Tool output is deliberately reduced to a small public summary. It never renders +// the raw browser payload, which can contain page text or implementation detail. +function publicToolSummary(content: string) { + try { + const payload = record(JSON.parse(content)); + if (!payload) return content; + const actions = Array.isArray(payload.actions) ? payload.actions : []; + const actionSummary = actions.flatMap((action) => { + const item = record(action); + const type = typeof item?.type === "string" ? item.type : undefined; + const status = typeof item?.status === "string" ? item.status : undefined; + return type ? [`${type}${status ? ` · ${status}` : ""}`] : []; + }); + const page = record(payload.page); + const pageSummary = typeof page?.title === "string" ? page.title : undefined; + return [...actionSummary, ...(pageSummary ? [pageSummary] : [])].join("\n") || "No public browser result was returned."; + } catch { + return "No structured public tool result was returned."; + } +} + +function sessionsFrom(steps: RunStepResult[]): Session[] { + const latestByPersona = new Map(); + for (const step of steps) { + const simulator = record(step.result?.insighta_persona_simulator); + const evidence = simulator?.persona_evidence; + if (!Array.isArray(evidence)) continue; + for (const [index, entry] of evidence.entries()) { + const item = record(entry); + const plan = record(item?.plan); + const messages = dialogue(plan?.dialogue); + if (!item || !messages.length) continue; + const persona = typeof item.persona === "string" ? item.persona : `Persona ${index + 1}`; + const personaName = typeof item.persona_name === "string" && item.persona_name ? item.persona_name : persona; + // A runner emits the same evidence from both the source-backed session + // and the retention step. Keep the later record for one Persona/iteration. + latestByPersona.set(`${step.loop_index ?? 0}:${persona}`, { + persona, + personaName, + dialogue: messages, + iteration: step.loop_index ?? 0, + recordedAt: step.ended_at ?? step.started_at, + artifacts: visualEvidenceArtifacts(step.data_files ?? []), + }); + } + } + return [...latestByPersona.values()]; +} + +export function RunDetailConversationPanel({ steps, runId, l, locale }: { steps: RunStepResult[]; runId: string; l: Copy; locale: Locale }) { + const sessions = useMemo(() => sessionsFrom(steps), [steps]); + const [selectedPersona, setSelectedPersona] = useState(""); + const session = sessions.find((item) => item.persona === selectedPersona) ?? sessions[0]; + if (!session) return
{l.noConversation}

{l.noConversationHint}

; + return
+
+ {sessions.map((item) => )} +
+
    + {session.dialogue.map((message, index) =>
  1. +
    {message.role === "persona" ? `${l.persona} (${session.personaName})` : message.role === "assistant" ? l.toolAi : l.toolResult}{(message.recordedAt ?? session.recordedAt) && }
    + {message.role === "tool" ?
    {l.showToolResult}
    {publicToolSummary(message.content)}
    :

    {message.content}

    } + {message.role === "tool" && } +
  2. )} +
+
; +} diff --git a/frontend/src/features/evaluations/run-detail-tabs.tsx b/frontend/src/features/evaluations/run-detail-tabs.tsx index c9f21f0..8c6be26 100644 --- a/frontend/src/features/evaluations/run-detail-tabs.tsx +++ b/frontend/src/features/evaluations/run-detail-tabs.tsx @@ -5,6 +5,7 @@ export type RunDetailTab = | "logs" | "supervisor" | "commits" + | "conversation" | "result"; type Tab = { id: T; label: string }; diff --git a/frontend/src/locales/languages/en.json b/frontend/src/locales/languages/en.json index 51e2b10..b12f9c4 100644 --- a/frontend/src/locales/languages/en.json +++ b/frontend/src/locales/languages/en.json @@ -331,6 +331,16 @@ "hint": "Keep supervisor proposals as evidence until a human approves their application." }, "humanApprovalEnable": "Enable", + "agentApplyPolicy": { + "label": "Agent proposal policy", + "hint": "Auto-commit writes only to an isolated proposal branch; it never pushes or merges. Sensitive paths are always blocked." + }, + "agentApplyReview": "Require review", + "agentApplyCommit": "Auto-commit proposal branch", + "agentAllowedPaths": { + "label": "Allowed auto-commit paths", + "hint": "Comma-separated Git glob patterns. Every changed path must match; leave empty to disable auto-commit." + }, "name": "Name", "next": "Next" }, @@ -926,6 +936,17 @@ "workflowGraph": "Workflow graph", "noWorkflowGraph": "This task has no declared workflow to display.", "logs": "Logs", + "conversation": "Conversation", + "conversationDescription": "Review the public conversation between each Persona and its dedicated tool AI.", + "conversationDataHint": "Only Persona messages, tool-AI replies, and sanitized tool results are shown. Private prompts and hidden reasoning are excluded.", + "session": "Session", + "persona": "Persona", + "toolAi": "Tool AI", + "toolResult": "Tool result", + "showToolResult": "Show tool result", + "hideToolResult": "Hide tool result", + "noConversation": "No conversation recorded", + "noConversationHint": "A conversation appears after a Persona session emits public dialogue evidence.", "logsDescription": "View all execution output together in chronological order.", "logsDataHint": "Entries appear when Orbit writes process output or a runner sends target logs with ctx.target_log().", "orbitLogs": "Orbit logs", diff --git a/frontend/src/locales/languages/ja.json b/frontend/src/locales/languages/ja.json index 3cd2798..702b6e5 100644 --- a/frontend/src/locales/languages/ja.json +++ b/frontend/src/locales/languages/ja.json @@ -325,6 +325,16 @@ "hint": "監督者の提案は、人が適用を承認するまで証跡として保持します。" }, "humanApprovalEnable": "有効化", + "agentApplyPolicy": { + "label": "エージェント提案ポリシー", + "hint": "自動コミットは分離された提案ブランチにのみ記録され、push やマージは行いません。機密パスは常にブロックされます。" + }, + "agentApplyReview": "レビュー必須", + "agentApplyCommit": "提案ブランチを自動コミット", + "agentAllowedPaths": { + "label": "自動コミットの許可パス", + "hint": "カンマ区切りの Git glob パターンです。すべての変更パスが一致する必要があり、空欄の場合は自動コミットしません。" + }, "name": "名前", "next": "次へ" }, @@ -907,6 +917,17 @@ "workflowGraph": "ワークフローグラフ", "noWorkflowGraph": "このタスクには表示する宣言済みワークフローがありません。", "logs": "ログ", + "conversation": "会話", + "conversationDescription": "各ペルソナと専用ツールAIの公開会話を確認します。", + "conversationDataHint": "ペルソナの発話、ツールAIの応答、サニタイズ済みのツール結果のみを表示します。非公開プロンプトと内部推論は除外されます。", + "session": "セッション", + "persona": "ペルソナ", + "toolAi": "ツールAI", + "toolResult": "ツール結果", + "showToolResult": "ツール結果を表示", + "hideToolResult": "ツール結果を隠す", + "noConversation": "記録された会話はありません", + "noConversationHint": "ペルソナセッションが公開会話の証拠を出力すると、ここに表示されます。", "logsDescription": "すべての実行出力を時系列でまとめて確認します。", "logsDataHint": "Orbit がプロセス出力を残すか、ランナーが ctx.target_log() で対象ログを送信すると表示されます。", "orbitLogs": "Orbit ログ", diff --git a/frontend/src/locales/languages/ko.json b/frontend/src/locales/languages/ko.json index ccc6817..3e63bc8 100644 --- a/frontend/src/locales/languages/ko.json +++ b/frontend/src/locales/languages/ko.json @@ -330,6 +330,16 @@ "hint": "감독자 제안은 사람이 적용을 승인할 때까지 증거로만 보존합니다." }, "humanApprovalEnable": "유효화", + "agentApplyPolicy": { + "label": "에이전트 제안 정책", + "hint": "자동 커밋은 격리된 제안 브랜치에만 기록하며 push나 병합은 하지 않습니다. 민감한 경로는 항상 차단됩니다." + }, + "agentApplyReview": "검토 필요", + "agentApplyCommit": "제안 브랜치 자동 커밋", + "agentAllowedPaths": { + "label": "자동 커밋 허용 경로", + "hint": "쉼표로 구분한 Git glob 패턴입니다. 모든 변경 경로가 일치해야 하며, 비워 두면 자동 커밋을 하지 않습니다." + }, "name": "이름", "next": "다음" }, @@ -952,6 +962,17 @@ "workflowGraph": "워크플로우 그래프", "noWorkflowGraph": "이 작업에는 표시할 워크플로우가 선언되어 있지 않습니다.", "logs": "로그", + "conversation": "대화", + "conversationDescription": "각 페르소나와 전용 도구 AI 사이에 공개된 대화를 확인합니다.", + "conversationDataHint": "페르소나 발화, 도구 AI 응답, 정제된 도구 결과만 표시합니다. 비공개 프롬프트와 내부 추론은 제외됩니다.", + "session": "세션", + "persona": "페르소나", + "toolAi": "도구 AI", + "toolResult": "도구 결과", + "showToolResult": "도구 결과 보기", + "hideToolResult": "도구 결과 숨기기", + "noConversation": "기록된 대화가 없습니다", + "noConversationHint": "페르소나 세션이 공개 대화 증거를 남기면 여기에 표시됩니다.", "logsDescription": "전체 실행 출력을 시간순으로 한 번에 확인합니다.", "logsDataHint": "Orbit 프로세스가 출력을 남기거나 러너가 ctx.target_log()로 대상 로그를 전송하면 표시됩니다.", "orbitLogs": "Orbit 로그", diff --git a/frontend/src/theme-overrides.css b/frontend/src/theme-overrides.css index d3fb3c6..25869bf 100644 --- a/frontend/src/theme-overrides.css +++ b/frontend/src/theme-overrides.css @@ -186,6 +186,7 @@ select option[value="docker"] { display:none; } .build-runner-workflow { display:grid; gap:8px; }.build-runner-workflow > strong { font-size:12px; }.build-runner-workflow > p,.build-runner-workflow .hint { margin:0; color:var(--muted); font-size:12px; line-height:1.6; }.build-runner-workflow .workflow-graph { height:300px; } .quick-start-card { cursor:default; }.quick-start-card__select { display:grid; grid-template-columns:auto minmax(0,1fr); align-items:start; gap:12px; width:100%; border:0; padding:0; color:inherit; text-align:left; background:transparent; cursor:pointer; }.quick-start-card__select > svg:last-child { display:none; }.template-translation-action { margin-left:auto; display:grid; justify-items:end; gap:4px; }.template-translation-action .hint { margin:0; max-width:220px; } .run-detail-tab-panel { display:grid; min-width:0; gap:14px; padding-top:14px; }.run-detail-tab-panel__description { margin:0; color:var(--muted); font-size:11px; line-height:1.5; }.run-detail-tab-panel__intro { display:flex; align-items:center; justify-content:space-between; gap:12px; }.run-detail-tab-panel__intro .iteration-navigator { flex:none; min-height:30px; padding:0; border:0; }.iteration-candidates { display:flex; justify-content:flex-end; flex-wrap:wrap; gap:6px; padding:8px 0; border-bottom:1px solid var(--line); }.iteration-candidates button { display:flex; align-items:center; gap:6px; padding:4px 7px; border:1px solid var(--line); border-radius:999px; color:var(--muted); background:transparent; font:10px 'DM Mono',monospace; cursor:pointer; }.iteration-candidates button.selected { border-color:color-mix(in srgb,var(--accent) 45%,var(--line)); color:var(--accent); background:color-mix(in srgb,var(--accent) 9%,var(--bg)); }.iteration-candidates small { font:inherit; }.iteration-candidates em { font-style:normal; } .run-detail-tab-panel .combined-log-output { width:100%; max-width:100%; min-width:0; }.run-detail-tab-panel .combined-log-output > section { min-width:0; } .tooltip-box { display:grid; grid-template-columns:auto minmax(0,1fr); align-items:start; gap:8px; padding:10px 12px; border:1px solid color-mix(in srgb,var(--accent) 40%,var(--line)); border-radius:8px; color:var(--text); background:color-mix(in srgb,var(--accent) 14%,var(--surface-raised)); font-size:11px; line-height:1.55; }.tooltip-box > svg { margin-top:1px; color:var(--accent); }.tooltip-box > span { min-width:0; } @media(max-width:520px){.run-detail-tab-panel__intro { align-items:flex-start; flex-direction:column; }} +.conversation-panel { display:grid; grid-template-columns:140px minmax(0,1fr); gap:12px; min-height:260px; }.conversation-sessions { display:grid; align-content:start; gap:6px; }.conversation-sessions button { display:grid; gap:3px; width:100%; padding:9px; border:1px solid var(--line); border-radius:7px; color:var(--muted); background:transparent; text-align:left; cursor:pointer; }.conversation-sessions button.selected { border-color:color-mix(in srgb,var(--accent) 50%,var(--line)); color:var(--text); background:color-mix(in srgb,var(--accent) 8%,var(--bg)); }.conversation-sessions strong { overflow:hidden; font-size:11px; text-overflow:ellipsis; white-space:nowrap; }.conversation-sessions small,.conversation-message > small { color:var(--muted); font:9px 'DM Mono',monospace; text-transform:uppercase; }.conversation-transcript { display:grid; align-content:start; gap:9px; margin:0; padding:0; list-style:none; }.conversation-message { display:grid; gap:5px; max-width:88%; padding:10px 12px; border:1px solid var(--line); border-radius:9px; background:var(--surface-raised); }.conversation-message header { display:flex; align-items:center; justify-content:space-between; gap:12px; }.conversation-message header time { color:var(--muted); font:9px 'DM Mono',monospace; white-space:nowrap; }.conversation-message p { margin:0; white-space:pre-wrap; font-size:12px; line-height:1.55; }.conversation-message--persona { justify-self:start; border-left:3px solid var(--accent); }.conversation-message--assistant { justify-self:end; background:var(--bg); }.conversation-message--tool { max-width:100%; background:color-mix(in srgb,var(--surface-raised) 72%,var(--bg)); }.conversation-message details summary { color:var(--muted); font-size:11px; cursor:pointer; }.conversation-message details[open] summary { margin-bottom:8px; }.conversation-message pre { max-height:160px; margin:0; overflow:auto; padding:8px; border-radius:6px; background:var(--bg); color:var(--muted); font:10px/1.5 'DM Mono',monospace; white-space:pre-wrap; }.conversation-message .icon-button { margin-top:2px; }.conversation-empty { display:grid; gap:5px; min-height:160px; place-content:center; padding:20px; border:1px dashed var(--line); border-radius:8px; text-align:center; }.conversation-empty strong { font-size:12px; }.conversation-empty p { margin:0; color:var(--muted); font-size:11px; line-height:1.5; } @media(max-width:620px){.conversation-panel { grid-template-columns:1fr; }.conversation-sessions { grid-template-columns:repeat(auto-fit,minmax(120px,1fr)); }.conversation-message { max-width:100%; }} .browser-evidence { display:grid; gap:6px; margin:10px 0; padding:10px; border:1px solid var(--line); border-radius:8px; background:var(--surface-raised); font-size:12px; }.browser-evidence > small,.browser-evidence div small { overflow-wrap:anywhere; color:var(--muted); }.browser-evidence div { display:grid; gap:3px; padding-top:7px; border-top:1px solid var(--line); }.browser-evidence b { width:max-content; padding:2px 6px; border-radius:999px; font-size:10px; }.browser-evidence__pass { color:#bdecc8; background:#1e4832; }.browser-evidence__fail { color:#ffc0b7; background:#4b2925; } .run-build__name { display:flex; align-items:center; gap:5px; min-width:0; }.run-build .run-build__orphan { display:inline-flex; flex:none; width:14px; height:14px; padding:0; color:var(--danger); }.run-build__orphan svg { display:block; flex:none; width:14px; height:14px; }.run-build code { overflow:hidden; color:#839088; text-overflow:ellipsis; white-space:nowrap; font:9px 'DM Mono',monospace; }.table .tr > span { min-width:0; overflow:visible; text-overflow:clip; white-space:normal; overflow-wrap:anywhere; word-break:break-word; line-height:1.35; font-size:clamp(9px,.76vw,11px); }.table .tr.th > span { font-size:clamp(8px,.7vw,10px); line-height:1.25; } .workflow-graph { height:378px; min-height:243px; border:1px solid var(--line); border-radius:10px; overflow:hidden; background:var(--surface); }.workflow-graph-node { position:relative; width:250px; border:1px solid var(--line); border-radius:8px; background:var(--surface-raised); color:var(--text); box-shadow:0 8px 22px rgb(0 0 0 / .18); }.workflow-graph .react-flow__handle { pointer-events:none; opacity:0; }.workflow-graph-node header,.workflow-graph-node footer { display:grid; gap:4px; padding:10px; }.workflow-graph-node header { border-bottom:1px solid var(--line); }.workflow-graph-node small { color:var(--muted); font:9px 'DM Mono',monospace; text-transform:uppercase; }.workflow-graph-node strong { font-size:12px; }.workflow-graph-node p { margin:0; padding:10px; color:var(--muted); font-size:11px; }.workflow-graph-node footer { grid-template-columns:1fr 1fr; color:var(--muted); font-size:10px; }.workflow-graph-node--idle { border-color:color-mix(in srgb,var(--line) 72%,var(--bg)); background:color-mix(in srgb,var(--surface-raised) 52%,var(--bg)); color:var(--muted); box-shadow:none; }.workflow-graph-node--running { border-color:var(--accent); box-shadow:0 0 0 1px color-mix(in srgb,var(--accent) 38%,transparent),0 0 20px color-mix(in srgb,var(--accent) 42%,transparent); animation:workflow-node-pulse 1.8s ease-in-out infinite; }.workflow-graph-node--running::after { content:""; position:absolute; top:0; left:0; width:18px; height:3px; border-radius:999px; pointer-events:none; background:var(--accent); box-shadow:0 0 7px 2px color-mix(in srgb,var(--accent) 82%,transparent),0 0 16px 3px color-mix(in srgb,var(--accent) 42%,transparent); offset-path:inset(-2px round 9px); offset-anchor:center; offset-rotate:0deg; animation:workflow-border-orbit 2.4s linear infinite; }.workflow-graph-node--failed { border-color:#eaa89f; }.workflow-graph-node--succeeded { border-color:#79c99e; }.workflow-graph-edge--condition .react-flow__edge-path { stroke:#f1d292; stroke-dasharray:5 4; }.workflow-graph-edge--loop .react-flow__edge-path { stroke:#8fb8ff; stroke-dasharray:6 4; }.workflow-graph-edge--error .react-flow__edge-path { stroke:#eaa89f; } @keyframes workflow-node-pulse { 50% { box-shadow:0 0 0 4px color-mix(in srgb,var(--accent) 10%,transparent),0 0 30px color-mix(in srgb,var(--accent) 56%,transparent); } } @keyframes workflow-border-orbit { to { offset-distance:100%; } } @media(prefers-reduced-motion:reduce) { .workflow-graph-node--running,.workflow-graph-node--running::after { animation:none; } } diff --git a/templates/runner-templates/autonomous-persona-journey/README.md b/templates/runner-templates/autonomous-persona-journey/README.md index ede9115..23fc5ec 100644 --- a/templates/runner-templates/autonomous-persona-journey/README.md +++ b/templates/runner-templates/autonomous-persona-journey/README.md @@ -1,9 +1,11 @@ # Autonomous persona journey Runs a persistent product persona through one safe, rendered browser action per -iteration. The persona observes visible same-origin links, chooses one bounded -action through the configured model, and retains evidence, learnings, -deduplicated issues, and the next intent. +iteration. One model turn produces a structured first-person message, stated +perspective, rationale, and intent. A separate action-planning turn receives +only that message plus rendered safe actions, then chooses one bounded action. +The retained history carries those messages into later turns along with +evidence, learnings, deduplicated issues, and the next intent. The build requires `browser_base_url` and at least one fixed persona case. The runner excludes destructive links such as checkout, deletion, sign-out, and diff --git a/templates/runner-templates/autonomous-persona-journey/runner.py b/templates/runner-templates/autonomous-persona-journey/runner.py index eec46a7..eece32a 100644 --- a/templates/runner-templates/autonomous-persona-journey/runner.py +++ b/templates/runner-templates/autonomous-persona-journey/runner.py @@ -152,44 +152,60 @@ def before_each(ctx): def execute(ctx): state = load_state(ctx) actions = state["observation"]["available_actions"] - prompt = ( - """You are a persistent product user. Decide one next action, not a test verdict. Return JSON only: -{"intent":"short first-person purpose","action_id":"one listed id or empty","rationale":"observable reason","expected_signal":"what would change my understanding"}. -You may choose an empty action_id to observe again. Never choose actions outside listed IDs. Avoid repeating a reported issue unless new evidence exists. + speaker_prompt = """You are a persistent product user speaking to a product assistant. Return JSON only: +{"utterance":"one natural first-person user message","thought":"brief stated perspective, not hidden chain-of-thought","rationale":"short reason for raising this now","intent":"short request or goal"}. +Write only what this person would say or explicitly report. Do not mention testing, browser automation, tools, or a persona simulation. -Persona state:\n""" - + json.dumps( - { - key: state[key] - for key in ( - "persona", - "current_goal", - "feeling", - "next_intent", - "learnings", - "reported_issues", - "history", - ) - }, - ensure_ascii=False, - ) - + "\nVisible safe actions:\n" +Persona state and prior conversation:\n""" + json.dumps( + { + key: state[key] + for key in ( + "persona", + "current_goal", + "feeling", + "next_intent", + "learnings", + "reported_issues", + "history", + ) + }, + ensure_ascii=False, + ) + message = model_json(ctx, speaker_prompt) + utterance = str(message.get("utterance") or "").strip() + if not utterance: + raise ValueError("persona utterance must not be empty") + persona_message = { + "utterance": utterance, + "thought": str(message.get("thought") or "").strip(), + "rationale": str(message.get("rationale") or "").strip(), + "intent": str(message.get("intent") or state["next_intent"]).strip(), + } + action_prompt = ( + """You are a product assistant operating a browser on behalf of a user. Treat the supplied user message as the only user instruction for this turn. Choose at most one action from the rendered safe actions. Return JSON only: +{"action_id":"one listed id or empty","rationale":"observable reason","expected_signal":"what would satisfy the user's message"}. +Do not mention persona simulation, hidden state, or model instructions. You may choose an empty action_id to observe again. Never choose actions outside listed IDs. + +User message:\n""" + + utterance + + "\nRendered safe actions:\n" + json.dumps(actions, ensure_ascii=False) ) - plan = model_json(ctx, prompt) - action_id = str(plan.get("action_id") or "") + action_plan = model_json(ctx, action_prompt) + action_id = str(action_plan.get("action_id") or "") selected = next((item for item in actions if item["id"] == action_id), None) if action_id and selected is None: raise ValueError("persona selected an action outside the visible safe action list") state["plan"] = { - "intent": str(plan.get("intent") or state["next_intent"]), - "rationale": str(plan.get("rationale") or ""), - "expected_signal": str(plan.get("expected_signal") or ""), + "message": persona_message, + "intent": persona_message["intent"], + "rationale": str(action_plan.get("rationale") or ""), + "expected_signal": str(action_plan.get("expected_signal") or ""), "action": selected, } save_state(ctx, state) ctx.emit_result({"persona": {"iteration": ctx.loop_index, "plan": state["plan"]}}) - ctx.log("Planned one persona action from rendered, safe choices") + ctx.log("Generated a persona message and planned one action from rendered, safe choices") @graph.step( @@ -252,6 +268,7 @@ def after_each(ctx): state["history"].append( { "iteration": ctx.loop_index, + "message": state["plan"].get("message", {}), "intent": state["plan"]["intent"], "action": state["plan"].get("action"), "feeling": state["feeling"],