@weavetab/mcp 2.5.0-beta.0

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 (281) hide show
  1. package/AGENTS.md +48 -0
  2. package/ARCHITECTURE.md +590 -0
  3. package/LICENSE +631 -0
  4. package/README.md +909 -0
  5. package/SECURITY.md +196 -0
  6. package/TROUBLESHOOTING.md +365 -0
  7. package/dist/anticaptcha/detector.d.ts +49 -0
  8. package/dist/anticaptcha/detector.js +465 -0
  9. package/dist/anticaptcha/integration.d.ts +36 -0
  10. package/dist/anticaptcha/integration.js +123 -0
  11. package/dist/anticaptcha/solver.d.ts +27 -0
  12. package/dist/anticaptcha/solver.js +552 -0
  13. package/dist/audit/logger.d.ts +13 -0
  14. package/dist/audit/logger.js +177 -0
  15. package/dist/audit/telemetry.d.ts +36 -0
  16. package/dist/audit/telemetry.js +162 -0
  17. package/dist/cdp/bridge.d.ts +16 -0
  18. package/dist/cdp/bridge.js +826 -0
  19. package/dist/cdp/confirm.d.ts +26 -0
  20. package/dist/cdp/confirm.js +79 -0
  21. package/dist/cdp/connector.d.ts +37 -0
  22. package/dist/cdp/connector.js +661 -0
  23. package/dist/cdp/extension.d.ts +36 -0
  24. package/dist/cdp/extension.js +118 -0
  25. package/dist/cdp/finder.d.ts +1 -0
  26. package/dist/cdp/finder.js +2 -0
  27. package/dist/cdp/helpers.d.ts +11 -0
  28. package/dist/cdp/helpers.js +195 -0
  29. package/dist/cdp/label_cache.d.ts +12 -0
  30. package/dist/cdp/label_cache.js +51 -0
  31. package/dist/cdp/lock.d.ts +33 -0
  32. package/dist/cdp/lock.js +206 -0
  33. package/dist/cdp/omni_broker.d.ts +17 -0
  34. package/dist/cdp/omni_broker.js +119 -0
  35. package/dist/cdp/profiles.d.ts +1 -0
  36. package/dist/cdp/profiles.js +87 -0
  37. package/dist/cdp/pruner.d.ts +41 -0
  38. package/dist/cdp/pruner.js +263 -0
  39. package/dist/cdp/ref_cache.d.ts +101 -0
  40. package/dist/cdp/ref_cache.js +234 -0
  41. package/dist/cdp/retry.d.ts +5 -0
  42. package/dist/cdp/retry.js +39 -0
  43. package/dist/cdp/retry_enhanced.d.ts +44 -0
  44. package/dist/cdp/retry_enhanced.js +102 -0
  45. package/dist/cdp/security.d.ts +50 -0
  46. package/dist/cdp/security.js +237 -0
  47. package/dist/cdp/verify.d.ts +39 -0
  48. package/dist/cdp/verify.js +143 -0
  49. package/dist/cdp/walker.d.ts +91 -0
  50. package/dist/cdp/walker.js +896 -0
  51. package/dist/cdp/walker.test.d.ts +2 -0
  52. package/dist/cdp/walker.test.js +172 -0
  53. package/dist/cdp/websocket_transport.d.ts +15 -0
  54. package/dist/cdp/websocket_transport.js +118 -0
  55. package/dist/cli/plugin.d.ts +9 -0
  56. package/dist/cli/plugin.js +1134 -0
  57. package/dist/cli/updater.d.ts +1 -0
  58. package/dist/cli/updater.js +72 -0
  59. package/dist/config/loader.d.ts +120 -0
  60. package/dist/config/loader.js +704 -0
  61. package/dist/index.d.ts +2 -0
  62. package/dist/index.js +1248 -0
  63. package/dist/intelligence/hints.d.ts +11 -0
  64. package/dist/intelligence/hints.js +39 -0
  65. package/dist/intelligence/intent.d.ts +33 -0
  66. package/dist/intelligence/intent.js +171 -0
  67. package/dist/intelligence/sessionMemory.d.ts +66 -0
  68. package/dist/intelligence/sessionMemory.js +284 -0
  69. package/dist/intelligence/sessionMemory.test.d.ts +2 -0
  70. package/dist/intelligence/sessionMemory.test.js +62 -0
  71. package/dist/intelligence/trail.d.ts +64 -0
  72. package/dist/intelligence/trail.js +233 -0
  73. package/dist/intelligence/trail.test.d.ts +2 -0
  74. package/dist/intelligence/trail.test.js +110 -0
  75. package/dist/intelligence/vision.d.ts +24 -0
  76. package/dist/intelligence/vision.js +151 -0
  77. package/dist/lifecycle/mission_manager.d.ts +16 -0
  78. package/dist/lifecycle/mission_manager.js +44 -0
  79. package/dist/overlay/bubble.d.ts +16 -0
  80. package/dist/overlay/bubble.js +37 -0
  81. package/dist/overlay/ghost.d.ts +35 -0
  82. package/dist/overlay/ghost.js +508 -0
  83. package/dist/overlay/injector.d.ts +22 -0
  84. package/dist/overlay/injector.js +198 -0
  85. package/dist/plugin/interface.d.ts +134 -0
  86. package/dist/plugin/interface.js +1 -0
  87. package/dist/plugin/loader.d.ts +18 -0
  88. package/dist/plugin/loader.js +155 -0
  89. package/dist/plugin/registry.d.ts +50 -0
  90. package/dist/plugin/registry.js +234 -0
  91. package/dist/security/blacklist.d.ts +24 -0
  92. package/dist/security/blacklist.js +80 -0
  93. package/dist/security/filter.d.ts +2 -0
  94. package/dist/security/filter.js +20 -0
  95. package/dist/security/guard.d.ts +8 -0
  96. package/dist/security/guard.js +35 -0
  97. package/dist/security/ratelimit.d.ts +11 -0
  98. package/dist/security/ratelimit.js +57 -0
  99. package/dist/security/secrets.d.ts +75 -0
  100. package/dist/security/secrets.js +365 -0
  101. package/dist/sensors/actionability.d.ts +81 -0
  102. package/dist/sensors/actionability.js +303 -0
  103. package/dist/sensors/guard.d.ts +25 -0
  104. package/dist/sensors/guard.js +168 -0
  105. package/dist/sensors/mutations.d.ts +23 -0
  106. package/dist/sensors/mutations.js +93 -0
  107. package/dist/sensors/network.d.ts +67 -0
  108. package/dist/sensors/network.js +193 -0
  109. package/dist/sensors/operation_monitor.d.ts +80 -0
  110. package/dist/sensors/operation_monitor.js +203 -0
  111. package/dist/sensors/pacing.d.ts +44 -0
  112. package/dist/sensors/pacing.js +111 -0
  113. package/dist/sensors/thoughts.d.ts +2 -0
  114. package/dist/sensors/thoughts.js +59 -0
  115. package/dist/sensors/wait.d.ts +12 -0
  116. package/dist/sensors/wait.js +44 -0
  117. package/dist/server.d.ts +7 -0
  118. package/dist/server.js +1687 -0
  119. package/dist/state/agent.d.ts +36 -0
  120. package/dist/state/agent.js +101 -0
  121. package/dist/state/cache.d.ts +16 -0
  122. package/dist/state/cache.js +92 -0
  123. package/dist/state/cache.test.d.ts +2 -0
  124. package/dist/state/cache.test.js +76 -0
  125. package/dist/state/delta.d.ts +71 -0
  126. package/dist/state/delta.js +234 -0
  127. package/dist/state/delta.test.d.ts +2 -0
  128. package/dist/state/delta.test.js +279 -0
  129. package/dist/state/groups.d.ts +15 -0
  130. package/dist/state/groups.js +80 -0
  131. package/dist/state/session.d.ts +30 -0
  132. package/dist/state/session.js +155 -0
  133. package/dist/tools/accessibility.d.ts +14 -0
  134. package/dist/tools/accessibility.js +32 -0
  135. package/dist/tools/ask.d.ts +14 -0
  136. package/dist/tools/ask.js +49 -0
  137. package/dist/tools/automation.d.ts +36 -0
  138. package/dist/tools/automation.js +218 -0
  139. package/dist/tools/browser_detect.d.ts +13 -0
  140. package/dist/tools/browser_detect.js +73 -0
  141. package/dist/tools/burst.d.ts +35 -0
  142. package/dist/tools/burst.js +344 -0
  143. package/dist/tools/canvas.d.ts +25 -0
  144. package/dist/tools/canvas.js +132 -0
  145. package/dist/tools/captcha.d.ts +38 -0
  146. package/dist/tools/captcha.js +209 -0
  147. package/dist/tools/click.d.ts +36 -0
  148. package/dist/tools/click.js +561 -0
  149. package/dist/tools/click_and_wait.d.ts +33 -0
  150. package/dist/tools/click_and_wait.js +149 -0
  151. package/dist/tools/clipboard.d.ts +29 -0
  152. package/dist/tools/clipboard.js +279 -0
  153. package/dist/tools/console.d.ts +21 -0
  154. package/dist/tools/console.js +107 -0
  155. package/dist/tools/cookies.d.ts +67 -0
  156. package/dist/tools/cookies.js +121 -0
  157. package/dist/tools/design_extract.d.ts +109 -0
  158. package/dist/tools/design_extract.js +641 -0
  159. package/dist/tools/dialog.d.ts +24 -0
  160. package/dist/tools/dialog.js +109 -0
  161. package/dist/tools/drag.d.ts +15 -0
  162. package/dist/tools/drag.js +29 -0
  163. package/dist/tools/emulation.d.ts +33 -0
  164. package/dist/tools/emulation.js +69 -0
  165. package/dist/tools/eval.d.ts +20 -0
  166. package/dist/tools/eval.js +92 -0
  167. package/dist/tools/fill.d.ts +41 -0
  168. package/dist/tools/fill.js +667 -0
  169. package/dist/tools/find.d.ts +30 -0
  170. package/dist/tools/find.js +60 -0
  171. package/dist/tools/geo.d.ts +19 -0
  172. package/dist/tools/geo.js +29 -0
  173. package/dist/tools/github/analyze.d.ts +4 -0
  174. package/dist/tools/github/analyze.js +113 -0
  175. package/dist/tools/github/cache.d.ts +21 -0
  176. package/dist/tools/github/cache.js +28 -0
  177. package/dist/tools/github/index.d.ts +4 -0
  178. package/dist/tools/github/index.js +4 -0
  179. package/dist/tools/github/issues.d.ts +9 -0
  180. package/dist/tools/github/issues.js +88 -0
  181. package/dist/tools/github/pr.d.ts +5 -0
  182. package/dist/tools/github/pr.js +88 -0
  183. package/dist/tools/github/rateLimiter.d.ts +4 -0
  184. package/dist/tools/github/rateLimiter.js +46 -0
  185. package/dist/tools/github/read.d.ts +34 -0
  186. package/dist/tools/github/read.js +74 -0
  187. package/dist/tools/github/repoContext.d.ts +20 -0
  188. package/dist/tools/github/repoContext.js +129 -0
  189. package/dist/tools/highlight.d.ts +20 -0
  190. package/dist/tools/highlight.js +140 -0
  191. package/dist/tools/hover.d.ts +19 -0
  192. package/dist/tools/hover.js +57 -0
  193. package/dist/tools/inspect.d.ts +17 -0
  194. package/dist/tools/inspect.js +125 -0
  195. package/dist/tools/integration.test.d.ts +2 -0
  196. package/dist/tools/integration.test.js +96 -0
  197. package/dist/tools/key.d.ts +25 -0
  198. package/dist/tools/key.js +173 -0
  199. package/dist/tools/macro_compiler.d.ts +7 -0
  200. package/dist/tools/macro_compiler.js +82 -0
  201. package/dist/tools/mouse.d.ts +21 -0
  202. package/dist/tools/mouse.js +62 -0
  203. package/dist/tools/navigate.d.ts +16 -0
  204. package/dist/tools/navigate.js +188 -0
  205. package/dist/tools/network_intercept.d.ts +17 -0
  206. package/dist/tools/network_intercept.js +151 -0
  207. package/dist/tools/office/index.d.ts +9 -0
  208. package/dist/tools/office/index.js +7 -0
  209. package/dist/tools/office/list.d.ts +15 -0
  210. package/dist/tools/office/list.js +41 -0
  211. package/dist/tools/office/parse.d.ts +20 -0
  212. package/dist/tools/office/parse.js +172 -0
  213. package/dist/tools/pdf.d.ts +22 -0
  214. package/dist/tools/pdf.js +42 -0
  215. package/dist/tools/performance.d.ts +12 -0
  216. package/dist/tools/performance.js +47 -0
  217. package/dist/tools/performance_test.d.ts +70 -0
  218. package/dist/tools/performance_test.js +128 -0
  219. package/dist/tools/plan.d.ts +39 -0
  220. package/dist/tools/plan.js +161 -0
  221. package/dist/tools/pointer.d.ts +35 -0
  222. package/dist/tools/pointer.js +522 -0
  223. package/dist/tools/read.d.ts +30 -0
  224. package/dist/tools/read.js +488 -0
  225. package/dist/tools/recording.d.ts +45 -0
  226. package/dist/tools/recording.js +124 -0
  227. package/dist/tools/response.d.ts +129 -0
  228. package/dist/tools/response.js +5 -0
  229. package/dist/tools/scrape.d.ts +24 -0
  230. package/dist/tools/scrape.js +140 -0
  231. package/dist/tools/screenshot.d.ts +40 -0
  232. package/dist/tools/screenshot.js +79 -0
  233. package/dist/tools/scroll.d.ts +23 -0
  234. package/dist/tools/scroll.js +196 -0
  235. package/dist/tools/select.d.ts +13 -0
  236. package/dist/tools/select.js +217 -0
  237. package/dist/tools/snapshot.d.ts +27 -0
  238. package/dist/tools/snapshot.js +99 -0
  239. package/dist/tools/storage.d.ts +18 -0
  240. package/dist/tools/storage.js +29 -0
  241. package/dist/tools/tabs.d.ts +77 -0
  242. package/dist/tools/tabs.js +342 -0
  243. package/dist/tools/thought.d.ts +16 -0
  244. package/dist/tools/thought.js +79 -0
  245. package/dist/tools/type.d.ts +65 -0
  246. package/dist/tools/type.js +1061 -0
  247. package/dist/tools/type_secret.d.ts +23 -0
  248. package/dist/tools/type_secret.js +229 -0
  249. package/dist/tools/upload.d.ts +19 -0
  250. package/dist/tools/upload.js +103 -0
  251. package/dist/tools/video_compiler.d.ts +24 -0
  252. package/dist/tools/video_compiler.js +199 -0
  253. package/dist/tools/viewport.d.ts +44 -0
  254. package/dist/tools/viewport.js +230 -0
  255. package/dist/tools/wait.d.ts +19 -0
  256. package/dist/tools/wait.js +202 -0
  257. package/dist/tools/wait_for.d.ts +23 -0
  258. package/dist/tools/wait_for.js +30 -0
  259. package/dist/tools/windows.d.ts +22 -0
  260. package/dist/tools/windows.js +57 -0
  261. package/dist/ui/index.d.ts +1 -0
  262. package/dist/ui/index.js +12 -0
  263. package/docs/DEV_MODE.md +68 -0
  264. package/docs/DOCUMENTATION.md +532 -0
  265. package/docs/PLUGINS.md +538 -0
  266. package/docs/TOOLS.md +104 -0
  267. package/docs/dev_plugin.md +310 -0
  268. package/ext-dist/background.js +467 -0
  269. package/ext-dist/content.js +3089 -0
  270. package/ext-dist/dashboard.html +583 -0
  271. package/ext-dist/hud/hud.js +73 -0
  272. package/ext-dist/hud/index.html +20 -0
  273. package/ext-dist/manifest.json +77 -0
  274. package/ext-dist/sidepanel/sidepanel.js +25 -0
  275. package/ext-dist/sidepanel.html +547 -0
  276. package/ext-dist/styles.css +218 -0
  277. package/icon.png +0 -0
  278. package/mcp.json +796 -0
  279. package/package.json +113 -0
  280. package/server.json +23 -0
  281. package/smithery.yaml +11 -0
package/AGENTS.md ADDED
@@ -0,0 +1,48 @@
1
+ # Weavetab MCP — AI Agent Developer Guide
2
+
3
+ This document is the universal specification for AI agents (Cursor, Antigravity, Claude Code, Copilot Workspace, Devin, OpenCode, Roo Code, Cline) contributing to or extending the Weavetab MCP server.
4
+
5
+ ---
6
+
7
+ ## Architectural Principles
8
+
9
+ 1. **Layer 0 Direct CDP**:
10
+ * Weavetab connects directly to Chrome DevTools Protocol (CDP) via WebSocket (`127.0.0.1`).
11
+ * **Do NOT introduce Puppeteer, Playwright, or Selenium wrapper abstractions**.
12
+
13
+ 2. **Deterministic State & Token Efficiency**:
14
+ * Use the **Semantic Delta Engine** for DOM snapshot diffing.
15
+ * Tool responses must return concise, actionable JSON payloads with stable DOM reference IDs (`w:NN`).
16
+
17
+ 3. **Security Constraints**:
18
+ * **Blind Injection**: Never leak credentials into LLM context. `browser_type_secret` must sanitize inputs to `[REDACTED]`.
19
+ * Enforce domain policy checks (`~/.weavetab/policy.json`) and RBAC permissions (`admin`, `system`, `viewer`, `automation`).
20
+
21
+ ---
22
+
23
+ ## Build & Test Commands
24
+
25
+ * **Build Everything**:
26
+ ```bash
27
+ npm run build
28
+ ```
29
+ * **Development Mode**:
30
+ ```bash
31
+ npm run dev
32
+ ```
33
+ * **Run Tests**:
34
+ ```bash
35
+ npm test
36
+ npm run test:unit
37
+ npm run test:e2e
38
+ ```
39
+
40
+ ---
41
+
42
+ ## Adding or Modifying MCP Tools
43
+
44
+ When adding or updating an MCP tool:
45
+ 1. Define tool input schema using `zod` in `src/`.
46
+ 2. Register the tool handler in the MCP server initialization.
47
+ 3. Update [mcp.json](file:///c:/Users/fy2ne/Music/Weavetab/MCP/mcp.json) and [server.json](file:///c:/Users/fy2ne/Music/Weavetab/MCP/server.json) metadata if tool list or capabilities change.
48
+ 4. Add unit test coverage under `tests/unit/`.
@@ -0,0 +1,590 @@
1
+ # Weavetab Architecture
2
+
3
+ > **Version:** 2.5.0 (Beta) | **Last Updated:** July 2026
4
+
5
+ ---
6
+
7
+ ## System Overview
8
+
9
+ Weavetab is an MCP (Model Context Protocol) server engineered for AI-driven browser automation. Unlike Playwright or Puppeteer, it communicates directly with Chromium via the Chrome DevTools Protocol (CDP) WebSocket — there is no WebDriver process, no browser binary download, and no heavy abstraction layer. This yields sub-10ms tool execution latency.
10
+
11
+ The system is composed of five architectural layers:
12
+
13
+
14
+
15
+ ---
16
+
17
+ ## Tool Execution Pipeline
18
+
19
+ Every tool invocation follows a deterministic pipeline:
20
+
21
+ ```mermaid
22
+ flowchart LR
23
+ Agent["AI Agent"] --> Sec["Security Guard"]
24
+ Sec --> Rate["Rate Limit Check"]
25
+ Rate --> Dom["Domain Policy"]
26
+ Dom --> RBAC["RBAC Check"]
27
+ RBAC --> Intel["Intelligence Engine"]
28
+ Intel --> CDP["CDP Execution"]
29
+ CDP --> Result["Result Return"]
30
+ ```
31
+
32
+ ### Pipeline Stages
33
+
34
+ 1. **Security Guard** — Initial rate limit check
35
+ 2. **Domain Policy** — Check domain against blacklist/policy engine
36
+ 3. **RBAC Check** — Verify role-based tool permissions
37
+ 4. **Agent State** — Report tool call, transition to 'weaving' state
38
+ 5. **Intelligence Engine** — Load domain profile, cached strategies, hints
39
+ 6. **CDP Execution** — Execute tool via Chrome DevTools Protocol
40
+ 7. **State Update** — Report success/failure, update domain profile
41
+ 8. **Return Result** — Return structured result to AI agent
42
+
43
+ ### Additional Checks
44
+
45
+ - **User stop requests** via `window.__wt_stop_requested` in overlay HUD
46
+ - **Chat queue** messages from user (`window.__wt_chat_queue`)
47
+ - **Config live-reload** via `fs.watch` on `config.json`
48
+
49
+ ---
50
+
51
+ ## Intelligence Engine
52
+
53
+ ### Session Memory
54
+
55
+ The session memory system maintains persistent per-domain profiles on disk at `~/.Weavetab/memory/`. Each profile tracks:
56
+
57
+ ```typescript
58
+ interface DomainProfile {
59
+ strategies: string[]; // Interaction strategies that succeeded
60
+ knownInputs: Array<{ // Previously discovered input selectors
61
+ label: string;
62
+ selector: string;
63
+ }>;
64
+ shadowDom: boolean; // Whether the domain uses Shadow DOM
65
+ framework?: string; // Auto-detected framework (react/vue/angular/etc.)
66
+ updatedAt: string; // ISO timestamp of last update
67
+ visitCount: number; // Total visits accumulated
68
+ }
69
+ ```
70
+
71
+ **Automatic Framework Detection** runs via `Runtime.evaluate` probes for 8 frameworks:
72
+
73
+ ```
74
+ Page Load → Check React → Check Vue → Check Angular → Check Lit
75
+ → Check Svelte → Check Next/Nuxt/Gatsby → Cache Result
76
+ ```
77
+
78
+ ### Semantic Delta Engine
79
+
80
+ The delta engine (`src/state/delta.ts`) implements a per-tab snapshot diffing system:
81
+
82
+ | Aspect | Implementation |
83
+ |--------|---------------|
84
+ | **Storage** | `Map<targetId, Map<refId, RefEntry>>` in memory |
85
+ | **Fingerprint** | `role:normalizedLabel:parentRole:depth` for stable identity |
86
+ | **Diff Output** | `{ added: [], removed: [], changed: [], stable_count: N }` |
87
+ | **Rich Delta** | Adds property-level diffs (label, value, disabled, href, className changes) |
88
+ | **Iframe Tracking** | Per-frame element counts tracked separately |
89
+ | **Actionable Recommendations** | Changed interactive elements flagged with suggested action |
90
+
91
+ **Delta Flow:**
92
+
93
+
94
+
95
+ ### Semantic DOM Pruner
96
+
97
+ The pruner (`src/cdp/pruner.ts`) performs **one-shot compression of a single DOM snapshot before it is returned to the agent**. This is fundamentally distinct from the Delta Engine:
98
+
99
+ | Dimension | Delta Engine | Semantic DOM Pruner |
100
+ |-----------|-------------|---------------------|
101
+ | **What it operates on** | Two snapshots across time | One snapshot, right now |
102
+ | **When it runs** | After the current map is built | Before the current map is returned |
103
+ | **Output** | Added / removed / changed elements | Compressed element list |
104
+ | **Activation** | `browser_map({ delta: true })` | `browser_map({ prune: true })` |
105
+ | **Combine?** | Yes — delta of a pruned snapshot gives maximum token efficiency |
106
+
107
+ **Implementation Details:**
108
+
109
+ | Aspect | Detail |
110
+ |--------|--------|
111
+ | **Execution** | 1 `Runtime.evaluate` call (2 if page exceeds perf gate) |
112
+ | **Performance target** | p95 < 5ms on Jira/AWS-scale DOMs |
113
+ | **Pass 1 — controlsMap** | Collects all `aria-controls`, `aria-owns`, `data-target` values |
114
+ | **Pass 2 — subtree annotation** | Bottom-up walk, computes `hasInteractiveDescendant` per node |
115
+ | **Pass 3 — prune decision** | Keep if: visible OR has interactive descendant OR in controlsMap |
116
+ | **SVG handling** | Resolves label from: svg `aria-label` → svg `<title>` → ancestor `aria-label` |
117
+ | **Secret safety** | `data-wt-secret` guard fires on the attribute, not the id |
118
+
119
+ ### Loop Detection and Trail System
120
+
121
+ The trail module (`src/intelligence/trail.ts`) maintains a rolling window of the last 50 tool actions. It implements strike-based loop detection:
122
+
123
+ ```
124
+ Loop Detection Algorithm
125
+ ─────────────────────────
126
+ Input: tool name, element ref
127
+ Process: Scan trail backwards, count consecutive failures
128
+ matching same tool + ref
129
+
130
+ strikes < 5 → severity: "none"
131
+ strikes 5-9 → severity: "warning" (HUD notification)
132
+ strikes >= 10 → severity: "critical" (state → "stuck", recovery triggered)
133
+ ```
134
+
135
+ **Auto-reset Triggers:**
136
+ - Navigation events
137
+ - Tab switches
138
+ - Burst mode start
139
+ - Manual override via `browser_reset_loop_counter`
140
+
141
+ ### Knowledge Hints (Rule 16)
142
+
143
+ Domain-specific knowledge is stored in `~/.Weavetab/knowledge/[domain].md`. When a tool discovers a site-specific quirk (e.g., "this login form requires clicking the label, not the input"), it appends a timestamped note. On subsequent visits, the hint is injected as a system prompt token (max 20 tokens).
144
+
145
+ **Hint Format:**
146
+
147
+ ```markdown
148
+ # example.com Knowledge Base
149
+
150
+ ## 2026-07-06T14:30:00Z
151
+ - Login form requires clicking the label, not the input element
152
+ - Search bar uses Shadow DOM, requires `ax_tree: true`
153
+
154
+ ## 2026-07-05T09:15:00Z
155
+ - Navigation triggers SPA route change, wait 200ms for DOM stability
156
+ ```
157
+
158
+ ### Vision Fallback System
159
+
160
+ When the CDP Accessibility Tree returns zero elements, Weavetab falls back to local pixel analysis using the `sharp` library:
161
+
162
+ ```mermaid
163
+ flowchart TD
164
+ AX[CDP AX Tree Empty] --> Capture[Capture Screenshot]
165
+ Capture --> Gray[Grayscale Conversion]
166
+ Gray --> Heat[4x4 Grid Heatmap]
167
+ Heat --> Text[Text Density Calculation]
168
+ Text --> Click[Clickable Zone Detection]
169
+ Click --> Classify[Page State Classification]
170
+ Classify --> Result["Loading / Blank / Content / Error"]
171
+ ```
172
+
173
+ This runs entirely locally with no external API calls or ML dependencies.
174
+
175
+ ---
176
+
177
+ ## Sensor Systems
178
+
179
+ ### Network Telemetry
180
+
181
+ The network sensor (`src/sensors/network.ts`) intercepts CDP Network events to track:
182
+
183
+ - Request/response timing
184
+ - Resource types (XHR, fetch, document, script, stylesheet)
185
+ - HTTP status codes
186
+ - Response sizes
187
+ - CORS errors
188
+
189
+ **Usage:** Enables `browser_network_intercept` for API mocking and tracking.
190
+
191
+ ### DOM Mutation Watcher
192
+
193
+ The mutation sensor (`src/sensors/mutations.ts`) uses CDP DOM mutation events to detect:
194
+
195
+ - Added/removed nodes
196
+ - Attribute changes
197
+ - Text content changes
198
+ - Shadow DOM updates
199
+
200
+ **Usage:** Powers the delta engine and automatic cache invalidation.
201
+
202
+ ### Human Pacing Engine
203
+
204
+ The pacing sensor (`src/sensors/pacing.ts`) tracks timing patterns to:
205
+
206
+ - Detect abnormal speed (too fast = bot, too slow = stuck)
207
+ - Adjust Ghost Cursor timing for natural movement
208
+ - Modulate typing cadence based on field complexity
209
+
210
+ **Usage:** Enhances input realism and prevents detection.
211
+
212
+ ### Agent State Machine
213
+
214
+ The state machine (`src/state/agent.ts`) manages agent lifecycle:
215
+
216
+ | State | Trigger | Behavior |
217
+ |-------|---------|----------|
218
+ | **idle** | No recent tool calls | HUD shows idle status |
219
+ | **weaving** | Tool execution in progress | HUD shows active tool |
220
+ | **stuck** | 10+ loop strikes | Auto-recovery triggered, HUD shows warning |
221
+
222
+ ### Thought HUD System
223
+
224
+ The HUD (`src/sensors/thoughts.ts`) provides real-time visual feedback:
225
+
226
+ - Current tool being executed
227
+ - Execution time and token estimates
228
+ - Loop warnings
229
+ - User chat messages
230
+ - Mission progress (when using `browser_plan`)
231
+
232
+ ### Audit & Telemetry
233
+
234
+ The audit system (`src/audit/logger.ts`) maintains structured logs:
235
+
236
+ - **Mission logs** (`~/.Weavetab/logs/audit.log`) — Human-readable activity log
237
+ - **Structured logs** (`~/.Weavabab/logs/audit.jsonl`) — Machine-readable JSONL format
238
+ - **Telemetry** (optional) — Event broadcasting for analytics
239
+
240
+ ---
241
+
242
+ ## CDP Bridge
243
+
244
+ ### DOM Walker
245
+
246
+ The walker (`src/cdp/walker.ts`) performs DOM enumeration via CDP:
247
+
248
+ - **Accessibility Tree** — Primary source for element discovery
249
+ - **DOM traversal** — Fallback for complex Shadow DOM scenarios
250
+ - **Element resolution** — Maps backend node IDs to volatile `w:NN` refs that invalidate on mutation
251
+ - **Label extraction** — Prioritizes aria-label, placeholder, text content
252
+
253
+ ### Ghost Cursor Engine
254
+
255
+ The ghost cursor (`src/overlay/ghost.ts`) implements human-like mouse movement:
256
+
257
+ - **Bézier curves** — Natural path generation with control points
258
+ - **Acceleration** — Variable speed based on distance
259
+ - **Jitter** — Subtle randomization for human variation
260
+ - **Hold delay** — Configurable button hold duration
261
+
262
+ ### Keystroke Engine
263
+
264
+ The typing engine (`src/tools/type.ts`) simulates realistic keyboard input:
265
+
266
+ - **Per-character jitter** — Randomized typing speed (50-150ms per char)
267
+ - **Burst patterns** — Natural typing cadence (fast bursts, natural pauses)
268
+ - **Stuck detection** — Real-time DOM diffing to detect failed input
269
+ - **Auto-clear** — Atomic field clearing before typing
270
+
271
+ ### Semantic Pruner
272
+
273
+ The pruner (`src/cdp/pruner.ts`) compresses DOM snapshots:
274
+
275
+ - **Hidden element removal** — Drops non-interactive hidden elements
276
+ - **SVG collapsing** — Replaces SVG icons with `[SVG Icon: label]` tokens
277
+ - **Controls preservation** — Keeps elements referenced by `aria-controls`
278
+ - **Secret safety** — Preserves `data-wt-secret` elements
279
+
280
+ ### Shadow DOM Injector
281
+
282
+ The injector (`src/overlay/injector.ts`) manages UI overlay:
283
+
284
+ - **Voice UI** — Speech-to-text input for 2FA and sensitive data
285
+ - **DevMode HUD** — Real-time debugging information
286
+ - **Chat interface** — User-to-agent communication
287
+ - **Plan dashboard** — Mission progress visualization
288
+
289
+ ### Tab & Window Manager
290
+
291
+ The session registry (`src/state/session.ts`) manages browser sessions:
292
+
293
+ - **Session pooling** — Reuses CDP connections across tabs
294
+ - **Target ID mapping** — Maps MCP client IDs to CDP targets
295
+ - **Lifecycle management** — Handles tab creation, switching, closure
296
+ - **Crash recovery** — Detects and heals crashed tabs
297
+
298
+ ### Browser Launcher
299
+
300
+ The launcher (`src/cdp/connector.ts`) manages browser startup:
301
+
302
+ - **Lock system** — Two-factor validation (PID + TCP port)
303
+ - **Extension loading** — Injects Weavetab extension on startup
304
+ - **Remote debugging** — Connects to existing Chrome instances
305
+ - **Headless mode** — Supports both headed and headless execution
306
+
307
+ ---
308
+
309
+ ## Security Architecture
310
+
311
+ ### Layered Security Model
312
+
313
+ ```mermaid
314
+ flowchart TD
315
+ subgraph Layers ["Security Defense Layers"]
316
+ direction TB
317
+
318
+ subgraph Top ["Network & Process"]
319
+ direction LR
320
+ N["Network Isolation<br/>(localhost)"]
321
+ P["Process Hardening<br/>(root guard)"]
322
+ A["Application Security<br/>(RBAC)"]
323
+ end
324
+
325
+ subgraph Bottom ["Data & Input"]
326
+ direction LR
327
+ D["Domain Governance<br/>(blacklist)"]
328
+ I["Input Filtering<br/>(sanitization)"]
329
+ S["Secret Protection<br/>(blind inj)"]
330
+ end
331
+
332
+ Top --- Bottom
333
+ end
334
+ ```
335
+
336
+ ### Security Mechanisms
337
+
338
+ | Mechanism | Implementation | Threat Mitigated |
339
+ |-----------|----------------|------------------|
340
+ | **Domain Blacklist** | Hardcoded + custom JSON config | High-risk domain access |
341
+ | **Domain Policy Engine** | Per-domain allow/read-only/deny/audit modes | Unauthorized domain interactions |
342
+ | **RBAC** | 4 roles with tool permission matrix | Privilege escalation |
343
+ | **Rate Limiting** | Mutex-based actions/min enforcement | Runaway agent behavior |
344
+ | **Root Guard** | `assertNotRoot()` at startup | Privileged execution |
345
+ | **Storage Blocker** | Optional localStorage/sessionStorage nullification | Tracking/fingerprinting |
346
+ | **Input Filter** | Suspicious label stripping | Prompt injection |
347
+ | **Blind Injection** | Domain-scoped secret injection with masking | Credential leakage |
348
+ | **Shadow DOM Isolation** | UI in isolated Shadow DOM | Host page tampering |
349
+ | **Localhost Binding** | CDP WS bound to 127.0.0.1 | Remote exploitation |
350
+ | **Two-Factor Lock** | PID + TCP port validation | Stale lock false-positives |
351
+
352
+ ---
353
+
354
+ ## Performance Characteristics
355
+
356
+ ### Latency Breakdown
357
+
358
+ | Operation | Mean Latency | P95 Latency | P99 Latency |
359
+ |-----------|--------------|-------------|-------------|
360
+ | **Tool security checks** | 0.5ms | 1ms | 2ms |
361
+ | **CDP round-trip** | 2-5ms | 8ms | 15ms |
362
+ | **DOM walk (first)** | 8-15ms | 25ms | 40ms |
363
+ | **DOM walk (cached)** | 1-3ms | 5ms | 10ms |
364
+ | **Delta computation** | 1-2ms | 4ms | 8ms |
365
+ | **Ghost cursor execution** | 3-8ms | 12ms | 20ms |
366
+ | **Total end-to-end** | 3-8ms | 15ms | 25ms |
367
+
368
+ ### Memory Footprint
369
+
370
+ | Component | Memory Usage |
371
+ |-----------|--------------|
372
+ | **Base server** | ~50MB |
373
+ | **Per-session cache** | ~10-20MB |
374
+ | **Extension** | ~5MB |
375
+ | **Total (typical)** | ~65-75MB |
376
+
377
+ ### Disk Usage
378
+
379
+ | Component | Disk Usage |
380
+ |-----------|------------|
381
+ | **Server code** | ~5MB |
382
+ | **Extension** | ~2MB |
383
+ | **Session memory** | ~1-5MB (per domain) |
384
+ | **Knowledge hints** | ~100KB (per domain) |
385
+ | **Audit logs** | ~1-10MB (per mission) |
386
+
387
+ ---
388
+
389
+ ## Extensibility Points
390
+
391
+ ### Plugin System
392
+
393
+ Weavetab supports dynamic plugin loading for any package containing a `weavetab.json` manifest (and official `@weavetab/plugin-*` packages):
394
+
395
+ ```typescript
396
+ interface WeavetabPlugin {
397
+ name: string;
398
+ version: string;
399
+ tools: Array<{
400
+ name: string;
401
+ description: string;
402
+ handler: (session: CDP.Client, config: Config) => Promise<any>;
403
+ }>;
404
+ }
405
+ ```
406
+
407
+ ### Skills Ecosystem
408
+
409
+ The `@weavetab/skills` package provides pre-built workflow patterns:
410
+
411
+ - **Multi-step form automation** — Complex form filling with validation
412
+ - **E-commerce checkout** — Shopping cart navigation and payment
413
+ - **Data extraction pipelines** — Structured scraping and export
414
+ - **CMS workflows** — WordPress, Drupal, and CMS-specific patterns
415
+ - **API testing** — Endpoint testing and response verification
416
+
417
+ ### Custom Tool Registration
418
+
419
+ Developers can add custom tools by:
420
+
421
+ 1. Implementing the tool handler function
422
+ 2. Registering via `server.tool()` in `src/server.ts`
423
+ 3. Adding Zod schema validation
424
+ 4. Implementing security checks via `withSecurity()`
425
+ 5. Adding audit logging via `logAction()`
426
+
427
+ ---
428
+
429
+ ## Monitoring and Observability
430
+
431
+ ### Built-in Metrics
432
+
433
+ - **Tool execution time** — Per-tool timing breakdown
434
+ - **Cache hit rates** — DOM map and delta cache efficiency
435
+ - **Loop detection events** — Strike count and severity
436
+ - **Domain profile hits** — Session memory utilization
437
+ - **Network request counts** — Per-domain request tracking
438
+
439
+ ### Audit Trail
440
+
441
+ Every tool invocation generates structured audit logs:
442
+
443
+ ```json
444
+ {
445
+ "timestamp": "2026-07-06T14:30:00Z",
446
+ "sessionId": "default",
447
+ "tool": "browser_click",
448
+ "duration": 8,
449
+ "result": "success",
450
+ "pageUrl": "https://example.com",
451
+ "tabTitle": "Example Domain"
452
+ }
453
+ ```
454
+
455
+ ### DevMode HUD
456
+
457
+ When `devMode: true` is enabled, the HUD displays:
458
+
459
+ - Current tool execution
460
+ - Real-time timing metrics
461
+ - Token usage estimates
462
+ - Loop detection warnings
463
+ - User chat messages
464
+
465
+ ---
466
+
467
+ ## Conclusion
468
+
469
+ Weavetab's architecture is designed for **autonomous AI agents** requiring:
470
+
471
+ - **Sub-10ms latency** for real-time interaction
472
+ - **5-10x token efficiency** for cost-effective operation
473
+ - **Enterprise-grade security** for production deployment
474
+ - **Self-learning capabilities** for improved success rates
475
+ - **Human-like behavior** for authorized automation
476
+ - **Extensibility** for custom workflows
477
+
478
+ The five-layer architecture (Transport → Security → Intelligence → Sensors → CDP) provides a robust foundation for AI-driven browser automation at scale.
479
+ - Loop detection warnings
480
+ - User chat messages
481
+
482
+ ---
483
+
484
+ ## Conclusion
485
+
486
+ Weavetab's architecture is designed for **autonomous AI agents** requiring:
487
+
488
+ - **Sub-10ms latency** for real-time interaction
489
+ - **5-10x token efficiency** for cost-effective operation
490
+ - **Enterprise-grade security** for production deployment
491
+ - **Self-learning capabilities** for improved success rates
492
+ - **Human-like behavior** for authorized automation
493
+ - **Extensibility** for custom workflows
494
+
495
+ The five-layer architecture (Transport → Security → Intelligence → Sensors → CDP) provides a robust foundation for AI-driven browser automation at scale.
496
+ - Loop detection warnings
497
+ - User chat messages
498
+
499
+ ---
500
+
501
+ ## Conclusion
502
+
503
+ Weavetab's architecture is designed for **autonomous AI agents** requiring:
504
+
505
+ - **Sub-10ms latency** for real-time interaction
506
+ - **5-10x token efficiency** for cost-effective operation
507
+ - **Enterprise-grade security** for production deployment
508
+ - **Self-learning capabilities** for improved success rates
509
+ - **Human-like behavior** for authorized automation
510
+ - **Extensibility** for custom workflows
511
+
512
+ The five-layer architecture (Transport → Security → Intelligence → Sensors → CDP) provides a robust foundation for AI-driven browser automation at scale.
513
+ description: string;
514
+ handler: (session: CDP.Client, config: Config) => Promise<any>;
515
+ }>;
516
+ }
517
+ ```
518
+
519
+ ### Skills Ecosystem
520
+
521
+ The `@weavetab/skills` package provides pre-built workflow patterns:
522
+
523
+ - **Multi-step form automation** — Complex form filling with validation
524
+ - **E-commerce checkout** — Shopping cart navigation and payment
525
+ - **Data extraction pipelines** — Structured scraping and export
526
+ - **CMS workflows** — WordPress, Drupal, and CMS-specific patterns
527
+ - **API testing** — Endpoint testing and response verification
528
+
529
+ ### Custom Tool Registration
530
+
531
+ Developers can add custom tools by:
532
+
533
+ 1. Implementing the tool handler function
534
+ 2. Registering via `server.tool()` in `src/server.ts`
535
+ 3. Adding Zod schema validation
536
+ 4. Implementing security checks via `withSecurity()`
537
+ 5. Adding audit logging via `logAction()`
538
+
539
+ ---
540
+
541
+ ## Monitoring and Observability
542
+
543
+ ### Built-in Metrics
544
+
545
+ - **Tool execution time** — Per-tool timing breakdown
546
+ - **Cache hit rates** — DOM map and delta cache efficiency
547
+ - **Loop detection events** — Strike count and severity
548
+ - **Domain profile hits** — Session memory utilization
549
+ - **Network request counts** — Per-domain request tracking
550
+
551
+ ### Audit Trail
552
+
553
+ Every tool invocation generates structured audit logs:
554
+
555
+ ```json
556
+ {
557
+ "timestamp": "2026-07-06T14:30:00Z",
558
+ "sessionId": "default",
559
+ "tool": "browser_click",
560
+ "duration": 8,
561
+ "result": "success",
562
+ "pageUrl": "https://example.com",
563
+ "tabTitle": "Example Domain"
564
+ }
565
+ ```
566
+
567
+ ### DevMode HUD
568
+
569
+ When `devMode: true` is enabled, the HUD displays:
570
+
571
+ - Current tool execution
572
+ - Real-time timing metrics
573
+ - Token usage estimates
574
+ - Loop detection warnings
575
+ - User chat messages
576
+
577
+ ---
578
+
579
+ ## Conclusion
580
+
581
+ Weavetab's architecture is designed for **autonomous AI agents** requiring:
582
+
583
+ - **Sub-10ms latency** for real-time interaction
584
+ - **5-10x token efficiency** for cost-effective operation
585
+ - **Enterprise-grade security** for production deployment
586
+ - **Self-learning capabilities** for improved success rates
587
+ - **Human-like behavior** for authorized automation
588
+ - **Extensibility** for custom workflows
589
+
590
+ The five-layer architecture (Transport → Security → Intelligence → Sensors → CDP) provides a robust foundation for AI-driven browser automation at scale.