Skip to content
Merged
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
8 changes: 7 additions & 1 deletion docs/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -7328,7 +7328,7 @@
"get": {
"operationId": "getRunAgentBrowser",
"summary": "Read the Agent browser state",
"description": "Reads the Run's process-local Agent browser status without starting a browser or executing an action. Excludes runtime authority and profile/DevTools handles.",
"description": "Reads the Run's process-local Agent browser status without starting a browser or executing an action. Excludes runtime authority and profile/DevTools handles. Scoped sessions surface their operator-declared origins in declared_origins.",
"tags": [
"Runs"
],
Expand Down Expand Up @@ -37880,6 +37880,12 @@
"cleanup_pending": {
"type": "boolean"
},
"declared_origins": {
"items": {
"type": "string"
},
"type": "array"
},
"document_epoch": {
"format": "int64",
"type": "integer"
Expand Down
38 changes: 38 additions & 0 deletions docs/reviews/browser-live-view-origins/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Agent browser live view origins 投影(ADR 0195 Phase 4 尾片):OCR delegate 复审

日期:2026-11-06。基线:`39772941`(PR #541 分支,Phase 4 CLI slice)。
主题:Phase 4 尾片 "live view origin display"——`AgentBrowserStatusView` 投影
`Capabilities.DeclaredOrigins`(omitempty),openapi/schema.d.ts 再生成,live view
双语边界声明(available 且非空时显示,live view 画布之前);refusal 会话不显示
(无边界可言)。unscoped Full 会话字段隐藏(omitempty + 上游 nil)。

## 覆盖范围

6 文件:`internal/httpapi/agent_browser.go`(投影)、`openapi.go`(描述)、
`docs/openapi.json`、`web/src/api/schema.d.ts`(再生成)、
`web/src/v2/components/agent-browser.tsx`(显示)、`agent_browser_test.go`(投影
正反两分支测试)+ web 组件测试两条(正例渲染/不可用与无声明隐藏)。

## 发现与修复(评审子代理报告)

| 发现 | 具体问题 | 最终处理 |
| --- | --- | --- |
| P2 | web 组件测试缺失(仓库先例:UI 改动同步改测试;新增条件 note 的正例分支零覆盖)。 | 随片补两条 it():scoped 会话渲染双语边界声明 + origin 列表;unscoped 与 unavailable 会话 note 不存在(两次独立渲染规避 refetch 不触发)。 |
| P3 | `run show` 不回显声明的 origins。 | 记录为 Phase 4 一致性跟进(CLI 展示非本片必须;run.Config 已有规范集可直接打印)。 |
| P3 | refusal 文案未提示"可声明来源"的补救路径。 | 留待 Phase 3 origin-add 操作面落地时统一改写(避免提示尚无入口的动作)。 |

评审确认(可合,无阻塞):DeclaredOrigins 全仓写入点唯一收敛到
currentAuthority 的 scope 规范化构造(无不可信来源,透传成立、无需 redact/
重排/截断——与同函数 ProcessScope/LastAction 透传先例一致);unscoped 与
refusal 会话不投影(上游 nil + omitempty + 测试锚定);openapi 契约纯 additive
(process_scope 字段先例一致,无 registry/版本动作);web 显示条件三重收敛、
轮询 refetch 自然覆盖未来 Phase 3 的声明变更;golden 契约测试与 check:api
逐字节把关无手编 schema;desktop 走同一 HTTP 端点无需改动。

## 验证

- `go build ./...`、`go vet ./internal/httpapi/`;`go test ./internal/httpapi/
-count=1` 全绿(233s 全包)。
- `go run ./cmd/cyberagent api openapi --output docs/openapi.json` +
`npm run generate:api` + `npx tsc --noEmit` + `npm run check:api`(提交后
diff 为零)+ `npx vitest run agent-browser.test.tsx` 25/25。
7 changes: 7 additions & 0 deletions internal/httpapi/agent_browser.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ type AgentBrowserStatusView struct {
ProfileRemoved bool `json:"profile_removed"`
ProcessScope string `json:"process_scope,omitempty"`
ProcessScopeVerified bool `json:"process_scope_verified"`
// DeclaredOrigins surfaces the Run's operator-declared scoped-session
// boundary (ADR 0195) so the live view shows exactly where the browser may
// operate; absent for unscoped Full sessions.
DeclaredOrigins []string `json:"declared_origins,omitempty"`
}

type AgentBrowserCloseRequestView struct {
Expand Down Expand Up @@ -217,6 +221,9 @@ func publicAgentBrowserStatus(value application.AgentBrowserView, runID string)
view.UnavailableCode = value.Capabilities.UnavailableCode
}
}
if len(value.Capabilities.DeclaredOrigins) != 0 {
view.DeclaredOrigins = append([]string(nil), value.Capabilities.DeclaredOrigins...)
}
if value.Cleanup != nil {
view.CleanupPending = value.Cleanup.CleanupPending
view.TreeReaped = value.Cleanup.TreeReaped
Expand Down
27 changes: 27 additions & 0 deletions internal/httpapi/agent_browser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,3 +334,30 @@ func TestAgentBrowserDownloadListAndReleaseEndpoint(t *testing.T) {
t.Fatalf("release accepted a read token: %d", denied.Code)
}
}

func TestAgentBrowserStatusSurfacesDeclaredOrigins(t *testing.T) {
fixture := newAPIFixture(t)
stub := &agentBrowserHTTPStub{}
stub.view = application.AgentBrowserView{Version: "agent_browser_status.v1", RunID: fixture.run.ID,
State: "idle", Headless: true, UpdatedAt: time.Now().UTC(),
Capabilities: application.AgentBrowserCapabilities{Available: true, CanStart: true,
DeclaredOrigins: []string{"https://example.org:443", "http://localhost:3000"}}}
api, err := New(fixture.store, Config{AccessToken: testAccessToken, ControlToken: testControlToken, AgentBrowserController: stub})
if err != nil {
t.Fatal(err)
}
path := "/api/v1/runs/" + fixture.run.ID + "/agent-browser"
response := performRequest(t, api, http.MethodGet, path, testAccessToken, "127.0.0.1:8765", "127.0.0.1:45000", nil)
var view AgentBrowserStatusView
decodeDataStatus(t, response, http.StatusOK, &view)
if len(view.DeclaredOrigins) != 2 || view.DeclaredOrigins[0] != "https://example.org:443" {
t.Fatalf("declared origins not projected: %+v", view.DeclaredOrigins)
}
stub.view.Capabilities.DeclaredOrigins = nil
response = performRequest(t, api, http.MethodGet, path, testAccessToken, "127.0.0.1:8765", "127.0.0.1:45000", nil)
var unscoped AgentBrowserStatusView
decodeDataStatus(t, response, http.StatusOK, &unscoped)
if len(unscoped.DeclaredOrigins) != 0 {
t.Fatalf("unscoped session must omit declared origins: %+v", unscoped.DeclaredOrigins)
}
}
2 changes: 1 addition & 1 deletion internal/httpapi/openapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -1861,7 +1861,7 @@ func openAPIOperationSpecs() []openAPIOperationSpec {
}},
{Path: AgentBrowserStatusPathTemplate, Method: http.MethodGet,
OperationID: "getRunAgentBrowser", Summary: "Read the Agent browser state", Tag: "Runs",
Description: "Reads the Run's process-local Agent browser status without starting a browser or executing an action. Excludes runtime authority and profile/DevTools handles.",
Description: "Reads the Run's process-local Agent browser status without starting a browser or executing an action. Excludes runtime authority and profile/DevTools handles. Scoped sessions surface their operator-declared origins in declared_origins.",
DataType: reflect.TypeOf(AgentBrowserStatusView{}), NotFound: true, Parameters: []openAPIParameter{runID}},
{Path: AgentBrowserClosePathTemplate, Method: http.MethodPost,
OperationID: "closeRunAgentBrowser", Summary: "Stop one exact Agent browser session", Tag: "Control", Control: true,
Expand Down
37 changes: 37 additions & 0 deletions output/playwright/pr542-origin-label/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Browser navigation origin label review

These images show the production `V2AgentBrowser` React component and its production styles in Microsoft Edge, driven by a local API-client fixture. The fixture replaces the status API with a ready, headed browser status containing declared origins. It does not start a browser session, execute server actions, or supply screenshots or live frames. The surrounding page is a component review harness, not the full workbench.

| Stage | Source revision | Meaning |
| --- | --- | --- |
| `base` | `bab65dca83986f105b16e45e59dfb6676ec16b33` | #542 base; no origin note |
| `current` | `d4f12cd7c08519aeeb7b269847266c155fd246ce` | #542 original head; longer origin claim |
| `after` | `3bb1837a0aee62e18366e0ca815d4c5c67a0494d` | Concise navigation-origin label |

For the base capture, the production component file was loaded byte-for-byte from the base commit. The base and original head have identical rendered imports/styles; their other web differences are the companion type, schema, and tests. `metrics.json` records the component blobs and measured dimensions.

## Suggested PR images

Use `base-desktop-card.png` and `after-desktop-card.png` for the PR base-to-head comparison. Use `current-desktop-card.png` and `after-desktop-card.png` to review the wording refinement.

Use `current-narrow-long-origins-card.png` and `after-narrow-long-origins-card.png` for the 390px window with three long origins. The origins wrap without horizontal scrolling; both header controls and the latest-status footer remain visible.

`*-viewport.png` files are unaltered full-window captures (1024×600 desktop; 390×800 narrow). `*-card.png` files are unscaled element crops of the complete card at its native width (738px desktop; 358px narrow). Both comparison stages use light theme, Chinese locale, and device scale 1. `after-desktop-dark-*` and `after-desktop-english-*` are supplementary checks.

## Verification

On Windows with Node 24.22.1:

```powershell
npm test -- src/v2/components/agent-browser.test.tsx
npm run typecheck
git diff --check
```

The component test file passed all 25 tests; type checking and the whitespace check exited successfully. The existing jsdom canvas warning appeared during the live-view test. These screenshots establish the label/layout behavior for the supplied component status, and do not establish backend network enforcement.

## Reproduce the component capture

Copy `pr542-browser-evidence.html`, `pr542-browser-evidence.tsx`, `capture-stage.js`, and `select-stage.mjs` into `web/.tmp/`. Save the original `d4f12cd7` component as `web/.tmp/agent-browser-original.tsx`. Start Vite in `web` on loopback port 5420, then open the fixture URL with Playwright CLI in the `pr542` session.

For each `base`, `current`, and `after` stage, run `node web/.tmp/select-stage.mjs STAGE`, navigate to `http://127.0.0.1:5420/.tmp/pr542-browser-evidence.html?phase=STAGE`, then run `playwright-cli --session pr542 run-code --filename web/.tmp/capture-stage.js`. Restore `after` when finished. The capture checks the expected label, horizontal overflow, and header-control placement before returning measurements.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
46 changes: 46 additions & 0 deletions output/playwright/pr542-origin-label/capture-stage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
async (page) => {
const phase = new URL(page.url()).searchParams.get("phase") || "current";
const checks = [];
for (const [size, viewport, query] of [
["desktop", {width: 1024, height: 600}, ""],
["narrow-long-origins", {width: 390, height: 800}, "&long=1"],
...(phase === "after" ? [["desktop-dark", {width: 1024, height: 600}, "&theme=dark"],
["desktop-english", {width: 1024, height: 600}, "&locale=en-US"]] : []),
]) {
await page.setViewportSize(viewport);
await page.goto(`http://127.0.0.1:5420/.tmp/pr542-browser-evidence.html?phase=${phase}${query}`);
await page.getByRole("region", {name: /Agent 浏览器|Agent browser/, exact: true}).waitFor();
await page.evaluate(() => document.fonts.ready);
const expected = phase === "base" ? null : phase === "after"
? size === "desktop-english" ? "Declared navigation origins: " : "已声明的导航来源:"
: "本会话的浏览器仅在操作者声明的来源内工作:";
const note = page.locator(".v2-agent-browser-note").first();
if (expected && !(await note.textContent()).startsWith(expected)) throw new Error("Unexpected label at " + phase);
if (phase === "base" && (await page.locator(".v2-agent-browser").textContent()).includes("example.org:443")) throw new Error("Base unexpectedly includes origins");
const prefix = `output/playwright/pr542-origin-label/${phase}-${size}`;
await page.screenshot({path: prefix + "-viewport.png"});
await page.locator(".v2-agent-browser").screenshot({path: prefix + "-card.png"});
const metrics = await page.evaluate(() => {
const card = document.querySelector(".v2-agent-browser");
const body = document.querySelector(".v2-agent-browser-body");
const note = document.querySelector(".v2-agent-browser-note");
const dismiss = document.querySelector(".v2-agent-browser-dismiss");
const stop = Array.from(document.querySelectorAll("button")).find(el => /停止浏览器|Stop browser/.test(el.textContent));
const dimensions = el => ({width: el.clientWidth, height: el.clientHeight, scrollWidth: el.scrollWidth, scrollHeight: el.scrollHeight});
const controls = [dismiss, stop].map(el => {const rect = el.getBoundingClientRect(); return {label: el.getAttribute("aria-label") || el.textContent, x: rect.x, right: rect.right, top: rect.top, bottom: rect.bottom};});
return {theme: document.documentElement.dataset.prayuTheme, locale: document.documentElement.lang,
viewport: {width: innerWidth, height: innerHeight}, document: dimensions(document.documentElement), card: dimensions(card), body: dimensions(body),
note: note.textContent, noteDimensions: dimensions(note), controls};
});
if (metrics.document.scrollWidth > viewport.width || metrics.body.scrollWidth > metrics.body.width) throw new Error("Horizontal overflow at " + size);
if (metrics.controls.some(c => c.right > viewport.width || c.x < 0)) throw new Error("Control outside viewport at " + size);
if (size === "narrow-long-origins") {
await page.locator(".v2-agent-browser-body").evaluate(el => {el.scrollTop = el.scrollHeight;});
if (!(await page.getByText("最近状态", {exact:true}).isVisible())) throw new Error("Status footer unreachable");
await page.screenshot({path: prefix + "-scrolled-viewport.png"});
}
checks.push({phase, size, ...metrics});
}
return checks;
}

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading