diff --git a/docs/openapi.json b/docs/openapi.json index 44607ecb..15272f53 100644 --- a/docs/openapi.json +++ b/docs/openapi.json @@ -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" ], @@ -37880,6 +37880,12 @@ "cleanup_pending": { "type": "boolean" }, + "declared_origins": { + "items": { + "type": "string" + }, + "type": "array" + }, "document_epoch": { "format": "int64", "type": "integer" diff --git a/docs/reviews/browser-live-view-origins/README.md b/docs/reviews/browser-live-view-origins/README.md new file mode 100644 index 00000000..7f59bbee --- /dev/null +++ b/docs/reviews/browser-live-view-origins/README.md @@ -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。 diff --git a/internal/httpapi/agent_browser.go b/internal/httpapi/agent_browser.go index e8765f10..af3ae627 100644 --- a/internal/httpapi/agent_browser.go +++ b/internal/httpapi/agent_browser.go @@ -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 { @@ -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 diff --git a/internal/httpapi/agent_browser_test.go b/internal/httpapi/agent_browser_test.go index fe3d5430..a9f5fce4 100644 --- a/internal/httpapi/agent_browser_test.go +++ b/internal/httpapi/agent_browser_test.go @@ -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) + } +} diff --git a/internal/httpapi/openapi.go b/internal/httpapi/openapi.go index 68fbd4f2..f19de058 100644 --- a/internal/httpapi/openapi.go +++ b/internal/httpapi/openapi.go @@ -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, diff --git a/output/playwright/pr542-origin-label/README.md b/output/playwright/pr542-origin-label/README.md new file mode 100644 index 00000000..453cc8cb --- /dev/null +++ b/output/playwright/pr542-origin-label/README.md @@ -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. diff --git a/output/playwright/pr542-origin-label/after-desktop-card.png b/output/playwright/pr542-origin-label/after-desktop-card.png new file mode 100644 index 00000000..d44472f7 Binary files /dev/null and b/output/playwright/pr542-origin-label/after-desktop-card.png differ diff --git a/output/playwright/pr542-origin-label/after-desktop-dark-card.png b/output/playwright/pr542-origin-label/after-desktop-dark-card.png new file mode 100644 index 00000000..bc777546 Binary files /dev/null and b/output/playwright/pr542-origin-label/after-desktop-dark-card.png differ diff --git a/output/playwright/pr542-origin-label/after-desktop-dark-viewport.png b/output/playwright/pr542-origin-label/after-desktop-dark-viewport.png new file mode 100644 index 00000000..e1624314 Binary files /dev/null and b/output/playwright/pr542-origin-label/after-desktop-dark-viewport.png differ diff --git a/output/playwright/pr542-origin-label/after-desktop-english-card.png b/output/playwright/pr542-origin-label/after-desktop-english-card.png new file mode 100644 index 00000000..d53217c6 Binary files /dev/null and b/output/playwright/pr542-origin-label/after-desktop-english-card.png differ diff --git a/output/playwright/pr542-origin-label/after-desktop-english-viewport.png b/output/playwright/pr542-origin-label/after-desktop-english-viewport.png new file mode 100644 index 00000000..35fd5931 Binary files /dev/null and b/output/playwright/pr542-origin-label/after-desktop-english-viewport.png differ diff --git a/output/playwright/pr542-origin-label/after-desktop-viewport.png b/output/playwright/pr542-origin-label/after-desktop-viewport.png new file mode 100644 index 00000000..dc3aabcc Binary files /dev/null and b/output/playwright/pr542-origin-label/after-desktop-viewport.png differ diff --git a/output/playwright/pr542-origin-label/after-narrow-long-origins-card.png b/output/playwright/pr542-origin-label/after-narrow-long-origins-card.png new file mode 100644 index 00000000..72b523be Binary files /dev/null and b/output/playwright/pr542-origin-label/after-narrow-long-origins-card.png differ diff --git a/output/playwright/pr542-origin-label/after-narrow-long-origins-viewport.png b/output/playwright/pr542-origin-label/after-narrow-long-origins-viewport.png new file mode 100644 index 00000000..099ac051 Binary files /dev/null and b/output/playwright/pr542-origin-label/after-narrow-long-origins-viewport.png differ diff --git a/output/playwright/pr542-origin-label/base-desktop-card.png b/output/playwright/pr542-origin-label/base-desktop-card.png new file mode 100644 index 00000000..f43c4274 Binary files /dev/null and b/output/playwright/pr542-origin-label/base-desktop-card.png differ diff --git a/output/playwright/pr542-origin-label/base-desktop-viewport.png b/output/playwright/pr542-origin-label/base-desktop-viewport.png new file mode 100644 index 00000000..b3850540 Binary files /dev/null and b/output/playwright/pr542-origin-label/base-desktop-viewport.png differ diff --git a/output/playwright/pr542-origin-label/base-narrow-long-origins-card.png b/output/playwright/pr542-origin-label/base-narrow-long-origins-card.png new file mode 100644 index 00000000..cd2cda14 Binary files /dev/null and b/output/playwright/pr542-origin-label/base-narrow-long-origins-card.png differ diff --git a/output/playwright/pr542-origin-label/base-narrow-long-origins-viewport.png b/output/playwright/pr542-origin-label/base-narrow-long-origins-viewport.png new file mode 100644 index 00000000..a41e785e Binary files /dev/null and b/output/playwright/pr542-origin-label/base-narrow-long-origins-viewport.png differ diff --git a/output/playwright/pr542-origin-label/capture-stage.js b/output/playwright/pr542-origin-label/capture-stage.js new file mode 100644 index 00000000..14bc863d --- /dev/null +++ b/output/playwright/pr542-origin-label/capture-stage.js @@ -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; +} + diff --git a/output/playwright/pr542-origin-label/current-desktop-card.png b/output/playwright/pr542-origin-label/current-desktop-card.png new file mode 100644 index 00000000..89b212cb Binary files /dev/null and b/output/playwright/pr542-origin-label/current-desktop-card.png differ diff --git a/output/playwright/pr542-origin-label/current-desktop-viewport.png b/output/playwright/pr542-origin-label/current-desktop-viewport.png new file mode 100644 index 00000000..d9abb944 Binary files /dev/null and b/output/playwright/pr542-origin-label/current-desktop-viewport.png differ diff --git a/output/playwright/pr542-origin-label/current-narrow-long-origins-card.png b/output/playwright/pr542-origin-label/current-narrow-long-origins-card.png new file mode 100644 index 00000000..25cce142 Binary files /dev/null and b/output/playwright/pr542-origin-label/current-narrow-long-origins-card.png differ diff --git a/output/playwright/pr542-origin-label/current-narrow-long-origins-viewport.png b/output/playwright/pr542-origin-label/current-narrow-long-origins-viewport.png new file mode 100644 index 00000000..eb4b113f Binary files /dev/null and b/output/playwright/pr542-origin-label/current-narrow-long-origins-viewport.png differ diff --git a/output/playwright/pr542-origin-label/metrics.json b/output/playwright/pr542-origin-label/metrics.json new file mode 100644 index 00000000..96a54a54 --- /dev/null +++ b/output/playwright/pr542-origin-label/metrics.json @@ -0,0 +1,431 @@ +{ + "captured_at_utc": "2026-11-06T12:16:58.797Z", + "environment": "Windows 10; Microsoft Edge 156.0.0.0; device scale 1; Vite 8.3.5", + "source": { + "base": "bab65dca83986f105b16e45e59dfb6676ec16b33", + "current": "d4f12cd7c08519aeeb7b269847266c155fd246ce", + "after": "3bb1837a0aee62e18366e0ca815d4c5c67a0494d" + }, + "component_blobs": { + "base": "9fb98f7389f382573dedad711b20773324a63f2d", + "current": "11ebb24c9b7f2286f2cd9687174042d03d24d2d8", + "after": "af446f5e8760206d871b5c082f3cfbd00731fe70" + }, + "fixture": "Production V2AgentBrowser with fixture API client; ready headed status; no backend execution, screenshots or live frames", + "verification": { + "node": "24.22.1", + "component_test": "25 passed", + "typecheck": "passed", + "diff_check": "passed" + }, + "captures": [ + { + "phase": "base", + "size": "desktop", + "theme": "light", + "locale": "zh-CN", + "viewport": { + "width": 1024, + "height": 600 + }, + "document": { + "width": 1024, + "height": 600, + "scrollWidth": 1024, + "scrollHeight": 600 + }, + "card": { + "width": 736, + "height": 150, + "scrollWidth": 736, + "scrollHeight": 150 + }, + "body": { + "width": 736, + "height": 110, + "scrollWidth": 736, + "scrollHeight": 110 + }, + "note": "需要结束网页操作时可停止浏览器;整个任务可在对话中停止。", + "noteDimensions": { + "width": 704, + "height": 20, + "scrollWidth": 704, + "scrollHeight": 20 + }, + "controls": [ + { + "label": "关闭浏览器提示", + "x": 834, + "right": 864, + "top": 41, + "bottom": 71 + }, + { + "label": "停止浏览器", + "x": 739, + "right": 826, + "top": 41, + "bottom": 71 + } + ] + }, + { + "phase": "base", + "size": "narrow-long-origins", + "theme": "light", + "locale": "zh-CN", + "viewport": { + "width": 390, + "height": 800 + }, + "document": { + "width": 390, + "height": 800, + "scrollWidth": 390, + "scrollHeight": 800 + }, + "card": { + "width": 356, + "height": 170, + "scrollWidth": 356, + "scrollHeight": 170 + }, + "body": { + "width": 356, + "height": 130, + "scrollWidth": 356, + "scrollHeight": 130 + }, + "note": "需要结束网页操作时可停止浏览器;整个任务可在对话中停止。", + "noteDimensions": { + "width": 324, + "height": 39, + "scrollWidth": 324, + "scrollHeight": 39 + }, + "controls": [ + { + "label": "关闭浏览器提示", + "x": 327, + "right": 357, + "top": 41, + "bottom": 71 + }, + { + "label": "停止浏览器", + "x": 232, + "right": 319, + "top": 41, + "bottom": 71 + } + ] + }, + { + "phase": "current", + "size": "desktop", + "theme": "light", + "locale": "zh-CN", + "viewport": { + "width": 1024, + "height": 600 + }, + "document": { + "width": 1024, + "height": 600, + "scrollWidth": 1024, + "scrollHeight": 600 + }, + "card": { + "width": 736, + "height": 178, + "scrollWidth": 736, + "scrollHeight": 178 + }, + "body": { + "width": 736, + "height": 138, + "scrollWidth": 736, + "scrollHeight": 138 + }, + "note": "本会话的浏览器仅在操作者声明的来源内工作:https://example.org:443, http://localhost:3000", + "noteDimensions": { + "width": 704, + "height": 20, + "scrollWidth": 704, + "scrollHeight": 20 + }, + "controls": [ + { + "label": "关闭浏览器提示", + "x": 834, + "right": 864, + "top": 41, + "bottom": 71 + }, + { + "label": "停止浏览器", + "x": 739, + "right": 826, + "top": 41, + "bottom": 71 + } + ] + }, + { + "phase": "current", + "size": "narrow-long-origins", + "theme": "light", + "locale": "zh-CN", + "viewport": { + "width": 390, + "height": 800 + }, + "document": { + "width": 390, + "height": 800, + "scrollWidth": 390, + "scrollHeight": 800 + }, + "card": { + "width": 356, + "height": 295, + "scrollWidth": 356, + "scrollHeight": 295 + }, + "body": { + "width": 356, + "height": 255, + "scrollWidth": 356, + "scrollHeight": 255 + }, + "note": "本会话的浏览器仅在操作者声明的来源内工作:https://browser-review.preview.customer-development.example.com:8443, https://identity-provider.integration.team-workspace.example.org:9443, https://documentation.release-candidate.platform-engineering.example.net:8443", + "noteDimensions": { + "width": 324, + "height": 117, + "scrollWidth": 324, + "scrollHeight": 117 + }, + "controls": [ + { + "label": "关闭浏览器提示", + "x": 327, + "right": 357, + "top": 41, + "bottom": 71 + }, + { + "label": "停止浏览器", + "x": 232, + "right": 319, + "top": 41, + "bottom": 71 + } + ] + }, + { + "phase": "after", + "size": "desktop", + "theme": "light", + "locale": "zh-CN", + "viewport": { + "width": 1024, + "height": 600 + }, + "document": { + "width": 1024, + "height": 600, + "scrollWidth": 1024, + "scrollHeight": 600 + }, + "card": { + "width": 736, + "height": 178, + "scrollWidth": 736, + "scrollHeight": 178 + }, + "body": { + "width": 736, + "height": 138, + "scrollWidth": 736, + "scrollHeight": 138 + }, + "note": "已声明的导航来源:https://example.org:443, http://localhost:3000", + "noteDimensions": { + "width": 704, + "height": 20, + "scrollWidth": 704, + "scrollHeight": 20 + }, + "controls": [ + { + "label": "关闭浏览器提示", + "x": 834, + "right": 864, + "top": 41, + "bottom": 71 + }, + { + "label": "停止浏览器", + "x": 739, + "right": 826, + "top": 41, + "bottom": 71 + } + ] + }, + { + "phase": "after", + "size": "narrow-long-origins", + "theme": "light", + "locale": "zh-CN", + "viewport": { + "width": 390, + "height": 800 + }, + "document": { + "width": 390, + "height": 800, + "scrollWidth": 390, + "scrollHeight": 800 + }, + "card": { + "width": 356, + "height": 295, + "scrollWidth": 356, + "scrollHeight": 295 + }, + "body": { + "width": 356, + "height": 255, + "scrollWidth": 356, + "scrollHeight": 255 + }, + "note": "已声明的导航来源:https://browser-review.preview.customer-development.example.com:8443, https://identity-provider.integration.team-workspace.example.org:9443, https://documentation.release-candidate.platform-engineering.example.net:8443", + "noteDimensions": { + "width": 324, + "height": 117, + "scrollWidth": 324, + "scrollHeight": 117 + }, + "controls": [ + { + "label": "关闭浏览器提示", + "x": 327, + "right": 357, + "top": 41, + "bottom": 71 + }, + { + "label": "停止浏览器", + "x": 232, + "right": 319, + "top": 41, + "bottom": 71 + } + ] + }, + { + "phase": "after", + "size": "desktop-dark", + "theme": "dark", + "locale": "zh-CN", + "viewport": { + "width": 1024, + "height": 600 + }, + "document": { + "width": 1024, + "height": 600, + "scrollWidth": 1024, + "scrollHeight": 600 + }, + "card": { + "width": 736, + "height": 178, + "scrollWidth": 736, + "scrollHeight": 178 + }, + "body": { + "width": 736, + "height": 138, + "scrollWidth": 736, + "scrollHeight": 138 + }, + "note": "已声明的导航来源:https://example.org:443, http://localhost:3000", + "noteDimensions": { + "width": 704, + "height": 20, + "scrollWidth": 704, + "scrollHeight": 20 + }, + "controls": [ + { + "label": "关闭浏览器提示", + "x": 834, + "right": 864, + "top": 41, + "bottom": 71 + }, + { + "label": "停止浏览器", + "x": 739, + "right": 826, + "top": 41, + "bottom": 71 + } + ] + }, + { + "phase": "after", + "size": "desktop-english", + "theme": "light", + "locale": "en-US", + "viewport": { + "width": 1024, + "height": 600 + }, + "document": { + "width": 1024, + "height": 600, + "scrollWidth": 1024, + "scrollHeight": 600 + }, + "card": { + "width": 736, + "height": 178, + "scrollWidth": 736, + "scrollHeight": 178 + }, + "body": { + "width": 736, + "height": 138, + "scrollWidth": 736, + "scrollHeight": 138 + }, + "note": "Declared navigation origins: https://example.org:443, http://localhost:3000", + "noteDimensions": { + "width": 704, + "height": 20, + "scrollWidth": 704, + "scrollHeight": 20 + }, + "controls": [ + { + "label": "Dismiss browser notice", + "x": 834, + "right": 864, + "top": 41, + "bottom": 71 + }, + { + "label": "Stop browser", + "x": 728.265625, + "right": 826, + "top": 41, + "bottom": 71 + } + ] + } + ] +} \ No newline at end of file diff --git a/output/playwright/pr542-origin-label/pr542-browser-evidence.html b/output/playwright/pr542-origin-label/pr542-browser-evidence.html new file mode 100644 index 00000000..1013b66d --- /dev/null +++ b/output/playwright/pr542-origin-label/pr542-browser-evidence.html @@ -0,0 +1,2 @@ + +Agent browser component review fixture
diff --git a/output/playwright/pr542-origin-label/pr542-browser-evidence.tsx b/output/playwright/pr542-origin-label/pr542-browser-evidence.tsx new file mode 100644 index 00000000..1154e84e --- /dev/null +++ b/output/playwright/pr542-origin-label/pr542-browser-evidence.tsx @@ -0,0 +1,40 @@ +import { createRoot } from "react-dom/client"; +import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; +import { V2AgentBrowser } from "../src/v2/components/agent-browser"; +import { LocaleProvider } from "../src/lib/locale"; +import { initializePrayuAppearance } from "../src/lib/appearance"; +import type { APIClient } from "../src/api/client"; +import "../src/styles.css"; +import "../src/v2/styles.css"; + +const params = new URLSearchParams(location.search); +localStorage.setItem("prayu.locale.v1", params.get("locale") || "zh-CN"); +localStorage.setItem("prayu.theme", params.get("theme") || "light"); +initializePrayuAppearance(); + +const origins = params.has("long") ? [ + "https://browser-review.preview.customer-development.example.com:8443", + "https://identity-provider.integration.team-workspace.example.org:9443", + "https://documentation.release-candidate.platform-engineering.example.net:8443", +] : ["https://example.org:443", "http://localhost:3000"]; +const fixture = { + version: "agent_browser_status.v1", run_id: "run-browser", session_id: "agent-browser-one", generation: 1, + state: "ready", available: true, can_start: true, product: "edge", headless: false, + url: "https://example.org/report", title: "导航检查", document_epoch: 2, + last_action: "browser_navigate", updated_at: "2026-11-06T10:00:00Z", + cleanup_pending: false, tree_reaped: false, profile_removed: false, + declared_origins: origins, +}; +const client = { + baseURL: "/component-review-fixture", + get: async () => structuredClone(fixture), + postControl: async () => { throw new Error("This review fixture has no backend control endpoint"); }, +} as unknown as APIClient; + +document.body.style.cssText = "margin:0; min-height:100dvh; box-sizing:border-box; padding:32px 16px; background:var(--prayu-panel);"; +const queries = new QueryClient({ defaultOptions: { queries: { retry: false, refetchOnWindowFocus: false } } }); +createRoot(document.getElementById("root")!).render( + + + , +); diff --git a/output/playwright/pr542-origin-label/select-stage.mjs b/output/playwright/pr542-origin-label/select-stage.mjs new file mode 100644 index 00000000..c3f65240 --- /dev/null +++ b/output/playwright/pr542-origin-label/select-stage.mjs @@ -0,0 +1,12 @@ +import {readFileSync, writeFileSync} from "node:fs"; +import {execFileSync} from "node:child_process"; +const target = "web/src/v2/components/agent-browser.tsx"; +const phase = process.argv[2]; +const original = readFileSync("web/.tmp/agent-browser-original.tsx", "utf8"); +const next = phase === "base" ? execFileSync("git", ["show", `bab65dca83986f105b16e45e59dfb6676ec16b33:${target}`], {encoding:"utf8"}) + : phase === "after" ? original.replace("本会话的浏览器仅在操作者声明的来源内工作:", "已声明的导航来源:") + .replace("This session's browser operates only inside the operator-declared origins: ", "Declared navigation origins: ") + : phase === "current" ? original : null; +if (!next) throw new Error("Unknown phase"); +writeFileSync(target, next); +console.log(phase, execFileSync("git", ["hash-object", target], {encoding:"utf8"}).trim()); diff --git a/web/src/api/agent-browser.ts b/web/src/api/agent-browser.ts index b143994a..121e1cab 100644 --- a/web/src/api/agent-browser.ts +++ b/web/src/api/agent-browser.ts @@ -34,6 +34,7 @@ export interface AgentBrowserStatus { profile_removed: boolean; process_scope?: "no_owned_process_resources" | "darwin_group_and_scoped_children.v1"; process_scope_verified?: boolean; + declared_origins?: string[]; } const states = new Set(["unavailable", "idle", "starting", "ready", "loading", "busy", "waiting_user", "failed", "closing", "closed", "cleanup_pending"]); diff --git a/web/src/api/schema.d.ts b/web/src/api/schema.d.ts index 6382c797..435aca6e 100644 --- a/web/src/api/schema.d.ts +++ b/web/src/api/schema.d.ts @@ -1363,7 +1363,7 @@ export interface paths { }; /** * 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. */ get: operations["getRunAgentBrowser"]; put?: never; @@ -6556,6 +6556,7 @@ export interface components { available: boolean; can_start: boolean; cleanup_pending: boolean; + declared_origins?: string[]; /** Format: int64 */ document_epoch: number; failure_code?: string; diff --git a/web/src/v2/components/agent-browser.test.tsx b/web/src/v2/components/agent-browser.test.tsx index 196fb1e6..208c3acd 100644 --- a/web/src/v2/components/agent-browser.test.tsx +++ b/web/src/v2/components/agent-browser.test.tsx @@ -309,3 +309,31 @@ it("falls back to screenshots when the live stream is unavailable", async () => expect(await screen.findByText("实时画面暂不可用,已回退到截图。")).toBeInTheDocument(); expect(screen.getByRole("img", { name: "Agent 浏览器实时画面" })).not.toHaveClass("is-live"); }); + +it("shows the operator-declared origins for a scoped session", async () => { + const scoped = { ...status(), declared_origins: ["https://example.org:443", "http://localhost:3000"] }; + const get = vi.fn(async () => scoped); + const client = { baseURL: "/api/v1", get, postControl: vi.fn(), + downloadVerifiedImage: vi.fn(async () => new Blob(["png"], { type: "image/png" })) } as unknown as APIClient; + draw(client); + expect(await screen.findByText(/https:\/\/example\.org:443, http:\/\/localhost:3000/)).toBeInTheDocument(); + expect(screen.getByText(/^已声明的导航来源:/)).toBeInTheDocument(); +}); + +it("hides the origins note for unscoped and unavailable sessions", async () => { + const unscoped = status(); + delete (unscoped as Record).declared_origins; + const get = vi.fn(async () => unscoped); + const client = { baseURL: "/api/v1", get, postControl: vi.fn(), + downloadVerifiedImage: vi.fn(async () => new Blob(["png"], { type: "image/png" })) } as unknown as APIClient; + const first = draw(client); + await first.findByText("Report run-browser"); + expect(first.queryByText(/^已声明的导航来源:/)).not.toBeInTheDocument(); + first.unmount(); + + const down = { ...status(), available: false, state: "closed", session_id: undefined, screenshot: undefined }; + const second = draw({ baseURL: "/api/v1", get: vi.fn(async () => down), postControl: vi.fn(), + downloadVerifiedImage: vi.fn(async () => new Blob(["png"], { type: "image/png" })) } as unknown as APIClient); + await second.findByText("当前环境没有可用的 Agent 浏览器运行时,请检查本机浏览器和执行权限配置。"); + expect(second.queryByText(/^已声明的导航来源:/)).not.toBeInTheDocument(); +}); diff --git a/web/src/v2/components/agent-browser.tsx b/web/src/v2/components/agent-browser.tsx index 9fb98f73..af446f5e 100644 --- a/web/src/v2/components/agent-browser.tsx +++ b/web/src/v2/components/agent-browser.tsx @@ -107,6 +107,7 @@ function AgentBrowserCard({ client, runID, running, onDismiss }: { client: APICl
{!current.available &&

{unavailableText(current.unavailable_code, t)}

} {current.available && !active &&

{current.headless ? t("页面将在独立的后台浏览器中打开,通过实时画面和截图查看。", "Pages open in a separate background browser and are shown as a live view and screenshots.") : t("页面将在独立浏览器窗口中打开。", "Pages open in a separate browser window.")}

} + {current.available && current.declared_origins && current.declared_origins.length > 0 &&

{t("已声明的导航来源:", "Declared navigation origins: ")}{current.declared_origins.join(", ")}

} {current.headless && active && current.session_id && } {current.headless && active &&

{t("浏览器在后台运行,上方为实时画面;已验证的截图仍会作为证据保存。需要结束网页操作时可停止浏览器;整个任务可在对话中停止。", "The browser runs in the background with the live view above; verified screenshots are still kept as evidence. Stop the browser to end web actions, or stop the whole task in the conversation.")}

} {!current.headless && canClose &&

{t("需要结束网页操作时可停止浏览器;整个任务可在对话中停止。", "Stop the browser to end web actions, or stop the whole task in the conversation.")}

}