An agentic browser harness: an AI side panel & orb in your own logged-in Chrome, Edge, Arc, Brave or even Firefox run by the agent/subscription you already use (Claude Code, Codex, Antigravity). Free, open source, no API key. Also an MCP server.
TypeScript agentic-browseragentic-browsingagy-cliaiai-agentai-browser-extensionai-toolsbrave-extensionbrowser-agentbrowser-automationbrowser-extensionbrowser-usebrowserskillchrome-extensionclaude-codecodexfirefox-addonmcp-servernanobrowserweb-automation
refactor(skills): share scrub and looksLikeInstruction with a new validator
Shahriara54a1dc39c6d
diff --git a/lib/skills/scrub.ts b/lib/skills/scrub.tsnew file mode 100644index 0000000..d6b85af--- /dev/null+++ b/lib/skills/scrub.ts@@ -0,0 +1,34 @@+const CONTROL_CHARS = new RegExp(+ '[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f\\u200b-\\u200f\\u202a-\\u202e\\u2066-\\u2069\\ufeff]',+ 'g',+);++export const SELECTOR_RE = /^[a-zA-Z0-9 .#>+~*,_:[\]="'()-]{1,120}$/;++export const MAX_SELECTOR_PARTS = 8;++export function scrub(value: unknown, limit: number): string {+ if (typeof value !== 'string') return '';+ return value+ .replace(/[\r\n\t]+/g, ' ')+ .replace(CONTROL_CHARS, '')+ .replace(/^[\s#>*\-+|`~=]+/, '')+ .replace(/[`|]/g, '')+ .replace(/\s+/g, ' ')+ .trim()+ .slice(0, limit);+}++export function looksLikeInstruction(text: string): boolean {+ return /\b(?:ignore (?:all |any )?previous|disregard (?:the |all )?(?:above|previous)|you (?:must|should|will) (?:now|always|never)|instead(?:,)? (?:navigate|go|send|email|transfer|click)|do not tell|without asking|system prompt|new instructions?)\b/i.test(+ text,+ );+}++export function looksLikeSelector(value: string): boolean {+ return SELECTOR_RE.test(value) && value.trim().split(/\s+/).length <= MAX_SELECTOR_PARTS;+}++export function clip(text: string, limit: number): string {+ return text.length > limit ? `${text.slice(0, limit - 1)}…` : text;+}diff --git a/lib/skills/site-map.ts b/lib/skills/site-map.tsindex eb02c62..9dc2f4f 100644--- a/lib/skills/site-map.ts+++ b/lib/skills/site-map.ts@@ -1,4 +1,7 @@import { byteLength, isDomain } from './format';+import { clip, looksLikeSelector, scrub, looksLikeInstruction } from './scrub';++export { scrub, looksLikeInstruction };export const SITE_MAPPER_SKILL = 'site-mapper';@@ -25,14 +28,6 @@ export const FIELD_LIMITS = {notes: 200,} as const;-const SELECTOR_RE = /^[a-zA-Z0-9 .#>+~*,_:[\]="'()-]{1,120}$/;--const MAX_SELECTOR_PARTS = 8;--function looksLikeSelector(value: string): boolean {- return SELECTOR_RE.test(value) && value.trim().split(/\s+/).length <= MAX_SELECTOR_PARTS;-}-export interface SiteMapReport {summary: string;landmarks: { name: string; selector: string; note?: string }[];@@ -125,24 +120,6 @@ export function validateSiteMapReport(return { ok: true, report, warnings };}-export function scrub(value: unknown, limit: number): string {- if (typeof value !== 'string') return '';- return value- .replace(/[\r\n\t]+/g, ' ')- .replace(/[\u0000-\u0008\u000b-\u001f\u007f-\u009f\u200b-\u200f\u202a-\u202e\u2066-\u2069\ufeff]/g, '')- .replace(/^[\s#>*\-+|`~=]+/, '')- .replace(/[`|]/g, '')- .replace(/\s+/g, ' ')- .trim()- .slice(0, limit);-}--export function looksLikeInstruction(text: string): boolean {- return /\b(?:ignore (?:all |any )?previous|disregard (?:the |all )?(?:above|previous)|you (?:must|should|will) (?:now|always|never)|instead(?:,)? (?:navigate|go|send|email|transfer|click)|do not tell|without asking|system prompt|new instructions?)\b/i.test(- text,- );-}-function samePath(value: unknown, origin: string): string {if (typeof value !== 'string' || !value.trim()) return '';try {@@ -202,10 +179,6 @@ function trimToBudget(report: SiteMapReport, warnings: string[]): void {if (report.pages.length === 1) warnings.push('Only the first page fitted in the map.');}-function clip(text: string, limit: number): string {- return text.length > limit ? `${text.slice(0, limit - 1)}…` : text;-}-export function isMappableHost(host: string): boolean {return isDomain(host);}