feat: bucle percibir->actuar — dom_click_ref/type_ref/hover_ref por #ref + auto-observe

This commit is contained in:
agent
2026-06-06 13:16:17 +02:00
parent f461296e8a
commit ae324562e8
4 changed files with 158 additions and 10 deletions
+24 -6
View File
@@ -86,16 +86,34 @@ func (d *deps) handlePagePerceive(_ context.Context, _ mcp.CallToolRequest, a pa
maxChars = 20000
}
outline, err := d.perceiveOutlineTab(port, a.TabID, maxChars)
if err != nil {
return mcp.NewToolResultError(err.Error()), nil
}
return mcp.NewToolResultText(outline), nil
}
// perceiveOutline genera el outline AX accionable de la pestaña (vía el pipeline
// cdp_perceive_outline). Usa la primera pestaña 'page' del puerto.
func (d *deps) perceiveOutline(port, maxChars int) (string, error) {
return d.perceiveOutlineTab(port, "", maxChars)
}
// perceiveOutlineTab genera el outline AX accionable de la pestaña indicada (vía
// el pipeline cdp_perceive_outline). Si tabID es "", usa la primera pestaña 'page'.
// Resuelve la raíz del registry para localizar el binario `fn` + el venv de Python
// y ejecuta `<root>/fn run cdp_perceive_outline <port> <tabID> <maxChars>` por
// subprocess, devolviendo su stdout truncado a htmlMax.
func (d *deps) perceiveOutlineTab(port int, tabID string, maxChars int) (string, error) {
root, err := resolveRoot()
if err != nil {
return mcp.NewToolResultError("resolve registry root: " + err.Error()), nil
return "", fmt.Errorf("resolve registry root: %w", err)
}
tabID := a.TabID
if tabID == "" {
tabs, err := browser.CdpListTabs("localhost", port)
if err != nil {
return mcp.NewToolResultError("list tabs: " + err.Error()), nil
return "", fmt.Errorf("list tabs: %w", err)
}
for _, t := range tabs {
if t.Type == "page" {
@@ -104,7 +122,7 @@ func (d *deps) handlePagePerceive(_ context.Context, _ mcp.CallToolRequest, a pa
}
}
if tabID == "" {
return mcp.NewToolResultError("no 'page' tab found on port " + fmt.Sprint(port)), nil
return "", fmt.Errorf("no 'page' tab found on port %d", port)
}
}
@@ -125,9 +143,9 @@ func (d *deps) handlePagePerceive(_ context.Context, _ mcp.CallToolRequest, a pa
if msg == "" {
msg = err.Error()
}
return mcp.NewToolResultError("cdp_perceive_outline failed: " + msg), nil
return "", fmt.Errorf("cdp_perceive_outline failed: %s", msg)
}
return mcp.NewToolResultText(truncate(stdout.String(), htmlMax)), nil
return truncate(stdout.String(), htmlMax), nil
}
// ---- page_get_html ----