GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat(acp): surface safe browser tool metadata (#1000) · Twigpine/zero@a6ec043

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • internal
    • acp
      • permission.go
      • permission_test.go
      • translate.go
      • translate_test.go
      • types.go
    • tools
      • local_browser.go
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎internal/acp/permission.go‎

Copy file name to clipboardExpand all lines: internal/acp/permission.go
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,15 @@ func actionOffered(optionID string, offered []PermissionOption) bool {
142142
// session/request_permission request from a ZERO permission request.
143143
func permissionToolCall(req agent.PermissionRequest) ToolCallUpdate {
144144
args := marshalArgs(req.Args)
145-
return ToolCallUpdate{
145+
upd := ToolCallUpdate{
146146
ToolCallID: req.ToolCallID,
147147
Title: toolTitle(req.ToolName, string(args)),
148148
Kind: toolKindFor(req.ToolName),
149149
Status: ToolStatusPending,
150150
RawInput: rawInputBytes(args),
151151
}
152+
attachBrowserToolDetails(&upd, req.ToolName)
153+
return upd
152154
}
153155

154156
func marshalArgs(args map[string]any) []byte {
Collapse file

‎internal/acp/permission_test.go‎

Copy file name to clipboardExpand all lines: internal/acp/permission_test.go
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,17 @@ func TestPermissionToolCall(t *testing.T) {
8282
t.Error("expected rawInput from args")
8383
}
8484
}
85+
86+
func TestPermissionToolCallKeepsTheBrowserDescriptor(t *testing.T) {
87+
call := permissionToolCall(agent.PermissionRequest{
88+
ToolCallID: "browser-1",
89+
ToolName: "browser_connect",
90+
Args: map[string]any{"target": "127.0.0.1:9222"},
91+
})
92+
if got := browserDescriptor(t, call); got != (BrowserToolDetails{Version: 1, Command: "connect"}) {
93+
t.Fatalf("browser descriptor = %#v", got)
94+
}
95+
if call.Title != "browser connect" {
96+
t.Fatalf("title = %q", call.Title)
97+
}
98+
}
Collapse file

‎internal/acp/translate.go‎

Copy file name to clipboardExpand all lines: internal/acp/translate.go
+119-1Lines changed: 119 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ package acp
22

33
import (
44
"encoding/json"
5+
"net/url"
56
"strings"
7+
"unicode"
68
"unicode/utf8"
79

810
"github.com/Gitlawb/zero/internal/agent"
@@ -44,12 +46,125 @@ func toolKindFor(name string) string {
4446

4547
// toolTitle builds a concise human title, e.g. "read_file src/main.go".
4648
func toolTitle(name, rawArgs string) string {
49+
if browser, ok := browserToolDetails(name); ok {
50+
return browserToolTitle(browser.Command, rawArgs)
51+
}
4752
if hint := primaryArgHint(rawArgs); hint != "" {
4853
return name + " " + hint
4954
}
5055
return name
5156
}
5257

58+
// browserToolDetails identifies ZERO's local browser helpers without treating
59+
// similarly named MCP tools as browser automation. The descriptor intentionally
60+
// contains no request data: ACP tool input is already protocol-visible, but a
61+
// durable UI must not need to retain text, local CDP targets, or full URLs just
62+
// to recognise the browser operation.
63+
func browserToolDetails(name string) (*BrowserToolDetails, bool) {
64+
const prefix = "browser_"
65+
command, ok := strings.CutPrefix(name, prefix)
66+
if !ok {
67+
return nil, false
68+
}
69+
switch command {
70+
case "install", "launch", "connect", "open", "snapshot", "click", "type", "press", "action":
71+
return &BrowserToolDetails{Version: 1, Command: command}, true
72+
default:
73+
return nil, false
74+
}
75+
}
76+
77+
const zeroBrowserMetaKey = "github.com/Gitlawb/zero/browser"
78+
79+
// attachBrowserToolDetails stores ZERO's browser descriptor in ACP's reserved
80+
// extension channel. Keeping this in one helper prevents start, result, and
81+
// permission payloads from drifting onto different wire shapes.
82+
func attachBrowserToolDetails(update *ToolCallUpdate, name string) {
83+
browser, ok := browserToolDetails(name)
84+
if !ok {
85+
return
86+
}
87+
raw, err := json.Marshal(browser)
88+
if err != nil {
89+
return
90+
}
91+
update.Meta = map[string]json.RawMessage{zeroBrowserMetaKey: raw}
92+
}
93+
94+
// browserToolTitle avoids putting browser_type text, an attached DevTools
95+
// endpoint, or a URL query/fragment in a tool-card title. Those values can
96+
// carry credentials or session data; the UI only needs the operation and, for
97+
// navigation, a human-recognisable origin.
98+
func browserToolTitle(command, rawArgs string) string {
99+
switch command {
100+
case "action":
101+
action, ok := exactJSONStringArg(rawArgs, "command")
102+
if !ok {
103+
return "browser action"
104+
}
105+
if action, ok := tools.NormalizedBrowserActionCommand(action); ok {
106+
return "browser action " + action
107+
}
108+
return "browser action"
109+
case "open":
110+
rawURL, ok := exactJSONStringArg(rawArgs, "url")
111+
if !ok {
112+
return "browser open"
113+
}
114+
normalized, err := tools.NormalizeBrowserOpenURL(rawURL)
115+
if err != nil {
116+
return "browser open"
117+
}
118+
u, err := url.Parse(normalized)
119+
if err != nil || u.Scheme == "" || u.Host == "" {
120+
return "browser open"
121+
}
122+
origin := u.Scheme + "://" + u.Host
123+
if !browserTitleTextSafe(origin) {
124+
return "browser open"
125+
}
126+
return "browser open " + truncateHint(origin)
127+
default:
128+
return "browser " + command
129+
}
130+
}
131+
132+
// browserTitleTextSafe validates text after URL parsing has decoded escaped
133+
// UTF-8 in the host. Valid UTF-8 alone is not presentation-safe: control,
134+
// format/bidi, and line/paragraph separator runes can reorder or split the
135+
// permission label shown to a user. The execution URL remains unchanged.
136+
func browserTitleTextSafe(text string) bool {
137+
if !utf8.ValidString(text) {
138+
return false
139+
}
140+
for _, r := range text {
141+
if unicode.IsControl(r) || unicode.Is(unicode.Cf, r) || unicode.Is(unicode.Zl, r) || unicode.Is(unicode.Zp, r) {
142+
return false
143+
}
144+
}
145+
return true
146+
}
147+
148+
// exactJSONStringArg mirrors ZERO's map-based tool argument decoding: only the
149+
// exact JSON key is considered, and a non-string value is invalid. In
150+
// particular, an incidental "URL" key must not change a permission title when
151+
// browser_open will only read "url".
152+
func exactJSONStringArg(rawArgs, key string) (string, bool) {
153+
var args map[string]json.RawMessage
154+
if json.Unmarshal([]byte(rawArgs), &args) != nil {
155+
return "", false
156+
}
157+
raw, ok := args[key]
158+
if !ok {
159+
return "", false
160+
}
161+
var value string
162+
if json.Unmarshal(raw, &value) != nil {
163+
return "", false
164+
}
165+
return value, true
166+
}
167+
53168
// primaryArgHint extracts the most relevant argument (path/pattern/command) from
54169
// raw JSON arguments. Best-effort; returns "" when it can't parse.
55170
func primaryArgHint(rawArgs string) string {
@@ -89,14 +204,16 @@ func rawInput(args string) json.RawMessage {
89204
// toolCallStart maps an advertised ZERO tool call to the initial ACP "tool_call"
90205
// update (status in_progress — ZERO executes immediately after advertising).
91206
func toolCallStart(call agent.ToolCall) ToolCallUpdate {
92-
return ToolCallUpdate{
207+
upd := ToolCallUpdate{
93208
SessionUpdate: UpdateToolCall,
94209
ToolCallID: call.ID,
95210
Title: toolTitle(call.Name, call.Arguments),
96211
Kind: toolKindFor(call.Name),
97212
Status: ToolStatusInProgress,
98213
RawInput: rawInput(call.Arguments),
99214
}
215+
attachBrowserToolDetails(&upd, call.Name)
216+
return upd
100217
}
101218

102219
// toolCallResult maps a finished ZERO tool result to a "tool_call_update".
@@ -116,6 +233,7 @@ func toolCallResult(result agent.ToolResult) ToolCallUpdate {
116233
if locs := toolResultLocations(result); len(locs) > 0 {
117234
upd.Locations = locs
118235
}
236+
attachBrowserToolDetails(&upd, result.Name)
119237
return upd
120238
}
121239

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.