lobster-cli 0.1.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 (45) hide show
  1. package/README.md +389 -0
  2. package/dist/agent/core.js +1013 -0
  3. package/dist/agent/core.js.map +1 -0
  4. package/dist/agent/index.js +1027 -0
  5. package/dist/agent/index.js.map +1 -0
  6. package/dist/brain/index.js +60 -0
  7. package/dist/brain/index.js.map +1 -0
  8. package/dist/browser/dom/index.js +1096 -0
  9. package/dist/browser/dom/index.js.map +1 -0
  10. package/dist/browser/index.js +2034 -0
  11. package/dist/browser/index.js.map +1 -0
  12. package/dist/browser/manager.js +86 -0
  13. package/dist/browser/manager.js.map +1 -0
  14. package/dist/browser/page-adapter.js +1345 -0
  15. package/dist/browser/page-adapter.js.map +1 -0
  16. package/dist/cascade/index.js +138 -0
  17. package/dist/cascade/index.js.map +1 -0
  18. package/dist/config/index.js +110 -0
  19. package/dist/config/index.js.map +1 -0
  20. package/dist/config/schema.js +66 -0
  21. package/dist/config/schema.js.map +1 -0
  22. package/dist/discover/index.js +545 -0
  23. package/dist/discover/index.js.map +1 -0
  24. package/dist/index.js +5529 -0
  25. package/dist/index.js.map +1 -0
  26. package/dist/lib.js +4206 -0
  27. package/dist/lib.js.map +1 -0
  28. package/dist/llm/client.js +379 -0
  29. package/dist/llm/client.js.map +1 -0
  30. package/dist/llm/index.js +397 -0
  31. package/dist/llm/index.js.map +1 -0
  32. package/dist/llm/openai-client.js +214 -0
  33. package/dist/llm/openai-client.js.map +1 -0
  34. package/dist/output/index.js +93 -0
  35. package/dist/output/index.js.map +1 -0
  36. package/dist/pipeline/index.js +802 -0
  37. package/dist/pipeline/index.js.map +1 -0
  38. package/dist/router/decision.js +80 -0
  39. package/dist/router/decision.js.map +1 -0
  40. package/dist/router/index.js +3443 -0
  41. package/dist/router/index.js.map +1 -0
  42. package/dist/types/index.js +23 -0
  43. package/dist/types/index.js.map +1 -0
  44. package/logo.svg +11 -0
  45. package/package.json +65 -0
package/README.md ADDED
@@ -0,0 +1,389 @@
1
+ <p align="center">
2
+ <img src="logo.svg" width="80" height="80" alt="LobsterCLI Logo" />
3
+ </p>
4
+
5
+ <h1 align="center">LobsterCLI</h1>
6
+
7
+ <p align="center">
8
+ Web automation engine — CLI, Chrome extension, and importable library.<br/>
9
+ Fetch pages, run pipelines, explore APIs, and let AI agents navigate sites.
10
+ </p>
11
+
12
+ <p align="center">
13
+ <img src="https://img.shields.io/badge/node-%3E%3D20-black?style=flat-square" />
14
+ <img src="https://img.shields.io/badge/license-MIT-black?style=flat-square" />
15
+ <img src="https://img.shields.io/badge/AI-optional-c9a84c?style=flat-square" />
16
+ </p>
17
+
18
+ ---
19
+
20
+ ## What is LobsterCLI
21
+
22
+ LobsterCLI is a web automation engine that works in three ways:
23
+
24
+ | Product | What it is | Install |
25
+ |---------|-----------|---------|
26
+ | **CLI** | Terminal tool — fetch, scrape, explore, automate | `npm install -g lobster-cli` |
27
+ | **Chrome Extension** | Side panel chat UI — analyze any page you're browsing | Load `extension/` folder in Chrome |
28
+ | **Library** | Import into your own Node.js project | `import { ... } from 'lobster-cli'` |
29
+
30
+ All three share the same core engine — same Brain, same DOM extraction, same LLM client, same agent loop.
31
+
32
+ ---
33
+
34
+ ## When AI is needed vs when it's free
35
+
36
+ This is the most important thing to understand:
37
+
38
+ ### CLI — What's free, what needs AI
39
+
40
+ | Command | AI needed? | What it does |
41
+ |---------|-----------|-------------|
42
+ | `lobster fetch <url>` | **No** | Fetch page, extract as markdown/text/snapshot/HTML. Uses in-house parser, no Chrome needed. |
43
+ | `lobster fetch <url> -e chrome` | **No** | Same but with full Chrome for JS-heavy pages. |
44
+ | `lobster explore <url>` | **No** | Discover APIs, intercept network calls, detect frameworks, generate adapters. |
45
+ | `lobster run <url>` | **No** | Run pre-built site adapters and YAML pipelines. |
46
+ | `lobster list` | **No** | List all registered adapters. |
47
+ | `lobster config` | **No** | View/edit settings. |
48
+ | `lobster doctor` | **No** | Diagnose setup, check Chrome, verify API key. |
49
+ | `lobster setup` | **No** | Interactive setup wizard (AI provider selection is optional). |
50
+ | `lobster plugin install` | **No** | Install community adapters from GitHub. |
51
+ | `lobster agent "task"` | **Yes** | AI agent that reads pages, reasons, clicks, types, and navigates autonomously. |
52
+
53
+ **80% of CLI features work without any API key.**
54
+
55
+ ### Chrome Extension — What's free, what needs AI
56
+
57
+ | Action | AI needed? | What it does |
58
+ |--------|-----------|-------------|
59
+ | Click **"Summarize this page"** | **No** | Extracts headings, word count, content preview, page type, framework detection. |
60
+ | Click **"Extract as Markdown"** | **No** | Converts full page DOM to clean Markdown. Copy to clipboard. |
61
+ | Click **"Detect all forms"** | **No** | Scans all form fields — labels, types, values, required/disabled state. |
62
+ | Click **"Show key links"** | **No** | Extracts all meaningful links from the page. |
63
+ | Click **"Monitor API calls"** | **No** | Intercepts fetch/XHR, shows live API calls with method/URL/status. |
64
+ | Click **"DOM snapshot"** | **No** | 12-stage pruned DOM snapshot, LLM-optimized. |
65
+ | Type any question | **Yes** | Brain classifies intent, gathers right data, sends to LLM for answer. |
66
+ | Click **"What's on screen?"** | **Yes** | Captures screenshot + sends to vision model for visual analysis. |
67
+
68
+ **The 6 built-in chips work without AI. Typed questions need an API key.**
69
+
70
+ ### What the Brain does (smart intent classification)
71
+
72
+ When you type a question, the Brain decides what data to gather before answering:
73
+
74
+ ```
75
+ "summarize this page" → Brain: { screenshot: false, markdown: true }
76
+ Cost: ~$0.001 (text only)
77
+
78
+ "what is this email about" → Brain: { screenshot: false, markdown: true }
79
+ Cost: ~$0.001 (text only)
80
+
81
+ "what images are on this page" → Brain: { screenshot: true, markdown: true }
82
+ Cost: ~$0.01 (screenshot + text)
83
+
84
+ "what does the layout look like" → Brain: { screenshot: true, markdown: false }
85
+ Cost: ~$0.01 (screenshot only)
86
+
87
+ "what forms are on this page" → Brain: { screenshot: false, forms: true }
88
+ Cost: ~$0.001 (form extraction + text)
89
+ ```
90
+
91
+ The Brain saves money by **not** taking screenshots when they aren't needed. Most questions only need text.
92
+
93
+ ### Library — Same rules apply
94
+
95
+ ```typescript
96
+ import { classifyIntent } from 'lobster-cli/brain' // No AI needed for heuristic mode
97
+ import { PuppeteerPage } from 'lobster-cli/page' // No AI needed
98
+ import { MARKDOWN_SCRIPT } from 'lobster-cli/dom' // No AI needed
99
+ import { exploreSite } from 'lobster-cli/discover' // No AI needed
100
+ import { AgentCore } from 'lobster-cli/agent' // Needs AI
101
+ import { LLM } from 'lobster-cli/llm' // Needs AI
102
+ ```
103
+
104
+ ---
105
+
106
+ ## Install
107
+
108
+ ### CLI
109
+
110
+ ```bash
111
+ # Install globally
112
+ npm install -g lobster-cli
113
+
114
+ # Or clone and build
115
+ git clone https://github.com/iexcalibur/lobster-cli.git
116
+ cd lobster-cli
117
+ npm install
118
+ npm run build
119
+ npm link
120
+ ```
121
+
122
+ Requires Node.js 20+. Chrome/Chromium needed only for browser features.
123
+
124
+ ### Chrome Extension
125
+
126
+ 1. Clone this repo
127
+ 2. Open `chrome://extensions/`
128
+ 3. Enable **Developer mode** (top right)
129
+ 4. Click **Load unpacked** → select the `extension/` folder
130
+ 5. Click the LobsterCLI icon → opens as a side panel
131
+
132
+ ### Library (in your own project)
133
+
134
+ ```bash
135
+ npm install lobster-cli
136
+ ```
137
+
138
+ ```typescript
139
+ import { classifyIntent, heuristicClassify } from 'lobster-cli/brain'
140
+ import { PuppeteerPage, BrowserManager } from 'lobster-cli/browser'
141
+ import { SNAPSHOT_SCRIPT, MARKDOWN_SCRIPT } from 'lobster-cli/dom'
142
+ import { AgentCore } from 'lobster-cli/agent'
143
+ import { exploreSite } from 'lobster-cli/discover'
144
+ import { executePipeline } from 'lobster-cli/pipeline'
145
+ import { LLM } from 'lobster-cli/llm'
146
+ ```
147
+
148
+ ---
149
+
150
+ ## AI Setup (optional)
151
+
152
+ AI is only needed for `lobster agent` and typed chat questions in the extension.
153
+
154
+ ```bash
155
+ lobster setup
156
+ ```
157
+
158
+ | Provider | Default Model | Cost | Best for |
159
+ |----------|--------------|------|----------|
160
+ | **Google Gemini** | gemini-2.5-flash | **Free tier** | Most users — free, fast, vision support |
161
+ | **OpenAI** | gpt-4o | Pay per token | Best reasoning |
162
+ | **Anthropic** | claude-sonnet-4 | Pay per token | Best for code analysis |
163
+ | **Ollama** | llama3.1 | **Free (local)** | Privacy, offline use |
164
+
165
+ Or set manually:
166
+
167
+ ```bash
168
+ lobster config set llm.provider gemini
169
+ lobster config set llm.apiKey AIza...
170
+ lobster config set llm.model gemini-2.5-flash
171
+ ```
172
+
173
+ ---
174
+
175
+ ## CLI Commands
176
+
177
+ ### `lobster fetch <url>` — Extract content (no AI)
178
+
179
+ ```bash
180
+ lobster fetch https://example.com # markdown output
181
+ lobster fetch https://example.com -d snapshot # LLM-optimized DOM
182
+ lobster fetch https://example.com -d text # plain text
183
+ lobster fetch https://example.com -d semantic # W3C accessible tree
184
+ lobster fetch https://example.com -d html # raw HTML
185
+ lobster fetch https://example.com -e chrome -w 5 # force Chrome, wait 5s
186
+ ```
187
+
188
+ Engines: `auto` (default), `fast` (in-house parser, no Chrome), `chrome` (full browser).
189
+
190
+ ### `lobster run <url>` — Smart router (no AI)
191
+
192
+ ```bash
193
+ lobster run https://api.github.com/users/octocat # direct HTTP fetch
194
+ lobster run https://news.ycombinator.com # adapter if registered
195
+ lobster run https://example.com -f yaml # output as YAML
196
+ ```
197
+
198
+ ### `lobster agent <task>` — AI agent (needs API key)
199
+
200
+ ```bash
201
+ lobster agent "search for TypeScript on Hacker News" --url https://news.ycombinator.com
202
+ lobster agent "find the cheapest flight to Tokyo" --url https://google.com/flights
203
+ lobster agent "log in and check my notifications" --url https://github.com
204
+ ```
205
+
206
+ The agent observes the DOM → sends to LLM → decides what to click/type/scroll → repeats until done (max 40 steps).
207
+
208
+ ### `lobster explore <url>` — Discover APIs (no AI)
209
+
210
+ ```bash
211
+ lobster explore https://reddit.com
212
+ lobster explore https://twitter.com -w 5
213
+ ```
214
+
215
+ Intercepts network calls, clicks around to find hidden APIs, detects frameworks, scores endpoints, and generates adapter files.
216
+
217
+ ### `lobster config` — Settings
218
+
219
+ ```bash
220
+ lobster config show
221
+ lobster config set llm.provider anthropic
222
+ lobster config set browser.headless false
223
+ ```
224
+
225
+ ### `lobster plugin` — Community adapters
226
+
227
+ ```bash
228
+ lobster plugin install github-user/reddit-adapter
229
+ lobster plugin list
230
+ ```
231
+
232
+ ---
233
+
234
+ ## Chrome Extension
235
+
236
+ The extension is a chat-style side panel (like Gemini or Claude) docked to the right of your browser.
237
+
238
+ ### Free features (no API key)
239
+
240
+ Click any of the 6 built-in chips:
241
+
242
+ - **Summarize this page** — page type, headings, word count, framework, content preview
243
+ - **Extract as Markdown** — full DOM-to-Markdown with copy button
244
+ - **Detect all forms** — every form field with label, type, value, required state
245
+ - **Show key links** — all meaningful links on the page
246
+ - **Monitor API calls** — live fetch/XHR interception
247
+ - **DOM snapshot** — 12-stage pruned snapshot
248
+
249
+ ### AI features (needs API key)
250
+
251
+ Type any question in the chat:
252
+
253
+ - "What is this email about?" — reads page text, gives natural language answer
254
+ - "What images are on this page?" — captures screenshot, uses vision model
255
+ - "Draft a reply to this email" — reads content, writes a response
256
+ - "What color is the header?" — captures screenshot, analyzes visually
257
+
258
+ The **Brain** automatically decides whether to capture a screenshot or just read text, so you don't pay for vision when you don't need it.
259
+
260
+ ### Setup AI in extension
261
+
262
+ Click the gear icon → Settings → pick provider → enter key → Save.
263
+
264
+ ---
265
+
266
+ ## Use as a library
267
+
268
+ LobsterCLI exports every module for use in your own projects:
269
+
270
+ ```typescript
271
+ // Brain — intent classification
272
+ import { classifyIntent, heuristicClassify } from 'lobster-cli/brain'
273
+
274
+ // Browser — page control
275
+ import { BrowserManager, PuppeteerPage } from 'lobster-cli/browser'
276
+
277
+ // DOM scripts — run in any browser context
278
+ import { SNAPSHOT_SCRIPT, MARKDOWN_SCRIPT, FORM_STATE_SCRIPT } from 'lobster-cli/dom'
279
+
280
+ // Agent — autonomous web navigation
281
+ import { AgentCore } from 'lobster-cli/agent'
282
+
283
+ // LLM — multi-provider client
284
+ import { LLM } from 'lobster-cli/llm'
285
+
286
+ // Pipeline — declarative YAML execution
287
+ import { executePipeline } from 'lobster-cli/pipeline'
288
+
289
+ // Discovery — find site APIs
290
+ import { exploreSite } from 'lobster-cli/discover'
291
+
292
+ // Config — load/save settings
293
+ import { loadConfig, saveConfig } from 'lobster-cli/config'
294
+ ```
295
+
296
+ ### Example: build a search agent
297
+
298
+ ```typescript
299
+ import { BrowserManager } from 'lobster-cli/browser'
300
+ import { AgentCore } from 'lobster-cli/agent'
301
+ import { LLM } from 'lobster-cli/llm'
302
+ import { classifyIntent } from 'lobster-cli/brain'
303
+
304
+ async function search(query) {
305
+ // Brain decides what data is needed
306
+ const intent = await classifyIntent(query, 'Google Search')
307
+
308
+ // Launch browser
309
+ const browser = new BrowserManager({ headless: true })
310
+ const page = await browser.launch('https://google.com')
311
+
312
+ // Run agent
313
+ const agent = new AgentCore({ page, llm: new LLM(config), maxSteps: 20 })
314
+ const result = await agent.execute(query)
315
+
316
+ await page.close()
317
+ return result
318
+ }
319
+ ```
320
+
321
+ ---
322
+
323
+ ## Architecture
324
+
325
+ ```
326
+ lobster-cli/
327
+ ├── src/
328
+ │ ├── brain/ → Intent classifier (LLM + heuristic fallback)
329
+ │ ├── browser/ → IPage interface, Puppeteer adapter, DOM scripts
330
+ │ │ └── dom/ → 6 extraction strategies (snapshot, markdown, semantic, etc.)
331
+ │ ├── agent/ → Observe-think-act loop, 8 tools, auto-fixer
332
+ │ ├── llm/ → Multi-provider client (OpenAI, Anthropic, Gemini, Ollama)
333
+ │ ├── pipeline/ → YAML pipeline engine, 17 steps, template expressions
334
+ │ ├── adapter/ → Site adapter registry, YAML/TS loaders
335
+ │ ├── router/ → Smart routing (HTTP → Engine → Adapter → Agent)
336
+ │ ├── discover/ → API discovery, endpoint scoring, adapter generation
337
+ │ ├── cascade/ → Auth strategy detection (public → cookie → header → intercept)
338
+ │ ├── config/ → Settings (~/.lobster/config.yaml)
339
+ │ ├── output/ → Formatters (table, JSON, YAML, CSV, Markdown)
340
+ │ ├── plugin/ → GitHub plugin install/uninstall
341
+ │ ├── lib.ts → Library exports (for npm import)
342
+ │ ├── cli.ts → CLI commands (commander)
343
+ │ └── index.ts → CLI entry point
344
+
345
+ ├── extension/ → Chrome extension (side panel)
346
+ │ ├── sidepanel/ → Chat UI (HTML/CSS/JS)
347
+ │ ├── background/ → Service worker (LLM calls, screenshot capture)
348
+ │ ├── shared/ → DOM scripts (same code as CLI, ported to browser JS)
349
+ │ ├── options/ → Settings page
350
+ │ └── manifest.json → Chrome extension manifest (v3, side panel API)
351
+
352
+ ├── logo.svg → Logo (SVG)
353
+ ├── logo.png → Logo (512px PNG)
354
+ └── package.json → Dual: CLI binary + library exports
355
+ ```
356
+
357
+ ---
358
+
359
+ ## Environment Variables
360
+
361
+ | Variable | Purpose |
362
+ |----------|---------|
363
+ | `LOBSTER_API_KEY` | LLM API key (overrides config) |
364
+ | `LOBSTER_MODEL` | LLM model name |
365
+ | `LOBSTER_BASE_URL` | LLM API base URL |
366
+ | `LOBSTER_CDP_ENDPOINT` | Chrome DevTools Protocol endpoint |
367
+ | `LOBSTER_BROWSER_PATH` | Path to Chrome/Chromium binary |
368
+
369
+ ---
370
+
371
+ ## Dependencies
372
+
373
+ | Package | Purpose |
374
+ |---------|---------|
375
+ | `commander` | CLI framework |
376
+ | `puppeteer-core` | Chrome control (no bundled Chrome) |
377
+ | `zod` | Schema validation |
378
+ | `chalk` | Terminal colors |
379
+ | `cli-table3` | Table formatting |
380
+ | `js-yaml` | YAML parsing |
381
+ | `ws` | WebSocket |
382
+
383
+ No AI SDK. LLM calls use native `fetch()` with our own protocol adapters.
384
+
385
+ ---
386
+
387
+ ## License
388
+
389
+ MIT