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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ determines which versions can connect.

### Fixed

- Added `--max-tokens` (`max_tokens` in MCP) to `bsk step`, `bsk plan`, `bsk_interact` (with `sync_after` or `until_visible`), and `bsk_plan`, forwarding it to the post-action `tool.cooperate` sync instead of hardcoding `None` so `--max-tokens` baselines stay reusable across `delta` and `unchanged` syncs without forcing an unbounded page re-capture (#755).
- Ignored internal `data-bsk-*` attributes and `<browser-skill-overlay>` (`[data-bsk-overlay]`) ShadowHost mutations in `cooperation-capture.ts` so active recording and sensitive-field markers no longer advance `FrameState.structure`, excluded extension ShadowRoot UI controls (`HelpRequestOverlay`, `RecordOverlay`, `BorrowConfirmationOverlay`) across `record-capture.ts`, `record-hover-surface.ts`, and `cooperation-capture.ts` so overlay interactions and hover surfaces are never mis-recorded as webpage steps, and re-evaluated tab control ownership after awaiting `ensureOverlayInjected` so mid-injection tab detachments never flash stale `control` state.
- VOM token estimation now handles unpaired UTF-16 surrogates without combining them with the following symbol or throwing a `RangeError`; valid emoji pairs retain their existing estimates.

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ CLI 和扩展可以分别发布,能否连接由协议兼容性决定。更新

### 修复

- 为 `bsk step`、`bsk plan`、MCP `bsk_interact`(搭配 `sync_after` 或 `until_visible`)及 `bsk_plan` 补齐 `--max-tokens`(MCP 为 `max_tokens`)参数并透传至后置 `tool.cooperate` 同步请求,解决此前硬编码 `None` 导致带预算会话在后续动作触发 `token_budget_changed` 并回退为整页无上限重采的问题(#755)。
- 在 `cooperation-capture.ts` 中忽略扩展内部私有 `data-bsk-*` 属性与 `<browser-skill-overlay>`(`[data-bsk-overlay]`)ShadowHost 变更以消除录制/敏感字段标记对 `FrameState.structure` 的自污染,在 `record-capture.ts`、`record-hover-surface.ts` 与 `cooperation-capture.ts` 中统一过滤扩展自身 ShadowRoot 浮层控件(`HelpRequestOverlay`、`RecordOverlay`、`BorrowConfirmationOverlay`)防止浮层内点击/输入或悬停面被误录为网页操作,并在 `ensureOverlayInjected` 异步注入完成后二次校验标签页受控归属以杜绝注入途中断开控制导致的陈旧浮层闪现。
- VOM Token 估算现在能处理未配对的 UTF-16 代理字符,不会再误合并后续符号或抛出 `RangeError`;有效 emoji 代理对的估算保持不变。

Expand Down
7 changes: 3 additions & 4 deletions crates/bsk-cli/skill/references/step-and-cache.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,9 @@ nothing is merged: apply the line patch yourself or sync again for a baseline.
Anything the extension cannot express as such a patch returns a fresh `baseline` with
a `baseline_reason`, for example `structure_changed`, `refs_replaced`, `frame_replaced`,
`focus_changed`, `human_activity`, `text_log_gap`, `text_outside_observation`,
`text_ambiguous`, `token_budget_changed` or `token_budget_shift`. Keep the same
`--max-tokens` across syncs you want patched. Pages with child frames, and text inside
controls, headings, labels, form fields, table rows or list items, always take the
baseline path.
`text_ambiguous`, `token_budget_changed` or `token_budget_shift`. Pass the same
`--max-tokens` on `step` and `plan` as well as `sync` across calls you want patched.
Pages with child frames, and text inside controls, headings, labels, form fields, table rows or list items, always take the baseline path.

For readonly date pickers, click to open the picker instead of filling it. If VOM
exposes only a containing control, inspect that observed ref with `get-html --ref`
Expand Down
16 changes: 14 additions & 2 deletions crates/bsk-cli/src/cli/mcp/tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2133,6 +2133,8 @@ struct InteractArgs {
wait_timeout_ms: Option<u32>,
/// Policy for the post-action sync. Default auto.
policy: Option<Policy>,
/// Approximate token cap for the post-action sync observation (requires sync_after or until_visible).
max_tokens: Option<u32>,
}

enum Prepared {
Expand Down Expand Up @@ -2191,9 +2193,11 @@ fn interact_prepare(args: InteractArgs, conn_scope: Option<&str>) -> Result<Prep
args.depends_on,
)?;
let stepped = args.sync_after.unwrap_or(false) || args.until_visible.is_some();
if !stepped && (args.policy.is_some() || args.wait_timeout_ms.is_some()) {
if !stepped
&& (args.policy.is_some() || args.wait_timeout_ms.is_some() || args.max_tokens.is_some())
{
return Err(invalid(
"policy and wait_timeout_ms apply only with sync_after or until_visible",
"policy, wait_timeout_ms and max_tokens apply only with sync_after or until_visible",
));
}
let validate_transfer_target =
Expand Down Expand Up @@ -2349,6 +2353,7 @@ fn interact_prepare(args: InteractArgs, conn_scope: Option<&str>) -> Result<Prep
params: Value::Object(args.params).to_string(),
until_visible: args.until_visible,
wait_timeout_ms,
max_tokens: args.max_tokens,
save_full: None,
baseline: None,
match_text: Vec::new(),
Expand Down Expand Up @@ -2750,6 +2755,8 @@ struct PlanArgs {
until_visible: Option<String>,
/// Readiness budget for until_visible, 1-25000 ms. Default 5000.
wait_timeout_ms: Option<u32>,
/// Approximate token cap for the post-plan sync observation. Keep the same budget across syncs, steps, and plans to preserve cache reuse.
max_tokens: Option<u32>,
}

/// Validate a plan completely before connecting to the daemon.
Expand All @@ -2776,6 +2783,7 @@ fn plan_prepare(
prepared.tab_id = args.tab_id;
prepared.until_visible = args.until_visible;
prepared.wait_timeout_ms = wait_timeout_ms;
prepared.max_tokens = args.max_tokens;
Ok((prepared, ctx))
}

Expand Down Expand Up @@ -4261,6 +4269,10 @@ mod tests {
error(json!({"action":"click","session":"s","params":{"ref":"e1"},"policy":"target"}))
.contains("sync_after")
);
assert!(
error(json!({"action":"click","session":"s","params":{"ref":"e1"},"max_tokens":150}))
.contains("sync_after")
);
let too_many = vec![json!({"target":"@e1","field":"exists","equals":true}); 17];
assert!(
error(json!({"action":"click","session":"s","params":{"ref":"e1"},"expect":too_many}))
Expand Down
7 changes: 7 additions & 0 deletions crates/bsk-cli/src/cli/plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ pub struct PlanArgs {
/// Readiness budget in milliseconds, independent of the steps' timeouts.
#[arg(long, default_value_t = 5000, value_parser = clap::value_parser!(u32).range(1..=25000))]
pub wait_timeout_ms: u32,
/// Token budget for the post-plan VOM observation. Keep the same budget across syncs, steps, and plans to preserve cache reuse.
#[arg(long = "max-tokens")]
pub max_tokens: Option<u32>,
/// Save the unfiltered combined result, atomically, without overwriting.
#[arg(long)]
pub save_full: Option<PathBuf>,
Expand Down Expand Up @@ -99,6 +102,7 @@ pub(crate) struct Plan {
pub(crate) steps: Vec<Step>,
pub(crate) until_visible: Option<String>,
pub(crate) wait_timeout_ms: u32,
pub(crate) max_tokens: Option<u32>,
pub(crate) budget: Duration,
}

Expand Down Expand Up @@ -143,6 +147,7 @@ impl Plan {
steps,
until_visible: None,
wait_timeout_ms: DEFAULT_WAIT_MS as u32,
max_tokens: None,
budget: BUDGET,
})
}
Expand Down Expand Up @@ -413,6 +418,7 @@ pub(crate) fn run_with_meta(
final_session,
cooperate::Policy::Auto,
tab,
plan.max_tokens,
&mut reply,
&mut exit,
&mut plain_call,
Expand Down Expand Up @@ -444,6 +450,7 @@ fn prepare(args: &PlanArgs, flags: &GlobalFlags) -> anyhow::Result<Plan> {
plan.tab_id = args.tab_id;
plan.until_visible = args.until_visible.clone();
plan.wait_timeout_ms = args.wait_timeout_ms;
plan.max_tokens = args.max_tokens;
Ok(plan)
}

Expand Down
18 changes: 16 additions & 2 deletions crates/bsk-cli/src/cli/step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ pub struct StepArgs {
/// Readiness budget in milliseconds, independent of the action timeout.
#[arg(long, default_value_t = 5000, value_parser = clap::value_parser!(u32).range(1..=25000))]
pub wait_timeout_ms: u32,
/// Token budget for the post-action VOM observation. Keep the same budget across syncs, steps, and plans to preserve cache reuse.
#[arg(long = "max-tokens")]
pub max_tokens: Option<u32>,
/// Save the unfiltered combined result, atomically, without overwriting.
#[arg(long)]
pub save_full: Option<PathBuf>,
Expand Down Expand Up @@ -256,6 +259,7 @@ pub(crate) fn post_sync(
session: &str,
policy: cooperate::Policy,
tab: Option<i64>,
max_tokens: Option<u32>,
result: &mut Value,
exit: &mut u8,
call: &mut impl FnMut(Method, Value, Duration) -> Result<Value, CliError>,
Expand All @@ -270,7 +274,9 @@ pub(crate) fn post_sync(
action: mode,
tab_id: tab,
timeout_ms: Some(1000),
max_tokens: None,
max_tokens: matches!(mode, CooperateAction::Sync | CooperateAction::Enable)
.then_some(max_tokens)
.flatten(),
})
.expect("serializable sync"),
TOOL_IPC_TIMEOUT,
Expand Down Expand Up @@ -346,7 +352,15 @@ pub(crate) fn run(
result["readiness"] = json!({"requested":false});
}
let ready_ms = start.elapsed().as_millis() - action_ms;
post_sync(session, args.policy, tab, &mut result, &mut exit, &mut call);
post_sync(
session,
args.policy,
tab,
args.max_tokens,
&mut result,
&mut exit,
&mut call,
);
result["phase"] = if exit == 0 {
"observed"
} else {
Expand Down
129 changes: 129 additions & 0 deletions crates/bsk-cli/tests/integration/wave2_ssot_mcp_e2e.rs
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,19 @@ async fn wave2_full_chain_ssot_mcp_parity_and_counterexamples() {
.iter()
.find(|t| t["name"] == "bsk_interact")
.unwrap();
assert!(
interact_def["inputSchema"]["properties"]["max_tokens"]["description"]
.as_str()
.is_some_and(|s| s.contains("sync_after")),
"bsk_interact schema must document max_tokens"
);
let plan_def = tools_arr.iter().find(|t| t["name"] == "bsk_plan").unwrap();
assert!(
plan_def["inputSchema"]["properties"]["max_tokens"]["description"]
.as_str()
.is_some_and(|s| s.contains("token")),
"bsk_plan schema must document max_tokens"
);
assert!(
interact_def["inputSchema"]["properties"]["expect"]["items"]["properties"]["target"]
["description"]
Expand Down Expand Up @@ -1392,6 +1405,122 @@ async fn wave2_full_chain_ssot_mcp_parity_and_counterexamples() {
.await;
assert_eq!(snap_mcp_ok["tab_id"], 7);

// Issue #755: MCP bsk_interact (with sync_after/until_visible) and bsk_plan forward max_tokens,
// while bsk_interact rejects max_tokens without sync_after/until_visible before daemon contact.
let before_mcp_budget_err = ext_state.lock().unwrap().recorded.len();
let interact_budget_err = mcp
.call_err(
"bsk_interact",
json!({
"action": "click",
"scope": "agent-alpha",
"params": { "ref": "@e1" },
"context": &next_ctx,
"max_tokens": 150
}),
)
.await;
assert_eq!(interact_budget_err["code"], "invalid_params");
assert_eq!(
ext_state.lock().unwrap().recorded.len(),
before_mcp_budget_err,
"bsk_interact with max_tokens without sync_after must fail closed before WS dispatch"
);

let before_mcp_step_budget = ext_state.lock().unwrap().recorded.len();
let interact_budget_ok = mcp
.call_ok(
"bsk_interact",
json!({
"action": "click",
"scope": "agent-alpha",
"params": { "ref": "@e1" },
"context": &next_ctx,
"sync_after": true,
"max_tokens": 150
}),
)
.await;
assert_eq!(interact_budget_ok["ok"], true);
let post_interact_ctx = interact_budget_ok["post"]["context_id"]
.as_str()
.expect("post context_id after budgeted bsk_interact")
.to_owned();
{
let st = ext_state.lock().unwrap();
let slice = &st.recorded[before_mcp_step_budget..];
let click_req = slice
.iter()
.find(|r| r.method == Method::ToolClick)
.expect("tool.click sent");
assert!(
click_req
.params
.as_ref()
.unwrap()
.get("max_tokens")
.is_none()
);
let coop_req = slice
.iter()
.find(|r| r.method == Method::ToolCooperate)
.expect("tool.cooperate sent");
assert_eq!(coop_req.params.as_ref().unwrap()["max_tokens"], 150);
}

let before_mcp_until_budget = ext_state.lock().unwrap().recorded.len();
let interact_until_ok = mcp
.call_ok(
"bsk_interact",
json!({
"action": "click",
"scope": "agent-alpha",
"params": { "ref": "@e1" },
"context": &post_interact_ctx,
"until_visible": "#saved",
"max_tokens": 150
}),
)
.await;
assert_eq!(interact_until_ok["ok"], true);
let post_until_ctx = interact_until_ok["post"]["context_id"]
.as_str()
.expect("post context_id after until_visible bsk_interact")
.to_owned();
{
let st = ext_state.lock().unwrap();
let slice = &st.recorded[before_mcp_until_budget..];
let coop_req = slice
.iter()
.find(|r| r.method == Method::ToolCooperate)
.expect("tool.cooperate sent after until_visible bsk_interact");
assert_eq!(coop_req.params.as_ref().unwrap()["max_tokens"], 150);
}

let before_mcp_plan_budget = ext_state.lock().unwrap().recorded.len();
let plan_budget_ok = mcp
.call_ok(
"bsk_plan",
json!({
"scope": "agent-alpha",
"context": &post_until_ctx,
"steps": [{ "action": "click", "ref": "@e1" }],
"max_tokens": 150
}),
)
.await;
assert_eq!(plan_budget_ok["ok"], true);
assert_eq!(plan_budget_ok["completed"], 1);
{
let st = ext_state.lock().unwrap();
let slice = &st.recorded[before_mcp_plan_budget..];
let coop_req = slice
.iter()
.find(|r| r.method == Method::ToolCooperate)
.expect("tool.cooperate sent after bsk_plan");
assert_eq!(coop_req.params.as_ref().unwrap()["max_tokens"], 150);
}

// Cleanly stop scoped sessions.
let _ = mcp
.call_ok("bsk_session", json!({ "action": "stop", "all": true }))
Expand Down
Loading
Loading