v0.42.0 82578de

web_search_guard.go RawHistoryFolder

1package agent
2
3import (
4	"context"
5	"encoding/json"
6	"errors"
7	"sync/atomic"
8
9	"github.com/bnema/zut/packages/agent/tools"
10	"github.com/bnema/zut/packages/core"
11)
12
13var errWebSearchSessionRevoked = errors.New("web capability is unavailable in this session")
14
15// webSearchSessionGuard is shared by every web capability tool instance built
16// for one interactive session. Registry refreshes replace the advertised
17// tools, but older tools already snapshotted by core still consult this guard
18// at their execution boundary.
19type webSearchSessionGuard struct {
20	available  atomic.Bool
21	generation atomic.Uint64
22}
23
24func (g *webSearchSessionGuard) setAvailable(available bool) {
25	if g == nil {
26		return
27	}
28	if !available {
29		// Increment only on an actual allow-to-deny transition. A wrapper built
30		// while denied then committed by a later successful refresh belongs to
31		// the new generation; wrappers from before revocation never revive.
32		if g.available.Swap(false) {
33			g.generation.Add(1)
34		}
35		return
36	}
37	g.available.Store(true)
38}
39
40func (g *webSearchSessionGuard) wrapRegistry(reg core.Registry) core.Registry {
41	if g == nil || reg == nil {
42		return reg
43	}
44	for name, tool := range reg {
45		if !tools.IsWebCapabilityName(name) || webSearchToolGuard(tool) == g {
46			continue
47		}
48		guarded := &guardedWebSearchTool{
49			Tool:       tool,
50			guard:      g,
51			generation: g.generation.Load(),
52		}
53		if previewer, ok := tool.(core.ToolPreviewer); ok {
54			reg[name] = &guardedWebSearchPreviewTool{
55				guardedWebSearchTool: guarded,
56				previewer:            previewer,
57			}
58			continue
59		}
60		reg[name] = guarded
61	}
62	return reg
63}
64
65// guardedWebSearchTool wraps every member of the web capability. All extension
66// interception, confirmation, and permission behavior remains in the normal
67// core path; this final check only closes the stale-registry execution window.
68type guardedWebSearchTool struct {
69	core.Tool
70	guard      *webSearchSessionGuard
71	generation uint64
72}
73
74func webSearchToolGuard(tool core.Tool) *webSearchSessionGuard {
75	switch tool := tool.(type) {
76	case *guardedWebSearchTool:
77		return tool.guard
78	case *guardedWebSearchPreviewTool:
79		return tool.guard
80	default:
81		return nil
82	}
83}
84
85func (t *guardedWebSearchTool) available() bool {
86	return t != nil && t.guard != nil && t.guard.available.Load() && t.generation == t.guard.generation.Load()
87}
88
89func (t *guardedWebSearchTool) Execute(ctx context.Context, args json.RawMessage, progress func(string)) (core.ToolResult, error) {
90	if !t.available() {
91		return core.ToolResult{}, errWebSearchSessionRevoked
92	}
93	return t.Tool.Execute(ctx, args, progress)
94}
95
96// guardedWebSearchPreviewTool preserves preview support only when the wrapped
97// tool already implements core.ToolPreviewer.
98type guardedWebSearchPreviewTool struct {
99	*guardedWebSearchTool
100	previewer core.ToolPreviewer
101}
102
103func (t *guardedWebSearchPreviewTool) Preview(ctx context.Context, args json.RawMessage) (core.ToolResult, error) {
104	if !t.available() {
105		return core.ToolResult{}, errWebSearchSessionRevoked
106	}
107	return t.previewer.Preview(ctx, args)
108}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 1

Tags 476

↑↓ moveenter openesc close