synabun 2026.4.27 → 2026.5.2-beta

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/CHANGELOG.md +189 -9
  2. package/README.md +67 -7
  3. package/hooks/claude-code/post-plan.mjs +56 -3
  4. package/hooks/claude-code/session-start.mjs +28 -1
  5. package/hooks/claude-code/shared.mjs +13 -1
  6. package/hooks/claude-code/stop.mjs +23 -0
  7. package/mcp-server/src/index.ts +4 -0
  8. package/mcp-server/src/services/profiles.ts +113 -7
  9. package/mcp-server/src/tools/gsc/experience.ts +440 -0
  10. package/mcp-server/src/tools/gsc/helpers.ts +288 -0
  11. package/mcp-server/src/tools/gsc/indexing.ts +495 -0
  12. package/mcp-server/src/tools/gsc/inspect.ts +391 -0
  13. package/mcp-server/src/tools/gsc/navigate.ts +236 -0
  14. package/mcp-server/src/tools/gsc/performance.ts +352 -0
  15. package/mcp-server/src/tools/gsc/settings.ts +564 -0
  16. package/mcp-server/src/tools/gsc.ts +95 -0
  17. package/mcp-server/src/tools/loop.ts +62 -15
  18. package/mcp-server/src/tools/profile.ts +1 -0
  19. package/neural-interface/public/shared/cdx/cdx-icons.js +1 -0
  20. package/neural-interface/public/shared/cdx/cdx-panel.js +24 -5
  21. package/neural-interface/public/shared/cdx/cdx-tabs.js +42 -0
  22. package/neural-interface/public/shared/html-shell.js +35 -35
  23. package/neural-interface/public/shared/ocp/ocp-panel.js +255 -25
  24. package/neural-interface/public/shared/ocp/ocp-render.js +152 -3
  25. package/neural-interface/public/shared/ocp/ocp-styles.js +520 -31
  26. package/neural-interface/public/shared/ocp/ocp-tabs.js +786 -128
  27. package/neural-interface/public/shared/provider-icons.js +2 -0
  28. package/neural-interface/public/shared/storage.js +5 -0
  29. package/neural-interface/public/shared/styles.css +538 -141
  30. package/neural-interface/public/shared/ui-claude-panel.js +35 -17
  31. package/neural-interface/public/shared/ui-file-explorer.js +65 -41
  32. package/neural-interface/public/shared/ui-menubar.js +17 -3
  33. package/neural-interface/public/shared/ui-navbar.js +33 -9
  34. package/neural-interface/public/shared/ui-sessions.js +613 -23
  35. package/neural-interface/public/shared/ui-settings.js +1 -2
  36. package/neural-interface/public/shared/ui-sidepanel-tray.js +173 -22
  37. package/neural-interface/public/shared/ui-sync.js +11 -5
  38. package/neural-interface/public/shared/ui-tool-updates.js +35 -16
  39. package/neural-interface/public/shared/ui-tutorial-steps.js +3 -3
  40. package/neural-interface/public/shared/ui-update.js +17 -2
  41. package/neural-interface/server.js +791 -21
  42. package/neural-interface/templates/CLAUDE-template.md +19 -6
  43. package/neural-interface/templates/ruleset-versions.json +31 -0
  44. package/package.json +1 -1
  45. package/setup.js +96 -37
@@ -0,0 +1,495 @@
1
+ /**
2
+ * GSC Indexing reports — pages, videos, sitemaps, removals.
3
+ * Tools: gsc_pages_report, gsc_pages_validate_fix, gsc_videos_report,
4
+ * gsc_sitemap, gsc_removals, gsc_removals_cancel
5
+ */
6
+
7
+ import { z } from 'zod';
8
+ import * as ni from '../../services/neural-interface.js';
9
+ import { text } from '../response.js';
10
+ import { GSC_BASE, encodeProperty, currentProperty, ensureAuth, resolve, wait, pollFor, safeNavigate, TABLE_EXTRACTOR_SCRIPT, readMetricTileScript } from './helpers.js';
11
+
12
+ const tabId = z.string().optional();
13
+
14
+ // ── gsc_pages_report ──────────────────────────────────────────
15
+
16
+ export const gscPagesReportSchema = {
17
+ reason: z.string().optional().describe('Drill into a specific reason (e.g. "Not found (404)", "Excluded by ‘noindex’ tag"). Returns URL examples for that bucket.'),
18
+ property: z.string().optional(),
19
+ sessionId: z.string().optional(),
20
+ tabId,
21
+ };
22
+
23
+ export const gscPagesReportDescription =
24
+ 'Read the Pages (Coverage/Indexação) report — totals indexed/notIndexed and per-reason buckets with counts and trends. ' +
25
+ 'Pass `reason` to drill into a bucket and list URL examples.';
26
+
27
+ export async function handleGscPagesReport(args: { reason?: string; property?: string; sessionId?: string; tabId?: string }) {
28
+ const r = await resolve(args.sessionId, args.tabId);
29
+ if ('error' in r) return text(r.error);
30
+
31
+ const prop = args.property || (await currentProperty(r));
32
+ if (!prop) return text('No active property.');
33
+
34
+ const url = `${GSC_BASE}/index?resource_id=${encodeProperty(prop)}`;
35
+ const nav = await safeNavigate(r, url);
36
+ if (nav.error) return text(`Navigation failed: ${nav.error}`);
37
+
38
+ const authErr = await ensureAuth(r);
39
+ if (authErr) return text(authErr);
40
+
41
+ await pollFor(r, `(() => document.querySelector('[role="grid"], [role="table"]') || /Indexad[oa]s?|Indexed/.test(document.body.innerText) ? true : null)()`, 20000, 500);
42
+ await wait(800);
43
+
44
+ // Top-level metrics — readMetricTileScript walks ancestors so it handles
45
+ // the GSC tile layout where label and number sit in adjacent (not nested)
46
+ // elements. Pages report uses "Indexados" (masculine) for the indexed tile
47
+ // even though listings/rows use "Indexadas" — both forms are in LOCALE_LABELS.
48
+ const [indexedRes, notIndexedRes] = await Promise.all([
49
+ ni.evaluate(r.sessionId, readMetricTileScript('indexed'), r.tabId),
50
+ ni.evaluate(r.sessionId, readMetricTileScript('notIndexed'), r.tabId),
51
+ ]);
52
+ const metrics = {
53
+ result: {
54
+ indexed: (indexedRes.result as string | null) ?? null,
55
+ notIndexed: (notIndexedRes.result as string | null) ?? null,
56
+ },
57
+ };
58
+
59
+ const tableRes = await ni.evaluate(r.sessionId, TABLE_EXTRACTOR_SCRIPT('[role="grid"], [role="table"], table'), r.tabId);
60
+ const reasons = (tableRes.result || { rows: [] }) as { rows: Array<Record<string, unknown>> };
61
+
62
+ if (args.reason) {
63
+ // Click row matching reason name
64
+ const click = await ni.evaluate(
65
+ r.sessionId,
66
+ `(() => {
67
+ const rows = Array.from(document.querySelectorAll('[role="row"], tr'));
68
+ const target = rows.find(row => (row.textContent || '').toLowerCase().includes(${JSON.stringify(args.reason.toLowerCase())}));
69
+ if (target) {
70
+ const link = target.querySelector('a, button, [role="link"]');
71
+ (link || target).click();
72
+ return true;
73
+ }
74
+ return false;
75
+ })()`,
76
+ r.tabId,
77
+ );
78
+ if (!click.result) return text(`Reason not found: "${args.reason}". Available reasons:\n${JSON.stringify(reasons.rows, null, 2)}`);
79
+ // Wait for either URL change to a drilldown OR a new grid with a URL
80
+ // column to appear — fixed waits race the SPA load.
81
+ await pollFor(
82
+ r,
83
+ `(() => {
84
+ if (location.search.includes('issue=') || location.pathname.includes('/drilldown')) return true;
85
+ const grids = document.querySelectorAll('[role="grid"], [role="table"]');
86
+ for (const g of grids) {
87
+ const heads = Array.from(g.querySelectorAll('[role="columnheader"], th')).map(c => (c.textContent || '').trim());
88
+ if (heads.some(h => /^URL$/i.test(h))) return true;
89
+ }
90
+ return null;
91
+ })()`,
92
+ 8000,
93
+ 400,
94
+ );
95
+ await wait(400);
96
+ // Tag the last grid (drilldown panel renders below summary) so the
97
+ // shared TABLE_EXTRACTOR_SCRIPT can scope to it via a unique selector.
98
+ await ni.evaluate(
99
+ r.sessionId,
100
+ `(() => {
101
+ document.querySelectorAll('[data-gsc-drilldown="1"]').forEach(n => n.removeAttribute('data-gsc-drilldown'));
102
+ const grids = document.querySelectorAll('[role="grid"], [role="table"], table');
103
+ if (grids.length === 0) return false;
104
+ grids[grids.length - 1].setAttribute('data-gsc-drilldown', '1');
105
+ return true;
106
+ })()`,
107
+ r.tabId,
108
+ );
109
+ const examples = await ni.evaluate(r.sessionId, TABLE_EXTRACTOR_SCRIPT('[data-gsc-drilldown="1"]'), r.tabId);
110
+ const examplesResult = examples.result || (await ni.evaluate(r.sessionId, TABLE_EXTRACTOR_SCRIPT('[role="grid"], [role="table"]'), r.tabId)).result;
111
+ return text(JSON.stringify({ metrics: metrics.result, reason: args.reason, examples: examplesResult }, null, 2));
112
+ }
113
+
114
+ return text(JSON.stringify({ metrics: metrics.result, reasons: reasons.rows }, null, 2));
115
+ }
116
+
117
+ // ── gsc_pages_validate_fix ────────────────────────────────────
118
+
119
+ export const gscPagesValidateFixSchema = {
120
+ reason: z.string().describe('Reason name for which to start a "Validate fix" run (e.g. "Server error (5xx)").'),
121
+ property: z.string().optional(),
122
+ sessionId: z.string().optional(),
123
+ tabId,
124
+ };
125
+
126
+ export const gscPagesValidateFixDescription =
127
+ '[mutating — starts a Google validation cycle] Open a Pages-report reason bucket and click "Validate fix" so Google re-checks the URLs. Returns confirmation status.';
128
+
129
+ export async function handleGscPagesValidateFix(args: { reason: string; property?: string; sessionId?: string; tabId?: string }) {
130
+ const r = await resolve(args.sessionId, args.tabId);
131
+ if ('error' in r) return text(r.error);
132
+
133
+ await handleGscPagesReport({ reason: args.reason, property: args.property, sessionId: args.sessionId, tabId: args.tabId });
134
+
135
+ const click = await ni.evaluate(
136
+ r.sessionId,
137
+ `(() => {
138
+ const btns = Array.from(document.querySelectorAll('button, [role="button"]'));
139
+ const v = btns.find(b => /validate\\s*fix|validar\\s*correção/i.test(b.textContent || b.getAttribute('aria-label') || ''));
140
+ if (v) { v.click(); return true; }
141
+ return false;
142
+ })()`,
143
+ r.tabId,
144
+ );
145
+ if (!click.result) return text('"Validate fix" button not found — reason may not support validation, or all issues already fixed.');
146
+
147
+ const result = await pollFor<Record<string, unknown>>(
148
+ r,
149
+ `(() => {
150
+ const txt = document.body.innerText;
151
+ if (/Validation started|Validação iniciada|We've started validating/i.test(txt)) return { started: true };
152
+ if (/Validation already in progress|já em andamento/i.test(txt)) return { started: false, reason: 'already_running' };
153
+ return null;
154
+ })()`,
155
+ 20000,
156
+ 600,
157
+ );
158
+ return text(`Validate fix:\n${JSON.stringify(result || { started: false, reason: 'no_confirmation' }, null, 2)}`);
159
+ }
160
+
161
+ // ── gsc_videos_report ─────────────────────────────────────────
162
+
163
+ export const gscVideosReportSchema = {
164
+ property: z.string().optional(),
165
+ sessionId: z.string().optional(),
166
+ tabId,
167
+ };
168
+
169
+ export const gscVideosReportDescription =
170
+ 'Read the Video indexing report — same shape as gsc_pages_report but for video pages.';
171
+
172
+ export async function handleGscVideosReport(args: { property?: string; sessionId?: string; tabId?: string }) {
173
+ const r = await resolve(args.sessionId, args.tabId);
174
+ if ('error' in r) return text(r.error);
175
+ const prop = args.property || (await currentProperty(r));
176
+ if (!prop) return text('No active property.');
177
+ const nav = await safeNavigate(r, `${GSC_BASE}/video-index?resource_id=${encodeProperty(prop)}`);
178
+ if (nav.error) return text(`Navigation failed: ${nav.error}`);
179
+ // Wait for either grid or no-data marker rather than only the grid.
180
+ await pollFor(
181
+ r,
182
+ `(() => (document.querySelector('[role="grid"], [role="table"]') || /no data|nenhum dado|no video pages|nenhuma página de vídeo/i.test(document.body.innerText)) ? true : null)()`,
183
+ 20000,
184
+ 500,
185
+ );
186
+ await wait(800);
187
+ const [indexedRes, notIndexedRes, tableRes] = await Promise.all([
188
+ ni.evaluate(r.sessionId, readMetricTileScript('indexed'), r.tabId),
189
+ ni.evaluate(r.sessionId, readMetricTileScript('notIndexed'), r.tabId),
190
+ ni.evaluate(r.sessionId, TABLE_EXTRACTOR_SCRIPT('[role="grid"], [role="table"], table'), r.tabId),
191
+ ]);
192
+ const metrics = {
193
+ indexed: (indexedRes.result as string | null) ?? null,
194
+ notIndexed: (notIndexedRes.result as string | null) ?? null,
195
+ };
196
+ const issues = tableRes.result;
197
+ if (!issues && metrics.indexed === null && metrics.notIndexed === null) {
198
+ return text(JSON.stringify({ metrics: { indexed: '0', notIndexed: '0' }, issues: { headers: [], rows: [] }, status: 'no_data' }, null, 2));
199
+ }
200
+ return text(JSON.stringify({ metrics, issues: issues || { headers: [], rows: [] } }, null, 2));
201
+ }
202
+
203
+ // ── gsc_sitemap ───────────────────────────────────────────────
204
+
205
+ export const gscSitemapSchema = {
206
+ action: z.enum(['list', 'submit', 'delete', 'view_errors'] as const),
207
+ url: z.string().optional().describe('Sitemap URL (relative or absolute) for submit/delete/view_errors.'),
208
+ property: z.string().optional(),
209
+ sessionId: z.string().optional(),
210
+ tabId,
211
+ };
212
+
213
+ export const gscSitemapDescription =
214
+ 'Manage sitemaps. action=list returns all submitted sitemaps; action=submit adds a sitemap (mutating); ' +
215
+ 'action=delete removes one (mutating); action=view_errors opens the per-sitemap detail and returns issues.';
216
+
217
+ export async function handleGscSitemap(args: { action: string; url?: string; property?: string; sessionId?: string; tabId?: string }) {
218
+ const r = await resolve(args.sessionId, args.tabId);
219
+ if ('error' in r) return text(r.error);
220
+ const prop = args.property || (await currentProperty(r));
221
+ if (!prop) return text('No active property.');
222
+
223
+ const nav = await safeNavigate(r, `${GSC_BASE}/sitemaps?resource_id=${encodeProperty(prop)}`);
224
+ if (nav.error) return text(`Navigation failed: ${nav.error}`);
225
+ // Bump from 15s → 30s; sitemaps page often blocks past domcontentloaded.
226
+ await pollFor(r, `(() => document.querySelector('[role="grid"], [role="table"], input[type="text"]') ? true : null)()`, 30000, 500);
227
+ await wait(700);
228
+
229
+ if (args.action === 'list') {
230
+ const tableRes = await ni.evaluate(r.sessionId, TABLE_EXTRACTOR_SCRIPT('[role="grid"], [role="table"], table'), r.tabId);
231
+ return text(JSON.stringify(tableRes.result, null, 2));
232
+ }
233
+
234
+ if (args.action === 'submit') {
235
+ if (!args.url) return text('url required for submit.');
236
+ await ni.evaluate(
237
+ r.sessionId,
238
+ `(() => { const i = document.querySelector('input[type="text"], input:not([type])'); if (i) { i.focus(); i.value = ${JSON.stringify(args.url)}; i.dispatchEvent(new Event('input', { bubbles: true })); } })()`,
239
+ r.tabId,
240
+ );
241
+ await wait(300);
242
+ await ni.evaluate(
243
+ r.sessionId,
244
+ `(() => { const btns = Array.from(document.querySelectorAll('button, [role="button"]')); const sub = btns.find(b => /submit|enviar/i.test(b.textContent || '')); if (sub) sub.click(); })()`,
245
+ r.tabId,
246
+ );
247
+ const result = await pollFor<Record<string, unknown>>(
248
+ r,
249
+ `(() => {
250
+ const txt = document.body.innerText;
251
+ if (/Sitemap submitted|Mapa do site enviado|Success/i.test(txt)) return { submitted: true };
252
+ if (/Couldn't read|Não foi possível ler|error|erro/i.test(txt)) return { submitted: false, error: 'parse_failure' };
253
+ return null;
254
+ })()`,
255
+ 30000,
256
+ 800,
257
+ );
258
+ return text(`Sitemap submit:\n${JSON.stringify(result || { submitted: false, error: 'no_confirmation' }, null, 2)}`);
259
+ }
260
+
261
+ if (args.action === 'delete') {
262
+ if (!args.url) return text('url required for delete.');
263
+ const click = await ni.evaluate(
264
+ r.sessionId,
265
+ `(() => {
266
+ const rows = Array.from(document.querySelectorAll('[role="row"], tr'));
267
+ const row = rows.find(r => (r.textContent || '').includes(${JSON.stringify(args.url)}));
268
+ if (!row) return false;
269
+ const link = row.querySelector('a, button');
270
+ (link || row).click();
271
+ return true;
272
+ })()`,
273
+ r.tabId,
274
+ );
275
+ if (!click.result) return text(`Sitemap not found: ${args.url}`);
276
+ await wait(1500);
277
+ await ni.evaluate(
278
+ r.sessionId,
279
+ `(() => {
280
+ const btns = Array.from(document.querySelectorAll('button, [role="button"]'));
281
+ const more = btns.find(b => (b.getAttribute('aria-label') || '').match(/more|menu|mais opções/i));
282
+ if (more) more.click();
283
+ })()`,
284
+ r.tabId,
285
+ );
286
+ await wait(500);
287
+ await ni.evaluate(
288
+ r.sessionId,
289
+ `(() => {
290
+ const items = Array.from(document.querySelectorAll('[role="menuitem"], button, [role="button"]'));
291
+ const del = items.find(i => /remove\\s*sitemap|delete|excluir|remover/i.test(i.textContent || ''));
292
+ if (del) del.click();
293
+ })()`,
294
+ r.tabId,
295
+ );
296
+ await wait(800);
297
+ await ni.evaluate(
298
+ r.sessionId,
299
+ `(() => {
300
+ const btns = Array.from(document.querySelectorAll('button, [role="button"]'));
301
+ const conf = btns.find(b => /^(remove|delete|excluir|remover)$/i.test((b.textContent || '').trim()));
302
+ if (conf) conf.click();
303
+ })()`,
304
+ r.tabId,
305
+ );
306
+ return text(`Delete requested for sitemap: ${args.url}.`);
307
+ }
308
+
309
+ if (args.action === 'view_errors') {
310
+ if (!args.url) return text('url required for view_errors.');
311
+ await ni.evaluate(
312
+ r.sessionId,
313
+ `(() => {
314
+ const rows = Array.from(document.querySelectorAll('[role="row"], tr'));
315
+ const row = rows.find(r => (r.textContent || '').includes(${JSON.stringify(args.url)}));
316
+ if (row) { const link = row.querySelector('a'); (link || row).click(); }
317
+ })()`,
318
+ r.tabId,
319
+ );
320
+ await wait(2500);
321
+ const tableRes = await ni.evaluate(r.sessionId, TABLE_EXTRACTOR_SCRIPT('[role="grid"], [role="table"], table'), r.tabId);
322
+ return text(JSON.stringify(tableRes.result, null, 2));
323
+ }
324
+
325
+ return text(`Unknown action: ${args.action}`);
326
+ }
327
+
328
+ // ── gsc_removals ──────────────────────────────────────────────
329
+
330
+ export const gscRemovalsSchema = {
331
+ action: z.enum(['list_temporary', 'list_outdated', 'list_safesearch', 'new'] as const),
332
+ removalType: z.enum(['temporary', 'outdated_content', 'safe_search'] as const).optional().describe('Required for action=new.'),
333
+ target: z.string().optional().describe('URL or prefix for action=new.'),
334
+ scope: z.enum(['url', 'prefix'] as const).optional().describe('For action=new + temporary: remove only this URL or all URLs starting with this prefix.'),
335
+ property: z.string().optional(),
336
+ sessionId: z.string().optional(),
337
+ tabId,
338
+ };
339
+
340
+ export const gscRemovalsDescription =
341
+ 'Manage URL removals. list_* returns existing requests; ' +
342
+ 'action=new submits a new removal (mutating). ' +
343
+ 'removalType: temporary (6-month hide), outdated_content (refresh Google\'s cached version), safe_search (report adult content).';
344
+
345
+ export async function handleGscRemovals(args: {
346
+ action: string; removalType?: string; target?: string; scope?: string;
347
+ property?: string; sessionId?: string; tabId?: string;
348
+ }) {
349
+ const r = await resolve(args.sessionId, args.tabId);
350
+ if ('error' in r) return text(r.error);
351
+ const prop = args.property || (await currentProperty(r));
352
+ if (!prop) return text('No active property.');
353
+
354
+ const nav = await safeNavigate(r, `${GSC_BASE}/removals?resource_id=${encodeProperty(prop)}`);
355
+ if (nav.error) return text(`Navigation failed: ${nav.error}`);
356
+ await pollFor(r, `(() => document.querySelector('[role="tab"], [role="grid"], button') ? true : null)()`, 15000, 400);
357
+ await wait(700);
358
+
359
+ const tabMap: Record<string, RegExp> = {
360
+ list_temporary: /Temporary|Temporárias/i,
361
+ list_outdated: /Outdated|Conteúdo desatualizado/i,
362
+ list_safesearch: /SafeSearch/i,
363
+ };
364
+
365
+ if (args.action.startsWith('list_')) {
366
+ const re = tabMap[args.action];
367
+ await ni.evaluate(
368
+ r.sessionId,
369
+ `(() => { const t = Array.from(document.querySelectorAll('[role="tab"]')).find(t => ${re.toString()}.test(t.textContent || '')); if (t) t.click(); })()`,
370
+ r.tabId,
371
+ );
372
+ await wait(1500);
373
+ const tableRes = await ni.evaluate(r.sessionId, TABLE_EXTRACTOR_SCRIPT('[role="grid"], [role="table"], table'), r.tabId);
374
+ const t = (tableRes.result || { headers: [], rows: [] }) as { headers: string[]; rows: Array<Record<string, unknown>> };
375
+ // Empty-state placeholder filter: GSC renders a single row pointing at
376
+ // the no-op `#` URL when there are no requests in the active tab.
377
+ t.rows = t.rows.filter(row => {
378
+ const keys = Object.keys(row);
379
+ if (keys.length === 1 && row.url === 'https://search.google.com/#') return false;
380
+ return true;
381
+ });
382
+ if (t.rows.length === 0) {
383
+ return text(JSON.stringify({ ...t, status: 'no_requests' }, null, 2));
384
+ }
385
+ return text(JSON.stringify(t, null, 2));
386
+ }
387
+
388
+ if (args.action === 'new') {
389
+ if (!args.removalType || !args.target) return text('removalType and target required for action=new.');
390
+ await ni.evaluate(
391
+ r.sessionId,
392
+ `(() => { const btns = Array.from(document.querySelectorAll('button, [role="button"]')); const n = btns.find(b => /new\\s*request|nova\\s*solicitação/i.test(b.textContent || '')); if (n) n.click(); })()`,
393
+ r.tabId,
394
+ );
395
+ await wait(1200);
396
+ // Click the right type tab inside the dialog
397
+ const typeRe: Record<string, RegExp> = {
398
+ temporary: /Temporarily remove|Remover\\s*temporariamente/i,
399
+ outdated_content: /Outdated|Desatualizado/i,
400
+ safe_search: /SafeSearch/i,
401
+ };
402
+ const tre = typeRe[args.removalType];
403
+ await ni.evaluate(
404
+ r.sessionId,
405
+ `(() => { const tabs = Array.from(document.querySelectorAll('[role="tab"], button, [role="button"]')); const t = tabs.find(t => ${tre.toString()}.test(t.textContent || '')); if (t) t.click(); })()`,
406
+ r.tabId,
407
+ );
408
+ await wait(700);
409
+ // Fill URL input
410
+ await ni.evaluate(
411
+ r.sessionId,
412
+ `(() => { const i = document.querySelector('input[type="text"], input[type="url"]'); if (i) { i.focus(); i.value = ${JSON.stringify(args.target)}; i.dispatchEvent(new Event('input', { bubbles: true })); } })()`,
413
+ r.tabId,
414
+ );
415
+ await wait(300);
416
+ // For temporary + prefix, click the prefix radio
417
+ if (args.removalType === 'temporary' && args.scope === 'prefix') {
418
+ await ni.evaluate(
419
+ r.sessionId,
420
+ `(() => { const radios = Array.from(document.querySelectorAll('[role="radio"], input[type="radio"]')); const p = radios.find(r => /prefix|prefixo|all\\s*URLs/i.test(r.closest('label')?.textContent || r.parentElement?.textContent || '')); if (p) p.click(); })()`,
421
+ r.tabId,
422
+ );
423
+ }
424
+ await ni.evaluate(
425
+ r.sessionId,
426
+ `(() => { const btns = Array.from(document.querySelectorAll('button, [role="button"]')); const n = btns.find(b => /^(next|próximo|continue)$/i.test((b.textContent || '').trim())); if (n) n.click(); })()`,
427
+ r.tabId,
428
+ );
429
+ await wait(800);
430
+ await ni.evaluate(
431
+ r.sessionId,
432
+ `(() => { const btns = Array.from(document.querySelectorAll('button, [role="button"]')); const sub = btns.find(b => /^(submit\\s*request|submit|enviar)$/i.test((b.textContent || '').trim())); if (sub) sub.click(); })()`,
433
+ r.tabId,
434
+ );
435
+ const result = await pollFor<Record<string, unknown>>(
436
+ r,
437
+ `(() => {
438
+ const txt = document.body.innerText;
439
+ if (/Request submitted|Solicitação enviada|Status:\\s*(Pending|Pendente|In progress)/i.test(txt)) return { submitted: true };
440
+ if (/Couldn't|Não foi possível|error|erro/i.test(txt)) return { submitted: false, error: 'submit_failed' };
441
+ return null;
442
+ })()`,
443
+ 30000,
444
+ 800,
445
+ );
446
+ return text(`Removal request:\n${JSON.stringify(result || { submitted: false, error: 'no_confirmation' }, null, 2)}`);
447
+ }
448
+
449
+ return text(`Unknown action: ${args.action}`);
450
+ }
451
+
452
+ // ── gsc_removals_cancel ───────────────────────────────────────
453
+
454
+ export const gscRemovalsCancelSchema = {
455
+ url: z.string().describe('URL of the removal request to cancel (must match exactly as listed).'),
456
+ property: z.string().optional(),
457
+ sessionId: z.string().optional(),
458
+ tabId,
459
+ };
460
+
461
+ export const gscRemovalsCancelDescription =
462
+ '[mutating] Cancel a pending temporary removal request. URL must match the listed entry exactly.';
463
+
464
+ export async function handleGscRemovalsCancel(args: { url: string; property?: string; sessionId?: string; tabId?: string }) {
465
+ const r = await resolve(args.sessionId, args.tabId);
466
+ if ('error' in r) return text(r.error);
467
+ await handleGscRemovals({ action: 'list_temporary', property: args.property, sessionId: args.sessionId, tabId: args.tabId });
468
+
469
+ const click = await ni.evaluate(
470
+ r.sessionId,
471
+ `(() => {
472
+ const rows = Array.from(document.querySelectorAll('[role="row"], tr'));
473
+ const row = rows.find(r => (r.textContent || '').includes(${JSON.stringify(args.url)}));
474
+ if (!row) return false;
475
+ const more = row.querySelector('[aria-label*="more" i], [aria-label*="opções" i], button');
476
+ if (more) more.click();
477
+ return true;
478
+ })()`,
479
+ r.tabId,
480
+ );
481
+ if (!click.result) return text(`Removal request not found: ${args.url}`);
482
+ await wait(500);
483
+ await ni.evaluate(
484
+ r.sessionId,
485
+ `(() => { const items = Array.from(document.querySelectorAll('[role="menuitem"], button')); const c = items.find(i => /cancel|cancelar/i.test(i.textContent || '')); if (c) c.click(); })()`,
486
+ r.tabId,
487
+ );
488
+ await wait(800);
489
+ await ni.evaluate(
490
+ r.sessionId,
491
+ `(() => { const btns = Array.from(document.querySelectorAll('button, [role="button"]')); const conf = btns.find(b => /^(cancel\\s*request|cancel|cancelar)$/i.test((b.textContent || '').trim())); if (conf) conf.click(); })()`,
492
+ r.tabId,
493
+ );
494
+ return text(`Cancellation requested for ${args.url}.`);
495
+ }