Skip to content

feat(site): local site memory with agent-recorded reusable workflows | 站点记忆与 agent 自驱录制的可复用流程 - #260

Open
fish0710 wants to merge 1 commit into
Tencent:mainfrom
fish0710:feat/site-memory-pr
Open

fish0710 wants to merge 1 commit into
Tencent:mainfrom
fish0710:feat/site-memory-pr

Conversation

@fish0710

Copy link
Copy Markdown

背景

BrowserSkill 已经有 bsk record 产出的 TraceV3 录制工件,但没有任何消费者:一次探索出来的流程下次仍要从头探索。本 PR 借鉴 webcmd 的"站点记忆纪律"(受约束的 SITE.md、草稿隔离、revision 比较交换、证据分级),用纯 CLI 在 ~/.bsk/sites/ 下实现本机私有的站点记忆,并让 agent 自己执行任务时顺手录制,不再依赖人工演示。

不移植 webcmd 的 JS 适配器、插件、pipeline、cookie/intercept 策略与云端 seed。

改动

bsk site 命令族(不需要 daemon)

  • site context / site checkpoint:SITE.md 每条事实必须带 [verified YYYY-MM-DD],行数预算与 references/ 指针;每个任务一份草稿;per-host revision 比较交换,conflict 时重跑 context 会用已发布版本重新播种草稿(agent 重放自己的编辑);仓库级文件锁;事务写入,失败回滚含 journal 截断;unix 上目录 0700、文件 0600。
  • site workflow save|list|show|verify:从录制 bundle 派生语义 workflow。强制剥除 @eN;锚点与参数名剥掉 [expanded] 一类 VOM 状态注解;fill 值一律参数化、不落盘(--inline-values 显式内联,且凭证/邮箱/手机号启发式仍转参数);<select> 的 option value 视为站点常量内联;页面因点击/提交自行发生的跳转视为前一步的效果而丢弃(落地 URL 常内嵌输入值,例如搜索结果页);about:blank 等非 http(s) 跳转丢弃而非致命;首步缺 navigate 时用 entry.start_url 补。verify --pass 清除复核标记,但无锚点 step 保留。
  • site candidate add|list|show:候选观察需 ≥2 个不同 UTC 日期的证据才晋升。
  • 银行、SSO、密码管理器域名在所有入口统一拒绝;SITE.md、references、candidate 全部做秘密特征扫描。

agent 自驱录制

  • bsk record start --detach:录制武装后立即返回并输出 session_id,不再占住 session 的 busy gate,agent 的 observe/act 由扩展录制器按 trusted event 自动捕获;record stop --output 导出。扩展代码无需改动。
  • daemon 的 idle 回收器跳过带录制标记的 session(长思考不会丢录制)。
  • record stop 与阻塞中的 record start 争抢 stop_session 的竞态不再导致 exit 4。

扩展缺陷(真机测试中发现,人工录制同样受影响)

  • record-capture 的搜索外壳启发式把 <body class="…skin-vector-search-vue…"> 当成搜索框外壳,zh.wikipedia.org 首次跳转后所有点击被吞。已收紧判定。
  • frame agent 在 bfcache 恢复(pageshow persisted)后重新武装。
  • navigate-back / navigate-forward 到 fragment-only 历史项时改等 Page.navigatedWithinDocument,返回 reached=same_document,不再超时(超时后重试会多退一格)。

文档

  • skill/SKILL.md 新增 "Site memory" 一节:三条规则(先读记忆、不为学习而探索、学习失败不影响任务)、detach 录制流程、conflict 恢复语义。
  • docs/operation-audit.md 新增"站点记忆:存什么、不存什么"。

验证

  • cargo fmt --checkcargo clippy --workspace --all-targets -D warningscargo test --workspace --locked:826 通过,0 失败(基于 upstream/main)。
  • 扩展:tsc --noEmit 干净,biome 干净,vitest 1691 通过。
  • 真机(Chrome 152 + 本 PR 扩展)在 zh.wikipedia.org / www.wikipedia.org 跑了两轮共 10 个场景:detach 录制覆盖 select/fill/click/press/navigate-back;派生结果无 @eN、无输入值、无注解;新会话按 workflow 直接查询另一座山峰海拔零探索命中;conflict 恢复保留双方内容;idle 回收器跳过录制;黑名单与 @ 劫持拒绝;grep 输入值与 @eN~/.bsk/sites/ 零命中。

已知限制

  • bsk observewww.wikipedia.org 上看不到 #searchInputpackages/vom 遮挡采样规则),复用时该步需用 CSS selector 兜底;同名多链接录制时标 unmatched,派生丢锚点,后续可用 ctx 消歧。
  • 未做引擎级 replay:agent 拿着 workflow 步骤自己 observe/act,锚点失配时退回探索并记 candidate,不自动重试。

🤖 Generated with Claude Code

Add `bsk site`, a daemon-free CLI family that keeps per-host site memory
under `~/.bsk/sites/` so an explored flow is not re-explored:

- `site context` / `checkpoint`: constrained SITE.md facts with
  `[verified YYYY-MM-DD]` stamps, per-task draft isolation, per-host
  revision CAS with draft re-seeding on conflict, repo-level file lock,
  transactional writes with journal rollback, 0700/0600 on unix.
- `site workflow save|list|show|verify`: derive a semantic workflow from a
  TraceV3 recording bundle. `@eN` refs are stripped, VOM state annotations
  are dropped from anchors, typed values become named parameters and are
  never stored, page-driven navigations after a click/submit are treated
  as effects (landing URLs can embed typed values), `<select>` option
  values stay inline. `verify --pass` clears review flags except on
  anchorless steps.
- `site candidate add|list|show`: evidence-gated observations that only
  promote after two distinct UTC dates.
- Sensitive hosts (banking, SSO, password managers) are refused at every
  entry point; SITE.md, references and candidates are secret-scanned.

Let an agent record its own run: `bsk record start --detach` arms the
recorder and returns instead of holding the session busy, so the agent's
observe/act commands are accepted and land in the bundle. The daemon's
idle reaper skips sessions with an armed recording, and `record stop` no
longer reports exit 4 when it races the blocked `record start`.

Extension fixes found while testing on real sites: the search-chrome
heuristic in record-capture treated `<body class="...search-vue...">` as a
search shell and swallowed every click on zh.wikipedia.org after the first
navigation (affects human recordings too); frame agents re-arm after a
bfcache restore; `navigate-back`/`forward` onto a fragment-only history
entry now waits for `Page.navigatedWithinDocument` and reports
`reached=same_document` instead of timing out.

Docs: SKILL.md "Site memory" section and operation-audit notes on what
site memory stores and what it never stores.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant