Commit Graph

20 Commits

Author SHA1 Message Date
yan5xu 690a8dc6e4 chore: add harness — tests, CI, protocol types, design invariants
Context layer:
- Rewrite AGENTS.md: new daemon architecture, 3-file command pattern,
  7 design invariants (INV-1 through INV-7), testing section
- Update protocol.ts: add tab/seq/cursor/since fields, update
  DaemonStatus, remove SSE types, widen TabInfo.tabId to string

Constraints layer:
- Unit tests: RingBuffer (14), TabState + TabStateManager (36)
- Contract tests: all 7 invariants verified (48)
- Protocol drift tests: real daemon HTTP response shape checks (13,
  skipped when Chrome unavailable)
- CI workflow: build + lint + test on push/PR to main
- Pre-commit hook: pnpm build && pnpm test via husky

GC layer:
- Harness scenarios doc: 6 reusable Agent workflow scenarios for
  periodic UX validation

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 11:59:14 +08:00
Yanwu 62af1f89d7 refactor: unify daemon — CDP direct, remove Extension dependency (#132)
Merge daemon + cdp-monitor into a single CDP-direct backend. All CLI
and MCP commands now route through the daemon HTTP API instead of
direct CDP connections or Extension relay.

Key changes:
- Daemon: rewrite to hold persistent CDP WebSocket, handle all 30+
  commands via dispatchRequest, per-tab event state with RingBuffer,
  short tab IDs (4-char hex), global seq counter, incremental queries
  via since/cursor mechanism
- CLI: all commands route through daemon HTTP, --tab accepts string
  short IDs, add --since/--method/--status flags for network queries,
  fix tab close with --tab flag, fix invalid tab ID silent fallback
- MCP: tab parameter z.number() → z.string(), add browser_console
  and browser_errors tools, add since/method/status/limit params to
  browser_network, remove Extension dependency hints
- Shared: export additional types for daemon consumption

Bug fixes from harness testing:
- Invalid tab ID now errors instead of silent fallback
- tab_new works with zero existing tabs
- console.warn() correctly captured as type "warn"
- --tab flag works with tab close command

Closes #131

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 11:02:48 +08:00
Ted Li 45c1fbb385 fix(shared): avoid global crypto for request ids (#89) 2026-03-22 14:36:05 +08:00
Waffle 0a2e150238 chore(lint): add small-scope eslint checks 2026-03-19 16:37:41 +08:00
yan5xu fdb8288ce2 feat: add history, site recommend, site info, --jq, and Agent UX guide
New commands:
- `history search/domains` — query Chrome browsing history via chrome.history API
- `site recommend` — cross-reference history with adapters for personalized discovery
- `site info <name>` — expose full adapter @meta (args, example, domain)
- `--jq <expr>` — inline jq-like JSON filtering (inspired by gh CLI)

Agent UX improvements:
- --help grouped by intent, "开始使用" section first with site examples
- --help top hint explicitly guides Agents to use site commands over browser automation
- `open` command shows 💡 hint when the URL has available site adapters
- `--jq` auto-strips `.data.` prefix for Agent tolerance
- `site update` post-install nudge for site recommend
- AGENTS.md with full UX writing spec for contributors

Closes #21, closes #23, relates #24

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-15 12:02:04 +08:00
yan5xu 537e5536f9 feat(mcp): add MCP server for AI agent integration
New package @bb-browser/mcp exposes all browser commands as MCP tools:
browser_snapshot, browser_click, browser_fill, browser_type, browser_open,
browser_tab_list, browser_tab_new, browser_press, browser_scroll,
browser_eval, browser_network, browser_screenshot, browser_get,
browser_close, browser_hover, browser_wait

All tools support `tab` parameter for concurrent multi-tab operations.
Uses stdio transport, connects to daemon via HTTP (same as CLI).

Also adds missing fields to shared protocol types:
- Request: key, modifiers, direction, pixels, waitType, ms
- ResponseData: dataUrl

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-14 21:59:22 +08:00
yan5xu a2e1f29daa feat: network requests --with-body captures full request/response data
Via CDP Network.loadingFinished + Network.getResponseBody, capture:
- Request headers and body (POST data)
- Response headers, body, and mimeType
- Memory management: 256KB/response, 64KB/request, 8MB/tab total
- Eviction: oldest bodies removed first when over budget
- Graceful error handling: bodyError field for failed captures

This enables a new paradigm for site adapters: instead of reverse-engineering
API signing (like Xiaohongshu's X-s), just navigate to a page and read the
response bodies from requests the page already made with proper authentication.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-14 20:44:22 +08:00
yan5xu e66256a138 feat: 切换 snapshot 到 CDP Accessibility Tree
- 新增 ax-tree-formatter.ts:将 CDP AXNode[] 格式化为语义化 accessibility 树文本
- cdp-dom-service.ts:getSnapshot 改用 Accessibility.getFullAXTree,元素操作改用 backendDOMNodeId
- 支持新参数:--compact/-c(移除空结构节点)、--depth/-d(限制树深度)、--selector/-s(CSS 范围)
- link 内联 /url:,heading 标记 [level=N],重复元素标记 [nth=N]
- GitHub 页面 snapshot 从 56KB 降到 31KB(-45%)

Closes #4

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-02-13 19:55:34 +08:00
yan5xu 1acfb6031b feat: tab select/close 支持按 tabId 操作
- 协议 Request 新增 tabId 字段(优先于 index,向下兼容)
- Extension handleTabSelect/handleTabClose 支持 tabId 直接定位
- CLI 新增 tab select --id <tabId> 和 tab close --id <tabId> 语法
- 解决多调用方共用时 index 重编号导致的 tab 错位问题
2026-02-06 09:35:33 +08:00
yan5xu 4c7c64f8ba fix: 解决 MV3 Service Worker 休眠导致连接断开的问题
- 添加 chrome.alarms 保活机制(每 24 秒唤醒)
- 使用 chrome.storage.session 持久化 refs(防止休眠后丢失)
- 心跳间隔从 30s 改为 15s
- 添加 storage 和 alarms 权限
2026-01-30 18:12:42 +08:00
yan5xu f02b081f48 feat: 添加 trace 命令 - 录制用户操作 2026-01-30 15:58:09 +08:00
yan5xu 02edcb4c85 feat: 添加 network/console/errors 调试命令
- network requests [filter]: 查看网络请求
- network route <url> [--abort|--body]: 拦截/mock 请求
- network unroute [url]: 移除拦截规则
- network clear: 清空请求记录
- console: 查看控制台消息(log/info/warn/error)
- console --clear: 清空控制台
- errors: 查看 JS 异常
- errors --clear: 清空错误记录

扩展通过 CDP Network/Fetch/Runtime/Log 域实现监控和拦截
2026-01-30 12:34:33 +08:00
yan5xu 0052ec5c31 merge: feat/dialogs - 添加 dialog 命令 2026-01-30 10:36:55 +08:00
yan5xu fb726aec3c merge: feat/frames - 添加 frame 命令 2026-01-30 10:32:37 +08:00
yan5xu 394d7e7dc3 feat: 添加 frame 命令(切换 iframe) 2026-01-30 10:28:48 +08:00
yan5xu 8d6e6c1d75 feat: 添加 dialog 命令(accept/dismiss) 2026-01-30 10:26:52 +08:00
yan5xu a608124f06 feat: 添加 tab 命令(list/new/select/close) 2026-01-30 10:26:31 +08:00
yan5xu bbfda3fc62 feat: 添加 Phase 3 命令 (eval/type/check/uncheck/select) 2026-01-30 10:02:53 +08:00
yan5xu 7e6bf96aba feat: 添加 eval 命令 - 执行 JavaScript 2026-01-30 09:58:22 +08:00
yan5xu 601f4ae813 feat: 实现 bb-browser 核心功能
- CLI: open, snapshot, click, fill, status, stop 命令
- Extension: buildDomTree 移植, DOM 服务, SSE 通信
- Daemon: HTTP SSE 架构, 请求管理
- Shared: 通信协议类型定义

snapshot 支持两种模式:
- 默认完整树模式 (含文本节点)
- -i 交互元素模式 (只含可交互元素)

已验证: 推特/Reddit 登录态页面访问正常
2026-01-29 21:17:28 +08:00