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.
- package/CHANGELOG.md +189 -9
- package/README.md +67 -7
- package/hooks/claude-code/post-plan.mjs +56 -3
- package/hooks/claude-code/session-start.mjs +28 -1
- package/hooks/claude-code/shared.mjs +13 -1
- package/hooks/claude-code/stop.mjs +23 -0
- package/mcp-server/src/index.ts +4 -0
- package/mcp-server/src/services/profiles.ts +113 -7
- package/mcp-server/src/tools/gsc/experience.ts +440 -0
- package/mcp-server/src/tools/gsc/helpers.ts +288 -0
- package/mcp-server/src/tools/gsc/indexing.ts +495 -0
- package/mcp-server/src/tools/gsc/inspect.ts +391 -0
- package/mcp-server/src/tools/gsc/navigate.ts +236 -0
- package/mcp-server/src/tools/gsc/performance.ts +352 -0
- package/mcp-server/src/tools/gsc/settings.ts +564 -0
- package/mcp-server/src/tools/gsc.ts +95 -0
- package/mcp-server/src/tools/loop.ts +62 -15
- package/mcp-server/src/tools/profile.ts +1 -0
- package/neural-interface/public/shared/cdx/cdx-icons.js +1 -0
- package/neural-interface/public/shared/cdx/cdx-panel.js +24 -5
- package/neural-interface/public/shared/cdx/cdx-tabs.js +42 -0
- package/neural-interface/public/shared/html-shell.js +35 -35
- package/neural-interface/public/shared/ocp/ocp-panel.js +255 -25
- package/neural-interface/public/shared/ocp/ocp-render.js +152 -3
- package/neural-interface/public/shared/ocp/ocp-styles.js +520 -31
- package/neural-interface/public/shared/ocp/ocp-tabs.js +786 -128
- package/neural-interface/public/shared/provider-icons.js +2 -0
- package/neural-interface/public/shared/storage.js +5 -0
- package/neural-interface/public/shared/styles.css +538 -141
- package/neural-interface/public/shared/ui-claude-panel.js +35 -17
- package/neural-interface/public/shared/ui-file-explorer.js +65 -41
- package/neural-interface/public/shared/ui-menubar.js +17 -3
- package/neural-interface/public/shared/ui-navbar.js +33 -9
- package/neural-interface/public/shared/ui-sessions.js +613 -23
- package/neural-interface/public/shared/ui-settings.js +1 -2
- package/neural-interface/public/shared/ui-sidepanel-tray.js +173 -22
- package/neural-interface/public/shared/ui-sync.js +11 -5
- package/neural-interface/public/shared/ui-tool-updates.js +35 -16
- package/neural-interface/public/shared/ui-tutorial-steps.js +3 -3
- package/neural-interface/public/shared/ui-update.js +17 -2
- package/neural-interface/server.js +791 -21
- package/neural-interface/templates/CLAUDE-template.md +19 -6
- package/neural-interface/templates/ruleset-versions.json +31 -0
- package/package.json +1 -1
- package/setup.js +96 -37
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Google Search Console — shared helpers.
|
|
3
|
+
*
|
|
4
|
+
* GSC paths use English slugs regardless of UI locale; selectors prefer
|
|
5
|
+
* material-icon ligatures, stable aria roles, and structural anchors over
|
|
6
|
+
* translated label text. The locale dictionary below centralises label
|
|
7
|
+
* matching across en + pt-BR so report parsers stay locale-tolerant.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import * as ni from '../../services/neural-interface.js';
|
|
11
|
+
|
|
12
|
+
export const GSC_BASE = 'https://search.google.com/search-console';
|
|
13
|
+
|
|
14
|
+
export type Resolved = { sessionId: string; tabId?: string };
|
|
15
|
+
|
|
16
|
+
export async function wait(ms: number): Promise<void> {
|
|
17
|
+
return new Promise((r) => setTimeout(r, ms));
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export async function resolve(
|
|
21
|
+
sessionId?: string,
|
|
22
|
+
tabId?: string,
|
|
23
|
+
autoCreate = true,
|
|
24
|
+
): Promise<Resolved | { error: string }> {
|
|
25
|
+
const r = await ni.resolveSession(sessionId, autoCreate ? { url: GSC_BASE } : undefined, tabId);
|
|
26
|
+
if ('error' in r) return r;
|
|
27
|
+
return { sessionId: r.sessionId, tabId: r.tabId };
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** URL-encoded `resource_id` segment for use in any GSC URL. */
|
|
31
|
+
export function encodeProperty(property: string): string {
|
|
32
|
+
return encodeURIComponent(property);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Read the current property from the URL bar (`?resource_id=…`).
|
|
37
|
+
* Returns null if not on a GSC page or property missing.
|
|
38
|
+
*/
|
|
39
|
+
export async function currentProperty(r: Resolved): Promise<string | null> {
|
|
40
|
+
const res = await ni.evaluate(
|
|
41
|
+
r.sessionId,
|
|
42
|
+
`(() => { const u = new URL(location.href); return u.searchParams.get('resource_id'); })()`,
|
|
43
|
+
r.tabId,
|
|
44
|
+
);
|
|
45
|
+
if (res.error) return null;
|
|
46
|
+
return (res.result as string | null) || null;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Build a GSC URL for `path` keeping the active `resource_id` in the query.
|
|
51
|
+
* Pass an explicit `property` to override.
|
|
52
|
+
*/
|
|
53
|
+
export async function gscUrl(r: Resolved, path: string, property?: string): Promise<string> {
|
|
54
|
+
const prop = property || (await currentProperty(r)) || '';
|
|
55
|
+
const sep = path.includes('?') ? '&' : '?';
|
|
56
|
+
return `${GSC_BASE}${path}${prop ? `${sep}resource_id=${encodeProperty(prop)}` : ''}`;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Verify session is on accounts.google.com — caller must be signed in.
|
|
61
|
+
* Returns error string if redirected to login, otherwise null.
|
|
62
|
+
*/
|
|
63
|
+
export async function ensureAuth(r: Resolved): Promise<string | null> {
|
|
64
|
+
const res = await ni.evaluate(r.sessionId, `location.href`, r.tabId);
|
|
65
|
+
const url = String(res.result || '');
|
|
66
|
+
if (/accounts\.google\.com/.test(url)) {
|
|
67
|
+
return 'Not authenticated. Sign into the Google account that owns the GSC property in the open browser, then retry.';
|
|
68
|
+
}
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Poll a JS predicate every `interval` ms until it returns truthy.
|
|
74
|
+
* `script` MUST evaluate to JSON-serializable value; truthy → success,
|
|
75
|
+
* `null`/`undefined`/`false` → keep polling. Returns last value or null on timeout.
|
|
76
|
+
*/
|
|
77
|
+
export async function pollFor<T = unknown>(
|
|
78
|
+
r: Resolved,
|
|
79
|
+
script: string,
|
|
80
|
+
timeoutMs = 30000,
|
|
81
|
+
interval = 400,
|
|
82
|
+
): Promise<T | null> {
|
|
83
|
+
const start = Date.now();
|
|
84
|
+
let last: T | null = null;
|
|
85
|
+
while (Date.now() - start < timeoutMs) {
|
|
86
|
+
const res = await ni.evaluate(r.sessionId, script, r.tabId);
|
|
87
|
+
if (!res.error) {
|
|
88
|
+
const v = res.result as T;
|
|
89
|
+
if (v) return v;
|
|
90
|
+
last = v;
|
|
91
|
+
}
|
|
92
|
+
await wait(interval);
|
|
93
|
+
}
|
|
94
|
+
return last;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// ── Locale-tolerant label dictionary ─────────────────────────────
|
|
98
|
+
// Lists per-locale forms for canonical metric keys. Used by metricRegex and
|
|
99
|
+
// readMetricTileScript to recognise GSC labels in en + pt-BR without ad-hoc
|
|
100
|
+
// alternations scattered through every handler.
|
|
101
|
+
|
|
102
|
+
export const LOCALE_LABELS: Record<string, string[]> = {
|
|
103
|
+
totalClicks: ['Total clicks', 'Total de cliques', 'Cliques totais', 'Cliques'],
|
|
104
|
+
totalImpressions: ['Total impressions', 'Total de impressões', 'Impressões totais', 'Impressões'],
|
|
105
|
+
avgCTR: ['Average CTR', 'CTR médio', 'CTR média'],
|
|
106
|
+
avgPosition: ['Average position', 'Posição média'],
|
|
107
|
+
indexed: ['Pages indexed', 'Páginas indexadas', 'Indexadas', 'Indexados', 'Indexed'],
|
|
108
|
+
notIndexed: ['Pages not indexed', 'Páginas não indexadas', 'Não indexadas', 'Não indexados', 'Not indexed'],
|
|
109
|
+
valid: ['Valid', 'Válido', 'Válidos', 'Válidas', 'Itens válidos', 'Entidades válidas'],
|
|
110
|
+
warnings: ['Warning', 'Warnings', 'Aviso', 'Avisos'],
|
|
111
|
+
errors: ['Error', 'Errors', 'Erro', 'Erros', 'Entidades inválidas'],
|
|
112
|
+
good: ['Good URLs', 'Good', 'Boas', 'Bons', 'URLs boas'],
|
|
113
|
+
needsImprovement: [
|
|
114
|
+
'Need improvement',
|
|
115
|
+
'Needs improvement',
|
|
116
|
+
'Precisa de melhorias',
|
|
117
|
+
'Precisam de melhorias',
|
|
118
|
+
'Melhorias necessárias',
|
|
119
|
+
],
|
|
120
|
+
poor: ['Poor URLs', 'Poor', 'Ruins'],
|
|
121
|
+
httpsUrls: ['HTTPS URLs', 'HTTPS'],
|
|
122
|
+
nonHttpsUrls: ['Non-HTTPS URLs', 'Non HTTPS', 'Não HTTPS', 'HTTP'],
|
|
123
|
+
totalRequests: [
|
|
124
|
+
'Total crawl requests',
|
|
125
|
+
'Total de solicitações de rastreamento',
|
|
126
|
+
'Solicitações de rastreamento',
|
|
127
|
+
'Crawl requests',
|
|
128
|
+
],
|
|
129
|
+
totalDownloadSize: ['Total download size', 'Tamanho total do download'],
|
|
130
|
+
avgResponseTime: ['Average response time', 'Tempo médio de resposta'],
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
function escapeRegex(s: string): string {
|
|
134
|
+
return s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** Build a single combined regex (case-insensitive) matching any locale form for `key`. */
|
|
138
|
+
export function metricRegex(key: keyof typeof LOCALE_LABELS | string): RegExp {
|
|
139
|
+
const list = LOCALE_LABELS[key] || [];
|
|
140
|
+
if (list.length === 0) return /(?!)/;
|
|
141
|
+
// Sort longest-first so multi-word labels match before single-word substrings.
|
|
142
|
+
const alt = [...list].sort((a, b) => b.length - a.length).map(escapeRegex).join('|');
|
|
143
|
+
return new RegExp(alt, 'i');
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Build a JS source string that finds a metric tile by label and returns
|
|
148
|
+
* the FIRST numeric value within the tile (not all numbers in the parent).
|
|
149
|
+
*
|
|
150
|
+
* The tile is detected by walking up from the matched label node to the
|
|
151
|
+
* smallest ancestor that also contains a numeric child — which mirrors the
|
|
152
|
+
* GSC metric-card structure (label + big number stacked).
|
|
153
|
+
*/
|
|
154
|
+
export function readMetricTileScript(key: keyof typeof LOCALE_LABELS | string): string {
|
|
155
|
+
const list = LOCALE_LABELS[key] || [];
|
|
156
|
+
const alt = [...list].sort((a, b) => b.length - a.length).map(escapeRegex).join('|');
|
|
157
|
+
if (!alt) return `(() => null)()`;
|
|
158
|
+
return `(() => {
|
|
159
|
+
const re = new RegExp(${JSON.stringify(alt)}, 'i');
|
|
160
|
+
const exact = new RegExp('^\\\\s*(?:' + ${JSON.stringify(alt)} + ')\\\\s*[::]?\\\\s*$', 'i');
|
|
161
|
+
const numRe = /-?\\d[\\d.,]*\\s*%?/;
|
|
162
|
+
const candidates = Array.from(document.querySelectorAll('div, span, p, dt, label, h2, h3, td, th'));
|
|
163
|
+
// Prefer exact-match label nodes (e.g. "Total de cliques") to avoid grabbing
|
|
164
|
+
// body paragraphs that mention the term in passing.
|
|
165
|
+
const labels = candidates.filter(n => exact.test((n.textContent || '').trim()));
|
|
166
|
+
const fallback = candidates.filter(n => re.test(n.textContent || ''));
|
|
167
|
+
const nodes = labels.length ? labels : fallback.slice(0, 6);
|
|
168
|
+
for (const node of nodes) {
|
|
169
|
+
let cur = node;
|
|
170
|
+
for (let depth = 0; cur && depth < 6; depth++, cur = cur.parentElement) {
|
|
171
|
+
const txt = (cur.innerText || cur.textContent || '');
|
|
172
|
+
if (re.test(txt) && numRe.test(txt)) {
|
|
173
|
+
// Strip the label so we don't pick up digits inside it.
|
|
174
|
+
const stripped = txt.replace(re, ' ');
|
|
175
|
+
const m = stripped.match(numRe);
|
|
176
|
+
if (m) return m[0].trim();
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
return null;
|
|
181
|
+
})()`;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Extract a GSC accessibility-tree grid as `{ headers, rows }`.
|
|
186
|
+
* `scopeSelector` should target a `[role="grid"]` or its container.
|
|
187
|
+
*
|
|
188
|
+
* - Strips nested tooltip/icon text from header cells (GSC often inlines a
|
|
189
|
+
* help-icon tooltip into the column header textContent).
|
|
190
|
+
* - Header fallback: when no `[role="columnheader"]`/`th` exists, treats the
|
|
191
|
+
* first body row as the header row (some report tables are pure tr-based).
|
|
192
|
+
* - List fallback: when no grid/table is found, attempts to extract rows from
|
|
193
|
+
* `[role="listitem"]`/`mat-list-item`/`li` cards in the scope.
|
|
194
|
+
*/
|
|
195
|
+
export const TABLE_EXTRACTOR_SCRIPT = (scope: string) =>
|
|
196
|
+
`(() => {
|
|
197
|
+
const root = document.querySelector(${JSON.stringify(scope)}) || document;
|
|
198
|
+
const stripText = (el) => {
|
|
199
|
+
if (!el) return '';
|
|
200
|
+
const clone = el.cloneNode(true);
|
|
201
|
+
// Remove tooltip/help-icon clutter that GSC inlines into header cells.
|
|
202
|
+
clone.querySelectorAll('[role="tooltip"], [aria-hidden="true"], .material-icons, .material-icons-extended, .material-icons-outlined, mat-icon, .mdc-tooltip, [class*="tooltip" i], [class*="help-icon" i], [class*="help_outline" i], [data-md-tooltip], gmat-tooltip, gmat-help').forEach(n => n.remove());
|
|
203
|
+
return (clone.textContent || '').trim().replace(/\\s+/g,' ');
|
|
204
|
+
};
|
|
205
|
+
// Prefer aria-label on a columnheader/cell when it exists — it's the
|
|
206
|
+
// canonical column name without inlined tooltip body text.
|
|
207
|
+
const ariaOrText = (el) => {
|
|
208
|
+
if (!el) return '';
|
|
209
|
+
const al = el.getAttribute('aria-label');
|
|
210
|
+
if (al && al.trim() && al.length < 80) return al.trim().replace(/\\s+/g, ' ');
|
|
211
|
+
return stripText(el);
|
|
212
|
+
};
|
|
213
|
+
const grid = root.matches?.('[role="grid"],[role="table"],table') ? root : root.querySelector('[role="grid"],[role="table"],table');
|
|
214
|
+
if (grid) {
|
|
215
|
+
let headers = [];
|
|
216
|
+
const headerRow = grid.querySelector('[role="row"]:has([role="columnheader"]), thead tr');
|
|
217
|
+
if (headerRow) {
|
|
218
|
+
headers = Array.from(headerRow.querySelectorAll('[role="columnheader"], th')).map(ariaOrText);
|
|
219
|
+
}
|
|
220
|
+
let bodyRows = Array.from(grid.querySelectorAll('[role="row"]:not(:has([role="columnheader"])), tbody tr'));
|
|
221
|
+
if (bodyRows.length === 0) bodyRows = Array.from(grid.querySelectorAll('[role="row"], tr'));
|
|
222
|
+
// Header fallback: if no columnheader row, promote the first body row.
|
|
223
|
+
if (headers.length === 0 && bodyRows.length > 0) {
|
|
224
|
+
const first = bodyRows[0];
|
|
225
|
+
headers = Array.from(first.querySelectorAll('[role="gridcell"], [role="cell"], td, th, [role="columnheader"]')).map(stripText);
|
|
226
|
+
bodyRows = bodyRows.slice(1);
|
|
227
|
+
}
|
|
228
|
+
const rows = bodyRows.map(tr => {
|
|
229
|
+
const cells = Array.from(tr.querySelectorAll('[role="gridcell"], [role="cell"], td')).map(stripText);
|
|
230
|
+
const link = tr.querySelector('a[href]')?.href || null;
|
|
231
|
+
const obj = {};
|
|
232
|
+
cells.forEach((v, i) => { obj[headers[i] || ('col' + i)] = v; });
|
|
233
|
+
if (link && link !== 'https://search.google.com/#') obj.url = link;
|
|
234
|
+
// Drop rows that just echo the header labels (some grids re-render
|
|
235
|
+
// the header inside the body when no data rows exist).
|
|
236
|
+
const isHeaderEcho = headers.length > 0 && Object.values(obj).every(v =>
|
|
237
|
+
!v || (headers.some(h => h && String(v).trim() === String(h).trim())));
|
|
238
|
+
if (isHeaderEcho) return null;
|
|
239
|
+
return obj;
|
|
240
|
+
}).filter(r => r && Object.values(r).some(v => v && String(v).trim()));
|
|
241
|
+
return { headers, rows };
|
|
242
|
+
}
|
|
243
|
+
// List fallback (e.g. Users page renders mat-list cards instead of a grid).
|
|
244
|
+
const items = Array.from(root.querySelectorAll('[role="listitem"], mat-list-item, li'));
|
|
245
|
+
if (items.length === 0) return null;
|
|
246
|
+
const rows = items.map(li => {
|
|
247
|
+
const text = stripText(li);
|
|
248
|
+
const link = li.querySelector('a[href]')?.href || null;
|
|
249
|
+
const obj = { text };
|
|
250
|
+
if (link) obj.url = link;
|
|
251
|
+
return obj;
|
|
252
|
+
}).filter(r => r.text && r.text.length > 0 && r.text.length < 400);
|
|
253
|
+
return rows.length > 0 ? { headers: [], rows } : null;
|
|
254
|
+
})()`;
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Navigate with a one-time retry on Playwright timeout. GSC's first paint
|
|
258
|
+
* occasionally exceeds the underlying 15s `domcontentloaded` budget; a
|
|
259
|
+
* second attempt almost always succeeds.
|
|
260
|
+
*/
|
|
261
|
+
export async function safeNavigate(r: Resolved, url: string): Promise<{ error?: string }> {
|
|
262
|
+
let res = await ni.navigate(r.sessionId, url, r.tabId);
|
|
263
|
+
if (res.error && /Timeout/i.test(res.error)) {
|
|
264
|
+
await wait(500);
|
|
265
|
+
res = await ni.navigate(r.sessionId, url, r.tabId);
|
|
266
|
+
}
|
|
267
|
+
return res;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/** Click a sidebar nav item by its material-icon ligature (locale-independent). */
|
|
271
|
+
export async function clickSidebarIcon(r: Resolved, iconText: string): Promise<{ ok: boolean; error?: string }> {
|
|
272
|
+
const res = await ni.evaluate(
|
|
273
|
+
r.sessionId,
|
|
274
|
+
`(() => {
|
|
275
|
+
const els = Array.from(document.querySelectorAll('.material-icons, .material-icons-extended, [class*="icon"]'));
|
|
276
|
+
for (const el of els) {
|
|
277
|
+
if (el.textContent.trim() === ${JSON.stringify(iconText)}) {
|
|
278
|
+
const link = el.closest('a, [role="link"], [role="button"], button');
|
|
279
|
+
if (link) { link.click(); return true; }
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
return false;
|
|
283
|
+
})()`,
|
|
284
|
+
r.tabId,
|
|
285
|
+
);
|
|
286
|
+
if (res.error) return { ok: false, error: res.error };
|
|
287
|
+
return { ok: !!res.result };
|
|
288
|
+
}
|