@docyrus/docyrus 0.0.20 → 0.0.22
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/agent-loader.js +32 -1
- package/agent-loader.js.map +2 -2
- package/main.js +325 -71
- package/main.js.map +4 -4
- package/package.json +16 -3
- package/resources/chrome-tools/browser-content.js +103 -0
- package/resources/chrome-tools/browser-cookies.js +35 -0
- package/resources/chrome-tools/browser-eval.js +53 -0
- package/resources/chrome-tools/browser-hn-scraper.js +108 -0
- package/resources/chrome-tools/browser-nav.js +44 -0
- package/resources/chrome-tools/browser-pick.js +162 -0
- package/resources/chrome-tools/browser-screenshot.js +34 -0
- package/resources/chrome-tools/browser-start.js +86 -0
- package/resources/pi-agent/extensions/answer.ts +532 -0
- package/resources/pi-agent/extensions/context.ts +578 -0
- package/resources/pi-agent/extensions/control.ts +1779 -0
- package/resources/pi-agent/extensions/diff.ts +218 -0
- package/resources/pi-agent/extensions/files.ts +199 -0
- package/resources/pi-agent/extensions/loop.ts +446 -0
- package/resources/pi-agent/extensions/multi-edit.ts +835 -0
- package/resources/pi-agent/extensions/notify.ts +88 -0
- package/resources/pi-agent/extensions/pi-bash-live-view/LICENSE +21 -0
- package/resources/pi-agent/extensions/pi-bash-live-view/README.md +19 -0
- package/resources/pi-agent/extensions/pi-bash-live-view/index.ts +52 -0
- package/resources/pi-agent/extensions/pi-bash-live-view/package.json +61 -0
- package/resources/pi-agent/extensions/pi-bash-live-view/pty-execute.ts +97 -0
- package/resources/pi-agent/extensions/pi-bash-live-view/pty-kill.ts +25 -0
- package/resources/pi-agent/extensions/pi-bash-live-view/pty-session.ts +143 -0
- package/resources/pi-agent/extensions/pi-bash-live-view/spawn-helper.ts +31 -0
- package/resources/pi-agent/extensions/pi-bash-live-view/terminal-emulator.ts +439 -0
- package/resources/pi-agent/extensions/pi-bash-live-view/truncate.ts +68 -0
- package/resources/pi-agent/extensions/pi-bash-live-view/widget.ts +114 -0
- package/resources/pi-agent/extensions/pi-mcp-adapter/CHANGELOG.md +192 -0
- package/resources/pi-agent/extensions/pi-mcp-adapter/LICENSE +21 -0
- package/resources/pi-agent/extensions/pi-mcp-adapter/README.md +296 -0
- package/resources/pi-agent/extensions/pi-mcp-adapter/app-bridge.bundle.js +67 -0
- package/resources/pi-agent/extensions/pi-mcp-adapter/cli.js +108 -0
- package/resources/pi-agent/extensions/pi-mcp-adapter/commands.ts +211 -0
- package/resources/pi-agent/extensions/pi-mcp-adapter/config.ts +227 -0
- package/resources/pi-agent/extensions/pi-mcp-adapter/consent-manager.ts +64 -0
- package/resources/pi-agent/extensions/pi-mcp-adapter/direct-tools.ts +301 -0
- package/resources/pi-agent/extensions/pi-mcp-adapter/errors.ts +219 -0
- package/resources/pi-agent/extensions/pi-mcp-adapter/glimpse-ui.ts +80 -0
- package/resources/pi-agent/extensions/pi-mcp-adapter/host-html-template.ts +427 -0
- package/resources/pi-agent/extensions/pi-mcp-adapter/index.ts +232 -0
- package/resources/pi-agent/extensions/pi-mcp-adapter/init.ts +319 -0
- package/resources/pi-agent/extensions/pi-mcp-adapter/lifecycle.ts +93 -0
- package/resources/pi-agent/extensions/pi-mcp-adapter/logger.ts +169 -0
- package/resources/pi-agent/extensions/pi-mcp-adapter/mcp-panel.ts +713 -0
- package/resources/pi-agent/extensions/pi-mcp-adapter/metadata-cache.ts +191 -0
- package/resources/pi-agent/extensions/pi-mcp-adapter/npx-resolver.ts +419 -0
- package/resources/pi-agent/extensions/pi-mcp-adapter/oauth-handler.ts +56 -0
- package/resources/pi-agent/extensions/pi-mcp-adapter/package.json +85 -0
- package/resources/pi-agent/extensions/pi-mcp-adapter/paths.ts +29 -0
- package/resources/pi-agent/extensions/pi-mcp-adapter/proxy-modes.ts +635 -0
- package/resources/pi-agent/extensions/pi-mcp-adapter/resource-tools.ts +17 -0
- package/resources/pi-agent/extensions/pi-mcp-adapter/server-manager.ts +330 -0
- package/resources/pi-agent/extensions/pi-mcp-adapter/state.ts +41 -0
- package/resources/pi-agent/extensions/pi-mcp-adapter/tool-metadata.ts +144 -0
- package/resources/pi-agent/extensions/pi-mcp-adapter/tool-registrar.ts +46 -0
- package/resources/pi-agent/extensions/pi-mcp-adapter/types.ts +367 -0
- package/resources/pi-agent/extensions/pi-mcp-adapter/ui-resource-handler.ts +145 -0
- package/resources/pi-agent/extensions/pi-mcp-adapter/ui-server.ts +623 -0
- package/resources/pi-agent/extensions/pi-mcp-adapter/ui-session.ts +384 -0
- package/resources/pi-agent/extensions/pi-mcp-adapter/ui-stream-types.ts +89 -0
- package/resources/pi-agent/extensions/pi-mcp-adapter/utils.ts +75 -0
- package/resources/pi-agent/extensions/prompt-editor.ts +1315 -0
- package/resources/pi-agent/extensions/prompt-url-widget.ts +158 -0
- package/resources/pi-agent/extensions/redraws.ts +24 -0
- package/resources/pi-agent/extensions/review.ts +2160 -0
- package/resources/pi-agent/extensions/todos.ts +2076 -0
- package/resources/pi-agent/extensions/tps.ts +47 -0
- package/resources/pi-agent/extensions/whimsical.ts +474 -0
- package/resources/pi-agent/skills/changelog-generator/SKILL.md +425 -0
- package/resources/pi-agent/skills/docyrus-chrome-devtools-cli/SKILL.md +80 -0
- package/resources/pi-agent/skills/docyrus-platform/references/docyrus-cli-usage.md +51 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docyrus/docyrus",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.22",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Docyrus API CLI",
|
|
6
6
|
"main": "./main.js",
|
|
@@ -8,17 +8,30 @@
|
|
|
8
8
|
"docyrus": "main.js"
|
|
9
9
|
},
|
|
10
10
|
"dependencies": {
|
|
11
|
+
"@mozilla/readability": "^0.6.0",
|
|
11
12
|
"@clack/prompts": "^0.11.0",
|
|
13
|
+
"@modelcontextprotocol/ext-apps": "^1.2.2",
|
|
14
|
+
"@modelcontextprotocol/sdk": "^1.25.1",
|
|
12
15
|
"@mariozechner/pi-ai": "0.61.0",
|
|
13
|
-
"@mariozechner/pi-coding-agent": "0.61.
|
|
16
|
+
"@mariozechner/pi-coding-agent": "0.61.1",
|
|
14
17
|
"@opentui/core": "^0.1.85",
|
|
15
18
|
"@opentui/react": "^0.1.85",
|
|
19
|
+
"@xterm/headless": "^5.5.0",
|
|
20
|
+
"cheerio": "^1.1.2",
|
|
21
|
+
"diff": "^8.0.2",
|
|
16
22
|
"incur": "^0.1.6",
|
|
23
|
+
"jsdom": "^27.0.1",
|
|
17
24
|
"marked": "^15.0.12",
|
|
18
25
|
"marked-terminal": "^7.3.0",
|
|
26
|
+
"node-pty": "^1.0.0",
|
|
19
27
|
"picocolors": "^1.1.1",
|
|
28
|
+
"puppeteer-core": "^24.31.0",
|
|
20
29
|
"react": "^19.1.1",
|
|
21
|
-
"
|
|
30
|
+
"strip-ansi": "^7.1.0",
|
|
31
|
+
"turndown": "^7.2.2",
|
|
32
|
+
"turndown-plugin-gfm": "^1.0.2",
|
|
33
|
+
"undici": "^7.16.0",
|
|
34
|
+
"zod": "^4.3.6"
|
|
22
35
|
},
|
|
23
36
|
"devDependencies": {
|
|
24
37
|
"@types/react": "^19.1.13"
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import puppeteer from "puppeteer-core";
|
|
4
|
+
import { Readability } from "@mozilla/readability";
|
|
5
|
+
import { JSDOM } from "jsdom";
|
|
6
|
+
import TurndownService from "turndown";
|
|
7
|
+
import { gfm } from "turndown-plugin-gfm";
|
|
8
|
+
|
|
9
|
+
// Global timeout - exit if script takes too long
|
|
10
|
+
const TIMEOUT = 30000;
|
|
11
|
+
const timeoutId = setTimeout(() => {
|
|
12
|
+
console.error("✗ Timeout after 30s");
|
|
13
|
+
process.exit(1);
|
|
14
|
+
}, TIMEOUT).unref();
|
|
15
|
+
|
|
16
|
+
const url = process.argv[2];
|
|
17
|
+
|
|
18
|
+
if (!url) {
|
|
19
|
+
console.log("Usage: browser-content.js <url>");
|
|
20
|
+
console.log("\nExtracts readable content from a URL as markdown.");
|
|
21
|
+
console.log("\nExamples:");
|
|
22
|
+
console.log(" browser-content.js https://example.com");
|
|
23
|
+
console.log(" browser-content.js https://en.wikipedia.org/wiki/Rust_(programming_language)");
|
|
24
|
+
process.exit(1);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const b = await Promise.race([
|
|
28
|
+
puppeteer.connect({
|
|
29
|
+
browserURL: "http://localhost:9222",
|
|
30
|
+
defaultViewport: null,
|
|
31
|
+
}),
|
|
32
|
+
new Promise((_, reject) => setTimeout(() => reject(new Error("timeout")), 5000)),
|
|
33
|
+
]).catch((e) => {
|
|
34
|
+
console.error("✗ Could not connect to browser:", e.message);
|
|
35
|
+
console.error(" Run: browser-start.js");
|
|
36
|
+
process.exit(1);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const p = (await b.pages()).at(-1);
|
|
40
|
+
if (!p) {
|
|
41
|
+
console.error("✗ No active tab found");
|
|
42
|
+
process.exit(1);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
await Promise.race([
|
|
46
|
+
p.goto(url, { waitUntil: "networkidle2" }),
|
|
47
|
+
new Promise((r) => setTimeout(r, 10000)),
|
|
48
|
+
]).catch(() => {});
|
|
49
|
+
|
|
50
|
+
// Get HTML via CDP (works even with TrustedScriptURL restrictions)
|
|
51
|
+
const client = await p.createCDPSession();
|
|
52
|
+
const { root } = await client.send("DOM.getDocument", { depth: -1, pierce: true });
|
|
53
|
+
const { outerHTML } = await client.send("DOM.getOuterHTML", { nodeId: root.nodeId });
|
|
54
|
+
await client.detach();
|
|
55
|
+
|
|
56
|
+
const finalUrl = p.url();
|
|
57
|
+
|
|
58
|
+
// Extract with Readability
|
|
59
|
+
const doc = new JSDOM(outerHTML, { url: finalUrl });
|
|
60
|
+
const reader = new Readability(doc.window.document);
|
|
61
|
+
const article = reader.parse();
|
|
62
|
+
|
|
63
|
+
// Convert to markdown
|
|
64
|
+
function htmlToMarkdown(html) {
|
|
65
|
+
const turndown = new TurndownService({ headingStyle: "atx", codeBlockStyle: "fenced" });
|
|
66
|
+
turndown.use(gfm);
|
|
67
|
+
turndown.addRule("removeEmptyLinks", {
|
|
68
|
+
filter: (node) => node.nodeName === "A" && !node.textContent?.trim(),
|
|
69
|
+
replacement: () => "",
|
|
70
|
+
});
|
|
71
|
+
return turndown
|
|
72
|
+
.turndown(html)
|
|
73
|
+
.replace(/\[\\?\[\s*\\?\]\]\([^)]*\)/g, "")
|
|
74
|
+
.replace(/ +/g, " ")
|
|
75
|
+
.replace(/\s+,/g, ",")
|
|
76
|
+
.replace(/\s+\./g, ".")
|
|
77
|
+
.replace(/\n{3,}/g, "\n\n")
|
|
78
|
+
.trim();
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
let content;
|
|
82
|
+
if (article && article.content) {
|
|
83
|
+
content = htmlToMarkdown(article.content);
|
|
84
|
+
} else {
|
|
85
|
+
// Fallback
|
|
86
|
+
const fallbackDoc = new JSDOM(outerHTML, { url: finalUrl });
|
|
87
|
+
const fallbackBody = fallbackDoc.window.document;
|
|
88
|
+
fallbackBody.querySelectorAll("script, style, noscript, nav, header, footer, aside").forEach((el) => el.remove());
|
|
89
|
+
const main = fallbackBody.querySelector("main, article, [role='main'], .content, #content") || fallbackBody.body;
|
|
90
|
+
const fallbackHtml = main?.innerHTML || "";
|
|
91
|
+
if (fallbackHtml.trim().length > 100) {
|
|
92
|
+
content = htmlToMarkdown(fallbackHtml);
|
|
93
|
+
} else {
|
|
94
|
+
content = "(Could not extract content)";
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
console.log(`URL: ${finalUrl}`);
|
|
99
|
+
if (article?.title) console.log(`Title: ${article.title}`);
|
|
100
|
+
console.log("");
|
|
101
|
+
console.log(content);
|
|
102
|
+
|
|
103
|
+
process.exit(0);
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import puppeteer from "puppeteer-core";
|
|
4
|
+
|
|
5
|
+
const b = await Promise.race([
|
|
6
|
+
puppeteer.connect({
|
|
7
|
+
browserURL: "http://localhost:9222",
|
|
8
|
+
defaultViewport: null,
|
|
9
|
+
}),
|
|
10
|
+
new Promise((_, reject) => setTimeout(() => reject(new Error("timeout")), 5000)),
|
|
11
|
+
]).catch((e) => {
|
|
12
|
+
console.error("✗ Could not connect to browser:", e.message);
|
|
13
|
+
console.error(" Run: browser-start.js");
|
|
14
|
+
process.exit(1);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
const p = (await b.pages()).at(-1);
|
|
18
|
+
|
|
19
|
+
if (!p) {
|
|
20
|
+
console.error("✗ No active tab found");
|
|
21
|
+
process.exit(1);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const cookies = await p.cookies();
|
|
25
|
+
|
|
26
|
+
for (const cookie of cookies) {
|
|
27
|
+
console.log(`${cookie.name}: ${cookie.value}`);
|
|
28
|
+
console.log(` domain: ${cookie.domain}`);
|
|
29
|
+
console.log(` path: ${cookie.path}`);
|
|
30
|
+
console.log(` httpOnly: ${cookie.httpOnly}`);
|
|
31
|
+
console.log(` secure: ${cookie.secure}`);
|
|
32
|
+
console.log("");
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
await b.disconnect();
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import puppeteer from "puppeteer-core";
|
|
4
|
+
|
|
5
|
+
const code = process.argv.slice(2).join(" ");
|
|
6
|
+
if (!code) {
|
|
7
|
+
console.log("Usage: browser-eval.js 'code'");
|
|
8
|
+
console.log("\nExamples:");
|
|
9
|
+
console.log(' browser-eval.js "document.title"');
|
|
10
|
+
console.log(' browser-eval.js "document.querySelectorAll(\'a\').length"');
|
|
11
|
+
process.exit(1);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const b = await Promise.race([
|
|
15
|
+
puppeteer.connect({
|
|
16
|
+
browserURL: "http://localhost:9222",
|
|
17
|
+
defaultViewport: null,
|
|
18
|
+
}),
|
|
19
|
+
new Promise((_, reject) => setTimeout(() => reject(new Error("timeout")), 5000)),
|
|
20
|
+
]).catch((e) => {
|
|
21
|
+
console.error("✗ Could not connect to browser:", e.message);
|
|
22
|
+
console.error(" Run: browser-start.js");
|
|
23
|
+
process.exit(1);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const p = (await b.pages()).at(-1);
|
|
27
|
+
|
|
28
|
+
if (!p) {
|
|
29
|
+
console.error("✗ No active tab found");
|
|
30
|
+
process.exit(1);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const result = await p.evaluate((c) => {
|
|
34
|
+
const AsyncFunction = (async () => {}).constructor;
|
|
35
|
+
return new AsyncFunction(`return (${c})`)();
|
|
36
|
+
}, code);
|
|
37
|
+
|
|
38
|
+
if (Array.isArray(result)) {
|
|
39
|
+
for (let i = 0; i < result.length; i++) {
|
|
40
|
+
if (i > 0) console.log("");
|
|
41
|
+
for (const [key, value] of Object.entries(result[i])) {
|
|
42
|
+
console.log(`${key}: ${value}`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
} else if (typeof result === "object" && result !== null) {
|
|
46
|
+
for (const [key, value] of Object.entries(result)) {
|
|
47
|
+
console.log(`${key}: ${value}`);
|
|
48
|
+
}
|
|
49
|
+
} else {
|
|
50
|
+
console.log(result);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
await b.disconnect();
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Hacker News Scraper
|
|
5
|
+
*
|
|
6
|
+
* Fetches and parses submissions from Hacker News front page.
|
|
7
|
+
* Usage: node browser-hn-scraper.js [--limit <number>]
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import * as cheerio from 'cheerio';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Scrapes Hacker News front page
|
|
14
|
+
* @param {number} limit - Maximum number of submissions to return (default: 30)
|
|
15
|
+
* @returns {Promise<Array>} Array of submission objects
|
|
16
|
+
*/
|
|
17
|
+
async function scrapeHackerNews(limit = 30) {
|
|
18
|
+
const url = 'https://news.ycombinator.com';
|
|
19
|
+
|
|
20
|
+
try {
|
|
21
|
+
const response = await fetch(url);
|
|
22
|
+
if (!response.ok) {
|
|
23
|
+
throw new Error(`HTTP error! status: ${response.status}`);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const html = await response.text();
|
|
27
|
+
const $ = cheerio.load(html);
|
|
28
|
+
const submissions = [];
|
|
29
|
+
|
|
30
|
+
// Each submission has class 'athing'
|
|
31
|
+
$('.athing').each((index, element) => {
|
|
32
|
+
if (submissions.length >= limit) return false; // Stop when limit reached
|
|
33
|
+
|
|
34
|
+
const $element = $(element);
|
|
35
|
+
const id = $element.attr('id');
|
|
36
|
+
|
|
37
|
+
// Get title and URL from titleline
|
|
38
|
+
const $titleLine = $element.find('.titleline > a').first();
|
|
39
|
+
const title = $titleLine.text().trim();
|
|
40
|
+
const url = $titleLine.attr('href');
|
|
41
|
+
|
|
42
|
+
// Get the next row which contains metadata (points, author, comments)
|
|
43
|
+
const $metadataRow = $element.next();
|
|
44
|
+
const $subtext = $metadataRow.find('.subtext');
|
|
45
|
+
|
|
46
|
+
// Get points
|
|
47
|
+
const $score = $subtext.find(`#score_${id}`);
|
|
48
|
+
const pointsText = $score.text();
|
|
49
|
+
const points = pointsText ? parseInt(pointsText.match(/\d+/)?.[0] || '0') : 0;
|
|
50
|
+
|
|
51
|
+
// Get author
|
|
52
|
+
const author = $subtext.find('.hnuser').text().trim();
|
|
53
|
+
|
|
54
|
+
// Get time
|
|
55
|
+
const time = $subtext.find('.age').attr('title') || $subtext.find('.age').text().trim();
|
|
56
|
+
|
|
57
|
+
// Get comments count
|
|
58
|
+
const $commentsLink = $subtext.find('a').last();
|
|
59
|
+
const commentsText = $commentsLink.text();
|
|
60
|
+
let commentsCount = 0;
|
|
61
|
+
|
|
62
|
+
if (commentsText.includes('comment')) {
|
|
63
|
+
const match = commentsText.match(/(\d+)/);
|
|
64
|
+
commentsCount = match ? parseInt(match[0]) : 0;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
submissions.push({
|
|
68
|
+
id,
|
|
69
|
+
title,
|
|
70
|
+
url,
|
|
71
|
+
points,
|
|
72
|
+
author,
|
|
73
|
+
time,
|
|
74
|
+
comments: commentsCount,
|
|
75
|
+
hnUrl: `https://news.ycombinator.com/item?id=${id}`
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
return submissions;
|
|
80
|
+
} catch (error) {
|
|
81
|
+
console.error('Error scraping Hacker News:', error.message);
|
|
82
|
+
throw error;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// CLI interface
|
|
87
|
+
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
88
|
+
const args = process.argv.slice(2);
|
|
89
|
+
let limit = 30;
|
|
90
|
+
|
|
91
|
+
// Parse --limit argument
|
|
92
|
+
const limitIndex = args.indexOf('--limit');
|
|
93
|
+
if (limitIndex !== -1 && args[limitIndex + 1]) {
|
|
94
|
+
limit = parseInt(args[limitIndex + 1]);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
scrapeHackerNews(limit)
|
|
98
|
+
.then(submissions => {
|
|
99
|
+
console.log(JSON.stringify(submissions, null, 2));
|
|
100
|
+
console.error(`\n✓ Scraped ${submissions.length} submissions`);
|
|
101
|
+
})
|
|
102
|
+
.catch(error => {
|
|
103
|
+
console.error('Failed to scrape:', error.message);
|
|
104
|
+
process.exit(1);
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export { scrapeHackerNews };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import puppeteer from "puppeteer-core";
|
|
4
|
+
|
|
5
|
+
const args = process.argv.slice(2);
|
|
6
|
+
const newTab = args.includes("--new");
|
|
7
|
+
const reload = args.includes("--reload");
|
|
8
|
+
const url = args.find(a => !a.startsWith("--"));
|
|
9
|
+
|
|
10
|
+
if (!url) {
|
|
11
|
+
console.log("Usage: browser-nav.js <url> [--new] [--reload]");
|
|
12
|
+
console.log("\nExamples:");
|
|
13
|
+
console.log(" browser-nav.js https://example.com # Navigate current tab");
|
|
14
|
+
console.log(" browser-nav.js https://example.com --new # Open in new tab");
|
|
15
|
+
console.log(" browser-nav.js https://example.com --reload # Navigate and force reload");
|
|
16
|
+
process.exit(1);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const b = await Promise.race([
|
|
20
|
+
puppeteer.connect({
|
|
21
|
+
browserURL: "http://localhost:9222",
|
|
22
|
+
defaultViewport: null,
|
|
23
|
+
}),
|
|
24
|
+
new Promise((_, reject) => setTimeout(() => reject(new Error("timeout")), 5000)),
|
|
25
|
+
]).catch((e) => {
|
|
26
|
+
console.error("✗ Could not connect to browser:", e.message);
|
|
27
|
+
console.error(" Run: browser-start.js");
|
|
28
|
+
process.exit(1);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
if (newTab) {
|
|
32
|
+
const p = await b.newPage();
|
|
33
|
+
await p.goto(url, { waitUntil: "domcontentloaded" });
|
|
34
|
+
console.log("✓ Opened:", url);
|
|
35
|
+
} else {
|
|
36
|
+
const p = (await b.pages()).at(-1);
|
|
37
|
+
await p.goto(url, { waitUntil: "domcontentloaded" });
|
|
38
|
+
if (reload) {
|
|
39
|
+
await p.reload({ waitUntil: "domcontentloaded" });
|
|
40
|
+
}
|
|
41
|
+
console.log("✓ Navigated to:", url);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
await b.disconnect();
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import puppeteer from "puppeteer-core";
|
|
4
|
+
|
|
5
|
+
const message = process.argv.slice(2).join(" ");
|
|
6
|
+
if (!message) {
|
|
7
|
+
console.log("Usage: browser-pick.js 'message'");
|
|
8
|
+
console.log("\nExample:");
|
|
9
|
+
console.log(' browser-pick.js "Click the submit button"');
|
|
10
|
+
process.exit(1);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const b = await Promise.race([
|
|
14
|
+
puppeteer.connect({
|
|
15
|
+
browserURL: "http://localhost:9222",
|
|
16
|
+
defaultViewport: null,
|
|
17
|
+
}),
|
|
18
|
+
new Promise((_, reject) => setTimeout(() => reject(new Error("timeout")), 5000)),
|
|
19
|
+
]).catch((e) => {
|
|
20
|
+
console.error("✗ Could not connect to browser:", e.message);
|
|
21
|
+
console.error(" Run: browser-start.js");
|
|
22
|
+
process.exit(1);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const p = (await b.pages()).at(-1);
|
|
26
|
+
|
|
27
|
+
if (!p) {
|
|
28
|
+
console.error("✗ No active tab found");
|
|
29
|
+
process.exit(1);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Inject pick() helper into current page
|
|
33
|
+
await p.evaluate(() => {
|
|
34
|
+
if (!window.pick) {
|
|
35
|
+
window.pick = async (message) => {
|
|
36
|
+
if (!message) {
|
|
37
|
+
throw new Error("pick() requires a message parameter");
|
|
38
|
+
}
|
|
39
|
+
return new Promise((resolve) => {
|
|
40
|
+
const selections = [];
|
|
41
|
+
const selectedElements = new Set();
|
|
42
|
+
|
|
43
|
+
const overlay = document.createElement("div");
|
|
44
|
+
overlay.style.cssText =
|
|
45
|
+
"position:fixed;top:0;left:0;width:100%;height:100%;z-index:2147483647;pointer-events:none";
|
|
46
|
+
|
|
47
|
+
const highlight = document.createElement("div");
|
|
48
|
+
highlight.style.cssText =
|
|
49
|
+
"position:absolute;border:2px solid #3b82f6;background:rgba(59,130,246,0.1);transition:all 0.1s";
|
|
50
|
+
overlay.appendChild(highlight);
|
|
51
|
+
|
|
52
|
+
const banner = document.createElement("div");
|
|
53
|
+
banner.style.cssText =
|
|
54
|
+
"position:fixed;bottom:20px;left:50%;transform:translateX(-50%);background:#1f2937;color:white;padding:12px 24px;border-radius:8px;font:14px sans-serif;box-shadow:0 4px 12px rgba(0,0,0,0.3);pointer-events:auto;z-index:2147483647";
|
|
55
|
+
|
|
56
|
+
const updateBanner = () => {
|
|
57
|
+
banner.textContent = `${message} (${selections.length} selected, Cmd/Ctrl+click to add, Enter to finish, ESC to cancel)`;
|
|
58
|
+
};
|
|
59
|
+
updateBanner();
|
|
60
|
+
|
|
61
|
+
document.body.append(banner, overlay);
|
|
62
|
+
|
|
63
|
+
const cleanup = () => {
|
|
64
|
+
document.removeEventListener("mousemove", onMove, true);
|
|
65
|
+
document.removeEventListener("click", onClick, true);
|
|
66
|
+
document.removeEventListener("keydown", onKey, true);
|
|
67
|
+
overlay.remove();
|
|
68
|
+
banner.remove();
|
|
69
|
+
selectedElements.forEach((el) => {
|
|
70
|
+
el.style.outline = "";
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const onMove = (e) => {
|
|
75
|
+
const el = document.elementFromPoint(e.clientX, e.clientY);
|
|
76
|
+
if (!el || overlay.contains(el) || banner.contains(el)) return;
|
|
77
|
+
const r = el.getBoundingClientRect();
|
|
78
|
+
highlight.style.cssText = `position:absolute;border:2px solid #3b82f6;background:rgba(59,130,246,0.1);top:${r.top}px;left:${r.left}px;width:${r.width}px;height:${r.height}px`;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const buildElementInfo = (el) => {
|
|
82
|
+
const parents = [];
|
|
83
|
+
let current = el.parentElement;
|
|
84
|
+
while (current && current !== document.body) {
|
|
85
|
+
const parentInfo = current.tagName.toLowerCase();
|
|
86
|
+
const id = current.id ? `#${current.id}` : "";
|
|
87
|
+
const cls = current.className
|
|
88
|
+
? `.${current.className.trim().split(/\s+/).join(".")}`
|
|
89
|
+
: "";
|
|
90
|
+
parents.push(parentInfo + id + cls);
|
|
91
|
+
current = current.parentElement;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return {
|
|
95
|
+
tag: el.tagName.toLowerCase(),
|
|
96
|
+
id: el.id || null,
|
|
97
|
+
class: el.className || null,
|
|
98
|
+
text: el.textContent?.trim().slice(0, 200) || null,
|
|
99
|
+
html: el.outerHTML.slice(0, 500),
|
|
100
|
+
parents: parents.join(" > "),
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
const onClick = (e) => {
|
|
105
|
+
if (banner.contains(e.target)) return;
|
|
106
|
+
e.preventDefault();
|
|
107
|
+
e.stopPropagation();
|
|
108
|
+
const el = document.elementFromPoint(e.clientX, e.clientY);
|
|
109
|
+
if (!el || overlay.contains(el) || banner.contains(el)) return;
|
|
110
|
+
|
|
111
|
+
if (e.metaKey || e.ctrlKey) {
|
|
112
|
+
if (!selectedElements.has(el)) {
|
|
113
|
+
selectedElements.add(el);
|
|
114
|
+
el.style.outline = "3px solid #10b981";
|
|
115
|
+
selections.push(buildElementInfo(el));
|
|
116
|
+
updateBanner();
|
|
117
|
+
}
|
|
118
|
+
} else {
|
|
119
|
+
cleanup();
|
|
120
|
+
const info = buildElementInfo(el);
|
|
121
|
+
resolve(selections.length > 0 ? selections : info);
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
const onKey = (e) => {
|
|
126
|
+
if (e.key === "Escape") {
|
|
127
|
+
e.preventDefault();
|
|
128
|
+
cleanup();
|
|
129
|
+
resolve(null);
|
|
130
|
+
} else if (e.key === "Enter" && selections.length > 0) {
|
|
131
|
+
e.preventDefault();
|
|
132
|
+
cleanup();
|
|
133
|
+
resolve(selections);
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
document.addEventListener("mousemove", onMove, true);
|
|
138
|
+
document.addEventListener("click", onClick, true);
|
|
139
|
+
document.addEventListener("keydown", onKey, true);
|
|
140
|
+
});
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
const result = await p.evaluate((msg) => window.pick(msg), message);
|
|
146
|
+
|
|
147
|
+
if (Array.isArray(result)) {
|
|
148
|
+
for (let i = 0; i < result.length; i++) {
|
|
149
|
+
if (i > 0) console.log("");
|
|
150
|
+
for (const [key, value] of Object.entries(result[i])) {
|
|
151
|
+
console.log(`${key}: ${value}`);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
} else if (typeof result === "object" && result !== null) {
|
|
155
|
+
for (const [key, value] of Object.entries(result)) {
|
|
156
|
+
console.log(`${key}: ${value}`);
|
|
157
|
+
}
|
|
158
|
+
} else {
|
|
159
|
+
console.log(result);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
await b.disconnect();
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import puppeteer from "puppeteer-core";
|
|
6
|
+
|
|
7
|
+
const b = await Promise.race([
|
|
8
|
+
puppeteer.connect({
|
|
9
|
+
browserURL: "http://localhost:9222",
|
|
10
|
+
defaultViewport: null,
|
|
11
|
+
}),
|
|
12
|
+
new Promise((_, reject) => setTimeout(() => reject(new Error("timeout")), 5000)),
|
|
13
|
+
]).catch((e) => {
|
|
14
|
+
console.error("✗ Could not connect to browser:", e.message);
|
|
15
|
+
console.error(" Run: browser-start.js");
|
|
16
|
+
process.exit(1);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
const p = (await b.pages()).at(-1);
|
|
20
|
+
|
|
21
|
+
if (!p) {
|
|
22
|
+
console.error("✗ No active tab found");
|
|
23
|
+
process.exit(1);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const timestamp = new Date().toISOString().replace(/[:.]/g, "-");
|
|
27
|
+
const filename = `screenshot-${timestamp}.png`;
|
|
28
|
+
const filepath = join(tmpdir(), filename);
|
|
29
|
+
|
|
30
|
+
await p.screenshot({ path: filepath });
|
|
31
|
+
|
|
32
|
+
console.log(filepath);
|
|
33
|
+
|
|
34
|
+
await b.disconnect();
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { spawn, execSync } from "node:child_process";
|
|
4
|
+
import puppeteer from "puppeteer-core";
|
|
5
|
+
|
|
6
|
+
const useProfile = process.argv[2] === "--profile";
|
|
7
|
+
|
|
8
|
+
if (process.argv[2] && process.argv[2] !== "--profile") {
|
|
9
|
+
console.log("Usage: browser-start.js [--profile]");
|
|
10
|
+
console.log("\nOptions:");
|
|
11
|
+
console.log(" --profile Copy your default Chrome profile (cookies, logins)");
|
|
12
|
+
process.exit(1);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const SCRAPING_DIR = `${process.env.HOME}/.cache/browser-tools`;
|
|
16
|
+
|
|
17
|
+
// Check if already running on :9222
|
|
18
|
+
try {
|
|
19
|
+
const browser = await puppeteer.connect({
|
|
20
|
+
browserURL: "http://localhost:9222",
|
|
21
|
+
defaultViewport: null,
|
|
22
|
+
});
|
|
23
|
+
await browser.disconnect();
|
|
24
|
+
console.log("✓ Chrome already running on :9222");
|
|
25
|
+
process.exit(0);
|
|
26
|
+
} catch {}
|
|
27
|
+
|
|
28
|
+
// Setup profile directory
|
|
29
|
+
execSync(`mkdir -p "${SCRAPING_DIR}"`, { stdio: "ignore" });
|
|
30
|
+
|
|
31
|
+
// Remove SingletonLock to allow new instance
|
|
32
|
+
try {
|
|
33
|
+
execSync(`rm -f "${SCRAPING_DIR}/SingletonLock" "${SCRAPING_DIR}/SingletonSocket" "${SCRAPING_DIR}/SingletonCookie"`, { stdio: "ignore" });
|
|
34
|
+
} catch {}
|
|
35
|
+
|
|
36
|
+
if (useProfile) {
|
|
37
|
+
console.log("Syncing profile...");
|
|
38
|
+
execSync(
|
|
39
|
+
`rsync -a --delete \
|
|
40
|
+
--exclude='SingletonLock' \
|
|
41
|
+
--exclude='SingletonSocket' \
|
|
42
|
+
--exclude='SingletonCookie' \
|
|
43
|
+
--exclude='*/Sessions/*' \
|
|
44
|
+
--exclude='*/Current Session' \
|
|
45
|
+
--exclude='*/Current Tabs' \
|
|
46
|
+
--exclude='*/Last Session' \
|
|
47
|
+
--exclude='*/Last Tabs' \
|
|
48
|
+
"${process.env.HOME}/Library/Application Support/Google/Chrome/" "${SCRAPING_DIR}/"`,
|
|
49
|
+
{ stdio: "pipe" },
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Start Chrome with flags to force new instance
|
|
54
|
+
spawn(
|
|
55
|
+
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
|
|
56
|
+
[
|
|
57
|
+
"--remote-debugging-port=9222",
|
|
58
|
+
`--user-data-dir=${SCRAPING_DIR}`,
|
|
59
|
+
"--no-first-run",
|
|
60
|
+
"--no-default-browser-check",
|
|
61
|
+
],
|
|
62
|
+
{ detached: true, stdio: "ignore" },
|
|
63
|
+
).unref();
|
|
64
|
+
|
|
65
|
+
// Wait for Chrome to be ready
|
|
66
|
+
let connected = false;
|
|
67
|
+
for (let i = 0; i < 30; i++) {
|
|
68
|
+
try {
|
|
69
|
+
const browser = await puppeteer.connect({
|
|
70
|
+
browserURL: "http://localhost:9222",
|
|
71
|
+
defaultViewport: null,
|
|
72
|
+
});
|
|
73
|
+
await browser.disconnect();
|
|
74
|
+
connected = true;
|
|
75
|
+
break;
|
|
76
|
+
} catch {
|
|
77
|
+
await new Promise((r) => setTimeout(r, 500));
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (!connected) {
|
|
82
|
+
console.error("✗ Failed to connect to Chrome");
|
|
83
|
+
process.exit(1);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
console.log(`✓ Chrome started on :9222${useProfile ? " with your profile" : ""}`);
|